@pixldocs/canvas-renderer 0.5.26 → 0.5.28

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.cjs CHANGED
@@ -2590,6 +2590,10 @@ async function _doLoadGoogleFont(fontFamily, weights) {
2590
2590
  return false;
2591
2591
  }
2592
2592
  }
2593
+ const getObjectId = (obj) => obj.__docuforgeId;
2594
+ const setObjectData = (obj, id) => {
2595
+ obj.__docuforgeId = id;
2596
+ };
2593
2597
  const FONTS_TO_PRELOAD = [
2594
2598
  "Open Sans",
2595
2599
  "Playfair Display",
@@ -2729,6 +2733,35 @@ const clearFabricCharCache = () => {
2729
2733
  };
2730
2734
  const clearFontCacheAndRerender = (canvas) => {
2731
2735
  clearFabricCharCache();
2736
+ const collectUnderlineMetrics = (obj) => {
2737
+ var _a, _b;
2738
+ if (obj instanceof fabric__namespace.Textbox) {
2739
+ if (!obj.underline) return [];
2740
+ const lineWidths = obj.__lineWidths;
2741
+ return [{
2742
+ id: getObjectId(obj) ?? null,
2743
+ text: (obj.text || "").slice(0, 120),
2744
+ textLength: ((_a = obj.text) == null ? void 0 : _a.length) ?? 0,
2745
+ fontFamily: obj.fontFamily,
2746
+ fontSize: obj.fontSize,
2747
+ fontWeight: obj.fontWeight,
2748
+ width: obj.width ?? null,
2749
+ height: obj.height ?? null,
2750
+ scaleX: obj.scaleX,
2751
+ scaleY: obj.scaleY,
2752
+ lineCount: ((_b = obj.textLines) == null ? void 0 : _b.length) ?? 0,
2753
+ maxLineWidth: lineWidths && lineWidths.length > 0 ? Math.max(...lineWidths) : null
2754
+ }];
2755
+ }
2756
+ if (obj instanceof fabric__namespace.Group) {
2757
+ return (obj._objects || []).flatMap((child) => collectUnderlineMetrics(child));
2758
+ }
2759
+ return [];
2760
+ };
2761
+ const beforeMetrics = canvas.getObjects().flatMap(collectUnderlineMetrics);
2762
+ if (beforeMetrics.length > 0) {
2763
+ console.log("[canvas-renderer][underline-debug] before-rerender", beforeMetrics);
2764
+ }
2732
2765
  const resetTextboxLayoutInternals = (obj) => {
2733
2766
  var _a;
2734
2767
  (_a = obj._clearCache) == null ? void 0 : _a.call(obj);
@@ -2743,7 +2776,7 @@ const clearFontCacheAndRerender = (canvas) => {
2743
2776
  obj.dirty = true;
2744
2777
  };
2745
2778
  const fixTextbox = (obj) => {
2746
- var _a, _b;
2779
+ var _a, _b, _c;
2747
2780
  if (obj instanceof fabric__namespace.Textbox) {
2748
2781
  const savedWidth = obj.width;
2749
2782
  const savedScaleX = obj.scaleX;
@@ -2756,15 +2789,35 @@ const clearFontCacheAndRerender = (canvas) => {
2756
2789
  obj.initDimensions();
2757
2790
  obj.set({ width: savedWidth, scaleX: savedScaleX, scaleY: savedScaleY, dirty: true });
2758
2791
  }
2759
- (_a = obj._clearCache) == null ? void 0 : _a.call(obj);
2792
+ if (obj.underline) {
2793
+ const lineWidths = obj.__lineWidths;
2794
+ console.log("[canvas-renderer][underline-debug] textbox-rerender", {
2795
+ id: getObjectId(obj) ?? null,
2796
+ text: (obj.text || "").slice(0, 120),
2797
+ fontFamily: obj.fontFamily,
2798
+ fontSize: obj.fontSize,
2799
+ savedWidth,
2800
+ finalWidth: obj.width ?? null,
2801
+ finalHeight: obj.height ?? null,
2802
+ scaleX: obj.scaleX,
2803
+ scaleY: obj.scaleY,
2804
+ lineCount: ((_a = obj.textLines) == null ? void 0 : _a.length) ?? 0,
2805
+ maxLineWidth: lineWidths && lineWidths.length > 0 ? Math.max(...lineWidths) : null
2806
+ });
2807
+ }
2808
+ (_b = obj._clearCache) == null ? void 0 : _b.call(obj);
2760
2809
  obj.setCoords();
2761
2810
  } else if (obj instanceof fabric__namespace.Group) {
2762
- (_b = obj._objects) == null ? void 0 : _b.forEach(fixTextbox);
2811
+ (_c = obj._objects) == null ? void 0 : _c.forEach(fixTextbox);
2763
2812
  obj.dirty = true;
2764
2813
  obj.setCoords();
2765
2814
  }
2766
2815
  };
2767
2816
  canvas.getObjects().forEach(fixTextbox);
2817
+ const afterMetrics = canvas.getObjects().flatMap(collectUnderlineMetrics);
2818
+ if (afterMetrics.length > 0) {
2819
+ console.log("[canvas-renderer][underline-debug] after-rerender", afterMetrics);
2820
+ }
2768
2821
  canvas.requestRenderAll();
2769
2822
  };
2770
2823
  const ensureFontLoaded = async (fontFamily) => {
@@ -2802,10 +2855,6 @@ const setupFontLoadingListener = (canvas, afterRerender) => {
2802
2855
  };
2803
2856
  };
2804
2857
  preloadAllFonts();
2805
- const getObjectId = (obj) => obj.__docuforgeId;
2806
- const setObjectData = (obj, id) => {
2807
- obj.__docuforgeId = id;
2808
- };
2809
2858
  const svgTextCache = /* @__PURE__ */ new Map();
2810
2859
  const htmlImageCache = /* @__PURE__ */ new Map();
2811
2860
  const MAX_CACHE_ENTRIES = 200;
@@ -11863,6 +11912,21 @@ async function ensureFontsForResolvedConfig(config) {
11863
11912
  });
11864
11913
  }
