weapp-tailwindcss 5.0.0-next.2 → 5.0.0-next.20
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.
- package/README.md +6 -7
- package/bin/weapp-tailwindcss.js +1 -21
- package/dist/bundle-state-BlXvU4jl.js +530 -0
- package/dist/bundle-state-PO6MysTJ.mjs +414 -0
- package/dist/bundlers/shared/cache.d.ts +6 -6
- package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +2 -0
- package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +3 -0
- package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +5 -0
- package/dist/bundlers/shared/css-cleanup/selectors.d.ts +8 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +7 -3
- package/dist/bundlers/shared/css-imports.d.ts +3 -3
- package/dist/bundlers/shared/generated-css-marker.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +20 -0
- package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
- package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
- package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/markers.d.ts +28 -0
- package/dist/bundlers/shared/generator-css/source-files.d.ts +14 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +24 -0
- package/dist/bundlers/shared/generator-css.d.ts +16 -22
- package/dist/bundlers/shared/hmr-timing.d.ts +22 -0
- package/dist/bundlers/shared/style-requests.d.ts +2 -0
- package/dist/bundlers/vite/bundle-state.d.ts +1 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +7 -1
- package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +24 -0
- package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
- package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
- package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +14 -2
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +5 -1
- package/dist/bundlers/vite/index.d.ts +1 -1
- package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
- package/dist/bundlers/vite/postcss-config.d.ts +6 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +32 -0
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +8 -3
- package/dist/bundlers/vite/runtime-class-set.d.ts +25 -0
- package/dist/bundlers/vite/source-candidates.d.ts +16 -1
- package/dist/bundlers/vite/source-scan.d.ts +26 -0
- package/dist/bundlers/vite/static-config-content.d.ts +5 -0
- package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +6 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +6 -2
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +9 -3
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -0
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +31 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +2 -6
- package/dist/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.d.ts +3 -7
- package/dist/cache/index.d.ts +6 -6
- package/dist/cli/context.d.ts +1 -14
- package/dist/cli/doctor/types.d.ts +11 -11
- package/dist/cli/helpers.d.ts +1 -2
- package/dist/cli/mount-options.d.ts +2 -0
- package/dist/cli/types.d.ts +0 -2
- package/dist/cli/vscode-entry.d.ts +3 -3
- package/dist/cli.js +605 -611
- package/dist/cli.mjs +614 -620
- package/dist/constants.d.ts +1 -2
- package/dist/core.js +13 -20
- package/dist/core.mjs +8 -14
- package/dist/css-macro/postcss.js +3 -2
- package/dist/css-macro/postcss.mjs +3 -2
- package/dist/css-macro.d.ts +1 -0
- package/dist/css-macro.js +2 -2
- package/dist/css-macro.mjs +2 -2
- package/dist/defaults-B1igPF_e.mjs +150 -0
- package/dist/defaults-IHhYxNeU.js +193 -0
- package/dist/defaults.d.ts +15 -1
- package/dist/defaults.js +6 -131
- package/dist/defaults.mjs +2 -129
- package/dist/escape.js +10 -2
- package/dist/escape.mjs +10 -2
- package/dist/generator/index.d.ts +1 -1
- package/dist/generator/options.d.ts +9 -8
- package/dist/generator/types.d.ts +3 -3
- package/dist/generator-DIuglJub.mjs +32 -0
- package/dist/generator-N4jy1HCk.js +55 -0
- package/dist/generator.js +12 -11
- package/dist/generator.mjs +2 -1
- package/dist/gulp.js +185 -47
- package/dist/gulp.mjs +179 -41
- package/dist/incremental-runtime-class-set-CJ0Pnsw2.js +2348 -0
- package/dist/incremental-runtime-class-set-hF-uiw6W.mjs +2285 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/index.mjs +5 -5
- package/dist/js/babel/cache-options.d.ts +3 -0
- package/dist/js/babel/parse.d.ts +7 -4
- package/dist/js/index.d.ts +1 -0
- package/dist/js/literal-transform.d.ts +2 -0
- package/dist/js/precheck.d.ts +2 -2
- package/dist/lightningcss/style-handler/selector-transform.d.ts +1 -1
- package/dist/lightningcss/style-handler.d.ts +3 -3
- package/dist/logger-CZUxvJJD.mjs +2 -0
- package/dist/logger-EVNB9z7i.js +1 -0
- package/dist/postcss/config-directive.d.ts +1 -0
- package/dist/postcss/context.d.ts +9 -0
- package/dist/postcss/source-files.d.ts +8 -0
- package/dist/postcss/tailwind-version.d.ts +3 -0
- package/dist/postcss-D4UdbBQ6.mjs +228 -0
- package/dist/postcss-DlY-YRvA.js +237 -0
- package/dist/postcss.d.ts +2 -2
- package/dist/postcss.js +3 -276
- package/dist/postcss.mjs +1 -269
- package/dist/{recorder-gYSNLfOP.js → precheck-BjEbVEpX.js} +218 -314
- package/dist/{recorder-zsgatmkB.mjs → precheck-tbk626YL.mjs} +186 -281
- package/dist/presets.js +13 -11
- package/dist/presets.mjs +11 -9
- package/dist/reset.d.ts +1 -0
- package/dist/runtime-registry-D5qnaSpo.js +5516 -0
- package/dist/shared/mpx.d.ts +1 -0
- package/dist/source-candidates-BrvneDDd.mjs +209 -0
- package/dist/source-candidates-gxijpPI3.js +222 -0
- package/dist/tailwindcss/miniprogram.d.ts +5 -1
- package/dist/tailwindcss/patcher-options.d.ts +3 -51
- package/dist/tailwindcss/patcher.d.ts +1 -2
- package/dist/tailwindcss/runtime/cache.d.ts +4 -3
- package/dist/tailwindcss/runtime-patch.d.ts +5 -0
- package/dist/tailwindcss/runtime.d.ts +11 -12
- package/dist/tailwindcss/source-scan.d.ts +35 -0
- package/dist/tailwindcss/targets.d.ts +1 -5
- package/dist/tailwindcss/v3-engine/types.d.ts +17 -14
- package/dist/tailwindcss/v4/css-entries.d.ts +2 -2
- package/dist/tailwindcss/v4/css-sources.d.ts +5 -0
- package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
- package/dist/tailwindcss/v4/patcher.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/source.d.ts +2 -2
- package/dist/tailwindcss/v4-engine/types.d.ts +17 -5
- package/dist/tailwindcss/version.d.ts +4 -0
- package/dist/tailwindcss-BhG7BtB-.js +651 -0
- package/dist/tailwindcss-c6ROlNNW.mjs +600 -0
- package/dist/typedoc.export.d.ts +0 -2
- package/dist/types/index.d.ts +51 -48
- package/dist/types/shared.d.ts +3 -0
- package/dist/types/user-defined-options/general.d.ts +23 -23
- package/dist/types/user-defined-options/important.d.ts +31 -28
- package/dist/types/user-defined-options/lifecycle.d.ts +4 -4
- package/dist/types/user-defined-options/matcher.d.ts +6 -6
- package/dist/uni-app-x/vite.d.ts +1 -1
- package/dist/utils/disabled.d.ts +2 -3
- package/dist/utils/object.d.ts +9 -0
- package/dist/{utils-DmC9_In3.js → utils-4ODFyoqD.js} +1 -1
- package/dist/{utils-7DUGTFED.mjs → utils-CGBVVNm6.mjs} +1 -1
- package/dist/v3-engine-5LoZUH-4.js +3695 -0
- package/dist/v3-engine-DIXDEDmL.mjs +3406 -0
- package/dist/{vite-CrlzCNqz.mjs → vite-B5faZcbE.mjs} +1256 -1088
- package/dist/vite-MyXBNux0.js +2368 -0
- package/dist/vite.d.ts +1 -2
- package/dist/vite.js +3 -4
- package/dist/vite.mjs +2 -2
- package/dist/weapp-tw-css-import-rewrite-loader.js +5157 -16
- package/dist/weapp-tw-runtime-classset-loader.js +32 -7
- package/dist/webpack-BnVyDmsD.mjs +836 -0
- package/dist/webpack-Mz1V0A9p.js +846 -0
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +27 -37
- package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
- package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
- package/dist/cli/config.d.ts +0 -5
- package/dist/cli/helpers/patch-cwd.d.ts +0 -1
- package/dist/cli/mount-options/patch-status.d.ts +0 -2
- package/dist/cli/patch-options.d.ts +0 -6
- package/dist/cli/tokens.d.ts +0 -4
- package/dist/cli/workspace/package-dirs.d.ts +0 -3
- package/dist/cli/workspace/patch-package.d.ts +0 -3
- package/dist/cli/workspace/patch-utils.d.ts +0 -3
- package/dist/cli/workspace/types.d.ts +0 -11
- package/dist/cli/workspace/workspace-globs.d.ts +0 -2
- package/dist/cli/workspace/workspace-io.d.ts +0 -1
- package/dist/cli/workspace/workspace-lock.d.ts +0 -1
- package/dist/cli/workspace.d.ts +0 -2
- package/dist/css-imports-BbrbluP9.js +0 -177
- package/dist/css-imports-CSdPq_Sc.mjs +0 -128
- package/dist/experimental/index.d.ts +0 -2
- package/dist/experimental/oxc/ast-utils.d.ts +0 -30
- package/dist/experimental/oxc/index.d.ts +0 -2
- package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
- package/dist/experimental/shared/cache.d.ts +0 -3
- package/dist/experimental/shared/transform.d.ts +0 -3
- package/dist/experimental/shared.d.ts +0 -8
- package/dist/experimental/swc/ast-utils.d.ts +0 -30
- package/dist/experimental/swc/index.d.ts +0 -2
- package/dist/experimental/swc/module-specifiers.d.ts +0 -2
- package/dist/generator-Y-Ikv4Fu.mjs +0 -1177
- package/dist/generator-css-B5ejWUMv.mjs +0 -1098
- package/dist/generator-css-D3OdPRiS.js +0 -1125
- package/dist/generator-mmhXzZnv.js +0 -1276
- package/dist/js/syntax.d.ts +0 -10
- package/dist/loader-anchors-CNkWT8hx.js +0 -273
- package/dist/loader-anchors-TrU7EUr7.mjs +0 -205
- package/dist/logger-BZ45DZJT.js +0 -1003
- package/dist/logger-BoVx1Dbt.mjs +0 -935
- package/dist/patcher-options-6gJN2EXy.js +0 -115
- package/dist/patcher-options-DQfR5xxT.mjs +0 -92
- package/dist/tailwindcss/recorder.d.ts +0 -13
- package/dist/tailwindcss/targets/paths.d.ts +0 -13
- package/dist/tailwindcss/targets/record-io.d.ts +0 -5
- package/dist/tailwindcss/targets/recorder.d.ts +0 -3
- package/dist/tailwindcss/targets/types.d.ts +0 -35
- package/dist/types/disabled-options.d.ts +0 -4
- package/dist/vite-BC9U7ahn.js +0 -2199
- package/dist/webpack-Bu6M-Hbw.mjs +0 -441
- package/dist/webpack-DD7A6V0u.js +0 -456
- package/dist/webpack4.d.ts +0 -4
- package/dist/webpack4.js +0 -387
- package/dist/webpack4.mjs +0 -379
- package/scripts/postinstall.mjs +0 -59
- /package/dist/{constants-B-_T5UnW.mjs → constants-BG12WAKw.mjs} +0 -0
- /package/dist/{constants-p1dyh1x1.js → constants-BeeyfJ9k.js} +0 -0
|
@@ -0,0 +1,2348 @@
|
|
|
1
|
+
const require_chunk = require("./chunk-8l464Juk.js");
|
|
2
|
+
const require_v3_engine = require("./v3-engine-5LoZUH-4.js");
|
|
3
|
+
const require_generator = require("./generator-N4jy1HCk.js");
|
|
4
|
+
const require_precheck = require("./precheck-BjEbVEpX.js");
|
|
5
|
+
const require_tailwindcss = require("./tailwindcss-BhG7BtB-.js");
|
|
6
|
+
let node_fs = require("node:fs");
|
|
7
|
+
let postcss = require("postcss");
|
|
8
|
+
postcss = require_chunk.__toESM(postcss);
|
|
9
|
+
let node_path = require("node:path");
|
|
10
|
+
node_path = require_chunk.__toESM(node_path);
|
|
11
|
+
let node_process = require("node:process");
|
|
12
|
+
node_process = require_chunk.__toESM(node_process);
|
|
13
|
+
let tailwindcss_patch = require("tailwindcss-patch");
|
|
14
|
+
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
15
|
+
//#region src/bundlers/shared/generator-css/markers.ts
|
|
16
|
+
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
17
|
+
const TAILWIND_GENERATED_CSS_MARKER_RE = /\/\*!\s*tailwindcss v|@property\s+--tw-|--tw-|:not\(#\\#\)|\.[^,{]*(?:\\:|\\\[|\\#)|(?::host|page|\.tw-root|wx-root-portal-content)[^{]*\{[^}]*--(?:color|spacing|text|font-weight|radius)-/;
|
|
18
|
+
const GENERATOR_PLACEHOLDER_MARKER_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\//i;
|
|
19
|
+
const GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/\s*/gi;
|
|
20
|
+
const TAILWIND_BANNER_PREFIX_RE = /^\/\*!\s*tailwindcss v[^*]*\*\/\s*/i;
|
|
21
|
+
const TAILWIND_BANNER_RE = /\/\*!\s*tailwindcss v[^*]*\*\//i;
|
|
22
|
+
const TAILWIND_BANNER_GLOBAL_RE = /\/\*!\s*tailwindcss v[^*]*\*\/\s*/gi;
|
|
23
|
+
const VITE_MARKER_RE = /\/\*\$vite\$:[^*]*\*\//g;
|
|
24
|
+
function createCssAppend(base, extra) {
|
|
25
|
+
if (!base) return extra;
|
|
26
|
+
if (!extra) return base;
|
|
27
|
+
return `${base}\n${extra}`;
|
|
28
|
+
}
|
|
29
|
+
function splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss) {
|
|
30
|
+
const trimmedRaw = rawSource.trim();
|
|
31
|
+
const trimmedTailwind = rawTailwindCss.trim();
|
|
32
|
+
if (trimmedRaw === trimmedTailwind) return {
|
|
33
|
+
before: "",
|
|
34
|
+
after: ""
|
|
35
|
+
};
|
|
36
|
+
if (trimmedTailwind.startsWith(trimmedRaw)) return {
|
|
37
|
+
before: "",
|
|
38
|
+
after: ""
|
|
39
|
+
};
|
|
40
|
+
const start = rawSource.indexOf(rawTailwindCss);
|
|
41
|
+
if (start === -1) return;
|
|
42
|
+
return {
|
|
43
|
+
before: rawSource.slice(0, start),
|
|
44
|
+
after: rawSource.slice(start + rawTailwindCss.length)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss) {
|
|
48
|
+
const match = GENERATOR_PLACEHOLDER_MARKER_RE.exec(rawSource);
|
|
49
|
+
if (!match || match.index === void 0) return;
|
|
50
|
+
let afterStart = match.index + match[0].length;
|
|
51
|
+
while (/\s/.test(rawSource[afterStart] ?? "")) afterStart++;
|
|
52
|
+
if (rawTailwindCss && rawSource.slice(afterStart).startsWith(rawTailwindCss)) {
|
|
53
|
+
afterStart += rawTailwindCss.length;
|
|
54
|
+
while (/\s/.test(rawSource[afterStart] ?? "")) afterStart++;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
before: rawSource.slice(0, match.index),
|
|
58
|
+
after: rawSource.slice(afterStart)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function splitTailwindGeneratedCssByBanner(rawSource, start) {
|
|
62
|
+
const match = start === void 0 ? TAILWIND_BANNER_RE.exec(rawSource) : { index: start };
|
|
63
|
+
if (!match || match.index === void 0) return;
|
|
64
|
+
return {
|
|
65
|
+
before: rawSource.slice(0, match.index),
|
|
66
|
+
after: [...rawSource.slice(match.index).matchAll(VITE_MARKER_RE)].map((item) => item[0]).join("\n")
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function stripTailwindBanner(css) {
|
|
70
|
+
return css.replace(TAILWIND_BANNER_PREFIX_RE, "");
|
|
71
|
+
}
|
|
72
|
+
function stripTailwindBanners(css) {
|
|
73
|
+
return css.replace(TAILWIND_BANNER_GLOBAL_RE, "");
|
|
74
|
+
}
|
|
75
|
+
function stripGeneratorPlaceholderMarkers(css) {
|
|
76
|
+
return css.replace(GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE, "");
|
|
77
|
+
}
|
|
78
|
+
function hasTailwindGeneratedCss(rawSource) {
|
|
79
|
+
return TAILWIND_V4_BANNER_RE.test(rawSource);
|
|
80
|
+
}
|
|
81
|
+
function hasTailwindGeneratedCssMarkers(rawSource) {
|
|
82
|
+
return TAILWIND_GENERATED_CSS_MARKER_RE.test(rawSource) || GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/bundlers/shared/generator-css/directives.ts
|
|
86
|
+
const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = new Set([
|
|
87
|
+
"config",
|
|
88
|
+
"custom-variant",
|
|
89
|
+
"layer",
|
|
90
|
+
"plugin",
|
|
91
|
+
"reference",
|
|
92
|
+
"source",
|
|
93
|
+
"tailwind",
|
|
94
|
+
"theme",
|
|
95
|
+
"utility",
|
|
96
|
+
"variant"
|
|
97
|
+
]);
|
|
98
|
+
const TAILWIND_ROOT_DIRECTIVE_NAMES = new Set([
|
|
99
|
+
"config",
|
|
100
|
+
"custom-variant",
|
|
101
|
+
"plugin",
|
|
102
|
+
"source",
|
|
103
|
+
"tailwind",
|
|
104
|
+
"theme",
|
|
105
|
+
"utility",
|
|
106
|
+
"variant"
|
|
107
|
+
]);
|
|
108
|
+
const TAILWIND_ROOT_DIRECTIVE_RE = /@(?:import\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|tailwind|config|custom-variant|plugin|source|theme|utility|variant)\b/;
|
|
109
|
+
const TAILWIND_EXTRACTABLE_DIRECTIVE_RE = /^\s*@(?:import|tailwind|config|source|reference|plugin)\b[\s\S]*?(?:;|$)/;
|
|
110
|
+
const TAILWIND_EXTRACTABLE_BLOCK_DIRECTIVE_RE = /^\s*@(?:theme|utility|variant|custom-variant)\b[\s\S]*$/;
|
|
111
|
+
const TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE = /^\s*@layer\s[^;{]+;\s*$/;
|
|
112
|
+
function parseImportRequest(params) {
|
|
113
|
+
return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
|
|
114
|
+
}
|
|
115
|
+
function parseConfigRequest(params) {
|
|
116
|
+
return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
|
|
117
|
+
}
|
|
118
|
+
function isPackageJsonImportRequest(request) {
|
|
119
|
+
return typeof request === "string" && request.startsWith("#");
|
|
120
|
+
}
|
|
121
|
+
function isWeappTailwindcssImportRequest(request) {
|
|
122
|
+
return request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
|
|
123
|
+
}
|
|
124
|
+
function normalizeTailwindImportRequest(request, options = {}) {
|
|
125
|
+
if (options.importFallback && isWeappTailwindcssImportRequest(request)) return request.replace(/^weapp-tailwindcss/, "tailwindcss");
|
|
126
|
+
return request;
|
|
127
|
+
}
|
|
128
|
+
function replaceImportRequest(params, request, replacement) {
|
|
129
|
+
const index = params.indexOf(request);
|
|
130
|
+
if (index === -1) return params;
|
|
131
|
+
return `${params.slice(0, index)}${replacement}${params.slice(index + request.length)}`;
|
|
132
|
+
}
|
|
133
|
+
function normalizeTailwindImportAtRules(root, options = {}) {
|
|
134
|
+
if (!options.importFallback) return false;
|
|
135
|
+
let changed = false;
|
|
136
|
+
const seenCanonicalImports = /* @__PURE__ */ new Set();
|
|
137
|
+
root.walkAtRules("import", (node) => {
|
|
138
|
+
const request = parseImportRequest(node.params);
|
|
139
|
+
const normalizedRequest = normalizeTailwindImportRequest(request, options);
|
|
140
|
+
if (!normalizedRequest || !isTailwindImportRequest(normalizedRequest)) return;
|
|
141
|
+
const normalizedParams = request && normalizedRequest !== request ? replaceImportRequest(node.params, request, normalizedRequest) : node.params;
|
|
142
|
+
const normalizedKey = normalizedParams.trim();
|
|
143
|
+
if (seenCanonicalImports.has(normalizedKey)) {
|
|
144
|
+
node.remove();
|
|
145
|
+
changed = true;
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
seenCanonicalImports.add(normalizedKey);
|
|
149
|
+
if (normalizedParams !== node.params) {
|
|
150
|
+
node.params = normalizedParams;
|
|
151
|
+
changed = true;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return changed;
|
|
155
|
+
}
|
|
156
|
+
function normalizeTailwindDirectiveLine(line, options = {}) {
|
|
157
|
+
if (!options.importFallback || !line.trimStart().startsWith("@import")) return line;
|
|
158
|
+
const request = parseImportRequest(line.trimStart().replace(/^@import\b/, ""));
|
|
159
|
+
if (!request || !isWeappTailwindcssImportRequest(request)) return line;
|
|
160
|
+
return replaceImportRequest(line, request, request.replace(/^weapp-tailwindcss/, "tailwindcss"));
|
|
161
|
+
}
|
|
162
|
+
function extractTailwindDirectiveLines(rawSource, options = {}) {
|
|
163
|
+
const directives = [];
|
|
164
|
+
const seenImports = /* @__PURE__ */ new Set();
|
|
165
|
+
for (const line of stripGeneratorPlaceholderMarkers(rawSource).split(/\r?\n/)) {
|
|
166
|
+
const trimmed = line.trim();
|
|
167
|
+
if (!trimmed || trimmed.startsWith("//")) continue;
|
|
168
|
+
const directive = TAILWIND_EXTRACTABLE_DIRECTIVE_RE.exec(line)?.[0] ?? TAILWIND_EXTRACTABLE_BLOCK_DIRECTIVE_RE.exec(line)?.[0] ?? TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE.exec(line)?.[0];
|
|
169
|
+
if (!directive) continue;
|
|
170
|
+
const normalized = normalizeTailwindDirectiveLine(directive.trimEnd(), options);
|
|
171
|
+
const normalizedTrimmed = normalized.trim();
|
|
172
|
+
if (options.removeConfig && normalizedTrimmed.startsWith("@config")) continue;
|
|
173
|
+
const request = /^@import\b/.test(normalizedTrimmed) ? parseImportRequest(normalizedTrimmed.replace(/^@import\b/, "")) : void 0;
|
|
174
|
+
if (request && !isTailwindImportRequest(request) && !isPackageJsonImportRequest(request)) continue;
|
|
175
|
+
if (/^@import\b/.test(normalizedTrimmed) && !request) continue;
|
|
176
|
+
if (request && isTailwindImportRequest(request)) {
|
|
177
|
+
const key = normalizedTrimmed;
|
|
178
|
+
if (seenImports.has(key)) continue;
|
|
179
|
+
seenImports.add(key);
|
|
180
|
+
}
|
|
181
|
+
directives.push(normalized);
|
|
182
|
+
}
|
|
183
|
+
return directives;
|
|
184
|
+
}
|
|
185
|
+
function extractTailwindSourceForPostcssFallback(rawSource, options = {}) {
|
|
186
|
+
const directives = extractTailwindDirectiveLines(rawSource, options);
|
|
187
|
+
return directives.length > 0 ? directives.join("\n") : void 0;
|
|
188
|
+
}
|
|
189
|
+
function extractConfigRequestFromSource(rawSource) {
|
|
190
|
+
for (const line of rawSource.split(/\r?\n/)) {
|
|
191
|
+
const match = /^\s*@config\b([\s\S]*?)(?:;|$)/.exec(line);
|
|
192
|
+
const request = match ? parseConfigRequest(match[1] ?? "") : void 0;
|
|
193
|
+
if (request) return request;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function hasPreprocessorOnlySyntax(rawSource) {
|
|
197
|
+
return /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@[\w-]+\s*:|@(?:mixin|include|function|use|forward)\b)/.test(rawSource);
|
|
198
|
+
}
|
|
199
|
+
function normalizeTailwindSourceForGenerator(rawSource, options = {}) {
|
|
200
|
+
return hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource : rawSource;
|
|
201
|
+
}
|
|
202
|
+
function normalizeTailwindSourceDirectives(rawSource, options = {}) {
|
|
203
|
+
if (!options.importFallback) return rawSource;
|
|
204
|
+
try {
|
|
205
|
+
const root = postcss.default.parse(rawSource);
|
|
206
|
+
return normalizeTailwindImportAtRules(root, options) ? root.toString() : rawSource;
|
|
207
|
+
} catch {
|
|
208
|
+
return extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function isTailwindImportRequest(request) {
|
|
212
|
+
return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/");
|
|
213
|
+
}
|
|
214
|
+
function isTailwindImportAtRule(node, options = {}) {
|
|
215
|
+
if (node.name === "tailwind") return true;
|
|
216
|
+
if (node.name !== "import") return false;
|
|
217
|
+
return isTailwindImportRequest(normalizeTailwindImportRequest(parseImportRequest(node.params), options));
|
|
218
|
+
}
|
|
219
|
+
function isTailwindSourceDirective(node, options = {}) {
|
|
220
|
+
if (node.type !== "atrule") return false;
|
|
221
|
+
const atRule = node;
|
|
222
|
+
if (isTailwindImportAtRule(atRule, options)) return true;
|
|
223
|
+
if (atRule.name === "import" && isPackageJsonImportRequest(parseImportRequest(atRule.params))) return true;
|
|
224
|
+
return TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES.has(atRule.name);
|
|
225
|
+
}
|
|
226
|
+
function hasGeneratedCssArtifacts(rawSource) {
|
|
227
|
+
return hasTailwindGeneratedCssMarkers(rawSource) && !GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
|
|
228
|
+
}
|
|
229
|
+
function isTailwindGenerationDirective(node, options = {}) {
|
|
230
|
+
if (node.type !== "atrule") return false;
|
|
231
|
+
const atRule = node;
|
|
232
|
+
const request = atRule.name === "import" ? parseImportRequest(atRule.params) : atRule.name === "config" || atRule.name === "plugin" || atRule.name === "reference" ? parseConfigRequest(atRule.params) : void 0;
|
|
233
|
+
return isTailwindImportAtRule(atRule, options) || isPackageJsonImportRequest(request) || atRule.name === "apply" || !options.ignoreLayer && atRule.name === "layer" || atRule.name === "config" || atRule.name === "source";
|
|
234
|
+
}
|
|
235
|
+
function removeTailwindSourceDirectives(rawSource, options = {}) {
|
|
236
|
+
try {
|
|
237
|
+
if (hasPreprocessorOnlySyntax(rawSource)) return "";
|
|
238
|
+
const source = stripGeneratorPlaceholderMarkers(rawSource);
|
|
239
|
+
const root = postcss.default.parse(source);
|
|
240
|
+
let removed = false;
|
|
241
|
+
root.walk((node) => {
|
|
242
|
+
if (isTailwindSourceDirective(node, options)) {
|
|
243
|
+
node.remove();
|
|
244
|
+
removed = true;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
return removed ? root.toString() : source;
|
|
248
|
+
} catch {
|
|
249
|
+
return stripGeneratorPlaceholderMarkers(rawSource);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function hasTailwindSourceDirectives(rawSource, options = {}) {
|
|
253
|
+
try {
|
|
254
|
+
if (GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource)) return true;
|
|
255
|
+
const root = postcss.default.parse(rawSource);
|
|
256
|
+
let found = false;
|
|
257
|
+
const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
|
|
258
|
+
root.walk((node) => {
|
|
259
|
+
if (isTailwindGenerationDirective(node, {
|
|
260
|
+
...options,
|
|
261
|
+
ignoreLayer
|
|
262
|
+
})) {
|
|
263
|
+
found = true;
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
return found;
|
|
268
|
+
} catch {
|
|
269
|
+
return extractTailwindDirectiveLines(rawSource, options).length > 0;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function hasTailwindRootDirectives(rawSource, options = {}) {
|
|
273
|
+
if (!TAILWIND_ROOT_DIRECTIVE_RE.test(rawSource) && !(options.importFallback && rawSource.includes("weapp-tailwindcss"))) return false;
|
|
274
|
+
try {
|
|
275
|
+
const root = postcss.default.parse(rawSource);
|
|
276
|
+
let found = false;
|
|
277
|
+
root.walkAtRules((node) => {
|
|
278
|
+
const request = node.name === "import" ? parseImportRequest(node.params) : node.name === "config" || node.name === "plugin" ? parseConfigRequest(node.params) : void 0;
|
|
279
|
+
if (isTailwindImportAtRule(node, options) || isPackageJsonImportRequest(request) || TAILWIND_ROOT_DIRECTIVE_NAMES.has(node.name)) {
|
|
280
|
+
found = true;
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
return found;
|
|
285
|
+
} catch {
|
|
286
|
+
return extractTailwindDirectiveLines(rawSource, options).length > 0;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function hasTailwindApplyDirective(rawSource) {
|
|
290
|
+
if (!rawSource.includes("@apply")) return false;
|
|
291
|
+
try {
|
|
292
|
+
const root = postcss.default.parse(rawSource);
|
|
293
|
+
let found = false;
|
|
294
|
+
root.walkAtRules("apply", () => {
|
|
295
|
+
found = true;
|
|
296
|
+
return false;
|
|
297
|
+
});
|
|
298
|
+
return found;
|
|
299
|
+
} catch {
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function resolveCssEntrySource(rawSource, base, options = {}) {
|
|
304
|
+
try {
|
|
305
|
+
const root = postcss.default.parse(rawSource);
|
|
306
|
+
const normalizedImports = normalizeTailwindImportAtRules(root, options);
|
|
307
|
+
let found = false;
|
|
308
|
+
let config;
|
|
309
|
+
let configRequest;
|
|
310
|
+
let removedConfig = false;
|
|
311
|
+
const removeConfig = options.removeConfig ?? true;
|
|
312
|
+
const ignoreLayer = hasGeneratedCssArtifacts(rawSource);
|
|
313
|
+
root.walk((node) => {
|
|
314
|
+
if (isTailwindGenerationDirective(node, {
|
|
315
|
+
...options,
|
|
316
|
+
ignoreLayer
|
|
317
|
+
})) found = true;
|
|
318
|
+
if (node.type === "atrule" && node.name === "config") {
|
|
319
|
+
const configPath = parseConfigRequest(node.params);
|
|
320
|
+
if (configPath && !config) {
|
|
321
|
+
configRequest = configPath;
|
|
322
|
+
config = isPackageJsonImportRequest(configPath) ? void 0 : node_path.default.isAbsolute(configPath) ? configPath : node_path.default.resolve(base, configPath);
|
|
323
|
+
}
|
|
324
|
+
if (removeConfig) {
|
|
325
|
+
node.remove();
|
|
326
|
+
removedConfig = true;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
if (!found) return;
|
|
331
|
+
if (hasPreprocessorOnlySyntax(rawSource)) {
|
|
332
|
+
const css = extractTailwindSourceForPostcssFallback(rawSource, {
|
|
333
|
+
...options,
|
|
334
|
+
removeConfig
|
|
335
|
+
});
|
|
336
|
+
if (css) return {
|
|
337
|
+
css,
|
|
338
|
+
config,
|
|
339
|
+
configRequest,
|
|
340
|
+
base
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
css: removedConfig || normalizedImports ? root.toString() : rawSource,
|
|
345
|
+
config,
|
|
346
|
+
configRequest,
|
|
347
|
+
base
|
|
348
|
+
};
|
|
349
|
+
} catch {
|
|
350
|
+
const css = extractTailwindSourceForPostcssFallback(rawSource, options);
|
|
351
|
+
const configRequest = extractConfigRequestFromSource(rawSource);
|
|
352
|
+
const config = configRequest && !isPackageJsonImportRequest(configRequest) ? node_path.default.isAbsolute(configRequest) ? configRequest : node_path.default.resolve(base, configRequest) : void 0;
|
|
353
|
+
return css ? {
|
|
354
|
+
css,
|
|
355
|
+
config,
|
|
356
|
+
configRequest,
|
|
357
|
+
base
|
|
358
|
+
} : void 0;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
//#endregion
|
|
362
|
+
//#region src/bundlers/shared/cache.ts
|
|
363
|
+
async function processCachedTask({ cache, cacheKey, hashKey = cacheKey, rawSource, hash, readCache, applyResult, transform, onCacheHit }) {
|
|
364
|
+
let cacheHit = false;
|
|
365
|
+
const result = await cache.process({
|
|
366
|
+
key: cacheKey,
|
|
367
|
+
hashKey,
|
|
368
|
+
rawSource,
|
|
369
|
+
hash,
|
|
370
|
+
resolveCache: readCache,
|
|
371
|
+
async onCacheHit(value) {
|
|
372
|
+
cacheHit = true;
|
|
373
|
+
await applyResult(value);
|
|
374
|
+
onCacheHit?.();
|
|
375
|
+
},
|
|
376
|
+
transform
|
|
377
|
+
});
|
|
378
|
+
if (!cacheHit) await applyResult(result);
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/bundlers/shared/css-cleanup/at-rules.ts
|
|
382
|
+
const MINI_PROGRAM_UNSUPPORTED_AT_RULES = new Set(["property", "supports"]);
|
|
383
|
+
function removeAtRulesByScan(css, names) {
|
|
384
|
+
let index = 0;
|
|
385
|
+
let result = "";
|
|
386
|
+
const atRulePattern = new RegExp(`@(?:${[...names].join("|")})\\b`, "i");
|
|
387
|
+
while (index < css.length) {
|
|
388
|
+
const match = atRulePattern.exec(css.slice(index));
|
|
389
|
+
if (!match || match.index === void 0) {
|
|
390
|
+
result += css.slice(index);
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
const start = index + match.index;
|
|
394
|
+
result += css.slice(index, start);
|
|
395
|
+
const blockStart = css.indexOf("{", start);
|
|
396
|
+
if (blockStart === -1) {
|
|
397
|
+
result += css.slice(start);
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
let depth = 0;
|
|
401
|
+
let cursor = blockStart;
|
|
402
|
+
for (; cursor < css.length; cursor++) {
|
|
403
|
+
const char = css[cursor];
|
|
404
|
+
if (char === "{") depth++;
|
|
405
|
+
else if (char === "}") {
|
|
406
|
+
depth--;
|
|
407
|
+
if (depth === 0) {
|
|
408
|
+
cursor++;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
index = cursor;
|
|
414
|
+
}
|
|
415
|
+
return result;
|
|
416
|
+
}
|
|
417
|
+
function removeUnsupportedMiniProgramAtRules(css) {
|
|
418
|
+
try {
|
|
419
|
+
const root = postcss.default.parse(css);
|
|
420
|
+
root.walkAtRules((atRule) => {
|
|
421
|
+
if (MINI_PROGRAM_UNSUPPORTED_AT_RULES.has(atRule.name)) atRule.remove();
|
|
422
|
+
});
|
|
423
|
+
root.walkAtRules((atRule) => {
|
|
424
|
+
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
425
|
+
});
|
|
426
|
+
return root.toString();
|
|
427
|
+
} catch {
|
|
428
|
+
return removeAtRulesByScan(css, MINI_PROGRAM_UNSUPPORTED_AT_RULES);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
//#endregion
|
|
432
|
+
//#region src/bundlers/shared/css-cleanup/color-gamut.ts
|
|
433
|
+
const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
|
|
434
|
+
const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
|
|
435
|
+
function isDisplayP3MediaRule(atRule) {
|
|
436
|
+
return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
|
|
437
|
+
}
|
|
438
|
+
function isDisplayP3Declaration(decl) {
|
|
439
|
+
return DISPLAY_P3_VALUE_RE.test(decl.value);
|
|
440
|
+
}
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region src/bundlers/shared/css-cleanup/selectors.ts
|
|
443
|
+
const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
|
|
444
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
|
|
445
|
+
"*",
|
|
446
|
+
"view",
|
|
447
|
+
"text",
|
|
448
|
+
":before",
|
|
449
|
+
":after",
|
|
450
|
+
"::before",
|
|
451
|
+
"::after"
|
|
452
|
+
]);
|
|
453
|
+
const MINI_PROGRAM_THEME_SCOPE_SELECTORS$1 = new Set([
|
|
454
|
+
":host",
|
|
455
|
+
":root",
|
|
456
|
+
"page",
|
|
457
|
+
".tw-root",
|
|
458
|
+
"wx-root-portal-content"
|
|
459
|
+
]);
|
|
460
|
+
const SPECIFICITY_PLACEHOLDER_SUFFIXES = [":not(#n)", ":not(#\\#)"];
|
|
461
|
+
const MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS = new Set([
|
|
462
|
+
":-moz-focusring",
|
|
463
|
+
":-moz-ui-invalid",
|
|
464
|
+
"::-webkit-calendar-picker-indicator",
|
|
465
|
+
"::-webkit-date-and-time-value",
|
|
466
|
+
"::-webkit-datetime-edit",
|
|
467
|
+
"::-webkit-datetime-edit-day-field",
|
|
468
|
+
"::-webkit-datetime-edit-fields-wrapper",
|
|
469
|
+
"::-webkit-datetime-edit-hour-field",
|
|
470
|
+
"::-webkit-datetime-edit-meridiem-field",
|
|
471
|
+
"::-webkit-datetime-edit-millisecond-field",
|
|
472
|
+
"::-webkit-datetime-edit-minute-field",
|
|
473
|
+
"::-webkit-datetime-edit-month-field",
|
|
474
|
+
"::-webkit-datetime-edit-second-field",
|
|
475
|
+
"::-webkit-datetime-edit-year-field",
|
|
476
|
+
"::-webkit-inner-spin-button",
|
|
477
|
+
"::-webkit-input-placeholder",
|
|
478
|
+
"::-webkit-outer-spin-button",
|
|
479
|
+
"::-webkit-search-decoration",
|
|
480
|
+
"::placeholder",
|
|
481
|
+
"[hidden]:where(:not([hidden='until-found']))"
|
|
482
|
+
]);
|
|
483
|
+
const MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS = new Set([
|
|
484
|
+
"a",
|
|
485
|
+
"abbr:where([title])",
|
|
486
|
+
"audio",
|
|
487
|
+
"b",
|
|
488
|
+
"button",
|
|
489
|
+
"canvas",
|
|
490
|
+
"code",
|
|
491
|
+
"embed",
|
|
492
|
+
"h1",
|
|
493
|
+
"h2",
|
|
494
|
+
"h3",
|
|
495
|
+
"h4",
|
|
496
|
+
"h5",
|
|
497
|
+
"h6",
|
|
498
|
+
"hr",
|
|
499
|
+
"html",
|
|
500
|
+
"iframe",
|
|
501
|
+
"img",
|
|
502
|
+
"input",
|
|
503
|
+
"input:where([type='button'],[type='reset'],[type='submit'])",
|
|
504
|
+
"kbd",
|
|
505
|
+
"menu",
|
|
506
|
+
"object",
|
|
507
|
+
"ol",
|
|
508
|
+
"optgroup",
|
|
509
|
+
"pre",
|
|
510
|
+
"progress",
|
|
511
|
+
"samp",
|
|
512
|
+
"select",
|
|
513
|
+
"select[multiple]optgroup",
|
|
514
|
+
"select[multiple]optgroupoption",
|
|
515
|
+
"select[size]optgroup",
|
|
516
|
+
"select[size]optgroupoption",
|
|
517
|
+
"small",
|
|
518
|
+
"strong",
|
|
519
|
+
"sub",
|
|
520
|
+
"summary",
|
|
521
|
+
"sup",
|
|
522
|
+
"svg",
|
|
523
|
+
"table",
|
|
524
|
+
"textarea",
|
|
525
|
+
"ul",
|
|
526
|
+
"video"
|
|
527
|
+
]);
|
|
528
|
+
function normalizeSelector(selector) {
|
|
529
|
+
return selector.trim().replace(/\s+/g, "");
|
|
530
|
+
}
|
|
531
|
+
function getRuleSelectors(rule) {
|
|
532
|
+
return rule.selector.split(",").map(normalizeSelector).filter(Boolean);
|
|
533
|
+
}
|
|
534
|
+
function isUnsupportedBrowserSelector(selector) {
|
|
535
|
+
const normalized = normalizeSelector(selector);
|
|
536
|
+
return MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS.has(normalized) || MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS.has(normalized);
|
|
537
|
+
}
|
|
538
|
+
//#endregion
|
|
539
|
+
//#region src/bundlers/shared/css-cleanup/root-cleanups.ts
|
|
540
|
+
function removeSpecificityPlaceholders(root) {
|
|
541
|
+
root.walkRules((rule) => {
|
|
542
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
543
|
+
let changed = false;
|
|
544
|
+
const selectors = rule.selectors.map((selector) => {
|
|
545
|
+
let next = selector;
|
|
546
|
+
for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (next.includes(suffix)) next = next.split(suffix).join("");
|
|
547
|
+
if (next !== selector) changed = true;
|
|
548
|
+
return next;
|
|
549
|
+
});
|
|
550
|
+
if (changed) rule.selectors = selectors;
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
function removeEmptyAtRuleAncestors(parent) {
|
|
554
|
+
while (parent?.type === "atrule" && (!parent.nodes || parent.nodes.length === 0)) {
|
|
555
|
+
const nextParent = parent.parent;
|
|
556
|
+
parent.remove();
|
|
557
|
+
parent = nextParent?.type === "atrule" ? nextParent : void 0;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
function removeUnsupportedBrowserSelectors(root) {
|
|
561
|
+
root.walkRules((rule) => {
|
|
562
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
563
|
+
const selectors = rule.selectors.filter((selector) => !isUnsupportedBrowserSelector(selector));
|
|
564
|
+
if (selectors.length === rule.selectors.length) return;
|
|
565
|
+
if (selectors.length === 0) {
|
|
566
|
+
const parent = rule.parent;
|
|
567
|
+
rule.remove();
|
|
568
|
+
removeEmptyAtRuleAncestors(parent);
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
rule.selectors = selectors;
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
function removeDeclarationAndEmptyRule(decl) {
|
|
575
|
+
const parent = decl.parent;
|
|
576
|
+
decl.remove();
|
|
577
|
+
if (parent?.type === "rule" && parent.nodes.length === 0) {
|
|
578
|
+
const ruleParent = parent.parent;
|
|
579
|
+
parent.remove();
|
|
580
|
+
removeEmptyAtRuleAncestors(ruleParent);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
function removeDisplayP3Declarations(root) {
|
|
584
|
+
root.walkAtRules((atRule) => {
|
|
585
|
+
if (isDisplayP3MediaRule(atRule)) {
|
|
586
|
+
const parent = atRule.parent;
|
|
587
|
+
atRule.remove();
|
|
588
|
+
removeEmptyAtRuleAncestors(parent);
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
function removeUnsupportedModernColorDeclarations(root) {
|
|
593
|
+
const customPropertyValues = /* @__PURE__ */ new Map();
|
|
594
|
+
root.walkDecls((decl) => {
|
|
595
|
+
if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
|
|
596
|
+
});
|
|
597
|
+
root.walkDecls((decl) => {
|
|
598
|
+
const normalized = (0, _weapp_tailwindcss_postcss.normalizeModernColorValue)(decl.value, customPropertyValues);
|
|
599
|
+
if (normalized.changed) {
|
|
600
|
+
decl.value = normalized.value;
|
|
601
|
+
if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
|
|
602
|
+
}
|
|
603
|
+
if (normalized.hasUnsupported) removeDeclarationAndEmptyRule(decl);
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
//#endregion
|
|
607
|
+
//#region src/bundlers/shared/css-cleanup.ts
|
|
608
|
+
const PREFLIGHT_RESET_PROPS = new Set([
|
|
609
|
+
"box-sizing",
|
|
610
|
+
"border",
|
|
611
|
+
"border-width",
|
|
612
|
+
"border-style",
|
|
613
|
+
"border-color",
|
|
614
|
+
"margin",
|
|
615
|
+
"padding"
|
|
616
|
+
]);
|
|
617
|
+
const CONTENT_VAR_RE = /var\(\s*--tw-content\b/;
|
|
618
|
+
const HOIST_ANCHOR_COMMENT = "__weapp_tailwindcss_base_anchor__";
|
|
619
|
+
function isMiniProgramThemeScopeSelector$1(selectors) {
|
|
620
|
+
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_THEME_SCOPE_SELECTORS$1.has(selector));
|
|
621
|
+
}
|
|
622
|
+
function isMiniProgramPreflightSelector(selectors) {
|
|
623
|
+
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_PREFLIGHT_SELECTORS.has(selector)) && selectors.some((selector) => selector === "*" || selector === ":before" || selector === ":after" || selector === "::before" || selector === "::after");
|
|
624
|
+
}
|
|
625
|
+
function hasTailwindPreflightDeclaration(rule) {
|
|
626
|
+
let hasTailwindVar = false;
|
|
627
|
+
let hasResetProp = false;
|
|
628
|
+
rule.walkDecls((decl) => {
|
|
629
|
+
if (decl.prop.startsWith("--tw-")) hasTailwindVar = true;
|
|
630
|
+
if (PREFLIGHT_RESET_PROPS.has(decl.prop)) hasResetProp = true;
|
|
631
|
+
});
|
|
632
|
+
return hasTailwindVar || hasResetProp;
|
|
633
|
+
}
|
|
634
|
+
function isCustomPropertyOnlyRule$1(rule) {
|
|
635
|
+
let hasDeclaration = false;
|
|
636
|
+
let allCustomProperties = true;
|
|
637
|
+
rule.each((node) => {
|
|
638
|
+
if (node.type !== "decl") return;
|
|
639
|
+
hasDeclaration = true;
|
|
640
|
+
if (!node.prop.startsWith("--")) allCustomProperties = false;
|
|
641
|
+
});
|
|
642
|
+
return hasDeclaration && allCustomProperties;
|
|
643
|
+
}
|
|
644
|
+
function hasContentInitDeclaration(rule) {
|
|
645
|
+
let hasContentInit = false;
|
|
646
|
+
rule.walkDecls("--tw-content", () => {
|
|
647
|
+
hasContentInit = true;
|
|
648
|
+
});
|
|
649
|
+
return hasContentInit;
|
|
650
|
+
}
|
|
651
|
+
function isEmptyContentInitDeclaration(decl) {
|
|
652
|
+
return decl.prop === "--tw-content" && (decl.value === "\"\"" || decl.value === "''");
|
|
653
|
+
}
|
|
654
|
+
function usesTwContentVariable(root) {
|
|
655
|
+
let used = false;
|
|
656
|
+
root.walkDecls((decl) => {
|
|
657
|
+
if (CONTENT_VAR_RE.test(decl.value)) used = true;
|
|
658
|
+
});
|
|
659
|
+
return used;
|
|
660
|
+
}
|
|
661
|
+
function isTailwindPreflightRule(node) {
|
|
662
|
+
if (node.type !== "rule" || node.parent?.type !== "root") return false;
|
|
663
|
+
const rule = node;
|
|
664
|
+
return isMiniProgramPreflightSelector(getRuleSelectors(rule)) && hasTailwindPreflightDeclaration(rule);
|
|
665
|
+
}
|
|
666
|
+
function isMiniProgramThemeVariableRule(node) {
|
|
667
|
+
if (node.type !== "rule" || node.parent?.type !== "root") return false;
|
|
668
|
+
const rule = node;
|
|
669
|
+
return isMiniProgramThemeScopeSelector$1(getRuleSelectors(rule)) && isCustomPropertyOnlyRule$1(rule);
|
|
670
|
+
}
|
|
671
|
+
function createPseudoContentInitRule() {
|
|
672
|
+
const rule = postcss.default.rule({ selector: "::before,\n::after" });
|
|
673
|
+
rule.append({
|
|
674
|
+
prop: "--tw-content",
|
|
675
|
+
value: "''"
|
|
676
|
+
});
|
|
677
|
+
return rule;
|
|
678
|
+
}
|
|
679
|
+
function collectPreflightRules(root, options = {}) {
|
|
680
|
+
const preflightNodes = [];
|
|
681
|
+
let hasContentInit = false;
|
|
682
|
+
for (const node of root.nodes ?? []) if (isTailwindPreflightRule(node)) {
|
|
683
|
+
preflightNodes.push(node);
|
|
684
|
+
if (hasContentInitDeclaration(node)) hasContentInit = true;
|
|
685
|
+
}
|
|
686
|
+
if (preflightNodes.length === 0) return [];
|
|
687
|
+
const clonedPreflightRules = preflightNodes.map((node) => node.clone());
|
|
688
|
+
const contentInitRules = options.preservePseudoContentInit ? clonedPreflightRules.filter((rule) => hasContentInitDeclaration(rule)) : [];
|
|
689
|
+
const otherPreflightRules = clonedPreflightRules.filter((rule) => !hasContentInitDeclaration(rule));
|
|
690
|
+
const preflightRules = hasContentInit ? [...contentInitRules, ...otherPreflightRules] : [...options.preservePseudoContentInit ? [createPseudoContentInitRule()] : [], ...otherPreflightRules];
|
|
691
|
+
for (const node of preflightNodes) node.remove();
|
|
692
|
+
return preflightRules;
|
|
693
|
+
}
|
|
694
|
+
function createPreflightResetRule(cssPreflight) {
|
|
695
|
+
if (!cssPreflight || typeof cssPreflight !== "object") return;
|
|
696
|
+
const rule = postcss.default.rule({ selector: "view,text,:after,:before" });
|
|
697
|
+
for (const [prop, value] of Object.entries(cssPreflight)) {
|
|
698
|
+
if (value === false) continue;
|
|
699
|
+
rule.append({
|
|
700
|
+
prop,
|
|
701
|
+
value: value.toString()
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
return rule.nodes?.length ? rule : void 0;
|
|
705
|
+
}
|
|
706
|
+
function collectThemeVariableRule(root, options = {}) {
|
|
707
|
+
const themeRules = [];
|
|
708
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
709
|
+
const shouldPreserveContentInit = options.preservePseudoContentInit || usesTwContentVariable(root);
|
|
710
|
+
for (const node of root.nodes ?? []) {
|
|
711
|
+
if (!isMiniProgramThemeVariableRule(node)) continue;
|
|
712
|
+
themeRules.push(node);
|
|
713
|
+
node.walkDecls((decl) => {
|
|
714
|
+
if (isDisplayP3Declaration(decl)) return;
|
|
715
|
+
if (!shouldPreserveContentInit && isEmptyContentInitDeclaration(decl)) return;
|
|
716
|
+
declarations.set(decl.prop, decl.clone());
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
for (const rule of themeRules) rule.remove();
|
|
720
|
+
if (declarations.size === 0) return;
|
|
721
|
+
const rule = postcss.default.rule({ selector: MINI_PROGRAM_THEME_SCOPE_SELECTOR });
|
|
722
|
+
for (const decl of declarations.values()) rule.append(decl);
|
|
723
|
+
return rule;
|
|
724
|
+
}
|
|
725
|
+
function getTopDirectiveTail(root) {
|
|
726
|
+
let tail;
|
|
727
|
+
for (const node of root.nodes ?? []) {
|
|
728
|
+
if (node.type === "atrule" && (node.name === "charset" || node.name === "import")) {
|
|
729
|
+
tail = node;
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
return tail;
|
|
735
|
+
}
|
|
736
|
+
function createHoistInsertionAnchor(root) {
|
|
737
|
+
for (const node of root.nodes ?? []) if (isTailwindPreflightRule(node) || isMiniProgramThemeVariableRule(node)) {
|
|
738
|
+
const anchor = postcss.default.comment({ text: HOIST_ANCHOR_COMMENT });
|
|
739
|
+
node.before(anchor);
|
|
740
|
+
return anchor;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
function insertHoistedRules(root, rules, anchor) {
|
|
744
|
+
if (anchor && !anchor.parent) anchor = void 0;
|
|
745
|
+
if (rules.length === 0) {
|
|
746
|
+
anchor?.remove();
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
const topDirectiveTail = getTopDirectiveTail(root);
|
|
750
|
+
const firstRule = rules[0];
|
|
751
|
+
if (!firstRule) return;
|
|
752
|
+
if (anchor) {
|
|
753
|
+
if (anchor.raws.before === void 0) delete firstRule.raws.before;
|
|
754
|
+
else firstRule.raws.before = anchor.raws.before;
|
|
755
|
+
anchor.replaceWith(rules);
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
firstRule.raws.before = topDirectiveTail ? "\n" : "";
|
|
759
|
+
if (topDirectiveTail) topDirectiveTail.after(rules);
|
|
760
|
+
else root.prepend(rules);
|
|
761
|
+
}
|
|
762
|
+
function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
763
|
+
require_v3_engine.removeUnsupportedCascadeLayers(root);
|
|
764
|
+
unwrapTailwindSourceMedia(root);
|
|
765
|
+
root.walkAtRules("property", (atRule) => {
|
|
766
|
+
atRule.remove();
|
|
767
|
+
});
|
|
768
|
+
removeSpecificityPlaceholders(root);
|
|
769
|
+
removeUnsupportedBrowserSelectors(root);
|
|
770
|
+
removeDisplayP3Declarations(root);
|
|
771
|
+
removeUnsupportedModernColorDeclarations(root);
|
|
772
|
+
root.walkDecls((decl) => {
|
|
773
|
+
(0, _weapp_tailwindcss_postcss.normalizeMiniProgramPrefixedDeclaration)(decl);
|
|
774
|
+
});
|
|
775
|
+
root.walkAtRules((atRule) => {
|
|
776
|
+
(0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramPrefixedAtRule)(atRule);
|
|
777
|
+
});
|
|
778
|
+
const hoistAnchor = createHoistInsertionAnchor(root);
|
|
779
|
+
const preflightRules = collectPreflightRules(root, options);
|
|
780
|
+
if (preflightRules.length === 0) {
|
|
781
|
+
const resetRule = createPreflightResetRule(options.cssPreflight);
|
|
782
|
+
if (resetRule) preflightRules.push(resetRule);
|
|
783
|
+
}
|
|
784
|
+
const themeRule = collectThemeVariableRule(root, options);
|
|
785
|
+
insertHoistedRules(root, themeRule ? [...preflightRules, themeRule] : preflightRules, hoistAnchor);
|
|
786
|
+
}
|
|
787
|
+
function unwrapTailwindSourceMedia(root) {
|
|
788
|
+
root.walkAtRules("media", (atRule) => {
|
|
789
|
+
if (atRule.params.startsWith("source(") && atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
function finalizeMiniProgramCss(css, options = {}) {
|
|
793
|
+
const cleanedCss = removeUnsupportedMiniProgramAtRules(css);
|
|
794
|
+
try {
|
|
795
|
+
const root = postcss.default.parse(cleanedCss);
|
|
796
|
+
finalizeMiniProgramCssRoot(root, options);
|
|
797
|
+
return root.toString();
|
|
798
|
+
} catch {
|
|
799
|
+
return cleanedCss;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
//#endregion
|
|
803
|
+
//#region src/bundlers/shared/generator-css/legacy-selectors.ts
|
|
804
|
+
const CLASS_SELECTOR_RE = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
805
|
+
const MINI_PROGRAM_THEME_SCOPE_SELECTORS = new Set([
|
|
806
|
+
":host",
|
|
807
|
+
"page",
|
|
808
|
+
".tw-root",
|
|
809
|
+
"wx-root-portal-content"
|
|
810
|
+
]);
|
|
811
|
+
const SPECIFICITY_PLACEHOLDER_RE = /:not\(#(?:\\#|n)\)/g;
|
|
812
|
+
const SELECTOR_CACHE_LIMIT = 64;
|
|
813
|
+
const generatedSelectorCache = /* @__PURE__ */ new Map();
|
|
814
|
+
function setGeneratedSelectorCache(css, selectors) {
|
|
815
|
+
if (generatedSelectorCache.size >= SELECTOR_CACHE_LIMIT) {
|
|
816
|
+
const firstKey = generatedSelectorCache.keys().next().value;
|
|
817
|
+
if (firstKey !== void 0) generatedSelectorCache.delete(firstKey);
|
|
818
|
+
}
|
|
819
|
+
generatedSelectorCache.set(css, selectors);
|
|
820
|
+
}
|
|
821
|
+
function normalizeCompatSelector(selector) {
|
|
822
|
+
return selector.replace(SPECIFICITY_PLACEHOLDER_RE, "").replace(/\s+/g, " ").trim();
|
|
823
|
+
}
|
|
824
|
+
function isClassSelectorTerminator(char) {
|
|
825
|
+
return /[\s>+~#,.:()[\]]/.test(char);
|
|
826
|
+
}
|
|
827
|
+
function unescapeSimpleCssIdent(value) {
|
|
828
|
+
return value.replaceAll(/\\(.)/g, "$1");
|
|
829
|
+
}
|
|
830
|
+
function escapeCompatSelectorClasses(selector) {
|
|
831
|
+
let result = "";
|
|
832
|
+
let index = 0;
|
|
833
|
+
let changed = false;
|
|
834
|
+
while (index < selector.length) {
|
|
835
|
+
const char = selector[index];
|
|
836
|
+
if (char !== ".") {
|
|
837
|
+
result += char;
|
|
838
|
+
index += 1;
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
let end = index + 1;
|
|
842
|
+
let className = "";
|
|
843
|
+
while (end < selector.length) {
|
|
844
|
+
const current = selector[end];
|
|
845
|
+
if (current === void 0) break;
|
|
846
|
+
if (current === "\\" && end + 1 < selector.length) {
|
|
847
|
+
const escaped = selector[end + 1];
|
|
848
|
+
if (escaped === void 0) break;
|
|
849
|
+
className += current + escaped;
|
|
850
|
+
end += 2;
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
if (isClassSelectorTerminator(current)) break;
|
|
854
|
+
className += current;
|
|
855
|
+
end += 1;
|
|
856
|
+
}
|
|
857
|
+
if (className.includes("\\")) {
|
|
858
|
+
result += `.${require_precheck.replaceWxml(unescapeSimpleCssIdent(className))}`;
|
|
859
|
+
changed = true;
|
|
860
|
+
} else result += `.${className}`;
|
|
861
|
+
index = end;
|
|
862
|
+
}
|
|
863
|
+
return changed ? result : selector;
|
|
864
|
+
}
|
|
865
|
+
function normalizeCompatSelectors(selector) {
|
|
866
|
+
const normalized = normalizeCompatSelector(selector);
|
|
867
|
+
if (!normalized) return [];
|
|
868
|
+
const selectors = new Set([normalized]);
|
|
869
|
+
const escaped = normalizeCompatSelector(escapeCompatSelectorClasses(normalized));
|
|
870
|
+
if (escaped) selectors.add(escaped);
|
|
871
|
+
return [...selectors];
|
|
872
|
+
}
|
|
873
|
+
function normalizeCssSelector(selector) {
|
|
874
|
+
return selector.trim().replace(/\s+/g, "");
|
|
875
|
+
}
|
|
876
|
+
function getCompatSelectorKeys(selector) {
|
|
877
|
+
return normalizeCompatSelectors(selector).map(normalizeCssSelector);
|
|
878
|
+
}
|
|
879
|
+
function getRuleCompatSelectorKeys(rule) {
|
|
880
|
+
return (rule.selectors?.length ? rule.selectors : [rule.selector]).flatMap((selector) => getCompatSelectorKeys(selector));
|
|
881
|
+
}
|
|
882
|
+
function hasClassSelector(selector) {
|
|
883
|
+
return CLASS_SELECTOR_RE.test(selector);
|
|
884
|
+
}
|
|
885
|
+
function getNormalizedSelectorList(selector) {
|
|
886
|
+
return selector.split(",").map(normalizeCssSelector).filter(Boolean);
|
|
887
|
+
}
|
|
888
|
+
function isMiniProgramThemeScopeSelector(selector) {
|
|
889
|
+
const selectors = getNormalizedSelectorList(selector);
|
|
890
|
+
return selectors.length > 0 && selectors.every((item) => MINI_PROGRAM_THEME_SCOPE_SELECTORS.has(item));
|
|
891
|
+
}
|
|
892
|
+
function hasUtilityClassSelector(selector) {
|
|
893
|
+
return hasClassSelector(selector) && !isMiniProgramThemeScopeSelector(selector);
|
|
894
|
+
}
|
|
895
|
+
function isCustomPropertyOnlyRule(rule) {
|
|
896
|
+
let hasDeclaration = false;
|
|
897
|
+
let allCustomProperties = true;
|
|
898
|
+
rule.each((node) => {
|
|
899
|
+
if (node.type !== "decl") return;
|
|
900
|
+
hasDeclaration = true;
|
|
901
|
+
if (!node.prop.startsWith("--")) allCustomProperties = false;
|
|
902
|
+
});
|
|
903
|
+
return hasDeclaration && allCustomProperties;
|
|
904
|
+
}
|
|
905
|
+
function isPseudoContentInitRule(rule) {
|
|
906
|
+
let hasDeclaration = false;
|
|
907
|
+
let onlyContentVariable = true;
|
|
908
|
+
rule.each((node) => {
|
|
909
|
+
if (node.type !== "decl") return;
|
|
910
|
+
hasDeclaration = true;
|
|
911
|
+
if (node.prop !== "--tw-content") onlyContentVariable = false;
|
|
912
|
+
});
|
|
913
|
+
return hasDeclaration && onlyContentVariable;
|
|
914
|
+
}
|
|
915
|
+
function collectGeneratedSelectors(css) {
|
|
916
|
+
const cached = generatedSelectorCache.get(css);
|
|
917
|
+
if (cached) return cached;
|
|
918
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
919
|
+
try {
|
|
920
|
+
postcss.default.parse(css).walkRules((rule) => {
|
|
921
|
+
if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
|
|
922
|
+
for (const selector of getRuleCompatSelectorKeys(rule)) selectors.add(selector);
|
|
923
|
+
});
|
|
924
|
+
} catch {
|
|
925
|
+
return selectors;
|
|
926
|
+
}
|
|
927
|
+
setGeneratedSelectorCache(css, selectors);
|
|
928
|
+
return selectors;
|
|
929
|
+
}
|
|
930
|
+
function collectGeneratedDeclarationPropsBySelector(generatedCss, selectors) {
|
|
931
|
+
const propsBySelector = /* @__PURE__ */ new Map();
|
|
932
|
+
try {
|
|
933
|
+
postcss.default.parse(generatedCss).walkRules((rule) => {
|
|
934
|
+
const matchedSelectors = getRuleCompatSelectorKeys(rule).filter((selector) => selectors.has(selector));
|
|
935
|
+
if (matchedSelectors.length === 0) return;
|
|
936
|
+
const props = /* @__PURE__ */ new Set();
|
|
937
|
+
rule.walkDecls((decl) => {
|
|
938
|
+
props.add(decl.prop);
|
|
939
|
+
});
|
|
940
|
+
for (const selector of matchedSelectors) {
|
|
941
|
+
const existing = propsBySelector.get(selector);
|
|
942
|
+
if (existing) for (const prop of props) existing.add(prop);
|
|
943
|
+
else propsBySelector.set(selector, new Set(props));
|
|
944
|
+
}
|
|
945
|
+
});
|
|
946
|
+
} catch {
|
|
947
|
+
return propsBySelector;
|
|
948
|
+
}
|
|
949
|
+
return propsBySelector;
|
|
950
|
+
}
|
|
951
|
+
function removeGeneratedSelectorCompatCss(css, generatedCss) {
|
|
952
|
+
const generatedSelectors = collectGeneratedSelectors(generatedCss);
|
|
953
|
+
if (generatedSelectors.size === 0) return css;
|
|
954
|
+
try {
|
|
955
|
+
const root = postcss.default.parse(css);
|
|
956
|
+
let removed = false;
|
|
957
|
+
root.walkRules((rule) => {
|
|
958
|
+
if (isPseudoContentInitRule(rule)) {
|
|
959
|
+
rule.remove();
|
|
960
|
+
removed = true;
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
|
|
964
|
+
if (getRuleCompatSelectorKeys(rule).some((selector) => generatedSelectors.has(selector))) {
|
|
965
|
+
rule.remove();
|
|
966
|
+
removed = true;
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
root.walkAtRules((atRule) => {
|
|
970
|
+
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
971
|
+
});
|
|
972
|
+
return removed ? root.toString() : css;
|
|
973
|
+
} catch {
|
|
974
|
+
return css;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
function collectDedupedPostTransformCompatCss(css, generatedCss) {
|
|
978
|
+
const generatedSelectors = collectGeneratedSelectors(generatedCss);
|
|
979
|
+
if (generatedSelectors.size === 0) return css;
|
|
980
|
+
const generatedDeclarationPropsBySelector = collectGeneratedDeclarationPropsBySelector(generatedCss, generatedSelectors);
|
|
981
|
+
const preservedNodes = [];
|
|
982
|
+
try {
|
|
983
|
+
const root = postcss.default.parse(css);
|
|
984
|
+
root.each((node) => {
|
|
985
|
+
if (node.type === "rule") {
|
|
986
|
+
const nodeSelectors = getRuleCompatSelectorKeys(node);
|
|
987
|
+
if (!nodeSelectors.some((selector) => generatedSelectors.has(selector))) {
|
|
988
|
+
preservedNodes.push(node.clone());
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
if (isCustomPropertyOnlyRule(node) && !isPseudoContentInitRule(node) && !hasUtilityClassSelector(node.selector)) {
|
|
992
|
+
const declarationProps = /* @__PURE__ */ new Set();
|
|
993
|
+
node.walkDecls((decl) => {
|
|
994
|
+
declarationProps.add(decl.prop);
|
|
995
|
+
});
|
|
996
|
+
for (const selector of nodeSelectors) {
|
|
997
|
+
const generatedProps = generatedDeclarationPropsBySelector.get(selector);
|
|
998
|
+
if (!generatedProps) continue;
|
|
999
|
+
for (const prop of generatedProps) declarationProps.delete(prop);
|
|
1000
|
+
}
|
|
1001
|
+
const nextRule = node.clone();
|
|
1002
|
+
nextRule.walkDecls((decl) => {
|
|
1003
|
+
if (!declarationProps.has(decl.prop)) decl.remove();
|
|
1004
|
+
});
|
|
1005
|
+
if (nextRule.nodes.length > 0) preservedNodes.push(nextRule);
|
|
1006
|
+
}
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
preservedNodes.push(node.clone());
|
|
1010
|
+
});
|
|
1011
|
+
if (preservedNodes.length === root.nodes.length) return css;
|
|
1012
|
+
const nextRoot = postcss.default.root();
|
|
1013
|
+
nextRoot.append(preservedNodes);
|
|
1014
|
+
return nextRoot.toString();
|
|
1015
|
+
} catch {
|
|
1016
|
+
return css;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
function removeDuplicatedViteMarkers(css, baseCss) {
|
|
1020
|
+
if (!VITE_MARKER_RE.test(baseCss)) return css;
|
|
1021
|
+
VITE_MARKER_RE.lastIndex = 0;
|
|
1022
|
+
return css.replace(VITE_MARKER_RE, "");
|
|
1023
|
+
}
|
|
1024
|
+
//#endregion
|
|
1025
|
+
//#region src/bundlers/shared/generator-css/config-directive.ts
|
|
1026
|
+
function quoteCssString(value) {
|
|
1027
|
+
return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
|
|
1028
|
+
}
|
|
1029
|
+
function toCssPath(value) {
|
|
1030
|
+
return value.replaceAll("\\", "/");
|
|
1031
|
+
}
|
|
1032
|
+
function prependConfigDirective(css, config) {
|
|
1033
|
+
if (!config || /@config\s+/.test(css)) return css;
|
|
1034
|
+
return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
|
|
1035
|
+
}
|
|
1036
|
+
function normalizeConfigDirective(css, config) {
|
|
1037
|
+
if (!config || !/@config\s+/.test(css)) return css;
|
|
1038
|
+
return css.replace(/@config\s+(["'])(.+?)\1\s*;?/, `@config "${quoteCssString(toCssPath(config))}";`);
|
|
1039
|
+
}
|
|
1040
|
+
//#endregion
|
|
1041
|
+
//#region src/bundlers/shared/generator-css/source-files.ts
|
|
1042
|
+
const SOURCE_STYLE_EXTENSIONS = [
|
|
1043
|
+
".vue",
|
|
1044
|
+
".uvue",
|
|
1045
|
+
".nvue",
|
|
1046
|
+
".css",
|
|
1047
|
+
".scss",
|
|
1048
|
+
".sass",
|
|
1049
|
+
".less",
|
|
1050
|
+
".styl",
|
|
1051
|
+
".stylus",
|
|
1052
|
+
".wxss",
|
|
1053
|
+
".acss",
|
|
1054
|
+
".jxss",
|
|
1055
|
+
".ttss",
|
|
1056
|
+
".qss"
|
|
1057
|
+
];
|
|
1058
|
+
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
1059
|
+
function stripStyleExtension(file) {
|
|
1060
|
+
return file.replace(/[?#].*$/, "").replace(/\.(?:wx|ac|jx|tt|q|c|ty)?ss$/i, "");
|
|
1061
|
+
}
|
|
1062
|
+
function createSourceStylePathCandidates(file, sourceOptions) {
|
|
1063
|
+
const bases = [
|
|
1064
|
+
sourceOptions.projectRoot,
|
|
1065
|
+
sourceOptions.cwd,
|
|
1066
|
+
node_process.default.cwd()
|
|
1067
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
1068
|
+
const outputRoots = [sourceOptions.outputRoot].filter((item) => typeof item === "string" && item.length > 0);
|
|
1069
|
+
const strippedFile = stripStyleExtension(file);
|
|
1070
|
+
const relativeFiles = /* @__PURE__ */ new Set();
|
|
1071
|
+
const addOutputRelativePath = (absoluteFile) => {
|
|
1072
|
+
for (const outputRoot of outputRoots) {
|
|
1073
|
+
const relative = node_path.default.relative(outputRoot, absoluteFile);
|
|
1074
|
+
if (!relative || relative.startsWith("..") || node_path.default.isAbsolute(relative)) continue;
|
|
1075
|
+
relativeFiles.add(relative);
|
|
1076
|
+
}
|
|
1077
|
+
};
|
|
1078
|
+
if (node_path.default.isAbsolute(strippedFile)) {
|
|
1079
|
+
addOutputRelativePath(strippedFile);
|
|
1080
|
+
for (const base of bases) {
|
|
1081
|
+
const relative = node_path.default.relative(base, strippedFile);
|
|
1082
|
+
if (!relative || relative.startsWith("..") || node_path.default.isAbsolute(relative)) continue;
|
|
1083
|
+
relativeFiles.add(relative);
|
|
1084
|
+
}
|
|
1085
|
+
} else relativeFiles.add(strippedFile);
|
|
1086
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
1087
|
+
for (const relativeFile of relativeFiles) {
|
|
1088
|
+
if (!relativeFile || node_path.default.isAbsolute(relativeFile)) continue;
|
|
1089
|
+
for (const base of bases) for (const sourceRoot of ["", "src"]) {
|
|
1090
|
+
const prefix = sourceRoot ? node_path.default.resolve(base, sourceRoot, relativeFile) : node_path.default.resolve(base, relativeFile);
|
|
1091
|
+
for (const extension of SOURCE_STYLE_EXTENSIONS) candidates.add(`${prefix}${extension}`);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
return [...candidates];
|
|
1095
|
+
}
|
|
1096
|
+
function extractStyleDirectiveSources(source) {
|
|
1097
|
+
const styleSources = [];
|
|
1098
|
+
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
1099
|
+
let match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
1100
|
+
while (match !== null) {
|
|
1101
|
+
const styleSource = match[1] ?? "";
|
|
1102
|
+
if (hasTailwindSourceDirectives(styleSource)) styleSources.push(styleSource);
|
|
1103
|
+
match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
1104
|
+
}
|
|
1105
|
+
if (styleSources.length > 0) return styleSources;
|
|
1106
|
+
return hasTailwindSourceDirectives(source) ? [source] : [];
|
|
1107
|
+
}
|
|
1108
|
+
function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {}) {
|
|
1109
|
+
for (const sourceFile of createSourceStylePathCandidates(file, sourceOptions)) {
|
|
1110
|
+
if (!(0, node_fs.existsSync)(sourceFile)) continue;
|
|
1111
|
+
try {
|
|
1112
|
+
const source = (0, node_fs.readFileSync)(sourceFile, "utf8");
|
|
1113
|
+
for (const styleSource of extractStyleDirectiveSources(source)) {
|
|
1114
|
+
const cssEntrySource = resolveCssEntrySource(styleSource, node_path.default.dirname(sourceFile), resolveOptions);
|
|
1115
|
+
if (cssEntrySource) return {
|
|
1116
|
+
...cssEntrySource,
|
|
1117
|
+
file: sourceFile
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
} catch {
|
|
1121
|
+
continue;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
//#endregion
|
|
1126
|
+
//#region src/bundlers/shared/generator-css/source-resolver.ts
|
|
1127
|
+
function resolvePostcssFromOption(cssHandlerOptions) {
|
|
1128
|
+
const from = cssHandlerOptions.postcssOptions?.options?.from;
|
|
1129
|
+
return typeof from === "string" && from.length > 0 ? from : void 0;
|
|
1130
|
+
}
|
|
1131
|
+
function resolvePostcssSourceFile(cssHandlerOptions) {
|
|
1132
|
+
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
1133
|
+
if (!from || !node_path.default.isAbsolute(from)) return;
|
|
1134
|
+
return from.replace(/[?#].*$/, "");
|
|
1135
|
+
}
|
|
1136
|
+
function resolveCssHandlerSourceOptions(cssHandlerOptions) {
|
|
1137
|
+
return cssHandlerOptions.sourceOptions;
|
|
1138
|
+
}
|
|
1139
|
+
function createSingleTailwindV4SourceOptions(sourceOptions, options) {
|
|
1140
|
+
return require_v3_engine.omitUndefined({
|
|
1141
|
+
projectRoot: sourceOptions.projectRoot,
|
|
1142
|
+
baseFallbacks: sourceOptions.baseFallbacks,
|
|
1143
|
+
packageName: sourceOptions.packageName,
|
|
1144
|
+
base: options.base,
|
|
1145
|
+
css: options.css
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
function resolveCssSourceBase(file, cssHandlerOptions) {
|
|
1149
|
+
const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
|
|
1150
|
+
return node_path.default.dirname(node_path.default.resolve(normalized));
|
|
1151
|
+
}
|
|
1152
|
+
function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
|
|
1153
|
+
if (config && (0, node_fs.existsSync)(config)) return config;
|
|
1154
|
+
if (!configRequest || node_path.default.isAbsolute(configRequest)) return sourceOptions.config;
|
|
1155
|
+
const outputDir = node_path.default.dirname(file.replace(/[?#].*$/, ""));
|
|
1156
|
+
const baseCandidates = [
|
|
1157
|
+
sourceOptions.projectRoot,
|
|
1158
|
+
sourceOptions.cwd,
|
|
1159
|
+
node_process.default.cwd()
|
|
1160
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
1161
|
+
for (const base of baseCandidates) {
|
|
1162
|
+
const candidates = [
|
|
1163
|
+
node_path.default.resolve(base, configRequest),
|
|
1164
|
+
node_path.default.resolve(base, "src", configRequest),
|
|
1165
|
+
node_path.default.resolve(base, outputDir, configRequest),
|
|
1166
|
+
node_path.default.resolve(base, "src", outputDir, configRequest)
|
|
1167
|
+
];
|
|
1168
|
+
for (const candidate of candidates) if ((0, node_fs.existsSync)(candidate)) return candidate;
|
|
1169
|
+
}
|
|
1170
|
+
return sourceOptions.config;
|
|
1171
|
+
}
|
|
1172
|
+
function canResolveSourceSideCssEntry(file, cssHandlerOptions) {
|
|
1173
|
+
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
1174
|
+
if (!from || !node_path.default.isAbsolute(from)) return node_path.default.isAbsolute(file);
|
|
1175
|
+
return true;
|
|
1176
|
+
}
|
|
1177
|
+
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
1178
|
+
return rawSource.includes("@apply") || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
|
|
1179
|
+
}
|
|
1180
|
+
function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
|
|
1181
|
+
return Boolean(sourceSideEntrySource) && !hasTailwindSourceDirectives(rawSource, { importFallback: true });
|
|
1182
|
+
}
|
|
1183
|
+
function normalizeCssSourceForCompare(css) {
|
|
1184
|
+
return stripGeneratorPlaceholderMarkers(stripTailwindBanners(css)).trim();
|
|
1185
|
+
}
|
|
1186
|
+
function getOutputFileStem(file) {
|
|
1187
|
+
const normalized = file.replace(/[?#].*$/, "");
|
|
1188
|
+
return node_path.default.basename(normalized, node_path.default.extname(normalized));
|
|
1189
|
+
}
|
|
1190
|
+
function getOutputFileWithoutExtension(file) {
|
|
1191
|
+
const normalized = file.replace(/[?#].*$/, "");
|
|
1192
|
+
const ext = node_path.default.extname(normalized);
|
|
1193
|
+
return ext ? normalized.slice(0, -ext.length) : normalized;
|
|
1194
|
+
}
|
|
1195
|
+
function normalizeMatchPath(file) {
|
|
1196
|
+
return file.split(node_path.default.sep).join("/");
|
|
1197
|
+
}
|
|
1198
|
+
function stripKnownBuildRootPrefix(file) {
|
|
1199
|
+
const segments = normalizeMatchPath(file).split("/");
|
|
1200
|
+
const knownRoots = new Set(["dist", "src"]);
|
|
1201
|
+
for (let index = segments.length - 1; index >= 0; index--) if (knownRoots.has(segments[index])) return segments.slice(index + 1).join("/");
|
|
1202
|
+
return segments.join("/");
|
|
1203
|
+
}
|
|
1204
|
+
function isMatchingTailwindV4CssSourceFile(file, cssSourceFile) {
|
|
1205
|
+
const outputBase = normalizeMatchPath(getOutputFileWithoutExtension(node_path.default.resolve(file)));
|
|
1206
|
+
const sourceBase = normalizeMatchPath(getOutputFileWithoutExtension(node_path.default.resolve(cssSourceFile)));
|
|
1207
|
+
const outputRelativeBase = stripKnownBuildRootPrefix(outputBase);
|
|
1208
|
+
const sourceRelativeBase = stripKnownBuildRootPrefix(sourceBase);
|
|
1209
|
+
return outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`) || outputRelativeBase.length > 0 && outputRelativeBase === sourceRelativeBase;
|
|
1210
|
+
}
|
|
1211
|
+
function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
|
|
1212
|
+
const cssEntries = sourceOptions.cssEntries;
|
|
1213
|
+
if (!cssEntries?.length) return;
|
|
1214
|
+
const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
|
|
1215
|
+
const outputStem = getOutputFileStem(file);
|
|
1216
|
+
const matchingEntry = cssEntries.find((cssEntry) => {
|
|
1217
|
+
if (!(0, node_fs.existsSync)(cssEntry)) return false;
|
|
1218
|
+
try {
|
|
1219
|
+
if (normalizeCssSourceForCompare((0, node_fs.readFileSync)(cssEntry, "utf8")) === normalizedRawSource) return true;
|
|
1220
|
+
return outputStem.length > 0 && getOutputFileStem(cssEntry) === outputStem;
|
|
1221
|
+
} catch {
|
|
1222
|
+
return false;
|
|
1223
|
+
}
|
|
1224
|
+
});
|
|
1225
|
+
if (!matchingEntry) return;
|
|
1226
|
+
return require_v3_engine.resolveTailwindV4Source({
|
|
1227
|
+
...require_v3_engine.omitUndefined(sourceOptions),
|
|
1228
|
+
cssEntries: [matchingEntry]
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions) {
|
|
1232
|
+
const cssSources = sourceOptions.cssSources;
|
|
1233
|
+
if (!cssSources?.length) return;
|
|
1234
|
+
const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
|
|
1235
|
+
const sourceFile = resolvePostcssSourceFile(cssHandlerOptions);
|
|
1236
|
+
const matchingSource = cssSources.find((cssSource) => {
|
|
1237
|
+
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) return false;
|
|
1238
|
+
if (sourceFile && typeof cssSource.file === "string" && node_path.default.resolve(sourceFile) === node_path.default.resolve(cssSource.file)) return true;
|
|
1239
|
+
if (typeof cssSource.file === "string" && isMatchingTailwindV4CssSourceFile(file, cssSource.file)) return true;
|
|
1240
|
+
return normalizeCssSourceForCompare(cssSource.css) === normalizedRawSource;
|
|
1241
|
+
});
|
|
1242
|
+
if (!matchingSource) return;
|
|
1243
|
+
return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions);
|
|
1244
|
+
}
|
|
1245
|
+
function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
1246
|
+
try {
|
|
1247
|
+
return require_v3_engine.resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
1248
|
+
} catch {
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
function hasConfiguredTailwindV4CssSource(sourceOptions) {
|
|
1253
|
+
return Boolean(sourceOptions?.css) || Boolean(sourceOptions?.cssSources?.length);
|
|
1254
|
+
}
|
|
1255
|
+
async function resolveSingleTailwindV4CssSource(cssSource, sourceOptions) {
|
|
1256
|
+
const source = await require_v3_engine.resolveTailwindV4Source({
|
|
1257
|
+
...require_v3_engine.omitUndefined(sourceOptions),
|
|
1258
|
+
cssSources: [cssSource]
|
|
1259
|
+
});
|
|
1260
|
+
const sourceBaseFallback = sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd();
|
|
1261
|
+
return withGeneratorSourceMetadata(source, {
|
|
1262
|
+
matchedCssSourceFile: typeof cssSource.file === "string" ? cssSource.file : void 0,
|
|
1263
|
+
sourceBase: require_v3_engine.resolveTailwindV4CssSourceBase(cssSource, sourceBaseFallback),
|
|
1264
|
+
sourceCss: cssSource.css
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
async function resolveTailwindV4CssSourceEntries(cssSource, sourceOptions) {
|
|
1268
|
+
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) return;
|
|
1269
|
+
const sourceBase = require_v3_engine.resolveTailwindV4CssSourceBase(cssSource, sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd());
|
|
1270
|
+
return require_v3_engine.resolveTailwindV4EntriesFromCss(cssSource.css, sourceBase);
|
|
1271
|
+
}
|
|
1272
|
+
function countRuntimeCandidateHits(candidates, runtime) {
|
|
1273
|
+
if (!runtime?.size) return 0;
|
|
1274
|
+
let hits = 0;
|
|
1275
|
+
for (const candidate of candidates) if (runtime.has(candidate)) hits += 1;
|
|
1276
|
+
return hits;
|
|
1277
|
+
}
|
|
1278
|
+
async function resolveCandidateMatchedTailwindV4CssSource(_rawSource, cssHandlerOptions, sourceOptions, selectionOptions) {
|
|
1279
|
+
const cssSources = sourceOptions.cssSources;
|
|
1280
|
+
const getSourceCandidatesForEntries = selectionOptions?.getSourceCandidatesForEntries;
|
|
1281
|
+
if (!cssHandlerOptions.isMainChunk || !cssSources?.length || !getSourceCandidatesForEntries) return;
|
|
1282
|
+
const matches = [];
|
|
1283
|
+
await Promise.all(cssSources.map(async (cssSource, index) => {
|
|
1284
|
+
const resolved = await resolveTailwindV4CssSourceEntries(cssSource, sourceOptions);
|
|
1285
|
+
if (resolved?.entries === void 0) return;
|
|
1286
|
+
const scopedCandidates = getSourceCandidatesForEntries(resolved?.entries);
|
|
1287
|
+
const runtimeHits = countRuntimeCandidateHits(scopedCandidates, selectionOptions?.runtime);
|
|
1288
|
+
if (runtimeHits === 0) return;
|
|
1289
|
+
matches.push({
|
|
1290
|
+
cssSource,
|
|
1291
|
+
index,
|
|
1292
|
+
runtimeHits,
|
|
1293
|
+
totalCandidates: scopedCandidates.size
|
|
1294
|
+
});
|
|
1295
|
+
}));
|
|
1296
|
+
if (matches.length === 0) return;
|
|
1297
|
+
matches.sort((a, b) => b.runtimeHits - a.runtimeHits || b.totalCandidates - a.totalCandidates || a.index - b.index);
|
|
1298
|
+
const best = matches[0];
|
|
1299
|
+
const second = matches[1];
|
|
1300
|
+
if (!best) return;
|
|
1301
|
+
if (second && second.runtimeHits === best.runtimeHits && second.totalCandidates === best.totalCandidates) return;
|
|
1302
|
+
return resolveSingleTailwindV4CssSource(best.cssSource, sourceOptions);
|
|
1303
|
+
}
|
|
1304
|
+
function createTailwindV4CssSourceResolver(sourceOptions, generatorOptions) {
|
|
1305
|
+
return (cssSource) => require_v3_engine.resolveTailwindV4Source({
|
|
1306
|
+
...require_v3_engine.omitUndefined(sourceOptions),
|
|
1307
|
+
cssSources: [cssSource]
|
|
1308
|
+
}).then((source) => generatorOptions?.config ? {
|
|
1309
|
+
...source,
|
|
1310
|
+
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
1311
|
+
} : source);
|
|
1312
|
+
}
|
|
1313
|
+
async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourceOptions, generatorOptions, file) {
|
|
1314
|
+
if (!resolvedEntrySource) return;
|
|
1315
|
+
const resolvedSourceOptions = require_v3_engine.omitUndefined(sourceOptions);
|
|
1316
|
+
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, resolvedSourceOptions);
|
|
1317
|
+
const css = createTailwindV4ApplyReferenceSource(normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions);
|
|
1318
|
+
return withMatchedSourceSideMetadata(await require_v3_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(resolvedSourceOptions, {
|
|
1319
|
+
base: resolvedEntrySource.base,
|
|
1320
|
+
css
|
|
1321
|
+
})), resolvedEntrySource);
|
|
1322
|
+
}
|
|
1323
|
+
function withGeneratorSourceMetadata(source, metadata) {
|
|
1324
|
+
return {
|
|
1325
|
+
...source,
|
|
1326
|
+
__weappTailwindcssMeta: metadata
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
1330
|
+
return resolvedEntrySource.file ? withGeneratorSourceMetadata(source, {
|
|
1331
|
+
matchedCssSourceFile: resolvedEntrySource.file,
|
|
1332
|
+
sourceBase: resolvedEntrySource.base,
|
|
1333
|
+
sourceCss: resolvedEntrySource.css
|
|
1334
|
+
}) : source;
|
|
1335
|
+
}
|
|
1336
|
+
function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
|
|
1337
|
+
if (!hasTailwindApplyDirective(css) || hasTailwindRootDirectives(css)) return css;
|
|
1338
|
+
return `@reference "${sourceOptions.packageName ?? "tailwindcss"}";\n${css}`;
|
|
1339
|
+
}
|
|
1340
|
+
async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
|
|
1341
|
+
const base = resolveCssSourceBase(file, cssHandlerOptions);
|
|
1342
|
+
const cssEntrySource = resolveCssEntrySource(rawSource, base, {
|
|
1343
|
+
importFallback: generatorOptions?.importFallback ?? false,
|
|
1344
|
+
removeConfig: majorVersion === 3
|
|
1345
|
+
});
|
|
1346
|
+
if (majorVersion === 3) {
|
|
1347
|
+
const sourceOptions = require_v3_engine.resolveTailwindV3SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
1348
|
+
const mergedSourceOptions = require_v3_engine.omitUndefined({
|
|
1349
|
+
...sourceOptions,
|
|
1350
|
+
config: generatorOptions?.config ?? sourceOptions.config,
|
|
1351
|
+
...resolveCssHandlerSourceOptions(cssHandlerOptions)
|
|
1352
|
+
});
|
|
1353
|
+
const applyEntrySource = hasTailwindApplyDirective(rawSource) ? {
|
|
1354
|
+
base,
|
|
1355
|
+
css: rawSource
|
|
1356
|
+
} : void 0;
|
|
1357
|
+
const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
|
|
1358
|
+
const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ? applyEntrySource ?? cssEntrySource ?? sourceSideEntrySource : shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) ? sourceSideEntrySource ?? cssEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource;
|
|
1359
|
+
if (!resolvedEntrySource) return generatorOptions?.config ? require_v3_engine.resolveTailwindV3Source(mergedSourceOptions) : require_v3_engine.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
|
|
1360
|
+
if (cssEntrySource && !sourceSideEntrySource && !applyEntrySource && !hasTailwindRootDirectives(rawSource, { importFallback: true })) return generatorOptions?.config ? require_v3_engine.resolveTailwindV3Source(mergedSourceOptions) : require_v3_engine.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
|
|
1361
|
+
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, require_v3_engine.omitUndefined(mergedSourceOptions));
|
|
1362
|
+
return require_v3_engine.resolveTailwindV3Source({
|
|
1363
|
+
...mergedSourceOptions,
|
|
1364
|
+
base: resolvedEntrySource.base,
|
|
1365
|
+
css: resolvedEntrySource.css,
|
|
1366
|
+
...config ? { config } : {}
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
|
|
1370
|
+
const resolvedSourceOptions = sourceOptions ? require_v3_engine.omitUndefined({
|
|
1371
|
+
...sourceOptions,
|
|
1372
|
+
...resolveCssHandlerSourceOptions(cssHandlerOptions)
|
|
1373
|
+
}) : void 0;
|
|
1374
|
+
const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder"));
|
|
1375
|
+
const sourceSideEntrySource = resolvedSourceOptions && shouldPreferSourceSideEntry ? resolveSourceSideCssEntrySource(file, resolvedSourceOptions, { removeConfig: false }) : void 0;
|
|
1376
|
+
const matchedCssSource = sourceOptions ? await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions) : void 0;
|
|
1377
|
+
const candidateMatchedCssSource = sourceOptions ? await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions) : void 0;
|
|
1378
|
+
const configuredCssSource = sourceOptions && hasConfiguredTailwindV4CssSource(sourceOptions) && hasTailwindGeneratedCssMarkers(rawSource) ? matchedCssSource ?? candidateMatchedCssSource ?? await require_v3_engine.resolveTailwindV4Source(sourceOptions) : void 0;
|
|
1379
|
+
if (configuredCssSource) return generatorOptions?.config ? {
|
|
1380
|
+
...configuredCssSource,
|
|
1381
|
+
css: prependConfigDirective(configuredCssSource.css, generatorOptions.config)
|
|
1382
|
+
} : configuredCssSource;
|
|
1383
|
+
const matchedCssEntrySource = sourceOptions && cssEntrySource ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
|
|
1384
|
+
const mainCssEntrySource = sourceOptions && cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1 ? await require_v3_engine.resolveTailwindV4Source({
|
|
1385
|
+
...require_v3_engine.omitUndefined(sourceOptions),
|
|
1386
|
+
cssEntries: [sourceOptions.cssEntries[0]]
|
|
1387
|
+
}) : void 0;
|
|
1388
|
+
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource ?? mainCssEntrySource;
|
|
1389
|
+
if (preferredCssEntrySource) return generatorOptions?.config ? {
|
|
1390
|
+
...preferredCssEntrySource,
|
|
1391
|
+
css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
1392
|
+
} : preferredCssEntrySource;
|
|
1393
|
+
const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource;
|
|
1394
|
+
if (!resolvedEntrySource) {
|
|
1395
|
+
const source = await require_v3_engine.resolveTailwindV4SourceFromPatcher(runtimeState.twPatcher);
|
|
1396
|
+
return generatorOptions?.config ? {
|
|
1397
|
+
...source,
|
|
1398
|
+
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
1399
|
+
} : source;
|
|
1400
|
+
}
|
|
1401
|
+
if (sourceSideEntrySource && resolvedSourceOptions) return resolveTailwindV4SourceSideEntrySource(sourceSideEntrySource, resolvedSourceOptions, generatorOptions, file);
|
|
1402
|
+
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, resolvedSourceOptions ?? {});
|
|
1403
|
+
const css = createTailwindV4ApplyReferenceSource(normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions ?? {});
|
|
1404
|
+
return require_v3_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(resolvedSourceOptions ?? {}, {
|
|
1405
|
+
base: resolvedEntrySource.base,
|
|
1406
|
+
css
|
|
1407
|
+
}));
|
|
1408
|
+
}
|
|
1409
|
+
async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
|
|
1410
|
+
const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), {
|
|
1411
|
+
importFallback: generatorOptions?.importFallback ?? false,
|
|
1412
|
+
removeConfig: majorVersion === 3
|
|
1413
|
+
});
|
|
1414
|
+
if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk) {
|
|
1415
|
+
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
1416
|
+
return resolved ? [resolved] : [];
|
|
1417
|
+
}
|
|
1418
|
+
let sourceOptions;
|
|
1419
|
+
try {
|
|
1420
|
+
sourceOptions = require_v3_engine.omitUndefined({
|
|
1421
|
+
...require_v3_engine.resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher),
|
|
1422
|
+
...resolveCssHandlerSourceOptions(cssHandlerOptions)
|
|
1423
|
+
});
|
|
1424
|
+
} catch {
|
|
1425
|
+
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
1426
|
+
return resolved ? [resolved] : [];
|
|
1427
|
+
}
|
|
1428
|
+
const matchedCssEntrySource = cssEntrySource ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
|
|
1429
|
+
const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
|
|
1430
|
+
const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
|
|
1431
|
+
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource(shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
|
|
1432
|
+
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource;
|
|
1433
|
+
if (sourceSideCssSource) return [sourceSideCssSource];
|
|
1434
|
+
if (preferredCssEntrySource) return [generatorOptions?.config ? {
|
|
1435
|
+
...preferredCssEntrySource,
|
|
1436
|
+
css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
1437
|
+
} : preferredCssEntrySource];
|
|
1438
|
+
if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) {
|
|
1439
|
+
if (sourceOptions.cssSources?.length === 1) return [await createTailwindV4CssSourceResolver(sourceOptions, generatorOptions)(sourceOptions.cssSources[0])];
|
|
1440
|
+
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
1441
|
+
return resolved ? [resolved] : [];
|
|
1442
|
+
}
|
|
1443
|
+
const cssEntrySources = await Promise.all(sourceOptions.cssEntries.map((cssEntry) => require_v3_engine.resolveTailwindV4Source({
|
|
1444
|
+
...require_v3_engine.omitUndefined(sourceOptions),
|
|
1445
|
+
cssEntries: [cssEntry]
|
|
1446
|
+
}).then((source) => generatorOptions?.config ? {
|
|
1447
|
+
...source,
|
|
1448
|
+
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
1449
|
+
} : source)));
|
|
1450
|
+
const cssSources = sourceOptions.cssSources?.length ? await Promise.all(sourceOptions.cssSources.map(createTailwindV4CssSourceResolver(sourceOptions, generatorOptions))) : [];
|
|
1451
|
+
return [...cssEntrySources, ...cssSources];
|
|
1452
|
+
}
|
|
1453
|
+
async function resolveGeneratorSourceEntries(source, runtimeState) {
|
|
1454
|
+
if (!("css" in source) || !("base" in source) || !("baseFallbacks" in source)) return;
|
|
1455
|
+
const sourceMetadata = source.__weappTailwindcssMeta;
|
|
1456
|
+
const resolved = await require_v3_engine.resolveTailwindV4EntriesFromCss(sourceMetadata?.sourceCss ?? source.css, sourceMetadata?.sourceBase ?? source.base);
|
|
1457
|
+
if (resolved?.entries.length || !resolved?.explicit && !sourceMetadata?.matchedCssSourceFile || !runtimeState) return resolved?.entries;
|
|
1458
|
+
const matchingCssSource = tryResolveTailwindV4SourceOptions(runtimeState)?.cssSources?.find((cssSource) => {
|
|
1459
|
+
if (sourceMetadata?.matchedCssSourceFile && typeof cssSource.file === "string" && node_path.default.resolve(cssSource.file) === node_path.default.resolve(sourceMetadata.matchedCssSourceFile)) return true;
|
|
1460
|
+
return cssSource.css === source.css;
|
|
1461
|
+
});
|
|
1462
|
+
if (!matchingCssSource) return resolved?.entries;
|
|
1463
|
+
const sourceResolved = await require_v3_engine.resolveTailwindV4EntriesFromCss(matchingCssSource.css, typeof matchingCssSource.base === "string" && matchingCssSource.base.length > 0 ? matchingCssSource.base : typeof matchingCssSource.file === "string" && matchingCssSource.file.length > 0 ? node_path.default.dirname(matchingCssSource.file) : source.base);
|
|
1464
|
+
if (sourceResolved?.entries.length) return sourceResolved.entries;
|
|
1465
|
+
for (const dependency of matchingCssSource.dependencies ?? []) {
|
|
1466
|
+
if (!(0, node_fs.existsSync)(dependency)) continue;
|
|
1467
|
+
try {
|
|
1468
|
+
const dependencyResolved = await require_v3_engine.resolveTailwindV4EntriesFromCss((0, node_fs.readFileSync)(dependency, "utf8"), node_path.default.dirname(dependency));
|
|
1469
|
+
if (dependencyResolved?.entries.length) return dependencyResolved.entries;
|
|
1470
|
+
} catch {}
|
|
1471
|
+
}
|
|
1472
|
+
return resolved?.entries;
|
|
1473
|
+
}
|
|
1474
|
+
//#endregion
|
|
1475
|
+
//#region src/bundlers/shared/generator-css/legacy-compat.ts
|
|
1476
|
+
const LEGACY_CONTAINER_COMPAT_CSS = [
|
|
1477
|
+
".container {",
|
|
1478
|
+
" width: 100%;",
|
|
1479
|
+
"}",
|
|
1480
|
+
"@media (min-width: 40rem) {",
|
|
1481
|
+
" .container {",
|
|
1482
|
+
" max-width: 40rem;",
|
|
1483
|
+
" }",
|
|
1484
|
+
"}",
|
|
1485
|
+
"@media (min-width: 48rem) {",
|
|
1486
|
+
" .container {",
|
|
1487
|
+
" max-width: 48rem;",
|
|
1488
|
+
" }",
|
|
1489
|
+
"}",
|
|
1490
|
+
"@media (min-width: 64rem) {",
|
|
1491
|
+
" .container {",
|
|
1492
|
+
" max-width: 64rem;",
|
|
1493
|
+
" }",
|
|
1494
|
+
"}",
|
|
1495
|
+
"@media (min-width: 80rem) {",
|
|
1496
|
+
" .container {",
|
|
1497
|
+
" max-width: 80rem;",
|
|
1498
|
+
" }",
|
|
1499
|
+
"}",
|
|
1500
|
+
"@media (min-width: 96rem) {",
|
|
1501
|
+
" .container {",
|
|
1502
|
+
" max-width: 96rem;",
|
|
1503
|
+
" }",
|
|
1504
|
+
"}"
|
|
1505
|
+
].join("\n");
|
|
1506
|
+
const LEGACY_COMPAT_CACHE_LIMIT = 128;
|
|
1507
|
+
const legacyCompatSourceCache = /* @__PURE__ */ new Map();
|
|
1508
|
+
const legacyCompatTransformCache = /* @__PURE__ */ new Map();
|
|
1509
|
+
function setLimitedCacheValue(cache, key, value) {
|
|
1510
|
+
if (cache.size >= LEGACY_COMPAT_CACHE_LIMIT) {
|
|
1511
|
+
const firstKey = cache.keys().next().value;
|
|
1512
|
+
if (firstKey !== void 0) cache.delete(firstKey);
|
|
1513
|
+
}
|
|
1514
|
+
cache.set(key, value);
|
|
1515
|
+
}
|
|
1516
|
+
function createStableJson(value) {
|
|
1517
|
+
if (value === void 0) return "undefined";
|
|
1518
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
1519
|
+
if (Array.isArray(value)) return `[${value.map((item) => createStableJson(item)).join(",")}]`;
|
|
1520
|
+
return `{${Object.keys(value).sort().map((key) => {
|
|
1521
|
+
const record = value;
|
|
1522
|
+
return `${JSON.stringify(key)}:${createStableJson(record[key])}`;
|
|
1523
|
+
}).join(",")}}`;
|
|
1524
|
+
}
|
|
1525
|
+
function createLegacyCompatTransformCacheKey(source, options) {
|
|
1526
|
+
return `${createStableJson(options)}\0${source}`;
|
|
1527
|
+
}
|
|
1528
|
+
function countUnclosedBlocks(source) {
|
|
1529
|
+
let depth = 0;
|
|
1530
|
+
let quote;
|
|
1531
|
+
let inComment = false;
|
|
1532
|
+
let escaped = false;
|
|
1533
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
1534
|
+
const char = source[index];
|
|
1535
|
+
const next = source[index + 1];
|
|
1536
|
+
if (inComment) {
|
|
1537
|
+
if (char === "*" && next === "/") {
|
|
1538
|
+
inComment = false;
|
|
1539
|
+
index += 1;
|
|
1540
|
+
}
|
|
1541
|
+
continue;
|
|
1542
|
+
}
|
|
1543
|
+
if (quote) {
|
|
1544
|
+
if (escaped) {
|
|
1545
|
+
escaped = false;
|
|
1546
|
+
continue;
|
|
1547
|
+
}
|
|
1548
|
+
if (char === "\\") {
|
|
1549
|
+
escaped = true;
|
|
1550
|
+
continue;
|
|
1551
|
+
}
|
|
1552
|
+
if (char === quote) quote = void 0;
|
|
1553
|
+
continue;
|
|
1554
|
+
}
|
|
1555
|
+
if (char === "/" && next === "*") {
|
|
1556
|
+
inComment = true;
|
|
1557
|
+
index += 1;
|
|
1558
|
+
continue;
|
|
1559
|
+
}
|
|
1560
|
+
if (char === "\"" || char === "'") {
|
|
1561
|
+
quote = char;
|
|
1562
|
+
continue;
|
|
1563
|
+
}
|
|
1564
|
+
if (char === "{") depth += 1;
|
|
1565
|
+
else if (char === "}" && depth > 0) depth -= 1;
|
|
1566
|
+
}
|
|
1567
|
+
return depth;
|
|
1568
|
+
}
|
|
1569
|
+
function closeTrailingUnclosedBlocks(source) {
|
|
1570
|
+
try {
|
|
1571
|
+
postcss.default.parse(source);
|
|
1572
|
+
return source;
|
|
1573
|
+
} catch (error) {
|
|
1574
|
+
if (error.reason !== "Unclosed block") return source;
|
|
1575
|
+
const unclosedBlocks = countUnclosedBlocks(source);
|
|
1576
|
+
return unclosedBlocks > 0 ? `${source}${"}".repeat(unclosedBlocks)}` : source;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
function removeTailwindApplyRules(rawSource) {
|
|
1580
|
+
try {
|
|
1581
|
+
const root = postcss.default.parse(rawSource);
|
|
1582
|
+
let removed = false;
|
|
1583
|
+
root.walkAtRules("apply", (rule) => {
|
|
1584
|
+
const parent = rule.parent;
|
|
1585
|
+
if (parent?.type === "rule") parent.remove();
|
|
1586
|
+
else rule.remove();
|
|
1587
|
+
removed = true;
|
|
1588
|
+
});
|
|
1589
|
+
root.walkAtRules((rule) => {
|
|
1590
|
+
if (rule.nodes && rule.nodes.length === 0) rule.remove();
|
|
1591
|
+
});
|
|
1592
|
+
return removed ? root.toString() : rawSource;
|
|
1593
|
+
} catch {
|
|
1594
|
+
return rawSource;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
function resolveLegacyCompatCssSource(rawSource) {
|
|
1598
|
+
const cached = legacyCompatSourceCache.get(rawSource);
|
|
1599
|
+
if (cached !== void 0) return cached;
|
|
1600
|
+
const resolved = closeTrailingUnclosedBlocks(removeUnsupportedMiniProgramAtRules(removeTailwindApplyRules(removeTailwindSourceDirectives(closeTrailingUnclosedBlocks(stripTailwindBanners(rawSource))))));
|
|
1601
|
+
setLimitedCacheValue(legacyCompatSourceCache, rawSource, resolved);
|
|
1602
|
+
return resolved;
|
|
1603
|
+
}
|
|
1604
|
+
function hasContainerConfigToken(rawSource) {
|
|
1605
|
+
return rawSource.includes("@config") && /\bcontainer\b/.test(rawSource);
|
|
1606
|
+
}
|
|
1607
|
+
function hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) {
|
|
1608
|
+
if (hasContainerConfigToken(rawSource)) return true;
|
|
1609
|
+
const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions));
|
|
1610
|
+
if (!cssEntrySource?.config) return false;
|
|
1611
|
+
try {
|
|
1612
|
+
return /\bcontainer\b/.test((0, node_fs.readFileSync)(cssEntrySource.config, "utf8"));
|
|
1613
|
+
} catch {
|
|
1614
|
+
return false;
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
function hasConfiguredContainerCompatSource(source) {
|
|
1618
|
+
if (hasContainerConfigToken(source.css)) return true;
|
|
1619
|
+
const cssEntrySource = resolveCssEntrySource(source.css, source.base);
|
|
1620
|
+
if (cssEntrySource?.config) try {
|
|
1621
|
+
if (/\bcontainer\b/.test((0, node_fs.readFileSync)(cssEntrySource.config, "utf8"))) return true;
|
|
1622
|
+
} catch {}
|
|
1623
|
+
if ("config" in source && source.config) try {
|
|
1624
|
+
if (/\bcontainer\b/.test((0, node_fs.readFileSync)(source.config, "utf8"))) return true;
|
|
1625
|
+
} catch {}
|
|
1626
|
+
return false;
|
|
1627
|
+
}
|
|
1628
|
+
function hasConfiguredContainerCompatSources(sources) {
|
|
1629
|
+
return sources.some((source) => hasConfiguredContainerCompatSource(source));
|
|
1630
|
+
}
|
|
1631
|
+
async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
|
|
1632
|
+
const compatSource = removeGeneratedSelectorCompatCss(resolveLegacyCompatCssSource(rawSource), css);
|
|
1633
|
+
if (compatSource.trim().length === 0) return css;
|
|
1634
|
+
if (generatorTarget !== "weapp") return createCssAppend(css, compatSource);
|
|
1635
|
+
const styleOptions = {
|
|
1636
|
+
...cssHandlerOptions,
|
|
1637
|
+
...generatorStyleOptions
|
|
1638
|
+
};
|
|
1639
|
+
const compatCssCacheKey = createLegacyCompatTransformCacheKey(compatSource, styleOptions);
|
|
1640
|
+
let compatCss = legacyCompatTransformCache.get(compatCssCacheKey);
|
|
1641
|
+
if (compatCss === void 0) {
|
|
1642
|
+
compatCss = (await styleHandler(compatSource, styleOptions)).css;
|
|
1643
|
+
setLimitedCacheValue(legacyCompatTransformCache, compatCssCacheKey, compatCss);
|
|
1644
|
+
}
|
|
1645
|
+
const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeDuplicatedViteMarkers(removeUnsupportedMiniProgramAtRules(compatCss), css), css);
|
|
1646
|
+
if (cleanedCompatCss.trim().length === 0) return css;
|
|
1647
|
+
return createCssAppend(css, cleanedCompatCss);
|
|
1648
|
+
}
|
|
1649
|
+
async function appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
|
|
1650
|
+
const compatSource = resolveLegacyCompatCssSource(rawSource);
|
|
1651
|
+
const shouldAppendContainer = runtime.has("container") || hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) || configuredContainerCompat || collectGeneratedSelectors(compatSource).has(".container");
|
|
1652
|
+
if (generatorTarget !== "weapp" || !shouldAppendContainer || collectGeneratedSelectors(css).has(".container")) return css;
|
|
1653
|
+
const styleOptions = {
|
|
1654
|
+
...cssHandlerOptions,
|
|
1655
|
+
...generatorStyleOptions
|
|
1656
|
+
};
|
|
1657
|
+
const compatCssCacheKey = createLegacyCompatTransformCacheKey(LEGACY_CONTAINER_COMPAT_CSS, styleOptions);
|
|
1658
|
+
let compatCss = legacyCompatTransformCache.get(compatCssCacheKey);
|
|
1659
|
+
if (compatCss === void 0) {
|
|
1660
|
+
compatCss = (await styleHandler(LEGACY_CONTAINER_COMPAT_CSS, styleOptions)).css;
|
|
1661
|
+
setLimitedCacheValue(legacyCompatTransformCache, compatCssCacheKey, compatCss);
|
|
1662
|
+
}
|
|
1663
|
+
const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeUnsupportedMiniProgramAtRules(compatCss), css);
|
|
1664
|
+
if (cleanedCompatCss.trim().length === 0) return css;
|
|
1665
|
+
return createCssAppend(css, cleanedCompatCss);
|
|
1666
|
+
}
|
|
1667
|
+
//#endregion
|
|
1668
|
+
//#region src/bundlers/shared/generator-css/legacy-units.ts
|
|
1669
|
+
const CSS_LENGTH_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)(?:px|rem)\b/i;
|
|
1670
|
+
const RPX_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)rpx\b/i;
|
|
1671
|
+
function createLegacyDeclarationValueMap(css) {
|
|
1672
|
+
const values = /* @__PURE__ */ new Map();
|
|
1673
|
+
postcss.default.parse(css).walkRules((rule) => {
|
|
1674
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
1675
|
+
for (const selector of rule.selectors) {
|
|
1676
|
+
const normalizedSelectors = normalizeCompatSelectors(selector);
|
|
1677
|
+
rule.walkDecls((decl) => {
|
|
1678
|
+
if (RPX_UNIT_RE.test(decl.value)) for (const normalizedSelector of normalizedSelectors) values.set(`${normalizedSelector}\n${decl.prop}`, decl.value);
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1681
|
+
});
|
|
1682
|
+
return values;
|
|
1683
|
+
}
|
|
1684
|
+
function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
|
|
1685
|
+
try {
|
|
1686
|
+
const legacyValues = createLegacyDeclarationValueMap(legacyCss);
|
|
1687
|
+
if (legacyValues.size === 0) return css;
|
|
1688
|
+
const root = postcss.default.parse(css);
|
|
1689
|
+
let changed = false;
|
|
1690
|
+
root.walkRules((rule) => {
|
|
1691
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
1692
|
+
const selectors = rule.selectors.flatMap((selector) => normalizeCompatSelectors(selector));
|
|
1693
|
+
if (selectors.length === 0) return;
|
|
1694
|
+
rule.walkDecls((decl) => {
|
|
1695
|
+
if (!CSS_LENGTH_UNIT_RE.test(decl.value)) return;
|
|
1696
|
+
for (const selector of selectors) {
|
|
1697
|
+
const legacyValue = legacyValues.get(`${selector}\n${decl.prop}`);
|
|
1698
|
+
if (legacyValue && legacyValue !== decl.value) {
|
|
1699
|
+
decl.value = legacyValue;
|
|
1700
|
+
changed = true;
|
|
1701
|
+
return;
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
});
|
|
1705
|
+
});
|
|
1706
|
+
return changed ? root.toString() : css;
|
|
1707
|
+
} catch {
|
|
1708
|
+
return css;
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
//#endregion
|
|
1712
|
+
//#region src/bundlers/shared/generator-css.ts
|
|
1713
|
+
const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
|
|
1714
|
+
const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
|
|
1715
|
+
function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight, options = {}) {
|
|
1716
|
+
if (target !== "weapp") return css;
|
|
1717
|
+
return finalizeMiniProgramCss(css, {
|
|
1718
|
+
cssPreflight: majorVersion === 4 && options.injectPreflight !== false ? cssPreflight : void 0,
|
|
1719
|
+
preservePseudoContentInit: majorVersion === 3
|
|
1720
|
+
});
|
|
1721
|
+
}
|
|
1722
|
+
function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
|
|
1723
|
+
if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.isolateCssSource) return scopedRuntime;
|
|
1724
|
+
return new Set([...scopedRuntime, ...runtime]);
|
|
1725
|
+
}
|
|
1726
|
+
function shouldIsolateMatchedCssSource(source, sourceEntries) {
|
|
1727
|
+
return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile && sourceEntries !== void 0);
|
|
1728
|
+
}
|
|
1729
|
+
function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
|
|
1730
|
+
const preflightStyleOptions = {
|
|
1731
|
+
cssPreflight: opts.cssPreflight,
|
|
1732
|
+
cssPreflightRange: opts.cssPreflightRange
|
|
1733
|
+
};
|
|
1734
|
+
const resolvedUniAppXOptions = require_tailwindcss.resolveUniAppXOptions(opts.uniAppX);
|
|
1735
|
+
return {
|
|
1736
|
+
cssChildCombinatorReplaceValue: opts.cssChildCombinatorReplaceValue,
|
|
1737
|
+
cssSelectorReplacement: opts.cssSelectorReplacement,
|
|
1738
|
+
rem2rpx: opts.rem2rpx,
|
|
1739
|
+
px2rpx: opts.px2rpx,
|
|
1740
|
+
unitsToPx: opts.unitsToPx,
|
|
1741
|
+
cssRemoveProperty: opts.cssRemoveProperty,
|
|
1742
|
+
cssRemoveHoverPseudoClass: opts.cssRemoveHoverPseudoClass,
|
|
1743
|
+
cssPresetEnv: opts.cssPresetEnv,
|
|
1744
|
+
autoprefixer: opts.autoprefixer,
|
|
1745
|
+
cssCalc: opts.cssCalc,
|
|
1746
|
+
atRules: opts.atRules,
|
|
1747
|
+
uniAppX: resolvedUniAppXOptions.enabled,
|
|
1748
|
+
uniAppXCssTarget: opts.uniAppXCssTarget,
|
|
1749
|
+
uniAppXUnsupported: opts.uniAppXUnsupported,
|
|
1750
|
+
...cssHandlerOptions,
|
|
1751
|
+
...preflightStyleOptions,
|
|
1752
|
+
...generatorStyleOptions
|
|
1753
|
+
};
|
|
1754
|
+
}
|
|
1755
|
+
function isLocalImportRequest(request) {
|
|
1756
|
+
return request.length > 0 && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
1757
|
+
}
|
|
1758
|
+
function isCommentOnlyCss(source) {
|
|
1759
|
+
try {
|
|
1760
|
+
const root = postcss.default.parse(source);
|
|
1761
|
+
return root.nodes.length > 0 && root.nodes.every((node) => node.type === "comment");
|
|
1762
|
+
} catch {
|
|
1763
|
+
return false;
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
function stripTailwindSourceMediaFragments(source) {
|
|
1767
|
+
return source.replace(/^\s*@media\s+source\([^)]*\)\s*\{\s*$/gm, "").replace(/^\s*\}\s*(?=@(?:source|theme|config|plugin|utility|variant|custom-variant)\b)/gm, "").replace(/^\s*\}\s*\/\*\s*source\([^)]*\)\s*\*\/\s*$/gm, "");
|
|
1768
|
+
}
|
|
1769
|
+
function stripLeadingTailwindSourceMediaCloseFragment(source) {
|
|
1770
|
+
return source.replace(/^\s*\}\s*(?:\n|$)/, "");
|
|
1771
|
+
}
|
|
1772
|
+
function stripUnmatchedTailwindSourceMediaCloseFragments(source) {
|
|
1773
|
+
try {
|
|
1774
|
+
postcss.default.parse(source);
|
|
1775
|
+
return source;
|
|
1776
|
+
} catch {
|
|
1777
|
+
return stripLeadingTailwindSourceMediaCloseFragment(source).replace(/\s*\}\s*$/, "");
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
function createCssSourceOrderAppend(base, extra) {
|
|
1781
|
+
if (!base) return extra;
|
|
1782
|
+
if (!extra) return base;
|
|
1783
|
+
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
1784
|
+
return `${base}\n${extra}`;
|
|
1785
|
+
}
|
|
1786
|
+
function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
|
|
1787
|
+
const placeholderParts = splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
|
|
1788
|
+
if (placeholderParts) return placeholderParts;
|
|
1789
|
+
const exactParts = splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss);
|
|
1790
|
+
if (exactParts) return exactParts;
|
|
1791
|
+
return splitTailwindGeneratedCssByBanner(rawSource);
|
|
1792
|
+
}
|
|
1793
|
+
async function transformGeneratorUserCss(source, options) {
|
|
1794
|
+
if (source.trim().length === 0) return "";
|
|
1795
|
+
const cleanedSource = removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source)), { importFallback: options.importFallback });
|
|
1796
|
+
if (cleanedSource.trim().length === 0) return "";
|
|
1797
|
+
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? removeUnsupportedMiniProgramAtRules(cleanedSource) : cleanedSource)), { importFallback: options.importFallback }));
|
|
1798
|
+
if (userSource.trim().length === 0) return "";
|
|
1799
|
+
if (isCommentOnlyCss(userSource)) return userSource;
|
|
1800
|
+
if (options.generatorTarget !== "weapp") return userSource;
|
|
1801
|
+
const { css } = await options.styleHandler(userSource, {
|
|
1802
|
+
...options.generatorStyleOptions,
|
|
1803
|
+
...options.cssUserHandlerOptions
|
|
1804
|
+
});
|
|
1805
|
+
return removeUnsupportedMiniProgramAtRules(css);
|
|
1806
|
+
}
|
|
1807
|
+
function isPureLocalCssImportWrapper(css) {
|
|
1808
|
+
let hasImport = false;
|
|
1809
|
+
try {
|
|
1810
|
+
const root = postcss.default.parse(css);
|
|
1811
|
+
for (const node of root.nodes) {
|
|
1812
|
+
if (node.type === "comment") continue;
|
|
1813
|
+
if (node.type !== "atrule" || node.name !== "import") return false;
|
|
1814
|
+
const request = parseImportRequest(node.params);
|
|
1815
|
+
if (!request || !isLocalImportRequest(request)) return false;
|
|
1816
|
+
hasImport = true;
|
|
1817
|
+
}
|
|
1818
|
+
} catch {
|
|
1819
|
+
return false;
|
|
1820
|
+
}
|
|
1821
|
+
return hasImport;
|
|
1822
|
+
}
|
|
1823
|
+
function cleanLocalCssImportWrapperTailwindDirectives(css) {
|
|
1824
|
+
let hasLocalImport = false;
|
|
1825
|
+
let hasTailwindDirective = false;
|
|
1826
|
+
try {
|
|
1827
|
+
const root = postcss.default.parse(css);
|
|
1828
|
+
for (const node of root.nodes) {
|
|
1829
|
+
if (node.type === "comment") continue;
|
|
1830
|
+
if (node.type === "atrule" && node.name === "import") {
|
|
1831
|
+
const request = parseImportRequest(node.params);
|
|
1832
|
+
if (!request || !isLocalImportRequest(request)) return;
|
|
1833
|
+
hasLocalImport = true;
|
|
1834
|
+
continue;
|
|
1835
|
+
}
|
|
1836
|
+
if (node.type === "atrule" && node.name === "source") {
|
|
1837
|
+
hasTailwindDirective = true;
|
|
1838
|
+
continue;
|
|
1839
|
+
}
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1842
|
+
} catch {
|
|
1843
|
+
return;
|
|
1844
|
+
}
|
|
1845
|
+
return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(removeTailwindSourceDirectives(css)) : void 0;
|
|
1846
|
+
}
|
|
1847
|
+
function prefixLocalCssImportsWithWebpackIgnore(css) {
|
|
1848
|
+
try {
|
|
1849
|
+
const root = postcss.default.parse(css);
|
|
1850
|
+
root.walkAtRules("import", (atRule) => {
|
|
1851
|
+
const request = parseImportRequest(atRule.params);
|
|
1852
|
+
if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
|
|
1853
|
+
});
|
|
1854
|
+
return root.toString();
|
|
1855
|
+
} catch {
|
|
1856
|
+
return css;
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
async function generateCssByGenerator(options) {
|
|
1860
|
+
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, debug } = options;
|
|
1861
|
+
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
1862
|
+
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
1863
|
+
const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
|
|
1864
|
+
const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(effectiveRawSource);
|
|
1865
|
+
if (cleanedLocalImportWrapper !== void 0) return {
|
|
1866
|
+
css: generatorOptions.target === "weapp" ? removeUnsupportedMiniProgramAtRules(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
|
|
1867
|
+
target: generatorOptions.target,
|
|
1868
|
+
source: "generator",
|
|
1869
|
+
dependencies: []
|
|
1870
|
+
};
|
|
1871
|
+
if (isPureLocalCssImportWrapper(effectiveRawSource)) return;
|
|
1872
|
+
const hasGeneratedCss = hasTailwindGeneratedCss(effectiveRawSource);
|
|
1873
|
+
const hasSourceDirectives = hasTailwindSourceDirectives(effectiveRawSource, { importFallback: generatorOptions.importFallback });
|
|
1874
|
+
const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(effectiveRawSource);
|
|
1875
|
+
const shouldGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
|
|
1876
|
+
if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
|
|
1877
|
+
try {
|
|
1878
|
+
await runtimeState.readyPromise;
|
|
1879
|
+
const sources = await resolveGeneratorSources(majorVersion, runtimeState, effectiveRawSource, file, cssHandlerOptions, generatorOptions, {
|
|
1880
|
+
getSourceCandidatesForEntries,
|
|
1881
|
+
runtime
|
|
1882
|
+
});
|
|
1883
|
+
const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
|
|
1884
|
+
const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
|
|
1885
|
+
const generatedResults = await Promise.all(sources.map(async (source) => {
|
|
1886
|
+
const generator = require_generator.createWeappTailwindcssGenerator(source);
|
|
1887
|
+
const sourceEntries = getSourceCandidatesForEntries && majorVersion === 4 ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
|
|
1888
|
+
const scopedRuntime = sourceEntries ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
|
|
1889
|
+
const isolateCssSource = shouldIsolateMatchedCssSource(source, sourceEntries);
|
|
1890
|
+
const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, {
|
|
1891
|
+
cssHandlerOptions,
|
|
1892
|
+
isolateCssSource
|
|
1893
|
+
}) : runtime;
|
|
1894
|
+
const generatorRuntime = majorVersion === 4 && generatorOptions.target === "weapp" ? require_v3_engine.filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
|
|
1895
|
+
return generator.generate({
|
|
1896
|
+
candidates: generatorRuntime,
|
|
1897
|
+
incrementalCache: majorVersion === 3 || majorVersion === 4,
|
|
1898
|
+
scanSources: majorVersion === 4 && generatorRuntime.size === 0 && !isolateCssSource,
|
|
1899
|
+
styleOptions: generatorStyleOptions,
|
|
1900
|
+
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
1901
|
+
target: generatorOptions.target
|
|
1902
|
+
});
|
|
1903
|
+
}));
|
|
1904
|
+
const firstGenerated = generatedResults[0];
|
|
1905
|
+
if (!firstGenerated) return;
|
|
1906
|
+
const incrementalCssResults = generatedResults.map((item) => item.incrementalCss).filter((css) => typeof css === "string");
|
|
1907
|
+
const incrementalRawCssResults = generatedResults.map((item) => item.incrementalRawCss).filter((css) => typeof css === "string");
|
|
1908
|
+
const generated = generatedResults.length === 1 ? firstGenerated : {
|
|
1909
|
+
...firstGenerated,
|
|
1910
|
+
css: generatedResults.map((item) => item.css).join("\n"),
|
|
1911
|
+
rawCss: generatedResults.map((item) => item.rawCss).join("\n"),
|
|
1912
|
+
incrementalCss: incrementalCssResults.length === generatedResults.length ? incrementalCssResults.filter(Boolean).join("\n") : void 0,
|
|
1913
|
+
incrementalRawCss: incrementalRawCssResults.length === generatedResults.length ? incrementalRawCssResults.filter(Boolean).join("\n") : void 0,
|
|
1914
|
+
classSet: new Set(generatedResults.flatMap((item) => [...item.classSet])),
|
|
1915
|
+
dependencies: [...new Set(generatedResults.flatMap((item) => item.dependencies))],
|
|
1916
|
+
sources: generatedResults.flatMap((item) => item.sources)
|
|
1917
|
+
};
|
|
1918
|
+
debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
|
|
1919
|
+
if (typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
1920
|
+
const incrementalCss = stripTailwindBanner(generated.incrementalCss);
|
|
1921
|
+
return {
|
|
1922
|
+
css: incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss,
|
|
1923
|
+
target: generated.target,
|
|
1924
|
+
source: "generator",
|
|
1925
|
+
dependencies: generated.dependencies,
|
|
1926
|
+
incremental: true
|
|
1927
|
+
};
|
|
1928
|
+
}
|
|
1929
|
+
const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
|
|
1930
|
+
const orderedExtraCss = hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(effectiveRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(effectiveRawSource, generated.rawCss);
|
|
1931
|
+
if (orderedExtraCss) {
|
|
1932
|
+
let css = stripTailwindBanner(generated.css);
|
|
1933
|
+
if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
|
|
1934
|
+
const userCssOptions = {
|
|
1935
|
+
generatorTarget: generated.target,
|
|
1936
|
+
generatorStyleOptions,
|
|
1937
|
+
cssUserHandlerOptions,
|
|
1938
|
+
styleHandler,
|
|
1939
|
+
importFallback: generatorOptions.importFallback
|
|
1940
|
+
};
|
|
1941
|
+
const beforeUserCss = await transformGeneratorUserCss(orderedExtraCss.before, userCssOptions);
|
|
1942
|
+
const afterUserCss = await transformGeneratorUserCss(orderedExtraCss.after, userCssOptions);
|
|
1943
|
+
css = createCssSourceOrderAppend(createCssSourceOrderAppend(beforeUserCss, css), afterUserCss);
|
|
1944
|
+
if (generated.target === "weapp") {
|
|
1945
|
+
css = await appendLegacyCompatCss(css, effectiveRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1946
|
+
css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1947
|
+
}
|
|
1948
|
+
return {
|
|
1949
|
+
css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight),
|
|
1950
|
+
target: generated.target,
|
|
1951
|
+
source: "generator",
|
|
1952
|
+
dependencies: generated.dependencies
|
|
1953
|
+
};
|
|
1954
|
+
}
|
|
1955
|
+
debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
|
|
1956
|
+
let css = stripTailwindBanner(generated.css);
|
|
1957
|
+
if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
|
|
1958
|
+
if (hasMatchedCssSourceFile || generated.target === "web") return {
|
|
1959
|
+
css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight),
|
|
1960
|
+
target: generated.target,
|
|
1961
|
+
source: "generator",
|
|
1962
|
+
dependencies: generated.dependencies
|
|
1963
|
+
};
|
|
1964
|
+
css = await appendLegacyCompatCss(css, effectiveRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1965
|
+
css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1966
|
+
return {
|
|
1967
|
+
css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight),
|
|
1968
|
+
target: generated.target,
|
|
1969
|
+
source: "generator",
|
|
1970
|
+
dependencies: generated.dependencies
|
|
1971
|
+
};
|
|
1972
|
+
} catch (error) {
|
|
1973
|
+
debug("tailwind direct css generation failed: %s %O", file, error);
|
|
1974
|
+
throw error;
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
async function validateCandidatesByGenerator(options) {
|
|
1978
|
+
const { candidates, cssHandlerOptions, debug, file, opts, rawSource, runtimeState } = options;
|
|
1979
|
+
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
1980
|
+
if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || candidates.size === 0) return /* @__PURE__ */ new Set();
|
|
1981
|
+
const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator), { runtime: candidates });
|
|
1982
|
+
const classSets = await Promise.all(sources.map(async (source) => {
|
|
1983
|
+
const generator = require_generator.createWeappTailwindcssGenerator(source);
|
|
1984
|
+
if (typeof generator.validateCandidates === "function") return generator.validateCandidates(candidates);
|
|
1985
|
+
return (await generator.generate({
|
|
1986
|
+
candidates,
|
|
1987
|
+
target: "tailwind"
|
|
1988
|
+
})).classSet;
|
|
1989
|
+
}));
|
|
1990
|
+
const classSet = new Set(classSets.flatMap((item) => [...item]));
|
|
1991
|
+
debug("tailwind generator validated candidates: %s candidates=%d classSet=%d", file, candidates.size, classSet.size);
|
|
1992
|
+
return classSet;
|
|
1993
|
+
}
|
|
1994
|
+
//#endregion
|
|
1995
|
+
//#region src/bundlers/shared/hmr-timing.ts
|
|
1996
|
+
function shouldEmitHmrTiming() {
|
|
1997
|
+
return node_process.default.env["WEAPP_TW_WATCH_REGRESSION"] === "1" || node_process.default.env["WEAPP_TW_HMR_TIMING"] === "1";
|
|
1998
|
+
}
|
|
1999
|
+
function shouldEmitHumanReadableTiming() {
|
|
2000
|
+
return node_process.default.env["WEAPP_TW_HMR_TIMING"] === "1" && node_process.default.env["WEAPP_TW_HMR_TIMING_LOG"] !== "0";
|
|
2001
|
+
}
|
|
2002
|
+
function emitHmrTiming(bundler, phase, durationMs, details = {}) {
|
|
2003
|
+
if (!shouldEmitHmrTiming()) return;
|
|
2004
|
+
const serializableDetails = { ...details };
|
|
2005
|
+
delete serializableDetails.emit;
|
|
2006
|
+
const payload = {
|
|
2007
|
+
bundler,
|
|
2008
|
+
phase,
|
|
2009
|
+
durationMs: Math.max(0, Math.round(durationMs)),
|
|
2010
|
+
...serializableDetails,
|
|
2011
|
+
...typeof details.wallMs === "number" ? { wallMs: Math.max(0, Math.round(details.wallMs)) } : {}
|
|
2012
|
+
};
|
|
2013
|
+
node_process.default.stdout.write(`[weapp-tailwindcss:hmr] ${JSON.stringify(payload)}\n`);
|
|
2014
|
+
if (shouldEmitHumanReadableTiming()) {
|
|
2015
|
+
const fileSuffix = details.file ? ` file=${details.file}` : "";
|
|
2016
|
+
if (details.metric === "total") {
|
|
2017
|
+
const hooks = details.hooks ? Object.entries(details.hooks).map(([hook, summary]) => `${hook}=${Math.max(0, Math.round(summary.durationMs))}ms/${summary.count}`).join(", ") : "";
|
|
2018
|
+
const hookSuffix = hooks ? ` (${hooks})` : "";
|
|
2019
|
+
const wallSuffix = typeof payload.wallMs === "number" ? ` wall=${payload.wallMs}ms` : "";
|
|
2020
|
+
node_process.default.stdout.write(`[weapp-tailwindcss] ${bundler}:weapp-tailwindcss 总耗时 ${payload.durationMs}ms${wallSuffix}${hookSuffix}\n`);
|
|
2021
|
+
return;
|
|
2022
|
+
}
|
|
2023
|
+
node_process.default.stdout.write(`[weapp-tailwindcss] ${bundler}:${phase} 耗时 ${payload.durationMs}ms${fileSuffix}\n`);
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
function createHmrTimingRecorder(bundler) {
|
|
2027
|
+
const session = {
|
|
2028
|
+
hooks: {},
|
|
2029
|
+
totalMs: 0
|
|
2030
|
+
};
|
|
2031
|
+
const record = (phase, durationMs, details = {}) => {
|
|
2032
|
+
const roundedDuration = Math.max(0, Math.round(durationMs));
|
|
2033
|
+
if (session.startedAt === void 0) session.startedAt = performance.now() - Math.max(0, durationMs);
|
|
2034
|
+
session.totalMs += Math.max(0, durationMs);
|
|
2035
|
+
const current = session.hooks[phase] ?? {
|
|
2036
|
+
count: 0,
|
|
2037
|
+
durationMs: 0,
|
|
2038
|
+
maxMs: 0
|
|
2039
|
+
};
|
|
2040
|
+
current.count += 1;
|
|
2041
|
+
current.durationMs += roundedDuration;
|
|
2042
|
+
current.maxMs = Math.max(current.maxMs, roundedDuration);
|
|
2043
|
+
session.hooks[phase] = current;
|
|
2044
|
+
if (details.emit !== false) emitHmrTiming(bundler, phase, durationMs, details);
|
|
2045
|
+
};
|
|
2046
|
+
const measure = async (phase, task, details = {}) => {
|
|
2047
|
+
const startedAt = performance.now();
|
|
2048
|
+
try {
|
|
2049
|
+
return await task();
|
|
2050
|
+
} finally {
|
|
2051
|
+
record(phase, performance.now() - startedAt, details);
|
|
2052
|
+
}
|
|
2053
|
+
};
|
|
2054
|
+
const emitTotal = (phase = "total") => {
|
|
2055
|
+
if (session.totalMs <= 0) return;
|
|
2056
|
+
const wallMs = session.startedAt === void 0 ? session.totalMs : performance.now() - session.startedAt;
|
|
2057
|
+
emitHmrTiming(bundler, phase, session.totalMs, {
|
|
2058
|
+
hooks: session.hooks,
|
|
2059
|
+
metric: "total",
|
|
2060
|
+
wallMs
|
|
2061
|
+
});
|
|
2062
|
+
session.hooks = {};
|
|
2063
|
+
delete session.startedAt;
|
|
2064
|
+
session.totalMs = 0;
|
|
2065
|
+
};
|
|
2066
|
+
return {
|
|
2067
|
+
emitTotal,
|
|
2068
|
+
measure,
|
|
2069
|
+
record
|
|
2070
|
+
};
|
|
2071
|
+
}
|
|
2072
|
+
//#endregion
|
|
2073
|
+
//#region src/bundlers/vite/incremental-runtime-class-set.ts
|
|
2074
|
+
const debug = require_v3_engine.createDebug("[vite:runtime-set] ");
|
|
2075
|
+
const EXTENSION_DOT_PREFIX_RE = /^\./;
|
|
2076
|
+
const VENDOR_CHUNK_BASENAME_RE = /^(?:vendor|vendors|chunk-vendors|common_vendor)(?:[.-]|$)/i;
|
|
2077
|
+
const COMMON_VENDOR_CHUNK_RE = /^(?:common|static|assets|chunks?)\/(?:vendor|vendors|chunk-vendors|common_vendor|runtime)(?:[.-]|$)/i;
|
|
2078
|
+
function toPosixPath(value) {
|
|
2079
|
+
return value.split("\\").join("/");
|
|
2080
|
+
}
|
|
2081
|
+
function isDependencyModuleId(id) {
|
|
2082
|
+
const normalized = toPosixPath(id);
|
|
2083
|
+
return normalized.includes("/node_modules/") || normalized.includes("/.pnpm/") || normalized.includes("/node_modules_");
|
|
2084
|
+
}
|
|
2085
|
+
function collectChunkModuleIds(entry) {
|
|
2086
|
+
if (entry.output.type !== "chunk") return [];
|
|
2087
|
+
return [...entry.output.moduleIds, ...Object.keys(entry.output.modules ?? {})].filter((id, index, ids) => ids.indexOf(id) === index);
|
|
2088
|
+
}
|
|
2089
|
+
function isKnownVendorChunkFile(file) {
|
|
2090
|
+
const normalized = toPosixPath(file).replace(/^\.\//, "");
|
|
2091
|
+
const basename = normalized.slice(normalized.lastIndexOf("/") + 1);
|
|
2092
|
+
return VENDOR_CHUNK_BASENAME_RE.test(basename) || COMMON_VENDOR_CHUNK_RE.test(normalized) || normalized.includes("/node_modules/") || normalized.includes("/node_modules_");
|
|
2093
|
+
}
|
|
2094
|
+
function isDependencyOnlyChunk(entry) {
|
|
2095
|
+
if (entry.output.type !== "chunk") return false;
|
|
2096
|
+
if (entry.output.isEntry || entry.output.isDynamicEntry || entry.output.isImplicitEntry) return false;
|
|
2097
|
+
const moduleIds = collectChunkModuleIds(entry);
|
|
2098
|
+
return moduleIds.length > 0 && moduleIds.every(isDependencyModuleId);
|
|
2099
|
+
}
|
|
2100
|
+
function isRuntimeCandidateEntry(entry) {
|
|
2101
|
+
if (entry.type === "html") return true;
|
|
2102
|
+
if (entry.type !== "js") return false;
|
|
2103
|
+
if (isDependencyOnlyChunk(entry)) return false;
|
|
2104
|
+
if (!isKnownVendorChunkFile(entry.file)) return true;
|
|
2105
|
+
if (entry.output.type !== "chunk") return false;
|
|
2106
|
+
if (entry.output.facadeModuleId && !isDependencyModuleId(entry.output.facadeModuleId)) return true;
|
|
2107
|
+
return collectChunkModuleIds(entry).some((id) => !isDependencyModuleId(id));
|
|
2108
|
+
}
|
|
2109
|
+
function createExtractOptions(context, source) {
|
|
2110
|
+
return {
|
|
2111
|
+
cwd: context.projectRoot,
|
|
2112
|
+
base: context.base,
|
|
2113
|
+
baseFallbacks: context.baseFallbacks,
|
|
2114
|
+
css: context.css,
|
|
2115
|
+
content: source,
|
|
2116
|
+
extension: "html"
|
|
2117
|
+
};
|
|
2118
|
+
}
|
|
2119
|
+
function createRuntimeEntries(snapshot) {
|
|
2120
|
+
return snapshot.entries.filter(isRuntimeCandidateEntry);
|
|
2121
|
+
}
|
|
2122
|
+
function collectChangedRuntimeFiles(snapshot) {
|
|
2123
|
+
return new Set([...snapshot.runtimeAffectingChangedByType.html, ...snapshot.runtimeAffectingChangedByType.js]);
|
|
2124
|
+
}
|
|
2125
|
+
function resolveEntryExtension(entry) {
|
|
2126
|
+
if (entry.type === "html") return "html";
|
|
2127
|
+
const ext = entry.file.split(/[?#]/, 1)[0]?.split(".").pop()?.replace(EXTENSION_DOT_PREFIX_RE, "") ?? "";
|
|
2128
|
+
if (ext.length > 0) return ext;
|
|
2129
|
+
return "js";
|
|
2130
|
+
}
|
|
2131
|
+
function createCandidateValidationSource(candidates) {
|
|
2132
|
+
return [...new Set(candidates)].sort().join("\n");
|
|
2133
|
+
}
|
|
2134
|
+
function removeCandidateSet(candidateCountByClass, candidates) {
|
|
2135
|
+
for (const className of candidates) {
|
|
2136
|
+
const count = candidateCountByClass.get(className);
|
|
2137
|
+
if (count == null) continue;
|
|
2138
|
+
if (count <= 1) {
|
|
2139
|
+
candidateCountByClass.delete(className);
|
|
2140
|
+
continue;
|
|
2141
|
+
}
|
|
2142
|
+
candidateCountByClass.set(className, count - 1);
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
function addCandidateSet(candidateCountByClass, candidates) {
|
|
2146
|
+
for (const className of candidates) {
|
|
2147
|
+
const nextCount = (candidateCountByClass.get(className) ?? 0) + 1;
|
|
2148
|
+
candidateCountByClass.set(className, nextCount);
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
function createRuntimeClassSet(baseClassSet, candidateCountByClass) {
|
|
2152
|
+
return new Set([...baseClassSet, ...candidateCountByClass.keys()]);
|
|
2153
|
+
}
|
|
2154
|
+
function createNonSourceBaseClassSet(baseClassSet, candidateCountByClass) {
|
|
2155
|
+
const nextBaseClassSet = new Set(baseClassSet);
|
|
2156
|
+
for (const candidate of candidateCountByClass.keys()) nextBaseClassSet.delete(candidate);
|
|
2157
|
+
return nextBaseClassSet;
|
|
2158
|
+
}
|
|
2159
|
+
function createBundleRuntimeClassSetManager(options = {}) {
|
|
2160
|
+
const customExtractCandidates = options.extractCandidates;
|
|
2161
|
+
const extractCandidates = customExtractCandidates ?? tailwindcss_patch.extractValidCandidates;
|
|
2162
|
+
const extractRawCandidates = options.extractRawCandidates ?? tailwindcss_patch.extractRawCandidatesWithPositions;
|
|
2163
|
+
let baseClassSet = /* @__PURE__ */ new Set();
|
|
2164
|
+
const candidateCountByClass = /* @__PURE__ */ new Map();
|
|
2165
|
+
const candidatesByFile = /* @__PURE__ */ new Map();
|
|
2166
|
+
const candidateValidityCache = /* @__PURE__ */ new Map();
|
|
2167
|
+
let runtimeSignature;
|
|
2168
|
+
let validationContext;
|
|
2169
|
+
let designSystemPromise;
|
|
2170
|
+
async function reset() {
|
|
2171
|
+
baseClassSet = /* @__PURE__ */ new Set();
|
|
2172
|
+
candidateCountByClass.clear();
|
|
2173
|
+
candidatesByFile.clear();
|
|
2174
|
+
candidateValidityCache.clear();
|
|
2175
|
+
runtimeSignature = void 0;
|
|
2176
|
+
validationContext = void 0;
|
|
2177
|
+
designSystemPromise = void 0;
|
|
2178
|
+
}
|
|
2179
|
+
async function resolveValidationContextCached(patcher) {
|
|
2180
|
+
if (!validationContext) validationContext = await require_v3_engine.resolveTailwindV4SourceFromPatcher(patcher);
|
|
2181
|
+
return validationContext;
|
|
2182
|
+
}
|
|
2183
|
+
async function loadDesignSystem(context) {
|
|
2184
|
+
if (!designSystemPromise) designSystemPromise = (0, tailwindcss_patch.loadTailwindV4DesignSystem)(context);
|
|
2185
|
+
return designSystemPromise;
|
|
2186
|
+
}
|
|
2187
|
+
function populateCandidateValidityCacheFromDesignSystem(designSystem, unknownCandidates) {
|
|
2188
|
+
const parsedCandidates = [...unknownCandidates].filter((candidate) => designSystem.parseCandidate(candidate).length > 0);
|
|
2189
|
+
const cssByCandidate = parsedCandidates.length > 0 ? designSystem.candidatesToCss(parsedCandidates) : [];
|
|
2190
|
+
const validCandidates = /* @__PURE__ */ new Set();
|
|
2191
|
+
for (let index = 0; index < parsedCandidates.length; index += 1) {
|
|
2192
|
+
const candidate = parsedCandidates[index];
|
|
2193
|
+
const css = cssByCandidate[index];
|
|
2194
|
+
if (candidate && typeof css === "string" && css.trim().length > 0) validCandidates.add(candidate);
|
|
2195
|
+
}
|
|
2196
|
+
for (const candidate of unknownCandidates) candidateValidityCache.set(candidate, validCandidates.has(candidate));
|
|
2197
|
+
}
|
|
2198
|
+
async function validateUnknownCandidates(patcher, unknownCandidates) {
|
|
2199
|
+
if (unknownCandidates.size === 0) return;
|
|
2200
|
+
if (patcher.majorVersion === 3 && !customExtractCandidates) {
|
|
2201
|
+
for (const candidate of unknownCandidates) candidateValidityCache.set(candidate, true);
|
|
2202
|
+
return;
|
|
2203
|
+
}
|
|
2204
|
+
const context = await resolveValidationContextCached(patcher);
|
|
2205
|
+
if (!customExtractCandidates) try {
|
|
2206
|
+
populateCandidateValidityCacheFromDesignSystem(await loadDesignSystem(context), unknownCandidates);
|
|
2207
|
+
return;
|
|
2208
|
+
} catch (error) {
|
|
2209
|
+
debug("incremental design-system validation failed: %O", error);
|
|
2210
|
+
designSystemPromise = void 0;
|
|
2211
|
+
throw error;
|
|
2212
|
+
}
|
|
2213
|
+
const source = createCandidateValidationSource(unknownCandidates);
|
|
2214
|
+
const validCandidates = new Set(await extractCandidates(createExtractOptions(context, source)));
|
|
2215
|
+
for (const candidate of unknownCandidates) candidateValidityCache.set(candidate, validCandidates.has(candidate));
|
|
2216
|
+
}
|
|
2217
|
+
async function extractEntryRawCandidates(entry) {
|
|
2218
|
+
const matches = await extractRawCandidates(entry.source, resolveEntryExtension(entry));
|
|
2219
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
2220
|
+
for (const match of matches) {
|
|
2221
|
+
const candidate = match?.rawCandidate;
|
|
2222
|
+
if (typeof candidate === "string" && candidate.length > 0) candidates.add(candidate);
|
|
2223
|
+
}
|
|
2224
|
+
return candidates;
|
|
2225
|
+
}
|
|
2226
|
+
async function sync(patcher, snapshot, options = {}) {
|
|
2227
|
+
const nextSignature = require_v3_engine.getRuntimeClassSetSignature(patcher) ?? "runtime:missing";
|
|
2228
|
+
const runtimeEntries = createRuntimeEntries(snapshot);
|
|
2229
|
+
const runtimeEntriesByFile = new Map(runtimeEntries.map((entry) => [entry.file, entry]));
|
|
2230
|
+
const currentRuntimeFiles = new Set(runtimeEntriesByFile.keys());
|
|
2231
|
+
const hadTrackedRuntimeFiles = candidatesByFile.size > 0;
|
|
2232
|
+
const fullRebuild = runtimeSignature !== nextSignature || candidatesByFile.size === 0;
|
|
2233
|
+
if (runtimeSignature !== nextSignature) {
|
|
2234
|
+
debug("runtime signature changed, reset incremental runtime set: %s", nextSignature);
|
|
2235
|
+
await reset();
|
|
2236
|
+
}
|
|
2237
|
+
runtimeSignature = nextSignature;
|
|
2238
|
+
const nextBaseClassSet = options.baseClassSet;
|
|
2239
|
+
const canUseBaseWithoutInitialFullScan = Boolean(fullRebuild && !hadTrackedRuntimeFiles && options.skipInitialFullScanWithBase === true && nextBaseClassSet && nextBaseClassSet.size > 0);
|
|
2240
|
+
for (const [file, previousCandidates] of candidatesByFile) {
|
|
2241
|
+
if (currentRuntimeFiles.has(file)) continue;
|
|
2242
|
+
removeCandidateSet(candidateCountByClass, previousCandidates);
|
|
2243
|
+
candidatesByFile.delete(file);
|
|
2244
|
+
}
|
|
2245
|
+
const changedRuntimeFiles = canUseBaseWithoutInitialFullScan ? [...collectChangedRuntimeFiles(snapshot)] : fullRebuild ? [...runtimeEntriesByFile.keys()] : [...collectChangedRuntimeFiles(snapshot)];
|
|
2246
|
+
if (changedRuntimeFiles.length === 0) {
|
|
2247
|
+
if (nextBaseClassSet) baseClassSet = canUseBaseWithoutInitialFullScan ? new Set(nextBaseClassSet) : createNonSourceBaseClassSet(nextBaseClassSet, candidateCountByClass);
|
|
2248
|
+
return createRuntimeClassSet(baseClassSet, candidateCountByClass);
|
|
2249
|
+
}
|
|
2250
|
+
const rawCandidatesByFile = /* @__PURE__ */ new Map();
|
|
2251
|
+
const unknownCandidates = /* @__PURE__ */ new Set();
|
|
2252
|
+
await Promise.all(changedRuntimeFiles.map(async (file) => {
|
|
2253
|
+
const entry = runtimeEntriesByFile.get(file);
|
|
2254
|
+
if (!entry) return;
|
|
2255
|
+
const candidates = await extractEntryRawCandidates(entry);
|
|
2256
|
+
rawCandidatesByFile.set(file, candidates);
|
|
2257
|
+
for (const candidate of candidates) if (!candidateValidityCache.has(candidate)) unknownCandidates.add(candidate);
|
|
2258
|
+
}));
|
|
2259
|
+
await validateUnknownCandidates(patcher, unknownCandidates);
|
|
2260
|
+
let rawCandidateCount = 0;
|
|
2261
|
+
for (const file of changedRuntimeFiles) {
|
|
2262
|
+
const nextRawCandidates = rawCandidatesByFile.get(file);
|
|
2263
|
+
const previousCandidates = candidatesByFile.get(file);
|
|
2264
|
+
if (previousCandidates) removeCandidateSet(candidateCountByClass, previousCandidates);
|
|
2265
|
+
if (!nextRawCandidates || nextRawCandidates.size === 0) {
|
|
2266
|
+
candidatesByFile.delete(file);
|
|
2267
|
+
continue;
|
|
2268
|
+
}
|
|
2269
|
+
rawCandidateCount += nextRawCandidates.size;
|
|
2270
|
+
const nextCandidates = new Set([...nextRawCandidates].filter((candidate) => candidateValidityCache.get(candidate) === true));
|
|
2271
|
+
if (nextCandidates.size === 0) {
|
|
2272
|
+
candidatesByFile.delete(file);
|
|
2273
|
+
continue;
|
|
2274
|
+
}
|
|
2275
|
+
addCandidateSet(candidateCountByClass, nextCandidates);
|
|
2276
|
+
candidatesByFile.set(file, nextCandidates);
|
|
2277
|
+
}
|
|
2278
|
+
if (nextBaseClassSet) baseClassSet = canUseBaseWithoutInitialFullScan ? new Set(nextBaseClassSet) : createNonSourceBaseClassSet(nextBaseClassSet, candidateCountByClass);
|
|
2279
|
+
const runtimeSet = createRuntimeClassSet(baseClassSet, candidateCountByClass);
|
|
2280
|
+
debug("incremental runtime set synced, changedFiles=%d rawCandidates=%d validateMisses=%d runtimeSize=%d trackedFiles=%d", changedRuntimeFiles.length, rawCandidateCount, unknownCandidates.size, runtimeSet.size, candidatesByFile.size);
|
|
2281
|
+
return new Set(runtimeSet);
|
|
2282
|
+
}
|
|
2283
|
+
return {
|
|
2284
|
+
sync,
|
|
2285
|
+
reset
|
|
2286
|
+
};
|
|
2287
|
+
}
|
|
2288
|
+
//#endregion
|
|
2289
|
+
Object.defineProperty(exports, "createBundleRuntimeClassSetManager", {
|
|
2290
|
+
enumerable: true,
|
|
2291
|
+
get: function() {
|
|
2292
|
+
return createBundleRuntimeClassSetManager;
|
|
2293
|
+
}
|
|
2294
|
+
});
|
|
2295
|
+
Object.defineProperty(exports, "createHmrTimingRecorder", {
|
|
2296
|
+
enumerable: true,
|
|
2297
|
+
get: function() {
|
|
2298
|
+
return createHmrTimingRecorder;
|
|
2299
|
+
}
|
|
2300
|
+
});
|
|
2301
|
+
Object.defineProperty(exports, "emitHmrTiming", {
|
|
2302
|
+
enumerable: true,
|
|
2303
|
+
get: function() {
|
|
2304
|
+
return emitHmrTiming;
|
|
2305
|
+
}
|
|
2306
|
+
});
|
|
2307
|
+
Object.defineProperty(exports, "generateCssByGenerator", {
|
|
2308
|
+
enumerable: true,
|
|
2309
|
+
get: function() {
|
|
2310
|
+
return generateCssByGenerator;
|
|
2311
|
+
}
|
|
2312
|
+
});
|
|
2313
|
+
Object.defineProperty(exports, "hasTailwindGeneratedCssMarkers", {
|
|
2314
|
+
enumerable: true,
|
|
2315
|
+
get: function() {
|
|
2316
|
+
return hasTailwindGeneratedCssMarkers;
|
|
2317
|
+
}
|
|
2318
|
+
});
|
|
2319
|
+
Object.defineProperty(exports, "hasTailwindRootDirectives", {
|
|
2320
|
+
enumerable: true,
|
|
2321
|
+
get: function() {
|
|
2322
|
+
return hasTailwindRootDirectives;
|
|
2323
|
+
}
|
|
2324
|
+
});
|
|
2325
|
+
Object.defineProperty(exports, "hasTailwindSourceDirectives", {
|
|
2326
|
+
enumerable: true,
|
|
2327
|
+
get: function() {
|
|
2328
|
+
return hasTailwindSourceDirectives;
|
|
2329
|
+
}
|
|
2330
|
+
});
|
|
2331
|
+
Object.defineProperty(exports, "normalizeTailwindSourceForGenerator", {
|
|
2332
|
+
enumerable: true,
|
|
2333
|
+
get: function() {
|
|
2334
|
+
return normalizeTailwindSourceForGenerator;
|
|
2335
|
+
}
|
|
2336
|
+
});
|
|
2337
|
+
Object.defineProperty(exports, "processCachedTask", {
|
|
2338
|
+
enumerable: true,
|
|
2339
|
+
get: function() {
|
|
2340
|
+
return processCachedTask;
|
|
2341
|
+
}
|
|
2342
|
+
});
|
|
2343
|
+
Object.defineProperty(exports, "validateCandidatesByGenerator", {
|
|
2344
|
+
enumerable: true,
|
|
2345
|
+
get: function() {
|
|
2346
|
+
return validateCandidatesByGenerator;
|
|
2347
|
+
}
|
|
2348
|
+
});
|