weapp-tailwindcss 5.0.0-next.9 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/README.md +2 -2
  2. package/dist/auto-DEHRmEAx.mjs +200 -0
  3. package/dist/auto-dPpsm6FB.js +238 -0
  4. package/dist/bundle-state-CBF5YX1m.js +529 -0
  5. package/dist/bundle-state-CQmxxx0R.mjs +413 -0
  6. package/dist/bundlers/shared/cache.d.ts +9 -7
  7. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +1 -2
  8. package/dist/bundlers/shared/css-cleanup.d.ts +1 -3
  9. package/dist/bundlers/shared/css-imports.d.ts +3 -3
  10. package/dist/bundlers/shared/generated-css-marker.d.ts +3 -0
  11. package/dist/bundlers/shared/generator-css/directives.d.ts +11 -3
  12. package/dist/bundlers/shared/generator-css/markers.d.ts +12 -0
  13. package/dist/bundlers/shared/generator-css/source-files.d.ts +9 -6
  14. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +16 -2
  15. package/dist/bundlers/shared/generator-css/user-layer-order.d.ts +10 -0
  16. package/dist/bundlers/shared/generator-css.d.ts +6 -2
  17. package/dist/bundlers/shared/hmr-timing.d.ts +22 -0
  18. package/dist/bundlers/shared/style-requests.d.ts +2 -0
  19. package/dist/bundlers/vite/bundle-state.d.ts +1 -0
  20. package/dist/bundlers/vite/css-finalizer.d.ts +6 -0
  21. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +1 -1
  22. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +5 -1
  23. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +1 -0
  24. package/dist/bundlers/vite/generate-bundle.d.ts +13 -1
  25. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +10 -2
  26. package/dist/bundlers/vite/index.d.ts +5 -2
  27. package/dist/bundlers/vite/processed-css-assets.d.ts +32 -0
  28. package/dist/bundlers/vite/rewrite-css-imports.d.ts +8 -5
  29. package/dist/bundlers/vite/runtime-class-set.d.ts +5 -1
  30. package/dist/bundlers/vite/serve-css-generation.d.ts +11 -0
  31. package/dist/bundlers/vite/source-candidates.d.ts +24 -2
  32. package/dist/bundlers/vite/source-scan.d.ts +26 -0
  33. package/dist/bundlers/vite/static-config-content.d.ts +5 -0
  34. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +5 -0
  35. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +5 -1
  36. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +8 -3
  37. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -1
  38. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +31 -0
  39. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +2 -8
  40. package/dist/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.d.ts +3 -7
  41. package/dist/cache/index.d.ts +6 -6
  42. package/dist/{chunk-8l464Juk.js → chunk-C5U5_Hdc.js} +14 -0
  43. package/dist/cli/context.d.ts +1 -11
  44. package/dist/cli/doctor/types.d.ts +11 -11
  45. package/dist/cli/vscode-entry.d.ts +3 -3
  46. package/dist/cli.js +684 -41
  47. package/dist/cli.mjs +682 -40
  48. package/dist/context/runtime-package-replacements.d.ts +2 -0
  49. package/dist/context/style-options.d.ts +3 -0
  50. package/dist/context/tailwindcss.d.ts +1 -1
  51. package/dist/core.js +1 -2
  52. package/dist/core.mjs +1 -1
  53. package/dist/css-macro/auto.d.ts +11 -0
  54. package/dist/css-macro/constants.d.ts +5 -2
  55. package/dist/css-macro/postcss.d.ts +1 -0
  56. package/dist/css-macro/postcss.js +7 -46
  57. package/dist/css-macro/postcss.mjs +2 -46
  58. package/dist/css-macro.js +16 -7
  59. package/dist/css-macro.mjs +15 -6
  60. package/dist/defaults-8xrgzxFY.mjs +151 -0
  61. package/dist/defaults-zKUH2mDe.js +193 -0
  62. package/dist/defaults.js +6 -150
  63. package/dist/defaults.mjs +1 -143
  64. package/dist/escape.js +10 -2
  65. package/dist/escape.mjs +10 -2
  66. package/dist/generator/options.d.ts +11 -6
  67. package/dist/generator/types.d.ts +3 -3
  68. package/dist/generator-CvmsIQFI.js +92 -0
  69. package/dist/generator-DDtsUvkH.mjs +67 -0
  70. package/dist/generator.js +12 -12
  71. package/dist/generator.mjs +2 -1
  72. package/dist/gulp.js +163 -40
  73. package/dist/gulp.mjs +155 -32
  74. package/dist/incremental-runtime-class-set-BffodqHh.js +2366 -0
  75. package/dist/incremental-runtime-class-set-DArodvWs.mjs +2291 -0
  76. package/dist/index.d.ts +2 -1
  77. package/dist/index.js +17 -5
  78. package/dist/index.mjs +6 -5
  79. package/dist/js/babel/cache-options.d.ts +3 -0
  80. package/dist/js/babel/parse.d.ts +7 -4
  81. package/dist/js/precheck.d.ts +2 -2
  82. package/dist/js/replacement-cache.d.ts +5 -0
  83. package/dist/{postcss-w48mGIhe.mjs → postcss-BzNYQUOH.mjs} +54 -114
  84. package/dist/postcss-C7BMYpEF.mjs +169 -0
  85. package/dist/postcss-CiYLsqZn.js +192 -0
  86. package/dist/{postcss-QIXwT40c.js → postcss-DE0TOtV9.js} +60 -121
  87. package/dist/postcss-html-transform.js +1 -1
  88. package/dist/postcss.js +1 -1
  89. package/dist/postcss.mjs +1 -1
  90. package/dist/precheck-BzYPm-EG.js +4842 -0
  91. package/dist/precheck-jZvTVXXG.mjs +4716 -0
  92. package/dist/presets/index.d.ts +1 -0
  93. package/dist/presets/uni-app-x.d.ts +1 -0
  94. package/dist/presets.js +27 -13
  95. package/dist/presets.mjs +25 -13
  96. package/dist/reset.js +1 -1
  97. package/dist/runtime-registry-DpcR3IHI.js +5496 -0
  98. package/dist/shared/mpx.d.ts +1 -0
  99. package/dist/source-candidates-BuTlMabx.mjs +322 -0
  100. package/dist/source-candidates-CxoIaS88.js +335 -0
  101. package/dist/tailwindcss/miniprogram.d.ts +1 -5
  102. package/dist/tailwindcss/remove-unsupported-css.d.ts +1 -2
  103. package/dist/tailwindcss/runtime/cache.d.ts +4 -3
  104. package/dist/tailwindcss/runtime.d.ts +9 -9
  105. package/dist/tailwindcss/source-scan.d.ts +35 -0
  106. package/dist/tailwindcss/v3-engine/types.d.ts +19 -14
  107. package/dist/tailwindcss/v4/css-entries.d.ts +2 -2
  108. package/dist/tailwindcss/v4/patcher.d.ts +1 -1
  109. package/dist/tailwindcss/v4-engine/source.d.ts +2 -2
  110. package/dist/tailwindcss/v4-engine/types.d.ts +18 -5
  111. package/dist/{tailwindcss-C5IgPlQ0.mjs → tailwindcss-CCZcu0lr.mjs} +75 -98
  112. package/dist/{tailwindcss-Bu-RWIHx.js → tailwindcss-DZckITp1.js} +83 -106
  113. package/dist/typedoc.export.d.ts +1 -1
  114. package/dist/types/index.d.ts +51 -41
  115. package/dist/types/shared.d.ts +3 -0
  116. package/dist/types/typedoc-tailwindcss-patch.d.ts +67 -0
  117. package/dist/types/user-defined-options/general.d.ts +25 -22
  118. package/dist/types/user-defined-options/important.d.ts +32 -27
  119. package/dist/types/user-defined-options/lifecycle.d.ts +4 -4
  120. package/dist/types/user-defined-options/matcher.d.ts +6 -6
  121. package/dist/unocss/index.d.ts +2 -0
  122. package/dist/utils/object.d.ts +9 -0
  123. package/dist/utils/options.d.ts +2 -0
  124. package/dist/utils/regex.d.ts +1 -0
  125. package/dist/{utils-BiShvil9.js → utils-D7Ygohep.js} +2 -2
  126. package/dist/{utils-Btw1iOVV.mjs → utils-DsaS975I.mjs} +1 -1
  127. package/dist/v3-engine-DGBhUnjn.mjs +3419 -0
  128. package/dist/v3-engine-M6Aqru5T.js +3714 -0
  129. package/dist/vite-BBcQIJpD.mjs +24493 -0
  130. package/dist/vite-DgRkWVPG.js +24507 -0
  131. package/dist/vite.js +1 -1
  132. package/dist/vite.mjs +1 -1
  133. package/dist/weapp-tw-css-import-rewrite-loader.js +5456 -22
  134. package/dist/weapp-tw-runtime-classset-loader.js +32 -9
  135. package/dist/{webpack-BzN2ly34.js → webpack-D-gb4ZvO.js} +341 -96
  136. package/dist/{webpack-DJazm5sT.mjs → webpack-D43aMQzO.mjs} +323 -79
  137. package/dist/webpack.d.ts +1 -3
  138. package/dist/webpack.js +3 -4
  139. package/dist/webpack.mjs +2 -2
  140. package/dist/wxml/utils/codegen/legacy-visitor.d.ts +2 -4
  141. package/package.json +22 -20
  142. package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +0 -3
  143. package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +0 -4
  144. package/dist/bundlers/shared/css-cleanup/selectors.d.ts +0 -8
  145. package/dist/cache-BVAiJV3J.js +0 -502
  146. package/dist/cache-CHs4DXui.mjs +0 -434
  147. package/dist/constants-BoB_6lFw.js +0 -73
  148. package/dist/constants-E_loJC49.mjs +0 -44
  149. package/dist/generator-DKkhJbOg.js +0 -1531
  150. package/dist/generator-UBmfduYg.mjs +0 -1432
  151. package/dist/generator-css-Bwp3nbrl.js +0 -1381
  152. package/dist/generator-css-DeLLmp2N.mjs +0 -1342
  153. package/dist/lightningcss/index.d.ts +0 -8
  154. package/dist/lightningcss/style-handler/options.d.ts +0 -3
  155. package/dist/lightningcss/style-handler/selector-transform.d.ts +0 -10
  156. package/dist/lightningcss/style-handler/selector-utils.d.ts +0 -10
  157. package/dist/lightningcss/style-handler.d.ts +0 -17
  158. package/dist/precheck-B32p-gLI.js +0 -2736
  159. package/dist/precheck-B4RH6ZNN.mjs +0 -2622
  160. package/dist/run-tasks-B50A3pxt.js +0 -128
  161. package/dist/run-tasks-DdNi-hkk.mjs +0 -91
  162. package/dist/runtime-patch-CwN5ya72.mjs +0 -71
  163. package/dist/runtime-patch-D6mBo_KB.js +0 -85
  164. package/dist/vite-By5KQi9s.js +0 -2419
  165. package/dist/vite-Cyp42bBf.mjs +0 -2406
  166. /package/dist/{logger-Bub1jggA.mjs → logger-BNzxZbZj.mjs} +0 -0
  167. /package/dist/{logger-BRy6XPQ2.js → logger-TlKT3xmR.js} +0 -0
