Skip to content

Commit

Permalink
fix stroke color being incorrectly detected as stroke width
Browse files Browse the repository at this point in the history
  • Loading branch information
dcastil committed Jan 22, 2024
1 parent 71f28c3 commit 1ca9250
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const stringLengths = new Set(['px', 'full', 'screen'])
const tshirtUnitRegex = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/
const lengthUnitRegex =
/\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$/
const colorFunctionRegex = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/
// Shadow always begins with x and y offset separated by underscore
const shadowRegex = /^-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/
const imageRegex =
Expand Down Expand Up @@ -84,7 +85,10 @@ function getIsArbitraryValue(
}

function isLengthOnly(value: string) {
return lengthUnitRegex.test(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.
return lengthUnitRegex.test(value) && !colorFunctionRegex.test(value)
}

function isNever() {
Expand Down

0 comments on commit 1ca9250

Please sign in to comment.