Skip to content

Commit

Permalink
feat(color): add hue() function
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Feb 9, 2023
1 parent 196b41f commit c5c3dd5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/color/src/hue.ts
Original file line number Diff line number Diff line change
@@ -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<TypedColor<any>, number>(
__dispatch0,
{
hcy: "hsv",
hsi: "hsv",
hsl: "hsv",
},
{
[DEFAULT]: (col: TypedColor<any>) => hsv(col)[0],

hsv: (col) => col[0],
}
);
1 change: 1 addition & 0 deletions packages/color/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit c5c3dd5

Please sign in to comment.