css-typed-vars 0.2.0 → 0.3.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 +8 -3
- package/dist/chunk-3XKCOLZL.js +26 -0
- package/dist/{chunk-6HASMGMT.js → chunk-4VL6W5GO.js} +28 -9
- package/dist/{chunk-2AQHBHAG.js → chunk-B57NHMQD.js} +4 -4
- package/dist/cli.cjs +71 -17
- package/dist/cli.js +11 -13
- package/dist/esbuild.cjs +26 -10
- package/dist/esbuild.d.cts +1 -0
- package/dist/esbuild.d.ts +1 -0
- package/dist/esbuild.js +2 -2
- package/dist/generator-Ba8XeISD.d.cts +6 -0
- package/dist/generator-Ba8XeISD.d.ts +6 -0
- package/dist/index.cjs +56 -8
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +8 -11
- package/dist/rollup.cjs +26 -10
- package/dist/rollup.d.cts +1 -0
- package/dist/rollup.d.ts +1 -0
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +26 -10
- package/dist/unplugin.d.cts +2 -0
- package/dist/unplugin.d.ts +2 -0
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +26 -10
- package/dist/vite.d.cts +1 -0
- package/dist/vite.d.ts +1 -0
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +26 -10
- package/dist/webpack.d.cts +1 -0
- package/dist/webpack.d.ts +1 -0
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -110,15 +110,17 @@ npx css-typed-vars --input "src/styles/**/*.{css,scss}" --output src/cssVars.ts
|
|
|
110
110
|
|
|
111
111
|
```sh
|
|
112
112
|
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --exclude "**/vendor/**"
|
|
113
|
-
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --prefix theme
|
|
113
|
+
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --prefix theme --naming snake
|
|
114
|
+
npx css-typed-vars --input "src/**/*.css" --output src/cssVars.js # generates .js + .d.ts
|
|
114
115
|
```
|
|
115
116
|
|
|
116
117
|
| Flag | Description |
|
|
117
118
|
|------|-------------|
|
|
118
119
|
| `--input` | Glob pattern for CSS/SCSS/Less files |
|
|
119
|
-
| `--output` |
|
|
120
|
+
| `--output` | Output file. `.ts` → TypeScript, `.js` → JavaScript + `.d.ts` alongside |
|
|
120
121
|
| `--exclude` | Glob pattern for files to exclude (single value; use config file for multiple) |
|
|
121
122
|
| `--prefix` | Prefix for generated keys: `--prefix theme` → `themeColorPrimary` |
|
|
123
|
+
| `--naming` | Key naming: `camelCase` (default), `snake`, `kebab` |
|
|
122
124
|
| `--watch` | Watch for file changes and regenerate |
|
|
123
125
|
|
|
124
126
|
CLI flags override values from the config file.
|
|
@@ -140,6 +142,7 @@ export default {
|
|
|
140
142
|
output: 'src/cssVars.ts',
|
|
141
143
|
exclude: ['**/vendor/**', '**/node_modules/**'],
|
|
142
144
|
prefix: 'theme',
|
|
145
|
+
naming: 'snake', // 'camelCase' | 'snake' | 'kebab'
|
|
143
146
|
};
|
|
144
147
|
```
|
|
145
148
|
|
|
@@ -236,6 +239,7 @@ Turbopack does not yet have a public plugin API for virtual modules. Use the CLI
|
|
|
236
239
|
| `input` | `string \| string[]` | — | Glob pattern for CSS/SCSS/Less files |
|
|
237
240
|
| `exclude` | `string \| string[]` | — | Glob pattern(s) for files to exclude |
|
|
238
241
|
| `prefix` | `string` | — | Prefix for generated keys: `'theme'` → `themeColorPrimary` |
|
|
242
|
+
| `naming` | `'camelCase' \| 'snake' \| 'kebab'` | `'camelCase'` | Key naming convention |
|
|
239
243
|
| `dts` | `string \| false` | inside `node_modules` | Path to write type declarations. `false` to skip |
|
|
240
244
|
|
|
241
245
|
---
|
|
@@ -288,9 +292,10 @@ import { generate } from 'css-typed-vars';
|
|
|
288
292
|
|
|
289
293
|
await generate({
|
|
290
294
|
input: 'src/styles/**/*.{css,scss}',
|
|
291
|
-
output: 'src/cssVars.ts',
|
|
295
|
+
output: 'src/cssVars.ts', // or 'src/cssVars.js' → generates .js + .d.ts
|
|
292
296
|
exclude: ['**/vendor/**'],
|
|
293
297
|
prefix: 'theme',
|
|
298
|
+
naming: 'snake', // 'camelCase' | 'snake' | 'kebab'
|
|
294
299
|
});
|
|
295
300
|
```
|
|
296
301
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateCode,
|
|
3
|
+
generateDeclaration,
|
|
4
|
+
generateJs,
|
|
5
|
+
scanVarNames
|
|
6
|
+
} from "./chunk-4VL6W5GO.js";
|
|
7
|
+
|
|
8
|
+
// src/index.ts
|
|
9
|
+
import { writeFile, mkdir } from "fs/promises";
|
|
10
|
+
import { dirname, resolve } from "path";
|
|
11
|
+
async function generate(options) {
|
|
12
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
13
|
+
const outPath = resolve(options.output);
|
|
14
|
+
await mkdir(dirname(outPath), { recursive: true });
|
|
15
|
+
if (options.output.endsWith(".js")) {
|
|
16
|
+
await writeFile(outPath, generateJs(names, options.prefix, options.naming), "utf8");
|
|
17
|
+
const dtsPath = outPath.replace(/\.js$/, ".d.ts");
|
|
18
|
+
await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
19
|
+
} else {
|
|
20
|
+
await writeFile(outPath, generateCode(names, options.prefix, options.naming), "utf8");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
generate
|
|
26
|
+
};
|
|
@@ -40,15 +40,27 @@ async function scanVarNames(patterns, exclude) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// src/generator.ts
|
|
43
|
-
function
|
|
44
|
-
|
|
43
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
44
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
45
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
46
|
+
if (naming === "kebab") return stripped;
|
|
47
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
45
48
|
}
|
|
46
|
-
function applyPrefix(key, prefix) {
|
|
49
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
47
50
|
if (!prefix) return key;
|
|
51
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
52
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
48
53
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
49
54
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
55
|
+
function formatKey(key, naming = "camelCase") {
|
|
56
|
+
if (naming === "kebab") return `'${key}'`;
|
|
57
|
+
return key;
|
|
58
|
+
}
|
|
59
|
+
function generateCode(varNames, prefix, naming) {
|
|
60
|
+
const entries = varNames.map((name) => {
|
|
61
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
62
|
+
return ` ${key}: 'var(${name})',`;
|
|
63
|
+
});
|
|
52
64
|
return [
|
|
53
65
|
"// generated \u2014 do not edit",
|
|
54
66
|
"export const cssVars = {",
|
|
@@ -59,17 +71,24 @@ function generateCode(varNames, prefix) {
|
|
|
59
71
|
""
|
|
60
72
|
].join("\n");
|
|
61
73
|
}
|
|
62
|
-
function generateJs(varNames, prefix) {
|
|
63
|
-
const entries = varNames.map((name) =>
|
|
74
|
+
function generateJs(varNames, prefix, naming) {
|
|
75
|
+
const entries = varNames.map((name) => {
|
|
76
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
77
|
+
return ` ${key}: 'var(${name})',`;
|
|
78
|
+
});
|
|
64
79
|
return [
|
|
80
|
+
"// generated \u2014 do not edit",
|
|
65
81
|
"export const cssVars = {",
|
|
66
82
|
...entries,
|
|
67
83
|
"};",
|
|
68
84
|
""
|
|
69
85
|
].join("\n");
|
|
70
86
|
}
|
|
71
|
-
function generateDeclaration(varNames, prefix) {
|
|
72
|
-
const entries = varNames.map((name) =>
|
|
87
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
88
|
+
const entries = varNames.map((name) => {
|
|
89
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
90
|
+
return ` ${key}: 'var(${name})';`;
|
|
91
|
+
});
|
|
73
92
|
return [
|
|
74
93
|
"export declare const cssVars: {",
|
|
75
94
|
...entries,
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
generateDeclaration,
|
|
4
4
|
generateJs,
|
|
5
5
|
scanVarNames
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-4VL6W5GO.js";
|
|
7
7
|
|
|
8
8
|
// src/unplugin.ts
|
|
9
9
|
import { createUnplugin } from "unplugin";
|
|
@@ -25,7 +25,7 @@ var unplugin_default = createUnplugin((options) => ({
|
|
|
25
25
|
const names = await scanVarNames(options.input, options.exclude);
|
|
26
26
|
const dtsPath = getDtsPath(options);
|
|
27
27
|
if (dtsPath) {
|
|
28
|
-
await writeFile(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
28
|
+
await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
29
29
|
}
|
|
30
30
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
31
31
|
if (mod) {
|
|
@@ -39,7 +39,7 @@ var unplugin_default = createUnplugin((options) => ({
|
|
|
39
39
|
const dtsPath = getDtsPath(options);
|
|
40
40
|
if (!dtsPath) return;
|
|
41
41
|
const names = await scanVarNames(options.input, options.exclude);
|
|
42
|
-
await writeFile(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
42
|
+
await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
43
43
|
},
|
|
44
44
|
resolveId(id) {
|
|
45
45
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
@@ -47,7 +47,7 @@ var unplugin_default = createUnplugin((options) => ({
|
|
|
47
47
|
async load(id) {
|
|
48
48
|
if (id === RESOLVED_ID) {
|
|
49
49
|
const names = await scanVarNames(options.input, options.exclude);
|
|
50
|
-
return generateJs(names, options.prefix);
|
|
50
|
+
return generateJs(names, options.prefix, options.naming);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
}));
|
package/dist/cli.cjs
CHANGED
|
@@ -24,11 +24,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
));
|
|
25
25
|
|
|
26
26
|
// src/cli.ts
|
|
27
|
-
var
|
|
28
|
-
var
|
|
27
|
+
var import_promises3 = require("fs/promises");
|
|
28
|
+
var import_node_path2 = require("path");
|
|
29
29
|
var import_node_url = require("url");
|
|
30
30
|
var import_chokidar = require("chokidar");
|
|
31
31
|
|
|
32
|
+
// src/index.ts
|
|
33
|
+
var import_promises2 = require("fs/promises");
|
|
34
|
+
var import_node_path = require("path");
|
|
35
|
+
|
|
32
36
|
// src/scanner.ts
|
|
33
37
|
var import_promises = require("fs/promises");
|
|
34
38
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
@@ -66,15 +70,27 @@ async function scanVarNames(patterns, exclude) {
|
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
// src/generator.ts
|
|
69
|
-
function
|
|
70
|
-
|
|
73
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
74
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
75
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
76
|
+
if (naming === "kebab") return stripped;
|
|
77
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
71
78
|
}
|
|
72
|
-
function applyPrefix(key, prefix) {
|
|
79
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
73
80
|
if (!prefix) return key;
|
|
81
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
82
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
74
83
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
75
84
|
}
|
|
76
|
-
function
|
|
77
|
-
|
|
85
|
+
function formatKey(key, naming = "camelCase") {
|
|
86
|
+
if (naming === "kebab") return `'${key}'`;
|
|
87
|
+
return key;
|
|
88
|
+
}
|
|
89
|
+
function generateCode(varNames, prefix, naming) {
|
|
90
|
+
const entries = varNames.map((name) => {
|
|
91
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
92
|
+
return ` ${key}: 'var(${name})',`;
|
|
93
|
+
});
|
|
78
94
|
return [
|
|
79
95
|
"// generated \u2014 do not edit",
|
|
80
96
|
"export const cssVars = {",
|
|
@@ -85,6 +101,46 @@ function generateCode(varNames, prefix) {
|
|
|
85
101
|
""
|
|
86
102
|
].join("\n");
|
|
87
103
|
}
|
|
104
|
+
function generateJs(varNames, prefix, naming) {
|
|
105
|
+
const entries = varNames.map((name) => {
|
|
106
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
107
|
+
return ` ${key}: 'var(${name})',`;
|
|
108
|
+
});
|
|
109
|
+
return [
|
|
110
|
+
"// generated \u2014 do not edit",
|
|
111
|
+
"export const cssVars = {",
|
|
112
|
+
...entries,
|
|
113
|
+
"};",
|
|
114
|
+
""
|
|
115
|
+
].join("\n");
|
|
116
|
+
}
|
|
117
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
118
|
+
const entries = varNames.map((name) => {
|
|
119
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
120
|
+
return ` ${key}: 'var(${name})';`;
|
|
121
|
+
});
|
|
122
|
+
return [
|
|
123
|
+
"export declare const cssVars: {",
|
|
124
|
+
...entries,
|
|
125
|
+
"};",
|
|
126
|
+
"export type CssVarName = keyof typeof cssVars;",
|
|
127
|
+
""
|
|
128
|
+
].join("\n");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// src/index.ts
|
|
132
|
+
async function generate(options) {
|
|
133
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
134
|
+
const outPath = (0, import_node_path.resolve)(options.output);
|
|
135
|
+
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
|
|
136
|
+
if (options.output.endsWith(".js")) {
|
|
137
|
+
await (0, import_promises2.writeFile)(outPath, generateJs(names, options.prefix, options.naming), "utf8");
|
|
138
|
+
const dtsPath = outPath.replace(/\.js$/, ".d.ts");
|
|
139
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
140
|
+
} else {
|
|
141
|
+
await (0, import_promises2.writeFile)(outPath, generateCode(names, options.prefix, options.naming), "utf8");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
88
144
|
|
|
89
145
|
// src/cli.ts
|
|
90
146
|
var args = process.argv.slice(2);
|
|
@@ -100,10 +156,10 @@ async function loadConfig() {
|
|
|
100
156
|
"css-typed-vars.config.json"
|
|
101
157
|
];
|
|
102
158
|
for (const file of candidates) {
|
|
103
|
-
const path = (0,
|
|
159
|
+
const path = (0, import_node_path2.resolve)(process.cwd(), file);
|
|
104
160
|
try {
|
|
105
161
|
if (file.endsWith(".json")) {
|
|
106
|
-
const content = await (0,
|
|
162
|
+
const content = await (0, import_promises3.readFile)(path, "utf8");
|
|
107
163
|
return JSON.parse(content);
|
|
108
164
|
} else {
|
|
109
165
|
const mod = await import((0, import_node_url.pathToFileURL)(path).href);
|
|
@@ -114,12 +170,9 @@ async function loadConfig() {
|
|
|
114
170
|
}
|
|
115
171
|
return {};
|
|
116
172
|
}
|
|
117
|
-
async function run(input, output, exclude, prefix) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
await (0, import_promises2.mkdir)((0, import_node_path.dirname)((0, import_node_path.resolve)(output)), { recursive: true });
|
|
121
|
-
await (0, import_promises2.writeFile)(output, code, "utf8");
|
|
122
|
-
console.log(`Generated ${names.length} variables \u2192 ${output}`);
|
|
173
|
+
async function run(input, output, exclude, prefix, naming) {
|
|
174
|
+
await generate({ input, output, exclude, prefix, naming });
|
|
175
|
+
console.log(`Generated \u2192 ${output}`);
|
|
123
176
|
}
|
|
124
177
|
async function main() {
|
|
125
178
|
const config = await loadConfig();
|
|
@@ -127,17 +180,18 @@ async function main() {
|
|
|
127
180
|
const output = getArg("--output") ?? config.output;
|
|
128
181
|
const exclude = getArg("--exclude") ?? config.exclude;
|
|
129
182
|
const prefix = getArg("--prefix") ?? config.prefix;
|
|
183
|
+
const naming = getArg("--naming") ?? config.naming;
|
|
130
184
|
if (!input || !output) {
|
|
131
185
|
console.error("Usage: css-typed-vars --input <glob> --output <file> [--watch]");
|
|
132
186
|
console.error("Or add a css-typed-vars.config.js file with input and output fields.");
|
|
133
187
|
process.exit(1);
|
|
134
188
|
}
|
|
135
|
-
await run(input, output, exclude, prefix);
|
|
189
|
+
await run(input, output, exclude, prefix, naming);
|
|
136
190
|
if (watchMode) {
|
|
137
191
|
const patterns = Array.isArray(input) ? input : [input];
|
|
138
192
|
(0, import_chokidar.watch)(patterns).on("change", (file) => {
|
|
139
193
|
console.log(`Changed: ${file}`);
|
|
140
|
-
run(input, output, exclude, prefix).catch(console.error);
|
|
194
|
+
run(input, output, exclude, prefix, naming).catch(console.error);
|
|
141
195
|
});
|
|
142
196
|
console.log("Watching for changes...");
|
|
143
197
|
}
|
package/dist/cli.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
generate
|
|
4
|
+
} from "./chunk-3XKCOLZL.js";
|
|
5
|
+
import "./chunk-4VL6W5GO.js";
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
8
|
-
import { readFile
|
|
9
|
-
import { resolve
|
|
8
|
+
import { readFile } from "fs/promises";
|
|
9
|
+
import { resolve } from "path";
|
|
10
10
|
import { pathToFileURL } from "url";
|
|
11
11
|
import { watch } from "chokidar";
|
|
12
12
|
var args = process.argv.slice(2);
|
|
@@ -36,12 +36,9 @@ async function loadConfig() {
|
|
|
36
36
|
}
|
|
37
37
|
return {};
|
|
38
38
|
}
|
|
39
|
-
async function run(input, output, exclude, prefix) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
await mkdir(dirname(resolve(output)), { recursive: true });
|
|
43
|
-
await writeFile(output, code, "utf8");
|
|
44
|
-
console.log(`Generated ${names.length} variables \u2192 ${output}`);
|
|
39
|
+
async function run(input, output, exclude, prefix, naming) {
|
|
40
|
+
await generate({ input, output, exclude, prefix, naming });
|
|
41
|
+
console.log(`Generated \u2192 ${output}`);
|
|
45
42
|
}
|
|
46
43
|
async function main() {
|
|
47
44
|
const config = await loadConfig();
|
|
@@ -49,17 +46,18 @@ async function main() {
|
|
|
49
46
|
const output = getArg("--output") ?? config.output;
|
|
50
47
|
const exclude = getArg("--exclude") ?? config.exclude;
|
|
51
48
|
const prefix = getArg("--prefix") ?? config.prefix;
|
|
49
|
+
const naming = getArg("--naming") ?? config.naming;
|
|
52
50
|
if (!input || !output) {
|
|
53
51
|
console.error("Usage: css-typed-vars --input <glob> --output <file> [--watch]");
|
|
54
52
|
console.error("Or add a css-typed-vars.config.js file with input and output fields.");
|
|
55
53
|
process.exit(1);
|
|
56
54
|
}
|
|
57
|
-
await run(input, output, exclude, prefix);
|
|
55
|
+
await run(input, output, exclude, prefix, naming);
|
|
58
56
|
if (watchMode) {
|
|
59
57
|
const patterns = Array.isArray(input) ? input : [input];
|
|
60
58
|
watch(patterns).on("change", (file) => {
|
|
61
59
|
console.log(`Changed: ${file}`);
|
|
62
|
-
run(input, output, exclude, prefix).catch(console.error);
|
|
60
|
+
run(input, output, exclude, prefix, naming).catch(console.error);
|
|
63
61
|
});
|
|
64
62
|
console.log("Watching for changes...");
|
|
65
63
|
}
|
package/dist/esbuild.cjs
CHANGED
|
@@ -76,24 +76,40 @@ async function scanVarNames(patterns, exclude) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// src/generator.ts
|
|
79
|
-
function
|
|
80
|
-
|
|
79
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
80
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
81
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
82
|
+
if (naming === "kebab") return stripped;
|
|
83
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
81
84
|
}
|
|
82
|
-
function applyPrefix(key, prefix) {
|
|
85
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
83
86
|
if (!prefix) return key;
|
|
87
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
88
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
84
89
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
85
90
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
91
|
+
function formatKey(key, naming = "camelCase") {
|
|
92
|
+
if (naming === "kebab") return `'${key}'`;
|
|
93
|
+
return key;
|
|
94
|
+
}
|
|
95
|
+
function generateJs(varNames, prefix, naming) {
|
|
96
|
+
const entries = varNames.map((name) => {
|
|
97
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
98
|
+
return ` ${key}: 'var(${name})',`;
|
|
99
|
+
});
|
|
88
100
|
return [
|
|
101
|
+
"// generated \u2014 do not edit",
|
|
89
102
|
"export const cssVars = {",
|
|
90
103
|
...entries,
|
|
91
104
|
"};",
|
|
92
105
|
""
|
|
93
106
|
].join("\n");
|
|
94
107
|
}
|
|
95
|
-
function generateDeclaration(varNames, prefix) {
|
|
96
|
-
const entries = varNames.map((name) =>
|
|
108
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
109
|
+
const entries = varNames.map((name) => {
|
|
110
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
111
|
+
return ` ${key}: 'var(${name})';`;
|
|
112
|
+
});
|
|
97
113
|
return [
|
|
98
114
|
"export declare const cssVars: {",
|
|
99
115
|
...entries,
|
|
@@ -120,7 +136,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
120
136
|
const names = await scanVarNames(options.input, options.exclude);
|
|
121
137
|
const dtsPath = getDtsPath(options);
|
|
122
138
|
if (dtsPath) {
|
|
123
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
139
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
124
140
|
}
|
|
125
141
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
126
142
|
if (mod) {
|
|
@@ -134,7 +150,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
134
150
|
const dtsPath = getDtsPath(options);
|
|
135
151
|
if (!dtsPath) return;
|
|
136
152
|
const names = await scanVarNames(options.input, options.exclude);
|
|
137
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
153
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
138
154
|
},
|
|
139
155
|
resolveId(id) {
|
|
140
156
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
@@ -142,7 +158,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
142
158
|
async load(id) {
|
|
143
159
|
if (id === RESOLVED_ID) {
|
|
144
160
|
const names = await scanVarNames(options.input, options.exclude);
|
|
145
|
-
return generateJs(names, options.prefix);
|
|
161
|
+
return generateJs(names, options.prefix, options.naming);
|
|
146
162
|
}
|
|
147
163
|
}
|
|
148
164
|
}));
|
package/dist/esbuild.d.cts
CHANGED
package/dist/esbuild.d.ts
CHANGED
package/dist/esbuild.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type NamingConvention = 'camelCase' | 'snake' | 'kebab';
|
|
2
|
+
declare function generateCode(varNames: string[], prefix?: string, naming?: NamingConvention): string;
|
|
3
|
+
declare function generateJs(varNames: string[], prefix?: string, naming?: NamingConvention): string;
|
|
4
|
+
declare function generateDeclaration(varNames: string[], prefix?: string, naming?: NamingConvention): string;
|
|
5
|
+
|
|
6
|
+
export { type NamingConvention as N, generateDeclaration as a, generateJs as b, generateCode as g };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type NamingConvention = 'camelCase' | 'snake' | 'kebab';
|
|
2
|
+
declare function generateCode(varNames: string[], prefix?: string, naming?: NamingConvention): string;
|
|
3
|
+
declare function generateJs(varNames: string[], prefix?: string, naming?: NamingConvention): string;
|
|
4
|
+
declare function generateDeclaration(varNames: string[], prefix?: string, naming?: NamingConvention): string;
|
|
5
|
+
|
|
6
|
+
export { type NamingConvention as N, generateDeclaration as a, generateJs as b, generateCode as g };
|
package/dist/index.cjs
CHANGED
|
@@ -32,6 +32,8 @@ var src_exports = {};
|
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
generate: () => generate,
|
|
34
34
|
generateCode: () => generateCode,
|
|
35
|
+
generateDeclaration: () => generateDeclaration,
|
|
36
|
+
generateJs: () => generateJs,
|
|
35
37
|
parseVarNames: () => parseVarNames,
|
|
36
38
|
scanVarNames: () => scanVarNames
|
|
37
39
|
});
|
|
@@ -76,15 +78,27 @@ async function scanVarNames(patterns, exclude) {
|
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
// src/generator.ts
|
|
79
|
-
function
|
|
80
|
-
|
|
81
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
82
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
83
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
84
|
+
if (naming === "kebab") return stripped;
|
|
85
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
81
86
|
}
|
|
82
|
-
function applyPrefix(key, prefix) {
|
|
87
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
83
88
|
if (!prefix) return key;
|
|
89
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
90
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
84
91
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
85
92
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
93
|
+
function formatKey(key, naming = "camelCase") {
|
|
94
|
+
if (naming === "kebab") return `'${key}'`;
|
|
95
|
+
return key;
|
|
96
|
+
}
|
|
97
|
+
function generateCode(varNames, prefix, naming) {
|
|
98
|
+
const entries = varNames.map((name) => {
|
|
99
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
100
|
+
return ` ${key}: 'var(${name})',`;
|
|
101
|
+
});
|
|
88
102
|
return [
|
|
89
103
|
"// generated \u2014 do not edit",
|
|
90
104
|
"export const cssVars = {",
|
|
@@ -95,18 +109,52 @@ function generateCode(varNames, prefix) {
|
|
|
95
109
|
""
|
|
96
110
|
].join("\n");
|
|
97
111
|
}
|
|
112
|
+
function generateJs(varNames, prefix, naming) {
|
|
113
|
+
const entries = varNames.map((name) => {
|
|
114
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
115
|
+
return ` ${key}: 'var(${name})',`;
|
|
116
|
+
});
|
|
117
|
+
return [
|
|
118
|
+
"// generated \u2014 do not edit",
|
|
119
|
+
"export const cssVars = {",
|
|
120
|
+
...entries,
|
|
121
|
+
"};",
|
|
122
|
+
""
|
|
123
|
+
].join("\n");
|
|
124
|
+
}
|
|
125
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
126
|
+
const entries = varNames.map((name) => {
|
|
127
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
128
|
+
return ` ${key}: 'var(${name})';`;
|
|
129
|
+
});
|
|
130
|
+
return [
|
|
131
|
+
"export declare const cssVars: {",
|
|
132
|
+
...entries,
|
|
133
|
+
"};",
|
|
134
|
+
"export type CssVarName = keyof typeof cssVars;",
|
|
135
|
+
""
|
|
136
|
+
].join("\n");
|
|
137
|
+
}
|
|
98
138
|
|
|
99
139
|
// src/index.ts
|
|
100
140
|
async function generate(options) {
|
|
101
141
|
const names = await scanVarNames(options.input, options.exclude);
|
|
102
|
-
const
|
|
103
|
-
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(
|
|
104
|
-
|
|
142
|
+
const outPath = (0, import_node_path.resolve)(options.output);
|
|
143
|
+
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
|
|
144
|
+
if (options.output.endsWith(".js")) {
|
|
145
|
+
await (0, import_promises2.writeFile)(outPath, generateJs(names, options.prefix, options.naming), "utf8");
|
|
146
|
+
const dtsPath = outPath.replace(/\.js$/, ".d.ts");
|
|
147
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
148
|
+
} else {
|
|
149
|
+
await (0, import_promises2.writeFile)(outPath, generateCode(names, options.prefix, options.naming), "utf8");
|
|
150
|
+
}
|
|
105
151
|
}
|
|
106
152
|
// Annotate the CommonJS export names for ESM import in node:
|
|
107
153
|
0 && (module.exports = {
|
|
108
154
|
generate,
|
|
109
155
|
generateCode,
|
|
156
|
+
generateDeclaration,
|
|
157
|
+
generateJs,
|
|
110
158
|
parseVarNames,
|
|
111
159
|
scanVarNames
|
|
112
160
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { N as NamingConvention } from './generator-Ba8XeISD.cjs';
|
|
2
|
+
export { g as generateCode, a as generateDeclaration, b as generateJs } from './generator-Ba8XeISD.cjs';
|
|
2
3
|
|
|
3
|
-
declare function
|
|
4
|
+
declare function parseVarNames(css: string): string[];
|
|
4
5
|
|
|
5
6
|
declare function scanVarNames(patterns: string | string[], exclude?: string | string[]): Promise<string[]>;
|
|
6
7
|
|
|
@@ -9,7 +10,8 @@ interface GenerateOptions {
|
|
|
9
10
|
output: string;
|
|
10
11
|
exclude?: string | string[];
|
|
11
12
|
prefix?: string;
|
|
13
|
+
naming?: NamingConvention;
|
|
12
14
|
}
|
|
13
15
|
declare function generate(options: GenerateOptions): Promise<void>;
|
|
14
16
|
|
|
15
|
-
export { type GenerateOptions,
|
|
17
|
+
export { type GenerateOptions, NamingConvention, generate, parseVarNames, scanVarNames };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { N as NamingConvention } from './generator-Ba8XeISD.js';
|
|
2
|
+
export { g as generateCode, a as generateDeclaration, b as generateJs } from './generator-Ba8XeISD.js';
|
|
2
3
|
|
|
3
|
-
declare function
|
|
4
|
+
declare function parseVarNames(css: string): string[];
|
|
4
5
|
|
|
5
6
|
declare function scanVarNames(patterns: string | string[], exclude?: string | string[]): Promise<string[]>;
|
|
6
7
|
|
|
@@ -9,7 +10,8 @@ interface GenerateOptions {
|
|
|
9
10
|
output: string;
|
|
10
11
|
exclude?: string | string[];
|
|
11
12
|
prefix?: string;
|
|
13
|
+
naming?: NamingConvention;
|
|
12
14
|
}
|
|
13
15
|
declare function generate(options: GenerateOptions): Promise<void>;
|
|
14
16
|
|
|
15
|
-
export { type GenerateOptions,
|
|
17
|
+
export { type GenerateOptions, NamingConvention, generate, parseVarNames, scanVarNames };
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generate
|
|
3
|
+
} from "./chunk-3XKCOLZL.js";
|
|
1
4
|
import {
|
|
2
5
|
generateCode,
|
|
6
|
+
generateDeclaration,
|
|
7
|
+
generateJs,
|
|
3
8
|
parseVarNames,
|
|
4
9
|
scanVarNames
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
|
|
7
|
-
// src/index.ts
|
|
8
|
-
import { writeFile, mkdir } from "fs/promises";
|
|
9
|
-
import { dirname, resolve } from "path";
|
|
10
|
-
async function generate(options) {
|
|
11
|
-
const names = await scanVarNames(options.input, options.exclude);
|
|
12
|
-
const code = generateCode(names, options.prefix);
|
|
13
|
-
await mkdir(dirname(resolve(options.output)), { recursive: true });
|
|
14
|
-
await writeFile(options.output, code, "utf8");
|
|
15
|
-
}
|
|
10
|
+
} from "./chunk-4VL6W5GO.js";
|
|
16
11
|
export {
|
|
17
12
|
generate,
|
|
18
13
|
generateCode,
|
|
14
|
+
generateDeclaration,
|
|
15
|
+
generateJs,
|
|
19
16
|
parseVarNames,
|
|
20
17
|
scanVarNames
|
|
21
18
|
};
|
package/dist/rollup.cjs
CHANGED
|
@@ -76,24 +76,40 @@ async function scanVarNames(patterns, exclude) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// src/generator.ts
|
|
79
|
-
function
|
|
80
|
-
|
|
79
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
80
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
81
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
82
|
+
if (naming === "kebab") return stripped;
|
|
83
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
81
84
|
}
|
|
82
|
-
function applyPrefix(key, prefix) {
|
|
85
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
83
86
|
if (!prefix) return key;
|
|
87
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
88
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
84
89
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
85
90
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
91
|
+
function formatKey(key, naming = "camelCase") {
|
|
92
|
+
if (naming === "kebab") return `'${key}'`;
|
|
93
|
+
return key;
|
|
94
|
+
}
|
|
95
|
+
function generateJs(varNames, prefix, naming) {
|
|
96
|
+
const entries = varNames.map((name) => {
|
|
97
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
98
|
+
return ` ${key}: 'var(${name})',`;
|
|
99
|
+
});
|
|
88
100
|
return [
|
|
101
|
+
"// generated \u2014 do not edit",
|
|
89
102
|
"export const cssVars = {",
|
|
90
103
|
...entries,
|
|
91
104
|
"};",
|
|
92
105
|
""
|
|
93
106
|
].join("\n");
|
|
94
107
|
}
|
|
95
|
-
function generateDeclaration(varNames, prefix) {
|
|
96
|
-
const entries = varNames.map((name) =>
|
|
108
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
109
|
+
const entries = varNames.map((name) => {
|
|
110
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
111
|
+
return ` ${key}: 'var(${name})';`;
|
|
112
|
+
});
|
|
97
113
|
return [
|
|
98
114
|
"export declare const cssVars: {",
|
|
99
115
|
...entries,
|
|
@@ -120,7 +136,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
120
136
|
const names = await scanVarNames(options.input, options.exclude);
|
|
121
137
|
const dtsPath = getDtsPath(options);
|
|
122
138
|
if (dtsPath) {
|
|
123
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
139
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
124
140
|
}
|
|
125
141
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
126
142
|
if (mod) {
|
|
@@ -134,7 +150,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
134
150
|
const dtsPath = getDtsPath(options);
|
|
135
151
|
if (!dtsPath) return;
|
|
136
152
|
const names = await scanVarNames(options.input, options.exclude);
|
|
137
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
153
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
138
154
|
},
|
|
139
155
|
resolveId(id) {
|
|
140
156
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
@@ -142,7 +158,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
142
158
|
async load(id) {
|
|
143
159
|
if (id === RESOLVED_ID) {
|
|
144
160
|
const names = await scanVarNames(options.input, options.exclude);
|
|
145
|
-
return generateJs(names, options.prefix);
|
|
161
|
+
return generateJs(names, options.prefix, options.naming);
|
|
146
162
|
}
|
|
147
163
|
}
|
|
148
164
|
}));
|
package/dist/rollup.d.cts
CHANGED
package/dist/rollup.d.ts
CHANGED
package/dist/rollup.js
CHANGED
package/dist/unplugin.cjs
CHANGED
|
@@ -74,24 +74,40 @@ async function scanVarNames(patterns, exclude) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// src/generator.ts
|
|
77
|
-
function
|
|
78
|
-
|
|
77
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
78
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
79
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
80
|
+
if (naming === "kebab") return stripped;
|
|
81
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
79
82
|
}
|
|
80
|
-
function applyPrefix(key, prefix) {
|
|
83
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
81
84
|
if (!prefix) return key;
|
|
85
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
86
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
82
87
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
83
88
|
}
|
|
84
|
-
function
|
|
85
|
-
|
|
89
|
+
function formatKey(key, naming = "camelCase") {
|
|
90
|
+
if (naming === "kebab") return `'${key}'`;
|
|
91
|
+
return key;
|
|
92
|
+
}
|
|
93
|
+
function generateJs(varNames, prefix, naming) {
|
|
94
|
+
const entries = varNames.map((name) => {
|
|
95
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
96
|
+
return ` ${key}: 'var(${name})',`;
|
|
97
|
+
});
|
|
86
98
|
return [
|
|
99
|
+
"// generated \u2014 do not edit",
|
|
87
100
|
"export const cssVars = {",
|
|
88
101
|
...entries,
|
|
89
102
|
"};",
|
|
90
103
|
""
|
|
91
104
|
].join("\n");
|
|
92
105
|
}
|
|
93
|
-
function generateDeclaration(varNames, prefix) {
|
|
94
|
-
const entries = varNames.map((name) =>
|
|
106
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
107
|
+
const entries = varNames.map((name) => {
|
|
108
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
109
|
+
return ` ${key}: 'var(${name})';`;
|
|
110
|
+
});
|
|
95
111
|
return [
|
|
96
112
|
"export declare const cssVars: {",
|
|
97
113
|
...entries,
|
|
@@ -118,7 +134,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
118
134
|
const names = await scanVarNames(options.input, options.exclude);
|
|
119
135
|
const dtsPath = getDtsPath(options);
|
|
120
136
|
if (dtsPath) {
|
|
121
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
137
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
122
138
|
}
|
|
123
139
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
124
140
|
if (mod) {
|
|
@@ -132,7 +148,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
132
148
|
const dtsPath = getDtsPath(options);
|
|
133
149
|
if (!dtsPath) return;
|
|
134
150
|
const names = await scanVarNames(options.input, options.exclude);
|
|
135
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
151
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
136
152
|
},
|
|
137
153
|
resolveId(id) {
|
|
138
154
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
@@ -140,7 +156,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
140
156
|
async load(id) {
|
|
141
157
|
if (id === RESOLVED_ID) {
|
|
142
158
|
const names = await scanVarNames(options.input, options.exclude);
|
|
143
|
-
return generateJs(names, options.prefix);
|
|
159
|
+
return generateJs(names, options.prefix, options.naming);
|
|
144
160
|
}
|
|
145
161
|
}
|
|
146
162
|
}));
|
package/dist/unplugin.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as unplugin from 'unplugin';
|
|
2
|
+
import { N as NamingConvention } from './generator-Ba8XeISD.cjs';
|
|
2
3
|
|
|
3
4
|
interface Options {
|
|
4
5
|
input: string | string[];
|
|
@@ -11,6 +12,7 @@ interface Options {
|
|
|
11
12
|
dts?: string | false;
|
|
12
13
|
exclude?: string | string[];
|
|
13
14
|
prefix?: string;
|
|
15
|
+
naming?: NamingConvention;
|
|
14
16
|
}
|
|
15
17
|
declare const _default: unplugin.UnpluginInstance<Options, boolean>;
|
|
16
18
|
|
package/dist/unplugin.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as unplugin from 'unplugin';
|
|
2
|
+
import { N as NamingConvention } from './generator-Ba8XeISD.js';
|
|
2
3
|
|
|
3
4
|
interface Options {
|
|
4
5
|
input: string | string[];
|
|
@@ -11,6 +12,7 @@ interface Options {
|
|
|
11
12
|
dts?: string | false;
|
|
12
13
|
exclude?: string | string[];
|
|
13
14
|
prefix?: string;
|
|
15
|
+
naming?: NamingConvention;
|
|
14
16
|
}
|
|
15
17
|
declare const _default: unplugin.UnpluginInstance<Options, boolean>;
|
|
16
18
|
|
package/dist/unplugin.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -76,24 +76,40 @@ async function scanVarNames(patterns, exclude) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// src/generator.ts
|
|
79
|
-
function
|
|
80
|
-
|
|
79
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
80
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
81
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
82
|
+
if (naming === "kebab") return stripped;
|
|
83
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
81
84
|
}
|
|
82
|
-
function applyPrefix(key, prefix) {
|
|
85
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
83
86
|
if (!prefix) return key;
|
|
87
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
88
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
84
89
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
85
90
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
91
|
+
function formatKey(key, naming = "camelCase") {
|
|
92
|
+
if (naming === "kebab") return `'${key}'`;
|
|
93
|
+
return key;
|
|
94
|
+
}
|
|
95
|
+
function generateJs(varNames, prefix, naming) {
|
|
96
|
+
const entries = varNames.map((name) => {
|
|
97
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
98
|
+
return ` ${key}: 'var(${name})',`;
|
|
99
|
+
});
|
|
88
100
|
return [
|
|
101
|
+
"// generated \u2014 do not edit",
|
|
89
102
|
"export const cssVars = {",
|
|
90
103
|
...entries,
|
|
91
104
|
"};",
|
|
92
105
|
""
|
|
93
106
|
].join("\n");
|
|
94
107
|
}
|
|
95
|
-
function generateDeclaration(varNames, prefix) {
|
|
96
|
-
const entries = varNames.map((name) =>
|
|
108
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
109
|
+
const entries = varNames.map((name) => {
|
|
110
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
111
|
+
return ` ${key}: 'var(${name})';`;
|
|
112
|
+
});
|
|
97
113
|
return [
|
|
98
114
|
"export declare const cssVars: {",
|
|
99
115
|
...entries,
|
|
@@ -120,7 +136,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
120
136
|
const names = await scanVarNames(options.input, options.exclude);
|
|
121
137
|
const dtsPath = getDtsPath(options);
|
|
122
138
|
if (dtsPath) {
|
|
123
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
139
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
124
140
|
}
|
|
125
141
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
126
142
|
if (mod) {
|
|
@@ -134,7 +150,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
134
150
|
const dtsPath = getDtsPath(options);
|
|
135
151
|
if (!dtsPath) return;
|
|
136
152
|
const names = await scanVarNames(options.input, options.exclude);
|
|
137
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
153
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
138
154
|
},
|
|
139
155
|
resolveId(id) {
|
|
140
156
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
@@ -142,7 +158,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
142
158
|
async load(id) {
|
|
143
159
|
if (id === RESOLVED_ID) {
|
|
144
160
|
const names = await scanVarNames(options.input, options.exclude);
|
|
145
|
-
return generateJs(names, options.prefix);
|
|
161
|
+
return generateJs(names, options.prefix, options.naming);
|
|
146
162
|
}
|
|
147
163
|
}
|
|
148
164
|
}));
|
package/dist/vite.d.cts
CHANGED
package/dist/vite.d.ts
CHANGED
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -76,24 +76,40 @@ async function scanVarNames(patterns, exclude) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// src/generator.ts
|
|
79
|
-
function
|
|
80
|
-
|
|
79
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
80
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
81
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
82
|
+
if (naming === "kebab") return stripped;
|
|
83
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
81
84
|
}
|
|
82
|
-
function applyPrefix(key, prefix) {
|
|
85
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
83
86
|
if (!prefix) return key;
|
|
87
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
88
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
84
89
|
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
85
90
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
91
|
+
function formatKey(key, naming = "camelCase") {
|
|
92
|
+
if (naming === "kebab") return `'${key}'`;
|
|
93
|
+
return key;
|
|
94
|
+
}
|
|
95
|
+
function generateJs(varNames, prefix, naming) {
|
|
96
|
+
const entries = varNames.map((name) => {
|
|
97
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
98
|
+
return ` ${key}: 'var(${name})',`;
|
|
99
|
+
});
|
|
88
100
|
return [
|
|
101
|
+
"// generated \u2014 do not edit",
|
|
89
102
|
"export const cssVars = {",
|
|
90
103
|
...entries,
|
|
91
104
|
"};",
|
|
92
105
|
""
|
|
93
106
|
].join("\n");
|
|
94
107
|
}
|
|
95
|
-
function generateDeclaration(varNames, prefix) {
|
|
96
|
-
const entries = varNames.map((name) =>
|
|
108
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
109
|
+
const entries = varNames.map((name) => {
|
|
110
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
111
|
+
return ` ${key}: 'var(${name})';`;
|
|
112
|
+
});
|
|
97
113
|
return [
|
|
98
114
|
"export declare const cssVars: {",
|
|
99
115
|
...entries,
|
|
@@ -120,7 +136,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
120
136
|
const names = await scanVarNames(options.input, options.exclude);
|
|
121
137
|
const dtsPath = getDtsPath(options);
|
|
122
138
|
if (dtsPath) {
|
|
123
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
139
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
124
140
|
}
|
|
125
141
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
126
142
|
if (mod) {
|
|
@@ -134,7 +150,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
134
150
|
const dtsPath = getDtsPath(options);
|
|
135
151
|
if (!dtsPath) return;
|
|
136
152
|
const names = await scanVarNames(options.input, options.exclude);
|
|
137
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix), "utf8");
|
|
153
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
138
154
|
},
|
|
139
155
|
resolveId(id) {
|
|
140
156
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
@@ -142,7 +158,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
142
158
|
async load(id) {
|
|
143
159
|
if (id === RESOLVED_ID) {
|
|
144
160
|
const names = await scanVarNames(options.input, options.exclude);
|
|
145
|
-
return generateJs(names, options.prefix);
|
|
161
|
+
return generateJs(names, options.prefix, options.naming);
|
|
146
162
|
}
|
|
147
163
|
}
|
|
148
164
|
}));
|
package/dist/webpack.d.cts
CHANGED
package/dist/webpack.d.ts
CHANGED
package/dist/webpack.js
CHANGED