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
@@ -14,15 +14,16 @@ node_path = require_watch_dependencies.__toESM(node_path);
14
14
  let node_util = require("node:util");
15
15
  let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
16
16
  let tailwindcss_patch = require("tailwindcss-patch");
17
+ tailwindcss_patch = require_watch_dependencies.__toESM(tailwindcss_patch);
17
18
  let node_module = require("node:module");
18
19
  let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
19
20
  let node_url = require("node:url");
20
21
  let debug = require("debug");
21
22
  debug = require_watch_dependencies.__toESM(debug);
22
23
  let node_fs_promises = require("node:fs/promises");
24
+ require("micromatch");
23
25
  require("fast-glob");
24
26
  let tailwindcss_config = require("tailwindcss-config");
25
- require("micromatch");
26
27
  let _weapp_core_escape = require("@weapp-core/escape");
27
28
  require("magic-string");
28
29
  let _babel_traverse = require("@babel/traverse");
@@ -63,66 +64,6 @@ function createBundlerGeneratedCssMarker(bundler, file) {
63
64
  return `/*! weapp-tailwindcss ${bundler}-generated-css:${encodeURIComponent(file)} */`;
64
65
  }
65
66
  //#endregion
66
- //#region src/uni-app-x/options.ts
67
- const DEFAULT_COMPONENT_LOCAL_STYLES_OPTIONS = {
68
- enabled: true,
69
- onlyWhenStyleIsolationVersion2: true
70
- };
71
- const DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS = {
72
- enabled: false,
73
- onlyWhenStyleIsolationVersion2: true
74
- };
75
- function isBooleanUniAppXShortcut(option) {
76
- return option === true || option === false || option === void 0;
77
- }
78
- function resolveComponentLocalStyles(option) {
79
- if (isBooleanUniAppXShortcut(option)) return DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS;
80
- const componentLocalStyles = option.componentLocalStyles;
81
- if (componentLocalStyles === false) return DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS;
82
- if (componentLocalStyles === true || componentLocalStyles === void 0) return DEFAULT_COMPONENT_LOCAL_STYLES_OPTIONS;
83
- return {
84
- enabled: componentLocalStyles.enabled !== false,
85
- onlyWhenStyleIsolationVersion2: componentLocalStyles.onlyWhenStyleIsolationVersion2 !== false
86
- };
87
- }
88
- function resolveUniAppXOptions(option) {
89
- if (typeof option === "object" && option) return {
90
- enabled: option.enabled !== false,
91
- componentLocalStyles: resolveComponentLocalStyles(option),
92
- uvueUnsupported: option.uvueUnsupported ?? "warn"
93
- };
94
- return {
95
- enabled: Boolean(option),
96
- componentLocalStyles: resolveComponentLocalStyles(option),
97
- uvueUnsupported: "warn"
98
- };
99
- }
100
- function isUniAppXEnabled(option) {
101
- return resolveUniAppXOptions(option).enabled;
102
- }
103
- //#endregion
104
- //#region src/context/style-options.ts
105
- function resolveStyleOptionsFromContext(ctx) {
106
- const resolvedUniAppXOptions = resolveUniAppXOptions(ctx.uniAppX);
107
- return {
108
- cssPreflight: ctx.cssPreflight,
109
- cssPreflightRange: ctx.cssPreflightRange,
110
- cssChildCombinatorReplaceValue: ctx.cssChildCombinatorReplaceValue,
111
- cssSelectorReplacement: ctx.cssSelectorReplacement,
112
- rem2rpx: ctx.rem2rpx,
113
- cssRemoveProperty: ctx.cssRemoveProperty,
114
- cssRemoveHoverPseudoClass: ctx.cssRemoveHoverPseudoClass,
115
- cssPresetEnv: ctx.cssPresetEnv,
116
- autoprefixer: ctx.autoprefixer,
117
- cssCalc: ctx.cssCalc,
118
- uniAppX: resolvedUniAppXOptions.enabled,
119
- platform: ctx.platform,
120
- px2rpx: ctx.px2rpx,
121
- unitsToPx: ctx.unitsToPx,
122
- unitConversion: ctx.unitConversion
123
- };
124
- }
125
- //#endregion
126
67
  //#region src/css-macro/constants.ts
127
68
  const queryKey = "weapp-tw-platform";
128
69
  const UNESCAPED_UNDERSCORE_RE = /(?<!\\)_/g;
@@ -465,6 +406,169 @@ async function transformCssMacroCss(css, options) {
465
406
  return compileCssMacroConditionalComments(result, options);
466
407
  }
467
408
  //#endregion
409
+ //#region src/utils/object.ts
410
+ function definedEntries(value) {
411
+ return Object.entries(value).filter(([, item]) => item !== void 0);
412
+ }
413
+ function omitUndefined(value) {
414
+ return Object.fromEntries(definedEntries(value));
415
+ }
416
+ //#endregion
417
+ //#region src/tailwindcss/v3-engine/generator/content.ts
418
+ function isLegacyContentObject$1(value) {
419
+ return typeof value === "object" && value !== null && "files" in value;
420
+ }
421
+ function createRawContentEntries(candidates, sources) {
422
+ const entries = [];
423
+ const candidateContent = [...candidates].join(" ");
424
+ if (candidateContent.length > 0) entries.push({
425
+ raw: candidateContent,
426
+ extension: "html"
427
+ });
428
+ for (const source of sources) entries.push({
429
+ raw: source.content,
430
+ extension: source.extension ?? "html"
431
+ });
432
+ return entries;
433
+ }
434
+ function createChangedContentEntries(candidates, sources) {
435
+ return createRawContentEntries(candidates, sources).map((entry) => ({
436
+ content: entry.raw,
437
+ extension: entry.extension
438
+ }));
439
+ }
440
+ function collectCandidates$1(candidates) {
441
+ return new Set(candidates ?? []);
442
+ }
443
+ function collectApplyCandidatesFromCss(css) {
444
+ if (!css.includes("@apply")) return [];
445
+ const candidates = /* @__PURE__ */ new Set();
446
+ try {
447
+ require_watch_dependencies.postcss_default.parse(css).walkAtRules("apply", (rule) => {
448
+ for (const candidate of rule.params.split(/\s+/)) {
449
+ const normalized = candidate.replace(/!important$/, "").trim();
450
+ if (normalized) candidates.add(normalized);
451
+ }
452
+ });
453
+ } catch {}
454
+ return [...candidates];
455
+ }
456
+ function isTailwindCandidateLayer(params) {
457
+ return params.split(/[,\s]+/).some((layer) => layer === "components" || layer === "utilities");
458
+ }
459
+ function extractClassCandidatesFromSelector(selector, candidates) {
460
+ for (let index = 0; index < selector.length; index++) {
461
+ if (selector[index] !== ".") continue;
462
+ let candidate = "";
463
+ let escaped = false;
464
+ for (let tokenIndex = index + 1; tokenIndex < selector.length; tokenIndex++) {
465
+ const char = selector[tokenIndex];
466
+ if (escaped) {
467
+ candidate += char;
468
+ escaped = false;
469
+ continue;
470
+ }
471
+ if (char === "\\") {
472
+ escaped = true;
473
+ continue;
474
+ }
475
+ if (char && /[\w-]/.test(char)) {
476
+ candidate += char;
477
+ continue;
478
+ }
479
+ break;
480
+ }
481
+ if (candidate) candidates.add(candidate);
482
+ }
483
+ }
484
+ function collectLayerCandidatesFromCss(css) {
485
+ if (!css.includes("@layer")) return [];
486
+ const candidates = /* @__PURE__ */ new Set();
487
+ try {
488
+ require_watch_dependencies.postcss_default.parse(css).walkAtRules("layer", (layer) => {
489
+ if (!isTailwindCandidateLayer(layer.params)) return;
490
+ layer.walkRules((rule) => {
491
+ extractClassCandidatesFromSelector(rule.selector, candidates);
492
+ });
493
+ });
494
+ } catch {}
495
+ return [...candidates];
496
+ }
497
+ function mergeGenerateCandidates(source, options) {
498
+ return collectCandidates$1([
499
+ ...collectLayerCandidatesFromCss(source.css),
500
+ ...collectApplyCandidatesFromCss(source.css),
501
+ ...collectCandidates$1(options.candidates)
502
+ ]);
503
+ }
504
+ function mergeContent(content, rawEntries) {
505
+ if (isLegacyContentObject$1(content)) return {
506
+ ...content,
507
+ relative: content.relative ?? true,
508
+ files: [...[].concat(content.files ?? []), ...rawEntries]
509
+ };
510
+ return {
511
+ relative: true,
512
+ files: [...[].concat(content ?? []), ...rawEntries]
513
+ };
514
+ }
515
+ function normalizeConfigObject(config) {
516
+ if (!config || typeof config !== "object") return config;
517
+ const maybeDefault = config.default;
518
+ if (maybeDefault && typeof maybeDefault === "object") return maybeDefault;
519
+ return config;
520
+ }
521
+ function hasExplicitContentInput(options) {
522
+ return options.candidates !== void 0 || options.sources !== void 0;
523
+ }
524
+ function createExplicitContentConfig(rawEntries) {
525
+ return {
526
+ relative: true,
527
+ files: rawEntries
528
+ };
529
+ }
530
+ function createTailwindConfig(source, options) {
531
+ const config = { ...normalizeConfigObject(source.configObject) ?? {} };
532
+ const rawEntries = createRawContentEntries(mergeGenerateCandidates(source, options), options.sources ?? []);
533
+ config.content = hasExplicitContentInput(options) ? createExplicitContentConfig(rawEntries) : mergeContent(config.content, rawEntries);
534
+ return config;
535
+ }
536
+ //#endregion
537
+ //#region src/tailwindcss/v3-engine/generator/cache-key.ts
538
+ function createStableJson$2(value) {
539
+ if (value === void 0) return "undefined";
540
+ if (value === null || typeof value !== "object") return JSON.stringify(value);
541
+ if (Array.isArray(value)) return `[${value.map((item) => createStableJson$2(item)).join(",")}]`;
542
+ return `{${Object.keys(value).sort().map((key) => {
543
+ const record = value;
544
+ return `${JSON.stringify(key)}:${createStableJson$2(record[key])}`;
545
+ }).join(",")}}`;
546
+ }
547
+ function createDependencyFingerprint$1(files) {
548
+ return files.map((file) => {
549
+ try {
550
+ const stat = node_fs.default.statSync(file);
551
+ return `${file}:${stat.size}:${stat.mtimeMs}`;
552
+ } catch {
553
+ return `${file}:missing`;
554
+ }
555
+ }).join("|");
556
+ }
557
+ function createIncrementalGenerateCacheKey$1(source, target, styleOptions, bareArbitraryValues) {
558
+ return [
559
+ source.packageName,
560
+ source.postcssPlugin,
561
+ source.cwd,
562
+ source.config ?? "config:missing",
563
+ createDependencyFingerprint$1(source.dependencies),
564
+ source.css,
565
+ createStableJson$2(normalizeConfigObject(source.configObject)?.content),
566
+ target,
567
+ createStableJson$2(styleOptions),
568
+ createStableJson$2(bareArbitraryValues)
569
+ ].join("\0");
570
+ }
571
+ //#endregion
468
572
  //#region src/context/workspace.ts
469
573
  function findWorkspaceRoot(startDir) {
470
574
  if (!startDir) return;
@@ -487,14 +591,6 @@ function findNearestPackageRoot(startDir) {
487
591
  }
488
592
  }
489
593
  //#endregion
490
- //#region src/utils/object.ts
491
- function definedEntries(value) {
492
- return Object.entries(value).filter(([, item]) => item !== void 0);
493
- }
494
- function omitUndefined(value) {
495
- return Object.fromEntries(definedEntries(value));
496
- }
497
- //#endregion
498
594
  //#region src/utils/options.ts
