@pixldocs/canvas-renderer 0.5.93 → 0.5.94

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 CHANGED
@@ -2612,10 +2612,10 @@ async function loadGoogleFont(fontFamily, weights) {
2612
2612
  if (LOCAL_FONTS.has(fontFamily)) return true;
2613
2613
  if (loadedGoogleFonts.has(fontFamily)) return true;
2614
2614
  if (failedGoogleFonts.has(fontFamily)) return false;
2615
- const existing = loadingPromises$1.get(fontFamily);
2615
+ const existing = loadingPromises$1.get(`google:${fontFamily}`);
2616
2616
  if (existing) return existing;
2617
- const promise = _doLoadGoogleFont(fontFamily, weights);
2618
- loadingPromises$1.set(fontFamily, promise);
2617
+ const promise = _doLoadGoogleFont(fontFamily);
2618
+ loadingPromises$1.set(`google:${fontFamily}`, promise);
2619
2619
  try {
2620
2620
  const result = await promise;
2621
2621
  if (result) {
@@ -2625,38 +2625,46 @@ async function loadGoogleFont(fontFamily, weights) {
2625
2625
  }
2626
2626
  return result;
2627
2627
  } finally {
2628
- loadingPromises$1.delete(fontFamily);
2628
+ loadingPromises$1.delete(`google:${fontFamily}`);
2629
2629
  }
2630
2630
  }
2631
- async function _doLoadGoogleFont(fontFamily, weights) {
2632
- try {
2633
- const weightStr = (weights || [300, 400, 500, 600, 700]).join(";");
2634
- const encodedFamily = encodeURIComponent(fontFamily);
2635
- const url = `https://fonts.googleapis.com/css2?family=${encodedFamily}:ital,wght@0,${weightStr};1,${weightStr}&display=swap`;
2636
- const existingLink = document.querySelector(`link[href="${url}"]`);
2637
- if (existingLink) return true;
2631
+ function tryInjectGoogleFontsLink(url, fontFamily) {
2632
+ if (document.querySelector(`link[href="${url}"]`)) return Promise.resolve(true);
2633
+ return new Promise((resolve) => {
2638
2634
  const link = document.createElement("link");
2639
2635
  link.rel = "stylesheet";
2640
2636
  link.href = url;
2641
- return new Promise((resolve) => {
2642
- link.onload = async () => {
2643
- try {
2644
- await document.fonts.load(`16px "${fontFamily}"`);
2645
- await document.fonts.load(`bold 16px "${fontFamily}"`);
2646
- } catch {
2647
- }
2648
- resolve(true);
2649
- };
2650
- link.onerror = () => {
2651
- console.warn(`[GoogleFonts] Failed to load: ${fontFamily}`);
2652
- resolve(false);
2653
- };
2654
- document.head.appendChild(link);
2655
- });
2656
- } catch (e) {
2657
- console.warn(`[GoogleFonts] Error loading ${fontFamily}:`, e);
2658
- return false;
2637
+ link.onload = async () => {
2638
+ try {
2639
+ await document.fonts.load(`16px "${fontFamily}"`);
2640
+ } catch {
2641
+ }
2642
+ resolve(true);
2643
+ };
2644
+ link.onerror = () => resolve(false);
2645
+ document.head.appendChild(link);
2646
+ });
2647
+ }
2648
+ async function _doLoadGoogleFont(fontFamily, weights) {
2649
+ const encodedFamily = encodeURIComponent(fontFamily);
2650
+ const weightSet = [300, 400, 500, 600, 700];
2651
+ const fullWeightStr = weightSet.join(";");
2652
+ const coreWeightStr = "400;700";
2653
+ const candidates = [
2654
+ `https://fonts.googleapis.com/css2?family=${encodedFamily}:ital,wght@0,${fullWeightStr};1,${fullWeightStr}&display=swap`,
2655
+ `https://fonts.googleapis.com/css2?family=${encodedFamily}:wght@${fullWeightStr}&display=swap`,
2656
+ `https://fonts.googleapis.com/css2?family=${encodedFamily}:ital,wght@0,${coreWeightStr};1,${coreWeightStr}&display=swap`,
2657
+ `https://fonts.googleapis.com/css2?family=${encodedFamily}:wght@${coreWeightStr}&display=swap`,
2658
+ // Plainest possible URL — works for any published Google Font, even
2659
+ // single-weight display/script families like "Frijole" or "Creepster".
2660
+ `https://fonts.googleapis.com/css2?family=${encodedFamily}&display=swap`
2661
+ ];
2662
+ for (const url of candidates) {
2663
+ const ok = await tryInjectGoogleFontsLink(url, fontFamily);
2664
+ if (ok) return true;
2659
2665
  }
2666
+ console.warn(`[GoogleFonts] Failed to load: ${fontFamily}`);
2667
+ return false;
2660
2668
  }
2661
2669
  const getObjectId = (obj) => obj.__docuforgeId;
2662
2670
  const setObjectData = (obj, id) => {
@@ -5563,7 +5571,7 @@ function createText(element) {
5563
5571
  }
5564
5572
  text = result;
5565
5573
  }
5566
- const targetWidth = overflowPolicy === "auto-shrink" ? fixedWidth : Math.max(baseWidth, getMinTextWidth(element));
5574
+ const targetWidth = fixedWidth;
5567
5575
  const targetScaleX = element.scaleX ?? 1;
5568
5576
  const targetScaleY = element.scaleY ?? 1;
5569
5577
  const textbox = new fabric__namespace.Textbox(text, {
@@ -11999,6 +12007,38 @@ function applyContentBoundsPagination(config) {
11999
12007
  if (!mutated) return config;
12000
12008
  return { ...config, pages: resultPages };
12001
12009
  }
12010
+ const FONTSHARE_SLUGS = {
12011
+ "Satoshi": "satoshi",
12012
+ "Cabinet Grotesk": "cabinet-grotesk",
12013
+ "Clash Display": "clash-display",
12014
+ "Clash Grotesk": "clash-grotesk",
12015
+ "General Sans": "general-sans",
12016
+ "Switzer": "switzer",
12017
+ "Supreme": "supreme",
12018
+ "Author": "author",
12019
+ "Boska": "boska",
12020
+ "Excon": "excon",
12021
+ "Khand": "khand",
12022
+ "Sentient": "sentient",
12023
+ "Synonym": "synonym",
12024
+ "Erode": "erode",
12025
+ "Ranade": "ranade",
12026
+ "Tanker": "tanker",
12027
+ "Zodiak": "zodiak",
12028
+ "Gambarino": "gambarino",
12029
+ "Melodrama": "melodrama",
12030
+ "Bespoke Serif": "bespoke-serif",
12031
+ "Bespoke Stencil": "bespoke-stencil",
12032
+ "Panchang": "panchang",
12033
+ "Quincy CF": "quincy-cf",
12034
+ "Pally": "pally",
12035
+ "Tabular": "tabular",
12036
+ "Sharpie": "sharpie",
12037
+ "Stardom": "stardom",
12038
+ "Rebond Grotesque": "rebond-grotesque",
12039
+ "Telma": "telma",
12040
+ "Nippo": "nippo"
12041
+ };
12002
12042
  function normalizeFontFamily(fontStack) {
12003
12043
  const first = fontStack.split(",")[0].trim();
12004
12044
  return first.replace(/^['"]|['"]$/g, "");
@@ -12025,6 +12065,20 @@ async function loadGoogleFontCSS(rawFontFamily) {
12025
12065
  if (existing) return existing;
12026
12066
  const promise = (async () => {
12027
12067
  try {
12068
+ const fontshareSlug = FONTSHARE_SLUGS[fontFamily];
12069
+ if (fontshareSlug) {
12070
+ const url2 = `https://api.fontshare.com/v2/css?f[]=${fontshareSlug}@300,400,500,700&display=swap`;
12071
+ const link2 = document.createElement("link");
12072
+ link2.rel = "stylesheet";
12073
+ link2.href = url2;
12074
+ await new Promise((resolve, reject) => {
12075
+ link2.onload = () => resolve();
12076
+ link2.onerror = () => reject(new Error(`Failed to load Fontshare font: ${fontFamily}`));
12077
+ document.head.appendChild(link2);
12078
+ });
12079
+ loadedFonts.add(fontFamily);
12080
+ return;
12081
+ }
12028
12082
  const encoded = encodeURIComponent(fontFamily);
12029
12083
  const url = `https://fonts.googleapis.com/css?family=${encoded}:300,400,500,600,700&display=swap`;
12030
12084
  const link = document.createElement("link");
@@ -12179,6 +12233,7 @@ async function awaitFontsForConfig(config, maxWaitMs) {
12179
12233
  await ensureFontsForResolvedConfig(config);
12180
12234
  const descriptors = collectFontDescriptorsFromConfig(config);
12181
12235
  if (descriptors.length === 0) return;
12236
+ const overallBudget = Math.max(maxWaitMs, 5e3);
12182
12237
  const loads = Promise.all(
12183
12238
  descriptors.map((d) => {
12184
12239
  const stylePrefix = d.style === "italic" ? "italic " : "";
@@ -12188,11 +12243,11 @@ async function awaitFontsForConfig(config, maxWaitMs) {
12188
12243
  ).then(() => void 0);
12189
12244
  await Promise.race([
12190
12245
  loads,
12191
- new Promise((resolve) => setTimeout(resolve, maxWaitMs))
12246
+ new Promise((resolve) => setTimeout(resolve, overallBudget))
12192
12247
  ]);
12193
12248
  await Promise.race([
12194
12249
  document.fonts.ready.catch(() => void 0).then(() => void 0),
12195
- new Promise((r) => setTimeout(r, Math.min(500, maxWaitMs)))
12250
+ new Promise((r) => setTimeout(r, 1500))
12196
12251
  ]);
12197
12252
  const checkSpecs = [];
12198
12253
  for (const d of descriptors) {
@@ -12200,7 +12255,7 @@ async function awaitFontsForConfig(config, maxWaitMs) {
12200
12255
  checkSpecs.push(`${stylePrefix}${d.weight} 16px "${d.family}"`);
12201
12256
  }
12202
12257
  const startedAt = Date.now();
12203
- const pollBudget = Math.min(maxWaitMs, 2500);
12258
+ const pollBudget = 2500;
12204
12259
  const allReady = () => {
12205
12260
  for (const spec of checkSpecs) {
12206
12261
  try {
@@ -16305,7 +16360,7 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
16305
16360
  }
16306
16361
  if (shouldOutlineText) {
16307
16362
  try {
16308
- const { convertAllTextToPath } = await Promise.resolve().then(() => require("./svgTextToPath-B4SihUQv.cjs"));
16363
+ const { convertAllTextToPath } = await Promise.resolve().then(() => require("./svgTextToPath-CWlhIf-q.cjs"));
16309
16364
  pageSvg = await convertAllTextToPath(pageSvg, fontBaseUrl, { mode: outlineSubMode });
16310
16365
  try {
16311
16366
  dumpSvgTextDiagnostics(pageSvg, i, PARITY_TAG, "STAGE-1b-after-text-to-path-raw");