@pixldocs/canvas-renderer 0.5.55 → 0.5.56

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.d.ts CHANGED
@@ -578,6 +578,14 @@ export declare function rewriteSvgFontsForJsPDF(svgStr: string): string;
578
578
 
579
579
  export { SectionFormState }
580
580
 
581
+ /**
582
+ * Enable verbose console logs for the auto-shrink loop in the live preview.
583
+ * Logs target width, measured line widths, font availability, and the chosen
584
+ * fontSize for each text element with `overflowPolicy: 'auto-shrink'`.
585
+ * Disabled by default — call once from the host app when debugging.
586
+ */
587
+ export declare function setAutoShrinkDebug(enabled: boolean): void;
588
+
581
589
  export { setBundledAssetPrefixes }
582
590
 
583
591
  export { SmartElementProps }
package/dist/index.js CHANGED
@@ -5270,6 +5270,10 @@ function createText(element) {
5270
5270
  const splitByGrapheme = overflowPolicy === "auto-shrink" ? false : element.splitByGrapheme ?? element.wordWrap === "break-word";
5271
5271
  if (overflowPolicy === "auto-shrink") {
5272
5272
  const explicitLineCount = Math.max(1, text.split("\n").length);
5273
+ const debugAutoShrink = typeof window !== "undefined" && window.__pixldocsDebugAutoShrink === true;
5274
+ const startFontSize = fontSize;
5275
+ let breakReason = "min-font-size-reached";
5276
+ let lastIter = null;
5273
5277
  while (fontSize > 1) {
5274
5278
  const testTextbox = new fabric.Textbox(text, {
5275
5279
  width: fixedWidth,
@@ -5291,11 +5295,47 @@ function createText(element) {
5291
5295
  const lineWidths = testTextbox.__lineWidths;
5292
5296
  const maxLineWidth = lineWidths && lineWidths.length > 0 ? Math.max(...lineWidths) : 0;
5293
5297
  const fitsWidth = !widthDidGrow && maxLineWidth <= fixedWidth + 1;
5298
+ if (debugAutoShrink) {
5299
+ lastIter = {
5300
+ fontSize,
5301
+ renderedLineCount,
5302
+ explicitLineCount,
5303
+ textHeight,
5304
+ maxLineWidth,
5305
+ fixedWidth,
5306
+ widthDidGrow,
5307
+ hasNoImplicitWrap,
5308
+ fitsHeight,
5309
+ fitsWidth
5310
+ };
5311
+ }
5294
5312
  if (hasNoImplicitWrap && fitsHeight && fitsWidth) {
5313
+ breakReason = "fits";
5295
5314
  break;
5296
5315
  }
5297
5316
  fontSize--;
5298
5317
  }
5318
+ if (debugAutoShrink) {
5319
+ console.log("[auto-shrink][diag]", {
5320
+ id: element.id,
5321
+ name: element.name,
5322
+ text,
5323
+ fontFamily: element.fontFamily,
5324
+ fontWeight: element.fontWeight,
5325
+ elementWidth: element.width,
5326
+ elementHeight: element.height,
5327
+ scaleX: element.scaleX ?? 1,
5328
+ scaleY: element.scaleY ?? 1,
5329
+ fixedWidth,
5330
+ baseHeight,
5331
+ startFontSize,
5332
+ finalFontSize: fontSize,
5333
+ breakReason,
5334
+ lastIter,
5335
+ fontCheckRegular: typeof document !== "undefined" && document.fonts ? document.fonts.check(`16px "${element.fontFamily || "Open Sans"}"`) : null,
5336
+ fontCheckBold: typeof document !== "undefined" && document.fonts ? document.fonts.check(`bold 16px "${element.fontFamily || "Open Sans"}"`) : null
5337
+ });
5338
+ }
5299
5339
  }
5300
5340
  if (overflowPolicy === "max-lines-ellipsis") {
5301
5341
  const originalText = element.text || "Text";
@@ -15461,6 +15501,11 @@ async function warmTemplateFromForm(options) {
15461
15501
  if (signal == null ? void 0 : signal.aborted) return;
15462
15502
  await warmResolvedTemplateForPreview(resolved.config, { signal, imageProxyUrl });
15463
15503
  }
15504
+ function setAutoShrinkDebug(enabled) {
15505
+ if (typeof window !== "undefined") {
15506
+ window.__pixldocsDebugAutoShrink = !!enabled;
15507
+ }
15508
+ }
15464
15509
  export {
15465
15510
  FONT_FALLBACK_DEVANAGARI,
15466
15511
  FONT_FALLBACK_SYMBOLS,
@@ -15489,6 +15534,7 @@ export {
15489
15534
  resolveFromForm,
15490
15535
  resolveTemplateData,
15491
15536
  rewriteSvgFontsForJsPDF,
15537
+ setAutoShrinkDebug,
15492
15538
  setBundledAssetPrefixes,
15493
15539
  warmResolvedTemplateForPreview,
15494
15540
  warmTemplateFromForm