@pacem/pacem-core 2.0.0-jacobi → 2.0.0-lyapunov

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pacem/pacem-core v2.0.0-jacobi (https://js.pacem.it)
2
+ * @pacem/pacem-core v2.0.0-lyapunov (https://js.pacem.it)
3
3
  * Pacem (https://pacem.it)
4
4
  * Licensed under Apache-2.0
5
5
  */
@@ -1842,8 +1842,15 @@ var CustomElementUtils = class _CustomElementUtils {
1842
1842
  }
1843
1843
  static {
1844
1844
  this.Theme = {
1845
- /** Downloads the web fonts referenced by the current theme's `--{@link PCSS}-font-*` CSS custom properties, resolving once at least one font face is ready (or after a short timeout). */
1845
+ /**
1846
+ * Downloads the web fonts referenced by the current theme's `--{@link PCSS}-font-*` CSS custom properties,
1847
+ * resolving once they are loaded and at least one font face is ready. Never rejects, never waits forever:
1848
+ * a font that fails to load is skipped, and the whole wait is capped (fonts refine a page, they must not
1849
+ * keep it hidden).
1850
+ */
1846
1851
  importWebFonts() {
1852
+ const WEB_FONTS_TIMEOUT = 3e3;
1853
+ const FONT_FACE_CHECKS = 4;
1847
1854
  function cleanupQuotes(input) {
1848
1855
  if (/^('|").*\1$/.test(input)) {
1849
1856
  return input.substring(1, input.length - 1);
@@ -1853,27 +1860,30 @@ var CustomElementUtils = class _CustomElementUtils {
1853
1860
  function downloadFont(fontFace) {
1854
1861
  return Utils.isNullOrEmpty(fontFace) ? Promise.resolve() : document.fonts.load("1rem " + fontFace);
1855
1862
  }
1856
- const promises = ["icons", "std", "main", "tech", "btn"].map((f) => {
1863
+ function importFont(f) {
1857
1864
  const fontFace = Utils.Css.getVariableValue(`--${PCSS}-font-${f}`).split(",")[0];
1858
- const url = cleanupQuotes(Utils.Css.getVariableValue(`--${PCSS}-font-${f}-api-url`));
1865
+ const apiUrl = Utils.Css.getVariableValue(`--${PCSS}-font-${f}-api-url`);
1866
+ const url = cleanupQuotes(apiUrl);
1859
1867
  if (Utils.isNullOrEmpty(url)) {
1860
1868
  return downloadFont(fontFace);
1861
- } else {
1862
- return _CustomElementUtils.importcss(url).then((_) => downloadFont(fontFace));
1863
1869
  }
1864
- });
1870
+ return _CustomElementUtils.importcss(url).then((_) => downloadFont(fontFace));
1871
+ }
1872
+ const promises = ["icons", "std", "main", "tech", "btn"].map((f) => importFont(f).catch((_) => void 0));
1865
1873
  const atLeast1FontFaceReady = new Promise((resolve) => {
1866
- function check(count = 0) {
1867
- if (count > 4 || !("size" in document.fonts) || typeof document.fonts.size === "number" && document.fonts.size > 0) {
1874
+ function check(count) {
1875
+ if (count > FONT_FACE_CHECKS || !("size" in document.fonts) || typeof document.fonts.size === "number" && document.fonts.size > 0) {
1868
1876
  document.fonts.ready.then(resolve);
1869
- } else {
1870
- setTimeout(check, 250, count++);
1877
+ return;
1871
1878
  }
1879
+ setTimeout(check, 250, count + 1);
1872
1880
  }
1873
- check();
1881
+ check(0);
1874
1882
  });
1875
1883
  promises.push(atLeast1FontFaceReady);
1876
- return Promise.all(promises);
1884
+ const timeout = new Promise((resolve) => setTimeout(resolve, WEB_FONTS_TIMEOUT));
1885
+ const fontsReady = Promise.all(promises);
1886
+ return Promise.race([fontsReady, timeout]);
1877
1887
  }
1878
1888
  };
1879
1889
  }