@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.js
CHANGED
|
@@ -12972,53 +12972,10 @@ function applyContentBoundsPagination(config) {
|
|
|
12972
12972
|
if (!mutated) return config;
|
|
12973
12973
|
return { ...config, pages: resultPages };
|
|
12974
12974
|
}
|
|
12975
|
-
const FONTSHARE_SLUGS = {
|
|
12976
|
-
"Satoshi": "satoshi",
|
|
12977
|
-
"Cabinet Grotesk": "cabinet-grotesk",
|
|
12978
|
-
"Clash Display": "clash-display",
|
|
12979
|
-
"Clash Grotesk": "clash-grotesk",
|
|
12980
|
-
"General Sans": "general-sans",
|
|
12981
|
-
"Switzer": "switzer",
|
|
12982
|
-
"Supreme": "supreme",
|
|
12983
|
-
"Author": "author",
|
|
12984
|
-
"Boska": "boska",
|
|
12985
|
-
"Excon": "excon",
|
|
12986
|
-
"Khand": "khand",
|
|
12987
|
-
"Sentient": "sentient",
|
|
12988
|
-
"Synonym": "synonym",
|
|
12989
|
-
"Erode": "erode",
|
|
12990
|
-
"Ranade": "ranade",
|
|
12991
|
-
"Tanker": "tanker",
|
|
12992
|
-
"Zodiak": "zodiak",
|
|
12993
|
-
"Gambarino": "gambarino",
|
|
12994
|
-
"Melodrama": "melodrama",
|
|
12995
|
-
"Bespoke Serif": "bespoke-serif",
|
|
12996
|
-
"Bespoke Stencil": "bespoke-stencil",
|
|
12997
|
-
"Panchang": "panchang",
|
|
12998
|
-
"Quincy CF": "quincy-cf",
|
|
12999
|
-
"Pally": "pally",
|
|
13000
|
-
"Tabular": "tabular",
|
|
13001
|
-
"Sharpie": "sharpie",
|
|
13002
|
-
"Stardom": "stardom",
|
|
13003
|
-
"Rebond Grotesque": "rebond-grotesque",
|
|
13004
|
-
"Telma": "telma",
|
|
13005
|
-
"Nippo": "nippo"
|
|
13006
|
-
};
|
|
13007
12975
|
function normalizeFontFamily(fontStack) {
|
|
13008
12976
|
const first = fontStack.split(",")[0].trim();
|
|
13009
12977
|
return first.replace(/^['"]|['"]$/g, "");
|
|
13010
12978
|
}
|
|
13011
|
-
function appendStylesheet(url, rejectOnError = true) {
|
|
13012
|
-
return new Promise((resolve, reject) => {
|
|
13013
|
-
const link = document.createElement("link");
|
|
13014
|
-
link.rel = "stylesheet";
|
|
13015
|
-
link.href = url;
|
|
13016
|
-
link.crossOrigin = "anonymous";
|
|
13017
|
-
link.onload = () => resolve();
|
|
13018
|
-
link.onerror = () => rejectOnError ? reject(new Error(`Failed to load stylesheet: ${url}`)) : resolve();
|
|
13019
|
-
document.head.appendChild(link);
|
|
13020
|
-
});
|
|
13021
|
-
}
|
|
13022
12979
|
const loadedFonts = /* @__PURE__ */ new Set();
|
|
13023
12980
|
const loadingPromises = /* @__PURE__ */ new Map();
|
|
13024
12981
|
function withTimeout(promise, timeoutMs = 4e3) {
|
|
@@ -13041,22 +12998,11 @@ async function loadGoogleFontCSS(rawFontFamily) {
|
|
|
13041
12998
|
if (existing) return existing;
|
|
13042
12999
|
const promise = (async () => {
|
|
13043
13000
|
try {
|
|
13044
|
-
|
|
13045
|
-
if (fontshareSlug) {
|
|
13046
|
-
const url2 = `https://api.fontshare.com/v2/css?f[]=${fontshareSlug}@300,400,500,700&display=swap`;
|
|
13047
|
-
await appendStylesheet(url2);
|
|
13048
|
-
const italicUrl = `https://api.fontshare.com/v2/css?f[]=${fontshareSlug}@300i,400i,500i,700i&display=swap`;
|
|
13049
|
-
await withTimeout(appendStylesheet(italicUrl, false), 1500);
|
|
13001
|
+
if (LOCAL_FONTS.has(fontFamily)) {
|
|
13050
13002
|
loadedFonts.add(fontFamily);
|
|
13051
13003
|
return;
|
|
13052
13004
|
}
|
|
13053
|
-
|
|
13054
|
-
const url = `https://fonts.googleapis.com/css?family=${encoded}:300,400,500,600,700&display=swap`;
|
|
13055
|
-
await appendStylesheet(url);
|
|
13056
|
-
await withTimeout(Promise.all([300, 400, 500, 600, 700].map((weight) => {
|
|
13057
|
-
const italicUrl = `https://fonts.googleapis.com/css2?family=${encoded}:ital,wght@1,${weight}&display=swap`;
|
|
13058
|
-
return appendStylesheet(italicUrl, false);
|
|
13059
|
-
})), 1800);
|
|
13005
|
+
await withTimeout(loadFont(fontFamily), 4e3);
|
|
13060
13006
|
loadedFonts.add(fontFamily);
|
|
13061
13007
|
} catch (e) {
|
|
13062
13008
|
console.warn(`[@pixldocs/canvas-renderer] Font load failed: ${fontFamily}`, e);
|
|
@@ -15895,6 +15841,23 @@ async function embedFontsForConfig(pdf, config, fontBaseUrl) {
|
|
|
15895
15841
|
addFontVariant(el.fontFamily, 700, false);
|
|
15896
15842
|
addFontVariant(el.fontFamily, 400, true);
|
|
15897
15843
|
addFontVariant(el.fontFamily, 700, true);
|
|
15844
|
+
if (el.formattingEnabled === true && typeof el.text === "string") {
|
|
15845
|
+
try {
|
|
15846
|
+
const parsed = parseTextMarkdown(el.text);
|
|
15847
|
+
for (const lineStyles of Object.values(parsed.styles || {})) {
|
|
15848
|
+
if (!lineStyles || typeof lineStyles !== "object") continue;
|
|
15849
|
+
for (const s of Object.values(lineStyles)) {
|
|
15850
|
+
if (!s) continue;
|
|
15851
|
+
const family = s.fontFamily || el.fontFamily;
|
|
15852
|
+
if (!family) continue;
|
|
15853
|
+
const ww = normalizeWeight(s.fontWeight ?? el.fontWeight);
|
|
15854
|
+
const it = /italic|oblique/i.test(String(s.fontStyle ?? el.fontStyle ?? ""));
|
|
15855
|
+
addFontVariant(family, ww, it);
|
|
15856
|
+
}
|
|
15857
|
+
}
|
|
15858
|
+
} catch {
|
|
15859
|
+
}
|
|
15860
|
+
}
|
|
15898
15861
|
}
|
|
15899
15862
|
if (el.styles && typeof el.styles === "object") {
|
|
15900
15863
|
for (const lineKey of Object.keys(el.styles)) {
|