/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{cssToRgba as t,cssHexToRgba as r,parseRgba as s,sanitizeRgbComponent as i,sanitizeAlpha as h}from"./colorUtils.js";import{isArrayWithReadonly as e}from"./core/arrayUtils.js";import{clamp as o}from"./core/mathUtils.js";import{ensureInteger as n}from"./core/accessorSupport/ensureType.js";function a(t){return o(n(t),0,255)}function u(t,r){const s=t.toString(16).padStart(2,"0");return r?s.slice(0,1):s}class g{static blendColors(t,r,s,i=new g){return i.r=Math.round(t.r+(r.r-t.r)*s),i.g=Math.round(t.g+(r.g-t.g)*s),i.b=Math.round(t.b+(r.b-t.b)*s),i.a=t.a+(r.a-t.a)*s,i._sanitize()}static fromRgb(r,s){const i=t(r);return i?g.fromArray(i,s):null}static fromHex(t,s=new g){const i=r(t);return i?g.fromArray(i,s):null}static fromArray(t,r=new g){return r._set(Number(t[0]),Number(t[1]),Number(t[2]),Number(t[3])),isNaN(r.a)&&(r.a=1),r._sanitize()}static fromString(t,r){const i=s(t);return i?g.fromArray(i,r):null}static fromJSON(t){return null!=t?new g([t[0],t[1],t[2],(t[3]??255)/255]):void 0}toUnitRGB(){return[this.r/255,this.g/255,this.b/255]}toUnitRGBA(t){return t??=[0,0,0,0],t[0]=this.r/255,t[1]=this.g/255,t[2]=this.b/255,t[3]=null!=this.a?this.a:1,t}constructor(t){this.r=255,this.g=255,this.b=255,this.a=1,t&&this.setColor(t)}get isBright(){return.299*this.r+.587*this.g+.114*this.b>=127}setColor(t){if("string"==typeof t)g.fromString(t,this);else if(e(t))g.fromArray(t,this);else{const r=t;this._set(r.r??0,r.g??0,r.b??0,r.a??1),t instanceof g||this._sanitize()}return this}toRgb(){return[this.r,this.g,this.b]}toRgba(){return[this.r,this.g,this.b,this.a]}toHex(t){const r=t?.capitalize??!1,s=t?.digits??6,i=3===s||4===s,h=4===s||8===s,e=`#${u(this.r,i)}${u(this.g,i)}${u(this.b,i)}${h?u(Math.round(255*this.a),i):""}`;return r?e.toUpperCase():e}toCss(t=!1){const r=this.r+", "+this.g+", "+this.b;return t?`rgba(${r}, ${this.a})`:`rgb(${r})`}toString(){return this.toCss(!0)}toJSON(){return this.toArray()}toArray(t=0){const r=a(this.r),s=a(this.g),i=a(this.b);return 0===t||1!==this.a?[r,s,i,a(255*this.a)]:[r,s,i]}clone(){return new g(this.toRgba())}hash(){return this.r<<24|this.g<<16|this.b<<8|255*this.a}equals(t){return null!=t&&t.r===this.r&&t.g===this.g&&t.b===this.b&&t.a===this.a}_sanitize(){return this.r=i(this.r),this.g=i(this.g),this.b=i(this.b),this.a=h(this.a),this}_set(t,r,s,i){this.r=t,this.g=r,this.b=s,this.a=i}}g.prototype.declaredClass="esri.Color";export{g as default};
