css-typed-vars 0.4.8 → 0.4.10
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-QJWQDFW4.js → chunk-3YUKUAJQ.js} +1 -1
- package/dist/{chunk-CDJTXVSE.js → chunk-K5FAEWQE.js} +5 -1
- package/dist/{chunk-MJEASOAN.js → chunk-YVFKCMBF.js} +15 -1
- package/dist/cli.cjs +21 -2
- package/dist/cli.js +6 -3
- 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-YVFKCMBF.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")) {
|
|
@@ -7,7 +7,7 @@ var __dirname = /* @__PURE__ */ getDirname();
|
|
|
7
7
|
|
|
8
8
|
// src/parser.ts
|
|
9
9
|
function parseVarNames(css, selectors) {
|
|
10
|
-
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(
|
|
10
|
+
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
11
11
|
const names = /* @__PURE__ */ new Set();
|
|
12
12
|
const allSelectors = [":root", ...selectors ?? []];
|
|
13
13
|
for (const sel of allSelectors) {
|
|
@@ -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
|
@@ -43,7 +43,7 @@ var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
|
43
43
|
|
|
44
44
|
// src/parser.ts
|
|
45
45
|
function parseVarNames(css, selectors) {
|
|
46
|
-
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(
|
|
46
|
+
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
47
47
|
const names = /* @__PURE__ */ new Set();
|
|
48
48
|
const allSelectors = [":root", ...selectors ?? []];
|
|
49
49
|
for (const sel of allSelectors) {
|
|
@@ -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;
|
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-K5FAEWQE.js";
|
|
5
|
+
import "./chunk-YVFKCMBF.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;
|
package/dist/esbuild.cjs
CHANGED
|
@@ -45,7 +45,7 @@ var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
47
|
function parseVarNames(css, selectors) {
|
|
48
|
-
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(
|
|
48
|
+
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
49
49
|
const names = /* @__PURE__ */ new Set();
|
|
50
50
|
const allSelectors = [":root", ...selectors ?? []];
|
|
51
51
|
for (const sel of allSelectors) {
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -47,7 +47,7 @@ var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
|
47
47
|
|
|
48
48
|
// src/parser.ts
|
|
49
49
|
function parseVarNames(css, selectors) {
|
|
50
|
-
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(
|
|
50
|
+
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
51
51
|
const names = /* @__PURE__ */ new Set();
|
|
52
52
|
const allSelectors = [":root", ...selectors ?? []];
|
|
53
53
|
for (const sel of allSelectors) {
|
|
@@ -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-K5FAEWQE.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-YVFKCMBF.js";
|
|
11
11
|
export {
|
|
12
12
|
generate,
|
|
13
13
|
generateCode,
|
package/dist/rollup.cjs
CHANGED
|
@@ -45,7 +45,7 @@ var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
47
|
function parseVarNames(css, selectors) {
|
|
48
|
-
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(
|
|
48
|
+
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
49
49
|
const names = /* @__PURE__ */ new Set();
|
|
50
50
|
const allSelectors = [":root", ...selectors ?? []];
|
|
51
51
|
for (const sel of allSelectors) {
|
package/dist/rollup.js
CHANGED
package/dist/unplugin.cjs
CHANGED
|
@@ -43,7 +43,7 @@ var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
|
43
43
|
|
|
44
44
|
// src/parser.ts
|
|
45
45
|
function parseVarNames(css, selectors) {
|
|
46
|
-
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(
|
|
46
|
+
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
47
47
|
const names = /* @__PURE__ */ new Set();
|
|
48
48
|
const allSelectors = [":root", ...selectors ?? []];
|
|
49
49
|
for (const sel of allSelectors) {
|
package/dist/unplugin.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -45,7 +45,7 @@ var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
47
|
function parseVarNames(css, selectors) {
|
|
48
|
-
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(
|
|
48
|
+
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
49
49
|
const names = /* @__PURE__ */ new Set();
|
|
50
50
|
const allSelectors = [":root", ...selectors ?? []];
|
|
51
51
|
for (const sel of allSelectors) {
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -45,7 +45,7 @@ var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
|
45
45
|
|
|
46
46
|
// src/parser.ts
|
|
47
47
|
function parseVarNames(css, selectors) {
|
|
48
|
-
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(
|
|
48
|
+
const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
|
|
49
49
|
const names = /* @__PURE__ */ new Set();
|
|
50
50
|
const allSelectors = [":root", ...selectors ?? []];
|
|
51
51
|
for (const sel of allSelectors) {
|
package/dist/webpack.js
CHANGED