UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) • 5.23 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ 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{e as u}from"../chunks/vec42.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 h(n){return"x"in n&&"y"in n&&"z"in n}const l=[[.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(l,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 w(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 x(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 w(d(m(n)))}function v(n){return M(p(x(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 U(n){return i(n)?n:f(n)?v(n):s(n)?y(n):h(n)?M(n):a(n)?A(n):n}function B(n){if(a(n))return n;return z(U(n))}function C(n){return s(n)?n:k(U(n))}function H(n){return f(n)?n:j(U(n))}function q(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 L(n,t){const{r,g:o,b:e}=t?.ignoreAlpha?n:G(n);return.2126*r+.7152*o+.0722*e}var R;function E(t,r=R.High){return L(t,{ignoreAlpha:!0})>r?new n([0,0,0,t.a]):new n([255,255,255,t.a])}function I(n,t){const r=C(n);r.l*=1-t;const o=U(r),e=n.clone();return e.setColor(o),e.a=n.a,e}function P(n,t){const r=n.clone();return r.a*=t,r}function D(n,t){const r=B(n);r.s*=t;const o=U(r),e=n.clone();return e.setColor(o),e.a=n.a,e}function F(t){return n.toUnitRGBA(t)}function J(n,t){return n===t||null!=n&&n.equals(t)}function K(n,t){return n===t||null!=n&&null!=t&&u(n,t)}function N(n){return c(n[0],n[1],n[2],n.length>3?n[3]:1)}function O(n){return n[0]??=0,n[1]??=0,n[2]??=0,n}function Q(n){return n.length=4,O(n),n[3]??=1,e(n[3],0,1),n}function S(t,r){const o=n.toUnitRGBA(t);return o[3]*=r,o}function T(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 V(r,e,u)}function V(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(X(u,i,a,o)),e.length+n.length===r)break n}}return[...n.map((n=>n.clone())),...t(e,o.seed??1)]}!function(n){n[n.Low=160]="Low",n[n.High=225]="High"}(R||(R={}));const W=(n,t)=>{const r=Math.floor(10*t())-5;return Math.min(255,Math.max(0,n+r))};function X(t,o,e,u={}){const c=t.r,i=t.g,a=t.b,s=o.r,f=o.g,h=o.b,l=Math.round(c+(s-c)*e),g=Math.round(i+(f-i)*e),b=Math.round(a+(h-a)*e);if(!u.offset)return new n([l,g,b]);const m=r(u.seed);return new n([W(l,m),W(g,m),W(b,m)])}export{R as BrightnessThreshold,J as colorEquals,K as colorVectorEquals,N as colorVectorToColorAndOpacity,T as createUniqueColors,I as darken,D as desaturate,L as getColorLuminance,q as getColorTheme,E as getContrast,i as isRGB,P as multiplyOpacity,S as multiplyOpacityToUnitRGBA,B as toHSV,C as toLAB,H as toLCH,U as toRGB,F as unitRGBAFromColor,O as validateColor,Q as validateColorAndOpacity};