weapp-tailwindcss 5.0.0-next.3 → 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-CRLrHW4F.js → generator-css-CGueCYbX.js} +173 -32
- package/dist/{generator-css-Bwy_Uz89.mjs → generator-css-MyjZhF0z.mjs} +173 -32
- package/dist/generator.js +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/gulp.js +15 -11
- package/dist/gulp.mjs +15 -11
- 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-XdFvVASS.mjs → recorder-BIW3Kuke.mjs} +5 -12
- package/dist/{recorder-GdTJ3QqX.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-DgRh_GXn.js → vite-BkMGwDeH.js} +106 -39
- package/dist/{vite-BDywuCjn.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-CAJR4hhP.js → webpack-CICGEKT9.js} +225 -43
- package/dist/{webpack-CiHqVZTg.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-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/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,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-8l464Juk.js");
|
|
2
|
-
const require_patcher_options = require("./patcher-options-
|
|
2
|
+
const require_patcher_options = require("./patcher-options-DnqazL9E.js");
|
|
3
3
|
let node_module = require("node:module");
|
|
4
4
|
let postcss = require("postcss");
|
|
5
5
|
postcss = require_chunk.__toESM(postcss);
|
|
@@ -28,9 +28,33 @@ function removeUnsupportedCascadeLayers(root) {
|
|
|
28
28
|
const DEFAULT_WEAPP_VARIABLE_SCOPE = "page,.tw-root,wx-root-portal-content,:host";
|
|
29
29
|
const CLASS_SELECTOR_RE = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
30
30
|
const PSEUDO_CONTENT_SELECTOR_RE = /^(?:::before|::after|:before|:after)(?:,(?:::before|::after|:before|:after))*$/;
|
|
31
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
|
|
32
|
+
"*",
|
|
33
|
+
"view",
|
|
34
|
+
"text",
|
|
35
|
+
":before",
|
|
36
|
+
":after",
|
|
37
|
+
"::before",
|
|
38
|
+
"::after"
|
|
39
|
+
]);
|
|
40
|
+
const PREFLIGHT_RESET_PROPS = new Set([
|
|
41
|
+
"box-sizing",
|
|
42
|
+
"border",
|
|
43
|
+
"border-width",
|
|
44
|
+
"border-style",
|
|
45
|
+
"border-color",
|
|
46
|
+
"margin",
|
|
47
|
+
"padding"
|
|
48
|
+
]);
|
|
31
49
|
function hasClassSelector(selector) {
|
|
32
50
|
return CLASS_SELECTOR_RE.test(selector);
|
|
33
51
|
}
|
|
52
|
+
function normalizeSelector$1(selector) {
|
|
53
|
+
return selector.trim().replace(/\s+/g, "");
|
|
54
|
+
}
|
|
55
|
+
function getRuleSelectors(rule) {
|
|
56
|
+
return rule.selector.split(",").map(normalizeSelector$1).filter(Boolean);
|
|
57
|
+
}
|
|
34
58
|
function isCustomPropertyRule(rule) {
|
|
35
59
|
let hasDeclaration = false;
|
|
36
60
|
let allCustomProperties = true;
|
|
@@ -51,13 +75,32 @@ function isPseudoContentInitRule(rule) {
|
|
|
51
75
|
});
|
|
52
76
|
return hasDeclaration && onlyContentVariable;
|
|
53
77
|
}
|
|
78
|
+
function isMiniProgramPreflightRule(rule) {
|
|
79
|
+
const selectors = getRuleSelectors(rule);
|
|
80
|
+
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;
|
|
81
|
+
let hasTailwindVariable = false;
|
|
82
|
+
let hasResetProp = false;
|
|
83
|
+
rule.walkDecls((decl) => {
|
|
84
|
+
if (decl.prop.startsWith("--tw-")) hasTailwindVariable = true;
|
|
85
|
+
if (PREFLIGHT_RESET_PROPS.has(decl.prop)) hasResetProp = true;
|
|
86
|
+
});
|
|
87
|
+
return hasTailwindVariable || hasResetProp;
|
|
88
|
+
}
|
|
89
|
+
function isKeyframesRule(rule) {
|
|
90
|
+
let parent = rule.parent;
|
|
91
|
+
while (parent) {
|
|
92
|
+
if (parent.type === "atrule" && parent.name.endsWith("keyframes")) return true;
|
|
93
|
+
parent = parent.parent;
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
54
97
|
/**
|
|
55
98
|
* 裁剪 Tailwind 生成 CSS 中面向浏览器的 classless 规则。
|
|
56
99
|
*
|
|
57
100
|
* 生成模式面向小程序时只需要保留业务 utility 与 Tailwind 变量初始化;
|
|
58
101
|
* 浏览器元素 reset、表单伪元素等 classless 规则不适合直接输出到小程序。
|
|
59
102
|
*/
|
|
60
|
-
function pruneMiniProgramGeneratedCss(css) {
|
|
103
|
+
function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
61
104
|
const root = postcss.default.parse(css);
|
|
62
105
|
root.walkComments((comment) => {
|
|
63
106
|
comment.remove();
|
|
@@ -67,8 +110,10 @@ function pruneMiniProgramGeneratedCss(css) {
|
|
|
67
110
|
atRule.remove();
|
|
68
111
|
});
|
|
69
112
|
root.walkRules((rule) => {
|
|
113
|
+
if (isKeyframesRule(rule)) return;
|
|
70
114
|
if (hasClassSelector(rule.selector)) return;
|
|
71
115
|
if (isPseudoContentInitRule(rule)) return;
|
|
116
|
+
if (options.preservePreflight && isMiniProgramPreflightRule(rule)) return;
|
|
72
117
|
if (isCustomPropertyRule(rule)) {
|
|
73
118
|
rule.selector = DEFAULT_WEAPP_VARIABLE_SCOPE;
|
|
74
119
|
return;
|
|
@@ -88,14 +133,63 @@ const defaultStyleHandler$1 = (0, _weapp_tailwindcss_postcss.createStyleHandler)
|
|
|
88
133
|
isMainChunk: true,
|
|
89
134
|
majorVersion: 3
|
|
90
135
|
});
|
|
136
|
+
const MINI_PROGRAM_V3_PREFLIGHT_SELECTOR = "view,text,::before,::after";
|
|
137
|
+
const V3_PREFLIGHT_RESET_PROPS = new Set([
|
|
138
|
+
"box-sizing",
|
|
139
|
+
"border",
|
|
140
|
+
"border-width",
|
|
141
|
+
"border-style",
|
|
142
|
+
"border-color",
|
|
143
|
+
"margin",
|
|
144
|
+
"padding"
|
|
145
|
+
]);
|
|
146
|
+
function normalizeSelector(selector) {
|
|
147
|
+
return selector.trim().replace(/\s+/g, "");
|
|
148
|
+
}
|
|
149
|
+
function isMiniProgramV3PreflightRule(rule) {
|
|
150
|
+
return normalizeSelector(rule.selector) === MINI_PROGRAM_V3_PREFLIGHT_SELECTOR;
|
|
151
|
+
}
|
|
152
|
+
function hasResetDeclaration(rule) {
|
|
153
|
+
let found = false;
|
|
154
|
+
rule.walkDecls((decl) => {
|
|
155
|
+
if (V3_PREFLIGHT_RESET_PROPS.has(decl.prop)) found = true;
|
|
156
|
+
});
|
|
157
|
+
return found;
|
|
158
|
+
}
|
|
159
|
+
function createPreflightDeclarations(cssPreflight) {
|
|
160
|
+
if (!cssPreflight || typeof cssPreflight !== "object") return [];
|
|
161
|
+
return Object.entries(cssPreflight).filter((entry) => entry[1] !== false).map(([prop, value]) => postcss.default.decl({
|
|
162
|
+
prop,
|
|
163
|
+
value: value.toString()
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
function ensureMiniProgramV3PreflightReset(css, cssPreflight) {
|
|
167
|
+
const declarations = createPreflightDeclarations(cssPreflight);
|
|
168
|
+
if (declarations.length === 0) return css;
|
|
169
|
+
try {
|
|
170
|
+
const root = postcss.default.parse(css);
|
|
171
|
+
let targetRule;
|
|
172
|
+
let hasReset = false;
|
|
173
|
+
root.walkRules((rule) => {
|
|
174
|
+
if (!isMiniProgramV3PreflightRule(rule)) return;
|
|
175
|
+
targetRule ?? (targetRule = rule);
|
|
176
|
+
if (hasResetDeclaration(rule)) hasReset = true;
|
|
177
|
+
});
|
|
178
|
+
if (!targetRule || hasReset) return css;
|
|
179
|
+
targetRule.append(...declarations.map((decl) => decl.clone()));
|
|
180
|
+
return root.toString();
|
|
181
|
+
} catch {
|
|
182
|
+
return css;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
91
185
|
async function transformTailwindV3CssToWeapp(css, options) {
|
|
92
|
-
return pruneMiniProgramGeneratedCss((await defaultStyleHandler$1(css, {
|
|
186
|
+
return ensureMiniProgramV3PreflightReset(pruneMiniProgramGeneratedCss((await defaultStyleHandler$1(css, {
|
|
93
187
|
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
94
188
|
cssRemoveHoverPseudoClass: true,
|
|
95
189
|
isMainChunk: true,
|
|
96
190
|
majorVersion: 3,
|
|
97
191
|
...options
|
|
98
|
-
})).css);
|
|
192
|
+
})).css, { preservePreflight: true }), options?.cssPreflight);
|
|
99
193
|
}
|
|
100
194
|
async function transformTailwindV3CssByTarget(css, target, options) {
|
|
101
195
|
return target === "weapp" ? transformTailwindV3CssToWeapp(css, options) : css;
|
|
@@ -305,17 +399,18 @@ function normalizeTailwindV4GeneratedUrlValues(css) {
|
|
|
305
399
|
});
|
|
306
400
|
}
|
|
307
401
|
async function transformTailwindV4CssToWeapp(css, options) {
|
|
308
|
-
|
|
402
|
+
const protectedCss = (0, _weapp_tailwindcss_postcss.protectDynamicColorMixAlpha)(normalizeTailwindV4GeneratedUrlValues(css));
|
|
403
|
+
const result = await defaultStyleHandler(protectedCss.css, {
|
|
309
404
|
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
310
405
|
cssRemoveHoverPseudoClass: true,
|
|
311
406
|
isMainChunk: true,
|
|
312
407
|
majorVersion: 4,
|
|
313
408
|
...options
|
|
314
|
-
})
|
|
409
|
+
});
|
|
410
|
+
return pruneMiniProgramGeneratedCss(protectedCss.restore(result.css));
|
|
315
411
|
}
|
|
316
412
|
async function transformTailwindV4CssByTarget(css, target, options) {
|
|
317
|
-
|
|
318
|
-
return target === "weapp" ? transformTailwindV4CssToWeapp(compatibleCss, options) : compatibleCss;
|
|
413
|
+
return target === "weapp" ? transformTailwindV4CssToWeapp(css, options) : css;
|
|
319
414
|
}
|
|
320
415
|
//#endregion
|
|
321
416
|
//#region src/tailwindcss/v4-engine/tailwind-v3-default-colors.ts
|
|
@@ -1068,16 +1163,117 @@ function applyMiniProgramTailwindV4DefaultColorCss(css) {
|
|
|
1068
1163
|
if (insertionIndex === 0) return `${themeCss}\n${css}`;
|
|
1069
1164
|
return `${css.slice(0, insertionIndex)}\n${themeCss}\n${css.slice(insertionIndex)}`;
|
|
1070
1165
|
}
|
|
1166
|
+
function parseImportSourceParam(params) {
|
|
1167
|
+
const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
|
|
1168
|
+
if (!match) return;
|
|
1169
|
+
return {
|
|
1170
|
+
none: match[1] === "none",
|
|
1171
|
+
sourcePath: match[3]
|
|
1172
|
+
};
|
|
1173
|
+
}
|
|
1174
|
+
function isTailwindCssImport(params) {
|
|
1175
|
+
return /^\s*(['"])tailwindcss(?:\/[^'"]*)?\1/.test(params);
|
|
1176
|
+
}
|
|
1177
|
+
function parseCssImportSpecifier$1(params) {
|
|
1178
|
+
const value = params.trim();
|
|
1179
|
+
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
1180
|
+
if (quoted) return quoted[2];
|
|
1181
|
+
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
1182
|
+
return url?.[2] ?? url?.[3];
|
|
1183
|
+
}
|
|
1184
|
+
function isTailwindCssPreflightImport(params) {
|
|
1185
|
+
const specifier = parseCssImportSpecifier$1(params);
|
|
1186
|
+
return specifier === "tailwindcss/preflight.css" || specifier === "tailwindcss/preflight";
|
|
1187
|
+
}
|
|
1188
|
+
function hasImportLayerOption(params) {
|
|
1189
|
+
return /\blayer(?:\s*\(|\s*$)/.test(params);
|
|
1190
|
+
}
|
|
1191
|
+
function removeUnlayeredTailwindV4PreflightImports(css) {
|
|
1192
|
+
if (!css.includes("preflight")) return css;
|
|
1193
|
+
let root;
|
|
1194
|
+
try {
|
|
1195
|
+
root = postcss.default.parse(css);
|
|
1196
|
+
} catch {
|
|
1197
|
+
return css;
|
|
1198
|
+
}
|
|
1199
|
+
let changed = false;
|
|
1200
|
+
root.walkAtRules("import", (rule) => {
|
|
1201
|
+
if (isTailwindCssPreflightImport(rule.params) && !hasImportLayerOption(rule.params)) {
|
|
1202
|
+
rule.remove();
|
|
1203
|
+
changed = true;
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1206
|
+
return changed ? root.toString() : css;
|
|
1207
|
+
}
|
|
1208
|
+
function parseSourceFileParam(params) {
|
|
1209
|
+
const value = params.trim();
|
|
1210
|
+
if (!value || value === "none" || value.startsWith("inline(")) return;
|
|
1211
|
+
const negated = value.startsWith("not ");
|
|
1212
|
+
const sourceValue = negated ? value.slice(4).trim() : value;
|
|
1213
|
+
if (sourceValue.startsWith("inline(")) return;
|
|
1214
|
+
const match = /^(['"])(.+)\1$/.exec(sourceValue);
|
|
1215
|
+
return match?.[2] ? {
|
|
1216
|
+
negated,
|
|
1217
|
+
pattern: match[2]
|
|
1218
|
+
} : void 0;
|
|
1219
|
+
}
|
|
1220
|
+
function resolveSourceBase(base, sourcePath) {
|
|
1221
|
+
return node_path.default.isAbsolute(sourcePath) ? sourcePath : node_path.default.resolve(base, sourcePath);
|
|
1222
|
+
}
|
|
1223
|
+
function resolveCssDefinedScanSources(source) {
|
|
1224
|
+
let importSourceBase;
|
|
1225
|
+
let hasSourceNone = false;
|
|
1226
|
+
const sourcePatterns = [];
|
|
1227
|
+
const from = source.dependencies[0];
|
|
1228
|
+
let root;
|
|
1229
|
+
try {
|
|
1230
|
+
root = postcss.default.parse(source.css, { from });
|
|
1231
|
+
} catch {
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
root.walkAtRules((rule) => {
|
|
1235
|
+
if (rule.name === "import") {
|
|
1236
|
+
if (!isTailwindCssImport(rule.params)) return;
|
|
1237
|
+
const sourceParam = parseImportSourceParam(rule.params);
|
|
1238
|
+
if (sourceParam?.none) hasSourceNone = true;
|
|
1239
|
+
if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase(source.base, sourceParam.sourcePath);
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
if (rule.name !== "source") return;
|
|
1243
|
+
const sourcePattern = parseSourceFileParam(rule.params);
|
|
1244
|
+
if (!sourcePattern) return;
|
|
1245
|
+
sourcePatterns.push({
|
|
1246
|
+
base: source.base,
|
|
1247
|
+
negated: sourcePattern.negated,
|
|
1248
|
+
pattern: sourcePattern.pattern
|
|
1249
|
+
});
|
|
1250
|
+
});
|
|
1251
|
+
if (!importSourceBase) {
|
|
1252
|
+
if (hasSourceNone) return sourcePatterns.length > 0 ? sourcePatterns : false;
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
return [{
|
|
1256
|
+
base: importSourceBase,
|
|
1257
|
+
negated: false,
|
|
1258
|
+
pattern: "**/*"
|
|
1259
|
+
}, ...sourcePatterns];
|
|
1260
|
+
}
|
|
1261
|
+
function resolveScanSources(source, scanSources) {
|
|
1262
|
+
if (scanSources !== true) return scanSources;
|
|
1263
|
+
return resolveCssDefinedScanSources(source) ?? scanSources;
|
|
1264
|
+
}
|
|
1071
1265
|
function createTailwindV4Engine(source) {
|
|
1072
1266
|
async function generate(options = {}) {
|
|
1073
1267
|
const { scanSources = true, styleOptions, tailwindcssV3Compatibility, target = "weapp", ...patchOptions } = options;
|
|
1074
|
-
const
|
|
1268
|
+
const shouldApplyTailwindV3Compatibility = tailwindcssV3Compatibility ?? target === "weapp";
|
|
1269
|
+
const filteredSourceCss = target === "weapp" ? removeUnlayeredTailwindV4PreflightImports(source.css) : source.css;
|
|
1270
|
+
const sourceCss = shouldApplyTailwindV3Compatibility ? applyTailwindV3CompatibilityCss(filteredSourceCss) : target === "weapp" ? applyMiniProgramTailwindV4DefaultColorCss(filteredSourceCss) : filteredSourceCss;
|
|
1075
1271
|
const candidates = target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(patchOptions.candidates) : patchOptions.candidates;
|
|
1076
1272
|
const result = await (0, tailwindcss_patch.createTailwindV4Engine)(sourceCss === source.css ? source : {
|
|
1077
1273
|
...source,
|
|
1078
1274
|
css: sourceCss
|
|
1079
1275
|
}).generate({
|
|
1080
|
-
scanSources,
|
|
1276
|
+
scanSources: resolveScanSources(source, scanSources),
|
|
1081
1277
|
...patchOptions,
|
|
1082
1278
|
candidates
|
|
1083
1279
|
});
|
|
@@ -1101,7 +1297,7 @@ function createTailwindV4Engine(source) {
|
|
|
1101
1297
|
//#region src/tailwindcss/v4-engine/source.ts
|
|
1102
1298
|
function isPostcssPluginImportTarget(value) {
|
|
1103
1299
|
if (!value) return false;
|
|
1104
|
-
return value === "@tailwindcss/postcss" || value
|
|
1300
|
+
return value === "@tailwindcss/postcss" || value.includes("/postcss");
|
|
1105
1301
|
}
|
|
1106
1302
|
function uniqueDefined(values) {
|
|
1107
1303
|
return [...new Set(values.filter((value) => typeof value === "string" && value.length > 0))];
|
|
@@ -1114,6 +1310,51 @@ function readConfiguredV4Base(tailwindOptions) {
|
|
|
1114
1310
|
if (typeof v4 !== "object" || v4 === null) return;
|
|
1115
1311
|
return v4.configuredBase;
|
|
1116
1312
|
}
|
|
1313
|
+
function isBarePackageSpecifier(specifier) {
|
|
1314
|
+
return !specifier.startsWith(".") && !specifier.startsWith("/") && !specifier.includes("\\") && !/^[a-z][a-z\d+.-]*:/i.test(specifier);
|
|
1315
|
+
}
|
|
1316
|
+
function parseCssImportSpecifier(params) {
|
|
1317
|
+
const value = params.trim();
|
|
1318
|
+
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
1319
|
+
if (quoted) return {
|
|
1320
|
+
quote: quoted[1],
|
|
1321
|
+
raw: quoted[0],
|
|
1322
|
+
specifier: quoted[2]
|
|
1323
|
+
};
|
|
1324
|
+
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
1325
|
+
if (!url) return;
|
|
1326
|
+
return {
|
|
1327
|
+
quote: url[1],
|
|
1328
|
+
raw: url[0],
|
|
1329
|
+
specifier: url[2] ?? url[3]
|
|
1330
|
+
};
|
|
1331
|
+
}
|
|
1332
|
+
function quoteCssImportSpecifier(specifier, quote = "\"") {
|
|
1333
|
+
return `${quote}${specifier.replaceAll("\\", "\\\\").replaceAll(quote, `\\${quote}`)}${quote}`;
|
|
1334
|
+
}
|
|
1335
|
+
function createTailwindV4CssImportSpecifierSet(packageName) {
|
|
1336
|
+
const specifiers = new Set(["tailwindcss"]);
|
|
1337
|
+
if (packageName && isBarePackageSpecifier(packageName)) specifiers.add(packageName);
|
|
1338
|
+
return specifiers;
|
|
1339
|
+
}
|
|
1340
|
+
function normalizeTailwindV4CssPackageImports(css, packageName) {
|
|
1341
|
+
if (!css.includes("tailwindcss")) return css;
|
|
1342
|
+
let root;
|
|
1343
|
+
try {
|
|
1344
|
+
root = postcss.default.parse(css);
|
|
1345
|
+
} catch {
|
|
1346
|
+
return css;
|
|
1347
|
+
}
|
|
1348
|
+
const importSpecifiers = createTailwindV4CssImportSpecifierSet(packageName);
|
|
1349
|
+
let changed = false;
|
|
1350
|
+
root.walkAtRules("import", (rule) => {
|
|
1351
|
+
const parsed = parseCssImportSpecifier(rule.params);
|
|
1352
|
+
if (!parsed || !importSpecifiers.has(parsed.specifier)) return;
|
|
1353
|
+
rule.params = rule.params.replace(parsed.raw, quoteCssImportSpecifier(`${parsed.specifier}/index.css`, parsed.quote));
|
|
1354
|
+
changed = true;
|
|
1355
|
+
});
|
|
1356
|
+
return changed ? root.toString() : css;
|
|
1357
|
+
}
|
|
1117
1358
|
function resolveTailwindCssImportTarget(patcher) {
|
|
1118
1359
|
const configuredPackageName = require_patcher_options.resolveTailwindcssOptions(patcher.options)?.packageName;
|
|
1119
1360
|
if (typeof configuredPackageName === "string" && configuredPackageName.length > 0 && !isPostcssPluginImportTarget(configuredPackageName)) return configuredPackageName;
|
|
@@ -1138,27 +1379,24 @@ function resolveTailwindV4SourceOptionsFromPatcher(patcher) {
|
|
|
1138
1379
|
};
|
|
1139
1380
|
}
|
|
1140
1381
|
function resolveTailwindV4Source(options) {
|
|
1141
|
-
return (0, tailwindcss_patch.resolveTailwindV4Source)(options
|
|
1382
|
+
return (0, tailwindcss_patch.resolveTailwindV4Source)(options?.css === void 0 ? options : {
|
|
1383
|
+
...options,
|
|
1384
|
+
css: normalizeTailwindV4CssPackageImports(options.css, options.packageName)
|
|
1385
|
+
});
|
|
1142
1386
|
}
|
|
1143
1387
|
async function resolveTailwindV4SourceFromPatcher(patcher) {
|
|
1144
|
-
return
|
|
1388
|
+
return resolveTailwindV4Source(resolveTailwindV4SourceOptionsFromPatcher(patcher));
|
|
1145
1389
|
}
|
|
1146
1390
|
//#endregion
|
|
1147
1391
|
//#region src/generator/options.ts
|
|
1148
1392
|
function normalizeWeappTailwindcssGeneratorOptions(options) {
|
|
1149
|
-
if (options
|
|
1150
|
-
mode: "off",
|
|
1151
|
-
target: "weapp",
|
|
1152
|
-
tailwindcssV3Compatibility: true
|
|
1153
|
-
};
|
|
1154
|
-
if (options === true || options == null) return {
|
|
1155
|
-
mode: "auto",
|
|
1393
|
+
if (options == null) return {
|
|
1156
1394
|
target: "weapp",
|
|
1157
1395
|
tailwindcssV3Compatibility: true
|
|
1158
1396
|
};
|
|
1159
1397
|
return {
|
|
1160
|
-
mode: options.mode ?? "auto",
|
|
1161
1398
|
target: options.target ?? "weapp",
|
|
1399
|
+
config: options.config,
|
|
1162
1400
|
styleOptions: options.styleOptions,
|
|
1163
1401
|
tailwindcssV3Compatibility: options.tailwindcssV3Compatibility ?? (options.target ?? "weapp") === "weapp"
|
|
1164
1402
|
};
|