@weapp-tailwindcss/postcss 1.3.2 → 1.3.3-alpha.0

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
@@ -514,6 +514,67 @@ function ruleTransformSync(rule, options) {
514
514
 
515
515
  // src/plugins/post.ts
516
516
  var OklabSuffix = "in oklab";
517
+ var logicalPropMap = /* @__PURE__ */ new Map([
518
+ ["margin-inline-start", "margin-left"],
519
+ ["margin-inline-end", "margin-right"],
520
+ ["margin-block-start", "margin-top"],
521
+ ["margin-block-end", "margin-bottom"],
522
+ ["padding-inline-start", "padding-left"],
523
+ ["padding-inline-end", "padding-right"],
524
+ ["padding-block-start", "padding-top"],
525
+ ["padding-block-end", "padding-bottom"]
526
+ ]);
527
+ function getCanonicalProp(prop) {
528
+ return _nullishCoalesce(logicalPropMap.get(prop), () => ( prop));
529
+ }
530
+ function normalizeCalcValue(value) {
531
+ if (!value.includes("calc")) {
532
+ return value;
533
+ }
534
+ let next = value;
535
+ let prev;
536
+ do {
537
+ prev = next;
538
+ next = prev.replace(/calc\(\s*calc\(/gi, "calc((");
539
+ } while (next !== prev);
540
+ return next.replace(/calc\(\s*(1\s*-\s*var\([^()]+\))\s*\)/gi, "($1)");
541
+ }
542
+ function dedupeDeclarations(rule) {
543
+ const entries = [];
544
+ for (const node of [...rule.nodes]) {
545
+ if (node.type !== "decl") {
546
+ continue;
547
+ }
548
+ const decl = node;
549
+ const normalizedValue = normalizeCalcValue(decl.value);
550
+ if (normalizedValue !== decl.value) {
551
+ decl.value = normalizedValue;
552
+ }
553
+ const canonicalProp = getCanonicalProp(decl.prop);
554
+ entries.push({
555
+ decl,
556
+ normalizedValue,
557
+ canonicalProp,
558
+ importantKey: decl.important ? "!important" : "",
559
+ isLogical: canonicalProp !== decl.prop
560
+ });
561
+ }
562
+ const seen = /* @__PURE__ */ new Map();
563
+ for (const entry of entries) {
564
+ const key = `${entry.canonicalProp}${entry.importantKey}@@${entry.normalizedValue}`;
565
+ const existing = seen.get(key);
566
+ if (!existing) {
567
+ seen.set(key, entry);
568
+ continue;
569
+ }
570
+ if (existing.isLogical && !entry.isLogical) {
571
+ existing.decl.remove();
572
+ seen.set(key, entry);
573
+ } else {
574
+ entry.decl.remove();
575
+ }
576
+ }
577
+ }
517
578
  var postcssWeappTailwindcssPostPlugin = (options) => {
518
579
  const opts = _shared.defu.call(void 0, options, {
519
580
  isMainChunk: true
@@ -525,6 +586,7 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
525
586
  const fallbackRemove = getFallbackRemove(void 0, opts);
526
587
  p.RuleExit = (rule) => {
527
588
  fallbackRemove.transformSync(rule);
589
+ dedupeDeclarations(rule);
528
590
  if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
529
591
  rule.remove();
530
592
  }
package/dist/index.mjs CHANGED
@@ -514,6 +514,67 @@ function ruleTransformSync(rule, options) {
514
514
 
515
515
  // src/plugins/post.ts
516
516
  var OklabSuffix = "in oklab";
517
+ var logicalPropMap = /* @__PURE__ */ new Map([
518
+ ["margin-inline-start", "margin-left"],
519
+ ["margin-inline-end", "margin-right"],
520
+ ["margin-block-start", "margin-top"],
521
+ ["margin-block-end", "margin-bottom"],
522
+ ["padding-inline-start", "padding-left"],
523
+ ["padding-inline-end", "padding-right"],
524
+ ["padding-block-start", "padding-top"],
525
+ ["padding-block-end", "padding-bottom"]
526
+ ]);
527
+ function getCanonicalProp(prop) {
528
+ return logicalPropMap.get(prop) ?? prop;
529
+ }
530
+ function normalizeCalcValue(value) {
531
+ if (!value.includes("calc")) {
532
+ return value;
533
+ }
534
+ let next = value;
535
+ let prev;
536
+ do {
537
+ prev = next;
538
+ next = prev.replace(/calc\(\s*calc\(/gi, "calc((");
539
+ } while (next !== prev);
540
+ return next.replace(/calc\(\s*(1\s*-\s*var\([^()]+\))\s*\)/gi, "($1)");
541
+ }
542
+ function dedupeDeclarations(rule) {
543
+ const entries = [];
544
+ for (const node of [...rule.nodes]) {
545
+ if (node.type !== "decl") {
546
+ continue;
547
+ }
548
+ const decl = node;
549
+ const normalizedValue = normalizeCalcValue(decl.value);
550
+ if (normalizedValue !== decl.value) {
551
+ decl.value = normalizedValue;
552
+ }
553
+ const canonicalProp = getCanonicalProp(decl.prop);
554
+ entries.push({
555
+ decl,
556
+ normalizedValue,
557
+ canonicalProp,
558
+ importantKey: decl.important ? "!important" : "",
559
+ isLogical: canonicalProp !== decl.prop
560
+ });
561
+ }
562
+ const seen = /* @__PURE__ */ new Map();
563
+ for (const entry of entries) {
564
+ const key = `${entry.canonicalProp}${entry.importantKey}@@${entry.normalizedValue}`;
565
+ const existing = seen.get(key);
566
+ if (!existing) {
567
+ seen.set(key, entry);
568
+ continue;
569
+ }
570
+ if (existing.isLogical && !entry.isLogical) {
571
+ existing.decl.remove();
572
+ seen.set(key, entry);
573
+ } else {
574
+ entry.decl.remove();
575
+ }
576
+ }
577
+ }
517
578
  var postcssWeappTailwindcssPostPlugin = (options) => {
518
579
  const opts = defu(options, {
519
580
  isMainChunk: true
@@ -525,6 +586,7 @@ var postcssWeappTailwindcssPostPlugin = (options) => {
525
586
  const fallbackRemove = getFallbackRemove(void 0, opts);
526
587
  p.RuleExit = (rule) => {
527
588
  fallbackRemove.transformSync(rule);
589
+ dedupeDeclarations(rule);
528
590
  if (rule.selectors.length === 0 || rule.selectors.length === 1 && rule.selector.trim() === "") {
529
591
  rule.remove();
530
592
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/postcss",
3
- "version": "1.3.2",
3
+ "version": "1.3.3-alpha.0",
4
4
  "description": "@weapp-tailwindcss/postcss",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -47,13 +47,13 @@
47
47
  "postcss-rem-to-responsive-pixel": "~6.1.0",
48
48
  "postcss-selector-parser": "~7.1.0",
49
49
  "postcss-value-parser": "^4.2.0",
50
- "@weapp-tailwindcss/shared": "1.0.3"
50
+ "@weapp-tailwindcss/shared": "1.1.0-alpha.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@csstools/postcss-is-pseudo-class": "^5.0.3",
54
54
  "postcss-calc": "^10.1.1",
55
55
  "postcss-custom-properties": "^14.0.6",
56
- "@weapp-tailwindcss/mangle": "1.0.5"
56
+ "@weapp-tailwindcss/mangle": "1.0.6-alpha.0"
57
57
  },
58
58
  "scripts": {
59
59
  "dev": "tsup --watch --sourcemap",