@pixldocs/canvas-renderer 0.3.20 → 0.3.22
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 +41 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.js +41 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -10777,6 +10777,18 @@ class PixldocsRenderer {
|
|
|
10777
10777
|
});
|
|
10778
10778
|
return this.render(resolved.config, options);
|
|
10779
10779
|
}
|
|
10780
|
+
/**
|
|
10781
|
+
* Convenience: fetch by ID with flat data and render ALL pages.
|
|
10782
|
+
*/
|
|
10783
|
+
async renderAllById(templateId, formData, options) {
|
|
10784
|
+
const resolved = await resolveTemplateData({
|
|
10785
|
+
templateId,
|
|
10786
|
+
formData,
|
|
10787
|
+
supabaseUrl: this.config.supabaseUrl,
|
|
10788
|
+
supabaseAnonKey: this.config.supabaseAnonKey
|
|
10789
|
+
});
|
|
10790
|
+
return this.renderAllPages(resolved.config, options);
|
|
10791
|
+
}
|
|
10780
10792
|
// ─── Internal: render a page using the full PreviewCanvas engine ───
|
|
10781
10793
|
getExpectedImageCount(config, pageIndex) {
|
|
10782
10794
|
const page = config.pages[pageIndex];
|
|
@@ -11082,7 +11094,8 @@ class PixldocsRenderer {
|
|
|
11082
11094
|
const prevSvgVPT = fabricInstance.svgViewportTransformation;
|
|
11083
11095
|
fabricInstance.viewportTransform = [1, 0, 0, 1, 0, 0];
|
|
11084
11096
|
fabricInstance.svgViewportTransformation = false;
|
|
11085
|
-
|
|
11097
|
+
let svgString = fabricInstance.toSVG();
|
|
11098
|
+
svgString = this.normalizeSvgDimensions(svgString, canvasWidth, canvasHeight);
|
|
11086
11099
|
if (prevVPT) fabricInstance.viewportTransform = prevVPT;
|
|
11087
11100
|
fabricInstance.svgViewportTransformation = prevSvgVPT;
|
|
11088
11101
|
const page = config.pages[pageIndex];
|
|
@@ -11115,6 +11128,33 @@ class PixldocsRenderer {
|
|
|
11115
11128
|
);
|
|
11116
11129
|
});
|
|
11117
11130
|
}
|
|
11131
|
+
/**
|
|
11132
|
+
* Normalize the SVG's width/height/viewBox to match the logical page dimensions.
|
|
11133
|
+
* Fabric's toSVG() may output dimensions scaled by the canvas element's actual
|
|
11134
|
+
* pixel size (e.g., 2x due to devicePixelRatio), causing svg2pdf to render
|
|
11135
|
+
* content at the wrong scale. This rewrites the root <svg> attributes to ensure
|
|
11136
|
+
* the SVG coordinate system matches the intended page size exactly.
|
|
11137
|
+
*/
|
|
11138
|
+
normalizeSvgDimensions(svg, targetWidth, targetHeight) {
|
|
11139
|
+
const widthMatch = svg.match(/<svg[^>]*\bwidth="([^"]+)"/);
|
|
11140
|
+
const heightMatch = svg.match(/<svg[^>]*\bheight="([^"]+)"/);
|
|
11141
|
+
const svgWidth = widthMatch ? parseFloat(widthMatch[1]) : targetWidth;
|
|
11142
|
+
const svgHeight = heightMatch ? parseFloat(heightMatch[1]) : targetHeight;
|
|
11143
|
+
if (Math.abs(svgWidth - targetWidth) < 1 && Math.abs(svgHeight - targetHeight) < 1) {
|
|
11144
|
+
return svg;
|
|
11145
|
+
}
|
|
11146
|
+
console.log(
|
|
11147
|
+
`[canvas-renderer][svg-normalize] SVG dimensions ${svgWidth}x${svgHeight} → ${targetWidth}x${targetHeight}`
|
|
11148
|
+
);
|
|
11149
|
+
let normalized = svg.replace(/(<svg[^>]*\b)width="[^"]*"/, `$1width="${targetWidth}"`).replace(/(<svg[^>]*\b)height="[^"]*"/, `$1height="${targetHeight}"`);
|
|
11150
|
+
const viewBox = `0 0 ${svgWidth} ${svgHeight}`;
|
|
11151
|
+
if (/viewBox="[^"]*"/.test(normalized)) {
|
|
11152
|
+
normalized = normalized.replace(/viewBox="[^"]*"/, `viewBox="${viewBox}"`);
|
|
11153
|
+
} else {
|
|
11154
|
+
normalized = normalized.replace(/<svg\b/, `<svg viewBox="${viewBox}"`);
|
|
11155
|
+
}
|
|
11156
|
+
return normalized;
|
|
11157
|
+
}
|
|
11118
11158
|
/**
|
|
11119
11159
|
* Find the Fabric.Canvas instance that belongs to a given container element,
|
|
11120
11160
|
* using the global __fabricCanvasRegistry (set by PageCanvas).
|