weapp-tailwindcss 5.1.5 → 5.1.7

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 (50) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/bundlers/shared/generator-css/types.d.ts +1 -0
  4. package/dist/bundlers/shared/generator-css/user-css.d.ts +4 -1
  5. package/dist/bundlers/vite/generate-bundle/finalize.d.ts +1 -0
  6. package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +1 -0
  7. package/dist/bundlers/vite/processed-css-assets.d.ts +7 -0
  8. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +10 -0
  9. package/dist/{context-rrYZuUBU.mjs → context-BqeDu1Ha.mjs} +5 -4
  10. package/dist/{context-BziwyWy1.js → context-C7KTDlrG.js} +5 -4
  11. package/dist/core.js +1 -1
  12. package/dist/core.mjs +1 -1
  13. package/dist/{generator-24-HgU9F.mjs → generator-BOt2Tvx3.mjs} +2 -2
  14. package/dist/{generator-CilgHtxb.js → generator-DASZwC6t.js} +2 -2
  15. package/dist/generator.js +2 -2
  16. package/dist/generator.mjs +2 -2
  17. package/dist/{gulp-CuVsZdO9.js → gulp-D6hsaTLM.js} +4 -4
  18. package/dist/{gulp-ygWfmOqh.mjs → gulp-alDZryyB.mjs} +4 -4
  19. package/dist/gulp.js +1 -1
  20. package/dist/gulp.mjs +1 -1
  21. package/dist/{hmr-timing-BKdCeIrn.js → hmr-timing-BIr_CiPW.js} +55 -566
  22. package/dist/{hmr-timing-Dh_nn3w5.mjs → hmr-timing-CYwVMRol.mjs} +32 -513
  23. package/dist/index.js +4 -4
  24. package/dist/index.mjs +4 -4
  25. package/dist/postcss.js +2 -2
  26. package/dist/postcss.mjs +2 -2
  27. package/dist/presets.js +6 -3
  28. package/dist/presets.mjs +6 -3
  29. package/dist/rspack.js +1 -1
  30. package/dist/rspack.mjs +1 -1
  31. package/dist/runtime-branch/generator-target-env.d.ts +1 -0
  32. package/dist/{source-candidate-scan-signature-DATRnS1X.mjs → source-candidate-scan-signature-D97ZEXcj.mjs} +3 -3
  33. package/dist/{source-candidate-scan-signature-DIj9m4wB.js → source-candidate-scan-signature-Djr2Hw8y.js} +3 -3
  34. package/dist/{tailwindcss-C-uM4rB8.mjs → tailwindcss-DDGD90w7.mjs} +15 -2
  35. package/dist/{tailwindcss-BwoNQ3t8.js → tailwindcss-DPxJpRVP.js} +15 -2
  36. package/dist/{transform-KLD1tJdb.js → transform-CvqqZBuq.js} +1 -1
  37. package/dist/{transform-DHLemtaX.mjs → transform-DPPr79r2.mjs} +1 -1
  38. package/dist/uni-app-x/web-preflight-reset.d.ts +3 -0
  39. package/dist/{v4-engine-CKtsdKxK.js → v4-engine-3UmJkAY7.js} +641 -3
  40. package/dist/{v4-engine-BuuYDXt1.mjs → v4-engine-CYSrDVNp.mjs} +560 -6
  41. package/dist/{vite-Yp14HNyS.js → vite-BJRlG835.js} +636 -114
  42. package/dist/{vite-cH0tTMHc.mjs → vite-XxJh7Xtu.mjs} +637 -115
  43. package/dist/vite.js +1 -1
  44. package/dist/vite.mjs +1 -1
  45. package/dist/weapp-tw-css-import-rewrite-loader.js +3078 -2907
  46. package/dist/{webpack-DN3tgLbF.js → webpack-BxBOMUtY.js} +286 -47
  47. package/dist/{webpack-DBhmJ-_P.mjs → webpack-eN8WzIT-.mjs} +280 -41
  48. package/dist/webpack.js +1 -1
  49. package/dist/webpack.mjs +1 -1
  50. package/package.json +3 -3
@@ -46,6 +46,9 @@ function inferGeneratorTargetFromExplicitEnv() {
46
46
  function shouldUseWebGeneratorTargetFromEnv() {
47
47
  return uniWebPlatformEnvKeys.some((key) => isUniWebPlatform(getEnvValue(key))) || isUniAppWebViewPlatform(getEnvValue("UNI_PLATFORM")) && !isUniNativeAppPlatform(getEnvValue("UNI_UTS_PLATFORM")) || mpxWebPlatformEnvKeys.some((key) => isMpxWebPlatform(getEnvValue(key))) || getEnvValue("TARO_ENV") === "h5";
48
48
  }
49
+ function shouldUseUniAppViteWebViewGeneratorTarget(appType, platform = getEnvValue("UNI_PLATFORM")) {
50
+ return appType === "uni-app-vite" && isUniAppWebViewPlatform(platform);
51
+ }
49
52
  function inferGeneratorTargetFromEnv() {
50
53
  return inferGeneratorTargetFromExplicitEnv() ?? (shouldUseWebGeneratorTargetFromEnv() ? "web" : "weapp");
51
54
  }
@@ -1860,6 +1863,557 @@ function resolveCssEntrySource(rawSource, base, options = {}) {
1860
1863
  }
1861
1864
  }
