@pixldocs/canvas-renderer 0.5.13 → 0.5.14

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
@@ -11862,6 +11862,7 @@ function PixldocsPreview(props) {
11862
11862
  const [fontsReady, setFontsReady] = react.useState(false);
11863
11863
  const [fontsReadyVersion, setFontsReadyVersion] = react.useState(0);
11864
11864
  const [canvasSettled, setCanvasSettled] = react.useState(false);
11865
+ const [stabilizationPass, setStabilizationPass] = react.useState(0);
11865
11866
  const isResolveMode = !("config" in props && props.config);
11866
11867
  react.useEffect(() => {
11867
11868
  if (!isResolveMode) {
@@ -11920,6 +11921,7 @@ function PixldocsPreview(props) {
11920
11921
  if (!config) return;
11921
11922
  let cancelled = false;
11922
11923
  setCanvasSettled(false);
11924
+ setStabilizationPass(0);
11923
11925
  const bump = () => {
11924
11926
  if (cancelled) return;
11925
11927
  clearMeasurementCache();
@@ -11932,22 +11934,32 @@ function PixldocsPreview(props) {
11932
11934
  window.clearTimeout(timeoutId);
11933
11935
  };
11934
11936
  }, [config]);
11935
- const previewKey = react.useMemo(() => `${pageIndex}-${fontsReadyVersion}`, [pageIndex, fontsReadyVersion]);
11937
+ const previewKey = react.useMemo(
11938
+ () => `${pageIndex}-${fontsReadyVersion}-${stabilizationPass}`,
11939
+ [pageIndex, fontsReadyVersion, stabilizationPass]
11940
+ );
11936
11941
  react.useEffect(() => {
11937
11942
  if (isResolveMode) return;
11938
11943
  if (!config) {
11939
11944
  setFontsReady(false);
11940
11945
  setCanvasSettled(false);
11946
+ setStabilizationPass(0);
11941
11947
  return;
11942
11948
  }
11943
11949
  setFontsReady(false);
11944
11950
  setCanvasSettled(false);
11951
+ setStabilizationPass(0);
11945
11952
  ensureFontsForResolvedConfig(config).then(() => setFontsReady(true)).catch(() => setFontsReady(true));
11946
11953
  }, [isResolveMode, config]);
11947
11954
  const handleCanvasReady = react.useCallback(() => {
11955
+ if (stabilizationPass === 0) {
11956
+ setCanvasSettled(false);
11957
+ setStabilizationPass(1);
11958
+ return;
11959
+ }
11948
11960
  setCanvasSettled(true);
11949
11961
  onReady == null ? void 0 : onReady();
11950
- }, [onReady]);
11962
+ }, [onReady, stabilizationPass]);
11951
11963
  if (isLoading) {
11952
11964
  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..." }) });
11953
11965
  }
@@ -12361,6 +12373,7 @@ class PixldocsRenderer {
12361
12373
  cleanup();
12362
12374
  reject(new Error("Render timeout (30s)"));
12363
12375
  }, 3e4);
12376
+ let stabilizationPass = 0;
12364
12377
  const cleanup = () => {
12365
12378
  clearTimeout(timeout);
12366
12379
  try {
@@ -12370,6 +12383,19 @@ class PixldocsRenderer {
12370
12383
  container.remove();
12371
12384
  };
12372
12385
  const onReady = () => {
12386
+ if (stabilizationPass === 0) {
12387
+ stabilizationPass = 1;
12388
+ root.render(
12389
+ react.createElement(PreviewCanvas2, {
12390
+ config,
12391
+ pageIndex,
12392
+ zoom: pixelRatio,
12393
+ absoluteZoom: true,
12394
+ onReady
12395
+ })
12396
+ );
12397
+ return;
12398
+ }
12373
12399
  const expectedImageCount = this.getExpectedImageCount(config, pageIndex);
12374
12400
  this.waitForCanvasImages(container, expectedImageCount).then(async () => {
12375
12401
  try {
@@ -12441,6 +12467,7 @@ class PixldocsRenderer {
12441
12467
  cleanup();
12442
12468
  reject(new Error("SVG render timeout (30s)"));
12443
12469
  }, 3e4);
12470
+ let stabilizationPass = 0;
12444
12471
  const cleanup = () => {
12445
12472
  clearTimeout(timeout);
12446
12473
  try {
@@ -12450,6 +12477,19 @@ class PixldocsRenderer {
12450
12477
  container.remove();
12451
12478
  };
12452
12479
  const onReady = () => {
12480
+ if (stabilizationPass === 0) {
12481
+ stabilizationPass = 1;
12482
+ root.render(
12483
+ react.createElement(PreviewCanvas2, {
12484
+ config,
12485
+ pageIndex,
12486
+ zoom: 1,
12487
+ absoluteZoom: true,
12488
+ onReady
12489
+ })
12490
+ );
12491
+ return;
12492
+ }
12453
12493
  const expectedImageCount = this.getExpectedImageCount(config, pageIndex);
12454
12494
  this.waitForCanvasImages(container, expectedImageCount).then(async () => {
12455
12495
  var _a, _b;