@pixldocs/canvas-renderer 0.5.196 → 0.5.197

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.
@@ -16919,9 +16919,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
16919
16919
  }
16920
16920
  return svgString;
16921
16921
  }
16922
- const resolvedPackageVersion = "0.5.196";
16922
+ const resolvedPackageVersion = "0.5.197";
16923
16923
  const PACKAGE_VERSION = resolvedPackageVersion;
16924
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.196";
16924
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.197";
16925
16925
  const roundParityValue = (value) => {
16926
16926
  if (typeof value !== "number") return value;
16927
16927
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -17006,19 +17006,41 @@ async function downscaleConfigRasterImages(config, maxEdgePx, maxDataUrlBytes =
17006
17006
  if (targets.length === 0) return 0;
17007
17007
  const shrinkOne = async (dataUrl) => {
17008
17008
  try {
17009
- const img = await new Promise((resolve, reject) => {
17009
+ const decode = async (src) => new Promise((resolve, reject) => {
17010
17010
  const el = new Image();
17011
17011
  el.onload = () => resolve(el);
17012
17012
  el.onerror = (e) => reject(e);
17013
17013
  el.decoding = "sync";
17014
- el.src = dataUrl;
17014
+ el.src = src;
17015
17015
  });
17016
+ let img;
17017
+ let blobUrl = null;
17018
+ try {
17019
+ img = await decode(dataUrl);
17020
+ } catch {
17021
+ try {
17022
+ const resp = await fetch(dataUrl);
17023
+ const blob = await resp.blob();
17024
+ blobUrl = URL.createObjectURL(blob);
17025
+ img = await decode(blobUrl);
17026
+ } catch (inner) {
17027
+ if (blobUrl) URL.revokeObjectURL(blobUrl);
17028
+ console.warn("[canvas-renderer] shrinkOne: failed to decode oversized data URL on this browser, dropping shrink attempt", inner);
17029
+ return null;
17030
+ }
17031
+ }
17016
17032
  const w = img.naturalWidth, h = img.naturalHeight;
17017
- if (!w || !h) return null;
17033
+ if (!w || !h) {
17034
+ if (blobUrl) URL.revokeObjectURL(blobUrl);
17035
+ return null;
17036
+ }
17018
17037
  const longest = Math.max(w, h);
17019
17038
  const tooLargeByEdge = longest > maxEdgePx;
17020
17039
  const tooLargeByBytes = estimateDataUrlBytes(dataUrl) > maxDataUrlBytes;
17021
- if (!tooLargeByEdge && !tooLargeByBytes) return null;
17040
+ if (!tooLargeByEdge && !tooLargeByBytes) {
17041
+ if (blobUrl) URL.revokeObjectURL(blobUrl);
17042
+ return null;
17043
+ }
17022
17044
  let scale = tooLargeByEdge ? maxEdgePx / longest : 1;
17023
17045
  let quality = 0.85;
17024
17046
  let best = null;
@@ -17029,17 +17051,24 @@ async function downscaleConfigRasterImages(config, maxEdgePx, maxDataUrlBytes =
17029
17051
  canvas.width = tw;
17030
17052
  canvas.height = th;
17031
17053
  const ctx = canvas.getContext("2d");
17032
- if (!ctx) return best;
17054
+ if (!ctx) {
17055
+ if (blobUrl) URL.revokeObjectURL(blobUrl);
17056
+ return best;
17057
+ }
17033
17058
  ctx.fillStyle = "#ffffff";
17034
17059
  ctx.fillRect(0, 0, tw, th);
17035
17060
  ctx.drawImage(img, 0, 0, tw, th);
17036
17061
  best = canvas.toDataURL("image/jpeg", quality);
17037
17062
  const outBytes = estimateDataUrlBytes(best);
17038
- if (outBytes <= maxDataUrlBytes || attempt === 3) return best;
17063
+ if (outBytes <= maxDataUrlBytes || attempt === 3) {
17064
+ if (blobUrl) URL.revokeObjectURL(blobUrl);
17065
+ return best;
17066
+ }
17039
17067
  const byteScale = Math.sqrt(maxDataUrlBytes / Math.max(1, outBytes)) * 0.92;
17040
17068
  scale = Math.max(0.1, scale * Math.min(0.95, byteScale));
17041
17069
  quality = Math.max(0.68, quality - 0.06);
17042
17070
  }
17071
+ if (blobUrl) URL.revokeObjectURL(blobUrl);
17043
17072
  return best;
17044
17073
  } catch {
17045
17074
  return null;
@@ -17568,7 +17597,7 @@ class PixldocsRenderer {
17568
17597
  await this.waitForCanvasScene(container, cloned, i);
17569
17598
  }
17570
17599
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
17571
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-BBQHeFKb.js");
17600
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-D4pUlnXw.js");
17572
17601
  const prepared = preparePagesForExport(
17573
17602
  cloned.pages,
17574
17603
  canvasWidth,
@@ -19765,7 +19794,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
19765
19794
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
19766
19795
  sanitizeSvgTreeForPdf(svgToDraw);
19767
19796
  try {
19768
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-BBQHeFKb.js");
19797
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-D4pUlnXw.js");
19769
19798
  try {
19770
19799
  await logTextMeasurementDiagnostic(svgToDraw);
19771
19800
  } catch {
@@ -20165,4 +20194,4 @@ export {
20165
20194
  buildTeaserBlurFlatKeys as y,
20166
20195
  collectFontDescriptorsFromConfig as z
20167
20196
  };
20168
- //# sourceMappingURL=index-KqyAyv91.js.map
20197
+ //# sourceMappingURL=index-6bqq7X_L.js.map