weapp-tailwindcss 5.0.4 → 5.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/{auto-BZ4n4Icc.js → auto-Cvy0zWpS.js} +1 -1
  2. package/dist/{bundle-state-D3RZHkXz.js → bundle-state-CFgzVHFP.js} +8 -2
  3. package/dist/{bundle-state-C-p9eFz1.mjs → bundle-state-CdNXQl-o.mjs} +2 -2
  4. package/dist/bundlers/shared/generator-css/directives.d.ts +1 -0
  5. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -0
  6. package/dist/bundlers/vite/generate-bundle.d.ts +3 -1
  7. package/dist/bundlers/vite/rewrite-css-imports.d.ts +8 -0
  8. package/dist/bundlers/vite/serve-css-generation.d.ts +5 -0
  9. package/dist/bundlers/vite/uni-app-x-css-options.d.ts +2 -0
  10. package/dist/{chunk-D6vf50IK.js → chunk-emK7D4bc.js} +7 -0
  11. package/dist/core.js +1 -1
  12. package/dist/core.mjs +1 -1
  13. package/dist/css-macro.js +3 -3
  14. package/dist/{defaults-C5w9OOrj.js → defaults-BPUuNYcD.js} +1 -1
  15. package/dist/defaults.js +1 -1
  16. package/dist/{generator-DRHWC1t-.mjs → generator-Bgn4m8An.mjs} +1 -1
  17. package/dist/{generator-DaPOkJ7W.js → generator-C56PJYxA.js} +2 -2
  18. package/dist/generator.js +2 -2
  19. package/dist/generator.mjs +2 -2
  20. package/dist/gulp.js +6 -6
  21. package/dist/gulp.mjs +5 -5
  22. package/dist/{incremental-runtime-class-set-Dt-FUQB5.mjs → incremental-runtime-class-set-BEYHQkZc.mjs} +238 -44
  23. package/dist/{incremental-runtime-class-set-BYV0yQdp.js → incremental-runtime-class-set-Bmzdjlk0.js} +239 -45
  24. package/dist/index.js +4 -4
  25. package/dist/index.mjs +4 -4
  26. package/dist/{postcss-Du8hY-MN.js → postcss-B7QNe78h.js} +57 -10
  27. package/dist/{postcss-CJrmfXvi.mjs → postcss-BgINK7Nm.mjs} +55 -8
  28. package/dist/postcss-html-transform.js +1 -1
  29. package/dist/postcss.js +1 -1
  30. package/dist/postcss.mjs +1 -1
  31. package/dist/{precheck-lfenbOTF.mjs → precheck-Copn2SqE.mjs} +14 -3
  32. package/dist/{precheck-DgpVCvYk.js → precheck-CyPbGn38.js} +17 -6
  33. package/dist/presets.js +9 -5
  34. package/dist/presets.mjs +7 -3
  35. package/dist/reset.js +1 -1
  36. package/dist/{source-candidates-D7b-Jzsx.mjs → source-candidates-BODCmzz5.mjs} +1 -1
  37. package/dist/{source-candidates-B4NvId_j.js → source-candidates-Caf2GDvx.js} +2 -2
  38. package/dist/{tailwindcss-D5RogwtV.mjs → tailwindcss-C0Zgo3Es.mjs} +1 -1
  39. package/dist/{tailwindcss-26ZFr5kv.js → tailwindcss-Tw6CSVHL.js} +3 -3
  40. package/dist/transform-95ivJthq.js +14868 -0
  41. package/dist/transform-DgCFGtQR.mjs +14871 -0
  42. package/dist/uni-app-x/vite.d.ts +3 -0
  43. package/dist/{utils-nta4tfFs.js → utils-Dolmt8EO.js} +1 -1
  44. package/dist/{v3-engine-CBahpuIg.js → v3-engine-6FVAcrZl.js} +31 -6
  45. package/dist/{v3-engine-BCUGX3gX.mjs → v3-engine-Ji6AXPh2.mjs} +24 -5
  46. package/dist/{vite-tjYalmVX.js → vite-Bw6LOXvf.js} +733 -79
  47. package/dist/{vite-DS4H5d0f.mjs → vite-ChZ2cbn4.mjs} +745 -91
  48. package/dist/vite.js +1 -1
  49. package/dist/vite.mjs +1 -1
  50. package/dist/weapp-tw-css-import-rewrite-loader.js +247 -45
  51. package/dist/{webpack-CA-40WU9.mjs → webpack-CMJ7iqN7.mjs} +6 -6
  52. package/dist/{webpack-0BwLOE_f.js → webpack-nn3P8_S_.js} +8 -8
  53. package/dist/webpack.js +1 -1
  54. package/dist/webpack.mjs +1 -1
  55. package/package.json +3 -4
  56. package/dist/transform-Crn84vTL.js +0 -257
  57. package/dist/transform-FAxHXVZp.mjs +0 -255
