tailwind_merge 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1d84d9d8ccb31fb4d40b8b3c01bdd4360a629bbb1edb6372c67e2593cec0fb9
4
- data.tar.gz: db09d2ca1a88e1e55dabe545307f94694bb05f38591a889d6cd5d4eea86b82d6
3
+ metadata.gz: 73a6da6946240630bba6b40dded91a06fb9ccf65ae58f71194bce07f2c706dd2
4
+ data.tar.gz: d8cd3a6cf999db8da115cc9ea90ed2ee33429998ee6ef35c184f99dca0924c59
5
5
  SHA512:
6
- metadata.gz: 67975440de152fe04b60ef762e6c6de724e45a6d3c8cbe922dcd13e9bea4cda1fd0253db2e6731014d1045c341e466d85fdbcfbb1f4657645e0ae3f8082d6a33
7
- data.tar.gz: 5d5e38c0173bb4cc06982aa1a381892c0223fa71709b485945bdf057d3358085714de24929766793a01431dd9da4cd858c7dc7b71c4ae7300a2ac4a0f7061419
6
+ metadata.gz: bd8ef4e8237ccf306153378db32e14c9b852f580b6cda79a95736a07763ac66d2f7a60a17bc65ace4ad27a9d7e7330e844702004d5c3a6030ca4306258f437a8
7
+ data.tar.gz: 2853d2427d0747761d90afc105e2226a4a6a0127b61448bcfc3fddff80a55858d371c503fa535c52e2313202599fd0d9aeb4b1f519e83ab3b57d982494e42f3d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.7.2](https://github.com/gjtorikian/tailwind_merge/tree/v0.7.2) (2023-06-08)
4
+
5
+ [Full Changelog](https://github.com/gjtorikian/tailwind_merge/compare/v0.7.1.2...v0.7.2)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Fix basis-auto and basis-full not being merged correctly [\#13](https://github.com/gjtorikian/tailwind_merge/pull/13) ([gjtorikian](https://github.com/gjtorikian))
10
+
3
11
  ## [v0.7.1.2](https://github.com/gjtorikian/tailwind_merge/tree/v0.7.1.2) (2023-06-02)
4
12
 
5
13
  [Full Changelog](https://github.com/gjtorikian/tailwind_merge/compare/v0.7.1.1...v0.7.1.2)
data/README.md CHANGED
@@ -91,6 +91,13 @@ The order of standard modifiers does not matter for tailwind-merge.
91
91
  @merger.merge('grid-cols-[1fr,auto] grid-cols-2') # → 'grid-cols-2'
92
92
  ```
93
93
 
94
+ > **Warning**
95
+ > Labels necessary in ambiguous cases
96
+ >
97
+ > When using arbitrary values in ambiguous classes like `text-[calc(var(--rebecca)-1rem)]` tailwind-merge looks at the arbitrary value for clues to determine what type of class it is. In this case, like in most ambiguous classes, it would try to figure out whether `calc(var(--rebecca)-1rem)` is a length (making it a font-size class) or a color (making it a text-color class). For lengths it takes clues into account like the presence of the `calc()` function or a digit followed by a length unit like `1rem`.
98
+ >
99
+ > But it isn't always possible to figure out the type by looking at the arbitrary value. E.g. in the class `text-[theme(myCustomScale.rebecca)]` tailwind-merge can't know the type of the arbitrary value and will default to a text-color class. To make tailwind-merge understand the correct type of the arbitrary value in those cases, you can use CSS data type labels [which are used by Tailwind CSS to disambiguate classes](https://tailwindcss.com/docs/adding-custom-styles#resolving-ambiguities): `text-[lengt
100
+
94
101
  ### Supports arbitrary properties
95
102
 
96
103
  ```ruby
@@ -101,8 +108,7 @@ The order of standard modifiers does not matter for tailwind-merge.
101
108
  @merger.merge('[padding:1rem] p-8') # → '[padding:1rem] p-8'
102
109
  ```
103
110
 
104
- > **Warning**
105
- > Watch out for using arbitrary properties which could be expressed as Tailwind classes. `tailwind_merge` does not resolve conflicts between arbitrary properties and their matching Tailwind classes to keep the bundle size small.
111
+ > **Warning** > `tailwind_merge` does not resolve conflicts between arbitrary properties and their matching Tailwind classes to keep the bundle size small.
106
112
 
107
113
  ### Supports arbitrary variants
108
114
 
@@ -34,7 +34,7 @@ module TailwindMerge
34
34
 
35
35
  return class_group_from_next_class_part if class_group_from_next_class_part
36
36
 
37
- return nil if class_part_object[:validators].empty?
37
+ return if class_part_object[:validators].empty?
38
38
 
39
39
  class_rest = class_parts.join(CLASS_PART_SEPARATOR)
40
40
 
@@ -64,7 +64,8 @@ module TailwindMerge
64
64
 
65
65
  OVERSCROLL = -> { ["auto", "contain", "none"] }
66
66
  OVERFLOW = -> { ["auto", "hidden", "clip", "visible", "scroll"] }
67
- SPACING_WITH_AUTO = -> { ["auto", SPACING] }
67
+ SPACING_WITH_AUTO_AND_ARBITRARY = -> { ["auto", IS_ARBITRARY_VALUE, SPACING] }
68
+ SPACING_WITH_ARBITRARY = -> { [IS_ARBITRARY_VALUE, SPACING] }
68
69
  LENGTH_WITH_EMPTY = -> { ["", IS_LENGTH] }
69
70
  NUMBER_WITH_AUTO_AND_ARBITRARY = -> { ["auto", IS_NUMBER, IS_ARBITRARY_VALUE] }
70
71
  POSITIONS = -> {
@@ -114,29 +115,29 @@ module TailwindMerge
114
115
  theme: {
115
116
  "colors" => [IS_ANY],
116
117
  "spacing" => [IS_LENGTH],
117
- "blur" => ["none", "", IS_TSHIRT_SIZE, IS_ARBITRARY_LENGTH],
118
+ "blur" => ["none", "", IS_TSHIRT_SIZE, IS_ARBITRARY_VALUE],
118
119
  "brightness" => NUMBER.call,
119
120
  "border-color" => [COLORS],
120
- "border-radius" => ["none", "", "full", IS_TSHIRT_SIZE, IS_ARBITRARY_LENGTH],
121
- "border-spacing" => [SPACING],
121
+ "border-radius" => ["none", "", "full", IS_TSHIRT_SIZE, IS_ARBITRARY_VALUE],
122
+ "border-spacing" => SPACING_WITH_ARBITRARY.call,
122
123
  "border-width" => LENGTH_WITH_EMPTY.call,
123
124
  "contrast" => NUMBER.call,
124
125
  "grayscale" => ZERO_AND_EMPTY.call,
125
126
  "hue-rotate" => NUMBER_AND_ARBITRARY.call,
126
127
  "invert" => ZERO_AND_EMPTY.call,
127
- "gap" => [SPACING],
128
+ "gap" => SPACING_WITH_ARBITRARY.call,
128
129
  "gradient-color-stops" => [COLORS],
129
130
  "gradient-color-stop-positions" => [IS_PERCENT, IS_ARBITRARY_LENGTH],
130
- "inset" => SPACING_WITH_AUTO.call,
131
- "margin" => SPACING_WITH_AUTO.call,
131
+ "inset" => SPACING_WITH_AUTO_AND_ARBITRARY.call,
132
+ "margin" => SPACING_WITH_AUTO_AND_ARBITRARY.call,
132
133
  "opacity" => NUMBER.call,
133
- "padding" => [SPACING],
134
+ "padding" => SPACING_WITH_ARBITRARY.call,
134
135
  "saturate" => NUMBER.call,
135
136
  "scale" => NUMBER.call,
136
137
  "sepia" => ZERO_AND_EMPTY.call,
137
138
  "skew" => NUMBER_AND_ARBITRARY.call,
138
- "space" => [SPACING],
139
- "translate" => [SPACING],
139
+ "space" => SPACING_WITH_ARBITRARY.call,
140
+ "translate" => SPACING_WITH_ARBITRARY.call,
140
141
  },
141
142
  class_groups: { # rubocop:disable Metrics/CollectionLiteralLength
142
143
  # Layout
@@ -327,7 +328,7 @@ module TailwindMerge
327
328
  # Flex Basis
328
329
  # @see https://tailwindcss.com/docs/flex-basis
329
330
  ##
330
- "basis" => [{ "basis" => SPACING_WITH_AUTO.call }],
331
+ "basis" => [{ "basis" => SPACING_WITH_AUTO_AND_ARBITRARY.call }],
331
332
  ##
332
333
  # Flex Direction
333
334
  # @see https://tailwindcss.com/docs/flex-direction
@@ -589,12 +590,12 @@ module TailwindMerge
589
590
  # Width
590
591
  # @see https://tailwindcss.com/docs/width
591
592
  ##
592
- "w" => [{ "w" => ["auto", "min", "max", "fit", SPACING] }],
593
+ "w" => [{ "w" => ["auto", "min", "max", "fit", IS_ARBITRARY_VALUE, SPACING] }],
593
594
  ##
594
595
  # Min-Width
595
596
  # @see https://tailwindcss.com/docs/min-width
596
597
  ##
597
- "min-w" => [{ "min-w" => ["min", "max", "fit", IS_LENGTH] }],
598
+ "min-w" => [{ "min-w" => ["min", "max", "fit", IS_ARBITRARY_VALUE, IS_LENGTH] }],
598
599
  ##
599
600
  # Max-Width
600
601
  # @see https://tailwindcss.com/docs/max-width
@@ -611,7 +612,7 @@ module TailwindMerge
611
612
  "prose",
612
613
  { "screen" => [IS_TSHIRT_SIZE] },
613
614
  IS_TSHIRT_SIZE,
614
- IS_ARBITRARY_LENGTH,
615
+ IS_ARBITRARY_VALUE,
615
616
  ],
616
617
  },
617
618
  ],
@@ -619,17 +620,17 @@ module TailwindMerge
619
620
  # Height
620
621
  # @see https://tailwindcss.com/docs/height
621
622
  ##
622
- "h" => [{ "h" => ["auto", "min", "max", "fit", SPACING] }],
623
+ "h" => [{ "h" => [IS_ARBITRARY_VALUE, SPACING, "auto", "min", "max", "fit"] }],
623
624
  ##
624
625
  # Min-Height
625
626
  # @see https://tailwindcss.com/docs/min-height
626
627
  ##
627
- "min-h" => [{ "min-h" => ["min", "max", "fit", IS_LENGTH] }],
628
+ "min-h" => [{ "min-h" => ["min", "max", "fit", IS_ARBITRARY_VALUE, IS_LENGTH] }],
628
629
  ##
629
630
  # Max-Height
630
631
  # @see https://tailwindcss.com/docs/max-height
631
632
  ##
632
- "max-h" => [{ "max-h" => [SPACING, "min", "max", "fit"] }],
633
+ "max-h" => [{ "max-h" => [IS_ARBITRARY_VALUE, SPACING, "min", "max", "fit"] }],
633
634
  # Typography
634
635
  ##
635
636
  # Font Size
@@ -714,7 +715,7 @@ module TailwindMerge
714
715
  "wide",
715
716
  "wider",
716
717
  "widest",
717
- IS_ARBITRARY_LENGTH,
718
+ IS_ARBITRARY_VALUE,
718
719
  ],
719
720
  }, # rubocop:enable Metrics/CollectionLiteralLength
720
721
  ],
