weapp-tailwindcss 5.0.0-next.9 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/README.md +2 -2
  2. package/dist/auto-DEHRmEAx.mjs +200 -0
  3. package/dist/auto-dPpsm6FB.js +238 -0
  4. package/dist/bundle-state-CnaJxkFY.mjs +413 -0
  5. package/dist/bundle-state-DgGEhk_z.js +529 -0
  6. package/dist/bundlers/shared/cache.d.ts +9 -7
  7. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +1 -2
  8. package/dist/bundlers/shared/css-cleanup.d.ts +1 -3
  9. package/dist/bundlers/shared/css-imports.d.ts +3 -3
  10. package/dist/bundlers/shared/generated-css-marker.d.ts +3 -0
  11. package/dist/bundlers/shared/generator-css/directives.d.ts +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--0-ekuVO.js +92 -0
  69. package/dist/generator-B76ovqsv.mjs +67 -0
  70. package/dist/generator.js +12 -12
  71. package/dist/generator.mjs +2 -1
  72. package/dist/gulp.js +163 -40
  73. package/dist/gulp.mjs +155 -32
  74. package/dist/incremental-runtime-class-set-CN6K_97P.js +2366 -0
  75. package/dist/incremental-runtime-class-set-x10M9bn_.mjs +2291 -0
  76. package/dist/index.d.ts +2 -1
  77. package/dist/index.js +17 -5
  78. package/dist/index.mjs +6 -5
  79. package/dist/js/babel/cache-options.d.ts +3 -0
  80. package/dist/js/babel/parse.d.ts +7 -4
  81. package/dist/js/precheck.d.ts +2 -2
  82. package/dist/js/replacement-cache.d.ts +5 -0
  83. package/dist/postcss-C7BMYpEF.mjs +169 -0
  84. package/dist/{postcss-w48mGIhe.mjs → postcss-CR9UCaIK.mjs} +54 -114
  85. package/dist/postcss-CiYLsqZn.js +192 -0
  86. package/dist/{postcss-QIXwT40c.js → postcss-hYimKoN_.js} +60 -121
  87. package/dist/postcss-html-transform.js +1 -1
  88. package/dist/postcss.js +1 -1
  89. package/dist/postcss.mjs +1 -1
  90. package/dist/precheck-BrNwLG2e.mjs +4716 -0
  91. package/dist/precheck-DPtJjZmV.js +4842 -0
  92. package/dist/presets/index.d.ts +1 -0
  93. package/dist/presets/uni-app-x.d.ts +1 -0
  94. package/dist/presets.js +27 -13
  95. package/dist/presets.mjs +25 -13
  96. package/dist/reset.js +1 -1
  97. package/dist/runtime-registry-DpcR3IHI.js +5496 -0
  98. package/dist/shared/mpx.d.ts +1 -0
  99. package/dist/source-candidates-DN1mihlU.mjs +322 -0
  100. package/dist/source-candidates-DSxme_O2.js +335 -0
  101. package/dist/tailwindcss/miniprogram.d.ts +1 -5
  102. package/dist/tailwindcss/remove-unsupported-css.d.ts +1 -2
  103. package/dist/tailwindcss/runtime/cache.d.ts +4 -3
  104. package/dist/tailwindcss/runtime.d.ts +9 -9
  105. package/dist/tailwindcss/source-scan.d.ts +35 -0
  106. package/dist/tailwindcss/v3-engine/types.d.ts +19 -14
  107. package/dist/tailwindcss/v4/css-entries.d.ts +2 -2
  108. package/dist/tailwindcss/v4/patcher.d.ts +1 -1
  109. package/dist/tailwindcss/v4-engine/source.d.ts +2 -2
  110. package/dist/tailwindcss/v4-engine/types.d.ts +18 -5
  111. package/dist/{tailwindcss-C5IgPlQ0.mjs → tailwindcss-DWtPieNE.mjs} +72 -60
  112. package/dist/{tailwindcss-Bu-RWIHx.js → tailwindcss-glCm_d3H.js} +81 -69
  113. package/dist/typedoc.export.d.ts +1 -1
  114. package/dist/types/index.d.ts +51 -41
  115. package/dist/types/shared.d.ts +3 -0
  116. package/dist/types/typedoc-tailwindcss-patch.d.ts +67 -0
  117. package/dist/types/user-defined-options/general.d.ts +25 -22
  118. package/dist/types/user-defined-options/important.d.ts +32 -27
  119. package/dist/types/user-defined-options/lifecycle.d.ts +4 -4
  120. package/dist/types/user-defined-options/matcher.d.ts +6 -6
  121. package/dist/unocss/index.d.ts +2 -0
  122. package/dist/utils/object.d.ts +9 -0
  123. package/dist/utils/options.d.ts +2 -0
  124. package/dist/utils/regex.d.ts +1 -0
  125. package/dist/{utils-BiShvil9.js → utils-D7Ygohep.js} +2 -2
  126. package/dist/{utils-Btw1iOVV.mjs → utils-DsaS975I.mjs} +1 -1
  127. package/dist/v3-engine-D3BMLVAN.js +3712 -0
  128. package/dist/v3-engine-DCxNPBVs.mjs +3417 -0
  129. package/dist/vite-DOprpdH-.mjs +24493 -0
  130. package/dist/vite-Ec0uX6kF.js +24507 -0
  131. package/dist/vite.js +1 -1
  132. package/dist/vite.mjs +1 -1
  133. package/dist/weapp-tw-css-import-rewrite-loader.js +5444 -22
  134. package/dist/weapp-tw-runtime-classset-loader.js +32 -9
  135. package/dist/{webpack-BzN2ly34.js → webpack-Ccohlg3A.js} +341 -96
  136. package/dist/{webpack-DJazm5sT.mjs → webpack-DFlZcqAU.mjs} +323 -79
  137. package/dist/webpack.d.ts +1 -3
  138. package/dist/webpack.js +3 -4
  139. package/dist/webpack.mjs +2 -2
  140. package/dist/wxml/utils/codegen/legacy-visitor.d.ts +2 -4
  141. package/package.json +22 -20
  142. package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +0 -3
  143. package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +0 -4
  144. package/dist/bundlers/shared/css-cleanup/selectors.d.ts +0 -8
  145. package/dist/cache-BVAiJV3J.js +0 -502
  146. package/dist/cache-CHs4DXui.mjs +0 -434
  147. package/dist/constants-BoB_6lFw.js +0 -73
  148. package/dist/constants-E_loJC49.mjs +0 -44
  149. package/dist/generator-DKkhJbOg.js +0 -1531
  150. package/dist/generator-UBmfduYg.mjs +0 -1432
  151. package/dist/generator-css-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
