css-typed-vars 0.12.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/README.md +14 -3
- package/dist/{chunk-ULIGESN5.js → chunk-FWKCSH2F.js} +1 -1
- package/dist/{chunk-XWMRTHOE.js → chunk-JGJ53FND.js} +1 -1
- package/dist/{chunk-RZLASYCF.js → chunk-XSFYQPH6.js} +20 -3
- package/dist/cli.cjs +21 -4
- package/dist/cli.js +3 -3
- package/dist/esbuild.cjs +14 -3
- package/dist/esbuild.d.cts +1 -1
- package/dist/esbuild.d.ts +1 -1
- package/dist/esbuild.js +2 -2
- package/dist/{generator-DJ9uOYBP.d.ts → generator-BokM5zux.d.cts} +1 -1
- package/dist/{generator-DJ9uOYBP.d.cts → generator-BokM5zux.d.ts} +1 -1
- package/dist/index.cjs +20 -3
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/rollup.cjs +14 -3
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.d.ts +1 -1
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +14 -3
- package/dist/unplugin.d.cts +2 -2
- package/dist/unplugin.d.ts +2 -2
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +14 -3
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +14 -3
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
- package/schema.json +1 -1
package/README.md
CHANGED
|
@@ -139,7 +139,7 @@ npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --prune-check
|
|
|
139
139
|
| `--selector` | Extra CSS selector to scan for variables (repeatable: `--selector ".dark" --selector "[data-theme='dark']"`) |
|
|
140
140
|
| `--theme` | Named theme block, kept out of the default value and emitted as `@theme <name> <value>` JSDoc tags (repeatable: `--theme dark='[data-theme="dark"]' --theme contrast='@media (prefers-contrast: more)'`) — see [Theme values](#theme-values) |
|
|
141
141
|
| `--group` | Nest keys under an object named after each variable's first hyphen segment: `--color-primary`/`--color-secondary` → `cssVars.color.primary`/`cssVars.color.secondary`. A variable with no hyphen stays top-level. Can't be combined with `--prefix`. |
|
|
142
|
-
| `--helpers` | Also emit the `CssVarRef` type and typed `getCssVar(ref, el?)`/`setCssVar(ref, value, el?)`/`withFallback(ref, fallback)` helpers — see [Usage](#usage). |
|
|
142
|
+
| `--helpers` | Also emit the `CssVarRef` type and typed `getCssVar(ref, el?)`/`setCssVar(ref, value, el?)`/`withFallback(ref, fallback)`/`varName(ref)` helpers — see [Usage](#usage). |
|
|
143
143
|
| `--prune` | Drop generated vars with no detected `cssVars.<key>` usage. Requires `--usage <glob>` (repeatable). With `--group`, matches `cssVars.<group>.<key>` and keeps a whole group referenced as `cssVars.<group>`. |
|
|
144
144
|
| `--prune-check` | Like `--prune`, but only reports unused vars without writing; exits 1 if any are found. Doesn't need `--output`. Useful in CI. |
|
|
145
145
|
| `--lint-refs` | Report `var(--name)` references to variables not declared anywhere in the input; exits 1 if any (without a fallback) are found — see [Linting var() references](#linting-var-references) |
|
|
@@ -365,7 +365,7 @@ Turbopack does not yet have a public plugin API for virtual modules. Use the CLI
|
|
|
365
365
|
| `selectors` | `string[]` | — | Extra CSS selectors to scan, e.g. `['.dark', '[data-theme="dark"]']` |
|
|
366
366
|
| `themes` | `Record<string, string>` | — | Theme name → selector or `@media` prelude; values become `@theme` JSDoc tags — see [Theme values](#theme-values) |
|
|
367
367
|
| `group` | `boolean` | `false` | Nest keys by each variable's first hyphen segment, e.g. `cssVars.color.primary`. Can't be combined with `prefix` |
|
|
368
|
-
| `helpers` | `boolean` | `false` | Also export the `CssVarRef` type and `getCssVar`/`setCssVar`/`withFallback` helpers from `css-typed-vars/vars` |
|
|
368
|
+
| `helpers` | `boolean` | `false` | Also export the `CssVarRef` type and `getCssVar`/`setCssVar`/`withFallback`/`varName` helpers from `css-typed-vars/vars` |
|
|
369
369
|
| `prune` | `boolean` | `false` | Drop vars with no detected `cssVars.<key>` (or `cssVars.<group>.<key>` with `group`) usage. Requires `usage` |
|
|
370
370
|
| `usage` | `string \| string[]` | — | Glob(s) of source files to scan for `cssVars` usage, for `prune` |
|
|
371
371
|
| `usageExclude` | `string \| string[]` | — | Glob(s) of source files to exclude from the usage scan |
|
|
@@ -435,6 +435,17 @@ withFallback(cssVars.spacingMd, 0); // 'var(--spacing-md, 0)'
|
|
|
435
435
|
withFallback(cssVars.colorLink, cssVars.colorPrimary); // 'var(--color-link, var(--color-primary))'
|
|
436
436
|
```
|
|
437
437
|
|
|
438
|
+
`varName` returns the custom property's own name, typed as the exact literal — for setting a variable from a style object (React inline styles, Vue `:style`), where you'd otherwise type the `--name` string by hand. Also a pure string helper:
|
|
439
|
+
|
|
440
|
+
```tsx
|
|
441
|
+
import { cssVars, varName } from './cssVars';
|
|
442
|
+
|
|
443
|
+
varName(cssVars.colorPrimary); // '--color-primary'
|
|
444
|
+
|
|
445
|
+
const style = { [varName(cssVars.colorPrimary)]: brandColor };
|
|
446
|
+
<div style={style} /> // sets --color-primary on this element
|
|
447
|
+
```
|
|
448
|
+
|
|
438
449
|
---
|
|
439
450
|
|
|
440
451
|
## Programmatic API
|
|
@@ -451,7 +462,7 @@ await generate({
|
|
|
451
462
|
selectors: ['.dark', '[data-theme="dark"]'],
|
|
452
463
|
themes: { dark: '[data-theme="dark"]' }, // per-theme values as @theme JSDoc tags
|
|
453
464
|
group: false, // nest keys by first hyphen segment, e.g. cssVars.color.primary
|
|
454
|
-
helpers: false, // also emit getCssVar/setCssVar/withFallback helpers
|
|
465
|
+
helpers: false, // also emit getCssVar/setCssVar/withFallback/varName helpers
|
|
455
466
|
prune: false, // drop vars with no detected cssVars.<key> usage (requires `usage`)
|
|
456
467
|
usage: 'src/**/*.{ts,tsx}',
|
|
457
468
|
});
|
|
@@ -121,9 +121,11 @@ function maskQuotedContent(text) {
|
|
|
121
121
|
}
|
|
122
122
|
return result;
|
|
123
123
|
}
|
|
124
|
+
var CLOSERS = { "(": ")", "[": "]", "{": "}" };
|
|
124
125
|
function extractValue(text, start) {
|
|
125
126
|
let i = start;
|
|
126
127
|
let quote = null;
|
|
128
|
+
const open = [];
|
|
127
129
|
for (; i < text.length; i++) {
|
|
128
130
|
const char = text[i];
|
|
129
131
|
if (quote) {
|
|
@@ -136,16 +138,19 @@ function extractValue(text, start) {
|
|
|
136
138
|
quote = char;
|
|
137
139
|
continue;
|
|
138
140
|
}
|
|
139
|
-
if (char
|
|
141
|
+
if (char in CLOSERS) open.push(CLOSERS[char]);
|
|
142
|
+
else if (char === open[open.length - 1]) open.pop();
|
|
143
|
+
else if (char === "}" || char === ";" && open.length === 0) break;
|
|
140
144
|
}
|
|
141
145
|
return text.slice(start, i).trim();
|
|
142
146
|
}
|
|
147
|
+
var IMPORTANT = /\s*!\s*important$/i;
|
|
143
148
|
function forEachProperty(block, onProperty, offset = 0) {
|
|
144
149
|
const masked = maskQuotedContent(block);
|
|
145
150
|
for (const prop of masked.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
146
151
|
const name = prop[0];
|
|
147
152
|
const colonIndex = block.indexOf(":", prop.index + name.length);
|
|
148
|
-
onProperty(name, extractValue(block, colonIndex + 1), offset + prop.index);
|
|
153
|
+
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
149
154
|
}
|
|
150
155
|
}
|
|
151
156
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
@@ -771,6 +776,12 @@ var HELPERS_TS = [
|
|
|
771
776
|
"",
|
|
772
777
|
"export function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F> {",
|
|
773
778
|
" return `${ref.slice(0, -1)}, ${fallback})` as CssVarWithFallback<R, F>;",
|
|
779
|
+
"}",
|
|
780
|
+
"",
|
|
781
|
+
"export type CssVarProperty<R extends CssVarRef> = R extends `var(${infer N})` ? N : never;",
|
|
782
|
+
"",
|
|
783
|
+
"export function varName<R extends CssVarRef>(ref: R): CssVarProperty<R> {",
|
|
784
|
+
" return ref.slice(4, -1) as CssVarProperty<R>;",
|
|
774
785
|
"}"
|
|
775
786
|
];
|
|
776
787
|
var HELPERS_JS = [
|
|
@@ -784,13 +795,19 @@ var HELPERS_JS = [
|
|
|
784
795
|
"",
|
|
785
796
|
"export function withFallback(ref, fallback) {",
|
|
786
797
|
" return `${ref.slice(0, -1)}, ${fallback})`;",
|
|
798
|
+
"}",
|
|
799
|
+
"",
|
|
800
|
+
"export function varName(ref) {",
|
|
801
|
+
" return ref.slice(4, -1);",
|
|
787
802
|
"}"
|
|
788
803
|
];
|
|
789
804
|
var HELPERS_DTS = [
|
|
790
805
|
"export declare function getCssVar(ref: CssVarRef, el?: Element): string;",
|
|
791
806
|
"export declare function setCssVar(ref: CssVarRef, value: string, el?: HTMLElement): void;",
|
|
792
807
|
"export type CssVarWithFallback<R extends CssVarRef, F extends string | number> = R extends `var(${infer N})` ? `var(${N}, ${F})` : never;",
|
|
793
|
-
"export declare function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F>;"
|
|
808
|
+
"export declare function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F>;",
|
|
809
|
+
"export type CssVarProperty<R extends CssVarRef> = R extends `var(${infer N})` ? N : never;",
|
|
810
|
+
"export declare function varName<R extends CssVarRef>(ref: R): CssVarProperty<R>;"
|
|
794
811
|
];
|
|
795
812
|
function generateCode(varNames, ...args) {
|
|
796
813
|
const options = normalizeOptions(args);
|
package/dist/cli.cjs
CHANGED
|
@@ -144,9 +144,11 @@ function maskQuotedContent(text) {
|
|
|
144
144
|
}
|
|
145
145
|
return result;
|
|
146
146
|
}
|
|
147
|
+
var CLOSERS = { "(": ")", "[": "]", "{": "}" };
|
|
147
148
|
function extractValue(text, start) {
|
|
148
149
|
let i = start;
|
|
149
150
|
let quote = null;
|
|
151
|
+
const open = [];
|
|
150
152
|
for (; i < text.length; i++) {
|
|
151
153
|
const char = text[i];
|
|
152
154
|
if (quote) {
|
|
@@ -159,16 +161,19 @@ function extractValue(text, start) {
|
|
|
159
161
|
quote = char;
|
|
160
162
|
continue;
|
|
161
163
|
}
|
|
162
|
-
if (char
|
|
164
|
+
if (char in CLOSERS) open.push(CLOSERS[char]);
|
|
165
|
+
else if (char === open[open.length - 1]) open.pop();
|
|
166
|
+
else if (char === "}" || char === ";" && open.length === 0) break;
|
|
163
167
|
}
|
|
164
168
|
return text.slice(start, i).trim();
|
|
165
169
|
}
|
|
170
|
+
var IMPORTANT = /\s*!\s*important$/i;
|
|
166
171
|
function forEachProperty(block, onProperty, offset = 0) {
|
|
167
172
|
const masked = maskQuotedContent(block);
|
|
168
173
|
for (const prop of masked.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
169
174
|
const name = prop[0];
|
|
170
175
|
const colonIndex = block.indexOf(":", prop.index + name.length);
|
|
171
|
-
onProperty(name, extractValue(block, colonIndex + 1), offset + prop.index);
|
|
176
|
+
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
172
177
|
}
|
|
173
178
|
}
|
|
174
179
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
@@ -782,6 +787,12 @@ var HELPERS_TS = [
|
|
|
782
787
|
"",
|
|
783
788
|
"export function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F> {",
|
|
784
789
|
" return `${ref.slice(0, -1)}, ${fallback})` as CssVarWithFallback<R, F>;",
|
|
790
|
+
"}",
|
|
791
|
+
"",
|
|
792
|
+
"export type CssVarProperty<R extends CssVarRef> = R extends `var(${infer N})` ? N : never;",
|
|
793
|
+
"",
|
|
794
|
+
"export function varName<R extends CssVarRef>(ref: R): CssVarProperty<R> {",
|
|
795
|
+
" return ref.slice(4, -1) as CssVarProperty<R>;",
|
|
785
796
|
"}"
|
|
786
797
|
];
|
|
787
798
|
var HELPERS_JS = [
|
|
@@ -795,13 +806,19 @@ var HELPERS_JS = [
|
|
|
795
806
|
"",
|
|
796
807
|
"export function withFallback(ref, fallback) {",
|
|
797
808
|
" return `${ref.slice(0, -1)}, ${fallback})`;",
|
|
809
|
+
"}",
|
|
810
|
+
"",
|
|
811
|
+
"export function varName(ref) {",
|
|
812
|
+
" return ref.slice(4, -1);",
|
|
798
813
|
"}"
|
|
799
814
|
];
|
|
800
815
|
var HELPERS_DTS = [
|
|
801
816
|
"export declare function getCssVar(ref: CssVarRef, el?: Element): string;",
|
|
802
817
|
"export declare function setCssVar(ref: CssVarRef, value: string, el?: HTMLElement): void;",
|
|
803
818
|
"export type CssVarWithFallback<R extends CssVarRef, F extends string | number> = R extends `var(${infer N})` ? `var(${N}, ${F})` : never;",
|
|
804
|
-
"export declare function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F>;"
|
|
819
|
+
"export declare function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F>;",
|
|
820
|
+
"export type CssVarProperty<R extends CssVarRef> = R extends `var(${infer N})` ? N : never;",
|
|
821
|
+
"export declare function varName<R extends CssVarRef>(ref: R): CssVarProperty<R>;"
|
|
805
822
|
];
|
|
806
823
|
function generateCode(varNames, ...args2) {
|
|
807
824
|
const options = normalizeOptions(args2);
|
|
@@ -1085,7 +1102,7 @@ Options:
|
|
|
1085
1102
|
--selector <selector> Also scan this selector's blocks, not just :root/@theme (repeatable)
|
|
1086
1103
|
--theme <name>=<sel> Theme block, emitted as @theme JSDoc tags (repeatable)
|
|
1087
1104
|
--group Nest keys by the first hyphen segment (cssVars.color.primary)
|
|
1088
|
-
--helpers Also emit CssVarRef and getCssVar/setCssVar/withFallback
|
|
1105
|
+
--helpers Also emit CssVarRef and getCssVar/setCssVar/withFallback/varName
|
|
1089
1106
|
--prune Drop vars with no cssVars.<key> usage (needs --usage)
|
|
1090
1107
|
--usage <glob> Source files to scan for cssVars usage (repeatable)
|
|
1091
1108
|
--usage-exclude <glob> Source files to skip in the usage scan (repeatable)
|
package/dist/cli.js
CHANGED
|
@@ -4,12 +4,12 @@ import {
|
|
|
4
4
|
findUndefinedRefs,
|
|
5
5
|
findUnusedVars,
|
|
6
6
|
generate
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-FWKCSH2F.js";
|
|
8
8
|
import {
|
|
9
9
|
VALID_NAMINGS,
|
|
10
10
|
createFileMatcher,
|
|
11
11
|
globWatchRoots
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-XSFYQPH6.js";
|
|
13
13
|
|
|
14
14
|
// src/cli.ts
|
|
15
15
|
import { access, readFile } from "fs/promises";
|
|
@@ -114,7 +114,7 @@ Options:
|
|
|
114
114
|
--selector <selector> Also scan this selector's blocks, not just :root/@theme (repeatable)
|
|
115
115
|
--theme <name>=<sel> Theme block, emitted as @theme JSDoc tags (repeatable)
|
|
116
116
|
--group Nest keys by the first hyphen segment (cssVars.color.primary)
|
|
117
|
-
--helpers Also emit CssVarRef and getCssVar/setCssVar/withFallback
|
|
117
|
+
--helpers Also emit CssVarRef and getCssVar/setCssVar/withFallback/varName
|
|
118
118
|
--prune Drop vars with no cssVars.<key> usage (needs --usage)
|
|
119
119
|
--usage <glob> Source files to scan for cssVars usage (repeatable)
|
|
120
120
|
--usage-exclude <glob> Source files to skip in the usage scan (repeatable)
|
package/dist/esbuild.cjs
CHANGED
|
@@ -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
|
|
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) {
|
|
@@ -719,13 +724,19 @@ var HELPERS_JS = [
|
|
|
719
724
|
"",
|
|
720
725
|
"export function withFallback(ref, fallback) {",
|
|
721
726
|
" return `${ref.slice(0, -1)}, ${fallback})`;",
|
|
727
|
+
"}",
|
|
728
|
+
"",
|
|
729
|
+
"export function varName(ref) {",
|
|
730
|
+
" return ref.slice(4, -1);",
|
|
722
731
|
"}"
|
|
723
732
|
];
|
|
724
733
|
var HELPERS_DTS = [
|
|
725
734
|
"export declare function getCssVar(ref: CssVarRef, el?: Element): string;",
|
|
726
735
|
"export declare function setCssVar(ref: CssVarRef, value: string, el?: HTMLElement): void;",
|
|
727
736
|
"export type CssVarWithFallback<R extends CssVarRef, F extends string | number> = R extends `var(${infer N})` ? `var(${N}, ${F})` : never;",
|
|
728
|
-
"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>;"
|
|
729
740
|
];
|
|
730
741
|
function generateJs(varNames, ...args) {
|
|
731
742
|
const options = normalizeOptions(args);
|
package/dist/esbuild.d.cts
CHANGED
package/dist/esbuild.d.ts
CHANGED
package/dist/esbuild.js
CHANGED
|
@@ -41,7 +41,7 @@ interface GeneratorOptions {
|
|
|
41
41
|
group?: boolean;
|
|
42
42
|
/** `@property` rules per var name, emitted as `@syntax` JSDoc tags and enum union types. */
|
|
43
43
|
properties?: Map<string, PropertyRule>;
|
|
44
|
-
/** Also emit the `CssVarRef` type and `getCssVar`/`setCssVar`
|
|
44
|
+
/** Also emit the `CssVarRef` type and `getCssVar`/`setCssVar`/`withFallback`/`varName` helpers. */
|
|
45
45
|
helpers?: boolean;
|
|
46
46
|
/** Per theme name, the values declared for it, emitted as `@theme <name> <value>` JSDoc tags. */
|
|
47
47
|
themes?: Map<string, Map<string, string>>;
|
|
@@ -41,7 +41,7 @@ interface GeneratorOptions {
|
|
|
41
41
|
group?: boolean;
|
|
42
42
|
/** `@property` rules per var name, emitted as `@syntax` JSDoc tags and enum union types. */
|
|
43
43
|
properties?: Map<string, PropertyRule>;
|
|
44
|
-
/** Also emit the `CssVarRef` type and `getCssVar`/`setCssVar`
|
|
44
|
+
/** Also emit the `CssVarRef` type and `getCssVar`/`setCssVar`/`withFallback`/`varName` helpers. */
|
|
45
45
|
helpers?: boolean;
|
|
46
46
|
/** Per theme name, the values declared for it, emitted as `@theme <name> <value>` JSDoc tags. */
|
|
47
47
|
themes?: Map<string, Map<string, string>>;
|
package/dist/index.cjs
CHANGED
|
@@ -177,9 +177,11 @@ function maskQuotedContent(text) {
|
|
|
177
177
|
}
|
|
178
178
|
return result;
|
|
179
179
|
}
|
|
180
|
+
var CLOSERS = { "(": ")", "[": "]", "{": "}" };
|
|
180
181
|
function extractValue(text, start) {
|
|
181
182
|
let i = start;
|
|
182
183
|
let quote = null;
|
|
184
|
+
const open = [];
|
|
183
185
|
for (; i < text.length; i++) {
|
|
184
186
|
const char = text[i];
|
|
185
187
|
if (quote) {
|
|
@@ -192,16 +194,19 @@ function extractValue(text, start) {
|
|
|
192
194
|
quote = char;
|
|
193
195
|
continue;
|
|
194
196
|
}
|
|
195
|
-
if (char
|
|
197
|
+
if (char in CLOSERS) open.push(CLOSERS[char]);
|
|
198
|
+
else if (char === open[open.length - 1]) open.pop();
|
|
199
|
+
else if (char === "}" || char === ";" && open.length === 0) break;
|
|
196
200
|
}
|
|
197
201
|
return text.slice(start, i).trim();
|
|
198
202
|
}
|
|
203
|
+
var IMPORTANT = /\s*!\s*important$/i;
|
|
199
204
|
function forEachProperty(block, onProperty, offset = 0) {
|
|
200
205
|
const masked = maskQuotedContent(block);
|
|
201
206
|
for (const prop of masked.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
202
207
|
const name = prop[0];
|
|
203
208
|
const colonIndex = block.indexOf(":", prop.index + name.length);
|
|
204
|
-
onProperty(name, extractValue(block, colonIndex + 1), offset + prop.index);
|
|
209
|
+
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
205
210
|
}
|
|
206
211
|
}
|
|
207
212
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
@@ -797,6 +802,12 @@ var HELPERS_TS = [
|
|
|
797
802
|
"",
|
|
798
803
|
"export function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F> {",
|
|
799
804
|
" return `${ref.slice(0, -1)}, ${fallback})` as CssVarWithFallback<R, F>;",
|
|
805
|
+
"}",
|
|
806
|
+
"",
|
|
807
|
+
"export type CssVarProperty<R extends CssVarRef> = R extends `var(${infer N})` ? N : never;",
|
|
808
|
+
"",
|
|
809
|
+
"export function varName<R extends CssVarRef>(ref: R): CssVarProperty<R> {",
|
|
810
|
+
" return ref.slice(4, -1) as CssVarProperty<R>;",
|
|
800
811
|
"}"
|
|
801
812
|
];
|
|
802
813
|
var HELPERS_JS = [
|
|
@@ -810,13 +821,19 @@ var HELPERS_JS = [
|
|
|
810
821
|
"",
|
|
811
822
|
"export function withFallback(ref, fallback) {",
|
|
812
823
|
" return `${ref.slice(0, -1)}, ${fallback})`;",
|
|
824
|
+
"}",
|
|
825
|
+
"",
|
|
826
|
+
"export function varName(ref) {",
|
|
827
|
+
" return ref.slice(4, -1);",
|
|
813
828
|
"}"
|
|
814
829
|
];
|
|
815
830
|
var HELPERS_DTS = [
|
|
816
831
|
"export declare function getCssVar(ref: CssVarRef, el?: Element): string;",
|
|
817
832
|
"export declare function setCssVar(ref: CssVarRef, value: string, el?: HTMLElement): void;",
|
|
818
833
|
"export type CssVarWithFallback<R extends CssVarRef, F extends string | number> = R extends `var(${infer N})` ? `var(${N}, ${F})` : never;",
|
|
819
|
-
"export declare function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F>;"
|
|
834
|
+
"export declare function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F>;",
|
|
835
|
+
"export type CssVarProperty<R extends CssVarRef> = R extends `var(${infer N})` ? N : never;",
|
|
836
|
+
"export declare function varName<R extends CssVarRef>(ref: R): CssVarProperty<R>;"
|
|
820
837
|
];
|
|
821
838
|
function generateCode(varNames, ...args) {
|
|
822
839
|
const options = normalizeOptions(args);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { V as VarReference, P as PropertyRule, a as VarDoc, N as NamingConvention } from './generator-
|
|
2
|
-
export { G as GeneratorOptions, T as ThemedDeclarations, g as generateCode, b as generateDeclaration, c as generateJs, d as generateTokens, p as parseDeclaredNames, e as parsePropertyRules, f as parseThemedDeclarations, h as parseVarDeclarations, i as parseVarNames, j as parseVarReferences } from './generator-
|
|
1
|
+
import { V as VarReference, P as PropertyRule, a as VarDoc, N as NamingConvention } from './generator-BokM5zux.cjs';
|
|
2
|
+
export { G as GeneratorOptions, T as ThemedDeclarations, g as generateCode, b as generateDeclaration, c as generateJs, d as generateTokens, p as parseDeclaredNames, e as parsePropertyRules, f as parseThemedDeclarations, h as parseVarDeclarations, i as parseVarNames, j as parseVarReferences } from './generator-BokM5zux.cjs';
|
|
3
3
|
|
|
4
4
|
interface ScannedCss {
|
|
5
5
|
declarations: Map<string, string>;
|
|
@@ -43,7 +43,7 @@ interface GenerateOptions {
|
|
|
43
43
|
/** Glob(s) of source files to scan for `cssVars` usage. Required when `prune` is true, or when calling `findUnusedVars`. */
|
|
44
44
|
usage?: string | string[];
|
|
45
45
|
usageExclude?: string | string[];
|
|
46
|
-
/** Also emit the `CssVarRef` type and `getCssVar`/`setCssVar`
|
|
46
|
+
/** Also emit the `CssVarRef` type and `getCssVar`/`setCssVar`/`withFallback`/`varName` helpers. */
|
|
47
47
|
helpers?: boolean;
|
|
48
48
|
/** Names (or `--prefix-*` patterns) that `findUndefinedRefs` shouldn't report, e.g. vars set from JS. */
|
|
49
49
|
refsIgnore?: string[];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { V as VarReference, P as PropertyRule, a as VarDoc, N as NamingConvention } from './generator-
|
|
2
|
-
export { G as GeneratorOptions, T as ThemedDeclarations, g as generateCode, b as generateDeclaration, c as generateJs, d as generateTokens, p as parseDeclaredNames, e as parsePropertyRules, f as parseThemedDeclarations, h as parseVarDeclarations, i as parseVarNames, j as parseVarReferences } from './generator-
|
|
1
|
+
import { V as VarReference, P as PropertyRule, a as VarDoc, N as NamingConvention } from './generator-BokM5zux.js';
|
|
2
|
+
export { G as GeneratorOptions, T as ThemedDeclarations, g as generateCode, b as generateDeclaration, c as generateJs, d as generateTokens, p as parseDeclaredNames, e as parsePropertyRules, f as parseThemedDeclarations, h as parseVarDeclarations, i as parseVarNames, j as parseVarReferences } from './generator-BokM5zux.js';
|
|
3
3
|
|
|
4
4
|
interface ScannedCss {
|
|
5
5
|
declarations: Map<string, string>;
|
|
@@ -43,7 +43,7 @@ interface GenerateOptions {
|
|
|
43
43
|
/** Glob(s) of source files to scan for `cssVars` usage. Required when `prune` is true, or when calling `findUnusedVars`. */
|
|
44
44
|
usage?: string | string[];
|
|
45
45
|
usageExclude?: string | string[];
|
|
46
|
-
/** Also emit the `CssVarRef` type and `getCssVar`/`setCssVar`
|
|
46
|
+
/** Also emit the `CssVarRef` type and `getCssVar`/`setCssVar`/`withFallback`/`varName` helpers. */
|
|
47
47
|
helpers?: boolean;
|
|
48
48
|
/** Names (or `--prefix-*` patterns) that `findUndefinedRefs` shouldn't report, e.g. vars set from JS. */
|
|
49
49
|
refsIgnore?: string[];
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
findUndefinedRefs,
|
|
5
5
|
findUnusedVars,
|
|
6
6
|
generate
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-FWKCSH2F.js";
|
|
8
8
|
import {
|
|
9
9
|
generateCode,
|
|
10
10
|
generateDeclaration,
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
scanUsedKeys,
|
|
22
22
|
scanVarDeclarations,
|
|
23
23
|
scanVarNames
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-XSFYQPH6.js";
|
|
25
25
|
export {
|
|
26
26
|
checkGenerated,
|
|
27
27
|
defineConfig,
|
package/dist/rollup.cjs
CHANGED
|
@@ -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
|
|
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) {
|
|
@@ -719,13 +724,19 @@ var HELPERS_JS = [
|
|
|
719
724
|
"",
|
|
720
725
|
"export function withFallback(ref, fallback) {",
|
|
721
726
|
" return `${ref.slice(0, -1)}, ${fallback})`;",
|
|
727
|
+
"}",
|
|
728
|
+
"",
|
|
729
|
+
"export function varName(ref) {",
|
|
730
|
+
" return ref.slice(4, -1);",
|
|
722
731
|
"}"
|
|
723
732
|
];
|
|
724
733
|
var HELPERS_DTS = [
|
|
725
734
|
"export declare function getCssVar(ref: CssVarRef, el?: Element): string;",
|
|
726
735
|
"export declare function setCssVar(ref: CssVarRef, value: string, el?: HTMLElement): void;",
|
|
727
736
|
"export type CssVarWithFallback<R extends CssVarRef, F extends string | number> = R extends `var(${infer N})` ? `var(${N}, ${F})` : never;",
|
|
728
|
-
"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>;"
|
|
729
740
|
];
|
|
730
741
|
function generateJs(varNames, ...args) {
|
|
731
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-
|
|
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
package/dist/rollup.js
CHANGED
package/dist/unplugin.cjs
CHANGED
|
@@ -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
|
|
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) {
|
|
@@ -717,13 +722,19 @@ var HELPERS_JS = [
|
|
|
717
722
|
"",
|
|
718
723
|
"export function withFallback(ref, fallback) {",
|
|
719
724
|
" return `${ref.slice(0, -1)}, ${fallback})`;",
|
|
725
|
+
"}",
|
|
726
|
+
"",
|
|
727
|
+
"export function varName(ref) {",
|
|
728
|
+
" return ref.slice(4, -1);",
|
|
720
729
|
"}"
|
|
721
730
|
];
|
|
722
731
|
var HELPERS_DTS = [
|
|
723
732
|
"export declare function getCssVar(ref: CssVarRef, el?: Element): string;",
|
|
724
733
|
"export declare function setCssVar(ref: CssVarRef, value: string, el?: HTMLElement): void;",
|
|
725
734
|
"export type CssVarWithFallback<R extends CssVarRef, F extends string | number> = R extends `var(${infer N})` ? `var(${N}, ${F})` : never;",
|
|
726
|
-
"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>;"
|
|
727
738
|
];
|
|
728
739
|
function generateJs(varNames, ...args) {
|
|
729
740
|
const options = normalizeOptions(args);
|
package/dist/unplugin.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as unplugin from 'unplugin';
|
|
2
|
-
import { N as NamingConvention } from './generator-
|
|
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`
|
|
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.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as unplugin from 'unplugin';
|
|
2
|
-
import { N as NamingConvention } from './generator-
|
|
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`
|
|
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
package/dist/vite.cjs
CHANGED
|
@@ -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
|
|
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) {
|
|
@@ -719,13 +724,19 @@ var HELPERS_JS = [
|
|
|
719
724
|
"",
|
|
720
725
|
"export function withFallback(ref, fallback) {",
|
|
721
726
|
" return `${ref.slice(0, -1)}, ${fallback})`;",
|
|
727
|
+
"}",
|
|
728
|
+
"",
|
|
729
|
+
"export function varName(ref) {",
|
|
730
|
+
" return ref.slice(4, -1);",
|
|
722
731
|
"}"
|
|
723
732
|
];
|
|
724
733
|
var HELPERS_DTS = [
|
|
725
734
|
"export declare function getCssVar(ref: CssVarRef, el?: Element): string;",
|
|
726
735
|
"export declare function setCssVar(ref: CssVarRef, value: string, el?: HTMLElement): void;",
|
|
727
736
|
"export type CssVarWithFallback<R extends CssVarRef, F extends string | number> = R extends `var(${infer N})` ? `var(${N}, ${F})` : never;",
|
|
728
|
-
"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>;"
|
|
729
740
|
];
|
|
730
741
|
function generateJs(varNames, ...args) {
|
|
731
742
|
const options = normalizeOptions(args);
|
package/dist/vite.d.cts
CHANGED
package/dist/vite.d.ts
CHANGED
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -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
|
|
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) {
|
|
@@ -719,13 +724,19 @@ var HELPERS_JS = [
|
|
|
719
724
|
"",
|
|
720
725
|
"export function withFallback(ref, fallback) {",
|
|
721
726
|
" return `${ref.slice(0, -1)}, ${fallback})`;",
|
|
727
|
+
"}",
|
|
728
|
+
"",
|
|
729
|
+
"export function varName(ref) {",
|
|
730
|
+
" return ref.slice(4, -1);",
|
|
722
731
|
"}"
|
|
723
732
|
];
|
|
724
733
|
var HELPERS_DTS = [
|
|
725
734
|
"export declare function getCssVar(ref: CssVarRef, el?: Element): string;",
|
|
726
735
|
"export declare function setCssVar(ref: CssVarRef, value: string, el?: HTMLElement): void;",
|
|
727
736
|
"export type CssVarWithFallback<R extends CssVarRef, F extends string | number> = R extends `var(${infer N})` ? `var(${N}, ${F})` : never;",
|
|
728
|
-
"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>;"
|
|
729
740
|
];
|
|
730
741
|
function generateJs(varNames, ...args) {
|
|
731
742
|
const options = normalizeOptions(args);
|
package/dist/webpack.d.cts
CHANGED
package/dist/webpack.d.ts
CHANGED
package/dist/webpack.js
CHANGED
package/package.json
CHANGED
package/schema.json
CHANGED
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"helpers": {
|
|
61
61
|
"type": "boolean",
|
|
62
|
-
"description": "Also emit the CssVarRef type and the getCssVar/setCssVar/withFallback helpers."
|
|
62
|
+
"description": "Also emit the CssVarRef type and the getCssVar/setCssVar/withFallback/varName helpers."
|
|
63
63
|
},
|
|
64
64
|
"prune": {
|
|
65
65
|
"type": "boolean",
|