@pixldocs/canvas-renderer 0.5.118 → 0.5.120
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-Gf5_pgK7.cjs → index-DjwTSk_C.cjs} +5 -4
- package/dist/{index-Gf5_pgK7.cjs.map → index-DjwTSk_C.cjs.map} +1 -1
- package/dist/{index-LbVR8GZp.js → index-Dm9AEQy0.js} +36 -35
- package/dist/{index-LbVR8GZp.js.map → index-Dm9AEQy0.js.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +31 -31
- package/dist/{pdfFonts-ts7v2Fja.js → pdfFonts-BUnZcHhp.js} +36 -12
- package/dist/pdfFonts-BUnZcHhp.js.map +1 -0
- package/dist/{pdfFonts-BSytIe1x.cjs → pdfFonts-DpkEz6IN.cjs} +29 -5
- package/dist/pdfFonts-DpkEz6IN.cjs.map +1 -0
- package/dist/{svgTextToPath-FrpfjI8G.js → svgTextToPath-DR7QIEWZ.js} +2 -2
- package/dist/{svgTextToPath-FrpfjI8G.js.map → svgTextToPath-DR7QIEWZ.js.map} +1 -1
- package/dist/{svgTextToPath-ByZSG1vO.cjs → svgTextToPath-DcQKj5Mc.cjs} +2 -2
- package/dist/{svgTextToPath-ByZSG1vO.cjs.map → svgTextToPath-DcQKj5Mc.cjs.map} +1 -1
- package/dist/{vectorPdfExport-CJd8RINw.js → vectorPdfExport-CxWPJs_l.js} +57 -27
- package/dist/vectorPdfExport-CxWPJs_l.js.map +1 -0
- package/dist/{vectorPdfExport-DMv7QYM5.cjs → vectorPdfExport-yAT4k3Je.cjs} +57 -27
- package/dist/vectorPdfExport-yAT4k3Je.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/pdfFonts-BSytIe1x.cjs.map +0 -1
- package/dist/pdfFonts-ts7v2Fja.js.map +0 -1
- package/dist/vectorPdfExport-CJd8RINw.js.map +0 -1
- package/dist/vectorPdfExport-DMv7QYM5.cjs.map +0 -1
|
@@ -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-
|
|
7
|
-
const pdfFonts = require("./pdfFonts-
|
|
6
|
+
const index = require("./index-DjwTSk_C.cjs");
|
|
7
|
+
const pdfFonts = require("./pdfFonts-DpkEz6IN.cjs");
|
|
8
8
|
function _interopNamespaceDefault(e) {
|
|
9
9
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
10
|
if (e) {
|
|
@@ -59,6 +59,54 @@ function pdfWithColorLogging(pdf, seq, elementId) {
|
|
|
59
59
|
return pdf;
|
|
60
60
|
}
|
|
61
61
|
const FONT_KEY_SEP = "";
|
|
62
|
+
function normalizePdfFontWeight(raw) {
|
|
63
|
+
if (typeof raw === "number" && Number.isFinite(raw)) return pdfFonts.resolveFontWeight(raw);
|
|
64
|
+
const str = String(raw ?? "").trim().toLowerCase();
|
|
65
|
+
const parsed = Number.parseInt(str, 10);
|
|
66
|
+
if (Number.isFinite(parsed)) return pdfFonts.resolveFontWeight(parsed);
|
|
67
|
+
if (str === "bold" || str === "bolder") return 700;
|
|
68
|
+
if (str === "semibold" || str === "demibold") return 600;
|
|
69
|
+
if (str === "medium") return 500;
|
|
70
|
+
if (str === "light" || str === "lighter" || str === "thin") return 300;
|
|
71
|
+
return 400;
|
|
72
|
+
}
|
|
73
|
+
function collectTextFontVariantsForPdf(el, fontKeysNeeded, italicKeysNeeded) {
|
|
74
|
+
var _a, _b, _c;
|
|
75
|
+
const baseFamily = (el == null ? void 0 : el.fontFamily) || ((_a = el == null ? void 0 : el.style) == null ? void 0 : _a.fontFamily);
|
|
76
|
+
if (!baseFamily) return;
|
|
77
|
+
const addVariant = (family, weightRaw, styleRaw) => {
|
|
78
|
+
const resolved = normalizePdfFontWeight(weightRaw);
|
|
79
|
+
if (/italic|oblique/i.test(String(styleRaw ?? ""))) {
|
|
80
|
+
italicKeysNeeded.add(`${family}${FONT_KEY_SEP}${resolved}${FONT_KEY_SEP}italic`);
|
|
81
|
+
} else {
|
|
82
|
+
fontKeysNeeded.add(`${family}${FONT_KEY_SEP}${resolved}`);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
addVariant(baseFamily, el.fontWeight ?? ((_b = el.style) == null ? void 0 : _b.fontWeight) ?? 400, el.fontStyle ?? ((_c = el.style) == null ? void 0 : _c.fontStyle) ?? "normal");
|
|
86
|
+
const styles = el.styles;
|
|
87
|
+
if (styles && typeof styles === "object") {
|
|
88
|
+
for (const lineStyles of Object.values(styles)) {
|
|
89
|
+
if (!lineStyles || typeof lineStyles !== "object") continue;
|
|
90
|
+
for (const s of Object.values(lineStyles)) {
|
|
91
|
+
if (!s || typeof s !== "object") continue;
|
|
92
|
+
addVariant(s.fontFamily || baseFamily, s.fontWeight ?? el.fontWeight ?? 400, s.fontStyle ?? el.fontStyle ?? "normal");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (el.formattingEnabled === true && typeof el.text === "string") {
|
|
97
|
+
try {
|
|
98
|
+
const parsed = index.parseTextMarkdown(el.text);
|
|
99
|
+
for (const lineStyles of Object.values(parsed.styles || {})) {
|
|
100
|
+
if (!lineStyles || typeof lineStyles !== "object") continue;
|
|
101
|
+
for (const s of Object.values(lineStyles)) {
|
|
102
|
+
if (!s || typeof s !== "object") continue;
|
|
103
|
+
addVariant(s.fontFamily || baseFamily, s.fontWeight ?? el.fontWeight ?? 400, s.fontStyle ?? el.fontStyle ?? "normal");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch {
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
62
110
|
function isBasicLatinOrLatin1(char) {
|
|
63
111
|
const c = char.codePointAt(0) ?? 0;
|
|
64
112
|
return c >= 32 && c <= 126 || c >= 160 && c <= 255;
|
|
@@ -1993,7 +2041,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
|
|
|
1993
2041
|
async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
|
|
1994
2042
|
if (!colorMap || Object.keys(colorMap).length === 0) return null;
|
|
1995
2043
|
try {
|
|
1996
|
-
const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-
|
|
2044
|
+
const { getNormalizedSvgUrl } = await Promise.resolve().then(() => require("./index-DjwTSk_C.cjs")).then((n) => n.canvasImageLoader);
|
|
1997
2045
|
return await getNormalizedSvgUrl(imageUrl, colorMap);
|
|
1998
2046
|
} catch {
|
|
1999
2047
|
return null;
|
|
@@ -2774,7 +2822,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
|
|
|
2774
2822
|
}
|
|
2775
2823
|
let fetchUrl = imageUrl;
|
|
2776
2824
|
if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
|
|
2777
|
-
const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-
|
|
2825
|
+
const { isPrivateUrl } = await Promise.resolve().then(() => require("./index-DjwTSk_C.cjs")).then((n) => n.canvasImageLoader);
|
|
2778
2826
|
if (isPrivateUrl(imageUrl)) return null;
|
|
2779
2827
|
const proxyUrl = new URL(`${index.API_URL}/image-proxy`);
|
|
2780
2828
|
proxyUrl.searchParams.set("url", imageUrl);
|
|
@@ -4267,6 +4315,7 @@ async function drawElementContentCore(pdf, element, norm, x, y, w, h, embeddedFo
|
|
|
4267
4315
|
}
|
|
4268
4316
|
async function exportFabricCanvasToVectorPdf(_fabricCanvas, options) {
|
|
4269
4317
|
const { filename = "document.pdf", width, height, title, elements, backgroundColor } = options;
|
|
4318
|
+
pdfFonts.resetPdfFontRegistry();
|
|
4270
4319
|
const orientation = width > height ? "landscape" : "portrait";
|
|
4271
4320
|
const pdf = new jspdf.jsPDF({
|
|
4272
4321
|
orientation,
|
|
@@ -4288,18 +4337,8 @@ async function exportFabricCanvasToVectorPdf(_fabricCanvas, options) {
|
|
|
4288
4337
|
const fontKeysNeeded = /* @__PURE__ */ new Set();
|
|
4289
4338
|
const italicKeysNeeded = /* @__PURE__ */ new Set();
|
|
4290
4339
|
elements.forEach((el) => {
|
|
4291
|
-
var _a;
|
|
4292
4340
|
if (el.type === "text") {
|
|
4293
|
-
|
|
4294
|
-
const { fontFamily, fontWeight } = norm;
|
|
4295
|
-
if (fontFamily) {
|
|
4296
|
-
const resolved = pdfFonts.resolveFontWeight(fontWeight ?? 400);
|
|
4297
|
-
fontKeysNeeded.add(`${fontFamily}${FONT_KEY_SEP}${resolved}`);
|
|
4298
|
-
const fontStyleRaw = el.fontStyle || ((_a = el.style) == null ? void 0 : _a.fontStyle) || "normal";
|
|
4299
|
-
if (fontStyleRaw === "italic") {
|
|
4300
|
-
italicKeysNeeded.add(`${fontFamily}${FONT_KEY_SEP}${resolved}${FONT_KEY_SEP}italic`);
|
|
4301
|
-
}
|
|
4302
|
-
}
|
|
4341
|
+
collectTextFontVariantsForPdf(el, fontKeysNeeded, italicKeysNeeded);
|
|
4303
4342
|
}
|
|
4304
4343
|
});
|
|
4305
4344
|
fontKeysNeeded.add(`${pdfFonts.FONT_FALLBACK_SYMBOLS}${FONT_KEY_SEP}400`);
|
|
@@ -4386,6 +4425,7 @@ function preparePagesForExport(pages, canvasWidth, canvasHeight, options) {
|
|
|
4386
4425
|
async function exportMultiPagePdf(pages, options) {
|
|
4387
4426
|
var _a, _b, _c, _d, _e;
|
|
4388
4427
|
const { filename = "document.pdf", title, watermark = false, returnBlob = false } = options;
|
|
4428
|
+
pdfFonts.resetPdfFontRegistry();
|
|
4389
4429
|
if (pages.length === 0) {
|
|
4390
4430
|
throw new Error("No pages to export");
|
|
4391
4431
|
}
|
|
@@ -4405,18 +4445,8 @@ async function exportMultiPagePdf(pages, options) {
|
|
|
4405
4445
|
const italicKeysNeeded = /* @__PURE__ */ new Set();
|
|
4406
4446
|
pages.forEach((page) => {
|
|
4407
4447
|
page.elements.forEach((item) => {
|
|
4408
|
-
var _a2;
|
|
4409
4448
|
if (!isGroupBackgroundDrawable(item) && item.type === "text") {
|
|
4410
|
-
|
|
4411
|
-
const { fontFamily, fontWeight } = norm;
|
|
4412
|
-
if (fontFamily) {
|
|
4413
|
-
const resolved = pdfFonts.resolveFontWeight(fontWeight ?? 400);
|
|
4414
|
-
fontKeysNeeded.add(`${fontFamily}${FONT_KEY_SEP}${resolved}`);
|
|
4415
|
-
const fontStyleRaw = item.fontStyle || ((_a2 = item.style) == null ? void 0 : _a2.fontStyle) || "normal";
|
|
4416
|
-
if (fontStyleRaw === "italic") {
|
|
4417
|
-
italicKeysNeeded.add(`${fontFamily}${FONT_KEY_SEP}${resolved}${FONT_KEY_SEP}italic`);
|
|
4418
|
-
}
|
|
4419
|
-
}
|
|
4449
|
+
collectTextFontVariantsForPdf(item, fontKeysNeeded, italicKeysNeeded);
|
|
4420
4450
|
}
|
|
4421
4451
|
});
|
|
4422
4452
|
});
|
|
@@ -4763,4 +4793,4 @@ exports.exportFabricCanvasToVectorPdf = exportFabricCanvasToVectorPdf;
|
|
|
4763
4793
|
exports.exportMultiPagePdf = exportMultiPagePdf;
|
|
4764
4794
|
exports.preparePagesForExport = preparePagesForExport;
|
|
4765
4795
|
exports.rewriteSvgFontsForJsPDFWithSourceMeta = rewriteSvgFontsForJsPDFWithSourceMeta;
|
|
4766
|
-
//# sourceMappingURL=vectorPdfExport-
|
|
4796
|
+
//# sourceMappingURL=vectorPdfExport-yAT4k3Je.cjs.map
|