weapp-tailwindcss 5.0.0-next.3 → 5.0.0-next.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -5
- package/bin/weapp-tailwindcss.js +1 -21
- 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 +11 -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 +12 -22
- 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 +2 -1
- package/dist/bundlers/vite/index.d.ts +1 -1
- package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
- package/dist/bundlers/vite/postcss-config.d.ts +6 -0
- package/dist/bundlers/vite/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 +0 -1
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +1 -1
- package/dist/cache-DPN5yKSX.js +497 -0
- package/dist/cache-nq0_XJoS.mjs +429 -0
- package/dist/cli/context.d.ts +0 -3
- package/dist/cli/helpers.d.ts +1 -2
- package/dist/cli/mount-options.d.ts +2 -0
- package/dist/cli/types.d.ts +0 -2
- package/dist/cli.js +108 -598
- package/dist/cli.mjs +119 -608
- package/dist/constants.d.ts +1 -2
- 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.d.ts +1 -0
- 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 +33 -14
- package/dist/defaults.mjs +30 -15
- package/dist/generator/index.d.ts +1 -1
- package/dist/generator/options.d.ts +3 -4
- package/dist/{generator-Y-Ikv4Fu.mjs → generator-CzfdCZyd.mjs} +277 -23
- package/dist/{generator-mmhXzZnv.js → generator-TOp4uz7c.js} +281 -27
- package/dist/{generator-css-Bwy_Uz89.mjs → generator-css-B938WI9a.mjs} +694 -506
- package/dist/{generator-css-CRLrHW4F.js → generator-css-Dnpl-IY2.js} +699 -505
- package/dist/generator.js +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/gulp.js +29 -28
- package/dist/gulp.mjs +25 -24
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/index.mjs +5 -5
- package/dist/js/index.d.ts +1 -0
- package/dist/js/literal-transform.d.ts +2 -0
- 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-BtAP6sQO.mjs +288 -0
- package/dist/postcss-WsXlC7A-.js +298 -0
- package/dist/postcss.d.ts +2 -2
- package/dist/postcss.js +3 -276
- package/dist/postcss.mjs +1 -269
- package/dist/{recorder-GdTJ3QqX.js → precheck-Dka94ArV.js} +141 -283
- package/dist/{recorder-XdFvVASS.mjs → precheck-DlrmwCc-.mjs} +106 -247
- package/dist/presets.js +6 -4
- package/dist/presets.mjs +4 -2
- package/dist/reset.d.ts +1 -0
- package/dist/{css-imports-BbrbluP9.js → run-tasks-B50A3pxt.js} +6 -55
- package/dist/{css-imports-CSdPq_Sc.mjs → run-tasks-DdNi-hkk.mjs} +5 -42
- package/dist/runtime-patch-pGdCqAEu.mjs +71 -0
- package/dist/runtime-patch-qwuisukL.js +85 -0
- package/dist/tailwindcss/miniprogram.d.ts +5 -1
- package/dist/tailwindcss/patcher-options.d.ts +3 -51
- package/dist/tailwindcss/patcher.d.ts +1 -2
- package/dist/tailwindcss/runtime-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/patcher-options.d.ts +1 -23
- package/dist/tailwindcss/v4/patcher.d.ts +2 -1
- package/dist/tailwindcss/v4-engine/types.d.ts +1 -1
- package/dist/tailwindcss/version.d.ts +4 -0
- package/dist/{logger-BoVx1Dbt.mjs → tailwindcss-BIJ185GB.mjs} +25 -434
- package/dist/{logger-BZ45DZJT.js → tailwindcss-T1U5T-iF.js} +30 -468
- package/dist/typedoc.export.d.ts +0 -2
- package/dist/types/index.d.ts +2 -9
- package/dist/types/shared.d.ts +3 -0
- package/dist/types/user-defined-options/general.d.ts +0 -2
- package/dist/types/user-defined-options/important.d.ts +3 -3
- package/dist/uni-app-x/vite.d.ts +1 -1
- package/dist/utils/disabled.d.ts +2 -3
- package/dist/{vite-BDywuCjn.mjs → vite-BXChkciE.mjs} +669 -481
- package/dist/{vite-DgRh_GXn.js → vite-D0CoRblu.js} +707 -519
- package/dist/vite.d.ts +1 -2
- package/dist/vite.js +3 -4
- package/dist/vite.mjs +2 -2
- package/dist/weapp-tw-css-import-rewrite-loader.js +1 -1
- package/dist/{webpack-CiHqVZTg.mjs → webpack-BNdGm9KL.mjs} +224 -38
- package/dist/{webpack-CAJR4hhP.js → webpack-D-sUCY0u.js} +250 -69
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +23 -35
- package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
- package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
- package/dist/cli/config.d.ts +0 -5
- package/dist/cli/helpers/patch-cwd.d.ts +0 -1
- package/dist/cli/mount-options/patch-status.d.ts +0 -2
- package/dist/cli/patch-options.d.ts +0 -6
- package/dist/cli/tokens.d.ts +0 -4
- package/dist/cli/workspace/package-dirs.d.ts +0 -3
- package/dist/cli/workspace/patch-package.d.ts +0 -3
- package/dist/cli/workspace/patch-utils.d.ts +0 -3
- package/dist/cli/workspace/types.d.ts +0 -11
- package/dist/cli/workspace/workspace-globs.d.ts +0 -2
- package/dist/cli/workspace/workspace-io.d.ts +0 -1
- package/dist/cli/workspace/workspace-lock.d.ts +0 -1
- package/dist/cli/workspace.d.ts +0 -2
- package/dist/experimental/index.d.ts +0 -2
- package/dist/experimental/oxc/ast-utils.d.ts +0 -30
- package/dist/experimental/oxc/index.d.ts +0 -2
- package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
- package/dist/experimental/shared/cache.d.ts +0 -3
- package/dist/experimental/shared/transform.d.ts +0 -3
- package/dist/experimental/shared.d.ts +0 -8
- package/dist/experimental/swc/ast-utils.d.ts +0 -30
- package/dist/experimental/swc/index.d.ts +0 -2
- package/dist/experimental/swc/module-specifiers.d.ts +0 -2
- package/dist/js/syntax.d.ts +0 -10
- package/dist/loader-anchors-1MumTAtA.mjs +0 -205
- package/dist/loader-anchors-TrFvT6g1.js +0 -273
- package/dist/patcher-options-6gJN2EXy.js +0 -115
- package/dist/patcher-options-DQfR5xxT.mjs +0 -92
- package/dist/tailwindcss/recorder.d.ts +0 -13
- package/dist/tailwindcss/targets/paths.d.ts +0 -13
- package/dist/tailwindcss/targets/record-io.d.ts +0 -5
- package/dist/tailwindcss/targets/recorder.d.ts +0 -3
- package/dist/tailwindcss/targets/types.d.ts +0 -35
- package/dist/types/disabled-options.d.ts +0 -4
- package/dist/webpack4.d.ts +0 -4
- package/dist/webpack4.js +0 -387
- package/dist/webpack4.mjs +0 -379
- package/scripts/postinstall.mjs +0 -59
- /package/dist/{constants-p1dyh1x1.js → constants-BoB_6lFw.js} +0 -0
- /package/dist/{constants-B-_T5UnW.mjs → constants-E_loJC49.mjs} +0 -0
- /package/dist/{utils-7DUGTFED.mjs → utils-BJjKRQgf.mjs} +0 -0
- /package/dist/{utils-DmC9_In3.js → utils-VZvGusYs.js} +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-TOp4uz7c.js");
|
|
3
|
+
const require_precheck = require("./precheck-Dka94ArV.js");
|
|
4
4
|
let postcss = require("postcss");
|
|
5
5
|
postcss = require_chunk.__toESM(postcss);
|
|
6
6
|
let node_path = require("node:path");
|
|
@@ -27,7 +27,69 @@ async function processCachedTask({ cache, cacheKey, hashKey = cacheKey, rawSourc
|
|
|
27
27
|
if (!cacheHit) await applyResult(result);
|
|
28
28
|
}
|
|
29
29
|
//#endregion
|
|
30
|
-
//#region src/bundlers/shared/css-cleanup.ts
|
|
30
|
+
//#region src/bundlers/shared/css-cleanup/at-rules.ts
|
|
31
|
+
const MINI_PROGRAM_UNSUPPORTED_AT_RULES = new Set(["property", "supports"]);
|
|
32
|
+
function removeAtRulesByScan(css, names) {
|
|
33
|
+
let index = 0;
|
|
34
|
+
let result = "";
|
|
35
|
+
const atRulePattern = new RegExp(`@(?:${[...names].join("|")})\\b`, "i");
|
|
36
|
+
while (index < css.length) {
|
|
37
|
+
const match = atRulePattern.exec(css.slice(index));
|
|
38
|
+
if (!match || match.index === void 0) {
|
|
39
|
+
result += css.slice(index);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
const start = index + match.index;
|
|
43
|
+
result += css.slice(index, start);
|
|
44
|
+
const blockStart = css.indexOf("{", start);
|
|
45
|
+
if (blockStart === -1) {
|
|
46
|
+
result += css.slice(start);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
let depth = 0;
|
|
50
|
+
let cursor = blockStart;
|
|
51
|
+
for (; cursor < css.length; cursor++) {
|
|
52
|
+
const char = css[cursor];
|
|
53
|
+
if (char === "{") depth++;
|
|
54
|
+
else if (char === "}") {
|
|
55
|
+
depth--;
|
|
56
|
+
if (depth === 0) {
|
|
57
|
+
cursor++;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
index = cursor;
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
function removeUnsupportedMiniProgramAtRules(css) {
|
|
67
|
+
try {
|
|
68
|
+
const root = postcss.default.parse(css);
|
|
69
|
+
root.walkAtRules((atRule) => {
|
|
70
|
+
if (MINI_PROGRAM_UNSUPPORTED_AT_RULES.has(atRule.name)) atRule.remove();
|
|
71
|
+
});
|
|
72
|
+
root.walkAtRules((atRule) => {
|
|
73
|
+
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
74
|
+
});
|
|
75
|
+
return root.toString();
|
|
76
|
+
} catch {
|
|
77
|
+
return removeAtRulesByScan(css, MINI_PROGRAM_UNSUPPORTED_AT_RULES);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/bundlers/shared/css-cleanup/color-gamut.ts
|
|
82
|
+
const DISPLAY_P3_VALUE_RE = /color\(\s*display-p3\b/i;
|
|
83
|
+
const COLOR_GAMUT_P3_RE = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
|
|
84
|
+
function isDisplayP3MediaRule(atRule) {
|
|
85
|
+
return atRule.name === "media" && COLOR_GAMUT_P3_RE.test(atRule.params);
|
|
86
|
+
}
|
|
87
|
+
function isDisplayP3Declaration(decl) {
|
|
88
|
+
return DISPLAY_P3_VALUE_RE.test(decl.value);
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/bundlers/shared/css-cleanup/selectors.ts
|
|
92
|
+
const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
|
|
31
93
|
const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
|
|
32
94
|
"*",
|
|
33
95
|
"view",
|
|
@@ -37,7 +99,6 @@ const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
|
|
|
37
99
|
"::before",
|
|
38
100
|
"::after"
|
|
39
101
|
]);
|
|
40
|
-
const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
|
|
41
102
|
const MINI_PROGRAM_THEME_SCOPE_SELECTORS$1 = new Set([
|
|
42
103
|
":host",
|
|
43
104
|
":root",
|
|
@@ -113,6 +174,75 @@ const MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS = new Set([
|
|
|
113
174
|
"ul",
|
|
114
175
|
"video"
|
|
115
176
|
]);
|
|
177
|
+
function normalizeSelector(selector) {
|
|
178
|
+
return selector.trim().replace(/\s+/g, "");
|
|
179
|
+
}
|
|
180
|
+
function getRuleSelectors(rule) {
|
|
181
|
+
return rule.selector.split(",").map(normalizeSelector).filter(Boolean);
|
|
182
|
+
}
|
|
183
|
+
function isUnsupportedBrowserSelector(selector) {
|
|
184
|
+
const normalized = normalizeSelector(selector);
|
|
185
|
+
return MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS.has(normalized) || MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS.has(normalized);
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/bundlers/shared/css-cleanup/root-cleanups.ts
|
|
189
|
+
function removeSpecificityPlaceholders(root) {
|
|
190
|
+
root.walkRules((rule) => {
|
|
191
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
192
|
+
let changed = false;
|
|
193
|
+
const selectors = rule.selectors.map((selector) => {
|
|
194
|
+
let next = selector;
|
|
195
|
+
for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (next.includes(suffix)) next = next.split(suffix).join("");
|
|
196
|
+
if (next !== selector) changed = true;
|
|
197
|
+
return next;
|
|
198
|
+
});
|
|
199
|
+
if (changed) rule.selectors = selectors;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function removeEmptyAtRuleAncestors(parent) {
|
|
203
|
+
while (parent?.type === "atrule" && (!parent.nodes || parent.nodes.length === 0)) {
|
|
204
|
+
const nextParent = parent.parent;
|
|
205
|
+
parent.remove();
|
|
206
|
+
parent = nextParent;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function removeUnsupportedBrowserSelectors(root) {
|
|
210
|
+
root.walkRules((rule) => {
|
|
211
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
212
|
+
const selectors = rule.selectors.filter((selector) => !isUnsupportedBrowserSelector(selector));
|
|
213
|
+
if (selectors.length === rule.selectors.length) return;
|
|
214
|
+
if (selectors.length === 0) {
|
|
215
|
+
const parent = rule.parent;
|
|
216
|
+
rule.remove();
|
|
217
|
+
removeEmptyAtRuleAncestors(parent);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
rule.selectors = selectors;
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
function removeDeclarationAndEmptyRule(decl) {
|
|
224
|
+
const parent = decl.parent;
|
|
225
|
+
decl.remove();
|
|
226
|
+
if (parent?.type === "rule" && parent.nodes.length === 0) {
|
|
227
|
+
const ruleParent = parent.parent;
|
|
228
|
+
parent.remove();
|
|
229
|
+
removeEmptyAtRuleAncestors(ruleParent);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function removeDisplayP3Declarations(root) {
|
|
233
|
+
root.walkAtRules((atRule) => {
|
|
234
|
+
if (isDisplayP3MediaRule(atRule)) {
|
|
235
|
+
const parent = atRule.parent;
|
|
236
|
+
atRule.remove();
|
|
237
|
+
removeEmptyAtRuleAncestors(parent);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
root.walkDecls((decl) => {
|
|
241
|
+
if (isDisplayP3Declaration(decl)) removeDeclarationAndEmptyRule(decl);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region src/bundlers/shared/css-cleanup.ts
|
|
116
246
|
const PREFLIGHT_RESET_PROPS = new Set([
|
|
117
247
|
"box-sizing",
|
|
118
248
|
"border",
|
|
@@ -122,63 +252,6 @@ const PREFLIGHT_RESET_PROPS = new Set([
|
|
|
122
252
|
"margin",
|
|
123
253
|
"padding"
|
|
124
254
|
]);
|
|
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
|
-
function normalizeSelector(selector) {
|
|
177
|
-
return selector.trim().replace(/\s+/g, "");
|
|
178
|
-
}
|
|
179
|
-
function getRuleSelectors(rule) {
|
|
180
|
-
return rule.selector.split(",").map(normalizeSelector).filter(Boolean);
|
|
181
|
-
}
|
|
182
255
|
function isMiniProgramThemeScopeSelector$1(selectors) {
|
|
183
256
|
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_THEME_SCOPE_SELECTORS$1.has(selector));
|
|
184
257
|
}
|
|
@@ -227,71 +300,6 @@ function createPseudoContentInitRule() {
|
|
|
227
300
|
});
|
|
228
301
|
return rule;
|
|
229
302
|
}
|
|
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);
|
|
235
|
-
}
|
|
236
|
-
function removeSpecificityPlaceholders(root) {
|
|
237
|
-
root.walkRules((rule) => {
|
|
238
|
-
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
239
|
-
let changed = false;
|
|
240
|
-
const selectors = rule.selectors.map((selector) => {
|
|
241
|
-
let next = selector;
|
|
242
|
-
for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (next.includes(suffix)) next = next.split(suffix).join("");
|
|
243
|
-
if (next !== selector) changed = true;
|
|
244
|
-
return next;
|
|
245
|
-
});
|
|
246
|
-
if (changed) rule.selectors = selectors;
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
function isUnsupportedBrowserSelector(selector) {
|
|
250
|
-
const normalized = normalizeSelector(selector);
|
|
251
|
-
return MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS.has(normalized) || MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS.has(normalized);
|
|
252
|
-
}
|
|
253
|
-
function removeUnsupportedBrowserSelectors(root) {
|
|
254
|
-
root.walkRules((rule) => {
|
|
255
|
-
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
256
|
-
const selectors = rule.selectors.filter((selector) => !isUnsupportedBrowserSelector(selector));
|
|
257
|
-
if (selectors.length === rule.selectors.length) return;
|
|
258
|
-
if (selectors.length === 0) {
|
|
259
|
-
const parent = rule.parent;
|
|
260
|
-
rule.remove();
|
|
261
|
-
removeEmptyAtRuleAncestors(parent);
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
rule.selectors = selectors;
|
|
265
|
-
});
|
|
266
|
-
}
|
|
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
|
-
function removeDeclarationAndEmptyRule(decl) {
|
|
275
|
-
const parent = decl.parent;
|
|
276
|
-
decl.remove();
|
|
277
|
-
if (parent?.type === "rule" && parent.nodes.length === 0) {
|
|
278
|
-
const ruleParent = parent.parent;
|
|
279
|
-
parent.remove();
|
|
280
|
-
removeEmptyAtRuleAncestors(ruleParent);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
function removeDisplayP3Declarations(root) {
|
|
284
|
-
root.walkAtRules((atRule) => {
|
|
285
|
-
if (isDisplayP3MediaRule(atRule)) {
|
|
286
|
-
const parent = atRule.parent;
|
|
287
|
-
atRule.remove();
|
|
288
|
-
removeEmptyAtRuleAncestors(parent);
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
root.walkDecls((decl) => {
|
|
292
|
-
if (isDisplayP3Declaration(decl)) removeDeclarationAndEmptyRule(decl);
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
303
|
function collectPreflightRules(root) {
|
|
296
304
|
const preflightNodes = [];
|
|
297
305
|
let hasContentInit = false;
|
|
@@ -365,7 +373,7 @@ function finalizeMiniProgramCss(css) {
|
|
|
365
373
|
}
|
|
366
374
|
}
|
|
367
375
|
//#endregion
|
|
368
|
-
//#region src/bundlers/shared/generator-css.ts
|
|
376
|
+
//#region src/bundlers/shared/generator-css/markers.ts
|
|
369
377
|
const TAILWIND_V4_BANNER_RE = /\/\*!\s*tailwindcss v4\./;
|
|
370
378
|
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
379
|
const GENERATOR_PLACEHOLDER_MARKER_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\//i;
|
|
@@ -373,77 +381,6 @@ const GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE = /\/\*!\s*weapp-tailwindcss genera
|
|
|
373
381
|
const TAILWIND_BANNER_PREFIX_RE = /^\/\*!\s*tailwindcss v[^*]*\*\/\s*/i;
|
|
374
382
|
const TAILWIND_BANNER_GLOBAL_RE = /\/\*!\s*tailwindcss v[^*]*\*\/\s*/gi;
|
|
375
383
|
const VITE_MARKER_RE = /\/\*\$vite\$:[^*]*\*\//g;
|
|
376
|
-
const CLASS_SELECTOR_RE = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
377
|
-
const MINI_PROGRAM_THEME_SCOPE_SELECTORS = new Set([
|
|
378
|
-
":host",
|
|
379
|
-
"page",
|
|
380
|
-
".tw-root",
|
|
381
|
-
"wx-root-portal-content"
|
|
382
|
-
]);
|
|
383
|
-
const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
|
|
384
|
-
const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
|
|
385
|
-
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
384
|
function createCssAppend(base, extra) {
|
|
448
385
|
if (!base) return extra;
|
|
449
386
|
if (!extra) return base;
|
|
@@ -473,132 +410,28 @@ function hasTailwindGeneratedCss(rawSource) {
|
|
|
473
410
|
function hasTailwindGeneratedCssMarkers(rawSource) {
|
|
474
411
|
return TAILWIND_GENERATED_CSS_MARKER_RE.test(rawSource) || GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
|
|
475
412
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
let result = "";
|
|
491
|
-
let index = 0;
|
|
492
|
-
let changed = false;
|
|
493
|
-
while (index < selector.length) {
|
|
494
|
-
const char = selector[index];
|
|
495
|
-
if (char !== ".") {
|
|
496
|
-
result += char;
|
|
497
|
-
index += 1;
|
|
498
|
-
continue;
|
|
499
|
-
}
|
|
500
|
-
let end = index + 1;
|
|
501
|
-
let className = "";
|
|
502
|
-
while (end < selector.length) {
|
|
503
|
-
const current = selector[end];
|
|
504
|
-
if (current === "\\" && end + 1 < selector.length) {
|
|
505
|
-
className += current + selector[end + 1];
|
|
506
|
-
end += 2;
|
|
507
|
-
continue;
|
|
508
|
-
}
|
|
509
|
-
if (isClassSelectorTerminator(current)) break;
|
|
510
|
-
className += current;
|
|
511
|
-
end += 1;
|
|
512
|
-
}
|
|
513
|
-
if (className.includes("\\")) {
|
|
514
|
-
result += `.${require_recorder.replaceWxml(unescapeSimpleCssIdent(className))}`;
|
|
515
|
-
changed = true;
|
|
516
|
-
} else result += `.${className}`;
|
|
517
|
-
index = end;
|
|
518
|
-
}
|
|
519
|
-
return changed ? result : selector;
|
|
520
|
-
}
|
|
521
|
-
function normalizeCompatSelectors(selector) {
|
|
522
|
-
const normalized = normalizeCompatSelector(selector);
|
|
523
|
-
if (!normalized) return [];
|
|
524
|
-
const selectors = new Set([normalized]);
|
|
525
|
-
const escaped = normalizeCompatSelector(escapeCompatSelectorClasses(normalized));
|
|
526
|
-
if (escaped) selectors.add(escaped);
|
|
527
|
-
return [...selectors];
|
|
528
|
-
}
|
|
529
|
-
function createLegacyDeclarationValueMap(css) {
|
|
530
|
-
const values = /* @__PURE__ */ new Map();
|
|
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
|
-
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
|
-
...generatorStyleOptions
|
|
587
|
-
};
|
|
588
|
-
}
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region src/bundlers/shared/generator-css/directives.ts
|
|
415
|
+
const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = new Set([
|
|
416
|
+
"config",
|
|
417
|
+
"custom-variant",
|
|
418
|
+
"layer",
|
|
419
|
+
"plugin",
|
|
420
|
+
"reference",
|
|
421
|
+
"source",
|
|
422
|
+
"tailwind",
|
|
423
|
+
"theme",
|
|
424
|
+
"utility",
|
|
425
|
+
"variant"
|
|
426
|
+
]);
|
|
589
427
|
function parseImportRequest(params) {
|
|
590
428
|
return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
|
|
591
429
|
}
|
|
592
430
|
function parseConfigRequest(params) {
|
|
593
431
|
return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
|
|
594
432
|
}
|
|
595
|
-
function
|
|
596
|
-
|
|
597
|
-
return typeof from === "string" && from.length > 0 ? from : void 0;
|
|
598
|
-
}
|
|
599
|
-
function resolveCssSourceBase(file, cssHandlerOptions) {
|
|
600
|
-
const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
|
|
601
|
-
return node_path.default.dirname(node_path.default.resolve(normalized));
|
|
433
|
+
function isPackageJsonImportRequest(request) {
|
|
434
|
+
return typeof request === "string" && request.startsWith("#");
|
|
602
435
|
}
|
|
603
436
|
function isTailwindImportAtRule(node) {
|
|
604
437
|
if (node.name === "tailwind") return true;
|
|
@@ -609,11 +442,13 @@ function isTailwindImportAtRule(node) {
|
|
|
609
442
|
function isTailwindSourceDirective(node) {
|
|
610
443
|
if (node.type !== "atrule") return false;
|
|
611
444
|
if (isTailwindImportAtRule(node)) return true;
|
|
445
|
+
if (node.name === "import" && isPackageJsonImportRequest(parseImportRequest(node.params))) return true;
|
|
612
446
|
return TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES.has(node.name);
|
|
613
447
|
}
|
|
614
448
|
function isTailwindGenerationDirective(node) {
|
|
615
449
|
if (node.type !== "atrule") return false;
|
|
616
|
-
|
|
450
|
+
const request = node.name === "import" ? parseImportRequest(node.params) : node.name === "config" || node.name === "plugin" || node.name === "reference" ? parseConfigRequest(node.params) : void 0;
|
|
451
|
+
return isTailwindImportAtRule(node) || isPackageJsonImportRequest(request) || node.name === "apply" || node.name === "layer" || node.name === "config" || node.name === "source";
|
|
617
452
|
}
|
|
618
453
|
function removeTailwindSourceDirectives(rawSource) {
|
|
619
454
|
try {
|
|
@@ -661,7 +496,7 @@ function resolveCssEntrySource(rawSource, base, options = {}) {
|
|
|
661
496
|
const configPath = parseConfigRequest(node.params);
|
|
662
497
|
if (configPath && !config) {
|
|
663
498
|
configRequest = configPath;
|
|
664
|
-
config = node_path.default.isAbsolute(configPath) ? configPath : node_path.default.resolve(base, configPath);
|
|
499
|
+
config = isPackageJsonImportRequest(configPath) ? void 0 : node_path.default.isAbsolute(configPath) ? configPath : node_path.default.resolve(base, configPath);
|
|
665
500
|
}
|
|
666
501
|
if (removeConfig) {
|
|
667
502
|
node.remove();
|
|
@@ -680,26 +515,223 @@ function resolveCssEntrySource(rawSource, base, options = {}) {
|
|
|
680
515
|
return;
|
|
681
516
|
}
|
|
682
517
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
518
|
+
//#endregion
|
|
519
|
+
//#region src/bundlers/shared/generator-css/legacy-selectors.ts
|
|
520
|
+
const CLASS_SELECTOR_RE = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
521
|
+
const MINI_PROGRAM_THEME_SCOPE_SELECTORS = new Set([
|
|
522
|
+
":host",
|
|
523
|
+
"page",
|
|
524
|
+
".tw-root",
|
|
525
|
+
"wx-root-portal-content"
|
|
526
|
+
]);
|
|
527
|
+
const SPECIFICITY_PLACEHOLDER_RE = /:not\(#(?:\\#|n)\)/g;
|
|
528
|
+
function normalizeCompatSelector(selector) {
|
|
529
|
+
return selector.replace(SPECIFICITY_PLACEHOLDER_RE, "").replace(/\s+/g, " ").trim();
|
|
530
|
+
}
|
|
531
|
+
function isClassSelectorTerminator(char) {
|
|
532
|
+
return /[\s>+~#,.:()[\]]/.test(char);
|
|
533
|
+
}
|
|
534
|
+
function unescapeSimpleCssIdent(value) {
|
|
535
|
+
return value.replaceAll(/\\(.)/g, "$1");
|
|
536
|
+
}
|
|
537
|
+
function escapeCompatSelectorClasses(selector) {
|
|
538
|
+
let result = "";
|
|
539
|
+
let index = 0;
|
|
540
|
+
let changed = false;
|
|
541
|
+
while (index < selector.length) {
|
|
542
|
+
const char = selector[index];
|
|
543
|
+
if (char !== ".") {
|
|
544
|
+
result += char;
|
|
545
|
+
index += 1;
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
let end = index + 1;
|
|
549
|
+
let className = "";
|
|
550
|
+
while (end < selector.length) {
|
|
551
|
+
const current = selector[end];
|
|
552
|
+
if (current === "\\" && end + 1 < selector.length) {
|
|
553
|
+
className += current + selector[end + 1];
|
|
554
|
+
end += 2;
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
557
|
+
if (isClassSelectorTerminator(current)) break;
|
|
558
|
+
className += current;
|
|
559
|
+
end += 1;
|
|
560
|
+
}
|
|
561
|
+
if (className.includes("\\")) {
|
|
562
|
+
result += `.${require_precheck.replaceWxml(unescapeSimpleCssIdent(className))}`;
|
|
563
|
+
changed = true;
|
|
564
|
+
} else result += `.${className}`;
|
|
565
|
+
index = end;
|
|
700
566
|
}
|
|
701
|
-
return
|
|
567
|
+
return changed ? result : selector;
|
|
568
|
+
}
|
|
569
|
+
function normalizeCompatSelectors(selector) {
|
|
570
|
+
const normalized = normalizeCompatSelector(selector);
|
|
571
|
+
if (!normalized) return [];
|
|
572
|
+
const selectors = new Set([normalized]);
|
|
573
|
+
const escaped = normalizeCompatSelector(escapeCompatSelectorClasses(normalized));
|
|
574
|
+
if (escaped) selectors.add(escaped);
|
|
575
|
+
return [...selectors];
|
|
576
|
+
}
|
|
577
|
+
function normalizeCssSelector(selector) {
|
|
578
|
+
return selector.trim().replace(/\s+/g, "");
|
|
579
|
+
}
|
|
580
|
+
function getCompatSelectorKeys(selector) {
|
|
581
|
+
return normalizeCompatSelectors(selector).map(normalizeCssSelector);
|
|
582
|
+
}
|
|
583
|
+
function getRuleCompatSelectorKeys(rule) {
|
|
584
|
+
return (rule.selectors?.length ? rule.selectors : [rule.selector]).flatMap((selector) => getCompatSelectorKeys(selector));
|
|
585
|
+
}
|
|
586
|
+
function hasClassSelector(selector) {
|
|
587
|
+
return CLASS_SELECTOR_RE.test(selector);
|
|
588
|
+
}
|
|
589
|
+
function getNormalizedSelectorList(selector) {
|
|
590
|
+
return selector.split(",").map(normalizeCssSelector).filter(Boolean);
|
|
591
|
+
}
|
|
592
|
+
function isMiniProgramThemeScopeSelector(selector) {
|
|
593
|
+
const selectors = getNormalizedSelectorList(selector);
|
|
594
|
+
return selectors.length > 0 && selectors.every((item) => MINI_PROGRAM_THEME_SCOPE_SELECTORS.has(item));
|
|
595
|
+
}
|
|
596
|
+
function hasUtilityClassSelector(selector) {
|
|
597
|
+
return hasClassSelector(selector) && !isMiniProgramThemeScopeSelector(selector);
|
|
598
|
+
}
|
|
599
|
+
function isCustomPropertyOnlyRule(rule) {
|
|
600
|
+
let hasDeclaration = false;
|
|
601
|
+
let allCustomProperties = true;
|
|
602
|
+
rule.each((node) => {
|
|
603
|
+
if (node.type !== "decl") return;
|
|
604
|
+
hasDeclaration = true;
|
|
605
|
+
if (!node.prop.startsWith("--")) allCustomProperties = false;
|
|
606
|
+
});
|
|
607
|
+
return hasDeclaration && allCustomProperties;
|
|
608
|
+
}
|
|
609
|
+
function isPseudoContentInitRule(rule) {
|
|
610
|
+
let hasDeclaration = false;
|
|
611
|
+
let onlyContentVariable = true;
|
|
612
|
+
rule.each((node) => {
|
|
613
|
+
if (node.type !== "decl") return;
|
|
614
|
+
hasDeclaration = true;
|
|
615
|
+
if (node.prop !== "--tw-content") onlyContentVariable = false;
|
|
616
|
+
});
|
|
617
|
+
return hasDeclaration && onlyContentVariable;
|
|
618
|
+
}
|
|
619
|
+
function collectGeneratedSelectors(css) {
|
|
620
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
621
|
+
try {
|
|
622
|
+
postcss.default.parse(css).walkRules((rule) => {
|
|
623
|
+
if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
|
|
624
|
+
for (const selector of getRuleCompatSelectorKeys(rule)) selectors.add(selector);
|
|
625
|
+
});
|
|
626
|
+
} catch {
|
|
627
|
+
return selectors;
|
|
628
|
+
}
|
|
629
|
+
return selectors;
|
|
702
630
|
}
|
|
631
|
+
function removeGeneratedSelectorCompatCss(css, generatedCss) {
|
|
632
|
+
const generatedSelectors = collectGeneratedSelectors(generatedCss);
|
|
633
|
+
if (generatedSelectors.size === 0) return css;
|
|
634
|
+
try {
|
|
635
|
+
const root = postcss.default.parse(css);
|
|
636
|
+
let removed = false;
|
|
637
|
+
root.walkRules((rule) => {
|
|
638
|
+
if (isPseudoContentInitRule(rule)) {
|
|
639
|
+
rule.remove();
|
|
640
|
+
removed = true;
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
|
|
644
|
+
if (getRuleCompatSelectorKeys(rule).some((selector) => generatedSelectors.has(selector))) {
|
|
645
|
+
rule.remove();
|
|
646
|
+
removed = true;
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
root.walkAtRules((atRule) => {
|
|
650
|
+
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
651
|
+
});
|
|
652
|
+
return removed ? root.toString() : css;
|
|
653
|
+
} catch {
|
|
654
|
+
return css;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function collectDedupedPostTransformCompatCss(css, generatedCss) {
|
|
658
|
+
const generatedSelectors = collectGeneratedSelectors(generatedCss);
|
|
659
|
+
if (generatedSelectors.size === 0) return css;
|
|
660
|
+
const preservedNodes = [];
|
|
661
|
+
try {
|
|
662
|
+
const root = postcss.default.parse(css);
|
|
663
|
+
root.each((node) => {
|
|
664
|
+
if (node.type === "rule" && getRuleCompatSelectorKeys(node).some((selector) => generatedSelectors.has(selector))) {
|
|
665
|
+
if (isCustomPropertyOnlyRule(node) && !isPseudoContentInitRule(node) && !hasUtilityClassSelector(node.selector)) {
|
|
666
|
+
const declarationProps = /* @__PURE__ */ new Set();
|
|
667
|
+
node.walkDecls((decl) => {
|
|
668
|
+
declarationProps.add(decl.prop);
|
|
669
|
+
});
|
|
670
|
+
postcss.default.parse(generatedCss).walkRules((rule) => {
|
|
671
|
+
const nodeSelectors = new Set(getRuleCompatSelectorKeys(node));
|
|
672
|
+
if (!getRuleCompatSelectorKeys(rule).some((selector) => nodeSelectors.has(selector))) return;
|
|
673
|
+
rule.walkDecls((decl) => {
|
|
674
|
+
declarationProps.delete(decl.prop);
|
|
675
|
+
});
|
|
676
|
+
});
|
|
677
|
+
const nextRule = node.clone();
|
|
678
|
+
nextRule.walkDecls((decl) => {
|
|
679
|
+
if (!declarationProps.has(decl.prop)) decl.remove();
|
|
680
|
+
});
|
|
681
|
+
if (nextRule.nodes.length > 0) preservedNodes.push(nextRule);
|
|
682
|
+
}
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
preservedNodes.push(node.clone());
|
|
686
|
+
});
|
|
687
|
+
if (preservedNodes.length === root.nodes.length) return css;
|
|
688
|
+
const nextRoot = postcss.default.root();
|
|
689
|
+
nextRoot.append(preservedNodes);
|
|
690
|
+
return nextRoot.toString();
|
|
691
|
+
} catch {
|
|
692
|
+
return css;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
function removeDuplicatedViteMarkers(css, baseCss) {
|
|
696
|
+
if (!VITE_MARKER_RE.test(baseCss)) return css;
|
|
697
|
+
VITE_MARKER_RE.lastIndex = 0;
|
|
698
|
+
return css.replace(VITE_MARKER_RE, "");
|
|
699
|
+
}
|
|
700
|
+
//#endregion
|
|
701
|
+
//#region src/bundlers/shared/generator-css/config-directive.ts
|
|
702
|
+
function quoteCssString(value) {
|
|
703
|
+
return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
|
|
704
|
+
}
|
|
705
|
+
function toCssPath(value) {
|
|
706
|
+
return value.replaceAll("\\", "/");
|
|
707
|
+
}
|
|
708
|
+
function prependConfigDirective(css, config) {
|
|
709
|
+
if (!config || /@config\s+/.test(css)) return css;
|
|
710
|
+
return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
|
|
711
|
+
}
|
|
712
|
+
function normalizeConfigDirective(css, config) {
|
|
713
|
+
if (!config || !/@config\s+/.test(css)) return css;
|
|
714
|
+
return css.replace(/@config\s+(["'])(.+?)\1\s*;?/, `@config "${quoteCssString(toCssPath(config))}";`);
|
|
715
|
+
}
|
|
716
|
+
//#endregion
|
|
717
|
+
//#region src/bundlers/shared/generator-css/source-files.ts
|
|
718
|
+
const SOURCE_STYLE_EXTENSIONS = [
|
|
719
|
+
".vue",
|
|
720
|
+
".uvue",
|
|
721
|
+
".nvue",
|
|
722
|
+
".css",
|
|
723
|
+
".scss",
|
|
724
|
+
".sass",
|
|
725
|
+
".less",
|
|
726
|
+
".styl",
|
|
727
|
+
".stylus",
|
|
728
|
+
".wxss",
|
|
729
|
+
".acss",
|
|
730
|
+
".jxss",
|
|
731
|
+
".ttss",
|
|
732
|
+
".qss"
|
|
733
|
+
];
|
|
734
|
+
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
703
735
|
function stripStyleExtension(file) {
|
|
704
736
|
return file.replace(/[?#].*$/, "").replace(/\.(?:wx|ac|jx|tt|q|c|ty)?ss$/i, "");
|
|
705
737
|
}
|
|
@@ -753,9 +785,6 @@ function extractStyleDirectiveSources(source) {
|
|
|
753
785
|
if (styleSources.length > 0) return styleSources;
|
|
754
786
|
return hasTailwindSourceDirectives(source) ? [source] : [];
|
|
755
787
|
}
|
|
756
|
-
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
757
|
-
return rawSource.includes("@apply");
|
|
758
|
-
}
|
|
759
788
|
function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {}) {
|
|
760
789
|
for (const sourceFile of createSourceStylePathCandidates(file, sourceOptions)) {
|
|
761
790
|
if (!(0, node_fs.existsSync)(sourceFile)) continue;
|
|
@@ -770,6 +799,72 @@ function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {
|
|
|
770
799
|
}
|
|
771
800
|
}
|
|
772
801
|
}
|
|
802
|
+
//#endregion
|
|
803
|
+
//#region src/bundlers/shared/generator-css/source-resolver.ts
|
|
804
|
+
function resolvePostcssFromOption(cssHandlerOptions) {
|
|
805
|
+
const from = cssHandlerOptions.postcssOptions?.options?.from;
|
|
806
|
+
return typeof from === "string" && from.length > 0 ? from : void 0;
|
|
807
|
+
}
|
|
808
|
+
function resolveCssSourceBase(file, cssHandlerOptions) {
|
|
809
|
+
const normalized = (resolvePostcssFromOption(cssHandlerOptions) ?? file).replace(/[?#].*$/, "");
|
|
810
|
+
return node_path.default.dirname(node_path.default.resolve(normalized));
|
|
811
|
+
}
|
|
812
|
+
function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
|
|
813
|
+
if (config && (0, node_fs.existsSync)(config)) return config;
|
|
814
|
+
if (!configRequest || node_path.default.isAbsolute(configRequest)) return sourceOptions.config;
|
|
815
|
+
const outputDir = node_path.default.dirname(file.replace(/[?#].*$/, ""));
|
|
816
|
+
const baseCandidates = [
|
|
817
|
+
sourceOptions.projectRoot,
|
|
818
|
+
sourceOptions.cwd,
|
|
819
|
+
node_process.default.cwd()
|
|
820
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
821
|
+
for (const base of baseCandidates) {
|
|
822
|
+
const candidates = [
|
|
823
|
+
node_path.default.resolve(base, configRequest),
|
|
824
|
+
node_path.default.resolve(base, "src", configRequest),
|
|
825
|
+
node_path.default.resolve(base, outputDir, configRequest),
|
|
826
|
+
node_path.default.resolve(base, "src", outputDir, configRequest)
|
|
827
|
+
];
|
|
828
|
+
for (const candidate of candidates) if ((0, node_fs.existsSync)(candidate)) return candidate;
|
|
829
|
+
}
|
|
830
|
+
return sourceOptions.config;
|
|
831
|
+
}
|
|
832
|
+
function canResolveSourceSideCssEntry(file, cssHandlerOptions) {
|
|
833
|
+
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
834
|
+
if (!from || !node_path.default.isAbsolute(from)) return node_path.default.isAbsolute(file);
|
|
835
|
+
return true;
|
|
836
|
+
}
|
|
837
|
+
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
838
|
+
return rawSource.includes("@apply");
|
|
839
|
+
}
|
|
840
|
+
function normalizeCssSourceForCompare(css) {
|
|
841
|
+
return stripGeneratorPlaceholderMarkers(stripTailwindBanners(css)).trim();
|
|
842
|
+
}
|
|
843
|
+
function getOutputFileStem(file) {
|
|
844
|
+
const normalized = file.replace(/[?#].*$/, "");
|
|
845
|
+
return node_path.default.basename(normalized, node_path.default.extname(normalized));
|
|
846
|
+
}
|
|
847
|
+
function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
|
|
848
|
+
const cssEntries = sourceOptions.cssEntries;
|
|
849
|
+
if (!cssEntries?.length) return;
|
|
850
|
+
const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
|
|
851
|
+
const outputStem = getOutputFileStem(file);
|
|
852
|
+
const matchingEntry = cssEntries.find((cssEntry) => {
|
|
853
|
+
if (!(0, node_fs.existsSync)(cssEntry)) return false;
|
|
854
|
+
try {
|
|
855
|
+
if (normalizeCssSourceForCompare((0, node_fs.readFileSync)(cssEntry, "utf8")) === normalizedRawSource) return true;
|
|
856
|
+
return outputStem.length > 0 && getOutputFileStem(cssEntry) === outputStem;
|
|
857
|
+
} catch {
|
|
858
|
+
return false;
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
if (!matchingEntry) return;
|
|
862
|
+
return require_generator.resolveTailwindV4Source({
|
|
863
|
+
...sourceOptions,
|
|
864
|
+
css: void 0,
|
|
865
|
+
cssEntries: [matchingEntry]
|
|
866
|
+
});
|
|
867
|
+
}
|
|
773
868
|
function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
774
869
|
try {
|
|
775
870
|
return require_generator.resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
@@ -777,16 +872,20 @@ function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
|
777
872
|
return;
|
|
778
873
|
}
|
|
779
874
|
}
|
|
780
|
-
async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions) {
|
|
875
|
+
async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions) {
|
|
781
876
|
const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), { removeConfig: majorVersion === 3 });
|
|
782
877
|
if (majorVersion === 3) {
|
|
783
878
|
const sourceOptions = require_generator.resolveTailwindV3SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
784
|
-
const
|
|
879
|
+
const mergedSourceOptions = {
|
|
880
|
+
...sourceOptions,
|
|
881
|
+
config: generatorOptions?.config ?? sourceOptions.config
|
|
882
|
+
};
|
|
883
|
+
const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
|
|
785
884
|
const resolvedEntrySource = cssEntrySource ?? sourceSideEntrySource;
|
|
786
|
-
if (!resolvedEntrySource) return require_generator.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
|
|
787
|
-
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file,
|
|
885
|
+
if (!resolvedEntrySource) return generatorOptions?.config ? require_generator.resolveTailwindV3Source(mergedSourceOptions) : require_generator.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
|
|
886
|
+
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, mergedSourceOptions);
|
|
788
887
|
return require_generator.resolveTailwindV3Source({
|
|
789
|
-
...
|
|
888
|
+
...mergedSourceOptions,
|
|
790
889
|
base: resolvedEntrySource.base,
|
|
791
890
|
css: resolvedEntrySource.css,
|
|
792
891
|
...config ? { config } : {}
|
|
@@ -794,51 +893,105 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
794
893
|
}
|
|
795
894
|
const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
|
|
796
895
|
const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder"));
|
|
797
|
-
const
|
|
798
|
-
|
|
896
|
+
const sourceSideEntrySource = sourceOptions && shouldPreferSourceSideEntry ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0;
|
|
897
|
+
const matchedCssEntrySource = sourceOptions && cssEntrySource ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
|
|
898
|
+
const mainCssEntrySource = sourceOptions && cssHandlerOptions.isMainChunk && sourceOptions.cssEntries?.length === 1 ? await require_generator.resolveTailwindV4Source({
|
|
899
|
+
...sourceOptions,
|
|
900
|
+
css: void 0,
|
|
901
|
+
cssEntries: [sourceOptions.cssEntries[0]]
|
|
902
|
+
}) : void 0;
|
|
903
|
+
const preferredCssEntrySource = matchedCssEntrySource ?? mainCssEntrySource;
|
|
904
|
+
if (preferredCssEntrySource) return generatorOptions?.config ? {
|
|
905
|
+
...preferredCssEntrySource,
|
|
906
|
+
css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
907
|
+
} : preferredCssEntrySource;
|
|
908
|
+
const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource;
|
|
909
|
+
if (!resolvedEntrySource) {
|
|
910
|
+
const source = await require_generator.resolveTailwindV4SourceFromPatcher(runtimeState.twPatcher);
|
|
911
|
+
return generatorOptions?.config ? {
|
|
912
|
+
...source,
|
|
913
|
+
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
914
|
+
} : source;
|
|
915
|
+
}
|
|
916
|
+
const resolvedSourceOptions = sourceOptions ?? {};
|
|
917
|
+
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, resolvedSourceOptions);
|
|
799
918
|
return require_generator.resolveTailwindV4Source({
|
|
800
|
-
...
|
|
919
|
+
...resolvedSourceOptions,
|
|
801
920
|
base: resolvedEntrySource.base,
|
|
802
|
-
css: resolvedEntrySource.css
|
|
921
|
+
css: normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config)
|
|
803
922
|
});
|
|
804
923
|
}
|
|
805
|
-
async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions) {
|
|
924
|
+
async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions) {
|
|
806
925
|
const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), { removeConfig: majorVersion === 3 });
|
|
807
|
-
if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions)];
|
|
926
|
+
if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions)];
|
|
808
927
|
let sourceOptions;
|
|
809
928
|
try {
|
|
810
929
|
sourceOptions = require_generator.resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
811
930
|
} catch {
|
|
812
|
-
return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions)];
|
|
931
|
+
return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions)];
|
|
813
932
|
}
|
|
814
|
-
if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions)];
|
|
933
|
+
if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions)];
|
|
815
934
|
return await Promise.all(sourceOptions.cssEntries.map((cssEntry) => require_generator.resolveTailwindV4Source({
|
|
816
935
|
...sourceOptions,
|
|
817
936
|
css: void 0,
|
|
818
937
|
cssEntries: [cssEntry]
|
|
819
|
-
}))
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
938
|
+
}).then((source) => generatorOptions?.config ? {
|
|
939
|
+
...source,
|
|
940
|
+
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
941
|
+
} : source)));
|
|
823
942
|
}
|
|
824
|
-
|
|
825
|
-
|
|
943
|
+
//#endregion
|
|
944
|
+
//#region src/bundlers/shared/generator-css/legacy-compat.ts
|
|
945
|
+
const LEGACY_CONTAINER_COMPAT_CSS = [
|
|
946
|
+
".container {",
|
|
947
|
+
" width: 100%;",
|
|
948
|
+
"}",
|
|
949
|
+
"@media (min-width: 40rem) {",
|
|
950
|
+
" .container {",
|
|
951
|
+
" max-width: 40rem;",
|
|
952
|
+
" }",
|
|
953
|
+
"}",
|
|
954
|
+
"@media (min-width: 48rem) {",
|
|
955
|
+
" .container {",
|
|
956
|
+
" max-width: 48rem;",
|
|
957
|
+
" }",
|
|
958
|
+
"}",
|
|
959
|
+
"@media (min-width: 64rem) {",
|
|
960
|
+
" .container {",
|
|
961
|
+
" max-width: 64rem;",
|
|
962
|
+
" }",
|
|
963
|
+
"}",
|
|
964
|
+
"@media (min-width: 80rem) {",
|
|
965
|
+
" .container {",
|
|
966
|
+
" max-width: 80rem;",
|
|
967
|
+
" }",
|
|
968
|
+
"}",
|
|
969
|
+
"@media (min-width: 96rem) {",
|
|
970
|
+
" .container {",
|
|
971
|
+
" max-width: 96rem;",
|
|
972
|
+
" }",
|
|
973
|
+
"}"
|
|
974
|
+
].join("\n");
|
|
975
|
+
function removeTailwindApplyRules(rawSource) {
|
|
826
976
|
try {
|
|
827
|
-
const root = postcss.default.parse(
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
}
|
|
977
|
+
const root = postcss.default.parse(rawSource);
|
|
978
|
+
let removed = false;
|
|
979
|
+
root.walkAtRules("apply", (rule) => {
|
|
980
|
+
const parent = rule.parent;
|
|
981
|
+
if (parent?.type === "rule") parent.remove();
|
|
982
|
+
else rule.remove();
|
|
983
|
+
removed = true;
|
|
984
|
+
});
|
|
985
|
+
root.walkAtRules((rule) => {
|
|
986
|
+
if (rule.nodes && rule.nodes.length === 0) rule.remove();
|
|
987
|
+
});
|
|
988
|
+
return removed ? root.toString() : rawSource;
|
|
835
989
|
} catch {
|
|
836
|
-
return
|
|
990
|
+
return rawSource;
|
|
837
991
|
}
|
|
838
|
-
return hasImport;
|
|
839
992
|
}
|
|
840
993
|
function resolveLegacyCompatCssSource(rawSource) {
|
|
841
|
-
return removeUnsupportedMiniProgramAtRules(removeTailwindSourceDirectives(stripTailwindBanners(rawSource)));
|
|
994
|
+
return removeUnsupportedMiniProgramAtRules(removeTailwindApplyRules(removeTailwindSourceDirectives(stripTailwindBanners(rawSource))));
|
|
842
995
|
}
|
|
843
996
|
function hasContainerConfigToken(rawSource) {
|
|
844
997
|
return rawSource.includes("@config") && /\bcontainer\b/.test(rawSource);
|
|
@@ -867,173 +1020,188 @@ function hasConfiguredContainerCompatSource(source) {
|
|
|
867
1020
|
function hasConfiguredContainerCompatSources(sources) {
|
|
868
1021
|
return sources.some((source) => hasConfiguredContainerCompatSource(source));
|
|
869
1022
|
}
|
|
870
|
-
function
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
function getRuleCompatSelectorKeys(rule) {
|
|
882
|
-
return (rule.selectors?.length ? rule.selectors : [rule.selector]).flatMap((selector) => getCompatSelectorKeys(selector));
|
|
1023
|
+
async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
|
|
1024
|
+
const compatSource = removeGeneratedSelectorCompatCss(resolveLegacyCompatCssSource(rawSource), css);
|
|
1025
|
+
if (compatSource.trim().length === 0) return css;
|
|
1026
|
+
if (generatorTarget !== "weapp") return createCssAppend(css, compatSource);
|
|
1027
|
+
const { css: compatCss } = await styleHandler(compatSource, {
|
|
1028
|
+
...cssHandlerOptions,
|
|
1029
|
+
...generatorStyleOptions
|
|
1030
|
+
});
|
|
1031
|
+
const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeDuplicatedViteMarkers(removeUnsupportedMiniProgramAtRules(compatCss), css), css);
|
|
1032
|
+
if (cleanedCompatCss.trim().length === 0) return css;
|
|
1033
|
+
return createCssAppend(css, cleanedCompatCss);
|
|
883
1034
|
}
|
|
884
|
-
function
|
|
885
|
-
|
|
1035
|
+
async function appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
|
|
1036
|
+
const compatSource = resolveLegacyCompatCssSource(rawSource);
|
|
1037
|
+
const shouldAppendContainer = runtime.has("container") || hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) || configuredContainerCompat || collectGeneratedSelectors(compatSource).has(".container");
|
|
1038
|
+
if (generatorTarget !== "weapp" || !shouldAppendContainer || collectGeneratedSelectors(css).has(".container")) return css;
|
|
1039
|
+
const { css: compatCss } = await styleHandler(LEGACY_CONTAINER_COMPAT_CSS, {
|
|
1040
|
+
...cssHandlerOptions,
|
|
1041
|
+
...generatorStyleOptions
|
|
1042
|
+
});
|
|
1043
|
+
const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeUnsupportedMiniProgramAtRules(compatCss), css);
|
|
1044
|
+
if (cleanedCompatCss.trim().length === 0) return css;
|
|
1045
|
+
return createCssAppend(css, cleanedCompatCss);
|
|
886
1046
|
}
|
|
887
|
-
|
|
888
|
-
|
|
1047
|
+
//#endregion
|
|
1048
|
+
//#region src/bundlers/shared/generator-css/legacy-units.ts
|
|
1049
|
+
const CSS_LENGTH_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)(?:px|rem)\b/i;
|
|
1050
|
+
const RPX_UNIT_RE = /(?:^|[\s(,])[-+]?(?:\d+|\d*\.\d+)rpx\b/i;
|
|
1051
|
+
function createLegacyDeclarationValueMap(css) {
|
|
1052
|
+
const values = /* @__PURE__ */ new Map();
|
|
1053
|
+
postcss.default.parse(css).walkRules((rule) => {
|
|
1054
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
1055
|
+
for (const selector of rule.selectors) {
|
|
1056
|
+
const normalizedSelectors = normalizeCompatSelectors(selector);
|
|
1057
|
+
rule.walkDecls((decl) => {
|
|
1058
|
+
if (RPX_UNIT_RE.test(decl.value)) for (const normalizedSelector of normalizedSelectors) values.set(`${normalizedSelector}\n${decl.prop}`, decl.value);
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
return values;
|
|
889
1063
|
}
|
|
890
|
-
function
|
|
891
|
-
|
|
892
|
-
|
|
1064
|
+
function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
|
|
1065
|
+
try {
|
|
1066
|
+
const legacyValues = createLegacyDeclarationValueMap(legacyCss);
|
|
1067
|
+
if (legacyValues.size === 0) return css;
|
|
1068
|
+
const root = postcss.default.parse(css);
|
|
1069
|
+
let changed = false;
|
|
1070
|
+
root.walkRules((rule) => {
|
|
1071
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
1072
|
+
const selectors = rule.selectors.flatMap((selector) => normalizeCompatSelectors(selector));
|
|
1073
|
+
if (selectors.length === 0) return;
|
|
1074
|
+
rule.walkDecls((decl) => {
|
|
1075
|
+
if (!CSS_LENGTH_UNIT_RE.test(decl.value)) return;
|
|
1076
|
+
for (const selector of selectors) {
|
|
1077
|
+
const legacyValue = legacyValues.get(`${selector}\n${decl.prop}`);
|
|
1078
|
+
if (legacyValue && legacyValue !== decl.value) {
|
|
1079
|
+
decl.value = legacyValue;
|
|
1080
|
+
changed = true;
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
});
|
|
1085
|
+
});
|
|
1086
|
+
return changed ? root.toString() : css;
|
|
1087
|
+
} catch {
|
|
1088
|
+
return css;
|
|
1089
|
+
}
|
|
893
1090
|
}
|
|
894
|
-
|
|
895
|
-
|
|
1091
|
+
//#endregion
|
|
1092
|
+
//#region src/bundlers/shared/generator-css.ts
|
|
1093
|
+
const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
|
|
1094
|
+
const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
|
|
1095
|
+
function finalizeMiniProgramGeneratorCss(css, target) {
|
|
1096
|
+
if (target !== "weapp") return css;
|
|
1097
|
+
return finalizeMiniProgramCss(css);
|
|
896
1098
|
}
|
|
897
|
-
function
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
1099
|
+
function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
|
|
1100
|
+
const tailwindV3StyleOptions = cssHandlerOptions.majorVersion === 3 ? {
|
|
1101
|
+
cssPreflight: opts.cssPreflight,
|
|
1102
|
+
cssPreflightRange: opts.cssPreflightRange
|
|
1103
|
+
} : {};
|
|
1104
|
+
return {
|
|
1105
|
+
cssChildCombinatorReplaceValue: opts.cssChildCombinatorReplaceValue,
|
|
1106
|
+
cssSelectorReplacement: opts.cssSelectorReplacement,
|
|
1107
|
+
rem2rpx: opts.rem2rpx,
|
|
1108
|
+
px2rpx: opts.px2rpx,
|
|
1109
|
+
unitsToPx: opts.unitsToPx,
|
|
1110
|
+
cssRemoveProperty: opts.cssRemoveProperty,
|
|
1111
|
+
cssRemoveHoverPseudoClass: opts.cssRemoveHoverPseudoClass,
|
|
1112
|
+
cssPresetEnv: opts.cssPresetEnv,
|
|
1113
|
+
autoprefixer: opts.autoprefixer,
|
|
1114
|
+
cssCalc: opts.cssCalc,
|
|
1115
|
+
atRules: opts.atRules,
|
|
1116
|
+
uniAppX: opts.uniAppX,
|
|
1117
|
+
uniAppXCssTarget: opts.uniAppXCssTarget,
|
|
1118
|
+
uniAppXUnsupported: opts.uniAppXUnsupported,
|
|
1119
|
+
...cssHandlerOptions,
|
|
1120
|
+
...tailwindV3StyleOptions,
|
|
1121
|
+
...generatorStyleOptions
|
|
1122
|
+
};
|
|
906
1123
|
}
|
|
907
|
-
function
|
|
908
|
-
|
|
909
|
-
let onlyContentVariable = true;
|
|
910
|
-
rule.each((node) => {
|
|
911
|
-
if (node.type !== "decl") return;
|
|
912
|
-
hasDeclaration = true;
|
|
913
|
-
if (node.prop !== "--tw-content") onlyContentVariable = false;
|
|
914
|
-
});
|
|
915
|
-
return hasDeclaration && onlyContentVariable;
|
|
1124
|
+
function isLocalImportRequest(request) {
|
|
1125
|
+
return request.length > 0 && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
916
1126
|
}
|
|
917
|
-
function
|
|
918
|
-
|
|
1127
|
+
function isPureLocalCssImportWrapper(css) {
|
|
1128
|
+
let hasImport = false;
|
|
919
1129
|
try {
|
|
920
|
-
postcss.default.parse(css)
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
1130
|
+
const root = postcss.default.parse(css);
|
|
1131
|
+
for (const node of root.nodes) {
|
|
1132
|
+
if (node.type === "comment") continue;
|
|
1133
|
+
if (node.type !== "atrule" || node.name !== "import") return false;
|
|
1134
|
+
const request = parseImportRequest(node.params);
|
|
1135
|
+
if (!request || !isLocalImportRequest(request)) return false;
|
|
1136
|
+
hasImport = true;
|
|
1137
|
+
}
|
|
924
1138
|
} catch {
|
|
925
|
-
return
|
|
1139
|
+
return false;
|
|
926
1140
|
}
|
|
927
|
-
return
|
|
1141
|
+
return hasImport;
|
|
928
1142
|
}
|
|
929
|
-
function
|
|
930
|
-
|
|
931
|
-
|
|
1143
|
+
function cleanLocalCssImportWrapperTailwindDirectives(css) {
|
|
1144
|
+
let hasLocalImport = false;
|
|
1145
|
+
let hasTailwindDirective = false;
|
|
932
1146
|
try {
|
|
933
1147
|
const root = postcss.default.parse(css);
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
if (
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
1148
|
+
for (const node of root.nodes) {
|
|
1149
|
+
if (node.type === "comment") continue;
|
|
1150
|
+
if (node.type === "atrule" && node.name === "import") {
|
|
1151
|
+
const request = parseImportRequest(node.params);
|
|
1152
|
+
if (!request || !isLocalImportRequest(request)) return;
|
|
1153
|
+
hasLocalImport = true;
|
|
1154
|
+
continue;
|
|
940
1155
|
}
|
|
941
|
-
if (
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
removed = true;
|
|
1156
|
+
if (node.type === "atrule" && node.name === "source") {
|
|
1157
|
+
hasTailwindDirective = true;
|
|
1158
|
+
continue;
|
|
945
1159
|
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
if (!atRule.nodes || atRule.nodes.length === 0) atRule.remove();
|
|
949
|
-
});
|
|
950
|
-
return removed ? root.toString() : css;
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
951
1162
|
} catch {
|
|
952
|
-
return
|
|
1163
|
+
return;
|
|
953
1164
|
}
|
|
1165
|
+
return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(removeTailwindSourceDirectives(css)) : void 0;
|
|
954
1166
|
}
|
|
955
|
-
function
|
|
956
|
-
const generatedSelectors = collectGeneratedSelectors(generatedCss);
|
|
957
|
-
if (generatedSelectors.size === 0) return css;
|
|
958
|
-
const preservedNodes = [];
|
|
1167
|
+
function prefixLocalCssImportsWithWebpackIgnore(css) {
|
|
959
1168
|
try {
|
|
960
1169
|
const root = postcss.default.parse(css);
|
|
961
|
-
root.
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
const declarationProps = /* @__PURE__ */ new Set();
|
|
965
|
-
node.walkDecls((decl) => {
|
|
966
|
-
declarationProps.add(decl.prop);
|
|
967
|
-
});
|
|
968
|
-
postcss.default.parse(generatedCss).walkRules((rule) => {
|
|
969
|
-
const nodeSelectors = new Set(getRuleCompatSelectorKeys(node));
|
|
970
|
-
if (!getRuleCompatSelectorKeys(rule).some((selector) => nodeSelectors.has(selector))) return;
|
|
971
|
-
rule.walkDecls((decl) => {
|
|
972
|
-
declarationProps.delete(decl.prop);
|
|
973
|
-
});
|
|
974
|
-
});
|
|
975
|
-
const nextRule = node.clone();
|
|
976
|
-
nextRule.walkDecls((decl) => {
|
|
977
|
-
if (!declarationProps.has(decl.prop)) decl.remove();
|
|
978
|
-
});
|
|
979
|
-
if (nextRule.nodes.length > 0) preservedNodes.push(nextRule);
|
|
980
|
-
}
|
|
981
|
-
return;
|
|
982
|
-
}
|
|
983
|
-
preservedNodes.push(node.clone());
|
|
1170
|
+
root.walkAtRules("import", (atRule) => {
|
|
1171
|
+
const request = parseImportRequest(atRule.params);
|
|
1172
|
+
if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
|
|
984
1173
|
});
|
|
985
|
-
|
|
986
|
-
const nextRoot = postcss.default.root();
|
|
987
|
-
nextRoot.append(preservedNodes);
|
|
988
|
-
return nextRoot.toString();
|
|
1174
|
+
return root.toString();
|
|
989
1175
|
} catch {
|
|
990
1176
|
return css;
|
|
991
1177
|
}
|
|
992
1178
|
}
|
|
993
|
-
async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
|
|
994
|
-
const compatSource = removeGeneratedSelectorCompatCss(resolveLegacyCompatCssSource(rawSource), css);
|
|
995
|
-
if (compatSource.trim().length === 0) return css;
|
|
996
|
-
if (generatorTarget !== "weapp") return createCssAppend(css, compatSource);
|
|
997
|
-
const { css: compatCss } = await styleHandler(compatSource, {
|
|
998
|
-
...cssHandlerOptions,
|
|
999
|
-
...generatorStyleOptions
|
|
1000
|
-
});
|
|
1001
|
-
const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeDuplicatedViteMarkers(removeUnsupportedMiniProgramAtRules(compatCss), css), css);
|
|
1002
|
-
if (cleanedCompatCss.trim().length === 0) return css;
|
|
1003
|
-
return createCssAppend(css, cleanedCompatCss);
|
|
1004
|
-
}
|
|
1005
|
-
async function appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
|
|
1006
|
-
const compatSource = resolveLegacyCompatCssSource(rawSource);
|
|
1007
|
-
const shouldAppendContainer = runtime.has("container") || hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) || configuredContainerCompat || collectGeneratedSelectors(compatSource).has(".container");
|
|
1008
|
-
if (generatorTarget !== "weapp" || !shouldAppendContainer || collectGeneratedSelectors(css).has(".container")) return css;
|
|
1009
|
-
const { css: compatCss } = await styleHandler(LEGACY_CONTAINER_COMPAT_CSS, {
|
|
1010
|
-
...cssHandlerOptions,
|
|
1011
|
-
...generatorStyleOptions
|
|
1012
|
-
});
|
|
1013
|
-
const cleanedCompatCss = collectDedupedPostTransformCompatCss(removeUnsupportedMiniProgramAtRules(compatCss), css);
|
|
1014
|
-
if (cleanedCompatCss.trim().length === 0) return css;
|
|
1015
|
-
return createCssAppend(css, cleanedCompatCss);
|
|
1016
|
-
}
|
|
1017
1179
|
async function generateCssByGenerator(options) {
|
|
1018
1180
|
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, styleHandler, debug } = options;
|
|
1019
1181
|
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
1020
1182
|
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
1183
|
+
const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(rawSource);
|
|
1184
|
+
if (cleanedLocalImportWrapper !== void 0) return {
|
|
1185
|
+
css: generatorOptions.target === "weapp" ? removeUnsupportedMiniProgramAtRules(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
|
|
1186
|
+
target: generatorOptions.target,
|
|
1187
|
+
source: "generator",
|
|
1188
|
+
dependencies: []
|
|
1189
|
+
};
|
|
1021
1190
|
if (isPureLocalCssImportWrapper(rawSource)) return;
|
|
1022
1191
|
const hasGeneratedCss = hasTailwindGeneratedCss(rawSource);
|
|
1023
1192
|
const hasSourceDirectives = hasTailwindSourceDirectives(rawSource);
|
|
1024
1193
|
const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(rawSource);
|
|
1025
|
-
const
|
|
1026
|
-
|
|
1027
|
-
if (generatorOptions.mode === "off" || !SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || (generatorOptions.mode === "force" ? !shouldForceGenerateCurrentCss : !shouldAutoGenerateCurrentCss) || generatorOptions.mode === "force" && majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers || generatorOptions.mode !== "force" && majorVersion === 3) return;
|
|
1194
|
+
const shouldGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
|
|
1195
|
+
if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
|
|
1028
1196
|
try {
|
|
1029
|
-
await runtimeState.
|
|
1030
|
-
const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions);
|
|
1197
|
+
await runtimeState.readyPromise;
|
|
1198
|
+
const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions);
|
|
1031
1199
|
const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
|
|
1032
1200
|
const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
|
|
1033
1201
|
const generatedResults = await Promise.all(sources.map(async (source) => {
|
|
1034
1202
|
return require_generator.createWeappTailwindcssGenerator(source).generate({
|
|
1035
1203
|
candidates: runtime,
|
|
1036
|
-
scanSources:
|
|
1204
|
+
scanSources: majorVersion === 4,
|
|
1037
1205
|
styleOptions: generatorStyleOptions,
|
|
1038
1206
|
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
1039
1207
|
target: generatorOptions.target
|
|
@@ -1061,7 +1229,8 @@ async function generateCssByGenerator(options) {
|
|
|
1061
1229
|
if (extraSource.trim().length === 0) return {
|
|
1062
1230
|
css: finalizeMiniProgramGeneratorCss(css, generated.target),
|
|
1063
1231
|
target: generated.target,
|
|
1064
|
-
source: "generator"
|
|
1232
|
+
source: "generator",
|
|
1233
|
+
dependencies: generated.dependencies
|
|
1065
1234
|
};
|
|
1066
1235
|
if (generated.target === "weapp") {
|
|
1067
1236
|
const { css: userCss } = await styleHandler(extraSource, {
|
|
@@ -1072,14 +1241,15 @@ async function generateCssByGenerator(options) {
|
|
|
1072
1241
|
} else css = createCssAppend(css, extraSource);
|
|
1073
1242
|
}
|
|
1074
1243
|
}
|
|
1075
|
-
if (generated.target === "weapp"
|
|
1244
|
+
if (generated.target === "weapp") {
|
|
1076
1245
|
css = await appendLegacyCompatCss(css, rawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1077
1246
|
css = await appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1078
1247
|
}
|
|
1079
1248
|
return {
|
|
1080
1249
|
css: finalizeMiniProgramGeneratorCss(css, generated.target),
|
|
1081
1250
|
target: generated.target,
|
|
1082
|
-
source: "generator"
|
|
1251
|
+
source: "generator",
|
|
1252
|
+
dependencies: generated.dependencies
|
|
1083
1253
|
};
|
|
1084
1254
|
}
|
|
1085
1255
|
debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
|
|
@@ -1090,13 +1260,31 @@ async function generateCssByGenerator(options) {
|
|
|
1090
1260
|
return {
|
|
1091
1261
|
css: finalizeMiniProgramGeneratorCss(css, generated.target),
|
|
1092
1262
|
target: generated.target,
|
|
1093
|
-
source:
|
|
1263
|
+
source: "generator",
|
|
1264
|
+
dependencies: generated.dependencies
|
|
1094
1265
|
};
|
|
1095
1266
|
} catch (error) {
|
|
1096
|
-
|
|
1097
|
-
|
|
1267
|
+
debug("tailwind direct css generation failed: %s %O", file, error);
|
|
1268
|
+
throw error;
|
|
1098
1269
|
}
|
|
1099
1270
|
}
|
|
1271
|
+
async function validateCandidatesByGenerator(options) {
|
|
1272
|
+
const { candidates, cssHandlerOptions, debug, file, opts, rawSource, runtimeState } = options;
|
|
1273
|
+
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
1274
|
+
if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || candidates.size === 0) return /* @__PURE__ */ new Set();
|
|
1275
|
+
const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator));
|
|
1276
|
+
const classSets = await Promise.all(sources.map(async (source) => {
|
|
1277
|
+
const generator = require_generator.createWeappTailwindcssGenerator(source);
|
|
1278
|
+
if (typeof generator.validateCandidates === "function") return generator.validateCandidates(candidates);
|
|
1279
|
+
return (await generator.generate({
|
|
1280
|
+
candidates,
|
|
1281
|
+
target: "tailwind"
|
|
1282
|
+
})).classSet;
|
|
1283
|
+
}));
|
|
1284
|
+
const classSet = new Set(classSets.flatMap((item) => [...item]));
|
|
1285
|
+
debug("tailwind generator validated candidates: %s candidates=%d classSet=%d", file, candidates.size, classSet.size);
|
|
1286
|
+
return classSet;
|
|
1287
|
+
}
|
|
1100
1288
|
//#endregion
|
|
1101
1289
|
Object.defineProperty(exports, "generateCssByGenerator", {
|
|
1102
1290
|
enumerable: true,
|
|
@@ -1122,3 +1310,9 @@ Object.defineProperty(exports, "processCachedTask", {
|
|
|
1122
1310
|
return processCachedTask;
|
|
1123
1311
|
}
|
|
1124
1312
|
});
|
|
1313
|
+
Object.defineProperty(exports, "validateCandidatesByGenerator", {
|
|
1314
|
+
enumerable: true,
|
|
1315
|
+
get: function() {
|
|
1316
|
+
return validateCandidatesByGenerator;
|
|
1317
|
+
}
|
|
1318
|
+
});
|