@pixldocs/canvas-renderer 0.3.23 → 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.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,17 +11081,20 @@ class PixldocsRenderer {
11073
11081
  }
11074
11082
  const prevVPT = fabricInstance.viewportTransform ? [...fabricInstance.viewportTransform] : void 0;
11075
11083
  const prevSvgVPT = fabricInstance.svgViewportTransformation;
11076
- const prevCanvasWidth = fabricInstance.width;
11077
- const prevCanvasHeight = fabricInstance.height;
11084
+ const prevRetina = fabricInstance.enableRetinaScaling;
11085
+ const prevWidth = fabricInstance.width;
11086
+ const prevHeight = fabricInstance.height;
11087
+ fabricInstance.viewportTransform = [1, 0, 0, 1, 0, 0];
11088
+ fabricInstance.svgViewportTransformation = false;
11089
+ fabricInstance.enableRetinaScaling = false;
11078
11090
  fabricInstance.setDimensions(
11079
11091
  { width: canvasWidth, height: canvasHeight },
11080
11092
  { cssOnly: false, backstoreOnly: false }
11081
11093
  );
11082
- fabricInstance.viewportTransform = [1, 0, 0, 1, 0, 0];
11083
- fabricInstance.svgViewportTransformation = false;
11084
11094
  const svgString = fabricInstance.toSVG();
11095
+ fabricInstance.enableRetinaScaling = prevRetina;
11085
11096
  fabricInstance.setDimensions(
11086
- { width: prevCanvasWidth, height: prevCanvasHeight },
11097
+ { width: prevWidth, height: prevHeight },
11087
11098
  { cssOnly: false, backstoreOnly: false }
11088
11099
  );
11089
11100
  if (prevVPT) fabricInstance.viewportTransform = prevVPT;
@@ -11111,7 +11122,7 @@ class PixldocsRenderer {
11111
11122
  config,
11112
11123
  pageIndex,
11113
11124
  zoom: 1,
11114
- // 1:1 — no scaling for SVG capture
11125
+ // 1:1 — no UI scaling for SVG capture
11115
11126
  absoluteZoom: true,
11116
11127
  onReady
11117
11128
  })