tailwind_merge 0.5.0 → 0.5.1

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: ab700417f6a4f25b6ca1f2dbc4fc88c8a4158107b3b446eb61c1806f9b017ed2
4
- data.tar.gz: 888edaa673497e967d596d387968bbc87af4aba71a9ee8bd1d3a2f0c16d1453d
3
+ metadata.gz: a91c2b0d982a08fffeb7f7a7de91124c386db75de621884d8dbe8370cba39943
4
+ data.tar.gz: 8f8ddc04bb758faf1f051ac90f3c5fb5020b1d54c1d87aedbfaf6c3eb6eb81f5
5
5
  SHA512:
6
- metadata.gz: d54fcc8481da5c205749eab9552be39ba2eb4f4c747d6d454d021c0d3ac71f3f4880541c9d5f559c7cb7759e0e653ee78a3e2a34458f4b9947ce5d4618d0d58e
7
- data.tar.gz: 355d00b020bd1db1345f15ce0833cf9af3baf3908b452355f4909dddd67e773ddbd861867ca60ebc9ef9dd59c10d744292ec39d1c7d69291ffbffd7acfe7cadb
6
+ metadata.gz: aec2902cd4796a3170b2806316cbbb8fb33f5d08a3bd8d9f34bbcdaec71b336ef9cd4c7404d8b307dd65c6db3501902bc17f65d651c0069cc08f44358fd92e7e
7
+ data.tar.gz: 8d8d0953a43e780061d462962cca27a4ade00fba4d19be6d23e299704173e3676db47c0cfb369c35dcd07a0f480a3a968916209a6f747609990d19042d2ba989
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.5.1](https://github.com/gjtorikian/tailwind_merge/tree/v0.5.1) (2023-02-05)
4
+
5
+ [Full Changelog](https://github.com/gjtorikian/tailwind_merge/compare/v0.5.0...v0.5.1)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Fix arbitrary value merging [\#7](https://github.com/gjtorikian/tailwind_merge/pull/7) ([gjtorikian](https://github.com/gjtorikian))
10
+
3
11
  ## [v0.5.0](https://github.com/gjtorikian/tailwind_merge/tree/v0.5.0) (2023-01-30)
4
12
 
5
13
  [Full Changelog](https://github.com/gjtorikian/tailwind_merge/compare/v0.4.1...v0.5.0)
@@ -64,7 +64,7 @@ module TailwindMerge
64
64
  OVERFLOW = -> { ["auto", "hidden", "clip", "visible", "scroll"] }
65
65
  SPACING_WITH_AUTO = -> { ["auto", SPACING] }
66
66
  LENGTH_WITH_EMPTY = -> { ["", IS_LENGTH] }
67
- INTEGER_WITH_AUTO = -> { ["auto", IS_INTEGER] }
67
+ NUMBER_WITH_AUTO_AND_ARBITRARY = -> { ["auto", IS_NUMBER, IS_ARBITRARY_VALUE] }
68
68
  POSITIONS = -> {
69
69
  [
70
70
  "bottom",
@@ -103,6 +103,8 @@ module TailwindMerge
103
103
  ALIGN = -> { ["start", "end", "center", "between", "around", "evenly"] }
104
104
  ZERO_AND_EMPTY = -> { ["", "0", IS_ARBITRARY_VALUE] }
105
105
  BREAKS = -> { ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"] }
106
+ NUMBER = -> { [IS_NUMBER, IS_ARBITRARY_NUMBER] }
107
+ NUMBER_AND_ARBITRARY = -> { [IS_NUMBER, IS_ARBITRARY_VALUE] }
106
108
 
107
109
  DEFAULTS = {
108
110
  cache_size: 500,
@@ -111,25 +113,25 @@ module TailwindMerge
111
113
  "colors" => [IS_ANY],
112
114
  "spacing" => [IS_LENGTH],
113
115
  "blur" => ["none", "", IS_TSHIRT_SIZE, IS_ARBITRARY_LENGTH],
114
- "brightness" => [IS_INTEGER],
116
+ "brightness" => NUMBER.call,
115
117
  "border-color" => [COLORS],
116
118
  "border-radius" => ["none", "", "full", IS_TSHIRT_SIZE, IS_ARBITRARY_LENGTH],
117
119
  "border-spacing" => [SPACING],
118
120
  "border-width" => LENGTH_WITH_EMPTY.call,
119
- "contrast" => [IS_INTEGER],
121
+ "contrast" => NUMBER.call,
120
122
  "grayscale" => ZERO_AND_EMPTY.call,
121
- "hue-rotate" => [IS_INTEGER],
123
+ "hue-rotate" => NUMBER_AND_ARBITRARY.call,
122
124
  "invert" => ZERO_AND_EMPTY.call,
123
125
  "gap" => [SPACING],
124
126
  "gradient-color-stops" => [COLORS],
125
127
  "inset" => SPACING_WITH_AUTO.call,
126
128
  "margin" => SPACING_WITH_AUTO.call,
127
- "opacity" => [IS_INTEGER],
129
+ "opacity" => NUMBER.call,
128
130
  "padding" => [SPACING],
129
- "saturate" => [IS_INTEGER],
130
- "scale" => [IS_INTEGER],
131
+ "saturate" => NUMBER.call,
132
+ "scale" => NUMBER.call,
131
133
  "sepia" => ZERO_AND_EMPTY.call,
132
- "skew" => [IS_INTEGER, IS_ARBITRARY_VALUE],
134
+ "skew" => NUMBER_AND_ARBITRARY.call,
133
135
  "space" => [SPACING],
134
136
  "translate" => [SPACING],
135
137
  },
@@ -306,7 +308,7 @@ module TailwindMerge
306
308
  # Z-Index
307
309
  # @see https://tailwindcss.com/docs/z-index
308
310
  ##
309
- "z" => [{ "z" => [IS_INTEGER] }],
311
+ "z" => [{ "z" => ["auto", IS_INTEGER] }],
310
312
  # Flexbox and Grid
311
313
  ##
312
314
  # Flex Basis
@@ -352,17 +354,17 @@ module TailwindMerge
352
354
  # Grid Column Start / End
353
355
  # @see https://tailwindcss.com/docs/grid-column
354
356
  ##
355
- "col-start-end" => [{ "col" => ["auto", { "span" => [IS_INTEGER] }] }],
357
+ "col-start-end" => [{ "col" => ["auto", { "span" => [IS_INTEGER, IS_ARBITRARY_VALUE] }] }],
356
358
  ##
357
359
  # Grid Column Start
358
360
  # @see https://tailwindcss.com/docs/grid-column
359
361
  ##
360
- "col-start" => [{ "col-start" => INTEGER_WITH_AUTO.call }],
362
+ "col-start" => [{ "col-start" => NUMBER_WITH_AUTO_AND_ARBITRARY.call }],
361
363
  ##
362
364
  # Grid Column End
363
365
  # @see https://tailwindcss.com/docs/grid-column
364
366
  ##
365
- "col-end" => [{ "col-end" => INTEGER_WITH_AUTO.call }],
367
+ "col-end" => [{ "col-end" => NUMBER_WITH_AUTO_AND_ARBITRARY.call }],
366
368
  ##
367
369
  # Grid Template Rows
368
370
  # @see https://tailwindcss.com/docs/grid-template-rows
@@ -377,12 +379,12 @@ module TailwindMerge
377
379
  # Grid Row Start
378
380
  # @see https://tailwindcss.com/docs/grid-row
379
381
  ##
380
- "row-start" => [{ "row-start" => INTEGER_WITH_AUTO.call }],
382
+ "row-start" => [{ "row-start" => NUMBER_WITH_AUTO_AND_ARBITRARY.call }],
381
383
  ##
382
384
  # Grid Row End
383
385
  # @see https://tailwindcss.com/docs/grid-row
384
386
  ##
385
- "row-end" => [{ "row-end" => INTEGER_WITH_AUTO.call }],
387
+ "row-end" => [{ "row-end" => NUMBER_WITH_AUTO_AND_ARBITRARY.call }],
386
388
  ##
387
389
  # Grid Auto Flow
388
390
  # @see https://tailwindcss.com/docs/grid-auto-flow
@@ -1259,7 +1261,7 @@ module TailwindMerge
1259
1261
  # Transition Duration
1260
1262
  # @see https://tailwindcss.com/docs/transition-duration
1261
1263
  ##
1262
- "duration" => [{ "duration" => [IS_INTEGER] }],
1264
+ "duration" => [{ "duration" => [NUMBER_AND_ARBITRARY] }],
1263
1265
  ##
1264
1266
  # Transition Timing Function
1265
1267
  # @see https://tailwindcss.com/docs/transition-timing-function
@@ -1269,7 +1271,7 @@ module TailwindMerge
1269
1271
  # Transition Delay
1270
1272
  # @see https://tailwindcss.com/docs/transition-delay
1271
1273
  ##
1272
- "delay" => [{ "delay" => [IS_INTEGER] }],
1274
+ "delay" => [{ "delay" => [NUMBER_AND_ARBITRARY] }],
1273
1275
  ##
1274
1276
  # Animation
1275
1277
  # @see https://tailwindcss.com/docs/animation
@@ -5,6 +5,15 @@ require "set"
5
5
  module TailwindMerge
6
6
  module Validators
7
7
  class << self
8
+ def arbitrary_value?(class_part, label, test_value)
9
+ match = ARBITRARY_VALUE_REGEX.match(class_part)
10
+ return false unless match
11
+
12
+ return match[1] == label if match[1]
13
+
14
+ test_value.call(match[2])
15
+ end
16
+
8
17
  def numeric?(x)
9
18
  Float(x, exception: false).is_a?(Numeric)
10
19
  end
@@ -16,84 +25,82 @@ module TailwindMerge
16
25
 
17
26
  STRING_LENGTHS = Set.new(["px", "full", "screen"]).freeze
18
27
 
19
- ARBITRARY_VALUE_REGEX = /^\[(.+)\]$/
28
+ ARBITRARY_VALUE_REGEX = /^\[(?:([a-z-]+):)?(.+)\]$/i
20
29
  FRACTION_REGEX = %r{^\d+/\d+$}
21
30
  LENGTH_UNIT_REGEX = /\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh)/
22
31
  TSHIRT_UNIT_REGEX = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/
23
32
  # Shadow always begins with x and y offset separated by underscore
24
33
  SHADOW_REGEX = /^-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/
25
34
 
26
- IS_ANY = ->(_) { return true }
27
-
28
- IS_LENGTH = ->(class_part) {
29
- numeric?(class_part) || \
30
- STRING_LENGTHS.include?(class_part) || \
31
- FRACTION_REGEX.match?(class_part) || \
32
- IS_ARBITRARY_LENGTH.call(class_part)
35
+ is_length_only = ->(value) {
36
+ LENGTH_UNIT_REGEX.match?(value)
33
37
  }
34
38
 
35
- IS_ARBITRARY_LENGTH = ->(class_part) {
36
- if (match = ARBITRARY_VALUE_REGEX.match(class_part))
37
- return match[1].start_with?("length:") || LENGTH_UNIT_REGEX.match?(class_part)
38
- end
39
+ is_never = ->(_) { false }
39
40
 
40
- false
41
+ is_url = ->(value) {
42
+ value.start_with?("url(")
41
43
  }
42
44
 
43
- IS_ARBITRARY_SIZE = ->(class_part) {
44
- if (match = ARBITRARY_VALUE_REGEX.match(class_part))
45
- return match[1].start_with?("size:")
46
- end
45
+ is_number = ->(value) {
46
+ numeric?(value)
47
+ }
47
48
 
48
- false
49
+ is_integer_only = ->(value) {
50
+ integer?(value)
49
51
  }
50
52
 
51
- IS_ARBITRARY_POSITION = ->(class_part) {
52
- if (match = ARBITRARY_VALUE_REGEX.match(class_part))
53
- return match[1].start_with?("position:")
54
- end
53
+ is_shadow = ->(value) {
54
+ SHADOW_REGEX.match?(value)
55
+ }
55
56
 
56
- false
57
+ IS_LENGTH = ->(value) {
58
+ numeric?(value) || \
59
+ STRING_LENGTHS.include?(value) || \
60
+ FRACTION_REGEX.match?(value) || \
61
+ IS_ARBITRARY_LENGTH.call(value)
57
62
  }
58
63
 
59
- IS_ARBITRARY_VALUE = ->(class_part) {
60
- ARBITRARY_VALUE_REGEX.match(class_part)
64
+ IS_ARBITRARY_LENGTH = ->(value) {
65
+ arbitrary_value?(value, "length", is_length_only)
61
66
  }
62
67
 
63
- IS_ARBITRARY_URL = ->(class_part) {
64
- if (match = ARBITRARY_VALUE_REGEX.match(class_part))
65
- return match[1].start_with?("url(", "url:")
66
- end
68
+ IS_ARBITRARY_SIZE = ->(value) {
69
+ arbitrary_value?(value, "size", is_never)
70
+ }
67
71
 
68
- false
72
+ IS_ARBITRARY_POSITION = ->(value) {
73
+ arbitrary_value?(value, "position", is_never)
69
74
  }
70
75
 
71
- IS_ARBITRARY_NUMBER = ->(class_part) {
72
- if (match = ARBITRARY_VALUE_REGEX.match(class_part))
73
- return match[1].start_with?("number:") || numeric?(match[1])
74
- end
76
+ IS_ARBITRARY_URL = ->(value) {
77
+ arbitrary_value?(value, "url", is_url)
78
+ }
75
79
 
76
- false
80
+ IS_ARBITRARY_NUMBER = ->(value) {
81
+ arbitrary_value?(value, "number", is_number)
77
82
  }
78
83
 
79
- IS_TSHIRT_SIZE = ->(class_part) {
80
- TSHIRT_UNIT_REGEX.match?(class_part)
84
+ IS_NUMBER = ->(value) {
85
+ is_number.call(value)
81
86
  }
82
87
 
83
- IS_INTEGER = ->(class_part) {
84
- if (match = ARBITRARY_VALUE_REGEX.match(class_part))
85
- return integer?(match[1])
86
- end
88
+ IS_INTEGER = ->(value) {
89
+ is_integer_only.call(value) || arbitrary_value?(value, "number", is_integer_only)
90
+ }
87
91
 
88
- integer?(class_part)
92
+ IS_ARBITRARY_VALUE = ->(value) {
93
+ ARBITRARY_VALUE_REGEX.match(value)
89
94
  }
90
95
 
91
- IS_ARBITRARY_SHADOW = ->(class_part) {
92
- if (match = ARBITRARY_VALUE_REGEX.match(class_part))
93
- return SHADOW_REGEX.match?(match[1])
94
- end
96
+ IS_ANY = ->(_) { return true }
97
+
98
+ IS_TSHIRT_SIZE = ->(value) {
99
+ TSHIRT_UNIT_REGEX.match?(value)
100
+ }
95
101
 
96
- return false
102
+ IS_ARBITRARY_SHADOW = ->(value) {
103
+ arbitrary_value?(value, "", is_shadow)
97
104
  }
98
105
  end
99
106
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TailwindMerge
4
- VERSION = "0.5.0"
4
+ VERSION = "0.5.1"
5
5
  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.5.0
4
+ version: 0.5.1
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-01-30 00:00:00.000000000 Z
11
+ date: 2023-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lru_redux