@pixldocs/canvas-renderer 0.5.14 → 0.5.15
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 +35 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2656,6 +2656,19 @@ const FONTS_TO_PRELOAD = [
|
|
|
2656
2656
|
];
|
|
2657
2657
|
let fontsLoaded = false;
|
|
2658
2658
|
let fontsLoadingPromise = null;
|
|
2659
|
+
const withFontTimeout = async (promise, timeoutMs = 4e3) => {
|
|
2660
|
+
let timeoutId;
|
|
2661
|
+
try {
|
|
2662
|
+
return await Promise.race([
|
|
2663
|
+
promise,
|
|
2664
|
+
new Promise((resolve) => {
|
|
2665
|
+
timeoutId = setTimeout(resolve, timeoutMs);
|
|
2666
|
+
})
|
|
2667
|
+
]);
|
|
2668
|
+
} finally {
|
|
2669
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
2670
|
+
}
|
|
2671
|
+
};
|
|
2659
2672
|
const preloadFont = async (fontFamily) => {
|
|
2660
2673
|
try {
|
|
2661
2674
|
if (document.fonts) {
|
|
@@ -2676,11 +2689,11 @@ const preloadAllFonts = async () => {
|
|
|
2676
2689
|
}
|
|
2677
2690
|
fontsLoadingPromise = (async () => {
|
|
2678
2691
|
if (document.fonts) {
|
|
2679
|
-
await document.fonts.ready;
|
|
2692
|
+
await withFontTimeout(document.fonts.ready, 2500);
|
|
2680
2693
|
}
|
|
2681
|
-
await Promise.all(FONTS_TO_PRELOAD.map((font) => preloadFont(font)));
|
|
2694
|
+
await withFontTimeout(Promise.all(FONTS_TO_PRELOAD.map((font) => preloadFont(font))).then(() => void 0), 5e3);
|
|
2682
2695
|
if (document.fonts) {
|
|
2683
|
-
await document.fonts.ready;
|
|
2696
|
+
await withFontTimeout(document.fonts.ready, 2500);
|
|
2684
2697
|
}
|
|
2685
2698
|
fontsLoaded = true;
|
|
2686
2699
|
})();
|
|
@@ -2688,7 +2701,7 @@ const preloadAllFonts = async () => {
|
|
|
2688
2701
|
};
|
|
2689
2702
|
const waitForFontsReady = async () => {
|
|
2690
2703
|
if (!document.fonts) return;
|
|
2691
|
-
await document.fonts.ready;
|
|
2704
|
+
await withFontTimeout(document.fonts.ready, 2500);
|
|
2692
2705
|
};
|
|
2693
2706
|
const DEFAULT_FONT_CHECK_TIMEOUT_MS = 3500;
|
|
2694
2707
|
const FONT_CHECK_POLL_MS = 60;
|
|
@@ -11694,6 +11707,19 @@ function normalizeFontFamily(fontStack) {
|
|
|
11694
11707
|
}
|
|
11695
11708
|
const loadedFonts = /* @__PURE__ */ new Set();
|
|
11696
11709
|
const loadingPromises = /* @__PURE__ */ new Map();
|
|
11710
|
+
async function withTimeout(promise, timeoutMs = 4e3) {
|
|
11711
|
+
let timeoutId;
|
|
11712
|
+
try {
|
|
11713
|
+
return await Promise.race([
|
|
11714
|
+
promise,
|
|
11715
|
+
new Promise((resolve) => {
|
|
11716
|
+
timeoutId = setTimeout(resolve, timeoutMs);
|
|
11717
|
+
})
|
|
11718
|
+
]);
|
|
11719
|
+
} finally {
|
|
11720
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
11721
|
+
}
|
|
11722
|
+
}
|
|
11697
11723
|
async function loadGoogleFontCSS(rawFontFamily) {
|
|
11698
11724
|
if (!rawFontFamily || typeof document === "undefined") return;
|
|
11699
11725
|
const fontFamily = normalizeFontFamily(rawFontFamily);
|
|
@@ -11715,8 +11741,8 @@ async function loadGoogleFontCSS(rawFontFamily) {
|
|
|
11715
11741
|
document.head.appendChild(link);
|
|
11716
11742
|
});
|
|
11717
11743
|
if (document.fonts) {
|
|
11718
|
-
await document.fonts.load(`16px "${fontFamily}"`);
|
|
11719
|
-
await document.fonts.ready;
|
|
11744
|
+
await withTimeout(document.fonts.load(`16px "${fontFamily}"`), 2500);
|
|
11745
|
+
await withTimeout(document.fonts.ready, 2500);
|
|
11720
11746
|
}
|
|
11721
11747
|
loadedFonts.add(fontFamily);
|
|
11722
11748
|
} catch (e) {
|
|
@@ -11829,7 +11855,7 @@ async function ensureFontsForResolvedConfig(config) {
|
|
|
11829
11855
|
if (typeof document === "undefined") return;
|
|
11830
11856
|
const descriptors = collectFontDescriptorsFromConfig(config);
|
|
11831
11857
|
const families = new Set(descriptors.map((d) => d.family));
|
|
11832
|
-
await Promise.all([...families].map((f) => loadGoogleFontCSS(f)));
|
|
11858
|
+
await withTimeout(Promise.all([...families].map((f) => loadGoogleFontCSS(f))), 8e3);
|
|
11833
11859
|
if (document.fonts) {
|
|
11834
11860
|
const loadPromises = descriptors.map((d) => {
|
|
11835
11861
|
const stylePrefix = d.style === "italic" ? "italic " : "";
|
|
@@ -11838,8 +11864,8 @@ async function ensureFontsForResolvedConfig(config) {
|
|
|
11838
11864
|
return document.fonts.load(spec).catch(() => {
|
|
11839
11865
|
});
|
|
11840
11866
|
});
|
|
11841
|
-
await Promise.all(loadPromises);
|
|
11842
|
-
await document.fonts.ready;
|
|
11867
|
+
await withTimeout(Promise.all(loadPromises), 8e3);
|
|
11868
|
+
await withTimeout(document.fonts.ready, 2500);
|
|
11843
11869
|
}
|
|
11844
11870
|
}
|
|
11845
11871
|
function PixldocsPreview(props) {
|