@pixldocs/canvas-renderer 0.5.494 → 0.5.495

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,8 +3,8 @@ 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-CCMdTuIr.cjs");
7
- const pdfFonts = require("./pdfFonts-BTj2f465.cjs");
6
+ const index = require("./index-DaaT4Mo7.cjs");
7
+ const pdfFonts = require("./pdfFonts-CySSLV-P.cjs");
8
8
  function _interopNamespaceDefault(e) {
9
9
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
10
10
  if (e) {
@@ -31,7 +31,7 @@ async function embedFontsForSvg(pdf, svgStr) {
31
31
  FONT_FALLBACK_SYMBOLS: FONT_FALLBACK_SYMBOLS2,
32
32
  FONT_FALLBACK_DEVANAGARI: FONT_FALLBACK_DEVANAGARI2,
33
33
  FONT_FALLBACK_MATH: FONT_FALLBACK_MATH2
34
- } = await Promise.resolve().then(() => require("./pdfFonts-BTj2f465.cjs"));
34
+ } = await Promise.resolve().then(() => require("./pdfFonts-CySSLV-P.cjs"));
35
35
  const parser = new DOMParser();
36
36
  const doc = parser.parseFromString(svgStr, "image/svg+xml");
37
37
  const textEls = Array.from(doc.querySelectorAll("text, tspan, textPath"));
@@ -1833,7 +1833,7 @@ function stripSuspiciousFullPageOverlayNodes(svg) {
1833
1833
  let isPathLike = false;
1834
1834
  if (el.tagName.toLowerCase() === "path") {
1835
1835
  const d = (el.getAttribute("d") || "").replace(/\s+/g, " ").trim();
1836
- isPathLike = !!d && (new RegExp(`^Ms*0(?:.0+)?s+0(?:.0+)?s*Hs*${Math.round(pageWidth)}(?:.0+)?s*Vs*${Math.round(pageHeight)}(?:.0+)?s*Hs*0(?:.0+)?s*Z?$`, "i").test(d) || new RegExp(`^Ms*0(?:.0+)?s+0(?:.0+)?s*Ls*${Math.round(pageWidth)}(?:.0+)?s+0(?:.0+)?s*Ls*${Math.round(pageWidth)}(?:.0+)?s+${Math.round(pageHeight)}(?:.0+)?s*Ls*0(?:.0+)?s+${Math.round(pageHeight)}(?:.0+)?s*Z?$`, "i").test(d));
1836
+ isPathLike = !!d && (new RegExp(`^M\\s*0(?:\\.0+)?\\s+0(?:\\.0+)?\\s*H\\s*${Math.round(pageWidth)}(?:\\.0+)?\\s*V\\s*${Math.round(pageHeight)}(?:\\.0+)?\\s*H\\s*0(?:\\.0+)?\\s*Z?$`, "i").test(d) || new RegExp(`^M\\s*0(?:\\.0+)?\\s+0(?:\\.0+)?\\s*L\\s*${Math.round(pageWidth)}(?:\\.0+)?\\s+0(?:\\.0+)?\\s*L\\s*${Math.round(pageWidth)}(?:\\.0+)?\\s+${Math.round(pageHeight)}(?:\\.0+)?\\s*L\\s*0(?:\\.0+)?\\s+${Math.round(pageHeight)}(?:\\.0+)?\\s*Z?$`, "i").test(d));
1837
1837
  }
1838
1838
  const inlineStyle = el.getAttribute("style") || "";
1839
1839
  const likelyOverlay = isRectLike || isPathLike || hasVisibleStyleToken(inlineStyle, "mix-blend-mode");
@@ -2626,7 +2626,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
2626
2626
  logSvgGradientClipDiagnostics("prepare:after-flatten-nested-viewports", svg, { pageKey, pageWidth, pageHeight });
2627
2627
  disambiguateNestedSvgIds(svg);
2628
2628
  expandSvgUseElements(svg, pageKey);
2629
- let svgToDraw = normalizeSvgExplicitColors(svg);
2629
+ const svgToDraw = normalizeSvgExplicitColors(svg);
2630
2630
  logSvgGradientClipDiagnostics("prepare:after-explicit-colors", svgToDraw, { pageKey, pageWidth, pageHeight });
2631
2631
  inlineComputedStyles(svgToDraw);
2632
2632
  sanitizeSvgTreeForPdf(svgToDraw);
@@ -3271,7 +3271,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
3271
3271
  async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
3272
3272
  if (!colorMap || Object.keys(colorMap).length === 0) return null;
3273
3273
  try {
3274
- const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-CCMdTuIr.cjs")).then((n) => n.canvasImageLoader);
3274
+ const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-DaaT4Mo7.cjs")).then((n) => n.canvasImageLoader);
3275
3275
  return await getNormalizedSvgUrl(imageUrl, colorMap);
3276
3276
  } catch {
3277
3277
  return null;
@@ -4080,7 +4080,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
4080
4080
  }
4081
4081
  let fetchUrl = imageUrl;
4082
4082
  if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
4083
- const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-CCMdTuIr.cjs")).then((n) => n.canvasImageLoader);
4083
+ const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-DaaT4Mo7.cjs")).then((n) => n.canvasImageLoader);
4084
4084
  if (isPrivateUrl(imageUrl)) return null;
4085
4085
  const proxyUrl = new URL(`${index.API_URL}/image-proxy`);
4086
4086
  proxyUrl.searchParams.set("url", imageUrl);
@@ -4178,7 +4178,7 @@ function getShapePoints(shapeType, x, y, w, h) {
4178
4178
  { x: x + w, y: y + h },
4179
4179
  { x, y: y + h }
4180
4180
  ];
4181
- case "cross":
4181
+ case "cross": {
4182
4182
  const t = 0.35;
4183
4183
  return [
4184
4184
  { x: x + w * t, y },
@@ -4194,6 +4194,7 @@ function getShapePoints(shapeType, x, y, w, h) {
4194
4194
  { x, y: y + h * t },
4195
4195
  { x: x + w * t, y: y + h * t }
4196
4196
  ];
4197
+ }
4197
4198
  default:
4198
4199
  return null;
4199
4200
  }
@@ -4697,7 +4698,7 @@ async function rasterizeCropGroupToPng(liveGroup, frameW, frameH, multiplier = 2
4697
4698
  return png;
4698
4699
  }
4699
4700
  async function drawElement(pdf, element, embeddedFonts, canvasWidth, canvasHeight, backgroundColor, fabricMatrix, fabricIntrinsic, pageId, liveFabricText, pageChildren) {
4700
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
4701
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
4701
4702
  if (!element.visible) return;
4702
4703
  debugLog(`drawElement START id=${element.id} type=${element.type}`);
4703
4704
  const norm = normalizeElement(element);
@@ -4709,6 +4710,18 @@ async function drawElement(pdf, element, embeddedFonts, canvasWidth, canvasHeigh
4709
4710
  norm.y = abs.top;
4710
4711
  norm.w = abs.width;
4711
4712
  norm.h = abs.height;
4713
+ if (index.isElement(node)) {
4714
+ norm.angle = index.getWorldAngleDeg(node, pageChildren);
4715
+ }
4716
+ }
4717
+ }
4718
+ {
4719
+ const elBg = element.backgroundColor;
4720
+ if (elBg && elBg !== "transparent" && elBg !== "none" && !fabricMatrix && norm.w > 0 && norm.h > 0) {
4721
+ const prevFill = (_a = pdf.getFillColor) == null ? void 0 : _a.call(pdf);
4722
+ pdf.setFillColor(normalizeBgColor(elBg));
4723
+ pdf.rect(norm.x, norm.y, norm.w, norm.h, "F");
4724
+ if (prevFill) pdf.setFillColor(prevFill);
4712
4725
  }
4713
4726
  }
4714
4727
  if (element.smartElementType && element.smartProps && norm.w > 0 && norm.h > 0) {
@@ -4784,11 +4797,11 @@ async function drawElement(pdf, element, embeddedFonts, canvasWidth, canvasHeigh
4784
4797
  const anyPdf3 = pdf;
4785
4798
  const canUseAdvancedTransforms3 = typeof anyPdf3.advancedAPI === "function" && typeof anyPdf3.setCurrentTransformationMatrix === "function" && typeof anyPdf3.Matrix === "function";
4786
4799
  pdf.setGState(pdf.GState({ opacity: 1, "stroke-opacity": 1 }));
4787
- const cropZoomVal = cropData ? Math.max(1, ((_b = (_a = cropData._img) == null ? void 0 : _a._ct) == null ? void 0 : _b.zoom) ?? element.cropZoom ?? 1) : 1;
4788
- const cropPanXVal = cropData ? Math.max(0, Math.min(1, ((_d = (_c = cropData._img) == null ? void 0 : _c._ct) == null ? void 0 : _d.panX) ?? element.cropPanX ?? 0.5)) : 0.5;
4789
- const cropPanYVal = cropData ? Math.max(0, Math.min(1, ((_f = (_e = cropData._img) == null ? void 0 : _e._ct) == null ? void 0 : _f.panY) ?? element.cropPanY ?? 0.5)) : 0.5;
4790
- const naturalW = Math.max(1, Number(element.imageNaturalWidth ?? 0) || Number(((_g = cropData == null ? void 0 : cropData._img) == null ? void 0 : _g.width) ?? 0) || frameW);
4791
- const naturalH = Math.max(1, Number(element.imageNaturalHeight ?? 0) || Number(((_h = cropData == null ? void 0 : cropData._img) == null ? void 0 : _h.height) ?? 0) || frameH);
4800
+ const cropZoomVal = cropData ? Math.max(1, ((_c = (_b = cropData._img) == null ? void 0 : _b._ct) == null ? void 0 : _c.zoom) ?? element.cropZoom ?? 1) : 1;
4801
+ const cropPanXVal = cropData ? Math.max(0, Math.min(1, ((_e = (_d = cropData._img) == null ? void 0 : _d._ct) == null ? void 0 : _e.panX) ?? element.cropPanX ?? 0.5)) : 0.5;
4802
+ const cropPanYVal = cropData ? Math.max(0, Math.min(1, ((_g = (_f = cropData._img) == null ? void 0 : _f._ct) == null ? void 0 : _g.panY) ?? element.cropPanY ?? 0.5)) : 0.5;
4803
+ const naturalW = Math.max(1, Number(element.imageNaturalWidth ?? 0) || Number(((_h = cropData == null ? void 0 : cropData._img) == null ? void 0 : _h.width) ?? 0) || frameW);
4804
+ const naturalH = Math.max(1, Number(element.imageNaturalHeight ?? 0) || Number(((_i = cropData == null ? void 0 : cropData._img) == null ? void 0 : _i.height) ?? 0) || frameH);
4792
4805
  const fitContain = ((cropData == null ? void 0 : cropData.fit) ?? element.imageFit ?? "cover") === "contain";
4793
4806
  const alignH = element.imageAlignH ?? "center";
4794
4807
  const alignV = element.imageAlignV ?? "middle";
@@ -5218,7 +5231,7 @@ async function drawElement(pdf, element, embeddedFonts, canvasWidth, canvasHeigh
5218
5231
  liveFabricText ?? void 0
5219
5232
  );
5220
5233
  pdf.setGState(pdf.GState({ opacity: 1, "stroke-opacity": 1 }));
5221
- const linkUrl2 = (_i = element.linkConfig) == null ? void 0 : _i.url;
5234
+ const linkUrl2 = (_j = element.linkConfig) == null ? void 0 : _j.url;
5222
5235
  if (linkUrl2) {
5223
5236
  addLinkAnnotation(pdf, linkUrl2, norm.x, norm.y, visualW, visualH);
5224
5237
  }
@@ -5318,7 +5331,7 @@ async function drawElement(pdf, element, embeddedFonts, canvasWidth, canvasHeigh
5318
5331
  );
5319
5332
  }
5320
5333
  pdf.setGState(pdf.GState({ opacity: 1, "stroke-opacity": 1 }));
5321
- const linkUrl = (_j = element.linkConfig) == null ? void 0 : _j.url;
5334
+ const linkUrl = (_k = element.linkConfig) == null ? void 0 : _k.url;
5322
5335
  if (linkUrl) {
5323
5336
  addLinkAnnotation(pdf, linkUrl, norm.x, norm.y, visualW, visualH);
5324
5337
  }
@@ -5954,7 +5967,7 @@ async function __exportMultiPagePdfInner(pages, options) {
5954
5967
  }
5955
5968
  let preppedSvgString = liveSvgString;
5956
5969
  try {
5957
- const { prepareSvgTextForPdfMode } = await Promise.resolve().then(() => require("./svgTextToPath-BT7lcwLT.cjs"));
5970
+ const { prepareSvgTextForPdfMode } = await Promise.resolve().then(() => require("./svgTextToPath-Bzd3FsHH.cjs"));
5958
5971
  preppedSvgString = await prepareSvgTextForPdfMode(liveSvgString, pdfTextMode);
5959
5972
  console.log("[client-pdf-export] gradient text mode", {
5960
5973
  pdfTextMode,
@@ -6179,7 +6192,7 @@ async function __exportMultiPagePdfInner(pages, options) {
6179
6192
  const liveMatrix = matrixByElementId.get(element.id);
6180
6193
  const storedMatrix = element.transformMatrix;
6181
6194
  const m = liveMatrix ?? storedMatrix ?? null;
6182
- let intrinsic = intrinsicByElementId.get(element.id) ?? null;
6195
+ const intrinsic = intrinsicByElementId.get(element.id) ?? null;
6183
6196
  const liveText = element.type === "text" ? liveTextByElementId.get(element.id) : void 0;
6184
6197
  await drawElement(pdf, element, embeddedFonts, page.width, page.height, page.backgroundColor, m, intrinsic, page.pageId, liveText, page.pageChildren);
6185
6198
  if (drawIndex % 3 === 2) await yieldToUI();
@@ -6213,4 +6226,4 @@ exports.exportMultiPagePdf = exportMultiPagePdf;
6213
6226
  exports.logTextMeasurementDiagnostic = logTextMeasurementDiagnostic;
6214
6227
  exports.preparePagesForExport = preparePagesForExport;
6215
6228
  exports.rewriteSvgFontsForJsPDFWithSourceMeta = rewriteSvgFontsForJsPDFWithSourceMeta;
6216
- //# sourceMappingURL=vectorPdfExport-BkAhiIFX.cjs.map
6229
+ //# sourceMappingURL=vectorPdfExport-roj_Ddzd.cjs.map