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/webpack.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/webpack.d.cts
CHANGED
package/dist/webpack.d.ts
CHANGED
package/dist/webpack.js
CHANGED