⚙️ Create clipboard, download, downloadSvg & parse svg utilities

This commit is contained in:
pheralb
2025-08-25 14:24:44 +01:00
parent f53d5418b6
commit 6761716dca
5 changed files with 175 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
type MimeType = "image/svg+xml" | "application/zip";
interface Download {
content: string | Blob;
filename: string;
mimeType: MimeType;
}
export const download = ({ content, filename, mimeType }: Download) => {
const blob =
typeof content === "string"
? new Blob([content], { type: mimeType })
: content;
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
a.style.display = "none";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
};