@@ -728,7 +729,7 @@ module TailwindMerge
728
729
  # @see https://tailwindcss.com/docs/line-height
729
730
  ##
730
731
  "leading" => [
731
- { "leading" => ["none", "tight", "snug", "normal", "relaxed", "loose", IS_LENGTH] },
732
+ { "leading" => ["none", "tight", "snug", "normal", "relaxed", "loose", IS_ARBITRARY_VALUE, IS_LENGTH] },
732
733
  ],
733
734
  #
734
735
  # List Style Image
@@ -790,7 +791,7 @@ module TailwindMerge
790
791
  # Text Underline Offset
791
792
  # @see https://tailwindcss.com/docs/text-underline-offset
792
793
  ##
793
- "underline-offset" => [{ "underline-offset" => ["auto", IS_LENGTH] }],
794
+ "underline-offset" => [{ "underline-offset" => ["auto", IS_ARBITRARY_VALUE, IS_LENGTH] }],
794
795
  ##
795
796
  # Text Decoration Color
796
797
  # @see https://tailwindcss.com/docs/text-decoration-color
@@ -810,7 +811,7 @@ module TailwindMerge
810
811
  # Text Indent
811
812
  # @see https://tailwindcss.com/docs/text-indent
812
813
  ##
813
- "indent" => [{ "indent" => [SPACING] }],
814
+ "indent" => [{ "indent" => SPACING_WITH_ARBITRARY.call }],
814
815
  ##
