weapp-tailwindcss 5.0.0-next.5 → 5.0.0-next.8

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 (131) hide show
  1. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +2 -0
  2. package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +3 -0
  3. package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +4 -0
  4. package/dist/bundlers/shared/css-cleanup/selectors.d.ts +8 -0
  5. package/dist/bundlers/shared/css-cleanup.d.ts +1 -2
  6. package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
  7. package/dist/bundlers/shared/generator-css/directives.d.ts +12 -0
  8. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
  9. package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
  10. package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
  11. package/dist/bundlers/shared/generator-css/markers.d.ts +16 -0
  12. package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -0
  13. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +10 -0
  14. package/dist/bundlers/shared/generator-css.d.ts +10 -23
  15. package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
  16. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
  17. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +20 -0
  18. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +3 -0
  19. package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
  20. package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
  21. package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
  22. package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
  23. package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
  24. package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
  25. package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
  26. package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
  27. package/dist/bundlers/vite/generate-bundle.d.ts +1 -1
  28. package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
  29. package/dist/bundlers/vite/postcss-config.d.ts +6 -0
  30. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  31. package/dist/bundlers/vite/runtime-class-set.d.ts +22 -0
  32. package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
  33. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +1 -0
  34. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -1
  35. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +2 -0
  36. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -0
  37. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +2 -0
  38. package/dist/cache-BVAiJV3J.js +502 -0
  39. package/dist/cache-CHs4DXui.mjs +434 -0
  40. package/dist/cli/helpers.d.ts +1 -2
  41. package/dist/cli/mount-options.d.ts +2 -2
  42. package/dist/cli/types.d.ts +0 -2
  43. package/dist/cli.js +107 -603
  44. package/dist/cli.mjs +118 -613
  45. package/dist/constants.d.ts +0 -1
  46. package/dist/context/tailwindcss.d.ts +1 -1
  47. package/dist/core.js +13 -20
  48. package/dist/core.mjs +8 -14
  49. package/dist/css-macro/postcss.js +1 -1
  50. package/dist/css-macro/postcss.mjs +1 -1
  51. package/dist/css-macro.js +2 -2
  52. package/dist/css-macro.mjs +2 -2
  53. package/dist/defaults.d.ts +15 -1
  54. package/dist/defaults.js +28 -7
  55. package/dist/defaults.mjs +25 -8
  56. package/dist/{generator-9UEp8OoQ.js → generator-DKkhJbOg.js} +24 -7
  57. package/dist/{generator-Dpp-5s8z.mjs → generator-UBmfduYg.mjs} +20 -3
  58. package/dist/{generator-css-MyjZhF0z.mjs → generator-css-BIapP56i.mjs} +691 -606
  59. package/dist/{generator-css-CGueCYbX.js → generator-css-Mksw8PgB.js} +703 -606
  60. package/dist/generator.js +1 -1
  61. package/dist/generator.mjs +1 -1
  62. package/dist/gulp.js +33 -21
  63. package/dist/gulp.mjs +29 -17
  64. package/dist/index.js +5 -5
  65. package/dist/index.mjs +4 -4
  66. package/dist/logger-BRy6XPQ2.js +1 -0
  67. package/dist/logger-Bub1jggA.mjs +2 -0
  68. package/dist/postcss/config-directive.d.ts +1 -0
  69. package/dist/postcss/context.d.ts +9 -0
  70. package/dist/postcss/source-files.d.ts +8 -0
  71. package/dist/postcss/tailwind-version.d.ts +3 -0
  72. package/dist/postcss-QIXwT40c.js +298 -0
  73. package/dist/postcss-w48mGIhe.mjs +288 -0
  74. package/dist/postcss.js +3 -285
  75. package/dist/postcss.mjs +1 -278
  76. package/dist/{recorder-D4BKt75Q.js → precheck-B32p-gLI.js} +139 -274
  77. package/dist/{recorder-BIW3Kuke.mjs → precheck-B4RH6ZNN.mjs} +105 -239
  78. package/dist/presets.js +6 -4
  79. package/dist/presets.mjs +4 -2
  80. package/dist/runtime-patch-CwN5ya72.mjs +71 -0
  81. package/dist/runtime-patch-D6mBo_KB.js +85 -0
  82. package/dist/tailwindcss/runtime-patch.d.ts +5 -0
  83. package/dist/tailwindcss/runtime.d.ts +2 -3
  84. package/dist/tailwindcss/targets.d.ts +1 -5
  85. package/dist/tailwindcss/v4/css-sources.d.ts +5 -0
  86. package/dist/tailwindcss/v4/patcher.d.ts +1 -1
  87. package/dist/{logger-D9clu_3f.js → tailwindcss-Bu-RWIHx.js} +70 -413
  88. package/dist/{logger-1gx9UllH.mjs → tailwindcss-C5IgPlQ0.mjs} +56 -382
  89. package/dist/types/index.d.ts +1 -6
  90. package/dist/uni-app-x/vite.d.ts +1 -1
  91. package/dist/{vite-fDM-UQpR.mjs → vite-BwgRVgxH.mjs} +677 -525
  92. package/dist/{vite-BkMGwDeH.js → vite-DyZuiyap.js} +704 -552
  93. package/dist/vite.js +1 -1
  94. package/dist/vite.mjs +1 -1
  95. package/dist/weapp-tw-css-import-rewrite-loader.js +10 -1
  96. package/dist/{webpack-CICGEKT9.js → webpack-CNV2dx3Q.js} +72 -37
  97. package/dist/{webpack-D2Wdk28V.mjs → webpack-CT6EEENx.mjs} +58 -23
  98. package/dist/webpack.js +1 -1
  99. package/dist/webpack.mjs +1 -1
  100. package/package.json +6 -9
  101. package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
  102. package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
  103. package/dist/cli/config.d.ts +0 -5
  104. package/dist/cli/helpers/patch-cwd.d.ts +0 -1
  105. package/dist/cli/mount-options/patch-status.d.ts +0 -2
  106. package/dist/cli/patch-options.d.ts +0 -6
  107. package/dist/cli/tokens.d.ts +0 -4
  108. package/dist/cli/workspace/package-dirs.d.ts +0 -3
  109. package/dist/cli/workspace/patch-package.d.ts +0 -3
  110. package/dist/cli/workspace/patch-utils.d.ts +0 -3
  111. package/dist/cli/workspace/types.d.ts +0 -11
  112. package/dist/cli/workspace/workspace-globs.d.ts +0 -2
  113. package/dist/cli/workspace/workspace-io.d.ts +0 -1
  114. package/dist/cli/workspace/workspace-lock.d.ts +0 -1
  115. package/dist/cli/workspace.d.ts +0 -2
  116. package/dist/js/syntax.d.ts +0 -10
  117. package/dist/patcher-options-DnqazL9E.js +0 -34
  118. package/dist/patcher-options-GuOwX0-k.mjs +0 -17
  119. package/dist/tailwindcss/recorder.d.ts +0 -13
  120. package/dist/tailwindcss/targets/paths.d.ts +0 -13
  121. package/dist/tailwindcss/targets/record-io.d.ts +0 -5
  122. package/dist/tailwindcss/targets/recorder.d.ts +0 -3
  123. package/dist/tailwindcss/targets/types.d.ts +0 -35
  124. package/dist/version-CWBxRFPB.js +0 -56
  125. package/dist/version-WNz3MwRv.mjs +0 -49
  126. /package/dist/{constants-p1dyh1x1.js → constants-BoB_6lFw.js} +0 -0
  127. /package/dist/{constants-B-_T5UnW.mjs → constants-E_loJC49.mjs} +0 -0
  128. /package/dist/{run-tasks-Cq5A5nVD.js → run-tasks-B50A3pxt.js} +0 -0
  129. /package/dist/{run-tasks-DUVrDJGl.mjs → run-tasks-DdNi-hkk.mjs} +0 -0
  130. /package/dist/{utils-DmC9_In3.js → utils-BiShvil9.js} +0 -0
  131. /package/dist/{utils-7DUGTFED.mjs → utils-Btw1iOVV.mjs} +0 -0
