Skip to content

Commit

Permalink
use inGamut culori func
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDroomer committed Aug 6, 2024
1 parent 7c103fb commit 7b1282a
Showing 1 changed file with 4 additions and 38 deletions.
42 changes: 4 additions & 38 deletions lib/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
type Color,
formatCss,
formatRgb as formatRgbFast,
inGamut,
type Lch,
type Lrgb,
modeHsl,
Expand Down Expand Up @@ -41,44 +42,9 @@ export let lab = useMode(modeLab)
export let lrgb = useMode(modeLrgb)
export let p3 = useMode(modeP3)

const GAMUT_MIN = -GAMUT_EPSILON
const GAMUT_MAX = 1 + GAMUT_EPSILON

export function inRGB(color: Color): boolean {
let { b, g, r } = rgb(color)
return (
r >= GAMUT_MIN &&
r <= GAMUT_MAX &&
g >= GAMUT_MIN &&
g <= GAMUT_MAX &&
b >= GAMUT_MIN &&
b <= GAMUT_MAX
)
}

export function inP3(color: Color): boolean {
let { b, g, r } = p3(color)
return (
r >= GAMUT_MIN &&
r <= GAMUT_MAX &&
g >= GAMUT_MIN &&
g <= GAMUT_MAX &&
b >= GAMUT_MIN &&
b <= GAMUT_MAX
)
}

export function inRec2020(color: Color): boolean {
let { b, g, r } = rec2020(color)
return (
r >= GAMUT_MIN &&
r <= GAMUT_MAX &&
g >= GAMUT_MIN &&
g <= GAMUT_MAX &&
b >= GAMUT_MIN &&
b <= GAMUT_MAX
)
}
export const inRGB = inGamut('rgb')
export const inP3 = inGamut('p3')
export const inRec2020 = inGamut('rec2020')

export function build(l: number, c: number, h: number, alpha = 1): AnyLch {
return { alpha, c, h, l, mode: COLOR_FN }
Expand Down

0 comments on commit 7b1282a

Please sign in to comment.