weapp-tailwindcss 5.0.6 → 5.0.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 (103) hide show
  1. package/dist/{bundle-state-CdNXQl-o.mjs → bundle-state-5FtFktJr.mjs} +2 -1
  2. package/dist/{bundle-state-CFgzVHFP.js → bundle-state-cHwTyrOS.js} +2 -1
  3. package/dist/bundlers/gulp/index.d.ts +3 -4
  4. package/dist/bundlers/gulp/module-graph.d.ts +2 -0
  5. package/dist/bundlers/gulp/runtime-snapshot.d.ts +5 -0
  6. package/dist/bundlers/gulp/vinyl-transform.d.ts +3 -0
  7. package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
  8. package/dist/bundlers/shared/css-source-trace.d.ts +20 -0
  9. package/dist/bundlers/shared/generator-css/directives/fallback.d.ts +11 -0
  10. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +56 -0
  11. package/dist/bundlers/shared/generator-css/local-imports.d.ts +7 -0
  12. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +1 -1
  13. package/dist/bundlers/shared/generator-css/types.d.ts +27 -0
  14. package/dist/bundlers/shared/generator-css/user-css.d.ts +26 -0
  15. package/dist/bundlers/shared/generator-css/validate.d.ts +5 -0
  16. package/dist/bundlers/shared/generator-css.d.ts +4 -32
  17. package/dist/bundlers/vite/css-finalizer.d.ts +3 -0
  18. package/dist/bundlers/vite/generate-bundle/css-config-directives.d.ts +2 -0
  19. package/dist/bundlers/vite/generate-bundle/css-output.d.ts +14 -0
  20. package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +11 -0
  21. package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +9 -0
  22. package/dist/bundlers/vite/generate-bundle/style-matching.d.ts +5 -0
  23. package/dist/bundlers/vite/generate-bundle/subpackages.d.ts +7 -0
  24. package/dist/bundlers/vite/generate-bundle/types.d.ts +68 -0
  25. package/dist/bundlers/vite/generate-bundle.d.ts +4 -62
  26. package/dist/bundlers/vite/incremental-runtime-class-set/entries.d.ts +4 -0
  27. package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +2 -0
  28. package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +13 -0
  29. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +1 -0
  30. package/dist/bundlers/vite/processed-css-assets/css-rules.d.ts +17 -0
  31. package/dist/bundlers/vite/processed-css-assets.d.ts +2 -0
  32. package/dist/bundlers/vite/source-candidates/scan-root.d.ts +10 -0
  33. package/dist/bundlers/vite/source-candidates/script.d.ts +7 -0
  34. package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +1 -0
  35. package/dist/bundlers/vite/source-candidates.d.ts +8 -3
  36. package/dist/bundlers/vite/source-scan/css-entries.d.ts +20 -0
  37. package/dist/bundlers/vite/source-scan/dependencies.d.ts +2 -0
  38. package/dist/bundlers/vite/source-scan.d.ts +2 -12
  39. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -0
  40. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -20
  41. package/dist/cli.js +71 -69
  42. package/dist/cli.mjs +71 -69
  43. package/dist/core.js +1 -1
  44. package/dist/core.mjs +1 -1
  45. package/dist/{defaults-BPUuNYcD.js → defaults-Boc26eel.js} +1 -0
  46. package/dist/{defaults-8xrgzxFY.mjs → defaults-DH0ZQRhy.mjs} +1 -0
  47. package/dist/defaults.js +1 -1
  48. package/dist/defaults.mjs +1 -1
  49. package/dist/{generator-C56PJYxA.js → generator-C--TrAod.js} +1 -1
  50. package/dist/{generator-Bgn4m8An.mjs → generator-DnwUQOXB.mjs} +1 -1
  51. package/dist/generator.js +2 -2
  52. package/dist/generator.mjs +2 -2
  53. package/dist/gulp-5Tan5bHG.js +473 -0
  54. package/dist/gulp-B22YSGU_.mjs +463 -0
  55. package/dist/gulp.js +4 -414
  56. package/dist/gulp.mjs +1 -406
  57. package/dist/{incremental-runtime-class-set-Bmzdjlk0.js → hmr-timing-CscCNKb9.js} +1205 -449
  58. package/dist/{incremental-runtime-class-set-BEYHQkZc.mjs → hmr-timing-DK-mine6.mjs} +1169 -467
  59. package/dist/index.js +5 -5
  60. package/dist/index.mjs +5 -5
  61. package/dist/{postcss-BgINK7Nm.mjs → postcss-CjWuDZwL.mjs} +4 -4
  62. package/dist/{postcss-B7QNe78h.js → postcss-R5pDVHUy.js} +7 -7
  63. package/dist/postcss.js +1 -1
  64. package/dist/postcss.mjs +1 -1
  65. package/dist/{precheck-CyPbGn38.js → precheck-B8y6tDvG.js} +19 -5
  66. package/dist/{precheck-Copn2SqE.mjs → precheck-CcxTR7E_.mjs} +19 -5
  67. package/dist/presets.js +2 -2
  68. package/dist/presets.mjs +2 -2
  69. package/dist/tailwindcss/source-scan/inline-source.d.ts +7 -0
  70. package/dist/tailwindcss/source-scan.d.ts +2 -7
  71. package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +3 -0
  72. package/dist/tailwindcss/v3-engine/generator/content.d.ts +10 -0
  73. package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +2 -0
  74. package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +2 -0
  75. package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +6 -0
  76. package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +2 -0
  77. package/dist/tailwindcss/v4-engine/types.d.ts +1 -1
  78. package/dist/{tailwindcss-C0Zgo3Es.mjs → tailwindcss-0DaftXcU.mjs} +2 -2
  79. package/dist/{tailwindcss-Tw6CSVHL.js → tailwindcss-DbZ4o4m_.js} +2 -2
  80. package/dist/{transform-DgCFGtQR.mjs → transform-DRyWUN5X.mjs} +11 -2
  81. package/dist/{transform-95ivJthq.js → transform-DiW_u3eD.js} +11 -2
  82. package/dist/types/typedoc-tailwindcss-patch.d.ts +4 -2
  83. package/dist/types/user-defined-options/general.d.ts +5 -0
  84. package/dist/uni-app-x/component-local-style.d.ts +1 -0
  85. package/dist/uni-app-x/harmony.d.ts +1 -0
  86. package/dist/uni-app-x/style-asset/style-value.d.ts +16 -0
  87. package/dist/uni-app-x/style-asset.d.ts +20 -0
  88. package/dist/uni-app-x/transform.d.ts +1 -0
  89. package/dist/uni-app-x/vite.d.ts +1 -0
  90. package/dist/{v3-engine-Ji6AXPh2.mjs → v3-engine-ArQVHEau.mjs} +786 -699
  91. package/dist/{v3-engine-6FVAcrZl.js → v3-engine-DdlvXpID.js} +788 -701
  92. package/dist/{vite-Bw6LOXvf.js → vite-C_IUnDBy.js} +1797 -386
  93. package/dist/{vite-ChZ2cbn4.mjs → vite-_iUhzc4t.mjs} +1779 -369
  94. package/dist/vite.js +1 -1
  95. package/dist/vite.mjs +1 -1
  96. package/dist/weapp-tw-css-import-rewrite-loader.js +1148 -987
  97. package/dist/{webpack-CMJ7iqN7.mjs → webpack-CqnI4Ymw.mjs} +104 -37
  98. package/dist/{webpack-nn3P8_S_.js → webpack-KLoTb5Dr.js} +113 -45
  99. package/dist/webpack.js +1 -1
  100. package/dist/webpack.mjs +1 -1
  101. package/package.json +6 -5
  102. package/dist/source-candidates-BODCmzz5.mjs +0 -355
  103. package/dist/source-candidates-Caf2GDvx.js +0 -374
