css-typed-vars 0.4.7 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-PYNEJIVI.js → chunk-7QP7R3IQ.js} +1 -1
- package/dist/{chunk-6OVNVVEP.js → chunk-MQAIY4QW.js} +5 -1
- package/dist/{chunk-J7ZV6AUQ.js → chunk-Y3WJXRDA.js} +15 -1
- package/dist/cli.cjs +27 -3
- package/dist/cli.js +12 -4
- package/dist/esbuild.cjs +1 -1
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +17 -1
- package/dist/index.js +2 -2
- package/dist/rollup.cjs +1 -1
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +1 -1
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +1 -1
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
+
findKeyCollisions,
|
|
2
3
|
generateCode,
|
|
3
4
|
generateDeclaration,
|
|
4
5
|
generateJs,
|
|
5
6
|
scanVarNames
|
|
6
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-Y3WJXRDA.js";
|
|
7
8
|
|
|
8
9
|
// src/index.ts
|
|
9
10
|
import { writeFile, mkdir } from "fs/promises";
|
|
@@ -13,6 +14,9 @@ async function generate(options) {
|
|
|
13
14
|
if (names.length === 0) {
|
|
14
15
|
console.warn("css-typed-vars: no CSS custom properties found.");
|
|
15
16
|
}
|
|
17
|
+
for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
|
|
18
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
19
|
+
}
|
|
16
20
|
const outPath = resolve(options.output);
|
|
17
21
|
await mkdir(dirname(outPath), { recursive: true });
|
|
18
22
|
if (options.output.endsWith(".js")) {
|
|
@@ -47,7 +47,7 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
47
47
|
function toKey(cssVarName, naming = "camelCase") {
|
|
48
48
|
const stripped = cssVarName.replace(/^--/, "");
|
|
49
49
|
if (naming === "kebab") return stripped;
|
|
50
|
-
const key = naming === "snake" ? stripped.replace(
|
|
50
|
+
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
51
51
|
return /^\d/.test(key) ? `_${key}` : key;
|
|
52
52
|
}
|
|
53
53
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
@@ -60,6 +60,19 @@ function formatKey(key, naming = "camelCase") {
|
|
|
60
60
|
if (naming === "kebab") return `'${key}'`;
|
|
61
61
|
return key;
|
|
62
62
|
}
|
|
63
|
+
function findKeyCollisions(varNames, prefix, naming) {
|
|
64
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
65
|
+
for (const name of varNames) {
|
|
66
|
+
const key = applyPrefix(toKey(name, naming), prefix, naming);
|
|
67
|
+
const existing = byKey.get(key);
|
|
68
|
+
if (existing) existing.push(name);
|
|
69
|
+
else byKey.set(key, [name]);
|
|
70
|
+
}
|
|
71
|
+
for (const [key, names] of byKey) {
|
|
72
|
+
if (names.length < 2) byKey.delete(key);
|
|
73
|
+
}
|
|
74
|
+
return byKey;
|
|
75
|
+
}
|
|
63
76
|
function generateCode(varNames, prefix, naming) {
|
|
64
77
|
const entries = varNames.map((name) => {
|
|
65
78
|
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
@@ -106,6 +119,7 @@ export {
|
|
|
106
119
|
__dirname,
|
|
107
120
|
parseVarNames,
|
|
108
121
|
scanVarNames,
|
|
122
|
+
findKeyCollisions,
|
|
109
123
|
generateCode,
|
|
110
124
|
generateJs,
|
|
111
125
|
generateDeclaration
|
package/dist/cli.cjs
CHANGED
|
@@ -81,7 +81,7 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
81
81
|
function toKey(cssVarName, naming = "camelCase") {
|
|
82
82
|
const stripped = cssVarName.replace(/^--/, "");
|
|
83
83
|
if (naming === "kebab") return stripped;
|
|
84
|
-
const key = naming === "snake" ? stripped.replace(
|
|
84
|
+
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
85
85
|
return /^\d/.test(key) ? `_${key}` : key;
|
|
86
86
|
}
|
|
87
87
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
@@ -94,6 +94,19 @@ function formatKey(key, naming = "camelCase") {
|
|
|
94
94
|
if (naming === "kebab") return `'${key}'`;
|
|
95
95
|
return key;
|
|
96
96
|
}
|
|
97
|
+
function findKeyCollisions(varNames, prefix, naming) {
|
|
98
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
99
|
+
for (const name of varNames) {
|
|
100
|
+
const key = applyPrefix(toKey(name, naming), prefix, naming);
|
|
101
|
+
const existing = byKey.get(key);
|
|
102
|
+
if (existing) existing.push(name);
|
|
103
|
+
else byKey.set(key, [name]);
|
|
104
|
+
}
|
|
105
|
+
for (const [key, names] of byKey) {
|
|
106
|
+
if (names.length < 2) byKey.delete(key);
|
|
107
|
+
}
|
|
108
|
+
return byKey;
|
|
109
|
+
}
|
|
97
110
|
function generateCode(varNames, prefix, naming) {
|
|
98
111
|
const entries = varNames.map((name) => {
|
|
99
112
|
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
@@ -142,6 +155,9 @@ async function generate(options) {
|
|
|
142
155
|
if (names.length === 0) {
|
|
143
156
|
console.warn("css-typed-vars: no CSS custom properties found.");
|
|
144
157
|
}
|
|
158
|
+
for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
|
|
159
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
160
|
+
}
|
|
145
161
|
const outPath = (0, import_node_path.resolve)(options.output);
|
|
146
162
|
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
|
|
147
163
|
if (options.output.endsWith(".js")) {
|
|
@@ -154,7 +170,10 @@ async function generate(options) {
|
|
|
154
170
|
}
|
|
155
171
|
|
|
156
172
|
// src/cli.ts
|
|
157
|
-
var args = process.argv.slice(2)
|
|
173
|
+
var args = process.argv.slice(2).flatMap((arg) => {
|
|
174
|
+
const match = /^(--[\w-]+)=(.*)$/.exec(arg);
|
|
175
|
+
return match ? [match[1], match[2]] : [arg];
|
|
176
|
+
});
|
|
158
177
|
var getArg = (flag) => {
|
|
159
178
|
const i = args.indexOf(flag);
|
|
160
179
|
return i !== -1 ? args[i + 1] : void 0;
|
|
@@ -208,7 +227,12 @@ async function main() {
|
|
|
208
227
|
const excludeArgs = getArgs("--exclude");
|
|
209
228
|
const exclude = excludeArgs.length > 0 ? excludeArgs : config.exclude;
|
|
210
229
|
const prefix = getArg("--prefix") ?? config.prefix;
|
|
211
|
-
const
|
|
230
|
+
const namingRaw = getArg("--naming") ?? config.naming;
|
|
231
|
+
if (namingRaw !== void 0 && !["camelCase", "snake", "kebab"].includes(namingRaw)) {
|
|
232
|
+
console.error(`css-typed-vars: invalid --naming value "${namingRaw}". Valid values: camelCase, snake, kebab`);
|
|
233
|
+
process.exit(1);
|
|
234
|
+
}
|
|
235
|
+
const naming = namingRaw;
|
|
212
236
|
const selectorArgs = getArgs("--selector");
|
|
213
237
|
const selectors = selectorArgs.length > 0 ? selectorArgs : config.selectors;
|
|
214
238
|
if (!input || !output) {
|
package/dist/cli.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
generate
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-MQAIY4QW.js";
|
|
5
|
+
import "./chunk-Y3WJXRDA.js";
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
8
8
|
import { readFile } from "fs/promises";
|
|
9
9
|
import { resolve } from "path";
|
|
10
10
|
import { pathToFileURL } from "url";
|
|
11
11
|
import { watch } from "chokidar";
|
|
12
|
-
var args = process.argv.slice(2)
|
|
12
|
+
var args = process.argv.slice(2).flatMap((arg) => {
|
|
13
|
+
const match = /^(--[\w-]+)=(.*)$/.exec(arg);
|
|
14
|
+
return match ? [match[1], match[2]] : [arg];
|
|
15
|
+
});
|
|
13
16
|
var getArg = (flag) => {
|
|
14
17
|
const i = args.indexOf(flag);
|
|
15
18
|
return i !== -1 ? args[i + 1] : void 0;
|
|
@@ -63,7 +66,12 @@ async function main() {
|
|
|
63
66
|
const excludeArgs = getArgs("--exclude");
|
|
64
67
|
const exclude = excludeArgs.length > 0 ? excludeArgs : config.exclude;
|
|
65
68
|
const prefix = getArg("--prefix") ?? config.prefix;
|
|
66
|
-
const
|
|
69
|
+
const namingRaw = getArg("--naming") ?? config.naming;
|
|
70
|
+
if (namingRaw !== void 0 && !["camelCase", "snake", "kebab"].includes(namingRaw)) {
|
|
71
|
+
console.error(`css-typed-vars: invalid --naming value "${namingRaw}". Valid values: camelCase, snake, kebab`);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
const naming = namingRaw;
|
|
67
75
|
const selectorArgs = getArgs("--selector");
|
|
68
76
|
const selectors = selectorArgs.length > 0 ? selectorArgs : config.selectors;
|
|
69
77
|
if (!input || !output) {
|
package/dist/esbuild.cjs
CHANGED
|
@@ -83,7 +83,7 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
83
83
|
function toKey(cssVarName, naming = "camelCase") {
|
|
84
84
|
const stripped = cssVarName.replace(/^--/, "");
|
|
85
85
|
if (naming === "kebab") return stripped;
|
|
86
|
-
const key = naming === "snake" ? stripped.replace(
|
|
86
|
+
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
87
87
|
return /^\d/.test(key) ? `_${key}` : key;
|
|
88
88
|
}
|
|
89
89
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -85,7 +85,7 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
85
85
|
function toKey(cssVarName, naming = "camelCase") {
|
|
86
86
|
const stripped = cssVarName.replace(/^--/, "");
|
|
87
87
|
if (naming === "kebab") return stripped;
|
|
88
|
-
const key = naming === "snake" ? stripped.replace(
|
|
88
|
+
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
89
89
|
return /^\d/.test(key) ? `_${key}` : key;
|
|
90
90
|
}
|
|
91
91
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
@@ -98,6 +98,19 @@ function formatKey(key, naming = "camelCase") {
|
|
|
98
98
|
if (naming === "kebab") return `'${key}'`;
|
|
99
99
|
return key;
|
|
100
100
|
}
|
|
101
|
+
function findKeyCollisions(varNames, prefix, naming) {
|
|
102
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
103
|
+
for (const name of varNames) {
|
|
104
|
+
const key = applyPrefix(toKey(name, naming), prefix, naming);
|
|
105
|
+
const existing = byKey.get(key);
|
|
106
|
+
if (existing) existing.push(name);
|
|
107
|
+
else byKey.set(key, [name]);
|
|
108
|
+
}
|
|
109
|
+
for (const [key, names] of byKey) {
|
|
110
|
+
if (names.length < 2) byKey.delete(key);
|
|
111
|
+
}
|
|
112
|
+
return byKey;
|
|
113
|
+
}
|
|
101
114
|
function generateCode(varNames, prefix, naming) {
|
|
102
115
|
const entries = varNames.map((name) => {
|
|
103
116
|
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
@@ -146,6 +159,9 @@ async function generate(options) {
|
|
|
146
159
|
if (names.length === 0) {
|
|
147
160
|
console.warn("css-typed-vars: no CSS custom properties found.");
|
|
148
161
|
}
|
|
162
|
+
for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
|
|
163
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
164
|
+
}
|
|
149
165
|
const outPath = (0, import_node_path.resolve)(options.output);
|
|
150
166
|
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
|
|
151
167
|
if (options.output.endsWith(".js")) {
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
generate
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MQAIY4QW.js";
|
|
4
4
|
import {
|
|
5
5
|
generateCode,
|
|
6
6
|
generateDeclaration,
|
|
7
7
|
generateJs,
|
|
8
8
|
parseVarNames,
|
|
9
9
|
scanVarNames
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-Y3WJXRDA.js";
|
|
11
11
|
export {
|
|
12
12
|
generate,
|
|
13
13
|
generateCode,
|
package/dist/rollup.cjs
CHANGED
|
@@ -83,7 +83,7 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
83
83
|
function toKey(cssVarName, naming = "camelCase") {
|
|
84
84
|
const stripped = cssVarName.replace(/^--/, "");
|
|
85
85
|
if (naming === "kebab") return stripped;
|
|
86
|
-
const key = naming === "snake" ? stripped.replace(
|
|
86
|
+
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
87
87
|
return /^\d/.test(key) ? `_${key}` : key;
|
|
88
88
|
}
|
|
89
89
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
package/dist/rollup.js
CHANGED
package/dist/unplugin.cjs
CHANGED
|
@@ -81,7 +81,7 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
81
81
|
function toKey(cssVarName, naming = "camelCase") {
|
|
82
82
|
const stripped = cssVarName.replace(/^--/, "");
|
|
83
83
|
if (naming === "kebab") return stripped;
|
|
84
|
-
const key = naming === "snake" ? stripped.replace(
|
|
84
|
+
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
85
85
|
return /^\d/.test(key) ? `_${key}` : key;
|
|
86
86
|
}
|
|
87
87
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
package/dist/unplugin.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -83,7 +83,7 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
83
83
|
function toKey(cssVarName, naming = "camelCase") {
|
|
84
84
|
const stripped = cssVarName.replace(/^--/, "");
|
|
85
85
|
if (naming === "kebab") return stripped;
|
|
86
|
-
const key = naming === "snake" ? stripped.replace(
|
|
86
|
+
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
87
87
|
return /^\d/.test(key) ? `_${key}` : key;
|
|
88
88
|
}
|
|
89
89
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -83,7 +83,7 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
83
83
|
function toKey(cssVarName, naming = "camelCase") {
|
|
84
84
|
const stripped = cssVarName.replace(/^--/, "");
|
|
85
85
|
if (naming === "kebab") return stripped;
|
|
86
|
-
const key = naming === "snake" ? stripped.replace(
|
|
86
|
+
const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
87
87
|
return /^\d/.test(key) ? `_${key}` : key;
|
|
88
88
|
}
|
|
89
89
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
package/dist/webpack.js
CHANGED