UNPKG

rybitten

Version:

A color space conversion library for transforming between RGB and RYB colors.

2 lines (1 loc) 1.22 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("./cubes.cjs"),p=n=>n*n*(3-2*n),l=(n,r,e)=>n+e*(r-n),i=(n,r,e,o,t,s)=>l(l(n,r,t),l(e,o,t),s),g=(n,r,e,o,t,s,a,h,f,T,R)=>l(i(n,r,e,o,f,T),i(t,s,a,h,f,T),R);function m(n,{cube:r=k.RYB_ITTEN,easingFn:e=p}={}){const o=e(n[0]),t=e(n[1]),s=e(n[2]);return[g(r[0][0],r[1][0],r[2][0],r[3][0],r[4][0],r[5][0],r[6][0],r[7][0],o,t,s),g(r[0][1],r[1][1],r[2][1],r[3][1],r[4][1],r[5][1],r[6][1],r[7][1],o,t,s),g(r[0][2],r[1][2],r[2][2],r[3][2],r[4][2],r[5][2],r[6][2],r[7][2],o,t,s)]}function S(n){return(n%360+360)%360}function y(n){let[r]=n;const[,e,o]=n;r=S(r||0);const t=o+e*(o<.5?o:1-o),s=t-(t-o)*2*Math.abs(r/60%2-1);let a;switch(Math.floor(r/60)){case 0:a=[t,s,2*o-t];break;case 1:a=[s,t,2*o-t];break;case 2:a=[2*o-t,t,s];break;case 3:a=[2*o-t,s,t];break;case 4:a=[s,2*o-t,t];break;case 5:a=[t,2*o-t,s];break;default:a=[2*o-t,2*o-t,2*o-t]}return a}function M(n,{cube:r=k.RYB_ITTEN,easingFn:e=p,invertLightness:o=!0}={}){const t=o?1-n[2]:n[2],s=y([n[0],n[1],t]);return m(s,{cube:r,easingFn:e})}exports.blerp=i;exports.easingSmoothstep=p;exports.hslToRgb=y;exports.lerp=l;exports.ryb2rgb=m;exports.rybHsl2rgb=M;exports.trilerp=g;