weapp-tailwindcss 5.5.6 → 5.5.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 (276) hide show
  1. package/dist/{auto-DtU6f3X6.cjs → auto-B1OyRrE8.cjs} +1 -1
  2. package/dist/{auto-2dg_uhEJ.js → auto-ENr4xzzw.js} +1 -1
  3. package/dist/bundlers/gulp/shared/create-native-framework-plugins/file-transforms.d.ts +1 -1
  4. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +1 -1
  5. package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
  6. package/dist/bundlers/shared/css-source-trace.d.ts +2 -5
  7. package/dist/bundlers/shared/final-css-cleanup.d.ts +1 -1
  8. package/dist/bundlers/shared/framework-css-composition.d.ts +1 -1
  9. package/dist/bundlers/shared/framework-postcss.d.ts +1 -25
  10. package/dist/bundlers/shared/framework-user-css.d.ts +1 -4
  11. package/dist/bundlers/shared/generated-css-marker.d.ts +1 -10
  12. package/dist/bundlers/shared/generator-css/candidates.d.ts +1 -2
  13. package/dist/bundlers/shared/generator-css/class-selectors.d.ts +1 -3
  14. package/dist/bundlers/shared/generator-css/config-directive.d.ts +1 -2
  15. package/dist/bundlers/shared/generator-css/directives/fallback.d.ts +1 -11
  16. package/dist/bundlers/shared/generator-css/directives.d.ts +1 -25
  17. package/dist/bundlers/shared/generator-css/generation-helpers/preflight.d.ts +1 -19
  18. package/dist/bundlers/shared/generator-css/generation-helpers/results.d.ts +1 -23
  19. package/dist/bundlers/shared/generator-css/generation-helpers/runtime-isolation.d.ts +1 -30
  20. package/dist/bundlers/shared/generator-css/generation-helpers/source-order.d.ts +1 -2
  21. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +1 -4
  22. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +1 -12
  23. package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +1 -2
  24. package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -1
  25. package/dist/bundlers/shared/generator-css/local-imports.d.ts +1 -1
  26. package/dist/bundlers/shared/generator-css/markers.d.ts +1 -28
  27. package/dist/bundlers/shared/generator-css/output-import-shell.d.ts +1 -8
  28. package/dist/bundlers/shared/generator-css/pipeline/context.d.ts +1 -60
  29. package/dist/bundlers/shared/generator-css/pipeline/deferred-output.d.ts +1 -3
  30. package/dist/bundlers/shared/generator-css/pipeline/execution.d.ts +1 -3
  31. package/dist/bundlers/shared/generator-css/pipeline/fallback-output.d.ts +1 -3
  32. package/dist/bundlers/shared/generator-css/pipeline/ordered-output.d.ts +1 -3
  33. package/dist/bundlers/shared/generator-css/pipeline.d.ts +1 -2
  34. package/dist/bundlers/shared/generator-css/result-helpers.d.ts +1 -6
  35. package/dist/bundlers/shared/generator-css/scoped-rules.d.ts +1 -1
  36. package/dist/bundlers/shared/generator-css/source-files.d.ts +1 -21
  37. package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +1 -13
  38. package/dist/bundlers/shared/generator-css/source-resolver/config.d.ts +1 -7
  39. package/dist/bundlers/shared/generator-css/source-resolver/configuration.d.ts +1 -33
  40. package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +1 -3
  41. package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -28
  42. package/dist/bundlers/shared/generator-css/source-resolver/postcss-source.d.ts +1 -14
  43. package/dist/bundlers/shared/generator-css/source-resolver/resolve-source.d.ts +1 -4
  44. package/dist/bundlers/shared/generator-css/source-resolver/resolve-sources.d.ts +1 -5
  45. package/dist/bundlers/shared/generator-css/source-resolver/single-source.d.ts +1 -16
  46. package/dist/bundlers/shared/generator-css/source-resolver/source-entries.d.ts +1 -3
  47. package/dist/bundlers/shared/generator-css/source-resolver/source-matching.d.ts +1 -5
  48. package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +1 -22
  49. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +1 -7
  50. package/dist/bundlers/shared/generator-css/types.d.ts +1 -64
  51. package/dist/bundlers/shared/generator-css/user-css/apply-only.d.ts +1 -10
  52. package/dist/bundlers/shared/generator-css/user-css/at-rules.d.ts +1 -3
  53. package/dist/bundlers/shared/generator-css/user-css/compile-functions.d.ts +1 -4
  54. package/dist/bundlers/shared/generator-css/user-css/generated-cleanup.d.ts +1 -6
  55. package/dist/bundlers/shared/generator-css/user-css/source-fragments.d.ts +1 -15
  56. package/dist/bundlers/shared/generator-css/user-css/transform.d.ts +1 -13
  57. package/dist/bundlers/shared/generator-css/user-css/user-layers.d.ts +1 -15
  58. package/dist/bundlers/shared/generator-css/user-css.d.ts +1 -5
  59. package/dist/bundlers/shared/generator-css/user-layer-order.d.ts +1 -10
  60. package/dist/bundlers/shared/generator-css/validate.d.ts +1 -7
  61. package/dist/bundlers/shared/generator-css.d.ts +1 -9
  62. package/dist/bundlers/shared/run-tasks.d.ts +1 -3
  63. package/dist/bundlers/shared/runtime-class-set.d.ts +1 -1
  64. package/dist/bundlers/shared/source-candidates/collector.d.ts +1 -8
  65. package/dist/bundlers/shared/source-candidates/scan-root.d.ts +1 -12
  66. package/dist/bundlers/shared/source-candidates/script.d.ts +1 -1
  67. package/dist/bundlers/shared/source-candidates/snapshot.d.ts +1 -19
  68. package/dist/bundlers/shared/source-candidates/source-priority.d.ts +1 -1
  69. package/dist/bundlers/shared/source-candidates/store.d.ts +1 -2
  70. package/dist/bundlers/shared/source-candidates/types-and-cache.d.ts +1 -75
  71. package/dist/bundlers/shared/source-candidates/views.d.ts +1 -12
  72. package/dist/bundlers/shared/source-candidates.d.ts +1 -4
  73. package/dist/bundlers/shared/source-scan/css-entries.d.ts +1 -18
  74. package/dist/bundlers/shared/source-scan/dependencies.d.ts +1 -2
  75. package/dist/bundlers/shared/source-scan.d.ts +1 -16
  76. package/dist/bundlers/shared/static-config-content.d.ts +1 -5
  77. package/dist/bundlers/shared/style-handler-options.d.ts +1 -7
  78. package/dist/bundlers/shared/style-requests.d.ts +1 -5
  79. package/dist/bundlers/shared/v4-generation-core.d.ts +1 -20
  80. package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +1 -1
  81. package/dist/bundlers/vite/generate-bundle/css-transform-task.d.ts +2 -2
  82. package/dist/bundlers/vite/processed-css-assets/cleanup.d.ts +1 -1
  83. package/dist/bundlers/vite/processed-css-assets/coverage.d.ts +1 -12
  84. package/dist/bundlers/vite/processed-css-assets/injection-plan.d.ts +1 -4
  85. package/dist/bundlers/vite/processed-css-assets/markers-imports.d.ts +4 -7
  86. package/dist/bundlers/vite/processed-css-assets/scoped-tailwind-noise.d.ts +1 -13
  87. package/dist/bundlers/vite/shared/framework-module-candidates.d.ts +2 -2
  88. package/dist/bundlers/vite/source-candidates/scan-root.d.ts +1 -1
  89. package/dist/bundlers/vite/source-candidates.d.ts +1 -1
  90. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/finalize.d.ts +1 -1
  91. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/generated-css.d.ts +2 -7
  92. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/preflight-runtime.d.ts +4 -8
  93. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/sources.d.ts +3 -3
  94. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css-markers.d.ts +1 -1
  95. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css.d.ts +2 -7
  96. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.d.ts +1 -1
  97. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +1 -1
  98. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +1 -1
  99. package/dist/bundlers/webpack/loaders/watch-dependencies.d.ts +6 -0
  100. package/dist/cache/index.d.ts +4 -4
  101. package/dist/cache/source.d.ts +29 -0
  102. package/dist/{cache-CBJFB1HN.cjs → cache-CzvIGfwS.cjs} +1 -0
  103. package/dist/compiler/composition.d.ts +1 -1
  104. package/dist/compiler/runtime-affecting-signature/js.d.ts +1 -0
  105. package/dist/compiler/semantic-css.d.ts +1 -1
  106. package/dist/compiler/types.d.ts +1 -1
  107. package/dist/{compiler-D3GBwxoa.js → compiler-CThodfGH.js} +3098 -3067
  108. package/dist/{compiler-C8FqI-P3.cjs → compiler-DkGY5Nmh.cjs} +5011 -4980
  109. package/dist/core/compiler/generation-cache.d.ts +4 -2
  110. package/dist/core/compiler/types.d.ts +1 -1
  111. package/dist/core.cjs +7 -7
  112. package/dist/core.d.ts +2 -2
  113. package/dist/core.js +2 -2
  114. package/dist/css-cleanup-B6FUJC3z.cjs +1 -0
  115. package/dist/{css-imports-XvtI1zCY.cjs → css-imports-R_RDMjPz.cjs} +7 -21
  116. package/dist/css-macro/auto.d.ts +1 -1
  117. package/dist/css-macro/postcss.cjs +1 -1
  118. package/dist/css-macro.cjs +2 -2
  119. package/dist/css-macro.js +1 -1
  120. package/dist/final-css-cleanup-B6FUJC3z.cjs +1 -0
  121. package/dist/{final-css-cleanup-u_sI2p56.js → final-css-cleanup-BOzhuhGz.js} +3 -2
  122. package/dist/framework.cjs +1 -1
  123. package/dist/{v4-generation-core-Cz1D7wm1.cjs → generated-css-marker-jMNbQHpy.cjs} +638 -1546
  124. package/dist/generation/candidates.d.ts +1 -0
  125. package/dist/generation/class-selectors.d.ts +4 -0
  126. package/dist/generation/config-directive.d.ts +1 -0
  127. package/dist/generation/directives/fallback.d.ts +1 -0
  128. package/dist/generation/directives.d.ts +1 -0
  129. package/dist/generation/framework-css-composition.d.ts +1 -0
  130. package/dist/generation/framework-postcss.d.ts +25 -0
  131. package/dist/generation/framework-user-css.d.ts +5 -0
  132. package/dist/generation/generation-helpers/preflight.d.ts +19 -0
  133. package/dist/generation/generation-helpers/results.d.ts +23 -0
  134. package/dist/generation/generation-helpers/runtime-isolation.d.ts +30 -0
  135. package/dist/generation/generation-helpers/source-order.d.ts +1 -0
  136. package/dist/generation/generation-helpers.d.ts +4 -0
  137. package/dist/generation/index.d.ts +9 -0
  138. package/dist/generation/legacy-compat.d.ts +12 -0
  139. package/dist/generation/legacy-selectors.d.ts +1 -0
  140. package/dist/generation/legacy-units.d.ts +1 -0
  141. package/dist/generation/local-imports.d.ts +1 -0
  142. package/dist/generation/markers.d.ts +1 -0
  143. package/dist/generation/output-import-shell.d.ts +1 -0
  144. package/dist/generation/pipeline/context.d.ts +60 -0
  145. package/dist/generation/pipeline/deferred-output.d.ts +3 -0
  146. package/dist/generation/pipeline/execution.d.ts +3 -0
  147. package/dist/generation/pipeline/fallback-output.d.ts +3 -0
  148. package/dist/generation/pipeline/ordered-output.d.ts +3 -0
  149. package/dist/generation/pipeline/preparation.d.ts +19 -0
  150. package/dist/generation/pipeline.d.ts +2 -0
  151. package/dist/generation/result-helpers.d.ts +6 -0
  152. package/dist/generation/scoped-rules.d.ts +1 -0
  153. package/dist/generation/service.d.ts +20 -0
  154. package/dist/generation/source-files.d.ts +21 -0
  155. package/dist/generation/source-resolver/apply-reference.d.ts +10 -0
  156. package/dist/generation/source-resolver/config.d.ts +7 -0
  157. package/dist/generation/source-resolver/configuration.d.ts +33 -0
  158. package/dist/generation/source-resolver/matching.d.ts +3 -0
  159. package/dist/generation/source-resolver/metadata.d.ts +28 -0
  160. package/dist/generation/source-resolver/postcss-source.d.ts +14 -0
  161. package/dist/generation/source-resolver/resolve-source.d.ts +4 -0
  162. package/dist/generation/source-resolver/resolve-sources.d.ts +5 -0
  163. package/dist/generation/source-resolver/single-source.d.ts +16 -0
  164. package/dist/generation/source-resolver/source-entries.d.ts +3 -0
  165. package/dist/generation/source-resolver/source-matching.d.ts +5 -0
  166. package/dist/generation/source-resolver/types.d.ts +22 -0
  167. package/dist/generation/source-resolver.d.ts +7 -0
  168. package/dist/generation/style-options.d.ts +8 -0
  169. package/dist/generation/style-requests.d.ts +5 -0
  170. package/dist/generation/types.d.ts +65 -0
  171. package/dist/generation/user-css/apply-only.d.ts +5 -0
  172. package/dist/generation/user-css/at-rules.d.ts +1 -0
  173. package/dist/generation/user-css/compile-functions.d.ts +3 -0
  174. package/dist/generation/user-css/generated-cleanup.d.ts +1 -0
  175. package/dist/generation/user-css/source-fragments.d.ts +1 -0
  176. package/dist/generation/user-css/transform.d.ts +1 -0
  177. package/dist/generation/user-css/user-layers.d.ts +1 -0
  178. package/dist/generation/user-css.d.ts +5 -0
  179. package/dist/generation/user-layer-order.d.ts +1 -0
  180. package/dist/generation/validate.d.ts +7 -0
  181. package/dist/generator-CxauQbx3.cjs +1868 -0
  182. package/dist/generator-oKZ5mCJ5.js +1637 -0
  183. package/dist/generator.cjs +10 -4
  184. package/dist/generator.js +1 -1
  185. package/dist/{gulp-BExe5RBF.cjs → gulp-CVvBpIlq.cjs} +27 -26
  186. package/dist/{gulp-BhkIIk7J.js → gulp-DhddVxGA.js} +6 -5
  187. package/dist/gulp.cjs +1 -1
  188. package/dist/gulp.js +1 -1
  189. package/dist/{hmr-timing-CoiJIqDu.cjs → hmr-timing-DfMbbZ1E.cjs} +13 -13
  190. package/dist/{hmr-timing-B9Yt86-U.js → hmr-timing-xPpat-km.js} +518 -1360
  191. package/dist/index.cjs +7 -7
  192. package/dist/index.d.ts +1 -1
  193. package/dist/index.js +5 -5
  194. package/dist/js/ModuleGraph.d.ts +3 -1
  195. package/dist/js/babel/analyze.d.ts +6 -0
  196. package/dist/js/babel.d.ts +1 -2
  197. package/dist/js/fast-path/analysis.d.ts +14 -0
  198. package/dist/js/fast-path/oxc.d.ts +1 -1
  199. package/dist/js/oxc-parser.d.ts +4 -0
  200. package/dist/pipeline-helpers-zMPmp5F3.cjs +516 -0
  201. package/dist/postcss-html-transform.cjs +1 -1
  202. package/dist/postcss.cjs +3 -2
  203. package/dist/postcss.d.ts +1 -1
  204. package/dist/postcss.js +3 -2
  205. package/dist/presets.cjs +3 -3
  206. package/dist/presets.js +2 -2
  207. package/dist/project-sources/candidates/collector.d.ts +8 -0
  208. package/dist/project-sources/candidates/scan-root.d.ts +12 -0
  209. package/dist/project-sources/candidates/script.d.ts +1 -0
  210. package/dist/project-sources/candidates/snapshot.d.ts +19 -0
  211. package/dist/project-sources/candidates/source-priority.d.ts +1 -0
  212. package/dist/project-sources/candidates/store.d.ts +2 -0
  213. package/dist/project-sources/candidates/types-and-cache.d.ts +75 -0
  214. package/dist/project-sources/candidates/views.d.ts +12 -0
  215. package/dist/project-sources/candidates.d.ts +4 -0
  216. package/dist/project-sources/css-entries.d.ts +18 -0
  217. package/dist/project-sources/dependencies.d.ts +2 -0
  218. package/dist/project-sources/index.d.ts +16 -0
  219. package/dist/project-sources/static-config-content.d.ts +5 -0
  220. package/dist/reset.cjs +1 -1
  221. package/dist/{rolldown-runtime-Ctb5zv51.cjs → rolldown-runtime-fg3euq-1.cjs} +7 -0
  222. package/dist/rspack.cjs +4 -4
  223. package/dist/rspack.js +2 -2
  224. package/dist/{runtime-state-XYSycuGu.cjs → runtime-state-BOzuVoKl.cjs} +1 -1
  225. package/dist/{scoped-generator-BUBls_oM.cjs → scoped-generator-BIZ7N_J-.cjs} +9 -9
  226. package/dist/{scoped-generator-B6Y1bxzM.js → scoped-generator-DlQrVbuC.js} +7 -6
  227. package/dist/{source-candidate-scan-signature-DNuGKTqf.js → source-candidate-scan-signature-BjVQYL-C.js} +3 -3
  228. package/dist/{source-candidate-scan-signature-BtJZp28T.cjs → source-candidate-scan-signature-nG-rg809.cjs} +4 -4
  229. package/dist/style-injector/internal.d.ts +35 -35
  230. package/dist/style-injector/options.d.ts +1 -1
  231. package/dist/tailwindcss/miniprogram.d.ts +1 -1
  232. package/dist/tailwindcss/remove-unsupported-css.d.ts +1 -1
  233. package/dist/tailwindcss/source-scan/inline-source.d.ts +1 -7
  234. package/dist/tailwindcss/source-scan.d.ts +3 -32
  235. package/dist/tailwindcss/v4/css-sources.d.ts +1 -1
  236. package/dist/tailwindcss/v4/preflight.d.ts +1 -3
  237. package/dist/tailwindcss/v4/rpx-theme-warning.d.ts +4 -0
  238. package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -1
  239. package/dist/tailwindcss/v4-engine/generator/incremental-cache.d.ts +2 -3
  240. package/dist/tailwindcss/v4-engine/generator/native-session.d.ts +1 -1
  241. package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +1 -6
  242. package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +5 -2
  243. package/dist/tailwindcss/v4-engine/miniprogram.d.ts +3 -7
  244. package/dist/tailwindcss/v4-engine/source.d.ts +1 -1
  245. package/dist/tailwindcss/v4-engine/types.d.ts +3 -1
  246. package/dist/{tailwindcss-CBYjzRmV.cjs → tailwindcss-U3KIUegn.cjs} +65 -264
  247. package/dist/{tailwindcss-B_4E52WF.js → tailwindcss-kSd0ykiX.js} +71 -243
  248. package/dist/{transform-CkEnJYIP.js → transform-BAon9ykq.js} +25 -16
  249. package/dist/{transform-FkqbTBJR.cjs → transform-D2KFdA3C.cjs} +32 -23
  250. package/dist/types/index.d.ts +2 -2
  251. package/dist/types/user-defined-options/general.d.ts +1 -1
  252. package/dist/uni-app-x/border-preflight.d.ts +1 -1
  253. package/dist/uni-app-x/component-local-style.d.ts +3 -1
  254. package/dist/uni-app-x/vite/style-result.d.ts +1 -1
  255. package/dist/utils/run-tasks.d.ts +3 -0
  256. package/dist/vite/web.cjs +1 -1
  257. package/dist/vite/web.js +1 -1
  258. package/dist/{vite-DxuKPZlp.cjs → vite-BxW0qd7J.cjs} +217 -828
  259. package/dist/{vite-lP35OguX.js → vite-D-RGkmOE.js} +62 -674
  260. package/dist/vite.cjs +1 -1
  261. package/dist/vite.js +1 -1
  262. package/dist/{watch-dependencies-GbC14Rlt.cjs → watch-dependencies-C1so1whD.cjs} +14 -1
  263. package/dist/weapp-tw-css-generation-loader.cjs +4 -3
  264. package/dist/weapp-tw-css-import-rewrite-loader.cjs +33 -28
  265. package/dist/weapp-tw-runtime-classset-loader.cjs +5 -18
  266. package/dist/{web-Dfz_jpNj.js → web--kA4HUTm.js} +16 -115
  267. package/dist/{web-DhDxhlkq.cjs → web-Y-H6I1k6.cjs} +83 -192
  268. package/dist/{webpack-D6jp1o3m.js → webpack-BB-kw4Qr.js} +27 -440
  269. package/dist/{webpack-R2Sbggiy.cjs → webpack-DxrWatNB.cjs} +87 -87
  270. package/dist/webpack.cjs +1 -1
  271. package/dist/webpack.js +1 -1
  272. package/package.json +10 -5
  273. package/dist/final-css-cleanup-CDTmVAye.cjs +0 -1
  274. package/dist/generator-Bvr4WmuF.cjs +0 -3891
  275. package/dist/generator-C0BJjyLM.js +0 -3343
  276. package/dist/pipeline-helpers-BOjTEmMi.cjs +0 -971