@@ -1,6 +1,7 @@
1
- import { A as parseImportRequest, B as stripGeneratorPlaceholderMarkers, C as hasTailwindApplyDirective, D as normalizeTailwindSourceDirectives, F as hasTailwindGeneratedCss, H as stripTailwindBanners, I as hasTailwindGeneratedCssMarkers, J as filterUnsupportedMiniProgramTailwindV4Candidates, L as splitGeneratorPlaceholderCssBySourceOrder, M as resolveCssEntrySource, N as VITE_MARKER_RE, P as createCssAppend, R as splitTailwindGeneratedCssByBanner, S as resolveTailwindV4SourceOptionsFromPatcher, T as hasTailwindSourceDirectives, U as normalizeConfigDirective, V as stripTailwindBanner, W as prependConfigDirective, Y as loadTailwindV4DesignSystem, ct as createDebug, h as resolveTailwindV4EntriesFromCss, ht as omitUndefined, j as removeTailwindSourceDirectives, k as normalizeTailwindV3CssEntrySource, l as getRuntimeClassSetSignature, n as resolveTailwindV3SourceFromPatcher, nt as normalizeLegacyContentEntries, ot as resolveTailwindV4CssSourceBase, r as resolveTailwindV3SourceOptionsFromPatcher, t as resolveTailwindV3Source, w as hasTailwindRootDirectives, x as resolveTailwindV4SourceFromPatcher, y as resolveTailwindV4Source$1, z as splitTailwindV4GeneratedCssBySourceOrder } from "./v3-engine-BCUGX3gX.mjs";
2
- import { i as normalizeWeappTailwindcssGeneratorOptions, t as createWeappTailwindcssGenerator } from "./generator-DRHWC1t-.mjs";
3
- import { p as replaceWxml, r as resolveStyleOptionsFromContext } from "./precheck-lfenbOTF.mjs";
1
+ import { A as normalizeTailwindV3CssEntrySource, B as splitTailwindV4GeneratedCssBySourceOrder, E as hasTailwindSourceDirectives, F as createCssAppend, G as prependConfigDirective, H as stripTailwindBanner, I as hasTailwindGeneratedCss, L as hasTailwindGeneratedCssMarkers, M as removeTailwindSourceDirectives, N as resolveCssEntrySource, O as normalizeTailwindSourceDirectives, P as VITE_MARKER_RE, R as splitGeneratorPlaceholderCssBySourceOrder, S as resolveTailwindV4SourceOptionsFromPatcher, T as hasTailwindRootDirectives, U as stripTailwindBanners, V as stripGeneratorPlaceholderMarkers, W as normalizeConfigDirective, X as loadTailwindV4DesignSystem, Y as filterUnsupportedMiniProgramTailwindV4Candidates, gt as omitUndefined, h as resolveTailwindV4EntriesFromCss, j as parseImportRequest, l as getRuntimeClassSetSignature, lt as createDebug, n as resolveTailwindV3SourceFromPatcher, r as resolveTailwindV3SourceOptionsFromPatcher, rt as normalizeLegacyContentEntries, st as resolveTailwindV4CssSourceBase, t as resolveTailwindV3Source, w as hasTailwindApplyDirective, x as resolveTailwindV4SourceFromPatcher, y as resolveTailwindV4Source$1, z as splitTailwindGeneratedCssByBanner } from "./v3-engine-Ji6AXPh2.mjs";
2
+ import { i as normalizeWeappTailwindcssGeneratorOptions, t as createWeappTailwindcssGenerator } from "./generator-Bgn4m8An.mjs";
3
+ import { p as replaceWxml, r as resolveStyleOptionsFromContext } from "./precheck-Copn2SqE.mjs";
4
+ import { r as isUniAppXEnabled } from "./tailwindcss-C0Zgo3Es.mjs";
4
5
  import { existsSync, readFileSync } from "node:fs";
5
6
  import postcss from "postcss";
