css-typed-vars 0.4.2 → 0.4.4

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
@@ -121,7 +121,7 @@ npx css-typed-vars --input "src/**/*.css" --output src/cssVars.ts --selector ".d
121
121
  |------|-------------|
122
122
  | `--input` | Glob pattern for CSS/SCSS/Less files |
123
123
  | `--output` | Output file. `.ts` → TypeScript, `.js` → JavaScript + `.d.ts` alongside |
124
- | `--exclude` | Glob pattern for files to exclude (single value; use config file for multiple) |
124
+ | `--exclude` | Glob pattern for files to exclude (repeatable: `--exclude "**/a/**" --exclude "**/b/**"`) |
125
125
  | `--prefix` | Prefix for generated keys: `--prefix theme` → `themeColorPrimary` |
126
126
  | `--naming` | Key naming: `camelCase` (default), `snake`, `kebab` |
127
127
  | `--selector` | Extra CSS selector to scan for variables (single value; use config file for multiple) |
@@ -3,7 +3,7 @@ import {
3
3
  generateDeclaration,
4
4
  generateJs,
5
5
  scanVarNames
6
- } from "./chunk-Y6U2ERL3.js";
6
+ } from "./chunk-J7ZV6AUQ.js";
7
7
 
8
8
  // src/index.ts
9
9
  import { writeFile, mkdir } from "fs/promises";
