| 162 | } |
| 163 | |
| 164 | static #hslToColor(hDeg, s, l, a) { |
| 165 | const h = (((hDeg % 360) + 360) % 360) / 360 |
| 166 | if (s === 0) { |
| 167 | const v = Math.round(l * 255) |
| 168 | return new Color(v, v, v, a) |
| 169 | } |
| 170 | const luminocity2 = l < 0.5 ? l * (1 + s) : l + s - l * s |
| 171 | const luminocity1 = 2 * l - luminocity2 |
| 172 | const hueToRgb = (l1, l2, hue) => { |
| 173 | if (hue < 0) hue += 1 |
| 174 | if (hue > 1) hue -= 1 |
| 175 | if (hue < 1 / 6) return l1 + (l2 - l1) * 6 * hue |
| 176 | if (hue < 1 / 2) return l2 |
| 177 | if (hue < 2 / 3) return l1 + (l2 - l1) * (2 / 3 - hue) * 6 |
| 178 | return l1 |
| 179 | } |
| 180 | const r = Math.round(hueToRgb(luminocity1, luminocity2, h + 1 / 3) * 255) |
| 181 | const g = Math.round(hueToRgb(luminocity1, luminocity2, h) * 255) |
| 182 | const b = Math.round(hueToRgb(luminocity1, luminocity2, h - 1 / 3) * 255) |
| 183 | return new Color(r, g, b, a) |
| 184 | } |
| 185 | |
| 186 | static #fromNamed(v) { |
| 187 | const name = String(v).trim().toLowerCase() |