| 1 |
import ColorSpace from "./ColorSpace.js"; |
| 2 |
import getColor from "./getColor.js"; |
| 3 |
|
| 4 |
/** @import { ColorTypes } from "./types.js" */ |
| 5 |
|
| 6 |
const ε = 0.000075; |
| 7 |
|
| 8 |
/** |
| 9 |
* Check if a color is in gamut of either its own or another color space |
| 10 |
* @param {ColorTypes} color |
| 11 |
* @param {string | ColorSpace} [space] |
| 12 |
* @param {{ epsilon?: number | undefined }} [param2] |
| 13 |
* @returns {boolean} |
| 14 |
*/ |
| 15 |
export default function inGamut (color, space, { epsilon = ε } = {}) { |
| 16 |
color = getColor(color); |
| 17 |
|
| 18 |
if (!space) { |
| 19 |
space = color.space; |
| 20 |
} |
| 21 |
|
| 22 |
space = ColorSpace.get(space); |
| 23 |
let coords = color.coords; |
| 24 |
|
| 25 |
if (space !== color.space) { |
| 26 |
coords = space.from(color); |
| 27 |
} |
| 28 |
|
| 29 |
return space.inGamut(coords, { epsilon }); |
| 30 |
} |