css-typed-vars 0.4.11 → 0.4.13
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-CHF2ERWU.js → chunk-3GTZH4ZM.js} +53 -3
- package/dist/{chunk-IJOMZOB4.js → chunk-IBTSCKH3.js} +4 -3
- package/dist/{chunk-EGDCGDEQ.js → chunk-OKHK5KHU.js} +5 -4
- package/dist/cli.cjs +62 -7
- package/dist/cli.js +8 -4
- package/dist/esbuild.cjs +57 -6
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +56 -5
- package/dist/index.js +2 -2
- package/dist/rollup.cjs +57 -6
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +57 -6
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +57 -6
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +57 -6
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
|
@@ -6,6 +6,55 @@ var getDirname = () => path.dirname(getFilename());
|
|
|
6
6
|
var __dirname = /* @__PURE__ */ getDirname();
|
|
7
7
|
|
|
8
8
|
// src/parser.ts
|
|
9
|
+
function stripComments(text) {
|
|
10
|
+
let result = "";
|
|
11
|
+
let quote = null;
|
|
12
|
+
let urlDepth = 0;
|
|
13
|
+
for (let i = 0; i < text.length; i++) {
|
|
14
|
+
const char = text[i];
|
|
15
|
+
if (quote) {
|
|
16
|
+
result += char;
|
|
17
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
18
|
+
result += text[++i];
|
|
19
|
+
} else if (char === quote) {
|
|
20
|
+
quote = null;
|
|
21
|
+
}
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (char === '"' || char === "'") {
|
|
25
|
+
quote = char;
|
|
26
|
+
result += char;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (urlDepth > 0) {
|
|
30
|
+
if (char === "(") urlDepth++;
|
|
31
|
+
else if (char === ")") urlDepth--;
|
|
32
|
+
result += char;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (char === "(" && result.slice(-3).toLowerCase() === "url") {
|
|
36
|
+
urlDepth = 1;
|
|
37
|
+
result += char;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (char === "/" && text[i + 1] === "*") {
|
|
41
|
+
const end = text.indexOf("*/", i + 2);
|
|
42
|
+
if (end === -1) {
|
|
43
|
+
result += char;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
i = end + 1;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
|
|
50
|
+
const nl = text.indexOf("\n", i);
|
|
51
|
+
i = nl === -1 ? text.length - 1 : nl - 1;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
result += char;
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
9
58
|
function extractBlock(text, start) {
|
|
10
59
|
let depth = 1;
|
|
11
60
|
let quote = null;
|
|
@@ -26,12 +75,12 @@ function extractBlock(text, start) {
|
|
|
26
75
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
27
76
|
}
|
|
28
77
|
function parseVarNames(css, selectors) {
|
|
29
|
-
const stripped = css
|
|
78
|
+
const stripped = stripComments(css);
|
|
30
79
|
const names = /* @__PURE__ */ new Set();
|
|
31
80
|
const allSelectors = [":root", ...selectors ?? []];
|
|
32
81
|
for (const sel of allSelectors) {
|
|
33
82
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
34
|
-
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
83
|
+
const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
|
|
35
84
|
let match;
|
|
36
85
|
while (match = openRegex.exec(stripped)) {
|
|
37
86
|
const start = match.index + match[0].length;
|
|
@@ -77,7 +126,8 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
77
126
|
}
|
|
78
127
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
79
128
|
if (!prefix) return key;
|
|
80
|
-
|
|
129
|
+
let normalizedPrefix = convertCase(prefix, naming);
|
|
130
|
+
if (naming !== "kebab" && /^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
81
131
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
82
132
|
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
83
133
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
generateDeclaration,
|
|
5
5
|
generateJs,
|
|
6
6
|
scanVarNames
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-3GTZH4ZM.js";
|
|
8
8
|
|
|
9
9
|
// src/index.ts
|
|
10
10
|
import { writeFile, mkdir } from "fs/promises";
|
|
@@ -19,9 +19,10 @@ async function generate(options) {
|
|
|
19
19
|
}
|
|
20
20
|
const outPath = resolve(options.output);
|
|
21
21
|
await mkdir(dirname(outPath), { recursive: true });
|
|
22
|
-
|
|
22
|
+
const jsExtMatch = /\.(m|c)?js$/.exec(options.output);
|
|
23
|
+
if (jsExtMatch) {
|
|
23
24
|
await writeFile(outPath, generateJs(names, options.prefix, options.naming), "utf8");
|
|
24
|
-
const dtsPath = outPath.
|
|
25
|
+
const dtsPath = outPath.slice(0, -jsExtMatch[0].length) + ".d.ts";
|
|
25
26
|
await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
26
27
|
} else {
|
|
27
28
|
await writeFile(outPath, generateCode(names, options.prefix, options.naming), "utf8");
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
generateDeclaration,
|
|
4
4
|
generateJs,
|
|
5
5
|
scanVarNames
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-3GTZH4ZM.js";
|
|
7
7
|
|
|
8
8
|
// src/unplugin.ts
|
|
9
9
|
import { createUnplugin } from "unplugin";
|
|
@@ -36,9 +36,10 @@ var unplugin_default = createUnplugin((options) => {
|
|
|
36
36
|
server.ws.send({ type: "full-reload" });
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
|
|
40
|
-
server.watcher.on("
|
|
41
|
-
server.watcher.on("
|
|
39
|
+
const safeHandle = (file) => handle(file).catch(console.error);
|
|
40
|
+
server.watcher.on("change", safeHandle);
|
|
41
|
+
server.watcher.on("add", safeHandle);
|
|
42
|
+
server.watcher.on("unlink", safeHandle);
|
|
42
43
|
}
|
|
43
44
|
},
|
|
44
45
|
async buildStart() {
|
package/dist/cli.cjs
CHANGED
|
@@ -42,6 +42,55 @@ 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 stripComments(text) {
|
|
46
|
+
let result = "";
|
|
47
|
+
let quote = null;
|
|
48
|
+
let urlDepth = 0;
|
|
49
|
+
for (let i = 0; i < text.length; i++) {
|
|
50
|
+
const char = text[i];
|
|
51
|
+
if (quote) {
|
|
52
|
+
result += char;
|
|
53
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
54
|
+
result += text[++i];
|
|
55
|
+
} else if (char === quote) {
|
|
56
|
+
quote = null;
|
|
57
|
+
}
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (char === '"' || char === "'") {
|
|
61
|
+
quote = char;
|
|
62
|
+
result += char;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (urlDepth > 0) {
|
|
66
|
+
if (char === "(") urlDepth++;
|
|
67
|
+
else if (char === ")") urlDepth--;
|
|
68
|
+
result += char;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (char === "(" && result.slice(-3).toLowerCase() === "url") {
|
|
72
|
+
urlDepth = 1;
|
|
73
|
+
result += char;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (char === "/" && text[i + 1] === "*") {
|
|
77
|
+
const end = text.indexOf("*/", i + 2);
|
|
78
|
+
if (end === -1) {
|
|
79
|
+
result += char;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
i = end + 1;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
|
|
86
|
+
const nl = text.indexOf("\n", i);
|
|
87
|
+
i = nl === -1 ? text.length - 1 : nl - 1;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
result += char;
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
45
94
|
function extractBlock(text, start) {
|
|
46
95
|
let depth = 1;
|
|
47
96
|
let quote = null;
|
|
@@ -62,12 +111,12 @@ function extractBlock(text, start) {
|
|
|
62
111
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
63
112
|
}
|
|
64
113
|
function parseVarNames(css, selectors) {
|
|
65
|
-
const stripped = css
|
|
114
|
+
const stripped = stripComments(css);
|
|
66
115
|
const names = /* @__PURE__ */ new Set();
|
|
67
116
|
const allSelectors = [":root", ...selectors ?? []];
|
|
68
117
|
for (const sel of allSelectors) {
|
|
69
118
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
70
|
-
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
119
|
+
const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
|
|
71
120
|
let match;
|
|
72
121
|
while (match = openRegex.exec(stripped)) {
|
|
73
122
|
const start = match.index + match[0].length;
|
|
@@ -111,7 +160,8 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
111
160
|
}
|
|
112
161
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
113
162
|
if (!prefix) return key;
|
|
114
|
-
|
|
163
|
+
let normalizedPrefix = convertCase(prefix, naming);
|
|
164
|
+
if (naming !== "kebab" && /^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
115
165
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
116
166
|
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
117
167
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
@@ -186,9 +236,10 @@ async function generate(options) {
|
|
|
186
236
|
}
|
|
187
237
|
const outPath = (0, import_node_path.resolve)(options.output);
|
|
188
238
|
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
|
|
189
|
-
|
|
239
|
+
const jsExtMatch = /\.(m|c)?js$/.exec(options.output);
|
|
240
|
+
if (jsExtMatch) {
|
|
190
241
|
await (0, import_promises2.writeFile)(outPath, generateJs(names, options.prefix, options.naming), "utf8");
|
|
191
|
-
const dtsPath = outPath.
|
|
242
|
+
const dtsPath = outPath.slice(0, -jsExtMatch[0].length) + ".d.ts";
|
|
192
243
|
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
193
244
|
} else {
|
|
194
245
|
await (0, import_promises2.writeFile)(outPath, generateCode(names, options.prefix, options.naming), "utf8");
|
|
@@ -273,8 +324,12 @@ async function main() {
|
|
|
273
324
|
console.log(`${label}: ${file}`);
|
|
274
325
|
run(input, output, exclude, prefix, naming, selectors).catch(console.error);
|
|
275
326
|
};
|
|
276
|
-
|
|
327
|
+
const ignored = exclude ? Array.isArray(exclude) ? exclude : [exclude] : void 0;
|
|
328
|
+
(0, import_chokidar.watch)(patterns, ignored ? { ignored } : void 0).on("change", makeHandler("Changed")).on("add", makeHandler("Added")).on("unlink", makeHandler("Removed"));
|
|
277
329
|
console.log("Watching for changes...");
|
|
278
330
|
}
|
|
279
331
|
}
|
|
280
|
-
main().catch(
|
|
332
|
+
main().catch((err) => {
|
|
333
|
+
console.error(err);
|
|
334
|
+
process.exit(1);
|
|
335
|
+
});
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
generate
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-IBTSCKH3.js";
|
|
5
|
+
import "./chunk-3GTZH4ZM.js";
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
8
8
|
import { readFile } from "fs/promises";
|
|
@@ -86,8 +86,12 @@ async function main() {
|
|
|
86
86
|
console.log(`${label}: ${file}`);
|
|
87
87
|
run(input, output, exclude, prefix, naming, selectors).catch(console.error);
|
|
88
88
|
};
|
|
89
|
-
|
|
89
|
+
const ignored = exclude ? Array.isArray(exclude) ? exclude : [exclude] : void 0;
|
|
90
|
+
watch(patterns, ignored ? { ignored } : void 0).on("change", makeHandler("Changed")).on("add", makeHandler("Added")).on("unlink", makeHandler("Removed"));
|
|
90
91
|
console.log("Watching for changes...");
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
|
-
main().catch(
|
|
94
|
+
main().catch((err) => {
|
|
95
|
+
console.error(err);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
});
|
package/dist/esbuild.cjs
CHANGED
|
@@ -44,6 +44,55 @@ 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 stripComments(text) {
|
|
48
|
+
let result = "";
|
|
49
|
+
let quote = null;
|
|
50
|
+
let urlDepth = 0;
|
|
51
|
+
for (let i = 0; i < text.length; i++) {
|
|
52
|
+
const char = text[i];
|
|
53
|
+
if (quote) {
|
|
54
|
+
result += char;
|
|
55
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
56
|
+
result += text[++i];
|
|
57
|
+
} else if (char === quote) {
|
|
58
|
+
quote = null;
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (char === '"' || char === "'") {
|
|
63
|
+
quote = char;
|
|
64
|
+
result += char;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (urlDepth > 0) {
|
|
68
|
+
if (char === "(") urlDepth++;
|
|
69
|
+
else if (char === ")") urlDepth--;
|
|
70
|
+
result += char;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (char === "(" && result.slice(-3).toLowerCase() === "url") {
|
|
74
|
+
urlDepth = 1;
|
|
75
|
+
result += char;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (char === "/" && text[i + 1] === "*") {
|
|
79
|
+
const end = text.indexOf("*/", i + 2);
|
|
80
|
+
if (end === -1) {
|
|
81
|
+
result += char;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
i = end + 1;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
|
|
88
|
+
const nl = text.indexOf("\n", i);
|
|
89
|
+
i = nl === -1 ? text.length - 1 : nl - 1;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
result += char;
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
47
96
|
function extractBlock(text, start) {
|
|
48
97
|
let depth = 1;
|
|
49
98
|
let quote = null;
|
|
@@ -64,12 +113,12 @@ function extractBlock(text, start) {
|
|
|
64
113
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
65
114
|
}
|
|
66
115
|
function parseVarNames(css, selectors) {
|
|
67
|
-
const stripped = css
|
|
116
|
+
const stripped = stripComments(css);
|
|
68
117
|
const names = /* @__PURE__ */ new Set();
|
|
69
118
|
const allSelectors = [":root", ...selectors ?? []];
|
|
70
119
|
for (const sel of allSelectors) {
|
|
71
120
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
72
|
-
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
121
|
+
const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
|
|
73
122
|
let match;
|
|
74
123
|
while (match = openRegex.exec(stripped)) {
|
|
75
124
|
const start = match.index + match[0].length;
|
|
@@ -113,7 +162,8 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
113
162
|
}
|
|
114
163
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
115
164
|
if (!prefix) return key;
|
|
116
|
-
|
|
165
|
+
let normalizedPrefix = convertCase(prefix, naming);
|
|
166
|
+
if (naming !== "kebab" && /^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
117
167
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
118
168
|
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
119
169
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
@@ -177,9 +227,10 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
177
227
|
server.ws.send({ type: "full-reload" });
|
|
178
228
|
}
|
|
179
229
|
};
|
|
180
|
-
|
|
181
|
-
server.watcher.on("
|
|
182
|
-
server.watcher.on("
|
|
230
|
+
const safeHandle = (file) => handle(file).catch(console.error);
|
|
231
|
+
server.watcher.on("change", safeHandle);
|
|
232
|
+
server.watcher.on("add", safeHandle);
|
|
233
|
+
server.watcher.on("unlink", safeHandle);
|
|
183
234
|
}
|
|
184
235
|
},
|
|
185
236
|
async buildStart() {
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,55 @@ 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 stripComments(text) {
|
|
50
|
+
let result = "";
|
|
51
|
+
let quote = null;
|
|
52
|
+
let urlDepth = 0;
|
|
53
|
+
for (let i = 0; i < text.length; i++) {
|
|
54
|
+
const char = text[i];
|
|
55
|
+
if (quote) {
|
|
56
|
+
result += char;
|
|
57
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
58
|
+
result += text[++i];
|
|
59
|
+
} else if (char === quote) {
|
|
60
|
+
quote = null;
|
|
61
|
+
}
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (char === '"' || char === "'") {
|
|
65
|
+
quote = char;
|
|
66
|
+
result += char;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (urlDepth > 0) {
|
|
70
|
+
if (char === "(") urlDepth++;
|
|
71
|
+
else if (char === ")") urlDepth--;
|
|
72
|
+
result += char;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (char === "(" && result.slice(-3).toLowerCase() === "url") {
|
|
76
|
+
urlDepth = 1;
|
|
77
|
+
result += char;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (char === "/" && text[i + 1] === "*") {
|
|
81
|
+
const end = text.indexOf("*/", i + 2);
|
|
82
|
+
if (end === -1) {
|
|
83
|
+
result += char;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
i = end + 1;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
|
|
90
|
+
const nl = text.indexOf("\n", i);
|
|
91
|
+
i = nl === -1 ? text.length - 1 : nl - 1;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
result += char;
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
49
98
|
function extractBlock(text, start) {
|
|
50
99
|
let depth = 1;
|
|
51
100
|
let quote = null;
|
|
@@ -66,12 +115,12 @@ function extractBlock(text, start) {
|
|
|
66
115
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
67
116
|
}
|
|
68
117
|
function parseVarNames(css, selectors) {
|
|
69
|
-
const stripped = css
|
|
118
|
+
const stripped = stripComments(css);
|
|
70
119
|
const names = /* @__PURE__ */ new Set();
|
|
71
120
|
const allSelectors = [":root", ...selectors ?? []];
|
|
72
121
|
for (const sel of allSelectors) {
|
|
73
122
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
74
|
-
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
123
|
+
const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
|
|
75
124
|
let match;
|
|
76
125
|
while (match = openRegex.exec(stripped)) {
|
|
77
126
|
const start = match.index + match[0].length;
|
|
@@ -115,7 +164,8 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
115
164
|
}
|
|
116
165
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
117
166
|
if (!prefix) return key;
|
|
118
|
-
|
|
167
|
+
let normalizedPrefix = convertCase(prefix, naming);
|
|
168
|
+
if (naming !== "kebab" && /^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
119
169
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
120
170
|
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
121
171
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
@@ -190,9 +240,10 @@ async function generate(options) {
|
|
|
190
240
|
}
|
|
191
241
|
const outPath = (0, import_node_path.resolve)(options.output);
|
|
192
242
|
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
|
|
193
|
-
|
|
243
|
+
const jsExtMatch = /\.(m|c)?js$/.exec(options.output);
|
|
244
|
+
if (jsExtMatch) {
|
|
194
245
|
await (0, import_promises2.writeFile)(outPath, generateJs(names, options.prefix, options.naming), "utf8");
|
|
195
|
-
const dtsPath = outPath.
|
|
246
|
+
const dtsPath = outPath.slice(0, -jsExtMatch[0].length) + ".d.ts";
|
|
196
247
|
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
197
248
|
} else {
|
|
198
249
|
await (0, import_promises2.writeFile)(outPath, generateCode(names, options.prefix, options.naming), "utf8");
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
generate
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IBTSCKH3.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-3GTZH4ZM.js";
|
|
11
11
|
export {
|
|
12
12
|
generate,
|
|
13
13
|
generateCode,
|
package/dist/rollup.cjs
CHANGED
|
@@ -44,6 +44,55 @@ 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 stripComments(text) {
|
|
48
|
+
let result = "";
|
|
49
|
+
let quote = null;
|
|
50
|
+
let urlDepth = 0;
|
|
51
|
+
for (let i = 0; i < text.length; i++) {
|
|
52
|
+
const char = text[i];
|
|
53
|
+
if (quote) {
|
|
54
|
+
result += char;
|
|
55
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
56
|
+
result += text[++i];
|
|
57
|
+
} else if (char === quote) {
|
|
58
|
+
quote = null;
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (char === '"' || char === "'") {
|
|
63
|
+
quote = char;
|
|
64
|
+
result += char;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (urlDepth > 0) {
|
|
68
|
+
if (char === "(") urlDepth++;
|
|
69
|
+
else if (char === ")") urlDepth--;
|
|
70
|
+
result += char;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (char === "(" && result.slice(-3).toLowerCase() === "url") {
|
|
74
|
+
urlDepth = 1;
|
|
75
|
+
result += char;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (char === "/" && text[i + 1] === "*") {
|
|
79
|
+
const end = text.indexOf("*/", i + 2);
|
|
80
|
+
if (end === -1) {
|
|
81
|
+
result += char;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
i = end + 1;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
|
|
88
|
+
const nl = text.indexOf("\n", i);
|
|
89
|
+
i = nl === -1 ? text.length - 1 : nl - 1;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
result += char;
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
47
96
|
function extractBlock(text, start) {
|
|
48
97
|
let depth = 1;
|
|
49
98
|
let quote = null;
|
|
@@ -64,12 +113,12 @@ function extractBlock(text, start) {
|
|
|
64
113
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
65
114
|
}
|
|
66
115
|
function parseVarNames(css, selectors) {
|
|
67
|
-
const stripped = css
|
|
116
|
+
const stripped = stripComments(css);
|
|
68
117
|
const names = /* @__PURE__ */ new Set();
|
|
69
118
|
const allSelectors = [":root", ...selectors ?? []];
|
|
70
119
|
for (const sel of allSelectors) {
|
|
71
120
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
72
|
-
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
121
|
+
const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
|
|
73
122
|
let match;
|
|
74
123
|
while (match = openRegex.exec(stripped)) {
|
|
75
124
|
const start = match.index + match[0].length;
|
|
@@ -113,7 +162,8 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
113
162
|
}
|
|
114
163
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
115
164
|
if (!prefix) return key;
|
|
116
|
-
|
|
165
|
+
let normalizedPrefix = convertCase(prefix, naming);
|
|
166
|
+
if (naming !== "kebab" && /^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
117
167
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
118
168
|
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
119
169
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
@@ -177,9 +227,10 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
177
227
|
server.ws.send({ type: "full-reload" });
|
|
178
228
|
}
|
|
179
229
|
};
|
|
180
|
-
|
|
181
|
-
server.watcher.on("
|
|
182
|
-
server.watcher.on("
|
|
230
|
+
const safeHandle = (file) => handle(file).catch(console.error);
|
|
231
|
+
server.watcher.on("change", safeHandle);
|
|
232
|
+
server.watcher.on("add", safeHandle);
|
|
233
|
+
server.watcher.on("unlink", safeHandle);
|
|
183
234
|
}
|
|
184
235
|
},
|
|
185
236
|
async buildStart() {
|
package/dist/rollup.js
CHANGED
package/dist/unplugin.cjs
CHANGED
|
@@ -42,6 +42,55 @@ 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 stripComments(text) {
|
|
46
|
+
let result = "";
|
|
47
|
+
let quote = null;
|
|
48
|
+
let urlDepth = 0;
|
|
49
|
+
for (let i = 0; i < text.length; i++) {
|
|
50
|
+
const char = text[i];
|
|
51
|
+
if (quote) {
|
|
52
|
+
result += char;
|
|
53
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
54
|
+
result += text[++i];
|
|
55
|
+
} else if (char === quote) {
|
|
56
|
+
quote = null;
|
|
57
|
+
}
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (char === '"' || char === "'") {
|
|
61
|
+
quote = char;
|
|
62
|
+
result += char;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (urlDepth > 0) {
|
|
66
|
+
if (char === "(") urlDepth++;
|
|
67
|
+
else if (char === ")") urlDepth--;
|
|
68
|
+
result += char;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (char === "(" && result.slice(-3).toLowerCase() === "url") {
|
|
72
|
+
urlDepth = 1;
|
|
73
|
+
result += char;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (char === "/" && text[i + 1] === "*") {
|
|
77
|
+
const end = text.indexOf("*/", i + 2);
|
|
78
|
+
if (end === -1) {
|
|
79
|
+
result += char;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
i = end + 1;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
|
|
86
|
+
const nl = text.indexOf("\n", i);
|
|
87
|
+
i = nl === -1 ? text.length - 1 : nl - 1;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
result += char;
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
45
94
|
function extractBlock(text, start) {
|
|
46
95
|
let depth = 1;
|
|
47
96
|
let quote = null;
|
|
@@ -62,12 +111,12 @@ function extractBlock(text, start) {
|
|
|
62
111
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
63
112
|
}
|
|
64
113
|
function parseVarNames(css, selectors) {
|
|
65
|
-
const stripped = css
|
|
114
|
+
const stripped = stripComments(css);
|
|
66
115
|
const names = /* @__PURE__ */ new Set();
|
|
67
116
|
const allSelectors = [":root", ...selectors ?? []];
|
|
68
117
|
for (const sel of allSelectors) {
|
|
69
118
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
70
|
-
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
119
|
+
const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
|
|
71
120
|
let match;
|
|
72
121
|
while (match = openRegex.exec(stripped)) {
|
|
73
122
|
const start = match.index + match[0].length;
|
|
@@ -111,7 +160,8 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
111
160
|
}
|
|
112
161
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
113
162
|
if (!prefix) return key;
|
|
114
|
-
|
|
163
|
+
let normalizedPrefix = convertCase(prefix, naming);
|
|
164
|
+
if (naming !== "kebab" && /^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
115
165
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
116
166
|
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
117
167
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
@@ -175,9 +225,10 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
175
225
|
server.ws.send({ type: "full-reload" });
|
|
176
226
|
}
|
|
177
227
|
};
|
|
178
|
-
|
|
179
|
-
server.watcher.on("
|
|
180
|
-
server.watcher.on("
|
|
228
|
+
const safeHandle = (file) => handle(file).catch(console.error);
|
|
229
|
+
server.watcher.on("change", safeHandle);
|
|
230
|
+
server.watcher.on("add", safeHandle);
|
|
231
|
+
server.watcher.on("unlink", safeHandle);
|
|
181
232
|
}
|
|
182
233
|
},
|
|
183
234
|
async buildStart() {
|
package/dist/unplugin.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -44,6 +44,55 @@ 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 stripComments(text) {
|
|
48
|
+
let result = "";
|
|
49
|
+
let quote = null;
|
|
50
|
+
let urlDepth = 0;
|
|
51
|
+
for (let i = 0; i < text.length; i++) {
|
|
52
|
+
const char = text[i];
|
|
53
|
+
if (quote) {
|
|
54
|
+
result += char;
|
|
55
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
56
|
+
result += text[++i];
|
|
57
|
+
} else if (char === quote) {
|
|
58
|
+
quote = null;
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (char === '"' || char === "'") {
|
|
63
|
+
quote = char;
|
|
64
|
+
result += char;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (urlDepth > 0) {
|
|
68
|
+
if (char === "(") urlDepth++;
|
|
69
|
+
else if (char === ")") urlDepth--;
|
|
70
|
+
result += char;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (char === "(" && result.slice(-3).toLowerCase() === "url") {
|
|
74
|
+
urlDepth = 1;
|
|
75
|
+
result += char;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (char === "/" && text[i + 1] === "*") {
|
|
79
|
+
const end = text.indexOf("*/", i + 2);
|
|
80
|
+
if (end === -1) {
|
|
81
|
+
result += char;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
i = end + 1;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
|
|
88
|
+
const nl = text.indexOf("\n", i);
|
|
89
|
+
i = nl === -1 ? text.length - 1 : nl - 1;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
result += char;
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
47
96
|
function extractBlock(text, start) {
|
|
48
97
|
let depth = 1;
|
|
49
98
|
let quote = null;
|
|
@@ -64,12 +113,12 @@ function extractBlock(text, start) {
|
|
|
64
113
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
65
114
|
}
|
|
66
115
|
function parseVarNames(css, selectors) {
|
|
67
|
-
const stripped = css
|
|
116
|
+
const stripped = stripComments(css);
|
|
68
117
|
const names = /* @__PURE__ */ new Set();
|
|
69
118
|
const allSelectors = [":root", ...selectors ?? []];
|
|
70
119
|
for (const sel of allSelectors) {
|
|
71
120
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
72
|
-
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
121
|
+
const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
|
|
73
122
|
let match;
|
|
74
123
|
while (match = openRegex.exec(stripped)) {
|
|
75
124
|
const start = match.index + match[0].length;
|
|
@@ -113,7 +162,8 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
113
162
|
}
|
|
114
163
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
115
164
|
if (!prefix) return key;
|
|
116
|
-
|
|
165
|
+
let normalizedPrefix = convertCase(prefix, naming);
|
|
166
|
+
if (naming !== "kebab" && /^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
117
167
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
118
168
|
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
119
169
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
@@ -177,9 +227,10 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
177
227
|
server.ws.send({ type: "full-reload" });
|
|
178
228
|
}
|
|
179
229
|
};
|
|
180
|
-
|
|
181
|
-
server.watcher.on("
|
|
182
|
-
server.watcher.on("
|
|
230
|
+
const safeHandle = (file) => handle(file).catch(console.error);
|
|
231
|
+
server.watcher.on("change", safeHandle);
|
|
232
|
+
server.watcher.on("add", safeHandle);
|
|
233
|
+
server.watcher.on("unlink", safeHandle);
|
|
183
234
|
}
|
|
184
235
|
},
|
|
185
236
|
async buildStart() {
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -44,6 +44,55 @@ 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 stripComments(text) {
|
|
48
|
+
let result = "";
|
|
49
|
+
let quote = null;
|
|
50
|
+
let urlDepth = 0;
|
|
51
|
+
for (let i = 0; i < text.length; i++) {
|
|
52
|
+
const char = text[i];
|
|
53
|
+
if (quote) {
|
|
54
|
+
result += char;
|
|
55
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
56
|
+
result += text[++i];
|
|
57
|
+
} else if (char === quote) {
|
|
58
|
+
quote = null;
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (char === '"' || char === "'") {
|
|
63
|
+
quote = char;
|
|
64
|
+
result += char;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (urlDepth > 0) {
|
|
68
|
+
if (char === "(") urlDepth++;
|
|
69
|
+
else if (char === ")") urlDepth--;
|
|
70
|
+
result += char;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (char === "(" && result.slice(-3).toLowerCase() === "url") {
|
|
74
|
+
urlDepth = 1;
|
|
75
|
+
result += char;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (char === "/" && text[i + 1] === "*") {
|
|
79
|
+
const end = text.indexOf("*/", i + 2);
|
|
80
|
+
if (end === -1) {
|
|
81
|
+
result += char;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
i = end + 1;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
|
|
88
|
+
const nl = text.indexOf("\n", i);
|
|
89
|
+
i = nl === -1 ? text.length - 1 : nl - 1;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
result += char;
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
47
96
|
function extractBlock(text, start) {
|
|
48
97
|
let depth = 1;
|
|
49
98
|
let quote = null;
|
|
@@ -64,12 +113,12 @@ function extractBlock(text, start) {
|
|
|
64
113
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
65
114
|
}
|
|
66
115
|
function parseVarNames(css, selectors) {
|
|
67
|
-
const stripped = css
|
|
116
|
+
const stripped = stripComments(css);
|
|
68
117
|
const names = /* @__PURE__ */ new Set();
|
|
69
118
|
const allSelectors = [":root", ...selectors ?? []];
|
|
70
119
|
for (const sel of allSelectors) {
|
|
71
120
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
72
|
-
const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
|
|
121
|
+
const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
|
|
73
122
|
let match;
|
|
74
123
|
while (match = openRegex.exec(stripped)) {
|
|
75
124
|
const start = match.index + match[0].length;
|
|
@@ -113,7 +162,8 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
113
162
|
}
|
|
114
163
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
115
164
|
if (!prefix) return key;
|
|
116
|
-
|
|
165
|
+
let normalizedPrefix = convertCase(prefix, naming);
|
|
166
|
+
if (naming !== "kebab" && /^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
117
167
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
118
168
|
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
119
169
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
@@ -177,9 +227,10 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
177
227
|
server.ws.send({ type: "full-reload" });
|
|
178
228
|
}
|
|
179
229
|
};
|
|
180
|
-
|
|
181
|
-
server.watcher.on("
|
|
182
|
-
server.watcher.on("
|
|
230
|
+
const safeHandle = (file) => handle(file).catch(console.error);
|
|
231
|
+
server.watcher.on("change", safeHandle);
|
|
232
|
+
server.watcher.on("add", safeHandle);
|
|
233
|
+
server.watcher.on("unlink", safeHandle);
|
|
183
234
|
}
|
|
184
235
|
},
|
|
185
236
|
async buildStart() {
|
package/dist/webpack.js
CHANGED