@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.js CHANGED
@@ -11823,10 +11823,12 @@ function PixldocsPreview(props) {
11823
11823
  const [isLoading, setIsLoading] = useState(false);
11824
11824
  const [fontsReady, setFontsReady] = useState(false);
11825
11825
  const [fontsReadyVersion, setFontsReadyVersion] = useState(0);
11826
+ const [canvasSettled, setCanvasSettled] = useState(false);
11826
11827
  const isResolveMode = !("config" in props && props.config);
11827
11828
  useEffect(() => {
11828
11829
  if (!isResolveMode) {
11829
11830
  setResolvedConfig(null);
11831
+ setCanvasSettled(false);
11830
11832
  return;
11831
11833
  }
11832
11834
  const p = props;
@@ -11834,6 +11836,7 @@ function PixldocsPreview(props) {
11834
11836
  let cancelled = false;
11835
11837
  setIsLoading(true);
11836
11838
  setFontsReady(false);
11839
+ setCanvasSettled(false);
11837
11840
  resolveFromForm({
11838
11841
  templateId: p.templateId,
11839
11842
  formSchemaId: p.formSchemaId,
@@ -11878,6 +11881,7 @@ function PixldocsPreview(props) {
11878
11881
  var _a, _b;
11879
11882
  if (!config) return;
11880
11883
  let cancelled = false;
11884
+ setCanvasSettled(false);
11881
11885
  const bump = () => {
11882
11886
  if (cancelled) return;
11883
11887
  clearMeasurementCache();
@@ -11895,11 +11899,17 @@ function PixldocsPreview(props) {
11895
11899
  if (isResolveMode) return;
11896
11900
  if (!config) {
11897
11901
  setFontsReady(false);
11902
+ setCanvasSettled(false);
11898
11903
  return;
11899
11904
  }
11900
11905
  setFontsReady(false);
11906
+ setCanvasSettled(false);
11901
11907
  ensureFontsForResolvedConfig(config).then(() => setFontsReady(true)).catch(() => setFontsReady(true));
11902
11908
  }, [isResolveMode, config]);
11909
+ const handleCanvasReady = useCallback(() => {
11910
+ setCanvasSettled(true);
11911
+ onReady == null ? void 0 : onReady();
11912
+ }, [onReady]);
11903
11913
  if (isLoading) {
11904
11914
  return /* @__PURE__ */ jsx("div", { className, style: { ...style, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) });
11905
11915
  }
@@ -11907,18 +11917,21 @@ function PixldocsPreview(props) {
11907
11917
  if (!fontsReady) {
11908
11918
  return /* @__PURE__ */ jsx("div", { className, style: { ...style, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) });
11909
11919
  }
11910
- return /* @__PURE__ */ jsx("div", { className, style, children: /* @__PURE__ */ jsx(
11911
- PreviewCanvas,
11912
- {
11913
- config,
11914
- pageIndex,
11915
- zoom,
11916
- absoluteZoom,
11917
- onDynamicFieldClick,
11918
- onReady
11919
- },
11920
- previewKey
11921
- ) });
11920
+ return /* @__PURE__ */ jsxs("div", { className, style: { ...style, position: "relative" }, children: [
11921
+ /* @__PURE__ */ jsx("div", { style: { visibility: canvasSettled ? "visible" : "hidden" }, children: /* @__PURE__ */ jsx(
11922
+ PreviewCanvas,
11923
+ {
11924
+ config,
11925
+ pageIndex,
11926
+ zoom,
11927
+ absoluteZoom,
11928
+ onDynamicFieldClick,
11929
+ onReady: handleCanvasReady
11930
+ },
11931
+ previewKey
11932
+ ) }),
11933
+ !canvasSettled && /* @__PURE__ */ jsx("div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) })
11934
+ ] });
11922
11935
  }
11923
11936
  class PixldocsRenderer {
11924
11937
  constructor(config) {
@@ -12549,23 +12562,41 @@ class PixldocsRenderer {
12549
12562
  clearMeasurementCache();
12550
12563
  };
12551
12564
  const reflowTextboxes = () => {
12552
- var _a2, _b;
12565
+ var _a2, _b, _c;
12553
12566
  const walk = (obj) => {
12554
- var _a3, _b2;
12567
+ var _a3, _b2, _c2, _d;
12555
12568
  if (!obj) return;
12556
12569
  const children = Array.isArray(obj._objects) ? obj._objects : Array.isArray(obj.objects) ? obj.objects : [];
12557
12570
  if (children.length) children.forEach(walk);
12558
- if (typeof obj.initDimensions === "function" && (obj.type === "textbox" || obj.isEditing !== void 0)) {
12559
- const savedWidth = obj.width;
12571
+ const isTextObject = typeof obj.text === "string" && typeof obj.initDimensions === "function" && (obj.type === "textbox" || obj.type === "text" || obj.type === "i-text" || obj.isEditing !== void 0);
12572
+ if (isTextObject) {
12573
+ const saved = {
12574
+ width: obj.width,
12575
+ scaleX: obj.scaleX,
12576
+ scaleY: obj.scaleY
12577
+ };
12578
+ (_a3 = obj._clearCache) == null ? void 0 : _a3.call(obj);
12579
+ obj.__charBounds = [];
12580
+ obj.__lineWidths = [];
12581
+ obj.__lineHeights = [];
12582
+ obj._textLines = [];
12583
+ obj.textLines = [];
12560
12584
  obj.dirty = true;
12561
12585
  obj.initDimensions();
12562
- if (savedWidth != null) (_a3 = obj.set) == null ? void 0 : _a3.call(obj, { width: savedWidth });
12563
- (_b2 = obj.setCoords) == null ? void 0 : _b2.call(obj);
12586
+ (_b2 = obj.set) == null ? void 0 : _b2.call(obj, {
12587
+ width: saved.width,
12588
+ scaleX: saved.scaleX,
12589
+ scaleY: saved.scaleY,
12590
+ dirty: true
12591
+ });
12592
+ (_c2 = obj._clearCache) == null ? void 0 : _c2.call(obj);
12593
+ (_d = obj.setCoords) == null ? void 0 : _d.call(obj);
12564
12594
  }
12565
12595
  };
12566
12596
  fabricInstance.getObjects().forEach(walk);
12567
12597
  (_a2 = fabricInstance.calcOffset) == null ? void 0 : _a2.call(fabricInstance);
12568
- (_b = fabricInstance.requestRenderAll) == null ? void 0 : _b.call(fabricInstance);
12598
+ (_b = fabricInstance.renderAll) == null ? void 0 : _b.call(fabricInstance);
12599
+ (_c = fabricInstance.requestRenderAll) == null ? void 0 : _c.call(fabricInstance);
12569
12600
  };
12570
12601
  clearTextMetricCaches();
12571
12602
  await waitForPaint();