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,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as createTailwindcssPatcher, c as resolveTailwindcssOptions } from "./cache-nq0_XJoS.mjs";
|
|
2
|
+
import { t as ensureTailwindcssRuntimePatch } from "./runtime-patch-pGdCqAEu.mjs";
|
|
2
3
|
import { createRequire } from "node:module";
|
|
3
4
|
import postcss from "postcss";
|
|
4
|
-
import { createStyleHandler } from "@weapp-tailwindcss/postcss";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import process from "node:process";
|
|
7
|
-
import { loadConfig } from "tailwindcss-config";
|
|
8
7
|
import { createTailwindV4Engine, loadTailwindV4DesignSystem, resolveTailwindV4Source, resolveTailwindV4SourceFromPatchOptions } from "tailwindcss-patch";
|
|
8
|
+
import { createStyleHandler, protectDynamicColorMixAlpha } from "@weapp-tailwindcss/postcss";
|
|
9
|
+
import { loadConfig } from "tailwindcss-config";
|
|
9
10
|
//#region src/tailwindcss/remove-unsupported-css.ts
|
|
10
11
|
/**
|
|
11
12
|
* 移除小程序不支持的 cascade layer 语法,同时保留 layer 内的实际规则。
|
|
@@ -24,9 +25,33 @@ function removeUnsupportedCascadeLayers(root) {
|
|
|
24
25
|
const DEFAULT_WEAPP_VARIABLE_SCOPE = "page,.tw-root,wx-root-portal-content,:host";
|
|
25
26
|
const CLASS_SELECTOR_RE = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
26
27
|
const PSEUDO_CONTENT_SELECTOR_RE = /^(?:::before|::after|:before|:after)(?:,(?:::before|::after|:before|:after))*$/;
|
|
28
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
|
|
29
|
+
"*",
|
|
30
|
+
"view",
|
|
31
|
+
"text",
|
|
32
|
+
":before",
|
|
33
|
+
":after",
|
|
34
|
+
"::before",
|
|
35
|
+
"::after"
|
|
36
|
+
]);
|
|
37
|
+
const PREFLIGHT_RESET_PROPS = new Set([
|
|
38
|
+
"box-sizing",
|
|
39
|
+
"border",
|
|
40
|
+
"border-width",
|
|
41
|
+
"border-style",
|
|
42
|
+
"border-color",
|
|
43
|
+
"margin",
|
|
44
|
+
"padding"
|
|
45
|
+
]);
|
|
27
46
|
function hasClassSelector(selector) {
|
|
28
47
|
return CLASS_SELECTOR_RE.test(selector);
|
|
29
48
|
}
|
|
49
|
+
function normalizeSelector$1(selector) {
|
|
50
|
+
return selector.trim().replace(/\s+/g, "");
|
|
51
|
+
}
|
|
52
|
+
function getRuleSelectors(rule) {
|
|
53
|
+
return rule.selector.split(",").map(normalizeSelector$1).filter(Boolean);
|
|
54
|
+
}
|
|
30
55
|
function isCustomPropertyRule(rule) {
|
|
31
56
|
let hasDeclaration = false;
|
|
32
57
|
let allCustomProperties = true;
|
|
@@ -47,13 +72,32 @@ function isPseudoContentInitRule(rule) {
|
|
|
47
72
|
});
|
|
48
73
|
return hasDeclaration && onlyContentVariable;
|
|
49
74
|
}
|
|
75
|
+
function isMiniProgramPreflightRule(rule) {
|
|
76
|
+
const selectors = getRuleSelectors(rule);
|
|
77
|
+
if (selectors.length === 0 || !selectors.every((selector) => MINI_PROGRAM_PREFLIGHT_SELECTORS.has(selector)) || !selectors.some((selector) => selector === "*" || selector === ":before" || selector === ":after" || selector === "::before" || selector === "::after")) return false;
|
|
78
|
+
let hasTailwindVariable = false;
|
|
79
|
+
let hasResetProp = false;
|
|
80
|
+
rule.walkDecls((decl) => {
|
|
81
|
+
if (decl.prop.startsWith("--tw-")) hasTailwindVariable = true;
|
|
82
|
+
if (PREFLIGHT_RESET_PROPS.has(decl.prop)) hasResetProp = true;
|
|
83
|
+
});
|
|
84
|
+
return hasTailwindVariable || hasResetProp;
|
|
85
|
+
}
|
|
86
|
+
function isKeyframesRule(rule) {
|
|
87
|
+
let parent = rule.parent;
|
|
88
|
+
while (parent) {
|
|
89
|
+
if (parent.type === "atrule" && parent.name.endsWith("keyframes")) return true;
|
|
90
|
+
parent = parent.parent;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
50
94
|
/**
|
|
51
95
|
* 裁剪 Tailwind 生成 CSS 中面向浏览器的 classless 规则。
|
|
52
96
|
*
|
|
53
97
|
* 生成模式面向小程序时只需要保留业务 utility 与 Tailwind 变量初始化;
|
|
54
98
|
* 浏览器元素 reset、表单伪元素等 classless 规则不适合直接输出到小程序。
|
|
55
99
|
*/
|
|
56
|
-
function pruneMiniProgramGeneratedCss(css) {
|
|
100
|
+
function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
57
101
|
const root = postcss.parse(css);
|
|
58
102
|
root.walkComments((comment) => {
|
|
59
103
|
comment.remove();
|
|
@@ -63,8 +107,10 @@ function pruneMiniProgramGeneratedCss(css) {
|
|
|
63
107
|
atRule.remove();
|
|
64
108
|
});
|
|
65
109
|
root.walkRules((rule) => {
|
|
110
|
+
if (isKeyframesRule(rule)) return;
|
|
66
111
|
if (hasClassSelector(rule.selector)) return;
|
|
67
112
|
if (isPseudoContentInitRule(rule)) return;
|
|
113
|
+
if (options.preservePreflight && isMiniProgramPreflightRule(rule)) return;
|
|
68
114
|
if (isCustomPropertyRule(rule)) {
|
|
69
115
|
rule.selector = DEFAULT_WEAPP_VARIABLE_SCOPE;
|
|
70
116
|
return;
|
|
@@ -84,14 +130,63 @@ const defaultStyleHandler$1 = createStyleHandler({
|
|
|
84
130
|
isMainChunk: true,
|
|
85
131
|
majorVersion: 3
|
|
86
132
|
});
|
|
133
|
+
const MINI_PROGRAM_V3_PREFLIGHT_SELECTOR = "view,text,::before,::after";
|
|
134
|
+
const V3_PREFLIGHT_RESET_PROPS = new Set([
|
|
135
|
+
"box-sizing",
|
|
136
|
+
"border",
|
|
137
|
+
"border-width",
|
|
138
|
+
"border-style",
|
|
139
|
+
"border-color",
|
|
140
|
+
"margin",
|
|
141
|
+
"padding"
|
|
142
|
+
]);
|
|
143
|
+
function normalizeSelector(selector) {
|
|
144
|
+
return selector.trim().replace(/\s+/g, "");
|
|
145
|
+
}
|
|
146
|
+
function isMiniProgramV3PreflightRule(rule) {
|
|
147
|
+
return normalizeSelector(rule.selector) === MINI_PROGRAM_V3_PREFLIGHT_SELECTOR;
|
|
148
|
+
}
|
|
149
|
+
function hasResetDeclaration(rule) {
|
|
150
|
+
let found = false;
|
|
151
|
+
rule.walkDecls((decl) => {
|
|
152
|
+
if (V3_PREFLIGHT_RESET_PROPS.has(decl.prop)) found = true;
|
|
153
|
+
});
|
|
154
|
+
return found;
|
|
155
|
+
}
|
|
156
|
+
function createPreflightDeclarations(cssPreflight) {
|
|
157
|
+
if (!cssPreflight || typeof cssPreflight !== "object") return [];
|
|
158
|
+
return Object.entries(cssPreflight).filter((entry) => entry[1] !== false).map(([prop, value]) => postcss.decl({
|
|
159
|
+
prop,
|
|
160
|
+
value: value.toString()
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
function ensureMiniProgramV3PreflightReset(css, cssPreflight) {
|
|
164
|
+
const declarations = createPreflightDeclarations(cssPreflight);
|
|
165
|
+
if (declarations.length === 0) return css;
|
|
166
|
+
try {
|
|
167
|
+
const root = postcss.parse(css);
|
|
168
|
+
let targetRule;
|
|
169
|
+
let hasReset = false;
|
|
170
|
+
root.walkRules((rule) => {
|
|
171
|
+
if (!isMiniProgramV3PreflightRule(rule)) return;
|
|
172
|
+
targetRule ?? (targetRule = rule);
|
|
173
|
+
if (hasResetDeclaration(rule)) hasReset = true;
|
|
174
|
+
});
|
|
175
|
+
if (!targetRule || hasReset) return css;
|
|
176
|
+
targetRule.append(...declarations.map((decl) => decl.clone()));
|
|
177
|
+
return root.toString();
|
|
178
|
+
} catch {
|
|
179
|
+
return css;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
87
182
|
async function transformTailwindV3CssToWeapp(css, options) {
|
|
88
|
-
return pruneMiniProgramGeneratedCss((await defaultStyleHandler$1(css, {
|
|
183
|
+
return ensureMiniProgramV3PreflightReset(pruneMiniProgramGeneratedCss((await defaultStyleHandler$1(css, {
|
|
89
184
|
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
90
185
|
cssRemoveHoverPseudoClass: true,
|
|
91
186
|
isMainChunk: true,
|
|
92
187
|
majorVersion: 3,
|
|
93
188
|
...options
|
|
94
|
-
})).css);
|
|
189
|
+
})).css, { preservePreflight: true }), options?.cssPreflight);
|
|
95
190
|
}
|
|
96
191
|
async function transformTailwindV3CssByTarget(css, target, options) {
|
|
97
192
|
return target === "weapp" ? transformTailwindV3CssToWeapp(css, options) : css;
|
|
@@ -158,8 +253,23 @@ function collectDependencyMessages(result) {
|
|
|
158
253
|
for (const message of result.messages) if (message.type === "dependency" && typeof message.file === "string") dependencies.add(message.file);
|
|
159
254
|
return dependencies;
|
|
160
255
|
}
|
|
256
|
+
function createRuntimeReadyPromise(source) {
|
|
257
|
+
return ensureTailwindcssRuntimePatch(createTailwindcssPatcher({
|
|
258
|
+
basedir: source.cwd,
|
|
259
|
+
supportCustomLengthUnitsPatch: true,
|
|
260
|
+
tailwindcss: {
|
|
261
|
+
config: source.config,
|
|
262
|
+
cwd: source.cwd,
|
|
263
|
+
packageName: source.packageName,
|
|
264
|
+
postcssPlugin: source.postcssPlugin,
|
|
265
|
+
version: 3
|
|
266
|
+
}
|
|
267
|
+
}), { clearRequireCache: true });
|
|
268
|
+
}
|
|
161
269
|
function createTailwindV3Engine(source) {
|
|
270
|
+
const runtimeReadyPromise = createRuntimeReadyPromise(source);
|
|
162
271
|
async function generate(options = {}) {
|
|
272
|
+
await runtimeReadyPromise;
|
|
163
273
|
const { styleOptions, target = "weapp" } = options;
|
|
164
274
|
const tailwindcss = loadTailwindcssPlugin(source);
|
|
165
275
|
const result = await postcss([tailwindcss(createTailwindConfig(source, options))]).process(source.css, { from: void 0 });
|
|
@@ -301,17 +411,18 @@ function normalizeTailwindV4GeneratedUrlValues(css) {
|
|
|
301
411
|
});
|
|
302
412
|
}
|
|
303
413
|
async function transformTailwindV4CssToWeapp(css, options) {
|
|
304
|
-
|
|
414
|
+
const protectedCss = protectDynamicColorMixAlpha(normalizeTailwindV4GeneratedUrlValues(css));
|
|
415
|
+
const result = await defaultStyleHandler(protectedCss.css, {
|
|
305
416
|
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
306
417
|
cssRemoveHoverPseudoClass: true,
|
|
307
418
|
isMainChunk: true,
|
|
308
419
|
majorVersion: 4,
|
|
309
420
|
...options
|
|
310
|
-
})
|
|
421
|
+
});
|
|
422
|
+
return pruneMiniProgramGeneratedCss(protectedCss.restore(result.css));
|
|
311
423
|
}
|
|
312
424
|
async function transformTailwindV4CssByTarget(css, target, options) {
|
|
313
|
-
|
|
314
|
-
return target === "weapp" ? transformTailwindV4CssToWeapp(compatibleCss, options) : compatibleCss;
|
|
425
|
+
return target === "weapp" ? transformTailwindV4CssToWeapp(css, options) : css;
|
|
315
426
|
}
|
|
316
427
|
//#endregion
|
|
317
428
|
//#region src/tailwindcss/v4-engine/tailwind-v3-default-colors.ts
|
|
@@ -1064,16 +1175,117 @@ function applyMiniProgramTailwindV4DefaultColorCss(css) {
|
|
|
1064
1175
|
if (insertionIndex === 0) return `${themeCss}\n${css}`;
|
|
1065
1176
|
return `${css.slice(0, insertionIndex)}\n${themeCss}\n${css.slice(insertionIndex)}`;
|
|
1066
1177
|
}
|
|
1178
|
+
function parseImportSourceParam(params) {
|
|
1179
|
+
const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
|
|
1180
|
+
if (!match) return;
|
|
1181
|
+
return {
|
|
1182
|
+
none: match[1] === "none",
|
|
1183
|
+
sourcePath: match[3]
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
function isTailwindCssImport(params) {
|
|
1187
|
+
return /^\s*(['"])tailwindcss(?:\/[^'"]*)?\1/.test(params);
|
|
1188
|
+
}
|
|
1189
|
+
function parseCssImportSpecifier$1(params) {
|
|
1190
|
+
const value = params.trim();
|
|
1191
|
+
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
1192
|
+
if (quoted) return quoted[2];
|
|
1193
|
+
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
1194
|
+
return url?.[2] ?? url?.[3];
|
|
1195
|
+
}
|
|
1196
|
+
function isTailwindCssPreflightImport(params) {
|
|
1197
|
+
const specifier = parseCssImportSpecifier$1(params);
|
|
1198
|
+
return specifier === "tailwindcss/preflight.css" || specifier === "tailwindcss/preflight";
|
|
1199
|
+
}
|
|
1200
|
+
function hasImportLayerOption(params) {
|
|
1201
|
+
return /\blayer(?:\s*\(|\s*$)/.test(params);
|
|
1202
|
+
}
|
|
1203
|
+
function removeUnlayeredTailwindV4PreflightImports(css) {
|
|
1204
|
+
if (!css.includes("preflight")) return css;
|
|
1205
|
+
let root;
|
|
1206
|
+
try {
|
|
1207
|
+
root = postcss.parse(css);
|
|
1208
|
+
} catch {
|
|
1209
|
+
return css;
|
|
1210
|
+
}
|
|
1211
|
+
let changed = false;
|
|
1212
|
+
root.walkAtRules("import", (rule) => {
|
|
1213
|
+
if (isTailwindCssPreflightImport(rule.params) && !hasImportLayerOption(rule.params)) {
|
|
1214
|
+
rule.remove();
|
|
1215
|
+
changed = true;
|
|
1216
|
+
}
|
|
1217
|
+
});
|
|
1218
|
+
return changed ? root.toString() : css;
|
|
1219
|
+
}
|
|
1220
|
+
function parseSourceFileParam(params) {
|
|
1221
|
+
const value = params.trim();
|
|
1222
|
+
if (!value || value === "none" || value.startsWith("inline(")) return;
|
|
1223
|
+
const negated = value.startsWith("not ");
|
|
1224
|
+
const sourceValue = negated ? value.slice(4).trim() : value;
|
|
1225
|
+
if (sourceValue.startsWith("inline(")) return;
|
|
1226
|
+
const match = /^(['"])(.+)\1$/.exec(sourceValue);
|
|
1227
|
+
return match?.[2] ? {
|
|
1228
|
+
negated,
|
|
1229
|
+
pattern: match[2]
|
|
1230
|
+
} : void 0;
|
|
1231
|
+
}
|
|
1232
|
+
function resolveSourceBase(base, sourcePath) {
|
|
1233
|
+
return path.isAbsolute(sourcePath) ? sourcePath : path.resolve(base, sourcePath);
|
|
1234
|
+
}
|
|
1235
|
+
function resolveCssDefinedScanSources(source) {
|
|
1236
|
+
let importSourceBase;
|
|
1237
|
+
let hasSourceNone = false;
|
|
1238
|
+
const sourcePatterns = [];
|
|
1239
|
+
const from = source.dependencies[0];
|
|
1240
|
+
let root;
|
|
1241
|
+
try {
|
|
1242
|
+
root = postcss.parse(source.css, { from });
|
|
1243
|
+
} catch {
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
root.walkAtRules((rule) => {
|
|
1247
|
+
if (rule.name === "import") {
|
|
1248
|
+
if (!isTailwindCssImport(rule.params)) return;
|
|
1249
|
+
const sourceParam = parseImportSourceParam(rule.params);
|
|
1250
|
+
if (sourceParam?.none) hasSourceNone = true;
|
|
1251
|
+
if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase(source.base, sourceParam.sourcePath);
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
if (rule.name !== "source") return;
|
|
1255
|
+
const sourcePattern = parseSourceFileParam(rule.params);
|
|
1256
|
+
if (!sourcePattern) return;
|
|
1257
|
+
sourcePatterns.push({
|
|
1258
|
+
base: source.base,
|
|
1259
|
+
negated: sourcePattern.negated,
|
|
1260
|
+
pattern: sourcePattern.pattern
|
|
1261
|
+
});
|
|
1262
|
+
});
|
|
1263
|
+
if (!importSourceBase) {
|
|
1264
|
+
if (hasSourceNone) return sourcePatterns.length > 0 ? sourcePatterns : false;
|
|
1265
|
+
return;
|
|
1266
|
+
}
|
|
1267
|
+
return [{
|
|
1268
|
+
base: importSourceBase,
|
|
1269
|
+
negated: false,
|
|
1270
|
+
pattern: "**/*"
|
|
1271
|
+
}, ...sourcePatterns];
|
|
1272
|
+
}
|
|
1273
|
+
function resolveScanSources(source, scanSources) {
|
|
1274
|
+
if (scanSources !== true) return scanSources;
|
|
1275
|
+
return resolveCssDefinedScanSources(source) ?? scanSources;
|
|
1276
|
+
}
|
|
1067
1277
|
function createTailwindV4Engine$1(source) {
|
|
1068
1278
|
async function generate(options = {}) {
|
|
1069
1279
|
const { scanSources = true, styleOptions, tailwindcssV3Compatibility, target = "weapp", ...patchOptions } = options;
|
|
1070
|
-
const
|
|
1280
|
+
const shouldApplyTailwindV3Compatibility = tailwindcssV3Compatibility ?? target === "weapp";
|
|
1281
|
+
const filteredSourceCss = target === "weapp" ? removeUnlayeredTailwindV4PreflightImports(source.css) : source.css;
|
|
1282
|
+
const sourceCss = shouldApplyTailwindV3Compatibility ? applyTailwindV3CompatibilityCss(filteredSourceCss) : target === "weapp" ? applyMiniProgramTailwindV4DefaultColorCss(filteredSourceCss) : filteredSourceCss;
|
|
1071
1283
|
const candidates = target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(patchOptions.candidates) : patchOptions.candidates;
|
|
1072
1284
|
const result = await createTailwindV4Engine(sourceCss === source.css ? source : {
|
|
1073
1285
|
...source,
|
|
1074
1286
|
css: sourceCss
|
|
1075
1287
|
}).generate({
|
|
1076
|
-
scanSources,
|
|
1288
|
+
scanSources: resolveScanSources(source, scanSources),
|
|
1077
1289
|
...patchOptions,
|
|
1078
1290
|
candidates
|
|
1079
1291
|
});
|
|
@@ -1097,7 +1309,7 @@ function createTailwindV4Engine$1(source) {
|
|
|
1097
1309
|
//#region src/tailwindcss/v4-engine/source.ts
|
|
1098
1310
|
function isPostcssPluginImportTarget(value) {
|
|
1099
1311
|
if (!value) return false;
|
|
1100
|
-
return value === "@tailwindcss/postcss" || value
|
|
1312
|
+
return value === "@tailwindcss/postcss" || value.includes("/postcss");
|
|
1101
1313
|
}
|
|
1102
1314
|
function uniqueDefined(values) {
|
|
1103
1315
|
return [...new Set(values.filter((value) => typeof value === "string" && value.length > 0))];
|
|
@@ -1110,6 +1322,51 @@ function readConfiguredV4Base(tailwindOptions) {
|
|
|
1110
1322
|
if (typeof v4 !== "object" || v4 === null) return;
|
|
1111
1323
|
return v4.configuredBase;
|
|
1112
1324
|
}
|
|
1325
|
+
function isBarePackageSpecifier(specifier) {
|
|
1326
|
+
return !specifier.startsWith(".") && !specifier.startsWith("/") && !specifier.includes("\\") && !/^[a-z][a-z\d+.-]*:/i.test(specifier);
|
|
1327
|
+
}
|
|
1328
|
+
function parseCssImportSpecifier(params) {
|
|
1329
|
+
const value = params.trim();
|
|
1330
|
+
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
1331
|
+
if (quoted) return {
|
|
1332
|
+
quote: quoted[1],
|
|
1333
|
+
raw: quoted[0],
|
|
1334
|
+
specifier: quoted[2]
|
|
1335
|
+
};
|
|
1336
|
+
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
1337
|
+
if (!url) return;
|
|
1338
|
+
return {
|
|
1339
|
+
quote: url[1],
|
|
1340
|
+
raw: url[0],
|
|
1341
|
+
specifier: url[2] ?? url[3]
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
function quoteCssImportSpecifier(specifier, quote = "\"") {
|
|
1345
|
+
return `${quote}${specifier.replaceAll("\\", "\\\\").replaceAll(quote, `\\${quote}`)}${quote}`;
|
|
1346
|
+
}
|
|
1347
|
+
function createTailwindV4CssImportSpecifierSet(packageName) {
|
|
1348
|
+
const specifiers = new Set(["tailwindcss"]);
|
|
1349
|
+
if (packageName && isBarePackageSpecifier(packageName)) specifiers.add(packageName);
|
|
1350
|
+
return specifiers;
|
|
1351
|
+
}
|
|
1352
|
+
function normalizeTailwindV4CssPackageImports(css, packageName) {
|
|
1353
|
+
if (!css.includes("tailwindcss")) return css;
|
|
1354
|
+
let root;
|
|
1355
|
+
try {
|
|
1356
|
+
root = postcss.parse(css);
|
|
1357
|
+
} catch {
|
|
1358
|
+
return css;
|
|
1359
|
+
}
|
|
1360
|
+
const importSpecifiers = createTailwindV4CssImportSpecifierSet(packageName);
|
|
1361
|
+
let changed = false;
|
|
1362
|
+
root.walkAtRules("import", (rule) => {
|
|
1363
|
+
const parsed = parseCssImportSpecifier(rule.params);
|
|
1364
|
+
if (!parsed || !importSpecifiers.has(parsed.specifier)) return;
|
|
1365
|
+
rule.params = rule.params.replace(parsed.raw, quoteCssImportSpecifier(`${parsed.specifier}/index.css`, parsed.quote));
|
|
1366
|
+
changed = true;
|
|
1367
|
+
});
|
|
1368
|
+
return changed ? root.toString() : css;
|
|
1369
|
+
}
|
|
1113
1370
|
function resolveTailwindCssImportTarget(patcher) {
|
|
1114
1371
|
const configuredPackageName = resolveTailwindcssOptions(patcher.options)?.packageName;
|
|
1115
1372
|
if (typeof configuredPackageName === "string" && configuredPackageName.length > 0 && !isPostcssPluginImportTarget(configuredPackageName)) return configuredPackageName;
|
|
@@ -1134,27 +1391,24 @@ function resolveTailwindV4SourceOptionsFromPatcher(patcher) {
|
|
|
1134
1391
|
};
|
|
1135
1392
|
}
|
|
1136
1393
|
function resolveTailwindV4Source$1(options) {
|
|
1137
|
-
return resolveTailwindV4Source(options
|
|
1394
|
+
return resolveTailwindV4Source(options?.css === void 0 ? options : {
|
|
1395
|
+
...options,
|
|
1396
|
+
css: normalizeTailwindV4CssPackageImports(options.css, options.packageName)
|
|
1397
|
+
});
|
|
1138
1398
|
}
|
|
1139
1399
|
async function resolveTailwindV4SourceFromPatcher(patcher) {
|
|
1140
|
-
return resolveTailwindV4Source(resolveTailwindV4SourceOptionsFromPatcher(patcher));
|
|
1400
|
+
return resolveTailwindV4Source$1(resolveTailwindV4SourceOptionsFromPatcher(patcher));
|
|
1141
1401
|
}
|
|
1142
1402
|
//#endregion
|
|
1143
1403
|
//#region src/generator/options.ts
|
|
1144
1404
|
function normalizeWeappTailwindcssGeneratorOptions(options) {
|
|
1145
|
-
if (options
|
|
1146
|
-
mode: "off",
|
|
1147
|
-
target: "weapp",
|
|
1148
|
-
tailwindcssV3Compatibility: true
|
|
1149
|
-
};
|
|
1150
|
-
if (options === true || options == null) return {
|
|
1151
|
-
mode: "auto",
|
|
1405
|
+
if (options == null) return {
|
|
1152
1406
|
target: "weapp",
|
|
1153
1407
|
tailwindcssV3Compatibility: true
|
|
1154
1408
|
};
|
|
1155
1409
|
return {
|
|
1156
|
-
mode: options.mode ?? "auto",
|
|
1157
1410
|
target: options.target ?? "weapp",
|
|
1411
|
+
config: options.config,
|
|
1158
1412
|
styleOptions: options.styleOptions,
|
|
1159
1413
|
tailwindcssV3Compatibility: options.tailwindcssV3Compatibility ?? (options.target ?? "weapp") === "weapp"
|
|
1160
1414
|
};
|