499
595
  function resolveBooleanObjectOption(value, enabledValue) {
500
596
  if (!value) return false;
@@ -665,7 +761,7 @@ function createTailwindcssPatcher(options) {
665
761
  const resolvedTailwindOptions = resolvedOptions.tailwindcss;
666
762
  if (resolvedTailwindOptions) {
667
763
  const existingResolve = resolvedTailwindOptions.resolve ?? {};
668
- const sourcePaths = Array.isArray(existingResolve.paths) && existingResolve.paths.length > 0 ? [...existingResolve.paths, ...resolvePaths] : resolvePaths;
764
+ const sourcePaths = Array.isArray(existingResolve.paths) && existingResolve.paths.length > 0 ? [...existingResolve.paths ?? [], ...resolvePaths] : resolvePaths;
669
765
  resolvedTailwindOptions.resolve = {
670
766
  ...existingResolve,
671
767
  paths: [...new Set(sourcePaths)]
@@ -727,104 +823,8 @@ function createDebug(prefix) {
727
823
  return debug$3;
728
824
  }
729
825
  //#endregion
730
- //#region src/tailwindcss/source-scan.ts
731
- const DEFAULT_SOURCE_SCAN_EXTENSIONS = [
732
- "html",
733
- "wxml",
734
- "axml",
735
- "jxml",
736
- "ksml",
737
- "ttml",
738
- "qml",
739
- "tyml",
740
- "xhsml",
741
- "swan",
742
- "vue",
743
- "mpx",
744
- "js",
745
- "jsx",
746
- "ts",
747
- "tsx"
748
- ];
749
- const FULL_SOURCE_SCAN_EXTENSIONS = [
750
- "js",
751
- "jsx",
752
- "mjs",
753
- "cjs",
754
- "ts",
755
- "tsx",
756
- "mts",
757
- "cts",
758
- "vue",
759
- "uvue",
760
- "nvue",
761
- "svelte",
762
- "mpx",
763
- "html",
764
- "wxml",
765
- "axml",
766
- "jxml",
767
- "ksml",
768
- "ttml",
769
- "qml",
770
- "tyml",
771
- "xhsml",
772
- "swan",
773
- "css",
774
- "wxss",
775
- "acss",
776
- "jxss",
777
- "ttss",
778
- "qss",
779
- "tyss",
780
- "scss",
781
- "sass",
782
- "less",
783
- "styl",
784
- "stylus"
785
- ];
786
- function createSourceScanPattern(extensions = DEFAULT_SOURCE_SCAN_EXTENSIONS) {
787
- return `**/*.{${extensions.join(",")}}`;
788
- }
789
- const FULL_SOURCE_SCAN_PATTERN = createSourceScanPattern(FULL_SOURCE_SCAN_EXTENSIONS);
790
- new RegExp(`\\.(?:${FULL_SOURCE_SCAN_EXTENSIONS.map((extension) => extension.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})$`);
791
- function resolveTailwindV4CssSourceBase(source, fallbackBase) {
792
- if (typeof source.base === "string" && source.base.length > 0) return source.base;
793
- if (typeof source.file === "string" && source.file.length > 0) return node_path.default.dirname(source.file);
794
- return fallbackBase;
795
- }
826
+ //#region src/tailwindcss/source-scan/inline-source.ts
796
827
  const NUMERICAL_RANGE_RE = /^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/;
797
- function parseConfigParam$1(params) {
798
- const value = params.trim();
799
- return /^(['"])(.+)\1$/.exec(value)?.[2];
800
- }
801
- function isLegacyContentObject$1(value) {
802
- return typeof value === "object" && value !== null && "files" in value;
803
- }
804
- function normalizeGlobPattern(pattern) {
805
- return pattern.startsWith("./") ? pattern.slice(2) : pattern;
806
- }
807
- function hasGlobMagic(value) {
808
- return /[*?[\]{}()!+@]/.test(value);
809
- }
810
- function splitStaticGlobPrefix(pattern) {
811
- const segments = normalizeGlobPattern(pattern).split(/[\\/]+/);
812
- const prefix = [];
813
- const rest = [];
814
- let reachedGlob = false;
815
- for (const segment of segments) {
816
- if (!reachedGlob && segment && !hasGlobMagic(segment)) {
817
- prefix.push(segment);
818
- continue;
819
- }
820
- reachedGlob = true;
821
- rest.push(segment);
822
- }
823
- return {
824
- prefix,
825
- rest
826
- };
827
- }
828
828
  function segmentTopLevel(input, separator, options = {}) {
829
829
  const parts = [];
830
830
  const stack = [];
@@ -951,6 +951,104 @@ function collectCssInlineSourceCandidates(root) {
951
951
  excluded
952
952
  };
953
953
  }
954
+ //#endregion
955
+ //#region src/tailwindcss/source-scan.ts
956
+ const DEFAULT_SOURCE_SCAN_EXTENSIONS = [
957
+ "html",
958
+ "wxml",
959
+ "axml",
960
+ "jxml",
961
+ "ksml",
962
+ "ttml",
963
+ "qml",
964
+ "tyml",
965
+ "xhsml",
966
+ "swan",
967
+ "vue",
968
+ "mpx",
969
+ "js",
970
+ "jsx",
971
+ "ts",
972
+ "tsx"
973
+ ];
974
+ const FULL_SOURCE_SCAN_EXTENSIONS = [
975
+ "js",
976
+ "jsx",
977
+ "mjs",
978
+ "cjs",
979
+ "ts",
980
+ "tsx",
981
+ "mts",
982
+ "cts",
983
+ "vue",
984
+ "uvue",
985
+ "nvue",
986
+ "svelte",
987
+ "mpx",
988
+ "html",
989
+ "wxml",
990
+ "axml",
991
+ "jxml",
992
+ "ksml",
993
+ "ttml",
994
+ "qml",
995
+ "tyml",
996
+ "xhsml",
997
+ "swan",
998
+ "css",
999
+ "wxss",
1000
+ "acss",
1001
+ "jxss",
1002
+ "ttss",
1003
+ "qss",
1004
+ "tyss",
1005
+ "scss",
1006
+ "sass",
1007
+ "less",
1008
+ "styl",
1009
+ "stylus"
1010
+ ];
1011
+ function createSourceScanPattern(extensions = DEFAULT_SOURCE_SCAN_EXTENSIONS) {
1012
+ return `**/*.{${extensions.join(",")}}`;
1013
+ }
1014
+ const FULL_SOURCE_SCAN_PATTERN = createSourceScanPattern(FULL_SOURCE_SCAN_EXTENSIONS);
1015
+ new RegExp(`\\.(?:${FULL_SOURCE_SCAN_EXTENSIONS.map((extension) => extension.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})$`);
1016
+ function resolveTailwindV4CssSourceBase(source, fallbackBase) {
1017
+ if (typeof source.base === "string" && source.base.length > 0) return source.base;
1018
+ if (typeof source.file === "string" && source.file.length > 0) return node_path.default.dirname(source.file);
1019
+ return fallbackBase;
1020
+ }
1021
+ function parseConfigParam$1(params) {
1022
+ const value = params.trim();
1023
+ return /^(['"])(.+)\1$/.exec(value)?.[2];
1024
+ }
1025
+ function isLegacyContentObject(value) {
1026
+ return typeof value === "object" && value !== null && "files" in value;
1027
+ }
1028
+ function normalizeGlobPattern(pattern) {
1029
+ return pattern.startsWith("./") ? pattern.slice(2) : pattern;
1030
+ }
1031
+ function hasGlobMagic(value) {
1032
+ return /[*?[\]{}()!+@]/.test(value);
1033
+ }
1034
+ function splitStaticGlobPrefix(pattern) {
1035
+ const segments = normalizeGlobPattern(pattern).split(/[\\/]+/);
1036
+ const prefix = [];
1037
+ const rest = [];
1038
+ let reachedGlob = false;
1039
+ for (const segment of segments) {
1040
+ if (!reachedGlob && segment && !hasGlobMagic(segment)) {
1041
+ prefix.push(segment);
1042
+ continue;
1043
+ }
1044
+ reachedGlob = true;
1045
+ rest.push(segment);
1046
+ }
1047
+ return {
1048
+ prefix,
1049
+ rest
1050
+ };
1051
+ }
954
1052
  function normalizeLegacyContentEntries(content, base, options = {}) {
955
1053
  if (typeof content === "string") {
956
1054
  const negated = content.startsWith("!");
@@ -961,7 +1059,7 @@ function normalizeLegacyContentEntries(content, base, options = {}) {
961
1059
  }];
962
1060
  }
963
1061
  if (Array.isArray(content)) return content.flatMap((item) => normalizeLegacyContentEntries(item, base, options));
964
- if (isLegacyContentObject$1(content)) return normalizeLegacyContentEntries(content.files, content.relative && options.relativeBase ? options.relativeBase : base, options);
1062
+ if (isLegacyContentObject(content)) return normalizeLegacyContentEntries(content.files, content.relative && options.relativeBase ? options.relativeBase : base, options);
965
1063
  return [];
966
1064
  }
967
1065
  async function pathExistsAsDirectory(file) {
@@ -1029,40 +1127,6 @@ function filterUnsupportedMiniProgramTailwindV4Candidates(candidates) {
1029
1127
  return new Set([...candidates].filter((candidate) => !isUnsupportedMiniProgramTailwindV4Candidate(candidate)));
1030
1128
  }
1031
1129
  //#endregion
1032
- //#region src/tailwindcss/v4-engine/miniprogram.ts
1033
- const defaultStyleHandler$1 = (0, _weapp_tailwindcss_postcss.createStyleHandler)({
1034
- cssChildCombinatorReplaceValue: ["view", "text"],
1035
- cssRemoveHoverPseudoClass: true,
1036
- isMainChunk: true,
1037
- majorVersion: 4
1038
- });
1039
- const CSS_DECLARATION_URL_RE = /(:\s*)url\(([^\n\r"';[\]{}]*[[\]{}][^\n\r;]*)\)(?=\s*;)/g;
1040
- function normalizeTailwindV4GeneratedUrlValues(css) {
1041
- return css.replace(CSS_DECLARATION_URL_RE, (match, prefix, urlValue) => {
1042
- try {
1043
- return `${prefix}url("${urlValue.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}")`;
1044
- } catch {
1045
- return match;
1046
- }
1047
- });
1048
- }
1049
- async function transformTailwindV4CssToWeapp(css, options) {
1050
- const protectedCss = (0, _weapp_tailwindcss_postcss.protectDynamicColorMixAlpha)(normalizeTailwindV4GeneratedUrlValues(hasCssMacroStyleOptions(options) ? await transformCssMacroCss(css, options) : css), { customPropertyValues: options && "customPropertyValues" in options ? options.customPropertyValues : void 0 });
1051
- const result = await defaultStyleHandler$1(protectedCss.css, {
1052
- cssChildCombinatorReplaceValue: ["view", "text"],
1053
- cssRemoveHoverPseudoClass: true,
1054
- isMainChunk: true,
1055
- majorVersion: 4,
1056
- ...options
1057
- });
1058
- const pruneOptions = { preserveConditionalComments: hasCssMacroStyleOptions(options) };
1059
- return (0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(protectedCss.restore(result.css), pruneOptions);
1060
- }
1061
- async function transformTailwindV4CssByTarget(css, target, options) {
1062
- if (target === "weapp") return transformTailwindV4CssToWeapp(css, options);
1063
- return hasCssMacroStyleOptions(options) ? transformCssMacroCss(css, options) : css;
1064
- }
1065
- //#endregion
1066
1130
  //#region src/tailwindcss/v4-engine/tailwind-v3-default-colors.ts
1067
1131
  const TAILWIND_V3_COLOR_STEPS = [
1068
1132
  "50",
@@ -1794,40 +1858,7 @@ function createTailwindV4DefaultColorThemeCss() {
1794
1858
  ].join("\n");
1795
1859
  }
1796
1860
  //#endregion
1797
- //#region src/tailwindcss/v4-engine/generator.ts
1798
- const incrementalGenerateCache$1 = /* @__PURE__ */ new Map();
1799
- const incrementalGenerateTaskCache = /* @__PURE__ */ new Map();
1800
- const BARE_RPX_TEXT_CANDIDATE_RE = /(^|:)text-\[([-+]?(?:\d+|\d*\.\d+)rpx)\](.*)$/u;
1801
- const RPX_TEXT_LENGTH_SELECTOR_RE = /text-\\\[length\\:((?:\\[.+-]|[+\-.\d])+rpx)\\\]/g;
1802
- const TAILWIND_V4_DEFAULT_IGNORED_SOURCE_PATTERNS = [
1803
- "**/.git/**",
1804
- "**/.hg/**",
1805
- "**/.jj/**",
1806
- "**/.next/**",
1807
- "**/.parcel-cache/**",
1808
- "**/.pnpm-store/**",
1809
- "**/.svelte-kit/**",
1810
- "**/.svn/**",
1811
- "**/.turbo/**",
1812
- "**/.venv/**",
1813
- "**/.vercel/**",
1814
- "**/.yarn/**",
1815
- "**/__pycache__/**",
1816
- "**/node_modules/**",
1817
- "**/venv/**",
1818
- "**/*.less",
1819
- "**/*.lock",
1820
- "**/*.sass",
1821
- "**/*.scss",
1822
- "**/*.styl",
1823
- "**/*.log",
1824
- "**/package-lock.json",
1825
- "**/pnpm-lock.yaml",
1826
- "**/bun.lockb",
1827
- "**/.gitignore",
1828
- "**/.env",
1829
- "**/.env.*"
1830
- ];
1861
+ //#region src/tailwindcss/v4-engine/generator/css-compat.ts
1831
1862
  function findLeadingImportInsertionIndex(css) {
1832
1863
  const importPattern = /(?:^|\n)\s*@import\b[^;]*;/g;
1833
1864
  let insertionIndex = 0;
@@ -1844,100 +1875,64 @@ function applyMiniProgramTailwindV4DefaultColorCss(css) {
1844
1875
  if (insertionIndex === 0) return `${themeCss}\n${css}`;
1845
1876
  return `${css.slice(0, insertionIndex)}\n${themeCss}\n${css.slice(insertionIndex)}`;
1846
1877
  }
1847
- function collectCandidates$1(candidates) {
1848
- return new Set(candidates ?? []);
1878
+ function parseCssImportSpecifier$3(params) {
1879
+ const value = params.trim();
1880
+ const quoted = /^(['"])(.*?)\1/.exec(value);
1881
+ if (quoted) return quoted[2];
1882
+ const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
1883
+ return url?.[2] ?? url?.[3];
1849
1884
  }
1850
- function hasRemovedCandidates$1(previousCandidates, nextCandidates) {
1851
- for (const candidate of previousCandidates) if (!nextCandidates.has(candidate)) return true;
1852
- return false;
1885
+ function isTailwindCssPreflightImport(params) {
1886
+ const specifier = parseCssImportSpecifier$3(params);
1887
+ return specifier === "tailwindcss/preflight.css" || specifier === "tailwindcss/preflight";
1853
1888
  }
1854
- function normalizeRpxTextCandidate(candidate) {
1855
- return candidate.replace(BARE_RPX_TEXT_CANDIDATE_RE, "$1text-[length:$2]$3");
1889
+ function hasImportLayerOption(params) {
1890
+ return /\blayer(?:\s*\(|\s*$)/.test(params);
1856
1891
  }
1857
- function normalizeRpxTextCandidates(candidates) {
1858
- const normalized = /* @__PURE__ */ new Set();
1859
- const restoreCandidates = /* @__PURE__ */ new Map();
1860
- for (const candidate of candidates) {
1861
- const normalizedCandidate = normalizeRpxTextCandidate(candidate);
1862
- normalized.add(normalizedCandidate);
1863
- if (normalizedCandidate !== candidate) restoreCandidates.set(normalizedCandidate, candidate);
1864
- }
1865
- return {
1866
- candidates: normalized,
1867
- restoreCandidates
1868
- };
1869
- }
1870
- function restoreRpxTextCandidates(candidates, restoreCandidates) {
1871
- if (restoreCandidates.size === 0) return new Set(candidates);
1872
- return new Set([...candidates].map((candidate) => restoreCandidates.get(candidate) ?? candidate));
1873
- }
1874
- function normalizeCssEscapedRpxSelectorValue(value) {
1875
- return value.replace(/\\([.+-])/g, "$1");
1876
- }
1877
- function restoreRpxTextCssSelectors(css, restoreCandidates) {
1878
- if (restoreCandidates.size === 0 || !css.includes("text-\\[length\\:")) return css;
1879
- const restoredValues = new Set([...restoreCandidates.keys()].map((candidate) => {
1880
- return BARE_RPX_TEXT_CANDIDATE_RE.exec(candidate.replace("[length:", "["))?.[2];
1881
- }).filter((value) => Boolean(value)));
1882
- return css.replace(RPX_TEXT_LENGTH_SELECTOR_RE, (match, value) => {
1883
- return restoredValues.has(normalizeCssEscapedRpxSelectorValue(value)) ? `text-\\[${value}\\]` : match;
1884
- });
1885
- }
1886
- function createStableJson$2(value) {
1887
- if (value === void 0) return "undefined";
1888
- if (value === null || typeof value !== "object") return JSON.stringify(value);
1889
- if (Array.isArray(value)) return `[${value.map((item) => createStableJson$2(item)).join(",")}]`;
1890
- return `{${Object.keys(value).sort().map((key) => {
1891
- const record = value;
1892
- return `${JSON.stringify(key)}:${createStableJson$2(record[key])}`;
1893
- }).join(",")}}`;
1894
- }
1895
- function createDependencyFingerprint$1(files) {
1896
- return files.map((file) => {
1897
- try {
1898
- const stat = node_fs.default.statSync(file);
1899
- return `${file}:${stat.size}:${stat.mtimeMs}`;
1900
- } catch {
1901
- return `${file}:missing`;
1892
+ function removeUnlayeredTailwindV4PreflightImports(css) {
1893
+ if (!css.includes("preflight")) return css;
1894
+ let root;
1895
+ try {
1896
+ root = require_watch_dependencies.postcss_default.parse(css);
1897
+ } catch {
1898
+ return css;
1899
+ }
1900
+ let changed = false;
1901
+ root.walkAtRules("import", (rule) => {
1902
+ if (isTailwindCssPreflightImport(rule.params) && !hasImportLayerOption(rule.params)) {
1903
+ rule.remove();
1904
+ changed = true;
1902
1905
  }
1903
- }).join("|");
1904
- }
1905
- function createIncrementalGenerateCacheKey$1(source, target, styleOptions, tailwindcssV3Compatibility) {
1906
- return [
1907
- source.projectRoot,
1908
- source.base,
1909
- createStableJson$2(source.baseFallbacks),
1910
- source.css,
1911
- createDependencyFingerprint$1(source.dependencies),
1912
- target,
1913
- createStableJson$2(styleOptions),
1914
- createStableJson$2(tailwindcssV3Compatibility)
1915
- ].join("\0");
1906
+ });
1907
+ return changed ? root.toString() : css;
1916
1908
  }
1917
- function createIncrementalGenerateTaskCacheKey(cacheKey, requestedCandidates, scanSources) {
1918
- return [
1919
- cacheKey,
1920
- scanSources === true ? "scan:1" : "scan:0",
1921
- [...requestedCandidates].sort().join("\n")
1922
- ].join("\0");
1909
+ function hasThemeParent(rule) {
1910
+ let parent = rule.parent;
1911
+ while (parent) {
1912
+ if (parent.type === "atrule" && parent.name === "theme") return true;
1913
+ parent = parent.parent;
1914
+ }
1915
+ return false;
1923
1916
  }
1924
- function runIncrementalGenerateTask(cacheKey, requestedCandidates, scanSources, task) {
1925
- const taskKey = createIncrementalGenerateTaskCacheKey(cacheKey, requestedCandidates, scanSources);
1926
- const cachedTask = incrementalGenerateTaskCache.get(taskKey);
1927
- if (cachedTask) return cachedTask;
1928
- const promise = task();
1929
- incrementalGenerateTaskCache.set(taskKey, promise);
1930
- promise.finally(() => {
1931
- if (incrementalGenerateTaskCache.get(taskKey) === promise) incrementalGenerateTaskCache.delete(taskKey);
1932
- });
1933
- return promise;
1917
+ function isVendorPrefixedKeyframes(rule) {
1918
+ return rule.name.startsWith("-") && rule.name.endsWith("keyframes");
1934
1919
  }
1935
- function createIncrementalDesignSystemPromise(source, cacheKey) {
1936
- const promise = (0, tailwindcss_patch.loadTailwindV4DesignSystem)(source);
1937
- promise.catch(() => {
1938
- if (incrementalGenerateCache$1.get(cacheKey)?.designSystemPromise === promise) incrementalGenerateCache$1.delete(cacheKey);
1920
+ function removeUnsupportedThemeVendorKeyframes(css) {
1921
+ if (!css.includes("@theme") || !css.includes("@-")) return css;
1922
+ let root;
1923
+ try {
1924
+ root = require_watch_dependencies.postcss_default.parse(css);
1925
+ } catch {
1926
+ return css;
1927
+ }
1928
+ let changed = false;
1929
+ root.walkAtRules((rule) => {
1930
+ if (isVendorPrefixedKeyframes(rule) && hasThemeParent(rule)) {
1931
+ rule.remove();
1932
+ changed = true;
1933
+ }
1939
1934
  });
1940
- return promise;
1935
+ return changed ? root.toString() : css;
1941
1936
  }
1942
1937
  function createCompatibleSource(source, target, tailwindcssV3Compatibility) {
1943
1938
  const shouldApplyTailwindV3Compatibility = tailwindcssV3Compatibility ?? target === "weapp";
@@ -1948,55 +1943,73 @@ function createCompatibleSource(source, target, tailwindcssV3Compatibility) {
1948
1943
  css: compatibleSourceCss
1949
1944
  };
1950
1945
  }
1951
- function resolveTargetCandidates(candidates, target) {
1952
- const collected = collectCandidates$1(candidates);
1953
- return target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(collected) : collected;
1954
- }
1955
- function collectSeenCandidates(generated, requestedCandidates) {
1956
- return new Set([
1957
- ...requestedCandidates,
1958
- ...generated.rawCandidates,
1959
- ...generated.classSet
1960
- ]);
1946
+ //#endregion
1947
+ //#region src/tailwindcss/v4-engine/generator/rpx-candidates.ts
1948
+ const BARE_RPX_TEXT_CANDIDATE_RE = /(^|:)text-\[([-+]?(?:\d+|\d*\.\d+)rpx)\](.*)$/u;
1949
+ const RPX_TEXT_LENGTH_SELECTOR_RE = /text-\\\[length\\:((?:\\[.+-]|[+\-.\d])+rpx)\\\]/g;
1950
+ function normalizeRpxTextCandidate(candidate) {
1951
+ return candidate.replace(BARE_RPX_TEXT_CANDIDATE_RE, "$1text-[length:$2]$3");
1961
1952
  }
1962
- function createIncrementalStyleOptions(styleOptions) {
1953
+ function normalizeRpxTextCandidates(candidates) {
1954
+ const normalized = /* @__PURE__ */ new Set();
1955
+ const restoreCandidates = /* @__PURE__ */ new Map();
1956
+ for (const candidate of candidates) {
1957
+ const normalizedCandidate = normalizeRpxTextCandidate(candidate);
1958
+ normalized.add(normalizedCandidate);
1959
+ if (normalizedCandidate !== candidate) restoreCandidates.set(normalizedCandidate, candidate);
1960
+ }
1963
1961
  return {
1964
- ...styleOptions,
1965
- isMainChunk: false
1962
+ candidates: normalized,
1963
+ restoreCandidates
1966
1964
  };
1967
1965
  }
1968
- function resolveStyleOptions$1(source, options) {
1969
- return hasCssMacroTailwindV4Directive(source.css) ? withCssMacroStyleOptions(options) : options;
1970
- }
1971
- function collectCustomPropertyValues(css) {
1972
- const values = /* @__PURE__ */ new Map();
1973
- try {
1974
- require_watch_dependencies.postcss_default.parse(css).walkDecls((decl) => {
1975
- if (decl.prop.startsWith("--")) values.set(decl.prop, decl.value.trim());
1976
- });
1977
- } catch {}
1978
- return values;
1966
+ function restoreRpxTextCandidates(candidates, restoreCandidates) {
1967
+ if (restoreCandidates.size === 0) return new Set(candidates);
1968
+ return new Set([...candidates].map((candidate) => restoreCandidates.get(candidate) ?? candidate));
1979
1969
  }
1980
- function mergeCustomPropertyValues(target, css) {
1981
- for (const [prop, value] of collectCustomPropertyValues(css)) target.set(prop, value);
1970
+ function normalizeCssEscapedRpxSelectorValue(value) {
1971
+ return value.replace(/\\([.+-])/g, "$1");
1982
1972
  }
1983
- function seedIncrementalGenerateCache(options) {
1984
- const cacheKey = createIncrementalGenerateCacheKey$1(options.compatibleSource, options.target, options.styleOptions, options.tailwindcssV3Compatibility);
1985
- const customPropertyValues = collectCustomPropertyValues(options.compatibleSource.css);
1986
- mergeCustomPropertyValues(customPropertyValues, options.generated.css);
1987
- incrementalGenerateCache$1.set(cacheKey, {
1988
- seenCandidates: collectSeenCandidates(options.generated, options.requestedCandidates),
1989
- classSet: new Set(options.generated.classSet),
1990
- css: options.generated.css,
1991
- rawCss: options.generated.rawCss,
1992
- customPropertyValues,
1993
- designSystemPromise: createIncrementalDesignSystemPromise(options.compatibleSource, cacheKey),
1994
- dependencies: options.generated.dependencies,
1995
- sources: options.generated.sources,
1996
- root: options.generated.root,
1997
- target: options.generated.target
1973
+ function restoreRpxTextCssSelectors(css, restoreCandidates) {
1974
+ if (restoreCandidates.size === 0 || !css.includes("text-\\[length\\:")) return css;
1975
+ const restoredValues = new Set([...restoreCandidates.keys()].map((candidate) => {
1976
+ return BARE_RPX_TEXT_CANDIDATE_RE.exec(candidate.replace("[length:", "["))?.[2];
1977
+ }).filter((value) => Boolean(value)));
1978
+ return css.replace(RPX_TEXT_LENGTH_SELECTOR_RE, (match, value) => {
1979
+ return restoredValues.has(normalizeCssEscapedRpxSelectorValue(value)) ? `text-\\[${value}\\]` : match;
1998
1980
  });
1999
1981
  }
1982
+ //#endregion
1983
+ //#region src/tailwindcss/v4-engine/generator/scan-sources.ts
1984
+ const TAILWIND_V4_DEFAULT_IGNORED_SOURCE_PATTERNS = [
1985
+ "**/.git/**",
1986
+ "**/.hg/**",
1987
+ "**/.jj/**",
1988
+ "**/.next/**",
1989
+ "**/.parcel-cache/**",
1990
+ "**/.pnpm-store/**",
1991
+ "**/.svelte-kit/**",
1992
+ "**/.svn/**",
1993
+ "**/.turbo/**",
1994
+ "**/.venv/**",
1995
+ "**/.vercel/**",
1996
+ "**/.yarn/**",
1997
+ "**/__pycache__/**",
1998
+ "**/node_modules/**",
1999
+ "**/venv/**",
2000
+ "**/*.less",
2001
+ "**/*.lock",
2002
+ "**/*.sass",
2003
+ "**/*.scss",
2004
+ "**/*.styl",
2005
+ "**/*.log",
2006
+ "**/package-lock.json",
2007
+ "**/pnpm-lock.yaml",
2008
+ "**/bun.lockb",
2009
+ "**/.gitignore",
2010
+ "**/.env",
2011
+ "**/.env.*"
2012
+ ];
2000
2013
  function parseImportSourceParam$1(params) {
2001
2014
  const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
2002
2015
  if (!match) return;
@@ -2005,10 +2018,6 @@ function parseImportSourceParam$1(params) {
2005
2018
  sourcePath: match[3]
2006
2019
  };
2007
2020
  }
2008
- function isTailwindCssImport$1(params) {
2009
- const specifier = parseCssImportSpecifier$2(params);
2010
- return specifier === "tailwindcss" || specifier?.startsWith("tailwindcss/") || specifier?.replaceAll("\\", "/").endsWith("/tailwindcss/index.css");
2011
- }
2012
2021
  function parseCssImportSpecifier$2(params) {
2013
2022
  const value = params.trim();
2014
2023
  const quoted = /^(['"])(.*?)\1/.exec(value);
@@ -2016,29 +2025,9 @@ function parseCssImportSpecifier$2(params) {
2016
2025
  const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
2017
2026
  return url?.[2] ?? url?.[3];
2018
2027
  }
2019
- function isTailwindCssPreflightImport(params) {
2028
+ function isTailwindCssImport$1(params) {
2020
2029
  const specifier = parseCssImportSpecifier$2(params);
2021
- return specifier === "tailwindcss/preflight.css" || specifier === "tailwindcss/preflight";
2022
- }
2023
- function hasImportLayerOption(params) {
2024
- return /\blayer(?:\s*\(|\s*$)/.test(params);
2025
- }
2026
- function removeUnlayeredTailwindV4PreflightImports(css) {
2027
- if (!css.includes("preflight")) return css;
2028
- let root;
2029
- try {
2030
- root = require_watch_dependencies.postcss_default.parse(css);
2031
- } catch {
2032
- return css;
2033
- }
2034
- let changed = false;
2035
- root.walkAtRules("import", (rule) => {
2036
- if (isTailwindCssPreflightImport(rule.params) && !hasImportLayerOption(rule.params)) {
2037
- rule.remove();
2038
- changed = true;
2039
- }
2040
- });
2041
- return changed ? root.toString() : css;
2030
+ return specifier === "tailwindcss" || specifier?.startsWith("tailwindcss/") || specifier?.replaceAll("\\", "/").endsWith("/tailwindcss/index.css");
2042
2031
  }
2043
2032
  function resolveSourceBase$1(base, sourcePath) {
2044
2033
  return node_path.default.isAbsolute(sourcePath) ? sourcePath : node_path.default.resolve(base, sourcePath);
@@ -2091,33 +2080,155 @@ async function resolveScanSources(source, scanSources) {
2091
2080
  if (scanSources !== true) return scanSources;
2092
2081
  return await resolveCssDefinedScanSources(source) ?? false;
2093
2082
  }
2094
- function hasThemeParent(rule) {
2095
- let parent = rule.parent;
2096
- while (parent) {
2097
- if (parent.type === "atrule" && parent.name === "theme") return true;
2098
- parent = parent.parent;
2099
- }
2100
- return false;
2083
+ //#endregion
2084
+ //#region src/tailwindcss/v4-engine/miniprogram.ts
2085
+ const defaultStyleHandler$1 = (0, _weapp_tailwindcss_postcss.createStyleHandler)({
2086
+ cssChildCombinatorReplaceValue: ["view", "text"],
2087
+ cssRemoveHoverPseudoClass: true,
2088
+ isMainChunk: true,
2089
+ majorVersion: 4
2090
+ });
2091
+ const CSS_DECLARATION_URL_RE = /(:\s*)url\(([^\n\r"';[\]{}]*[[\]{}][^\n\r;]*)\)(?=\s*;)/g;
2092
+ function normalizeTailwindV4GeneratedUrlValues(css) {
2093
+ return css.replace(CSS_DECLARATION_URL_RE, (match, prefix, urlValue) => {
2094
+ try {
2095
+ return `${prefix}url("${urlValue.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}")`;
2096
+ } catch {
2097
+ return match;
2098
+ }
2099
+ });
2100
+ }
2101
+ async function transformTailwindV4CssToWeapp(css, options) {
2102
+ const protectedCss = (0, _weapp_tailwindcss_postcss.protectDynamicColorMixAlpha)(normalizeTailwindV4GeneratedUrlValues(hasCssMacroStyleOptions(options) ? await transformCssMacroCss(css, options) : css), { customPropertyValues: options && "customPropertyValues" in options ? options.customPropertyValues : void 0 });
2103
+ const result = await defaultStyleHandler$1(protectedCss.css, {
2104
+ cssChildCombinatorReplaceValue: ["view", "text"],
2105
+ cssRemoveHoverPseudoClass: true,
2106
+ isMainChunk: true,
2107
+ majorVersion: 4,
2108
+ ...options
2109
+ });
2110
+ const pruneOptions = { preserveConditionalComments: hasCssMacroStyleOptions(options) };
2111
+ return (0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(protectedCss.restore(result.css), pruneOptions);
2112
+ }
2113
+ async function transformTailwindV4CssByTarget(css, target, options) {
2114
+ if (target === "weapp") return transformTailwindV4CssToWeapp(css, options);
2115
+ return hasCssMacroStyleOptions(options) ? transformCssMacroCss(css, options) : css;
2116
+ }
2117
+ //#endregion
2118
+ //#region src/tailwindcss/v4-engine/generator.ts
2119
+ const incrementalGenerateCache$1 = /* @__PURE__ */ new Map();
2120
+ const incrementalGenerateTaskCache = /* @__PURE__ */ new Map();
2121
+ function collectCandidates(candidates) {
2122
+ return new Set(candidates ?? []);
2123
+ }
2124
+ function hasRemovedCandidates$1(previousCandidates, nextCandidates) {
2125
+ for (const candidate of previousCandidates) if (!nextCandidates.has(candidate)) return true;
2126
+ return false;
2127
+ }
2128
+ function createStableJson$1(value) {
2129
+ if (value === void 0) return "undefined";
2130
+ if (value === null || typeof value !== "object") return JSON.stringify(value);
2131
+ if (Array.isArray(value)) return `[${value.map((item) => createStableJson$1(item)).join(",")}]`;
2132
+ return `{${Object.keys(value).sort().map((key) => {
2133
+ const record = value;
2134
+ return `${JSON.stringify(key)}:${createStableJson$1(record[key])}`;
2135
+ }).join(",")}}`;
2136
+ }
2137
+ function createDependencyFingerprint(files) {
2138
+ return files.map((file) => {
2139
+ try {
2140
+ const stat = node_fs.default.statSync(file);
2141
+ return `${file}:${stat.size}:${stat.mtimeMs}`;
2142
+ } catch {
2143
+ return `${file}:missing`;
2144
+ }
2145
+ }).join("|");
2146
+ }
2147
+ function createIncrementalGenerateCacheKey(source, target, styleOptions, tailwindcssV3Compatibility) {
2148
+ return [
2149
+ source.projectRoot,
2150
+ source.base,
2151
+ createStableJson$1(source.baseFallbacks),
2152
+ source.css,
2153
+ createDependencyFingerprint(source.dependencies),
2154
+ target,
2155
+ createStableJson$1(styleOptions),
2156
+ createStableJson$1(tailwindcssV3Compatibility)
2157
+ ].join("\0");
2158
+ }
2159
+ function createIncrementalGenerateTaskCacheKey(cacheKey, requestedCandidates, scanSources) {
2160
+ return [
2161
+ cacheKey,
2162
+ scanSources === true ? "scan:1" : "scan:0",
2163
+ [...requestedCandidates].sort().join("\n")
2164
+ ].join("\0");
2165
+ }
2166
+ function runIncrementalGenerateTask(cacheKey, requestedCandidates, scanSources, task) {
2167
+ const taskKey = createIncrementalGenerateTaskCacheKey(cacheKey, requestedCandidates, scanSources);
2168
+ const cachedTask = incrementalGenerateTaskCache.get(taskKey);
2169
+ if (cachedTask) return cachedTask;
2170
+ const promise = task();
2171
+ incrementalGenerateTaskCache.set(taskKey, promise);
2172
+ promise.finally(() => {
2173
+ if (incrementalGenerateTaskCache.get(taskKey) === promise) incrementalGenerateTaskCache.delete(taskKey);
2174
+ });
2175
+ return promise;
2176
+ }
2177
+ function createIncrementalDesignSystemPromise(source, cacheKey) {
2178
+ const promise = (0, tailwindcss_patch.loadTailwindV4DesignSystem)(source);
2179
+ promise.catch(() => {
2180
+ if (incrementalGenerateCache$1.get(cacheKey)?.designSystemPromise === promise) incrementalGenerateCache$1.delete(cacheKey);
2181
+ });
2182
+ return promise;
2183
+ }
2184
+ function resolveTargetCandidates(candidates, target) {
2185
+ const collected = collectCandidates(candidates);
2186
+ return target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(collected) : collected;
2187
+ }
2188
+ function collectSeenCandidates(generated, requestedCandidates) {
2189
+ return new Set([
2190
+ ...requestedCandidates,
2191
+ ...generated.rawCandidates,
2192
+ ...generated.classSet
2193
+ ]);
2194
+ }
2195
+ function createIncrementalStyleOptions(styleOptions) {
2196
+ return {
2197
+ ...styleOptions,
2198
+ isMainChunk: false
2199
+ };
2101
2200
  }
2102
- function isVendorPrefixedKeyframes(rule) {
2103
- return rule.name.startsWith("-") && rule.name.endsWith("keyframes");
2201
+ function resolveStyleOptions$1(source, options) {
2202
+ return hasCssMacroTailwindV4Directive(source.css) ? withCssMacroStyleOptions(options) : options;
2104
2203
  }
2105
- function removeUnsupportedThemeVendorKeyframes(css) {
2106
- if (!css.includes("@theme") || !css.includes("@-")) return css;
2107
- let root;
2204
+ function collectCustomPropertyValues(css) {
2205
+ const values = /* @__PURE__ */ new Map();
2108
2206
  try {
2109
- root = require_watch_dependencies.postcss_default.parse(css);
2110
- } catch {
2111
- return css;
2112
- }
2113
- let changed = false;
2114
- root.walkAtRules((rule) => {
2115
- if (isVendorPrefixedKeyframes(rule) && hasThemeParent(rule)) {
2116
- rule.remove();
2117
- changed = true;
2118
- }
2207
+ require_watch_dependencies.postcss_default.parse(css).walkDecls((decl) => {
2208
+ if (decl.prop.startsWith("--")) values.set(decl.prop, decl.value.trim());
2209
+ });
2210
+ } catch {}
2211
+ return values;
2212
+ }
2213
+ function mergeCustomPropertyValues(target, css) {
2214
+ for (const [prop, value] of collectCustomPropertyValues(css)) target.set(prop, value);
2215
+ }
2216
+ function seedIncrementalGenerateCache(options) {
2217
+ const cacheKey = createIncrementalGenerateCacheKey(options.compatibleSource, options.target, options.styleOptions, options.tailwindcssV3Compatibility);
2218
+ const customPropertyValues = collectCustomPropertyValues(options.compatibleSource.css);
2219
+ mergeCustomPropertyValues(customPropertyValues, options.generated.css);
2220
+ incrementalGenerateCache$1.set(cacheKey, {
2221
+ seenCandidates: collectSeenCandidates(options.generated, options.requestedCandidates),
2222
+ classSet: new Set(options.generated.classSet),
2223
+ css: options.generated.css,
2224
+ rawCss: options.generated.rawCss,
2225
+ customPropertyValues,
2226
+ designSystemPromise: createIncrementalDesignSystemPromise(options.compatibleSource, cacheKey),
2227
+ dependencies: options.generated.dependencies,
2228
+ sources: options.generated.sources,
2229
+ root: options.generated.root,
2230
+ target: options.generated.target
2119
2231
  });
2120
- return changed ? root.toString() : css;
2121
2232
  }
2122
2233
  function createTailwindV4Engine(source) {
2123
2234
  async function generateOnce(generateSource, options = {}) {
@@ -2125,8 +2236,8 @@ function createTailwindV4Engine(source) {
2125
2236
  const resolvedStyleOptions = resolveStyleOptions$1(generateSource, styleOptions);
2126
2237
  const engine = (0, tailwindcss_patch.createTailwindV4Engine)(createCompatibleSource(generateSource, target, tailwindcssV3Compatibility));
2127
2238
  const resolvedScanSources = await resolveScanSources(generateSource, scanSources);
2128
- const filesystemCandidates = Array.isArray(resolvedScanSources) ? new Set(await (0, tailwindcss_patch.extractRawCandidates)(resolvedScanSources, { bareArbitraryValues: patchOptions.bareArbitraryValues })) : void 0;
2129
- const normalizedCandidates = normalizeRpxTextCandidates(resolveTargetCandidates(new Set([...collectCandidates$1(patchOptions.candidates), ...filesystemCandidates ?? []]), target));
2239
+ const filesystemCandidates = Array.isArray(resolvedScanSources) ? new Set(await (0, tailwindcss_patch.extractRawCandidates)(resolvedScanSources, { ...patchOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: patchOptions.bareArbitraryValues } })) : void 0;
2240
+ const normalizedCandidates = normalizeRpxTextCandidates(resolveTargetCandidates(new Set([...collectCandidates(patchOptions.candidates), ...filesystemCandidates ?? []]), target));
2130
2241
  const result = await engine.generate(omitUndefined({
2131
2242
  scanSources: false,
2132
2243
  ...patchOptions,
@@ -2149,7 +2260,7 @@ function createTailwindV4Engine(source) {
2149
2260
  const requestedCandidates = resolveTargetCandidates(options.candidates, target);
2150
2261
  const styleOptions = resolveStyleOptions$1(source, options.styleOptions);
2151
2262
  if ((options.sources?.length ?? 0) > 0 || options.bareArbitraryValues !== void 0 || Array.isArray(options.scanSources)) return generateOnce(source, options);
2152
- const cacheKey = createIncrementalGenerateCacheKey$1(compatibleSource, target, styleOptions, options.tailwindcssV3Compatibility);
2263
+ const cacheKey = createIncrementalGenerateCacheKey(compatibleSource, target, styleOptions, options.tailwindcssV3Compatibility);
2153
2264
  if (options.scanSources === true) return runIncrementalGenerateTask(cacheKey, requestedCandidates, options.scanSources, async () => {
2154
2265
  const generated = await generateOnce(source, options);
2155
2266
  seedIncrementalGenerateCache({
@@ -2338,96 +2449,48 @@ function hasTailwindGeneratedCssMarkers(rawSource) {
2338
2449
  return TAILWIND_GENERATED_CSS_MARKER_RE.test(rawSource) || GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
2339
2450
  }
2340
2451
  //#endregion
2341
- //#region src/bundlers/shared/generator-css/directives.ts
2342
- const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = new Set([
2343
- "config",
2344
- "custom-variant",
2345
- "layer",
2346
- "plugin",
2347
- "reference",
2348
- "source",
2349
- "tailwind",
2350
- "theme",
2351
- "utility",
2352
- "variant"
2353
- ]);
2354
- const TAILWIND_ROOT_DIRECTIVE_NAMES = new Set([
2355
- "config",
2356
- "custom-variant",
2357
- "plugin",
2358
- "source",
2359
- "tailwind",
2360
- "theme",
2361
- "utility",
2362
- "variant"
2363
- ]);
2364
- const TAILWIND_ROOT_DIRECTIVE_RE = /@(?:import\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|(?:use|forward)\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|tailwind|config|custom-variant|plugin|source|theme|utility|variant)\b/;
2452
+ //#region src/bundlers/shared/generator-css/directives/fallback.ts
2365
2453
  const TAILWIND_EXTRACTABLE_DIRECTIVE_RE = /^\s*@(?:import|use|forward|tailwind|config|source|reference|plugin)\b[\s\S]*?(?:;|$)/;
2366
2454
  const TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE = /^\s*@layer\s[^;{]+;\s*$/;
2367
2455
  const TAILWIND_EXTRACTABLE_BLOCK_START_RE = /^\s*@(?:layer|theme|utility|variant|custom-variant|plugin)\b[\s\S]*\{/;
2368
- const TAILWIND_V3_SUBPATH_IMPORT_LAYERS = new Map([
2369
- ["tailwindcss/base", "base"],
2370
- ["tailwindcss/components", "components"],
2371
- ["tailwindcss/utilities", "utilities"]
2372
- ]);
2373
- function parseImportRequest(params) {
2456
+ function parseImportRequest$1(params) {
2374
2457
  return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
2375
2458
  }
2376
- function parseConfigRequest(params) {
2459
+ function parseConfigRequest$1(params) {
2377
2460
  return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
2378
2461
  }
2379
- function isPackageJsonImportRequest$1(request) {
2462
+ function isPackageJsonImportRequest$2(request) {
2380
2463
  return typeof request === "string" && request.startsWith("#");
2381
2464
  }
2382
- function isWeappTailwindcssImportRequest(request) {
2465
+ function isWeappTailwindcssImportRequest$1(request) {
2383
2466
  return request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
2384
2467
  }
2385
- function normalizeTailwindImportRequest(request, options = {}) {
2386
- if (options.importFallback && isWeappTailwindcssImportRequest(request)) return request.replace(/^weapp-tailwindcss/, "tailwindcss");
2468
+ function isTailwindImportRequest$1(request) {
2469
+ return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/");
2470
+ }
2471
+ function normalizeTailwindImportRequest$1(request, options = {}) {
2472
+ if (options.importFallback && isWeappTailwindcssImportRequest$1(request)) return request.replace(/^weapp-tailwindcss/, "tailwindcss");
2387
2473
  return request;
2388
2474
  }
2389
- function replaceImportRequest(params, request, replacement) {
2475
+ function replaceImportRequest$1(params, request, replacement) {
2390
2476
  const index = params.indexOf(request);
2391
2477
  if (index === -1) return params;
2392
2478
  return `${params.slice(0, index)}${replacement}${params.slice(index + request.length)}`;
2393
2479
  }
2394
- function normalizeTailwindImportAtRules(root, options = {}) {
2395
- if (!options.importFallback) return false;
2396
- let changed = false;
2397
- const seenCanonicalImports = /* @__PURE__ */ new Set();
2398
- root.walkAtRules("import", (node) => {
2399
- const request = parseImportRequest(node.params);
2400
- const normalizedRequest = normalizeTailwindImportRequest(request, options);
2401
- if (!normalizedRequest || !isTailwindImportRequest(normalizedRequest)) return;
2402
- const normalizedParams = request && normalizedRequest !== request ? replaceImportRequest(node.params, request, normalizedRequest) : node.params;
2403
- const normalizedKey = normalizedParams.trim();
2404
- if (seenCanonicalImports.has(normalizedKey)) {
2405
- node.remove();
2406
- changed = true;
2407
- return;
2408
- }
2409
- seenCanonicalImports.add(normalizedKey);
2410
- if (normalizedParams !== node.params) {
2411
- node.params = normalizedParams;
2412
- changed = true;
2413
- }
2414
- });
2415
- return changed;
2416
- }
2417
2480
  function normalizeTailwindDirectiveLine(line, options = {}) {
2418
2481
  const trimmed = line.trimStart();
2419
2482
  if (/^@(?:use|forward)\b/.test(trimmed)) {
2420
- const request = parseImportRequest(trimmed.replace(/^@(?:use|forward)\b/, ""));
2421
- if (isTailwindImportRequest(request) || options.importFallback && isWeappTailwindcssImportRequest(request)) {
2422
- const normalizedRequest = normalizeTailwindImportRequest(request, options);
2423
- return replaceImportRequest(line.replace(/^(\s*)@(?:use|forward)\b/, "$1@import"), request, normalizedRequest);
2483
+ const request = parseImportRequest$1(trimmed.replace(/^@(?:use|forward)\b/, ""));
2484
+ if (isTailwindImportRequest$1(request) || options.importFallback && isWeappTailwindcssImportRequest$1(request)) {
2485
+ const normalizedRequest = normalizeTailwindImportRequest$1(request, options);
2486
+ return replaceImportRequest$1(line.replace(/^(\s*)@(?:use|forward)\b/, "$1@import"), request, normalizedRequest);
2424
2487
  }
2425
2488
  return line;
2426
2489
  }
2427
2490
  if (!options.importFallback || !trimmed.startsWith("@import")) return line;
2428
- const request = parseImportRequest(trimmed.replace(/^@import\b/, ""));
2429
- if (!request || !isWeappTailwindcssImportRequest(request)) return line;
2430
- return replaceImportRequest(line, request, request.replace(/^weapp-tailwindcss/, "tailwindcss"));
2491
+ const request = parseImportRequest$1(trimmed.replace(/^@import\b/, ""));
2492
+ if (!request || !isWeappTailwindcssImportRequest$1(request)) return line;
2493
+ return replaceImportRequest$1(line, request, request.replace(/^weapp-tailwindcss/, "tailwindcss"));
2431
2494
  }
2432
2495
  function extractTailwindDirectiveLines(rawSource, options = {}) {
2433
2496
  const directives = [];
@@ -2441,10 +2504,10 @@ function extractTailwindDirectiveLines(rawSource, options = {}) {
2441
2504
  const normalized = normalizeTailwindDirectiveLine(directive.trimEnd(), options);
2442
2505
  const normalizedTrimmed = normalized.trim();
2443
2506
  if (options.removeConfig && normalizedTrimmed.startsWith("@config")) continue;
2444
- const request = /^@(?:import|use|forward)\b/.test(normalizedTrimmed) ? parseImportRequest(normalizedTrimmed.replace(/^@(?:import|use|forward)\b/, "")) : void 0;
2445
- if (request && !isTailwindImportRequest(request) && !isPackageJsonImportRequest$1(request)) continue;
2507
+ const request = /^@(?:import|use|forward)\b/.test(normalizedTrimmed) ? parseImportRequest$1(normalizedTrimmed.replace(/^@(?:import|use|forward)\b/, "")) : void 0;
2508
+ if (request && !isTailwindImportRequest$1(request) && !isPackageJsonImportRequest$2(request)) continue;
2446
2509
  if (/^@(?:import|use|forward)\b/.test(normalizedTrimmed) && !request) continue;
2447
- if (request && isTailwindImportRequest(request)) {
2510
+ if (request && isTailwindImportRequest$1(request)) {
2448
2511
  const key = normalizedTrimmed;
2449
2512
  if (seenImports.has(key)) continue;
2450
2513
  seenImports.add(key);
@@ -2540,10 +2603,84 @@ function extractTailwindSourceForPostcssFallback(rawSource, options = {}) {
2540
2603
  function extractConfigRequestFromSource(rawSource) {
2541
2604
  for (const line of rawSource.split(/\r?\n/)) {
2542
2605
  const match = /^\s*@config\b([\s\S]*?)(?:;|$)/.exec(line);
2543
- const request = match ? parseConfigRequest(match[1] ?? "") : void 0;
2606
+ const request = match ? parseConfigRequest$1(match[1] ?? "") : void 0;
2544
2607
  if (request) return request;
2545
2608
  }
2546
2609
  }
2610
+ //#endregion
2611
+ //#region src/bundlers/shared/generator-css/directives.ts
2612
+ const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = new Set([
2613
+ "config",
2614
+ "custom-variant",
2615
+ "layer",
2616
+ "plugin",
2617
+ "reference",
2618
+ "source",
2619
+ "tailwind",
2620
+ "theme",
2621
+ "utility",
2622
+ "variant"
2623
+ ]);
2624
+ const TAILWIND_ROOT_DIRECTIVE_NAMES = new Set([
2625
+ "config",
2626
+ "custom-variant",
2627
+ "plugin",
2628
+ "source",
2629
+ "tailwind",
2630
+ "theme",
2631
+ "utility",
2632
+ "variant"
2633
+ ]);
2634
+ const TAILWIND_ROOT_DIRECTIVE_RE = /@(?:import\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|(?:use|forward)\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|tailwind|config|custom-variant|plugin|source|theme|utility|variant)\b/;
2635
+ const TAILWIND_V3_SUBPATH_IMPORT_LAYERS = new Map([
2636
+ ["tailwindcss/base", "base"],
2637
+ ["tailwindcss/components", "components"],
2638
+ ["tailwindcss/utilities", "utilities"]
2639
+ ]);
2640
+ function parseImportRequest(params) {
2641
+ return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
2642
+ }
2643
+ function parseConfigRequest(params) {
2644
+ return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
2645
+ }
2646
+ function isPackageJsonImportRequest$1(request) {
2647
+ return typeof request === "string" && request.startsWith("#");
2648
+ }
2649
+ function isWeappTailwindcssImportRequest(request) {
2650
+ return request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
2651
+ }
2652
+ function normalizeTailwindImportRequest(request, options = {}) {
2653
+ if (options.importFallback && isWeappTailwindcssImportRequest(request)) return request.replace(/^weapp-tailwindcss/, "tailwindcss");
2654
+ return request;
2655
+ }
2656
+ function replaceImportRequest(params, request, replacement) {
2657
+ const index = params.indexOf(request);
2658
+ if (index === -1) return params;
2659
+ return `${params.slice(0, index)}${replacement}${params.slice(index + request.length)}`;
2660
+ }
2661
+ function normalizeTailwindImportAtRules(root, options = {}) {
2662
+ if (!options.importFallback) return false;
2663
+ let changed = false;
2664
+ const seenCanonicalImports = /* @__PURE__ */ new Set();
2665
+ root.walkAtRules("import", (node) => {
2666
+ const request = parseImportRequest(node.params);
2667
+ const normalizedRequest = normalizeTailwindImportRequest(request, options);
2668
+ if (!normalizedRequest || !isTailwindImportRequest(normalizedRequest)) return;
2669
+ const normalizedParams = request && normalizedRequest !== request ? replaceImportRequest(node.params, request, normalizedRequest) : node.params;
2670
+ const normalizedKey = normalizedParams.trim();
2671
+ if (seenCanonicalImports.has(normalizedKey)) {
2672
+ node.remove();
2673
+ changed = true;
2674
+ return;
2675
+ }
2676
+ seenCanonicalImports.add(normalizedKey);
2677
+ if (normalizedParams !== node.params) {
2678
+ node.params = normalizedParams;
2679
+ changed = true;
2680
+ }
2681
+ });
2682
+ return changed;
2683
+ }
2547
2684
  function resolveConfigPath$1(base, configPath) {
2548
2685
  if (node_path.default.isAbsolute(configPath) || isPackageJsonImportRequest$1(configPath)) return node_path.default.isAbsolute(configPath) ? configPath : void 0;
2549
2686
  return node_path.default.resolve(base, configPath);
@@ -3117,7 +3254,7 @@ function readStaticConfigContent(configPath) {
3117
3254
  return parseStaticContentValue(source, contentProperty.start)?.value;
3118
3255
  }
3119
3256
  //#endregion
3120
- //#region src/bundlers/vite/source-scan.ts
3257
+ //#region src/bundlers/vite/source-scan/css-entries.ts
3121
3258
  const VITE_SOURCE_CANDIDATE_PATTERN = FULL_SOURCE_SCAN_PATTERN;
3122
3259
  function parseImportSourceParam(params) {
3123
3260
  const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
@@ -3281,6 +3418,40 @@ async function ensureTailwindcssRuntimePatch(twPatcher, options = {}) {
3281
3418
  return task;
3282
3419
  }
3283
3420
  //#endregion
3421
+ //#region src/tailwindcss/v3-engine/generator/runtime-ready.ts
3422
+ const runtimeReadyPromiseCache = /* @__PURE__ */ new Map();
3423
+ function createRuntimeReadyCacheKey(source, rootPath) {
3424
+ return [
3425
+ source.packageName,
3426
+ source.postcssPlugin,
3427
+ rootPath ?? "missing",
3428
+ source.config ?? "config:missing",
3429
+ source.cwd
3430
+ ].join("\0");
3431
+ }
3432
+ function createRuntimeReadyPromise(source) {
3433
+ const patcher = createTailwindcssPatcher({
3434
+ basedir: source.cwd,
3435
+ supportCustomLengthUnitsPatch: true,
3436
+ tailwindcss: {
3437
+ ...source.config === void 0 ? {} : { config: source.config },
3438
+ cwd: source.cwd,
3439
+ packageName: source.packageName,
3440
+ postcssPlugin: source.postcssPlugin,
3441
+ version: 3
3442
+ }
3443
+ });
3444
+ const cacheKey = createRuntimeReadyCacheKey(source, patcher.packageInfo?.rootPath);
3445
+ const cached = runtimeReadyPromiseCache.get(cacheKey);
3446
+ if (cached) return cached;
3447
+ const task = ensureTailwindcssRuntimePatch(patcher, { clearRequireCache: true }).catch((error) => {
3448
+ runtimeReadyPromiseCache.delete(cacheKey);
3449
+ throw error;
3450
+ });
3451
+ runtimeReadyPromiseCache.set(cacheKey, task);
3452
+ return task;
3453
+ }
3454
+ //#endregion
3284
3455
  //#region src/tailwindcss/v3-engine/miniprogram.ts
3285
3456
  const defaultStyleHandler = (0, _weapp_tailwindcss_postcss.createStyleHandler)({
3286
3457
  cssChildCombinatorReplaceValue: ["view", "text"],
@@ -3360,34 +3531,15 @@ async function transformTailwindV3CssByTarget(css, target, options) {
3360
3531
  if (target === "weapp") return transformTailwindV3CssToWeapp(css, options);
3361
3532
  return hasCssMacroStyleOptions(options) ? transformCssMacroCss(css, options) : css;
3362
3533
  }
3363
- //#endregion
3364
- //#region src/tailwindcss/v3-engine/generator.ts
3365
- const runtimeReadyPromiseCache = /* @__PURE__ */ new Map();
3366
- const incrementalGenerateCache = /* @__PURE__ */ new Map();
3367
- function isLegacyContentObject(value) {
3368
- return typeof value === "object" && value !== null && "files" in value;
3369
- }
3370
- function createRawContentEntries(candidates, sources) {
3371
- const entries = [];
3372
- const candidateContent = [...candidates].join(" ");
3373
- if (candidateContent.length > 0) entries.push({
3374
- raw: candidateContent,
3375
- extension: "html"
3376
- });
3377
- for (const source of sources) entries.push({
3378
- raw: source.content,
3379
- extension: source.extension ?? "html"
3380
- });
3381
- return entries;
3382
- }
3383
- function createChangedContentEntries(candidates, sources) {
3384
- return createRawContentEntries(candidates, sources).map((entry) => ({
3385
- content: entry.raw,
3386
- extension: entry.extension
3387
- }));
3388
- }
3389
- function collectCandidates(candidates) {
3390
- return new Set(candidates ?? []);
3534
+ //#endregion
3535
+ //#region src/tailwindcss/v3-engine/generator.ts
3536
+ const incrementalGenerateCache = /* @__PURE__ */ new Map();
3537
+ const patchRawStyleGenerator = typeof tailwindcss_patch.generateTailwindV3RawStyle === "function" ? tailwindcss_patch.generateTailwindV3RawStyle : void 0;
3538
+ function isTailwindV3PatchResolutionError(error, packageName) {
3539
+ if (!error || typeof error !== "object") return false;
3540
+ const code = error.code;
3541
+ if (code !== "MODULE_NOT_FOUND" && code !== "ERR_PACKAGE_PATH_NOT_EXPORTED") return false;
3542
+ return String(error.message ?? "").includes(`${packageName}/lib/`);
3391
3543
  }
3392
3544
  function normalizeBareArbitraryValueCandidate(candidate, bareArbitraryValues) {
3393
3545
  return (0, tailwindcss_patch.resolveBareArbitraryValueCandidate)(candidate, bareArbitraryValues)?.canonicalCandidate ?? candidate;
@@ -3408,7 +3560,7 @@ function normalizeBareArbitraryValueCandidates(candidates, bareArbitraryValues)
3408
3560
  async function collectSourceBareArbitraryValueCandidates(sources, bareArbitraryValues) {
3409
3561
  if (!(0, tailwindcss_patch.isBareArbitraryValuesEnabled)(bareArbitraryValues)) return [];
3410
3562
  const candidates = /* @__PURE__ */ new Set();
3411
- for (const source of sources ?? []) for (const candidate of await (0, tailwindcss_patch.extractSourceCandidates)(source.content, source.extension ?? "html", { bareArbitraryValues })) if ((0, tailwindcss_patch.resolveBareArbitraryValueCandidate)(candidate, bareArbitraryValues)) candidates.add(candidate);
3563
+ for (const source of sources ?? []) for (const candidate of await (0, tailwindcss_patch.extractSourceCandidates)(source.content, source.extension ?? "html", omitUndefined({ bareArbitraryValues }))) if ((0, tailwindcss_patch.resolveBareArbitraryValueCandidate)(candidate, bareArbitraryValues)) candidates.add(candidate);
3412
3564
  return [...candidates];
3413
3565
  }
3414
3566
  function escapeCssClassSelector(className) {
@@ -3444,99 +3596,6 @@ function hasRemovedCandidates(previousCandidates, nextCandidates) {
3444
3596
  for (const candidate of previousCandidates) if (!nextCandidates.has(candidate)) return true;
3445
3597
  return false;
3446
3598
  }
3447
- function collectApplyCandidatesFromCss(css) {
3448
- if (!css.includes("@apply")) return [];
3449
- const candidates = /* @__PURE__ */ new Set();
3450
- try {
3451
- require_watch_dependencies.postcss_default.parse(css).walkAtRules("apply", (rule) => {
3452
- for (const candidate of rule.params.split(/\s+/)) {
3453
- const normalized = candidate.replace(/!important$/, "").trim();
3454
- if (normalized) candidates.add(normalized);
3455
- }
3456
- });
3457
- } catch {}
3458
- return [...candidates];
3459
- }
3460
- function isTailwindCandidateLayer(params) {
3461
- return params.split(/[,\s]+/).some((layer) => layer === "components" || layer === "utilities");
3462
- }
3463
- function extractClassCandidatesFromSelector(selector, candidates) {
3464
- for (let index = 0; index < selector.length; index++) {
3465
- if (selector[index] !== ".") continue;
3466
- let candidate = "";
3467
- let escaped = false;
3468
- for (let tokenIndex = index + 1; tokenIndex < selector.length; tokenIndex++) {
3469
- const char = selector[tokenIndex];
3470
- if (escaped) {
3471
- candidate += char;
3472
- escaped = false;
3473
- continue;
3474
- }
3475
- if (char === "\\") {
3476
- escaped = true;
3477
- continue;
3478
- }
3479
- if (char && /[\w-]/.test(char)) {
3480
- candidate += char;
3481
- continue;
3482
- }
3483
- break;
3484
- }
3485
- if (candidate) candidates.add(candidate);
3486
- }
3487
- }
3488
- function collectLayerCandidatesFromCss(css) {
3489
- if (!css.includes("@layer")) return [];
3490
- const candidates = /* @__PURE__ */ new Set();
3491
- try {
3492
- require_watch_dependencies.postcss_default.parse(css).walkAtRules("layer", (layer) => {
3493
- if (!isTailwindCandidateLayer(layer.params)) return;
3494
- layer.walkRules((rule) => {
3495
- extractClassCandidatesFromSelector(rule.selector, candidates);
3496
- });
3497
- });
3498
- } catch {}
3499
- return [...candidates];
3500
- }
3501
- function mergeGenerateCandidates(source, options) {
3502
- return collectCandidates([
3503
- ...collectLayerCandidatesFromCss(source.css),
3504
- ...collectApplyCandidatesFromCss(source.css),
3505
- ...collectCandidates(options.candidates)
3506
- ]);
3507
- }
3508
- function mergeContent(content, rawEntries) {
3509
- if (isLegacyContentObject(content)) return {
3510
- ...content,
3511
- relative: content.relative ?? true,
3512
- files: [...[].concat(content.files ?? []), ...rawEntries]
3513
- };
3514
- return {
3515
- relative: true,
3516
- files: [...[].concat(content ?? []), ...rawEntries]
3517
- };
3518
- }
3519
- function normalizeConfigObject(config) {
3520
- if (!config || typeof config !== "object") return config;
3521
- const maybeDefault = config.default;
3522
- if (maybeDefault && typeof maybeDefault === "object") return maybeDefault;
3523
- return config;
3524
- }
3525
- function hasExplicitContentInput(options) {
3526
- return options.candidates !== void 0 || options.sources !== void 0;
3527
- }
3528
- function createExplicitContentConfig(rawEntries) {
3529
- return {
3530
- relative: true,
3531
- files: rawEntries
3532
- };
3533
- }
3534
- function createTailwindConfig(source, options) {
3535
- const config = { ...normalizeConfigObject(source.configObject) ?? {} };
3536
- const rawEntries = createRawContentEntries(mergeGenerateCandidates(source, options), options.sources ?? []);
3537
- config.content = hasExplicitContentInput(options) ? createExplicitContentConfig(rawEntries) : mergeContent(config.content, rawEntries);
3538
- return config;
3539
- }
3540
3599
  function shouldAutoEnableCssMacro(source) {
3541
3600
  return hasCssMacroTailwindPlugin(normalizeConfigObject(source.configObject)?.plugins);
3542
3601
  }
@@ -3576,48 +3635,6 @@ function loadTailwindV3Internals(source) {
3576
3635
  validateConfig: validateConfigModule["validateConfig"]
3577
3636
  };
3578
3637
  }
3579
- function createStableJson$1(value) {
3580
- if (value === void 0) return "undefined";
3581
- if (value === null || typeof value !== "object") return JSON.stringify(value);
3582
- if (Array.isArray(value)) return `[${value.map((item) => createStableJson$1(item)).join(",")}]`;
3583
- return `{${Object.keys(value).sort().map((key) => {
3584
- const record = value;
3585
- return `${JSON.stringify(key)}:${createStableJson$1(record[key])}`;
3586
- }).join(",")}}`;
3587
- }
3588
- function createDependencyFingerprint(files) {
3589
- return files.map((file) => {
3590
- try {
3591
- const stat = node_fs.default.statSync(file);
3592
- return `${file}:${stat.size}:${stat.mtimeMs}`;
3593
- } catch {
3594
- return `${file}:missing`;
3595
- }
3596
- }).join("|");
3597
- }
3598
- function createIncrementalGenerateCacheKey(source, target, styleOptions, bareArbitraryValues) {
3599
- return [
3600
- source.packageName,
3601
- source.postcssPlugin,
3602
- source.cwd,
3603
- source.config ?? "config:missing",
3604
- createDependencyFingerprint(source.dependencies),
3605
- source.css,
3606
- createStableJson$1(normalizeConfigObject(source.configObject)?.content),
3607
- target,
3608
- createStableJson$1(styleOptions),
3609
- createStableJson$1(bareArbitraryValues)
3610
- ].join("\0");
3611
- }
3612
- function createRuntimeReadyCacheKey(source, rootPath) {
3613
- return [
3614
- source.packageName,
3615
- source.postcssPlugin,
3616
- rootPath ?? "missing",
3617
- source.config ?? "config:missing",
3618
- source.cwd
3619
- ].join("\0");
3620
- }
3621
3638
  function isDirectUtilitiesOnlyCss(css) {
3622
3639
  return css.replace(/\s+/g, "") === "@tailwindutilities;";
3623
3640
  }
@@ -3650,27 +3667,25 @@ function appendUtilityRules(root, context, rules) {
3650
3667
  function appendDirectUtilityRules(root, context) {
3651
3668
  appendUtilityRules(root, context, [...context.ruleCache]);
3652
3669
  }
3653
- function createRuntimeReadyPromise(source) {
3654
- const patcher = createTailwindcssPatcher({
3655
- basedir: source.cwd,
3656
- supportCustomLengthUnitsPatch: true,
3657
- tailwindcss: {
3658
- ...source.config === void 0 ? {} : { config: source.config },
3659
- cwd: source.cwd,
3660
- packageName: source.packageName,
3661
- postcssPlugin: source.postcssPlugin,
3662
- version: 3
3663
- }
3664
- });
3665
- const cacheKey = createRuntimeReadyCacheKey(source, patcher.packageInfo?.rootPath);
3666
- const cached = runtimeReadyPromiseCache.get(cacheKey);
3667
- if (cached) return cached;
3668
- const task = ensureTailwindcssRuntimePatch(patcher, { clearRequireCache: true }).catch((error) => {
3669
- runtimeReadyPromiseCache.delete(cacheKey);
3670
+ async function generateRawStyleWithPatch(generateSource, candidates, sources) {
3671
+ if (!patchRawStyleGenerator) return;
3672
+ try {
3673
+ return await patchRawStyleGenerator({
3674
+ cwd: generateSource.cwd,
3675
+ packageName: generateSource.packageName,
3676
+ css: generateSource.css,
3677
+ candidates,
3678
+ sources,
3679
+ config: createTailwindConfig(generateSource, {
3680
+ candidates,
3681
+ sources
3682
+ }),
3683
+ directUtilitiesOnly: "auto"
3684
+ });
3685
+ } catch (error) {
3686
+ if (isTailwindV3PatchResolutionError(error, generateSource.packageName)) return;
3670
3687
  throw error;
3671
- });
3672
- runtimeReadyPromiseCache.set(cacheKey, task);
3673
- return task;
3688
+ }
3674
3689
  }
3675
3690
  function createTailwindV3Engine(source) {
3676
3691
  const runtimeReadyPromise = createRuntimeReadyPromise(source);
@@ -3697,23 +3712,32 @@ function createTailwindV3Engine(source) {
3697
3712
  messages: []
3698
3713
  };
3699
3714
  let context;
3700
- if (isDirectUtilitiesOnlyCss(generateSource.css)) {
3701
- context = internals.createContext(tailwindConfig, changedContent, root);
3702
- internals.generateRules(new Set(sortCandidates([internals.notOnDemandCandidate, ...candidates])), context);
3703
- root.removeAll();
3704
- appendDirectUtilityRules(root, context);
3705
- internals.resolveDefaultsAtRules(context)(root, result);
3706
- internals.collapseAdjacentRules(context)(root, result);
3707
- internals.collapseDuplicateDeclarations(context)(root, result);
3715
+ let rawCss;
3716
+ let dependencies;
3717
+ const patchGenerated = await generateRawStyleWithPatch(generateSource, candidates, options.sources ?? []);
3718
+ if (patchGenerated) {
3719
+ context = patchGenerated.context;
3720
+ rawCss = restoreBareArbitraryValueCssSelectors(patchGenerated.css, requestedCandidates, options.bareArbitraryValues, internals.escapeClassName);
3721
+ dependencies = new Set(patchGenerated.dependencies);
3708
3722
  } else {
3709
- const setupContext = () => {
3710
- return (currentRoot) => internals.createContext(tailwindConfig, changedContent, currentRoot);
3711
- };
3712
- context = await internals.processTailwindFeatures(setupContext)(root, result);
3723
+ if (isDirectUtilitiesOnlyCss(generateSource.css)) {
3724
+ context = internals.createContext(tailwindConfig, changedContent, root);
3725
+ internals.generateRules(new Set(sortCandidates([internals.notOnDemandCandidate, ...candidates])), context);
3726
+ root.removeAll();
3727
+ appendDirectUtilityRules(root, context);
3728
+ internals.resolveDefaultsAtRules(context)(root, result);
3729
+ internals.collapseAdjacentRules(context)(root, result);
3730
+ internals.collapseDuplicateDeclarations(context)(root, result);
3731
+ } else {
3732
+ const setupContext = () => {
3733
+ return (currentRoot) => internals.createContext(tailwindConfig, changedContent, currentRoot);
3734
+ };
3735
+ context = await internals.processTailwindFeatures(setupContext)(root, result);
3736
+ }
3737
+ rawCss = restoreBareArbitraryValueCssSelectors(root.toString(), requestedCandidates, options.bareArbitraryValues, internals.escapeClassName);
3738
+ dependencies = collectDependencyMessages(result);
3713
3739
  }
3714
- const rawCss = restoreBareArbitraryValueCssSelectors(root.toString(), requestedCandidates, options.bareArbitraryValues, internals.escapeClassName);
3715
3740
  const css = await transformTailwindV3CssByTarget(rawCss, target, resolvedStyleOptions);
3716
- const dependencies = collectDependencyMessages(result);
3717
3741
  for (const dependency of generateSource.dependencies) dependencies.add(dependency);
3718
3742
  const classSet = restoreBareArbitraryValueClassSet(collectClassSet(context), requestedCandidates, options.bareArbitraryValues);
3719
3743
  return {
@@ -3757,7 +3781,7 @@ function createTailwindV3Engine(source) {
3757
3781
  const requestedCandidates = mergeGenerateCandidates(source, options);
3758
3782
  if (requestedCandidates.size === 0) return generateOnce(source, options);
3759
3783
  const styleOptions = resolveStyleOptions(source, options.styleOptions);
3760
- const cacheKey = createIncrementalGenerateCacheKey(source, target, styleOptions, options.bareArbitraryValues);
3784
+ const cacheKey = createIncrementalGenerateCacheKey$1(source, target, styleOptions, options.bareArbitraryValues);
3761
3785
  const cached = incrementalGenerateCache.get(cacheKey);
3762
3786
  if (cached) {
3763
3787
  if (hasRemovedCandidates(cached.seenCandidates, requestedCandidates)) {
@@ -3913,66 +3937,223 @@ function resolveTailwindV3SourceOptionsFromPatcher(patcher) {
3913
3937
  postcssPlugin: tailwindOptions?.v3?.postcssPlugin ?? tailwindOptions?.postcssPlugin
3914
3938
  };
3915
3939
  }
3916
- function resolveTailwindV3SourceFromPatcher(patcher) {
3917
- return resolveTailwindV3Source(resolveTailwindV3SourceOptionsFromPatcher(patcher));
3940
+ function resolveTailwindV3SourceFromPatcher(patcher) {
3941
+ return resolveTailwindV3Source(resolveTailwindV3SourceOptionsFromPatcher(patcher));
3942
+ }
3943
+ //#endregion
3944
+ //#region src/generator/options.ts
3945
+ const explicitGeneratorTargetEnvKeys = ["WEAPP_TW_TARGET", "WEAPP_TAILWINDCSS_TARGET"];
3946
+ const uniWebPlatformEnvKeys = ["UNI_PLATFORM", "UNI_UTS_PLATFORM"];
3947
+ const mpxWebPlatformEnvKeys = ["MPX_CLI_MODE", "MPX_CURRENT_TARGET_MODE"];
3948
+ function getEnvValue(key) {
3949
+ return typeof node_process.default === "undefined" ? void 0 : node_process.default.env[key];
3950
+ }
3951
+ function normalizeGeneratorTargetValue(value) {
3952
+ return value === "weapp" || value === "web" || value === "tailwind" ? value : void 0;
3953
+ }
3954
+ function isUniWebPlatform(value) {
3955
+ const normalized = value?.trim().toLowerCase();
3956
+ return normalized === "h5" || normalized?.startsWith("web") === true;
3957
+ }
3958
+ function isUniAppWebViewPlatform(value) {
3959
+ const normalized = value?.trim().toLowerCase();
3960
+ return normalized === "app" || normalized === "app-plus";
3961
+ }
3962
+ function isUniNativeAppPlatform(value) {
3963
+ return (value?.trim().toLowerCase())?.startsWith("app-") === true;
3964
+ }
3965
+ function isMpxWebPlatform(value) {
3966
+ return value?.trim().toLowerCase() === "web";
3967
+ }
3968
+ function inferGeneratorTargetFromEnv() {
3969
+ for (const key of explicitGeneratorTargetEnvKeys) {
3970
+ const target = normalizeGeneratorTargetValue(getEnvValue(key));
3971
+ if (target !== void 0) return target;
3972
+ }
3973
+ if (uniWebPlatformEnvKeys.some((key) => isUniWebPlatform(getEnvValue(key))) || isUniAppWebViewPlatform(getEnvValue("UNI_PLATFORM")) && !isUniNativeAppPlatform(getEnvValue("UNI_UTS_PLATFORM")) || mpxWebPlatformEnvKeys.some((key) => isMpxWebPlatform(getEnvValue(key))) || getEnvValue("TARO_ENV") === "h5") return "web";
3974
+ return "weapp";
3975
+ }
3976
+ function normalizeWeappTailwindcssGeneratorOptions(options) {
3977
+ const target = options?.target ?? inferGeneratorTargetFromEnv();
3978
+ if (options == null) return {
3979
+ target,
3980
+ importFallback: true,
3981
+ tailwindcssV3Compatibility: target === "weapp",
3982
+ bareArbitraryValues: void 0
3983
+ };
3984
+ return {
3985
+ target,
3986
+ config: options.config,
3987
+ styleOptions: options.styleOptions,
3988
+ importFallback: options.importFallback ?? true,
3989
+ tailwindcssV3Compatibility: options.tailwindcssV3Compatibility ?? target === "weapp",
3990
+ bareArbitraryValues: options.bareArbitraryValues
3991
+ };
3992
+ }
3993
+ //#endregion
3994
+ //#region src/generator/index.ts
3995
+ function isTailwindV3Source(source) {
3996
+ return "version" in source && source.version === 3;
3997
+ }
3998
+ function createWeappTailwindcssGenerator(source) {
3999
+ return isTailwindV3Source(source) ? createTailwindV3Engine(source) : createTailwindV4Engine(source);
4000
+ }
4001
+ //#endregion
4002
+ //#region src/uni-app-x/options.ts
4003
+ const DEFAULT_COMPONENT_LOCAL_STYLES_OPTIONS = {
4004
+ enabled: true,
4005
+ onlyWhenStyleIsolationVersion2: true
4006
+ };
4007
+ const DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS = {
4008
+ enabled: false,
4009
+ onlyWhenStyleIsolationVersion2: true
4010
+ };
4011
+ function isBooleanUniAppXShortcut(option) {
4012
+ return option === true || option === false || option === void 0;
4013
+ }
4014
+ function resolveComponentLocalStyles(option) {
4015
+ if (isBooleanUniAppXShortcut(option)) return DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS;
4016
+ const componentLocalStyles = option.componentLocalStyles;
4017
+ if (componentLocalStyles === false) return DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS;
4018
+ if (componentLocalStyles === true || componentLocalStyles === void 0) return DEFAULT_COMPONENT_LOCAL_STYLES_OPTIONS;
4019
+ return {
4020
+ enabled: componentLocalStyles.enabled !== false,
4021
+ onlyWhenStyleIsolationVersion2: componentLocalStyles.onlyWhenStyleIsolationVersion2 !== false
4022
+ };
4023
+ }
4024
+ function resolveUniAppXOptions(option) {
4025
+ if (typeof option === "object" && option) return {
4026
+ enabled: option.enabled !== false,
4027
+ componentLocalStyles: resolveComponentLocalStyles(option),
4028
+ uvueUnsupported: option.uvueUnsupported ?? "warn"
4029
+ };
4030
+ return {
4031
+ enabled: Boolean(option),
4032
+ componentLocalStyles: resolveComponentLocalStyles(option),
4033
+ uvueUnsupported: "warn"
4034
+ };
4035
+ }
4036
+ function isUniAppXEnabled(option) {
4037
+ return resolveUniAppXOptions(option).enabled;
3918
4038
  }
3919
4039
  //#endregion
3920
- //#region src/generator/options.ts
3921
- const explicitGeneratorTargetEnvKeys = ["WEAPP_TW_TARGET", "WEAPP_TAILWINDCSS_TARGET"];
3922
- const uniWebPlatformEnvKeys = ["UNI_PLATFORM", "UNI_UTS_PLATFORM"];
3923
- const mpxWebPlatformEnvKeys = ["MPX_CLI_MODE", "MPX_CURRENT_TARGET_MODE"];
3924
- function getEnvValue(key) {
3925
- return typeof node_process.default === "undefined" ? void 0 : node_process.default.env[key];
4040
+ //#region src/context/style-options.ts
4041
+ function resolveStyleOptionsFromContext(ctx) {
4042
+ const resolvedUniAppXOptions = resolveUniAppXOptions(ctx.uniAppX);
4043
+ return {
4044
+ cssPreflight: ctx.cssPreflight,
4045
+ cssPreflightRange: ctx.cssPreflightRange,
4046
+ cssChildCombinatorReplaceValue: ctx.cssChildCombinatorReplaceValue,
4047
+ cssSelectorReplacement: ctx.cssSelectorReplacement,
4048
+ rem2rpx: ctx.rem2rpx,
4049
+ cssRemoveProperty: ctx.cssRemoveProperty,
4050
+ cssRemoveHoverPseudoClass: ctx.cssRemoveHoverPseudoClass,
4051
+ cssPresetEnv: ctx.cssPresetEnv,
4052
+ autoprefixer: ctx.autoprefixer,
4053
+ cssCalc: ctx.cssCalc,
4054
+ uniAppX: resolvedUniAppXOptions.enabled,
4055
+ platform: ctx.platform,
4056
+ px2rpx: ctx.px2rpx,
4057
+ unitsToPx: ctx.unitsToPx,
4058
+ unitConversion: ctx.unitConversion
4059
+ };
3926
4060
  }
3927
- function normalizeGeneratorTargetValue(value) {
3928
- return value === "weapp" || value === "web" || value === "tailwind" ? value : void 0;
4061
+ //#endregion
4062
+ //#region src/bundlers/shared/generator-css/generation-helpers.ts
4063
+ function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight, options = {}) {
4064
+ if (target !== "weapp") return css;
4065
+ return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, {
4066
+ cssPreflight: majorVersion === 4 && options.injectPreflight !== false ? cssPreflight : void 0,
4067
+ isTailwindcssV4: majorVersion === 4,
4068
+ preservePseudoContentInit: majorVersion === 3
4069
+ });
3929
4070
  }
3930
- function isUniWebPlatform(value) {
3931
- const normalized = value?.trim().toLowerCase();
3932
- return normalized === "h5" || normalized?.startsWith("web") === true;
4071
+ function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
4072
+ if (options.cssHandlerOptions.uniAppX === true && options.cssHandlerOptions.uniAppXCssTarget === "uvue") return false;
4073
+ if (!options.isolateCurrentCssCandidates) return true;
4074
+ return isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
3933
4075
  }
3934
- function isUniAppWebViewPlatform(value) {
3935
- const normalized = value?.trim().toLowerCase();
3936
- return normalized === "app" || normalized === "app-plus";
4076
+ function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
4077
+ if (options.isolateCssSource && options.currentCssCandidates?.length) return new Set([...scopedRuntime, ...options.currentCssCandidates]);
4078
+ if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.matchedCssSourceFile || options.isolateCssSource && scopedRuntime.size === 0) return scopedRuntime;
4079
+ return new Set([...scopedRuntime, ...runtime]);
3937
4080
  }
3938
- function isUniNativeAppPlatform(value) {
3939
- return (value?.trim().toLowerCase())?.startsWith("app-") === true;
4081
+ function shouldIsolateScopedCssSource(source, sourceEntries) {
4082
+ return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile) || sourceEntries !== void 0 && sourceEntries.length > 0;
3940
4083
  }
3941
- function isMpxWebPlatform(value) {
3942
- return value?.trim().toLowerCase() === "web";
4084
+ function shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, options) {
4085
+ return majorVersion === 4 && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(options.rawSource) && !hasTailwindRootDirectives(options.rawSource) && !options.hasGeneratedCss && !options.hasGeneratedMarkers;
3943
4086
  }
3944
- function inferGeneratorTargetFromEnv() {
3945
- for (const key of explicitGeneratorTargetEnvKeys) {
3946
- const target = normalizeGeneratorTargetValue(getEnvValue(key));
3947
- if (target !== void 0) return target;
3948
- }
3949
- if (uniWebPlatformEnvKeys.some((key) => isUniWebPlatform(getEnvValue(key))) || isUniAppWebViewPlatform(getEnvValue("UNI_PLATFORM")) && !isUniNativeAppPlatform(getEnvValue("UNI_UTS_PLATFORM")) || mpxWebPlatformEnvKeys.some((key) => isMpxWebPlatform(getEnvValue(key))) || getEnvValue("TARO_ENV") === "h5") return "web";
3950
- return "weapp";
4087
+ function shouldScanTailwindV4Sources(majorVersion, target, generatorRuntime, isolateCssSource) {
4088
+ if (majorVersion !== 4) return false;
4089
+ if (target === "web") return true;
4090
+ if (isolateCssSource) return false;
4091
+ return generatorRuntime.size === 0;
3951
4092
  }
3952
- function normalizeWeappTailwindcssGeneratorOptions(options) {
3953
- const target = options?.target ?? inferGeneratorTargetFromEnv();
3954
- if (options == null) return {
3955
- target,
3956
- importFallback: true,
3957
- tailwindcssV3Compatibility: target === "weapp",
3958
- bareArbitraryValues: void 0
4093
+ function shouldAppendWebBundleCssFallback(target, options) {
4094
+ return target === "web" && !options.hasMatchedCssSourceFile && !options.hasSourceDirectives;
4095
+ }
4096
+ function isEmptyCssSourceOrderParts(parts) {
4097
+ return parts.before.trim().length === 0 && parts.after.trim().length === 0;
4098
+ }
4099
+ function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
4100
+ const preflightStyleOptions = {
4101
+ cssPreflight: opts.cssPreflight,
4102
+ cssPreflightRange: opts.cssPreflightRange
3959
4103
  };
3960
4104
  return {
3961
- target,
3962
- config: options.config,
3963
- styleOptions: options.styleOptions,
3964
- importFallback: options.importFallback ?? true,
3965
- tailwindcssV3Compatibility: options.tailwindcssV3Compatibility ?? target === "weapp",
3966
- bareArbitraryValues: options.bareArbitraryValues
4105
+ ...resolveStyleOptionsFromContext(opts),
4106
+ atRules: opts.atRules,
4107
+ uniAppXCssTarget: opts.uniAppXCssTarget,
4108
+ uniAppXUnsupported: opts.uniAppXUnsupported,
4109
+ ...cssHandlerOptions,
4110
+ ...preflightStyleOptions,
4111
+ ...generatorStyleOptions
3967
4112
  };
3968
4113
  }
3969
- //#endregion
3970
- //#region src/generator/index.ts
3971
- function isTailwindV3Source(source) {
3972
- return "version" in source && source.version === 3;
4114
+ function createCssSourceOrderAppend$1(base, extra) {
4115
+ if (!base) return extra;
4116
+ if (!extra) return base;
4117
+ if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
4118
+ return `${base}\n${extra}`;
3973
4119
  }
3974
- function createWeappTailwindcssGenerator(source) {
3975
- return isTailwindV3Source(source) ? createTailwindV3Engine(source) : createTailwindV4Engine(source);
4120
+ function shouldFinalizeMarkedUserLayerComponentsCss(file) {
4121
+ return !/\.(?:vue|svelte|astro|scss|sass|less|styl)(?:[?#].*)?$/i.test(file);
4122
+ }
4123
+ function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
4124
+ const placeholderParts = splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
4125
+ if (placeholderParts) return placeholderParts;
4126
+ const exactParts = splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss);
4127
+ if (exactParts) return exactParts;
4128
+ return splitTailwindGeneratedCssByBanner(rawSource);
4129
+ }
4130
+ function shouldUseGeneratorForCurrentCss(majorVersion, cssHandlerOptions, options) {
4131
+ const hasApplyDirectives = hasTailwindApplyDirective(options.rawSource);
4132
+ return options.hasGeneratedCss || options.hasGeneratedMarkers || options.hasSourceDirectives || majorVersion === 4 && hasApplyDirectives || cssHandlerOptions.isMainChunk;
4133
+ }
4134
+ function createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates) {
4135
+ return isolateCurrentCssCandidates ? new Set(currentCssCandidates) : currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
4136
+ }
4137
+ function mergeGeneratorResults(generatedResults) {
4138
+ const firstGenerated = generatedResults[0];
4139
+ if (!firstGenerated) return;
4140
+ if (generatedResults.length === 1) return firstGenerated;
4141
+ const incrementalCssResults = generatedResults.map((item) => item.incrementalCss).filter((css) => typeof css === "string");
4142
+ const incrementalRawCssResults = generatedResults.map((item) => item.incrementalRawCss).filter((css) => typeof css === "string");
4143
+ return {
4144
+ ...firstGenerated,
4145
+ css: generatedResults.map((item) => item.css).join("\n"),
4146
+ rawCss: generatedResults.map((item) => item.rawCss).join("\n"),
4147
+ incrementalCss: incrementalCssResults.length === generatedResults.length ? incrementalCssResults.filter(Boolean).join("\n") : void 0,
4148
+ incrementalRawCss: incrementalRawCssResults.length === generatedResults.length ? incrementalRawCssResults.filter(Boolean).join("\n") : void 0,
4149
+ classSet: new Set(generatedResults.flatMap((item) => [...item.classSet])),
4150
+ dependencies: [...new Set(generatedResults.flatMap((item) => item.dependencies))],
4151
+ sources: generatedResults.flatMap((item) => item.sources)
4152
+ };
4153
+ }
4154
+ const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
4155
+ function isSupportedGeneratorMajorVersion(majorVersion) {
4156
+ return SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0);
3976
4157
  }
3977
4158
  //#endregion
3978
4159
  //#region src/wxml/shared.ts
@@ -4376,13 +4557,6 @@ function isPathWithinRoot$1(file, root) {
4376
4557
  const relative = node_path.default.relative(root, file);
4377
4558
  return Boolean(relative) && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
4378
4559
  }
4379
- function countCommonSuffixSegments(a, b) {
4380
- const aSegments = a.split("/").filter(Boolean);
4381
- const bSegments = b.split("/").filter(Boolean);
4382
- let count = 0;
4383
- while (count < aSegments.length && count < bSegments.length && aSegments[aSegments.length - 1 - count] === bSegments[bSegments.length - 1 - count]) count++;
4384
- return count;
4385
- }
4386
4560
  function collectOutputMatchBases(file, sourceOptions) {
4387
4561
  const normalizedFile = file.replace(/[?#].*$/, "");
4388
4562
  const roots = [
@@ -4417,7 +4591,7 @@ function isMatchingSourceStyleFile(file, sourceFile, sourceOptions) {
4417
4591
  const normalizedRoot = node_path.default.resolve(root);
4418
4592
  if (isPathWithinRoot$1(normalizedSourceFile, normalizedRoot)) addSourceBase(node_path.default.relative(normalizedRoot, normalizedSourceFile));
4419
4593
  }
4420
- for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`) || countCommonSuffixSegments(outputBase, sourceBase) >= 2) return true;
4594
+ for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`)) return true;
4421
4595
  return false;
4422
4596
  }
4423
4597
  function scoreMatchingSourceStyleFile(file, sourceFile, sourceOptions) {
@@ -4435,13 +4609,9 @@ function scoreMatchingSourceStyleFile(file, sourceFile, sourceOptions) {
4435
4609
  if (isPathWithinRoot$1(normalizedSourceFile, normalizedRoot)) addSourceBase(node_path.default.relative(normalizedRoot, normalizedSourceFile));
4436
4610
  }
4437
4611
  let bestScore = 0;
4438
- for (const outputBase of outputBases) for (const sourceBase of sourceBases) {
4439
- const commonSuffixSegments = countCommonSuffixSegments(outputBase, sourceBase);
4440
- if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
4441
- else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
4442
- else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
4443
- else if (commonSuffixSegments >= 2) bestScore = Math.max(bestScore, 100 + commonSuffixSegments);
4444
- }
4612
+ for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
4613
+ else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
4614
+ else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
4445
4615
  return bestScore;
4446
4616
  }
4447
4617
  function collectMatchedConfiguredSourceFiles(file, sourceOptions) {
@@ -4600,7 +4770,7 @@ function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
4600
4770
  return true;
4601
4771
  }
4602
4772
  function shouldResolveSourceSideCssEntry(rawSource) {
4603
- return rawSource.includes("@apply") || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
4773
+ return rawSource.includes("@apply") || hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindSourceDirectives(rawSource, { importFallback: true }) || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
4604
4774
  }
4605
4775
  function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
4606
4776
  return Boolean(sourceSideEntrySource) && !hasTailwindSourceDirectives(rawSource, { importFallback: true });
@@ -4645,17 +4815,6 @@ function collectCssSourceMatchBases(file, roots) {
4645
4815
  } else for (const root of resolvedRoots) addBase(node_path.default.resolve(root, normalizedFile));
4646
4816
  return bases;
4647
4817
  }
4648
- function hasMatchingCssSourceBase(outputBases, sourceBases) {
4649
- for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`)) return true;
4650
- return false;
4651
- }
4652
- function isMatchingTailwindV4CssSourceFile(file, cssSourceFile, sourceOptions) {
4653
- return hasMatchingCssSourceBase(collectCssSourceMatchBases(file, [
4654
- sourceOptions.outputRoot,
4655
- sourceOptions.projectRoot,
4656
- sourceOptions.cwd
4657
- ]), collectCssSourceMatchBases(cssSourceFile, [sourceOptions.projectRoot, sourceOptions.cwd]));
4658
- }
4659
4818
  function scoreTailwindV4CssSourceFileMatch(file, cssSourceFile, sourceOptions) {
4660
4819
  const outputBases = collectCssSourceMatchBases(file, [
4661
4820
  sourceOptions.outputRoot,
@@ -4742,12 +4901,29 @@ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOpt
4742
4901
  if (!cssSources?.length) return;
4743
4902
  const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
4744
4903
  const sourceFile = resolvePostcssSourceFile(cssHandlerOptions);
4745
- const matchingSource = cssSources.find((cssSource) => {
4746
- if (typeof cssSource.css !== "string" || cssSource.css.length === 0) return false;
4747
- if (sourceFile && typeof cssSource.file === "string" && node_path.default.resolve(sourceFile) === node_path.default.resolve(cssSource.file)) return true;
4748
- if (typeof cssSource.file === "string" && isMatchingTailwindV4CssSourceFile(file, cssSource.file, sourceOptions)) return true;
4749
- return normalizeCssSourceForCompare(cssSource.css) === normalizedRawSource;
4750
- });
4904
+ const matches = cssSources.map((cssSource, index) => {
4905
+ if (typeof cssSource.css !== "string" || cssSource.css.length === 0) return;
4906
+ if (sourceFile && typeof cssSource.file === "string" && node_path.default.resolve(sourceFile) === node_path.default.resolve(cssSource.file)) return {
4907
+ cssSource,
4908
+ index,
4909
+ score: 1e6
4910
+ };
4911
+ if (typeof cssSource.file === "string") {
4912
+ const pathScore = scoreTailwindV4CssSourceFileMatch(file, cssSource.file, sourceOptions);
4913
+ if (pathScore > 0) return {
4914
+ cssSource,
4915
+ index,
4916
+ score: pathScore
4917
+ };
4918
+ }
4919
+ if (normalizeCssSourceForCompare(cssSource.css) === normalizedRawSource) return {
4920
+ cssSource,
4921
+ index,
4922
+ score: 1
4923
+ };
4924
+ }).filter((match) => Boolean(match)).sort((a, b) => b.score - a.score || a.index - b.index);
4925
+ const bestScore = matches[0]?.score;
4926
+ const matchingSource = bestScore && matches.filter((match) => match.score === bestScore).length === 1 ? matches[0]?.cssSource : void 0;
4751
4927
  if (!matchingSource) return;
4752
4928
  return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions, { matched: true });
4753
4929
  }
@@ -4819,7 +4995,10 @@ function createTailwindV4CssSourceResolver(sourceOptions, generatorOptions) {
4819
4995
  async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourceOptions, generatorOptions, file) {
4820
4996
  if (!resolvedEntrySource) return;
4821
4997
  const resolvedSourceOptions = omitUndefined(sourceOptions);
4822
- const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, resolvedSourceOptions);
4998
+ const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, {
4999
+ ...resolvedSourceOptions,
5000
+ sourceFile: resolvedEntrySource.file
5001
+ });
4823
5002
  const css = createTailwindV4ApplyReferenceSource(normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions);
4824
5003
  return withMatchedSourceSideMetadata(await resolveTailwindV4Source(createSingleTailwindV4SourceOptions(resolvedSourceOptions, {
4825
5004
  base: resolvedEntrySource.base,
@@ -4850,7 +5029,25 @@ function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
4850
5029
  }
4851
5030
  function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
4852
5031
  if (!hasTailwindApplyDirective(css) || hasTailwindRootDirectives(css)) return css;
4853
- return `@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);\n${css}`;
5032
+ const utilities = collectTailwindApplyUtilities(css);
5033
+ return [
5034
+ `@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);`,
5035
+ utilities.length > 0 ? `@source inline(${JSON.stringify(utilities.join(" "))});` : void 0,
5036
+ css
5037
+ ].filter(Boolean).join("\n");
5038
+ }
5039
+ function collectTailwindApplyUtilities(css) {
5040
+ let root;
5041
+ try {
5042
+ root = require_watch_dependencies.postcss_default.parse(css);
5043
+ } catch {
5044
+ return [];
5045
+ }
5046
+ const utilities = /* @__PURE__ */ new Set();
5047
+ root.walkAtRules("apply", (rule) => {
5048
+ for (const utility of (0, tailwindcss_patch.splitCandidateTokens)(rule.params)) utilities.add(utility);
5049
+ });
5050
+ return [...utilities].sort();
4854
5051
  }
4855
5052
  async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
4856
5053
  const base = resolveCssSourceBase(file, cssHandlerOptions);
@@ -4963,11 +5160,15 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
4963
5160
  return resolved ? [resolved] : [];
4964
5161
  }
4965
5162
  const matchedCssEntrySource = sourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
5163
+ if (matchedCssEntrySource) return [generatorOptions?.config ? {
5164
+ ...matchedCssEntrySource,
5165
+ css: prependConfigDirective(matchedCssEntrySource.css, generatorOptions.config)
5166
+ } : matchedCssEntrySource];
5167
+ const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource((shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions.cssEntries?.length ?? 0) <= 1) && canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
5168
+ if (sourceSideCssSource) return [sourceSideCssSource];
4966
5169
  const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
4967
5170
  const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
4968
- const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource((shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions.cssEntries?.length ?? 0) <= 1) && canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
4969
5171
  const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource;
4970
- if (sourceSideCssSource) return [sourceSideCssSource];
4971
5172
  if (preferredCssEntrySource) return [generatorOptions?.config ? {
4972
5173
  ...preferredCssEntrySource,
4973
5174
  css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
@@ -5145,6 +5346,27 @@ function resolveLegacyCompatCssSource(rawSource) {
5145
5346
  setLimitedCacheValue(legacyCompatSourceCache, rawSource, resolved);
5146
5347
  return resolved;
5147
5348
  }
5349
+ function removeMiniProgramContainerCompatCss(css) {
5350
+ try {
5351
+ const root = require_watch_dependencies.postcss_default.parse(css);
5352
+ let removed = false;
5353
+ root.walkRules((rule) => {
5354
+ if (rule.selectors?.length === 1 && rule.selectors[0] === ".container") {
5355
+ rule.remove();
5356
+ removed = true;
5357
+ }
5358
+ });
5359
+ root.walkAtRules((atRule) => {
5360
+ if (atRule.nodes && atRule.nodes.length === 0) {
5361
+ atRule.remove();
5362
+ removed = true;
5363
+ }
5364
+ });
5365
+ return removed ? root.toString() : css;
5366
+ } catch {
5367
+ return css;
5368
+ }
5369
+ }
5148
5370
  function hasContainerConfigToken(rawSource) {
5149
5371
  return rawSource.includes("@config") && /\bcontainer\b/.test(rawSource);
5150
5372
  }
@@ -5173,7 +5395,8 @@ function hasConfiguredContainerCompatSources(sources) {
5173
5395
  return sources.some((source) => hasConfiguredContainerCompatSource(source));
5174
5396
  }
5175
5397
  async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
5176
- const compatSource = removeGeneratedSelectorCompatCss(resolveLegacyCompatCssSource(rawSource), css);
5398
+ const resolvedCompatSource = resolveLegacyCompatCssSource(rawSource);
5399
+ const compatSource = removeGeneratedSelectorCompatCss(generatorTarget === "weapp" ? removeMiniProgramContainerCompatCss(resolvedCompatSource) : resolvedCompatSource, css);
5177
5400
  if (compatSource.trim().length === 0) return css;
5178
5401
  if (generatorTarget !== "weapp") return createCssAppend(css, compatSource);
5179
5402
  const styleOptions = {
@@ -5191,6 +5414,7 @@ async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandl
5191
5414
  return createCssAppend(css, cleanedCompatCss);
5192
5415
  }
5193
5416
  async function appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
5417
+ if (generatorTarget === "weapp") return css;
5194
5418
  const compatSource = resolveLegacyCompatCssSource(rawSource);
5195
5419
  const shouldAppendContainer = runtime.has("container") || hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) || configuredContainerCompat || collectGeneratedSelectors(compatSource).has(".container");
5196
5420
  if (generatorTarget !== "weapp" || !shouldAppendContainer || collectGeneratedSelectors(css).has(".container")) return css;
@@ -5253,74 +5477,97 @@ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
5253
5477
  }
5254
5478
  }
5255
5479
  //#endregion
5256
- //#region src/bundlers/shared/generator-css/user-layer-order.ts
5257
- const USER_LAYER_COMPONENTS_START = "/*! weapp-tailwindcss layer components start */";
5258
- const USER_LAYER_COMPONENTS_END = "/*! weapp-tailwindcss layer components end */";
5259
- const UTILITY_LAYER_INSERTION_RES = [
5260
- /(^|\n)\.(?:fixed|absolute|relative|sticky|static)\s*\{/,
5261
- /(^|\n)\.(?:block|inline-block|inline|flex|inline-flex|grid|hidden)\s*\{/,
5262
- /(^|\n)\.(?:m|mx|my|mt|mr|mb|ml|p|px|py|pt|pr|pb|pl)-/,
5263
- /(^|\n)\.(?:w|h|min-w|min-h|max-w|max-h)-/,
5264
- /(^|\n)\.(?:bg|text|border|rounded|shadow|opacity|transition|transform|translate|scale|rotate|gap|items|justify|content)-/
5265
- ];
5266
- function appendCss(base, extra) {
5480
+ //#region src/bundlers/shared/generator-css/local-imports.ts
5481
+ const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
5482
+ function createCssSourceOrderAppend(base, extra) {
5267
5483
  if (!base) return extra;
5268
5484
  if (!extra) return base;
5269
5485
  if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
5270
5486
  return `${base}\n${extra}`;
5271
5487
  }
5272
- function wrapUserLayerComponentsCss(css) {
5273
- return css.trim().length > 0 ? `${USER_LAYER_COMPONENTS_START}\n${css}\n${USER_LAYER_COMPONENTS_END}` : css;
5488
+ function isLocalImportRequest(request) {
5489
+ return request.length > 0 && !request.startsWith("#") && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
5274
5490
  }
5275
- function extractMarkedUserLayerComponentsCss(css) {
5276
- const layers = [];
5277
- let rest = "";
5278
- let cursor = 0;
5279
- while (cursor < css.length) {
5280
- const startIndex = css.indexOf(USER_LAYER_COMPONENTS_START, cursor);
5281
- if (startIndex === -1) {
5282
- rest += css.slice(cursor);
5283
- break;
5491
+ function isPureLocalCssImportWrapper(css) {
5492
+ let hasImport = false;
5493
+ try {
5494
+ const root = require_watch_dependencies.postcss_default.parse(css);
5495
+ for (const node of root.nodes) {
5496
+ if (node.type === "comment") continue;
5497
+ if (node.type !== "atrule" || node.name !== "import") return false;
5498
+ const request = parseImportRequest(node.params);
5499
+ if (!request || !isLocalImportRequest(request)) return false;
5500
+ hasImport = true;
5284
5501
  }
5285
- rest += css.slice(cursor, startIndex);
5286
- const contentStart = startIndex + 47;
5287
- const endIndex = css.indexOf(USER_LAYER_COMPONENTS_END, contentStart);
5288
- if (endIndex === -1) {
5289
- rest += css.slice(startIndex);
5290
- break;
5502
+ } catch {
5503
+ return false;
5504
+ }
5505
+ return hasImport;
5506
+ }
5507
+ function cleanLocalCssImportWrapperTailwindDirectives(css) {
5508
+ let hasLocalImport = false;
5509
+ let hasTailwindDirective = false;
5510
+ try {
5511
+ const root = require_watch_dependencies.postcss_default.parse(css);
5512
+ for (const node of root.nodes) {
5513
+ if (node.type === "comment") continue;
5514
+ if (node.type === "atrule" && node.name === "import") {
5515
+ const request = parseImportRequest(node.params);
5516
+ if (!request || !isLocalImportRequest(request)) return;
5517
+ hasLocalImport = true;
5518
+ continue;
5519
+ }
5520
+ if (node.type === "atrule" && node.name === "source") {
5521
+ hasTailwindDirective = true;
5522
+ continue;
5523
+ }
5524
+ return;
5291
5525
  }
5292
- const layerCss = css.slice(contentStart, endIndex).trim();
5293
- if (layerCss) layers.push(layerCss);
5294
- cursor = endIndex + 45;
5526
+ } catch {
5527
+ return;
5528
+ }
5529
+ return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(removeTailwindSourceDirectives(css)) : void 0;
5530
+ }
5531
+ function prefixLocalCssImportsWithWebpackIgnore(css) {
5532
+ try {
5533
+ const root = require_watch_dependencies.postcss_default.parse(css);
5534
+ root.walkAtRules("import", (atRule) => {
5535
+ const request = parseImportRequest(atRule.params);
5536
+ if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
5537
+ });
5538
+ return root.toString();
5539
+ } catch {
5540
+ return css;
5295
5541
  }
5296
- return {
5297
- layers,
5298
- rest
5299
- };
5300
5542
  }
5301
- function findUtilityLayerInsertionIndex(css) {
5302
- let index = -1;
5303
- for (const pattern of UTILITY_LAYER_INSERTION_RES) {
5304
- const match = pattern.exec(css);
5305
- if (!match) continue;
5306
- const nextIndex = match.index + (match[1]?.length ?? 0);
5307
- index = index === -1 ? nextIndex : Math.min(index, nextIndex);
5543
+ function splitLocalCssImports(source) {
5544
+ try {
5545
+ const root = require_watch_dependencies.postcss_default.parse(source);
5546
+ const importRoot = require_watch_dependencies.postcss_default.root();
5547
+ let changed = false;
5548
+ for (const node of [...root.nodes]) {
5549
+ if (node.type !== "atrule" || node.name !== "import") continue;
5550
+ const request = parseImportRequest(node.params);
5551
+ if (!request || !isLocalImportRequest(request)) continue;
5552
+ importRoot.append(node.clone());
5553
+ node.remove();
5554
+ changed = true;
5555
+ }
5556
+ const imports = importRoot.nodes.filter((node) => node.type === "atrule" && node.name === "import").map((node) => `@import ${node.params};`).join("\n");
5557
+ return changed ? {
5558
+ imports,
5559
+ source: root.toString()
5560
+ } : void 0;
5561
+ } catch {
5562
+ return;
5308
5563
  }
5309
- return index;
5310
5564
  }
5311
- function reorderMarkedUserLayerComponentsCss(css) {
5312
- if (!css.includes(USER_LAYER_COMPONENTS_START)) return css;
5313
- const { layers, rest } = extractMarkedUserLayerComponentsCss(css);
5314
- if (layers.length === 0) return rest;
5315
- const layerCss = layers.join("\n");
5316
- const insertionIndex = findUtilityLayerInsertionIndex(rest);
5317
- if (insertionIndex === -1) return appendCss(rest, layerCss);
5318
- return appendCss(appendCss(rest.slice(0, insertionIndex), layerCss), rest.slice(insertionIndex));
5565
+ function restoreLocalCssImports(css, imports) {
5566
+ if (!imports?.trim()) return css;
5567
+ return createCssSourceOrderAppend(imports, css);
5319
5568
  }
5320
5569
  //#endregion
5321
- //#region src/bundlers/shared/generator-css.ts
5322
- const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
5323
- const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
5570
+ //#region src/bundlers/shared/generator-css/user-css.ts
5324
5571
  const TAILWIND_V4_GENERATOR_AT_RULES = new Set([
5325
5572
  "config",
5326
5573
  "custom-variant",
@@ -5330,30 +5577,6 @@ const TAILWIND_V4_GENERATOR_AT_RULES = new Set([
5330
5577
  "utility",
5331
5578
  "variant"
5332
5579
  ]);
5333
- function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight, options = {}) {
5334
- if (target !== "weapp") return css;
5335
- return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, {
5336
- cssPreflight: majorVersion === 4 && options.injectPreflight !== false ? cssPreflight : void 0,
5337
- isTailwindcssV4: majorVersion === 4,
5338
- preservePseudoContentInit: majorVersion === 3
5339
- });
5340
- }
5341
- function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
5342
- if (options.cssHandlerOptions.uniAppX === true && options.cssHandlerOptions.uniAppXCssTarget === "uvue") return false;
5343
- if (!options.isolateCurrentCssCandidates) return true;
5344
- return isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
5345
- }
5346
- function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
5347
- if (options.isolateCssSource && options.currentCssCandidates?.length) return new Set([...scopedRuntime, ...options.currentCssCandidates]);
5348
- if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.matchedCssSourceFile || options.isolateCssSource && scopedRuntime.size === 0) return scopedRuntime;
5349
- return new Set([...scopedRuntime, ...runtime]);
5350
- }
5351
- function shouldIsolateScopedCssSource(source, sourceEntries) {
5352
- return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile) || sourceEntries !== void 0 && sourceEntries.length > 0;
5353
- }
5354
- function shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, options) {
5355
- return majorVersion === 4 && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(options.rawSource) && !hasTailwindRootDirectives(options.rawSource) && !options.hasGeneratedCss && !options.hasGeneratedMarkers;
5356
- }
5357
5580
  function removeTailwindApplyAtRules(source) {
5358
5581
  if (!source.includes("@apply")) return source;
5359
5582
  try {
@@ -5391,34 +5614,6 @@ function removeTailwindV4GeneratorAtRules(source) {
5391
5614
  return source;
5392
5615
  }
5393
5616
  }
5394
- function shouldScanTailwindV4Sources(majorVersion, target, generatorRuntime, isolateCssSource) {
5395
- if (majorVersion !== 4 || isolateCssSource) return false;
5396
- return target === "web" || generatorRuntime.size === 0;
5397
- }
5398
- function shouldAppendWebBundleCssFallback(target, options) {
5399
- return target === "web" && !options.hasMatchedCssSourceFile && !options.hasSourceDirectives;
5400
- }
5401
- function isEmptyCssSourceOrderParts(parts) {
5402
- return parts.before.trim().length === 0 && parts.after.trim().length === 0;
5403
- }
5404
- function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
5405
- const preflightStyleOptions = {
5406
- cssPreflight: opts.cssPreflight,
5407
- cssPreflightRange: opts.cssPreflightRange
5408
- };
5409
- return {
5410
- ...resolveStyleOptionsFromContext(opts),
5411
- atRules: opts.atRules,
5412
- uniAppXCssTarget: opts.uniAppXCssTarget,
5413
- uniAppXUnsupported: opts.uniAppXUnsupported,
5414
- ...cssHandlerOptions,
5415
- ...preflightStyleOptions,
5416
- ...generatorStyleOptions
5417
- };
5418
- }
5419
- function isLocalImportRequest(request) {
5420
- return request.length > 0 && !request.startsWith("#") && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
5421
- }
5422
5617
  function isCommentOnlyCss(source) {
5423
5618
  try {
5424
5619
  const root = require_watch_dependencies.postcss_default.parse(source);
@@ -5453,22 +5648,6 @@ function stripUnmatchedTailwindSourceMediaCloseFragments(source) {
5453
5648
  return stripLeadingTailwindSourceMediaCloseFragment(source).replace(/\s*\}\s*$/, "");
5454
5649
  }
5455
5650
  }
5456
- function createCssSourceOrderAppend(base, extra) {
5457
- if (!base) return extra;
5458
- if (!extra) return base;
5459
- if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
5460
- return `${base}\n${extra}`;
5461
- }
5462
- function shouldFinalizeMarkedUserLayerComponentsCss(file) {
5463
- return !/\.(?:vue|svelte|astro|scss|sass|less|styl)(?:[?#].*)?$/i.test(file);
5464
- }
5465
- function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
5466
- const placeholderParts = splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
5467
- if (placeholderParts) return placeholderParts;
5468
- const exactParts = splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss);
5469
- if (exactParts) return exactParts;
5470
- return splitTailwindGeneratedCssByBanner(rawSource);
5471
- }
5472
5651
  function splitUserCssLayerBlocks(source) {
5473
5652
  if (!source.includes("@layer")) return {
5474
5653
  layer: "",
@@ -5620,84 +5799,73 @@ async function transformGeneratorUserCss(source, options) {
5620
5799
  });
5621
5800
  return (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(css);
5622
5801
  }
5623
- function isPureLocalCssImportWrapper(css) {
5624
- let hasImport = false;
5625
- try {
5626
- const root = require_watch_dependencies.postcss_default.parse(css);
5627
- for (const node of root.nodes) {
5628
- if (node.type === "comment") continue;
5629
- if (node.type !== "atrule" || node.name !== "import") return false;
5630
- const request = parseImportRequest(node.params);
5631
- if (!request || !isLocalImportRequest(request)) return false;
5632
- hasImport = true;
5633
- }
5634
- } catch {
5635
- return false;
5636
- }
5637
- return hasImport;
5802
+ //#endregion
5803
+ //#region src/bundlers/shared/generator-css/user-layer-order.ts
5804
+ const USER_LAYER_COMPONENTS_START = "/*! weapp-tailwindcss layer components start */";
5805
+ const USER_LAYER_COMPONENTS_END = "/*! weapp-tailwindcss layer components end */";
5806
+ const UTILITY_LAYER_INSERTION_RES = [
5807
+ /(^|\n)\.(?:fixed|absolute|relative|sticky|static)\s*\{/,
5808
+ /(^|\n)\.(?:block|inline-block|inline|flex|inline-flex|grid|hidden)\s*\{/,
5809
+ /(^|\n)\.(?:m|mx|my|mt|mr|mb|ml|p|px|py|pt|pr|pb|pl)-/,
5810
+ /(^|\n)\.(?:w|h|min-w|min-h|max-w|max-h)-/,
5811
+ /(^|\n)\.(?:bg|text|border|rounded|shadow|opacity|transition|transform|translate|scale|rotate|gap|items|justify|content)-/
5812
+ ];
5813
+ function appendCss(base, extra) {
5814
+ if (!base) return extra;
5815
+ if (!extra) return base;
5816
+ if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
5817
+ return `${base}\n${extra}`;
5638
5818
  }
5639
- function cleanLocalCssImportWrapperTailwindDirectives(css) {
5640
- let hasLocalImport = false;
5641
- let hasTailwindDirective = false;
5642
- try {
5643
- const root = require_watch_dependencies.postcss_default.parse(css);
5644
- for (const node of root.nodes) {
5645
- if (node.type === "comment") continue;
5646
- if (node.type === "atrule" && node.name === "import") {
5647
- const request = parseImportRequest(node.params);
5648
- if (!request || !isLocalImportRequest(request)) return;
5649
- hasLocalImport = true;
5650
- continue;
5651
- }
5652
- if (node.type === "atrule" && node.name === "source") {
5653
- hasTailwindDirective = true;
5654
- continue;
5655
- }
5656
- return;
5657
- }
5658
- } catch {
5659
- return;
5660
- }
5661
- return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(removeTailwindSourceDirectives(css)) : void 0;
5819
+ function wrapUserLayerComponentsCss(css) {
5820
+ return css.trim().length > 0 ? `${USER_LAYER_COMPONENTS_START}\n${css}\n${USER_LAYER_COMPONENTS_END}` : css;
5662
5821
  }
5663
- function prefixLocalCssImportsWithWebpackIgnore(css) {
5664
- try {
5665
- const root = require_watch_dependencies.postcss_default.parse(css);
5666
- root.walkAtRules("import", (atRule) => {
5667
- const request = parseImportRequest(atRule.params);
5668
- if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
5669
- });
5670
- return root.toString();
5671
- } catch {
5672
- return css;
5822
+ function extractMarkedUserLayerComponentsCss(css) {
5823
+ const layers = [];
5824
+ let rest = "";
5825
+ let cursor = 0;
5826
+ while (cursor < css.length) {
5827
+ const startIndex = css.indexOf(USER_LAYER_COMPONENTS_START, cursor);
5828
+ if (startIndex === -1) {
5829
+ rest += css.slice(cursor);
5830
+ break;
5831
+ }
5832
+ rest += css.slice(cursor, startIndex);
5833
+ const contentStart = startIndex + 47;
5834
+ const endIndex = css.indexOf(USER_LAYER_COMPONENTS_END, contentStart);
5835
+ if (endIndex === -1) {
5836
+ rest += css.slice(startIndex);
5837
+ break;
5838
+ }
5839
+ const layerCss = css.slice(contentStart, endIndex).trim();
5840
+ if (layerCss) layers.push(layerCss);
5841
+ cursor = endIndex + 45;
5673
5842
  }
5843
+ return {
5844
+ layers,
5845
+ rest
5846
+ };
5674
5847
  }
5675
- function splitLocalCssImports(source) {
5676
- try {
5677
- const root = require_watch_dependencies.postcss_default.parse(source);
5678
- const importRoot = require_watch_dependencies.postcss_default.root();
5679
- let changed = false;
5680
- for (const node of [...root.nodes]) {
5681
- if (node.type !== "atrule" || node.name !== "import") continue;
5682
- const request = parseImportRequest(node.params);
5683
- if (!request || !isLocalImportRequest(request)) continue;
5684
- importRoot.append(node.clone());
5685
- node.remove();
5686
- changed = true;
5687
- }
5688
- const imports = importRoot.nodes.filter((node) => node.type === "atrule" && node.name === "import").map((node) => `@import ${node.params};`).join("\n");
5689
- return changed ? {
5690
- imports,
5691
- source: root.toString()
5692
- } : void 0;
5693
- } catch {
5694
- return;
5848
+ function findUtilityLayerInsertionIndex(css) {
5849
+ let index = -1;
5850
+ for (const pattern of UTILITY_LAYER_INSERTION_RES) {
5851
+ const match = pattern.exec(css);
5852
+ if (!match) continue;
5853
+ const nextIndex = match.index + (match[1]?.length ?? 0);
5854
+ index = index === -1 ? nextIndex : Math.min(index, nextIndex);
5695
5855
  }
5856
+ return index;
5696
5857
  }
5697
- function restoreLocalCssImports(css, imports) {
5698
- if (!imports?.trim()) return css;
5699
- return createCssSourceOrderAppend(imports, css);
5858
+ function reorderMarkedUserLayerComponentsCss(css) {
5859
+ if (!css.includes(USER_LAYER_COMPONENTS_START)) return css;
5860
+ const { layers, rest } = extractMarkedUserLayerComponentsCss(css);
5861
+ if (layers.length === 0) return rest;
5862
+ const layerCss = layers.join("\n");
5863
+ const insertionIndex = findUtilityLayerInsertionIndex(rest);
5864
+ if (insertionIndex === -1) return appendCss(rest, layerCss);
5865
+ return appendCss(appendCss(rest.slice(0, insertionIndex), layerCss), rest.slice(insertionIndex));
5700
5866
  }
5867
+ //#endregion
5868
+ //#region src/bundlers/shared/generator-css.ts
5701
5869
  async function generateCssByGenerator(options) {
5702
5870
  const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, debug } = options;
5703
5871
  const generatorOptions = {
@@ -5720,8 +5888,13 @@ async function generateCssByGenerator(options) {
5720
5888
  const hasGeneratedCss = hasTailwindGeneratedCss(generatorRawSource);
5721
5889
  const hasSourceDirectives = hasTailwindSourceDirectives(generatorRawSource, { importFallback: generatorOptions.importFallback });
5722
5890
  const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(generatorRawSource);
5723
- const shouldGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
5724
- if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
5891
+ const shouldGenerateCurrentCss = shouldUseGeneratorForCurrentCss(majorVersion, cssHandlerOptions, {
5892
+ hasGeneratedCss,
5893
+ hasGeneratedMarkers,
5894
+ hasSourceDirectives,
5895
+ rawSource: generatorRawSource
5896
+ });
5897
+ if (!isSupportedGeneratorMajorVersion(majorVersion) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
5725
5898
  try {
5726
5899
  await runtimeState.readyPromise;
5727
5900
  const currentCssCandidates = majorVersion === 4 ? await (0, tailwindcss_patch.extractSourceCandidates)(generatorRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } }) : [];
@@ -5730,7 +5903,7 @@ async function generateCssByGenerator(options) {
5730
5903
  hasGeneratedMarkers,
5731
5904
  rawSource: generatorRawSource
5732
5905
  });
5733
- const runtimeWithCurrentCss = isolateCurrentCssCandidates ? new Set(currentCssCandidates) : currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
5906
+ const runtimeWithCurrentCss = createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates);
5734
5907
  const sources = await resolveGeneratorSources(majorVersion, runtimeState, generatorRawSource, file, cssHandlerOptions, generatorOptions, {
5735
5908
  cssEntries: opts.cssEntries,
5736
5909
  getSourceCandidatesForEntries,
@@ -5738,12 +5911,13 @@ async function generateCssByGenerator(options) {
5738
5911
  });
5739
5912
  const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
5740
5913
  const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
5741
- const generatedResults = (await Promise.all(sources.map(async (source) => {
5914
+ const generated = mergeGeneratorResults((await Promise.all(sources.map(async (source) => {
5742
5915
  const generator = createWeappTailwindcssGenerator(source);
5743
5916
  const sourceEntries = getSourceCandidatesForEntries && (majorVersion === 3 || majorVersion === 4) ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
5744
5917
  const scopedRuntime = sourceEntries ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
5745
5918
  const isolateCssSource = shouldIsolateScopedCssSource(source, sourceEntries);
5746
- const matchedCssSourceFile = Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile);
5919
+ const sourceMetadata = source.__weappTailwindcssMeta;
5920
+ const matchedCssSourceFile = Boolean(sourceMetadata?.matchedCssSourceFile);
5747
5921
  if (options.deferEmptyScopedCssSource && isolateCssSource && scopedRuntime?.size === 0 && currentCssCandidates.length === 0 && !cssHandlerOptions.isMainChunk) {
5748
5922
  debug("defer empty scoped css source generation: %s", file);
5749
5923
  return;
@@ -5765,21 +5939,8 @@ async function generateCssByGenerator(options) {
5765
5939
  tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
5766
5940
  target: generatorOptions.target
5767
5941
  });
5768
- }))).filter((item) => Boolean(item));
5769
- const firstGenerated = generatedResults[0];
5770
- if (!firstGenerated) return;
5771
- const incrementalCssResults = generatedResults.map((item) => item.incrementalCss).filter((css) => typeof css === "string");
5772
- const incrementalRawCssResults = generatedResults.map((item) => item.incrementalRawCss).filter((css) => typeof css === "string");
5773
- const generated = generatedResults.length === 1 ? firstGenerated : {
5774
- ...firstGenerated,
5775
- css: generatedResults.map((item) => item.css).join("\n"),
5776
- rawCss: generatedResults.map((item) => item.rawCss).join("\n"),
5777
- incrementalCss: incrementalCssResults.length === generatedResults.length ? incrementalCssResults.filter(Boolean).join("\n") : void 0,
5778
- incrementalRawCss: incrementalRawCssResults.length === generatedResults.length ? incrementalRawCssResults.filter(Boolean).join("\n") : void 0,
5779
- classSet: new Set(generatedResults.flatMap((item) => [...item.classSet])),
5780
- dependencies: [...new Set(generatedResults.flatMap((item) => item.dependencies))],
5781
- sources: generatedResults.flatMap((item) => item.sources)
5782
- };
5942
+ }))).filter((item) => Boolean(item)));
5943
+ if (!generated) return;
5783
5944
  debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
5784
5945
  if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(generatorRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
5785
5946
  const incrementalCss = stripTailwindBanner(generated.incrementalCss);
@@ -5816,13 +5977,13 @@ async function generateCssByGenerator(options) {
5816
5977
  const beforeUserCss = await transformGeneratorUserCss(orderedExtraCss.before, userCssOptions);
5817
5978
  const afterLayerUserCss = await transformGeneratorUserCss(afterLayerParts.layer, userCssOptions);
5818
5979
  const afterUserCss = await transformGeneratorUserCss(afterLayerParts.rest, userCssOptions);
5819
- css = createCssSourceOrderAppend(createCssSourceOrderAppend(createCssSourceOrderAppend(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(afterLayerUserCss) : afterLayerUserCss), css), afterUserCss);
5980
+ css = createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(afterLayerUserCss) : afterLayerUserCss), css), afterUserCss);
5820
5981
  if (isEmptyCssSourceOrderParts(orderedExtraCss) && shouldAppendWebBundleCssFallback(generated.target, {
5821
5982
  hasSourceDirectives,
5822
5983
  hasMatchedCssSourceFile
5823
5984
  })) {
5824
5985
  const userCss = await transformGeneratorUserCss(userCssRawSource, userCssOptions);
5825
- css = createCssSourceOrderAppend(css, userCss);
5986
+ css = createCssSourceOrderAppend$1(css, userCss);
5826
5987
  }
5827
5988
  if (generated.target === "weapp" && shouldAppendMatchedCssSourceCompat) {
5828
5989
  if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
@@ -5860,7 +6021,7 @@ async function generateCssByGenerator(options) {
5860
6021
  rest: css
5861
6022
  } : extractGeneratedCssForUserLayerSelectors(css, layerParts.layer);
5862
6023
  if (layerCss.layer.trim().length > 0) {
5863
- css = createCssSourceOrderAppend(wrapUserLayerComponentsCss(layerCss.layer), layerCss.rest);
6024
+ css = createCssSourceOrderAppend$1(wrapUserLayerComponentsCss(layerCss.layer), layerCss.rest);
5864
6025
  if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
5865
6026
  }
5866
6027
  }
@@ -5874,7 +6035,7 @@ async function generateCssByGenerator(options) {
5874
6035
  styleHandler,
5875
6036
  importFallback: generatorOptions.importFallback
5876
6037
  });
5877
- css = createCssSourceOrderAppend(css, userCss);
6038
+ css = createCssSourceOrderAppend$1(css, userCss);
5878
6039
  }
5879
6040
  if (hasMatchedCssSourceFile && generated.target === "weapp") {
5880
6041
  if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
@@ -5890,7 +6051,7 @@ async function generateCssByGenerator(options) {
5890
6051
  styleHandler,
5891
6052
  importFallback: generatorOptions.importFallback
5892
6053
  });
5893
- css = createCssSourceOrderAppend(css, userCss);
6054
+ css = createCssSourceOrderAppend$1(css, userCss);
5894
6055
  }
5895
6056
  return {
5896
6057
  css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {