Skip to content

Commit

Permalink
fix: support for more than one digit after . for hsl colors in parseT…
Browse files Browse the repository at this point in the history
…oRgb

> both S and L parts are <percentage>  values see 
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/hsl#s


> The <percentage> data type consists of a <number> followed by the percentage sign (%). 
https://developer.mozilla.org/en-US/docs/Web/CSS/percentage


>The syntax of <number> extends the syntax of <integer>. A fractional value is represented by a . followed by one or more decimal digits, and may be appended to an integer
https://developer.mozilla.org/en-US/docs/Web/CSS/number
  • Loading branch information
safareli authored Nov 27, 2024
1 parent a7e3dee commit 3041310
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/color/parseToRgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const reducedHexRegex = /^#[a-fA-F0-9]{3}$/
const reducedRgbaHexRegex = /^#[a-fA-F0-9]{4}$/
const rgbRegex = /^rgb\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*\)$/i
const rgbaRegex = /^rgb(?:a)?\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i
const hslRegex = /^hsl\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*\)$/i
const hslaRegex = /^hsl(?:a)?\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i
const hslRegex = /^hsl\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]+)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]+)%\s*\)$/i
const hslaRegex = /^hsl(?:a)?\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]+)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]+)%\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i

/**
* Returns an RgbColor or RgbaColor object. This utility function is only useful
Expand Down

0 comments on commit 3041310

Please sign in to comment.