css-typed-vars 0.13.1 → 0.14.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/README.md +6 -6
- package/dist/{chunk-3QCGO2EN.js → chunk-7J7UZYHB.js} +1 -1
- package/dist/{chunk-L2T4LBKN.js → chunk-BPZRXE6W.js} +105 -15
- package/dist/{chunk-DIGUOQES.js → chunk-VWEQJVXA.js} +1 -1
- package/dist/cli.cjs +109 -14
- package/dist/cli.js +8 -3
- package/dist/esbuild.cjs +103 -13
- package/dist/esbuild.d.cts +1 -1
- package/dist/esbuild.d.ts +1 -1
- package/dist/esbuild.js +2 -2
- package/dist/{generator-BokM5zux.d.ts → generator-TJNk6ET_.d.cts} +5 -0
- package/dist/{generator-BokM5zux.d.cts → generator-TJNk6ET_.d.ts} +5 -0
- package/dist/index.cjs +97 -12
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/rollup.cjs +103 -13
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.d.ts +1 -1
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +103 -13
- package/dist/unplugin.d.cts +1 -1
- package/dist/unplugin.d.ts +1 -1
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +103 -13
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +103 -13
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
package/dist/esbuild.cjs
CHANGED
|
@@ -183,7 +183,18 @@ function extractValue(text, start) {
|
|
|
183
183
|
else if (char === open[open.length - 1]) open.pop();
|
|
184
184
|
else if (char === "}" || char === ";" && open.length === 0) break;
|
|
185
185
|
}
|
|
186
|
-
return text.slice(start, i).trim();
|
|
186
|
+
return joinLines(text.slice(start, i).trim());
|
|
187
|
+
}
|
|
188
|
+
function joinLines(value) {
|
|
189
|
+
if (!/[\n\r]/.test(value)) return value;
|
|
190
|
+
const masked = maskQuotedContent(value);
|
|
191
|
+
let result = "";
|
|
192
|
+
let last = 0;
|
|
193
|
+
for (const match of masked.matchAll(/\s*[\n\r]\s*/g)) {
|
|
194
|
+
result += value.slice(last, match.index) + " ";
|
|
195
|
+
last = match.index + match[0].length;
|
|
196
|
+
}
|
|
197
|
+
return result + value.slice(last);
|
|
187
198
|
}
|
|
188
199
|
var IMPORTANT = /\s*!\s*important$/i;
|
|
189
200
|
var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
|
|
@@ -195,6 +206,55 @@ function forEachProperty(block, onProperty, offset = 0) {
|
|
|
195
206
|
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
196
207
|
}
|
|
197
208
|
}
|
|
209
|
+
var inRanges = (ranges, position) => ranges.some(([start, end]) => position >= start && position < end);
|
|
210
|
+
function nestedRanges(block) {
|
|
211
|
+
const masked = maskQuotedContent(block);
|
|
212
|
+
const ranges = [];
|
|
213
|
+
const statement = /\s*(--[\w-]+\s*:)?/y;
|
|
214
|
+
let i = 0;
|
|
215
|
+
while (i < block.length) {
|
|
216
|
+
statement.lastIndex = i;
|
|
217
|
+
const match = statement.exec(masked);
|
|
218
|
+
i = statement.lastIndex;
|
|
219
|
+
if (match[1]) {
|
|
220
|
+
const raw = block.slice(i);
|
|
221
|
+
i += raw.length - raw.trimStart().length + extractValue(block, i).length;
|
|
222
|
+
while (i < block.length && block[i] !== ";" && block[i] !== "}") i++;
|
|
223
|
+
i++;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
for (let depth = 0; i < block.length; i++) {
|
|
227
|
+
const char = masked[i];
|
|
228
|
+
if (char === "(") depth++;
|
|
229
|
+
else if (char === ")") depth = Math.max(0, depth - 1);
|
|
230
|
+
else if (depth === 0 && (char === ";" || char === "{" || char === "}")) break;
|
|
231
|
+
}
|
|
232
|
+
if (masked[i] === "{") {
|
|
233
|
+
const body = extractBlock(block, i + 1);
|
|
234
|
+
ranges.push([i + 1, i + 1 + body.length]);
|
|
235
|
+
i += body.length + 1;
|
|
236
|
+
}
|
|
237
|
+
i++;
|
|
238
|
+
}
|
|
239
|
+
return ranges;
|
|
240
|
+
}
|
|
241
|
+
function forEachOwnProperty(block, onProperty, offset = 0) {
|
|
242
|
+
const nested = nestedRanges(block);
|
|
243
|
+
forEachProperty(block, (name, value, position) => {
|
|
244
|
+
if (!inRanges(nested, position - offset)) onProperty(name, value, position);
|
|
245
|
+
}, offset);
|
|
246
|
+
}
|
|
247
|
+
function conditionalRanges(stripped) {
|
|
248
|
+
const masked = maskQuotedContent(stripped);
|
|
249
|
+
const ranges = [];
|
|
250
|
+
const openRegex = /@(?:media|supports|container)\b[^{;]*\{/gi;
|
|
251
|
+
let match;
|
|
252
|
+
while (match = openRegex.exec(masked)) {
|
|
253
|
+
const start = match.index + match[0].length;
|
|
254
|
+
ranges.push([start, start + extractBlock(stripped, start).length]);
|
|
255
|
+
}
|
|
256
|
+
return ranges;
|
|
257
|
+
}
|
|
198
258
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
199
259
|
for (const sel of selectors) {
|
|
200
260
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -211,11 +271,27 @@ function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
|
211
271
|
}
|
|
212
272
|
var BASE_SELECTORS = [":root", "@theme"];
|
|
213
273
|
function scanDeclarations(css, selectors, onProperty, skip = [], stripped = stripComments(css)) {
|
|
274
|
+
const conditional = conditionalRanges(stripped);
|
|
214
275
|
forEachSelectorBlock(stripped, [...BASE_SELECTORS, ...selectors ?? []], (block, [bodyStart]) => {
|
|
215
|
-
|
|
216
|
-
forEachProperty(block,
|
|
276
|
+
const nested = nestedRanges(block);
|
|
277
|
+
forEachProperty(block, (name, value, position) => {
|
|
278
|
+
if (inRanges(skip, position)) return;
|
|
279
|
+
onProperty(name, value, position, inRanges(conditional, position) || inRanges(nested, position - bodyStart));
|
|
280
|
+
}, bodyStart);
|
|
217
281
|
});
|
|
218
282
|
}
|
|
283
|
+
function makeDeclarationCollector() {
|
|
284
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
285
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
286
|
+
const add = (name, value, isConditional) => {
|
|
287
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) return false;
|
|
288
|
+
declarations.set(name, value);
|
|
289
|
+
if (isConditional) conditional.add(name);
|
|
290
|
+
else conditional.delete(name);
|
|
291
|
+
return true;
|
|
292
|
+
};
|
|
293
|
+
return { declarations, conditional, add };
|
|
294
|
+
}
|
|
219
295
|
var normalizePrelude = (prelude) => prelude.replace(/\s+/g, "").toLowerCase();
|
|
220
296
|
function forEachMediaBlock(stripped, media, onBlock) {
|
|
221
297
|
const wanted = normalizePrelude(media.replace(/^@media/i, ""));
|
|
@@ -271,15 +347,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
271
347
|
for (const [themeName, themeSelector] of Object.entries(themes)) {
|
|
272
348
|
const values = /* @__PURE__ */ new Map();
|
|
273
349
|
themeValues.set(themeName, values);
|
|
274
|
-
const
|
|
350
|
+
const onProperty = (name, value, position) => {
|
|
275
351
|
values.set(name, value);
|
|
276
352
|
const doc = docAt(position);
|
|
277
353
|
if (doc) themeDocs.set(name, doc);
|
|
278
|
-
}
|
|
354
|
+
};
|
|
355
|
+
const collect = (block, offset) => forEachProperty(block, onProperty, offset);
|
|
279
356
|
const selector = themeSelector.trim();
|
|
280
357
|
if (/^@media\b/i.test(selector)) {
|
|
281
358
|
forEachMediaBlock(stripped, selector, (mediaBlock, range) => {
|
|
282
359
|
skip.push(range);
|
|
360
|
+
forEachOwnProperty(mediaBlock, onProperty, range[0]);
|
|
283
361
|
forEachSelectorBlock(mediaBlock, BASE_SELECTORS, (block, [innerStart]) => collect(block, range[0] + innerStart));
|
|
284
362
|
});
|
|
285
363
|
} else {
|
|
@@ -289,17 +367,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
289
367
|
});
|
|
290
368
|
}
|
|
291
369
|
}
|
|
292
|
-
const declarations
|
|
370
|
+
const { declarations, conditional, add } = makeDeclarationCollector();
|
|
293
371
|
const docs = /* @__PURE__ */ new Map();
|
|
294
|
-
scanDeclarations(css, selectors, (name, value, position) => {
|
|
295
|
-
|
|
372
|
+
scanDeclarations(css, selectors, (name, value, position, isConditional) => {
|
|
373
|
+
if (!add(name, value, isConditional)) return;
|
|
296
374
|
const doc = docAt(position);
|
|
297
375
|
if (doc) docs.set(name, doc);
|
|
298
376
|
}, skip, stripped);
|
|
299
377
|
for (const [name, doc] of themeDocs) {
|
|
300
378
|
if (!docs.has(name)) docs.set(name, doc);
|
|
301
379
|
}
|
|
302
|
-
return { declarations, themes: themeValues, docs };
|
|
380
|
+
return { declarations, conditional, themes: themeValues, docs };
|
|
303
381
|
}
|
|
304
382
|
var PROPERTY_DESCRIPTORS = [
|
|
305
383
|
["syntax", "syntax"],
|
|
@@ -377,9 +455,13 @@ async function findFiles(patterns, exclude) {
|
|
|
377
455
|
return [...new Set(files.reverse())].reverse();
|
|
378
456
|
}
|
|
379
457
|
function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
380
|
-
const compile = (globs) => (0, import_picomatch.default)(
|
|
381
|
-
const
|
|
382
|
-
const
|
|
458
|
+
const compile = (globs) => (0, import_picomatch.default)(globs.map((p) => p.replace(/^\.\//, "")));
|
|
459
|
+
const normalized = normalizePatterns(patterns);
|
|
460
|
+
const include = compile(normalized.filter((p) => !p.startsWith("!")));
|
|
461
|
+
const ignore = compile([
|
|
462
|
+
...exclude ? normalizePatterns(exclude) : [],
|
|
463
|
+
...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
|
|
464
|
+
]);
|
|
383
465
|
return (file) => {
|
|
384
466
|
const absolute = (0, import_node_path2.resolve)(cwd, file).replace(/\\/g, "/");
|
|
385
467
|
const fromCwd = (0, import_node_path2.relative)(cwd, absolute).replace(/\\/g, "/");
|
|
@@ -390,6 +472,7 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
|
390
472
|
function globWatchRoots(patterns, cwd = process.cwd()) {
|
|
391
473
|
const roots = /* @__PURE__ */ new Map();
|
|
392
474
|
for (const pattern of normalizePatterns(patterns)) {
|
|
475
|
+
if (pattern.startsWith("!")) continue;
|
|
393
476
|
const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
|
|
394
477
|
const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
|
|
395
478
|
const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
|
|
@@ -424,12 +507,19 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
424
507
|
})
|
|
425
508
|
);
|
|
426
509
|
const declarations = /* @__PURE__ */ new Map();
|
|
510
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
427
511
|
const properties = /* @__PURE__ */ new Map();
|
|
428
512
|
const themeValues = new Map(Object.keys(themes).map((theme) => [theme, /* @__PURE__ */ new Map()]));
|
|
429
513
|
const docs = /* @__PURE__ */ new Map();
|
|
430
514
|
for (const result of perFile) {
|
|
431
515
|
if (!result) continue;
|
|
432
|
-
for (const [name, value] of result.declarations)
|
|
516
|
+
for (const [name, value] of result.declarations) {
|
|
517
|
+
const isConditional = result.conditional.has(name);
|
|
518
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) continue;
|
|
519
|
+
declarations.set(name, value);
|
|
520
|
+
if (isConditional) conditional.add(name);
|
|
521
|
+
else conditional.delete(name);
|
|
522
|
+
}
|
|
433
523
|
for (const [name, rule] of result.properties) properties.set(name, rule);
|
|
434
524
|
for (const [name, doc] of result.docs) docs.set(name, doc);
|
|
435
525
|
for (const [theme, values] of result.themes) {
|
package/dist/esbuild.d.cts
CHANGED
package/dist/esbuild.d.ts
CHANGED
package/dist/esbuild.js
CHANGED
|
@@ -9,6 +9,11 @@ interface VarDoc {
|
|
|
9
9
|
interface ThemedDeclarations {
|
|
10
10
|
/** Base values, from `:root`/`@theme`/`selectors` blocks outside any theme block. */
|
|
11
11
|
declarations: Map<string, string>;
|
|
12
|
+
/**
|
|
13
|
+
* Names whose base value is conditional: only declared inside an
|
|
14
|
+
* `@media`/`@supports`/`@container` rule, or a rule nested in a base block.
|
|
15
|
+
*/
|
|
16
|
+
conditional: Set<string>;
|
|
12
17
|
/** Per theme name, the values declared inside that theme's blocks. */
|
|
13
18
|
themes: Map<string, Map<string, string>>;
|
|
14
19
|
/** `/** ... *\/` doc comments placed directly before a declaration — from a base block, else from a theme block. */
|
|
@@ -9,6 +9,11 @@ interface VarDoc {
|
|
|
9
9
|
interface ThemedDeclarations {
|
|
10
10
|
/** Base values, from `:root`/`@theme`/`selectors` blocks outside any theme block. */
|
|
11
11
|
declarations: Map<string, string>;
|
|
12
|
+
/**
|
|
13
|
+
* Names whose base value is conditional: only declared inside an
|
|
14
|
+
* `@media`/`@supports`/`@container` rule, or a rule nested in a base block.
|
|
15
|
+
*/
|
|
16
|
+
conditional: Set<string>;
|
|
12
17
|
/** Per theme name, the values declared inside that theme's blocks. */
|
|
13
18
|
themes: Map<string, Map<string, string>>;
|
|
14
19
|
/** `/** ... *\/` doc comments placed directly before a declaration — from a base block, else from a theme block. */
|
package/dist/index.cjs
CHANGED
|
@@ -198,7 +198,18 @@ function extractValue(text, start) {
|
|
|
198
198
|
else if (char === open[open.length - 1]) open.pop();
|
|
199
199
|
else if (char === "}" || char === ";" && open.length === 0) break;
|
|
200
200
|
}
|
|
201
|
-
return text.slice(start, i).trim();
|
|
201
|
+
return joinLines(text.slice(start, i).trim());
|
|
202
|
+
}
|
|
203
|
+
function joinLines(value) {
|
|
204
|
+
if (!/[\n\r]/.test(value)) return value;
|
|
205
|
+
const masked = maskQuotedContent(value);
|
|
206
|
+
let result = "";
|
|
207
|
+
let last = 0;
|
|
208
|
+
for (const match of masked.matchAll(/\s*[\n\r]\s*/g)) {
|
|
209
|
+
result += value.slice(last, match.index) + " ";
|
|
210
|
+
last = match.index + match[0].length;
|
|
211
|
+
}
|
|
212
|
+
return result + value.slice(last);
|
|
202
213
|
}
|
|
203
214
|
var IMPORTANT = /\s*!\s*important$/i;
|
|
204
215
|
var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
|
|
@@ -210,6 +221,55 @@ function forEachProperty(block, onProperty, offset = 0) {
|
|
|
210
221
|
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
211
222
|
}
|
|
212
223
|
}
|
|
224
|
+
var inRanges = (ranges, position) => ranges.some(([start, end]) => position >= start && position < end);
|
|
225
|
+
function nestedRanges(block) {
|
|
226
|
+
const masked = maskQuotedContent(block);
|
|
227
|
+
const ranges = [];
|
|
228
|
+
const statement = /\s*(--[\w-]+\s*:)?/y;
|
|
229
|
+
let i = 0;
|
|
230
|
+
while (i < block.length) {
|
|
231
|
+
statement.lastIndex = i;
|
|
232
|
+
const match = statement.exec(masked);
|
|
233
|
+
i = statement.lastIndex;
|
|
234
|
+
if (match[1]) {
|
|
235
|
+
const raw = block.slice(i);
|
|
236
|
+
i += raw.length - raw.trimStart().length + extractValue(block, i).length;
|
|
237
|
+
while (i < block.length && block[i] !== ";" && block[i] !== "}") i++;
|
|
238
|
+
i++;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
for (let depth = 0; i < block.length; i++) {
|
|
242
|
+
const char = masked[i];
|
|
243
|
+
if (char === "(") depth++;
|
|
244
|
+
else if (char === ")") depth = Math.max(0, depth - 1);
|
|
245
|
+
else if (depth === 0 && (char === ";" || char === "{" || char === "}")) break;
|
|
246
|
+
}
|
|
247
|
+
if (masked[i] === "{") {
|
|
248
|
+
const body = extractBlock(block, i + 1);
|
|
249
|
+
ranges.push([i + 1, i + 1 + body.length]);
|
|
250
|
+
i += body.length + 1;
|
|
251
|
+
}
|
|
252
|
+
i++;
|
|
253
|
+
}
|
|
254
|
+
return ranges;
|
|
255
|
+
}
|
|
256
|
+
function forEachOwnProperty(block, onProperty, offset = 0) {
|
|
257
|
+
const nested = nestedRanges(block);
|
|
258
|
+
forEachProperty(block, (name, value, position) => {
|
|
259
|
+
if (!inRanges(nested, position - offset)) onProperty(name, value, position);
|
|
260
|
+
}, offset);
|
|
261
|
+
}
|
|
262
|
+
function conditionalRanges(stripped) {
|
|
263
|
+
const masked = maskQuotedContent(stripped);
|
|
264
|
+
const ranges = [];
|
|
265
|
+
const openRegex = /@(?:media|supports|container)\b[^{;]*\{/gi;
|
|
266
|
+
let match;
|
|
267
|
+
while (match = openRegex.exec(masked)) {
|
|
268
|
+
const start = match.index + match[0].length;
|
|
269
|
+
ranges.push([start, start + extractBlock(stripped, start).length]);
|
|
270
|
+
}
|
|
271
|
+
return ranges;
|
|
272
|
+
}
|
|
213
273
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
214
274
|
for (const sel of selectors) {
|
|
215
275
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -226,19 +286,35 @@ function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
|
226
286
|
}
|
|
227
287
|
var BASE_SELECTORS = [":root", "@theme"];
|
|
228
288
|
function scanDeclarations(css, selectors, onProperty, skip = [], stripped = stripComments(css)) {
|
|
289
|
+
const conditional = conditionalRanges(stripped);
|
|
229
290
|
forEachSelectorBlock(stripped, [...BASE_SELECTORS, ...selectors ?? []], (block, [bodyStart]) => {
|
|
230
|
-
|
|
231
|
-
forEachProperty(block,
|
|
291
|
+
const nested = nestedRanges(block);
|
|
292
|
+
forEachProperty(block, (name, value, position) => {
|
|
293
|
+
if (inRanges(skip, position)) return;
|
|
294
|
+
onProperty(name, value, position, inRanges(conditional, position) || inRanges(nested, position - bodyStart));
|
|
295
|
+
}, bodyStart);
|
|
232
296
|
});
|
|
233
297
|
}
|
|
298
|
+
function makeDeclarationCollector() {
|
|
299
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
300
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
301
|
+
const add = (name, value, isConditional) => {
|
|
302
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) return false;
|
|
303
|
+
declarations.set(name, value);
|
|
304
|
+
if (isConditional) conditional.add(name);
|
|
305
|
+
else conditional.delete(name);
|
|
306
|
+
return true;
|
|
307
|
+
};
|
|
308
|
+
return { declarations, conditional, add };
|
|
309
|
+
}
|
|
234
310
|
function parseVarNames(css, selectors) {
|
|
235
311
|
const names = /* @__PURE__ */ new Set();
|
|
236
312
|
scanDeclarations(css, selectors, (name) => names.add(name));
|
|
237
313
|
return [...names];
|
|
238
314
|
}
|
|
239
315
|
function parseVarDeclarations(css, selectors) {
|
|
240
|
-
const declarations
|
|
241
|
-
scanDeclarations(css, selectors, (name, value) =>
|
|
316
|
+
const { declarations, add } = makeDeclarationCollector();
|
|
317
|
+
scanDeclarations(css, selectors, (name, value, _position, conditional) => add(name, value, conditional));
|
|
242
318
|
return declarations;
|
|
243
319
|
}
|
|
244
320
|
var normalizePrelude = (prelude) => prelude.replace(/\s+/g, "").toLowerCase();
|
|
@@ -296,15 +372,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
296
372
|
for (const [themeName, themeSelector] of Object.entries(themes)) {
|
|
297
373
|
const values = /* @__PURE__ */ new Map();
|
|
298
374
|
themeValues.set(themeName, values);
|
|
299
|
-
const
|
|
375
|
+
const onProperty = (name, value, position) => {
|
|
300
376
|
values.set(name, value);
|
|
301
377
|
const doc = docAt(position);
|
|
302
378
|
if (doc) themeDocs.set(name, doc);
|
|
303
|
-
}
|
|
379
|
+
};
|
|
380
|
+
const collect = (block, offset) => forEachProperty(block, onProperty, offset);
|
|
304
381
|
const selector = themeSelector.trim();
|
|
305
382
|
if (/^@media\b/i.test(selector)) {
|
|
306
383
|
forEachMediaBlock(stripped, selector, (mediaBlock, range) => {
|
|
307
384
|
skip.push(range);
|
|
385
|
+
forEachOwnProperty(mediaBlock, onProperty, range[0]);
|
|
308
386
|
forEachSelectorBlock(mediaBlock, BASE_SELECTORS, (block, [innerStart]) => collect(block, range[0] + innerStart));
|
|
309
387
|
});
|
|
310
388
|
} else {
|
|
@@ -314,17 +392,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
314
392
|
});
|
|
315
393
|
}
|
|
316
394
|
}
|
|
317
|
-
const declarations
|
|
395
|
+
const { declarations, conditional, add } = makeDeclarationCollector();
|
|
318
396
|
const docs = /* @__PURE__ */ new Map();
|
|
319
|
-
scanDeclarations(css, selectors, (name, value, position) => {
|
|
320
|
-
|
|
397
|
+
scanDeclarations(css, selectors, (name, value, position, isConditional) => {
|
|
398
|
+
if (!add(name, value, isConditional)) return;
|
|
321
399
|
const doc = docAt(position);
|
|
322
400
|
if (doc) docs.set(name, doc);
|
|
323
401
|
}, skip, stripped);
|
|
324
402
|
for (const [name, doc] of themeDocs) {
|
|
325
403
|
if (!docs.has(name)) docs.set(name, doc);
|
|
326
404
|
}
|
|
327
|
-
return { declarations, themes: themeValues, docs };
|
|
405
|
+
return { declarations, conditional, themes: themeValues, docs };
|
|
328
406
|
}
|
|
329
407
|
var PROPERTY_DESCRIPTORS = [
|
|
330
408
|
["syntax", "syntax"],
|
|
@@ -468,12 +546,19 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
468
546
|
})
|
|
469
547
|
);
|
|
470
548
|
const declarations = /* @__PURE__ */ new Map();
|
|
549
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
471
550
|
const properties = /* @__PURE__ */ new Map();
|
|
472
551
|
const themeValues = new Map(Object.keys(themes).map((theme) => [theme, /* @__PURE__ */ new Map()]));
|
|
473
552
|
const docs = /* @__PURE__ */ new Map();
|
|
474
553
|
for (const result of perFile) {
|
|
475
554
|
if (!result) continue;
|
|
476
|
-
for (const [name, value] of result.declarations)
|
|
555
|
+
for (const [name, value] of result.declarations) {
|
|
556
|
+
const isConditional = result.conditional.has(name);
|
|
557
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) continue;
|
|
558
|
+
declarations.set(name, value);
|
|
559
|
+
if (isConditional) conditional.add(name);
|
|
560
|
+
else conditional.delete(name);
|
|
561
|
+
}
|
|
477
562
|
for (const [name, rule] of result.properties) properties.set(name, rule);
|
|
478
563
|
for (const [name, doc] of result.docs) docs.set(name, doc);
|
|
479
564
|
for (const [theme, values] of result.themes) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { V as VarReference, P as PropertyRule, a as VarDoc, N as NamingConvention } from './generator-
|
|
2
|
-
export { G as GeneratorOptions, T as ThemedDeclarations, g as generateCode, b as generateDeclaration, c as generateJs, d as generateTokens, p as parseDeclaredNames, e as parsePropertyRules, f as parseThemedDeclarations, h as parseVarDeclarations, i as parseVarNames, j as parseVarReferences } from './generator-
|
|
1
|
+
import { V as VarReference, P as PropertyRule, a as VarDoc, N as NamingConvention } from './generator-TJNk6ET_.cjs';
|
|
2
|
+
export { G as GeneratorOptions, T as ThemedDeclarations, g as generateCode, b as generateDeclaration, c as generateJs, d as generateTokens, p as parseDeclaredNames, e as parsePropertyRules, f as parseThemedDeclarations, h as parseVarDeclarations, i as parseVarNames, j as parseVarReferences } from './generator-TJNk6ET_.cjs';
|
|
3
3
|
|
|
4
4
|
interface ScannedCss {
|
|
5
5
|
declarations: Map<string, string>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { V as VarReference, P as PropertyRule, a as VarDoc, N as NamingConvention } from './generator-
|
|
2
|
-
export { G as GeneratorOptions, T as ThemedDeclarations, g as generateCode, b as generateDeclaration, c as generateJs, d as generateTokens, p as parseDeclaredNames, e as parsePropertyRules, f as parseThemedDeclarations, h as parseVarDeclarations, i as parseVarNames, j as parseVarReferences } from './generator-
|
|
1
|
+
import { V as VarReference, P as PropertyRule, a as VarDoc, N as NamingConvention } from './generator-TJNk6ET_.js';
|
|
2
|
+
export { G as GeneratorOptions, T as ThemedDeclarations, g as generateCode, b as generateDeclaration, c as generateJs, d as generateTokens, p as parseDeclaredNames, e as parsePropertyRules, f as parseThemedDeclarations, h as parseVarDeclarations, i as parseVarNames, j as parseVarReferences } from './generator-TJNk6ET_.js';
|
|
3
3
|
|
|
4
4
|
interface ScannedCss {
|
|
5
5
|
declarations: Map<string, string>;
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
findUndefinedRefs,
|
|
5
5
|
findUnusedVars,
|
|
6
6
|
generate
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-VWEQJVXA.js";
|
|
8
8
|
import {
|
|
9
9
|
generateCode,
|
|
10
10
|
generateDeclaration,
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
scanUsedKeys,
|
|
22
22
|
scanVarDeclarations,
|
|
23
23
|
scanVarNames
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-BPZRXE6W.js";
|
|
25
25
|
export {
|
|
26
26
|
checkGenerated,
|
|
27
27
|
defineConfig,
|
package/dist/rollup.cjs
CHANGED
|
@@ -183,7 +183,18 @@ function extractValue(text, start) {
|
|
|
183
183
|
else if (char === open[open.length - 1]) open.pop();
|
|
184
184
|
else if (char === "}" || char === ";" && open.length === 0) break;
|
|
185
185
|
}
|
|
186
|
-
return text.slice(start, i).trim();
|
|
186
|
+
return joinLines(text.slice(start, i).trim());
|
|
187
|
+
}
|
|
188
|
+
function joinLines(value) {
|
|
189
|
+
if (!/[\n\r]/.test(value)) return value;
|
|
190
|
+
const masked = maskQuotedContent(value);
|
|
191
|
+
let result = "";
|
|
192
|
+
let last = 0;
|
|
193
|
+
for (const match of masked.matchAll(/\s*[\n\r]\s*/g)) {
|
|
194
|
+
result += value.slice(last, match.index) + " ";
|
|
195
|
+
last = match.index + match[0].length;
|
|
196
|
+
}
|
|
197
|
+
return result + value.slice(last);
|
|
187
198
|
}
|
|
188
199
|
var IMPORTANT = /\s*!\s*important$/i;
|
|
189
200
|
var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
|
|
@@ -195,6 +206,55 @@ function forEachProperty(block, onProperty, offset = 0) {
|
|
|
195
206
|
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
196
207
|
}
|
|
197
208
|
}
|
|
209
|
+
var inRanges = (ranges, position) => ranges.some(([start, end]) => position >= start && position < end);
|
|
210
|
+
function nestedRanges(block) {
|
|
211
|
+
const masked = maskQuotedContent(block);
|
|
212
|
+
const ranges = [];
|
|
213
|
+
const statement = /\s*(--[\w-]+\s*:)?/y;
|
|
214
|
+
let i = 0;
|
|
215
|
+
while (i < block.length) {
|
|
216
|
+
statement.lastIndex = i;
|
|
217
|
+
const match = statement.exec(masked);
|
|
218
|
+
i = statement.lastIndex;
|
|
219
|
+
if (match[1]) {
|
|
220
|
+
const raw = block.slice(i);
|
|
221
|
+
i += raw.length - raw.trimStart().length + extractValue(block, i).length;
|
|
222
|
+
while (i < block.length && block[i] !== ";" && block[i] !== "}") i++;
|
|
223
|
+
i++;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
for (let depth = 0; i < block.length; i++) {
|
|
227
|
+
const char = masked[i];
|
|
228
|
+
if (char === "(") depth++;
|
|
229
|
+
else if (char === ")") depth = Math.max(0, depth - 1);
|
|
230
|
+
else if (depth === 0 && (char === ";" || char === "{" || char === "}")) break;
|
|
231
|
+
}
|
|
232
|
+
if (masked[i] === "{") {
|
|
233
|
+
const body = extractBlock(block, i + 1);
|
|
234
|
+
ranges.push([i + 1, i + 1 + body.length]);
|
|
235
|
+
i += body.length + 1;
|
|
236
|
+
}
|
|
237
|
+
i++;
|
|
238
|
+
}
|
|
239
|
+
return ranges;
|
|
240
|
+
}
|
|
241
|
+
function forEachOwnProperty(block, onProperty, offset = 0) {
|
|
242
|
+
const nested = nestedRanges(block);
|
|
243
|
+
forEachProperty(block, (name, value, position) => {
|
|
244
|
+
if (!inRanges(nested, position - offset)) onProperty(name, value, position);
|
|
245
|
+
}, offset);
|
|
246
|
+
}
|
|
247
|
+
function conditionalRanges(stripped) {
|
|
248
|
+
const masked = maskQuotedContent(stripped);
|
|
249
|
+
const ranges = [];
|
|
250
|
+
const openRegex = /@(?:media|supports|container)\b[^{;]*\{/gi;
|
|
251
|
+
let match;
|
|
252
|
+
while (match = openRegex.exec(masked)) {
|
|
253
|
+
const start = match.index + match[0].length;
|
|
254
|
+
ranges.push([start, start + extractBlock(stripped, start).length]);
|
|
255
|
+
}
|
|
256
|
+
return ranges;
|
|
257
|
+
}
|
|
198
258
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
199
259
|
for (const sel of selectors) {
|
|
200
260
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -211,11 +271,27 @@ function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
|
211
271
|
}
|
|
212
272
|
var BASE_SELECTORS = [":root", "@theme"];
|
|
213
273
|
function scanDeclarations(css, selectors, onProperty, skip = [], stripped = stripComments(css)) {
|
|
274
|
+
const conditional = conditionalRanges(stripped);
|
|
214
275
|
forEachSelectorBlock(stripped, [...BASE_SELECTORS, ...selectors ?? []], (block, [bodyStart]) => {
|
|
215
|
-
|
|
216
|
-
forEachProperty(block,
|
|
276
|
+
const nested = nestedRanges(block);
|
|
277
|
+
forEachProperty(block, (name, value, position) => {
|
|
278
|
+
if (inRanges(skip, position)) return;
|
|
279
|
+
onProperty(name, value, position, inRanges(conditional, position) || inRanges(nested, position - bodyStart));
|
|
280
|
+
}, bodyStart);
|
|
217
281
|
});
|
|
218
282
|
}
|
|
283
|
+
function makeDeclarationCollector() {
|
|
284
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
285
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
286
|
+
const add = (name, value, isConditional) => {
|
|
287
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) return false;
|
|
288
|
+
declarations.set(name, value);
|
|
289
|
+
if (isConditional) conditional.add(name);
|
|
290
|
+
else conditional.delete(name);
|
|
291
|
+
return true;
|
|
292
|
+
};
|
|
293
|
+
return { declarations, conditional, add };
|
|
294
|
+
}
|
|
219
295
|
var normalizePrelude = (prelude) => prelude.replace(/\s+/g, "").toLowerCase();
|
|
220
296
|
function forEachMediaBlock(stripped, media, onBlock) {
|
|
221
297
|
const wanted = normalizePrelude(media.replace(/^@media/i, ""));
|
|
@@ -271,15 +347,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
271
347
|
for (const [themeName, themeSelector] of Object.entries(themes)) {
|
|
272
348
|
const values = /* @__PURE__ */ new Map();
|
|
273
349
|
themeValues.set(themeName, values);
|
|
274
|
-
const
|
|
350
|
+
const onProperty = (name, value, position) => {
|
|
275
351
|
values.set(name, value);
|
|
276
352
|
const doc = docAt(position);
|
|
277
353
|
if (doc) themeDocs.set(name, doc);
|
|
278
|
-
}
|
|
354
|
+
};
|
|
355
|
+
const collect = (block, offset) => forEachProperty(block, onProperty, offset);
|
|
279
356
|
const selector = themeSelector.trim();
|
|
280
357
|
if (/^@media\b/i.test(selector)) {
|
|
281
358
|
forEachMediaBlock(stripped, selector, (mediaBlock, range) => {
|
|
282
359
|
skip.push(range);
|
|
360
|
+
forEachOwnProperty(mediaBlock, onProperty, range[0]);
|
|
283
361
|
forEachSelectorBlock(mediaBlock, BASE_SELECTORS, (block, [innerStart]) => collect(block, range[0] + innerStart));
|
|
284
362
|
});
|
|
285
363
|
} else {
|
|
@@ -289,17 +367,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
289
367
|
});
|
|
290
368
|
}
|
|
291
369
|
}
|
|
292
|
-
const declarations
|
|
370
|
+
const { declarations, conditional, add } = makeDeclarationCollector();
|
|
293
371
|
const docs = /* @__PURE__ */ new Map();
|
|
294
|
-
scanDeclarations(css, selectors, (name, value, position) => {
|
|
295
|
-
|
|
372
|
+
scanDeclarations(css, selectors, (name, value, position, isConditional) => {
|
|
373
|
+
if (!add(name, value, isConditional)) return;
|
|
296
374
|
const doc = docAt(position);
|
|
297
375
|
if (doc) docs.set(name, doc);
|
|
298
376
|
}, skip, stripped);
|
|
299
377
|
for (const [name, doc] of themeDocs) {
|
|
300
378
|
if (!docs.has(name)) docs.set(name, doc);
|
|
301
379
|
}
|
|
302
|
-
return { declarations, themes: themeValues, docs };
|
|
380
|
+
return { declarations, conditional, themes: themeValues, docs };
|
|
303
381
|
}
|
|
304
382
|
var PROPERTY_DESCRIPTORS = [
|
|
305
383
|
["syntax", "syntax"],
|
|
@@ -377,9 +455,13 @@ async function findFiles(patterns, exclude) {
|
|
|
377
455
|
return [...new Set(files.reverse())].reverse();
|
|
378
456
|
}
|
|
379
457
|
function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
380
|
-
const compile = (globs) => (0, import_picomatch.default)(
|
|
381
|
-
const
|
|
382
|
-
const
|
|
458
|
+
const compile = (globs) => (0, import_picomatch.default)(globs.map((p) => p.replace(/^\.\//, "")));
|
|
459
|
+
const normalized = normalizePatterns(patterns);
|
|
460
|
+
const include = compile(normalized.filter((p) => !p.startsWith("!")));
|
|
461
|
+
const ignore = compile([
|
|
462
|
+
...exclude ? normalizePatterns(exclude) : [],
|
|
463
|
+
...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
|
|
464
|
+
]);
|
|
383
465
|
return (file) => {
|
|
384
466
|
const absolute = (0, import_node_path2.resolve)(cwd, file).replace(/\\/g, "/");
|
|
385
467
|
const fromCwd = (0, import_node_path2.relative)(cwd, absolute).replace(/\\/g, "/");
|
|
@@ -390,6 +472,7 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
|
390
472
|
function globWatchRoots(patterns, cwd = process.cwd()) {
|
|
391
473
|
const roots = /* @__PURE__ */ new Map();
|
|
392
474
|
for (const pattern of normalizePatterns(patterns)) {
|
|
475
|
+
if (pattern.startsWith("!")) continue;
|
|
393
476
|
const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
|
|
394
477
|
const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
|
|
395
478
|
const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
|
|
@@ -424,12 +507,19 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
424
507
|
})
|
|
425
508
|
);
|
|
426
509
|
const declarations = /* @__PURE__ */ new Map();
|
|
510
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
427
511
|
const properties = /* @__PURE__ */ new Map();
|
|
428
512
|
const themeValues = new Map(Object.keys(themes).map((theme) => [theme, /* @__PURE__ */ new Map()]));
|
|
429
513
|
const docs = /* @__PURE__ */ new Map();
|
|
430
514
|
for (const result of perFile) {
|
|
431
515
|
if (!result) continue;
|
|
432
|
-
for (const [name, value] of result.declarations)
|
|
516
|
+
for (const [name, value] of result.declarations) {
|
|
517
|
+
const isConditional = result.conditional.has(name);
|
|
518
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) continue;
|
|
519
|
+
declarations.set(name, value);
|
|
520
|
+
if (isConditional) conditional.add(name);
|
|
521
|
+
else conditional.delete(name);
|
|
522
|
+
}
|
|
433
523
|
for (const [name, rule] of result.properties) properties.set(name, rule);
|
|
434
524
|
for (const [name, doc] of result.docs) docs.set(name, doc);
|
|
435
525
|
for (const [theme, values] of result.themes) {
|
package/dist/rollup.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as rollup from 'rollup';
|
|
2
2
|
import { Options } from './unplugin.cjs';
|
|
3
3
|
import 'unplugin';
|
|
4
|
-
import './generator-
|
|
4
|
+
import './generator-TJNk6ET_.cjs';
|
|
5
5
|
|
|
6
6
|
declare const _default: (options: Options) => rollup.Plugin<any> | rollup.Plugin<any>[];
|
|
7
7
|
|