@weapp-tailwindcss/postcss 2.2.1-next.5 → 3.0.0-next.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compat/mini-program-css/at-rules.d.ts +7 -0
- package/dist/compat/mini-program-css/color-gamut.d.ts +3 -0
- package/dist/compat/mini-program-css/finalize.d.ts +12 -0
- package/dist/compat/mini-program-css/index.d.ts +3 -0
- package/dist/compat/mini-program-css/predicates.d.ts +10 -0
- package/dist/compat/mini-program-css/prune-generated.d.ts +8 -0
- package/dist/compat/mini-program-css/root-cleanups.d.ts +5 -0
- package/dist/compat/mini-program-css/selectors.d.ts +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +800 -3
- package/dist/index.mjs +783 -5
- package/dist/plugins/getUnitConversionPlugin.d.ts +5 -0
- package/dist/plugins/post/decl-dedupe.d.ts +1 -0
- package/dist/types.d.ts +16 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -22,6 +22,8 @@ let postcss_pxtrans = require("postcss-pxtrans");
|
|
|
22
22
|
postcss_pxtrans = require_html_transform.__toESM(postcss_pxtrans);
|
|
23
23
|
let postcss_rem_to_responsive_pixel = require("postcss-rem-to-responsive-pixel");
|
|
24
24
|
postcss_rem_to_responsive_pixel = require_html_transform.__toESM(postcss_rem_to_responsive_pixel);
|
|
25
|
+
let node_process = require("node:process");
|
|
26
|
+
node_process = require_html_transform.__toESM(node_process);
|
|
25
27
|
let postcss_rule_unit_converter = require("postcss-rule-unit-converter");
|
|
26
28
|
postcss_rule_unit_converter = require_html_transform.__toESM(postcss_rule_unit_converter);
|
|
27
29
|
let _weapp_core_escape = require("@weapp-core/escape");
|
|
@@ -274,6 +276,72 @@ function protectDynamicColorMixAlpha(css, options = {}) {
|
|
|
274
276
|
};
|
|
275
277
|
}
|
|
276
278
|
//#endregion
|
|
279
|
+
//#region src/compat/mini-program-css/at-rules.ts
|
|
280
|
+
const MINI_PROGRAM_UNSUPPORTED_AT_RULES = new Set(["property", "supports"]);
|
|
281
|
+
function removeAtRulesByScan(css, names) {
|
|
282
|
+
let index = 0;
|
|
283
|
+
let result = "";
|
|
284
|
+
const atRulePattern = new RegExp(`@(?:${[...names].join("|")})\\b`, "i");
|
|
285
|
+
while (index < css.length) {
|
|
286
|
+
const match = atRulePattern.exec(css.slice(index));
|
|
287
|
+
if (!match || match.index === void 0) {
|
|
288
|
+
result += css.slice(index);
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
const start = index + match.index;
|
|
292
|
+
result += css.slice(index, start);
|
|
293
|
+
const blockStart = css.indexOf("{", start);
|
|
294
|
+
if (blockStart === -1) {
|
|
295
|
+
result += css.slice(start);
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
let depth = 0;
|
|
299
|
+
let cursor = blockStart;
|
|
300
|
+
for (; cursor < css.length; cursor++) {
|
|
301
|
+
const char = css[cursor];
|
|
302
|
+
if (char === "{") depth++;
|
|
303
|
+
else if (char === "}") {
|
|
304
|
+
depth--;
|
|
305
|
+
if (depth === 0) {
|
|
306
|
+
cursor++;
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
index = cursor;
|
|
312
|
+
}
|
|
313
|
+
return result;
|
|
314
|
+
}
|
|
315
|
+
function removeUnsupportedMiniProgramAtRules(css) {
|
|
316
|
+
try {
|
|
317
|
+
const root = postcss.default.parse(css);
|
|
318
|
+
root.walkAtRules((atRule) => {
|
|
319
|
+
if (MINI_PROGRAM_UNSUPPORTED_AT_RULES.has(atRule.name)) atRule.remove();
|
|
320
|
+
});
|
|
321
|
+
root.walkAtRules((atRule) => {
|
|
322
|
+
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
323
|
+
});
|
|
324
|
+
return root.toString();
|
|
325
|
+
} catch {
|
|
326
|
+
return removeAtRulesByScan(css, MINI_PROGRAM_UNSUPPORTED_AT_RULES);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function removeUnsupportedAtSupports(css) {
|
|
330
|
+
return removeUnsupportedMiniProgramAtRules(css);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* 移除小程序不支持的 cascade layer 语法,同时保留 layer 内的实际规则。
|
|
334
|
+
*/
|
|
335
|
+
function removeUnsupportedCascadeLayers(root) {
|
|
336
|
+
root.walkAtRules("layer", (atRule) => {
|
|
337
|
+
if (!atRule.nodes || atRule.nodes.length === 0) {
|
|
338
|
+
atRule.remove();
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
atRule.replaceWith(...atRule.nodes);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
//#endregion
|
|
277
345
|
//#region src/compat/mini-program-prefixes.ts
|
|
278
346
|
const PRESERVED_WEBKIT_DECLARATION_PROPS = new Set([
|
|
279
347
|
"-webkit-box-orient",
|
|
@@ -286,7 +354,7 @@ const PRESERVED_WEBKIT_DECLARATION_PROPS = new Set([
|
|
|
286
354
|
]);
|
|
287
355
|
const PRESERVED_WEBKIT_VALUE_DECLARATIONS = new Map([["display", new Set(["-webkit-box"])], ["-webkit-background-clip", new Set(["text"])]]);
|
|
288
356
|
const TRANSITION_PROPS = new Set(["transition", "transition-property"]);
|
|
289
|
-
function splitTopLevelCommaList(value) {
|
|
357
|
+
function splitTopLevelCommaList$1(value) {
|
|
290
358
|
const parts = [];
|
|
291
359
|
let start = 0;
|
|
292
360
|
let depth = 0;
|
|
@@ -333,7 +401,7 @@ function isPreservedWebkitDeclaration(decl) {
|
|
|
333
401
|
return PRESERVED_WEBKIT_VALUE_DECLARATIONS.get(prop)?.has(decl.value.trim().toLowerCase()) ?? false;
|
|
334
402
|
}
|
|
335
403
|
function normalizeTransitionValue(value) {
|
|
336
|
-
return splitTopLevelCommaList(value).map((part) => part.trim()).filter((part) => part.length > 0 && !part.toLowerCase().startsWith("-webkit-")).join(", ");
|
|
404
|
+
return splitTopLevelCommaList$1(value).map((part) => part.trim()).filter((part) => part.length > 0 && !part.toLowerCase().startsWith("-webkit-")).join(", ");
|
|
337
405
|
}
|
|
338
406
|
function hasUnsupportedWebkitKeywordValue(decl) {
|
|
339
407
|
const value = decl.value.trim().toLowerCase();
|
|
@@ -364,6 +432,506 @@ function removeUnsupportedMiniProgramPrefixedAtRule(atRule) {
|
|
|
364
432
|
if (atRule.name.toLowerCase() === "-webkit-keyframes") atRule.remove();
|
|
365
433
|
}
|
|
366
434
|
//#endregion
|
|
435
|
+
//#region src/compat/mini-program-css/color-gamut.ts
|
|
436
|
+
const DISPLAY_P3_VALUE_RE$1 = /color\(\s*display-p3\b/i;
|
|
437
|
+
const COLOR_GAMUT_P3_RE$1 = /\(\s*color-gamut\s*:\s*p3\s*\)/i;
|
|
438
|
+
function isDisplayP3MediaRule(atRule) {
|
|
439
|
+
return atRule.name === "media" && COLOR_GAMUT_P3_RE$1.test(atRule.params);
|
|
440
|
+
}
|
|
441
|
+
function isDisplayP3Declaration(decl) {
|
|
442
|
+
return DISPLAY_P3_VALUE_RE$1.test(decl.value);
|
|
443
|
+
}
|
|
444
|
+
//#endregion
|
|
445
|
+
//#region src/compat/mini-program-css/selectors.ts
|
|
446
|
+
const MINI_PROGRAM_THEME_SCOPE_SELECTOR = ":host,page,.tw-root,wx-root-portal-content";
|
|
447
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTORS = new Set([
|
|
448
|
+
"*",
|
|
449
|
+
"view",
|
|
450
|
+
"text",
|
|
451
|
+
":before",
|
|
452
|
+
":after",
|
|
453
|
+
"::before",
|
|
454
|
+
"::after"
|
|
455
|
+
]);
|
|
456
|
+
const MINI_PROGRAM_THEME_SCOPE_SELECTORS = new Set([
|
|
457
|
+
":host",
|
|
458
|
+
":root",
|
|
459
|
+
"page",
|
|
460
|
+
".tw-root",
|
|
461
|
+
"wx-root-portal-content"
|
|
462
|
+
]);
|
|
463
|
+
const SPECIFICITY_PLACEHOLDER_SUFFIXES = [":not(#n)", ":not(#\\#)"];
|
|
464
|
+
const MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS = new Set([
|
|
465
|
+
":-moz-focusring",
|
|
466
|
+
":-moz-ui-invalid",
|
|
467
|
+
"::-webkit-calendar-picker-indicator",
|
|
468
|
+
"::-webkit-date-and-time-value",
|
|
469
|
+
"::-webkit-datetime-edit",
|
|
470
|
+
"::-webkit-datetime-edit-day-field",
|
|
471
|
+
"::-webkit-datetime-edit-fields-wrapper",
|
|
472
|
+
"::-webkit-datetime-edit-hour-field",
|
|
473
|
+
"::-webkit-datetime-edit-meridiem-field",
|
|
474
|
+
"::-webkit-datetime-edit-millisecond-field",
|
|
475
|
+
"::-webkit-datetime-edit-minute-field",
|
|
476
|
+
"::-webkit-datetime-edit-month-field",
|
|
477
|
+
"::-webkit-datetime-edit-second-field",
|
|
478
|
+
"::-webkit-datetime-edit-year-field",
|
|
479
|
+
"::-webkit-inner-spin-button",
|
|
480
|
+
"::-webkit-input-placeholder",
|
|
481
|
+
"::-webkit-outer-spin-button",
|
|
482
|
+
"::-webkit-search-decoration",
|
|
483
|
+
"::placeholder",
|
|
484
|
+
"[hidden]:where(:not([hidden='until-found']))"
|
|
485
|
+
]);
|
|
486
|
+
const MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS = new Set([
|
|
487
|
+
"a",
|
|
488
|
+
"abbr:where([title])",
|
|
489
|
+
"audio",
|
|
490
|
+
"b",
|
|
491
|
+
"button",
|
|
492
|
+
"canvas",
|
|
493
|
+
"code",
|
|
494
|
+
"embed",
|
|
495
|
+
"h1",
|
|
496
|
+
"h2",
|
|
497
|
+
"h3",
|
|
498
|
+
"h4",
|
|
499
|
+
"h5",
|
|
500
|
+
"h6",
|
|
501
|
+
"hr",
|
|
502
|
+
"html",
|
|
503
|
+
"iframe",
|
|
504
|
+
"img",
|
|
505
|
+
"input",
|
|
506
|
+
"input:where([type='button'],[type='reset'],[type='submit'])",
|
|
507
|
+
"kbd",
|
|
508
|
+
"menu",
|
|
509
|
+
"object",
|
|
510
|
+
"ol",
|
|
511
|
+
"optgroup",
|
|
512
|
+
"pre",
|
|
513
|
+
"progress",
|
|
514
|
+
"samp",
|
|
515
|
+
"select",
|
|
516
|
+
"select[multiple]optgroup",
|
|
517
|
+
"select[multiple]optgroupoption",
|
|
518
|
+
"select[size]optgroup",
|
|
519
|
+
"select[size]optgroupoption",
|
|
520
|
+
"small",
|
|
521
|
+
"strong",
|
|
522
|
+
"sub",
|
|
523
|
+
"summary",
|
|
524
|
+
"sup",
|
|
525
|
+
"svg",
|
|
526
|
+
"table",
|
|
527
|
+
"textarea",
|
|
528
|
+
"ul",
|
|
529
|
+
"video"
|
|
530
|
+
]);
|
|
531
|
+
function normalizeSelector$1(selector) {
|
|
532
|
+
return selector.trim().replace(/\s+/g, "");
|
|
533
|
+
}
|
|
534
|
+
function getRuleSelectors(rule) {
|
|
535
|
+
return rule.selector.split(",").map(normalizeSelector$1).filter(Boolean);
|
|
536
|
+
}
|
|
537
|
+
function isUnsupportedBrowserSelector(selector) {
|
|
538
|
+
const normalized = normalizeSelector$1(selector);
|
|
539
|
+
return MINI_PROGRAM_UNSUPPORTED_BROWSER_SELECTORS.has(normalized) || MINI_PROGRAM_UNSUPPORTED_BROWSER_TAG_SELECTORS.has(normalized);
|
|
540
|
+
}
|
|
541
|
+
function isMiniProgramPreflightSelector(selectors) {
|
|
542
|
+
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_PREFLIGHT_SELECTORS.has(selector)) && selectors.some((selector) => selector === "*" || selector === ":before" || selector === ":after" || selector === "::before" || selector === "::after");
|
|
543
|
+
}
|
|
544
|
+
function isMiniProgramThemeScopeSelector(selectors) {
|
|
545
|
+
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_THEME_SCOPE_SELECTORS.has(selector));
|
|
546
|
+
}
|
|
547
|
+
//#endregion
|
|
548
|
+
//#region src/compat/mini-program-css/predicates.ts
|
|
549
|
+
const PREFLIGHT_RESET_PROPS = new Set([
|
|
550
|
+
"box-sizing",
|
|
551
|
+
"border",
|
|
552
|
+
"border-width",
|
|
553
|
+
"border-style",
|
|
554
|
+
"border-color",
|
|
555
|
+
"margin",
|
|
556
|
+
"padding"
|
|
557
|
+
]);
|
|
558
|
+
const PSEUDO_CONTENT_SELECTOR_RE = /^(?:::before|::after|:before|:after)(?:,(?:::before|::after|:before|:after))*$/;
|
|
559
|
+
const TW_CONTENT_VAR_RE$1 = /var\(\s*--tw-content\b/;
|
|
560
|
+
function hasTailwindPreflightDeclaration(rule) {
|
|
561
|
+
let hasTailwindVar = false;
|
|
562
|
+
let hasResetProp = false;
|
|
563
|
+
rule.walkDecls((decl) => {
|
|
564
|
+
if (decl.prop.startsWith("--tw-")) hasTailwindVar = true;
|
|
565
|
+
if (PREFLIGHT_RESET_PROPS.has(decl.prop)) hasResetProp = true;
|
|
566
|
+
});
|
|
567
|
+
return hasTailwindVar || hasResetProp;
|
|
568
|
+
}
|
|
569
|
+
function hasTwContentDeclaration(rule) {
|
|
570
|
+
let hasContentInit = false;
|
|
571
|
+
rule.walkDecls("--tw-content", () => {
|
|
572
|
+
hasContentInit = true;
|
|
573
|
+
});
|
|
574
|
+
return hasContentInit;
|
|
575
|
+
}
|
|
576
|
+
function isCustomPropertyRule(rule) {
|
|
577
|
+
let hasDeclaration = false;
|
|
578
|
+
let allCustomProperties = true;
|
|
579
|
+
rule.each((node) => {
|
|
580
|
+
if (node.type !== "decl") return;
|
|
581
|
+
hasDeclaration = true;
|
|
582
|
+
if (!node.prop.startsWith("--")) allCustomProperties = false;
|
|
583
|
+
});
|
|
584
|
+
return hasDeclaration && allCustomProperties;
|
|
585
|
+
}
|
|
586
|
+
function isEmptyTwContentDeclaration(decl) {
|
|
587
|
+
return decl.prop === "--tw-content" && (decl.value === "\"\"" || decl.value === "''");
|
|
588
|
+
}
|
|
589
|
+
function isOnlyTwContentDeclarations(rule) {
|
|
590
|
+
let hasDeclaration = false;
|
|
591
|
+
let onlyContentVariable = true;
|
|
592
|
+
rule.walkDecls((decl) => {
|
|
593
|
+
hasDeclaration = true;
|
|
594
|
+
if (decl.prop !== "--tw-content") onlyContentVariable = false;
|
|
595
|
+
});
|
|
596
|
+
return hasDeclaration && onlyContentVariable;
|
|
597
|
+
}
|
|
598
|
+
function isPseudoContentInitRule(rule) {
|
|
599
|
+
const selector = rule.selector.replace(/\s+/g, "");
|
|
600
|
+
return PSEUDO_CONTENT_SELECTOR_RE.test(selector) && isOnlyTwContentDeclarations(rule);
|
|
601
|
+
}
|
|
602
|
+
function usesTwContentVariable(root) {
|
|
603
|
+
let used = false;
|
|
604
|
+
root.walkDecls((decl) => {
|
|
605
|
+
if (TW_CONTENT_VAR_RE$1.test(decl.value)) used = true;
|
|
606
|
+
});
|
|
607
|
+
return used;
|
|
608
|
+
}
|
|
609
|
+
function isMiniProgramPreflightRule(node) {
|
|
610
|
+
if (node.type !== "rule") return false;
|
|
611
|
+
return isMiniProgramPreflightSelector(getRuleSelectors(node)) && hasTailwindPreflightDeclaration(node);
|
|
612
|
+
}
|
|
613
|
+
function isMiniProgramThemeVariableRule(node) {
|
|
614
|
+
if (node.type !== "rule") return false;
|
|
615
|
+
return isMiniProgramThemeScopeSelector(getRuleSelectors(node)) && isCustomPropertyRule(node);
|
|
616
|
+
}
|
|
617
|
+
//#endregion
|
|
618
|
+
//#region src/compat/mini-program-css/root-cleanups.ts
|
|
619
|
+
function removeSpecificityPlaceholders(root) {
|
|
620
|
+
root.walkRules((rule) => {
|
|
621
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
622
|
+
let changed = false;
|
|
623
|
+
const selectors = rule.selectors.map((selector) => {
|
|
624
|
+
let next = selector;
|
|
625
|
+
for (const suffix of SPECIFICITY_PLACEHOLDER_SUFFIXES) if (next.includes(suffix)) next = next.split(suffix).join("");
|
|
626
|
+
if (next !== selector) changed = true;
|
|
627
|
+
return next;
|
|
628
|
+
});
|
|
629
|
+
if (changed) rule.selectors = selectors;
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
function removeEmptyAtRuleAncestors(parent) {
|
|
633
|
+
while (parent?.type === "atrule" && (!parent.nodes || parent.nodes.length === 0)) {
|
|
634
|
+
const nextParent = parent.parent;
|
|
635
|
+
parent.remove();
|
|
636
|
+
parent = nextParent?.type === "atrule" ? nextParent : void 0;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
function removeUnsupportedBrowserSelectors(root) {
|
|
640
|
+
root.walkRules((rule) => {
|
|
641
|
+
if (!rule.selectors || rule.selectors.length === 0) return;
|
|
642
|
+
const selectors = rule.selectors.filter((selector) => !isUnsupportedBrowserSelector(selector));
|
|
643
|
+
if (selectors.length === rule.selectors.length) return;
|
|
644
|
+
if (selectors.length === 0) {
|
|
645
|
+
const parent = rule.parent;
|
|
646
|
+
rule.remove();
|
|
647
|
+
removeEmptyAtRuleAncestors(parent);
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
rule.selectors = selectors;
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
function removeDeclarationAndEmptyRule$1(decl) {
|
|
654
|
+
const parent = decl.parent;
|
|
655
|
+
decl.remove();
|
|
656
|
+
if (parent?.type === "rule" && parent.nodes.length === 0) {
|
|
657
|
+
const ruleParent = parent.parent;
|
|
658
|
+
parent.remove();
|
|
659
|
+
removeEmptyAtRuleAncestors(ruleParent);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
function removeDisplayP3Declarations(root) {
|
|
663
|
+
root.walkAtRules((atRule) => {
|
|
664
|
+
if (isDisplayP3MediaRule(atRule)) {
|
|
665
|
+
const parent = atRule.parent;
|
|
666
|
+
atRule.remove();
|
|
667
|
+
removeEmptyAtRuleAncestors(parent);
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
}
|
|
671
|
+
function removeUnsupportedModernColorDeclarations(root) {
|
|
672
|
+
const customPropertyValues = /* @__PURE__ */ new Map();
|
|
673
|
+
root.walkDecls((decl) => {
|
|
674
|
+
if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
|
|
675
|
+
});
|
|
676
|
+
root.walkDecls((decl) => {
|
|
677
|
+
const normalized = normalizeModernColorValue(decl.value, customPropertyValues);
|
|
678
|
+
if (normalized.changed) {
|
|
679
|
+
decl.value = normalized.value;
|
|
680
|
+
if (decl.prop.startsWith("--")) customPropertyValues.set(decl.prop, decl.value.trim());
|
|
681
|
+
}
|
|
682
|
+
if (normalized.hasUnsupported) removeDeclarationAndEmptyRule$1(decl);
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
//#endregion
|
|
686
|
+
//#region src/compat/mini-program-css/finalize.ts
|
|
687
|
+
const HOIST_ANCHOR_COMMENT = "__weapp_tailwindcss_base_anchor__";
|
|
688
|
+
function createPseudoContentInitRule() {
|
|
689
|
+
const rule = postcss.default.rule({ selector: "::before,\n::after" });
|
|
690
|
+
rule.append({
|
|
691
|
+
prop: "--tw-content",
|
|
692
|
+
value: "''"
|
|
693
|
+
});
|
|
694
|
+
return rule;
|
|
695
|
+
}
|
|
696
|
+
function collectPreflightRules(root, options = {}) {
|
|
697
|
+
const preflightNodes = [];
|
|
698
|
+
let hasContentInit = false;
|
|
699
|
+
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node)) {
|
|
700
|
+
preflightNodes.push(node);
|
|
701
|
+
if (hasTwContentDeclaration(node)) hasContentInit = true;
|
|
702
|
+
}
|
|
703
|
+
if (preflightNodes.length === 0) return [];
|
|
704
|
+
const clonedPreflightRules = preflightNodes.map((node) => node.clone());
|
|
705
|
+
const contentInitRules = options.preservePseudoContentInit ? clonedPreflightRules.filter((rule) => hasTwContentDeclaration(rule)) : [];
|
|
706
|
+
const otherPreflightRules = clonedPreflightRules.filter((rule) => !hasTwContentDeclaration(rule));
|
|
707
|
+
const preflightRules = hasContentInit ? [...contentInitRules, ...otherPreflightRules] : [...options.preservePseudoContentInit ? [createPseudoContentInitRule()] : [], ...otherPreflightRules];
|
|
708
|
+
for (const node of preflightNodes) node.remove();
|
|
709
|
+
return preflightRules;
|
|
710
|
+
}
|
|
711
|
+
function createPreflightResetRule(cssPreflight) {
|
|
712
|
+
if (!cssPreflight || typeof cssPreflight !== "object") return;
|
|
713
|
+
const rule = postcss.default.rule({ selector: "view,text,:after,:before" });
|
|
714
|
+
for (const [prop, value] of Object.entries(cssPreflight)) {
|
|
715
|
+
if (value === false) continue;
|
|
716
|
+
rule.append({
|
|
717
|
+
prop,
|
|
718
|
+
value: value.toString()
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
return rule.nodes?.length ? rule : void 0;
|
|
722
|
+
}
|
|
723
|
+
function collectThemeVariableRule(root, options = {}) {
|
|
724
|
+
const themeRules = [];
|
|
725
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
726
|
+
const shouldPreserveContentInit = options.preservePseudoContentInit || usesTwContentVariable(root);
|
|
727
|
+
for (const node of root.nodes ?? []) {
|
|
728
|
+
if (!isMiniProgramThemeVariableRule(node)) continue;
|
|
729
|
+
themeRules.push(node);
|
|
730
|
+
node.walkDecls((decl) => {
|
|
731
|
+
if (isDisplayP3Declaration(decl)) return;
|
|
732
|
+
if (!shouldPreserveContentInit && isEmptyTwContentDeclaration(decl)) return;
|
|
733
|
+
declarations.set(decl.prop, decl.clone());
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
for (const rule of themeRules) rule.remove();
|
|
737
|
+
if (declarations.size === 0) return;
|
|
738
|
+
const rule = postcss.default.rule({ selector: MINI_PROGRAM_THEME_SCOPE_SELECTOR });
|
|
739
|
+
for (const decl of declarations.values()) rule.append(decl);
|
|
740
|
+
return rule;
|
|
741
|
+
}
|
|
742
|
+
function getTopDirectiveTail(root) {
|
|
743
|
+
let tail;
|
|
744
|
+
for (const node of root.nodes ?? []) {
|
|
745
|
+
if (node.type === "atrule" && (node.name === "charset" || node.name === "import")) {
|
|
746
|
+
tail = node;
|
|
747
|
+
continue;
|
|
748
|
+
}
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
751
|
+
return tail;
|
|
752
|
+
}
|
|
753
|
+
function createHoistInsertionAnchor(root) {
|
|
754
|
+
for (const node of root.nodes ?? []) if (isMiniProgramPreflightRule(node) || isMiniProgramThemeVariableRule(node)) {
|
|
755
|
+
const anchor = postcss.default.comment({ text: HOIST_ANCHOR_COMMENT });
|
|
756
|
+
node.before(anchor);
|
|
757
|
+
return anchor;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
function insertHoistedRules(root, rules, anchor) {
|
|
761
|
+
if (anchor && !anchor.parent) anchor = void 0;
|
|
762
|
+
if (rules.length === 0) {
|
|
763
|
+
anchor?.remove();
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
const topDirectiveTail = getTopDirectiveTail(root);
|
|
767
|
+
const firstRule = rules[0];
|
|
768
|
+
if (!firstRule) return;
|
|
769
|
+
if (anchor) {
|
|
770
|
+
if (anchor.raws.before === void 0) delete firstRule.raws.before;
|
|
771
|
+
else firstRule.raws.before = anchor.raws.before;
|
|
772
|
+
anchor.replaceWith(rules);
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
firstRule.raws.before = topDirectiveTail ? "\n" : "";
|
|
776
|
+
if (topDirectiveTail) topDirectiveTail.after(rules);
|
|
777
|
+
else root.prepend(rules);
|
|
778
|
+
}
|
|
779
|
+
function unwrapTailwindSourceMedia(root) {
|
|
780
|
+
root.walkAtRules("media", (atRule) => {
|
|
781
|
+
if (atRule.params.startsWith("source(") && atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
function finalizeMiniProgramCssRoot(root, options = {}) {
|
|
785
|
+
removeUnsupportedCascadeLayers(root);
|
|
786
|
+
unwrapTailwindSourceMedia(root);
|
|
787
|
+
root.walkAtRules("property", (atRule) => {
|
|
788
|
+
atRule.remove();
|
|
789
|
+
});
|
|
790
|
+
removeSpecificityPlaceholders(root);
|
|
791
|
+
removeUnsupportedBrowserSelectors(root);
|
|
792
|
+
removeDisplayP3Declarations(root);
|
|
793
|
+
removeUnsupportedModernColorDeclarations(root);
|
|
794
|
+
root.walkDecls((decl) => {
|
|
795
|
+
normalizeMiniProgramPrefixedDeclaration(decl);
|
|
796
|
+
});
|
|
797
|
+
root.walkAtRules((atRule) => {
|
|
798
|
+
removeUnsupportedMiniProgramPrefixedAtRule(atRule);
|
|
799
|
+
});
|
|
800
|
+
const hoistAnchor = createHoistInsertionAnchor(root);
|
|
801
|
+
const preflightRules = collectPreflightRules(root, options);
|
|
802
|
+
if (preflightRules.length === 0) {
|
|
803
|
+
const resetRule = createPreflightResetRule(options.cssPreflight);
|
|
804
|
+
if (resetRule) preflightRules.push(resetRule);
|
|
805
|
+
}
|
|
806
|
+
const themeRule = collectThemeVariableRule(root, options);
|
|
807
|
+
insertHoistedRules(root, themeRule ? [...preflightRules, themeRule] : preflightRules, hoistAnchor);
|
|
808
|
+
}
|
|
809
|
+
function hoistTailwindPreflightBase(css) {
|
|
810
|
+
try {
|
|
811
|
+
const root = postcss.default.parse(css);
|
|
812
|
+
insertHoistedRules(root, collectPreflightRules(root, { preservePseudoContentInit: true }));
|
|
813
|
+
return root.toString();
|
|
814
|
+
} catch {
|
|
815
|
+
return css;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
function finalizeMiniProgramCss(css, options = {}) {
|
|
819
|
+
const cleanedCss = removeUnsupportedMiniProgramAtRules(css);
|
|
820
|
+
try {
|
|
821
|
+
const root = postcss.default.parse(cleanedCss);
|
|
822
|
+
finalizeMiniProgramCssRoot(root, options);
|
|
823
|
+
return root.toString();
|
|
824
|
+
} catch {
|
|
825
|
+
return cleanedCss;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
//#endregion
|
|
829
|
+
//#region src/compat/mini-program-css/prune-generated.ts
|
|
830
|
+
const DEFAULT_WEAPP_VARIABLE_SCOPE = "page,.tw-root,wx-root-portal-content,:host";
|
|
831
|
+
const DEFAULT_WEAPP_ELEMENT_VARIABLE_SCOPE = "view,text,:before,:after";
|
|
832
|
+
const CLASS_SELECTOR_RE$1 = /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i;
|
|
833
|
+
const MINI_PROGRAM_ELEMENT_VARIABLE_SCOPE_SELECTORS = new Set([
|
|
834
|
+
"view",
|
|
835
|
+
"text",
|
|
836
|
+
":before",
|
|
837
|
+
":after",
|
|
838
|
+
"::before",
|
|
839
|
+
"::after"
|
|
840
|
+
]);
|
|
841
|
+
function isConditionalCompilationComment(text) {
|
|
842
|
+
return /#(?:ifn?def|endif)\b/.test(text);
|
|
843
|
+
}
|
|
844
|
+
function hasClassSelector$2(selector) {
|
|
845
|
+
return CLASS_SELECTOR_RE$1.test(selector);
|
|
846
|
+
}
|
|
847
|
+
function removeEmptyContentInitDeclarations(rule) {
|
|
848
|
+
rule.walkDecls((decl) => {
|
|
849
|
+
if (isEmptyTwContentDeclaration(decl)) decl.remove();
|
|
850
|
+
});
|
|
851
|
+
}
|
|
852
|
+
function isMiniProgramElementVariableScopeRule(rule) {
|
|
853
|
+
const selectors = getRuleSelectors(rule);
|
|
854
|
+
return selectors.length > 0 && selectors.every((selector) => MINI_PROGRAM_ELEMENT_VARIABLE_SCOPE_SELECTORS.has(selector));
|
|
855
|
+
}
|
|
856
|
+
function isTailwindV4GradientRuntimeDeclaration(decl) {
|
|
857
|
+
return decl.prop.startsWith("--tw-gradient-");
|
|
858
|
+
}
|
|
859
|
+
function moveTailwindV4GradientRuntimeDeclarations(rule) {
|
|
860
|
+
const gradientDeclarations = [];
|
|
861
|
+
rule.walkDecls((decl) => {
|
|
862
|
+
if (isTailwindV4GradientRuntimeDeclaration(decl)) {
|
|
863
|
+
gradientDeclarations.push(decl.clone());
|
|
864
|
+
decl.remove();
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
if (gradientDeclarations.length > 0) rule.before(new postcss.default.Rule({
|
|
868
|
+
selector: DEFAULT_WEAPP_ELEMENT_VARIABLE_SCOPE,
|
|
869
|
+
nodes: gradientDeclarations
|
|
870
|
+
}));
|
|
871
|
+
if (rule.nodes.length === 0) rule.remove();
|
|
872
|
+
}
|
|
873
|
+
function isKeyframesRule(rule) {
|
|
874
|
+
let parent = rule.parent;
|
|
875
|
+
while (parent) {
|
|
876
|
+
if (parent.type === "atrule" && parent.name.endsWith("keyframes")) return true;
|
|
877
|
+
parent = parent.parent;
|
|
878
|
+
}
|
|
879
|
+
return false;
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* 裁剪 Tailwind 生成 CSS 中面向浏览器的 classless 规则。
|
|
883
|
+
*/
|
|
884
|
+
function pruneMiniProgramGeneratedCss(css, options = {}) {
|
|
885
|
+
const root = postcss.default.parse(css);
|
|
886
|
+
const shouldPreserveContentInit = options.preservePreflight || usesTwContentVariable(root);
|
|
887
|
+
root.walkComments((comment) => {
|
|
888
|
+
if (options.preserveConditionalComments && isConditionalCompilationComment(comment.text)) return;
|
|
889
|
+
comment.remove();
|
|
890
|
+
});
|
|
891
|
+
removeUnsupportedCascadeLayers(root);
|
|
892
|
+
removeUnsupportedModernColorDeclarations(root);
|
|
893
|
+
root.walkAtRules("supports", (atRule) => {
|
|
894
|
+
atRule.remove();
|
|
895
|
+
});
|
|
896
|
+
root.walkAtRules((atRule) => {
|
|
897
|
+
removeUnsupportedMiniProgramPrefixedAtRule(atRule);
|
|
898
|
+
});
|
|
899
|
+
root.walkDecls((decl) => {
|
|
900
|
+
normalizeMiniProgramPrefixedDeclaration(decl);
|
|
901
|
+
});
|
|
902
|
+
root.walkRules((rule) => {
|
|
903
|
+
if (isKeyframesRule(rule)) return;
|
|
904
|
+
if (isCustomPropertyRule(rule) && isMiniProgramElementVariableScopeRule(rule)) {
|
|
905
|
+
rule.selector = DEFAULT_WEAPP_ELEMENT_VARIABLE_SCOPE;
|
|
906
|
+
return;
|
|
907
|
+
}
|
|
908
|
+
if (isMiniProgramThemeVariableRule(rule)) {
|
|
909
|
+
moveTailwindV4GradientRuntimeDeclarations(rule);
|
|
910
|
+
if (!rule.parent) return;
|
|
911
|
+
rule.selector = DEFAULT_WEAPP_VARIABLE_SCOPE;
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
if (hasClassSelector$2(rule.selector)) return;
|
|
915
|
+
if (!shouldPreserveContentInit) removeEmptyContentInitDeclarations(rule);
|
|
916
|
+
if (isPseudoContentInitRule(rule)) {
|
|
917
|
+
if (!shouldPreserveContentInit) rule.remove();
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
if (options.preservePreflight && isMiniProgramPreflightRule(rule)) return;
|
|
921
|
+
if (isCustomPropertyRule(rule)) {
|
|
922
|
+
moveTailwindV4GradientRuntimeDeclarations(rule);
|
|
923
|
+
if (!rule.parent) return;
|
|
924
|
+
rule.selector = DEFAULT_WEAPP_VARIABLE_SCOPE;
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
rule.remove();
|
|
928
|
+
});
|
|
929
|
+
root.walkAtRules((atRule) => {
|
|
930
|
+
if (!atRule.nodes || atRule.nodes.length === 0) atRule.remove();
|
|
931
|
+
});
|
|
932
|
+
return root.toString();
|
|
933
|
+
}
|
|
934
|
+
//#endregion
|
|
367
935
|
//#region src/compat/uni-app-x.ts
|
|
368
936
|
const UNI_APP_X_BASE_CARRIER_SELECTORS = new Set([
|
|
369
937
|
"*",
|
|
@@ -640,6 +1208,8 @@ function getSimpleOverrideCacheKey(options) {
|
|
|
640
1208
|
let rem2rpx = SIMPLE_OVERRIDE_UNSET;
|
|
641
1209
|
let px2rpx = SIMPLE_OVERRIDE_UNSET;
|
|
642
1210
|
let unitsToPx = SIMPLE_OVERRIDE_UNSET;
|
|
1211
|
+
let unitConversion = SIMPLE_OVERRIDE_UNSET;
|
|
1212
|
+
let platform = SIMPLE_OVERRIDE_UNSET;
|
|
643
1213
|
let cssCalc = SIMPLE_OVERRIDE_UNSET;
|
|
644
1214
|
let cssChildCombinatorReplaceValue = SIMPLE_OVERRIDE_UNSET;
|
|
645
1215
|
let cssPreflight = SIMPLE_OVERRIDE_UNSET;
|
|
@@ -687,6 +1257,14 @@ function getSimpleOverrideCacheKey(options) {
|
|
|
687
1257
|
if (typeof value !== "boolean") return;
|
|
688
1258
|
unitsToPx = value ? "1" : "0";
|
|
689
1259
|
break;
|
|
1260
|
+
case "unitConversion":
|
|
1261
|
+
if (value !== false) return;
|
|
1262
|
+
unitConversion = "0";
|
|
1263
|
+
break;
|
|
1264
|
+
case "platform":
|
|
1265
|
+
if (typeof value !== "string") return;
|
|
1266
|
+
platform = value;
|
|
1267
|
+
break;
|
|
690
1268
|
case "cssCalc":
|
|
691
1269
|
if (typeof value !== "boolean") return;
|
|
692
1270
|
cssCalc = value ? "1" : "0";
|
|
@@ -718,6 +1296,8 @@ function getSimpleOverrideCacheKey(options) {
|
|
|
718
1296
|
rem2rpx,
|
|
719
1297
|
px2rpx,
|
|
720
1298
|
unitsToPx,
|
|
1299
|
+
unitConversion,
|
|
1300
|
+
platform,
|
|
721
1301
|
cssCalc,
|
|
722
1302
|
cssChildCombinatorReplaceValue,
|
|
723
1303
|
cssPreflight,
|
|
@@ -906,7 +1486,24 @@ function getCalcDuplicateCleaner(options) {
|
|
|
906
1486
|
return calcDuplicateCleanerPlugin;
|
|
907
1487
|
}
|
|
908
1488
|
//#endregion
|
|
909
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.
|
|
1489
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/object/omit.mjs
|
|
1490
|
+
/**
|
|
1491
|
+
* Creates a new object with specified keys omitted.
|
|
1492
|
+
*
|
|
1493
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
1494
|
+
* excludes the properties corresponding to the specified keys.
|
|
1495
|
+
*
|
|
1496
|
+
* @template T - The type of object.
|
|
1497
|
+
* @template K - The type of keys in object.
|
|
1498
|
+
* @param {T} obj - The object to omit keys from.
|
|
1499
|
+
* @param {K[]} keys - An array of keys to be omitted from the object.
|
|
1500
|
+
* @returns {Omit<T, K>} A new object with the specified keys omitted.
|
|
1501
|
+
*
|
|
1502
|
+
* @example
|
|
1503
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
1504
|
+
* const result = omit(obj, ['b', 'c']);
|
|
1505
|
+
* // result will be { a: 1 }
|
|
1506
|
+
*/
|
|
910
1507
|
function omit(obj, keys) {
|
|
911
1508
|
const result = { ...obj };
|
|
912
1509
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -995,6 +1592,110 @@ function getRemTransformPlugin(options) {
|
|
|
995
1592
|
return (0, postcss_rem_to_responsive_pixel.default)((0, _weapp_tailwindcss_shared.defuOverrideArray)(options.rem2rpx, defaultStage));
|
|
996
1593
|
}
|
|
997
1594
|
//#endregion
|
|
1595
|
+
//#region src/plugins/getUnitConversionPlugin.ts
|
|
1596
|
+
const DEFAULT_PLATFORM_KEYS = ["default", "*"];
|
|
1597
|
+
const PLATFORM_ENV_KEYS = [
|
|
1598
|
+
"WEAPP_TW_TARGET",
|
|
1599
|
+
"WEAPP_TAILWINDCSS_TARGET",
|
|
1600
|
+
"UNI_PLATFORM",
|
|
1601
|
+
"UNI_UTS_PLATFORM",
|
|
1602
|
+
"TARO_ENV",
|
|
1603
|
+
"MPX_CLI_MODE",
|
|
1604
|
+
"MPX_CURRENT_TARGET_MODE"
|
|
1605
|
+
];
|
|
1606
|
+
const PLATFORM_ALIASES = {
|
|
1607
|
+
"weapp": [
|
|
1608
|
+
"mp-weixin",
|
|
1609
|
+
"weixin",
|
|
1610
|
+
"wechat",
|
|
1611
|
+
"wx",
|
|
1612
|
+
"mp"
|
|
1613
|
+
],
|
|
1614
|
+
"mp-weixin": [
|
|
1615
|
+
"weapp",
|
|
1616
|
+
"weixin",
|
|
1617
|
+
"wechat",
|
|
1618
|
+
"wx",
|
|
1619
|
+
"mp"
|
|
1620
|
+
],
|
|
1621
|
+
"wx": [
|
|
1622
|
+
"weapp",
|
|
1623
|
+
"mp-weixin",
|
|
1624
|
+
"weixin",
|
|
1625
|
+
"wechat",
|
|
1626
|
+
"mp"
|
|
1627
|
+
],
|
|
1628
|
+
"h5": ["web"],
|
|
1629
|
+
"web": ["h5"],
|
|
1630
|
+
"app": [
|
|
1631
|
+
"app-plus",
|
|
1632
|
+
"app-android",
|
|
1633
|
+
"app-ios",
|
|
1634
|
+
"android",
|
|
1635
|
+
"ios"
|
|
1636
|
+
],
|
|
1637
|
+
"app-plus": ["app"],
|
|
1638
|
+
"app-android": ["app", "android"],
|
|
1639
|
+
"app-ios": ["app", "ios"],
|
|
1640
|
+
"android": ["app", "app-android"],
|
|
1641
|
+
"ios": ["app", "app-ios"]
|
|
1642
|
+
};
|
|
1643
|
+
function normalizePlatform(value) {
|
|
1644
|
+
return value?.trim().toLowerCase() || void 0;
|
|
1645
|
+
}
|
|
1646
|
+
function readEnvValue(key) {
|
|
1647
|
+
return typeof node_process.default === "undefined" ? void 0 : node_process.default.env[key];
|
|
1648
|
+
}
|
|
1649
|
+
function resolveUnitConversionPlatform(options) {
|
|
1650
|
+
const explicit = normalizePlatform(options.platform);
|
|
1651
|
+
if (explicit) return explicit;
|
|
1652
|
+
for (const key of PLATFORM_ENV_KEYS) {
|
|
1653
|
+
const value = normalizePlatform(readEnvValue(key));
|
|
1654
|
+
if (value) return value;
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
function isPlatformUnitConversionOptions(options) {
|
|
1658
|
+
return Boolean(options && typeof options === "object" && "platforms" in options);
|
|
1659
|
+
}
|
|
1660
|
+
function hasRules(config) {
|
|
1661
|
+
return Array.isArray(config.rules) && config.rules.length > 0;
|
|
1662
|
+
}
|
|
1663
|
+
function getPlatformCandidateKeys(platform) {
|
|
1664
|
+
if (!platform) return [];
|
|
1665
|
+
const normalized = normalizePlatform(platform);
|
|
1666
|
+
if (!normalized) return [];
|
|
1667
|
+
return [normalized, ...PLATFORM_ALIASES[normalized] ?? []];
|
|
1668
|
+
}
|
|
1669
|
+
function getPlatformConfig(platforms, key) {
|
|
1670
|
+
if (Object.hasOwn(platforms, key)) return platforms[key];
|
|
1671
|
+
for (const [platform, config] of Object.entries(platforms)) if (normalizePlatform(platform) === key) return config;
|
|
1672
|
+
}
|
|
1673
|
+
function resolvePlatformConfig(options, platform) {
|
|
1674
|
+
if (!isPlatformUnitConversionOptions(options)) return options;
|
|
1675
|
+
const platforms = options.platforms;
|
|
1676
|
+
for (const key of getPlatformCandidateKeys(platform)) {
|
|
1677
|
+
const config = getPlatformConfig(platforms, key);
|
|
1678
|
+
if (config !== void 0) return config;
|
|
1679
|
+
}
|
|
1680
|
+
if (options.default !== void 0) return options.default;
|
|
1681
|
+
for (const key of DEFAULT_PLATFORM_KEYS) {
|
|
1682
|
+
const config = getPlatformConfig(platforms, key);
|
|
1683
|
+
if (config !== void 0) return config;
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
function resolveUnitConversionConfig(options) {
|
|
1687
|
+
const unitConversion = options.unitConversion;
|
|
1688
|
+
if (!unitConversion || unitConversion === false) return;
|
|
1689
|
+
const config = resolvePlatformConfig(unitConversion, resolveUnitConversionPlatform(options));
|
|
1690
|
+
if (!config || config === false || config.disabled || !hasRules(config)) return;
|
|
1691
|
+
return config;
|
|
1692
|
+
}
|
|
1693
|
+
function getUnitConversionPlugin(options) {
|
|
1694
|
+
const config = resolveUnitConversionConfig(options);
|
|
1695
|
+
if (!config) return null;
|
|
1696
|
+
return (0, postcss_rule_unit_converter.default)(config);
|
|
1697
|
+
}
|
|
1698
|
+
//#endregion
|
|
998
1699
|
//#region src/plugins/getUnitsToPxPlugin.ts
|
|
999
1700
|
function getUnitsToPxPlugin(options) {
|
|
1000
1701
|
if (!options.unitsToPx) return null;
|
|
@@ -1935,6 +2636,78 @@ function normalizeCalcValue(value) {
|
|
|
1935
2636
|
function hasVariableReference(value) {
|
|
1936
2637
|
return value.includes("var(");
|
|
1937
2638
|
}
|
|
2639
|
+
function splitTopLevelCommaList(value) {
|
|
2640
|
+
const parts = [];
|
|
2641
|
+
let start = 0;
|
|
2642
|
+
let depth = 0;
|
|
2643
|
+
let quote;
|
|
2644
|
+
let escaped = false;
|
|
2645
|
+
for (let i = 0; i < value.length; i++) {
|
|
2646
|
+
const char = value[i];
|
|
2647
|
+
if (escaped) {
|
|
2648
|
+
escaped = false;
|
|
2649
|
+
continue;
|
|
2650
|
+
}
|
|
2651
|
+
if (char === "\\") {
|
|
2652
|
+
escaped = true;
|
|
2653
|
+
continue;
|
|
2654
|
+
}
|
|
2655
|
+
if (quote) {
|
|
2656
|
+
if (char === quote) quote = void 0;
|
|
2657
|
+
continue;
|
|
2658
|
+
}
|
|
2659
|
+
if (char === "\"" || char === "'") {
|
|
2660
|
+
quote = char;
|
|
2661
|
+
continue;
|
|
2662
|
+
}
|
|
2663
|
+
if (char === "(") {
|
|
2664
|
+
depth++;
|
|
2665
|
+
continue;
|
|
2666
|
+
}
|
|
2667
|
+
if (char === ")") {
|
|
2668
|
+
depth = Math.max(0, depth - 1);
|
|
2669
|
+
continue;
|
|
2670
|
+
}
|
|
2671
|
+
if (char === "," && depth === 0) {
|
|
2672
|
+
parts.push(value.slice(start, i));
|
|
2673
|
+
start = i + 1;
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
parts.push(value.slice(start));
|
|
2677
|
+
return parts;
|
|
2678
|
+
}
|
|
2679
|
+
function getTransitionPropertySet(value) {
|
|
2680
|
+
const items = splitTopLevelCommaList(value).map((item) => item.trim().toLowerCase()).filter(Boolean);
|
|
2681
|
+
return items.length > 0 ? new Set(items) : void 0;
|
|
2682
|
+
}
|
|
2683
|
+
function isSubsetOfSet(subset, superset) {
|
|
2684
|
+
for (const item of subset) if (!superset.has(item)) return false;
|
|
2685
|
+
return true;
|
|
2686
|
+
}
|
|
2687
|
+
function removeRedundantTransitionPropertyFallbacks(rule) {
|
|
2688
|
+
const entries = rule.nodes.filter((node) => node.type === "decl" && node.prop.toLowerCase() === "transition-property").map((decl) => ({
|
|
2689
|
+
decl,
|
|
2690
|
+
items: getTransitionPropertySet(decl.value)
|
|
2691
|
+
}));
|
|
2692
|
+
for (let i = 0; i < entries.length; i++) {
|
|
2693
|
+
const entry = entries[i];
|
|
2694
|
+
if (!entry?.items) continue;
|
|
2695
|
+
for (let j = i + 1; j < entries.length; j++) {
|
|
2696
|
+
const next = entries[j];
|
|
2697
|
+
if (!next?.items) continue;
|
|
2698
|
+
if (next.items.size === entry.items.size && isSubsetOfSet(entry.items, next.items)) {
|
|
2699
|
+
next.decl.remove();
|
|
2700
|
+
entries.splice(j, 1);
|
|
2701
|
+
j--;
|
|
2702
|
+
continue;
|
|
2703
|
+
}
|
|
2704
|
+
if (next.items.size > entry.items.size && isSubsetOfSet(entry.items, next.items)) {
|
|
2705
|
+
entry.decl.remove();
|
|
2706
|
+
break;
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
1938
2711
|
function dedupeDeclarations(rule) {
|
|
1939
2712
|
const entries = [];
|
|
1940
2713
|
for (const node of [...rule.nodes]) {
|
|
@@ -1986,6 +2759,7 @@ function dedupeDeclarations(rule) {
|
|
|
1986
2759
|
if (literalSeen.get(canonical)) node.remove();
|
|
1987
2760
|
else literalSeen.set(canonical, node);
|
|
1988
2761
|
}
|
|
2762
|
+
removeRedundantTransitionPropertyFallbacks(rule);
|
|
1989
2763
|
}
|
|
1990
2764
|
//#endregion
|
|
1991
2765
|
//#region src/plugins/post/specificity-cleaner.ts
|
|
@@ -2135,6 +2909,9 @@ const postcssWeappTailwindcssPostPlugin = (options) => {
|
|
|
2135
2909
|
root.walkDecls((decl) => {
|
|
2136
2910
|
normalizeMiniProgramPrefixedDeclaration(decl);
|
|
2137
2911
|
});
|
|
2912
|
+
root.walkRules((rule) => {
|
|
2913
|
+
removeRedundantTransitionPropertyFallbacks(rule);
|
|
2914
|
+
});
|
|
2138
2915
|
root.walkAtRules((atRule) => {
|
|
2139
2916
|
removeUnsupportedMiniProgramPrefixedAtRule(atRule);
|
|
2140
2917
|
});
|
|
@@ -2615,6 +3392,8 @@ function createPreparedNodes(options, signal) {
|
|
|
2615
3392
|
if (pxTransformPlugin) preparedNodes.push(createPreparedNode("normal:px-transform", "normal", () => pxTransformPlugin));
|
|
2616
3393
|
const remTransformPlugin = getRemTransformPlugin(options);
|
|
2617
3394
|
if (remTransformPlugin) preparedNodes.push(createPreparedNode("normal:rem-transform", "normal", () => remTransformPlugin));
|
|
3395
|
+
const unitConversionPlugin = getUnitConversionPlugin(options);
|
|
3396
|
+
if (unitConversionPlugin) preparedNodes.push(createPreparedNode("normal:unit-conversion", "normal", () => unitConversionPlugin));
|
|
2618
3397
|
const calcPlugin = getCalcPlugin(options);
|
|
2619
3398
|
if (calcPlugin) preparedNodes.push(createPreparedNode("normal:calc", "normal", () => calcPlugin));
|
|
2620
3399
|
const calcDuplicateCleaner = getCalcDuplicateCleaner(options);
|
|
@@ -2864,9 +3643,27 @@ exports.createFallbackPlaceholderReplacer = createFallbackPlaceholderReplacer;
|
|
|
2864
3643
|
exports.createInjectPreflight = createInjectPreflight;
|
|
2865
3644
|
exports.createStyleHandler = createStyleHandler;
|
|
2866
3645
|
exports.createStylePipeline = createStylePipeline;
|
|
3646
|
+
exports.finalizeMiniProgramCss = finalizeMiniProgramCss;
|
|
3647
|
+
exports.hoistTailwindPreflightBase = hoistTailwindPreflightBase;
|
|
2867
3648
|
exports.internalCssSelectorReplacer = internalCssSelectorReplacer;
|
|
2868
3649
|
exports.normalizeMiniProgramPrefixedDeclaration = normalizeMiniProgramPrefixedDeclaration;
|
|
2869
3650
|
exports.normalizeModernColorValue = normalizeModernColorValue;
|
|
2870
3651
|
exports.postcssHtmlTransform = require_html_transform.postcssHtmlTransform;
|
|
2871
3652
|
exports.protectDynamicColorMixAlpha = protectDynamicColorMixAlpha;
|
|
3653
|
+
exports.pruneMiniProgramGeneratedCss = pruneMiniProgramGeneratedCss;
|
|
3654
|
+
exports.removeUnsupportedAtSupports = removeUnsupportedAtSupports;
|
|
3655
|
+
exports.removeUnsupportedCascadeLayers = removeUnsupportedCascadeLayers;
|
|
3656
|
+
exports.removeUnsupportedMiniProgramAtRules = removeUnsupportedMiniProgramAtRules;
|
|
2872
3657
|
exports.removeUnsupportedMiniProgramPrefixedAtRule = removeUnsupportedMiniProgramPrefixedAtRule;
|
|
3658
|
+
Object.defineProperty(exports, "unitConversionComposeRules", {
|
|
3659
|
+
enumerable: true,
|
|
3660
|
+
get: function() {
|
|
3661
|
+
return postcss_rule_unit_converter.composeRules;
|
|
3662
|
+
}
|
|
3663
|
+
});
|
|
3664
|
+
Object.defineProperty(exports, "unitConversionPresets", {
|
|
3665
|
+
enumerable: true,
|
|
3666
|
+
get: function() {
|
|
3667
|
+
return postcss_rule_unit_converter.presets;
|
|
3668
|
+
}
|
|
3669
|
+
});
|