css-typed-vars 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -110,16 +110,19 @@ 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` | Path to the generated TypeScript file |
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 |
125
+ | `--version`, `-v` | Print the version number and exit |
123
126
 
124
127
  CLI flags override values from the config file.
125
128
 
@@ -140,6 +143,7 @@ export default {
140
143
  output: 'src/cssVars.ts',
141
144
  exclude: ['**/vendor/**', '**/node_modules/**'],
142
145
  prefix: 'theme',
146
+ naming: 'snake', // 'camelCase' | 'snake' | 'kebab'
143
147
  };
144
148
  ```
145
149
 
@@ -236,6 +240,7 @@ Turbopack does not yet have a public plugin API for virtual modules. Use the CLI
236
240
  | `input` | `string \| string[]` | — | Glob pattern for CSS/SCSS/Less files |
237
241
  | `exclude` | `string \| string[]` | — | Glob pattern(s) for files to exclude |
238
242
  | `prefix` | `string` | — | Prefix for generated keys: `'theme'` → `themeColorPrimary` |
243
+ | `naming` | `'camelCase' \| 'snake' \| 'kebab'` | `'camelCase'` | Key naming convention |
239
244
  | `dts` | `string \| false` | inside `node_modules` | Path to write type declarations. `false` to skip |
240
245
 
241
246
  ---
@@ -288,9 +293,10 @@ import { generate } from 'css-typed-vars';
288
293
 
289
294
  await generate({
290
295
  input: 'src/styles/**/*.{css,scss}',
291
- output: 'src/cssVars.ts',
296
+ output: 'src/cssVars.ts', // or 'src/cssVars.js' → generates .js + .d.ts
292
297
  exclude: ['**/vendor/**'],
293
298
  prefix: 'theme',
299
+ naming: 'snake', // 'camelCase' | 'snake' | 'kebab'
294
300
  });
