css-typed-vars 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -2
- package/dist/chunk-3XKCOLZL.js +26 -0
- package/dist/{chunk-SUEAXDIO.js → chunk-4VL6W5GO.js} +34 -10
- package/dist/{chunk-3LGOJDGV.js → chunk-B57NHMQD.js} +7 -7
- package/dist/cli.cjs +79 -18
- package/dist/cli.js +13 -13
- package/dist/esbuild.cjs +35 -14
- package/dist/esbuild.d.cts +1 -0
- package/dist/esbuild.d.ts +1 -0
- package/dist/esbuild.js +2 -2
- package/dist/generator-Ba8XeISD.d.cts +6 -0
- package/dist/generator-Ba8XeISD.d.ts +6 -0
- package/dist/index.cjs +63 -10
- package/dist/index.d.cts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.js +8 -11
- package/dist/rollup.cjs +35 -14
- package/dist/rollup.d.cts +1 -0
- package/dist/rollup.d.ts +1 -0
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +35 -14
- package/dist/unplugin.d.cts +4 -0
- package/dist/unplugin.d.ts +4 -0
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +35 -14
- package/dist/vite.d.cts +1 -0
- package/dist/vite.d.ts +1 -0
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +35 -14
- package/dist/webpack.d.cts +1 -0
- package/dist/webpack.d.ts +1 -0
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -32,6 +32,8 @@ var src_exports = {};
|
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
generate: () => generate,
|
|
34
34
|
generateCode: () => generateCode,
|
|
35
|
+
generateDeclaration: () => generateDeclaration,
|
|
36
|
+
generateJs: () => generateJs,
|
|
35
37
|
parseVarNames: () => parseVarNames,
|
|
36
38
|
scanVarNames: () => scanVarNames
|
|
37
39
|
});
|
|
@@ -57,11 +59,12 @@ function parseVarNames(css) {
|
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
// src/scanner.ts
|
|
60
|
-
async function scanVarNames(patterns) {
|
|
62
|
+
async function scanVarNames(patterns, exclude) {
|
|
61
63
|
const normalized = (Array.isArray(patterns) ? patterns : [patterns]).map(
|
|
62
64
|
(p) => p.replace(/\\/g, "/")
|
|
63
65
|
);
|
|
64
|
-
const
|
|
66
|
+
const normalizedExclude = exclude ? (Array.isArray(exclude) ? exclude : [exclude]).map((p) => p.replace(/\\/g, "/")) : [];
|
|
67
|
+
const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
|
|
65
68
|
const all = /* @__PURE__ */ new Set();
|
|
66
69
|
await Promise.all(
|
|
67
70
|
files.map(async (file) => {
|
|
@@ -75,11 +78,27 @@ async function scanVarNames(patterns) {
|
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
// src/generator.ts
|
|
78
|
-
function
|
|
79
|
-
|
|
81
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
82
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
83
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
84
|
+
if (naming === "kebab") return stripped;
|
|
85
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
80
86
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
87
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
88
|
+
if (!prefix) return key;
|
|
89
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
90
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
91
|
+
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
92
|
+
}
|
|
93
|
+
function formatKey(key, naming = "camelCase") {
|
|
94
|
+
if (naming === "kebab") return `'${key}'`;
|
|
95
|
+
return key;
|
|
96
|
+
}
|
|
97
|
+
function generateCode(varNames, prefix, naming) {
|
|
98
|
+
const entries = varNames.map((name) => {
|
|
99
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
100
|
+
return ` ${key}: 'var(${name})',`;
|
|
101
|
+
});
|
|
83
102
|
return [
|
|
84
103
|
"// generated \u2014 do not edit",
|
|
85
104
|
"export const cssVars = {",
|
|
@@ -90,18 +109,52 @@ function generateCode(varNames) {
|
|
|
90
109
|
""
|
|
91
110
|
].join("\n");
|
|
92
111
|
}
|
|
112
|
+
function generateJs(varNames, prefix, naming) {
|
|
113
|
+
const entries = varNames.map((name) => {
|
|
114
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
115
|
+
return ` ${key}: 'var(${name})',`;
|
|
116
|
+
});
|
|
117
|
+
return [
|
|
118
|
+
"// generated \u2014 do not edit",
|
|
119
|
+
"export const cssVars = {",
|
|
120
|
+
...entries,
|
|
121
|
+
"};",
|
|
122
|
+
""
|
|
123
|
+
].join("\n");
|
|
124
|
+
}
|
|
125
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
126
|
+
const entries = varNames.map((name) => {
|
|
127
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
128
|
+
return ` ${key}: 'var(${name})';`;
|
|
129
|
+
});
|
|
130
|
+
return [
|
|
131
|
+
"export declare const cssVars: {",
|
|
132
|
+
...entries,
|
|
133
|
+
"};",
|
|
134
|
+
"export type CssVarName = keyof typeof cssVars;",
|
|
135
|
+
""
|
|
136
|
+
].join("\n");
|
|
137
|
+
}
|
|
93
138
|
|
|
94
139
|
// src/index.ts
|
|
95
140
|
async function generate(options) {
|
|
96
|
-
const names = await scanVarNames(options.input);
|
|
97
|
-
const
|
|
98
|
-
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(
|
|
99
|
-
|
|
141
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
142
|
+
const outPath = (0, import_node_path.resolve)(options.output);
|
|
143
|
+
await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
|
|
144
|
+
if (options.output.endsWith(".js")) {
|
|
145
|
+
await (0, import_promises2.writeFile)(outPath, generateJs(names, options.prefix, options.naming), "utf8");
|
|
146
|
+
const dtsPath = outPath.replace(/\.js$/, ".d.ts");
|
|
147
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
148
|
+
} else {
|
|
149
|
+
await (0, import_promises2.writeFile)(outPath, generateCode(names, options.prefix, options.naming), "utf8");
|
|
150
|
+
}
|
|
100
151
|
}
|
|
101
152
|
// Annotate the CommonJS export names for ESM import in node:
|
|
102
153
|
0 && (module.exports = {
|
|
103
154
|
generate,
|
|
104
155
|
generateCode,
|
|
156
|
+
generateDeclaration,
|
|
157
|
+
generateJs,
|
|
105
158
|
parseVarNames,
|
|
106
159
|
scanVarNames
|
|
107
160
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { N as NamingConvention } from './generator-Ba8XeISD.cjs';
|
|
2
|
+
export { g as generateCode, a as generateDeclaration, b as generateJs } from './generator-Ba8XeISD.cjs';
|
|
2
3
|
|
|
3
|
-
declare function
|
|
4
|
+
declare function parseVarNames(css: string): string[];
|
|
4
5
|
|
|
5
|
-
declare function scanVarNames(patterns: string | string[]): Promise<string[]>;
|
|
6
|
+
declare function scanVarNames(patterns: string | string[], exclude?: string | string[]): Promise<string[]>;
|
|
6
7
|
|
|
7
8
|
interface GenerateOptions {
|
|
8
9
|
input: string | string[];
|
|
9
10
|
output: string;
|
|
11
|
+
exclude?: string | string[];
|
|
12
|
+
prefix?: string;
|
|
13
|
+
naming?: NamingConvention;
|
|
10
14
|
}
|
|
11
15
|
declare function generate(options: GenerateOptions): Promise<void>;
|
|
12
16
|
|
|
13
|
-
export { type GenerateOptions,
|
|
17
|
+
export { type GenerateOptions, NamingConvention, generate, parseVarNames, scanVarNames };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { N as NamingConvention } from './generator-Ba8XeISD.js';
|
|
2
|
+
export { g as generateCode, a as generateDeclaration, b as generateJs } from './generator-Ba8XeISD.js';
|
|
2
3
|
|
|
3
|
-
declare function
|
|
4
|
+
declare function parseVarNames(css: string): string[];
|
|
4
5
|
|
|
5
|
-
declare function scanVarNames(patterns: string | string[]): Promise<string[]>;
|
|
6
|
+
declare function scanVarNames(patterns: string | string[], exclude?: string | string[]): Promise<string[]>;
|
|
6
7
|
|
|
7
8
|
interface GenerateOptions {
|
|
8
9
|
input: string | string[];
|
|
9
10
|
output: string;
|
|
11
|
+
exclude?: string | string[];
|
|
12
|
+
prefix?: string;
|
|
13
|
+
naming?: NamingConvention;
|
|
10
14
|
}
|
|
11
15
|
declare function generate(options: GenerateOptions): Promise<void>;
|
|
12
16
|
|
|
13
|
-
export { type GenerateOptions,
|
|
17
|
+
export { type GenerateOptions, NamingConvention, generate, parseVarNames, scanVarNames };
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generate
|
|
3
|
+
} from "./chunk-3XKCOLZL.js";
|
|
1
4
|
import {
|
|
2
5
|
generateCode,
|
|
6
|
+
generateDeclaration,
|
|
7
|
+
generateJs,
|
|
3
8
|
parseVarNames,
|
|
4
9
|
scanVarNames
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
|
|
7
|
-
// src/index.ts
|
|
8
|
-
import { writeFile, mkdir } from "fs/promises";
|
|
9
|
-
import { dirname, resolve } from "path";
|
|
10
|
-
async function generate(options) {
|
|
11
|
-
const names = await scanVarNames(options.input);
|
|
12
|
-
const code = generateCode(names);
|
|
13
|
-
await mkdir(dirname(resolve(options.output)), { recursive: true });
|
|
14
|
-
await writeFile(options.output, code, "utf8");
|
|
15
|
-
}
|
|
10
|
+
} from "./chunk-4VL6W5GO.js";
|
|
16
11
|
export {
|
|
17
12
|
generate,
|
|
18
13
|
generateCode,
|
|
14
|
+
generateDeclaration,
|
|
15
|
+
generateJs,
|
|
19
16
|
parseVarNames,
|
|
20
17
|
scanVarNames
|
|
21
18
|
};
|
package/dist/rollup.cjs
CHANGED
|
@@ -57,11 +57,12 @@ function parseVarNames(css) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// src/scanner.ts
|
|
60
|
-
async function scanVarNames(patterns) {
|
|
60
|
+
async function scanVarNames(patterns, exclude) {
|
|
61
61
|
const normalized = (Array.isArray(patterns) ? patterns : [patterns]).map(
|
|
62
62
|
(p) => p.replace(/\\/g, "/")
|
|
63
63
|
);
|
|
64
|
-
const
|
|
64
|
+
const normalizedExclude = exclude ? (Array.isArray(exclude) ? exclude : [exclude]).map((p) => p.replace(/\\/g, "/")) : [];
|
|
65
|
+
const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
|
|
65
66
|
const all = /* @__PURE__ */ new Set();
|
|
66
67
|
await Promise.all(
|
|
67
68
|
files.map(async (file) => {
|
|
@@ -75,20 +76,40 @@ async function scanVarNames(patterns) {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
// src/generator.ts
|
|
78
|
-
function
|
|
79
|
-
|
|
79
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
80
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
81
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
82
|
+
if (naming === "kebab") return stripped;
|
|
83
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
80
84
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
85
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
86
|
+
if (!prefix) return key;
|
|
87
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
88
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
89
|
+
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
90
|
+
}
|
|
91
|
+
function formatKey(key, naming = "camelCase") {
|
|
92
|
+
if (naming === "kebab") return `'${key}'`;
|
|
93
|
+
return key;
|
|
94
|
+
}
|
|
95
|
+
function generateJs(varNames, prefix, naming) {
|
|
96
|
+
const entries = varNames.map((name) => {
|
|
97
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
98
|
+
return ` ${key}: 'var(${name})',`;
|
|
99
|
+
});
|
|
83
100
|
return [
|
|
101
|
+
"// generated \u2014 do not edit",
|
|
84
102
|
"export const cssVars = {",
|
|
85
103
|
...entries,
|
|
86
104
|
"};",
|
|
87
105
|
""
|
|
88
106
|
].join("\n");
|
|
89
107
|
}
|
|
90
|
-
function generateDeclaration(varNames) {
|
|
91
|
-
const entries = varNames.map((name) =>
|
|
108
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
109
|
+
const entries = varNames.map((name) => {
|
|
110
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
111
|
+
return ` ${key}: 'var(${name})';`;
|
|
112
|
+
});
|
|
92
113
|
return [
|
|
93
114
|
"export declare const cssVars: {",
|
|
94
115
|
...entries,
|
|
@@ -112,10 +133,10 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
112
133
|
configureServer(server) {
|
|
113
134
|
server.watcher.on("change", async (file) => {
|
|
114
135
|
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
115
|
-
const names = await scanVarNames(options.input);
|
|
136
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
116
137
|
const dtsPath = getDtsPath(options);
|
|
117
138
|
if (dtsPath) {
|
|
118
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
139
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
119
140
|
}
|
|
120
141
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
121
142
|
if (mod) {
|
|
@@ -128,16 +149,16 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
128
149
|
async buildStart() {
|
|
129
150
|
const dtsPath = getDtsPath(options);
|
|
130
151
|
if (!dtsPath) return;
|
|
131
|
-
const names = await scanVarNames(options.input);
|
|
132
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
152
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
153
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
133
154
|
},
|
|
134
155
|
resolveId(id) {
|
|
135
156
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
136
157
|
},
|
|
137
158
|
async load(id) {
|
|
138
159
|
if (id === RESOLVED_ID) {
|
|
139
|
-
const names = await scanVarNames(options.input);
|
|
140
|
-
return generateJs(names);
|
|
160
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
161
|
+
return generateJs(names, options.prefix, options.naming);
|
|
141
162
|
}
|
|
142
163
|
}
|
|
143
164
|
}));
|
package/dist/rollup.d.cts
CHANGED
package/dist/rollup.d.ts
CHANGED
package/dist/rollup.js
CHANGED
package/dist/unplugin.cjs
CHANGED
|
@@ -55,11 +55,12 @@ function parseVarNames(css) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
// src/scanner.ts
|
|
58
|
-
async function scanVarNames(patterns) {
|
|
58
|
+
async function scanVarNames(patterns, exclude) {
|
|
59
59
|
const normalized = (Array.isArray(patterns) ? patterns : [patterns]).map(
|
|
60
60
|
(p) => p.replace(/\\/g, "/")
|
|
61
61
|
);
|
|
62
|
-
const
|
|
62
|
+
const normalizedExclude = exclude ? (Array.isArray(exclude) ? exclude : [exclude]).map((p) => p.replace(/\\/g, "/")) : [];
|
|
63
|
+
const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
|
|
63
64
|
const all = /* @__PURE__ */ new Set();
|
|
64
65
|
await Promise.all(
|
|
65
66
|
files.map(async (file) => {
|
|
@@ -73,20 +74,40 @@ async function scanVarNames(patterns) {
|
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
// src/generator.ts
|
|
76
|
-
function
|
|
77
|
-
|
|
77
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
78
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
79
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
80
|
+
if (naming === "kebab") return stripped;
|
|
81
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
78
82
|
}
|
|
79
|
-
function
|
|
80
|
-
|
|
83
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
84
|
+
if (!prefix) return key;
|
|
85
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
86
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
87
|
+
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
88
|
+
}
|
|
89
|
+
function formatKey(key, naming = "camelCase") {
|
|
90
|
+
if (naming === "kebab") return `'${key}'`;
|
|
91
|
+
return key;
|
|
92
|
+
}
|
|
93
|
+
function generateJs(varNames, prefix, naming) {
|
|
94
|
+
const entries = varNames.map((name) => {
|
|
95
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
96
|
+
return ` ${key}: 'var(${name})',`;
|
|
97
|
+
});
|
|
81
98
|
return [
|
|
99
|
+
"// generated \u2014 do not edit",
|
|
82
100
|
"export const cssVars = {",
|
|
83
101
|
...entries,
|
|
84
102
|
"};",
|
|
85
103
|
""
|
|
86
104
|
].join("\n");
|
|
87
105
|
}
|
|
88
|
-
function generateDeclaration(varNames) {
|
|
89
|
-
const entries = varNames.map((name) =>
|
|
106
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
107
|
+
const entries = varNames.map((name) => {
|
|
108
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
109
|
+
return ` ${key}: 'var(${name})';`;
|
|
110
|
+
});
|
|
90
111
|
return [
|
|
91
112
|
"export declare const cssVars: {",
|
|
92
113
|
...entries,
|
|
@@ -110,10 +131,10 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
110
131
|
configureServer(server) {
|
|
111
132
|
server.watcher.on("change", async (file) => {
|
|
112
133
|
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
113
|
-
const names = await scanVarNames(options.input);
|
|
134
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
114
135
|
const dtsPath = getDtsPath(options);
|
|
115
136
|
if (dtsPath) {
|
|
116
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
137
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
117
138
|
}
|
|
118
139
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
119
140
|
if (mod) {
|
|
@@ -126,16 +147,16 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
126
147
|
async buildStart() {
|
|
127
148
|
const dtsPath = getDtsPath(options);
|
|
128
149
|
if (!dtsPath) return;
|
|
129
|
-
const names = await scanVarNames(options.input);
|
|
130
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
150
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
151
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
131
152
|
},
|
|
132
153
|
resolveId(id) {
|
|
133
154
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
134
155
|
},
|
|
135
156
|
async load(id) {
|
|
136
157
|
if (id === RESOLVED_ID) {
|
|
137
|
-
const names = await scanVarNames(options.input);
|
|
138
|
-
return generateJs(names);
|
|
158
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
159
|
+
return generateJs(names, options.prefix, options.naming);
|
|
139
160
|
}
|
|
140
161
|
}
|
|
141
162
|
}));
|
package/dist/unplugin.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as unplugin from 'unplugin';
|
|
2
|
+
import { N as NamingConvention } from './generator-Ba8XeISD.cjs';
|
|
2
3
|
|
|
3
4
|
interface Options {
|
|
4
5
|
input: string | string[];
|
|
@@ -9,6 +10,9 @@ interface Options {
|
|
|
9
10
|
* - `false`: skip writing
|
|
10
11
|
*/
|
|
11
12
|
dts?: string | false;
|
|
13
|
+
exclude?: string | string[];
|
|
14
|
+
prefix?: string;
|
|
15
|
+
naming?: NamingConvention;
|
|
12
16
|
}
|
|
13
17
|
declare const _default: unplugin.UnpluginInstance<Options, boolean>;
|
|
14
18
|
|
package/dist/unplugin.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as unplugin from 'unplugin';
|
|
2
|
+
import { N as NamingConvention } from './generator-Ba8XeISD.js';
|
|
2
3
|
|
|
3
4
|
interface Options {
|
|
4
5
|
input: string | string[];
|
|
@@ -9,6 +10,9 @@ interface Options {
|
|
|
9
10
|
* - `false`: skip writing
|
|
10
11
|
*/
|
|
11
12
|
dts?: string | false;
|
|
13
|
+
exclude?: string | string[];
|
|
14
|
+
prefix?: string;
|
|
15
|
+
naming?: NamingConvention;
|
|
12
16
|
}
|
|
13
17
|
declare const _default: unplugin.UnpluginInstance<Options, boolean>;
|
|
14
18
|
|
package/dist/unplugin.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -57,11 +57,12 @@ function parseVarNames(css) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// src/scanner.ts
|
|
60
|
-
async function scanVarNames(patterns) {
|
|
60
|
+
async function scanVarNames(patterns, exclude) {
|
|
61
61
|
const normalized = (Array.isArray(patterns) ? patterns : [patterns]).map(
|
|
62
62
|
(p) => p.replace(/\\/g, "/")
|
|
63
63
|
);
|
|
64
|
-
const
|
|
64
|
+
const normalizedExclude = exclude ? (Array.isArray(exclude) ? exclude : [exclude]).map((p) => p.replace(/\\/g, "/")) : [];
|
|
65
|
+
const files = await (0, import_fast_glob.default)(normalized, { absolute: true, ignore: normalizedExclude });
|
|
65
66
|
const all = /* @__PURE__ */ new Set();
|
|
66
67
|
await Promise.all(
|
|
67
68
|
files.map(async (file) => {
|
|
@@ -75,20 +76,40 @@ async function scanVarNames(patterns) {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
// src/generator.ts
|
|
78
|
-
function
|
|
79
|
-
|
|
79
|
+
function toKey(cssVarName, naming = "camelCase") {
|
|
80
|
+
const stripped = cssVarName.replace(/^--/, "");
|
|
81
|
+
if (naming === "snake") return stripped.replace(/-/g, "_");
|
|
82
|
+
if (naming === "kebab") return stripped;
|
|
83
|
+
return stripped.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
80
84
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
85
|
+
function applyPrefix(key, prefix, naming = "camelCase") {
|
|
86
|
+
if (!prefix) return key;
|
|
87
|
+
if (naming === "snake") return `${prefix}_${key}`;
|
|
88
|
+
if (naming === "kebab") return `${prefix}-${key}`;
|
|
89
|
+
return prefix + key.charAt(0).toUpperCase() + key.slice(1);
|
|
90
|
+
}
|
|
91
|
+
function formatKey(key, naming = "camelCase") {
|
|
92
|
+
if (naming === "kebab") return `'${key}'`;
|
|
93
|
+
return key;
|
|
94
|
+
}
|
|
95
|
+
function generateJs(varNames, prefix, naming) {
|
|
96
|
+
const entries = varNames.map((name) => {
|
|
97
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
98
|
+
return ` ${key}: 'var(${name})',`;
|
|
99
|
+
});
|
|
83
100
|
return [
|
|
101
|
+
"// generated \u2014 do not edit",
|
|
84
102
|
"export const cssVars = {",
|
|
85
103
|
...entries,
|
|
86
104
|
"};",
|
|
87
105
|
""
|
|
88
106
|
].join("\n");
|
|
89
107
|
}
|
|
90
|
-
function generateDeclaration(varNames) {
|
|
91
|
-
const entries = varNames.map((name) =>
|
|
108
|
+
function generateDeclaration(varNames, prefix, naming) {
|
|
109
|
+
const entries = varNames.map((name) => {
|
|
110
|
+
const key = formatKey(applyPrefix(toKey(name, naming), prefix, naming), naming);
|
|
111
|
+
return ` ${key}: 'var(${name})';`;
|
|
112
|
+
});
|
|
92
113
|
return [
|
|
93
114
|
"export declare const cssVars: {",
|
|
94
115
|
...entries,
|
|
@@ -112,10 +133,10 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
112
133
|
configureServer(server) {
|
|
113
134
|
server.watcher.on("change", async (file) => {
|
|
114
135
|
if (!/\.(css|scss|less)$/i.test(file)) return;
|
|
115
|
-
const names = await scanVarNames(options.input);
|
|
136
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
116
137
|
const dtsPath = getDtsPath(options);
|
|
117
138
|
if (dtsPath) {
|
|
118
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
139
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
119
140
|
}
|
|
120
141
|
const mod = server.moduleGraph.getModuleById(RESOLVED_ID);
|
|
121
142
|
if (mod) {
|
|
@@ -128,16 +149,16 @@ var unplugin_default = (0, import_unplugin.createUnplugin)((options) => ({
|
|
|
128
149
|
async buildStart() {
|
|
129
150
|
const dtsPath = getDtsPath(options);
|
|
130
151
|
if (!dtsPath) return;
|
|
131
|
-
const names = await scanVarNames(options.input);
|
|
132
|
-
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names), "utf8");
|
|
152
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
153
|
+
await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
|
|
133
154
|
},
|
|
134
155
|
resolveId(id) {
|
|
135
156
|
if (id === VIRTUAL_ID) return RESOLVED_ID;
|
|
136
157
|
},
|
|
137
158
|
async load(id) {
|
|
138
159
|
if (id === RESOLVED_ID) {
|
|
139
|
-
const names = await scanVarNames(options.input);
|
|
140
|
-
return generateJs(names);
|
|
160
|
+
const names = await scanVarNames(options.input, options.exclude);
|
|
161
|
+
return generateJs(names, options.prefix, options.naming);
|
|
141
162
|
}
|
|
142
163
|
}
|
|
143
164
|
}));
|
package/dist/vite.d.cts
CHANGED
package/dist/vite.d.ts
CHANGED