@@ -1,434 +0,0 @@
1
- import { createRequire } from "node:module";
2
- import path from "node:path";
3
- import process from "node:process";
4
- import { logger } from "@weapp-tailwindcss/logger";
5
- import { defuOverrideArray } from "@weapp-tailwindcss/shared";
6
- import { TailwindcssPatcher } from "tailwindcss-patch";
7
- import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
8
- import { fileURLToPath } from "node:url";
9
- //#region src/context/workspace.ts
10
- const IGNORED_WORKSPACE_DIRS = new Set([
11
- "node_modules",
12
- ".git",
13
- ".hg",
14
- ".svn",
15
- ".turbo",
16
- ".output",
17
- ".next",
18
- "dist",
19
- "build"
20
- ]);
21
- function findWorkspaceRoot(startDir) {
22
- if (!startDir) return;
23
- let current = path.resolve(startDir);
24
- while (true) {
25
- if (existsSync(path.join(current, "pnpm-workspace.yaml"))) return current;
26
- const parent = path.dirname(current);
27
- if (parent === current) return;
28
- current = parent;
29
- }
30
- }
31
- function findNearestPackageRoot(startDir) {
32
- if (!startDir) return;
33
- let current = path.resolve(startDir);
34
- while (true) {
35
- if (existsSync(path.join(current, "package.json"))) return current;
36
- const parent = path.dirname(current);
37
- if (parent === current) return;
38
- current = parent;
39
- }
40
- }
41
- function findWorkspacePackageDir(rootDir, packageName) {
42
- const visited = /* @__PURE__ */ new Set();
43
- const queue = [path.resolve(rootDir)];
44
- while (queue.length > 0) {
45
- const current = queue.shift();
46
- const normalized = path.normalize(current);
47
- if (visited.has(normalized)) continue;
48
- visited.add(normalized);
49
- try {
50
- const pkgPath = path.join(normalized, "package.json");
51
- if (existsSync(pkgPath)) {
52
- if (JSON.parse(readFileSync(pkgPath, "utf8"))?.name === packageName) return normalized;
53
- }
54
- } catch {}
55
- let entries;
56
- try {
57
- entries = readdirSync(normalized, { withFileTypes: true });
58
- } catch {
59
- continue;
60
- }
61
- for (const entry of entries) {
62
- if (!entry.isDirectory() || IGNORED_WORKSPACE_DIRS.has(entry.name) || entry.isSymbolicLink?.()) continue;
63
- queue.push(path.join(normalized, entry.name));
64
- }
65
- }
66
- }
67
- //#endregion
68
- //#region src/tailwindcss/patcher-options.ts
69
- function resolveTailwindcssOptions(options) {
70
- return options?.tailwindcss ?? options?.tailwind;
71
- }
72
- function normalizeExtendLengthUnits(value) {
73
- if (value === false) return false;
74
- if (value === true) return { enabled: true };
75
- if (value && typeof value === "object") return {
76
- enabled: true,
77
- ...value
78
- };
79
- }
80
- function normalizeTailwindcssPatcherOptions(options) {
81
- return options;
82
- }
83
- //#endregion
84
- //#region src/tailwindcss/patcher-resolve.ts
85
- const GENERIC_RELATIVE_SPECIFIERS = [".", ".."];
86
- const DEFAULT_TAILWIND_CONFIG_SPECIFIERS = ["stubs/config.full.js", "defaultConfig.js"];
87
- const TAILWIND_CONFIG_FILES = [
88
- "tailwind.config.js",
89
- "tailwind.config.cjs",
90
- "tailwind.config.mjs",
91
- "tailwind.config.ts",
92
- "tailwind.config.cts",
93
- "tailwind.config.mts"
94
- ];
95
- function isPathSpecifier(specifier) {
96
- if (!specifier) return false;
97
- if (specifier.startsWith("file://")) return true;
98
- if (path.isAbsolute(specifier)) return true;
99
- return GENERIC_RELATIVE_SPECIFIERS.some((prefix) => specifier.startsWith(`${prefix}/`) || specifier.startsWith(`${prefix}\\`));
100
- }
101
- function resolveModuleFromPaths(specifier, paths) {
102
- if (!specifier || isPathSpecifier(specifier) || paths.length === 0) return;
103
- try {
104
- return createRequire(import.meta.url).resolve(specifier, { paths });
105
- } catch {
106
- return;
107
- }
108
- }
109
- function resolveTailwindConfigFallback(packageName, paths) {
110
- if (!packageName) return;
111
- for (const suffix of DEFAULT_TAILWIND_CONFIG_SPECIFIERS) {
112
- const resolved = resolveModuleFromPaths(`${packageName}/${suffix}`, paths);
113
- if (resolved) return resolved;
114
- }
115
- }
116
- function appendNodeModules(paths, dir) {
117
- if (!dir) return;
118
- const nodeModulesDir = path.join(dir, "node_modules");
119
- if (existsSync(nodeModulesDir)) paths.add(nodeModulesDir);
120
- }
121
- function findTailwindConfig(searchRoots) {
122
- for (const root of searchRoots) for (const file of TAILWIND_CONFIG_FILES) {
123
- const candidate = path.resolve(root, file);
124
- if (existsSync(candidate)) return candidate;
125
- }
126
- }
127
- function createDefaultResolvePaths(basedir) {
128
- const paths = /* @__PURE__ */ new Set();
129
- let fallbackCandidates = [];
130
- if (basedir) {
131
- const resolvedBase = path.resolve(basedir);
132
- appendNodeModules(paths, resolvedBase);
133
- fallbackCandidates.push(resolvedBase);
134
- const packageRoot = findNearestPackageRoot(resolvedBase);
135
- if (packageRoot) {
136
- appendNodeModules(paths, packageRoot);
137
- fallbackCandidates.push(packageRoot);
138
- }
139
- }
140
- const cwd = process.cwd();
141
- appendNodeModules(paths, cwd);
142
- try {
143
- const modulePath = fileURLToPath(import.meta.url);
144
- const candidate = existsSync(modulePath) && !path.extname(modulePath) ? modulePath : path.dirname(modulePath);
145
- paths.add(candidate);
146
- } catch {
147
- paths.add(import.meta.url);
148
- }
149
- if (paths.size === 0) {
150
- fallbackCandidates = fallbackCandidates.filter(Boolean);
151
- if (fallbackCandidates.length === 0) fallbackCandidates.push(cwd);
152
- for (const candidate of fallbackCandidates) paths.add(candidate);
153
- }
154
- return [...paths];
155
- }
156
- //#endregion
157
- //#region src/tailwindcss/version.ts
158
- function normalizeSupportedTailwindcssMajorVersion(version) {
159
- return version === 3 || version === 4 ? version : void 0;
160
- }
161
- function readPackageJson(packageJsonPath) {
162
- try {
163
- return JSON.parse(readFileSync(packageJsonPath, "utf8"));
164
- } catch {
165
- return;
166
- }
167
- }
168
- function findPackageJsonDeclaringPackage(packageName, base) {
169
- let current = path.resolve(base);
170
- while (true) {
171
- const pkgPath = path.join(current, "package.json");
172
- if (existsSync(pkgPath)) {
173
- const pkg = readPackageJson(pkgPath);
174
- if (readDeclaredPackageVersion(packageName, pkg)) return pkgPath;
175
- if (pkg?.name !== "weapp-tailwindcss") return;
176
- }
177
- const parent = path.dirname(current);
178
- if (parent === current) return;
179
- current = parent;
180
- }
181
- }
182
- function readDeclaredPackageVersion(packageName, pkg) {
183
- return pkg?.dependencies?.[packageName] ?? pkg?.devDependencies?.[packageName] ?? pkg?.peerDependencies?.[packageName] ?? pkg?.optionalDependencies?.[packageName];
184
- }
185
- function readDeclaredPackageMajorVersion(version) {
186
- const match = version?.match(/(?:^|\D)([34])(?:\.|\b)/);
187
- return normalizeSupportedTailwindcssMajorVersion(match ? Number(match[1]) : void 0);
188
- }
189
- function readInstalledPackageMajorVersion(packageName, base) {
190
- const packageJsonPath = findPackageJsonDeclaringPackage(packageName, base);
191
- if (!packageJsonPath) return;
192
- const declaredVersion = readDeclaredPackageVersion(packageName, readPackageJson(packageJsonPath));
193
- if (!declaredVersion) return;
194
- try {
195
- const pkg = createRequire(packageJsonPath)(`${packageName}/package.json`);
196
- return normalizeSupportedTailwindcssMajorVersion(Number(pkg.version?.split(".")[0]));
197
- } catch {
198
- return readDeclaredPackageMajorVersion(declaredVersion);
199
- }
200
- }
201
- //#endregion
202
- //#region src/tailwindcss/patcher.ts
203
- function createFallbackTailwindcssPatcher() {
204
- return {
205
- packageInfo: {
206
- name: "tailwindcss",
207
- version: void 0,
208
- rootPath: "",
209
- packageJsonPath: "",
210
- packageJson: {}
211
- },
212
- majorVersion: 4,
213
- async getClassSet() {
214
- return /* @__PURE__ */ new Set();
215
- },
216
- async extract(_options) {
217
- return {
218
- classList: [],
219
- classSet: /* @__PURE__ */ new Set()
220
- };
221
- },
222
- async collectContentTokens() {
223
- return {
224
- entries: [],
225
- filesScanned: 0,
226
- sources: [],
227
- skippedFiles: []
228
- };
229
- }
230
- };
231
- }
232
- let hasLoggedMissingTailwind = false;
233
- const TAILWINDCSS_NOT_FOUND_RE = /tailwindcss not found/i;
234
- const UNABLE_TO_LOCATE_TAILWINDCSS_RE = /unable to locate tailwind css package/i;
235
- function isTailwindcssV4PackageName(packageName) {
236
- return packageName === "@tailwindcss/postcss" || packageName === "tailwindcss4" || Boolean(packageName && packageName.includes("tailwindcss4"));
237
- }
238
- function createTailwindcssPatcher(options) {
239
- const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
240
- const cache = { driver: "memory" };
241
- const normalizedBasedir = basedir ? path.resolve(basedir) : void 0;
242
- const cacheRoot = findNearestPackageRoot(normalizedBasedir) ?? normalizedBasedir ?? process.cwd();
243
- if (cacheDir) if (path.isAbsolute(cacheDir)) cache.dir = cacheDir;
244
- else if (normalizedBasedir) cache.dir = path.resolve(normalizedBasedir, cacheDir);
245
- else cache.dir = path.resolve(process.cwd(), cacheDir);
246
- else cache.dir = path.join(cacheRoot, "node_modules", ".cache", "tailwindcss-patch");
247
- if (normalizedBasedir) cache.cwd = normalizedBasedir;
248
- const resolvePaths = createDefaultResolvePaths(cache.cwd ?? normalizedBasedir ?? process.cwd());
249
- const normalizedUserOptions = normalizeTailwindcssPatcherOptions(tailwindcssPatcherOptions);
250
- const extendLengthUnits = normalizeExtendLengthUnits(supportCustomLengthUnitsPatch ?? true);
251
- const baseTailwindOptions = defuOverrideArray(tailwindcss ?? {}, {
252
- cwd: normalizedBasedir,
253
- resolve: { paths: resolvePaths }
254
- });
255
- if (!baseTailwindOptions.packageName) baseTailwindOptions.packageName = "tailwindcss";
256
- if (!baseTailwindOptions.postcssPlugin) baseTailwindOptions.postcssPlugin = baseTailwindOptions.version === 4 || isTailwindcssV4PackageName(baseTailwindOptions.packageName) ? "@tailwindcss/postcss" : "tailwindcss";
257
- if (typeof baseTailwindOptions.postcssPlugin === "string") {
258
- const resolvedPlugin = resolveModuleFromPaths(baseTailwindOptions.postcssPlugin, resolvePaths);
259
- if (resolvedPlugin) baseTailwindOptions.postcssPlugin = resolvedPlugin;
260
- }
261
- const resolvedOptions = defuOverrideArray(normalizedUserOptions ?? {}, {
262
- projectRoot: normalizedBasedir,
263
- cache,
264
- tailwindcss: baseTailwindOptions,
265
- apply: {
266
- exposeContext: true,
267
- extendLengthUnits
268
- }
269
- });
270
- const resolvedTailwindOptions = resolvedOptions.tailwindcss;
271
- if (resolvedTailwindOptions) {
272
- const existingResolve = resolvedTailwindOptions.resolve ?? {};
273
- const sourcePaths = Array.isArray(existingResolve.paths) && existingResolve.paths.length > 0 ? existingResolve.paths : resolvePaths;
274
- resolvedTailwindOptions.resolve = {
275
- ...existingResolve,
276
- paths: [...new Set(sourcePaths)]
277
- };
278
- logger.debug("Tailwind resolve config %O", {
279
- packageName: resolvedTailwindOptions.packageName,
280
- version: resolvedTailwindOptions.version,
281
- resolve: resolvedTailwindOptions.resolve,
282
- cwd: resolvedTailwindOptions.cwd
283
- });
284
- if (typeof resolvedTailwindOptions.postcssPlugin === "string") {
285
- const resolvedPlugin = resolveModuleFromPaths(resolvedTailwindOptions.postcssPlugin, resolvedTailwindOptions.resolve?.paths ?? resolvePaths);
286
- if (resolvedPlugin) resolvedTailwindOptions.postcssPlugin = resolvedPlugin;
287
- }
288
- const searchRoots = /* @__PURE__ */ new Set();
289
- if (resolvedTailwindOptions.cwd) searchRoots.add(resolvedTailwindOptions.cwd);
290
- for (const resolvePath of resolvedTailwindOptions.resolve?.paths ?? []) {
291
- const parentDir = path.dirname(resolvePath);
292
- searchRoots.add(parentDir);
293
- }
294
- const configPath = findTailwindConfig(searchRoots);
295
- if (!resolvedTailwindOptions.config) if (configPath) resolvedTailwindOptions.config = configPath;
296
- else {
297
- const fallbackConfig = resolveTailwindConfigFallback(resolvedTailwindOptions.packageName, resolvedTailwindOptions.resolve.paths ?? resolvePaths);
298
- if (fallbackConfig) resolvedTailwindOptions.config = fallbackConfig;
299
- }
300
- if (!resolvedTailwindOptions.cwd && configPath) resolvedTailwindOptions.cwd = path.dirname(configPath);
301
- resolvedOptions.tailwindcss = resolvedTailwindOptions;
302
- }
303
- try {
304
- return new TailwindcssPatcher(resolvedOptions);
305
- } catch (error) {
306
- const searchPaths = resolvedOptions.tailwindcss?.resolve?.paths;
307
- if (error instanceof Error && TAILWINDCSS_NOT_FOUND_RE.test(error.message)) {
308
- if (!hasLoggedMissingTailwind) {
309
- logger.warn("Tailwind CSS 未安装,已跳过 Tailwind 运行时能力。若需使用 Tailwind 能力,请安装 tailwindcss。");
310
- hasLoggedMissingTailwind = true;
311
- }
312
- return createFallbackTailwindcssPatcher();
313
- }
314
- if (error instanceof Error && UNABLE_TO_LOCATE_TAILWINDCSS_RE.test(error.message)) logger.error("无法定位 Tailwind CSS 包 \"%s\",已尝试路径: %O", resolvedOptions.tailwindcss?.packageName, searchPaths);
315
- throw error;
316
- }
317
- }
318
- //#endregion
319
- //#region src/tailwindcss/runtime/cache.ts
320
- const runtimeClassSetCache = /* @__PURE__ */ new WeakMap();
321
- const runtimeFileSignatureCache = /* @__PURE__ */ new Map();
322
- let runtimeFileSignatureCacheClearTimer;
323
- const runtimeSignaturePatchersSymbol = Symbol.for("weapp-tailwindcss.runtimeSignaturePatchers");
324
- function getCacheEntry(twPatcher) {
325
- let entry = runtimeClassSetCache.get(twPatcher);
326
- if (!entry) {
327
- entry = {};
328
- runtimeClassSetCache.set(twPatcher, entry);
329
- }
330
- return entry;
331
- }
332
- function scheduleRuntimeConfigSignatureCacheClear() {
333
- if (runtimeFileSignatureCacheClearTimer) return;
334
- runtimeFileSignatureCacheClearTimer = setTimeout(() => {
335
- runtimeFileSignatureCache.clear();
336
- runtimeFileSignatureCacheClearTimer = void 0;
337
- }, 0);
338
- runtimeFileSignatureCacheClearTimer.unref?.();
339
- }
340
- function getFileSignature(filePath) {
341
- const cached = runtimeFileSignatureCache.get(filePath);
342
- if (cached !== void 0) return cached;
343
- let signature;
344
- try {
345
- const stats = statSync(filePath);
346
- signature = `${filePath}:${stats.size}:${stats.mtimeMs}`;
347
- } catch {
348
- signature = `${filePath}:missing`;
349
- }
350
- runtimeFileSignatureCache.set(filePath, signature);
351
- scheduleRuntimeConfigSignatureCacheClear();
352
- return signature;
353
- }
354
- function getTailwindTrackedFiles(twPatcher) {
355
- const tailwindOptions = resolveTailwindcssOptions(twPatcher.options);
356
- const tracked = /* @__PURE__ */ new Set();
357
- const configPath = tailwindOptions?.config;
358
- if (typeof configPath === "string" && configPath.length > 0) tracked.add(configPath);
359
- for (const entry of tailwindOptions?.v4?.cssEntries ?? []) if (typeof entry === "string" && entry.length > 0) tracked.add(entry);
360
- for (const source of tailwindOptions?.v4?.cssSources ?? []) {
361
- if (typeof source.file === "string" && source.file.length > 0) tracked.add(source.file);
362
- for (const dependency of source.dependencies ?? []) if (typeof dependency === "string" && dependency.length > 0) tracked.add(dependency);
363
- }
364
- return tracked;
365
- }
366
- function normalizeSignatureValue(value) {
367
- if (value == null) return "null";
368
- if (typeof value === "string") return value;
369
- if (typeof value === "number" || typeof value === "boolean") return String(value);
370
- if (Array.isArray(value)) return `[${value.map((item) => normalizeSignatureValue(item)).join(",")}]`;
371
- 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(",")}}`;
372
- return String(value);
373
- }
374
- function readOptionalProperty(value, key) {
375
- if (typeof value !== "object" || value === null || !(key in value)) return;
376
- return value[key];
377
- }
378
- function getTailwindOptionsSignature(twPatcher) {
379
- const options = twPatcher.options;
380
- const tailwindOptions = resolveTailwindcssOptions(options);
381
- return normalizeSignatureValue({
382
- projectRoot: options?.projectRoot,
383
- packageName: tailwindOptions?.packageName,
384
- versionHint: readOptionalProperty(tailwindOptions, "versionHint"),
385
- cwd: tailwindOptions?.cwd,
386
- config: tailwindOptions?.config,
387
- v2: tailwindOptions?.v2,
388
- v3: tailwindOptions?.v3,
389
- v4: {
390
- base: tailwindOptions?.v4?.base,
391
- configuredBase: readOptionalProperty(tailwindOptions?.v4, "configuredBase"),
392
- css: tailwindOptions?.v4?.css,
393
- cssEntries: tailwindOptions?.v4?.cssEntries,
394
- cssSources: tailwindOptions?.v4?.cssSources,
395
- hasUserDefinedSources: readOptionalProperty(tailwindOptions?.v4, "hasUserDefinedSources"),
396
- sources: tailwindOptions?.v4?.sources
397
- }
398
- });
399
- }
400
- function getRuntimeTargetSignature(twPatcher) {
401
- const packageInfo = twPatcher.packageInfo;
402
- return [
403
- packageInfo?.name ?? "missing",
404
- packageInfo?.rootPath ?? "missing",
405
- packageInfo?.version ?? "unknown",
406
- twPatcher.majorVersion ?? "unknown",
407
- getTailwindOptionsSignature(twPatcher)
408
- ].join(":");
409
- }
410
- function getNestedPatchers(twPatcher) {
411
- const nested = twPatcher[runtimeSignaturePatchersSymbol];
412
- return Array.isArray(nested) && nested.length > 0 ? nested : void 0;
413
- }
414
- function getOwnRuntimeClassSetSignature(twPatcher) {
415
- const trackedFiles = [...getTailwindTrackedFiles(twPatcher)].sort((a, b) => a.localeCompare(b)).map(getFileSignature);
416
- return `${trackedFiles.length > 0 ? trackedFiles.join("|") : "files:missing"}|runtime:${getRuntimeTargetSignature(twPatcher)}`;
417
- }
418
- function invalidateRuntimeClassSet(twPatcher) {
419
- if (!twPatcher) return;
420
- const nestedPatchers = getNestedPatchers(twPatcher);
421
- if (nestedPatchers) for (const patcher of nestedPatchers) invalidateRuntimeClassSet(patcher);
422
- for (const trackedFile of getTailwindTrackedFiles(twPatcher)) runtimeFileSignatureCache.delete(trackedFile);
423
- runtimeClassSetCache.delete(twPatcher);
424
- }
425
- function getRuntimeClassSetCacheEntry(twPatcher) {
426
- return getCacheEntry(twPatcher);
427
- }
428
- function getRuntimeClassSetSignature(twPatcher) {
429
- const nestedPatchers = getNestedPatchers(twPatcher);
430
- if (nestedPatchers) return nestedPatchers.map(getOwnRuntimeClassSetSignature).sort((a, b) => a.localeCompare(b)).join("||");
431
- return getOwnRuntimeClassSetSignature(twPatcher);
432
- }
433
- //#endregion
434
- export { createTailwindcssPatcher as a, resolveTailwindcssOptions as c, findWorkspaceRoot as d, runtimeSignaturePatchersSymbol as i, findNearestPackageRoot as l, getRuntimeClassSetSignature as n, readInstalledPackageMajorVersion as o, invalidateRuntimeClassSet as r, findTailwindConfig as s, getRuntimeClassSetCacheEntry as t, findWorkspacePackageDir as u };
@@ -1,73 +0,0 @@
1
- //#region src/css-macro/constants.ts
2
- const queryKey = "weapp-tw-platform";
3
- function createMediaQuery(value) {
4
- return `@media (${queryKey}:"${value}"){&}`;
5
- }
6
- function createNegativeMediaQuery(value) {
7
- return `@media not screen and (${queryKey}:"${value}"){&}`;
8
- }
9
- const UNESCAPED_UNDERSCORE_RE = /(?<!\\)_/g;
10
- const WHITESPACE_RE = /\s+/g;
11
- const LOGICAL_OPERATOR_RE = /\s*(\|\||&&)\s*/g;
12
- function normalComment(text) {
13
- if (typeof text === "string") {
14
- const normalized = text.replaceAll(UNESCAPED_UNDERSCORE_RE, " ").replaceAll(WHITESPACE_RE, " ").trim();
15
- if (normalized.includes("\\")) return normalized;
16
- return normalized.replaceAll(LOGICAL_OPERATOR_RE, " $1 ").replaceAll(WHITESPACE_RE, " ").trim();
17
- }
18
- return text;
19
- }
20
- function ifdef(text) {
21
- return {
22
- start: `#ifdef ${normalComment(text)}`,
23
- end: `#endif`
24
- };
25
- }
26
- function ifndef(text) {
27
- return {
28
- start: `#ifndef ${normalComment(text)}`,
29
- end: `#endif`
30
- };
31
- }
32
- const QUERY_KEY_REGEX = new RegExp(`\\(\\s*${queryKey}\\s*:\\s*"([^)]*)"\\)`, "g");
33
- function matchCustomPropertyFromValue(str, cb) {
34
- let index = 0;
35
- QUERY_KEY_REGEX.lastIndex = 0;
36
- let arr = QUERY_KEY_REGEX.exec(str);
37
- while (arr !== null) {
38
- cb(arr, index);
39
- index++;
40
- arr = QUERY_KEY_REGEX.exec(str);
41
- }
42
- }
43
- //#endregion
44
- Object.defineProperty(exports, "createMediaQuery", {
45
- enumerable: true,
46
- get: function() {
47
- return createMediaQuery;
48
- }
49
- });
50
- Object.defineProperty(exports, "createNegativeMediaQuery", {
51
- enumerable: true,
52
- get: function() {
53
- return createNegativeMediaQuery;
54
- }
55
- });
56
- Object.defineProperty(exports, "ifdef", {
57
- enumerable: true,
58
- get: function() {
59
- return ifdef;
60
- }
61
- });
62
- Object.defineProperty(exports, "ifndef", {
63
- enumerable: true,
64
- get: function() {
65
- return ifndef;
66
- }
67
- });
68
- Object.defineProperty(exports, "matchCustomPropertyFromValue", {
69
- enumerable: true,
70
- get: function() {
71
- return matchCustomPropertyFromValue;
72
- }
73
- });
@@ -1,44 +0,0 @@
1
- //#region src/css-macro/constants.ts
2
- const queryKey = "weapp-tw-platform";
3
- function createMediaQuery(value) {
4
- return `@media (${queryKey}:"${value}"){&}`;
5
- }
6
- function createNegativeMediaQuery(value) {
7
- return `@media not screen and (${queryKey}:"${value}"){&}`;
8
- }
9
- const UNESCAPED_UNDERSCORE_RE = /(?<!\\)_/g;
10
- const WHITESPACE_RE = /\s+/g;
11
- const LOGICAL_OPERATOR_RE = /\s*(\|\||&&)\s*/g;
12
- function normalComment(text) {
13
- if (typeof text === "string") {
14
- const normalized = text.replaceAll(UNESCAPED_UNDERSCORE_RE, " ").replaceAll(WHITESPACE_RE, " ").trim();
15
- if (normalized.includes("\\")) return normalized;
16
- return normalized.replaceAll(LOGICAL_OPERATOR_RE, " $1 ").replaceAll(WHITESPACE_RE, " ").trim();
17
- }
18
- return text;
19
- }
20
- function ifdef(text) {
21
- return {
22
- start: `#ifdef ${normalComment(text)}`,
23
- end: `#endif`
24
- };
25
- }
26
- function ifndef(text) {
27
- return {
28
- start: `#ifndef ${normalComment(text)}`,
29
- end: `#endif`
30
- };
31
- }
32
- const QUERY_KEY_REGEX = new RegExp(`\\(\\s*${queryKey}\\s*:\\s*"([^)]*)"\\)`, "g");
33
- function matchCustomPropertyFromValue(str, cb) {
34
- let index = 0;
35
- QUERY_KEY_REGEX.lastIndex = 0;
36
- let arr = QUERY_KEY_REGEX.exec(str);
37
- while (arr !== null) {
38
- cb(arr, index);
39
- index++;
40
- arr = QUERY_KEY_REGEX.exec(str);
41
- }
42
- }
43
- //#endregion
44
- export { matchCustomPropertyFromValue as a, ifndef as i, createNegativeMediaQuery as n, ifdef as r, createMediaQuery as t };