295
301
  ```
296
302
 
@@ -40,15 +40,27 @@ async function scanVarNames(patterns, exclude) {
40
40
  }
41
41
 
42
42
  // src/generator.ts
43
- function toCamelCase(cssVarName) {
44
- return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
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 generateCode(varNames, prefix) {
51
- const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
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) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${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) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${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-6HASMGMT.js";
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
  }));
@@ -0,0 +1,29 @@
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
+ if (names.length === 0) {
14
+ console.warn("css-typed-vars: no CSS custom properties found.");
15
+ }
16
+ const outPath = resolve(options.output);
17
+ await mkdir(dirname(outPath), { recursive: true });
18
+ if (options.output.endsWith(".js")) {
19
+ await writeFile(outPath, generateJs(names, options.prefix, options.naming), "utf8");
20
+ const dtsPath = outPath.replace(/\.js$/, ".d.ts");
21
+ await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
22
+ } else {
23
+ await writeFile(outPath, generateCode(names, options.prefix, options.naming), "utf8");
24
+ }
25
+ }
26
+
27
+ export {
28
+ generate
29
+ };
package/dist/cli.cjs CHANGED
@@ -23,12 +23,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  mod
24
24
  ));
25
25
 
26
+ // node_modules/tsup/assets/cjs_shims.js
27
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
28
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
29
+
26
30
  // src/cli.ts
27
- var import_promises2 = require("fs/promises");
28
- var import_node_path = require("path");
31
+ var import_promises3 = require("fs/promises");
32
+ var import_node_path2 = require("path");
29
33
  var import_node_url = require("url");
30
34
  var import_chokidar = require("chokidar");
31
35
 
36
+ // src/index.ts
37
+ var import_promises2 = require("fs/promises");
38
+ var import_node_path = require("path");
39
+
32
40
  // src/scanner.ts
33
41
  var import_promises = require("fs/promises");
34
42
  var import_fast_glob = __toESM(require("fast-glob"), 1);
@@ -66,15 +74,27 @@ async function scanVarNames(patterns, exclude) {
66
74
  }
67
75
 
68
76
  // src/generator.ts
69
- function toCamelCase(cssVarName) {
70
- return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
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());
71
82
  }
72
- function applyPrefix(key, prefix) {
83
+ function applyPrefix(key, prefix, naming = "camelCase") {
73
84
  if (!prefix) return key;
85
+ if (naming === "snake") return `${prefix}_${key}`;
86
+ if (naming === "kebab") return `${prefix}-${key}`;
74
87
  return prefix + key.charAt(0).toUpperCase() + key.slice(1);
75
88
  }
76
- function generateCode(varNames, prefix) {
77
- const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
89
+ function formatKey(key, naming = "camelCase") {
90
+ if (naming === "kebab") return `'${key}'`;
91
+ return key;
92
+ }
93
+ function generateCode(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
+ });
78
98
  return [
79
99
  "// generated \u2014 do not edit",
80
100
  "export const cssVars = {",
@@ -85,6 +105,49 @@ function generateCode(varNames, prefix) {
85
105
  ""
86
106
  ].join("\n");
87
107
  }
108
+ function generateJs(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
+ });
113
+ return [
114
+ "// generated \u2014 do not edit",
115
+ "export const cssVars = {",
116
+ ...entries,
117
+ "};",
118
+ ""
119
+ ].join("\n");
120
+ }
121
+ function generateDeclaration(varNames, prefix, naming) {
122
+ const entries = varNames.map((name) => {
123
+ const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
124
+ return ` ${key}: 'var(${name})';`;
125
+ });
126
+ return [
127
+ "export declare const cssVars: {",
128
+ ...entries,
129
+ "};",
130
+ "export type CssVarName = keyof typeof cssVars;",
131
+ ""
132
+ ].join("\n");
133
+ }
134
+
135
+ // src/index.ts
136
+ async function generate(options) {
137
+ const names = await scanVarNames(options.input, options.exclude);
138
+ if (names.length === 0) {
139
+ console.warn("css-typed-vars: no CSS custom properties found.");
140
+ }
141
+ const outPath = (0, import_node_path.resolve)(options.output);
142
+ await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
143
+ if (options.output.endsWith(".js")) {
144
+ await (0, import_promises2.writeFile)(outPath, generateJs(names, options.prefix, options.naming), "utf8");
145
+ const dtsPath = outPath.replace(/\.js$/, ".d.ts");
146
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
147
+ } else {
148
+ await (0, import_promises2.writeFile)(outPath, generateCode(names, options.prefix, options.naming), "utf8");
149
+ }
150
+ }
88
151
 
89
152
  // src/cli.ts
90
153
  var args = process.argv.slice(2);
@@ -100,10 +163,10 @@ async function loadConfig() {
100
163
  "css-typed-vars.config.json"
101
164
  ];
102
165
  for (const file of candidates) {
103
- const path = (0, import_node_path.resolve)(process.cwd(), file);
166
+ const path = (0, import_node_path2.resolve)(process.cwd(), file);
104
167
  try {
105
168
  if (file.endsWith(".json")) {
106
- const content = await (0, import_promises2.readFile)(path, "utf8");
169
+ const content = await (0, import_promises3.readFile)(path, "utf8");
107
170
  return JSON.parse(content);
108
171
  } else {
109
172
  const mod = await import((0, import_node_url.pathToFileURL)(path).href);
@@ -114,31 +177,35 @@ async function loadConfig() {
114
177
  }
115
178
  return {};
116
179
  }
117
- async function run(input, output, exclude, prefix) {
118
- const names = await scanVarNames(input, exclude);
119
- const code = generateCode(names, prefix);
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}`);
180
+ async function run(input, output, exclude, prefix, naming) {
181
+ await generate({ input, output, exclude, prefix, naming });
182
+ console.log(`Generated \u2192 ${output}`);
123
183
  }
