import type { FnN3 , FnU4 } from "@thi.ng/api" ; import { DEFAULT , defmulti } from "@thi.ng/defmulti/defmulti" ; import { mix as $mix } from "@thi.ng/math/mix" ; import { fract } from "@thi.ng/math/prec" ; import { mixN4 } from "@thi.ng/vectors/mixn" ; import { setC4 } from "@thi.ng/vectors/setc" ; import type { Color , ColorMixFn , TypedColor } from "./api.js" ; import { __dispatch1 } from "./internal/dispatch.js" ; /**
 * HOF color mix function. Takes 4 scalar mix fns (one per color channel) and
 * returns new  ColorMixFn .
 *
 *  param x param y param z param alpha export const defMix = ( x , y , z , alpha ) => ( out , a , b , t ) => setC4 ( out || a , x ( a [ 0 ] , b [ 0 ] , t ) , y ( a [ 1 ] , b [ 1 ] , t ) , z ( a [ 2 ] , b [ 2 ] , t ) , alpha ( a [ 3 ] , b [ 3 ] , t ) ) ; param a param b param t export const mixH = ( a , b , t ) => { a = fract ( a ) ; b = fract ( b ) ; const delta = b - a ; return fract ( a + ( Math . abs ( delta ) > 0.5 ? delta < 0 ? delta + 1 : - ( 1 - delta ) : delta ) * t ) ; } ; param a param b param t export const mixN = $mix ; export const mixHNNN = defMix ( mixH , mixN , mixN , mixN ) ; export const mixNNHN = defMix ( mixN , mixN , mixH , mixN ) ; param out param a param b param t export const mixNNNN = mixN4 ; /**
 * Channelwise and  ColorMode -aware interpolation between colors `a` and
 * `b` using `t` [0..1] as blend factor. `a` and `b` need to be of same color
 * type.
 *
 *  remarks Any hue channel will always be interpolated using the smallest angle
 * difference (using  mixH ).
 *
 * The  {@link @thi.ng/math#} package provides various easing functions to create
 * non-linear interpolations. For example:
 *
 *  example param out param a param b param t export const mix = defmulti < Color | null , TypedColor < any > , TypedColor < any > , number , Color > ( __dispatch1 , { } , { hcy : mixHNNN , hsi : mixHNNN , hsl : mixHNNN , hsv : mixHNNN , lch : mixNNHN , [ DEFAULT ] : mixN4 , } ) ;