@pixldocs/canvas-renderer 0.5.151 → 0.5.152

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.
@@ -5744,7 +5744,7 @@ function recolorSvgFills(svg, color) {
5744
5744
  return _recolorSvgFills(svg, color);
5745
5745
  }
5746
5746
  function bakeTextSvgToFabricLineStarts(svg, obj, w) {
5747
- var _a;
5747
+ var _a, _b, _c;
5748
5748
  try {
5749
5749
  const lines = (obj == null ? void 0 : obj._textLines) ?? [];
5750
5750
  if (!Array.isArray(lines) || lines.length === 0) return svg;
@@ -5752,12 +5752,25 @@ function bakeTextSvgToFabricLineStarts(svg, obj, w) {
5752
5752
  const lineXs = [];
5753
5753
  for (let i = 0; i < lines.length; i++) {
5754
5754
  let lineLeft = 0;
5755
+ let firstGlyphAdjust = 0;
5755
5756
  try {
5756
5757
  lineLeft = ((_a = obj._getLineLeftOffset) == null ? void 0 : _a.call(obj, i)) ?? 0;
5757
5758
  } catch {
5758
5759
  lineLeft = 0;
5759
5760
  }
5760
- lineXs.push(-halfW + (Number.isFinite(lineLeft) ? lineLeft : 0));
5761
+ try {
5762
+ const firstBox = (_c = (_b = obj.__charBounds) == null ? void 0 : _b[i]) == null ? void 0 : _c[0];
5763
+ const kerned = Number(firstBox == null ? void 0 : firstBox.kernedWidth);
5764
+ const glyphW = Number(firstBox == null ? void 0 : firstBox.width);
5765
+ if (Number.isFinite(kerned) && Number.isFinite(glyphW)) {
5766
+ firstGlyphAdjust = kerned - glyphW;
5767
+ }
5768
+ } catch {
5769
+ firstGlyphAdjust = 0;
5770
+ }
5771
+ lineXs.push(
5772
+ -halfW + (Number.isFinite(lineLeft) ? lineLeft : 0) + (Number.isFinite(firstGlyphAdjust) ? firstGlyphAdjust : 0)
5773
+ );
5761
5774
  }
5762
5775
  const textOpenRe = /<text\b([^>]*)>/i;
5763
5776
  const textOpenMatch = svg.match(textOpenRe);
@@ -5774,9 +5787,16 @@ function bakeTextSvgToFabricLineStarts(svg, obj, w) {
5774
5787
  );
5775
5788
  const newTextOpen = `<text${textAttrs}>`;
5776
5789
  let lineIdx = 0;
5790
+ let lastY = "";
5777
5791
  const newSvg = svg.replace(textOpenMatch[0], newTextOpen).replace(
5778
5792
  /<tspan\b([^>]*?)\sx="([^"]*)"([^>]*)>/gi,
5779
5793
  (_m, pre, _oldX, post) => {
5794
+ const attrs = `${pre} ${post}`;
5795
+ const yMatch = attrs.match(/\sy\s*=\s*"([^"]*)"/i);
5796
+ const y = (yMatch == null ? void 0 : yMatch[1]) ?? "";
5797
+ const isLineStart = y !== "" ? y !== lastY : lineIdx < lineXs.length;
5798
+ if (!isLineStart) return _m;
5799
+ if (y !== "") lastY = y;
5780
5800
  const x = lineXs[lineIdx];
5781
5801
  lineIdx += 1;
5782
5802
  if (typeof x !== "number" || !Number.isFinite(x)) return _m;
@@ -16009,9 +16029,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
16009
16029
  }
16010
16030
  return svgString;
16011
16031
  }
16012
- const resolvedPackageVersion = "0.5.151";
16032
+ const resolvedPackageVersion = "0.5.152";
16013
16033
  const PACKAGE_VERSION = resolvedPackageVersion;
16014
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.151";
16034
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.152";
16015
16035
  const roundParityValue = (value) => {
16016
16036
  if (typeof value !== "number") return value;
16017
16037
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -16446,7 +16466,7 @@ class PixldocsRenderer {
16446
16466
  await this.waitForCanvasScene(container, cloned, i);
16447
16467
  }
16448
16468
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
16449
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-TF3IGImZ.js");
16469
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-RiNowoiG.js");
16450
16470
  const prepared = preparePagesForExport(
16451
16471
  cloned.pages,
16452
16472
  canvasWidth,
@@ -18548,7 +18568,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
18548
18568
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
18549
18569
  sanitizeSvgTreeForPdf(svgToDraw);
18550
18570
  try {
18551
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-TF3IGImZ.js");
18571
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-RiNowoiG.js");
18552
18572
  try {
18553
18573
  await logTextMeasurementDiagnostic(svgToDraw);
18554
18574
  } catch {
@@ -18898,4 +18918,4 @@ export {
18898
18918
  collectFontDescriptorsFromConfig as y,
18899
18919
  collectFontsFromConfig as z
18900
18920
  };
18901
- //# sourceMappingURL=index-Dp8yJxTW.js.map
18921
+ //# sourceMappingURL=index-DjobDQ7X.js.map