package/dist/webpack.d.ts CHANGED
@@ -1,4 +1,2 @@
1
- export * from './bundlers/webpack/index';
2
- export { UnifiedWebpackPluginV5 as WeappTailwindcss } from './bundlers/webpack/index';
3
- export { UnifiedWebpackPluginV5 as weappTailwindcss } from './bundlers/webpack/index';
1
+ export { WeappTailwindcss, WeappTailwindcss as weappTailwindcss, weappTailwindcssPackageDir, } from './bundlers/webpack/index';
4
2
  export type { UserDefinedOptions } from './types';
package/dist/webpack.js CHANGED
@@ -1,6 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_webpack = require("./webpack-BzN2ly34.js");
3
- exports.UnifiedWebpackPluginV5 = require_webpack.UnifiedWebpackPluginV5;
4
- exports.WeappTailwindcss = require_webpack.UnifiedWebpackPluginV5;
5
- exports.weappTailwindcss = require_webpack.UnifiedWebpackPluginV5;
2
+ const require_webpack = require("./webpack-D-gb4ZvO.js");
3
+ exports.WeappTailwindcss = require_webpack.WeappTailwindcss;
4
+ exports.weappTailwindcss = require_webpack.WeappTailwindcss;
6
5
  exports.weappTailwindcssPackageDir = require_webpack.weappTailwindcssPackageDir;