1862
1865
  //#endregion
1866
+ //#region src/bundlers/shared/generator-css/user-css.ts
1867
+ const TAILWIND_V4_GENERATOR_AT_RULES = /* @__PURE__ */ new Set([
1868
+ "config",
1869
+ "custom-variant",
1870
+ "plugin",
1871
+ "source",
1872
+ "theme",
1873
+ "utility",
1874
+ "variant"
1875
+ ]);
1876
+ function removeBalancedAtRuleBlock(source, atRuleStart) {
1877
+ const blockStart = source.indexOf("{", atRuleStart);
1878
+ if (blockStart === -1) {
1879
+ const semicolon = source.indexOf(";", atRuleStart);
1880
+ return semicolon === -1 ? source.slice(0, atRuleStart) : `${source.slice(0, atRuleStart)}${source.slice(semicolon + 1)}`;
1881
+ }
1882
+ let depth = 0;
1883
+ for (let index = blockStart; index < source.length; index++) {
1884
+ const char = source[index];
1885
+ if (char === "{") {
1886
+ depth++;
1887
+ continue;
1888
+ }
1889
+ if (char !== "}") continue;
1890
+ depth--;
1891
+ if (depth === 0) return `${source.slice(0, atRuleStart)}${source.slice(index + 1)}`;
1892
+ }
1893
+ return source.slice(0, atRuleStart);
1894
+ }
1895
+ function removeTailwindV4GeneratorAtRulesFallback(source) {
1896
+ let next = source;
1897
+ let changed = false;
1898
+ const sourceMediaRE = /@media\s+source\([^)]*\)\s*\{/g;
1899
+ for (;;) {
1900
+ sourceMediaRE.lastIndex = 0;
1901
+ const match = sourceMediaRE.exec(next);
1902
+ if (!match) break;
1903
+ next = removeBalancedAtRuleBlock(next, match.index);
1904
+ changed = true;
1905
+ }
1906
+ const atRuleRE = /@(?:config|custom-variant|plugin|source|theme|utility|variant)\b/g;
1907
+ for (;;) {
1908
+ atRuleRE.lastIndex = 0;
1909
+ const match = atRuleRE.exec(next);
1910
+ if (!match) break;
1911
+ next = removeBalancedAtRuleBlock(next, match.index);
1912
+ changed = true;
1913
+ }
1914
+ return changed ? next : source;
1915
+ }
1916
+ function isTailwindGeneratedPreflightComment(text) {
1917
+ return text.includes("cssremedy") || text.includes("Use the user's configured") || text.includes("tailwindlabs/tailwindcss") || text.includes("Prevent padding and border from affecting element width") || text.includes("Remove default margins and padding") || text.includes("Deprecated") || text.includes("Reset all borders") || text.includes("Add the correct text decoration") || text.includes("Make elements with the HTML hidden attribute stay hidden") || text.includes("Inherit font styles in all browsers") || text.includes("Add the correct height in Firefox") || text.includes("Remove the default font size and weight for headings") || text.includes("Reset links to optimize for opt-in styling") || text.includes("Add the correct font weight in Edge and Safari") || text.includes("Use the user's configured `mono` font-family") || text.includes("Add the correct font size in all browsers") || text.includes("Prevent `sub` and `sup` elements from affecting the line height") || text.includes("Remove text indentation from table contents") || text.includes("Use the modern Firefox focus style") || text.includes("Add the correct vertical alignment") || text.includes("Add the correct display") || text.includes("Make lists unstyled by default") || text.includes("Make replaced elements `display: block` by default") || text.includes("Constrain images and videos to the parent width") || text.includes("Restore default font weight") || text.includes("Restore indentation") || text.includes("Restore space after button") || text.includes("Prevent resizing textareas horizontally") || text.includes("Remove the inner padding in Chrome and Safari") || text.includes("Ensure date/time inputs have the same height") || text.includes("Prevent height from changing on date/time inputs") || text.includes("Remove excess padding from pseudo-elements") || text.includes("Center dropdown marker shown on inputs") || text.includes("Remove the additional `:invalid` styles") || text.includes("Correct the inability to style the border radius") || text.includes("Correct the cursor style of increment and decrement buttons");
1918
+ }
1919
+ function isTailwindGeneratedThemeRule(selector, node) {
1920
+ if (!/(?:^|,)\s*(?::host|page|\.tw-root|wx-root-portal-content)\b/.test(selector)) return false;
1921
+ return node.nodes?.some((child) => child.type === "decl" && /^--(?:color|spacing|text|font|default|radius|tw-)/.test(child.prop)) ?? false;
1922
+ }
1923
+ function isTailwindGeneratedPreflightRule(selector, node) {
1924
+ if (selector === "view,text,::after,::before" || selector === "view, text, ::after, ::before" || selector === "*" || selector === "::after" || selector === "::before" || selector === "::backdrop" || selector === ":host" || selector === "[hidden]:not([hidden=\"until-found\"])" || selector === "[hidden]:not([hidden='until-found'])" || selector === "button,input[type=\"button\"],input[type=\"reset\"],input[type=\"submit\"]" || selector === "button, input[type=\"button\"], input[type=\"reset\"], input[type=\"submit\"]" || selector === "button,input[type='button'],input[type='reset'],input[type='submit']" || selector === "button, input[type='button'], input[type='reset'], input[type='submit']") return true;
1925
+ if (selector === "abbr[title]") return node.nodes?.some((child) => child.type === "decl" && child.prop === "text-decoration") ?? false;
1926
+ if (selector === ":host") return node.nodes?.some((child) => child.type === "decl" && child.value?.includes("--theme(")) ?? false;
1927
+ return false;
1928
+ }
1929
+ function removeTailwindV4GeneratedUserCssArtifacts(source) {
1930
+ try {
1931
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
1932
+ let changed = false;
1933
+ root.walkComments((comment) => {
1934
+ if (!isTailwindGeneratedPreflightComment(comment.text)) return;
1935
+ comment.remove();
1936
+ changed = true;
1937
+ });
1938
+ root.walkRules((rule) => {
1939
+ const selector = rule.selector.replace(/\s+/g, " ").trim();
1940
+ if (isTailwindGeneratedThemeRule(selector, rule) || isTailwindGeneratedPreflightRule(selector, rule)) {
1941
+ rule.remove();
1942
+ changed = true;
1943
+ }
1944
+ });
1945
+ root.walkAtRules((rule) => {
1946
+ if (rule.nodes !== void 0 && rule.nodes.length === 0) {
1947
+ rule.remove();
1948
+ changed = true;
1949
+ }
1950
+ });
1951
+ return changed ? root.toString() : source;
1952
+ } catch {
1953
+ return source;
1954
+ }
1955
+ }
1956
+ function removeTailwindSourceMediaBlocks(source) {
1957
+ let next = source;
1958
+ let changed = false;
1959
+ const sourceMediaRE = /@media\s+source\([^)]*\)\s*\{/g;
1960
+ for (;;) {
1961
+ sourceMediaRE.lastIndex = 0;
1962
+ const match = sourceMediaRE.exec(next);
1963
+ if (!match) break;
1964
+ const blockStart = next.indexOf("{", match.index);
1965
+ if (blockStart === -1) break;
1966
+ let depth = 0;
1967
+ let blockEnd = -1;
1968
+ for (let index = blockStart; index < next.length; index++) {
1969
+ const char = next[index];
1970
+ if (char === "{") {
1971
+ depth++;
1972
+ continue;
1973
+ }
1974
+ if (char !== "}") continue;
1975
+ depth--;
1976
+ if (depth === 0) {
1977
+ blockEnd = index;
1978
+ break;
1979
+ }
1980
+ }
1981
+ if (blockEnd === -1) break;
1982
+ next = `${next.slice(0, match.index)}${next.slice(blockEnd + 1)}`;
1983
+ changed = true;
1984
+ }
1985
+ for (;;) {
1986
+ const atRuleStart = findTailwindSourceWrapperBlockStart(next);
1987
+ if (atRuleStart === -1) break;
1988
+ next = removeBalancedAtRuleBlock(next, atRuleStart);
1989
+ changed = true;
1990
+ }
1991
+ return changed ? next : source;
1992
+ }
1993
+ function terminateTailwindSourceAtRulesBeforeNextDirective(source) {
1994
+ if (!source.includes("@source")) return source;
1995
+ let next = "";
1996
+ let searchIndex = 0;
1997
+ for (;;) {
1998
+ const atRuleStart = source.indexOf("@source", searchIndex);
1999
+ if (atRuleStart === -1) {
2000
+ next += source.slice(searchIndex);
2001
+ break;
2002
+ }
2003
+ const nextChar = source[atRuleStart + 7];
2004
+ if (nextChar && /[\w-]/.test(nextChar)) {
2005
+ next += source.slice(searchIndex, atRuleStart + 7);
2006
+ searchIndex = atRuleStart + 7;
2007
+ continue;
2008
+ }
2009
+ next += source.slice(searchIndex, atRuleStart);
2010
+ let quote;
2011
+ let parenDepth = 0;
2012
+ let terminated = false;
2013
+ let index = atRuleStart + 7;
2014
+ for (; index < source.length; index++) {
2015
+ const char = source[index];
2016
+ if (quote) {
2017
+ if (char === "\\") {
2018
+ index++;
2019
+ continue;
2020
+ }
2021
+ if (char === quote) quote = void 0;
2022
+ continue;
2023
+ }
2024
+ if (char === "\"" || char === "'") {
2025
+ quote = char;
2026
+ continue;
2027
+ }
2028
+ if (char === "(") {
2029
+ parenDepth++;
2030
+ continue;
2031
+ }
2032
+ if (char === ")" && parenDepth > 0) {
2033
+ parenDepth--;
2034
+ continue;
2035
+ }
2036
+ if (parenDepth > 0) continue;
2037
+ if (char === ";" || char === "{") {
2038
+ terminated = true;
2039
+ index++;
2040
+ break;
2041
+ }
2042
+ if (char === "@" && /^(?:config|custom-variant|plugin|source|theme|utility|variant)\b/.test(source.slice(index + 1))) break;
2043
+ }
2044
+ const segment = source.slice(atRuleStart, index);
2045
+ const trimmedSegment = segment.trimEnd();
2046
+ next += terminated || trimmedSegment.endsWith(";") || trimmedSegment.endsWith("{") ? segment : `${trimmedSegment};${segment.slice(trimmedSegment.length)}`;
2047
+ searchIndex = index;
2048
+ }
2049
+ return next;
2050
+ }
2051
+ function findTailwindSourceWrapperBlockStart(source) {
2052
+ let searchIndex = 0;
2053
+ for (;;) {
2054
+ const atRuleStart = source.indexOf("@source", searchIndex);
2055
+ if (atRuleStart === -1) return -1;
2056
+ const nextChar = source[atRuleStart + 7];
2057
+ if (nextChar && /[\w-]/.test(nextChar)) {
2058
+ searchIndex = atRuleStart + 7;
2059
+ continue;
2060
+ }
2061
+ let quote;
2062
+ let parenDepth = 0;
2063
+ for (let index = atRuleStart + 7; index < source.length; index++) {
2064
+ const char = source[index];
2065
+ if (quote) {
2066
+ if (char === "\\") {
2067
+ index++;
2068
+ continue;
2069
+ }
2070
+ if (char === quote) quote = void 0;
2071
+ continue;
2072
+ }
2073
+ if (char === "\"" || char === "'") {
2074
+ quote = char;
2075
+ continue;
2076
+ }
2077
+ if (char === "(") {
2078
+ parenDepth++;
2079
+ continue;
2080
+ }
2081
+ if (char === ")" && parenDepth > 0) {
2082
+ parenDepth--;
2083
+ continue;
2084
+ }
2085
+ if (parenDepth > 0) continue;
2086
+ if (char === ";") {
2087
+ searchIndex = index + 1;
2088
+ break;
2089
+ }
2090
+ if (char === "{") return atRuleStart;
2091
+ }
2092
+ if (searchIndex <= atRuleStart) return -1;
2093
+ }
2094
+ }
2095
+ function removeTailwindApplyAtRules(source) {
2096
+ if (!source.includes("@apply")) return source;
2097
+ try {
2098
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
2099
+ let changed = false;
2100
+ root.walkAtRules("apply", (rule) => {
2101
+ rule.remove();
2102
+ changed = true;
2103
+ });
2104
+ root.walk((node) => {
2105
+ if ("nodes" in node && node.nodes?.length === 0) node.remove();
2106
+ });
2107
+ return changed ? root.toString() : source;
2108
+ } catch {
2109
+ return source;
2110
+ }
2111
+ }
2112
+ function removeTailwindV4GeneratorAtRules(source) {
2113
+ try {
2114
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
2115
+ let changed = false;
2116
+ root.walkAtRules((rule) => {
2117
+ if (rule.name === "media" && /^source\(/.test(rule.params.trim())) {
2118
+ rule.remove();
2119
+ changed = true;
2120
+ return;
2121
+ }
2122
+ if (!TAILWIND_V4_GENERATOR_AT_RULES.has(rule.name)) return;
2123
+ rule.remove();
2124
+ changed = true;
2125
+ });
2126
+ return changed ? root.toString() : source;
2127
+ } catch {
2128
+ return removeTailwindV4GeneratorAtRulesFallback(source);
2129
+ }
2130
+ }
2131
+ function isCommentOnlyCss(source) {
2132
+ try {
2133
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
2134
+ return root.nodes.length > 0 && root.nodes.every((node) => node.type === "comment");
2135
+ } catch {
2136
+ return false;
2137
+ }
2138
+ }
2139
+ function removeMiniProgramHoverSelectors(source, enabled = true) {
2140
+ if (!enabled || !source.includes(":hover")) return source;
2141
+ try {
2142
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
2143
+ let changed = false;
2144
+ root.walkRules((rule) => {
2145
+ const selectors = rule.selectors ?? [rule.selector];
2146
+ const keptSelectors = selectors.filter((selector) => !selector.includes(":hover"));
2147
+ if (keptSelectors.length === selectors.length) return;
2148
+ changed = true;
2149
+ if (keptSelectors.length === 0) {
2150
+ rule.remove();
2151
+ return;
2152
+ }
2153
+ rule.selectors = keptSelectors;
2154
+ });
2155
+ root.walk((node) => {
2156
+ if ("nodes" in node && node.nodes?.length === 0) {
2157
+ node.remove();
2158
+ changed = true;
2159
+ }
2160
+ });
2161
+ return changed ? root.toString() : source;
2162
+ } catch {
2163
+ return source;
2164
+ }
2165
+ }
2166
+ function removeProcessedMiniProgramUnsupportedCss(source, options) {
2167
+ return removeMiniProgramHoverSelectors((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(source), options.cssRemoveHoverPseudoClass);
2168
+ }
2169
+ function unwrapMiniProgramCascadeLayers(source) {
2170
+ if (!source.includes("@layer")) return source;
2171
+ try {
2172
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
2173
+ (0, _weapp_tailwindcss_postcss.removeUnsupportedCascadeLayers)(root);
2174
+ return root.toString();
2175
+ } catch {
2176
+ return source;
2177
+ }
2178
+ }
2179
+ function hasClassSelector(selector) {
2180
+ return /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(selector);
2181
+ }
2182
+ function collectBareSelectorUserCss(source) {
2183
+ try {
2184
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
2185
+ let changed = false;
2186
+ root.walkAtRules("import", (rule) => {
2187
+ rule.remove();
2188
+ changed = true;
2189
+ });
2190
+ root.walkRules((rule) => {
2191
+ if ((rule.selectors?.length ? rule.selectors : [rule.selector]).some((selector) => hasClassSelector(selector))) {
2192
+ rule.remove();
2193
+ changed = true;
2194
+ }
2195
+ });
2196
+ root.walkAtRules((rule) => {
2197
+ if (rule.nodes !== void 0 && rule.nodes.length === 0) {
2198
+ rule.remove();
2199
+ changed = true;
2200
+ }
2201
+ });
2202
+ return changed ? root.toString() : source;
2203
+ } catch {
2204
+ return "";
2205
+ }
2206
+ }
2207
+ function stripTailwindSourceMediaFragments(source) {
2208
+ let removedSourceMediaStart = false;
2209
+ return terminateTailwindSourceAtRulesBeforeNextDirective(removeTailwindSourceMediaBlocks(source)).split(/\r?\n/).filter((line) => {
2210
+ if (/^\s*@media\s+source\([^)]*\)\s*\{\s*$/.test(line)) {
2211
+ removedSourceMediaStart = true;
2212
+ return false;
2213
+ }
2214
+ if (/^\s*\}\s*\/\*\s*source\([^)]*\)\s*\*\/\s*$/.test(line)) return false;
2215
+ if (removedSourceMediaStart && /^\s*\}\s*$/.test(line)) {
2216
+ removedSourceMediaStart = false;
2217
+ return false;
2218
+ }
2219
+ return true;
2220
+ }).join("\n");
2221
+ }
2222
+ function stripLeadingTailwindSourceMediaCloseFragment(source) {
2223
+ return source.replace(/^\s*\}\s*(?:\n|$)/, "");
2224
+ }
2225
+ function stripUnmatchedTailwindSourceMediaCloseFragments(source) {
2226
+ try {
2227
+ _weapp_tailwindcss_postcss.postcss.parse(source);
2228
+ return source;
2229
+ } catch {
2230
+ return stripLeadingTailwindSourceMediaCloseFragment(source).replace(/\s*\}\s*$/, "");
2231
+ }
2232
+ }
2233
+ function splitUserCssLayerBlocks(source) {
2234
+ if (!source.includes("@layer")) return {
2235
+ layer: "",
2236
+ rest: source
2237
+ };
2238
+ try {
2239
+ const root = _weapp_tailwindcss_postcss.postcss.parse(source);
2240
+ const layerRoot = _weapp_tailwindcss_postcss.postcss.root();
2241
+ const restRoot = _weapp_tailwindcss_postcss.postcss.root();
2242
+ for (const node of root.nodes) (node.type === "atrule" && node.name === "layer" && node.nodes?.length ? layerRoot : restRoot).append(node.clone());
2243
+ return {
2244
+ layer: layerRoot.toString(),
2245
+ rest: restRoot.toString()
2246
+ };
2247
+ } catch {
2248
+ return {
2249
+ layer: source,
2250
+ rest: ""
2251
+ };
2252
+ }
2253
+ }
2254
+ function hasUserCssLayerBlocks(source) {
2255
+ if (!source.includes("@layer")) return false;
2256
+ try {
2257
+ let hasLayerBlock = false;
2258
+ _weapp_tailwindcss_postcss.postcss.parse(source).walkAtRules("layer", (node) => {
2259
+ if (node.nodes?.length) hasLayerBlock = true;
2260
+ });
2261
+ return hasLayerBlock;
2262
+ } catch {
2263
+ return true;
2264
+ }
2265
+ }
2266
+ function collectUserLayerSelectors(source) {
2267
+ const selectors = /* @__PURE__ */ new Set();
2268
+ try {
2269
+ _weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
2270
+ for (const selector of rule.selectors ?? [rule.selector]) {
2271
+ const normalized = selector.trim();
2272
+ if (normalized) selectors.add(normalized);
2273
+ }
2274
+ });
2275
+ } catch {}
2276
+ return selectors;
2277
+ }
2278
+ function matchesUserLayerSelector(selector, userLayerSelector) {
2279
+ if (selector === userLayerSelector) return true;
2280
+ if (!selector.startsWith(userLayerSelector)) return false;
2281
+ const next = selector[userLayerSelector.length];
2282
+ return next === ":" || next === "[";
2283
+ }
2284
+ function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
2285
+ const selectors = collectUserLayerSelectors(userLayerSource);
2286
+ if (selectors.size === 0) return {
2287
+ layer: "",
2288
+ rest: css
2289
+ };
2290
+ try {
2291
+ const root = _weapp_tailwindcss_postcss.postcss.parse(css);
2292
+ const layerRoot = _weapp_tailwindcss_postcss.postcss.root();
2293
+ const selectorList = [...selectors];
2294
+ root.walkRules((rule) => {
2295
+ if ((rule.selectors ?? [rule.selector]).some((selector) => selectorList.some((userSelector) => matchesUserLayerSelector(selector.trim(), userSelector)))) {
2296
+ layerRoot.append(rule.clone());
2297
+ rule.remove();
2298
+ }
2299
+ });
2300
+ return {
2301
+ layer: layerRoot.toString(),
2302
+ rest: root.toString()
2303
+ };
2304
+ } catch {
2305
+ return {
2306
+ layer: "",
2307
+ rest: css
2308
+ };
2309
+ }
2310
+ }
2311
+ function normalizeGeneratedSelector(selector) {
2312
+ return selector.replace(/:not\(#\\#\)/g, "").trim();
2313
+ }
2314
+ function collectApplyOnlySourceSelectors(source) {
2315
+ const selectors = /* @__PURE__ */ new Set();
2316
+ try {
2317
+ _weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
2318
+ if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
2319
+ for (const selector of rule.selectors ?? [rule.selector]) {
2320
+ const normalized = normalizeGeneratedSelector(selector);
2321
+ if (normalized) selectors.add(normalized);
2322
+ }
2323
+ });
2324
+ } catch {}
2325
+ return selectors;
2326
+ }
2327
+ function hasOnlyApplyBackedSourceRules(source) {
2328
+ let hasApplyRule = false;
2329
+ let hasNonApplyRule = false;
2330
+ try {
2331
+ _weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
2332
+ if (rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) hasApplyRule = true;
2333
+ else hasNonApplyRule = true;
2334
+ });
2335
+ } catch {
2336
+ return false;
2337
+ }
2338
+ return hasApplyRule && !hasNonApplyRule;
2339
+ }
2340
+ function removeCssComments(css) {
2341
+ return css.replace(/\/\*[\s\S]*?\*\//g, "");
2342
+ }
2343
+ function isEmptyCustomVariantBlock(rule) {
2344
+ if (rule.name !== "custom-variant") return false;
2345
+ if (!/^[\w-]+$/.test(rule.params.trim())) return false;
2346
+ if (rule.nodes === void 0) return true;
2347
+ return rule.nodes.every((node) => node.type === "comment");
2348
+ }
2349
+ function normalizeEmptyTailwindCustomVariants(css) {
2350
+ if (!css.includes("@custom-variant")) return css;
2351
+ try {
2352
+ const root = _weapp_tailwindcss_postcss.postcss.parse(css);
2353
+ let changed = false;
2354
+ root.walkAtRules("custom-variant", (rule) => {
2355
+ if (!isEmptyCustomVariantBlock(rule)) return;
2356
+ rule.remove();
2357
+ changed = true;
2358
+ });
2359
+ return changed ? root.toString() : css;
2360
+ } catch {
2361
+ return css;
2362
+ }
2363
+ }
2364
+ function filterApplyOnlyGeneratedCss(css, source, options = {}) {
2365
+ const selectors = collectApplyOnlySourceSelectors(source);
2366
+ if (selectors.size === 0) return css;
2367
+ const selectorList = [...selectors];
2368
+ const preserveVariables = options.preserveVariables !== false;
2369
+ try {
2370
+ const root = _weapp_tailwindcss_postcss.postcss.parse(css);
2371
+ root.walkRules((rule) => {
2372
+ const isApplySelector = (rule.selectors ?? [rule.selector]).some((selector) => {
2373
+ const normalized = normalizeGeneratedSelector(selector);
2374
+ return selectorList.some((sourceSelector) => {
2375
+ if (normalized === sourceSelector) return true;
2376
+ if (!normalized.startsWith(sourceSelector)) return false;
2377
+ const next = normalized[sourceSelector.length];
2378
+ return next === ":" || next === "[" || next === ".";
2379
+ });
2380
+ });
2381
+ const isVariableRule = rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"));
2382
+ if (!isApplySelector && (!preserveVariables || !isVariableRule)) rule.remove();
2383
+ });
2384
+ root.walkAtRules((rule) => {
2385
+ if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
2386
+ });
2387
+ return removeCssComments(root.toString()).trim();
2388
+ } catch {
2389
+ return css;
2390
+ }
2391
+ }
2392
+ function shouldFilterApplyOnlyGeneratedCss(_majorVersion, target, source, options) {
2393
+ return (target === "weapp" || target === "web") && hasTailwindApplyDirective(source) && !hasTailwindRootDirectives(source) && !options.hasGeneratedCss && !options.hasGeneratedMarkers && collectApplyOnlySourceSelectors(source).size > 0 && hasOnlyApplyBackedSourceRules(source);
2394
+ }
2395
+ async function transformGeneratorUserCss(source, options) {
2396
+ if (source.trim().length === 0) return "";
2397
+ if (options.processed) return stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(removeTailwindV4GeneratorAtRules(options.generatorTarget === "weapp" ? removeTailwindV4GeneratedUserCssArtifacts(removeProcessedMiniProgramUnsupportedCss(source, {
2398
+ ...options.generatorStyleOptions,
2399
+ ...options.cssUserHandlerOptions
2400
+ })) : source)));
2401
+ const cleanedSource = removeTailwindSourceDirectives(removeTailwindV4GeneratorAtRules(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source))), { importFallback: options.importFallback });
2402
+ if (cleanedSource.trim().length === 0) return "";
2403
+ const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? removeTailwindV4GeneratedUserCssArtifacts((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(unwrapMiniProgramCascadeLayers(cleanedSource))) : cleanedSource)), { importFallback: options.importFallback })));
2404
+ if (userSource.trim().length === 0) return "";
2405
+ if (isCommentOnlyCss(userSource)) return userSource;
2406
+ if (options.generatorTarget !== "weapp") return userSource;
2407
+ const { css } = await options.styleHandler(userSource, {
2408
+ ...options.generatorStyleOptions,
2409
+ ...options.cssUserHandlerOptions
2410
+ });
2411
+ const transformedCss = removeTailwindV4GeneratedUserCssArtifacts((0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(css));
2412
+ const bareSelectorUserCss = collectBareSelectorUserCss(userSource);
2413
+ const missingBareSelectorUserCss = bareSelectorUserCss.trim().length > 0 ? (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(transformedCss, bareSelectorUserCss) : "";
2414
+ return missingBareSelectorUserCss.trim().length > 0 ? `${transformedCss}\n${missingBareSelectorUserCss}` : transformedCss;
2415
+ }
2416
+ //#endregion
1863
2417
  //#region src/utils/options.ts
1864
2418
  function resolveBooleanObjectOption(value, enabledValue) {
1865
2419
  if (!value) return false;
@@ -2198,7 +2752,7 @@ function normalizeTailwindV4CssSources(cssSources, packageName, projectRoot) {
2198
2752
  };
2199
2753
  }
2200
2754
  const configBase = base ?? projectRoot ?? node_process.default.cwd();
2201
- const css = normalizeTailwindV4CssPackageImports(normalizeTailwindConfigDirectives(cssSource.css, configBase), packageName);
2755
+ const css = normalizeTailwindV4CssPackageImports(normalizeEmptyTailwindCustomVariants(normalizeTailwindConfigDirectives(cssSource.css, configBase)), packageName);
2202
2756
  if (css === cssSource.css && file === cssSource.file && base === cssSource.base) return cssSource;
2203
2757
  changed = true;
2204
2758
  return {
@@ -2223,7 +2777,7 @@ function normalizeTailwindV4CssEntrySources(cssEntries, packageName) {
2223
2777
  const base = node_path.default.dirname(file);
2224
2778
  const rawCss = (0, node_fs.readFileSync)(file, "utf8");
2225
2779
  const entrySource = resolveCssEntrySource(rawCss, base, { removeConfig: false });
2226
- const css = normalizeTailwindV4CssPackageImports(normalizeConfigDirective(rawCss, entrySource?.config && (0, node_fs.existsSync)(entrySource.config) ? entrySource.config : entrySource?.configRequest && !node_path.default.isAbsolute(entrySource.configRequest) && !isPackageJsonImportSpecifier(entrySource.configRequest) ? node_path.default.resolve(base, entrySource.configRequest) : entrySource?.config), packageName);
2780
+ const css = normalizeTailwindV4CssPackageImports(normalizeEmptyTailwindCustomVariants(normalizeConfigDirective(rawCss, entrySource?.config && (0, node_fs.existsSync)(entrySource.config) ? entrySource.config : entrySource?.configRequest && !node_path.default.isAbsolute(entrySource.configRequest) && !isPackageJsonImportSpecifier(entrySource.configRequest) ? node_path.default.resolve(base, entrySource.configRequest) : entrySource?.config)), packageName);
2227
2781
  cssSources.push({
2228
2782
  file,
2229
2783
  base,
@@ -2239,7 +2793,7 @@ function normalizeTailwindV4CssEntrySources(cssEntries, packageName) {
2239
2793
  function normalizeTailwindV4SourceOptions(options) {
2240
2794
  if (!options) return options;
2241
2795
  const cssBase = resolveBase(options.base, options.projectRoot ?? options.cwd ?? node_process.default.cwd());
2242
- const css = options.css === void 0 ? void 0 : normalizeTailwindV4CssPackageImports(normalizeTailwindConfigDirectives(options.css, cssBase), options.packageName);
2796
+ const css = options.css === void 0 ? void 0 : normalizeTailwindV4CssPackageImports(normalizeEmptyTailwindCustomVariants(normalizeTailwindConfigDirectives(options.css, cssBase)), options.packageName);
2243
2797
  const entrySources = normalizeTailwindV4CssEntrySources(options.cssEntries, options.packageName);
2244
2798
  const configuredCssSources = filterTailwindV4CssSourceRoots(options.cssSources);
2245
2799
  const cssSources = normalizeTailwindV4CssSources(configuredCssSources || entrySources?.cssSources ? [...configuredCssSources ?? [], ...entrySources?.cssSources ?? []] : void 0, options.packageName, options.projectRoot);
@@ -2372,6 +2926,18 @@ Object.defineProperty(exports, "expandTailwindSourceEntries", {
2372
2926
  return expandTailwindSourceEntries;
2373
2927
  }
2374
2928
  });
2929
+ Object.defineProperty(exports, "extractGeneratedCssForUserLayerSelectors", {
2930
+ enumerable: true,
2931
+ get: function() {
2932
+ return extractGeneratedCssForUserLayerSelectors;
2933
+ }
2934
+ });
2935
+ Object.defineProperty(exports, "filterApplyOnlyGeneratedCss", {
2936
+ enumerable: true,
2937
+ get: function() {
2938
+ return filterApplyOnlyGeneratedCss;
2939
+ }
2940
+ });
2375
2941
  Object.defineProperty(exports, "filterTailwindV4CssSourceRoots", {
2376
2942
  enumerable: true,
2377
2943
  get: function() {
@@ -2468,12 +3034,24 @@ Object.defineProperty(exports, "hasTailwindSourceDirectives", {
2468
3034
  return hasTailwindSourceDirectives;
2469
3035
  }
2470
3036
  });
3037
+ Object.defineProperty(exports, "hasUserCssLayerBlocks", {
3038
+ enumerable: true,
3039
+ get: function() {
3040
+ return hasUserCssLayerBlocks;
3041
+ }
3042
+ });
2471
3043
  Object.defineProperty(exports, "inferGeneratorTargetFromEnv", {
2472
3044
  enumerable: true,
2473
3045
  get: function() {
2474
3046
  return inferGeneratorTargetFromEnv;
2475
3047
  }
2476
3048
  });
3049
+ Object.defineProperty(exports, "isCommentOnlyCss", {
3050
+ enumerable: true,
3051
+ get: function() {
3052
+ return isCommentOnlyCss;
3053
+ }
3054
+ });
2477
3055
  Object.defineProperty(exports, "isFileMatchedByTailwindSourceEntries", {
2478
3056
  enumerable: true,
2479
3057
  get: function() {
@@ -2498,6 +3076,12 @@ Object.defineProperty(exports, "normalizeCssEntries", {
2498
3076
  return normalizeCssEntries;
2499
3077
  }
2500
3078
  });
3079
+ Object.defineProperty(exports, "normalizeEmptyTailwindCustomVariants", {
3080
+ enumerable: true,
3081
+ get: function() {
3082
+ return normalizeEmptyTailwindCustomVariants;
3083
+ }
3084
+ });
2501
3085
  Object.defineProperty(exports, "normalizeExtendLengthUnits", {
2502
3086
  enumerable: true,
2503
3087
  get: function() {
@@ -2564,12 +3148,30 @@ Object.defineProperty(exports, "prependConfigDirective", {
2564
3148
  return prependConfigDirective;
2565
3149
  }
2566
3150
  });
3151
+ Object.defineProperty(exports, "removeMiniProgramHoverSelectors", {
3152
+ enumerable: true,
3153
+ get: function() {
3154
+ return removeMiniProgramHoverSelectors;
3155
+ }
3156
+ });
2567
3157
  Object.defineProperty(exports, "removeTailwindSourceDirectives", {
2568
3158
  enumerable: true,
2569
3159
  get: function() {
2570
3160
  return removeTailwindSourceDirectives;
2571
3161
  }
2572
3162
  });
3163
+ Object.defineProperty(exports, "removeTailwindV4GeneratedUserCssArtifacts", {
3164
+ enumerable: true,
3165
+ get: function() {
3166
+ return removeTailwindV4GeneratedUserCssArtifacts;
3167
+ }
3168
+ });
3169
+ Object.defineProperty(exports, "removeTailwindV4GeneratorAtRules", {
3170
+ enumerable: true,
3171
+ get: function() {
3172
+ return removeTailwindV4GeneratorAtRules;
3173
+ }
3174
+ });
2573
3175
  Object.defineProperty(exports, "resolveBooleanObjectOption", {
2574
3176
  enumerable: true,
2575
3177
  get: function() {
@@ -2636,6 +3238,18 @@ Object.defineProperty(exports, "resolveTailwindcssOptions", {
2636
3238
  return resolveTailwindcssOptions;
2637
3239
  }
2638
3240
  });
3241
+ Object.defineProperty(exports, "shouldFilterApplyOnlyGeneratedCss", {
3242
+ enumerable: true,
3243
+ get: function() {
3244
+ return shouldFilterApplyOnlyGeneratedCss;
3245
+ }
3246
+ });
3247
+ Object.defineProperty(exports, "shouldUseUniAppViteWebViewGeneratorTarget", {
3248
+ enumerable: true,
3249
+ get: function() {
3250
+ return shouldUseUniAppViteWebViewGeneratorTarget;
3251
+ }
3252
+ });
2639
3253
  Object.defineProperty(exports, "splitGeneratorPlaceholderCssBySourceOrder", {
2640
3254
  enumerable: true,
2641
3255
  get: function() {
@@ -2654,6 +3268,12 @@ Object.defineProperty(exports, "splitTailwindV4GeneratedCssBySourceOrder", {
2654
3268
  return splitTailwindV4GeneratedCssBySourceOrder;
2655
3269
  }
2656
3270
  });
3271
+ Object.defineProperty(exports, "splitUserCssLayerBlocks", {
3272
+ enumerable: true,
3273
+ get: function() {
3274
+ return splitUserCssLayerBlocks;
3275
+ }
3276
+ });
2657
3277
  Object.defineProperty(exports, "stripGeneratorPlaceholderMarkers", {
2658
3278
  enumerable: true,
2659
3279
  get: function() {
@@ -2672,12 +3292,30 @@ Object.defineProperty(exports, "stripTailwindBanners", {
2672
3292
  return stripTailwindBanners;
2673
3293
  }
2674
3294
  });
3295
+ Object.defineProperty(exports, "stripTailwindSourceMediaFragments", {
3296
+ enumerable: true,
3297
+ get: function() {
3298
+ return stripTailwindSourceMediaFragments;
3299
+ }
3300
+ });
3301
+ Object.defineProperty(exports, "stripUnmatchedTailwindSourceMediaCloseFragments", {
3302
+ enumerable: true,
3303
+ get: function() {
3304
+ return stripUnmatchedTailwindSourceMediaCloseFragments;
3305
+ }
3306
+ });
2675
3307
  Object.defineProperty(exports, "toPosixPath", {
2676
3308
  enumerable: true,
2677
3309
  get: function() {
2678
3310
  return toPosixPath;
2679
3311
  }
2680
3312
  });
3313
+ Object.defineProperty(exports, "transformGeneratorUserCss", {
3314
+ enumerable: true,
3315
+ get: function() {
3316
+ return transformGeneratorUserCss;
3317
+ }
3318
+ });
2681
3319
  Object.defineProperty(exports, "transformTailwindV4CssByTarget", {
2682
3320
  enumerable: true,
2683
3321
  get: function() {