@unocss/preset-web-fonts 0.46.2 → 0.46.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
@@ -71,6 +71,7 @@ Currently supported Providers:
71
71
  - `none` - do nothing, treat the font as system font
72
72
  - `google` - [Google Fonts](https://fonts.google.com/)
73
73
  - `bunny` - [Privacy-Friendly Google Fonts](https://fonts.bunny.net/)
74
+ - `fontshare` - [Quality Font Service by ITF](https://www.fontshare.com/)
74
75
 
75
76
  PR welcome to add more providers 🙌
76
77
 
package/dist/index.cjs CHANGED
@@ -26,6 +26,27 @@ function createGoogleProvider(name, host) {
26
26
 
27
27
  const BunnyFontsProvider = createGoogleProvider("bunny", "https://fonts.bunny.net");
28
28
 
29
+ const FontshareProvider = createFontshareProvider("fontshare", "https://api.fontshare.com");
30
+ function createFontshareProvider(name, host) {
31
+ return {
32
+ name,
33
+ getImportUrl(fonts) {
34
+ const strings = fonts.filter((f) => f.provider === name).map((f) => {
35
+ let name2 = f.name.replace(/\s+/g, "-").toLocaleLowerCase();
36
+ if (f.weights?.length)
37
+ name2 += `@${f.weights.flatMap((w) => f.italic ? Number(w) + 1 : w).sort().join()}`;
38
+ else
39
+ name2 += `@${f.italic ? 2 : 1}`;
40
+ return `f[]=${name2}`;
41
+ }).join("&");
42
+ return `${host}/v2/css?${strings}&display=swap`;
43
+ },
44
+ getFontName(font) {
45
+ return `"${font.name}"`;
46
+ }
47
+ };
48
+ }
49
+
29
50
  const NoneProvider = {
30
51
  name: "none",
31
52
  getPreflight() {
@@ -51,6 +72,7 @@ function normalizedFontMeta(meta, defaultProvider) {
51
72
  const providers = {
52
73
  google: GoogleFontsProvider,
53
74
  bunny: BunnyFontsProvider,
75
+ fontshare: FontshareProvider,
54
76
  none: NoneProvider
55
77
  };
56
78
  const preset = (options = {}) => {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Preset } from '@unocss/core';
2
2
 
3
- declare type WebFontsProviders = 'google' | 'bunny' | 'none';
3
+ declare type WebFontsProviders = 'google' | 'bunny' | 'fontshare' | 'none';
4
4
  interface WebFontMeta {
5
5
  name: string;
6
6
  weights?: (string | number)[];
package/dist/index.mjs CHANGED
@@ -22,6 +22,27 @@ function createGoogleProvider(name, host) {
22
22
 
23
23
  const BunnyFontsProvider = createGoogleProvider("bunny", "https://fonts.bunny.net");
24
24
 
25
+ const FontshareProvider = createFontshareProvider("fontshare", "https://api.fontshare.com");
26
+ function createFontshareProvider(name, host) {
27
+ return {
28
+ name,
29
+ getImportUrl(fonts) {
30
+ const strings = fonts.filter((f) => f.provider === name).map((f) => {
31
+ let name2 = f.name.replace(/\s+/g, "-").toLocaleLowerCase();
32
+ if (f.weights?.length)
33
+ name2 += `@${f.weights.flatMap((w) => f.italic ? Number(w) + 1 : w).sort().join()}`;
34
+ else
35
+ name2 += `@${f.italic ? 2 : 1}`;
36
+ return `f[]=${name2}`;
37
+ }).join("&");
38
+ return `${host}/v2/css?${strings}&display=swap`;
39
+ },
40
+ getFontName(font) {
41
+ return `"${font.name}"`;
42
+ }
43
+ };
44
+ }
45
+
25
46
  const NoneProvider = {
26
47
  name: "none",
27
48
  getPreflight() {
@@ -47,6 +68,7 @@ function normalizedFontMeta(meta, defaultProvider) {
47
68
  const providers = {
48
69
  google: GoogleFontsProvider,
49
70
  bunny: BunnyFontsProvider,
71
+ fontshare: FontshareProvider,
50
72
  none: NoneProvider
51
73
  };
52
74
  const preset = (options = {}) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/preset-web-fonts",
3
- "version": "0.46.2",
3
+ "version": "0.46.3",
4
4
  "description": "Web Fonts support for Uno CSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -37,7 +37,7 @@
37
37
  "*.css"
38
38
  ],
39
39
  "dependencies": {
40
- "@unocss/core": "0.46.2",
40
+ "@unocss/core": "0.46.3",
41
41
  "ohmyfetch": "^0.4.20"
42
42
  },
43
43
  "scripts": {