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