6
7
  import { extractRawCandidatesWithPositions, extractSourceCandidates, extractValidCandidates, resolveValidTailwindV4Candidates } from "tailwindcss-patch";
@@ -435,7 +436,10 @@ async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
435
436
  const css = readFileSync(cssEntry, "utf8");
436
437
  const base = path.dirname(path.resolve(cssEntry));
437
438
  const entrySource = resolveCssEntrySource(css, base, { removeConfig: false });
438
- const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, cssEntry, sourceOptions);
439
+ const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, cssEntry, {
440
+ ...sourceOptions,
441
+ sourceFile: sourceOptions.sourceFile ?? cssEntry
442
+ });
439
443
  return withGeneratorSourceMetadata(await resolveTailwindV4Source$1({
440
444
  ...omitUndefined(singleEntrySourceOptions),
441
445
  base,
@@ -733,7 +737,7 @@ function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
733
737
  }
734
738
  function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
735
739
  if (!hasTailwindApplyDirective(css) || hasTailwindRootDirectives(css)) return css;
736
- return `@reference "${sourceOptions.packageName ?? "tailwindcss"}";\n${css}`;
740
+ return `@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);\n${css}`;
737
741
  }
738
742
  async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
739
743
  const base = resolveCssSourceBase(file, cssHandlerOptions);
@@ -741,6 +745,10 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
741
745
  importFallback: generatorOptions?.importFallback ?? false,
742
746
  removeConfig: majorVersion === 3
743
747
  });
748
+ const applyEntrySource = hasTailwindApplyDirective(rawSource) ? {
749
+ base,
750
+ css: rawSource
751
+ } : void 0;
744
752
  if (majorVersion === 3) {
745
753
  const sourceOptions = resolveTailwindV3SourceOptionsFromPatcher(runtimeState.twPatcher);
746
754
  const mergedSourceOptions = omitUndefined({
@@ -751,10 +759,6 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
751
759
  cssEntries: selectionOptions?.cssEntries,
752
760
  cssSources: createCssEntrySources(selectionOptions?.cssEntries)
753
761
  });
754
- const applyEntrySource = hasTailwindApplyDirective(rawSource) ? {
755
- base,
756
- css: rawSource
757
- } : void 0;
758
762
  const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions, mergedSourceOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
759
763
  const shouldPreferSourceSideEntry = shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource);
760
764
  const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ? shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource : shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) || shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource;
@@ -781,6 +785,13 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
781
785
  cssSources: mergeCssSources(sourceOptions.cssSources, sourceOptions.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
782
786
  }) : void 0;
783
787
  const normalizedSourceOptions = resolvedSourceOptions ? normalizeTailwindV4CssSourceConfigs(resolvedSourceOptions) : void 0;
788
+ if (applyEntrySource && !cssHandlerOptions.isMainChunk && !hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false })) {
789
+ const css = createTailwindV4ApplyReferenceSource(normalizeConfigDirective(prependConfigDirective(applyEntrySource.css, generatorOptions?.config), void 0), normalizedSourceOptions ?? {});
790
+ return resolveTailwindV4Source$1(createSingleTailwindV4SourceOptions(normalizedSourceOptions ?? {}, {
791
+ base: applyEntrySource.base,
792
+ css
793
+ }));
794
+ }
784
795
  const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions?.cssEntries?.length ?? 0) <= 1;
785
796
  const sourceSideEntrySource = normalizedSourceOptions && shouldPreferSourceSideEntry && canResolveSourceSideCssEntry(file, cssHandlerOptions, normalizedSourceOptions) ? resolveSourceSideCssEntrySource(file, normalizedSourceOptions, { removeConfig: false }) : void 0;
786
797
  const matchedCssEntrySource = normalizedSourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, normalizedSourceOptions) : void 0;
@@ -797,7 +808,7 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
797
808
  ...preferredCssEntrySource,
798
809
  css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
799
810
  } : preferredCssEntrySource;
800
- const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource;
811
+ const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource;
801
812
  if (!resolvedEntrySource) {
802
813
  const source = await resolveTailwindV4SourceFromPatcher(runtimeState.twPatcher);
803
814
  return generatorOptions?.config ? {
@@ -819,7 +830,7 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
819
830
  importFallback: generatorOptions?.importFallback ?? false,
820
831
  removeConfig: majorVersion === 3
821
832
  });