815
816
  # Vertical Alignment
816
817
  # @see https://tailwindcss.com/docs/vertical-align
@@ -826,7 +827,7 @@ module TailwindMerge
826
827
  "text-bottom",
827
828
  "sub",
828
829
  "super",
829
- IS_ARBITRARY_LENGTH,
830
+ IS_ARBITRARY_VALUE,
830
831
  ],
831
832
  },
832
833
  ],
@@ -1145,7 +1146,7 @@ module TailwindMerge
1145
1146
  # Outline Offset
1146
1147
  # @see https://tailwindcss.com/docs/outline-offset
1147
1148
  ##
1148
- "outline-offset" => [{ "outline-offset" => [IS_LENGTH] }],
1149
+ "outline-offset" => [{ "outline-offset" => [IS_ARBITRARY_VALUE, IS_LENGTH] }],
1149
1150
  ##
1150
1151
  # Outline Width
1151
1152
  # @see https://tailwindcss.com/docs/outline-width
@@ -1533,92 +1534,92 @@ module TailwindMerge
1533
1534
  # Scroll Margin
1534
1535
  # @see https://tailwindcss.com/docs/scroll-margin
1535
1536
  ##
1536
- "scroll-m" => [{ "scroll-m" => [SPACING] }],
1537
+ "scroll-m" => [{ "scroll-m" => SPACING_WITH_ARBITRARY.call }],
1537
1538
  ##
