tailwind_merge 0.12.0 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +1 -1
- data/lib/tailwind_merge/config.rb +5 -6
- 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: 7bd029b3106698874b67142336e597f9369c92664531879ad22eedd0cba6645b
|
4
|
+
data.tar.gz: 5389d8adf19d10d5f4edd08bff8cfd94f23e8ce65f6893400b0a8416de629faa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2236d20be8ac16e9fb1ee61682c00d8cc00a8102a1f12ef6ab2d56bd9829a041feb08e5448ebcf09e7940a43b3d6ca512ce0f381bdd006275302167c245700b1
|
7
|
+
data.tar.gz: aa34f52e7f697c8b1c01d3bead20a4868393f054dfbf9dbb7595d842d3883c26c23e1039dc6b14cd309671b198f6751181465478f246f5b609acf628694de861
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
# [v0.12.2] - 18-08-2024
|
2
|
+
## What's Changed
|
3
|
+
* remove spurious debug statement by @gjtorikian in https://github.com/gjtorikian/tailwind_merge/pull/28
|
4
|
+
* Port over latest updates + bugfixes by @gjtorikian in https://github.com/gjtorikian/tailwind_merge/pull/29
|
5
|
+
|
6
|
+
|
7
|
+
**Full Changelog**: https://github.com/gjtorikian/tailwind_merge/compare/v0.12.0...v0.12.2
|
8
|
+
## [v0.12.0] - 25-04-2024
|
9
|
+
## What's Changed
|
10
|
+
* Add support for mix-blend-plus-darker utility by @gjtorikian in https://github.com/gjtorikian/tailwind_merge/pull/27
|
11
|
+
|
12
|
+
|
13
|
+
**Full Changelog**: https://github.com/gjtorikian/tailwind_merge/compare/v0.11.0...v0.12.0
|
1
14
|
## [v0.11.0] - 26-03-2024
|
2
15
|
## What's Changed
|
3
16
|
* 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
|
|
@@ -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,
|
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.12.
|
4
|
+
version: 0.12.2
|
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-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lru_redux
|