@pixldocs/canvas-renderer 0.5.159 → 0.5.161
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-ogNxtubz.js → index-Co0kEgTl.js} +5 -194
- package/dist/index-Co0kEgTl.js.map +1 -0
- package/dist/{index-CA-UhjM7.cjs → index-OWSb_i03.cjs} +5 -194
- package/dist/index-OWSb_i03.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{vectorPdfExport-BRxfHxZU.js → vectorPdfExport-B_T8jiQ3.js} +4 -4
- package/dist/{vectorPdfExport-BRxfHxZU.js.map → vectorPdfExport-B_T8jiQ3.js.map} +1 -1
- package/dist/{vectorPdfExport-BqyoXT--.cjs → vectorPdfExport-CqdQi3YK.cjs} +4 -4
- package/dist/{vectorPdfExport-BqyoXT--.cjs.map → vectorPdfExport-CqdQi3YK.cjs.map} +1 -1
- package/package.json +1 -1
- package/dist/index-CA-UhjM7.cjs.map +0 -1
- package/dist/index-ogNxtubz.js.map +0 -1
|
@@ -5711,7 +5711,6 @@ function applyTextBackground(obj, cfg) {
|
|
|
5711
5711
|
const bgPath = hasBg ? `<path d="${bgD}" fill="${escapeXmlAttr(bgFill)}"${bgOpacityAttr} />` : "";
|
|
5712
5712
|
svg = svg.replace(/style="[^"]*filter:\s*url\([^)]+\)[^"]*"/i, "");
|
|
5713
5713
|
svg = svg.replace(/<filter[\s\S]*?<\/filter>/gi, "");
|
|
5714
|
-
svg = bakeTextSvgToFabricLineStarts(svg, this, w);
|
|
5715
5714
|
let bgShadowMarker = "";
|
|
5716
5715
|
let textShadowMarker = "";
|
|
5717
5716
|
if (hasShadow) {
|
|
@@ -5761,100 +5760,6 @@ function applyTextBackground(obj, cfg) {
|
|
|
5761
5760
|
function recolorSvgFills(svg, color) {
|
|
5762
5761
|
return _recolorSvgFills(svg, color);
|
|
5763
5762
|
}
|
|
5764
|
-
function bakeTextSvgToFabricLineStarts(svg, obj, w) {
|
|
5765
|
-
var _a, _b, _c, _d;
|
|
5766
|
-
try {
|
|
5767
|
-
const lines = (obj == null ? void 0 : obj._textLines) ?? [];
|
|
5768
|
-
if (!Array.isArray(lines) || lines.length === 0) return svg;
|
|
5769
|
-
const rawAlign = String((obj == null ? void 0 : obj.textAlign) || "left").toLowerCase();
|
|
5770
|
-
const alignmentAnchor = /right|end/.test(rawAlign) ? "end" : /center/.test(rawAlign) ? "middle" : "start";
|
|
5771
|
-
const hasStyledChars = (() => {
|
|
5772
|
-
const styles = obj == null ? void 0 : obj.styles;
|
|
5773
|
-
if (!styles || typeof styles !== "object") return false;
|
|
5774
|
-
return Object.values(styles).some((line) => line && typeof line === "object" && Object.keys(line).length > 0);
|
|
5775
|
-
})();
|
|
5776
|
-
const canUseAlignmentAnchor = alignmentAnchor !== "start" && !hasStyledChars && !(obj == null ? void 0 : obj.path) && !Number((obj == null ? void 0 : obj.charSpacing) ?? 0);
|
|
5777
|
-
const halfW = w / 2;
|
|
5778
|
-
const lineAnchors = [];
|
|
5779
|
-
for (let i = 0; i < lines.length; i++) {
|
|
5780
|
-
let lineLeft = 0;
|
|
5781
|
-
let lineW = 0;
|
|
5782
|
-
let firstGlyphAdjust = 0;
|
|
5783
|
-
try {
|
|
5784
|
-
lineLeft = ((_a = obj._getLineLeftOffset) == null ? void 0 : _a.call(obj, i)) ?? 0;
|
|
5785
|
-
} catch {
|
|
5786
|
-
lineLeft = 0;
|
|
5787
|
-
}
|
|
5788
|
-
try {
|
|
5789
|
-
lineW = ((_b = obj.getLineWidth) == null ? void 0 : _b.call(obj, i)) ?? 0;
|
|
5790
|
-
} catch {
|
|
5791
|
-
lineW = 0;
|
|
5792
|
-
}
|
|
5793
|
-
try {
|
|
5794
|
-
const firstBox = (_d = (_c = obj.__charBounds) == null ? void 0 : _c[i]) == null ? void 0 : _d[0];
|
|
5795
|
-
const kerned = Number(firstBox == null ? void 0 : firstBox.kernedWidth);
|
|
5796
|
-
const glyphW = Number(firstBox == null ? void 0 : firstBox.width);
|
|
5797
|
-
if (Number.isFinite(kerned) && Number.isFinite(glyphW)) {
|
|
5798
|
-
firstGlyphAdjust = kerned - glyphW;
|
|
5799
|
-
}
|
|
5800
|
-
} catch {
|
|
5801
|
-
firstGlyphAdjust = 0;
|
|
5802
|
-
}
|
|
5803
|
-
const baseStart = -halfW + (Number.isFinite(lineLeft) ? lineLeft : 0);
|
|
5804
|
-
if (canUseAlignmentAnchor && Number.isFinite(lineW) && lineW > 0) {
|
|
5805
|
-
lineAnchors.push({
|
|
5806
|
-
x: alignmentAnchor === "end" ? baseStart + lineW : baseStart + lineW / 2,
|
|
5807
|
-
anchor: alignmentAnchor
|
|
5808
|
-
});
|
|
5809
|
-
} else {
|
|
5810
|
-
lineAnchors.push({
|
|
5811
|
-
x: baseStart + (Number.isFinite(firstGlyphAdjust) ? firstGlyphAdjust : 0),
|
|
5812
|
-
anchor: "start"
|
|
5813
|
-
});
|
|
5814
|
-
}
|
|
5815
|
-
}
|
|
5816
|
-
const textOpenRe = /<text\b([^>]*)>/i;
|
|
5817
|
-
const textOpenMatch = svg.match(textOpenRe);
|
|
5818
|
-
if (!textOpenMatch) return svg;
|
|
5819
|
-
let textAttrs = textOpenMatch[1];
|
|
5820
|
-
if (/\stext-anchor\s*=\s*"[^"]*"/i.test(textAttrs)) {
|
|
5821
|
-
textAttrs = textAttrs.replace(/\stext-anchor\s*=\s*"[^"]*"/i, ' text-anchor="start"');
|
|
5822
|
-
} else {
|
|
5823
|
-
textAttrs = ` text-anchor="start"${textAttrs}`;
|
|
5824
|
-
}
|
|
5825
|
-
textAttrs = textAttrs.replace(
|
|
5826
|
-
/(\sstyle=")([^"]*)(")/i,
|
|
5827
|
-
(_m, pre, val, post) => pre + val.replace(/text-align\s*:\s*[^;"']+;?/gi, "").trim() + post
|
|
5828
|
-
);
|
|
5829
|
-
const newTextOpen = `<text${textAttrs}>`;
|
|
5830
|
-
const stripAnchorAttrs = (attrs) => attrs.replace(/\s+text-anchor\s*=\s*"[^"]*"/gi, "").replace(
|
|
5831
|
-
/(\sstyle=")([^"]*)(")/i,
|
|
5832
|
-
(_m, pre, val, post) => pre + val.replace(/text-anchor\s*:\s*[^;"']+;?/gi, "").trim() + post
|
|
5833
|
-
);
|
|
5834
|
-
let lineIdx = 0;
|
|
5835
|
-
let lastY = "";
|
|
5836
|
-
const newSvg = svg.replace(textOpenMatch[0], newTextOpen).replace(
|
|
5837
|
-
/<tspan\b([^>]*?)\sx="([^"]*)"([^>]*)>/gi,
|
|
5838
|
-
(_m, pre, _oldX, post) => {
|
|
5839
|
-
const attrs = `${pre} ${post}`;
|
|
5840
|
-
const yMatch = attrs.match(/\sy\s*=\s*"([^"]*)"/i);
|
|
5841
|
-
const y = (yMatch == null ? void 0 : yMatch[1]) ?? "";
|
|
5842
|
-
const isLineStart = y !== "" ? y !== lastY : lineIdx < lineAnchors.length;
|
|
5843
|
-
if (!isLineStart) return _m;
|
|
5844
|
-
if (y !== "") lastY = y;
|
|
5845
|
-
const lineAnchor = lineAnchors[lineIdx];
|
|
5846
|
-
lineIdx += 1;
|
|
5847
|
-
if (!lineAnchor || typeof lineAnchor.x !== "number" || !Number.isFinite(lineAnchor.x)) return _m;
|
|
5848
|
-
const cleanPre = stripAnchorAttrs(pre);
|
|
5849
|
-
const cleanPost = stripAnchorAttrs(post);
|
|
5850
|
-
return `<tspan${cleanPre} x="${lineAnchor.x.toFixed(3)}" text-anchor="${lineAnchor.anchor}" data-pd-line-anchor="1"${cleanPost}>`;
|
|
5851
|
-
}
|
|
5852
|
-
);
|
|
5853
|
-
return newSvg;
|
|
5854
|
-
} catch {
|
|
5855
|
-
return svg;
|
|
5856
|
-
}
|
|
5857
|
-
}
|
|
5858
5763
|
function _recolorSvgFills(svg, color) {
|
|
5859
5764
|
const safe = escapeXmlAttr(color);
|
|
5860
5765
|
let out = svg.replace(
|
|
@@ -15955,93 +15860,6 @@ function PixldocsPreview(props) {
|
|
|
15955
15860
|
!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..." }) })
|
|
15956
15861
|
] });
|
|
15957
15862
|
}
|
|
15958
|
-
function isFabricTextLike(obj) {
|
|
15959
|
-
return !!obj && (obj.type === "textbox" || obj.type === "i-text" || obj.type === "text" || Array.isArray(obj._textLines) && typeof obj.getLineWidth === "function");
|
|
15960
|
-
}
|
|
15961
|
-
function bakeSelectableTextSvgToFabricLineStarts(svg, obj) {
|
|
15962
|
-
try {
|
|
15963
|
-
const rawAlign = String((obj == null ? void 0 : obj.textAlign) || "left").toLowerCase();
|
|
15964
|
-
if (!/center|right|end/.test(rawAlign)) return svg;
|
|
15965
|
-
const lines = (obj == null ? void 0 : obj._textLines) ?? [];
|
|
15966
|
-
const width = Number((obj == null ? void 0 : obj.width) ?? 0);
|
|
15967
|
-
if (!Array.isArray(lines) || lines.length === 0 || !Number.isFinite(width) || width <= 0) return svg;
|
|
15968
|
-
const halfW = width / 2;
|
|
15969
|
-
const lineStarts = lines.map((_line, i) => {
|
|
15970
|
-
var _a, _b, _c;
|
|
15971
|
-
let lineLeft = 0;
|
|
15972
|
-
let firstGlyphAdjust = 0;
|
|
15973
|
-
try {
|
|
15974
|
-
lineLeft = Number(((_a = obj._getLineLeftOffset) == null ? void 0 : _a.call(obj, i)) ?? 0);
|
|
15975
|
-
} catch {
|
|
15976
|
-
lineLeft = 0;
|
|
15977
|
-
}
|
|
15978
|
-
try {
|
|
15979
|
-
const firstBox = (_c = (_b = obj.__charBounds) == null ? void 0 : _b[i]) == null ? void 0 : _c[0];
|
|
15980
|
-
const kerned = Number(firstBox == null ? void 0 : firstBox.kernedWidth);
|
|
15981
|
-
const glyphW = Number(firstBox == null ? void 0 : firstBox.width);
|
|
15982
|
-
if (Number.isFinite(kerned) && Number.isFinite(glyphW)) firstGlyphAdjust = kerned - glyphW;
|
|
15983
|
-
} catch {
|
|
15984
|
-
firstGlyphAdjust = 0;
|
|
15985
|
-
}
|
|
15986
|
-
return -halfW + (Number.isFinite(lineLeft) ? lineLeft : 0) + (Number.isFinite(firstGlyphAdjust) ? firstGlyphAdjust : 0);
|
|
15987
|
-
});
|
|
15988
|
-
const stripAnchorAttrs = (attrs) => attrs.replace(/\s+text-anchor\s*=\s*"[^"]*"/gi, "").replace(/\s+data-pd-line-anchor\s*=\s*"[^"]*"/gi, "").replace(/(\sstyle=")([^"]*)(")/i, (_m, pre, val, post) => {
|
|
15989
|
-
const cleaned = val.replace(/text-anchor\s*:\s*[^;"']+;?/gi, "").replace(/text-align\s*:\s*[^;"']+;?/gi, "").trim();
|
|
15990
|
-
return cleaned ? `${pre}${cleaned}${post}` : "";
|
|
15991
|
-
});
|
|
15992
|
-
const textOpenMatch = svg.match(/<text\b([^>]*)>/i);
|
|
15993
|
-
if (!textOpenMatch) return svg;
|
|
15994
|
-
const textAttrs = stripAnchorAttrs(textOpenMatch[1]);
|
|
15995
|
-
let lineIdx = 0;
|
|
15996
|
-
let lastY = "";
|
|
15997
|
-
let replacedLine = false;
|
|
15998
|
-
const patched = svg.replace(textOpenMatch[0], `<text text-anchor="start"${textAttrs}>`).replace(
|
|
15999
|
-
/<tspan\b([^>]*?)\sx="([^"]*)"([^>]*)>/gi,
|
|
16000
|
-
(match, pre, _oldX, post) => {
|
|
16001
|
-
const attrs = `${pre} ${post}`;
|
|
16002
|
-
const yMatch = attrs.match(/\sy\s*=\s*"([^"]*)"/i);
|
|
16003
|
-
const y = (yMatch == null ? void 0 : yMatch[1]) ?? "";
|
|
16004
|
-
const isLineStart = y !== "" ? y !== lastY : lineIdx < lineStarts.length;
|
|
16005
|
-
if (!isLineStart) return match;
|
|
16006
|
-
if (y !== "") lastY = y;
|
|
16007
|
-
const x2 = lineStarts[lineIdx++];
|
|
16008
|
-
if (!Number.isFinite(x2)) return match;
|
|
16009
|
-
replacedLine = true;
|
|
16010
|
-
return `<tspan${stripAnchorAttrs(pre)} x="${x2.toFixed(3)}" text-anchor="start" data-pd-line-anchor="1"${stripAnchorAttrs(post)}>`;
|
|
16011
|
-
}
|
|
16012
|
-
);
|
|
16013
|
-
if (replacedLine) return patched;
|
|
16014
|
-
const x = lineStarts[0];
|
|
16015
|
-
if (!Number.isFinite(x)) return patched;
|
|
16016
|
-
return patched.replace(/<text\b([^>]*)>/i, (_m, attrs) => {
|
|
16017
|
-
const clean = stripAnchorAttrs(attrs).replace(/\s+x\s*=\s*"[^"]*"/i, "");
|
|
16018
|
-
return `<text x="${x.toFixed(3)}" text-anchor="start" data-pd-line-anchor="1"${clean}>`;
|
|
16019
|
-
});
|
|
16020
|
-
} catch {
|
|
16021
|
-
return svg;
|
|
16022
|
-
}
|
|
16023
|
-
}
|
|
16024
|
-
function patchTextObjectsForSelectableSvg(fabricInstance) {
|
|
16025
|
-
var _a;
|
|
16026
|
-
const records = [];
|
|
16027
|
-
const visit = (obj) => {
|
|
16028
|
-
if (!obj || typeof obj !== "object") return;
|
|
16029
|
-
if (isFabricTextLike(obj) && typeof obj.toSVG === "function") {
|
|
16030
|
-
const original = obj.toSVG;
|
|
16031
|
-
obj.toSVG = function patchedSelectableTextToSVG(reviver) {
|
|
16032
|
-
return bakeSelectableTextSvgToFabricLineStarts(original.call(this, reviver), this);
|
|
16033
|
-
};
|
|
16034
|
-
records.push({ obj, toSVG: original });
|
|
16035
|
-
}
|
|
16036
|
-
const children = typeof obj.getObjects === "function" ? obj.getObjects() : obj._objects;
|
|
16037
|
-
if (Array.isArray(children)) children.forEach(visit);
|
|
16038
|
-
};
|
|
16039
|
-
try {
|
|
16040
|
-
(_a = fabricInstance == null ? void 0 : fabricInstance.getObjects) == null ? void 0 : _a.call(fabricInstance).forEach(visit);
|
|
16041
|
-
} catch {
|
|
16042
|
-
}
|
|
16043
|
-
return records;
|
|
16044
|
-
}
|
|
16045
15863
|
function normalizeSvgDimensions(svg, targetWidth, targetHeight) {
|
|
16046
15864
|
let normalized = svg;
|
|
16047
15865
|
if (/\bwidth="[^"]*"/i.test(normalized)) {
|
|
@@ -16095,7 +15913,6 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
|
|
|
16095
15913
|
} catch {
|
|
16096
15914
|
}
|
|
16097
15915
|
const fadeBakeRecords = [];
|
|
16098
|
-
const textSvgPatchRecords = patchTextObjectsForSelectableSvg(fabricInstance);
|
|
16099
15916
|
try {
|
|
16100
15917
|
const objs = fabricInstance.getObjects().slice();
|
|
16101
15918
|
for (const obj of objs) {
|
|
@@ -16144,12 +15961,6 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
|
|
|
16144
15961
|
const raw = fabricInstance.toSVG();
|
|
16145
15962
|
svgString = normalizeSvgDimensions(raw, canvasWidth, canvasHeight);
|
|
16146
15963
|
} finally {
|
|
16147
|
-
for (const rec of textSvgPatchRecords) {
|
|
16148
|
-
try {
|
|
16149
|
-
rec.obj.toSVG = rec.toSVG;
|
|
16150
|
-
} catch {
|
|
16151
|
-
}
|
|
16152
|
-
}
|
|
16153
15964
|
for (const rec of fadeBakeRecords) {
|
|
16154
15965
|
try {
|
|
16155
15966
|
fabricInstance.remove(rec.replacement);
|
|
@@ -16170,9 +15981,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
|
|
|
16170
15981
|
}
|
|
16171
15982
|
return svgString;
|
|
16172
15983
|
}
|
|
16173
|
-
const resolvedPackageVersion = "0.5.
|
|
15984
|
+
const resolvedPackageVersion = "0.5.161";
|
|
16174
15985
|
const PACKAGE_VERSION = resolvedPackageVersion;
|
|
16175
|
-
const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.
|
|
15986
|
+
const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.161";
|
|
16176
15987
|
const roundParityValue = (value) => {
|
|
16177
15988
|
if (typeof value !== "number") return value;
|
|
16178
15989
|
return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
|
|
@@ -16607,7 +16418,7 @@ class PixldocsRenderer {
|
|
|
16607
16418
|
await this.waitForCanvasScene(container, cloned, i);
|
|
16608
16419
|
}
|
|
16609
16420
|
console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
|
|
16610
|
-
const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-
|
|
16421
|
+
const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-CqdQi3YK.cjs"));
|
|
16611
16422
|
const prepared = preparePagesForExport(
|
|
16612
16423
|
cloned.pages,
|
|
16613
16424
|
canvasWidth,
|
|
@@ -18709,7 +18520,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
|
|
|
18709
18520
|
if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
|
|
18710
18521
|
sanitizeSvgTreeForPdf(svgToDraw);
|
|
18711
18522
|
try {
|
|
18712
|
-
const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-
|
|
18523
|
+
const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-CqdQi3YK.cjs"));
|
|
18713
18524
|
try {
|
|
18714
18525
|
await logTextMeasurementDiagnostic(svgToDraw);
|
|
18715
18526
|
} catch {
|
|
@@ -19056,4 +18867,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
|
|
|
19056
18867
|
exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
|
|
19057
18868
|
exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
|
|
19058
18869
|
exports.warmTemplateFromForm = warmTemplateFromForm;
|
|
19059
|
-
//# sourceMappingURL=index-
|
|
18870
|
+
//# sourceMappingURL=index-OWSb_i03.cjs.map
|