@weapp-tailwindcss/postcss 1.3.4 → 2.0.1

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/index.js CHANGED
@@ -34,7 +34,7 @@ function getDefaultOptions(options) {
34
34
  };
35
35
  }
36
36
 
37
- // src/plugins/index.ts
37
+ // src/pipeline.ts
38
38
  var _postcsspresetenv = require('postcss-preset-env'); var _postcsspresetenv2 = _interopRequireDefault(_postcsspresetenv);
39
39
 
40
40
  // src/plugins/ctx.ts
@@ -80,32 +80,41 @@ function getCalcPlugin(options) {
80
80
  var _postcssvalueparser = require('postcss-value-parser'); var _postcssvalueparser2 = _interopRequireDefault(_postcssvalueparser);
81
81
  function getCustomPropertyCleaner(options) {
82
82
  const includeCustomProperties = Array.isArray(options.cssCalc) ? options.cssCalc : typeof options.cssCalc === "object" ? options.cssCalc.includeCustomProperties : [];
83
- if (!includeCustomProperties || includeCustomProperties.length === 0) {
83
+ const shouldMatchCustomProperties = Array.isArray(includeCustomProperties) && includeCustomProperties.length > 0;
84
+ if (!shouldMatchCustomProperties) {
84
85
  return null;
85
86
  }
86
87
  return {
87
88
  postcssPlugin: "postcss-remove-include-custom-properties",
88
89
  OnceExit(root) {
89
- root.walkDecls((decl, idx) => {
90
- if (idx === 0 || !/--/.test(decl.value)) {
90
+ root.walkDecls((decl) => {
91
+ const prevNode = decl.prev();
92
+ if (!prevNode || prevNode.type !== "decl" || prevNode.prop !== decl.prop) {
91
93
  return;
92
94
  }
93
- const prevNode = _optionalChain([decl, 'access', _5 => _5.parent, 'optionalAccess', _6 => _6.nodes, 'access', _7 => _7[idx - 1]]);
94
- if (!prevNode || prevNode.prop !== decl.prop) {
95
+ if (prevNode.value === decl.value) {
96
+ decl.remove();
97
+ return;
98
+ }
99
+ if (!shouldMatchCustomProperties || !/--/.test(decl.value)) {
95
100
  return;
96
101
  }
97
102
  const parsed = _postcssvalueparser2.default.call(void 0, decl.value);
103
+ let containsIncludedCustomProperty = false;
98
104
  parsed.walk((node) => {
99
- if (node.type !== "function" || node.value !== "var") {
105
+ if (node.type !== "function" || node.value !== "var" || containsIncludedCustomProperty) {
100
106
  return;
101
107
  }
102
108
  const match = node.nodes.find((x) => {
103
109
  return x.type === "word" && _shared.regExpTest.call(void 0, includeCustomProperties, x.value);
104
110
  });
105
111
  if (match) {
106
- decl.remove();
112
+ containsIncludedCustomProperty = true;
107
113
  }
108
114
  });
115
+ if (containsIncludedCustomProperty) {
116
+ decl.remove();
117
+ }
109
118
  });
110
119
  }
111
120
  };
@@ -181,7 +190,7 @@ var beforeAfterParser = _postcssselectorparser2.default.call(void 0, (selectors)
181
190
  return;
182
191
  }
183
192
  selectors.walkPseudos((s) => {
184
- if (_optionalChain([s, 'access', _8 => _8.parent, 'optionalAccess', _9 => _9.length]) === 1) {
193
+ if (_optionalChain([s, 'access', _5 => _5.parent, 'optionalAccess', _6 => _6.length]) === 1) {
185
194
  if (/^:?:before$/.test(s.value)) {
186
195
  state.before = true;
187
196
  }
@@ -259,7 +268,7 @@ function getFallbackRemove(_rule, options) {
259
268
  const cacheKey = _nullishCoalesce(options, () => ( fallbackDefaultKey));
260
269
  let entry = fallbackRemoveCache.get(cacheKey);
261
270
  if (!entry) {
262
- const uniAppX = Boolean(_optionalChain([options, 'optionalAccess', _10 => _10.uniAppX]));
271
+ const uniAppX = Boolean(_optionalChain([options, 'optionalAccess', _7 => _7.uniAppX]));
263
272
  let currentRule;
264
273
  const parser = _postcssselectorparser2.default.call(void 0, (selectors) => {
265
274
  const activeRule = currentRule;
@@ -269,13 +278,13 @@ function getFallbackRemove(_rule, options) {
269
278
  maybeImportantId = true;
270
279
  }
271
280
  if (selector.type === "universal") {
272
- _optionalChain([selector, 'access', _11 => _11.parent, 'optionalAccess', _12 => _12.remove, 'call', _13 => _13()]);
281
+ _optionalChain([selector, 'access', _8 => _8.parent, 'optionalAccess', _9 => _9.remove, 'call', _10 => _10()]);
273
282
  } else if (selector.type === "pseudo") {
274
283
  if (selector.value === ":is") {
275
- if (maybeImportantId && _optionalChain([selector, 'access', _14 => _14.nodes, 'access', _15 => _15[0], 'optionalAccess', _16 => _16.type]) === "selector") {
284
+ if (maybeImportantId && _optionalChain([selector, 'access', _11 => _11.nodes, 'access', _12 => _12[0], 'optionalAccess', _13 => _13.type]) === "selector") {
276
285
  selector.replaceWith(selector.nodes[0]);
277
286
  } else {
278
- _optionalChain([selector, 'access', _17 => _17.parent, 'optionalAccess', _18 => _18.remove, 'call', _19 => _19()]);
287
+ _optionalChain([selector, 'access', _14 => _14.parent, 'optionalAccess', _15 => _15.remove, 'call', _16 => _16()]);
279
288
  }
280
289
  } else if (selector.value === ":not") {
281
290
  for (const x of selector.nodes) {
@@ -298,7 +307,7 @@ function getFallbackRemove(_rule, options) {
298
307
  }
299
308
  } else if (selector.type === "attribute") {
300
309
  if (selector.attribute === "hidden") {
301
- _optionalChain([activeRule, 'optionalAccess', _20 => _20.remove, 'call', _21 => _21()]);
310
+ _optionalChain([activeRule, 'optionalAccess', _17 => _17.remove, 'call', _18 => _18()]);
302
311
  }
303
312
  }
304
313
  });
@@ -374,128 +383,306 @@ function composeIsPseudo(strs) {
374
383
 
375
384
  // src/selectorParser/rule-transformer.ts
376
385
  var ruleTransformCache = /* @__PURE__ */ new WeakMap();
377
- function createRuleTransformer(options) {
378
- let currentRule;
379
- const { escapeMap, cssSelectorReplacement, cssRemoveHoverPseudoClass, uniAppX } = options;
380
- const transform = (selectors) => {
381
- const rule = currentRule;
382
- if (!rule) {
383
- return;
386
+ var MIRROR_PROP_PAIRS = [
387
+ ["margin-top", "margin-bottom"],
388
+ ["margin-left", "margin-right"],
389
+ ["margin-inline-start", "margin-inline-end"],
390
+ ["margin-block-start", "margin-block-end"],
391
+ ["border-top-width", "border-bottom-width"],
392
+ ["border-left-width", "border-right-width"],
393
+ ["border-inline-start-width", "border-inline-end-width"],
394
+ ["border-block-start-width", "border-block-end-width"]
395
+ ];
396
+ var MIRROR_PROP_MAP = /* @__PURE__ */ new Map();
397
+ var SPACING_PROP_SET = /* @__PURE__ */ new Set();
398
+ for (const [a, b] of MIRROR_PROP_PAIRS) {
399
+ MIRROR_PROP_MAP.set(a, b);
400
+ MIRROR_PROP_MAP.set(b, a);
401
+ SPACING_PROP_SET.add(a);
402
+ SPACING_PROP_SET.add(b);
403
+ }
404
+ var LEGACY_WEBKIT_SPACING_PROPS = /* @__PURE__ */ new Set([
405
+ "-webkit-margin-start",
406
+ "-webkit-margin-end",
407
+ "-webkit-margin-before",
408
+ "-webkit-margin-after"
409
+ ]);
410
+ var VAR_REFERENCE_PATTERN = /var\(/i;
411
+ function dedupeSpacingProps(rule) {
412
+ const grouped = /* @__PURE__ */ new Map();
413
+ for (const node of rule.nodes) {
414
+ if (node.type !== "decl") {
415
+ continue;
384
416
  }
385
- selectors.walk((selector, index) => {
386
- if (selector.type === "class") {
387
- selector.value = internalCssSelectorReplacer(selector.value, {
388
- escapeMap
389
- });
390
- } else if (selector.type === "universal") {
391
- if (_optionalChain([cssSelectorReplacement, 'optionalAccess', _22 => _22.universal])) {
392
- selector.value = composeIsPseudo(cssSelectorReplacement.universal);
393
- }
394
- } else if (selector.type === "selector") {
395
- if (cssRemoveHoverPseudoClass) {
396
- const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
397
- if (node) {
398
- selector.remove();
399
- }
400
- }
401
- } else if (selector.type === "pseudo") {
402
- if (selector.value === ":root" && _optionalChain([cssSelectorReplacement, 'optionalAccess', _23 => _23.root])) {
403
- selector.value = composeIsPseudo(cssSelectorReplacement.root);
404
- } else if (selector.value === ":where") {
405
- if (uniAppX) {
406
- selector.value = ":is";
407
- }
408
- if (index === 0 && selector.length === 1) {
409
- selector.walk((node, idx) => {
410
- if (idx === 0 && node.type === "class") {
411
- const nodes2 = _optionalChain([node, 'access', _24 => _24.parent, 'optionalAccess', _25 => _25.nodes]);
412
- if (nodes2) {
413
- const first = nodes2[idx + 1];
414
- if (first && first.type === "combinator" && first.value === ">") {
415
- const second = nodes2[idx + 2];
416
- if (second && second.type === "pseudo" && second.value === ":not" && second.first.first.type === "pseudo" && second.first.first.value === ":last-child") {
417
- const ast = getCombinatorSelectorAst(options);
418
- second.replaceWith(
419
- ...ast
420
- );
421
- }
422
- }
423
- }
424
- }
425
- });
426
- selector.replaceWith(...selector.nodes);
427
- for (const node of rule.nodes) {
428
- if (node.type === "decl") {
429
- if (node.prop === "margin-block-start") {
430
- node.prop = "margin-block-end";
431
- } else if (node.prop === "margin-block-end") {
432
- node.prop = "margin-block-start";
433
- } else if (node.prop === "margin-inline-start") {
434
- node.prop = "margin-inline-end";
435
- } else if (node.prop === "margin-inline-end") {
436
- node.prop = "margin-inline-start";
437
- } else if (node.prop === "margin-top") {
438
- node.prop = "margin-bottom";
439
- } else if (node.prop === "margin-bottom") {
440
- node.prop = "margin-top";
441
- } else if (node.prop === "margin-left") {
442
- node.prop = "margin-right";
443
- } else if (node.prop === "margin-right") {
444
- node.prop = "margin-left";
445
- } else if (node.prop === "-webkit-margin-start" || node.prop === "-webkit-margin-end" || node.prop === "-webkit-margin-before" || node.prop === "-webkit-margin-after") {
446
- node.remove();
447
- }
448
- }
449
- }
450
- }
451
- }
452
- } else if (selector.type === "combinator") {
453
- if (selector.value === ">") {
454
- const nodes2 = _optionalChain([selector, 'access', _26 => _26.parent, 'optionalAccess', _27 => _27.nodes]);
455
- if (nodes2) {
456
- const first = nodes2[index + 1];
457
- if (first && first.type === "pseudo" && first.value === ":not" && (first.first.first.type === "attribute" && first.first.first.attribute === "hidden" || first.first.first.type === "tag" && first.first.first.value === "template")) {
458
- const second = nodes2[index + 2];
459
- if (second && second.type === "combinator" && (second.value === "~" || second.value === "+")) {
460
- const third = nodes2[index + 3];
461
- if (third && third.type === "pseudo" && third.value === ":not" && (third.first.first.type === "attribute" && third.first.first.attribute === "hidden" || third.first.first.type === "tag" && third.first.first.value === "template")) {
462
- const ast = getCombinatorSelectorAst(options);
463
- _optionalChain([selector, 'access', _28 => _28.parent, 'optionalAccess', _29 => _29.nodes, 'access', _30 => _30.splice, 'call', _31 => _31(
464
- index + 1,
465
- 3,
466
- ...ast
467
- )]);
468
- }
469
- }
470
- }
471
- }
472
- }
473
- } else if (selector.type === "tag") {
474
- if (uniAppX) {
475
- selector.remove();
476
- }
477
- } else if (selector.type === "attribute") {
478
- if (uniAppX) {
479
- selector.remove();
480
- }
417
+ if (!SPACING_PROP_SET.has(node.prop)) {
418
+ continue;
419
+ }
420
+ const list = grouped.get(node.prop);
421
+ if (list) {
422
+ list.push(node);
423
+ } else {
424
+ grouped.set(node.prop, [node]);
425
+ }
426
+ }
427
+ for (const [, declarations] of grouped) {
428
+ if (declarations.length <= 1) {
429
+ continue;
430
+ }
431
+ const unique = [];
432
+ const seenValues = /* @__PURE__ */ new Set();
433
+ for (const decl of declarations) {
434
+ if (decl.parent !== rule) {
435
+ continue;
481
436
  }
482
- });
483
- selectors.walk((selector) => {
484
- if (selector.type === "selector") {
485
- selector.length === 0 && selector.remove();
437
+ const key = `${decl.important ? "!important@@" : ""}${decl.value}`;
438
+ if (seenValues.has(key)) {
439
+ decl.remove();
440
+ continue;
486
441
  }
487
- });
488
- if (selectors.length === 0) {
489
- rule.remove();
442
+ seenValues.add(key);
443
+ unique.push(decl);
490
444
  }
445
+ if (unique.length <= 1) {
446
+ continue;
447
+ }
448
+ const literals = unique.filter((decl) => !VAR_REFERENCE_PATTERN.test(decl.value));
449
+ const variables = unique.filter((decl) => VAR_REFERENCE_PATTERN.test(decl.value));
450
+ if (variables.length === 0 || literals.length === 0) {
451
+ continue;
452
+ }
453
+ const ordered = [...literals, ...variables];
454
+ const alreadyOrdered = ordered.every((decl, index) => decl === unique[index]);
455
+ if (alreadyOrdered) {
456
+ continue;
457
+ }
458
+ const anchor = _nullishCoalesce(_optionalChain([unique, 'access', _19 => _19[unique.length - 1], 'optionalAccess', _20 => _20.next, 'call', _21 => _21()]), () => ( void 0));
459
+ for (const decl of unique) {
460
+ decl.remove();
461
+ }
462
+ for (const decl of ordered) {
463
+ if (anchor) {
464
+ rule.insertBefore(anchor, decl);
465
+ } else {
466
+ rule.append(decl);
467
+ }
468
+ }
469
+ }
470
+ }
471
+ function isNotLastChildPseudo(node) {
472
+ if (!node || node.type !== "pseudo" || node.value !== ":not") {
473
+ return false;
474
+ }
475
+ const selectors = node.nodes;
476
+ if (!selectors || selectors.length !== 1) {
477
+ return false;
478
+ }
479
+ const firstSelector = selectors[0];
480
+ if (firstSelector.type !== "selector") {
481
+ return false;
482
+ }
483
+ const target = _optionalChain([firstSelector, 'access', _22 => _22.nodes, 'optionalAccess', _23 => _23[0]]);
484
+ return Boolean(target && target.type === "pseudo" && target.value === ":last-child");
485
+ }
486
+ function transformSpacingSelector(nodes2, options) {
487
+ if (!nodes2 || nodes2.length === 0) {
488
+ return false;
489
+ }
490
+ for (let idx = 0; idx < nodes2.length; idx++) {
491
+ const current = nodes2[idx];
492
+ if (current.type !== "class" && current.type !== "nesting") {
493
+ continue;
494
+ }
495
+ const combinator = nodes2[idx + 1];
496
+ if (!combinator || combinator.type !== "combinator" || combinator.value !== ">") {
497
+ continue;
498
+ }
499
+ const candidate = nodes2[idx + 2];
500
+ if (!isNotLastChildPseudo(candidate)) {
501
+ continue;
502
+ }
503
+ const ast = getCombinatorSelectorAst(options);
504
+ candidate.replaceWith(...ast);
505
+ return true;
506
+ }
507
+ return false;
508
+ }
509
+ function normalizeSpacingDeclarations(rule) {
510
+ for (const node of [...rule.nodes]) {
511
+ if (node.type !== "decl") {
512
+ continue;
513
+ }
514
+ if (LEGACY_WEBKIT_SPACING_PROPS.has(node.prop)) {
515
+ node.remove();
516
+ continue;
517
+ }
518
+ const mirror = MIRROR_PROP_MAP.get(node.prop);
519
+ if (mirror) {
520
+ node.prop = mirror;
521
+ }
522
+ }
523
+ dedupeSpacingProps(rule);
524
+ }
525
+ function flattenWherePseudo(node, context, index, parent) {
526
+ if (context.options.uniAppX) {
527
+ node.value = ":is";
528
+ }
529
+ if (index === 0 && node.length === 1) {
530
+ const targetSelector = _optionalChain([node, 'access', _24 => _24.nodes, 'optionalAccess', _25 => _25[0]]);
531
+ if (targetSelector && targetSelector.type === "selector" && transformSpacingSelector(targetSelector.nodes, context.options)) {
532
+ context.requiresSpacingNormalization = true;
533
+ }
534
+ node.replaceWith(...node.nodes);
535
+ if (parent && parent.type === "selector" && parent.length === 0) {
536
+ parent.remove();
537
+ }
538
+ }
539
+ }
540
+ function handleClassNode(node, context) {
541
+ if (node.type !== "class") {
542
+ return;
543
+ }
544
+ node.value = internalCssSelectorReplacer(node.value, { escapeMap: context.options.escapeMap });
545
+ }
546
+ function handleUniversalNode(node, context) {
547
+ if (node.type !== "universal") {
548
+ return;
549
+ }
550
+ const replacement = _optionalChain([context, 'access', _26 => _26.options, 'access', _27 => _27.cssSelectorReplacement, 'optionalAccess', _28 => _28.universal]);
551
+ if (replacement) {
552
+ node.value = composeIsPseudo(replacement);
553
+ }
554
+ }
555
+ function shouldRemoveHoverSelector(selector, options) {
556
+ if (!options.cssRemoveHoverPseudoClass) {
557
+ return false;
558
+ }
559
+ return selector.nodes.some((node) => node.type === "pseudo" && node.value === ":hover");
560
+ }
561
+ function isHiddenOrTemplateNotPseudo(node) {
562
+ if (!node || node.type !== "pseudo" || node.value !== ":not") {
563
+ return false;
564
+ }
565
+ const selector = node.first;
566
+ if (!selector || selector.type !== "selector") {
567
+ return false;
568
+ }
569
+ const first = selector.first;
570
+ if (!first) {
571
+ return false;
572
+ }
573
+ if (first.type === "attribute") {
574
+ return first.attribute === "hidden";
575
+ }
576
+ if (first.type === "tag") {
577
+ return first.value === "template";
578
+ }
579
+ return false;
580
+ }
581
+ function handleCombinatorNode(node, index, context) {
582
+ if (node.type !== "combinator" || node.value !== ">") {
583
+ return;
584
+ }
585
+ const nodes2 = _optionalChain([node, 'access', _29 => _29.parent, 'optionalAccess', _30 => _30.nodes]);
586
+ if (!nodes2) {
587
+ return;
588
+ }
589
+ const first = nodes2[index + 1];
590
+ const second = nodes2[index + 2];
591
+ const third = nodes2[index + 3];
592
+ if (isHiddenOrTemplateNotPseudo(first) && second && second.type === "combinator" && (second.value === "~" || second.value === "+") && isHiddenOrTemplateNotPseudo(third)) {
593
+ const ast = getCombinatorSelectorAst(context.options);
594
+ nodes2.splice(index + 1, 3, ...ast);
595
+ }
596
+ }
597
+ function handlePseudoNode(node, index, context, parent) {
598
+ if (node.type !== "pseudo") {
599
+ return;
600
+ }
601
+ if (node.value === ":root" && _optionalChain([context, 'access', _31 => _31.options, 'access', _32 => _32.cssSelectorReplacement, 'optionalAccess', _33 => _33.root])) {
602
+ node.value = composeIsPseudo(context.options.cssSelectorReplacement.root);
603
+ return;
604
+ }
605
+ if (node.value === ":where") {
606
+ flattenWherePseudo(node, context, index, parent);
607
+ }
608
+ }
609
+ function handleTagOrAttribute(node, context) {
610
+ if (!context.options.uniAppX) {
611
+ return;
612
+ }
613
+ if (node.type === "tag" || node.type === "attribute") {
614
+ node.remove();
615
+ }
616
+ }
617
+ function handleSelectorNode(selector, context) {
618
+ if (shouldRemoveHoverSelector(selector, context.options)) {
619
+ selector.remove();
620
+ return;
621
+ }
622
+ if (transformSpacingSelector(selector.nodes, context.options)) {
623
+ context.requiresSpacingNormalization = true;
624
+ }
625
+ }
626
+ function transformSelectors(selectors, context) {
627
+ selectors.walk((node, index) => {
628
+ const parent = _optionalChain([node, 'access', _34 => _34.parent, 'optionalAccess', _35 => _35.type]) === "selector" ? node.parent : void 0;
629
+ switch (node.type) {
630
+ case "class":
631
+ handleClassNode(node, context);
632
+ break;
633
+ case "universal":
634
+ handleUniversalNode(node, context);
635
+ break;
636
+ case "selector":
637
+ handleSelectorNode(node, context);
638
+ break;
639
+ case "pseudo":
640
+ if (!isNotLastChildPseudo(node)) {
641
+ handlePseudoNode(node, index, context, parent);
642
+ }
643
+ break;
644
+ case "combinator":
645
+ handleCombinatorNode(node, index, context);
646
+ break;
647
+ case "tag":
648
+ case "attribute":
649
+ handleTagOrAttribute(node, context);
650
+ break;
651
+ default:
652
+ break;
653
+ }
654
+ });
655
+ if (context.requiresSpacingNormalization) {
656
+ normalizeSpacingDeclarations(context.rule);
657
+ }
658
+ selectors.walk((node) => {
659
+ if (node.type === "selector" && node.length === 0) {
660
+ node.remove();
661
+ }
662
+ });
663
+ if (selectors.length === 0) {
664
+ context.rule.remove();
665
+ }
666
+ }
667
+ function createRuleTransformer(options) {
668
+ let context;
669
+ const transform = (selectors) => {
670
+ if (!context) {
671
+ return;
672
+ }
673
+ transformSelectors(selectors, context);
491
674
  };
492
675
  const parser = _postcssselectorparser2.default.call(void 0, transform);
493
676
  return (rule) => {
494
- currentRule = rule;
677
+ context = {
678
+ options,
679
+ requiresSpacingNormalization: false,
680
+ rule
681
+ };
495
682
  try {
496
683
  parser.transformSync(rule, normalizeTransformOptions());
497
684
  } finally {
498
- currentRule = void 0;
685
+ context = void 0;
499
686
  }
500
687
  };
501
688
  }
@@ -516,7 +703,7 @@ function normalizeSelectorList(value) {
516
703
  return Array.isArray(value) ? value.filter(Boolean) : [value];
517
704
  }
518
705
  function getSpecificityMatchingName(options) {
519
- const feature = _optionalChain([options, 'access', _32 => _32.cssPresetEnv, 'optionalAccess', _33 => _33.features, 'optionalAccess', _34 => _34["is-pseudo-class"]]);
706
+ const feature = _optionalChain([options, 'access', _36 => _36.cssPresetEnv, 'optionalAccess', _37 => _37.features, 'optionalAccess', _38 => _38["is-pseudo-class"]]);
520
707
  if (feature && typeof feature === "object" && "specificityMatchingName" in feature) {
521
708
  const specificityName = feature.specificityMatchingName;
522
709
  return typeof specificityName === "string" && specificityName.length > 0 ? specificityName : void 0;
@@ -525,12 +712,12 @@ function getSpecificityMatchingName(options) {
525
712
  }
526
713
  function createRootSpecificityCleaner(options) {
527
714
  const specificityMatchingName = getSpecificityMatchingName(options);
528
- const selectors = normalizeSelectorList(_optionalChain([options, 'access', _35 => _35.cssSelectorReplacement, 'optionalAccess', _36 => _36.root]));
715
+ const selectors = normalizeSelectorList(_optionalChain([options, 'access', _39 => _39.cssSelectorReplacement, 'optionalAccess', _40 => _40.root]));
529
716
  if (!specificityMatchingName || selectors.length === 0) {
530
717
  return void 0;
531
718
  }
532
719
  const suffix = `:not(.${specificityMatchingName})`;
533
- const targets = selectors.map((selector) => _optionalChain([selector, 'optionalAccess', _37 => _37.trim, 'call', _38 => _38()])).filter((selector) => Boolean(_optionalChain([selector, 'optionalAccess', _39 => _39.length]))).map((selector) => ({
720
+ const targets = selectors.map((selector) => _optionalChain([selector, 'optionalAccess', _41 => _41.trim, 'call', _42 => _42()])).filter((selector) => Boolean(_optionalChain([selector, 'optionalAccess', _43 => _43.length]))).map((selector) => ({
534
721
  match: `${selector}${suffix}`,
535
722
  spacedMatch: `${selector} ${suffix}`,
536
723
  replacement: selector
@@ -559,14 +746,33 @@ function createRootSpecificityCleaner(options) {
559
746
  }
560
747
  var OklabSuffix = "in oklab";
561
748
  var logicalPropMap = /* @__PURE__ */ new Map([
749
+ // margin
562
750
  ["margin-inline-start", "margin-left"],
563
751
  ["margin-inline-end", "margin-right"],
564
752
  ["margin-block-start", "margin-top"],
565
753
  ["margin-block-end", "margin-bottom"],
754
+ // padding
566
755
  ["padding-inline-start", "padding-left"],
567
756
  ["padding-inline-end", "padding-right"],
568
757
  ["padding-block-start", "padding-top"],
569
- ["padding-block-end", "padding-bottom"]
758
+ ["padding-block-end", "padding-bottom"],
759
+ // border
760
+ ["border-inline-start", "border-left"],
761
+ ["border-inline-end", "border-right"],
762
+ ["border-block-start", "border-top"],
763
+ ["border-block-end", "border-bottom"],
764
+ ["border-inline-start-width", "border-left-width"],
765
+ ["border-inline-end-width", "border-right-width"]
766
+ ]);
767
+ var variablePriorityProps = /* @__PURE__ */ new Set([
768
+ "margin-left",
769
+ "margin-right",
770
+ "margin-top",
771
+ "margin-bottom",
772
+ "border-left-width",
773
+ "border-right-width",
774
+ "border-top-width",
775
+ "border-bottom-width"
570
776
  ]);
571
777
  function getCanonicalProp(prop) {
572
778
  return _nullishCoalesce(logicalPropMap.get(prop), () => ( prop));
@@ -583,6 +789,9 @@ function normalizeCalcValue(value) {
583
789
  } while (next !== prev);
584
790
  return next.replace(/calc\(\s*(1\s*-\s*var\([^()]+\))\s*\)/gi, "($1)");
585
791
  }
792
+ function hasVariableReference(value) {
793
+ return value.includes("var(");
794
+ }
586
795
  function dedupeDeclarations(rule) {
587
796
  const entries = [];
588
797
  for (const node of [...rule.nodes]) {
@@ -618,6 +827,73 @@ function dedupeDeclarations(rule) {
618
827
  entry.decl.remove();
619
828
  }
620
829
  }
830
+ const reorderGroups = /* @__PURE__ */ new Map();
831
+ for (const node of rule.nodes) {
832
+ if (node.type !== "decl") {
833
+ continue;
834
+ }
835
+ const canonical = getCanonicalProp(node.prop);
836
+ if (!variablePriorityProps.has(canonical)) {
837
+ continue;
838
+ }
839
+ const existing = reorderGroups.get(canonical);
840
+ if (existing) {
841
+ existing.push(node);
842
+ } else {
843
+ reorderGroups.set(canonical, [node]);
844
+ }
845
+ }
846
+ for (const declarations of reorderGroups.values()) {
847
+ if (declarations.length <= 1) {
848
+ continue;
849
+ }
850
+ const literals = declarations.filter((decl) => !hasVariableReference(decl.value));
851
+ const variables = declarations.filter((decl) => hasVariableReference(decl.value));
852
+ if (literals.length === 0 || variables.length === 0) {
853
+ continue;
854
+ }
855
+ const ordered = [...literals, ...variables];
856
+ let needReorder = false;
857
+ for (let index = 0; index < ordered.length; index++) {
858
+ if (ordered[index] !== declarations[index]) {
859
+ needReorder = true;
860
+ break;
861
+ }
862
+ }
863
+ if (!needReorder) {
864
+ continue;
865
+ }
866
+ const anchor = _nullishCoalesce(_optionalChain([declarations, 'access', _44 => _44[declarations.length - 1], 'optionalAccess', _45 => _45.next, 'call', _46 => _46()]), () => ( void 0));
867
+ for (const decl of declarations) {
868
+ decl.remove();
869
+ }
870
+ for (const decl of ordered) {
871
+ if (anchor) {
872
+ rule.insertBefore(anchor, decl);
873
+ } else {
874
+ rule.append(decl);
875
+ }
876
+ }
877
+ }
878
+ const literalSeen = /* @__PURE__ */ new Map();
879
+ for (const node of [...rule.nodes]) {
880
+ if (node.type !== "decl") {
881
+ continue;
882
+ }
883
+ const canonical = getCanonicalProp(node.prop);
884
+ if (!variablePriorityProps.has(canonical)) {
885
+ continue;
886
+ }
887
+ if (hasVariableReference(node.value)) {
888
+ continue;
889
+ }
890
+ const existing = literalSeen.get(canonical);
891
+ if (existing) {
892
+ node.remove();
893
+ } else {
894
+ literalSeen.set(canonical, node);
895
+ }
896
+ }
621
897
  }
622
898
  var postcssWeappTailwindcssPostPlugin = (options) => {
623
899
  const opts = _shared.defu.call(void 0, options, {
@@ -632,9 +908,9 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
632
908
  const fallbackRemove = enableMainChunkTransforms ? getFallbackRemove(void 0, opts) : void 0;
633
909
  p.RuleExit = (rule) => {
634
910
  if (enableMainChunkTransforms) {
635
- _optionalChain([fallbackRemove, 'optionalAccess', _40 => _40.transformSync, 'call', _41 => _41(rule)]);
911
+ _optionalChain([fallbackRemove, 'optionalAccess', _47 => _47.transformSync, 'call', _48 => _48(rule)]);
636
912
  }
637
- _optionalChain([cleanRootSpecificity, 'optionalCall', _42 => _42(rule)]);
913
+ _optionalChain([cleanRootSpecificity, 'optionalCall', _49 => _49(rule)]);
638
914
  if (enableMainChunkTransforms) {
639
915
  dedupeDeclarations(rule);
640
916
  if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
@@ -658,12 +934,7 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
658
934
  if (opts.cssRemoveProperty && atRule.name === "property") {
659
935
  atRule.remove();
660
936
  }
661
- _optionalChain([atRule, 'access', _43 => _43.nodes, 'optionalAccess', _44 => _44.length]) === 0 && atRule.remove();
662
- };
663
- }
664
- if (typeof opts.customRuleCallback === "function") {
665
- p.Rule = (rule) => {
666
- _optionalChain([opts, 'access', _45 => _45.customRuleCallback, 'optionalCall', _46 => _46(rule, opts)]);
937
+ _optionalChain([atRule, 'access', _50 => _50.nodes, 'optionalAccess', _51 => _51.length]) === 0 && atRule.remove();
667
938
  };
668
939
  }
669
940
  return p;
@@ -1104,7 +1375,7 @@ function remakeCssVarSelector(selectors, options) {
1104
1375
  function commonChunkPreflight(node, options) {
1105
1376
  const { ctx, cssInjectPreflight, injectAdditionalCssVarScope } = options;
1106
1377
  if (testIfVariablesScope(node)) {
1107
- _optionalChain([ctx, 'optionalAccess', _47 => _47.markVariablesScope, 'call', _48 => _48(node)]);
1378
+ _optionalChain([ctx, 'optionalAccess', _52 => _52.markVariablesScope, 'call', _53 => _53(node)]);
1108
1379
  node.selectors = remakeCssVarSelector(node.selectors, options);
1109
1380
  node.before(makePseudoVarRule());
1110
1381
  if (typeof cssInjectPreflight === "function") {
@@ -1169,9 +1440,9 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
1169
1440
  root.walkAtRules((atRule) => {
1170
1441
  if (atRule.name === "layer") {
1171
1442
  if (atRule.params === "properties") {
1172
- if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _49 => _49.nodes, 'optionalAccess', _50 => _50.length]) === 0) {
1443
+ if (atRule.nodes === void 0 || _optionalChain([atRule, 'access', _54 => _54.nodes, 'optionalAccess', _55 => _55.length]) === 0) {
1173
1444
  layerProperties = atRule;
1174
- } else if (_optionalChain([atRule, 'access', _51 => _51.first, 'optionalAccess', _52 => _52.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
1445
+ } else if (_optionalChain([atRule, 'access', _56 => _56.first, 'optionalAccess', _57 => _57.type]) === "atrule" && isTailwindcssV4ModernCheck(atRule.first)) {
1175
1446
  if (layerProperties) {
1176
1447
  layerProperties.replaceWith(atRule.first.nodes);
1177
1448
  atRule.remove();
@@ -1183,7 +1454,7 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
1183
1454
  atRule.replaceWith(atRule.nodes);
1184
1455
  }
1185
1456
  } else if (isTailwindcssV4ModernCheck(atRule)) {
1186
- if (_optionalChain([atRule, 'access', _53 => _53.first, 'optionalAccess', _54 => _54.type]) === "atrule" && atRule.first.name === "layer") {
1457
+ if (_optionalChain([atRule, 'access', _58 => _58.first, 'optionalAccess', _59 => _59.type]) === "atrule" && atRule.first.name === "layer") {
1187
1458
  atRule.replaceWith(atRule.first.nodes);
1188
1459
  }
1189
1460
  }
@@ -1197,39 +1468,163 @@ var postcssWeappTailwindcssPrePlugin = (options) => {
1197
1468
  };
1198
1469
  postcssWeappTailwindcssPrePlugin.postcss = true;
1199
1470
 
1200
- // src/plugins/index.ts
1201
-
1202
- function normalizePlugins(options) {
1203
- const plugins = [];
1204
- const pxPlugin = getPxTransformPlugin(options);
1205
- if (pxPlugin) {
1206
- plugins.push(pxPlugin);
1207
- }
1208
- const remPlugin = getRemTransformPlugin(options);
1209
- if (remPlugin) {
1210
- plugins.push(remPlugin);
1471
+ // src/pipeline.ts
1472
+ var STAGE_ORDER = ["pre", "normal", "post"];
1473
+ function normalizeUserPlugins(plugins) {
1474
+ if (!plugins) {
1475
+ return [];
1211
1476
  }
1212
- const calcPlugin = getCalcPlugin(options);
1213
- if (calcPlugin) {
1214
- plugins.push(calcPlugin);
1477
+ if (Array.isArray(plugins)) {
1478
+ return plugins.filter(Boolean);
1215
1479
  }
1216
- const customPropertyCleaner = getCustomPropertyCleaner(options);
1217
- if (customPropertyCleaner) {
1218
- plugins.push(customPropertyCleaner);
1480
+ if (typeof plugins === "object") {
1481
+ return Object.values(plugins).filter(Boolean);
1219
1482
  }
1220
- return plugins;
1483
+ return [];
1484
+ }
1485
+ function createStaticDefinition(id, stage, plugin) {
1486
+ return {
1487
+ id,
1488
+ stage,
1489
+ prepare: () => ({
1490
+ id,
1491
+ stage,
1492
+ createPlugin: () => plugin
1493
+ })
1494
+ };
1495
+ }
1496
+ function createPipelineDefinitions(options) {
1497
+ const stages = {
1498
+ pre: [],
1499
+ normal: [],
1500
+ post: []
1501
+ };
1502
+ const userPlugins = normalizeUserPlugins(_optionalChain([options, 'access', _60 => _60.postcssOptions, 'optionalAccess', _61 => _61.plugins]));
1503
+ userPlugins.forEach((plugin, index) => {
1504
+ stages.pre.push(createStaticDefinition(`pre:user-${index}`, "pre", plugin));
1505
+ });
1506
+ stages.pre.push({
1507
+ id: "pre:core",
1508
+ stage: "pre",
1509
+ prepare: () => ({
1510
+ id: "pre:core",
1511
+ stage: "pre",
1512
+ createPlugin: () => postcssWeappTailwindcssPrePlugin(options)
1513
+ })
1514
+ });
1515
+ stages.normal.push({
1516
+ id: "normal:preset-env",
1517
+ stage: "normal",
1518
+ prepare: () => ({
1519
+ id: "normal:preset-env",
1520
+ stage: "normal",
1521
+ createPlugin: () => _postcsspresetenv2.default.call(void 0, options.cssPresetEnv)
1522
+ })
1523
+ });
1524
+ stages.normal.push({
1525
+ id: "normal:px-transform",
1526
+ stage: "normal",
1527
+ prepare: () => {
1528
+ const plugin = getPxTransformPlugin(options);
1529
+ return plugin ? {
1530
+ id: "normal:px-transform",
1531
+ stage: "normal",
1532
+ createPlugin: () => plugin
1533
+ } : void 0;
1534
+ }
1535
+ });
1536
+ stages.normal.push({
1537
+ id: "normal:rem-transform",
1538
+ stage: "normal",
1539
+ prepare: () => {
1540
+ const plugin = getRemTransformPlugin(options);
1541
+ return plugin ? {
1542
+ id: "normal:rem-transform",
1543
+ stage: "normal",
1544
+ createPlugin: () => plugin
1545
+ } : void 0;
1546
+ }
1547
+ });
1548
+ stages.normal.push({
1549
+ id: "normal:calc",
1550
+ stage: "normal",
1551
+ prepare: () => {
1552
+ const plugin = getCalcPlugin(options);
1553
+ return plugin ? {
1554
+ id: "normal:calc",
1555
+ stage: "normal",
1556
+ createPlugin: () => plugin
1557
+ } : void 0;
1558
+ }
1559
+ });
1560
+ stages.normal.push({
1561
+ id: "normal:custom-property-cleaner",
1562
+ stage: "normal",
1563
+ prepare: () => {
1564
+ const plugin = getCustomPropertyCleaner(options);
1565
+ return plugin ? {
1566
+ id: "normal:custom-property-cleaner",
1567
+ stage: "normal",
1568
+ createPlugin: () => plugin
1569
+ } : void 0;
1570
+ }
1571
+ });
1572
+ stages.post.push({
1573
+ id: "post:core",
1574
+ stage: "post",
1575
+ prepare: () => ({
1576
+ id: "post:core",
1577
+ stage: "post",
1578
+ createPlugin: () => postcssWeappTailwindcssPostPlugin(options)
1579
+ })
1580
+ });
1581
+ return STAGE_ORDER.flatMap((stage) => stages[stage]);
1221
1582
  }
1222
- function getPlugins(options) {
1223
- const ctx = createContext();
1224
- options.ctx = ctx;
1225
- const plugins = [
1226
- ..._nullishCoalesce(_optionalChain([options, 'access', _55 => _55.postcssOptions, 'optionalAccess', _56 => _56.plugins]), () => ( [])),
1227
- postcssWeappTailwindcssPrePlugin(options),
1228
- _postcsspresetenv2.default.call(void 0, options.cssPresetEnv),
1229
- ...normalizePlugins(options),
1230
- postcssWeappTailwindcssPostPlugin(options)
1231
- ].filter(Boolean);
1232
- return plugins;
1583
+ function createStylePipeline(options) {
1584
+ options.ctx = createContext();
1585
+ const preparedNodes = createPipelineDefinitions(options).map((definition) => definition.prepare(options)).filter(Boolean);
1586
+ if (preparedNodes.length === 0) {
1587
+ return {
1588
+ nodes: [],
1589
+ plugins: []
1590
+ };
1591
+ }
1592
+ const stageSizes = /* @__PURE__ */ new Map();
1593
+ preparedNodes.forEach((node) => {
1594
+ stageSizes.set(node.stage, (_nullishCoalesce(stageSizes.get(node.stage), () => ( 0))) + 1);
1595
+ });
1596
+ const stageIndices = /* @__PURE__ */ new Map();
1597
+ const nodes2 = [];
1598
+ const size = preparedNodes.length;
1599
+ preparedNodes.forEach((node, index) => {
1600
+ const stageIndex = _nullishCoalesce(stageIndices.get(node.stage), () => ( 0));
1601
+ const context = {
1602
+ stage: node.stage,
1603
+ index,
1604
+ size,
1605
+ stageIndex,
1606
+ stageSize: _nullishCoalesce(stageSizes.get(node.stage), () => ( 0)),
1607
+ previous: index > 0 ? {
1608
+ id: preparedNodes[index - 1].id,
1609
+ stage: preparedNodes[index - 1].stage
1610
+ } : void 0,
1611
+ next: index < size - 1 ? {
1612
+ id: preparedNodes[index + 1].id,
1613
+ stage: preparedNodes[index + 1].stage
1614
+ } : void 0
1615
+ };
1616
+ stageIndices.set(node.stage, stageIndex + 1);
1617
+ nodes2.push({
1618
+ id: node.id,
1619
+ stage: node.stage,
1620
+ plugin: node.createPlugin(context),
1621
+ context
1622
+ });
1623
+ });
1624
+ return {
1625
+ nodes: nodes2,
1626
+ plugins: nodes2.map((node) => node.plugin)
1627
+ };
1233
1628
  }
1234
1629
 
1235
1630
  // src/preflight.ts
@@ -1255,22 +1650,22 @@ function createInjectPreflight(options) {
1255
1650
  function createProcessOptions(options) {
1256
1651
  return {
1257
1652
  from: void 0,
1258
- ..._nullishCoalesce(_optionalChain([options, 'access', _57 => _57.postcssOptions, 'optionalAccess', _58 => _58.options]), () => ( {}))
1653
+ ..._nullishCoalesce(_optionalChain([options, 'access', _62 => _62.postcssOptions, 'optionalAccess', _63 => _63.options]), () => ( {}))
1259
1654
  };
1260
1655
  }
1261
- var pluginCache = /* @__PURE__ */ new WeakMap();
1656
+ var pipelineCache = /* @__PURE__ */ new WeakMap();
1262
1657
  var processOptionsCache = /* @__PURE__ */ new WeakMap();
1263
1658
  var processOptionsSourceCache = /* @__PURE__ */ new WeakMap();
1264
- function getCachedPlugins(options) {
1265
- let plugins = pluginCache.get(options);
1266
- if (!plugins) {
1267
- plugins = getPlugins(options);
1268
- pluginCache.set(options, plugins);
1659
+ function getCachedPipeline(options) {
1660
+ let pipeline = pipelineCache.get(options);
1661
+ if (!pipeline) {
1662
+ pipeline = createStylePipeline(options);
1663
+ pipelineCache.set(options, pipeline);
1269
1664
  }
1270
- return plugins;
1665
+ return pipeline;
1271
1666
  }
1272
1667
  function getCachedProcessOptions(options) {
1273
- const source = _optionalChain([options, 'access', _59 => _59.postcssOptions, 'optionalAccess', _60 => _60.options]);
1668
+ const source = _optionalChain([options, 'access', _64 => _64.postcssOptions, 'optionalAccess', _65 => _65.options]);
1274
1669
  let cached = processOptionsCache.get(options);
1275
1670
  const cachedSource = processOptionsSourceCache.get(options);
1276
1671
  if (!cached || cachedSource !== source) {
@@ -1281,7 +1676,7 @@ function getCachedProcessOptions(options) {
1281
1676
  return { ...cached };
1282
1677
  }
1283
1678
  function styleHandler(rawSource, options) {
1284
- const plugins = getCachedPlugins(options);
1679
+ const plugins = getCachedPipeline(options).plugins;
1285
1680
  const processOptions = getCachedProcessOptions(options);
1286
1681
  return _postcss2.default.call(void 0, plugins).process(
1287
1682
  rawSource,
@@ -1294,18 +1689,27 @@ function createStyleHandler(options) {
1294
1689
  getDefaultOptions(options)
1295
1690
  );
1296
1691
  cachedOptions.cssInjectPreflight = createInjectPreflight(cachedOptions.cssPreflight);
1297
- getCachedPlugins(cachedOptions);
1692
+ getCachedPipeline(cachedOptions);
1298
1693
  getCachedProcessOptions(cachedOptions);
1299
- return (rawSource, opt) => {
1694
+ const handler = ((rawSource, opt) => {
1300
1695
  const resolvedOptions = _shared.defuOverrideArray.call(void 0, opt, cachedOptions);
1301
1696
  return styleHandler(
1302
1697
  rawSource,
1303
1698
  resolvedOptions
1304
1699
  );
1700
+ });
1701
+ handler.getPipeline = (opt) => {
1702
+ if (!opt) {
1703
+ return getCachedPipeline(cachedOptions);
1704
+ }
1705
+ const resolvedOptions = _shared.defuOverrideArray.call(void 0, opt, cachedOptions);
1706
+ return getCachedPipeline(resolvedOptions);
1305
1707
  };
1708
+ return handler;
1306
1709
  }
1307
1710
 
1308
1711
 
1309
1712
 
1310
1713
 
1311
- exports.createInjectPreflight = createInjectPreflight; exports.createStyleHandler = createStyleHandler; exports.internalCssSelectorReplacer = internalCssSelectorReplacer;
1714
+
1715
+ exports.createInjectPreflight = createInjectPreflight; exports.createStyleHandler = createStyleHandler; exports.createStylePipeline = createStylePipeline; exports.internalCssSelectorReplacer = internalCssSelectorReplacer;