weapp-tailwindcss 5.1.6 → 5.1.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 (76) hide show
  1. package/dist/bundlers/framework-selector.d.ts +26 -0
  2. package/dist/bundlers/gulp/frameworks/native/index.d.ts +6 -0
  3. package/dist/bundlers/gulp/index.d.ts +4 -4
  4. package/dist/bundlers/gulp/shared/create-native-framework-plugins.d.ts +6 -0
  5. package/dist/bundlers/vite/css-finalizer.d.ts +2 -0
  6. package/dist/bundlers/vite/frameworks/generic/index.d.ts +2 -0
  7. package/dist/bundlers/vite/frameworks/taro/index.d.ts +2 -0
  8. package/dist/bundlers/vite/frameworks/uni-app/index.d.ts +2 -0
  9. package/dist/bundlers/vite/frameworks/uni-app-x/index.d.ts +2 -0
  10. package/dist/bundlers/vite/frameworks/weapp-vite/index.d.ts +2 -0
  11. package/dist/bundlers/vite/generate-bundle/css-output-helpers.d.ts +5 -1
  12. package/dist/bundlers/vite/generate-bundle/finalize.d.ts +5 -1
  13. package/dist/bundlers/vite/generate-bundle/root-style-output.d.ts +2 -2
  14. package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +8 -0
  15. package/dist/bundlers/vite/generate-bundle/types.d.ts +2 -0
  16. package/dist/bundlers/vite/index.d.ts +2 -4
  17. package/dist/bundlers/vite/processed-css-assets.d.ts +5 -0
  18. package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +35 -0
  19. package/dist/bundlers/vite/shared/framework-strategy.d.ts +88 -0
  20. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +1 -2
  21. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +11 -0
  22. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +3 -0
  23. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -2
  24. package/dist/bundlers/webpack/frameworks/generic/index.d.ts +5 -0
  25. package/dist/bundlers/webpack/frameworks/index.d.ts +8 -0
  26. package/dist/bundlers/webpack/frameworks/mpx/index.d.ts +5 -0
  27. package/dist/bundlers/webpack/frameworks/taro/index.d.ts +5 -0
  28. package/dist/bundlers/webpack/frameworks/uni-app/index.d.ts +5 -0
  29. package/dist/bundlers/webpack/frameworks/weapp-vite/index.d.ts +5 -0
  30. package/dist/bundlers/webpack/shared/create-framework-plugin.d.ts +21 -0
  31. package/dist/bundlers/webpack/shared/loader-anchors.d.ts +4 -3
  32. package/dist/cli.js +8 -0
  33. package/dist/cli.mjs +8 -0
  34. package/dist/{context-BCSk_YnL.js → context-CRhUs_5e.js} +13 -4
  35. package/dist/{context-3GGqW9vw.mjs → context-CfXr3hWz.mjs} +13 -4
  36. package/dist/core.js +1 -1
  37. package/dist/core.mjs +1 -1
  38. package/dist/{generator-CqWzj2Z1.js → generator-DaaFxR5V.js} +1 -1
  39. package/dist/{generator-CoT5vu9w.mjs → generator-DugIHBgl.mjs} +1 -1
  40. package/dist/generator.js +2 -2
  41. package/dist/generator.mjs +2 -2
  42. package/dist/{gulp-Bss4wJ8t.mjs → gulp-CRjkPsbX.mjs} +22 -7
  43. package/dist/{gulp-hXE1U4Cu.js → gulp-JUfnhOOo.js} +22 -7
  44. package/dist/gulp.js +1 -1
  45. package/dist/gulp.mjs +1 -1
  46. package/dist/{hmr-timing-Cfu-4Bnf.mjs → hmr-timing-BecOXMd8.mjs} +13 -7
  47. package/dist/{hmr-timing-Df4203aI.js → hmr-timing-DcIEXnf8.js} +13 -7
  48. package/dist/index.js +4 -4
  49. package/dist/index.mjs +4 -4
  50. package/dist/postcss.js +2 -2
  51. package/dist/postcss.mjs +2 -2
  52. package/dist/presets.js +2 -2
  53. package/dist/presets.mjs +2 -2
  54. package/dist/rspack.js +1 -1
  55. package/dist/rspack.mjs +1 -1
  56. package/dist/{source-candidate-scan-signature-5Uk6U72B.js → source-candidate-scan-signature-10tvdJVC.js} +185 -98
  57. package/dist/{source-candidate-scan-signature-BbCmW975.mjs → source-candidate-scan-signature-DAg8QSgh.mjs} +162 -99
  58. package/dist/style-injector/internal.d.ts +18 -4
  59. package/dist/{tailwindcss-DYJ3HZD2.js → tailwindcss-BZjZZi60.js} +1 -1
  60. package/dist/{tailwindcss-Bjr3aphG.mjs → tailwindcss-PA2jHHpx.mjs} +1 -1
  61. package/dist/{transform-B6_y_yCB.js → transform-B0BxX3XB.js} +1 -1
  62. package/dist/{transform--155BmeJ.mjs → transform-wNEbcZeQ.mjs} +1 -1
  63. package/dist/uni-app-x/vite.d.ts +1 -0
  64. package/dist/uni-app-x/web-preflight-reset.d.ts +3 -0
  65. package/dist/{v4-engine-C9cmNlP8.js → v4-engine-BZP2462H.js} +44 -1
  66. package/dist/{v4-engine-DRQaCFMm.mjs → v4-engine-CjjWONB0.mjs} +45 -2
  67. package/dist/{vite-Baw9qNrc.js → vite-GdzlG_lx.js} +1332 -790
  68. package/dist/{vite-PdxjaqhO.mjs → vite-vf2-cDdk.mjs} +1330 -788
  69. package/dist/vite.js +1 -1
  70. package/dist/vite.mjs +1 -1
  71. package/dist/weapp-tw-css-import-rewrite-loader.js +162 -7
  72. package/dist/{webpack-BffTDmod.mjs → webpack-2s-TFhgm.mjs} +583 -238
  73. package/dist/{webpack-C9u7mfGE.js → webpack-BhM4Hqla.js} +582 -237
  74. package/dist/webpack.js +1 -1
  75. package/dist/webpack.mjs +1 -1
  76. package/package.json +3 -3
@@ -1,12 +1,12 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-emK7D4bc.js");
2
2
  const require_framework = require("./framework.js");
3
- const require_v4_engine = require("./v4-engine-C9cmNlP8.js");
4
- const require_generator = require("./generator-CqWzj2Z1.js");
3
+ const require_v4_engine = require("./v4-engine-BZP2462H.js");
4
+ const require_generator = require("./generator-DaaFxR5V.js");
5
5
  const require_utils = require("./utils-D3h8j7Mk.js");
6
- const require_context = require("./context-BCSk_YnL.js");
7
- const require_tailwindcss = require("./tailwindcss-DYJ3HZD2.js");
8
- const require_hmr_timing = require("./hmr-timing-Df4203aI.js");
9
- const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-5Uk6U72B.js");
6
+ const require_context = require("./context-CRhUs_5e.js");
7
+ const require_tailwindcss = require("./tailwindcss-BZjZZi60.js");
8
+ const require_hmr_timing = require("./hmr-timing-DcIEXnf8.js");
9
+ const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-10tvdJVC.js");
10
10
  require("./logger-TlKT3xmR.js");
11
11
  let node_fs = require("node:fs");
12
12
  node_fs = require_rolldown_runtime.__toESM(node_fs);
@@ -24,30 +24,6 @@ let node_buffer = require("node:buffer");
24
24
  let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
25
25
  let comment_json = require("comment-json");
26
26
  let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
27
- //#region src/uni-app-x/harmony.ts
28
- function isUniAppXHarmonyOutDir(outDir) {
29
- return typeof outDir === "string" && /(?:^|[/\\])\.?app-harmony(?:[/\\]|$)/.test(outDir);
30
- }
31
- //#endregion
32
- //#region src/bundlers/vite/query.ts
33
- function parseVueRequest(id) {
34
- const [filename = id, rawQuery] = id.split(`?`, 2);
35
- const searchParams = new URLSearchParams(rawQuery);
36
- const query = Object.fromEntries(searchParams);
37
- if (query.vue != null) query.vue = true;
38
- if (query.index != null) query.index = Number(query.index);
39
- if (query.raw != null) query.raw = true;
40
- if (query.url != null) query.url = true;
41
- if (query.scoped != null) query.scoped = true;
42
- const langTypeMatch = [...searchParams.keys()].find((key) => key.startsWith("lang."));
43
- const langType = query.lang || (langTypeMatch ? langTypeMatch.slice(5) : void 0);
44
- if (langType) query.lang = langType;
45
- return {
46
- filename,
47
- query
48
- };
49
- }
50
- //#endregion
51
27
  //#region src/uni-app-x/style-asset/style-value.ts
52
28
  const GEN_APP_STYLES_RE = /const\s+GenAppStyles\s*=\s*\[_uM\(\[([\s\S]*?)\]\)\]/;
53
29
  const STYLE_ENTRY_RE = /\[\s*("((?:\\.|[^"\\])+)")\s*,\s*(_pS\(_uM\(\[[\s\S]*?\]\)\))\s*\]/g;
@@ -494,426 +470,170 @@ function createUniAppXBundleAssetSourceGetter(bundle) {
494
470
  };
495
471
  }
496
472
  //#endregion
