From c5c3dd52cc1096b70fdfb95913b4446e1a16a3ca Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Thu, 9 Feb 2023 14:31:59 +0100 Subject: [PATCH] feat(color): add hue() function --- packages/color/src/hue.ts | 25 +++++++++++++++++++++++++ packages/color/src/index.ts | 1 + 2 files changed, 26 insertions(+) create mode 100644 packages/color/src/hue.ts diff --git a/packages/color/src/hue.ts b/packages/color/src/hue.ts new file mode 100644 index 0000000000..83b5a8a545 --- /dev/null +++ b/packages/color/src/hue.ts @@ -0,0 +1,25 @@ +import { DEFAULT, defmulti } from "@thi.ng/defmulti/defmulti"; +import type { TypedColor } from "./api.js"; +import { hsv } from "./hsv/hsv.js"; +import { __dispatch0 } from "./internal/dispatch.js"; + +/** + * Returns the (normalized) hue of given color. + * + * @remarks + * Since LCH uses different hue values than the more familiar HSV/HSL color + * wheel, LCH colors will be first converted to HSV to ensure uniform results. + */ +export const hue = defmulti, number>( + __dispatch0, + { + hcy: "hsv", + hsi: "hsv", + hsl: "hsv", + }, + { + [DEFAULT]: (col: TypedColor) => hsv(col)[0], + + hsv: (col) => col[0], + } +); diff --git a/packages/color/src/index.ts b/packages/color/src/index.ts index 7f68c373ed..3f96ea54ff 100644 --- a/packages/color/src/index.ts +++ b/packages/color/src/index.ts @@ -58,6 +58,7 @@ export * from "./color-range.js"; export * from "./cosine-gradients.js"; export * from "./distance.js"; export * from "./gradients.js"; +export * from "./hue.js"; export * from "./invert.js"; export * from "./is-black.js"; export * from "./is-gamut.js";