822
- if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk) {
833
+ if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk || !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(rawSource) && !hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false })) {
823
834
  const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
824
835
  return resolved ? [resolved] : [];
825
836
  }
@@ -1251,6 +1262,15 @@ function mergeMarkedUserLayerComponentsCss(baseCss, markedCss) {
1251
1262
  //#region src/bundlers/shared/generator-css.ts
1252
1263
  const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
1253
1264
  const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
1265
+ const TAILWIND_V4_GENERATOR_AT_RULES = new Set([
1266
+ "config",
1267
+ "custom-variant",
1268
+ "plugin",
1269
+ "source",
1270
+ "theme",
1271
+ "utility",
1272
+ "variant"
1273
+ ]);
1254
1274
  function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight, options = {}) {
1255
1275
  if (target !== "weapp") return css;
1256
1276
  return finalizeMiniProgramCss(css, {
@@ -1259,13 +1279,58 @@ function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight
1259
1279
  preservePseudoContentInit: majorVersion === 3
1260
1280
  });
1261
1281
  }
1282
+ function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
1283
+ if (options.cssHandlerOptions.uniAppX === true && options.cssHandlerOptions.uniAppXCssTarget === "uvue") return false;
1284
+ if (!options.isolateCurrentCssCandidates) return true;
1285
+ return isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
1286
+ }
1262
1287
  function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
1263
1288
  if (options.isolateCssSource && options.currentCssCandidates?.length) return new Set([...scopedRuntime, ...options.currentCssCandidates]);
1264
1289
  if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.matchedCssSourceFile || options.isolateCssSource && scopedRuntime.size === 0) return scopedRuntime;
1265
1290
  return new Set([...scopedRuntime, ...runtime]);
1266
1291
  }
1267
1292
  function shouldIsolateScopedCssSource(source, sourceEntries) {
1268
- return sourceEntries !== void 0 && Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile || sourceEntries.length > 0);
1293
+ return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile) || sourceEntries !== void 0 && sourceEntries.length > 0;
1294
+ }
1295
+ function shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, options) {
1296
+ return majorVersion === 4 && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(options.rawSource) && !hasTailwindRootDirectives(options.rawSource) && !options.hasGeneratedCss && !options.hasGeneratedMarkers;
1297
+ }
1298
+ function removeTailwindApplyAtRules(source) {
1299
+ if (!source.includes("@apply")) return source;
1300
+ try {
1301
+ const root = postcss.parse(source);
1302
+ let changed = false;
1303
+ root.walkAtRules("apply", (rule) => {
1304
+ rule.remove();
1305
+ changed = true;
1306
+ });
1307
+ root.walk((node) => {
1308
+ if ("nodes" in node && node.nodes?.length === 0) node.remove();
1309
+ });
1310
+ return changed ? root.toString() : source;
1311
+ } catch {
1312
+ return source;
1313
+ }
1314
+ }
1315
+ function removeTailwindV4GeneratorAtRules(source) {
1316
+ try {
1317
+ const root = postcss.parse(source);
1318
+ let changed = false;
1319
+ root.walkAtRules((rule) => {
1320
+ if (!TAILWIND_V4_GENERATOR_AT_RULES.has(rule.name)) return;
1321
+ rule.remove();
1322
+ changed = true;
1323
+ });
1324
+ root.walk((node) => {
1325
+ if ("nodes" in node && node.nodes?.length === 0) {
1326
+ node.remove();
1327
+ changed = true;
1328
+ }
1329
+ });
1330
+ return changed ? root.toString() : source;
1331
+ } catch {
1332
+ return source;
1333
+ }
1269
1334
  }
1270
1335
  function shouldScanTailwindV4Sources(majorVersion, target, generatorRuntime, isolateCssSource) {
1271
1336
  if (majorVersion !== 4 || isolateCssSource) return false;
@@ -1293,7 +1358,7 @@ function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOpt
1293
1358
  };
1294
1359
  }
1295
1360
  function isLocalImportRequest(request) {
1296
- return request.length > 0 && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
1361
+ return request.length > 0 && !request.startsWith("#") && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
1297
1362
  }
