@pixldocs/canvas-renderer 0.5.145 → 0.5.147

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.
@@ -1,7 +1,7 @@
1
1
  import { jsPDF, ShadingPattern } from "jspdf";
2
2
  import { svg2pdf } from "svg2pdf.js";
3
3
  import * as fabric from "fabric";
4
- import { g as getCanvasForPage, c as captureFabricCanvasSvgForPdf, f as findNodeById, a as getAbsoluteBounds, p as parseTextMarkdown, r as renderSmartElementToSvg, n as normalizeShapeType, h as hasEdgeFade, b as getProxiedImageUrl, d as bakeEdgeFade, i as isElement, e as isGroup, j as buildRoundedTrianglePath, A as API_URL, k as getImageProxyFetchOptions, l as getRoundedRectRadii, T as TRIANGLE_STROKE_MITER_LIMIT, m as getTrianglePoints } from "./index-Br7Pk6Ol.js";
4
+ import { g as getCanvasForPage, c as captureFabricCanvasSvgForPdf, f as findNodeById, a as getAbsoluteBounds, p as parseTextMarkdown, r as renderSmartElementToSvg, n as normalizeShapeType, h as hasEdgeFade, b as getProxiedImageUrl, d as bakeEdgeFade, i as isElement, e as isGroup, j as buildRoundedTrianglePath, A as API_URL, k as getImageProxyFetchOptions, l as getRoundedRectRadii, T as TRIANGLE_STROKE_MITER_LIMIT, m as getTrianglePoints } from "./index-NMZJF9C9.js";
5
5
  import { resetPdfFontRegistry, FONT_FALLBACK_SYMBOLS, FONT_FALLBACK_MATH, FONT_FALLBACK_DEVANAGARI, embedFontWithGoogleFallback, getEmbeddedVariantsList, isFontAvailable, isFamilyEmbedded, resolveBestRegisteredVariant, getEmbeddedJsPDFFontName, resolveFontWeight, doesVariantSupportChar } from "./pdfFonts-b3_bv7F0.js";
