@pixldocs/canvas-renderer 0.5.154 → 0.5.156

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,8 +1,8 @@
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-CoH2Xntr.js";
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";
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-DJQnrBbh.js";
5
+ import { r as resetPdfFontRegistry, F as FONT_FALLBACK_SYMBOLS, a as FONT_FALLBACK_MATH, b as FONT_FALLBACK_DEVANAGARI, e as embedFontWithGoogleFallback, g as getEmbeddedVariantsList, i as isFontAvailable, c as isFamilyEmbedded, d as resolveBestRegisteredVariant, f as getEmbeddedJsPDFFontName, h as convertAllTextToPath, j as resolveFontWeight, k as doesVariantSupportChar } from "./svgTextToPath-V1vC0SQt.js";
6
6
  async function embedFontsForSvg(pdf, svgStr) {
7
7
  var _a;
8
8
  const {
@@ -12,7 +12,7 @@ async function embedFontsForSvg(pdf, svgStr) {
12
12
  FONT_FALLBACK_SYMBOLS: FONT_FALLBACK_SYMBOLS2,
13
13
  FONT_FALLBACK_DEVANAGARI: FONT_FALLBACK_DEVANAGARI2,
14
14
  FONT_FALLBACK_MATH: FONT_FALLBACK_MATH2
15
- } = await import("./pdfFonts-b3_bv7F0.js");
15
+ } = await import("./svgTextToPath-V1vC0SQt.js").then((n) => n.p);
16
16
  const parser = new DOMParser();
17
17
  const doc = parser.parseFromString(svgStr, "image/svg+xml");
18
18
  const textEls = Array.from(doc.querySelectorAll("text, tspan, textPath"));
@@ -1308,6 +1308,35 @@ async function bakeTextAnchorPositionsFromLiveSvg(svg) {
1308
1308
  }
1309
1309
  }
1310
1310
  }