11865
11914
  }
11915
+ const PREVIEW_DEBUG_PREFIX = "[canvas-renderer][preview-debug]";
11916
+ function countUnderlinedNodes(config) {
11917
+ var _a;
11918
+ if (!((_a = config == null ? void 0 : config.pages) == null ? void 0 : _a.length)) return 0;
11919
+ let count = 0;
11920
+ const walk = (nodes) => {
11921
+ var _a2;
11922
+ for (const node of nodes || []) {
11923
+ if (node == null ? void 0 : node.underline) count += 1;
11924
+ if ((_a2 = node == null ? void 0 : node.children) == null ? void 0 : _a2.length) walk(node.children);
11925
+ }
11926
+ };
11927
+ for (const page of config.pages) walk(page.children || []);
11928
+ return count;
11929
+ }
11866
11930
  function PixldocsPreview(props) {
11867
11931
  const {
11868
11932
  pageIndex = 0,
@@ -11890,6 +11954,7 @@ function PixldocsPreview(props) {
11890
11954
  if (!isResolveMode) {
11891
11955
  setResolvedConfig(null);
11892
11956
  setCanvasSettled(false);
11957
+ console.log(PREVIEW_DEBUG_PREFIX, "config-mode active");
11893
11958
  return;
11894
11959
  }
11895
11960
  const p = props;
@@ -11898,6 +11963,12 @@ function PixldocsPreview(props) {
11898
11963
  setIsLoading(true);
11899
11964
  setFontsReady(false);
11900
11965
  setCanvasSettled(false);
11966
+ console.log(PREVIEW_DEBUG_PREFIX, "resolve-start", {
11967
+ templateId: p.templateId,
11968
+ formSchemaId: p.formSchemaId,
11969
+ themeId: p.themeId ?? null,
11970
+ pageIndex
11971
+ });
11901
11972
  resolveFromForm({
11902
11973
  templateId: p.templateId,
11903
11974
  formSchemaId: p.formSchemaId,
@@ -11906,15 +11977,22 @@ function PixldocsPreview(props) {
11906
11977
  supabaseUrl: p.supabaseUrl,
11907
11978
  supabaseAnonKey: p.supabaseAnonKey
11908
11979
  }).then((resolved) => {
11980
+ var _a, _b;
11909
11981
  if (!cancelled) {
11982
+ console.log(PREVIEW_DEBUG_PREFIX, "resolve-done", {
11983
+ pages: ((_b = (_a = resolved.config) == null ? void 0 : _a.pages) == null ? void 0 : _b.length) ?? 0,
11984
+ underlinedNodes: countUnderlinedNodes(resolved.config)
11985
+ });
11910
11986
  setResolvedConfig(resolved.config);
11911
11987
  ensureFontsForResolvedConfig(resolved.config).then(() => {
11912
11988
  if (!cancelled) {
11989
+ console.log(PREVIEW_DEBUG_PREFIX, "resolve-mode fonts queued");
11913
11990
  setFontsReady(true);
11914
11991
  setIsLoading(false);
11915
11992
  }
11916
- }).catch(() => {
11993
+ }).catch((err) => {
11917
11994
  if (!cancelled) {
11995
+ console.warn(PREVIEW_DEBUG_PREFIX, "resolve-mode fonts queue failed", err);
11918
11996
  setFontsReady(true);
11919
11997
  setIsLoading(false);
11920
11998
  }
@@ -11923,6 +12001,7 @@ function PixldocsPreview(props) {
11923
12001
  }).catch((err) => {
11924
12002
  if (!cancelled) {
11925
12003
  setIsLoading(false);
12004
+ console.warn(PREVIEW_DEBUG_PREFIX, "resolve-error", err);
11926
12005
  onError == null ? void 0 : onError(err instanceof Error ? err : new Error(String(err)));
11927
12006
  }
11928
12007
  });
@@ -11939,17 +12018,28 @@ function PixldocsPreview(props) {
11939
12018
  ]);
11940
12019
  const config = isResolveMode ? resolvedConfig : props.config;
11941
12020
  react.useEffect(() => {
11942
- var _a, _b;
12021
+ var _a, _b, _c;
11943
12022
  if (!config) return;
11944
12023
  let cancelled = false;
11945
12024
  setCanvasSettled(false);
11946
12025
  setStabilizationPass(0);
12026
+ console.log(PREVIEW_DEBUG_PREFIX, "config-changed", {
12027
+ pageIndex,
12028
+ pages: ((_a = config.pages) == null ? void 0 : _a.length) ?? 0,
12029
+ underlinedNodes: countUnderlinedNodes(config),
12030
+ isResolveMode
12031
+ });
11947
12032
  const bump = () => {
11948
12033
  if (cancelled) return;
11949
12034
  clearMeasurementCache();
11950
- setFontsReadyVersion((v) => v + 1);
12035
+ clearFabricCharCache();
12036
+ setFontsReadyVersion((v) => {
12037
+ const next = v + 1;
12038
+ console.log(PREVIEW_DEBUG_PREFIX, "font-bump", { pageIndex, next, stabilizationPass });
12039
+ return next;
12040
+ });
11951
12041
  };
11952
- (_b = (_a = document.fonts) == null ? void 0 : _a.ready) == null ? void 0 : _b.then(bump);
12042
+ (_c = (_b = document.fonts) == null ? void 0 : _b.ready) == null ? void 0 : _c.then(bump);
11953
12043
  const timeoutId = window.setTimeout(bump, 350);
11954
12044
  return () => {
11955
12045
  cancelled = true;
@@ -11971,17 +12061,28 @@ function PixldocsPreview(props) {
11971
12061
  setFontsReady(false);
11972
12062
  setCanvasSettled(false);
11973
12063
  setStabilizationPass(0);
11974
- ensureFontsForResolvedConfig(config).then(() => setFontsReady(true)).catch(() => setFontsReady(true));
12064
+ ensureFontsForResolvedConfig(config).then(() => {
12065
+ console.log(PREVIEW_DEBUG_PREFIX, "config-mode fonts queued", {
12066
+ pageIndex,
12067
+ underlinedNodes: countUnderlinedNodes(config)
12068
+ });
12069
+ setFontsReady(true);
12070
+ }).catch((err) => {
12071
+ console.warn(PREVIEW_DEBUG_PREFIX, "config-mode fonts queue failed", err);
12072
+ setFontsReady(true);
12073
+ });
11975
12074
  }, [isResolveMode, config]);
11976
12075
  const handleCanvasReady = react.useCallback(() => {
11977
12076
  if (stabilizationPass === 0) {
12077
+ console.log(PREVIEW_DEBUG_PREFIX, "canvas-ready-pass", { pageIndex, stabilizationPass, action: "stabilize-again" });
11978
12078
  setCanvasSettled(false);
11979
12079
  setStabilizationPass(1);
11980
12080
  return;
11981
12081
  }
12082
+ console.log(PREVIEW_DEBUG_PREFIX, "canvas-ready-pass", { pageIndex, stabilizationPass, action: "settled" });
11982
12083
  setCanvasSettled(true);
11983
12084
  onReady == null ? void 0 : onReady();
11984
- }, [onReady, stabilizationPass]);
12085
+ }, [onReady, pageIndex, stabilizationPass]);
11985
12086
  if (isLoading) {
11986
12087
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style: { ...style, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) });
11987
12088
  }