package/dist/webpack.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as weappTailwindcssPackageDir, t as UnifiedWebpackPluginV5 } from "./webpack-DJazm5sT.mjs";
2
- export { UnifiedWebpackPluginV5, UnifiedWebpackPluginV5 as WeappTailwindcss, UnifiedWebpackPluginV5 as weappTailwindcss, weappTailwindcssPackageDir };
1
+ import { n as weappTailwindcssPackageDir, t as WeappTailwindcss } from "./webpack-D43aMQzO.mjs";
2
+ export { WeappTailwindcss, WeappTailwindcss as weappTailwindcss, weappTailwindcssPackageDir };
@@ -1,8 +1,6 @@
1
- import type { StringLiteral } from '@babel/types';
1
+ import type { TraverseOptions } from '@babel/traverse';
2
2
  import type { JsTokenUpdater } from '../../../js/JsTokenUpdater';
3
3
  import type { ITemplateHandlerOptions } from '../../../types';
4
- import * as t from '@babel/types';
5
- export declare function createLegacyTraverseOptions(options: ITemplateHandlerOptions, jsTokenUpdater: JsTokenUpdater): {
6
- StringLiteral(this: t.Node, path: import("@babel/traverse").NodePath<StringLiteral>): void;
4
+ export declare function createLegacyTraverseOptions(options: ITemplateHandlerOptions, jsTokenUpdater: JsTokenUpdater): TraverseOptions & {
7
5
  noScope: true;
8
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weapp-tailwindcss",
3
- "version": "5.0.0-next.9",
3
+ "version": "5.0.1",
4
4
  "description": "把 tailwindcss 原子化样式思想,带给小程序开发者们! bring tailwindcss to miniprogram developers!",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -169,30 +169,31 @@
169
169
  },
170
170
  "dependencies": {
171
171
  "@ast-core/escape": "~1.0.1",
172
- "@babel/parser": "~7.29.3",
173
- "@babel/traverse": "~7.29.0",
174
- "@babel/types": "~7.29.0",
175
- "@vue/compiler-dom": "^3.5.34",
176
- "@vue/compiler-sfc": "^3.5.34",
177
- "@weapp-core/escape": "~7.0.0",
178
- "@weapp-core/regex": "~1.0.1",
179
- "comment-json": "^4.6.2",
172
+ "@babel/parser": "~7.29.7",
173
+ "@babel/traverse": "~7.29.7",
174
+ "@babel/types": "~7.29.7",
175
+ "@weapp-core/escape": "~8.0.0",
176
+ "comment-json": "^5.0.0",
180
177
  "debug": "~4.4.3",
181
178
  "fast-glob": "^3.3.3",
182
- "htmlparser2": "10.1.0",
183
- "loader-utils": "2.0.4",
184
- "local-pkg": "^1.1.2",
185
- "lru-cache": "10.4.3",
179
+ "local-pkg": "^1.2.1",
180
+ "lru-cache": "11.5.1",
186
181
  "magic-string": "0.30.21",
182
+ "micromatch": "^4.0.8",
187
183
  "postcss-load-config": "^6.0.1",
188
- "semver": "~7.8.0",
189
- "tailwindcss-patch": "9.3.3",
184
+ "semver": "~7.8.1",
185
+ "tailwindcss-patch": "9.4.2",
190
186
  "yaml": "^2.9.0",
191
- "@weapp-tailwindcss/logger": "1.1.0",
192
- "@weapp-tailwindcss/reset": "0.1.1-next.0",
193
- "@weapp-tailwindcss/shared": "1.1.3",
194
- "@weapp-tailwindcss/postcss": "2.2.1-next.1",
195
- "tailwindcss-config": "1.1.6-next.1"
187
+ "@weapp-tailwindcss/logger": "2.0.0",
188
+ "@weapp-tailwindcss/postcss": "3.0.0",
189
+ "@weapp-tailwindcss/reset": "0.1.1",
190
+ "@weapp-tailwindcss/shared": "2.0.0",
191
+ "tailwindcss-config": "2.0.0"
192
+ },
193
+ "devDependencies": {
194
+ "@vue/compiler-dom": "^3.5.35",
195
+ "@vue/compiler-sfc": "^3.5.35",
196
+ "htmlparser2": "12.0.0"
196
197
  },
197
198
  "scripts": {
198
199
  "dev": "tsdown --watch --sourcemap",
@@ -219,6 +220,7 @@
219
220
  "lint": "eslint .",
220
221
  "lint:fix": "eslint ./src --fix",
221
222
  "bench:vite-dev-hmr": "pnpm --filter @weapp-tailwindcss/scripts bench:vite-dev-hmr",
223
+ "watch-hmr:speed-report": "pnpm --filter @weapp-tailwindcss/scripts watch-hmr:speed-report",
222
224
  "test:watch-hmr": "pnpm --filter @weapp-tailwindcss/scripts test:watch-hmr"
223
225
  }
224
226
  }
