weapp-tailwindcss 5.0.0-next.1 → 5.0.0-next.11

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 (215) hide show
  1. package/README.md +4 -5
  2. package/bin/weapp-tailwindcss.js +1 -21
  3. package/dist/bundle-state-BRkhpjio.js +448 -0
  4. package/dist/bundle-state-BrtFgX-A.mjs +369 -0
  5. package/dist/bundlers/shared/cache.d.ts +6 -6
  6. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +2 -0
  7. package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +3 -0
  8. package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +4 -0
  9. package/dist/bundlers/shared/css-cleanup/selectors.d.ts +8 -0
  10. package/dist/bundlers/shared/css-cleanup.d.ts +1 -2
  11. package/dist/bundlers/shared/css-imports.d.ts +3 -3
  12. package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
  13. package/dist/bundlers/shared/generator-css/directives.d.ts +20 -0
  14. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
  15. package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
  16. package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
  17. package/dist/bundlers/shared/generator-css/markers.d.ts +16 -0
  18. package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -0
  19. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +10 -0
  20. package/dist/bundlers/shared/generator-css.d.ts +12 -20
  21. package/dist/bundlers/shared/hmr-timing.d.ts +5 -0
  22. package/dist/bundlers/shared/style-requests.d.ts +2 -0
  23. package/dist/bundlers/vite/css-finalizer.d.ts +4 -1
  24. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
  25. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +20 -0
  26. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +3 -0
  27. package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
  28. package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
  29. package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
  30. package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
  31. package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
  32. package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
  33. package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
  34. package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
  35. package/dist/bundlers/vite/generate-bundle.d.ts +16 -2
  36. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +4 -1
  37. package/dist/bundlers/vite/index.d.ts +1 -1
  38. package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
  39. package/dist/bundlers/vite/postcss-config.d.ts +6 -0
  40. package/dist/bundlers/vite/rewrite-css-imports.d.ts +5 -3
  41. package/dist/bundlers/vite/runtime-class-set.d.ts +22 -0
  42. package/dist/bundlers/vite/source-candidates.d.ts +18 -0
  43. package/dist/bundlers/vite/source-scan.d.ts +9 -0
  44. package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
  45. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +1 -0
  46. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +5 -2
  47. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -3
  48. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -0
  49. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +3 -1
  50. package/dist/cache/index.d.ts +6 -6
  51. package/dist/cache-B_9E7FxF.js +517 -0
  52. package/dist/cache-DEDxBMIw.mjs +443 -0
  53. package/dist/cli/context.d.ts +1 -14
  54. package/dist/cli/doctor/types.d.ts +11 -11
  55. package/dist/cli/helpers.d.ts +1 -2
  56. package/dist/cli/mount-options.d.ts +2 -0
  57. package/dist/cli/types.d.ts +0 -2
  58. package/dist/cli/vscode-entry.d.ts +3 -3
  59. package/dist/cli.js +126 -602
  60. package/dist/cli.mjs +135 -610
  61. package/dist/constants.d.ts +1 -2
  62. package/dist/core.js +13 -20
  63. package/dist/core.mjs +8 -14
  64. package/dist/css-macro/postcss.js +3 -2
  65. package/dist/css-macro/postcss.mjs +3 -2
  66. package/dist/css-macro.d.ts +1 -0
  67. package/dist/css-macro.js +2 -2
  68. package/dist/css-macro.mjs +2 -2
  69. package/dist/defaults.d.ts +15 -1
  70. package/dist/defaults.js +33 -14
  71. package/dist/defaults.mjs +30 -15
  72. package/dist/escape.js +10 -2
  73. package/dist/escape.mjs +10 -2
  74. package/dist/generator/index.d.ts +1 -1
  75. package/dist/generator/options.d.ts +10 -7
  76. package/dist/generator/types.d.ts +3 -2
  77. package/dist/generator-CahkD2vq.mjs +1469 -0
  78. package/dist/generator-Ck1Dd1V0.js +1568 -0
  79. package/dist/generator.js +1 -1
  80. package/dist/generator.mjs +1 -1
  81. package/dist/gulp.js +149 -47
  82. package/dist/gulp.mjs +144 -42
  83. package/dist/incremental-runtime-class-set-CBMefNHQ.js +1744 -0
  84. package/dist/incremental-runtime-class-set-DaS2yw5c.mjs +1687 -0
  85. package/dist/index.d.ts +1 -1
  86. package/dist/index.js +6 -6
  87. package/dist/index.mjs +5 -5
  88. package/dist/js/index.d.ts +1 -0
  89. package/dist/js/literal-transform.d.ts +2 -0
  90. package/dist/js/precheck.d.ts +2 -2
  91. package/dist/lightningcss/style-handler/selector-transform.d.ts +1 -1
  92. package/dist/lightningcss/style-handler.d.ts +3 -3
  93. package/dist/logger-CZUxvJJD.mjs +2 -0
  94. package/dist/logger-EVNB9z7i.js +1 -0
  95. package/dist/postcss/config-directive.d.ts +1 -0
  96. package/dist/postcss/context.d.ts +9 -0
  97. package/dist/postcss/source-files.d.ts +8 -0
  98. package/dist/postcss/tailwind-version.d.ts +3 -0
  99. package/dist/postcss-BdcRlSpp.js +243 -0
  100. package/dist/postcss-Bs-RbNzK.js +5477 -0
  101. package/dist/postcss-xZDiTRII.mjs +234 -0
  102. package/dist/postcss.d.ts +2 -2
  103. package/dist/postcss.js +3 -274
  104. package/dist/postcss.mjs +1 -267
  105. package/dist/{recorder-rn_2v_nd.js → precheck-D5eEdqeH.js} +168 -304
  106. package/dist/{recorder-B_XyZ576.mjs → precheck-DtBGFS-n.mjs} +134 -269
  107. package/dist/presets.js +13 -11
  108. package/dist/presets.mjs +11 -9
  109. package/dist/reset.d.ts +1 -0
  110. package/dist/runtime-patch-CqB-A4zA.js +85 -0
  111. package/dist/runtime-patch-DGKsVkiG.mjs +71 -0
  112. package/dist/shared/mpx.d.ts +1 -0
  113. package/dist/source-scan-CIVTa3Cj.js +297 -0
  114. package/dist/source-scan-CJ0y0XBj.mjs +258 -0
  115. package/dist/tailwindcss/miniprogram.d.ts +5 -1
  116. package/dist/tailwindcss/patcher-options.d.ts +3 -51
  117. package/dist/tailwindcss/patcher.d.ts +1 -2
  118. package/dist/tailwindcss/runtime/cache.d.ts +3 -3
  119. package/dist/tailwindcss/runtime-patch.d.ts +5 -0
  120. package/dist/tailwindcss/runtime.d.ts +11 -12
  121. package/dist/tailwindcss/source-scan.d.ts +25 -0
  122. package/dist/tailwindcss/targets.d.ts +1 -5
  123. package/dist/tailwindcss/v3-engine/types.d.ts +14 -14
  124. package/dist/tailwindcss/v4/css-entries.d.ts +2 -2
  125. package/dist/tailwindcss/v4/css-sources.d.ts +5 -0
  126. package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
  127. package/dist/tailwindcss/v4/patcher.d.ts +1 -0
  128. package/dist/tailwindcss/v4-engine/candidates.d.ts +2 -0
  129. package/dist/tailwindcss/v4-engine/miniprogram.d.ts +1 -0
  130. package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +1 -0
  131. package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +1 -0
  132. package/dist/tailwindcss/v4-engine/tailwind-v4-default-colors.d.ts +1 -0
  133. package/dist/tailwindcss/v4-engine/types.d.ts +6 -3
  134. package/dist/tailwindcss/version.d.ts +4 -0
  135. package/dist/tailwindcss-B78nj6n7.js +644 -0
  136. package/dist/tailwindcss-DGM8lHUj.mjs +593 -0
  137. package/dist/typedoc.export.d.ts +0 -2
  138. package/dist/types/index.d.ts +45 -48
  139. package/dist/types/shared.d.ts +3 -0
  140. package/dist/types/user-defined-options/general.d.ts +21 -23
  141. package/dist/types/user-defined-options/important.d.ts +31 -28
  142. package/dist/types/user-defined-options/lifecycle.d.ts +4 -4
  143. package/dist/types/user-defined-options/matcher.d.ts +6 -6
  144. package/dist/uni-app-x/vite.d.ts +1 -1
  145. package/dist/utils/disabled.d.ts +2 -3
  146. package/dist/utils/object.d.ts +9 -0
  147. package/dist/{utils-DmC9_In3.js → utils-4ODFyoqD.js} +1 -1
  148. package/dist/{utils-7DUGTFED.mjs → utils-CGBVVNm6.mjs} +1 -1
  149. package/dist/{vite-BHpAqldo.js → vite-BEj9JOOA.js} +1245 -876
  150. package/dist/{vite-C8JlHiyR.mjs → vite-C8S1wfyQ.mjs} +1208 -842
  151. package/dist/vite.d.ts +1 -2
  152. package/dist/vite.js +3 -4
  153. package/dist/vite.mjs +2 -2
  154. package/dist/weapp-tw-css-import-rewrite-loader.js +129 -15
  155. package/dist/weapp-tw-runtime-classset-loader.js +44 -6
  156. package/dist/webpack-Dm1IXTIh.js +778 -0
  157. package/dist/webpack-ZGIKKpFf.mjs +768 -0
  158. package/dist/webpack.js +1 -1
  159. package/dist/webpack.mjs +1 -1
  160. package/package.json +26 -39
  161. package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
  162. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
  163. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
  164. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
  165. package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
  166. package/dist/cli/config.d.ts +0 -5
  167. package/dist/cli/helpers/patch-cwd.d.ts +0 -1
  168. package/dist/cli/mount-options/patch-status.d.ts +0 -2
  169. package/dist/cli/patch-options.d.ts +0 -6
  170. package/dist/cli/tokens.d.ts +0 -4
  171. package/dist/cli/workspace/package-dirs.d.ts +0 -3
  172. package/dist/cli/workspace/patch-package.d.ts +0 -3
  173. package/dist/cli/workspace/patch-utils.d.ts +0 -3
  174. package/dist/cli/workspace/types.d.ts +0 -11
  175. package/dist/cli/workspace/workspace-globs.d.ts +0 -2
  176. package/dist/cli/workspace/workspace-io.d.ts +0 -1
  177. package/dist/cli/workspace/workspace-lock.d.ts +0 -1
  178. package/dist/cli/workspace.d.ts +0 -2
  179. package/dist/css-imports-BbrbluP9.js +0 -177
  180. package/dist/css-imports-CSdPq_Sc.mjs +0 -128
  181. package/dist/experimental/index.d.ts +0 -2
  182. package/dist/experimental/oxc/ast-utils.d.ts +0 -30
  183. package/dist/experimental/oxc/index.d.ts +0 -2
  184. package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
  185. package/dist/experimental/shared/cache.d.ts +0 -3
  186. package/dist/experimental/shared/transform.d.ts +0 -3
  187. package/dist/experimental/shared.d.ts +0 -8
  188. package/dist/experimental/swc/ast-utils.d.ts +0 -30
  189. package/dist/experimental/swc/index.d.ts +0 -2
  190. package/dist/experimental/swc/module-specifiers.d.ts +0 -2
  191. package/dist/generator-CZ-JXw6T.js +0 -492
  192. package/dist/generator-Dwxgra97.mjs +0 -399
  193. package/dist/generator-css-CnYjiMrD.js +0 -1084
  194. package/dist/generator-css-DhPFjSzK.mjs +0 -1057
  195. package/dist/js/syntax.d.ts +0 -10
  196. package/dist/loader-anchors-DvwgIYdA.mjs +0 -205
  197. package/dist/loader-anchors-cprm4Klq.js +0 -273
  198. package/dist/logger-BZ45DZJT.js +0 -1003
  199. package/dist/logger-BoVx1Dbt.mjs +0 -935
  200. package/dist/patcher-options-6gJN2EXy.js +0 -115
  201. package/dist/patcher-options-DQfR5xxT.mjs +0 -92
  202. package/dist/tailwindcss/recorder.d.ts +0 -13
  203. package/dist/tailwindcss/targets/paths.d.ts +0 -13
  204. package/dist/tailwindcss/targets/record-io.d.ts +0 -5
  205. package/dist/tailwindcss/targets/recorder.d.ts +0 -3
  206. package/dist/tailwindcss/targets/types.d.ts +0 -35
  207. package/dist/types/disabled-options.d.ts +0 -4
  208. package/dist/webpack-CABjKGGQ.mjs +0 -441
  209. package/dist/webpack-DNIJ0ysE.js +0 -456
  210. package/dist/webpack4.d.ts +0 -4
  211. package/dist/webpack4.js +0 -387
  212. package/dist/webpack4.mjs +0 -379
  213. package/scripts/postinstall.mjs +0 -59
  214. /package/dist/{constants-B-_T5UnW.mjs → constants-BG12WAKw.mjs} +0 -0
  215. /package/dist/{constants-p1dyh1x1.js → constants-BeeyfJ9k.js} +0 -0
