/*! * vanilla-picker v2.12.3 * https://vanilla-picker.js.org * * Copyright 2017-2024 Andreas Borgen (https://github.com/Sphinxxxx), Adam Brooks (https://github.com/dissimulate) * Released under the ISC license. */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Picker=e()}(this,function(){"use strict";function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var t=function(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),t};function i(t,e){for(var n=0;ne&&(i=!0)):(g(t),i=!0):i=!0,i&&this.hide()&&(this.settings.parent.style.pointerEvents="",n!==l&&this.settings.parent.focus(),this.onClose&&this.onClose(this.colour))}},{key:"movePopup",value:function(t,e){this.closeHandler(),this.setOptions(t),e&&this.openHandler()}},{key:"setColor",value:function(t,e){this._setColor(t,{silent:e})}},{key:"_setColor",value:function(t,e){if(t="string"==typeof t?t.trim():t){e=e||{};var n=void 0;try{n=new s(t)}catch(t){if(e.failSilently)return;throw t}this.settings.alpha||((t=n.hsla)[3]=1,n.hsla=t),this.colour=this.color=n,this._setHSLA(null,null,null,null,e)}}},{key:"setColour",value:function(t,e){this.setColor(t,e)}},{key:"show",value:function(){if(!this.settings.parent)return!1;if(this.domElement){var t=this._toggleDOM(!0);return this._setPosition(),t}var e=this.settings.template||'
',n=(t=e,(e=document.createElement("div")).innerHTML=t,e.firstElementChild);return this.domElement=n,this._domH=p(".picker_hue",n),this._domSL=p(".picker_sl",n),this._domA=p(".picker_alpha",n),this._domEdit=p(".picker_editor input",n),this._domSample=p(".picker_sample",n),this._domOkay=p(".picker_done button",n),this._domCancel=p(".picker_cancel button",n),n.classList.add("layout_"+this.settings.layout),this.settings.alpha||n.classList.add("no_alpha"),this.settings.editor||n.classList.add("no_editor"),this.settings.cancelButton||n.classList.add("no_cancel"),this._ifPopup(function(){return n.classList.add("popup")}),this._setPosition(),this.colour?this._updateUI():this._setColor(this.settings.defaultColor),this._bindEvents(),!0}},{key:"hide",value:function(){return this._toggleDOM(!1)}},{key:"destroy",value:function(){this._events.destroy(),this.domElement&&this.settings.parent.removeChild(this.domElement)}},{key:"_bindEvents",value:function(){var n=this,i=this,r=this.domElement,s=this._events;function o(t,e,n){s.add(t,e,n)}o(r,"click",function(t){return t.preventDefault()}),a(s,this._domH,function(t,e){return i._setHSLA(t)}),a(s,this._domSL,function(t,e){return i._setHSLA(null,t,1-e)}),this.settings.alpha&&a(s,this._domA,function(t,e){return i._setHSLA(null,null,null,1-e)});var t=this._domEdit;o(t,"input",function(t){i._setColor(this.value,{fromEditor:!0,failSilently:!0})}),o(t,"focus",function(t){this.selectionStart===this.selectionEnd&&this.select()}),this._ifPopup(function(){function t(t){return n.closeHandler(t)}o(window,l,t),o(window,h,t),v(s,r,["Esc","Escape"],t);function e(t){n.__containedEvent=t.timeStamp}o(r,l,e),o(r,h,e),o(n._domCancel,"click",t)});t=function(t){n._ifPopup(function(){return n.closeHandler(t)}),n.onDone&&n.onDone(n.colour)};o(this._domOkay,"click",t),v(s,r,["Enter"],t)}},{key:"_setPosition",value:function(){var n=this.settings.parent,i=this.domElement;n!==i.parentNode&&n.appendChild(i),this._ifPopup(function(t){"static"===getComputedStyle(n).position&&(n.style.position="relative");var e=!0===t?"popup_right":"popup_"+t;["popup_top","popup_bottom","popup_left","popup_right"].forEach(function(t){t===e?i.classList.add(t):i.classList.remove(t)}),i.classList.add(e)})}},{key:"_setHSLA",value:function(t,e,n,i,r){r=r||{};var s=this.colour,o=s.hsla;[t,e,n,i].forEach(function(t,e){!t&&0!==t||(o[e]=t)}),s.hsla=o,this._updateUI(r),this.onChange&&!r.silent&&this.onChange(s)}},{key:"_updateUI",value:function(t){if(this.domElement){t=t||{};var e=this.colour,n=e.hsla,i="hsl("+360*n[0]+", 100%, 50%)",r=e.hslString,s=e.hslaString,o=this._domH,a=this._domSL,c=this._domA,l=p(".picker_selector",o),o=p(".picker_selector",a),c=p(".picker_selector",c);d(0,l,n[0]),this._domSL.style.backgroundColor=this._domH.style.color=i,d(0,o,n[1]),f(0,o,1-n[2]),a.style.color=r,f(0,c,1-n[3]);n=r,r=n.replace("hsl","hsla").replace(")",", 0)");if(this._domA.style.background="linear-gradient("+[n,r]+")"+", linear-gradient(45deg, lightgrey 25%, transparent 25%, transparent 75%, lightgrey 75%) 0 0 / 2em 2em,\n linear-gradient(45deg, lightgrey 25%, white 25%, white 75%, lightgrey 75%) 1em 1em / 2em 2em",!t.fromEditor){var t=this.settings.editorFormat,h=this.settings.alpha,u=void 0;switch(t){case"rgb":u=e.printRGB(h);break;case"hsl":u=e.printHSL(h);break;default:u=e.printHex(h)}this._domEdit.value=u}this._domSample.style.color=s}function d(t,e,n){e.style.left=100*n+"%"}function f(t,e,n){e.style.top=100*n+"%"}}},{key:"_ifPopup",value:function(t,e){this.settings.parent&&this.settings.popup?t&&t(this.settings.popup):e&&e()}},{key:"_toggleDOM",value:function(t){var e=this.domElement;if(!e)return!1;var n=t?"":"none",t=e.style.display!==n;return t&&(e.style.display=n),t}}]),b});