css-typed-vars 0.13.0 → 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 +10 -7
- package/dist/{chunk-JGJ53FND.js → chunk-7J7UZYHB.js} +1 -1
- package/dist/{chunk-XSFYQPH6.js → chunk-BPZRXE6W.js} +141 -22
- package/dist/{chunk-FWKCSH2F.js → chunk-VWEQJVXA.js} +1 -1
- package/dist/cli.cjs +145 -21
- package/dist/cli.js +8 -3
- package/dist/esbuild.cjs +135 -17
- 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 +133 -19
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/rollup.cjs +135 -17
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.d.ts +1 -1
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +135 -17
- package/dist/unplugin.d.cts +1 -1
- package/dist/unplugin.d.ts +1 -1
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +135 -17
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +135 -17
- 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/index.cjs
CHANGED
|
@@ -198,17 +198,78 @@ 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;
|
|
215
|
+
var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
|
|
204
216
|
function forEachProperty(block, onProperty, offset = 0) {
|
|
205
217
|
const masked = maskQuotedContent(block);
|
|
206
|
-
for (const prop of masked.matchAll(
|
|
218
|
+
for (const prop of masked.matchAll(DECLARATION_NAME)) {
|
|
207
219
|
const name = prop[0];
|
|
208
220
|
const colonIndex = block.indexOf(":", prop.index + name.length);
|
|
209
221
|
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
210
222
|
}
|
|
211
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
|
+
}
|
|
212
273
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
213
274
|
for (const sel of selectors) {
|
|
214
275
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -225,19 +286,35 @@ function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
|
225
286
|
}
|
|
226
287
|
var BASE_SELECTORS = [":root", "@theme"];
|
|
227
288
|
function scanDeclarations(css, selectors, onProperty, skip = [], stripped = stripComments(css)) {
|
|
289
|
+
const conditional = conditionalRanges(stripped);
|
|
228
290
|
forEachSelectorBlock(stripped, [...BASE_SELECTORS, ...selectors ?? []], (block, [bodyStart]) => {
|
|
229
|
-
|
|
230
|
-
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);
|
|
231
296
|
});
|
|
232
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
|
+
}
|
|
233
310
|
function parseVarNames(css, selectors) {
|
|
234
311
|
const names = /* @__PURE__ */ new Set();
|
|
235
312
|
scanDeclarations(css, selectors, (name) => names.add(name));
|
|
236
313
|
return [...names];
|
|
237
314
|
}
|
|
238
315
|
function parseVarDeclarations(css, selectors) {
|
|
239
|
-
const declarations
|
|
240
|
-
scanDeclarations(css, selectors, (name, value) =>
|
|
316
|
+
const { declarations, add } = makeDeclarationCollector();
|
|
317
|
+
scanDeclarations(css, selectors, (name, value, _position, conditional) => add(name, value, conditional));
|
|
241
318
|
return declarations;
|
|
242
319
|
}
|
|
243
320
|
var normalizePrelude = (prelude) => prelude.replace(/\s+/g, "").toLowerCase();
|
|
@@ -295,15 +372,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
295
372
|
for (const [themeName, themeSelector] of Object.entries(themes)) {
|
|
296
373
|
const values = /* @__PURE__ */ new Map();
|
|
297
374
|
themeValues.set(themeName, values);
|
|
298
|
-
const
|
|
375
|
+
const onProperty = (name, value, position) => {
|
|
299
376
|
values.set(name, value);
|
|
300
377
|
const doc = docAt(position);
|
|
301
378
|
if (doc) themeDocs.set(name, doc);
|
|
302
|
-
}
|
|
379
|
+
};
|
|
380
|
+
const collect = (block, offset) => forEachProperty(block, onProperty, offset);
|
|
303
381
|
const selector = themeSelector.trim();
|
|
304
382
|
if (/^@media\b/i.test(selector)) {
|
|
305
383
|
forEachMediaBlock(stripped, selector, (mediaBlock, range) => {
|
|
306
384
|
skip.push(range);
|
|
385
|
+
forEachOwnProperty(mediaBlock, onProperty, range[0]);
|
|
307
386
|
forEachSelectorBlock(mediaBlock, BASE_SELECTORS, (block, [innerStart]) => collect(block, range[0] + innerStart));
|
|
308
387
|
});
|
|
309
388
|
} else {
|
|
@@ -313,17 +392,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
313
392
|
});
|
|
314
393
|
}
|
|
315
394
|
}
|
|
316
|
-
const declarations
|
|
395
|
+
const { declarations, conditional, add } = makeDeclarationCollector();
|
|
317
396
|
const docs = /* @__PURE__ */ new Map();
|
|
318
|
-
scanDeclarations(css, selectors, (name, value, position) => {
|
|
319
|
-
|
|
397
|
+
scanDeclarations(css, selectors, (name, value, position, isConditional) => {
|
|
398
|
+
if (!add(name, value, isConditional)) return;
|
|
320
399
|
const doc = docAt(position);
|
|
321
400
|
if (doc) docs.set(name, doc);
|
|
322
401
|
}, skip, stripped);
|
|
323
402
|
for (const [name, doc] of themeDocs) {
|
|
324
403
|
if (!docs.has(name)) docs.set(name, doc);
|
|
325
404
|
}
|
|
326
|
-
return { declarations, themes: themeValues, docs };
|
|
405
|
+
return { declarations, conditional, themes: themeValues, docs };
|
|
327
406
|
}
|
|
328
407
|
var PROPERTY_DESCRIPTORS = [
|
|
329
408
|
["syntax", "syntax"],
|
|
@@ -362,13 +441,14 @@ function toRawPosition(stripped, strippedPos) {
|
|
|
362
441
|
}
|
|
363
442
|
return rawPos;
|
|
364
443
|
}
|
|
444
|
+
var CSS_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(?:(,)|\))/gi;
|
|
365
445
|
function parseVarReferences(css) {
|
|
366
446
|
const stripped = stripCommentsWithMap(css);
|
|
367
447
|
const masked = maskQuotedContent(stripped.text);
|
|
368
448
|
const lineStarts = [0];
|
|
369
449
|
for (let i = 0; i < css.length; i++) if (css[i] === "\n") lineStarts.push(i + 1);
|
|
370
450
|
const refs = [];
|
|
371
|
-
for (const match of masked.matchAll(
|
|
451
|
+
for (const match of masked.matchAll(CSS_REF_RE)) {
|
|
372
452
|
const rawPos = toRawPosition(stripped, match.index);
|
|
373
453
|
let line = lineStarts.length - 1;
|
|
374
454
|
while (lineStarts[line] > rawPos) line--;
|
|
@@ -376,7 +456,7 @@ function parseVarReferences(css) {
|
|
|
376
456
|
}
|
|
377
457
|
return refs;
|
|
378
458
|
}
|
|
379
|
-
var SOURCE_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(,)
|
|
459
|
+
var SOURCE_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(?:(,)|\))|(?<=[\w-]-)\((?:[\w-]+:)?(--[\w-]+)\)/g;
|
|
380
460
|
function parseSourceVarReferences(text) {
|
|
381
461
|
const lineStarts = [0];
|
|
382
462
|
for (let i = 0; i < text.length; i++) if (text[i] === "\n") lineStarts.push(i + 1);
|
|
@@ -402,7 +482,7 @@ function parseSourceDeclaredNames(text) {
|
|
|
402
482
|
function parseDeclaredNames(css) {
|
|
403
483
|
const masked = maskQuotedContent(stripComments(css));
|
|
404
484
|
const names = /* @__PURE__ */ new Set();
|
|
405
|
-
for (const match of masked.matchAll(/(?<![\w
|
|
485
|
+
for (const match of masked.matchAll(/(?<![\w&-])(--[\w-]+)\s*:/g)) names.add(match[1]);
|
|
406
486
|
for (const match of masked.matchAll(/@property\s+(--[\w-]+)/g)) names.add(match[1]);
|
|
407
487
|
return names;
|
|
408
488
|
}
|
|
@@ -466,12 +546,19 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
466
546
|
})
|
|
467
547
|
);
|
|
468
548
|
const declarations = /* @__PURE__ */ new Map();
|
|
549
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
469
550
|
const properties = /* @__PURE__ */ new Map();
|
|
470
551
|
const themeValues = new Map(Object.keys(themes).map((theme) => [theme, /* @__PURE__ */ new Map()]));
|
|
471
552
|
const docs = /* @__PURE__ */ new Map();
|
|
472
553
|
for (const result of perFile) {
|
|
473
554
|
if (!result) continue;
|
|
474
|
-
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
|
+
}
|
|
475
562
|
for (const [name, rule] of result.properties) properties.set(name, rule);
|
|
476
563
|
for (const [name, doc] of result.docs) docs.set(name, doc);
|
|
477
564
|
for (const [theme, values] of result.themes) {
|
|
@@ -499,19 +586,46 @@ function rootPattern(text) {
|
|
|
499
586
|
const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
|
|
500
587
|
return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
|
|
501
588
|
}
|
|
502
|
-
var ACCESS_RE = /\s*(
|
|
589
|
+
var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
|
|
503
590
|
function readAccess(text, from) {
|
|
504
591
|
ACCESS_RE.lastIndex = from;
|
|
505
592
|
const match = ACCESS_RE.exec(text);
|
|
506
593
|
return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
|
|
507
594
|
}
|
|
595
|
+
var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
|
|
596
|
+
function readPatternKeys(text, at) {
|
|
597
|
+
let i = at - 1;
|
|
598
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
599
|
+
if (text[i] !== "=") return [];
|
|
600
|
+
i--;
|
|
601
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
602
|
+
if (text[i] !== "}") return [];
|
|
603
|
+
const open = text.lastIndexOf("{", i);
|
|
604
|
+
if (open === -1) return [];
|
|
605
|
+
const body = text.slice(open + 1, i);
|
|
606
|
+
if (body.includes("}")) return [];
|
|
607
|
+
const keys = [];
|
|
608
|
+
for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
|
|
609
|
+
const match = PATTERN_KEY_RE.exec(part);
|
|
610
|
+
if (match) keys.push(match[1] ?? match[3]);
|
|
611
|
+
}
|
|
612
|
+
return keys;
|
|
613
|
+
}
|
|
508
614
|
function extractUsage(text, into) {
|
|
509
615
|
for (const root of text.matchAll(rootPattern(text))) {
|
|
510
616
|
const first = readAccess(text, root.index + root[0].length);
|
|
511
|
-
|
|
617
|
+
const second = first && readAccess(text, first.end);
|
|
618
|
+
const destructured = second ? [] : readPatternKeys(text, root.index);
|
|
619
|
+
if (!first) {
|
|
620
|
+
for (const key of destructured) {
|
|
621
|
+
into.keys.add(key);
|
|
622
|
+
into.wholeKeys.add(key);
|
|
623
|
+
}
|
|
624
|
+
continue;
|
|
625
|
+
}
|
|
512
626
|
into.keys.add(first.key);
|
|
513
|
-
const second = readAccess(text, first.end);
|
|
514
627
|
if (second) into.paths.add(`${first.key}\0${second.key}`);
|
|
628
|
+
else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
|
|
515
629
|
else into.wholeKeys.add(first.key);
|
|
516
630
|
}
|
|
517
631
|
}
|
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,17 +183,78 @@ 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;
|
|
200
|
+
var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
|
|
189
201
|
function forEachProperty(block, onProperty, offset = 0) {
|
|
190
202
|
const masked = maskQuotedContent(block);
|
|
191
|
-
for (const prop of masked.matchAll(
|
|
203
|
+
for (const prop of masked.matchAll(DECLARATION_NAME)) {
|
|
192
204
|
const name = prop[0];
|
|
193
205
|
const colonIndex = block.indexOf(":", prop.index + name.length);
|
|
194
206
|
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
195
207
|
}
|
|
196
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
|
+
}
|
|
197
258
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
198
259
|
for (const sel of selectors) {
|
|
199
260
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -210,11 +271,27 @@ function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
|
210
271
|
}
|
|
211
272
|
var BASE_SELECTORS = [":root", "@theme"];
|
|
212
273
|
function scanDeclarations(css, selectors, onProperty, skip = [], stripped = stripComments(css)) {
|
|
274
|
+
const conditional = conditionalRanges(stripped);
|
|
213
275
|
forEachSelectorBlock(stripped, [...BASE_SELECTORS, ...selectors ?? []], (block, [bodyStart]) => {
|
|
214
|
-
|
|
215
|
-
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);
|
|
216
281
|
});
|
|
217
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
|
+
}
|
|
218
295
|
var normalizePrelude = (prelude) => prelude.replace(/\s+/g, "").toLowerCase();
|
|
219
296
|
function forEachMediaBlock(stripped, media, onBlock) {
|
|
220
297
|
const wanted = normalizePrelude(media.replace(/^@media/i, ""));
|
|
@@ -270,15 +347,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
270
347
|
for (const [themeName, themeSelector] of Object.entries(themes)) {
|
|
271
348
|
const values = /* @__PURE__ */ new Map();
|
|
272
349
|
themeValues.set(themeName, values);
|
|
273
|
-
const
|
|
350
|
+
const onProperty = (name, value, position) => {
|
|
274
351
|
values.set(name, value);
|
|
275
352
|
const doc = docAt(position);
|
|
276
353
|
if (doc) themeDocs.set(name, doc);
|
|
277
|
-
}
|
|
354
|
+
};
|
|
355
|
+
const collect = (block, offset) => forEachProperty(block, onProperty, offset);
|
|
278
356
|
const selector = themeSelector.trim();
|
|
279
357
|
if (/^@media\b/i.test(selector)) {
|
|
280
358
|
forEachMediaBlock(stripped, selector, (mediaBlock, range) => {
|
|
281
359
|
skip.push(range);
|
|
360
|
+
forEachOwnProperty(mediaBlock, onProperty, range[0]);
|
|
282
361
|
forEachSelectorBlock(mediaBlock, BASE_SELECTORS, (block, [innerStart]) => collect(block, range[0] + innerStart));
|
|
283
362
|
});
|
|
284
363
|
} else {
|
|
@@ -288,17 +367,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
288
367
|
});
|
|
289
368
|
}
|
|
290
369
|
}
|
|
291
|
-
const declarations
|
|
370
|
+
const { declarations, conditional, add } = makeDeclarationCollector();
|
|
292
371
|
const docs = /* @__PURE__ */ new Map();
|
|
293
|
-
scanDeclarations(css, selectors, (name, value, position) => {
|
|
294
|
-
|
|
372
|
+
scanDeclarations(css, selectors, (name, value, position, isConditional) => {
|
|
373
|
+
if (!add(name, value, isConditional)) return;
|
|
295
374
|
const doc = docAt(position);
|
|
296
375
|
if (doc) docs.set(name, doc);
|
|
297
376
|
}, skip, stripped);
|
|
298
377
|
for (const [name, doc] of themeDocs) {
|
|
299
378
|
if (!docs.has(name)) docs.set(name, doc);
|
|
300
379
|
}
|
|
301
|
-
return { declarations, themes: themeValues, docs };
|
|
380
|
+
return { declarations, conditional, themes: themeValues, docs };
|
|
302
381
|
}
|
|
303
382
|
var PROPERTY_DESCRIPTORS = [
|
|
304
383
|
["syntax", "syntax"],
|
|
@@ -376,9 +455,13 @@ async function findFiles(patterns, exclude) {
|
|
|
376
455
|
return [...new Set(files.reverse())].reverse();
|
|
377
456
|
}
|
|
378
457
|
function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
379
|
-
const compile = (globs) => (0, import_picomatch.default)(
|
|
380
|
-
const
|
|
381
|
-
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
|
+
]);
|
|
382
465
|
return (file) => {
|
|
383
466
|
const absolute = (0, import_node_path2.resolve)(cwd, file).replace(/\\/g, "/");
|
|
384
467
|
const fromCwd = (0, import_node_path2.relative)(cwd, absolute).replace(/\\/g, "/");
|
|
@@ -389,6 +472,7 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
|
389
472
|
function globWatchRoots(patterns, cwd = process.cwd()) {
|
|
390
473
|
const roots = /* @__PURE__ */ new Map();
|
|
391
474
|
for (const pattern of normalizePatterns(patterns)) {
|
|
475
|
+
if (pattern.startsWith("!")) continue;
|
|
392
476
|
const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
|
|
393
477
|
const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
|
|
394
478
|
const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
|
|
@@ -423,12 +507,19 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
423
507
|
})
|
|
424
508
|
);
|
|
425
509
|
const declarations = /* @__PURE__ */ new Map();
|
|
510
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
426
511
|
const properties = /* @__PURE__ */ new Map();
|
|
427
512
|
const themeValues = new Map(Object.keys(themes).map((theme) => [theme, /* @__PURE__ */ new Map()]));
|
|
428
513
|
const docs = /* @__PURE__ */ new Map();
|
|
429
514
|
for (const result of perFile) {
|
|
430
515
|
if (!result) continue;
|
|
431
|
-
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
|
+
}
|
|
432
523
|
for (const [name, rule] of result.properties) properties.set(name, rule);
|
|
433
524
|
for (const [name, doc] of result.docs) docs.set(name, doc);
|
|
434
525
|
for (const [theme, values] of result.themes) {
|
|
@@ -449,19 +540,46 @@ function rootPattern(text) {
|
|
|
449
540
|
const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
|
|
450
541
|
return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
|
|
451
542
|
}
|
|
452
|
-
var ACCESS_RE = /\s*(
|
|
543
|
+
var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
|
|
453
544
|
function readAccess(text, from) {
|
|
454
545
|
ACCESS_RE.lastIndex = from;
|
|
455
546
|
const match = ACCESS_RE.exec(text);
|
|
456
547
|
return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
|
|
457
548
|
}
|
|
549
|
+
var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
|
|
550
|
+
function readPatternKeys(text, at) {
|
|
551
|
+
let i = at - 1;
|
|
552
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
553
|
+
if (text[i] !== "=") return [];
|
|
554
|
+
i--;
|
|
555
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
556
|
+
if (text[i] !== "}") return [];
|
|
557
|
+
const open = text.lastIndexOf("{", i);
|
|
558
|
+
if (open === -1) return [];
|
|
559
|
+
const body = text.slice(open + 1, i);
|
|
560
|
+
if (body.includes("}")) return [];
|
|
561
|
+
const keys = [];
|
|
562
|
+
for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
|
|
563
|
+
const match = PATTERN_KEY_RE.exec(part);
|
|
564
|
+
if (match) keys.push(match[1] ?? match[3]);
|
|
565
|
+
}
|
|
566
|
+
return keys;
|
|
567
|
+
}
|
|
458
568
|
function extractUsage(text, into) {
|
|
459
569
|
for (const root of text.matchAll(rootPattern(text))) {
|
|
460
570
|
const first = readAccess(text, root.index + root[0].length);
|
|
461
|
-
|
|
571
|
+
const second = first && readAccess(text, first.end);
|
|
572
|
+
const destructured = second ? [] : readPatternKeys(text, root.index);
|
|
573
|
+
if (!first) {
|
|
574
|
+
for (const key of destructured) {
|
|
575
|
+
into.keys.add(key);
|
|
576
|
+
into.wholeKeys.add(key);
|
|
577
|
+
}
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
462
580
|
into.keys.add(first.key);
|
|
463
|
-
const second = readAccess(text, first.end);
|
|
464
581
|
if (second) into.paths.add(`${first.key}\0${second.key}`);
|
|
582
|
+
else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
|
|
465
583
|
else into.wholeKeys.add(first.key);
|
|
466
584
|
}
|
|
467
585
|
}
|
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
|
|
package/dist/rollup.d.ts
CHANGED