@@ -1,30 +0,0 @@
1
- export interface SwcAst {
2
- [key: string]: any;
3
- }
4
- export declare function parseWithSwc(code: string): SwcAst;
5
- export declare function getIdentifierName(node: any): string | undefined;
6
- export declare function isStringLiteral(node: any): node is {
7
- type: string;
8
- value: string;
9
- };
10
- export declare function isTemplateLiteral(node: any): boolean;
11
- export declare function getTemplateQuasis(node: any): any[];
12
- export declare function getTplElementRaw(elem: any): string | undefined;
13
- export declare function isTaggedTemplate(node: any): boolean;
14
- export declare function getTaggedTemplateTag(node: any): any;
15
- export declare function isCallExpression(node: any): boolean;
16
- export declare function getCallCallee(node: any): any;
17
- export declare function getCallArguments(node: any): any[];
18
- export declare function isImportDeclaration(node: any): boolean;
19
- export declare function isExportAllDeclaration(node: any): boolean;
20
- export declare function getImportSourceLiteral(node: any): any | undefined;
21
- export declare function sliceStringLiteralText(code: string, node: any): {
22
- start: number;
23
- end: number;
24
- text: string;
25
- } | undefined;
26
- export declare function sliceTplElementText(code: string, elem: any): {
27
- start: number;
28
- end: number;
29
- text: string;
30
- } | undefined;
@@ -1,2 +0,0 @@
1
- import type { IJsHandlerOptions, JsHandlerResult } from '../../types';
2
- export declare function swcJsHandler(rawSource: string, options: IJsHandlerOptions): JsHandlerResult;
@@ -1,2 +0,0 @@
1
- import { createToken } from '../shared';
2
- export declare function maybePushModuleSpecifierReplacement(tokens: ReturnType<typeof createToken>[], code: string, nodeWithSource: any, replacements: Record<string, string> | undefined): void;
@@ -1,492 +0,0 @@
1
- const require_chunk = require("./chunk-8l464Juk.js");
2
- const require_patcher_options = require("./patcher-options-6gJN2EXy.js");
3
- let node_module = require("node:module");
4
- let postcss = require("postcss");
5
- postcss = require_chunk.__toESM(postcss);
6
- let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
7
- let node_path = require("node:path");
8
- node_path = require_chunk.__toESM(node_path);
9
- let node_process = require("node:process");
10
- node_process = require_chunk.__toESM(node_process);
11
- let tailwindcss_config = require("tailwindcss-config");
12
- let tailwindcss_patch = require("tailwindcss-patch");
13
- //#region src/tailwindcss/remove-unsupported-css.ts
14
- /**
15
- * 移除小程序不支持的 cascade layer 语法,同时保留 layer 内的实际规则。
16
- */
17
- function removeUnsupportedCascadeLayers(root) {
18
- root.walkAtRules("layer", (atRule) => {
19
- if (!atRule.nodes || atRule.nodes.length === 0) {
20
- atRule.remove();
21
- return;
22
- }
23
- atRule.replaceWith(...atRule.nodes);
24
- });
25
- }
26
- //#endregion
27
- //#region src/tailwindcss/miniprogram.ts
28
- const DEFAULT_WEAPP_VARIABLE_SCOPE = "page,.tw-root,wx-root-portal-content,:host";
29
- const CLASS_SELECTOR_RE = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
30
- const PSEUDO_CONTENT_SELECTOR_RE = /^(?:::before|::after|:before|:after)(?:,(?:::before|::after|:before|:after))*$/;
31
- function hasClassSelector(selector) {
32
- return CLASS_SELECTOR_RE.test(selector);
33
- }
34
- function isCustomPropertyRule(rule) {
35
- let hasDeclaration = false;
36
- let allCustomProperties = true;
37
- rule.walkDecls((decl) => {
38
- hasDeclaration = true;
39
- if (!decl.prop.startsWith("--")) allCustomProperties = false;
40
- });
41
- return hasDeclaration && allCustomProperties;
42
- }
43
- function isPseudoContentInitRule(rule) {
44
- const selector = rule.selector.replace(/\s+/g, "");
45
- if (!PSEUDO_CONTENT_SELECTOR_RE.test(selector)) return false;
46
- let hasDeclaration = false;
47
- let onlyContentVariable = true;
48
- rule.walkDecls((decl) => {
49
- hasDeclaration = true;
50
- if (decl.prop !== "--tw-content") onlyContentVariable = false;
51
- });
52
- return hasDeclaration && onlyContentVariable;
53
- }
54
- /**
55
- * 裁剪 Tailwind 生成 CSS 中面向浏览器的 classless 规则。
56
- *
57
- * 生成模式面向小程序时只需要保留业务 utility 与 Tailwind 变量初始化;
58
- * 浏览器元素 reset、表单伪元素等 classless 规则不适合直接输出到小程序。
59
- */
60
- function pruneMiniProgramGeneratedCss(css) {
61
- const root = postcss.default.parse(css);
62
- root.walkComments((comment) => {
63
- comment.remove();
64
- });
65
- removeUnsupportedCascadeLayers(root);
66
- root.walkAtRules("supports", (atRule) => {
67
- atRule.remove();
68
- });
69
- root.walkRules((rule) => {
70
- if (hasClassSelector(rule.selector)) return;
71
- if (isPseudoContentInitRule(rule)) return;
72
- if (isCustomPropertyRule(rule)) {
73
- rule.selector = DEFAULT_WEAPP_VARIABLE_SCOPE;
74
- return;
75
- }
76
- rule.remove();
77
- });
78
- root.walkAtRules((atRule) => {
79
- if (!atRule.nodes || atRule.nodes.length === 0) atRule.remove();
80
- });
81
- return root.toString();
82
- }
83
- //#endregion
84
- //#region src/tailwindcss/v3-engine/miniprogram.ts
85
- const defaultStyleHandler$1 = (0, _weapp_tailwindcss_postcss.createStyleHandler)({
86
- cssChildCombinatorReplaceValue: ["view", "text"],
87
- cssRemoveHoverPseudoClass: true,
88
- isMainChunk: true,
89
- majorVersion: 3
90
- });
91
- async function transformTailwindV3CssToWeapp(css, options) {
92
- return pruneMiniProgramGeneratedCss((await defaultStyleHandler$1(css, {
93
- cssChildCombinatorReplaceValue: ["view", "text"],
94
- cssRemoveHoverPseudoClass: true,
95
- isMainChunk: true,
96
- majorVersion: 3,
97
- ...options
98
- })).css);
99
- }
100
- async function transformTailwindV3CssByTarget(css, target, options) {
101
- return target === "weapp" ? transformTailwindV3CssToWeapp(css, options) : css;
102
- }
103
- //#endregion
104
- //#region src/tailwindcss/v3-engine/generator.ts
105
- function isLegacyContentObject(value) {
106
- return typeof value === "object" && value !== null && "files" in value;
107
- }
108
- function createRawContentEntries(candidates, sources) {
109
- const entries = [];
110
- const candidateContent = [...candidates].join(" ");
111
- if (candidateContent.length > 0) entries.push({
112
- raw: candidateContent,
113
- extension: "html"
114
- });
115
- for (const source of sources) entries.push({
116
- raw: source.content,
117
- extension: source.extension ?? "html"
118
- });
119
- return entries;
120
- }
121
- function mergeContent(content, rawEntries) {
122
- if (isLegacyContentObject(content)) return {
123
- ...content,
124
- relative: content.relative ?? true,
125
- files: [...[].concat(content.files ?? []), ...rawEntries]
126
- };
127
- return {
128
- relative: true,
129
- files: [...[].concat(content ?? []), ...rawEntries]
130
- };
131
- }
132
- function normalizeConfigObject(config) {
133
- if (!config || typeof config !== "object") return config;
134
- const maybeDefault = config.default;
135
- if (maybeDefault && typeof maybeDefault === "object") return maybeDefault;
136
- return config;
137
- }
138
- function createTailwindConfig(source, options) {
139
- const config = { ...normalizeConfigObject(source.configObject) ?? {} };
140
- const rawEntries = createRawContentEntries(options.candidates ?? [], options.sources ?? []);
141
- config.content = mergeContent(config.content, rawEntries);
142
- return config;
143
- }
144
- function loadTailwindcssPlugin(source) {
145
- const requireFromProject = (0, node_module.createRequire)(`${source.cwd}/package.json`);
146
- const requireFromRuntime = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
147
- let plugin;
148
- try {
149
- plugin = requireFromProject(source.postcssPlugin);
150
- } catch {
151
- plugin = requireFromRuntime(source.postcssPlugin);
152
- }
153
- return typeof plugin === "function" ? plugin : plugin.default;
154
- }
155
- function collectClassSet(plugin) {
156
- const classSet = /* @__PURE__ */ new Set();
157
- for (const context of plugin.contextRef?.value ?? []) for (const candidate of context.classCache?.keys() ?? []) if (candidate !== "*") classSet.add(candidate);
158
- return classSet;
159
- }
160
- function collectDependencyMessages(result) {
161
- const dependencies = /* @__PURE__ */ new Set();
162
- for (const message of result.messages) if (message.type === "dependency" && typeof message.file === "string") dependencies.add(message.file);
163
- return dependencies;
164
- }
165
- function createTailwindV3Engine(source) {
166
- async function generate(options = {}) {
167
- const { styleOptions, target = "weapp" } = options;
168
- const tailwindcss = loadTailwindcssPlugin(source);
169
- const result = await (0, postcss.default)([tailwindcss(createTailwindConfig(source, options))]).process(source.css, { from: void 0 });
170
- const rawCss = result.css;
171
- const css = await transformTailwindV3CssByTarget(rawCss, target, styleOptions);
172
- const dependencies = collectDependencyMessages(result);
173
- for (const dependency of source.dependencies) dependencies.add(dependency);
174
- return {
175
- css,
176
- rawCss,
177
- classSet: collectClassSet(tailwindcss),
178
- rawCandidates: new Set(options.candidates ?? []),
179
- dependencies: [...dependencies],
180
- sources: [],
181
- root: null,
182
- target,
183
- version: 3
184
- };
185
- }
186
- return {
187
- source,
188
- async validateCandidates(candidates) {
189
- return (await generate({
190
- candidates,
191
- target: "tailwind"
192
- })).classSet;
193
- },
194
- generate
195
- };
196
- }
197
- //#endregion
198
- //#region src/tailwindcss/v3-engine/source.ts
199
- const DEFAULT_TAILWIND_V3_CSS = [
200
- "@tailwind base;",
201
- "@tailwind components;",
202
- "@tailwind utilities;"
203
- ].join("\n");
204
- function parseConfigParam(params) {
205
- const value = params.trim();
206
- return /^(['"])(.+)\1$/.exec(value)?.[2];
207
- }
208
- function resolveOptionalPath(value, base) {
209
- if (!value) return;
210
- return node_path.default.isAbsolute(value) ? value : node_path.default.resolve(base, value);
211
- }
212
- function resolveCssConfig(css, base) {
213
- if (!css) return {
214
- css,
215
- config: void 0
216
- };
217
- const root = postcss.default.parse(css);
218
- let config;
219
- root.walkAtRules("config", (rule) => {
220
- const configPath = parseConfigParam(rule.params);
221
- if (!configPath) return;
222
- if (!config) config = resolveOptionalPath(configPath, base);
223
- rule.remove();
224
- });
225
- return {
226
- config,
227
- css: root.toString()
228
- };
229
- }
230
- function getProjectRoot$1(patcher) {
231
- return patcher.options?.projectRoot ?? node_process.default.cwd();
232
- }
233
- function normalizeLoadedConfig(config) {
234
- if (!config || typeof config !== "object") return config;
235
- const maybeDefault = config.default;
236
- if (maybeDefault && typeof maybeDefault === "object") return maybeDefault;
237
- return config;
238
- }
239
- function resolveTailwindCssPackageName(patcher) {
240
- return require_patcher_options.resolveTailwindcssOptions(patcher.options)?.packageName ?? patcher.packageInfo?.name ?? "tailwindcss";
241
- }
242
- async function resolveTailwindV3Source(options = {}) {
243
- const projectRoot = options.projectRoot ?? node_process.default.cwd();
244
- const base = options.base ?? options.cwd ?? projectRoot;
245
- const cssConfig = resolveCssConfig(options.css, base);
246
- const config = resolveOptionalPath(options.config, base) ?? cssConfig.config;
247
- const cwd = options.cwd ?? (config ? node_path.default.dirname(config) : projectRoot);
248
- const loaded = await (0, tailwindcss_config.loadConfig)({
249
- config,
250
- cwd
251
- });
252
- return {
253
- version: 3,
254
- projectRoot,
255
- cwd,
256
- base,
257
- css: cssConfig.css ?? options.css ?? DEFAULT_TAILWIND_V3_CSS,
258
- config: loaded?.filepath ?? config,
259
- configObject: normalizeLoadedConfig(loaded?.config),
260
- dependencies: loaded?.filepath ? [loaded.filepath] : [],
261
- packageName: options.packageName ?? "tailwindcss",
262
- postcssPlugin: options.postcssPlugin ?? options.packageName ?? "tailwindcss"
263
- };
264
- }
265
- function resolveTailwindV3SourceOptionsFromPatcher(patcher) {
266
- const projectRoot = getProjectRoot$1(patcher);
267
- const tailwindOptions = require_patcher_options.resolveTailwindcssOptions(patcher.options);
268
- return {
269
- projectRoot,
270
- cwd: tailwindOptions?.v3?.cwd ?? tailwindOptions?.cwd ?? projectRoot,
271
- config: tailwindOptions?.v3?.config ?? tailwindOptions?.config,
272
- packageName: resolveTailwindCssPackageName(patcher),
273
- postcssPlugin: tailwindOptions?.v3?.postcssPlugin ?? tailwindOptions?.postcssPlugin
274
- };
275
- }
276
- function resolveTailwindV3SourceFromPatcher(patcher) {
277
- return resolveTailwindV3Source(resolveTailwindV3SourceOptionsFromPatcher(patcher));
278
- }
279
- //#endregion
280
- //#region src/tailwindcss/v4-engine/miniprogram.ts
281
- const defaultStyleHandler = (0, _weapp_tailwindcss_postcss.createStyleHandler)({
282
- cssChildCombinatorReplaceValue: ["view", "text"],
283
- cssRemoveHoverPseudoClass: true,
284
- isMainChunk: true,
285
- majorVersion: 4
286
- });
287
- async function transformTailwindV4CssToWeapp(css, options) {
288
- return pruneMiniProgramGeneratedCss((await defaultStyleHandler(css, {
289
- cssChildCombinatorReplaceValue: ["view", "text"],
290
- cssRemoveHoverPseudoClass: true,
291
- isMainChunk: true,
292
- majorVersion: 4,
293
- ...options
294
- })).css);
295
- }
296
- async function transformTailwindV4CssByTarget(css, target, options) {
297
- return target === "weapp" ? transformTailwindV4CssToWeapp(css, options) : css;
298
- }
299
- //#endregion
300
- //#region src/tailwindcss/v4-engine/generator.ts
301
- function createTailwindV4Engine(source) {
302
- const engine = (0, tailwindcss_patch.createTailwindV4Engine)(source);
303
- async function generate(options = {}) {
304
- const { styleOptions, target = "weapp", ...patchOptions } = options;
305
- const result = await engine.generate({
306
- scanSources: true,
307
- ...patchOptions
308
- });
309
- const rawCss = result.css;
310
- const css = await transformTailwindV4CssByTarget(rawCss, target, styleOptions);
311
- return {
312
- ...result,
313
- css,
314
- rawCss,
315
- target
316
- };
317
- }
318
- return {
319
- source,
320
- loadDesignSystem: engine.loadDesignSystem,
321
- validateCandidates: engine.validateCandidates,
322
- generate
323
- };
324
- }
325
- //#endregion
326
- //#region src/tailwindcss/v4-engine/source.ts
327
- function isPostcssPluginImportTarget(value) {
328
- if (!value) return false;
329
- return value === "@tailwindcss/postcss" || value === "@tailwindcss/postcss7-compat" || value.includes("/postcss");
330
- }
331
- function uniqueDefined(values) {
332
- return [...new Set(values.filter((value) => typeof value === "string" && value.length > 0))];
333
- }
334
- function getProjectRoot(patcher) {
335
- return patcher.options?.projectRoot ?? node_process.default.cwd();
336
- }
337
- function readConfiguredV4Base(tailwindOptions) {
338
- const v4 = tailwindOptions?.v4;
339
- if (typeof v4 !== "object" || v4 === null) return;
340
- return v4.configuredBase;
341
- }
342
- function resolveTailwindCssImportTarget(patcher) {
343
- const configuredPackageName = require_patcher_options.resolveTailwindcssOptions(patcher.options)?.packageName;
344
- if (typeof configuredPackageName === "string" && configuredPackageName.length > 0 && !isPostcssPluginImportTarget(configuredPackageName)) return configuredPackageName;
345
- const packageName = patcher.packageInfo?.name;
346
- if (typeof packageName === "string" && packageName.length > 0 && !isPostcssPluginImportTarget(packageName)) return packageName;
347
- return "tailwindcss";
348
- }
349
- function resolveTailwindV4SourceOptionsFromPatcher(patcher) {
350
- const projectRoot = getProjectRoot(patcher);
351
- const tailwindOptions = require_patcher_options.resolveTailwindcssOptions(patcher.options);
352
- const configDir = tailwindOptions?.config ? node_path.default.dirname(tailwindOptions.config) : void 0;
353
- const configuredBase = readConfiguredV4Base(tailwindOptions);
354
- const hasCssEntries = Boolean(tailwindOptions?.v4?.cssEntries?.length);
355
- return {
356
- projectRoot,
357
- base: configuredBase ?? (hasCssEntries ? void 0 : tailwindOptions?.v4?.base),
358
- baseFallbacks: uniqueDefined([tailwindOptions?.cwd, configDir]),
359
- css: tailwindOptions?.v4?.css,
360
- cssEntries: tailwindOptions?.v4?.cssEntries,
361
- sources: tailwindOptions?.v4?.sources,
362
- packageName: resolveTailwindCssImportTarget(patcher)
363
- };
364
- }
365
- function resolveTailwindV4Source(options) {
366
- return (0, tailwindcss_patch.resolveTailwindV4Source)(options);
367
- }
368
- async function resolveTailwindV4SourceFromPatcher(patcher) {
369
- return (0, tailwindcss_patch.resolveTailwindV4Source)(resolveTailwindV4SourceOptionsFromPatcher(patcher));
370
- }
371
- //#endregion
372
- //#region src/generator/options.ts
373
- function normalizeWeappTailwindcssGeneratorOptions(options) {
374
- if (options === false) return {
375
- mode: "off",
376
- target: "weapp"
377
- };
378
- if (options === true || options == null) return {
379
- mode: "auto",
380
- target: "weapp"
381
- };
382
- return {
383
- mode: options.mode ?? "auto",
384
- target: options.target ?? "weapp",
385
- styleOptions: options.styleOptions
386
- };
387
- }
388
- //#endregion
389
- //#region src/generator/index.ts
390
- function isTailwindV3Source(source) {
391
- return "version" in source && source.version === 3;
392
- }
393
- function createWeappTailwindcssGenerator(source) {
394
- return isTailwindV3Source(source) ? createTailwindV3Engine(source) : createTailwindV4Engine(source);
395
- }
396
- async function resolveTailwindSourceFromPatcher(patcher) {
397
- return patcher.majorVersion === 3 ? resolveTailwindV3SourceFromPatcher(patcher) : resolveTailwindV4SourceFromPatcher(patcher);
398
- }
399
- async function createWeappTailwindcssGeneratorFromPatcher(patcher) {
400
- return createWeappTailwindcssGenerator(await resolveTailwindSourceFromPatcher(patcher));
401
- }
402
- //#endregion
403
- Object.defineProperty(exports, "createWeappTailwindcssGenerator", {
404
- enumerable: true,
405
- get: function() {
406
- return createWeappTailwindcssGenerator;
407
- }
408
- });
409
- Object.defineProperty(exports, "createWeappTailwindcssGeneratorFromPatcher", {
410
- enumerable: true,
411
- get: function() {
412
- return createWeappTailwindcssGeneratorFromPatcher;
413
- }
414
- });
415
- Object.defineProperty(exports, "normalizeWeappTailwindcssGeneratorOptions", {
416
- enumerable: true,
417
- get: function() {
418
- return normalizeWeappTailwindcssGeneratorOptions;
419
- }
420
- });
421
- Object.defineProperty(exports, "removeUnsupportedCascadeLayers", {
422
- enumerable: true,
423
- get: function() {
424
- return removeUnsupportedCascadeLayers;
425
- }
426
- });
427
- Object.defineProperty(exports, "resolveTailwindSourceFromPatcher", {
428
- enumerable: true,
429
- get: function() {
430
- return resolveTailwindSourceFromPatcher;
431
- }
432
- });
433
- Object.defineProperty(exports, "resolveTailwindV3Source", {
434
- enumerable: true,
435
- get: function() {
436
- return resolveTailwindV3Source;
437
- }
438
- });
439
- Object.defineProperty(exports, "resolveTailwindV3SourceFromPatcher", {
440
- enumerable: true,
441
- get: function() {
442
- return resolveTailwindV3SourceFromPatcher;
443
- }
444
- });
445
- Object.defineProperty(exports, "resolveTailwindV3SourceOptionsFromPatcher", {
446
- enumerable: true,
447
- get: function() {
448
- return resolveTailwindV3SourceOptionsFromPatcher;
449
- }
450
- });
451
- Object.defineProperty(exports, "resolveTailwindV4Source", {
452
- enumerable: true,
453
- get: function() {
454
- return resolveTailwindV4Source;
455
- }
456
- });
457
- Object.defineProperty(exports, "resolveTailwindV4SourceFromPatcher", {
458
- enumerable: true,
459
- get: function() {
460
- return resolveTailwindV4SourceFromPatcher;
461
- }
462
- });
463
- Object.defineProperty(exports, "resolveTailwindV4SourceOptionsFromPatcher", {
464
- enumerable: true,
465
- get: function() {
466
- return resolveTailwindV4SourceOptionsFromPatcher;
467
- }
468
- });
469
- Object.defineProperty(exports, "transformTailwindV3CssByTarget", {
470
- enumerable: true,
471
- get: function() {
472
- return transformTailwindV3CssByTarget;
473
- }
474
- });
475
- Object.defineProperty(exports, "transformTailwindV3CssToWeapp", {
476
- enumerable: true,
477
- get: function() {
478
- return transformTailwindV3CssToWeapp;
479
- }
480
- });
481
- Object.defineProperty(exports, "transformTailwindV4CssByTarget", {
482
- enumerable: true,
483
- get: function() {
484
- return transformTailwindV4CssByTarget;
485
- }
486
- });
487
- Object.defineProperty(exports, "transformTailwindV4CssToWeapp", {
488
- enumerable: true,
489
- get: function() {
490
- return transformTailwindV4CssToWeapp;
491
- }
492
- });