| 51 | const sat = clamp(s, 0, 100) / 100; |
| 52 | const light = clamp(l, 0, 100) / 100; |
| 53 | const q = light < 0.5 ? light * (1 + sat) : light + sat - light * sat; |
| 54 | const p = 2 * light - q; |
| 55 | const hueToRgb = (t: number) => { |
| 56 | let next = t; |
| 57 | if (next < 0) next += 1; |
| 58 | if (next > 1) next -= 1; |
| 59 | if (next < 1 / 6) return p + (q - p) * 6 * next; |
| 60 | if (next < 1 / 2) return q; |
| 61 | if (next < 2 / 3) return p + (q - p) * (2 / 3 - next) * 6; |
| 62 | return p; |
| 63 | }; |
| 64 | const toHex = (n: number) => Math.round(n * 255).toString(16).padStart(2, "0"); |