@unocss/preset-web-fonts 0.61.0 → 0.61.2
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.d.mts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.mjs +21 -3
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -47,6 +47,23 @@ interface WebFontsOptions {
|
|
|
47
47
|
* @default undefined
|
|
48
48
|
*/
|
|
49
49
|
customFetch?: (url: string) => Promise<any>;
|
|
50
|
+
/**
|
|
51
|
+
* Timeouts for fetching web fonts
|
|
52
|
+
*/
|
|
53
|
+
timeouts?: false | {
|
|
54
|
+
/**
|
|
55
|
+
* Timeout for printing warning message
|
|
56
|
+
*
|
|
57
|
+
* @default 500
|
|
58
|
+
*/
|
|
59
|
+
warning?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Timeout for failing the fetch
|
|
62
|
+
*
|
|
63
|
+
* @default 2000
|
|
64
|
+
*/
|
|
65
|
+
failure?: number;
|
|
66
|
+
};
|
|
50
67
|
}
|
|
51
68
|
interface Provider {
|
|
52
69
|
name: WebFontsProviders;
|
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,23 @@ interface WebFontsOptions {
|
|
|
47
47
|
* @default undefined
|
|
48
48
|
*/
|
|
49
49
|
customFetch?: (url: string) => Promise<any>;
|
|
50
|
+
/**
|
|
51
|
+
* Timeouts for fetching web fonts
|
|
52
|
+
*/
|
|
53
|
+
timeouts?: false | {
|
|
54
|
+
/**
|
|
55
|
+
* Timeout for printing warning message
|
|
56
|
+
*
|
|
57
|
+
* @default 500
|
|
58
|
+
*/
|
|
59
|
+
warning?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Timeout for failing the fetch
|
|
62
|
+
*
|
|
63
|
+
* @default 2000
|
|
64
|
+
*/
|
|
65
|
+
failure?: number;
|
|
66
|
+
};
|
|
50
67
|
}
|
|
51
68
|
interface Provider {
|
|
52
69
|
name: WebFontsProviders;
|
package/dist/index.mjs
CHANGED
|
@@ -108,18 +108,36 @@ function createWebFontPreset(fetcher) {
|
|
|
108
108
|
extendTheme = true,
|
|
109
109
|
inlineImports = true,
|
|
110
110
|
themeKey = "fontFamily",
|
|
111
|
-
customFetch = fetcher
|
|
111
|
+
customFetch = fetcher,
|
|
112
|
+
timeouts = {}
|
|
112
113
|
} = options;
|
|
113
114
|
const fontObject = Object.fromEntries(
|
|
114
115
|
Object.entries(options.fonts || {}).map(([name, meta]) => [name, toArray(meta).map((m) => normalizedFontMeta(m, defaultProvider))])
|
|
115
116
|
);
|
|
116
117
|
const fonts = Object.values(fontObject).flatMap((i) => i);
|
|
117
118
|
const importCache = {};
|
|
119
|
+
async function fetchWithTimeout(url) {
|
|
120
|
+
if (timeouts === false)
|
|
121
|
+
return customFetch(url);
|
|
122
|
+
const {
|
|
123
|
+
warning = 500,
|
|
124
|
+
failure = 2e3
|
|
125
|
+
} = timeouts;
|
|
126
|
+
const timer = setTimeout(() => {
|
|
127
|
+
console.warn(`[unocss] Fetching web fonts: ${url}`);
|
|
128
|
+
}, warning);
|
|
129
|
+
return await Promise.race([
|
|
130
|
+
customFetch(url),
|
|
131
|
+
new Promise((_, reject) => {
|
|
132
|
+
setTimeout(() => reject(new Error(`[unocss] Fetch web fonts timeout.`)), failure);
|
|
133
|
+
})
|
|
134
|
+
]).finally(() => clearTimeout(timer));
|
|
135
|
+
}
|
|
118
136
|
async function importUrl(url) {
|
|
119
137
|
if (inlineImports) {
|
|
120
138
|
if (!importCache[url]) {
|
|
121
|
-
importCache[url] =
|
|
122
|
-
console.error(
|
|
139
|
+
importCache[url] = fetchWithTimeout(url).catch((e) => {
|
|
140
|
+
console.error(`[unocss] Failed to fetch web fonts: ${url}`);
|
|
123
141
|
console.error(e);
|
|
124
142
|
if (typeof process !== "undefined" && process.env.CI)
|
|
125
143
|
throw e;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/preset-web-fonts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.61.
|
|
4
|
+
"version": "0.61.2",
|
|
5
5
|
"description": "Web Fonts support for Uno CSS",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"ofetch": "^1.3.4",
|
|
41
|
-
"@unocss/core": "0.61.
|
|
41
|
+
"@unocss/core": "0.61.2"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "unbuild",
|