@pixldocs/canvas-renderer 0.5.152 → 0.5.154

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.
@@ -5762,14 +5762,23 @@ function recolorSvgFills(svg, color) {
5762
5762
  return _recolorSvgFills(svg, color);
5763
5763
  }
5764
5764
  function bakeTextSvgToFabricLineStarts(svg, obj, w) {
5765
- var _a, _b, _c;
5765
+ var _a, _b, _c, _d;
5766
5766
  try {
5767
5767
  const lines = (obj == null ? void 0 : obj._textLines) ?? [];
5768
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);
5769
5777
  const halfW = w / 2;
5770
- const lineXs = [];
5778
+ const lineAnchors = [];
5771
5779
  for (let i = 0; i < lines.length; i++) {
5772
5780
  let lineLeft = 0;
5781
+ let lineW = 0;
5773
5782
  let firstGlyphAdjust = 0;
5774
5783
  try {
5775
5784
  lineLeft = ((_a = obj._getLineLeftOffset) == null ? void 0 : _a.call(obj, i)) ?? 0;
@@ -5777,7 +5786,12 @@ function bakeTextSvgToFabricLineStarts(svg, obj, w) {
5777
5786
  lineLeft = 0;
5778
5787
  }
5779
5788
  try {
5780
- const firstBox = (_c = (_b = obj.__charBounds) == null ? void 0 : _b[i]) == null ? void 0 : _c[0];
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];
5781
5795
  const kerned = Number(firstBox == null ? void 0 : firstBox.kernedWidth);
5782
5796
  const glyphW = Number(firstBox == null ? void 0 : firstBox.width);
5783
5797
  if (Number.isFinite(kerned) && Number.isFinite(glyphW)) {
@@ -5786,9 +5800,18 @@ function bakeTextSvgToFabricLineStarts(svg, obj, w) {
5786
5800
  } catch {
5787
5801
  firstGlyphAdjust = 0;
5788
5802
  }
5789
- lineXs.push(
5790
- -halfW + (Number.isFinite(lineLeft) ? lineLeft : 0) + (Number.isFinite(firstGlyphAdjust) ? firstGlyphAdjust : 0)
5791
- );
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
+ }
5792
5815
  }
5793
5816
  const textOpenRe = /<text\b([^>]*)>/i;
5794
5817
  const textOpenMatch = svg.match(textOpenRe);
@@ -5804,6 +5827,10 @@ function bakeTextSvgToFabricLineStarts(svg, obj, w) {
5804
5827
  (_m, pre, val, post) => pre + val.replace(/text-align\s*:\s*[^;"']+;?/gi, "").trim() + post
5805
5828
  );
5806
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
+ );
5807
5834
  let lineIdx = 0;
5808
5835
  let lastY = "";
5809
5836
  const newSvg = svg.replace(textOpenMatch[0], newTextOpen).replace(
@@ -5812,13 +5839,15 @@ function bakeTextSvgToFabricLineStarts(svg, obj, w) {
5812
5839
  const attrs = `${pre} ${post}`;
5813
5840
  const yMatch = attrs.match(/\sy\s*=\s*"([^"]*)"/i);
5814
5841
  const y = (yMatch == null ? void 0 : yMatch[1]) ?? "";
5815
- const isLineStart = y !== "" ? y !== lastY : lineIdx < lineXs.length;
5842
+ const isLineStart = y !== "" ? y !== lastY : lineIdx < lineAnchors.length;
5816
5843
  if (!isLineStart) return _m;
5817
5844
  if (y !== "") lastY = y;
5818
- const x = lineXs[lineIdx];
5845
+ const lineAnchor = lineAnchors[lineIdx];
5819
5846
  lineIdx += 1;
5820
- if (typeof x !== "number" || !Number.isFinite(x)) return _m;
5821
- return `<tspan${pre} x="${x.toFixed(3)}"${post}>`;
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}>`;
5822
5851
  }
5823
5852
  );
5824
5853
  return newSvg;
@@ -16047,9 +16076,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
16047
16076
  }
16048
16077
  return svgString;
16049
16078
  }
16050
- const resolvedPackageVersion = "0.5.152";
16079
+ const resolvedPackageVersion = "0.5.154";
16051
16080
  const PACKAGE_VERSION = resolvedPackageVersion;
16052
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.152";
16081
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.154";
16053
16082
  const roundParityValue = (value) => {
16054
16083
  if (typeof value !== "number") return value;
16055
16084
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -16484,7 +16513,7 @@ class PixldocsRenderer {
16484
16513
  await this.waitForCanvasScene(container, cloned, i);
16485
16514
  }
16486
16515
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
16487
- const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-gHfbrQfT.cjs"));
16516
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-BHADcvGH.cjs"));
16488
16517
  const prepared = preparePagesForExport(
16489
16518
  cloned.pages,
16490
16519
  canvasWidth,
@@ -18586,7 +18615,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
18586
18615
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
18587
18616
  sanitizeSvgTreeForPdf(svgToDraw);
18588
18617
  try {
18589
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-gHfbrQfT.cjs"));
18618
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-BHADcvGH.cjs"));
18590
18619
  try {
18591
18620
  await logTextMeasurementDiagnostic(svgToDraw);
18592
18621
  } catch {
@@ -18721,7 +18750,7 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
18721
18750
  }
18722
18751
  if (shouldOutlineText) {
18723
18752
  try {
18724
- const { convertAllTextToPath } = await Promise.resolve().then(() => require("./svgTextToPath-qhinMiiS.cjs"));
18753
+ const { convertAllTextToPath } = await Promise.resolve().then(() => require("./svgTextToPath-IM1f6F-f.cjs"));
18725
18754
  pageSvg = await convertAllTextToPath(pageSvg, fontBaseUrl, { mode: outlineSubMode });
18726
18755
  try {
18727
18756
  dumpSvgTextDiagnostics(pageSvg, i, PARITY_TAG, "STAGE-1b-after-text-to-path-raw");
@@ -18933,4 +18962,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
18933
18962
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
18934
18963
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
18935
18964
  exports.warmTemplateFromForm = warmTemplateFromForm;
18936
- //# sourceMappingURL=index-CM_LXIKO.cjs.map
18965
+ //# sourceMappingURL=index-Cl1_1tTg.cjs.map