uniwind-plugin-next 1.1.2 → 1.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 +21 -11
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/index.cjs +8 -365
- package/dist/index.d.cts +6 -9
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +6 -9
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +8 -336
- package/dist/index.mjs.map +1 -0
- 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 +49 -0
- package/dist/webpack/UniwindWebpackPlugin.mjs +48 -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 +28 -0
- package/dist/webpack/uniwind/src/css/index.mjs +26 -0
- package/dist/webpack/uniwind/src/css/index.mjs.map +1 -0
- package/dist/webpack/uniwind/src/css/insets.cjs +87 -0
- package/dist/webpack/uniwind/src/css/insets.mjs +87 -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/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/util.cjs +6 -0
- package/dist/webpack/util.mjs +6 -0
- package/dist/webpack/util.mjs.map +1 -0
- package/dist/webpack/withUniwindBase.cjs +34 -0
- package/dist/webpack/withUniwindBase.mjs +32 -0
- package/dist/webpack/withUniwindBase.mjs.map +1 -0
- package/package.json +27 -8
- package/dist/chunk-3qlvafw2.mjs +0 -8
- package/dist/clientDirectiveLoader.js +0 -8
- package/dist/configInjectionLoader.js +0 -6
package/dist/index.mjs
CHANGED
|
@@ -1,341 +1,13 @@
|
|
|
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 { withUniwindBase } from "./webpack/withUniwindBase.mjs";
|
|
7
2
|
|
|
8
|
-
//#region src/
|
|
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$1 = 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$1, "../../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
|
-
const dirname = typeof __dirname !== "undefined" ? __dirname : import.meta.dirname;
|
|
277
|
-
var UniwindWebpackPlugin = class {
|
|
278
|
-
constructor({ cssEntryFile, extraThemes = [], dtsFile = "uniwind-types.d.ts" }) {
|
|
279
|
-
this.hasRun = false;
|
|
280
|
-
this.themes = uniq([
|
|
281
|
-
"light",
|
|
282
|
-
"dark",
|
|
283
|
-
...extraThemes ?? []
|
|
284
|
-
]);
|
|
285
|
-
this.dtsFile = dtsFile;
|
|
286
|
-
this.cssEntryFile = cssEntryFile;
|
|
287
|
-
}
|
|
288
|
-
apply(compiler) {
|
|
289
|
-
compiler.hooks.beforeCompile.tapPromise("UniwindWebpackPlugin", async () => {
|
|
290
|
-
if (this.hasRun) return;
|
|
291
|
-
this.hasRun = true;
|
|
292
|
-
const removePatch = patchFsForWritingUniwindCSSFile();
|
|
293
|
-
await buildCSS(this.themes, this.cssEntryFile);
|
|
294
|
-
removePatch();
|
|
295
|
-
buildDtsFile(this.dtsFile, stringifyThemes(this.themes));
|
|
296
|
-
});
|
|
297
|
-
compiler.options.module = compiler.options.module || { rules: [] };
|
|
298
|
-
compiler.options.module.rules.push({
|
|
299
|
-
test: /config\.c?js$/,
|
|
300
|
-
include: /uniwind[\/\\]dist/,
|
|
301
|
-
use: [{
|
|
302
|
-
loader: path.resolve(dirname, "configInjectionLoader.js"),
|
|
303
|
-
options: { stringifiedThemes: stringifyThemes(this.themes) }
|
|
304
|
-
}]
|
|
305
|
-
});
|
|
306
|
-
compiler.options.module.rules.push({
|
|
307
|
-
test: /\.js$/,
|
|
308
|
-
exclude: /index\.js$/,
|
|
309
|
-
include: /uniwind[\/\\]dist[\/\\]module[\/\\]components[\/\\]web/,
|
|
310
|
-
use: [{ loader: path.resolve(dirname, "clientDirectiveLoader.js") }]
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
//#endregion
|
|
316
|
-
//#region src/webpack/withUniwind.ts
|
|
317
|
-
const { NormalModuleReplacementPlugin } = webpack;
|
|
3
|
+
//#region src/index.ts
|
|
318
4
|
function withUniwind(nextConfig = {}, uniwindConfig) {
|
|
319
|
-
return
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
"uniwind",
|
|
324
|
-
"react-native",
|
|
325
|
-
"react-native-web"
|
|
326
|
-
]),
|
|
327
|
-
webpack(config, options) {
|
|
328
|
-
if (!config.plugins) config.plugins = [];
|
|
329
|
-
config.plugins.push(new NormalModuleReplacementPlugin(/^react-native$/, (resource) => {
|
|
330
|
-
if ((resource.context || "").includes(`${path.sep}uniwind${path.sep}dist${path.sep}module${path.sep}components${path.sep}web`)) resource.request = "react-native-web";
|
|
331
|
-
else resource.request = "uniwind/components/index";
|
|
332
|
-
}));
|
|
333
|
-
config.plugins.push(new UniwindWebpackPlugin(uniwindConfig));
|
|
334
|
-
if (typeof nextConfig.webpack === "function") return nextConfig.webpack(config, options);
|
|
335
|
-
return config;
|
|
336
|
-
}
|
|
337
|
-
};
|
|
5
|
+
return withUniwindBase("uniwind", nextConfig, uniwindConfig);
|
|
6
|
+
}
|
|
7
|
+
function withUniwindPro(nextConfig = {}, uniwindConfig) {
|
|
8
|
+
return withUniwindBase("uniwind-pro", nextConfig, uniwindConfig);
|
|
338
9
|
}
|
|
339
10
|
|
|
340
11
|
//#endregion
|
|
341
|
-
export { withUniwind };
|
|
12
|
+
export { withUniwind, withUniwindPro };
|
|
13
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { UniwindConfig } from \"./webpack/types\";\nimport { withUniwindBase } from \"./webpack/withUniwindBase\";\n\nexport function withUniwind(\n nextConfig: any = {},\n uniwindConfig: UniwindConfig,\n): any {\n return withUniwindBase(\"uniwind\", nextConfig, uniwindConfig);\n}\n\nexport function withUniwindPro(\n nextConfig: any = {},\n uniwindConfig: UniwindConfig,\n): any {\n return withUniwindBase(\"uniwind-pro\", nextConfig, uniwindConfig);\n}\n"],"mappings":";;;AAGA,SAAgB,YACd,aAAkB,EAAE,EACpB,eACK;AACL,QAAO,gBAAgB,WAAW,YAAY,cAAc;;AAG9D,SAAgB,eACd,aAAkB,EAAE,EACpB,eACK;AACL,QAAO,gBAAgB,eAAe,YAAY,cAAc"}
|
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,49 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_index = require('./uniwind/src/css/index.cjs');
|
|
3
|
+
const require_buildDtsFile = require('./uniwind/src/utils/buildDtsFile.cjs');
|
|
4
|
+
const require_stringifyThemes = require('./uniwind/src/utils/stringifyThemes.cjs');
|
|
5
|
+
const require_util = require('./util.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(packageName, { cssEntryFile, extraThemes = [], dtsFile = "uniwind-types.d.ts" }) {
|
|
13
|
+
this.packageName = packageName;
|
|
14
|
+
this.hasRun = false;
|
|
15
|
+
this.themes = require_util.uniq([
|
|
16
|
+
"light",
|
|
17
|
+
"dark",
|
|
18
|
+
...extraThemes ?? []
|
|
19
|
+
]);
|
|
20
|
+
this.dtsFile = dtsFile;
|
|
21
|
+
this.cssEntryFile = cssEntryFile;
|
|
22
|
+
}
|
|
23
|
+
apply(compiler) {
|
|
24
|
+
compiler.hooks.beforeCompile.tapPromise("UniwindWebpackPlugin", async () => {
|
|
25
|
+
if (this.hasRun) return;
|
|
26
|
+
this.hasRun = true;
|
|
27
|
+
await require_index.buildCSS(this.themes, this.cssEntryFile);
|
|
28
|
+
require_buildDtsFile.buildDtsFile(this.dtsFile, require_stringifyThemes.stringifyThemes(this.themes));
|
|
29
|
+
});
|
|
30
|
+
compiler.options.module = compiler.options.module || { rules: [] };
|
|
31
|
+
compiler.options.module.rules.push({
|
|
32
|
+
test: /config\.c?js$/,
|
|
33
|
+
include: /* @__PURE__ */ new RegExp(`${this.packageName}[\\/\\\\]dist`),
|
|
34
|
+
use: [{
|
|
35
|
+
loader: path.default.resolve(dirname, "configInjectionLoader.js"),
|
|
36
|
+
options: { stringifiedThemes: require_stringifyThemes.stringifyThemes(this.themes) }
|
|
37
|
+
}]
|
|
38
|
+
});
|
|
39
|
+
compiler.options.module.rules.push({
|
|
40
|
+
test: /\.js$/,
|
|
41
|
+
exclude: /index\.js$/,
|
|
42
|
+
include: /* @__PURE__ */ new RegExp(`${this.packageName}[\\/\\\\]dist[\\/\\\\]module[\\/\\\\]components[\\/\\\\]web`),
|
|
43
|
+
use: [{ loader: path.default.resolve(dirname, "clientDirectiveLoader.js") }]
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
exports.UniwindWebpackPlugin = UniwindWebpackPlugin;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { buildCSS } from "./uniwind/src/css/index.mjs";
|
|
2
|
+
import { buildDtsFile } from "./uniwind/src/utils/buildDtsFile.mjs";
|
|
3
|
+
import { stringifyThemes } from "./uniwind/src/utils/stringifyThemes.mjs";
|
|
4
|
+
import { uniq } from "./util.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(packageName, { cssEntryFile, extraThemes = [], dtsFile = "uniwind-types.d.ts" }) {
|
|
11
|
+
this.packageName = packageName;
|
|
12
|
+
this.hasRun = false;
|
|
13
|
+
this.themes = uniq([
|
|
14
|
+
"light",
|
|
15
|
+
"dark",
|
|
16
|
+
...extraThemes ?? []
|
|
17
|
+
]);
|
|
18
|
+
this.dtsFile = dtsFile;
|
|
19
|
+
this.cssEntryFile = cssEntryFile;
|
|
20
|
+
}
|
|
21
|
+
apply(compiler) {
|
|
22
|
+
compiler.hooks.beforeCompile.tapPromise("UniwindWebpackPlugin", async () => {
|
|
23
|
+
if (this.hasRun) return;
|
|
24
|
+
this.hasRun = true;
|
|
25
|
+
await buildCSS(this.themes, this.cssEntryFile);
|
|
26
|
+
buildDtsFile(this.dtsFile, stringifyThemes(this.themes));
|
|
27
|
+
});
|
|
28
|
+
compiler.options.module = compiler.options.module || { rules: [] };
|
|
29
|
+
compiler.options.module.rules.push({
|
|
30
|
+
test: /config\.c?js$/,
|
|
31
|
+
include: /* @__PURE__ */ new RegExp(`${this.packageName}[\\/\\\\]dist`),
|
|
32
|
+
use: [{
|
|
33
|
+
loader: path.resolve(dirname, "configInjectionLoader.js"),
|
|
34
|
+
options: { stringifiedThemes: stringifyThemes(this.themes) }
|
|
35
|
+
}]
|
|
36
|
+
});
|
|
37
|
+
compiler.options.module.rules.push({
|
|
38
|
+
test: /\.js$/,
|
|
39
|
+
exclude: /index\.js$/,
|
|
40
|
+
include: /* @__PURE__ */ new RegExp(`${this.packageName}[\\/\\\\]dist[\\/\\\\]module[\\/\\\\]components[\\/\\\\]web`),
|
|
41
|
+
use: [{ loader: path.resolve(dirname, "clientDirectiveLoader.js") }]
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { UniwindWebpackPlugin };
|
|
48
|
+
//# sourceMappingURL=UniwindWebpackPlugin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UniwindWebpackPlugin.mjs","names":["packageName: uniwindPackageName"],"sources":["../../src/webpack/UniwindWebpackPlugin.ts"],"sourcesContent":["import { UniwindConfig, uniwindPackageName } from \"./types\";\nimport type { Compiler } from \"webpack\";\nimport path from \"path\";\nimport { buildCSS } from \"./uniwind/src/css\";\nimport { buildDtsFile } from \"./uniwind/src/utils/buildDtsFile\";\nimport { stringifyThemes } from \"./uniwind/src/utils/stringifyThemes\";\nimport { uniq } from \"./util\";\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 private readonly packageName: uniwindPackageName,\n {\n cssEntryFile,\n extraThemes = [],\n dtsFile = \"uniwind-types.d.ts\",\n }: UniwindConfig,\n ) {\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: new RegExp(`${this.packageName}[\\\\/\\\\\\\\]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: new RegExp(\n `${this.packageName}[\\\\/\\\\\\\\]dist[\\\\/\\\\\\\\]module[\\\\/\\\\\\\\]components[\\\\/\\\\\\\\]web`,\n ),\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,YACE,AAAiBA,aACjB,EACE,cACA,cAAc,EAAE,EAChB,UAAU,wBAEZ;EANiB;gBANF;AAaf,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,yBAAS,IAAI,OAAO,GAAG,KAAK,YAAY,eAAe;GACvD,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,yBAAS,IAAI,OACX,GAAG,KAAK,YAAY,6DACrB;GACD,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,28 @@
|
|
|
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 cssFilePath = path.default.join(dirname, "../../uniwind.css");
|
|
17
|
+
const oldCSSFile = fs.default.existsSync(cssFilePath) ? fs.default.readFileSync(cssFilePath, "utf-8") : "";
|
|
18
|
+
const newCssFile = [
|
|
19
|
+
variants,
|
|
20
|
+
insets,
|
|
21
|
+
themesCSS
|
|
22
|
+
].join("\n");
|
|
23
|
+
if (oldCSSFile === newCssFile) return;
|
|
24
|
+
fs.default.writeFileSync(cssFilePath, newCssFile);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.buildCSS = buildCSS;
|