6
6
  async function embedFontsForSvg(pdf, svgStr) {
7
7
  var _a;
@@ -123,6 +123,33 @@ const yieldToUI = () => new Promise((resolve) => {
123
123
  requestAnimationFrame(() => setTimeout(resolve, 0));
124
124
  });
125
125
  const SHADOW_RASTER_ALPHA_COMPENSATION = 0.84;
126
+ function collectFontSpecsFromShadowMarkup(markup) {
127
+ const specs = /* @__PURE__ */ new Set();
128
+ const re = /<(?:text|tspan)\b[^>]*>/gi;
129
+ let match;
130
+ while ((match = re.exec(markup)) !== null) {
131
+ const tag = match[0];
132
+ const get = (attr) => {
133
+ const m = tag.match(new RegExp(`\\s${attr}\\s*=\\s*"([^"]*)"`, "i"));
134
+ if (m) return m[1];
135
+ const styleM = tag.match(/\sstyle\s*=\s*"([^"]*)"/i);
136
+ if (styleM) {
137
+ const sm = styleM[1].match(new RegExp(`${attr}\\s*:\\s*([^;]+)`, "i"));
138
+ if (sm) return sm[1].trim();
139
+ }
140
+ return null;
141
+ };
142
+ const family = (get("font-family") || "").split(",")[0].replace(/['"]/g, "").trim();
143
+ if (!family) continue;
144
+ const weight = get("font-weight") || "400";
145
+ const style = get("font-style") || "normal";
146
+ const size = get("font-size") || "16px";
147
+ const sizePx = /[a-z%]/i.test(size) ? size : `${size}px`;
148
+ const famSpec = /\s/.test(family) ? `"${family}"` : family;
149
+ specs.add(`${style} ${weight} ${sizePx} ${famSpec}`);
150
+ }
151
+ return Array.from(specs);
152
+ }
126
153
  let debugSvgDrawSequence = 0;
127
154
  function debugLog(...args) {
128
155
  }
@@ -1503,7 +1530,7 @@ async function convertSvgTextDecorationsToLinesString(svgStr) {
1503
1530
  }
1504
1531
  }
1505
1532
  async function rasterizeShadowMarkers(svg) {
1506
- var _a, _b, _c, _d, _e;
1533
+ var _a, _b, _c, _d, _e, _f;
1507
1534
  if (typeof window === "undefined" || typeof document === "undefined") return;
1508
1535
  const markers = Array.from(svg.querySelectorAll("g.__pdShadowRaster"));
1509
1536
  if (markers.length === 0) return;
@@ -1530,6 +1557,17 @@ async function rasterizeShadowMarkers(svg) {
1530
1557
  const innerXml = restoreSourceFontsForShadowRaster(
1531
1558
  Array.from(marker.childNodes).map((n) => n instanceof Element ? new XMLSerializer().serializeToString(n) : "").join("")
1532
1559
  );
1560
+ try {
1561
+ const fontSpecs = collectFontSpecsFromShadowMarkup(innerXml);
1562
+ if (fontSpecs.length > 0 && ((_c = document.fonts) == null ? void 0 : _c.load)) {
1563
+ await Promise.all(
1564
+ fontSpecs.map(
1565
+ (spec) => document.fonts.load(spec).catch(() => void 0)
1566
+ )
1567
+ );
1568
+ }
1569
+ } catch {
1570
+ }
1533
1571
  const scale = 2;
1534
1572
  const pxW = Math.min(4096, Math.max(8, Math.ceil(bw * scale)));
1535
1573
  const pxH = Math.min(4096, Math.max(8, Math.ceil(bh * scale)));
@@ -1539,7 +1577,7 @@ async function rasterizeShadowMarkers(svg) {
1539
1577
  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>`;
1540
1578
  const dataUrl = await rasterSvgToPngDataUrl(miniSvg, pxW, pxH);
1541
1579
  if (!dataUrl) {
1542
- (_c = marker.parentNode) == null ? void 0 : _c.removeChild(marker);
1580
+ (_d = marker.parentNode) == null ? void 0 : _d.removeChild(marker);
1543
1581
  continue;
1544
1582
  }
1545
1583
  const img = svg.ownerDocument.createElementNS(SVG_NS, "image");
@@ -1551,11 +1589,11 @@ async function rasterizeShadowMarkers(svg) {
1551
1589
  img.setAttribute("preserveAspectRatio", "none");
1552
1590
  img.setAttributeNS(XLINK_NS, "xlink:href", dataUrl);
1553
1591
  img.setAttribute("href", dataUrl);
1554
- (_d = marker.parentNode) == null ? void 0 : _d.replaceChild(img, marker);
1592
+ (_e = marker.parentNode) == null ? void 0 : _e.replaceChild(img, marker);
1555
1593
  } catch (error) {
1556
1594
  console.warn("[Vector PDF] text shadow rasterization failed for one marker:", error);
1557
1595
  try {
1558
- (_e = marker.parentNode) == null ? void 0 : _e.removeChild(marker);
1596
+ (_f = marker.parentNode) == null ? void 0 : _f.removeChild(marker);
1559
1597
  } catch {
1560
1598
  }
1561
1599
  }
@@ -2348,7 +2386,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
2348
2386
  async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
2349
2387
  if (!colorMap || Object.keys(colorMap).length === 0) return null;
2350
2388
  try {
2351
- const { getNormalizedSvgUrl } = await import("./index-Br7Pk6Ol.js").then((n) => n._);
2389
+ const { getNormalizedSvgUrl } = await import("./index-NMZJF9C9.js").then((n) => n.$);
2352
2390
  return await getNormalizedSvgUrl(imageUrl, colorMap);
2353
2391
  } catch {
2354
2392
  return null;
@@ -3129,7 +3167,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
3129
3167
  }
3130
3168
  let fetchUrl = imageUrl;
3131
3169
  if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
3132
- const { isPrivateUrl } = await import("./index-Br7Pk6Ol.js").then((n) => n._);
3170
+ const { isPrivateUrl } = await import("./index-NMZJF9C9.js").then((n) => n.$);
3133
3171
  if (isPrivateUrl(imageUrl)) return null;
3134
3172
  const proxyUrl = new URL(`${API_URL}/image-proxy`);
3135
3173
  proxyUrl.searchParams.set("url", imageUrl);
@@ -5113,4 +5151,4 @@ export {
5113
5151
  preparePagesForExport,
5114
5152
  rewriteSvgFontsForJsPDFWithSourceMeta
5115
5153
  };
5116
- //# sourceMappingURL=vectorPdfExport-B63qQqDW.js.map
5154
+ //# sourceMappingURL=vectorPdfExport-_m5TiQjK.js.map