Skip to content

Commit

Permalink
Merge pull request #24 from gjtorikian/the-strokes
Browse files Browse the repository at this point in the history
Fix stroke-color being incorrectly detected as stroke-width
  • Loading branch information
gjtorikian authored Jan 30, 2024
2 parents df1eba3 + d8da95c commit 5773c8a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/tailwind_merge/validators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def integer?(x)
FRACTION_REGEX = %r{^\d+/\d+$}
LENGTH_UNIT_REGEX = /\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/
TSHIRT_UNIT_REGEX = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/
COLOR_FUNCTION_REGEX = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/
# Shadow always begins with x and y offset separated by underscore
SHADOW_REGEX = /^-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/
IMAGE_REGEX = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/
Expand All @@ -39,7 +40,10 @@ def integer?(x)
IMAGE_LABELS = Set.new(["image", "url"]).freeze

is_length_only = ->(value) {
LENGTH_UNIT_REGEX.match?(value)
# `colorFunctionRegex` check is necessary because color functions can have percentages in them which which would be incorrectly classified as lengths.
# For example, `hsl(0 0% 0%)` would be classified as a length without this check.
# I could also use lookbehind assertion in `lengthUnitRegex` but that isn't supported widely enough.
LENGTH_UNIT_REGEX.match?(value) && !COLOR_FUNCTION_REGEX.match?(value)
}

is_never = ->(_) { false }
Expand Down
2 changes: 1 addition & 1 deletion lib/tailwind_merge/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module TailwindMerge
VERSION = "0.10.0"
VERSION = "0.10.1"
end
1 change: 1 addition & 0 deletions test/test_colors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ def setup
def test_handles_color_conflicts_properly
assert_equal("bg-hotpink", @merger.merge("bg-grey-5 bg-hotpink"))
assert_equal("hover:bg-hotpink", @merger.merge("hover:bg-grey-5 hover:bg-hotpink"))
assert_equal("stroke-[hsl(350_80%_0%)] stroke-[10px]", @merger.merge("stroke-[hsl(350_80%_0%)] stroke-[10px]"))
end
end

0 comments on commit 5773c8a

Please sign in to comment.