vuepress-theme-plume/assets/pickr.min-1dwDXx4g.js

1 line
23 KiB
JavaScript

import{t as e}from"./chunk-DseTPa7n.js";var t=e(((e,t)=>{(function(n,r){typeof e==`object`&&typeof t==`object`?t.exports=r():typeof define==`function`&&define.amd?define([],r):typeof e==`object`?e.Pickr=r():n.Pickr=r()})(self,(()=>(()=>{var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{typeof Symbol<`u`&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:`Module`}),Object.defineProperty(e,`__esModule`,{value:!0})}},t={};e.d(t,{default:()=>O});var n={};function r(e,t,n,r,i={}){t instanceof HTMLCollection||t instanceof NodeList?t=Array.from(t):Array.isArray(t)||(t=[t]),Array.isArray(n)||(n=[n]);for(let a of t)for(let t of n)a[e](t,r,{capture:!1,...i});return Array.prototype.slice.call(arguments,1)}e.r(n),e.d(n,{adjustableInputNumbers:()=>u,createElementFromString:()=>o,createFromTemplate:()=>s,eventPath:()=>c,off:()=>a,on:()=>i,resolveElement:()=>l});let i=r.bind(null,`addEventListener`),a=r.bind(null,`removeEventListener`);function o(e){let t=document.createElement(`div`);return t.innerHTML=e.trim(),t.firstElementChild}function s(e){let t=(e,t)=>{let n=e.getAttribute(t);return e.removeAttribute(t),n},n=(e,r={})=>{let i=t(e,`:obj`),a=t(e,`:ref`),o=i?r[i]={}:r;a&&(r[a]=e);for(let r of Array.from(e.children)){let e=t(r,`:arr`),i=n(r,e?{}:o);e&&(o[e]||(o[e]=[])).push(Object.keys(i).length?i:r)}return r};return n(o(e))}function c(e){let t=e.path||e.composedPath&&e.composedPath();if(t)return t;let n=e.target.parentElement;for(t=[e.target,n];n=n.parentElement;)t.push(n);return t.push(document,window),t}function l(e){return e instanceof Element?e:typeof e==`string`?e.split(/>>/g).reduce(((e,t,n,r)=>(e=e.querySelector(t),n<r.length-1?e.shadowRoot:e)),document):null}function u(e,t=(e=>e)){function n(n){let r=[.001,.01,.1][Number(n.shiftKey||2*n.ctrlKey)]*(n.deltaY<0?1:-1),i=0,a=e.selectionStart;e.value=e.value.replace(/[\d.]+/g,((e,n)=>n<=a&&n+e.length>=a?(a=n,t(Number(e),r,i)):(i++,e))),e.focus(),e.setSelectionRange(a,a),n.preventDefault(),e.dispatchEvent(new Event(`input`))}i(e,`focus`,(()=>i(window,`wheel`,n,{passive:!1}))),i(e,`blur`,(()=>a(window,`wheel`,n)))}let{min:d,max:f,floor:p,round:m}=Math;function h(e,t,n){t/=100,n/=100;let r=p(e=e/360*6),i=e-r,a=n*(1-t),o=n*(1-i*t),s=n*(1-(1-i)*t),c=r%6;return[255*[n,o,a,a,s,n][c],255*[s,n,n,o,a,a][c],255*[a,a,s,n,n,o][c]]}function g(e,t,n){let r=(2-(t/=100))*(n/=100)/2;return r!==0&&(t=r===1?0:r<.5?t*n/(2*r):t*n/(2-2*r)),[e,100*t,100*r]}function _(e,t,n){let r=d(e/=255,t/=255,n/=255),i=f(e,t,n),a=i-r,o,s;if(a===0)o=s=0;else{s=a/i;let r=((i-e)/6+a/2)/a,c=((i-t)/6+a/2)/a,l=((i-n)/6+a/2)/a;e===i?o=l-c:t===i?o=1/3+r-l:n===i&&(o=2/3+c-r),o<0?o+=1:o>1&&--o}return[360*o,100*s,100*i]}function v(e,t,n,r){return t/=100,n/=100,[..._(255*(1-d(1,(e/=100)*(1-(r/=100))+r)),255*(1-d(1,t*(1-r)+r)),255*(1-d(1,n*(1-r)+r)))]}function y(e,t,n){t/=100;let r=2*(t*=(n/=100)<.5?n:1-n)/(n+t)*100,i=100*(n+t);return[e,isNaN(r)?0:r,i]}function b(e){return _(...e.match(/.{2}/g).map((e=>parseInt(e,16))))}function x(e){e=e.match(/^[a-zA-Z]+$/)?function(e){if(e.toLowerCase()===`black`)return`#000`;let t=document.createElement(`canvas`).getContext(`2d`);return t.fillStyle=e,t.fillStyle===`#000`?null:t.fillStyle}(e):e;let t={cmyk:/^cmyk\D+([\d.]+)\D+([\d.]+)\D+([\d.]+)\D+([\d.]+)/i,rgba:/^rgba?\D+([\d.]+)(%?)\D+([\d.]+)(%?)\D+([\d.]+)(%?)\D*?(([\d.]+)(%?)|$)/i,hsla:/^hsla?\D+([\d.]+)\D+([\d.]+)\D+([\d.]+)\D*?(([\d.]+)(%?)|$)/i,hsva:/^hsva?\D+([\d.]+)\D+([\d.]+)\D+([\d.]+)\D*?(([\d.]+)(%?)|$)/i,hexa:/^#?(([\dA-Fa-f]{3,4})|([\dA-Fa-f]{6})|([\dA-Fa-f]{8}))$/i},n=e=>e.map((e=>/^(|\d+)\.\d+|\d+$/.test(e)?Number(e):void 0)),r;t:for(let i in t)if(r=t[i].exec(e))switch(i){case`cmyk`:{let[,e,t,a,o]=n(r);if(e>100||t>100||a>100||o>100)break t;return{values:v(e,t,a,o),type:i}}case`rgba`:{let[,e,,t,,a,,,o]=n(r);if(e=r[2]===`%`?e/100*255:e,t=r[4]===`%`?t/100*255:t,a=r[6]===`%`?a/100*255:a,o=r[9]===`%`?o/100:o,e>255||t>255||a>255||o<0||o>1)break t;return{values:[..._(e,t,a),o],a:o,type:i}}case`hexa`:{let[,e]=r;e.length!==4&&e.length!==3||(e=e.split(``).map((e=>e+e)).join(``));let t=e.substring(0,6),n=e.substring(6);return n=n?parseInt(n,16)/255:void 0,{values:[...b(t),n],a:n,type:i}}case`hsla`:{let[,e,t,a,,o]=n(r);if(o=r[6]===`%`?o/100:o,e>360||t>100||a>100||o<0||o>1)break t;return{values:[...y(e,t,a),o],a:o,type:i}}case`hsva`:{let[,e,t,a,,o]=n(r);if(o=r[6]===`%`?o/100:o,e>360||t>100||a>100||o<0||o>1)break t;return{values:[e,t,a,o],a:o,type:i}}}return{values:null,type:null}}function S(e=0,t=0,n=0,r=1){let i=(e,t)=>(n=-1)=>t(~n?e.map((e=>Number(e.toFixed(n)))):e),a={h:e,s:t,v:n,a:r,toHSVA(){let e=[a.h,a.s,a.v,a.a];return e.toString=i(e,(e=>`hsva(${e[0]}, ${e[1]}%, ${e[2]}%, ${a.a})`)),e},toHSLA(){let e=[...g(a.h,a.s,a.v),a.a];return e.toString=i(e,(e=>`hsla(${e[0]}, ${e[1]}%, ${e[2]}%, ${a.a})`)),e},toRGBA(){let e=[...h(a.h,a.s,a.v),a.a];return e.toString=i(e,(e=>`rgba(${e[0]}, ${e[1]}, ${e[2]}, ${a.a})`)),e},toCMYK(){let e=function(e,t,n){let r=h(e,t,n),i=r[0]/255,a=r[1]/255,o=r[2]/255,s=d(1-i,1-a,1-o);return[100*(s===1?0:(1-i-s)/(1-s)),100*(s===1?0:(1-a-s)/(1-s)),100*(s===1?0:(1-o-s)/(1-s)),100*s]}(a.h,a.s,a.v);return e.toString=i(e,(e=>`cmyk(${e[0]}%, ${e[1]}%, ${e[2]}%, ${e[3]}%)`)),e},toHEXA(){let e=function(e,t,n){return h(e,t,n).map((e=>m(e).toString(16).padStart(2,`0`)))}(a.h,a.s,a.v),t=a.a>=1?``:Number((255*a.a).toFixed(0)).toString(16).toUpperCase().padStart(2,`0`);return t&&e.push(t),e.toString=()=>`#${e.join(``).toUpperCase()}`,e},clone:()=>S(a.h,a.s,a.v,a.a)};return a}let C=e=>Math.max(Math.min(e,1),0);function w(e){let t={options:Object.assign({lock:null,onchange:()=>0,onstop:()=>0},e),_keyboard(e){let{options:n}=t,{type:r,key:i}=e;if(document.activeElement===n.wrapper){let{lock:n}=t.options,a=i===`ArrowUp`,o=i===`ArrowRight`,s=i===`ArrowDown`,c=i===`ArrowLeft`;if(r===`keydown`&&(a||o||s||c)){let r=0,i=0;n===`v`?r=a||o?1:-1:n===`h`?r=a||o?-1:1:(i=a?-1:+!!s,r=c?-1:+!!o),t.update(C(t.cache.x+.01*r),C(t.cache.y+.01*i)),e.preventDefault()}else i.startsWith(`Arrow`)&&(t.options.onstop(),e.preventDefault())}},_tapstart(e){i(document,[`mouseup`,`touchend`,`touchcancel`],t._tapstop),i(document,[`mousemove`,`touchmove`],t._tapmove),e.cancelable&&e.preventDefault(),t._tapmove(e)},_tapmove(e){let{options:n,cache:r}=t,{lock:i,element:a,wrapper:o}=n,s=o.getBoundingClientRect(),c=0,l=0;if(e){let t=e&&e.touches&&e.touches[0];c=e?(t||e).clientX:0,l=e?(t||e).clientY:0,c<s.left?c=s.left:c>s.left+s.width&&(c=s.left+s.width),l<s.top?l=s.top:l>s.top+s.height&&(l=s.top+s.height),c-=s.left,l-=s.top}else r&&(c=r.x*s.width,l=r.y*s.height);i!==`h`&&(a.style.left=`calc(${c/s.width*100}% - ${a.offsetWidth/2}px)`),i!==`v`&&(a.style.top=`calc(${l/s.height*100}% - ${a.offsetHeight/2}px)`),t.cache={x:c/s.width,y:l/s.height};let u=C(c/s.width),d=C(l/s.height);switch(i){case`v`:return n.onchange(u);case`h`:return n.onchange(d);default:return n.onchange(u,d)}},_tapstop(){t.options.onstop(),a(document,[`mouseup`,`touchend`,`touchcancel`],t._tapstop),a(document,[`mousemove`,`touchmove`],t._tapmove)},trigger(){t._tapmove()},update(e=0,n=0){let{left:r,top:i,width:a,height:o}=t.options.wrapper.getBoundingClientRect();t.options.lock===`h`&&(n=e),t._tapmove({clientX:r+a*e,clientY:i+o*n})},destroy(){let{options:e,_tapstart:n,_keyboard:r}=t;a(document,[`keydown`,`keyup`],r),a([e.wrapper,e.element],`mousedown`,n),a([e.wrapper,e.element],`touchstart`,n,{passive:!1})}},{options:n,_tapstart:r,_keyboard:o}=t;return i([n.wrapper,n.element],`mousedown`,r),i([n.wrapper,n.element],`touchstart`,r,{passive:!1}),i(document,[`keydown`,`keyup`],o),t}function T(e={}){e=Object.assign({onchange:()=>0,className:``,elements:[]},e);let t=i(e.elements,`click`,(t=>{e.elements.forEach((n=>n.classList[t.target===n?`add`:`remove`](e.className))),e.onchange(t),t.stopPropagation()}));return{destroy:()=>a(...t)}}let E={variantFlipOrder:{start:`sme`,middle:`mse`,end:`ems`},positionFlipOrder:{top:`tbrl`,right:`rltb`,bottom:`btrl`,left:`lrbt`},position:`bottom`,margin:8,padding:0},D=(e,t,n)=>{let r=typeof e!=`object`||e instanceof HTMLElement?{reference:e,popper:t,...n}:e;return{update(e=r){let{reference:t,popper:n}=Object.assign(r,e);if(!n||!t)throw Error(`Popper- or reference-element missing.`);return((e,t,n)=>{let{container:r,arrow:i,margin:a,padding:o,position:s,variantFlipOrder:c,positionFlipOrder:l}={container:document.documentElement.getBoundingClientRect(),...E,...n},{left:u,top:d}=t.style;t.style.left=`0`,t.style.top=`0`;let f=e.getBoundingClientRect(),p=t.getBoundingClientRect(),m={t:f.top-p.height-a,b:f.bottom+a,r:f.right+a,l:f.left-p.width-a},h={vs:f.left,vm:f.left+f.width/2-p.width/2,ve:f.left+f.width-p.width,hs:f.top,hm:f.bottom-f.height/2-p.height/2,he:f.bottom-p.height},[g,_=`middle`]=s.split(`-`),v=l[g],y=c[_],{top:b,left:x,bottom:S,right:C}=r;for(let e of v){let n=e===`t`||e===`b`,r=m[e],[a,s]=n?[`top`,`left`]:[`left`,`top`],[c,l]=n?[p.height,p.width]:[p.width,p.height],[u,d]=n?[S,C]:[C,S],[g,_]=n?[b,x]:[x,b];if(!(r<g||r+c+o>u))for(let u of y){let m=h[(n?`v`:`h`)+u];if(!(m<_||m+l+o>d)){if(m-=p[s],r-=p[a],t.style[s]=`${m}px`,t.style[a]=`${r}px`,i){let t=n?f.width/2:f.height/2,o=l/2,d=t>o,p=m+{s:d?o:t,m:o,e:d?o:l-t}[u],h=r+{t:c,b:0,r:0,l:c}[e];i.style[s]=`${p}px`,i.style[a]=`${h}px`}return e+u}}}return t.style.left=u,t.style.top=d,null})(t,n,r)}}};class O{static utils=n;static version=`1.9.1`;static I18N_DEFAULTS={"ui:dialog":`color picker dialog`,"btn:toggle":`toggle color picker dialog`,"btn:swatch":`color swatch`,"btn:last-color":`use previous color`,"btn:save":`Save`,"btn:cancel":`Cancel`,"btn:clear":`Clear`,"aria:btn:save":`save and close`,"aria:btn:cancel":`cancel and close`,"aria:btn:clear":`clear and close`,"aria:input":`color input field`,"aria:palette":`color selection area`,"aria:hue":`hue selection slider`,"aria:opacity":`selection slider`};static DEFAULT_OPTIONS={appClass:null,theme:`classic`,useAsButton:!1,padding:8,disabled:!1,comparison:!0,closeOnScroll:!1,outputPrecision:0,lockOpacity:!1,autoReposition:!0,container:`body`,components:{interaction:{}},i18n:{},swatches:null,inline:!1,sliders:null,default:`#42445a`,defaultRepresentation:null,position:`bottom-middle`,adjustableNumbers:!0,showAlways:!1,closeWithKey:`Escape`};_initializingActive=!0;_recalc=!0;_nanopop=null;_root=null;_color=S();_lastColor=S();_swatchColors=[];_setupAnimationFrame=null;_eventListener={init:[],save:[],hide:[],show:[],clear:[],change:[],changestop:[],cancel:[],swatchselect:[]};constructor(e){this.options=e=Object.assign({...O.DEFAULT_OPTIONS},e);let{swatches:t,components:n,theme:r,sliders:i,lockOpacity:a,padding:o}=e;[`nano`,`monolith`].includes(r)&&!i&&(e.sliders=`h`),n.interaction||={};let{preview:s,opacity:c,hue:l,palette:u}=n;n.opacity=!a&&c,n.palette=u||s||c||l,this._preBuild(),this._buildComponents(),this._bindEvents(),this._finalBuild(),t&&t.length&&t.forEach((e=>this.addSwatch(e)));let{button:d,app:f}=this._root;this._nanopop=D(d,f,{margin:o}),d.setAttribute(`role`,`button`),d.setAttribute(`aria-label`,this._t(`btn:toggle`));let p=this;this._setupAnimationFrame=requestAnimationFrame((function t(){if(!f.offsetWidth)return requestAnimationFrame(t);p.setColor(e.default),p._rePositioningPicker(),e.defaultRepresentation&&(p._representation=e.defaultRepresentation,p.setColorRepresentation(p._representation)),e.showAlways&&p.show(),p._initializingActive=!1,p._emit(`init`)}))}static create=e=>new O(e);_preBuild(){let{options:e}=this;for(let t of[`el`,`container`])e[t]=l(e[t]);this._root=(e=>{let{components:t,useAsButton:n,inline:r,appClass:i,theme:a,lockOpacity:o}=e.options,c=e=>e?``:`style="display:none" hidden`,l=t=>e._t(t),u=s(`\n <div :ref="root" class="pickr">\n\n ${n?``:`<button type="button" :ref="button" class="pcr-button"></button>`}\n\n <div :ref="app" class="pcr-app ${i||``}" data-theme="${a}" ${r?`style="position: unset"`:``} aria-label="${l(`ui:dialog`)}" role="window">\n <div class="pcr-selection" ${c(t.palette)}>\n <div :obj="preview" class="pcr-color-preview" ${c(t.preview)}>\n <button type="button" :ref="lastColor" class="pcr-last-color" aria-label="${l(`btn:last-color`)}"></button>\n <div :ref="currentColor" class="pcr-current-color"></div>\n </div>\n\n <div :obj="palette" class="pcr-color-palette">\n <div :ref="picker" class="pcr-picker"></div>\n <div :ref="palette" class="pcr-palette" tabindex="0" aria-label="${l(`aria:palette`)}" role="listbox"></div>\n </div>\n\n <div :obj="hue" class="pcr-color-chooser" ${c(t.hue)}>\n <div :ref="picker" class="pcr-picker"></div>\n <div :ref="slider" class="pcr-hue pcr-slider" tabindex="0" aria-label="${l(`aria:hue`)}" role="slider"></div>\n </div>\n\n <div :obj="opacity" class="pcr-color-opacity" ${c(t.opacity)}>\n <div :ref="picker" class="pcr-picker"></div>\n <div :ref="slider" class="pcr-opacity pcr-slider" tabindex="0" aria-label="${l(`aria:opacity`)}" role="slider"></div>\n </div>\n </div>\n\n <div class="pcr-swatches ${t.palette?``:`pcr-last`}" :ref="swatches"></div>\n\n <div :obj="interaction" class="pcr-interaction" ${c(Object.keys(t.interaction).length)}>\n <input :ref="result" class="pcr-result" type="text" spellcheck="false" ${c(t.interaction.input)} aria-label="${l(`aria:input`)}">\n\n <input :arr="options" class="pcr-type" data-type="HEXA" value="${o?`HEX`:`HEXA`}" type="button" ${c(t.interaction.hex)}>\n <input :arr="options" class="pcr-type" data-type="RGBA" value="${o?`RGB`:`RGBA`}" type="button" ${c(t.interaction.rgba)}>\n <input :arr="options" class="pcr-type" data-type="HSLA" value="${o?`HSL`:`HSLA`}" type="button" ${c(t.interaction.hsla)}>\n <input :arr="options" class="pcr-type" data-type="HSVA" value="${o?`HSV`:`HSVA`}" type="button" ${c(t.interaction.hsva)}>\n <input :arr="options" class="pcr-type" data-type="CMYK" value="CMYK" type="button" ${c(t.interaction.cmyk)}>\n\n <input :ref="save" class="pcr-save" value="${l(`btn:save`)}" type="button" ${c(t.interaction.save)} aria-label="${l(`aria:btn:save`)}">\n <input :ref="cancel" class="pcr-cancel" value="${l(`btn:cancel`)}" type="button" ${c(t.interaction.cancel)} aria-label="${l(`aria:btn:cancel`)}">\n <input :ref="clear" class="pcr-clear" value="${l(`btn:clear`)}" type="button" ${c(t.interaction.clear)} aria-label="${l(`aria:btn:clear`)}">\n </div>\n </div>\n </div>\n `),d=u.interaction;return d.options.find((e=>!e.hidden&&!e.classList.add(`active`))),d.type=()=>d.options.find((e=>e.classList.contains(`active`))),u})(this),e.useAsButton&&(this._root.button=e.el),e.container.appendChild(this._root.root)}_finalBuild(){let e=this.options,t=this._root;if(e.container.removeChild(t.root),e.inline){let n=e.el.parentElement;e.el.nextSibling?n.insertBefore(t.app,e.el.nextSibling):n.appendChild(t.app)}else e.container.appendChild(t.app);e.useAsButton?e.inline&&e.el.remove():e.el.parentNode.replaceChild(t.root,e.el),e.disabled&&this.disable(),e.comparison||(t.button.style.transition=`none`,e.useAsButton||(t.preview.lastColor.style.transition=`none`)),this.hide()}_buildComponents(){let e=this,t=this.options.components,n=(e.options.sliders||`v`).repeat(2),[r,i]=n.match(/^[vh]+$/g)?n:[],a=()=>this._color||=this._lastColor.clone(),o={palette:w({element:e._root.palette.picker,wrapper:e._root.palette.palette,onstop:()=>e._emit(`changestop`,`slider`,e),onchange(n,r){if(!t.palette)return;let i=a(),{_root:o,options:s}=e,{lastColor:c,currentColor:l}=o.preview;e._recalc&&(i.s=100*n,i.v=100-100*r,i.v<0&&(i.v=0),e._updateOutput(`slider`));let u=i.toRGBA().toString(0);this.element.style.background=u,this.wrapper.style.background=`\n linear-gradient(to top, rgba(0, 0, 0, ${i.a}), transparent),\n linear-gradient(to left, hsla(${i.h}, 100%, 50%, ${i.a}), rgba(255, 255, 255, ${i.a}))\n `,s.comparison?s.useAsButton||e._lastColor||c.style.setProperty(`--pcr-color`,u):(o.button.style.setProperty(`--pcr-color`,u),o.button.classList.remove(`clear`));let d=i.toHEXA().toString();for(let{el:t,color:n}of e._swatchColors)t.classList[d===n.toHEXA().toString()?`add`:`remove`](`pcr-active`);l.style.setProperty(`--pcr-color`,u)}}),hue:w({lock:i===`v`?`h`:`v`,element:e._root.hue.picker,wrapper:e._root.hue.slider,onstop:()=>e._emit(`changestop`,`slider`,e),onchange(n){if(!t.hue||!t.palette)return;let r=a();e._recalc&&(r.h=360*n),this.element.style.backgroundColor=`hsl(${r.h}, 100%, 50%)`,o.palette.trigger()}}),opacity:w({lock:r===`v`?`h`:`v`,element:e._root.opacity.picker,wrapper:e._root.opacity.slider,onstop:()=>e._emit(`changestop`,`slider`,e),onchange(n){if(!t.opacity||!t.palette)return;let r=a();e._recalc&&(r.a=Math.round(100*n)/100),this.element.style.background=`rgba(0, 0, 0, ${r.a})`,o.palette.trigger()}}),selectable:T({elements:e._root.interaction.options,className:`active`,onchange(t){e._representation=t.target.getAttribute(`data-type`).toUpperCase(),e._recalc&&e._updateOutput(`swatch`)}})};this._components=o}_bindEvents(){let{_root:e,options:t}=this,n=[i(e.interaction.clear,`click`,(()=>this._clearColor())),i([e.interaction.cancel,e.preview.lastColor],`click`,(()=>{this.setHSVA(...(this._lastColor||this._color).toHSVA(),!0),this._emit(`cancel`)})),i(e.interaction.save,`click`,(()=>{!this.applyColor()&&!t.showAlways&&this.hide()})),i(e.interaction.result,[`keyup`,`input`],(e=>{this.setColor(e.target.value,!0)&&!this._initializingActive&&(this._emit(`change`,this._color,`input`,this),this._emit(`changestop`,`input`,this)),e.stopImmediatePropagation()})),i(e.interaction.result,[`focus`,`blur`],(e=>{this._recalc=e.type===`blur`,this._recalc&&this._updateOutput(null)})),i([e.palette.palette,e.palette.picker,e.hue.slider,e.hue.picker,e.opacity.slider,e.opacity.picker],[`mousedown`,`touchstart`],(()=>this._recalc=!0),{passive:!0})];if(!t.showAlways){let r=t.closeWithKey;n.push(i(e.button,`click`,(()=>this.isOpen()?this.hide():this.show())),i(document,`keyup`,(e=>this.isOpen()&&(e.key===r||e.code===r)&&this.hide())),i(document,[`touchstart`,`mousedown`],(t=>{this.isOpen()&&!c(t).some((t=>t===e.app||t===e.button))&&this.hide()}),{capture:!0}))}if(t.adjustableNumbers){let t={rgba:[255,255,255,1],hsva:[360,100,100,1],hsla:[360,100,100,1],cmyk:[100,100,100,100]};u(e.interaction.result,((e,n,r)=>{let i=t[this.getColorRepresentation().toLowerCase()];if(i){let t=i[r],a=e+(t>=100?1e3*n:n);return a<=0?0:Number((a<t?a:t).toPrecision(3))}return e}))}if(t.autoReposition&&!t.inline){let e=null,r=this;n.push(i(window,[`scroll`,`resize`],(()=>{r.isOpen()&&(t.closeOnScroll&&r.hide(),e===null?(e=setTimeout((()=>e=null),100),requestAnimationFrame((function t(){r._rePositioningPicker(),e!==null&&requestAnimationFrame(t)}))):(clearTimeout(e),e=setTimeout((()=>e=null),100)))}),{capture:!0}))}this._eventBindings=n}_rePositioningPicker(){let{options:e}=this;if(!e.inline&&!this._nanopop.update({container:document.body.getBoundingClientRect(),position:e.position})){let e=this._root.app,t=e.getBoundingClientRect();e.style.top=(window.innerHeight-t.height)/2+`px`,e.style.left=(window.innerWidth-t.width)/2+`px`}}_updateOutput(e){let{_root:t,_color:n,options:r}=this;if(t.interaction.type()){let e=`to${t.interaction.type().getAttribute(`data-type`)}`;t.interaction.result.value=typeof n[e]==`function`?n[e]().toString(r.outputPrecision):``}!this._initializingActive&&this._recalc&&this._emit(`change`,n,e,this)}_clearColor(e=!1){let{_root:t,options:n}=this;n.useAsButton||t.button.style.setProperty(`--pcr-color`,`rgba(0, 0, 0, 0.15)`),t.button.classList.add(`clear`),n.showAlways||this.hide(),this._lastColor=null,this._initializingActive||e||(this._emit(`save`,null),this._emit(`clear`))}_parseLocalColor(e){let{values:t,type:n,a:r}=x(e),{lockOpacity:i}=this.options,a=r!==void 0&&r!==1;return t&&t.length===3&&(t[3]=void 0),{values:!t||i&&a?null:t,type:n}}_t(e){return this.options.i18n[e]||O.I18N_DEFAULTS[e]}_emit(e,...t){this._eventListener[e].forEach((e=>e(...t,this)))}on(e,t){return this._eventListener[e].push(t),this}off(e,t){let n=this._eventListener[e]||[],r=n.indexOf(t);return~r&&n.splice(r,1),this}addSwatch(e){let{values:t}=this._parseLocalColor(e);if(t){let{_swatchColors:e,_root:n}=this,r=S(...t),a=o(`<button type="button" style="--pcr-color: ${r.toRGBA().toString(0)}" aria-label="${this._t(`btn:swatch`)}"/>`);return n.swatches.appendChild(a),e.push({el:a,color:r}),this._eventBindings.push(i(a,`click`,(()=>{this.setHSVA(...r.toHSVA(),!0),this._emit(`swatchselect`,r),this._emit(`change`,r,`swatch`,this)}))),!0}return!1}removeSwatch(e){let t=this._swatchColors[e];if(t){let{el:n}=t;return this._root.swatches.removeChild(n),this._swatchColors.splice(e,1),!0}return!1}applyColor(e=!1){let{preview:t,button:n}=this._root,r=this._color.toRGBA().toString(0);return t.lastColor.style.setProperty(`--pcr-color`,r),this.options.useAsButton||n.style.setProperty(`--pcr-color`,r),n.classList.remove(`clear`),this._lastColor=this._color.clone(),this._initializingActive||e||this._emit(`save`,this._color),this}destroy(){cancelAnimationFrame(this._setupAnimationFrame),this._eventBindings.forEach((e=>a(...e))),Object.keys(this._components).forEach((e=>this._components[e].destroy()))}destroyAndRemove(){this.destroy();let{root:e,app:t}=this._root;e.parentElement&&e.parentElement.removeChild(e),t.parentElement.removeChild(t),Object.keys(this).forEach((e=>this[e]=null))}hide(){return!!this.isOpen()&&(this._root.app.classList.remove(`visible`),this._emit(`hide`),!0)}show(){return!this.options.disabled&&!this.isOpen()&&(this._root.app.classList.add(`visible`),this._rePositioningPicker(),this._emit(`show`,this._color),this)}isOpen(){return this._root.app.classList.contains(`visible`)}setHSVA(e=360,t=0,n=0,r=1,i=!1){let a=this._recalc;if(this._recalc=!1,e<0||e>360||t<0||t>100||n<0||n>100||r<0||r>1)return!1;this._color=S(e,t,n,r);let{hue:o,opacity:s,palette:c}=this._components;return o.update(e/360),s.update(r),c.update(t/100,1-n/100),i||this.applyColor(),a&&this._updateOutput(),this._recalc=a,!0}setColor(e,t=!1){if(e===null)return this._clearColor(t),!0;let{values:n,type:r}=this._parseLocalColor(e);if(n){let e=r.toUpperCase(),{options:i}=this._root.interaction,a=i.find((t=>t.getAttribute(`data-type`)===e));if(a&&!a.hidden)for(let e of i)e.classList[e===a?`add`:`remove`](`active`);return!!this.setHSVA(...n,t)&&this.setColorRepresentation(e)}return!1}setColorRepresentation(e){return e=e.toUpperCase(),!!this._root.interaction.options.find((t=>t.getAttribute(`data-type`).startsWith(e)&&!t.click()))}getColorRepresentation(){return this._representation}getColor(){return this._color}getSelectedColor(){return this._lastColor}getRoot(){return this._root}disable(){return this.hide(),this.options.disabled=!0,this._root.button.classList.add(`disabled`),this}enable(){return this.options.disabled=!1,this._root.button.classList.remove(`disabled`),this}}return t=t.default})()))}));export default t();