| 81 | |
| 82 | const cssColorRegEx = /\s*((?:rgb|rgba|hsl|hsla|hsv|hsva)\([^\(\)]*\))/gy; |
| 83 | export function parseCssColor(text: string, start = 0): Parsed<Color> { |
| 84 | cssColorRegEx.lastIndex = start; |
| 85 | const result = cssColorRegEx.exec(text); |
| 86 | if (!result) { |
| 87 | return null; |
| 88 | } |
| 89 | const end = cssColorRegEx.lastIndex; |
| 90 | try { |
| 91 | return { start, end, value: new Color(result[1]) }; |
| 92 | } catch { |
| 93 | return null; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | export function convertHSLToRGBColor(hue: number, saturation: number, lightness: number): { r: number; g: number; b: number } { |
| 98 | // Per formula it will be easier if hue is divided to 60° and saturation to 100 beforehand |