1298
1363
  function isCommentOnlyCss(source) {
1299
1364
  try {
@@ -1304,7 +1369,19 @@ function isCommentOnlyCss(source) {
1304
1369
  }
1305
1370
  }
1306
1371
  function stripTailwindSourceMediaFragments(source) {
1307
- return source.replace(/^\s*@media\s+source\([^)]*\)\s*\{\s*$/gm, "").replace(/^\s*\}\s*(?=@(?:source|theme|config|plugin|utility|variant|custom-variant)\b)/gm, "").replace(/^\s*\}\s*\/\*\s*source\([^)]*\)\s*\*\/\s*$/gm, "");
1372
+ let removedSourceMediaStart = false;
1373
+ return source.split(/\r?\n/).filter((line) => {
1374
+ if (/^\s*@media\s+source\([^)]*\)\s*\{\s*$/.test(line)) {
1375
+ removedSourceMediaStart = true;
1376
+ return false;
1377
+ }
1378
+ if (/^\s*\}\s*\/\*\s*source\([^)]*\)\s*\*\/\s*$/.test(line)) return false;
1379
+ if (removedSourceMediaStart && /^\s*\}\s*$/.test(line)) {
1380
+ removedSourceMediaStart = false;
1381
+ return false;
1382
+ }
1383
+ return true;
1384
+ }).join("\n").replace(/\}[^\S\r\n]*(?=@(?:config|source)\b)/g, "");
1308
1385
  }
1309
1386
  function stripLeadingTailwindSourceMediaCloseFragment(source) {
1310
1387
  return source.replace(/^\s*\}\s*(?:\n|$)/, "");
@@ -1411,11 +1488,70 @@ function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
1411
1488
  };
1412
1489
  }
1413
1490
  }
1491
+ function normalizeGeneratedSelector(selector) {
1492
+ return selector.replace(/:not\(#\\#\)/g, "").trim();
1493
+ }
1494
+ function collectApplyOnlySourceSelectors(source) {
1495
+ const selectors = /* @__PURE__ */ new Set();
1496
+ try {
1497
+ postcss.parse(source).walkRules((rule) => {
1498
+ if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
1499
+ for (const selector of rule.selectors ?? [rule.selector]) {
1500
+ const normalized = normalizeGeneratedSelector(selector);
1501
+ if (normalized) selectors.add(normalized);
1502
+ }
1503
+ });
1504
+ } catch {}
1505
+ return selectors;
1506
+ }
1507
+ function hasOnlyApplyBackedSourceRules(source) {
1508
+ let hasApplyRule = false;
1509
+ let hasNonApplyRule = false;
1510
+ try {
1511
+ postcss.parse(source).walkRules((rule) => {
1512
+ if (rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) hasApplyRule = true;
1513
+ else hasNonApplyRule = true;
1514
+ });
1515
+ } catch {
1516
+ return false;
1517
+ }
1518
+ return hasApplyRule && !hasNonApplyRule;
1519
+ }
1520
+ function filterApplyOnlyGeneratedCss(css, source) {
1521
+ const selectors = collectApplyOnlySourceSelectors(source);
1522
+ if (selectors.size === 0) return css;
1523
+ const selectorList = [...selectors];
1524
+ try {
1525
+ const root = postcss.parse(css);
1526
+ root.walkRules((rule) => {
1527
+ const isApplySelector = (rule.selectors ?? [rule.selector]).some((selector) => {
1528
+ const normalized = normalizeGeneratedSelector(selector);
1529
+ return selectorList.some((sourceSelector) => {
1530
+ if (normalized === sourceSelector) return true;
1531
+ if (!normalized.startsWith(sourceSelector)) return false;
1532
+ const next = normalized[sourceSelector.length];
1533
+ return next === ":" || next === "[" || next === ".";
1534
+ });
1535
+ });
1536
+ const isVariableRule = rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"));
1537
+ if (!isApplySelector && !isVariableRule) rule.remove();
1538
+ });
1539
+ root.walkAtRules((rule) => {
1540
+ if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
1541
+ });
1542
+ return root.toString();
1543
+ } catch {
1544
+ return css;
1545
+ }
1546
+ }
1547
+ function shouldFilterApplyOnlyGeneratedCss(majorVersion, target, source, options) {
1548
+ return majorVersion === 4 && target === "weapp" && hasTailwindApplyDirective(source) && !hasTailwindRootDirectives(source) && !options.hasGeneratedCss && !options.hasGeneratedMarkers && collectApplyOnlySourceSelectors(source).size > 0 && hasOnlyApplyBackedSourceRules(source);
1549
+ }
1414
1550
  async function transformGeneratorUserCss(source, options) {
1415
1551
  if (source.trim().length === 0) return "";
1416
- const cleanedSource = removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source)), { importFallback: options.importFallback });
1552
+ const cleanedSource = removeTailwindSourceDirectives(removeTailwindV4GeneratorAtRules(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source))), { importFallback: options.importFallback });
1417
1553
  if (cleanedSource.trim().length === 0) return "";
