(level: number)
| 333 | const cast = 0.25 * (1 - chroma(bg)) ** 2 |
| 334 | |
| 335 | const gray = (level: number) => { |
| 336 | const factor = level / 12 |
| 337 | |
| 338 | if (isDark && lum < 10) { |
| 339 | const value = Math.floor(factor * 0.4 * 255) |
| 340 | return map(RGBA.fromInts(value, value, value)) |
| 341 | } |
| 342 | |
| 343 | if (!isDark && lum > 245) { |
| 344 | const value = Math.floor(255 - factor * 0.4 * 255) |
| 345 | return map(RGBA.fromInts(value, value, value)) |
| 346 | } |
| 347 | |
| 348 | const value = isDark ? lum + (255 - lum) * factor * 0.4 : lum * (1 - factor * 0.4) |
| 349 | const tone = RGBA.fromInts(Math.floor(value), Math.floor(value), Math.floor(value)) |
| 350 | if (cast === 0) return map(tone) |
| 351 | |
| 352 | const ratio = lum === 0 ? 0 : value / lum |
| 353 | return map( |
| 354 | tint( |
| 355 | tone, |
| 356 | RGBA.fromInts( |
| 357 | Math.floor(Math.max(0, Math.min(r * ratio, 255))), |
| 358 | Math.floor(Math.max(0, Math.min(g * ratio, 255))), |
| 359 | Math.floor(Math.max(0, Math.min(b * ratio, 255))), |
| 360 | ), |
| 361 | cast, |
| 362 | ), |
| 363 | ) |
| 364 | } |
| 365 | |
| 366 | return Object.fromEntries(Array.from({ length: 12 }, (_, index) => [index + 1, gray(index + 1)])) |
| 367 | } |
no test coverage detected