@@ -46,9 +46,9 @@ async function scanVarNames(patterns, exclude, selectors) {
46
46
  // src/generator.ts
47
47
  function toKey(cssVarName, naming = "camelCase") {
48
48
  const stripped = cssVarName.replace(/^--/, "");
49
- if (naming === "snake") return stripped.replace(/-/g, "_");
50
49
  if (naming === "kebab") return stripped;
51
- return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
50
+ const key = naming === "snake" ? stripped.replace(/-/g, "_") : stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
51
+ return /^\d/.test(key) ? `_${key}` : key;
52
52
  }
53
53
  function applyPrefix(key, prefix, naming = "camelCase") {
54
54
  if (!prefix) return key;
@@ -0,0 +1,65 @@
1
+ import {
2
+ __dirname,
3
+ generateDeclaration,
4
+ generateJs,
5
+ scanVarNames
6
+ } from "./chunk-J7ZV6AUQ.js";
7
+
8
+ // src/unplugin.ts
9
+ import { createUnplugin } from "unplugin";
10
+ import { writeFile } from "fs/promises";
11
+ import { join, resolve } from "path";
12
+ var VIRTUAL_ID = "css-typed-vars/vars";
13
+ var RESOLVED_ID = "\0css-typed-vars/vars";
14
+ function getDtsPath(options) {
15
+ if (options.dts === false) return null;
16
+ return options.dts ? resolve(process.cwd(), options.dts) : join(__dirname, "generated.d.ts");
17
+ }
18
+ var unplugin_default = createUnplugin((options) => {
19
+ let cachedNames = null;
20
+ return {
21
+ name: "css-typed-vars",
22
+ vite: {
23
+ enforce: "pre",
24
+ configureServer(server) {
25
+ const handle = async (file) => {
26
+ if (!/\.(css|scss|less)$/i.test(file)) return;
27
+ cachedNames = null;
28
+ const names = await scanVarNames(options.input, options.exclude, options.selectors);
29
+ const dtsPath = getDtsPath(options);
30
+ if (dtsPath) {
31
+ await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
32
+ }
33
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
34
+ if (mod) {
35
+ server.moduleGraph.invalidateModule(mod);
36
+ server.ws.send({ type: "full-reload" });
37
+ }
38
+ };
39
+ server.watcher.on("change", handle);
40
+ server.watcher.on("add", handle);
41
+ server.watcher.on("unlink", handle);
42
+ }
43
+ },
44
+ async buildStart() {
45
+ cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
46
+ const dtsPath = getDtsPath(options);
47
+ if (!dtsPath) return;
48
+ const names = await cachedNames;
49
+ await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
50
+ },
51
+ resolveId(id) {
52
+ if (id === VIRTUAL_ID) return RESOLVED_ID;
53
+ },
54
+ async load(id) {
55
+ if (id === RESOLVED_ID) {
56
+ const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
57
+ return generateJs(names, options.prefix, options.naming);
58
+ }
59
+ }
60
+ };
61
+ });
62
+
63
+ export {
64
+ unplugin_default
65
+ };
package/dist/cli.cjs CHANGED
@@ -80,9 +80,9 @@ async function scanVarNames(patterns, exclude, selectors) {
80
80
  // src/generator.ts
81
81
  function toKey(cssVarName, naming = "camelCase") {
82
82
  const stripped = cssVarName.replace(/^--/, "");
83
- if (naming === "snake") return stripped.replace(/-/g, "_");
84
83
  if (naming === "kebab") return stripped;
85
- return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
84
+ const key = naming === "snake" ? stripped.replace(/-/g, "_") : stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
85
+ return /^\d/.test(key) ? `_${key}` : key;
86
86
  }
87
87
  function applyPrefix(key, prefix, naming = "camelCase") {
88
88
  if (!prefix) return key;
@@ -201,7 +201,8 @@ async function main() {
201
201
  const config = await loadConfig();
202
202
  const input = getArg("--input") ?? config.input;
203
203
  const output = getArg("--output") ?? config.output;
204
- const exclude = getArg("--exclude") ?? config.exclude;
204
+ const excludeArgs = getArgs("--exclude");
205
+ const exclude = excludeArgs.length > 0 ? excludeArgs : config.exclude;
205
206
  const prefix = getArg("--prefix") ?? config.prefix;
206
207
  const naming = getArg("--naming") ?? config.naming;
207
208
  const selectorArgs = getArgs("--selector");
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  generate
4
- } from "./chunk-CCFKX6NQ.js";
5
- import "./chunk-Y6U2ERL3.js";
4
+ } from "./chunk-6OVNVVEP.js";
5
+ import "./chunk-J7ZV6AUQ.js";
6
6
 
7
7
  // src/cli.ts
8
8
  import { readFile } from "fs/promises";
@@ -56,7 +56,8 @@ async function main() {
56
56
  const config = await loadConfig();
57
57
  const input = getArg("--input") ?? config.input;
58
58
  const output = getArg("--output") ?? config.output;
59
- const exclude = getArg("--exclude") ?? config.exclude;
59
+ const excludeArgs = getArgs("--exclude");
60
+ const exclude = excludeArgs.length > 0 ? excludeArgs : config.exclude;
60
61
  const prefix = getArg("--prefix") ?? config.prefix;
61
62
  const naming = getArg("--naming") ?? config.naming;
62
63
  const selectorArgs = getArgs("--selector");
package/dist/esbuild.cjs CHANGED
@@ -82,9 +82,9 @@ async function scanVarNames(patterns, exclude, selectors) {
82
82
  // src/generator.ts
83
83
  function toKey(cssVarName, naming = "camelCase") {
84
84
  const stripped = cssVarName.replace(/^--/, "");
85
- if (naming === "snake") return stripped.replace(/-/g, "_");
86
85
  if (naming === "kebab") return stripped;
87
- return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
86
+ const key = naming === "snake" ? stripped.replace(/-/g, "_") : stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
87
+ return /^\d/.test(key) ? `_${key}` : key;
88
88
  }
89
89
  function applyPrefix(key, prefix, naming = "camelCase") {
90
90
  if (!prefix) return key;
@@ -130,42 +130,50 @@ function getDtsPath(options) {
130
130
  if (options.dts === false) return null;
131
131
  return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
132
132
  }
133
- var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
134
- name: "css-typed-vars",
135
- vite: {
136
- enforce: "pre",
137
- configureServer(server) {
138
- server.watcher.on("change", async (file) => {
139
- if (!/\.(css|scss|less)$/i.test(file)) return;
140
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
141
- const dtsPath = getDtsPath(options);
142
- if (dtsPath) {
143
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
144
- }
145
- const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
146
- if (mod) {
147
- server.moduleGraph.invalidateModule(mod);
148
- server.ws.send({ type: "full-reload" });
149
- }
150
- });
151
- }
152
- },
153
- async buildStart() {
154
- const dtsPath = getDtsPath(options);
155
- if (!dtsPath) return;
156
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
157
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
158
- },
159
- resolveId(id) {
160
- if (id === VIRTUAL_ID) return RESOLVED_ID;
161
- },
162
- async load(id) {
163
- if (id === RESOLVED_ID) {
164
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
165
- return generateJs(names, options.prefix, options.naming);
133
+ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
134
+ let cachedNames = null;
135
+ return {
136
+ name: "css-typed-vars",
137
+ vite: {
138
+ enforce: "pre",
139
+ configureServer(server) {
140
+ const handle = async (file) => {
141
+ if (!/\.(css|scss|less)$/i.test(file)) return;
142
+ cachedNames = null;
143
+ const names = await scanVarNames(options.input, options.exclude, options.selectors);
144
+ const dtsPath = getDtsPath(options);
145
+ if (dtsPath) {
146
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
147
+ }
148
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
149
+ if (mod) {
150
+ server.moduleGraph.invalidateModule(mod);
151
+ server.ws.send({ type: "full-reload" });
152
+ }
153
+ };
154
+ server.watcher.on("change", handle);
155
+ server.watcher.on("add", handle);
156
+ server.watcher.on("unlink", handle);
157
+ }
158
+ },
159
+ async buildStart() {
160
+ cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
161
+ const dtsPath = getDtsPath(options);
162
+ if (!dtsPath) return;
163
+ const names = await cachedNames;
164
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
165
+ },
166
+ resolveId(id) {
167
+ if (id === VIRTUAL_ID) return RESOLVED_ID;
168
+ },
169
+ async load(id) {
170
+ if (id === RESOLVED_ID) {
171
+ const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
172
+ return generateJs(names, options.prefix, options.naming);
173
+ }
166
174
  }
167
- }
168
- }));
175
+ };
176
+ });
169
177
 
170
178
  // src/esbuild.ts
171
179
  var esbuild_default = unplugin_default.esbuild;
package/dist/esbuild.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-7PBWBCVY.js";
4
- import "./chunk-Y6U2ERL3.js";
3
+ } from "./chunk-SWVHEM3S.js";
4
+ import "./chunk-J7ZV6AUQ.js";
5
5
 
6
6
  // src/esbuild.ts
7
7
  var esbuild_default = unplugin_default.esbuild;
package/dist/index.cjs CHANGED
@@ -84,9 +84,9 @@ async function scanVarNames(patterns, exclude, selectors) {
84
84
  // src/generator.ts
85
85
  function toKey(cssVarName, naming = "camelCase") {
86
86
  const stripped = cssVarName.replace(/^--/, "");
87
- if (naming === "snake") return stripped.replace(/-/g, "_");
88
87
  if (naming === "kebab") return stripped;
89
- return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
88
+ const key = naming === "snake" ? stripped.replace(/-/g, "_") : stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
89
+ return /^\d/.test(key) ? `_${key}` : key;
90
90
  }
91
91
  function applyPrefix(key, prefix, naming = "camelCase") {
92
92
  if (!prefix) return key;
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  generate
3
- } from "./chunk-CCFKX6NQ.js";
3
+ } from "./chunk-6OVNVVEP.js";
4
4
  import {
5
5
  generateCode,
6
6
  generateDeclaration,
7
7
  generateJs,
8
8
  parseVarNames,
9
9
  scanVarNames
10
- } from "./chunk-Y6U2ERL3.js";
10
+ } from "./chunk-J7ZV6AUQ.js";
11
11
  export {
12
12
  generate,
13
13
  generateCode,
package/dist/rollup.cjs CHANGED
@@ -82,9 +82,9 @@ async function scanVarNames(patterns, exclude, selectors) {
82
82
  // src/generator.ts
83
83
  function toKey(cssVarName, naming = "camelCase") {
84
84
  const stripped = cssVarName.replace(/^--/, "");
85
- if (naming === "snake") return stripped.replace(/-/g, "_");
86
85
  if (naming === "kebab") return stripped;
87
- return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
86
+ const key = naming === "snake" ? stripped.replace(/-/g, "_") : stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
87
+ return /^\d/.test(key) ? `_${key}` : key;
88
88
  }
89
89
  function applyPrefix(key, prefix, naming = "camelCase") {
90
90
  if (!prefix) return key;
@@ -130,42 +130,50 @@ function getDtsPath(options) {
130
130
  if (options.dts === false) return null;
131
131
  return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
132
132
  }
133
- var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
134
- name: "css-typed-vars",
135
- vite: {
136
- enforce: "pre",
137
- configureServer(server) {
138
- server.watcher.on("change", async (file) => {
139
- if (!/\.(css|scss|less)$/i.test(file)) return;
140
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
141
- const dtsPath = getDtsPath(options);
142
- if (dtsPath) {
143
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
144
- }
145
- const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
146
- if (mod) {
147
- server.moduleGraph.invalidateModule(mod);
148
- server.ws.send({ type: "full-reload" });
149
- }
150
- });
151
- }
152
- },
153
- async buildStart() {
154
- const dtsPath = getDtsPath(options);
155
- if (!dtsPath) return;
156
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
157
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
158
- },
159
- resolveId(id) {
160
- if (id === VIRTUAL_ID) return RESOLVED_ID;
161
- },
162
- async load(id) {
163
- if (id === RESOLVED_ID) {
164
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
165
- return generateJs(names, options.prefix, options.naming);
133
+ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
134
+ let cachedNames = null;
135
+ return {
136
+ name: "css-typed-vars",
137
+ vite: {
138
+ enforce: "pre",
139
+ configureServer(server) {
140
+ const handle = async (file) => {
141
+ if (!/\.(css|scss|less)$/i.test(file)) return;
142
+ cachedNames = null;
143
+ const names = await scanVarNames(options.input, options.exclude, options.selectors);
144
+ const dtsPath = getDtsPath(options);
145
+ if (dtsPath) {
146
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
147
+ }
148
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
149
+ if (mod) {
150
+ server.moduleGraph.invalidateModule(mod);
151
+ server.ws.send({ type: "full-reload" });
152
+ }
153
+ };
154
+ server.watcher.on("change", handle);
155
+ server.watcher.on("add", handle);
156
+ server.watcher.on("unlink", handle);
157
+ }
158
+ },
159
+ async buildStart() {
160
+ cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
161
+ const dtsPath = getDtsPath(options);
162
+ if (!dtsPath) return;
163
+ const names = await cachedNames;
164
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
165
+ },
166
+ resolveId(id) {
167
+ if (id === VIRTUAL_ID) return RESOLVED_ID;
168
+ },
169
+ async load(id) {
170
+ if (id === RESOLVED_ID) {
171
+ const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
172
+ return generateJs(names, options.prefix, options.naming);
173
+ }
166
174
  }
167
- }
168
- }));
175
+ };
176
+ });
169
177
 
