@pixldocs/canvas-renderer 0.5.192 → 0.5.194
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/{index-CqgOWYwR.js → index-C1BrMJjh.js} +86 -25
- package/dist/{index-CqgOWYwR.js.map → index-C1BrMJjh.js.map} +1 -1
- package/dist/{index-UIDDdWwb.cjs → index-pshD8xMc.cjs} +86 -25
- package/dist/{index-UIDDdWwb.cjs.map → index-pshD8xMc.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +7 -15
- package/dist/index.js +1 -1
- package/dist/{vectorPdfExport-DuVMxQSS.js → vectorPdfExport-CuD_Ax0x.js} +65 -6
- package/dist/vectorPdfExport-CuD_Ax0x.js.map +1 -0
- package/dist/{vectorPdfExport-O8vRHBlU.cjs → vectorPdfExport-D5Xagjna.cjs} +65 -6
- package/dist/vectorPdfExport-D5Xagjna.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/vectorPdfExport-DuVMxQSS.js.map +0 -1
- package/dist/vectorPdfExport-O8vRHBlU.cjs.map +0 -1
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const jspdf = require("jspdf");
|
|
4
4
|
const svg2pdf_js = require("svg2pdf.js");
|
|
5
5
|
const fabric = require("fabric");
|
|
6
|
-
const index = require("./index-
|
|
6
|
+
const index = require("./index-pshD8xMc.cjs");
|
|
7
7
|
const pdfFonts = require("./pdfFonts-BTj2f465.cjs");
|
|
8
8
|
function _interopNamespaceDefault(e) {
|
|
9
9
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
@@ -468,7 +468,8 @@ function buildMatrixTransformedSvgForPage(svg, matrix, localX, localY, width, he
|
|
|
468
468
|
frame: { x: minX, y: minY, width: frameW, height: frameH }
|
|
469
469
|
};
|
|
470
470
|
}
|
|
471
|
-
async function svg2pdfWithDomMount(svg, pdf, opts) {
|
|
471
|
+
async function svg2pdfWithDomMount(svg, pdf, opts, options) {
|
|
472
|
+
await preloadSvgImagesForPdf(svg, options);
|
|
472
473
|
const wrap = document.createElement("div");
|
|
473
474
|
wrap.style.cssText = "position:fixed;left:-9999px;top:0;width:0;height:0;overflow:hidden;pointer-events:none;opacity:0";
|
|
474
475
|
wrap.appendChild(svg);
|
|
@@ -480,6 +481,51 @@ async function svg2pdfWithDomMount(svg, pdf, opts) {
|
|
|
480
481
|
if (wrap.parentNode) document.body.removeChild(wrap);
|
|
481
482
|
}
|
|
482
483
|
}
|
|
484
|
+
function getSvgImageHref(image) {
|
|
485
|
+
return image.getAttribute("href") || image.getAttribute("xlink:href") || "";
|
|
486
|
+
}
|
|
487
|
+
async function preloadSvgImagesForPdf(svg, options) {
|
|
488
|
+
const images = Array.from(svg.querySelectorAll("image"));
|
|
489
|
+
if (!images.length) return;
|
|
490
|
+
const required = new Set((options == null ? void 0 : options.requiredImageIds) ?? []);
|
|
491
|
+
const failedRequired = [];
|
|
492
|
+
const loadOne = (href) => new Promise((resolve) => {
|
|
493
|
+
if (!href) return resolve(false);
|
|
494
|
+
const img = new Image();
|
|
495
|
+
if (!href.startsWith("data:") && !href.startsWith("blob:")) img.crossOrigin = "anonymous";
|
|
496
|
+
const done = (ok) => resolve(ok);
|
|
497
|
+
img.onload = async () => {
|
|
498
|
+
try {
|
|
499
|
+
if (typeof img.decode === "function") await img.decode();
|
|
500
|
+
} catch {
|
|
501
|
+
}
|
|
502
|
+
done(img.naturalWidth > 0 && img.naturalHeight > 0);
|
|
503
|
+
};
|
|
504
|
+
img.onerror = () => done(false);
|
|
505
|
+
try {
|
|
506
|
+
img.src = href;
|
|
507
|
+
} catch {
|
|
508
|
+
done(false);
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
for (const image of images) {
|
|
512
|
+
const href = getSvgImageHref(image);
|
|
513
|
+
const id = image.getAttribute("data-pixldocs-image-id") || "";
|
|
514
|
+
const ok = await loadOne(href);
|
|
515
|
+
if (id && required.has(id) && !ok) failedRequired.push(id);
|
|
516
|
+
}
|
|
517
|
+
if (required.size > 0) {
|
|
518
|
+
const present = new Set(images.map((image) => image.getAttribute("data-pixldocs-image-id") || "").filter(Boolean));
|
|
519
|
+
const missing = [...required].filter((id) => !present.has(id));
|
|
520
|
+
if (missing.length || failedRequired.length) {
|
|
521
|
+
console.warn(
|
|
522
|
+
`[client-pdf-export] expected image(s) not ready for SVG PDF${(options == null ? void 0 : options.context) ? ` (${options.context})` : ""}: missing=${missing.join(",") || "none"} failed=${failedRequired.join(",") || "none"}`
|
|
523
|
+
);
|
|
524
|
+
} else {
|
|
525
|
+
console.log("[client-pdf-export] SVG image ids ready", { context: options == null ? void 0 : options.context, count: required.size, ids: [...required] });
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
483
529
|
function resetPdfColorState(pdf, label) {
|
|
484
530
|
pdf.setFillColor(0, 0, 0);
|
|
485
531
|
pdf.setDrawColor(0, 0, 0);
|
|
@@ -2525,7 +2571,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
|
|
|
2525
2571
|
async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
|
|
2526
2572
|
if (!colorMap || Object.keys(colorMap).length === 0) return null;
|
|
2527
2573
|
try {
|
|
2528
|
-
const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-
|
|
2574
|
+
const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-pshD8xMc.cjs")).then((n) => n.canvasImageLoader);
|
|
2529
2575
|
return await getNormalizedSvgUrl(imageUrl, colorMap);
|
|
2530
2576
|
} catch {
|
|
2531
2577
|
return null;
|
|
@@ -3316,7 +3362,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
|
|
|
3316
3362
|
}
|
|
3317
3363
|
let fetchUrl = imageUrl;
|
|
3318
3364
|
if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
|
|
3319
|
-
const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-
|
|
3365
|
+
const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-pshD8xMc.cjs")).then((n) => n.canvasImageLoader);
|
|
3320
3366
|
if (isPrivateUrl(imageUrl)) return null;
|
|
3321
3367
|
const proxyUrl = new URL(`${index.API_URL}/image-proxy`);
|
|
3322
3368
|
proxyUrl.searchParams.set("url", imageUrl);
|
|
@@ -4921,6 +4967,17 @@ function preparePagesForExport(pages, canvasWidth, canvasHeight, options) {
|
|
|
4921
4967
|
};
|
|
4922
4968
|
});
|
|
4923
4969
|
}
|
|
4970
|
+
function getExpectedRasterImageIdsForPdfPage(page) {
|
|
4971
|
+
const ids = [];
|
|
4972
|
+
const isSvgUrl = (url) => /\.svg(?:\?|#|$)/i.test(url) || /^data:image\/svg/i.test(url);
|
|
4973
|
+
for (const item of page.elements) {
|
|
4974
|
+
if (isGroupBackgroundDrawable(item) || item.type !== "image" || item.visible === false) continue;
|
|
4975
|
+
const src = String(item.src || item.imageUrl || "").trim();
|
|
4976
|
+
if (!src || item.sourceFormat === "svg" || isSvgUrl(src)) continue;
|
|
4977
|
+
ids.push(item.id);
|
|
4978
|
+
}
|
|
4979
|
+
return [...new Set(ids)];
|
|
4980
|
+
}
|
|
4924
4981
|
async function exportMultiPagePdf(pages, options) {
|
|
4925
4982
|
var _a, _b, _c, _d, _e;
|
|
4926
4983
|
const { filename = "document.pdf", title, watermark = false, returnBlob = false, pdfTextMode = "selectable", skipLiveCanvasSvgFastPath = false } = options;
|
|
@@ -5068,6 +5125,7 @@ async function exportMultiPagePdf(pages, options) {
|
|
|
5068
5125
|
}
|
|
5069
5126
|
const liveCanvasForPage = page.pageId ? index.getCanvasForPage(page.pageId) : null;
|
|
5070
5127
|
let allowLiveCanvasFallback = !!liveCanvasForPage && !skipLiveCanvasSvgFastPath;
|
|
5128
|
+
const expectedRasterImageIds = getExpectedRasterImageIdsForPdfPage(page);
|
|
5071
5129
|
if (liveCanvasForPage && !skipLiveCanvasSvgFastPath) {
|
|
5072
5130
|
try {
|
|
5073
5131
|
const liveSvgString = index.captureFabricCanvasSvgForPdf(
|
|
@@ -5110,7 +5168,8 @@ async function exportMultiPagePdf(pages, options) {
|
|
|
5110
5168
|
await svg2pdfWithDomMount(
|
|
5111
5169
|
liveSvg,
|
|
5112
5170
|
pdfWithColorLogging(pdf, seq, `page-${pageIndex + 1}`),
|
|
5113
|
-
svg2pdfOpts(0, 0, page.width, page.height)
|
|
5171
|
+
svg2pdfOpts(0, 0, page.width, page.height),
|
|
5172
|
+
{ requiredImageIds: expectedRasterImageIds, context: `page-${pageIndex + 1}` }
|
|
5114
5173
|
);
|
|
5115
5174
|
debugLog(`live canvas svg2pdf DONE #${seq} page=${pageIndex + 1}`);
|
|
5116
5175
|
resetPdfColorState(pdf, `after live canvas svg2pdf page ${pageIndex + 1}`);
|
|
@@ -5310,4 +5369,4 @@ exports.exportMultiPagePdf = exportMultiPagePdf;
|
|
|
5310
5369
|
exports.logTextMeasurementDiagnostic = logTextMeasurementDiagnostic;
|
|
5311
5370
|
exports.preparePagesForExport = preparePagesForExport;
|
|
5312
5371
|
exports.rewriteSvgFontsForJsPDFWithSourceMeta = rewriteSvgFontsForJsPDFWithSourceMeta;
|
|
5313
|
-
//# sourceMappingURL=vectorPdfExport-
|
|
5372
|
+
//# sourceMappingURL=vectorPdfExport-D5Xagjna.cjs.map
|