Debian Codegraph @

node/colorjs.io/src/get.js

raw
1 import ColorSpace from "./ColorSpace.js";
2 import getAll from "./getAll.js";
3 import getColor from "./getColor.js";
4
5 /** @import { ColorTypes, Ref } from "./types.js" */
6
7 /**
8 * @param {ColorTypes} color
9 * @param {Ref} prop
10 * @returns {number}
11 */
12 export default function get (color, prop) {
13 color = getColor(color);
14
15 if (prop === "alpha") {
16 return color.alpha ?? 1;
17 }
18
19 let { space, index } = ColorSpace.resolveCoord(prop, color.space);
20 let coords = getAll(color, space);
21 return coords[index];
22 }