124
184
  async function main() {
185
+ if (args.includes("--version") || args.includes("-v")) {
186
+ const pkg = JSON.parse(await (0, import_promises3.readFile)(new URL("../package.json", importMetaUrl), "utf8"));
187
+ console.log(pkg.version);
188
+ process.exit(0);
189
+ }
125
190
  const config = await loadConfig();
126
191
  const input = getArg("--input") ?? config.input;
127
192
  const output = getArg("--output") ?? config.output;
128
193
  const exclude = getArg("--exclude") ?? config.exclude;
129
194
  const prefix = getArg("--prefix") ?? config.prefix;
195
+ const naming = getArg("--naming") ?? config.naming;
130
196
  if (!input || !output) {
131
197
  console.error("Usage: css-typed-vars --input <glob> --output <file> [--watch]");
132
198
  console.error("Or add a css-typed-vars.config.js file with input and output fields.");
133
199
  process.exit(1);
134
200
  }
135
- await run(input, output, exclude, prefix);
201
+ await run(input, output, exclude, prefix, naming);
136
202
  if (watchMode) {
137
203
  const patterns = Array.isArray(input) ? input : [input];
138
- (0, import_chokidar.watch)(patterns).on("change", (file) => {
139
- console.log(`Changed: ${file}`);
140
- run(input, output, exclude, prefix).catch(console.error);
141
- });
204
+ const makeHandler = (label) => (file) => {
205
+ console.log(`${label}: ${file}`);
206
+ run(input, output, exclude, prefix, naming).catch(console.error);
207
+ };
208
+ (0, import_chokidar.watch)(patterns).on("change", makeHandler("Changed")).on("add", makeHandler("Added")).on("unlink", makeHandler("Removed"));
142
209
  console.log("Watching for changes...");
143
210
  }
144
211
  }
package/dist/cli.js CHANGED
@@ -1,12 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- generateCode,
4
- scanVarNames
5
- } from "./chunk-6HASMGMT.js";
3
+ generate
4
+ } from "./chunk-S2QNFCPF.js";
5
+ import "./chunk-4VL6W5GO.js";
6
6
 
7
7
  // src/cli.ts
8
- import { readFile, writeFile, mkdir } from "fs/promises";
9
- import { resolve, dirname } from "path";
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,31 +36,35 @@ async function loadConfig() {
36
36
  }
37
37
  return {};
38
38
  }
39
- async function run(input, output, exclude, prefix) {
40
- const names = await scanVarNames(input, exclude);
41
- const code = generateCode(names, prefix);
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() {
44
+ if (args.includes("--version") || args.includes("-v")) {
45
+ const pkg = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8"));
46
+ console.log(pkg.version);
47
+ process.exit(0);
48
+ }
47
49
  const config = await loadConfig();
48
50
  const input = getArg("--input") ?? config.input;
49
51
  const output = getArg("--output") ?? config.output;
50
52
  const exclude = getArg("--exclude") ?? config.exclude;
51
53
  const prefix = getArg("--prefix") ?? config.prefix;
54
+ const naming = getArg("--naming") ?? config.naming;
52
55
  if (!input || !output) {
53
56
  console.error("Usage: css-typed-vars --input <glob> --output <file> [--watch]");
54
57
  console.error("Or add a css-typed-vars.config.js file with input and output fields.");
55
58
  process.exit(1);
56
59
  }
57
- await run(input, output, exclude, prefix);
60
+ await run(input, output, exclude, prefix, naming);
58
61
  if (watchMode) {
59
62
  const patterns = Array.isArray(input) ? input : [input];
60
- watch(patterns).on("change", (file) => {
61
- console.log(`Changed: ${file}`);
62
- run(input, output, exclude, prefix).catch(console.error);
63
- });
63
+ const makeHandler = (label) => (file) => {
64
+ console.log(`${label}: ${file}`);
65
+ run(input, output, exclude, prefix, naming).catch(console.error);
66
+ };
67
+ watch(patterns).on("change", makeHandler("Changed")).on("add", makeHandler("Added")).on("unlink", makeHandler("Removed"));
64
68
  console.log("Watching for changes...");
65
69
  }
66
70
  }
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 toCamelCase(cssVarName) {
80
- return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
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 generateJs(varNames, prefix) {
87
- const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
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) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${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
  }));