1418
- const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? removeUnsupportedMiniProgramAtRules(cleanedSource) : cleanedSource)), { importFallback: options.importFallback }));
1554
+ const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? removeUnsupportedMiniProgramAtRules(cleanedSource) : cleanedSource)), { importFallback: options.importFallback })));
1419
1555
  if (userSource.trim().length === 0) return "";
1420
1556
  if (isCommentOnlyCss(userSource)) return userSource;
1421
1557
  if (options.generatorTarget !== "weapp") return userSource;
@@ -1477,6 +1613,32 @@ function prefixLocalCssImportsWithWebpackIgnore(css) {
1477
1613
  return css;
1478
1614
  }
1479
1615
  }
1616
+ function splitLocalCssImports(source) {
1617
+ try {
1618
+ const root = postcss.parse(source);
1619
+ const importRoot = postcss.root();
1620
+ let changed = false;
1621
+ for (const node of [...root.nodes]) {
1622
+ if (node.type !== "atrule" || node.name !== "import") continue;
1623
+ const request = parseImportRequest(node.params);
1624
+ if (!request || !isLocalImportRequest(request)) continue;
1625
+ importRoot.append(node.clone());
1626
+ node.remove();
1627
+ changed = true;
1628
+ }
1629
+ const imports = importRoot.nodes.filter((node) => node.type === "atrule" && node.name === "import").map((node) => `@import ${node.params};`).join("\n");
1630
+ return changed ? {
1631
+ imports,
1632
+ source: root.toString()
1633
+ } : void 0;
1634
+ } catch {
1635
+ return;
1636
+ }
1637
+ }
1638
+ function restoreLocalCssImports(css, imports) {
1639
+ if (!imports?.trim()) return css;
1640
+ return createCssSourceOrderAppend(imports, css);
1641
+ }
1480
1642
  async function generateCssByGenerator(options) {
1481
1643
  const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, debug } = options;
