css-typed-vars 0.5.0 → 0.6.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/dist/index.cjs CHANGED
@@ -31,12 +31,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
33
  checkGenerated: () => checkGenerated,
34
+ findUnusedVars: () => findUnusedVars,
34
35
  generate: () => generate,
35
36
  generateCode: () => generateCode,
36
37
  generateDeclaration: () => generateDeclaration,
37
38
  generateJs: () => generateJs,
39
+ parsePropertyRules: () => parsePropertyRules,
38
40
  parseVarDeclarations: () => parseVarDeclarations,
39
41
  parseVarNames: () => parseVarNames,
42
+ scanCss: () => scanCss,
43
+ scanUsedKeys: () => scanUsedKeys,
40
44
  scanVarDeclarations: () => scanVarDeclarations,
41
45
  scanVarNames: () => scanVarNames
42
46
  });
@@ -166,7 +170,7 @@ function extractValue(text, start) {
166
170
  }
167
171
  function scanDeclarations(css, selectors, onProperty) {
168
172
  const stripped = stripComments(css);
169
- const allSelectors = [":root", ...selectors ?? []];
173
+ const allSelectors = [":root", "@theme", ...selectors ?? []];
170
174
  for (const sel of allSelectors) {
171
175
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
172
176
  const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
@@ -194,12 +198,41 @@ function parseVarDeclarations(css, selectors) {
194
198
  scanDeclarations(css, selectors, (name, value) => declarations.set(name, value));
195
199
  return declarations;
196
200
  }
201
+ var PROPERTY_DESCRIPTORS = [
202
+ ["syntax", "syntax"],
203
+ ["inherits", "inherits"],
204
+ ["initial-value", "initialValue"]
205
+ ];
206
+ function parsePropertyRules(css) {
207
+ const stripped = stripComments(css);
208
+ const rules = /* @__PURE__ */ new Map();
209
+ const openRegex = /@property\s+(--[\w-]+)\s*\{/g;
210
+ let match;
211
+ while (match = openRegex.exec(stripped)) {
212
+ const name = match[1];
213
+ const start = match.index + match[0].length;
214
+ const block = extractBlock(stripped, start);
215
+ const masked = maskQuotedContent(block);
216
+ const rule = {};
217
+ for (const [descriptor, key] of PROPERTY_DESCRIPTORS) {
218
+ const descRegex = new RegExp(`(?:^|[;{\\s])${descriptor}(?=\\s*:)`);
219
+ const descMatch = descRegex.exec(masked);
220
+ if (!descMatch) continue;
221
+ const nameEnd = descMatch.index + descMatch[0].length;
222
+ const colonIndex = block.indexOf(":", nameEnd);
223
+ rule[key] = extractValue(block, colonIndex + 1);
224
+ }
225
+ if (Object.keys(rule).length > 0) rules.set(name, rule);
226
+ openRegex.lastIndex = start + block.length + 1;
227
+ }
228
+ return rules;
229
+ }
197
230
 
198
231
  // src/scanner.ts
199
232
  function normalizePatterns(patterns) {
200
233
  return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
201
234
  }
202
- async function scanVarDeclarations(patterns, exclude, selectors) {
235
+ async function scanCss(patterns, exclude, selectors) {
203
236
  const normalized = normalizePatterns(patterns);
204
237
  const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
205
238
  const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
@@ -210,23 +243,56 @@ async function scanVarDeclarations(patterns, exclude, selectors) {
210
243
  css = await (0, import_promises.readFile)(file, "utf8");
211
244
  } catch (err) {
212
245
  console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
213
- return /* @__PURE__ */ new Map();
246
+ return { declarations: /* @__PURE__ */ new Map(), properties: /* @__PURE__ */ new Map() };
214
247
  }
215
- return parseVarDeclarations(css, selectors);
248
+ return { declarations: parseVarDeclarations(css, selectors), properties: parsePropertyRules(css) };
216
249
  })
217
250
  );
218
- const all = /* @__PURE__ */ new Map();
219
- for (const declarations of perFile) {
220
- for (const [name, value] of declarations) {
221
- all.set(name, value);
222
- }
251
+ const declarations = /* @__PURE__ */ new Map();
252
+ const properties = /* @__PURE__ */ new Map();
253
+ for (const result of perFile) {
254
+ for (const [name, value] of result.declarations) declarations.set(name, value);
255
+ for (const [name, rule] of result.properties) properties.set(name, rule);
223
256
  }
224
- return all;
257
+ return { declarations, properties };
258
+ }
259
+ async function scanVarDeclarations(patterns, exclude, selectors) {
260
+ return (await scanCss(patterns, exclude, selectors)).declarations;
225
261
  }
226
262
  async function scanVarNames(patterns, exclude, selectors) {
227
263
  const declarations = await scanVarDeclarations(patterns, exclude, selectors);
228
264
  return [...declarations.keys()].sort();
229
265
  }
266
+ var USAGE_RE = /\bcssVars\s*(?:\.\s*([A-Za-z_$][\w$]*)|\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/g;
267
+ function extractUsedKeys(text, into) {
268
+ for (const match of text.matchAll(USAGE_RE)) {
269
+ into.add(match[1] ?? match[3]);
270
+ }
271
+ }
272
+ async function scanUsedKeys(patterns, exclude) {
273
+ const normalized = normalizePatterns(patterns);
274
+ const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
275
+ const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
276
+ const perFile = await Promise.all(
277
+ files.map(async (file) => {
278
+ const used = /* @__PURE__ */ new Set();
279
+ let text;
280
+ try {
281
+ text = await (0, import_promises.readFile)(file, "utf8");
282
+ } catch (err) {
283
+ console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
284
+ return used;
285
+ }
286
+ extractUsedKeys(text, used);
287
+ return used;
288
+ })
289
+ );
290
+ const all = /* @__PURE__ */ new Set();
291
+ for (const used of perFile) {
292
+ for (const key of used) all.add(key);
293
+ }
294
+ return all;
295
+ }
230
296
 
231
297
  // src/generator.ts
232
298
  var VALID_NAMINGS = ["camelCase", "snake", "kebab", "constant", "pascal"];
@@ -240,10 +306,19 @@ function convertCase(value, naming) {
240
306
  if (naming === "pascal") return value.replace(/(^|-+)([a-z0-9])/g, (_, __, c) => c.toUpperCase()).replace(/-/g, "");
241
307
  return value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
242
308
  }
243
- function toKey(cssVarName, naming = "camelCase") {
244
- const key = convertCase(cssVarName.replace(/^--/, ""), naming);
309
+ function toKeyFragment(fragment, naming = "camelCase") {
310
+ const key = convertCase(fragment, naming);
245
311
  return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
246
312
  }
313
+ function toKey(cssVarName, naming = "camelCase") {
314
+ return toKeyFragment(cssVarName.replace(/^--/, ""), naming);
315
+ }
316
+ function splitGroupKey(cssVarName) {
317
+ const stripped = cssVarName.replace(/^--/, "");
318
+ const dashIndex = stripped.indexOf("-");
319
+ if (dashIndex === -1) return null;
320
+ return { group: stripped.slice(0, dashIndex), rest: stripped.slice(dashIndex + 1) };
321
+ }
247
322
  var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
248
323
  var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
249
324
  var SINGLE_QUOTE_ESCAPES = {};
@@ -276,6 +351,9 @@ function formatKey(key, naming = "camelCase") {
276
351
  if (naming === "kebab") return `'${key}'`;
277
352
  return key;
278
353
  }
354
+ function computeKey(cssVarName, prefix, naming) {
355
+ return applyPrefix(toKey(cssVarName, naming), prefix, naming);
356
+ }
279
357
  function findKeyCollisions(varNames, prefix, naming) {
280
358
  const byKey = /* @__PURE__ */ new Map();
281
359
  for (const name of varNames) {
@@ -294,37 +372,126 @@ function warnOnCollisions(varNames, prefix, naming) {
294
372
  console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
295
373
  }
296
374
  }
297
- function buildEntries(varNames, prefix, naming, declarations) {
375
+ function buildEntries(varNames, prefix, naming, declarations, properties) {
298
376
  const byKey = /* @__PURE__ */ new Map();
299
377
  for (const name of varNames) {
300
378
  const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
301
- byKey.set(key, { name, value: declarations?.get(name) });
379
+ byKey.set(key, { name, value: declarations?.get(name), syntax: properties?.get(name)?.syntax });
302
380
  }
303
381
  return [...byKey].map(([key, entry]) => ({ key, ...entry }));
304
382
  }
305
- function formatDefaultComment(value) {
306
- return ` /** @default ${value.replace(/\*\//g, "*\\/")} */`;
383
+ function buildGroupedEntries(varNames, naming, declarations, properties) {
384
+ const groupMap = /* @__PURE__ */ new Map();
385
+ const ungroupedMap = /* @__PURE__ */ new Map();
386
+ for (const name of varNames) {
387
+ const value = declarations?.get(name);
388
+ const syntax = properties?.get(name)?.syntax;
389
+ const split = splitGroupKey(name);
390
+ if (!split) {
391
+ ungroupedMap.set(formatKey(toKey(name, naming), naming), { name, value, syntax });
392
+ continue;
393
+ }
394
+ const groupKey = formatKey(toKeyFragment(split.group, naming), naming);
395
+ const leafKey = formatKey(toKeyFragment(split.rest, naming), naming);
396
+ let leafMap = groupMap.get(groupKey);
397
+ if (!leafMap) {
398
+ leafMap = /* @__PURE__ */ new Map();
399
+ groupMap.set(groupKey, leafMap);
400
+ }
401
+ leafMap.set(leafKey, { name, value, syntax });
402
+ }
403
+ for (const groupKey of groupMap.keys()) ungroupedMap.delete(groupKey);
404
+ const groups = [...groupMap].map(([key, leafMap]) => ({
405
+ key,
406
+ entries: [...leafMap].map(([key2, entry]) => ({ key: key2, ...entry }))
407
+ }));
408
+ const ungrouped = [...ungroupedMap].map(([key, entry]) => ({ key, ...entry }));
409
+ return { groups, ungrouped };
410
+ }
411
+ function formatDefaultComment(value, indent = " ") {
412
+ return `${indent}/** @default ${value.replace(/\*\//g, "*\\/")} */`;
413
+ }
414
+ function unquoteCssString(value) {
415
+ const quote = value[0];
416
+ if ((quote === '"' || quote === "'") && value[value.length - 1] === quote) {
417
+ return value.slice(1, -1);
418
+ }
419
+ return value;
420
+ }
421
+ function formatSyntaxComment(syntax, indent = " ") {
422
+ return `${indent}/** @syntax ${unquoteCssString(syntax).replace(/\*\//g, "*\\/")} */`;
307
423
  }
308
- function generateCode(varNames, prefix, naming, declarations) {
309
- const entries = buildEntries(varNames, prefix, naming, declarations).flatMap(({ key, name, value }) => [
310
- ...value ? [formatDefaultComment(value)] : [],
311
- ` ${key}: 'var(${name})',`
424
+ var ENUM_SYNTAX_RE = /^[\w-]+(?:\s*\|\s*[\w-]+)+$/;
425
+ function parseEnumSyntax(syntax) {
426
+ const unquoted = unquoteCssString(syntax).trim();
427
+ if (!ENUM_SYNTAX_RE.test(unquoted)) return null;
428
+ return unquoted.split("|").map((v) => v.trim());
429
+ }
430
+ function syntaxTypeName(cssVarName) {
431
+ const pascal = convertCase(cssVarName.replace(/^--/, ""), "pascal");
432
+ return (/^\d/.test(pascal) ? `_${pascal}` : pascal) + "Syntax";
433
+ }
434
+ function buildSyntaxTypes(varNames, properties) {
435
+ if (!properties) return [];
436
+ const byName = /* @__PURE__ */ new Map();
437
+ for (const name of varNames) {
438
+ const values = parseEnumSyntax(properties.get(name)?.syntax ?? "");
439
+ if (values) byName.set(syntaxTypeName(name), values);
440
+ }
441
+ return [...byName].map(([name, values]) => ({ name, values }));
442
+ }
443
+ function renderSyntaxTypeLines(types) {
444
+ return types.map(({ name, values }) => `export type ${name} = ${values.map((v) => `'${escapeSingleQuoted(v)}'`).join(" | ")};`);
445
+ }
446
+ function buildTailBlocks(varNames, group, properties) {
447
+ const blocks = [];
448
+ if (!group) blocks.push(["export type CssVarName = keyof typeof cssVars;"]);
449
+ const syntaxLines = renderSyntaxTypeLines(buildSyntaxTypes(varNames, properties));
450
+ if (syntaxLines.length > 0) blocks.push(syntaxLines);
451
+ return blocks;
452
+ }
453
+ function renderEntryLines(entries, indent, lineFor) {
454
+ return entries.flatMap(({ key, name, value, syntax }) => [
455
+ ...value ? [formatDefaultComment(value, indent)] : [],
456
+ ...syntax ? [formatSyntaxComment(syntax, indent)] : [],
457
+ `${indent}${lineFor(key, name)}`
312
458
  ]);
459
+ }
460
+ function renderGroupedBlock(varNames, naming, declarations, properties, indent, closeSuffix, lineFor) {
461
+ const { groups, ungrouped } = buildGroupedEntries(varNames, naming, declarations, properties);
462
+ const lines = [];
463
+ for (const group of groups) {
464
+ lines.push(`${indent}${group.key}: {`);
465
+ lines.push(...renderEntryLines(group.entries, indent + " ", lineFor));
466
+ lines.push(`${indent}}${closeSuffix}`);
467
+ }
468
+ lines.push(...renderEntryLines(ungrouped, indent, lineFor));
469
+ return lines;
470
+ }
471
+ function assertGroupPrefixCompatible(prefix, group) {
472
+ if (group && prefix) {
473
+ throw new Error('css-typed-vars: the "group" option cannot be combined with "prefix".');
474
+ }
475
+ }
476
+ var codeLineFor = (key, name) => `${key}: 'var(${name})',`;
477
+ var declarationLineFor = (key, name) => `${key}: 'var(${name})';`;
478
+ function generateCode(varNames, prefix, naming, declarations, group, properties) {
479
+ assertGroupPrefixCompatible(prefix, group);
480
+ const entries = group ? renderGroupedBlock(varNames, naming, declarations, properties, " ", ",", codeLineFor) : renderEntryLines(buildEntries(varNames, prefix, naming, declarations, properties), " ", codeLineFor);
481
+ const blocks = buildTailBlocks(varNames, group, properties);
482
+ const tailBody = blocks.flatMap((block, i) => i === 0 ? block : ["", ...block]);
313
483
  return [
314
484
  "// generated \u2014 do not edit",
315
485
  "export const cssVars = {",
316
486
  ...entries,
317
487
  "} as const;",
318
- "",
319
- "export type CssVarName = keyof typeof cssVars;",
488
+ ...tailBody.length > 0 ? ["", ...tailBody] : [],
320
489
  ""
321
490
  ].join("\n");
322
491
  }
323
- function generateJs(varNames, prefix, naming, declarations) {
324
- const entries = buildEntries(varNames, prefix, naming, declarations).flatMap(({ key, name, value }) => [
325
- ...value ? [formatDefaultComment(value)] : [],
326
- ` ${key}: 'var(${name})',`
327
- ]);
492
+ function generateJs(varNames, prefix, naming, declarations, group, properties) {
493
+ assertGroupPrefixCompatible(prefix, group);
494
+ const entries = group ? renderGroupedBlock(varNames, naming, declarations, properties, " ", ",", codeLineFor) : renderEntryLines(buildEntries(varNames, prefix, naming, declarations, properties), " ", codeLineFor);
328
495
  return [
329
496
  "// generated \u2014 do not edit",
330
497
  "export const cssVars = {",
@@ -333,37 +500,68 @@ function generateJs(varNames, prefix, naming, declarations) {
333
500
  ""
334
501
  ].join("\n");
335
502
  }
336
- function generateDeclaration(varNames, prefix, naming, declarations) {
337
- const entries = buildEntries(varNames, prefix, naming, declarations).flatMap(({ key, name, value }) => [
338
- ...value ? [formatDefaultComment(value)] : [],
339
- ` ${key}: 'var(${name})';`
340
- ]);
503
+ function generateDeclaration(varNames, prefix, naming, declarations, group, properties) {
504
+ assertGroupPrefixCompatible(prefix, group);
505
+ const entries = group ? renderGroupedBlock(varNames, naming, declarations, properties, " ", ";", declarationLineFor) : renderEntryLines(buildEntries(varNames, prefix, naming, declarations, properties), " ", declarationLineFor);
506
+ const blocks = buildTailBlocks(varNames, group, properties);
507
+ const tailBody = blocks.flatMap((block, i) => i === 0 ? block : ["", ...block]);
341
508
  return [
342
509
  "export declare const cssVars: {",
343
510
  ...entries,
344
511
  "};",
345
- "export type CssVarName = keyof typeof cssVars;",
512
+ ...tailBody,
346
513
  ""
347
514
  ].join("\n");
348
515
  }
349
516
 
350
517
  // src/index.ts
351
- async function computeOutputs(options) {
352
- const declarations = await scanVarDeclarations(options.input, options.exclude, options.selectors);
518
+ function assertPruneCompatible(options) {
519
+ if (!options.prune) return;
520
+ if (options.group) throw new Error('css-typed-vars: "prune" cannot be combined with "group".');
521
+ if (!options.usage) throw new Error('css-typed-vars: "prune" requires "usage" (glob(s) of source files to scan).');
522
+ }
523
+ function partitionUnused(names, usedKeys, prefix, naming) {
524
+ const used = [];
525
+ const unused = [];
526
+ for (const name of names) {
527
+ (usedKeys.has(computeKey(name, prefix, naming)) ? used : unused).push(name);
528
+ }
529
+ return { used, unused };
530
+ }
531
+ async function findUnusedVars(options) {
532
+ if (!options.usage) throw new Error('css-typed-vars: findUnusedVars requires "usage" (glob(s) of source files to scan).');
533
+ const [declarations, usedKeys] = await Promise.all([
534
+ scanVarDeclarations(options.input, options.exclude, options.selectors),
535
+ scanUsedKeys(options.usage, options.usageExclude)
536
+ ]);
353
537
  const names = [...declarations.keys()].sort();
538
+ return partitionUnused(names, usedKeys, options.prefix, options.naming).unused;
539
+ }
540
+ async function computeOutputs(options) {
541
+ assertPruneCompatible(options);
542
+ const { declarations, properties } = await scanCss(options.input, options.exclude, options.selectors);
543
+ let names = [...declarations.keys()].sort();
354
544
  if (names.length === 0) {
355
545
  console.warn("css-typed-vars: no CSS custom properties found.");
356
546
  }
357
547
  warnOnCollisions(names, options.prefix, options.naming);
548
+ if (options.prune) {
549
+ const usedKeys = await scanUsedKeys(options.usage, options.usageExclude);
550
+ const { used, unused } = partitionUnused(names, usedKeys, options.prefix, options.naming);
551
+ if (unused.length > 0) {
552
+ console.warn(`css-typed-vars: pruned ${unused.length} unused variable(s): ${unused.join(", ")}`);
553
+ }
554
+ names = used;
555
+ }
358
556
  const outPath = (0, import_node_path.resolve)(options.output);
359
557
  const jsExtMatch = /\.(m|c)?js$/i.exec(options.output);
360
558
  if (jsExtMatch) {
361
- const content = generateJs(names, options.prefix, options.naming, declarations);
559
+ const content = generateJs(names, options.prefix, options.naming, declarations, options.group, properties);
362
560
  const dtsPath = outPath.slice(0, -jsExtMatch[0].length) + ".d.ts";
363
- const dtsContent = generateDeclaration(names, options.prefix, options.naming, declarations);
561
+ const dtsContent = generateDeclaration(names, options.prefix, options.naming, declarations, options.group, properties);
364
562
  return { outPath, content, dtsPath, dtsContent };
365
563
  }
366
- return { outPath, content: generateCode(names, options.prefix, options.naming, declarations) };
564
+ return { outPath, content: generateCode(names, options.prefix, options.naming, declarations, options.group, properties) };
367
565
  }
368
566
  async function generate(options) {
369
567
  const { outPath, content, dtsPath, dtsContent } = await computeOutputs(options);
@@ -386,12 +584,16 @@ async function checkGenerated(options) {
386
584
  // Annotate the CommonJS export names for ESM import in node:
387
585
  0 && (module.exports = {
388
586
  checkGenerated,
587
+ findUnusedVars,
389
588
  generate,
390
589
  generateCode,
391
590
  generateDeclaration,
392
591
  generateJs,
592
+ parsePropertyRules,
393
593
  parseVarDeclarations,
394
594
  parseVarNames,
595
+ scanCss,
596
+ scanUsedKeys,
395
597
  scanVarDeclarations,
396
598
  scanVarNames
397
599
  });
package/dist/index.d.cts CHANGED
@@ -1,11 +1,14 @@
1
- import { N as NamingConvention } from './generator-t6h8Ic7V.cjs';
2
- export { g as generateCode, a as generateDeclaration, b as generateJs } from './generator-t6h8Ic7V.cjs';
3
-
4
- declare function parseVarNames(css: string, selectors?: string[]): string[];
5
- declare function parseVarDeclarations(css: string, selectors?: string[]): Map<string, string>;
1
+ import { P as PropertyRule, N as NamingConvention } from './generator-C2AppeJL.cjs';
2
+ export { g as generateCode, a as generateDeclaration, b as generateJs, p as parsePropertyRules, c as parseVarDeclarations, d as parseVarNames } from './generator-C2AppeJL.cjs';
6
3
 
4
+ interface ScannedCss {
5
+ declarations: Map<string, string>;
6
+ properties: Map<string, PropertyRule>;
7
+ }
8
+ declare function scanCss(patterns: string | string[], exclude?: string | string[], selectors?: string[]): Promise<ScannedCss>;
7
9
  declare function scanVarDeclarations(patterns: string | string[], exclude?: string | string[], selectors?: string[]): Promise<Map<string, string>>;
8
10
  declare function scanVarNames(patterns: string | string[], exclude?: string | string[], selectors?: string[]): Promise<string[]>;
11
+ declare function scanUsedKeys(patterns: string | string[], exclude?: string | string[]): Promise<Set<string>>;
9
12
 
10
13
  interface GenerateOptions {
11
14
  input: string | string[];
@@ -14,8 +17,15 @@ interface GenerateOptions {
14
17
  prefix?: string;
15
18
  naming?: NamingConvention;
16
19
  selectors?: string[];
20
+ group?: boolean;
21
+ /** Prune generated vars with no detected `cssVars.<key>` usage. Requires `usage`, and can't be combined with `group`. */
22
+ prune?: boolean;
23
+ /** Glob(s) of source files to scan for `cssVars` usage. Required when `prune` is true, or when calling `findUnusedVars`. */
24
+ usage?: string | string[];
25
+ usageExclude?: string | string[];
17
26
  }
27
+ declare function findUnusedVars(options: Pick<GenerateOptions, 'input' | 'exclude' | 'selectors' | 'prefix' | 'naming' | 'usage' | 'usageExclude'>): Promise<string[]>;
18
28
  declare function generate(options: GenerateOptions): Promise<void>;
19
29
  declare function checkGenerated(options: GenerateOptions): Promise<boolean>;
20
30
 
21
- export { type GenerateOptions, NamingConvention, checkGenerated, generate, parseVarDeclarations, parseVarNames, scanVarDeclarations, scanVarNames };
31
+ export { type GenerateOptions, NamingConvention, PropertyRule, checkGenerated, findUnusedVars, generate, scanCss, scanUsedKeys, scanVarDeclarations, scanVarNames };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,14 @@
1
- import { N as NamingConvention } from './generator-t6h8Ic7V.js';
2
- export { g as generateCode, a as generateDeclaration, b as generateJs } from './generator-t6h8Ic7V.js';
3
-
4
- declare function parseVarNames(css: string, selectors?: string[]): string[];
5
- declare function parseVarDeclarations(css: string, selectors?: string[]): Map<string, string>;
1
+ import { P as PropertyRule, N as NamingConvention } from './generator-C2AppeJL.js';
2
+ export { g as generateCode, a as generateDeclaration, b as generateJs, p as parsePropertyRules, c as parseVarDeclarations, d as parseVarNames } from './generator-C2AppeJL.js';
6
3
 
4
+ interface ScannedCss {
5
+ declarations: Map<string, string>;
6
+ properties: Map<string, PropertyRule>;
7
+ }
8
+ declare function scanCss(patterns: string | string[], exclude?: string | string[], selectors?: string[]): Promise<ScannedCss>;
7
9
  declare function scanVarDeclarations(patterns: string | string[], exclude?: string | string[], selectors?: string[]): Promise<Map<string, string>>;
8
10
  declare function scanVarNames(patterns: string | string[], exclude?: string | string[], selectors?: string[]): Promise<string[]>;
11
+ declare function scanUsedKeys(patterns: string | string[], exclude?: string | string[]): Promise<Set<string>>;
9
12
 
10
13
  interface GenerateOptions {
11
14
  input: string | string[];
@@ -14,8 +17,15 @@ interface GenerateOptions {
14
17
  prefix?: string;
15
18
  naming?: NamingConvention;
16
19
  selectors?: string[];
20
+ group?: boolean;
21
+ /** Prune generated vars with no detected `cssVars.<key>` usage. Requires `usage`, and can't be combined with `group`. */
22
+ prune?: boolean;
23
+ /** Glob(s) of source files to scan for `cssVars` usage. Required when `prune` is true, or when calling `findUnusedVars`. */
24
+ usage?: string | string[];
25
+ usageExclude?: string | string[];
17
26
  }
27
+ declare function findUnusedVars(options: Pick<GenerateOptions, 'input' | 'exclude' | 'selectors' | 'prefix' | 'naming' | 'usage' | 'usageExclude'>): Promise<string[]>;
18
28
  declare function generate(options: GenerateOptions): Promise<void>;
19
29
  declare function checkGenerated(options: GenerateOptions): Promise<boolean>;
20
30
 
21
- export { type GenerateOptions, NamingConvention, checkGenerated, generate, parseVarDeclarations, parseVarNames, scanVarDeclarations, scanVarNames };
31
+ export { type GenerateOptions, NamingConvention, PropertyRule, checkGenerated, findUnusedVars, generate, scanCss, scanUsedKeys, scanVarDeclarations, scanVarNames };
package/dist/index.js CHANGED
@@ -1,24 +1,32 @@
1
1
  import {
2
2
  checkGenerated,
3
+ findUnusedVars,
3
4
  generate
4
- } from "./chunk-H3T6RMQQ.js";
5
+ } from "./chunk-VZ2BHHXD.js";
5
6
  import {
6
7
  generateCode,
7
8
  generateDeclaration,
8
9
  generateJs,
10
+ parsePropertyRules,
9
11
  parseVarDeclarations,
10
12
  parseVarNames,
13
+ scanCss,
14
+ scanUsedKeys,
11
15
  scanVarDeclarations,
12
16
  scanVarNames
13
- } from "./chunk-JDZAH2YQ.js";
17
+ } from "./chunk-LH53WYFF.js";
14
18
  export {
15
19
  checkGenerated,
20
+ findUnusedVars,
16
21
  generate,
17
22
  generateCode,
18
23
  generateDeclaration,
19
24
  generateJs,
25
+ parsePropertyRules,
20
26
  parseVarDeclarations,
21
27
  parseVarNames,
28
+ scanCss,
29
+ scanUsedKeys,
22
30
  scanVarDeclarations,
23
31
  scanVarNames
24
32
  };