@vinicunca/unocss-preset 1.46.0 → 1.48.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/{akar-VedW04rH.mjs → akar-DW0k-RQw.mjs} +1 -2
- package/dist/{animation-DsnEDm70.mjs → animation-CwBXwE2g.mjs} +1 -1
- package/dist/{constants-CD9LkNQP.mjs → constants-X7mmwX-F.mjs} +29 -1
- package/dist/dist-BaR0zMmx.mjs +357 -0
- package/dist/dist-CJHzGraD.mjs +461 -0
- package/dist/dist-CRklVSbu.mjs +1743 -0
- package/dist/dist-CUVvXCsz.mjs +1224 -0
- package/dist/dist-aKOzxsNl.mjs +110 -0
- package/dist/index.d.mts +2269 -8
- package/dist/index.mjs +8 -9
- package/dist/loader-w_QTsl1j.mjs +476 -0
- package/dist/multipart-parser-DWwgMt8_.mjs +166 -0
- package/dist/node-CsRin8Rz.mjs +470 -0
- package/dist/node-Di28XAWx.mjs +3975 -0
- package/dist/node-loader-DeYaYavU.mjs +1910 -0
- package/dist/rolldown-runtime-BhDjJH2R.mjs +15 -0
- package/dist/{scrollbar-CdK-zPqW.mjs → scrollbar-TN4l13tK.mjs} +1 -1
- package/dist/{transformer-alias-CUUXiUed.mjs → transformer-alias-B5L6CNdC.mjs} +1 -1
- package/dist/utils-BtCNpQqm-Bygqfcj5.mjs +644 -0
- package/package.json +23 -25
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { i as compressCSS, t as DEFAULT_AKAR_OPTIONS } from "./constants-
|
|
2
|
-
import { defu } from "defu";
|
|
1
|
+
import { i as compressCSS, s as defu, t as DEFAULT_AKAR_OPTIONS } from "./constants-X7mmwX-F.mjs";
|
|
3
2
|
import { isObjectType, isString } from "@vinicunca/perkakas";
|
|
4
3
|
import { theme } from "unocss/preset-wind4";
|
|
5
4
|
//#region src/presets/akar/akar.drawer-preflights.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as layerMeta } from "./meta-BWU-BFPZ.mjs";
|
|
2
|
-
import { h } from "
|
|
2
|
+
import { n as h } from "./utils-BtCNpQqm-Bygqfcj5.mjs";
|
|
3
3
|
//#region src/presets/animation/animation.entity.ts
|
|
4
4
|
const CSS_VARIABLE_PREFIX = "--vin";
|
|
5
5
|
const ENTER_ANIMATION_NAME = "vin-in";
|
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
//#region node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.mjs
|
|
2
|
+
function isPlainObject(value) {
|
|
3
|
+
if (value === null || typeof value !== "object") return false;
|
|
4
|
+
const prototype = Object.getPrototypeOf(value);
|
|
5
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) return false;
|
|
6
|
+
if (Symbol.iterator in value) return false;
|
|
7
|
+
if (Symbol.toStringTag in value) return Object.prototype.toString.call(value) === "[object Module]";
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
11
|
+
if (!isPlainObject(defaults)) return _defu(baseObject, {}, namespace, merger);
|
|
12
|
+
const object = { ...defaults };
|
|
13
|
+
for (const key of Object.keys(baseObject)) {
|
|
14
|
+
if (key === "__proto__" || key === "constructor") continue;
|
|
15
|
+
const value = baseObject[key];
|
|
16
|
+
if (value === null || value === void 0) continue;
|
|
17
|
+
if (merger && merger(object, key, value, namespace)) continue;
|
|
18
|
+
if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
|
|
19
|
+
else if (isPlainObject(value) && isPlainObject(object[key])) object[key] = _defu(value, object[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
|
|
20
|
+
else object[key] = value;
|
|
21
|
+
}
|
|
22
|
+
return object;
|
|
23
|
+
}
|
|
24
|
+
function createDefu(merger) {
|
|
25
|
+
return (...arguments_) => arguments_.reduce((p, c) => _defu(p, c, "", merger), {});
|
|
26
|
+
}
|
|
27
|
+
const defu = createDefu();
|
|
28
|
+
//#endregion
|
|
1
29
|
//#region src/utils.ts
|
|
2
30
|
const RE_ANIMATION = /^([a-z-]+)\s+([0-9.]+m?s?|var\([^)]+\)|[*+])?\s?([a-z-]+(?:\([^)]+\))?|[*+])?\s*([a-z0-9-]+|var\([^)]+\)|[*+])?$/i;
|
|
3
31
|
/**
|
|
@@ -283,4 +311,4 @@ const DEFAULT_PRESET_OPTIONS = {
|
|
|
283
311
|
akar: DEFAULT_AKAR_OPTIONS
|
|
284
312
|
};
|
|
285
313
|
//#endregion
|
|
286
|
-
export { cssObj2StrSync as a, compressCSS as i, DEFAULT_OPTIONS as n, resolveAnimation as o, DEFAULT_PRESET_OPTIONS as r, DEFAULT_AKAR_OPTIONS as t };
|
|
314
|
+
export { cssObj2StrSync as a, compressCSS as i, DEFAULT_OPTIONS as n, resolveAnimation as o, DEFAULT_PRESET_OPTIONS as r, defu as s, DEFAULT_AKAR_OPTIONS as t };
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { l as toArray, r as definePreset, s as mergeDeep, t as LAYER_IMPORTS } from "./dist-aKOzxsNl.mjs";
|
|
2
|
+
//#region node_modules/.pnpm/@unocss+preset-web-fonts@66.7.2/node_modules/@unocss/preset-web-fonts/dist/index.mjs
|
|
3
|
+
function createBunnyFontsProvider(name, host) {
|
|
4
|
+
return {
|
|
5
|
+
name,
|
|
6
|
+
getImportUrl(fonts) {
|
|
7
|
+
return `${host}/css?family=${fonts.map((font) => {
|
|
8
|
+
const { name, weights, italic } = font;
|
|
9
|
+
const formattedName = name.toLowerCase().replace(/\s/g, "-");
|
|
10
|
+
if (!weights?.length) return `${formattedName}${italic ? ":i" : ""}`;
|
|
11
|
+
let weightsAsString = weights.map((weight) => weight.toString());
|
|
12
|
+
if (!weightsAsString.some((weight) => weight.endsWith("i")) && italic) weightsAsString = weightsAsString.map((weight) => weight += "i");
|
|
13
|
+
return `${formattedName}:${weightsAsString.join(",")}`;
|
|
14
|
+
}).join("|")}&display=swap`;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const BunnyFontsProvider = createBunnyFontsProvider("bunny", "https://fonts.bunny.net");
|
|
19
|
+
function generateFontAxes(axes) {
|
|
20
|
+
if (!axes || axes.length === 0) return "";
|
|
21
|
+
let combinations = [[]];
|
|
22
|
+
for (const { values } of axes) {
|
|
23
|
+
const newCombinations = [];
|
|
24
|
+
for (const combo of combinations) for (const value of values) newCombinations.push([...combo, value]);
|
|
25
|
+
combinations = newCombinations;
|
|
26
|
+
}
|
|
27
|
+
return combinations.map((arr) => arr.join(",")).join(";");
|
|
28
|
+
}
|
|
29
|
+
function createGoogleCompatibleProvider(name, host) {
|
|
30
|
+
return {
|
|
31
|
+
name,
|
|
32
|
+
getImportUrl(fonts) {
|
|
33
|
+
return `${host}/css2?${fonts.map((i) => {
|
|
34
|
+
let name = i.name.replace(/\s+/g, "+");
|
|
35
|
+
/**
|
|
36
|
+
* When using the Google Fonts API, be sure to list them alphabetically.
|
|
37
|
+
* @see https://fonts.google.com/knowledge/using_type/styling_type_on_the_web_with_variable_fonts
|
|
38
|
+
* @example ital, opsz, slnt, wdth, wght
|
|
39
|
+
*/
|
|
40
|
+
const axisValues = [];
|
|
41
|
+
if (i.italic) axisValues.push({
|
|
42
|
+
axis: "ital",
|
|
43
|
+
values: ["0", "1"]
|
|
44
|
+
});
|
|
45
|
+
if (i.widths?.length) axisValues.push({
|
|
46
|
+
axis: "wdth",
|
|
47
|
+
values: i.widths.map((w) => w.toString())
|
|
48
|
+
});
|
|
49
|
+
if (i.weights?.length) axisValues.push({
|
|
50
|
+
axis: "wght",
|
|
51
|
+
values: i.weights.map((w) => w.toString())
|
|
52
|
+
});
|
|
53
|
+
if (axisValues.length) {
|
|
54
|
+
name += ":";
|
|
55
|
+
name += axisValues.map((a) => a.axis).join(",");
|
|
56
|
+
name += "@";
|
|
57
|
+
name += generateFontAxes(axisValues);
|
|
58
|
+
}
|
|
59
|
+
return `family=${name}`;
|
|
60
|
+
}).join("&")}&display=swap`;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const GoogleFontsProvider = createGoogleCompatibleProvider("google", "https://fonts.googleapis.com");
|
|
65
|
+
const CoolLabsFontsProvider = createGoogleCompatibleProvider("coollabs", "https://api.fonts.coollabs.io");
|
|
66
|
+
const FontshareProvider = createFontshareProvider("fontshare", "https://api.fontshare.com");
|
|
67
|
+
function createFontshareProvider(name, host) {
|
|
68
|
+
return {
|
|
69
|
+
name,
|
|
70
|
+
getImportUrl(fonts) {
|
|
71
|
+
return `${host}/v2/css?${fonts.map((f) => {
|
|
72
|
+
let name = f.name.replace(/\s+/g, "-").toLocaleLowerCase();
|
|
73
|
+
if (f.weights?.length) name += `@${f.weights.flatMap((w) => f.italic ? Number(w) + 1 : w).sort().join()}`;
|
|
74
|
+
else name += `@${f.italic ? 2 : 1}`;
|
|
75
|
+
return `f[]=${name}`;
|
|
76
|
+
}).join("&")}&display=swap`;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function createFontSourceProvider(name, host) {
|
|
81
|
+
const fontsMap = /* @__PURE__ */ new Map();
|
|
82
|
+
const variablesMap = /* @__PURE__ */ new Map();
|
|
83
|
+
return {
|
|
84
|
+
name,
|
|
85
|
+
async getPreflight(fonts, fetcher) {
|
|
86
|
+
return (await Promise.all(fonts.map(async (font) => {
|
|
87
|
+
const css = [];
|
|
88
|
+
const id = font.name.toLowerCase().replace(/\s+/g, "-");
|
|
89
|
+
let metadata = fontsMap.get(id);
|
|
90
|
+
if (!metadata) {
|
|
91
|
+
const url = `https://api.fontsource.org/v1/fonts/${id}`;
|
|
92
|
+
try {
|
|
93
|
+
metadata = await fetcher(url);
|
|
94
|
+
fontsMap.set(id, metadata);
|
|
95
|
+
} catch {
|
|
96
|
+
throw new Error(`Failed to fetch font: ${font.name}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const { weights, unicodeRange, variants, family } = metadata;
|
|
100
|
+
const subsets = metadata.subsets.filter((subset) => font.subsets ? font.subsets.includes(subset) : true);
|
|
101
|
+
const style = font.italic ? "italic" : "normal";
|
|
102
|
+
if (metadata.variable && !font.preferStatic) {
|
|
103
|
+
let variableData = variablesMap.get(id);
|
|
104
|
+
const url = `https://api.fontsource.org/v1/variable/${id}`;
|
|
105
|
+
try {
|
|
106
|
+
variableData = await fetcher(url);
|
|
107
|
+
variablesMap.set(id, variableData);
|
|
108
|
+
} catch {
|
|
109
|
+
throw new Error(`Failed to fetch font variable: ${font.name}`);
|
|
110
|
+
}
|
|
111
|
+
const mergeAxes = mergeDeep(variableData.axes, font.variable ?? {});
|
|
112
|
+
for (const subset of subsets) if (unicodeRange[subset]) {
|
|
113
|
+
const fontObj = {
|
|
114
|
+
family,
|
|
115
|
+
display: "swap",
|
|
116
|
+
style,
|
|
117
|
+
weight: 400,
|
|
118
|
+
src: [{
|
|
119
|
+
url: `${host}/fontsource/fonts/${metadata.id}:vf@latest/${subset}-wght-${style}.woff2`,
|
|
120
|
+
format: "woff2-variations"
|
|
121
|
+
}],
|
|
122
|
+
variable: {
|
|
123
|
+
wght: mergeAxes.wght ?? void 0,
|
|
124
|
+
wdth: mergeAxes.wdth ?? void 0,
|
|
125
|
+
slnt: mergeAxes.slnt ?? void 0
|
|
126
|
+
},
|
|
127
|
+
unicodeRange: unicodeRange[subset],
|
|
128
|
+
comment: `${metadata.id}-${subset}-wght-normal`
|
|
129
|
+
};
|
|
130
|
+
css.push(generateFontFace(fontObj));
|
|
131
|
+
} else Object.entries(unicodeRange).filter(([subKey]) => !metadata.subsets.includes(subKey)).forEach(([subKey, range]) => {
|
|
132
|
+
const fontObj = {
|
|
133
|
+
family,
|
|
134
|
+
display: "swap",
|
|
135
|
+
style,
|
|
136
|
+
weight: 400,
|
|
137
|
+
src: [{
|
|
138
|
+
url: `${host}/fontsource/fonts/${metadata.id}:vf@latest/${subKey.slice(1, -1)}-wght-${style}.woff2`,
|
|
139
|
+
format: "woff2-variations"
|
|
140
|
+
}],
|
|
141
|
+
variable: {
|
|
142
|
+
wght: mergeAxes.wght ?? void 0,
|
|
143
|
+
wdth: mergeAxes.wdth ?? void 0,
|
|
144
|
+
slnt: mergeAxes.slnt ?? void 0
|
|
145
|
+
},
|
|
146
|
+
unicodeRange: range,
|
|
147
|
+
comment: `${metadata.id}-${subKey}-wght-normal`
|
|
148
|
+
};
|
|
149
|
+
css.push(generateFontFace(fontObj));
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
const _weights = font.weights && font.weights.length > 0 ? font.weights : weights;
|
|
153
|
+
for (const subset of subsets) for (const weight of _weights) {
|
|
154
|
+
const url = variants[weight][style][subset].url;
|
|
155
|
+
const fontObj = {
|
|
156
|
+
family,
|
|
157
|
+
display: "swap",
|
|
158
|
+
style,
|
|
159
|
+
weight: Number(weight),
|
|
160
|
+
src: [{
|
|
161
|
+
url: url.woff2,
|
|
162
|
+
format: "woff2"
|
|
163
|
+
}],
|
|
164
|
+
unicodeRange: unicodeRange[subset],
|
|
165
|
+
comment: `${metadata.id}-${subset}-${weight}-${style}`
|
|
166
|
+
};
|
|
167
|
+
css.push(generateFontFace(fontObj));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return css;
|
|
171
|
+
}))).flat().join("\n\n");
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const FontSourceProvider = createFontSourceProvider("fontsource", "https://cdn.jsdelivr.net");
|
|
176
|
+
function generateFontFace(font) {
|
|
177
|
+
const { family, style, display, weight, variable, src, unicodeRange, comment, spacer = "\n " } = font;
|
|
178
|
+
const { wght, wdth, slnt } = variable ?? {};
|
|
179
|
+
let result = "@font-face {";
|
|
180
|
+
result += `${spacer}font-family: '${family}';`;
|
|
181
|
+
result += `${spacer}font-style: ${slnt ? `oblique ${Number(slnt.max) * -1}deg ${Number(slnt.min) * -1}deg` : style};`;
|
|
182
|
+
result += `${spacer}font-display: ${display};`;
|
|
183
|
+
result += `${spacer}font-weight: ${wght ? getVariableWght(wght) : weight};`;
|
|
184
|
+
if (wdth) result += `${spacer}font-stretch: ${wdth.min}% ${wdth.max}%;`;
|
|
185
|
+
result += `${spacer}src: ${src.map(({ url, format }) => `url(${url}) format('${format}')`).join(", ")};`;
|
|
186
|
+
if (unicodeRange) result += `${spacer}unicode-range: ${unicodeRange};`;
|
|
187
|
+
if (comment) result = `/* ${comment} */\n${result}`;
|
|
188
|
+
return `${result}\n}`;
|
|
189
|
+
}
|
|
190
|
+
function getVariableWght(axes) {
|
|
191
|
+
if (!axes) return "400";
|
|
192
|
+
if (axes.min === axes.max) return `${axes.min}`;
|
|
193
|
+
return `${axes.min} ${axes.max}`;
|
|
194
|
+
}
|
|
195
|
+
const NoneProvider = {
|
|
196
|
+
name: "none",
|
|
197
|
+
getPreflight() {
|
|
198
|
+
return "";
|
|
199
|
+
},
|
|
200
|
+
getFontName(font) {
|
|
201
|
+
return font.name;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
function parseFontName(name) {
|
|
205
|
+
const atIndex = name.lastIndexOf("@");
|
|
206
|
+
if (atIndex === -1) throw new Error(`[unocss] ZeoSeven provider requires font ID in format "FontFamily@id", e.g. "LXGW WenKai@292". Got: "${name}"`);
|
|
207
|
+
return {
|
|
208
|
+
family: name.slice(0, atIndex).trim(),
|
|
209
|
+
id: name.slice(atIndex + 1).trim()
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function createZeoSevenProvider(name, host) {
|
|
213
|
+
return {
|
|
214
|
+
name,
|
|
215
|
+
getFontName(font) {
|
|
216
|
+
const { family } = parseFontName(font.name);
|
|
217
|
+
return `"${family}"`;
|
|
218
|
+
},
|
|
219
|
+
async getPreflight(fonts, fetcher) {
|
|
220
|
+
const cssParts = [];
|
|
221
|
+
for (const font of fonts) {
|
|
222
|
+
const { id } = parseFontName(font.name);
|
|
223
|
+
const baseUrl = `${host}/${id}/main/`;
|
|
224
|
+
const url = `${baseUrl}result.css`;
|
|
225
|
+
try {
|
|
226
|
+
const processed = (await fetcher(url)).replace(/url\("\.\/([^"]+)"\)/g, `url("${baseUrl}$1")`);
|
|
227
|
+
cssParts.push(processed);
|
|
228
|
+
} catch {
|
|
229
|
+
throw new Error(`[unocss] Failed to fetch ZeoSeven font CSS for ID "${id}"`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return cssParts.join("\n");
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
const builtinProviders = {
|
|
237
|
+
google: GoogleFontsProvider,
|
|
238
|
+
bunny: BunnyFontsProvider,
|
|
239
|
+
fontshare: FontshareProvider,
|
|
240
|
+
fontsource: FontSourceProvider,
|
|
241
|
+
coollabs: CoolLabsFontsProvider,
|
|
242
|
+
none: NoneProvider,
|
|
243
|
+
zeoseven: createZeoSevenProvider("zeoseven", "https://fontsapi.zeoseven.com")
|
|
244
|
+
};
|
|
245
|
+
function resolveProvider(provider) {
|
|
246
|
+
if (typeof provider === "string") return builtinProviders[provider];
|
|
247
|
+
return provider;
|
|
248
|
+
}
|
|
249
|
+
function normalizedFontMeta(meta, defaultProvider) {
|
|
250
|
+
if (typeof meta !== "string") {
|
|
251
|
+
meta.provider = resolveProvider(meta.provider || defaultProvider);
|
|
252
|
+
if (meta.weights) meta.weights = [...new Set(meta.weights.sort((a, b) => a.toString().localeCompare(b.toString(), "en", { numeric: true })))];
|
|
253
|
+
if (meta.widths) meta.widths = [...new Set(meta.widths.sort((a, b) => a.toString().localeCompare(b.toString(), "en", { numeric: true })))];
|
|
254
|
+
return meta;
|
|
255
|
+
}
|
|
256
|
+
const [name, weights = ""] = meta.split(":");
|
|
257
|
+
return {
|
|
258
|
+
name,
|
|
259
|
+
weights: [...new Set(weights.split(/[,;]\s*/).filter(Boolean).sort((a, b) => a.localeCompare(b, "en", { numeric: true })))],
|
|
260
|
+
provider: resolveProvider(defaultProvider)
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function createWebFontPreset(fetcher) {
|
|
264
|
+
return (options = {}) => {
|
|
265
|
+
const { provider: defaultProvider = "google", extendTheme = true, inlineImports = true, customFetch = fetcher, timeouts = {} } = options;
|
|
266
|
+
const fontLayer = "fonts";
|
|
267
|
+
const layerName = inlineImports ? fontLayer : LAYER_IMPORTS;
|
|
268
|
+
const processors = toArray(options.processors || []);
|
|
269
|
+
const fontObject = Object.fromEntries(Object.entries(options.fonts || {}).map(([name, meta]) => [name, toArray(meta).map((m) => normalizedFontMeta(m, defaultProvider))]));
|
|
270
|
+
const fonts = Object.values(fontObject).flatMap((i) => i);
|
|
271
|
+
const importCache = {};
|
|
272
|
+
async function fetchWithTimeout(url) {
|
|
273
|
+
if (timeouts === false) return customFetch(url);
|
|
274
|
+
const { warning = 1e3, failure = 2e3 } = timeouts;
|
|
275
|
+
let warned = false;
|
|
276
|
+
const timer = setTimeout(() => {
|
|
277
|
+
console.warn(`[unocss] Fetching web fonts: ${url}`);
|
|
278
|
+
warned = true;
|
|
279
|
+
}, warning);
|
|
280
|
+
return await Promise.race([customFetch(url), new Promise((_, reject) => {
|
|
281
|
+
setTimeout(() => reject(/* @__PURE__ */ new Error(`[unocss] Fetch web fonts timeout.`)), failure);
|
|
282
|
+
})]).then((res) => {
|
|
283
|
+
if (warned) console.info(`[unocss] Web fonts fetched.`);
|
|
284
|
+
return res;
|
|
285
|
+
}).finally(() => clearTimeout(timer));
|
|
286
|
+
}
|
|
287
|
+
async function importUrl(url) {
|
|
288
|
+
if (inlineImports) {
|
|
289
|
+
if (!importCache[url]) importCache[url] = fetchWithTimeout(url).catch((e) => {
|
|
290
|
+
console.error(`[unocss] Failed to fetch web fonts: ${url}`);
|
|
291
|
+
console.error(e);
|
|
292
|
+
if (typeof process !== "undefined" && process.env.CI) throw e;
|
|
293
|
+
});
|
|
294
|
+
return await importCache[url];
|
|
295
|
+
} else return `@import url('${url}');`;
|
|
296
|
+
}
|
|
297
|
+
const enabledProviders = Array.from(new Set(fonts.map((i) => i.provider)));
|
|
298
|
+
async function getCSSDefault(fonts, providers) {
|
|
299
|
+
const preflights = [];
|
|
300
|
+
for (const provider of providers) {
|
|
301
|
+
const fontsForProvider = fonts.filter((i) => i.provider.name === provider.name);
|
|
302
|
+
if (provider.getImportUrl) {
|
|
303
|
+
const url = provider.getImportUrl(fontsForProvider);
|
|
304
|
+
if (url) preflights.push(await importUrl(url));
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
preflights.push(await provider.getPreflight?.(fontsForProvider, fetchWithTimeout));
|
|
308
|
+
} catch (e) {
|
|
309
|
+
console.warn(`[unocss] Web fonts preflight fetch failed.`, e);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return preflights.filter(Boolean).join("\n");
|
|
313
|
+
}
|
|
314
|
+
const preset = {
|
|
315
|
+
name: "@unocss/preset-web-fonts",
|
|
316
|
+
preflights: [{
|
|
317
|
+
async getCSS() {
|
|
318
|
+
let css;
|
|
319
|
+
for (const processor of processors) {
|
|
320
|
+
const result = await processor.getCSS?.(fonts, enabledProviders, getCSSDefault);
|
|
321
|
+
if (result) {
|
|
322
|
+
css = result;
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (!css) css = await getCSSDefault(fonts, enabledProviders);
|
|
327
|
+
for (const processor of processors) css = await processor.transformCSS?.(css) || css;
|
|
328
|
+
return css;
|
|
329
|
+
},
|
|
330
|
+
layer: layerName
|
|
331
|
+
}],
|
|
332
|
+
layers: { [fontLayer]: -200 }
|
|
333
|
+
};
|
|
334
|
+
if (extendTheme) preset.extendTheme = (theme, config) => {
|
|
335
|
+
const hasWind4 = config.presets.some((p) => p.name === "@unocss/preset-wind4");
|
|
336
|
+
const themeKey = options.themeKey ?? (hasWind4 ? "font" : "fontFamily");
|
|
337
|
+
if (!theme[themeKey]) theme[themeKey] = {};
|
|
338
|
+
const obj = Object.fromEntries(Object.entries(fontObject).map(([name, fonts]) => [name, fonts.map((f) => f.provider.getFontName?.(f) ?? `"${f.name}"`)]));
|
|
339
|
+
for (const key of Object.keys(obj)) if (typeof theme[themeKey][key] === "string") theme[themeKey][key] = obj[key].map((i) => `${i},`).join("") + theme[themeKey][key];
|
|
340
|
+
else theme[themeKey][key] = obj[key].join(",");
|
|
341
|
+
};
|
|
342
|
+
return preset;
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
const userAgentWoff2 = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36";
|
|
346
|
+
const defaultFetch = async (url) => (await import("./node-CsRin8Rz.mjs")).$fetch(url, {
|
|
347
|
+
headers: { "User-Agent": userAgentWoff2 },
|
|
348
|
+
retry: 3
|
|
349
|
+
});
|
|
350
|
+
/**
|
|
351
|
+
* Preset for using web fonts by provide just the names.
|
|
352
|
+
*
|
|
353
|
+
* @see https://unocss.dev/presets/web-fonts
|
|
354
|
+
*/
|
|
355
|
+
const presetWebFonts = definePreset(createWebFontPreset(defaultFetch));
|
|
356
|
+
//#endregion
|
|
357
|
+
export { presetWebFonts as default, presetWebFonts };
|