170
178
  // src/rollup.ts
171
179
  var rollup_default = unplugin_default.rollup;
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-7PBWBCVY.js";
4
- import "./chunk-Y6U2ERL3.js";
3
+ } from "./chunk-SWVHEM3S.js";
4
+ import "./chunk-J7ZV6AUQ.js";
5
5
 
6
6
  // src/rollup.ts
7
7
  var rollup_default = unplugin_default.rollup;
package/dist/unplugin.cjs CHANGED
@@ -80,9 +80,9 @@ async function scanVarNames(patterns, exclude, selectors) {
80
80
  // src/generator.ts
81
81
  function toKey(cssVarName, naming = "camelCase") {
82
82
  const stripped = cssVarName.replace(/^--/, "");
83
- if (naming === "snake") return stripped.replace(/-/g, "_");
84
83
  if (naming === "kebab") return stripped;
85
- return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
84
+ const key = naming === "snake" ? stripped.replace(/-/g, "_") : stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
85
+ return /^\d/.test(key) ? `_${key}` : key;
86
86
  }
87
87
  function applyPrefix(key, prefix, naming = "camelCase") {
88
88
  if (!prefix) return key;
@@ -128,39 +128,47 @@ function getDtsPath(options) {
128
128
  if (options.dts === false) return null;
129
129
  return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
130
130
  }
131
- var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
132
- name: "css-typed-vars",
133
- vite: {
134
- enforce: "pre",
135
- configureServer(server) {
136
- server.watcher.on("change", async (file) => {
137
- if (!/\.(css|scss|less)$/i.test(file)) return;
138
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
139
- const dtsPath = getDtsPath(options);
140
- if (dtsPath) {
141
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
142
- }
143
- const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
144
- if (mod) {
145
- server.moduleGraph.invalidateModule(mod);
146
- server.ws.send({ type: "full-reload" });
147
- }
148
- });
149
- }
150
- },
151
- async buildStart() {
152
- const dtsPath = getDtsPath(options);
153
- if (!dtsPath) return;
154
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
155
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
156
- },
157
- resolveId(id) {
158
- if (id === VIRTUAL_ID) return RESOLVED_ID;
159
- },
160
- async load(id) {
161
- if (id === RESOLVED_ID) {
162
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
163
- return generateJs(names, options.prefix, options.naming);
131
+ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
132
+ let cachedNames = null;
133
+ return {
134
+ name: "css-typed-vars",
135
+ vite: {
136
+ enforce: "pre",
137
+ configureServer(server) {
138
+ const handle = async (file) => {
139
+ if (!/\.(css|scss|less)$/i.test(file)) return;
140
+ cachedNames = null;
141
+ const names = await scanVarNames(options.input, options.exclude, options.selectors);
142
+ const dtsPath = getDtsPath(options);
143
+ if (dtsPath) {
144
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
145
+ }
146
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
147
+ if (mod) {
148
+ server.moduleGraph.invalidateModule(mod);
149
+ server.ws.send({ type: "full-reload" });
150
+ }
151
+ };
152
+ server.watcher.on("change", handle);
153
+ server.watcher.on("add", handle);
154
+ server.watcher.on("unlink", handle);
155
+ }
156
+ },
157
+ async buildStart() {
158
+ cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
159
+ const dtsPath = getDtsPath(options);
160
+ if (!dtsPath) return;
161
+ const names = await cachedNames;
162
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
163
+ },
164
+ resolveId(id) {
165
+ if (id === VIRTUAL_ID) return RESOLVED_ID;
166
+ },
167
+ async load(id) {
168
+ if (id === RESOLVED_ID) {
169
+ const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
170
+ return generateJs(names, options.prefix, options.naming);
171
+ }
164
172
  }
165
- }
166
- }));
173
+ };
174
+ });
package/dist/unplugin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-7PBWBCVY.js";
4
- import "./chunk-Y6U2ERL3.js";
3
+ } from "./chunk-SWVHEM3S.js";
4
+ import "./chunk-J7ZV6AUQ.js";
5
5
  export {
6
6
  unplugin_default as default
7
7
  };
