@unocss/preset-web-fonts 0.44.5 → 0.45.3

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 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 avaliable.
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
- name: "google",
9
- getImportUrl(fonts) {
10
- const strings = fonts.filter((i) => i.provider === "google").map((i) => {
11
- let name = i.name.replace(/\s+/g, "+");
12
- if (i.weights?.length) {
13
- name += i.italic ? `:ital,wght@${i.weights.flatMap((i2) => [`0,${i2}`, `1,${i2}`]).sort().join(";")}` : `:wght@${i.weights.sort().join(";")}`;
14
- }
15
- return `family=${name}`;
16
- }).join("&");
17
- return `https://fonts.googleapis.com/css2?${strings}&display=swap`;
18
- },
19
- getFontName(font) {
20
- return `"${font.name}"`;
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 = {}) => {
@@ -54,7 +60,9 @@ const preset = (options = {}) => {
54
60
  inlineImports = true,
55
61
  themeKey = "fontFamily"
56
62
  } = options;
57
- const fontObject = Object.fromEntries(Object.entries(options.fonts || {}).map(([name, meta]) => [name, core.toArray(meta).map((m) => normalizedFontMeta(m, defaultProvider))]));
63
+ const fontObject = Object.fromEntries(
64
+ Object.entries(options.fonts || {}).map(([name, meta]) => [name, core.toArray(meta).map((m) => normalizedFontMeta(m, defaultProvider))])
65
+ );
58
66
  const fonts = Object.values(fontObject).flatMap((i) => i);
59
67
  const importCache = {};
60
68
  async function importUrl(url) {
@@ -101,7 +109,9 @@ const preset = (options = {}) => {
101
109
  preset2.extendTheme = (theme) => {
102
110
  if (!theme[themeKey])
103
111
  theme[themeKey] = {};
104
- const obj = Object.fromEntries(Object.entries(fontObject).map(([name, fonts2]) => [name, fonts2.map((f) => providers[f.provider || defaultProvider].getFontName(f))]));
112
+ const obj = Object.fromEntries(
113
+ Object.entries(fontObject).map(([name, fonts2]) => [name, fonts2.map((f) => providers[f.provider || defaultProvider].getFontName(f))])
114
+ );
105
115
  for (const key of Object.keys(obj)) {
106
116
  if (typeof theme[themeKey][key] === "string")
107
117
  theme[themeKey][key] = obj[key].map((i) => `${i},`).join("") + theme[themeKey][key];
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Preset } from '@unocss/core';
2
2
 
3
- declare type WebFontsProviders = 'google' | 'none';
3
+ declare type WebFontsProviders = 'google' | 'bunny' | 'none';
4
4
  interface WebFontMeta {
5
5
  name: string;
6
6
  weights?: (string | number)[];
package/dist/index.mjs CHANGED
@@ -1,21 +1,26 @@
1
1
  import { toArray } from '@unocss/core';
2
2
 
3
- const GoogleFontsProvider = {
4
- name: "google",
5
- getImportUrl(fonts) {
6
- const strings = fonts.filter((i) => i.provider === "google").map((i) => {
7
- let name = i.name.replace(/\s+/g, "+");
8
- if (i.weights?.length) {
9
- name += i.italic ? `:ital,wght@${i.weights.flatMap((i2) => [`0,${i2}`, `1,${i2}`]).sort().join(";")}` : `:wght@${i.weights.sort().join(";")}`;
10
- }
11
- return `family=${name}`;
12
- }).join("&");
13
- return `https://fonts.googleapis.com/css2?${strings}&display=swap`;
14
- },
15
- getFontName(font) {
16
- return `"${font.name}"`;
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 = {}) => {
@@ -50,7 +56,9 @@ const preset = (options = {}) => {
50
56
  inlineImports = true,
51
57
  themeKey = "fontFamily"
52
58
  } = options;
53
- const fontObject = Object.fromEntries(Object.entries(options.fonts || {}).map(([name, meta]) => [name, toArray(meta).map((m) => normalizedFontMeta(m, defaultProvider))]));
59
+ const fontObject = Object.fromEntries(
60
+ Object.entries(options.fonts || {}).map(([name, meta]) => [name, toArray(meta).map((m) => normalizedFontMeta(m, defaultProvider))])
61
+ );
54
62
  const fonts = Object.values(fontObject).flatMap((i) => i);
55
63
  const importCache = {};
56
64
  async function importUrl(url) {
@@ -97,7 +105,9 @@ const preset = (options = {}) => {
97
105
  preset2.extendTheme = (theme) => {
98
106
  if (!theme[themeKey])
99
107
  theme[themeKey] = {};
100
- const obj = Object.fromEntries(Object.entries(fontObject).map(([name, fonts2]) => [name, fonts2.map((f) => providers[f.provider || defaultProvider].getFontName(f))]));
108
+ const obj = Object.fromEntries(
109
+ Object.entries(fontObject).map(([name, fonts2]) => [name, fonts2.map((f) => providers[f.provider || defaultProvider].getFontName(f))])
110
+ );
101
111
  for (const key of Object.keys(obj)) {
102
112
  if (typeof theme[themeKey][key] === "string")
103
113
  theme[themeKey][key] = obj[key].map((i) => `${i},`).join("") + theme[themeKey][key];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/preset-web-fonts",
3
- "version": "0.44.5",
3
+ "version": "0.45.3",
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.44.5",
45
+ "@unocss/core": "0.45.3",
46
46
  "ohmyfetch": "^0.4.18"
47
47
  },
48
48
  "scripts": {