@pixldocs/canvas-renderer 0.5.62 → 0.5.63

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
@@ -12561,7 +12561,7 @@ function PixldocsPreview(props) {
12561
12561
  !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..." }) })
12562
12562
  ] });
12563
12563
  }
12564
- const PACKAGE_VERSION = "0.5.62";
12564
+ const PACKAGE_VERSION = "0.5.63";
12565
12565
  let __underlineFixInstalled = false;
12566
12566
  function installUnderlineFix(fab) {
12567
12567
  var _a;
@@ -13277,6 +13277,7 @@ class PixldocsRenderer {
13277
13277
  captureSvgViaPreviewCanvas(config, pageIndex, canvasWidth, canvasHeight) {
13278
13278
  return new Promise(async (resolve, reject) => {
13279
13279
  const { PreviewCanvas: PreviewCanvas2 } = await Promise.resolve().then(() => PreviewCanvas$1);
13280
+ const hasAutoShrink = configHasAutoShrinkText(config);
13280
13281
  const container = document.createElement("div");
13281
13282
  container.style.cssText = `
13282
13283
  position: fixed; left: -99999px; top: -99999px;
@@ -13288,28 +13289,74 @@ class PixldocsRenderer {
13288
13289
  cleanup();
13289
13290
  reject(new Error("SVG render timeout (30s)"));
13290
13291
  }, 3e4);
13292
+ let root = null;
13293
+ let mountKey = 0;
13294
+ let didAutoShrinkParityRemount = false;
13291
13295
  const cleanup = () => {
13292
13296
  clearTimeout(timeout);
13293
13297
  try {
13294
- root.unmount();
13298
+ root == null ? void 0 : root.unmount();
13295
13299
  } catch {
13296
13300
  }
13297
13301
  container.remove();
13298
13302
  };
13303
+ const remountForAutoShrinkParity = async () => {
13304
+ didAutoShrinkParityRemount = true;
13305
+ mountKey += 1;
13306
+ try {
13307
+ clearMeasurementCache();
13308
+ } catch {
13309
+ }
13310
+ try {
13311
+ clearFabricCharCache();
13312
+ } catch {
13313
+ }
13314
+ try {
13315
+ root == null ? void 0 : root.unmount();
13316
+ } catch {
13317
+ }
13318
+ root = client.createRoot(container);
13319
+ await new Promise((settle) => {
13320
+ const onReadyOnce = () => {
13321
+ this.waitForCanvasScene(container, config, pageIndex).then(async () => {
13322
+ const expectedImageCount = this.getExpectedImageCount(config, pageIndex);
13323
+ await this.waitForCanvasImages(container, expectedImageCount);
13324
+ await this.waitForStableTextMetrics(container, config);
13325
+ await this.waitForCanvasScene(container, config, pageIndex);
13326
+ settle();
13327
+ }).catch(() => settle());
13328
+ };
13329
+ root.render(
13330
+ react.createElement(PreviewCanvas2, {
13331
+ key: `svg-auto-shrink-remount-${mountKey}`,
13332
+ config,
13333
+ pageIndex,
13334
+ zoom: 1,
13335
+ absoluteZoom: true,
13336
+ skipFontReadyWait: false,
13337
+ onReady: onReadyOnce
13338
+ })
13339
+ );
13340
+ });
13341
+ };
13299
13342
  const onReady = () => {
13300
13343
  this.waitForCanvasScene(container, config, pageIndex).then(async () => {
13301
13344
  var _a, _b;
13302
13345
  try {
13346
+ const expectedImageCount = this.getExpectedImageCount(config, pageIndex);
13347
+ await this.waitForCanvasImages(container, expectedImageCount);
13348
+ await this.waitForStableTextMetrics(container, config);
13349
+ await this.waitForCanvasScene(container, config, pageIndex);
13350
+ if (hasAutoShrink && !didAutoShrinkParityRemount) {
13351
+ console.log("[canvas-renderer][svg-parity] remounting auto-shrink text before PDF SVG capture");
13352
+ await remountForAutoShrinkParity();
13353
+ }
13303
13354
  const fabricInstance = this.getFabricCanvasFromContainer(container);
13304
13355
  if (!fabricInstance) {
13305
13356
  cleanup();
13306
13357
  reject(new Error("No Fabric canvas instance found for SVG capture"));
13307
13358
  return;
13308
13359
  }
13309
- const expectedImageCount = this.getExpectedImageCount(config, pageIndex);
13310
- await this.waitForCanvasImages(container, expectedImageCount);
13311
- await this.waitForStableTextMetrics(container, config);
13312
- await this.waitForCanvasScene(container, config, pageIndex);
13313
13360
  const prevVPT = fabricInstance.viewportTransform ? [...fabricInstance.viewportTransform] : void 0;
13314
13361
  const prevSvgVPT = fabricInstance.svgViewportTransformation;
13315
13362
  const prevRetina = fabricInstance.enableRetinaScaling;
@@ -13353,7 +13400,7 @@ class PixldocsRenderer {
13353
13400
  }
13354
13401
  });
13355
13402
  };
13356
- const root = client.createRoot(container);
13403
+ root = client.createRoot(container);
13357
13404
  root.render(
13358
13405
  react.createElement(PreviewCanvas2, {
13359
13406
  config,