39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import {
|
|
sanitizeDownloadFilename,
|
|
stableStringify,
|
|
} from "@add-ideas/toolbox-helpers";
|
|
import { strToU8, zipSync } from "fflate";
|
|
import type { RenderResult } from "./types";
|
|
|
|
export function createSvgZip(result: RenderResult): Blob {
|
|
const files: Record<string, Uint8Array> = {};
|
|
result.pages.forEach((svg, index) => {
|
|
files[`label-sheet-${String(index + 1).padStart(3, "0")}.svg`] =
|
|
strToU8(svg);
|
|
});
|
|
files["merge-report.json"] = strToU8(
|
|
stableStringify(
|
|
{
|
|
application: "Label Tools 0.2.0",
|
|
pages: result.totalPages,
|
|
labels: result.totalLabels,
|
|
warnings: result.warnings,
|
|
boundary:
|
|
"System fonts and printer scaling are not embedded or controlled; print a calibration sheet first.",
|
|
},
|
|
2,
|
|
),
|
|
);
|
|
const bytes = zipSync(files, {
|
|
level: 6,
|
|
mtime: new Date("1980-01-01T00:00:00.000Z"),
|
|
});
|
|
return new Blob([new Uint8Array(bytes).buffer], { type: "application/zip" });
|
|
}
|
|
|
|
export function svgFilename(index: number): string {
|
|
return sanitizeDownloadFilename(
|
|
`label-sheet-${String(index + 1).padStart(3, "0")}.svg`,
|
|
);
|
|
}
|