@pixldocs/canvas-renderer 0.5.145 → 0.5.146

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.
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jspdf = require("jspdf");
4
4
  const svg2pdf_js = require("svg2pdf.js");
5
5
  const fabric = require("fabric");
6
- const index = require("./index-DVjmPr0D.cjs");
6
+ const index = require("./index-DoPXmxDJ.cjs");
7
7
  const pdfFonts = require("./pdfFonts-BTEVnYX8.cjs");
8
8
  function _interopNamespaceDefault(e) {
9
9
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -142,6 +142,33 @@ const yieldToUI = () => new Promise((resolve) => {
142
142
  requestAnimationFrame(() => setTimeout(resolve, 0));
143
143
  });
144
144
  const SHADOW_RASTER_ALPHA_COMPENSATION = 0.84;
145
+ function collectFontSpecsFromShadowMarkup(markup) {
146
+ const specs = /* @__PURE__ */ new Set();
147
+ const re = /<(?:text|tspan)\b[^>]*>/gi;
148
+ let match;
149
+ while ((match = re.exec(markup)) !== null) {
150
+ const tag = match[0];
151
+ const get = (attr) => {
152
+ const m = tag.match(new RegExp(`\\s${attr}\\s*=\\s*"([^"]*)"`, "i"));
153
+ if (m) return m[1];
154
+ const styleM = tag.match(/\sstyle\s*=\s*"([^"]*)"/i);
155
+ if (styleM) {
156
+ const sm = styleM[1].match(new RegExp(`${attr}\\s*:\\s*([^;]+)`, "i"));
157
+ if (sm) return sm[1].trim();
158
+ }
159
+ return null;
160
+ };
161
+ const family = (get("font-family") || "").split(",")[0].replace(/['"]/g, "").trim();
162
+ if (!family) continue;
163
+ const weight = get("font-weight") || "400";
164
+ const style = get("font-style") || "normal";
165
+ const size = get("font-size") || "16px";
166
+ const sizePx = /[a-z%]/i.test(size) ? size : `${size}px`;
167
+ const famSpec = /\s/.test(family) ? `"${family}"` : family;
168
+ specs.add(`${style} ${weight} ${sizePx} ${famSpec}`);
169
+ }
170
+ return Array.from(specs);
171
+ }
145
172
  let debugSvgDrawSequence = 0;
146
173
  function debugLog(...args) {
147
174
  }
@@ -1522,7 +1549,7 @@ async function convertSvgTextDecorationsToLinesString(svgStr) {
1522
1549
  }
1523
1550
  }
1524
1551
  async function rasterizeShadowMarkers(svg) {
1525
- var _a, _b, _c, _d, _e;
1552
+ var _a, _b, _c, _d, _e, _f;
1526
1553
  if (typeof window === "undefined" || typeof document === "undefined") return;
1527
1554
  const markers = Array.from(svg.querySelectorAll("g.__pdShadowRaster"));
1528
1555
  if (markers.length === 0) return;
@@ -1549,6 +1576,17 @@ async function rasterizeShadowMarkers(svg) {
1549
1576
  const innerXml = restoreSourceFontsForShadowRaster(
1550
1577
  Array.from(marker.childNodes).map((n) => n instanceof Element ? new XMLSerializer().serializeToString(n) : "").join("")
1551
1578
  );
1579
+ try {
1580
+ const fontSpecs = collectFontSpecsFromShadowMarkup(innerXml);
1581
+ if (fontSpecs.length > 0 && ((_c = document.fonts) == null ? void 0 : _c.load)) {
1582
+ await Promise.all(
1583
+ fontSpecs.map(
1584
+ (spec) => document.fonts.load(spec).catch(() => void 0)
1585
+ )
1586
+ );
1587
+ }
1588
+ } catch {
1589
+ }
1552
1590
  const scale = 2;
1553
1591
  const pxW = Math.min(4096, Math.max(8, Math.ceil(bw * scale)));
1554
1592
  const pxH = Math.min(4096, Math.max(8, Math.ceil(bh * scale)));
@@ -1558,7 +1596,7 @@ async function rasterizeShadowMarkers(svg) {
1558
1596
  const miniSvg = `<svg xmlns="${SVG_NS}" xmlns:xlink="${XLINK_NS}" width="${pxW}" height="${pxH}" viewBox="${bx} ${by} ${bw} ${bh}">${styleBlock}<defs><filter id="${filterId}" filterUnits="userSpaceOnUse" x="${bx}" y="${by}" width="${bw}" height="${bh}" color-interpolation-filters="sRGB"><feOffset dx="${ox}" dy="${oy}" result="offsetShadow" /><feGaussianBlur in="offsetShadow" stdDeviation="${stdDev}" /></filter></defs><g filter="url(#${filterId})">${innerXml}</g></svg>`;
1559
1597
  const dataUrl = await rasterSvgToPngDataUrl(miniSvg, pxW, pxH);
1560
1598
  if (!dataUrl) {
1561
- (_c = marker.parentNode) == null ? void 0 : _c.removeChild(marker);
1599
+ (_d = marker.parentNode) == null ? void 0 : _d.removeChild(marker);
1562
1600
  continue;
1563
1601
  }
1564
1602
  const img = svg.ownerDocument.createElementNS(SVG_NS, "image");
@@ -1570,11 +1608,11 @@ async function rasterizeShadowMarkers(svg) {
1570
1608
  img.setAttribute("preserveAspectRatio", "none");
1571
1609
  img.setAttributeNS(XLINK_NS, "xlink:href", dataUrl);
1572
1610
  img.setAttribute("href", dataUrl);
1573
- (_d = marker.parentNode) == null ? void 0 : _d.replaceChild(img, marker);
1611
+ (_e = marker.parentNode) == null ? void 0 : _e.replaceChild(img, marker);
1574
1612
  } catch (error) {
1575
1613
  console.warn("[Vector PDF] text shadow rasterization failed for one marker:", error);
1576
1614
  try {
1577
- (_e = marker.parentNode) == null ? void 0 : _e.removeChild(marker);
1615
+ (_f = marker.parentNode) == null ? void 0 : _f.removeChild(marker);
1578
1616
  } catch {
1579
1617
  }
1580
1618
  }
@@ -2367,7 +2405,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
2367
2405
  async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
2368
2406
  if (!colorMap || Object.keys(colorMap).length === 0) return null;
2369
2407
  try {
2370
- const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-DVjmPr0D.cjs")).then((n) => n.canvasImageLoader);
2408
+ const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-DoPXmxDJ.cjs")).then((n) => n.canvasImageLoader);
2371
2409
  return await getNormalizedSvgUrl(imageUrl, colorMap);
2372
2410
  } catch {
2373
2411
  return null;
@@ -3148,7 +3186,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
3148
3186
  }
3149
3187
  let fetchUrl = imageUrl;
3150
3188
  if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
3151
- const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-DVjmPr0D.cjs")).then((n) => n.canvasImageLoader);
3189
+ const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-DoPXmxDJ.cjs")).then((n) => n.canvasImageLoader);
3152
3190
  if (isPrivateUrl(imageUrl)) return null;
3153
3191
  const proxyUrl = new URL(`${index.API_URL}/image-proxy`);
3154
3192
  proxyUrl.searchParams.set("url", imageUrl);
@@ -5130,4 +5168,4 @@ exports.exportMultiPagePdf = exportMultiPagePdf;
5130
5168
  exports.logTextMeasurementDiagnostic = logTextMeasurementDiagnostic;
5131
5169
  exports.preparePagesForExport = preparePagesForExport;
5132
5170
  exports.rewriteSvgFontsForJsPDFWithSourceMeta = rewriteSvgFontsForJsPDFWithSourceMeta;
5133
- //# sourceMappingURL=vectorPdfExport-C9jFFq3k.cjs.map
5171
+ //# sourceMappingURL=vectorPdfExport-SMvSP0el.cjs.map