@weapp-tailwindcss/postcss 3.2.8 → 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 +271 -108
- package/dist/index.d.ts +1 -0
- package/dist/index.js +270 -108
- 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 +5 -5
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,
|
|
@@ -5105,7 +5166,8 @@ const defaultRemTransformOptions = {
|
|
|
5105
5166
|
function getRemTransformPlugin(options) {
|
|
5106
5167
|
if (!options.rem2rpx) return null;
|
|
5107
5168
|
if (options.rem2rpx === true) return (0, postcss_rem_to_responsive_pixel.default)(defaultRemTransformOptions);
|
|
5108
|
-
|
|
5169
|
+
const merged = (0, _weapp_tailwindcss_shared.defuOverrideArray)(options.rem2rpx, defaultStage);
|
|
5170
|
+
return (0, postcss_rem_to_responsive_pixel.default)(merged);
|
|
5109
5171
|
}
|
|
5110
5172
|
//#endregion
|
|
5111
5173
|
//#region src/plugins/getUnitConversionPlugin.ts
|
|
@@ -5345,9 +5407,10 @@ function getFallbackRemove(_rule, options) {
|
|
|
5345
5407
|
if (idx === 0 && (selector.type === "id" || selector.type === "class" || selector.type === "attribute")) maybeImportantId = true;
|
|
5346
5408
|
if (selector.type === "universal") selector.parent?.remove();
|
|
5347
5409
|
else if (selector.type === "pseudo") {
|
|
5348
|
-
if (selector.value === ":is")
|
|
5349
|
-
|
|
5350
|
-
|
|
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") {
|
|
5351
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" })];
|
|
5352
5415
|
}
|
|
5353
5416
|
} else if (selector.type === "attribute") {
|
|
@@ -5387,14 +5450,16 @@ function getFallbackRemove(_rule, options) {
|
|
|
5387
5450
|
} finally {
|
|
5388
5451
|
currentRule = void 0;
|
|
5389
5452
|
}
|
|
5390
|
-
if (transformOptions === FALLBACK_TRANSFORM_OPTIONS)
|
|
5391
|
-
targetRule.
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
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
|
+
}
|
|
5398
5463
|
};
|
|
5399
5464
|
parser.transformSync = ((input, opts) => {
|
|
5400
5465
|
const transformOptions = opts ? normalizeTransformOptions(opts) : FALLBACK_TRANSFORM_OPTIONS;
|
|
@@ -5412,6 +5477,47 @@ function getFallbackRemove(_rule, options) {
|
|
|
5412
5477
|
return entry.parser;
|
|
5413
5478
|
}
|
|
5414
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
|
|
5415
5521
|
//#region src/utils/decl-order.ts
|
|
5416
5522
|
/**
|
|
5417
5523
|
* 将同一规则内的声明重排,使字面量优先,带变量的声明靠后,保持各自相对顺序。
|
|
@@ -5521,6 +5627,53 @@ function normalizeSpacingDeclarations(rule) {
|
|
|
5521
5627
|
for (const declarations of grouped.values()) dedupeSpacingGroup(rule, declarations);
|
|
5522
5628
|
}
|
|
5523
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
|
|
5524
5677
|
//#region src/selectorParser/rule-transformer/pseudos.ts
|
|
5525
5678
|
const RTL_LANGUAGE_ANY_PSEUDO_SET = /* @__PURE__ */ new Set([
|
|
5526
5679
|
":-moz-any",
|
|
@@ -5654,6 +5807,12 @@ function transformExpandedSelectorNodes(selector, context) {
|
|
|
5654
5807
|
else if (node.type === "universal" && context.universalReplacement) node.value = context.universalReplacement;
|
|
5655
5808
|
});
|
|
5656
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
|
+
}
|
|
5657
5816
|
function appendExpandedWhereSelectors(parent, index, branches, context) {
|
|
5658
5817
|
const root = parent.parent;
|
|
5659
5818
|
if (!root) return false;
|
|
@@ -5674,7 +5833,10 @@ function flattenWherePseudo(node, context, index, parent) {
|
|
|
5674
5833
|
for (const branch of branches) if (transformSpacingSelector(branch.nodes, context.options)) context.requiresSpacingNormalization = true;
|
|
5675
5834
|
if (branches.length > 1 && appendExpandedWhereSelectors(parent, index, branches, context)) return;
|
|
5676
5835
|
const targetSelector = branches[0];
|
|
5677
|
-
if (targetSelector)
|
|
5836
|
+
if (targetSelector) {
|
|
5837
|
+
transformExpandedUniversalNodes(targetSelector, context);
|
|
5838
|
+
node.replaceWith(...targetSelector.nodes.map((item) => item.clone()));
|
|
5839
|
+
}
|
|
5678
5840
|
if (parent.type === "selector" && parent.length === 0) parent.remove();
|
|
5679
5841
|
}
|
|
5680
5842
|
function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
|
|
@@ -5683,6 +5845,7 @@ function shouldRemoveUnsupportedPseudoElementSelector(selector, options) {
|
|
|
5683
5845
|
}
|
|
5684
5846
|
function handlePseudoNode(node, index, context, parent) {
|
|
5685
5847
|
if (node.type !== "pseudo") return;
|
|
5848
|
+
if (removeUnsupportedPseudoSelector(node, context.options, context.unsupportedPseudoClasses ?? getUnsupportedPseudoClassSet(context.options))) return;
|
|
5686
5849
|
if (isRtlLanguageAnyPseudo(node)) {
|
|
5687
5850
|
stripUnsupportedRtlLanguagePseudo(node);
|
|
5688
5851
|
return;
|
|
@@ -5708,10 +5871,6 @@ function handleUniversalNode(node, context) {
|
|
|
5708
5871
|
if (node.type !== "universal") return;
|
|
5709
5872
|
if (context.universalReplacement) node.value = context.universalReplacement;
|
|
5710
5873
|
}
|
|
5711
|
-
function shouldRemoveHoverSelector(selector, options) {
|
|
5712
|
-
if (!options.cssRemoveHoverPseudoClass) return false;
|
|
5713
|
-
return selector.nodes.some((node) => node.type === "pseudo" && node.value === ":hover");
|
|
5714
|
-
}
|
|
5715
5874
|
function isHiddenOrTemplateNotPseudo(node) {
|
|
5716
5875
|
if (!node || node.type !== "pseudo" || node.value !== ":not") return false;
|
|
5717
5876
|
const selector = node.first;
|
|
@@ -5742,8 +5901,10 @@ function handleSelectorNode(selector, context) {
|
|
|
5742
5901
|
selector.remove();
|
|
5743
5902
|
return;
|
|
5744
5903
|
}
|
|
5745
|
-
|
|
5746
|
-
|
|
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);
|
|
5747
5908
|
return;
|
|
5748
5909
|
}
|
|
5749
5910
|
if (transformSpacingSelector(selector.nodes, context.options)) context.requiresSpacingNormalization = true;
|
|
@@ -5778,10 +5939,7 @@ function transformSelectors(selectors, context) {
|
|
|
5778
5939
|
handleCombinatorNode(node, index, context);
|
|
5779
5940
|
break;
|
|
5780
5941
|
case "tag":
|
|
5781
|
-
case "attribute":
|
|
5782
|
-
handleTagOrAttribute(node, context);
|
|
5783
|
-
break;
|
|
5784
|
-
default: break;
|
|
5942
|
+
case "attribute": handleTagOrAttribute(node, context);
|
|
5785
5943
|
}
|
|
5786
5944
|
});
|
|
5787
5945
|
if (context.requiresSpacingNormalization) normalizeSpacingDeclarations(context.rule);
|
|
@@ -5801,6 +5959,7 @@ function createRuleTransformer(options) {
|
|
|
5801
5959
|
const rootReplacement = options.cssSelectorReplacement?.root ? composeIsPseudo(options.cssSelectorReplacement.root) : void 0;
|
|
5802
5960
|
const universalReplacement = options.cssSelectorReplacement?.universal ? composeIsPseudo(options.cssSelectorReplacement.universal) : void 0;
|
|
5803
5961
|
const selectorReplacerOptions = options.escapeMap ? { escapeMap: options.escapeMap } : void 0;
|
|
5962
|
+
const unsupportedPseudoClasses = getUnsupportedPseudoClassSet(options);
|
|
5804
5963
|
function writeSelectorResultCache(selector, result) {
|
|
5805
5964
|
if (selectorResultCache.size >= selectorResultCacheLimit) selectorResultCache.clear();
|
|
5806
5965
|
selectorResultCache.set(selector, result);
|
|
@@ -5829,7 +5988,8 @@ function createRuleTransformer(options) {
|
|
|
5829
5988
|
rule,
|
|
5830
5989
|
rootReplacement,
|
|
5831
5990
|
universalReplacement,
|
|
5832
|
-
selectorReplacerOptions
|
|
5991
|
+
selectorReplacerOptions,
|
|
5992
|
+
unsupportedPseudoClasses
|
|
5833
5993
|
};
|
|
5834
5994
|
let wasRemoved = false;
|
|
5835
5995
|
let requiresSpacingNormalization = false;
|
|
@@ -6474,9 +6634,10 @@ const postcssWeappTailwindcssPrePlugin = (options) => {
|
|
|
6474
6634
|
ruleTransformSync(rule, opts);
|
|
6475
6635
|
},
|
|
6476
6636
|
AtRule(atRule) {
|
|
6477
|
-
if (isAtMediaHover(atRule))
|
|
6478
|
-
|
|
6479
|
-
|
|
6637
|
+
if (isAtMediaHover(atRule)) {
|
|
6638
|
+
if (atRule.nodes) atRule.replaceWith(atRule.nodes);
|
|
6639
|
+
else atRule.remove();
|
|
6640
|
+
} else if (atRule.name === "supports") {
|
|
6480
6641
|
if (COLOR_MIX_RE.test(atRule.params)) removeAtRuleAndEmptyAncestors(atRule);
|
|
6481
6642
|
else if (isTailwindcssV4LinearGradientSupports(atRule)) removeAtRuleAndEmptyAncestors(atRule);
|
|
6482
6643
|
else if (isTailwindcssV4DisplayP3Supports(atRule)) removeAtRuleAndEmptyAncestors(atRule);
|
|
@@ -6744,7 +6905,8 @@ var StyleProcessorCache = class {
|
|
|
6744
6905
|
const compositeKey = this.createCompositeCacheKey(optionsKey, signal);
|
|
6745
6906
|
let processor = this.processorCacheByKey.get(compositeKey);
|
|
6746
6907
|
if (!processor) {
|
|
6747
|
-
|
|
6908
|
+
const pipeline = this.getPipeline(options, signal);
|
|
6909
|
+
processor = (0, postcss.default)(pipeline.plugins);
|
|
6748
6910
|
this.processorCacheByKey.set(compositeKey, processor);
|
|
6749
6911
|
}
|
|
6750
6912
|
return processor;
|
|
@@ -7465,6 +7627,7 @@ exports.resolveTailwindSourceEntry = resolveTailwindSourceEntry;
|
|
|
7465
7627
|
exports.restoreLocalCssImports = restoreLocalCssImports;
|
|
7466
7628
|
exports.rewriteLocalCssImportRequestsForOutput = rewriteLocalCssImportRequestsForOutput;
|
|
7467
7629
|
exports.rewriteLocalCssImportRequestsForOutputRoot = rewriteLocalCssImportRequestsForOutputRoot;
|
|
7630
|
+
exports.selectorContainsPseudoClass = selectorContainsPseudoClass;
|
|
7468
7631
|
exports.splitLocalCssImports = splitLocalCssImports;
|
|
7469
7632
|
exports.splitLocalCssImportsRoot = splitLocalCssImportsRoot;
|
|
7470
7633
|
exports.stripMiniProgramCssSpecificityPlaceholders = stripMiniProgramCssSpecificityPlaceholders;
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { getPostcssPluginName, removeTailwindPostcssPlugins, resolveFilteredPost
|
|
|
21
21
|
export { postcss } from './postcss-runtime.js';
|
|
22
22
|
export type { AcceptedPlugin, AtRule, Container, Declaration, Document, Helpers, Plugin, PluginCreator, Node as PostcssNode, ProcessOptions, Processor, Result, Root, Rule, } from './postcss-runtime.js';
|
|
23
23
|
export { createInjectPreflight } from './preflight.js';
|
|
24
|
+
export { selectorContainsPseudoClass } from './selectorParser/pseudo.js';
|
|
24
25
|
export { internalCssSelectorReplacer } from './shared.js';
|
|
25
26
|
export { collectCssInlineSourceCandidates, createSourceScanPattern, createTailwindSourceEntryMatcher, expandInlineSourceCandidatePattern, expandTailwindSourceEntries, FULL_SOURCE_SCAN_EXTENSION_RE, FULL_SOURCE_SCAN_EXTENSIONS, FULL_SOURCE_SCAN_PATTERN, isFileExcludedByTailwindSourceEntries, isFileMatchedByTailwindSourceEntries, normalizeLegacyContentEntries, parseConfigParam, parseSourceFileParam, resolveCssSourceEntries, resolveSourceScanPath, resolveTailwindSourceEntry, type TailwindInlineSourceCandidates, type TailwindSourceEntry, toPosixPath, } from './source-scan.js';
|
|
26
27
|
export { createPostcssStyleTargetProfile, type PostcssStyleTarget, type PostcssStyleTargetProfile, } from './style-targets/index.js';
|