@unocss/preset-web-fonts 0.45.1 → 0.45.5
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/README.md +2 -1
- package/dist/index.cjs +26 -22
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +26 -22
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -70,12 +70,13 @@ Currently supported Providers:
|
|
|
70
70
|
|
|
71
71
|
- `none` - do nothing, treat the font as system font
|
|
72
72
|
- `google` - [Google Fonts](https://fonts.google.com/)
|
|
73
|
+
- `bunny` - [Privacy-Friendly Google Fonts](https://fonts.bunny.net/)
|
|
73
74
|
|
|
74
75
|
PR welcome to add more providers 🙌
|
|
75
76
|
|
|
76
77
|
## Configuration
|
|
77
78
|
|
|
78
|
-
Refer to the [type definition](https://github.com/unocss/unocss/blob/main/packages/preset-web-fonts/src/types.ts#L4) for all configurations
|
|
79
|
+
Refer to the [type definition](https://github.com/unocss/unocss/blob/main/packages/preset-web-fonts/src/types.ts#L4) for all configurations available.
|
|
79
80
|
|
|
80
81
|
## License
|
|
81
82
|
|
package/dist/index.cjs
CHANGED
|
@@ -4,22 +4,27 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const core = require('@unocss/core');
|
|
6
6
|
|
|
7
|
-
const GoogleFontsProvider =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
7
|
+
const GoogleFontsProvider = createGoogleProvider("google", "https://fonts.googleapis.com");
|
|
8
|
+
function createGoogleProvider(name, host) {
|
|
9
|
+
return {
|
|
10
|
+
name,
|
|
11
|
+
getImportUrl(fonts) {
|
|
12
|
+
const strings = fonts.filter((i) => i.provider === name).map((i) => {
|
|
13
|
+
let name2 = i.name.replace(/\s+/g, "+");
|
|
14
|
+
if (i.weights?.length) {
|
|
15
|
+
name2 += i.italic ? `:ital,wght@${i.weights.flatMap((i2) => [`0,${i2}`, `1,${i2}`]).sort().join(";")}` : `:wght@${i.weights.sort().join(";")}`;
|
|
16
|
+
}
|
|
17
|
+
return `family=${name2}`;
|
|
18
|
+
}).join("&");
|
|
19
|
+
return `${host}/css2?${strings}&display=swap`;
|
|
20
|
+
},
|
|
21
|
+
getFontName(font) {
|
|
22
|
+
return `"${font.name}"`;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const BunnyFontsProvider = createGoogleProvider("bunny", "https://fonts.bunny.net");
|
|
23
28
|
|
|
24
29
|
const NoneProvider = {
|
|
25
30
|
name: "none",
|
|
@@ -45,6 +50,7 @@ function normalizedFontMeta(meta, defaultProvider) {
|
|
|
45
50
|
}
|
|
46
51
|
const providers = {
|
|
47
52
|
google: GoogleFontsProvider,
|
|
53
|
+
bunny: BunnyFontsProvider,
|
|
48
54
|
none: NoneProvider
|
|
49
55
|
};
|
|
50
56
|
const preset = (options = {}) => {
|
|
@@ -62,17 +68,15 @@ const preset = (options = {}) => {
|
|
|
62
68
|
async function importUrl(url) {
|
|
63
69
|
if (inlineImports) {
|
|
64
70
|
if (!importCache[url]) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
importCache[url] = await $fetch(url, { headers: {} });
|
|
68
|
-
} catch (e) {
|
|
71
|
+
const { $fetch } = await import('ohmyfetch');
|
|
72
|
+
importCache[url] = $fetch(url, { headers: {}, retry: 3 }).catch((e) => {
|
|
69
73
|
console.error("Failed to fetch web fonts");
|
|
70
74
|
console.error(e);
|
|
71
75
|
if (typeof process !== "undefined" && process.env.CI)
|
|
72
76
|
throw e;
|
|
73
|
-
}
|
|
77
|
+
});
|
|
74
78
|
}
|
|
75
|
-
return importCache[url];
|
|
79
|
+
return await importCache[url];
|
|
76
80
|
} else {
|
|
77
81
|
return `@import url('${url}')`;
|
|
78
82
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import { toArray } from '@unocss/core';
|
|
2
2
|
|
|
3
|
-
const GoogleFontsProvider =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
3
|
+
const GoogleFontsProvider = createGoogleProvider("google", "https://fonts.googleapis.com");
|
|
4
|
+
function createGoogleProvider(name, host) {
|
|
5
|
+
return {
|
|
6
|
+
name,
|
|
7
|
+
getImportUrl(fonts) {
|
|
8
|
+
const strings = fonts.filter((i) => i.provider === name).map((i) => {
|
|
9
|
+
let name2 = i.name.replace(/\s+/g, "+");
|
|
10
|
+
if (i.weights?.length) {
|
|
11
|
+
name2 += i.italic ? `:ital,wght@${i.weights.flatMap((i2) => [`0,${i2}`, `1,${i2}`]).sort().join(";")}` : `:wght@${i.weights.sort().join(";")}`;
|
|
12
|
+
}
|
|
13
|
+
return `family=${name2}`;
|
|
14
|
+
}).join("&");
|
|
15
|
+
return `${host}/css2?${strings}&display=swap`;
|
|
16
|
+
},
|
|
17
|
+
getFontName(font) {
|
|
18
|
+
return `"${font.name}"`;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const BunnyFontsProvider = createGoogleProvider("bunny", "https://fonts.bunny.net");
|
|
19
24
|
|
|
20
25
|
const NoneProvider = {
|
|
21
26
|
name: "none",
|
|
@@ -41,6 +46,7 @@ function normalizedFontMeta(meta, defaultProvider) {
|
|
|
41
46
|
}
|
|
42
47
|
const providers = {
|
|
43
48
|
google: GoogleFontsProvider,
|
|
49
|
+
bunny: BunnyFontsProvider,
|
|
44
50
|
none: NoneProvider
|
|
45
51
|
};
|
|
46
52
|
const preset = (options = {}) => {
|
|
@@ -58,17 +64,15 @@ const preset = (options = {}) => {
|
|
|
58
64
|
async function importUrl(url) {
|
|
59
65
|
if (inlineImports) {
|
|
60
66
|
if (!importCache[url]) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
importCache[url] = await $fetch(url, { headers: {} });
|
|
64
|
-
} catch (e) {
|
|
67
|
+
const { $fetch } = await import('ohmyfetch');
|
|
68
|
+
importCache[url] = $fetch(url, { headers: {}, retry: 3 }).catch((e) => {
|
|
65
69
|
console.error("Failed to fetch web fonts");
|
|
66
70
|
console.error(e);
|
|
67
71
|
if (typeof process !== "undefined" && process.env.CI)
|
|
68
72
|
throw e;
|
|
69
|
-
}
|
|
73
|
+
});
|
|
70
74
|
}
|
|
71
|
-
return importCache[url];
|
|
75
|
+
return await importCache[url];
|
|
72
76
|
} else {
|
|
73
77
|
return `@import url('${url}')`;
|
|
74
78
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/preset-web-fonts",
|
|
3
|
-
"version": "0.45.
|
|
3
|
+
"version": "0.45.5",
|
|
4
4
|
"description": "Web Fonts support for Uno CSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"*.css"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@unocss/core": "0.45.
|
|
45
|
+
"@unocss/core": "0.45.5",
|
|
46
46
|
"ohmyfetch": "^0.4.18"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|