@pixldocs/canvas-renderer 0.5.132 → 0.5.134
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-4IzWx9f-.cjs → index-DmqoeVsF.cjs} +143 -15
- package/dist/index-DmqoeVsF.cjs.map +1 -0
- package/dist/{index-TWLUgM18.js → index-Sc4qRn5o.js} +143 -15
- package/dist/index-Sc4qRn5o.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{pdfFonts-Cr8l-y3z.cjs → pdfFonts-BU2Lqz_O.cjs} +36 -11
- package/dist/{pdfFonts-Cr8l-y3z.cjs.map → pdfFonts-BU2Lqz_O.cjs.map} +1 -1
- package/dist/{pdfFonts-Y49FLHuG.js → pdfFonts-BVHbPFEz.js} +36 -11
- package/dist/{pdfFonts-Y49FLHuG.js.map → pdfFonts-BVHbPFEz.js.map} +1 -1
- package/dist/{svgTextToPath-Bne0QyE7.js → svgTextToPath-DG7rcbDE.js} +2 -2
- package/dist/{svgTextToPath-Bne0QyE7.js.map → svgTextToPath-DG7rcbDE.js.map} +1 -1
- package/dist/{svgTextToPath-D6xJoPO2.cjs → svgTextToPath-GeR0CexD.cjs} +2 -2
- package/dist/{svgTextToPath-D6xJoPO2.cjs.map → svgTextToPath-GeR0CexD.cjs.map} +1 -1
- package/dist/{vectorPdfExport-BmqYmqUF.cjs → vectorPdfExport-8Q3O7Z_Q.cjs} +8 -31
- package/dist/vectorPdfExport-8Q3O7Z_Q.cjs.map +1 -0
- package/dist/{vectorPdfExport-3QFNDStb.js → vectorPdfExport-BA6bhLs-.js} +8 -31
- package/dist/vectorPdfExport-BA6bhLs-.js.map +1 -0
- package/package.json +1 -1
- package/dist/index-4IzWx9f-.cjs.map +0 -1
- package/dist/index-TWLUgM18.js.map +0 -1
- package/dist/vectorPdfExport-3QFNDStb.js.map +0 -1
- package/dist/vectorPdfExport-BmqYmqUF.cjs.map +0 -1
|
@@ -5712,7 +5712,8 @@ function applyTextBackground(obj, cfg) {
|
|
|
5712
5712
|
const dataAttrs = `data-blur="${blur.toFixed(3)}" data-ox="${ox.toFixed(3)}" data-oy="${oy.toFixed(3)}" data-bx="${bx.toFixed(3)}" data-by="${by.toFixed(3)}" data-bw="${bw.toFixed(3)}" data-bh="${bh.toFixed(3)}" data-color="${escapeXmlAttr(shadowColor)}"`;
|
|
5713
5713
|
const wrapShadow = (markup) => blur <= 0 ? `<g transform="translate(${ox.toFixed(3)} ${oy.toFixed(3)})">${markup}</g>` : `<g class="__pdShadowRaster" ${dataAttrs}>${markup}</g>`;
|
|
5714
5714
|
if (hasBg && (bg == null ? void 0 : bg.shadowAffectsBg) !== false) {
|
|
5715
|
-
const
|
|
5715
|
+
const shadowOpacityAttr = bgOpacity < 1 ? ` fill-opacity="${bgOpacity}"` : "";
|
|
5716
|
+
const shadowBgPath = `<path d="${bgD}" fill="${escapeXmlAttr(shadowColor)}"${shadowOpacityAttr} />`;
|
|
5716
5717
|
bgShadowMarker = wrapShadow(shadowBgPath);
|
|
5717
5718
|
}
|
|
5718
5719
|
if ((bg == null ? void 0 : bg.shadowAffectsText) !== false) {
|
|
@@ -14013,7 +14014,8 @@ async function fetchGoogleFontTTF(fontFamily, weight, isItalic = false) {
|
|
|
14013
14014
|
async function fetchFontshareTTF(fontFamily, weight, isItalic = false) {
|
|
14014
14015
|
const cacheKey = `fs:${fontFamily}:${weight}:${isItalic ? "i" : "n"}`;
|
|
14015
14016
|
if (ttfCache.has(cacheKey)) return ttfCache.get(cacheKey);
|
|
14016
|
-
|
|
14017
|
+
const notFoundKey = remoteVariantKey(fontFamily, weight, isItalic);
|
|
14018
|
+
if (fontshareNotFound.has(notFoundKey)) return null;
|
|
14017
14019
|
const slug = fontFamily.trim().toLowerCase().replace(/\s+/g, "-");
|
|
14018
14020
|
const proxyBytes = await fetchTtfViaProxy(fontFamily, weight, isItalic, "fontshare");
|
|
14019
14021
|
if (proxyBytes) {
|
|
@@ -14026,13 +14028,13 @@ async function fetchFontshareTTF(fontFamily, weight, isItalic = false) {
|
|
|
14026
14028
|
const cssUrl = `https://api.fontshare.com/v2/css?f[]=${slug}@${weight}${styleSuffix}&display=swap`;
|
|
14027
14029
|
const cssRes = await fetch(cssUrl);
|
|
14028
14030
|
if (!cssRes.ok) {
|
|
14029
|
-
if (cssRes.status === 400 || cssRes.status === 404) fontshareNotFound.add(
|
|
14031
|
+
if (cssRes.status === 400 || cssRes.status === 404) fontshareNotFound.add(notFoundKey);
|
|
14030
14032
|
return null;
|
|
14031
14033
|
}
|
|
14032
14034
|
const css = await cssRes.text();
|
|
14033
14035
|
const ttMatch = css.match(/url\(([^)]+)\)\s+format\(['"]?truetype['"]?\)/i);
|
|
14034
14036
|
if (!ttMatch) {
|
|
14035
|
-
fontshareNotFound.add(
|
|
14037
|
+
fontshareNotFound.add(notFoundKey);
|
|
14036
14038
|
return null;
|
|
14037
14039
|
}
|
|
14038
14040
|
let ttfUrl = ttMatch[1].replace(/['"]/g, "").trim();
|
|
@@ -14079,11 +14081,38 @@ async function embedFontWithGoogleFallback(pdf, fontName, weight = 400, fontBase
|
|
|
14079
14081
|
if (ok) return true;
|
|
14080
14082
|
}
|
|
14081
14083
|
const resolved = resolveFontWeight(weight);
|
|
14082
|
-
const
|
|
14083
|
-
|
|
14084
|
-
|
|
14085
|
-
|
|
14086
|
-
|
|
14084
|
+
const weightLadder = [resolved];
|
|
14085
|
+
for (const w of [400, 500, 700, 600, 300]) {
|
|
14086
|
+
if (!weightLadder.includes(w)) weightLadder.push(w);
|
|
14087
|
+
}
|
|
14088
|
+
const tryFetch = async (w, italic) => {
|
|
14089
|
+
const fs = await fetchFontshareTTF(fontName, w, italic);
|
|
14090
|
+
if (fs) return fs;
|
|
14091
|
+
const g = await fetchGoogleFontTTF(fontName, w, italic);
|
|
14092
|
+
return g;
|
|
14093
|
+
};
|
|
14094
|
+
let b64 = null;
|
|
14095
|
+
let usedItalic = isItalic;
|
|
14096
|
+
let usedWeight = resolved;
|
|
14097
|
+
for (const w of weightLadder) {
|
|
14098
|
+
b64 = await tryFetch(w, isItalic);
|
|
14099
|
+
if (b64) {
|
|
14100
|
+
usedWeight = w;
|
|
14101
|
+
break;
|
|
14102
|
+
}
|
|
14103
|
+
}
|
|
14104
|
+
if (!b64 && isItalic) {
|
|
14105
|
+
for (const w of weightLadder) {
|
|
14106
|
+
b64 = await tryFetch(w, false);
|
|
14107
|
+
if (b64) {
|
|
14108
|
+
usedItalic = false;
|
|
14109
|
+
usedWeight = w;
|
|
14110
|
+
break;
|
|
14111
|
+
}
|
|
14112
|
+
}
|
|
14113
|
+
}
|
|
14114
|
+
if (!b64) return false;
|
|
14115
|
+
return registerJsPdfFont(pdf, fontName, usedWeight, usedItalic, b64);
|
|
14087
14116
|
}
|
|
14088
14117
|
async function embedFontsForConfig(pdf, config, fontBaseUrl) {
|
|
14089
14118
|
const fontKeys = /* @__PURE__ */ new Set();
|
|
@@ -16185,7 +16214,7 @@ class PixldocsRenderer {
|
|
|
16185
16214
|
await this.waitForCanvasScene(container, cloned, i);
|
|
16186
16215
|
}
|
|
16187
16216
|
console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
|
|
16188
|
-
const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-
|
|
16217
|
+
const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-BA6bhLs-.js");
|
|
16189
16218
|
const prepared = preparePagesForExport(
|
|
16190
16219
|
cloned.pages,
|
|
16191
16220
|
canvasWidth,
|
|
@@ -18023,7 +18052,7 @@ async function rasterizeShadowMarkers(svg) {
|
|
|
18023
18052
|
if ((_a = document.fonts) == null ? void 0 : _a.ready) await document.fonts.ready;
|
|
18024
18053
|
} catch {
|
|
18025
18054
|
}
|
|
18026
|
-
const fontFaceCss =
|
|
18055
|
+
const fontFaceCss = await collectInlinedFontFaceCss();
|
|
18027
18056
|
for (const marker of markers) {
|
|
18028
18057
|
try {
|
|
18029
18058
|
const blur = parseFloat(marker.getAttribute("data-blur") || "0");
|
|
@@ -18037,7 +18066,9 @@ async function rasterizeShadowMarkers(svg) {
|
|
|
18037
18066
|
(_b = marker.parentNode) == null ? void 0 : _b.removeChild(marker);
|
|
18038
18067
|
continue;
|
|
18039
18068
|
}
|
|
18040
|
-
const innerXml =
|
|
18069
|
+
const innerXml = restoreSourceFontsForShadowRaster(
|
|
18070
|
+
Array.from(marker.childNodes).map((n) => n instanceof Element ? new XMLSerializer().serializeToString(n) : "").join("")
|
|
18071
|
+
);
|
|
18041
18072
|
try {
|
|
18042
18073
|
const fontSpecs = collectFontSpecsFromMarkup(innerXml);
|
|
18043
18074
|
if (fontSpecs.length > 0 && ((_c = document.fonts) == null ? void 0 : _c.load)) {
|
|
@@ -18148,6 +18179,103 @@ function collectDocumentFontFaceCss() {
|
|
|
18148
18179
|
cachedFontFaceCss = out.join("\n");
|
|
18149
18180
|
return cachedFontFaceCss;
|
|
18150
18181
|
}
|
|
18182
|
+
let cachedInlinedFontFaceCss = null;
|
|
18183
|
+
const fontUrlDataCache = /* @__PURE__ */ new Map();
|
|
18184
|
+
async function fetchFontAsDataUri(url) {
|
|
18185
|
+
if (fontUrlDataCache.has(url)) return fontUrlDataCache.get(url) ?? null;
|
|
18186
|
+
try {
|
|
18187
|
+
const resp = await fetch(url, { mode: "cors", credentials: "omit" });
|
|
18188
|
+
if (!resp.ok) {
|
|
18189
|
+
fontUrlDataCache.set(url, null);
|
|
18190
|
+
return null;
|
|
18191
|
+
}
|
|
18192
|
+
const blob = await resp.blob();
|
|
18193
|
+
const dataUri = await new Promise((resolve, reject) => {
|
|
18194
|
+
const fr = new FileReader();
|
|
18195
|
+
fr.onload = () => resolve(String(fr.result));
|
|
18196
|
+
fr.onerror = () => reject(fr.error);
|
|
18197
|
+
fr.readAsDataURL(blob);
|
|
18198
|
+
});
|
|
18199
|
+
fontUrlDataCache.set(url, dataUri);
|
|
18200
|
+
return dataUri;
|
|
18201
|
+
} catch {
|
|
18202
|
+
fontUrlDataCache.set(url, null);
|
|
18203
|
+
return null;
|
|
18204
|
+
}
|
|
18205
|
+
}
|
|
18206
|
+
async function inlineUrlsInCss(css) {
|
|
18207
|
+
const urlRe = /url\((['"]?)([^'")]+)\1\)/gi;
|
|
18208
|
+
const matches = [];
|
|
18209
|
+
let m;
|
|
18210
|
+
while ((m = urlRe.exec(css)) !== null) {
|
|
18211
|
+
const raw = m[2].trim();
|
|
18212
|
+
if (raw.startsWith("data:")) continue;
|
|
18213
|
+
let abs = raw;
|
|
18214
|
+
try {
|
|
18215
|
+
abs = new URL(raw, document.baseURI).toString();
|
|
18216
|
+
} catch {
|
|
18217
|
+
}
|
|
18218
|
+
matches.push({ full: m[0], url: abs });
|
|
18219
|
+
}
|
|
18220
|
+
if (matches.length === 0) return css;
|
|
18221
|
+
const unique = Array.from(new Set(matches.map((mm) => mm.url)));
|
|
18222
|
+
const results = await Promise.all(unique.map((u) => fetchFontAsDataUri(u)));
|
|
18223
|
+
const map = /* @__PURE__ */ new Map();
|
|
18224
|
+
unique.forEach((u, i) => map.set(u, results[i]));
|
|
18225
|
+
let out = css;
|
|
18226
|
+
for (const { full, url } of matches) {
|
|
18227
|
+
const data = map.get(url);
|
|
18228
|
+
if (!data) continue;
|
|
18229
|
+
const safeFull = full.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
18230
|
+
out = out.replace(new RegExp(safeFull, "g"), `url("${data}")`);
|
|
18231
|
+
}
|
|
18232
|
+
return out;
|
|
18233
|
+
}
|
|
18234
|
+
async function collectInlinedFontFaceCss() {
|
|
18235
|
+
if (cachedInlinedFontFaceCss !== null) return cachedInlinedFontFaceCss;
|
|
18236
|
+
const raw = collectDocumentFontFaceCss();
|
|
18237
|
+
if (!raw) {
|
|
18238
|
+
cachedInlinedFontFaceCss = "";
|
|
18239
|
+
return "";
|
|
18240
|
+
}
|
|
18241
|
+
try {
|
|
18242
|
+
cachedInlinedFontFaceCss = await inlineUrlsInCss(raw);
|
|
18243
|
+
} catch {
|
|
18244
|
+
cachedInlinedFontFaceCss = raw;
|
|
18245
|
+
}
|
|
18246
|
+
return cachedInlinedFontFaceCss;
|
|
18247
|
+
}
|
|
18248
|
+
function restoreSourceFontsForShadowRaster(markup) {
|
|
18249
|
+
try {
|
|
18250
|
+
const parser = new DOMParser();
|
|
18251
|
+
const doc = parser.parseFromString(`<svg xmlns="http://www.w3.org/2000/svg">${markup}</svg>`, "image/svg+xml");
|
|
18252
|
+
if (doc.querySelector("parsererror")) return markup;
|
|
18253
|
+
for (const node of Array.from(doc.querySelectorAll("text, tspan, textPath"))) {
|
|
18254
|
+
const family = node.getAttribute("data-source-font-family");
|
|
18255
|
+
const weight = node.getAttribute("data-source-font-weight");
|
|
18256
|
+
const style = node.getAttribute("data-source-font-style");
|
|
18257
|
+
if (!family && !weight && !style) continue;
|
|
18258
|
+
const stylePairs = (node.getAttribute("style") || "").split(";").map((part) => part.trim()).filter(Boolean).filter((part) => !/^font-family\s*:/i.test(part) && !/^font-weight\s*:/i.test(part) && !/^font-style\s*:/i.test(part));
|
|
18259
|
+
if (family) {
|
|
18260
|
+
node.setAttribute("font-family", family);
|
|
18261
|
+
stylePairs.push(`font-family: ${family}`);
|
|
18262
|
+
}
|
|
18263
|
+
if (weight) {
|
|
18264
|
+
node.setAttribute("font-weight", weight);
|
|
18265
|
+
stylePairs.push(`font-weight: ${weight}`);
|
|
18266
|
+
}
|
|
18267
|
+
if (style) {
|
|
18268
|
+
node.setAttribute("font-style", style);
|
|
18269
|
+
stylePairs.push(`font-style: ${style}`);
|
|
18270
|
+
}
|
|
18271
|
+
if (stylePairs.length > 0) node.setAttribute("style", stylePairs.join("; "));
|
|
18272
|
+
}
|
|
18273
|
+
const root = doc.documentElement;
|
|
18274
|
+
return Array.from(root.childNodes).map((n) => n instanceof Element ? new XMLSerializer().serializeToString(n) : "").join("");
|
|
18275
|
+
} catch {
|
|
18276
|
+
return markup;
|
|
18277
|
+
}
|
|
18278
|
+
}
|
|
18151
18279
|
async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey, options) {
|
|
18152
18280
|
try {
|
|
18153
18281
|
const parser = new DOMParser();
|
|
@@ -18178,7 +18306,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
|
|
|
18178
18306
|
if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
|
|
18179
18307
|
sanitizeSvgTreeForPdf(svgToDraw);
|
|
18180
18308
|
try {
|
|
18181
|
-
const { bakeTextAnchorPositionsFromLiveSvg } = await import("./vectorPdfExport-
|
|
18309
|
+
const { bakeTextAnchorPositionsFromLiveSvg } = await import("./vectorPdfExport-BA6bhLs-.js");
|
|
18182
18310
|
await bakeTextAnchorPositionsFromLiveSvg(svgToDraw);
|
|
18183
18311
|
} catch (e) {
|
|
18184
18312
|
console.warn("[canvas-renderer][pdf-export] anchor-bake pass failed (continuing):", e);
|
|
@@ -18309,7 +18437,7 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
|
|
|
18309
18437
|
}
|
|
18310
18438
|
if (shouldOutlineText) {
|
|
18311
18439
|
try {
|
|
18312
|
-
const { convertAllTextToPath } = await import("./svgTextToPath-
|
|
18440
|
+
const { convertAllTextToPath } = await import("./svgTextToPath-DG7rcbDE.js");
|
|
18313
18441
|
pageSvg = await convertAllTextToPath(pageSvg, fontBaseUrl, { mode: outlineSubMode });
|
|
18314
18442
|
try {
|
|
18315
18443
|
dumpSvgTextDiagnostics(pageSvg, i, PARITY_TAG, "STAGE-1b-after-text-to-path-raw");
|
|
@@ -18523,4 +18651,4 @@ export {
|
|
|
18523
18651
|
collectFontDescriptorsFromConfig as y,
|
|
18524
18652
|
collectFontsFromConfig as z
|
|
18525
18653
|
};
|
|
18526
|
-
//# sourceMappingURL=index-
|
|
18654
|
+
//# sourceMappingURL=index-Sc4qRn5o.js.map
|