@pixldocs/canvas-renderer 0.5.11 → 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) {