uniwind-plugin-next 1.1.1 → 1.2.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/LICENSE +21 -0
- package/README.md +8 -9
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/index.cjs +2 -368
- package/dist/index.d.cts +1 -10
- package/dist/index.d.mts +1 -10
- package/dist/index.mjs +1 -338
- package/dist/postcss/index.cjs +8 -4
- package/dist/postcss/index.d.cts +10 -1
- package/dist/postcss/index.d.cts.map +1 -0
- package/dist/postcss/index.d.mts +11 -1
- package/dist/postcss/index.d.mts.map +1 -0
- package/dist/postcss/index.mjs +17 -19
- package/dist/postcss/index.mjs.map +1 -0
- package/dist/webpack/UniwindWebpackPlugin.cjs +48 -0
- package/dist/webpack/UniwindWebpackPlugin.mjs +47 -0
- package/dist/webpack/UniwindWebpackPlugin.mjs.map +1 -0
- package/dist/webpack/clientDirectiveLoader.js +8 -0
- package/dist/webpack/configInjectionLoader.js +6 -0
- package/dist/webpack/types.d.cts +9 -0
- package/dist/webpack/types.d.cts.map +1 -0
- package/dist/webpack/types.d.mts +9 -0
- package/dist/webpack/types.d.mts.map +1 -0
- package/dist/webpack/uniwind/package.cjs +11 -0
- package/dist/webpack/uniwind/package.mjs +6 -0
- package/dist/webpack/uniwind/package.mjs.map +1 -0
- package/dist/webpack/uniwind/src/css/index.cjs +26 -0
- package/dist/webpack/uniwind/src/css/index.mjs +24 -0
- package/dist/webpack/uniwind/src/css/index.mjs.map +1 -0
- package/dist/webpack/uniwind/src/css/insets.cjs +66 -0
- package/dist/webpack/uniwind/src/css/insets.mjs +66 -0
- package/dist/webpack/uniwind/src/css/insets.mjs.map +1 -0
- package/dist/webpack/uniwind/src/css/themes.cjs +84 -0
- package/dist/webpack/uniwind/src/css/themes.mjs +82 -0
- package/dist/webpack/uniwind/src/css/themes.mjs.map +1 -0
- package/dist/webpack/uniwind/src/css/variants.cjs +18 -0
- package/dist/webpack/uniwind/src/css/variants.mjs +18 -0
- package/dist/webpack/uniwind/src/css/variants.mjs.map +1 -0
- package/dist/webpack/uniwind/src/metro/logger.cjs +37 -0
- package/dist/webpack/uniwind/src/metro/logger.mjs +37 -0
- package/dist/webpack/uniwind/src/metro/logger.mjs.map +1 -0
- package/dist/webpack/uniwind/src/utils/buildDtsFile.cjs +27 -0
- package/dist/webpack/uniwind/src/utils/buildDtsFile.mjs +26 -0
- package/dist/webpack/uniwind/src/utils/buildDtsFile.mjs.map +1 -0
- package/dist/webpack/uniwind/src/utils/common.cjs +6 -0
- package/dist/webpack/uniwind/src/utils/common.mjs +6 -0
- package/dist/webpack/uniwind/src/utils/common.mjs.map +1 -0
- package/dist/webpack/uniwind/src/utils/stringifyThemes.cjs +6 -0
- package/dist/webpack/uniwind/src/utils/stringifyThemes.mjs +6 -0
- package/dist/webpack/uniwind/src/utils/stringifyThemes.mjs.map +1 -0
- package/dist/webpack/withUniwind.cjs +34 -0
- package/dist/webpack/withUniwind.d.cts +7 -0
- package/dist/webpack/withUniwind.d.cts.map +1 -0
- package/dist/webpack/withUniwind.d.mts +7 -0
- package/dist/webpack/withUniwind.d.mts.map +1 -0
- package/dist/webpack/withUniwind.mjs +32 -0
- package/dist/webpack/withUniwind.mjs.map +1 -0
- package/package.json +24 -5
- package/dist/chunk-3qlvafw2.mjs +0 -8
- package/dist/clientDirectiveLoader.js +0 -9
- package/dist/configInjectionLoader.js +0 -6
package/dist/index.mjs
CHANGED
|
@@ -1,340 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import webpack from "webpack";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import fs from "fs";
|
|
5
|
-
import { compile } from "@tailwindcss/node";
|
|
6
|
-
import { transform } from "lightningcss";
|
|
1
|
+
import { withUniwind } from "./webpack/withUniwind.mjs";
|
|
7
2
|
|
|
8
|
-
//#region src/webpack/uniwind/src/utils/common.ts
|
|
9
|
-
const uniq = (arr) => Array.from(new Set(arr));
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/webpack/patchFsForWritingUniwindCSSFile.ts
|
|
13
|
-
const uniwindDir = path.dirname(__require.resolve("uniwind/package.json"));
|
|
14
|
-
/**
|
|
15
|
-
* The contents of the `css` directory is copied direct from the uniwind source code. This makes it easier to keep it in
|
|
16
|
-
* sync with the upstream uniwind package, so we purposefully avoid modifying any code in `css`.
|
|
17
|
-
*
|
|
18
|
-
* However, we do need to patch `buildCSS()` to output the generated `uniwind.css` file into the `uniwind` package directory
|
|
19
|
-
* within node_modules. To do this we temporarily patch `fs.writeFileSync` to redirect all writes of `uniwind.css` to the
|
|
20
|
-
* correct location.
|
|
21
|
-
*
|
|
22
|
-
* Usage:
|
|
23
|
-
* ```ts
|
|
24
|
-
* const unpatchFs = patchFs();
|
|
25
|
-
* await buildCSS(themes, cssEntryFile);
|
|
26
|
-
* unpatchFs();
|
|
27
|
-
*/
|
|
28
|
-
function patchFsForWritingUniwindCSSFile() {
|
|
29
|
-
const originalWriteFileSync = fs.writeFileSync;
|
|
30
|
-
fs.writeFileSync = function(_path, data, options) {
|
|
31
|
-
let newPath = _path;
|
|
32
|
-
if (typeof newPath === "string" && newPath.endsWith("uniwind.css")) newPath = path.join(uniwindDir, "uniwind.css");
|
|
33
|
-
return originalWriteFileSync.call(fs, newPath, data, options);
|
|
34
|
-
};
|
|
35
|
-
return function unpatchFs() {
|
|
36
|
-
fs.writeFileSync = originalWriteFileSync;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/webpack/uniwind/src/css/insets.ts
|
|
42
|
-
const types = ["m", "p"];
|
|
43
|
-
const sides = [
|
|
44
|
-
"",
|
|
45
|
-
"x",
|
|
46
|
-
"y",
|
|
47
|
-
"t",
|
|
48
|
-
"b",
|
|
49
|
-
"l",
|
|
50
|
-
"r"
|
|
51
|
-
];
|
|
52
|
-
const spacing = "--spacing(--value(integer))";
|
|
53
|
-
const length = "--value([length])";
|
|
54
|
-
const generateCSSForInsets = () => {
|
|
55
|
-
let css = `@utility h-screen-safe {
|
|
56
|
-
height: calc(100vh - (env(safe-area-inset-top) + env(safe-area-inset-bottom)));
|
|
57
|
-
}\n`;
|
|
58
|
-
const getInsetsForSide = (side) => {
|
|
59
|
-
switch (side) {
|
|
60
|
-
case "t": return ["top"];
|
|
61
|
-
case "b": return ["bottom"];
|
|
62
|
-
case "l": return ["left"];
|
|
63
|
-
case "r": return ["right"];
|
|
64
|
-
case "x": return ["left", "right"];
|
|
65
|
-
case "y": return ["top", "bottom"];
|
|
66
|
-
default: return [
|
|
67
|
-
"top",
|
|
68
|
-
"bottom",
|
|
69
|
-
"left",
|
|
70
|
-
"right"
|
|
71
|
-
];
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
types.forEach((type) => {
|
|
75
|
-
sides.forEach((side) => {
|
|
76
|
-
const styleName = type === "m" ? "margin" : "padding";
|
|
77
|
-
const styles = getInsetsForSide(side).map((inset) => `${styleName}-${inset}: env(safe-area-inset-${inset});`);
|
|
78
|
-
const safeStyles = styles.flatMap((style) => {
|
|
79
|
-
const styleWithoutSemicolon = style.replace(";", "");
|
|
80
|
-
return [styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: max(${env}, ${spacing});`), styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: max(${env}, ${length});`)];
|
|
81
|
-
});
|
|
82
|
-
const safeOffsetStyles = styles.flatMap((style) => {
|
|
83
|
-
const styleWithoutSemicolon = style.replace(";", "");
|
|
84
|
-
return [styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: calc(${env} + ${spacing});`), styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: calc(${env} + ${length});`)];
|
|
85
|
-
});
|
|
86
|
-
css += `
|
|
87
|
-
@utility ${type}${side}-safe {
|
|
88
|
-
${styles.join("\n ")}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
@utility ${type}${side}-safe-or-* {
|
|
92
|
-
${safeStyles.join("\n ")}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
@utility ${type}${side}-safe-offset-* {
|
|
96
|
-
${safeOffsetStyles.join("\n ")}
|
|
97
|
-
}
|
|
98
|
-
`;
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
return css.replaceAll(" ", "").trim() + "\n";
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
//#endregion
|
|
105
|
-
//#region src/webpack/uniwind/src/metro/logger.ts
|
|
106
|
-
const red = "\x1B[91m";
|
|
107
|
-
const yellow = "\x1B[33m";
|
|
108
|
-
const blue = "\x1B[36m";
|
|
109
|
-
const reset = "\x1B[0m";
|
|
110
|
-
var Logger = class Logger {
|
|
111
|
-
static {
|
|
112
|
-
this.debug = false;
|
|
113
|
-
}
|
|
114
|
-
constructor(name$1) {
|
|
115
|
-
this.name = name$1;
|
|
116
|
-
}
|
|
117
|
-
static log(message, meta = "") {
|
|
118
|
-
if (!Logger.debug) return;
|
|
119
|
-
console.log(`${blue}Uniwind ${meta}- ${message}${reset}`);
|
|
120
|
-
}
|
|
121
|
-
static error(message, meta = "") {
|
|
122
|
-
console.log(`${red}Uniwind Error ${meta}- ${message}${reset}`);
|
|
123
|
-
}
|
|
124
|
-
static warn(message, meta = "") {
|
|
125
|
-
if (!Logger.debug) return;
|
|
126
|
-
console.log(`${yellow}Uniwind Warning ${meta}- ${message}${reset}`);
|
|
127
|
-
}
|
|
128
|
-
log(message) {
|
|
129
|
-
Logger.log(message, `[${this.name} Processor] `);
|
|
130
|
-
}
|
|
131
|
-
error(message) {
|
|
132
|
-
Logger.error(message, `[${this.name} Processor] `);
|
|
133
|
-
}
|
|
134
|
-
warn(message) {
|
|
135
|
-
Logger.warn(message, `[${this.name} Processor] `);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
//#endregion
|
|
140
|
-
//#region src/webpack/uniwind/src/css/themes.ts
|
|
141
|
-
const readFileSafe = (filePath) => {
|
|
142
|
-
try {
|
|
143
|
-
return fs.readFileSync(filePath, "utf-8");
|
|
144
|
-
} catch {
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
const isExcludedDependency = (url) => [
|
|
149
|
-
url.includes("node_modules/tailwindcss"),
|
|
150
|
-
url.includes("node_modules/@tailwindcss"),
|
|
151
|
-
url.includes("node_modules/uniwind")
|
|
152
|
-
].some(Boolean);
|
|
153
|
-
const generateCSSForThemes = async (themes, input) => {
|
|
154
|
-
const themesVariables = Object.fromEntries(themes.map((theme) => [theme, /* @__PURE__ */ new Set()]));
|
|
155
|
-
const findVariantsRec = async (cssPath) => {
|
|
156
|
-
const css = readFileSafe(cssPath);
|
|
157
|
-
if (css === null) return;
|
|
158
|
-
const { dependencies } = transform({
|
|
159
|
-
code: Buffer.from(css),
|
|
160
|
-
filename: "uniwind.css",
|
|
161
|
-
analyzeDependencies: true,
|
|
162
|
-
visitor: { Rule: (rule) => {
|
|
163
|
-
if (rule.type === "unknown" && rule.value.name === "variant") {
|
|
164
|
-
const [firstPrelude] = rule.value.prelude;
|
|
165
|
-
if (firstPrelude?.type !== "token" || firstPrelude.value.type !== "ident" || !themes.includes(firstPrelude.value.value)) return;
|
|
166
|
-
const theme = firstPrelude.value.value;
|
|
167
|
-
rule.value.block?.forEach((block) => {
|
|
168
|
-
if (block.type === "dashed-ident") themesVariables[theme]?.add(block.value);
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
} }
|
|
172
|
-
});
|
|
173
|
-
if (!Array.isArray(dependencies)) return;
|
|
174
|
-
const importUrls = /* @__PURE__ */ new Set();
|
|
175
|
-
await compile(dependencies.filter((dependency) => {
|
|
176
|
-
if (dependency.url.startsWith(".")) {
|
|
177
|
-
importUrls.add(path.resolve(path.dirname(cssPath), dependency.url));
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
return !isExcludedDependency(dependency.url);
|
|
181
|
-
}).map((dependency) => `@import "${dependency.url}";`).join("\n"), {
|
|
182
|
-
base: path.resolve(path.dirname(cssPath)),
|
|
183
|
-
onDependency: (dependency) => {
|
|
184
|
-
if (isExcludedDependency(dependency)) return;
|
|
185
|
-
importUrls.add(dependency);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
for (const filePath of importUrls) await findVariantsRec(filePath);
|
|
189
|
-
};
|
|
190
|
-
await findVariantsRec(input);
|
|
191
|
-
let hasErrors = false;
|
|
192
|
-
const hasVariables = Object.values(themesVariables).some((variables) => variables.size > 0);
|
|
193
|
-
Object.values(themesVariables).forEach((variables) => {
|
|
194
|
-
Object.entries(themesVariables).forEach(([checkedTheme, checkedVariables]) => {
|
|
195
|
-
variables.forEach((variable) => {
|
|
196
|
-
if (!checkedVariables.has(variable)) {
|
|
197
|
-
Logger.error(`Theme ${checkedTheme} is missing variable ${variable}`);
|
|
198
|
-
hasErrors = true;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
if (hasErrors) Logger.error("All themes must have the same variables");
|
|
204
|
-
const variablesCSS = hasVariables ? [
|
|
205
|
-
"",
|
|
206
|
-
"@theme {",
|
|
207
|
-
...Array.from(Object.values(themesVariables).at(0) ?? []).map((variable) => ` ${variable}: unset;`),
|
|
208
|
-
"}"
|
|
209
|
-
] : [];
|
|
210
|
-
return [...themes.map((theme) => `@custom-variant ${theme} (&:where(.${theme}, .${theme} *));`), ...variablesCSS].join("\n");
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
//#endregion
|
|
214
|
-
//#region src/webpack/uniwind/src/css/variants.ts
|
|
215
|
-
const variants = [
|
|
216
|
-
"ios",
|
|
217
|
-
"android",
|
|
218
|
-
"web",
|
|
219
|
-
"native"
|
|
220
|
-
];
|
|
221
|
-
const generateCSSForVariants = () => {
|
|
222
|
-
let css = "";
|
|
223
|
-
variants.forEach((variant) => {
|
|
224
|
-
css += `@custom-variant ${variant} (${variant === "web" ? "html &" : `@media ${variant}`});\n`;
|
|
225
|
-
});
|
|
226
|
-
return css;
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
//#endregion
|
|
230
|
-
//#region src/webpack/uniwind/src/css/index.ts
|
|
231
|
-
const dirname = typeof __dirname !== "undefined" ? __dirname : import.meta.dirname;
|
|
232
|
-
const buildCSS = async (themes, input) => {
|
|
233
|
-
const variants$1 = generateCSSForVariants();
|
|
234
|
-
const insets = generateCSSForInsets();
|
|
235
|
-
const themesCSS = await generateCSSForThemes(themes, input);
|
|
236
|
-
const cssFile = path.join(dirname, "../../uniwind.css");
|
|
237
|
-
if ((fs.existsSync(cssFile) ? fs.readFileSync(cssFile, "utf-8") : "") === cssFile) return;
|
|
238
|
-
fs.writeFileSync(cssFile, [
|
|
239
|
-
variants$1,
|
|
240
|
-
insets,
|
|
241
|
-
themesCSS
|
|
242
|
-
].join("\n"));
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
//#endregion
|
|
246
|
-
//#region src/webpack/uniwind/package.json
|
|
247
|
-
var name = "uniwind";
|
|
248
|
-
|
|
249
|
-
//#endregion
|
|
250
|
-
//#region src/webpack/uniwind/src/utils/buildDtsFile.ts
|
|
251
|
-
const buildDtsFile = (dtsPath, stringifiedThemes) => {
|
|
252
|
-
const oldDtsContent = fs.existsSync(dtsPath) ? fs.readFileSync(dtsPath, "utf-8") : "";
|
|
253
|
-
const dtsContent = [
|
|
254
|
-
`// NOTE: This file is generated by ${name} and it should not be edited manually.`,
|
|
255
|
-
`/// <reference types="${name}/types" />`,
|
|
256
|
-
"",
|
|
257
|
-
`declare module '${name}' {`,
|
|
258
|
-
` export interface UniwindConfig {`,
|
|
259
|
-
` themes: readonly ${stringifiedThemes}`,
|
|
260
|
-
` }`,
|
|
261
|
-
`}`,
|
|
262
|
-
"",
|
|
263
|
-
`export {}`,
|
|
264
|
-
""
|
|
265
|
-
].join("\n");
|
|
266
|
-
if (oldDtsContent === dtsContent) return;
|
|
267
|
-
fs.writeFileSync(dtsPath, dtsContent);
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
//#endregion
|
|
271
|
-
//#region src/webpack/uniwind/src/utils/stringifyThemes.ts
|
|
272
|
-
const stringifyThemes = (themes = []) => `[${themes.map((theme) => `'${theme}'`).join(", ")}]`;
|
|
273
|
-
|
|
274
|
-
//#endregion
|
|
275
|
-
//#region src/webpack/UniwindWebpackPlugin.ts
|
|
276
|
-
var UniwindWebpackPlugin = class {
|
|
277
|
-
constructor({ cssEntryFile, extraThemes = [], dtsFile = "uniwind-types.d.ts" }) {
|
|
278
|
-
this.hasRun = false;
|
|
279
|
-
this.themes = uniq([
|
|
280
|
-
"light",
|
|
281
|
-
"dark",
|
|
282
|
-
...extraThemes ?? []
|
|
283
|
-
]);
|
|
284
|
-
this.dtsFile = dtsFile;
|
|
285
|
-
this.cssEntryFile = cssEntryFile;
|
|
286
|
-
}
|
|
287
|
-
apply(compiler) {
|
|
288
|
-
compiler.hooks.beforeCompile.tapPromise("UniwindWebpackPlugin", async () => {
|
|
289
|
-
if (this.hasRun) return;
|
|
290
|
-
this.hasRun = true;
|
|
291
|
-
const removePatch = patchFsForWritingUniwindCSSFile();
|
|
292
|
-
await buildCSS(this.themes, this.cssEntryFile);
|
|
293
|
-
removePatch();
|
|
294
|
-
buildDtsFile(this.dtsFile, stringifyThemes(this.themes));
|
|
295
|
-
});
|
|
296
|
-
compiler.options.module = compiler.options.module || { rules: [] };
|
|
297
|
-
compiler.options.module.rules.push({
|
|
298
|
-
test: /config\.c?js$/,
|
|
299
|
-
include: /uniwind[\/\\]dist/,
|
|
300
|
-
use: [{
|
|
301
|
-
loader: path.resolve(__dirname, "configInjectionLoader.js"),
|
|
302
|
-
options: { stringifiedThemes: stringifyThemes(this.themes) }
|
|
303
|
-
}]
|
|
304
|
-
});
|
|
305
|
-
compiler.options.module.rules.push({
|
|
306
|
-
test: /\.js$/,
|
|
307
|
-
exclude: /index\.js$/,
|
|
308
|
-
include: /uniwind[\/\\]dist[\/\\]module[\/\\]components[\/\\]web/,
|
|
309
|
-
use: [{ loader: path.resolve(__dirname, "clientDirectiveLoader.js") }]
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
//#endregion
|
|
315
|
-
//#region src/webpack/withUniwind.ts
|
|
316
|
-
const { NormalModuleReplacementPlugin } = webpack;
|
|
317
|
-
function withUniwind(nextConfig = {}, uniwindConfig) {
|
|
318
|
-
return {
|
|
319
|
-
...nextConfig,
|
|
320
|
-
transpilePackages: uniq([
|
|
321
|
-
...nextConfig.transpilePackages || [],
|
|
322
|
-
"uniwind",
|
|
323
|
-
"react-native",
|
|
324
|
-
"react-native-web"
|
|
325
|
-
]),
|
|
326
|
-
webpack(config, options) {
|
|
327
|
-
if (!config.plugins) config.plugins = [];
|
|
328
|
-
config.plugins.push(new NormalModuleReplacementPlugin(/^react-native$/, (resource) => {
|
|
329
|
-
if ((resource.context || "").includes(`${path.sep}uniwind${path.sep}dist${path.sep}module${path.sep}components${path.sep}web`)) resource.request = "react-native-web";
|
|
330
|
-
else resource.request = "uniwind/components/index";
|
|
331
|
-
}));
|
|
332
|
-
config.plugins.push(new UniwindWebpackPlugin(uniwindConfig));
|
|
333
|
-
if (typeof nextConfig.webpack === "function") return nextConfig.webpack(config, options);
|
|
334
|
-
return config;
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
//#endregion
|
|
340
3
|
export { withUniwind };
|
package/dist/postcss/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/postcss/index.ts
|
|
3
|
-
|
|
3
|
+
function UniwindPluginNext() {
|
|
4
4
|
return {
|
|
5
5
|
postcssPlugin: "uniwind-plugin-next",
|
|
6
6
|
Once(root) {
|
|
@@ -9,9 +9,13 @@ module.exports = () => {
|
|
|
9
9
|
decl.value = decl.value.replace(/fontScale\(([^)]+)\)/g, "calc($1 * 1rem)");
|
|
10
10
|
decl.value = decl.value.replace(/hairlineWidth\(\)/g, "1px");
|
|
11
11
|
});
|
|
12
|
+
root.walkAtRules("import", (rule) => {
|
|
13
|
+
if (rule.params.replace(/['"]/g, "") === "uniwind") rule.params = "\"uniwind-plugin-next/css\"";
|
|
14
|
+
});
|
|
12
15
|
}
|
|
13
16
|
};
|
|
14
|
-
}
|
|
15
|
-
|
|
17
|
+
}
|
|
18
|
+
UniwindPluginNext.postcss = true;
|
|
16
19
|
|
|
17
|
-
//#endregion
|
|
20
|
+
//#endregion
|
|
21
|
+
module.exports = UniwindPluginNext;
|
package/dist/postcss/index.d.cts
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/postcss/index.d.ts
|
|
2
|
+
declare function UniwindPluginNext(): {
|
|
3
|
+
postcssPlugin: string;
|
|
4
|
+
Once(root: any): void;
|
|
5
|
+
};
|
|
6
|
+
declare namespace UniwindPluginNext {
|
|
7
|
+
var postcss: boolean;
|
|
8
|
+
}
|
|
9
|
+
export = UniwindPluginNext;
|
|
10
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/postcss/index.ts"],"sourcesContent":[],"mappings":";iBAAwB,iBAAA,CAAA;EAAA,aAAA,EAAA,MAAiB;EAAjB,IAAA,CAAA,IAAA,EAAA,GAAA,CAAA,EAAA,IAAiB;;kBAAjB,iBAAA"}
|
package/dist/postcss/index.d.mts
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/postcss/index.d.ts
|
|
2
|
+
declare function UniwindPluginNext(): {
|
|
3
|
+
postcssPlugin: string;
|
|
4
|
+
Once(root: any): void;
|
|
5
|
+
};
|
|
6
|
+
declare namespace UniwindPluginNext {
|
|
7
|
+
var postcss: boolean;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { UniwindPluginNext as default };
|
|
11
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/postcss/index.ts"],"sourcesContent":[],"mappings":";iBAAwB,iBAAA,CAAA;EAAA,aAAA,EAAA,MAAiB;EAAjB,IAAA,CAAA,IAAA,EAAA,GAAA,CAAA,EAAA,IAAiB;;kBAAjB,iBAAA"}
|
package/dist/postcss/index.mjs
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import { t as __commonJSMin } from "../chunk-3qlvafw2.mjs";
|
|
2
|
-
|
|
3
1
|
//#region src/postcss/index.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
function UniwindPluginNext() {
|
|
3
|
+
return {
|
|
4
|
+
postcssPlugin: "uniwind-plugin-next",
|
|
5
|
+
Once(root) {
|
|
6
|
+
root.walkDecls((decl) => {
|
|
7
|
+
decl.value = decl.value.replace(/pixelRatio\(([^)]+)\)/g, "calc($1 * 1px)");
|
|
8
|
+
decl.value = decl.value.replace(/fontScale\(([^)]+)\)/g, "calc($1 * 1rem)");
|
|
9
|
+
decl.value = decl.value.replace(/hairlineWidth\(\)/g, "1px");
|
|
10
|
+
});
|
|
11
|
+
root.walkAtRules("import", (rule) => {
|
|
12
|
+
if (rule.params.replace(/['"]/g, "") === "uniwind") rule.params = "\"uniwind-plugin-next/css\"";
|
|
13
|
+
});
|
|
14
|
+
}
|
|
16
15
|
};
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
}
|
|
17
|
+
UniwindPluginNext.postcss = true;
|
|
19
18
|
|
|
20
19
|
//#endregion
|
|
21
|
-
export default
|
|
22
|
-
|
|
23
|
-
export { };
|
|
20
|
+
export { UniwindPluginNext as default };
|
|
21
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/postcss/index.ts"],"sourcesContent":["export default function UniwindPluginNext() {\n return {\n postcssPlugin: \"uniwind-plugin-next\",\n Once(root: any) {\n root.walkDecls((decl: any) => {\n // Transform pixelRatio(X) → calc(X * 1px)\n decl.value = decl.value.replace(\n /pixelRatio\\(([^)]+)\\)/g,\n \"calc($1 * 1px)\",\n );\n // Transform fontScale(X) → calc(X * 1rem)\n decl.value = decl.value.replace(\n /fontScale\\(([^)]+)\\)/g,\n \"calc($1 * 1rem)\",\n );\n // Transform hairlineWidth() → 1px\n decl.value = decl.value.replace(/hairlineWidth\\(\\)/g, \"1px\");\n });\n // Replace `@import 'uniwind'` with `@import 'uniwind-plugin-next'`\n root.walkAtRules(\"import\", (rule: any) => {\n const importPath = rule.params.replace(/['\"]/g, \"\");\n\n if (importPath === \"uniwind\") {\n rule.params = '\"uniwind-plugin-next/css\"';\n }\n });\n },\n };\n}\n\nUniwindPluginNext.postcss = true;\n"],"mappings":";AAAA,SAAwB,oBAAoB;AAC1C,QAAO;EACL,eAAe;EACf,KAAK,MAAW;AACd,QAAK,WAAW,SAAc;AAE5B,SAAK,QAAQ,KAAK,MAAM,QACtB,0BACA,iBACD;AAED,SAAK,QAAQ,KAAK,MAAM,QACtB,yBACA,kBACD;AAED,SAAK,QAAQ,KAAK,MAAM,QAAQ,sBAAsB,MAAM;KAC5D;AAEF,QAAK,YAAY,WAAW,SAAc;AAGxC,QAFmB,KAAK,OAAO,QAAQ,SAAS,GAAG,KAEhC,UACjB,MAAK,SAAS;KAEhB;;EAEL;;AAGH,kBAAkB,UAAU"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_common = require('./uniwind/src/utils/common.cjs');
|
|
3
|
+
const require_index = require('./uniwind/src/css/index.cjs');
|
|
4
|
+
const require_buildDtsFile = require('./uniwind/src/utils/buildDtsFile.cjs');
|
|
5
|
+
const require_stringifyThemes = require('./uniwind/src/utils/stringifyThemes.cjs');
|
|
6
|
+
let path = require("path");
|
|
7
|
+
path = require_rolldown_runtime.__toESM(path);
|
|
8
|
+
|
|
9
|
+
//#region src/webpack/UniwindWebpackPlugin.ts
|
|
10
|
+
const dirname = typeof __dirname !== "undefined" ? __dirname : __dirname;
|
|
11
|
+
var UniwindWebpackPlugin = class {
|
|
12
|
+
constructor({ cssEntryFile, extraThemes = [], dtsFile = "uniwind-types.d.ts" }) {
|
|
13
|
+
this.hasRun = false;
|
|
14
|
+
this.themes = require_common.uniq([
|
|
15
|
+
"light",
|
|
16
|
+
"dark",
|
|
17
|
+
...extraThemes ?? []
|
|
18
|
+
]);
|
|
19
|
+
this.dtsFile = dtsFile;
|
|
20
|
+
this.cssEntryFile = cssEntryFile;
|
|
21
|
+
}
|
|
22
|
+
apply(compiler) {
|
|
23
|
+
compiler.hooks.beforeCompile.tapPromise("UniwindWebpackPlugin", async () => {
|
|
24
|
+
if (this.hasRun) return;
|
|
25
|
+
this.hasRun = true;
|
|
26
|
+
await require_index.buildCSS(this.themes, this.cssEntryFile);
|
|
27
|
+
require_buildDtsFile.buildDtsFile(this.dtsFile, require_stringifyThemes.stringifyThemes(this.themes));
|
|
28
|
+
});
|
|
29
|
+
compiler.options.module = compiler.options.module || { rules: [] };
|
|
30
|
+
compiler.options.module.rules.push({
|
|
31
|
+
test: /config\.c?js$/,
|
|
32
|
+
include: /uniwind[\/\\]dist/,
|
|
33
|
+
use: [{
|
|
34
|
+
loader: path.default.resolve(dirname, "configInjectionLoader.js"),
|
|
35
|
+
options: { stringifiedThemes: require_stringifyThemes.stringifyThemes(this.themes) }
|
|
36
|
+
}]
|
|
37
|
+
});
|
|
38
|
+
compiler.options.module.rules.push({
|
|
39
|
+
test: /\.js$/,
|
|
40
|
+
exclude: /index\.js$/,
|
|
41
|
+
include: /uniwind[\/\\]dist[\/\\]module[\/\\]components[\/\\]web/,
|
|
42
|
+
use: [{ loader: path.default.resolve(dirname, "clientDirectiveLoader.js") }]
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
exports.UniwindWebpackPlugin = UniwindWebpackPlugin;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { uniq } from "./uniwind/src/utils/common.mjs";
|
|
2
|
+
import { buildCSS } from "./uniwind/src/css/index.mjs";
|
|
3
|
+
import { buildDtsFile } from "./uniwind/src/utils/buildDtsFile.mjs";
|
|
4
|
+
import { stringifyThemes } from "./uniwind/src/utils/stringifyThemes.mjs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
|
|
7
|
+
//#region src/webpack/UniwindWebpackPlugin.ts
|
|
8
|
+
const dirname = typeof __dirname !== "undefined" ? __dirname : import.meta.dirname;
|
|
9
|
+
var UniwindWebpackPlugin = class {
|
|
10
|
+
constructor({ cssEntryFile, extraThemes = [], dtsFile = "uniwind-types.d.ts" }) {
|
|
11
|
+
this.hasRun = false;
|
|
12
|
+
this.themes = uniq([
|
|
13
|
+
"light",
|
|
14
|
+
"dark",
|
|
15
|
+
...extraThemes ?? []
|
|
16
|
+
]);
|
|
17
|
+
this.dtsFile = dtsFile;
|
|
18
|
+
this.cssEntryFile = cssEntryFile;
|
|
19
|
+
}
|
|
20
|
+
apply(compiler) {
|
|
21
|
+
compiler.hooks.beforeCompile.tapPromise("UniwindWebpackPlugin", async () => {
|
|
22
|
+
if (this.hasRun) return;
|
|
23
|
+
this.hasRun = true;
|
|
24
|
+
await buildCSS(this.themes, this.cssEntryFile);
|
|
25
|
+
buildDtsFile(this.dtsFile, stringifyThemes(this.themes));
|
|
26
|
+
});
|
|
27
|
+
compiler.options.module = compiler.options.module || { rules: [] };
|
|
28
|
+
compiler.options.module.rules.push({
|
|
29
|
+
test: /config\.c?js$/,
|
|
30
|
+
include: /uniwind[\/\\]dist/,
|
|
31
|
+
use: [{
|
|
32
|
+
loader: path.resolve(dirname, "configInjectionLoader.js"),
|
|
33
|
+
options: { stringifiedThemes: stringifyThemes(this.themes) }
|
|
34
|
+
}]
|
|
35
|
+
});
|
|
36
|
+
compiler.options.module.rules.push({
|
|
37
|
+
test: /\.js$/,
|
|
38
|
+
exclude: /index\.js$/,
|
|
39
|
+
include: /uniwind[\/\\]dist[\/\\]module[\/\\]components[\/\\]web/,
|
|
40
|
+
use: [{ loader: path.resolve(dirname, "clientDirectiveLoader.js") }]
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { UniwindWebpackPlugin };
|
|
47
|
+
//# sourceMappingURL=UniwindWebpackPlugin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UniwindWebpackPlugin.mjs","names":[],"sources":["../../src/webpack/UniwindWebpackPlugin.ts"],"sourcesContent":["import { UniwindConfig } from \"./types\";\nimport type { Compiler } from \"webpack\";\nimport path from \"path\";\nimport { uniq } from \"./uniwind/src/utils/common\";\nimport { buildCSS } from \"./uniwind/src/css\";\nimport { buildDtsFile } from \"./uniwind/src/utils/buildDtsFile\";\nimport { stringifyThemes } from \"./uniwind/src/utils/stringifyThemes\";\n\nconst dirname =\n typeof __dirname !== \"undefined\" ? __dirname : import.meta.dirname;\n\nexport class UniwindWebpackPlugin {\n private hasRun = false;\n private readonly themes: string[];\n private readonly dtsFile: string;\n private readonly cssEntryFile: string;\n\n constructor({\n cssEntryFile,\n extraThemes = [],\n dtsFile = \"uniwind-types.d.ts\",\n }: UniwindConfig) {\n this.themes = uniq([\"light\", \"dark\", ...(extraThemes ?? [])]);\n this.dtsFile = dtsFile;\n this.cssEntryFile = cssEntryFile;\n }\n\n apply(compiler: Compiler) {\n compiler.hooks.beforeCompile.tapPromise(\n \"UniwindWebpackPlugin\",\n async () => {\n if (this.hasRun) return;\n this.hasRun = true;\n\n // 1. Generate uniwind.css\n await buildCSS(this.themes, this.cssEntryFile);\n\n // 2. Generate uniwind-types.d.ts\n buildDtsFile(this.dtsFile, stringifyThemes(this.themes));\n },\n );\n\n // Inject the uniwind reinit() call\n compiler.options.module = compiler.options.module || { rules: [] };\n compiler.options.module.rules.push({\n test: /config\\.c?js$/,\n include: /uniwind[\\/\\\\]dist/,\n use: [\n {\n loader: path.resolve(dirname, \"configInjectionLoader.js\"),\n options: {\n stringifiedThemes: stringifyThemes(this.themes),\n },\n },\n ],\n });\n // Add \"use client\" to uniwind web components\n compiler.options.module.rules.push({\n test: /\\.js$/,\n exclude: /index\\.js$/,\n include: /uniwind[\\/\\\\]dist[\\/\\\\]module[\\/\\\\]components[\\/\\\\]web/,\n use: [\n {\n loader: path.resolve(dirname, \"clientDirectiveLoader.js\"),\n },\n ],\n });\n }\n}\n"],"mappings":";;;;;;;AAQA,MAAM,UACJ,OAAO,cAAc,cAAc,YAAY,OAAO,KAAK;AAE7D,IAAa,uBAAb,MAAkC;CAMhC,YAAY,EACV,cACA,cAAc,EAAE,EAChB,UAAU,wBACM;gBATD;AAUf,OAAK,SAAS,KAAK;GAAC;GAAS;GAAQ,GAAI,eAAe,EAAE;GAAE,CAAC;AAC7D,OAAK,UAAU;AACf,OAAK,eAAe;;CAGtB,MAAM,UAAoB;AACxB,WAAS,MAAM,cAAc,WAC3B,wBACA,YAAY;AACV,OAAI,KAAK,OAAQ;AACjB,QAAK,SAAS;AAGd,SAAM,SAAS,KAAK,QAAQ,KAAK,aAAa;AAG9C,gBAAa,KAAK,SAAS,gBAAgB,KAAK,OAAO,CAAC;IAE3D;AAGD,WAAS,QAAQ,SAAS,SAAS,QAAQ,UAAU,EAAE,OAAO,EAAE,EAAE;AAClE,WAAS,QAAQ,OAAO,MAAM,KAAK;GACjC,MAAM;GACN,SAAS;GACT,KAAK,CACH;IACE,QAAQ,KAAK,QAAQ,SAAS,2BAA2B;IACzD,SAAS,EACP,mBAAmB,gBAAgB,KAAK,OAAO,EAChD;IACF,CACF;GACF,CAAC;AAEF,WAAS,QAAQ,OAAO,MAAM,KAAK;GACjC,MAAM;GACN,SAAS;GACT,SAAS;GACT,KAAK,CACH,EACE,QAAQ,KAAK,QAAQ,SAAS,2BAA2B,EAC1D,CACF;GACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../../src/webpack/types.ts"],"sourcesContent":[],"mappings":";KAAY,aAAA;EAAA,YAAA,EAAA,MAAa;gBAET"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/webpack/types.ts"],"sourcesContent":[],"mappings":";KAAY,aAAA;EAAA,YAAA,EAAA,MAAa;gBAET"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.mjs","names":[],"sources":["../../../src/webpack/uniwind/package.json"],"sourcesContent":[""],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_insets = require('./insets.cjs');
|
|
3
|
+
const require_themes = require('./themes.cjs');
|
|
4
|
+
const require_variants = require('./variants.cjs');
|
|
5
|
+
let path = require("path");
|
|
6
|
+
path = require_rolldown_runtime.__toESM(path);
|
|
7
|
+
let fs = require("fs");
|
|
8
|
+
fs = require_rolldown_runtime.__toESM(fs);
|
|
9
|
+
|
|
10
|
+
//#region src/webpack/uniwind/src/css/index.ts
|
|
11
|
+
const dirname = typeof __dirname !== "undefined" ? __dirname : __dirname;
|
|
12
|
+
const buildCSS = async (themes, input) => {
|
|
13
|
+
const variants = require_variants.generateCSSForVariants();
|
|
14
|
+
const insets = require_insets.generateCSSForInsets();
|
|
15
|
+
const themesCSS = await require_themes.generateCSSForThemes(themes, input);
|
|
16
|
+
const cssFile = path.default.join(dirname, "../../uniwind.css");
|
|
17
|
+
if ((fs.default.existsSync(cssFile) ? fs.default.readFileSync(cssFile, "utf-8") : "") === cssFile) return;
|
|
18
|
+
fs.default.writeFileSync(cssFile, [
|
|
19
|
+
variants,
|
|
20
|
+
insets,
|
|
21
|
+
themesCSS
|
|
22
|
+
].join("\n"));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.buildCSS = buildCSS;
|