@thi.ng/color
Version:
Array-based color types, CSS parsing, conversions, transformations, declarative theme generation, gradients, presets
25 lines (24 loc) • 671 B
JavaScript
import { atan2Abs } from "@thi.ng/math/angle";
import { INV_TAU, TAU } from "@thi.ng/math/api";
import { setC4 } from "@thi.ng/vectors/setc";
import { __ensureAlpha } from "../internal/ensure.js";
const labLch = (out, src) => {
const { 1: a, 2: b } = src;
return setC4(
out || src,
src[0],
Math.hypot(a, b),
a === 0 && b === 0 ? 0 : atan2Abs(b, a) * INV_TAU,
__ensureAlpha(src[3])
);
};
const lchLab = (out, src) => {
let { 1: c, 2: h } = src;
h *= TAU;
const a = __ensureAlpha(src[3]);
return c > 0 ? setC4(out || src, src[0], Math.cos(h) * c, Math.sin(h) * c, a) : setC4(out || src, src[0], 0, 0, a);
};
export {
labLch,
lchLab
};