YUI.add("aui-hsva-palette",function(e,t){var n=e.Lang,r=e.Color,i=e.Do,s=e.Widget,t="hsva-palette",o=e.getClassName,u=".",a="",f="#",l=" ",c="backgroundColor",h="HSVA",p="RGBA",d="contentBox",v="controls",m="ff0000ff",g="rgb(255, 0, 0, 0)",y="hsThumbChange",b="hsvaInputChange",w="length",E="offsetHeight",S="opacity",x="Hex",T="0",N="railMouseDown",C="rgbInputChange",k="slideStart",L="strings",A="to",O="value",M="valueChange",_=0,D=255,P=360,H=100,B=100,j=8,F="fffff",I="ff",q="-hex",R="-a",U="alpha",z="hex",W=o("hsv-container-alpha"),X=o("hsv-alpha-canvas"),V=o("hsv-alpha-slider-container"),$=o("hsv-alpha-thumb"),J=o("hsv-alpha-image"),K=/^([a-f0-9]{6}|[a-f0-9]{8}|[a-f0-9]{3})$/i,Q=e.Base.create(t,e.HSVPalette,[],{TPL_ALPHA_CANVAS:'<span class="'+X+'"></span>',TPL_ALPHA_SLIDER_CONTAINER:'<div class="'+V+'"><div>',TPL_ALPHA_THUMB:'<span class="'+$+'"><span class="'+J+'"></span></span>',initializer:function(){var e=this;e.set("fieldValidator.hex",K),e.after(y,e._afterHsThumbChangeFn,e),e.after(b,e._afterHSVAInputChange,e),e.after(C,e._afterRGBInputChange,e)},_afterHexInputChange:function(e){var t=this,n=e.hexColor,r=n.substr(6,2),i=parseInt(r,16);t._alphaSlider.set(O,D-i,{src:s.UI_SRC}),t._alphaSliderContainer.setStyle(c,n),t._resultView.setStyle(S,i/D),t.get(v)&&t._setFieldValue(t._aContainer,i)},_afterHsThumbChangeFn:function(e){var t=this;t._alphaSliderContainer.setStyle(c,e.hexColor)},_afterHSVAInputChange:function(e){var t=this,n=t._getFieldValue(t._aContainer);t._alphaSlider.set(O,D-n,{src:s.UI_SRC}),t._alphaSliderContainer.setStyle(c,e.hexColor),t._resultView.setStyle(S,n/D)},_afterRGBInputChange:function(e){var t=this;t._alphaSliderContainer.setStyle(c,e.hexColor)},_calculateRGBArray:function(e,t,n){var i=this,s;return s=255-i._alphaSlider.get(O),r.fromArray([e,t,n,s],p)},_calculateRGBColor:function(e,t,n){var r=this,i=255-r._alphaSlider.get(O);return r._calculateRGBA(e,t,n,i)},_calculateRGBA:function(e,t,i,s){var o=g,u,a;if(e!==P||n.toInt(t)!==H||n.toInt(i)!==B)u="hsva("+(e===P?P-1:e)+", "+t+"%, "+i+"%, "+s+")",o=r.toRGBA(u),n.toInt(s)===0&&(a=r.toArray(o),a[3]=T,o=r.fromArray(a,p));return o},_convertColor:function(e,t,n){var i=this,s,o;return o=n===z,t===z&&(e=f+e),o?n=x:n=(n+"a").toUpperCase(),s=r[A+n](e),o&&(s=s.substr(1)),s},_getContainerClassName:function(){var t=this,n;return n=e.HSVAPalette.superclass._getContainerClassName.call(t),n+=l+W,n},_getHexValue:function(e,t){var n,r;return n=parseInt(t[3],10).toString(16),n.length===1&&(n=T+n),r=e+n,r.substring(1)},_getHSVArray:function(e){var t=this;return r.toArray(e,h)},_createAlphaSlider:function(){var t=this,n,r,i;r=t.get(d),i=new e.Slider({axis:"y",min:_,max:D}),i.RAIL_TEMPLATE=t.TPL_ALPHA_CANVAS,i.THUMB_TEMPLATE=t.TPL_ALPHA_THUMB,i.render(t._alphaSliderContainer),n=r.one(u+J).get(E),i.set(w,t._alphaSliderContainer.get(E)+n/2),i.on([k,N],t._setHSContainerXY,t),i.on(M,t._onAlphaChange,t),t._alphaSlider=i},_createSliders:function(){var t=this;e.HSVAPalette.superclass._createSliders.call(t),t._createAlphaSlider()},_getHexContainerConfig:function(){var e=this;return{label:e.get(L).hex,maxlength:j,suffix:q,type:z,unit:a,value:m}},_normalizeHexValue:function(e){var t="";return e.length===3?t=F:e.length===6&&(t=I),e+=t},_onAlphaChange:function(e){var t=this,n,i,o,u,a,f,l,c,h,p;e.src!==s.UI_SRC&&(n=e.newVal,t._resultView.setStyle(S,1-n/D),i=t._colorThumb.getXY(),o=i[0]-t._hsContainerXY[0]+t._colorThumbGutter,u=i[1]-t._hsContainerXY[1]+t._colorThumbGutter,a=t._calculateHue(o),f=t._calculateSaturation(u),l=B-t._valueSlider.get(O),c=t._calculateRGBA(a,f,l,D-n),h=r.toArray(c),p=t._getHexValue(r.toHex(c),h),t._setFieldValue(t._outputContainer,p),t.get(v)&&(t._setFieldValue(t._aContainer,D-n),t._setFieldValue(t._rContainer,h[0]),t._setFieldValue(t._gContainer,h[1]),t._setFieldValue(t._bContainer,h[2])))},_renderAlphaSliderContainer:function(){var e=this;e._alphaSliderContainer=e._viewContainer.appendChild(e.TPL_ALPHA_SLIDER_CONTAINER)},_renderFields:function(){var t=this;e.HSVAPalette.superclass._renderFields.call(t),t._aContainer=t._renderField(t._labelValueHSVContainer,{label:t.get(L).a,maxlength:3,suffix:R,type:U,unit:a,value:D})},_renderViewContainerContent:function(){var t=this;e.HSVAPalette.superclass._renderViewContainerContent.call(t),t._renderAlphaSliderContainer()}},{NAME:t,NS:t});e.HSVAPalette=Q},"2.0.0",{requires:["aui-hsv-palette"],skinnable:!0});
