@pixldocs/canvas-renderer 0.5.93 → 0.5.95

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.js CHANGED
@@ -2593,10 +2593,10 @@ async function loadGoogleFont(fontFamily, weights) {
2593
2593
  if (LOCAL_FONTS.has(fontFamily)) return true;
2594
2594
  if (loadedGoogleFonts.has(fontFamily)) return true;
2595
2595
  if (failedGoogleFonts.has(fontFamily)) return false;
2596
- const existing = loadingPromises$1.get(fontFamily);
2596
+ const existing = loadingPromises$1.get(`google:${fontFamily}`);
2597
2597
  if (existing) return existing;
2598
- const promise = _doLoadGoogleFont(fontFamily, weights);
2599
- loadingPromises$1.set(fontFamily, promise);
2598
+ const promise = _doLoadGoogleFont(fontFamily);
2599
+ loadingPromises$1.set(`google:${fontFamily}`, promise);
2600
2600
  try {
2601
2601
  const result = await promise;
2602
2602
  if (result) {
@@ -2606,38 +2606,46 @@ async function loadGoogleFont(fontFamily, weights) {
2606
2606
  }
2607
2607
  return result;
2608
2608
  } finally {
2609
- loadingPromises$1.delete(fontFamily);
2609
+ loadingPromises$1.delete(`google:${fontFamily}`);
2610
2610
  }
2611
2611
  }
2612
- async function _doLoadGoogleFont(fontFamily, weights) {
2613
- try {
2614
- const weightStr = (weights || [300, 400, 500, 600, 700]).join(";");
2615
- const encodedFamily = encodeURIComponent(fontFamily);
2616
- const url = `https://fonts.googleapis.com/css2?family=${encodedFamily}:ital,wght@0,${weightStr};1,${weightStr}&display=swap`;
2617
- const existingLink = document.querySelector(`link[href="${url}"]`);
2618
- if (existingLink) return true;
2612
+ function tryInjectGoogleFontsLink(url, fontFamily) {
2613
+ if (document.querySelector(`link[href="${url}"]`)) return Promise.resolve(true);
2614
+ return new Promise((resolve) => {
2619
2615
  const link = document.createElement("link");
2620
2616
  link.rel = "stylesheet";
2621
2617
  link.href = url;
2622
- return new Promise((resolve) => {
2623
- link.onload = async () => {
2624
- try {
2625
- await document.fonts.load(`16px "${fontFamily}"`);
2626
- await document.fonts.load(`bold 16px "${fontFamily}"`);
2627
- } catch {
2628
- }
2629
- resolve(true);
2630
- };
2631
- link.onerror = () => {
2632
- console.warn(`[GoogleFonts] Failed to load: ${fontFamily}`);
2633
- resolve(false);
2634
- };
2635
- document.head.appendChild(link);
2636
- });
2637
- } catch (e) {
2638
- console.warn(`[GoogleFonts] Error loading ${fontFamily}:`, e);
2639
- return false;
2618
+ link.onload = async () => {
2619
+ try {
2620
+ await document.fonts.load(`16px "${fontFamily}"`);
2621
+ } catch {
2622
+ }
2623
+ resolve(true);
2624
+ };
2625
+ link.onerror = () => resolve(false);
2626
+ document.head.appendChild(link);
2627
+ });
2628
+ }
2629
+ async function _doLoadGoogleFont(fontFamily, weights) {
2630
+ const encodedFamily = encodeURIComponent(fontFamily);
2631
+ const weightSet = [300, 400, 500, 600, 700];
2632
+ const fullWeightStr = weightSet.join(";");
2633
+ const coreWeightStr = "400;700";
2634
+ const candidates = [
2635
+ `https://fonts.googleapis.com/css2?family=${encodedFamily}:ital,wght@0,${fullWeightStr};1,${fullWeightStr}&display=swap`,
2636
+ `https://fonts.googleapis.com/css2?family=${encodedFamily}:wght@${fullWeightStr}&display=swap`,
2637
+ `https://fonts.googleapis.com/css2?family=${encodedFamily}:ital,wght@0,${coreWeightStr};1,${coreWeightStr}&display=swap`,
2638
+ `https://fonts.googleapis.com/css2?family=${encodedFamily}:wght@${coreWeightStr}&display=swap`,
2639
+ // Plainest possible URL — works for any published Google Font, even
2640
+ // single-weight display/script families like "Frijole" or "Creepster".
2641
+ `https://fonts.googleapis.com/css2?family=${encodedFamily}&display=swap`
2642
+ ];
2643
+ for (const url of candidates) {
2644
+ const ok = await tryInjectGoogleFontsLink(url, fontFamily);
2645
+ if (ok) return true;
2640
2646
  }
2647
+ console.warn(`[GoogleFonts] Failed to load: ${fontFamily}`);
2648
+ return false;
2641
2649
  }
2642
2650
  const getObjectId = (obj) => obj.__docuforgeId;
2643
2651
  const setObjectData = (obj, id) => {
@@ -5544,7 +5552,7 @@ function createText(element) {
5544
5552
  }
5545
5553
  text = result;
5546
5554
  }
5547
- const targetWidth = overflowPolicy === "auto-shrink" ? fixedWidth : Math.max(baseWidth, getMinTextWidth(element));
5555
+ const targetWidth = fixedWidth;
5548
5556
  const targetScaleX = element.scaleX ?? 1;
5549
5557
  const targetScaleY = element.scaleY ?? 1;
5550
5558
  const textbox = new fabric.Textbox(text, {
@@ -7708,7 +7716,7 @@ const PageCanvas = forwardRef(
7708
7716
  useEffect(() => {
7709
7717
  const fc = fabricRef.current;
7710
7718
  if (!fc) return;
7711
- if (!ready && !isPreviewMode) {
7719
+ if (!ready) {
7712
7720
  hasClearedCachesBeforeFirstSyncRef.current = false;
7713
7721
  return;
7714
7722
  }
@@ -11980,6 +11988,38 @@ function applyContentBoundsPagination(config) {
11980
11988
  if (!mutated) return config;
11981
11989
  return { ...config, pages: resultPages };
11982
11990
  }
11991
+ const FONTSHARE_SLUGS = {
11992
+ "Satoshi": "satoshi",
11993
+ "Cabinet Grotesk": "cabinet-grotesk",
11994
+ "Clash Display": "clash-display",
11995
+ "Clash Grotesk": "clash-grotesk",
11996
+ "General Sans": "general-sans",
11997
+ "Switzer": "switzer",
11998
+ "Supreme": "supreme",
11999
+ "Author": "author",
12000
+ "Boska": "boska",
12001
+ "Excon": "excon",
12002
+ "Khand": "khand",
12003
+ "Sentient": "sentient",
12004
+ "Synonym": "synonym",
12005
+ "Erode": "erode",
12006
+ "Ranade": "ranade",
12007
+ "Tanker": "tanker",
12008
+ "Zodiak": "zodiak",
12009
+ "Gambarino": "gambarino",
12010
+ "Melodrama": "melodrama",
12011
+ "Bespoke Serif": "bespoke-serif",
12012
+ "Bespoke Stencil": "bespoke-stencil",
12013
+ "Panchang": "panchang",
12014
+ "Quincy CF": "quincy-cf",
12015
+ "Pally": "pally",
12016
+ "Tabular": "tabular",
12017
+ "Sharpie": "sharpie",
12018
+ "Stardom": "stardom",
12019
+ "Rebond Grotesque": "rebond-grotesque",
12020
+ "Telma": "telma",
12021
+ "Nippo": "nippo"
12022
+ };
11983
12023
  function normalizeFontFamily(fontStack) {
11984
12024
  const first = fontStack.split(",")[0].trim();
11985
12025
  return first.replace(/^['"]|['"]$/g, "");
@@ -12006,6 +12046,20 @@ async function loadGoogleFontCSS(rawFontFamily) {
12006
12046
  if (existing) return existing;
12007
12047
  const promise = (async () => {
12008
12048
  try {
12049
+ const fontshareSlug = FONTSHARE_SLUGS[fontFamily];
12050
+ if (fontshareSlug) {
12051
+ const url2 = `https://api.fontshare.com/v2/css?f[]=${fontshareSlug}@300,400,500,700&display=swap`;
12052
+ const link2 = document.createElement("link");
12053
+ link2.rel = "stylesheet";
12054
+ link2.href = url2;
12055
+ await new Promise((resolve, reject) => {
12056
+ link2.onload = () => resolve();
12057
+ link2.onerror = () => reject(new Error(`Failed to load Fontshare font: ${fontFamily}`));
12058
+ document.head.appendChild(link2);
12059
+ });
12060
+ loadedFonts.add(fontFamily);
12061
+ return;
12062
+ }
12009
12063
  const encoded = encodeURIComponent(fontFamily);
12010
12064
  const url = `https://fonts.googleapis.com/css?family=${encoded}:300,400,500,600,700&display=swap`;
12011
12065
  const link = document.createElement("link");
@@ -12160,6 +12214,7 @@ async function awaitFontsForConfig(config, maxWaitMs) {
12160
12214
  await ensureFontsForResolvedConfig(config);
12161
12215
  const descriptors = collectFontDescriptorsFromConfig(config);
12162
12216
  if (descriptors.length === 0) return;
12217
+ const overallBudget = Math.max(maxWaitMs, 5e3);
12163
12218
  const loads = Promise.all(
12164
12219
  descriptors.map((d) => {
12165
12220
  const stylePrefix = d.style === "italic" ? "italic " : "";
@@ -12169,11 +12224,11 @@ async function awaitFontsForConfig(config, maxWaitMs) {
12169
12224
  ).then(() => void 0);
12170
12225
  await Promise.race([
12171
12226
  loads,
12172
- new Promise((resolve) => setTimeout(resolve, maxWaitMs))
12227
+ new Promise((resolve) => setTimeout(resolve, overallBudget))
12173
12228
  ]);
12174
12229
  await Promise.race([
12175
12230
  document.fonts.ready.catch(() => void 0).then(() => void 0),
12176
- new Promise((r) => setTimeout(r, Math.min(500, maxWaitMs)))
12231
+ new Promise((r) => setTimeout(r, 1500))
12177
12232
  ]);
12178
12233
  const checkSpecs = [];
12179
12234
  for (const d of descriptors) {
@@ -12181,7 +12236,7 @@ async function awaitFontsForConfig(config, maxWaitMs) {
12181
12236
  checkSpecs.push(`${stylePrefix}${d.weight} 16px "${d.family}"`);
12182
12237
  }
12183
12238
  const startedAt = Date.now();
12184
- const pollBudget = Math.min(maxWaitMs, 2500);
12239
+ const pollBudget = 2500;
12185
12240
  const allReady = () => {
12186
12241
  for (const spec of checkSpecs) {
12187
12242
  try {
@@ -16286,7 +16341,7 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
16286
16341
  }
16287
16342
  if (shouldOutlineText) {
16288
16343
  try {
16289
- const { convertAllTextToPath } = await import("./svgTextToPath-BmOzWJsV.js");
16344
+ const { convertAllTextToPath } = await import("./svgTextToPath-CpWdqc8K.js");
16290
16345
  pageSvg = await convertAllTextToPath(pageSvg, fontBaseUrl, { mode: outlineSubMode });
16291
16346
  try {
16292
16347
  dumpSvgTextDiagnostics(pageSvg, i, PARITY_TAG, "STAGE-1b-after-text-to-path-raw");