| 1 |
import ColorSpace from "./ColorSpace.js"; |
| 2 |
import set from "./set.js"; |
| 3 |
|
| 4 |
/** @import { ColorTypes, PlainColorObject, Ref } from "./types.js" */ |
| 5 |
|
| 6 |
/** |
| 7 |
* @param {ColorTypes} color |
| 8 |
* @param {number} amount |
| 9 |
* @returns {PlainColorObject} |
| 10 |
*/ |
| 11 |
export function lighten (color, amount = 0.25) { |
| 12 |
let space = ColorSpace.get("oklch", "lch"); |
| 13 |
let /** @type {Ref} */ lightness = [space, "l"]; |
| 14 |
return set(color, lightness, l => l * (1 + amount)); |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* @param {ColorTypes} color |
| 19 |
* @param {number} amount |
| 20 |
* @returns {PlainColorObject} |
| 21 |
*/ |
| 22 |
export function darken (color, amount = 0.25) { |
| 23 |
let space = ColorSpace.get("oklch", "lch"); |
| 24 |
let /** @type {Ref} */ lightness = [space, "l"]; |
| 25 |
return set(color, lightness, l => l * (1 - amount)); |
| 26 |
} |
| 27 |
|
| 28 |
/** @type {"color"} */ |
| 29 |
lighten.returns = "color"; |
| 30 |
|
| 31 |
/** @type {"color"} */ |
| 32 |
darken.returns = "color"; |