1482
1644
  const generatorOptions = {
@@ -1485,6 +1647,9 @@ async function generateCssByGenerator(options) {
1485
1647
  };
1486
1648
  const majorVersion = runtimeState.twPatcher.majorVersion;
1487
1649
  const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
1650
+ const localImportParts = splitLocalCssImports(effectiveRawSource);
1651
+ const generatorRawSource = localImportParts?.source ?? effectiveRawSource;
1652
+ const userCssRawSource = majorVersion === 4 ? removeTailwindV4GeneratorAtRules(generatorRawSource) : generatorRawSource;
1488
1653
  const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(effectiveRawSource);
1489
1654
  if (cleanedLocalImportWrapper !== void 0) return {
1490
1655
  css: generatorOptions.target === "weapp" ? removeUnsupportedMiniProgramAtRules(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
@@ -1493,16 +1658,21 @@ async function generateCssByGenerator(options) {
1493
1658
  dependencies: []
1494
1659
  };
1495
1660
  if (isPureLocalCssImportWrapper(effectiveRawSource)) return;
1496
- const hasGeneratedCss = hasTailwindGeneratedCss(effectiveRawSource);
1497
- const hasSourceDirectives = hasTailwindSourceDirectives(effectiveRawSource, { importFallback: generatorOptions.importFallback });
1498
- const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(effectiveRawSource);
1661
+ const hasGeneratedCss = hasTailwindGeneratedCss(generatorRawSource);
1662
+ const hasSourceDirectives = hasTailwindSourceDirectives(generatorRawSource, { importFallback: generatorOptions.importFallback });
1663
+ const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(generatorRawSource);
1499
1664
  const shouldGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
1500
1665
  if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
1501
1666
  try {
1502
1667
  await runtimeState.readyPromise;
1503
- const currentCssCandidates = majorVersion === 4 ? await extractSourceCandidates(effectiveRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } }) : [];
1504
- const runtimeWithCurrentCss = currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
1505
- const sources = await resolveGeneratorSources(majorVersion, runtimeState, effectiveRawSource, file, cssHandlerOptions, generatorOptions, {
1668
+ const currentCssCandidates = majorVersion === 4 ? await extractSourceCandidates(generatorRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } }) : [];
1669
+ const isolateCurrentCssCandidates = shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, {
1670
+ hasGeneratedCss,
1671
+ hasGeneratedMarkers,
1672
+ rawSource: generatorRawSource
1673
+ });
1674
+ const runtimeWithCurrentCss = isolateCurrentCssCandidates ? new Set(currentCssCandidates) : currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
1675
+ const sources = await resolveGeneratorSources(majorVersion, runtimeState, generatorRawSource, file, cssHandlerOptions, generatorOptions, {
1506
1676
  cssEntries: opts.cssEntries,
1507
1677
  getSourceCandidatesForEntries,
1508
1678
  runtime: runtimeWithCurrentCss
@@ -1519,17 +1689,18 @@ async function generateCssByGenerator(options) {
1519
1689
  debug("defer empty scoped css source generation: %s", file);
1520
1690
  return;
1521
1691
  }
1522
- const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
1692
+ const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? isolateCurrentCssCandidates ? runtimeWithCurrentCss : mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
1523
1693
  currentCssCandidates,
1524
1694
  cssHandlerOptions,
1525
1695
  isolateCssSource,
1526
1696
  matchedCssSourceFile
1527
1697
  }) : runtimeWithCurrentCss;
1528
1698
  const generatorRuntime = majorVersion === 4 && generatorOptions.target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
1699
+ const useIncrementalCache = (majorVersion === 3 || majorVersion === 4) && !(majorVersion === 3 && isolateCssSource);
1529
1700
  return generator.generate({
1530
1701
  bareArbitraryValues: generatorOptions.bareArbitraryValues,
1531
1702
  candidates: generatorRuntime,
1532
- incrementalCache: majorVersion === 3 || majorVersion === 4,
1703
+ incrementalCache: useIncrementalCache,
1533
1704
  scanSources: shouldScanTailwindV4Sources(majorVersion, generatorOptions.target, generatorRuntime, isolateCssSource),
1534
1705
  styleOptions: generatorStyleOptions,
1535
1706
  tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
@@ -1551,22 +1722,27 @@ async function generateCssByGenerator(options) {
1551
1722
  sources: generatedResults.flatMap((item) => item.sources)
1552
1723
  };
1553
1724
  debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
1554
- if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(effectiveRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
1725
+ if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(generatorRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
1555
1726
  const incrementalCss = stripTailwindBanner(generated.incrementalCss);
1556
1727
  return {
1557
- css: incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss,
1728
+ css: restoreLocalCssImports(incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss, localImportParts?.imports),
1558
1729
  target: generated.target,
1559
1730
  source: "generator",
1560
1731
  dependencies: generated.dependencies,
1561
1732
  incremental: true
1562
1733
  };
1563
1734
  }
1735
+ const shouldFilterApplyOnlyCss = shouldFilterApplyOnlyGeneratedCss(majorVersion, generated.target, generatorRawSource, {
1736
+ hasGeneratedCss,
1737
+ hasGeneratedMarkers
1738
+ });
1739
+ const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(stripTailwindBanner(generated.css), generatorRawSource) : stripTailwindBanner(generated.css);
1564
1740
  const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
1565
- const orderedExtraCss = hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(effectiveRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(effectiveRawSource, generated.rawCss);
1741
+ const orderedExtraCss = hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(userCssRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(userCssRawSource, generated.rawCss);
1566
1742
  const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
1567
1743
  if (orderedExtraCss) {
1568
- let css = stripTailwindBanner(generated.css);
1569
- if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
1744
+ let css = generatedCss;
1745
+ if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, generatorRawSource);
1570
1746
  const userCssOptions = {
1571
1747
  generatorTarget: generated.target,
1572
1748
  generatorStyleOptions,
@@ -1586,27 +1762,33 @@ async function generateCssByGenerator(options) {
1586
1762
  hasSourceDirectives,
1587
1763
  hasMatchedCssSourceFile
1588
1764
  })) {
1589
- const userCss = await transformGeneratorUserCss(effectiveRawSource, userCssOptions);
1765
+ const userCss = await transformGeneratorUserCss(userCssRawSource, userCssOptions);
1590
1766
  css = createCssSourceOrderAppend(css, userCss);
1591
1767
  }
1592
1768
  if (generated.target === "weapp" && shouldAppendMatchedCssSourceCompat) {
1593
1769
  if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
1594
- css = await appendLegacyCompatCss(css, effectiveRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1595
- css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1770
+ if (!shouldFilterApplyOnlyCss) {
1771
+ css = await appendLegacyCompatCss(css, userCssRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1772
+ if (!isolateCurrentCssCandidates) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1773
+ }
1596
1774
  } else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
1597
1775
  return {
1598
- css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight),
1776
+ css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
1777
+ cssHandlerOptions,
1778
+ isolateCurrentCssCandidates,
1779
+ localImports: localImportParts?.imports
1780
+ }) }), localImportParts?.imports),
1599
1781
  target: generated.target,
1600
1782
  source: "generator",
1601
1783
  dependencies: generated.dependencies
1602
1784
  };
1603
1785
  }
