css-typed-vars 0.13.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -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) or `cssVars['<key>']`/`cssVars["<key>"]` (bracket access) usage and compare that against the generated keys. This is a textual scan, not a full parser, so it has limitations worth knowing:
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.
@@ -12,7 +12,7 @@ import {
12
12
  scanUsage,
13
13
  warnOnCollisions,
14
14
  writeOutput
15
- } from "./chunk-XSFYQPH6.js";
15
+ } from "./chunk-L2T4LBKN.js";
16
16
 
17
17
  // src/unplugin.ts
18
18
  import { createUnplugin } from "unplugin";
@@ -11,7 +11,7 @@ import {
11
11
  scanUsage,
12
12
  warnOnCollisions,
13
13
  writeOutput
14
- } from "./chunk-XSFYQPH6.js";
14
+ } from "./chunk-L2T4LBKN.js";
15
15
 
16
16
  // src/index.ts
17
17
  import { readFile } from "fs/promises";
@@ -145,9 +145,10 @@ function extractValue(text, start) {
145
145
  return text.slice(start, i).trim();
146
146
  }
147
147
  var IMPORTANT = /\s*!\s*important$/i;
148
+ var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
148
149
  function forEachProperty(block, onProperty, offset = 0) {
149
150
  const masked = maskQuotedContent(block);
150
- for (const prop of masked.matchAll(/--[\w-]+(?=\s*:)/g)) {
151
+ for (const prop of masked.matchAll(DECLARATION_NAME)) {
151
152
  const name = prop[0];
152
153
  const colonIndex = block.indexOf(":", prop.index + name.length);
153
154
  onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
@@ -306,13 +307,14 @@ function toRawPosition(stripped, strippedPos) {
306
307
  }
307
308
  return rawPos;
308
309
  }
310
+ var CSS_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(?:(,)|\))/gi;
309
311
  function parseVarReferences(css) {
310
312
  const stripped = stripCommentsWithMap(css);
311
313
  const masked = maskQuotedContent(stripped.text);
312
314
  const lineStarts = [0];
313
315
  for (let i = 0; i < css.length; i++) if (css[i] === "\n") lineStarts.push(i + 1);
314
316
  const refs = [];
315
- for (const match of masked.matchAll(/\bvar\(\s*(--[\w-]+)\s*(,)?/gi)) {
317
+ for (const match of masked.matchAll(CSS_REF_RE)) {
316
318
  const rawPos = toRawPosition(stripped, match.index);
317
319
  let line = lineStarts.length - 1;
318
320
  while (lineStarts[line] > rawPos) line--;
@@ -320,7 +322,7 @@ function parseVarReferences(css) {
320
322
  }
321
323
  return refs;
322
324
  }
323
- var SOURCE_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(,)?|(?<=[\w-]-)\((?:[\w-]+:)?(--[\w-]+)\)/g;
325
+ var SOURCE_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(?:(,)|\))|(?<=[\w-]-)\((?:[\w-]+:)?(--[\w-]+)\)/g;
324
326
  function parseSourceVarReferences(text) {
325
327
  const lineStarts = [0];
326
328
  for (let i = 0; i < text.length; i++) if (text[i] === "\n") lineStarts.push(i + 1);
@@ -346,7 +348,7 @@ function parseSourceDeclaredNames(text) {
346
348
  function parseDeclaredNames(css) {
347
349
  const masked = maskQuotedContent(stripComments(css));
348
350
  const names = /* @__PURE__ */ new Set();
349
- for (const match of masked.matchAll(/(?<![\w-])(--[\w-]+)\s*:/g)) names.add(match[1]);
351
+ for (const match of masked.matchAll(/(?<![\w&-])(--[\w-]+)\s*:/g)) names.add(match[1]);
350
352
  for (const match of masked.matchAll(/@property\s+(--[\w-]+)/g)) names.add(match[1]);
351
353
  return names;
352
354
  }
@@ -473,19 +475,46 @@ function rootPattern(text) {
473
475
  const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
474
476
  return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
475
477
  }
476
- var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
478
+ var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
477
479
  function readAccess(text, from) {
478
480
  ACCESS_RE.lastIndex = from;
479
481
  const match = ACCESS_RE.exec(text);
480
482
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
481
483
  }
484
+ var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
485
+ function readPatternKeys(text, at) {
486
+ let i = at - 1;
487
+ while (i >= 0 && /\s/.test(text[i])) i--;
488
+ if (text[i] !== "=") return [];
489
+ i--;
490
+ while (i >= 0 && /\s/.test(text[i])) i--;
491
+ if (text[i] !== "}") return [];
492
+ const open = text.lastIndexOf("{", i);
493
+ if (open === -1) return [];
494
+ const body = text.slice(open + 1, i);
495
+ if (body.includes("}")) return [];
496
+ const keys = [];
497
+ for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
498
+ const match = PATTERN_KEY_RE.exec(part);
499
+ if (match) keys.push(match[1] ?? match[3]);
500
+ }
501
+ return keys;
502
+ }
482
503
  function extractUsage(text, into) {
483
504
  for (const root of text.matchAll(rootPattern(text))) {
484
505
  const first = readAccess(text, root.index + root[0].length);
485
- if (!first) continue;
506
+ const second = first && readAccess(text, first.end);
507
+ const destructured = second ? [] : readPatternKeys(text, root.index);
508
+ if (!first) {
509
+ for (const key of destructured) {
510
+ into.keys.add(key);
511
+ into.wholeKeys.add(key);
512
+ }
513
+ continue;
514
+ }
486
515
  into.keys.add(first.key);
487
- const second = readAccess(text, first.end);
488
516
  if (second) into.paths.add(`${first.key}\0${second.key}`);
517
+ else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
489
518
  else into.wholeKeys.add(first.key);
490
519
  }
491
520
  }
package/dist/cli.cjs CHANGED
@@ -168,9 +168,10 @@ function extractValue(text, start) {
168
168
  return text.slice(start, i).trim();
169
169
  }
170
170
  var IMPORTANT = /\s*!\s*important$/i;
171
+ var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
171
172
  function forEachProperty(block, onProperty, offset = 0) {
172
173
  const masked = maskQuotedContent(block);
173
- for (const prop of masked.matchAll(/--[\w-]+(?=\s*:)/g)) {
174
+ for (const prop of masked.matchAll(DECLARATION_NAME)) {
174
175
  const name = prop[0];
175
176
  const colonIndex = block.indexOf(":", prop.index + name.length);
176
177
  onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
@@ -319,13 +320,14 @@ function toRawPosition(stripped, strippedPos) {
319
320
  }
320
321
  return rawPos;
321
322
  }
323
+ var CSS_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(?:(,)|\))/gi;
322
324
  function parseVarReferences(css) {
323
325
  const stripped = stripCommentsWithMap(css);
324
326
  const masked = maskQuotedContent(stripped.text);
325
327
  const lineStarts = [0];
326
328
  for (let i = 0; i < css.length; i++) if (css[i] === "\n") lineStarts.push(i + 1);
327
329
  const refs = [];
328
- for (const match of masked.matchAll(/\bvar\(\s*(--[\w-]+)\s*(,)?/gi)) {
330
+ for (const match of masked.matchAll(CSS_REF_RE)) {
329
331
  const rawPos = toRawPosition(stripped, match.index);
330
332
  let line = lineStarts.length - 1;
331
333
  while (lineStarts[line] > rawPos) line--;
@@ -333,7 +335,7 @@ function parseVarReferences(css) {
333
335
  }
334
336
  return refs;
335
337
  }
336
- var SOURCE_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(,)?|(?<=[\w-]-)\((?:[\w-]+:)?(--[\w-]+)\)/g;
338
+ var SOURCE_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(?:(,)|\))|(?<=[\w-]-)\((?:[\w-]+:)?(--[\w-]+)\)/g;
337
339
  function parseSourceVarReferences(text) {
338
340
  const lineStarts = [0];
339
341
  for (let i = 0; i < text.length; i++) if (text[i] === "\n") lineStarts.push(i + 1);
@@ -359,7 +361,7 @@ function parseSourceDeclaredNames(text) {
359
361
  function parseDeclaredNames(css) {
360
362
  const masked = maskQuotedContent(stripComments(css));
361
363
  const names = /* @__PURE__ */ new Set();
362
- for (const match of masked.matchAll(/(?<![\w-])(--[\w-]+)\s*:/g)) names.add(match[1]);
364
+ for (const match of masked.matchAll(/(?<![\w&-])(--[\w-]+)\s*:/g)) names.add(match[1]);
363
365
  for (const match of masked.matchAll(/@property\s+(--[\w-]+)/g)) names.add(match[1]);
364
366
  return names;
365
367
  }
@@ -472,19 +474,46 @@ function rootPattern(text) {
472
474
  const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
473
475
  return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
474
476
  }
475
- var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
477
+ var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
476
478
  function readAccess(text, from) {
477
479
  ACCESS_RE.lastIndex = from;
478
480
  const match = ACCESS_RE.exec(text);
479
481
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
480
482
  }
483
+ var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
484
+ function readPatternKeys(text, at) {
485
+ let i = at - 1;
486
+ while (i >= 0 && /\s/.test(text[i])) i--;
487
+ if (text[i] !== "=") return [];
488
+ i--;
489
+ while (i >= 0 && /\s/.test(text[i])) i--;
490
+ if (text[i] !== "}") return [];
491
+ const open = text.lastIndexOf("{", i);
492
+ if (open === -1) return [];
493
+ const body = text.slice(open + 1, i);
494
+ if (body.includes("}")) return [];
495
+ const keys = [];
496
+ for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
497
+ const match = PATTERN_KEY_RE.exec(part);
498
+ if (match) keys.push(match[1] ?? match[3]);
499
+ }
500
+ return keys;
501
+ }
481
502
  function extractUsage(text, into) {
482
503
  for (const root of text.matchAll(rootPattern(text))) {
483
504
  const first = readAccess(text, root.index + root[0].length);
484
- if (!first) continue;
505
+ const second = first && readAccess(text, first.end);
506
+ const destructured = second ? [] : readPatternKeys(text, root.index);
507
+ if (!first) {
508
+ for (const key of destructured) {
509
+ into.keys.add(key);
510
+ into.wholeKeys.add(key);
511
+ }
512
+ continue;
513
+ }
485
514
  into.keys.add(first.key);
486
- const second = readAccess(text, first.end);
487
515
  if (second) into.paths.add(`${first.key}\0${second.key}`);
516
+ else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
488
517
  else into.wholeKeys.add(first.key);
489
518
  }
490
519
  }
package/dist/cli.js CHANGED
@@ -4,12 +4,12 @@ import {
4
4
  findUndefinedRefs,
5
5
  findUnusedVars,
6
6
  generate
7
- } from "./chunk-FWKCSH2F.js";
7
+ } from "./chunk-DIGUOQES.js";
8
8
  import {
9
9
  VALID_NAMINGS,
10
10
  createFileMatcher,
11
11
  globWatchRoots
12
- } from "./chunk-XSFYQPH6.js";
12
+ } from "./chunk-L2T4LBKN.js";
13
13
 
14
14
  // src/cli.ts
15
15
  import { access, readFile } from "fs/promises";
package/dist/esbuild.cjs CHANGED
@@ -186,9 +186,10 @@ function extractValue(text, start) {
186
186
  return text.slice(start, i).trim();
187
187
  }
188
188
  var IMPORTANT = /\s*!\s*important$/i;
189
+ var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
189
190
  function forEachProperty(block, onProperty, offset = 0) {
190
191
  const masked = maskQuotedContent(block);
191
- for (const prop of masked.matchAll(/--[\w-]+(?=\s*:)/g)) {
192
+ for (const prop of masked.matchAll(DECLARATION_NAME)) {
192
193
  const name = prop[0];
193
194
  const colonIndex = block.indexOf(":", prop.index + name.length);
194
195
  onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
@@ -449,19 +450,46 @@ function rootPattern(text) {
449
450
  const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
450
451
  return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
451
452
  }
452
- var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
453
+ var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
453
454
  function readAccess(text, from) {
454
455
  ACCESS_RE.lastIndex = from;
455
456
  const match = ACCESS_RE.exec(text);
456
457
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
457
458
  }
459
+ var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
460
+ function readPatternKeys(text, at) {
461
+ let i = at - 1;
462
+ while (i >= 0 && /\s/.test(text[i])) i--;
463
+ if (text[i] !== "=") return [];
464
+ i--;
465
+ while (i >= 0 && /\s/.test(text[i])) i--;
466
+ if (text[i] !== "}") return [];
467
+ const open = text.lastIndexOf("{", i);
468
+ if (open === -1) return [];
469
+ const body = text.slice(open + 1, i);
470
+ if (body.includes("}")) return [];
471
+ const keys = [];
472
+ for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
473
+ const match = PATTERN_KEY_RE.exec(part);
474
+ if (match) keys.push(match[1] ?? match[3]);
475
+ }
476
+ return keys;
477
+ }
458
478
  function extractUsage(text, into) {
459
479
  for (const root of text.matchAll(rootPattern(text))) {
460
480
  const first = readAccess(text, root.index + root[0].length);
461
- if (!first) continue;
481
+ const second = first && readAccess(text, first.end);
482
+ const destructured = second ? [] : readPatternKeys(text, root.index);
483
+ if (!first) {
484
+ for (const key of destructured) {
485
+ into.keys.add(key);
486
+ into.wholeKeys.add(key);
487
+ }
488
+ continue;
489
+ }
462
490
  into.keys.add(first.key);
463
- const second = readAccess(text, first.end);
464
491
  if (second) into.paths.add(`${first.key}\0${second.key}`);
492
+ else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
465
493
  else into.wholeKeys.add(first.key);
466
494
  }
467
495
  }
package/dist/esbuild.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-JGJ53FND.js";
4
- import "./chunk-XSFYQPH6.js";
3
+ } from "./chunk-3QCGO2EN.js";
4
+ import "./chunk-L2T4LBKN.js";
5
5
 
6
6
  // src/esbuild.ts
7
7
  var esbuild_default = unplugin_default.esbuild;
package/dist/index.cjs CHANGED
@@ -201,9 +201,10 @@ function extractValue(text, start) {
201
201
  return text.slice(start, i).trim();
202
202
  }
203
203
  var IMPORTANT = /\s*!\s*important$/i;
204
+ var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
204
205
  function forEachProperty(block, onProperty, offset = 0) {
205
206
  const masked = maskQuotedContent(block);
206
- for (const prop of masked.matchAll(/--[\w-]+(?=\s*:)/g)) {
207
+ for (const prop of masked.matchAll(DECLARATION_NAME)) {
207
208
  const name = prop[0];
208
209
  const colonIndex = block.indexOf(":", prop.index + name.length);
209
210
  onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
@@ -362,13 +363,14 @@ function toRawPosition(stripped, strippedPos) {
362
363
  }
363
364
  return rawPos;
364
365
  }
366
+ var CSS_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(?:(,)|\))/gi;
365
367
  function parseVarReferences(css) {
366
368
  const stripped = stripCommentsWithMap(css);
367
369
  const masked = maskQuotedContent(stripped.text);
368
370
  const lineStarts = [0];
369
371
  for (let i = 0; i < css.length; i++) if (css[i] === "\n") lineStarts.push(i + 1);
370
372
  const refs = [];
371
- for (const match of masked.matchAll(/\bvar\(\s*(--[\w-]+)\s*(,)?/gi)) {
373
+ for (const match of masked.matchAll(CSS_REF_RE)) {
372
374
  const rawPos = toRawPosition(stripped, match.index);
373
375
  let line = lineStarts.length - 1;
374
376
  while (lineStarts[line] > rawPos) line--;
@@ -376,7 +378,7 @@ function parseVarReferences(css) {
376
378
  }
377
379
  return refs;
378
380
  }
379
- var SOURCE_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(,)?|(?<=[\w-]-)\((?:[\w-]+:)?(--[\w-]+)\)/g;
381
+ var SOURCE_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(?:(,)|\))|(?<=[\w-]-)\((?:[\w-]+:)?(--[\w-]+)\)/g;
380
382
  function parseSourceVarReferences(text) {
381
383
  const lineStarts = [0];
382
384
  for (let i = 0; i < text.length; i++) if (text[i] === "\n") lineStarts.push(i + 1);
@@ -402,7 +404,7 @@ function parseSourceDeclaredNames(text) {
402
404
  function parseDeclaredNames(css) {
403
405
  const masked = maskQuotedContent(stripComments(css));
404
406
  const names = /* @__PURE__ */ new Set();
405
- for (const match of masked.matchAll(/(?<![\w-])(--[\w-]+)\s*:/g)) names.add(match[1]);
407
+ for (const match of masked.matchAll(/(?<![\w&-])(--[\w-]+)\s*:/g)) names.add(match[1]);
406
408
  for (const match of masked.matchAll(/@property\s+(--[\w-]+)/g)) names.add(match[1]);
407
409
  return names;
408
410
  }
@@ -499,19 +501,46 @@ function rootPattern(text) {
499
501
  const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
500
502
  return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
501
503
  }
502
- var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
504
+ var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
503
505
  function readAccess(text, from) {
504
506
  ACCESS_RE.lastIndex = from;
505
507
  const match = ACCESS_RE.exec(text);
506
508
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
507
509
  }
510
+ var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
511
+ function readPatternKeys(text, at) {
512
+ let i = at - 1;
513
+ while (i >= 0 && /\s/.test(text[i])) i--;
514
+ if (text[i] !== "=") return [];
515
+ i--;
516
+ while (i >= 0 && /\s/.test(text[i])) i--;
517
+ if (text[i] !== "}") return [];
518
+ const open = text.lastIndexOf("{", i);
519
+ if (open === -1) return [];
520
+ const body = text.slice(open + 1, i);
521
+ if (body.includes("}")) return [];
522
+ const keys = [];
523
+ for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
524
+ const match = PATTERN_KEY_RE.exec(part);
525
+ if (match) keys.push(match[1] ?? match[3]);
526
+ }
527
+ return keys;
528
+ }
508
529
  function extractUsage(text, into) {
509
530
  for (const root of text.matchAll(rootPattern(text))) {
510
531
  const first = readAccess(text, root.index + root[0].length);
511
- if (!first) continue;
532
+ const second = first && readAccess(text, first.end);
533
+ const destructured = second ? [] : readPatternKeys(text, root.index);
534
+ if (!first) {
535
+ for (const key of destructured) {
536
+ into.keys.add(key);
537
+ into.wholeKeys.add(key);
538
+ }
539
+ continue;
540
+ }
512
541
  into.keys.add(first.key);
513
- const second = readAccess(text, first.end);
514
542
  if (second) into.paths.add(`${first.key}\0${second.key}`);
543
+ else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
515
544
  else into.wholeKeys.add(first.key);
516
545
  }
517
546
  }
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  findUndefinedRefs,
5
5
  findUnusedVars,
6
6
  generate
7
- } from "./chunk-FWKCSH2F.js";
7
+ } from "./chunk-DIGUOQES.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-XSFYQPH6.js";
24
+ } from "./chunk-L2T4LBKN.js";
25
25
  export {
26
26
  checkGenerated,
27
27
  defineConfig,
package/dist/rollup.cjs CHANGED
@@ -186,9 +186,10 @@ function extractValue(text, start) {
186
186
  return text.slice(start, i).trim();
187
187
  }
188
188
  var IMPORTANT = /\s*!\s*important$/i;
189
+ var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
189
190
  function forEachProperty(block, onProperty, offset = 0) {
190
191
  const masked = maskQuotedContent(block);
191
- for (const prop of masked.matchAll(/--[\w-]+(?=\s*:)/g)) {
192
+ for (const prop of masked.matchAll(DECLARATION_NAME)) {
192
193
  const name = prop[0];
193
194
  const colonIndex = block.indexOf(":", prop.index + name.length);
194
195
  onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
@@ -449,19 +450,46 @@ function rootPattern(text) {
449
450
  const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
450
451
  return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
451
452
  }
452
- var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
453
+ var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
453
454
  function readAccess(text, from) {
454
455
  ACCESS_RE.lastIndex = from;
455
456
  const match = ACCESS_RE.exec(text);
456
457
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
457
458
  }
459
+ var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
460
+ function readPatternKeys(text, at) {
461
+ let i = at - 1;
462
+ while (i >= 0 && /\s/.test(text[i])) i--;
463
+ if (text[i] !== "=") return [];
464
+ i--;
465
+ while (i >= 0 && /\s/.test(text[i])) i--;
466
+ if (text[i] !== "}") return [];
467
+ const open = text.lastIndexOf("{", i);
468
+ if (open === -1) return [];
469
+ const body = text.slice(open + 1, i);
470
+ if (body.includes("}")) return [];
471
+ const keys = [];
472
+ for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
473
+ const match = PATTERN_KEY_RE.exec(part);
474
+ if (match) keys.push(match[1] ?? match[3]);
475
+ }
476
+ return keys;
477
+ }
458
478
  function extractUsage(text, into) {
459
479
  for (const root of text.matchAll(rootPattern(text))) {
460
480
  const first = readAccess(text, root.index + root[0].length);
461
- if (!first) continue;
481
+ const second = first && readAccess(text, first.end);
482
+ const destructured = second ? [] : readPatternKeys(text, root.index);
483
+ if (!first) {
484
+ for (const key of destructured) {
485
+ into.keys.add(key);
486
+ into.wholeKeys.add(key);
487
+ }
488
+ continue;
489
+ }
462
490
  into.keys.add(first.key);
463
- const second = readAccess(text, first.end);
464
491
  if (second) into.paths.add(`${first.key}\0${second.key}`);
492
+ else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
465
493
  else into.wholeKeys.add(first.key);
466
494
  }
467
495
  }
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-JGJ53FND.js";
4
- import "./chunk-XSFYQPH6.js";
3
+ } from "./chunk-3QCGO2EN.js";
4
+ import "./chunk-L2T4LBKN.js";
5
5
 
6
6
  // src/rollup.ts
7
7
  var rollup_default = unplugin_default.rollup;
package/dist/unplugin.cjs CHANGED
@@ -184,9 +184,10 @@ function extractValue(text, start) {
184
184
  return text.slice(start, i).trim();
185
185
  }
186
186
  var IMPORTANT = /\s*!\s*important$/i;
187
+ var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
187
188
  function forEachProperty(block, onProperty, offset = 0) {
188
189
  const masked = maskQuotedContent(block);
189
- for (const prop of masked.matchAll(/--[\w-]+(?=\s*:)/g)) {
190
+ for (const prop of masked.matchAll(DECLARATION_NAME)) {
190
191
  const name = prop[0];
191
192
  const colonIndex = block.indexOf(":", prop.index + name.length);
192
193
  onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
@@ -447,19 +448,46 @@ function rootPattern(text) {
447
448
  const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
448
449
  return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
449
450
  }
450
- var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
451
+ var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
451
452
  function readAccess(text, from) {
452
453
  ACCESS_RE.lastIndex = from;
453
454
  const match = ACCESS_RE.exec(text);
454
455
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
455
456
  }
457
+ var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
458
+ function readPatternKeys(text, at) {
459
+ let i = at - 1;
460
+ while (i >= 0 && /\s/.test(text[i])) i--;
461
+ if (text[i] !== "=") return [];
462
+ i--;
463
+ while (i >= 0 && /\s/.test(text[i])) i--;
464
+ if (text[i] !== "}") return [];
465
+ const open = text.lastIndexOf("{", i);
466
+ if (open === -1) return [];
467
+ const body = text.slice(open + 1, i);
468
+ if (body.includes("}")) return [];
469
+ const keys = [];
470
+ for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
471
+ const match = PATTERN_KEY_RE.exec(part);
472
+ if (match) keys.push(match[1] ?? match[3]);
473
+ }
474
+ return keys;
475
+ }
456
476
  function extractUsage(text, into) {
457
477
  for (const root of text.matchAll(rootPattern(text))) {
458
478
  const first = readAccess(text, root.index + root[0].length);
459
- if (!first) continue;
479
+ const second = first && readAccess(text, first.end);
480
+ const destructured = second ? [] : readPatternKeys(text, root.index);
481
+ if (!first) {
482
+ for (const key of destructured) {
483
+ into.keys.add(key);
484
+ into.wholeKeys.add(key);
485
+ }
486
+ continue;
487
+ }
460
488
  into.keys.add(first.key);
461
- const second = readAccess(text, first.end);
462
489
  if (second) into.paths.add(`${first.key}\0${second.key}`);
490
+ else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
463
491
  else into.wholeKeys.add(first.key);
464
492
  }
465
493
  }
package/dist/unplugin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-JGJ53FND.js";
4
- import "./chunk-XSFYQPH6.js";
3
+ } from "./chunk-3QCGO2EN.js";
4
+ import "./chunk-L2T4LBKN.js";
5
5
  export {
6
6
  unplugin_default as default
7
7
  };
package/dist/vite.cjs CHANGED
@@ -186,9 +186,10 @@ function extractValue(text, start) {
186
186
  return text.slice(start, i).trim();
187
187
  }
188
188
  var IMPORTANT = /\s*!\s*important$/i;
189
+ var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
189
190
  function forEachProperty(block, onProperty, offset = 0) {
190
191
  const masked = maskQuotedContent(block);
191
- for (const prop of masked.matchAll(/--[\w-]+(?=\s*:)/g)) {
192
+ for (const prop of masked.matchAll(DECLARATION_NAME)) {
192
193
  const name = prop[0];
193
194
  const colonIndex = block.indexOf(":", prop.index + name.length);
194
195
  onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
@@ -449,19 +450,46 @@ function rootPattern(text) {
449
450
  const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
450
451
  return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
451
452
  }
452
- var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
453
+ var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
453
454
  function readAccess(text, from) {
454
455
  ACCESS_RE.lastIndex = from;
455
456
  const match = ACCESS_RE.exec(text);
456
457
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
457
458
  }
459
+ var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
460
+ function readPatternKeys(text, at) {
461
+ let i = at - 1;
462
+ while (i >= 0 && /\s/.test(text[i])) i--;
463
+ if (text[i] !== "=") return [];
464
+ i--;
465
+ while (i >= 0 && /\s/.test(text[i])) i--;
466
+ if (text[i] !== "}") return [];
467
+ const open = text.lastIndexOf("{", i);
468
+ if (open === -1) return [];
469
+ const body = text.slice(open + 1, i);
470
+ if (body.includes("}")) return [];
471
+ const keys = [];
472
+ for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
473
+ const match = PATTERN_KEY_RE.exec(part);
474
+ if (match) keys.push(match[1] ?? match[3]);
475
+ }
476
+ return keys;
477
+ }
458
478
  function extractUsage(text, into) {
459
479
  for (const root of text.matchAll(rootPattern(text))) {
460
480
  const first = readAccess(text, root.index + root[0].length);
461
- if (!first) continue;
481
+ const second = first && readAccess(text, first.end);
482
+ const destructured = second ? [] : readPatternKeys(text, root.index);
483
+ if (!first) {
484
+ for (const key of destructured) {
485
+ into.keys.add(key);
486
+ into.wholeKeys.add(key);
487
+ }
488
+ continue;
489
+ }
462
490
  into.keys.add(first.key);
463
- const second = readAccess(text, first.end);
464
491
  if (second) into.paths.add(`${first.key}\0${second.key}`);
492
+ else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
465
493
  else into.wholeKeys.add(first.key);
466
494
  }
467
495
  }
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-JGJ53FND.js";
4
- import "./chunk-XSFYQPH6.js";
3
+ } from "./chunk-3QCGO2EN.js";
4
+ import "./chunk-L2T4LBKN.js";
5
5
 
6
6
  // src/vite.ts
7
7
  var vite_default = unplugin_default.vite;
package/dist/webpack.cjs CHANGED
@@ -186,9 +186,10 @@ function extractValue(text, start) {
186
186
  return text.slice(start, i).trim();
187
187
  }
188
188
  var IMPORTANT = /\s*!\s*important$/i;
189
+ var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
189
190
  function forEachProperty(block, onProperty, offset = 0) {
190
191
  const masked = maskQuotedContent(block);
191
- for (const prop of masked.matchAll(/--[\w-]+(?=\s*:)/g)) {
192
+ for (const prop of masked.matchAll(DECLARATION_NAME)) {
192
193
  const name = prop[0];
193
194
  const colonIndex = block.indexOf(":", prop.index + name.length);
194
195
  onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
@@ -449,19 +450,46 @@ function rootPattern(text) {
449
450
  const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
450
451
  return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
451
452
  }
452
- var ACCESS_RE = /\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
453
+ var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
453
454
  function readAccess(text, from) {
454
455
  ACCESS_RE.lastIndex = from;
455
456
  const match = ACCESS_RE.exec(text);
456
457
  return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
457
458
  }
459
+ var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
460
+ function readPatternKeys(text, at) {
461
+ let i = at - 1;
462
+ while (i >= 0 && /\s/.test(text[i])) i--;
463
+ if (text[i] !== "=") return [];
464
+ i--;
465
+ while (i >= 0 && /\s/.test(text[i])) i--;
466
+ if (text[i] !== "}") return [];
467
+ const open = text.lastIndexOf("{", i);
468
+ if (open === -1) return [];
469
+ const body = text.slice(open + 1, i);
470
+ if (body.includes("}")) return [];
471
+ const keys = [];
472
+ for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
473
+ const match = PATTERN_KEY_RE.exec(part);
474
+ if (match) keys.push(match[1] ?? match[3]);
475
+ }
476
+ return keys;
477
+ }
458
478
  function extractUsage(text, into) {
459
479
  for (const root of text.matchAll(rootPattern(text))) {
460
480
  const first = readAccess(text, root.index + root[0].length);
461
- if (!first) continue;
481
+ const second = first && readAccess(text, first.end);
482
+ const destructured = second ? [] : readPatternKeys(text, root.index);
483
+ if (!first) {
484
+ for (const key of destructured) {
485
+ into.keys.add(key);
486
+ into.wholeKeys.add(key);
487
+ }
488
+ continue;
489
+ }
462
490
  into.keys.add(first.key);
463
- const second = readAccess(text, first.end);
464
491
  if (second) into.paths.add(`${first.key}\0${second.key}`);
492
+ else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
465
493
  else into.wholeKeys.add(first.key);
466
494
  }
467
495
  }
package/dist/webpack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-JGJ53FND.js";
4
- import "./chunk-XSFYQPH6.js";
3
+ } from "./chunk-3QCGO2EN.js";
4
+ import "./chunk-L2T4LBKN.js";
5
5
 
6
6
  // src/webpack.ts
7
7
  var webpack_default = unplugin_default.webpack;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-typed-vars",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "Generate TypeScript typed constants from CSS custom properties",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",