async function download(url,{ dpr = 1, scale = 1, backgroundColor =  "#fff", format = "png", filename = "capture"} = {}) {
  if (format === "svg") {
    const blob = await toBlob(url);
    const objectURL = URL.createObjectURL(blob);
    const a = document.createElement("a");
    a.href = objectURL;
    a.download = `${filename}.svg`;
    a.click();
    URL.revokeObjectURL(objectURL);
    return;
  }

  const defaultBg = ["jpg", "jpeg", "webp"].includes(format) ? "#fff" : undefined;
  const finalBg = backgroundColor ?? defaultBg;

  const canvas = await createBackground(url, { dpr, scale }, finalBg);
  const mime = {
    jpg: "image/jpeg",
    jpeg: "image/jpeg",
    png: "image/png",
    webp: "image/webp",
  }[format] || "image/png";

  const dataURL = canvas.toDataURL(mime);

  const a = document.createElement("a");
  a.href = dataURL;
  a.download = `${filename}.${format}`;
  a.click();
}
Downloads a captured image in the specified format.

@param {string} url - SVG data URL
@param {Object} options
@param {number} [options.dpr=1] - Device pixel ratio
@param {number} [options.scale=1] - Scale multiplier
@param {string} [options.backgroundColor="#fff"] - Background color for rasterization
@param {string} [options.format="png"] - Output format
@param {string} [options.filename="capture"] - Download filename
@returns {Promise<void>} Resolves when download is triggered