weapp-tailwindcss 5.0.0-next.2 → 5.0.0-next.5
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/generator-css.d.ts +5 -2
- package/dist/bundlers/vite/generate-bundle.d.ts +1 -0
- package/dist/bundlers/vite/index.d.ts +1 -1
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
- 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/cli/context.d.ts +0 -3
- package/dist/cli/mount-options.d.ts +2 -0
- package/dist/cli.js +8 -2
- package/dist/cli.mjs +8 -2
- package/dist/constants.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro.d.ts +1 -0
- package/dist/defaults.js +5 -7
- package/dist/defaults.mjs +5 -7
- package/dist/generator/index.d.ts +1 -1
- package/dist/generator/options.d.ts +3 -4
- package/dist/{generator-mmhXzZnv.js → generator-9UEp8OoQ.js} +259 -21
- package/dist/{generator-Y-Ikv4Fu.mjs → generator-Dpp-5s8z.mjs} +260 -22
- package/dist/{generator-css-D3OdPRiS.js → generator-css-CGueCYbX.js} +182 -42
- package/dist/{generator-css-B5ejWUMv.mjs → generator-css-MyjZhF0z.mjs} +182 -42
- package/dist/generator.js +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/gulp.js +17 -14
- package/dist/gulp.mjs +17 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/js/index.d.ts +1 -0
- package/dist/js/literal-transform.d.ts +2 -0
- package/dist/{logger-BoVx1Dbt.mjs → logger-1gx9UllH.mjs} +21 -51
- package/dist/{logger-BZ45DZJT.js → logger-D9clu_3f.js} +21 -51
- package/dist/patcher-options-DnqazL9E.js +34 -0
- package/dist/patcher-options-GuOwX0-k.mjs +17 -0
- package/dist/postcss.d.ts +2 -2
- package/dist/postcss.js +37 -28
- package/dist/postcss.mjs +37 -28
- package/dist/presets.js +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/{recorder-zsgatmkB.mjs → recorder-BIW3Kuke.mjs} +5 -12
- package/dist/{recorder-gYSNLfOP.js → recorder-D4BKt75Q.js} +5 -12
- package/dist/reset.d.ts +1 -0
- package/dist/{css-imports-BbrbluP9.js → run-tasks-Cq5A5nVD.js} +6 -55
- package/dist/{css-imports-CSdPq_Sc.mjs → run-tasks-DUVrDJGl.mjs} +5 -42
- 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/v4/patcher-options.d.ts +1 -23
- package/dist/tailwindcss/v4/patcher.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/types.d.ts +1 -1
- package/dist/tailwindcss/version.d.ts +4 -0
- package/dist/typedoc.export.d.ts +0 -2
- package/dist/types/index.d.ts +1 -3
- 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/utils/disabled.d.ts +2 -3
- package/dist/version-CWBxRFPB.js +56 -0
- package/dist/version-WNz3MwRv.mjs +49 -0
- package/dist/{vite-BC9U7ahn.js → vite-BkMGwDeH.js} +106 -39
- package/dist/{vite-CrlzCNqz.mjs → vite-fDM-UQpR.mjs} +89 -22
- 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-DD7A6V0u.js → webpack-CICGEKT9.js} +225 -43
- package/dist/{webpack-Bu6M-Hbw.mjs → webpack-D2Wdk28V.mjs} +214 -27
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +21 -30
- 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/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/loader-anchors-CNkWT8hx.js +0 -273
- package/dist/loader-anchors-TrU7EUr7.mjs +0 -205
- package/dist/patcher-options-6gJN2EXy.js +0 -115
- package/dist/patcher-options-DQfR5xxT.mjs +0 -92
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { r as resolveTailwindcssOptions } from "./patcher-options-
|
|
1
|
+
import { r as resolveTailwindcssOptions } from "./patcher-options-GuOwX0-k.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import postcss from "postcss";
|
|
4
|
-
import { createStyleHandler } from "@weapp-tailwindcss/postcss";
|
|
4
|
+
import { createStyleHandler, protectDynamicColorMixAlpha } from "@weapp-tailwindcss/postcss";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import process from "node:process";
|
|
7
7
|
import { loadConfig } from "tailwindcss-config";
|
|
@@ -24,9 +24,33 @@ function removeUnsupportedCascadeLayers(root) {
|
|
|
24
24
|
const DEFAULT_WEAPP_VARIABLE_SCOPE = "page,.tw-root,wx-root-portal-content,:host";
|
|
25
25
|
const CLASS_SELECTOR_RE = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
26
26
|
const PSEUDO_CONTENT_SELECTOR_RE = /^(?:::before|::after|:before|:after)(?:,(?:::before|::after|:before|:after))*$/;
|
|
27
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
|
|
28
|
+
"*",
|
|
29
|
+
"view",
|
|
30
|
+
"text",
|
|
31
|
+
":before",
|
|
32
|
+
":after",
|
|
33
|
+
"::before",
|
|
34
|
+
"::after"
|
|
35
|
+
]);
|
|
36
|
+
const PREFLIGHT_RESET_PROPS = new Set([
|
|
37
|
+
"box-sizing",
|
|
38
|
+
"border",
|
|
39
|
+
"border-width",
|
|
40
|
+
"border-style",
|
|
41
|
+
"border-color",
|
|
42
|
+
"margin",
|
|
43
|
+
"padding"
|
|
44
|
+
]);
|
|
27
45
|
function hasClassSelector(selector) {
|
|
28
46
|
return CLASS_SELECTOR_RE.test(selector);
|
|
29
47
|
}
|
|
48
|
+
function normalizeSelector$1(selector) {
|
|
49
|
+
return selector.trim().replace(/\s+/g, "");
|
|
50
|
+
}
|
|
51
|
+
function getRuleSelectors(rule) {
|
|
52
|
+
return rule.selector.split(",").map(normalizeSelector$1).filter(Boolean);
|
|
53
|
+
}
|
|
30
54
|
function isCustomPropertyRule(rule) {
|
|
31
55
|
let hasDeclaration = false;
|
|
32
56
|
let allCustomProperties = true;
|
|
@@ -47,13 +71,32 @@ function isPseudoContentInitRule(rule) {
|
|
|
47
71
|
});
|
|
48
72
|
return hasDeclaration && onlyContentVariable;
|
|
49
73
|
}
|
|
74
|
+
function isMiniProgramPreflightRule(rule) {
|
|
75
|
+
const selectors = getRuleSelectors(rule);
|
|
76
|
+
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;
|
|
77
|
+
let hasTailwindVariable = false;
|
|
78
|
+
let hasResetProp = false;
|
|
79
|
+
rule.walkDecls((decl) => {
|
|
80
|
+
if (decl.prop.startsWith("--tw-")) hasTailwindVariable = true;
|
|
81
|
+
if (PREFLIGHT_RESET_PROPS.has(decl.prop)) hasResetProp = true;
|
|
82
|
+
});
|
|
83
|
+
return hasTailwindVariable || hasResetProp;
|
|
84
|
+
}
|
|
85
|
+
function isKeyframesRule(rule) {
|
|
86
|
+
let parent = rule.parent;
|
|
87
|
+
while (parent) {
|
|
88
|
+
if (parent.type === "atrule" && parent.name.endsWith("keyframes")) return true;
|
|
89
|
+
parent = parent.parent;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
50
93
|
/**
|
|
51
94
|
* 裁剪 Tailwind 生成 CSS 中面向浏览器的 classless 规则。
|
|
52
95
|
*
|
|
53
96
|
* 生成模式面向小程序时只需要保留业务 utility 与 Tailwind 变量初始化;
|
|
54
97
|
* 浏览器元素 reset、表单伪元素等 classless 规则不适合直接输出到小程序。
|
|
55
98
|
*/
|
|
56
|
-
function pruneMiniProgramGeneratedCss(css) {
|
|
99
|
+
function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
57
100
|
const root = postcss.parse(css);
|
|
58
101
|
root.walkComments((comment) => {
|
|
59
102
|
comment.remove();
|
|
@@ -63,8 +106,10 @@ function pruneMiniProgramGeneratedCss(css) {
|
|
|
63
106
|
atRule.remove();
|
|
64
107
|
});
|
|
65
108
|
root.walkRules((rule) => {
|
|
109
|
+
if (isKeyframesRule(rule)) return;
|
|
66
110
|
if (hasClassSelector(rule.selector)) return;
|
|
67
111
|
if (isPseudoContentInitRule(rule)) return;
|
|
112
|
+
if (options.preservePreflight && isMiniProgramPreflightRule(rule)) return;
|
|
68
113
|
if (isCustomPropertyRule(rule)) {
|
|
69
114
|
rule.selector = DEFAULT_WEAPP_VARIABLE_SCOPE;
|
|
70
115
|
return;
|
|
@@ -84,14 +129,63 @@ const defaultStyleHandler$1 = createStyleHandler({
|
|
|
84
129
|
isMainChunk: true,
|
|
85
130
|
majorVersion: 3
|
|
86
131
|
});
|
|
132
|
+
const MINI_PROGRAM_V3_PREFLIGHT_SELECTOR = "view,text,::before,::after";
|
|
133
|
+
const V3_PREFLIGHT_RESET_PROPS = new Set([
|
|
134
|
+
"box-sizing",
|
|
135
|
+
"border",
|
|
136
|
+
"border-width",
|
|
137
|
+
"border-style",
|
|
138
|
+
"border-color",
|
|
139
|
+
"margin",
|
|
140
|
+
"padding"
|
|
141
|
+
]);
|
|
142
|
+
function normalizeSelector(selector) {
|
|
143
|
+
return selector.trim().replace(/\s+/g, "");
|
|
144
|
+
}
|
|
145
|
+
function isMiniProgramV3PreflightRule(rule) {
|
|
146
|
+
return normalizeSelector(rule.selector) === MINI_PROGRAM_V3_PREFLIGHT_SELECTOR;
|
|
147
|
+
}
|
|
148
|
+
function hasResetDeclaration(rule) {
|
|
149
|
+
let found = false;
|
|
150
|
+
rule.walkDecls((decl) => {
|
|
151
|
+
if (V3_PREFLIGHT_RESET_PROPS.has(decl.prop)) found = true;
|
|
152
|
+
});
|
|
153
|
+
return found;
|
|
154
|
+
}
|
|
155
|
+
function createPreflightDeclarations(cssPreflight) {
|
|
156
|
+
if (!cssPreflight || typeof cssPreflight !== "object") return [];
|
|
157
|
+
return Object.entries(cssPreflight).filter((entry) => entry[1] !== false).map(([prop, value]) => postcss.decl({
|
|
158
|
+
prop,
|
|
159
|
+
value: value.toString()
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
function ensureMiniProgramV3PreflightReset(css, cssPreflight) {
|
|
163
|
+
const declarations = createPreflightDeclarations(cssPreflight);
|
|
164
|
+
if (declarations.length === 0) return css;
|
|
165
|
+
try {
|
|
166
|
+
const root = postcss.parse(css);
|
|
167
|
+
let targetRule;
|
|
168
|
+
let hasReset = false;
|
|
169
|
+
root.walkRules((rule) => {
|
|
170
|
+
if (!isMiniProgramV3PreflightRule(rule)) return;
|
|
171
|
+
targetRule ?? (targetRule = rule);
|
|
172
|
+
if (hasResetDeclaration(rule)) hasReset = true;
|
|
173
|
+
});
|
|
174
|
+
if (!targetRule || hasReset) return css;
|
|
175
|
+
targetRule.append(...declarations.map((decl) => decl.clone()));
|
|
176
|
+
return root.toString();
|
|
177
|
+
} catch {
|
|
178
|
+
return css;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
87
181
|
async function transformTailwindV3CssToWeapp(css, options) {
|
|
88
|
-
return pruneMiniProgramGeneratedCss((await defaultStyleHandler$1(css, {
|
|
182
|
+
return ensureMiniProgramV3PreflightReset(pruneMiniProgramGeneratedCss((await defaultStyleHandler$1(css, {
|
|
89
183
|
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
90
184
|
cssRemoveHoverPseudoClass: true,
|
|
91
185
|
isMainChunk: true,
|
|
92
186
|
majorVersion: 3,
|
|
93
187
|
...options
|
|
94
|
-
})).css);
|
|
188
|
+
})).css, { preservePreflight: true }), options?.cssPreflight);
|
|
95
189
|
}
|
|
96
190
|
async function transformTailwindV3CssByTarget(css, target, options) {
|
|
97
191
|
return target === "weapp" ? transformTailwindV3CssToWeapp(css, options) : css;
|
|
@@ -301,17 +395,18 @@ function normalizeTailwindV4GeneratedUrlValues(css) {
|
|
|
301
395
|
});
|
|
302
396
|
}
|
|
303
397
|
async function transformTailwindV4CssToWeapp(css, options) {
|
|
304
|
-
|
|
398
|
+
const protectedCss = protectDynamicColorMixAlpha(normalizeTailwindV4GeneratedUrlValues(css));
|
|
399
|
+
const result = await defaultStyleHandler(protectedCss.css, {
|
|
305
400
|
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
306
401
|
cssRemoveHoverPseudoClass: true,
|
|
307
402
|
isMainChunk: true,
|
|
308
403
|
majorVersion: 4,
|
|
309
404
|
...options
|
|
310
|
-
})
|
|
405
|
+
});
|
|
406
|
+
return pruneMiniProgramGeneratedCss(protectedCss.restore(result.css));
|
|
311
407
|
}
|
|
312
408
|
async function transformTailwindV4CssByTarget(css, target, options) {
|
|
313
|
-
|
|
314
|
-
return target === "weapp" ? transformTailwindV4CssToWeapp(compatibleCss, options) : compatibleCss;
|
|
409
|
+
return target === "weapp" ? transformTailwindV4CssToWeapp(css, options) : css;
|
|
315
410
|
}
|
|
316
411
|
//#endregion
|
|
317
412
|
//#region src/tailwindcss/v4-engine/tailwind-v3-default-colors.ts
|
|
@@ -1064,16 +1159,117 @@ function applyMiniProgramTailwindV4DefaultColorCss(css) {
|
|
|
1064
1159
|
if (insertionIndex === 0) return `${themeCss}\n${css}`;
|
|
1065
1160
|
return `${css.slice(0, insertionIndex)}\n${themeCss}\n${css.slice(insertionIndex)}`;
|
|
1066
1161
|
}
|
|
1162
|
+
function parseImportSourceParam(params) {
|
|
1163
|
+
const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
|
|
1164
|
+
if (!match) return;
|
|
1165
|
+
return {
|
|
1166
|
+
none: match[1] === "none",
|
|
1167
|
+
sourcePath: match[3]
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
function isTailwindCssImport(params) {
|
|
1171
|
+
return /^\s*(['"])tailwindcss(?:\/[^'"]*)?\1/.test(params);
|
|
1172
|
+
}
|
|
1173
|
+
function parseCssImportSpecifier$1(params) {
|
|
1174
|
+
const value = params.trim();
|
|
1175
|
+
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
1176
|
+
if (quoted) return quoted[2];
|
|
1177
|
+
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
1178
|
+
return url?.[2] ?? url?.[3];
|
|
1179
|
+
}
|
|
1180
|
+
function isTailwindCssPreflightImport(params) {
|
|
1181
|
+
const specifier = parseCssImportSpecifier$1(params);
|
|
1182
|
+
return specifier === "tailwindcss/preflight.css" || specifier === "tailwindcss/preflight";
|
|
1183
|
+
}
|
|
1184
|
+
function hasImportLayerOption(params) {
|
|
1185
|
+
return /\blayer(?:\s*\(|\s*$)/.test(params);
|
|
1186
|
+
}
|
|
1187
|
+
function removeUnlayeredTailwindV4PreflightImports(css) {
|
|
1188
|
+
if (!css.includes("preflight")) return css;
|
|
1189
|
+
let root;
|
|
1190
|
+
try {
|
|
1191
|
+
root = postcss.parse(css);
|
|
1192
|
+
} catch {
|
|
1193
|
+
return css;
|
|
1194
|
+
}
|
|
1195
|
+
let changed = false;
|
|
1196
|
+
root.walkAtRules("import", (rule) => {
|
|
1197
|
+
if (isTailwindCssPreflightImport(rule.params) && !hasImportLayerOption(rule.params)) {
|
|
1198
|
+
rule.remove();
|
|
1199
|
+
changed = true;
|
|
1200
|
+
}
|
|
1201
|
+
});
|
|
1202
|
+
return changed ? root.toString() : css;
|
|
1203
|
+
}
|
|
1204
|
+
function parseSourceFileParam(params) {
|
|
1205
|
+
const value = params.trim();
|
|
1206
|
+
if (!value || value === "none" || value.startsWith("inline(")) return;
|
|
1207
|
+
const negated = value.startsWith("not ");
|
|
1208
|
+
const sourceValue = negated ? value.slice(4).trim() : value;
|
|
1209
|
+
if (sourceValue.startsWith("inline(")) return;
|
|
1210
|
+
const match = /^(['"])(.+)\1$/.exec(sourceValue);
|
|
1211
|
+
return match?.[2] ? {
|
|
1212
|
+
negated,
|
|
1213
|
+
pattern: match[2]
|
|
1214
|
+
} : void 0;
|
|
1215
|
+
}
|
|
1216
|
+
function resolveSourceBase(base, sourcePath) {
|
|
1217
|
+
return path.isAbsolute(sourcePath) ? sourcePath : path.resolve(base, sourcePath);
|
|
1218
|
+
}
|
|
1219
|
+
function resolveCssDefinedScanSources(source) {
|
|
1220
|
+
let importSourceBase;
|
|
1221
|
+
let hasSourceNone = false;
|
|
1222
|
+
const sourcePatterns = [];
|
|
1223
|
+
const from = source.dependencies[0];
|
|
1224
|
+
let root;
|
|
1225
|
+
try {
|
|
1226
|
+
root = postcss.parse(source.css, { from });
|
|
1227
|
+
} catch {
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
root.walkAtRules((rule) => {
|
|
1231
|
+
if (rule.name === "import") {
|
|
1232
|
+
if (!isTailwindCssImport(rule.params)) return;
|
|
1233
|
+
const sourceParam = parseImportSourceParam(rule.params);
|
|
1234
|
+
if (sourceParam?.none) hasSourceNone = true;
|
|
1235
|
+
if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase(source.base, sourceParam.sourcePath);
|
|
1236
|
+
return;
|
|
1237
|
+
}
|
|
1238
|
+
if (rule.name !== "source") return;
|
|
1239
|
+
const sourcePattern = parseSourceFileParam(rule.params);
|
|
1240
|
+
if (!sourcePattern) return;
|
|
1241
|
+
sourcePatterns.push({
|
|
1242
|
+
base: source.base,
|
|
1243
|
+
negated: sourcePattern.negated,
|
|
1244
|
+
pattern: sourcePattern.pattern
|
|
1245
|
+
});
|
|
1246
|
+
});
|
|
1247
|
+
if (!importSourceBase) {
|
|
1248
|
+
if (hasSourceNone) return sourcePatterns.length > 0 ? sourcePatterns : false;
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
return [{
|
|
1252
|
+
base: importSourceBase,
|
|
1253
|
+
negated: false,
|
|
1254
|
+
pattern: "**/*"
|
|
1255
|
+
}, ...sourcePatterns];
|
|
1256
|
+
}
|
|
1257
|
+
function resolveScanSources(source, scanSources) {
|
|
1258
|
+
if (scanSources !== true) return scanSources;
|
|
1259
|
+
return resolveCssDefinedScanSources(source) ?? scanSources;
|
|
1260
|
+
}
|
|
1067
1261
|
function createTailwindV4Engine$1(source) {
|
|
1068
1262
|
async function generate(options = {}) {
|
|
1069
1263
|
const { scanSources = true, styleOptions, tailwindcssV3Compatibility, target = "weapp", ...patchOptions } = options;
|
|
1070
|
-
const
|
|
1264
|
+
const shouldApplyTailwindV3Compatibility = tailwindcssV3Compatibility ?? target === "weapp";
|
|
1265
|
+
const filteredSourceCss = target === "weapp" ? removeUnlayeredTailwindV4PreflightImports(source.css) : source.css;
|
|
1266
|
+
const sourceCss = shouldApplyTailwindV3Compatibility ? applyTailwindV3CompatibilityCss(filteredSourceCss) : target === "weapp" ? applyMiniProgramTailwindV4DefaultColorCss(filteredSourceCss) : filteredSourceCss;
|
|
1071
1267
|
const candidates = target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(patchOptions.candidates) : patchOptions.candidates;
|
|
1072
1268
|
const result = await createTailwindV4Engine(sourceCss === source.css ? source : {
|
|
1073
1269
|
...source,
|
|
1074
1270
|
css: sourceCss
|
|
1075
1271
|
}).generate({
|
|
1076
|
-
scanSources,
|
|
1272
|
+
scanSources: resolveScanSources(source, scanSources),
|
|
1077
1273
|
...patchOptions,
|
|
1078
1274
|
candidates
|
|
1079
1275
|
});
|
|
@@ -1097,7 +1293,7 @@ function createTailwindV4Engine$1(source) {
|
|
|
1097
1293
|
//#region src/tailwindcss/v4-engine/source.ts
|
|
1098
1294
|
function isPostcssPluginImportTarget(value) {
|
|
1099
1295
|
if (!value) return false;
|
|
1100
|
-
return value === "@tailwindcss/postcss" || value
|
|
1296
|
+
return value === "@tailwindcss/postcss" || value.includes("/postcss");
|
|
1101
1297
|
}
|
|
1102
1298
|
function uniqueDefined(values) {
|
|
1103
1299
|
return [...new Set(values.filter((value) => typeof value === "string" && value.length > 0))];
|
|
@@ -1110,6 +1306,51 @@ function readConfiguredV4Base(tailwindOptions) {
|
|
|
1110
1306
|
if (typeof v4 !== "object" || v4 === null) return;
|
|
1111
1307
|
return v4.configuredBase;
|
|
1112
1308
|
}
|
|
1309
|
+
function isBarePackageSpecifier(specifier) {
|
|
1310
|
+
return !specifier.startsWith(".") && !specifier.startsWith("/") && !specifier.includes("\\") && !/^[a-z][a-z\d+.-]*:/i.test(specifier);
|
|
1311
|
+
}
|
|
1312
|
+
function parseCssImportSpecifier(params) {
|
|
1313
|
+
const value = params.trim();
|
|
1314
|
+
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
1315
|
+
if (quoted) return {
|
|
1316
|
+
quote: quoted[1],
|
|
1317
|
+
raw: quoted[0],
|
|
1318
|
+
specifier: quoted[2]
|
|
1319
|
+
};
|
|
1320
|
+
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
1321
|
+
if (!url) return;
|
|
1322
|
+
return {
|
|
1323
|
+
quote: url[1],
|
|
1324
|
+
raw: url[0],
|
|
1325
|
+
specifier: url[2] ?? url[3]
|
|
1326
|
+
};
|
|
1327
|
+
}
|
|
1328
|
+
function quoteCssImportSpecifier(specifier, quote = "\"") {
|
|
1329
|
+
return `${quote}${specifier.replaceAll("\\", "\\\\").replaceAll(quote, `\\${quote}`)}${quote}`;
|
|
1330
|
+
}
|
|
1331
|
+
function createTailwindV4CssImportSpecifierSet(packageName) {
|
|
1332
|
+
const specifiers = new Set(["tailwindcss"]);
|
|
1333
|
+
if (packageName && isBarePackageSpecifier(packageName)) specifiers.add(packageName);
|
|
1334
|
+
return specifiers;
|
|
1335
|
+
}
|
|
1336
|
+
function normalizeTailwindV4CssPackageImports(css, packageName) {
|
|
1337
|
+
if (!css.includes("tailwindcss")) return css;
|
|
1338
|
+
let root;
|
|
1339
|
+
try {
|
|
1340
|
+
root = postcss.parse(css);
|
|
1341
|
+
} catch {
|
|
1342
|
+
return css;
|
|
1343
|
+
}
|
|
1344
|
+
const importSpecifiers = createTailwindV4CssImportSpecifierSet(packageName);
|
|
1345
|
+
let changed = false;
|
|
1346
|
+
root.walkAtRules("import", (rule) => {
|
|
1347
|
+
const parsed = parseCssImportSpecifier(rule.params);
|
|
1348
|
+
if (!parsed || !importSpecifiers.has(parsed.specifier)) return;
|
|
1349
|
+
rule.params = rule.params.replace(parsed.raw, quoteCssImportSpecifier(`${parsed.specifier}/index.css`, parsed.quote));
|
|
1350
|
+
changed = true;
|
|
1351
|
+
});
|
|
1352
|
+
return changed ? root.toString() : css;
|
|
1353
|
+
}
|
|
1113
1354
|
function resolveTailwindCssImportTarget(patcher) {
|
|
1114
1355
|
const configuredPackageName = resolveTailwindcssOptions(patcher.options)?.packageName;
|
|
1115
1356
|
if (typeof configuredPackageName === "string" && configuredPackageName.length > 0 && !isPostcssPluginImportTarget(configuredPackageName)) return configuredPackageName;
|
|
@@ -1134,27 +1375,24 @@ function resolveTailwindV4SourceOptionsFromPatcher(patcher) {
|
|
|
1134
1375
|
};
|
|
1135
1376
|
}
|
|
1136
1377
|
function resolveTailwindV4Source$1(options) {
|
|
1137
|
-
return resolveTailwindV4Source(options
|
|
1378
|
+
return resolveTailwindV4Source(options?.css === void 0 ? options : {
|
|
1379
|
+
...options,
|
|
1380
|
+
css: normalizeTailwindV4CssPackageImports(options.css, options.packageName)
|
|
1381
|
+
});
|
|
1138
1382
|
}
|
|
1139
1383
|
async function resolveTailwindV4SourceFromPatcher(patcher) {
|
|
1140
|
-
return resolveTailwindV4Source(resolveTailwindV4SourceOptionsFromPatcher(patcher));
|
|
1384
|
+
return resolveTailwindV4Source$1(resolveTailwindV4SourceOptionsFromPatcher(patcher));
|
|
1141
1385
|
}
|
|
1142
1386
|
//#endregion
|
|
1143
1387
|
//#region src/generator/options.ts
|
|
1144
1388
|
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",
|
|
1389
|
+
if (options == null) return {
|
|
1152
1390
|
target: "weapp",
|
|
1153
1391
|
tailwindcssV3Compatibility: true
|
|
1154
1392
|
};
|
|
1155
1393
|
return {
|
|
1156
|
-
mode: options.mode ?? "auto",
|
|
1157
1394
|
target: options.target ?? "weapp",
|
|
1395
|
+
config: options.config,
|
|
1158
1396
|
styleOptions: options.styleOptions,
|
|
1159
1397
|
tailwindcssV3Compatibility: options.tailwindcssV3Compatibility ?? (options.target ?? "weapp") === "weapp"
|
|
1160
1398
|
};
|