@pixldocs/canvas-renderer 0.5.488 → 0.5.489

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.
@@ -552,6 +552,7 @@ function getCacheKey(element) {
552
552
  });
553
553
  }
554
554
  function measureTextHeight(element) {
555
+ var _a2;
555
556
  if (element.type !== "text") {
556
557
  return element.height || 20;
557
558
  }
@@ -570,6 +571,7 @@ function measureTextHeight(element) {
570
571
  if (overflowPolicy === "auto-shrink") {
571
572
  const minBoxH = Math.max(0, Number(element.minBoxHeight) || 0);
572
573
  const baseHeight = typeof element.height === "number" ? Math.max(element.height, minBoxH) : minBoxH > 0 ? minBoxH : element.height;
574
+ const explicitLineCount = Math.max(1, textToMeasure.split("\n").length);
573
575
  while (fontSize > 1) {
574
576
  const testTb = new fabric__namespace.Textbox(textToMeasure, {
575
577
  width: measureWidth,
@@ -583,9 +585,11 @@ function measureTextHeight(element) {
583
585
  });
584
586
  testTb.initDimensions();
585
587
  const textHeight = testTb.height || 0;
588
+ const renderedLineCount = ((_a2 = testTb.textLines) == null ? void 0 : _a2.length) || 1;
589
+ const hasNoImplicitWrap = renderedLineCount <= explicitLineCount;
586
590
  const fitsHeight = !baseHeight || textHeight <= baseHeight;
587
591
  const { fitsWidth } = getTextboxWidthFitMetrics(testTb, measureWidth);
588
- if (fitsHeight && fitsWidth) break;
592
+ if (hasNoImplicitWrap && fitsHeight && fitsWidth) break;
589
593
  fontSize--;
590
594
  }
591
595
  const finalTb = new fabric__namespace.Textbox(textToMeasure, {
@@ -653,6 +657,7 @@ function clearMeasurementCache() {
653
657
  heightCache.clear();
654
658
  }
655
659
  function computeAutoShrinkFontSize(element) {
660
+ var _a2;
656
661
  const baseFontSize = element.fontSize || 16;
657
662
  if (element.overflowPolicy !== "auto-shrink") return baseFontSize;
658
663
  const text = element.text || element.content || "";
@@ -662,6 +667,7 @@ function computeAutoShrinkFontSize(element) {
662
667
  if (!height) return baseFontSize;
663
668
  let fontSize = baseFontSize;
664
669
  try {
670
+ const explicitLineCount = Math.max(1, text.split("\n").length);
665
671
  while (fontSize > 1) {
666
672
  const testTb = new fabric__namespace.Textbox(text, {
667
673
  width,
@@ -675,11 +681,13 @@ function computeAutoShrinkFontSize(element) {
675
681
  });
676
682
  testTb.initDimensions();
677
683
  const textHeight = testTb.height || 0;
684
+ const renderedLineCount = ((_a2 = testTb.textLines) == null ? void 0 : _a2.length) || 1;
685
+ const hasNoImplicitWrap = renderedLineCount <= explicitLineCount;
678
686
  const fitsHeight = textHeight <= height;
679
687
  const lineWidths = testTb.__lineWidths;
680
688
  const maxLineWidth = lineWidths && lineWidths.length > 0 ? Math.max(...lineWidths) : 0;
681
689
  const fitsWidth = maxLineWidth <= width + 1;
682
- if (fitsHeight && fitsWidth) break;
690
+ if (hasNoImplicitWrap && fitsHeight && fitsWidth) break;
683
691
  fontSize--;
684
692
  }
685
693
  } catch (e) {
@@ -9889,7 +9897,7 @@ function createText(element) {
9889
9897
  iterationSamples.push(lastIter);
9890
9898
  }
9891
9899
  }
9892
- if (fitsHeight && fitsWidth) {
9900
+ if (hasNoImplicitWrap && fitsHeight && fitsWidth) {
9893
9901
  breakReason = "fits";
9894
9902
  break;
9895
9903
  }
@@ -18604,7 +18612,7 @@ const PageCanvas = react.forwardRef(
18604
18612
  return unsub;
18605
18613
  }, []);
18606
18614
  const updateFabricObject = (obj, element, skipPositionUpdate = false) => {
18607
- var _a2, _b2, _c2;
18615
+ var _a2, _b2, _c2, _d;
18608
18616
  const fc = fabricRef.current;
18609
18617
  if (fc && isTransforming(fc)) {
18610
18618
  return;
@@ -18988,6 +18996,7 @@ const PageCanvas = react.forwardRef(
18988
18996
  const minBoxHForShrink = Math.max(0, Number(element.minBoxHeight) || 0);
18989
18997
  const elementHeight = typeof element.height === "number" ? element.height : 0;
18990
18998
  const heightBound = Math.max(elementHeight, minBoxHForShrink);
18999
+ const explicitLineCount = Math.max(1, text.split("\n").length);
18991
19000
  while (fontSize > 1) {
18992
19001
  const testTextbox = new fabric__namespace.Textbox(text, {
18993
19002
  width: fixedWidth,
@@ -18997,13 +19006,15 @@ const PageCanvas = react.forwardRef(
18997
19006
  fontStyle: element.fontStyle || "normal",
18998
19007
  lineHeight: element.lineHeight || 1.2,
18999
19008
  charSpacing: element.charSpacing || 0,
19000
- splitByGrapheme: element.splitByGrapheme ?? false
19009
+ splitByGrapheme: false
19001
19010
  });
19002
19011
  testTextbox.initDimensions();
19003
19012
  const textHeight = testTextbox.height || 0;
19013
+ const renderedLineCount = ((_c2 = testTextbox.textLines) == null ? void 0 : _c2.length) || 1;
19014
+ const hasNoImplicitWrap = renderedLineCount <= explicitLineCount;
19004
19015
  const fitsHeight = heightBound <= 0 || textHeight <= heightBound;
19005
19016
  const { fitsWidth } = getTextboxWidthFitMetrics(testTextbox, fixedWidth);
19006
- if (fitsHeight && fitsWidth) {
19017
+ if (hasNoImplicitWrap && fitsHeight && fitsWidth) {
19007
19018
  break;
19008
19019
  }
19009
19020
  fontSize--;
@@ -19124,7 +19135,7 @@ const PageCanvas = react.forwardRef(
19124
19135
  } catch {
19125
19136
  }
19126
19137
  obj.dirty = true;
19127
- (_c2 = obj.setCoords) == null ? void 0 : _c2.call(obj);
19138
+ (_d = obj.setCoords) == null ? void 0 : _d.call(obj);
19128
19139
  obj.__lastTextBgShadowJson = JSON.stringify({
19129
19140
  c: element.textBgColor ?? null,
19130
19141
  g: element.textBgGradient ?? null,
@@ -26441,9 +26452,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
26441
26452
  }
26442
26453
  return svgString;
26443
26454
  }
26444
- const resolvedPackageVersion = "0.5.488";
26455
+ const resolvedPackageVersion = "0.5.489";
26445
26456
  const PACKAGE_VERSION = resolvedPackageVersion;
26446
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.488";
26457
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.489";
26447
26458
  const roundParityValue = (value) => {
26448
26459
  if (typeof value !== "number") return value;
26449
26460
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -27257,7 +27268,7 @@ class PixldocsRenderer {
27257
27268
  await this.waitForCanvasScene(container, cloned, i);
27258
27269
  }
27259
27270
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
27260
- const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-CoHsXSrT.cjs"));
27271
+ const { exportMultiPagePdf, preparePagesForExport } = await Promise.resolve().then(() => require("./vectorPdfExport-c8OVQAkW.cjs"));
27261
27272
  const prepared = preparePagesForExport(
27262
27273
  cloned.pages,
27263
27274
  canvasWidth,
@@ -29577,7 +29588,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
29577
29588
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
29578
29589
  sanitizeSvgTreeForPdf(svgToDraw);
29579
29590
  try {
29580
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-CoHsXSrT.cjs"));
29591
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await Promise.resolve().then(() => require("./vectorPdfExport-c8OVQAkW.cjs"));
29581
29592
  try {
29582
29593
  await logTextMeasurementDiagnostic(svgToDraw);
29583
29594
  } catch {
@@ -29891,4 +29902,4 @@ exports.setAutoShrinkDebug = setAutoShrinkDebug;
29891
29902
  exports.setBundledAssetPrefixes = setBundledAssetPrefixes;
29892
29903
  exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
29893
29904
  exports.warmTemplateFromForm = warmTemplateFromForm;
29894
- //# sourceMappingURL=index-0K5eJY1O.cjs.map
29905
+ //# sourceMappingURL=index-SOZMTq-v.cjs.map