@@ -1,3343 +0,0 @@
1
- import { resolveUniUtsPlatform as resolveUniUtsPlatform$1 } from "./framework.js";
2
- import { c as withCssMacroStyleOptions, i as hasCssMacroTailwindV4Source, o as transformCssMacroCss, s as transformCssMacroTailwindV4Source, t as hasCssMacroStyleOptions } from "./auto-2dg_uhEJ.js";
3
- import "./utils-MVwpU07P.js";
4
- import { createRequire } from "node:module";
5
- import fs, { existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
6
- import path from "node:path";
7
- import process from "node:process";
8
- import { createTailwindGenerationSession, createTailwindV4Engine, extractRawCandidates, loadTailwindV4DesignSystem, resolveProjectSourceFiles, resolveTailwindV4Source, resolveValidTailwindV4Candidates as resolveValidTailwindV4Candidates$1 } from "@tailwindcss-mangle/engine";
9
- import { analyzeTailwindCssDirectives, applyConfiguredCssCalc, createStyleHandler, filterExistingCssRules, finalizeMiniProgramCss as finalizeMiniProgramCss$1, hasMiniProgramCssSpecificityPlaceholders, isTailwindCssGenerationDirective, isTailwindCssImport, isTailwindCssImportAtRule, isTailwindCssPackageJsonImportRequest, isTailwindRuntimePropertyRule, normalizeTailwindCssImportRequest, normalizeTailwindcssWebRpxDeclarations, parseCssImportSpecifier, parseImportSourceParam, parseTailwindCssConfigRequest, parseTailwindCssDirectiveRequest, postcss, protectDynamicColorMixAlpha, pruneMiniProgramGeneratedCss, pruneMiniProgramGeneratedCss as pruneMiniProgramGeneratedCss$1, quoteCssImportSpecifier, removeTailwindV4PreflightImports, removeUnsupportedCascadeLayers, removeUnsupportedMiniProgramAtRules, removeUnsupportedThemeVendorKeyframes, selectorContainsPseudoClass, stripMiniProgramCssSpecificityPlaceholders } from "@weapp-tailwindcss/postcss";
10
- import { LRUCache } from "lru-cache";
11
- import { stat } from "node:fs/promises";
12
- import micromatch from "micromatch";
13
- //#region src/runtime-branch/generator-target-env.ts
14
- const explicitGeneratorTargetEnvKeys = ["WEAPP_TW_TARGET", "WEAPP_TAILWINDCSS_TARGET"];
15
- const uniWebPlatformEnvKeys = ["UNI_PLATFORM", "UNI_UTS_PLATFORM"];
16
- const mpxWebPlatformEnvKeys = ["MPX_CLI_MODE", "MPX_CURRENT_TARGET_MODE"];
17
- function getEnvValue(key) {
18
- return typeof process === "undefined" ? void 0 : process.env[key];
19
- }
20
- function normalizeGeneratorTargetValue(value) {
21
- return value === "weapp" || value === "web" ? value : void 0;
22
- }
23
- function isUniWebPlatform(value) {
24
- const normalized = value?.trim().toLowerCase();
25
- return normalized === "h5" || normalized?.startsWith("web") === true;
26
- }
27
- function isUniAppWebViewPlatform(value) {
28
- const normalized = value?.trim().toLowerCase();
29
- return normalized === "app" || normalized === "app-plus";
30
- }
31
- function isUniNativeAppPlatform(value) {
32
- return (value?.trim().toLowerCase())?.startsWith("app-") === true;
33
- }
34
- function isMpxWebPlatform(value) {
35
- return value?.trim().toLowerCase() === "web";
36
- }
37
- function inferGeneratorTargetFromExplicitEnv() {
38
- for (const key of explicitGeneratorTargetEnvKeys) {
39
- const target = normalizeGeneratorTargetValue(getEnvValue(key));
40
- if (target !== void 0) return target;
41
- }
42
- }
43
- function shouldUseWebGeneratorTargetFromEnv() {
44
- 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";
45
- }
46
- function shouldUseUniAppWebRpxCompatibility(appType) {
47
- return appType === "uni-app-vite" || appType === "uni-app-x" || shouldUseWebGeneratorTargetFromEnv();
48
- }
49
- function shouldUseUniAppViteWebViewGeneratorTarget(appType, platform = getEnvValue("UNI_PLATFORM")) {
50
- return appType === "uni-app-vite" && isUniAppWebViewPlatform(platform);
51
- }
52
- function inferGeneratorTargetFromEnv() {
53
- return inferGeneratorTargetFromExplicitEnv() ?? (shouldUseWebGeneratorTargetFromEnv() ? "web" : "weapp");
54
- }
55
- //#endregion
56
- //#region src/tailwindcss/v4-engine/candidates.ts
57
- const UNSUPPORTED_MINI_PROGRAM_TAILWIND_V4_CANDIDATE_RE = /(?:^|:)(?:has-)?(?:group|peer|in|not-in)-[^\s:]*\/|(?:^|:)(?:has-)?(?:in|not-in)-\[/;
58
- function isUnsupportedMiniProgramTailwindV4Candidate(candidate) {
59
- return UNSUPPORTED_MINI_PROGRAM_TAILWIND_V4_CANDIDATE_RE.test(candidate);
60
- }
61
- function filterUnsupportedMiniProgramTailwindV4Candidates(candidates) {
62
- if (!candidates) return;
63
- return new Set([...candidates].filter((candidate) => !isUnsupportedMiniProgramTailwindV4Candidate(candidate)));
64
- }
65
- //#endregion
66
- //#region src/tailwindcss/v4-engine/generator/rpx-candidates.ts
67
- const RPX_LENGTH_UTILITY_PATTERN = String.raw`text|border(?:-[trblxyse])?|bg|outline|ring`;
68
- const BARE_RPX_LENGTH_CANDIDATE_RE = new RegExp(String.raw`(^|:)(!?)(${RPX_LENGTH_UTILITY_PATTERN})-\[([-+]?(?:\d+|\d*\.\d+)rpx)\](.*)$`, "u");
69
- const BARE_RPX_LENGTH_HINT_CANDIDATE_RE = new RegExp(String.raw`(?:^|:)!?(${RPX_LENGTH_UTILITY_PATTERN})-\[length:([-+]?(?:\d+|\d*\.\d+)rpx)\].*$`, "u");
70
- const RPX_LENGTH_SELECTOR_RE = new RegExp(String.raw`(${RPX_LENGTH_UTILITY_PATTERN})-\\\[length\\:((?:\\[.+-]|[+\-.\d])+rpx)\\\]`, "g");
71
- function normalizeRpxLengthCandidate(candidate) {
72
- return candidate.replace(BARE_RPX_LENGTH_CANDIDATE_RE, (_match, prefix, important, utility, value, suffix) => {
73
- return `${prefix}${important}${utility}-[length:${value}]${suffix}`;
74
- });
75
- }
76
- function normalizeRpxLengthCandidates(candidates) {
77
- const normalized = /* @__PURE__ */ new Set();
78
- const restoreCandidates = /* @__PURE__ */ new Map();
79
- for (const candidate of candidates) {
80
- const normalizedCandidate = normalizeRpxLengthCandidate(candidate);
81
- normalized.add(normalizedCandidate);
82
- if (normalizedCandidate !== candidate) restoreCandidates.set(normalizedCandidate, candidate);
83
- }
84
- return {
85
- candidates: normalized,
86
- restoreCandidates
87
- };
88
- }
89
- function restoreRpxLengthCandidates(candidates, restoreCandidates) {
90
- if (restoreCandidates.size === 0) return new Set(candidates);
91
- return new Set([...candidates].map((candidate) => restoreCandidates.get(candidate) ?? candidate));
92
- }
93
- function normalizeCssEscapedRpxSelectorValue(value) {
94
- return value.replace(/\\([.+-])/g, "$1");
95
- }
96
- function restoreRpxLengthCssSelectors(css, restoreCandidates) {
97
- if (restoreCandidates.size === 0 || !css.includes("\\[length\\:")) return css;
98
- const restoredUtilities = new Set([...restoreCandidates.keys()].map((candidate) => {
99
- const match = BARE_RPX_LENGTH_HINT_CANDIDATE_RE.exec(candidate);
100
- return match ? `${match[1]}:${match[2]}` : void 0;
101
- }).filter((value) => Boolean(value)));
102
- return css.replace(RPX_LENGTH_SELECTOR_RE, (match, utility, value) => {
103
- return restoredUtilities.has(`${utility}:${normalizeCssEscapedRpxSelectorValue(value)}`) ? `${utility}-\\[${value}\\]` : match;
104
- });
105
- }
106
- const INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX = 12e3;
107
- const INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX = 2097152;
108
- const incrementalGenerateCache = new LRUCache({ max: 8 });
109
- const incrementalGenerateTaskCache = new LRUCache({ max: 32 });
110
- function collectCandidates(candidates) {
111
- return new Set(candidates ?? []);
112
- }
113
- function hasRemovedCandidates(previousCandidates, nextCandidates) {
114
- for (const candidate of previousCandidates) if (!nextCandidates.has(candidate)) return true;
115
- return false;
116
- }
117
- function createStableJson(value) {
118
- if (value === void 0) return "undefined";
119
- if (value === null || typeof value !== "object") return JSON.stringify(value);
120
- if (Array.isArray(value)) return `[${value.map((item) => createStableJson(item)).join(",")}]`;
121
- return `{${Object.keys(value).sort().map((key) => {
122
- const record = value;
123
- return `${JSON.stringify(key)}:${createStableJson(record[key])}`;
124
- }).join(",")}}`;
125
- }
126
- function createDependencyFingerprint(files) {
127
- return files.map((file) => {
128
- try {
129
- const stat = fs.statSync(file);
130
- return `${file}:${stat.size}:${stat.mtimeMs}`;
131
- } catch {
132
- return `${file}:missing`;
133
- }
134
- }).join("|");
135
- }
136
- function createTailwindV4SourceCacheKey(source) {
137
- return [
138
- source.projectRoot,
139
- source.base,
140
- createStableJson(source.baseFallbacks),
141
- source.css,
142
- createDependencyFingerprint(source.dependencies)
143
- ].join("\0");
144
- }
145
- function createIncrementalGenerateCacheKey(source, target, styleOptions) {
146
- return [
147
- createTailwindV4SourceCacheKey(source),
148
- target,
149
- createStableJson(styleOptions)
150
- ].join("\0");
151
- }
152
- function createIncrementalGenerateTaskCacheKey(cacheKey, requestedCandidates, scanSources) {
153
- return [
154
- cacheKey,
155
- scanSources === true ? "scan:1" : "scan:0",
156
- [...requestedCandidates].sort().join("\n")
157
- ].join("\0");
158
- }
159
- function runIncrementalGenerateTask(cacheKey, requestedCandidates, scanSources, task) {
160
- const taskKey = createIncrementalGenerateTaskCacheKey(cacheKey, requestedCandidates, scanSources);
161
- const cachedTask = incrementalGenerateTaskCache.get(taskKey);
162
- if (cachedTask) return cachedTask;
163
- const promise = task();
164
- incrementalGenerateTaskCache.set(taskKey, promise);
165
- promise.finally(() => {
166
- if (incrementalGenerateTaskCache.get(taskKey) === promise) incrementalGenerateTaskCache.delete(taskKey);
167
- });
168
- return promise;
169
- }
170
- function createIncrementalDesignSystemPromise(source, cacheKey) {
171
- const promise = loadTailwindV4DesignSystem(source);
172
- promise.catch(() => {
173
- if (incrementalGenerateCache.get(cacheKey)?.designSystemPromise === promise) incrementalGenerateCache.delete(cacheKey);
174
- });
175
- return promise;
176
- }
177
- function resolveTargetCandidates(candidates, target) {
178
- const collected = collectCandidates(candidates);
179
- return target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(collected) : collected;
180
- }
181
- function collectSeenCandidates(generated) {
182
- return new Set(generated.classSet);
183
- }
184
- function createIncrementalStyleOptions(styleOptions) {
185
- return {
186
- ...styleOptions,
187
- isMainChunk: false
188
- };
189
- }
190
- function resolveStyleOptions(source, options) {
191
- return hasCssMacroTailwindV4Source(source.css) ? withCssMacroStyleOptions(options) : options;
192
- }
193
- function collectCustomPropertyValues(css) {
194
- const values = /* @__PURE__ */ new Map();
195
- try {
196
- postcss.parse(css).walkDecls((decl) => {
197
- if (decl.prop.startsWith("--")) values.set(decl.prop, decl.value.trim());
198
- });
199
- } catch {}
200
- return values;
201
- }
202
- function mergeCustomPropertyValues(target, css) {
203
- for (const [prop, value] of collectCustomPropertyValues(css)) target.set(prop, value);
204
- }
205
- function createStableTextSignature(input) {
206
- let hash = 2166136261;
207
- for (let i = 0; i < input.length; i++) {
208
- hash ^= input.charCodeAt(i);
209
- hash = Math.imul(hash, 16777619);
210
- }
211
- return (hash >>> 0).toString(36);
212
- }
213
- function summarizeIncrementalCacheKey(key) {
214
- return {
215
- keyHash: createStableTextSignature(key),
216
- keyBytes: key.length
217
- };
218
- }
219
- function shouldRebuildIncrementalEntry(cached, requestedCandidates, missingCandidates) {
220
- return cached.seenCandidates.size + missingCandidates.length > 12e3 || cached.css.length > 2097152 || cached.rawCss.length > 2097152 || requestedCandidates.size > 12e3;
221
- }
222
- function shouldAdmitIncrementalEntry(requestedCandidates, generated) {
223
- return requestedCandidates.size <= 12e3 && generated.css.length <= 2097152 && generated.rawCss.length <= 2097152;
224
- }
225
- function seedIncrementalGenerateCache(options) {
226
- if (!shouldAdmitIncrementalEntry(options.requestedCandidates, options.generated)) return false;
227
- const cacheKey = createIncrementalGenerateCacheKey(options.compatibleSource, options.target, options.styleOptions);
228
- const customPropertyValues = collectCustomPropertyValues(options.compatibleSource.css);
229
- mergeCustomPropertyValues(customPropertyValues, options.generated.css);
230
- incrementalGenerateCache.set(cacheKey, {
231
- seenCandidates: collectSeenCandidates(options.generated),
232
- classSet: new Set(options.generated.classSet),
233
- css: options.generated.css,
234
- rawCss: options.generated.rawCss,
235
- customPropertyValues,
236
- designSystemPromise: createIncrementalDesignSystemPromise(options.compatibleSource, cacheKey),
237
- dependencies: options.generated.dependencies,
238
- sources: options.generated.sources,
239
- root: options.generated.root,
240
- target: options.generated.target
241
- });
242
- return true;
243
- }
244
- function shouldNormalizeRpxLengthCandidatesForTarget(target, styleOptions) {
245
- if (target !== "web") return true;
246
- return shouldUseUniAppWebRpxCompatibility(styleOptions?.appType);
247
- }
248
- function normalizeTargetRpxLengthCandidates(candidates, target, styleOptions) {
249
- return shouldNormalizeRpxLengthCandidatesForTarget(target, styleOptions) ? normalizeRpxLengthCandidates(candidates) : {
250
- candidates: new Set(candidates),
251
- restoreCandidates: /* @__PURE__ */ new Map()
252
- };
253
- }
254
- //#endregion
255
- //#region src/tailwindcss/v4-engine/generator/cache-stats.ts
256
- function getTailwindV4IncrementalGenerateCacheStats() {
257
- return {
258
- max: 8,
259
- entryCandidatesMax: INCREMENTAL_GENERATE_ENTRY_CANDIDATES_MAX,
260
- entryCssBytesMax: INCREMENTAL_GENERATE_ENTRY_CSS_BYTES_MAX,
261
- size: incrementalGenerateCache.size,
262
- taskMax: 32,
263
- taskSize: incrementalGenerateTaskCache.size,
264
- entries: [...incrementalGenerateCache.entries()].map(([key, entry]) => ({
265
- ...summarizeIncrementalCacheKey(key),
266
- candidates: entry.seenCandidates.size,
267
- classSet: entry.classSet.size,
268
- cssBytes: entry.css.length,
269
- rawCssBytes: entry.rawCss.length
270
- })),
271
- keys: [...incrementalGenerateCache.keys()].map(summarizeIncrementalCacheKey),
272
- taskKeys: [...incrementalGenerateTaskCache.keys()].map(summarizeIncrementalCacheKey)
273
- };
274
- }
275
- //#endregion
276
- //#region src/tailwindcss/v4-engine/css-macro-source.ts
277
- function resolveCssMacroTailwindV4Source(source) {
278
- const css = transformCssMacroTailwindV4Source(source.css);
279
- return css === source.css ? source : {
280
- ...source,
281
- css
282
- };
283
- }
284
- //#endregion
285
- //#region src/tailwindcss/v4-engine/miniprogram.ts
286
- const defaultStyleHandler = createStyleHandler({
287
- cssChildCombinatorReplaceValue: ["view", "text"],
288
- cssRemoveActivePseudoClass: true,
289
- cssRemoveHoverPseudoClass: true,
290
- cssRemoveFocusPseudoClass: true,
291
- isMainChunk: true,
292
- majorVersion: 4
293
- });
294
- const CSS_DECLARATION_URL_RE = /(:\s*)url\(([^\n\r"';[\]{}]*[[\]{}][^\n\r;]*)\)(?=\s*;)/g;
295
- function normalizeTailwindV4GeneratedUrlValues(css) {
296
- return css.replace(CSS_DECLARATION_URL_RE, (match, prefix, urlValue) => {
297
- try {
298
- return `${prefix}url("${urlValue.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}")`;
299
- } catch {
300
- return match;
301
- }
302
- });
303
- }
304
- async function transformTailwindV4CssToWeapp(css, options) {
305
- const compatibleCss = normalizeTailwindV4GeneratedUrlValues(hasCssMacroStyleOptions(options) ? await transformCssMacroCss(css, options) : css);
306
- const customPropertyValues = options?.customPropertyValues;
307
- const protectedCss = protectDynamicColorMixAlpha(compatibleCss, { customPropertyValues });
308
- const result = await defaultStyleHandler(protectedCss.css, {
309
- cssChildCombinatorReplaceValue: ["view", "text"],
310
- cssRemoveActivePseudoClass: true,
311
- cssRemoveHoverPseudoClass: true,
312
- cssRemoveFocusPseudoClass: true,
313
- isMainChunk: true,
314
- majorVersion: 4,
315
- ...options
316
- });
317
- const pruneOptions = {
318
- ...options?.uniAppX === true && options.uniAppXCssTarget === "uvue" ? { preserveContentInit: false } : {},
319
- preservePreflight: true,
320
- preserveConditionalComments: hasCssMacroStyleOptions(options)
321
- };
322
- return pruneMiniProgramGeneratedCss$1(protectedCss.restore(result.css), pruneOptions);
323
- }
324
- function transformTailwindV4WebRpxCss(css) {
325
- if (!css.includes("rpx")) return css;
326
- try {
327
- const root = postcss.parse(css);
328
- return normalizeTailwindcssWebRpxDeclarations(root, { majorVersion: 4 }) ? root.toString() : css;
329
- } catch {
330
- return css;
331
- }
332
- }
333
- async function transformTailwindV4CssByTarget(css, target, options) {
334
- if (target === "weapp") return transformTailwindV4CssToWeapp(css, options);
335
- const resolvedWebCss = await (hasCssMacroStyleOptions(options) ? transformCssMacroCss(css, options) : css);
336
- const calculatedWebCss = await applyConfiguredCssCalc(resolvedWebCss, options ?? {});
337
- return shouldUseUniAppWebRpxCompatibility(options?.appType) ? transformTailwindV4WebRpxCss(calculatedWebCss) : calculatedWebCss;
338
- }
339
- //#endregion
340
- //#region src/tailwindcss/v4-engine/tailwind-v4-default-colors.ts
341
- const TAILWIND_V4_COLOR_STEPS = [
342
- "50",
343
- "100",
344
- "200",
345
- "300",
346
- "400",
347
- "500",
348
- "600",
349
- "700",
350
- "800",
351
- "900",
352
- "950"
353
- ];
354
- const TAILWIND_V4_COLOR_PALETTE = {
355
- slate: [
356
- "#f8fafc",
357
- "#f1f5f9",
358
- "#e2e8f0",
359
- "#cad5e2",
360
- "#90a1b9",
361
- "#62748e",
362
- "#45556c",
363
- "#314158",
364
- "#1d293d",
365
- "#0f172b",
366
- "#020618"
367
- ],
368
- gray: [
369
- "#f9fafb",
370
- "#f3f4f6",
371
- "#e5e7eb",
372
- "#d1d5dc",
373
- "#99a1af",
374
- "#6a7282",
375
- "#4a5565",
376
- "#364153",
377
- "#1e2939",
378
- "#101828",
379
- "#030712"
380
- ],
381
- zinc: [
382
- "#fafafa",
383
- "#f4f4f5",
384
- "#e4e4e7",
385
- "#d4d4d8",
386
- "#9f9fa9",
387
- "#71717b",
388
- "#52525c",
389
- "#3f3f46",
390
- "#27272a",
391
- "#18181b",
392
- "#09090b"
393
- ],
394
- neutral: [
395
- "#fafafa",
396
- "#f5f5f5",
397
- "#e5e5e5",
398
- "#d4d4d4",
399
- "#a1a1a1",
400
- "#737373",
401
- "#525252",
402
- "#404040",
403
- "#262626",
404
- "#171717",
405
- "#0a0a0a"
406
- ],
407
- stone: [
408
- "#fafaf9",
409
- "#f5f5f4",
410
- "#e7e5e4",
411
- "#d6d3d1",
412
- "#a6a09b",
413
- "#79716b",
414
- "#57534d",
415
- "#44403b",
416
- "#292524",
417
- "#1c1917",
418
- "#0c0a09"
419
- ],
420
- mauve: [
421
- "#fafafa",
422
- "#f3f1f3",
423
- "#e7e4e7",
424
- "#d7d0d7",
425
- "#a89ea9",
426
- "#79697b",
427
- "#594c5b",
428
- "#463947",
429
- "#2a212c",
430
- "#1d161e",
431
- "#0c090c"
432
- ],
433
- olive: [
434
- "#fbfbf9",
435
- "#f4f4f0",
436
- "#e8e8e3",
437
- "#d8d8d0",
438
- "#abab9c",
439
- "#7c7c67",
440
- "#5b5b4b",
441
- "#474739",
442
- "#2b2b22",
443
- "#1d1d16",
444
- "#0c0c09"
445
- ],
446
- mist: [
447
- "#f9fbfb",
448
- "#f1f3f3",
449
- "#e3e7e8",
450
- "#d0d6d8",
451
- "#9ca8ab",
452
- "#67787c",
453
- "#4b585b",
454
- "#394447",
455
- "#22292b",
456
- "#161b1d",
457
- "#090b0c"
458
- ],
459
- taupe: [
460
- "#fbfaf9",
461
- "#f3f1f1",
462
- "#e8e4e3",
463
- "#d8d2d0",
464
- "#aba09c",
465
- "#7c6d67",
466
- "#5b4f4b",
467
- "#473c39",
468
- "#2b2422",
469
- "#1d1816",
470
- "#0c0a09"
471
- ],
472
- red: [
473
- "#fef2f2",
474
- "#ffe2e2",
475
- "#ffc9c9",
476
- "#ffa2a2",
477
- "#ff6467",
478
- "#fb2c36",
479
- "#e7000b",
480
- "#c10007",
481
- "#9f0712",
482
- "#82181a",
483
- "#460809"
484
- ],
485
- orange: [
486
- "#fff7ed",
487
- "#ffedd4",
488
- "#ffd6a7",
489
- "#ffb86a",
490
- "#ff8904",
491
- "#ff6900",
492
- "#f54900",
493
- "#ca3500",
494
- "#9f2d00",
495
- "#7e2a0c",
496
- "#441306"
497
- ],
498
- amber: [
499
- "#fffbeb",
500
- "#fef3c6",
501
- "#fee685",
502
- "#ffd230",
503
- "#ffb900",
504
- "#fe9a00",
505
- "#e17100",
506
- "#bb4d00",
507
- "#973c00",
508
- "#7b3306",
509
- "#461901"
510
- ],
511
- yellow: [
512
- "#fefce8",
513
- "#fef9c2",
514
- "#fff085",
515
- "#ffdf20",
516
- "#fdc700",
517
- "#f0b100",
518
- "#d08700",
519
- "#a65f00",
520
- "#894b00",
521
- "#733e0a",
522
- "#432004"
523
- ],
524
- lime: [
525
- "#f7fee7",
526
- "#ecfcca",
527
- "#d8f999",
528
- "#bbf451",
529
- "#9ae600",
530
- "#7ccf00",
531
- "#5ea500",
532
- "#497d00",
533
- "#3c6300",
534
- "#35530e",
535
- "#192e03"
536
- ],
537
- green: [
538
- "#f0fdf4",
539
- "#dcfce7",
540
- "#b9f8cf",
541
- "#7bf1a8",
542
- "#05df72",
543
- "#00c950",
544
- "#00a63e",
545
- "#008236",
546
- "#016630",
547
- "#0d542b",
548
- "#032e15"
549
- ],
550
- emerald: [
551
- "#ecfdf5",
552
- "#d0fae5",
553
- "#a4f4cf",
554
- "#5ee9b5",
555
- "#00d492",
556
- "#00bc7d",
557
- "#009966",
558
- "#007a55",
559
- "#006045",
560
- "#004f3b",
561
- "#002c22"
562
- ],
563
- teal: [
564
- "#f0fdfa",
565
- "#cbfbf1",
566
- "#96f7e4",
567
- "#46ecd5",
568
- "#00d5be",
569
- "#00bba7",
570
- "#009689",
571
- "#00786f",
572
- "#005f5a",
573
- "#0b4f4a",
574
- "#022f2e"
575
- ],
576
- cyan: [
577
- "#ecfeff",
578
- "#cefafe",
579
- "#a2f4fd",
580
- "#53eafd",
581
- "#00d3f2",
582
- "#00b8db",
583
- "#0092b8",
584
- "#007595",
585
- "#005f78",
586
- "#104e64",
587
- "#053345"
588
- ],
589
- sky: [
590
- "#f0f9ff",
591
- "#dff2fe",
592
- "#b8e6fe",
593
- "#74d4ff",
594
- "#00bcff",
595
- "#00a6f4",
596
- "#0084d1",
597
- "#0069a8",
598
- "#00598a",
599
- "#024a70",
600
- "#052f4a"
601
- ],
602
- blue: [
603
- "#eff6ff",
604
- "#dbeafe",
605
- "#bedbff",
606
- "#8ec5ff",
607
- "#51a2ff",
608
- "#2b7fff",
609
- "#155dfc",
610
- "#1447e6",
611
- "#193cb8",
612
- "#1c398e",
613
- "#162456"
614
- ],
615
- indigo: [
616
- "#eef2ff",
617
- "#e0e7ff",
618
- "#c6d2ff",
619
- "#a3b3ff",
620
- "#7c86ff",
621
- "#615fff",
622
- "#4f39f6",
623
- "#432dd7",
624
- "#372aac",
625
- "#312c85",
626
- "#1e1a4d"
627
- ],
628
- violet: [
629
- "#f5f3ff",
630
- "#ede9fe",
631
- "#ddd6ff",
632
- "#c4b4ff",
633
- "#a684ff",
634
- "#8e51ff",
635
- "#7f22fe",
636
- "#7008e7",
637
- "#5d0ec0",
638
- "#4d179a",
639
- "#2f0d68"
640
- ],
641
- purple: [
642
- "#faf5ff",
643
- "#f3e8ff",
644
- "#e9d4ff",
645
- "#dab2ff",
646
- "#c27aff",
647
- "#ad46ff",
648
- "#9810fa",
649
- "#8200db",
650
- "#6e11b0",
651
- "#59168b",
652
- "#3c0366"
653
- ],
654
- fuchsia: [
655
- "#fdf4ff",
656
- "#fae8ff",
657
- "#f6cfff",
658
- "#f4a8ff",
659
- "#ed6aff",
660
- "#e12afb",
661
- "#c800de",
662
- "#a800b7",
663
- "#8a0194",
664
- "#721378",
665
- "#4b004f"
666
- ],
667
- pink: [
668
- "#fdf2f8",
669
- "#fce7f3",
670
- "#fccee8",
671
- "#fda5d5",
672
- "#fb64b6",
673
- "#f6339a",
674
- "#e60076",
675
- "#c6005c",
676
- "#a3004c",
677
- "#861043",
678
- "#510424"
679
- ],
680
- rose: [
681
- "#fff1f2",
682
- "#ffe4e6",
683
- "#ffccd3",
684
- "#ffa1ad",
685
- "#ff637e",
686
- "#ff2056",
687
- "#ec003f",
688
- "#c70036",
689
- "#a50036",
690
- "#8b0836",
691
- "#4d0218"
692
- ]
693
- };
694
- function createTailwindV4DefaultColorThemeCss() {
695
- const declarations = [" --color-black: #000;", " --color-white: #fff;"];
696
- for (const [color, values] of Object.entries(TAILWIND_V4_COLOR_PALETTE)) for (let index = 0; index < TAILWIND_V4_COLOR_STEPS.length; index++) declarations.push(` --color-${color}-${TAILWIND_V4_COLOR_STEPS[index]}: ${values[index]};`);
697
- return [
698
- "@theme {",
699
- ...declarations,
700
- "}"
701
- ].join("\n");
702
- }
703
- //#endregion
704
- //#region src/tailwindcss/v4-engine/generator/css-compat.ts
705
- const require$1 = createRequire(import.meta.url);
706
- const tailwindThemeCssCache = /* @__PURE__ */ new Map();
707
- function findLeadingImportInsertionIndex(css) {
708
- const importPattern = /(?:^|\n)\s*@import\b[^;]*;/g;
709
- let insertionIndex = 0;
710
- let match = importPattern.exec(css);
711
- while (match !== null) {
712
- insertionIndex = match.index + match[0].length;
713
- match = importPattern.exec(css);
714
- }
715
- return insertionIndex;
716
- }
717
- function readCachedCss(file) {
718
- const cached = tailwindThemeCssCache.get(file);
719
- if (cached !== void 0) return cached;
720
- const css = readFileSync(file, "utf8");
721
- tailwindThemeCssCache.set(file, css);
722
- return css;
723
- }
724
- function resolveTailwindV4ThemeCssFromImport(css) {
725
- const root = postcss.parse(css);
726
- let resolved;
727
- root.walkAtRules("import", (rule) => {
728
- if (resolved) return;
729
- const specifier = parseCssImportSpecifier(rule.params)?.specifier;
730
- if (!specifier || !path.isAbsolute(specifier) || path.basename(specifier) !== "index.css") return;
731
- const themeCss = path.join(path.dirname(specifier), "theme.css");
732
- if (existsSync(themeCss)) resolved = themeCss;
733
- });
734
- return resolved;
735
- }
736
- function resolveTailwindV4ThemeCssFromBase(base) {
737
- try {
738
- return createRequire(path.join(base, "package.json")).resolve("tailwindcss/theme.css");
739
- } catch {
740
- try {
741
- return require$1.resolve("tailwindcss/theme.css");
742
- } catch {
743
- return;
744
- }
745
- }
746
- }
747
- function resolveTailwindV4DefaultThemeCss(source) {
748
- try {
749
- const themeCss = resolveTailwindV4ThemeCssFromImport(source.css) ?? resolveTailwindV4ThemeCssFromBase(source.base);
750
- return themeCss ? readCachedCss(themeCss) : createTailwindV4DefaultColorThemeCss();
751
- } catch {
752
- return createTailwindV4DefaultColorThemeCss();
753
- }
754
- }
755
- function applyMiniProgramTailwindV4DefaultColorCss(css, source) {
756
- const themeCss = resolveTailwindV4DefaultThemeCss(source);
757
- const insertionIndex = findLeadingImportInsertionIndex(css);
758
- if (insertionIndex === 0) return `${themeCss}\n${css}`;
759
- return `${css.slice(0, insertionIndex)}\n${themeCss}\n${css.slice(insertionIndex)}`;
760
- }
761
- function createCompatibleSource(source, target) {
762
- const filteredSourceCss = target === "weapp" ? removeTailwindV4PreflightImports(source.css) : source.css;
763
- const sourceCss = target === "weapp" ? applyMiniProgramTailwindV4DefaultColorCss(filteredSourceCss, source) : filteredSourceCss;
764
- const compatibleSourceCss = removeUnsupportedThemeVendorKeyframes(sourceCss);
765
- return compatibleSourceCss === source.css ? source : {
766
- ...source,
767
- css: compatibleSourceCss
768
- };
769
- }
770
- //#endregion
771
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/typeof.js
772
- function _typeof(o) {
773
- "@babel/helpers - typeof";
774
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
775
- return typeof o;
776
- } : function(o) {
777
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
778
- }, _typeof(o);
779
- }
780
- //#endregion
781
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPrimitive.js
782
- function toPrimitive(t, r) {
783
- if ("object" != _typeof(t) || !t) return t;
784
- var e = t[Symbol.toPrimitive];
785
- if (void 0 !== e) {
786
- var i = e.call(t, r || "default");
787
- if ("object" != _typeof(i)) return i;
788
- throw new TypeError("@@toPrimitive must return a primitive value.");
789
- }
790
- return ("string" === r ? String : Number)(t);
791
- }
792
- //#endregion
793
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPropertyKey.js
794
- function toPropertyKey(t) {
795
- var i = toPrimitive(t, "string");
796
- return "symbol" == _typeof(i) ? i : i + "";
797
- }
798
- //#endregion
799
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/defineProperty.js
800
- function _defineProperty(e, r, t) {
801
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
802
- value: t,
803
- enumerable: !0,
804
- configurable: !0,
805
- writable: !0
806
- }) : e[r] = t, e;
807
- }
808
- //#endregion
809
- //#region src/tailwindcss/v4-engine/generator/native-session.ts
810
- var TailwindV4NativeSessionPool = class {
811
- constructor(createSession = createTailwindGenerationSession) {
812
- this.createSession = createSession;
813
- _defineProperty(this, "sessions", /* @__PURE__ */ new Map());
814
- _defineProperty(this, "disposed", false);
815
- }
816
- generate(target, sourceKey, source, request) {
817
- const entry = this.getSession(target, sourceKey, source);
818
- const generated = entry.pending.then(() => entry.session.generate(request));
819
- entry.pending = generated.then(() => void 0, () => void 0);
820
- return generated;
821
- }
822
- dispose() {
823
- for (const entry of this.sessions.values()) this.disposeEntry(entry);
824
- this.sessions.clear();
825
- this.disposed = true;
826
- }
827
- get size() {
828
- return this.sessions.size;
829
- }
830
- getSession(target, sourceKey, source) {
831
- if (this.disposed) throw new Error("TailwindV4NativeSessionPool 已释放。");
832
- const cached = this.sessions.get(target);
833
- if (cached?.sourceKey === sourceKey) return cached;
834
- if (cached) this.disposeEntry(cached);
835
- const session = this.createSession(source);
836
- const entry = {
837
- pending: Promise.resolve(),
838
- session,
839
- sourceKey
840
- };
841
- this.sessions.set(target, entry);
842
- return entry;
843
- }
844
- disposeEntry(entry) {
845
- entry.pending.then(() => entry.session.dispose());
846
- }
847
- };
848
- function createEngineSourceEntries(sources, sourceId) {
849
- return sources.map((source, index) => ({
850
- id: `${sourceId}:candidate-source:${index}`,
851
- ...source
852
- }));
853
- }
854
- function serializeTailwindGenerationArtifact(artifact) {
855
- return [...artifact.fragments].sort((left, right) => left.order - right.order).map((fragment) => fragment.root.toString()).join("\n");
856
- }
857
- //#endregion
858
- //#region src/tailwindcss/source-scan.ts
859
- const DEFAULT_SOURCE_SCAN_EXTENSIONS = [
860
- "html",
861
- "wxml",
862
- "axml",
863
- "jxml",
864
- "ksml",
865
- "ttml",
866
- "qml",
867
- "qxml",
868
- "tyml",
869
- "xhsml",
870
- "swan",
871
- "vue",
872
- "mpx",
873
- "js",
874
- "jsx",
875
- "ts",
876
- "tsx"
877
- ];
878
- const FULL_SOURCE_SCAN_EXTENSIONS = [
879
- "js",
880
- "jsx",
881
- "mjs",
882
- "cjs",
883
- "ts",
884
- "tsx",
885
- "mts",
886
- "cts",
887
- "vue",
888
- "uvue",
889
- "nvue",
890
- "svelte",
891
- "mpx",
892
- "html",
893
- "wxml",
894
- "axml",
895
- "jxml",
896
- "ksml",
897
- "ttml",
898
- "qml",
899
- "qxml",
900
- "tyml",
901
- "xhsml",
902
- "swan",
903
- "css",
904
- "wxss",
905
- "acss",
906
- "jxss",
907
- "ttss",
908
- "qss",
909
- "tyss",
910
- "scss",
911
- "sass",
912
- "less",
913
- "styl",
914
- "stylus"
915
- ];
916
- function createSourceScanPattern(extensions = DEFAULT_SOURCE_SCAN_EXTENSIONS) {
917
- return `**/*.{${extensions.join(",")}}`;
918
- }
919
- const FULL_SOURCE_SCAN_PATTERN = createSourceScanPattern(FULL_SOURCE_SCAN_EXTENSIONS);
920
- const FULL_SOURCE_SCAN_EXTENSION_RE = new RegExp(`\\.(?:${FULL_SOURCE_SCAN_EXTENSIONS.map((extension) => extension.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})$`);
921
- function toPosixPath(value) {
922
- return value.split(path.sep).join("/").split(path.win32.sep).join("/");
923
- }
924
- function resolveSourceScanPath(value) {
925
- return resolveSourceScanPathWithApi(value, path);
926
- }
927
- function resolveSourceScanPathWithApi(value, pathApi) {
928
- const resolved = pathApi.resolve(value);
929
- let current = resolved;
930
- const missing = [];
931
- while (true) try {
932
- return pathApi.join(realpathSync.native(current), ...missing.reverse());
933
- } catch (error) {
934
- const parent = pathApi.dirname(current);
935
- if (error.code !== "ENOENT" || parent === current) return resolved;
936
- missing.push(pathApi.basename(current));
937
- current = parent;
938
- }
939
- }
940
- function normalizeEntryPattern(entry) {
941
- const pathApi = isWindowsPath(entry.base) || isWindowsPath(entry.pattern) ? path.win32 : path;
942
- return pathApi.isAbsolute(entry.pattern) ? toPosixPath(pathApi.relative(pathApi.resolve(entry.base), entry.pattern)) : entry.pattern;
943
- }
944
- function isFileMatchedByTailwindSourceEntry(file, entry) {
945
- const pathApi = isWindowsPath(entry.base) || isWindowsPath(file) ? path.win32 : path;
946
- const base = resolveSourceScanPathWithApi(entry.base, pathApi);
947
- const relative = toPosixPath(pathApi.relative(base, file));
948
- return relative && !relative.startsWith("../") && !pathApi.isAbsolute(relative) && micromatch.isMatch(relative, normalizeEntryPattern(entry));
949
- }
950
- function isWindowsPath(value) {
951
- return /^[A-Z]:[\\/]/i.test(value) || value.includes("\\");
952
- }
953
- function isFileExcludedByTailwindSourceEntries(file, entries) {
954
- if (!entries?.length) return false;
955
- const resolvedFile = resolveSourceScanMatcherFile(file, entries);
956
- return entries.some((entry) => entry.negated && isFileMatchedByTailwindSourceEntry(resolvedFile, entry));
957
- }
958
- function isFileMatchedByTailwindSourceEntries(file, entries) {
959
- if (!entries?.length) return true;
960
- const resolvedFile = resolveSourceScanMatcherFile(file, entries);
961
- const positiveEntries = entries.filter((entry) => !entry.negated);
962
- const negativeEntries = entries.filter((entry) => entry.negated);
963
- if (positiveEntries.length === 0) return !negativeEntries.some((entry) => isFileMatchedByTailwindSourceEntry(resolvedFile, entry));
964
- if (!positiveEntries.some((entry) => isFileMatchedByTailwindSourceEntry(resolvedFile, entry))) return false;
965
- return !negativeEntries.some((entry) => isFileMatchedByTailwindSourceEntry(resolvedFile, entry));
966
- }
967
- function resolveSourceScanMatcherFile(file, entries) {
968
- return isWindowsPath(file) || entries.some((entry) => isWindowsPath(entry.base) || isWindowsPath(entry.pattern)) ? resolveSourceScanPathWithApi(file, path.win32) : resolveSourceScanPath(file);
969
- }
970
- function resolveTailwindV4CssSourceBase(source, fallbackBase) {
971
- if (typeof source.base === "string" && source.base.length > 0) return source.base;
972
- if (typeof source.file === "string" && source.file.length > 0) return path.dirname(source.file);
973
- return fallbackBase;
974
- }
975
- function parseConfigParam(params) {
976
- const value = params.trim();
977
- return /^(['"])(.+)\1$/.exec(value)?.[2];
978
- }
979
- function isLegacyContentObject(value) {
980
- return typeof value === "object" && value !== null && "files" in value;
981
- }
982
- function normalizeGlobPattern(pattern) {
983
- return pattern.startsWith("./") ? pattern.slice(2) : pattern;
984
- }
985
- function hasGlobMagic(value) {
986
- return /[*?[\]{}()!+@]/.test(value);
987
- }
988
- function splitStaticGlobPrefix(pattern) {
989
- const segments = normalizeGlobPattern(pattern).split(/[\\/]+/);
990
- const prefix = [];
991
- const rest = [];
992
- let reachedGlob = false;
993
- for (const segment of segments) {
994
- if (!reachedGlob && segment && !hasGlobMagic(segment)) {
995
- prefix.push(segment);
996
- continue;
997
- }
998
- reachedGlob = true;
999
- rest.push(segment);
1000
- }
1001
- return {
1002
- prefix,
1003
- rest
1004
- };
1005
- }
1006
- function normalizeLegacyContentEntries(content, base, options = {}) {
1007
- if (typeof content === "string") {
1008
- const negated = content.startsWith("!");
1009
- return [{
1010
- base,
1011
- negated,
1012
- pattern: normalizeGlobPattern(negated ? content.slice(1) : content)
1013
- }];
1014
- }
1015
- if (Array.isArray(content)) return content.flatMap((item) => normalizeLegacyContentEntries(item, base, options));
1016
- if (isLegacyContentObject(content)) return normalizeLegacyContentEntries(content.files, content.relative && options.relativeBase ? options.relativeBase : base, options);
1017
- return [];
1018
- }
1019
- async function pathExistsAsDirectory(file) {
1020
- try {
1021
- return (await stat(file)).isDirectory();
1022
- } catch {
1023
- return false;
1024
- }
1025
- }
1026
- async function resolveTailwindSourceEntry(sourcePath, base, negated, defaultPattern = createSourceScanPattern()) {
1027
- const absoluteSource = path.isAbsolute(sourcePath) ? path.resolve(sourcePath) : path.resolve(base, sourcePath);
1028
- if (await pathExistsAsDirectory(absoluteSource)) return {
1029
- base: absoluteSource,
1030
- negated,
1031
- pattern: normalizeGlobPattern(defaultPattern)
1032
- };
1033
- if (path.isAbsolute(sourcePath) && hasGlobMagic(sourcePath)) {
1034
- const { prefix, rest } = splitStaticGlobPrefix(sourcePath);
1035
- const root = path.parse(sourcePath).root;
1036
- const normalizedPrefix = prefix[0] === "" ? prefix.slice(1) : prefix;
1037
- if (rest.length > 0) return {
1038
- base: path.resolve(root, ...normalizedPrefix),
1039
- negated,
1040
- pattern: normalizeGlobPattern(rest.join("/"))
1041
- };
1042
- }
1043
- if (path.isAbsolute(sourcePath)) return {
1044
- base: path.dirname(absoluteSource),
1045
- negated,
1046
- pattern: normalizeGlobPattern(path.basename(absoluteSource))
1047
- };
1048
- const { prefix, rest } = splitStaticGlobPrefix(sourcePath);
1049
- if (prefix.length > 0 && rest.length > 0) return {
1050
- base: path.resolve(base, ...prefix),
1051
- negated,
1052
- pattern: normalizeGlobPattern(rest.join("/"))
1053
- };
1054
- return {
1055
- base,
1056
- negated,
1057
- pattern: normalizeGlobPattern(sourcePath)
1058
- };
1059
- }
1060
- function parseSourceFileParam(params) {
1061
- const value = params.trim();
1062
- if (!value || value === "none" || value.startsWith("inline(")) return;
1063
- const negated = value.startsWith("not ");
1064
- const sourceValue = negated ? value.slice(4).trim() : value;
1065
- if (sourceValue.startsWith("inline(")) return;
1066
- const match = /^(['"])(.+)\1$/.exec(sourceValue);
1067
- return match?.[2] ? {
1068
- negated,
1069
- sourcePath: match[2]
1070
- } : void 0;
1071
- }
1072
- async function resolveCssSourceEntries(root, base, defaultPattern = createSourceScanPattern()) {
1073
- const entries = [];
1074
- const tasks = [];
1075
- root.walkAtRules("source", (rule) => {
1076
- const parsed = parseSourceFileParam(rule.params);
1077
- if (!parsed) return;
1078
- tasks.push(resolveTailwindSourceEntry(parsed.sourcePath, base, parsed.negated, defaultPattern));
1079
- });
1080
- entries.push(...await Promise.all(tasks));
1081
- return entries;
1082
- }
1083
- async function expandTailwindSourceEntries(entries, options = {}) {
1084
- if (entries.length === 0) return [];
1085
- const files = /* @__PURE__ */ new Set();
1086
- const entriesByBase = /* @__PURE__ */ new Map();
1087
- for (const entry of entries) {
1088
- const base = path.resolve(entry.base);
1089
- const group = entriesByBase.get(base) ?? [];
1090
- group.push({
1091
- ...entry,
1092
- base
1093
- });
1094
- entriesByBase.set(base, group);
1095
- }
1096
- await Promise.all([...entriesByBase.entries()].map(async ([base, group]) => {
1097
- const ignoredSources = options.ignore?.map((pattern) => ({
1098
- base,
1099
- pattern: normalizeGlobPattern(pattern),
1100
- negated: true
1101
- }));
1102
- const matched = await resolveProjectSourceFiles({
1103
- cwd: base,
1104
- sources: group,
1105
- ...ignoredSources === void 0 ? {} : { ignoredSources }
1106
- });
1107
- for (const file of matched) files.add(path.resolve(file));
1108
- }));
1109
- return [...files].filter((file) => !isFileExcludedByTailwindSourceEntries(file, entries));
1110
- }
1111
- //#endregion
1112
- //#region src/tailwindcss/v4-engine/generator/scan-sources.ts
1113
- const TAILWIND_V4_DEFAULT_IGNORED_SOURCE_PATTERNS = [
1114
- "**/.git/**",
1115
- "**/.hg/**",
1116
- "**/.jj/**",
1117
- "**/.next/**",
1118
- "**/.parcel-cache/**",
1119
- "**/.pnpm-store/**",
1120
- "**/.svelte-kit/**",
1121
- "**/.svn/**",
1122
- "**/.turbo/**",
1123
- "**/.venv/**",
1124
- "**/.vercel/**",
1125
- "**/.yarn/**",
1126
- "**/__pycache__/**",
1127
- "**/node_modules/**",
1128
- "**/venv/**",
1129
- "**/*.less",
1130
- "**/*.lock",
1131
- "**/*.sass",
1132
- "**/*.scss",
1133
- "**/*.styl",
1134
- "**/*.log",
1135
- "**/tailwind.config.js",
1136
- "**/tailwind.config.cjs",
1137
- "**/tailwind.config.mjs",
1138
- "**/tailwind.config.ts",
1139
- "**/tailwind.config.cts",
1140
- "**/tailwind.config.mts",
1141
- "**/tailwind.config.*.js",
1142
- "**/tailwind.config.*.cjs",
1143
- "**/tailwind.config.*.mjs",
1144
- "**/tailwind.config.*.ts",
1145
- "**/tailwind.config.*.cts",
1146
- "**/tailwind.config.*.mts",
1147
- "**/package-lock.json",
1148
- "**/pnpm-lock.yaml",
1149
- "**/bun.lockb",
1150
- "**/.gitignore",
1151
- "**/.env",
1152
- "**/.env.*"
1153
- ];
1154
- function resolveSourceBase(base, sourcePath) {
1155
- return path.isAbsolute(sourcePath) ? sourcePath : path.resolve(base, sourcePath);
1156
- }
1157
- function createDefaultIgnoredScanSources(base) {
1158
- return TAILWIND_V4_DEFAULT_IGNORED_SOURCE_PATTERNS.map((pattern) => ({
1159
- base,
1160
- pattern,
1161
- negated: true
1162
- }));
1163
- }
1164
- function normalizeCssDefinedScanSources(base, entries) {
1165
- return entries.length > 0 && entries.every((entry) => entry.negated) ? [{
1166
- base,
1167
- pattern: "**/*",
1168
- negated: false
1169
- }, ...entries] : entries;
1170
- }
1171
- function resolveDefaultSourceBase(source) {
1172
- return source.projectRoot ?? source.cwd ?? source.base;
1173
- }
1174
- async function resolveCssDefinedScanSources(source) {
1175
- let importSourceBase;
1176
- let hasSourceNone = false;
1177
- let hasTailwindImport = false;
1178
- const sourcePatterns = [];
1179
- const definitions = [{
1180
- css: source.css,
1181
- base: source.base,
1182
- ...source.dependencies[0] === void 0 ? {} : { from: source.dependencies[0] }
1183
- }];
1184
- for (const dependency of source.dependencies.slice(1)) {
1185
- if (!existsSync(dependency)) continue;
1186
- try {
1187
- definitions.push({
1188
- css: readFileSync(dependency, "utf8"),
1189
- base: path.dirname(dependency),
1190
- from: dependency
1191
- });
1192
- } catch {}
1193
- }
1194
- for (const definition of definitions) {
1195
- let root;
1196
- try {
1197
- root = postcss.parse(definition.css, { from: definition.from });
1198
- } catch {
1199
- continue;
1200
- }
1201
- root.walkAtRules((rule) => {
1202
- if (rule.name !== "import" || !isTailwindCssImport(rule.params)) return;
1203
- hasTailwindImport = true;
1204
- const sourceParam = parseImportSourceParam(rule.params);
1205
- if (sourceParam?.none) hasSourceNone = true;
1206
- if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase(definition.base, sourceParam.sourcePath);
1207
- });
1208
- sourcePatterns.push(...await resolveCssSourceEntries(root, definition.base, "**/*"));
1209
- }
1210
- let entries;
1211
- if (importSourceBase) entries = [await resolveTailwindSourceEntry(".", importSourceBase, false, "**/*"), ...sourcePatterns];
1212
- else if (sourcePatterns.length > 0) entries = normalizeCssDefinedScanSources(source.base, sourcePatterns);
1213
- else if (hasSourceNone) return false;
1214
- else if (hasTailwindImport) entries = [await resolveTailwindSourceEntry(".", resolveDefaultSourceBase(source), false, "**/*")];
1215
- else return;
1216
- const scanBases = /* @__PURE__ */ new Set([importSourceBase ?? (sourcePatterns.length > 0 ? source.base : resolveDefaultSourceBase(source)), ...entries.filter((entry) => !entry.negated).map((entry) => entry.base)]);
1217
- return [...entries, ...[...scanBases].flatMap((base) => createDefaultIgnoredScanSources(base))];
1218
- }
1219
- async function resolveScanSources(source, scanSources) {
1220
- if (scanSources !== true) return scanSources;
1221
- return await resolveCssDefinedScanSources(source) ?? false;
1222
- }
1223
- function resolveCompiledSourceRoot(source) {
1224
- let root = null;
1225
- try {
1226
- postcss.parse(source.css).walkAtRules("import", (rule) => {
1227
- if (!isTailwindCssImport(rule.params)) return;
1228
- const sourceParam = parseImportSourceParam(rule.params);
1229
- if (sourceParam?.none) {
1230
- root = "none";
1231
- return false;
1232
- }
1233
- if (sourceParam?.sourcePath) {
1234
- root = {
1235
- base: source.base,
1236
- pattern: sourceParam.sourcePath
1237
- };
1238
- return false;
1239
- }
1240
- });
1241
- } catch {}
1242
- return root;
1243
- }
1244
- //#endregion
1245
- //#region src/tailwindcss/v4-engine/generator/style-context.ts
1246
- function resolveGenerationStyleContext(sourceCss, generatedCss, options) {
1247
- const calc = options?.cssOptions?.cssCalc ?? options?.cssCalc;
1248
- const include = Array.isArray(calc) ? calc : calc && typeof calc === "object" ? calc.includeCustomProperties : void 0;
1249
- if (calc !== true && !include?.length) return options;
1250
- const customPropertyValues = collectCustomPropertyValues(sourceCss);
1251
- mergeCustomPropertyValues(customPropertyValues, generatedCss);
1252
- for (const [name, value] of options?.customPropertyValues ?? []) customPropertyValues.set(name, value);
1253
- return {
1254
- ...options,
1255
- customPropertyValues
1256
- };
1257
- }
1258
- //#endregion
1259
- //#region src/tailwindcss/v4-engine/generator/engine.ts
1260
- function isCssSyntaxError(error) {
1261
- return error instanceof Error && error.name === "CssSyntaxError";
1262
- }
1263
- function createTailwindV4Engine$1(source) {
1264
- const generationSessions = new TailwindV4NativeSessionPool();
1265
- const incrementalCacheKeys = /* @__PURE__ */ new Set();
1266
- const validationEngine = createTailwindV4Engine(source);
1267
- async function generateOnce(generateSource, options = {}) {
1268
- const { scanSources = true, styleOptions, target = "weapp", ...patchOptions } = options;
1269
- const resolvedStyleOptions = resolveStyleOptions(generateSource, styleOptions);
1270
- const compatibleSource = createCompatibleSource(resolveCssMacroTailwindV4Source(generateSource), target);
1271
- const resolvedScanSources = await resolveScanSources(generateSource, scanSources);
1272
- const filesystemCandidates = Array.isArray(resolvedScanSources) ? new Set(await extractRawCandidates(resolvedScanSources, { ...patchOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: patchOptions.bareArbitraryValues } })) : void 0;
1273
- const normalizedCandidates = normalizeTargetRpxLengthCandidates(resolveTargetCandidates(/* @__PURE__ */ new Set([...collectCandidates(patchOptions.candidates), ...filesystemCandidates ?? []]), target), target, resolvedStyleOptions);
1274
- const sourceId = compatibleSource.dependencies[0] ?? compatibleSource.base;
1275
- const generationRequest = {
1276
- ...patchOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: patchOptions.bareArbitraryValues },
1277
- ...patchOptions.sources === void 0 ? {} : { sourceEntries: createEngineSourceEntries(patchOptions.sources, sourceId) },
1278
- candidates: normalizedCandidates.candidates
1279
- };
1280
- let generatedCss;
1281
- let classSet;
1282
- let rawCandidates;
1283
- let dependencies;
1284
- try {
1285
- const artifact = await generationSessions.generate(target, createTailwindV4SourceCacheKey(compatibleSource), compatibleSource, generationRequest);
1286
- generatedCss = serializeTailwindGenerationArtifact(artifact);
1287
- classSet = artifact.classSet;
1288
- rawCandidates = artifact.rawCandidates;
1289
- dependencies = artifact.dependencies;
1290
- } catch (error) {
1291
- if (!isCssSyntaxError(error)) throw error;
1292
- const legacyResult = await createTailwindV4Engine(compatibleSource).generate({
1293
- ...patchOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: patchOptions.bareArbitraryValues },
1294
- ...patchOptions.sources === void 0 ? {} : { sources: patchOptions.sources },
1295
- candidates: normalizedCandidates.candidates,
1296
- scanSources: false
1297
- });
1298
- generatedCss = legacyResult.css;
1299
- classSet = legacyResult.classSet;
1300
- rawCandidates = legacyResult.rawCandidates;
1301
- dependencies = legacyResult.dependencies;
1302
- }
1303
- const sources = Array.isArray(resolvedScanSources) ? resolvedScanSources : [];
1304
- const rawCss = restoreRpxLengthCssSelectors(generatedCss, normalizedCandidates.restoreCandidates);
1305
- const css = await transformTailwindV4CssByTarget(rawCss, target, resolveGenerationStyleContext(compatibleSource.css, rawCss, resolvedStyleOptions));
1306
- return {
1307
- classSet: restoreRpxLengthCandidates(classSet, normalizedCandidates.restoreCandidates),
1308
- rawCandidates: restoreRpxLengthCandidates(rawCandidates, normalizedCandidates.restoreCandidates),
1309
- dependencies,
1310
- root: resolveCompiledSourceRoot(compatibleSource),
1311
- sources,
1312
- css,
1313
- rawCss,
1314
- target
1315
- };
1316
- }
1317
- async function generateWithIncrementalCache(options = {}) {
1318
- const target = options.target ?? "weapp";
1319
- const cssMacroSource = resolveCssMacroTailwindV4Source(source);
1320
- const compatibleSource = createCompatibleSource(cssMacroSource, target);
1321
- const requestedCandidates = resolveTargetCandidates(options.candidates, target);
1322
- const styleOptions = resolveStyleOptions(source, options.styleOptions);
1323
- if ((options.sources?.length ?? 0) > 0 || options.bareArbitraryValues !== void 0 || Array.isArray(options.scanSources)) return generateOnce(cssMacroSource, options);
1324
- const cacheKey = createIncrementalGenerateCacheKey(compatibleSource, target, styleOptions);
1325
- incrementalCacheKeys.add(cacheKey);
1326
- if (options.scanSources === true) return runIncrementalGenerateTask(cacheKey, requestedCandidates, options.scanSources, async () => {
1327
- const generated = await generateOnce(cssMacroSource, options);
1328
- if (!seedIncrementalGenerateCache({
1329
- compatibleSource,
1330
- generated,
1331
- requestedCandidates,
1332
- styleOptions,
1333
- target
1334
- })) incrementalGenerateCache.delete(cacheKey);
1335
- return generated;
1336
- });
1337
- const cached = incrementalGenerateCache.get(cacheKey);
1338
- if (cached) {
1339
- if (hasRemovedCandidates(cached.seenCandidates, requestedCandidates)) return runIncrementalGenerateTask(cacheKey, requestedCandidates, options.scanSources, async () => {
1340
- const generated = await generateOnce(cssMacroSource, options);
1341
- if (!seedIncrementalGenerateCache({
1342
- compatibleSource,
1343
- generated,
1344
- requestedCandidates,
1345
- styleOptions,
1346
- target
1347
- })) incrementalGenerateCache.delete(cacheKey);
1348
- return generated;
1349
- });
1350
- const missingCandidates = [...requestedCandidates].filter((candidate) => !cached.seenCandidates.has(candidate));
1351
- if (missingCandidates.length === 0) return {
1352
- css: cached.css,
1353
- rawCss: cached.rawCss,
1354
- incrementalCss: "",
1355
- incrementalRawCss: "",
1356
- classSet: new Set(cached.classSet),
1357
- rawCandidates: new Set(cached.seenCandidates),
1358
- dependencies: cached.dependencies,
1359
- sources: cached.sources,
1360
- root: cached.root,
1361
- target: cached.target
1362
- };
1363
- if (shouldRebuildIncrementalEntry(cached, requestedCandidates, missingCandidates)) return runIncrementalGenerateTask(cacheKey, requestedCandidates, options.scanSources, async () => {
1364
- const generated = await generateOnce(cssMacroSource, options);
1365
- if (!seedIncrementalGenerateCache({
1366
- compatibleSource,
1367
- generated,
1368
- requestedCandidates,
1369
- styleOptions,
1370
- target
1371
- })) incrementalGenerateCache.delete(cacheKey);
1372
- return generated;
1373
- });
1374
- return runIncrementalGenerateTask(cacheKey, requestedCandidates, options.scanSources, async () => {
1375
- const designSystem = await cached.designSystemPromise;
1376
- const normalizedMissing = normalizeTargetRpxLengthCandidates(missingCandidates, target, styleOptions);
1377
- const normalizedMissingCandidates = [...normalizedMissing.candidates];
1378
- const cssByCandidate = designSystem.candidatesToCss(normalizedMissingCandidates);
1379
- const rawCssParts = [];
1380
- const classSet = /* @__PURE__ */ new Set();
1381
- for (let index = 0; index < normalizedMissingCandidates.length; index += 1) {
1382
- const candidate = normalizedMissingCandidates[index];
1383
- const css = cssByCandidate[index];
1384
- if (candidate && typeof css === "string" && css.trim().length > 0) {
1385
- rawCssParts.push(restoreRpxLengthCssSelectors(css, normalizedMissing.restoreCandidates));
1386
- classSet.add(normalizedMissing.restoreCandidates.get(candidate) ?? candidate);
1387
- }
1388
- }
1389
- const rawCss = rawCssParts.join("\n");
1390
- const incrementalCss = rawCss.length > 0 ? await transformTailwindV4CssByTarget(rawCss, target, {
1391
- ...createIncrementalStyleOptions(styleOptions),
1392
- customPropertyValues: cached.customPropertyValues
1393
- }) : "";
1394
- for (const candidate of missingCandidates) cached.seenCandidates.add(candidate);
1395
- for (const className of classSet) cached.classSet.add(className);
1396
- cached.css = [cached.css, incrementalCss].filter(Boolean).join("\n");
1397
- cached.rawCss = [cached.rawCss, rawCss].filter(Boolean).join("\n");
1398
- mergeCustomPropertyValues(cached.customPropertyValues, incrementalCss);
1399
- return {
1400
- css: cached.css,
1401
- rawCss: cached.rawCss,
1402
- incrementalCss,
1403
- incrementalRawCss: rawCss,
1404
- classSet: new Set(cached.classSet),
1405
- rawCandidates: new Set(cached.seenCandidates),
1406
- dependencies: cached.dependencies,
1407
- sources: cached.sources,
1408
- root: cached.root,
1409
- target: cached.target
1410
- };
1411
- });
1412
- }
1413
- return runIncrementalGenerateTask(cacheKey, requestedCandidates, options.scanSources, async () => {
1414
- const generated = await generateOnce(cssMacroSource, options);
1415
- seedIncrementalGenerateCache({
1416
- compatibleSource,
1417
- generated,
1418
- requestedCandidates,
1419
- styleOptions,
1420
- target
1421
- });
1422
- return generated;
1423
- });
1424
- }
1425
- async function generate(options = {}) {
1426
- return options.incrementalCache ? generateWithIncrementalCache(options) : generateOnce(source, options);
1427
- }
1428
- return {
1429
- source,
1430
- loadDesignSystem: validationEngine.loadDesignSystem,
1431
- validateCandidates: validationEngine.validateCandidates,
1432
- generate,
1433
- dispose() {
1434
- generationSessions.dispose();
1435
- for (const cacheKey of incrementalCacheKeys) incrementalGenerateCache.delete(cacheKey);
1436
- incrementalCacheKeys.clear();
1437
- }
1438
- };
1439
- }
1440
- //#endregion
1441
- //#region src/bundlers/shared/generator-css/config-directive.ts
1442
- function quoteCssString(value) {
1443
- return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
1444
- }
1445
- function toCssPath(value) {
1446
- return value.replaceAll("\\", "/");
1447
- }
1448
- function prependConfigDirective(css, config) {
1449
- if (!config || /@config\s+/.test(css)) return css;
1450
- return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
1451
- }
1452
- function normalizeConfigDirective(css, config) {
1453
- if (!config || !/@config\s+/.test(css)) return css;
1454
- return css.replace(/@config\s+(["'])(.+?)\1\s*;?/, `@config "${quoteCssString(toCssPath(config))}";`);
1455
- }
1456
- //#endregion
1457
- //#region src/bundlers/shared/generator-css/markers.ts
1458
- const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
1459
- const TAILWIND_ESCAPED_UTILITY_MARKER_RE = /\.[^,{]{0,512}(?:\\:|\\\[|\\#)/;
1460
- const TAILWIND_ROOT_THEME_MARKER_RE = /(?::root\s*,\s*:host|:host\s*,\s*page\s*,\s*\.tw-root\s*,\s*wx-root-portal-content)[^{]{0,256}\{[^}]{0,4096}(?:--spacing\b|--(?:color|text|font|default|radius)-)/;
1461
- const GENERATOR_PLACEHOLDER_MARKER_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\//i;
1462
- const GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/\s*/gi;
1463
- const TAILWIND_BANNER_PREFIX_RE = /^\/\*!\s*tailwindcss v[^*]*\*\/\s*/i;
1464
- const TAILWIND_BANNER_RE = /\/\*!\s*tailwindcss v[^*]*\*\//i;
1465
- const TAILWIND_BANNER_GLOBAL_RE = /\/\*!\s*tailwindcss v[^*]*\*\/\s*/gi;
1466
- const VITE_MARKER_RE = /\/\*\$vite\$:[^*]*\*\//g;
1467
- function createCssAppend(base, extra) {
1468
- if (!base) return extra;
1469
- if (!extra) return base;
1470
- return `${base}\n${extra}`;
1471
- }
1472
- function splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss) {
1473
- const trimmedRaw = rawSource.trim();
1474
- const trimmedTailwind = rawTailwindCss.trim();
1475
- if (trimmedRaw === trimmedTailwind) return {
1476
- before: "",
1477
- after: ""
1478
- };
1479
- if (trimmedTailwind.startsWith(trimmedRaw)) return {
1480
- before: "",
1481
- after: ""
1482
- };
1483
- const start = rawSource.indexOf(rawTailwindCss);
1484
- if (start === -1) return;
1485
- return {
1486
- before: rawSource.slice(0, start),
1487
- after: rawSource.slice(start + rawTailwindCss.length)
1488
- };
1489
- }
1490
- function splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss) {
1491
- const match = GENERATOR_PLACEHOLDER_MARKER_RE.exec(rawSource);
1492
- if (!match || match.index === void 0) return;
1493
- let afterStart = match.index + match[0].length;
1494
- while (/\s/.test(rawSource[afterStart] ?? "")) afterStart++;
1495
- if (rawTailwindCss && rawSource.slice(afterStart).startsWith(rawTailwindCss)) {
1496
- afterStart += rawTailwindCss.length;
1497
- while (/\s/.test(rawSource[afterStart] ?? "")) afterStart++;
1498
- }
1499
- return {
1500
- before: rawSource.slice(0, match.index),
1501
- after: rawSource.slice(afterStart)
1502
- };
1503
- }
1504
- function splitTailwindGeneratedCssByBanner(rawSource, start) {
1505
- const match = start === void 0 ? TAILWIND_BANNER_RE.exec(rawSource) : { index: start };
1506
- if (!match || match.index === void 0) return;
1507
- return {
1508
- before: rawSource.slice(0, match.index),
1509
- after: [...rawSource.slice(match.index).matchAll(VITE_MARKER_RE)].map((item) => item[0]).join("\n")
1510
- };
1511
- }
1512
- function stripTailwindBanner(css) {
1513
- return css.replace(TAILWIND_BANNER_PREFIX_RE, "");
1514
- }
1515
- function stripTailwindBanners(css) {
1516
- return css.replace(TAILWIND_BANNER_GLOBAL_RE, "");
1517
- }
1518
- function stripGeneratorPlaceholderMarkers(css) {
1519
- return css.replace(GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE, "");
1520
- }
1521
- function hasTailwindGeneratedCss(rawSource) {
1522
- return TAILWIND_V4_BANNER_RE.test(rawSource);
1523
- }
1524
- function hasTailwindGeneratedCssMarkers(rawSource) {
1525
- if (rawSource.includes("--tw-") || rawSource.includes("tailwindcss v") || rawSource.includes(":not(#\\#)") || GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource)) return true;
1526
- if (!rawSource.includes("\\:") && !rawSource.includes("\\[") && !rawSource.includes("\\#") && !rawSource.includes("--color-") && !rawSource.includes("--spacing") && !rawSource.includes("--text-") && !rawSource.includes("--font-") && !rawSource.includes("--font-weight-") && !rawSource.includes("--default-") && !rawSource.includes("--radius-")) return false;
1527
- return TAILWIND_ESCAPED_UTILITY_MARKER_RE.test(rawSource) || TAILWIND_ROOT_THEME_MARKER_RE.test(rawSource);
1528
- }
1529
- //#endregion
1530
- //#region src/bundlers/shared/generator-css/directives/fallback.ts
1531
- const TAILWIND_EXTRACTABLE_DIRECTIVE_RE = /^\s*@(?:import|use|forward|tailwind|config|source|reference|plugin)\b[\s\S]*?(?:;|$)/;
1532
- const TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE = /^\s*@layer\s[^;{]+;\s*$/;
1533
- const TAILWIND_EXTRACTABLE_BLOCK_START_RE = /^\s*@(?:layer|theme|utility|variant|custom-variant|plugin)\b[\s\S]*\{/;
1534
- function parseImportRequest$1(params) {
1535
- return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
1536
- }
1537
- function parseConfigRequest$1(params) {
1538
- return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
1539
- }
1540
- function isPackageJsonImportRequest$1(request) {
1541
- return typeof request === "string" && request.startsWith("#");
1542
- }
1543
- function isWeappTailwindcssImportRequest(request) {
1544
- return request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
1545
- }
1546
- function isTailwindImportRequest$1(request) {
1547
- return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/");
1548
- }
1549
- function normalizeTailwindImportRequest$1(request, options = {}) {
1550
- if (options.importFallback && isWeappTailwindcssImportRequest(request)) return request.replace(/^weapp-tailwindcss/, "tailwindcss");
1551
- return request;
1552
- }
1553
- function replaceImportRequest$1(params, request, replacement) {
1554
- const index = params.indexOf(request);
1555
- if (index === -1) return params;
1556
- return `${params.slice(0, index)}${replacement}${params.slice(index + request.length)}`;
1557
- }
1558
- function normalizeTailwindDirectiveLine(line, options = {}) {
1559
- const trimmed = line.trimStart();
1560
- if (/^@(?:use|forward)\b/.test(trimmed)) {
1561
- const request = parseImportRequest$1(trimmed.replace(/^@(?:use|forward)\b/, ""));
1562
- if (isTailwindImportRequest$1(request) || options.importFallback && isWeappTailwindcssImportRequest(request)) {
1563
- const normalizedRequest = normalizeTailwindImportRequest$1(request, options);
1564
- return replaceImportRequest$1(line.replace(/^(\s*)@(?:use|forward)\b/, "$1@import"), request, normalizedRequest);
1565
- }
1566
- return line;
1567
- }
1568
- if (!options.importFallback || !trimmed.startsWith("@import")) return line;
1569
- const request = parseImportRequest$1(trimmed.replace(/^@import\b/, ""));
1570
- if (!request || !isWeappTailwindcssImportRequest(request)) return line;
1571
- return replaceImportRequest$1(line, request, request.replace(/^weapp-tailwindcss/, "tailwindcss"));
1572
- }
1573
- function extractTailwindDirectiveLines(rawSource, options = {}) {
1574
- const directives = [];
1575
- const seenImports = /* @__PURE__ */ new Set();
1576
- for (const line of stripGeneratorPlaceholderMarkers(rawSource).split(/\r?\n/)) {
1577
- const trimmed = line.trim();
1578
- if (!trimmed || trimmed.startsWith("//")) continue;
1579
- const directive = TAILWIND_EXTRACTABLE_DIRECTIVE_RE.exec(line)?.[0] ?? TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE.exec(line)?.[0];
1580
- if (!directive) continue;
1581
- if (TAILWIND_EXTRACTABLE_BLOCK_START_RE.test(directive)) continue;
1582
- const normalized = normalizeTailwindDirectiveLine(directive.trimEnd(), options);
1583
- const normalizedTrimmed = normalized.trim();
1584
- if (options.removeConfig && normalizedTrimmed.startsWith("@config")) continue;
1585
- const request = /^@(?:import|use|forward)\b/.test(normalizedTrimmed) ? parseImportRequest$1(normalizedTrimmed.replace(/^@(?:import|use|forward)\b/, "")) : void 0;
1586
- if (request && !isTailwindImportRequest$1(request) && !isPackageJsonImportRequest$1(request)) continue;
1587
- if (/^@(?:import|use|forward)\b/.test(normalizedTrimmed) && !request) continue;
1588
- if (request && isTailwindImportRequest$1(request)) {
1589
- const key = normalizedTrimmed;
1590
- if (seenImports.has(key)) continue;
1591
- seenImports.add(key);
1592
- }
1593
- directives.push(normalized);
1594
- }
1595
- return directives;
1596
- }
1597
- function stripPreprocessorLineComment(line) {
1598
- let quote;
1599
- let escaped = false;
1600
- for (let index = 0; index < line.length; index++) {
1601
- const char = line[index];
1602
- if (escaped) {
1603
- escaped = false;
1604
- continue;
1605
- }
1606
- if (char === "\\") {
1607
- escaped = true;
1608
- continue;
1609
- }
1610
- if (quote) {
1611
- if (char === quote) quote = void 0;
1612
- continue;
1613
- }
1614
- if (char === "\"" || char === "'") {
1615
- quote = char;
1616
- continue;
1617
- }
1618
- if (char === "/" && line[index + 1] === "/" && (index === 0 || /\s/.test(line[index - 1]))) return line.slice(0, index).trimEnd();
1619
- }
1620
- return line;
1621
- }
1622
- function countBlockBraceDelta(line) {
1623
- let quote;
1624
- let escaped = false;
1625
- let delta = 0;
1626
- for (let index = 0; index < line.length; index++) {
1627
- const char = line[index];
1628
- if (escaped) {
1629
- escaped = false;
1630
- continue;
1631
- }
1632
- if (char === "\\") {
1633
- escaped = true;
1634
- continue;
1635
- }
1636
- if (quote) {
1637
- if (char === quote) quote = void 0;
1638
- continue;
1639
- }
1640
- if (char === "\"" || char === "'") {
1641
- quote = char;
1642
- continue;
1643
- }
1644
- if (char === "{") delta++;
1645
- else if (char === "}") delta--;
1646
- }
1647
- return delta;
1648
- }
1649
- function extractTailwindFallbackBlocks(rawSource) {
1650
- const blocks = [];
1651
- let current;
1652
- let depth = 0;
1653
- for (const rawLine of stripGeneratorPlaceholderMarkers(rawSource).split(/\r?\n/)) {
1654
- const line = stripPreprocessorLineComment(rawLine);
1655
- if (!line.trim()) continue;
1656
- if (!current) {
1657
- if (!TAILWIND_EXTRACTABLE_BLOCK_START_RE.test(line)) continue;
1658
- current = [line];
1659
- depth = countBlockBraceDelta(line);
1660
- if (depth <= 0) {
1661
- blocks.push(current.join("\n"));
1662
- current = void 0;
1663
- depth = 0;
1664
- }
1665
- continue;
1666
- }
1667
- current.push(line);
1668
- depth += countBlockBraceDelta(line);
1669
- if (depth <= 0) {
1670
- blocks.push(current.join("\n"));
1671
- current = void 0;
1672
- depth = 0;
1673
- }
1674
- }
1675
- return blocks;
1676
- }
1677
- function extractTailwindSourceForPostcssFallback(rawSource, options = {}) {
1678
- const directives = [...extractTailwindDirectiveLines(rawSource, options), ...extractTailwindFallbackBlocks(rawSource)];
1679
- return directives.length > 0 ? directives.join("\n") : void 0;
1680
- }
1681
- function extractConfigRequestFromSource(rawSource) {
1682
- for (const line of rawSource.split(/\r?\n/)) {
1683
- const match = /^\s*@config\b([\s\S]*?)(?:;|$)/.exec(line);
1684
- const request = match ? parseConfigRequest$1(match[1] ?? "") : void 0;
1685
- if (request) return request;
1686
- }
1687
- }
1688
- //#endregion
1689
- //#region src/bundlers/shared/generator-css/directives.ts
1690
- const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = /* @__PURE__ */ new Set([
1691
- "config",
1692
- "custom-variant",
1693
- "layer",
1694
- "plugin",
1695
- "reference",
1696
- "source",
1697
- "tailwind",
1698
- "theme",
1699
- "utility",
1700
- "variant"
1701
- ]);
1702
- const TAILWIND_APPLY_CONTEXT_DIRECTIVE_NAMES = /* @__PURE__ */ new Set([
1703
- "config",
1704
- "custom-variant",
1705
- "plugin",
1706
- "reference",
1707
- "theme",
1708
- "utility",
1709
- "variant"
1710
- ]);
1711
- const TAILWIND_ROOT_DIRECTIVE_RE = /@(?:import\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|(?:use|forward)\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|tailwind|config|custom-variant|plugin|source|theme|utility|variant)\b/;
1712
- function parseImportRequest(params) {
1713
- return parseTailwindCssDirectiveRequest(params);
1714
- }
1715
- function hasLocalCssImport(rawSource) {
1716
- return analyzeParseableTailwindDirectives(rawSource)?.hasLocalCssImport ?? false;
1717
- }
1718
- function parseConfigRequest(params) {
1719
- return parseTailwindCssConfigRequest(params);
1720
- }
1721
- function isPackageJsonImportRequest(request) {
1722
- return isTailwindCssPackageJsonImportRequest(request);
1723
- }
1724
- function normalizeTailwindImportRequest(request, options = {}) {
1725
- return normalizeTailwindCssImportRequest(request, options);
1726
- }
1727
- function replaceImportRequest(params, request, replacement) {
1728
- const index = params.indexOf(request);
1729
- if (index === -1) return params;
1730
- return `${params.slice(0, index)}${replacement}${params.slice(index + request.length)}`;
1731
- }
1732
- function normalizeTailwindImportAtRules(root, options = {}) {
1733
- if (!options.importFallback) return false;
1734
- let changed = false;
1735
- const seenCanonicalImports = /* @__PURE__ */ new Set();
1736
- root.walkAtRules("import", (node) => {
1737
- const request = parseImportRequest(node.params);
1738
- const normalizedRequest = normalizeTailwindImportRequest(request, options);
1739
- if (!normalizedRequest || !isTailwindImportRequest(normalizedRequest)) return;
1740
- const normalizedParams = request && normalizedRequest !== request ? replaceImportRequest(node.params, request, normalizedRequest) : node.params;
1741
- const normalizedKey = normalizedParams.trim();
1742
- if (seenCanonicalImports.has(normalizedKey)) {
1743
- node.remove();
1744
- changed = true;
1745
- return;
1746
- }
1747
- seenCanonicalImports.add(normalizedKey);
1748
- if (normalizedParams !== node.params) {
1749
- node.params = normalizedParams;
1750
- changed = true;
1751
- }
1752
- });
1753
- return changed;
1754
- }
1755
- function resolveConfigPath(base, configPath) {
1756
- if (path.isAbsolute(configPath) || isPackageJsonImportRequest(configPath)) return path.isAbsolute(configPath) ? configPath : void 0;
1757
- return path.resolve(base, configPath);
1758
- }
1759
- function normalizeTailwindConfigDirectives(rawSource, base) {
1760
- return rawSource.replace(/@config\s+(["'])(.+?)\1\s*;?/g, (full, quote, request) => {
1761
- if (path.isAbsolute(request) || isPackageJsonImportRequest(request)) return full;
1762
- return `@config ${quote}${path.resolve(base, request).replace(/\\/g, "/")}${quote};`;
1763
- });
1764
- }
1765
- function hasPreprocessorOnlySyntax(rawSource) {
1766
- return /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@[\w-]+\s*:|@(?:mixin|include|function|use|forward)\b)/.test(rawSource);
1767
- }
1768
- function normalizeTailwindSourceForGenerator(rawSource, options = {}) {
1769
- return hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource : rawSource;
1770
- }
1771
- function normalizeTailwindSourceDirectives(rawSource, options = {}) {
1772
- if (!options.importFallback) return rawSource;
1773
- try {
1774
- const root = postcss.parse(rawSource);
1775
- return normalizeTailwindImportAtRules(root, options) ? root.toString() : rawSource;
1776
- } catch {
1777
- return extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource;
1778
- }
1779
- }
1780
- function isTailwindImportRequest(request) {
1781
- const normalized = normalizeTailwindImportRequest(request);
1782
- return normalized === "tailwindcss" || normalized === "tailwindcss4" || normalized?.startsWith("tailwindcss/") === true || normalized?.startsWith("tailwindcss4/") === true;
1783
- }
1784
- function isTailwindImportAtRule(node, options = {}) {
1785
- return isTailwindCssImportAtRule(node, options);
1786
- }
1787
- function isTailwindSourceDirective(node, options = {}) {
1788
- if (node.type !== "atrule") return false;
1789
- const atRule = node;
1790
- if (isTailwindImportAtRule(atRule, options)) return true;
1791
- if (atRule.name === "import" && isPackageJsonImportRequest(parseImportRequest(atRule.params))) return true;
1792
- if (atRule.name === "layer") return !atRule.nodes || atRule.nodes.length === 0;
1793
- if (options.preserveApplyContext && TAILWIND_APPLY_CONTEXT_DIRECTIVE_NAMES.has(atRule.name)) return false;
1794
- return TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES.has(atRule.name);
1795
- }
1796
- function hasGeneratedCssArtifacts(rawSource) {
1797
- return hasTailwindGeneratedCssMarkers(rawSource) && !GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
1798
- }
1799
- function isTailwindGenerationDirective(node, options = {}) {
1800
- return isTailwindCssGenerationDirective(node, options);
1801
- }
1802
- function analyzeParseableTailwindDirectives(rawSource, options = {}) {
1803
- try {
1804
- const ignoreLayer = options.ignoreLayer ?? hasGeneratedCssArtifacts(rawSource);
1805
- return analyzeTailwindCssDirectives(postcss.parse(rawSource), {
1806
- ...options,
1807
- ignoreLayer
1808
- });
1809
- } catch {
1810
- return;
1811
- }
1812
- }
1813
- function removeTailwindSourceDirectives(rawSource, options = {}) {
1814
- try {
1815
- const source = hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) : stripGeneratorPlaceholderMarkers(rawSource);
1816
- if (!source) return "";
1817
- const root = postcss.parse(source);
1818
- let removed = false;
1819
- root.walk((node) => {
1820
- if (isTailwindSourceDirective(node, options)) {
1821
- node.remove();
1822
- removed = true;
1823
- }
1824
- });
1825
- return removed ? root.toString() : source;
1826
- } catch {
1827
- return stripGeneratorPlaceholderMarkers(rawSource);
1828
- }
1829
- }
1830
- function hasTailwindSourceDirectives(rawSource, options = {}) {
1831
- if (GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource)) return true;
1832
- return analyzeParseableTailwindDirectives(rawSource, options)?.hasTailwindSourceDirectives ?? extractTailwindDirectiveLines(rawSource, options).length > 0;
1833
- }
1834
- function hasTailwindNonRootGenerationDirectives(rawSource, options = {}) {
1835
- if (GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource)) return true;
1836
- return analyzeParseableTailwindDirectives(rawSource, options)?.hasTailwindNonRootGenerationDirectives ?? /@(?:apply|config|custom-variant|plugin|source|theme|utility|variant)\b/.test(rawSource);
1837
- }
1838
- function hasTailwindRootDirectives(rawSource, options = {}) {
1839
- if (!TAILWIND_ROOT_DIRECTIVE_RE.test(rawSource) && !(options.importFallback && rawSource.includes("weapp-tailwindcss"))) return false;
1840
- return analyzeParseableTailwindDirectives(rawSource, options)?.hasTailwindRootDirectives ?? extractTailwindDirectiveLines(rawSource, options).length > 0;
1841
- }
1842
- function hasTailwindApplyDirective(rawSource) {
1843
- if (!rawSource.includes("@apply")) return false;
1844
- const analysis = analyzeParseableTailwindDirectives(rawSource);
1845
- if (analysis) return analysis.hasTailwindApplyDirective;
1846
- const fallback = extractTailwindSourceForPostcssFallback(rawSource);
1847
- return typeof fallback === "string" && /@apply\s[^;{}]+;/.test(fallback);
1848
- }
1849
- function resolveCssEntrySource(rawSource, base, options = {}) {
1850
- try {
1851
- const root = postcss.parse(rawSource);
1852
- const normalizedImports = normalizeTailwindImportAtRules(root, options);
1853
- let found = false;
1854
- let config;
1855
- let configRequest;
1856
- let removedConfig = false;
1857
- const removeConfig = options.removeConfig ?? true;
1858
- const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
1859
- root.walk((node) => {
1860
- if (isTailwindGenerationDirective(node, {
1861
- ...options,
1862
- ignoreLayer
1863
- })) found = true;
1864
- if (node.type === "atrule" && node.name === "config") {
1865
- const configPath = parseConfigRequest(node.params);
1866
- if (configPath && !config) {
1867
- configRequest = configPath;
1868
- config = resolveConfigPath(base, configPath);
1869
- }
1870
- if (removeConfig) {
1871
- node.remove();
1872
- removedConfig = true;
1873
- }
1874
- }
1875
- });
1876
- if (!found) return;
1877
- if (hasPreprocessorOnlySyntax(rawSource)) {
1878
- const css = extractTailwindSourceForPostcssFallback(rawSource, {
1879
- ...options,
1880
- removeConfig
1881
- });
1882
- if (css) return {
1883
- css,
1884
- config,
1885
- configRequest,
1886
- base
1887
- };
1888
- }
1889
- return {
1890
- css: removedConfig || normalizedImports ? root.toString() : rawSource,
1891
- config,
1892
- configRequest,
1893
- base
1894
- };
1895
- } catch {
1896
- const css = extractTailwindSourceForPostcssFallback(rawSource, options);
1897
- const configRequest = extractConfigRequestFromSource(rawSource);
1898
- const config = configRequest ? resolveConfigPath(base, configRequest) : void 0;
1899
- return css ? {
1900
- css,
1901
- config,
1902
- configRequest,
1903
- base
1904
- } : void 0;
1905
- }
1906
- }
1907
- //#endregion
1908
- //#region src/bundlers/shared/generator-css/scoped-rules.ts
1909
- const VUE_SCOPED_SELECTOR_RE = /\.data-v-[\w-]+|\[data-v-[^\]]+\]/g;
1910
- function normalizeGeneratedSelector$1(selector) {
1911
- return selector.replace(/:not\(#\\#\)/g, "").trim();
1912
- }
1913
- function normalizeVueScopedSelector(selector) {
1914
- let scoped = false;
1915
- return {
1916
- normalized: normalizeGeneratedSelector$1(selector).replace(VUE_SCOPED_SELECTOR_RE, () => {
1917
- scoped = true;
1918
- return "";
1919
- }).trim(),
1920
- scoped
1921
- };
1922
- }
1923
- function normalizeCssComparableValue(value) {
1924
- const normalizeUnquotedSegment = (segment) => segment.replace(/(^|[^\w.-])(-?)0+\.(\d+)/g, "$1$2.$3");
1925
- let result = "";
1926
- let segmentStart = 0;
1927
- let index = 0;
1928
- while (index < value.length) {
1929
- const quote = value[index];
1930
- if (quote !== "\"" && quote !== "'") {
1931
- index++;
1932
- continue;
1933
- }
1934
- result += normalizeUnquotedSegment(value.slice(segmentStart, index));
1935
- const stringStart = index;
1936
- index++;
1937
- while (index < value.length) {
1938
- if (value[index] === "\\") {
1939
- index += 2;
1940
- continue;
1941
- }
1942
- if (value[index] === quote) {
1943
- index++;
1944
- break;
1945
- }
1946
- index++;
1947
- }
1948
- result += value.slice(stringStart, index);
1949
- segmentStart = index;
1950
- }
1951
- return result + normalizeUnquotedSegment(value.slice(segmentStart));
1952
- }
1953
- function createCssNodeSignature(node) {
1954
- if (node.type === "decl") return JSON.stringify([
1955
- "decl",
1956
- node.prop,
1957
- normalizeCssComparableValue(node.value),
1958
- node.important
1959
- ]);
1960
- if (node.type === "atrule") return JSON.stringify([
1961
- "atrule",
1962
- node.name,
1963
- normalizeCssComparableValue(node.params),
1964
- node.nodes?.map(createCssNodeSignature) ?? null
1965
- ]);
1966
- if (node.type === "rule") return JSON.stringify([
1967
- "rule",
1968
- node.selector,
1969
- node.nodes?.map(createCssNodeSignature) ?? null
1970
- ]);
1971
- return JSON.stringify(["comment", node.text]);
1972
- }
1973
- function createRuleBodySignature(rule) {
1974
- return JSON.stringify(rule.nodes?.map(createCssNodeSignature) ?? []);
1975
- }
1976
- function createRuleAtRuleContextSignature(rule) {
1977
- const context = [];
1978
- let parent = rule.parent;
1979
- while (parent && parent.type !== "root") {
1980
- if (parent.type === "atrule") context.unshift(JSON.stringify([parent.name, parent.params]));
1981
- parent = parent.parent;
1982
- }
1983
- return JSON.stringify(context);
1984
- }
1985
- function createScopedRuleCoverageKey(rule, selector) {
1986
- return JSON.stringify([
1987
- createRuleAtRuleContextSignature(rule),
1988
- createRuleBodySignature(rule),
1989
- selector
1990
- ]);
1991
- }
1992
- function removeUnscopedRulesCoveredByScopedRules(root) {
1993
- const scopedCoverage = /* @__PURE__ */ new Set();
1994
- root.walkRules((rule) => {
1995
- for (const selector of rule.selectors ?? [rule.selector]) {
1996
- const normalized = normalizeVueScopedSelector(selector);
1997
- if (normalized.scoped && normalized.normalized) scopedCoverage.add(createScopedRuleCoverageKey(rule, normalized.normalized));
1998
- }
1999
- });
2000
- if (scopedCoverage.size === 0) return;
2001
- root.walkRules((rule) => {
2002
- const normalizedSelectors = (rule.selectors ?? [rule.selector]).map(normalizeVueScopedSelector);
2003
- if (normalizedSelectors.some((selector) => selector.scoped || !selector.normalized) || !normalizedSelectors.every((selector) => scopedCoverage.has(createScopedRuleCoverageKey(rule, selector.normalized)))) return;
2004
- rule.remove();
2005
- });
2006
- }
2007
- function preferScopedGeneratedCssRules(css) {
2008
- if (!css.includes("data-v-")) return css;
2009
- try {
2010
- const root = postcss.parse(css);
2011
- removeUnscopedRulesCoveredByScopedRules(root);
2012
- root.walkAtRules((rule) => {
2013
- if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
2014
- });
2015
- return root.toString();
2016
- } catch {
2017
- return css;
2018
- }
2019
- }
2020
- //#endregion
2021
- //#region src/bundlers/shared/generator-css/user-css/user-layers.ts
2022
- function splitUserCssLayerBlocks(source) {
2023
- if (!source.includes("@layer")) return {
2024
- layer: "",
2025
- rest: source
2026
- };
2027
- try {
2028
- const root = postcss.parse(source);
2029
- const layerRoot = postcss.root();
2030
- const restRoot = postcss.root();
2031
- for (const node of root.nodes) (node.type === "atrule" && node.name === "layer" && node.nodes?.length ? layerRoot : restRoot).append(node.clone());
2032
- return {
2033
- layer: layerRoot.toString(),
2034
- rest: restRoot.toString()
2035
- };
2036
- } catch {
2037
- return {
2038
- layer: source,
2039
- rest: ""
2040
- };
2041
- }
2042
- }
2043
- function hasUserCssLayerBlocks(source) {
2044
- if (!source.includes("@layer")) return false;
2045
- try {
2046
- let hasLayerBlock = false;
2047
- postcss.parse(source).walkAtRules("layer", (node) => {
2048
- if (node.nodes?.length) hasLayerBlock = true;
2049
- });
2050
- return hasLayerBlock;
2051
- } catch {
2052
- return true;
2053
- }
2054
- }
2055
- function collectUserLayerSelectors(source) {
2056
- const selectors = /* @__PURE__ */ new Set();
2057
- try {
2058
- postcss.parse(source).walkRules((rule) => {
2059
- for (const selector of rule.selectors ?? [rule.selector]) {
2060
- const normalized = selector.trim();
2061
- if (normalized) selectors.add(normalized);
2062
- }
2063
- });
2064
- } catch {}
2065
- return selectors;
2066
- }
2067
- function matchesUserLayerSelector(selector, userLayerSelector) {
2068
- if (selector === userLayerSelector) return true;
2069
- if (!selector.startsWith(userLayerSelector)) return false;
2070
- const next = selector[userLayerSelector.length];
2071
- return next === ":" || next === "[";
2072
- }
2073
- function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
2074
- const selectors = collectUserLayerSelectors(userLayerSource);
2075
- if (selectors.size === 0) return {
2076
- layer: "",
2077
- rest: css
2078
- };
2079
- try {
2080
- const root = postcss.parse(css);
2081
- const layerRoot = postcss.root();
2082
- const selectorList = [...selectors];
2083
- root.walkRules((rule) => {
2084
- if ((rule.selectors ?? [rule.selector]).some((selector) => selectorList.some((userSelector) => matchesUserLayerSelector(selector.trim(), userSelector)))) {
2085
- layerRoot.append(rule.clone());
2086
- rule.remove();
2087
- }
2088
- });
2089
- return {
2090
- layer: layerRoot.toString(),
2091
- rest: root.toString()
2092
- };
2093
- } catch {
2094
- return {
2095
- layer: "",
2096
- rest: css
2097
- };
2098
- }
2099
- }
2100
- function normalizeGeneratedSelector(selector) {
2101
- return selector.replace(/:not\(#\\#\)/g, "").trim();
2102
- }
2103
- function collectApplyOnlySourceSelectors(source) {
2104
- const selectors = /* @__PURE__ */ new Set();
2105
- try {
2106
- postcss.parse(source).walkRules((rule) => {
2107
- if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
2108
- for (const selector of rule.selectors ?? [rule.selector]) {
2109
- const normalized = normalizeGeneratedSelector(selector);
2110
- if (normalized) selectors.add(normalized);
2111
- }
2112
- });
2113
- } catch {}
2114
- return selectors;
2115
- }
2116
- function hasOnlyApplyBackedSourceRules(source) {
2117
- let hasApplyRule = false;
2118
- let hasNonApplyRule = false;
2119
- try {
2120
- postcss.parse(source).walkRules((rule) => {
2121
- if (rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) hasApplyRule = true;
2122
- else hasNonApplyRule = true;
2123
- });
2124
- } catch {
2125
- return false;
2126
- }
2127
- return hasApplyRule && !hasNonApplyRule;
2128
- }
2129
- function removeCssComments(css) {
2130
- return css.replace(/\/\*[\s\S]*?\*\//g, "");
2131
- }
2132
- function isEmptyCustomVariantBlock(rule) {
2133
- if (rule.name !== "custom-variant") return false;
2134
- if (!/^[\w-]+$/.test(rule.params.trim())) return false;
2135
- if (rule.nodes === void 0) return true;
2136
- return rule.nodes.every((node) => node.type === "comment");
2137
- }
2138
- //#endregion
2139
- //#region src/bundlers/shared/generator-css/user-css/apply-only.ts
2140
- function normalizeEmptyTailwindCustomVariants(css) {
2141
- if (!css.includes("@custom-variant")) return css;
2142
- try {
2143
- const root = postcss.parse(css);
2144
- let changed = false;
2145
- root.walkAtRules("custom-variant", (rule) => {
2146
- if (!isEmptyCustomVariantBlock(rule)) return;
2147
- rule.remove();
2148
- changed = true;
2149
- });
2150
- return changed ? root.toString() : css;
2151
- } catch {
2152
- return css;
2153
- }
2154
- }
2155
- function filterApplyOnlyGeneratedCss(css, source, options = {}) {
2156
- const selectors = collectApplyOnlySourceSelectors(source);
2157
- if (selectors.size === 0) return css;
2158
- const selectorList = [...selectors];
2159
- const preserveVariables = options.preserveVariables !== false;
2160
- try {
2161
- const root = postcss.parse(css);
2162
- root.walkRules((rule) => {
2163
- const isApplySelector = (rule.selectors ?? [rule.selector]).some((selector) => {
2164
- const normalized = normalizeGeneratedSelector(selector);
2165
- return selectorList.some((sourceSelector) => {
2166
- if (normalized === sourceSelector) return true;
2167
- if (!normalized.startsWith(sourceSelector)) return false;
2168
- const next = normalized[sourceSelector.length];
2169
- return next === ":" || next === "[" || next === ".";
2170
- });
2171
- });
2172
- const isVariableRule = rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"));
2173
- if (options.preserveRuntimeProperties && isTailwindRuntimePropertyRule(rule)) return;
2174
- if (!isApplySelector && (!preserveVariables || !isVariableRule)) rule.remove();
2175
- });
2176
- root.walkAtRules((rule) => {
2177
- if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
2178
- });
2179
- const filteredCss = root.toString();
2180
- return removeCssComments(options.preferScopedRules ? preferScopedGeneratedCssRules(filteredCss) : filteredCss).trim();
2181
- } catch {
2182
- return css;
2183
- }
2184
- }
2185
- function shouldFilterApplyOnlyGeneratedCss(_majorVersion, target, source, options) {
2186
- return (target === "weapp" || target === "web") && hasTailwindApplyDirective(source) && !hasTailwindRootDirectives(source) && !options.hasGeneratedCss && !options.hasGeneratedMarkers && collectApplyOnlySourceSelectors(source).size > 0 && hasOnlyApplyBackedSourceRules(source);
2187
- }
2188
- //#endregion
2189
- //#region src/bundlers/shared/generator-css/user-css/generated-cleanup.ts
2190
- const TAILWIND_V4_GENERATOR_AT_RULES = /* @__PURE__ */ new Set([
2191
- "config",
2192
- "custom-variant",
2193
- "plugin",
2194
- "source",
2195
- "theme",
2196
- "utility",
2197
- "variant"
2198
- ]);
2199
- function removeBalancedAtRuleBlock(source, atRuleStart) {
2200
- const blockStart = source.indexOf("{", atRuleStart);
2201
- if (blockStart === -1) {
2202
- const semicolon = source.indexOf(";", atRuleStart);
2203
- return semicolon === -1 ? source.slice(0, atRuleStart) : `${source.slice(0, atRuleStart)}${source.slice(semicolon + 1)}`;
2204
- }
2205
- let depth = 0;
2206
- for (let index = blockStart; index < source.length; index++) {
2207
- const char = source[index];
2208
- if (char === "{") {
2209
- depth++;
2210
- continue;
2211
- }
2212
- if (char !== "}") continue;
2213
- depth--;
2214
- if (depth === 0) return `${source.slice(0, atRuleStart)}${source.slice(index + 1)}`;
2215
- }
2216
- return source.slice(0, atRuleStart);
2217
- }
2218
- function removeTailwindV4GeneratorAtRulesFallback(source) {
2219
- let next = source;
2220
- let changed = false;
2221
- const sourceMediaRE = /@media\s+source\([^)]*\)\s*\{/g;
2222
- for (;;) {
2223
- sourceMediaRE.lastIndex = 0;
2224
- const match = sourceMediaRE.exec(next);
2225
- if (!match) break;
2226
- next = removeBalancedAtRuleBlock(next, match.index);
2227
- changed = true;
2228
- }
2229
- const atRuleRE = /@(?:config|custom-variant|plugin|source|theme|utility|variant)\b/g;
2230
- for (;;) {
2231
- atRuleRE.lastIndex = 0;
2232
- const match = atRuleRE.exec(next);
2233
- if (!match) break;
2234
- next = removeBalancedAtRuleBlock(next, match.index);
2235
- changed = true;
2236
- }
2237
- return changed ? next : source;
2238
- }
2239
- function isTailwindGeneratedPreflightComment(text) {
2240
- 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");
2241
- }
2242
- const TAILWIND_GENERATED_THEME_SCOPE_SELECTORS = /* @__PURE__ */ new Set([
2243
- ":host",
2244
- ":root",
2245
- "page",
2246
- ".tw-root",
2247
- "wx-root-portal-content"
2248
- ]);
2249
- function isTailwindGeneratedThemeScopeSelector(selector) {
2250
- const selectors = selector.split(",").map((item) => item.trim()).filter(Boolean);
2251
- const selectorSet = new Set(selectors);
2252
- if (selectorSet.size !== selectors.length) return false;
2253
- if (!selectors.every((item) => TAILWIND_GENERATED_THEME_SCOPE_SELECTORS.has(item))) return false;
2254
- return selectorSet.size === 2 && selectorSet.has(":root") && selectorSet.has(":host") || selectorSet.size === 4 && selectorSet.has(":host") && selectorSet.has("page") && selectorSet.has(".tw-root") && selectorSet.has("wx-root-portal-content");
2255
- }
2256
- function themeDeclarationContext(declaration) {
2257
- const context = [];
2258
- let parent = declaration.parent?.parent;
2259
- while (parent && parent.type !== "root") {
2260
- if (parent.type === "atrule" && parent.name !== "layer") context.unshift(`@${parent.name} ${parent.params}`);
2261
- parent = parent.parent;
2262
- }
2263
- return context;
2264
- }
2265
- function themeDeclarationKey(declaration) {
2266
- const value = declaration.value.trim().replace(/^(-?)0\.(\d+(?:[a-z]+|%)?)$/i, "$1.$2");
2267
- return JSON.stringify([
2268
- themeDeclarationContext(declaration),
2269
- declaration.prop,
2270
- value,
2271
- Boolean(declaration.important)
2272
- ]);
2273
- }
2274
- function collectGeneratedThemeDeclarations(source) {
2275
- const declarations = /* @__PURE__ */ new Set();
2276
- try {
2277
- postcss.parse(source).walkRules((rule) => {
2278
- if (!isTailwindGeneratedThemeScopeSelector(rule.selector.replace(/\s+/g, " ").replace(/\s*,\s*/g, ",").trim())) return;
2279
- for (const child of rule.nodes ?? []) if (child.type === "decl") declarations.add(themeDeclarationKey(child));
2280
- });
2281
- } catch {}
2282
- return declarations;
2283
- }
2284
- /** 同一轮框架恢复共享声明索引;只有遇到根变量时才解析生成产物。 */
2285
- function createGeneratedThemeDeclarationResolver(source) {
2286
- let declarations;
2287
- return () => declarations ?? (declarations = collectGeneratedThemeDeclarations(source));
2288
- }
2289
- function isTailwindGeneratedPreflightRule(selector, node) {
2290
- 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;
2291
- if (selector === "abbr[title]") return node.nodes?.some((child) => child.type === "decl" && child.prop === "text-decoration") ?? false;
2292
- if (selector === ":host") return node.nodes?.some((child) => child.type === "decl" && child.value?.includes("--theme(")) ?? false;
2293
- return false;
2294
- }
2295
- function removeTailwindV4GeneratedUserCssArtifacts(source, generatedSource) {
2296
- try {
2297
- const root = postcss.parse(source);
2298
- let changed = false;
2299
- root.walkComments((comment) => {
2300
- if (!isTailwindGeneratedPreflightComment(comment.text)) return;
2301
- comment.remove();
2302
- changed = true;
2303
- });
2304
- let generatedDeclarations;
2305
- const overriddenProperties = /* @__PURE__ */ new Set();
2306
- root.walkRules((rule) => {
2307
- const selector = rule.selector.replace(/\s+/g, " ").replace(/\s*,\s*/g, ",").trim();
2308
- if (isTailwindGeneratedThemeScopeSelector(selector) || TAILWIND_GENERATED_THEME_SCOPE_SELECTORS.has(selector) && rule.nodes.some((child) => child.type === "decl" && child.prop.startsWith("--"))) {
2309
- generatedDeclarations ?? (generatedDeclarations = typeof generatedSource === "function" ? generatedSource() : generatedSource ? collectGeneratedThemeDeclarations(generatedSource) : /* @__PURE__ */ new Set());
2310
- for (const child of [...rule.nodes]) {
2311
- if (child.type !== "decl") continue;
2312
- const propertyKey = JSON.stringify([themeDeclarationContext(child), child.prop]);
2313
- if (generatedDeclarations?.has(themeDeclarationKey(child)) && !overriddenProperties.has(propertyKey)) {
2314
- child.remove();
2315
- changed = true;
2316
- } else overriddenProperties.add(propertyKey);
2317
- }
2318
- if (rule.nodes.length === 0) {
2319
- rule.remove();
2320
- changed = true;
2321
- }
2322
- return;
2323
- }
2324
- if (isTailwindGeneratedPreflightRule(selector, rule)) {
2325
- rule.remove();
2326
- changed = true;
2327
- }
2328
- });
2329
- root.walkAtRules((rule) => {
2330
- if (rule.nodes !== void 0 && rule.nodes.length === 0) {
2331
- rule.remove();
2332
- changed = true;
2333
- }
2334
- });
2335
- return changed ? root.toString() : source;
2336
- } catch {
2337
- return source;
2338
- }
2339
- }
2340
- //#endregion
2341
- //#region src/bundlers/shared/generator-css/user-css/at-rules.ts
2342
- function removeTailwindSourceMediaBlocks(source) {
2343
- let next = source;
2344
- let changed = false;
2345
- const sourceMediaRE = /@media\s+source\([^)]*\)\s*\{/g;
2346
- for (;;) {
2347
- sourceMediaRE.lastIndex = 0;
2348
- const match = sourceMediaRE.exec(next);
2349
- if (!match) break;
2350
- const blockStart = next.indexOf("{", match.index);
2351
- if (blockStart === -1) break;
2352
- let depth = 0;
2353
- let blockEnd = -1;
2354
- for (let index = blockStart; index < next.length; index++) {
2355
- const char = next[index];
2356
- if (char === "{") {
2357
- depth++;
2358
- continue;
2359
- }
2360
- if (char !== "}") continue;
2361
- depth--;
2362
- if (depth === 0) {
2363
- blockEnd = index;
2364
- break;
2365
- }
2366
- }
2367
- if (blockEnd === -1) break;
2368
- next = `${next.slice(0, match.index)}${next.slice(blockEnd + 1)}`;
2369
- changed = true;
2370
- }
2371
- for (;;) {
2372
- const atRuleStart = findTailwindSourceWrapperBlockStart(next);
2373
- if (atRuleStart === -1) break;
2374
- next = removeBalancedAtRuleBlock(next, atRuleStart);
2375
- changed = true;
2376
- }
2377
- return changed ? next : source;
2378
- }
2379
- function terminateTailwindSourceAtRulesBeforeNextDirective(source) {
2380
- if (!source.includes("@source")) return source;
2381
- let next = "";
2382
- let searchIndex = 0;
2383
- for (;;) {
2384
- const atRuleStart = source.indexOf("@source", searchIndex);
2385
- if (atRuleStart === -1) {
2386
- next += source.slice(searchIndex);
2387
- break;
2388
- }
2389
- const nextChar = source[atRuleStart + 7];
2390
- if (nextChar && /[\w-]/.test(nextChar)) {
2391
- next += source.slice(searchIndex, atRuleStart + 7);
2392
- searchIndex = atRuleStart + 7;
2393
- continue;
2394
- }
2395
- next += source.slice(searchIndex, atRuleStart);
2396
- let quote;
2397
- let parenDepth = 0;
2398
- let terminated = false;
2399
- let index = atRuleStart + 7;
2400
- for (; index < source.length; index++) {
2401
- const char = source[index];
2402
- if (quote) {
2403
- if (char === "\\") {
2404
- index++;
2405
- continue;
2406
- }
2407
- if (char === quote) quote = void 0;
2408
- continue;
2409
- }
2410
- if (char === "\"" || char === "'") {
2411
- quote = char;
2412
- continue;
2413
- }
2414
- if (char === "(") {
2415
- parenDepth++;
2416
- continue;
2417
- }
2418
- if (char === ")" && parenDepth > 0) {
2419
- parenDepth--;
2420
- continue;
2421
- }
2422
- if (parenDepth > 0) continue;
2423
- if (char === ";" || char === "{") {
2424
- terminated = true;
2425
- index++;
2426
- break;
2427
- }
2428
- if (char === "@" && /^(?:config|custom-variant|plugin|source|theme|utility|variant)\b/.test(source.slice(index + 1))) break;
2429
- }
2430
- const segment = source.slice(atRuleStart, index);
2431
- const trimmedSegment = segment.trimEnd();
2432
- next += terminated || trimmedSegment.endsWith(";") || trimmedSegment.endsWith("{") ? segment : `${trimmedSegment};${segment.slice(trimmedSegment.length)}`;
2433
- searchIndex = index;
2434
- }
2435
- return next;
2436
- }
2437
- function findTailwindSourceWrapperBlockStart(source) {
2438
- let searchIndex = 0;
2439
- for (;;) {
2440
- const atRuleStart = source.indexOf("@source", searchIndex);
2441
- if (atRuleStart === -1) return -1;
2442
- const nextChar = source[atRuleStart + 7];
2443
- if (nextChar && /[\w-]/.test(nextChar)) {
2444
- searchIndex = atRuleStart + 7;
2445
- continue;
2446
- }
2447
- let quote;
2448
- let parenDepth = 0;
2449
- for (let index = atRuleStart + 7; index < source.length; index++) {
2450
- const char = source[index];
2451
- if (quote) {
2452
- if (char === "\\") {
2453
- index++;
2454
- continue;
2455
- }
2456
- if (char === quote) quote = void 0;
2457
- continue;
2458
- }
2459
- if (char === "\"" || char === "'") {
2460
- quote = char;
2461
- continue;
2462
- }
2463
- if (char === "(") {
2464
- parenDepth++;
2465
- continue;
2466
- }
2467
- if (char === ")" && parenDepth > 0) {
2468
- parenDepth--;
2469
- continue;
2470
- }
2471
- if (parenDepth > 0) continue;
2472
- if (char === ";") {
2473
- searchIndex = index + 1;
2474
- break;
2475
- }
2476
- if (char === "{") return atRuleStart;
2477
- }
2478
- if (searchIndex <= atRuleStart) return -1;
2479
- }
2480
- }
2481
- function removeTailwindApplyAtRules(source) {
2482
- if (!source.includes("@apply")) return source;
2483
- try {
2484
- const root = postcss.parse(source);
2485
- let changed = false;
2486
- root.walkAtRules("apply", (rule) => {
2487
- rule.remove();
2488
- changed = true;
2489
- });
2490
- root.walk((node) => {
2491
- if ("nodes" in node && node.nodes?.length === 0) node.remove();
2492
- });
2493
- return changed ? root.toString() : source;
2494
- } catch {
2495
- return source;
2496
- }
2497
- }
2498
- //#endregion
2499
- //#region src/bundlers/shared/generator-css/user-css/source-fragments.ts
2500
- function removeTailwindV4GeneratorAtRules(source) {
2501
- try {
2502
- const root = postcss.parse(source);
2503
- let changed = false;
2504
- root.walkAtRules((rule) => {
2505
- if (rule.name === "media" && /^source\(/.test(rule.params.trim())) {
2506
- rule.remove();
2507
- changed = true;
2508
- return;
2509
- }
2510
- if (!TAILWIND_V4_GENERATOR_AT_RULES.has(rule.name)) return;
2511
- rule.remove();
2512
- changed = true;
2513
- });
2514
- return changed ? root.toString() : source;
2515
- } catch {
2516
- return removeTailwindV4GeneratorAtRulesFallback(source);
2517
- }
2518
- }
2519
- function isCommentOnlyCss(source) {
2520
- try {
2521
- const root = postcss.parse(source);
2522
- return root.nodes.length > 0 && root.nodes.every((node) => node.type === "comment");
2523
- } catch {
2524
- return false;
2525
- }
2526
- }
2527
- function removeMiniProgramInteractiveSelectors(source, options = {
2528
- active: true,
2529
- hover: true
2530
- }) {
2531
- const removeActive = options.active === true;
2532
- const removeHover = options.hover === true;
2533
- const removeFocus = options.focus === true;
2534
- const unsupportedPseudoClasses = [
2535
- ...removeActive ? [":active"] : [],
2536
- ...removeHover ? [":hover"] : [],
2537
- ...removeFocus ? [":focus"] : []
2538
- ];
2539
- if (unsupportedPseudoClasses.length === 0 || !source.includes(":active") && !source.includes(":hover") && !source.includes(":focus")) return source;
2540
- try {
2541
- const root = postcss.parse(source);
2542
- let changed = false;
2543
- root.walkRules((rule) => {
2544
- const selectors = rule.selectors ?? [rule.selector];
2545
- const keptSelectors = selectors.filter((selector) => {
2546
- if (!unsupportedPseudoClasses.some((pseudoClass) => selector.includes(pseudoClass))) return true;
2547
- return !selectorContainsPseudoClass(selector, unsupportedPseudoClasses);
2548
- });
2549
- if (keptSelectors.length === selectors.length) return;
2550
- changed = true;
2551
- if (keptSelectors.length === 0) {
2552
- rule.remove();
2553
- return;
2554
- }
2555
- rule.selectors = keptSelectors;
2556
- });
2557
- root.walk((node) => {
2558
- if ("nodes" in node && node.nodes?.length === 0) {
2559
- node.remove();
2560
- changed = true;
2561
- }
2562
- });
2563
- return changed ? root.toString() : source;
2564
- } catch {
2565
- return source;
2566
- }
2567
- }
2568
- function removeProcessedMiniProgramUnsupportedCss(source, options) {
2569
- return removeMiniProgramInteractiveSelectors(removeUnsupportedMiniProgramAtRules(source), {
2570
- active: options.cssRemoveActivePseudoClass ?? true,
2571
- hover: options.cssRemoveHoverPseudoClass ?? true,
2572
- focus: options.cssRemoveFocusPseudoClass ?? true
2573
- });
2574
- }
2575
- function unwrapMiniProgramCascadeLayers(source) {
2576
- if (!source.includes("@layer")) return source;
2577
- try {
2578
- const root = postcss.parse(source);
2579
- removeUnsupportedCascadeLayers(root);
2580
- return root.toString();
2581
- } catch {
2582
- return source;
2583
- }
2584
- }
2585
- function hasClassSelector(selector) {
2586
- return /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(selector);
2587
- }
2588
- function collectBareSelectorUserCss(source, transformedCss) {
2589
- try {
2590
- const root = postcss.parse(source);
2591
- const representedSelectors = /* @__PURE__ */ new Set();
2592
- const rootSelectors = /* @__PURE__ */ new Set([
2593
- ":root",
2594
- ":host",
2595
- "page",
2596
- ".tw-root",
2597
- "wx-root-portal-content"
2598
- ]);
2599
- const selectorKey = (rule, selector) => {
2600
- const context = [];
2601
- let parent = rule.parent;
2602
- while (parent && parent.type !== "root") {
2603
- if (parent.type === "atrule") context.unshift(`@${parent.name} ${parent.params}`);
2604
- parent = parent.parent;
2605
- }
2606
- return JSON.stringify([...context, rootSelectors.has(selector.trim()) ? ":root" : selector.trim()]);
2607
- };
2608
- if (transformedCss !== void 0) postcss.parse(transformedCss).walkRules((rule) => {
2609
- for (const selector of rule.selectors) representedSelectors.add(selectorKey(rule, selector));
2610
- });
2611
- let changed = false;
2612
- root.walkAtRules("import", (rule) => {
2613
- rule.remove();
2614
- changed = true;
2615
- });
2616
- root.walkRules((rule) => {
2617
- const selectors = rule.selectors?.length ? rule.selectors : [rule.selector];
2618
- if (selectors.some((selector) => hasClassSelector(selector)) || selectors.every((selector) => representedSelectors.has(selectorKey(rule, selector)))) {
2619
- rule.remove();
2620
- changed = true;
2621
- }
2622
- });
2623
- root.walkAtRules((rule) => {
2624
- if (rule.nodes !== void 0 && rule.nodes.length === 0) {
2625
- rule.remove();
2626
- changed = true;
2627
- }
2628
- });
2629
- return changed ? root.toString() : source;
2630
- } catch {
2631
- return "";
2632
- }
2633
- }
2634
- function stripTailwindSourceMediaFragments(source) {
2635
- let removedSourceMediaStart = false;
2636
- return terminateTailwindSourceAtRulesBeforeNextDirective(removeTailwindSourceMediaBlocks(source)).split(/\r?\n/).filter((line) => {
2637
- if (/^\s*@media\s+source\([^)]*\)\s*\{\s*$/.test(line)) {
2638
- removedSourceMediaStart = true;
2639
- return false;
2640
- }
2641
- if (/^\s*\}\s*\/\*\s*source\([^)]*\)\s*\*\/\s*$/.test(line)) return false;
2642
- if (removedSourceMediaStart && /^\s*\}\s*$/.test(line)) {
2643
- removedSourceMediaStart = false;
2644
- return false;
2645
- }
2646
- return true;
2647
- }).join("\n");
2648
- }
2649
- function stripLeadingTailwindSourceMediaCloseFragment(source) {
2650
- return source.replace(/^\s*\}\s*(?:\n|$)/, "");
2651
- }
2652
- function stripUnmatchedTailwindSourceMediaCloseFragments(source) {
2653
- try {
2654
- postcss.parse(source);
2655
- return source;
2656
- } catch {
2657
- return stripLeadingTailwindSourceMediaCloseFragment(source).replace(/\s*\}\s*$/, "");
2658
- }
2659
- }
2660
- //#endregion
2661
- //#region src/bundlers/shared/generator-css/user-css/transform.ts
2662
- async function transformGeneratorUserCss(source, options) {
2663
- if (source.trim().length === 0) return "";
2664
- if (options.processed) {
2665
- const compiledSource = await options.compileAuthorCssFunctions?.(source) ?? source;
2666
- return stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(removeTailwindV4GeneratorAtRules(options.generatorTarget === "weapp" ? removeTailwindV4GeneratedUserCssArtifacts(unwrapMiniProgramCascadeLayers(removeProcessedMiniProgramUnsupportedCss(compiledSource, {
2667
- ...options.generatorStyleOptions,
2668
- ...options.cssUserHandlerOptions
2669
- })), options.generatedSource) : compiledSource)));
2670
- }
2671
- const cleanedSource = removeTailwindSourceDirectives(removeTailwindV4GeneratorAtRules(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source))), { importFallback: options.importFallback });
2672
- if (cleanedSource.trim().length === 0) return "";
2673
- const authorSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? removeTailwindV4GeneratedUserCssArtifacts(removeUnsupportedMiniProgramAtRules(unwrapMiniProgramCascadeLayers(stripTailwindBanners(cleanedSource))), options.generatedSource) : cleanedSource)), { importFallback: options.importFallback })));
2674
- const userSource = await options.compileAuthorCssFunctions?.(authorSource) ?? authorSource;
2675
- if (userSource.trim().length === 0) return "";
2676
- if (isCommentOnlyCss(userSource)) return userSource;
2677
- if (options.generatorTarget !== "weapp") return applyConfiguredCssCalc(userSource, {
2678
- cssCalc: options.generatorStyleOptions.cssOptions?.cssCalc ?? options.generatorStyleOptions.cssCalc ?? options.cssUserHandlerOptions.cssOptions?.cssCalc ?? options.cssUserHandlerOptions.cssCalc,
2679
- customPropertyValues: options.generatorStyleOptions.customPropertyValues ?? options.cssUserHandlerOptions.customPropertyValues,
2680
- contextCss: typeof options.generatedSource === "string" ? options.generatedSource : void 0
2681
- });
2682
- const { css } = await options.styleHandler(userSource, {
2683
- ...options.generatorStyleOptions,
2684
- ...options.cssUserHandlerOptions
2685
- });
2686
- const transformedCss = removeTailwindV4GeneratedUserCssArtifacts(removeUnsupportedMiniProgramAtRules(stripTailwindBanners(css)), options.generatedSource);
2687
- const bareSelectorUserCss = collectBareSelectorUserCss(userSource, transformedCss);
2688
- const missingBareSelectorUserCss = bareSelectorUserCss.trim().length > 0 ? filterExistingCssRules(transformedCss, bareSelectorUserCss) : "";
2689
- return missingBareSelectorUserCss.trim().length > 0 ? `${transformedCss}\n${missingBareSelectorUserCss}` : transformedCss;
2690
- }
2691
- //#endregion
2692
- //#region src/utils/options.ts
2693
- function resolveBooleanObjectOption(value, enabledValue) {
2694
- if (!value) return false;
2695
- if (value === true) return enabledValue;
2696
- return value;
2697
- }
2698
- function normalizeStringListOption(value) {
2699
- if (!value) return;
2700
- const values = typeof value === "string" ? [value] : Array.isArray(value) ? value : void 0;
2701
- if (!values) return;
2702
- const normalized = values.map((entry) => typeof entry === "string" ? entry.trim() : "").filter((entry) => entry.length > 0);
2703
- return normalized.length > 0 ? normalized : void 0;
2704
- }
2705
- //#endregion
2706
- //#region src/tailwindcss/runtime-options.ts
2707
- function resolveTailwindcssOptions(options) {
2708
- return options?.tailwindcss ?? options?.tailwind;
2709
- }
2710
- function normalizeExtendLengthUnits(value) {
2711
- if (value === void 0) return;
2712
- const resolved = resolveBooleanObjectOption(value, { enabled: true });
2713
- return resolved && typeof resolved === "object" ? {
2714
- enabled: true,
2715
- ...resolved
2716
- } : resolved;
2717
- }
2718
- function normalizeTailwindcssRuntimeOptions(options) {
2719
- return options;
2720
- }
2721
- /** 清除可选字段中的 undefined,再交给引擎候选校验与生成契约。 */
2722
- function resolveRuntimeBareArbitraryValues(options) {
2723
- const value = resolveTailwindcssOptions(options)?.v4?.bareArbitraryValues;
2724
- return value && typeof value === "object" ? value.units === void 0 ? {} : { units: value.units } : value;
2725
- }
2726
- //#endregion
2727
- //#region src/utils/object.ts
2728
- function definedEntries(value) {
2729
- return Object.entries(value).filter(([, item]) => item !== void 0);
2730
- }
2731
- function omitUndefined(value) {
2732
- return Object.fromEntries(definedEntries(value));
2733
- }
2734
- //#endregion
2735
- //#region src/context/workspace.ts
2736
- const IGNORED_WORKSPACE_DIRS = /* @__PURE__ */ new Set([
2737
- "node_modules",
2738
- ".git",
2739
- ".hg",
2740
- ".svn",
2741
- ".turbo",
2742
- ".output",
2743
- ".next",
2744
- "dist",
2745
- "build"
2746
- ]);
2747
- function findWorkspaceRoot(startDir) {
2748
- if (!startDir) return;
2749
- let current = path.resolve(startDir);
2750
- while (true) {
2751
- const workspaceFile = path.join(current, "pnpm-workspace.yaml");
2752
- if (existsSync(workspaceFile)) return current;
2753
- const parent = path.dirname(current);
2754
- if (parent === current) return;
2755
- current = parent;
2756
- }
2757
- }
2758
- function findNearestPackageRoot(startDir) {
2759
- if (!startDir) return;
2760
- let current = path.resolve(startDir);
2761
- while (true) {
2762
- const pkgPath = path.join(current, "package.json");
2763
- if (existsSync(pkgPath)) return current;
2764
- const parent = path.dirname(current);
2765
- if (parent === current) return;
2766
- current = parent;
2767
- }
2768
- }
2769
- function findWorkspacePackageDir(rootDir, packageName) {
2770
- const visited = /* @__PURE__ */ new Set();
2771
- const queue = [path.resolve(rootDir)];
2772
- while (queue.length > 0) {
2773
- const current = queue.shift();
2774
- const normalized = path.normalize(current);
2775
- if (visited.has(normalized)) continue;
2776
- visited.add(normalized);
2777
- try {
2778
- const pkgPath = path.join(normalized, "package.json");
2779
- if (existsSync(pkgPath)) {
2780
- if (JSON.parse(readFileSync(pkgPath, "utf8"))?.name === packageName) return normalized;
2781
- }
2782
- } catch {}
2783
- let entries;
2784
- try {
2785
- entries = readdirSync(normalized, { withFileTypes: true });
2786
- } catch {
2787
- continue;
2788
- }
2789
- for (const entry of entries) {
2790
- if (!entry.isDirectory() || IGNORED_WORKSPACE_DIRS.has(entry.name) || entry.isSymbolicLink?.()) continue;
2791
- queue.push(path.join(normalized, entry.name));
2792
- }
2793
- }
2794
- }
2795
- //#endregion
2796
- //#region src/tailwindcss/v4/css-entries.ts
2797
- const TAILWIND_V4_CSS_ENTRY_RE = /\.css(?:[?#].*)?$/i;
2798
- function isTailwindV4CssEntry(entry) {
2799
- return typeof entry === "string" && TAILWIND_V4_CSS_ENTRY_RE.test(entry.trim());
2800
- }
2801
- function guessBasedirFromEntries(entries) {
2802
- if (!entries) return;
2803
- for (const entry of entries) {
2804
- if (typeof entry !== "string") continue;
2805
- const trimmed = entry.trim();
2806
- if (!trimmed || !path.isAbsolute(trimmed)) continue;
2807
- if (!isTailwindV4CssEntry(trimmed)) continue;
2808
- const entryDir = path.dirname(trimmed);
2809
- const resolved = findNearestPackageRoot(entryDir) ?? entryDir;
2810
- if (resolved) return resolved;
2811
- }
2812
- }
2813
- function normalizeCssEntries(entries, anchor) {
2814
- if (!entries || entries.length === 0) return;
2815
- const normalized = /* @__PURE__ */ new Set();
2816
- for (const entry of entries) {
2817
- if (typeof entry !== "string") continue;
2818
- const trimmed = entry.trim();
2819
- if (trimmed.length === 0) continue;
2820
- if (!isTailwindV4CssEntry(trimmed)) continue;
2821
- const resolved = path.isAbsolute(trimmed) ? path.normalize(trimmed) : path.normalize(path.resolve(anchor, trimmed));
2822
- normalized.add(resolved);
2823
- }
2824
- return normalized.size > 0 ? [...normalized] : void 0;
2825
- }
2826
- function isSubPath(parent, child) {
2827
- if (!parent || !child) return false;
2828
- const relative = path.relative(parent, child);
2829
- return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
2830
- }
2831
- function resolveCssEntryBase(entryDir, options) {
2832
- const normalizedDir = path.normalize(entryDir);
2833
- const { preferredBaseDir, workspaceRoot } = options;
2834
- if (preferredBaseDir && isSubPath(preferredBaseDir, normalizedDir)) return preferredBaseDir;
2835
- if (workspaceRoot && isSubPath(workspaceRoot, normalizedDir)) return workspaceRoot;
2836
- const packageRoot = findNearestPackageRoot(normalizedDir);
2837
- if (packageRoot) return path.normalize(packageRoot);
2838
- return normalizedDir;
2839
- }
2840
- function groupCssEntriesByBase(entries, options = {}) {
2841
- const normalizedOptions = {
2842
- preferredBaseDir: options.preferredBaseDir ? path.normalize(options.preferredBaseDir) : void 0,
2843
- workspaceRoot: options.workspaceRoot ? path.normalize(options.workspaceRoot) : void 0
2844
- };
2845
- const groups = /* @__PURE__ */ new Map();
2846
- for (const entry of entries) {
2847
- const baseDir = resolveCssEntryBase(path.dirname(entry), normalizedOptions);
2848
- const bucket = groups.get(baseDir);
2849
- if (bucket) bucket.push(entry);
2850
- else groups.set(baseDir, [entry]);
2851
- }
2852
- return groups;
2853
- }
2854
- //#endregion
2855
- //#region src/tailwindcss/v4/css-sources.ts
2856
- function hasCssEntriesValue(value) {
2857
- if (typeof value === "string") return isTailwindV4CssEntry(value);
2858
- return Array.isArray(value) && value.some(isTailwindV4CssEntry);
2859
- }
2860
- function hasCssSourcesValue(value) {
2861
- return Array.isArray(value) && value.some((source) => {
2862
- const file = source?.file;
2863
- return typeof source === "object" && source !== null && typeof file === "string" && isTailwindV4CssEntry(file) && typeof source.css === "string" && source.css.trim().length > 0;
2864
- });
2865
- }
2866
- function isTailwindV4CssSourceRoot(source) {
2867
- return typeof source === "object" && source !== null && typeof source.file === "string" && isTailwindV4CssEntry(source.file);
2868
- }
2869
- function filterTailwindV4CssSourceRoots(sources) {
2870
- const filtered = sources?.filter(isTailwindV4CssSourceRoot);
2871
- return filtered && filtered.length > 0 ? filtered : void 0;
2872
- }
2873
- function hasConfiguredTailwindV4CssRoots(options) {
2874
- return hasCssEntriesValue(options.cssEntries) || hasCssEntriesValue(options.tailwindcss?.v4?.cssEntries) || hasCssEntriesValue(options.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries) || hasCssSourcesValue(options.tailwindcss?.v4?.cssSources) || hasCssSourcesValue(options.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources);
2875
- }
2876
- function normalizeCssSourceFile(file) {
2877
- if (!file) return;
2878
- return path.isAbsolute(file) ? path.normalize(file) : file;
2879
- }
2880
- function normalizeCssSourceBase(base) {
2881
- if (!base) return;
2882
- return path.resolve(base);
2883
- }
2884
- function normalizeDependencies(dependencies) {
2885
- return dependencies?.map(normalizeCssSourceFile).filter((dependency) => typeof dependency === "string" && dependency.length > 0);
2886
- }
2887
- function isSameCssSource(a, b) {
2888
- return a.css === b.css && normalizeCssSourceBase(a.base) === normalizeCssSourceBase(b.base) && normalizeCssSourceFile(a.file) === normalizeCssSourceFile(b.file) && JSON.stringify(normalizeDependencies(a.dependencies)) === JSON.stringify(normalizeDependencies(b.dependencies));
2889
- }
2890
- function upsertTailwindV4CssSource(opts, source) {
2891
- if (!isTailwindV4CssEntry(source.file)) return false;
2892
- const normalizedSource = omitUndefined({
2893
- ...source,
2894
- ...source.base === void 0 ? {} : { base: normalizeCssSourceBase(source.base) },
2895
- ...source.file === void 0 ? {} : { file: normalizeCssSourceFile(source.file) },
2896
- ...source.dependencies === void 0 ? {} : { dependencies: normalizeDependencies(source.dependencies) }
2897
- });
2898
- const tailwindcss = opts.tailwindcss ?? {};
2899
- const v4 = tailwindcss.v4 ?? {};
2900
- const cssSources = [...v4.cssSources ?? []];
2901
- const sourceFile = normalizeCssSourceFile(normalizedSource.file);
2902
- const existingIndex = cssSources.findIndex((candidate) => normalizeCssSourceFile(candidate.file) === sourceFile);
2903
- if (existingIndex >= 0) {
2904
- const existing = cssSources[existingIndex];
2905
- if (!existing) {
2906
- cssSources[existingIndex] = normalizedSource;
2907
- return true;
2908
- }
2909
- const nextSource = {
2910
- ...existing,
2911
- ...normalizedSource
2912
- };
2913
- if (isSameCssSource(existing, nextSource)) return false;
2914
- cssSources[existingIndex] = nextSource;
2915
- } else cssSources.push(normalizedSource);
2916
- opts.tailwindcss = {
2917
- ...tailwindcss,
2918
- v4: {
2919
- ...v4,
2920
- cssSources
2921
- }
2922
- };
2923
- return true;
2924
- }
2925
- function removeTailwindV4CssSource(opts, file) {
2926
- const tailwindcss = opts.tailwindcss;
2927
- const v4 = tailwindcss?.v4;
2928
- const cssSources = v4?.cssSources;
2929
- if (!cssSources || cssSources.length === 0) return false;
2930
- const sourceFile = normalizeCssSourceFile(file);
2931
- const nextCssSources = cssSources.filter((source) => normalizeCssSourceFile(source.file) !== sourceFile);
2932
- if (nextCssSources.length === cssSources.length) return false;
2933
- opts.tailwindcss = {
2934
- ...tailwindcss,
2935
- v4: {
2936
- ...v4,
2937
- cssSources: nextCssSources
2938
- }
2939
- };
2940
- return true;
2941
- }
2942
- //#endregion
2943
- //#region src/tailwindcss/v4-engine/source.ts
2944
- const require = createRequire(import.meta.url);
2945
- function isCssEntryPoint(file) {
2946
- return typeof file === "string" && path.basename(file) === "index.css" && existsSync(file);
2947
- }
2948
- function resolvePackageCssEntryPoint(specifier) {
2949
- try {
2950
- const resolved = require.resolve(specifier);
2951
- if (isCssEntryPoint(resolved)) return resolved;
2952
- } catch {}
2953
- const packageName = specifier.replace(/\/index\.css$/, "");
2954
- if (packageName !== "tailwindcss") return;
2955
- try {
2956
- const packageJson = require.resolve(`${packageName}/package.json`);
2957
- const cssEntry = path.resolve(path.dirname(packageJson), "index.css");
2958
- if (isCssEntryPoint(cssEntry)) return cssEntry;
2959
- } catch {}
2960
- try {
2961
- let current = path.dirname(require.resolve("@tailwindcss-mangle/engine"));
2962
- while (true) {
2963
- const cssEntry = path.resolve(current, "..", "tailwindcss", "index.css");
2964
- if (isCssEntryPoint(cssEntry)) return cssEntry;
2965
- const parent = path.dirname(current);
2966
- if (parent === current) break;
2967
- current = parent;
2968
- }
2969
- } catch {}
2970
- }
2971
- function isPostcssPluginImportTarget(value) {
2972
- if (!value) return false;
2973
- return value === "@tailwindcss/postcss" || value.includes("/postcss");
2974
- }
2975
- function uniqueDefined(values) {
2976
- return [...new Set(values.filter((value) => typeof value === "string" && value.length > 0))];
2977
- }
2978
- function resolveCssImportFile(base, specifier) {
2979
- const normalizedSpecifier = path.sep === "\\" ? specifier.replaceAll("/", "\\") : specifier.replaceAll("\\", "/");
2980
- return path.resolve(base, normalizedSpecifier);
2981
- }
2982
- function getProjectRoot(runtime) {
2983
- return runtime.options?.projectRoot ?? process.cwd();
2984
- }
2985
- function resolveBase(value, fallback) {
2986
- return value === void 0 ? fallback : path.isAbsolute(value) ? path.resolve(value) : path.resolve(fallback, value);
2987
- }
2988
- function resolveConfigDir(config, projectRoot) {
2989
- if (!config) return;
2990
- const configPath = path.isAbsolute(config) ? config : path.resolve(projectRoot, config);
2991
- return path.dirname(configPath);
2992
- }
2993
- function isBarePackageSpecifier(specifier) {
2994
- return !specifier.startsWith(".") && !specifier.startsWith("/") && !specifier.startsWith("#") && !specifier.includes("\\") && !/^[a-z][a-z\d+.-]*:/i.test(specifier);
2995
- }
2996
- function isPackageJsonImportSpecifier(specifier) {
2997
- return typeof specifier === "string" && specifier.startsWith("#");
2998
- }
2999
- function createTailwindV4CssImportSpecifierSet(packageName) {
3000
- const specifiers = /* @__PURE__ */ new Set(["tailwindcss"]);
3001
- if (packageName && isBarePackageSpecifier(packageName)) specifiers.add(packageName);
3002
- return specifiers;
3003
- }
3004
- function normalizeTailwindV4CssPackageImports(css, packageName) {
3005
- if (!css.includes("tailwindcss")) return css;
3006
- let root;
3007
- try {
3008
- root = postcss.parse(css);
3009
- } catch {
3010
- return css;
3011
- }
3012
- const importSpecifiers = createTailwindV4CssImportSpecifierSet(packageName);
3013
- let changed = false;
3014
- root.walkAtRules((rule) => {
3015
- if (rule.name !== "import" && rule.name !== "reference") return;
3016
- const parsed = parseCssImportSpecifier(rule.params);
3017
- if (!parsed || !importSpecifiers.has(parsed.specifier)) return;
3018
- const cssEntryPoint = resolvePackageCssEntryPoint(`${parsed.specifier}/index.css`);
3019
- if (!cssEntryPoint) return;
3020
- rule.params = rule.params.replace(parsed.raw, quoteCssImportSpecifier(cssEntryPoint, parsed.quote));
3021
- changed = true;
3022
- });
3023
- return changed ? root.toString() : css;
3024
- }
3025
- function normalizeTailwindV4CssSources(cssSources, packageName, projectRoot) {
3026
- if (!cssSources?.length) return cssSources;
3027
- let changed = false;
3028
- const normalizedCssSources = cssSources.map((cssSource) => {
3029
- const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? path.isAbsolute(cssSource.file) ? path.resolve(cssSource.file) : path.resolve(projectRoot ?? process.cwd(), cssSource.file) : void 0;
3030
- const base = typeof cssSource.base === "string" && cssSource.base.length > 0 ? path.isAbsolute(cssSource.base) ? path.resolve(cssSource.base) : path.resolve(projectRoot ?? process.cwd(), cssSource.base) : file ? path.dirname(file) : void 0;
3031
- if (typeof cssSource.css !== "string") {
3032
- if (file === cssSource.file && base === cssSource.base) return cssSource;
3033
- changed = true;
3034
- return {
3035
- ...cssSource,
3036
- ...base === void 0 ? {} : { base },
3037
- ...file === void 0 ? {} : { file }
3038
- };
3039
- }
3040
- const configBase = base ?? projectRoot ?? process.cwd();
3041
- const css = normalizeTailwindV4CssPackageImports(normalizeEmptyTailwindCustomVariants(normalizeTailwindConfigDirectives(cssSource.css, configBase)), packageName);
3042
- if (css === cssSource.css && file === cssSource.file && base === cssSource.base) return cssSource;
3043
- changed = true;
3044
- return {
3045
- ...cssSource,
3046
- css,
3047
- ...base === void 0 ? {} : { base },
3048
- ...file === void 0 ? {} : { file }
3049
- };
3050
- });
3051
- return changed ? normalizedCssSources : cssSources;
3052
- }
3053
- function normalizeTailwindV4CssEntrySources(cssEntries, packageName) {
3054
- if (!cssEntries?.length) return;
3055
- const remainingCssEntries = [];
3056
- const cssSources = [];
3057
- const graphs = /* @__PURE__ */ new Map();
3058
- const collectCssGraph = (file, visiting = /* @__PURE__ */ new Set()) => {
3059
- const normalizedFile = path.resolve(file);
3060
- const cached = graphs.get(normalizedFile);
3061
- if (cached) return cached;
3062
- const graph = /* @__PURE__ */ new Set([normalizedFile]);
3063
- graphs.set(normalizedFile, graph);
3064
- if (visiting.has(normalizedFile) || !existsSync(normalizedFile)) return graph;
3065
- const nextVisiting = new Set(visiting).add(normalizedFile);
3066
- let root;
3067
- try {
3068
- root = postcss.parse(readFileSync(normalizedFile, "utf8"));
3069
- } catch {
3070
- return graph;
3071
- }
3072
- const base = path.dirname(normalizedFile);
3073
- root.walkAtRules("import", (rule) => {
3074
- const parsed = parseCssImportSpecifier(rule.params);
3075
- if (!parsed || !parsed.specifier.startsWith(".")) return;
3076
- const importedFile = resolveCssImportFile(base, parsed.specifier);
3077
- const resolved = (path.extname(importedFile) ? [importedFile] : [
3078
- importedFile,
3079
- `${importedFile}.css`,
3080
- `${importedFile}.pcss`,
3081
- `${importedFile}.scss`,
3082
- `${importedFile}.sass`
3083
- ]).find((candidate) => existsSync(candidate));
3084
- if (!resolved) return;
3085
- for (const dependency of collectCssGraph(resolved, nextVisiting)) graph.add(dependency);
3086
- });
3087
- return graph;
3088
- };
3089
- const createCssSource = (file, dependencies) => {
3090
- const normalizedFile = path.resolve(file);
3091
- const base = path.dirname(normalizedFile);
3092
- const rawCss = readFileSync(normalizedFile, "utf8");
3093
- const entrySource = resolveCssEntrySource(rawCss, base, { removeConfig: false });
3094
- return {
3095
- file: normalizedFile,
3096
- base,
3097
- css: normalizeTailwindV4CssPackageImports(normalizeEmptyTailwindCustomVariants(normalizeConfigDirective(rawCss, entrySource?.config && existsSync(entrySource.config) ? entrySource.config : entrySource?.configRequest && !path.isAbsolute(entrySource.configRequest) && !isPackageJsonImportSpecifier(entrySource.configRequest) ? path.resolve(base, entrySource.configRequest) : entrySource?.config)), packageName),
3098
- dependencies: [...dependencies]
3099
- };
3100
- };
3101
- const rootEntries = [];
3102
- for (const cssEntry of cssEntries) {
3103
- const normalizedCssEntry = cssEntry.replace(/[?#].*$/, "");
3104
- const file = path.resolve(normalizedCssEntry);
3105
- if (!existsSync(file)) {
3106
- remainingCssEntries.push(normalizedCssEntry);
3107
- continue;
3108
- }
3109
- rootEntries.push(file);
3110
- }
3111
- const entryGraphs = rootEntries.map((entry) => [entry, collectCssGraph(entry)]);
3112
- const nestedEntries = /* @__PURE__ */ new Set();
3113
- for (const [entry] of entryGraphs) for (const [otherEntry, otherGraph] of entryGraphs) if (entry !== otherEntry && otherGraph.has(entry)) {
3114
- nestedEntries.add(entry);
3115
- break;
3116
- }
3117
- const selectedEntries = entryGraphs.filter(([entry]) => !nestedEntries.has(entry));
3118
- const roots = selectedEntries.length > 0 ? selectedEntries : entryGraphs.slice(0, 1);
3119
- for (const [rootEntry, dependencies] of roots) cssSources.push(createCssSource(rootEntry, dependencies));
3120
- return {
3121
- cssEntries: remainingCssEntries,
3122
- cssSources
3123
- };
3124
- }
3125
- function normalizeTailwindV4SourceOptions(options) {
3126
- if (!options) return options;
3127
- const cssBase = resolveBase(options.base, options.projectRoot ?? options.cwd ?? process.cwd());
3128
- const css = options.css === void 0 ? void 0 : normalizeTailwindV4CssPackageImports(normalizeEmptyTailwindCustomVariants(normalizeTailwindConfigDirectives(options.css, cssBase)), options.packageName);
3129
- const entrySources = normalizeTailwindV4CssEntrySources(options.cssEntries, options.packageName);
3130
- const configuredCssSources = filterTailwindV4CssSourceRoots(options.cssSources);
3131
- const cssSources = normalizeTailwindV4CssSources(configuredCssSources || entrySources?.cssSources ? [...configuredCssSources ?? [], ...entrySources?.cssSources ?? []] : void 0, options.packageName, options.projectRoot);
3132
- const cssEntries = entrySources?.cssEntries ?? options.cssEntries;
3133
- if (css === options.css && cssSources === options.cssSources && cssEntries === options.cssEntries) return options;
3134
- return {
3135
- ...options,
3136
- ...css === void 0 ? {} : { css },
3137
- ...cssEntries === void 0 ? {} : { cssEntries },
3138
- ...cssSources === void 0 ? {} : { cssSources }
3139
- };
3140
- }
3141
- function resolveTailwindCssImportTarget(runtime) {
3142
- const configuredPackageName = resolveTailwindcssOptions(runtime.options)?.packageName;
3143
- if (typeof configuredPackageName === "string" && configuredPackageName.length > 0 && !isPostcssPluginImportTarget(configuredPackageName)) return configuredPackageName;
3144
- const packageName = runtime.packageInfo?.name;
3145
- if (typeof packageName === "string" && packageName.length > 0 && !isPostcssPluginImportTarget(packageName)) return packageName;
3146
- return "tailwindcss";
3147
- }
3148
- function readTailwindV4Options(runtime) {
3149
- return resolveTailwindcssOptions(runtime.options)?.v4 ?? runtime.options?.tailwind?.v4;
3150
- }
3151
- function isRawTailwindcssPatchOptions(options) {
3152
- return Boolean(options && "tailwindcss" in options);
3153
- }
3154
- function resolveEngineTailwindV4SourceOptions(runtime) {
3155
- if (runtime.options) {
3156
- const projectRoot = getProjectRoot(runtime);
3157
- const tailwindOptions = resolveTailwindcssOptions(runtime.options);
3158
- const tailwindV4Options = readTailwindV4Options(runtime);
3159
- const cwd = resolveBase(tailwindOptions?.cwd, projectRoot);
3160
- const configuredBase = tailwindV4Options?.configuredBase ?? (isRawTailwindcssPatchOptions(runtime.options) ? tailwindV4Options?.base : void 0);
3161
- const baseFallbacks = uniqueDefined([
3162
- configuredBase,
3163
- cwd,
3164
- projectRoot,
3165
- resolveConfigDir(tailwindOptions?.config, projectRoot)
3166
- ]);
3167
- return {
3168
- projectRoot,
3169
- cwd,
3170
- ...configuredBase === void 0 ? {} : { base: configuredBase },
3171
- baseFallbacks,
3172
- ...tailwindV4Options?.cssSources === void 0 ? {} : { cssSources: tailwindV4Options.cssSources },
3173
- ...tailwindV4Options?.cssEntries === void 0 ? {} : { cssEntries: tailwindV4Options.cssEntries },
3174
- packageName: resolveTailwindCssImportTarget(runtime)
3175
- };
3176
- }
3177
- return {
3178
- projectRoot: getProjectRoot(runtime),
3179
- packageName: resolveTailwindCssImportTarget(runtime)
3180
- };
3181
- }
3182
- function resolveTailwindV4SourceOptionsFromRuntime(runtime) {
3183
- const tailwindV4Options = readTailwindV4Options(runtime);
3184
- return normalizeTailwindV4SourceOptions(omitUndefined({
3185
- ...resolveEngineTailwindV4SourceOptions(runtime),
3186
- sources: tailwindV4Options?.sources
3187
- }));
3188
- }
3189
- function resolveTailwindV4Source$1(options) {
3190
- const normalizedOptions = normalizeTailwindV4SourceOptions(options);
3191
- return resolveTailwindV4Source(normalizedOptions);
3192
- }
3193
- function resolveTailwindV4SourceFromRuntimeOptions(options) {
3194
- const projectRoot = options?.projectRoot ?? process.cwd();
3195
- const tailwindOptions = options?.tailwindcss;
3196
- const v4Options = tailwindOptions?.v4;
3197
- return resolveTailwindV4Source$1({
3198
- projectRoot,
3199
- cwd: resolveBase(tailwindOptions?.cwd, projectRoot),
3200
- packageName: tailwindOptions?.packageName ?? "tailwindcss",
3201
- ...v4Options ?? {}
3202
- });
3203
- }
3204
- async function resolveTailwindV4SourceFromRuntime(runtime) {
3205
- return resolveTailwindV4Source$1(resolveTailwindV4SourceOptionsFromRuntime(runtime));
3206
- }
3207
- //#endregion
3208
- //#region src/runtime-branch/create-branch.ts
3209
- function createRuntimeBranch(base, platformFamily, options) {
3210
- const { context, tailwindcssVersion } = base;
3211
- return {
3212
- tailwindcssVersion,
3213
- generatorTarget: context.generatorTarget,
3214
- platformFamily,
3215
- platform: options.platform,
3216
- nativeAppPlatform: options.nativeAppPlatform,
3217
- isTailwindV4: tailwindcssVersion === 4,
3218
- isWeb: platformFamily === "web",
3219
- isMiniProgram: platformFamily === "mini-program",
3220
- isNativeApp: platformFamily === "native-app"
3221
- };
3222
- }
3223
- //#endregion
3224
- //#region src/runtime-branch/mini-program.ts
3225
- function createMiniProgramRuntimeBranch(base) {
3226
- const { context, uniUtsPlatform } = base;
3227
- return createRuntimeBranch(base, "mini-program", { platform: typeof context.platform === "string" && context.platform.length > 0 ? context.platform : uniUtsPlatform.isMp ? uniUtsPlatform.normalized : context.platform });
3228
- }
3229
- //#endregion
3230
- //#region src/utils/uni-platform.ts
3231
- function resolveUniUtsPlatform(value = process.env["UNI_UTS_PLATFORM"]) {
3232
- return resolveUniUtsPlatform$1(value);
3233
- }
3234
- //#endregion
3235
- //#region src/runtime-branch/platform.ts
3236
- function isRuntimeUniAppXEnabled(value) {
3237
- return value === true || typeof value === "object" && value?.enabled !== false;
3238
- }
3239
- function normalizeRuntimeUniUtsPlatform(value) {
3240
- return typeof value === "object" && value !== null ? value : resolveUniUtsPlatform(value);
3241
- }
3242
- function resolveNativeAppPlatform(platform) {
3243
- if (platform.isAppAndroid) return "android";
3244
- if (platform.isAppIos) return "ios";
3245
- if (platform.isAppHarmony) return "harmony";
3246
- return "unknown";
3247
- }
3248
- function resolveExplicitOrEnvPlatform(context, uniUtsPlatform) {
3249
- if (typeof context.platform === "string" && context.platform.length > 0) return context.platform;
3250
- return uniUtsPlatform.normalized;
3251
- }
3252
- //#endregion
3253
- //#region src/runtime-branch/native-app.ts
3254
- function createNativeAppRuntimeBranch(base) {
3255
- return createRuntimeBranch(base, "native-app", {
3256
- platform: resolveExplicitOrEnvPlatform(base.context, base.uniUtsPlatform),
3257
- nativeAppPlatform: resolveNativeAppPlatform(base.uniUtsPlatform)
3258
- });
3259
- }
3260
- //#endregion
3261
- //#region src/runtime-branch/tailwind-version.ts
3262
- function resolveTailwindcssBranchVersion(_majorVersion) {
3263
- return 4;
3264
- }
3265
- //#endregion
3266
- //#region src/runtime-branch/web.ts
3267
- function createWebRuntimeBranch(base) {
3268
- return createRuntimeBranch(base, "web", { platform: resolveExplicitOrEnvPlatform(base.context, base.uniUtsPlatform) });
3269
- }
3270
- //#endregion
3271
- //#region src/runtime-branch/index.ts
3272
- function shouldUseNativeAppBranch(base, uniUtsPlatform) {
3273
- return base.appType === "uni-app-x" && isRuntimeUniAppXEnabled(base.uniAppX) && uniUtsPlatform.isApp;
3274
- }
3275
- function resolveRuntimeBranch(context) {
3276
- const uniUtsPlatform = normalizeRuntimeUniUtsPlatform(context.uniUtsPlatform);
3277
- const base = {
3278
- context,
3279
- tailwindcssVersion: resolveTailwindcssBranchVersion(context.tailwindcssMajorVersion),
3280
- uniUtsPlatform
3281
- };
3282
- if (context.generatorTarget === "web") return createWebRuntimeBranch(base);
3283
- if (shouldUseNativeAppBranch(context, uniUtsPlatform)) return createNativeAppRuntimeBranch(base);
3284
- return createMiniProgramRuntimeBranch(base);
3285
- }
3286
- function resolveGeneratorRuntimeBranch(options, context = {}) {
3287
- return options.branch ?? resolveRuntimeBranch({
3288
- ...context,
3289
- generatorTarget: options.target
3290
- });
3291
- }
3292
- function shouldUseMiniProgramCssBranch(branch) {
3293
- return branch.platformFamily === "mini-program" || branch.platformFamily === "native-app";
3294
- }
3295
- function shouldUseNativeAppCssBranch(branch) {
3296
- return branch.platformFamily === "native-app";
3297
- }
3298
- //#endregion
3299
- //#region src/generator/options.ts
3300
- function normalizeWeappTailwindcssGeneratorOptions(options, context = {}) {
3301
- const enabled = options !== false;
3302
- const objectOptions = enabled ? options : void 0;
3303
- const target = objectOptions?.target ?? (shouldUseUniAppViteWebViewGeneratorTarget(context.appType, context.platform) ? "web" : inferGeneratorTargetFromEnv());
3304
- const branch = resolveRuntimeBranch({
3305
- ...context,
3306
- generatorTarget: target
3307
- });
3308
- const hasExplicitTarget = objectOptions !== void 0 && Object.hasOwn(objectOptions, "target");
3309
- const webCompat = objectOptions?.webCompat ?? (!hasExplicitTarget && branch.isWeb ? true : void 0);
3310
- if (objectOptions == null) return {
3311
- enabled,
3312
- target,
3313
- branch,
3314
- webCompat,
3315
- hmr: { preserveDeletedCss: true },
3316
- importFallback: false,
3317
- bareArbitraryValues: void 0
3318
- };
3319
- return {
3320
- enabled,
3321
- target,
3322
- branch,
3323
- config: objectOptions.config,
3324
- styleOptions: objectOptions.styleOptions,
3325
- webCompat,
3326
- hmr: { preserveDeletedCss: objectOptions.hmr?.preserveDeletedCss ?? true },
3327
- importFallback: objectOptions.importFallback ?? false,
3328
- bareArbitraryValues: objectOptions.bareArbitraryValues
3329
- };
3330
- }
3331
- //#endregion
3332
- //#region src/generator/index.ts
3333
- function createWeappTailwindcssGenerator(source) {
3334
- return createTailwindV4Engine$1(source);
3335
- }
3336
- async function resolveTailwindSourceFromRuntime(tailwindRuntime) {
3337
- return resolveTailwindV4SourceFromRuntime(tailwindRuntime);
3338
- }
3339
- async function createWeappTailwindcssGeneratorFromRuntime(tailwindRuntime) {
3340
- return createWeappTailwindcssGenerator(await resolveTailwindSourceFromRuntime(tailwindRuntime));
3341
- }
3342
- //#endregion
3343
- export { hasTailwindApplyDirective as $, normalizeStringListOption as A, resolveCssSourceEntries as At, pruneMiniProgramGeneratedCss as B, shouldUseUniAppWebRpxCompatibility as Bt, findWorkspacePackageDir as C, FULL_SOURCE_SCAN_EXTENSION_RE as Ct, normalizeTailwindcssRuntimeOptions as D, isFileMatchedByTailwindSourceEntries as Dt, normalizeExtendLengthUnits as E, isFileExcludedByTailwindSourceEntries as Et, removeTailwindV4GeneratorAtRules as F, transformTailwindV4CssByTarget as Ft, filterApplyOnlyGeneratedCss as G, stripMiniProgramCssSpecificityPlaceholders as H, resolveValidTailwindV4Candidates$1 as Ht, stripTailwindSourceMediaFragments as I, transformTailwindV4CssToWeapp as It, extractGeneratedCssForUserLayerSelectors as J, normalizeEmptyTailwindCustomVariants as K, stripUnmatchedTailwindSourceMediaCloseFragments as L, resolveCssMacroTailwindV4Source as Lt, transformGeneratorUserCss as M, resolveTailwindV4CssSourceBase as Mt, isCommentOnlyCss as N, toPosixPath as Nt, resolveRuntimeBareArbitraryValues as O, normalizeLegacyContentEntries as Ot, removeMiniProgramInteractiveSelectors as P, _defineProperty as Pt, hasLocalCssImport as Q, finalizeMiniProgramCss$1 as R, getTailwindV4IncrementalGenerateCacheStats as Rt, findNearestPackageRoot as S, createTailwindV4Engine$1 as St, omitUndefined as T, expandTailwindSourceEntries as Tt, createGeneratedThemeDeclarationResolver as U, removeUnsupportedMiniProgramAtRules as V, loadTailwindV4DesignSystem as Vt, removeTailwindV4GeneratedUserCssArtifacts as W, splitUserCssLayerBlocks as X, hasUserCssLayerBlocks as Y, preferScopedGeneratedCssRules as Z, upsertTailwindV4CssSource as _, stripGeneratorPlaceholderMarkers as _t, resolveGeneratorRuntimeBranch as a, normalizeTailwindSourceForGenerator as at, isTailwindV4CssEntry as b, normalizeConfigDirective as bt, shouldUseNativeAppCssBranch as c, resolveCssEntrySource as ct, resolveTailwindV4SourceFromRuntime as d, createCssAppend as dt, hasTailwindNonRootGenerationDirectives as et, resolveTailwindV4SourceFromRuntimeOptions as f, hasTailwindGeneratedCss as ft, removeTailwindV4CssSource as g, splitTailwindV4GeneratedCssBySourceOrder as gt, hasConfiguredTailwindV4CssRoots as h, splitTailwindGeneratedCssByBanner as ht, normalizeWeappTailwindcssGeneratorOptions as i, normalizeTailwindSourceDirectives as it, resolveBooleanObjectOption as j, resolveSourceScanPath as jt, resolveTailwindcssOptions as k, parseConfigParam as kt, resolveUniUtsPlatform as l, GENERATOR_PLACEHOLDER_MARKER_RE as lt, filterTailwindV4CssSourceRoots as m, splitGeneratorPlaceholderCssBySourceOrder as mt, createWeappTailwindcssGeneratorFromRuntime as n, hasTailwindSourceDirectives as nt, resolveRuntimeBranch as o, parseImportRequest as ot, resolveTailwindV4SourceOptionsFromRuntime as p, hasTailwindGeneratedCssMarkers as pt, shouldFilterApplyOnlyGeneratedCss as q, resolveTailwindSourceFromRuntime as r, normalizeTailwindConfigDirectives as rt, shouldUseMiniProgramCssBranch as s, removeTailwindSourceDirectives as st, createWeappTailwindcssGenerator as t, hasTailwindRootDirectives as tt, resolveTailwindV4Source$1 as u, VITE_MARKER_RE as ut, groupCssEntriesByBase as v, stripTailwindBanner as vt, findWorkspaceRoot as w, FULL_SOURCE_SCAN_PATTERN as wt, normalizeCssEntries as x, prependConfigDirective as xt, guessBasedirFromEntries as y, stripTailwindBanners as yt, hasMiniProgramCssSpecificityPlaceholders as z, filterUnsupportedMiniProgramTailwindV4Candidates as zt };