@unocss/svelte-scoped 66.6.8 → 66.7.0-beta.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/{preprocess-BolxGJ9J.d.mts → preprocess-BlFuH8z9.d.mts} +11 -14
- package/dist/preprocess.d.mts +2 -2
- package/dist/preprocess.mjs +101 -1
- package/dist/{preprocess-CZVi4cj2.mjs → transformStyle-NRa-cUil.mjs} +28 -134
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +2239 -51
- package/package.json +14 -9
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { UnoGenerator, UserConfig } from "@unocss/core";
|
|
1
|
+
import { UnocssPluginContext } from "@unocss/core";
|
|
3
2
|
import { PreprocessorGroup } from "svelte/types/compiler/preprocess";
|
|
4
3
|
|
|
5
|
-
//#region src/
|
|
6
|
-
interface UnocssSveltePreprocessOptions extends TransformClassesOptions, TransformApplyOptions, TransformDirectivesOptions {
|
|
7
|
-
/**
|
|
8
|
-
* UnoCSS config or path to config file. If not provided, will load unocss.config.ts/js. It's recommended to use the separate config file if you are having trouble with the UnoCSS extension in VSCode.
|
|
9
|
-
*/
|
|
10
|
-
configOrPath?: UserConfig | string;
|
|
11
|
-
}
|
|
4
|
+
//#region src/types.d.ts
|
|
12
5
|
interface TransformClassesOptions {
|
|
13
6
|
/**
|
|
14
7
|
* Prefix for compiled class names. Distinct between `@unocss/svelte-scoped/vite` and `@unocss/svelte-scoped/preprocessor` to avoid bugs when using a component library built with `@unocss/svelte-scoped/preprocessor` in a project using `@unocss/svelte-scoped/vite`.
|
|
@@ -55,12 +48,16 @@ interface TransformDirectivesOptions {
|
|
|
55
48
|
*/
|
|
56
49
|
transformThemeDirective?: boolean;
|
|
57
50
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/_preprocess/types.d.ts
|
|
53
|
+
interface UnocssSveltePreprocessOptions extends TransformClassesOptions, TransformApplyOptions, TransformDirectivesOptions {
|
|
54
|
+
/**
|
|
55
|
+
* UnoCSS config or path to config file. If not provided, will load unocss.config.ts/js. It's recommended to use the separate config file if you are having trouble with the UnoCSS extension in VSCode.
|
|
56
|
+
*/
|
|
57
|
+
configOrPath?: UserConfig | string;
|
|
61
58
|
}
|
|
62
59
|
//#endregion
|
|
63
60
|
//#region src/_preprocess/index.d.ts
|
|
64
|
-
declare function UnocssSveltePreprocess(options?: UnocssSveltePreprocessOptions, unoContextFromVite?:
|
|
61
|
+
declare function UnocssSveltePreprocess(options?: UnocssSveltePreprocessOptions, unoContextFromVite?: Pick<UnocssPluginContext, 'ready' | 'uno'>, isViteBuild?: () => boolean): PreprocessorGroup;
|
|
65
62
|
//#endregion
|
|
66
|
-
export { TransformDirectivesOptions as a, TransformClassesOptions as i,
|
|
63
|
+
export { TransformDirectivesOptions as a, TransformClassesOptions as i, UnocssSveltePreprocessOptions as n, TransformApplyOptions as r, UnocssSveltePreprocess as t };
|
package/dist/preprocess.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as TransformDirectivesOptions, i as TransformClassesOptions, n as
|
|
2
|
-
export {
|
|
1
|
+
import { a as TransformDirectivesOptions, i as TransformClassesOptions, n as UnocssSveltePreprocessOptions, r as TransformApplyOptions, t as UnocssSveltePreprocess } from "./preprocess-BlFuH8z9.mjs";
|
|
2
|
+
export { type TransformApplyOptions, type TransformClassesOptions, type TransformDirectivesOptions, type UnocssSveltePreprocessOptions, UnocssSveltePreprocess as default };
|
package/dist/preprocess.mjs
CHANGED
|
@@ -1,2 +1,102 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { i as transformClasses, n as transformStyle, r as themeRE, t as checkForApply } from "./transformStyle-NRa-cUil.mjs";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { createRecoveryConfigLoader } from "@unocss/config";
|
|
4
|
+
import { createGenerator, warnOnce } from "@unocss/core";
|
|
5
|
+
import presetWind3 from "@unocss/preset-wind3";
|
|
6
|
+
import MagicString from "magic-string";
|
|
7
|
+
//#region src/_preprocess/addGeneratedStyles.ts
|
|
8
|
+
const actualStylesTagWithCapturedDirectivesRE = new RegExp(/(?<!<!--\s*)/.source + /<style([^>]*)>[\s\S]*?<\/style\s*>/.source, "g");
|
|
9
|
+
const captureOpeningStyleTagWithAttributesRE = /(<style[^>]*>)/;
|
|
10
|
+
function addGeneratedStylesIntoStyleBlock(s, styles) {
|
|
11
|
+
if (s.original.match(actualStylesTagWithCapturedDirectivesRE)) s.replace(captureOpeningStyleTagWithAttributesRE, `$1${styles}`);
|
|
12
|
+
else s.append(`\n<style>${styles}</style>`);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/_preprocess/wrapGlobal.ts
|
|
16
|
+
const EXTRACT_SELECTOR_RE = new RegExp(/(?<![\d(])/.source + /([[.][\s\S]+?)/.source + /(\{[\s\S]+?\})/.source, "g");
|
|
17
|
+
function wrapSelectorsWithGlobal(css) {
|
|
18
|
+
return css.replace(EXTRACT_SELECTOR_RE, ":global($1)$2");
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/_preprocess/index.ts
|
|
22
|
+
function UnocssSveltePreprocess(options = {}, unoContextFromVite, isViteBuild) {
|
|
23
|
+
if (!options.classPrefix) options.classPrefix = "usp-";
|
|
24
|
+
let uno;
|
|
25
|
+
const makeGenerator = async () => {
|
|
26
|
+
if (unoContextFromVite) {
|
|
27
|
+
await unoContextFromVite.ready;
|
|
28
|
+
return unoContextFromVite.uno;
|
|
29
|
+
}
|
|
30
|
+
const defaults = { presets: [presetWind3()] };
|
|
31
|
+
return await createGenerator((await createRecoveryConfigLoader()(process.cwd(), options.configOrPath)).config, defaults);
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
markup: async ({ content, filename }) => {
|
|
35
|
+
uno ??= await makeGenerator();
|
|
36
|
+
if (isViteBuild && options.combine === void 0) options.combine = isViteBuild();
|
|
37
|
+
const s = new MagicString(content);
|
|
38
|
+
const transformed = await transformClasses({
|
|
39
|
+
s,
|
|
40
|
+
filename: filename ?? "",
|
|
41
|
+
uno,
|
|
42
|
+
options,
|
|
43
|
+
removeCommentsToMakeGlobalWrappingEasy: true
|
|
44
|
+
});
|
|
45
|
+
if (!transformed) return;
|
|
46
|
+
addGeneratedStylesIntoStyleBlock(s, wrapSelectorsWithGlobal(transformed.generatedStyles));
|
|
47
|
+
if (s.hasChanged()) return {
|
|
48
|
+
code: s.toString(),
|
|
49
|
+
map: s.generateMap({
|
|
50
|
+
hires: true,
|
|
51
|
+
source: filename ?? ""
|
|
52
|
+
})
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
style: async ({ content, attributes, filename }) => {
|
|
56
|
+
const svelte3AddPreflights = attributes["uno:preflights"];
|
|
57
|
+
const svelte3AddSafelist = attributes["uno:safelist"];
|
|
58
|
+
const svelte4DeprecatedAddPreflights = attributes.uno && attributes.preflights;
|
|
59
|
+
const svelte4DeprecatedAddSafelist = attributes.uno && attributes.safelist;
|
|
60
|
+
let addPreflights = attributes["uno-preflights"] || svelte3AddPreflights || svelte4DeprecatedAddPreflights;
|
|
61
|
+
let addSafelist = attributes["uno-safelist"] || svelte3AddSafelist || svelte4DeprecatedAddSafelist;
|
|
62
|
+
if (unoContextFromVite && (addPreflights || addSafelist)) {
|
|
63
|
+
addPreflights = false;
|
|
64
|
+
addSafelist = false;
|
|
65
|
+
warnOnce("Notice for those transitioning to @unocss/svelte-scoped/vite: uno-preflights and uno-safelist are only for use in component libraries. Please see the documentation for how to add preflights and safelist into your head tag. If you are consuming a component library built by @unocss/svelte-scoped/preprocess, you can ignore this upgrade notice.");
|
|
66
|
+
}
|
|
67
|
+
const { hasApply, applyVariables } = checkForApply(content, options.applyVariables);
|
|
68
|
+
const hasThemeFn = options.transformThemeDirective === false ? false : !!content.match(themeRE);
|
|
69
|
+
if (!(addPreflights || addSafelist || hasApply || hasThemeFn)) return;
|
|
70
|
+
uno ??= await makeGenerator();
|
|
71
|
+
let preflightsSafelistCss = "";
|
|
72
|
+
if (addPreflights || addSafelist) {
|
|
73
|
+
const { css } = await uno.generate([], {
|
|
74
|
+
preflights: !!addPreflights,
|
|
75
|
+
safelist: !!addSafelist,
|
|
76
|
+
minify: true
|
|
77
|
+
});
|
|
78
|
+
preflightsSafelistCss = wrapSelectorsWithGlobal(css);
|
|
79
|
+
}
|
|
80
|
+
if (hasApply || hasThemeFn) {
|
|
81
|
+
const s = new MagicString(content);
|
|
82
|
+
await transformStyle({
|
|
83
|
+
s,
|
|
84
|
+
uno,
|
|
85
|
+
prepend: preflightsSafelistCss,
|
|
86
|
+
applyVariables,
|
|
87
|
+
transformThemeFn: hasThemeFn
|
|
88
|
+
});
|
|
89
|
+
if (s.hasChanged()) return {
|
|
90
|
+
code: s.toString(),
|
|
91
|
+
map: s.generateMap({
|
|
92
|
+
hires: true,
|
|
93
|
+
source: filename ?? ""
|
|
94
|
+
})
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (preflightsSafelistCss) return { code: preflightsSafelistCss + content };
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
2
102
|
export { UnocssSveltePreprocess as default };
|
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createRecoveryConfigLoader } from "@unocss/config";
|
|
3
|
-
import { createGenerator, expandVariantGroup, regexScopePlaceholder, toArray, warnOnce } from "@unocss/core";
|
|
4
|
-
import presetWind3 from "@unocss/preset-wind3";
|
|
5
|
-
import MagicString from "magic-string";
|
|
1
|
+
import { expandVariantGroup, regexScopePlaceholder, toArray, warnOnce } from "@unocss/core";
|
|
6
2
|
import * as acorn from "acorn";
|
|
7
3
|
import { walk } from "zimmerframe";
|
|
8
4
|
import { clone, generate, parse, walk as walk$1 } from "css-tree";
|
|
9
|
-
//#region src/
|
|
10
|
-
const actualStylesTagWithCapturedDirectivesRE = new RegExp(/(?<!<!--\s*)/.source + /<style([^>]*)>[\s\S]*?<\/style\s*>/.source, "g");
|
|
11
|
-
const captureOpeningStyleTagWithAttributesRE = /(<style[^>]*>)/;
|
|
12
|
-
function addGeneratedStylesIntoStyleBlock(code, styles) {
|
|
13
|
-
if (code.match(actualStylesTagWithCapturedDirectivesRE)) return code.replace(captureOpeningStyleTagWithAttributesRE, `$1${styles}`);
|
|
14
|
-
return `${code}\n<style>${styles}</style>`;
|
|
15
|
-
}
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region src/_preprocess/transformClasses/findClasses.ts
|
|
5
|
+
//#region src/_common/transformClasses/findClasses.ts
|
|
18
6
|
const classesRE$1 = /class=(["'`])([\s\S]*?)\1/g;
|
|
19
7
|
const classDirectivesRE = /class:(\S+?)="?\{/g;
|
|
20
8
|
const classDirectivesShorthandRE = /class:([^=>\s/]+)[{>\s/]/g;
|
|
@@ -104,7 +92,7 @@ function parseMatchesWithAcorn(matches, code) {
|
|
|
104
92
|
}).filter(hasBody);
|
|
105
93
|
}
|
|
106
94
|
//#endregion
|
|
107
|
-
//#region src/
|
|
95
|
+
//#region src/_common/transformClasses/hash.ts
|
|
108
96
|
function hash(str) {
|
|
109
97
|
let i;
|
|
110
98
|
let l;
|
|
@@ -116,25 +104,25 @@ function hash(str) {
|
|
|
116
104
|
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
117
105
|
}
|
|
118
106
|
//#endregion
|
|
119
|
-
//#region src/
|
|
107
|
+
//#region src/_common/transformClasses/generateClassName.ts
|
|
120
108
|
function generateClassName(body, options, filename) {
|
|
121
109
|
const { classPrefix = "uno-", combine = true, hashFn = hash } = options;
|
|
122
110
|
if (combine) return `${classPrefix}${hashFn(body + filename)}`;
|
|
123
111
|
else return `_${body}_${hashFn(filename)}`;
|
|
124
112
|
}
|
|
125
113
|
//#endregion
|
|
126
|
-
//#region src/
|
|
114
|
+
//#region src/_common/transformClasses/isShortcut.ts
|
|
127
115
|
function isShortcut(token, shortcuts) {
|
|
128
116
|
return shortcuts.some((s) => s[0] === token);
|
|
129
117
|
}
|
|
130
118
|
//#endregion
|
|
131
|
-
//#region src/
|
|
119
|
+
//#region src/_common/transformClasses/needsGenerated.ts
|
|
132
120
|
async function needsGenerated(token, uno) {
|
|
133
121
|
if (uno.config.safelist.includes(token)) return false;
|
|
134
122
|
return !!await uno.parseToken(token);
|
|
135
123
|
}
|
|
136
124
|
//#endregion
|
|
137
|
-
//#region src/
|
|
125
|
+
//#region src/_common/transformClasses/sortClassesIntoCategories.ts
|
|
138
126
|
async function sortClassesIntoCategories(body, options, uno, filename) {
|
|
139
127
|
const { combine = true, hashSafelistClasses = false } = options;
|
|
140
128
|
const rulesToGenerate = {};
|
|
@@ -166,7 +154,7 @@ async function sortClassesIntoCategories(body, options, uno, filename) {
|
|
|
166
154
|
};
|
|
167
155
|
}
|
|
168
156
|
//#endregion
|
|
169
|
-
//#region src/
|
|
157
|
+
//#region src/_common/transformClasses/processExpressions.ts
|
|
170
158
|
const expressionsRE = /\S*\{[^{}]+\}\S*/g;
|
|
171
159
|
const classesRE = /(?<=\?\s*|:\s*)(["'`])([\s\S]*?)\1/g;
|
|
172
160
|
async function processExpressions(body, options, uno, filename) {
|
|
@@ -192,7 +180,7 @@ async function processExpressions(body, options, uno, filename) {
|
|
|
192
180
|
};
|
|
193
181
|
}
|
|
194
182
|
//#endregion
|
|
195
|
-
//#region src/
|
|
183
|
+
//#region src/_common/transformClasses/processClassBody.ts
|
|
196
184
|
async function processClassBody({ body, start, end }, options, uno, filename) {
|
|
197
185
|
const { rulesToGenerate: rulesFromExpressions, restOfBody, updatedExpressions } = await processExpressions(expandVariantGroup(body), options, uno, filename);
|
|
198
186
|
const { rulesToGenerate: rulesFromRegularClasses, ignore } = await sortClassesIntoCategories(restOfBody, options, uno, filename);
|
|
@@ -211,7 +199,7 @@ async function processClassBody({ body, start, end }, options, uno, filename) {
|
|
|
211
199
|
};
|
|
212
200
|
}
|
|
213
201
|
//#endregion
|
|
214
|
-
//#region src/
|
|
202
|
+
//#region src/_common/transformClasses/processDirective.ts
|
|
215
203
|
async function processDirective({ body: token, start, end, type }, options, uno, filename) {
|
|
216
204
|
if (!(isShortcut(token, uno.config.shortcuts) || await needsGenerated(token, uno))) return;
|
|
217
205
|
const generatedClassName = generateClassName(token, options, filename);
|
|
@@ -226,7 +214,7 @@ async function processDirective({ body: token, start, end, type }, options, uno,
|
|
|
226
214
|
};
|
|
227
215
|
}
|
|
228
216
|
//#endregion
|
|
229
|
-
//#region src/
|
|
217
|
+
//#region src/_common/transformClasses/processClsx.ts
|
|
230
218
|
async function processClsx(cls, options, uno, filename) {
|
|
231
219
|
if (cls.type === "clsxObject") {
|
|
232
220
|
const { rulesToGenerate, codeUpdate } = await processClassBody({
|
|
@@ -255,7 +243,7 @@ async function processClsx(cls, options, uno, filename) {
|
|
|
255
243
|
}
|
|
256
244
|
}
|
|
257
245
|
//#endregion
|
|
258
|
-
//#region src/
|
|
246
|
+
//#region src/_common/transformClasses/processClasses.ts
|
|
259
247
|
async function processClasses(classes, options, uno, filename) {
|
|
260
248
|
const result = {
|
|
261
249
|
rulesToGenerate: {},
|
|
@@ -274,53 +262,28 @@ async function processClass(foundClass, options, uno, filename) {
|
|
|
274
262
|
return await processDirective(foundClass, options, uno, filename) ?? {};
|
|
275
263
|
}
|
|
276
264
|
//#endregion
|
|
277
|
-
//#region src/
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
return css.replace(EXTRACT_SELECTOR_RE, ":global($1)$2");
|
|
281
|
-
}
|
|
282
|
-
//#endregion
|
|
283
|
-
//#region src/_preprocess/transformClasses/index.ts
|
|
284
|
-
async function transformClasses({ content, filename, uno, options }) {
|
|
285
|
-
const classesToProcess = findClasses(content);
|
|
265
|
+
//#region src/_common/transformClasses/index.ts
|
|
266
|
+
async function transformClasses({ s, filename, uno, options, removeCommentsToMakeGlobalWrappingEasy }) {
|
|
267
|
+
const classesToProcess = findClasses(s.original);
|
|
286
268
|
if (!classesToProcess.length) return;
|
|
287
269
|
const { rulesToGenerate, codeUpdates } = await processClasses(classesToProcess, options, uno, filename);
|
|
288
270
|
if (!Object.keys(rulesToGenerate).length) return;
|
|
289
|
-
const {
|
|
290
|
-
return {
|
|
291
|
-
code: addGeneratedStylesIntoStyleBlock(code, await generateStyles(rulesToGenerate, uno)),
|
|
292
|
-
map
|
|
293
|
-
};
|
|
271
|
+
if (codeUpdates.length) for (const { start, end, content } of codeUpdates) s.overwrite(start, end, content);
|
|
272
|
+
return { generatedStyles: await generateStyles(rulesToGenerate, uno, removeCommentsToMakeGlobalWrappingEasy) };
|
|
294
273
|
}
|
|
295
|
-
function
|
|
296
|
-
if (!codeUpdates.length) return {
|
|
297
|
-
code: source,
|
|
298
|
-
map: void 0
|
|
299
|
-
};
|
|
300
|
-
const s = new MagicString(source);
|
|
301
|
-
for (const { start, end, content } of codeUpdates) s.overwrite(start, end, content);
|
|
302
|
-
return {
|
|
303
|
-
code: s.toString(),
|
|
304
|
-
map: s.generateMap({
|
|
305
|
-
hires: true,
|
|
306
|
-
source: filename
|
|
307
|
-
})
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
const REMOVE_COMMENTS_TO_MAKE_GLOBAL_WRAPPING_EASY = true;
|
|
311
|
-
async function generateStyles(rulesToGenerate, uno) {
|
|
274
|
+
async function generateStyles(rulesToGenerate, uno, minify) {
|
|
312
275
|
const shortcutsForThisComponent = Object.entries(rulesToGenerate);
|
|
313
276
|
uno.config.shortcuts.push(...shortcutsForThisComponent);
|
|
314
277
|
const selectorsToGenerate = Object.keys(rulesToGenerate);
|
|
315
278
|
const { css } = await uno.generate(selectorsToGenerate, {
|
|
316
279
|
preflights: false,
|
|
317
280
|
safelist: false,
|
|
318
|
-
minify
|
|
281
|
+
minify
|
|
319
282
|
});
|
|
320
|
-
return
|
|
283
|
+
return css;
|
|
321
284
|
}
|
|
322
285
|
//#endregion
|
|
323
|
-
//#region src/
|
|
286
|
+
//#region src/_common/transformApply/getUtils.ts
|
|
324
287
|
async function getUtils(body, uno) {
|
|
325
288
|
return (await parseUtils(expandVariantGroup(body).split(/\s+/g).map((className) => className.trim().replace(/\\/, "")), uno)).sort(([aIndex], [bIndex]) => aIndex - bIndex).sort(([, , , aParent], [, , , bParent]) => (aParent ? uno.parentOrders.get(aParent) ?? 0 : 0) - (bParent ? uno.parentOrders.get(bParent) ?? 0 : 0)).reduce((acc, item) => {
|
|
326
289
|
const [, selector, body, parent] = item;
|
|
@@ -340,13 +303,13 @@ async function parseUtils(classNames, uno) {
|
|
|
340
303
|
return foundUtils.flat();
|
|
341
304
|
}
|
|
342
305
|
//#endregion
|
|
343
|
-
//#region src/
|
|
306
|
+
//#region src/_common/transformApply/removeOuterQuotes.ts
|
|
344
307
|
function removeOuterQuotes(input) {
|
|
345
308
|
if (!input) return "";
|
|
346
309
|
return /^(['"]).*\1$/.test(input) ? input.slice(1, -1) : input;
|
|
347
310
|
}
|
|
348
311
|
//#endregion
|
|
349
|
-
//#region src/
|
|
312
|
+
//#region src/_common/transformApply/writeUtilStyles.ts
|
|
350
313
|
function writeUtilStyles([, selector, body, parent], s, node, childNode) {
|
|
351
314
|
if (!selector) return;
|
|
352
315
|
const selectorChanged = selector !== ".\\-";
|
|
@@ -398,7 +361,7 @@ function findFirstCombinatorIndex(input) {
|
|
|
398
361
|
return -1;
|
|
399
362
|
}
|
|
400
363
|
//#endregion
|
|
401
|
-
//#region src/
|
|
364
|
+
//#region src/_common/transformApply/index.ts
|
|
402
365
|
async function transformApply(ctx) {
|
|
403
366
|
const ast = parse(ctx.s.original, {
|
|
404
367
|
parseAtrulePrelude: false,
|
|
@@ -434,7 +397,7 @@ function getChildNodeValue(childNode, applyVariables) {
|
|
|
434
397
|
if (childNode.type === "Declaration" && applyVariables.includes(childNode.property) && childNode.value.type === "Raw") return removeOuterQuotes(childNode.value.value.trim());
|
|
435
398
|
}
|
|
436
399
|
//#endregion
|
|
437
|
-
//#region src/
|
|
400
|
+
//#region src/_common/transformTheme.ts
|
|
438
401
|
const themeRE = /theme\((.+?)\)/g;
|
|
439
402
|
function transformTheme(s, theme) {
|
|
440
403
|
return s.replace(themeRE, (_, match) => {
|
|
@@ -449,7 +412,7 @@ function getThemeValue(rawArguments, theme) {
|
|
|
449
412
|
return current;
|
|
450
413
|
}
|
|
451
414
|
//#endregion
|
|
452
|
-
//#region src/
|
|
415
|
+
//#region src/_common/transformStyle.ts
|
|
453
416
|
const DEFAULT_APPLY_VARIABLES = ["--at-apply"];
|
|
454
417
|
function checkForApply(content, _applyVariables) {
|
|
455
418
|
if (_applyVariables === false) return {
|
|
@@ -462,8 +425,7 @@ function checkForApply(content, _applyVariables) {
|
|
|
462
425
|
applyVariables
|
|
463
426
|
};
|
|
464
427
|
}
|
|
465
|
-
async function transformStyle({
|
|
466
|
-
const s = new MagicString(content);
|
|
428
|
+
async function transformStyle({ s, uno, prepend, applyVariables, transformThemeFn }) {
|
|
467
429
|
if (applyVariables?.length) await transformApply({
|
|
468
430
|
s,
|
|
469
431
|
uno,
|
|
@@ -472,74 +434,6 @@ async function transformStyle({ content, uno, prepend, filename, applyVariables,
|
|
|
472
434
|
if (transformThemeFn) transformTheme(s, uno.config.theme);
|
|
473
435
|
if (!s.hasChanged()) return;
|
|
474
436
|
if (prepend) s.prepend(prepend);
|
|
475
|
-
return {
|
|
476
|
-
code: s.toString(),
|
|
477
|
-
map: s.generateMap({
|
|
478
|
-
hires: true,
|
|
479
|
-
source: filename || ""
|
|
480
|
-
})
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
//#endregion
|
|
484
|
-
//#region src/_preprocess/index.ts
|
|
485
|
-
function UnocssSveltePreprocess(options = {}, unoContextFromVite, isViteBuild) {
|
|
486
|
-
if (!options.classPrefix) options.classPrefix = "usp-";
|
|
487
|
-
let uno;
|
|
488
|
-
const makeGenerator = async () => {
|
|
489
|
-
if (unoContextFromVite) {
|
|
490
|
-
await unoContextFromVite.ready;
|
|
491
|
-
return unoContextFromVite.uno;
|
|
492
|
-
}
|
|
493
|
-
const defaults = { presets: [presetWind3()] };
|
|
494
|
-
return await createGenerator((await createRecoveryConfigLoader()(process.cwd(), options.configOrPath)).config, defaults);
|
|
495
|
-
};
|
|
496
|
-
return {
|
|
497
|
-
markup: async ({ content, filename }) => {
|
|
498
|
-
uno ??= await makeGenerator();
|
|
499
|
-
if (isViteBuild && options.combine === void 0) options.combine = isViteBuild();
|
|
500
|
-
return await transformClasses({
|
|
501
|
-
content,
|
|
502
|
-
filename: filename || "",
|
|
503
|
-
uno,
|
|
504
|
-
options
|
|
505
|
-
});
|
|
506
|
-
},
|
|
507
|
-
style: async ({ content, attributes, filename }) => {
|
|
508
|
-
const svelte3AddPreflights = attributes["uno:preflights"];
|
|
509
|
-
const svelte3AddSafelist = attributes["uno:safelist"];
|
|
510
|
-
const svelte4DeprecatedAddPreflights = attributes.uno && attributes.preflights;
|
|
511
|
-
const svelte4DeprecatedAddSafelist = attributes.uno && attributes.safelist;
|
|
512
|
-
let addPreflights = attributes["uno-preflights"] || svelte3AddPreflights || svelte4DeprecatedAddPreflights;
|
|
513
|
-
let addSafelist = attributes["uno-safelist"] || svelte3AddSafelist || svelte4DeprecatedAddSafelist;
|
|
514
|
-
if (unoContextFromVite && (addPreflights || addSafelist)) {
|
|
515
|
-
addPreflights = false;
|
|
516
|
-
addSafelist = false;
|
|
517
|
-
warnOnce("Notice for those transitioning to @unocss/svelte-scoped/vite: uno-preflights and uno-safelist are only for use in component libraries. Please see the documentation for how to add preflights and safelist into your head tag. If you are consuming a component library built by @unocss/svelte-scoped/preprocess, you can ignore this upgrade notice.");
|
|
518
|
-
}
|
|
519
|
-
const { hasApply, applyVariables } = checkForApply(content, options.applyVariables);
|
|
520
|
-
const hasThemeFn = options.transformThemeDirective === false ? false : !!content.match(themeRE);
|
|
521
|
-
if (!(addPreflights || addSafelist || hasApply || hasThemeFn)) return;
|
|
522
|
-
uno ??= await makeGenerator();
|
|
523
|
-
let preflightsSafelistCss = "";
|
|
524
|
-
if (addPreflights || addSafelist) {
|
|
525
|
-
const { css } = await uno.generate([], {
|
|
526
|
-
preflights: !!addPreflights,
|
|
527
|
-
safelist: !!addSafelist,
|
|
528
|
-
minify: true
|
|
529
|
-
});
|
|
530
|
-
preflightsSafelistCss = wrapSelectorsWithGlobal(css);
|
|
531
|
-
}
|
|
532
|
-
if (hasApply || hasThemeFn) return await transformStyle({
|
|
533
|
-
content,
|
|
534
|
-
uno,
|
|
535
|
-
filename,
|
|
536
|
-
prepend: preflightsSafelistCss,
|
|
537
|
-
applyVariables,
|
|
538
|
-
transformThemeFn: hasThemeFn
|
|
539
|
-
});
|
|
540
|
-
if (preflightsSafelistCss) return { code: preflightsSafelistCss + content };
|
|
541
|
-
}
|
|
542
|
-
};
|
|
543
437
|
}
|
|
544
438
|
//#endregion
|
|
545
|
-
export {
|
|
439
|
+
export { transformClasses as i, transformStyle as n, themeRE as r, checkForApply as t };
|
package/dist/vite.d.mts
CHANGED