weapp-tailwindcss 5.0.0-next.24 → 5.0.0-next.25
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/dist/auto-AduSz49t.mjs +80 -0
- package/dist/auto-B11j1XiD.js +117 -0
- package/dist/{bundle-state-DXFq2nEo.js → bundle-state-BY7PWHAc.js} +1 -1
- package/dist/{bundle-state-CP_BWXfx.mjs → bundle-state-CBouNDzi.mjs} +1 -1
- package/dist/cli.js +167 -5
- package/dist/cli.mjs +166 -4
- package/dist/context/runtime-package-replacements.d.ts +2 -0
- package/dist/context/style-options.d.ts +3 -0
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro/auto.d.ts +10 -0
- package/dist/css-macro/constants.d.ts +5 -2
- package/dist/css-macro/postcss.d.ts +1 -0
- package/dist/css-macro/postcss.js +7 -47
- package/dist/css-macro/postcss.mjs +2 -47
- package/dist/css-macro.js +15 -6
- package/dist/css-macro.mjs +15 -6
- package/dist/{defaults-C6sIKXgC.mjs → defaults-B-1EEhdL.mjs} +2 -1
- package/dist/{defaults-D3cFX6Cq.js → defaults-C10hYUch.js} +2 -1
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/{generator-DdEgn8nG.mjs → generator-CtqzN9L-.mjs} +1 -1
- package/dist/{generator-BcH28HU-.js → generator-DTPePQZ9.js} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/gulp.js +5 -5
- package/dist/gulp.mjs +5 -5
- package/dist/{incremental-runtime-class-set-Bux7viee.mjs → incremental-runtime-class-set-BlJ86j-A.mjs} +4 -16
- package/dist/{incremental-runtime-class-set-CWdfLHON.js → incremental-runtime-class-set-CERcE0fP.js} +4 -16
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -4
- package/dist/index.mjs +6 -5
- package/dist/{postcss-cD5PXmMU.js → postcss-BAO9tGi5.js} +2 -2
- package/dist/{postcss-nk5bhdoV.mjs → postcss-CYPHxj7a.mjs} +2 -2
- package/dist/postcss-DXkxsPNg.js +192 -0
- package/dist/postcss-DYktK8_T.mjs +169 -0
- package/dist/postcss.js +1 -1
- package/dist/postcss.mjs +1 -1
- package/dist/{precheck-DreRGvYH.mjs → precheck-B4CpMt_w.mjs} +69 -32
- package/dist/{precheck-DtYqujIx.js → precheck-ezN3ovAq.js} +75 -32
- package/dist/presets/uni-app-x.d.ts +1 -0
- package/dist/presets.js +5 -4
- package/dist/presets.mjs +5 -4
- package/dist/{source-candidates-lHtAHLQq.js → source-candidates-0jPRIPmC.js} +1 -1
- package/dist/{source-candidates-B7wmEa-G.mjs → source-candidates-DoyOltpZ.mjs} +1 -1
- package/dist/{tailwindcss-BtUBeOes.js → tailwindcss-nQetCaPp.js} +17 -26
- package/dist/{tailwindcss-DO-VVR5k.mjs → tailwindcss-ujlr9Iad.mjs} +17 -26
- package/dist/types/index.d.ts +1 -1
- package/dist/types/shared.d.ts +3 -0
- package/dist/types/user-defined-options/general.d.ts +2 -1
- package/dist/types/user-defined-options/important.d.ts +3 -1
- package/dist/unocss/index.d.ts +2 -0
- package/dist/utils/options.d.ts +2 -0
- package/dist/utils/regex.d.ts +1 -0
- package/dist/{v3-engine-vHlppqaZ.js → v3-engine-Bbsrez2w.js} +67 -19
- package/dist/{v3-engine-CXqgQZUc.mjs → v3-engine-COw08vWd.mjs} +56 -20
- package/dist/{vite-BkNDGBZ2.js → vite-DE8Vfzal.js} +9 -9
- package/dist/{vite-BthAm8kt.mjs → vite-hZsQAY1a.mjs} +9 -9
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +329 -72
- package/dist/weapp-tw-runtime-classset-loader.js +1 -4
- package/dist/{webpack-prCus5xn.js → webpack-CTJcw_sX.js} +6 -6
- package/dist/{webpack-hPc8wUAi.mjs → webpack-c2WJnCJI.mjs} +6 -6
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +9 -11
- package/dist/constants-BG12WAKw.mjs +0 -44
- package/dist/constants-BeeyfJ9k.js +0 -73
- /package/dist/{logger-EVNB9z7i.js → logger-Cdzl3p8j.js} +0 -0
- /package/dist/{logger-CZUxvJJD.mjs → logger-Dr7IvyH2.mjs} +0 -0
- /package/dist/{utils-CGBVVNm6.mjs → utils-B2SJgA1L.mjs} +0 -0
- /package/dist/{utils-4ODFyoqD.js → utils-CSA174-I.js} +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { n as creator, t as CSS_MACRO_POSTCSS_PLUGIN_NAME } from "./postcss-DYktK8_T.mjs";
|
|
2
|
+
import postcss from "postcss";
|
|
3
|
+
//#region src/css-macro/auto.ts
|
|
4
|
+
const CSS_MACRO_PLUGIN_MARKER = "__weappTailwindcssCssMacro";
|
|
5
|
+
const CSS_MACRO_STYLE_OPTIONS_MARKER = "__weappTailwindcssCssMacroEnabled";
|
|
6
|
+
function markCssMacroPlugin(value) {
|
|
7
|
+
Object.defineProperty(value, CSS_MACRO_PLUGIN_MARKER, {
|
|
8
|
+
configurable: false,
|
|
9
|
+
enumerable: false,
|
|
10
|
+
value: true
|
|
11
|
+
});
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function isCssMacroTailwindPlugin(value) {
|
|
15
|
+
return Boolean(value && (typeof value === "function" || typeof value === "object") && value["__weappTailwindcssCssMacro"] === true);
|
|
16
|
+
}
|
|
17
|
+
function hasCssMacroTailwindPlugin(plugins) {
|
|
18
|
+
if (!plugins) return false;
|
|
19
|
+
if (Array.isArray(plugins)) return plugins.some(isCssMacroTailwindPlugin);
|
|
20
|
+
if (typeof plugins === "object") return Object.values(plugins).some(isCssMacroTailwindPlugin);
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
function parseCssPluginRequest(params) {
|
|
24
|
+
const value = params.trim();
|
|
25
|
+
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
26
|
+
if (quoted) return quoted[2];
|
|
27
|
+
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
28
|
+
return url?.[2] ?? url?.[3];
|
|
29
|
+
}
|
|
30
|
+
function isCssMacroPluginRequest(request) {
|
|
31
|
+
return request === "weapp-tailwindcss/css-macro";
|
|
32
|
+
}
|
|
33
|
+
function hasCssMacroTailwindV4Directive(css) {
|
|
34
|
+
if (!css?.includes("css-macro")) return false;
|
|
35
|
+
try {
|
|
36
|
+
let found = false;
|
|
37
|
+
postcss.parse(css).walkAtRules("plugin", (rule) => {
|
|
38
|
+
if (isCssMacroPluginRequest(parseCssPluginRequest(rule.params))) found = true;
|
|
39
|
+
});
|
|
40
|
+
return found;
|
|
41
|
+
} catch {
|
|
42
|
+
return /@plugin\s+(?:url\(\s*)?["']weapp-tailwindcss\/css-macro["']/.test(css);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function isCssMacroPostcssPlugin(plugin) {
|
|
46
|
+
if (plugin === creator) return true;
|
|
47
|
+
return Boolean(plugin && (typeof plugin === "function" || typeof plugin === "object") && plugin.postcssPlugin === "postcss-weapp-tw-css-macro-plugin");
|
|
48
|
+
}
|
|
49
|
+
function withCssMacroPostcssPlugins(plugins) {
|
|
50
|
+
const macroPlugin = creator();
|
|
51
|
+
if (!plugins) return [macroPlugin];
|
|
52
|
+
if (Array.isArray(plugins)) return plugins.some(isCssMacroPostcssPlugin) ? plugins : [...plugins, macroPlugin];
|
|
53
|
+
if (typeof plugins === "object") {
|
|
54
|
+
if (Object.values(plugins).some(isCssMacroPostcssPlugin)) return plugins;
|
|
55
|
+
return {
|
|
56
|
+
...plugins,
|
|
57
|
+
[CSS_MACRO_POSTCSS_PLUGIN_NAME]: macroPlugin
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return [macroPlugin];
|
|
61
|
+
}
|
|
62
|
+
function withCssMacroStyleOptions(options) {
|
|
63
|
+
const postcssOptions = options?.postcssOptions;
|
|
64
|
+
return {
|
|
65
|
+
...options,
|
|
66
|
+
[CSS_MACRO_STYLE_OPTIONS_MARKER]: true,
|
|
67
|
+
postcssOptions: {
|
|
68
|
+
...postcssOptions,
|
|
69
|
+
plugins: withCssMacroPostcssPlugins(postcssOptions?.plugins)
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function hasCssMacroStyleOptions(options) {
|
|
74
|
+
return Boolean(options?.[CSS_MACRO_STYLE_OPTIONS_MARKER]);
|
|
75
|
+
}
|
|
76
|
+
async function transformCssMacroCss(css) {
|
|
77
|
+
return (await postcss([creator()]).process(css, { from: void 0 })).css;
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
export { transformCssMacroCss as a, markCssMacroPlugin as i, hasCssMacroTailwindPlugin as n, withCssMacroStyleOptions as o, hasCssMacroTailwindV4Directive as r, hasCssMacroStyleOptions as t };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
const require_chunk = require("./chunk-8l464Juk.js");
|
|
2
|
+
const require_postcss = require("./postcss-DXkxsPNg.js");
|
|
3
|
+
let postcss = require("postcss");
|
|
4
|
+
postcss = require_chunk.__toESM(postcss);
|
|
5
|
+
//#region src/css-macro/auto.ts
|
|
6
|
+
const CSS_MACRO_PLUGIN_MARKER = "__weappTailwindcssCssMacro";
|
|
7
|
+
const CSS_MACRO_STYLE_OPTIONS_MARKER = "__weappTailwindcssCssMacroEnabled";
|
|
8
|
+
function markCssMacroPlugin(value) {
|
|
9
|
+
Object.defineProperty(value, CSS_MACRO_PLUGIN_MARKER, {
|
|
10
|
+
configurable: false,
|
|
11
|
+
enumerable: false,
|
|
12
|
+
value: true
|
|
13
|
+
});
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
function isCssMacroTailwindPlugin(value) {
|
|
17
|
+
return Boolean(value && (typeof value === "function" || typeof value === "object") && value["__weappTailwindcssCssMacro"] === true);
|
|
18
|
+
}
|
|
19
|
+
function hasCssMacroTailwindPlugin(plugins) {
|
|
20
|
+
if (!plugins) return false;
|
|
21
|
+
if (Array.isArray(plugins)) return plugins.some(isCssMacroTailwindPlugin);
|
|
22
|
+
if (typeof plugins === "object") return Object.values(plugins).some(isCssMacroTailwindPlugin);
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
function parseCssPluginRequest(params) {
|
|
26
|
+
const value = params.trim();
|
|
27
|
+
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
28
|
+
if (quoted) return quoted[2];
|
|
29
|
+
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
30
|
+
return url?.[2] ?? url?.[3];
|
|
31
|
+
}
|
|
32
|
+
function isCssMacroPluginRequest(request) {
|
|
33
|
+
return request === "weapp-tailwindcss/css-macro";
|
|
34
|
+
}
|
|
35
|
+
function hasCssMacroTailwindV4Directive(css) {
|
|
36
|
+
if (!css?.includes("css-macro")) return false;
|
|
37
|
+
try {
|
|
38
|
+
let found = false;
|
|
39
|
+
postcss.default.parse(css).walkAtRules("plugin", (rule) => {
|
|
40
|
+
if (isCssMacroPluginRequest(parseCssPluginRequest(rule.params))) found = true;
|
|
41
|
+
});
|
|
42
|
+
return found;
|
|
43
|
+
} catch {
|
|
44
|
+
return /@plugin\s+(?:url\(\s*)?["']weapp-tailwindcss\/css-macro["']/.test(css);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function isCssMacroPostcssPlugin(plugin) {
|
|
48
|
+
if (plugin === require_postcss.creator) return true;
|
|
49
|
+
return Boolean(plugin && (typeof plugin === "function" || typeof plugin === "object") && plugin.postcssPlugin === "postcss-weapp-tw-css-macro-plugin");
|
|
50
|
+
}
|
|
51
|
+
function withCssMacroPostcssPlugins(plugins) {
|
|
52
|
+
const macroPlugin = require_postcss.creator();
|
|
53
|
+
if (!plugins) return [macroPlugin];
|
|
54
|
+
if (Array.isArray(plugins)) return plugins.some(isCssMacroPostcssPlugin) ? plugins : [...plugins, macroPlugin];
|
|
55
|
+
if (typeof plugins === "object") {
|
|
56
|
+
if (Object.values(plugins).some(isCssMacroPostcssPlugin)) return plugins;
|
|
57
|
+
return {
|
|
58
|
+
...plugins,
|
|
59
|
+
[require_postcss.CSS_MACRO_POSTCSS_PLUGIN_NAME]: macroPlugin
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return [macroPlugin];
|
|
63
|
+
}
|
|
64
|
+
function withCssMacroStyleOptions(options) {
|
|
65
|
+
const postcssOptions = options?.postcssOptions;
|
|
66
|
+
return {
|
|
67
|
+
...options,
|
|
68
|
+
[CSS_MACRO_STYLE_OPTIONS_MARKER]: true,
|
|
69
|
+
postcssOptions: {
|
|
70
|
+
...postcssOptions,
|
|
71
|
+
plugins: withCssMacroPostcssPlugins(postcssOptions?.plugins)
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function hasCssMacroStyleOptions(options) {
|
|
76
|
+
return Boolean(options?.[CSS_MACRO_STYLE_OPTIONS_MARKER]);
|
|
77
|
+
}
|
|
78
|
+
async function transformCssMacroCss(css) {
|
|
79
|
+
return (await (0, postcss.default)([require_postcss.creator()]).process(css, { from: void 0 })).css;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
Object.defineProperty(exports, "hasCssMacroStyleOptions", {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
get: function() {
|
|
85
|
+
return hasCssMacroStyleOptions;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(exports, "hasCssMacroTailwindPlugin", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
get: function() {
|
|
91
|
+
return hasCssMacroTailwindPlugin;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(exports, "hasCssMacroTailwindV4Directive", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
get: function() {
|
|
97
|
+
return hasCssMacroTailwindV4Directive;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
Object.defineProperty(exports, "markCssMacroPlugin", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
get: function() {
|
|
103
|
+
return markCssMacroPlugin;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
Object.defineProperty(exports, "transformCssMacroCss", {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
get: function() {
|
|
109
|
+
return transformCssMacroCss;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
Object.defineProperty(exports, "withCssMacroStyleOptions", {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
get: function() {
|
|
115
|
+
return withCssMacroStyleOptions;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-8l464Juk.js");
|
|
2
|
-
const require_precheck = require("./precheck-
|
|
2
|
+
const require_precheck = require("./precheck-ezN3ovAq.js");
|
|
3
3
|
let node_module = require("node:module");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
5
|
node_path = require_chunk.__toESM(node_path);
|
package/dist/cli.js
CHANGED
|
@@ -46,7 +46,6 @@ require("tailwindcss-config");
|
|
|
46
46
|
let _babel_traverse = require("@babel/traverse");
|
|
47
47
|
_babel_traverse = __toESM(_babel_traverse);
|
|
48
48
|
let _babel_parser = require("@babel/parser");
|
|
49
|
-
let _weapp_core_regex = require("@weapp-core/regex");
|
|
50
49
|
let magic_string = require("magic-string");
|
|
51
50
|
magic_string = __toESM(magic_string);
|
|
52
51
|
let _ast_core_escape = require("@ast-core/escape");
|
|
@@ -73,6 +72,163 @@ function createDebug(prefix) {
|
|
|
73
72
|
return debug$4;
|
|
74
73
|
}
|
|
75
74
|
//#endregion
|
|
75
|
+
//#region src/css-macro/constants.ts
|
|
76
|
+
const queryKey = "weapp-tw-platform";
|
|
77
|
+
const UNESCAPED_UNDERSCORE_RE = /(?<!\\)_/g;
|
|
78
|
+
const WHITESPACE_RE = /\s+/g;
|
|
79
|
+
const LOGICAL_OPERATOR_RE = /\s*(\|\||&&)\s*/g;
|
|
80
|
+
function normalComment(text) {
|
|
81
|
+
if (typeof text === "string") {
|
|
82
|
+
const normalized = text.replaceAll(UNESCAPED_UNDERSCORE_RE, " ").replaceAll(WHITESPACE_RE, " ").trim();
|
|
83
|
+
if (normalized.includes("\\")) return normalized;
|
|
84
|
+
return normalized.replaceAll(LOGICAL_OPERATOR_RE, " $1 ").replaceAll(WHITESPACE_RE, " ").trim();
|
|
85
|
+
}
|
|
86
|
+
return text;
|
|
87
|
+
}
|
|
88
|
+
function ifdef(text) {
|
|
89
|
+
return {
|
|
90
|
+
start: `#ifdef ${normalComment(text)}`,
|
|
91
|
+
end: `#endif`
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function ifndef(text) {
|
|
95
|
+
return {
|
|
96
|
+
start: `#ifndef ${normalComment(text)}`,
|
|
97
|
+
end: `#endif`
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const QUERY_KEY_REGEX = new RegExp(`\\(\\s*${queryKey}\\s*:\\s*"([^)]*)"\\)`, "g");
|
|
101
|
+
function matchCustomPropertyFromValue(str, cb) {
|
|
102
|
+
let index = 0;
|
|
103
|
+
QUERY_KEY_REGEX.lastIndex = 0;
|
|
104
|
+
let arr = QUERY_KEY_REGEX.exec(str);
|
|
105
|
+
while (arr !== null) {
|
|
106
|
+
cb(arr, index);
|
|
107
|
+
index++;
|
|
108
|
+
arr = QUERY_KEY_REGEX.exec(str);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function parseConditionalAtRuleParam(params) {
|
|
112
|
+
const value = params.trim();
|
|
113
|
+
const quoted = /^(['"])((?:\\.|(?!\1).)*)\1/.exec(value);
|
|
114
|
+
if (!quoted) return value;
|
|
115
|
+
return quoted[2]?.replaceAll(/\\(["'\\])/g, "$1") ?? "";
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/css-macro/postcss.ts
|
|
119
|
+
const IFDEF_ENDIF_RE = /#(?:ifn?def|endif)/;
|
|
120
|
+
const CONDITIONAL_COMMENT_SPACING = " ";
|
|
121
|
+
const CSS_MACRO_POSTCSS_PLUGIN_NAME = "postcss-weapp-tw-css-macro-plugin";
|
|
122
|
+
const creator = () => {
|
|
123
|
+
return {
|
|
124
|
+
postcssPlugin: CSS_MACRO_POSTCSS_PLUGIN_NAME,
|
|
125
|
+
prepare() {
|
|
126
|
+
function replaceAtRuleWithConditionalComments(atRule, helper, comment) {
|
|
127
|
+
const hasPreviousNode = Boolean(atRule.prev());
|
|
128
|
+
const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
|
|
129
|
+
const startComment = helper.comment({
|
|
130
|
+
raws: {
|
|
131
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
132
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
133
|
+
},
|
|
134
|
+
text: comment.start
|
|
135
|
+
});
|
|
136
|
+
const endComment = helper.comment({
|
|
137
|
+
raws: {
|
|
138
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
139
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
140
|
+
},
|
|
141
|
+
text: comment.end
|
|
142
|
+
});
|
|
143
|
+
const nextNodes = [
|
|
144
|
+
startComment,
|
|
145
|
+
...clonedNodes,
|
|
146
|
+
endComment
|
|
147
|
+
];
|
|
148
|
+
atRule.replaceWith(nextNodes);
|
|
149
|
+
startComment.raws.before = hasPreviousNode ? "\n" : "";
|
|
150
|
+
startComment.raws.after = "\n";
|
|
151
|
+
if (clonedNodes[0]) clonedNodes[0].raws.before = "\n";
|
|
152
|
+
endComment.raws.before = "\n";
|
|
153
|
+
endComment.raws.after = "\n";
|
|
154
|
+
const nextNode = endComment?.next();
|
|
155
|
+
if (nextNode) nextNode.raws.before = "\n";
|
|
156
|
+
}
|
|
157
|
+
function replaceNestedAtRuleWithConditionalRule(atRule, helper, comment) {
|
|
158
|
+
if (atRule.parent?.type !== "rule") return false;
|
|
159
|
+
const parentRule = atRule.parent;
|
|
160
|
+
const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
|
|
161
|
+
const conditionalRule = parentRule.clone();
|
|
162
|
+
conditionalRule.removeAll();
|
|
163
|
+
conditionalRule.append(...clonedNodes);
|
|
164
|
+
const startComment = helper.comment({
|
|
165
|
+
raws: {
|
|
166
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
167
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
168
|
+
},
|
|
169
|
+
text: comment.start
|
|
170
|
+
});
|
|
171
|
+
const endComment = helper.comment({
|
|
172
|
+
raws: {
|
|
173
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
174
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
175
|
+
},
|
|
176
|
+
text: comment.end
|
|
177
|
+
});
|
|
178
|
+
const nextNodes = [
|
|
179
|
+
startComment,
|
|
180
|
+
conditionalRule,
|
|
181
|
+
endComment
|
|
182
|
+
];
|
|
183
|
+
const hasPreviousNode = Boolean(parentRule.prev());
|
|
184
|
+
atRule.remove();
|
|
185
|
+
if ((parentRule.nodes?.length ?? 0) === 0) parentRule.replaceWith(nextNodes);
|
|
186
|
+
else parentRule.after(nextNodes);
|
|
187
|
+
startComment.raws.before = hasPreviousNode ? "\n" : "";
|
|
188
|
+
startComment.raws.after = "\n";
|
|
189
|
+
conditionalRule.raws.before = "\n";
|
|
190
|
+
endComment.raws.before = "\n";
|
|
191
|
+
endComment.raws.after = "\n";
|
|
192
|
+
const nextNode = endComment.next();
|
|
193
|
+
if (nextNode) nextNode.raws.before = "\n";
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
AtRule(atRule, helper) {
|
|
198
|
+
if (atRule.name === "weapp-tw-ifdef" || atRule.name === "weapp-tw-ifndef") {
|
|
199
|
+
const text = parseConditionalAtRuleParam(atRule.params);
|
|
200
|
+
const comment = atRule.name === "weapp-tw-ifndef" ? ifndef(text) : ifdef(text);
|
|
201
|
+
if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
|
|
202
|
+
replaceAtRuleWithConditionalComments(atRule, helper, comment);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (atRule.name === "media") {
|
|
206
|
+
const values = [];
|
|
207
|
+
matchCustomPropertyFromValue(atRule.params, (arr) => {
|
|
208
|
+
const value = arr[1];
|
|
209
|
+
if (value) values.push(value);
|
|
210
|
+
});
|
|
211
|
+
if (values.length > 0) {
|
|
212
|
+
const isNegative = atRule.params.includes("not");
|
|
213
|
+
const text = values.join(" ");
|
|
214
|
+
const comment = isNegative ? ifndef(text) : ifdef(text);
|
|
215
|
+
if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
|
|
216
|
+
replaceAtRuleWithConditionalComments(atRule, helper, comment);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
CommentExit(comment) {
|
|
221
|
+
if (IFDEF_ENDIF_RE.test(comment.text)) {
|
|
222
|
+
comment.raws.left = CONDITIONAL_COMMENT_SPACING;
|
|
223
|
+
comment.raws.right = CONDITIONAL_COMMENT_SPACING;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
creator.postcss = true;
|
|
231
|
+
//#endregion
|
|
76
232
|
//#region src/tailwindcss/source-scan.ts
|
|
77
233
|
const DEFAULT_SOURCE_SCAN_EXTENSIONS = [
|
|
78
234
|
"html",
|
|
@@ -533,15 +689,18 @@ runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ ?? (runtimeLogDedupeHolde
|
|
|
533
689
|
const globalCacheHolder = globalThis;
|
|
534
690
|
globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
|
|
535
691
|
//#endregion
|
|
536
|
-
//#region src/constants.ts
|
|
537
|
-
const WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
|
|
538
|
-
//#endregion
|
|
539
692
|
//#region src/babel/index.ts
|
|
540
693
|
function _interopDefaultCompat(e) {
|
|
541
694
|
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
542
695
|
}
|
|
543
696
|
const traverse = _interopDefaultCompat(_babel_traverse.default);
|
|
544
697
|
//#endregion
|
|
698
|
+
//#region src/utils/regex.ts
|
|
699
|
+
function escapeStringRegexp(str) {
|
|
700
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
701
|
+
return str.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&").replaceAll("-", "\\x2d");
|
|
702
|
+
}
|
|
703
|
+
//#endregion
|
|
545
704
|
//#region src/utils/nameMatcher.ts
|
|
546
705
|
const NEVER_MATCH_NAME$1 = () => false;
|
|
547
706
|
const GLOBAL_FLAG_REGEXP = /g/g;
|
|
@@ -553,7 +712,7 @@ function buildFuzzyMatcher(fuzzyStrings) {
|
|
|
553
712
|
return (value) => value.includes(needle);
|
|
554
713
|
}
|
|
555
714
|
const unique = [...new Set(fuzzyStrings)];
|
|
556
|
-
const pattern = new RegExp(unique.map(
|
|
715
|
+
const pattern = new RegExp(unique.map(escapeStringRegexp).join("|"));
|
|
557
716
|
return (value) => pattern.test(value);
|
|
558
717
|
}
|
|
559
718
|
function normaliseRegex(regex) {
|
|
@@ -2106,6 +2265,9 @@ var Tokenizer = class {
|
|
|
2106
2265
|
};
|
|
2107
2266
|
new Tokenizer();
|
|
2108
2267
|
//#endregion
|
|
2268
|
+
//#region src/constants.ts
|
|
2269
|
+
const WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
|
|
2270
|
+
//#endregion
|
|
2109
2271
|
//#region src/cli/context.ts
|
|
2110
2272
|
function formatOutputPath(target, baseDir) {
|
|
2111
2273
|
const root = baseDir ?? node_process.default.cwd();
|
package/dist/cli.mjs
CHANGED
|
@@ -18,7 +18,6 @@ import "fast-glob";
|
|
|
18
18
|
import "tailwindcss-config";
|
|
19
19
|
import _babelTraverse from "@babel/traverse";
|
|
20
20
|
import { parse } from "@babel/parser";
|
|
21
|
-
import { escapeStringRegexp } from "@weapp-core/regex";
|
|
22
21
|
import MagicString from "magic-string";
|
|
23
22
|
import { jsStringEscape } from "@ast-core/escape";
|
|
24
23
|
import { splitCode } from "@weapp-tailwindcss/shared/extractors";
|
|
@@ -44,6 +43,163 @@ function createDebug(prefix) {
|
|
|
44
43
|
return debug;
|
|
45
44
|
}
|
|
46
45
|
//#endregion
|
|
46
|
+
//#region src/css-macro/constants.ts
|
|
47
|
+
const queryKey = "weapp-tw-platform";
|
|
48
|
+
const UNESCAPED_UNDERSCORE_RE = /(?<!\\)_/g;
|
|
49
|
+
const WHITESPACE_RE = /\s+/g;
|
|
50
|
+
const LOGICAL_OPERATOR_RE = /\s*(\|\||&&)\s*/g;
|
|
51
|
+
function normalComment(text) {
|
|
52
|
+
if (typeof text === "string") {
|
|
53
|
+
const normalized = text.replaceAll(UNESCAPED_UNDERSCORE_RE, " ").replaceAll(WHITESPACE_RE, " ").trim();
|
|
54
|
+
if (normalized.includes("\\")) return normalized;
|
|
55
|
+
return normalized.replaceAll(LOGICAL_OPERATOR_RE, " $1 ").replaceAll(WHITESPACE_RE, " ").trim();
|
|
56
|
+
}
|
|
57
|
+
return text;
|
|
58
|
+
}
|
|
59
|
+
function ifdef(text) {
|
|
60
|
+
return {
|
|
61
|
+
start: `#ifdef ${normalComment(text)}`,
|
|
62
|
+
end: `#endif`
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function ifndef(text) {
|
|
66
|
+
return {
|
|
67
|
+
start: `#ifndef ${normalComment(text)}`,
|
|
68
|
+
end: `#endif`
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const QUERY_KEY_REGEX = new RegExp(`\\(\\s*${queryKey}\\s*:\\s*"([^)]*)"\\)`, "g");
|
|
72
|
+
function matchCustomPropertyFromValue(str, cb) {
|
|
73
|
+
let index = 0;
|
|
74
|
+
QUERY_KEY_REGEX.lastIndex = 0;
|
|
75
|
+
let arr = QUERY_KEY_REGEX.exec(str);
|
|
76
|
+
while (arr !== null) {
|
|
77
|
+
cb(arr, index);
|
|
78
|
+
index++;
|
|
79
|
+
arr = QUERY_KEY_REGEX.exec(str);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function parseConditionalAtRuleParam(params) {
|
|
83
|
+
const value = params.trim();
|
|
84
|
+
const quoted = /^(['"])((?:\\.|(?!\1).)*)\1/.exec(value);
|
|
85
|
+
if (!quoted) return value;
|
|
86
|
+
return quoted[2]?.replaceAll(/\\(["'\\])/g, "$1") ?? "";
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/css-macro/postcss.ts
|
|
90
|
+
const IFDEF_ENDIF_RE = /#(?:ifn?def|endif)/;
|
|
91
|
+
const CONDITIONAL_COMMENT_SPACING = " ";
|
|
92
|
+
const CSS_MACRO_POSTCSS_PLUGIN_NAME = "postcss-weapp-tw-css-macro-plugin";
|
|
93
|
+
const creator = () => {
|
|
94
|
+
return {
|
|
95
|
+
postcssPlugin: CSS_MACRO_POSTCSS_PLUGIN_NAME,
|
|
96
|
+
prepare() {
|
|
97
|
+
function replaceAtRuleWithConditionalComments(atRule, helper, comment) {
|
|
98
|
+
const hasPreviousNode = Boolean(atRule.prev());
|
|
99
|
+
const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
|
|
100
|
+
const startComment = helper.comment({
|
|
101
|
+
raws: {
|
|
102
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
103
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
104
|
+
},
|
|
105
|
+
text: comment.start
|
|
106
|
+
});
|
|
107
|
+
const endComment = helper.comment({
|
|
108
|
+
raws: {
|
|
109
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
110
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
111
|
+
},
|
|
112
|
+
text: comment.end
|
|
113
|
+
});
|
|
114
|
+
const nextNodes = [
|
|
115
|
+
startComment,
|
|
116
|
+
...clonedNodes,
|
|
117
|
+
endComment
|
|
118
|
+
];
|
|
119
|
+
atRule.replaceWith(nextNodes);
|
|
120
|
+
startComment.raws.before = hasPreviousNode ? "\n" : "";
|
|
121
|
+
startComment.raws.after = "\n";
|
|
122
|
+
if (clonedNodes[0]) clonedNodes[0].raws.before = "\n";
|
|
123
|
+
endComment.raws.before = "\n";
|
|
124
|
+
endComment.raws.after = "\n";
|
|
125
|
+
const nextNode = endComment?.next();
|
|
126
|
+
if (nextNode) nextNode.raws.before = "\n";
|
|
127
|
+
}
|
|
128
|
+
function replaceNestedAtRuleWithConditionalRule(atRule, helper, comment) {
|
|
129
|
+
if (atRule.parent?.type !== "rule") return false;
|
|
130
|
+
const parentRule = atRule.parent;
|
|
131
|
+
const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
|
|
132
|
+
const conditionalRule = parentRule.clone();
|
|
133
|
+
conditionalRule.removeAll();
|
|
134
|
+
conditionalRule.append(...clonedNodes);
|
|
135
|
+
const startComment = helper.comment({
|
|
136
|
+
raws: {
|
|
137
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
138
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
139
|
+
},
|
|
140
|
+
text: comment.start
|
|
141
|
+
});
|
|
142
|
+
const endComment = helper.comment({
|
|
143
|
+
raws: {
|
|
144
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
145
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
146
|
+
},
|
|
147
|
+
text: comment.end
|
|
148
|
+
});
|
|
149
|
+
const nextNodes = [
|
|
150
|
+
startComment,
|
|
151
|
+
conditionalRule,
|
|
152
|
+
endComment
|
|
153
|
+
];
|
|
154
|
+
const hasPreviousNode = Boolean(parentRule.prev());
|
|
155
|
+
atRule.remove();
|
|
156
|
+
if ((parentRule.nodes?.length ?? 0) === 0) parentRule.replaceWith(nextNodes);
|
|
157
|
+
else parentRule.after(nextNodes);
|
|
158
|
+
startComment.raws.before = hasPreviousNode ? "\n" : "";
|
|
159
|
+
startComment.raws.after = "\n";
|
|
160
|
+
conditionalRule.raws.before = "\n";
|
|
161
|
+
endComment.raws.before = "\n";
|
|
162
|
+
endComment.raws.after = "\n";
|
|
163
|
+
const nextNode = endComment.next();
|
|
164
|
+
if (nextNode) nextNode.raws.before = "\n";
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
AtRule(atRule, helper) {
|
|
169
|
+
if (atRule.name === "weapp-tw-ifdef" || atRule.name === "weapp-tw-ifndef") {
|
|
170
|
+
const text = parseConditionalAtRuleParam(atRule.params);
|
|
171
|
+
const comment = atRule.name === "weapp-tw-ifndef" ? ifndef(text) : ifdef(text);
|
|
172
|
+
if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
|
|
173
|
+
replaceAtRuleWithConditionalComments(atRule, helper, comment);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (atRule.name === "media") {
|
|
177
|
+
const values = [];
|
|
178
|
+
matchCustomPropertyFromValue(atRule.params, (arr) => {
|
|
179
|
+
const value = arr[1];
|
|
180
|
+
if (value) values.push(value);
|
|
181
|
+
});
|
|
182
|
+
if (values.length > 0) {
|
|
183
|
+
const isNegative = atRule.params.includes("not");
|
|
184
|
+
const text = values.join(" ");
|
|
185
|
+
const comment = isNegative ? ifndef(text) : ifdef(text);
|
|
186
|
+
if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
|
|
187
|
+
replaceAtRuleWithConditionalComments(atRule, helper, comment);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
CommentExit(comment) {
|
|
192
|
+
if (IFDEF_ENDIF_RE.test(comment.text)) {
|
|
193
|
+
comment.raws.left = CONDITIONAL_COMMENT_SPACING;
|
|
194
|
+
comment.raws.right = CONDITIONAL_COMMENT_SPACING;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
creator.postcss = true;
|
|
202
|
+
//#endregion
|
|
47
203
|
//#region src/tailwindcss/source-scan.ts
|
|
48
204
|
const DEFAULT_SOURCE_SCAN_EXTENSIONS = [
|
|
49
205
|
"html",
|
|
@@ -504,15 +660,18 @@ runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ ?? (runtimeLogDedupeHolde
|
|
|
504
660
|
const globalCacheHolder = globalThis;
|
|
505
661
|
globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
|
|
506
662
|
//#endregion
|
|
507
|
-
//#region src/constants.ts
|
|
508
|
-
const WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
|
|
509
|
-
//#endregion
|
|
510
663
|
//#region src/babel/index.ts
|
|
511
664
|
function _interopDefaultCompat(e) {
|
|
512
665
|
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
513
666
|
}
|
|
514
667
|
const traverse = _interopDefaultCompat(_babelTraverse);
|
|
515
668
|
//#endregion
|
|
669
|
+
//#region src/utils/regex.ts
|
|
670
|
+
function escapeStringRegexp(str) {
|
|
671
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
672
|
+
return str.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&").replaceAll("-", "\\x2d");
|
|
673
|
+
}
|
|
674
|
+
//#endregion
|
|
516
675
|
//#region src/utils/nameMatcher.ts
|
|
517
676
|
const NEVER_MATCH_NAME$1 = () => false;
|
|
518
677
|
const GLOBAL_FLAG_REGEXP = /g/g;
|
|
@@ -2077,6 +2236,9 @@ var Tokenizer = class {
|
|
|
2077
2236
|
};
|
|
2078
2237
|
new Tokenizer();
|
|
2079
2238
|
//#endregion
|
|
2239
|
+
//#region src/constants.ts
|
|
2240
|
+
const WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
|
|
2241
|
+
//#endregion
|
|
2080
2242
|
//#region src/cli/context.ts
|
|
2081
2243
|
function formatOutputPath(target, baseDir) {
|
|
2082
2244
|
const root = baseDir ?? process.cwd();
|
package/dist/core.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("./chunk-8l464Juk.js");
|
|
3
|
-
const require_precheck = require("./precheck-
|
|
3
|
+
const require_precheck = require("./precheck-ezN3ovAq.js");
|
|
4
4
|
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
5
5
|
//#region src/core.ts
|
|
6
6
|
const DEFAULT_MAIN_CHUNK_STYLE_OPTIONS = Object.freeze({ isMainChunk: true });
|
package/dist/core.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { _ as createTailwindRuntimeReadyPromise, n as getCompilerContext, t as shouldSkipJsTransform, v as ensureRuntimeClassSet } from "./precheck-B4CpMt_w.mjs";
|
|
2
2
|
import { defuOverrideArray } from "@weapp-tailwindcss/shared";
|
|
3
3
|
//#region src/core.ts
|
|
4
4
|
const DEFAULT_MAIN_CHUNK_STYLE_OPTIONS = Object.freeze({ isMainChunk: true });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IStyleHandlerOptions } from '@weapp-tailwindcss/postcss/types';
|
|
2
|
+
export declare const CSS_MACRO_PLUGIN_MARKER = "__weappTailwindcssCssMacro";
|
|
3
|
+
export declare const CSS_MACRO_STYLE_OPTIONS_MARKER = "__weappTailwindcssCssMacroEnabled";
|
|
4
|
+
export declare function markCssMacroPlugin<T extends object>(value: T): T;
|
|
5
|
+
export declare function isCssMacroTailwindPlugin(value: unknown): boolean;
|
|
6
|
+
export declare function hasCssMacroTailwindPlugin(plugins: unknown): boolean;
|
|
7
|
+
export declare function hasCssMacroTailwindV4Directive(css: string | undefined): boolean;
|
|
8
|
+
export declare function withCssMacroStyleOptions(options: Partial<IStyleHandlerOptions> | undefined): Partial<IStyleHandlerOptions>;
|
|
9
|
+
export declare function hasCssMacroStyleOptions(options: Partial<IStyleHandlerOptions> | undefined): boolean;
|
|
10
|
+
export declare function transformCssMacroCss(css: string): Promise<string>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export declare const uniAppPlatform: string[];
|
|
2
2
|
export declare const queryKey = "weapp-tw-platform";
|
|
3
|
-
export declare
|
|
4
|
-
export declare
|
|
3
|
+
export declare const ifdefAtRule = "weapp-tw-ifdef";
|
|
4
|
+
export declare const ifndefAtRule = "weapp-tw-ifndef";
|
|
5
|
+
export declare function createConditionalAtRule(value: string): string;
|
|
6
|
+
export declare function createNegativeConditionalAtRule(value: string): string;
|
|
5
7
|
export declare function normalComment(text: string): string;
|
|
6
8
|
export declare function ifdef(text: string): {
|
|
7
9
|
start: string;
|
|
@@ -12,3 +14,4 @@ export declare function ifndef(text: string): {
|
|
|
12
14
|
end: string;
|
|
13
15
|
};
|
|
14
16
|
export declare function matchCustomPropertyFromValue(str: string, cb: (arr: RegExpExecArray, index: number) => void): void;
|
|
17
|
+
export declare function parseConditionalAtRuleParam(params: string): string;
|