@pixldocs/canvas-renderer 0.5.126 → 0.5.127
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.
- package/dist/{index-8Dj3s-9A.cjs → index-D3W__oF4.cjs} +4 -4
- package/dist/{index-8Dj3s-9A.cjs.map → index-D3W__oF4.cjs.map} +1 -1
- package/dist/{index-D-lngEWM.js → index-DAeQbGws.js} +4 -4
- package/dist/{index-D-lngEWM.js.map → index-DAeQbGws.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{pdfFonts-BPQ8WSXF.cjs → pdfFonts-Cr8l-y3z.cjs} +10 -1
- package/dist/{pdfFonts-BPQ8WSXF.cjs.map → pdfFonts-Cr8l-y3z.cjs.map} +1 -1
- package/dist/{pdfFonts-CZpNVjX9.js → pdfFonts-Y49FLHuG.js} +25 -17
- package/dist/{pdfFonts-CZpNVjX9.js.map → pdfFonts-Y49FLHuG.js.map} +1 -1
- package/dist/{svgTextToPath-BytLBSI5.cjs → svgTextToPath-1WbtFu9C.cjs} +2 -2
- package/dist/{svgTextToPath-BytLBSI5.cjs.map → svgTextToPath-1WbtFu9C.cjs.map} +1 -1
- package/dist/{svgTextToPath-Bsxjuz6-.js → svgTextToPath-n7TTV6Xv.js} +2 -2
- package/dist/{svgTextToPath-Bsxjuz6-.js.map → svgTextToPath-n7TTV6Xv.js.map} +1 -1
- package/dist/{vectorPdfExport-DSf_ziXM.cjs → vectorPdfExport-BDy3-lzN.cjs} +101 -5
- package/dist/vectorPdfExport-BDy3-lzN.cjs.map +1 -0
- package/dist/{vectorPdfExport-ix7Z1pGO.js → vectorPdfExport-DtWByjEA.js} +101 -5
- package/dist/vectorPdfExport-DtWByjEA.js.map +1 -0
- package/package.json +1 -1
- package/dist/vectorPdfExport-DSf_ziXM.cjs.map +0 -1
- package/dist/vectorPdfExport-ix7Z1pGO.js.map +0 -1
|
@@ -1,8 +1,98 @@
|
|
|
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-
|
|
5
|
-
import {
|
|
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-DAeQbGws.js";
|
|
5
|
+
import { resetPdfFontRegistry, FONT_FALLBACK_SYMBOLS, FONT_FALLBACK_MATH, FONT_FALLBACK_DEVANAGARI, embedFontWithGoogleFallback, getEmbeddedVariantsList, isFontAvailable, isFamilyEmbedded, resolveBestRegisteredVariant, getEmbeddedJsPDFFontName, resolveFontWeight, doesVariantSupportChar } from "./pdfFonts-Y49FLHuG.js";
|
|
6
|
+
async function embedFontsForSvg(pdf, svgStr) {
|
|
7
|
+
var _a;
|
|
8
|
+
const {
|
|
9
|
+
embedFontWithGoogleFallback: _embedFontWithGoogleFallback,
|
|
10
|
+
isVariantEmbedded,
|
|
11
|
+
resolveFontWeight: _resolveFontWeight,
|
|
12
|
+
FONT_FALLBACK_SYMBOLS: FONT_FALLBACK_SYMBOLS2,
|
|
13
|
+
FONT_FALLBACK_DEVANAGARI: FONT_FALLBACK_DEVANAGARI2,
|
|
14
|
+
FONT_FALLBACK_MATH: FONT_FALLBACK_MATH2
|
|
15
|
+
} = await import("./pdfFonts-Y49FLHuG.js");
|
|
16
|
+
const parser = new DOMParser();
|
|
17
|
+
const doc = parser.parseFromString(svgStr, "image/svg+xml");
|
|
18
|
+
const textEls = Array.from(doc.querySelectorAll("text, tspan, textPath"));
|
|
19
|
+
const readStyleToken = (style, prop) => {
|
|
20
|
+
var _a2;
|
|
21
|
+
const m = style.match(new RegExp(`${prop}\\s*:\\s*([^;]+)`, "i"));
|
|
22
|
+
return ((_a2 = m == null ? void 0 : m[1]) == null ? void 0 : _a2.trim()) || null;
|
|
23
|
+
};
|
|
24
|
+
const resolveInherited = (el, attr, styleProp = attr) => {
|
|
25
|
+
var _a2;
|
|
26
|
+
let cur = el;
|
|
27
|
+
while (cur) {
|
|
28
|
+
const a = (_a2 = cur.getAttribute(attr)) == null ? void 0 : _a2.trim();
|
|
29
|
+
if (a) return a;
|
|
30
|
+
const s = readStyleToken(cur.getAttribute("style") || "", styleProp);
|
|
31
|
+
if (s) return s;
|
|
32
|
+
cur = cur.parentElement;
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
36
|
+
const parseWeight = (raw) => {
|
|
37
|
+
const n = Number.parseInt(raw, 10);
|
|
38
|
+
if (Number.isFinite(n)) return n;
|
|
39
|
+
const s = raw.toLowerCase();
|
|
40
|
+
if (/bold/.test(s)) return 700;
|
|
41
|
+
if (/semi|demi/.test(s)) return 600;
|
|
42
|
+
if (/medium/.test(s)) return 500;
|
|
43
|
+
if (/light|thin/.test(s)) return 300;
|
|
44
|
+
return 400;
|
|
45
|
+
};
|
|
46
|
+
const needed = /* @__PURE__ */ new Map();
|
|
47
|
+
for (const el of textEls) {
|
|
48
|
+
const rawFf = resolveInherited(el, "font-family");
|
|
49
|
+
if (!rawFf) continue;
|
|
50
|
+
const family = (_a = rawFf.split(",")[0]) == null ? void 0 : _a.replace(/['"]/g, "").trim();
|
|
51
|
+
if (!family) continue;
|
|
52
|
+
const weight = _resolveFontWeight(parseWeight(resolveInherited(el, "font-weight") || "400"));
|
|
53
|
+
const italic = /italic|oblique/i.test(resolveInherited(el, "font-style") || "normal");
|
|
54
|
+
const key = `${family}${weight}${italic ? "i" : "n"}`;
|
|
55
|
+
if (!needed.has(key)) needed.set(key, { family, weight, italic });
|
|
56
|
+
}
|
|
57
|
+
let embedded = 0;
|
|
58
|
+
for (const { family, weight, italic } of needed.values()) {
|
|
59
|
+
if (isVariantEmbedded(family, weight, italic)) continue;
|
|
60
|
+
await _embedFontWithGoogleFallback(pdf, family, weight, italic);
|
|
61
|
+
if (isVariantEmbedded(family, weight, italic)) embedded++;
|
|
62
|
+
}
|
|
63
|
+
const fallbackFamilies = [
|
|
64
|
+
{ family: FONT_FALLBACK_SYMBOLS2, weight: 400 },
|
|
65
|
+
{ family: FONT_FALLBACK_MATH2, weight: 400 }
|
|
66
|
+
];
|
|
67
|
+
for (const w of [300, 400, 500, 600, 700]) {
|
|
68
|
+
fallbackFamilies.push({ family: FONT_FALLBACK_DEVANAGARI2, weight: w });
|
|
69
|
+
}
|
|
70
|
+
for (const { family, weight } of fallbackFamilies) {
|
|
71
|
+
if (isVariantEmbedded(family, weight, false)) continue;
|
|
72
|
+
await _embedFontWithGoogleFallback(pdf, family, weight, false);
|
|
73
|
+
if (isVariantEmbedded(family, weight, false)) embedded++;
|
|
74
|
+
}
|
|
75
|
+
for (const { family, weight, italic } of needed.values()) {
|
|
76
|
+
if (!italic) continue;
|
|
77
|
+
if (!isVariantEmbedded(family, weight, false)) {
|
|
78
|
+
await _embedFontWithGoogleFallback(pdf, family, weight, false);
|
|
79
|
+
if (isVariantEmbedded(family, weight, false)) embedded++;
|
|
80
|
+
}
|
|
81
|
+
if (!isVariantEmbedded(family, 400, false)) {
|
|
82
|
+
await _embedFontWithGoogleFallback(pdf, family, 400, false);
|
|
83
|
+
if (isVariantEmbedded(family, 400, false)) embedded++;
|
|
84
|
+
}
|
|
85
|
+
if (weight <= 400) continue;
|
|
86
|
+
if (isVariantEmbedded(family, 400, true)) continue;
|
|
87
|
+
await _embedFontWithGoogleFallback(pdf, family, 400, true);
|
|
88
|
+
if (isVariantEmbedded(family, 400, true)) embedded++;
|
|
89
|
+
}
|
|
90
|
+
console.log("[Vector PDF Debug] embedFontsForSvg", {
|
|
91
|
+
requested: needed.size,
|
|
92
|
+
newlyEmbedded: embedded,
|
|
93
|
+
sample: [...needed.values()].slice(0, 12)
|
|
94
|
+
});
|
|
95
|
+
}
|
|
6
96
|
async function bakeEdgeFadeIntoDataUrl(dataUrl, element) {
|
|
7
97
|
const fade = element;
|
|
8
98
|
if (!hasEdgeFade(fade)) return null;
|
|
@@ -2022,7 +2112,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
|
|
|
2022
2112
|
async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
|
|
2023
2113
|
if (!colorMap || Object.keys(colorMap).length === 0) return null;
|
|
2024
2114
|
try {
|
|
2025
|
-
const { getNormalizedSvgUrl } = await import("./index-
|
|
2115
|
+
const { getNormalizedSvgUrl } = await import("./index-DAeQbGws.js").then((n) => n._);
|
|
2026
2116
|
return await getNormalizedSvgUrl(imageUrl, colorMap);
|
|
2027
2117
|
} catch {
|
|
2028
2118
|
return null;
|
|
@@ -2803,7 +2893,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
|
|
|
2803
2893
|
}
|
|
2804
2894
|
let fetchUrl = imageUrl;
|
|
2805
2895
|
if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
|
|
2806
|
-
const { isPrivateUrl } = await import("./index-
|
|
2896
|
+
const { isPrivateUrl } = await import("./index-DAeQbGws.js").then((n) => n._);
|
|
2807
2897
|
if (isPrivateUrl(imageUrl)) return null;
|
|
2808
2898
|
const proxyUrl = new URL(`${API_URL}/image-proxy`);
|
|
2809
2899
|
proxyUrl.searchParams.set("url", imageUrl);
|
|
@@ -4564,6 +4654,11 @@ async function exportMultiPagePdf(pages, options) {
|
|
|
4564
4654
|
);
|
|
4565
4655
|
const liveSvgWidth = page.width;
|
|
4566
4656
|
const liveSvgHeight = page.height;
|
|
4657
|
+
try {
|
|
4658
|
+
await embedFontsForSvg(pdf, liveSvgString);
|
|
4659
|
+
} catch (fontEmbedErr) {
|
|
4660
|
+
console.warn("[client-pdf-export] JIT font embed for live SVG failed", fontEmbedErr);
|
|
4661
|
+
}
|
|
4567
4662
|
const liveSvg = await prepareLiveCanvasSvgForPdf(
|
|
4568
4663
|
liveSvgString,
|
|
4569
4664
|
liveSvgWidth,
|
|
@@ -4774,9 +4869,10 @@ async function exportMultiPagePdf(pages, options) {
|
|
|
4774
4869
|
export {
|
|
4775
4870
|
convertSvgTextDecorationsToLinesString,
|
|
4776
4871
|
drawPreparedLiveCanvasSvgPageToPdf,
|
|
4872
|
+
embedFontsForSvg,
|
|
4777
4873
|
exportFabricCanvasToVectorPdf,
|
|
4778
4874
|
exportMultiPagePdf,
|
|
4779
4875
|
preparePagesForExport,
|
|
4780
4876
|
rewriteSvgFontsForJsPDFWithSourceMeta
|
|
4781
4877
|
};
|
|
4782
|
-
//# sourceMappingURL=vectorPdfExport-
|
|
4878
|
+
//# sourceMappingURL=vectorPdfExport-DtWByjEA.js.map
|