weapp-tailwindcss 5.0.0-next.8 → 5.0.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.
Files changed (167) hide show
  1. package/README.md +2 -2
  2. package/dist/auto-DEHRmEAx.mjs +200 -0
  3. package/dist/auto-dPpsm6FB.js +238 -0
  4. package/dist/bundle-state-CnaJxkFY.mjs +413 -0
  5. package/dist/bundle-state-DgGEhk_z.js +529 -0
  6. package/dist/bundlers/shared/cache.d.ts +9 -7
  7. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +1 -2
  8. package/dist/bundlers/shared/css-cleanup.d.ts +1 -3
  9. package/dist/bundlers/shared/css-imports.d.ts +3 -3
  10. package/dist/bundlers/shared/generated-css-marker.d.ts +3 -0
  11. package/dist/bundlers/shared/generator-css/directives.d.ts +12 -3
  12. package/dist/bundlers/shared/generator-css/markers.d.ts +12 -0
  13. package/dist/bundlers/shared/generator-css/source-files.d.ts +9 -6
  14. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +16 -2
  15. package/dist/bundlers/shared/generator-css/user-layer-order.d.ts +10 -0
  16. package/dist/bundlers/shared/generator-css.d.ts +6 -2
  17. package/dist/bundlers/shared/hmr-timing.d.ts +22 -0
  18. package/dist/bundlers/shared/style-requests.d.ts +2 -0
  19. package/dist/bundlers/vite/bundle-state.d.ts +1 -0
  20. package/dist/bundlers/vite/css-finalizer.d.ts +6 -0
  21. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +1 -1
  22. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +5 -1
  23. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +1 -0
  24. package/dist/bundlers/vite/generate-bundle.d.ts +13 -1
  25. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +10 -2
  26. package/dist/bundlers/vite/index.d.ts +5 -2
  27. package/dist/bundlers/vite/processed-css-assets.d.ts +32 -0
  28. package/dist/bundlers/vite/rewrite-css-imports.d.ts +8 -5
  29. package/dist/bundlers/vite/runtime-class-set.d.ts +5 -1
  30. package/dist/bundlers/vite/serve-css-generation.d.ts +11 -0
  31. package/dist/bundlers/vite/source-candidates.d.ts +24 -2
  32. package/dist/bundlers/vite/source-scan.d.ts +26 -0
  33. package/dist/bundlers/vite/static-config-content.d.ts +5 -0
  34. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +5 -0
  35. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +5 -1
  36. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +8 -3
  37. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -1
  38. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +31 -0
  39. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +2 -8
  40. package/dist/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.d.ts +3 -7
  41. package/dist/cache/index.d.ts +6 -6
  42. package/dist/{chunk-8l464Juk.js → chunk-C5U5_Hdc.js} +14 -0
  43. package/dist/cli/context.d.ts +1 -11
  44. package/dist/cli/doctor/types.d.ts +11 -11
  45. package/dist/cli/vscode-entry.d.ts +3 -3
  46. package/dist/cli.js +684 -41
  47. package/dist/cli.mjs +682 -40
  48. package/dist/context/runtime-package-replacements.d.ts +2 -0
  49. package/dist/context/style-options.d.ts +3 -0
  50. package/dist/context/tailwindcss.d.ts +1 -1
  51. package/dist/core.js +1 -2
  52. package/dist/core.mjs +1 -1
  53. package/dist/css-macro/auto.d.ts +11 -0
  54. package/dist/css-macro/constants.d.ts +5 -2
  55. package/dist/css-macro/postcss.d.ts +1 -0
  56. package/dist/css-macro/postcss.js +7 -46
  57. package/dist/css-macro/postcss.mjs +2 -46
  58. package/dist/css-macro.js +16 -7
  59. package/dist/css-macro.mjs +15 -6
  60. package/dist/defaults-8xrgzxFY.mjs +151 -0
  61. package/dist/defaults-zKUH2mDe.js +193 -0
  62. package/dist/defaults.js +6 -150
  63. package/dist/defaults.mjs +1 -143
  64. package/dist/escape.js +10 -2
  65. package/dist/escape.mjs +10 -2
  66. package/dist/generator/options.d.ts +11 -6
  67. package/dist/generator/types.d.ts +3 -3
  68. package/dist/generator--0-ekuVO.js +92 -0
  69. package/dist/generator-B76ovqsv.mjs +67 -0
  70. package/dist/generator.js +12 -12
  71. package/dist/generator.mjs +2 -1
  72. package/dist/gulp.js +163 -40
  73. package/dist/gulp.mjs +155 -32
  74. package/dist/incremental-runtime-class-set-CN6K_97P.js +2366 -0
  75. package/dist/incremental-runtime-class-set-x10M9bn_.mjs +2291 -0
  76. package/dist/index.d.ts +2 -1
  77. package/dist/index.js +17 -5
  78. package/dist/index.mjs +6 -5
  79. package/dist/js/babel/cache-options.d.ts +3 -0
  80. package/dist/js/babel/parse.d.ts +7 -4
  81. package/dist/js/precheck.d.ts +2 -2
  82. package/dist/js/replacement-cache.d.ts +5 -0
  83. package/dist/postcss-C7BMYpEF.mjs +169 -0
  84. package/dist/{postcss-w48mGIhe.mjs → postcss-CR9UCaIK.mjs} +54 -114
  85. package/dist/postcss-CiYLsqZn.js +192 -0
  86. package/dist/{postcss-QIXwT40c.js → postcss-hYimKoN_.js} +60 -121
  87. package/dist/postcss-html-transform.js +1 -1
  88. package/dist/postcss.js +1 -1
  89. package/dist/postcss.mjs +1 -1
  90. package/dist/precheck-BrNwLG2e.mjs +4716 -0
  91. package/dist/precheck-DPtJjZmV.js +4842 -0
  92. package/dist/presets/index.d.ts +1 -0
  93. package/dist/presets/uni-app-x.d.ts +1 -0
  94. package/dist/presets.js +27 -13
  95. package/dist/presets.mjs +25 -13
  96. package/dist/reset.js +1 -1
  97. package/dist/runtime-registry-DpcR3IHI.js +5496 -0
  98. package/dist/shared/mpx.d.ts +1 -0
  99. package/dist/source-candidates-DN1mihlU.mjs +322 -0
  100. package/dist/source-candidates-DSxme_O2.js +335 -0
  101. package/dist/tailwindcss/miniprogram.d.ts +1 -5
  102. package/dist/tailwindcss/remove-unsupported-css.d.ts +1 -2
  103. package/dist/tailwindcss/runtime/cache.d.ts +4 -3
  104. package/dist/tailwindcss/runtime.d.ts +9 -9
  105. package/dist/tailwindcss/source-scan.d.ts +35 -0
  106. package/dist/tailwindcss/v3-engine/types.d.ts +19 -14
  107. package/dist/tailwindcss/v4/css-entries.d.ts +2 -2
  108. package/dist/tailwindcss/v4/patcher.d.ts +1 -1
  109. package/dist/tailwindcss/v4-engine/source.d.ts +2 -2
  110. package/dist/tailwindcss/v4-engine/types.d.ts +18 -5
  111. package/dist/{tailwindcss-C5IgPlQ0.mjs → tailwindcss-DWtPieNE.mjs} +72 -60
  112. package/dist/{tailwindcss-Bu-RWIHx.js → tailwindcss-glCm_d3H.js} +81 -69
  113. package/dist/typedoc.export.d.ts +1 -1
  114. package/dist/types/index.d.ts +51 -41
  115. package/dist/types/shared.d.ts +3 -0
  116. package/dist/types/typedoc-tailwindcss-patch.d.ts +67 -0
  117. package/dist/types/user-defined-options/general.d.ts +25 -22
  118. package/dist/types/user-defined-options/important.d.ts +32 -27
  119. package/dist/types/user-defined-options/lifecycle.d.ts +4 -4
  120. package/dist/types/user-defined-options/matcher.d.ts +6 -6
  121. package/dist/unocss/index.d.ts +2 -0
  122. package/dist/utils/object.d.ts +9 -0
  123. package/dist/utils/options.d.ts +2 -0
  124. package/dist/utils/regex.d.ts +1 -0
  125. package/dist/{utils-BiShvil9.js → utils-D7Ygohep.js} +2 -2
  126. package/dist/{utils-Btw1iOVV.mjs → utils-DsaS975I.mjs} +1 -1
  127. package/dist/v3-engine-D3BMLVAN.js +3712 -0
  128. package/dist/v3-engine-DCxNPBVs.mjs +3417 -0
  129. package/dist/vite-DOprpdH-.mjs +24493 -0
  130. package/dist/vite-Ec0uX6kF.js +24507 -0
  131. package/dist/vite.js +1 -1
  132. package/dist/vite.mjs +1 -1
  133. package/dist/weapp-tw-css-import-rewrite-loader.js +5444 -22
  134. package/dist/weapp-tw-runtime-classset-loader.js +32 -9
  135. package/dist/{webpack-CNV2dx3Q.js → webpack-Ccohlg3A.js} +341 -96
  136. package/dist/{webpack-CT6EEENx.mjs → webpack-DFlZcqAU.mjs} +323 -79
  137. package/dist/webpack.d.ts +1 -3
  138. package/dist/webpack.js +3 -4
  139. package/dist/webpack.mjs +2 -2
  140. package/dist/wxml/utils/codegen/legacy-visitor.d.ts +2 -4
  141. package/package.json +22 -20
  142. package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +0 -3
  143. package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +0 -4
  144. package/dist/bundlers/shared/css-cleanup/selectors.d.ts +0 -8
  145. package/dist/cache-BVAiJV3J.js +0 -502
  146. package/dist/cache-CHs4DXui.mjs +0 -434
  147. package/dist/constants-BoB_6lFw.js +0 -73
  148. package/dist/constants-E_loJC49.mjs +0 -44
  149. package/dist/generator-DKkhJbOg.js +0 -1531
  150. package/dist/generator-UBmfduYg.mjs +0 -1432
  151. package/dist/generator-css-BIapP56i.mjs +0 -1323
  152. package/dist/generator-css-Mksw8PgB.js +0 -1362
  153. package/dist/lightningcss/index.d.ts +0 -8
  154. package/dist/lightningcss/style-handler/options.d.ts +0 -3
  155. package/dist/lightningcss/style-handler/selector-transform.d.ts +0 -10
  156. package/dist/lightningcss/style-handler/selector-utils.d.ts +0 -10
  157. package/dist/lightningcss/style-handler.d.ts +0 -17
  158. package/dist/precheck-B32p-gLI.js +0 -2736
  159. package/dist/precheck-B4RH6ZNN.mjs +0 -2622
  160. package/dist/run-tasks-B50A3pxt.js +0 -128
  161. package/dist/run-tasks-DdNi-hkk.mjs +0 -91
  162. package/dist/runtime-patch-CwN5ya72.mjs +0 -71
  163. package/dist/runtime-patch-D6mBo_KB.js +0 -85
  164. package/dist/vite-BwgRVgxH.mjs +0 -2405
  165. package/dist/vite-DyZuiyap.js +0 -2418
  166. /package/dist/{logger-Bub1jggA.mjs → logger-BNzxZbZj.mjs} +0 -0
  167. /package/dist/{logger-BRy6XPQ2.js → logger-TlKT3xmR.js} +0 -0