@@ -0,0 +1,463 @@
1
+ import { D as normalizeTailwindConfigDirectives, T as hasTailwindRootDirectives, k as normalizeTailwindSourceForGenerator, l as getRuntimeClassSetSignature, lt as createDebug, m as resolveViteSourceScanEntries } from "./v3-engine-ArQVHEau.mjs";
2
+ import { n as getCompilerContext, t as shouldSkipJsTransform, v as createTailwindRuntimeReadyPromise, y as ensureRuntimeClassSet } from "./precheck-CcxTR7E_.mjs";
3
+ import { c as hasConfiguredTailwindV4CssRoots, l as upsertTailwindV4CssSource } from "./tailwindcss-0DaftXcU.mjs";
4
+ import { a as createTailwindV3DefaultExtractor, g as createCssTokenSourceMap, h as createCssSourceTraceCacheSignature, m as annotateCssSourceTrace, n as emitHmrTiming, o as createBundleRuntimeClassSetManager, r as createSourceCandidateCollector, s as generateCssByGenerator, v as processCachedTask } from "./hmr-timing-DK-mine6.mjs";
5
+ import process from "node:process";
6
+ import fs from "node:fs";
7
+ import path from "node:path";
8
+ import { Buffer } from "node:buffer";
9
+ import stream from "node:stream";
10
+ //#region src/bundlers/gulp/module-graph.ts
11
+ const MODULE_EXTENSIONS = [
12
+ ".js",
13
+ ".mjs",
14
+ ".cjs",
15
+ ".ts",
16
+ ".tsx",
17
+ ".jsx"
18
+ ];
19
+ function resolveWithExtensions(base) {
20
+ for (const ext of MODULE_EXTENSIONS) {
21
+ const candidate = `${base}${ext}`;
22
+ try {
23
+ if (fs.statSync(candidate).isFile()) return candidate;
24
+ } catch {
25
+ continue;
26
+ }
27
+ }
28
+ }
29
+ function resolveLocalModuleCandidate(base) {
30
+ try {
31
+ const stat = fs.statSync(base);
32
+ if (stat.isFile()) return base;
33
+ if (stat.isDirectory()) {
34
+ const resolvedIndex = resolveWithExtensions(path.join(base, "index"));
35
+ if (resolvedIndex) return resolvedIndex;
36
+ }
37
+ } catch {}
38
+ if (!path.extname(base)) return resolveWithExtensions(base);
39
+ }
40
+ function createGulpModuleGraphOptions(opts) {
41
+ return {
42
+ resolve(specifier, importer) {
43
+ if (!specifier) return;
44
+ if (!specifier.startsWith(".") && !path.isAbsolute(specifier)) return;
45
+ return resolveLocalModuleCandidate(path.resolve(path.dirname(importer), specifier));
46
+ },
47
+ load(id) {
48
+ try {
49
+ return fs.readFileSync(id, "utf8");
50
+ } catch {
51
+ return;
52
+ }
53
+ },
54
+ filter(id) {
55
+ const relative = path.relative(process.cwd(), id);
56
+ return opts.jsMatcher(relative) || opts.wxsMatcher(relative);
57
+ }
58
+ };
59
+ }
60
+ //#endregion
61
+ //#region src/bundlers/gulp/runtime-snapshot.ts
62
+ function createGulpRuntimeSnapshot(runtimeSourcesByFile, changedFiles) {
63
+ const runtimeAffectingChangedByType = {
64
+ html: /* @__PURE__ */ new Set(),
65
+ js: /* @__PURE__ */ new Set(),
66
+ css: /* @__PURE__ */ new Set(),
67
+ other: /* @__PURE__ */ new Set()
68
+ };
69
+ for (const file of changedFiles) {
70
+ const entry = runtimeSourcesByFile.get(file);
71
+ if (entry) runtimeAffectingChangedByType[entry.type].add(file);
72
+ }
73
+ return {
74
+ entries: [...runtimeSourcesByFile.entries()].map(([file, entry]) => ({
75
+ file,
76
+ output: {
77
+ fileName: file,
78
+ source: entry.source,
79
+ type: "asset"
80
+ },
81
+ source: entry.source,
82
+ type: entry.type
83
+ })),
84
+ jsEntries: /* @__PURE__ */ new Map(),
85
+ sourceHashByFile: /* @__PURE__ */ new Map(),
86
+ runtimeAffectingSignatureByFile: /* @__PURE__ */ new Map(),
87
+ runtimeAffectingHashByFile: /* @__PURE__ */ new Map(),
88
+ hasOmittedKnownFiles: false,
89
+ changedByType: {
90
+ html: /* @__PURE__ */ new Set(),
91
+ js: /* @__PURE__ */ new Set(),
92
+ css: /* @__PURE__ */ new Set(),
93
+ other: /* @__PURE__ */ new Set()
94
+ },
95
+ runtimeAffectingChangedByType,
96
+ processFiles: {
97
+ html: /* @__PURE__ */ new Set(),
98
+ js: /* @__PURE__ */ new Set(),
99
+ css: /* @__PURE__ */ new Set()
100
+ },
101
+ linkedImpactsByEntry: /* @__PURE__ */ new Map()
102
+ };
103
+ }
104
+ //#endregion
105
+ //#region src/bundlers/gulp/vinyl-transform.ts
106
+ const Transform = stream.Transform;
107
+ function createVinylTransform(phase, handler) {
108
+ return new Transform({
109
+ objectMode: true,
110
+ async transform(file, _encoding, callback) {
111
+ const hmrTimingStartedAt = performance.now();
112
+ try {
113
+ await handler(file);
114
+ emitHmrTiming("gulp", phase, performance.now() - hmrTimingStartedAt, { file: file.relative || path.basename(file.path) });
115
+ callback(null, file);
116
+ } catch (error) {
117
+ callback(error, file);
118
+ }
119
+ }
120
+ });
121
+ }
122
+ //#endregion
123
+ //#region src/bundlers/gulp/index.ts
124
+ const debug = createDebug();
125
+ /**
126
+ * @name weapp-tw-gulp
127
+ * @description gulp版本weapp-tw插件
128
+ * @link https://tw.icebreaker.top/docs/quick-start/frameworks/native
129
+ */
130
+ function createPlugins(options = {}) {
131
+ const hasInitialTailwindCssRoots = hasConfiguredTailwindV4CssRoots(options);
132
+ const opts = getCompilerContext({
133
+ ...options,
134
+ __internalDeferMissingCssEntriesWarning: true
135
+ });
136
+ const { templateHandler, styleHandler, jsHandler, cache, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = opts;
137
+ const readyPromise = createTailwindRuntimeReadyPromise(initialTwPatcher);
138
+ let runtimeSet = /* @__PURE__ */ new Set();
139
+ const runtimeState = {
140
+ twPatcher: initialTwPatcher,
141
+ readyPromise,
142
+ refreshTailwindcssPatcher
143
+ };
144
+ const defaultStyleHandlerOptionsCache = /* @__PURE__ */ new Map();
145
+ let cachedDefaultTemplateHandlerOptions;
146
+ let cachedDefaultTemplateRuntimeSet;
147
+ let cachedDefaultModuleGraphOptions;
148
+ let cachedGulpSourceCandidateGetter;
149
+ let cachedGulpSourceCandidateSourceGetter;
150
+ let runtimeSetInitialized = false;
151
+ let runtimeSetDirty = false;
152
+ const runtimeSourceHashByFile = /* @__PURE__ */ new Map();
153
+ const runtimeSourcesByFile = /* @__PURE__ */ new Map();
154
+ let cachedGulpSourceCandidates;
155
+ let cachedGulpSourceCandidateSignature;
156
+ const sourceCandidateExtractor = initialTwPatcher.majorVersion === 3 ? createTailwindV3DefaultExtractor() : void 0;
157
+ const bundleRuntimeClassSetManager = options.__internalGulpRuntimeClassSetManager ?? createBundleRuntimeClassSetManager();
158
+ function invalidateGulpSourceCandidates() {
159
+ cachedGulpSourceCandidates = void 0;
160
+ cachedGulpSourceCandidateSignature = void 0;
161
+ cachedGulpSourceCandidateGetter = void 0;
162
+ cachedGulpSourceCandidateSourceGetter = void 0;
163
+ }
164
+ async function refreshRuntimeSet(options = false) {
165
+ const normalizedOptions = typeof options === "boolean" ? {
166
+ forceRefresh: options,
167
+ forceCollect: options,
168
+ clearCache: options
169
+ } : options;
170
+ const forceRefresh = normalizedOptions.forceRefresh === true;
171
+ const shouldForceCollect = normalizedOptions.forceCollect === true || runtimeSetDirty;
172
+ const clearCache = normalizedOptions.clearCache === true || runtimeSetDirty;
173
+ if (!forceRefresh && !shouldForceCollect && runtimeSetInitialized) return runtimeSet;
174
+ runtimeSet = await ensureRuntimeClassSet(runtimeState, {
175
+ forceRefresh,
176
+ forceCollect: shouldForceCollect,
177
+ clearCache,
178
+ allowEmpty: false
179
+ });
180
+ runtimeSetInitialized = true;
181
+ runtimeSetDirty = false;
182
+ return runtimeSet;
183
+ }
184
+ async function refreshRuntimeSetForSource(file, rawSource, type) {
185
+ const filename = path.resolve(file.path);
186
+ const hash = cache.computeHash(rawSource);
187
+ const changed = runtimeSourceHashByFile.get(filename) !== hash;
188
+ runtimeSourceHashByFile.set(filename, hash);
189
+ runtimeSourcesByFile.set(filename, {
190
+ source: rawSource,
191
+ type
192
+ });
193
+ if (changed && runtimeState.twPatcher.majorVersion === 4) invalidateGulpSourceCandidates();
194
+ if (!changed && runtimeSetInitialized) return runtimeSet;
195
+ if (runtimeState.twPatcher.majorVersion === 4 && !runtimeSetDirty) try {
196
+ runtimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, createGulpRuntimeSnapshot(runtimeSourcesByFile, [filename]));
197
+ runtimeSetInitialized = true;
198
+ return runtimeSet;
199
+ } catch (error) {
200
+ debug("gulp incremental runtime set sync failed, fallback to collect: %O", error);
201
+ await bundleRuntimeClassSetManager.reset();
202
+ }
203
+ return refreshRuntimeSet({ forceCollect: true });
204
+ }
205
+ async function refreshGulpSourceCandidates(forceRefresh = false) {
206
+ if (runtimeState.twPatcher.majorVersion !== 3) return /* @__PURE__ */ new Set();
207
+ const root = opts.tailwindcssBasedir ?? process.cwd();
208
+ const sourceScan = await resolveViteSourceScanEntries(opts, runtimeState.twPatcher, { root });
209
+ const nextSignature = cache.computeHash(JSON.stringify({
210
+ root,
211
+ entries: sourceScan?.entries,
212
+ inlineCandidates: sourceScan?.inlineCandidates ? {
213
+ included: [...sourceScan.inlineCandidates.included].sort(),
214
+ excluded: [...sourceScan.inlineCandidates.excluded].sort()
215
+ } : void 0,
216
+ explicit: sourceScan?.explicit ?? false,
217
+ dependencies: [...sourceScan?.dependencies ?? []].sort()
218
+ }));
219
+ if (!forceRefresh && cachedGulpSourceCandidateSignature === nextSignature && cachedGulpSourceCandidates) return cachedGulpSourceCandidates;
220
+ const collector = createSourceCandidateCollector({
221
+ bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
222
+ extractor: sourceCandidateExtractor
223
+ });
224
+ await collector.scanRoot({
225
+ entries: sourceScan?.entries,
226
+ root
227
+ });
228
+ collector.syncInline(sourceScan?.inlineCandidates);
229
+ cachedGulpSourceCandidateSignature = nextSignature;
230
+ cachedGulpSourceCandidateGetter = (entries) => collector.valuesForEntries(entries);
231
+ cachedGulpSourceCandidateSourceGetter = (entries) => collector.sourcesForEntries(entries);
232
+ cachedGulpSourceCandidates = sourceScan?.entries ? collector.valuesForEntries(sourceScan.entries) : collector.values();
233
+ return cachedGulpSourceCandidates;
234
+ }
235
+ async function refreshGulpV4SourceCandidates(forceRefresh = false) {
236
+ if (runtimeState.twPatcher.majorVersion !== 4) {
237
+ cachedGulpSourceCandidateGetter = void 0;
238
+ cachedGulpSourceCandidateSourceGetter = void 0;
239
+ return;
240
+ }
241
+ const root = opts.tailwindcssBasedir ?? process.cwd();
242
+ const sourceScan = await resolveViteSourceScanEntries(opts, runtimeState.twPatcher, { root });
243
+ const nextSignature = cache.computeHash(JSON.stringify({
244
+ root,
245
+ entries: sourceScan?.entries,
246
+ inlineCandidates: sourceScan?.inlineCandidates ? {
247
+ included: [...sourceScan.inlineCandidates.included].sort(),
248
+ excluded: [...sourceScan.inlineCandidates.excluded].sort()
249
+ } : void 0,
250
+ explicit: sourceScan?.explicit ?? false,
251
+ dependencies: [...sourceScan?.dependencies ?? []].sort()
252
+ }));
253
+ if (!forceRefresh && cachedGulpSourceCandidateSignature === nextSignature && cachedGulpSourceCandidateGetter) return cachedGulpSourceCandidateGetter;
254
+ const collector = createSourceCandidateCollector({ bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues });
255
+ await collector.scanRoot({
256
+ entries: sourceScan?.entries,
257
+ explicit: sourceScan?.explicit,
258
+ root
259
+ });
260
+ collector.syncInline(sourceScan?.inlineCandidates);
261
+ cachedGulpSourceCandidateSignature = nextSignature;
262
+ cachedGulpSourceCandidateGetter = (entries) => collector.valuesForEntries(entries);
263
+ cachedGulpSourceCandidateSourceGetter = (entries) => collector.sourcesForEntries(entries);
264
+ return cachedGulpSourceCandidateGetter;
265
+ }
266
+ function createRuntimeSetHash(rawSource, nextRuntimeSet, sourceTraceSignature) {
267
+ return cache.computeHash([
268
+ rawSource,
269
+ getRuntimeClassSetSignature(runtimeState.twPatcher),
270
+ [...nextRuntimeSet].sort().join("\n"),
271
+ sourceTraceSignature ?? "css-source-trace:0"
272
+ ].join("\n\n"));
273
+ }
274
+ async function registerAutoCssSource(file, rawSource) {
275
+ if (hasInitialTailwindCssRoots || (runtimeState.twPatcher.majorVersion ?? 0) < 4 || !file.path || !hasTailwindRootDirectives(rawSource)) return false;
276
+ const sourceFile = path.resolve(file.path);
277
+ const sourceCss = normalizeTailwindSourceForGenerator(normalizeTailwindConfigDirectives(rawSource, path.dirname(sourceFile)), { importFallback: true });
278
+ if (!upsertTailwindV4CssSource(opts, {
279
+ file: sourceFile,
280
+ base: path.dirname(sourceFile),
281
+ css: sourceCss
282
+ })) return false;
283
+ runtimeSetInitialized = false;
284
+ runtimeSetDirty = true;
285
+ await bundleRuntimeClassSetManager.reset();
286
+ debug("detected tailwindcss v4 css source from gulp css file: %s", file.path);
287
+ return true;
288
+ }
289
+ function resolveModuleGraphOptions(moduleGraph) {
290
+ if (moduleGraph) return moduleGraph;
291
+ if (!cachedDefaultModuleGraphOptions) cachedDefaultModuleGraphOptions = createGulpModuleGraphOptions(opts);
292
+ return cachedDefaultModuleGraphOptions;
293
+ }
294
+ function resolveWxssHandlerOptions(options) {
295
+ const majorVersion = runtimeState.twPatcher.majorVersion ?? "unknown";
296
+ if (!options || Object.keys(options).length === 0) {
297
+ let cached = defaultStyleHandlerOptionsCache.get(majorVersion);
298
+ if (!cached) {
299
+ cached = runtimeState.twPatcher.majorVersion === void 0 ? {} : { majorVersion: runtimeState.twPatcher.majorVersion };
300
+ defaultStyleHandlerOptionsCache.set(majorVersion, cached);
301
+ }
302
+ return cached;
303
+ }
304
+ return runtimeState.twPatcher.majorVersion === void 0 ? { ...options } : {
305
+ majorVersion: runtimeState.twPatcher.majorVersion,
306
+ ...options
307
+ };
308
+ }
309
+ function resolveGulpMatcherName(file) {
310
+ return (file.relative || path.basename(file.path)).replaceAll(path.sep, "/");
311
+ }
312
+ function resolveWxssFileHandlerOptions(file, options) {
313
+ const resolved = resolveWxssHandlerOptions(options);
314
+ if (resolved.isMainChunk !== void 0) return resolved;
315
+ return {
316
+ ...resolved,
317
+ isMainChunk: opts.mainCssChunkMatcher(resolveGulpMatcherName(file), opts.appType)
318
+ };
319
+ }
320
+ function resolveWxssUserHandlerOptions(options) {
321
+ return {
322
+ ...resolveWxssHandlerOptions(options),
323
+ isMainChunk: false
324
+ };
325
+ }
326
+ function resolveWxmlHandlerOptions(options) {
327
+ if (!options || Object.keys(options).length === 0) {
328
+ if (cachedDefaultTemplateRuntimeSet !== runtimeSet || !cachedDefaultTemplateHandlerOptions) {
329
+ cachedDefaultTemplateRuntimeSet = runtimeSet;
330
+ cachedDefaultTemplateHandlerOptions = { runtimeSet };
331
+ }
332
+ return cachedDefaultTemplateHandlerOptions;
333
+ }
334
+ return {
335
+ runtimeSet,
336
+ ...options
337
+ };
338
+ }
339
+ const transformWxss = (options = {}) => createVinylTransform("css", async (file) => {
340
+ if (!file.contents) return;
341
+ const rawSource = file.contents.toString();
342
+ const cssSourceChanged = await registerAutoCssSource(file, rawSource);
343
+ const isMainChunk = opts.mainCssChunkMatcher(resolveGulpMatcherName(file), opts.appType);
344
+ const shouldUseGenerator = runtimeState.twPatcher.majorVersion !== 3 || hasTailwindRootDirectives(rawSource);
345
+ const gulpV4SourceCandidates = shouldUseGenerator && runtimeState.twPatcher.majorVersion === 4 ? await refreshGulpV4SourceCandidates(cssSourceChanged) : void 0;
346
+ let nextRuntimeSet = await refreshRuntimeSet({
347
+ forceRefresh: cssSourceChanged,
348
+ forceCollect: cssSourceChanged || runtimeState.twPatcher.majorVersion !== 4 && isMainChunk,
349
+ clearCache: cssSourceChanged
350
+ });
351
+ if (runtimeState.twPatcher.majorVersion === 3 && isMainChunk && shouldUseGenerator) {
352
+ const sourceCandidates = await refreshGulpSourceCandidates(cssSourceChanged);
353
+ if (sourceCandidates.size > 0) {
354
+ nextRuntimeSet = new Set([...nextRuntimeSet, ...sourceCandidates]);
355
+ runtimeSet = nextRuntimeSet;
356
+ }
357
+ }
358
+ const sourceTraceTokenSources = cachedGulpSourceCandidateSourceGetter ? createCssTokenSourceMap(cachedGulpSourceCandidateSourceGetter(void 0), opts) : void 0;
359
+ const sourceTraceSignature = createCssSourceTraceCacheSignature(sourceTraceTokenSources, opts);
360
+ await processCachedTask({
361
+ cache,
362
+ cacheKey: file.path,
363
+ hash: createRuntimeSetHash(rawSource, nextRuntimeSet, sourceTraceSignature),
364
+ applyResult(source) {
365
+ file.contents = Buffer.from(source);
366
+ },
367
+ onCacheHit() {
368
+ debug("css cache hit: %s", file.path);
369
+ },
370
+ async transform() {
371
+ await runtimeState.readyPromise;
372
+ const cssHandlerOptions = resolveWxssFileHandlerOptions(file, options);
373
+ const css = annotateCssSourceTrace((shouldUseGenerator ? await generateCssByGenerator({
374
+ opts,
375
+ runtimeState,
376
+ runtime: nextRuntimeSet,
377
+ rawSource,
378
+ file: file.path,
379
+ cssHandlerOptions,
380
+ cssUserHandlerOptions: resolveWxssUserHandlerOptions(options),
381
+ getSourceCandidatesForEntries: gulpV4SourceCandidates,
382
+ styleHandler,
383
+ debug
384
+ }) : void 0)?.css ?? (await styleHandler(rawSource, cssHandlerOptions)).css, {
385
+ opts,
386
+ tokenSources: sourceTraceTokenSources
387
+ });
388
+ debug("css handle: %s", file.path);
389
+ return { result: css };
390
+ }
391
+ });
392
+ });
393
+ const transformJs = (options = {}) => createVinylTransform("js", async (file) => {
394
+ if (!file.contents) return;
395
+ const filename = path.resolve(file.path);
396
+ const rawSource = file.contents.toString();
397
+ await refreshRuntimeSetForSource(file, rawSource, "js");
398
+ await runtimeState.readyPromise;
399
+ const moduleGraph = resolveModuleGraphOptions(options.moduleGraph);
400
+ const handlerOptions = {
401
+ ...options,
402
+ filename,
403
+ moduleGraph,
404
+ babelParserOptions: {
405
+ ...options?.babelParserOptions ?? {},
406
+ sourceFilename: filename
407
+ }
408
+ };
409
+ if (runtimeState.twPatcher.majorVersion !== void 0) handlerOptions.tailwindcssMajorVersion = runtimeState.twPatcher.majorVersion;
410
+ await processCachedTask({
411
+ cache,
412
+ cacheKey: file.path,
413
+ rawSource,
414
+ applyResult(source) {
415
+ file.contents = Buffer.from(source);
416
+ },
417
+ onCacheHit() {
418
+ debug("js cache hit: %s", file.path);
419
+ },
420
+ async transform() {
421
+ await runtimeState.readyPromise;
422
+ const currentSource = file.contents?.toString() ?? rawSource;
423
+ if (shouldSkipJsTransform(currentSource, {
424
+ ...handlerOptions,
425
+ classNameSet: runtimeSet
426
+ })) return { result: currentSource };
427
+ const { code } = await jsHandler(currentSource, runtimeSet, handlerOptions);
428
+ debug("js handle: %s", file.path);
429
+ return { result: code };
430
+ }
431
+ });
432
+ });
433
+ const transformWxml = (options = {}) => createVinylTransform("html", async (file) => {
434
+ if (!file.contents) return;
435
+ const rawSource = file.contents.toString();
436
+ await refreshRuntimeSetForSource(file, rawSource, "html");
437
+ await runtimeState.readyPromise;
438
+ await processCachedTask({
439
+ cache,
440
+ cacheKey: file.path,
441
+ rawSource,
442
+ applyResult(source) {
443
+ file.contents = Buffer.from(source);
444
+ },
445
+ onCacheHit() {
446
+ debug("html cache hit: %s", file.path);
447
+ },
448
+ async transform() {
449
+ await runtimeState.readyPromise;
450
+ const code = await templateHandler(rawSource, resolveWxmlHandlerOptions(options));
451
+ debug("html handle: %s", file.path);
452
+ return { result: code };
453
+ }
454
+ });
455
+ });
456
+ return {
457
+ transformWxss,
458
+ transformWxml,
459
+ transformJs
460
+ };
461
+ }
462
+ //#endregion
463
+ export { createPlugins as t };