From 3041310d2ea58056a191f887f8a6f8df1b727828 Mon Sep 17 00:00:00 2001 From: Irakli Safareli Date: Wed, 27 Nov 2024 18:11:06 +0400 Subject: [PATCH] fix: support for more than one digit after . for hsl colors in parseToRgb > both S and L parts are values see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/hsl#s > The data type consists of a followed by the percentage sign (%). https://developer.mozilla.org/en-US/docs/Web/CSS/percentage >The syntax of extends the syntax of . 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 --- src/color/parseToRgb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/color/parseToRgb.js b/src/color/parseToRgb.js index a7c91fa4..395a50dd 100644 --- a/src/color/parseToRgb.js +++ b/src/color/parseToRgb.js @@ -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