@pixldocs/canvas-renderer 0.5.105 → 0.5.106
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.cjs +19 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -56
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -12991,53 +12991,10 @@ function applyContentBoundsPagination(config) {
|
|
|
12991
12991
|
if (!mutated) return config;
|
|
12992
12992
|
return { ...config, pages: resultPages };
|
|
12993
12993
|
}
|
|
12994
|
-
const FONTSHARE_SLUGS = {
|
|
12995
|
-
"Satoshi": "satoshi",
|
|
12996
|
-
"Cabinet Grotesk": "cabinet-grotesk",
|
|
12997
|
-
"Clash Display": "clash-display",
|
|
12998
|
-
"Clash Grotesk": "clash-grotesk",
|
|
12999
|
-
"General Sans": "general-sans",
|
|
13000
|
-
"Switzer": "switzer",
|
|
13001
|
-
"Supreme": "supreme",
|
|
13002
|
-
"Author": "author",
|
|
13003
|
-
"Boska": "boska",
|
|
13004
|
-
"Excon": "excon",
|
|
13005
|
-
"Khand": "khand",
|
|
13006
|
-
"Sentient": "sentient",
|
|
13007
|
-
"Synonym": "synonym",
|
|
13008
|
-
"Erode": "erode",
|
|
13009
|
-
"Ranade": "ranade",
|
|
13010
|
-
"Tanker": "tanker",
|
|
13011
|
-
"Zodiak": "zodiak",
|
|
13012
|
-
"Gambarino": "gambarino",
|
|
13013
|
-
"Melodrama": "melodrama",
|
|
13014
|
-
"Bespoke Serif": "bespoke-serif",
|
|
13015
|
-
"Bespoke Stencil": "bespoke-stencil",
|
|
13016
|
-
"Panchang": "panchang",
|
|
13017
|
-
"Quincy CF": "quincy-cf",
|
|
13018
|
-
"Pally": "pally",
|
|
13019
|
-
"Tabular": "tabular",
|
|
13020
|
-
"Sharpie": "sharpie",
|
|
13021
|
-
"Stardom": "stardom",
|
|
13022
|
-
"Rebond Grotesque": "rebond-grotesque",
|
|
13023
|
-
"Telma": "telma",
|
|
13024
|
-
"Nippo": "nippo"
|
|
13025
|
-
};
|
|
13026
12994
|
function normalizeFontFamily(fontStack) {
|
|
13027
12995
|
const first = fontStack.split(",")[0].trim();
|
|
13028
12996
|
return first.replace(/^['"]|['"]$/g, "");
|
|
13029
12997
|
}
|
|
13030
|
-
function appendStylesheet(url, rejectOnError = true) {
|
|
13031
|
-
return new Promise((resolve, reject) => {
|
|
13032
|
-
const link = document.createElement("link");
|
|
13033
|
-
link.rel = "stylesheet";
|
|
13034
|
-
link.href = url;
|
|
13035
|
-
link.crossOrigin = "anonymous";
|
|
13036
|
-
link.onload = () => resolve();
|
|
13037
|
-
link.onerror = () => rejectOnError ? reject(new Error(`Failed to load stylesheet: ${url}`)) : resolve();
|
|
13038
|
-
document.head.appendChild(link);
|
|
13039
|
-
});
|
|
13040
|
-
}
|
|
13041
12998
|
const loadedFonts = /* @__PURE__ */ new Set();
|
|
13042
12999
|
const loadingPromises = /* @__PURE__ */ new Map();
|
|
13043
13000
|
function withTimeout(promise, timeoutMs = 4e3) {
|
|
@@ -13060,22 +13017,11 @@ async function loadGoogleFontCSS(rawFontFamily) {
|
|
|
13060
13017
|
if (existing) return existing;
|
|
13061
13018
|
const promise = (async () => {
|
|
13062
13019
|
try {
|
|
13063
|
-
|
|
13064
|
-
if (fontshareSlug) {
|
|
13065
|
-
const url2 = `https://api.fontshare.com/v2/css?f[]=${fontshareSlug}@300,400,500,700&display=swap`;
|
|
13066
|
-
await appendStylesheet(url2);
|
|
13067
|
-
const italicUrl = `https://api.fontshare.com/v2/css?f[]=${fontshareSlug}@300i,400i,500i,700i&display=swap`;
|
|
13068
|
-
await withTimeout(appendStylesheet(italicUrl, false), 1500);
|
|
13020
|
+
if (LOCAL_FONTS.has(fontFamily)) {
|
|
13069
13021
|
loadedFonts.add(fontFamily);
|
|
13070
13022
|
return;
|
|
13071
13023
|
}
|
|
13072
|
-
|
|
13073
|
-
const url = `https://fonts.googleapis.com/css?family=${encoded}:300,400,500,600,700&display=swap`;
|
|
13074
|
-
await appendStylesheet(url);
|
|
13075
|
-
await withTimeout(Promise.all([300, 400, 500, 600, 700].map((weight) => {
|
|
13076
|
-
const italicUrl = `https://fonts.googleapis.com/css2?family=${encoded}:ital,wght@1,${weight}&display=swap`;
|
|
13077
|
-
return appendStylesheet(italicUrl, false);
|
|
13078
|
-
})), 1800);
|
|
13024
|
+
await withTimeout(loadFont(fontFamily), 4e3);
|
|
13079
13025
|
loadedFonts.add(fontFamily);
|
|
13080
13026
|
} catch (e) {
|
|
13081
13027
|
console.warn(`[@pixldocs/canvas-renderer] Font load failed: ${fontFamily}`, e);
|
|
@@ -15914,6 +15860,23 @@ async function embedFontsForConfig(pdf, config, fontBaseUrl) {
|
|
|
15914
15860
|
addFontVariant(el.fontFamily, 700, false);
|
|
15915
15861
|
addFontVariant(el.fontFamily, 400, true);
|
|
15916
15862
|
addFontVariant(el.fontFamily, 700, true);
|
|
15863
|
+
if (el.formattingEnabled === true && typeof el.text === "string") {
|
|
15864
|
+
try {
|
|
15865
|
+
const parsed = parseTextMarkdown(el.text);
|
|
15866
|
+
for (const lineStyles of Object.values(parsed.styles || {})) {
|
|
15867
|
+
if (!lineStyles || typeof lineStyles !== "object") continue;
|
|
15868
|
+
for (const s of Object.values(lineStyles)) {
|
|
15869
|
+
if (!s) continue;
|
|
15870
|
+
const family = s.fontFamily || el.fontFamily;
|
|
15871
|
+
if (!family) continue;
|
|
15872
|
+
const ww = normalizeWeight(s.fontWeight ?? el.fontWeight);
|
|
15873
|
+
const it = /italic|oblique/i.test(String(s.fontStyle ?? el.fontStyle ?? ""));
|
|
15874
|
+
addFontVariant(family, ww, it);
|
|
15875
|
+
}
|
|
15876
|
+
}
|
|
15877
|
+
} catch {
|
|
15878
|
+
}
|
|
15879
|
+
}
|
|
15917
15880
|
}
|
|
15918
15881
|
if (el.styles && typeof el.styles === "object") {
|
|
15919
15882
|
for (const lineKey of Object.keys(el.styles)) {
|