weapp-tailwindcss 5.0.4 → 5.0.6

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 (57) hide show
  1. package/dist/{auto-BZ4n4Icc.js → auto-Cvy0zWpS.js} +1 -1
  2. package/dist/{bundle-state-D3RZHkXz.js → bundle-state-CFgzVHFP.js} +8 -2
  3. package/dist/{bundle-state-C-p9eFz1.mjs → bundle-state-CdNXQl-o.mjs} +2 -2
  4. package/dist/bundlers/shared/generator-css/directives.d.ts +1 -0
  5. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -0
  6. package/dist/bundlers/vite/generate-bundle.d.ts +3 -1
  7. package/dist/bundlers/vite/rewrite-css-imports.d.ts +8 -0
  8. package/dist/bundlers/vite/serve-css-generation.d.ts +5 -0
  9. package/dist/bundlers/vite/uni-app-x-css-options.d.ts +2 -0
  10. package/dist/{chunk-D6vf50IK.js → chunk-emK7D4bc.js} +7 -0
  11. package/dist/core.js +1 -1
  12. package/dist/core.mjs +1 -1
  13. package/dist/css-macro.js +3 -3
  14. package/dist/{defaults-C5w9OOrj.js → defaults-BPUuNYcD.js} +1 -1
  15. package/dist/defaults.js +1 -1
  16. package/dist/{generator-DRHWC1t-.mjs → generator-Bgn4m8An.mjs} +1 -1
  17. package/dist/{generator-DaPOkJ7W.js → generator-C56PJYxA.js} +2 -2
  18. package/dist/generator.js +2 -2
  19. package/dist/generator.mjs +2 -2
  20. package/dist/gulp.js +6 -6
  21. package/dist/gulp.mjs +5 -5
  22. package/dist/{incremental-runtime-class-set-Dt-FUQB5.mjs → incremental-runtime-class-set-BEYHQkZc.mjs} +238 -44
  23. package/dist/{incremental-runtime-class-set-BYV0yQdp.js → incremental-runtime-class-set-Bmzdjlk0.js} +239 -45
  24. package/dist/index.js +4 -4
  25. package/dist/index.mjs +4 -4
  26. package/dist/{postcss-Du8hY-MN.js → postcss-B7QNe78h.js} +57 -10
  27. package/dist/{postcss-CJrmfXvi.mjs → postcss-BgINK7Nm.mjs} +55 -8
  28. package/dist/postcss-html-transform.js +1 -1
  29. package/dist/postcss.js +1 -1
  30. package/dist/postcss.mjs +1 -1
  31. package/dist/{precheck-lfenbOTF.mjs → precheck-Copn2SqE.mjs} +14 -3
  32. package/dist/{precheck-DgpVCvYk.js → precheck-CyPbGn38.js} +17 -6
  33. package/dist/presets.js +9 -5
  34. package/dist/presets.mjs +7 -3
  35. package/dist/reset.js +1 -1
  36. package/dist/{source-candidates-D7b-Jzsx.mjs → source-candidates-BODCmzz5.mjs} +1 -1
  37. package/dist/{source-candidates-B4NvId_j.js → source-candidates-Caf2GDvx.js} +2 -2
  38. package/dist/{tailwindcss-D5RogwtV.mjs → tailwindcss-C0Zgo3Es.mjs} +1 -1
  39. package/dist/{tailwindcss-26ZFr5kv.js → tailwindcss-Tw6CSVHL.js} +3 -3
  40. package/dist/transform-95ivJthq.js +14868 -0
  41. package/dist/transform-DgCFGtQR.mjs +14871 -0
  42. package/dist/uni-app-x/vite.d.ts +3 -0
  43. package/dist/{utils-nta4tfFs.js → utils-Dolmt8EO.js} +1 -1
  44. package/dist/{v3-engine-CBahpuIg.js → v3-engine-6FVAcrZl.js} +31 -6
  45. package/dist/{v3-engine-BCUGX3gX.mjs → v3-engine-Ji6AXPh2.mjs} +24 -5
  46. package/dist/{vite-tjYalmVX.js → vite-Bw6LOXvf.js} +733 -79
  47. package/dist/{vite-DS4H5d0f.mjs → vite-ChZ2cbn4.mjs} +745 -91
  48. package/dist/vite.js +1 -1
  49. package/dist/vite.mjs +1 -1
  50. package/dist/weapp-tw-css-import-rewrite-loader.js +247 -45
  51. package/dist/{webpack-CA-40WU9.mjs → webpack-CMJ7iqN7.mjs} +6 -6
  52. package/dist/{webpack-0BwLOE_f.js → webpack-nn3P8_S_.js} +8 -8
  53. package/dist/webpack.js +1 -1
  54. package/dist/webpack.mjs +1 -1
  55. package/package.json +3 -4
  56. package/dist/transform-Crn84vTL.js +0 -257
  57. package/dist/transform-FAxHXVZp.mjs +0 -255
@@ -1,16 +1,16 @@
1
- import { E as normalizeTailwindConfigDirectives, I as hasTailwindGeneratedCssMarkers, J as filterUnsupportedMiniProgramTailwindV4Candidates, O as normalizeTailwindSourceForGenerator, T as hasTailwindSourceDirectives, _ as resolveViteSourceScanEntries, ct as createDebug, dt as findTailwindConfig, ft as resolveTailwindcssOptions, g as resolveTailwindV4EntriesFromCssCached, gt as findNearestPackageRoot, ht as omitUndefined, l as getRuntimeClassSetSignature, m as discoverTailwindV4CssEntries, ot as resolveTailwindV4CssSourceBase, p as createViteSourceScanMatcher, v as resolveViteTailwindV4CssDependencies, w as hasTailwindRootDirectives } from "./v3-engine-BCUGX3gX.mjs";
2
- import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-DRHWC1t-.mjs";
3
- import { _ as collectRuntimeClassSet, a as vitePluginName, b as refreshTailwindRuntimeState, g as toCustomAttributesEntities, n as getCompilerContext, t as shouldSkipJsTransform, v as createTailwindRuntimeReadyPromise } from "./precheck-lfenbOTF.mjs";
1
+ import { C as hasLocalCssImport, D as normalizeTailwindConfigDirectives, E as hasTailwindSourceDirectives, L as hasTailwindGeneratedCssMarkers, M as removeTailwindSourceDirectives, T as hasTailwindRootDirectives, Y as filterUnsupportedMiniProgramTailwindV4Candidates, _ as resolveViteSourceScanEntries, _t as findNearestPackageRoot, ft as findTailwindConfig, g as resolveTailwindV4EntriesFromCssCached, gt as omitUndefined, j as parseImportRequest, k as normalizeTailwindSourceForGenerator, l as getRuntimeClassSetSignature, lt as createDebug, m as discoverTailwindV4CssEntries, p as createViteSourceScanMatcher, pt as resolveTailwindcssOptions, st as resolveTailwindV4CssSourceBase, v as resolveViteTailwindV4CssDependencies, w as hasTailwindApplyDirective } from "./v3-engine-Ji6AXPh2.mjs";
2
+ import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-Bgn4m8An.mjs";
3
+ import { _ as collectRuntimeClassSet, a as vitePluginName, b as refreshTailwindRuntimeState, g as toCustomAttributesEntities, n as getCompilerContext, t as shouldSkipJsTransform, v as createTailwindRuntimeReadyPromise } from "./precheck-Copn2SqE.mjs";
4
4
  import { o as resolveUniUtsPlatform } from "./utils-DsaS975I.mjs";
5
- import { a as normalizeCssEntries, c as hasConfiguredTailwindV4CssRoots, i as resolveUniAppXOptions, l as upsertTailwindV4CssSource, r as isUniAppXEnabled } from "./tailwindcss-D5RogwtV.mjs";
6
- import { a as validateCandidatesByGenerator, i as generateCssByGenerator, n as createHmrTimingRecorder, o as mergeMarkedUserLayerComponentsCss, s as processCachedTask, t as createBundleRuntimeClassSetManager } from "./incremental-runtime-class-set-Dt-FUQB5.mjs";
7
- import { n as createTailwindV3DefaultExtractor, r as isSourceCandidateRequest, t as createSourceCandidateCollector } from "./source-candidates-D7b-Jzsx.mjs";
8
- import { S as toAbsoluteOutputPath, _ as slash, a as applyLinkedResults, b as normalizeOutputPathKey, c as createBundlerGeneratedCssMarker, d as stripBundlerGeneratedCssMarkers, f as resolvePackageDir, g as isCSSRequest, h as formatPostcssSourceMap, i as createRuntimeAffectingSourceSignature, l as hasBundlerGeneratedCssMarker, m as cleanUrl, n as createBundleBuildState, o as createBundleModuleGraphOptions, p as resolvePluginDisabledState, r as updateBundleBuildState, s as pushConcurrentTaskFactories, t as buildBundleSnapshot, u as parseBundlerGeneratedCssMarkerBlocks, v as isSourceStyleRequest } from "./bundle-state-C-p9eFz1.mjs";
5
+ import { a as normalizeCssEntries, c as hasConfiguredTailwindV4CssRoots, i as resolveUniAppXOptions, l as upsertTailwindV4CssSource, r as isUniAppXEnabled } from "./tailwindcss-C0Zgo3Es.mjs";
6
+ import { a as validateCandidatesByGenerator, i as generateCssByGenerator, n as createHmrTimingRecorder, o as mergeMarkedUserLayerComponentsCss, s as processCachedTask, t as createBundleRuntimeClassSetManager } from "./incremental-runtime-class-set-BEYHQkZc.mjs";
7
+ import { n as createTailwindV3DefaultExtractor, r as isSourceCandidateRequest, t as createSourceCandidateCollector } from "./source-candidates-BODCmzz5.mjs";
8
+ import { C as toAbsoluteOutputPath, _ as normalizePath, a as applyLinkedResults, b as stripRequestQuery, c as createBundlerGeneratedCssMarker, d as stripBundlerGeneratedCssMarkers, f as resolvePackageDir, g as isCSSRequest, h as formatPostcssSourceMap, i as createRuntimeAffectingSourceSignature, l as hasBundlerGeneratedCssMarker, m as cleanUrl, n as createBundleBuildState, o as createBundleModuleGraphOptions, p as resolvePluginDisabledState, r as updateBundleBuildState, s as pushConcurrentTaskFactories, t as buildBundleSnapshot, u as parseBundlerGeneratedCssMarkerBlocks, v as slash, x as normalizeOutputPathKey, y as isSourceStyleRequest } from "./bundle-state-CdNXQl-o.mjs";
9
9
  import { t as logger$1 } from "./logger-BNzxZbZj.mjs";
10
10
  import fs, { existsSync, readFileSync } from "node:fs";
11
11
  import postcss from "postcss";
12
12
  import { splitCandidateTokens } from "tailwindcss-patch";
13
- import process from "node:process";
13
+ import process$1 from "node:process";
14
14
  import path from "node:path";
15
15
  import { logger } from "@weapp-tailwindcss/logger";
16
16
  import { readFile } from "node:fs/promises";
