@weapp-tailwindcss/postcss 3.2.7 → 3.2.9
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/css-macro/auto.d.ts +2 -4
- package/dist/css-macro/conditions.d.ts +6 -0
- package/dist/html-transform.cjs +5 -3
- package/dist/html-transform.js +4 -2
- package/dist/index.cjs +302 -120
- package/dist/index.d.ts +1 -0
- package/dist/index.js +301 -120
- package/dist/{rolldown-runtime-D6vf50IK.cjs → rolldown-runtime-VH7oDXx4.cjs} +1 -1
- package/dist/selectorParser/pseudo.d.ts +1 -0
- package/dist/selectorParser/rule-transformer/types.d.ts +1 -0
- package/dist/selectorParser/rule-transformer/unsupported-pseudos.d.ts +5 -0
- package/dist/selectorParser.d.ts +1 -0
- package/dist/types.d.ts +13 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_rolldown_runtime = require("./rolldown-runtime-
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.cjs");
|
|
3
3
|
const require_postcss = require("./postcss-CfbYRXJi.cjs");
|
|
4
4
|
const require_html_transform = require("./html-transform.cjs");
|
|
5
5
|
require("./types.cjs");
|
|
@@ -231,7 +231,8 @@ function trimNodes$1(nodes) {
|
|
|
231
231
|
}
|
|
232
232
|
function getParsedColorData(colorSource) {
|
|
233
233
|
try {
|
|
234
|
-
|
|
234
|
+
const parsed = (0, _csstools_css_parser_algorithms.parseComponentValue)((0, _csstools_css_tokenizer.tokenize)({ css: colorSource }));
|
|
235
|
+
return (0, _csstools_css_color_parser.color)(parsed);
|
|
235
236
|
} catch {
|
|
236
237
|
return false;
|
|
237
238
|
}
|
|
@@ -3263,8 +3264,7 @@ function transformWebCssSafeSelectors(css, options) {
|
|
|
3263
3264
|
}
|
|
3264
3265
|
}
|
|
3265
3266
|
//#endregion
|
|
3266
|
-
//#region src/css-macro/
|
|
3267
|
-
const CSS_MACRO_STYLE_OPTIONS_MARKER = "__weappTailwindcssCssMacroEnabled";
|
|
3267
|
+
//#region src/css-macro/conditions.ts
|
|
3268
3268
|
const PLATFORM_ENV_KEYS$1 = [
|
|
3269
3269
|
"WEAPP_TW_TARGET",
|
|
3270
3270
|
"WEAPP_TAILWINDCSS_TARGET",
|
|
@@ -3276,9 +3276,6 @@ const PLATFORM_ENV_KEYS$1 = [
|
|
|
3276
3276
|
];
|
|
3277
3277
|
const CONDITIONAL_END_RE = /^\s*#endif\s*$/;
|
|
3278
3278
|
const CUSTOM_VARIANT_CONDITIONAL_FALLBACK_RE = /@custom-variant\b[\s\S]*?\/\*\s*#ifn?def\s[^*]*\*\/[\s\S]*?@slot\b[\s\S]*?\/\*\s*#endif\s*\*\//;
|
|
3279
|
-
function readEnvValue$1(key) {
|
|
3280
|
-
return typeof node_process.default === "undefined" ? void 0 : node_process.default.env[key];
|
|
3281
|
-
}
|
|
3282
3279
|
function normalizePlatformToken(value) {
|
|
3283
3280
|
return value?.trim().replaceAll("_", "-").toUpperCase() || void 0;
|
|
3284
3281
|
}
|
|
@@ -3286,7 +3283,7 @@ function resolveCssMacroPlatform(options) {
|
|
|
3286
3283
|
const explicit = normalizePlatformToken(options?.platform);
|
|
3287
3284
|
if (explicit) return explicit;
|
|
3288
3285
|
for (const key of PLATFORM_ENV_KEYS$1) {
|
|
3289
|
-
const value = normalizePlatformToken(
|
|
3286
|
+
const value = normalizePlatformToken(node_process.default.env[key]);
|
|
3290
3287
|
if (value) return value;
|
|
3291
3288
|
}
|
|
3292
3289
|
}
|
|
@@ -3356,45 +3353,84 @@ function quoteAtRuleParam(value) {
|
|
|
3356
3353
|
function hasSlotNode(nodes) {
|
|
3357
3354
|
return nodes.some((node) => node.type === "atrule" && node.name === "slot");
|
|
3358
3355
|
}
|
|
3356
|
+
function createConditionalAtRule(start, nodes) {
|
|
3357
|
+
const rule = postcss.default.atRule({
|
|
3358
|
+
name: start.directive === "ifndef" ? require_postcss.ifndefAtRule : require_postcss.ifdefAtRule,
|
|
3359
|
+
params: quoteAtRuleParam(start.expression)
|
|
3360
|
+
});
|
|
3361
|
+
rule.append(...nodes.map((node) => node.clone()));
|
|
3362
|
+
return rule;
|
|
3363
|
+
}
|
|
3364
|
+
function findConditionalEnd(nodes, index) {
|
|
3365
|
+
let depth = 1;
|
|
3366
|
+
for (let searchIndex = index + 1; searchIndex < nodes.length; searchIndex += 1) {
|
|
3367
|
+
const current = nodes[searchIndex];
|
|
3368
|
+
if (current?.type !== "comment") continue;
|
|
3369
|
+
if (parseConditionalStart(current.text)) depth += 1;
|
|
3370
|
+
else if (CONDITIONAL_END_RE.test(current.text) && --depth === 0) return searchIndex;
|
|
3371
|
+
}
|
|
3372
|
+
return -1;
|
|
3373
|
+
}
|
|
3359
3374
|
function rewriteCustomVariantConditionalComments(root) {
|
|
3360
3375
|
let changed = false;
|
|
3361
|
-
|
|
3362
|
-
const nodes = [...
|
|
3376
|
+
const transformContainer = (container, variant) => {
|
|
3377
|
+
const nodes = [...container.nodes ?? []];
|
|
3363
3378
|
for (let index = 0; index < nodes.length; index += 1) {
|
|
3364
3379
|
const node = nodes[index];
|
|
3365
|
-
|
|
3366
|
-
const start = parseConditionalStart(node.text);
|
|
3380
|
+
const start = node?.type === "comment" ? parseConditionalStart(node.text) : void 0;
|
|
3367
3381
|
if (!start) continue;
|
|
3368
|
-
|
|
3369
|
-
let endIndex = -1;
|
|
3370
|
-
for (let searchIndex = index + 1; searchIndex < nodes.length; searchIndex += 1) {
|
|
3371
|
-
const current = nodes[searchIndex];
|
|
3372
|
-
if (current?.type !== "comment") continue;
|
|
3373
|
-
if (parseConditionalStart(current.text)) {
|
|
3374
|
-
depth += 1;
|
|
3375
|
-
continue;
|
|
3376
|
-
}
|
|
3377
|
-
if (CONDITIONAL_END_RE.test(current.text)) {
|
|
3378
|
-
depth -= 1;
|
|
3379
|
-
if (depth === 0) {
|
|
3380
|
-
endIndex = searchIndex;
|
|
3381
|
-
break;
|
|
3382
|
-
}
|
|
3383
|
-
}
|
|
3384
|
-
}
|
|
3382
|
+
const endIndex = findConditionalEnd(nodes, index);
|
|
3385
3383
|
if (endIndex < 0) continue;
|
|
3386
3384
|
const conditionalNodes = nodes.slice(index + 1, endIndex);
|
|
3387
3385
|
if (!hasSlotNode(conditionalNodes)) continue;
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3386
|
+
if (container !== variant) {
|
|
3387
|
+
node.remove();
|
|
3388
|
+
nodes[endIndex]?.remove();
|
|
3389
|
+
const variantNodes = [...variant.nodes ?? []];
|
|
3390
|
+
variant.removeAll();
|
|
3391
|
+
variant.append(createConditionalAtRule(start, variantNodes));
|
|
3392
|
+
changed = true;
|
|
3393
|
+
return true;
|
|
3394
|
+
}
|
|
3395
|
+
node.replaceWith(createConditionalAtRule(start, conditionalNodes));
|
|
3394
3396
|
for (const removedNode of nodes.slice(index + 1, endIndex + 1)) removedNode.remove();
|
|
3395
3397
|
changed = true;
|
|
3396
3398
|
}
|
|
3397
|
-
|
|
3399
|
+
for (const node of [...container.nodes ?? []]) if ("nodes" in node && node.nodes && transformContainer(node, variant)) return true;
|
|
3400
|
+
return false;
|
|
3401
|
+
};
|
|
3402
|
+
const variants = [];
|
|
3403
|
+
root.walkAtRules("custom-variant", (rule) => variants.push(rule));
|
|
3404
|
+
for (const variant of variants) transformContainer(variant, variant);
|
|
3405
|
+
return changed;
|
|
3406
|
+
}
|
|
3407
|
+
function rewriteOuterCustomVariantConditionalComments(root) {
|
|
3408
|
+
let changed = false;
|
|
3409
|
+
const transformContainer = (container) => {
|
|
3410
|
+
const nodes = [...container.nodes ?? []];
|
|
3411
|
+
for (let index = 0; index < nodes.length; index += 1) {
|
|
3412
|
+
const node = nodes[index];
|
|
3413
|
+
const start = node?.type === "comment" ? parseConditionalStart(node.text) : void 0;
|
|
3414
|
+
if (!start) continue;
|
|
3415
|
+
const endIndex = findConditionalEnd(nodes, index);
|
|
3416
|
+
if (endIndex < 0) continue;
|
|
3417
|
+
const conditionalNodes = nodes.slice(index + 1, endIndex);
|
|
3418
|
+
const customVariants = conditionalNodes.filter((current) => current.type === "atrule" && current.name === "custom-variant");
|
|
3419
|
+
if (customVariants.length === 0 || customVariants.some((variant) => !variant.nodes?.length)) continue;
|
|
3420
|
+
for (const variant of customVariants) {
|
|
3421
|
+
const variantNodes = [...variant.nodes ?? []];
|
|
3422
|
+
variant.removeAll();
|
|
3423
|
+
variant.append(createConditionalAtRule(start, variantNodes));
|
|
3424
|
+
}
|
|
3425
|
+
if (conditionalNodes.every((current) => current.type === "comment" || current.type === "atrule" && current.name === "custom-variant")) {
|
|
3426
|
+
node.remove();
|
|
3427
|
+
for (const removedNode of nodes.slice(index + 1, endIndex + 1)) if (removedNode.type === "comment") removedNode.remove();
|
|
3428
|
+
}
|
|
3429
|
+
changed = true;
|
|
3430
|
+
}
|
|
3431
|
+
for (const node of [...container.nodes ?? []]) if ("nodes" in node && node.nodes) transformContainer(node);
|
|
3432
|
+
};
|
|
3433
|
+
transformContainer(root);
|
|
3398
3434
|
return changed;
|
|
3399
3435
|
}
|
|
3400
3436
|
function compileCssMacroConditionalComments(css, options) {
|
|
@@ -3420,11 +3456,8 @@ function compileCssMacroConditionalComments(css, options) {
|
|
|
3420
3456
|
continue;
|
|
3421
3457
|
}
|
|
3422
3458
|
}
|
|
3423
|
-
if (getActiveConditionalValue(stack) === false)
|
|
3424
|
-
|
|
3425
|
-
continue;
|
|
3426
|
-
}
|
|
3427
|
-
if ("nodes" in node && node.nodes) transformContainer(node);
|
|
3459
|
+
if (getActiveConditionalValue(stack) === false) node.remove();
|
|
3460
|
+
else if ("nodes" in node && node.nodes) transformContainer(node);
|
|
3428
3461
|
}
|
|
3429
3462
|
};
|
|
3430
3463
|
transformContainer(root);
|
|
@@ -3433,28 +3466,15 @@ function compileCssMacroConditionalComments(css, options) {
|
|
|
3433
3466
|
return css;
|
|
3434
3467
|
}
|
|
3435
3468
|
}
|
|
3436
|
-
function
|
|
3437
|
-
|
|
3438
|
-
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
3439
|
-
if (quoted) return quoted[2];
|
|
3440
|
-
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
3441
|
-
return url?.[2] ?? url?.[3];
|
|
3442
|
-
}
|
|
3443
|
-
function isCssMacroPluginRequest(request) {
|
|
3444
|
-
if (request === "weapp-tailwindcss/css-macro") return true;
|
|
3445
|
-
if (!request?.includes("css-macro")) return false;
|
|
3446
|
-
return node_path.default.basename(request).startsWith("css-macro");
|
|
3447
|
-
}
|
|
3448
|
-
function hasCssMacroTailwindV4Directive(css) {
|
|
3449
|
-
if (!css?.includes("css-macro")) return false;
|
|
3469
|
+
function transformCssMacroTailwindV4Source(css) {
|
|
3470
|
+
if (!hasCssMacroTailwindV4CustomVariantConditionalComments(css)) return css;
|
|
3450
3471
|
try {
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
return found;
|
|
3472
|
+
const root = postcss.default.parse(css);
|
|
3473
|
+
const outerChanged = rewriteOuterCustomVariantConditionalComments(root);
|
|
3474
|
+
const innerChanged = rewriteCustomVariantConditionalComments(root);
|
|
3475
|
+
return outerChanged || innerChanged ? root.toString() : css;
|
|
3456
3476
|
} catch {
|
|
3457
|
-
return
|
|
3477
|
+
return css;
|
|
3458
3478
|
}
|
|
3459
3479
|
}
|
|
3460
3480
|
function hasCssMacroTailwindV4CustomVariantConditionalComments(css) {
|
|
@@ -3462,18 +3482,31 @@ function hasCssMacroTailwindV4CustomVariantConditionalComments(css) {
|
|
|
3462
3482
|
try {
|
|
3463
3483
|
const root = postcss.default.parse(css);
|
|
3464
3484
|
let found = false;
|
|
3465
|
-
|
|
3466
|
-
const nodes = [...
|
|
3485
|
+
const hasConditionalSlot = (container) => {
|
|
3486
|
+
const nodes = [...container.nodes ?? []];
|
|
3467
3487
|
for (let index = 0; index < nodes.length; index += 1) {
|
|
3468
3488
|
const node = nodes[index];
|
|
3469
3489
|
if (node?.type !== "comment" || !parseConditionalStart(node.text)) continue;
|
|
3470
3490
|
const tail = nodes.slice(index + 1);
|
|
3471
|
-
if (tail.some((current) => current.type === "comment" && CONDITIONAL_END_RE.test(current.text)) && hasSlotNode(tail))
|
|
3472
|
-
found = true;
|
|
3473
|
-
return false;
|
|
3474
|
-
}
|
|
3491
|
+
if (tail.some((current) => current.type === "comment" && CONDITIONAL_END_RE.test(current.text)) && hasSlotNode(tail)) return true;
|
|
3475
3492
|
}
|
|
3493
|
+
return nodes.some((node) => "nodes" in node && node.nodes && hasConditionalSlot(node));
|
|
3494
|
+
};
|
|
3495
|
+
root.walkAtRules("custom-variant", (rule) => {
|
|
3496
|
+
if (hasConditionalSlot(rule)) found = true;
|
|
3476
3497
|
});
|
|
3498
|
+
const scanOuterConditional = (container) => {
|
|
3499
|
+
const nodes = [...container.nodes ?? []];
|
|
3500
|
+
for (let index = 0; index < nodes.length; index += 1) {
|
|
3501
|
+
const node = nodes[index];
|
|
3502
|
+
if (node?.type !== "comment" || !parseConditionalStart(node.text)) continue;
|
|
3503
|
+
const endIndex = findConditionalEnd(nodes, index);
|
|
3504
|
+
if (endIndex < 0) continue;
|
|
3505
|
+
if (nodes.slice(index + 1, endIndex).some((current) => current.type === "atrule" && current.name === "custom-variant")) return true;
|
|
3506
|
+
}
|
|
3507
|
+
return nodes.some((node) => "nodes" in node && node.nodes && scanOuterConditional(node));
|
|
3508
|
+
};
|
|
3509
|
+
found ||= scanOuterConditional(root);
|
|
3477
3510
|
return found;
|
|
3478
3511
|
} catch {
|
|
3479
3512
|
return CUSTOM_VARIANT_CONDITIONAL_FALLBACK_RE.test(css);
|
|
@@ -3484,28 +3517,42 @@ function hasCssMacroTailwindV4InternalAtRules(css) {
|
|
|
3484
3517
|
try {
|
|
3485
3518
|
let found = false;
|
|
3486
3519
|
postcss.default.parse(css).walkAtRules((rule) => {
|
|
3487
|
-
if (rule.name === "weapp-tw-ifdef" || rule.name === "weapp-tw-ifndef")
|
|
3488
|
-
found = true;
|
|
3489
|
-
return false;
|
|
3490
|
-
}
|
|
3520
|
+
if (rule.name === "weapp-tw-ifdef" || rule.name === "weapp-tw-ifndef") found = true;
|
|
3491
3521
|
});
|
|
3492
3522
|
return found;
|
|
3493
3523
|
} catch {
|
|
3494
3524
|
return /@weapp-tw-ifn?def\b/.test(css);
|
|
3495
3525
|
}
|
|
3496
3526
|
}
|
|
3497
|
-
|
|
3498
|
-
|
|
3527
|
+
//#endregion
|
|
3528
|
+
//#region src/css-macro/auto.ts
|
|
3529
|
+
const CSS_MACRO_STYLE_OPTIONS_MARKER = "__weappTailwindcssCssMacroEnabled";
|
|
3530
|
+
function parseCssPluginRequest(params) {
|
|
3531
|
+
const value = params.trim();
|
|
3532
|
+
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
3533
|
+
if (quoted) return quoted[2];
|
|
3534
|
+
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
3535
|
+
return url?.[2] ?? url?.[3];
|
|
3499
3536
|
}
|
|
3500
|
-
function
|
|
3501
|
-
if (
|
|
3537
|
+
function isCssMacroPluginRequest(request) {
|
|
3538
|
+
if (request === "weapp-tailwindcss/css-macro") return true;
|
|
3539
|
+
return Boolean(request?.includes("css-macro") && node_path.default.basename(request).startsWith("css-macro"));
|
|
3540
|
+
}
|
|
3541
|
+
function hasCssMacroTailwindV4Directive(css) {
|
|
3542
|
+
if (!css?.includes("css-macro")) return false;
|
|
3502
3543
|
try {
|
|
3503
|
-
|
|
3504
|
-
|
|
3544
|
+
let found = false;
|
|
3545
|
+
postcss.default.parse(css).walkAtRules("plugin", (rule) => {
|
|
3546
|
+
if (isCssMacroPluginRequest(parseCssPluginRequest(rule.params))) found = true;
|
|
3547
|
+
});
|
|
3548
|
+
return found;
|
|
3505
3549
|
} catch {
|
|
3506
|
-
return css;
|
|
3550
|
+
return /@plugin\s+(?:url\(\s*)?["']weapp-tailwindcss\/css-macro["']/.test(css);
|
|
3507
3551
|
}
|
|
3508
3552
|
}
|
|
3553
|
+
function hasCssMacroTailwindV4Source(css) {
|
|
3554
|
+
return hasCssMacroTailwindV4Directive(css) || hasCssMacroTailwindV4CustomVariantConditionalComments(css) || hasCssMacroTailwindV4InternalAtRules(css);
|
|
3555
|
+
}
|
|
3509
3556
|
function isCssMacroPostcssPlugin(plugin) {
|
|
3510
3557
|
if (plugin === require_postcss.creator) return true;
|
|
3511
3558
|
return Boolean(plugin && (typeof plugin === "function" || typeof plugin === "object") && plugin.postcssPlugin === "postcss-weapp-tw-css-macro-plugin");
|
|
@@ -3516,8 +3563,7 @@ function withCssMacroPostcssPlugins(plugins) {
|
|
|
3516
3563
|
if (Array.isArray(plugins)) return plugins.some(isCssMacroPostcssPlugin) ? plugins : [...plugins, macroPlugin];
|
|
3517
3564
|
if (typeof plugins === "object") {
|
|
3518
3565
|
const values = Object.values(plugins).filter(Boolean);
|
|
3519
|
-
|
|
3520
|
-
return [...values, macroPlugin];
|
|
3566
|
+
return values.some(isCssMacroPostcssPlugin) ? values : [...values, macroPlugin];
|
|
3521
3567
|
}
|
|
3522
3568
|
return [macroPlugin];
|
|
3523
3569
|
}
|
|
@@ -4626,6 +4672,7 @@ function getDefaultOptions(options) {
|
|
|
4626
4672
|
autoprefixer: { add: false }
|
|
4627
4673
|
},
|
|
4628
4674
|
cssRemoveProperty: true,
|
|
4675
|
+
cssRemoveFocusPseudoClass: true,
|
|
4629
4676
|
uniAppXUnsupported: "warn",
|
|
4630
4677
|
cssSelectorReplacement: {
|
|
4631
4678
|
root: [
|
|
@@ -4673,7 +4720,9 @@ const CSS_OPTION_KEYS = [
|
|
|
4673
4720
|
"unitsToPx",
|
|
4674
4721
|
"unitConversion",
|
|
4675
4722
|
"platform",
|
|
4723
|
+
"cssRemoveActivePseudoClass",
|
|
4676
4724
|
"cssRemoveHoverPseudoClass",
|
|
4725
|
+
"cssRemoveFocusPseudoClass",
|
|
4677
4726
|
"cssRemoveProperty",
|
|
4678
4727
|
"cssCalc",
|
|
4679
4728
|
"atRules",
|
|
@@ -4683,7 +4732,9 @@ function getSimpleOverrideCacheKey(options) {
|
|
|
4683
4732
|
let isMainChunk = SIMPLE_OVERRIDE_UNSET;
|
|
4684
4733
|
let majorVersion = SIMPLE_OVERRIDE_UNSET;
|
|
4685
4734
|
let cssRemoveProperty = SIMPLE_OVERRIDE_UNSET;
|
|
4735
|
+
let cssRemoveActivePseudoClass = SIMPLE_OVERRIDE_UNSET;
|
|
4686
4736
|
let cssRemoveHoverPseudoClass = SIMPLE_OVERRIDE_UNSET;
|
|
4737
|
+
let cssRemoveFocusPseudoClass = SIMPLE_OVERRIDE_UNSET;
|
|
4687
4738
|
let uniAppX = SIMPLE_OVERRIDE_UNSET;
|
|
4688
4739
|
let cssPreflightRange = SIMPLE_OVERRIDE_UNSET;
|
|
4689
4740
|
let injectAdditionalCssVarScope = SIMPLE_OVERRIDE_UNSET;
|
|
@@ -4715,6 +4766,14 @@ function getSimpleOverrideCacheKey(options) {
|
|
|
4715
4766
|
if (typeof value !== "boolean") return;
|
|
4716
4767
|
cssRemoveHoverPseudoClass = value ? "1" : "0";
|
|
4717
4768
|
break;
|
|
4769
|
+
case "cssRemoveActivePseudoClass":
|
|
4770
|
+
if (typeof value !== "boolean") return;
|
|
4771
|
+
cssRemoveActivePseudoClass = value ? "1" : "0";
|
|
4772
|
+
break;
|
|
4773
|
+
case "cssRemoveFocusPseudoClass":
|
|
4774
|
+
if (typeof value !== "boolean") return;
|
|
4775
|
+
cssRemoveFocusPseudoClass = value ? "1" : "0";
|
|
4776
|
+
break;
|
|
4718
4777
|
case "uniAppX":
|
|
4719
4778
|
if (typeof value !== "boolean") return;
|
|
4720
4779
|
uniAppX = value ? "1" : "0";
|
|
@@ -4771,7 +4830,9 @@ function getSimpleOverrideCacheKey(options) {
|
|
|
4771
4830
|
isMainChunk,
|
|
4772
4831
|
majorVersion,
|
|
4773
4832
|
cssRemoveProperty,
|
|
4833
|
+
cssRemoveActivePseudoClass,
|
|
4774
4834
|
cssRemoveHoverPseudoClass,
|
|
4835
|
+
cssRemoveFocusPseudoClass,
|
|
4775
4836
|
uniAppX,
|
|
4776
4837
|
cssPreflightRange,
|
|
4777
4838
|
injectAdditionalCssVarScope,
|
|
@@ -5023,26 +5084,45 @@ function getCustomPropertyCleaner(options) {
|
|
|
5023
5084
|
const includeCustomProperties = Array.isArray(options.cssCalc) ? options.cssCalc : typeof options.cssCalc === "object" ? options.cssCalc.includeCustomProperties : [];
|
|
5024
5085
|
if (!(Array.isArray(includeCustomProperties) && includeCustomProperties.length > 0)) return null;
|
|
5025
5086
|
const shouldInspectValue = (value) => value.includes("var(") && value.includes("--");
|
|
5087
|
+
const containsIncludedCustomProperty = (value) => {
|
|
5088
|
+
if (!shouldInspectValue(value)) return false;
|
|
5089
|
+
const parsed = (0, postcss_value_parser.default)(value);
|
|
5090
|
+
let containsIncludedCustomProperty = false;
|
|
5091
|
+
parsed.walk((node) => {
|
|
5092
|
+
if (node.type !== "function" || node.value !== "var" || containsIncludedCustomProperty) return;
|
|
5093
|
+
if (node.nodes.find((x) => {
|
|
5094
|
+
return x.type === "word" && (0, _weapp_tailwindcss_shared.regExpTest)(includeCustomProperties, x.value);
|
|
5095
|
+
})) containsIncludedCustomProperty = true;
|
|
5096
|
+
});
|
|
5097
|
+
return containsIncludedCustomProperty;
|
|
5098
|
+
};
|
|
5099
|
+
const hasSameSourceRange = (left, right) => {
|
|
5100
|
+
const leftSource = left.source;
|
|
5101
|
+
const rightSource = right.source;
|
|
5102
|
+
if (!leftSource?.start || !leftSource.end || !rightSource?.start || !rightSource.end || leftSource.input !== rightSource.input) return false;
|
|
5103
|
+
return leftSource.start.line === rightSource.start.line && leftSource.start.column === rightSource.start.column && leftSource.end.line === rightSource.end.line && leftSource.end.column === rightSource.end.column;
|
|
5104
|
+
};
|
|
5026
5105
|
return {
|
|
5027
5106
|
postcssPlugin: "postcss-remove-include-custom-properties",
|
|
5028
5107
|
OnceExit(root) {
|
|
5029
5108
|
root.walkDecls((decl) => {
|
|
5030
5109
|
const prevNode = decl.prev();
|
|
5031
|
-
if (
|
|
5032
|
-
if (prevNode.value === decl.value) {
|
|
5110
|
+
if (prevNode && prevNode.type === "decl" && prevNode.prop === decl.prop && prevNode.important === decl.important && prevNode.value === decl.value) {
|
|
5033
5111
|
decl.remove();
|
|
5034
5112
|
return;
|
|
5035
5113
|
}
|
|
5036
|
-
if (!
|
|
5037
|
-
|
|
5038
|
-
let
|
|
5039
|
-
|
|
5040
|
-
if (node.type
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
}
|
|
5044
|
-
|
|
5045
|
-
|
|
5114
|
+
if (!containsIncludedCustomProperty(decl.value)) return;
|
|
5115
|
+
let fallbackDecl;
|
|
5116
|
+
let node = prevNode;
|
|
5117
|
+
while (node) {
|
|
5118
|
+
if (node.type === "decl" && node.prop === decl.prop) {
|
|
5119
|
+
fallbackDecl = node;
|
|
5120
|
+
break;
|
|
5121
|
+
}
|
|
5122
|
+
node = node.prev();
|
|
5123
|
+
}
|
|
5124
|
+
if (!fallbackDecl || fallbackDecl.important !== decl.important || fallbackDecl !== prevNode && !hasSameSourceRange(fallbackDecl, decl) || containsIncludedCustomProperty(fallbackDecl.value)) return;
|
|
5125
|
+
decl.remove();
|
|
5046
5126
|
});
|
|
5047
5127
|
}
|
|
5048
5128
|
};
|
|
@@ -5086,7 +5166,8 @@ const defaultRemTransformOptions = {
|
|
|
5086
5166
|
function getRemTransformPlugin(options) {
|
|
5087
5167
|
if (!options.rem2rpx) return null;
|
|
5088
5168
|
if (options.rem2rpx === true) return (0, postcss_rem_to_responsive_pixel.default)(defaultRemTransformOptions);
|
|
5089
|
-
|
|
5169
|
+
const merged = (0, _weapp_tailwindcss_shared.defuOverrideArray)(options.rem2rpx, defaultStage);
|
|
5170
|
+
return (0, postcss_rem_to_responsive_pixel.default)(merged);
|
|
5090
5171
|
}
|
|
5091
5172
|
//#endregion
|
|
5092
5173
|
//#region src/plugins/getUnitConversionPlugin.ts
|
|
@@ -5326,9 +5407,10 @@ function getFallbackRemove(_rule, options) {
|
|
|
5326
5407
|
if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) maybeImportantId = true;
|
|
5327
5408
|
if (selector.type === "universal") selector.parent?.remove();
|
|
5328
5409
|
else if (selector.type === "pseudo") {
|
|
5329
|
-
if (selector.value === ":is")
|
|
5330
|
-
|
|
5331
|
-
|
|
5410
|
+
if (selector.value === ":is") {
|
|
5411
|
+
if (maybeImportantId && selector.nodes[0]?.type === "selector") selector.replaceWith(selector.nodes[0]);
|
|
5412
|
+
else selector.parent?.remove();
|
|
5413
|
+
} else if (selector.value === ":not") {
|
|
5332
5414
|
for (const x of selector.nodes) if (x.nodes.length === 1 && x.nodes[0].type === "id" && x.nodes[0].value === "#") x.nodes = [postcss_selector_parser.default.tag({ value: "#n" })];
|
|
5333
5415
|
}
|
|
5334
5416
|
} else if (selector.type === "attribute") {
|
|
@@ -5368,14 +5450,16 @@ function getFallbackRemove(_rule, options) {
|
|
|
5368
5450
|
} finally {
|
|
5369
5451
|
currentRule = void 0;
|
|
5370
5452
|
}
|
|
5371
|
-
if (transformOptions === FALLBACK_TRANSFORM_OPTIONS)
|
|
5372
|
-
targetRule.
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5453
|
+
if (transformOptions === FALLBACK_TRANSFORM_OPTIONS) {
|
|
5454
|
+
if (targetRule.parent == null) {
|
|
5455
|
+
targetRule.selector = "";
|
|
5456
|
+
writeSelectorCache(sourceSelector, { action: "remove" });
|
|
5457
|
+
} else if (targetRule.selector === sourceSelector) writeSelectorCache(sourceSelector, { action: "keep" });
|
|
5458
|
+
else writeSelectorCache(sourceSelector, {
|
|
5459
|
+
action: "update",
|
|
5460
|
+
selector: targetRule.selector
|
|
5461
|
+
});
|
|
5462
|
+
}
|
|
5379
5463
|
};
|
|
5380
5464
|
parser.transformSync = ((input, opts) => {
|
|
5381
5465
|
const transformOptions = opts ? normalizeTransformOptions(opts) : FALLBACK_TRANSFORM_OPTIONS;
|
|
@@ -5393,6 +5477,47 @@ function getFallbackRemove(_rule, options) {
|
|
|
5393
5477
|
return entry.parser;
|
|
5394
5478
|
}
|
|
5395
5479
|
//#endregion
|
|
5480
|
+
//#region src/selectorParser/pseudo.ts
|
|
5481
|
+
function selectorContainsPseudoClass(selector, pseudoClasses) {
|
|
5482
|
+
if (pseudoClasses.length === 0) return false;
|
|
5483
|
+
let attributeDepth = 0;
|
|
5484
|
+
let quote;
|
|
5485
|
+
let escaped = false;
|
|
5486
|
+
for (let index = 0; index < selector.length; index += 1) {
|
|
5487
|
+
const character = selector[index];
|
|
5488
|
+
if (escaped) {
|
|
5489
|
+
escaped = false;
|
|
5490
|
+
continue;
|
|
5491
|
+
}
|
|
5492
|
+
if (character === "\\") {
|
|
5493
|
+
escaped = true;
|
|
5494
|
+
continue;
|
|
5495
|
+
}
|
|
5496
|
+
if (quote) {
|
|
5497
|
+
if (character === quote) quote = void 0;
|
|
5498
|
+
continue;
|
|
5499
|
+
}
|
|
5500
|
+
if (character === "\"" || character === "'") {
|
|
5501
|
+
quote = character;
|
|
5502
|
+
continue;
|
|
5503
|
+
}
|
|
5504
|
+
if (character === "[") {
|
|
5505
|
+
attributeDepth += 1;
|
|
5506
|
+
continue;
|
|
5507
|
+
}
|
|
5508
|
+
if (character === "]") {
|
|
5509
|
+
attributeDepth = Math.max(0, attributeDepth - 1);
|
|
5510
|
+
continue;
|
|
5511
|
+
}
|
|
5512
|
+
if (attributeDepth > 0 || character !== ":") continue;
|
|
5513
|
+
let end = index + 1;
|
|
5514
|
+
while (end < selector.length && /[\w-]/.test(selector[end] ?? "")) end += 1;
|
|
5515
|
+
if (pseudoClasses.includes(selector.slice(index, end))) return true;
|
|
5516
|
+
index = end - 1;
|
|
5517
|
+
}
|
|
5518
|
+
return false;
|
|
5519
|
+
}
|
|
5520
|
+
//#endregion
|
|
5396
5521
|
//#region src/utils/decl-order.ts
|
|
5397
5522
|
/**
|
|
5398
5523
|
* 将同一规则内的声明重排,使字面量优先,带变量的声明靠后,保持各自相对顺序。
|
|
@@ -5502,6 +5627,53 @@ function normalizeSpacingDeclarations(rule) {
|
|
|
5502
5627
|
for (const declarations of grouped.values()) dedupeSpacingGroup(rule, declarations);
|
|
5503
5628
|
}
|
|
5504
5629
|
//#endregion
|
|
5630
|
+
//#region src/selectorParser/rule-transformer/unsupported-pseudos.ts
|
|
5631
|
+
const UNSUPPORTED_MINI_PROGRAM_PSEUDO_CLASS_SET = /* @__PURE__ */ new Set([
|
|
5632
|
+
":autofill",
|
|
5633
|
+
":checked",
|
|
5634
|
+
":default",
|
|
5635
|
+
":disabled",
|
|
5636
|
+
":enabled",
|
|
5637
|
+
":focus-visible",
|
|
5638
|
+
":focus-within",
|
|
5639
|
+
":fullscreen",
|
|
5640
|
+
":indeterminate",
|
|
5641
|
+
":in-range",
|
|
5642
|
+
":invalid",
|
|
5643
|
+
":modal",
|
|
5644
|
+
":open",
|
|
5645
|
+
":optional",
|
|
5646
|
+
":out-of-range",
|
|
5647
|
+
":placeholder-shown",
|
|
5648
|
+
":read-only",
|
|
5649
|
+
":read-write",
|
|
5650
|
+
":required",
|
|
5651
|
+
":target",
|
|
5652
|
+
":valid",
|
|
5653
|
+
":visited"
|
|
5654
|
+
]);
|
|
5655
|
+
const unsupportedPseudoClassSetCache = /* @__PURE__ */ new WeakMap();
|
|
5656
|
+
function getUnsupportedPseudoClassSet(options) {
|
|
5657
|
+
const cached = unsupportedPseudoClassSetCache.get(options);
|
|
5658
|
+
if (cached) return cached;
|
|
5659
|
+
const pseudoClasses = new Set(UNSUPPORTED_MINI_PROGRAM_PSEUDO_CLASS_SET);
|
|
5660
|
+
if (options.cssRemoveHoverPseudoClass) pseudoClasses.add(":hover");
|
|
5661
|
+
if (options.cssRemoveActivePseudoClass) pseudoClasses.add(":active");
|
|
5662
|
+
if (options.cssRemoveFocusPseudoClass) pseudoClasses.add(":focus");
|
|
5663
|
+
unsupportedPseudoClassSetCache.set(options, pseudoClasses);
|
|
5664
|
+
return pseudoClasses;
|
|
5665
|
+
}
|
|
5666
|
+
function findRootSelector(node) {
|
|
5667
|
+
let current = node;
|
|
5668
|
+
while (current.parent && current.parent.type !== "root") current = current.parent;
|
|
5669
|
+
return current.type === "selector" ? current : void 0;
|
|
5670
|
+
}
|
|
5671
|
+
function removeUnsupportedPseudoSelector(node, options, unsupportedPseudoClasses = getUnsupportedPseudoClassSet(options)) {
|
|
5672
|
+
if (node.type !== "pseudo" || !unsupportedPseudoClasses.has(node.value)) return false;
|
|
5673
|
+
findRootSelector(node)?.remove();
|
|
5674
|
+
return true;
|
|
5675
|
+
}
|
|
5676
|
+
//#endregion
|
|
5505
5677
|
//#region src/selectorParser/rule-transformer/pseudos.ts
|
|
5506
5678
|
const RTL_LANGUAGE_ANY_PSEUDO_SET = /* @__PURE__ */ new Set([
|
|
5507
5679
|
":-moz-any",
|
|
@@ -5635,6 +5807,12 @@ function transformExpandedSelectorNodes(selector, context) {
|
|
|
5635
5807
|
else if (node.type === "universal" && context.universalReplacement) node.value = context.universalReplacement;
|
|
5636
5808
|
});
|
|
5637
5809
|
}
|
|
5810
|
+
function transformExpandedUniversalNodes(selector, context) {
|
|
5811
|
+
if (!context.universalReplacement) return;
|
|
5812
|
+
selector.walk((node) => {
|
|
5813
|
+
if (node.type === "universal") node.value = context.universalReplacement;
|
|
5814
|
+
});
|
|
5815
|
+
}
|
|
5638
5816
|
function appendExpandedWhereSelectors(parent, index, branches, context) {
|
|
5639
5817
|
const root = parent.parent;
|
|
5640
5818
|
if (!root) return false;
|
|
@@ -5655,7 +5833,10 @@ function flattenWherePseudo(node, context, index, parent) {
|
|
|
5655
5833
|
for (const branch of branches) if (transformSpacingSelector(branch.nodes, context.options)) context.requiresSpacingNormalization = true;
|
|
5656
5834
|
if (branches.length > 1 && appendExpandedWhereSelectors(parent, index, branches, context)) return;
|
|
5657
5835
|
const targetSelector = branches[0];
|
|
5658
|
-
if (targetSelector)
|
|
5836
|
+
if (targetSelector) {
|
|
5837
|
+
transformExpandedUniversalNodes(targetSelector, context);
|
|
5838
|
+
node.replaceWith(...targetSelector.nodes.map((item) => item.clone()));
|
|
5839
|
+
}
|
|
5659
5840
|
if (parent.type === "selector" && parent.length === 0) parent.remove();
|
|
5660
5841
|
}
|
|
5661
5842
|
function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
|
|
@@ -5664,6 +5845,7 @@ function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
|
|
|
5664
5845
|
}
|
|
5665
5846
|
function handlePseudoNode(node, index, context, parent) {
|
|
5666
5847
|
if (node.type !== "pseudo") return;
|
|
5848
|
+
if (removeUnsupportedPseudoSelector(node, context.options, context.unsupportedPseudoClasses ?? getUnsupportedPseudoClassSet(context.options))) return;
|
|
5667
5849
|
if (isRtlLanguageAnyPseudo(node)) {
|
|
5668
5850
|
stripUnsupportedRtlLanguagePseudo(node);
|
|
5669
5851
|
return;
|
|
@@ -5689,10 +5871,6 @@ function handleUniversalNode(node, context) {
|
|
|
5689
5871
|
if (node.type !== "universal") return;
|
|
5690
5872
|
if (context.universalReplacement) node.value = context.universalReplacement;
|
|
5691
5873
|
}
|
|
5692
|
-
function shouldRemoveHoverSelector(selector, options) {
|
|
5693
|
-
if (!options.cssRemoveHoverPseudoClass) return false;
|
|
5694
|
-
return selector.nodes.some((node) => node.type === "pseudo" && node.value === ":hover");
|
|
5695
|
-
}
|
|
5696
5874
|
function isHiddenOrTemplateNotPseudo(node) {
|
|
5697
5875
|
if (!node || node.type !== "pseudo" || node.value !== ":not") return false;
|
|
5698
5876
|
const selector = node.first;
|
|
@@ -5723,8 +5901,10 @@ function handleSelectorNode(selector, context) {
|
|
|
5723
5901
|
selector.remove();
|
|
5724
5902
|
return;
|
|
5725
5903
|
}
|
|
5726
|
-
|
|
5727
|
-
|
|
5904
|
+
const unsupportedPseudoClasses = context.unsupportedPseudoClasses ?? getUnsupportedPseudoClassSet(context.options);
|
|
5905
|
+
const unsupportedPseudo = selector.nodes.find((node) => node.type === "pseudo" && unsupportedPseudoClasses.has(node.value));
|
|
5906
|
+
if (unsupportedPseudo) {
|
|
5907
|
+
removeUnsupportedPseudoSelector(unsupportedPseudo, context.options, unsupportedPseudoClasses);
|
|
5728
5908
|
return;
|
|
5729
5909
|
}
|
|
5730
5910
|
if (transformSpacingSelector(selector.nodes, context.options)) context.requiresSpacingNormalization = true;
|
|
@@ -5759,10 +5939,7 @@ function transformSelectors(selectors, context) {
|
|
|
5759
5939
|
handleCombinatorNode(node, index, context);
|
|
5760
5940
|
break;
|
|
5761
5941
|
case "tag":
|
|
5762
|
-
case "attribute":
|
|
5763
|
-
handleTagOrAttribute(node, context);
|
|
5764
|
-
break;
|
|
5765
|
-
default: break;
|
|
5942
|
+
case "attribute": handleTagOrAttribute(node, context);
|
|
5766
5943
|
}
|
|
5767
5944
|
});
|
|
5768
5945
|
if (context.requiresSpacingNormalization) normalizeSpacingDeclarations(context.rule);
|
|
@@ -5782,6 +5959,7 @@ function createRuleTransformer(options) {
|
|
|
5782
5959
|
const rootReplacement = options.cssSelectorReplacement?.root ? composeIsPseudo(options.cssSelectorReplacement.root) : void 0;
|
|
5783
5960
|
const universalReplacement = options.cssSelectorReplacement?.universal ? composeIsPseudo(options.cssSelectorReplacement.universal) : void 0;
|
|
5784
5961
|
const selectorReplacerOptions = options.escapeMap ? { escapeMap: options.escapeMap } : void 0;
|
|
5962
|
+
const unsupportedPseudoClasses = getUnsupportedPseudoClassSet(options);
|
|
5785
5963
|
function writeSelectorResultCache(selector, result) {
|
|
5786
5964
|
if (selectorResultCache.size >= selectorResultCacheLimit) selectorResultCache.clear();
|
|
5787
5965
|
selectorResultCache.set(selector, result);
|
|
@@ -5810,7 +5988,8 @@ function createRuleTransformer(options) {
|
|
|
5810
5988
|
rule,
|
|
5811
5989
|
rootReplacement,
|
|
5812
5990
|
universalReplacement,
|
|
5813
|
-
selectorReplacerOptions
|
|
5991
|
+
selectorReplacerOptions,
|
|
5992
|
+
unsupportedPseudoClasses
|
|
5814
5993
|
};
|
|
5815
5994
|
let wasRemoved = false;
|
|
5816
5995
|
let requiresSpacingNormalization = false;
|
|
@@ -6455,9 +6634,10 @@ const postcssWeappTailwindcssPrePlugin = (options) => {
|
|
|
6455
6634
|
ruleTransformSync(rule, opts);
|
|
6456
6635
|
},
|
|
6457
6636
|
AtRule(atRule) {
|
|
6458
|
-
if (isAtMediaHover(atRule))
|
|
6459
|
-
|
|
6460
|
-
|
|
6637
|
+
if (isAtMediaHover(atRule)) {
|
|
6638
|
+
if (atRule.nodes) atRule.replaceWith(atRule.nodes);
|
|
6639
|
+
else atRule.remove();
|
|
6640
|
+
} else if (atRule.name === "supports") {
|
|
6461
6641
|
if (COLOR_MIX_RE.test(atRule.params)) removeAtRuleAndEmptyAncestors(atRule);
|
|
6462
6642
|
else if (isTailwindcssV4LinearGradientSupports(atRule)) removeAtRuleAndEmptyAncestors(atRule);
|
|
6463
6643
|
else if (isTailwindcssV4DisplayP3Supports(atRule)) removeAtRuleAndEmptyAncestors(atRule);
|
|
@@ -6725,7 +6905,8 @@ var StyleProcessorCache = class {
|
|
|
6725
6905
|
const compositeKey = this.createCompositeCacheKey(optionsKey, signal);
|
|
6726
6906
|
let processor = this.processorCacheByKey.get(compositeKey);
|
|
6727
6907
|
if (!processor) {
|
|
6728
|
-
|
|
6908
|
+
const pipeline = this.getPipeline(options, signal);
|
|
6909
|
+
processor = (0, postcss.default)(pipeline.plugins);
|
|
6729
6910
|
this.processorCacheByKey.set(compositeKey, processor);
|
|
6730
6911
|
}
|
|
6731
6912
|
return processor;
|
|
@@ -7446,6 +7627,7 @@ exports.resolveTailwindSourceEntry = resolveTailwindSourceEntry;
|
|
|
7446
7627
|
exports.restoreLocalCssImports = restoreLocalCssImports;
|
|
7447
7628
|
exports.rewriteLocalCssImportRequestsForOutput = rewriteLocalCssImportRequestsForOutput;
|
|
7448
7629
|
exports.rewriteLocalCssImportRequestsForOutputRoot = rewriteLocalCssImportRequestsForOutputRoot;
|
|
7630
|
+
exports.selectorContainsPseudoClass = selectorContainsPseudoClass;
|
|
7449
7631
|
exports.splitLocalCssImports = splitLocalCssImports;
|
|
7450
7632
|
exports.splitLocalCssImportsRoot = splitLocalCssImportsRoot;
|
|
7451
7633
|
exports.stripMiniProgramCssSpecificityPlaceholders = stripMiniProgramCssSpecificityPlaceholders;
|