@unocss/svelte-scoped 66.2.3 → 66.3.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.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export { U as default } from './shared/svelte-scoped.
|
|
1
|
+
export { U as default } from './shared/svelte-scoped.OigInX2n.mjs';
|
|
2
2
|
import 'node:process';
|
|
3
3
|
import '@unocss/config';
|
|
4
4
|
import '@unocss/core';
|
|
5
5
|
import '@unocss/preset-uno';
|
|
6
6
|
import 'magic-string';
|
|
7
|
+
import 'acorn';
|
|
8
|
+
import 'zimmerframe';
|
|
7
9
|
import 'css-tree';
|
|
@@ -3,7 +3,9 @@ import { createRecoveryConfigLoader } from '@unocss/config';
|
|
|
3
3
|
import { expandVariantGroup, warnOnce, regexScopePlaceholder, toArray, createGenerator } from '@unocss/core';
|
|
4
4
|
import presetUno from '@unocss/preset-uno';
|
|
5
5
|
import MagicString from 'magic-string';
|
|
6
|
-
import
|
|
6
|
+
import * as acorn from 'acorn';
|
|
7
|
+
import { walk } from 'zimmerframe';
|
|
8
|
+
import { generate, parse, clone, walk as walk$1 } from 'css-tree';
|
|
7
9
|
|
|
8
10
|
const notInCommentRE = /(?<!<!--\s*)/;
|
|
9
11
|
const stylesTagWithCapturedDirectivesRE = /<style([^>]*)>[\s\S]*?<\/style\s*>/;
|
|
@@ -20,14 +22,17 @@ function addGeneratedStylesIntoStyleBlock(code, styles) {
|
|
|
20
22
|
const classesRE$1 = /class=(["'`])([\s\S]*?)\1/g;
|
|
21
23
|
const classDirectivesRE = /class:(\S+?)="?\{/g;
|
|
22
24
|
const classDirectivesShorthandRE = /class:([^=>\s/]+)[{>\s/]/g;
|
|
25
|
+
const classClsxRE = /(?<prefix>class=\{\w*)[[{(]/g;
|
|
23
26
|
function findClasses(code) {
|
|
24
27
|
const matchedClasses = [...code.matchAll(classesRE$1)];
|
|
25
28
|
const matchedClassDirectives = [...code.matchAll(classDirectivesRE)];
|
|
26
29
|
const matchedClassDirectivesShorthand = [...code.matchAll(classDirectivesShorthandRE)];
|
|
30
|
+
const matchedClassClsx = [...code.matchAll(classClsxRE)];
|
|
27
31
|
const classes = parseMatches(matchedClasses, "regular", 'class="'.length);
|
|
28
32
|
const classDirectives = parseMatches(matchedClassDirectives, "directive", "class:".length);
|
|
29
33
|
const classDirectivesShorthand = parseMatches(matchedClassDirectivesShorthand, "directiveShorthand", "class:".length);
|
|
30
|
-
|
|
34
|
+
const classClsx = parseMatchesWithAcorn(matchedClassClsx, code);
|
|
35
|
+
return [...classes, ...classDirectives, ...classDirectivesShorthand, ...classClsx];
|
|
31
36
|
}
|
|
32
37
|
function parseMatches(matches, type, prefixLength) {
|
|
33
38
|
return matches.map((match) => {
|
|
@@ -44,6 +49,71 @@ function parseMatches(matches, type, prefixLength) {
|
|
|
44
49
|
function hasBody(foundClass) {
|
|
45
50
|
return foundClass.body;
|
|
46
51
|
}
|
|
52
|
+
function parseMatchesWithAcorn(matches, code) {
|
|
53
|
+
return matches.flatMap((match) => {
|
|
54
|
+
const start = match.index + match.groups.prefix.length;
|
|
55
|
+
const ast = acorn.parseExpressionAt(code, start, {
|
|
56
|
+
sourceType: "module",
|
|
57
|
+
ecmaVersion: 16,
|
|
58
|
+
locations: true
|
|
59
|
+
});
|
|
60
|
+
const classes = [];
|
|
61
|
+
function fromProperty(body, node, property) {
|
|
62
|
+
return {
|
|
63
|
+
body,
|
|
64
|
+
start: node.start,
|
|
65
|
+
end: node.end,
|
|
66
|
+
type: property.shorthand ? "clsxObjectShorthand" : "clsxObject"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function fromString(body, node) {
|
|
70
|
+
return {
|
|
71
|
+
body,
|
|
72
|
+
start: node.start + 1,
|
|
73
|
+
end: node.end - 1,
|
|
74
|
+
type: "regular"
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
walk(
|
|
78
|
+
ast,
|
|
79
|
+
{ property: void 0 },
|
|
80
|
+
{
|
|
81
|
+
Property(node, { visit }) {
|
|
82
|
+
visit(node.key, { property: node });
|
|
83
|
+
},
|
|
84
|
+
Identifier(node, { state, next }) {
|
|
85
|
+
if (state.property) {
|
|
86
|
+
classes.push(fromProperty(node.name, node, state.property));
|
|
87
|
+
}
|
|
88
|
+
next();
|
|
89
|
+
},
|
|
90
|
+
Literal(node, { state, next }) {
|
|
91
|
+
if (typeof node.value === "string") {
|
|
92
|
+
const body = node.value;
|
|
93
|
+
if (state.property) {
|
|
94
|
+
classes.push(fromProperty(body, node, state.property));
|
|
95
|
+
} else {
|
|
96
|
+
classes.push(fromString(body, node));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
next();
|
|
100
|
+
},
|
|
101
|
+
TemplateLiteral(node, { state, next }) {
|
|
102
|
+
if (node.expressions.length === 0 && node.quasis.length === 1) {
|
|
103
|
+
const body = node.quasis[0].value.raw;
|
|
104
|
+
if (state.property) {
|
|
105
|
+
classes.push(fromProperty(body, node, state.property));
|
|
106
|
+
} else {
|
|
107
|
+
classes.push(fromString(body, node));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
next();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
return classes;
|
|
115
|
+
}).filter(hasBody);
|
|
116
|
+
}
|
|
47
117
|
|
|
48
118
|
function hash(str) {
|
|
49
119
|
let i;
|
|
@@ -161,28 +231,45 @@ async function processDirective({ body: token, start, end, type }, options, uno,
|
|
|
161
231
|
};
|
|
162
232
|
}
|
|
163
233
|
|
|
234
|
+
async function processClsx(cls, options, uno, filename) {
|
|
235
|
+
if (cls.type === "clsxObject") {
|
|
236
|
+
const { rulesToGenerate, codeUpdate } = await processClassBody({ ...cls}, options, uno, filename);
|
|
237
|
+
if (rulesToGenerate && codeUpdate) {
|
|
238
|
+
codeUpdate.content = `"${codeUpdate.content}"`;
|
|
239
|
+
return { rulesToGenerate, codeUpdate };
|
|
240
|
+
}
|
|
241
|
+
} else if (cls.type === "clsxObjectShorthand") {
|
|
242
|
+
const { rulesToGenerate, codeUpdate } = await processDirective({ ...cls, type: "directive" }, options, uno, filename) ?? {};
|
|
243
|
+
if (rulesToGenerate && codeUpdate) {
|
|
244
|
+
codeUpdate.content = `"${codeUpdate.content}": ${cls.body}`;
|
|
245
|
+
return { rulesToGenerate, codeUpdate };
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
164
250
|
async function processClasses(classes, options, uno, filename) {
|
|
165
251
|
const result = {
|
|
166
252
|
rulesToGenerate: {},
|
|
167
253
|
codeUpdates: []
|
|
168
254
|
};
|
|
169
255
|
for (const foundClass of classes) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
result.codeUpdates.push(codeUpdate);
|
|
176
|
-
} else {
|
|
177
|
-
const { rulesToGenerate, codeUpdate } = await processDirective(foundClass, options, uno, filename) || {};
|
|
178
|
-
if (rulesToGenerate)
|
|
179
|
-
Object.assign(result.rulesToGenerate, rulesToGenerate);
|
|
180
|
-
if (codeUpdate)
|
|
181
|
-
result.codeUpdates.push(codeUpdate);
|
|
182
|
-
}
|
|
256
|
+
const { rulesToGenerate, codeUpdate } = await processClass(foundClass, options, uno, filename);
|
|
257
|
+
if (rulesToGenerate)
|
|
258
|
+
Object.assign(result.rulesToGenerate, rulesToGenerate);
|
|
259
|
+
if (codeUpdate)
|
|
260
|
+
result.codeUpdates.push(codeUpdate);
|
|
183
261
|
}
|
|
184
262
|
return result;
|
|
185
263
|
}
|
|
264
|
+
async function processClass(foundClass, options, uno, filename) {
|
|
265
|
+
if (foundClass.type === "regular") {
|
|
266
|
+
return await processClassBody(foundClass, options, uno, filename);
|
|
267
|
+
}
|
|
268
|
+
if (foundClass.type === "clsxObject" || foundClass.type === "clsxObjectShorthand") {
|
|
269
|
+
return await processClsx(foundClass, options, uno, filename) ?? {};
|
|
270
|
+
}
|
|
271
|
+
return await processDirective(foundClass, options, uno, filename) ?? {};
|
|
272
|
+
}
|
|
186
273
|
|
|
187
274
|
const NOT_PRECEDED_BY_DIGIT_OR_OPEN_PARENTHESIS_RE = /(?<![\d(])/;
|
|
188
275
|
const SELECTOR_STARTING_WITH_BRACKET_OR_PERIOD_RE = /([[.][\s\S]+?)/;
|
|
@@ -335,7 +422,7 @@ async function transformApply(ctx) {
|
|
|
335
422
|
if (ast.type !== "StyleSheet")
|
|
336
423
|
return ctx.s;
|
|
337
424
|
const stack = [];
|
|
338
|
-
walk(ast, (node) => {
|
|
425
|
+
walk$1(ast, (node) => {
|
|
339
426
|
if (node.type === "Rule")
|
|
340
427
|
stack.push(handleApply(ctx, node));
|
|
341
428
|
});
|
package/dist/vite.mjs
CHANGED
|
@@ -7,7 +7,9 @@ import MagicString from 'magic-string';
|
|
|
7
7
|
import { readFileSync, existsSync, statSync } from 'node:fs';
|
|
8
8
|
import { resolve, dirname } from 'node:path';
|
|
9
9
|
import { fileURLToPath } from 'node:url';
|
|
10
|
-
import { U as UnocssSveltePreprocess } from './shared/svelte-scoped.
|
|
10
|
+
import { U as UnocssSveltePreprocess } from './shared/svelte-scoped.OigInX2n.mjs';
|
|
11
|
+
import 'acorn';
|
|
12
|
+
import 'zimmerframe';
|
|
11
13
|
import 'css-tree';
|
|
12
14
|
|
|
13
15
|
function ConfigHMRPlugin({ ready }) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/svelte-scoped",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "66.
|
|
4
|
+
"version": "66.3.1",
|
|
5
5
|
"description": "Use UnoCSS in a modular fashion with styles being stored only in the Svelte component they are used in: Vite plugin for apps, Svelte preprocessor for component libraries",
|
|
6
6
|
"author": "Jacob Bowdoin",
|
|
7
7
|
"license": "MIT",
|
|
@@ -50,15 +50,17 @@
|
|
|
50
50
|
"dist"
|
|
51
51
|
],
|
|
52
52
|
"dependencies": {
|
|
53
|
+
"acorn": "^8.15.0",
|
|
53
54
|
"css-tree": "^3.1.0",
|
|
54
55
|
"magic-string": "^0.30.17",
|
|
55
|
-
"
|
|
56
|
-
"@unocss/
|
|
57
|
-
"@unocss/reset": "66.
|
|
56
|
+
"zimmerframe": "^1.1.2",
|
|
57
|
+
"@unocss/config": "66.3.1",
|
|
58
|
+
"@unocss/reset": "66.3.1",
|
|
59
|
+
"@unocss/preset-uno": "66.3.1"
|
|
58
60
|
},
|
|
59
61
|
"devDependencies": {
|
|
60
62
|
"prettier-plugin-svelte": "^2.10.1",
|
|
61
|
-
"svelte": "^5.34.
|
|
63
|
+
"svelte": "^5.34.7"
|
|
62
64
|
},
|
|
63
65
|
"scripts": {
|
|
64
66
|
"build": "unbuild",
|