tailwind_merge 0.7.4 → 0.8.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 +2 -0
 - data/Gemfile +0 -2
 - data/README.md +14 -8
 - data/lib/tailwind_merge/config.rb +1 -1
 - data/lib/tailwind_merge/validators.rb +14 -8
 - data/lib/tailwind_merge/version.rb +1 -1
 - metadata +3 -4
 - data/script/generate_changelog +0 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e5402fe57c8b5f28ac07847bc17a04c6b5cd1ba9ad62ce945920759a95aece31
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 0ef6aad523beb48f559b70e6e88662e0db9df8269152d2ccdcb5d08b5f96801b
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 568f47ffb9084553b5efc2b37dadcfdf1da552f698340f94bbbd6695618836213d4906b820370e55418350176d2d47c6f63dea5c5957efd34987b0a5ccb2cd4f
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: f4656fe96ddfed6d74308733575503b33a69cecd9ff261cded4e60978e7a9927652afbd09a2ad0b02ea8988c6540730bc63cbec1edb4f782b5e14d04d4cbebe7
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/Gemfile
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -34,15 +34,15 @@ If you use Tailwind with a component-based UI renderer (like [ViewComponent](htt 
     | 
|
| 
       34 
34 
     | 
    
         
             
            <%= render(ConfirmEmailComponent.new(class: "p-5")) %>
         
     | 
| 
       35 
35 
     | 
    
         
             
            ```
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
            When the `ConfirmEmailComponent` is rendered, an input with the className `border rounded px-2 py-1` gets created. But because of the way the [CSS cascade](https://developer.mozilla.org/en-US/docs/Web/CSS/Cascade) works, the styles of the `p-5` class are ignored. The order of the classes in the `class` string doesn't matter at all and the only way to apply the `p- 
     | 
| 
      
 37 
     | 
    
         
            +
            When the `ConfirmEmailComponent` is rendered, an input with the className `border rounded px-2 py-1` gets created. But because of the way the [CSS cascade](https://developer.mozilla.org/en-US/docs/Web/CSS/Cascade) works, the styles of the `p-5` class are ignored. The order of the classes in the `class` string doesn't matter at all and the only way to apply the `p-5` style is to remove both `px-2` and `py-1`.
         
     | 
| 
       38 
38 
     | 
    
         | 
| 
       39 
39 
     | 
    
         
             
            This is where `tailwind_merge` comes in:
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
            ```ruby
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
43 
     | 
    
         
             
            @merger = TailwindMerge::Merger.new
         
     | 
| 
       44 
     | 
    
         
            -
            @merger.merge("border rounded px-2 py-1  
     | 
| 
       45 
     | 
    
         
            -
            # border rounded p-5
         
     | 
| 
      
 44 
     | 
    
         
            +
            @merger.merge("border rounded px-2 py-1 p-5")
         
     | 
| 
      
 45 
     | 
    
         
            +
            # → "border rounded p-5"
         
     | 
| 
       46 
46 
     | 
    
         
             
            ```
         
     | 
| 
       47 
47 
     | 
    
         | 
| 
       48 
48 
     | 
    
         
             
            tailwind-merge overrides conflicting classes and keeps everything else untouched. In the case of the implementation of `ConfirmEmailComponent`, the input now only renders the classes `border rounded p-5`.
         
     | 
| 
         @@ -96,7 +96,7 @@ The order of standard modifiers does not matter for tailwind-merge. 
     | 
|
| 
       96 
96 
     | 
    
         
             
            >
         
     | 
| 
       97 
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 
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-[ 
     | 
| 
      
 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-[length:theme(myCustomScale.rebecca)]`.
         
     | 
| 
       100 
100 
     | 
    
         | 
| 
       101 
101 
     | 
    
         
             
            ### Supports arbitrary properties
         
     | 
| 
       102 
102 
     | 
    
         | 
| 
         @@ -159,9 +159,9 @@ merger = TailwindMerge::Merger.new 
     | 
|
| 
       159 
159 
     | 
    
         | 
| 
       160 
160 
     | 
    
         
             
            ### Usage with custom Tailwind config
         
     | 
| 
       161 
161 
     | 
    
         | 
| 
       162 
     | 
    
         
            -
            If you're using a custom Tailwind config, you may need to configure  
     | 
| 
      
 162 
     | 
    
         
            +
            If you're using a custom Tailwind config, you may need to configure `tailwind_merge` as well to merge classes properly.
         
     | 
| 
       163 
163 
     | 
    
         | 
| 
       164 
     | 
    
         
            -
            The default  
     | 
| 
      
 164 
     | 
    
         
            +
            The default `TailwindMerge::Merger` initializer is configured in a way that you can still use it if all the following points apply to your Tailwind config:
         
     | 
| 
       165 
165 
     | 
    
         | 
| 
       166 
166 
     | 
    
         
             
            - Only using color names which don't clash with other Tailwind class names
         
     | 
| 
       167 
167 
     | 
    
         
             
            - Only deviating by number values from number-based Tailwind classes
         
     | 
| 
         @@ -177,7 +177,7 @@ The `tailwind_merge` config is different from the Tailwind config because it's e 
     | 
|
| 
       177 
177 
     | 
    
         
             
            The `tailwind_merge` config is an object with several keys:
         
     | 
| 
       178 
178 
     | 
    
         | 
| 
       179 
179 
     | 
    
         
             
            ```ruby
         
     | 
| 
       180 
     | 
    
         
            -
             
     | 
| 
      
 180 
     | 
    
         
            +
            tailwind_merge_config = {
         
     | 
| 
       181 
181 
     | 
    
         
             
                # ↓ *Optional* Define how many values should be stored in cache.
         
     | 
| 
       182 
182 
     | 
    
         
             
                cache_size: 500,
         
     | 
| 
       183 
183 
     | 
    
         
             
                # ↓ *Optional* modifier separator from Tailwind config
         
     | 
| 
         @@ -197,6 +197,12 @@ tailwindMergeConfig = { 
     | 
|
| 
       197 
197 
     | 
    
         
             
            }
         
     | 
| 
       198 
198 
     | 
    
         
             
            ```
         
     | 
| 
       199 
199 
     | 
    
         | 
| 
      
 200 
     | 
    
         
            +
            To use the custom configuration, pass it to the `TailwindMerge::Merger` initializer:
         
     | 
| 
      
 201 
     | 
    
         
            +
             
     | 
| 
      
 202 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 203 
     | 
    
         
            +
            @merger = TailwindMerge::Merger.new(config: tailwind_merge_config)
         
     | 
| 
      
 204 
     | 
    
         
            +
            ```
         
     | 
| 
      
 205 
     | 
    
         
            +
             
     | 
| 
       200 
206 
     | 
    
         
             
            ### Class groups
         
     | 
| 
       201 
207 
     | 
    
         | 
| 
       202 
208 
     | 
    
         
             
            The library uses a concept of _class groups_ which is an array of Tailwind classes which all modify the same CSS property. For example, here is the position class group:
         
     | 
| 
         @@ -307,7 +313,7 @@ Here's a brief summary for each validator: 
     | 
|
| 
       307 
313 
     | 
    
         
             
            - `IS_TSHIRT_SIZE`checks whether class part is a T-shirt size (`sm`, `xl`), optionally with a preceding number (`2xl`).
         
     | 
| 
       308 
314 
     | 
    
         
             
            - `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.
         
     | 
| 
       309 
315 
     | 
    
         
             
            - `IS_ARBITRARY_POSITION` checks whether class part is an arbitrary value which starts with `position:` (`[position:200px_100px]`) which is necessary for background-position classNames.
         
     | 
| 
       310 
     | 
    
         
            -
            - ` 
     | 
| 
      
 316 
     | 
    
         
            +
            - `IS_ARBITRARY_IMAGE` checks whether class part is an arbitrary value which is an iamge, e.g. by starting with `image:`, `url:`, `linear-gradient(` or `url(` (`[url('/path-to-image.png')]`, `image:var(--maybe-an-image-at-runtime)]`) which is necessary for background-image classNames.
         
     | 
| 
       311 
317 
     | 
    
         
             
            - `IS_ARBITRARY_NUMBER` checks whether class part is an arbitrary value which starts with `number:` or is a number (`[number:var(--value)]`, `[450]`) which is necessary for font-weight classNames.
         
     | 
| 
       312 
318 
     | 
    
         
             
            - `IS_ARBITRARY_SHADOW` checks whether class part is an arbitrary value which starts with the same pattern as a shadow value (`[0_35px_60px_-15px_rgba(0,0,0,0.3)]`), namely with two lengths separated by a underscore.
         
     | 
| 
       313 
319 
     | 
    
         
             
            - `IS_ANY` always returns true. Be careful with this validator as it might match unwanted classes. I use it primarily to match colors or when it's certain there are no other class groups in a namespace.
         
     | 
| 
         @@ -9,7 +9,9 @@ module TailwindMerge 
     | 
|
| 
       9 
9 
     | 
    
         
             
                    match = ARBITRARY_VALUE_REGEX.match(class_part)
         
     | 
| 
       10 
10 
     | 
    
         
             
                    return false unless match
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
                     
     | 
| 
      
 12 
     | 
    
         
            +
                    unless match[1].nil?
         
     | 
| 
      
 13 
     | 
    
         
            +
                      return label.is_a?(Set) ? label.include?(match[1]) : label == match[1]
         
     | 
| 
      
 14 
     | 
    
         
            +
                    end
         
     | 
| 
       13 
15 
     | 
    
         | 
| 
       14 
16 
     | 
    
         
             
                    test_value.call(match[2])
         
     | 
| 
       15 
17 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -31,6 +33,10 @@ module TailwindMerge 
     | 
|
| 
       31 
33 
     | 
    
         
             
                TSHIRT_UNIT_REGEX = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/
         
     | 
| 
       32 
34 
     | 
    
         
             
                # Shadow always begins with x and y offset separated by underscore
         
     | 
| 
       33 
35 
     | 
    
         
             
                SHADOW_REGEX = /^-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/
         
     | 
| 
      
 36 
     | 
    
         
            +
                IMAGE_REGEX = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                SIZE_LABELS = Set.new(["length", "size", "percentage"]).freeze
         
     | 
| 
      
 39 
     | 
    
         
            +
                IMAGE_LABELS = Set.new(["image", "url"]).freeze
         
     | 
| 
       34 
40 
     | 
    
         | 
| 
       35 
41 
     | 
    
         
             
                is_length_only = ->(value) {
         
     | 
| 
       36 
42 
     | 
    
         
             
                  LENGTH_UNIT_REGEX.match?(value)
         
     | 
| 
         @@ -38,10 +44,6 @@ module TailwindMerge 
     | 
|
| 
       38 
44 
     | 
    
         | 
| 
       39 
45 
     | 
    
         
             
                is_never = ->(_) { false }
         
     | 
| 
       40 
46 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
                is_url = ->(value) {
         
     | 
| 
       42 
     | 
    
         
            -
                  value.start_with?("url(")
         
     | 
| 
       43 
     | 
    
         
            -
                }
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
47 
     | 
    
         
             
                is_number = ->(value) {
         
     | 
| 
       46 
48 
     | 
    
         
             
                  numeric?(value)
         
     | 
| 
       47 
49 
     | 
    
         
             
                }
         
     | 
| 
         @@ -54,6 +56,10 @@ module TailwindMerge 
     | 
|
| 
       54 
56 
     | 
    
         
             
                  SHADOW_REGEX.match?(value)
         
     | 
| 
       55 
57 
     | 
    
         
             
                }
         
     | 
| 
       56 
58 
     | 
    
         | 
| 
      
 59 
     | 
    
         
            +
                is_image = ->(value) {
         
     | 
| 
      
 60 
     | 
    
         
            +
                  IMAGE_REGEX.match?(value)
         
     | 
| 
      
 61 
     | 
    
         
            +
                }
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
       57 
63 
     | 
    
         
             
                IS_LENGTH = ->(value) {
         
     | 
| 
       58 
64 
     | 
    
         
             
                  numeric?(value) ||
         
     | 
| 
       59 
65 
     | 
    
         
             
                    STRING_LENGTHS.include?(value) ||
         
     | 
| 
         @@ -66,15 +72,15 @@ module TailwindMerge 
     | 
|
| 
       66 
72 
     | 
    
         
             
                }
         
     | 
| 
       67 
73 
     | 
    
         | 
| 
       68 
74 
     | 
    
         
             
                IS_ARBITRARY_SIZE = ->(value) {
         
     | 
| 
       69 
     | 
    
         
            -
                  arbitrary_value?(value,  
     | 
| 
      
 75 
     | 
    
         
            +
                  arbitrary_value?(value, SIZE_LABELS, is_never)
         
     | 
| 
       70 
76 
     | 
    
         
             
                }
         
     | 
| 
       71 
77 
     | 
    
         | 
| 
       72 
78 
     | 
    
         
             
                IS_ARBITRARY_POSITION = ->(value) {
         
     | 
| 
       73 
79 
     | 
    
         
             
                  arbitrary_value?(value, "position", is_never)
         
     | 
| 
       74 
80 
     | 
    
         
             
                }
         
     | 
| 
       75 
81 
     | 
    
         | 
| 
       76 
     | 
    
         
            -
                 
     | 
| 
       77 
     | 
    
         
            -
                  arbitrary_value?(value,  
     | 
| 
      
 82 
     | 
    
         
            +
                IS_ARBITRARY_IMAGE = ->(value) {
         
     | 
| 
      
 83 
     | 
    
         
            +
                  arbitrary_value?(value, IMAGE_LABELS, is_image)
         
     | 
| 
       78 
84 
     | 
    
         
             
                }
         
     | 
| 
       79 
85 
     | 
    
         | 
| 
       80 
86 
     | 
    
         
             
                IS_ARBITRARY_NUMBER = ->(value) {
         
     | 
    
        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.8.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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2023-09-19 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: lru_redux
         
     | 
| 
         @@ -73,7 +73,6 @@ files: 
     | 
|
| 
       73 
73 
     | 
    
         
             
            - lib/tailwind_merge/modifier_utils.rb
         
     | 
| 
       74 
74 
     | 
    
         
             
            - lib/tailwind_merge/validators.rb
         
     | 
| 
       75 
75 
     | 
    
         
             
            - lib/tailwind_merge/version.rb
         
     | 
| 
       76 
     | 
    
         
            -
            - script/generate_changelog
         
     | 
| 
       77 
76 
     | 
    
         
             
            - tailwind_merge.gemspec
         
     | 
| 
       78 
77 
     | 
    
         
             
            homepage: https://www.github.com/gjtorikian/tailwind_merge
         
     | 
| 
       79 
78 
     | 
    
         
             
            licenses:
         
     | 
| 
         @@ -100,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       100 
99 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       101 
100 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       102 
101 
     | 
    
         
             
            requirements: []
         
     | 
| 
       103 
     | 
    
         
            -
            rubygems_version: 3.4. 
     | 
| 
      
 102 
     | 
    
         
            +
            rubygems_version: 3.4.19
         
     | 
| 
       104 
103 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       105 
104 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       106 
105 
     | 
    
         
             
            summary: Utility function to efficiently merge Tailwind CSS classes without style
         
     | 
    
        data/script/generate_changelog
    DELETED