tailwind_merge 0.12.0 → 0.13.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 +19 -0
- data/README.md +13 -2
- data/lib/tailwind_merge/config.rb +12 -10
- data/lib/tailwind_merge/version.rb +1 -1
- data/lib/tailwind_merge.rb +38 -39
- 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: 963bec3ea5a28c6f2e282b5836fd2b1bb317aafee92a6c65872b1b52919bca3a
|
4
|
+
data.tar.gz: 8b86c7e251064a52b8a591933bb09dcdf5e72efba0edc508066d0bcbf3bf3cfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f980fb0cb733e00de99e109fa12c36a125af360f62ee471ec49da0c2aaa4d57590dcd2957cb3531ab4ebb25bf197ca8e3ccd85b679c140e0dcecb5b38b96324d
|
7
|
+
data.tar.gz: 7327cef609f7617f99196d2ef8dd2f98190e7eaf90dc7af0305b5eb4062bc3c8887b5653ce13be427602b9665671745c788a57fa8fa4b1775253b4784ed7bbee
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
# [v0.13.0] - 29-08-2024
|
2
|
+
## What's Changed
|
3
|
+
* Add theme support by @gjtorikian in https://github.com/gjtorikian/tailwind_merge/pull/32
|
4
|
+
|
5
|
+
|
6
|
+
**Full Changelog**: https://github.com/gjtorikian/tailwind_merge/compare/v0.12.2...v0.13.0
|
7
|
+
# [v0.12.2] - 18-08-2024
|
8
|
+
## What's Changed
|
9
|
+
* remove spurious debug statement by @gjtorikian in https://github.com/gjtorikian/tailwind_merge/pull/28
|
10
|
+
* Port over latest updates + bugfixes by @gjtorikian in https://github.com/gjtorikian/tailwind_merge/pull/29
|
11
|
+
|
12
|
+
|
13
|
+
**Full Changelog**: https://github.com/gjtorikian/tailwind_merge/compare/v0.12.0...v0.12.2
|
14
|
+
## [v0.12.0] - 25-04-2024
|
15
|
+
## What's Changed
|
16
|
+
* Add support for mix-blend-plus-darker utility by @gjtorikian in https://github.com/gjtorikian/tailwind_merge/pull/27
|
17
|
+
|
18
|
+
|
19
|
+
**Full Changelog**: https://github.com/gjtorikian/tailwind_merge/compare/v0.11.0...v0.12.0
|
1
20
|
## [v0.11.0] - 26-03-2024
|
2
21
|
## What's Changed
|
3
22
|
* Support accepting an array of strings by @gjtorikian in https://github.com/gjtorikian/tailwind_merge/pull/26
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Utility function to efficiently merge [Tailwind CSS](https://tailwindcss.com/) classes without style conflicts. Essentially, a Ruby port of [tailwind-merge](https://github.com/dcastil/tailwind-merge).
|
4
4
|
|
5
|
-
Supports Tailwind v3.0 up to v3.
|
5
|
+
Supports Tailwind v3.0 up to v3.4.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -310,7 +310,18 @@ In the Tailwind config you can modify theme scales. `tailwind_merge` follows the
|
|
310
310
|
- `space`
|
311
311
|
- `translate`
|
312
312
|
|
313
|
-
If you modified one of these theme scales in your Tailwind config, you can add all your keys right here and tailwind-merge will take care of the rest.
|
313
|
+
If you modified one of these theme scales in your Tailwind config, you can add all your keys right here and tailwind-merge will take care of the rest. For example, to add custom spaces and margin, you would provide the following `theme`:
|
314
|
+
|
315
|
+
```ruby
|
316
|
+
merger = TailwindMerge::Merger.new(config: {
|
317
|
+
theme: {
|
318
|
+
"spacing" => ["my-space"],
|
319
|
+
"margin" => ["my-margin"],
|
320
|
+
},
|
321
|
+
})
|
322
|
+
```
|
323
|
+
|
324
|
+
If you modified other theme scales, you need to figure out the class group to modify in the [default config](#getdefaultconfig).
|
314
325
|
|
315
326
|
### Validators
|
316
327
|
|
@@ -4,8 +4,8 @@ module TailwindMerge
|
|
4
4
|
module Config
|
5
5
|
include Validators
|
6
6
|
|
7
|
-
FROM_THEME = ->(config,
|
8
|
-
config
|
7
|
+
FROM_THEME = ->(config, key) {
|
8
|
+
config[:theme].fetch(key, nil)
|
9
9
|
}
|
10
10
|
|
11
11
|
COLORS = ->(config) { FROM_THEME.call(config, "colors") }
|
@@ -105,7 +105,6 @@ module TailwindMerge
|
|
105
105
|
ALIGN = -> { ["start", "end", "center", "between", "around", "evenly", "stretch"] }
|
106
106
|
ZERO_AND_EMPTY = -> { ["", "0", IS_ARBITRARY_VALUE] }
|
107
107
|
BREAKS = -> { ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"] }
|
108
|
-
NUMBER = -> { [IS_NUMBER, IS_ARBITRARY_NUMBER] }
|
109
108
|
NUMBER_AND_ARBITRARY = -> { [IS_NUMBER, IS_ARBITRARY_VALUE] }
|
110
109
|
|
111
110
|
DEFAULTS = {
|
@@ -115,12 +114,12 @@ module TailwindMerge
|
|
115
114
|
"colors" => [IS_ANY],
|
116
115
|
"spacing" => [IS_LENGTH, IS_ARBITRARY_LENGTH],
|
117
116
|
"blur" => ["none", "", IS_TSHIRT_SIZE, IS_ARBITRARY_VALUE],
|
118
|
-
"brightness" =>
|
117
|
+
"brightness" => NUMBER_AND_ARBITRARY.call,
|
119
118
|
"border-color" => [COLORS],
|
120
119
|
"border-radius" => ["none", "", "full", IS_TSHIRT_SIZE, IS_ARBITRARY_VALUE],
|
121
120
|
"border-spacing" => SPACING_WITH_ARBITRARY.call,
|
122
121
|
"border-width" => LENGTH_WITH_EMPTY_AND_ARBITRARY.call,
|
123
|
-
"contrast" =>
|
122
|
+
"contrast" => NUMBER_AND_ARBITRARY.call,
|
124
123
|
"grayscale" => ZERO_AND_EMPTY.call,
|
125
124
|
"hue-rotate" => NUMBER_AND_ARBITRARY.call,
|
126
125
|
"invert" => ZERO_AND_EMPTY.call,
|
@@ -129,10 +128,10 @@ module TailwindMerge
|
|
129
128
|
"gradient-color-stop-positions" => [IS_PERCENT, IS_ARBITRARY_LENGTH],
|
130
129
|
"inset" => SPACING_WITH_AUTO_AND_ARBITRARY.call,
|
131
130
|
"margin" => SPACING_WITH_AUTO_AND_ARBITRARY.call,
|
132
|
-
"opacity" =>
|
131
|
+
"opacity" => NUMBER_AND_ARBITRARY.call,
|
133
132
|
"padding" => SPACING_WITH_ARBITRARY.call,
|
134
|
-
"saturate" =>
|
135
|
-
"scale" =>
|
133
|
+
"saturate" => NUMBER_AND_ARBITRARY.call,
|
134
|
+
"scale" => NUMBER_AND_ARBITRARY.call,
|
136
135
|
"sepia" => ZERO_AND_EMPTY.call,
|
137
136
|
"skew" => NUMBER_AND_ARBITRARY.call,
|
138
137
|
"space" => SPACING_WITH_ARBITRARY.call,
|
@@ -1841,10 +1840,13 @@ module TailwindMerge
|
|
1841
1840
|
def merge_configs(extension_config)
|
1842
1841
|
config = TailwindMerge::Config::DEFAULTS
|
1843
1842
|
[:theme].each do |type|
|
1844
|
-
extension_config.fetch(type, {}).each_pair do |key,
|
1845
|
-
config[type][
|
1843
|
+
extension_config.fetch(type, {}).each_pair do |key, scales|
|
1844
|
+
config[type][key] << ->(klass) {
|
1845
|
+
scales.include?(klass)
|
1846
|
+
}
|
1846
1847
|
end
|
1847
1848
|
end
|
1849
|
+
|
1848
1850
|
config
|
1849
1851
|
end
|
1850
1852
|
end
|
data/lib/tailwind_merge.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
if ENV.fetch("DEBUG", false)
|
4
|
-
require "amazing_print"
|
5
4
|
require "debug"
|
5
|
+
begin
|
6
|
+
require "amazing_print"
|
7
|
+
rescue LoadError # rubocop:disable Lint/SuppressedException
|
8
|
+
end
|
6
9
|
end
|
7
10
|
|
8
11
|
require "lru_redux"
|
@@ -44,15 +47,24 @@ module TailwindMerge
|
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
47
|
-
private def merge_class_list(
|
50
|
+
private def merge_class_list(class_list)
|
48
51
|
# Set of class_group_ids in following format:
|
49
52
|
# `{importantModifier}{variantModifiers}{classGroupId}`
|
50
53
|
# @example 'float'
|
51
54
|
# @example 'hover:focus:bg-color'
|
52
55
|
# @example 'md:!pr'
|
53
|
-
class_groups_in_conflict =
|
56
|
+
class_groups_in_conflict = []
|
57
|
+
class_names = class_list.strip.split(SPLIT_CLASSES_REGEX)
|
58
|
+
|
59
|
+
result = ""
|
60
|
+
|
61
|
+
i = class_names.length - 1
|
62
|
+
|
63
|
+
loop do
|
64
|
+
break if i < 0
|
65
|
+
|
66
|
+
original_class_name = class_names[i]
|
54
67
|
|
55
|
-
classes.strip.split(SPLIT_CLASSES_REGEX).map do |original_class_name|
|
56
68
|
modifiers, has_important_modifier, base_class_name, maybe_postfix_modifier_position = split_modifiers(original_class_name, separator: @config[:separator])
|
57
69
|
|
58
70
|
actual_base_class_name = maybe_postfix_modifier_position ? base_class_name[0...maybe_postfix_modifier_position] : base_class_name
|
@@ -60,61 +72,48 @@ module TailwindMerge
|
|
60
72
|
|
61
73
|
unless class_group_id
|
62
74
|
unless maybe_postfix_modifier_position
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
75
|
+
# not a Tailwind class
|
76
|
+
result = original_class_name + (!result.empty? ? " " + result : result)
|
77
|
+
i -= 1
|
78
|
+
next
|
67
79
|
end
|
68
80
|
|
69
81
|
class_group_id = @class_utils.class_group_id(base_class_name)
|
70
82
|
|
71
83
|
unless class_group_id
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
84
|
+
# not a Tailwind class
|
85
|
+
result = original_class_name + (!result.empty? ? " " + result : result)
|
86
|
+
i -= 1
|
87
|
+
next
|
77
88
|
end
|
78
89
|
|
79
90
|
has_postfix_modifier = false
|
80
|
-
|
81
|
-
next {
|
82
|
-
is_tailwind_class: false,
|
83
|
-
original_class_name: original_class_name,
|
84
|
-
}
|
85
91
|
end
|
86
92
|
|
87
93
|
variant_modifier = sort_modifiers(modifiers).join(":")
|
88
94
|
|
89
95
|
modifier_id = has_important_modifier ? "#{variant_modifier}#{IMPORTANT_MODIFIER}" : variant_modifier
|
90
|
-
|
91
|
-
{
|
92
|
-
is_tailwind_class: true,
|
93
|
-
modifier_id: modifier_id,
|
94
|
-
class_group_id: class_group_id,
|
95
|
-
original_class_name: original_class_name,
|
96
|
-
has_postfix_modifier: has_postfix_modifier,
|
97
|
-
}
|
98
|
-
end.reverse # Last class in conflict wins, so filter conflicting classes in reverse order.
|
99
|
-
.select do |parsed|
|
100
|
-
next(true) unless parsed[:is_tailwind_class]
|
101
|
-
|
102
|
-
modifier_id = parsed[:modifier_id]
|
103
|
-
class_group_id = parsed[:class_group_id]
|
104
|
-
has_postfix_modifier = parsed[:has_postfix_modifier]
|
105
|
-
|
106
96
|
class_id = "#{modifier_id}#{class_group_id}"
|
107
97
|
|
108
|
-
|
98
|
+
# Tailwind class omitted due to pre-existing conflict
|
99
|
+
if class_groups_in_conflict.include?(class_id)
|
100
|
+
i -= 1
|
101
|
+
next
|
102
|
+
end
|
109
103
|
|
110
|
-
class_groups_in_conflict.
|
104
|
+
class_groups_in_conflict.push(class_id)
|
111
105
|
|
112
106
|
@class_utils.get_conflicting_class_group_ids(class_group_id, has_postfix_modifier).each do |group|
|
113
|
-
class_groups_in_conflict.
|
107
|
+
class_groups_in_conflict.push("#{modifier_id}#{group}")
|
114
108
|
end
|
115
109
|
|
116
|
-
|
117
|
-
|
110
|
+
# no conflict!
|
111
|
+
result = original_class_name + (!result.empty? ? " " + result : result)
|
112
|
+
|
113
|
+
i -= 1
|
114
|
+
end
|
115
|
+
|
116
|
+
result
|
118
117
|
end
|
119
118
|
end
|
120
119
|
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.
|
4
|
+
version: 0.13.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: 2024-
|
11
|
+
date: 2024-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lru_redux
|