1311
+ function appendInvisibleSelectableTextLayer(svg) {
1312
+ var _a;
1313
+ const doc = svg.ownerDocument;
1314
+ if (!doc) return;
1315
+ const texts = Array.from(svg.querySelectorAll("text"));
1316
+ if (texts.length === 0) return;
1317
+ const SVG_NS = "http://www.w3.org/2000/svg";
1318
+ const layer = doc.createElementNS(SVG_NS, "g");
1319
+ layer.setAttribute("data-pd-selectable-layer", "1");
1320
+ layer.setAttribute("fill", "none");
1321
+ layer.setAttribute("stroke", "none");
1322
+ let cloned = 0;
1323
+ for (const text of texts) {
1324
+ if ((_a = text.closest) == null ? void 0 : _a.call(text, '[data-pd-selectable-layer="1"]')) continue;
1325
+ if (!(text.textContent || "").trim()) continue;
1326
+ const clone = text.cloneNode(true);
1327
+ clone.setAttribute("fill", "none");
1328
+ clone.setAttribute("stroke", "none");
1329
+ clone.removeAttribute("opacity");
1330
+ clone.removeAttribute("fill-opacity");
1331
+ clone.removeAttribute("stroke-opacity");
1332
+ layer.appendChild(clone);
1333
+ cloned++;
1334
+ }
1335
+ if (cloned > 0) {
1336
+ svg.appendChild(layer);
1337
+ console.log(`[Vector PDF][selectable-layer] appended ${cloned} invisible text clone(s)`);
1338
+ }
1339
+ }
1311
1340
  async function logTextMeasurementDiagnostic(svg) {
1312
1341
  var _a, _b, _c, _d, _e;
1313
1342
  if (typeof window === "undefined" || typeof document === "undefined") return;
@@ -1836,7 +1865,7 @@ async function collectInlinedFontFaceCss() {
1836
1865
  return cachedInlinedFontFaceCss;
1837
1866
  }
1838
1867
  async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey, options) {
1839
- var _a;
1868
+ var _a, _b;
1840
1869
  try {
1841
1870
  const parser = new DOMParser();
1842
1871
  const processedSvg = inlineNestedSvgImageDataUris(rawSvg, parser);
@@ -1873,11 +1902,17 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
1873
1902
  } catch (e) {
1874
1903
  console.warn("[Vector PDF] anchor-bake pass failed (continuing):", e);
1875
1904
  }
1905
+ appendInvisibleSelectableTextLayer(svgToDraw);
1876
1906
  await rasterizeShadowMarkers(svgToDraw);
1877
1907
  await convertTextDecorationsToLines(svgToDraw);
1908
+ const outlined = await convertAllTextToPath(new XMLSerializer().serializeToString(svgToDraw), void 0, { mode: "shadow-bound" });
1909
+ const outlinedDoc = parser.parseFromString(outlined, "image/svg+xml");
1910
+ if (!outlinedDoc.querySelector("parsererror") && ((_a = outlinedDoc.documentElement) == null ? void 0 : _a.tagName.toLowerCase()) === "svg") {
1911
+ svgToDraw = outlinedDoc.documentElement;
1912
+ }
1878
1913
  const rewritten = rewriteSvgFontsForJsPDFWithSourceMeta(new XMLSerializer().serializeToString(svgToDraw));
1879
1914
  const rewrittenDoc = parser.parseFromString(rewritten, "image/svg+xml");
1880
- if (!rewrittenDoc.querySelector("parsererror") && ((_a = rewrittenDoc.documentElement) == null ? void 0 : _a.tagName.toLowerCase()) === "svg") {
1915
+ if (!rewrittenDoc.querySelector("parsererror") && ((_b = rewrittenDoc.documentElement) == null ? void 0 : _b.tagName.toLowerCase()) === "svg") {
1881
1916
  return rewrittenDoc.documentElement;
1882
1917
  }
1883
1918
  return svgToDraw;
@@ -2459,7 +2494,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
2459
2494
  async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
2460
2495
  if (!colorMap || Object.keys(colorMap).length === 0) return null;
2461
2496
  try {
2462
- const { getNormalizedSvgUrl } = await import("./index-CoH2Xntr.js").then((n) => n.$);
2497
+ const { getNormalizedSvgUrl } = await import("./index-DJQnrBbh.js").then((n) => n.$);
2463
2498
  return await getNormalizedSvgUrl(imageUrl, colorMap);
2464
2499
  } catch {
2465
2500
  return null;
@@ -3240,7 +3275,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
3240
3275
  }
3241
3276
  let fetchUrl = imageUrl;
3242
3277
  if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
3243
- const { isPrivateUrl } = await import("./index-CoH2Xntr.js").then((n) => n.$);
3278
+ const { isPrivateUrl } = await import("./index-DJQnrBbh.js").then((n) => n.$);
3244
3279
  if (isPrivateUrl(imageUrl)) return null;
3245
3280
  const proxyUrl = new URL(`${API_URL}/image-proxy`);
3246
3281
  proxyUrl.searchParams.set("url", imageUrl);
@@ -5214,6 +5249,7 @@ async function exportMultiPagePdf(pages, options) {
5214
5249
  pdf.save(filename);
5215
5250
  }
5216
5251
  export {
5252
+ appendInvisibleSelectableTextLayer,
5217
5253
  bakeTextAnchorPositionsFromLiveSvg,
5218
5254
  convertSvgTextDecorationsToLinesString,
5219
5255
  drawPreparedLiveCanvasSvgPageToPdf,
@@ -5224,4 +5260,4 @@ export {
5224
5260
  preparePagesForExport,
5225
5261
  rewriteSvgFontsForJsPDFWithSourceMeta
5226
5262
  };
5227
- //# sourceMappingURL=vectorPdfExport-Db9b2C3K.js.map
5263
+ //# sourceMappingURL=vectorPdfExport-DSTA9YWG.js.map