Debian Codegraph @

node/colorjs.io/src/luminance.js

raw
1 /**
2 * Relative luminance
3 */
4 import get from "./get.js";
5 import set from "./set.js";
6 import xyz_d65 from "./spaces/xyz-d65.js";
7
8 /** @import { ColorTypes } from "./types.js" */
9
10 /**
11 *
12 * @param {ColorTypes} color
13 * @returns {number}
14 */
15 export function getLuminance (color) {
16 // Assume getColor() is called on color in get()
17 return get(color, [xyz_d65, "y"]);
18 }
19
20 /**
21 * @param {ColorTypes} color
22 * @param {number | ((coord: number) => number)} value
23 */
24 export function setLuminance (color, value) {
25 // Assume getColor() is called on color in set()
26 set(color, [xyz_d65, "y"], value);
27 }
28
29 /**
30 * @param {typeof import("./color.js").default} Color
31 */
32 export function register (Color) {
33 Object.defineProperty(Color.prototype, "luminance", {
34 get () {
35 return getLuminance(this);
36 },
37 set (value) {
38 setLuminance(this, value);
39 },
40 });
41 }