@pixldocs/canvas-renderer 0.5.172 → 0.5.173

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-DuI8QJDd.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-ChHYFk0E.js";
5
+ import { resetPdfFontRegistry, FONT_FALLBACK_SYMBOLS, FONT_FALLBACK_MATH, FONT_FALLBACK_DEVANAGARI, embedFontWithGoogleFallback, getEmbeddedVariantsList, isFontAvailable, isFamilyEmbedded, resolveBestRegisteredVariant, getEmbeddedJsPDFFontName, resolveFontWeight, doesVariantSupportChar } from "./pdfFonts-DhEaMTZl.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("./pdfFonts-DhEaMTZl.js");
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"));
@@ -2500,7 +2500,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
2500
2500
  async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
2501
2501
  if (!colorMap || Object.keys(colorMap).length === 0) return null;
2502
2502
  try {
2503
- const { getNormalizedSvgUrl } = await import("./index-DuI8QJDd.js").then((n) => n.a2);
2503
+ const { getNormalizedSvgUrl } = await import("./index-ChHYFk0E.js").then((n) => n.a2);
2504
2504
  return await getNormalizedSvgUrl(imageUrl, colorMap);
2505
2505
  } catch {
2506
2506
  return null;
@@ -2529,8 +2529,18 @@ function normalizeElement(el) {
2529
2529
  const skewY = el.skewY ?? 0;
2530
2530
  const style = el.style || {};
2531
2531
  const opacity = el.opacity ?? style.opacity ?? 1;
2532
- const fill = el.fill || style.fill || "";
2533
- const stroke = el.stroke || style.stroke || "";
2532
+ const firstStop = (g) => {
2533
+ var _a2;
2534
+ const stops = g == null ? void 0 : g.stops;
2535
+ if (!Array.isArray(stops) || stops.length === 0) return null;
2536
+ const sorted = [...stops].sort((a, b) => (Number(a == null ? void 0 : a.offset) || 0) - (Number(b == null ? void 0 : b.offset) || 0));
2537
+ const c = (_a2 = sorted[0]) == null ? void 0 : _a2.color;
2538
+ return typeof c === "string" && c ? c : null;
2539
+ };
2540
+ const fillGradientFirst = firstStop(el.fillGradient);
2541
+ const strokeGradientFirst = firstStop(el.strokeGradient);
2542
+ const fill = fillGradientFirst ?? (el.fill || style.fill || "");
2543
+ const stroke = strokeGradientFirst ?? (el.stroke || style.stroke || "");
2534
2544
  const strokeWidth = el.strokeWidth ?? style.strokeWidth ?? 0;
2535
2545
  const strokeDashArray = ((_e = el.strokeDashArray) == null ? void 0 : _e.join(",")) || style.strokeDasharray;
2536
2546
  const text = el.text || el.content || "";
@@ -3281,7 +3291,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
3281
3291
  }
3282
3292
  let fetchUrl = imageUrl;
3283
3293
  if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
3284
- const { isPrivateUrl } = await import("./index-DuI8QJDd.js").then((n) => n.a2);
3294
+ const { isPrivateUrl } = await import("./index-ChHYFk0E.js").then((n) => n.a2);
3285
3295
  if (isPrivateUrl(imageUrl)) return null;
3286
3296
  const proxyUrl = new URL(`${API_URL}/image-proxy`);
3287
3297
  proxyUrl.searchParams.set("url", imageUrl);
@@ -4888,7 +4898,7 @@ function preparePagesForExport(pages, canvasWidth, canvasHeight, options) {
4888
4898
  }
4889
4899
  async function exportMultiPagePdf(pages, options) {
4890
4900
  var _a, _b, _c, _d, _e;
4891
- const { filename = "document.pdf", title, watermark = false, returnBlob = false } = options;
4901
+ const { filename = "document.pdf", title, watermark = false, returnBlob = false, pdfTextMode = "selectable" } = options;
4892
4902
  resetPdfFontRegistry();
4893
4903
  if (pages.length === 0) {
4894
4904
  throw new Error("No pages to export");
@@ -5047,8 +5057,24 @@ async function exportMultiPagePdf(pages, options) {
5047
5057
  } catch (fontEmbedErr) {
5048
5058
  console.warn("[client-pdf-export] JIT font embed for live SVG failed", fontEmbedErr);
5049
5059
  }
5060
+ let preppedSvgString = liveSvgString;
5061
+ try {
5062
+ if (pdfTextMode === "auto" || pdfTextMode === "pixel-perfect") {
5063
+ const { convertDevanagariTextToPath } = await import("./svgTextToPath-ra4EhtBL.js");
5064
+ preppedSvgString = await convertDevanagariTextToPath(
5065
+ liveSvgString,
5066
+ void 0,
5067
+ { mode: "gradient-only" }
5068
+ );
5069
+ } else {
5070
+ const { replaceGradientTextFillsWithFirstStop } = await import("./svgTextToPath-ra4EhtBL.js");
5071
+ preppedSvgString = replaceGradientTextFillsWithFirstStop(liveSvgString);
5072
+ }
5073
+ } catch (gradErr) {
5074
+ console.warn("[client-pdf-export] gradient-text fill resolution failed", gradErr);
5075
+ }
5050
5076
  const liveSvg = await prepareLiveCanvasSvgForPdf(
5051
- liveSvgString,
5077
+ preppedSvgString,
5052
5078
  liveSvgWidth,
5053
5079
  liveSvgHeight,
5054
5080
  `page-${pageIndex + 1}`,
@@ -5265,4 +5291,4 @@ export {
5265
5291
  preparePagesForExport,
5266
5292
  rewriteSvgFontsForJsPDFWithSourceMeta
5267
5293
  };
5268
- //# sourceMappingURL=vectorPdfExport-wH2x4QIj.js.map
5294
+ //# sourceMappingURL=vectorPdfExport-CyTa-D1p.js.map