css-typed-vars 0.4.13 → 0.4.14
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-IBTSCKH3.js → chunk-2JDQ2DY7.js} +2 -2
- package/dist/{chunk-3GTZH4ZM.js → chunk-3UIYKYIL.js} +42 -4
- package/dist/{chunk-OKHK5KHU.js → chunk-HS4B2QT2.js} +1 -1
- package/dist/cli.cjs +44 -6
- package/dist/cli.js +3 -3
- package/dist/esbuild.cjs +42 -4
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +43 -5
- package/dist/index.js +2 -2
- package/dist/rollup.cjs +42 -4
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +42 -4
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +42 -4
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +42 -4
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
generateDeclaration,
|
|
5
5
|
generateJs,
|
|
6
6
|
scanVarNames
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-3UIYKYIL.js";
|
|
8
8
|
|
|
9
9
|
// src/index.ts
|
|
10
10
|
import { writeFile, mkdir } from "fs/promises";
|
|
@@ -19,7 +19,7 @@ async function generate(options) {
|
|
|
19
19
|
}
|
|
20
20
|
const outPath = resolve(options.output);
|
|
21
21
|
await mkdir(dirname(outPath), { recursive: true });
|
|
22
|
-
const jsExtMatch = /\.(m|c)?js
|
|
22
|
+
const jsExtMatch = /\.(m|c)?js$/i.exec(options.output);
|
|
23
23
|
if (jsExtMatch) {
|
|
24
24
|
await writeFile(outPath, generateJs(names, options.prefix, options.naming), "utf8");
|
|
25
25
|
const dtsPath = outPath.slice(0, -jsExtMatch[0].length) + ".d.ts";
|
|
@@ -74,6 +74,30 @@ function extractBlock(text, start) {
|
|
|
74
74
|
}
|
|
75
75
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
76
76
|
}
|
|
77
|
+
function maskQuotedContent(text) {
|
|
78
|
+
let result = "";
|
|
79
|
+
let quote = null;
|
|
80
|
+
for (let i = 0; i < text.length; i++) {
|
|
81
|
+
const char = text[i];
|
|
82
|
+
if (quote) {
|
|
83
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
84
|
+
result += " ";
|
|
85
|
+
i++;
|
|
86
|
+
} else if (char === quote) {
|
|
87
|
+
quote = null;
|
|
88
|
+
result += char;
|
|
89
|
+
} else {
|
|
90
|
+
result += " ";
|
|
91
|
+
}
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (char === '"' || char === "'") {
|
|
95
|
+
quote = char;
|
|
96
|
+
}
|
|
97
|
+
result += char;
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
77
101
|
function parseVarNames(css, selectors) {
|
|
78
102
|
const stripped = stripComments(css);
|
|
79
103
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -85,7 +109,7 @@ function parseVarNames(css, selectors) {
|
|
|
85
109
|
while (match = openRegex.exec(stripped)) {
|
|
86
110
|
const start = match.index + match[0].length;
|
|
87
111
|
const block = extractBlock(stripped, start);
|
|
88
|
-
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
112
|
+
for (const prop of maskQuotedContent(block).matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
89
113
|
names.add(prop[0]);
|
|
90
114
|
}
|
|
91
115
|
openRegex.lastIndex = start + block.length + 1;
|
|
@@ -106,7 +130,13 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
106
130
|
const all = /* @__PURE__ */ new Set();
|
|
107
131
|
await Promise.all(
|
|
108
132
|
files.map(async (file) => {
|
|
109
|
-
|
|
133
|
+
let css;
|
|
134
|
+
try {
|
|
135
|
+
css = await readFile(file, "utf8");
|
|
136
|
+
} catch (err) {
|
|
137
|
+
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
110
140
|
for (const name of parseVarNames(css, selectors)) {
|
|
111
141
|
all.add(name);
|
|
112
142
|
}
|
|
@@ -116,7 +146,11 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
116
146
|
}
|
|
117
147
|
|
|
118
148
|
// src/generator.ts
|
|
149
|
+
var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
|
|
119
150
|
function convertCase(value, naming) {
|
|
151
|
+
if (!VALID_NAMINGS.includes(naming)) {
|
|
152
|
+
throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
|
|
153
|
+
}
|
|
120
154
|
if (naming === "kebab") return value;
|
|
121
155
|
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
122
156
|
}
|
|
@@ -127,9 +161,13 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
127
161
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
128
162
|
if (!prefix) return key;
|
|
129
163
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
130
|
-
if (naming
|
|
164
|
+
if (naming === "kebab") {
|
|
165
|
+
normalizedPrefix = normalizedPrefix.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
166
|
+
return `${normalizedPrefix}-${key}`;
|
|
167
|
+
}
|
|
168
|
+
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
169
|
+
if (/^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
131
170
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
132
|
-
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
133
171
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
134
172
|
}
|
|
135
173
|
function formatKey(key, naming = "camelCase") {
|
package/dist/cli.cjs
CHANGED
|
@@ -110,6 +110,30 @@ function extractBlock(text, start) {
|
|
|
110
110
|
}
|
|
111
111
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
112
112
|
}
|
|
113
|
+
function maskQuotedContent(text) {
|
|
114
|
+
let result = "";
|
|
115
|
+
let quote = null;
|
|
116
|
+
for (let i = 0; i < text.length; i++) {
|
|
117
|
+
const char = text[i];
|
|
118
|
+
if (quote) {
|
|
119
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
120
|
+
result += " ";
|
|
121
|
+
i++;
|
|
122
|
+
} else if (char === quote) {
|
|
123
|
+
quote = null;
|
|
124
|
+
result += char;
|
|
125
|
+
} else {
|
|
126
|
+
result += " ";
|
|
127
|
+
}
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (char === '"' || char === "'") {
|
|
131
|
+
quote = char;
|
|
132
|
+
}
|
|
133
|
+
result += char;
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
113
137
|
function parseVarNames(css, selectors) {
|
|
114
138
|
const stripped = stripComments(css);
|
|
115
139
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -121,7 +145,7 @@ function parseVarNames(css, selectors) {
|
|
|
121
145
|
while (match = openRegex.exec(stripped)) {
|
|
122
146
|
const start = match.index + match[0].length;
|
|
123
147
|
const block = extractBlock(stripped, start);
|
|
124
|
-
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
148
|
+
for (const prop of maskQuotedContent(block).matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
125
149
|
names.add(prop[0]);
|
|
126
150
|
}
|
|
127
151
|
openRegex.lastIndex = start + block.length + 1;
|
|
@@ -140,7 +164,13 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
140
164
|
const all = /* @__PURE__ */ new Set();
|
|
141
165
|
await Promise.all(
|
|
142
166
|
files.map(async (file) => {
|
|
143
|
-
|
|
167
|
+
let css;
|
|
168
|
+
try {
|
|
169
|
+
css = await (0, import_promises.readFile)(file, "utf8");
|
|
170
|
+
} catch (err) {
|
|
171
|
+
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
144
174
|
for (const name of parseVarNames(css, selectors)) {
|
|
145
175
|
all.add(name);
|
|
146
176
|
}
|
|
@@ -150,7 +180,11 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
150
180
|
}
|
|
151
181
|
|
|
152
182
|
// src/generator.ts
|
|
183
|
+
var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
|
|
153
184
|
function convertCase(value, naming) {
|
|
185
|
+
if (!VALID_NAMINGS.includes(naming)) {
|
|
186
|
+
throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
|
|
187
|
+
}
|
|
154
188
|
if (naming === "kebab") return value;
|
|
155
189
|
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
156
190
|
}
|
|
@@ -161,9 +195,13 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
161
195
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
162
196
|
if (!prefix) return key;
|
|
163
197
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
164
|
-
if (naming
|
|
198
|
+
if (naming === "kebab") {
|
|
199
|
+
normalizedPrefix = normalizedPrefix.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
200
|
+
return `${normalizedPrefix}-${key}`;
|
|
201
|
+
}
|
|
202
|
+
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
203
|
+
if (/^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
165
204
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
166
|
-
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
167
205
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
168
206
|
}
|
|
169
207
|
function formatKey(key, naming = "camelCase") {
|
|
@@ -236,7 +274,7 @@ async function generate(options) {
|
|
|
236
274
|
}
|
|
237
275
|
const outPath = (0, import_node_path.resolve)(options.output);
|
|
238
276
|
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
|
|
239
|
-
const jsExtMatch = /\.(m|c)?js
|
|
277
|
+
const jsExtMatch = /\.(m|c)?js$/i.exec(options.output);
|
|
240
278
|
if (jsExtMatch) {
|
|
241
279
|
await (0, import_promises2.writeFile)(outPath, generateJs(names, options.prefix, options.naming), "utf8");
|
|
242
280
|
const dtsPath = outPath.slice(0, -jsExtMatch[0].length) + ".d.ts";
|
|
@@ -277,7 +315,7 @@ async function loadConfig() {
|
|
|
277
315
|
return JSON.parse(content);
|
|
278
316
|
} else {
|
|
279
317
|
const mod = await import((0, import_node_url.pathToFileURL)(path).href);
|
|
280
|
-
return mod.default;
|
|
318
|
+
return mod.default ?? {};
|
|
281
319
|
}
|
|
282
320
|
} catch (err) {
|
|
283
321
|
const code = err.code;
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
generate
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-2JDQ2DY7.js";
|
|
5
|
+
import "./chunk-3UIYKYIL.js";
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
8
8
|
import { readFile } from "fs/promises";
|
|
@@ -39,7 +39,7 @@ async function loadConfig() {
|
|
|
39
39
|
return JSON.parse(content);
|
|
40
40
|
} else {
|
|
41
41
|
const mod = await import(pathToFileURL(path).href);
|
|
42
|
-
return mod.default;
|
|
42
|
+
return mod.default ?? {};
|
|
43
43
|
}
|
|
44
44
|
} catch (err) {
|
|
45
45
|
const code = err.code;
|
package/dist/esbuild.cjs
CHANGED
|
@@ -112,6 +112,30 @@ function extractBlock(text, start) {
|
|
|
112
112
|
}
|
|
113
113
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
114
114
|
}
|
|
115
|
+
function maskQuotedContent(text) {
|
|
116
|
+
let result = "";
|
|
117
|
+
let quote = null;
|
|
118
|
+
for (let i = 0; i < text.length; i++) {
|
|
119
|
+
const char = text[i];
|
|
120
|
+
if (quote) {
|
|
121
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
122
|
+
result += " ";
|
|
123
|
+
i++;
|
|
124
|
+
} else if (char === quote) {
|
|
125
|
+
quote = null;
|
|
126
|
+
result += char;
|
|
127
|
+
} else {
|
|
128
|
+
result += " ";
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (char === '"' || char === "'") {
|
|
133
|
+
quote = char;
|
|
134
|
+
}
|
|
135
|
+
result += char;
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
115
139
|
function parseVarNames(css, selectors) {
|
|
116
140
|
const stripped = stripComments(css);
|
|
117
141
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -123,7 +147,7 @@ function parseVarNames(css, selectors) {
|
|
|
123
147
|
while (match = openRegex.exec(stripped)) {
|
|
124
148
|
const start = match.index + match[0].length;
|
|
125
149
|
const block = extractBlock(stripped, start);
|
|
126
|
-
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
150
|
+
for (const prop of maskQuotedContent(block).matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
127
151
|
names.add(prop[0]);
|
|
128
152
|
}
|
|
129
153
|
openRegex.lastIndex = start + block.length + 1;
|
|
@@ -142,7 +166,13 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
142
166
|
const all = /* @__PURE__ */ new Set();
|
|
143
167
|
await Promise.all(
|
|
144
168
|
files.map(async (file) => {
|
|
145
|
-
|
|
169
|
+
let css;
|
|
170
|
+
try {
|
|
171
|
+
css = await (0, import_promises.readFile)(file, "utf8");
|
|
172
|
+
} catch (err) {
|
|
173
|
+
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
146
176
|
for (const name of parseVarNames(css, selectors)) {
|
|
147
177
|
all.add(name);
|
|
148
178
|
}
|
|
@@ -152,7 +182,11 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
152
182
|
}
|
|
153
183
|
|
|
154
184
|
// src/generator.ts
|
|
185
|
+
var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
|
|
155
186
|
function convertCase(value, naming) {
|
|
187
|
+
if (!VALID_NAMINGS.includes(naming)) {
|
|
188
|
+
throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
|
|
189
|
+
}
|
|
156
190
|
if (naming === "kebab") return value;
|
|
157
191
|
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
158
192
|
}
|
|
@@ -163,9 +197,13 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
163
197
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
164
198
|
if (!prefix) return key;
|
|
165
199
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
166
|
-
if (naming
|
|
200
|
+
if (naming === "kebab") {
|
|
201
|
+
normalizedPrefix = normalizedPrefix.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
202
|
+
return `${normalizedPrefix}-${key}`;
|
|
203
|
+
}
|
|
204
|
+
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
205
|
+
if (/^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
167
206
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
168
|
-
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
169
207
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
170
208
|
}
|
|
171
209
|
function formatKey(key, naming = "camelCase") {
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -114,6 +114,30 @@ function extractBlock(text, start) {
|
|
|
114
114
|
}
|
|
115
115
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
116
116
|
}
|
|
117
|
+
function maskQuotedContent(text) {
|
|
118
|
+
let result = "";
|
|
119
|
+
let quote = null;
|
|
120
|
+
for (let i = 0; i < text.length; i++) {
|
|
121
|
+
const char = text[i];
|
|
122
|
+
if (quote) {
|
|
123
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
124
|
+
result += " ";
|
|
125
|
+
i++;
|
|
126
|
+
} else if (char === quote) {
|
|
127
|
+
quote = null;
|
|
128
|
+
result += char;
|
|
129
|
+
} else {
|
|
130
|
+
result += " ";
|
|
131
|
+
}
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (char === '"' || char === "'") {
|
|
135
|
+
quote = char;
|
|
136
|
+
}
|
|
137
|
+
result += char;
|
|
138
|
+
}
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
117
141
|
function parseVarNames(css, selectors) {
|
|
118
142
|
const stripped = stripComments(css);
|
|
119
143
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -125,7 +149,7 @@ function parseVarNames(css, selectors) {
|
|
|
125
149
|
while (match = openRegex.exec(stripped)) {
|
|
126
150
|
const start = match.index + match[0].length;
|
|
127
151
|
const block = extractBlock(stripped, start);
|
|
128
|
-
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
152
|
+
for (const prop of maskQuotedContent(block).matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
129
153
|
names.add(prop[0]);
|
|
130
154
|
}
|
|
131
155
|
openRegex.lastIndex = start + block.length + 1;
|
|
@@ -144,7 +168,13 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
144
168
|
const all = /* @__PURE__ */ new Set();
|
|
145
169
|
await Promise.all(
|
|
146
170
|
files.map(async (file) => {
|
|
147
|
-
|
|
171
|
+
let css;
|
|
172
|
+
try {
|
|
173
|
+
css = await (0, import_promises.readFile)(file, "utf8");
|
|
174
|
+
} catch (err) {
|
|
175
|
+
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
148
178
|
for (const name of parseVarNames(css, selectors)) {
|
|
149
179
|
all.add(name);
|
|
150
180
|
}
|
|
@@ -154,7 +184,11 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
154
184
|
}
|
|
155
185
|
|
|
156
186
|
// src/generator.ts
|
|
187
|
+
var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
|
|
157
188
|
function convertCase(value, naming) {
|
|
189
|
+
if (!VALID_NAMINGS.includes(naming)) {
|
|
190
|
+
throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
|
|
191
|
+
}
|
|
158
192
|
if (naming === "kebab") return value;
|
|
159
193
|
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
160
194
|
}
|
|
@@ -165,9 +199,13 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
165
199
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
166
200
|
if (!prefix) return key;
|
|
167
201
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
168
|
-
if (naming
|
|
202
|
+
if (naming === "kebab") {
|
|
203
|
+
normalizedPrefix = normalizedPrefix.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
204
|
+
return `${normalizedPrefix}-${key}`;
|
|
205
|
+
}
|
|
206
|
+
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
207
|
+
if (/^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
169
208
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
170
|
-
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
171
209
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
172
210
|
}
|
|
173
211
|
function formatKey(key, naming = "camelCase") {
|
|
@@ -240,7 +278,7 @@ async function generate(options) {
|
|
|
240
278
|
}
|
|
241
279
|
const outPath = (0, import_node_path.resolve)(options.output);
|
|
242
280
|
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
|
|
243
|
-
const jsExtMatch = /\.(m|c)?js
|
|
281
|
+
const jsExtMatch = /\.(m|c)?js$/i.exec(options.output);
|
|
244
282
|
if (jsExtMatch) {
|
|
245
283
|
await (0, import_promises2.writeFile)(outPath, generateJs(names, options.prefix, options.naming), "utf8");
|
|
246
284
|
const dtsPath = outPath.slice(0, -jsExtMatch[0].length) + ".d.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
generate
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2JDQ2DY7.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-3UIYKYIL.js";
|
|
11
11
|
export {
|
|
12
12
|
generate,
|
|
13
13
|
generateCode,
|
package/dist/rollup.cjs
CHANGED
|
@@ -112,6 +112,30 @@ function extractBlock(text, start) {
|
|
|
112
112
|
}
|
|
113
113
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
114
114
|
}
|
|
115
|
+
function maskQuotedContent(text) {
|
|
116
|
+
let result = "";
|
|
117
|
+
let quote = null;
|
|
118
|
+
for (let i = 0; i < text.length; i++) {
|
|
119
|
+
const char = text[i];
|
|
120
|
+
if (quote) {
|
|
121
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
122
|
+
result += " ";
|
|
123
|
+
i++;
|
|
124
|
+
} else if (char === quote) {
|
|
125
|
+
quote = null;
|
|
126
|
+
result += char;
|
|
127
|
+
} else {
|
|
128
|
+
result += " ";
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (char === '"' || char === "'") {
|
|
133
|
+
quote = char;
|
|
134
|
+
}
|
|
135
|
+
result += char;
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
115
139
|
function parseVarNames(css, selectors) {
|
|
116
140
|
const stripped = stripComments(css);
|
|
117
141
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -123,7 +147,7 @@ function parseVarNames(css, selectors) {
|
|
|
123
147
|
while (match = openRegex.exec(stripped)) {
|
|
124
148
|
const start = match.index + match[0].length;
|
|
125
149
|
const block = extractBlock(stripped, start);
|
|
126
|
-
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
150
|
+
for (const prop of maskQuotedContent(block).matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
127
151
|
names.add(prop[0]);
|
|
128
152
|
}
|
|
129
153
|
openRegex.lastIndex = start + block.length + 1;
|
|
@@ -142,7 +166,13 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
142
166
|
const all = /* @__PURE__ */ new Set();
|
|
143
167
|
await Promise.all(
|
|
144
168
|
files.map(async (file) => {
|
|
145
|
-
|
|
169
|
+
let css;
|
|
170
|
+
try {
|
|
171
|
+
css = await (0, import_promises.readFile)(file, "utf8");
|
|
172
|
+
} catch (err) {
|
|
173
|
+
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
146
176
|
for (const name of parseVarNames(css, selectors)) {
|
|
147
177
|
all.add(name);
|
|
148
178
|
}
|
|
@@ -152,7 +182,11 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
152
182
|
}
|
|
153
183
|
|
|
154
184
|
// src/generator.ts
|
|
185
|
+
var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
|
|
155
186
|
function convertCase(value, naming) {
|
|
187
|
+
if (!VALID_NAMINGS.includes(naming)) {
|
|
188
|
+
throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
|
|
189
|
+
}
|
|
156
190
|
if (naming === "kebab") return value;
|
|
157
191
|
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
158
192
|
}
|
|
@@ -163,9 +197,13 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
163
197
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
164
198
|
if (!prefix) return key;
|
|
165
199
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
166
|
-
if (naming
|
|
200
|
+
if (naming === "kebab") {
|
|
201
|
+
normalizedPrefix = normalizedPrefix.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
202
|
+
return `${normalizedPrefix}-${key}`;
|
|
203
|
+
}
|
|
204
|
+
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
205
|
+
if (/^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
167
206
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
168
|
-
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
169
207
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
170
208
|
}
|
|
171
209
|
function formatKey(key, naming = "camelCase") {
|
package/dist/rollup.js
CHANGED
package/dist/unplugin.cjs
CHANGED
|
@@ -110,6 +110,30 @@ function extractBlock(text, start) {
|
|
|
110
110
|
}
|
|
111
111
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
112
112
|
}
|
|
113
|
+
function maskQuotedContent(text) {
|
|
114
|
+
let result = "";
|
|
115
|
+
let quote = null;
|
|
116
|
+
for (let i = 0; i < text.length; i++) {
|
|
117
|
+
const char = text[i];
|
|
118
|
+
if (quote) {
|
|
119
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
120
|
+
result += " ";
|
|
121
|
+
i++;
|
|
122
|
+
} else if (char === quote) {
|
|
123
|
+
quote = null;
|
|
124
|
+
result += char;
|
|
125
|
+
} else {
|
|
126
|
+
result += " ";
|
|
127
|
+
}
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (char === '"' || char === "'") {
|
|
131
|
+
quote = char;
|
|
132
|
+
}
|
|
133
|
+
result += char;
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
113
137
|
function parseVarNames(css, selectors) {
|
|
114
138
|
const stripped = stripComments(css);
|
|
115
139
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -121,7 +145,7 @@ function parseVarNames(css, selectors) {
|
|
|
121
145
|
while (match = openRegex.exec(stripped)) {
|
|
122
146
|
const start = match.index + match[0].length;
|
|
123
147
|
const block = extractBlock(stripped, start);
|
|
124
|
-
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
148
|
+
for (const prop of maskQuotedContent(block).matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
125
149
|
names.add(prop[0]);
|
|
126
150
|
}
|
|
127
151
|
openRegex.lastIndex = start + block.length + 1;
|
|
@@ -140,7 +164,13 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
140
164
|
const all = /* @__PURE__ */ new Set();
|
|
141
165
|
await Promise.all(
|
|
142
166
|
files.map(async (file) => {
|
|
143
|
-
|
|
167
|
+
let css;
|
|
168
|
+
try {
|
|
169
|
+
css = await (0, import_promises.readFile)(file, "utf8");
|
|
170
|
+
} catch (err) {
|
|
171
|
+
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
144
174
|
for (const name of parseVarNames(css, selectors)) {
|
|
145
175
|
all.add(name);
|
|
146
176
|
}
|
|
@@ -150,7 +180,11 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
150
180
|
}
|
|
151
181
|
|
|
152
182
|
// src/generator.ts
|
|
183
|
+
var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
|
|
153
184
|
function convertCase(value, naming) {
|
|
185
|
+
if (!VALID_NAMINGS.includes(naming)) {
|
|
186
|
+
throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
|
|
187
|
+
}
|
|
154
188
|
if (naming === "kebab") return value;
|
|
155
189
|
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
156
190
|
}
|
|
@@ -161,9 +195,13 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
161
195
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
162
196
|
if (!prefix) return key;
|
|
163
197
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
164
|
-
if (naming
|
|
198
|
+
if (naming === "kebab") {
|
|
199
|
+
normalizedPrefix = normalizedPrefix.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
200
|
+
return `${normalizedPrefix}-${key}`;
|
|
201
|
+
}
|
|
202
|
+
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
203
|
+
if (/^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
165
204
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
166
|
-
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
167
205
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
168
206
|
}
|
|
169
207
|
function formatKey(key, naming = "camelCase") {
|
package/dist/unplugin.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -112,6 +112,30 @@ function extractBlock(text, start) {
|
|
|
112
112
|
}
|
|
113
113
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
114
114
|
}
|
|
115
|
+
function maskQuotedContent(text) {
|
|
116
|
+
let result = "";
|
|
117
|
+
let quote = null;
|
|
118
|
+
for (let i = 0; i < text.length; i++) {
|
|
119
|
+
const char = text[i];
|
|
120
|
+
if (quote) {
|
|
121
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
122
|
+
result += " ";
|
|
123
|
+
i++;
|
|
124
|
+
} else if (char === quote) {
|
|
125
|
+
quote = null;
|
|
126
|
+
result += char;
|
|
127
|
+
} else {
|
|
128
|
+
result += " ";
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (char === '"' || char === "'") {
|
|
133
|
+
quote = char;
|
|
134
|
+
}
|
|
135
|
+
result += char;
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
115
139
|
function parseVarNames(css, selectors) {
|
|
116
140
|
const stripped = stripComments(css);
|
|
117
141
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -123,7 +147,7 @@ function parseVarNames(css, selectors) {
|
|
|
123
147
|
while (match = openRegex.exec(stripped)) {
|
|
124
148
|
const start = match.index + match[0].length;
|
|
125
149
|
const block = extractBlock(stripped, start);
|
|
126
|
-
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
150
|
+
for (const prop of maskQuotedContent(block).matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
127
151
|
names.add(prop[0]);
|
|
128
152
|
}
|
|
129
153
|
openRegex.lastIndex = start + block.length + 1;
|
|
@@ -142,7 +166,13 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
142
166
|
const all = /* @__PURE__ */ new Set();
|
|
143
167
|
await Promise.all(
|
|
144
168
|
files.map(async (file) => {
|
|
145
|
-
|
|
169
|
+
let css;
|
|
170
|
+
try {
|
|
171
|
+
css = await (0, import_promises.readFile)(file, "utf8");
|
|
172
|
+
} catch (err) {
|
|
173
|
+
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
146
176
|
for (const name of parseVarNames(css, selectors)) {
|
|
147
177
|
all.add(name);
|
|
148
178
|
}
|
|
@@ -152,7 +182,11 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
152
182
|
}
|
|
153
183
|
|
|
154
184
|
// src/generator.ts
|
|
185
|
+
var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
|
|
155
186
|
function convertCase(value, naming) {
|
|
187
|
+
if (!VALID_NAMINGS.includes(naming)) {
|
|
188
|
+
throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
|
|
189
|
+
}
|
|
156
190
|
if (naming === "kebab") return value;
|
|
157
191
|
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
158
192
|
}
|
|
@@ -163,9 +197,13 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
163
197
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
164
198
|
if (!prefix) return key;
|
|
165
199
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
166
|
-
if (naming
|
|
200
|
+
if (naming === "kebab") {
|
|
201
|
+
normalizedPrefix = normalizedPrefix.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
202
|
+
return `${normalizedPrefix}-${key}`;
|
|
203
|
+
}
|
|
204
|
+
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
205
|
+
if (/^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
167
206
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
168
|
-
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
169
207
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
170
208
|
}
|
|
171
209
|
function formatKey(key, naming = "camelCase") {
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -112,6 +112,30 @@ function extractBlock(text, start) {
|
|
|
112
112
|
}
|
|
113
113
|
return text.slice(start, depth === 0 ? i - 1 : i);
|
|
114
114
|
}
|
|
115
|
+
function maskQuotedContent(text) {
|
|
116
|
+
let result = "";
|
|
117
|
+
let quote = null;
|
|
118
|
+
for (let i = 0; i < text.length; i++) {
|
|
119
|
+
const char = text[i];
|
|
120
|
+
if (quote) {
|
|
121
|
+
if (char === "\\" && i + 1 < text.length) {
|
|
122
|
+
result += " ";
|
|
123
|
+
i++;
|
|
124
|
+
} else if (char === quote) {
|
|
125
|
+
quote = null;
|
|
126
|
+
result += char;
|
|
127
|
+
} else {
|
|
128
|
+
result += " ";
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (char === '"' || char === "'") {
|
|
133
|
+
quote = char;
|
|
134
|
+
}
|
|
135
|
+
result += char;
|
|
136
|
+
}
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
115
139
|
function parseVarNames(css, selectors) {
|
|
116
140
|
const stripped = stripComments(css);
|
|
117
141
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -123,7 +147,7 @@ function parseVarNames(css, selectors) {
|
|
|
123
147
|
while (match = openRegex.exec(stripped)) {
|
|
124
148
|
const start = match.index + match[0].length;
|
|
125
149
|
const block = extractBlock(stripped, start);
|
|
126
|
-
for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
150
|
+
for (const prop of maskQuotedContent(block).matchAll(/--[\w-]+(?=\s*:)/g)) {
|
|
127
151
|
names.add(prop[0]);
|
|
128
152
|
}
|
|
129
153
|
openRegex.lastIndex = start + block.length + 1;
|
|
@@ -142,7 +166,13 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
142
166
|
const all = /* @__PURE__ */ new Set();
|
|
143
167
|
await Promise.all(
|
|
144
168
|
files.map(async (file) => {
|
|
145
|
-
|
|
169
|
+
let css;
|
|
170
|
+
try {
|
|
171
|
+
css = await (0, import_promises.readFile)(file, "utf8");
|
|
172
|
+
} catch (err) {
|
|
173
|
+
console.warn(`css-typed-vars: skipping "${file}": ${err.message}`);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
146
176
|
for (const name of parseVarNames(css, selectors)) {
|
|
147
177
|
all.add(name);
|
|
148
178
|
}
|
|
@@ -152,7 +182,11 @@ async function scanVarNames(patterns, exclude, selectors) {
|
|
|
152
182
|
}
|
|
153
183
|
|
|
154
184
|
// src/generator.ts
|
|
185
|
+
var VALID_NAMINGS = ["camelCase", "snake", "kebab"];
|
|
155
186
|
function convertCase(value, naming) {
|
|
187
|
+
if (!VALID_NAMINGS.includes(naming)) {
|
|
188
|
+
throw new Error(`css-typed-vars: invalid naming "${naming}". Valid values: camelCase, snake, kebab`);
|
|
189
|
+
}
|
|
156
190
|
if (naming === "kebab") return value;
|
|
157
191
|
return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
|
|
158
192
|
}
|
|
@@ -163,9 +197,13 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
163
197
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
164
198
|
if (!prefix) return key;
|
|
165
199
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
166
|
-
if (naming
|
|
200
|
+
if (naming === "kebab") {
|
|
201
|
+
normalizedPrefix = normalizedPrefix.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
202
|
+
return `${normalizedPrefix}-${key}`;
|
|
203
|
+
}
|
|
204
|
+
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
205
|
+
if (/^\d/.test(normalizedPrefix)) normalizedPrefix = `_${normalizedPrefix}`;
|
|
167
206
|
if (naming === "snake") return `${normalizedPrefix}_${key}`;
|
|
168
|
-
if (naming === "kebab") return `${normalizedPrefix}-${key}`;
|
|
169
207
|
return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
170
208
|
}
|
|
171
209
|
function formatKey(key, naming = "camelCase") {
|
package/dist/webpack.js
CHANGED