/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import n from"../Color.js";import{shuffle as t,getRandomNumberGenerator as r}from"./arrayUtils.js";import{clone as o}from"./lang.js";import{clamp as e}from"./mathUtils.js";import{equals as u}from"./libs/gl-matrix-2/math/vec4.js";import{fromValues as c}from"./libs/gl-matrix-2/factories/vec4f64.js";function i(n){return"r"in n&&"g"in n&&"b"in n}function a(n){return"h"in n&&"s"in n&&"v"in n}function s(n){return"l"in n&&"a"in n&&"b"in n}function f(n){return"l"in n&&"c"in n&&"h"in n}function l(n){return"x"in n&&"y"in n&&"z"in n}const h=[[.4124,.3576,.1805],[.2126,.7152,.0722],[.0193,.1192,.9505]],g=[[3.2406,-1.5372,-.4986],[-.9689,1.8758,.0415],[.0557,-.204,1.057]];function b(n,t){const r=[];let o,e;if(n[0].length!==t.length)throw new Error("dimensions do not match");const u=n.length,c=n[0].length;let i=0;for(o=0;o<u;o++){for(i=0,e=0;e<c;e++)i+=n[o][e]*t[e];r.push(i)}return r}function m(n){const t=[n.r/255,n.g/255,n.b/255].map(n=>n<=.04045?n/12.92:((n+.055)/1.055)**2.4),r=b(h,t);return{x:100*r[0],y:100*r[1],z:100*r[2]}}function M(n){const t=b(g,[n.x/100,n.y/100,n.z/100]).map(n=>{const t=n<=.0031308?12.92*n:1.055*n**(1/2.4)-.055;return Math.min(1,Math.max(t,0))});return{r:Math.round(255*t[0]),g:Math.round(255*t[1]),b:Math.round(255*t[2])}}function d(n){const t=[n.x/95.047,n.y/100,n.z/108.883].map(n=>n>(6/29)**3?n**(1/3):1/3*(29/6)**2*n+4/29);return{l:116*t[1]-16,a:500*(t[0]-t[1]),b:200*(t[1]-t[2])}}function p(n){const t=n.l,r=[(t+16)/116+n.a/500,(t+16)/116,(t+16)/116-n.b/200].map(n=>n>6/29?n**3:3*(6/29)**2*(n-4/29));return{x:95.047*r[0],y:100*r[1],z:108.883*r[2]}}function x(n){const t=n.l,r=n.a,o=n.b,e=Math.sqrt(r*r+o*o);let u=Math.atan2(o,r);return u=u>0?u:u+2*Math.PI,{l:t,c:e,h:u}}function w(n){const t=n.l,r=n.c,o=n.h;return{l:t,a:r*Math.cos(o),b:r*Math.sin(o)}}function k(n){return d(m(n))}function y(n){return M(p(n))}function j(n){return x(d(m(n)))}function v(n){return M(p(w(n)))}function z(n){const t=n.r,r=n.g,o=n.b,e=Math.max(t,r,o),u=e-Math.min(t,r,o);let c=e,i=0===u?0:e===t?(r-o)/u%6:e===r?(o-t)/u+2:(t-r)/u+4,a=0===u?0:u/c;return i<0&&(i+=6),i*=60,a*=100,c*=100/255,{h:i,s:a,v:c}}function A(n){const t=(n.h+360)%360/60,r=n.s/100,o=n.v/100*255,e=o*r,u=e*(1-Math.abs(t%2-1));let c;switch(Math.floor(t)){case 0:c={r:e,g:u,b:0};break;case 1:c={r:u,g:e,b:0};break;case 2:c={r:0,g:e,b:u};break;case 3:c={r:0,g:u,b:e};break;case 4:c={r:u,g:0,b:e};break;case 5:case 6:c={r:e,g:0,b:u};break;default:c={r:0,g:0,b:0}}return c.r=Math.round(c.r+o-e),c.g=Math.round(c.g+o-e),c.b=Math.round(c.b+o-e),c}function C(n){return i(n)?n:f(n)?v(n):s(n)?y(n):l(n)?M(n):a(n)?A(n):n}function U(n){if(a(n))return n;return z(C(n))}function q(n){return s(n)?n:k(C(n))}function B(n){return f(n)?n:j(C(n))}function E(n){return G(n).isBright?"light":"dark"}function G(t){let{r,g:o,b:e,a:u}=t;return u<1&&(r=Math.round(u*r+255*(1-u)),o=Math.round(u*o+255*(1-u)),e=Math.round(u*e+255*(1-u))),new n({r,g:o,b:e})}function I(n,t){const{r,g:o,b:e}=t?.ignoreAlpha?n:G(n);return.2126*r+.7152*o+.0722*e}function P(t,r=225){return I(t,{ignoreAlpha:!0})>r?new n([0,0,0,t.a]):new n([255,255,255,t.a])}function R(n,t){const r=q(n);r.l*=1-t;const o=C(r),e=n.clone();return e.setColor(o),e.a=n.a,e}function D(n,t){const r=n.clone();return r.a*=t,r}function F(n,t){const r=U(n);r.s*=t;const o=C(r),e=n.clone();return e.setColor(o),e.a=n.a,e}function H(n,t){return n===t||null!=n&&n.equals(t)}function J(n,t){return n===t||null!=n&&null!=t&&u(n,t)}function K(n){return c(n[0],n[1],n[2],n.length>3?n[3]:1)}function L(n){return n[0]??=0,n[1]??=0,n[2]??=0,n}function N(n){return n.length=4,L(n),n[3]??=1,e(n[3],0,1),n}function O(n,t){const r=n.toUnitRGBA();return r[3]*=t,r}function Q(r,e,u={}){if(0===r.length||e<=0)return[];if(1===(r=r.map(t=>"string"==typeof t?new n(t):t)).length||1===e){const n=[],t=r[0];for(let r=0;r<e;r++)n.push(t.clone());return n}if(u.shuffle&&(r=t(o(r),u.seed)),r.length>=e){const n=[],t=(r.length-1)/(e-1);for(let o=0;o<e;o++){const e=Math.round(o*t);n.push(r[e].clone())}return n}return S(r,e,u)}function S(n,r,o={}){const e=[],u=n.length-1,c=Math.ceil((r-n.length)/u);n:for(let t=0;t<u;t++){const u=n[t],i=n[t+1];for(let t=1;t<=c;t++){const a=t/(c+1);if(e.push(V(u,i,a,o)),e.length+n.length===r)break n}}return[...n.map(n=>n.clone()),...t(e,o.seed??1)]}const T=(n,t)=>{const r=Math.floor(10*t())-5;return Math.min(255,Math.max(0,n+r))};function V(t,o,e,u={}){const c=t.r,i=t.g,a=t.b,s=o.r,f=o.g,l=o.b,h=Math.round(c+(s-c)*e),g=Math.round(i+(f-i)*e),b=Math.round(a+(l-a)*e);if(!u.offset)return new n([h,g,b]);const m=r(u.seed);return new n([T(h,m),T(g,m),T(b,m)])}export{H as colorEquals,J as colorVectorEquals,K as colorVectorToColorAndOpacity,Q as createUniqueColors,R as darken,F as desaturate,I as getColorLuminance,E as getColorTheme,P as getContrast,i as isRGB,D as multiplyOpacity,O as multiplyOpacityToUnitRGBA,U as toHSV,q as toLAB,B as toLCH,C as toRGB,L as validateColor,N as validateColorAndOpacity};
