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/README.md
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
|
|
38
38
|
`css-typed-vars` scans your CSS files and gives you typed constants. Use `cssVars.colorPrimary` instead — TypeScript catches missing variables at compile time.
|
|
39
39
|
|
|
40
|
-
Each generated key also carries a `/** @default ... */` comment with the property's declared CSS value, so your editor shows it on hover and autocomplete. If the variable is registered with [`@property`](#property-syntax-typing), its `syntax` descriptor shows up too, and an enum-like syntax (e.g. `"light | dark | system"`) gets its own exported TS union type.
|
|
40
|
+
Each generated key also carries a `/** @default ... */` comment with the property's declared CSS value, so your editor shows it on hover and autocomplete. A value written over several lines (a font stack, a list of shadows) is joined into one. If the variable is registered with [`@property`](#property-syntax-typing), its `syntax` descriptor shows up too, and an enum-like syntax (e.g. `"light | dark | system"`) gets its own exported TS union type.
|
|
41
41
|
|
|
42
42
|
## Installation
|
|
43
43
|
|
|
@@ -133,9 +133,9 @@ npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --prune-check
|
|
|
133
133
|
| `--config` | Config file to use instead of looking one up in the working directory — see [Config file](#config-file) |
|
|
134
134
|
| `--input` | Glob pattern for CSS/SCSS/Less files (repeatable: `--input "src/**/*.css" --input "lib/**/*.css"`) |
|
|
135
135
|
| `--output` | Output file. `.ts` → TypeScript, `.js` → JavaScript + `.d.ts` alongside, `.json` → [design tokens](#design-tokens-dtcg) |
|
|
136
|
-
| `--exclude` | Glob pattern for files to exclude (repeatable: `--exclude "**/a/**" --exclude "**/b/**"`) |
|
|
136
|
+
| `--exclude` | Glob pattern for files to exclude (repeatable: `--exclude "**/a/**" --exclude "**/b/**"`). A negated `--input` glob excludes too: `--input "!**/vendor/**"` |
|
|
137
137
|
| `--prefix` | Prefix for generated keys: `--prefix theme` → `themeColorPrimary` |
|
|
138
|
-
| `--naming` | Key naming: `camelCase` (default), `snake`, `kebab`, `constant`, `pascal` |
|
|
138
|
+
| `--naming` | Key naming: `camelCase` (default), `snake`, `kebab`, `constant`, `pascal`. Another spelling of one (`snake_case`, `PascalCase`) is rejected with a hint at the value to use |
|
|
139
139
|
| `--selector` | Extra CSS selector to scan for variables (repeatable: `--selector ".dark" --selector "[data-theme='dark']"`) |
|
|
140
140
|
| `--theme` | Named theme block, kept out of the default value and emitted as `@theme <name> <value>` JSDoc tags (repeatable: `--theme dark='[data-theme="dark"]' --theme contrast='@media (prefers-contrast: more)'`) — see [Theme values](#theme-values) |
|
|
141
141
|
| `--group` | Nest keys under an object named after each variable's first hyphen segment: `--color-primary`/`--color-secondary` → `cssVars.color.primary`/`cssVars.color.secondary`. A variable with no hyphen stays top-level. Can't be combined with `--prefix`. |
|
|
@@ -154,8 +154,9 @@ npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --prune-check
|
|
|
154
154
|
|
|
155
155
|
### Pruning unused variables
|
|
156
156
|
|
|
157
|
-
`--prune`/`--prune-check` scan your source files for `cssVars.<key>` (dot access)
|
|
157
|
+
`--prune`/`--prune-check` scan your source files for `cssVars.<key>` (dot access), `cssVars['<key>']`/`cssVars["<key>"]` (bracket access) or `const { <key> } = cssVars` (destructuring) usage — optional chaining (`cssVars?.<key>`) included — and compare that against the generated keys. This is a textual scan, not a full parser, so it has limitations worth knowing:
|
|
158
158
|
|
|
159
|
+
- Destructuring is read one level deep — `const { colorPrimary, gap: g } = cssVars`, or `const { primary } = cssVars.color` with `--group` — but not a nested pattern (`{ color: { primary } }`), a `...rest` element or a destructured function parameter.
|
|
159
160
|
- A renamed import (`import { cssVars as vars } from './cssVars'`) is followed within the file that declares it, but not a re-export under another name or an assignment (`const v = cssVars`).
|
|
160
161
|
- A match inside a comment or string still counts as "used".
|
|
161
162
|
|
|
@@ -182,6 +183,7 @@ css-typed-vars: 2 reference(s) to undeclared variables:
|
|
|
182
183
|
- A variable counts as declared if any input file declares it in any block (not just `:root`), or registers it with `@property`.
|
|
183
184
|
- References without a fallback are errors and make the command exit `1`. References with a fallback (`var(--x, 4px)`) still work at runtime, so they're only reported as warnings.
|
|
184
185
|
- References inside comments and strings are ignored; positions point to the original file.
|
|
186
|
+
- A name with an interpolated part — SCSS `var(--color-#{$name})`, Less `var(--size-@{n})` — isn't a reference to one variable, and is skipped.
|
|
185
187
|
- Variables set from JavaScript or defined by another stylesheet you don't scan can be skipped with `--refs-ignore` (repeatable, a trailing `*` matches a prefix): `--refs-ignore "--tw-*" --refs-ignore --app-height`, or `refsIgnore` in the config file.
|
|
186
188
|
|
|
187
189
|
#### In source files
|
|
@@ -198,6 +200,7 @@ css-typed-vars: 1 reference(s) to undeclared variables:
|
|
|
198
200
|
```
|
|
199
201
|
|
|
200
202
|
- Finds `var(--name)` anywhere in the file — in strings, template literals, Tailwind classes like `bg-[var(--brand)]` — and Tailwind v4's `bg-(--brand)` shorthand.
|
|
203
|
+
- A name built at runtime is skipped: `` `var(--color-${name})` ``, `'var(--size-' + n + ')'`.
|
|
201
204
|
- Variables a source file sets itself count as declared: an object key (`{ '--gap': '4px' }`), a `style` attribute (`style="--gap: 4px"`), `setProperty('--gap', ...)` or a Tailwind arbitrary property (`[--gap:4px]`). This applies to the CSS references too.
|
|
202
205
|
- Like the `--prune` usage scan, this is textual: a reference inside a comment counts too.
|
|
203
206
|
- The target's own output file is skipped even if the glob matches it — `--check` is what tells whether it's stale.
|
|
@@ -359,7 +362,7 @@ Turbopack does not yet have a public plugin API for virtual modules. Use the CLI
|
|
|
359
362
|
| Option | Type | Default | Description |
|
|
360
363
|
|--------|------|---------|-------------|
|
|
361
364
|
| `input` | `string \| string[]` | — | Glob pattern for CSS/SCSS/Less files |
|
|
362
|
-
| `exclude` | `string \| string[]` | — | Glob pattern(s) for files to exclude |
|
|
365
|
+
| `exclude` | `string \| string[]` | — | Glob pattern(s) for files to exclude. A negated `input` glob (`'!**/vendor/**'`) excludes too |
|
|
363
366
|
| `prefix` | `string` | — | Prefix for generated keys: `'theme'` → `themeColorPrimary` |
|
|
364
367
|
| `naming` | `'camelCase' \| 'snake' \| 'kebab' \| 'constant' \| 'pascal'` | `'camelCase'` | Key naming convention |
|
|
365
368
|
| `selectors` | `string[]` | — | Extra CSS selectors to scan, e.g. `['.dark', '[data-theme="dark"]']` |
|
|
@@ -494,7 +497,7 @@ By default, variables are scanned from `:root {}` blocks (including attribute se
|
|
|
494
497
|
|
|
495
498
|
When a variable is declared in several files, the last file read wins. Files are read in `input` order (a file matched by several globs counts at the last one), and within a glob a directory's files come before its subdirectories', alphabetically — so `styles/themes/dark.css` overrides `styles/tokens.css`.
|
|
496
499
|
|
|
497
|
-
By default, a variable redeclared in another block (`:root[data-theme="dark"]`, or a `selectors` entry) simply overwrites its `@default` value — last one wins. The `themes` option names those blocks instead, so each theme's value is kept separately:
|
|
500
|
+
By default, a variable redeclared in another block (`:root[data-theme="dark"]`, or a `selectors` entry) simply overwrites its `@default` value — last one wins. A conditional declaration is the exception: one inside an `@media`, `@supports` or `@container` rule, or in a rule nested in the block (`:root { .compact & { --gap: 2px; } }`), doesn't replace an unconditional one, in the same file or another — it's only used when the variable has no other value. The `themes` option names those blocks instead, so each theme's value is kept separately:
|
|
498
501
|
|
|
499
502
|
```js
|
|
500
503
|
// css-typed-vars.config.js
|
|
@@ -529,7 +532,7 @@ export const cssVars = {
|
|
|
529
532
|
|
|
530
533
|
- Theme blocks are kept out of the default value, so `@default` always shows the base (`:root`/`@theme`/`selectors`) value.
|
|
531
534
|
- A variable declared only inside a theme (`--glow` above) is still generated, with just its theme tags.
|
|
532
|
-
- An `@media` theme matches by its prelude, ignoring whitespace and case. Other `@media` blocks are read as before.
|
|
535
|
+
- An `@media` theme matches by its prelude, ignoring whitespace and case, whether it wraps the `:root`/`@theme` block or is nested in it (`:root { @media (prefers-color-scheme: dark) { --bg: #000; } }`). Other `@media` blocks are read as before.
|
|
533
536
|
- On the CLI, pass `--theme <name>=<selector>` (repeatable): `--theme dark='[data-theme="dark"]'`.
|
|
534
537
|
|
|
535
538
|
## Doc comments
|
|
@@ -142,17 +142,78 @@ function extractValue(text, start) {
|
|
|
142
142
|
else if (char === open[open.length - 1]) open.pop();
|
|
143
143
|
else if (char === "}" || char === ";" && open.length === 0) break;
|
|
144
144
|
}
|
|
145
|
-
return text.slice(start, i).trim();
|
|
145
|
+
return joinLines(text.slice(start, i).trim());
|
|
146
|
+
}
|
|
147
|
+
function joinLines(value) {
|
|
148
|
+
if (!/[\n\r]/.test(value)) return value;
|
|
149
|
+
const masked = maskQuotedContent(value);
|
|
150
|
+
let result = "";
|
|
151
|
+
let last = 0;
|
|
152
|
+
for (const match of masked.matchAll(/\s*[\n\r]\s*/g)) {
|
|
153
|
+
result += value.slice(last, match.index) + " ";
|
|
154
|
+
last = match.index + match[0].length;
|
|
155
|
+
}
|
|
156
|
+
return result + value.slice(last);
|
|
146
157
|
}
|
|
147
158
|
var IMPORTANT = /\s*!\s*important$/i;
|
|
159
|
+
var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
|
|
148
160
|
function forEachProperty(block, onProperty, offset = 0) {
|
|
149
161
|
const masked = maskQuotedContent(block);
|
|
150
|
-
for (const prop of masked.matchAll(
|
|
162
|
+
for (const prop of masked.matchAll(DECLARATION_NAME)) {
|
|
151
163
|
const name = prop[0];
|
|
152
164
|
const colonIndex = block.indexOf(":", prop.index + name.length);
|
|
153
165
|
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
154
166
|
}
|
|
155
167
|
}
|
|
168
|
+
var inRanges = (ranges, position) => ranges.some(([start, end]) => position >= start && position < end);
|
|
169
|
+
function nestedRanges(block) {
|
|
170
|
+
const masked = maskQuotedContent(block);
|
|
171
|
+
const ranges = [];
|
|
172
|
+
const statement = /\s*(--[\w-]+\s*:)?/y;
|
|
173
|
+
let i = 0;
|
|
174
|
+
while (i < block.length) {
|
|
175
|
+
statement.lastIndex = i;
|
|
176
|
+
const match = statement.exec(masked);
|
|
177
|
+
i = statement.lastIndex;
|
|
178
|
+
if (match[1]) {
|
|
179
|
+
const raw = block.slice(i);
|
|
180
|
+
i += raw.length - raw.trimStart().length + extractValue(block, i).length;
|
|
181
|
+
while (i < block.length && block[i] !== ";" && block[i] !== "}") i++;
|
|
182
|
+
i++;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
for (let depth = 0; i < block.length; i++) {
|
|
186
|
+
const char = masked[i];
|
|
187
|
+
if (char === "(") depth++;
|
|
188
|
+
else if (char === ")") depth = Math.max(0, depth - 1);
|
|
189
|
+
else if (depth === 0 && (char === ";" || char === "{" || char === "}")) break;
|
|
190
|
+
}
|
|
191
|
+
if (masked[i] === "{") {
|
|
192
|
+
const body = extractBlock(block, i + 1);
|
|
193
|
+
ranges.push([i + 1, i + 1 + body.length]);
|
|
194
|
+
i += body.length + 1;
|
|
195
|
+
}
|
|
196
|
+
i++;
|
|
197
|
+
}
|
|
198
|
+
return ranges;
|
|
199
|
+
}
|
|
200
|
+
function forEachOwnProperty(block, onProperty, offset = 0) {
|
|
201
|
+
const nested = nestedRanges(block);
|
|
202
|
+
forEachProperty(block, (name, value, position) => {
|
|
203
|
+
if (!inRanges(nested, position - offset)) onProperty(name, value, position);
|
|
204
|
+
}, offset);
|
|
205
|
+
}
|
|
206
|
+
function conditionalRanges(stripped) {
|
|
207
|
+
const masked = maskQuotedContent(stripped);
|
|
208
|
+
const ranges = [];
|
|
209
|
+
const openRegex = /@(?:media|supports|container)\b[^{;]*\{/gi;
|
|
210
|
+
let match;
|
|
211
|
+
while (match = openRegex.exec(masked)) {
|
|
212
|
+
const start = match.index + match[0].length;
|
|
213
|
+
ranges.push([start, start + extractBlock(stripped, start).length]);
|
|
214
|
+
}
|
|
215
|
+
return ranges;
|
|
216
|
+
}
|
|
156
217
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
157
218
|
for (const sel of selectors) {
|
|
158
219
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -169,19 +230,35 @@ function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
|
169
230
|
}
|
|
170
231
|
var BASE_SELECTORS = [":root", "@theme"];
|
|
171
232
|
function scanDeclarations(css, selectors, onProperty, skip = [], stripped = stripComments(css)) {
|
|
233
|
+
const conditional = conditionalRanges(stripped);
|
|
172
234
|
forEachSelectorBlock(stripped, [...BASE_SELECTORS, ...selectors ?? []], (block, [bodyStart]) => {
|
|
173
|
-
|
|
174
|
-
forEachProperty(block,
|
|
235
|
+
const nested = nestedRanges(block);
|
|
236
|
+
forEachProperty(block, (name, value, position) => {
|
|
237
|
+
if (inRanges(skip, position)) return;
|
|
238
|
+
onProperty(name, value, position, inRanges(conditional, position) || inRanges(nested, position - bodyStart));
|
|
239
|
+
}, bodyStart);
|
|
175
240
|
});
|
|
176
241
|
}
|
|
242
|
+
function makeDeclarationCollector() {
|
|
243
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
244
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
245
|
+
const add = (name, value, isConditional) => {
|
|
246
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) return false;
|
|
247
|
+
declarations.set(name, value);
|
|
248
|
+
if (isConditional) conditional.add(name);
|
|
249
|
+
else conditional.delete(name);
|
|
250
|
+
return true;
|
|
251
|
+
};
|
|
252
|
+
return { declarations, conditional, add };
|
|
253
|
+
}
|
|
177
254
|
function parseVarNames(css, selectors) {
|
|
178
255
|
const names = /* @__PURE__ */ new Set();
|
|
179
256
|
scanDeclarations(css, selectors, (name) => names.add(name));
|
|
180
257
|
return [...names];
|
|
181
258
|
}
|
|
182
259
|
function parseVarDeclarations(css, selectors) {
|
|
183
|
-
const declarations
|
|
184
|
-
scanDeclarations(css, selectors, (name, value) =>
|
|
260
|
+
const { declarations, add } = makeDeclarationCollector();
|
|
261
|
+
scanDeclarations(css, selectors, (name, value, _position, conditional) => add(name, value, conditional));
|
|
185
262
|
return declarations;
|
|
186
263
|
}
|
|
187
264
|
var normalizePrelude = (prelude) => prelude.replace(/\s+/g, "").toLowerCase();
|
|
@@ -239,15 +316,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
239
316
|
for (const [themeName, themeSelector] of Object.entries(themes)) {
|
|
240
317
|
const values = /* @__PURE__ */ new Map();
|
|
241
318
|
themeValues.set(themeName, values);
|
|
242
|
-
const
|
|
319
|
+
const onProperty = (name, value, position) => {
|
|
243
320
|
values.set(name, value);
|
|
244
321
|
const doc = docAt(position);
|
|
245
322
|
if (doc) themeDocs.set(name, doc);
|
|
246
|
-
}
|
|
323
|
+
};
|
|
324
|
+
const collect = (block, offset) => forEachProperty(block, onProperty, offset);
|
|
247
325
|
const selector = themeSelector.trim();
|
|
248
326
|
if (/^@media\b/i.test(selector)) {
|
|
249
327
|
forEachMediaBlock(stripped, selector, (mediaBlock, range) => {
|
|
250
328
|
skip.push(range);
|
|
329
|
+
forEachOwnProperty(mediaBlock, onProperty, range[0]);
|
|
251
330
|
forEachSelectorBlock(mediaBlock, BASE_SELECTORS, (block, [innerStart]) => collect(block, range[0] + innerStart));
|
|
252
331
|
});
|
|
253
332
|
} else {
|
|
@@ -257,17 +336,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
257
336
|
});
|
|
258
337
|
}
|
|
259
338
|
}
|
|
260
|
-
const declarations
|
|
339
|
+
const { declarations, conditional, add } = makeDeclarationCollector();
|
|
261
340
|
const docs = /* @__PURE__ */ new Map();
|
|
262
|
-
scanDeclarations(css, selectors, (name, value, position) => {
|
|
263
|
-
|
|
341
|
+
scanDeclarations(css, selectors, (name, value, position, isConditional) => {
|
|
342
|
+
if (!add(name, value, isConditional)) return;
|
|
264
343
|
const doc = docAt(position);
|
|
265
344
|
if (doc) docs.set(name, doc);
|
|
266
345
|
}, skip, stripped);
|
|
267
346
|
for (const [name, doc] of themeDocs) {
|
|
268
347
|
if (!docs.has(name)) docs.set(name, doc);
|
|
269
348
|
}
|
|
270
|
-
return { declarations, themes: themeValues, docs };
|
|
349
|
+
return { declarations, conditional, themes: themeValues, docs };
|
|
271
350
|
}
|
|
272
351
|
var PROPERTY_DESCRIPTORS = [
|
|
273
352
|
["syntax", "syntax"],
|
|
@@ -306,13 +385,14 @@ function toRawPosition(stripped, strippedPos) {
|
|
|
306
385
|
}
|
|
307
386
|
return rawPos;
|
|
308
387
|
}
|
|
388
|
+
var CSS_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(?:(,)|\))/gi;
|
|
309
389
|
function parseVarReferences(css) {
|
|
310
390
|
const stripped = stripCommentsWithMap(css);
|
|
311
391
|
const masked = maskQuotedContent(stripped.text);
|
|
312
392
|
const lineStarts = [0];
|
|
313
393
|
for (let i = 0; i < css.length; i++) if (css[i] === "\n") lineStarts.push(i + 1);
|
|
314
394
|
const refs = [];
|
|
315
|
-
for (const match of masked.matchAll(
|
|
395
|
+
for (const match of masked.matchAll(CSS_REF_RE)) {
|
|
316
396
|
const rawPos = toRawPosition(stripped, match.index);
|
|
317
397
|
let line = lineStarts.length - 1;
|
|
318
398
|
while (lineStarts[line] > rawPos) line--;
|
|
@@ -320,7 +400,7 @@ function parseVarReferences(css) {
|
|
|
320
400
|
}
|
|
321
401
|
return refs;
|
|
322
402
|
}
|
|
323
|
-
var SOURCE_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(,)
|
|
403
|
+
var SOURCE_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(?:(,)|\))|(?<=[\w-]-)\((?:[\w-]+:)?(--[\w-]+)\)/g;
|
|
324
404
|
function parseSourceVarReferences(text) {
|
|
325
405
|
const lineStarts = [0];
|
|
326
406
|
for (let i = 0; i < text.length; i++) if (text[i] === "\n") lineStarts.push(i + 1);
|
|
@@ -346,7 +426,7 @@ function parseSourceDeclaredNames(text) {
|
|
|
346
426
|
function parseDeclaredNames(css) {
|
|
347
427
|
const masked = maskQuotedContent(stripComments(css));
|
|
348
428
|
const names = /* @__PURE__ */ new Set();
|
|
349
|
-
for (const match of masked.matchAll(/(?<![\w
|
|
429
|
+
for (const match of masked.matchAll(/(?<![\w&-])(--[\w-]+)\s*:/g)) names.add(match[1]);
|
|
350
430
|
for (const match of masked.matchAll(/@property\s+(--[\w-]+)/g)) names.add(match[1]);
|
|
351
431
|
return names;
|
|
352
432
|
}
|
|
@@ -393,9 +473,13 @@ async function findFiles(patterns, exclude) {
|
|
|
393
473
|
return [...new Set(files.reverse())].reverse();
|
|
394
474
|
}
|
|
395
475
|
function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
396
|
-
const compile = (globs) => picomatch(
|
|
397
|
-
const
|
|
398
|
-
const
|
|
476
|
+
const compile = (globs) => picomatch(globs.map((p) => p.replace(/^\.\//, "")));
|
|
477
|
+
const normalized = normalizePatterns(patterns);
|
|
478
|
+
const include = compile(normalized.filter((p) => !p.startsWith("!")));
|
|
479
|
+
const ignore = compile([
|
|
480
|
+
...exclude ? normalizePatterns(exclude) : [],
|
|
481
|
+
...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
|
|
482
|
+
]);
|
|
399
483
|
return (file) => {
|
|
400
484
|
const absolute = resolve(cwd, file).replace(/\\/g, "/");
|
|
401
485
|
const fromCwd = relative(cwd, absolute).replace(/\\/g, "/");
|
|
@@ -406,6 +490,7 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
|
406
490
|
function globWatchRoots(patterns, cwd = process.cwd()) {
|
|
407
491
|
const roots = /* @__PURE__ */ new Map();
|
|
408
492
|
for (const pattern of normalizePatterns(patterns)) {
|
|
493
|
+
if (pattern.startsWith("!")) continue;
|
|
409
494
|
const { base, glob: glob2, isGlob } = picomatch.scan(pattern);
|
|
410
495
|
const dir = resolve(cwd, isGlob ? base || "." : dirname2(pattern));
|
|
411
496
|
const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
|
|
@@ -440,12 +525,19 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
440
525
|
})
|
|
441
526
|
);
|
|
442
527
|
const declarations = /* @__PURE__ */ new Map();
|
|
528
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
443
529
|
const properties = /* @__PURE__ */ new Map();
|
|
444
530
|
const themeValues = new Map(Object.keys(themes).map((theme) => [theme, /* @__PURE__ */ new Map()]));
|
|
445
531
|
const docs = /* @__PURE__ */ new Map();
|
|
446
532
|
for (const result of perFile) {
|
|
447
533
|
if (!result) continue;
|
|
448
|
-
for (const [name, value] of result.declarations)
|
|
534
|
+
for (const [name, value] of result.declarations) {
|
|
535
|
+
const isConditional = result.conditional.has(name);
|
|
536
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) continue;
|
|
537
|
+
declarations.set(name, value);
|
|
538
|
+
if (isConditional) conditional.add(name);
|
|
539
|
+
else conditional.delete(name);
|
|
540
|
+
}
|
|
449
541
|
for (const [name, rule] of result.properties) properties.set(name, rule);
|
|
450
542
|
for (const [name, doc] of result.docs) docs.set(name, doc);
|
|
451
543
|
for (const [theme, values] of result.themes) {
|
|
@@ -473,19 +565,46 @@ function rootPattern(text) {
|
|
|
473
565
|
const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
|
|
474
566
|
return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
|
|
475
567
|
}
|
|
476
|
-
var ACCESS_RE = /\s*(
|
|
568
|
+
var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
|
|
477
569
|
function readAccess(text, from) {
|
|
478
570
|
ACCESS_RE.lastIndex = from;
|
|
479
571
|
const match = ACCESS_RE.exec(text);
|
|
480
572
|
return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
|
|
481
573
|
}
|
|
574
|
+
var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
|
|
575
|
+
function readPatternKeys(text, at) {
|
|
576
|
+
let i = at - 1;
|
|
577
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
578
|
+
if (text[i] !== "=") return [];
|
|
579
|
+
i--;
|
|
580
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
581
|
+
if (text[i] !== "}") return [];
|
|
582
|
+
const open = text.lastIndexOf("{", i);
|
|
583
|
+
if (open === -1) return [];
|
|
584
|
+
const body = text.slice(open + 1, i);
|
|
585
|
+
if (body.includes("}")) return [];
|
|
586
|
+
const keys = [];
|
|
587
|
+
for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
|
|
588
|
+
const match = PATTERN_KEY_RE.exec(part);
|
|
589
|
+
if (match) keys.push(match[1] ?? match[3]);
|
|
590
|
+
}
|
|
591
|
+
return keys;
|
|
592
|
+
}
|
|
482
593
|
function extractUsage(text, into) {
|
|
483
594
|
for (const root of text.matchAll(rootPattern(text))) {
|
|
484
595
|
const first = readAccess(text, root.index + root[0].length);
|
|
485
|
-
|
|
596
|
+
const second = first && readAccess(text, first.end);
|
|
597
|
+
const destructured = second ? [] : readPatternKeys(text, root.index);
|
|
598
|
+
if (!first) {
|
|
599
|
+
for (const key of destructured) {
|
|
600
|
+
into.keys.add(key);
|
|
601
|
+
into.wholeKeys.add(key);
|
|
602
|
+
}
|
|
603
|
+
continue;
|
|
604
|
+
}
|
|
486
605
|
into.keys.add(first.key);
|
|
487
|
-
const second = readAccess(text, first.end);
|
|
488
606
|
if (second) into.paths.add(`${first.key}\0${second.key}`);
|
|
607
|
+
else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
|
|
489
608
|
else into.wholeKeys.add(first.key);
|
|
490
609
|
}
|
|
491
610
|
}
|