1 line
22 KiB
JavaScript
1 line
22 KiB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Pickr=e():t.Pickr=e()}(window,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="dist/",n(n.s=7)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t};e.createElementFromString=s,e.removeAttribute=c,e.createFromTemplate=function(t){return function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=c(e,"data-con"),o=c(e,"data-key");o&&(n[o]=e);var i=Array.from(e.children),a=r?n[r]={}:n,s=!0,u=!1,l=void 0;try{for(var p,d=i[Symbol.iterator]();!(s=(p=d.next()).done);s=!0){var f=p.value,h=c(f,"data-arr");h?(a[h]||(a[h]=[])).push(f):t(f,a)}}catch(t){u=!0,l=t}finally{try{!s&&d.return&&d.return()}finally{if(u)throw l}}return n}(s(t))},e.eventPath=function(t){var e=t.path||t.composedPath&&t.composedPath();if(e)return e;var n=t.target.parentElement;for(e=[t.target,n];n=n.parentElement;)e.push(n);return e.push(document,window),e},e.adjustableInputNumbers=function(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=function(t){return t>="0"&&t<="9"||"-"===t||"."===t};function r(r){for(var o=t.value,i=t.selectionStart,a=i,s="",c=i-1;c>0&&n(o[c]);c--)s=o[c]+s,a--;for(var u=i,l=o.length;u<l&&n(o[u]);u++)s+=o[u];if(s.length>0&&!isNaN(s)&&isFinite(s)){var p=r.deltaY<0?1:-1,d=r.ctrlKey?5*p:p,f=Number(s)+d;!e&&f<0&&(f=0);var h=o.substr(0,a)+f+o.substring(a+s.length,o.length),v=a+String(f).length;t.value=h,t.focus(),t.setSelectionRange(v,v)}r.preventDefault(),t.dispatchEvent(new Event("input"))}o(t,"focus",function(){return o(window,"wheel",r)}),o(t,"blur",function(){return i(window,"wheel",r)})},e.once=function(t,e,n,r){return o(t,e,function t(){n.apply(this,arguments),this.removeEventListener(e,t)},r)};var o=e.on=a.bind(null,"addEventListener"),i=e.off=a.bind(null,"removeEventListener");function a(t,e,n,o){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};return e instanceof HTMLCollection||e instanceof NodeList?e=Array.from(e):Array.isArray(e)||(e=[e]),Array.isArray(n)||(n=[n]),e.forEach(function(e){return n.forEach(function(n){return e[t](n,o,r({capture:!1},i))})}),Array.prototype.slice.call(arguments,1)}function s(t){var e=document.createElement("div");return e.innerHTML=t.trim(),e.firstElementChild}function c(t,e){var n=t.getAttribute(e);return t.removeAttribute(e),n}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,e){var n=[],r=!0,o=!1,i=void 0;try{for(var a,s=t[Symbol.iterator]();!(r=(a=s.next()).done)&&(n.push(a.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{!r&&s.return&&s.return()}finally{if(o)throw i}}return n}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")};function o(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}e.hsvToRgb=s,e.hsvToHex=function(t,e,n){return s(t,e,n).map(function(t){return Math.round(t).toString(16).padStart(2,"0")})},e.hsvToCmyk=function(t,e,n){var r,o=s(t,e,n),a=o[0]/255,c=o[1]/255,u=o[2]/255;return[100*(1===(r=i(1-a,1-c,1-u))?0:(1-a-r)/(1-r)),100*(1===r?0:(1-c-r)/(1-r)),100*(1===r?0:(1-u-r)/(1-r)),100*r]},e.hsvToHsl=function(t,e,n){var r=(2-(e/=100))*(n/=100)/2;return 0!==r&&(e=1===r?0:r<.5?e*n/(2*r):e*n/(2-2*r)),[t,100*e,100*r]},e.parseToHSV=function(t){var e={cmyk:/^cmyk[\D]+(\d+)[\D]+(\d+)[\D]+(\d+)[\D]+(\d+)/i,rgba:/^(rgb|rgba)[\D]+(\d+)[\D]+(\d+)[\D]+(\d+)[\D]*?([\d.]+|$)/i,hsla:/^(hsl|hsla)[\D]+(\d+)[\D]+(\d+)[\D]+(\d+)[\D]*?([\d.]+|$)/i,hsva:/^(hsv|hsva)[\D]+(\d+)[\D]+(\d+)[\D]+(\d+)[\D]*?([\d.]+|$)/i,hex:/^#?(([\dA-Fa-f]{3,4})|([\dA-Fa-f]{6})|([\dA-Fa-f]{8}))$/i},n=function(t){return t.map(function(t){return/^(|\d+)\.\d+|\d+$/.test(t)?Number(t):void 0})},i=void 0;for(var a in e)if(i=e[a].exec(t))switch(a){case"cmyk":var s=n(i),d=r(s,5),f=d[1],h=d[2],v=d[3],y=d[4];return f>100||h>100||v>100||y>100?null:[].concat(o(u(f,h,v,y)),[1]);case"rgba":var g=n(i),m=r(g,6),b=m[2],_=m[3],k=m[4],w=m[5],A=void 0===w?1:w;return b>255||_>255||k>255||A<0||A>1?null:[].concat(o(c(b,_,k)),[A]);case"hex":var C=function(t,e){return[t.substring(0,e),t.substring(e,t.length)]},S=r(i,2)[1];3===S.length?S+="F":6===S.length&&(S+="FF");var O=void 0;if(4===S.length){var H=C(S,3).map(function(t){return t+t}),j=r(H,2);S=j[0],O=j[1]}else if(8===S.length){var x=C(S,6),P=r(x,2);S=P[0],O=P[1]}return O=parseInt(O,16)/255,[].concat(o(p(S)),[O]);case"hsla":var R=n(i),E=r(R,6),B=E[2],M=E[3],L=E[4],T=E[5],D=void 0===T?1:T;return B>360||M>100||L>100||D<0||D>1?null:[].concat(o(l(B,M,L)),[D]);case"hsva":var F=n(i),N=r(F,6),V=N[2],X=N[3],I=N[4],Y=N[5],z=void 0===Y?1:Y;return V>360||X>100||I>100||z<0||z>1?null:[V,X,I,z]}return null};var i=Math.min,a=Math.max;function s(t,e,n){t=t/360*6,e/=100,n/=100;var r=Math.floor(t),o=t-r,i=n*(1-e),a=n*(1-o*e),s=n*(1-(1-o)*e),c=r%6;return[255*[n,a,i,i,s,n][c],255*[s,n,n,a,i,i][c],255*[i,i,s,n,n,a][c]]}function c(t,e,n){var r,o=void 0,s=void 0,c=i(t/=255,e/=255,n/=255),u=a(t,e,n),l=u-c;if(r=u,0===l)o=s=0;else{s=l/u;var p=((u-t)/6+l/2)/l,d=((u-e)/6+l/2)/l,f=((u-n)/6+l/2)/l;t===u?o=f-d:e===u?o=1/3+p-f:n===u&&(o=2/3+d-p),o<0?o+=1:o>1&&(o-=1)}return[360*o,100*s,100*r]}function u(t,e,n,r){e/=100,n/=100;var a=255*(1-i(1,(t/=100)*(1-(r/=100))+r)),s=255*(1-i(1,e*(1-r)+r)),u=255*(1-i(1,n*(1-r)+r));return[].concat(o(c(a,s,u)))}function l(t,e,n){return e/=100,[t,2*(e*=(n/=100)<.5?n:1-n)/(n+e)*100,100*(n+e)]}function p(t){return c.apply(void 0,o(t.match(/.{2}/g).map(function(t){return parseInt(t,16)})))}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e={options:Object.assign({onchange:function(){return 0},className:"",elements:[]},t),_ontap:function(t){var n=e.options;n.elements.forEach(function(e){return e.classList[t.target===e?"add":"remove"](n.className)}),n.onchange(t)},destroy:function(){r.off(e.options.elements,"click",this._ontap)}};return r.on(e.options.elements,"click",e._ontap),e};var r=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(0))},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e={options:Object.assign({lockX:!1,lockY:!1,onchange:function(){return 0}},t),_tapstart:function(t){r.on(document,["mouseup","touchend","touchcancel"],e._tapstop),r.on(document,["mousemove","touchmove"],e._tapmove),t.preventDefault(),e.wrapperRect=e.options.wrapper.getBoundingClientRect(),e._tapmove(t)},_tapmove:function(t){var n=e.options,r=e.cache,o=n.element,i=e.wrapperRect,a=0,s=0;if(t){var c=t&&t.touches&&t.touches[0];a=t?(c||t).clientX:0,s=t?(c||t).clientY:0,a<i.left?a=i.left:a>i.left+i.width&&(a=i.left+i.width),s<i.top?s=i.top:s>i.top+i.height&&(s=i.top+i.height),a-=i.left,s-=i.top}else r&&(a=r.x,s=r.y);n.lockX||(o.style.left=a-o.offsetWidth/2+"px"),n.lockY||(o.style.top=s-o.offsetHeight/2+"px"),e.cache={x:a,y:s},n.onchange(a,s)},_tapstop:function(){r.off(document,["mouseup","touchend","touchcancel"],e._tapstop),r.off(document,["mousemove","touchmove"],e._tapmove)},trigger:function(){e.wrapperRect=e.options.wrapper.getBoundingClientRect(),e._tapmove()},update:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;e.wrapperRect=e.options.wrapper.getBoundingClientRect(),e._tapmove({clientX:e.wrapperRect.left+t,clientY:e.wrapperRect.top+n})},destroy:function(){var t=e.options,n=e._tapstart;r.off([t.wrapper,t.element],"mousedown",n),r.off([t.wrapper,t.element],"touchstart",n,{passive:!1})}};e.wrapperRect=e.options.wrapper.getBoundingClientRect();var n=e.options,o=e._tapstart;return r.on([n.wrapper,n.element],"mousedown",o),r.on([n.wrapper,n.element],"touchstart",o,{passive:!1}),e};var r=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(0))},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.HSVaColor=function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,a=Math.ceil,s={h:e,s:n,v:o,a:i,toHSVA:function(){var t=[s.h,s.s,s.v],e=t.map(a);return t.toString=function(){return"hsva("+e[0]+", "+e[1]+"%, "+e[2]+"%, "+s.a.toFixed(1)+")"},t},toHSLA:function(){var t=r.hsvToHsl(s.h,s.s,s.v),e=t.map(a);return t.toString=function(){return"hsla("+e[0]+", "+e[1]+"%, "+e[2]+"%, "+s.a.toFixed(1)+")"},t},toRGBA:function(){var t=r.hsvToRgb(s.h,s.s,s.v),e=t.map(a);return t.toString=function(){return"rgba("+e[0]+", "+e[1]+", "+e[2]+", "+s.a.toFixed(1)+")"},t},toCMYK:function(){var t=r.hsvToCmyk(s.h,s.s,s.v),e=t.map(a);return t.toString=function(){return"cmyk("+e[0]+"%, "+e[1]+"%, "+e[2]+"%, "+e[3]+"%)"},t},toHEX:function(){var t=r.hsvToHex.apply(r,[s.h,s.s,s.v]);return t.toString=function(){var e=s.a>=1?"":Number((255*s.a).toFixed(0)).toString(16).toUpperCase().padStart(2,"0");return"#"+(t.join("").toUpperCase()+e)},t},clone:function(){return t(s.h,s.s,s.v,s.a)}};return s};var r=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(1))},,function(t,e,n){},function(t,e,n){"use strict";var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}();n(6);var o=l(n(0)),i=l(n(1)),a=n(4),s=u(n(3)),c=u(n(2));function u(t){return t&&t.__esModule?t:{default:t}}function l(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function p(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}var d=function(){function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options=Object.assign({useAsButton:!1,disabled:!1,comparison:!0,components:{interaction:{}},strings:{},default:"fff",defaultRepresentation:"HEX",position:"middle",adjustableNumbers:!0,showAlways:!1,parent:void 0,closeWithKey:"Escape",onChange:function(){return 0},onSave:function(){return 0}},e),this.options.components.interaction||(this.options.components.interaction={}),this._initializingActive=!0,this._recalc=!0,this._color=new a.HSVaColor,this._lastColor=new a.HSVaColor,this._preBuild(),this._rePositioningPicker(),this._buildComponents(),this._bindEvents(),this.setColor(this.options.default),this._representation=this.options.defaultRepresentation,this.setColorRepresentation(this._representation),this._initializingActive=!1,this._finalBuild()}return r(t,[{key:"_preBuild",value:function(){var t=this.options;"string"==typeof t.el&&(t.el=document.querySelector(t.el)),this._root=function(t){var e=t.components,n=t.strings,r=t.useAsButton,i=function(t){return t?"":'style="display:none" hidden'},a=o.createFromTemplate('\n <div data-key="root" class="pickr">\n \n '+(r?"":'<div data-key="button" class="pcr-button"></div>')+'\n\n <div data-key="app" class="pcr-app">\n <div class="pcr-selection">\n <div data-con="preview" class="pcr-color-preview" '+i(e.preview)+'>\n <div data-key="lastColor" class="pcr-last-color"></div>\n <div data-key="currentColor" class="pcr-current-color"></div>\n </div>\n\n <div data-con="palette" class="pcr-color-palette">\n <div data-key="picker" class="pcr-picker"></div>\n <div data-key="palette" class="pcr-palette"></div>\n </div>\n\n <div data-con="hue" class="pcr-color-chooser" '+i(e.hue)+'>\n <div data-key="picker" class="pcr-picker"></div>\n <div data-key="slider" class="pcr-hue pcr-slider"></div>\n </div>\n\n <div data-con="opacity" class="pcr-color-opacity" '+i(e.opacity)+'>\n <div data-key="picker" class="pcr-picker"></div>\n <div data-key="slider" class="pcr-opacity pcr-slider"></div>\n </div>\n </div>\n\n <div data-con="interaction" class="pcr-interaction" '+i(e.interaction)+'>\n <input data-key="result" class="pcr-result" type="text" spellcheck="false" '+i(e.interaction.input)+'>\n\n <input data-arr="options" class="pcr-type" data-type="HEX" value="HEX" type="button" '+i(e.interaction.hex)+'>\n <input data-arr="options" class="pcr-type" data-type="RGBA" value="RGBa" type="button" '+i(e.interaction.rgba)+'>\n <input data-arr="options" class="pcr-type" data-type="HSLA" value="HSLa" type="button" '+i(e.interaction.hsla)+'>\n <input data-arr="options" class="pcr-type" data-type="HSVA" value="HSVa" type="button" '+i(e.interaction.hsva)+'>\n <input data-arr="options" class="pcr-type" data-type="CMYK" value="CMYK" type="button" '+i(e.interaction.cmyk)+'>\n\n <input data-key="save" class="pcr-save" value="'+(n.save||"Save")+'" type="button" '+i(e.interaction.save)+'>\n <input data-key="clear" class="pcr-clear" value="'+(n.clear||"Clear")+'" type="button" '+i(e.interaction.clear)+">\n </div>\n </div>\n </div>\n "),s=a.interaction;return s.options.find(function(t){return!t.hidden&&!t.classList.add("active")}),s.type=function(){return s.options.find(function(t){return t.classList.contains("active")})},a}(t),t.useAsButton&&(t.parent||(t.parent="body"),this._root.button=t.el),document.body.appendChild(this._root.root)}},{key:"_finalBuild",value:function(){var t=this.options,e=this._root;document.body.removeChild(e.root),t.parent&&("string"==typeof t.parent&&(t.parent=document.querySelector(t.parent)),t.parent.appendChild(e.app)),t.useAsButton||t.el.parentElement.replaceChild(e.root,t.el),t.disabled&&this.disable(),t.comparison||(e.button.style.transition="none",t.useAsButton||(e.preview.lastColor.style.transition="none")),t.showAlways?e.app.classList.add("visible"):this.hide()}},{key:"_buildComponents",value:function(){var t=this,e=this.options.components,n={palette:(0,s.default)({element:t._root.palette.picker,wrapper:t._root.palette.palette,onchange:function(e,n){var r=t._color,o=t._root,i=t.options;r.s=e/this.wrapper.offsetWidth*100,r.v=100-n/this.wrapper.offsetHeight*100;var a=r.toRGBA().toString();this.element.style.background=a,this.wrapper.style.background="\n linear-gradient(to top, rgba(0, 0, 0, "+r.a+"), transparent), \n linear-gradient(to left, hsla("+r.h+", 100%, 50%, "+r.a+"), rgba(255, 255, 255, "+r.a+"))\n ",i.comparison||(o.button.style.background=a,i.useAsButton||(o.preview.lastColor.style.background=a)),o.preview.currentColor.style.background=a,t._recalc&&t._updateOutput(),o.button.classList.remove("clear")}}),hue:(0,s.default)({lockX:!0,element:t._root.hue.picker,wrapper:t._root.hue.slider,onchange:function(r,o){e.hue&&(t._color.h=o/this.wrapper.offsetHeight*360,this.element.style.backgroundColor="hsl("+t._color.h+", 100%, 50%)",n.palette.trigger())}}),opacity:(0,s.default)({lockX:!0,element:t._root.opacity.picker,wrapper:t._root.opacity.slider,onchange:function(n,r){e.opacity&&(t._color.a=Math.round(r/this.wrapper.offsetHeight*100)/100,this.element.style.background="rgba(0, 0, 0, "+t._color.a+")",t.components.palette.trigger())}}),selectable:(0,c.default)({elements:t._root.interaction.options,className:"active",onchange:function(e){t._representation=e.target.getAttribute("data-type").toUpperCase(),t._updateOutput()}})};this.components=n}},{key:"_bindEvents",value:function(){var t=this,e=this._root,n=this.options,r=[o.on(e.interaction.clear,"click",function(){return t._clearColor()}),o.on(e.preview.lastColor,"click",function(){return t.setHSVA.apply(t,p(t._lastColor.toHSVA()))}),o.on(e.interaction.save,"click",function(){!t._saveColor()&&!n.showAlways&&t.hide()}),o.on(e.interaction.result,["keyup","input"],function(e){t._recalc=!1,t.setColor(e.target.value,!0)&&!t._initializingActive&&t.options.onChange(t._color,t),e.stopImmediatePropagation()}),o.on([e.palette.palette,e.palette.picker,e.hue.slider,e.hue.picker,e.opacity.slider,e.opacity.picker],["mousedown","touchstart"],function(){return t._recalc=!0}),o.on(window,"resize",function(){return t._rePositioningPicker})];if(!n.showAlways){r.push(o.on(e.button,"click",function(){return t.isOpen()?t.hide():t.show()}));var i=n.closeWithKey;r.push(o.on(document,"keyup",function(e){return t.isOpen()&&(e.key===i||e.code===i)&&t.hide()})),r.push(o.on(document,"click",function(n){o.eventPath(n).some(function(t){return t===e.root||t===e.button})||t.isOpen()&&t.hide()}))}n.adjustableNumbers&&o.adjustableInputNumbers(e.interaction.result,!1),this._eventBindings=r}},{key:"_rePositioningPicker",value:function(){var t=this._root,e=this._root.app;if(this.options.parent){var n=t.button.getBoundingClientRect();e.style.position="fixed",e.style.marginLeft=n.left+"px",e.style.marginTop=n.top+"px"}var r=t.button.getBoundingClientRect(),o=e.getBoundingClientRect(),i=e.style;o.bottom>window.innerHeight?i.top=-o.height-5+"px":r.bottom+o.height<window.innerHeight&&(i.top=r.height+5+"px");var a={left:-o.width+r.width,middle:-o.width/2+r.width/2,right:0},s=parseInt(getComputedStyle(e).left,10),c=a[this.options.position];o.left-s+c<0?c=a.right:o.left-s-c>window.innerWidth&&(c=a.left),i.left=c+"px"}},{key:"_updateOutput",value:function(){var t=this;this._root.interaction.type()&&(this._root.interaction.result.value=function(){var e="to"+t._root.interaction.type().getAttribute("data-type");return"function"==typeof t._color[e]?t._color[e]().toString():""}()),this._initializingActive||this.options.onChange(this._color,this)}},{key:"_saveColor",value:function(){var t=this._root,e=t.preview,n=t.button,r=this._color.toRGBA().toString();e.lastColor.style.background=r,this.options.useAsButton||(n.style.background=r),n.classList.remove("clear"),this._lastColor=this._color.clone(),this._initializingActive||this.options.onSave(this._color,this)}},{key:"_clearColor",value:function(){var t=this._root,e=this.options;e.useAsButton||(t.button.style.background="rgba(255, 255, 255, 0.4)"),t.button.classList.add("clear"),e.showAlways||this.hide(),e.onSave(null,this)}},{key:"destroy",value:function(){var t=this;this._eventBindings.forEach(function(t){return o.off.apply(o,p(t))}),Object.keys(this.components).forEach(function(e){return t.components[e].destroy()})}},{key:"destroyAndRemove",value:function(){this.destroy();var t=this._root.root;t.parentElement.removeChild(t)}},{key:"hide",value:function(){return this._root.app.classList.remove("visible"),this}},{key:"show",value:function(){if(!this.options.disabled)return this._root.app.classList.add("visible"),this._rePositioningPicker(),this}},{key:"isOpen",value:function(){return this._root.app.classList.contains("visible")}},{key:"setHSVA",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:360,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,o=arguments.length>4&&void 0!==arguments[4]&&arguments[4],i=this._recalc;if(this._recalc=!1,t<0||t>360||e<0||e>100||n<0||n>100||r<0||r>1)return!1;var s=this.components,c=s.hue,u=s.opacity,l=s.palette,p=c.options.wrapper.offsetHeight*(t/360);c.update(0,p);var d=u.options.wrapper.offsetHeight*r;u.update(0,d);var f=l.options.wrapper,h=f.offsetWidth*(e/100),v=f.offsetHeight*(1-n/100);return l.update(h,v),this._color=new a.HSVaColor(t,e,n,r),this._recalc=i,this._recalc&&this._updateOutput(),o||this._saveColor(),!0}},{key:"setColor",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(null===t)return this._clearColor(),!0;var n=i.parseToHSV(t);return n?this.setHSVA.apply(this,p(n).concat([e])):void 0}},{key:"setColorRepresentation",value:function(t){return t=t.toUpperCase(),!!this._root.interaction.options.find(function(e){return e.getAttribute("data-type")===t&&!e.click()})}},{key:"getColorRepresentation",value:function(){return this._representation}},{key:"getColor",value:function(){return this._color}},{key:"getRoot",value:function(){return this._root}},{key:"disable",value:function(){return this.hide(),this.options.disabled=!0,this._root.button.classList.add("disabled"),this}},{key:"enable",value:function(){return this.options.disabled=!1,this._root.button.classList.remove("disabled"),this}}]),t}();d.utils={once:o.once,on:o.on,off:o.off,eventPath:o.eventPath,createElementFromString:o.createElementFromString,adjustableInputNumbers:o.adjustableInputNumbers,removeAttribute:o.removeAttribute,createFromTemplate:o.createFromTemplate},d.create=function(t){return new d(t)},d.version="0.2.5",t.exports=d}])}); |