@pixldocs/canvas-renderer 0.5.10 → 0.5.12

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
@@ -11842,10 +11842,12 @@ function PixldocsPreview(props) {
11842
11842
  const [isLoading, setIsLoading] = react.useState(false);
11843
11843
  const [fontsReady, setFontsReady] = react.useState(false);
11844
11844
  const [fontsReadyVersion, setFontsReadyVersion] = react.useState(0);
11845
+ const [canvasSettled, setCanvasSettled] = react.useState(false);
11845
11846
  const isResolveMode = !("config" in props && props.config);
11846
11847
  react.useEffect(() => {
11847
11848
  if (!isResolveMode) {
11848
11849
  setResolvedConfig(null);
11850
+ setCanvasSettled(false);
11849
11851
  return;
11850
11852
  }
11851
11853
  const p = props;
@@ -11853,6 +11855,7 @@ function PixldocsPreview(props) {
11853
11855
  let cancelled = false;
11854
11856
  setIsLoading(true);
11855
11857
  setFontsReady(false);
11858
+ setCanvasSettled(false);
11856
11859
  resolveFromForm({
11857
11860
  templateId: p.templateId,
11858
11861
  formSchemaId: p.formSchemaId,
@@ -11897,6 +11900,7 @@ function PixldocsPreview(props) {
11897
11900
  var _a, _b;
11898
11901
  if (!config) return;
11899
11902
  let cancelled = false;
11903
+ setCanvasSettled(false);
11900
11904
  const bump = () => {
11901
11905
  if (cancelled) return;
11902
11906
  clearMeasurementCache();
@@ -11914,11 +11918,17 @@ function PixldocsPreview(props) {
11914
11918
  if (isResolveMode) return;
11915
11919
  if (!config) {
11916
11920
  setFontsReady(false);
11921
+ setCanvasSettled(false);
11917
11922
  return;
11918
11923
  }
11919
11924
  setFontsReady(false);
11925
+ setCanvasSettled(false);
11920
11926
  ensureFontsForResolvedConfig(config).then(() => setFontsReady(true)).catch(() => setFontsReady(true));
11921
11927
  }, [isResolveMode, config]);
11928
+ const handleCanvasReady = react.useCallback(() => {
11929
+ setCanvasSettled(true);
11930
+ onReady == null ? void 0 : onReady();
11931
+ }, [onReady]);
11922
11932
  if (isLoading) {
11923
11933
  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..." }) });
11924
11934
  }
@@ -11926,18 +11936,21 @@ function PixldocsPreview(props) {
11926
11936
  if (!fontsReady) {
11927
11937
  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..." }) });
11928
11938
  }
11929
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style, children: /* @__PURE__ */ jsxRuntime.jsx(
11930
- PreviewCanvas,
11931
- {
11932
- config,
11933
- pageIndex,
11934
- zoom,
11935
- absoluteZoom,
11936
- onDynamicFieldClick,
11937
- onReady
11938
- },
11939
- previewKey
11940
- ) });
11939
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, style: { ...style, position: "relative" }, children: [
11940
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { visibility: canvasSettled ? "visible" : "hidden" }, children: /* @__PURE__ */ jsxRuntime.jsx(
11941
+ PreviewCanvas,
11942
+ {
11943
+ config,
11944
+ pageIndex,
11945
+ zoom,
11946
+ absoluteZoom,
11947
+ onDynamicFieldClick,
11948
+ onReady: handleCanvasReady
11949
+ },
11950
+ previewKey
11951
+ ) }),
11952
+ !canvasSettled && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) })
11953
+ ] });
11941
11954
  }
11942
11955
  class PixldocsRenderer {
11943
11956
  constructor(config) {
@@ -12568,23 +12581,41 @@ class PixldocsRenderer {
12568
12581
  clearMeasurementCache();
12569
12582
  };
12570
12583
  const reflowTextboxes = () => {
12571
- var _a2, _b;
12584
+ var _a2, _b, _c;
12572
12585
  const walk = (obj) => {
12573
- var _a3, _b2;
12586
+ var _a3, _b2, _c2, _d;
12574
12587
  if (!obj) return;
12575
12588
  const children = Array.isArray(obj._objects) ? obj._objects : Array.isArray(obj.objects) ? obj.objects : [];
12576
12589
  if (children.length) children.forEach(walk);
12577
- if (typeof obj.initDimensions === "function" && (obj.type === "textbox" || obj.isEditing !== void 0)) {
12578
- const savedWidth = obj.width;
12590
+ const isTextObject = typeof obj.text === "string" && typeof obj.initDimensions === "function" && (obj.type === "textbox" || obj.type === "text" || obj.type === "i-text" || obj.isEditing !== void 0);
12591
+ if (isTextObject) {
12592
+ const saved = {
12593
+ width: obj.width,
12594
+ scaleX: obj.scaleX,
12595
+ scaleY: obj.scaleY
12596
+ };
12597
+ (_a3 = obj._clearCache) == null ? void 0 : _a3.call(obj);
12598
+ obj.__charBounds = [];
12599
+ obj.__lineWidths = [];
12600
+ obj.__lineHeights = [];
12601
+ obj._textLines = [];
12602
+ obj.textLines = [];
12579
12603
  obj.dirty = true;
12580
12604
  obj.initDimensions();
12581
- if (savedWidth != null) (_a3 = obj.set) == null ? void 0 : _a3.call(obj, { width: savedWidth });
12582
- (_b2 = obj.setCoords) == null ? void 0 : _b2.call(obj);
12605
+ (_b2 = obj.set) == null ? void 0 : _b2.call(obj, {
12606
+ width: saved.width,
12607
+ scaleX: saved.scaleX,
12608
+ scaleY: saved.scaleY,
12609
+ dirty: true
12610
+ });
12611
+ (_c2 = obj._clearCache) == null ? void 0 : _c2.call(obj);
12612
+ (_d = obj.setCoords) == null ? void 0 : _d.call(obj);
12583
12613
  }
12584
12614
  };
12585
12615
  fabricInstance.getObjects().forEach(walk);
12586
12616
  (_a2 = fabricInstance.calcOffset) == null ? void 0 : _a2.call(fabricInstance);
12587
- (_b = fabricInstance.requestRenderAll) == null ? void 0 : _b.call(fabricInstance);
12617
+ (_b = fabricInstance.renderAll) == null ? void 0 : _b.call(fabricInstance);
12618
+ (_c = fabricInstance.requestRenderAll) == null ? void 0 : _c.call(fabricInstance);
12588
12619
  };
12589
12620
  clearTextMetricCaches();
12590
12621
  await waitForPaint();