@pixldocs/canvas-renderer 0.5.119 → 0.5.121
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-81pAjQOk.cjs → index-D1vSAOoA.cjs} +5 -4
- package/dist/{index-81pAjQOk.cjs.map → index-D1vSAOoA.cjs.map} +1 -1
- package/dist/{index-CuTWdeXZ.js → index-O3pWbOEB.js} +36 -35
- package/dist/{index-CuTWdeXZ.js.map → index-O3pWbOEB.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-CHHpRsRK.cjs → pdfFonts-CGJbTRCQ.cjs} +40 -3
- package/dist/pdfFonts-CGJbTRCQ.cjs.map +1 -0
- package/dist/{pdfFonts-CB5z77qO.js → pdfFonts-CiKT_ha_.js} +47 -10
- package/dist/pdfFonts-CiKT_ha_.js.map +1 -0
- package/dist/{svgTextToPath-B6FmPvcr.js → svgTextToPath-BUX6rrUo.js} +2 -2
- package/dist/{svgTextToPath-B6FmPvcr.js.map → svgTextToPath-BUX6rrUo.js.map} +1 -1
- package/dist/{svgTextToPath-B77kYzHp.cjs → svgTextToPath-Ce8QSoUf.cjs} +2 -2
- package/dist/{svgTextToPath-B77kYzHp.cjs.map → svgTextToPath-Ce8QSoUf.cjs.map} +1 -1
- package/dist/{vectorPdfExport-CyJXH2cR.cjs → vectorPdfExport-CPu9f6GR.cjs} +57 -27
- package/dist/vectorPdfExport-CPu9f6GR.cjs.map +1 -0
- package/dist/{vectorPdfExport-BrHHt_7L.js → vectorPdfExport-CganHKyZ.js} +57 -27
- package/dist/vectorPdfExport-CganHKyZ.js.map +1 -0
- package/package.json +1 -1
- package/dist/pdfFonts-CB5z77qO.js.map +0 -1
- package/dist/pdfFonts-CHHpRsRK.cjs.map +0 -1
- package/dist/vectorPdfExport-BrHHt_7L.js.map +0 -1
- package/dist/vectorPdfExport-CyJXH2cR.cjs.map +0 -1
|
@@ -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, f as findNodeById, a as getAbsoluteBounds,
|
|
5
|
-
import { F as FONT_FALLBACK_SYMBOLS, a as FONT_FALLBACK_MATH, b as FONT_FALLBACK_DEVANAGARI, e as embedFontWithGoogleFallback, i as isFontAvailable, c as isFamilyEmbedded,
|
|
4
|
+
import { g as getCanvasForPage, f as findNodeById, a as getAbsoluteBounds, p as parseTextMarkdown, r as renderSmartElementToSvg, n as normalizeShapeType, h as hasEdgeFade, b as getProxiedImageUrl, c as bakeEdgeFade, i as isElement, d as isGroup, e as buildRoundedTrianglePath, A as API_URL, j as getImageProxyFetchOptions, k as getRoundedRectRadii, T as TRIANGLE_STROKE_MITER_LIMIT, l as getTrianglePoints } from "./index-O3pWbOEB.js";
|
|
5
|
+
import { r as resetPdfFontRegistry, F as FONT_FALLBACK_SYMBOLS, a as FONT_FALLBACK_MATH, b as FONT_FALLBACK_DEVANAGARI, e as embedFontWithGoogleFallback, i as isFontAvailable, c as isFamilyEmbedded, d as resolveBestRegisteredVariant, g as getEmbeddedJsPDFFontName, f as resolveFontWeight, h as doesVariantSupportChar } from "./pdfFonts-CiKT_ha_.js";
|
|
6
6
|
async function bakeEdgeFadeIntoDataUrl(dataUrl, element) {
|
|
7
7
|
const fade = element;
|
|
8
8
|
if (!hasEdgeFade(fade)) return null;
|
|
@@ -40,6 +40,54 @@ function pdfWithColorLogging(pdf, seq, elementId) {
|
|
|
40
40
|
return pdf;
|
|
41
41
|
}
|
|
42
42
|
const FONT_KEY_SEP = "";
|
|
43
|
+
function normalizePdfFontWeight(raw) {
|
|
44
|
+
if (typeof raw === "number" && Number.isFinite(raw)) return resolveFontWeight(raw);
|
|
45
|
+
const str = String(raw ?? "").trim().toLowerCase();
|
|
46
|
+
const parsed = Number.parseInt(str, 10);
|
|
47
|
+
if (Number.isFinite(parsed)) return resolveFontWeight(parsed);
|
|
48
|
+
if (str === "bold" || str === "bolder") return 700;
|
|
49
|
+
if (str === "semibold" || str === "demibold") return 600;
|
|
50
|
+
if (str === "medium") return 500;
|
|
51
|
+
if (str === "light" || str === "lighter" || str === "thin") return 300;
|
|
52
|
+
return 400;
|
|
53
|
+
}
|
|
54
|
+
function collectTextFontVariantsForPdf(el, fontKeysNeeded, italicKeysNeeded) {
|
|
55
|
+
var _a, _b, _c;
|
|
56
|
+
const baseFamily = (el == null ? void 0 : el.fontFamily) || ((_a = el == null ? void 0 : el.style) == null ? void 0 : _a.fontFamily);
|
|
57
|
+
if (!baseFamily) return;
|
|
58
|
+
const addVariant = (family, weightRaw, styleRaw) => {
|
|
59
|
+
const resolved = normalizePdfFontWeight(weightRaw);
|
|
60
|
+
if (/italic|oblique/i.test(String(styleRaw ?? ""))) {
|
|
61
|
+
italicKeysNeeded.add(`${family}${FONT_KEY_SEP}${resolved}${FONT_KEY_SEP}italic`);
|
|
62
|
+
} else {
|
|
63
|
+
fontKeysNeeded.add(`${family}${FONT_KEY_SEP}${resolved}`);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
addVariant(baseFamily, el.fontWeight ?? ((_b = el.style) == null ? void 0 : _b.fontWeight) ?? 400, el.fontStyle ?? ((_c = el.style) == null ? void 0 : _c.fontStyle) ?? "normal");
|
|
67
|
+
const styles = el.styles;
|
|
68
|
+
if (styles && typeof styles === "object") {
|
|
69
|
+
for (const lineStyles of Object.values(styles)) {
|
|
70
|
+
if (!lineStyles || typeof lineStyles !== "object") continue;
|
|
71
|
+
for (const s of Object.values(lineStyles)) {
|
|
72
|
+
if (!s || typeof s !== "object") continue;
|
|
73
|
+
addVariant(s.fontFamily || baseFamily, s.fontWeight ?? el.fontWeight ?? 400, s.fontStyle ?? el.fontStyle ?? "normal");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (el.formattingEnabled === true && typeof el.text === "string") {
|
|
78
|
+
try {
|
|
79
|
+
const parsed = parseTextMarkdown(el.text);
|
|
80
|
+
for (const lineStyles of Object.values(parsed.styles || {})) {
|
|
81
|
+
if (!lineStyles || typeof lineStyles !== "object") continue;
|
|
82
|
+
for (const s of Object.values(lineStyles)) {
|
|
83
|
+
if (!s || typeof s !== "object") continue;
|
|
84
|
+
addVariant(s.fontFamily || baseFamily, s.fontWeight ?? el.fontWeight ?? 400, s.fontStyle ?? el.fontStyle ?? "normal");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
43
91
|
function isBasicLatinOrLatin1(char) {
|
|
44
92
|
const c = char.codePointAt(0) ?? 0;
|
|
45
93
|
return c >= 32 && c <= 126 || c >= 160 && c <= 255;
|
|
@@ -1974,7 +2022,7 @@ async function fetchSvgAsElement(imageUrl, colorMap) {
|
|
|
1974
2022
|
async function getRecoloredSvgDataUrl(imageUrl, colorMap) {
|
|
1975
2023
|
if (!colorMap || Object.keys(colorMap).length === 0) return null;
|
|
1976
2024
|
try {
|
|
1977
|
-
const { getNormalizedSvgUrl } = await import("./index-
|
|
2025
|
+
const { getNormalizedSvgUrl } = await import("./index-O3pWbOEB.js").then((n) => n.Z);
|
|
1978
2026
|
return await getNormalizedSvgUrl(imageUrl, colorMap);
|
|
1979
2027
|
} catch {
|
|
1980
2028
|
return null;
|
|
@@ -2755,7 +2803,7 @@ async function fetchImageAsBase64(imageUrl, opts = {}) {
|
|
|
2755
2803
|
}
|
|
2756
2804
|
let fetchUrl = imageUrl;
|
|
2757
2805
|
if (imageUrl.startsWith("http://") || imageUrl.startsWith("https://")) {
|
|
2758
|
-
const { isPrivateUrl } = await import("./index-
|
|
2806
|
+
const { isPrivateUrl } = await import("./index-O3pWbOEB.js").then((n) => n.Z);
|
|
2759
2807
|
if (isPrivateUrl(imageUrl)) return null;
|
|
2760
2808
|
const proxyUrl = new URL(`${API_URL}/image-proxy`);
|
|
2761
2809
|
proxyUrl.searchParams.set("url", imageUrl);
|
|
@@ -4248,6 +4296,7 @@ async function drawElementContentCore(pdf, element, norm, x, y, w, h, embeddedFo
|
|
|
4248
4296
|
}
|
|
4249
4297
|
async function exportFabricCanvasToVectorPdf(_fabricCanvas, options) {
|
|
4250
4298
|
const { filename = "document.pdf", width, height, title, elements, backgroundColor } = options;
|
|
4299
|
+
resetPdfFontRegistry();
|
|
4251
4300
|
const orientation = width > height ? "landscape" : "portrait";
|
|
4252
4301
|
const pdf = new jsPDF({
|
|
4253
4302
|
orientation,
|
|
@@ -4269,18 +4318,8 @@ async function exportFabricCanvasToVectorPdf(_fabricCanvas, options) {
|
|
|
4269
4318
|
const fontKeysNeeded = /* @__PURE__ */ new Set();
|
|
4270
4319
|
const italicKeysNeeded = /* @__PURE__ */ new Set();
|
|
4271
4320
|
elements.forEach((el) => {
|
|
4272
|
-
var _a;
|
|
4273
4321
|
if (el.type === "text") {
|
|
4274
|
-
|
|
4275
|
-
const { fontFamily, fontWeight } = norm;
|
|
4276
|
-
if (fontFamily) {
|
|
4277
|
-
const resolved = resolveFontWeight(fontWeight ?? 400);
|
|
4278
|
-
fontKeysNeeded.add(`${fontFamily}${FONT_KEY_SEP}${resolved}`);
|
|
4279
|
-
const fontStyleRaw = el.fontStyle || ((_a = el.style) == null ? void 0 : _a.fontStyle) || "normal";
|
|
4280
|
-
if (fontStyleRaw === "italic") {
|
|
4281
|
-
italicKeysNeeded.add(`${fontFamily}${FONT_KEY_SEP}${resolved}${FONT_KEY_SEP}italic`);
|
|
4282
|
-
}
|
|
4283
|
-
}
|
|
4322
|
+
collectTextFontVariantsForPdf(el, fontKeysNeeded, italicKeysNeeded);
|
|
4284
4323
|
}
|
|
4285
4324
|
});
|
|
4286
4325
|
fontKeysNeeded.add(`${FONT_FALLBACK_SYMBOLS}${FONT_KEY_SEP}400`);
|
|
@@ -4367,6 +4406,7 @@ function preparePagesForExport(pages, canvasWidth, canvasHeight, options) {
|
|
|
4367
4406
|
async function exportMultiPagePdf(pages, options) {
|
|
4368
4407
|
var _a, _b, _c, _d, _e;
|
|
4369
4408
|
const { filename = "document.pdf", title, watermark = false, returnBlob = false } = options;
|
|
4409
|
+
resetPdfFontRegistry();
|
|
4370
4410
|
if (pages.length === 0) {
|
|
4371
4411
|
throw new Error("No pages to export");
|
|
4372
4412
|
}
|
|
@@ -4386,18 +4426,8 @@ async function exportMultiPagePdf(pages, options) {
|
|
|
4386
4426
|
const italicKeysNeeded = /* @__PURE__ */ new Set();
|
|
4387
4427
|
pages.forEach((page) => {
|
|
4388
4428
|
page.elements.forEach((item) => {
|
|
4389
|
-
var _a2;
|
|
4390
4429
|
if (!isGroupBackgroundDrawable(item) && item.type === "text") {
|
|
4391
|
-
|
|
4392
|
-
const { fontFamily, fontWeight } = norm;
|
|
4393
|
-
if (fontFamily) {
|
|
4394
|
-
const resolved = resolveFontWeight(fontWeight ?? 400);
|
|
4395
|
-
fontKeysNeeded.add(`${fontFamily}${FONT_KEY_SEP}${resolved}`);
|
|
4396
|
-
const fontStyleRaw = item.fontStyle || ((_a2 = item.style) == null ? void 0 : _a2.fontStyle) || "normal";
|
|
4397
|
-
if (fontStyleRaw === "italic") {
|
|
4398
|
-
italicKeysNeeded.add(`${fontFamily}${FONT_KEY_SEP}${resolved}${FONT_KEY_SEP}italic`);
|
|
4399
|
-
}
|
|
4400
|
-
}
|
|
4430
|
+
collectTextFontVariantsForPdf(item, fontKeysNeeded, italicKeysNeeded);
|
|
4401
4431
|
}
|
|
4402
4432
|
});
|
|
4403
4433
|
});
|
|
@@ -4746,4 +4776,4 @@ export {
|
|
|
4746
4776
|
preparePagesForExport,
|
|
4747
4777
|
rewriteSvgFontsForJsPDFWithSourceMeta
|
|
4748
4778
|
};
|
|
4749
|
-
//# sourceMappingURL=vectorPdfExport-
|
|
4779
|
+
//# sourceMappingURL=vectorPdfExport-CganHKyZ.js.map
|