css-typed-vars 0.4.10 → 0.4.11
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/{chunk-YVFKCMBF.js → chunk-CHF2ERWU.js} +36 -10
- package/dist/{chunk-3YUKUAJQ.js → chunk-EGDCGDEQ.js} +1 -1
- package/dist/{chunk-K5FAEWQE.js → chunk-IJOMZOB4.js} +1 -1
- package/dist/cli.cjs +36 -10
- package/dist/cli.js +2 -2
- package/dist/esbuild.cjs +36 -10
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +36 -10
- package/dist/index.js +2 -2
- package/dist/rollup.cjs +36 -10
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +36 -10
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +36 -10
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +36 -10
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
|
@@ -6,17 +6,40 @@ var getDirname = () => path.dirname(getFilename());
|
|
|
6
6
|
var __dirname = /* @__PURE__ */ getDirname();
|
|
7
7
|
|
|
8
8
|
// src/parser.ts
|
|
9
|
+
function extractBlock(text, start) {
|
|
10
|
+
let depth = 1;
|
|
11
|
+
let quote = null;
|
|
12
|
+
let i = start;
|
|
13
|
+
for (; i < text.length && depth > 0; i++) {
|
|
14
|
+
const char = text[i];
|
|
15
|
+
if (quote) {
|
|
16
|
+
if (char === "\\") i++;
|
|
17
|
+
else if (char === quote) quote = null;
|
|
18
|
+
} else if (char === '"' || char === "'") {
|
|
19
|
+
quote = char;
|
|
20
|
+
} else if (char === "{") {
|
|
21
|
+
depth++;
|
|
22
|
+
} else if (char === "}") {
|
|
23
|
+
depth--;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
27
|
+
}
|
|
9
28
|
function parseVarNames(css, selectors) {
|
|
10
29
|
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
11
30
|
const names = /* @__PURE__ */ new Set();
|
|
12
31
|
const allSelectors = [":root", ...selectors ?? []];
|
|
13
32
|
for (const sel of allSelectors) {
|
|
14
33
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
34
|
+
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
35
|
+
let match;
|
|
36
|
+
while (match = openRegex.exec(stripped)) {
|
|
37
|
+
const start = match.index + match[0].length;
|
|
38
|
+
const block = extractBlock(stripped, start);
|
|
39
|
+
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
18
40
|
names.add(prop[0]);
|
|
19
41
|
}
|
|
42
|
+
openRegex.lastIndex = start + block.length + 1;
|
|
20
43
|
}
|
|
21
44
|
}
|
|
22
45
|
return [...names];
|
|
@@ -44,17 +67,20 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
44
67
|
}
|
|
45
68
|
|
|
46
69
|
// src/generator.ts
|
|
70
|
+
function convertCase(value, naming) {
|
|
71
|
+
if (naming === "kebab") return value;
|
|
72
|
+
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
73
|
+
}
|
|
47
74
|
function toKey(cssVarName, naming = "camelCase") {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
51
|
-
return /^\d/.test(key) ? `_${key}` : key;
|
|
75
|
+
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
76
|
+
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
52
77
|
}
|
|
53
78
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
54
79
|
if (!prefix) return key;
|
|
55
|
-
|
|
56
|
-
if (naming === "
|
|
57
|
-
|
|
80
|
+
const normalizedPrefix = convertCase(prefix, naming);
|
|
81
|
+
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
82
|
+
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
83
|
+
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
58
84
|
}
|
|
59
85
|
function formatKey(key, naming = "camelCase") {
|
|
60
86
|
if (naming === "kebab") return `'${key}'`;
|
package/dist/cli.cjs
CHANGED
|
@@ -42,17 +42,40 @@ var import_promises = require("fs/promises");
|
|
|
42
42
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
43
43
|
|
|
44
44
|
// src/parser.ts
|
|
45
|
+
function extractBlock(text, start) {
|
|
46
|
+
let depth = 1;
|
|
47
|
+
let quote = null;
|
|
48
|
+
let i = start;
|
|
49
|
+
for (; i < text.length && depth > 0; i++) {
|
|
50
|
+
const char = text[i];
|
|
51
|
+
if (quote) {
|
|
52
|
+
if (char === "\\") i++;
|
|
53
|
+
else if (char === quote) quote = null;
|
|
54
|
+
} else if (char === '"' || char === "'") {
|
|
55
|
+
quote = char;
|
|
56
|
+
} else if (char === "{") {
|
|
57
|
+
depth++;
|
|
58
|
+
} else if (char === "}") {
|
|
59
|
+
depth--;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
63
|
+
}
|
|
45
64
|
function parseVarNames(css, selectors) {
|
|
46
65
|
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
47
66
|
const names = /* @__PURE__ */ new Set();
|
|
48
67
|
const allSelectors = [":root", ...selectors ?? []];
|
|
49
68
|
for (const sel of allSelectors) {
|
|
50
69
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
70
|
+
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
71
|
+
let match;
|
|
72
|
+
while (match = openRegex.exec(stripped)) {
|
|
73
|
+
const start = match.index + match[0].length;
|
|
74
|
+
const block = extractBlock(stripped, start);
|
|
75
|
+
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
54
76
|
names.add(prop[0]);
|
|
55
77
|
}
|
|
78
|
+
openRegex.lastIndex = start + block.length + 1;
|
|
56
79
|
}
|
|
57
80
|
}
|
|
58
81
|
return [...names];
|
|
@@ -78,17 +101,20 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
78
101
|
}
|
|
79
102
|
|
|
80
103
|
// src/generator.ts
|
|
104
|
+
function convertCase(value, naming) {
|
|
105
|
+
if (naming === "kebab") return value;
|
|
106
|
+
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
107
|
+
}
|
|
81
108
|
function toKey(cssVarName, naming = "camelCase") {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
85
|
-
return /^\d/.test(key) ? `_${key}` : key;
|
|
109
|
+
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
110
|
+
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
86
111
|
}
|
|
87
112
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
88
113
|
if (!prefix) return key;
|
|
89
|
-
|
|
90
|
-
if (naming === "
|
|
91
|
-
|
|
114
|
+
const normalizedPrefix = convertCase(prefix, naming);
|
|
115
|
+
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
116
|
+
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
117
|
+
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
92
118
|
}
|
|
93
119
|
function formatKey(key, naming = "camelCase") {
|
|
94
120
|
if (naming === "kebab") return `'${key}'`;
|
package/dist/cli.js
CHANGED
package/dist/esbuild.cjs
CHANGED
|
@@ -44,17 +44,40 @@ var import_promises = require("fs/promises");
|
|
|
44
44
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
|
+
function extractBlock(text, start) {
|
|
48
|
+
let depth = 1;
|
|
49
|
+
let quote = null;
|
|
50
|
+
let i = start;
|
|
51
|
+
for (; i < text.length && depth > 0; i++) {
|
|
52
|
+
const char = text[i];
|
|
53
|
+
if (quote) {
|
|
54
|
+
if (char === "\\") i++;
|
|
55
|
+
else if (char === quote) quote = null;
|
|
56
|
+
} else if (char === '"' || char === "'") {
|
|
57
|
+
quote = char;
|
|
58
|
+
} else if (char === "{") {
|
|
59
|
+
depth++;
|
|
60
|
+
} else if (char === "}") {
|
|
61
|
+
depth--;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
65
|
+
}
|
|
47
66
|
function parseVarNames(css, selectors) {
|
|
48
67
|
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
49
68
|
const names = /* @__PURE__ */ new Set();
|
|
50
69
|
const allSelectors = [":root", ...selectors ?? []];
|
|
51
70
|
for (const sel of allSelectors) {
|
|
52
71
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
72
|
+
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
73
|
+
let match;
|
|
74
|
+
while (match = openRegex.exec(stripped)) {
|
|
75
|
+
const start = match.index + match[0].length;
|
|
76
|
+
const block = extractBlock(stripped, start);
|
|
77
|
+
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
56
78
|
names.add(prop[0]);
|
|
57
79
|
}
|
|
80
|
+
openRegex.lastIndex = start + block.length + 1;
|
|
58
81
|
}
|
|
59
82
|
}
|
|
60
83
|
return [...names];
|
|
@@ -80,17 +103,20 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
80
103
|
}
|
|
81
104
|
|
|
82
105
|
// src/generator.ts
|
|
106
|
+
function convertCase(value, naming) {
|
|
107
|
+
if (naming === "kebab") return value;
|
|
108
|
+
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
109
|
+
}
|
|
83
110
|
function toKey(cssVarName, naming = "camelCase") {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
87
|
-
return /^\d/.test(key) ? `_${key}` : key;
|
|
111
|
+
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
112
|
+
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
88
113
|
}
|
|
89
114
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
90
115
|
if (!prefix) return key;
|
|
91
|
-
|
|
92
|
-
if (naming === "
|
|
93
|
-
|
|
116
|
+
const normalizedPrefix = convertCase(prefix, naming);
|
|
117
|
+
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
118
|
+
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
119
|
+
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
94
120
|
}
|
|
95
121
|
function formatKey(key, naming = "camelCase") {
|
|
96
122
|
if (naming === "kebab") return `'${key}'`;
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -46,17 +46,40 @@ var import_promises = require("fs/promises");
|
|
|
46
46
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
47
47
|
|
|
48
48
|
// src/parser.ts
|
|
49
|
+
function extractBlock(text, start) {
|
|
50
|
+
let depth = 1;
|
|
51
|
+
let quote = null;
|
|
52
|
+
let i = start;
|
|
53
|
+
for (; i < text.length && depth > 0; i++) {
|
|
54
|
+
const char = text[i];
|
|
55
|
+
if (quote) {
|
|
56
|
+
if (char === "\\") i++;
|
|
57
|
+
else if (char === quote) quote = null;
|
|
58
|
+
} else if (char === '"' || char === "'") {
|
|
59
|
+
quote = char;
|
|
60
|
+
} else if (char === "{") {
|
|
61
|
+
depth++;
|
|
62
|
+
} else if (char === "}") {
|
|
63
|
+
depth--;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
67
|
+
}
|
|
49
68
|
function parseVarNames(css, selectors) {
|
|
50
69
|
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
51
70
|
const names = /* @__PURE__ */ new Set();
|
|
52
71
|
const allSelectors = [":root", ...selectors ?? []];
|
|
53
72
|
for (const sel of allSelectors) {
|
|
54
73
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
74
|
+
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
75
|
+
let match;
|
|
76
|
+
while (match = openRegex.exec(stripped)) {
|
|
77
|
+
const start = match.index + match[0].length;
|
|
78
|
+
const block = extractBlock(stripped, start);
|
|
79
|
+
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
58
80
|
names.add(prop[0]);
|
|
59
81
|
}
|
|
82
|
+
openRegex.lastIndex = start + block.length + 1;
|
|
60
83
|
}
|
|
61
84
|
}
|
|
62
85
|
return [...names];
|
|
@@ -82,17 +105,20 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
82
105
|
}
|
|
83
106
|
|
|
84
107
|
// src/generator.ts
|
|
108
|
+
function convertCase(value, naming) {
|
|
109
|
+
if (naming === "kebab") return value;
|
|
110
|
+
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
111
|
+
}
|
|
85
112
|
function toKey(cssVarName, naming = "camelCase") {
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
89
|
-
return /^\d/.test(key) ? `_${key}` : key;
|
|
113
|
+
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
114
|
+
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
90
115
|
}
|
|
91
116
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
92
117
|
if (!prefix) return key;
|
|
93
|
-
|
|
94
|
-
if (naming === "
|
|
95
|
-
|
|
118
|
+
const normalizedPrefix = convertCase(prefix, naming);
|
|
119
|
+
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
120
|
+
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
121
|
+
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
96
122
|
}
|
|
97
123
|
function formatKey(key, naming = "camelCase") {
|
|
98
124
|
if (naming === "kebab") return `'${key}'`;
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
generate
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IJOMZOB4.js";
|
|
4
4
|
import {
|
|
5
5
|
generateCode,
|
|
6
6
|
generateDeclaration,
|
|
7
7
|
generateJs,
|
|
8
8
|
parseVarNames,
|
|
9
9
|
scanVarNames
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-CHF2ERWU.js";
|
|
11
11
|
export {
|
|
12
12
|
generate,
|
|
13
13
|
generateCode,
|
package/dist/rollup.cjs
CHANGED
|
@@ -44,17 +44,40 @@ var import_promises = require("fs/promises");
|
|
|
44
44
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
|
+
function extractBlock(text, start) {
|
|
48
|
+
let depth = 1;
|
|
49
|
+
let quote = null;
|
|
50
|
+
let i = start;
|
|
51
|
+
for (; i < text.length && depth > 0; i++) {
|
|
52
|
+
const char = text[i];
|
|
53
|
+
if (quote) {
|
|
54
|
+
if (char === "\\") i++;
|
|
55
|
+
else if (char === quote) quote = null;
|
|
56
|
+
} else if (char === '"' || char === "'") {
|
|
57
|
+
quote = char;
|
|
58
|
+
} else if (char === "{") {
|
|
59
|
+
depth++;
|
|
60
|
+
} else if (char === "}") {
|
|
61
|
+
depth--;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
65
|
+
}
|
|
47
66
|
function parseVarNames(css, selectors) {
|
|
48
67
|
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
49
68
|
const names = /* @__PURE__ */ new Set();
|
|
50
69
|
const allSelectors = [":root", ...selectors ?? []];
|
|
51
70
|
for (const sel of allSelectors) {
|
|
52
71
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
72
|
+
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
73
|
+
let match;
|
|
74
|
+
while (match = openRegex.exec(stripped)) {
|
|
75
|
+
const start = match.index + match[0].length;
|
|
76
|
+
const block = extractBlock(stripped, start);
|
|
77
|
+
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
56
78
|
names.add(prop[0]);
|
|
57
79
|
}
|
|
80
|
+
openRegex.lastIndex = start + block.length + 1;
|
|
58
81
|
}
|
|
59
82
|
}
|
|
60
83
|
return [...names];
|
|
@@ -80,17 +103,20 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
80
103
|
}
|
|
81
104
|
|
|
82
105
|
// src/generator.ts
|
|
106
|
+
function convertCase(value, naming) {
|
|
107
|
+
if (naming === "kebab") return value;
|
|
108
|
+
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
109
|
+
}
|
|
83
110
|
function toKey(cssVarName, naming = "camelCase") {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
87
|
-
return /^\d/.test(key) ? `_${key}` : key;
|
|
111
|
+
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
112
|
+
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
88
113
|
}
|
|
89
114
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
90
115
|
if (!prefix) return key;
|
|
91
|
-
|
|
92
|
-
if (naming === "
|
|
93
|
-
|
|
116
|
+
const normalizedPrefix = convertCase(prefix, naming);
|
|
117
|
+
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
118
|
+
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
119
|
+
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
94
120
|
}
|
|
95
121
|
function formatKey(key, naming = "camelCase") {
|
|
96
122
|
if (naming === "kebab") return `'${key}'`;
|
package/dist/rollup.js
CHANGED
package/dist/unplugin.cjs
CHANGED
|
@@ -42,17 +42,40 @@ var import_promises = require("fs/promises");
|
|
|
42
42
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
43
43
|
|
|
44
44
|
// src/parser.ts
|
|
45
|
+
function extractBlock(text, start) {
|
|
46
|
+
let depth = 1;
|
|
47
|
+
let quote = null;
|
|
48
|
+
let i = start;
|
|
49
|
+
for (; i < text.length && depth > 0; i++) {
|
|
50
|
+
const char = text[i];
|
|
51
|
+
if (quote) {
|
|
52
|
+
if (char === "\\") i++;
|
|
53
|
+
else if (char === quote) quote = null;
|
|
54
|
+
} else if (char === '"' || char === "'") {
|
|
55
|
+
quote = char;
|
|
56
|
+
} else if (char === "{") {
|
|
57
|
+
depth++;
|
|
58
|
+
} else if (char === "}") {
|
|
59
|
+
depth--;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
63
|
+
}
|
|
45
64
|
function parseVarNames(css, selectors) {
|
|
46
65
|
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
47
66
|
const names = /* @__PURE__ */ new Set();
|
|
48
67
|
const allSelectors = [":root", ...selectors ?? []];
|
|
49
68
|
for (const sel of allSelectors) {
|
|
50
69
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
70
|
+
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
71
|
+
let match;
|
|
72
|
+
while (match = openRegex.exec(stripped)) {
|
|
73
|
+
const start = match.index + match[0].length;
|
|
74
|
+
const block = extractBlock(stripped, start);
|
|
75
|
+
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
54
76
|
names.add(prop[0]);
|
|
55
77
|
}
|
|
78
|
+
openRegex.lastIndex = start + block.length + 1;
|
|
56
79
|
}
|
|
57
80
|
}
|
|
58
81
|
return [...names];
|
|
@@ -78,17 +101,20 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
78
101
|
}
|
|
79
102
|
|
|
80
103
|
// src/generator.ts
|
|
104
|
+
function convertCase(value, naming) {
|
|
105
|
+
if (naming === "kebab") return value;
|
|
106
|
+
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
107
|
+
}
|
|
81
108
|
function toKey(cssVarName, naming = "camelCase") {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
85
|
-
return /^\d/.test(key) ? `_${key}` : key;
|
|
109
|
+
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
110
|
+
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
86
111
|
}
|
|
87
112
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
88
113
|
if (!prefix) return key;
|
|
89
|
-
|
|
90
|
-
if (naming === "
|
|
91
|
-
|
|
114
|
+
const normalizedPrefix = convertCase(prefix, naming);
|
|
115
|
+
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
116
|
+
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
117
|
+
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
92
118
|
}
|
|
93
119
|
function formatKey(key, naming = "camelCase") {
|
|
94
120
|
if (naming === "kebab") return `'${key}'`;
|
package/dist/unplugin.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -44,17 +44,40 @@ var import_promises = require("fs/promises");
|
|
|
44
44
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
|
+
function extractBlock(text, start) {
|
|
48
|
+
let depth = 1;
|
|
49
|
+
let quote = null;
|
|
50
|
+
let i = start;
|
|
51
|
+
for (; i < text.length && depth > 0; i++) {
|
|
52
|
+
const char = text[i];
|
|
53
|
+
if (quote) {
|
|
54
|
+
if (char === "\\") i++;
|
|
55
|
+
else if (char === quote) quote = null;
|
|
56
|
+
} else if (char === '"' || char === "'") {
|
|
57
|
+
quote = char;
|
|
58
|
+
} else if (char === "{") {
|
|
59
|
+
depth++;
|
|
60
|
+
} else if (char === "}") {
|
|
61
|
+
depth--;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
65
|
+
}
|
|
47
66
|
function parseVarNames(css, selectors) {
|
|
48
67
|
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
49
68
|
const names = /* @__PURE__ */ new Set();
|
|
50
69
|
const allSelectors = [":root", ...selectors ?? []];
|
|
51
70
|
for (const sel of allSelectors) {
|
|
52
71
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
72
|
+
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
73
|
+
let match;
|
|
74
|
+
while (match = openRegex.exec(stripped)) {
|
|
75
|
+
const start = match.index + match[0].length;
|
|
76
|
+
const block = extractBlock(stripped, start);
|
|
77
|
+
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
56
78
|
names.add(prop[0]);
|
|
57
79
|
}
|
|
80
|
+
openRegex.lastIndex = start + block.length + 1;
|
|
58
81
|
}
|
|
59
82
|
}
|
|
60
83
|
return [...names];
|
|
@@ -80,17 +103,20 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
80
103
|
}
|
|
81
104
|
|
|
82
105
|
// src/generator.ts
|
|
106
|
+
function convertCase(value, naming) {
|
|
107
|
+
if (naming === "kebab") return value;
|
|
108
|
+
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
109
|
+
}
|
|
83
110
|
function toKey(cssVarName, naming = "camelCase") {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
87
|
-
return /^\d/.test(key) ? `_${key}` : key;
|
|
111
|
+
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
112
|
+
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
88
113
|
}
|
|
89
114
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
90
115
|
if (!prefix) return key;
|
|
91
|
-
|
|
92
|
-
if (naming === "
|
|
93
|
-
|
|
116
|
+
const normalizedPrefix = convertCase(prefix, naming);
|
|
117
|
+
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
118
|
+
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
119
|
+
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
94
120
|
}
|
|
95
121
|
function formatKey(key, naming = "camelCase") {
|
|
96
122
|
if (naming === "kebab") return `'${key}'`;
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -44,17 +44,40 @@ var import_promises = require("fs/promises");
|
|
|
44
44
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
|
+
function extractBlock(text, start) {
|
|
48
|
+
let depth = 1;
|
|
49
|
+
let quote = null;
|
|
50
|
+
let i = start;
|
|
51
|
+
for (; i < text.length && depth > 0; i++) {
|
|
52
|
+
const char = text[i];
|
|
53
|
+
if (quote) {
|
|
54
|
+
if (char === "\\") i++;
|
|
55
|
+
else if (char === quote) quote = null;
|
|
56
|
+
} else if (char === '"' || char === "'") {
|
|
57
|
+
quote = char;
|
|
58
|
+
} else if (char === "{") {
|
|
59
|
+
depth++;
|
|
60
|
+
} else if (char === "}") {
|
|
61
|
+
depth--;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
65
|
+
}
|
|
47
66
|
function parseVarNames(css, selectors) {
|
|
48
67
|
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
49
68
|
const names = /* @__PURE__ */ new Set();
|
|
50
69
|
const allSelectors = [":root", ...selectors ?? []];
|
|
51
70
|
for (const sel of allSelectors) {
|
|
52
71
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
72
|
+
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
73
|
+
let match;
|
|
74
|
+
while (match = openRegex.exec(stripped)) {
|
|
75
|
+
const start = match.index + match[0].length;
|
|
76
|
+
const block = extractBlock(stripped, start);
|
|
77
|
+
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
56
78
|
names.add(prop[0]);
|
|
57
79
|
}
|
|
80
|
+
openRegex.lastIndex = start + block.length + 1;
|
|
58
81
|
}
|
|
59
82
|
}
|
|
60
83
|
return [...names];
|
|
@@ -80,17 +103,20 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
80
103
|
}
|
|
81
104
|
|
|
82
105
|
// src/generator.ts
|
|
106
|
+
function convertCase(value, naming) {
|
|
107
|
+
if (naming === "kebab") return value;
|
|
108
|
+
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
109
|
+
}
|
|
83
110
|
function toKey(cssVarName, naming = "camelCase") {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
87
|
-
return /^\d/.test(key) ? `_${key}` : key;
|
|
111
|
+
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
112
|
+
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
88
113
|
}
|
|
89
114
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
90
115
|
if (!prefix) return key;
|
|
91
|
-
|
|
92
|
-
if (naming === "
|
|
93
|
-
|
|
116
|
+
const normalizedPrefix = convertCase(prefix, naming);
|
|
117
|
+
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
118
|
+
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
119
|
+
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
94
120
|
}
|
|
95
121
|
function formatKey(key, naming = "camelCase") {
|
|
96
122
|
if (naming === "kebab") return `'${key}'`;
|
package/dist/webpack.js
CHANGED