@unocss/preset-web-fonts 66.4.2 → 66.5.1
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +38 -32
- package/dist/local.d.mts +6 -1
- package/dist/local.d.ts +6 -1
- package/dist/local.mjs +2 -1
- package/dist/shared/{preset-web-fonts.CZc_IGwW.d.mts → preset-web-fonts.COdQKJpo.d.mts} +5 -0
- package/dist/shared/{preset-web-fonts.CZc_IGwW.d.ts → preset-web-fonts.COdQKJpo.d.ts} +5 -0
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _unocss_core from '@unocss/core';
|
|
2
|
-
import { W as WebFontMeta, a as WebFontsProviders, R as ResolvedWebFontMeta, P as Provider, b as WebFontsOptions } from './shared/preset-web-fonts.
|
|
3
|
-
export { A as Axes, c as WebFontProcessor } from './shared/preset-web-fonts.
|
|
2
|
+
import { W as WebFontMeta, a as WebFontsProviders, R as ResolvedWebFontMeta, P as Provider, b as WebFontsOptions } from './shared/preset-web-fonts.COdQKJpo.mjs';
|
|
3
|
+
export { A as Axes, c as WebFontProcessor } from './shared/preset-web-fonts.COdQKJpo.mjs';
|
|
4
4
|
|
|
5
5
|
declare function normalizedFontMeta(meta: WebFontMeta | string, defaultProvider: WebFontsProviders): ResolvedWebFontMeta;
|
|
6
6
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _unocss_core from '@unocss/core';
|
|
2
|
-
import { W as WebFontMeta, a as WebFontsProviders, R as ResolvedWebFontMeta, P as Provider, b as WebFontsOptions } from './shared/preset-web-fonts.
|
|
3
|
-
export { A as Axes, c as WebFontProcessor } from './shared/preset-web-fonts.
|
|
2
|
+
import { W as WebFontMeta, a as WebFontsProviders, R as ResolvedWebFontMeta, P as Provider, b as WebFontsOptions } from './shared/preset-web-fonts.COdQKJpo.js';
|
|
3
|
+
export { A as Axes, c as WebFontProcessor } from './shared/preset-web-fonts.COdQKJpo.js';
|
|
4
4
|
|
|
5
5
|
declare function normalizedFontMeta(meta: WebFontMeta | string, defaultProvider: WebFontsProviders): ResolvedWebFontMeta;
|
|
6
6
|
|
package/dist/index.mjs
CHANGED
|
@@ -24,19 +24,39 @@ const BunnyFontsProvider = createBunnyFontsProvider(
|
|
|
24
24
|
"https://fonts.bunny.net"
|
|
25
25
|
);
|
|
26
26
|
|
|
27
|
-
function
|
|
27
|
+
function generateFontAxes(axes) {
|
|
28
|
+
if (!axes || axes.length === 0)
|
|
29
|
+
return "";
|
|
30
|
+
let combinations = [[]];
|
|
31
|
+
for (const { values } of axes) {
|
|
32
|
+
const newCombinations = [];
|
|
33
|
+
for (const combo of combinations) {
|
|
34
|
+
for (const value of values) {
|
|
35
|
+
newCombinations.push([...combo, value]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
combinations = newCombinations;
|
|
39
|
+
}
|
|
40
|
+
return combinations.map((arr) => arr.join(",")).join(";");
|
|
41
|
+
}
|
|
42
|
+
function createGoogleCompatibleProvider(name, host) {
|
|
28
43
|
return {
|
|
29
44
|
name,
|
|
30
45
|
getImportUrl(fonts) {
|
|
31
|
-
const sort = (weights) => {
|
|
32
|
-
const firstW = weights.map((w) => w[0]);
|
|
33
|
-
const lastW = weights.map((w) => w[1]);
|
|
34
|
-
return `${firstW.join(";")};${lastW.join(";")}`;
|
|
35
|
-
};
|
|
36
46
|
const strings = fonts.map((i) => {
|
|
37
47
|
let name2 = i.name.replace(/\s+/g, "+");
|
|
38
|
-
|
|
39
|
-
|
|
48
|
+
const axisValues = [];
|
|
49
|
+
if (i.italic)
|
|
50
|
+
axisValues.push({ axis: "ital", values: ["0", "1"] });
|
|
51
|
+
if (i.widths?.length)
|
|
52
|
+
axisValues.push({ axis: "wdth", values: i.widths.map((w) => w.toString()) });
|
|
53
|
+
if (i.weights?.length)
|
|
54
|
+
axisValues.push({ axis: "wght", values: i.weights.map((w) => w.toString()) });
|
|
55
|
+
if (axisValues.length) {
|
|
56
|
+
name2 += ":";
|
|
57
|
+
name2 += axisValues.map((a) => a.axis).join(",");
|
|
58
|
+
name2 += "@";
|
|
59
|
+
name2 += generateFontAxes(axisValues);
|
|
40
60
|
}
|
|
41
61
|
return `family=${name2}`;
|
|
42
62
|
}).join("&");
|
|
@@ -44,7 +64,9 @@ function createCoolLabsCompatibleProvider(name, host) {
|
|
|
44
64
|
}
|
|
45
65
|
};
|
|
46
66
|
}
|
|
47
|
-
const
|
|
67
|
+
const GoogleFontsProvider = createGoogleCompatibleProvider("google", "https://fonts.googleapis.com");
|
|
68
|
+
|
|
69
|
+
const CoolLabsFontsProvider = createGoogleCompatibleProvider("coollabs", "https://api.fonts.coollabs.io");
|
|
48
70
|
|
|
49
71
|
const FontshareProvider = createFontshareProvider("fontshare", "https://api.fontshare.com");
|
|
50
72
|
function createFontshareProvider(name, host) {
|
|
@@ -205,28 +227,6 @@ function getVariableWght(axes) {
|
|
|
205
227
|
return `${axes.min} ${axes.max}`;
|
|
206
228
|
}
|
|
207
229
|
|
|
208
|
-
function createGoogleCompatibleProvider(name, host) {
|
|
209
|
-
return {
|
|
210
|
-
name,
|
|
211
|
-
getImportUrl(fonts) {
|
|
212
|
-
const sort = (weights) => {
|
|
213
|
-
const firstW = weights.map((w) => w[0]);
|
|
214
|
-
const lastW = weights.map((w) => w[1]);
|
|
215
|
-
return `${firstW.join(";")};${lastW.join(";")}`;
|
|
216
|
-
};
|
|
217
|
-
const strings = fonts.map((i) => {
|
|
218
|
-
let name2 = i.name.replace(/\s+/g, "+");
|
|
219
|
-
if (i.weights?.length) {
|
|
220
|
-
name2 += i.italic ? `:ital,wght@${sort(i.weights.map((w) => [`0,${w}`, `1,${w}`]))}` : `:wght@${i.weights.join(";")}`;
|
|
221
|
-
}
|
|
222
|
-
return `family=${name2}`;
|
|
223
|
-
}).join("&");
|
|
224
|
-
return `${host}/css2?${strings}&display=swap`;
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
const GoogleFontsProvider = createGoogleCompatibleProvider("google", "https://fonts.googleapis.com");
|
|
229
|
-
|
|
230
230
|
const NoneProvider = {
|
|
231
231
|
name: "none",
|
|
232
232
|
getPreflight() {
|
|
@@ -255,6 +255,8 @@ function normalizedFontMeta(meta, defaultProvider) {
|
|
|
255
255
|
meta.provider = resolveProvider(meta.provider || defaultProvider);
|
|
256
256
|
if (meta.weights)
|
|
257
257
|
meta.weights = [...new Set(meta.weights.sort((a, b) => a.toString().localeCompare(b.toString(), "en", { numeric: true })))];
|
|
258
|
+
if (meta.widths)
|
|
259
|
+
meta.widths = [...new Set(meta.widths.sort((a, b) => a.toString().localeCompare(b.toString(), "en", { numeric: true })))];
|
|
258
260
|
return meta;
|
|
259
261
|
}
|
|
260
262
|
const [name, weights = ""] = meta.split(":");
|
|
@@ -329,7 +331,11 @@ function createWebFontPreset(fetcher) {
|
|
|
329
331
|
if (url)
|
|
330
332
|
preflights.push(await importUrl(url));
|
|
331
333
|
}
|
|
332
|
-
|
|
334
|
+
try {
|
|
335
|
+
preflights.push(await provider.getPreflight?.(fontsForProvider, fetchWithTimeout));
|
|
336
|
+
} catch (e) {
|
|
337
|
+
console.warn(`[unocss] Web fonts preflight fetch failed.`, e);
|
|
338
|
+
}
|
|
333
339
|
}
|
|
334
340
|
const css = preflights.filter(Boolean).join("\n");
|
|
335
341
|
return css;
|
package/dist/local.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { c as WebFontProcessor } from './shared/preset-web-fonts.
|
|
1
|
+
import { c as WebFontProcessor } from './shared/preset-web-fonts.COdQKJpo.mjs';
|
|
2
|
+
import { fetch } from 'ofetch';
|
|
2
3
|
import '@unocss/core';
|
|
3
4
|
|
|
4
5
|
interface LocalFontProcessorOptions {
|
|
@@ -26,6 +27,10 @@ interface LocalFontProcessorOptions {
|
|
|
26
27
|
* @default '/assets/fonts'
|
|
27
28
|
*/
|
|
28
29
|
fontServeBaseUrl?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Custom fetch function to provide the font data.
|
|
32
|
+
*/
|
|
33
|
+
fetch?: typeof fetch;
|
|
29
34
|
}
|
|
30
35
|
declare function createLocalFontProcessor(options?: LocalFontProcessorOptions): WebFontProcessor;
|
|
31
36
|
|
package/dist/local.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { c as WebFontProcessor } from './shared/preset-web-fonts.
|
|
1
|
+
import { c as WebFontProcessor } from './shared/preset-web-fonts.COdQKJpo.js';
|
|
2
|
+
import { fetch } from 'ofetch';
|
|
2
3
|
import '@unocss/core';
|
|
3
4
|
|
|
4
5
|
interface LocalFontProcessorOptions {
|
|
@@ -26,6 +27,10 @@ interface LocalFontProcessorOptions {
|
|
|
26
27
|
* @default '/assets/fonts'
|
|
27
28
|
*/
|
|
28
29
|
fontServeBaseUrl?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Custom fetch function to provide the font data.
|
|
32
|
+
*/
|
|
33
|
+
fetch?: typeof fetch;
|
|
29
34
|
}
|
|
30
35
|
declare function createLocalFontProcessor(options?: LocalFontProcessorOptions): WebFontProcessor;
|
|
31
36
|
|
package/dist/local.mjs
CHANGED
|
@@ -38,7 +38,8 @@ function createLocalFontProcessor(options) {
|
|
|
38
38
|
const fontAssetsDir = resolve(cwd, options?.fontAssetsDir || "public/assets/fonts");
|
|
39
39
|
const fontServeBaseUrl = options?.fontServeBaseUrl || "/assets/fonts";
|
|
40
40
|
async function _downloadFont(url, assetPath) {
|
|
41
|
-
const
|
|
41
|
+
const fetcher = options?.fetch ?? fetch;
|
|
42
|
+
const response = await fetcher(url).then((r) => r.arrayBuffer());
|
|
42
43
|
await fsp.mkdir(fontAssetsDir, { recursive: true });
|
|
43
44
|
await fsp.writeFile(assetPath, Buffer.from(response));
|
|
44
45
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/preset-web-fonts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "66.
|
|
4
|
+
"version": "66.5.1",
|
|
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.4.1",
|
|
53
|
-
"@unocss/core": "66.
|
|
53
|
+
"@unocss/core": "66.5.1"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"build": "unbuild",
|