1604
1786
  debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
1605
- let css = stripTailwindBanner(generated.css);
1787
+ let css = generatedCss;
1606
1788
  if (generated.target === "weapp") {
1607
- css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
1608
- if (hasUserCssLayerBlocks(effectiveRawSource)) {
1609
- const layerParts = splitUserCssLayerBlocks(effectiveRawSource);
1789
+ css = inheritLegacyUnitConvertedDeclarations(css, generatorRawSource);
1790
+ if (hasUserCssLayerBlocks(generatorRawSource)) {
1791
+ const layerParts = splitUserCssLayerBlocks(generatorRawSource);
1610
1792
  const layerUserCss = await transformGeneratorUserCss(layerParts.layer, {
1611
1793
  generatorTarget: generated.target,
1612
1794
  generatorStyleOptions,
@@ -1626,7 +1808,7 @@ async function generateCssByGenerator(options) {
1626
1808
  }
1627
1809
  if (hasMatchedCssSourceFile || generated.target === "web") {
1628
1810
  if (hasMatchedCssSourceFile && generated.target === "weapp" && !hasGeneratedCss && !hasGeneratedMarkers) {
1629
- const userCss = await transformGeneratorUserCss(effectiveRawSource, {
1811
+ const userCss = await transformGeneratorUserCss(userCssRawSource, {
1630
1812
  generatorTarget: generated.target,
1631
1813
  generatorStyleOptions,
1632
1814
  cssUserHandlerOptions,
@@ -1635,12 +1817,14 @@ async function generateCssByGenerator(options) {
1635
1817
  });
1636
1818
  css = createCssSourceOrderAppend(css, userCss);
1637
1819
  }
1638
- if (hasMatchedCssSourceFile && generated.target === "weapp") css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1820
+ if (hasMatchedCssSourceFile && generated.target === "weapp") {
1821
+ if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1822
+ }
1639
1823
  if (shouldAppendWebBundleCssFallback(generated.target, {
1640
1824
  hasSourceDirectives,
1641
1825
  hasMatchedCssSourceFile
1642
1826
  })) {
1643
- const userCss = await transformGeneratorUserCss(effectiveRawSource, {
1827
+ const userCss = await transformGeneratorUserCss(userCssRawSource, {
1644
1828
  generatorTarget: generated.target,
1645
1829
  generatorStyleOptions,
1646
1830
  cssUserHandlerOptions,
@@ -1650,16 +1834,26 @@ async function generateCssByGenerator(options) {
1650
1834
  css = createCssSourceOrderAppend(css, userCss);
1651
1835
  }
1652
1836
  return {
1653
- css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight),
1837
+ css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
1838
+ cssHandlerOptions,
1839
+ isolateCurrentCssCandidates,
1840
+ localImports: localImportParts?.imports
1841
+ }) }), localImportParts?.imports),
1654
1842
  target: generated.target,
1655
1843
  source: "generator",
1656
1844
  dependencies: generated.dependencies
1657
1845
  };
1658
1846
  }
1659
- css = await appendLegacyCompatCss(css, effectiveRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1660
- css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1847
+ if (!shouldFilterApplyOnlyCss) {
1848
+ css = await appendLegacyCompatCss(css, userCssRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1849
+ css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
1850
+ }
1661
1851
  return {
1662
- css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight),
1852
+ css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
1853
+ cssHandlerOptions,
1854
+ isolateCurrentCssCandidates,
1855
+ localImports: localImportParts?.imports
1856
+ }) }), localImportParts?.imports),
1663
1857
  target: generated.target,
1664
1858
  source: "generator",
1665
1859
  dependencies: generated.dependencies