package/dist/vite.cjs CHANGED
@@ -82,9 +82,9 @@ async function scanVarNames(patterns, exclude, selectors) {
82
82
  // src/generator.ts
83
83
  function toKey(cssVarName, naming = "camelCase") {
84
84
  const stripped = cssVarName.replace(/^--/, "");
85
- if (naming === "snake") return stripped.replace(/-/g, "_");
86
85
  if (naming === "kebab") return stripped;
87
- return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
86
+ const key = naming === "snake" ? stripped.replace(/-/g, "_") : stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
87
+ return /^\d/.test(key) ? `_${key}` : key;
88
88
  }
89
89
  function applyPrefix(key, prefix, naming = "camelCase") {
90
90
  if (!prefix) return key;
@@ -130,42 +130,50 @@ function getDtsPath(options) {
130
130
  if (options.dts === false) return null;
131
131
  return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
132
132
  }
133
- var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
134
- name: "css-typed-vars",
135
- vite: {
136
- enforce: "pre",
137
- configureServer(server) {
138
- server.watcher.on("change", async (file) => {
139
- if (!/\.(css|scss|less)$/i.test(file)) return;
140
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
141
- const dtsPath = getDtsPath(options);
142
- if (dtsPath) {
143
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
144
- }
145
- const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
146
- if (mod) {
147
- server.moduleGraph.invalidateModule(mod);
148
- server.ws.send({ type: "full-reload" });
149
- }
150
- });
151
- }
152
- },
153
- async buildStart() {
154
- const dtsPath = getDtsPath(options);
155
- if (!dtsPath) return;
156
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
157
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
158
- },
159
- resolveId(id) {
160
- if (id === VIRTUAL_ID) return RESOLVED_ID;
161
- },
162
- async load(id) {
163
- if (id === RESOLVED_ID) {
164
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
165
- return generateJs(names, options.prefix, options.naming);
133
+ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
134
+ let cachedNames = null;
135
+ return {
136
+ name: "css-typed-vars",
137
+ vite: {
138
+ enforce: "pre",
139
+ configureServer(server) {
140
+ const handle = async (file) => {
141
+ if (!/\.(css|scss|less)$/i.test(file)) return;
142
+ cachedNames = null;
143
+ const names = await scanVarNames(options.input, options.exclude, options.selectors);
144
+ const dtsPath = getDtsPath(options);
145
+ if (dtsPath) {
146
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
147
+ }
148
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
149
+ if (mod) {
150
+ server.moduleGraph.invalidateModule(mod);
151
+ server.ws.send({ type: "full-reload" });
152
+ }
153
+ };
154
+ server.watcher.on("change", handle);
155
+ server.watcher.on("add", handle);
156
+ server.watcher.on("unlink", handle);
157
+ }
158
+ },
159
+ async buildStart() {
160
+ cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
161
+ const dtsPath = getDtsPath(options);
162
+ if (!dtsPath) return;
163
+ const names = await cachedNames;
164
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
165
+ },
166
+ resolveId(id) {
167
+ if (id === VIRTUAL_ID) return RESOLVED_ID;
168
+ },
169
+ async load(id) {
170
+ if (id === RESOLVED_ID) {
171
+ const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
172
+ return generateJs(names, options.prefix, options.naming);
173
+ }
166
174
  }
167
- }
168
- }));
175
+ };
176
+ });
169
177
 
