css-typed-vars 0.11.0 → 0.13.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/rollup.cjs CHANGED
@@ -54,8 +54,8 @@ var import_node_path3 = require("path");
54
54
  // src/scanner.ts
55
55
  var import_promises2 = require("fs/promises");
56
56
  var import_node_path2 = require("path");
57
- var import_fast_glob = __toESM(require("fast-glob"), 1);
58
57
  var import_picomatch = __toESM(require("picomatch"), 1);
58
+ var import_tinyglobby = require("tinyglobby");
59
59
 
60
60
  // src/parser.ts
61
61
  function stepQuote(text, i, quote) {
@@ -162,9 +162,11 @@ function maskQuotedContent(text) {
162
162
  }
163
163
  return result;
164
164
  }
165
+ var CLOSERS = { "(": ")", "[": "]", "{": "}" };
165
166
  function extractValue(text, start) {
166
167
  let i = start;
167
168
  let quote = null;
169
+ const open = [];
168
170
  for (; i < text.length; i++) {
169
171
  const char = text[i];
170
172
  if (quote) {
@@ -177,16 +179,19 @@ function extractValue(text, start) {
177
179
  quote = char;
178
180
  continue;
179
181
  }
180
- if (char === ";" || char === "}") break;
182
+ if (char in CLOSERS) open.push(CLOSERS[char]);
183
+ else if (char === open[open.length - 1]) open.pop();
184
+ else if (char === "}" || char === ";" && open.length === 0) break;
181
185
  }
182
186
  return text.slice(start, i).trim();
183
187
  }
188
+ var IMPORTANT = /\s*!\s*important$/i;
184
189
  function forEachProperty(block, onProperty, offset = 0) {
185
190
  const masked = maskQuotedContent(block);
186
191
  for (const prop of masked.matchAll(/--[\w-]+(?=\s*:)/g)) {
187
192
  const name = prop[0];
188
193
  const colonIndex = block.indexOf(":", prop.index + name.length);
189
- onProperty(name, extractValue(block, colonIndex + 1), offset + prop.index);
194
+ onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
190
195
  }
191
196
  }
192
197
  function forEachSelectorBlock(stripped, selectors, onBlock) {
@@ -337,6 +342,39 @@ function toRawPosition(stripped, strippedPos) {
337
342
  function normalizePatterns(patterns) {
338
343
  return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
339
344
  }
345
+ function comparePaths(a, b) {
346
+ const as = a.split("/");
347
+ const bs = b.split("/");
348
+ for (let i = 0; i < Math.min(as.length, bs.length); i++) {
349
+ if (as[i] === bs[i]) continue;
350
+ const aIsFile = i === as.length - 1;
351
+ const bIsFile = i === bs.length - 1;
352
+ if (aIsFile !== bIsFile) return aIsFile ? -1 : 1;
353
+ return as[i] < bs[i] ? -1 : 1;
354
+ }
355
+ return as.length - bs.length;
356
+ }
357
+ async function globFiles(pattern, ignore) {
358
+ if (!/^(?:[A-Za-z]:)?\//.test(pattern)) {
359
+ return (0, import_tinyglobby.glob)(pattern, { absolute: true, ignore, expandDirectories: false });
360
+ }
361
+ const { base, glob: rest, isGlob } = import_picomatch.default.scan(pattern);
362
+ const [cwd, relativeGlob] = isGlob ? [base, rest] : [import_node_path2.posix.dirname(pattern), import_node_path2.posix.basename(pattern)];
363
+ const matches = await (0, import_tinyglobby.glob)(relativeGlob, { cwd, absolute: true, expandDirectories: false });
364
+ if (ignore.length === 0) return matches;
365
+ const isIgnored = (0, import_picomatch.default)(ignore, { dot: true });
366
+ return matches.filter((file) => !isIgnored(file));
367
+ }
368
+ async function findFiles(patterns, exclude) {
369
+ const normalized = normalizePatterns(patterns);
370
+ const ignore = [
371
+ ...exclude ? normalizePatterns(exclude) : [],
372
+ ...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
373
+ ];
374
+ const perGlob = await Promise.all(normalized.filter((p) => !p.startsWith("!")).map((p) => globFiles(p, ignore)));
375
+ const files = perGlob.flatMap((matches) => matches.sort(comparePaths));
376
+ return [...new Set(files.reverse())].reverse();
377
+ }
340
378
  function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
341
379
  const compile = (globs) => (0, import_picomatch.default)(normalizePatterns(globs).map((p) => p.replace(/^\.\//, "")));
342
380
  const include = compile(patterns);
@@ -351,9 +389,9 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
351
389
  function globWatchRoots(patterns, cwd = process.cwd()) {
352
390
  const roots = /* @__PURE__ */ new Map();
353
391
  for (const pattern of normalizePatterns(patterns)) {
354
- const { base, glob, isGlob } = import_picomatch.default.scan(pattern);
392
+ const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
355
393
  const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
356
- const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob) ? void 0 : glob.split("/").length - 1;
394
+ const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
357
395
  const previous = roots.get(dir);
358
396
  const unlimited = roots.has(dir) && previous === void 0 || depth === void 0;
359
397
  roots.set(dir, unlimited ? void 0 : Math.max(previous ?? 0, depth));
@@ -371,9 +409,7 @@ function collectVarNames(scanned) {
371
409
  return [...names].sort();
372
410
  }
373
411
  async function scanCss(patterns, exclude, selectors, themes = {}) {
374
- const normalized = normalizePatterns(patterns);
375
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
376
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
412
+ const files = await findFiles(patterns, exclude);
377
413
  const perFile = await Promise.all(
378
414
  files.map(async (file) => {
379
415
  let css;
@@ -430,9 +466,7 @@ function extractUsage(text, into) {
430
466
  }
431
467
  }
432
468
  async function scanUsage(patterns, exclude) {
433
- const normalized = normalizePatterns(patterns);
434
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
435
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
469
+ const files = await findFiles(patterns, exclude);
436
470
  const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
437
471
  const texts = await Promise.all(
438
472
  files.map(async (file) => {
@@ -690,13 +724,19 @@ var HELPERS_JS = [
690
724
  "",
691
725
  "export function withFallback(ref, fallback) {",
692
726
  " return `${ref.slice(0, -1)}, ${fallback})`;",
727
+ "}",
728
+ "",
729
+ "export function varName(ref) {",
730
+ " return ref.slice(4, -1);",
693
731
  "}"
694
732
  ];
695
733
  var HELPERS_DTS = [
696
734
  "export declare function getCssVar(ref: CssVarRef, el?: Element): string;",
697
735
  "export declare function setCssVar(ref: CssVarRef, value: string, el?: HTMLElement): void;",
698
736
  "export type CssVarWithFallback<R extends CssVarRef, F extends string | number> = R extends `var(${infer N})` ? `var(${N}, ${F})` : never;",
699
- "export declare function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F>;"
737
+ "export declare function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F>;",
738
+ "export type CssVarProperty<R extends CssVarRef> = R extends `var(${infer N})` ? N : never;",
739
+ "export declare function varName<R extends CssVarRef>(ref: R): CssVarProperty<R>;"
700
740
  ];
701
741
  function generateJs(varNames, ...args) {
702
742
  const options = normalizeOptions(args);
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-DJ9uOYBP.cjs';
4
+ import './generator-BokM5zux.cjs';
5
5
 
6
6
  declare const _default: (options: Options) => rollup.Plugin<any> | rollup.Plugin<any>[];
7
7
 
package/dist/rollup.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as rollup from 'rollup';
2
2
  import { Options } from './unplugin.js';
3
3
  import 'unplugin';
4
- import './generator-DJ9uOYBP.js';
4
+ import './generator-BokM5zux.js';
5
5
 
6
6
  declare const _default: (options: Options) => rollup.Plugin<any> | rollup.Plugin<any>[];
7
7
 
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-CBN3J54B.js";
4
- import "./chunk-TR53YUPE.js";
3
+ } from "./chunk-JGJ53FND.js";
4
+ import "./chunk-XSFYQPH6.js";
5
5
 
6
6
  // src/rollup.ts
7
7
  var rollup_default = unplugin_default.rollup;
package/dist/unplugin.cjs CHANGED
@@ -52,8 +52,8 @@ var import_node_path3 = require("path");
52
52
  // src/scanner.ts
53
53
  var import_promises2 = require("fs/promises");
54
54
  var import_node_path2 = require("path");
55
- var import_fast_glob = __toESM(require("fast-glob"), 1);
56
55
  var import_picomatch = __toESM(require("picomatch"), 1);
56
+ var import_tinyglobby = require("tinyglobby");
57
57
 
58
58
  // src/parser.ts
59
59
  function stepQuote(text, i, quote) {
@@ -160,9 +160,11 @@ function maskQuotedContent(text) {
160
160
  }
161
161
  return result;
162
162
  }
163
+ var CLOSERS = { "(": ")", "[": "]", "{": "}" };
163
164
  function extractValue(text, start) {
164
165
  let i = start;
165
166
  let quote = null;
167
+ const open = [];
166
168
  for (; i < text.length; i++) {
167
169
  const char = text[i];
168
170
  if (quote) {
@@ -175,16 +177,19 @@ function extractValue(text, start) {
175
177
  quote = char;
176
178
  continue;
177
179
  }
178
- if (char === ";" || char === "}") break;
180
+ if (char in CLOSERS) open.push(CLOSERS[char]);
181
+ else if (char === open[open.length - 1]) open.pop();
182
+ else if (char === "}" || char === ";" && open.length === 0) break;
179
183
  }
180
184
  return text.slice(start, i).trim();
181
185
  }
186
+ var IMPORTANT = /\s*!\s*important$/i;
182
187
  function forEachProperty(block, onProperty, offset = 0) {
183
188
  const masked = maskQuotedContent(block);
184
189
  for (const prop of masked.matchAll(/--[\w-]+(?=\s*:)/g)) {
185
190
  const name = prop[0];
186
191
  const colonIndex = block.indexOf(":", prop.index + name.length);
187
- onProperty(name, extractValue(block, colonIndex + 1), offset + prop.index);
192
+ onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
188
193
  }
189
194
  }
190
195
  function forEachSelectorBlock(stripped, selectors, onBlock) {
@@ -335,6 +340,39 @@ function toRawPosition(stripped, strippedPos) {
335
340
  function normalizePatterns(patterns) {
336
341
  return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
337
342
  }
343
+ function comparePaths(a, b) {
344
+ const as = a.split("/");
345
+ const bs = b.split("/");
346
+ for (let i = 0; i < Math.min(as.length, bs.length); i++) {
347
+ if (as[i] === bs[i]) continue;
348
+ const aIsFile = i === as.length - 1;
349
+ const bIsFile = i === bs.length - 1;
350
+ if (aIsFile !== bIsFile) return aIsFile ? -1 : 1;
351
+ return as[i] < bs[i] ? -1 : 1;
352
+ }
353
+ return as.length - bs.length;
354
+ }
355
+ async function globFiles(pattern, ignore) {
356
+ if (!/^(?:[A-Za-z]:)?\//.test(pattern)) {
357
+ return (0, import_tinyglobby.glob)(pattern, { absolute: true, ignore, expandDirectories: false });
358
+ }
359
+ const { base, glob: rest, isGlob } = import_picomatch.default.scan(pattern);
360
+ const [cwd, relativeGlob] = isGlob ? [base, rest] : [import_node_path2.posix.dirname(pattern), import_node_path2.posix.basename(pattern)];
361
+ const matches = await (0, import_tinyglobby.glob)(relativeGlob, { cwd, absolute: true, expandDirectories: false });
362
+ if (ignore.length === 0) return matches;
363
+ const isIgnored = (0, import_picomatch.default)(ignore, { dot: true });
364
+ return matches.filter((file) => !isIgnored(file));
365
+ }
366
+ async function findFiles(patterns, exclude) {
367
+ const normalized = normalizePatterns(patterns);
368
+ const ignore = [
369
+ ...exclude ? normalizePatterns(exclude) : [],
370
+ ...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
371
+ ];
372
+ const perGlob = await Promise.all(normalized.filter((p) => !p.startsWith("!")).map((p) => globFiles(p, ignore)));
373
+ const files = perGlob.flatMap((matches) => matches.sort(comparePaths));
374
+ return [...new Set(files.reverse())].reverse();
375
+ }
338
376
  function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
339
377
  const compile = (globs) => (0, import_picomatch.default)(normalizePatterns(globs).map((p) => p.replace(/^\.\//, "")));
340
378
  const include = compile(patterns);
@@ -349,9 +387,9 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
349
387
  function globWatchRoots(patterns, cwd = process.cwd()) {
350
388
  const roots = /* @__PURE__ */ new Map();
351
389
  for (const pattern of normalizePatterns(patterns)) {
352
- const { base, glob, isGlob } = import_picomatch.default.scan(pattern);
390
+ const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
353
391
  const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
354
- const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob) ? void 0 : glob.split("/").length - 1;
392
+ const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
355
393
  const previous = roots.get(dir);
356
394
  const unlimited = roots.has(dir) && previous === void 0 || depth === void 0;
357
395
  roots.set(dir, unlimited ? void 0 : Math.max(previous ?? 0, depth));
@@ -369,9 +407,7 @@ function collectVarNames(scanned) {
369
407
  return [...names].sort();
370
408
  }
371
409
  async function scanCss(patterns, exclude, selectors, themes = {}) {
372
- const normalized = normalizePatterns(patterns);
373
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
374
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
410
+ const files = await findFiles(patterns, exclude);
375
411
  const perFile = await Promise.all(
376
412
  files.map(async (file) => {
377
413
  let css;
@@ -428,9 +464,7 @@ function extractUsage(text, into) {
428
464
  }
429
465
  }
430
466
  async function scanUsage(patterns, exclude) {
431
- const normalized = normalizePatterns(patterns);
432
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
433
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
467
+ const files = await findFiles(patterns, exclude);
434
468
  const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
435
469
  const texts = await Promise.all(
436
470
  files.map(async (file) => {
@@ -688,13 +722,19 @@ var HELPERS_JS = [
688
722
  "",
689
723
  "export function withFallback(ref, fallback) {",
690
724
  " return `${ref.slice(0, -1)}, ${fallback})`;",
725
+ "}",
726
+ "",
727
+ "export function varName(ref) {",
728
+ " return ref.slice(4, -1);",
691
729
  "}"
692
730
  ];
693
731
  var HELPERS_DTS = [
694
732
  "export declare function getCssVar(ref: CssVarRef, el?: Element): string;",
695
733
  "export declare function setCssVar(ref: CssVarRef, value: string, el?: HTMLElement): void;",
696
734
  "export type CssVarWithFallback<R extends CssVarRef, F extends string | number> = R extends `var(${infer N})` ? `var(${N}, ${F})` : never;",
697
- "export declare function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F>;"
735
+ "export declare function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F>;",
736
+ "export type CssVarProperty<R extends CssVarRef> = R extends `var(${infer N})` ? N : never;",
737
+ "export declare function varName<R extends CssVarRef>(ref: R): CssVarProperty<R>;"
698
738
  ];
699
739
  function generateJs(varNames, ...args) {
700
740
  const options = normalizeOptions(args);
@@ -1,5 +1,5 @@
1
1
  import * as unplugin from 'unplugin';
2
- import { N as NamingConvention } from './generator-DJ9uOYBP.cjs';
2
+ import { N as NamingConvention } from './generator-BokM5zux.cjs';
3
3
 
4
4
  interface Options {
5
5
  input: string | string[];
@@ -28,7 +28,7 @@ interface Options {
28
28
  /** Glob(s) of source files to scan for `cssVars` usage. Required when `prune` is true. */
29
29
  usage?: string | string[];
30
30
  usageExclude?: string | string[];
31
- /** Also emit the `CssVarRef` type and `getCssVar`/`setCssVar` runtime helpers. */
31
+ /** Also emit the `CssVarRef` type and `getCssVar`/`setCssVar`/`withFallback`/`varName` helpers. */
32
32
  helpers?: boolean;
33
33
  }
34
34
  declare const _default: unplugin.UnpluginInstance<Options, boolean>;
@@ -1,5 +1,5 @@
1
1
  import * as unplugin from 'unplugin';
2
- import { N as NamingConvention } from './generator-DJ9uOYBP.js';
2
+ import { N as NamingConvention } from './generator-BokM5zux.js';
3
3
 
4
4
  interface Options {
5
5
  input: string | string[];
@@ -28,7 +28,7 @@ interface Options {
28
28
  /** Glob(s) of source files to scan for `cssVars` usage. Required when `prune` is true. */
29
29
  usage?: string | string[];
30
30
  usageExclude?: string | string[];
31
- /** Also emit the `CssVarRef` type and `getCssVar`/`setCssVar` runtime helpers. */
31
+ /** Also emit the `CssVarRef` type and `getCssVar`/`setCssVar`/`withFallback`/`varName` helpers. */
32
32
  helpers?: boolean;
33
33
  }
34
34
  declare const _default: unplugin.UnpluginInstance<Options, boolean>;
package/dist/unplugin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-CBN3J54B.js";
4
- import "./chunk-TR53YUPE.js";
3
+ } from "./chunk-JGJ53FND.js";
4
+ import "./chunk-XSFYQPH6.js";
5
5
  export {
6
6
  unplugin_default as default
7
7
  };
package/dist/vite.cjs CHANGED
@@ -54,8 +54,8 @@ var import_node_path3 = require("path");
54
54
  // src/scanner.ts
55
55
  var import_promises2 = require("fs/promises");
56
56
  var import_node_path2 = require("path");
57
- var import_fast_glob = __toESM(require("fast-glob"), 1);
58
57
  var import_picomatch = __toESM(require("picomatch"), 1);
58
+ var import_tinyglobby = require("tinyglobby");
59
59
 
60
60
  // src/parser.ts
61
61
  function stepQuote(text, i, quote) {
@@ -162,9 +162,11 @@ function maskQuotedContent(text) {
162
162
  }
163
163
  return result;
164
164
  }
165
+ var CLOSERS = { "(": ")", "[": "]", "{": "}" };
165
166
  function extractValue(text, start) {
166
167
  let i = start;
167
168
  let quote = null;
169
+ const open = [];
168
170
  for (; i < text.length; i++) {
169
171
  const char = text[i];
170
172
  if (quote) {
@@ -177,16 +179,19 @@ function extractValue(text, start) {
177
179
  quote = char;
178
180
  continue;
179
181
  }
180
- if (char === ";" || char === "}") break;
182
+ if (char in CLOSERS) open.push(CLOSERS[char]);
183
+ else if (char === open[open.length - 1]) open.pop();
184
+ else if (char === "}" || char === ";" && open.length === 0) break;
181
185
  }
182
186
  return text.slice(start, i).trim();
183
187
  }
188
+ var IMPORTANT = /\s*!\s*important$/i;
184
189
  function forEachProperty(block, onProperty, offset = 0) {
185
190
  const masked = maskQuotedContent(block);
186
191
  for (const prop of masked.matchAll(/--[\w-]+(?=\s*:)/g)) {
187
192
  const name = prop[0];
188
193
  const colonIndex = block.indexOf(":", prop.index + name.length);
189
- onProperty(name, extractValue(block, colonIndex + 1), offset + prop.index);
194
+ onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
190
195
  }
191
196
  }
192
197
  function forEachSelectorBlock(stripped, selectors, onBlock) {
@@ -337,6 +342,39 @@ function toRawPosition(stripped, strippedPos) {
337
342
  function normalizePatterns(patterns) {
338
343
  return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
339
344
  }
345
+ function comparePaths(a, b) {
346
+ const as = a.split("/");
347
+ const bs = b.split("/");
348
+ for (let i = 0; i < Math.min(as.length, bs.length); i++) {
349
+ if (as[i] === bs[i]) continue;
350
+ const aIsFile = i === as.length - 1;
351
+ const bIsFile = i === bs.length - 1;
352
+ if (aIsFile !== bIsFile) return aIsFile ? -1 : 1;
353
+ return as[i] < bs[i] ? -1 : 1;
354
+ }
355
+ return as.length - bs.length;
356
+ }
357
+ async function globFiles(pattern, ignore) {
358
+ if (!/^(?:[A-Za-z]:)?\//.test(pattern)) {
359
+ return (0, import_tinyglobby.glob)(pattern, { absolute: true, ignore, expandDirectories: false });
360
+ }
361
+ const { base, glob: rest, isGlob } = import_picomatch.default.scan(pattern);
362
+ const [cwd, relativeGlob] = isGlob ? [base, rest] : [import_node_path2.posix.dirname(pattern), import_node_path2.posix.basename(pattern)];
363
+ const matches = await (0, import_tinyglobby.glob)(relativeGlob, { cwd, absolute: true, expandDirectories: false });
364
+ if (ignore.length === 0) return matches;
365
+ const isIgnored = (0, import_picomatch.default)(ignore, { dot: true });
366
+ return matches.filter((file) => !isIgnored(file));
367
+ }
368
+ async function findFiles(patterns, exclude) {
369
+ const normalized = normalizePatterns(patterns);
370
+ const ignore = [
371
+ ...exclude ? normalizePatterns(exclude) : [],
372
+ ...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
373
+ ];
374
+ const perGlob = await Promise.all(normalized.filter((p) => !p.startsWith("!")).map((p) => globFiles(p, ignore)));
375
+ const files = perGlob.flatMap((matches) => matches.sort(comparePaths));
376
+ return [...new Set(files.reverse())].reverse();
377
+ }
340
378
  function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
341
379
  const compile = (globs) => (0, import_picomatch.default)(normalizePatterns(globs).map((p) => p.replace(/^\.\//, "")));
342
380
  const include = compile(patterns);
@@ -351,9 +389,9 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
351
389
  function globWatchRoots(patterns, cwd = process.cwd()) {
352
390
  const roots = /* @__PURE__ */ new Map();
353
391
  for (const pattern of normalizePatterns(patterns)) {
354
- const { base, glob, isGlob } = import_picomatch.default.scan(pattern);
392
+ const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
355
393
  const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
356
- const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob) ? void 0 : glob.split("/").length - 1;
394
+ const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
357
395
  const previous = roots.get(dir);
358
396
  const unlimited = roots.has(dir) && previous === void 0 || depth === void 0;
359
397
  roots.set(dir, unlimited ? void 0 : Math.max(previous ?? 0, depth));
@@ -371,9 +409,7 @@ function collectVarNames(scanned) {
371
409
  return [...names].sort();
372
410
  }
373
411
  async function scanCss(patterns, exclude, selectors, themes = {}) {
374
- const normalized = normalizePatterns(patterns);
375
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
376
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
412
+ const files = await findFiles(patterns, exclude);
377
413
  const perFile = await Promise.all(
378
414
  files.map(async (file) => {
379
415
  let css;
@@ -430,9 +466,7 @@ function extractUsage(text, into) {
430
466
  }
431
467
  }
432
468
  async function scanUsage(patterns, exclude) {
433
- const normalized = normalizePatterns(patterns);
434
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
435
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
469
+ const files = await findFiles(patterns, exclude);
436
470
  const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
437
471
  const texts = await Promise.all(
438
472
  files.map(async (file) => {
@@ -690,13 +724,19 @@ var HELPERS_JS = [
690
724
  "",
691
725
  "export function withFallback(ref, fallback) {",
692
726
  " return `${ref.slice(0, -1)}, ${fallback})`;",
727
+ "}",
728
+ "",
729
+ "export function varName(ref) {",
730
+ " return ref.slice(4, -1);",
693
731
  "}"
694
732
  ];
695
733
  var HELPERS_DTS = [
696
734
  "export declare function getCssVar(ref: CssVarRef, el?: Element): string;",
697
735
  "export declare function setCssVar(ref: CssVarRef, value: string, el?: HTMLElement): void;",
698
736
  "export type CssVarWithFallback<R extends CssVarRef, F extends string | number> = R extends `var(${infer N})` ? `var(${N}, ${F})` : never;",
699
- "export declare function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F>;"
737
+ "export declare function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F>;",
738
+ "export type CssVarProperty<R extends CssVarRef> = R extends `var(${infer N})` ? N : never;",
739
+ "export declare function varName<R extends CssVarRef>(ref: R): CssVarProperty<R>;"
700
740
  ];
701
741
  function generateJs(varNames, ...args) {
702
742
  const options = normalizeOptions(args);
package/dist/vite.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as vite from 'vite';
2
2
  import { Options } from './unplugin.cjs';
3
3
  import 'unplugin';
4
- import './generator-DJ9uOYBP.cjs';
4
+ import './generator-BokM5zux.cjs';
5
5
 
6
6
  declare const _default: (options: Options) => vite.Plugin<any> | vite.Plugin<any>[];
7
7
 
package/dist/vite.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as vite from 'vite';
2
2
  import { Options } from './unplugin.js';
3
3
  import 'unplugin';
4
- import './generator-DJ9uOYBP.js';
4
+ import './generator-BokM5zux.js';
5
5
 
6
6
  declare const _default: (options: Options) => vite.Plugin<any> | vite.Plugin<any>[];
7
7
 
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-CBN3J54B.js";
4
- import "./chunk-TR53YUPE.js";
3
+ } from "./chunk-JGJ53FND.js";
4
+ import "./chunk-XSFYQPH6.js";
5
5
 
6
6
  // src/vite.ts
7
7
  var vite_default = unplugin_default.vite;
package/dist/webpack.cjs CHANGED
@@ -54,8 +54,8 @@ var import_node_path3 = require("path");
54
54
  // src/scanner.ts
55
55
  var import_promises2 = require("fs/promises");
56
56
  var import_node_path2 = require("path");
57
- var import_fast_glob = __toESM(require("fast-glob"), 1);
58
57
  var import_picomatch = __toESM(require("picomatch"), 1);
58
+ var import_tinyglobby = require("tinyglobby");
59
59
 
60
60
  // src/parser.ts
61
61
  function stepQuote(text, i, quote) {
@@ -162,9 +162,11 @@ function maskQuotedContent(text) {
162
162
  }
163
163
  return result;
164
164
  }
165
+ var CLOSERS = { "(": ")", "[": "]", "{": "}" };
165
166
  function extractValue(text, start) {
166
167
  let i = start;
167
168
  let quote = null;
169
+ const open = [];
168
170
  for (; i < text.length; i++) {
169
171
  const char = text[i];
170
172
  if (quote) {
@@ -177,16 +179,19 @@ function extractValue(text, start) {
177
179
  quote = char;
178
180
  continue;
179
181
  }
180
- if (char === ";" || char === "}") break;
182
+ if (char in CLOSERS) open.push(CLOSERS[char]);
183
+ else if (char === open[open.length - 1]) open.pop();
184
+ else if (char === "}" || char === ";" && open.length === 0) break;
181
185
  }
182
186
  return text.slice(start, i).trim();
183
187
  }
188
+ var IMPORTANT = /\s*!\s*important$/i;
184
189
  function forEachProperty(block, onProperty, offset = 0) {
185
190
  const masked = maskQuotedContent(block);
186
191
  for (const prop of masked.matchAll(/--[\w-]+(?=\s*:)/g)) {
187
192
  const name = prop[0];
188
193
  const colonIndex = block.indexOf(":", prop.index + name.length);
189
- onProperty(name, extractValue(block, colonIndex + 1), offset + prop.index);
194
+ onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
190
195
  }
191
196
  }
192
197
  function forEachSelectorBlock(stripped, selectors, onBlock) {
@@ -337,6 +342,39 @@ function toRawPosition(stripped, strippedPos) {
337
342
  function normalizePatterns(patterns) {
338
343
  return (Array.isArray(patterns) ? patterns : [patterns]).map((p) => p.replace(/\\/g, "/"));
339
344
  }
345
+ function comparePaths(a, b) {
346
+ const as = a.split("/");
347
+ const bs = b.split("/");
348
+ for (let i = 0; i < Math.min(as.length, bs.length); i++) {
349
+ if (as[i] === bs[i]) continue;
350
+ const aIsFile = i === as.length - 1;
351
+ const bIsFile = i === bs.length - 1;
352
+ if (aIsFile !== bIsFile) return aIsFile ? -1 : 1;
353
+ return as[i] < bs[i] ? -1 : 1;
354
+ }
355
+ return as.length - bs.length;
356
+ }
357
+ async function globFiles(pattern, ignore) {
358
+ if (!/^(?:[A-Za-z]:)?\//.test(pattern)) {
359
+ return (0, import_tinyglobby.glob)(pattern, { absolute: true, ignore, expandDirectories: false });
360
+ }
361
+ const { base, glob: rest, isGlob } = import_picomatch.default.scan(pattern);
362
+ const [cwd, relativeGlob] = isGlob ? [base, rest] : [import_node_path2.posix.dirname(pattern), import_node_path2.posix.basename(pattern)];
363
+ const matches = await (0, import_tinyglobby.glob)(relativeGlob, { cwd, absolute: true, expandDirectories: false });
364
+ if (ignore.length === 0) return matches;
365
+ const isIgnored = (0, import_picomatch.default)(ignore, { dot: true });
366
+ return matches.filter((file) => !isIgnored(file));
367
+ }
368
+ async function findFiles(patterns, exclude) {
369
+ const normalized = normalizePatterns(patterns);
370
+ const ignore = [
371
+ ...exclude ? normalizePatterns(exclude) : [],
372
+ ...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
373
+ ];
374
+ const perGlob = await Promise.all(normalized.filter((p) => !p.startsWith("!")).map((p) => globFiles(p, ignore)));
375
+ const files = perGlob.flatMap((matches) => matches.sort(comparePaths));
376
+ return [...new Set(files.reverse())].reverse();
377
+ }
340
378
  function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
341
379
  const compile = (globs) => (0, import_picomatch.default)(normalizePatterns(globs).map((p) => p.replace(/^\.\//, "")));
342
380
  const include = compile(patterns);
@@ -351,9 +389,9 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
351
389
  function globWatchRoots(patterns, cwd = process.cwd()) {
352
390
  const roots = /* @__PURE__ */ new Map();
353
391
  for (const pattern of normalizePatterns(patterns)) {
354
- const { base, glob, isGlob } = import_picomatch.default.scan(pattern);
392
+ const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
355
393
  const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
356
- const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob) ? void 0 : glob.split("/").length - 1;
394
+ const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
357
395
  const previous = roots.get(dir);
358
396
  const unlimited = roots.has(dir) && previous === void 0 || depth === void 0;
359
397
  roots.set(dir, unlimited ? void 0 : Math.max(previous ?? 0, depth));
@@ -371,9 +409,7 @@ function collectVarNames(scanned) {
371
409
  return [...names].sort();
372
410
  }
373
411
  async function scanCss(patterns, exclude, selectors, themes = {}) {
374
- const normalized = normalizePatterns(patterns);
375
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
376
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
412
+ const files = await findFiles(patterns, exclude);
377
413
  const perFile = await Promise.all(
378
414
  files.map(async (file) => {
379
415
  let css;
@@ -430,9 +466,7 @@ function extractUsage(text, into) {
430
466
  }
431
467
  }
432
468
  async function scanUsage(patterns, exclude) {
433
- const normalized = normalizePatterns(patterns);
434
- const normalizedExclude = exclude ? normalizePatterns(exclude) : [];
435
- const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
469
+ const files = await findFiles(patterns, exclude);
436
470
  const usage = { keys: /* @__PURE__ */ new Set(), wholeKeys: /* @__PURE__ */ new Set(), paths: /* @__PURE__ */ new Set(), files };
437
471
  const texts = await Promise.all(
438
472
  files.map(async (file) => {
@@ -690,13 +724,19 @@ var HELPERS_JS = [
690
724
  "",
691
725
  "export function withFallback(ref, fallback) {",
692
726
  " return `${ref.slice(0, -1)}, ${fallback})`;",
727
+ "}",
728
+ "",
729
+ "export function varName(ref) {",
730
+ " return ref.slice(4, -1);",
693
731
  "}"
694
732
  ];
695
733
  var HELPERS_DTS = [
696
734
  "export declare function getCssVar(ref: CssVarRef, el?: Element): string;",
697
735
  "export declare function setCssVar(ref: CssVarRef, value: string, el?: HTMLElement): void;",
698
736
  "export type CssVarWithFallback<R extends CssVarRef, F extends string | number> = R extends `var(${infer N})` ? `var(${N}, ${F})` : never;",
699
- "export declare function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F>;"
737
+ "export declare function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F>;",
738
+ "export type CssVarProperty<R extends CssVarRef> = R extends `var(${infer N})` ? N : never;",
739
+ "export declare function varName<R extends CssVarRef>(ref: R): CssVarProperty<R>;"
700
740
  ];
701
741
  function generateJs(varNames, ...args) {
702
742
  const options = normalizeOptions(args);