@@ -0,0 +1,288 @@
1
+ import { o as readInstalledPackageMajorVersion } from "./cache-CHs4DXui.mjs";
2
+ import { a as resolveTailwindV4Source$1, i as normalizeWeappTailwindcssGeneratorOptions, p as resolveTailwindV3Source, t as createWeappTailwindcssGenerator } from "./generator-UBmfduYg.mjs";
3
+ import postcss from "postcss";
4
+ import path from "node:path";
5
+ import process from "node:process";
6
+ import { extractValidCandidates } from "tailwindcss-patch";
7
+ import { loadConfig } from "tailwindcss-config";
8
+ import { readFile, stat } from "node:fs/promises";
9
+ import fg from "fast-glob";
10
+ //#region src/postcss/config-directive.ts
11
+ function quoteCssString(value) {
12
+ return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
13
+ }
14
+ function toCssPath(value) {
15
+ return value.replaceAll("\\", "/");
16
+ }
17
+ function prependConfigDirective(css, config) {
18
+ if (!config || /@config\s+/.test(css)) return css;
19
+ return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
20
+ }
21
+ //#endregion
22
+ //#region src/postcss/context.ts
23
+ const PLUGIN_NAME$1 = "weapp-tailwindcss";
24
+ function resolveInputFile(result) {
25
+ const from = result.opts.from;
26
+ if (typeof from !== "string" || from.length === 0) return;
27
+ return path.isAbsolute(from) ? from : path.resolve(process.cwd(), from);
28
+ }
29
+ function resolvePostcssBase(result, options) {
30
+ if (options.base) return options.base;
31
+ const inputFile = resolveInputFile(result);
32
+ return inputFile ? path.dirname(inputFile) : process.cwd();
33
+ }
34
+ function resolvePostcssProjectRoot(result, options) {
35
+ if (options.projectRoot) return options.projectRoot;
36
+ const inputFile = resolveInputFile(result);
37
+ return inputFile ? path.dirname(inputFile) : process.cwd();
38
+ }
39
+ function replaceRootCss(root, css, result) {
40
+ root.removeAll();
41
+ try {
42
+ const nextRoot = postcss.parse(css, { from: resolveInputFile(result) });
43
+ root.append(nextRoot.nodes);
44
+ } catch {
45
+ root.raws = { after: css };
46
+ }
47
+ }
48
+ function addDependencyMessages(result, generated) {
49
+ for (const file of generated.dependencies) result.messages.push({
50
+ type: "dependency",
51
+ plugin: PLUGIN_NAME$1,
52
+ file
53
+ });
54
+ }
55
+ function addSourceDependencyMessages(result, files) {
56
+ for (const file of files) result.messages.push({
57
+ type: "dependency",
58
+ plugin: PLUGIN_NAME$1,
59
+ file
60
+ });
61
+ }
62
+ //#endregion
63
+ //#region src/postcss/source-files.ts
64
+ const POSTCSS_SOURCE_PATTERN = `**/*.{${[
65
+ "html",
66
+ "wxml",
67
+ "axml",
68
+ "jxml",
69
+ "ksml",
70
+ "ttml",
71
+ "qml",
72
+ "tyml",
73
+ "xhsml",
74
+ "swan",
75
+ "vue",
76
+ "mpx",
77
+ "js",
78
+ "jsx",
79
+ "ts",
80
+ "tsx"
81
+ ].join(",")}}`;
82
+ function parseLocalSourceParam(params) {
83
+ const value = params.trim();
84
+ if (!value || value === "none" || value.startsWith("not ") || value.startsWith("inline(")) return;
85
+ return /^(['"])(.+)\1$/.exec(value)?.[2];
86
+ }
87
+ function parseConfigParam(params) {
88
+ const value = params.trim();
89
+ return /^(['"])(.+)\1$/.exec(value)?.[2];
90
+ }
91
+ function parseSourceFileParam(params) {
92
+ const value = params.trim();
93
+ if (!value || value === "none" || value.startsWith("inline(")) return;
94
+ const negated = value.startsWith("not ");
95
+ const sourceValue = negated ? value.slice(4).trim() : value;
96
+ const match = /^(['"])(.+)\1$/.exec(sourceValue);
97
+ return match?.[2] ? {
98
+ negated,
99
+ sourcePath: match[2]
100
+ } : void 0;
101
+ }
102
+ function getSourceExtension(file) {
103
+ return path.extname(file).slice(1) || void 0;
104
+ }
105
+ async function pathExistsAsDirectory(file) {
106
+ try {
107
+ return (await stat(file)).isDirectory();
108
+ } catch {
109
+ return false;
110
+ }
111
+ }
112
+ async function expandLocalSourceFiles(sourcePath, base) {
113
+ const absoluteSource = path.isAbsolute(sourcePath) ? sourcePath : path.resolve(base, sourcePath);
114
+ if (await pathExistsAsDirectory(absoluteSource)) return fg(POSTCSS_SOURCE_PATTERN, {
115
+ absolute: true,
116
+ cwd: absoluteSource,
117
+ onlyFiles: true
118
+ });
119
+ return fg(sourcePath, {
120
+ absolute: true,
121
+ cwd: base,
122
+ onlyFiles: true
123
+ });
124
+ }
125
+ async function resolveTailwindSourceEntry(sourcePath, base, negated) {
126
+ const absoluteSource = path.isAbsolute(sourcePath) ? path.resolve(sourcePath) : path.resolve(base, sourcePath);
127
+ if (await pathExistsAsDirectory(absoluteSource)) return {
128
+ base: absoluteSource,
129
+ negated,
130
+ pattern: POSTCSS_SOURCE_PATTERN
131
+ };
132
+ if (path.isAbsolute(sourcePath)) return {
133
+ base: path.dirname(absoluteSource),
134
+ negated,
135
+ pattern: path.basename(absoluteSource)
136
+ };
137
+ return {
138
+ base,
139
+ negated,
140
+ pattern: sourcePath
141
+ };
142
+ }
143
+ function collectConfigPaths(root, base) {
144
+ const configPaths = [];
145
+ root.walkAtRules("config", (rule) => {
146
+ const configPath = parseConfigParam(rule.params);
147
+ if (configPath) configPaths.push(path.isAbsolute(configPath) ? configPath : path.resolve(base, configPath));
148
+ });
149
+ return [...new Set(configPaths)];
150
+ }
151
+ function normalizeContentFiles(content) {
152
+ if (typeof content === "string") return [content];
153
+ if (Array.isArray(content)) return content.flatMap((item) => normalizeContentFiles(item));
154
+ if (typeof content === "object" && content !== null && "files" in content) return normalizeContentFiles(content.files);
155
+ return [];
156
+ }
157
+ async function collectConfigContentFiles(root, base) {
158
+ const configPaths = collectConfigPaths(root, base);
159
+ const files = [];
160
+ for (const configPath of configPaths) {
161
+ const contentFiles = normalizeContentFiles((await loadConfig({
162
+ config: configPath,
163
+ cwd: path.dirname(configPath)
164
+ }))?.config.content);
165
+ for (const contentFile of contentFiles) files.push(...await expandLocalSourceFiles(contentFile, path.dirname(configPath)));
166
+ }
167
+ return {
168
+ configPaths,
169
+ files: [...new Set(files)]
170
+ };
171
+ }
172
+ async function collectAutoTailwindCandidates(root, result, options) {
173
+ if (options.scanSources === false) return /* @__PURE__ */ new Set();
174
+ const base = resolvePostcssBase(result, options);
175
+ const projectRoot = resolvePostcssProjectRoot(result, options);
176
+ const sourceEntryTasks = [];
177
+ if (!root.toString().includes("source(none)")) sourceEntryTasks.push(Promise.resolve({
178
+ base,
179
+ negated: false,
180
+ pattern: POSTCSS_SOURCE_PATTERN
181
+ }));
182
+ root.walkAtRules("source", (rule) => {
183
+ const parsed = parseSourceFileParam(rule.params);
184
+ if (!parsed) return;
185
+ sourceEntryTasks.push(resolveTailwindSourceEntry(parsed.sourcePath, base, parsed.negated));
186
+ });
187
+ const sourceEntries = await Promise.all(sourceEntryTasks);
188
+ if (sourceEntries.length === 0) return /* @__PURE__ */ new Set();
189
+ const candidates = await extractValidCandidates({
190
+ base,
191
+ css: root.toString(),
192
+ cwd: projectRoot,
193
+ sources: sourceEntries
194
+ });
195
+ return new Set(candidates);
196
+ }
197
+ async function collectPostcssLocalSources(root, result, options) {
198
+ const base = resolvePostcssBase(result, options);
199
+ const sourcePaths = [];
200
+ root.walkAtRules("source", (rule) => {
201
+ const sourcePath = parseLocalSourceParam(rule.params);
202
+ if (sourcePath) sourcePaths.push(sourcePath);
203
+ });
204
+ const configContentFiles = await collectConfigContentFiles(root, base);
205
+ const files = [...new Set((await Promise.all(sourcePaths.map((sourcePath) => expandLocalSourceFiles(sourcePath, base)))).flat().concat(configContentFiles.files))];
206
+ const sources = await Promise.all(files.map(async (file) => ({
207
+ content: await readFile(file, "utf8"),
208
+ extension: getSourceExtension(file)
209
+ })));
210
+ return {
211
+ files: [...files, ...configContentFiles.configPaths],
212
+ sources
213
+ };
214
+ }
215
+ //#endregion
216
+ //#region src/postcss/tailwind-version.ts
217
+ function hasTailwindV4CssSyntax(root) {
218
+ let hasV4Syntax = false;
219
+ root.walkAtRules((rule) => {
220
+ if (rule.name === "theme" || rule.name === "source" || rule.name === "custom-variant") hasV4Syntax = true;
221
+ if (rule.name === "import" && /(['"])tailwindcss\1/.test(rule.params)) hasV4Syntax = true;
222
+ });
223
+ return hasV4Syntax;
224
+ }
225
+ function resolvePostcssTailwindVersion(root, result, options) {
226
+ const packageName = options.packageName ?? "tailwindcss";
227
+ const installedVersion = readInstalledPackageMajorVersion(packageName, resolvePostcssProjectRoot(result, options));
228
+ if (installedVersion) return installedVersion;
229
+ if (options.version) return options.version;
230
+ if (packageName === "@tailwindcss/postcss" || packageName.includes("tailwindcss4")) return 4;
231
+ if (packageName.includes("tailwindcss3")) return 3;
232
+ if (hasTailwindV4CssSyntax(root)) return 4;
233
+ return 4;
234
+ }
235
+ //#endregion
236
+ //#region src/postcss.ts
237
+ const PLUGIN_NAME = "weapp-tailwindcss";
238
+ const weappTailwindcssPostcssPlugin = (options = {}) => {
239
+ return {
240
+ postcssPlugin: PLUGIN_NAME,
241
+ async Once(root, { result }) {
242
+ const { candidates, generator: userGeneratorOptions, scanSources, sources, styleOptions, ...sourceOptions } = options;
243
+ const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(userGeneratorOptions);
244
+ const tailwindVersion = resolvePostcssTailwindVersion(root, result, options);
245
+ const [collectedSources, autoCandidates] = await Promise.all([collectPostcssLocalSources(root, result, options), collectAutoTailwindCandidates(root, result, options)]);
246
+ const generatorConfig = generatorOptions.config ?? options.config;
247
+ const generator = createWeappTailwindcssGenerator(tailwindVersion === 3 ? await resolveTailwindV3Source({
248
+ config: generatorConfig,
249
+ css: sourceOptions.css ?? root.toString(),
250
+ base: resolvePostcssBase(result, options),
251
+ cwd: resolvePostcssProjectRoot(result, options),
252
+ projectRoot: resolvePostcssProjectRoot(result, options),
253
+ packageName: options.packageName,
254
+ postcssPlugin: options.postcssPlugin
255
+ }) : await resolveTailwindV4Source$1({
256
+ ...sourceOptions,
257
+ css: prependConfigDirective(sourceOptions.css ?? root.toString(), generatorConfig),
258
+ base: resolvePostcssBase(result, options),
259
+ projectRoot: resolvePostcssProjectRoot(result, options)
260
+ }));
261
+ const generateOptions = {
262
+ candidates: new Set([...autoCandidates, ...candidates ?? []]),
263
+ scanSources: scanSources ?? false,
264
+ sources: [...collectedSources.sources, ...sources ?? []],
265
+ styleOptions: {
266
+ ...generatorOptions.styleOptions,
267
+ ...styleOptions
268
+ },
269
+ tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
270
+ target: generatorOptions.target
271
+ };
272
+ const generated = await generator.generate(generateOptions);
273
+ replaceRootCss(root, generated.css, result);
274
+ addDependencyMessages(result, generated);
275
+ addSourceDependencyMessages(result, collectedSources.files);
276
+ result.messages.push({
277
+ type: "weapp-tailwindcss:generated",
278
+ plugin: PLUGIN_NAME,
279
+ target: generated.target,
280
+ classSet: generated.classSet,
281
+ rawCss: generated.rawCss
282
+ });
283
+ }
284
+ };
285
+ };
286
+ weappTailwindcssPostcssPlugin.postcss = true;
287
+ //#endregion
288
+ export { weappTailwindcssPostcssPlugin as t };
package/dist/postcss.js CHANGED
@@ -2,288 +2,6 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- const require_chunk = require("./chunk-8l464Juk.js");
6
- const require_generator = require("./generator-9UEp8OoQ.js");
7
- const require_version = require("./version-CWBxRFPB.js");
8
- let postcss = require("postcss");
9
- postcss = require_chunk.__toESM(postcss);
10
- let node_path = require("node:path");
11
- node_path = require_chunk.__toESM(node_path);
12
- let node_process = require("node:process");
13
- node_process = require_chunk.__toESM(node_process);
14
- let tailwindcss_config = require("tailwindcss-config");
15
- let tailwindcss_patch = require("tailwindcss-patch");
16
- let node_fs_promises = require("node:fs/promises");
17
- let fast_glob = require("fast-glob");
18
- fast_glob = require_chunk.__toESM(fast_glob);
19
- //#region src/postcss.ts
20
- const PLUGIN_NAME = "weapp-tailwindcss";
21
- const POSTCSS_SOURCE_PATTERN = `**/*.{${[
22
- "html",
23
- "wxml",
24
- "axml",
25
- "jxml",
26
- "ksml",
27
- "ttml",
28
- "qml",
29
- "tyml",
30
- "xhsml",
31
- "swan",
32
- "vue",
33
- "mpx",
34
- "js",
35
- "jsx",
36
- "ts",
37
- "tsx"
38
- ].join(",")}}`;
39
- function resolveInputFile(result) {
40
- const from = result.opts.from;
41
- if (typeof from !== "string" || from.length === 0) return;
42
- return node_path.default.isAbsolute(from) ? from : node_path.default.resolve(node_process.default.cwd(), from);
43
- }
44
- function resolvePostcssBase(result, options) {
45
- if (options.base) return options.base;
46
- const inputFile = resolveInputFile(result);
47
- return inputFile ? node_path.default.dirname(inputFile) : node_process.default.cwd();
48
- }
49
- function resolvePostcssProjectRoot(result, options) {
50
- if (options.projectRoot) return options.projectRoot;
51
- const inputFile = resolveInputFile(result);
52
- return inputFile ? node_path.default.dirname(inputFile) : node_process.default.cwd();
53
- }
54
- function replaceRootCss(root, css, result) {
55
- root.removeAll();
56
- try {
57
- const nextRoot = postcss.default.parse(css, { from: resolveInputFile(result) });
58
- root.append(nextRoot.nodes);
59
- } catch {
60
- root.raws = { after: css };
61
- }
62
- }
63
- function addDependencyMessages(result, generated) {
64
- for (const file of generated.dependencies) result.messages.push({
65
- type: "dependency",
66
- plugin: PLUGIN_NAME,
67
- file
68
- });
69
- }
70
- function parseLocalSourceParam(params) {
71
- const value = params.trim();
72
- if (!value || value === "none" || value.startsWith("not ") || value.startsWith("inline(")) return;
73
- return /^(['"])(.+)\1$/.exec(value)?.[2];
74
- }
75
- function parseConfigParam(params) {
76
- const value = params.trim();
77
- return /^(['"])(.+)\1$/.exec(value)?.[2];
78
- }
79
- function parseSourceFileParam(params) {
80
- const value = params.trim();
81
- if (!value || value === "none" || value.startsWith("inline(")) return;
82
- const negated = value.startsWith("not ");
83
- const sourceValue = negated ? value.slice(4).trim() : value;
84
- const match = /^(['"])(.+)\1$/.exec(sourceValue);
85
- return match?.[2] ? {
86
- negated,
87
- sourcePath: match[2]
88
- } : void 0;
89
- }
90
- function hasTailwindV4CssSyntax(root) {
91
- let hasV4Syntax = false;
92
- root.walkAtRules((rule) => {
93
- if (rule.name === "theme" || rule.name === "source" || rule.name === "custom-variant") hasV4Syntax = true;
94
- if (rule.name === "import" && /(['"])tailwindcss\1/.test(rule.params)) hasV4Syntax = true;
95
- });
96
- return hasV4Syntax;
97
- }
98
- function resolvePostcssTailwindVersion(root, result, options) {
99
- const packageName = options.packageName ?? "tailwindcss";
100
- const installedVersion = require_version.readInstalledPackageMajorVersion(packageName, resolvePostcssProjectRoot(result, options));
101
- if (installedVersion) return installedVersion;
102
- if (options.version) return options.version;
103
- if (packageName === "@tailwindcss/postcss" || packageName.includes("tailwindcss4")) return 4;
104
- if (packageName.includes("tailwindcss3")) return 3;
105
- if (hasTailwindV4CssSyntax(root)) return 4;
106
- return 4;
107
- }
108
- function getSourceExtension(file) {
109
- return node_path.default.extname(file).slice(1) || void 0;
110
- }
111
- async function pathExistsAsDirectory(file) {
112
- try {
113
- return (await (0, node_fs_promises.stat)(file)).isDirectory();
114
- } catch {
115
- return false;
116
- }
117
- }
118
- async function expandLocalSourceFiles(sourcePath, base) {
119
- const absoluteSource = node_path.default.isAbsolute(sourcePath) ? sourcePath : node_path.default.resolve(base, sourcePath);
120
- if (await pathExistsAsDirectory(absoluteSource)) return (0, fast_glob.default)(POSTCSS_SOURCE_PATTERN, {
121
- absolute: true,
122
- cwd: absoluteSource,
123
- onlyFiles: true
124
- });
125
- return (0, fast_glob.default)(sourcePath, {
126
- absolute: true,
127
- cwd: base,
128
- onlyFiles: true
129
- });
130
- }
131
- async function resolveTailwindSourceEntry(sourcePath, base, negated) {
132
- const absoluteSource = node_path.default.isAbsolute(sourcePath) ? node_path.default.resolve(sourcePath) : node_path.default.resolve(base, sourcePath);
133
- if (await pathExistsAsDirectory(absoluteSource)) return {
134
- base: absoluteSource,
135
- negated,
136
- pattern: POSTCSS_SOURCE_PATTERN
137
- };
138
- if (node_path.default.isAbsolute(sourcePath)) return {
139
- base: node_path.default.dirname(absoluteSource),
140
- negated,
141
- pattern: node_path.default.basename(absoluteSource)
142
- };
143
- return {
144
- base,
145
- negated,
146
- pattern: sourcePath
147
- };
148
- }
149
- function collectConfigPaths(root, base) {
150
- const configPaths = [];
151
- root.walkAtRules("config", (rule) => {
152
- const configPath = parseConfigParam(rule.params);
153
- if (configPath) configPaths.push(node_path.default.isAbsolute(configPath) ? configPath : node_path.default.resolve(base, configPath));
154
- });
155
- return [...new Set(configPaths)];
156
- }
157
- function normalizeContentFiles(content) {
158
- if (typeof content === "string") return [content];
159
- if (Array.isArray(content)) return content.flatMap((item) => normalizeContentFiles(item));
160
- if (typeof content === "object" && content !== null && "files" in content) return normalizeContentFiles(content.files);
161
- return [];
162
- }
163
- async function collectConfigContentFiles(root, base) {
164
- const configPaths = collectConfigPaths(root, base);
165
- const files = [];
166
- for (const configPath of configPaths) {
167
- const contentFiles = normalizeContentFiles((await (0, tailwindcss_config.loadConfig)({
168
- config: configPath,
169
- cwd: node_path.default.dirname(configPath)
170
- }))?.config.content);
171
- for (const contentFile of contentFiles) files.push(...await expandLocalSourceFiles(contentFile, node_path.default.dirname(configPath)));
172
- }
173
- return {
174
- configPaths,
175
- files: [...new Set(files)]
176
- };
177
- }
178
- async function collectAutoTailwindCandidates(root, result, options) {
179
- if (options.scanSources === false) return /* @__PURE__ */ new Set();
180
- const base = resolvePostcssBase(result, options);
181
- const projectRoot = resolvePostcssProjectRoot(result, options);
182
- const sourceEntryTasks = [];
183
- if (!root.toString().includes("source(none)")) sourceEntryTasks.push(Promise.resolve({
184
- base,
185
- negated: false,
186
- pattern: POSTCSS_SOURCE_PATTERN
187
- }));
188
- root.walkAtRules("source", (rule) => {
189
- const parsed = parseSourceFileParam(rule.params);
190
- if (!parsed) return;
191
- sourceEntryTasks.push(resolveTailwindSourceEntry(parsed.sourcePath, base, parsed.negated));
192
- });
193
- const sourceEntries = await Promise.all(sourceEntryTasks);
194
- if (sourceEntries.length === 0) return /* @__PURE__ */ new Set();
195
- const candidates = await (0, tailwindcss_patch.extractValidCandidates)({
196
- base,
197
- css: root.toString(),
198
- cwd: projectRoot,
199
- sources: sourceEntries
200
- });
201
- return new Set(candidates);
202
- }
203
- async function collectPostcssLocalSources(root, result, options) {
204
- const base = resolvePostcssBase(result, options);
205
- const sourcePaths = [];
206
- root.walkAtRules("source", (rule) => {
207
- const sourcePath = parseLocalSourceParam(rule.params);
208
- if (sourcePath) sourcePaths.push(sourcePath);
209
- });
210
- const configContentFiles = await collectConfigContentFiles(root, base);
211
- const files = [...new Set((await Promise.all(sourcePaths.map((sourcePath) => expandLocalSourceFiles(sourcePath, base)))).flat().concat(configContentFiles.files))];
212
- const sources = await Promise.all(files.map(async (file) => ({
213
- content: await (0, node_fs_promises.readFile)(file, "utf8"),
214
- extension: getSourceExtension(file)
215
- })));
216
- return {
217
- files: [...files, ...configContentFiles.configPaths],
218
- sources
219
- };
220
- }
221
- function addSourceDependencyMessages(result, files) {
222
- for (const file of files) result.messages.push({
223
- type: "dependency",
224
- plugin: PLUGIN_NAME,
225
- file
226
- });
227
- }
228
- function quoteCssString(value) {
229
- return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
230
- }
231
- function toCssPath(value) {
232
- return value.replaceAll("\\", "/");
233
- }
234
- function prependConfigDirective(css, config) {
235
- if (!config || /@config\s+/.test(css)) return css;
236
- return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
237
- }
238
- const weappTailwindcssPostcssPlugin = (options = {}) => {
239
- return {
240
- postcssPlugin: PLUGIN_NAME,
241
- async Once(root, { result }) {
242
- const { candidates, generator: userGeneratorOptions, scanSources, sources, styleOptions, ...sourceOptions } = options;
243
- const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(userGeneratorOptions);
244
- const tailwindVersion = resolvePostcssTailwindVersion(root, result, options);
245
- const [collectedSources, autoCandidates] = await Promise.all([collectPostcssLocalSources(root, result, options), collectAutoTailwindCandidates(root, result, options)]);
246
- const generatorConfig = generatorOptions.config ?? options.config;
247
- const generator = require_generator.createWeappTailwindcssGenerator(tailwindVersion === 3 ? await require_generator.resolveTailwindV3Source({
248
- config: generatorConfig,
249
- css: sourceOptions.css ?? root.toString(),
250
- base: resolvePostcssBase(result, options),
251
- cwd: resolvePostcssProjectRoot(result, options),
252
- projectRoot: resolvePostcssProjectRoot(result, options),
253
- packageName: options.packageName,
254
- postcssPlugin: options.postcssPlugin
255
- }) : await require_generator.resolveTailwindV4Source({
256
- ...sourceOptions,
257
- css: prependConfigDirective(sourceOptions.css ?? root.toString(), generatorConfig),
258
- base: resolvePostcssBase(result, options),
259
- projectRoot: resolvePostcssProjectRoot(result, options)
260
- }));
261
- const generateOptions = {
262
- candidates: new Set([...autoCandidates, ...candidates ?? []]),
263
- scanSources: scanSources ?? false,
264
- sources: [...collectedSources.sources, ...sources ?? []],
265
- styleOptions: {
266
- ...generatorOptions.styleOptions,
267
- ...styleOptions
268
- },
269
- tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
270
- target: generatorOptions.target
271
- };
272
- const generated = await generator.generate(generateOptions);
273
- replaceRootCss(root, generated.css, result);
274
- addDependencyMessages(result, generated);
275
- addSourceDependencyMessages(result, collectedSources.files);
276
- result.messages.push({
277
- type: "weapp-tailwindcss:generated",
278
- plugin: PLUGIN_NAME,
279
- target: generated.target,
280
- classSet: generated.classSet,
281
- rawCss: generated.rawCss
282
- });
283
- }
284
- };
285
- };
286
- weappTailwindcssPostcssPlugin.postcss = true;
287
- //#endregion
288
- exports.default = weappTailwindcssPostcssPlugin;
289
- exports.weappTailwindcssPostcssPlugin = weappTailwindcssPostcssPlugin;
5
+ const require_postcss = require("./postcss-QIXwT40c.js");
6
+ exports.default = require_postcss.weappTailwindcssPostcssPlugin;
7
+ exports.weappTailwindcssPostcssPlugin = require_postcss.weappTailwindcssPostcssPlugin;