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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alexander Nicholson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
> This is an unofficial plugin, and is not affiliated with Uniwind or Next.js.
|
|
4
4
|
|
|
5
|
-
[Uniwind](https://uniwind.dev/) config plugin for Next.js. Note that only Webpack-based projects are supported, there are no plans to support Turbopack-based projects.
|
|
5
|
+
[Uniwind](https://uniwind.dev/) config plugin for Next.js. Note that only Webpack-based projects are supported, there are no plans to support Turbopack-based projects.
|
|
6
|
+
|
|
7
|
+
## Example
|
|
8
|
+
See a fully working example project here: [Demo](http://uniwind-next.a16n.dev/) ([Source](https://github.com/a16n-dev/uniwind-plugin-next/tree/main/examples/next-16))
|
|
6
9
|
|
|
7
|
-
The implementation of this plugin is based on the official [Uniwind Vite plugin](https://docs.uniwind.dev/quickstart#vite), and aims to match its functionality as closely as possible. All Uniwind features should work as expected - see the limitations section below for any documented differences.
|
|
8
10
|
|
|
9
11
|
## Compatibility
|
|
10
12
|
See the table below for tested versions of `uniwind-plugin-next` and corresponding versions of `uniwind`. Other versions of `uniwind` may work, but are not guaranteed to.
|
|
@@ -13,7 +15,8 @@ Tested on Next `16.1`, but other versions will likely work fine.
|
|
|
13
15
|
|
|
14
16
|
| uniwind-plugin-next | Uniwind |
|
|
15
17
|
|---------------------|---------|
|
|
16
|
-
| `1.
|
|
18
|
+
| `1.1.x` | `1.2.2` |
|
|
19
|
+
| `1.2.x` | `1.2.2` |
|
|
17
20
|
|
|
18
21
|
## Installation & setup
|
|
19
22
|
This setup guide assumes you already have a next.js project setup with Tailwind v4
|
|
@@ -47,8 +50,8 @@ export default withUniwind(withExpo(nextConfig), {
|
|
|
47
50
|
```js
|
|
48
51
|
const config = {
|
|
49
52
|
plugins: {
|
|
50
|
-
'@tailwindcss/postcss': {},
|
|
51
53
|
'uniwind-plugin-next/postcss': {}, // Add this line
|
|
54
|
+
'@tailwindcss/postcss': {},
|
|
52
55
|
},
|
|
53
56
|
};
|
|
54
57
|
|
|
@@ -80,8 +83,4 @@ return (
|
|
|
80
83
|
|
|
81
84
|
- Be aware that some Uniwind features, such as `withUniwind` and `useResolveClassNames` will not work in a server environment, as they rely on accessing `window` or `document`.
|
|
82
85
|
|
|
83
|
-
-
|
|
84
|
-
|
|
85
|
-
## Known limitations
|
|
86
|
-
|
|
87
|
-
- This plugin uses a much more primitive regex-based postcss plugin for transforming Uniwind CSS functions (`pixelRatio()`, `fontScale()`, `hairlineWidth()`) compared to the official Vite plugin (which uses a full AST parser). As a result, some edge cases may not be handled correctly. If you do not use these functions in your CSS, this will not impact you. If you do run into any issues, please open an issue.
|
|
86
|
+
- Additional code is required to avoid a flash of unstyled content (FOUC). See the example project for reference.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
|
|
29
|
+
exports.__toESM = __toESM;
|
package/dist/index.cjs
CHANGED
|
@@ -1,369 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
1
|
+
const require_withUniwind = require('./webpack/withUniwind.cjs');
|
|
26
2
|
|
|
27
|
-
|
|
28
|
-
let webpack = require("webpack");
|
|
29
|
-
webpack = __toESM(webpack);
|
|
30
|
-
let path = require("path");
|
|
31
|
-
path = __toESM(path);
|
|
32
|
-
let fs = require("fs");
|
|
33
|
-
fs = __toESM(fs);
|
|
34
|
-
let _tailwindcss_node = require("@tailwindcss/node");
|
|
35
|
-
let lightningcss = require("lightningcss");
|
|
36
|
-
|
|
37
|
-
//#region src/webpack/uniwind/src/utils/common.ts
|
|
38
|
-
const uniq = (arr) => Array.from(new Set(arr));
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/webpack/patchFsForWritingUniwindCSSFile.ts
|
|
42
|
-
const uniwindDir = path.default.dirname(require.resolve("uniwind/package.json"));
|
|
43
|
-
/**
|
|
44
|
-
* The contents of the `css` directory is copied direct from the uniwind source code. This makes it easier to keep it in
|
|
45
|
-
* sync with the upstream uniwind package, so we purposefully avoid modifying any code in `css`.
|
|
46
|
-
*
|
|
47
|
-
* However, we do need to patch `buildCSS()` to output the generated `uniwind.css` file into the `uniwind` package directory
|
|
48
|
-
* within node_modules. To do this we temporarily patch `fs.writeFileSync` to redirect all writes of `uniwind.css` to the
|
|
49
|
-
* correct location.
|
|
50
|
-
*
|
|
51
|
-
* Usage:
|
|
52
|
-
* ```ts
|
|
53
|
-
* const unpatchFs = patchFs();
|
|
54
|
-
* await buildCSS(themes, cssEntryFile);
|
|
55
|
-
* unpatchFs();
|
|
56
|
-
*/
|
|
57
|
-
function patchFsForWritingUniwindCSSFile() {
|
|
58
|
-
const originalWriteFileSync = fs.default.writeFileSync;
|
|
59
|
-
fs.default.writeFileSync = function(_path, data, options) {
|
|
60
|
-
let newPath = _path;
|
|
61
|
-
if (typeof newPath === "string" && newPath.endsWith("uniwind.css")) newPath = path.default.join(uniwindDir, "uniwind.css");
|
|
62
|
-
return originalWriteFileSync.call(fs.default, newPath, data, options);
|
|
63
|
-
};
|
|
64
|
-
return function unpatchFs() {
|
|
65
|
-
fs.default.writeFileSync = originalWriteFileSync;
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
//#endregion
|
|
70
|
-
//#region src/webpack/uniwind/src/css/insets.ts
|
|
71
|
-
const types = ["m", "p"];
|
|
72
|
-
const sides = [
|
|
73
|
-
"",
|
|
74
|
-
"x",
|
|
75
|
-
"y",
|
|
76
|
-
"t",
|
|
77
|
-
"b",
|
|
78
|
-
"l",
|
|
79
|
-
"r"
|
|
80
|
-
];
|
|
81
|
-
const spacing = "--spacing(--value(integer))";
|
|
82
|
-
const length = "--value([length])";
|
|
83
|
-
const generateCSSForInsets = () => {
|
|
84
|
-
let css = `@utility h-screen-safe {
|
|
85
|
-
height: calc(100vh - (env(safe-area-inset-top) + env(safe-area-inset-bottom)));
|
|
86
|
-
}\n`;
|
|
87
|
-
const getInsetsForSide = (side) => {
|
|
88
|
-
switch (side) {
|
|
89
|
-
case "t": return ["top"];
|
|
90
|
-
case "b": return ["bottom"];
|
|
91
|
-
case "l": return ["left"];
|
|
92
|
-
case "r": return ["right"];
|
|
93
|
-
case "x": return ["left", "right"];
|
|
94
|
-
case "y": return ["top", "bottom"];
|
|
95
|
-
default: return [
|
|
96
|
-
"top",
|
|
97
|
-
"bottom",
|
|
98
|
-
"left",
|
|
99
|
-
"right"
|
|
100
|
-
];
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
types.forEach((type) => {
|
|
104
|
-
sides.forEach((side) => {
|
|
105
|
-
const styleName = type === "m" ? "margin" : "padding";
|
|
106
|
-
const styles = getInsetsForSide(side).map((inset) => `${styleName}-${inset}: env(safe-area-inset-${inset});`);
|
|
107
|
-
const safeStyles = styles.flatMap((style) => {
|
|
108
|
-
const styleWithoutSemicolon = style.replace(";", "");
|
|
109
|
-
return [styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: max(${env}, ${spacing});`), styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: max(${env}, ${length});`)];
|
|
110
|
-
});
|
|
111
|
-
const safeOffsetStyles = styles.flatMap((style) => {
|
|
112
|
-
const styleWithoutSemicolon = style.replace(";", "");
|
|
113
|
-
return [styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: calc(${env} + ${spacing});`), styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: calc(${env} + ${length});`)];
|
|
114
|
-
});
|
|
115
|
-
css += `
|
|
116
|
-
@utility ${type}${side}-safe {
|
|
117
|
-
${styles.join("\n ")}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
@utility ${type}${side}-safe-or-* {
|
|
121
|
-
${safeStyles.join("\n ")}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
@utility ${type}${side}-safe-offset-* {
|
|
125
|
-
${safeOffsetStyles.join("\n ")}
|
|
126
|
-
}
|
|
127
|
-
`;
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
return css.replaceAll(" ", "").trim() + "\n";
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
//#endregion
|
|
134
|
-
//#region src/webpack/uniwind/src/metro/logger.ts
|
|
135
|
-
const red = "\x1B[91m";
|
|
136
|
-
const yellow = "\x1B[33m";
|
|
137
|
-
const blue = "\x1B[36m";
|
|
138
|
-
const reset = "\x1B[0m";
|
|
139
|
-
var Logger = class Logger {
|
|
140
|
-
static {
|
|
141
|
-
this.debug = false;
|
|
142
|
-
}
|
|
143
|
-
constructor(name$1) {
|
|
144
|
-
this.name = name$1;
|
|
145
|
-
}
|
|
146
|
-
static log(message, meta = "") {
|
|
147
|
-
if (!Logger.debug) return;
|
|
148
|
-
console.log(`${blue}Uniwind ${meta}- ${message}${reset}`);
|
|
149
|
-
}
|
|
150
|
-
static error(message, meta = "") {
|
|
151
|
-
console.log(`${red}Uniwind Error ${meta}- ${message}${reset}`);
|
|
152
|
-
}
|
|
153
|
-
static warn(message, meta = "") {
|
|
154
|
-
if (!Logger.debug) return;
|
|
155
|
-
console.log(`${yellow}Uniwind Warning ${meta}- ${message}${reset}`);
|
|
156
|
-
}
|
|
157
|
-
log(message) {
|
|
158
|
-
Logger.log(message, `[${this.name} Processor] `);
|
|
159
|
-
}
|
|
160
|
-
error(message) {
|
|
161
|
-
Logger.error(message, `[${this.name} Processor] `);
|
|
162
|
-
}
|
|
163
|
-
warn(message) {
|
|
164
|
-
Logger.warn(message, `[${this.name} Processor] `);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
//#endregion
|
|
169
|
-
//#region src/webpack/uniwind/src/css/themes.ts
|
|
170
|
-
const readFileSafe = (filePath) => {
|
|
171
|
-
try {
|
|
172
|
-
return fs.default.readFileSync(filePath, "utf-8");
|
|
173
|
-
} catch {
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
const isExcludedDependency = (url) => [
|
|
178
|
-
url.includes("node_modules/tailwindcss"),
|
|
179
|
-
url.includes("node_modules/@tailwindcss"),
|
|
180
|
-
url.includes("node_modules/uniwind")
|
|
181
|
-
].some(Boolean);
|
|
182
|
-
const generateCSSForThemes = async (themes, input) => {
|
|
183
|
-
const themesVariables = Object.fromEntries(themes.map((theme) => [theme, /* @__PURE__ */ new Set()]));
|
|
184
|
-
const findVariantsRec = async (cssPath) => {
|
|
185
|
-
const css = readFileSafe(cssPath);
|
|
186
|
-
if (css === null) return;
|
|
187
|
-
const { dependencies } = (0, lightningcss.transform)({
|
|
188
|
-
code: Buffer.from(css),
|
|
189
|
-
filename: "uniwind.css",
|
|
190
|
-
analyzeDependencies: true,
|
|
191
|
-
visitor: { Rule: (rule) => {
|
|
192
|
-
if (rule.type === "unknown" && rule.value.name === "variant") {
|
|
193
|
-
const [firstPrelude] = rule.value.prelude;
|
|
194
|
-
if (firstPrelude?.type !== "token" || firstPrelude.value.type !== "ident" || !themes.includes(firstPrelude.value.value)) return;
|
|
195
|
-
const theme = firstPrelude.value.value;
|
|
196
|
-
rule.value.block?.forEach((block) => {
|
|
197
|
-
if (block.type === "dashed-ident") themesVariables[theme]?.add(block.value);
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
} }
|
|
201
|
-
});
|
|
202
|
-
if (!Array.isArray(dependencies)) return;
|
|
203
|
-
const importUrls = /* @__PURE__ */ new Set();
|
|
204
|
-
await (0, _tailwindcss_node.compile)(dependencies.filter((dependency) => {
|
|
205
|
-
if (dependency.url.startsWith(".")) {
|
|
206
|
-
importUrls.add(path.default.resolve(path.default.dirname(cssPath), dependency.url));
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
return !isExcludedDependency(dependency.url);
|
|
210
|
-
}).map((dependency) => `@import "${dependency.url}";`).join("\n"), {
|
|
211
|
-
base: path.default.resolve(path.default.dirname(cssPath)),
|
|
212
|
-
onDependency: (dependency) => {
|
|
213
|
-
if (isExcludedDependency(dependency)) return;
|
|
214
|
-
importUrls.add(dependency);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
for (const filePath of importUrls) await findVariantsRec(filePath);
|
|
218
|
-
};
|
|
219
|
-
await findVariantsRec(input);
|
|
220
|
-
let hasErrors = false;
|
|
221
|
-
const hasVariables = Object.values(themesVariables).some((variables) => variables.size > 0);
|
|
222
|
-
Object.values(themesVariables).forEach((variables) => {
|
|
223
|
-
Object.entries(themesVariables).forEach(([checkedTheme, checkedVariables]) => {
|
|
224
|
-
variables.forEach((variable) => {
|
|
225
|
-
if (!checkedVariables.has(variable)) {
|
|
226
|
-
Logger.error(`Theme ${checkedTheme} is missing variable ${variable}`);
|
|
227
|
-
hasErrors = true;
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
if (hasErrors) Logger.error("All themes must have the same variables");
|
|
233
|
-
const variablesCSS = hasVariables ? [
|
|
234
|
-
"",
|
|
235
|
-
"@theme {",
|
|
236
|
-
...Array.from(Object.values(themesVariables).at(0) ?? []).map((variable) => ` ${variable}: unset;`),
|
|
237
|
-
"}"
|
|
238
|
-
] : [];
|
|
239
|
-
return [...themes.map((theme) => `@custom-variant ${theme} (&:where(.${theme}, .${theme} *));`), ...variablesCSS].join("\n");
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
//#endregion
|
|
243
|
-
//#region src/webpack/uniwind/src/css/variants.ts
|
|
244
|
-
const variants = [
|
|
245
|
-
"ios",
|
|
246
|
-
"android",
|
|
247
|
-
"web",
|
|
248
|
-
"native"
|
|
249
|
-
];
|
|
250
|
-
const generateCSSForVariants = () => {
|
|
251
|
-
let css = "";
|
|
252
|
-
variants.forEach((variant) => {
|
|
253
|
-
css += `@custom-variant ${variant} (${variant === "web" ? "html &" : `@media ${variant}`});\n`;
|
|
254
|
-
});
|
|
255
|
-
return css;
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
//#endregion
|
|
259
|
-
//#region src/webpack/uniwind/src/css/index.ts
|
|
260
|
-
const dirname = typeof __dirname !== "undefined" ? __dirname : __dirname;
|
|
261
|
-
const buildCSS = async (themes, input) => {
|
|
262
|
-
const variants$1 = generateCSSForVariants();
|
|
263
|
-
const insets = generateCSSForInsets();
|
|
264
|
-
const themesCSS = await generateCSSForThemes(themes, input);
|
|
265
|
-
const cssFile = path.default.join(dirname, "../../uniwind.css");
|
|
266
|
-
if ((fs.default.existsSync(cssFile) ? fs.default.readFileSync(cssFile, "utf-8") : "") === cssFile) return;
|
|
267
|
-
fs.default.writeFileSync(cssFile, [
|
|
268
|
-
variants$1,
|
|
269
|
-
insets,
|
|
270
|
-
themesCSS
|
|
271
|
-
].join("\n"));
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
//#endregion
|
|
275
|
-
//#region src/webpack/uniwind/package.json
|
|
276
|
-
var name = "uniwind";
|
|
277
|
-
|
|
278
|
-
//#endregion
|
|
279
|
-
//#region src/webpack/uniwind/src/utils/buildDtsFile.ts
|
|
280
|
-
const buildDtsFile = (dtsPath, stringifiedThemes) => {
|
|
281
|
-
const oldDtsContent = fs.default.existsSync(dtsPath) ? fs.default.readFileSync(dtsPath, "utf-8") : "";
|
|
282
|
-
const dtsContent = [
|
|
283
|
-
`// NOTE: This file is generated by ${name} and it should not be edited manually.`,
|
|
284
|
-
`/// <reference types="${name}/types" />`,
|
|
285
|
-
"",
|
|
286
|
-
`declare module '${name}' {`,
|
|
287
|
-
` export interface UniwindConfig {`,
|
|
288
|
-
` themes: readonly ${stringifiedThemes}`,
|
|
289
|
-
` }`,
|
|
290
|
-
`}`,
|
|
291
|
-
"",
|
|
292
|
-
`export {}`,
|
|
293
|
-
""
|
|
294
|
-
].join("\n");
|
|
295
|
-
if (oldDtsContent === dtsContent) return;
|
|
296
|
-
fs.default.writeFileSync(dtsPath, dtsContent);
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
//#endregion
|
|
300
|
-
//#region src/webpack/uniwind/src/utils/stringifyThemes.ts
|
|
301
|
-
const stringifyThemes = (themes = []) => `[${themes.map((theme) => `'${theme}'`).join(", ")}]`;
|
|
302
|
-
|
|
303
|
-
//#endregion
|
|
304
|
-
//#region src/webpack/UniwindWebpackPlugin.ts
|
|
305
|
-
var UniwindWebpackPlugin = class {
|
|
306
|
-
constructor({ cssEntryFile, extraThemes = [], dtsFile = "uniwind-types.d.ts" }) {
|
|
307
|
-
this.hasRun = false;
|
|
308
|
-
this.themes = uniq([
|
|
309
|
-
"light",
|
|
310
|
-
"dark",
|
|
311
|
-
...extraThemes ?? []
|
|
312
|
-
]);
|
|
313
|
-
this.dtsFile = dtsFile;
|
|
314
|
-
this.cssEntryFile = cssEntryFile;
|
|
315
|
-
}
|
|
316
|
-
apply(compiler) {
|
|
317
|
-
compiler.hooks.beforeCompile.tapPromise("UniwindWebpackPlugin", async () => {
|
|
318
|
-
if (this.hasRun) return;
|
|
319
|
-
this.hasRun = true;
|
|
320
|
-
const removePatch = patchFsForWritingUniwindCSSFile();
|
|
321
|
-
await buildCSS(this.themes, this.cssEntryFile);
|
|
322
|
-
removePatch();
|
|
323
|
-
buildDtsFile(this.dtsFile, stringifyThemes(this.themes));
|
|
324
|
-
});
|
|
325
|
-
compiler.options.module = compiler.options.module || { rules: [] };
|
|
326
|
-
compiler.options.module.rules.push({
|
|
327
|
-
test: /config\.c?js$/,
|
|
328
|
-
include: /uniwind[\/\\]dist/,
|
|
329
|
-
use: [{
|
|
330
|
-
loader: path.default.resolve(__dirname, "configInjectionLoader.js"),
|
|
331
|
-
options: { stringifiedThemes: stringifyThemes(this.themes) }
|
|
332
|
-
}]
|
|
333
|
-
});
|
|
334
|
-
compiler.options.module.rules.push({
|
|
335
|
-
test: /\.js$/,
|
|
336
|
-
exclude: /index\.js$/,
|
|
337
|
-
include: /uniwind[\/\\]dist[\/\\]module[\/\\]components[\/\\]web/,
|
|
338
|
-
use: [{ loader: path.default.resolve(__dirname, "clientDirectiveLoader.js") }]
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
//#endregion
|
|
344
|
-
//#region src/webpack/withUniwind.ts
|
|
345
|
-
const { NormalModuleReplacementPlugin } = webpack.default;
|
|
346
|
-
function withUniwind(nextConfig = {}, uniwindConfig) {
|
|
347
|
-
return {
|
|
348
|
-
...nextConfig,
|
|
349
|
-
transpilePackages: uniq([
|
|
350
|
-
...nextConfig.transpilePackages || [],
|
|
351
|
-
"uniwind",
|
|
352
|
-
"react-native",
|
|
353
|
-
"react-native-web"
|
|
354
|
-
]),
|
|
355
|
-
webpack(config, options) {
|
|
356
|
-
if (!config.plugins) config.plugins = [];
|
|
357
|
-
config.plugins.push(new NormalModuleReplacementPlugin(/^react-native$/, (resource) => {
|
|
358
|
-
if ((resource.context || "").includes(`${path.default.sep}uniwind${path.default.sep}dist${path.default.sep}module${path.default.sep}components${path.default.sep}web`)) resource.request = "react-native-web";
|
|
359
|
-
else resource.request = "uniwind/components/index";
|
|
360
|
-
}));
|
|
361
|
-
config.plugins.push(new UniwindWebpackPlugin(uniwindConfig));
|
|
362
|
-
if (typeof nextConfig.webpack === "function") return nextConfig.webpack(config, options);
|
|
363
|
-
return config;
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
//#endregion
|
|
369
|
-
exports.withUniwind = withUniwind;
|
|
3
|
+
exports.withUniwind = require_withUniwind.withUniwind;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
type UniwindConfig = {
|
|
3
|
-
cssEntryFile: string;
|
|
4
|
-
extraThemes?: Array<string>;
|
|
5
|
-
dtsFile?: string;
|
|
6
|
-
};
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/webpack/withUniwind.d.ts
|
|
9
|
-
declare function withUniwind(nextConfig: any | undefined, uniwindConfig: UniwindConfig): any;
|
|
10
|
-
//#endregion
|
|
1
|
+
import { withUniwind } from "./webpack/withUniwind.cjs";
|
|
11
2
|
export { withUniwind };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
type UniwindConfig = {
|
|
3
|
-
cssEntryFile: string;
|
|
4
|
-
extraThemes?: Array<string>;
|
|
5
|
-
dtsFile?: string;
|
|
6
|
-
};
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/webpack/withUniwind.d.ts
|
|
9
|
-
declare function withUniwind(nextConfig: any | undefined, uniwindConfig: UniwindConfig): any;
|
|
10
|
-
//#endregion
|
|
1
|
+
import { withUniwind } from "./webpack/withUniwind.mjs";
|
|
11
2
|
export { withUniwind };
|