uniwind-plugin-next 1.1.2 → 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 -369
- package/dist/index.d.cts +1 -10
- package/dist/index.d.mts +1 -10
- package/dist/index.mjs +1 -339
- 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 -8
- package/dist/configInjectionLoader.js +0 -6
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { generateCSSForInsets } from "./insets.mjs";
|
|
2
|
+
import { generateCSSForThemes } from "./themes.mjs";
|
|
3
|
+
import { generateCSSForVariants } from "./variants.mjs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
|
|
7
|
+
//#region src/webpack/uniwind/src/css/index.ts
|
|
8
|
+
const dirname = typeof __dirname !== "undefined" ? __dirname : import.meta.dirname;
|
|
9
|
+
const buildCSS = async (themes, input) => {
|
|
10
|
+
const variants = generateCSSForVariants();
|
|
11
|
+
const insets = generateCSSForInsets();
|
|
12
|
+
const themesCSS = await generateCSSForThemes(themes, input);
|
|
13
|
+
const cssFile = path.join(dirname, "../../uniwind.css");
|
|
14
|
+
if ((fs.existsSync(cssFile) ? fs.readFileSync(cssFile, "utf-8") : "") === cssFile) return;
|
|
15
|
+
fs.writeFileSync(cssFile, [
|
|
16
|
+
variants,
|
|
17
|
+
insets,
|
|
18
|
+
themesCSS
|
|
19
|
+
].join("\n"));
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { buildCSS };
|
|
24
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../../src/webpack/uniwind/src/css/index.ts"],"sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport { generateCSSForInsets } from \"./insets\";\nimport { generateCSSForThemes } from \"./themes\";\nimport { generateCSSForVariants } from \"./variants\";\n\nconst dirname =\n typeof __dirname !== \"undefined\" ? __dirname : import.meta.dirname;\n\nexport const buildCSS = async (themes: Array<string>, input: string) => {\n const variants = generateCSSForVariants();\n const insets = generateCSSForInsets();\n const themesCSS = await generateCSSForThemes(themes, input);\n const cssFile = path.join(dirname, \"../../uniwind.css\");\n const oldCSSFile = fs.existsSync(cssFile)\n ? fs.readFileSync(cssFile, \"utf-8\")\n : \"\";\n\n if (oldCSSFile === cssFile) {\n return;\n }\n\n fs.writeFileSync(cssFile, [variants, insets, themesCSS].join(\"\\n\"));\n};\n"],"mappings":";;;;;;;AAMA,MAAM,UACJ,OAAO,cAAc,cAAc,YAAY,OAAO,KAAK;AAE7D,MAAa,WAAW,OAAO,QAAuB,UAAkB;CACtE,MAAM,WAAW,wBAAwB;CACzC,MAAM,SAAS,sBAAsB;CACrC,MAAM,YAAY,MAAM,qBAAqB,QAAQ,MAAM;CAC3D,MAAM,UAAU,KAAK,KAAK,SAAS,oBAAoB;AAKvD,MAJmB,GAAG,WAAW,QAAQ,GACrC,GAAG,aAAa,SAAS,QAAQ,GACjC,QAEe,QACjB;AAGF,IAAG,cAAc,SAAS;EAAC;EAAU;EAAQ;EAAU,CAAC,KAAK,KAAK,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/webpack/uniwind/src/css/insets.ts
|
|
3
|
+
const types = ["m", "p"];
|
|
4
|
+
const sides = [
|
|
5
|
+
"",
|
|
6
|
+
"x",
|
|
7
|
+
"y",
|
|
8
|
+
"t",
|
|
9
|
+
"b",
|
|
10
|
+
"l",
|
|
11
|
+
"r"
|
|
12
|
+
];
|
|
13
|
+
const spacing = "--spacing(--value(integer))";
|
|
14
|
+
const length = "--value([length])";
|
|
15
|
+
const generateCSSForInsets = () => {
|
|
16
|
+
let css = `@utility h-screen-safe {
|
|
17
|
+
height: calc(100vh - (env(safe-area-inset-top) + env(safe-area-inset-bottom)));
|
|
18
|
+
}\n`;
|
|
19
|
+
const getInsetsForSide = (side) => {
|
|
20
|
+
switch (side) {
|
|
21
|
+
case "t": return ["top"];
|
|
22
|
+
case "b": return ["bottom"];
|
|
23
|
+
case "l": return ["left"];
|
|
24
|
+
case "r": return ["right"];
|
|
25
|
+
case "x": return ["left", "right"];
|
|
26
|
+
case "y": return ["top", "bottom"];
|
|
27
|
+
default: return [
|
|
28
|
+
"top",
|
|
29
|
+
"bottom",
|
|
30
|
+
"left",
|
|
31
|
+
"right"
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
types.forEach((type) => {
|
|
36
|
+
sides.forEach((side) => {
|
|
37
|
+
const styleName = type === "m" ? "margin" : "padding";
|
|
38
|
+
const styles = getInsetsForSide(side).map((inset) => `${styleName}-${inset}: env(safe-area-inset-${inset});`);
|
|
39
|
+
const safeStyles = styles.flatMap((style) => {
|
|
40
|
+
const styleWithoutSemicolon = style.replace(";", "");
|
|
41
|
+
return [styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: max(${env}, ${spacing});`), styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: max(${env}, ${length});`)];
|
|
42
|
+
});
|
|
43
|
+
const safeOffsetStyles = styles.flatMap((style) => {
|
|
44
|
+
const styleWithoutSemicolon = style.replace(";", "");
|
|
45
|
+
return [styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: calc(${env} + ${spacing});`), styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: calc(${env} + ${length});`)];
|
|
46
|
+
});
|
|
47
|
+
css += `
|
|
48
|
+
@utility ${type}${side}-safe {
|
|
49
|
+
${styles.join("\n ")}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@utility ${type}${side}-safe-or-* {
|
|
53
|
+
${safeStyles.join("\n ")}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@utility ${type}${side}-safe-offset-* {
|
|
57
|
+
${safeOffsetStyles.join("\n ")}
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
return css.replaceAll(" ", "").trim() + "\n";
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
exports.generateCSSForInsets = generateCSSForInsets;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//#region src/webpack/uniwind/src/css/insets.ts
|
|
2
|
+
const types = ["m", "p"];
|
|
3
|
+
const sides = [
|
|
4
|
+
"",
|
|
5
|
+
"x",
|
|
6
|
+
"y",
|
|
7
|
+
"t",
|
|
8
|
+
"b",
|
|
9
|
+
"l",
|
|
10
|
+
"r"
|
|
11
|
+
];
|
|
12
|
+
const spacing = "--spacing(--value(integer))";
|
|
13
|
+
const length = "--value([length])";
|
|
14
|
+
const generateCSSForInsets = () => {
|
|
15
|
+
let css = `@utility h-screen-safe {
|
|
16
|
+
height: calc(100vh - (env(safe-area-inset-top) + env(safe-area-inset-bottom)));
|
|
17
|
+
}\n`;
|
|
18
|
+
const getInsetsForSide = (side) => {
|
|
19
|
+
switch (side) {
|
|
20
|
+
case "t": return ["top"];
|
|
21
|
+
case "b": return ["bottom"];
|
|
22
|
+
case "l": return ["left"];
|
|
23
|
+
case "r": return ["right"];
|
|
24
|
+
case "x": return ["left", "right"];
|
|
25
|
+
case "y": return ["top", "bottom"];
|
|
26
|
+
default: return [
|
|
27
|
+
"top",
|
|
28
|
+
"bottom",
|
|
29
|
+
"left",
|
|
30
|
+
"right"
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
types.forEach((type) => {
|
|
35
|
+
sides.forEach((side) => {
|
|
36
|
+
const styleName = type === "m" ? "margin" : "padding";
|
|
37
|
+
const styles = getInsetsForSide(side).map((inset) => `${styleName}-${inset}: env(safe-area-inset-${inset});`);
|
|
38
|
+
const safeStyles = styles.flatMap((style) => {
|
|
39
|
+
const styleWithoutSemicolon = style.replace(";", "");
|
|
40
|
+
return [styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: max(${env}, ${spacing});`), styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: max(${env}, ${length});`)];
|
|
41
|
+
});
|
|
42
|
+
const safeOffsetStyles = styles.flatMap((style) => {
|
|
43
|
+
const styleWithoutSemicolon = style.replace(";", "");
|
|
44
|
+
return [styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: calc(${env} + ${spacing});`), styleWithoutSemicolon.replace(/: (env.*)/, (_, env) => `: calc(${env} + ${length});`)];
|
|
45
|
+
});
|
|
46
|
+
css += `
|
|
47
|
+
@utility ${type}${side}-safe {
|
|
48
|
+
${styles.join("\n ")}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@utility ${type}${side}-safe-or-* {
|
|
52
|
+
${safeStyles.join("\n ")}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@utility ${type}${side}-safe-offset-* {
|
|
56
|
+
${safeOffsetStyles.join("\n ")}
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
return css.replaceAll(" ", "").trim() + "\n";
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
export { generateCSSForInsets };
|
|
66
|
+
//# sourceMappingURL=insets.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insets.mjs","names":[],"sources":["../../../../../src/webpack/uniwind/src/css/insets.ts"],"sourcesContent":["const types = [\"m\", \"p\"] as const;\nconst sides = [\"\", \"x\", \"y\", \"t\", \"b\", \"l\", \"r\"] as const;\nconst spacing = \"--spacing(--value(integer))\";\nconst length = \"--value([length])\";\n\ntype Side = (typeof sides)[number];\n\nexport const generateCSSForInsets = () => {\n let css = `@utility h-screen-safe {\n height: calc(100vh - (env(safe-area-inset-top) + env(safe-area-inset-bottom)));\n}\\n`;\n\n const getInsetsForSide = (side: Side) => {\n switch (side) {\n case \"t\":\n return [\"top\"];\n case \"b\":\n return [\"bottom\"];\n case \"l\":\n return [\"left\"];\n case \"r\":\n return [\"right\"];\n case \"x\":\n return [\"left\", \"right\"];\n case \"y\":\n return [\"top\", \"bottom\"];\n default:\n return [\"top\", \"bottom\", \"left\", \"right\"];\n }\n };\n\n types.forEach((type) => {\n sides.forEach((side) => {\n const styleName = type === \"m\" ? \"margin\" : \"padding\";\n const insets = getInsetsForSide(side);\n const styles = insets.map(\n (inset) => `${styleName}-${inset}: env(safe-area-inset-${inset});`,\n );\n const safeStyles = styles.flatMap((style) => {\n const styleWithoutSemicolon = style.replace(\";\", \"\");\n\n return [\n styleWithoutSemicolon.replace(\n /: (env.*)/,\n (_, env) => `: max(${env}, ${spacing});`,\n ),\n styleWithoutSemicolon.replace(\n /: (env.*)/,\n (_, env) => `: max(${env}, ${length});`,\n ),\n ];\n });\n const safeOffsetStyles = styles.flatMap((style) => {\n const styleWithoutSemicolon = style.replace(\";\", \"\");\n\n return [\n styleWithoutSemicolon.replace(\n /: (env.*)/,\n (_, env) => `: calc(${env} + ${spacing});`,\n ),\n styleWithoutSemicolon.replace(\n /: (env.*)/,\n (_, env) => `: calc(${env} + ${length});`,\n ),\n ];\n });\n\n css += `\n @utility ${type}${side}-safe {\n ${styles.join(\"\\n \")}\n }\n \n @utility ${type}${side}-safe-or-* {\n ${safeStyles.join(\"\\n \")}\n }\n \n @utility ${type}${side}-safe-offset-* {\n ${safeOffsetStyles.join(\"\\n \")}\n }\n `;\n });\n });\n\n // Remove all 8 spaces groups\n // eslint-disable-next-line prefer-template\n return css.replaceAll(\" \", \"\").trim() + \"\\n\";\n};\n"],"mappings":";AAAA,MAAM,QAAQ,CAAC,KAAK,IAAI;AACxB,MAAM,QAAQ;CAAC;CAAI;CAAK;CAAK;CAAK;CAAK;CAAK;CAAI;AAChD,MAAM,UAAU;AAChB,MAAM,SAAS;AAIf,MAAa,6BAA6B;CACxC,IAAI,MAAM;;;CAIV,MAAM,oBAAoB,SAAe;AACvC,UAAQ,MAAR;GACE,KAAK,IACH,QAAO,CAAC,MAAM;GAChB,KAAK,IACH,QAAO,CAAC,SAAS;GACnB,KAAK,IACH,QAAO,CAAC,OAAO;GACjB,KAAK,IACH,QAAO,CAAC,QAAQ;GAClB,KAAK,IACH,QAAO,CAAC,QAAQ,QAAQ;GAC1B,KAAK,IACH,QAAO,CAAC,OAAO,SAAS;GAC1B,QACE,QAAO;IAAC;IAAO;IAAU;IAAQ;IAAQ;;;AAI/C,OAAM,SAAS,SAAS;AACtB,QAAM,SAAS,SAAS;GACtB,MAAM,YAAY,SAAS,MAAM,WAAW;GAE5C,MAAM,SADS,iBAAiB,KAAK,CACf,KACnB,UAAU,GAAG,UAAU,GAAG,MAAM,wBAAwB,MAAM,IAChE;GACD,MAAM,aAAa,OAAO,SAAS,UAAU;IAC3C,MAAM,wBAAwB,MAAM,QAAQ,KAAK,GAAG;AAEpD,WAAO,CACL,sBAAsB,QACpB,cACC,GAAG,QAAQ,SAAS,IAAI,IAAI,QAAQ,IACtC,EACD,sBAAsB,QACpB,cACC,GAAG,QAAQ,SAAS,IAAI,IAAI,OAAO,IACrC,CACF;KACD;GACF,MAAM,mBAAmB,OAAO,SAAS,UAAU;IACjD,MAAM,wBAAwB,MAAM,QAAQ,KAAK,GAAG;AAEpD,WAAO,CACL,sBAAsB,QACpB,cACC,GAAG,QAAQ,UAAU,IAAI,KAAK,QAAQ,IACxC,EACD,sBAAsB,QACpB,cACC,GAAG,QAAQ,UAAU,IAAI,KAAK,OAAO,IACvC,CACF;KACD;AAEF,UAAO;2BACc,OAAO,KAAK;sBACjB,OAAO,KAAK,SAAS,CAAC;;;2BAGjB,OAAO,KAAK;sBACjB,WAAW,KAAK,SAAS,CAAC;;;2BAGrB,OAAO,KAAK;sBACjB,iBAAiB,KAAK,SAAS,CAAC;;;IAGhD;GACF;AAIF,QAAO,IAAI,WAAW,YAAY,GAAG,CAAC,MAAM,GAAG"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_logger = require('../metro/logger.cjs');
|
|
3
|
+
let path = require("path");
|
|
4
|
+
path = require_rolldown_runtime.__toESM(path);
|
|
5
|
+
let fs = require("fs");
|
|
6
|
+
fs = require_rolldown_runtime.__toESM(fs);
|
|
7
|
+
let _tailwindcss_node = require("@tailwindcss/node");
|
|
8
|
+
let lightningcss = require("lightningcss");
|
|
9
|
+
|
|
10
|
+
//#region src/webpack/uniwind/src/css/themes.ts
|
|
11
|
+
const readFileSafe = (filePath) => {
|
|
12
|
+
try {
|
|
13
|
+
return fs.default.readFileSync(filePath, "utf-8");
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const isExcludedDependency = (url) => [
|
|
19
|
+
url.includes("node_modules/tailwindcss"),
|
|
20
|
+
url.includes("node_modules/@tailwindcss"),
|
|
21
|
+
url.includes("node_modules/uniwind")
|
|
22
|
+
].some(Boolean);
|
|
23
|
+
const generateCSSForThemes = async (themes, input) => {
|
|
24
|
+
const themesVariables = Object.fromEntries(themes.map((theme) => [theme, /* @__PURE__ */ new Set()]));
|
|
25
|
+
const findVariantsRec = async (cssPath) => {
|
|
26
|
+
const css = readFileSafe(cssPath);
|
|
27
|
+
if (css === null) return;
|
|
28
|
+
const { dependencies } = (0, lightningcss.transform)({
|
|
29
|
+
code: Buffer.from(css),
|
|
30
|
+
filename: "uniwind.css",
|
|
31
|
+
analyzeDependencies: true,
|
|
32
|
+
visitor: { Rule: (rule) => {
|
|
33
|
+
if (rule.type === "unknown" && rule.value.name === "variant") {
|
|
34
|
+
const [firstPrelude] = rule.value.prelude;
|
|
35
|
+
if (firstPrelude?.type !== "token" || firstPrelude.value.type !== "ident" || !themes.includes(firstPrelude.value.value)) return;
|
|
36
|
+
const theme = firstPrelude.value.value;
|
|
37
|
+
rule.value.block?.forEach((block) => {
|
|
38
|
+
if (block.type === "dashed-ident") themesVariables[theme]?.add(block.value);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
} }
|
|
42
|
+
});
|
|
43
|
+
if (!Array.isArray(dependencies)) return;
|
|
44
|
+
const importUrls = /* @__PURE__ */ new Set();
|
|
45
|
+
await (0, _tailwindcss_node.compile)(dependencies.filter((dependency) => {
|
|
46
|
+
if (dependency.url.startsWith(".")) {
|
|
47
|
+
importUrls.add(path.default.resolve(path.default.dirname(cssPath), dependency.url));
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return !isExcludedDependency(dependency.url);
|
|
51
|
+
}).map((dependency) => `@import "${dependency.url}";`).join("\n"), {
|
|
52
|
+
base: path.default.resolve(path.default.dirname(cssPath)),
|
|
53
|
+
onDependency: (dependency) => {
|
|
54
|
+
if (isExcludedDependency(dependency)) return;
|
|
55
|
+
importUrls.add(dependency);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
for (const filePath of importUrls) await findVariantsRec(filePath);
|
|
59
|
+
};
|
|
60
|
+
await findVariantsRec(input);
|
|
61
|
+
let hasErrors = false;
|
|
62
|
+
const hasVariables = Object.values(themesVariables).some((variables) => variables.size > 0);
|
|
63
|
+
Object.values(themesVariables).forEach((variables) => {
|
|
64
|
+
Object.entries(themesVariables).forEach(([checkedTheme, checkedVariables]) => {
|
|
65
|
+
variables.forEach((variable) => {
|
|
66
|
+
if (!checkedVariables.has(variable)) {
|
|
67
|
+
require_logger.Logger.error(`Theme ${checkedTheme} is missing variable ${variable}`);
|
|
68
|
+
hasErrors = true;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
if (hasErrors) require_logger.Logger.error("All themes must have the same variables");
|
|
74
|
+
const variablesCSS = hasVariables ? [
|
|
75
|
+
"",
|
|
76
|
+
"@theme {",
|
|
77
|
+
...Array.from(Object.values(themesVariables).at(0) ?? []).map((variable) => ` ${variable}: unset;`),
|
|
78
|
+
"}"
|
|
79
|
+
] : [];
|
|
80
|
+
return [...themes.map((theme) => `@custom-variant ${theme} (&:where(.${theme}, .${theme} *));`), ...variablesCSS].join("\n");
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
exports.generateCSSForThemes = generateCSSForThemes;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Logger } from "../metro/logger.mjs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import { compile } from "@tailwindcss/node";
|
|
5
|
+
import { transform } from "lightningcss";
|
|
6
|
+
|
|
7
|
+
//#region src/webpack/uniwind/src/css/themes.ts
|
|
8
|
+
const readFileSafe = (filePath) => {
|
|
9
|
+
try {
|
|
10
|
+
return fs.readFileSync(filePath, "utf-8");
|
|
11
|
+
} catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const isExcludedDependency = (url) => [
|
|
16
|
+
url.includes("node_modules/tailwindcss"),
|
|
17
|
+
url.includes("node_modules/@tailwindcss"),
|
|
18
|
+
url.includes("node_modules/uniwind")
|
|
19
|
+
].some(Boolean);
|
|
20
|
+
const generateCSSForThemes = async (themes, input) => {
|
|
21
|
+
const themesVariables = Object.fromEntries(themes.map((theme) => [theme, /* @__PURE__ */ new Set()]));
|
|
22
|
+
const findVariantsRec = async (cssPath) => {
|
|
23
|
+
const css = readFileSafe(cssPath);
|
|
24
|
+
if (css === null) return;
|
|
25
|
+
const { dependencies } = transform({
|
|
26
|
+
code: Buffer.from(css),
|
|
27
|
+
filename: "uniwind.css",
|
|
28
|
+
analyzeDependencies: true,
|
|
29
|
+
visitor: { Rule: (rule) => {
|
|
30
|
+
if (rule.type === "unknown" && rule.value.name === "variant") {
|
|
31
|
+
const [firstPrelude] = rule.value.prelude;
|
|
32
|
+
if (firstPrelude?.type !== "token" || firstPrelude.value.type !== "ident" || !themes.includes(firstPrelude.value.value)) return;
|
|
33
|
+
const theme = firstPrelude.value.value;
|
|
34
|
+
rule.value.block?.forEach((block) => {
|
|
35
|
+
if (block.type === "dashed-ident") themesVariables[theme]?.add(block.value);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
} }
|
|
39
|
+
});
|
|
40
|
+
if (!Array.isArray(dependencies)) return;
|
|
41
|
+
const importUrls = /* @__PURE__ */ new Set();
|
|
42
|
+
await compile(dependencies.filter((dependency) => {
|
|
43
|
+
if (dependency.url.startsWith(".")) {
|
|
44
|
+
importUrls.add(path.resolve(path.dirname(cssPath), dependency.url));
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return !isExcludedDependency(dependency.url);
|
|
48
|
+
}).map((dependency) => `@import "${dependency.url}";`).join("\n"), {
|
|
49
|
+
base: path.resolve(path.dirname(cssPath)),
|
|
50
|
+
onDependency: (dependency) => {
|
|
51
|
+
if (isExcludedDependency(dependency)) return;
|
|
52
|
+
importUrls.add(dependency);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
for (const filePath of importUrls) await findVariantsRec(filePath);
|
|
56
|
+
};
|
|
57
|
+
await findVariantsRec(input);
|
|
58
|
+
let hasErrors = false;
|
|
59
|
+
const hasVariables = Object.values(themesVariables).some((variables) => variables.size > 0);
|
|
60
|
+
Object.values(themesVariables).forEach((variables) => {
|
|
61
|
+
Object.entries(themesVariables).forEach(([checkedTheme, checkedVariables]) => {
|
|
62
|
+
variables.forEach((variable) => {
|
|
63
|
+
if (!checkedVariables.has(variable)) {
|
|
64
|
+
Logger.error(`Theme ${checkedTheme} is missing variable ${variable}`);
|
|
65
|
+
hasErrors = true;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
if (hasErrors) Logger.error("All themes must have the same variables");
|
|
71
|
+
const variablesCSS = hasVariables ? [
|
|
72
|
+
"",
|
|
73
|
+
"@theme {",
|
|
74
|
+
...Array.from(Object.values(themesVariables).at(0) ?? []).map((variable) => ` ${variable}: unset;`),
|
|
75
|
+
"}"
|
|
76
|
+
] : [];
|
|
77
|
+
return [...themes.map((theme) => `@custom-variant ${theme} (&:where(.${theme}, .${theme} *));`), ...variablesCSS].join("\n");
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { generateCSSForThemes };
|
|
82
|
+
//# sourceMappingURL=themes.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"themes.mjs","names":[],"sources":["../../../../../src/webpack/uniwind/src/css/themes.ts"],"sourcesContent":["import { compile } from \"@tailwindcss/node\";\nimport fs from \"fs\";\nimport { transform } from \"lightningcss\";\nimport path from \"path\";\nimport { Logger } from \"../metro/logger\";\n\nconst readFileSafe = (filePath: string) => {\n try {\n return fs.readFileSync(filePath, \"utf-8\");\n } catch {\n return null;\n }\n};\n\nconst isExcludedDependency = (url: string) =>\n [\n url.includes(\"node_modules/tailwindcss\"),\n url.includes(\"node_modules/@tailwindcss\"),\n url.includes(\"node_modules/uniwind\"),\n ].some(Boolean);\n\nexport const generateCSSForThemes = async (\n themes: Array<string>,\n input: string,\n) => {\n // css generation\n const themesVariables = Object.fromEntries(\n themes.map((theme) => [theme, new Set<string>()]),\n );\n\n const findVariantsRec = async (cssPath: string) => {\n const css = readFileSafe(cssPath);\n\n if (css === null) {\n return;\n }\n\n const { dependencies } = transform({\n code: Buffer.from(css),\n filename: \"uniwind.css\",\n analyzeDependencies: true,\n visitor: {\n Rule: (rule) => {\n if (rule.type === \"unknown\" && rule.value.name === \"variant\") {\n const [firstPrelude] = rule.value.prelude;\n\n if (\n firstPrelude?.type !== \"token\" ||\n firstPrelude.value.type !== \"ident\" ||\n !themes.includes(firstPrelude.value.value)\n ) {\n return;\n }\n\n const theme = firstPrelude.value.value;\n\n rule.value.block?.forEach((block) => {\n if (block.type === \"dashed-ident\") {\n themesVariables[theme]?.add(block.value);\n }\n });\n }\n },\n },\n });\n\n if (!Array.isArray(dependencies)) {\n return;\n }\n\n const importUrls = new Set<string>();\n const importsCSS = dependencies\n .filter((dependency) => {\n if (dependency.url.startsWith(\".\")) {\n importUrls.add(path.resolve(path.dirname(cssPath), dependency.url));\n\n return false;\n }\n\n return !isExcludedDependency(dependency.url);\n })\n .map((dependency) => `@import \"${dependency.url}\";`)\n .join(\"\\n\");\n\n await compile(importsCSS, {\n base: path.resolve(path.dirname(cssPath)),\n onDependency: (dependency) => {\n if (isExcludedDependency(dependency)) {\n return;\n }\n\n importUrls.add(dependency);\n },\n });\n\n for (const filePath of importUrls) {\n await findVariantsRec(filePath);\n }\n };\n\n await findVariantsRec(input);\n\n // Check if all themes have the same variables\n let hasErrors = false as boolean;\n const hasVariables = Object.values(themesVariables).some(\n (variables) => variables.size > 0,\n );\n\n Object.values(themesVariables).forEach((variables) => {\n Object.entries(themesVariables).forEach(\n ([checkedTheme, checkedVariables]) => {\n variables.forEach((variable) => {\n if (!checkedVariables.has(variable)) {\n Logger.error(\n `Theme ${checkedTheme} is missing variable ${variable}`,\n );\n hasErrors = true;\n }\n });\n },\n );\n });\n\n if (hasErrors) {\n Logger.error(\"All themes must have the same variables\");\n }\n\n const variablesCSS = hasVariables\n ? [\n \"\",\n \"@theme {\",\n ...Array.from(Object.values(themesVariables).at(0) ?? []).map(\n (variable) => ` ${variable}: unset;`,\n ),\n \"}\",\n ]\n : [];\n const uniwindCSS = [\n ...themes.map(\n (theme) => `@custom-variant ${theme} (&:where(.${theme}, .${theme} *));`,\n ),\n ...variablesCSS,\n ].join(\"\\n\");\n\n return uniwindCSS;\n};\n"],"mappings":";;;;;;;AAMA,MAAM,gBAAgB,aAAqB;AACzC,KAAI;AACF,SAAO,GAAG,aAAa,UAAU,QAAQ;SACnC;AACN,SAAO;;;AAIX,MAAM,wBAAwB,QAC5B;CACE,IAAI,SAAS,2BAA2B;CACxC,IAAI,SAAS,4BAA4B;CACzC,IAAI,SAAS,uBAAuB;CACrC,CAAC,KAAK,QAAQ;AAEjB,MAAa,uBAAuB,OAClC,QACA,UACG;CAEH,MAAM,kBAAkB,OAAO,YAC7B,OAAO,KAAK,UAAU,CAAC,uBAAO,IAAI,KAAa,CAAC,CAAC,CAClD;CAED,MAAM,kBAAkB,OAAO,YAAoB;EACjD,MAAM,MAAM,aAAa,QAAQ;AAEjC,MAAI,QAAQ,KACV;EAGF,MAAM,EAAE,iBAAiB,UAAU;GACjC,MAAM,OAAO,KAAK,IAAI;GACtB,UAAU;GACV,qBAAqB;GACrB,SAAS,EACP,OAAO,SAAS;AACd,QAAI,KAAK,SAAS,aAAa,KAAK,MAAM,SAAS,WAAW;KAC5D,MAAM,CAAC,gBAAgB,KAAK,MAAM;AAElC,SACE,cAAc,SAAS,WACvB,aAAa,MAAM,SAAS,WAC5B,CAAC,OAAO,SAAS,aAAa,MAAM,MAAM,CAE1C;KAGF,MAAM,QAAQ,aAAa,MAAM;AAEjC,UAAK,MAAM,OAAO,SAAS,UAAU;AACnC,UAAI,MAAM,SAAS,eACjB,iBAAgB,QAAQ,IAAI,MAAM,MAAM;OAE1C;;MAGP;GACF,CAAC;AAEF,MAAI,CAAC,MAAM,QAAQ,aAAa,CAC9B;EAGF,MAAM,6BAAa,IAAI,KAAa;AAcpC,QAAM,QAba,aAChB,QAAQ,eAAe;AACtB,OAAI,WAAW,IAAI,WAAW,IAAI,EAAE;AAClC,eAAW,IAAI,KAAK,QAAQ,KAAK,QAAQ,QAAQ,EAAE,WAAW,IAAI,CAAC;AAEnE,WAAO;;AAGT,UAAO,CAAC,qBAAqB,WAAW,IAAI;IAC5C,CACD,KAAK,eAAe,YAAY,WAAW,IAAI,IAAI,CACnD,KAAK,KAAK,EAEa;GACxB,MAAM,KAAK,QAAQ,KAAK,QAAQ,QAAQ,CAAC;GACzC,eAAe,eAAe;AAC5B,QAAI,qBAAqB,WAAW,CAClC;AAGF,eAAW,IAAI,WAAW;;GAE7B,CAAC;AAEF,OAAK,MAAM,YAAY,WACrB,OAAM,gBAAgB,SAAS;;AAInC,OAAM,gBAAgB,MAAM;CAG5B,IAAI,YAAY;CAChB,MAAM,eAAe,OAAO,OAAO,gBAAgB,CAAC,MACjD,cAAc,UAAU,OAAO,EACjC;AAED,QAAO,OAAO,gBAAgB,CAAC,SAAS,cAAc;AACpD,SAAO,QAAQ,gBAAgB,CAAC,SAC7B,CAAC,cAAc,sBAAsB;AACpC,aAAU,SAAS,aAAa;AAC9B,QAAI,CAAC,iBAAiB,IAAI,SAAS,EAAE;AACnC,YAAO,MACL,SAAS,aAAa,uBAAuB,WAC9C;AACD,iBAAY;;KAEd;IAEL;GACD;AAEF,KAAI,UACF,QAAO,MAAM,0CAA0C;CAGzD,MAAM,eAAe,eACjB;EACE;EACA;EACA,GAAG,MAAM,KAAK,OAAO,OAAO,gBAAgB,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,KACvD,aAAa,OAAO,SAAS,UAC/B;EACD;EACD,GACD,EAAE;AAQN,QAPmB,CACjB,GAAG,OAAO,KACP,UAAU,mBAAmB,MAAM,aAAa,MAAM,KAAK,MAAM,OACnE,EACD,GAAG,aACJ,CAAC,KAAK,KAAK"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/webpack/uniwind/src/css/variants.ts
|
|
3
|
+
const variants = [
|
|
4
|
+
"ios",
|
|
5
|
+
"android",
|
|
6
|
+
"web",
|
|
7
|
+
"native"
|
|
8
|
+
];
|
|
9
|
+
const generateCSSForVariants = () => {
|
|
10
|
+
let css = "";
|
|
11
|
+
variants.forEach((variant) => {
|
|
12
|
+
css += `@custom-variant ${variant} (${variant === "web" ? "html &" : `@media ${variant}`});\n`;
|
|
13
|
+
});
|
|
14
|
+
return css;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.generateCSSForVariants = generateCSSForVariants;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/webpack/uniwind/src/css/variants.ts
|
|
2
|
+
const variants = [
|
|
3
|
+
"ios",
|
|
4
|
+
"android",
|
|
5
|
+
"web",
|
|
6
|
+
"native"
|
|
7
|
+
];
|
|
8
|
+
const generateCSSForVariants = () => {
|
|
9
|
+
let css = "";
|
|
10
|
+
variants.forEach((variant) => {
|
|
11
|
+
css += `@custom-variant ${variant} (${variant === "web" ? "html &" : `@media ${variant}`});\n`;
|
|
12
|
+
});
|
|
13
|
+
return css;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { generateCSSForVariants };
|
|
18
|
+
//# sourceMappingURL=variants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variants.mjs","names":[],"sources":["../../../../../src/webpack/uniwind/src/css/variants.ts"],"sourcesContent":["const variants = [\"ios\", \"android\", \"web\", \"native\"];\n\nexport const generateCSSForVariants = () => {\n let css = \"\";\n\n variants.forEach((variant) => {\n css += `@custom-variant ${variant} (${variant === \"web\" ? \"html &\" : `@media ${variant}`});\\n`;\n });\n\n return css;\n};\n"],"mappings":";AAAA,MAAM,WAAW;CAAC;CAAO;CAAW;CAAO;CAAS;AAEpD,MAAa,+BAA+B;CAC1C,IAAI,MAAM;AAEV,UAAS,SAAS,YAAY;AAC5B,SAAO,mBAAmB,QAAQ,IAAI,YAAY,QAAQ,WAAW,UAAU,UAAU;GACzF;AAEF,QAAO"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/webpack/uniwind/src/metro/logger.ts
|
|
3
|
+
const red = "\x1B[91m";
|
|
4
|
+
const yellow = "\x1B[33m";
|
|
5
|
+
const blue = "\x1B[36m";
|
|
6
|
+
const reset = "\x1B[0m";
|
|
7
|
+
var Logger = class Logger {
|
|
8
|
+
static {
|
|
9
|
+
this.debug = false;
|
|
10
|
+
}
|
|
11
|
+
constructor(name) {
|
|
12
|
+
this.name = name;
|
|
13
|
+
}
|
|
14
|
+
static log(message, meta = "") {
|
|
15
|
+
if (!Logger.debug) return;
|
|
16
|
+
console.log(`${blue}Uniwind ${meta}- ${message}${reset}`);
|
|
17
|
+
}
|
|
18
|
+
static error(message, meta = "") {
|
|
19
|
+
console.log(`${red}Uniwind Error ${meta}- ${message}${reset}`);
|
|
20
|
+
}
|
|
21
|
+
static warn(message, meta = "") {
|
|
22
|
+
if (!Logger.debug) return;
|
|
23
|
+
console.log(`${yellow}Uniwind Warning ${meta}- ${message}${reset}`);
|
|
24
|
+
}
|
|
25
|
+
log(message) {
|
|
26
|
+
Logger.log(message, `[${this.name} Processor] `);
|
|
27
|
+
}
|
|
28
|
+
error(message) {
|
|
29
|
+
Logger.error(message, `[${this.name} Processor] `);
|
|
30
|
+
}
|
|
31
|
+
warn(message) {
|
|
32
|
+
Logger.warn(message, `[${this.name} Processor] `);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/webpack/uniwind/src/metro/logger.ts
|
|
2
|
+
const red = "\x1B[91m";
|
|
3
|
+
const yellow = "\x1B[33m";
|
|
4
|
+
const blue = "\x1B[36m";
|
|
5
|
+
const reset = "\x1B[0m";
|
|
6
|
+
var Logger = class Logger {
|
|
7
|
+
static {
|
|
8
|
+
this.debug = false;
|
|
9
|
+
}
|
|
10
|
+
constructor(name) {
|
|
11
|
+
this.name = name;
|
|
12
|
+
}
|
|
13
|
+
static log(message, meta = "") {
|
|
14
|
+
if (!Logger.debug) return;
|
|
15
|
+
console.log(`${blue}Uniwind ${meta}- ${message}${reset}`);
|
|
16
|
+
}
|
|
17
|
+
static error(message, meta = "") {
|
|
18
|
+
console.log(`${red}Uniwind Error ${meta}- ${message}${reset}`);
|
|
19
|
+
}
|
|
20
|
+
static warn(message, meta = "") {
|
|
21
|
+
if (!Logger.debug) return;
|
|
22
|
+
console.log(`${yellow}Uniwind Warning ${meta}- ${message}${reset}`);
|
|
23
|
+
}
|
|
24
|
+
log(message) {
|
|
25
|
+
Logger.log(message, `[${this.name} Processor] `);
|
|
26
|
+
}
|
|
27
|
+
error(message) {
|
|
28
|
+
Logger.error(message, `[${this.name} Processor] `);
|
|
29
|
+
}
|
|
30
|
+
warn(message) {
|
|
31
|
+
Logger.warn(message, `[${this.name} Processor] `);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { Logger };
|
|
37
|
+
//# sourceMappingURL=logger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.mjs","names":["name: string"],"sources":["../../../../../src/webpack/uniwind/src/metro/logger.ts"],"sourcesContent":["/* eslint-disable no-console */\n\nconst red = \"\\x1b[91m\";\nconst yellow = \"\\x1b[33m\";\nconst blue = \"\\x1b[36m\";\nconst reset = \"\\x1b[0m\";\n\nexport class Logger {\n static debug = false;\n\n constructor(private readonly name: string) {}\n\n static log(message: string, meta = \"\") {\n if (!Logger.debug) {\n return;\n }\n\n console.log(`${blue}Uniwind ${meta}- ${message}${reset}`);\n }\n\n static error(message: string, meta = \"\") {\n console.log(`${red}Uniwind Error ${meta}- ${message}${reset}`);\n }\n\n static warn(message: string, meta = \"\") {\n if (!Logger.debug) {\n return;\n }\n\n console.log(`${yellow}Uniwind Warning ${meta}- ${message}${reset}`);\n }\n\n log(message: string) {\n Logger.log(message, `[${this.name} Processor] `);\n }\n\n error(message: string) {\n Logger.error(message, `[${this.name} Processor] `);\n }\n\n warn(message: string) {\n Logger.warn(message, `[${this.name} Processor] `);\n }\n}\n"],"mappings":";AAEA,MAAM,MAAM;AACZ,MAAM,SAAS;AACf,MAAM,OAAO;AACb,MAAM,QAAQ;AAEd,IAAa,SAAb,MAAa,OAAO;;eACH;;CAEf,YAAY,AAAiBA,MAAc;EAAd;;CAE7B,OAAO,IAAI,SAAiB,OAAO,IAAI;AACrC,MAAI,CAAC,OAAO,MACV;AAGF,UAAQ,IAAI,GAAG,KAAK,UAAU,KAAK,IAAI,UAAU,QAAQ;;CAG3D,OAAO,MAAM,SAAiB,OAAO,IAAI;AACvC,UAAQ,IAAI,GAAG,IAAI,gBAAgB,KAAK,IAAI,UAAU,QAAQ;;CAGhE,OAAO,KAAK,SAAiB,OAAO,IAAI;AACtC,MAAI,CAAC,OAAO,MACV;AAGF,UAAQ,IAAI,GAAG,OAAO,kBAAkB,KAAK,IAAI,UAAU,QAAQ;;CAGrE,IAAI,SAAiB;AACnB,SAAO,IAAI,SAAS,IAAI,KAAK,KAAK,cAAc;;CAGlD,MAAM,SAAiB;AACrB,SAAO,MAAM,SAAS,IAAI,KAAK,KAAK,cAAc;;CAGpD,KAAK,SAAiB;AACpB,SAAO,KAAK,SAAS,IAAI,KAAK,KAAK,cAAc"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_package = require('../../package.cjs');
|
|
3
|
+
let fs = require("fs");
|
|
4
|
+
fs = require_rolldown_runtime.__toESM(fs);
|
|
5
|
+
|
|
6
|
+
//#region src/webpack/uniwind/src/utils/buildDtsFile.ts
|
|
7
|
+
const buildDtsFile = (dtsPath, stringifiedThemes) => {
|
|
8
|
+
const oldDtsContent = fs.default.existsSync(dtsPath) ? fs.default.readFileSync(dtsPath, "utf-8") : "";
|
|
9
|
+
const dtsContent = [
|
|
10
|
+
`// NOTE: This file is generated by ${require_package.name} and it should not be edited manually.`,
|
|
11
|
+
`/// <reference types="${require_package.name}/types" />`,
|
|
12
|
+
"",
|
|
13
|
+
`declare module '${require_package.name}' {`,
|
|
14
|
+
` export interface UniwindConfig {`,
|
|
15
|
+
` themes: readonly ${stringifiedThemes}`,
|
|
16
|
+
` }`,
|
|
17
|
+
`}`,
|
|
18
|
+
"",
|
|
19
|
+
`export {}`,
|
|
20
|
+
""
|
|
21
|
+
].join("\n");
|
|
22
|
+
if (oldDtsContent === dtsContent) return;
|
|
23
|
+
fs.default.writeFileSync(dtsPath, dtsContent);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.buildDtsFile = buildDtsFile;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { name } from "../../package.mjs";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
|
|
4
|
+
//#region src/webpack/uniwind/src/utils/buildDtsFile.ts
|
|
5
|
+
const buildDtsFile = (dtsPath, stringifiedThemes) => {
|
|
6
|
+
const oldDtsContent = fs.existsSync(dtsPath) ? fs.readFileSync(dtsPath, "utf-8") : "";
|
|
7
|
+
const dtsContent = [
|
|
8
|
+
`// NOTE: This file is generated by ${name} and it should not be edited manually.`,
|
|
9
|
+
`/// <reference types="${name}/types" />`,
|
|
10
|
+
"",
|
|
11
|
+
`declare module '${name}' {`,
|
|
12
|
+
` export interface UniwindConfig {`,
|
|
13
|
+
` themes: readonly ${stringifiedThemes}`,
|
|
14
|
+
` }`,
|
|
15
|
+
`}`,
|
|
16
|
+
"",
|
|
17
|
+
`export {}`,
|
|
18
|
+
""
|
|
19
|
+
].join("\n");
|
|
20
|
+
if (oldDtsContent === dtsContent) return;
|
|
21
|
+
fs.writeFileSync(dtsPath, dtsContent);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { buildDtsFile };
|
|
26
|
+
//# sourceMappingURL=buildDtsFile.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildDtsFile.mjs","names":[],"sources":["../../../../../src/webpack/uniwind/src/utils/buildDtsFile.ts"],"sourcesContent":["import fs from \"fs\";\nimport { name } from \"../../package.json\";\n\nexport const buildDtsFile = (dtsPath: string, stringifiedThemes: string) => {\n const oldDtsContent = fs.existsSync(dtsPath)\n ? fs.readFileSync(dtsPath, \"utf-8\")\n : \"\";\n const dtsContent = [\n `// NOTE: This file is generated by ${name} and it should not be edited manually.`,\n `/// <reference types=\"${name}/types\" />`,\n \"\",\n `declare module '${name}' {`,\n ` export interface UniwindConfig {`,\n ` themes: readonly ${stringifiedThemes}`,\n ` }`,\n `}`,\n \"\",\n `export {}`,\n \"\",\n ].join(\"\\n\");\n\n if (oldDtsContent === dtsContent) {\n return;\n }\n\n fs.writeFileSync(dtsPath, dtsContent);\n};\n"],"mappings":";;;;AAGA,MAAa,gBAAgB,SAAiB,sBAA8B;CAC1E,MAAM,gBAAgB,GAAG,WAAW,QAAQ,GACxC,GAAG,aAAa,SAAS,QAAQ,GACjC;CACJ,MAAM,aAAa;EACjB,sCAAsC,KAAK;EAC3C,yBAAyB,KAAK;EAC9B;EACA,mBAAmB,KAAK;EACxB;EACA,4BAA4B;EAC5B;EACA;EACA;EACA;EACA;EACD,CAAC,KAAK,KAAK;AAEZ,KAAI,kBAAkB,WACpB;AAGF,IAAG,cAAc,SAAS,WAAW"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.mjs","names":[],"sources":["../../../../../src/webpack/uniwind/src/utils/common.ts"],"sourcesContent":["export const isDefined = <T>(value: T): value is NonNullable<T> =>\n value !== null && value !== undefined;\n\nexport const toCamelCase = (str: string) =>\n str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());\n\ntype P<I, O> = (data: I) => O;\ntype PipeFns<T> = {\n <A>(a: P<T, A>): A;\n <A, B>(a: P<T, A>, b: P<A, B>): B;\n <A, B, C>(a: P<T, A>, b: P<A, B>, c: P<B, C>): C;\n <A, B, C, D>(a: P<T, A>, b: P<A, B>, c: P<B, C>, d: P<C, D>): D;\n <A, B, C, D, E>(\n a: P<T, A>,\n b: P<A, B>,\n c: P<B, C>,\n d: P<C, D>,\n e: P<D, E>,\n ): E;\n <A, B, C, D, E, F>(\n a: P<T, A>,\n b: P<A, B>,\n c: P<B, C>,\n d: P<C, D>,\n e: P<D, E>,\n f: P<E, F>,\n ): F;\n <A, B, C, D, E, F, G>(\n a: P<T, A>,\n b: P<A, B>,\n c: P<B, C>,\n d: P<C, D>,\n e: P<D, E>,\n f: P<E, F>,\n g: P<F, G>,\n ): G;\n <A, B, C, D, E, F, G, H>(\n a: P<T, A>,\n b: P<A, B>,\n c: P<B, C>,\n d: P<C, D>,\n e: P<D, E>,\n f: P<E, F>,\n g: P<F, G>,\n h: P<G, H>,\n ): H;\n (...fns: Array<P<T, T>>): T;\n};\n\nexport const pipe = <T>(data: T) =>\n ((...fns: Array<any>) =>\n fns.reduce((acc, fn) => fn(acc), data)) as PipeFns<T>;\n\nexport const isNumber = (data: any) => {\n if (typeof data === \"number\") {\n return true;\n }\n\n if (typeof data === \"string\" && data !== \"\") {\n return !isNaN(Number(data));\n }\n\n return false;\n};\n\nexport const smartSplit = (str: string, separator = \" \" as string | RegExp) => {\n const escaper = \"&&&\";\n\n return pipe(str)(\n (x) => x.replace(/\\s\\?\\?\\s/g, `${escaper}??${escaper}`),\n (x) => x.replace(/\\s([+\\-*/])\\s/g, `${escaper}$1${escaper}`),\n (x) => x.split(separator),\n (x) => x.map((token) => token.replace(new RegExp(escaper, \"g\"), \" \")),\n );\n};\n\nexport const addMissingSpaces = (str: string) =>\n pipe(str)(\n (x) => x.trim(),\n (x) => x.replace(/([^ {])this/g, \"$1 this\"),\n (x) => x.replace(/\\](?=\\d)/g, \"] \"),\n (x) => x.replace(/\\)(?=\\S)/g, \") \"),\n (x) => x.replace(/(?<!^)(?<!\\s)\"(?=\\d)/g, '\" '),\n );\n\nexport const uniq = <T>(arr: Array<T>) => Array.from(new Set(arr));\n\nexport const isValidJSValue = (jsValueString: string) => {\n try {\n // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func\n new Function(`const test = ${jsValueString}`);\n\n return true;\n } catch {\n return false;\n }\n};\n\nexport const shouldBeSerialized = (value: string) => {\n if (value.includes(\"-\")) {\n return value.split(\"-\").some(shouldBeSerialized);\n }\n\n return [\n isNumber(value),\n value.startsWith(\"this[\"),\n value.startsWith(\"rt.\"),\n /[*/+-]/.test(value),\n value.includes('\"'),\n value.includes(\" \"),\n ].some(Boolean);\n};\n\nexport const roundToPrecision = (value: number, precision: number) =>\n parseFloat(value.toFixed(precision));\n\nexport const deepEqual = <T>(a: T, b: T): boolean => {\n if (Object.is(a, b)) {\n return true;\n }\n\n if (\n typeof a !== \"object\" ||\n a === null ||\n typeof b !== \"object\" ||\n b === null\n ) {\n return false;\n }\n\n const keysA = Object.keys(a) as Array<keyof T>;\n\n if (keysA.length !== Object.keys(b).length) {\n return false;\n }\n\n return keysA.every(\n (key) =>\n deepEqual(a[key], b[key]) && Object.prototype.hasOwnProperty.call(b, key),\n );\n};\n"],"mappings":";AAqFA,MAAa,QAAW,QAAkB,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringifyThemes.mjs","names":[],"sources":["../../../../../src/webpack/uniwind/src/utils/stringifyThemes.ts"],"sourcesContent":["export const stringifyThemes = (themes: Array<string> = []) =>\n `[${themes.map((theme) => `'${theme}'`).join(\", \")}]`;\n"],"mappings":";AAAA,MAAa,mBAAmB,SAAwB,EAAE,KACxD,IAAI,OAAO,KAAK,UAAU,IAAI,MAAM,GAAG,CAAC,KAAK,KAAK,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_common = require('./uniwind/src/utils/common.cjs');
|
|
3
|
+
const require_UniwindWebpackPlugin = require('./UniwindWebpackPlugin.cjs');
|
|
4
|
+
let webpack = require("webpack");
|
|
5
|
+
webpack = require_rolldown_runtime.__toESM(webpack);
|
|
6
|
+
let path = require("path");
|
|
7
|
+
path = require_rolldown_runtime.__toESM(path);
|
|
8
|
+
|
|
9
|
+
//#region src/webpack/withUniwind.ts
|
|
10
|
+
const { NormalModuleReplacementPlugin } = webpack.default;
|
|
11
|
+
function withUniwind(nextConfig = {}, uniwindConfig) {
|
|
12
|
+
return {
|
|
13
|
+
...nextConfig,
|
|
14
|
+
transpilePackages: require_common.uniq([
|
|
15
|
+
...nextConfig.transpilePackages || [],
|
|
16
|
+
"uniwind",
|
|
17
|
+
"react-native",
|
|
18
|
+
"react-native-web"
|
|
19
|
+
]),
|
|
20
|
+
webpack(config, options) {
|
|
21
|
+
if (!config.plugins) config.plugins = [];
|
|
22
|
+
config.plugins.push(new NormalModuleReplacementPlugin(/^react-native$/, (resource) => {
|
|
23
|
+
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";
|
|
24
|
+
else resource.request = "uniwind/components/index";
|
|
25
|
+
}));
|
|
26
|
+
config.plugins.push(new require_UniwindWebpackPlugin.UniwindWebpackPlugin(uniwindConfig));
|
|
27
|
+
if (typeof nextConfig.webpack === "function") return nextConfig.webpack(config, options);
|
|
28
|
+
return config;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
exports.withUniwind = withUniwind;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UniwindConfig } from "./types.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/webpack/withUniwind.d.ts
|
|
4
|
+
declare function withUniwind(nextConfig: any | undefined, uniwindConfig: UniwindConfig): any;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { withUniwind };
|
|
7
|
+
//# sourceMappingURL=withUniwind.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withUniwind.d.cts","names":[],"sources":["../../src/webpack/withUniwind.ts"],"sourcesContent":[],"mappings":";;;iBASgB,WAAA,6CAEC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UniwindConfig } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/webpack/withUniwind.d.ts
|
|
4
|
+
declare function withUniwind(nextConfig: any | undefined, uniwindConfig: UniwindConfig): any;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { withUniwind };
|
|
7
|
+
//# sourceMappingURL=withUniwind.d.mts.map
|