@@ -1,3 +0,0 @@
1
- import type postcss from 'postcss';
2
- export declare function isDisplayP3MediaRule(atRule: postcss.AtRule): boolean;
3
- export declare function isDisplayP3Declaration(decl: postcss.Declaration): boolean;
@@ -1,4 +0,0 @@
1
- import type postcss from 'postcss';
2
- export declare function removeSpecificityPlaceholders(root: postcss.Root): void;
3
- export declare function removeUnsupportedBrowserSelectors(root: postcss.Root): void;
4
- export declare function removeDisplayP3Declarations(root: postcss.Root): void;
@@ -1,8 +0,0 @@
1
- import type postcss from 'postcss';
2
- export declare const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
3
- export declare const MINI_PROGRAM_PREFLIGHT_SELECTORS: Set<string>;
4
- export declare const MINI_PROGRAM_THEME_SCOPE_SELECTORS: Set<string>;
5
- export declare const SPECIFICITY_PLACEHOLDER_SUFFIXES: string[];
6
- export declare function normalizeSelector(selector: string): string;
7
- export declare function getRuleSelectors(rule: postcss.Rule): string[];
8
- export declare function isUnsupportedBrowserSelector(selector: string): boolean;
@@ -1,502 +0,0 @@
1
- const require_chunk = require("./chunk-8l464Juk.js");
2
- let node_module = require("node:module");
3
- let node_path = require("node:path");
4
- node_path = require_chunk.__toESM(node_path);
5
- let node_process = require("node:process");
6
- node_process = require_chunk.__toESM(node_process);
7
- let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
8
- let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
9
- let tailwindcss_patch = require("tailwindcss-patch");
10
- let node_fs = require("node:fs");
11
- let node_url = require("node:url");
12
- //#region src/context/workspace.ts
13
- const IGNORED_WORKSPACE_DIRS = new Set([
14
- "node_modules",
15
- ".git",
16
- ".hg",
17
- ".svn",
18
- ".turbo",
19
- ".output",
20
- ".next",
21
- "dist",
22
- "build"
23
- ]);
24
- function findWorkspaceRoot(startDir) {
25
- if (!startDir) return;
26
- let current = node_path.default.resolve(startDir);
27
- while (true) {
28
- if ((0, node_fs.existsSync)(node_path.default.join(current, "pnpm-workspace.yaml"))) return current;
29
- const parent = node_path.default.dirname(current);
30
- if (parent === current) return;
31
- current = parent;
32
- }
33
- }
34
- function findNearestPackageRoot(startDir) {
35
- if (!startDir) return;
36
- let current = node_path.default.resolve(startDir);
37
- while (true) {
38
- if ((0, node_fs.existsSync)(node_path.default.join(current, "package.json"))) return current;
39
- const parent = node_path.default.dirname(current);
40
- if (parent === current) return;
41
- current = parent;
42
- }
43
- }
44
- function findWorkspacePackageDir(rootDir, packageName) {
45
- const visited = /* @__PURE__ */ new Set();
46
- const queue = [node_path.default.resolve(rootDir)];
47
- while (queue.length > 0) {
48
- const current = queue.shift();
49
- const normalized = node_path.default.normalize(current);
50
- if (visited.has(normalized)) continue;
51
- visited.add(normalized);
52
- try {
53
- const pkgPath = node_path.default.join(normalized, "package.json");
54
- if ((0, node_fs.existsSync)(pkgPath)) {
55
- if (JSON.parse((0, node_fs.readFileSync)(pkgPath, "utf8"))?.name === packageName) return normalized;
56
- }
57
- } catch {}
58
- let entries;
59
- try {
60
- entries = (0, node_fs.readdirSync)(normalized, { withFileTypes: true });
61
- } catch {
62
- continue;
63
- }
64
- for (const entry of entries) {
65
- if (!entry.isDirectory() || IGNORED_WORKSPACE_DIRS.has(entry.name) || entry.isSymbolicLink?.()) continue;
66
- queue.push(node_path.default.join(normalized, entry.name));
67
- }
68
- }
69
- }
70
- //#endregion
71
- //#region src/tailwindcss/patcher-options.ts
72
- function resolveTailwindcssOptions(options) {
73
- return options?.tailwindcss ?? options?.tailwind;
74
- }
75
- function normalizeExtendLengthUnits(value) {
76
- if (value === false) return false;
77
- if (value === true) return { enabled: true };
78
- if (value && typeof value === "object") return {
79
- enabled: true,
80
- ...value
81
- };
82
- }
83
- function normalizeTailwindcssPatcherOptions(options) {
84
- return options;
85
- }
86
- //#endregion
87
- //#region src/tailwindcss/patcher-resolve.ts
88
- const GENERIC_RELATIVE_SPECIFIERS = [".", ".."];
89
- const DEFAULT_TAILWIND_CONFIG_SPECIFIERS = ["stubs/config.full.js", "defaultConfig.js"];
90
- const TAILWIND_CONFIG_FILES = [
91
- "tailwind.config.js",
92
- "tailwind.config.cjs",
93
- "tailwind.config.mjs",
94
- "tailwind.config.ts",
95
- "tailwind.config.cts",
96
- "tailwind.config.mts"
97
- ];
98
- function isPathSpecifier(specifier) {
99
- if (!specifier) return false;
100
- if (specifier.startsWith("file://")) return true;
101
- if (node_path.default.isAbsolute(specifier)) return true;
102
- return GENERIC_RELATIVE_SPECIFIERS.some((prefix) => specifier.startsWith(`${prefix}/`) || specifier.startsWith(`${prefix}\\`));
103
- }
104
- function resolveModuleFromPaths(specifier, paths) {
105
- if (!specifier || isPathSpecifier(specifier) || paths.length === 0) return;
106
- try {
107
- return (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href).resolve(specifier, { paths });
108
- } catch {
109
- return;
110
- }
111
- }
112
- function resolveTailwindConfigFallback(packageName, paths) {
113
- if (!packageName) return;
114
- for (const suffix of DEFAULT_TAILWIND_CONFIG_SPECIFIERS) {
115
- const resolved = resolveModuleFromPaths(`${packageName}/${suffix}`, paths);
116
- if (resolved) return resolved;
117
- }
118
- }
119
- function appendNodeModules(paths, dir) {
120
- if (!dir) return;
121
- const nodeModulesDir = node_path.default.join(dir, "node_modules");
122
- if ((0, node_fs.existsSync)(nodeModulesDir)) paths.add(nodeModulesDir);
123
- }
124
- function findTailwindConfig(searchRoots) {
125
- for (const root of searchRoots) for (const file of TAILWIND_CONFIG_FILES) {
126
- const candidate = node_path.default.resolve(root, file);
127
- if ((0, node_fs.existsSync)(candidate)) return candidate;
128
- }
129
- }
130
- function createDefaultResolvePaths(basedir) {
131
- const paths = /* @__PURE__ */ new Set();
132
- let fallbackCandidates = [];
133
- if (basedir) {
134
- const resolvedBase = node_path.default.resolve(basedir);
135
- appendNodeModules(paths, resolvedBase);
136
- fallbackCandidates.push(resolvedBase);
137
- const packageRoot = findNearestPackageRoot(resolvedBase);
138
- if (packageRoot) {
139
- appendNodeModules(paths, packageRoot);
140
- fallbackCandidates.push(packageRoot);
141
- }
142
- }
143
- const cwd = node_process.default.cwd();
144
- appendNodeModules(paths, cwd);
145
- try {
146
- const modulePath = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
147
- const candidate = (0, node_fs.existsSync)(modulePath) && !node_path.default.extname(modulePath) ? modulePath : node_path.default.dirname(modulePath);
148
- paths.add(candidate);
149
- } catch {
150
- paths.add(require("url").pathToFileURL(__filename).href);
151
- }
152
- if (paths.size === 0) {
153
- fallbackCandidates = fallbackCandidates.filter(Boolean);
154
- if (fallbackCandidates.length === 0) fallbackCandidates.push(cwd);
155
- for (const candidate of fallbackCandidates) paths.add(candidate);
156
- }
157
- return [...paths];
158
- }
159
- //#endregion
160
- //#region src/tailwindcss/version.ts
161
- function normalizeSupportedTailwindcssMajorVersion(version) {
162
- return version === 3 || version === 4 ? version : void 0;
163
- }
164
- function readPackageJson(packageJsonPath) {
165
- try {
166
- return JSON.parse((0, node_fs.readFileSync)(packageJsonPath, "utf8"));
167
- } catch {
168
- return;
169
- }
170
- }
171
- function findPackageJsonDeclaringPackage(packageName, base) {
172
- let current = node_path.default.resolve(base);
173
- while (true) {
174
- const pkgPath = node_path.default.join(current, "package.json");
175
- if ((0, node_fs.existsSync)(pkgPath)) {
176
- const pkg = readPackageJson(pkgPath);
177
- if (readDeclaredPackageVersion(packageName, pkg)) return pkgPath;
178
- if (pkg?.name !== "weapp-tailwindcss") return;
179
- }
180
- const parent = node_path.default.dirname(current);
181
- if (parent === current) return;
182
- current = parent;
183
- }
184
- }
185
- function readDeclaredPackageVersion(packageName, pkg) {
186
- return pkg?.dependencies?.[packageName] ?? pkg?.devDependencies?.[packageName] ?? pkg?.peerDependencies?.[packageName] ?? pkg?.optionalDependencies?.[packageName];
187
- }
188
- function readDeclaredPackageMajorVersion(version) {
189
- const match = version?.match(/(?:^|\D)([34])(?:\.|\b)/);
190
- return normalizeSupportedTailwindcssMajorVersion(match ? Number(match[1]) : void 0);
191
- }
192
- function readInstalledPackageMajorVersion(packageName, base) {
193
- const packageJsonPath = findPackageJsonDeclaringPackage(packageName, base);
194
- if (!packageJsonPath) return;
195
- const declaredVersion = readDeclaredPackageVersion(packageName, readPackageJson(packageJsonPath));
196
- if (!declaredVersion) return;
197
- try {
198
- const pkg = (0, node_module.createRequire)(packageJsonPath)(`${packageName}/package.json`);
199
- return normalizeSupportedTailwindcssMajorVersion(Number(pkg.version?.split(".")[0]));
200
- } catch {
201
- return readDeclaredPackageMajorVersion(declaredVersion);
202
- }
203
- }
204
- //#endregion
205
- //#region src/tailwindcss/patcher.ts
206
- function createFallbackTailwindcssPatcher() {
207
- return {
208
- packageInfo: {
209
- name: "tailwindcss",
210
- version: void 0,
211
- rootPath: "",
212
- packageJsonPath: "",
213
- packageJson: {}
214
- },
215
- majorVersion: 4,
216
- async getClassSet() {
217
- return /* @__PURE__ */ new Set();
218
- },
219
- async extract(_options) {
220
- return {
221
- classList: [],
222
- classSet: /* @__PURE__ */ new Set()
223
- };
224
- },
225
- async collectContentTokens() {
226
- return {
227
- entries: [],
228
- filesScanned: 0,
229
- sources: [],
230
- skippedFiles: []
231
- };
232
- }
233
- };
234
- }
235
- let hasLoggedMissingTailwind = false;
236
- const TAILWINDCSS_NOT_FOUND_RE = /tailwindcss not found/i;
237
- const UNABLE_TO_LOCATE_TAILWINDCSS_RE = /unable to locate tailwind css package/i;
238
- function isTailwindcssV4PackageName(packageName) {
239
- return packageName === "@tailwindcss/postcss" || packageName === "tailwindcss4" || Boolean(packageName && packageName.includes("tailwindcss4"));
240
- }
241
- function createTailwindcssPatcher(options) {
242
- const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
243
- const cache = { driver: "memory" };
244
- const normalizedBasedir = basedir ? node_path.default.resolve(basedir) : void 0;
245
- const cacheRoot = findNearestPackageRoot(normalizedBasedir) ?? normalizedBasedir ?? node_process.default.cwd();
246
- if (cacheDir) if (node_path.default.isAbsolute(cacheDir)) cache.dir = cacheDir;
247
- else if (normalizedBasedir) cache.dir = node_path.default.resolve(normalizedBasedir, cacheDir);
248
- else cache.dir = node_path.default.resolve(node_process.default.cwd(), cacheDir);
249
- else cache.dir = node_path.default.join(cacheRoot, "node_modules", ".cache", "tailwindcss-patch");
250
- if (normalizedBasedir) cache.cwd = normalizedBasedir;
251
- const resolvePaths = createDefaultResolvePaths(cache.cwd ?? normalizedBasedir ?? node_process.default.cwd());
252
- const normalizedUserOptions = normalizeTailwindcssPatcherOptions(tailwindcssPatcherOptions);
253
- const extendLengthUnits = normalizeExtendLengthUnits(supportCustomLengthUnitsPatch ?? true);
254
- const baseTailwindOptions = (0, _weapp_tailwindcss_shared.defuOverrideArray)(tailwindcss ?? {}, {
255
- cwd: normalizedBasedir,
256
- resolve: { paths: resolvePaths }
257
- });
258
- if (!baseTailwindOptions.packageName) baseTailwindOptions.packageName = "tailwindcss";
259
- if (!baseTailwindOptions.postcssPlugin) baseTailwindOptions.postcssPlugin = baseTailwindOptions.version === 4 || isTailwindcssV4PackageName(baseTailwindOptions.packageName) ? "@tailwindcss/postcss" : "tailwindcss";
260
- if (typeof baseTailwindOptions.postcssPlugin === "string") {
261
- const resolvedPlugin = resolveModuleFromPaths(baseTailwindOptions.postcssPlugin, resolvePaths);
262
- if (resolvedPlugin) baseTailwindOptions.postcssPlugin = resolvedPlugin;
263
- }
264
- const resolvedOptions = (0, _weapp_tailwindcss_shared.defuOverrideArray)(normalizedUserOptions ?? {}, {
265
- projectRoot: normalizedBasedir,
266
- cache,
267
- tailwindcss: baseTailwindOptions,
268
- apply: {
269
- exposeContext: true,
270
- extendLengthUnits
271
- }
272
- });
273
- const resolvedTailwindOptions = resolvedOptions.tailwindcss;
274
- if (resolvedTailwindOptions) {
275
- const existingResolve = resolvedTailwindOptions.resolve ?? {};
276
- const sourcePaths = Array.isArray(existingResolve.paths) && existingResolve.paths.length > 0 ? existingResolve.paths : resolvePaths;
277
- resolvedTailwindOptions.resolve = {
278
- ...existingResolve,
279
- paths: [...new Set(sourcePaths)]
280
- };
281
- _weapp_tailwindcss_logger.logger.debug("Tailwind resolve config %O", {
282
- packageName: resolvedTailwindOptions.packageName,
283
- version: resolvedTailwindOptions.version,
284
- resolve: resolvedTailwindOptions.resolve,
285
- cwd: resolvedTailwindOptions.cwd
286
- });
287
- if (typeof resolvedTailwindOptions.postcssPlugin === "string") {
288
- const resolvedPlugin = resolveModuleFromPaths(resolvedTailwindOptions.postcssPlugin, resolvedTailwindOptions.resolve?.paths ?? resolvePaths);
289
- if (resolvedPlugin) resolvedTailwindOptions.postcssPlugin = resolvedPlugin;
290
- }
291
- const searchRoots = /* @__PURE__ */ new Set();
292
- if (resolvedTailwindOptions.cwd) searchRoots.add(resolvedTailwindOptions.cwd);
293
- for (const resolvePath of resolvedTailwindOptions.resolve?.paths ?? []) {
294
- const parentDir = node_path.default.dirname(resolvePath);
295
- searchRoots.add(parentDir);
296
- }
297
- const configPath = findTailwindConfig(searchRoots);
298
- if (!resolvedTailwindOptions.config) if (configPath) resolvedTailwindOptions.config = configPath;
299
- else {
300
- const fallbackConfig = resolveTailwindConfigFallback(resolvedTailwindOptions.packageName, resolvedTailwindOptions.resolve.paths ?? resolvePaths);
301
- if (fallbackConfig) resolvedTailwindOptions.config = fallbackConfig;
302
- }
303
- if (!resolvedTailwindOptions.cwd && configPath) resolvedTailwindOptions.cwd = node_path.default.dirname(configPath);
304
- resolvedOptions.tailwindcss = resolvedTailwindOptions;
305
- }
306
- try {
307
- return new tailwindcss_patch.TailwindcssPatcher(resolvedOptions);
308
- } catch (error) {
309
- const searchPaths = resolvedOptions.tailwindcss?.resolve?.paths;
310
- if (error instanceof Error && TAILWINDCSS_NOT_FOUND_RE.test(error.message)) {
311
- if (!hasLoggedMissingTailwind) {
312
- _weapp_tailwindcss_logger.logger.warn("Tailwind CSS 未安装,已跳过 Tailwind 运行时能力。若需使用 Tailwind 能力,请安装 tailwindcss。");
313
- hasLoggedMissingTailwind = true;
314
- }
315
- return createFallbackTailwindcssPatcher();
316
- }
317
- if (error instanceof Error && UNABLE_TO_LOCATE_TAILWINDCSS_RE.test(error.message)) _weapp_tailwindcss_logger.logger.error("无法定位 Tailwind CSS 包 \"%s\",已尝试路径: %O", resolvedOptions.tailwindcss?.packageName, searchPaths);
318
- throw error;
319
- }
320
- }
321
- //#endregion
322
- //#region src/tailwindcss/runtime/cache.ts
323
- const runtimeClassSetCache = /* @__PURE__ */ new WeakMap();
324
- const runtimeFileSignatureCache = /* @__PURE__ */ new Map();
325
- let runtimeFileSignatureCacheClearTimer;
326
- const runtimeSignaturePatchersSymbol = Symbol.for("weapp-tailwindcss.runtimeSignaturePatchers");
327
- function getCacheEntry(twPatcher) {
328
- let entry = runtimeClassSetCache.get(twPatcher);
329
- if (!entry) {
330
- entry = {};
331
- runtimeClassSetCache.set(twPatcher, entry);
332
- }
333
- return entry;
334
- }
335
- function scheduleRuntimeConfigSignatureCacheClear() {
336
- if (runtimeFileSignatureCacheClearTimer) return;
337
- runtimeFileSignatureCacheClearTimer = setTimeout(() => {
338
- runtimeFileSignatureCache.clear();
339
- runtimeFileSignatureCacheClearTimer = void 0;
340
- }, 0);
341
- runtimeFileSignatureCacheClearTimer.unref?.();
342
- }
343
- function getFileSignature(filePath) {
344
- const cached = runtimeFileSignatureCache.get(filePath);
345
- if (cached !== void 0) return cached;
346
- let signature;
347
- try {
348
- const stats = (0, node_fs.statSync)(filePath);
349
- signature = `${filePath}:${stats.size}:${stats.mtimeMs}`;
350
- } catch {
351
- signature = `${filePath}:missing`;
352
- }
353
- runtimeFileSignatureCache.set(filePath, signature);
354
- scheduleRuntimeConfigSignatureCacheClear();
355
- return signature;
356
- }
357
- function getTailwindTrackedFiles(twPatcher) {
358
- const tailwindOptions = resolveTailwindcssOptions(twPatcher.options);
359
- const tracked = /* @__PURE__ */ new Set();
360
- const configPath = tailwindOptions?.config;
361
- if (typeof configPath === "string" && configPath.length > 0) tracked.add(configPath);
362
- for (const entry of tailwindOptions?.v4?.cssEntries ?? []) if (typeof entry === "string" && entry.length > 0) tracked.add(entry);
363
- for (const source of tailwindOptions?.v4?.cssSources ?? []) {
364
- if (typeof source.file === "string" && source.file.length > 0) tracked.add(source.file);
365
- for (const dependency of source.dependencies ?? []) if (typeof dependency === "string" && dependency.length > 0) tracked.add(dependency);
366
- }
367
- return tracked;
368
- }
369
- function normalizeSignatureValue(value) {
370
- if (value == null) return "null";
371
- if (typeof value === "string") return value;
372
- if (typeof value === "number" || typeof value === "boolean") return String(value);
373
- if (Array.isArray(value)) return `[${value.map((item) => normalizeSignatureValue(item)).join(",")}]`;
374
- if (typeof value === "object") return `{${Object.entries(value).filter(([, item]) => item !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key, item]) => `${key}:${normalizeSignatureValue(item)}`).join(",")}}`;
375
- return String(value);
376
- }
377
- function readOptionalProperty(value, key) {
378
- if (typeof value !== "object" || value === null || !(key in value)) return;
379
- return value[key];
380
- }
381
- function getTailwindOptionsSignature(twPatcher) {
382
- const options = twPatcher.options;
383
- const tailwindOptions = resolveTailwindcssOptions(options);
384
- return normalizeSignatureValue({
385
- projectRoot: options?.projectRoot,
386
- packageName: tailwindOptions?.packageName,
387
- versionHint: readOptionalProperty(tailwindOptions, "versionHint"),
388
- cwd: tailwindOptions?.cwd,
389
- config: tailwindOptions?.config,
390
- v2: tailwindOptions?.v2,
391
- v3: tailwindOptions?.v3,
392
- v4: {
393
- base: tailwindOptions?.v4?.base,
394
- configuredBase: readOptionalProperty(tailwindOptions?.v4, "configuredBase"),
395
- css: tailwindOptions?.v4?.css,
396
- cssEntries: tailwindOptions?.v4?.cssEntries,
397
- cssSources: tailwindOptions?.v4?.cssSources,
398
- hasUserDefinedSources: readOptionalProperty(tailwindOptions?.v4, "hasUserDefinedSources"),
399
- sources: tailwindOptions?.v4?.sources
400
- }
401
- });
402
- }
403
- function getRuntimeTargetSignature(twPatcher) {
404
- const packageInfo = twPatcher.packageInfo;
405
- return [
406
- packageInfo?.name ?? "missing",
407
- packageInfo?.rootPath ?? "missing",
408
- packageInfo?.version ?? "unknown",
409
- twPatcher.majorVersion ?? "unknown",
410
- getTailwindOptionsSignature(twPatcher)
411
- ].join(":");
412
- }
413
- function getNestedPatchers(twPatcher) {
414
- const nested = twPatcher[runtimeSignaturePatchersSymbol];
415
- return Array.isArray(nested) && nested.length > 0 ? nested : void 0;
416
- }
417
- function getOwnRuntimeClassSetSignature(twPatcher) {
418
- const trackedFiles = [...getTailwindTrackedFiles(twPatcher)].sort((a, b) => a.localeCompare(b)).map(getFileSignature);
419
- return `${trackedFiles.length > 0 ? trackedFiles.join("|") : "files:missing"}|runtime:${getRuntimeTargetSignature(twPatcher)}`;
420
- }
421
- function invalidateRuntimeClassSet(twPatcher) {
422
- if (!twPatcher) return;
423
- const nestedPatchers = getNestedPatchers(twPatcher);
424
- if (nestedPatchers) for (const patcher of nestedPatchers) invalidateRuntimeClassSet(patcher);
425
- for (const trackedFile of getTailwindTrackedFiles(twPatcher)) runtimeFileSignatureCache.delete(trackedFile);
426
- runtimeClassSetCache.delete(twPatcher);
427
- }
428
- function getRuntimeClassSetCacheEntry(twPatcher) {
429
- return getCacheEntry(twPatcher);
430
- }
431
- function getRuntimeClassSetSignature(twPatcher) {
432
- const nestedPatchers = getNestedPatchers(twPatcher);
433
- if (nestedPatchers) return nestedPatchers.map(getOwnRuntimeClassSetSignature).sort((a, b) => a.localeCompare(b)).join("||");
434
- return getOwnRuntimeClassSetSignature(twPatcher);
435
- }
436
- //#endregion
437
- Object.defineProperty(exports, "createTailwindcssPatcher", {
438
- enumerable: true,
439
- get: function() {
440
- return createTailwindcssPatcher;
441
- }
442
- });
443
- Object.defineProperty(exports, "findNearestPackageRoot", {
444
- enumerable: true,
445
- get: function() {
446
- return findNearestPackageRoot;
447
- }
448
- });
449
- Object.defineProperty(exports, "findTailwindConfig", {
450
- enumerable: true,
451
- get: function() {
452
- return findTailwindConfig;
453
- }
454
- });
455
- Object.defineProperty(exports, "findWorkspacePackageDir", {
456
- enumerable: true,
457
- get: function() {
458
- return findWorkspacePackageDir;
459
- }
460
- });
461
- Object.defineProperty(exports, "findWorkspaceRoot", {
462
- enumerable: true,
463
- get: function() {
464
- return findWorkspaceRoot;
465
- }
466
- });
467
- Object.defineProperty(exports, "getRuntimeClassSetCacheEntry", {
468
- enumerable: true,
469
- get: function() {
470
- return getRuntimeClassSetCacheEntry;
471
- }
472
- });
473
- Object.defineProperty(exports, "getRuntimeClassSetSignature", {
474
- enumerable: true,
475
- get: function() {
476
- return getRuntimeClassSetSignature;
477
- }
478
- });
479
- Object.defineProperty(exports, "invalidateRuntimeClassSet", {
480
- enumerable: true,
481
- get: function() {
482
- return invalidateRuntimeClassSet;
483
- }
484
- });
485
- Object.defineProperty(exports, "readInstalledPackageMajorVersion", {
486
- enumerable: true,
487
- get: function() {
488
- return readInstalledPackageMajorVersion;
489
- }
490
- });
491
- Object.defineProperty(exports, "resolveTailwindcssOptions", {
492
- enumerable: true,
493
- get: function() {
494
- return resolveTailwindcssOptions;
495
- }
496
- });
497
- Object.defineProperty(exports, "runtimeSignaturePatchersSymbol", {
498
- enumerable: true,
499
- get: function() {
500
- return runtimeSignaturePatchersSymbol;
501
- }
502
- });