@@ -58,7 +58,7 @@ function resolveUniAppXStyleIsolationEnabled(root) {
58
58
  //#region src/uni-app-x/vite.ts
59
59
  let transformUVuePromise;
60
60
  function loadTransformUVue() {
61
- transformUVuePromise ?? (transformUVuePromise = import("./transform-FAxHXVZp.mjs").then((mod) => mod.transformUVue));
61
+ transformUVuePromise ?? (transformUVuePromise = import("./transform-DgCFGtQR.mjs").then((mod) => mod.transformUVue));
62
62
  return transformUVuePromise;
63
63
  }
64
64
  const preprocessorLangs = new Set([
@@ -72,6 +72,7 @@ const INLINE_LANG_RE = /lang\.([a-z]+)/i;
72
72
  const PREPROCESSOR_EXT_RE = /\.(?:scss|sass|less|styl|stylus)(?:\?|$)/i;
73
73
  const UVUE_NVUE_QUERY_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
74
74
  const UVUE_NVUE_RE = /\.(?:uvue|nvue)$/;
75
+ const CSS_MODULE_EXPORT_RE = /^\s*export\s+default\s+(?:\{|\w|\[\])/;
75
76
  function isPreprocessorRequest(id, lang) {
76
77
  const normalizedLang = lang?.toLowerCase();
77
78
  if (normalizedLang && preprocessorLangs.has(normalizedLang)) return true;
@@ -85,8 +86,11 @@ function resolveUniAppXCssTarget(id) {
85
86
  function resolveUniAppXJsTransformEnabled$1(uniAppX) {
86
87
  return uniAppX === void 0 ? true : isUniAppXEnabled(uniAppX);
87
88
  }
89
+ function isCssModuleExport(code) {
90
+ return CSS_MODULE_EXPORT_RE.test(code);
91
+ }
88
92
  function createUniAppXPlugins(options) {
89
- const { appType, customAttributesEntities, disabledDefaultTemplateHandler, isIosPlatform: providedIosPlatform, mainCssChunkMatcher, runtimeState, styleHandler, jsHandler, ensureRuntimeClassSet, getResolvedConfig, uniAppX } = options;
93
+ const { appType, customAttributesEntities, disabledDefaultTemplateHandler, isIosPlatform: providedIosPlatform, mainCssChunkMatcher, runtimeState, styleHandler, generateCss, jsHandler, ensureRuntimeClassSet, getResolvedConfig, uniAppX } = options;
90
94
  const resolvedUniAppXOptions = resolveUniAppXOptions(uniAppX);
91
95
  const isIosPlatform = providedIosPlatform ?? resolveUniUtsPlatform().isAppIos;
92
96
  const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
@@ -105,9 +109,12 @@ function createUniAppXPlugins(options) {
105
109
  componentLocalStyleEnabled = resolveUniAppXStyleIsolationEnabled(root);
106
110
  return componentLocalStyleEnabled;
107
111
  }
108
- async function transformStyle(code, id, query) {
112
+ async function transformStyle(code, id, query, hookContext) {
109
113
  const parsed = query ?? parseVueRequest(id).query;
110
114
  if (isCSSRequest(id) || parsed.vue && parsed.type === "style") {
115
+ if (isCssModuleExport(code)) return;
116
+ const generatedCss = hasTailwindSourceDirectives(code, { importFallback: true }) || hasTailwindApplyDirective(code) ? await generateCss?.(id, code, hookContext) : void 0;
117
+ const styleCode = typeof generatedCss === "string" && generatedCss.trim().length > 0 ? generatedCss : code;
111
118
  const cacheKey = `${mainCssChunkMatcher(id, appType) ? "1" : "0"}:${id}`;
112
119
  let styleHandlerOptions = cssHandlerOptionsCache.get(cacheKey);
113
120
  if (!styleHandlerOptions) {
@@ -126,10 +133,10 @@ function createUniAppXPlugins(options) {
126
133
  });
127
134
  cssHandlerOptionsCache.set(cacheKey, styleHandlerOptions);
128
135
  }
129
- const postcssResult = await styleHandler(code, styleHandlerOptions);
136
+ const postcssResult = await styleHandler(styleCode, styleHandlerOptions);
130
137
  const warnings = typeof postcssResult.warnings === "function" ? postcssResult.warnings() : [];
131
138
  for (const warning of warnings) logger$1.warn(warning.toString());
132
- const postcssMap = await formatPostcssSourceMap(postcssResult.map.toJSON(), cleanUrl(id));
139
+ const postcssMap = await formatPostcssSourceMap(postcssResult.map.toJSON(), normalizePath(cleanUrl(id)));
133
140
  return {
134
141
  code: postcssResult.css,
135
142
  map: postcssMap
@@ -140,7 +147,7 @@ function createUniAppXPlugins(options) {
140
147
  name: "weapp-tailwindcss:uni-app-x:css",
141
148
  async transform(code, id) {
142
149
  await runtimeState.readyPromise;
143
- return transformStyle(code, id);
150
+ return transformStyle(code, id, void 0, this);
144
151
  }
145
152
  }, {
146
153
  name: "weapp-tailwindcss:uni-app-x:css:pre",
@@ -150,7 +157,7 @@ function createUniAppXPlugins(options) {
150
157
  const { query } = parseVueRequest(id);
151
158
  const lang = query.lang;
152
159
  if (isIosPlatform && isPreprocessorRequest(id, lang)) return;
153
- return transformStyle(code, id, query);
160
+ return transformStyle(code, id, query, this);
154
161
  }
155
162
  }];
156
163
  const nvuePlugin = {
@@ -304,10 +311,12 @@ function createCssHandlerOptionsCache(options) {
304
311
  const isMainChunk = options.mainCssChunkMatcher(file, appType);
305
312
  const outputRoot = options.getOutputRoot?.();
306
313
  const from = outputRoot ? path.resolve(outputRoot, file) : file;
307
- const cacheKey = `${majorVersion ?? "unknown"}:${appType ?? "unknown"}:${isMainChunk ? "1" : "0"}:${outputRoot ?? ""}:${file}`;
314
+ const extraOptions = options.getExtraOptions?.(file) ?? {};
315
+ const cacheKey = `${majorVersion ?? "unknown"}:${appType ?? "unknown"}:${isMainChunk ? "1" : "0"}:${outputRoot ?? ""}:${file}:${JSON.stringify(extraOptions)}`;
308
316
  const cached = cssHandlerOptionsCache.get(cacheKey);
309
317
  if (cached) return cached;
310
318
  const created = {
319
+ ...extraOptions,
311
320
  isMainChunk,
312
321
  postcssOptions: { options: { from } },
313
322
  majorVersion,
@@ -550,6 +559,452 @@ function hasRuntimeAffectingSourceChanges(changedByType) {
550
559
  return changedByType.html.size > 0 || changedByType.js.size > 0;
551
560
  }
552
561
  //#endregion
562
+ //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
563
+ let _lazyMatch = () => {
564
+ var __lib__ = (() => {
565
+ var m = Object.defineProperty, V = Object.getOwnPropertyDescriptor, G = Object.getOwnPropertyNames, T = Object.prototype.hasOwnProperty, q = (r, e) => {
566
+ for (var n in e) m(r, n, {
567
+ get: e[n],
568
+ enumerable: true
569
+ });
570
+ }, H = (r, e, n, a) => {
571
+ if (e && typeof e == "object" || typeof e == "function") for (let t of G(e)) !T.call(r, t) && t !== n && m(r, t, {
572
+ get: () => e[t],
573
+ enumerable: !(a = V(e, t)) || a.enumerable
574
+ });
575
+ return r;
576
+ }, J = (r) => H(m({}, "__esModule", { value: true }), r), w = {};
577
+ q(w, { default: () => re });
578
+ var A = (r) => Array.isArray(r), d = (r) => typeof r == "function", Q = (r) => r.length === 0, W = (r) => typeof r == "number", K = (r) => typeof r == "object" && r !== null, X = (r) => r instanceof RegExp, b = (r) => typeof r == "string", h = (r) => r === void 0, Y = (r) => {
579
+ const e = /* @__PURE__ */ new Map();
580
+ return (n) => {
581
+ const a = e.get(n);
582
+ if (a) return a;
583
+ const t = r(n);
584
+ return e.set(n, t), t;
585
+ };
586
+ }, rr = (r, e, n = {}) => {
587
+ const a = {
588
+ cache: {},
589
+ input: r,
590
+ index: 0,
591
+ indexMax: 0,
592
+ options: n,
593
+ output: []
594
+ };
595
+ if (v(e)(a) && a.index === r.length) return a.output;
596
+ throw new Error(`Failed to parse at index ${a.indexMax}`);
597
+ }, i = (r, e) => A(r) ? er(r, e) : b(r) ? ar(r, e) : nr(r, e), er = (r, e) => {
598
+ const n = {};
599
+ for (const a of r) {
600
+ if (a.length !== 1) throw new Error(`Invalid character: "${a}"`);
601
+ const t = a.charCodeAt(0);
602
+ n[t] = true;
603
+ }
604
+ return (a) => {
605
+ const t = a.index, o = a.input;
606
+ for (; a.index < o.length && o.charCodeAt(a.index) in n;) a.index += 1;
607
+ const u = a.index;
608
+ if (u > t) {
609
+ if (!h(e) && !a.options.silent) {
610
+ const s = a.input.slice(t, u), c = d(e) ? e(s, o, String(t)) : e;
611
+ h(c) || a.output.push(c);
612
+ }
613
+ a.indexMax = Math.max(a.indexMax, a.index);
614
+ }
615
+ return true;
616
+ };
617
+ }, nr = (r, e) => {
618
+ const n = r.source, a = r.flags.replace(/y|$/, "y"), t = new RegExp(n, a);
619
+ return g((o) => {
620
+ t.lastIndex = o.index;
621
+ const u = t.exec(o.input);
622
+ if (u) {
623
+ if (!h(e) && !o.options.silent) {
624
+ const s = d(e) ? e(...u, o.input, String(o.index)) : e;
625
+ h(s) || o.output.push(s);
626
+ }
627
+ return o.index += u[0].length, o.indexMax = Math.max(o.indexMax, o.index), true;
628
+ } else return false;
629
+ });
630
+ }, ar = (r, e) => (n) => {
631
+ if (n.input.startsWith(r, n.index)) {
632
+ if (!h(e) && !n.options.silent) {
633
+ const t = d(e) ? e(r, n.input, String(n.index)) : e;
634
+ h(t) || n.output.push(t);
635
+ }
636
+ return n.index += r.length, n.indexMax = Math.max(n.indexMax, n.index), true;
637
+ } else return false;
638
+ }, C = (r, e, n, a) => {
639
+ const t = v(r);
640
+ return g(_(M((o) => {
641
+ let u = 0;
642
+ for (; u < n;) {
643
+ const s = o.index;
644
+ if (!t(o) || (u += 1, o.index === s)) break;
645
+ }
646
+ return u >= e;
647
+ })));
648
+ }, tr = (r, e) => C(r, 0, 1), f = (r, e) => C(r, 0, Infinity), x = (r, e) => {
649
+ const n = r.map(v);
650
+ return g(_(M((a) => {
651
+ for (let t = 0, o = n.length; t < o; t++) if (!n[t](a)) return false;
652
+ return true;
653
+ })));
654
+ }, l = (r, e) => {
655
+ const n = r.map(v);
656
+ return g(_((a) => {
657
+ for (let t = 0, o = n.length; t < o; t++) if (n[t](a)) return true;
658
+ return false;
659
+ }));
660
+ }, M = (r, e = false) => {
661
+ const n = v(r);
662
+ return (a) => {
663
+ const t = a.index, o = a.output.length, u = n(a);
664
+ return (!u || e) && (a.index = t, a.output.length !== o && (a.output.length = o)), u;
665
+ };
666
+ }, _ = (r, e) => {
667
+ return v(r);
668
+ }, g = (() => {
669
+ let r = 0;
670
+ return (e) => {
671
+ const n = v(e), a = r += 1;
672
+ return (t) => {
673
+ var o;
674
+ if (t.options.memoization === false) return n(t);
675
+ const u = t.index, s = (o = t.cache)[a] || (o[a] = /* @__PURE__ */ new Map()), c = s.get(u);
676
+ if (c === false) return false;
677
+ if (W(c)) return t.index = c, true;
678
+ if (c) return t.index = c.index, c.output?.length && t.output.push(...c.output), true;
679
+ {
680
+ const Z = t.output.length;
681
+ if (n(t)) {
682
+ const D = t.index, U = t.output.length;
683
+ if (U > Z) {
684
+ const ee = t.output.slice(Z, U);
685
+ s.set(u, {
686
+ index: D,
687
+ output: ee
688
+ });
689
+ } else s.set(u, D);
690
+ return true;
691
+ } else return s.set(u, false), false;
692
+ }
693
+ };
694
+ };
695
+ })(), E = (r) => {
696
+ let e;
697
+ return (n) => (e || (e = v(r())), e(n));
698
+ }, v = Y((r) => {
699
+ if (d(r)) return Q(r) ? E(r) : r;
700
+ if (b(r) || X(r)) return i(r);
701
+ if (A(r)) return x(r);
702
+ if (K(r)) return l(Object.values(r));
703
+ throw new Error("Invalid rule");
704
+ }), P = "abcdefghijklmnopqrstuvwxyz", ir = (r) => {
705
+ let e = "";
706
+ for (; r > 0;) e = P[(r - 1) % 26] + e, r = Math.floor((r - 1) / 26);
707
+ return e;
708
+ }, O = (r) => {
709
+ let e = 0;
710
+ for (let n = 0, a = r.length; n < a; n++) e = e * 26 + P.indexOf(r[n]) + 1;
711
+ return e;
712
+ }, S = (r, e) => {
713
+ if (e < r) return S(e, r);
714
+ const n = [];
715
+ for (; r <= e;) n.push(r++);
716
+ return n;
717
+ }, or = (r, e, n) => S(r, e).map((a) => String(a).padStart(n, "0")), R = (r, e) => S(O(r), O(e)).map(ir), p = (r) => r, z = (r) => ur((e) => rr(e, r, { memoization: false }).join("")), ur = (r) => {
718
+ const e = {};
719
+ return (n) => e[n] ?? (e[n] = r(n));
720
+ }, sr = i(/^\*\*\/\*$/, ".*"), cr = i(/^\*\*\/(\*)?([ a-zA-Z0-9._-]+)$/, (r, e, n) => `.*${e ? "" : "(?:^|/)"}${n.replaceAll(".", "\\.")}`), lr = i(/^\*\*\/(\*)?([ a-zA-Z0-9._-]*)\{([ a-zA-Z0-9._-]+(?:,[ a-zA-Z0-9._-]+)*)\}$/, (r, e, n, a) => `.*${e ? "" : "(?:^|/)"}${n.replaceAll(".", "\\.")}(?:${a.replaceAll(",", "|").replaceAll(".", "\\.")})`), y = i(/\\./, p), pr = i(/[$.*+?^(){}[\]\|]/, (r) => `\\${r}`), vr = i(/./, p), fr = l([i(/^(?:!!)*!(.*)$/, (r, e) => `(?!^${L(e)}$).*?`), i(/^(!!)+/, "")]), j = l([
721
+ i(/\/(\*\*\/)+/, "(?:/.+/|/)"),
722
+ i(/^(\*\*\/)+/, "(?:^|.*/)"),
723
+ i(/\/(\*\*)$/, "(?:/.*|$)"),
724
+ i(/\*\*/, ".*")
725
+ ]), N = l([i(/\*\/(?!\*\*\/)/, "[^/]*/"), i(/\*/, "[^/]*")]), k = i("?", "[^/]"), $r = i("[", p), wr = i("]", p), Ar = i(/[!^]/, "^/"), br = i(/[a-z]-[a-z]|[0-9]-[0-9]/i, p), Er = l([
726
+ y,
727
+ i(/[$.*+?^(){}[\|]/, (r) => `\\${r}`),
728
+ br,
729
+ i(/[^\]]/, p)
730
+ ]), B = x([
731
+ $r,
732
+ tr(Ar),
733
+ f(Er),
734
+ wr
735
+ ]), Pr = i("{", "(?:"), Or = i("}", ")"), I = x([
736
+ Pr,
737
+ l([
738
+ i(/(\d+)\.\.(\d+)/, (r, e, n) => or(+e, +n, Math.min(e.length, n.length)).join("|")),
739
+ i(/([a-z]+)\.\.([a-z]+)/, (r, e, n) => R(e, n).join("|")),
740
+ i(/([A-Z]+)\.\.([A-Z]+)/, (r, e, n) => R(e.toLowerCase(), n.toLowerCase()).join("|").toUpperCase())
741
+ ]),
742
+ Or
743
+ ]), kr = i("{", "(?:"), Br = i("}", ")"), Ir = i(",", "|"), Fr = i(/[$.*+?^(){[\]\|]/, (r) => `\\${r}`), Lr = i(/[^}]/, p), F = x([
744
+ kr,
745
+ f(l([
746
+ j,
747
+ N,
748
+ k,
749
+ B,
750
+ I,
751
+ E(() => F),
752
+ y,
753
+ Fr,
754
+ Ir,
755
+ Lr
756
+ ])),
757
+ Br
758
+ ]), L = z(f(l([
759
+ sr,
760
+ cr,
761
+ lr,
762
+ fr,
763
+ j,
764
+ N,
765
+ k,
766
+ B,
767
+ I,
768
+ F,
769
+ y,
770
+ pr,
771
+ vr
772
+ ]))), Tr = i(/\\./, p), qr = i(/./, p), Yr = z(f(l([
773
+ Tr,
774
+ i(/\*\*\*+/, "*"),
775
+ i(/([^/{[(!])\*\*/, (r, e) => `${e}*`),
776
+ i(/(^|.)\*\*(?=[^*/)\]}])/, (r, e) => `${e}*`),
777
+ qr
778
+ ]))), $ = (r, e) => {
779
+ const n = Array.isArray(r) ? r : [r];
780
+ if (!n.length) return false;
781
+ const a = n.map($.compile), t = n.every((s) => /(\/(?:\*\*)?|\[\/\])$/.test(s)), o = e.replace(/[\\\/]+/g, "/").replace(/\/$/, t ? "/" : "");
782
+ return a.some((s) => s.test(o));
783
+ };
784
+ $.compile = (r) => new RegExp(`^${L(Yr(r))}$`, "s");
785
+ var re = $;
786
+ return J(w);
787
+ })();
788
+ return __lib__.default || __lib__;
789
+ };
790
+ let _match;
791
+ const zeptomatch = (path, pattern) => {
792
+ if (!_match) {
793
+ _match = _lazyMatch();
794
+ _lazyMatch = null;
795
+ }
796
+ return _match(path, pattern);
797
+ };
798
+ const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
799
+ function normalizeWindowsPath(input = "") {
800
+ if (!input) return input;
801
+ return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
802
+ }
803
+ const _UNC_REGEX = /^[/\\]{2}/;
804
+ const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
805
+ const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
806
+ const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
807
+ const _EXTNAME_RE = /.(\.[^./]+|\.)$/;
808
+ const _PATH_ROOT_RE = /^[/\\]|^[a-zA-Z]:[/\\]/;
809
+ const normalize = function(path) {
810
+ if (path.length === 0) return ".";
811
+ path = normalizeWindowsPath(path);
812
+ const isUNCPath = path.match(_UNC_REGEX);
813
+ const isPathAbsolute = isAbsolute(path);
814
+ const trailingSeparator = path[path.length - 1] === "/";
815
+ path = normalizeString(path, !isPathAbsolute);
816
+ if (path.length === 0) {
817
+ if (isPathAbsolute) return "/";
818
+ return trailingSeparator ? "./" : ".";
819
+ }
820
+ if (trailingSeparator) path += "/";
821
+ if (_DRIVE_LETTER_RE.test(path)) path += "/";
822
+ if (isUNCPath) {
823
+ if (!isPathAbsolute) return `//./${path}`;
824
+ return `//${path}`;
825
+ }
826
+ return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
827
+ };
828
+ const join = function(...segments) {
829
+ let path = "";
830
+ for (const seg of segments) {
831
+ if (!seg) continue;
832
+ if (path.length > 0) {
833
+ const pathTrailing = path[path.length - 1] === "/";
834
+ const segLeading = seg[0] === "/";
835
+ if (pathTrailing && segLeading) path += seg.slice(1);
836
+ else path += pathTrailing || segLeading ? seg : `/${seg}`;
837
+ } else path += seg;
838
+ }
839
+ return normalize(path);
840
+ };
841
+ function cwd() {
842
+ if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
843
+ return "/";
844
+ }
845
+ const resolve = function(...arguments_) {
846
+ arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
847
+ let resolvedPath = "";
848
+ let resolvedAbsolute = false;
849
+ for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
850
+ const path = index >= 0 ? arguments_[index] : cwd();
851
+ if (!path || path.length === 0) continue;
852
+ resolvedPath = `${path}/${resolvedPath}`;
853
+ resolvedAbsolute = isAbsolute(path);
854
+ }
855
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
856
+ if (resolvedAbsolute && !isAbsolute(resolvedPath)) return `/${resolvedPath}`;
857
+ return resolvedPath.length > 0 ? resolvedPath : ".";
858
+ };
859
+ function normalizeString(path, allowAboveRoot) {
860
+ let res = "";
861
+ let lastSegmentLength = 0;
862
+ let lastSlash = -1;
863
+ let dots = 0;
864
+ let char = null;
865
+ for (let index = 0; index <= path.length; ++index) {
866
+ if (index < path.length) char = path[index];
867
+ else if (char === "/") break;
868
+ else char = "/";
869
+ if (char === "/") {
870
+ if (lastSlash === index - 1 || dots === 1);
871
+ else if (dots === 2) {
872
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
873
+ if (res.length > 2) {
874
+ const lastSlashIndex = res.lastIndexOf("/");
875
+ if (lastSlashIndex === -1) {
876
+ res = "";
877
+ lastSegmentLength = 0;
878
+ } else {
879
+ res = res.slice(0, lastSlashIndex);
880
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
881
+ }
882
+ lastSlash = index;
883
+ dots = 0;
884
+ continue;
885
+ } else if (res.length > 0) {
886
+ res = "";
887
+ lastSegmentLength = 0;
888
+ lastSlash = index;
889
+ dots = 0;
890
+ continue;
891
+ }
892
+ }
893
+ if (allowAboveRoot) {
894
+ res += res.length > 0 ? "/.." : "..";
895
+ lastSegmentLength = 2;
896
+ }
897
+ } else {
898
+ if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
899
+ else res = path.slice(lastSlash + 1, index);
900
+ lastSegmentLength = index - lastSlash - 1;
901
+ }
902
+ lastSlash = index;
903
+ dots = 0;
904
+ } else if (char === "." && dots !== -1) ++dots;
905
+ else dots = -1;
906
+ }
907
+ return res;
908
+ }
909
+ const isAbsolute = function(p) {
910
+ return _IS_ABSOLUTE_RE.test(p);
911
+ };
912
+ const toNamespacedPath = function(p) {
913
+ return normalizeWindowsPath(p);
914
+ };
915
+ const extname = function(p) {
916
+ if (p === "..") return "";
917
+ const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
918
+ return match && match[1] || "";
919
+ };
920
+ const relative = function(from, to) {
921
+ const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
922
+ const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
923
+ if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) return _to.join("/");
924
+ const _fromCopy = [..._from];
925
+ for (const segment of _fromCopy) {
926
+ if (_to[0] !== segment) break;
927
+ _from.shift();
928
+ _to.shift();
929
+ }
930
+ return [..._from.map(() => ".."), ..._to].join("/");
931
+ };
932
+ const dirname = function(p) {
933
+ const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
934
+ if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
935
+ return segments.join("/") || (isAbsolute(p) ? "/" : ".");
936
+ };
937
+ const format = function(p) {
938
+ const ext = p.ext ? p.ext.startsWith(".") ? p.ext : `.${p.ext}` : "";
939
+ const segments = [
940
+ p.root,
941
+ p.dir,
942
+ p.base ?? (p.name ?? "") + ext
943
+ ].filter(Boolean);
944
+ return normalizeWindowsPath(p.root ? resolve(...segments) : segments.join("/"));
945
+ };
946
+ const basename = function(p, extension) {
947
+ const segments = normalizeWindowsPath(p).split("/");
948
+ let lastSegment = "";
949
+ for (let i = segments.length - 1; i >= 0; i--) {
950
+ const val = segments[i];
951
+ if (val) {
952
+ lastSegment = val;
953
+ break;
954
+ }
955
+ }
956
+ return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
957
+ };
958
+ const parse$1 = function(p) {
959
+ const root = _PATH_ROOT_RE.exec(p)?.[0]?.replace(/\\/g, "/") || "";
960
+ const base = basename(p);
961
+ const extension = extname(base);
962
+ return {
963
+ root,
964
+ dir: dirname(p),
965
+ base,
966
+ ext: extension,
967
+ name: base.slice(0, base.length - extension.length)
968
+ };
969
+ };
970
+ const matchesGlob = (path, pattern) => {
971
+ return zeptomatch(pattern, normalize(path));
972
+ };
973
+ const _path = {
974
+ __proto__: null,
975
+ basename,
976
+ dirname,
977
+ extname,
978
+ format,
979
+ isAbsolute,
980
+ join,
981
+ matchesGlob,
982
+ normalize,
983
+ normalizeString,
984
+ parse: parse$1,
985
+ relative,
986
+ resolve,
987
+ sep: "/",
988
+ toNamespacedPath
989
+ };
990
+ //#endregion
991
+ //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.mjs
992
+ const delimiter = /* @__PURE__ */ (() => globalThis.process?.platform === "win32" ? ";" : ":")();
993
+ const _platforms = {
994
+ posix: void 0,
995
+ win32: void 0
996
+ };
997
+ const mix = (del = delimiter) => {
998
+ return new Proxy(_path, { get(_, prop) {
999
+ if (prop === "delimiter") return del;
1000
+ if (prop === "posix") return posix;
1001
+ if (prop === "win32") return win32;
1002
+ return _platforms[prop] || _path[prop];
1003
+ } });
1004
+ };
1005
+ const posix = /* @__PURE__ */ mix(":");
1006
+ const win32 = /* @__PURE__ */ mix(";");
1007
+ //#endregion
553
1008
  //#region src/bundlers/vite/processed-css-assets.ts
554
1009
  const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
555
1010
  function isCssOutputFile(file) {
@@ -566,11 +1021,53 @@ function appendCss(baseCss, css) {
566
1021
  if (css.length === 0) return baseCss;
567
1022
  return `${baseCss}\n${css}`;
568
1023
  }
1024
+ function removeTailwindSourceMediaWrappers(css) {
1025
+ if (!css.includes("@media source(")) return css;
1026
+ try {
1027
+ const root = postcss.parse(css);
1028
+ let changed = false;
1029
+ root.walkAtRules("media", (atRule) => {
1030
+ if (!atRule.params.startsWith("source(")) return;
1031
+ if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
1032
+ else atRule.remove();
1033
+ changed = true;
1034
+ });
1035
+ root.walkAtRules((atRule) => {
1036
+ if (atRule.nodes && atRule.nodes.length === 0) {
1037
+ atRule.remove();
1038
+ changed = true;
1039
+ }
1040
+ });
1041
+ return changed ? root.toString() : css;
1042
+ } catch {
1043
+ return css.replace(/@media\s+source\([^)]*\)\s*\{\s*\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/?\s*\}/gi, "").replace(/@media\s+source\([^)]*\)\s*\{\s*\}/gi, "");
1044
+ }
1045
+ }
1046
+ function removeTailwindEntryDirectivesFromCss(css) {
1047
+ return removeTailwindSourceDirectives(removeTailwindSourceMediaWrappers(css));
1048
+ }
569
1049
  function stripStyleExtension(file) {
570
1050
  return file.replace(/[?#].*$/, "").replace(/\.(?:css|wxss|acss|ttss|qss|jxss|tyss|scss|sass|less|styl|stylus|pcss|postcss)$/i, "");
571
1051
  }
572
- function isAppOriginCssFile$1(file) {
573
- return stripStyleExtension(file).split("/").pop() === "app-origin";
1052
+ function isStyleImportRequest(request) {
1053
+ return typeof request === "string" && request.length > 0 && !/^(?:https?:)?\/\//i.test(request) && /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(request);
1054
+ }
1055
+ function resolveImportedStyleFile(targetFile, request) {
1056
+ if (!isStyleImportRequest(request)) return;
1057
+ const cleanRequest = request.replace(/[?#].*$/, "");
1058
+ if (cleanRequest.startsWith("/")) return normalizeOutputPathKey(cleanRequest.slice(1));
1059
+ const targetDir = posix.posix.dirname(normalizeOutputPathKey(targetFile));
1060
+ return normalizeOutputPathKey(posix.posix.join(targetDir === "." ? "" : targetDir, cleanRequest));
1061
+ }
1062
+ function collectImportedStyleFiles(css, targetFile) {
1063
+ const imports = /* @__PURE__ */ new Set();
1064
+ try {
1065
+ postcss.parse(css).walkAtRules("import", (atRule) => {
1066
+ const importedFile = resolveImportedStyleFile(targetFile, parseImportRequest(atRule.params));
1067
+ if (importedFile) imports.add(importedFile);
1068
+ });
1069
+ } catch {}
1070
+ return imports;
574
1071
  }
575
1072
  function normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile) {
576
1073
  return resolveViteProcessedCssOutputFile?.(markerFile) ?? markerFile;
@@ -587,6 +1084,7 @@ function resolveViteProcessedCssAssetSource(file, rawSource, resolveViteProcesse
587
1084
  }
588
1085
  function shouldInjectViteProcessedCssResult(opts, targetFile, sourceFile, options) {
589
1086
  if (options.injectIntoMain === true) return true;
1087
+ if (options.injectIntoMain === false) return false;
590
1088
  const targetFileKey = normalizeOutputPathKey(targetFile);
591
1089
  const sourceFileKey = normalizeOutputPathKey(sourceFile);
592
1090
  const sourceBaseName = sourceFileKey.replace(/\.(?:css|wxss|acss|ttss|qss|jxss|tyss)$/i, "").split("/").pop();
@@ -604,7 +1102,7 @@ function collectViteProcessedCssAssetResults(bundle, options) {
604
1102
  options.markCssAssetProcessed?.(output, file);
605
1103
  options.recordCssAssetResult?.(file, nextCss);
606
1104
  const resolvedOutputFile = options.resolveViteProcessedCssOutputFile?.(file) ?? file;
607
- const shouldReplayIntoMainCss = options.opts != null && (normalizeOutputPathKey(resolvedOutputFile) !== normalizeOutputPathKey(file) && options.opts.mainCssChunkMatcher(resolvedOutputFile, options.opts.appType) || isAppOriginCssFile$1(file));
1105
+ const shouldReplayIntoMainCss = options.opts != null && normalizeOutputPathKey(resolvedOutputFile) !== normalizeOutputPathKey(file) && options.opts.mainCssChunkMatcher(resolvedOutputFile, options.opts.appType);
608
1106
  options.recordViteProcessedCssAssetResult?.(file, nextCss, { injectIntoMain: shouldReplayIntoMainCss || void 0 });
609
1107
  options.debug?.("collect vite-processed css asset: %s bytes=%d", file, nextCss.length);
610
1108
  collected++;
@@ -631,9 +1129,11 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
631
1129
  if (!options.opts.cssMatcher(file) || !options.opts.mainCssChunkMatcher(file, options.opts.appType)) continue;
632
1130
  const mainFileKey = normalizeOutputPathKey(file);
633
1131
  const originalSource = readAssetSource(output);
634
- let nextCss = originalSource;
1132
+ let nextCss = removeTailwindEntryDirectivesFromCss(originalSource);
1133
+ const importedStyleFiles = collectImportedStyleFiles(nextCss, file);
635
1134
  for (const record of viteCssResults) {
636
1135
  if (!shouldInjectViteProcessedCssResult(options.opts, mainFileKey, record.file, record)) continue;
1136
+ if (importedStyleFiles.has(normalizeOutputPathKey(record.file))) continue;
637
1137
  const css = stripBundlerGeneratedCssMarkers(record.css).trim();
638
1138
  if (css.length === 0) continue;
639
1139
  const mergedLayerCss = mergeMarkedUserLayerComponentsCss(nextCss, css);
@@ -655,6 +1155,16 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
655
1155
  return injected;
656
1156
  }
657
1157
  //#endregion
1158
+ //#region src/bundlers/vite/uni-app-x-css-options.ts
1159
+ function resolveUniAppXNativeCssHandlerOptions(opts) {
1160
+ if (opts.appType !== "uni-app-x" || !isUniAppXEnabled(opts.uniAppX) || !resolveUniUtsPlatform().isApp) return {};
1161
+ return {
1162
+ uniAppX: true,
1163
+ uniAppXCssTarget: "uvue",
1164
+ uniAppXUnsupported: resolveUniAppXOptions(opts.uniAppX).uvueUnsupported
1165
+ };
1166
+ }
1167
+ //#endregion
658
1168
  //#region src/bundlers/vite/generate-bundle.ts
659
1169
  function addSiblingCssFile(files, file) {
660
1170
  if (file.endsWith(".wxml")) files.add(file.replace(/\.wxml$/, ".wxss"));
@@ -679,9 +1189,9 @@ function resolveViteCssOutputFile(file, opts, isWebGeneratorTarget) {
679
1189
  if (isWebGeneratorTarget || opts.cssMatcher(file) || !SOURCE_STYLE_OUTPUT_EXT_RE.test(file) || !isCSSRequest(file)) return file;
680
1190
  return file.replace(SOURCE_STYLE_OUTPUT_EXT_RE, ".wxss");
681
1191
  }
682
- function resolveViteCssPipelineOutputFile(file, _opts, rootDir, isWebGeneratorTarget = false) {
1192
+ function resolveViteCssPipelineOutputFile(file, _opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false) {
683
1193
  const normalizedFile = resolveReplayCssOutputFile(rootDir, file);
684
- if (isWebGeneratorTarget || MINI_PROGRAM_STYLE_OUTPUT_EXT_RE.test(normalizedFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(normalizedFile) || !isCSSRequest(normalizedFile)) return normalizedFile;
1194
+ if (isWebGeneratorTarget || preserveCssExtension || MINI_PROGRAM_STYLE_OUTPUT_EXT_RE.test(normalizedFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(normalizedFile) || !isCSSRequest(normalizedFile)) return normalizedFile;
685
1195
  return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, ".wxss");
686
1196
  }
687
1197
  function canProcessViteSourceStyleAsCss(source, file) {
@@ -708,9 +1218,15 @@ function stripStyleFileExtension(file) {
708
1218
  function isAppOriginCssFile(file) {
709
1219
  return path.basename(stripStyleFileExtension(file)) === "app-origin";
710
1220
  }
1221
+ function isMainAppCssFile(file) {
1222
+ return path.basename(stripStyleFileExtension(file)) === "app";
1223
+ }
711
1224
  function normalizeCssSourceForCompare(css) {
712
1225
  return css.trim();
713
1226
  }
1227
+ function createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash) {
1228
+ return `${cssRuntimeSignature}:${cssRuntimeAffectingHash}`;
1229
+ }
714
1230
  async function createScopedGeneratorCandidateSignature(rawSource, sourceFile, fallbackSignature, getSourceCandidatesForEntries, options = {}) {
715
1231
  if (!getSourceCandidatesForEntries || !rawSource.includes("@source")) return fallbackSignature;
716
1232
  const resolved = await resolveTailwindV4EntriesFromCssCached(rawSource, path.dirname(path.resolve(sourceFile.replace(/[?#].*$/, ""))));
@@ -749,10 +1265,35 @@ function collectParentDirectories(file) {
749
1265
  return directories;
750
1266
  }
751
1267
  function hasMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot) {
1268
+ return scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot) > 0;
1269
+ }
1270
+ function scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot) {
752
1271
  const outputBases = collectStyleFileMatchBases(outputFile, [outputRoot]);
753
1272
  const sourceBases = collectStyleFileMatchBases(sourceFile, [sourceRoot, ...collectParentDirectories(sourceFile)]);
754
- for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`)) return true;
755
- return false;
1273
+ let bestScore = 0;
1274
+ for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
1275
+ else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
1276
+ else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
1277
+ return bestScore;
1278
+ }
1279
+ function findRememberedCssSource(sources, outputFile, file, originalSource, outputRoot, sourceRoot) {
1280
+ if (!sources) return;
1281
+ const rememberedSources = [...sources].map(([, remembered]) => remembered);
1282
+ const originalFiles = [
1283
+ file,
1284
+ originalSource.originalFileName,
1285
+ ...originalSource.originalFileNames ?? []
1286
+ ].filter((item) => typeof item === "string" && item.length > 0);
1287
+ const sourceMatched = rememberedSources.find((remembered) => originalFiles.some((originalFile) => normalizeOutputPathKey(remembered.sourceFile) === normalizeOutputPathKey(originalFile)));
1288
+ if (sourceMatched) return sourceMatched;
1289
+ const outputMatched = rememberedSources.find((remembered) => normalizeOutputPathKey(remembered.outputFile) === normalizeOutputPathKey(outputFile));
1290
+ if (outputMatched) return outputMatched;
1291
+ const scoredMatches = rememberedSources.filter((remembered) => !(isMainAppCssFile(outputFile) && isAppOriginCssFile(remembered.outputFile))).map((remembered) => ({
1292
+ remembered,
1293
+ score: Math.max(scoreMatchingStyleFileBase(outputFile, remembered.sourceFile, outputRoot, sourceRoot), scoreMatchingStyleFileBase(outputFile, remembered.outputFile, outputRoot, sourceRoot))
1294
+ })).filter((match) => match.score > 0).sort((a, b) => b.score - a.score);
1295
+ const bestScore = scoredMatches[0]?.score;
1296
+ return bestScore && scoredMatches.filter((match) => match.score === bestScore).length === 1 ? scoredMatches[0]?.remembered : void 0;
756
1297
  }
757
1298
  function collectConfiguredTailwindV4CssSources(opts) {
758
1299
  const patcherCssSources = opts.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssSources ?? [];
@@ -815,18 +1356,20 @@ function createGenerateBundleHook(context) {
815
1356
  getAppType: () => context.opts.appType,
816
1357
  mainCssChunkMatcher: context.opts.mainCssChunkMatcher,
817
1358
  getMajorVersion: () => context.runtimeState.twPatcher.majorVersion,
818
- getOutputRoot: () => currentOutDir
1359
+ getOutputRoot: () => currentOutDir,
1360
+ getExtraOptions: () => resolveUniAppXNativeCssHandlerOptions(context.opts)
819
1361
  });
820
1362
  return async function generateBundle(_opt, bundle) {
821
1363
  const addWatchFile = (id) => this.addWatchFile?.(id);
822
- const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getViteProcessedCssAssetResult, getSourceCandidates, getSourceCandidatesForEntries, waitForSourceCandidateSyncs, rememberCssSource, getRememberedCssSources, getRememberedCssSignature, setRememberedCssSignature, recordGeneratorCandidates, hmrTimingRecorder } = context;
1364
+ const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getViteProcessedCssAssetResult, getSourceCandidates, getSourceCandidatesForEntries, waitForSourceCandidateSyncs, rememberCssSource, refreshRememberedCssSource, getRememberedCssSources, getRememberedCssSignature, setRememberedCssSignature, recordGeneratorCandidates, hmrTimingRecorder } = context;
823
1365
  const { cache, onEnd, onStart, onUpdate, styleHandler, templateHandler, jsHandler, uniAppX } = opts;
824
1366
  const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
825
1367
  const isWebGeneratorTarget = generatorOptions.target === "web";
1368
+ const isNativeAppStyleTarget = resolveUniUtsPlatform().isApp;
826
1369
  const shouldGenerateWebCssByGenerator = isWebGeneratorTarget && runtimeState.twPatcher.majorVersion === 3;
827
1370
  const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
828
1371
  const resolvedConfig = getResolvedConfig();
829
- const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process.cwd();
1372
+ const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
830
1373
  const outDir = resolvedConfig?.build?.outDir ? path.resolve(rootDir, resolvedConfig.build.outDir) : rootDir;
831
1374
  await runtimeState.readyPromise;
832
1375
  debug("start");
@@ -837,7 +1380,7 @@ function createGenerateBundleHook(context) {
837
1380
  markCssAssetProcessed,
838
1381
  recordCssAssetResult,
839
1382
  recordViteProcessedCssAssetResult,
840
- resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget),
1383
+ resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget),
841
1384
  debug
842
1385
  });
843
1386
  const hmrTimingStartedAt = performance.now();
@@ -854,11 +1397,11 @@ function createGenerateBundleHook(context) {
854
1397
  }
855
1398
  };
856
1399
  const metrics = createEmptyMetrics();
857
- const forceRuntimeRefreshByEnv = process.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
858
- const disableDirtyOptimization = process.env["WEAPP_TW_VITE_DISABLE_DIRTY"] === "1";
859
- const disableJsPrecheck = process.env["WEAPP_TW_VITE_DISABLE_JS_PRECHECK"] === "1";
860
- const debugCssDiff = process.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1";
861
- const disableV3OxideSourceRuntime = process.env["WEAPP_TW_VITE_DISABLE_V3_OXIDE_RUNTIME"] === "1";
1400
+ const forceRuntimeRefreshByEnv = process$1.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
1401
+ const disableDirtyOptimization = process$1.env["WEAPP_TW_VITE_DISABLE_DIRTY"] === "1";
1402
+ const disableJsPrecheck = process$1.env["WEAPP_TW_VITE_DISABLE_JS_PRECHECK"] === "1";
1403
+ const debugCssDiff = process$1.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1";
1404
+ const disableV3OxideSourceRuntime = process$1.env["WEAPP_TW_VITE_DISABLE_V3_OXIDE_RUNTIME"] === "1";
862
1405
  const bundleFiles = Object.keys(bundle);
863
1406
  const buildCommand = resolvedConfig?.command === "build";
864
1407
  const hasPreviousBundleState = state.iteration > 0 || state.sourceHashByFile.size > 0;
@@ -1033,29 +1576,30 @@ function createGenerateBundleHook(context) {
1033
1576
  const viteProcessedCssAsset = isViteProcessedCssAsset?.(originalSource, file) === true || hasViteProcessedCssRecord;
1034
1577
  const cssAssetProcessed = isCssAssetProcessed?.(originalSource, file) === true;
1035
1578
  const alreadyProcessedCssAsset = viteProcessedCssAsset || cssAssetProcessed;
1036
- const rememberedCssSource = viteProcessedCssAsset && getRememberedCssSources != null ? [...getRememberedCssSources()].map(([, remembered]) => remembered).find((remembered) => {
1037
- const originalFiles = [
1038
- file,
1039
- originalSource.originalFileName,
1040
- ...originalSource.originalFileNames ?? []
1041
- ].filter((item) => typeof item === "string" && item.length > 0);
1042
- return normalizeOutputPathKey(remembered.outputFile) === normalizeOutputPathKey(outputFile) || originalFiles.some((originalFile) => normalizeOutputPathKey(remembered.sourceFile) === normalizeOutputPathKey(originalFile));
1043
- }) : void 0;
1044
- const generatorRawSource = viteProcessedCssAsset ? rememberedCssSource?.rawSource ?? rawSource : rawSource;
1045
- const generatorSourceFile = viteProcessedCssAsset ? rememberedCssSource?.sourceFile ?? file : file;
1579
+ let rememberedCssSource = findRememberedCssSource(getRememberedCssSources?.(), outputFile, file, originalSource, outDir, opts.tailwindcssBasedir);
1580
+ if (rememberedCssSource != null) rememberedCssSource = await refreshRememberedCssSource?.(rememberedCssSource) ?? rememberedCssSource;
1581
+ const useRememberedCssSource = rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.sourceFile) !== normalizeOutputPathKey(file);
1582
+ const vitePipelineCssAsset = viteProcessedCssAsset || useRememberedCssSource;
1583
+ const generatorRawSource = vitePipelineCssAsset ? rememberedCssSource?.rawSource ?? rawSource : rawSource;
1584
+ const hasRememberedApplySource = vitePipelineCssAsset && rememberedCssSource != null && hasTailwindApplyDirective(generatorRawSource);
1585
+ const hasDifferentRememberedCssSource = rememberedCssSource != null && normalizeCssSourceForCompare(rememberedCssSource.rawSource) !== normalizeCssSourceForCompare(rawSource);
1586
+ const hasCurrentTailwindGenerationDirective = hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindApplyDirective(rawSource);
1587
+ const hasRememberedApplyDirective = rememberedCssSource != null && hasTailwindApplyDirective(rememberedCssSource.rawSource);
1588
+ const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective);
1589
+ const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? file : file;
1046
1590
  const outputCssHandlerOptions = getCssHandlerOptions(outputFile);
1047
- const cssHandlerOptions = viteProcessedCssAsset ? {
1591
+ const cssHandlerOptions = vitePipelineCssAsset ? {
1048
1592
  ...getCssHandlerOptions(generatorSourceFile),
1049
1593
  isMainChunk: outputCssHandlerOptions.isMainChunk || isAppOriginCssFile(file)
1050
1594
  } : getCssHandlerOptions(file);
1051
1595
  const generatorCssUserHandlerOptions = getCssUserHandlerOptions(generatorSourceFile);
1052
- const cssRuntimeAffectingSignature = snapshot.runtimeAffectingSignatureByFile.get(file) ?? createRuntimeAffectingSourceSignature(generatorRawSource, "css");
1053
- const cssRuntimeAffectingHash = snapshot.runtimeAffectingHashByFile.get(file) ?? cache.computeHash(cssRuntimeAffectingSignature);
1596
+ const cssRuntimeAffectingSignature = vitePipelineCssAsset ? createRuntimeAffectingSourceSignature(generatorRawSource, "css") : snapshot.runtimeAffectingSignatureByFile.get(file) ?? createRuntimeAffectingSourceSignature(generatorRawSource, "css");
1597
+ const cssRuntimeAffectingHash = vitePipelineCssAsset ? cache.computeHash(cssRuntimeAffectingSignature) : snapshot.runtimeAffectingHashByFile.get(file) ?? cache.computeHash(cssRuntimeAffectingSignature);
1054
1598
  const cssShareScope = createCssTransformShareScopeKey(opts, generatorSourceFile, generatorRawSource);
1055
1599
  const shouldRegenerateAppOriginCss = viteProcessedCssAsset && isAppOriginCssFile(file);
1056
- const shouldTrackGeneratorRuntime = shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || shouldRegenerateAppOriginCss);
1600
+ const shouldTrackGeneratorRuntime = hasStaleViteProcessedCssSource || shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || shouldRegenerateAppOriginCss);
1057
1601
  const canRegenerateProcessedMainCss = cssHandlerOptions.isMainChunk && (getViteProcessedCssAssetResult?.(file)?.injectIntoMain === true || shouldRegenerateAppOriginCss);
1058
- if (alreadyProcessedCssAsset && (!shouldTrackGeneratorRuntime || !canRegenerateProcessedMainCss)) {
1602
+ if (alreadyProcessedCssAsset && !hasStaleViteProcessedCssSource && !hasRememberedApplySource && (!shouldTrackGeneratorRuntime || !canRegenerateProcessedMainCss)) {
1059
1603
  const nextCss = stripBundlerGeneratedCssMarkers(rawSource);
1060
1604
  applyCssResult(nextCss);
1061
1605
  markCssAssetProcessed?.(originalSource, outputFile);
@@ -1067,6 +1611,7 @@ function createGenerateBundleHook(context) {
1067
1611
  const trackedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? generatorCandidateSignature : "generator:stable";
1068
1612
  const scopedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? await createScopedGeneratorCandidateSignature(generatorRawSource, generatorSourceFile, trackedGeneratorCandidateSignature, getSourceCandidatesForEntries, { includeFallbackSignature: cssHandlerOptions.isMainChunk }) : trackedGeneratorCandidateSignature;
1069
1613
  const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, scopedGeneratorCandidateSignature);
1614
+ const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
1070
1615
  const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.twPatcher.majorVersion ?? "unknown"}:${cssHandlerOptions.isMainChunk ? "1" : "0"}:${cssRuntimeAffectingSignature}`;
1071
1616
  if (!shouldTrackGeneratorRuntime) {
1072
1617
  const lastCss = lastCssResultByFile.get(outputFile) ?? lastCssResultByFile.get(file);
@@ -1082,7 +1627,7 @@ function createGenerateBundleHook(context) {
1082
1627
  cache,
1083
1628
  cacheKey: file,
1084
1629
  hashKey: `${file}:css:${cssRuntimeSignature}:${runtimeState.twPatcher.majorVersion ?? "unknown"}`,
1085
- hash: `${getSnapshotHash(snapshot.runtimeAffectingHashByFile, file, cssRuntimeAffectingHash)}:${scopedGeneratorCandidateSignature}`,
1630
+ hash: `${cssRuntimeAffectingHash}:${scopedGeneratorCandidateSignature}`,
1086
1631
  applyResult(source) {
1087
1632
  applyCssResult(source);
1088
1633
  lastCssResultByFile.set(outputFile, source);
@@ -1091,7 +1636,7 @@ function createGenerateBundleHook(context) {
1091
1636
  outputFile,
1092
1637
  rawSource: generatorRawSource,
1093
1638
  sourceFile: generatorSourceFile
1094
- }, cssRuntimeSignature);
1639
+ }, rememberedCssRuntimeSignature);
1095
1640
  },
1096
1641
  onCacheHit() {
1097
1642
  metrics.css.cacheHits++;
@@ -1111,7 +1656,7 @@ function createGenerateBundleHook(context) {
1111
1656
  const runTransform = async () => {
1112
1657
  const start = performance.now();
1113
1658
  await runtimeState.readyPromise;
1114
- const previousCss = useIncrementalMode && !hasRuntimeAffectingChanges && !snapshot.changedByType.css.has(file) ? lastCssResultByFile.get(outputFile) ?? lastCssResultByFile.get(file) : void 0;
1659
+ const previousCss = !vitePipelineCssAsset && useIncrementalMode && !hasRuntimeAffectingChanges && !snapshot.changedByType.css.has(file) ? lastCssResultByFile.get(outputFile) ?? lastCssResultByFile.get(file) : void 0;
1115
1660
  const generated = await generateCssByGenerator({
1116
1661
  opts,
1117
1662
  runtimeState,
@@ -1130,7 +1675,8 @@ function createGenerateBundleHook(context) {
1130
1675
  if (debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, generated.css));
1131
1676
  debug("css generated result: %s bytes=%d", file, generated.css.length);
1132
1677
  recordCssAssetResult?.(outputFile, generated.css);
1133
- if (viteProcessedCssAsset && cssHandlerOptions.isMainChunk) recordViteProcessedCssAssetResult?.(file, generated.css, { injectIntoMain: true });
1678
+ if (vitePipelineCssAsset && cssHandlerOptions.isMainChunk) recordViteProcessedCssAssetResult?.(file, generated.css, { injectIntoMain: !isAppOriginCssFile(file) });
1679
+ if (vitePipelineCssAsset) recordViteProcessedCssAssetResult?.(outputFile, generated.css, { injectIntoMain: false });
1134
1680
  metrics.css.elapsed += measureElapsed(start);
1135
1681
  metrics.css.transformed++;
1136
1682
  debug("css handle via tailwind v%s engine(%s): %s", runtimeState.twPatcher.majorVersion, generated.target, outputFile);
@@ -1142,8 +1688,8 @@ function createGenerateBundleHook(context) {
1142
1688
  debug("css preserve web target: %s", outputFile);
1143
1689
  return rawSource;
1144
1690
  }
1145
- const { css } = await styleHandler(rawSource, getCssHandlerOptions(file));
1146
- if (debugCssDiff) debug("css diff %s: %s", file, summarizeStringDiff(rawSource, css));
1691
+ const { css } = await styleHandler(generatorRawSource, cssHandlerOptions);
1692
+ if (debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, css));
1147
1693
  metrics.css.elapsed += measureElapsed(start);
1148
1694
  metrics.css.transformed++;
1149
1695
  return css;
@@ -1258,12 +1804,12 @@ function createGenerateBundleHook(context) {
1258
1804
  });
1259
1805
  }
1260
1806
  }
1261
- if (useIncrementalMode) for (const [key, remembered] of getRememberedCssSources?.() ?? []) {
1262
- const { outputFile: rememberedOutputFile, rawSource, sourceFile } = remembered;
1263
- const outputFile = resolveViteCssPipelineOutputFile(rememberedOutputFile, opts, rootDir, isWebGeneratorTarget);
1264
- const cssHandlerOptions = getCssHandlerOptions(sourceFile);
1265
- const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, await createScopedGeneratorCandidateSignature(rawSource, sourceFile, generatorCandidateSignature, getSourceCandidatesForEntries, { includeFallbackSignature: cssHandlerOptions.isMainChunk }));
1266
- if (bundleFiles.includes(outputFile) || bundleFiles.includes(sourceFile) || getRememberedCssSignature?.(key) === cssRuntimeSignature) continue;
1807
+ if (useIncrementalMode || isNativeAppStyleTarget) for (const [key, rememberedEntry] of getRememberedCssSources?.() ?? []) {
1808
+ const { outputFile: rememberedOutputFile, rawSource, sourceFile } = await refreshRememberedCssSource?.(rememberedEntry) ?? rememberedEntry;
1809
+ const outputFile = resolveViteCssPipelineOutputFile(rememberedOutputFile, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget);
1810
+ const cssHandlerOptions = getCssHandlerOptions(outputFile);
1811
+ const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(createCssRuntimeSignature(runtimeSignature, await createScopedGeneratorCandidateSignature(rawSource, sourceFile, generatorCandidateSignature, getSourceCandidatesForEntries, { includeFallbackSignature: cssHandlerOptions.isMainChunk })), cache.computeHash(createRuntimeAffectingSourceSignature(rawSource, "css")));
1812
+ if (bundleFiles.includes(outputFile) || bundleFiles.includes(sourceFile) || getRememberedCssSignature?.(key) === rememberedCssRuntimeSignature) continue;
1267
1813
  tasks.push(timeTask("css.replay", async () => {
1268
1814
  const start = performance.now();
1269
1815
  const generated = await generateCssByGenerator({
@@ -1273,13 +1819,13 @@ function createGenerateBundleHook(context) {
1273
1819
  rawSource,
1274
1820
  file: sourceFile,
1275
1821
  cssHandlerOptions,
1276
- cssUserHandlerOptions: getCssUserHandlerOptions(sourceFile),
1822
+ cssUserHandlerOptions: getCssUserHandlerOptions(outputFile),
1277
1823
  getSourceCandidatesForEntries,
1278
1824
  styleHandler,
1279
1825
  debug
1280
1826
  });
1281
1827
  const css = generated?.css ?? (await styleHandler(rawSource, cssHandlerOptions)).css;
1282
- setRememberedCssSignature?.(key, cssRuntimeSignature);
1828
+ setRememberedCssSignature?.(key, rememberedCssRuntimeSignature);
1283
1829
  if (generated) {
1284
1830
  registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
1285
1831
  recordCssAssetResult?.(outputFile, generated.css);
@@ -1346,6 +1892,7 @@ function registerGeneratorDependencies(ctx, dependencies) {
1346
1892
  }
1347
1893
  function createCssHandlerOptions(opts, majorVersion, file) {
1348
1894
  return {
1895
+ ...resolveUniAppXNativeCssHandlerOptions(opts),
1349
1896
  isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
1350
1897
  postcssOptions: { options: { from: file } },
1351
1898
  ...majorVersion === void 0 ? {} : { majorVersion }
@@ -1353,10 +1900,11 @@ function createCssHandlerOptions(opts, majorVersion, file) {
1353
1900
  }
1354
1901
  function shouldGenerateCssByGenerator(opts, file, rawSource, processed) {
1355
1902
  const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
1356
- if (generatorOptions.target === "web" && opts.twPatcher.majorVersion !== 3) return false;
1357
- if (hasTailwindGeneratedCssMarkers(rawSource) || hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return true;
1903
+ if (hasLocalCssImport(rawSource)) return false;
1904
+ if (hasTailwindGeneratedCssMarkers(rawSource)) return true;
1905
+ if (hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return true;
1358
1906
  if (opts.twPatcher.majorVersion === 3) return false;
1359
- return processed && shouldFinalizeProcessedCssAsset(opts, file);
1907
+ return processed && hasTailwindApplyDirective(rawSource) && shouldFinalizeProcessedCssAsset(opts, file);
1360
1908
  }
1361
1909
  function shouldFinalizeProcessedCssAsset(opts, file) {
1362
1910
  return opts.mainCssChunkMatcher(file, opts.appType);
@@ -1373,14 +1921,15 @@ function createViteCssFinalizerOutputPlugin(context) {
1373
1921
  if (resolvedConfig?.command !== "build") return;
1374
1922
  const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
1375
1923
  const isWebGeneratorTarget = generatorOptions.target === "web";
1376
- const rootDir = resolvedConfig.root ? path.resolve(resolvedConfig.root) : process.cwd();
1924
+ const isNativeAppStyleTarget = resolveUniUtsPlatform().isApp;
1925
+ const rootDir = resolvedConfig.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
1377
1926
  collectViteProcessedCssAssetResults(bundle, {
1378
1927
  opts,
1379
1928
  isViteProcessedCssAsset,
1380
1929
  markCssAssetProcessed,
1381
1930
  recordCssAssetResult,
1382
1931
  recordViteProcessedCssAssetResult,
1383
- resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget),
1932
+ resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget),
1384
1933
  debug
1385
1934
  });
1386
1935
  const isCssOutputAssetEntry = (entry) => {
@@ -1675,15 +2224,15 @@ function createRewriteCssImportsPlugins(options) {
1675
2224
  if (!isCSSRequest(id)) return null;
1676
2225
  const file = cleanUrl(id);
1677
2226
  const normalizedCode = hasTailwindRootDirectives(code) ? normalizeTailwindConfigDirectives(code, path.dirname(file)) : code;
1678
- if (hasTailwindRootDirectives(normalizedCode)) {
1679
- await options.onTailwindRootCss?.(id, normalizedCode);
1680
- if (options.shouldOwnTailwindGeneration) {
1681
- const generatedCss = await options.generateTailwindCss?.(id, normalizedCode, this);
1682
- if (generatedCss !== void 0) return {
1683
- code: generatedCss,
1684
- map: null
1685
- };
1686
- }
2227
+ await options.onCssSourceTransform?.(id, normalizedCode);
2228
+ const hasTailwindRoot = hasTailwindRootDirectives(normalizedCode);
2229
+ if (hasTailwindRoot) await options.onTailwindRootCss?.(id, normalizedCode);
2230
+ if (options.shouldOwnTailwindGeneration && (hasTailwindRoot || options.shouldGenerateCss?.(id, normalizedCode))) {
2231
+ const generatedCss = await options.generateTailwindCss?.(id, normalizedCode, this);
2232
+ if (generatedCss !== void 0) return {
2233
+ code: generatedCss,
2234
+ map: null
2235
+ };
1687
2236
  }
1688
2237
  if (!options.shouldRewrite) return null;
1689
2238
  const rewritten = rewriteTailwindcssImportsInCode(normalizedCode, weappTailwindcssDirPosix, {
@@ -1700,6 +2249,9 @@ function createRewriteCssImportsPlugins(options) {
1700
2249
  }
1701
2250
  }];
1702
2251
  }
2252
+ function hasVitePipelineTailwindGenerationDirective(code) {
2253
+ return hasTailwindRootDirectives(code) || hasTailwindApplyDirective(code);
2254
+ }
1703
2255
  //#endregion
1704
2256
  //#region src/bundlers/vite/runtime-class-set.ts
1705
2257
  function createViteRuntimeClassSet(options) {
@@ -1747,7 +2299,7 @@ function createViteRuntimeClassSet(options) {
1747
2299
  }
1748
2300
  }
1749
2301
  async function ensureRuntimeClassSet(force = false) {
1750
- const forceRuntimeRefresh = force || process.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
2302
+ const forceRuntimeRefresh = force || process$1.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
1751
2303
  await refreshRuntimeState(force);
1752
2304
  await runtimeState.readyPromise;
1753
2305
  if (!forceRuntimeRefresh && runtimeSet) return runtimeSet;
@@ -1768,7 +2320,7 @@ function createViteRuntimeClassSet(options) {
1768
2320
  }
1769
2321
  }
1770
2322
  async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false, options = {}) {
1771
- const forceRuntimeRefresh = forceRefresh || process.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
2323
+ const forceRuntimeRefresh = forceRefresh || process$1.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
1772
2324
  const invalidation = resolveRuntimeRefreshOptions();
1773
2325
  const shouldRefreshPatcher = forceRuntimeRefresh || invalidation.changed;
1774
2326
  const forceCollectBySource = snapshot.runtimeAffectingChangedByType.html.size > 0 || snapshot.runtimeAffectingChangedByType.js.size > 0;
@@ -1937,6 +2489,7 @@ const debug = createDebug();
1937
2489
  const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
1938
2490
  const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
1939
2491
  const sourceCandidateScanSnapshotCache = /* @__PURE__ */ new Map();
2492
+ const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
1940
2493
  function normalizeSignaturePath(value) {
1941
2494
  return slash(path.resolve(value));
1942
2495
  }
@@ -1964,6 +2517,17 @@ function createSourceCandidateScanSignature(input) {
1964
2517
  scanAllSources: input.scanAllSources ?? false
1965
2518
  });
1966
2519
  }
2520
+ function stripSourceHash(sourceFile) {
2521
+ const hashIndex = sourceFile.indexOf("#");
2522
+ return hashIndex === -1 ? sourceFile : sourceFile.slice(0, hashIndex);
2523
+ }
2524
+ function normalizeCssSourceIdentity(sourceFile) {
2525
+ const cleanSourceFile = stripSourceHash(sourceFile);
2526
+ const { filename, query } = parseVueRequest(cleanSourceFile);
2527
+ const normalizedFile = normalizeOutputPathKey(filename);
2528
+ if (query.type === "style") return `${normalizedFile}?type=style&index=${query.index ?? 0}`;
2529
+ return normalizeOutputPathKey(stripRequestQuery(cleanSourceFile));
2530
+ }
1967
2531
  /**
1968
2532
  * @name WeappTailwindcss
1969
2533
  * @description uni-app vite / uni-app-x 版本插件
@@ -1976,7 +2540,7 @@ function WeappTailwindcss(options = {}) {
1976
2540
  ...options,
1977
2541
  __internalDeferMissingCssEntriesWarning: true
1978
2542
  });
1979
- const normalizedCssEntries = normalizeCssEntries(options.cssEntries, opts.tailwindcssBasedir ?? process.cwd());
2543
+ const normalizedCssEntries = normalizeCssEntries(options.cssEntries, opts.tailwindcssBasedir ?? process$1.cwd());
1980
2544
  if (normalizedCssEntries) opts.cssEntries ?? (opts.cssEntries = normalizedCssEntries);
1981
2545
  if (opts.cssEntries?.length) {
1982
2546
  var _opts$tailwindcss, _opts$tailwindcss$v;
@@ -2109,7 +2673,7 @@ function WeappTailwindcss(options = {}) {
2109
2673
  const getSourceCandidates = () => sourceCandidateCollector.values();
2110
2674
  const getSourceCandidatesForEntries = (entries) => sourceCandidateCollector.valuesForEntries(entries);
2111
2675
  const isWatchBuild = () => resolvedConfig?.command === "build" && resolvedConfig.build.watch != null;
2112
- const isWatchLikeBuild = () => isWatchBuild() || resolvedConfig?.command === "serve" || process.env["WEAPP_TW_WATCH_REGRESSION"] === "1" || process.env["WEAPP_TW_HMR_TIMING"] === "1";
2676
+ const isWatchLikeBuild = () => isWatchBuild() || resolvedConfig?.command === "serve" || process$1.env["WEAPP_TW_WATCH_REGRESSION"] === "1" || process$1.env["WEAPP_TW_HMR_TIMING"] === "1";
2113
2677
  const hasSourceCandidateScanState = () => sourceCandidateScanSignature !== void 0;
2114
2678
  const normalizeSourceScanDependency = (file) => path.normalize(path.resolve(cleanUrl(file)));
2115
2679
  const isSourceScanDependency = (file) => sourceScanDependencies.has(normalizeSourceScanDependency(file));
@@ -2167,7 +2731,7 @@ function WeappTailwindcss(options = {}) {
2167
2731
  debug("reuse vite source candidate scan definition for watch rebuild");
2168
2732
  return;
2169
2733
  }
2170
- const root = resolvedConfig?.root ?? process.cwd();
2734
+ const root = resolvedConfig?.root ?? process$1.cwd();
2171
2735
  const outDir = resolvedConfig?.build?.outDir;
2172
2736
  const sourceScan = await resolveViteSourceScanEntries(opts, runtimeState.twPatcher, {
2173
2737
  outDir,
@@ -2215,18 +2779,19 @@ function WeappTailwindcss(options = {}) {
2215
2779
  const syncChangedSourceCandidateFile = (id) => {
2216
2780
  if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id)) return Promise.resolve();
2217
2781
  const file = cleanUrl(id);
2782
+ const refreshRememberedCssSourceTask = refreshRememberedCssSourceByCurrentFile(file);
2218
2783
  if (isSourceScanDependency(file)) invalidateSourceCandidateScan();
2219
2784
  if (sourceScanMatcher && !sourceScanMatcher(file)) {
2220
2785
  sourceCandidateCollector.remove(file);
2221
2786
  cacheCurrentSourceCandidateScan();
2222
- return Promise.resolve();
2787
+ return refreshRememberedCssSourceTask;
2223
2788
  }
2224
2789
  if (sourceScanExplicit && sourceScanEntries?.length === 0) {
2225
2790
  cacheCurrentSourceCandidateScan();
2226
- return Promise.resolve();
2791
+ return refreshRememberedCssSourceTask;
2227
2792
  }
2228
2793
  const existingTask = pendingSourceCandidateSyncByFile.get(file);
2229
- if (existingTask) return existingTask;
2794
+ if (existingTask) return Promise.all([refreshRememberedCssSourceTask, existingTask]).then(() => void 0);
2230
2795
  const task = sourceCandidateCollector.syncCurrentFile(id).catch((error) => {
2231
2796
  debug("source candidate watch sync failed: %s %O", id, error);
2232
2797
  }).then(() => {
@@ -2237,7 +2802,7 @@ function WeappTailwindcss(options = {}) {
2237
2802
  });
2238
2803
  pendingSourceCandidateSyncs.add(task);
2239
2804
  pendingSourceCandidateSyncByFile.set(file, task);
2240
- return task;
2805
+ return Promise.all([refreshRememberedCssSourceTask, task]).then(() => void 0);
2241
2806
  };
2242
2807
  const shouldCollectTransformedSourceCandidates = (id) => {
2243
2808
  if (id.search(/[?#]/) < 0) return true;
@@ -2246,8 +2811,85 @@ function WeappTailwindcss(options = {}) {
2246
2811
  };
2247
2812
  const rememberCssSource = (entry, cssRuntimeSignature) => {
2248
2813
  const key = normalizeOutputPathKey(entry.outputFile);
2814
+ const previous = rememberedCssSources.get(key);
2249
2815
  rememberedCssSources.set(key, entry);
2816
+ const normalizedSourceFile = normalizeCssSourceIdentity(entry.sourceFile);
2817
+ for (const [rememberedKey, remembered] of rememberedCssSources) {
2818
+ if (rememberedKey === key || normalizeCssSourceIdentity(remembered.sourceFile) !== normalizedSourceFile) continue;
2819
+ rememberedCssSources.set(rememberedKey, {
2820
+ ...remembered,
2821
+ rawSource: entry.rawSource,
2822
+ sourceFile: entry.sourceFile
2823
+ });
2824
+ rememberedCssSignatureByFile.delete(rememberedKey);
2825
+ }
2250
2826
  if (cssRuntimeSignature) rememberedCssSignatureByFile.set(key, cssRuntimeSignature);
2827
+ else if (previous?.rawSource !== entry.rawSource || previous?.sourceFile !== entry.sourceFile) rememberedCssSignatureByFile.delete(key);
2828
+ };
2829
+ const refreshRememberedCssSourceEntry = (rememberedKey, remembered, sourceFile, rawSource) => {
2830
+ if (remembered.rawSource === rawSource && remembered.sourceFile === sourceFile) return remembered;
2831
+ const nextRemembered = {
2832
+ ...remembered,
2833
+ rawSource,
2834
+ sourceFile
2835
+ };
2836
+ rememberedCssSources.set(rememberedKey, nextRemembered);
2837
+ rememberedCssSignatureByFile.delete(rememberedKey);
2838
+ return nextRemembered;
2839
+ };
2840
+ const refreshRememberedCssSourceBySourceFile = (sourceFile, rawSource) => {
2841
+ const normalizedSourceFile = normalizeCssSourceIdentity(sourceFile);
2842
+ for (const [rememberedKey, remembered] of rememberedCssSources) {
2843
+ if (normalizeCssSourceIdentity(remembered.sourceFile) !== normalizedSourceFile) continue;
2844
+ refreshRememberedCssSourceEntry(rememberedKey, remembered, sourceFile, rawSource);
2845
+ }
2846
+ };
2847
+ const extractSfcStyleBlock = (source, index) => {
2848
+ const targetIndex = index ?? 0;
2849
+ SFC_STYLE_BLOCK_RE.lastIndex = 0;
2850
+ let currentIndex = 0;
2851
+ let match = SFC_STYLE_BLOCK_RE.exec(source);
2852
+ while (match !== null) {
2853
+ if (currentIndex === targetIndex) return match[1] ?? "";
2854
+ currentIndex++;
2855
+ match = SFC_STYLE_BLOCK_RE.exec(source);
2856
+ }
2857
+ };
2858
+ const refreshRememberedCssSourceByCurrentFile = async (sourceFile) => {
2859
+ const file = cleanUrl(sourceFile);
2860
+ const normalizedSourceFile = normalizeOutputPathKey(file);
2861
+ const matchedRememberedSources = [...rememberedCssSources.values()].filter((remembered) => normalizeOutputPathKey(stripRequestQuery(cleanUrl(remembered.sourceFile))) === normalizedSourceFile);
2862
+ if (matchedRememberedSources.length === 0) return;
2863
+ try {
2864
+ const source = await readFile(file, "utf8");
2865
+ if (/\.(?:vue|uvue|nvue|svelte|mpx)$/i.test(file)) {
2866
+ for (const remembered of matchedRememberedSources) {
2867
+ const { query } = parseVueRequest(remembered.sourceFile);
2868
+ const styleSource = extractSfcStyleBlock(source, query.type === "style" ? query.index : void 0);
2869
+ if (styleSource !== void 0) refreshRememberedCssSourceBySourceFile(remembered.sourceFile, styleSource);
2870
+ }
2871
+ return;
2872
+ }
2873
+ if (isSourceStyleRequest(file)) refreshRememberedCssSourceBySourceFile(file, source);
2874
+ } catch (error) {
2875
+ debug("refresh remembered css source failed: %s %O", file, error);
2876
+ }
2877
+ };
2878
+ const refreshRememberedCssSource = async (remembered) => {
2879
+ const file = cleanUrl(stripRequestQuery(remembered.sourceFile));
2880
+ const rememberedKey = [...rememberedCssSources.entries()].find(([, entry]) => entry === remembered)?.[0];
2881
+ if (!rememberedKey || !path.isAbsolute(file)) return;
2882
+ try {
2883
+ const source = await readFile(file, "utf8");
2884
+ if (/\.(?:vue|uvue|nvue|svelte|mpx)$/i.test(file)) {
2885
+ const { query } = parseVueRequest(remembered.sourceFile);
2886
+ const styleSource = extractSfcStyleBlock(source, query.type === "style" ? query.index : void 0);
2887
+ return styleSource === void 0 ? void 0 : refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, styleSource);
2888
+ }
2889
+ if (isSourceStyleRequest(file)) return refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, source);
2890
+ } catch (error) {
2891
+ debug("refresh remembered css source before bundle replay failed: %s %O", file, error);
2892
+ }
2251
2893
  };
2252
2894
  const getRememberedCssSources = () => rememberedCssSources;
2253
2895
  const getRememberedCssSourceEntry = (file) => rememberedCssSources.get(normalizeOutputPathKey(file));
@@ -2360,15 +3002,19 @@ function WeappTailwindcss(options = {}) {
2360
3002
  getAppType: () => opts.appType,
2361
3003
  mainCssChunkMatcher,
2362
3004
  getMajorVersion: () => runtimeState.twPatcher.majorVersion,
2363
- getOutputRoot: () => resolvedConfig?.build?.outDir ? path.resolve(resolvedConfig.root, resolvedConfig.build.outDir) : resolvedConfig?.root
3005
+ getOutputRoot: () => resolvedConfig?.build?.outDir ? path.resolve(resolvedConfig.root, resolvedConfig.build.outDir) : resolvedConfig?.root,
3006
+ getExtraOptions: () => resolveUniAppXNativeCssHandlerOptions(opts)
2364
3007
  });
2365
3008
  const generateTailwindCssForVitePipeline = async (id, code, hookContext) => {
2366
3009
  if (!shouldOwnTailwindGeneration) return;
2367
3010
  await runtimeState.readyPromise;
2368
3011
  await waitForSourceCandidateSyncs();
2369
3012
  const file = cleanUrl(id);
3013
+ const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
3014
+ const isNativeAppStyleTarget = resolveUniUtsPlatform().isApp;
3015
+ const outputFile = resolveViteCssPipelineOutputFile(file, opts, rootDir, generatorOptions.target === "web", isNativeAppStyleTarget);
2370
3016
  const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
2371
- const cssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(file);
3017
+ const cssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
2372
3018
  const generated = await generateCssByGenerator({
2373
3019
  opts,
2374
3020
  runtimeState,
@@ -2376,7 +3022,7 @@ function WeappTailwindcss(options = {}) {
2376
3022
  rawSource: code,
2377
3023
  file,
2378
3024
  cssHandlerOptions,
2379
- cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(file),
3025
+ cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(outputFile),
2380
3026
  getSourceCandidatesForEntries,
2381
3027
  styleHandler,
2382
3028
  debug,
@@ -2384,17 +3030,21 @@ function WeappTailwindcss(options = {}) {
2384
3030
  deferEmptyScopedCssSource: true
2385
3031
  });
2386
3032
  if (!generated) return;
2387
- const outputFile = resolveViteCssPipelineOutputFile(file, opts, resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process.cwd(), generatorOptions.target === "web");
2388
3033
  for (const dependency of generated.dependencies) hookContext?.addWatchFile?.(dependency);
2389
3034
  viteGeneratedCssByFile.set(file, generated.css);
2390
3035
  if (generated.css.includes("weapp-tailwindcss layer components start")) recordViteProcessedCssAssetResult(file, generated.css, { injectIntoMain: cssHandlerOptions.isMainChunk });
3036
+ if (isNativeAppStyleTarget && outputFile.endsWith(".css")) hookContext?.emitFile?.({
3037
+ type: "asset",
3038
+ fileName: outputFile,
3039
+ source: generated.css
3040
+ });
2391
3041
  markViteProcessedCssSource(file);
2392
3042
  rememberTailwindRootCssModule(id);
2393
3043
  recordGeneratorCandidates(runtime);
2394
3044
  rememberCssSource({
2395
3045
  outputFile,
2396
3046
  rawSource: code,
2397
- sourceFile: file
3047
+ sourceFile: id
2398
3048
  });
2399
3049
  debug("css generated for vite postcss pipeline: %s bytes=%d", file, generated.css.length);
2400
3050
  return `${createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}\n${generated.css}`;
@@ -2404,6 +3054,8 @@ function WeappTailwindcss(options = {}) {
2404
3054
  generateTailwindCss: generateTailwindCssForVitePipeline,
2405
3055
  rootImport: shouldOwnTailwindGeneration ? `${weappTailwindcssDirPosix}/generator-placeholder.css` : void 0,
2406
3056
  onTailwindRootCss: (id, code) => registerAutoCssSource(id, code),
3057
+ onCssSourceTransform: (id, code) => refreshRememberedCssSourceBySourceFile(id, code),
3058
+ shouldGenerateCss: (_id, code) => hasVitePipelineTailwindGenerationDirective(code),
2407
3059
  shouldOwnTailwindGeneration,
2408
3060
  shouldRewrite: shouldRewriteCssImports,
2409
3061
  weappTailwindcssDirPosix
@@ -2427,6 +3079,7 @@ function WeappTailwindcss(options = {}) {
2427
3079
  getSourceCandidatesForEntries,
2428
3080
  waitForSourceCandidateSyncs,
2429
3081
  rememberCssSource,
3082
+ refreshRememberedCssSource,
2430
3083
  getRememberedCssSources,
2431
3084
  getRememberedCssSignature,
2432
3085
  setRememberedCssSignature,
@@ -2469,6 +3122,7 @@ function WeappTailwindcss(options = {}) {
2469
3122
  mainCssChunkMatcher,
2470
3123
  runtimeState,
2471
3124
  styleHandler,
3125
+ generateCss: generateTailwindCssForVitePipeline,
2472
3126
  jsHandler,
2473
3127
  ensureRuntimeClassSet,
2474
3128
  getResolvedConfig,
@@ -2544,7 +3198,7 @@ function WeappTailwindcss(options = {}) {
2544
3198
  const removed = disableAndRemoveTailwindVitePlugins(config.plugins);
2545
3199
  if (removed > 0) debug("disable official tailwind vite plugins in generator mode: %d", removed);
2546
3200
  }
2547
- const root = config.root ? path.resolve(config.root) : process.cwd();
3201
+ const root = config.root ? path.resolve(config.root) : process$1.cwd();
2548
3202
  const baseConfig = { resolve: { alias: [{
2549
3203
  find: /^tailwindcss$/,
2550
3204
  replacement: path.join(weappTailwindcssPackageDir, "generator-placeholder.css")