1538
1539
  # Scroll Margin X
1539
1540
  # @see https://tailwindcss.com/docs/scroll-margin
1540
1541
  ##
1541
- "scroll-mx" => [{ "scroll-mx" => [SPACING] }],
1542
+ "scroll-mx" => [{ "scroll-mx" => SPACING_WITH_ARBITRARY.call }],
1542
1543
  ##
1543
1544
  # Scroll Margin Y
1544
1545
  # @see https://tailwindcss.com/docs/scroll-margin
1545
1546
  ##
1546
- "scroll-my" => [{ "scroll-my" => [SPACING] }],
1547
+ "scroll-my" => [{ "scroll-my" => SPACING_WITH_ARBITRARY.call }],
1547
1548
  #
1548
1549
  # Scroll Margin Start
1549
1550
  # @see https://tailwindcss.com/docs/scroll-margin
1550
1551
  #
1551
- "scroll-ms" => [{ "scroll-ms" => [SPACING] }],
1552
+ "scroll-ms" => [{ "scroll-ms" => SPACING_WITH_ARBITRARY.call }],
1552
1553
  #
1553
1554
  # Scroll Margin End
1554
1555
  # @see https://tailwindcss.com/docs/scroll-margin
1555
1556
  #
1556
- "scroll-me" => [{ "scroll-me" => [SPACING] }],
1557
+ "scroll-me" => [{ "scroll-me" => SPACING_WITH_ARBITRARY.call }],
1557
1558
  ##
1558
1559
  # Scroll Margin Top
1559
1560
  # @see https://tailwindcss.com/docs/scroll-margin
1560
1561
  ##
1561
- "scroll-mt" => [{ "scroll-mt" => [SPACING] }],
1562
+ "scroll-mt" => [{ "scroll-mt" => SPACING_WITH_ARBITRARY.call }],
1562
1563
  ##
1563
1564
  # Scroll Margin Right
1564
1565
  # @see https://tailwindcss.com/docs/scroll-margin
1565
1566
  ##
1566
- "scroll-mr" => [{ "scroll-mr" => [SPACING] }],
1567
+ "scroll-mr" => [{ "scroll-mr" => SPACING_WITH_ARBITRARY.call }],
1567
1568
  ##
1568
1569
  # Scroll Margin Bottom
1569
1570
  # @see https://tailwindcss.com/docs/scroll-margin
1570
1571
  ##
1571
- "scroll-mb" => [{ "scroll-mb" => [SPACING] }],
1572
+ "scroll-mb" => [{ "scroll-mb" => SPACING_WITH_ARBITRARY.call }],
1572
1573
  ##
1573
1574
  # Scroll Margin Left
1574
1575
  # @see https://tailwindcss.com/docs/scroll-margin
1575
1576
  ##
1576
- "scroll-ml" => [{ "scroll-ml" => [SPACING] }],
1577
+ "scroll-ml" => [{ "scroll-ml" => SPACING_WITH_ARBITRARY.call }],
1577
1578
  ##
1578
1579
  # Scroll Padding