170
178
  // src/vite.ts
171
179
  var vite_default = unplugin_default.vite;
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-7PBWBCVY.js";
4
- import "./chunk-Y6U2ERL3.js";
3
+ } from "./chunk-SWVHEM3S.js";
4
+ import "./chunk-J7ZV6AUQ.js";
5
5
 
6
6
  // src/vite.ts
7
7
  var vite_default = unplugin_default.vite;
package/dist/webpack.cjs CHANGED
@@ -82,9 +82,9 @@ async function scanVarNames(patterns, exclude, selectors) {
82
82
  // src/generator.ts
83
83
  function toKey(cssVarName, naming = "camelCase") {
84
84
  const stripped = cssVarName.replace(/^--/, "");
85
- if (naming === "snake") return stripped.replace(/-/g, "_");
86
85
  if (naming === "kebab") return stripped;
87
- return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
86
+ const key = naming === "snake" ? stripped.replace(/-/g, "_") : stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
87
+ return /^\d/.test(key) ? `_${key}` : key;
88
88
  }
89
89
  function applyPrefix(key, prefix, naming = "camelCase") {
90
90
  if (!prefix) return key;
@@ -130,42 +130,50 @@ function getDtsPath(options) {
130
130
  if (options.dts === false) return null;
131
131
  return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
132
132
  }
133
- var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
134
- name: "css-typed-vars",
135
- vite: {
136
- enforce: "pre",
137
- configureServer(server) {
138
- server.watcher.on("change", async (file) => {
139
- if (!/\.(css|scss|less)$/i.test(file)) return;
140
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
141
- const dtsPath = getDtsPath(options);
142
- if (dtsPath) {
143
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
144
- }
145
- const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
146
- if (mod) {
147
- server.moduleGraph.invalidateModule(mod);
148
- server.ws.send({ type: "full-reload" });
149
- }
150
- });
151
- }
152
- },
153
- async buildStart() {
154
- const dtsPath = getDtsPath(options);
155
- if (!dtsPath) return;
156
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
157
- await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
158
- },
159
- resolveId(id) {
160
- if (id === VIRTUAL_ID) return RESOLVED_ID;
161
- },
162
- async load(id) {
163
- if (id === RESOLVED_ID) {
164
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
165
- return generateJs(names, options.prefix, options.naming);
133
+ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
134
+ let cachedNames = null;
135
+ return {
136
+ name: "css-typed-vars",
137
+ vite: {
138
+ enforce: "pre",
139
+ configureServer(server) {
140
+ const handle = async (file) => {
141
+ if (!/\.(css|scss|less)$/i.test(file)) return;
142
+ cachedNames = null;
143
+ const names = await scanVarNames(options.input, options.exclude, options.selectors);
144
+ const dtsPath = getDtsPath(options);
145
+ if (dtsPath) {
146
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
147
+ }
148
+ const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
149
+ if (mod) {
150
+ server.moduleGraph.invalidateModule(mod);
151
+ server.ws.send({ type: "full-reload" });
152
+ }
153
+ };
154
+ server.watcher.on("change", handle);
155
+ server.watcher.on("add", handle);
156
+ server.watcher.on("unlink", handle);
157
+ }
158
+ },
159
+ async buildStart() {
160
+ cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
161
+ const dtsPath = getDtsPath(options);
162
+ if (!dtsPath) return;
163
+ const names = await cachedNames;
164
+ await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
165
+ },
166
+ resolveId(id) {
167
+ if (id === VIRTUAL_ID) return RESOLVED_ID;
168
+ },
169
+ async load(id) {
170
+ if (id === RESOLVED_ID) {
171
+ const names = await (cachedNames ?? scanVarNames(options.input, options.exclude, options.selectors));
172
+ return generateJs(names, options.prefix, options.naming);
173
+ }
166
174
  }
167
- }
168
- }));
175
+ };
176
+ });
169
177
 
