@pixldocs/canvas-renderer 0.5.174 → 0.5.176

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.
@@ -3206,8 +3206,8 @@ const clearFabricCharCache = () => {
3206
3206
  fabric.util.clearFabricFontCache();
3207
3207
  }
3208
3208
  };
3209
- const clearFontCacheAndRerender = (canvas) => {
3210
- clearFabricCharCache();
3209
+ const clearFontCacheAndRerender = (canvas, options = {}) => {
3210
+ if (options.clearGlobalCharCache !== false) clearFabricCharCache();
3211
3211
  const logUnderlineDebug = (stage, payload) => {
3212
3212
  try {
3213
3213
  console.log(`[canvas-renderer][underline-debug] ${stage} ${JSON.stringify(payload)}`);
@@ -3298,9 +3298,9 @@ const ensureFontLoaded = async (fontFamily) => {
3298
3298
  } catch {
3299
3299
  }
3300
3300
  };
3301
- const setupFontLoadingListener = (canvas, afterRerender) => {
3301
+ const setupFontLoadingListener = (canvas, afterRerender, options = {}) => {
3302
3302
  const handleFontLoad = () => {
3303
- clearFontCacheAndRerender(canvas);
3303
+ clearFontCacheAndRerender(canvas, options);
3304
3304
  afterRerender == null ? void 0 : afterRerender(canvas);
3305
3305
  };
3306
3306
  if (document.fonts) {
@@ -7360,6 +7360,7 @@ const PageCanvas = forwardRef(
7360
7360
  canvasUpdateVersion = 0,
7361
7361
  pageChildren,
7362
7362
  skipFontReadyWait = false,
7363
+ preserveGlobalFontCache = false,
7363
7364
  onReady
7364
7365
  }, ref) => {
7365
7366
  setMarkdownThemeColors({
@@ -7725,7 +7726,7 @@ const PageCanvas = forwardRef(
7725
7726
  await waitUntilFontsAvailable(fontFamilies, { timeoutMs: 3500, pollIntervalMs: 60 });
7726
7727
  await new Promise((r) => requestAnimationFrame(() => r()));
7727
7728
  }
7728
- clearFabricCharCache();
7729
+ if (!preserveGlobalFontCache) clearFabricCharCache();
7729
7730
  clearMeasurementCache();
7730
7731
  setReady(true);
7731
7732
  } catch (e) {
@@ -7764,7 +7765,11 @@ const PageCanvas = forwardRef(
7764
7765
  }
7765
7766
  });
7766
7767
  };
7767
- const fontCleanup = setupFontLoadingListener(fabricCanvas, persistTextDimensionsAfterFontLoad);
7768
+ const fontCleanup = setupFontLoadingListener(
7769
+ fabricCanvas,
7770
+ persistTextDimensionsAfterFontLoad,
7771
+ { clearGlobalCharCache: !preserveGlobalFontCache }
7772
+ );
7768
7773
  fabricCanvas.__fontCleanup = fontCleanup;
7769
7774
  fabricCanvas.__isUserTransforming = false;
7770
7775
  fabricCanvas.on("mouse:down", () => {
@@ -9764,7 +9769,7 @@ const PageCanvas = forwardRef(
9764
9769
  pendingSyncRef.current = false;
9765
9770
  if (ready && !hasClearedCachesBeforeFirstSyncRef.current) {
9766
9771
  hasClearedCachesBeforeFirstSyncRef.current = true;
9767
- clearFabricCharCache();
9772
+ if (!preserveGlobalFontCache) clearFabricCharCache();
9768
9773
  clearMeasurementCache();
9769
9774
  }
9770
9775
  doSyncRef.current();
@@ -9848,7 +9853,7 @@ const PageCanvas = forwardRef(
9848
9853
  const runReflowAndPersist = () => {
9849
9854
  const fc = fabricRef.current;
9850
9855
  if (!fc || cancelled) return;
9851
- clearFontCacheAndRerender(fc);
9856
+ clearFontCacheAndRerender(fc, { clearGlobalCharCache: !preserveGlobalFontCache });
9852
9857
  const state = useEditorStore.getState();
9853
9858
  const page = state.canvas.pages.find((p) => p.id === pageId);
9854
9859
  if (page) {
@@ -11425,6 +11430,7 @@ function PreviewCanvas({
11425
11430
  zoom = 1,
11426
11431
  absoluteZoom = false,
11427
11432
  skipFontReadyWait = false,
11433
+ preserveGlobalFontCache = false,
11428
11434
  pageIdOverride,
11429
11435
  className,
11430
11436
  onDynamicFieldClick,
@@ -11587,6 +11593,7 @@ function PreviewCanvas({
11587
11593
  activeTool: "select",
11588
11594
  mode: "preview",
11589
11595
  skipFontReadyWait,
11596
+ preserveGlobalFontCache,
11590
11597
  dynamicFieldIds,
11591
11598
  onDynamicFieldClick: handleDynamicFieldClick,
11592
11599
  onReady
@@ -16331,9 +16338,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
16331
16338
  }
16332
16339
  return svgString;
16333
16340
  }
16334
- const resolvedPackageVersion = "0.5.174";
16341
+ const resolvedPackageVersion = "0.5.176";
16335
16342
  const PACKAGE_VERSION = resolvedPackageVersion;
16336
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.174";
16343
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.176";
16337
16344
  const roundParityValue = (value) => {
16338
16345
  if (typeof value !== "number") return value;
16339
16346
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -16820,6 +16827,7 @@ class PixldocsRenderer {
16820
16827
  zoom: 1,
16821
16828
  absoluteZoom: true,
16822
16829
  skipFontReadyWait: false,
16830
+ preserveGlobalFontCache: true,
16823
16831
  onReady: () => {
16824
16832
  clearTimeout(timer);
16825
16833
  resolve();
@@ -16830,11 +16838,11 @@ class PixldocsRenderer {
16830
16838
  await this.waitForCanvasScene(container, cloned, i);
16831
16839
  const expected = this.getExpectedImageCount(cloned, i);
16832
16840
  await this.waitForCanvasImages(container, expected);
16833
- await this.waitForStableTextMetrics(container, cloned);
16841
+ await this.waitForStableTextMetrics(container, cloned, { clearGlobalCharCache: false });
16834
16842
  await this.waitForCanvasScene(container, cloned, i);
16835
16843
  }
16836
16844
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
16837
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-B4B0CPjW.js");
16845
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-CA6a-apV.js");
16838
16846
  const prepared = preparePagesForExport(
16839
16847
  cloned.pages,
16840
16848
  canvasWidth,
@@ -17217,6 +17225,7 @@ class PixldocsRenderer {
17217
17225
  zoom: pixelRatio,
17218
17226
  absoluteZoom: true,
17219
17227
  skipFontReadyWait: false,
17228
+ preserveGlobalFontCache: true,
17220
17229
  onReady: onReadyOnce
17221
17230
  })
17222
17231
  );
@@ -17277,6 +17286,7 @@ class PixldocsRenderer {
17277
17286
  zoom: pixelRatio,
17278
17287
  absoluteZoom: true,
17279
17288
  skipFontReadyWait: false,
17289
+ preserveGlobalFontCache: true,
17280
17290
  onReady
17281
17291
  })
17282
17292
  );
@@ -17328,6 +17338,7 @@ class PixldocsRenderer {
17328
17338
  zoom: 1,
17329
17339
  absoluteZoom: true,
17330
17340
  skipFontReadyWait: false,
17341
+ preserveGlobalFontCache: true,
17331
17342
  onReady: readyHandler
17332
17343
  })
17333
17344
  );
@@ -17473,7 +17484,7 @@ class PixldocsRenderer {
17473
17484
  (_a = fabricInstance == null ? void 0 : fabricInstance.getObjects) == null ? void 0 : _a.call(fabricInstance).forEach((obj) => visit(obj));
17474
17485
  logJsonLine("[canvas-renderer][fabric-text-parity]", { stage, textboxes: sample.length, sample });
17475
17486
  }
17476
- async waitForStableTextMetrics(container, config) {
17487
+ async waitForStableTextMetrics(container, config, options = {}) {
17477
17488
  var _a, _b, _c;
17478
17489
  if (typeof document !== "undefined") {
17479
17490
  void ensureFontsForResolvedConfig(config);
@@ -17508,9 +17519,11 @@ class PixldocsRenderer {
17508
17519
  obj.dirty = true;
17509
17520
  }
17510
17521
  };
17511
- try {
17512
- clearFabricCharCache();
17513
- } catch {
17522
+ if (options.clearGlobalCharCache !== false) {
17523
+ try {
17524
+ clearFabricCharCache();
17525
+ } catch {
17526
+ }
17514
17527
  }
17515
17528
  fabricInstance.getObjects().forEach(primeCharBounds);
17516
17529
  (_a = fabricInstance.calcOffset) == null ? void 0 : _a.call(fabricInstance);
@@ -18970,7 +18983,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
18970
18983
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
18971
18984
  sanitizeSvgTreeForPdf(svgToDraw);
18972
18985
  try {
18973
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-B4B0CPjW.js");
18986
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-CA6a-apV.js");
18974
18987
  try {
18975
18988
  await logTextMeasurementDiagnostic(svgToDraw);
18976
18989
  } catch {
@@ -19092,8 +19105,6 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
19092
19105
  drawPageBackground(pdf, i, page.width, page.height, page.backgroundColor, page.backgroundGradient);
19093
19106
  const shouldStripBg = stripPageBackground ?? hasGradient;
19094
19107
  const textMode = options.textMode ?? (options.outlineText === true ? "pixel-perfect" : "selectable");
19095
- const shouldOutlineText = textMode === "pixel-perfect" || textMode === "auto";
19096
- const outlineSubMode = textMode === "auto" ? "complex-only" : "all";
19097
19108
  let pageSvg = page.svg;
19098
19109
  try {
19099
19110
  pageSvg = await convertSvgTextDecorationsToLinesString(pageSvg);
@@ -19103,30 +19114,15 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
19103
19114
  underlineErr
19104
19115
  );
19105
19116
  }
19106
- if (shouldOutlineText) {
19107
- try {
19108
- const { convertAllTextToPath } = await import("./svgTextToPath-ra4EhtBL.js");
19109
- pageSvg = await convertAllTextToPath(pageSvg, fontBaseUrl, { mode: outlineSubMode });
19110
- try {
19111
- dumpSvgTextDiagnostics(pageSvg, i, PARITY_TAG, "STAGE-1b-after-text-to-path-raw");
19112
- } catch {
19113
- }
19114
- } catch (outlineErr) {
19115
- console.warn(
19116
- "[canvas-renderer][pdf] raw-stage text outlining unavailable, falling back to embedded SVG text:",
19117
- outlineErr
19118
- );
19119
- }
19120
- } else {
19117
+ try {
19118
+ const { prepareSvgTextForPdfMode } = await import("./svgTextToPath-BoT6H7Lz.js");
19119
+ pageSvg = await prepareSvgTextForPdfMode(pageSvg, textMode, fontBaseUrl);
19121
19120
  try {
19122
- const { replaceGradientTextFillsWithFirstStop } = await import("./svgTextToPath-ra4EhtBL.js");
19123
- pageSvg = replaceGradientTextFillsWithFirstStop(pageSvg);
19124
- } catch (gradErr) {
19125
- console.warn(
19126
- "[canvas-renderer][pdf] gradient-text fill resolution failed:",
19127
- gradErr
19128
- );
19121
+ dumpSvgTextDiagnostics(pageSvg, i, PARITY_TAG, "STAGE-1b-after-shared-text-prep");
19122
+ } catch {
19129
19123
  }
19124
+ } catch (textPrepErr) {
19125
+ console.warn("[canvas-renderer][pdf] shared text prep failed:", textPrepErr);
19130
19126
  }
19131
19127
  let processedSvg = await prepareLiveCanvasSvgForPdf(pageSvg, page.width, page.height, `page-${i + 1}`, {
19132
19128
  stripPageBackground: shouldStripBg
@@ -19383,4 +19379,4 @@ export {
19383
19379
  collectFontDescriptorsFromConfig as y,
19384
19380
  collectFontsFromConfig as z
19385
19381
  };
19386
- //# sourceMappingURL=index-DLAkGTqW.js.map
19382
+ //# sourceMappingURL=index-C03-L2j3.js.map