tailwind_merge 0.6.0 → 0.7.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +6 -0
- data/lib/tailwind_merge/class_utils.rb +8 -2
- data/lib/tailwind_merge/config.rb +3 -0
- data/lib/tailwind_merge/modifier_utils.rb +13 -5
- data/lib/tailwind_merge/validators.rb +3 -3
- data/lib/tailwind_merge/version.rb +1 -1
- data/lib/tailwind_merge.rb +25 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14ce1b50125c55e8f6d320cb0886d221ca2b91ddaf70e3c57fdb3147416d751f
|
4
|
+
data.tar.gz: dcedb7f0b798ae164669cccfd3f2c41385c5f33c36ea289d79062c8cdd806393
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a02d67ea60287416a8c1a9b2076aedf1e0864dec8c2fd36ffe69492c1eac386e99eac2b84bd035a9e2d69728bd9711d256550329015d6056708a2f836260f8f4
|
7
|
+
data.tar.gz: 94bec180c77255b7d74cfc730fffbc28869150b8d0efdb3ebef019e7a0b7e36c9552887884c72c7d1104a9dc525b93a367555dd0f122ecbb9d01aa4108df03a2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
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
|
+
|
3
11
|
## [v0.6.0](https://github.com/gjtorikian/tailwind_merge/tree/v0.6.0) (2023-03-29)
|
4
12
|
|
5
13
|
[Full Changelog](https://github.com/gjtorikian/tailwind_merge/compare/v0.5.2...v0.6.0)
|
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
|
@@ -51,8 +51,14 @@ module TailwindMerge
|
|
51
51
|
result.nil? ? result : result[:class_group_id]
|
52
52
|
end
|
53
53
|
|
54
|
-
def get_conflicting_class_group_ids(class_group_id)
|
55
|
-
@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
|
56
62
|
end
|
57
63
|
|
58
64
|
private def create_class_map(config)
|
@@ -1782,6 +1782,9 @@ module TailwindMerge
|
|
1782
1782
|
"scroll-px" => ["scroll-pr", "scroll-pl"],
|
1783
1783
|
"scroll-py" => ["scroll-pt", "scroll-pb"],
|
1784
1784
|
},
|
1785
|
+
conflicting_class_group_modifiers: {
|
1786
|
+
"font-size": ["leading"],
|
1787
|
+
},
|
1785
1788
|
}.freeze
|
1786
1789
|
|
1787
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?
|
17
|
-
if
|
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
|
30
|
+
if char == "["
|
24
31
|
bracket_depth += 1
|
25
|
-
elsif
|
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
|
|
data/lib/tailwind_merge.rb
CHANGED
@@ -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
|
-
|
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.
|
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-03
|
11
|
+
date: 2023-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lru_redux
|