package/README.md CHANGED
@@ -73,9 +73,9 @@
73
73
 
74
74
  ## [配置项参考](https://tw.icebreaker.top/docs/api/interfaces/UserDefinedOptions)
75
75
 
76
- ### Tailwind CSS v4 自动前缀
76
+ ### Tailwind CSS 自动前缀
77
77
 
78
- 在 Tailwind CSS v4 场景下,`weapp-tailwindcss` 会默认对生成后的小程序 CSS 执行内置 `autoprefixer` 后处理,用于补齐小程序 WebView 需要的兼容前缀。例如 `bg-clip-text` 会输出 `-webkit-background-clip: text`,从而支持渐变文字。
78
+ 在 Tailwind CSS v3 / v4 场景下,`weapp-tailwindcss` 会默认对生成后的小程序 CSS 执行内置 `autoprefixer` 后处理,用于补齐小程序 WebView 需要的兼容前缀。例如 `bg-clip-text` 会输出 `-webkit-background-clip: text`,从而支持渐变文字。
79
79
 
80
80
  通常不再需要在业务项目的 `postcss.config.js` 中手动配置 `autoprefixer`。如果项目已经显式配置了 `autoprefixer`,内置后处理会避免重复追加。需要关闭时可配置:
81
81
 
@@ -0,0 +1,200 @@
1
+ import { n as creator } from "./postcss-C7BMYpEF.mjs";
2
+ import postcss from "postcss";
3
+ import process from "node:process";
4
+ //#region src/css-macro/auto.ts
5
+ const CSS_MACRO_PLUGIN_MARKER = "__weappTailwindcssCssMacro";
6
+ const CSS_MACRO_STYLE_OPTIONS_MARKER = "__weappTailwindcssCssMacroEnabled";
7
+ const PLATFORM_ENV_KEYS = [
8
+ "WEAPP_TW_TARGET",
9
+ "WEAPP_TAILWINDCSS_TARGET",
10
+ "UNI_PLATFORM",
11
+ "UNI_UTS_PLATFORM",
12
+ "TARO_ENV",
13
+ "MPX_CLI_MODE",
14
+ "MPX_CURRENT_TARGET_MODE"
15
+ ];
16
+ const CONDITIONAL_END_RE = /^\s*#endif\s*$/;
17
+ function readEnvValue(key) {
18
+ return typeof process === "undefined" ? void 0 : process.env[key];
19
+ }
20
+ function normalizePlatformToken(value) {
21
+ return value?.trim().replaceAll("_", "-").toUpperCase() || void 0;
22
+ }
23
+ function resolveCssMacroPlatform(options) {
24
+ const explicit = normalizePlatformToken(options?.platform);
25
+ if (explicit) return explicit;
26
+ for (const key of PLATFORM_ENV_KEYS) {
27
+ const value = normalizePlatformToken(readEnvValue(key));
28
+ if (value) return value;
29
+ }
30
+ }
31
+ function createPlatformTokenSet(platform) {
32
+ const normalized = normalizePlatformToken(platform);
33
+ const tokens = /* @__PURE__ */ new Set();
34
+ if (!normalized) return tokens;
35
+ tokens.add(normalized);
36
+ if (normalized.startsWith("MP-")) tokens.add("MP");
37
+ if (normalized === "WEAPP" || normalized === "WEIXIN" || normalized === "WX") {
38
+ tokens.add("MP");
39
+ tokens.add("MP-WEIXIN");
40
+ }
41
+ if (normalized === "MP-WEIXIN") {
42
+ tokens.add("WEAPP");
43
+ tokens.add("WEIXIN");
44
+ tokens.add("WX");
45
+ }
46
+ if (normalized === "H5") tokens.add("WEB");
47
+ if (normalized === "WEB") tokens.add("H5");
48
+ if (normalized === "APP") tokens.add("APP-PLUS");
49
+ if (normalized.startsWith("APP-")) tokens.add("APP");
50
+ if (normalized.startsWith("QUICKAPP-WEBVIEW")) tokens.add("QUICKAPP-WEBVIEW");
51
+ return tokens;
52
+ }
53
+ function combineAnd(values) {
54
+ if (values.includes(false)) return false;
55
+ return values.every((value) => value === true) ? true : void 0;
56
+ }
57
+ function combineOr(values) {
58
+ if (values.includes(true)) return true;
59
+ return values.every((value) => value === false) ? false : void 0;
60
+ }
61
+ function evaluatePlatformExpression(expression, platformTokens) {
62
+ return combineOr(expression.split(/\s*\|\|\s*/).map((orPart) => {
63
+ return combineAnd(orPart.split(/\s*&&\s*/).map((part) => {
64
+ const token = normalizePlatformToken(part);
65
+ if (!token || /[<>=!()]/.test(token)) return;
66
+ return platformTokens.has(token);
67
+ }));
68
+ }));
69
+ }
70
+ function negateConditionalValue(value) {
71
+ return value === void 0 ? void 0 : !value;
72
+ }
73
+ function getActiveConditionalValue(stack) {
74
+ if (stack.includes(false)) return false;
75
+ return stack.includes(void 0) ? void 0 : true;
76
+ }
77
+ function parseConditionalStart(text) {
78
+ const normalized = text.trim();
79
+ if (!normalized.startsWith("#")) return;
80
+ const body = normalized.slice(1).trimStart();
81
+ for (const directive of ["ifndef", "ifdef"]) {
82
+ if (!body.startsWith(directive)) continue;
83
+ const expression = body.slice(directive.length).trim();
84
+ if (expression.length === 0) return;
85
+ return {
86
+ directive,
87
+ expression
88
+ };
89
+ }
90
+ }
91
+ function compileCssMacroConditionalComments(css, options) {
92
+ const platformTokens = createPlatformTokenSet(resolveCssMacroPlatform(options));
93
+ if (platformTokens.size === 0 || !css.includes("#if")) return css;
94
+ try {
95
+ const root = postcss.parse(css);
96
+ const transformContainer = (container) => {
97
+ const stack = [];
98
+ for (const node of [...container.nodes ?? []]) {
99
+ if (node.type === "comment") {
100
+ const start = parseConditionalStart(node.text);
101
+ if (start) {
102
+ const value = start.directive === "ifndef" ? negateConditionalValue(evaluatePlatformExpression(start.expression, platformTokens)) : evaluatePlatformExpression(start.expression, platformTokens);
103
+ const parentActive = getActiveConditionalValue(stack);
104
+ stack.push(value);
105
+ if (parentActive !== void 0 && value !== void 0) node.remove();
106
+ continue;
107
+ }
108
+ if (CONDITIONAL_END_RE.test(node.text)) {
109
+ const value = stack.pop();
110
+ if (getActiveConditionalValue(stack) !== void 0 && value !== void 0) node.remove();
111
+ continue;
112
+ }
113
+ }
114
+ if (getActiveConditionalValue(stack) === false) {
115
+ node.remove();
116
+ continue;
117
+ }
118
+ if ("nodes" in node && node.nodes) transformContainer(node);
119
+ }
120
+ };
121
+ transformContainer(root);
122
+ return root.toString();
123
+ } catch {
124
+ return css;
125
+ }
126
+ }
127
+ function markCssMacroPlugin(value) {
128
+ Object.defineProperty(value, CSS_MACRO_PLUGIN_MARKER, {
129
+ configurable: false,
130
+ enumerable: false,
131
+ value: true
132
+ });
133
+ return value;
134
+ }
135
+ function isCssMacroTailwindPlugin(value) {
136
+ return Boolean(value && (typeof value === "function" || typeof value === "object") && value["__weappTailwindcssCssMacro"] === true);
137
+ }
138
+ function hasCssMacroTailwindPlugin(plugins) {
139
+ if (!plugins) return false;
140
+ if (Array.isArray(plugins)) return plugins.some(isCssMacroTailwindPlugin);
141
+ if (typeof plugins === "object") return Object.values(plugins).some(isCssMacroTailwindPlugin);
142
+ return false;
143
+ }
144
+ function parseCssPluginRequest(params) {
145
+ const value = params.trim();
146
+ const quoted = /^(['"])(.*?)\1/.exec(value);
147
+ if (quoted) return quoted[2];
148
+ const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
149
+ return url?.[2] ?? url?.[3];
150
+ }
151
+ function isCssMacroPluginRequest(request) {
152
+ return request === "weapp-tailwindcss/css-macro";
153
+ }
154
+ function hasCssMacroTailwindV4Directive(css) {
155
+ if (!css?.includes("css-macro")) return false;
156
+ try {
157
+ let found = false;
158
+ postcss.parse(css).walkAtRules("plugin", (rule) => {
159
+ if (isCssMacroPluginRequest(parseCssPluginRequest(rule.params))) found = true;
160
+ });
161
+ return found;
162
+ } catch {
163
+ return /@plugin\s+(?:url\(\s*)?["']weapp-tailwindcss\/css-macro["']/.test(css);
164
+ }
165
+ }
166
+ function isCssMacroPostcssPlugin(plugin) {
167
+ if (plugin === creator) return true;
168
+ return Boolean(plugin && (typeof plugin === "function" || typeof plugin === "object") && plugin.postcssPlugin === "postcss-weapp-tw-css-macro-plugin");
169
+ }
170
+ function withCssMacroPostcssPlugins(plugins) {
171
+ const macroPlugin = creator();
172
+ if (!plugins) return [macroPlugin];
173
+ if (Array.isArray(plugins)) return plugins.some(isCssMacroPostcssPlugin) ? plugins : [...plugins, macroPlugin];
174
+ if (typeof plugins === "object") {
175
+ const values = Object.values(plugins).filter(Boolean);
176
+ if (values.some(isCssMacroPostcssPlugin)) return values;
177
+ return [...values, macroPlugin];
178
+ }
179
+ return [macroPlugin];
180
+ }
181
+ function withCssMacroStyleOptions(options) {
182
+ const postcssOptions = options?.postcssOptions;
183
+ return {
184
+ ...options,
185
+ [CSS_MACRO_STYLE_OPTIONS_MARKER]: true,
186
+ postcssOptions: {
187
+ ...postcssOptions,
188
+ plugins: withCssMacroPostcssPlugins(postcssOptions?.plugins)
189
+ }
190
+ };
191
+ }
192
+ function hasCssMacroStyleOptions(options) {
193
+ return Boolean(options?.[CSS_MACRO_STYLE_OPTIONS_MARKER]);
194
+ }
195
+ async function transformCssMacroCss(css, options) {
196
+ const result = (await postcss([creator()]).process(css, { from: void 0 })).css;
197
+ return compileCssMacroConditionalComments(result, options);
198
+ }
199
+ //#endregion
200
+ export { transformCssMacroCss as a, markCssMacroPlugin as i, hasCssMacroTailwindPlugin as n, withCssMacroStyleOptions as o, hasCssMacroTailwindV4Directive as r, hasCssMacroStyleOptions as t };
@@ -0,0 +1,238 @@
1
+ const require_chunk = require("./chunk-C5U5_Hdc.js");
2
+ const require_postcss = require("./postcss-CiYLsqZn.js");
3
+ let postcss = require("postcss");
4
+ postcss = require_chunk.__toESM(postcss);
5
+ let node_process = require("node:process");
6
+ node_process = require_chunk.__toESM(node_process);
7
+ //#region src/css-macro/auto.ts
8
+ const CSS_MACRO_PLUGIN_MARKER = "__weappTailwindcssCssMacro";
9
+ const CSS_MACRO_STYLE_OPTIONS_MARKER = "__weappTailwindcssCssMacroEnabled";
10
+ const PLATFORM_ENV_KEYS = [
11
+ "WEAPP_TW_TARGET",
12
+ "WEAPP_TAILWINDCSS_TARGET",
13
+ "UNI_PLATFORM",
14
+ "UNI_UTS_PLATFORM",
15
+ "TARO_ENV",
16
+ "MPX_CLI_MODE",
17
+ "MPX_CURRENT_TARGET_MODE"
18
+ ];
19
+ const CONDITIONAL_END_RE = /^\s*#endif\s*$/;
20
+ function readEnvValue(key) {
21
+ return typeof node_process.default === "undefined" ? void 0 : node_process.default.env[key];
22
+ }
23
+ function normalizePlatformToken(value) {
24
+ return value?.trim().replaceAll("_", "-").toUpperCase() || void 0;
25
+ }
26
+ function resolveCssMacroPlatform(options) {
27
+ const explicit = normalizePlatformToken(options?.platform);
28
+ if (explicit) return explicit;
29
+ for (const key of PLATFORM_ENV_KEYS) {
30
+ const value = normalizePlatformToken(readEnvValue(key));
31
+ if (value) return value;
32
+ }
33
+ }
34
+ function createPlatformTokenSet(platform) {
35
+ const normalized = normalizePlatformToken(platform);
36
+ const tokens = /* @__PURE__ */ new Set();
37
+ if (!normalized) return tokens;
38
+ tokens.add(normalized);
39
+ if (normalized.startsWith("MP-")) tokens.add("MP");
40
+ if (normalized === "WEAPP" || normalized === "WEIXIN" || normalized === "WX") {
41
+ tokens.add("MP");
42
+ tokens.add("MP-WEIXIN");
43
+ }
44
+ if (normalized === "MP-WEIXIN") {
45
+ tokens.add("WEAPP");
46
+ tokens.add("WEIXIN");
47
+ tokens.add("WX");
48
+ }
49
+ if (normalized === "H5") tokens.add("WEB");
50
+ if (normalized === "WEB") tokens.add("H5");
51
+ if (normalized === "APP") tokens.add("APP-PLUS");
52
+ if (normalized.startsWith("APP-")) tokens.add("APP");
53
+ if (normalized.startsWith("QUICKAPP-WEBVIEW")) tokens.add("QUICKAPP-WEBVIEW");
54
+ return tokens;
55
+ }
56
+ function combineAnd(values) {
57
+ if (values.includes(false)) return false;
58
+ return values.every((value) => value === true) ? true : void 0;
59
+ }
60
+ function combineOr(values) {
61
+ if (values.includes(true)) return true;
62
+ return values.every((value) => value === false) ? false : void 0;
63
+ }
64
+ function evaluatePlatformExpression(expression, platformTokens) {
65
+ return combineOr(expression.split(/\s*\|\|\s*/).map((orPart) => {
66
+ return combineAnd(orPart.split(/\s*&&\s*/).map((part) => {
67
+ const token = normalizePlatformToken(part);
68
+ if (!token || /[<>=!()]/.test(token)) return;
69
+ return platformTokens.has(token);
70
+ }));
71
+ }));
72
+ }
73
+ function negateConditionalValue(value) {
74
+ return value === void 0 ? void 0 : !value;
75
+ }
76
+ function getActiveConditionalValue(stack) {
77
+ if (stack.includes(false)) return false;
78
+ return stack.includes(void 0) ? void 0 : true;
79
+ }
80
+ function parseConditionalStart(text) {
81
+ const normalized = text.trim();
82
+ if (!normalized.startsWith("#")) return;
83
+ const body = normalized.slice(1).trimStart();
84
+ for (const directive of ["ifndef", "ifdef"]) {
85
+ if (!body.startsWith(directive)) continue;
86
+ const expression = body.slice(directive.length).trim();
87
+ if (expression.length === 0) return;
88
+ return {
89
+ directive,
90
+ expression
91
+ };
92
+ }
93
+ }
94
+ function compileCssMacroConditionalComments(css, options) {
95
+ const platformTokens = createPlatformTokenSet(resolveCssMacroPlatform(options));
96
+ if (platformTokens.size === 0 || !css.includes("#if")) return css;
97
+ try {
98
+ const root = postcss.default.parse(css);
99
+ const transformContainer = (container) => {
100
+ const stack = [];
101
+ for (const node of [...container.nodes ?? []]) {
102
+ if (node.type === "comment") {
103
+ const start = parseConditionalStart(node.text);
104
+ if (start) {
105
+ const value = start.directive === "ifndef" ? negateConditionalValue(evaluatePlatformExpression(start.expression, platformTokens)) : evaluatePlatformExpression(start.expression, platformTokens);
106
+ const parentActive = getActiveConditionalValue(stack);
107
+ stack.push(value);
108
+ if (parentActive !== void 0 && value !== void 0) node.remove();
109
+ continue;
110
+ }
111
+ if (CONDITIONAL_END_RE.test(node.text)) {
112
+ const value = stack.pop();
113
+ if (getActiveConditionalValue(stack) !== void 0 && value !== void 0) node.remove();
114
+ continue;
115
+ }
116
+ }
117
+ if (getActiveConditionalValue(stack) === false) {
118
+ node.remove();
119
+ continue;
120
+ }
121
+ if ("nodes" in node && node.nodes) transformContainer(node);
122
+ }
123
+ };
124
+ transformContainer(root);
125
+ return root.toString();
126
+ } catch {
127
+ return css;
128
+ }
129
+ }
130
+ function markCssMacroPlugin(value) {
131
+ Object.defineProperty(value, CSS_MACRO_PLUGIN_MARKER, {
132
+ configurable: false,
133
+ enumerable: false,
134
+ value: true
135
+ });
136
+ return value;
137
+ }
138
+ function isCssMacroTailwindPlugin(value) {
139
+ return Boolean(value && (typeof value === "function" || typeof value === "object") && value["__weappTailwindcssCssMacro"] === true);
140
+ }
141
+ function hasCssMacroTailwindPlugin(plugins) {
142
+ if (!plugins) return false;
143
+ if (Array.isArray(plugins)) return plugins.some(isCssMacroTailwindPlugin);
144
+ if (typeof plugins === "object") return Object.values(plugins).some(isCssMacroTailwindPlugin);
145
+ return false;
146
+ }
147
+ function parseCssPluginRequest(params) {
148
+ const value = params.trim();
149
+ const quoted = /^(['"])(.*?)\1/.exec(value);
150
+ if (quoted) return quoted[2];
151
+ const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
152
+ return url?.[2] ?? url?.[3];
153
+ }
154
+ function isCssMacroPluginRequest(request) {
155
+ return request === "weapp-tailwindcss/css-macro";
156
+ }
157
+ function hasCssMacroTailwindV4Directive(css) {
158
+ if (!css?.includes("css-macro")) return false;
159
+ try {
160
+ let found = false;
161
+ postcss.default.parse(css).walkAtRules("plugin", (rule) => {
162
+ if (isCssMacroPluginRequest(parseCssPluginRequest(rule.params))) found = true;
163
+ });
164
+ return found;
165
+ } catch {
166
+ return /@plugin\s+(?:url\(\s*)?["']weapp-tailwindcss\/css-macro["']/.test(css);
167
+ }
168
+ }
169
+ function isCssMacroPostcssPlugin(plugin) {
170
+ if (plugin === require_postcss.creator) return true;
171
+ return Boolean(plugin && (typeof plugin === "function" || typeof plugin === "object") && plugin.postcssPlugin === "postcss-weapp-tw-css-macro-plugin");
172
+ }
173
+ function withCssMacroPostcssPlugins(plugins) {
174
+ const macroPlugin = require_postcss.creator();
175
+ if (!plugins) return [macroPlugin];
176
+ if (Array.isArray(plugins)) return plugins.some(isCssMacroPostcssPlugin) ? plugins : [...plugins, macroPlugin];
177
+ if (typeof plugins === "object") {
178
+ const values = Object.values(plugins).filter(Boolean);
179
+ if (values.some(isCssMacroPostcssPlugin)) return values;
180
+ return [...values, macroPlugin];
181
+ }
182
+ return [macroPlugin];
183
+ }
184
+ function withCssMacroStyleOptions(options) {
185
+ const postcssOptions = options?.postcssOptions;
186
+ return {
187
+ ...options,
188
+ [CSS_MACRO_STYLE_OPTIONS_MARKER]: true,
189
+ postcssOptions: {
190
+ ...postcssOptions,
191
+ plugins: withCssMacroPostcssPlugins(postcssOptions?.plugins)
192
+ }
193
+ };
194
+ }
195
+ function hasCssMacroStyleOptions(options) {
196
+ return Boolean(options?.[CSS_MACRO_STYLE_OPTIONS_MARKER]);
197
+ }
198
+ async function transformCssMacroCss(css, options) {
199
+ const result = (await (0, postcss.default)([require_postcss.creator()]).process(css, { from: void 0 })).css;
200
+ return compileCssMacroConditionalComments(result, options);
201
+ }
202
+ //#endregion
203
+ Object.defineProperty(exports, "hasCssMacroStyleOptions", {
204
+ enumerable: true,
205
+ get: function() {
206
+ return hasCssMacroStyleOptions;
207
+ }
208
+ });
209
+ Object.defineProperty(exports, "hasCssMacroTailwindPlugin", {
210
+ enumerable: true,
211
+ get: function() {
212
+ return hasCssMacroTailwindPlugin;
213
+ }
214
+ });
215
+ Object.defineProperty(exports, "hasCssMacroTailwindV4Directive", {
216
+ enumerable: true,
217
+ get: function() {
218
+ return hasCssMacroTailwindV4Directive;
219
+ }
220
+ });
221
+ Object.defineProperty(exports, "markCssMacroPlugin", {
222
+ enumerable: true,
223
+ get: function() {
224
+ return markCssMacroPlugin;
225
+ }
226
+ });
227
+ Object.defineProperty(exports, "transformCssMacroCss", {
228
+ enumerable: true,
229
+ get: function() {
230
+ return transformCssMacroCss;
231
+ }
232
+ });
233
+ Object.defineProperty(exports, "withCssMacroStyleOptions", {
234
+ enumerable: true,
235
+ get: function() {
236
+ return withCssMacroStyleOptions;
237
+ }
238
+ });