@@ -1,6 +1,7 @@
1
1
  import * as esbuild from 'esbuild';
2
2
  import { Options } from './unplugin.cjs';
3
3
  import 'unplugin';
4
+ import './generator-Ba8XeISD.cjs';
4
5
 
5
6
  declare const _default: (options: Options) => esbuild.Plugin;
6
7
 
package/dist/esbuild.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as esbuild from 'esbuild';
2
2
  import { Options } from './unplugin.js';
3
3
  import 'unplugin';
4
+ import './generator-Ba8XeISD.js';
4
5
 
5
6
  declare const _default: (options: Options) => esbuild.Plugin;
6
7
 
package/dist/esbuild.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-2AQHBHAG.js";
4
- import "./chunk-6HASMGMT.js";
3
+ } from "./chunk-B57NHMQD.js";
4
+ import "./chunk-4VL6W5GO.js";
5
5
 
6
6
  // src/esbuild.ts
7
7
  var esbuild_default = unplugin_default.esbuild;
@@ -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 toCamelCase(cssVarName) {
80
- return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
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 generateCode(varNames, prefix) {
87
- const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
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,55 @@ 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 code = generateCode(names, options.prefix);
103
- await (0, import_promises2.mkdir)((0, import_node_path.dirname)((0, import_node_path.resolve)(options.output)), { recursive: true });
104
- await (0, import_promises2.writeFile)(options.output, code, "utf8");
142
+ if (names.length === 0) {
143
+ console.warn("css-typed-vars: no CSS custom properties found.");
144
+ }
145
+ const outPath = (0, import_node_path.resolve)(options.output);
146
+ await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
147
+ if (options.output.endsWith(".js")) {
148
+ await (0, import_promises2.writeFile)(outPath, generateJs(names, options.prefix, options.naming), "utf8");
149
+ const dtsPath = outPath.replace(/\.js$/, ".d.ts");
150
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
151
+ } else {
152
+ await (0, import_promises2.writeFile)(outPath, generateCode(names, options.prefix, options.naming), "utf8");
153
+ }
105
154
  }
106
155
  // Annotate the CommonJS export names for ESM import in node:
107
156
  0 && (module.exports = {
108
157
  generate,
109
158
  generateCode,
159
+ generateDeclaration,
160
+ generateJs,
110
161
  parseVarNames,
111
162
  scanVarNames
112
163
  });
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
- declare function parseVarNames(css: string): string[];
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 generateCode(varNames: string[], prefix?: string): string;
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, generate, generateCode, parseVarNames, scanVarNames };
17
+ export { type GenerateOptions, NamingConvention, generate, parseVarNames, scanVarNames };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- declare function parseVarNames(css: string): string[];
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 generateCode(varNames: string[], prefix?: string): string;
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, generate, generateCode, parseVarNames, scanVarNames };
17
+ export { type GenerateOptions, NamingConvention, generate, parseVarNames, scanVarNames };
package/dist/index.js CHANGED
@@ -1,21 +1,18 @@
1
+ import {
2
+ generate
3
+ } from "./chunk-S2QNFCPF.js";
1
4
  import {
2
5
  generateCode,
6
+ generateDeclaration,
7
+ generateJs,
3
8
  parseVarNames,
4
9
  scanVarNames
5
- } from "./chunk-6HASMGMT.js";
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 toCamelCase(cssVarName) {
80
- return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
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 generateJs(varNames, prefix) {
87
- const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
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) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${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
@@ -1,6 +1,7 @@
1
1
  import * as rollup from 'rollup';
2
2
  import { Options } from './unplugin.cjs';
3
3
  import 'unplugin';
4
+ import './generator-Ba8XeISD.cjs';
4
5
 
5
6
  declare const _default: (options: Options) => rollup.Plugin<any> | rollup.Plugin<any>[];
6
7
 
package/dist/rollup.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as rollup from 'rollup';
2
2
  import { Options } from './unplugin.js';
3
3
  import 'unplugin';
4
+ import './generator-Ba8XeISD.js';
4
5
 
5
6
  declare const _default: (options: Options) => rollup.Plugin<any> | rollup.Plugin<any>[];
6
7
 
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-2AQHBHAG.js";
4
- import "./chunk-6HASMGMT.js";
3
+ } from "./chunk-B57NHMQD.js";
4
+ import "./chunk-4VL6W5GO.js";
5
5
 
6
6
  // src/rollup.ts
7
7
  var rollup_default = unplugin_default.rollup;
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 toCamelCase(cssVarName) {
78
- return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
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 generateJs(varNames, prefix) {
85
- const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
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) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${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
  }));
