css-typed-vars 0.4.15 → 0.4.16
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-2QDRH4OL.js → chunk-ARQR224L.js} +4 -6
- package/dist/{chunk-W4JDUG2N.js → chunk-NS2BULH3.js} +38 -14
- package/dist/{chunk-AUFD5VOT.js → chunk-YJPHNISO.js} +12 -11
- package/dist/cli.cjs +38 -16
- package/dist/cli.js +2 -2
- package/dist/esbuild.cjs +46 -21
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +38 -16
- package/dist/index.js +2 -2
- package/dist/rollup.cjs +46 -21
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +46 -21
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +46 -21
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +46 -21
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
findKeyCollisions,
|
|
3
2
|
generateCode,
|
|
4
3
|
generateDeclaration,
|
|
5
4
|
generateJs,
|
|
6
|
-
scanVarNames
|
|
7
|
-
|
|
5
|
+
scanVarNames,
|
|
6
|
+
warnOnCollisions
|
|
7
|
+
} from "./chunk-NS2BULH3.js";
|
|
8
8
|
|
|
9
9
|
// src/index.ts
|
|
10
10
|
import { writeFile, mkdir } from "fs/promises";
|
|
@@ -14,9 +14,7 @@ async function generate(options) {
|
|
|
14
14
|
if (names.length === 0) {
|
|
15
15
|
console.warn("css-typed-vars: no CSS custom properties found.");
|
|
16
16
|
}
|
|
17
|
-
|
|
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
|
-
}
|
|
17
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
20
18
|
const outPath = resolve(options.output);
|
|
21
19
|
await mkdir(dirname(outPath), { recursive: true });
|
|
22
20
|
const jsExtMatch = /\.(m|c)?js$/i.exec(options.output);
|
|
@@ -6,6 +6,12 @@ var getDirname = () => path.dirname(getFilename());
|
|
|
6
6
|
var __dirname = /* @__PURE__ */ getDirname();
|
|
7
7
|
|
|
8
8
|
// src/parser.ts
|
|
9
|
+
function stepQuote(text, i, quote) {
|
|
10
|
+
const char = text[i];
|
|
11
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
12
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
13
|
+
return { consumed: 1, closed: false };
|
|
14
|
+
}
|
|
9
15
|
function stripComments(text) {
|
|
10
16
|
let result = "";
|
|
11
17
|
let quote = null;
|
|
@@ -13,12 +19,10 @@ function stripComments(text) {
|
|
|
13
19
|
for (let i = 0; i < text.length; i++) {
|
|
14
20
|
const char = text[i];
|
|
15
21
|
if (quote) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
quote = null;
|
|
21
|
-
}
|
|
22
|
+
const step = stepQuote(text, i, quote);
|
|
23
|
+
result += text.slice(i, i + step.consumed);
|
|
24
|
+
if (step.closed) quote = null;
|
|
25
|
+
i += step.consumed - 1;
|
|
22
26
|
continue;
|
|
23
27
|
}
|
|
24
28
|
if (char === '"' || char === "'") {
|
|
@@ -80,15 +84,14 @@ function maskQuotedContent(text) {
|
|
|
80
84
|
for (let i = 0; i < text.length; i++) {
|
|
81
85
|
const char = text[i];
|
|
82
86
|
if (quote) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
i++;
|
|
86
|
-
} else if (char === quote) {
|
|
87
|
-
quote = null;
|
|
87
|
+
const step = stepQuote(text, i, quote);
|
|
88
|
+
if (step.closed) {
|
|
88
89
|
result += char;
|
|
90
|
+
quote = null;
|
|
89
91
|
} else {
|
|
90
|
-
result += " ";
|
|
92
|
+
result += " ".repeat(step.consumed);
|
|
91
93
|
}
|
|
94
|
+
i += step.consumed - 1;
|
|
92
95
|
continue;
|
|
93
96
|
}
|
|
94
97
|
if (char === '"' || char === "'") {
|
|
@@ -158,11 +161,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
158
161
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
159
162
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
160
163
|
}
|
|
164
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
165
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
166
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
167
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
168
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
169
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
170
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
171
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
172
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
173
|
+
function escapeSingleQuoted(value) {
|
|
174
|
+
let result = "";
|
|
175
|
+
for (const char of value) {
|
|
176
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
161
180
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
162
181
|
if (!prefix) return key;
|
|
163
182
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
164
183
|
if (naming === "kebab") {
|
|
165
|
-
normalizedPrefix = normalizedPrefix
|
|
184
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
166
185
|
return `${normalizedPrefix}-${key}`;
|
|
167
186
|
}
|
|
168
187
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -187,6 +206,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
187
206
|
}
|
|
188
207
|
return byKey;
|
|
189
208
|
}
|
|
209
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
210
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
211
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
190
214
|
function buildEntries(varNames, prefix, naming) {
|
|
191
215
|
const byKey = /* @__PURE__ */ new Map();
|
|
192
216
|
for (const name of varNames) {
|
|
@@ -233,7 +257,7 @@ export {
|
|
|
233
257
|
parseVarNames,
|
|
234
258
|
scanVarNames,
|
|
235
259
|
VALID_NAMINGS,
|
|
236
|
-
|
|
260
|
+
warnOnCollisions,
|
|
237
261
|
generateCode,
|
|
238
262
|
generateJs,
|
|
239
263
|
generateDeclaration
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__dirname,
|
|
3
|
-
findKeyCollisions,
|
|
4
3
|
generateDeclaration,
|
|
5
4
|
generateJs,
|
|
6
|
-
scanVarNames
|
|
7
|
-
|
|
5
|
+
scanVarNames,
|
|
6
|
+
warnOnCollisions
|
|
7
|
+
} from "./chunk-NS2BULH3.js";
|
|
8
8
|
|
|
9
9
|
// src/unplugin.ts
|
|
10
10
|
import { createUnplugin } from "unplugin";
|
|
@@ -12,11 +12,6 @@ import { writeFile } from "fs/promises";
|
|
|
12
12
|
import { join, resolve } from "path";
|
|
13
13
|
var VIRTUAL_ID = "css-typed-vars/vars";
|
|
14
14
|
var RESOLVED_ID = "\0css-typed-vars/vars";
|
|
15
|
-
function warnOnCollisions(names, options) {
|
|
16
|
-
for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
|
|
17
|
-
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
15
|
function getDtsPath(options) {
|
|
21
16
|
if (options.dts === false) return null;
|
|
22
17
|
return options.dts ? resolve(process.cwd(), options.dts) : join(__dirname, "generated.d.ts");
|
|
@@ -30,16 +25,22 @@ var unplugin_default = createUnplugin((options) => {
|
|
|
30
25
|
configureServer(server) {
|
|
31
26
|
let generation = 0;
|
|
32
27
|
let debounceTimer = null;
|
|
28
|
+
let writeQueue = Promise.resolve();
|
|
33
29
|
const rescan = async () => {
|
|
34
30
|
const myGeneration = ++generation;
|
|
35
31
|
const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
|
|
36
32
|
cachedNames = namesPromise;
|
|
37
33
|
const names = await namesPromise;
|
|
38
34
|
if (myGeneration !== generation) return;
|
|
39
|
-
warnOnCollisions(names, options);
|
|
35
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
40
36
|
const dtsPath = getDtsPath(options);
|
|
41
37
|
if (dtsPath) {
|
|
42
|
-
|
|
38
|
+
const content = generateDeclaration(names, options.prefix, options.naming);
|
|
39
|
+
writeQueue = writeQueue.then(async () => {
|
|
40
|
+
if (myGeneration !== generation) return;
|
|
41
|
+
await writeFile(dtsPath, content, "utf8");
|
|
42
|
+
}).catch(console.error);
|
|
43
|
+
await writeQueue;
|
|
43
44
|
}
|
|
44
45
|
if (myGeneration !== generation) return;
|
|
45
46
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
@@ -64,7 +65,7 @@ var unplugin_default = createUnplugin((options) => {
|
|
|
64
65
|
async buildStart() {
|
|
65
66
|
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
66
67
|
const names = await cachedNames;
|
|
67
|
-
warnOnCollisions(names, options);
|
|
68
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
68
69
|
const dtsPath = getDtsPath(options);
|
|
69
70
|
if (!dtsPath) return;
|
|
70
71
|
await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
package/dist/cli.cjs
CHANGED
|
@@ -42,6 +42,12 @@ var import_promises = require("fs/promises");
|
|
|
42
42
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
43
43
|
|
|
44
44
|
// src/parser.ts
|
|
45
|
+
function stepQuote(text, i, quote) {
|
|
46
|
+
const char = text[i];
|
|
47
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
48
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
49
|
+
return { consumed: 1, closed: false };
|
|
50
|
+
}
|
|
45
51
|
function stripComments(text) {
|
|
46
52
|
let result = "";
|
|
47
53
|
let quote = null;
|
|
@@ -49,12 +55,10 @@ function stripComments(text) {
|
|
|
49
55
|
for (let i = 0; i < text.length; i++) {
|
|
50
56
|
const char = text[i];
|
|
51
57
|
if (quote) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
quote = null;
|
|
57
|
-
}
|
|
58
|
+
const step = stepQuote(text, i, quote);
|
|
59
|
+
result += text.slice(i, i + step.consumed);
|
|
60
|
+
if (step.closed) quote = null;
|
|
61
|
+
i += step.consumed - 1;
|
|
58
62
|
continue;
|
|
59
63
|
}
|
|
60
64
|
if (char === '"' || char === "'") {
|
|
@@ -116,15 +120,14 @@ function maskQuotedContent(text) {
|
|
|
116
120
|
for (let i = 0; i < text.length; i++) {
|
|
117
121
|
const char = text[i];
|
|
118
122
|
if (quote) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
i++;
|
|
122
|
-
} else if (char === quote) {
|
|
123
|
-
quote = null;
|
|
123
|
+
const step = stepQuote(text, i, quote);
|
|
124
|
+
if (step.closed) {
|
|
124
125
|
result += char;
|
|
126
|
+
quote = null;
|
|
125
127
|
} else {
|
|
126
|
-
result += " ";
|
|
128
|
+
result += " ".repeat(step.consumed);
|
|
127
129
|
}
|
|
130
|
+
i += step.consumed - 1;
|
|
128
131
|
continue;
|
|
129
132
|
}
|
|
130
133
|
if (char === '"' || char === "'") {
|
|
@@ -192,11 +195,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
192
195
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
193
196
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
194
197
|
}
|
|
198
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
199
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
200
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
201
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
202
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
203
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
204
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
205
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
206
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
207
|
+
function escapeSingleQuoted(value) {
|
|
208
|
+
let result = "";
|
|
209
|
+
for (const char of value) {
|
|
210
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
195
214
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
196
215
|
if (!prefix) return key;
|
|
197
216
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
198
217
|
if (naming === "kebab") {
|
|
199
|
-
normalizedPrefix = normalizedPrefix
|
|
218
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
200
219
|
return `${normalizedPrefix}-${key}`;
|
|
201
220
|
}
|
|
202
221
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -221,6 +240,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
221
240
|
}
|
|
222
241
|
return byKey;
|
|
223
242
|
}
|
|
243
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
244
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
245
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
224
248
|
function buildEntries(varNames, prefix, naming) {
|
|
225
249
|
const byKey = /* @__PURE__ */ new Map();
|
|
226
250
|
for (const name of varNames) {
|
|
@@ -268,9 +292,7 @@ async function generate(options) {
|
|
|
268
292
|
if (names.length === 0) {
|
|
269
293
|
console.warn("css-typed-vars: no CSS custom properties found.");
|
|
270
294
|
}
|
|
271
|
-
|
|
272
|
-
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
273
|
-
}
|
|
295
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
274
296
|
const outPath = (0, import_node_path.resolve)(options.output);
|
|
275
297
|
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
|
|
276
298
|
const jsExtMatch = /\.(m|c)?js$/i.exec(options.output);
|
package/dist/cli.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
generate
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ARQR224L.js";
|
|
5
5
|
import {
|
|
6
6
|
VALID_NAMINGS
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-NS2BULH3.js";
|
|
8
8
|
|
|
9
9
|
// src/cli.ts
|
|
10
10
|
import { readFile } from "fs/promises";
|
package/dist/esbuild.cjs
CHANGED
|
@@ -44,6 +44,12 @@ var import_promises = require("fs/promises");
|
|
|
44
44
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
|
+
function stepQuote(text, i, quote) {
|
|
48
|
+
const char = text[i];
|
|
49
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
50
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
51
|
+
return { consumed: 1, closed: false };
|
|
52
|
+
}
|
|
47
53
|
function stripComments(text) {
|
|
48
54
|
let result = "";
|
|
49
55
|
let quote = null;
|
|
@@ -51,12 +57,10 @@ function stripComments(text) {
|
|
|
51
57
|
for (let i = 0; i < text.length; i++) {
|
|
52
58
|
const char = text[i];
|
|
53
59
|
if (quote) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
quote = null;
|
|
59
|
-
}
|
|
60
|
+
const step = stepQuote(text, i, quote);
|
|
61
|
+
result += text.slice(i, i + step.consumed);
|
|
62
|
+
if (step.closed) quote = null;
|
|
63
|
+
i += step.consumed - 1;
|
|
60
64
|
continue;
|
|
61
65
|
}
|
|
62
66
|
if (char === '"' || char === "'") {
|
|
@@ -118,15 +122,14 @@ function maskQuotedContent(text) {
|
|
|
118
122
|
for (let i = 0; i < text.length; i++) {
|
|
119
123
|
const char = text[i];
|
|
120
124
|
if (quote) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
i++;
|
|
124
|
-
} else if (char === quote) {
|
|
125
|
-
quote = null;
|
|
125
|
+
const step = stepQuote(text, i, quote);
|
|
126
|
+
if (step.closed) {
|
|
126
127
|
result += char;
|
|
128
|
+
quote = null;
|
|
127
129
|
} else {
|
|
128
|
-
result += " ";
|
|
130
|
+
result += " ".repeat(step.consumed);
|
|
129
131
|
}
|
|
132
|
+
i += step.consumed - 1;
|
|
130
133
|
continue;
|
|
131
134
|
}
|
|
132
135
|
if (char === '"' || char === "'") {
|
|
@@ -194,11 +197,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
194
197
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
195
198
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
196
199
|
}
|
|
200
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
201
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
202
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
203
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
204
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
205
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
206
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
207
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
208
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
209
|
+
function escapeSingleQuoted(value) {
|
|
210
|
+
let result = "";
|
|
211
|
+
for (const char of value) {
|
|
212
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
213
|
+
}
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
197
216
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
198
217
|
if (!prefix) return key;
|
|
199
218
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
200
219
|
if (naming === "kebab") {
|
|
201
|
-
normalizedPrefix = normalizedPrefix
|
|
220
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
202
221
|
return `${normalizedPrefix}-${key}`;
|
|
203
222
|
}
|
|
204
223
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -223,6 +242,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
223
242
|
}
|
|
224
243
|
return byKey;
|
|
225
244
|
}
|
|
245
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
246
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
247
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
226
250
|
function buildEntries(varNames, prefix, naming) {
|
|
227
251
|
const byKey = /* @__PURE__ */ new Map();
|
|
228
252
|
for (const name of varNames) {
|
|
@@ -255,11 +279,6 @@ function generateDeclaration(varNames, prefix, naming) {
|
|
|
255
279
|
// src/unplugin.ts
|
|
256
280
|
var VIRTUAL_ID = "css-typed-vars/vars";
|
|
257
281
|
var RESOLVED_ID = "\0css-typed-vars/vars";
|
|
258
|
-
function warnOnCollisions(names, options) {
|
|
259
|
-
for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
|
|
260
|
-
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
282
|
function getDtsPath(options) {
|
|
264
283
|
if (options.dts === false) return null;
|
|
265
284
|
return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
|
|
@@ -273,16 +292,22 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
273
292
|
configureServer(server) {
|
|
274
293
|
let generation = 0;
|
|
275
294
|
let debounceTimer = null;
|
|
295
|
+
let writeQueue = Promise.resolve();
|
|
276
296
|
const rescan = async () => {
|
|
277
297
|
const myGeneration = ++generation;
|
|
278
298
|
const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
|
|
279
299
|
cachedNames = namesPromise;
|
|
280
300
|
const names = await namesPromise;
|
|
281
301
|
if (myGeneration !== generation) return;
|
|
282
|
-
warnOnCollisions(names, options);
|
|
302
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
283
303
|
const dtsPath = getDtsPath(options);
|
|
284
304
|
if (dtsPath) {
|
|
285
|
-
|
|
305
|
+
const content = generateDeclaration(names, options.prefix, options.naming);
|
|
306
|
+
writeQueue = writeQueue.then(async () => {
|
|
307
|
+
if (myGeneration !== generation) return;
|
|
308
|
+
await (0, import_promises2.writeFile)(dtsPath, content, "utf8");
|
|
309
|
+
}).catch(console.error);
|
|
310
|
+
await writeQueue;
|
|
286
311
|
}
|
|
287
312
|
if (myGeneration !== generation) return;
|
|
288
313
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
@@ -307,7 +332,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
307
332
|
async buildStart() {
|
|
308
333
|
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
309
334
|
const names = await cachedNames;
|
|
310
|
-
warnOnCollisions(names, options);
|
|
335
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
311
336
|
const dtsPath = getDtsPath(options);
|
|
312
337
|
if (!dtsPath) return;
|
|
313
338
|
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,12 @@ var import_promises = require("fs/promises");
|
|
|
46
46
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
47
47
|
|
|
48
48
|
// src/parser.ts
|
|
49
|
+
function stepQuote(text, i, quote) {
|
|
50
|
+
const char = text[i];
|
|
51
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
52
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
53
|
+
return { consumed: 1, closed: false };
|
|
54
|
+
}
|
|
49
55
|
function stripComments(text) {
|
|
50
56
|
let result = "";
|
|
51
57
|
let quote = null;
|
|
@@ -53,12 +59,10 @@ function stripComments(text) {
|
|
|
53
59
|
for (let i = 0; i < text.length; i++) {
|
|
54
60
|
const char = text[i];
|
|
55
61
|
if (quote) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
quote = null;
|
|
61
|
-
}
|
|
62
|
+
const step = stepQuote(text, i, quote);
|
|
63
|
+
result += text.slice(i, i + step.consumed);
|
|
64
|
+
if (step.closed) quote = null;
|
|
65
|
+
i += step.consumed - 1;
|
|
62
66
|
continue;
|
|
63
67
|
}
|
|
64
68
|
if (char === '"' || char === "'") {
|
|
@@ -120,15 +124,14 @@ function maskQuotedContent(text) {
|
|
|
120
124
|
for (let i = 0; i < text.length; i++) {
|
|
121
125
|
const char = text[i];
|
|
122
126
|
if (quote) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
i++;
|
|
126
|
-
} else if (char === quote) {
|
|
127
|
-
quote = null;
|
|
127
|
+
const step = stepQuote(text, i, quote);
|
|
128
|
+
if (step.closed) {
|
|
128
129
|
result += char;
|
|
130
|
+
quote = null;
|
|
129
131
|
} else {
|
|
130
|
-
result += " ";
|
|
132
|
+
result += " ".repeat(step.consumed);
|
|
131
133
|
}
|
|
134
|
+
i += step.consumed - 1;
|
|
132
135
|
continue;
|
|
133
136
|
}
|
|
134
137
|
if (char === '"' || char === "'") {
|
|
@@ -196,11 +199,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
196
199
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
197
200
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
198
201
|
}
|
|
202
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
203
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
204
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
205
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
206
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
207
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
208
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
209
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
210
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
211
|
+
function escapeSingleQuoted(value) {
|
|
212
|
+
let result = "";
|
|
213
|
+
for (const char of value) {
|
|
214
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
215
|
+
}
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
199
218
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
200
219
|
if (!prefix) return key;
|
|
201
220
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
202
221
|
if (naming === "kebab") {
|
|
203
|
-
normalizedPrefix = normalizedPrefix
|
|
222
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
204
223
|
return `${normalizedPrefix}-${key}`;
|
|
205
224
|
}
|
|
206
225
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -225,6 +244,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
225
244
|
}
|
|
226
245
|
return byKey;
|
|
227
246
|
}
|
|
247
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
248
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
249
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
228
252
|
function buildEntries(varNames, prefix, naming) {
|
|
229
253
|
const byKey = /* @__PURE__ */ new Map();
|
|
230
254
|
for (const name of varNames) {
|
|
@@ -272,9 +296,7 @@ async function generate(options) {
|
|
|
272
296
|
if (names.length === 0) {
|
|
273
297
|
console.warn("css-typed-vars: no CSS custom properties found.");
|
|
274
298
|
}
|
|
275
|
-
|
|
276
|
-
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
277
|
-
}
|
|
299
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
278
300
|
const outPath = (0, import_node_path.resolve)(options.output);
|
|
279
301
|
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
|
|
280
302
|
const jsExtMatch = /\.(m|c)?js$/i.exec(options.output);
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
generate
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ARQR224L.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-NS2BULH3.js";
|
|
11
11
|
export {
|
|
12
12
|
generate,
|
|
13
13
|
generateCode,
|
package/dist/rollup.cjs
CHANGED
|
@@ -44,6 +44,12 @@ var import_promises = require("fs/promises");
|
|
|
44
44
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
|
+
function stepQuote(text, i, quote) {
|
|
48
|
+
const char = text[i];
|
|
49
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
50
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
51
|
+
return { consumed: 1, closed: false };
|
|
52
|
+
}
|
|
47
53
|
function stripComments(text) {
|
|
48
54
|
let result = "";
|
|
49
55
|
let quote = null;
|
|
@@ -51,12 +57,10 @@ function stripComments(text) {
|
|
|
51
57
|
for (let i = 0; i < text.length; i++) {
|
|
52
58
|
const char = text[i];
|
|
53
59
|
if (quote) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
quote = null;
|
|
59
|
-
}
|
|
60
|
+
const step = stepQuote(text, i, quote);
|
|
61
|
+
result += text.slice(i, i + step.consumed);
|
|
62
|
+
if (step.closed) quote = null;
|
|
63
|
+
i += step.consumed - 1;
|
|
60
64
|
continue;
|
|
61
65
|
}
|
|
62
66
|
if (char === '"' || char === "'") {
|
|
@@ -118,15 +122,14 @@ function maskQuotedContent(text) {
|
|
|
118
122
|
for (let i = 0; i < text.length; i++) {
|
|
119
123
|
const char = text[i];
|
|
120
124
|
if (quote) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
i++;
|
|
124
|
-
} else if (char === quote) {
|
|
125
|
-
quote = null;
|
|
125
|
+
const step = stepQuote(text, i, quote);
|
|
126
|
+
if (step.closed) {
|
|
126
127
|
result += char;
|
|
128
|
+
quote = null;
|
|
127
129
|
} else {
|
|
128
|
-
result += " ";
|
|
130
|
+
result += " ".repeat(step.consumed);
|
|
129
131
|
}
|
|
132
|
+
i += step.consumed - 1;
|
|
130
133
|
continue;
|
|
131
134
|
}
|
|
132
135
|
if (char === '"' || char === "'") {
|
|
@@ -194,11 +197,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
194
197
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
195
198
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
196
199
|
}
|
|
200
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
201
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
202
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
203
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
204
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
205
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
206
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
207
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
208
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
209
|
+
function escapeSingleQuoted(value) {
|
|
210
|
+
let result = "";
|
|
211
|
+
for (const char of value) {
|
|
212
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
213
|
+
}
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
197
216
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
198
217
|
if (!prefix) return key;
|
|
199
218
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
200
219
|
if (naming === "kebab") {
|
|
201
|
-
normalizedPrefix = normalizedPrefix
|
|
220
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
202
221
|
return `${normalizedPrefix}-${key}`;
|
|
203
222
|
}
|
|
204
223
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -223,6 +242,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
223
242
|
}
|
|
224
243
|
return byKey;
|
|
225
244
|
}
|
|
245
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
246
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
247
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
226
250
|
function buildEntries(varNames, prefix, naming) {
|
|
227
251
|
const byKey = /* @__PURE__ */ new Map();
|
|
228
252
|
for (const name of varNames) {
|
|
@@ -255,11 +279,6 @@ function generateDeclaration(varNames, prefix, naming) {
|
|
|
255
279
|
// src/unplugin.ts
|
|
256
280
|
var VIRTUAL_ID = "css-typed-vars/vars";
|
|
257
281
|
var RESOLVED_ID = "\0css-typed-vars/vars";
|
|
258
|
-
function warnOnCollisions(names, options) {
|
|
259
|
-
for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
|
|
260
|
-
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
282
|
function getDtsPath(options) {
|
|
264
283
|
if (options.dts === false) return null;
|
|
265
284
|
return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
|
|
@@ -273,16 +292,22 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
273
292
|
configureServer(server) {
|
|
274
293
|
let generation = 0;
|
|
275
294
|
let debounceTimer = null;
|
|
295
|
+
let writeQueue = Promise.resolve();
|
|
276
296
|
const rescan = async () => {
|
|
277
297
|
const myGeneration = ++generation;
|
|
278
298
|
const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
|
|
279
299
|
cachedNames = namesPromise;
|
|
280
300
|
const names = await namesPromise;
|
|
281
301
|
if (myGeneration !== generation) return;
|
|
282
|
-
warnOnCollisions(names, options);
|
|
302
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
283
303
|
const dtsPath = getDtsPath(options);
|
|
284
304
|
if (dtsPath) {
|
|
285
|
-
|
|
305
|
+
const content = generateDeclaration(names, options.prefix, options.naming);
|
|
306
|
+
writeQueue = writeQueue.then(async () => {
|
|
307
|
+
if (myGeneration !== generation) return;
|
|
308
|
+
await (0, import_promises2.writeFile)(dtsPath, content, "utf8");
|
|
309
|
+
}).catch(console.error);
|
|
310
|
+
await writeQueue;
|
|
286
311
|
}
|
|
287
312
|
if (myGeneration !== generation) return;
|
|
288
313
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
@@ -307,7 +332,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
307
332
|
async buildStart() {
|
|
308
333
|
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
309
334
|
const names = await cachedNames;
|
|
310
|
-
warnOnCollisions(names, options);
|
|
335
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
311
336
|
const dtsPath = getDtsPath(options);
|
|
312
337
|
if (!dtsPath) return;
|
|
313
338
|
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
package/dist/rollup.js
CHANGED
package/dist/unplugin.cjs
CHANGED
|
@@ -42,6 +42,12 @@ var import_promises = require("fs/promises");
|
|
|
42
42
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
43
43
|
|
|
44
44
|
// src/parser.ts
|
|
45
|
+
function stepQuote(text, i, quote) {
|
|
46
|
+
const char = text[i];
|
|
47
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
48
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
49
|
+
return { consumed: 1, closed: false };
|
|
50
|
+
}
|
|
45
51
|
function stripComments(text) {
|
|
46
52
|
let result = "";
|
|
47
53
|
let quote = null;
|
|
@@ -49,12 +55,10 @@ function stripComments(text) {
|
|
|
49
55
|
for (let i = 0; i < text.length; i++) {
|
|
50
56
|
const char = text[i];
|
|
51
57
|
if (quote) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
quote = null;
|
|
57
|
-
}
|
|
58
|
+
const step = stepQuote(text, i, quote);
|
|
59
|
+
result += text.slice(i, i + step.consumed);
|
|
60
|
+
if (step.closed) quote = null;
|
|
61
|
+
i += step.consumed - 1;
|
|
58
62
|
continue;
|
|
59
63
|
}
|
|
60
64
|
if (char === '"' || char === "'") {
|
|
@@ -116,15 +120,14 @@ function maskQuotedContent(text) {
|
|
|
116
120
|
for (let i = 0; i < text.length; i++) {
|
|
117
121
|
const char = text[i];
|
|
118
122
|
if (quote) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
i++;
|
|
122
|
-
} else if (char === quote) {
|
|
123
|
-
quote = null;
|
|
123
|
+
const step = stepQuote(text, i, quote);
|
|
124
|
+
if (step.closed) {
|
|
124
125
|
result += char;
|
|
126
|
+
quote = null;
|
|
125
127
|
} else {
|
|
126
|
-
result += " ";
|
|
128
|
+
result += " ".repeat(step.consumed);
|
|
127
129
|
}
|
|
130
|
+
i += step.consumed - 1;
|
|
128
131
|
continue;
|
|
129
132
|
}
|
|
130
133
|
if (char === '"' || char === "'") {
|
|
@@ -192,11 +195,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
192
195
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
193
196
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
194
197
|
}
|
|
198
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
199
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
200
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
201
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
202
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
203
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
204
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
205
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
206
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
207
|
+
function escapeSingleQuoted(value) {
|
|
208
|
+
let result = "";
|
|
209
|
+
for (const char of value) {
|
|
210
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
195
214
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
196
215
|
if (!prefix) return key;
|
|
197
216
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
198
217
|
if (naming === "kebab") {
|
|
199
|
-
normalizedPrefix = normalizedPrefix
|
|
218
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
200
219
|
return `${normalizedPrefix}-${key}`;
|
|
201
220
|
}
|
|
202
221
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -221,6 +240,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
221
240
|
}
|
|
222
241
|
return byKey;
|
|
223
242
|
}
|
|
243
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
244
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
245
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
224
248
|
function buildEntries(varNames, prefix, naming) {
|
|
225
249
|
const byKey = /* @__PURE__ */ new Map();
|
|
226
250
|
for (const name of varNames) {
|
|
@@ -253,11 +277,6 @@ function generateDeclaration(varNames, prefix, naming) {
|
|
|
253
277
|
// src/unplugin.ts
|
|
254
278
|
var VIRTUAL_ID = "css-typed-vars/vars";
|
|
255
279
|
var RESOLVED_ID = "\0css-typed-vars/vars";
|
|
256
|
-
function warnOnCollisions(names, options) {
|
|
257
|
-
for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
|
|
258
|
-
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
280
|
function getDtsPath(options) {
|
|
262
281
|
if (options.dts === false) return null;
|
|
263
282
|
return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
|
|
@@ -271,16 +290,22 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
271
290
|
configureServer(server) {
|
|
272
291
|
let generation = 0;
|
|
273
292
|
let debounceTimer = null;
|
|
293
|
+
let writeQueue = Promise.resolve();
|
|
274
294
|
const rescan = async () => {
|
|
275
295
|
const myGeneration = ++generation;
|
|
276
296
|
const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
|
|
277
297
|
cachedNames = namesPromise;
|
|
278
298
|
const names = await namesPromise;
|
|
279
299
|
if (myGeneration !== generation) return;
|
|
280
|
-
warnOnCollisions(names, options);
|
|
300
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
281
301
|
const dtsPath = getDtsPath(options);
|
|
282
302
|
if (dtsPath) {
|
|
283
|
-
|
|
303
|
+
const content = generateDeclaration(names, options.prefix, options.naming);
|
|
304
|
+
writeQueue = writeQueue.then(async () => {
|
|
305
|
+
if (myGeneration !== generation) return;
|
|
306
|
+
await (0, import_promises2.writeFile)(dtsPath, content, "utf8");
|
|
307
|
+
}).catch(console.error);
|
|
308
|
+
await writeQueue;
|
|
284
309
|
}
|
|
285
310
|
if (myGeneration !== generation) return;
|
|
286
311
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
@@ -305,7 +330,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
305
330
|
async buildStart() {
|
|
306
331
|
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
307
332
|
const names = await cachedNames;
|
|
308
|
-
warnOnCollisions(names, options);
|
|
333
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
309
334
|
const dtsPath = getDtsPath(options);
|
|
310
335
|
if (!dtsPath) return;
|
|
311
336
|
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
package/dist/unplugin.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -44,6 +44,12 @@ var import_promises = require("fs/promises");
|
|
|
44
44
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
|
+
function stepQuote(text, i, quote) {
|
|
48
|
+
const char = text[i];
|
|
49
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
50
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
51
|
+
return { consumed: 1, closed: false };
|
|
52
|
+
}
|
|
47
53
|
function stripComments(text) {
|
|
48
54
|
let result = "";
|
|
49
55
|
let quote = null;
|
|
@@ -51,12 +57,10 @@ function stripComments(text) {
|
|
|
51
57
|
for (let i = 0; i < text.length; i++) {
|
|
52
58
|
const char = text[i];
|
|
53
59
|
if (quote) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
quote = null;
|
|
59
|
-
}
|
|
60
|
+
const step = stepQuote(text, i, quote);
|
|
61
|
+
result += text.slice(i, i + step.consumed);
|
|
62
|
+
if (step.closed) quote = null;
|
|
63
|
+
i += step.consumed - 1;
|
|
60
64
|
continue;
|
|
61
65
|
}
|
|
62
66
|
if (char === '"' || char === "'") {
|
|
@@ -118,15 +122,14 @@ function maskQuotedContent(text) {
|
|
|
118
122
|
for (let i = 0; i < text.length; i++) {
|
|
119
123
|
const char = text[i];
|
|
120
124
|
if (quote) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
i++;
|
|
124
|
-
} else if (char === quote) {
|
|
125
|
-
quote = null;
|
|
125
|
+
const step = stepQuote(text, i, quote);
|
|
126
|
+
if (step.closed) {
|
|
126
127
|
result += char;
|
|
128
|
+
quote = null;
|
|
127
129
|
} else {
|
|
128
|
-
result += " ";
|
|
130
|
+
result += " ".repeat(step.consumed);
|
|
129
131
|
}
|
|
132
|
+
i += step.consumed - 1;
|
|
130
133
|
continue;
|
|
131
134
|
}
|
|
132
135
|
if (char === '"' || char === "'") {
|
|
@@ -194,11 +197,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
194
197
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
195
198
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
196
199
|
}
|
|
200
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
201
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
202
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
203
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
204
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
205
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
206
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
207
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
208
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
209
|
+
function escapeSingleQuoted(value) {
|
|
210
|
+
let result = "";
|
|
211
|
+
for (const char of value) {
|
|
212
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
213
|
+
}
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
197
216
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
198
217
|
if (!prefix) return key;
|
|
199
218
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
200
219
|
if (naming === "kebab") {
|
|
201
|
-
normalizedPrefix = normalizedPrefix
|
|
220
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
202
221
|
return `${normalizedPrefix}-${key}`;
|
|
203
222
|
}
|
|
204
223
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -223,6 +242,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
223
242
|
}
|
|
224
243
|
return byKey;
|
|
225
244
|
}
|
|
245
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
246
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
247
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
226
250
|
function buildEntries(varNames, prefix, naming) {
|
|
227
251
|
const byKey = /* @__PURE__ */ new Map();
|
|
228
252
|
for (const name of varNames) {
|
|
@@ -255,11 +279,6 @@ function generateDeclaration(varNames, prefix, naming) {
|
|
|
255
279
|
// src/unplugin.ts
|
|
256
280
|
var VIRTUAL_ID = "css-typed-vars/vars";
|
|
257
281
|
var RESOLVED_ID = "\0css-typed-vars/vars";
|
|
258
|
-
function warnOnCollisions(names, options) {
|
|
259
|
-
for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
|
|
260
|
-
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
282
|
function getDtsPath(options) {
|
|
264
283
|
if (options.dts === false) return null;
|
|
265
284
|
return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
|
|
@@ -273,16 +292,22 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
273
292
|
configureServer(server) {
|
|
274
293
|
let generation = 0;
|
|
275
294
|
let debounceTimer = null;
|
|
295
|
+
let writeQueue = Promise.resolve();
|
|
276
296
|
const rescan = async () => {
|
|
277
297
|
const myGeneration = ++generation;
|
|
278
298
|
const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
|
|
279
299
|
cachedNames = namesPromise;
|
|
280
300
|
const names = await namesPromise;
|
|
281
301
|
if (myGeneration !== generation) return;
|
|
282
|
-
warnOnCollisions(names, options);
|
|
302
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
283
303
|
const dtsPath = getDtsPath(options);
|
|
284
304
|
if (dtsPath) {
|
|
285
|
-
|
|
305
|
+
const content = generateDeclaration(names, options.prefix, options.naming);
|
|
306
|
+
writeQueue = writeQueue.then(async () => {
|
|
307
|
+
if (myGeneration !== generation) return;
|
|
308
|
+
await (0, import_promises2.writeFile)(dtsPath, content, "utf8");
|
|
309
|
+
}).catch(console.error);
|
|
310
|
+
await writeQueue;
|
|
286
311
|
}
|
|
287
312
|
if (myGeneration !== generation) return;
|
|
288
313
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
@@ -307,7 +332,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
307
332
|
async buildStart() {
|
|
308
333
|
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
309
334
|
const names = await cachedNames;
|
|
310
|
-
warnOnCollisions(names, options);
|
|
335
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
311
336
|
const dtsPath = getDtsPath(options);
|
|
312
337
|
if (!dtsPath) return;
|
|
313
338
|
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -44,6 +44,12 @@ var import_promises = require("fs/promises");
|
|
|
44
44
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
|
+
function stepQuote(text, i, quote) {
|
|
48
|
+
const char = text[i];
|
|
49
|
+
if (char === "\\" && i + 1 < text.length) return { consumed: 2, closed: false };
|
|
50
|
+
if (char === quote) return { consumed: 1, closed: true };
|
|
51
|
+
return { consumed: 1, closed: false };
|
|
52
|
+
}
|
|
47
53
|
function stripComments(text) {
|
|
48
54
|
let result = "";
|
|
49
55
|
let quote = null;
|
|
@@ -51,12 +57,10 @@ function stripComments(text) {
|
|
|
51
57
|
for (let i = 0; i < text.length; i++) {
|
|
52
58
|
const char = text[i];
|
|
53
59
|
if (quote) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
quote = null;
|
|
59
|
-
}
|
|
60
|
+
const step = stepQuote(text, i, quote);
|
|
61
|
+
result += text.slice(i, i + step.consumed);
|
|
62
|
+
if (step.closed) quote = null;
|
|
63
|
+
i += step.consumed - 1;
|
|
60
64
|
continue;
|
|
61
65
|
}
|
|
62
66
|
if (char === '"' || char === "'") {
|
|
@@ -118,15 +122,14 @@ function maskQuotedContent(text) {
|
|
|
118
122
|
for (let i = 0; i < text.length; i++) {
|
|
119
123
|
const char = text[i];
|
|
120
124
|
if (quote) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
i++;
|
|
124
|
-
} else if (char === quote) {
|
|
125
|
-
quote = null;
|
|
125
|
+
const step = stepQuote(text, i, quote);
|
|
126
|
+
if (step.closed) {
|
|
126
127
|
result += char;
|
|
128
|
+
quote = null;
|
|
127
129
|
} else {
|
|
128
|
-
result += " ";
|
|
130
|
+
result += " ".repeat(step.consumed);
|
|
129
131
|
}
|
|
132
|
+
i += step.consumed - 1;
|
|
130
133
|
continue;
|
|
131
134
|
}
|
|
132
135
|
if (char === '"' || char === "'") {
|
|
@@ -194,11 +197,27 @@ function toKey(cssVarName, naming = "camelCase") {
|
|
|
194
197
|
const key = convertCase(cssVarName.replace(/^--/, ""), naming);
|
|
195
198
|
return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
|
|
196
199
|
}
|
|
200
|
+
var LINE_SEPARATOR_CHAR = String.fromCharCode(8232);
|
|
201
|
+
var PARAGRAPH_SEPARATOR_CHAR = String.fromCharCode(8233);
|
|
202
|
+
var SINGLE_QUOTE_ESCAPES = {};
|
|
203
|
+
SINGLE_QUOTE_ESCAPES["\\"] = "\\\\";
|
|
204
|
+
SINGLE_QUOTE_ESCAPES["'"] = "\\'";
|
|
205
|
+
SINGLE_QUOTE_ESCAPES["\n"] = "\\n";
|
|
206
|
+
SINGLE_QUOTE_ESCAPES["\r"] = "\\r";
|
|
207
|
+
SINGLE_QUOTE_ESCAPES[LINE_SEPARATOR_CHAR] = "\\u2028";
|
|
208
|
+
SINGLE_QUOTE_ESCAPES[PARAGRAPH_SEPARATOR_CHAR] = "\\u2029";
|
|
209
|
+
function escapeSingleQuoted(value) {
|
|
210
|
+
let result = "";
|
|
211
|
+
for (const char of value) {
|
|
212
|
+
result += SINGLE_QUOTE_ESCAPES[char] ?? char;
|
|
213
|
+
}
|
|
214
|
+
return result;
|
|
215
|
+
}
|
|
197
216
|
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
198
217
|
if (!prefix) return key;
|
|
199
218
|
let normalizedPrefix = convertCase(prefix, naming);
|
|
200
219
|
if (naming === "kebab") {
|
|
201
|
-
normalizedPrefix = normalizedPrefix
|
|
220
|
+
normalizedPrefix = escapeSingleQuoted(normalizedPrefix);
|
|
202
221
|
return `${normalizedPrefix}-${key}`;
|
|
203
222
|
}
|
|
204
223
|
normalizedPrefix = normalizedPrefix.replace(/[^A-Za-z0-9_$]/g, "");
|
|
@@ -223,6 +242,11 @@ function findKeyCollisions(varNames, prefix, naming) {
|
|
|
223
242
|
}
|
|
224
243
|
return byKey;
|
|
225
244
|
}
|
|
245
|
+
function warnOnCollisions(varNames, prefix, naming) {
|
|
246
|
+
for (const [key, vars] of findKeyCollisions(varNames, prefix, naming)) {
|
|
247
|
+
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
226
250
|
function buildEntries(varNames, prefix, naming) {
|
|
227
251
|
const byKey = /* @__PURE__ */ new Map();
|
|
228
252
|
for (const name of varNames) {
|
|
@@ -255,11 +279,6 @@ function generateDeclaration(varNames, prefix, naming) {
|
|
|
255
279
|
// src/unplugin.ts
|
|
256
280
|
var VIRTUAL_ID = "css-typed-vars/vars";
|
|
257
281
|
var RESOLVED_ID = "\0css-typed-vars/vars";
|
|
258
|
-
function warnOnCollisions(names, options) {
|
|
259
|
-
for (const [key, vars] of findKeyCollisions(names, options.prefix, options.naming)) {
|
|
260
|
-
console.warn(`css-typed-vars: multiple CSS variables map to the same key "${key}" (${vars.join(", ")}) \u2014 only the last one will be kept.`);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
282
|
function getDtsPath(options) {
|
|
264
283
|
if (options.dts === false) return null;
|
|
265
284
|
return options.dts ? (0, import_node_path.resolve)(process.cwd(), options.dts) : (0, import_node_path.join)(__dirname, "generated.d.ts");
|
|
@@ -273,16 +292,22 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
273
292
|
configureServer(server) {
|
|
274
293
|
let generation = 0;
|
|
275
294
|
let debounceTimer = null;
|
|
295
|
+
let writeQueue = Promise.resolve();
|
|
276
296
|
const rescan = async () => {
|
|
277
297
|
const myGeneration = ++generation;
|
|
278
298
|
const namesPromise = scanVarNames(options.input, options.exclude, options.selectors);
|
|
279
299
|
cachedNames = namesPromise;
|
|
280
300
|
const names = await namesPromise;
|
|
281
301
|
if (myGeneration !== generation) return;
|
|
282
|
-
warnOnCollisions(names, options);
|
|
302
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
283
303
|
const dtsPath = getDtsPath(options);
|
|
284
304
|
if (dtsPath) {
|
|
285
|
-
|
|
305
|
+
const content = generateDeclaration(names, options.prefix, options.naming);
|
|
306
|
+
writeQueue = writeQueue.then(async () => {
|
|
307
|
+
if (myGeneration !== generation) return;
|
|
308
|
+
await (0, import_promises2.writeFile)(dtsPath, content, "utf8");
|
|
309
|
+
}).catch(console.error);
|
|
310
|
+
await writeQueue;
|
|
286
311
|
}
|
|
287
312
|
if (myGeneration !== generation) return;
|
|
288
313
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
@@ -307,7 +332,7 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => {
|
|
|
307
332
|
async buildStart() {
|
|
308
333
|
cachedNames = scanVarNames(options.input, options.exclude, options.selectors);
|
|
309
334
|
const names = await cachedNames;
|
|
310
|
-
warnOnCollisions(names, options);
|
|
335
|
+
warnOnCollisions(names, options.prefix, options.naming);
|
|
311
336
|
const dtsPath = getDtsPath(options);
|
|
312
337
|
if (!dtsPath) return;
|
|
313
338
|
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
package/dist/webpack.js
CHANGED