weapp-tailwindcss 4.12.0 → 5.0.0-next.2
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/babel/index.d.ts +3 -0
- package/dist/bundlers/gulp/index.d.ts +7 -0
- package/dist/bundlers/shared/cache.d.ts +16 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +4 -0
- package/dist/bundlers/shared/css-imports.d.ts +8 -0
- package/dist/bundlers/shared/generator-candidates.d.ts +5 -0
- package/dist/bundlers/shared/generator-css.d.ts +43 -0
- package/dist/bundlers/shared/module-graph.d.ts +5 -0
- package/dist/bundlers/shared/run-tasks.d.ts +2 -0
- package/dist/bundlers/vite/bundle-entries.d.ts +14 -0
- package/dist/bundlers/vite/bundle-state.d.ts +43 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +22 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +33 -0
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +21 -0
- package/dist/bundlers/vite/index.d.ts +3 -0
- package/dist/bundlers/vite/js-precheck.d.ts +1 -0
- package/dist/bundlers/vite/query.d.ts +15 -0
- package/dist/bundlers/vite/resolve-app-type.d.ts +2 -0
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +11 -0
- package/dist/bundlers/vite/runtime-affecting-signature.d.ts +2 -0
- package/dist/bundlers/vite/source-candidates.d.ts +15 -0
- package/dist/bundlers/vite/utils.d.ts +9 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +20 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +14 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +15 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +9 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +17 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +19 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +9 -0
- package/dist/bundlers/webpack/index.d.ts +1 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +12 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.d.ts +11 -0
- package/dist/bundlers/webpack/shared/css-imports.d.ts +6 -0
- package/dist/bundlers/webpack/shared/loader-anchors.d.ts +8 -0
- package/dist/cache/index.d.ts +38 -0
- package/dist/cache/md5.d.ts +1 -0
- package/dist/chunk-8l464Juk.js +28 -0
- package/dist/cli/config.d.ts +5 -0
- package/dist/cli/context.d.ts +16 -0
- package/dist/cli/doctor/constants.d.ts +7 -0
- package/dist/cli/doctor/types.d.ts +31 -0
- package/dist/cli/doctor.d.ts +4 -0
- package/dist/cli/helpers/options/format.d.ts +2 -0
- package/dist/cli/helpers/options/parse.d.ts +3 -0
- package/dist/cli/helpers/options/resolve.d.ts +1 -0
- package/dist/cli/helpers/options.d.ts +3 -0
- package/dist/cli/helpers/patch-cwd.d.ts +1 -0
- package/dist/cli/helpers.d.ts +5 -0
- package/dist/cli/mount-options/patch-status.d.ts +2 -0
- package/dist/cli/mount-options.d.ts +2 -0
- package/dist/cli/patch-options.d.ts +6 -0
- package/dist/cli/tokens.d.ts +4 -0
- package/dist/cli/types.d.ts +17 -0
- package/dist/cli/vscode-entry.d.ts +14 -0
- package/dist/cli/workspace/package-dirs.d.ts +3 -0
- package/dist/cli/workspace/patch-package.d.ts +3 -0
- package/dist/cli/workspace/patch-utils.d.ts +3 -0
- package/dist/cli/workspace/types.d.ts +11 -0
- package/dist/cli/workspace/workspace-globs.d.ts +2 -0
- package/dist/cli/workspace/workspace-io.d.ts +1 -0
- package/dist/cli/workspace/workspace-lock.d.ts +1 -0
- package/dist/cli/workspace.d.ts +2 -0
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +2425 -3524
- package/dist/cli.mjs +2402 -3505
- package/dist/constants-B-_T5UnW.mjs +44 -0
- package/dist/constants-p1dyh1x1.js +73 -0
- package/dist/constants.d.ts +13 -0
- package/dist/context/compiler-context-cache.d.ts +3 -0
- package/dist/context/custom-attributes.d.ts +2 -0
- package/dist/context/handlers.d.ts +6 -0
- package/dist/context/index.d.ts +7 -0
- package/dist/context/logger.d.ts +4 -0
- package/dist/context/tailwindcss/basedir.d.ts +1 -0
- package/dist/context/tailwindcss/rax.d.ts +2 -0
- package/dist/context/tailwindcss.d.ts +4 -0
- package/dist/context/workspace.d.ts +3 -0
- package/dist/core.d.ts +5 -21
- package/dist/core.js +138 -180
- package/dist/core.mjs +135 -180
- package/dist/css-imports-BbrbluP9.js +177 -0
- package/dist/css-imports-CSdPq_Sc.mjs +128 -0
- package/dist/css-macro/constants.d.ts +14 -0
- package/dist/css-macro/index.d.ts +15 -0
- package/dist/css-macro/postcss.d.ts +3 -7
- package/dist/css-macro/postcss.js +44 -58
- package/dist/css-macro/postcss.mjs +44 -56
- package/dist/css-macro.d.ts +1 -20
- package/dist/css-macro.js +37 -50
- package/dist/css-macro.mjs +33 -47
- package/dist/debug/index.d.ts +5 -0
- package/dist/defaults.d.ts +2 -11
- package/dist/defaults.js +132 -8
- package/dist/defaults.mjs +128 -7
- package/dist/escape.js +31 -54
- package/dist/escape.mjs +18 -25
- package/dist/experimental/index.d.ts +2 -0
- package/dist/experimental/oxc/ast-utils.d.ts +30 -0
- package/dist/experimental/oxc/index.d.ts +2 -0
- package/dist/experimental/oxc/module-specifiers.d.ts +2 -0
- package/dist/experimental/shared/cache.d.ts +3 -0
- package/dist/experimental/shared/transform.d.ts +3 -0
- package/dist/experimental/shared.d.ts +8 -0
- package/dist/experimental/swc/ast-utils.d.ts +30 -0
- package/dist/experimental/swc/index.d.ts +2 -0
- package/dist/experimental/swc/module-specifiers.d.ts +2 -0
- package/dist/generator/index.d.ts +11 -0
- package/dist/generator/options.d.ts +17 -0
- package/dist/generator/types.d.ts +20 -0
- package/dist/generator-Y-Ikv4Fu.mjs +1177 -0
- package/dist/generator-css-B5ejWUMv.mjs +1098 -0
- package/dist/generator-css-D3OdPRiS.js +1125 -0
- package/dist/generator-mmhXzZnv.js +1276 -0
- package/dist/generator.d.ts +1 -0
- package/dist/generator.js +19 -0
- package/dist/generator.mjs +2 -0
- package/dist/gulp.d.ts +4 -24
- package/dist/gulp.js +271 -13
- package/dist/gulp.mjs +263 -13
- package/dist/index.d.ts +8 -15
- package/dist/index.js +12 -24
- package/dist/index.mjs +6 -24
- package/dist/js/JsTokenUpdater.d.ts +14 -0
- package/dist/js/ModuleGraph.d.ts +18 -0
- package/dist/js/NodePathWalker.d.ts +33 -0
- package/dist/js/babel/parse.d.ts +9 -0
- package/dist/js/babel/process.d.ts +4 -0
- package/dist/js/babel.d.ts +13 -0
- package/dist/js/class-context.d.ts +3 -0
- package/dist/js/evalTransforms.d.ts +7 -0
- package/dist/js/handlers.d.ts +5 -0
- package/dist/js/index.d.ts +4 -0
- package/dist/js/module-graph/ignored-exports.d.ts +18 -0
- package/dist/js/module-graph/types.d.ts +17 -0
- package/dist/js/node-path-walker/export-handlers.d.ts +12 -0
- package/dist/js/node-path-walker/import-tokens.d.ts +24 -0
- package/dist/js/precheck.d.ts +2 -0
- package/dist/js/sourceAnalysis.d.ts +17 -0
- package/dist/js/syntax.d.ts +10 -0
- package/dist/js/taggedTemplateIgnore.d.ts +13 -0
- package/dist/js/types.d.ts +11 -0
- package/dist/lightningcss/index.d.ts +8 -0
- package/dist/lightningcss/style-handler/options.d.ts +3 -0
- package/dist/lightningcss/style-handler/selector-transform.d.ts +10 -0
- package/dist/lightningcss/style-handler/selector-utils.d.ts +10 -0
- package/dist/lightningcss/style-handler.d.ts +17 -0
- package/dist/loader-anchors-CNkWT8hx.js +273 -0
- package/dist/loader-anchors-TrU7EUr7.mjs +205 -0
- package/dist/logger/index.d.ts +2 -0
- package/dist/logger-BZ45DZJT.js +1003 -0
- package/dist/logger-BoVx1Dbt.mjs +935 -0
- package/dist/patcher-options-6gJN2EXy.js +115 -0
- package/dist/patcher-options-DQfR5xxT.mjs +92 -0
- package/dist/postcss-html-transform.d.ts +3 -3
- package/dist/postcss-html-transform.js +7 -10
- package/dist/postcss-html-transform.mjs +3 -6
- package/dist/postcss.d.ts +15 -0
- package/dist/postcss.js +280 -0
- package/dist/postcss.mjs +270 -0
- package/dist/presets/hbuilderx.d.ts +4 -0
- package/dist/presets/index.d.ts +3 -0
- package/dist/presets/shared.d.ts +10 -0
- package/dist/presets/taro.d.ts +4 -0
- package/dist/presets/uni-app-x.d.ts +16 -0
- package/dist/presets/uni-app.d.ts +4 -0
- package/dist/presets.d.ts +1 -76
- package/dist/presets.js +115 -163
- package/dist/presets.mjs +107 -163
- package/dist/recorder-gYSNLfOP.js +2878 -0
- package/dist/recorder-zsgatmkB.mjs +2763 -0
- package/dist/reset/index.d.ts +2 -0
- package/dist/reset.d.ts +1 -4
- package/dist/reset.js +19 -8
- package/dist/reset.mjs +2 -8
- package/dist/shared/classname-transform.d.ts +14 -0
- package/dist/shared/mpx.d.ts +7 -0
- package/dist/shared/tailwindcss-css-redirect.d.ts +1 -0
- package/dist/tailwindcss/index.d.ts +11 -0
- package/dist/tailwindcss/miniprogram.d.ts +1 -0
- package/dist/tailwindcss/patcher-options.d.ts +56 -0
- package/dist/tailwindcss/patcher-resolve.d.ts +4 -0
- package/dist/tailwindcss/patcher.d.ts +13 -0
- package/dist/tailwindcss/recorder.d.ts +13 -0
- package/dist/tailwindcss/remove-unsupported-css.d.ts +2 -0
- package/dist/tailwindcss/runtime/cache.d.ts +11 -0
- package/dist/tailwindcss/runtime-logs.d.ts +3 -0
- package/dist/tailwindcss/runtime.d.ts +29 -0
- package/dist/tailwindcss/targets/paths.d.ts +13 -0
- package/dist/tailwindcss/targets/record-io.d.ts +5 -0
- package/dist/tailwindcss/targets/recorder.d.ts +3 -0
- package/dist/tailwindcss/targets/types.d.ts +35 -0
- package/dist/tailwindcss/targets.d.ts +6 -0
- package/dist/tailwindcss/v3-engine/generator.d.ts +2 -0
- package/dist/tailwindcss/v3-engine/index.d.ts +4 -0
- package/dist/tailwindcss/v3-engine/miniprogram.d.ts +4 -0
- package/dist/tailwindcss/v3-engine/source.d.ts +5 -0
- package/dist/tailwindcss/v3-engine/types.d.ts +55 -0
- package/dist/tailwindcss/v4/config.d.ts +5 -0
- package/dist/tailwindcss/v4/css-entries.d.ts +7 -0
- package/dist/tailwindcss/v4/index.d.ts +2 -0
- package/dist/tailwindcss/v4/multi-patcher.d.ts +2 -0
- package/dist/tailwindcss/v4/patcher-options.d.ts +24 -0
- package/dist/tailwindcss/v4/patcher.d.ts +14 -0
- package/dist/tailwindcss/v4-engine/candidates.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/generator.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/index.d.ts +5 -0
- package/dist/tailwindcss/v4-engine/miniprogram.d.ts +5 -0
- package/dist/tailwindcss/v4-engine/source.d.ts +7 -0
- package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/tailwind-v4-default-colors.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/types.d.ts +19 -0
- package/dist/typedoc.export.d.ts +5 -0
- package/dist/types/base.d.ts +1 -0
- package/dist/types/disabled-options.d.ts +4 -0
- package/dist/types/index.d.ts +104 -0
- package/dist/types/shared.d.ts +7 -0
- package/dist/types/user-defined-options/general.d.ts +31 -0
- package/dist/types/user-defined-options/important.d.ts +37 -0
- package/dist/types/user-defined-options/index.d.ts +11 -0
- package/dist/types/user-defined-options/lifecycle.d.ts +6 -0
- package/dist/types/user-defined-options/matcher.d.ts +9 -0
- package/dist/types.d.ts +1 -150
- package/dist/types.js +0 -1
- package/dist/types.mjs +1 -1
- package/dist/uni-app-x/component-local-style.d.ts +19 -0
- package/dist/uni-app-x/index.d.ts +2 -0
- package/dist/uni-app-x/options.d.ts +12 -0
- package/dist/uni-app-x/style-isolation.d.ts +2 -0
- package/dist/uni-app-x/transform.d.ts +9 -0
- package/dist/uni-app-x/vite.d.ts +36 -0
- package/dist/utils/decode.d.ts +2 -0
- package/dist/utils/disabled.d.ts +6 -0
- package/dist/utils/hbuilderx.d.ts +5 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/nameMatcher.d.ts +4 -0
- package/dist/utils/resolve-package.d.ts +1 -0
- package/dist/utils/uni-platform.d.ts +11 -0
- package/dist/utils-7DUGTFED.mjs +48 -0
- package/dist/utils-DmC9_In3.js +61 -0
- package/dist/vite-BC9U7ahn.js +2199 -0
- package/dist/vite-CrlzCNqz.mjs +2186 -0
- package/dist/vite.d.ts +4 -17
- package/dist/vite.js +5 -14
- package/dist/vite.mjs +2 -14
- package/dist/weapp-tw-css-import-rewrite-loader.js +59 -92
- package/dist/weapp-tw-runtime-classset-loader.js +31 -50
- package/dist/webpack-Bu6M-Hbw.mjs +441 -0
- package/dist/webpack-DD7A6V0u.js +456 -0
- package/dist/webpack.d.ts +4 -25
- package/dist/webpack.js +6 -17
- package/dist/webpack.mjs +2 -17
- package/dist/webpack4.d.ts +4 -26
- package/dist/webpack4.js +375 -481
- package/dist/webpack4.mjs +366 -482
- package/dist/wxml/Tokenizer.d.ts +15 -0
- package/dist/wxml/custom-attributes.d.ts +4 -0
- package/dist/wxml/index.d.ts +2 -0
- package/dist/wxml/shared.d.ts +2 -0
- package/dist/wxml/tokenizer/types.d.ts +18 -0
- package/dist/wxml/utils/codegen/legacy-rewriter.d.ts +2 -0
- package/dist/wxml/utils/codegen/legacy-visitor.d.ts +8 -0
- package/dist/wxml/utils/codegen.d.ts +2 -0
- package/dist/wxml/utils/custom-template.d.ts +3 -0
- package/dist/wxml/utils/fragment-helpers.d.ts +6 -0
- package/dist/wxml/utils/fragment-updater.d.ts +4 -0
- package/dist/wxml/utils/template-fragments.d.ts +3 -0
- package/dist/wxml/utils.d.ts +8 -0
- package/dist/wxml/whitespace.d.ts +2 -0
- package/generator-placeholder.css +1 -0
- package/package.json +19 -8
- package/dist/chunk-24AGZQVR.js +0 -183
- package/dist/chunk-3VQKDHGP.mjs +0 -179
- package/dist/chunk-4AFQP74Z.js +0 -24
- package/dist/chunk-57SOQCAU.mjs +0 -582
- package/dist/chunk-5ZYHNDEK.mjs +0 -2439
- package/dist/chunk-76S2EME4.mjs +0 -34
- package/dist/chunk-A5PB4KZT.js +0 -138
- package/dist/chunk-DUHYLR2R.js +0 -276
- package/dist/chunk-DYLQ6UOI.js +0 -71
- package/dist/chunk-E7I5TW5K.js +0 -52
- package/dist/chunk-FS2NOOEB.js +0 -292
- package/dist/chunk-HVNGIKLS.js +0 -3930
- package/dist/chunk-JZQBZHN5.js +0 -579
- package/dist/chunk-KGTVD4EP.mjs +0 -3930
- package/dist/chunk-NNOQDMUP.mjs +0 -10
- package/dist/chunk-OF6MFURR.js +0 -34
- package/dist/chunk-OFB2KBRP.js +0 -2442
- package/dist/chunk-OOHJLO5M.mjs +0 -71
- package/dist/chunk-PCDYXXSK.mjs +0 -1515
- package/dist/chunk-RKISS72P.js +0 -7
- package/dist/chunk-RRQZL7FQ.mjs +0 -292
- package/dist/chunk-XAKAD2CR.mjs +0 -138
- package/dist/chunk-XZP3MREK.mjs +0 -276
- package/dist/chunk-ZAA5ZG3D.js +0 -1518
- package/dist/chunk-ZCH4YINE.mjs +0 -52
- package/dist/cli.d.mts +0 -2
- package/dist/core.d.mts +0 -26
- package/dist/css-macro/postcss.d.mts +0 -7
- package/dist/css-macro.d.mts +0 -18
- package/dist/defaults.d.mts +0 -11
- package/dist/gulp.d.mts +0 -24
- package/dist/index-BXrmQelt.d.mts +0 -672
- package/dist/index-BXrmQelt.d.ts +0 -672
- package/dist/index.d.mts +0 -15
- package/dist/postcss-html-transform.d.mts +0 -2
- package/dist/presets.d.mts +0 -76
- package/dist/reset.d.mts +0 -1
- package/dist/types.d.mts +0 -150
- package/dist/vite.d.mts +0 -17
- package/dist/webpack.d.mts +0 -25
- package/dist/webpack4.d.mts +0 -26
|
@@ -0,0 +1,1125 @@
|
|
|
1
|
+
const require_chunk = require("./chunk-8l464Juk.js");
|
|
2
|
+
const require_generator = require("./generator-mmhXzZnv.js");
|
|
3
|
+
const require_recorder = require("./recorder-gYSNLfOP.js");
|
|
4
|
+
let postcss = require("postcss");
|
|
5
|
+
postcss = require_chunk.__toESM(postcss);
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
node_path = require_chunk.__toESM(node_path);
|
|
8
|
+
let node_process = require("node:process");
|
|
9
|
+
node_process = require_chunk.__toESM(node_process);
|
|
10
|
+
let node_fs = require("node:fs");
|
|
11
|
+
//#region src/bundlers/shared/cache.ts
|
|
12
|
+
async function processCachedTask({ cache, cacheKey, hashKey = cacheKey, rawSource, hash, readCache, applyResult, transform, onCacheHit }) {
|
|
13
|
+
let cacheHit = false;
|
|
14
|
+
const result = await cache.process({
|
|
15
|
+
key: cacheKey,
|
|
16
|
+
hashKey,
|
|
17
|
+
rawSource,
|
|
18
|
+
hash,
|
|
19
|
+
resolveCache: readCache,
|
|
20
|
+
async onCacheHit(value) {
|
|
21
|
+
cacheHit = true;
|
|
22
|
+
await applyResult(value);
|
|
23
|
+
onCacheHit?.();
|
|
24
|
+
},
|
|
25
|
+
transform
|
|
26
|
+
});
|
|
27
|
+
if (!cacheHit) await applyResult(result);
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/bundlers/shared/css-cleanup.ts
|
|
31
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
|
|
32
|
+
"*",
|
|
33
|
+
"view",
|
|
34
|
+
"text",
|
|
35
|
+
":before",
|
|
36
|
+
":after",
|
|
37
|
+
"::before",
|
|
38
|
+
"::after"
|
|
39
|
+
]);
|
|
40
|
+
const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
|
|
41
|
+
const MINI_PROGRAM_THEME_SCOPE_SELECTORS$1 = new Set([
|
|
42
|
+
":host",
|
|
43
|
+
":root",
|
|
44
|
+
"page",
|
|
45
|
+
".tw-root",
|
|
46
|
+
"wx-root-portal-content"
|
|
47
|
+
]);
|
|
48
|
+
const SPECIFICITY_PLACEHOLDER_SUFFIXES = [":not(#n)", ":not(#\\#)"];
|
|
49
|
+
const MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS = new Set([
|
|
50
|
+
":-moz-focusring",
|
|
51
|
+
":-moz-ui-invalid",
|
|
52
|
+
"::-webkit-calendar-picker-indicator",
|
|
53
|
+
"::-webkit-date-and-time-value",
|
|
54
|
+
"::-webkit-datetime-edit",
|
|
55
|
+
"::-webkit-datetime-edit-day-field",
|
|
56
|
+
"::-webkit-datetime-edit-fields-wrapper",
|
|
57
|
+
"::-webkit-datetime-edit-hour-field",
|
|
58
|
+
"::-webkit-datetime-edit-meridiem-field",
|
|
59
|
+
"::-webkit-datetime-edit-millisecond-field",
|
|
60
|
+
"::-webkit-datetime-edit-minute-field",
|
|
61
|
+
"::-webkit-datetime-edit-month-field",
|
|
62
|
+
"::-webkit-datetime-edit-second-field",
|
|
63
|
+
"::-webkit-datetime-edit-year-field",
|
|
64
|
+
"::-webkit-inner-spin-button",
|
|
65
|
+
"::-webkit-input-placeholder",
|
|
66
|
+
"::-webkit-outer-spin-button",
|
|
67
|
+
"::-webkit-search-decoration",
|
|
68
|
+
"::placeholder",
|
|
69
|
+
"[hidden]:where(:not([hidden='until-found']))"
|
|
70
|
+
]);
|
|
71
|
+
const MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS = new Set([
|
|
72
|
+
"a",
|
|
73
|
+
"abbr:where([title])",
|
|
74
|
+
"audio",
|
|
75
|
+
"b",
|
|
76
|
+
"button",
|
|
77
|
+
"canvas",
|
|
78
|
+
"code",
|
|
79
|
+
"embed",
|
|
80
|
+
"h1",
|
|
81
|
+
"h2",
|
|
82
|
+
"h3",
|
|
83
|
+
"h4",
|
|
84
|
+
"h5",
|
|
85
|
+
"h6",
|
|
86
|
+
"hr",
|
|
87
|
+
"html",
|
|
88
|
+
"iframe",
|
|
89
|
+
"img",
|
|
90
|
+
"input",
|
|
91
|
+
"input:where([type='button'],[type='reset'],[type='submit'])",
|
|
92
|
+
"kbd",
|
|
93
|
+
"menu",
|
|
94
|
+
"object",
|
|
95
|
+
"ol",
|
|
96
|
+
"optgroup",
|
|
97
|
+
"pre",
|
|
98
|
+
"progress",
|
|
99
|
+
"samp",
|
|
100
|
+
"select",
|
|
101
|
+
"select[multiple]optgroup",
|
|
102
|
+
"select[multiple]optgroupoption",
|
|
103
|
+
"select[size]optgroup",
|
|
104
|
+
"select[size]optgroupoption",
|
|
105
|
+
"small",
|
|
106
|
+
"strong",
|
|
107
|
+
"sub",
|
|
108
|
+
"summary",
|
|
109
|
+
"sup",
|
|
110
|
+
"svg",
|
|
111
|
+
"table",
|
|
112
|
+
"textarea",
|
|
113
|
+
"ul",
|
|
114
|
+
"video"
|
|
115
|
+
]);
|
|
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
|
+
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
|
+
function isMiniProgramThemeScopeSelector$1(selectors) {
|
|
183
|
+
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_THEME_SCOPE_SELECTORS$1.has(selector));
|
|
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);
|
|
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
|
+
function collectPreflightRules(root) {
|
|
296
|
+
const preflightNodes = [];
|
|
297
|
+
let hasContentInit = false;
|
|
298
|
+
for (const node of root.nodes ?? []) if (isTailwindPreflightRule(node)) {
|
|
299
|
+
preflightNodes.push(node);
|
|
300
|
+
if (hasContentInitDeclaration(node)) hasContentInit = true;
|
|
301
|
+
}
|
|
302
|
+
if (preflightNodes.length === 0) return [];
|
|
303
|
+
const clonedPreflightRules = preflightNodes.map((node) => node.clone());
|
|
304
|
+
const contentInitRules = clonedPreflightRules.filter((rule) => hasContentInitDeclaration(rule));
|
|
305
|
+
const otherPreflightRules = clonedPreflightRules.filter((rule) => !hasContentInitDeclaration(rule));
|
|
306
|
+
const preflightRules = hasContentInit ? [...contentInitRules, ...otherPreflightRules] : [createPseudoContentInitRule(), ...otherPreflightRules];
|
|
307
|
+
for (const node of preflightNodes) node.remove();
|
|
308
|
+
return preflightRules;
|
|
309
|
+
}
|
|
310
|
+
function collectThemeVariableRule(root) {
|
|
311
|
+
const themeRules = [];
|
|
312
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
313
|
+
for (const node of root.nodes ?? []) {
|
|
314
|
+
if (!isMiniProgramThemeVariableRule(node)) continue;
|
|
315
|
+
themeRules.push(node);
|
|
316
|
+
node.walkDecls((decl) => {
|
|
317
|
+
if (isDisplayP3Declaration(decl)) return;
|
|
318
|
+
declarations.set(decl.prop, decl.clone());
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
for (const rule of themeRules) rule.remove();
|
|
322
|
+
if (declarations.size === 0) return;
|
|
323
|
+
const rule = postcss.default.rule({ selector: MINI_PROGRAM_THEME_SCOPE_SELECTOR });
|
|
324
|
+
for (const decl of declarations.values()) rule.append(decl);
|
|
325
|
+
return rule;
|
|
326
|
+
}
|
|
327
|
+
function getTopDirectiveTail(root) {
|
|
328
|
+
let tail;
|
|
329
|
+
for (const node of root.nodes ?? []) {
|
|
330
|
+
if (node.type === "atrule" && (node.name === "charset" || node.name === "import")) {
|
|
331
|
+
tail = node;
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
return tail;
|
|
337
|
+
}
|
|
338
|
+
function insertHoistedRules(root, rules) {
|
|
339
|
+
if (rules.length === 0) return;
|
|
340
|
+
const topDirectiveTail = getTopDirectiveTail(root);
|
|
341
|
+
rules[0].raws.before = topDirectiveTail ? "\n" : "";
|
|
342
|
+
if (topDirectiveTail) topDirectiveTail.after(...rules);
|
|
343
|
+
else root.prepend(...rules);
|
|
344
|
+
}
|
|
345
|
+
function finalizeMiniProgramCssRoot(root) {
|
|
346
|
+
require_generator.removeUnsupportedCascadeLayers(root);
|
|
347
|
+
root.walkAtRules("property", (atRule) => {
|
|
348
|
+
atRule.remove();
|
|
349
|
+
});
|
|
350
|
+
removeSpecificityPlaceholders(root);
|
|
351
|
+
removeUnsupportedBrowserSelectors(root);
|
|
352
|
+
removeDisplayP3Declarations(root);
|
|
353
|
+
const preflightRules = collectPreflightRules(root);
|
|
354
|
+
const themeRule = collectThemeVariableRule(root);
|
|
355
|
+
insertHoistedRules(root, themeRule ? [...preflightRules, themeRule] : preflightRules);
|
|
356
|
+
}
|
|
357
|
+
function finalizeMiniProgramCss(css) {
|
|
358
|
+
const cleanedCss = removeUnsupportedMiniProgramAtRules(css);
|
|
359
|
+
try {
|
|
360
|
+
const root = postcss.default.parse(cleanedCss);
|
|
361
|
+
finalizeMiniProgramCssRoot(root);
|
|
362
|
+
return root.toString();
|
|
363
|
+
} catch {
|
|
364
|
+
return cleanedCss;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
//#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;
|
|
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
|
+
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
|
+
function normalizeCompatSelector(selector) {
|
|
481
|
+
return selector.replace(SPECIFICITY_PLACEHOLDER_RE, "").replace(/\s+/g, " ").trim();
|
|
482
|
+
}
|
|
483
|
+
function isClassSelectorTerminator(char) {
|
|
484
|
+
return /[\s>+~#,.:()[\]]/.test(char);
|
|
485
|
+
}
|
|
486
|
+
function unescapeSimpleCssIdent(value) {
|
|
487
|
+
return value.replaceAll(/\\(.)/g, "$1");
|
|
488
|
+
}
|
|
489
|
+
function escapeCompatSelectorClasses(selector) {
|
|
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
|
+
}
|
|
589
|
+
function parseImportRequest(params) {
|
|
590
|
+
return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
|
|
591
|
+
}
|
|
592
|
+
function parseConfigRequest(params) {
|
|
593
|
+
return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
|
|
594
|
+
}
|
|
595
|
+
function resolvePostcssFromOption(cssHandlerOptions) {
|
|
596
|
+
const from = cssHandlerOptions.postcssOptions?.options?.from;
|
|
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));
|
|
602
|
+
}
|
|
603
|
+
function isTailwindImportAtRule(node) {
|
|
604
|
+
if (node.name === "tailwind") return true;
|
|
605
|
+
if (node.name !== "import") return false;
|
|
606
|
+
const request = parseImportRequest(node.params);
|
|
607
|
+
return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/");
|
|
608
|
+
}
|
|
609
|
+
function isTailwindSourceDirective(node) {
|
|
610
|
+
if (node.type !== "atrule") return false;
|
|
611
|
+
if (isTailwindImportAtRule(node)) return true;
|
|
612
|
+
return TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES.has(node.name);
|
|
613
|
+
}
|
|
614
|
+
function isTailwindGenerationDirective(node) {
|
|
615
|
+
if (node.type !== "atrule") return false;
|
|
616
|
+
return isTailwindImportAtRule(node) || node.name === "layer" || node.name === "config";
|
|
617
|
+
}
|
|
618
|
+
function removeTailwindSourceDirectives(rawSource) {
|
|
619
|
+
try {
|
|
620
|
+
const source = stripGeneratorPlaceholderMarkers(rawSource);
|
|
621
|
+
const root = postcss.default.parse(source);
|
|
622
|
+
let removed = false;
|
|
623
|
+
root.walk((node) => {
|
|
624
|
+
if (isTailwindSourceDirective(node)) {
|
|
625
|
+
node.remove();
|
|
626
|
+
removed = true;
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
return removed ? root.toString() : source;
|
|
630
|
+
} catch {
|
|
631
|
+
return stripGeneratorPlaceholderMarkers(rawSource);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
function hasTailwindSourceDirectives(rawSource) {
|
|
635
|
+
try {
|
|
636
|
+
if (GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource)) return true;
|
|
637
|
+
const root = postcss.default.parse(rawSource);
|
|
638
|
+
let found = false;
|
|
639
|
+
root.walk((node) => {
|
|
640
|
+
if (isTailwindGenerationDirective(node)) {
|
|
641
|
+
found = true;
|
|
642
|
+
return false;
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
return found;
|
|
646
|
+
} catch {
|
|
647
|
+
return false;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
function resolveCssEntrySource(rawSource, base, options = {}) {
|
|
651
|
+
try {
|
|
652
|
+
const root = postcss.default.parse(rawSource);
|
|
653
|
+
let found = false;
|
|
654
|
+
let config;
|
|
655
|
+
let configRequest;
|
|
656
|
+
let removedConfig = false;
|
|
657
|
+
const removeConfig = options.removeConfig ?? true;
|
|
658
|
+
root.walk((node) => {
|
|
659
|
+
if (isTailwindGenerationDirective(node)) found = true;
|
|
660
|
+
if (node.type === "atrule" && node.name === "config") {
|
|
661
|
+
const configPath = parseConfigRequest(node.params);
|
|
662
|
+
if (configPath && !config) {
|
|
663
|
+
configRequest = configPath;
|
|
664
|
+
config = node_path.default.isAbsolute(configPath) ? configPath : node_path.default.resolve(base, configPath);
|
|
665
|
+
}
|
|
666
|
+
if (removeConfig) {
|
|
667
|
+
node.remove();
|
|
668
|
+
removedConfig = true;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
if (!found) return;
|
|
673
|
+
return {
|
|
674
|
+
css: removedConfig ? root.toString() : rawSource,
|
|
675
|
+
config,
|
|
676
|
+
configRequest,
|
|
677
|
+
base
|
|
678
|
+
};
|
|
679
|
+
} catch {
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
|
|
684
|
+
if (config && (0, node_fs.existsSync)(config)) return config;
|
|
685
|
+
if (!configRequest || node_path.default.isAbsolute(configRequest)) return sourceOptions.config;
|
|
686
|
+
const outputDir = node_path.default.dirname(file.replace(/[?#].*$/, ""));
|
|
687
|
+
const baseCandidates = [
|
|
688
|
+
sourceOptions.projectRoot,
|
|
689
|
+
sourceOptions.cwd,
|
|
690
|
+
node_process.default.cwd()
|
|
691
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
692
|
+
for (const base of baseCandidates) {
|
|
693
|
+
const candidates = [
|
|
694
|
+
node_path.default.resolve(base, configRequest),
|
|
695
|
+
node_path.default.resolve(base, "src", configRequest),
|
|
696
|
+
node_path.default.resolve(base, outputDir, configRequest),
|
|
697
|
+
node_path.default.resolve(base, "src", outputDir, configRequest)
|
|
698
|
+
];
|
|
699
|
+
for (const candidate of candidates) if ((0, node_fs.existsSync)(candidate)) return candidate;
|
|
700
|
+
}
|
|
701
|
+
return sourceOptions.config;
|
|
702
|
+
}
|
|
703
|
+
function stripStyleExtension(file) {
|
|
704
|
+
return file.replace(/[?#].*$/, "").replace(/\.(?:wx|ac|jx|tt|q|c|ty)?ss$/i, "");
|
|
705
|
+
}
|
|
706
|
+
function createSourceStylePathCandidates(file, sourceOptions) {
|
|
707
|
+
const bases = [
|
|
708
|
+
sourceOptions.projectRoot,
|
|
709
|
+
sourceOptions.cwd,
|
|
710
|
+
node_process.default.cwd()
|
|
711
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
712
|
+
const strippedFile = stripStyleExtension(file);
|
|
713
|
+
const relativeFiles = /* @__PURE__ */ new Set();
|
|
714
|
+
if (node_path.default.isAbsolute(strippedFile)) for (const base of bases) {
|
|
715
|
+
const relative = node_path.default.relative(base, strippedFile);
|
|
716
|
+
if (!relative || relative.startsWith("..") || node_path.default.isAbsolute(relative)) continue;
|
|
717
|
+
relativeFiles.add(relative);
|
|
718
|
+
const parts = relative.split(node_path.default.sep).filter(Boolean);
|
|
719
|
+
if (parts.length > 1) {
|
|
720
|
+
relativeFiles.add(parts.slice(1).join(node_path.default.sep));
|
|
721
|
+
const distIndex = parts.lastIndexOf("dist");
|
|
722
|
+
if (distIndex >= 0 && distIndex < parts.length - 1) relativeFiles.add([...parts.slice(0, distIndex), ...parts.slice(distIndex + 1)].join(node_path.default.sep));
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
else {
|
|
726
|
+
relativeFiles.add(strippedFile);
|
|
727
|
+
const parts = strippedFile.split(/[\\/]/).filter(Boolean);
|
|
728
|
+
if (parts.length > 1) {
|
|
729
|
+
relativeFiles.add(parts.slice(1).join(node_path.default.sep));
|
|
730
|
+
const distIndex = parts.lastIndexOf("dist");
|
|
731
|
+
if (distIndex >= 0 && distIndex < parts.length - 1) relativeFiles.add([...parts.slice(0, distIndex), ...parts.slice(distIndex + 1)].join(node_path.default.sep));
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
735
|
+
for (const relativeFile of relativeFiles) {
|
|
736
|
+
if (!relativeFile || node_path.default.isAbsolute(relativeFile)) continue;
|
|
737
|
+
for (const base of bases) for (const sourceRoot of ["", "src"]) {
|
|
738
|
+
const prefix = sourceRoot ? node_path.default.resolve(base, sourceRoot, relativeFile) : node_path.default.resolve(base, relativeFile);
|
|
739
|
+
for (const extension of SOURCE_STYLE_EXTENSIONS) candidates.add(`${prefix}${extension}`);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
return [...candidates];
|
|
743
|
+
}
|
|
744
|
+
function extractStyleDirectiveSources(source) {
|
|
745
|
+
const styleSources = [];
|
|
746
|
+
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
747
|
+
let match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
748
|
+
while (match !== null) {
|
|
749
|
+
const styleSource = match[1] ?? "";
|
|
750
|
+
if (hasTailwindSourceDirectives(styleSource)) styleSources.push(styleSource);
|
|
751
|
+
match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
752
|
+
}
|
|
753
|
+
if (styleSources.length > 0) return styleSources;
|
|
754
|
+
return hasTailwindSourceDirectives(source) ? [source] : [];
|
|
755
|
+
}
|
|
756
|
+
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
757
|
+
return rawSource.includes("@apply");
|
|
758
|
+
}
|
|
759
|
+
function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {}) {
|
|
760
|
+
for (const sourceFile of createSourceStylePathCandidates(file, sourceOptions)) {
|
|
761
|
+
if (!(0, node_fs.existsSync)(sourceFile)) continue;
|
|
762
|
+
try {
|
|
763
|
+
const source = (0, node_fs.readFileSync)(sourceFile, "utf8");
|
|
764
|
+
for (const styleSource of extractStyleDirectiveSources(source)) {
|
|
765
|
+
const cssEntrySource = resolveCssEntrySource(styleSource, node_path.default.dirname(sourceFile), resolveOptions);
|
|
766
|
+
if (cssEntrySource) return cssEntrySource;
|
|
767
|
+
}
|
|
768
|
+
} catch {
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
774
|
+
try {
|
|
775
|
+
return require_generator.resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
776
|
+
} catch {
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions) {
|
|
781
|
+
const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), { removeConfig: majorVersion === 3 });
|
|
782
|
+
if (majorVersion === 3) {
|
|
783
|
+
const sourceOptions = require_generator.resolveTailwindV3SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
784
|
+
const sourceSideEntrySource = resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: true });
|
|
785
|
+
const resolvedEntrySource = cssEntrySource ?? sourceSideEntrySource;
|
|
786
|
+
if (!resolvedEntrySource) return require_generator.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
|
|
787
|
+
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, sourceOptions);
|
|
788
|
+
return require_generator.resolveTailwindV3Source({
|
|
789
|
+
...sourceOptions,
|
|
790
|
+
base: resolvedEntrySource.base,
|
|
791
|
+
css: resolvedEntrySource.css,
|
|
792
|
+
...config ? { config } : {}
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
|
|
796
|
+
const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder"));
|
|
797
|
+
const resolvedEntrySource = (sourceOptions && shouldPreferSourceSideEntry ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0) ?? cssEntrySource;
|
|
798
|
+
if (!resolvedEntrySource) return require_generator.resolveTailwindV4SourceFromPatcher(runtimeState.twPatcher);
|
|
799
|
+
return require_generator.resolveTailwindV4Source({
|
|
800
|
+
...sourceOptions ?? {},
|
|
801
|
+
base: resolvedEntrySource.base,
|
|
802
|
+
css: resolvedEntrySource.css
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions) {
|
|
806
|
+
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)];
|
|
808
|
+
let sourceOptions;
|
|
809
|
+
try {
|
|
810
|
+
sourceOptions = require_generator.resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
811
|
+
} catch {
|
|
812
|
+
return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions)];
|
|
813
|
+
}
|
|
814
|
+
if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions)];
|
|
815
|
+
return await Promise.all(sourceOptions.cssEntries.map((cssEntry) => require_generator.resolveTailwindV4Source({
|
|
816
|
+
...sourceOptions,
|
|
817
|
+
css: void 0,
|
|
818
|
+
cssEntries: [cssEntry]
|
|
819
|
+
})));
|
|
820
|
+
}
|
|
821
|
+
function isLocalImportRequest(request) {
|
|
822
|
+
return request.length > 0 && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
823
|
+
}
|
|
824
|
+
function isPureLocalCssImportWrapper(css) {
|
|
825
|
+
let hasImport = false;
|
|
826
|
+
try {
|
|
827
|
+
const root = postcss.default.parse(css);
|
|
828
|
+
for (const node of root.nodes) {
|
|
829
|
+
if (node.type === "comment") continue;
|
|
830
|
+
if (node.type !== "atrule" || node.name !== "import") return false;
|
|
831
|
+
const request = parseImportRequest(node.params);
|
|
832
|
+
if (!request || !isLocalImportRequest(request)) return false;
|
|
833
|
+
hasImport = true;
|
|
834
|
+
}
|
|
835
|
+
} catch {
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
return hasImport;
|
|
839
|
+
}
|
|
840
|
+
function resolveLegacyCompatCssSource(rawSource) {
|
|
841
|
+
return removeUnsupportedMiniProgramAtRules(removeTailwindSourceDirectives(stripTailwindBanners(rawSource)));
|
|
842
|
+
}
|
|
843
|
+
function hasContainerConfigToken(rawSource) {
|
|
844
|
+
return rawSource.includes("@config") && /\bcontainer\b/.test(rawSource);
|
|
845
|
+
}
|
|
846
|
+
function hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) {
|
|
847
|
+
if (hasContainerConfigToken(rawSource)) return true;
|
|
848
|
+
const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions));
|
|
849
|
+
if (!cssEntrySource?.config) return false;
|
|
850
|
+
try {
|
|
851
|
+
return /\bcontainer\b/.test((0, node_fs.readFileSync)(cssEntrySource.config, "utf8"));
|
|
852
|
+
} catch {
|
|
853
|
+
return false;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
function hasConfiguredContainerCompatSource(source) {
|
|
857
|
+
if (hasContainerConfigToken(source.css)) return true;
|
|
858
|
+
const cssEntrySource = resolveCssEntrySource(source.css, source.base);
|
|
859
|
+
if (cssEntrySource?.config) try {
|
|
860
|
+
if (/\bcontainer\b/.test((0, node_fs.readFileSync)(cssEntrySource.config, "utf8"))) return true;
|
|
861
|
+
} catch {}
|
|
862
|
+
if ("config" in source && source.config) try {
|
|
863
|
+
if (/\bcontainer\b/.test((0, node_fs.readFileSync)(source.config, "utf8"))) return true;
|
|
864
|
+
} catch {}
|
|
865
|
+
return false;
|
|
866
|
+
}
|
|
867
|
+
function hasConfiguredContainerCompatSources(sources) {
|
|
868
|
+
return sources.some((source) => hasConfiguredContainerCompatSource(source));
|
|
869
|
+
}
|
|
870
|
+
function removeDuplicatedViteMarkers(css, baseCss) {
|
|
871
|
+
if (!VITE_MARKER_RE.test(baseCss)) return css;
|
|
872
|
+
VITE_MARKER_RE.lastIndex = 0;
|
|
873
|
+
return css.replace(VITE_MARKER_RE, "");
|
|
874
|
+
}
|
|
875
|
+
function normalizeCssSelector(selector) {
|
|
876
|
+
return selector.trim().replace(/\s+/g, "");
|
|
877
|
+
}
|
|
878
|
+
function getCompatSelectorKeys(selector) {
|
|
879
|
+
return normalizeCompatSelectors(selector).map(normalizeCssSelector);
|
|
880
|
+
}
|
|
881
|
+
function getRuleCompatSelectorKeys(rule) {
|
|
882
|
+
return (rule.selectors?.length ? rule.selectors : [rule.selector]).flatMap((selector) => getCompatSelectorKeys(selector));
|
|
883
|
+
}
|
|
884
|
+
function hasClassSelector(selector) {
|
|
885
|
+
return CLASS_SELECTOR_RE.test(selector);
|
|
886
|
+
}
|
|
887
|
+
function getNormalizedSelectorList(selector) {
|
|
888
|
+
return selector.split(",").map(normalizeCssSelector).filter(Boolean);
|
|
889
|
+
}
|
|
890
|
+
function isMiniProgramThemeScopeSelector(selector) {
|
|
891
|
+
const selectors = getNormalizedSelectorList(selector);
|
|
892
|
+
return selectors.length > 0 && selectors.every((item) => MINI_PROGRAM_THEME_SCOPE_SELECTORS.has(item));
|
|
893
|
+
}
|
|
894
|
+
function hasUtilityClassSelector(selector) {
|
|
895
|
+
return hasClassSelector(selector) && !isMiniProgramThemeScopeSelector(selector);
|
|
896
|
+
}
|
|
897
|
+
function isCustomPropertyOnlyRule(rule) {
|
|
898
|
+
let hasDeclaration = false;
|
|
899
|
+
let allCustomProperties = true;
|
|
900
|
+
rule.each((node) => {
|
|
901
|
+
if (node.type !== "decl") return;
|
|
902
|
+
hasDeclaration = true;
|
|
903
|
+
if (!node.prop.startsWith("--")) allCustomProperties = false;
|
|
904
|
+
});
|
|
905
|
+
return hasDeclaration && allCustomProperties;
|
|
906
|
+
}
|
|
907
|
+
function isPseudoContentInitRule(rule) {
|
|
908
|
+
let hasDeclaration = false;
|
|
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;
|
|
916
|
+
}
|
|
917
|
+
function collectGeneratedSelectors(css) {
|
|
918
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
919
|
+
try {
|
|
920
|
+
postcss.default.parse(css).walkRules((rule) => {
|
|
921
|
+
if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
|
|
922
|
+
for (const selector of getRuleCompatSelectorKeys(rule)) selectors.add(selector);
|
|
923
|
+
});
|
|
924
|
+
} catch {
|
|
925
|
+
return selectors;
|
|
926
|
+
}
|
|
927
|
+
return selectors;
|
|
928
|
+
}
|
|
929
|
+
function removeGeneratedSelectorCompatCss(css, generatedCss) {
|
|
930
|
+
const generatedSelectors = collectGeneratedSelectors(generatedCss);
|
|
931
|
+
if (generatedSelectors.size === 0) return css;
|
|
932
|
+
try {
|
|
933
|
+
const root = postcss.default.parse(css);
|
|
934
|
+
let removed = false;
|
|
935
|
+
root.walkRules((rule) => {
|
|
936
|
+
if (isPseudoContentInitRule(rule)) {
|
|
937
|
+
rule.remove();
|
|
938
|
+
removed = true;
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
if (isCustomPropertyOnlyRule(rule) && !isPseudoContentInitRule(rule) && !hasUtilityClassSelector(rule.selector)) return;
|
|
942
|
+
if (getRuleCompatSelectorKeys(rule).some((selector) => generatedSelectors.has(selector))) {
|
|
943
|
+
rule.remove();
|
|
944
|
+
removed = true;
|
|
945
|
+
}
|
|
946
|
+
});
|
|
947
|
+
root.walkAtRules((atRule) => {
|
|
948
|
+
if (!atRule.nodes || atRule.nodes.length === 0) atRule.remove();
|
|
949
|
+
});
|
|
950
|
+
return removed ? root.toString() : css;
|
|
951
|
+
} catch {
|
|
952
|
+
return css;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
function collectDedupedPostTransformCompatCss(css, generatedCss) {
|
|
956
|
+
const generatedSelectors = collectGeneratedSelectors(generatedCss);
|
|
957
|
+
if (generatedSelectors.size === 0) return css;
|
|
958
|
+
const preservedNodes = [];
|
|
959
|
+
try {
|
|
960
|
+
const root = postcss.default.parse(css);
|
|
961
|
+
root.each((node) => {
|
|
962
|
+
if (node.type === "rule" && getRuleCompatSelectorKeys(node).some((selector) => generatedSelectors.has(selector))) {
|
|
963
|
+
if (isCustomPropertyOnlyRule(node) && !isPseudoContentInitRule(node) && !hasUtilityClassSelector(node.selector)) {
|
|
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());
|
|
984
|
+
});
|
|
985
|
+
if (preservedNodes.length === root.nodes.length) return css;
|
|
986
|
+
const nextRoot = postcss.default.root();
|
|
987
|
+
nextRoot.append(preservedNodes);
|
|
988
|
+
return nextRoot.toString();
|
|
989
|
+
} catch {
|
|
990
|
+
return css;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
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
|
+
async function generateCssByGenerator(options) {
|
|
1018
|
+
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, styleHandler, debug } = options;
|
|
1019
|
+
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
1020
|
+
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
1021
|
+
if (isPureLocalCssImportWrapper(rawSource)) return;
|
|
1022
|
+
const hasGeneratedCss = hasTailwindGeneratedCss(rawSource);
|
|
1023
|
+
const hasSourceDirectives = hasTailwindSourceDirectives(rawSource);
|
|
1024
|
+
const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(rawSource);
|
|
1025
|
+
const shouldForceGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
|
|
1026
|
+
if (generatorOptions.mode === "off" || !SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || generatorOptions.mode === "force" && (!shouldForceGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) || generatorOptions.mode !== "force" && majorVersion !== 3 && !hasGeneratedCss || !cssHandlerOptions.isMainChunk && majorVersion !== 3 && generatorOptions.mode !== "force" && !hasGeneratedCss) return;
|
|
1027
|
+
try {
|
|
1028
|
+
await runtimeState.patchPromise;
|
|
1029
|
+
const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions);
|
|
1030
|
+
const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
|
|
1031
|
+
const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
|
|
1032
|
+
const generatedResults = await Promise.all(sources.map(async (source) => {
|
|
1033
|
+
return require_generator.createWeappTailwindcssGenerator(source).generate({
|
|
1034
|
+
candidates: runtime,
|
|
1035
|
+
scanSources: false,
|
|
1036
|
+
styleOptions: generatorStyleOptions,
|
|
1037
|
+
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
1038
|
+
target: generatorOptions.target
|
|
1039
|
+
});
|
|
1040
|
+
}));
|
|
1041
|
+
const firstGenerated = generatedResults[0];
|
|
1042
|
+
if (!firstGenerated) return;
|
|
1043
|
+
const generated = generatedResults.length === 1 ? firstGenerated : {
|
|
1044
|
+
...firstGenerated,
|
|
1045
|
+
css: generatedResults.map((item) => item.css).join("\n"),
|
|
1046
|
+
rawCss: generatedResults.map((item) => item.rawCss).join("\n"),
|
|
1047
|
+
classSet: new Set(generatedResults.flatMap((item) => [...item.classSet])),
|
|
1048
|
+
dependencies: [...new Set(generatedResults.flatMap((item) => item.dependencies))],
|
|
1049
|
+
sources: generatedResults.flatMap((item) => item.sources)
|
|
1050
|
+
};
|
|
1051
|
+
debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
|
|
1052
|
+
const extraCss = splitTailwindV4GeneratedCss(rawSource, generated.rawCss);
|
|
1053
|
+
if (typeof extraCss === "string") {
|
|
1054
|
+
let css = stripTailwindBanner(generated.css);
|
|
1055
|
+
if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, rawSource);
|
|
1056
|
+
if (extraCss.trim().length > 0) {
|
|
1057
|
+
const cleanedExtraCss = removeTailwindSourceDirectives(extraCss);
|
|
1058
|
+
if (cleanedExtraCss.trim().length > 0) {
|
|
1059
|
+
const extraSource = generated.target === "weapp" ? removeUnsupportedMiniProgramAtRules(cleanedExtraCss) : cleanedExtraCss;
|
|
1060
|
+
if (extraSource.trim().length === 0) return {
|
|
1061
|
+
css: finalizeMiniProgramGeneratorCss(css, generated.target),
|
|
1062
|
+
target: generated.target,
|
|
1063
|
+
source: "generator"
|
|
1064
|
+
};
|
|
1065
|
+
if (generated.target === "weapp") {
|
|
1066
|
+
const { css: userCss } = await styleHandler(extraSource, {
|
|
1067
|
+
...generatorStyleOptions,
|
|
1068
|
+
...cssUserHandlerOptions
|
|
1069
|
+
});
|
|
1070
|
+
css = createCssAppend(css, removeUnsupportedMiniProgramAtRules(userCss));
|
|
1071
|
+
} else css = createCssAppend(css, extraSource);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
if (generated.target === "weapp" && generatorOptions.mode === "force") {
|
|
1075
|
+
css = await appendLegacyCompatCss(css, rawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1076
|
+
css = await appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1077
|
+
}
|
|
1078
|
+
return {
|
|
1079
|
+
css: finalizeMiniProgramGeneratorCss(css, generated.target),
|
|
1080
|
+
target: generated.target,
|
|
1081
|
+
source: "generator"
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
if (generatorOptions.mode === "force") {
|
|
1085
|
+
debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
|
|
1086
|
+
let css = stripTailwindBanner(generated.css);
|
|
1087
|
+
if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, rawSource);
|
|
1088
|
+
css = await appendLegacyCompatCss(css, rawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1089
|
+
css = await appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1090
|
+
return {
|
|
1091
|
+
css: finalizeMiniProgramGeneratorCss(css, generated.target),
|
|
1092
|
+
target: generated.target,
|
|
1093
|
+
source: "generator-forced"
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
} catch (error) {
|
|
1097
|
+
if (generatorOptions.mode === "force") throw error;
|
|
1098
|
+
debug("tailwind direct css generation failed, fallback to styleHandler: %s %O", file, error);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
//#endregion
|
|
1102
|
+
Object.defineProperty(exports, "generateCssByGenerator", {
|
|
1103
|
+
enumerable: true,
|
|
1104
|
+
get: function() {
|
|
1105
|
+
return generateCssByGenerator;
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
Object.defineProperty(exports, "hasTailwindGeneratedCssMarkers", {
|
|
1109
|
+
enumerable: true,
|
|
1110
|
+
get: function() {
|
|
1111
|
+
return hasTailwindGeneratedCssMarkers;
|
|
1112
|
+
}
|
|
1113
|
+
});
|
|
1114
|
+
Object.defineProperty(exports, "hasTailwindSourceDirectives", {
|
|
1115
|
+
enumerable: true,
|
|
1116
|
+
get: function() {
|
|
1117
|
+
return hasTailwindSourceDirectives;
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1120
|
+
Object.defineProperty(exports, "processCachedTask", {
|
|
1121
|
+
enumerable: true,
|
|
1122
|
+
get: function() {
|
|
1123
|
+
return processCachedTask;
|
|
1124
|
+
}
|
|
1125
|
+
});
|