@pixldocs/canvas-renderer 0.3.22 → 0.3.24
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.cjs +23 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +23 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11038,6 +11038,14 @@ class PixldocsRenderer {
|
|
|
11038
11038
|
});
|
|
11039
11039
|
}
|
|
11040
11040
|
// ─── Internal: capture SVG from a rendered Fabric canvas ───
|
|
11041
|
+
//
|
|
11042
|
+
// APPROACH: Use the SAME PreviewCanvas that renders perfect PNGs, then call
|
|
11043
|
+
// Fabric's toSVG() on that canvas. This guarantees 100% layout parity —
|
|
11044
|
+
// the SVG is a vector snapshot of exactly what's on screen.
|
|
11045
|
+
//
|
|
11046
|
+
// The trick: before calling toSVG(), we temporarily neutralize the viewport
|
|
11047
|
+
// transform and retina scaling so Fabric emits coordinates in logical
|
|
11048
|
+
// document space (e.g. 612x792) instead of inflated pixel space.
|
|
11041
11049
|
captureSvgViaPreviewCanvas(config, pageIndex, canvasWidth, canvasHeight) {
|
|
11042
11050
|
return new Promise(async (resolve, reject) => {
|
|
11043
11051
|
const { PreviewCanvas: PreviewCanvas2 } = await Promise.resolve().then(() => PreviewCanvas$1);
|
|
@@ -11073,10 +11081,22 @@ class PixldocsRenderer {
|
|
|
11073
11081
|
}
|
|
11074
11082
|
const prevVPT = fabricInstance.viewportTransform ? [...fabricInstance.viewportTransform] : void 0;
|
|
11075
11083
|
const prevSvgVPT = fabricInstance.svgViewportTransformation;
|
|
11084
|
+
const prevRetina = fabricInstance.enableRetinaScaling;
|
|
11085
|
+
const prevWidth = fabricInstance.width;
|
|
11086
|
+
const prevHeight = fabricInstance.height;
|
|
11076
11087
|
fabricInstance.viewportTransform = [1, 0, 0, 1, 0, 0];
|
|
11077
11088
|
fabricInstance.svgViewportTransformation = false;
|
|
11078
|
-
|
|
11079
|
-
|
|
11089
|
+
fabricInstance.enableRetinaScaling = false;
|
|
11090
|
+
fabricInstance.setDimensions(
|
|
11091
|
+
{ width: canvasWidth, height: canvasHeight },
|
|
11092
|
+
{ cssOnly: false, backstoreOnly: false }
|
|
11093
|
+
);
|
|
11094
|
+
const svgString = fabricInstance.toSVG();
|
|
11095
|
+
fabricInstance.enableRetinaScaling = prevRetina;
|
|
11096
|
+
fabricInstance.setDimensions(
|
|
11097
|
+
{ width: prevWidth, height: prevHeight },
|
|
11098
|
+
{ cssOnly: false, backstoreOnly: false }
|
|
11099
|
+
);
|
|
11080
11100
|
if (prevVPT) fabricInstance.viewportTransform = prevVPT;
|
|
11081
11101
|
fabricInstance.svgViewportTransformation = prevSvgVPT;
|
|
11082
11102
|
const page = config.pages[pageIndex];
|
|
@@ -11102,7 +11122,7 @@ class PixldocsRenderer {
|
|
|
11102
11122
|
config,
|
|
11103
11123
|
pageIndex,
|
|
11104
11124
|
zoom: 1,
|
|
11105
|
-
// 1:1 — no scaling for SVG capture
|
|
11125
|
+
// 1:1 — no UI scaling for SVG capture
|
|
11106
11126
|
absoluteZoom: true,
|
|
11107
11127
|
onReady
|
|
11108
11128
|
})
|