170
178
  // src/webpack.ts
171
179
  var webpack_default = unplugin_default.webpack;
package/dist/webpack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-7PBWBCVY.js";
4
- import "./chunk-Y6U2ERL3.js";
3
+ } from "./chunk-SWVHEM3S.js";
4
+ import "./chunk-J7ZV6AUQ.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.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "Generate TypeScript typed constants from CSS custom properties",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -1,57 +0,0 @@
1
- import {
2
- __dirname,
3
- generateDeclaration,
4
- generateJs,
5
- scanVarNames
6
- } from "./chunk-Y6U2ERL3.js";
7
-
8
- // src/unplugin.ts
9
- import { createUnplugin } from "unplugin";
10
- import { writeFile } from "fs/promises";
11
- import { join, resolve } from "path";
12
- var VIRTUAL_ID = "css-typed-vars/vars";
13
- var RESOLVED_ID = "\0css-typed-vars/vars";
14
- function getDtsPath(options) {
15
- if (options.dts === false) return null;
16
- return options.dts ? resolve(process.cwd(), options.dts) : join(__dirname, "generated.d.ts");
17
- }
18
- var unplugin_default = createUnplugin((options) => ({
19
- name: "css-typed-vars",
20
- vite: {
21
- enforce: "pre",
22
- configureServer(server) {
23
- server.watcher.on("change", async (file) => {
24
- if (!/\.(css|scss|less)$/i.test(file)) return;
25
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
26
- const dtsPath = getDtsPath(options);
27
- if (dtsPath) {
28
- await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
29
- }
30
- const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
31
- if (mod) {
32
- server.moduleGraph.invalidateModule(mod);
33
- server.ws.send({ type: "full-reload" });
34
- }
35
- });
36
- }
37
- },
38
- async buildStart() {
39
- const dtsPath = getDtsPath(options);
40
- if (!dtsPath) return;
41
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
42
- await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
43
- },
44
- resolveId(id) {
45
- if (id === VIRTUAL_ID) return RESOLVED_ID;
46
- },
47
- async load(id) {
48
- if (id === RESOLVED_ID) {
49
- const names = await scanVarNames(options.input, options.exclude, options.selectors);
50
- return generateJs(names, options.prefix, options.naming);
51
- }
52
- }
53
- }));
54
-
55
- export {
56
- unplugin_default
57
- };