tailwind_merge 0.5.2 → 0.7.0

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: 841da2a133c0b534ffaf670b2d392f22ea11ed1f073f196af0cb7a2faef236b0
4
- data.tar.gz: 0f3acf7e784203b48b89bf6edc0607971c5dadd3da378e3f098ecd4ae0f289a2
3
+ metadata.gz: 14ce1b50125c55e8f6d320cb0886d221ca2b91ddaf70e3c57fdb3147416d751f
4
+ data.tar.gz: dcedb7f0b798ae164669cccfd3f2c41385c5f33c36ea289d79062c8cdd806393
5
5
  SHA512:
6
- metadata.gz: b094c38211947c3110c538c982e0e38ac85aebc39d10619caf2d5fe9dadae8d81413f4ab052a789398cd728d1070c206401d7f8691cd17af87ef8bb784e09609
7
- data.tar.gz: a2aaf8d635559f1055f4324f3dd622daf8bb75e3ff36cf24dd118261165dcc90f2272143bbca31dc1350101682cde21bb38d5c1a18ba8271138a4a6f7a470eec
6
+ metadata.gz: a02d67ea60287416a8c1a9b2076aedf1e0864dec8c2fd36ffe69492c1eac386e99eac2b84bd035a9e2d69728bd9711d256550329015d6056708a2f836260f8f4
7
+ data.tar.gz: 94bec180c77255b7d74cfc730fffbc28869150b8d0efdb3ebef019e7a0b7e36c9552887884c72c7d1104a9dc525b93a367555dd0f122ecbb9d01aa4108df03a2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.7.0](https://github.com/gjtorikian/tailwind_merge/tree/v0.7.0) (2023-04-03)
4
+
5
+ [Full Changelog](https://github.com/gjtorikian/tailwind_merge/compare/v0.6.0...v0.7.0)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Add postfix support [\#10](https://github.com/gjtorikian/tailwind_merge/pull/10) ([gjtorikian](https://github.com/gjtorikian))
10
+
11
+ ## [v0.6.0](https://github.com/gjtorikian/tailwind_merge/tree/v0.6.0) (2023-03-29)
12
+
13
+ [Full Changelog](https://github.com/gjtorikian/tailwind_merge/compare/v0.5.2...v0.6.0)
14
+
15
+ **Merged pull requests:**
16
+
17
+ - Support 3.3 [\#9](https://github.com/gjtorikian/tailwind_merge/pull/9) ([gjtorikian](https://github.com/gjtorikian))
18
+
3
19
  ## [v0.5.2](https://github.com/gjtorikian/tailwind_merge/tree/v0.5.2) (2023-02-21)
4
20
 
5
21
  [Full Changelog](https://github.com/gjtorikian/tailwind_merge/compare/v0.5.1...v0.5.2)
data/Gemfile CHANGED
@@ -15,5 +15,5 @@ gem "github_changelog_generator", "~> 1.16"
15
15
 
16
16
  gem "rubocop-standard"
17
17
 
18
- gem "amazing_print"
19
- gem "debug"
18
+ gem "amazing_print", require: false
19
+ gem "debug", require: false
data/README.md CHANGED
@@ -122,6 +122,12 @@ Similarly to arbitrary properties, `tailwind_merge` does not resolve conflicts b
122
122
  @merger.merge('!right-2 !-inset-x-1') # → '!-inset-x-1'
123
123
  ```
124
124
 
125
+ ## Supports postfix modifiers
126
+
127
+ ```ts
128
+ twMerge('text-sm leading-6 text-lg/7') // → 'text-lg/7'
129
+ ```
130
+
125
131
  ### Preserves non-Tailwind classes
126
132
 
127
133
  ```ruby
@@ -266,6 +272,7 @@ In the Tailwind config you can modify theme scales. `tailwind_merge` follows the
266
272
  - `invert`
267
273
  - `gap`
268
274
  - `gradientColorStops`
275
+ - `gradientColorStopPositions`
269
276
  - `inset`
270
277
  - `margin`
271
278
  - `opacity`
@@ -286,6 +293,7 @@ Here's a brief summary for each validator:
286
293
  - `IS_LENGTH` checks whether a class part is a number (`3`, `1.5`), a fraction (`3/4`), a arbitrary length (`[3%]`, `[4px]`, `[length:var(--my-var)]`), or one of the strings `px`, `full` or `screen`.
287
294
  - `IS_ARBITRARY_LENGTH` checks for arbitrary length values (`[3%]`, `[4px]`, `[length:var(--my-var)]`).
288
295
  - `IS_INTEGER` checks for integer values (`3`) and arbitrary integer values (`[3]`).
296
+ - `IS_PERCENT` checks for percent values (`12.5%`) which is used for color stop positions.
289
297
  - `IS_ARBITRARY_VALUE` checks whether the class part is enclosed in brackets (`[something]`)
290
298
  - `IS_TSHIRT_SIZE`checks whether class part is a T-shirt size (`sm`, `xl`), optionally with a preceding number (`2xl`).
291
299
  - `IS_ARBITRARY_SIZE` checks whether class part is an arbitrary value which starts with `size:` (`[size:200px_100px]`) which is necessary for background-size classNames.
@@ -39,18 +39,26 @@ module TailwindMerge
39
39
  class_rest = class_parts.join(CLASS_PART_SEPARATOR)
40
40
 
41
41
  result = class_part_object[:validators].find do |v|
42
- if from_theme?(v[:validator])
43
- v[:validator].call(@config)
42
+ validator = v[:validator]
43
+
44
+ if from_theme?(validator)
45
+ validator.call(@config)
44
46
  else
45
- v[:validator].call(class_rest)
47
+ validator.call(class_rest)
46
48
  end
47
49
  end
48
50
 
49
51
  result.nil? ? result : result[:class_group_id]
50
52
  end
51
53
 
52
- def get_conflicting_class_group_ids(class_group_id)
53
- @config[:conflicting_class_groups][class_group_id] || []
54
+ def get_conflicting_class_group_ids(class_group_id, has_postfix_modifier)
55
+ conflicts = @config[:conflicting_class_groups][class_group_id] || []
56
+
57
+ if has_postfix_modifier && @config[:conflicting_class_group_modifiers][class_group_id]
58
+ return [...conflicts, ...@config[:conflicting_class_group_modifiers][class_group_id]]
59
+ end
60
+
61
+ conflicts
54
62
  end
55
63
 
56
64
  private def create_class_map(config)
@@ -22,6 +22,7 @@ module TailwindMerge
22
22
  INVERT = ->(config) { FROM_THEME.call(config, "invert") }
23
23
  GAP = ->(config) { FROM_THEME.call(config, "gap") }
24
24
  GRADIENT_COLOR_STOPS = ->(config) { FROM_THEME.call(config, "gradient-color-stops") }
25
+ GRADIENT_COLOR_STOP_POSITIONS = ->(config) { FROM_THEME.call(config, "gradient-color-stop-positions") }
25
26
  INSET = ->(config) { FROM_THEME.call(config, "inset") }
26
27
  MARGIN = ->(config) { FROM_THEME.call(config, "margin") }
27
28
  OPACITY = ->(config) { FROM_THEME.call(config, "opacity") }
@@ -48,6 +49,7 @@ module TailwindMerge
48
49
  INVERT.object_id,
49
50
  GAP.object_id,
50
51
  GRADIENT_COLOR_STOPS.object_id,
52
+ GRADIENT_COLOR_STOP_POSITIONS.object_id,
51
53
  INSET.object_id,
52
54
  MARGIN.object_id,
53
55
  OPACITY.object_id,
@@ -100,7 +102,7 @@ module TailwindMerge
100
102
  "plus-lighter",
101
103
  ]
102
104
  }
103
- ALIGN = -> { ["start", "end", "center", "between", "around", "evenly"] }
105
+ ALIGN = -> { ["start", "end", "center", "between", "around", "evenly", "stretch"] }
104
106
  ZERO_AND_EMPTY = -> { ["", "0", IS_ARBITRARY_VALUE] }
105
107
  BREAKS = -> { ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"] }
106
108
  NUMBER = -> { [IS_NUMBER, IS_ARBITRARY_NUMBER] }
@@ -124,6 +126,7 @@ module TailwindMerge
124
126
  "invert" => ZERO_AND_EMPTY.call,
125
127
  "gap" => [SPACING],
126
128
  "gradient-color-stops" => [COLORS],
129
+ "gradient-color-stop-positions" => [IS_PERCENT, IS_ARBITRARY_LENGTH],
127
130
  "inset" => SPACING_WITH_AUTO.call,
128
131
  "margin" => SPACING_WITH_AUTO.call,
129
132
  "opacity" => NUMBER.call,
@@ -135,7 +138,7 @@ module TailwindMerge
135
138
  "space" => [SPACING],
136
139
  "translate" => [SPACING],
137
140
  },
138
- class_groups: {
141
+ class_groups: { # rubocop:disable Metrics/CollectionLiteralLength
139
142
  # Layout
140
143
  ##
141
144
  # Aspect Ratio
@@ -279,6 +282,16 @@ module TailwindMerge
279
282
  # @see https://tailwindcss.com/docs/top-right-bottom-left
280
283
  ##
281
284
  "inset-y" => [{ "inset-y" => [INSET] }],
285
+ #
286
+ # Start
287
+ # @see https://tailwindcss.com/docs/top-right-bottom-left
288
+ #
289
+ "start" => [{ "start" => [INSET] }],
290
+ #
291
+ # End
292
+ # @see https://tailwindcss.com/docs/top-right-bottom-left
293
+ #
294
+ "end" => [{ "end" => [INSET] }],
282
295
  ##
283
296
  # Top
284
297
  # @see https://tailwindcss.com/docs/top-right-bottom-left
@@ -419,7 +432,7 @@ module TailwindMerge
419
432
  # Justify Content
420
433
  # @see https://tailwindcss.com/docs/justify-content
421
434
  ##
422
- "justify-content" => [{ "justify" => ALIGN.call }],
435
+ "justify-content" => [{ "justify" => ["normal", *ALIGN.call] }],
423
436
  ##
424
437
  # Justify Items
425
438
  # @see https://tailwindcss.com/docs/justify-items
@@ -434,7 +447,7 @@ module TailwindMerge
434
447
  # Align Content
435
448
  # @see https://tailwindcss.com/docs/align-content
436
449
  ##
437
- "align-content" => [{ content: [*ALIGN.call, "baseline"] }],
450
+ "align-content" => [{ "content" => ["normal", *ALIGN.call, "baseline"] }],
438
451
  ##
439
452
  # Align Items
440
453
  # @see https://tailwindcss.com/docs/align-items
@@ -449,7 +462,7 @@ module TailwindMerge
449
462
  # Place Content
450
463
  # @see https://tailwindcss.com/docs/place-content
451
464
  ##
452
- "place-content" => [{ "place-content" => [*ALIGN.call, "baseline", "stretch"] }],
465
+ "place-content" => [{ "place-content" => [*ALIGN.call, "baseline"] }],
453
466
  ##
454
467
  # Place Items
455
468
  # @see https://tailwindcss.com/docs/place-items
@@ -476,6 +489,16 @@ module TailwindMerge
476
489
  # @see https://tailwindcss.com/docs/padding
477
490
  ##
478
491
  "py" => [{ "py" => [PADDING] }],
492
+ #
493
+ # Padding Start
494
+ # @see https://tailwindcss.com/docs/padding
495
+ #
496
+ "ps" => [{ "ps" => [PADDING] }],
497
+ #
498
+ # Padding End
499
+ # @see https://tailwindcss.com/docs/padding
500
+ #
501
+ "pe" => [{ "pe" => [PADDING] }],
479
502
  ##
480
503
  # Padding Top
481
504
  # @see https://tailwindcss.com/docs/padding
@@ -511,6 +534,16 @@ module TailwindMerge
511
534
  # @see https://tailwindcss.com/docs/margin
512
535
  ##
513
536
  "my" => [{ "my" => [MARGIN] }],
537
+ #
538
+ # Margin Start
539
+ # @see https://tailwindcss.com/docs/margin
540
+ #
541
+ "ms" => [{ "ms" => [MARGIN] }],
542
+ #
543
+ # Margin End
544
+ # @see https://tailwindcss.com/docs/margin
545
+ #
546
+ "me" => [{ "me" => [MARGIN] }],
514
547
  ##
515
548
  # Margin Top
516
549
  # @see https://tailwindcss.com/docs/margin
@@ -683,8 +716,13 @@ module TailwindMerge
683
716
  "widest",
684
717
  IS_ARBITRARY_LENGTH,
685
718
  ],
686
- },
719
+ }, # rubocop:enable Metrics/CollectionLiteralLength
687
720
  ],
721
+ #
722
+ # Line Clamp
723
+ # @see https://tailwindcss.com/docs/line-clamp
724
+ #
725
+ "line-clamp" => [{ "line-clamp" => ["none", IS_NUMBER, IS_ARBITRARY_NUMBER] }],
688
726
  ##
689
727
  # Line Height
690
728
  # @see https://tailwindcss.com/docs/line-height
@@ -692,6 +730,11 @@ module TailwindMerge
692
730
  "leading" => [
693
731
  { "leading" => ["none", "tight", "snug", "normal", "relaxed", "loose", IS_LENGTH] },
694
732
  ],
733
+ #
734
+ # List Style Image
735
+ # @see https://tailwindcss.com/docs/list-style-image
736
+ #
737
+ "list-image" => [{ "list-image" => ["none", IS_ARBITRARY_VALUE] }],
695
738
  ##
696
739
  # List Style Type
697
740
  # @see https://tailwindcss.com/docs/list-style-type
@@ -791,12 +834,17 @@ module TailwindMerge
791
834
  # Whitespace
792
835
  # @see https://tailwindcss.com/docs/whitespace
793
836
  ##
794
- "whitespace" => [{ "whitespace" => ["normal", "nowrap", "pre", "pre-line", "pre-wrap"] }],
837
+ "whitespace" => [{ "whitespace" => ["normal", "nowrap", "pre", "pre-line", "pre-wrap", "break-spaces"] }],
795
838
  ##
796
839
  # Word Break
797
840
  # @see https://tailwindcss.com/docs/word-break
798
841
  ##
799
842
  "break" => [{ "break" => ["normal", "words", "all", "keep"] }],
843
+ #
844
+ # Hyphens
845
+ # @see https://tailwindcss.com/docs/hyphens
846
+ #
847
+ "hyphens" => [{ "hyphens" => ["none", "manual", "auto"] }],
800
848
  ##
801
849
  # Content
802
850
  # @see https://tailwindcss.com/docs/content
@@ -857,6 +905,21 @@ module TailwindMerge
857
905
  # @see https://tailwindcss.com/docs/background-color
858
906
  ##
859
907
  "bg-color" => [{ "bg" => [COLORS] }],
908
+ #
909
+ # Gradient Color Stops From Position
910
+ # @see https://tailwindcss.com/docs/gradient-color-stops
911
+ #
912
+ "gradient-from-pos" => [{ "from" => [GRADIENT_COLOR_STOP_POSITIONS] }],
913
+ #
914
+ # Gradient Color Stops Via Position
915
+ # @see https://tailwindcss.com/docs/gradient-color-stops
916
+ #
917
+ "gradient-via-pos" => [{ "via" => [GRADIENT_COLOR_STOP_POSITIONS] }],
918
+ #
919
+ # Gradient Color Stops To Position
920
+ # @see https://tailwindcss.com/docs/gradient-color-stops
921
+ #
922
+ "gradient-to-pos" => [{ "to" => [GRADIENT_COLOR_STOP_POSITIONS] }],
860
923
  ##
861
924
  # Gradient Color Stops From
862
925
  # @see https://tailwindcss.com/docs/gradient-color-stops
@@ -878,6 +941,16 @@ module TailwindMerge
878
941
  # @see https://tailwindcss.com/docs/border-radius
879
942
  ##
880
943
  "rounded" => [{ "rounded" => [BORDER_RADIUS] }],
944
+ #
945
+ # Border Radius Start
946
+ # @see https://tailwindcss.com/docs/border-radius
947
+ #
948
+ "rounded-s" => [{ "rounded-s" => [BORDER_RADIUS] }],
949
+ #
950
+ # Border Radius End
951
+ # @see https://tailwindcss.com/docs/border-radius
952
+ #
953
+ "rounded-e" => [{ "rounded-e" => [BORDER_RADIUS] }],
881
954
  ##
882
955
  # Border Radius Top
883
956
  # @see https://tailwindcss.com/docs/border-radius
@@ -898,6 +971,26 @@ module TailwindMerge
898
971
  # @see https://tailwindcss.com/docs/border-radius
899
972
  ##
900
973
  "rounded-l" => [{ "rounded-l" => [BORDER_RADIUS] }],
974
+ #
975
+ # Border Radius Start Start
976
+ # @see https://tailwindcss.com/docs/border-radius
977
+ #
978
+ "rounded-ss" => [{ "rounded-ss" => [BORDER_RADIUS] }],
979
+ #
980
+ # Border Radius Start End
981
+ # @see https://tailwindcss.com/docs/border-radius
982
+ #
983
+ "rounded-se" => [{ "rounded-se" => [BORDER_RADIUS] }],
984
+ #
985
+ # Border Radius End End
986
+ # @see https://tailwindcss.com/docs/border-radius
987
+ #
988
+ "rounded-ee" => [{ "rounded-ee" => [BORDER_RADIUS] }],
989
+ #
990
+ # Border Radius End Start
991
+ # @see https://tailwindcss.com/docs/border-radius
992
+ #
993
+ "rounded-es" => [{ "rounded-es" => [BORDER_RADIUS] }],
901
994
  ##
902
995
  # Border Radius Top Left
903
996
  # @see https://tailwindcss.com/docs/border-radius
@@ -933,6 +1026,16 @@ module TailwindMerge
933
1026
  # @see https://tailwindcss.com/docs/border-width
934
1027
  ##
935
1028
  "border-w-y" => [{ "border-y" => [BORDER_WIDTH] }],
1029
+ #
1030
+ # Border Width Start
1031
+ # @see https://tailwindcss.com/docs/border-width
1032
+ #
1033
+ "border-w-s" => [{ "border-s" => [BORDER_WIDTH] }],
1034
+ #
1035
+ # Border Width End
1036
+ # @see https://tailwindcss.com/docs/border-width
1037
+ #
1038
+ "border-w-e" => [{ "border-e" => [BORDER_WIDTH] }],
936
1039
  ##
937
1040
  # Border Width Top
938
1041
  # @see https://tailwindcss.com/docs/border-width
@@ -1238,6 +1341,11 @@ module TailwindMerge
1238
1341
  # @see https://tailwindcss.com/docs/table-layout
1239
1342
  ##
1240
1343
  "table-layout" => [{ "table" => ["auto", "fixed"] }],
1344
+ #
1345
+ # Caption Side
1346
+ # @see https://tailwindcss.com/docs/caption-side
1347
+ #
1348
+ "caption" => [{ "caption" => ["top", "bottom"] }],
1241
1349
  # Transitions and Animation
1242
1350
  ##
1243
1351
  # Tranisition Property
@@ -1261,7 +1369,7 @@ module TailwindMerge
1261
1369
  # Transition Duration
1262
1370
  # @see https://tailwindcss.com/docs/transition-duration
1263
1371
  ##
1264
- "duration" => [{ "duration" => [NUMBER_AND_ARBITRARY] }],
1372
+ "duration" => [{ "duration" => NUMBER_AND_ARBITRARY.call }],
1265
1373
  ##
1266
1374
  # Transition Timing Function
1267
1375
  # @see https://tailwindcss.com/docs/transition-timing-function
@@ -1271,7 +1379,7 @@ module TailwindMerge
1271
1379
  # Transition Delay
1272
1380
  # @see https://tailwindcss.com/docs/transition-delay
1273
1381
  ##
1274
- "delay" => [{ "delay" => [NUMBER_AND_ARBITRARY] }],
1382
+ "delay" => [{ "delay" => NUMBER_AND_ARBITRARY.call }],
1275
1383
  ##
1276
1384
  # Animation
1277
1385
  # @see https://tailwindcss.com/docs/animation
@@ -1436,6 +1544,16 @@ module TailwindMerge
1436
1544
  # @see https://tailwindcss.com/docs/scroll-margin
1437
1545
  ##
1438
1546
  "scroll-my" => [{ "scroll-my" => [SPACING] }],
1547
+ #
1548
+ # Scroll Margin Start
1549
+ # @see https://tailwindcss.com/docs/scroll-margin
1550
+ #
1551
+ "scroll-ms" => [{ "scroll-ms" => [SPACING] }],
1552
+ #
1553
+ # Scroll Margin End
1554
+ # @see https://tailwindcss.com/docs/scroll-margin
1555
+ #
1556
+ "scroll-me" => [{ "scroll-me" => [SPACING] }],
1439
1557
  ##
1440
1558
  # Scroll Margin Top
1441
1559
  # @see https://tailwindcss.com/docs/scroll-margin
@@ -1471,6 +1589,16 @@ module TailwindMerge
1471
1589
  # @see https://tailwindcss.com/docs/scroll-padding
1472
1590
  ##
1473
1591
  "scroll-py" => [{ "scroll-py" => [SPACING] }],
1592
+ #
1593
+ # Scroll Padding Start
1594
+ # @see https://tailwindcss.com/docs/scroll-padding
1595
+ #
1596
+ "scroll-ps" => [{ "scroll-ps" => [SPACING] }],
1597
+ #
1598
+ # Scroll Padding End
1599
+ # @see https://tailwindcss.com/docs/scroll-padding
1600
+ #
1601
+ "scroll-pe" => [{ "scroll-pe" => [SPACING] }],
1474
1602
  ##
1475
1603
  # Scroll Padding Top
1476
1604
  # @see https://tailwindcss.com/docs/scroll-padding
@@ -1564,15 +1692,15 @@ module TailwindMerge
1564
1692
  conflicting_class_groups: {
1565
1693
  "overflow" => ["overflow-x", "overflow-y"],
1566
1694
  "overscroll" => ["overscroll-x", "overscroll-y"],
1567
- "inset" => ["inset-x", "inset-y", "top", "right", "bottom", "left"],
1695
+ "inset" => ["inset-x", "inset-y", "start", "end", "top", "right", "bottom", "left"],
1568
1696
  "inset-x" => ["right", "left"],
1569
1697
  "inset-y" => ["top", "bottom"],
1570
1698
  "flex" => ["basis", "grow", "shrink"],
1571
1699
  "gap" => ["gap-x", "gap-y"],
1572
- "p" => ["px", "py", "pt", "pr", "pb", "pl"],
1700
+ "p" => ["px", "py", "ps", "pe", "pt", "pr", "pb", "pl"],
1573
1701
  "px" => ["pr", "pl"],
1574
1702
  "py" => ["pt", "pb"],
1575
- "m" => ["mx", "my", "mt", "mr", "mb", "ml"],
1703
+ "m" => ["mx", "my", "ms", "me", "mt", "mr", "mb", "ml"],
1576
1704
  "mx" => ["mr", "ml"],
1577
1705
  "my" => ["mt", "mb"],
1578
1706
  "font-size" => ["leading"],
@@ -1589,21 +1717,36 @@ module TailwindMerge
1589
1717
  "fvn-spacing" => ["fvn-normal"],
1590
1718
  "fvn-fraction" => ["fvn-normal"],
1591
1719
  "rounded" => [
1720
+ "rounded-s",
1721
+ "rounded-e",
1592
1722
  "rounded-t",
1593
1723
  "rounded-r",
1594
1724
  "rounded-b",
1595
1725
  "rounded-l",
1726
+ "rounded-ss",
1727
+ "rounded-se",
1728
+ "rounded-ee",
1729
+ "rounded-es",
1596
1730
  "rounded-tl",
1597
1731
  "rounded-tr",
1598
1732
  "rounded-br",
1599
1733
  "rounded-bl",
1600
1734
  ],
1735
+ "rounded-s" => ["rounded-ss", "rounded-es"],
1736
+ "rounded-e" => ["rounded-se", "rounded-ee"],
1601
1737
  "rounded-t" => ["rounded-tl", "rounded-tr"],
1602
1738
  "rounded-r" => ["rounded-tr", "rounded-br"],
1603
1739
  "rounded-b" => ["rounded-br", "rounded-bl"],
1604
1740
  "rounded-l" => ["rounded-tl", "rounded-bl"],
1605
1741
  "border-spacing" => ["border-spacing-x", "border-spacing-y"],
1606
- "border-w" => ["border-w-t", "border-w-r", "border-w-b", "border-w-l"],
1742
+ "border-w" => [
1743
+ "border-w-s",
1744
+ "border-w-e",
1745
+ "border-w-t",
1746
+ "border-w-r",
1747
+ "border-w-b",
1748
+ "border-w-l",
1749
+ ],
1607
1750
  "border-w-x" => ["border-w-r", "border-w-l"],
1608
1751
  "border-w-y" => ["border-w-t", "border-w-b"],
1609
1752
  "border-color" => [
@@ -1617,6 +1760,8 @@ module TailwindMerge
1617
1760
  "scroll-m" => [
1618
1761
  "scroll-mx",
1619
1762
  "scroll-my",
1763
+ "scroll-ms",
1764
+ "scroll-me",
1620
1765
  "scroll-mt",
1621
1766
  "scroll-mr",
1622
1767
  "scroll-mb",
@@ -1627,6 +1772,8 @@ module TailwindMerge
1627
1772
  "scroll-p" => [
1628
1773
  "scroll-px",
1629
1774
  "scroll-py",
1775
+ "scroll-ps",
1776
+ "scroll-pe",
1630
1777
  "scroll-pt",
1631
1778
  "scroll-pr",
1632
1779
  "scroll-pb",
@@ -1635,6 +1782,9 @@ module TailwindMerge
1635
1782
  "scroll-px" => ["scroll-pr", "scroll-pl"],
1636
1783
  "scroll-py" => ["scroll-pt", "scroll-pb"],
1637
1784
  },
1785
+ conflicting_class_group_modifiers: {
1786
+ "font-size": ["leading"],
1787
+ },
1638
1788
  }.freeze
1639
1789
 
1640
1790
  def merge_configs(extension_config)
@@ -7,22 +7,29 @@ module TailwindMerge
7
7
  def split_modifiers(class_name, separator: nil)
8
8
  separator ||= ":"
9
9
  separator_length = separator.length
10
+ seperator_is_single_char = separator_length == 1
11
+ first_seperator_char = separator[0]
10
12
 
11
13
  modifiers = []
12
14
  bracket_depth = 0
13
15
  modifier_start = 0
16
+ postfix_modifier_position = 0
14
17
 
15
18
  class_name.each_char.with_index do |char, index|
16
- if bracket_depth.zero? && char == separator[0]
17
- if separator_length == 1 || class_name[index..(index + separator_length - 1)] == separator
19
+ if bracket_depth.zero?
20
+ if char == first_seperator_char && (seperator_is_single_char || class_name[index..(index + separator_length - 1)] == separator)
18
21
  modifiers << class_name[modifier_start..index]
19
22
  modifier_start = index + separator_length
23
+ next
24
+ elsif char == "/"
25
+ postfix_modifier_position = index
26
+ next
20
27
  end
21
28
  end
22
29
 
23
- if class_name[index] == "["
30
+ if char == "["
24
31
  bracket_depth += 1
25
- elsif class_name[index] == "]"
32
+ elsif char == "]"
26
33
  bracket_depth -= 1
27
34
  end
28
35
  end
@@ -30,8 +37,9 @@ module TailwindMerge
30
37
  base_class_name_with_important_modifier = modifiers.empty? ? class_name : class_name[modifier_start..-1]
31
38
  has_important_modifier = base_class_name_with_important_modifier.start_with?(IMPORTANT_MODIFIER)
32
39
  base_class_name = has_important_modifier ? base_class_name_with_important_modifier[1..-1] : base_class_name_with_important_modifier
40
+ maybe_postfix_modifier_position = postfix_modifier_position && postfix_modifier_position > modifier_start ? postfix_modifier_position - modifier_start : false
33
41
 
34
- [modifiers, has_important_modifier, base_class_name]
42
+ [modifiers, has_important_modifier, base_class_name, maybe_postfix_modifier_position]
35
43
  end
36
44
 
37
45
  # Sorts modifiers according to following schema:
@@ -55,9 +55,9 @@ module TailwindMerge
55
55
  }
56
56
 
57
57
  IS_LENGTH = ->(value) {
58
- numeric?(value) || \
59
- STRING_LENGTHS.include?(value) || \
60
- FRACTION_REGEX.match?(value) || \
58
+ numeric?(value) ||
59
+ STRING_LENGTHS.include?(value) ||
60
+ FRACTION_REGEX.match?(value) ||
61
61
  IS_ARBITRARY_LENGTH.call(value)
62
62
  }
63
63
 
@@ -85,6 +85,10 @@ module TailwindMerge
85
85
  is_number.call(value)
86
86
  }
87
87
 
88
+ IS_PERCENT = ->(value) {
89
+ value.end_with?("%") && is_number.call(value[0..-2])
90
+ }
91
+
88
92
  IS_INTEGER = ->(value) {
89
93
  is_integer_only.call(value) || arbitrary_value?(value, "number", is_integer_only)
90
94
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TailwindMerge
4
- VERSION = "0.5.2"
4
+ VERSION = "0.7.0"
5
5
  end
@@ -49,11 +49,31 @@ module TailwindMerge
49
49
  class_groups_in_conflict = Set.new
50
50
 
51
51
  classes.strip.split(SPLIT_CLASSES_REGEX).map do |original_class_name|
52
- modifiers, has_important_modifier, base_class_name = split_modifiers(original_class_name, separator: @config[:separator])
52
+ modifiers, has_important_modifier, base_class_name, maybe_postfix_modifier_position = split_modifiers(original_class_name, separator: @config[:separator])
53
53
 
54
- class_group_id = @class_utils.class_group_id(base_class_name)
54
+ actual_base_class_name = maybe_postfix_modifier_position ? base_class_name[0...maybe_postfix_modifier_position] : base_class_name
55
+ class_group_id = @class_utils.class_group_id(actual_base_class_name)
55
56
 
56
57
  unless class_group_id
58
+ unless maybe_postfix_modifier_position
59
+ next {
60
+ is_tailwind_class: false,
61
+ original_class_name: original_class_name,
62
+ }
63
+ end
64
+
65
+ class_group_id = @class_utils.class_group_id(base_class_name)
66
+
67
+ unless class_group_id
68
+ next {
69
+ isTailwindClass: false,
70
+ original_class_name: original_class_name,
71
+ }
72
+
73
+ end
74
+
75
+ has_postfix_modifier = false
76
+
57
77
  next {
58
78
  is_tailwind_class: false,
59
79
  original_class_name: original_class_name,
@@ -69,6 +89,7 @@ module TailwindMerge
69
89
  modifier_id: modifier_id,
70
90
  class_group_id: class_group_id,
71
91
  original_class_name: original_class_name,
92
+ has_postfix_modifier: has_postfix_modifier,
72
93
  }
73
94
  end.reverse # Last class in conflict wins, so filter conflicting classes in reverse order.
74
95
  .select do |parsed|
@@ -76,6 +97,7 @@ module TailwindMerge
76
97
 
77
98
  modifier_id = parsed[:modifier_id]
78
99
  class_group_id = parsed[:class_group_id]
100
+ has_postfix_modifier = parsed[:has_postfix_modifier]
79
101
 
80
102
  class_id = "#{modifier_id}#{class_group_id}"
81
103
 
@@ -83,7 +105,7 @@ module TailwindMerge
83
105
 
84
106
  class_groups_in_conflict.add(class_id)
85
107
 
86
- @class_utils.get_conflicting_class_group_ids(class_group_id).each do |group|
108
+ @class_utils.get_conflicting_class_group_ids(class_group_id, has_postfix_modifier).each do |group|
87
109
  class_groups_in_conflict.add("#{modifier_id}#{group}")
88
110
  end
89
111
 
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.5.2
4
+ version: 0.7.0
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-02-21 00:00:00.000000000 Z
11
+ date: 2023-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lru_redux