/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["./chunks/_rollupPluginBabelHelpers","./colorUtils","./core/mathUtils","./core/maybe","./core/accessorSupport/ensureType"],(function(t,r,n,s,i){"use strict";function e(t){return n.clamp(i.ensureInteger(t),0,255)}function o(t,r,n){return t=Number(t),isNaN(t)?n:t<r?r:t>n?n:t}let a=function(){function n(t){this.r=255,this.g=255,this.b=255,this.a=1,t&&this.setColor(t)}n.blendColors=function(t,r,s,i=new n){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()},n.fromRgb=function(t,s){const i=t.toLowerCase().match(/^(rgba?|hsla?)\(([\s\.\-,%0-9]+)\)/);if(i){const t=i[2].split(/\s*,\s*/),e=i[1];if("rgb"===e&&3===t.length||"rgba"===e&&4===t.length){const r=t[0];if("%"===r.charAt(r.length-1)){const r=t.map((t=>2.56*parseFloat(t)));return 4===t.length&&(r[3]=parseFloat(t[3])),n.fromArray(r,s)}return n.fromArray(t.map((t=>parseFloat(t))),s)}if("hsl"===e&&3===t.length||"hsla"===e&&4===t.length)return n.fromArray(r.hsla2rgba(parseFloat(t[0]),parseFloat(t[1])/100,parseFloat(t[2])/100,parseFloat(t[3])),s)}return null},n.fromHex=function(t,r=new n){if(4!==t.length&&7!==t.length||"#"!==t[0])return null;const s=4===t.length?4:8,i=(1<<s)-1;let e=Number("0x"+t.substr(1));return isNaN(e)?null:(["b","g","r"].forEach((t=>{const n=e&i;e>>=s,r[t]=4===s?17*n:n})),r.a=1,r)},n.fromArray=function(t,r=new n){return r._set(Number(t[0]),Number(t[1]),Number(t[2]),Number(t[3])),isNaN(r.a)&&(r.a=1),r._sanitize()},n.fromString=function(t,s){const i=r.isNamedColor(t)?r.getNamedColor(t):null;return i&&n.fromArray(i,s)||n.fromRgb(t,s)||n.fromHex(t,s)},n.fromJSON=function(t){return t&&new n([t[0],t[1],t[2],t[3]/255])},n.toUnitRGB=function(t){return s.isSome(t)?[t.r/255,t.g/255,t.b/255]:null},n.toUnitRGBA=function(t){return s.isSome(t)?[t.r/255,t.g/255,t.b/255,null!=t.a?t.a:1]:null};var i=n.prototype;return i.setColor=function(t){if("string"==typeof t)n.fromString(t,this);else if(Array.isArray(t))n.fromArray(t,this);else{var r,s,i,e;this._set(null!=(r=t.r)?r:0,null!=(s=t.g)?s:0,null!=(i=t.b)?i:0,null!=(e=t.a)?e:1),t instanceof n||this._sanitize()}return this},i.toRgb=function(){return[this.r,this.g,this.b]},i.toRgba=function(){return[this.r,this.g,this.b,this.a]},i.toHex=function(){const t=this.r.toString(16),r=this.g.toString(16),n=this.b.toString(16);return`#${t.length<2?"0"+t:t}${r.length<2?"0"+r:r}${n.length<2?"0"+n:n}`},i.toCss=function(t=!1){const r=this.r+", "+this.g+", "+this.b;return t?`rgba(${r}, ${this.a})`:`rgb(${r})`},i.toString=function(){return this.toCss(!0)},i.toJSON=function(){return this.toArray()},i.toArray=function(t=n.AlphaMode.ALWAYS){const r=e(this.r),s=e(this.g),i=e(this.b);return t===n.AlphaMode.ALWAYS||1!==this.a?[r,s,i,e(255*this.a)]:[r,s,i]},i.clone=function(){return new n(this.toRgba())},i.hash=function(){return this.r<<24|this.g<<16|this.b<<8|255*this.a},i.equals=function(t){return s.isSome(t)&&t.r===this.r&&t.g===this.g&&t.b===this.b&&t.a===this.a},i._sanitize=function(){return this.r=Math.round(o(this.r,0,255)),this.g=Math.round(o(this.g,0,255)),this.b=Math.round(o(this.b,0,255)),this.a=o(this.a,0,1),this},i._set=function(t,r,n,s){this.r=t,this.g=r,this.b=n,this.a=s},t._createClass(n,[{key:"isBright",get:function(){return.299*this.r+.587*this.g+.114*this.b>=127}}]),n}();a.prototype.declaredClass="esri.Color",function(t){var r;(r=t.AlphaMode||(t.AlphaMode={}))[r.ALWAYS=0]="ALWAYS",r[r.UNLESS_OPAQUE=1]="UNLESS_OPAQUE"}(a||(a={}));return a}));
