css-typed-vars 0.12.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -4
- package/dist/{chunk-XWMRTHOE.js → chunk-3QCGO2EN.js} +1 -1
- package/dist/{chunk-ULIGESN5.js → chunk-DIGUOQES.js} +1 -1
- package/dist/{chunk-RZLASYCF.js → chunk-L2T4LBKN.js} +56 -10
- package/dist/cli.cjs +57 -11
- package/dist/cli.js +3 -3
- package/dist/esbuild.cjs +46 -7
- 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 +56 -10
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/rollup.cjs +46 -7
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.d.ts +1 -1
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +46 -7
- package/dist/unplugin.d.cts +2 -2
- package/dist/unplugin.d.ts +2 -2
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +46 -7
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +46 -7
- 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/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,20 @@ 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;
|
|
189
|
+
var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
|
|
184
190
|
function forEachProperty(block, onProperty, offset = 0) {
|
|
185
191
|
const masked = maskQuotedContent(block);
|
|
186
|
-
for (const prop of masked.matchAll(
|
|
192
|
+
for (const prop of masked.matchAll(DECLARATION_NAME)) {
|
|
187
193
|
const name = prop[0];
|
|
188
194
|
const colonIndex = block.indexOf(":", prop.index + name.length);
|
|
189
|
-
onProperty(name, extractValue(block, colonIndex + 1), offset + prop.index);
|
|
195
|
+
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
190
196
|
}
|
|
191
197
|
}
|
|
192
198
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
@@ -444,19 +450,46 @@ function rootPattern(text) {
|
|
|
444
450
|
const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
|
|
445
451
|
return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
|
|
446
452
|
}
|
|
447
|
-
var ACCESS_RE = /\s*(
|
|
453
|
+
var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
|
|
448
454
|
function readAccess(text, from) {
|
|
449
455
|
ACCESS_RE.lastIndex = from;
|
|
450
456
|
const match = ACCESS_RE.exec(text);
|
|
451
457
|
return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
|
|
452
458
|
}
|
|
459
|
+
var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
|
|
460
|
+
function readPatternKeys(text, at) {
|
|
461
|
+
let i = at - 1;
|
|
462
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
463
|
+
if (text[i] !== "=") return [];
|
|
464
|
+
i--;
|
|
465
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
466
|
+
if (text[i] !== "}") return [];
|
|
467
|
+
const open = text.lastIndexOf("{", i);
|
|
468
|
+
if (open === -1) return [];
|
|
469
|
+
const body = text.slice(open + 1, i);
|
|
470
|
+
if (body.includes("}")) return [];
|
|
471
|
+
const keys = [];
|
|
472
|
+
for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
|
|
473
|
+
const match = PATTERN_KEY_RE.exec(part);
|
|
474
|
+
if (match) keys.push(match[1] ?? match[3]);
|
|
475
|
+
}
|
|
476
|
+
return keys;
|
|
477
|
+
}
|
|
453
478
|
function extractUsage(text, into) {
|
|
454
479
|
for (const root of text.matchAll(rootPattern(text))) {
|
|
455
480
|
const first = readAccess(text, root.index + root[0].length);
|
|
456
|
-
|
|
481
|
+
const second = first && readAccess(text, first.end);
|
|
482
|
+
const destructured = second ? [] : readPatternKeys(text, root.index);
|
|
483
|
+
if (!first) {
|
|
484
|
+
for (const key of destructured) {
|
|
485
|
+
into.keys.add(key);
|
|
486
|
+
into.wholeKeys.add(key);
|
|
487
|
+
}
|
|
488
|
+
continue;
|
|
489
|
+
}
|
|
457
490
|
into.keys.add(first.key);
|
|
458
|
-
const second = readAccess(text, first.end);
|
|
459
491
|
if (second) into.paths.add(`${first.key}\0${second.key}`);
|
|
492
|
+
else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
|
|
460
493
|
else into.wholeKeys.add(first.key);
|
|
461
494
|
}
|
|
462
495
|
}
|
|
@@ -719,13 +752,19 @@ var HELPERS_JS = [
|
|
|
719
752
|
"",
|
|
720
753
|
"export function withFallback(ref, fallback) {",
|
|
721
754
|
" return `${ref.slice(0, -1)}, ${fallback})`;",
|
|
755
|
+
"}",
|
|
756
|
+
"",
|
|
757
|
+
"export function varName(ref) {",
|
|
758
|
+
" return ref.slice(4, -1);",
|
|
722
759
|
"}"
|
|
723
760
|
];
|
|
724
761
|
var HELPERS_DTS = [
|
|
725
762
|
"export declare function getCssVar(ref: CssVarRef, el?: Element): string;",
|
|
726
763
|
"export declare function setCssVar(ref: CssVarRef, value: string, el?: HTMLElement): void;",
|
|
727
764
|
"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>;"
|
|
765
|
+
"export declare function withFallback<R extends CssVarRef, F extends string | number>(ref: R, fallback: F): CssVarWithFallback<R, F>;",
|
|
766
|
+
"export type CssVarProperty<R extends CssVarRef> = R extends `var(${infer N})` ? N : never;",
|
|
767
|
+
"export declare function varName<R extends CssVarRef>(ref: R): CssVarProperty<R>;"
|
|
729
768
|
];
|
|
730
769
|
function generateJs(varNames, ...args) {
|
|
731
770
|
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",
|