497
- //#region src/uni-app-x/style-isolation.ts
498
- const manifestCache = /* @__PURE__ */ new Map();
499
- function resolveUniAppXStyleIsolationEnabled(root) {
500
- if (!root) return false;
501
- const normalizedRoot = node_path.default.resolve(root);
502
- const cached = manifestCache.get(normalizedRoot);
503
- if (cached !== void 0) return cached;
504
- const manifestPath = node_path.default.join(normalizedRoot, "manifest.json");
505
- let enabled = false;
506
- try {
507
- enabled = `${(0, comment_json.parse)(node_fs.default.readFileSync(manifestPath, "utf8"))["uni-app-x"]?.styleIsolationVersion ?? ""}` === "2";
508
- } catch {
509
- enabled = false;
473
+ //#region src/bundlers/vite/generate-bundle/configured-css-sources.ts
474
+ function collectConfiguredTailwindV4CssSources(opts) {
475
+ const runtimeCssSources = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources ?? [];
476
+ return require_v4_engine.filterTailwindV4CssSourceRoots([...opts.tailwindcss?.v4?.cssSources ?? [], ...runtimeCssSources]) ?? [];
477
+ }
478
+ function collectExplicitTailwindV4CssEntries(opts) {
479
+ const entries = [
480
+ ...opts.cssEntries ?? [],
481
+ ...opts.tailwindcss?.v4?.cssEntries ?? [],
482
+ ...opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries ?? []
483
+ ];
484
+ return [...new Set(entries.filter((entry) => typeof entry === "string" && entry.length > 0))];
485
+ }
486
+ function collectConfiguredTailwindV4CssSourceEntries(opts, fallbackBase) {
487
+ const entries = [];
488
+ const seen = /* @__PURE__ */ new Set();
489
+ const explicitCssEntries = collectExplicitTailwindV4CssEntries(opts);
490
+ for (const cssEntry of explicitCssEntries.length > 1 ? explicitCssEntries : []) {
491
+ if (typeof cssEntry !== "string" || cssEntry.length === 0) continue;
492
+ const resolvedFile = node_path.default.isAbsolute(cssEntry) ? node_path.default.resolve(cssEntry) : node_path.default.resolve(fallbackBase, cssEntry);
493
+ if (!(0, node_fs.existsSync)(resolvedFile)) continue;
494
+ const source = (0, node_fs.readFileSync)(resolvedFile, "utf8");
495
+ const key = `${resolvedFile}\0${source}`;
496
+ if (seen.has(key)) continue;
497
+ seen.add(key);
498
+ entries.push({
499
+ file: resolvedFile,
500
+ source
501
+ });
510
502
  }
511
- manifestCache.set(normalizedRoot, enabled);
512
- return enabled;
503
+ for (const cssSource of collectConfiguredTailwindV4CssSources(opts)) {
504
+ if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
505
+ const base = require_v4_engine.resolveTailwindV4CssSourceBase(cssSource, fallbackBase);
506
+ const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? cssSource.file : node_path.default.join(base, "tailwind.css");
507
+ const resolvedFile = node_path.default.isAbsolute(file) ? node_path.default.resolve(file) : node_path.default.resolve(base, file);
508
+ const key = `${resolvedFile}\0${cssSource.css}`;
509
+ if (seen.has(key)) continue;
510
+ seen.add(key);
511
+ entries.push({
512
+ file: resolvedFile,
513
+ source: cssSource.css
514
+ });
515
+ }
516
+ return entries;
513
517
  }
514
518
  //#endregion
515
- //#region src/uni-app-x/vite.ts
516
- let transformUVuePromise;
517
- function loadTransformUVue() {
518
- transformUVuePromise ?? (transformUVuePromise = Promise.resolve().then(() => require("./transform-B6_y_yCB.js")).then((mod) => mod.transformUVue));
519
- return transformUVuePromise;
519
+ //#region src/bundlers/vite/generate-bundle/rollup-assets.ts
520
+ function createReplayCssAsset(fileName, source) {
521
+ return {
522
+ type: "asset",
523
+ fileName,
524
+ name: void 0,
525
+ source,
526
+ needsCodeReference: false,
527
+ names: [],
528
+ originalFileName: null,
529
+ originalFileNames: []
530
+ };
520
531
  }
521
- const preprocessorLangs = /* @__PURE__ */ new Set([
522
- "scss",
523
- "sass",
524
- "less",
525
- "styl",
526
- "stylus"
527
- ]);
528
- const INLINE_LANG_RE = /lang\.([a-z]+)/i;
529
- const PREPROCESSOR_EXT_RE = /\.(?:scss|sass|less|styl|stylus)(?:\?|$)/i;
530
- const UVUE_NVUE_QUERY_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
531
- const UVUE_NVUE_RE = /\.(?:uvue|nvue)$/;
532
- const CSS_MODULE_EXPORT_RE = /^\s*export\s+default\s+(?:\{|\w|\[\])/;
533
- function isPreprocessorRequest(id, lang) {
534
- const normalizedLang = lang?.toLowerCase();
535
- if (normalizedLang && preprocessorLangs.has(normalizedLang)) return true;
536
- const inlineLang = id.match(INLINE_LANG_RE)?.[1];
537
- if (inlineLang && preprocessorLangs.has(inlineLang.toLowerCase())) return true;
538
- return PREPROCESSOR_EXT_RE.test(id);
532
+ function isAddWatchFileInvalidRollupPhaseError$1(error) {
533
+ const candidate = error;
534
+ return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
539
535
  }
540
- function resolveUniAppXCssTarget(id) {
541
- return UVUE_NVUE_RE.test((0, _weapp_tailwindcss_shared.cleanUrl)(id)) ? "uvue" : void 0;
536
+ function registerGeneratorDependencies$1(ctx, dependencies) {
537
+ if (typeof ctx.addWatchFile !== "function") return;
538
+ for (const dependency of dependencies ?? []) try {
539
+ ctx.addWatchFile(dependency);
540
+ } catch (error) {
541
+ if (isAddWatchFileInvalidRollupPhaseError$1(error)) {
542
+ _weapp_tailwindcss_logger.logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
543
+ continue;
544
+ }
545
+ throw error;
546
+ }
542
547
  }
543
- function resolveUniAppXJsTransformEnabled$1(uniAppX) {
544
- return uniAppX === void 0 ? true : require_tailwindcss.isUniAppXEnabled(uniAppX);
548
+ //#endregion
549
+ //#region src/bundlers/vite/generate-bundle/css-assets.ts
550
+ function createCssAssetEmitter(context) {
551
+ return (fileName, source) => {
552
+ if (context.emitFile) {
553
+ context.emitFile({
554
+ type: "asset",
555
+ fileName,
556
+ source
557
+ });
558
+ return;
559
+ }
560
+ return createReplayCssAsset(fileName, source);
561
+ };
545
562
  }
546
- function isCssModuleExport(code) {
547
- return CSS_MODULE_EXPORT_RE.test(code);
563
+ function resolveAssetSourceFile(asset, fallbackFile) {
564
+ return [asset.originalFileName, ...asset.originalFileNames ?? []].filter((item) => typeof item === "string" && item.length > 0)[0] ?? fallbackFile;
548
565
  }
549
- function createUniAppXPlugins(options) {
550
- const { appType, customAttributesEntities, disabledDefaultTemplateHandler, isIosPlatform: providedIosPlatform, mainCssChunkMatcher, runtimeState, styleHandler, generateCss, jsHandler, ensureRuntimeClassSet, getResolvedConfig, uniAppX } = options;
551
- const resolvedUniAppXOptions = require_tailwindcss.resolveUniAppXOptions(uniAppX);
552
- const utsPlatform = require_utils.resolveUniUtsPlatform();
553
- const isIosPlatform = providedIosPlatform ?? utsPlatform.isAppIos;
554
- const isHarmonyPlatform = utsPlatform.isAppHarmony;
555
- const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
556
- let componentLocalStyleEnabled;
557
- const harmonyApplyStyleSources = /* @__PURE__ */ new Set();
558
- const harmonyApplyUtilities = /* @__PURE__ */ new Set();
559
- function rememberHarmonyApplySource(code) {
560
- const styleSources = collectUniAppXHarmonyApplyStyleSourcesFromSource(code);
561
- if (styleSources.length === 0) return;
562
- for (const styleSource of styleSources) {
563
- harmonyApplyStyleSources.add(styleSource);
564
- for (const utility of collectUniAppXHarmonyApplyUtilitiesFromSources([styleSource])) harmonyApplyUtilities.add(utility);
565
- }
566
+ //#endregion
567
+ //#region src/bundlers/vite/generate-bundle/css-output.ts
568
+ const SOURCE_STYLE_OUTPUT_EXT_RE = /\.(?:less|sass|scss|styl|stylus|pcss|postcss)$/i;
569
+ const CSS_SOURCE_OUTPUT_EXT_RE = /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss)$/i;
570
+ const SOURCE_STYLE_NON_CSS_SYNTAX_RE = /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@(?:use|forward|mixin|include|function)\b)/;
571
+ const FALLBACK_STYLE_OUTPUT_EXTENSION = ".css";
572
+ const COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS = [
573
+ ".wxss",
574
+ ".acss",
575
+ ".ttss",
576
+ ".qss",
577
+ ".jxss",
578
+ ".tyss"
579
+ ];
580
+ function resolveCssOutputRealPath(value) {
581
+ const resolved = node_path.default.resolve(value);
582
+ let current = resolved;
583
+ const pendingSegments = [];
584
+ while (!(0, node_fs.existsSync)(current)) {
585
+ const parent = node_path.default.dirname(current);
586
+ if (parent === current) return resolved;
587
+ pendingSegments.unshift(node_path.default.basename(current));
588
+ current = parent;
566
589
  }
567
- function shouldEnableComponentLocalStyle() {
568
- if (!resolvedUniAppXOptions.componentLocalStyles.enabled) {
569
- componentLocalStyleEnabled = false;
570
- return false;
571
- }
572
- if (!resolvedUniAppXOptions.componentLocalStyles.onlyWhenStyleIsolationVersion2) {
573
- componentLocalStyleEnabled = true;
574
- return true;
575
- }
576
- if (componentLocalStyleEnabled !== void 0) return componentLocalStyleEnabled;
577
- const root = getResolvedConfig()?.root;
578
- componentLocalStyleEnabled = resolveUniAppXStyleIsolationEnabled(root);
579
- return componentLocalStyleEnabled;
590
+ try {
591
+ const realPath = node_fs.realpathSync.native(current);
592
+ return pendingSegments.length > 0 ? node_path.default.join(realPath, ...pendingSegments) : realPath;
593
+ } catch {
594
+ return resolved;
580
595
  }
581
- function shouldEnableHarmonyPageLocalStyle() {
582
- return isHarmonyPlatform && resolvedUniAppXOptions.componentLocalStyles.enabled;
596
+ }
597
+ function normalizeStyleOutputExtension(value) {
598
+ if (typeof value !== "string" || value.trim().length === 0) return;
599
+ const normalized = value.trim().toLowerCase();
600
+ return normalized.startsWith(".") ? normalized : `.${normalized}`;
601
+ }
602
+ function getMatchedStyleOutputExtension(file, cssMatcher) {
603
+ const cleanFile = file.replace(/[?#].*$/, "");
604
+ if (!cssMatcher?.(cleanFile)) return;
605
+ const ext = node_path.default.extname(cleanFile);
606
+ if (!ext || ext === ".css") return;
607
+ return ext;
608
+ }
609
+ function resolveStyleOutputExtensionFromFiles(files, cssMatcher, stem) {
610
+ let extension;
611
+ for (const file of files ?? []) {
612
+ const cleanFile = file.replace(/[?#].*$/, "");
613
+ const matchedExtension = getMatchedStyleOutputExtension(cleanFile, cssMatcher);
614
+ if (!matchedExtension) continue;
615
+ if (stem && cleanFile.slice(0, -matchedExtension.length) !== stem) continue;
616
+ if (extension && extension !== matchedExtension) return;
617
+ extension = matchedExtension;
583
618
  }
584
- function isHarmonyBuildTarget() {
585
- if (require_utils.resolveUniUtsPlatform().isAppHarmony) return true;
586
- return isUniAppXHarmonyOutDir(getResolvedConfig()?.build?.outDir);
587
- }
588
- async function transformStyle(code, id, query, hookContext) {
589
- const parsed = query ?? parseVueRequest(id).query;
590
- if (require_source_candidate_scan_signature.isCSSRequest(id) || parsed.vue && parsed.type === "style") {
591
- if (isCssModuleExport(code)) return;
592
- const shouldGenerateCss = require_v4_engine.hasTailwindSourceDirectives(code, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(code);
593
- rememberHarmonyApplySource(code);
594
- const generatedCss = shouldGenerateCss ? await generateCss?.(id, code, hookContext) : void 0;
595
- const styleCode = typeof generatedCss === "string" && generatedCss.trim().length > 0 ? generatedCss : code;
596
- const cacheKey = `${mainCssChunkMatcher(id, appType) ? "1" : "0"}:${id}`;
597
- let styleHandlerOptions = cssHandlerOptionsCache.get(cacheKey);
598
- if (!styleHandlerOptions) {
599
- styleHandlerOptions = require_v4_engine.omitUndefined({
600
- isMainChunk: mainCssChunkMatcher(id, appType),
601
- uniAppXCssTarget: resolveUniAppXCssTarget(id),
602
- uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
603
- postcssOptions: { options: {
604
- from: id,
605
- map: {
606
- inline: false,
607
- annotation: false,
608
- sourcesContent: true
609
- }
610
- } }
611
- });
612
- cssHandlerOptionsCache.set(cacheKey, styleHandlerOptions);
613
- }
614
- const postcssResult = await styleHandler(styleCode, styleHandlerOptions);
615
- const warnings = typeof postcssResult.warnings === "function" ? postcssResult.warnings() : [];
616
- for (const warning of warnings) _weapp_tailwindcss_logger.logger.warn(warning.toString());
617
- const postcssMap = await require_source_candidate_scan_signature.formatPostcssSourceMap(postcssResult.map.toJSON(), require_source_candidate_scan_signature.normalizePath((0, _weapp_tailwindcss_shared.cleanUrl)(id)));
618
- return {
619
- code: postcssResult.css,
620
- map: postcssMap
621
- };
622
- }
623
- }
624
- const cssPlugins = [{
625
- name: "weapp-tailwindcss:uni-app-x:css",
626
- async transform(code, id) {
627
- await runtimeState.readyPromise;
628
- return transformStyle(code, id, void 0, this);
629
- }
630
- }, {
631
- name: "weapp-tailwindcss:uni-app-x:css:pre",
632
- enforce: "pre",
633
- async transform(code, id) {
634
- await runtimeState.readyPromise;
635
- const { query } = parseVueRequest(id);
636
- const lang = query.lang;
637
- if (isIosPlatform && isPreprocessorRequest(id, lang)) return;
638
- return transformStyle(code, id, query, this);
639
- }
640
- }];
641
- const nvuePlugin = {
642
- name: "weapp-tailwindcss:uni-app-x:nvue",
643
- enforce: "pre",
644
- async buildStart() {
645
- await ensureRuntimeClassSet(true);
646
- },
647
- async transform(code, id) {
648
- if (!UVUE_NVUE_QUERY_RE.test(id)) return;
649
- rememberHarmonyApplySource(code);
650
- const resolvedConfig = getResolvedConfig();
651
- const isServeCommand = resolvedConfig?.command === "serve";
652
- const isWatchBuild = resolvedConfig?.command === "build" && !!resolvedConfig.build?.watch;
653
- const isNonWatchBuild = resolvedConfig?.command === "build" && !resolvedConfig.build?.watch;
654
- const currentRuntimeSet = isServeCommand || isWatchBuild || isNonWatchBuild ? await ensureRuntimeClassSet(true) : await ensureRuntimeClassSet();
655
- const transformUVue = await loadTransformUVue();
656
- const enableComponentLocalStyle = shouldEnableComponentLocalStyle();
657
- const enablePageLocalStyle = shouldEnableHarmonyPageLocalStyle();
658
- if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle) return transformUVue(code, id, jsHandler, currentRuntimeSet, require_v4_engine.omitUndefined({
659
- ...customAttributesEntities.length > 0 ? { customAttributesEntities } : {},
660
- ...disabledDefaultTemplateHandler ? { disabledDefaultTemplateHandler } : {},
661
- ...enableComponentLocalStyle ? { enableComponentLocalStyle } : {},
662
- ...enablePageLocalStyle ? { enablePageLocalStyle } : {}
663
- }));
664
- return transformUVue(code, id, jsHandler, currentRuntimeSet);
665
- },
666
- async handleHotUpdate(ctx) {
667
- if (getResolvedConfig()?.command !== "serve") return;
668
- if (!UVUE_NVUE_RE.test(ctx.file)) return;
669
- await ensureRuntimeClassSet(true);
670
- },
671
- async watchChange(id) {
672
- const resolvedConfig = getResolvedConfig();
673
- if (resolvedConfig?.command !== "build" || !resolvedConfig.build?.watch) return;
674
- if (!UVUE_NVUE_QUERY_RE.test(id)) return;
675
- await ensureRuntimeClassSet(true);
676
- }
677
- };
678
- const stylePlaceholderPlugin = {
679
- name: "weapp-tailwindcss:uni-app-x:style-placeholder",
680
- enforce: "post",
681
- generateBundle: {
682
- order: "post",
683
- async handler(_options, bundle) {
684
- const currentUtsPlatform = require_utils.resolveUniUtsPlatform();
685
- const canInferHarmonyTarget = !currentUtsPlatform.normalized || currentUtsPlatform.isApp;
686
- const isHarmonyTarget = currentUtsPlatform.isAppHarmony || canInferHarmonyTarget && isHarmonyBuildTarget();
687
- if (!currentUtsPlatform.isApp && !isHarmonyTarget) return;
688
- const getAssetSource = createUniAppXBundleAssetSourceGetter(bundle);
689
- if (isHarmonyTarget) {
690
- const cssSources = [];
691
- const applyStyleSources = [...harmonyApplyStyleSources, ...collectUniAppXHarmonyApplyStyleSources(bundle)];
692
- const applyUtilities = /* @__PURE__ */ new Set([...harmonyApplyUtilities, ...collectUniAppXHarmonyApplyUtilities(bundle)]);
693
- if (applyStyleSources.length > 0 && applyUtilities.size > 0) {
694
- const harmonyApplyCssFile = node_path.default.resolve(getResolvedConfig()?.root ?? node_process.default.cwd(), "uni-app-x-harmony-apply.css");
695
- const generatedCss = await generateCss?.(harmonyApplyCssFile, createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities), this);
696
- if (typeof generatedCss === "string" && generatedCss.trim().length > 0) cssSources.push(generatedCss);
697
- }
698
- injectUniAppXHarmonyBundleStyles(bundle, {
699
- cssSources,
700
- excludeComponents: shouldEnableComponentLocalStyle()
701
- });
702
- }
703
- for (const [file, item] of Object.entries(bundle)) {
704
- if (item.type !== "asset" || !file.endsWith(".uvue.ts")) continue;
705
- const currentSource = String(item.source);
706
- const nextSource = injectUniAppXStylePlaceholder(file, currentSource, getAssetSource);
707
- if (nextSource !== currentSource) item.source = nextSource;
708
- }
709
- }
710
- }
711
- };
712
- return [
713
- ...cssPlugins,
714
- nvuePlugin,
715
- stylePlaceholderPlugin
716
- ];
717
- }
718
- function createUniAppXAssetTask(file, originalSource, outDir, options) {
719
- return async () => {
720
- const { cache, hashKey, createHandlerOptions, debug, getAssetSource, jsHandler, onUpdate, runtimeSet, applyLinkedResults } = options;
721
- const absoluteFile = require_source_candidate_scan_signature.toAbsoluteOutputPath(file, outDir);
722
- const rawSource = originalSource.source.toString();
723
- await require_hmr_timing.processCachedTask({
724
- cache,
725
- cacheKey: file,
726
- hashKey,
727
- rawSource: options.hashSalt ? `${rawSource}\n/*${options.hashSalt}*/` : rawSource,
728
- applyResult(source) {
729
- originalSource.source = source;
730
- },
731
- onCacheHit() {
732
- debug("js cache hit: %s", file);
733
- },
734
- async transform() {
735
- const currentSource = originalSource.source.toString();
736
- const { code, linked } = await jsHandler(currentSource, runtimeSet, createHandlerOptions(absoluteFile, {
737
- uniAppX: resolveUniAppXJsTransformEnabled$1(options.uniAppX),
738
- babelParserOptions: {
739
- plugins: ["typescript"],
740
- sourceType: "unambiguous"
741
- }
742
- }));
743
- const nextCode = injectUniAppXStylePlaceholder(file, code, getAssetSource);
744
- onUpdate(file, currentSource, nextCode);
745
- debug("js handle: %s", file);
746
- applyLinkedResults(linked);
747
- return { result: nextCode };
748
- }
749
- });
750
- };
751
- }
752
- //#endregion
753
- //#region src/bundlers/vite/generate-bundle/configured-css-sources.ts
754
- function collectConfiguredTailwindV4CssSources(opts) {
755
- const runtimeCssSources = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources ?? [];
756
- return require_v4_engine.filterTailwindV4CssSourceRoots([...opts.tailwindcss?.v4?.cssSources ?? [], ...runtimeCssSources]) ?? [];
757
- }
758
- function collectExplicitTailwindV4CssEntries(opts) {
759
- const entries = [
760
- ...opts.cssEntries ?? [],
761
- ...opts.tailwindcss?.v4?.cssEntries ?? [],
762
- ...opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries ?? []
763
- ];
764
- return [...new Set(entries.filter((entry) => typeof entry === "string" && entry.length > 0))];
765
- }
766
- function collectConfiguredTailwindV4CssSourceEntries(opts, fallbackBase) {
767
- const entries = [];
768
- const seen = /* @__PURE__ */ new Set();
769
- const explicitCssEntries = collectExplicitTailwindV4CssEntries(opts);
770
- for (const cssEntry of explicitCssEntries.length > 1 ? explicitCssEntries : []) {
771
- if (typeof cssEntry !== "string" || cssEntry.length === 0) continue;
772
- const resolvedFile = node_path.default.isAbsolute(cssEntry) ? node_path.default.resolve(cssEntry) : node_path.default.resolve(fallbackBase, cssEntry);
773
- if (!(0, node_fs.existsSync)(resolvedFile)) continue;
774
- const source = (0, node_fs.readFileSync)(resolvedFile, "utf8");
775
- const key = `${resolvedFile}\0${source}`;
776
- if (seen.has(key)) continue;
777
- seen.add(key);
778
- entries.push({
779
- file: resolvedFile,
780
- source
781
- });
782
- }
783
- for (const cssSource of collectConfiguredTailwindV4CssSources(opts)) {
784
- if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
785
- const base = require_v4_engine.resolveTailwindV4CssSourceBase(cssSource, fallbackBase);
786
- const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? cssSource.file : node_path.default.join(base, "tailwind.css");
787
- const resolvedFile = node_path.default.isAbsolute(file) ? node_path.default.resolve(file) : node_path.default.resolve(base, file);
788
- const key = `${resolvedFile}\0${cssSource.css}`;
789
- if (seen.has(key)) continue;
790
- seen.add(key);
791
- entries.push({
792
- file: resolvedFile,
793
- source: cssSource.css
794
- });
795
- }
796
- return entries;
797
- }
798
- //#endregion
799
- //#region src/bundlers/vite/generate-bundle/rollup-assets.ts
800
- function createReplayCssAsset(fileName, source) {
801
- return {
802
- type: "asset",
803
- fileName,
804
- name: void 0,
805
- source,
806
- needsCodeReference: false,
807
- names: [],
808
- originalFileName: null,
809
- originalFileNames: []
810
- };
811
- }
812
- function isAddWatchFileInvalidRollupPhaseError$1(error) {
813
- const candidate = error;
814
- return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
815
- }
816
- function registerGeneratorDependencies$1(ctx, dependencies) {
817
- if (typeof ctx.addWatchFile !== "function") return;
818
- for (const dependency of dependencies ?? []) try {
819
- ctx.addWatchFile(dependency);
820
- } catch (error) {
821
- if (isAddWatchFileInvalidRollupPhaseError$1(error)) {
822
- _weapp_tailwindcss_logger.logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
823
- continue;
824
- }
825
- throw error;
826
- }
827
- }
828
- //#endregion
829
- //#region src/bundlers/vite/generate-bundle/css-assets.ts
830
- function createCssAssetEmitter(context) {
831
- return (fileName, source) => {
832
- if (context.emitFile) {
833
- context.emitFile({
834
- type: "asset",
835
- fileName,
836
- source
837
- });
838
- return;
839
- }
840
- return createReplayCssAsset(fileName, source);
841
- };
842
- }
843
- function resolveAssetSourceFile(asset, fallbackFile) {
844
- return [asset.originalFileName, ...asset.originalFileNames ?? []].filter((item) => typeof item === "string" && item.length > 0)[0] ?? fallbackFile;
845
- }
846
- //#endregion
847
- //#region src/bundlers/vite/generate-bundle/css-output.ts
848
- const SOURCE_STYLE_OUTPUT_EXT_RE = /\.(?:less|sass|scss|styl|stylus|pcss|postcss)$/i;
849
- const CSS_SOURCE_OUTPUT_EXT_RE = /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss)$/i;
850
- const SOURCE_STYLE_NON_CSS_SYNTAX_RE = /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@(?:use|forward|mixin|include|function)\b)/;
851
- const FALLBACK_STYLE_OUTPUT_EXTENSION = ".css";
852
- const COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS = [
853
- ".wxss",
854
- ".acss",
855
- ".ttss",
856
- ".qss",
857
- ".jxss",
858
- ".tyss"
859
- ];
860
- function resolveCssOutputRealPath(value) {
861
- const resolved = node_path.default.resolve(value);
862
- let current = resolved;
863
- const pendingSegments = [];
864
- while (!(0, node_fs.existsSync)(current)) {
865
- const parent = node_path.default.dirname(current);
866
- if (parent === current) return resolved;
867
- pendingSegments.unshift(node_path.default.basename(current));
868
- current = parent;
869
- }
870
- try {
871
- const realPath = node_fs.realpathSync.native(current);
872
- return pendingSegments.length > 0 ? node_path.default.join(realPath, ...pendingSegments) : realPath;
873
- } catch {
874
- return resolved;
875
- }
876
- }
877
- function normalizeStyleOutputExtension(value) {
878
- if (typeof value !== "string" || value.trim().length === 0) return;
879
- const normalized = value.trim().toLowerCase();
880
- return normalized.startsWith(".") ? normalized : `.${normalized}`;
881
- }
882
- function getMatchedStyleOutputExtension(file, cssMatcher) {
883
- const cleanFile = file.replace(/[?#].*$/, "");
884
- if (!cssMatcher?.(cleanFile)) return;
885
- const ext = node_path.default.extname(cleanFile);
886
- if (!ext || ext === ".css") return;
887
- return ext;
888
- }
889
- function resolveStyleOutputExtensionFromFiles(files, cssMatcher, stem) {
890
- let extension;
891
- for (const file of files ?? []) {
892
- const cleanFile = file.replace(/[?#].*$/, "");
893
- const matchedExtension = getMatchedStyleOutputExtension(cleanFile, cssMatcher);
894
- if (!matchedExtension) continue;
895
- if (stem && cleanFile.slice(0, -matchedExtension.length) !== stem) continue;
896
- if (extension && extension !== matchedExtension) return;
897
- extension = matchedExtension;
898
- }
899
- return extension;
900
- }
901
- function resolveStyleOutputExtensionFromMatcher(cssMatcher, stem) {
902
- if (!cssMatcher || !stem) return;
903
- return COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS.find((extension) => cssMatcher(`${stem}${extension}`));
904
- }
905
- function resolveStyleOutputFileFromFiles(files, cssMatcher, stem) {
906
- const cleanStem = require_source_candidate_scan_signature.normalizeOutputPathKey(stem);
907
- const stemSuffix = `/${cleanStem}`;
908
- const matchedFiles = /* @__PURE__ */ new Set();
909
- for (const file of files ?? []) {
910
- const cleanFile = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
911
- if (!cssMatcher?.(cleanFile)) continue;
912
- const extension = node_path.default.extname(cleanFile);
913
- if (!extension || extension === ".css") continue;
914
- const outputStem = cleanFile.slice(0, -extension.length);
915
- const outputStemSuffix = `/${outputStem}`;
916
- if (outputStem === cleanStem || outputStem.endsWith(stemSuffix) || cleanStem.endsWith(outputStemSuffix) || cleanStem.endsWith(`/${outputStem}`)) matchedFiles.add(cleanFile);
619
+ return extension;
620
+ }
621
+ function resolveStyleOutputExtensionFromMatcher(cssMatcher, stem) {
622
+ if (!cssMatcher || !stem) return;
623
+ return COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS.find((extension) => cssMatcher(`${stem}${extension}`));
624
+ }
625
+ function resolveStyleOutputFileFromFiles(files, cssMatcher, stem) {
626
+ const cleanStem = require_source_candidate_scan_signature.normalizeOutputPathKey(stem);
627
+ const stemSuffix = `/${cleanStem}`;
628
+ const matchedFiles = /* @__PURE__ */ new Set();
629
+ for (const file of files ?? []) {
630
+ const cleanFile = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
631
+ if (!cssMatcher?.(cleanFile)) continue;
632
+ const extension = node_path.default.extname(cleanFile);
633
+ if (!extension || extension === ".css") continue;
634
+ const outputStem = cleanFile.slice(0, -extension.length);
635
+ const outputStemSuffix = `/${outputStem}`;
636
+ if (outputStem === cleanStem || outputStem.endsWith(stemSuffix) || cleanStem.endsWith(outputStemSuffix) || cleanStem.endsWith(`/${outputStem}`)) matchedFiles.add(cleanFile);
917
637
  }
918
638
  return matchedFiles.size === 1 ? [...matchedFiles][0] : void 0;
919
639
  }
@@ -1180,18 +900,21 @@ function createRootMiniProgramOriginStyleOutputFile(file) {
1180
900
  if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return normalized;
1181
901
  return normalized.replace(/(\.[^.]+)$/, "-origin$1");
1182
902
  }
1183
- function shouldKeepRootMiniProgramStyleAsImportShell(appType) {
1184
- return appType === "uni-app-vite" || appType === "uni-app-x" || appType === "taro";
903
+ function shouldKeepRootMiniProgramStyleAsImportShell(enabled) {
904
+ return enabled === true;
1185
905
  }
1186
- function shouldMoveRootMiniProgramStyleToImportShellOrigin(appType) {
1187
- return appType === "taro";
906
+ function shouldMoveRootMiniProgramStyleToImportShellOrigin(enabled) {
907
+ return enabled === true;
1188
908
  }
1189
909
  //#endregion
1190
910
  //#region src/bundlers/vite/generate-bundle/css-output-helpers.ts
1191
911
  function resolveCssBundleOutputFile(options) {
1192
- const { bundleFiles, defaultStyleOutputExtension, file, isWebGeneratorTarget, opts, shouldPreserveAppCssExtension } = options;
912
+ const { bundleFiles, defaultStyleOutputExtension, file, isWebGeneratorTarget, opts, pipelineContext, cssPipelineStrategy, shouldPreserveAppCssExtension } = options;
1193
913
  let outputFile = resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, shouldPreserveAppCssExtension, defaultStyleOutputExtension, bundleFiles);
1194
- if (outputFile === file && isRootMiniProgramStyleOutputFile$1(file) && shouldMoveRootMiniProgramStyleToImportShellOrigin(opts.appType)) outputFile = createRootMiniProgramOriginStyleOutputFile(file);
914
+ if (outputFile === file && isRootMiniProgramStyleOutputFile$1(file) && shouldMoveRootMiniProgramStyleToImportShellOrigin(cssPipelineStrategy?.shouldMoveRootMiniProgramStyleToImportShellOrigin?.({
915
+ ...pipelineContext,
916
+ file
917
+ }))) outputFile = createRootMiniProgramOriginStyleOutputFile(file);
1195
918
  return outputFile;
1196
919
  }
1197
920
  function shouldSkipRawSourceStyleAsset(outputFile, file, rawSource, assetSourceFile = file, cssMatcher) {
@@ -1229,12 +952,16 @@ function hasViteProcessedCssResultForSource(sourceFile, getViteProcessedCssAsset
1229
952
  return false;
1230
953
  }
1231
954
  function applyCssResultToBundle(options) {
1232
- const { appType, assetSourceFile, bundle, emitOrReplayCssAsset, file, originalSource, outputFile, source, viteProcessedCssAsset } = options;
955
+ const { assetSourceFile, bundle, cssPipelineStrategy, emitOrReplayCssAsset, file, originalSource, outputFile, pipelineContext, source, viteProcessedCssAsset } = options;
1233
956
  if (outputFile === file) {
1234
957
  originalSource.source = source;
1235
958
  return;
1236
959
  }
1237
- const importShellSource = isRootMiniProgramStyleOutputFile$1(file) && isRootMiniProgramStyleOutputFile$1(outputFile) && shouldKeepRootMiniProgramStyleAsImportShell(appType) ? createCssImportShell$1(file, outputFile) : void 0;
960
+ const importShellSource = isRootMiniProgramStyleOutputFile$1(file) && isRootMiniProgramStyleOutputFile$1(outputFile) && shouldKeepRootMiniProgramStyleAsImportShell(cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
961
+ ...pipelineContext,
962
+ css: source,
963
+ file
964
+ })) ? createCssImportShell$1(file, outputFile) : void 0;
1238
965
  if (bundle[file] === originalSource && originalSource.originalFileNames?.includes(assetSourceFile)) {
1239
966
  const existingOutput = bundle[outputFile];
1240
967
  if (existingOutput?.type === "asset") existingOutput.source = source;
@@ -1701,7 +1428,7 @@ const basename = function(p, extension) {
1701
1428
  }
1702
1429
  return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
1703
1430
  };
1704
- const parse = function(p) {
1431
+ const parse$1 = function(p) {
1705
1432
  const root = _PATH_ROOT_RE.exec(p)?.[0]?.replace(/\\/g, "/") || "";
1706
1433
  const base = basename(p);
1707
1434
  const extension = extname(base);
@@ -1727,7 +1454,7 @@ const _path = {
1727
1454
  matchesGlob,
1728
1455
  normalize,
1729
1456
  normalizeString,
1730
- parse,
1457
+ parse: parse$1,
1731
1458
  relative,
1732
1459
  resolve,
1733
1460
  sep: "/",
@@ -1759,20 +1486,66 @@ const SFC_STYLE_SOURCE_EXTENSIONS = [
1759
1486
  ".svelte",
1760
1487
  ".mpx"
1761
1488
  ];
1762
- const SFC_STYLE_BLOCK_RE$1 = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
1763
- function extractSfcStyleSources(source) {
1489
+ const SFC_STYLE_BLOCK_RE$1 = /<style\b([^>]*)>([\s\S]*?)<\/style>/gi;
1490
+ const SFC_SCOPED_STYLE_ATTR_RE = /(?:^|\s)scoped(?:\s|=|$)/i;
1491
+ const SFC_LANG_STYLE_ATTR_RE = /(?:^|\s)lang(?:=(?:"([^"]+)"|'([^']+)'|([^\s"'=<>`]+)))?/i;
1492
+ function extractSfcStyleBlocks(source) {
1764
1493
  const styleSources = [];
1765
1494
  SFC_STYLE_BLOCK_RE$1.lastIndex = 0;
1495
+ let index = 0;
1766
1496
  let match = SFC_STYLE_BLOCK_RE$1.exec(source);
1767
1497
  while (match !== null) {
1768
- styleSources.push(match[1] ?? "");
1498
+ const attrs = match[1] ?? "";
1499
+ styleSources.push({
1500
+ attrs,
1501
+ index,
1502
+ scoped: SFC_SCOPED_STYLE_ATTR_RE.test(attrs),
1503
+ source: match[2] ?? ""
1504
+ });
1505
+ index += 1;
1769
1506
  match = SFC_STYLE_BLOCK_RE$1.exec(source);
1770
1507
  }
1771
1508
  return styleSources;
1772
1509
  }
1510
+ function extractSfcStyleSources(source) {
1511
+ return extractSfcStyleBlocks(source).map((style) => style.source);
1512
+ }
1773
1513
  function hasSfcStyleSources(source) {
1774
1514
  return extractSfcStyleSources(source).length > 0;
1775
1515
  }
1516
+ function resolveSfcStyleHandlerSourceFile(sourceFile, styleBlocks) {
1517
+ const scopedStyleBlock = styleBlocks.find((style) => style.scoped);
1518
+ return scopedStyleBlock ? `${sourceFile}?vue&type=style&index=${scopedStyleBlock.index}&scoped=true` : sourceFile;
1519
+ }
1520
+ function normalizeSfcStyleSourceForCompare(source) {
1521
+ return source.replace(/\r\n?/g, "\n").trim();
1522
+ }
1523
+ function resolveSfcStyleBlockLang(attrs) {
1524
+ const match = SFC_LANG_STYLE_ATTR_RE.exec(attrs);
1525
+ return match?.[1] ?? match?.[2] ?? match?.[3];
1526
+ }
1527
+ function createSfcStyleRequest(sourceFile, styleBlock) {
1528
+ const params = new URLSearchParams();
1529
+ params.set("vue", "");
1530
+ params.set("type", "style");
1531
+ params.set("index", String(styleBlock.index));
1532
+ if (styleBlock.scoped) params.set("scoped", "true");
1533
+ const lang = resolveSfcStyleBlockLang(styleBlock.attrs);
1534
+ if (lang) params.set("lang", lang);
1535
+ return `${sourceFile}?${params.toString()}`;
1536
+ }
1537
+ function resolveSfcStyleRequestFromKnownSource(sourceFile, sfcSource, styleSource) {
1538
+ if (!sfcSource) return sourceFile;
1539
+ const styleBlocks = extractSfcStyleBlocks(sfcSource);
1540
+ if (styleBlocks.length === 0) return sourceFile;
1541
+ const normalizedStyleSource = normalizeSfcStyleSourceForCompare(styleSource);
1542
+ const matchedBlocks = styleBlocks.filter((styleBlock) => {
1543
+ const normalizedBlockSource = normalizeSfcStyleSourceForCompare(styleBlock.source);
1544
+ return normalizedBlockSource === normalizedStyleSource || normalizedBlockSource.includes(normalizedStyleSource) || normalizedStyleSource.includes(normalizedBlockSource);
1545
+ });
1546
+ const styleBlock = matchedBlocks.length === 1 ? matchedBlocks[0] : styleBlocks.length === 1 ? styleBlocks[0] : void 0;
1547
+ return styleBlock ? createSfcStyleRequest(sourceFile, styleBlock) : sourceFile;
1548
+ }
1776
1549
  function hasTailwindGenerationSource(source, options = {}) {
1777
1550
  const allowRootDirectives = options.allowRootDirectives !== false;
1778
1551
  return require_v4_engine.hasTailwindNonRootGenerationDirectives(source, { importFallback: true }) || allowRootDirectives && require_v4_engine.hasTailwindSourceDirectives(source, { importFallback: true }) || allowRootDirectives && require_v4_engine.hasTailwindRootDirectives(source, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(source);
@@ -1792,7 +1565,8 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
1792
1565
  debug("sfc style source infer skipped: missing known source for %s -> %s", outputFile, sourceFile);
1793
1566
  return;
1794
1567
  }
1795
- const rawSource = extractSfcStyleSources(source).join("\n");
1568
+ const styleBlocks = extractSfcStyleBlocks(source);
1569
+ const rawSource = styleBlocks.map((style) => style.source).join("\n");
1796
1570
  if (!rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
1797
1571
  debug("sfc style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
1798
1572
  return;
@@ -1801,7 +1575,7 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
1801
1575
  return {
1802
1576
  outputFile,
1803
1577
  rawSource,
1804
- sourceFile
1578
+ sourceFile: resolveSfcStyleHandlerSourceFile(sourceFile, styleBlocks)
1805
1579
  };
1806
1580
  }
1807
1581
  function normalizeSfcSourceFileForCompare(file) {
@@ -2003,6 +1777,13 @@ function collectMiniProgramSubpackageSourceEntries(snapshot, subpackageRoots, so
2003
1777
  //#endregion
2004
1778
  //#region src/bundlers/vite/processed-css-assets.ts
2005
1779
  const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
1780
+ function createCssAssetPipelineContext(options, file, bundle) {
1781
+ const context = options.createCssPipelineContext?.(file);
1782
+ return context ? {
1783
+ ...context,
1784
+ bundle
1785
+ } : void 0;
1786
+ }
2006
1787
  function isCssOutputFile(file) {
2007
1788
  return CSS_OUTPUT_FILE_RE.test(file);
2008
1789
  }
@@ -2177,14 +1958,17 @@ function removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, options =
2177
1958
  return removed;
2178
1959
  }
2179
1960
  const VUE_SCOPED_ATTR_RE = /\[data-v-[^\]]+\]/gi;
1961
+ const VUE_SCOPED_CLASS_RE = /\.data-v-[\w-]+/gi;
2180
1962
  function hasVueScopedAttr(value) {
2181
1963
  VUE_SCOPED_ATTR_RE.lastIndex = 0;
2182
- const matched = VUE_SCOPED_ATTR_RE.test(value);
1964
+ VUE_SCOPED_CLASS_RE.lastIndex = 0;
1965
+ const matched = VUE_SCOPED_ATTR_RE.test(value) || VUE_SCOPED_CLASS_RE.test(value);
2183
1966
  VUE_SCOPED_ATTR_RE.lastIndex = 0;
1967
+ VUE_SCOPED_CLASS_RE.lastIndex = 0;
2184
1968
  return matched;
2185
1969
  }
2186
1970
  function normalizeCssSignatureValue(value) {
2187
- return value.replace(VUE_SCOPED_ATTR_RE, "").replace(/\s+/g, " ").replace(/\s*([>+~])\s*/g, "$1").replace(/\(\s+/g, "(").replace(/\s+\)/g, ")").trim();
1971
+ return value.replace(VUE_SCOPED_ATTR_RE, "").replace(VUE_SCOPED_CLASS_RE, "").replace(/\s+/g, " ").replace(/\s*([>+~])\s*/g, "$1").replace(/\(\s+/g, "(").replace(/\s+\)/g, ")").trim();
2188
1972
  }
2189
1973
  function createDeclarationSignature(rule) {
2190
1974
  return createDeclarationKeys(rule).sort().join(";");
@@ -2211,6 +1995,33 @@ function isLikelyTailwindGlobalRule(rule) {
2211
1995
  function isLikelyTailwindPropertyAtRule(atRule) {
2212
1996
  return atRule.name.toLowerCase() === "property" && normalizeCssSignatureValue(atRule.params).startsWith("--tw-");
2213
1997
  }
1998
+ const MINI_PROGRAM_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
1999
+ "view",
2000
+ "text",
2001
+ "::after",
2002
+ "::before"
2003
+ ]);
2004
+ const MINI_PROGRAM_PREFLIGHT_DECLARATIONS = /* @__PURE__ */ new Set([
2005
+ "box-sizing",
2006
+ "margin",
2007
+ "padding",
2008
+ "border"
2009
+ ]);
2010
+ function isMiniProgramTailwindPreflightDeclaration(decl) {
2011
+ return decl.prop.startsWith("--tw-") || MINI_PROGRAM_PREFLIGHT_DECLARATIONS.has(decl.prop);
2012
+ }
2013
+ function isUnscopedMiniProgramTailwindPreflightRule(rule) {
2014
+ const selectors = rule.selectors ?? [rule.selector];
2015
+ if (selectors.length === 0 || !selectors.every((selector) => {
2016
+ const normalized = normalizeCssSignatureValue(selector);
2017
+ return !hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS.has(normalized);
2018
+ })) return false;
2019
+ const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
2020
+ return declarations.length > 0 && declarations.every(isMiniProgramTailwindPreflightDeclaration);
2021
+ }
2022
+ function hasUnscopedMiniProgramTailwindPreflightRule(css) {
2023
+ return /(?:^|[{}])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{/.test(css);
2024
+ }
2214
2025
  function collectRootScopedComparableCssCoverage(cssSources) {
2215
2026
  const rules = /* @__PURE__ */ new Set();
2216
2027
  const atRules = /* @__PURE__ */ new Set();
@@ -2252,8 +2063,9 @@ function isRuleCoveredByRootCss(rule, coverage) {
2252
2063
  function removeScopedCssCoveredByRootStyleSources(css, rootSources) {
2253
2064
  if (!hasVueScopedAttr(css)) return css;
2254
2065
  const hasScopedTailwindGeneratedCss = /tailwindcss v\d/i.test(css);
2066
+ const hasUnscopedMiniProgramPreflight = hasUnscopedMiniProgramTailwindPreflightRule(css);
2255
2067
  const coverage = collectRootScopedComparableCssCoverage(rootSources);
2256
- if (coverage.rules.size === 0 && coverage.atRules.size === 0 && !hasScopedTailwindGeneratedCss) return css;
2068
+ if (coverage.rules.size === 0 && coverage.atRules.size === 0 && !hasScopedTailwindGeneratedCss && !hasUnscopedMiniProgramPreflight) return css;
2257
2069
  try {
2258
2070
  const root = _weapp_tailwindcss_postcss.postcss.parse(css);
2259
2071
  let changed = false;
@@ -2264,7 +2076,7 @@ function removeScopedCssCoveredByRootStyleSources(css, rootSources) {
2264
2076
  }
2265
2077
  });
2266
2078
  root.walkRules((rule) => {
2267
- if (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule)) {
2079
+ if (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule) || isUnscopedMiniProgramTailwindPreflightRule(rule)) {
2268
2080
  rule.remove();
2269
2081
  changed = true;
2270
2082
  }
@@ -2363,11 +2175,17 @@ function isRootStyleOutputFile(file) {
2363
2175
  function isMiniProgramStyleOutputFile(file) {
2364
2176
  return /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
2365
2177
  }
2366
- function shouldPreserveMiniProgramImportShell(opts, file, css) {
2367
- return (opts.appType === "taro" || opts.appType === "uni-app-vite" || opts.appType === "uni-app-x") && isMiniProgramStyleOutputFile(file) && opts.cssMatcher(file) && (0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapper)(css);
2178
+ function shouldPreserveMiniProgramImportShell(options, bundle, file, css) {
2179
+ const context = createCssAssetPipelineContext(options, file, bundle);
2180
+ return context !== void 0 && options.cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
2181
+ ...context,
2182
+ css,
2183
+ file
2184
+ }) === true && isMiniProgramStyleOutputFile(file) && options.opts.cssMatcher(file) && (0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapper)(css);
2368
2185
  }
2369
- function resolvePreservedImportShellInjectionTarget(opts, bundle, file, css) {
2370
- if (opts.appType !== "taro") return;
2186
+ function resolvePreservedImportShellInjectionTarget(options, bundle, file, css) {
2187
+ const context = createCssAssetPipelineContext(options, file, bundle);
2188
+ if (context === void 0 || options.cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(context) !== true) return;
2371
2189
  const importedStyleFiles = collectImportedStyleFiles(css, file);
2372
2190
  if (importedStyleFiles.size !== 1) return;
2373
2191
  const [importedFile] = importedStyleFiles;
@@ -2379,15 +2197,25 @@ function resolvePreservedImportShellInjectionTarget(opts, bundle, file, css) {
2379
2197
  if (require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(importedFile)) return outputFile;
2380
2198
  }
2381
2199
  }
2382
- function shouldUseCssAssetAsMainInjectionTarget(opts, file, records) {
2200
+ function shouldUseCssAssetAsMainInjectionTarget(opts, file, records, options, bundle) {
2201
+ const context = createCssAssetPipelineContext(options, file, bundle);
2383
2202
  const fileKey = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
2384
2203
  if (!isRootStyleOutputFile(file) && records.some((record) => typeof record.outputFile === "string" && require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) === fileKey)) return true;
2385
2204
  if (!isRootStyleOutputFile(file)) return records.some((record) => record.injectIntoMain === true && typeof record.outputFile === "string" && require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) === fileKey);
2386
2205
  const matchedRootWebOutputTargets = records.map((record) => typeof record.outputFile === "string" ? require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) : void 0).filter((outputFile) => typeof outputFile === "string" && isRootStyleOutputFile(outputFile) && !isMiniProgramStyleOutputFile(outputFile)).filter((outputFile) => opts.mainCssChunkMatcher(outputFile, opts.appType));
2387
- if (opts.appType === "uni-app-vite" && !isMiniProgramStyleOutputFile(file) && matchedRootWebOutputTargets.length > 0) return matchedRootWebOutputTargets.includes(fileKey);
2206
+ if (context !== void 0 && options.cssPipelineStrategy?.shouldPreferMatchedRootWebOutputTarget?.({
2207
+ ...context,
2208
+ file,
2209
+ matchedRootWebOutputTargets
2210
+ }) === true && !isMiniProgramStyleOutputFile(file) && matchedRootWebOutputTargets.length > 0) return matchedRootWebOutputTargets.includes(fileKey);
2388
2211
  const explicitRootTargets = records.filter((record) => record.injectIntoMain === true).map((record) => typeof record.outputFile === "string" ? require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) : void 0).filter((outputFile) => typeof outputFile === "string" && isRootStyleOutputFile(outputFile) && !isMiniProgramStyleOutputFile(outputFile));
2389
2212
  const explicitWebCssTargets = records.filter((record) => record.injectIntoMain === true).map((record) => typeof record.outputFile === "string" ? require_source_candidate_scan_signature.normalizeOutputPathKey(record.outputFile) : void 0).filter((outputFile) => typeof outputFile === "string" && isCssOutputFile(outputFile) && !isMiniProgramStyleOutputFile(outputFile));
2390
- if (opts.appType === "uni-app-vite" && !isMiniProgramStyleOutputFile(file) && explicitWebCssTargets.length > 0) return explicitRootTargets.includes(fileKey);
2213
+ if (context !== void 0 && options.cssPipelineStrategy?.shouldPreferExplicitWebCssTargets?.({
2214
+ ...context,
2215
+ explicitRootTargets,
2216
+ explicitWebCssTargets,
2217
+ file
2218
+ }) === true && !isMiniProgramStyleOutputFile(file) && explicitWebCssTargets.length > 0) return explicitRootTargets.includes(fileKey);
2391
2219
  if (explicitRootTargets.length > 0) return explicitRootTargets.includes(fileKey);
2392
2220
  if (records.some((record) => {
2393
2221
  if (record.injectIntoMain !== true) return false;
@@ -2427,7 +2255,7 @@ function removeCoveredInjectedSourceAssets(bundle, targetFile, targetCss, record
2427
2255
  const isProcessedSource = candidateSource === record.css.trim() || candidateSource.length > 0 && (0, _weapp_tailwindcss_postcss.containsCssAfterMinify)(targetCss, candidateSource) || targetIsRootWebStyle && candidateIsRootWebStyle && candidateSource.length > 0 && !hasNonCommentCss(uncoveredCandidateSource);
2428
2256
  if (!isRecordFile && !isProcessedSource) continue;
2429
2257
  if (candidateIsRootWebStyle && !targetIsRootWebStyle) continue;
2430
- if (candidateIsRootWebStyle && !isRecordFile) continue;
2258
+ if (candidateIsRootWebStyle && !isRecordFile && !isProcessedSource) continue;
2431
2259
  if (candidateIsRootWebStyle) delete bundle[candidateFile];
2432
2260
  else clearAssetSource(candidateOutput);
2433
2261
  options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, targetFile);
@@ -2479,8 +2307,22 @@ function isConfiguredTailwindV4CssEntryFile(opts, file) {
2479
2307
  const fileKey = normalizeComparableStyleFile(file);
2480
2308
  return collectConfiguredTailwindV4CssEntryFiles(opts).some((entry) => normalizeComparableStyleFile(entry) === fileKey);
2481
2309
  }
2482
- function resolveUniAppViteWebviewRootCssInjectionTarget(bundle, opts, sourceFile, outputFile) {
2483
- if (opts.appType !== "uni-app-vite" || isMiniProgramStyleOutputFile(outputFile) || !isConfiguredTailwindV4CssEntryFile(opts, sourceFile)) return;
2310
+ function resolveConfiguredCssEntryRootInjectionTarget(bundle, options, sourceFile, outputFile) {
2311
+ const opts = options.opts;
2312
+ if (opts === void 0 || isMiniProgramStyleOutputFile(outputFile) || !isConfiguredTailwindV4CssEntryFile(opts, sourceFile)) return;
2313
+ const context = createCssAssetPipelineContext(options, outputFile, bundle);
2314
+ if (context === void 0) return;
2315
+ const resolvedByStrategy = options.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget?.({
2316
+ ...context,
2317
+ bundle,
2318
+ isConfiguredCssEntryFile: (file) => isConfiguredTailwindV4CssEntryFile(opts, file),
2319
+ isMiniProgramStyleOutputFile,
2320
+ isRootStyleOutputFile,
2321
+ outputFile,
2322
+ sourceFile
2323
+ });
2324
+ if (resolvedByStrategy !== void 0) return resolvedByStrategy;
2325
+ if (options.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget == null) return;
2484
2326
  const rootCssFiles = [];
2485
2327
  const matchedRootCssFiles = [];
2486
2328
  for (const [bundleFile, output] of Object.entries(bundle)) {
@@ -2547,7 +2389,7 @@ function collectViteProcessedCssAssetResults(bundle, options) {
2547
2389
  options.markCssAssetProcessed?.(output, file);
2548
2390
  options.recordCssAssetResult?.(file, nextCss);
2549
2391
  const resolvedOutputFile = resolveViteGeneratedCssMarkerOutputFile(file, singleMarkerFile, existingAssetFiles, options.resolveViteProcessedCssOutputFile);
2550
- const webviewRootCssInjectionTarget = options.opts ? resolveUniAppViteWebviewRootCssInjectionTarget(bundle, options.opts, singleMarkerFile ?? file, resolvedOutputFile) : void 0;
2392
+ const webviewRootCssInjectionTarget = options.opts ? resolveConfiguredCssEntryRootInjectionTarget(bundle, options, singleMarkerFile ?? file, resolvedOutputFile) : void 0;
2551
2393
  const recordOutputFile = webviewRootCssInjectionTarget ?? resolvedOutputFile;
2552
2394
  if (singleMarkerFile && require_source_candidate_scan_signature.normalizeOutputPathKey(resolvedOutputFile) !== require_source_candidate_scan_signature.normalizeOutputPathKey(file) && !isRootStyleOutputFile(resolvedOutputFile) && existingAssetFiles.has(require_source_candidate_scan_signature.normalizeOutputPathKey(resolvedOutputFile))) {
2553
2395
  const targetAsset = findBundleAssetByOutputFile(bundle, resolvedOutputFile);
@@ -2622,10 +2464,10 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
2622
2464
  if (bundle[bundleFile] !== bundleOutput) continue;
2623
2465
  if (output.type !== "asset") continue;
2624
2466
  let file = getAssetFile$1(bundleFile, output);
2625
- if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults)) continue;
2467
+ if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults, options, bundle)) continue;
2626
2468
  let originalSource = readAssetSource$2(output);
2627
- if (shouldPreserveMiniProgramImportShell(options.opts, file, originalSource)) {
2628
- const importedTargetFile = resolvePreservedImportShellInjectionTarget(options.opts, bundle, file, originalSource);
2469
+ if (shouldPreserveMiniProgramImportShell(options, bundle, file, originalSource)) {
2470
+ const importedTargetFile = resolvePreservedImportShellInjectionTarget(options, bundle, file, originalSource);
2629
2471
  if (typeof importedTargetFile === "string") {
2630
2472
  options.debug?.("preserve mini-program css import shell asset: %s -> %s", file, importedTargetFile);
2631
2473
  const importedOutput = Object.entries(bundle).find(([candidateFile, candidate]) => candidate.type === "asset" && require_source_candidate_scan_signature.normalizeOutputPathKey(getAssetFile$1(candidateFile, candidate)) === require_source_candidate_scan_signature.normalizeOutputPathKey(importedTargetFile))?.[1];
@@ -2972,17 +2814,10 @@ function pruneLastCssResults(resultByFile, sourceHashByFile, activeFiles) {
2972
2814
  function readAssetSource(asset) {
2973
2815
  return typeof asset.source === "string" ? asset.source : asset.source.toString();
2974
2816
  }
2975
- function isUniAppViteWebviewAppBundle(bundleFiles) {
2976
- return bundleFiles.some((file) => node_path.default.basename(file.replace(/[?#].*$/, "")) === "app-service.js");
2977
- }
2978
- function isUniAppViteWebviewOutDir$2(outDir) {
2979
- const normalized = outDir ? node_path.default.basename(node_path.default.normalize(outDir)).trim().toLowerCase() : void 0;
2980
- return normalized === "app" || normalized === "app-plus";
2981
- }
2982
2817
  function getAssetFile(bundleFile, asset) {
2983
2818
  return asset.fileName || bundleFile;
2984
2819
  }
2985
- function finalizeUniAppViteWebviewCssCompat(bundle, options) {
2820
+ function finalizeWebviewCssCompat(bundle, options) {
2986
2821
  if (options.opts.generator?.webCompat === false) return 0;
2987
2822
  let transformed = 0;
2988
2823
  for (const [bundleFile, output] of Object.entries(bundle)) {
@@ -2995,7 +2830,7 @@ function finalizeUniAppViteWebviewCssCompat(bundle, options) {
2995
2830
  output.source = nextCss;
2996
2831
  options.recordCssAssetResult?.(file, nextCss);
2997
2832
  options.onUpdate(file, rawSource, nextCss);
2998
- options.debug("finalize uni-app vite webview css compat: %s bytes=%d", file, nextCss.length);
2833
+ options.debug("finalize webview css compat: %s bytes=%d", file, nextCss.length);
2999
2834
  transformed++;
3000
2835
  }
3001
2836
  return transformed;
@@ -3036,8 +2871,8 @@ function resolveSingleCssImportOutputFile(targetFile, css) {
3036
2871
  } catch {}
3037
2872
  return importedFile;
3038
2873
  }
3039
- function normalizeTaroRootImportShellAssets(bundle, options) {
3040
- if (options.appType !== "taro") return 0;
2874
+ function normalizeRootMiniProgramImportShellAssets(bundle, options) {
2875
+ if (!options.enabled) return 0;
3041
2876
  let updated = 0;
3042
2877
  for (const [rootBundleFile, rootOutput] of Object.entries(bundle)) {
3043
2878
  if (rootOutput.type !== "asset") continue;
@@ -3048,6 +2883,17 @@ function normalizeTaroRootImportShellAssets(bundle, options) {
3048
2883
  const originOutput = Object.entries(bundle).find(([bundleFile, output]) => output.type === "asset" && require_source_candidate_scan_signature.normalizeOutputPathKey(getAssetFile(bundleFile, output)) === require_source_candidate_scan_signature.normalizeOutputPathKey(originFile))?.[1];
3049
2884
  if (originOutput?.type !== "asset") continue;
3050
2885
  const rootSource = readAssetSource(rootOutput);
2886
+ const importedRootFile = resolveSingleCssImportOutputFile(rootFile, rootSource);
2887
+ if (importedRootFile && require_source_candidate_scan_signature.normalizeOutputPathKey(importedRootFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(originFile)) {
2888
+ const nextRootSource = createCssImportShell(rootFile, originFile);
2889
+ if (rootSource === nextRootSource) continue;
2890
+ rootOutput.source = nextRootSource;
2891
+ options.recordCssAssetResult?.(rootFile, nextRootSource);
2892
+ options.onUpdate?.(rootFile, rootSource, nextRootSource);
2893
+ options.debug("normalize root css import shell request: %s -> %s", rootFile, originFile);
2894
+ updated++;
2895
+ continue;
2896
+ }
3051
2897
  if ((0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapper)(rootSource)) continue;
3052
2898
  const originSource = readAssetSource(originOutput);
3053
2899
  if ((0, _weapp_tailwindcss_postcss.isPureLocalCssImportWrapper)(originSource)) {
@@ -3062,13 +2908,13 @@ function normalizeTaroRootImportShellAssets(bundle, options) {
3062
2908
  options.recordCssAssetResult?.(originFile, rootSource);
3063
2909
  options.onUpdate?.(rootFile, rootSource, nextRootSource);
3064
2910
  options.onUpdate?.(originFile, originSource, rootSource);
3065
- options.debug("normalize taro root css import shell: %s -> %s", rootFile, originFile);
2911
+ options.debug("normalize root css import shell: %s -> %s", rootFile, originFile);
3066
2912
  updated++;
3067
2913
  }
3068
2914
  return updated;
3069
2915
  }
3070
2916
  async function finalizeGenerateBundle(options) {
3071
- const { activeProcessCacheKeys, activeProcessHashKeys, activeViteCssCacheFiles, bundle, bundleFiles, cache, cssTaskFactories, debug, defaultStyleOutputExtension, formatIteration, generatorCandidateSignature, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteCssCacheStats, getViteProcessedCssAssetResults, hmrTimingRecorder, hmrTimingStartedAt, isHarmonyAppStyleTarget, isNativeAppStyleTarget, isViteProcessedCssAsset, isWebGeneratorTarget, jsAfterCss, jsTaskFactories, lastCssResultByFile, lastCssSourceHashByFile, linkedByEntry, markCssAssetProcessed, metrics, onEnd, onUpdate, opts, outDir, pendingLinkedUpdates, pruneViteCssCaches, recordCssAssetResult, recordTimingDetail, recordViteProcessedCssAssetResult, rootDir, runtime, runtimeState, shouldPreserveAppCssExtension, snapshot, sourceCandidates, sourceRoot, state, styleHandler, tasks, timingDetails, transformRuntime, transformWebTargetCss, useIncrementalMode } = options;
2917
+ const { activeProcessCacheKeys, activeProcessHashKeys, activeViteCssCacheFiles, bundle, bundleFiles, cache, cssTaskFactories, cssPipelineStrategy, createCssPipelineContext, debug, defaultStyleOutputExtension, formatIteration, generatorCandidateSignature, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteCssCacheStats, getViteProcessedCssAssetResults, hmrTimingRecorder, hmrTimingStartedAt, isHarmonyAppStyleTarget, isNativeAppStyleTarget, isViteProcessedCssAsset, isWebGeneratorTarget, jsAfterCss, jsTaskFactories, lastCssResultByFile, lastCssSourceHashByFile, linkedByEntry, markCssAssetProcessed, metrics, onEnd, onUpdate, opts, outDir, pendingLinkedUpdates, pruneViteCssCaches, recordCssAssetResult, recordTimingDetail, recordViteProcessedCssAssetResult, rootDir, runtime, runtimeState, shouldPreserveAppCssExtension, snapshot, sourceCandidates, sourceRoot, state, styleHandler, tasks, timingDetails, transformRuntime, transformWebTargetCss, useIncrementalMode } = options;
3072
2918
  const tasksStart = performance.now();
3073
2919
  if (cssTaskFactories.length > 0) {
3074
2920
  const cssTask = require_hmr_timing.runWithConcurrency(cssTaskFactories, resolveViteCssTaskConcurrency(useIncrementalMode, runtimeState.tailwindRuntime.majorVersion)).then(() => void 0);
@@ -3097,6 +2943,8 @@ async function finalizeGenerateBundle(options) {
3097
2943
  const syncViteProcessedCssIntoMainCssAssets = () => {
3098
2944
  collectViteProcessedCssAssetResults(bundle, {
3099
2945
  opts,
2946
+ cssPipelineStrategy,
2947
+ createCssPipelineContext,
3100
2948
  isViteProcessedCssAsset,
3101
2949
  markCssAssetProcessed,
3102
2950
  recordCssAssetResult,
@@ -3108,6 +2956,8 @@ async function finalizeGenerateBundle(options) {
3108
2956
  });
3109
2957
  return injectViteProcessedCssIntoMainCssAssets(bundle, {
3110
2958
  opts,
2959
+ cssPipelineStrategy,
2960
+ createCssPipelineContext,
3111
2961
  getViteProcessedCssAssetResults,
3112
2962
  markCssAssetProcessed,
3113
2963
  recordCssAssetResult,
@@ -3126,10 +2976,12 @@ async function finalizeGenerateBundle(options) {
3126
2976
  if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css) })) debug("uni-app-x harmony bundle styles inject after css assets");
3127
2977
  syncViteProcessedCssIntoMainCssAssets();
3128
2978
  }
3129
- normalizeTaroRootImportShellAssets(bundle, {
3130
- appType: opts.appType,
2979
+ const createFinalizeCssPipelineContext = (file = "") => createCssPipelineContext?.(file);
2980
+ const finalizeCssPipelineContext = createFinalizeCssPipelineContext();
2981
+ normalizeRootMiniProgramImportShellAssets(bundle, {
3131
2982
  cssMatcher: opts.cssMatcher,
3132
2983
  debug,
2984
+ enabled: finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(finalizeCssPipelineContext) === true,
3133
2985
  onUpdate,
3134
2986
  recordCssAssetResult
3135
2987
  });
@@ -3137,13 +2989,23 @@ async function finalizeGenerateBundle(options) {
3137
2989
  removeCssCoveredByRootStyleAssets(bundle, {
3138
2990
  cssMatcher: opts.cssMatcher,
3139
2991
  debug,
3140
- includeTailwindGeneratedCssAssets: opts.appType === "uni-app-vite" && isWebGeneratorTarget && isUniAppViteWebviewAppBundle(bundleFiles),
2992
+ includeTailwindGeneratedCssAssets: finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.includeTailwindGeneratedCssAssetsInRootCoverage?.({
2993
+ ...finalizeCssPipelineContext,
2994
+ bundleFiles,
2995
+ isWebGeneratorTarget,
2996
+ outDir
2997
+ }) === true,
3141
2998
  isViteProcessedCssAsset,
3142
2999
  onUpdate,
3143
3000
  recordCssAssetResult,
3144
3001
  subpackageRoots: collectMiniProgramSubpackageRoots(bundle)
3145
3002
  });
3146
- if (opts.appType === "uni-app-vite" && isWebGeneratorTarget && isUniAppViteWebviewAppBundle(Object.keys(bundle))) removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, { debug });
3003
+ if (finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.shouldRemoveDuplicateUnlinkedRootCssAssetsReferencedByHtml?.({
3004
+ ...finalizeCssPipelineContext,
3005
+ bundleFiles: Object.keys(bundle),
3006
+ isWebGeneratorTarget,
3007
+ outDir
3008
+ }) === true) removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, { debug });
3147
3009
  await finalizeMiniProgramCssAssets(bundle, {
3148
3010
  cssMatcher: opts.cssMatcher,
3149
3011
  debug,
@@ -3154,7 +3016,12 @@ async function finalizeGenerateBundle(options) {
3154
3016
  recordCssAssetResult,
3155
3017
  styleHandler
3156
3018
  });
3157
- if (opts.appType === "uni-app-vite" && (isWebGeneratorTarget || isUniAppViteWebviewAppBundle(Object.keys(bundle)) || isUniAppViteWebviewOutDir$2(outDir))) finalizeUniAppViteWebviewCssCompat(bundle, {
3019
+ if (finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.shouldApplyFinalWebviewCssCompat?.({
3020
+ ...finalizeCssPipelineContext,
3021
+ bundleFiles: Object.keys(bundle),
3022
+ isWebGeneratorTarget,
3023
+ outDir
3024
+ }) === true) finalizeWebviewCssCompat(bundle, {
3158
3025
  debug,
3159
3026
  onUpdate,
3160
3027
  opts,
@@ -3204,173 +3071,460 @@ async function finalizeGenerateBundle(options) {
3204
3071
  onEnd();
3205
3072
  debug("end");
3206
3073
  }
3207
- //#endregion
3208
- //#region src/bundlers/vite/generate-bundle/candidates.ts
3209
- const MUSTACHE_EXPRESSION_RE = /\{\{[\s\S]*?\}\}/g;
3210
- const QUOTED_LITERAL_RE = /'([^']*)'|"([^"]*)"|`([^`]*)`/g;
3211
- const CLASS_ATTRIBUTE_RE = /\bclass\s*=\s*/g;
3212
- const MUSTACHE_OPEN = "{{";
3213
- const MUSTACHE_CLOSE = "}}";
3214
- function isUrlLikeCandidate(candidate) {
3215
- return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
3074
+ //#endregion
3075
+ //#region src/bundlers/vite/generate-bundle/candidates.ts
3076
+ const MUSTACHE_EXPRESSION_RE = /\{\{[\s\S]*?\}\}/g;
3077
+ const QUOTED_LITERAL_RE = /'([^']*)'|"([^"]*)"|`([^`]*)`/g;
3078
+ const CLASS_ATTRIBUTE_RE = /\bclass\s*=\s*/g;
3079
+ const MUSTACHE_OPEN = "{{";
3080
+ const MUSTACHE_CLOSE = "}}";
3081
+ function isUrlLikeCandidate(candidate) {
3082
+ return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
3083
+ }
3084
+ function isArbitraryValueCandidate(candidate) {
3085
+ return candidate.includes("[") && candidate.includes("]") && !isUrlLikeCandidate(candidate.trim());
3086
+ }
3087
+ function collectClassAttributeValues(source) {
3088
+ const values = [];
3089
+ CLASS_ATTRIBUTE_RE.lastIndex = 0;
3090
+ let matched = CLASS_ATTRIBUTE_RE.exec(source);
3091
+ while (matched !== null) {
3092
+ const quoteIndex = CLASS_ATTRIBUTE_RE.lastIndex;
3093
+ const quote = source[quoteIndex];
3094
+ if (quote !== "\"" && quote !== "'") {
3095
+ matched = CLASS_ATTRIBUTE_RE.exec(source);
3096
+ continue;
3097
+ }
3098
+ let expressionDepth = 0;
3099
+ for (let index = quoteIndex + 1; index < source.length; index++) {
3100
+ if (source.startsWith(MUSTACHE_OPEN, index)) {
3101
+ expressionDepth++;
3102
+ index += 1;
3103
+ continue;
3104
+ }
3105
+ if (expressionDepth > 0 && source.startsWith(MUSTACHE_CLOSE, index)) {
3106
+ expressionDepth--;
3107
+ index += 1;
3108
+ continue;
3109
+ }
3110
+ if (expressionDepth === 0 && source[index] === quote) {
3111
+ values.push(source.slice(quoteIndex + 1, index));
3112
+ CLASS_ATTRIBUTE_RE.lastIndex = index + 1;
3113
+ break;
3114
+ }
3115
+ }
3116
+ matched = CLASS_ATTRIBUTE_RE.exec(source);
3117
+ }
3118
+ return values;
3119
+ }
3120
+ function collectUnescapedDynamicCandidates(source, allowedCandidates) {
3121
+ const matches = /* @__PURE__ */ new Set();
3122
+ const shouldFilterByAllowedCandidates = allowedCandidates !== void 0 && allowedCandidates.size > 0;
3123
+ for (const classValue of collectClassAttributeValues(source)) for (const expression of classValue.match(MUSTACHE_EXPRESSION_RE) ?? []) {
3124
+ QUOTED_LITERAL_RE.lastIndex = 0;
3125
+ let quoted = QUOTED_LITERAL_RE.exec(expression);
3126
+ while (quoted !== null) {
3127
+ const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
3128
+ for (const candidate of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(literal)) {
3129
+ const normalized = candidate.trim();
3130
+ if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
3131
+ if (shouldFilterByAllowedCandidates && !allowedCandidates.has(normalized)) continue;
3132
+ matches.add(normalized);
3133
+ }
3134
+ quoted = QUOTED_LITERAL_RE.exec(expression);
3135
+ }
3136
+ }
3137
+ return [...matches];
3138
+ }
3139
+ //#endregion
3140
+ //#region src/bundlers/vite/generate-bundle/html-processing.ts
3141
+ function processHtmlBundleEntry(options) {
3142
+ const { cache, context, debug, dynamicRetryCandidates, file, metrics, onUpdate, originalEntrySource, originalSource, rememberProcessCacheKey, resolveCurrentSourceCandidateSource, tasks, templateHandler, timeTask, transformRuntime, transformRuntimeSignature } = options;
3143
+ const rawSource = resolveCurrentSourceCandidateSource(file) ?? originalEntrySource;
3144
+ const currentRawDynamicCandidates = collectUnescapedDynamicCandidates(rawSource);
3145
+ const templateRuntime = currentRawDynamicCandidates.length > 0 ? /* @__PURE__ */ new Set([...transformRuntime, ...currentRawDynamicCandidates]) : transformRuntime;
3146
+ const templateRuntimeSignature = templateRuntime === transformRuntime ? transformRuntimeSignature : require_source_candidate_scan_signature.createCandidateSignature(templateRuntime);
3147
+ const htmlProcessHash = `${cache.computeHash(rawSource)}:${cache.computeHash(require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(rawSource, "html"))}:${templateRuntimeSignature}`;
3148
+ const cacheKey = `${file}:html:${htmlProcessHash}`;
3149
+ const hashKey = cacheKey;
3150
+ rememberProcessCacheKey(cacheKey, hashKey);
3151
+ tasks.push(timeTask("html", () => require_hmr_timing.processCachedTask({
3152
+ cache,
3153
+ cacheKey,
3154
+ hashKey,
3155
+ hash: htmlProcessHash,
3156
+ applyResult(source) {
3157
+ originalSource.source = source;
3158
+ },
3159
+ onCacheHit() {
3160
+ metrics.html.cacheHits++;
3161
+ debug("html cache hit: %s", file);
3162
+ },
3163
+ async transform() {
3164
+ const start = performance.now();
3165
+ let transformed = await templateHandler(rawSource, { runtimeSet: templateRuntime });
3166
+ let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
3167
+ let retryRuntimeSet;
3168
+ if (unresolvedDynamicCandidates.length > 0) {
3169
+ const fullRuntimeSet = await context.ensureRuntimeClassSet(true);
3170
+ const allowedRetryCandidates = fullRuntimeSet.size === 0 ? unresolvedDynamicCandidates : unresolvedDynamicCandidates.filter((candidate) => dynamicRetryCandidates.has(candidate) || fullRuntimeSet.has(candidate));
3171
+ retryRuntimeSet = /* @__PURE__ */ new Set([...fullRuntimeSet, ...allowedRetryCandidates]);
3172
+ unresolvedDynamicCandidates = unresolvedDynamicCandidates.filter((candidate) => retryRuntimeSet?.has(candidate) === true);
3173
+ }
3174
+ if (retryRuntimeSet && unresolvedDynamicCandidates.length > 0) {
3175
+ _weapp_tailwindcss_logger.logger.warn("检测到已提取 WXML 动态类名未完成转译,已回退到完整 runtimeSet 重试: %s -> %O", file, unresolvedDynamicCandidates);
3176
+ transformed = await templateHandler(rawSource, { runtimeSet: retryRuntimeSet });
3177
+ unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed, retryRuntimeSet);
3178
+ if (unresolvedDynamicCandidates.length > 0) _weapp_tailwindcss_logger.logger.warn("已提取 WXML 动态类名在完整 runtimeSet 重试后仍未完成转译: %s -> %O", file, unresolvedDynamicCandidates);
3179
+ }
3180
+ metrics.html.elapsed += measureElapsed(start);
3181
+ metrics.html.transformed++;
3182
+ onUpdate(file, rawSource, transformed);
3183
+ debug("html handle: %s", file);
3184
+ return { result: transformed };
3185
+ }
3186
+ })));
3187
+ }
3188
+ //#endregion
3189
+ //#region src/bundlers/vite/generate-bundle/js-entries.ts
3190
+ function createJsEntryResolver(jsEntries) {
3191
+ const normalizedJsEntries = /* @__PURE__ */ new Map();
3192
+ for (const [id, entry] of jsEntries) normalizedJsEntries.set(require_source_candidate_scan_signature.normalizeOutputPathKey(id), entry);
3193
+ return (id) => jsEntries.get(id) ?? normalizedJsEntries.get(require_source_candidate_scan_signature.normalizeOutputPathKey(id));
3194
+ }
3195
+ //#endregion
3196
+ //#region src/bundlers/vite/generate-bundle/js-handler-options.ts
3197
+ function resolveUniAppXJsTransformEnabled$1(uniAppX) {
3198
+ return uniAppX === void 0 ? true : require_tailwindcss.isUniAppXEnabled(uniAppX);
3199
+ }
3200
+ function createJsHandlerOptionsFactory(options) {
3201
+ return (absoluteFilename, extra) => ({
3202
+ ...extra,
3203
+ generateMap: false,
3204
+ filename: absoluteFilename,
3205
+ tailwindcssMajorVersion: options.getMajorVersion(),
3206
+ moduleGraph: options.moduleGraph,
3207
+ babelParserOptions: {
3208
+ ...extra?.babelParserOptions ?? {},
3209
+ sourceFilename: absoluteFilename
3210
+ }
3211
+ });
3212
+ }
3213
+ //#endregion
3214
+ //#region src/bundlers/vite/generate-bundle/js-linking.ts
3215
+ function createLinkedUpdateHelpers(options) {
3216
+ const pendingLinkedUpdates = [];
3217
+ const handleLinkedUpdate = (fileName, previous, next) => {
3218
+ options.onUpdate(fileName, previous, next);
3219
+ options.debug("js linked handle: %s", fileName);
3220
+ };
3221
+ const scheduleLinkedApply = (entry, code) => {
3222
+ pendingLinkedUpdates.push(() => {
3223
+ if (entry.output.type === "chunk") entry.output.code = code;
3224
+ else entry.output.source = code;
3225
+ });
3226
+ };
3227
+ const applyLinkedUpdates = (linked) => {
3228
+ require_source_candidate_scan_signature.applyLinkedResults(linked, options.jsEntries, handleLinkedUpdate, scheduleLinkedApply);
3229
+ };
3230
+ return {
3231
+ applyLinkedUpdates,
3232
+ pendingLinkedUpdates
3233
+ };
3234
+ }
3235
+ function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
3236
+ if (!linked || !linkedSet) return;
3237
+ for (const id of Object.keys(linked)) {
3238
+ const linkedEntry = getJsEntry(id);
3239
+ if (linkedEntry) linkedSet.add(linkedEntry.fileName);
3240
+ }
3241
+ }
3242
+ //#endregion
3243
+ //#region src/bundlers/vite/query.ts
3244
+ function parseVueRequest(id) {
3245
+ const [filename = id, rawQuery] = id.split(`?`, 2);
3246
+ const searchParams = new URLSearchParams(rawQuery);
3247
+ const query = Object.fromEntries(searchParams);
3248
+ if (query.vue != null) query.vue = true;
3249
+ if (query.index != null) query.index = Number(query.index);
3250
+ if (query.raw != null) query.raw = true;
3251
+ if (query.url != null) query.url = true;
3252
+ if (query.scoped != null) query.scoped = true;
3253
+ const langTypeMatch = [...searchParams.keys()].find((key) => key.startsWith("lang."));
3254
+ const langType = query.lang || (langTypeMatch ? langTypeMatch.slice(5) : void 0);
3255
+ if (langType) query.lang = langType;
3256
+ return {
3257
+ filename,
3258
+ query
3259
+ };
3260
+ }
3261
+ //#endregion
3262
+ //#region src/uni-app-x/harmony.ts
3263
+ function isUniAppXHarmonyOutDir(outDir) {
3264
+ return typeof outDir === "string" && /(?:^|[/\\])\.?app-harmony(?:[/\\]|$)/.test(outDir);
3265
+ }
3266
+ //#endregion
3267
+ //#region src/uni-app-x/style-isolation.ts
3268
+ const manifestCache = /* @__PURE__ */ new Map();
3269
+ function resolveUniAppXStyleIsolationEnabled(root) {
3270
+ if (!root) return false;
3271
+ const normalizedRoot = node_path.default.resolve(root);
3272
+ const cached = manifestCache.get(normalizedRoot);
3273
+ if (cached !== void 0) return cached;
3274
+ const manifestPath = node_path.default.join(normalizedRoot, "manifest.json");
3275
+ let enabled = false;
3276
+ try {
3277
+ enabled = `${(0, comment_json.parse)(node_fs.default.readFileSync(manifestPath, "utf8"))["uni-app-x"]?.styleIsolationVersion ?? ""}` === "2";
3278
+ } catch {
3279
+ enabled = false;
3280
+ }
3281
+ manifestCache.set(normalizedRoot, enabled);
3282
+ return enabled;
3283
+ }
3284
+ //#endregion
3285
+ //#region src/uni-app-x/vite.ts
3286
+ let transformUVuePromise;
3287
+ function loadTransformUVue() {
3288
+ transformUVuePromise ?? (transformUVuePromise = Promise.resolve().then(() => require("./transform-B0BxX3XB.js")).then((mod) => mod.transformUVue));
3289
+ return transformUVuePromise;
3290
+ }
3291
+ const preprocessorLangs = /* @__PURE__ */ new Set([
3292
+ "scss",
3293
+ "sass",
3294
+ "less",
3295
+ "styl",
3296
+ "stylus"
3297
+ ]);
3298
+ const INLINE_LANG_RE = /lang\.([a-z]+)/i;
3299
+ const PREPROCESSOR_EXT_RE = /\.(?:scss|sass|less|styl|stylus)(?:\?|$)/i;
3300
+ const UVUE_NVUE_QUERY_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
3301
+ const UVUE_NVUE_RE = /\.(?:uvue|nvue)$/;
3302
+ const CSS_MODULE_EXPORT_RE = /^\s*export\s+default\s+(?:\{|\w|\[\])/;
3303
+ function isPreprocessorRequest(id, lang) {
3304
+ const normalizedLang = lang?.toLowerCase();
3305
+ if (normalizedLang && preprocessorLangs.has(normalizedLang)) return true;
3306
+ const inlineLang = id.match(INLINE_LANG_RE)?.[1];
3307
+ if (inlineLang && preprocessorLangs.has(inlineLang.toLowerCase())) return true;
3308
+ return PREPROCESSOR_EXT_RE.test(id);
3309
+ }
3310
+ function resolveUniAppXCssTarget(id) {
3311
+ return UVUE_NVUE_RE.test((0, _weapp_tailwindcss_shared.cleanUrl)(id)) ? "uvue" : void 0;
3216
3312
  }
3217
- function isArbitraryValueCandidate(candidate) {
3218
- return candidate.includes("[") && candidate.includes("]") && !isUrlLikeCandidate(candidate.trim());
3313
+ function resolveUniAppXJsTransformEnabled(uniAppX) {
3314
+ return uniAppX === void 0 ? true : require_tailwindcss.isUniAppXEnabled(uniAppX);
3219
3315
  }
3220
- function collectClassAttributeValues(source) {
3221
- const values = [];
3222
- CLASS_ATTRIBUTE_RE.lastIndex = 0;
3223
- let matched = CLASS_ATTRIBUTE_RE.exec(source);
3224
- while (matched !== null) {
3225
- const quoteIndex = CLASS_ATTRIBUTE_RE.lastIndex;
3226
- const quote = source[quoteIndex];
3227
- if (quote !== "\"" && quote !== "'") {
3228
- matched = CLASS_ATTRIBUTE_RE.exec(source);
3229
- continue;
3316
+ function isCssModuleExport(code) {
3317
+ return CSS_MODULE_EXPORT_RE.test(code);
3318
+ }
3319
+ function createUniAppXPlugins(options) {
3320
+ const { appType, customAttributesEntities, disabledDefaultTemplateHandler, isIosPlatform: providedIosPlatform, mainCssChunkMatcher, runtimeState, styleHandler, generateCss, jsHandler, ensureRuntimeClassSet, getResolvedConfig, isEnabled = () => true, uniAppX } = options;
3321
+ const resolvedUniAppXOptions = require_tailwindcss.resolveUniAppXOptions(uniAppX);
3322
+ const utsPlatform = require_utils.resolveUniUtsPlatform();
3323
+ const isIosPlatform = providedIosPlatform ?? utsPlatform.isAppIos;
3324
+ const isHarmonyPlatform = utsPlatform.isAppHarmony;
3325
+ const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
3326
+ let componentLocalStyleEnabled;
3327
+ const harmonyApplyStyleSources = /* @__PURE__ */ new Set();
3328
+ const harmonyApplyUtilities = /* @__PURE__ */ new Set();
3329
+ function rememberHarmonyApplySource(code) {
3330
+ const styleSources = collectUniAppXHarmonyApplyStyleSourcesFromSource(code);
3331
+ if (styleSources.length === 0) return;
3332
+ for (const styleSource of styleSources) {
3333
+ harmonyApplyStyleSources.add(styleSource);
3334
+ for (const utility of collectUniAppXHarmonyApplyUtilitiesFromSources([styleSource])) harmonyApplyUtilities.add(utility);
3230
3335
  }
3231
- let expressionDepth = 0;
3232
- for (let index = quoteIndex + 1; index < source.length; index++) {
3233
- if (source.startsWith(MUSTACHE_OPEN, index)) {
3234
- expressionDepth++;
3235
- index += 1;
3236
- continue;
3237
- }
3238
- if (expressionDepth > 0 && source.startsWith(MUSTACHE_CLOSE, index)) {
3239
- expressionDepth--;
3240
- index += 1;
3241
- continue;
3242
- }
3243
- if (expressionDepth === 0 && source[index] === quote) {
3244
- values.push(source.slice(quoteIndex + 1, index));
3245
- CLASS_ATTRIBUTE_RE.lastIndex = index + 1;
3246
- break;
3247
- }
3336
+ }
3337
+ function shouldEnableComponentLocalStyle() {
3338
+ if (!resolvedUniAppXOptions.componentLocalStyles.enabled) {
3339
+ componentLocalStyleEnabled = false;
3340
+ return false;
3248
3341
  }
3249
- matched = CLASS_ATTRIBUTE_RE.exec(source);
3342
+ if (!resolvedUniAppXOptions.componentLocalStyles.onlyWhenStyleIsolationVersion2) {
3343
+ componentLocalStyleEnabled = true;
3344
+ return true;
3345
+ }
3346
+ if (componentLocalStyleEnabled !== void 0) return componentLocalStyleEnabled;
3347
+ const root = getResolvedConfig()?.root;
3348
+ componentLocalStyleEnabled = resolveUniAppXStyleIsolationEnabled(root);
3349
+ return componentLocalStyleEnabled;
3250
3350
  }
3251
- return values;
3252
- }
3253
- function collectUnescapedDynamicCandidates(source, allowedCandidates) {
3254
- const matches = /* @__PURE__ */ new Set();
3255
- const shouldFilterByAllowedCandidates = allowedCandidates !== void 0 && allowedCandidates.size > 0;
3256
- for (const classValue of collectClassAttributeValues(source)) for (const expression of classValue.match(MUSTACHE_EXPRESSION_RE) ?? []) {
3257
- QUOTED_LITERAL_RE.lastIndex = 0;
3258
- let quoted = QUOTED_LITERAL_RE.exec(expression);
3259
- while (quoted !== null) {
3260
- const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
3261
- for (const candidate of (0, _tailwindcss_mangle_engine.splitCandidateTokens)(literal)) {
3262
- const normalized = candidate.trim();
3263
- if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
3264
- if (shouldFilterByAllowedCandidates && !allowedCandidates.has(normalized)) continue;
3265
- matches.add(normalized);
3351
+ function shouldEnableHarmonyPageLocalStyle() {
3352
+ return isHarmonyPlatform && resolvedUniAppXOptions.componentLocalStyles.enabled;
3353
+ }
3354
+ function isHarmonyBuildTarget() {
3355
+ if (require_utils.resolveUniUtsPlatform().isAppHarmony) return true;
3356
+ return isUniAppXHarmonyOutDir(getResolvedConfig()?.build?.outDir);
3357
+ }
3358
+ async function transformStyle(code, id, query, hookContext) {
3359
+ const parsed = query ?? parseVueRequest(id).query;
3360
+ if (require_source_candidate_scan_signature.isCSSRequest(id) || parsed.vue && parsed.type === "style") {
3361
+ if (isCssModuleExport(code)) return;
3362
+ const shouldGenerateCss = require_v4_engine.hasTailwindSourceDirectives(code, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(code);
3363
+ rememberHarmonyApplySource(code);
3364
+ const generatedCss = shouldGenerateCss ? await generateCss?.(id, code, hookContext) : void 0;
3365
+ const styleCode = typeof generatedCss === "string" && generatedCss.trim().length > 0 ? generatedCss : code;
3366
+ const cacheKey = `${mainCssChunkMatcher(id, appType) ? "1" : "0"}:${id}`;
3367
+ let styleHandlerOptions = cssHandlerOptionsCache.get(cacheKey);
3368
+ if (!styleHandlerOptions) {
3369
+ styleHandlerOptions = require_v4_engine.omitUndefined({
3370
+ isMainChunk: mainCssChunkMatcher(id, appType),
3371
+ uniAppXCssTarget: resolveUniAppXCssTarget(id),
3372
+ uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
3373
+ postcssOptions: { options: {
3374
+ from: id,
3375
+ map: {
3376
+ inline: false,
3377
+ annotation: false,
3378
+ sourcesContent: true
3379
+ }
3380
+ } }
3381
+ });
3382
+ cssHandlerOptionsCache.set(cacheKey, styleHandlerOptions);
3266
3383
  }
3267
- quoted = QUOTED_LITERAL_RE.exec(expression);
3384
+ const postcssResult = await styleHandler(styleCode, styleHandlerOptions);
3385
+ const warnings = typeof postcssResult.warnings === "function" ? postcssResult.warnings() : [];
3386
+ for (const warning of warnings) _weapp_tailwindcss_logger.logger.warn(warning.toString());
3387
+ const postcssMap = await require_source_candidate_scan_signature.formatPostcssSourceMap(postcssResult.map.toJSON(), require_source_candidate_scan_signature.normalizePath((0, _weapp_tailwindcss_shared.cleanUrl)(id)));
3388
+ return {
3389
+ code: postcssResult.css,
3390
+ map: postcssMap
3391
+ };
3268
3392
  }
3269
3393
  }
3270
- return [...matches];
3271
- }
3272
- //#endregion
3273
- //#region src/bundlers/vite/generate-bundle/html-processing.ts
3274
- function processHtmlBundleEntry(options) {
3275
- const { cache, context, debug, dynamicRetryCandidates, file, metrics, onUpdate, originalEntrySource, originalSource, rememberProcessCacheKey, resolveCurrentSourceCandidateSource, tasks, templateHandler, timeTask, transformRuntime, transformRuntimeSignature } = options;
3276
- const rawSource = resolveCurrentSourceCandidateSource(file) ?? originalEntrySource;
3277
- const currentRawDynamicCandidates = collectUnescapedDynamicCandidates(rawSource);
3278
- const templateRuntime = currentRawDynamicCandidates.length > 0 ? /* @__PURE__ */ new Set([...transformRuntime, ...currentRawDynamicCandidates]) : transformRuntime;
3279
- const templateRuntimeSignature = templateRuntime === transformRuntime ? transformRuntimeSignature : require_source_candidate_scan_signature.createCandidateSignature(templateRuntime);
3280
- const htmlProcessHash = `${cache.computeHash(rawSource)}:${cache.computeHash(require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(rawSource, "html"))}:${templateRuntimeSignature}`;
3281
- const cacheKey = `${file}:html:${htmlProcessHash}`;
3282
- const hashKey = cacheKey;
3283
- rememberProcessCacheKey(cacheKey, hashKey);
3284
- tasks.push(timeTask("html", () => require_hmr_timing.processCachedTask({
3285
- cache,
3286
- cacheKey,
3287
- hashKey,
3288
- hash: htmlProcessHash,
3289
- applyResult(source) {
3290
- originalSource.source = source;
3394
+ const cssPlugins = [{
3395
+ name: "weapp-tailwindcss:uni-app-x:css",
3396
+ async transform(code, id) {
3397
+ if (!isEnabled()) return;
3398
+ await runtimeState.readyPromise;
3399
+ return transformStyle(code, id, void 0, this);
3400
+ }
3401
+ }, {
3402
+ name: "weapp-tailwindcss:uni-app-x:css:pre",
3403
+ enforce: "pre",
3404
+ async transform(code, id) {
3405
+ if (!isEnabled()) return;
3406
+ await runtimeState.readyPromise;
3407
+ const { query } = parseVueRequest(id);
3408
+ const lang = query.lang;
3409
+ if (isIosPlatform && isPreprocessorRequest(id, lang)) return;
3410
+ return transformStyle(code, id, query, this);
3411
+ }
3412
+ }];
3413
+ const nvuePlugin = {
3414
+ name: "weapp-tailwindcss:uni-app-x:nvue",
3415
+ enforce: "pre",
3416
+ async buildStart() {
3417
+ if (!isEnabled()) return;
3418
+ await ensureRuntimeClassSet(true);
3291
3419
  },
3292
- onCacheHit() {
3293
- metrics.html.cacheHits++;
3294
- debug("html cache hit: %s", file);
3420
+ async transform(code, id) {
3421
+ if (!isEnabled()) return;
3422
+ if (!UVUE_NVUE_QUERY_RE.test(id)) return;
3423
+ rememberHarmonyApplySource(code);
3424
+ const resolvedConfig = getResolvedConfig();
3425
+ const isServeCommand = resolvedConfig?.command === "serve";
3426
+ const isWatchBuild = resolvedConfig?.command === "build" && !!resolvedConfig.build?.watch;
3427
+ const isNonWatchBuild = resolvedConfig?.command === "build" && !resolvedConfig.build?.watch;
3428
+ const currentRuntimeSet = isServeCommand || isWatchBuild || isNonWatchBuild ? await ensureRuntimeClassSet(true) : await ensureRuntimeClassSet();
3429
+ const transformUVue = await loadTransformUVue();
3430
+ const enableComponentLocalStyle = shouldEnableComponentLocalStyle();
3431
+ const enablePageLocalStyle = shouldEnableHarmonyPageLocalStyle();
3432
+ if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle) return transformUVue(code, id, jsHandler, currentRuntimeSet, require_v4_engine.omitUndefined({
3433
+ ...customAttributesEntities.length > 0 ? { customAttributesEntities } : {},
3434
+ ...disabledDefaultTemplateHandler ? { disabledDefaultTemplateHandler } : {},
3435
+ ...enableComponentLocalStyle ? { enableComponentLocalStyle } : {},
3436
+ ...enablePageLocalStyle ? { enablePageLocalStyle } : {}
3437
+ }));
3438
+ return transformUVue(code, id, jsHandler, currentRuntimeSet);
3295
3439
  },
3296
- async transform() {
3297
- const start = performance.now();
3298
- let transformed = await templateHandler(rawSource, { runtimeSet: templateRuntime });
3299
- let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
3300
- let retryRuntimeSet;
3301
- if (unresolvedDynamicCandidates.length > 0) {
3302
- const fullRuntimeSet = await context.ensureRuntimeClassSet(true);
3303
- const allowedRetryCandidates = fullRuntimeSet.size === 0 ? unresolvedDynamicCandidates : unresolvedDynamicCandidates.filter((candidate) => dynamicRetryCandidates.has(candidate) || fullRuntimeSet.has(candidate));
3304
- retryRuntimeSet = /* @__PURE__ */ new Set([...fullRuntimeSet, ...allowedRetryCandidates]);
3305
- unresolvedDynamicCandidates = unresolvedDynamicCandidates.filter((candidate) => retryRuntimeSet?.has(candidate) === true);
3306
- }
3307
- if (retryRuntimeSet && unresolvedDynamicCandidates.length > 0) {
3308
- _weapp_tailwindcss_logger.logger.warn("检测到已提取 WXML 动态类名未完成转译,已回退到完整 runtimeSet 重试: %s -> %O", file, unresolvedDynamicCandidates);
3309
- transformed = await templateHandler(rawSource, { runtimeSet: retryRuntimeSet });
3310
- unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed, retryRuntimeSet);
3311
- if (unresolvedDynamicCandidates.length > 0) _weapp_tailwindcss_logger.logger.warn("已提取 WXML 动态类名在完整 runtimeSet 重试后仍未完成转译: %s -> %O", file, unresolvedDynamicCandidates);
3440
+ async handleHotUpdate(ctx) {
3441
+ if (!isEnabled()) return;
3442
+ if (getResolvedConfig()?.command !== "serve") return;
3443
+ if (!UVUE_NVUE_RE.test(ctx.file)) return;
3444
+ await ensureRuntimeClassSet(true);
3445
+ },
3446
+ async watchChange(id) {
3447
+ if (!isEnabled()) return;
3448
+ const resolvedConfig = getResolvedConfig();
3449
+ if (resolvedConfig?.command !== "build" || !resolvedConfig.build?.watch) return;
3450
+ if (!UVUE_NVUE_QUERY_RE.test(id)) return;
3451
+ await ensureRuntimeClassSet(true);
3452
+ }
3453
+ };
3454
+ const stylePlaceholderPlugin = {
3455
+ name: "weapp-tailwindcss:uni-app-x:style-placeholder",
3456
+ enforce: "post",
3457
+ generateBundle: {
3458
+ order: "post",
3459
+ async handler(_options, bundle) {
3460
+ if (!isEnabled()) return;
3461
+ const currentUtsPlatform = require_utils.resolveUniUtsPlatform();
3462
+ const canInferHarmonyTarget = !currentUtsPlatform.normalized || currentUtsPlatform.isApp;
3463
+ const isHarmonyTarget = currentUtsPlatform.isAppHarmony || canInferHarmonyTarget && isHarmonyBuildTarget();
3464
+ if (!currentUtsPlatform.isApp && !isHarmonyTarget) return;
3465
+ const getAssetSource = createUniAppXBundleAssetSourceGetter(bundle);
3466
+ if (isHarmonyTarget) {
3467
+ const cssSources = [];
3468
+ const applyStyleSources = [...harmonyApplyStyleSources, ...collectUniAppXHarmonyApplyStyleSources(bundle)];
3469
+ const applyUtilities = /* @__PURE__ */ new Set([...harmonyApplyUtilities, ...collectUniAppXHarmonyApplyUtilities(bundle)]);
3470
+ if (applyStyleSources.length > 0 && applyUtilities.size > 0) {
3471
+ const harmonyApplyCssFile = node_path.default.resolve(getResolvedConfig()?.root ?? node_process.default.cwd(), "uni-app-x-harmony-apply.css");
3472
+ const generatedCss = await generateCss?.(harmonyApplyCssFile, createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities), this);
3473
+ if (typeof generatedCss === "string" && generatedCss.trim().length > 0) cssSources.push(generatedCss);
3474
+ }
3475
+ injectUniAppXHarmonyBundleStyles(bundle, {
3476
+ cssSources,
3477
+ excludeComponents: shouldEnableComponentLocalStyle()
3478
+ });
3479
+ }
3480
+ for (const [file, item] of Object.entries(bundle)) {
3481
+ if (item.type !== "asset" || !file.endsWith(".uvue.ts")) continue;
3482
+ const currentSource = String(item.source);
3483
+ const nextSource = injectUniAppXStylePlaceholder(file, currentSource, getAssetSource);
3484
+ if (nextSource !== currentSource) item.source = nextSource;
3485
+ }
3312
3486
  }
3313
- metrics.html.elapsed += measureElapsed(start);
3314
- metrics.html.transformed++;
3315
- onUpdate(file, rawSource, transformed);
3316
- debug("html handle: %s", file);
3317
- return { result: transformed };
3318
- }
3319
- })));
3320
- }
3321
- //#endregion
3322
- //#region src/bundlers/vite/generate-bundle/js-entries.ts
3323
- function createJsEntryResolver(jsEntries) {
3324
- const normalizedJsEntries = /* @__PURE__ */ new Map();
3325
- for (const [id, entry] of jsEntries) normalizedJsEntries.set(require_source_candidate_scan_signature.normalizeOutputPathKey(id), entry);
3326
- return (id) => jsEntries.get(id) ?? normalizedJsEntries.get(require_source_candidate_scan_signature.normalizeOutputPathKey(id));
3327
- }
3328
- //#endregion
3329
- //#region src/bundlers/vite/generate-bundle/js-handler-options.ts
3330
- function resolveUniAppXJsTransformEnabled(uniAppX) {
3331
- return uniAppX === void 0 ? true : require_tailwindcss.isUniAppXEnabled(uniAppX);
3332
- }
3333
- function createJsHandlerOptionsFactory(options) {
3334
- return (absoluteFilename, extra) => ({
3335
- ...extra,
3336
- generateMap: false,
3337
- filename: absoluteFilename,
3338
- tailwindcssMajorVersion: options.getMajorVersion(),
3339
- moduleGraph: options.moduleGraph,
3340
- babelParserOptions: {
3341
- ...extra?.babelParserOptions ?? {},
3342
- sourceFilename: absoluteFilename
3343
3487
  }
3344
- });
3345
- }
3346
- //#endregion
3347
- //#region src/bundlers/vite/generate-bundle/js-linking.ts
3348
- function createLinkedUpdateHelpers(options) {
3349
- const pendingLinkedUpdates = [];
3350
- const handleLinkedUpdate = (fileName, previous, next) => {
3351
- options.onUpdate(fileName, previous, next);
3352
- options.debug("js linked handle: %s", fileName);
3353
3488
  };
3354
- const scheduleLinkedApply = (entry, code) => {
3355
- pendingLinkedUpdates.push(() => {
3356
- if (entry.output.type === "chunk") entry.output.code = code;
3357
- else entry.output.source = code;
3489
+ return [
3490
+ ...cssPlugins,
3491
+ nvuePlugin,
3492
+ stylePlaceholderPlugin
3493
+ ];
3494
+ }
3495
+ function createUniAppXAssetTask(file, originalSource, outDir, options) {
3496
+ return async () => {
3497
+ const { cache, hashKey, createHandlerOptions, debug, getAssetSource, jsHandler, onUpdate, runtimeSet, applyLinkedResults } = options;
3498
+ const absoluteFile = require_source_candidate_scan_signature.toAbsoluteOutputPath(file, outDir);
3499
+ const rawSource = originalSource.source.toString();
3500
+ await require_hmr_timing.processCachedTask({
3501
+ cache,
3502
+ cacheKey: file,
3503
+ hashKey,
3504
+ rawSource: options.hashSalt ? `${rawSource}\n/*${options.hashSalt}*/` : rawSource,
3505
+ applyResult(source) {
3506
+ originalSource.source = source;
3507
+ },
3508
+ onCacheHit() {
3509
+ debug("js cache hit: %s", file);
3510
+ },
3511
+ async transform() {
3512
+ const currentSource = originalSource.source.toString();
3513
+ const { code, linked } = await jsHandler(currentSource, runtimeSet, createHandlerOptions(absoluteFile, {
3514
+ uniAppX: resolveUniAppXJsTransformEnabled(options.uniAppX),
3515
+ babelParserOptions: {
3516
+ plugins: ["typescript"],
3517
+ sourceType: "unambiguous"
3518
+ }
3519
+ }));
3520
+ const nextCode = injectUniAppXStylePlaceholder(file, code, getAssetSource);
3521
+ onUpdate(file, currentSource, nextCode);
3522
+ debug("js handle: %s", file);
3523
+ applyLinkedResults(linked);
3524
+ return { result: nextCode };
3525
+ }
3358
3526
  });
3359
3527
  };
3360
- const applyLinkedUpdates = (linked) => {
3361
- require_source_candidate_scan_signature.applyLinkedResults(linked, options.jsEntries, handleLinkedUpdate, scheduleLinkedApply);
3362
- };
3363
- return {
3364
- applyLinkedUpdates,
3365
- pendingLinkedUpdates
3366
- };
3367
- }
3368
- function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
3369
- if (!linked || !linkedSet) return;
3370
- for (const id of Object.keys(linked)) {
3371
- const linkedEntry = getJsEntry(id);
3372
- if (linkedEntry) linkedSet.add(linkedEntry.fileName);
3373
- }
3374
3528
  }
3375
3529
  //#endregion
3376
3530
  //#region src/bundlers/vite/generate-bundle/js-processing.ts
@@ -3478,7 +3632,7 @@ function processJsBundleEntry(options) {
3478
3632
  }
3479
3633
  const currentSource = originalEntrySource;
3480
3634
  const precheckOptions = createHandlerOptions(node_path.default.resolve(outDir, file), {
3481
- uniAppX: resolveUniAppXJsTransformEnabled(uniAppX),
3635
+ uniAppX: resolveUniAppXJsTransformEnabled$1(uniAppX),
3482
3636
  babelParserOptions: {
3483
3637
  plugins: ["typescript"],
3484
3638
  sourceType: "unambiguous"
@@ -4146,27 +4300,6 @@ function createTransformFilterSignature(options) {
4146
4300
  return [`include:${createRuleSignature(options?.include)}`, `exclude:${createRuleSignature(options?.exclude)}`].join(";");
4147
4301
  }
4148
4302
  //#endregion
4149
- //#region src/bundlers/vite/uni-app-x-css-options.ts
4150
- function resolveUniAppXNativeCssHandlerOptions(opts) {
4151
- const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
4152
- if (!require_generator.shouldUseNativeAppCssBranch(require_generator.resolveGeneratorRuntimeBranch(require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
4153
- appType: opts.appType,
4154
- platform: opts.cssOptions?.platform ?? opts.platform,
4155
- uniAppX: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX),
4156
- uniUtsPlatform
4157
- }), {
4158
- appType: opts.appType,
4159
- platform: opts.cssOptions?.platform ?? opts.platform,
4160
- uniAppX: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX),
4161
- uniUtsPlatform
4162
- })) || !require_tailwindcss.isUniAppXEnabled(opts.uniAppX)) return {};
4163
- return {
4164
- uniAppX: true,
4165
- uniAppXCssTarget: "uvue",
4166
- uniAppXUnsupported: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX).uvueUnsupported
4167
- };
4168
- }
4169
- //#endregion
4170
4303
  //#region src/bundlers/vite/weapp-vite-config.ts
4171
4304
  function resolveSourceRootCandidate(root, value) {
4172
4305
  if (typeof value !== "string" || value.trim().length === 0) return;
@@ -4228,16 +4361,35 @@ function inferPlatformFromViteOutDir$1(outDir) {
4228
4361
  const normalized = segment.trim().toLowerCase();
4229
4362
  if (normalized === "h5" || normalized === "web" || normalized === "app" || normalized === "app-plus" || normalized.startsWith("app-") || normalized.startsWith("mp-") || normalized.startsWith("quickapp-webview")) return normalized;
4230
4363
  }
4231
- function isUniAppViteWebviewOutDir$1(outDir) {
4232
- const normalized = outDir ? node_path.default.basename(node_path.default.normalize(outDir)).trim().toLowerCase() : void 0;
4233
- return normalized === "app" || normalized === "app-plus";
4234
- }
4235
4364
  function createGenerateBundleHook(context) {
4236
4365
  const state = require_source_candidate_scan_signature.createBundleBuildState();
4237
4366
  const lastCssResultByFile = /* @__PURE__ */ new Map();
4238
4367
  const lastCssSourceHashByFile = /* @__PURE__ */ new Map();
4239
4368
  let currentOutDir;
4240
4369
  let currentSubpackageRoots;
4370
+ const createInitialCssPipelineContext = (file) => {
4371
+ const resolvedConfig = context.getResolvedConfig();
4372
+ const platform = context.opts.cssOptions?.platform ?? context.opts.platform ?? inferPlatformFromViteOutDir$1(resolvedConfig?.build?.outDir);
4373
+ const currentGeneratorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(context.opts.generator, {
4374
+ appType: context.opts.appType,
4375
+ platform,
4376
+ tailwindcssMajorVersion: context.runtimeState.tailwindRuntime.majorVersion,
4377
+ uniAppX: context.opts.uniAppX
4378
+ });
4379
+ return {
4380
+ currentGeneratorBranch: require_generator.resolveGeneratorRuntimeBranch(currentGeneratorOptions, {
4381
+ appType: context.opts.appType,
4382
+ platform,
4383
+ tailwindcssMajorVersion: context.runtimeState.tailwindRuntime.majorVersion,
4384
+ uniAppX: context.opts.uniAppX
4385
+ }),
4386
+ currentGeneratorOptions,
4387
+ file,
4388
+ opts: context.opts,
4389
+ resolvedConfig,
4390
+ resolveStylePlatform: () => platform
4391
+ };
4392
+ };
4241
4393
  const cssHandlerOptions = createCssHandlerOptionsCache({
4242
4394
  getAppType: () => context.opts.appType,
4243
4395
  mainCssChunkMatcher: context.opts.mainCssChunkMatcher,
@@ -4245,7 +4397,7 @@ function createGenerateBundleHook(context) {
4245
4397
  getOutputRoot: () => currentOutDir,
4246
4398
  getExtraOptions: (file) => ({
4247
4399
  ...resolveViteCssHandlerExtraOptions(file),
4248
- ...resolveUniAppXNativeCssHandlerOptions(context.opts),
4400
+ ...context.cssPipelineStrategy?.getCssHandlerExtraOptions?.(createInitialCssPipelineContext(file)) ?? {},
4249
4401
  ...currentSubpackageRoots && isSubpackageOutputFile(file, currentSubpackageRoots) ? { isMainChunk: false } : {}
4250
4402
  })
4251
4403
  });
@@ -4276,18 +4428,27 @@ function createGenerateBundleHook(context) {
4276
4428
  uniAppX,
4277
4429
  uniUtsPlatform
4278
4430
  });
4431
+ const cssPipelineContext = {
4432
+ bundle,
4433
+ currentGeneratorBranch: generatorBranch,
4434
+ currentGeneratorOptions: generatorOptions,
4435
+ opts,
4436
+ resolvedConfig,
4437
+ resolveStylePlatform: () => generatorPlatform
4438
+ };
4279
4439
  const isWebGeneratorTarget = generatorBranch.isWeb;
4280
- const shouldApplyWebviewSafeSelectors = opts.appType === "uni-app-vite" && isUniAppViteWebviewOutDir$1(resolvedConfig?.build?.outDir);
4281
- const shouldApplyWebviewCssCompat = isWebGeneratorTarget || shouldApplyWebviewSafeSelectors;
4440
+ const shouldApplyWebCssCompat = context.cssPipelineStrategy?.shouldApplyWebCssCompat?.(cssPipelineContext) === true;
4282
4441
  const transformWebTargetCss = (css) => {
4283
- const compatCss = isWebGeneratorTarget ? (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(css, generatorOptions.webCompat) : shouldApplyWebviewCssCompat ? (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(css, generatorOptions.webCompat ?? true) : css;
4284
- return shouldApplyWebviewSafeSelectors ? (0, _weapp_tailwindcss_postcss.transformWebCssSafeSelectors)(compatCss, { escapeMap: opts.escapeMap }) : compatCss;
4442
+ return context.cssPipelineStrategy?.transformGeneratedCss?.(css, {
4443
+ ...cssPipelineContext,
4444
+ defaultWebCssCompat: (value) => (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(value, isWebGeneratorTarget ? generatorOptions.webCompat : generatorOptions.webCompat ?? true),
4445
+ removeScopedPreflight: (value) => value,
4446
+ shouldApplyWebCssCompat
4447
+ }) ?? (shouldApplyWebCssCompat ? (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(css, isWebGeneratorTarget ? generatorOptions.webCompat : generatorOptions.webCompat ?? true) : css);
4285
4448
  };
4286
- const isUniAppXStyleTarget = opts.appType === "uni-app-x";
4287
- const isNativeAppStyleTarget = isUniAppXStyleTarget && uniUtsPlatform.isApp;
4288
- const canInferHarmonyAppStyleTarget = isUniAppXStyleTarget && (!uniUtsPlatform.normalized || uniUtsPlatform.isApp);
4289
- const isHarmonyAppStyleTarget = isUniAppXStyleTarget && (uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir)));
4290
- const shouldPreserveAppCssExtension = isNativeAppStyleTarget || isHarmonyAppStyleTarget;
4449
+ const isNativeAppStyleTarget = context.cssPipelineStrategy?.isNativeAppStyleTarget?.(cssPipelineContext) === true;
4450
+ const isHarmonyAppStyleTarget = context.cssPipelineStrategy?.isHarmonyAppStyleTarget?.(cssPipelineContext) === true;
4451
+ const shouldPreserveAppCssExtension = context.cssPipelineStrategy?.shouldPreserveStyleOutputExtension?.(cssPipelineContext) ?? (isNativeAppStyleTarget || isHarmonyAppStyleTarget);
4291
4452
  const shouldGenerateWebCssByGenerator = isWebGeneratorTarget;
4292
4453
  const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
4293
4454
  const rootDir = resolvedConfig?.root ? node_path.default.resolve(resolvedConfig.root) : node_process.default.cwd();
@@ -4302,6 +4463,8 @@ function createGenerateBundleHook(context) {
4302
4463
  if (subpackageRoots) currentSubpackageRoots = subpackageRoots;
4303
4464
  collectViteProcessedCssAssetResults(bundle, {
4304
4465
  opts,
4466
+ cssPipelineStrategy: context.cssPipelineStrategy,
4467
+ createCssPipelineContext: () => cssPipelineContext,
4305
4468
  isViteProcessedCssAsset,
4306
4469
  markCssAssetProcessed,
4307
4470
  recordCssAssetResult,
@@ -4366,20 +4529,32 @@ function createGenerateBundleHook(context) {
4366
4529
  ...Array.isArray(runtimeTailwindcssOptions?.v4?.cssEntries) ? runtimeTailwindcssOptions.v4.cssEntries : [],
4367
4530
  ...Array.isArray(tailwindRuntimeOptions?.v4?.cssEntries) ? tailwindRuntimeOptions.v4.cssEntries : []
4368
4531
  ].filter((file) => typeof file === "string" && file.length > 0).map(normalizeConfiguredTailwindV4CssEntryFileKey));
4369
- const resolveUniAppViteWebviewRootCssInjectionTarget = (sourceFile, outputFile) => {
4370
- if (opts.appType !== "uni-app-vite" || !outputFile.replace(/[?#].*$/, "").endsWith(".css") || typeof sourceFile !== "string" || !configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(sourceFile))) return;
4371
- const rootCssFiles = bundleFiles.filter((file) => {
4372
- const normalized = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
4373
- return opts.cssMatcher(file) && normalized.endsWith(".css") && !normalized.includes("/");
4532
+ const isRootStyleOutputFile = (file) => {
4533
+ const normalized = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
4534
+ return normalized.endsWith(".css") && !normalized.includes("/");
4535
+ };
4536
+ const isMiniProgramStyleOutputFile = (file) => /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
4537
+ const resolveConfiguredCssEntryRootInjectionTarget = (sourceFile, outputFile) => {
4538
+ if (!outputFile.replace(/[?#].*$/, "").endsWith(".css") || typeof sourceFile !== "string" || !configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(sourceFile))) return;
4539
+ return context.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget?.({
4540
+ ...cssPipelineContext,
4541
+ bundle,
4542
+ isConfiguredCssEntryFile: (file) => typeof file === "string" && configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(file)),
4543
+ isMiniProgramStyleOutputFile,
4544
+ isRootStyleOutputFile,
4545
+ outputFile,
4546
+ sourceFile
4374
4547
  });
4375
- const matchedRootCssFiles = rootCssFiles.filter((file) => getCssHandlerOptions(file).isMainChunk);
4376
- if (matchedRootCssFiles.length === 1) return matchedRootCssFiles[0];
4377
- if (matchedRootCssFiles.length > 1) return;
4378
- return rootCssFiles.length === 1 ? rootCssFiles[0] : void 0;
4379
4548
  };
4380
4549
  const resolveConfiguredTailwindV4CssEntryOutputFile = (sourceFile) => resolveViteCssPipelineOutputFile(sourceFile, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
4381
- const selectUniAppViteWebviewRootCssSourceEntry = (outputFile, entries) => {
4382
- if (opts.appType !== "uni-app-vite" || !isWebGeneratorTarget || !opts.cssMatcher(outputFile) || require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile.replace(/[?#].*$/, "")).includes("/")) return;
4550
+ const selectConfiguredRootCssSourceEntry = (outputFile, entries, originalFileNames) => {
4551
+ const matchedOriginalEntry = entries.find((entry) => originalFileNames?.some((originalFile) => normalizeConfiguredTailwindV4CssEntryFileKey(originalFile) === normalizeConfiguredTailwindV4CssEntryFileKey(entry.file)) === true);
4552
+ if (matchedOriginalEntry && outputFile.replace(/[?#].*$/, "").endsWith(".css")) return matchedOriginalEntry;
4553
+ if (!(context.cssPipelineStrategy?.shouldSelectConfiguredCssEntryRootSource?.({
4554
+ ...cssPipelineContext,
4555
+ isRootStyleOutputFile,
4556
+ outputFile
4557
+ }) === true || cssPipelineContext.currentGeneratorBranch.isWeb && opts.cssMatcher(outputFile) && isRootStyleOutputFile(outputFile))) return;
4383
4558
  const generationEntries = entries.filter((entry) => hasTailwindGenerationSource(entry.source));
4384
4559
  if (generationEntries.length <= 1) return generationEntries[0];
4385
4560
  const rootOutputEntries = generationEntries.filter((entry) => {
@@ -4552,10 +4727,18 @@ function createGenerateBundleHook(context) {
4552
4727
  getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
4553
4728
  moduleGraph: moduleGraphOptions
4554
4729
  });
4555
- const createHandlerOptions = (absoluteFilename, extra) => createBaseHandlerOptions(absoluteFilename, shouldApplyWebviewSafeSelectors ? {
4556
- needEscaped: true,
4557
- ...extra
4558
- } : extra);
4730
+ const resolveFrameworkJsHandlerOptions = (absoluteFilename) => context.cssPipelineStrategy?.getServeJsHandlerOptions?.({
4731
+ ...cssPipelineContext,
4732
+ file: absoluteFilename
4733
+ });
4734
+ const createHandlerOptions = (absoluteFilename, extra) => {
4735
+ const frameworkExtra = resolveFrameworkJsHandlerOptions(absoluteFilename);
4736
+ return createBaseHandlerOptions(absoluteFilename, frameworkExtra || extra ? {
4737
+ ...frameworkExtra,
4738
+ ...extra
4739
+ } : void 0);
4740
+ };
4741
+ const shouldTransformJsBundle = !isWebGeneratorTarget || context.cssPipelineStrategy?.shouldTransformServeJs?.(cssPipelineContext) === true;
4559
4742
  const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
4560
4743
  const sharedCssResultCache = /* @__PURE__ */ new Map();
4561
4744
  const activeProcessCacheKeys = /* @__PURE__ */ new Set();
@@ -4612,12 +4795,18 @@ function createGenerateBundleHook(context) {
4612
4795
  metrics.css.total++;
4613
4796
  const assetSourceFile = resolveAssetSourceFile(originalSource, file);
4614
4797
  const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, assetSourceFile, outDir, opts);
4798
+ const cssPipelineContext = {
4799
+ ...createInitialCssPipelineContext(file),
4800
+ bundle
4801
+ };
4615
4802
  let outputFile = resolveCssBundleOutputFile({
4616
4803
  bundleFiles,
4804
+ cssPipelineStrategy: context.cssPipelineStrategy,
4617
4805
  defaultStyleOutputExtension,
4618
4806
  file,
4619
4807
  isWebGeneratorTarget,
4620
4808
  opts,
4809
+ pipelineContext: cssPipelineContext,
4621
4810
  shouldPreserveAppCssExtension
4622
4811
  });
4623
4812
  const resolveMatchedOutputFileForCurrentAsset = createMatchedCssSourceOutputResolver({
@@ -4626,6 +4815,13 @@ function createGenerateBundleHook(context) {
4626
4815
  originalFileNames: originalSource.originalFileNames,
4627
4816
  resolveOutputFileFromMatchedCssSource: resolveMatchedCssSourceOutputFile
4628
4817
  });
4818
+ const configuredOriginalSourceEntry = outputFile.replace(/[?#].*$/, "").endsWith(".css") ? getConfiguredTailwindV4CssSourceEntries().find((entry) => originalSource.originalFileNames?.some((originalFile) => normalizeConfiguredTailwindV4CssEntryFileKey(originalFile) === normalizeConfiguredTailwindV4CssEntryFileKey(entry.file)) === true) : void 0;
4819
+ const configuredOriginalOutputFile = configuredOriginalSourceEntry ? resolveMatchedOutputFileForCurrentAsset(configuredOriginalSourceEntry.file) : void 0;
4820
+ let resolvedFromConfiguredOriginalCssEntry = false;
4821
+ if (configuredOriginalOutputFile && require_source_candidate_scan_signature.normalizeOutputPathKey(configuredOriginalOutputFile) !== require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile)) {
4822
+ outputFile = configuredOriginalOutputFile;
4823
+ resolvedFromConfiguredOriginalCssEntry = true;
4824
+ }
4629
4825
  activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
4630
4826
  if (shouldSkipRawSourceStyleAsset(outputFile, file, rawSource, assetSourceFile, opts.cssMatcher)) {
4631
4827
  delete bundle[file];
@@ -4637,13 +4833,14 @@ function createGenerateBundleHook(context) {
4637
4833
  let resolvedFromTemporaryCssAsset = false;
4638
4834
  const applyCssResult = (source) => {
4639
4835
  applyCssResultToBundle({
4640
- appType: opts.appType,
4641
4836
  assetSourceFile,
4642
4837
  bundle,
4838
+ cssPipelineStrategy: context.cssPipelineStrategy,
4643
4839
  emitOrReplayCssAsset,
4644
4840
  file,
4645
4841
  originalSource,
4646
4842
  outputFile,
4843
+ pipelineContext: cssPipelineContext,
4647
4844
  source,
4648
4845
  viteProcessedCssAsset
4649
4846
  });
@@ -4710,7 +4907,7 @@ function createGenerateBundleHook(context) {
4710
4907
  if (!hasUsableRememberedTailwindSource) {
4711
4908
  const configuredTailwindV4CssSourceEntries = getConfiguredTailwindV4CssSourceEntries();
4712
4909
  const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug);
4713
- const inferredWebviewRootSourceEntry = inferredSourceStyle ? void 0 : selectUniAppViteWebviewRootCssSourceEntry(outputFile, configuredTailwindV4CssSourceEntries);
4910
+ const inferredWebviewRootSourceEntry = inferredSourceStyle ? void 0 : selectConfiguredRootCssSourceEntry(outputFile, configuredTailwindV4CssSourceEntries, originalSource.originalFileNames);
4714
4911
  const inferredWebviewRootSourceStyle = inferredWebviewRootSourceEntry ? {
4715
4912
  outputFile,
4716
4913
  rawSource: inferredWebviewRootSourceEntry.source,
@@ -4798,7 +4995,7 @@ function createGenerateBundleHook(context) {
4798
4995
  const hasSameOutputRememberedTailwindGenerationSource = hasRememberedTailwindGenerationSource && rememberedCssSource != null && require_source_candidate_scan_signature.normalizeOutputPathKey(rememberedCssSource.outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile);
4799
4996
  const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective || hasRememberedTailwindGenerationSource);
4800
4997
  const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? assetSourceFile : assetSourceFile;
4801
- const webviewRootCssInjectionTarget = vitePipelineCssAsset ? resolveUniAppViteWebviewRootCssInjectionTarget(generatorSourceFile, outputFile) : void 0;
4998
+ const webviewRootCssInjectionTarget = vitePipelineCssAsset ? resolveConfiguredCssEntryRootInjectionTarget(generatorSourceFile, outputFile) : void 0;
4802
4999
  const usesConfiguredTailwindV4FallbackSource = rememberedCssSource != null && require_source_candidate_scan_signature.normalizeOutputPathKey(rememberedCssSource.outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile) && require_source_candidate_scan_signature.normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")) !== require_source_candidate_scan_signature.normalizeOutputPathKey(file);
4803
5000
  if (vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(generatorSourceFile))) {
4804
5001
  usedConfiguredTailwindV4CssSourceFiles.add(require_source_candidate_scan_signature.normalizeOutputPathKey(generatorSourceFile));
@@ -4839,7 +5036,7 @@ function createGenerateBundleHook(context) {
4839
5036
  const shouldRefreshViteProcessedCssByCandidates = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged;
4840
5037
  const vitePipelineCssInjectionOutputFile = webviewRootCssInjectionTarget ?? outputFile;
4841
5038
  const shouldRecordVitePipelineCssByOutput = require_source_candidate_scan_signature.normalizeOutputPathKey(vitePipelineCssInjectionOutputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile);
4842
- const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && (webviewRootCssInjectionTarget != null || shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions));
5039
+ const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && !resolvedFromConfiguredOriginalCssEntry && outputCssHandlerOptions.isMainChunk !== true && (webviewRootCssInjectionTarget != null || shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions));
4843
5040
  const shouldTrackGeneratorRuntime = hasStaleViteProcessedCssSource || shouldRegenerateMainPackageCssWithScopedCandidates || hasCurrentTailwindGenerationDirective || hasSameOutputRememberedTailwindGenerationSource || shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || runtimeLinkedCssFiles.has(outputFile) || shouldRegenerateCollectedViteCss || hasRuntimeAffectingChanges && (alreadyProcessedCssAsset || vitePipelineCssAsset));
4844
5041
  const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) || require_source_candidate_scan_signature.hasBundlerGeneratedCssMarker(rawSource));
4845
5042
  const strippedViteProcessedCss = require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource);
@@ -4985,7 +5182,7 @@ function createGenerateBundleHook(context) {
4985
5182
  continue;
4986
5183
  }
4987
5184
  if (type !== "js") continue;
4988
- if (isWebGeneratorTarget && !shouldApplyWebviewSafeSelectors) {
5185
+ if (!shouldTransformJsBundle) {
4989
5186
  debug("js skip web target: %s", file);
4990
5187
  continue;
4991
5188
  }
@@ -5067,6 +5264,8 @@ function createGenerateBundleHook(context) {
5067
5264
  bundleFiles,
5068
5265
  cache,
5069
5266
  cssTaskFactories,
5267
+ cssPipelineStrategy: context.cssPipelineStrategy,
5268
+ createCssPipelineContext: () => cssPipelineContext,
5070
5269
  debug,
5071
5270
  defaultStyleOutputExtension,
5072
5271
  formatIteration: useIncrementalMode ? state.iteration : 0,
@@ -5140,9 +5339,9 @@ function registerGeneratorDependencies(ctx, dependencies) {
5140
5339
  throw error;
5141
5340
  }
5142
5341
  }
5143
- function createCssHandlerOptions(opts, majorVersion, file) {
5342
+ function createCssHandlerOptions(opts, majorVersion, file, extraOptions = {}) {
5144
5343
  return {
5145
- ...resolveUniAppXNativeCssHandlerOptions(opts),
5344
+ ...extraOptions,
5146
5345
  cssPreflight: opts.cssPreflight,
5147
5346
  isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
5148
5347
  postcssOptions: { options: { from: file } },
@@ -5167,13 +5366,15 @@ function shouldFinalizeProcessedCssAsset(opts, file) {
5167
5366
  function collectViteProcessedCssSources(getViteProcessedCssAssetResults) {
5168
5367
  return [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
5169
5368
  }
5170
- function isUniAppViteWebviewOutDir(outDir) {
5171
- const normalized = outDir ? node_path.default.basename(node_path.default.normalize(outDir)).trim().toLowerCase() : void 0;
5172
- return normalized === "app" || normalized === "app-plus";
5173
- }
5174
- function finalizeWebCss(css, enabled, webCompat, options = {}) {
5175
- const compatCss = enabled ? (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(css, webCompat) : css;
5176
- return options.safeSelectors ? (0, _weapp_tailwindcss_postcss.transformWebCssSafeSelectors)(compatCss, { escapeMap: options.escapeMap }) : compatCss;
5369
+ function finalizeWebCss(css, context, cssPipelineStrategy) {
5370
+ const shouldApplyWebCssCompat = cssPipelineStrategy?.shouldApplyWebCssCompat?.(context) === true;
5371
+ const defaultWebCssCompat = (value) => (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(value, context.currentGeneratorBranch.isWeb ? context.currentGeneratorOptions.webCompat : context.currentGeneratorOptions.webCompat ?? true);
5372
+ return cssPipelineStrategy?.transformGeneratedCss?.(css, {
5373
+ ...context,
5374
+ defaultWebCssCompat,
5375
+ removeScopedPreflight: (value) => value,
5376
+ shouldApplyWebCssCompat
5377
+ }) ?? (shouldApplyWebCssCompat ? defaultWebCssCompat(css) : css);
5177
5378
  }
5178
5379
  function createViteCssFinalizerOutputPlugin(context) {
5179
5380
  return {
@@ -5182,7 +5383,7 @@ function createViteCssFinalizerOutputPlugin(context) {
5182
5383
  generateBundle: {
5183
5384
  order: "post",
5184
5385
  async handler(_options, bundle) {
5185
- const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
5386
+ const { opts, runtimeState, ensureRuntimeClassSet, cssPipelineStrategy, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
5186
5387
  const resolvedConfig = getResolvedConfig();
5187
5388
  const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
5188
5389
  const generatorPlatform = opts.cssOptions?.platform ?? opts.platform ?? inferPlatformFromViteOutDir(resolvedConfig?.build?.outDir);
@@ -5201,11 +5402,16 @@ function createViteCssFinalizerOutputPlugin(context) {
5201
5402
  uniUtsPlatform
5202
5403
  });
5203
5404
  const isWebGeneratorTarget = generatorBranch.isWeb;
5204
- const shouldApplyWebviewSafeSelectors = opts.appType === "uni-app-vite" && isUniAppViteWebviewOutDir(resolvedConfig?.build?.outDir);
5205
- const isUniAppXStyleTarget = opts.appType === "uni-app-x";
5206
- const canInferHarmonyAppStyleTarget = isUniAppXStyleTarget && (!uniUtsPlatform.normalized || uniUtsPlatform.isApp);
5207
- const isHarmonyAppStyleTarget = isUniAppXStyleTarget && (uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir)));
5208
- const isNativeAppStyleTarget = isUniAppXStyleTarget && (uniUtsPlatform.isApp || isHarmonyAppStyleTarget);
5405
+ const createCssPipelineContext = (_file) => ({
5406
+ bundle,
5407
+ currentGeneratorBranch: generatorBranch,
5408
+ currentGeneratorOptions: generatorOptions,
5409
+ opts,
5410
+ resolvedConfig,
5411
+ resolveStylePlatform: () => generatorPlatform
5412
+ });
5413
+ const isHarmonyAppStyleTarget = cssPipelineStrategy?.isHarmonyAppStyleTarget?.(createCssPipelineContext("")) === true;
5414
+ const isNativeAppStyleTarget = cssPipelineStrategy?.isNativeAppStyleTarget?.(createCssPipelineContext("")) === true;
5209
5415
  if (resolvedConfig?.command !== "build" && !isNativeAppStyleTarget) return;
5210
5416
  const rootDir = resolvedConfig?.root ? node_path.default.resolve(resolvedConfig.root) : node_process.default.cwd();
5211
5417
  const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
@@ -5217,28 +5423,32 @@ function createViteCssFinalizerOutputPlugin(context) {
5217
5423
  const collectViteProcessedCssAssets = () => {
5218
5424
  collectViteProcessedCssAssetResults(bundle, {
5219
5425
  opts,
5426
+ cssPipelineStrategy,
5427
+ createCssPipelineContext,
5220
5428
  isViteProcessedCssAsset,
5221
5429
  markCssAssetProcessed,
5222
5430
  recordCssAssetResult,
5223
5431
  recordViteProcessedCssAssetResult,
5224
5432
  resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget, sourceRoot, resolveMiniProgramStyleOutputExtension({ files: Object.keys(bundle) }), Object.keys(bundle)),
5225
- transformCss: (css) => finalizeWebCss(css, generatorBranch.isWeb, generatorOptions.webCompat, {
5226
- escapeMap: opts.escapeMap,
5227
- safeSelectors: shouldApplyWebviewSafeSelectors
5228
- }),
5433
+ transformCss: (css, file) => finalizeWebCss(css, {
5434
+ ...createCssPipelineContext(file),
5435
+ file
5436
+ }, cssPipelineStrategy),
5229
5437
  debug
5230
5438
  });
5231
5439
  };
5232
5440
  const injectViteProcessedCssIntoMainCss = () => {
5233
5441
  return injectViteProcessedCssIntoMainCssAssets(bundle, {
5234
5442
  opts,
5443
+ cssPipelineStrategy,
5444
+ createCssPipelineContext,
5235
5445
  getViteProcessedCssAssetResults,
5236
5446
  markCssAssetProcessed,
5237
5447
  recordCssAssetResult,
5238
- transformCss: (css) => finalizeWebCss(css, generatorBranch.isWeb, generatorOptions.webCompat, {
5239
- escapeMap: opts.escapeMap,
5240
- safeSelectors: shouldApplyWebviewSafeSelectors
5241
- }),
5448
+ transformCss: (css, file) => finalizeWebCss(css, {
5449
+ ...createCssPipelineContext(file),
5450
+ file
5451
+ }, cssPipelineStrategy),
5242
5452
  debug,
5243
5453
  onUpdate: opts.onUpdate
5244
5454
  });
@@ -5250,7 +5460,10 @@ function createViteCssFinalizerOutputPlugin(context) {
5250
5460
  const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
5251
5461
  if (applyUtilities.size === 0 || applyStyleSources.length === 0) return cssSources;
5252
5462
  const harmonyRuntime = /* @__PURE__ */ new Set([...runtime, ...applyUtilities]);
5253
- const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css");
5463
+ const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css", cssPipelineStrategy?.getCssHandlerExtraOptions?.({
5464
+ ...createCssPipelineContext("uni-app-x-harmony-apply.css"),
5465
+ file: "uni-app-x-harmony-apply.css"
5466
+ }) ?? {});
5254
5467
  const generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
5255
5468
  opts,
5256
5469
  runtimeState,
@@ -5285,10 +5498,10 @@ function createViteCssFinalizerOutputPlugin(context) {
5285
5498
  await injectHarmonyBundleStyles(getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet());
5286
5499
  collectViteProcessedCssAssets();
5287
5500
  injectViteProcessedCssIntoMainCss();
5288
- normalizeTaroRootImportShellAssets(bundle, {
5289
- appType: opts.appType,
5501
+ normalizeRootMiniProgramImportShellAssets(bundle, {
5290
5502
  cssMatcher: opts.cssMatcher,
5291
5503
  debug,
5504
+ enabled: cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(createCssPipelineContext("")) === true,
5292
5505
  onUpdate: opts.onUpdate,
5293
5506
  recordCssAssetResult
5294
5507
  });
@@ -5303,17 +5516,20 @@ function createViteCssFinalizerOutputPlugin(context) {
5303
5516
  const file = output.fileName || bundleFile;
5304
5517
  const rawSource = output.source.toString();
5305
5518
  if (isViteProcessedCssAsset?.(output, file)) {
5306
- const nextCss = annotateCss(finalizeWebCss(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource), generatorBranch.isWeb, generatorOptions.webCompat, {
5307
- escapeMap: opts.escapeMap,
5308
- safeSelectors: shouldApplyWebviewSafeSelectors
5309
- }));
5519
+ const nextCss = annotateCss(finalizeWebCss(require_source_candidate_scan_signature.stripBundlerGeneratedCssMarkers(rawSource), {
5520
+ ...createCssPipelineContext(file),
5521
+ file
5522
+ }, cssPipelineStrategy));
5310
5523
  output.source = nextCss;
5311
5524
  markCssAssetProcessed(output, file);
5312
5525
  recordCssAssetResult?.(file, nextCss);
5313
5526
  debug("css finalizer skip vite-processed css: %s", file);
5314
5527
  return;
5315
5528
  }
5316
- const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file);
5529
+ const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
5530
+ ...createCssPipelineContext(file),
5531
+ file
5532
+ }) ?? {});
5317
5533
  const cssUserHandlerOptions = {
5318
5534
  ...cssHandlerOptions,
5319
5535
  isMainChunk: false
@@ -5322,7 +5538,10 @@ function createViteCssFinalizerOutputPlugin(context) {
5322
5538
  const rememberedMainCssSource = processed && cssHandlerOptions.isMainChunk ? getRememberedMainCssSource?.(file) : void 0;
5323
5539
  const generatorRawSource = rememberedMainCssSource?.rawSource ?? rawSource;
5324
5540
  const generatorSourceFile = rememberedMainCssSource?.sourceFile ?? file;
5325
- const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, generatorSourceFile) : cssHandlerOptions;
5541
+ const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, generatorSourceFile, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
5542
+ ...createCssPipelineContext(generatorSourceFile),
5543
+ file: generatorSourceFile
5544
+ }) ?? {}) : cssHandlerOptions;
5326
5545
  const generatorCssUserHandlerOptions = rememberedMainCssSource ? {
5327
5546
  ...generatorCssHandlerOptions,
5328
5547
  isMainChunk: false
@@ -5341,10 +5560,10 @@ function createViteCssFinalizerOutputPlugin(context) {
5341
5560
  styleHandler: opts.styleHandler,
5342
5561
  debug
5343
5562
  }) : void 0;
5344
- const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? finalizeWebCss(rawSource, true, generatorOptions.webCompat, {
5345
- escapeMap: opts.escapeMap,
5346
- safeSelectors: shouldApplyWebviewSafeSelectors
5347
- }) : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
5563
+ const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? finalizeWebCss(rawSource, {
5564
+ ...createCssPipelineContext(file),
5565
+ file
5566
+ }, cssPipelineStrategy) : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
5348
5567
  if (generated) {
5349
5568
  registerGeneratorDependencies(this, generated.dependencies);
5350
5569
  debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
@@ -5359,10 +5578,10 @@ function createViteCssFinalizerOutputPlugin(context) {
5359
5578
  await injectHarmonyBundleStyles(generatorRuntime);
5360
5579
  collectViteProcessedCssAssets();
5361
5580
  injectViteProcessedCssIntoMainCss();
5362
- normalizeTaroRootImportShellAssets(bundle, {
5363
- appType: opts.appType,
5581
+ normalizeRootMiniProgramImportShellAssets(bundle, {
5364
5582
  cssMatcher: opts.cssMatcher,
5365
5583
  debug,
5584
+ enabled: cssPipelineStrategy?.shouldNormalizeRootMiniProgramImportShell?.(createCssPipelineContext("")) === true,
5366
5585
  onUpdate: opts.onUpdate,
5367
5586
  recordCssAssetResult
5368
5587
  });
@@ -6043,6 +6262,12 @@ function isViteServeCssRootRequest(id, command) {
6043
6262
  function isViteCssHmrModule(code, id, command) {
6044
6263
  return isViteServeStyleRequest(id, command) && VITE_CSS_HMR_MODULE_RE.test(code) && /[?&](?:direct|vue)(?:&|$)/.test(id);
6045
6264
  }
6265
+ function hasViteServeCssGenerationDirective(code) {
6266
+ return require_v4_engine.hasTailwindRootDirectives(code) || require_v4_engine.hasTailwindSourceDirectives(code, { importFallback: true }) || require_v4_engine.hasTailwindApplyDirective(code);
6267
+ }
6268
+ function hasViteServeCssRootDirective(code) {
6269
+ return require_v4_engine.hasTailwindRootDirectives(code);
6270
+ }
6046
6271
  function createViteServeCssGenerationPlugins(options) {
6047
6272
  return [{
6048
6273
  name: `${require_context.vitePluginName}:generate:serve`,
@@ -6067,7 +6292,8 @@ function createViteServeCssGenerationPlugins(options) {
6067
6292
  if (!options.shouldGenerate() || !isViteCssHmrModule(code, id, options.getCommand())) return;
6068
6293
  const extracted = extractViteCssHmrModuleCss(code);
6069
6294
  if (!extracted) return;
6070
- await options.onTailwindRootCss?.(id, extracted.css);
6295
+ if (!hasViteServeCssGenerationDirective(extracted.css)) return;
6296
+ if (hasViteServeCssRootDirective(extracted.css)) await options.onTailwindRootCss?.(id, extracted.css);
6071
6297
  const generatedCss = await options.generateCss(id, extracted.css, this);
6072
6298
  if (generatedCss === void 0 || generatedCss === extracted.css) return;
6073
6299
  const nextCode = replaceViteCssHmrModuleCss(code, generatedCss);
@@ -6126,7 +6352,7 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
6126
6352
  return resolvedRoot;
6127
6353
  }
6128
6354
  //#endregion
6129
- //#region src/bundlers/vite/index.ts
6355
+ //#region src/bundlers/vite/shared/create-framework-plugins.ts
6130
6356
  const debug = require_context.createDebug();
6131
6357
  const weappTailwindcssPackageDir = require_source_candidate_scan_signature.resolvePackageDir("weapp-tailwindcss");
6132
6358
  const weappTailwindcssDirPosix = require_source_candidate_scan_signature.slash(weappTailwindcssPackageDir);
@@ -6165,23 +6391,22 @@ function inferPlatformFromOutDir(outDir) {
6165
6391
  function isWebOrNativeAppPlatform(platform) {
6166
6392
  return platform === "h5" || platform === "web" || platform?.startsWith("web-") === true || platform === "app" || platform === "app-plus" || platform?.startsWith("app-") === true;
6167
6393
  }
6168
- function isUniAppViteWebviewStylePlatform(platform) {
6169
- return platform === "app" || platform === "app-plus";
6394
+ function applyViteWebCssCompat(css, options) {
6395
+ return (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(css, options.compat);
6170
6396
  }
6171
- function applyUniAppViteWebviewCssCompat(css, options) {
6172
- const compatCss = (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(css, options.compat);
6173
- return options.safeSelectors ? (0, _weapp_tailwindcss_postcss.transformWebCssSafeSelectors)(compatCss, { escapeMap: options.escapeMap }) : compatCss;
6397
+ function isInternalUserDefinedOptions(options) {
6398
+ return typeof options.onLoad === "function" && typeof options.mainCssChunkMatcher === "function" && typeof options.tailwindRuntime === "object" && typeof options.refreshTailwindcssRuntime === "function";
6174
6399
  }
6175
6400
  /**
6176
- * @name WeappTailwindcss
6177
- * @description uni-app vite / uni-app-x 版本插件
6178
- * @link https://tw.icebreaker.top/docs/quick-start/frameworks/uni-app-vite
6401
+ * Vite 各框架分支共享的组合工厂。框架分支只负责选择和拥有各自入口,公共稳定能力放在这里复用。
6179
6402
  */
6180
- function WeappTailwindcss(options = {}) {
6181
- const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
6182
- const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
6183
- const rawCssEntries = collectConfiguredCssEntries(options);
6184
- const opts = require_context.getCompilerContext({
6403
+ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
6404
+ debug("create vite framework plugins framework=%s", frameworkBranch.frameworkName);
6405
+ const rawOptions = options.__internalViteRawOptions ?? options;
6406
+ const hasExplicitAppType = typeof options.__internalViteRawExplicitAppType === "boolean" ? options.__internalViteRawExplicitAppType : typeof options.appType === "string" && options.appType.trim().length > 0;
6407
+ const hasExplicitTailwindcssBasedir = typeof options.__internalViteRawExplicitTailwindcssBasedir === "boolean" ? options.__internalViteRawExplicitTailwindcssBasedir : typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
6408
+ const rawCssEntries = collectConfiguredCssEntries(rawOptions);
6409
+ const opts = isInternalUserDefinedOptions(options) ? options : require_context.getCompilerContext({
6185
6410
  ...options,
6186
6411
  __internalDeferMissingCssEntriesWarning: true
6187
6412
  });
@@ -6202,7 +6427,9 @@ function WeappTailwindcss(options = {}) {
6202
6427
  const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler, tailwindRuntime, refreshTailwindcssRuntime, uniAppX, disabledDefaultTemplateHandler, styleInjector } = opts;
6203
6428
  const initialTailwindRuntime = tailwindRuntime;
6204
6429
  const refreshTailwindRuntime = refreshTailwindcssRuntime;
6205
- const uniAppXEnabled = require_tailwindcss.isUniAppXEnabled(uniAppX);
6430
+ const frameworkCssPipelineStrategy = frameworkBranch.cssPipelineStrategy;
6431
+ const uniAppXEnabled = frameworkBranch.isRuntimeClassSetFeatureEnabled?.({ uniAppX }) === true;
6432
+ const shouldEnableFrameworkExtraPlugins = () => frameworkBranch.createExtraPlugins !== void 0;
6206
6433
  const disabledOptions = require_source_candidate_scan_signature.resolvePluginDisabledState(disabled);
6207
6434
  const tailwindcssMajorVersion = initialTailwindRuntime.majorVersion ?? 0;
6208
6435
  if (!disabledOptions.plugin && tailwindcssMajorVersion !== 4) throw new Error("weapp-tailwindcss/vite 新生成管线仅支持 Tailwind CSS v4,请升级 tailwindcss 或停留在旧版 weapp-tailwindcss。");
@@ -6231,6 +6458,14 @@ function WeappTailwindcss(options = {}) {
6231
6458
  tailwindcssMajorVersion,
6232
6459
  uniAppX
6233
6460
  });
6461
+ const createCssPipelineContext = (overrides = {}) => ({
6462
+ currentGeneratorBranch: resolveCurrentGeneratorBranch(),
6463
+ currentGeneratorOptions: resolveCurrentGeneratorOptions(),
6464
+ opts,
6465
+ resolvedConfig,
6466
+ resolveStylePlatform: resolveViteStylePlatform,
6467
+ ...overrides
6468
+ });
6234
6469
  const initialGeneratorBranch = resolveCurrentGeneratorBranch();
6235
6470
  const transformEarlyMiniProgramCss = (code) => {
6236
6471
  const platform = resolveViteStylePlatform();
@@ -6247,8 +6482,8 @@ function WeappTailwindcss(options = {}) {
6247
6482
  };
6248
6483
  const shouldInferAppType = !hasExplicitAppType && !initialGeneratorBranch.isWeb;
6249
6484
  const hasInitialTailwindCssRoots = require_v4_engine.hasConfiguredTailwindV4CssRoots({
6250
- ...options,
6251
- cssEntries: opts.cssEntries ?? options.cssEntries
6485
+ ...rawOptions,
6486
+ cssEntries: opts.cssEntries ?? rawOptions.cssEntries
6252
6487
  });
6253
6488
  const autoCssSourceContent = /* @__PURE__ */ new Map();
6254
6489
  const transientAutoCssSources = /* @__PURE__ */ new Map();
@@ -6564,10 +6799,6 @@ function WeappTailwindcss(options = {}) {
6564
6799
  const isUniViteProject = () => {
6565
6800
  return resolvedConfig?.plugins?.some((plugin) => plugin.name.includes("uni")) ?? false;
6566
6801
  };
6567
- const isHarmonyAppBuildTarget = () => {
6568
- if (require_utils.resolveUniUtsPlatform().isAppHarmony) return true;
6569
- return isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir);
6570
- };
6571
6802
  const matchesViteProcessedCssSource = (candidate) => {
6572
6803
  const normalized = normalizeViteProcessedCssFile(candidate);
6573
6804
  return viteProcessedCssSourceFiles.has(normalized);
@@ -6587,7 +6818,10 @@ function WeappTailwindcss(options = {}) {
6587
6818
  getOutputRoot: () => resolvedConfig?.build?.outDir ? node_path.default.resolve(resolvedConfig.root, resolvedConfig.build.outDir) : resolvedConfig?.root,
6588
6819
  getExtraOptions: (file) => ({
6589
6820
  ...resolveViteCssHandlerExtraOptions(file),
6590
- ...resolveUniAppXNativeCssHandlerOptions(opts)
6821
+ ...frameworkCssPipelineStrategy?.getCssHandlerExtraOptions?.({
6822
+ ...createCssPipelineContext(),
6823
+ file
6824
+ }) ?? {}
6591
6825
  }),
6592
6826
  getDynamicCssOptions: () => ({ cssPreflight: opts.cssPreflight })
6593
6827
  });
@@ -6600,20 +6834,24 @@ function WeappTailwindcss(options = {}) {
6600
6834
  await runtimeState.readyPromise;
6601
6835
  await waitForSourceCandidateSyncs();
6602
6836
  const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
6603
- const requestFile = require_source_candidate_scan_signature.isCSSRequest(id) ? id : file;
6837
+ const requestFile = require_source_candidate_scan_signature.isCSSRequest(id) ? id === file ? resolveSfcStyleRequestFromKnownSource(file, cssMemory.getKnownSfcSource(file), code) : id : file;
6604
6838
  if (!require_source_candidate_scan_signature.isCSSRequest(requestFile) || opts.htmlMatcher(file) || require_source_candidate_scan_signature.isHTMLRequest(file)) return;
6605
6839
  const generatorCode = require_v4_engine.normalizeEmptyTailwindCustomVariants(code);
6606
6840
  const rootDir = resolvedConfig?.root ? node_path.default.resolve(resolvedConfig.root) : node_process.default.cwd();
6607
- const isHarmonyAppStyleTarget = isHarmonyAppBuildTarget();
6608
- const isNativeAppStyleTarget = opts.appType === "uni-app-x" && (require_utils.resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget);
6609
- const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
6610
6841
  const currentGeneratorOptions = resolveCurrentGeneratorOptions();
6611
6842
  const currentGeneratorBranch = resolveCurrentGeneratorBranch();
6612
- const outputFile = resolveViteCssPipelineOutputFile(requestFile, opts, rootDir, currentGeneratorBranch.isWeb, isNativeAppStyleTarget, sourceRoot);
6843
+ const cssPipelineContext = createCssPipelineContext({
6844
+ currentGeneratorBranch,
6845
+ currentGeneratorOptions
6846
+ });
6847
+ const shouldPreserveStyleOutputExtension = frameworkCssPipelineStrategy?.shouldPreserveStyleOutputExtension?.(cssPipelineContext) ?? frameworkCssPipelineStrategy?.isNativeAppStyleTarget?.(cssPipelineContext) === true;
6848
+ const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
6849
+ const outputFile = resolveViteCssPipelineOutputFile(requestFile, opts, rootDir, currentGeneratorBranch.isWeb, shouldPreserveStyleOutputExtension, sourceRoot);
6613
6850
  const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
6851
+ const sourceCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(requestFile);
6614
6852
  const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
6615
6853
  const cssHandlerOptions = {
6616
- ...transformCssHandlerOptions.getCssHandlerOptions(file),
6854
+ ...sourceCssHandlerOptions,
6617
6855
  isMainChunk: outputCssHandlerOptions.isMainChunk
6618
6856
  };
6619
6857
  const transientCssSource = transientAutoCssSources.get(file) ?? (require_v4_engine.hasTailwindRootDirectives(generatorCode, { importFallback: currentGeneratorOptions.importFallback }) || require_v4_engine.hasTailwindSourceDirectives(generatorCode, { importFallback: currentGeneratorOptions.importFallback }) || require_v4_engine.hasTailwindApplyDirective(generatorCode) ? {
@@ -6621,7 +6859,11 @@ function WeappTailwindcss(options = {}) {
6621
6859
  css: generatorCode,
6622
6860
  file: node_path.default.resolve(file)
6623
6861
  } : void 0);
6624
- const shouldDeferEmptyScopedCssSource = transientCssSource == null && !(opts.appType === "uni-app-x" && !cssHandlerOptions.isMainChunk && require_v4_engine.hasTailwindApplyDirective(generatorCode));
6862
+ const shouldDeferEmptyScopedCssSource = transientCssSource == null && (frameworkCssPipelineStrategy?.shouldDeferEmptyScopedCssSource?.({
6863
+ ...cssPipelineContext,
6864
+ cssHandlerOptions,
6865
+ generatorCode
6866
+ }) ?? true);
6625
6867
  const generated = await require_source_candidate_scan_signature.generateTailwindV4Css({
6626
6868
  opts,
6627
6869
  runtimeState,
@@ -6630,7 +6872,7 @@ function WeappTailwindcss(options = {}) {
6630
6872
  file,
6631
6873
  outputFile,
6632
6874
  cssHandlerOptions,
6633
- cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(file),
6875
+ cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(requestFile),
6634
6876
  cssSources: transientCssSource ? [transientCssSource] : void 0,
6635
6877
  getSourceCandidatesForEntries,
6636
6878
  generatorPlatform: resolveGeneratorPlatform(),
@@ -6642,12 +6884,13 @@ function WeappTailwindcss(options = {}) {
6642
6884
  });
6643
6885
  if (!generated) return;
6644
6886
  const finalizedCss = finalizeViteMiniProgramCss(generated.css);
6645
- const isUniAppViteWebviewPlatform = opts.appType === "uni-app-vite" && isUniAppViteWebviewStylePlatform(resolveViteStylePlatform());
6646
- const tracedCss = require_hmr_timing.annotateCssSourceTrace(removeScopedTailwindPreflightCss(currentGeneratorBranch.isWeb || isUniAppViteWebviewPlatform ? applyUniAppViteWebviewCssCompat(finalizedCss, {
6647
- compat: currentGeneratorOptions.webCompat ?? true,
6648
- escapeMap: opts.escapeMap,
6649
- safeSelectors: isUniAppViteWebviewPlatform
6650
- }) : finalizedCss), {
6887
+ const shouldApplyWebCssCompat = currentGeneratorBranch.isWeb || frameworkCssPipelineStrategy?.shouldApplyWebCssCompat?.(cssPipelineContext) === true;
6888
+ const tracedCss = require_hmr_timing.annotateCssSourceTrace(frameworkCssPipelineStrategy?.transformGeneratedCss?.(finalizedCss, {
6889
+ ...cssPipelineContext,
6890
+ defaultWebCssCompat: (css) => applyViteWebCssCompat(css, { compat: currentGeneratorOptions.webCompat ?? true }),
6891
+ removeScopedPreflight: removeScopedTailwindPreflightCss,
6892
+ shouldApplyWebCssCompat
6893
+ }) ?? removeScopedTailwindPreflightCss(shouldApplyWebCssCompat ? applyViteWebCssCompat(finalizedCss, { compat: currentGeneratorOptions.webCompat ?? true }) : finalizedCss), {
6651
6894
  opts,
6652
6895
  tokenSources: require_hmr_timing.createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts)
6653
6896
  });
@@ -6662,7 +6905,7 @@ function WeappTailwindcss(options = {}) {
6662
6905
  injectIntoMain: shouldInjectGeneratedCssIntoMain,
6663
6906
  outputFile
6664
6907
  });
6665
- if (isNativeAppStyleTarget && outputFile.endsWith(".css")) hookContext?.emitFile?.({
6908
+ if (shouldPreserveStyleOutputExtension && outputFile.endsWith(".css")) hookContext?.emitFile?.({
6666
6909
  type: "asset",
6667
6910
  fileName: outputFile,
6668
6911
  source: tracedCss
@@ -6673,9 +6916,9 @@ function WeappTailwindcss(options = {}) {
6673
6916
  cssMemory.rememberCssSource({
6674
6917
  outputFile,
6675
6918
  rawSource: code,
6676
- sourceFile: id
6919
+ sourceFile: requestFile
6677
6920
  });
6678
- debug("css generated for vite postcss pipeline: %s bytes=%d", file, tracedCss.length);
6921
+ debug("css generated for vite postcss pipeline: %s bytes=%d", requestFile, tracedCss.length);
6679
6922
  return `${require_source_candidate_scan_signature.createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}\n${tracedCss}`;
6680
6923
  };
6681
6924
  const rewritePlugins = createRewriteCssImportsPlugins({
@@ -6721,12 +6964,14 @@ function WeappTailwindcss(options = {}) {
6721
6964
  recordGeneratorCandidates,
6722
6965
  pruneViteCssCaches,
6723
6966
  getViteCssCacheStats,
6724
- hmrTimingRecorder
6967
+ hmrTimingRecorder,
6968
+ cssPipelineStrategy: frameworkCssPipelineStrategy
6725
6969
  });
6726
6970
  const cssFinalizerOutputPlugin = createViteCssFinalizerOutputPlugin({
6727
6971
  opts,
6728
6972
  runtimeState,
6729
6973
  ensureRuntimeClassSet,
6974
+ cssPipelineStrategy: frameworkCssPipelineStrategy,
6730
6975
  debug,
6731
6976
  getResolvedConfig,
6732
6977
  markCssAssetProcessed,
@@ -6747,25 +6992,25 @@ function WeappTailwindcss(options = {}) {
6747
6992
  }),
6748
6993
  getRememberedMainCssSource: cssMemory.getRememberedCssSourceEntry
6749
6994
  });
6750
- const isIosPlatform = require_utils.resolveUniUtsPlatform().isAppIos;
6995
+ const extraPluginPlatform = frameworkBranch.getExtraPluginPlatform?.() ?? {};
6751
6996
  const prepareTailwindGeneration = async () => {
6752
6997
  if (shouldDiscoverAutoCssSources()) await discoverAndRegisterAutoCssSources();
6753
6998
  await syncSourceCandidateScan();
6754
6999
  };
6755
- const uniAppXPlugins = uniAppXEnabled ? createUniAppXPlugins({
6756
- appType: opts.appType ?? "uni-app-x",
7000
+ const extraPlugins = frameworkBranch.createExtraPlugins?.({
6757
7001
  customAttributesEntities,
6758
7002
  disabledDefaultTemplateHandler,
6759
- isIosPlatform,
7003
+ ensureRuntimeClassSet,
7004
+ generateCss: generateTailwindCssForVitePipeline,
7005
+ getResolvedConfig,
7006
+ isEnabled: shouldEnableFrameworkExtraPlugins,
7007
+ isIosPlatform: extraPluginPlatform.isIosPlatform === true,
7008
+ jsHandler,
6760
7009
  mainCssChunkMatcher,
6761
7010
  runtimeState,
6762
7011
  styleHandler,
6763
- generateCss: generateTailwindCssForVitePipeline,
6764
- jsHandler,
6765
- ensureRuntimeClassSet,
6766
- getResolvedConfig,
6767
7012
  uniAppX
6768
- }) : void 0;
7013
+ }) ?? [];
6769
7014
  const plugins = [
6770
7015
  ...rewritePlugins,
6771
7016
  {
@@ -6864,10 +7109,13 @@ function WeappTailwindcss(options = {}) {
6864
7109
  shouldGenerate: () => shouldOwnTailwindGeneration
6865
7110
  }),
6866
7111
  createViteServeJsTransformPlugin({
6867
- createHandlerOptions: (file) => serveJsHandlerOptions(file, opts.appType === "uni-app-vite" && isUniAppViteWebviewStylePlatform(resolveViteStylePlatform()) ? { needEscaped: true } : void 0),
7112
+ createHandlerOptions: (file) => serveJsHandlerOptions(file, frameworkCssPipelineStrategy?.getServeJsHandlerOptions?.({
7113
+ ...createCssPipelineContext(),
7114
+ file
7115
+ })),
6868
7116
  getCommand: () => resolvedConfig?.command,
6869
7117
  jsHandler,
6870
- shouldTransform: () => shouldOwnTailwindGeneration && (!resolveCurrentGeneratorBranch().isWeb || opts.appType === "uni-app-vite" && isUniAppViteWebviewStylePlatform(resolveViteStylePlatform())),
7118
+ shouldTransform: () => shouldOwnTailwindGeneration && (frameworkCssPipelineStrategy?.shouldTransformServeJs?.(createCssPipelineContext()) ?? !resolveCurrentGeneratorBranch().isWeb),
6871
7119
  transformRuntime: ensureRuntimeClassSet
6872
7120
  }),
6873
7121
  {
@@ -6942,12 +7190,306 @@ function WeappTailwindcss(options = {}) {
6942
7190
  }
6943
7191
  }
6944
7192
  ];
6945
- if (uniAppXPlugins) plugins.push(...uniAppXPlugins);
7193
+ plugins.push(...extraPlugins);
6946
7194
  plugins.push(cssFinalizerOutputPlugin);
6947
- plugins.push(...require_source_candidate_scan_signature.createBuiltinViteStyleInjectorPlugins(styleInjector, () => opts.appType));
7195
+ plugins.push(...require_source_candidate_scan_signature.createBuiltinViteStyleInjectorPlugins(styleInjector, () => frameworkBranch.styleInjectorDelegate));
6948
7196
  return plugins;
6949
7197
  }
6950
7198
  //#endregion
7199
+ //#region src/bundlers/vite/frameworks/generic/index.ts
7200
+ function createGenericVitePlugins(options = {}) {
7201
+ return createViteFrameworkPlugins(options, {
7202
+ frameworkName: "generic",
7203
+ styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.generic
7204
+ });
7205
+ }
7206
+ //#endregion
7207
+ //#region src/bundlers/vite/frameworks/taro/index.ts
7208
+ const taroCssPipelineStrategy = {
7209
+ shouldKeepRootMiniProgramStyleAsImportShell() {
7210
+ return true;
7211
+ },
7212
+ shouldMoveRootMiniProgramStyleToImportShellOrigin() {
7213
+ return true;
7214
+ },
7215
+ shouldNormalizeRootMiniProgramImportShell() {
7216
+ return true;
7217
+ }
7218
+ };
7219
+ function createTaroAlipayBrowserslistAssetPlugin() {
7220
+ return {
7221
+ name: "weapp-tailwindcss:taro-alipay-browserslist-asset",
7222
+ enforce: "pre",
7223
+ generateBundle(_options, bundle) {
7224
+ if (node_process.default.env.TARO_ENV !== "alipay") return;
7225
+ bundle[".browserslistrc"] = {
7226
+ type: "asset",
7227
+ fileName: ".browserslistrc",
7228
+ source: "defaults and fully supports es6-module"
7229
+ };
7230
+ }
7231
+ };
7232
+ }
7233
+ function createTaroVitePlugins(options = {}) {
7234
+ return [createTaroAlipayBrowserslistAssetPlugin(), ...createViteFrameworkPlugins(options, {
7235
+ frameworkName: "taro",
7236
+ cssPipelineStrategy: taroCssPipelineStrategy,
7237
+ styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.taro
7238
+ })];
7239
+ }
7240
+ //#endregion
7241
+ //#region src/bundlers/vite/frameworks/uni-app/index.ts
7242
+ function isUniAppWebviewStylePlatform(platform) {
7243
+ return platform === "app" || platform === "app-plus";
7244
+ }
7245
+ function isUniAppWebviewAppBundle(bundleFiles) {
7246
+ return bundleFiles.some((file) => node_path.default.basename(file.replace(/[?#].*$/, "")) === "app-service.js");
7247
+ }
7248
+ function isUniAppWebviewOutDir(outDir) {
7249
+ const normalized = outDir ? node_path.default.basename(node_path.default.normalize(outDir)).trim().toLowerCase() : void 0;
7250
+ return normalized === "app" || normalized === "app-plus";
7251
+ }
7252
+ const uniAppCssPipelineStrategy = {
7253
+ getServeJsHandlerOptions(context) {
7254
+ return isUniAppWebviewStylePlatform(context.resolveStylePlatform()) ? { needEscaped: true } : void 0;
7255
+ },
7256
+ shouldApplyWebCssCompat(context) {
7257
+ return isUniAppWebviewStylePlatform(context.resolveStylePlatform());
7258
+ },
7259
+ includeTailwindGeneratedCssAssetsInRootCoverage(context) {
7260
+ return context.isWebGeneratorTarget && isUniAppWebviewAppBundle(context.bundleFiles);
7261
+ },
7262
+ resolveConfiguredCssEntryRootInjectionTarget(context) {
7263
+ if (context.isMiniProgramStyleOutputFile(context.outputFile) || !context.isConfiguredCssEntryFile(context.sourceFile)) return;
7264
+ const rootCssFiles = [];
7265
+ const matchedRootCssFiles = [];
7266
+ for (const [bundleFile, output] of Object.entries(context.bundle)) {
7267
+ if (output.type !== "asset") continue;
7268
+ const file = output.fileName || bundleFile;
7269
+ if (!context.opts.cssMatcher(file) || !context.isRootStyleOutputFile(file) || context.isMiniProgramStyleOutputFile(file)) continue;
7270
+ rootCssFiles.push(file);
7271
+ if (context.opts.mainCssChunkMatcher(file, context.opts.appType)) matchedRootCssFiles.push(file);
7272
+ }
7273
+ if (matchedRootCssFiles.length === 1) return matchedRootCssFiles[0];
7274
+ if (matchedRootCssFiles.length > 1) return;
7275
+ return rootCssFiles.length === 1 ? rootCssFiles[0] : void 0;
7276
+ },
7277
+ shouldApplyFinalWebviewCssCompat(context) {
7278
+ return isUniAppWebviewAppBundle(context.bundleFiles) || isUniAppWebviewOutDir(context.outDir);
7279
+ },
7280
+ shouldKeepRootMiniProgramStyleAsImportShell() {
7281
+ return true;
7282
+ },
7283
+ shouldPreferExplicitWebCssTargets() {
7284
+ return true;
7285
+ },
7286
+ shouldPreferMatchedRootWebOutputTarget() {
7287
+ return true;
7288
+ },
7289
+ shouldRemoveDuplicateUnlinkedRootCssAssetsReferencedByHtml(context) {
7290
+ return context.isWebGeneratorTarget && isUniAppWebviewAppBundle(context.bundleFiles);
7291
+ },
7292
+ shouldSelectConfiguredCssEntryRootSource(context) {
7293
+ return context.currentGeneratorBranch.isWeb && context.opts.cssMatcher(context.outputFile) && context.isRootStyleOutputFile(context.outputFile);
7294
+ },
7295
+ shouldTransformServeJs(context) {
7296
+ return !context.currentGeneratorBranch.isWeb || isUniAppWebviewStylePlatform(context.resolveStylePlatform());
7297
+ },
7298
+ transformGeneratedCss(css, context) {
7299
+ const webCss = context.shouldApplyWebCssCompat ? (0, _weapp_tailwindcss_postcss.transformWebCssCompat)(css, context.currentGeneratorBranch.isWeb ? context.currentGeneratorOptions.webCompat : context.currentGeneratorOptions.webCompat ?? true) : css;
7300
+ const safeCss = isUniAppWebviewStylePlatform(context.resolveStylePlatform()) ? (0, _weapp_tailwindcss_postcss.transformWebCssSafeSelectors)(webCss, { escapeMap: context.opts.escapeMap }) : webCss;
7301
+ return context.removeScopedPreflight(safeCss);
7302
+ }
7303
+ };
7304
+ function createUniAppVitePlugins(options = {}) {
7305
+ return createViteFrameworkPlugins(options, {
7306
+ frameworkName: "uni-app",
7307
+ cssPipelineStrategy: uniAppCssPipelineStrategy,
7308
+ styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.uniApp
7309
+ });
7310
+ }
7311
+ const UNI_APP_X_WEB_PREFLIGHT_RESET_CSS = [`/* weapp-tailwindcss uni-app-x web preflight reset */`, `${[
7312
+ "uni-ad-draw",
7313
+ "uni-ad-fullscreen-video",
7314
+ "uni-ad-interactive",
7315
+ "uni-ad-interstitial",
7316
+ "uni-ad-rewarded-video",
7317
+ "uni-ad",
7318
+ "uni-animation-view",
7319
+ "uni-audio",
7320
+ "uni-block",
7321
+ "uni-button",
7322
+ "uni-camera",
7323
+ "uni-canvas",
7324
+ "uni-checkbox-group",
7325
+ "uni-checkbox",
7326
+ "uni-cover-image",
7327
+ "uni-cover-view",
7328
+ "uni-custom-tab-bar",
7329
+ "uni-editor",
7330
+ "uni-form",
7331
+ "uni-icon",
7332
+ "uni-image",
7333
+ "uni-input",
7334
+ "uni-label",
7335
+ "uni-list-item",
7336
+ "uni-list-view",
7337
+ "uni-live-player",
7338
+ "uni-live-pusher",
7339
+ "uni-map",
7340
+ "uni-match-media",
7341
+ "uni-movable-area",
7342
+ "uni-movable-view",
7343
+ "uni-navigation-bar",
7344
+ "uni-navigator",
7345
+ "uni-open-data",
7346
+ "uni-page-meta",
7347
+ "uni-picker-view",
7348
+ "uni-picker",
7349
+ "uni-progress",
7350
+ "uni-radio-group",
7351
+ "uni-radio",
7352
+ "uni-rich-text",
7353
+ "uni-scroll-view",
7354
+ "uni-slider",
7355
+ "uni-sticky-header",
7356
+ "uni-sticky-section",
7357
+ "uni-swiper-item",
7358
+ "uni-swiper",
7359
+ "uni-switch",
7360
+ "uni-template",
7361
+ "uni-text",
7362
+ "uni-textarea",
7363
+ "uni-unicloud-db",
7364
+ "uni-video",
7365
+ "uni-view",
7366
+ "uni-web-view"
7367
+ ].map((tag) => `uni-app ${tag}`).join(", ")}{border-width:0;}`].join("\n");
7368
+ const TAILWIND_PREFLIGHT_BORDER_RE = /\bborder\s*:\s*0(?:px)?\s+solid\b/;
7369
+ function withUniAppXWebPreflightReset(css, enabled) {
7370
+ if (!enabled || css.includes("weapp-tailwindcss uni-app-x web preflight reset") || !TAILWIND_PREFLIGHT_BORDER_RE.test(css)) return css;
7371
+ return css.length > 0 ? `${UNI_APP_X_WEB_PREFLIGHT_RESET_CSS}\n${css}` : UNI_APP_X_WEB_PREFLIGHT_RESET_CSS;
7372
+ }
7373
+ //#endregion
7374
+ //#region src/bundlers/vite/uni-app-x-css-options.ts
7375
+ function resolveUniAppXNativeCssHandlerOptions(opts) {
7376
+ const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
7377
+ if (!require_generator.shouldUseNativeAppCssBranch(require_generator.resolveGeneratorRuntimeBranch(require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
7378
+ appType: opts.appType,
7379
+ platform: opts.cssOptions?.platform ?? opts.platform,
7380
+ uniAppX: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX),
7381
+ uniUtsPlatform
7382
+ }), {
7383
+ appType: opts.appType,
7384
+ platform: opts.cssOptions?.platform ?? opts.platform,
7385
+ uniAppX: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX),
7386
+ uniUtsPlatform
7387
+ })) || !require_tailwindcss.isUniAppXEnabled(opts.uniAppX)) return {};
7388
+ return {
7389
+ uniAppX: true,
7390
+ uniAppXCssTarget: "uvue",
7391
+ uniAppXUnsupported: require_tailwindcss.resolveUniAppXOptions(opts.uniAppX).uvueUnsupported
7392
+ };
7393
+ }
7394
+ //#endregion
7395
+ //#region src/bundlers/vite/frameworks/uni-app-x/index.ts
7396
+ function isUniAppXNativeAppStyleTarget() {
7397
+ return require_utils.resolveUniUtsPlatform().isApp;
7398
+ }
7399
+ function isUniAppXHarmonyAppStyleTarget(context) {
7400
+ const uniUtsPlatform = require_utils.resolveUniUtsPlatform();
7401
+ const canInferHarmonyAppStyleTarget = !uniUtsPlatform.normalized || uniUtsPlatform.isApp;
7402
+ return uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (context.bundle != null && isUniAppXHarmonyBundle(context.bundle) || isUniAppXHarmonyOutDir(context.resolvedConfig?.build?.outDir));
7403
+ }
7404
+ const uniAppXCssPipelineStrategy = {
7405
+ getCssHandlerExtraOptions(context) {
7406
+ return resolveUniAppXNativeCssHandlerOptions(context.opts);
7407
+ },
7408
+ isNativeAppStyleTarget() {
7409
+ return isUniAppXNativeAppStyleTarget();
7410
+ },
7411
+ isHarmonyAppStyleTarget(context) {
7412
+ return isUniAppXHarmonyAppStyleTarget(context);
7413
+ },
7414
+ shouldPreserveStyleOutputExtension(context) {
7415
+ return isUniAppXNativeAppStyleTarget() || isUniAppXHarmonyAppStyleTarget(context);
7416
+ },
7417
+ shouldKeepRootMiniProgramStyleAsImportShell() {
7418
+ return true;
7419
+ },
7420
+ shouldDeferEmptyScopedCssSource(context) {
7421
+ if (!context.cssHandlerOptions.isMainChunk && require_v4_engine.hasTailwindApplyDirective(context.generatorCode)) return false;
7422
+ return true;
7423
+ },
7424
+ transformGeneratedCss(css, context) {
7425
+ const webCss = context.shouldApplyWebCssCompat ? context.defaultWebCssCompat(css) : css;
7426
+ return withUniAppXWebPreflightReset(context.removeScopedPreflight(webCss), context.currentGeneratorBranch.isWeb);
7427
+ }
7428
+ };
7429
+ function createUniAppXVitePlugins(options = {}) {
7430
+ return createViteFrameworkPlugins(options, {
7431
+ frameworkName: "uni-app-x",
7432
+ cssPipelineStrategy: uniAppXCssPipelineStrategy,
7433
+ getExtraPluginPlatform: () => ({ isIosPlatform: require_utils.resolveUniUtsPlatform().isAppIos }),
7434
+ styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.uniApp,
7435
+ isRuntimeClassSetFeatureEnabled: () => true,
7436
+ createExtraPlugins: (context) => createUniAppXPlugins({
7437
+ appType: "uni-app-x",
7438
+ customAttributesEntities: context.customAttributesEntities,
7439
+ disabledDefaultTemplateHandler: context.disabledDefaultTemplateHandler,
7440
+ ensureRuntimeClassSet: context.ensureRuntimeClassSet,
7441
+ generateCss: context.generateCss,
7442
+ getResolvedConfig: context.getResolvedConfig,
7443
+ isEnabled: context.isEnabled,
7444
+ isIosPlatform: context.isIosPlatform,
7445
+ jsHandler: context.jsHandler,
7446
+ mainCssChunkMatcher: context.mainCssChunkMatcher,
7447
+ runtimeState: context.runtimeState,
7448
+ styleHandler: context.styleHandler,
7449
+ uniAppX: context.uniAppX
7450
+ })
7451
+ });
7452
+ }
7453
+ //#endregion
7454
+ //#region src/bundlers/vite/frameworks/weapp-vite/index.ts
7455
+ function createWeappVitePlugins(options = {}) {
7456
+ return createViteFrameworkPlugins(options, {
7457
+ frameworkName: "weapp-vite",
7458
+ styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.generic
7459
+ });
7460
+ }
7461
+ //#endregion
7462
+ //#region src/bundlers/vite/index.ts
7463
+ /**
7464
+ * @name WeappTailwindcss
7465
+ * @description Vite 入口只负责早期识别框架分支,具体插件组合由各 framework 目录拥有。
7466
+ * @link https://tw.icebreaker.top/docs/quick-start/frameworks/uni-app-vite
7467
+ */
7468
+ function WeappTailwindcss(options = {}) {
7469
+ const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
7470
+ const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
7471
+ const opts = require_context.getCompilerContext({
7472
+ ...options,
7473
+ __internalDeferMissingCssEntriesWarning: true
7474
+ });
7475
+ opts.__internalViteRawOptions = options;
7476
+ opts.__internalViteRawExplicitAppType = hasExplicitAppType;
7477
+ opts.__internalViteRawExplicitTailwindcssBasedir = hasExplicitTailwindcssBasedir;
7478
+ switch (require_source_candidate_scan_signature.resolveViteFrameworkProfile({
7479
+ appType: opts.appType,
7480
+ detectEnv: true,
7481
+ env: node_process.default.env,
7482
+ root: opts.tailwindcssBasedir ?? node_process.default.cwd(),
7483
+ uniAppX: opts.uniAppX
7484
+ }).frameworkName) {
7485
+ case "taro": return createTaroVitePlugins(opts);
7486
+ case "uni-app": return createUniAppVitePlugins(opts);
7487
+ case "uni-app-x": return createUniAppXVitePlugins(opts);
7488
+ case "weapp-vite": return createWeappVitePlugins(opts);
7489
+ default: return createGenericVitePlugins(opts);
7490
+ }
7491
+ }
7492
+ //#endregion
6951
7493
  Object.defineProperty(exports, "WeappTailwindcss", {
6952
7494
  enumerable: true,
6953
7495
  get: function() {