@unocss/preset-web-fonts 0.61.9 → 0.62.0

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 CHANGED
@@ -13,4 +13,4 @@ declare function createGoogleCompatibleProvider(name: WebFontsProviders, host: s
13
13
  */
14
14
  declare const presetWebFonts: _unocss_core.PresetFactory<any, WebFontsOptions>;
15
15
 
16
- export { Provider, ResolvedWebFontMeta, WebFontMeta, WebFontsOptions, WebFontsProviders, createGoogleCompatibleProvider as createGoogleProvider, presetWebFonts as default, normalizedFontMeta };
16
+ export { Provider, ResolvedWebFontMeta, WebFontMeta, WebFontsOptions, WebFontsProviders, createGoogleCompatibleProvider as createGoogleProvider, presetWebFonts as default, normalizedFontMeta, presetWebFonts };
package/dist/index.d.ts CHANGED
@@ -13,4 +13,4 @@ declare function createGoogleCompatibleProvider(name: WebFontsProviders, host: s
13
13
  */
14
14
  declare const presetWebFonts: _unocss_core.PresetFactory<any, WebFontsOptions>;
15
15
 
16
- export { Provider, ResolvedWebFontMeta, WebFontMeta, WebFontsOptions, WebFontsProviders, createGoogleCompatibleProvider as createGoogleProvider, presetWebFonts as default, normalizedFontMeta };
16
+ export { Provider, ResolvedWebFontMeta, WebFontMeta, WebFontsOptions, WebFontsProviders, createGoogleCompatibleProvider as createGoogleProvider, presetWebFonts as default, normalizedFontMeta, presetWebFonts };
package/dist/index.mjs CHANGED
@@ -220,4 +220,4 @@ const userAgentWoff2 = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTM
220
220
  const defaultFetch = async (url) => (await import('ofetch')).$fetch(url, { headers: { "User-Agent": userAgentWoff2 }, retry: 3 });
221
221
  const presetWebFonts = definePreset(createWebFontPreset(defaultFetch));
222
222
 
223
- export { createGoogleCompatibleProvider as createGoogleProvider, presetWebFonts as default, normalizedFontMeta };
223
+ export { createGoogleCompatibleProvider as createGoogleProvider, presetWebFonts as default, normalizedFontMeta, presetWebFonts };
package/dist/local.mjs CHANGED
@@ -30,6 +30,7 @@ function replaceAsync(string, searchValue, replacer) {
30
30
  }
31
31
 
32
32
  const fontUrlRegex = /[-\w@:%+.~#?&/=]+\.(?:woff2?|eot|ttf|otf|svg)/gi;
33
+ const urlProtocolRegex = /^[\s\w\0+.-]{2,}:([/\\]{1,2})/;
33
34
  function createLocalFontProcessor(options) {
34
35
  const cwd = options?.cwd || process.cwd();
35
36
  const cacheDir = resolve(cwd, options?.cacheDir || "node_modules/.cache/unocss/fonts");
@@ -69,7 +70,8 @@ function createLocalFontProcessor(options) {
69
70
  const filename = `${[name, hash].filter(Boolean).join("-")}.${ext}`;
70
71
  const assetPath = join(fontAssetsDir, filename);
71
72
  if (!fs.existsSync(assetPath)) {
72
- await downloadFont(url, assetPath);
73
+ const _url = hasProtocol(url) ? url : withProtocol(url);
74
+ await downloadFont(_url, assetPath);
73
75
  }
74
76
  return `${fontServeBaseUrl}/${filename}`;
75
77
  });
@@ -79,5 +81,14 @@ function createLocalFontProcessor(options) {
79
81
  function getHash(input, length = 8) {
80
82
  return createHash("sha256").update(input).digest("hex").slice(0, length);
81
83
  }
84
+ function hasProtocol(input) {
85
+ return urlProtocolRegex.test(input);
86
+ }
87
+ function withProtocol(input, protocol = "https://") {
88
+ const match = input.match(/^\/{2,}/);
89
+ if (!match)
90
+ return protocol + input;
91
+ return protocol + input.slice(match[0].length);
92
+ }
82
93
 
83
94
  export { createLocalFontProcessor };
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.9",
4
+ "version": "0.62.0",
5
5
  "description": "Web Fonts support for Uno CSS",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -50,7 +50,7 @@
50
50
  ],
51
51
  "dependencies": {
52
52
  "ofetch": "^1.3.4",
53
- "@unocss/core": "0.61.9"
53
+ "@unocss/core": "0.62.0"
54
54
  },
55
55
  "scripts": {
56
56
  "build": "unbuild",