weapp-tailwindcss 5.0.0-next.5 → 5.0.0-next.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +4 -0
- package/dist/bundlers/shared/css-cleanup/selectors.d.ts +8 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +1 -2
- package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +12 -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 +16 -0
- package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +10 -0
- package/dist/bundlers/shared/generator-css.d.ts +10 -23
- package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +20 -0
- package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +3 -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 +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/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/vite/runtime-class-set.d.ts +22 -0
- package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -1
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +2 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +2 -0
- package/dist/cache-BVAiJV3J.js +502 -0
- package/dist/cache-CHs4DXui.mjs +434 -0
- package/dist/cli/helpers.d.ts +1 -2
- package/dist/cli/mount-options.d.ts +2 -2
- package/dist/cli/types.d.ts +0 -2
- package/dist/cli.js +107 -603
- package/dist/cli.mjs +118 -613
- package/dist/constants.d.ts +0 -1
- package/dist/context/tailwindcss.d.ts +1 -1
- package/dist/core.js +13 -20
- package/dist/core.mjs +8 -14
- package/dist/css-macro/postcss.js +1 -1
- package/dist/css-macro/postcss.mjs +1 -1
- package/dist/css-macro.js +2 -2
- package/dist/css-macro.mjs +2 -2
- package/dist/defaults.d.ts +15 -1
- package/dist/defaults.js +28 -7
- package/dist/defaults.mjs +25 -8
- package/dist/{generator-9UEp8OoQ.js → generator-DKkhJbOg.js} +24 -7
- package/dist/{generator-Dpp-5s8z.mjs → generator-UBmfduYg.mjs} +20 -3
- package/dist/{generator-css-MyjZhF0z.mjs → generator-css-BIapP56i.mjs} +691 -606
- package/dist/{generator-css-CGueCYbX.js → generator-css-Mksw8PgB.js} +703 -606
- package/dist/generator.js +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/gulp.js +33 -21
- package/dist/gulp.mjs +29 -17
- package/dist/index.js +5 -5
- package/dist/index.mjs +4 -4
- package/dist/logger-BRy6XPQ2.js +1 -0
- package/dist/logger-Bub1jggA.mjs +2 -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-QIXwT40c.js +298 -0
- package/dist/postcss-w48mGIhe.mjs +288 -0
- package/dist/postcss.js +3 -285
- package/dist/postcss.mjs +1 -278
- package/dist/{recorder-D4BKt75Q.js → precheck-B32p-gLI.js} +139 -274
- package/dist/{recorder-BIW3Kuke.mjs → precheck-B4RH6ZNN.mjs} +105 -239
- package/dist/presets.js +6 -4
- package/dist/presets.mjs +4 -2
- package/dist/runtime-patch-CwN5ya72.mjs +71 -0
- package/dist/runtime-patch-D6mBo_KB.js +85 -0
- package/dist/tailwindcss/runtime-patch.d.ts +5 -0
- package/dist/tailwindcss/runtime.d.ts +2 -3
- package/dist/tailwindcss/targets.d.ts +1 -5
- package/dist/tailwindcss/v4/css-sources.d.ts +5 -0
- package/dist/tailwindcss/v4/patcher.d.ts +1 -1
- package/dist/{logger-D9clu_3f.js → tailwindcss-Bu-RWIHx.js} +70 -413
- package/dist/{logger-1gx9UllH.mjs → tailwindcss-C5IgPlQ0.mjs} +56 -382
- package/dist/types/index.d.ts +1 -6
- package/dist/uni-app-x/vite.d.ts +1 -1
- package/dist/{vite-fDM-UQpR.mjs → vite-BwgRVgxH.mjs} +677 -525
- package/dist/{vite-BkMGwDeH.js → vite-DyZuiyap.js} +704 -552
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +10 -1
- package/dist/{webpack-CICGEKT9.js → webpack-CNV2dx3Q.js} +72 -37
- package/dist/{webpack-D2Wdk28V.mjs → webpack-CT6EEENx.mjs} +58 -23
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +6 -9
- package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
- 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/js/syntax.d.ts +0 -10
- package/dist/patcher-options-DnqazL9E.js +0 -34
- package/dist/patcher-options-GuOwX0-k.mjs +0 -17
- 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/version-CWBxRFPB.js +0 -56
- package/dist/version-WNz3MwRv.mjs +0 -49
- /package/dist/{constants-p1dyh1x1.js → constants-BoB_6lFw.js} +0 -0
- /package/dist/{constants-B-_T5UnW.mjs → constants-E_loJC49.mjs} +0 -0
- /package/dist/{run-tasks-Cq5A5nVD.js → run-tasks-B50A3pxt.js} +0 -0
- /package/dist/{run-tasks-DUVrDJGl.mjs → run-tasks-DdNi-hkk.mjs} +0 -0
- /package/dist/{utils-DmC9_In3.js → utils-BiShvil9.js} +0 -0
- /package/dist/{utils-7DUGTFED.mjs → utils-Btw1iOVV.mjs} +0 -0
|
@@ -1,9 +1,182 @@
|
|
|
1
|
-
import { a as resolveTailwindV4Source, c as resolveTailwindV4SourceOptionsFromPatcher, h as resolveTailwindV3SourceOptionsFromPatcher, i as normalizeWeappTailwindcssGeneratorOptions, m as resolveTailwindV3SourceFromPatcher, p as resolveTailwindV3Source, s as resolveTailwindV4SourceFromPatcher, t as createWeappTailwindcssGenerator, v as removeUnsupportedCascadeLayers } from "./generator-
|
|
2
|
-
import { l as replaceWxml } from "./
|
|
1
|
+
import { a as resolveTailwindV4Source, c as resolveTailwindV4SourceOptionsFromPatcher, h as resolveTailwindV3SourceOptionsFromPatcher, i as normalizeWeappTailwindcssGeneratorOptions, m as resolveTailwindV3SourceFromPatcher, p as resolveTailwindV3Source, s as resolveTailwindV4SourceFromPatcher, t as createWeappTailwindcssGenerator, v as removeUnsupportedCascadeLayers } from "./generator-UBmfduYg.mjs";
|
|
2
|
+
import { l as replaceWxml } from "./precheck-B4RH6ZNN.mjs";
|
|
3
3
|
import postcss from "postcss";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
//#region src/bundlers/shared/generator-css/markers.ts
|
|
8
|
+
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
9
|
+
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)-/;
|
|
10
|
+
const GENERATOR_PLACEHOLDER_MARKER_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\//i;
|
|
11
|
+
const GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/\s*/gi;
|
|
12
|
+
const TAILWIND_BANNER_PREFIX_RE = /^\/\*!\s*tailwindcss v[^*]*\*\/\s*/i;
|
|
13
|
+
const TAILWIND_BANNER_GLOBAL_RE = /\/\*!\s*tailwindcss v[^*]*\*\/\s*/gi;
|
|
14
|
+
const VITE_MARKER_RE = /\/\*\$vite\$:[^*]*\*\//g;
|
|
15
|
+
function createCssAppend(base, extra) {
|
|
16
|
+
if (!base) return extra;
|
|
17
|
+
if (!extra) return base;
|
|
18
|
+
return `${base}\n${extra}`;
|
|
19
|
+
}
|
|
20
|
+
function splitTailwindV4GeneratedCss(rawSource, rawTailwindCss) {
|
|
21
|
+
const trimmedRaw = rawSource.trim();
|
|
22
|
+
const trimmedTailwind = rawTailwindCss.trim();
|
|
23
|
+
if (trimmedRaw === trimmedTailwind) return "";
|
|
24
|
+
if (trimmedTailwind.startsWith(trimmedRaw)) return "";
|
|
25
|
+
const start = rawSource.indexOf(rawTailwindCss);
|
|
26
|
+
if (start === -1) return;
|
|
27
|
+
return createCssAppend(rawSource.slice(0, start), rawSource.slice(start + rawTailwindCss.length));
|
|
28
|
+
}
|
|
29
|
+
function stripTailwindBanner(css) {
|
|
30
|
+
return css.replace(TAILWIND_BANNER_PREFIX_RE, "");
|
|
31
|
+
}
|
|
32
|
+
function stripTailwindBanners(css) {
|
|
33
|
+
return css.replace(TAILWIND_BANNER_GLOBAL_RE, "");
|
|
34
|
+
}
|
|
35
|
+
function stripGeneratorPlaceholderMarkers(css) {
|
|
36
|
+
return css.replace(GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE, "");
|
|
37
|
+
}
|
|
38
|
+
function hasTailwindGeneratedCss(rawSource) {
|
|
39
|
+
return TAILWIND_V4_BANNER_RE.test(rawSource);
|
|
40
|
+
}
|
|
41
|
+
function hasTailwindGeneratedCssMarkers(rawSource) {
|
|
42
|
+
return TAILWIND_GENERATED_CSS_MARKER_RE.test(rawSource) || GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/bundlers/shared/generator-css/directives.ts
|
|
46
|
+
const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = new Set([
|
|
47
|
+
"config",
|
|
48
|
+
"custom-variant",
|
|
49
|
+
"layer",
|
|
50
|
+
"plugin",
|
|
51
|
+
"reference",
|
|
52
|
+
"source",
|
|
53
|
+
"tailwind",
|
|
54
|
+
"theme",
|
|
55
|
+
"utility",
|
|
56
|
+
"variant"
|
|
57
|
+
]);
|
|
58
|
+
const TAILWIND_ROOT_DIRECTIVE_NAMES = new Set([
|
|
59
|
+
"config",
|
|
60
|
+
"custom-variant",
|
|
61
|
+
"plugin",
|
|
62
|
+
"source",
|
|
63
|
+
"tailwind",
|
|
64
|
+
"theme",
|
|
65
|
+
"utility",
|
|
66
|
+
"variant"
|
|
67
|
+
]);
|
|
68
|
+
const TAILWIND_ROOT_DIRECTIVE_RE = /@(?:import\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|tailwind|config|custom-variant|plugin|source|theme|utility|variant)\b/;
|
|
69
|
+
function parseImportRequest(params) {
|
|
70
|
+
return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
|
|
71
|
+
}
|
|
72
|
+
function parseConfigRequest(params) {
|
|
73
|
+
return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
|
|
74
|
+
}
|
|
75
|
+
function isPackageJsonImportRequest(request) {
|
|
76
|
+
return typeof request === "string" && request.startsWith("#");
|
|
77
|
+
}
|
|
78
|
+
function isTailwindImportAtRule(node) {
|
|
79
|
+
if (node.name === "tailwind") return true;
|
|
80
|
+
if (node.name !== "import") return false;
|
|
81
|
+
const request = parseImportRequest(node.params);
|
|
82
|
+
return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/");
|
|
83
|
+
}
|
|
84
|
+
function isTailwindSourceDirective(node) {
|
|
85
|
+
if (node.type !== "atrule") return false;
|
|
86
|
+
const atRule = node;
|
|
87
|
+
if (isTailwindImportAtRule(atRule)) return true;
|
|
88
|
+
if (atRule.name === "import" && isPackageJsonImportRequest(parseImportRequest(atRule.params))) return true;
|
|
89
|
+
return TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES.has(atRule.name);
|
|
90
|
+
}
|
|
91
|
+
function isTailwindGenerationDirective(node) {
|
|
92
|
+
if (node.type !== "atrule") return false;
|
|
93
|
+
const atRule = node;
|
|
94
|
+
const request = atRule.name === "import" ? parseImportRequest(atRule.params) : atRule.name === "config" || atRule.name === "plugin" || atRule.name === "reference" ? parseConfigRequest(atRule.params) : void 0;
|
|
95
|
+
return isTailwindImportAtRule(atRule) || isPackageJsonImportRequest(request) || atRule.name === "apply" || atRule.name === "layer" || atRule.name === "config" || atRule.name === "source";
|
|
96
|
+
}
|
|
97
|
+
function removeTailwindSourceDirectives(rawSource) {
|
|
98
|
+
try {
|
|
99
|
+
const source = stripGeneratorPlaceholderMarkers(rawSource);
|
|
100
|
+
const root = postcss.parse(source);
|
|
101
|
+
let removed = false;
|
|
102
|
+
root.walk((node) => {
|
|
103
|
+
if (isTailwindSourceDirective(node)) {
|
|
104
|
+
node.remove();
|
|
105
|
+
removed = true;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return removed ? root.toString() : source;
|
|
109
|
+
} catch {
|
|
110
|
+
return stripGeneratorPlaceholderMarkers(rawSource);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function hasTailwindSourceDirectives(rawSource) {
|
|
114
|
+
try {
|
|
115
|
+
if (GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource)) return true;
|
|
116
|
+
const root = postcss.parse(rawSource);
|
|
117
|
+
let found = false;
|
|
118
|
+
root.walk((node) => {
|
|
119
|
+
if (isTailwindGenerationDirective(node)) {
|
|
120
|
+
found = true;
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
return found;
|
|
125
|
+
} catch {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function hasTailwindRootDirectives(rawSource) {
|
|
130
|
+
if (!TAILWIND_ROOT_DIRECTIVE_RE.test(rawSource)) return false;
|
|
131
|
+
try {
|
|
132
|
+
const root = postcss.parse(rawSource);
|
|
133
|
+
let found = false;
|
|
134
|
+
root.walkAtRules((node) => {
|
|
135
|
+
const request = node.name === "import" ? parseImportRequest(node.params) : node.name === "config" || node.name === "plugin" ? parseConfigRequest(node.params) : void 0;
|
|
136
|
+
if (isTailwindImportAtRule(node) || isPackageJsonImportRequest(request) || TAILWIND_ROOT_DIRECTIVE_NAMES.has(node.name)) {
|
|
137
|
+
found = true;
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
return found;
|
|
142
|
+
} catch {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function resolveCssEntrySource(rawSource, base, options = {}) {
|
|
147
|
+
try {
|
|
148
|
+
const root = postcss.parse(rawSource);
|
|
149
|
+
let found = false;
|
|
150
|
+
let config;
|
|
151
|
+
let configRequest;
|
|
152
|
+
let removedConfig = false;
|
|
153
|
+
const removeConfig = options.removeConfig ?? true;
|
|
154
|
+
root.walk((node) => {
|
|
155
|
+
if (isTailwindGenerationDirective(node)) found = true;
|
|
156
|
+
if (node.type === "atrule" && node.name === "config") {
|
|
157
|
+
const configPath = parseConfigRequest(node.params);
|
|
158
|
+
if (configPath && !config) {
|
|
159
|
+
configRequest = configPath;
|
|
160
|
+
config = isPackageJsonImportRequest(configPath) ? void 0 : path.isAbsolute(configPath) ? configPath : path.resolve(base, configPath);
|
|
161
|
+
}
|
|
162
|
+
if (removeConfig) {
|
|
163
|
+
node.remove();
|
|
164
|
+
removedConfig = true;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
if (!found) return;
|
|
169
|
+
return {
|
|
170
|
+
css: removedConfig ? root.toString() : rawSource,
|
|
171
|
+
config,
|
|
172
|
+
configRequest,
|
|
173
|
+
base
|
|
174
|
+
};
|
|
175
|
+
} catch {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
7
180
|
//#region src/bundlers/shared/cache.ts
|
|
8
181
|
async function processCachedTask({ cache, cacheKey, hashKey = cacheKey, rawSource, hash, readCache, applyResult, transform, onCacheHit }) {
|
|
9
182
|
let cacheHit = false;
|
|
@@ -23,7 +196,69 @@ async function processCachedTask({ cache, cacheKey, hashKey = cacheKey, rawSourc
|
|
|
23
196
|
if (!cacheHit) await applyResult(result);
|
|
24
197
|
}
|
|
25
198
|
//#endregion
|
|
26
|
-
//#region src/bundlers/shared/css-cleanup.ts
|
|
199
|
+
//#region src/bundlers/shared/css-cleanup/at-rules.ts
|
|
200
|
+
const MINI_PROGRAM_UNSUPPORTED_AT_RULES = new Set(["property", "supports"]);
|
|
201
|
+
function removeAtRulesByScan(css, names) {
|
|
202
|
+
let index = 0;
|
|
203
|
+
let result = "";
|
|
204
|
+
const atRulePattern = new RegExp(`@(?:${[...names].join("|")})\\b`, "i");
|
|
205
|
+
while (index < css.length) {
|
|
206
|
+
const match = atRulePattern.exec(css.slice(index));
|
|
207
|
+
if (!match || match.index === void 0) {
|
|
208
|
+
result += css.slice(index);
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
const start = index + match.index;
|
|
212
|
+
result += css.slice(index, start);
|
|
213
|
+
const blockStart = css.indexOf("{", start);
|
|
214
|
+
if (blockStart === -1) {
|
|
215
|
+
result += css.slice(start);
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
let depth = 0;
|
|
219
|
+
let cursor = blockStart;
|
|
220
|
+
for (; cursor < css.length; cursor++) {
|
|
221
|
+
const char = css[cursor];
|
|
222
|
+
if (char === "{") depth++;
|
|
223
|
+
else if (char === "}") {
|
|
224
|
+
depth--;
|
|
225
|
+
if (depth === 0) {
|
|
226
|
+
cursor++;
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
index = cursor;
|
|
232
|
+
}
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
function removeUnsupportedMiniProgramAtRules(css) {
|
|
236
|
+
try {
|
|
237
|
+
const root = postcss.parse(css);
|
|
238
|
+
root.walkAtRules((atRule) => {
|
|
239
|
+
if (MINI_PROGRAM_UNSUPPORTED_AT_RULES.has(atRule.name)) atRule.remove();
|
|
240
|
+
});
|
|
241
|
+
root.walkAtRules((atRule) => {
|
|
242
|
+
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
243
|
+
});
|
|
244
|
+
return root.toString();
|
|
245
|
+
} catch {
|
|
246
|
+
return removeAtRulesByScan(css, MINI_PROGRAM_UNSUPPORTED_AT_RULES);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/bundlers/shared/css-cleanup/color-gamut.ts
|
|
251
|
+
const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
|
|
252
|
+
const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
|
|
253
|
+
function isDisplayP3MediaRule(atRule) {
|
|
254
|
+
return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
|
|
255
|
+
}
|
|
256
|
+
function isDisplayP3Declaration(decl) {
|
|
257
|
+
return DISPLAY_P3_VALUE_RE.test(decl.value);
|
|
258
|
+
}
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/bundlers/shared/css-cleanup/selectors.ts
|
|
261
|
+
const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
|
|
27
262
|
const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
|
|
28
263
|
"*",
|
|
29
264
|
"view",
|
|
@@ -33,7 +268,6 @@ const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
|
|
|
33
268
|
"::before",
|
|
34
269
|
"::after"
|
|
35
270
|
]);
|
|
36
|
-
const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
|
|
37
271
|
const MINI_PROGRAM_THEME_SCOPE_SELECTORS$1 = new Set([
|
|
38
272
|
":host",
|
|
39
273
|
":root",
|
|
@@ -109,126 +343,18 @@ const MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS = new Set([
|
|
|
109
343
|
"ul",
|
|
110
344
|
"video"
|
|
111
345
|
]);
|
|
112
|
-
const PREFLIGHT_RESET_PROPS = new Set([
|
|
113
|
-
"box-sizing",
|
|
114
|
-
"border",
|
|
115
|
-
"border-width",
|
|
116
|
-
"border-style",
|
|
117
|
-
"border-color",
|
|
118
|
-
"margin",
|
|
119
|
-
"padding"
|
|
120
|
-
]);
|
|
121
|
-
const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
|
|
122
|
-
const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
|
|
123
|
-
function removeAtRulesByScan(css, names) {
|
|
124
|
-
let index = 0;
|
|
125
|
-
let result = "";
|
|
126
|
-
const atRulePattern = new RegExp(`@(?:${[...names].join("|")})\\b`, "i");
|
|
127
|
-
while (index < css.length) {
|
|
128
|
-
const match = atRulePattern.exec(css.slice(index));
|
|
129
|
-
if (!match || match.index === void 0) {
|
|
130
|
-
result += css.slice(index);
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
const start = index + match.index;
|
|
134
|
-
result += css.slice(index, start);
|
|
135
|
-
const blockStart = css.indexOf("{", start);
|
|
136
|
-
if (blockStart === -1) {
|
|
137
|
-
result += css.slice(start);
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
let depth = 0;
|
|
141
|
-
let cursor = blockStart;
|
|
142
|
-
for (; cursor < css.length; cursor++) {
|
|
143
|
-
const char = css[cursor];
|
|
144
|
-
if (char === "{") depth++;
|
|
145
|
-
else if (char === "}") {
|
|
146
|
-
depth--;
|
|
147
|
-
if (depth === 0) {
|
|
148
|
-
cursor++;
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
index = cursor;
|
|
154
|
-
}
|
|
155
|
-
return result;
|
|
156
|
-
}
|
|
157
|
-
const MINI_PROGRAM_UNSUPPORTED_AT_RULES = new Set(["property", "supports"]);
|
|
158
|
-
function removeUnsupportedMiniProgramAtRules(css) {
|
|
159
|
-
try {
|
|
160
|
-
const root = postcss.parse(css);
|
|
161
|
-
root.walkAtRules((atRule) => {
|
|
162
|
-
if (MINI_PROGRAM_UNSUPPORTED_AT_RULES.has(atRule.name)) atRule.remove();
|
|
163
|
-
});
|
|
164
|
-
root.walkAtRules((atRule) => {
|
|
165
|
-
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
166
|
-
});
|
|
167
|
-
return root.toString();
|
|
168
|
-
} catch {
|
|
169
|
-
return removeAtRulesByScan(css, MINI_PROGRAM_UNSUPPORTED_AT_RULES);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
346
|
function normalizeSelector(selector) {
|
|
173
347
|
return selector.trim().replace(/\s+/g, "");
|
|
174
348
|
}
|
|
175
349
|
function getRuleSelectors(rule) {
|
|
176
350
|
return rule.selector.split(",").map(normalizeSelector).filter(Boolean);
|
|
177
351
|
}
|
|
178
|
-
function
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
function isMiniProgramPreflightSelector(selectors) {
|
|
182
|
-
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");
|
|
183
|
-
}
|
|
184
|
-
function hasTailwindPreflightDeclaration(rule) {
|
|
185
|
-
let hasTailwindVar = false;
|
|
186
|
-
let hasResetProp = false;
|
|
187
|
-
rule.walkDecls((decl) => {
|
|
188
|
-
if (decl.prop.startsWith("--tw-")) hasTailwindVar = true;
|
|
189
|
-
if (PREFLIGHT_RESET_PROPS.has(decl.prop)) hasResetProp = true;
|
|
190
|
-
});
|
|
191
|
-
return hasTailwindVar || hasResetProp;
|
|
192
|
-
}
|
|
193
|
-
function isCustomPropertyOnlyRule$1(rule) {
|
|
194
|
-
let hasDeclaration = false;
|
|
195
|
-
let allCustomProperties = true;
|
|
196
|
-
rule.each((node) => {
|
|
197
|
-
if (node.type !== "decl") return;
|
|
198
|
-
hasDeclaration = true;
|
|
199
|
-
if (!node.prop.startsWith("--")) allCustomProperties = false;
|
|
200
|
-
});
|
|
201
|
-
return hasDeclaration && allCustomProperties;
|
|
202
|
-
}
|
|
203
|
-
function hasContentInitDeclaration(rule) {
|
|
204
|
-
let hasContentInit = false;
|
|
205
|
-
rule.walkDecls("--tw-content", () => {
|
|
206
|
-
hasContentInit = true;
|
|
207
|
-
});
|
|
208
|
-
return hasContentInit;
|
|
209
|
-
}
|
|
210
|
-
function isTailwindPreflightRule(node) {
|
|
211
|
-
if (node.type !== "rule" || node.parent?.type !== "root") return false;
|
|
212
|
-
return isMiniProgramPreflightSelector(getRuleSelectors(node)) && hasTailwindPreflightDeclaration(node);
|
|
213
|
-
}
|
|
214
|
-
function isMiniProgramThemeVariableRule(node) {
|
|
215
|
-
if (node.type !== "rule" || node.parent?.type !== "root") return false;
|
|
216
|
-
return isMiniProgramThemeScopeSelector$1(getRuleSelectors(node)) && isCustomPropertyOnlyRule$1(node);
|
|
217
|
-
}
|
|
218
|
-
function createPseudoContentInitRule() {
|
|
219
|
-
const rule = postcss.rule({ selector: "::before,\n::after" });
|
|
220
|
-
rule.append({
|
|
221
|
-
prop: "--tw-content",
|
|
222
|
-
value: "''"
|
|
223
|
-
});
|
|
224
|
-
return rule;
|
|
225
|
-
}
|
|
226
|
-
function isDisplayP3MediaRule(atRule) {
|
|
227
|
-
return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
|
|
228
|
-
}
|
|
229
|
-
function isDisplayP3Declaration(decl) {
|
|
230
|
-
return DISPLAY_P3_VALUE_RE.test(decl.value);
|
|
352
|
+
function isUnsupportedBrowserSelector(selector) {
|
|
353
|
+
const normalized = normalizeSelector(selector);
|
|
354
|
+
return MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS.has(normalized) || MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS.has(normalized);
|
|
231
355
|
}
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/bundlers/shared/css-cleanup/root-cleanups.ts
|
|
232
358
|
function removeSpecificityPlaceholders(root) {
|
|
233
359
|
root.walkRules((rule) => {
|
|
234
360
|
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
@@ -242,9 +368,12 @@ function removeSpecificityPlaceholders(root) {
|
|
|
242
368
|
if (changed) rule.selectors = selectors;
|
|
243
369
|
});
|
|
244
370
|
}
|
|
245
|
-
function
|
|
246
|
-
|
|
247
|
-
|
|
371
|
+
function removeEmptyAtRuleAncestors(parent) {
|
|
372
|
+
while (parent?.type === "atrule" && (!parent.nodes || parent.nodes.length === 0)) {
|
|
373
|
+
const nextParent = parent.parent;
|
|
374
|
+
parent.remove();
|
|
375
|
+
parent = nextParent;
|
|
376
|
+
}
|
|
248
377
|
}
|
|
249
378
|
function removeUnsupportedBrowserSelectors(root) {
|
|
250
379
|
root.walkRules((rule) => {
|
|
@@ -260,13 +389,6 @@ function removeUnsupportedBrowserSelectors(root) {
|
|
|
260
389
|
rule.selectors = selectors;
|
|
261
390
|
});
|
|
262
391
|
}
|
|
263
|
-
function removeEmptyAtRuleAncestors(parent) {
|
|
264
|
-
while (parent?.type === "atrule" && (!parent.nodes || parent.nodes.length === 0)) {
|
|
265
|
-
const nextParent = parent.parent;
|
|
266
|
-
parent.remove();
|
|
267
|
-
parent = nextParent;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
392
|
function removeDeclarationAndEmptyRule(decl) {
|
|
271
393
|
const parent = decl.parent;
|
|
272
394
|
decl.remove();
|
|
@@ -288,6 +410,65 @@ function removeDisplayP3Declarations(root) {
|
|
|
288
410
|
if (isDisplayP3Declaration(decl)) removeDeclarationAndEmptyRule(decl);
|
|
289
411
|
});
|
|
290
412
|
}
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region src/bundlers/shared/css-cleanup.ts
|
|
415
|
+
const PREFLIGHT_RESET_PROPS = new Set([
|
|
416
|
+
"box-sizing",
|
|
417
|
+
"border",
|
|
418
|
+
"border-width",
|
|
419
|
+
"border-style",
|
|
420
|
+
"border-color",
|
|
421
|
+
"margin",
|
|
422
|
+
"padding"
|
|
423
|
+
]);
|
|
424
|
+
function isMiniProgramThemeScopeSelector$1(selectors) {
|
|
425
|
+
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_THEME_SCOPE_SELECTORS$1.has(selector));
|
|
426
|
+
}
|
|
427
|
+
function isMiniProgramPreflightSelector(selectors) {
|
|
428
|
+
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");
|
|
429
|
+
}
|
|
430
|
+
function hasTailwindPreflightDeclaration(rule) {
|
|
431
|
+
let hasTailwindVar = false;
|
|
432
|
+
let hasResetProp = false;
|
|
433
|
+
rule.walkDecls((decl) => {
|
|
434
|
+
if (decl.prop.startsWith("--tw-")) hasTailwindVar = true;
|
|
435
|
+
if (PREFLIGHT_RESET_PROPS.has(decl.prop)) hasResetProp = true;
|
|
436
|
+
});
|
|
437
|
+
return hasTailwindVar || hasResetProp;
|
|
438
|
+
}
|
|
439
|
+
function isCustomPropertyOnlyRule$1(rule) {
|
|
440
|
+
let hasDeclaration = false;
|
|
441
|
+
let allCustomProperties = true;
|
|
442
|
+
rule.each((node) => {
|
|
443
|
+
if (node.type !== "decl") return;
|
|
444
|
+
hasDeclaration = true;
|
|
445
|
+
if (!node.prop.startsWith("--")) allCustomProperties = false;
|
|
446
|
+
});
|
|
447
|
+
return hasDeclaration && allCustomProperties;
|
|
448
|
+
}
|
|
449
|
+
function hasContentInitDeclaration(rule) {
|
|
450
|
+
let hasContentInit = false;
|
|
451
|
+
rule.walkDecls("--tw-content", () => {
|
|
452
|
+
hasContentInit = true;
|
|
453
|
+
});
|
|
454
|
+
return hasContentInit;
|
|
455
|
+
}
|
|
456
|
+
function isTailwindPreflightRule(node) {
|
|
457
|
+
if (node.type !== "rule" || node.parent?.type !== "root") return false;
|
|
458
|
+
return isMiniProgramPreflightSelector(getRuleSelectors(node)) && hasTailwindPreflightDeclaration(node);
|
|
459
|
+
}
|
|
460
|
+
function isMiniProgramThemeVariableRule(node) {
|
|
461
|
+
if (node.type !== "rule" || node.parent?.type !== "root") return false;
|
|
462
|
+
return isMiniProgramThemeScopeSelector$1(getRuleSelectors(node)) && isCustomPropertyOnlyRule$1(node);
|
|
463
|
+
}
|
|
464
|
+
function createPseudoContentInitRule() {
|
|
465
|
+
const rule = postcss.rule({ selector: "::before,\n::after" });
|
|
466
|
+
rule.append({
|
|
467
|
+
prop: "--tw-content",
|
|
468
|
+
value: "''"
|
|
469
|
+
});
|
|
470
|
+
return rule;
|
|
471
|
+
}
|
|
291
472
|
function collectPreflightRules(root) {
|
|
292
473
|
const preflightNodes = [];
|
|
293
474
|
let hasContentInit = false;
|
|
@@ -361,14 +542,7 @@ function finalizeMiniProgramCss(css) {
|
|
|
361
542
|
}
|
|
362
543
|
}
|
|
363
544
|
//#endregion
|
|
364
|
-
//#region src/bundlers/shared/generator-css.ts
|
|
365
|
-
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
366
|
-
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)-/;
|
|
367
|
-
const GENERATOR_PLACEHOLDER_MARKER_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\//i;
|
|
368
|
-
const GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/\s*/gi;
|
|
369
|
-
const TAILWIND_BANNER_PREFIX_RE = /^\/\*!\s*tailwindcss v[^*]*\*\/\s*/i;
|
|
370
|
-
const TAILWIND_BANNER_GLOBAL_RE = /\/\*!\s*tailwindcss v[^*]*\*\/\s*/gi;
|
|
371
|
-
const VITE_MARKER_RE = /\/\*\$vite\$:[^*]*\*\//g;
|
|
545
|
+
//#region src/bundlers/shared/generator-css/legacy-selectors.ts
|
|
372
546
|
const CLASS_SELECTOR_RE = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
373
547
|
const MINI_PROGRAM_THEME_SCOPE_SELECTORS = new Set([
|
|
374
548
|
":host",
|
|
@@ -376,103 +550,7 @@ const MINI_PROGRAM_THEME_SCOPE_SELECTORS = new Set([
|
|
|
376
550
|
".tw-root",
|
|
377
551
|
"wx-root-portal-content"
|
|
378
552
|
]);
|
|
379
|
-
const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
|
|
380
|
-
const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
|
|
381
553
|
const SPECIFICITY_PLACEHOLDER_RE = /:not\(#(?:\\#|n)\)/g;
|
|
382
|
-
const CSS_LENGTH_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)(?:px|rem)\b/i;
|
|
383
|
-
const RPX_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)rpx\b/i;
|
|
384
|
-
const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = new Set([
|
|
385
|
-
"config",
|
|
386
|
-
"custom-variant",
|
|
387
|
-
"layer",
|
|
388
|
-
"plugin",
|
|
389
|
-
"reference",
|
|
390
|
-
"source",
|
|
391
|
-
"tailwind",
|
|
392
|
-
"theme",
|
|
393
|
-
"utility",
|
|
394
|
-
"variant"
|
|
395
|
-
]);
|
|
396
|
-
const LEGACY_CONTAINER_COMPAT_CSS = [
|
|
397
|
-
".container {",
|
|
398
|
-
" width: 100%;",
|
|
399
|
-
"}",
|
|
400
|
-
"@media (min-width: 40rem) {",
|
|
401
|
-
" .container {",
|
|
402
|
-
" max-width: 40rem;",
|
|
403
|
-
" }",
|
|
404
|
-
"}",
|
|
405
|
-
"@media (min-width: 48rem) {",
|
|
406
|
-
" .container {",
|
|
407
|
-
" max-width: 48rem;",
|
|
408
|
-
" }",
|
|
409
|
-
"}",
|
|
410
|
-
"@media (min-width: 64rem) {",
|
|
411
|
-
" .container {",
|
|
412
|
-
" max-width: 64rem;",
|
|
413
|
-
" }",
|
|
414
|
-
"}",
|
|
415
|
-
"@media (min-width: 80rem) {",
|
|
416
|
-
" .container {",
|
|
417
|
-
" max-width: 80rem;",
|
|
418
|
-
" }",
|
|
419
|
-
"}",
|
|
420
|
-
"@media (min-width: 96rem) {",
|
|
421
|
-
" .container {",
|
|
422
|
-
" max-width: 96rem;",
|
|
423
|
-
" }",
|
|
424
|
-
"}"
|
|
425
|
-
].join("\n");
|
|
426
|
-
const SOURCE_STYLE_EXTENSIONS = [
|
|
427
|
-
".vue",
|
|
428
|
-
".uvue",
|
|
429
|
-
".nvue",
|
|
430
|
-
".css",
|
|
431
|
-
".scss",
|
|
432
|
-
".sass",
|
|
433
|
-
".less",
|
|
434
|
-
".styl",
|
|
435
|
-
".stylus",
|
|
436
|
-
".wxss",
|
|
437
|
-
".acss",
|
|
438
|
-
".jxss",
|
|
439
|
-
".ttss",
|
|
440
|
-
".qss"
|
|
441
|
-
];
|
|
442
|
-
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
443
|
-
function createCssAppend(base, extra) {
|
|
444
|
-
if (!base) return extra;
|
|
445
|
-
if (!extra) return base;
|
|
446
|
-
return `${base}\n${extra}`;
|
|
447
|
-
}
|
|
448
|
-
function splitTailwindV4GeneratedCss(rawSource, rawTailwindCss) {
|
|
449
|
-
const trimmedRaw = rawSource.trim();
|
|
450
|
-
const trimmedTailwind = rawTailwindCss.trim();
|
|
451
|
-
if (trimmedRaw === trimmedTailwind) return "";
|
|
452
|
-
if (trimmedTailwind.startsWith(trimmedRaw)) return "";
|
|
453
|
-
const start = rawSource.indexOf(rawTailwindCss);
|
|
454
|
-
if (start === -1) return;
|
|
455
|
-
return createCssAppend(rawSource.slice(0, start), rawSource.slice(start + rawTailwindCss.length));
|
|
456
|
-
}
|
|
457
|
-
function stripTailwindBanner(css) {
|
|
458
|
-
return css.replace(TAILWIND_BANNER_PREFIX_RE, "");
|
|
459
|
-
}
|
|
460
|
-
function stripTailwindBanners(css) {
|
|
461
|
-
return css.replace(TAILWIND_BANNER_GLOBAL_RE, "");
|
|
462
|
-
}
|
|
463
|
-
function stripGeneratorPlaceholderMarkers(css) {
|
|
464
|
-
return css.replace(GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE, "");
|
|
465
|
-
}
|
|
466
|
-
function hasTailwindGeneratedCss(rawSource) {
|
|
467
|
-
return TAILWIND_V4_BANNER_RE.test(rawSource);
|
|
468
|
-
}
|
|
469
|
-
function hasTailwindGeneratedCssMarkers(rawSource) {
|
|
470
|
-
return TAILWIND_GENERATED_CSS_MARKER_RE.test(rawSource) || GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
|
|
471
|
-
}
|
|
472
|
-
function finalizeMiniProgramGeneratorCss(css, target) {
|
|
473
|
-
if (target !== "weapp") return css;
|
|
474
|
-
return finalizeMiniProgramCss(css);
|
|
475
|
-
}
|
|
476
554
|
function normalizeCompatSelector(selector) {
|
|
477
555
|
return selector.replace(SPECIFICITY_PLACEHOLDER_RE, "").replace(/\s+/g, " ").trim();
|
|
478
556
|
}
|
|
@@ -522,190 +600,131 @@ function normalizeCompatSelectors(selector) {
|
|
|
522
600
|
if (escaped) selectors.add(escaped);
|
|
523
601
|
return [...selectors];
|
|
524
602
|
}
|
|
525
|
-
function
|
|
526
|
-
|
|
527
|
-
postcss.parse(css).walkRules((rule) => {
|
|
528
|
-
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
529
|
-
for (const selector of rule.selectors) {
|
|
530
|
-
const normalizedSelectors = normalizeCompatSelectors(selector);
|
|
531
|
-
rule.walkDecls((decl) => {
|
|
532
|
-
if (RPX_UNIT_RE.test(decl.value)) for (const normalizedSelector of normalizedSelectors) values.set(`${normalizedSelector}\n${decl.prop}`, decl.value);
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
});
|
|
536
|
-
return values;
|
|
537
|
-
}
|
|
538
|
-
function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
|
|
539
|
-
try {
|
|
540
|
-
const legacyValues = createLegacyDeclarationValueMap(legacyCss);
|
|
541
|
-
if (legacyValues.size === 0) return css;
|
|
542
|
-
const root = postcss.parse(css);
|
|
543
|
-
let changed = false;
|
|
544
|
-
root.walkRules((rule) => {
|
|
545
|
-
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
546
|
-
const selectors = rule.selectors.flatMap((selector) => normalizeCompatSelectors(selector));
|
|
547
|
-
if (selectors.length === 0) return;
|
|
548
|
-
rule.walkDecls((decl) => {
|
|
549
|
-
if (!CSS_LENGTH_UNIT_RE.test(decl.value)) return;
|
|
550
|
-
for (const selector of selectors) {
|
|
551
|
-
const legacyValue = legacyValues.get(`${selector}\n${decl.prop}`);
|
|
552
|
-
if (legacyValue && legacyValue !== decl.value) {
|
|
553
|
-
decl.value = legacyValue;
|
|
554
|
-
changed = true;
|
|
555
|
-
return;
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
});
|
|
559
|
-
});
|
|
560
|
-
return changed ? root.toString() : css;
|
|
561
|
-
} catch {
|
|
562
|
-
return css;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
|
|
566
|
-
const tailwindV3StyleOptions = cssHandlerOptions.majorVersion === 3 ? {
|
|
567
|
-
cssPreflight: opts.cssPreflight,
|
|
568
|
-
cssPreflightRange: opts.cssPreflightRange
|
|
569
|
-
} : {};
|
|
570
|
-
return {
|
|
571
|
-
cssChildCombinatorReplaceValue: opts.cssChildCombinatorReplaceValue,
|
|
572
|
-
cssSelectorReplacement: opts.cssSelectorReplacement,
|
|
573
|
-
rem2rpx: opts.rem2rpx,
|
|
574
|
-
px2rpx: opts.px2rpx,
|
|
575
|
-
unitsToPx: opts.unitsToPx,
|
|
576
|
-
cssRemoveProperty: opts.cssRemoveProperty,
|
|
577
|
-
cssRemoveHoverPseudoClass: opts.cssRemoveHoverPseudoClass,
|
|
578
|
-
cssPresetEnv: opts.cssPresetEnv,
|
|
579
|
-
autoprefixer: opts.autoprefixer,
|
|
580
|
-
cssCalc: opts.cssCalc,
|
|
581
|
-
atRules: opts.atRules,
|
|
582
|
-
uniAppX: opts.uniAppX,
|
|
583
|
-
uniAppXCssTarget: opts.uniAppXCssTarget,
|
|
584
|
-
uniAppXUnsupported: opts.uniAppXUnsupported,
|
|
585
|
-
...cssHandlerOptions,
|
|
586
|
-
...tailwindV3StyleOptions,
|
|
587
|
-
...generatorStyleOptions
|
|
588
|
-
};
|
|
603
|
+
function normalizeCssSelector(selector) {
|
|
604
|
+
return selector.trim().replace(/\s+/g, "");
|
|
589
605
|
}
|
|
590
|
-
function
|
|
591
|
-
return
|
|
606
|
+
function getCompatSelectorKeys(selector) {
|
|
607
|
+
return normalizeCompatSelectors(selector).map(normalizeCssSelector);
|
|
592
608
|
}
|
|
593
|
-
function
|
|
594
|
-
return
|
|
609
|
+
function getRuleCompatSelectorKeys(rule) {
|
|
610
|
+
return (rule.selectors?.length ? rule.selectors : [rule.selector]).flatMap((selector) => getCompatSelectorKeys(selector));
|
|
595
611
|
}
|
|
596
|
-
function
|
|
597
|
-
return
|
|
612
|
+
function hasClassSelector(selector) {
|
|
613
|
+
return CLASS_SELECTOR_RE.test(selector);
|
|
598
614
|
}
|
|
599
|
-
function
|
|
600
|
-
|
|
601
|
-
return typeof from === "string" && from.length > 0 ? from : void 0;
|
|
615
|
+
function getNormalizedSelectorList(selector) {
|
|
616
|
+
return selector.split(",").map(normalizeCssSelector).filter(Boolean);
|
|
602
617
|
}
|
|
603
|
-
function
|
|
604
|
-
const
|
|
605
|
-
return
|
|
618
|
+
function isMiniProgramThemeScopeSelector(selector) {
|
|
619
|
+
const selectors = getNormalizedSelectorList(selector);
|
|
620
|
+
return selectors.length > 0 && selectors.every((item) => MINI_PROGRAM_THEME_SCOPE_SELECTORS.has(item));
|
|
606
621
|
}
|
|
607
|
-
function
|
|
608
|
-
|
|
609
|
-
if (node.name !== "import") return false;
|
|
610
|
-
const request = parseImportRequest(node.params);
|
|
611
|
-
return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/");
|
|
622
|
+
function hasUtilityClassSelector(selector) {
|
|
623
|
+
return hasClassSelector(selector) && !isMiniProgramThemeScopeSelector(selector);
|
|
612
624
|
}
|
|
613
|
-
function
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
625
|
+
function isCustomPropertyOnlyRule(rule) {
|
|
626
|
+
let hasDeclaration = false;
|
|
627
|
+
let allCustomProperties = true;
|
|
628
|
+
rule.each((node) => {
|
|
629
|
+
if (node.type !== "decl") return;
|
|
630
|
+
hasDeclaration = true;
|
|
631
|
+
if (!node.prop.startsWith("--")) allCustomProperties = false;
|
|
632
|
+
});
|
|
633
|
+
return hasDeclaration && allCustomProperties;
|
|
618
634
|
}
|
|
619
|
-
function
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
635
|
+
function isPseudoContentInitRule(rule) {
|
|
636
|
+
let hasDeclaration = false;
|
|
637
|
+
let onlyContentVariable = true;
|
|
638
|
+
rule.each((node) => {
|
|
639
|
+
if (node.type !== "decl") return;
|
|
640
|
+
hasDeclaration = true;
|
|
641
|
+
if (node.prop !== "--tw-content") onlyContentVariable = false;
|
|
642
|
+
});
|
|
643
|
+
return hasDeclaration && onlyContentVariable;
|
|
623
644
|
}
|
|
624
|
-
function
|
|
645
|
+
function collectGeneratedSelectors(css) {
|
|
646
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
625
647
|
try {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
root.walk((node) => {
|
|
630
|
-
if (isTailwindSourceDirective(node)) {
|
|
631
|
-
node.remove();
|
|
632
|
-
removed = true;
|
|
633
|
-
}
|
|
648
|
+
postcss.parse(css).walkRules((rule) => {
|
|
649
|
+
if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
|
|
650
|
+
for (const selector of getRuleCompatSelectorKeys(rule)) selectors.add(selector);
|
|
634
651
|
});
|
|
635
|
-
return removed ? root.toString() : source;
|
|
636
652
|
} catch {
|
|
637
|
-
return
|
|
653
|
+
return selectors;
|
|
638
654
|
}
|
|
655
|
+
return selectors;
|
|
639
656
|
}
|
|
640
|
-
function
|
|
657
|
+
function removeGeneratedSelectorCompatCss(css, generatedCss) {
|
|
658
|
+
const generatedSelectors = collectGeneratedSelectors(generatedCss);
|
|
659
|
+
if (generatedSelectors.size === 0) return css;
|
|
641
660
|
try {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
return
|
|
661
|
+
const root = postcss.parse(css);
|
|
662
|
+
let removed = false;
|
|
663
|
+
root.walkRules((rule) => {
|
|
664
|
+
if (isPseudoContentInitRule(rule)) {
|
|
665
|
+
rule.remove();
|
|
666
|
+
removed = true;
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
|
|
670
|
+
if (getRuleCompatSelectorKeys(rule).some((selector) => generatedSelectors.has(selector))) {
|
|
671
|
+
rule.remove();
|
|
672
|
+
removed = true;
|
|
649
673
|
}
|
|
650
674
|
});
|
|
651
|
-
|
|
675
|
+
root.walkAtRules((atRule) => {
|
|
676
|
+
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
677
|
+
});
|
|
678
|
+
return removed ? root.toString() : css;
|
|
652
679
|
} catch {
|
|
653
|
-
return
|
|
680
|
+
return css;
|
|
654
681
|
}
|
|
655
682
|
}
|
|
656
|
-
function
|
|
683
|
+
function collectDedupedPostTransformCompatCss(css, generatedCss) {
|
|
684
|
+
const generatedSelectors = collectGeneratedSelectors(generatedCss);
|
|
685
|
+
if (generatedSelectors.size === 0) return css;
|
|
686
|
+
const preservedNodes = [];
|
|
657
687
|
try {
|
|
658
|
-
const root = postcss.parse(
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
node.
|
|
674
|
-
|
|
688
|
+
const root = postcss.parse(css);
|
|
689
|
+
root.each((node) => {
|
|
690
|
+
if (node.type === "rule" && getRuleCompatSelectorKeys(node).some((selector) => generatedSelectors.has(selector))) {
|
|
691
|
+
if (isCustomPropertyOnlyRule(node) && !isPseudoContentInitRule(node) && !hasUtilityClassSelector(node.selector)) {
|
|
692
|
+
const declarationProps = /* @__PURE__ */ new Set();
|
|
693
|
+
node.walkDecls((decl) => {
|
|
694
|
+
declarationProps.add(decl.prop);
|
|
695
|
+
});
|
|
696
|
+
postcss.parse(generatedCss).walkRules((rule) => {
|
|
697
|
+
const nodeSelectors = new Set(getRuleCompatSelectorKeys(node));
|
|
698
|
+
if (!getRuleCompatSelectorKeys(rule).some((selector) => nodeSelectors.has(selector))) return;
|
|
699
|
+
rule.walkDecls((decl) => {
|
|
700
|
+
declarationProps.delete(decl.prop);
|
|
701
|
+
});
|
|
702
|
+
});
|
|
703
|
+
const nextRule = node.clone();
|
|
704
|
+
nextRule.walkDecls((decl) => {
|
|
705
|
+
if (!declarationProps.has(decl.prop)) decl.remove();
|
|
706
|
+
});
|
|
707
|
+
if (nextRule.nodes.length > 0) preservedNodes.push(nextRule);
|
|
675
708
|
}
|
|
709
|
+
return;
|
|
676
710
|
}
|
|
711
|
+
preservedNodes.push(node.clone());
|
|
677
712
|
});
|
|
678
|
-
if (
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
configRequest,
|
|
683
|
-
base
|
|
684
|
-
};
|
|
713
|
+
if (preservedNodes.length === root.nodes.length) return css;
|
|
714
|
+
const nextRoot = postcss.root();
|
|
715
|
+
nextRoot.append(preservedNodes);
|
|
716
|
+
return nextRoot.toString();
|
|
685
717
|
} catch {
|
|
686
|
-
return;
|
|
718
|
+
return css;
|
|
687
719
|
}
|
|
688
720
|
}
|
|
689
|
-
function
|
|
690
|
-
if (
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
const baseCandidates = [
|
|
694
|
-
sourceOptions.projectRoot,
|
|
695
|
-
sourceOptions.cwd,
|
|
696
|
-
process.cwd()
|
|
697
|
-
].filter((item) => typeof item === "string" && item.length > 0);
|
|
698
|
-
for (const base of baseCandidates) {
|
|
699
|
-
const candidates = [
|
|
700
|
-
path.resolve(base, configRequest),
|
|
701
|
-
path.resolve(base, "src", configRequest),
|
|
702
|
-
path.resolve(base, outputDir, configRequest),
|
|
703
|
-
path.resolve(base, "src", outputDir, configRequest)
|
|
704
|
-
];
|
|
705
|
-
for (const candidate of candidates) if (existsSync(candidate)) return candidate;
|
|
706
|
-
}
|
|
707
|
-
return sourceOptions.config;
|
|
721
|
+
function removeDuplicatedViteMarkers(css, baseCss) {
|
|
722
|
+
if (!VITE_MARKER_RE.test(baseCss)) return css;
|
|
723
|
+
VITE_MARKER_RE.lastIndex = 0;
|
|
724
|
+
return css.replace(VITE_MARKER_RE, "");
|
|
708
725
|
}
|
|
726
|
+
//#endregion
|
|
727
|
+
//#region src/bundlers/shared/generator-css/config-directive.ts
|
|
709
728
|
function quoteCssString(value) {
|
|
710
729
|
return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
|
|
711
730
|
}
|
|
@@ -720,6 +739,25 @@ function normalizeConfigDirective(css, config) {
|
|
|
720
739
|
if (!config || !/@config\s+/.test(css)) return css;
|
|
721
740
|
return css.replace(/@config\s+(["'])(.+?)\1\s*;?/, `@config "${quoteCssString(toCssPath(config))}";`);
|
|
722
741
|
}
|
|
742
|
+
//#endregion
|
|
743
|
+
//#region src/bundlers/shared/generator-css/source-files.ts
|
|
744
|
+
const SOURCE_STYLE_EXTENSIONS = [
|
|
745
|
+
".vue",
|
|
746
|
+
".uvue",
|
|
747
|
+
".nvue",
|
|
748
|
+
".css",
|
|
749
|
+
".scss",
|
|
750
|
+
".sass",
|
|
751
|
+
".less",
|
|
752
|
+
".styl",
|
|
753
|
+
".stylus",
|
|
754
|
+
".wxss",
|
|
755
|
+
".acss",
|
|
756
|
+
".jxss",
|
|
757
|
+
".ttss",
|
|
758
|
+
".qss"
|
|
759
|
+
];
|
|
760
|
+
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
723
761
|
function stripStyleExtension(file) {
|
|
724
762
|
return file.replace(/[?#].*$/, "").replace(/\.(?:wx|ac|jx|tt|q|c|ty)?ss$/i, "");
|
|
725
763
|
}
|
|
@@ -761,11 +799,6 @@ function createSourceStylePathCandidates(file, sourceOptions) {
|
|
|
761
799
|
}
|
|
762
800
|
return [...candidates];
|
|
763
801
|
}
|
|
764
|
-
function canResolveSourceSideCssEntry(file, cssHandlerOptions) {
|
|
765
|
-
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
766
|
-
if (!from || !path.isAbsolute(from)) return path.isAbsolute(file);
|
|
767
|
-
return true;
|
|
768
|
-
}
|
|
769
802
|
function extractStyleDirectiveSources(source) {
|
|
770
803
|
const styleSources = [];
|
|
771
804
|
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
@@ -778,9 +811,6 @@ function extractStyleDirectiveSources(source) {
|
|
|
778
811
|
if (styleSources.length > 0) return styleSources;
|
|
779
812
|
return hasTailwindSourceDirectives(source) ? [source] : [];
|
|
780
813
|
}
|
|
781
|
-
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
782
|
-
return rawSource.includes("@apply");
|
|
783
|
-
}
|
|
784
814
|
function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {}) {
|
|
785
815
|
for (const sourceFile of createSourceStylePathCandidates(file, sourceOptions)) {
|
|
786
816
|
if (!existsSync(sourceFile)) continue;
|
|
@@ -795,6 +825,44 @@ function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {
|
|
|
795
825
|
}
|
|
796
826
|
}
|
|
797
827
|
}
|
|
828
|
+
//#endregion
|
|
829
|
+
//#region src/bundlers/shared/generator-css/source-resolver.ts
|
|
830
|
+
function resolvePostcssFromOption(cssHandlerOptions) {
|
|
831
|
+
const from = cssHandlerOptions.postcssOptions?.options?.from;
|
|
832
|
+
return typeof from === "string" && from.length > 0 ? from : void 0;
|
|
833
|
+
}
|
|
834
|
+
function resolveCssSourceBase(file, cssHandlerOptions) {
|
|
835
|
+
const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
|
|
836
|
+
return path.dirname(path.resolve(normalized));
|
|
837
|
+
}
|
|
838
|
+
function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
|
|
839
|
+
if (config && existsSync(config)) return config;
|
|
840
|
+
if (!configRequest || path.isAbsolute(configRequest)) return sourceOptions.config;
|
|
841
|
+
const outputDir = path.dirname(file.replace(/[?#].*$/, ""));
|
|
842
|
+
const baseCandidates = [
|
|
843
|
+
sourceOptions.projectRoot,
|
|
844
|
+
sourceOptions.cwd,
|
|
845
|
+
process.cwd()
|
|
846
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
847
|
+
for (const base of baseCandidates) {
|
|
848
|
+
const candidates = [
|
|
849
|
+
path.resolve(base, configRequest),
|
|
850
|
+
path.resolve(base, "src", configRequest),
|
|
851
|
+
path.resolve(base, outputDir, configRequest),
|
|
852
|
+
path.resolve(base, "src", outputDir, configRequest)
|
|
853
|
+
];
|
|
854
|
+
for (const candidate of candidates) if (existsSync(candidate)) return candidate;
|
|
855
|
+
}
|
|
856
|
+
return sourceOptions.config;
|
|
857
|
+
}
|
|
858
|
+
function canResolveSourceSideCssEntry(file, cssHandlerOptions) {
|
|
859
|
+
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
860
|
+
if (!from || !path.isAbsolute(from)) return path.isAbsolute(file);
|
|
861
|
+
return true;
|
|
862
|
+
}
|
|
863
|
+
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
864
|
+
return rawSource.includes("@apply");
|
|
865
|
+
}
|
|
798
866
|
function normalizeCssSourceForCompare(css) {
|
|
799
867
|
return stripGeneratorPlaceholderMarkers(stripTailwindBanners(css)).trim();
|
|
800
868
|
}
|
|
@@ -830,6 +898,9 @@ function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
|
830
898
|
return;
|
|
831
899
|
}
|
|
832
900
|
}
|
|
901
|
+
function hasConfiguredTailwindV4CssSource(sourceOptions) {
|
|
902
|
+
return Boolean(sourceOptions?.css) || Boolean(sourceOptions?.cssSources?.length);
|
|
903
|
+
}
|
|
833
904
|
async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions) {
|
|
834
905
|
const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), { removeConfig: majorVersion === 3 });
|
|
835
906
|
if (majorVersion === 3) {
|
|
@@ -850,13 +921,24 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
850
921
|
});
|
|
851
922
|
}
|
|
852
923
|
const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
|
|
924
|
+
const configuredCssSource = sourceOptions && hasConfiguredTailwindV4CssSource(sourceOptions) && hasTailwindGeneratedCssMarkers(rawSource) ? await resolveTailwindV4Source(sourceOptions) : void 0;
|
|
925
|
+
if (configuredCssSource) return generatorOptions?.config ? {
|
|
926
|
+
...configuredCssSource,
|
|
927
|
+
css: prependConfigDirective(configuredCssSource.css, generatorOptions.config)
|
|
928
|
+
} : configuredCssSource;
|
|
853
929
|
const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder"));
|
|
854
930
|
const sourceSideEntrySource = sourceOptions && shouldPreferSourceSideEntry ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0;
|
|
855
931
|
const matchedCssEntrySource = sourceOptions && cssEntrySource ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
|
|
856
|
-
|
|
857
|
-
...
|
|
858
|
-
css:
|
|
859
|
-
|
|
932
|
+
const mainCssEntrySource = sourceOptions && cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1 ? await resolveTailwindV4Source({
|
|
933
|
+
...sourceOptions,
|
|
934
|
+
css: void 0,
|
|
935
|
+
cssEntries: [sourceOptions.cssEntries[0]]
|
|
936
|
+
}) : void 0;
|
|
937
|
+
const preferredCssEntrySource = matchedCssEntrySource ?? mainCssEntrySource;
|
|
938
|
+
if (preferredCssEntrySource) return generatorOptions?.config ? {
|
|
939
|
+
...preferredCssEntrySource,
|
|
940
|
+
css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
941
|
+
} : preferredCssEntrySource;
|
|
860
942
|
const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource;
|
|
861
943
|
if (!resolvedEntrySource) {
|
|
862
944
|
const source = await resolveTailwindV4SourceFromPatcher(runtimeState.twPatcher);
|
|
@@ -880,17 +962,198 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
880
962
|
try {
|
|
881
963
|
sourceOptions = resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
882
964
|
} catch {
|
|
883
|
-
return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions)];
|
|
965
|
+
return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions)];
|
|
966
|
+
}
|
|
967
|
+
if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions)];
|
|
968
|
+
return await Promise.all(sourceOptions.cssEntries.map((cssEntry) => resolveTailwindV4Source({
|
|
969
|
+
...sourceOptions,
|
|
970
|
+
css: void 0,
|
|
971
|
+
cssEntries: [cssEntry]
|
|
972
|
+
}).then((source) => generatorOptions?.config ? {
|
|
973
|
+
...source,
|
|
974
|
+
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
975
|
+
} : source)));
|
|
976
|
+
}
|
|
977
|
+
//#endregion
|
|
978
|
+
//#region src/bundlers/shared/generator-css/legacy-compat.ts
|
|
979
|
+
const LEGACY_CONTAINER_COMPAT_CSS = [
|
|
980
|
+
".container {",
|
|
981
|
+
" width: 100%;",
|
|
982
|
+
"}",
|
|
983
|
+
"@media (min-width: 40rem) {",
|
|
984
|
+
" .container {",
|
|
985
|
+
" max-width: 40rem;",
|
|
986
|
+
" }",
|
|
987
|
+
"}",
|
|
988
|
+
"@media (min-width: 48rem) {",
|
|
989
|
+
" .container {",
|
|
990
|
+
" max-width: 48rem;",
|
|
991
|
+
" }",
|
|
992
|
+
"}",
|
|
993
|
+
"@media (min-width: 64rem) {",
|
|
994
|
+
" .container {",
|
|
995
|
+
" max-width: 64rem;",
|
|
996
|
+
" }",
|
|
997
|
+
"}",
|
|
998
|
+
"@media (min-width: 80rem) {",
|
|
999
|
+
" .container {",
|
|
1000
|
+
" max-width: 80rem;",
|
|
1001
|
+
" }",
|
|
1002
|
+
"}",
|
|
1003
|
+
"@media (min-width: 96rem) {",
|
|
1004
|
+
" .container {",
|
|
1005
|
+
" max-width: 96rem;",
|
|
1006
|
+
" }",
|
|
1007
|
+
"}"
|
|
1008
|
+
].join("\n");
|
|
1009
|
+
function removeTailwindApplyRules(rawSource) {
|
|
1010
|
+
try {
|
|
1011
|
+
const root = postcss.parse(rawSource);
|
|
1012
|
+
let removed = false;
|
|
1013
|
+
root.walkAtRules("apply", (rule) => {
|
|
1014
|
+
const parent = rule.parent;
|
|
1015
|
+
if (parent?.type === "rule") parent.remove();
|
|
1016
|
+
else rule.remove();
|
|
1017
|
+
removed = true;
|
|
1018
|
+
});
|
|
1019
|
+
root.walkAtRules((rule) => {
|
|
1020
|
+
if (rule.nodes && rule.nodes.length === 0) rule.remove();
|
|
1021
|
+
});
|
|
1022
|
+
return removed ? root.toString() : rawSource;
|
|
1023
|
+
} catch {
|
|
1024
|
+
return rawSource;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
function resolveLegacyCompatCssSource(rawSource) {
|
|
1028
|
+
return removeUnsupportedMiniProgramAtRules(removeTailwindApplyRules(removeTailwindSourceDirectives(stripTailwindBanners(rawSource))));
|
|
1029
|
+
}
|
|
1030
|
+
function hasContainerConfigToken(rawSource) {
|
|
1031
|
+
return rawSource.includes("@config") && /\bcontainer\b/.test(rawSource);
|
|
1032
|
+
}
|
|
1033
|
+
function hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) {
|
|
1034
|
+
if (hasContainerConfigToken(rawSource)) return true;
|
|
1035
|
+
const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions));
|
|
1036
|
+
if (!cssEntrySource?.config) return false;
|
|
1037
|
+
try {
|
|
1038
|
+
return /\bcontainer\b/.test(readFileSync(cssEntrySource.config, "utf8"));
|
|
1039
|
+
} catch {
|
|
1040
|
+
return false;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
function hasConfiguredContainerCompatSource(source) {
|
|
1044
|
+
if (hasContainerConfigToken(source.css)) return true;
|
|
1045
|
+
const cssEntrySource = resolveCssEntrySource(source.css, source.base);
|
|
1046
|
+
if (cssEntrySource?.config) try {
|
|
1047
|
+
if (/\bcontainer\b/.test(readFileSync(cssEntrySource.config, "utf8"))) return true;
|
|
1048
|
+
} catch {}
|
|
1049
|
+
if ("config" in source && source.config) try {
|
|
1050
|
+
if (/\bcontainer\b/.test(readFileSync(source.config, "utf8"))) return true;
|
|
1051
|
+
} catch {}
|
|
1052
|
+
return false;
|
|
1053
|
+
}
|
|
1054
|
+
function hasConfiguredContainerCompatSources(sources) {
|
|
1055
|
+
return sources.some((source) => hasConfiguredContainerCompatSource(source));
|
|
1056
|
+
}
|
|
1057
|
+
async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
|
|
1058
|
+
const compatSource = removeGeneratedSelectorCompatCss(resolveLegacyCompatCssSource(rawSource), css);
|
|
1059
|
+
if (compatSource.trim().length === 0) return css;
|
|
1060
|
+
if (generatorTarget !== "weapp") return createCssAppend(css, compatSource);
|
|
1061
|
+
const { css: compatCss } = await styleHandler(compatSource, {
|
|
1062
|
+
...cssHandlerOptions,
|
|
1063
|
+
...generatorStyleOptions
|
|
1064
|
+
});
|
|
1065
|
+
const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeDuplicatedViteMarkers(removeUnsupportedMiniProgramAtRules(compatCss), css), css);
|
|
1066
|
+
if (cleanedCompatCss.trim().length === 0) return css;
|
|
1067
|
+
return createCssAppend(css, cleanedCompatCss);
|
|
1068
|
+
}
|
|
1069
|
+
async function appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
|
|
1070
|
+
const compatSource = resolveLegacyCompatCssSource(rawSource);
|
|
1071
|
+
const shouldAppendContainer = runtime.has("container") || hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) || configuredContainerCompat || collectGeneratedSelectors(compatSource).has(".container");
|
|
1072
|
+
if (generatorTarget !== "weapp" || !shouldAppendContainer || collectGeneratedSelectors(css).has(".container")) return css;
|
|
1073
|
+
const { css: compatCss } = await styleHandler(LEGACY_CONTAINER_COMPAT_CSS, {
|
|
1074
|
+
...cssHandlerOptions,
|
|
1075
|
+
...generatorStyleOptions
|
|
1076
|
+
});
|
|
1077
|
+
const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeUnsupportedMiniProgramAtRules(compatCss), css);
|
|
1078
|
+
if (cleanedCompatCss.trim().length === 0) return css;
|
|
1079
|
+
return createCssAppend(css, cleanedCompatCss);
|
|
1080
|
+
}
|
|
1081
|
+
//#endregion
|
|
1082
|
+
//#region src/bundlers/shared/generator-css/legacy-units.ts
|
|
1083
|
+
const CSS_LENGTH_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)(?:px|rem)\b/i;
|
|
1084
|
+
const RPX_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)rpx\b/i;
|
|
1085
|
+
function createLegacyDeclarationValueMap(css) {
|
|
1086
|
+
const values = /* @__PURE__ */ new Map();
|
|
1087
|
+
postcss.parse(css).walkRules((rule) => {
|
|
1088
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
1089
|
+
for (const selector of rule.selectors) {
|
|
1090
|
+
const normalizedSelectors = normalizeCompatSelectors(selector);
|
|
1091
|
+
rule.walkDecls((decl) => {
|
|
1092
|
+
if (RPX_UNIT_RE.test(decl.value)) for (const normalizedSelector of normalizedSelectors) values.set(`${normalizedSelector}\n${decl.prop}`, decl.value);
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
return values;
|
|
1097
|
+
}
|
|
1098
|
+
function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
|
|
1099
|
+
try {
|
|
1100
|
+
const legacyValues = createLegacyDeclarationValueMap(legacyCss);
|
|
1101
|
+
if (legacyValues.size === 0) return css;
|
|
1102
|
+
const root = postcss.parse(css);
|
|
1103
|
+
let changed = false;
|
|
1104
|
+
root.walkRules((rule) => {
|
|
1105
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
1106
|
+
const selectors = rule.selectors.flatMap((selector) => normalizeCompatSelectors(selector));
|
|
1107
|
+
if (selectors.length === 0) return;
|
|
1108
|
+
rule.walkDecls((decl) => {
|
|
1109
|
+
if (!CSS_LENGTH_UNIT_RE.test(decl.value)) return;
|
|
1110
|
+
for (const selector of selectors) {
|
|
1111
|
+
const legacyValue = legacyValues.get(`${selector}\n${decl.prop}`);
|
|
1112
|
+
if (legacyValue && legacyValue !== decl.value) {
|
|
1113
|
+
decl.value = legacyValue;
|
|
1114
|
+
changed = true;
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
});
|
|
1120
|
+
return changed ? root.toString() : css;
|
|
1121
|
+
} catch {
|
|
1122
|
+
return css;
|
|
884
1123
|
}
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
1124
|
+
}
|
|
1125
|
+
//#endregion
|
|
1126
|
+
//#region src/bundlers/shared/generator-css.ts
|
|
1127
|
+
const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
|
|
1128
|
+
const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
|
|
1129
|
+
function finalizeMiniProgramGeneratorCss(css, target) {
|
|
1130
|
+
if (target !== "weapp") return css;
|
|
1131
|
+
return finalizeMiniProgramCss(css);
|
|
1132
|
+
}
|
|
1133
|
+
function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
|
|
1134
|
+
const tailwindV3StyleOptions = cssHandlerOptions.majorVersion === 3 ? {
|
|
1135
|
+
cssPreflight: opts.cssPreflight,
|
|
1136
|
+
cssPreflightRange: opts.cssPreflightRange
|
|
1137
|
+
} : {};
|
|
1138
|
+
return {
|
|
1139
|
+
cssChildCombinatorReplaceValue: opts.cssChildCombinatorReplaceValue,
|
|
1140
|
+
cssSelectorReplacement: opts.cssSelectorReplacement,
|
|
1141
|
+
rem2rpx: opts.rem2rpx,
|
|
1142
|
+
px2rpx: opts.px2rpx,
|
|
1143
|
+
unitsToPx: opts.unitsToPx,
|
|
1144
|
+
cssRemoveProperty: opts.cssRemoveProperty,
|
|
1145
|
+
cssRemoveHoverPseudoClass: opts.cssRemoveHoverPseudoClass,
|
|
1146
|
+
cssPresetEnv: opts.cssPresetEnv,
|
|
1147
|
+
autoprefixer: opts.autoprefixer,
|
|
1148
|
+
cssCalc: opts.cssCalc,
|
|
1149
|
+
atRules: opts.atRules,
|
|
1150
|
+
uniAppX: opts.uniAppX,
|
|
1151
|
+
uniAppXCssTarget: opts.uniAppXCssTarget,
|
|
1152
|
+
uniAppXUnsupported: opts.uniAppXUnsupported,
|
|
1153
|
+
...cssHandlerOptions,
|
|
1154
|
+
...tailwindV3StyleOptions,
|
|
1155
|
+
...generatorStyleOptions
|
|
1156
|
+
};
|
|
894
1157
|
}
|
|
895
1158
|
function isLocalImportRequest(request) {
|
|
896
1159
|
return request.length > 0 && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
@@ -947,201 +1210,6 @@ function prefixLocalCssImportsWithWebpackIgnore(css) {
|
|
|
947
1210
|
return css;
|
|
948
1211
|
}
|
|
949
1212
|
}
|
|
950
|
-
function resolveLegacyCompatCssSource(rawSource) {
|
|
951
|
-
return removeUnsupportedMiniProgramAtRules(removeTailwindApplyRules(removeTailwindSourceDirectives(stripTailwindBanners(rawSource))));
|
|
952
|
-
}
|
|
953
|
-
function removeTailwindApplyRules(rawSource) {
|
|
954
|
-
try {
|
|
955
|
-
const root = postcss.parse(rawSource);
|
|
956
|
-
let removed = false;
|
|
957
|
-
root.walkAtRules("apply", (rule) => {
|
|
958
|
-
const parent = rule.parent;
|
|
959
|
-
if (parent?.type === "rule") parent.remove();
|
|
960
|
-
else rule.remove();
|
|
961
|
-
removed = true;
|
|
962
|
-
});
|
|
963
|
-
root.walkAtRules((rule) => {
|
|
964
|
-
if (rule.nodes && rule.nodes.length === 0) rule.remove();
|
|
965
|
-
});
|
|
966
|
-
return removed ? root.toString() : rawSource;
|
|
967
|
-
} catch {
|
|
968
|
-
return rawSource;
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
function hasContainerConfigToken(rawSource) {
|
|
972
|
-
return rawSource.includes("@config") && /\bcontainer\b/.test(rawSource);
|
|
973
|
-
}
|
|
974
|
-
function hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) {
|
|
975
|
-
if (hasContainerConfigToken(rawSource)) return true;
|
|
976
|
-
const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions));
|
|
977
|
-
if (!cssEntrySource?.config) return false;
|
|
978
|
-
try {
|
|
979
|
-
return /\bcontainer\b/.test(readFileSync(cssEntrySource.config, "utf8"));
|
|
980
|
-
} catch {
|
|
981
|
-
return false;
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
function hasConfiguredContainerCompatSource(source) {
|
|
985
|
-
if (hasContainerConfigToken(source.css)) return true;
|
|
986
|
-
const cssEntrySource = resolveCssEntrySource(source.css, source.base);
|
|
987
|
-
if (cssEntrySource?.config) try {
|
|
988
|
-
if (/\bcontainer\b/.test(readFileSync(cssEntrySource.config, "utf8"))) return true;
|
|
989
|
-
} catch {}
|
|
990
|
-
if ("config" in source && source.config) try {
|
|
991
|
-
if (/\bcontainer\b/.test(readFileSync(source.config, "utf8"))) return true;
|
|
992
|
-
} catch {}
|
|
993
|
-
return false;
|
|
994
|
-
}
|
|
995
|
-
function hasConfiguredContainerCompatSources(sources) {
|
|
996
|
-
return sources.some((source) => hasConfiguredContainerCompatSource(source));
|
|
997
|
-
}
|
|
998
|
-
function removeDuplicatedViteMarkers(css, baseCss) {
|
|
999
|
-
if (!VITE_MARKER_RE.test(baseCss)) return css;
|
|
1000
|
-
VITE_MARKER_RE.lastIndex = 0;
|
|
1001
|
-
return css.replace(VITE_MARKER_RE, "");
|
|
1002
|
-
}
|
|
1003
|
-
function normalizeCssSelector(selector) {
|
|
1004
|
-
return selector.trim().replace(/\s+/g, "");
|
|
1005
|
-
}
|
|
1006
|
-
function getCompatSelectorKeys(selector) {
|
|
1007
|
-
return normalizeCompatSelectors(selector).map(normalizeCssSelector);
|
|
1008
|
-
}
|
|
1009
|
-
function getRuleCompatSelectorKeys(rule) {
|
|
1010
|
-
return (rule.selectors?.length ? rule.selectors : [rule.selector]).flatMap((selector) => getCompatSelectorKeys(selector));
|
|
1011
|
-
}
|
|
1012
|
-
function hasClassSelector(selector) {
|
|
1013
|
-
return CLASS_SELECTOR_RE.test(selector);
|
|
1014
|
-
}
|
|
1015
|
-
function getNormalizedSelectorList(selector) {
|
|
1016
|
-
return selector.split(",").map(normalizeCssSelector).filter(Boolean);
|
|
1017
|
-
}
|
|
1018
|
-
function isMiniProgramThemeScopeSelector(selector) {
|
|
1019
|
-
const selectors = getNormalizedSelectorList(selector);
|
|
1020
|
-
return selectors.length > 0 && selectors.every((item) => MINI_PROGRAM_THEME_SCOPE_SELECTORS.has(item));
|
|
1021
|
-
}
|
|
1022
|
-
function hasUtilityClassSelector(selector) {
|
|
1023
|
-
return hasClassSelector(selector) && !isMiniProgramThemeScopeSelector(selector);
|
|
1024
|
-
}
|
|
1025
|
-
function isCustomPropertyOnlyRule(rule) {
|
|
1026
|
-
let hasDeclaration = false;
|
|
1027
|
-
let allCustomProperties = true;
|
|
1028
|
-
rule.each((node) => {
|
|
1029
|
-
if (node.type !== "decl") return;
|
|
1030
|
-
hasDeclaration = true;
|
|
1031
|
-
if (!node.prop.startsWith("--")) allCustomProperties = false;
|
|
1032
|
-
});
|
|
1033
|
-
return hasDeclaration && allCustomProperties;
|
|
1034
|
-
}
|
|
1035
|
-
function isPseudoContentInitRule(rule) {
|
|
1036
|
-
let hasDeclaration = false;
|
|
1037
|
-
let onlyContentVariable = true;
|
|
1038
|
-
rule.each((node) => {
|
|
1039
|
-
if (node.type !== "decl") return;
|
|
1040
|
-
hasDeclaration = true;
|
|
1041
|
-
if (node.prop !== "--tw-content") onlyContentVariable = false;
|
|
1042
|
-
});
|
|
1043
|
-
return hasDeclaration && onlyContentVariable;
|
|
1044
|
-
}
|
|
1045
|
-
function collectGeneratedSelectors(css) {
|
|
1046
|
-
const selectors = /* @__PURE__ */ new Set();
|
|
1047
|
-
try {
|
|
1048
|
-
postcss.parse(css).walkRules((rule) => {
|
|
1049
|
-
if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
|
|
1050
|
-
for (const selector of getRuleCompatSelectorKeys(rule)) selectors.add(selector);
|
|
1051
|
-
});
|
|
1052
|
-
} catch {
|
|
1053
|
-
return selectors;
|
|
1054
|
-
}
|
|
1055
|
-
return selectors;
|
|
1056
|
-
}
|
|
1057
|
-
function removeGeneratedSelectorCompatCss(css, generatedCss) {
|
|
1058
|
-
const generatedSelectors = collectGeneratedSelectors(generatedCss);
|
|
1059
|
-
if (generatedSelectors.size === 0) return css;
|
|
1060
|
-
try {
|
|
1061
|
-
const root = postcss.parse(css);
|
|
1062
|
-
let removed = false;
|
|
1063
|
-
root.walkRules((rule) => {
|
|
1064
|
-
if (isPseudoContentInitRule(rule)) {
|
|
1065
|
-
rule.remove();
|
|
1066
|
-
removed = true;
|
|
1067
|
-
return;
|
|
1068
|
-
}
|
|
1069
|
-
if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
|
|
1070
|
-
if (getRuleCompatSelectorKeys(rule).some((selector) => generatedSelectors.has(selector))) {
|
|
1071
|
-
rule.remove();
|
|
1072
|
-
removed = true;
|
|
1073
|
-
}
|
|
1074
|
-
});
|
|
1075
|
-
root.walkAtRules((atRule) => {
|
|
1076
|
-
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
1077
|
-
});
|
|
1078
|
-
return removed ? root.toString() : css;
|
|
1079
|
-
} catch {
|
|
1080
|
-
return css;
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
function collectDedupedPostTransformCompatCss(css, generatedCss) {
|
|
1084
|
-
const generatedSelectors = collectGeneratedSelectors(generatedCss);
|
|
1085
|
-
if (generatedSelectors.size === 0) return css;
|
|
1086
|
-
const preservedNodes = [];
|
|
1087
|
-
try {
|
|
1088
|
-
const root = postcss.parse(css);
|
|
1089
|
-
root.each((node) => {
|
|
1090
|
-
if (node.type === "rule" && getRuleCompatSelectorKeys(node).some((selector) => generatedSelectors.has(selector))) {
|
|
1091
|
-
if (isCustomPropertyOnlyRule(node) && !isPseudoContentInitRule(node) && !hasUtilityClassSelector(node.selector)) {
|
|
1092
|
-
const declarationProps = /* @__PURE__ */ new Set();
|
|
1093
|
-
node.walkDecls((decl) => {
|
|
1094
|
-
declarationProps.add(decl.prop);
|
|
1095
|
-
});
|
|
1096
|
-
postcss.parse(generatedCss).walkRules((rule) => {
|
|
1097
|
-
const nodeSelectors = new Set(getRuleCompatSelectorKeys(node));
|
|
1098
|
-
if (!getRuleCompatSelectorKeys(rule).some((selector) => nodeSelectors.has(selector))) return;
|
|
1099
|
-
rule.walkDecls((decl) => {
|
|
1100
|
-
declarationProps.delete(decl.prop);
|
|
1101
|
-
});
|
|
1102
|
-
});
|
|
1103
|
-
const nextRule = node.clone();
|
|
1104
|
-
nextRule.walkDecls((decl) => {
|
|
1105
|
-
if (!declarationProps.has(decl.prop)) decl.remove();
|
|
1106
|
-
});
|
|
1107
|
-
if (nextRule.nodes.length > 0) preservedNodes.push(nextRule);
|
|
1108
|
-
}
|
|
1109
|
-
return;
|
|
1110
|
-
}
|
|
1111
|
-
preservedNodes.push(node.clone());
|
|
1112
|
-
});
|
|
1113
|
-
if (preservedNodes.length === root.nodes.length) return css;
|
|
1114
|
-
const nextRoot = postcss.root();
|
|
1115
|
-
nextRoot.append(preservedNodes);
|
|
1116
|
-
return nextRoot.toString();
|
|
1117
|
-
} catch {
|
|
1118
|
-
return css;
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
|
|
1122
|
-
const compatSource = removeGeneratedSelectorCompatCss(resolveLegacyCompatCssSource(rawSource), css);
|
|
1123
|
-
if (compatSource.trim().length === 0) return css;
|
|
1124
|
-
if (generatorTarget !== "weapp") return createCssAppend(css, compatSource);
|
|
1125
|
-
const { css: compatCss } = await styleHandler(compatSource, {
|
|
1126
|
-
...cssHandlerOptions,
|
|
1127
|
-
...generatorStyleOptions
|
|
1128
|
-
});
|
|
1129
|
-
const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeDuplicatedViteMarkers(removeUnsupportedMiniProgramAtRules(compatCss), css), css);
|
|
1130
|
-
if (cleanedCompatCss.trim().length === 0) return css;
|
|
1131
|
-
return createCssAppend(css, cleanedCompatCss);
|
|
1132
|
-
}
|
|
1133
|
-
async function appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
|
|
1134
|
-
const compatSource = resolveLegacyCompatCssSource(rawSource);
|
|
1135
|
-
const shouldAppendContainer = runtime.has("container") || hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) || configuredContainerCompat || collectGeneratedSelectors(compatSource).has(".container");
|
|
1136
|
-
if (generatorTarget !== "weapp" || !shouldAppendContainer || collectGeneratedSelectors(css).has(".container")) return css;
|
|
1137
|
-
const { css: compatCss } = await styleHandler(LEGACY_CONTAINER_COMPAT_CSS, {
|
|
1138
|
-
...cssHandlerOptions,
|
|
1139
|
-
...generatorStyleOptions
|
|
1140
|
-
});
|
|
1141
|
-
const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeUnsupportedMiniProgramAtRules(compatCss), css);
|
|
1142
|
-
if (cleanedCompatCss.trim().length === 0) return css;
|
|
1143
|
-
return createCssAppend(css, cleanedCompatCss);
|
|
1144
|
-
}
|
|
1145
1213
|
async function generateCssByGenerator(options) {
|
|
1146
1214
|
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, styleHandler, debug } = options;
|
|
1147
1215
|
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
@@ -1160,7 +1228,7 @@ async function generateCssByGenerator(options) {
|
|
|
1160
1228
|
const shouldGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
|
|
1161
1229
|
if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
|
|
1162
1230
|
try {
|
|
1163
|
-
await runtimeState.
|
|
1231
|
+
await runtimeState.readyPromise;
|
|
1164
1232
|
const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions);
|
|
1165
1233
|
const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
|
|
1166
1234
|
const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
|
|
@@ -1234,5 +1302,22 @@ async function generateCssByGenerator(options) {
|
|
|
1234
1302
|
throw error;
|
|
1235
1303
|
}
|
|
1236
1304
|
}
|
|
1305
|
+
async function validateCandidatesByGenerator(options) {
|
|
1306
|
+
const { candidates, cssHandlerOptions, debug, file, opts, rawSource, runtimeState } = options;
|
|
1307
|
+
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
1308
|
+
if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || candidates.size === 0) return /* @__PURE__ */ new Set();
|
|
1309
|
+
const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, normalizeWeappTailwindcssGeneratorOptions(opts.generator));
|
|
1310
|
+
const classSets = await Promise.all(sources.map(async (source) => {
|
|
1311
|
+
const generator = createWeappTailwindcssGenerator(source);
|
|
1312
|
+
if (typeof generator.validateCandidates === "function") return generator.validateCandidates(candidates);
|
|
1313
|
+
return (await generator.generate({
|
|
1314
|
+
candidates,
|
|
1315
|
+
target: "tailwind"
|
|
1316
|
+
})).classSet;
|
|
1317
|
+
}));
|
|
1318
|
+
const classSet = new Set(classSets.flatMap((item) => [...item]));
|
|
1319
|
+
debug("tailwind generator validated candidates: %s candidates=%d classSet=%d", file, candidates.size, classSet.size);
|
|
1320
|
+
return classSet;
|
|
1321
|
+
}
|
|
1237
1322
|
//#endregion
|
|
1238
|
-
export {
|
|
1323
|
+
export { hasTailwindSourceDirectives as a, hasTailwindRootDirectives as i, validateCandidatesByGenerator as n, hasTailwindGeneratedCssMarkers as o, processCachedTask as r, generateCssByGenerator as t };
|