@@ -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
 
@@ -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
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-2AQHBHAG.js";
4
- import "./chunk-6HASMGMT.js";
3
+ } from "./chunk-B57NHMQD.js";
4
+ import "./chunk-4VL6W5GO.js";
5
5
  export {
6
6
  unplugin_default as default
7
7
  };
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 toCamelCase(cssVarName) {
80
- return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
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 generateJs(varNames, prefix) {
87
- const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
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) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${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
@@ -1,6 +1,7 @@
1
1
  import * as vite from 'vite';
2
2
  import { Options } from './unplugin.cjs';
3
3
  import 'unplugin';
4
+ import './generator-Ba8XeISD.cjs';
4
5
 
5
6
  declare const _default: (options: Options) => vite.Plugin<any> | vite.Plugin<any>[];
6
7
 
package/dist/vite.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as vite from 'vite';
2
2
  import { Options } from './unplugin.js';
3
3
  import 'unplugin';
4
+ import './generator-Ba8XeISD.js';
4
5
 
5
6
  declare const _default: (options: Options) => vite.Plugin<any> | vite.Plugin<any>[];
6
7
 
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-2AQHBHAG.js";
4
- import "./chunk-6HASMGMT.js";
3
+ } from "./chunk-B57NHMQD.js";
4
+ import "./chunk-4VL6W5GO.js";
5
5
 
6
6
  // src/vite.ts
7
7
  var vite_default = unplugin_default.vite;
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 toCamelCase(cssVarName) {
80
- return cssVarName.replace(/^--/, "").replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
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 generateJs(varNames, prefix) {
87
- const entries = varNames.map((name) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${name})',`);
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) => ` ${applyPrefix(toCamelCase(name), prefix)}: 'var(${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
  }));
@@ -1,5 +1,6 @@
1
1
  import { Options } from './unplugin.cjs';
2
2
  import 'unplugin';
3
+ import './generator-Ba8XeISD.cjs';
3
4
 
4
5
  declare const _default: (options: Options) => WebpackPluginInstance;
5
6
 
package/dist/webpack.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Options } from './unplugin.js';
2
2
  import 'unplugin';
3
+ import './generator-Ba8XeISD.js';
3
4
 
4
5
  declare const _default: (options: Options) => WebpackPluginInstance;
5
6
 
package/dist/webpack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-2AQHBHAG.js";
4
- import "./chunk-6HASMGMT.js";
3
+ } from "./chunk-B57NHMQD.js";
4
+ import "./chunk-4VL6W5GO.js";
5
5
 
6
6
  // src/webpack.ts
7
7
  var webpack_default = unplugin_default.webpack;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-typed-vars",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Generate TypeScript typed constants from CSS custom properties",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",