@pixldocs/canvas-renderer 0.5.125 → 0.5.126
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/dist/{index-CNN2CRQh.cjs → index-8Dj3s-9A.cjs} +127 -83
- package/dist/index-8Dj3s-9A.cjs.map +1 -0
- package/dist/{index-D7cGwzxX.js → index-D-lngEWM.js} +166 -122
- package/dist/index-D-lngEWM.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +33 -33
- package/dist/{vectorPdfExport-DVISwrvS.cjs → vectorPdfExport-DSf_ziXM.cjs} +9 -16
- package/dist/vectorPdfExport-DSf_ziXM.cjs.map +1 -0
- package/dist/{vectorPdfExport-BBV3abJi.js → vectorPdfExport-ix7Z1pGO.js} +9 -16
- package/dist/vectorPdfExport-ix7Z1pGO.js.map +1 -0
- package/package.json +1 -1
- package/dist/index-CNN2CRQh.cjs.map +0 -1
- package/dist/index-D7cGwzxX.js.map +0 -1
- package/dist/vectorPdfExport-BBV3abJi.js.map +0 -1
- package/dist/vectorPdfExport-DVISwrvS.cjs.map +0 -1
|
@@ -15660,7 +15660,128 @@ function PixldocsPreview(props) {
|
|
|
15660
15660
|
!canvasSettled && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) })
|
|
15661
15661
|
] });
|
|
15662
15662
|
}
|
|
15663
|
-
|
|
15663
|
+
function normalizeSvgDimensions(svg, targetWidth, targetHeight) {
|
|
15664
|
+
let normalized = svg;
|
|
15665
|
+
if (/\bwidth="[^"]*"/i.test(normalized)) {
|
|
15666
|
+
normalized = normalized.replace(/(<svg[^>]*\b)width="[^"]*"/i, `$1width="${targetWidth}"`);
|
|
15667
|
+
} else {
|
|
15668
|
+
normalized = normalized.replace(/<svg\b/i, `<svg width="${targetWidth}"`);
|
|
15669
|
+
}
|
|
15670
|
+
if (/\bheight="[^"]*"/i.test(normalized)) {
|
|
15671
|
+
normalized = normalized.replace(/(<svg[^>]*\b)height="[^"]*"/i, `$1height="${targetHeight}"`);
|
|
15672
|
+
} else {
|
|
15673
|
+
normalized = normalized.replace(/<svg\b/i, `<svg height="${targetHeight}"`);
|
|
15674
|
+
}
|
|
15675
|
+
const viewBox = `0 0 ${targetWidth} ${targetHeight}`;
|
|
15676
|
+
if (/\bviewBox="[^"]*"/i.test(normalized)) {
|
|
15677
|
+
normalized = normalized.replace(/viewBox="[^"]*"/i, `viewBox="${viewBox}"`);
|
|
15678
|
+
} else {
|
|
15679
|
+
normalized = normalized.replace(/<svg\b/i, `<svg viewBox="${viewBox}"`);
|
|
15680
|
+
}
|
|
15681
|
+
normalized = normalized.replace(/="undefined"/g, '="0"');
|
|
15682
|
+
normalized = normalized.replace(/="NaN"/g, '="0"');
|
|
15683
|
+
if (/\bx="[^"]*"/i.test(normalized)) {
|
|
15684
|
+
normalized = normalized.replace(/(<svg[^>]*\b)x="[^"]*"/i, '$1x="0"');
|
|
15685
|
+
} else {
|
|
15686
|
+
normalized = normalized.replace(/<svg\b/i, '<svg x="0"');
|
|
15687
|
+
}
|
|
15688
|
+
if (/\by="[^"]*"/i.test(normalized)) {
|
|
15689
|
+
normalized = normalized.replace(/(<svg[^>]*\b)y="[^"]*"/i, '$1y="0"');
|
|
15690
|
+
} else {
|
|
15691
|
+
normalized = normalized.replace(/<svg\b/i, '<svg y="0"');
|
|
15692
|
+
}
|
|
15693
|
+
normalized = normalized.replace(/\bpreserveAspectRatio="[^"]*"/i, 'preserveAspectRatio="none"');
|
|
15694
|
+
if (!/\bpreserveAspectRatio="[^"]*"/i.test(normalized)) {
|
|
15695
|
+
normalized = normalized.replace(/<svg\b/i, '<svg preserveAspectRatio="none"');
|
|
15696
|
+
}
|
|
15697
|
+
return normalized;
|
|
15698
|
+
}
|
|
15699
|
+
function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight) {
|
|
15700
|
+
const prevVPT = fabricInstance.viewportTransform ? [...fabricInstance.viewportTransform] : void 0;
|
|
15701
|
+
const prevSvgVPT = fabricInstance.svgViewportTransformation;
|
|
15702
|
+
const prevRetina = fabricInstance.enableRetinaScaling;
|
|
15703
|
+
const prevWidth = fabricInstance.width;
|
|
15704
|
+
const prevHeight = fabricInstance.height;
|
|
15705
|
+
fabricInstance.viewportTransform = [1, 0, 0, 1, 0, 0];
|
|
15706
|
+
fabricInstance.svgViewportTransformation = false;
|
|
15707
|
+
fabricInstance.enableRetinaScaling = false;
|
|
15708
|
+
try {
|
|
15709
|
+
fabricInstance.setDimensions(
|
|
15710
|
+
{ width: canvasWidth, height: canvasHeight },
|
|
15711
|
+
{ cssOnly: false, backstoreOnly: false }
|
|
15712
|
+
);
|
|
15713
|
+
} catch {
|
|
15714
|
+
}
|
|
15715
|
+
const fadeBakeRecords = [];
|
|
15716
|
+
try {
|
|
15717
|
+
const objs = fabricInstance.getObjects().slice();
|
|
15718
|
+
for (const obj of objs) {
|
|
15719
|
+
const isGroupLike = obj instanceof fabric__namespace.Group || (obj == null ? void 0 : obj.type) === "group" || Array.isArray(obj == null ? void 0 : obj._objects);
|
|
15720
|
+
const isFadedCropGroup = isGroupLike && (Boolean(obj.__edgeFadeRenderConfig) || Boolean(obj.__edgeFadeKey) || Boolean(obj.__edgeFadeInputKey));
|
|
15721
|
+
if (!isFadedCropGroup) continue;
|
|
15722
|
+
try {
|
|
15723
|
+
const baked = obj.toCanvasElement({
|
|
15724
|
+
multiplier: 2,
|
|
15725
|
+
enableRetinaScaling: false
|
|
15726
|
+
});
|
|
15727
|
+
const rect = obj.getBoundingRect();
|
|
15728
|
+
const replacement = new fabric__namespace.FabricImage(baked, {
|
|
15729
|
+
left: rect.left,
|
|
15730
|
+
top: rect.top,
|
|
15731
|
+
originX: "left",
|
|
15732
|
+
originY: "top",
|
|
15733
|
+
scaleX: rect.width / baked.width,
|
|
15734
|
+
scaleY: rect.height / baked.height,
|
|
15735
|
+
selectable: false,
|
|
15736
|
+
evented: false,
|
|
15737
|
+
objectCaching: false
|
|
15738
|
+
});
|
|
15739
|
+
const insertIndex = fabricInstance._objects.indexOf(obj);
|
|
15740
|
+
const prevExclude = obj.excludeFromExport;
|
|
15741
|
+
obj.excludeFromExport = true;
|
|
15742
|
+
if (insertIndex >= 0) {
|
|
15743
|
+
fabricInstance.insertAt(insertIndex + 1, replacement);
|
|
15744
|
+
} else {
|
|
15745
|
+
fabricInstance.add(replacement);
|
|
15746
|
+
}
|
|
15747
|
+
fadeBakeRecords.push({ original: obj, replacement, prevExclude, insertIndex });
|
|
15748
|
+
} catch (bakeErr) {
|
|
15749
|
+
console.warn("[canvas-svg-capture][edgeFade] bake failed:", bakeErr);
|
|
15750
|
+
}
|
|
15751
|
+
}
|
|
15752
|
+
if (fadeBakeRecords.length) {
|
|
15753
|
+
fabricInstance.renderAll();
|
|
15754
|
+
console.log(`[canvas-svg-capture][edgeFade] baked ${fadeBakeRecords.length} faded object(s)`);
|
|
15755
|
+
}
|
|
15756
|
+
} catch (e) {
|
|
15757
|
+
console.warn("[canvas-svg-capture][edgeFade] bake pass error:", e);
|
|
15758
|
+
}
|
|
15759
|
+
let svgString = "";
|
|
15760
|
+
try {
|
|
15761
|
+
const raw = fabricInstance.toSVG();
|
|
15762
|
+
svgString = normalizeSvgDimensions(raw, canvasWidth, canvasHeight);
|
|
15763
|
+
} finally {
|
|
15764
|
+
for (const rec of fadeBakeRecords) {
|
|
15765
|
+
try {
|
|
15766
|
+
fabricInstance.remove(rec.replacement);
|
|
15767
|
+
rec.original.excludeFromExport = rec.prevExclude;
|
|
15768
|
+
} catch {
|
|
15769
|
+
}
|
|
15770
|
+
}
|
|
15771
|
+
try {
|
|
15772
|
+
fabricInstance.enableRetinaScaling = prevRetina;
|
|
15773
|
+
fabricInstance.setDimensions(
|
|
15774
|
+
{ width: prevWidth, height: prevHeight },
|
|
15775
|
+
{ cssOnly: false, backstoreOnly: false }
|
|
15776
|
+
);
|
|
15777
|
+
} catch {
|
|
15778
|
+
}
|
|
15779
|
+
if (prevVPT) fabricInstance.viewportTransform = prevVPT;
|
|
15780
|
+
fabricInstance.svgViewportTransformation = prevSvgVPT;
|
|
15781
|
+
}
|
|
15782
|
+
return svgString;
|
|
15783
|
+
}
|
|
15784
|
+
const PACKAGE_VERSION = "0.5.126";
|
|
15664
15785
|
const roundParityValue = (value) => {
|
|
15665
15786
|
if (typeof value !== "number") return value;
|
|
15666
15787
|
return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
|
|
@@ -16079,7 +16200,7 @@ class PixldocsRenderer {
|
|
|
16079
16200
|
await this.waitForCanvasScene(container, cloned, i);
|
|
16080
16201
|
}
|
|
16081
16202
|
console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
|
|
16082
|
-
const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-
|
|
16203
|
+
const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-DSf_ziXM.cjs"));
|
|
16083
16204
|
const prepared = preparePagesForExport(
|
|
16084
16205
|
cloned.pages,
|
|
16085
16206
|
canvasWidth,
|
|
@@ -16557,89 +16678,11 @@ class PixldocsRenderer {
|
|
|
16557
16678
|
reject(new Error("No Fabric canvas instance found for SVG capture"));
|
|
16558
16679
|
return;
|
|
16559
16680
|
}
|
|
16560
|
-
const
|
|
16561
|
-
|
|
16562
|
-
const prevRetina = fabricInstance.enableRetinaScaling;
|
|
16563
|
-
const prevWidth = fabricInstance.width;
|
|
16564
|
-
const prevHeight = fabricInstance.height;
|
|
16565
|
-
fabricInstance.viewportTransform = [1, 0, 0, 1, 0, 0];
|
|
16566
|
-
fabricInstance.svgViewportTransformation = false;
|
|
16567
|
-
fabricInstance.enableRetinaScaling = false;
|
|
16568
|
-
fabricInstance.setDimensions(
|
|
16569
|
-
{ width: canvasWidth, height: canvasHeight },
|
|
16570
|
-
{ cssOnly: false, backstoreOnly: false }
|
|
16571
|
-
);
|
|
16572
|
-
const fadeBakeRecords = [];
|
|
16573
|
-
try {
|
|
16574
|
-
const objs = fabricInstance.getObjects().slice();
|
|
16575
|
-
for (const obj of objs) {
|
|
16576
|
-
const isGroupLike = obj instanceof fabric__namespace.Group || (obj == null ? void 0 : obj.type) === "group" || Array.isArray(obj == null ? void 0 : obj._objects);
|
|
16577
|
-
const isFadedCropGroup = isGroupLike && (Boolean(obj.__edgeFadeRenderConfig) || Boolean(obj.__edgeFadeKey) || Boolean(obj.__edgeFadeInputKey));
|
|
16578
|
-
if (!isFadedCropGroup) continue;
|
|
16579
|
-
try {
|
|
16580
|
-
const baked = obj.toCanvasElement({
|
|
16581
|
-
multiplier: 2,
|
|
16582
|
-
enableRetinaScaling: false
|
|
16583
|
-
});
|
|
16584
|
-
const rect = obj.getBoundingRect();
|
|
16585
|
-
const replacement = new fabric__namespace.FabricImage(baked, {
|
|
16586
|
-
left: rect.left,
|
|
16587
|
-
top: rect.top,
|
|
16588
|
-
originX: "left",
|
|
16589
|
-
originY: "top",
|
|
16590
|
-
scaleX: rect.width / baked.width,
|
|
16591
|
-
scaleY: rect.height / baked.height,
|
|
16592
|
-
selectable: false,
|
|
16593
|
-
evented: false,
|
|
16594
|
-
objectCaching: false
|
|
16595
|
-
});
|
|
16596
|
-
const insertIndex = fabricInstance._objects.indexOf(obj);
|
|
16597
|
-
const prevExclude = obj.excludeFromExport;
|
|
16598
|
-
obj.excludeFromExport = true;
|
|
16599
|
-
if (insertIndex >= 0) {
|
|
16600
|
-
fabricInstance.insertAt(insertIndex + 1, replacement);
|
|
16601
|
-
} else {
|
|
16602
|
-
fabricInstance.add(replacement);
|
|
16603
|
-
}
|
|
16604
|
-
fadeBakeRecords.push({
|
|
16605
|
-
original: obj,
|
|
16606
|
-
replacement,
|
|
16607
|
-
prevExclude,
|
|
16608
|
-
insertIndex
|
|
16609
|
-
});
|
|
16610
|
-
} catch (bakeErr) {
|
|
16611
|
-
console.warn("[canvas-renderer][edgeFade] bake-for-svg failed:", bakeErr);
|
|
16612
|
-
}
|
|
16613
|
-
}
|
|
16614
|
-
if (fadeBakeRecords.length) {
|
|
16615
|
-
fabricInstance.renderAll();
|
|
16616
|
-
console.log(
|
|
16617
|
-
`[canvas-renderer][edgeFade] baked ${fadeBakeRecords.length} faded object(s) for SVG capture`
|
|
16618
|
-
);
|
|
16619
|
-
}
|
|
16620
|
-
} catch (e) {
|
|
16621
|
-
console.warn("[canvas-renderer][edgeFade] bake pass failed:", e);
|
|
16622
|
-
}
|
|
16623
|
-
const rawSvgString = fabricInstance.toSVG();
|
|
16624
|
-
const svgString = this.normalizeSvgDimensions(
|
|
16625
|
-
rawSvgString,
|
|
16681
|
+
const svgString = captureFabricCanvasSvgForPdf(
|
|
16682
|
+
fabricInstance,
|
|
16626
16683
|
canvasWidth,
|
|
16627
16684
|
canvasHeight
|
|
16628
16685
|
);
|
|
16629
|
-
for (const rec of fadeBakeRecords) {
|
|
16630
|
-
try {
|
|
16631
|
-
fabricInstance.remove(rec.replacement);
|
|
16632
|
-
rec.original.excludeFromExport = rec.prevExclude;
|
|
16633
|
-
} catch {
|
|
16634
|
-
}
|
|
16635
|
-
}
|
|
16636
|
-
fabricInstance.enableRetinaScaling = prevRetina;
|
|
16637
|
-
fabricInstance.setDimensions(
|
|
16638
|
-
{ width: prevWidth, height: prevHeight },
|
|
16639
|
-
{ cssOnly: false, backstoreOnly: false }
|
|
16640
|
-
);
|
|
16641
|
-
if (prevVPT) fabricInstance.viewportTransform = prevVPT;
|
|
16642
|
-
fabricInstance.svgViewportTransformation = prevSvgVPT;
|
|
16643
16686
|
const page = renderConfig.pages[pageIndex];
|
|
16644
16687
|
const backgroundColor = ((_a = page == null ? void 0 : page.settings) == null ? void 0 : _a.backgroundColor) || "#ffffff";
|
|
16645
16688
|
const backgroundGradient = (_b = page == null ? void 0 : page.settings) == null ? void 0 : _b.backgroundGradient;
|
|
@@ -18448,6 +18491,7 @@ exports.awaitFontsForConfig = awaitFontsForConfig;
|
|
|
18448
18491
|
exports.bakeEdgeFade = bakeEdgeFade;
|
|
18449
18492
|
exports.buildRoundedTrianglePath = buildRoundedTrianglePath;
|
|
18450
18493
|
exports.canvasImageLoader = canvasImageLoader;
|
|
18494
|
+
exports.captureFabricCanvasSvgForPdf = captureFabricCanvasSvgForPdf;
|
|
18451
18495
|
exports.collectFontDescriptorsFromConfig = collectFontDescriptorsFromConfig;
|
|
18452
18496
|
exports.collectFontsFromConfig = collectFontsFromConfig;
|
|
18453
18497
|
exports.collectImageUrls = collectImageUrls;
|
|
@@ -18485,4 +18529,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
|
|
|
18485
18529
|
exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
|
|
18486
18530
|
exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
|
|
18487
18531
|
exports.warmTemplateFromForm = warmTemplateFromForm;
|
|
18488
|
-
//# sourceMappingURL=index-
|
|
18532
|
+
//# sourceMappingURL=index-8Dj3s-9A.cjs.map
|