Debian Codegraph @

node/colorjs.io/src/deltaE.js

raw
1 import defaults from "./defaults.js";
2 import { isString } from "./util.js";
3 import deltaEMethods from "./deltaE/index.js";
4
5 /** @import { ColorTypes } from "./types.js" */
6
7 // Type re-exports
8 /** @typedef {import("./types.js").Methods} Methods */
9
10 /**
11 *
12 * @param {ColorTypes} c1
13 * @param {ColorTypes} c2
14 * @param {Methods | ({ method?: Methods | undefined } & Record<string, any>)} [o]
15 * deltaE method to use as well as any other options to pass to the deltaE function
16 * @returns {number}
17 * @throws {TypeError} Unknown or unspecified method
18 */
19 export default function deltaE (c1, c2, o = {}) {
20 if (isString(o)) {
21 o = { method: o };
22 }
23
24 let { method = defaults.deltaE, ...rest } = o;
25
26 for (let m in deltaEMethods) {
27 if ("deltae" + method.toLowerCase() === m.toLowerCase()) {
28 return deltaEMethods[m](c1, c2, rest);
29 }
30 }
31
32 throw new TypeError(`Unknown deltaE method: ${method}`);
33 }