1579
1580
  # @see https://tailwindcss.com/docs/scroll-padding
1580
1581
  ##
1581
- "scroll-p" => [{ "scroll-p" => [SPACING] }],
1582
+ "scroll-p" => [{ "scroll-p" => SPACING_WITH_ARBITRARY.call }],
1582
1583
  ##
1583
1584
  # Scroll Padding X
1584
1585
  # @see https://tailwindcss.com/docs/scroll-padding
1585
1586
  ##
1586
- "scroll-px" => [{ "scroll-px" => [SPACING] }],
1587
+ "scroll-px" => [{ "scroll-px" => SPACING_WITH_ARBITRARY.call }],
1587
1588
  ##
1588
1589
  # Scroll Padding Y
1589
1590
  # @see https://tailwindcss.com/docs/scroll-padding
1590
1591
  ##
1591
- "scroll-py" => [{ "scroll-py" => [SPACING] }],
1592
+ "scroll-py" => [{ "scroll-py" => SPACING_WITH_ARBITRARY.call }],
1592
1593
  #
1593
1594
  # Scroll Padding Start
1594
1595
  # @see https://tailwindcss.com/docs/scroll-padding
1595
1596
  #
1596
- "scroll-ps" => [{ "scroll-ps" => [SPACING] }],
1597
+ "scroll-ps" => [{ "scroll-ps" => SPACING_WITH_ARBITRARY.call }],
1597
1598
  #
1598
1599
  # Scroll Padding End
1599
1600
  # @see https://tailwindcss.com/docs/scroll-padding
1600
1601
  #
1601
- "scroll-pe" => [{ "scroll-pe" => [SPACING] }],
1602
+ "scroll-pe" => [{ "scroll-pe" => SPACING_WITH_ARBITRARY.call }],
1602
1603
  ##
1603
1604
  # Scroll Padding Top
1604
1605
  # @see https://tailwindcss.com/docs/scroll-padding
1605
1606
  ##
1606
- "scroll-pt" => [{ "scroll-pt" => [SPACING] }],
1607
+ "scroll-pt" => [{ "scroll-pt" => SPACING_WITH_ARBITRARY.call }],
1607
1608
  ##
1608
1609
  # Scroll Padding Right
1609
1610
  # @see https://tailwindcss.com/docs/scroll-padding
1610
1611
  ##
1611
- "scroll-pr" => [{ "scroll-pr" => [SPACING] }],
1612
+ "scroll-pr" => [{ "scroll-pr" => SPACING_WITH_ARBITRARY.call }],
1612
1613
  ##
1613
1614
  # Scroll Padding Bottom
1614
1615
  # @see https://tailwindcss.com/docs/scroll-padding
1615
1616
  ##
1616
- "scroll-pb" => [{ "scroll-pb" => [SPACING] }],
1617
+ "scroll-pb" => [{ "scroll-pb" => SPACING_WITH_ARBITRARY.call }],
1617
1618
  ##
1618
1619
  # Scroll Padding Left
1619
1620
  # @see https://tailwindcss.com/docs/scroll-padding
1620
1621
  ##
1621
- "scroll-pl" => [{ "scroll-pl" => [SPACING] }],
1622
+ "scroll-pl" => [{ "scroll-pl" => SPACING_WITH_ARBITRARY.call }],
1622
1623
  ##
1623
1624
  # Scroll Snap Align
1624
1625
  # @see https://tailwindcss.com/docs/scroll-snap-align
@@ -27,7 +27,7 @@ module TailwindMerge
27
27
 
28
28
  ARBITRARY_VALUE_REGEX = /^\[(?:([a-z-]+):)?(.+)\]$/i
29
29
  FRACTION_REGEX = %r{^\d+/\d+$}
30
- LENGTH_UNIT_REGEX = /\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|^0$/
30
+ LENGTH_UNIT_REGEX = /\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/
31
31
  TSHIRT_UNIT_REGEX = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/
32
32
  # Shadow always begins with x and y offset separated by underscore
33
33
  SHADOW_REGEX = /^-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TailwindMerge
4
- VERSION = "0.7.2"
4
+ VERSION = "0.7.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tailwind_merge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen J. Torikian
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-08 00:00:00.000000000 Z
11
+ date: 2023-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lru_redux
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  requirements: []
103
- rubygems_version: 3.4.13
103
+ rubygems_version: 3.4.14
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Utility function to efficiently merge Tailwind CSS classes without style