@unocss/preset-web-fonts 0.51.7 → 0.51.11

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 CHANGED
@@ -4,12 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const core = require('@unocss/core');
6
6
 
7
- const GoogleFontsProvider = createGoogleProvider("google", "https://fonts.googleapis.com");
8
- function createGoogleProvider(name, host) {
7
+ function createGoogleCompatibleProvider(name, host) {
9
8
  return {
10
9
  name,
11
10
  getImportUrl(fonts) {
12
- const strings = fonts.filter((i) => i.provider === name).map((i) => {
11
+ const strings = fonts.map((i) => {
13
12
  let name2 = i.name.replace(/\s+/g, "+");
14
13
  if (i.weights?.length) {
15
14
  name2 += i.italic ? `:ital,wght@${i.weights.flatMap((i2) => [`0,${i2}`, `1,${i2}`]).sort().join(";")}` : `:wght@${i.weights.sort().join(";")}`;
@@ -20,15 +19,16 @@ function createGoogleProvider(name, host) {
20
19
  }
21
20
  };
22
21
  }
22
+ const GoogleFontsProvider = createGoogleCompatibleProvider("google", "https://fonts.googleapis.com");
23
23
 
24
- const BunnyFontsProvider = createGoogleProvider("bunny", "https://fonts.bunny.net");
24
+ const BunnyFontsProvider = createGoogleCompatibleProvider("bunny", "https://fonts.bunny.net");
25
25
 
26
26
  const FontshareProvider = createFontshareProvider("fontshare", "https://api.fontshare.com");
27
27
  function createFontshareProvider(name, host) {
28
28
  return {
29
29
  name,
30
30
  getImportUrl(fonts) {
31
- const strings = fonts.filter((f) => f.provider === name).map((f) => {
31
+ const strings = fonts.map((f) => {
32
32
  let name2 = f.name.replace(/\s+/g, "-").toLocaleLowerCase();
33
33
  if (f.weights?.length)
34
34
  name2 += `@${f.weights.flatMap((w) => f.italic ? Number(w) + 1 : w).sort().join()}`;
@@ -112,7 +112,7 @@ function preset(options = {}) {
112
112
  async getCSS() {
113
113
  const preflights = [];
114
114
  for (const provider of enabledProviders) {
115
- const fontsForProvider = fonts.filter((i) => i.provider === provider);
115
+ const fontsForProvider = fonts.filter((i) => i.provider.name === provider.name);
116
116
  if (provider.getImportUrl) {
117
117
  const url = provider.getImportUrl(fontsForProvider);
118
118
  if (url)
@@ -143,5 +143,6 @@ function preset(options = {}) {
143
143
  return preset2;
144
144
  }
145
145
 
146
+ exports.createGoogleProvider = createGoogleCompatibleProvider;
146
147
  exports["default"] = preset;
147
148
  exports.normalizedFontMeta = normalizedFontMeta;
package/dist/index.d.ts CHANGED
@@ -55,7 +55,9 @@ interface Provider {
55
55
  getFontName?(font: WebFontMeta): string;
56
56
  }
57
57
 
58
+ declare function createGoogleCompatibleProvider(name: WebFontsProviders, host: string): Provider;
59
+
58
60
  declare function normalizedFontMeta(meta: WebFontMeta | string, defaultProvider: WebFontsProviders): ResolvedWebFontMeta;
59
61
  declare function preset(options?: WebFontsOptions): Preset<any>;
60
62
 
61
- export { Provider, ResolvedWebFontMeta, WebFontMeta, WebFontsOptions, WebFontsProviders, preset as default, normalizedFontMeta };
63
+ export { Provider, ResolvedWebFontMeta, WebFontMeta, WebFontsOptions, WebFontsProviders, createGoogleCompatibleProvider as createGoogleProvider, preset as default, normalizedFontMeta };
package/dist/index.mjs CHANGED
@@ -1,11 +1,10 @@
1
1
  import { toArray } from '@unocss/core';
2
2
 
3
- const GoogleFontsProvider = createGoogleProvider("google", "https://fonts.googleapis.com");
4
- function createGoogleProvider(name, host) {
3
+ function createGoogleCompatibleProvider(name, host) {
5
4
  return {
6
5
  name,
7
6
  getImportUrl(fonts) {
8
- const strings = fonts.filter((i) => i.provider === name).map((i) => {
7
+ const strings = fonts.map((i) => {
9
8
  let name2 = i.name.replace(/\s+/g, "+");
10
9
  if (i.weights?.length) {
11
10
  name2 += i.italic ? `:ital,wght@${i.weights.flatMap((i2) => [`0,${i2}`, `1,${i2}`]).sort().join(";")}` : `:wght@${i.weights.sort().join(";")}`;
@@ -16,15 +15,16 @@ function createGoogleProvider(name, host) {
16
15
  }
17
16
  };
18
17
  }
18
+ const GoogleFontsProvider = createGoogleCompatibleProvider("google", "https://fonts.googleapis.com");
19
19
 
20
- const BunnyFontsProvider = createGoogleProvider("bunny", "https://fonts.bunny.net");
20
+ const BunnyFontsProvider = createGoogleCompatibleProvider("bunny", "https://fonts.bunny.net");
21
21
 
22
22
  const FontshareProvider = createFontshareProvider("fontshare", "https://api.fontshare.com");
23
23
  function createFontshareProvider(name, host) {
24
24
  return {
25
25
  name,
26
26
  getImportUrl(fonts) {
27
- const strings = fonts.filter((f) => f.provider === name).map((f) => {
27
+ const strings = fonts.map((f) => {
28
28
  let name2 = f.name.replace(/\s+/g, "-").toLocaleLowerCase();
29
29
  if (f.weights?.length)
30
30
  name2 += `@${f.weights.flatMap((w) => f.italic ? Number(w) + 1 : w).sort().join()}`;
@@ -108,7 +108,7 @@ function preset(options = {}) {
108
108
  async getCSS() {
109
109
  const preflights = [];
110
110
  for (const provider of enabledProviders) {
111
- const fontsForProvider = fonts.filter((i) => i.provider === provider);
111
+ const fontsForProvider = fonts.filter((i) => i.provider.name === provider.name);
112
112
  if (provider.getImportUrl) {
113
113
  const url = provider.getImportUrl(fontsForProvider);
114
114
  if (url)
@@ -139,4 +139,4 @@ function preset(options = {}) {
139
139
  return preset2;
140
140
  }
141
141
 
142
- export { preset as default, normalizedFontMeta };
142
+ export { createGoogleCompatibleProvider as createGoogleProvider, preset as default, normalizedFontMeta };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/preset-web-fonts",
3
- "version": "0.51.7",
3
+ "version": "0.51.11",
4
4
  "description": "Web Fonts support for Uno CSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -8,7 +8,7 @@
8
8
  "homepage": "https://github.com/unocss/unocss/tree/main/packages/preset-web-fonts#readme",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://github.com/unocss/unocss.git",
11
+ "url": "https://github.com/unocss/unocss",
12
12
  "directory": "packages/preset-web-fonts"
13
13
  },
14
14
  "bugs": {
@@ -38,7 +38,7 @@
38
38
  ],
39
39
  "dependencies": {
40
40
  "ofetch": "^1.0.1",
41
- "@unocss/core": "0.51.7"
41
+ "@unocss/core": "0.51.11"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "unbuild",