@thednp/color-picker 0.0.1-alpha2 → 0.0.2-alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. package/README.md +32 -15
  2. package/dist/css/color-picker.css +38 -15
  3. package/dist/css/color-picker.min.css +2 -2
  4. package/dist/css/color-picker.rtl.css +38 -15
  5. package/dist/css/color-picker.rtl.min.css +2 -2
  6. package/dist/js/color-esm.js +1178 -0
  7. package/dist/js/color-esm.min.js +2 -0
  8. package/dist/js/color-palette-esm.js +1252 -0
  9. package/dist/js/color-palette-esm.min.js +2 -0
  10. package/dist/js/color-palette.js +1260 -0
  11. package/dist/js/color-palette.min.js +2 -0
  12. package/dist/js/color-picker-element-esm.js +433 -424
  13. package/dist/js/color-picker-element-esm.min.js +2 -2
  14. package/dist/js/color-picker-element.js +435 -426
  15. package/dist/js/color-picker-element.min.js +2 -2
  16. package/dist/js/color-picker-esm.js +745 -739
  17. package/dist/js/color-picker-esm.min.js +2 -2
  18. package/dist/js/color-picker.js +747 -741
  19. package/dist/js/color-picker.min.js +2 -2
  20. package/dist/js/color.js +1186 -0
  21. package/dist/js/color.min.js +2 -0
  22. package/package.json +19 -3
  23. package/src/js/color-palette.js +28 -12
  24. package/src/js/color-picker-element.js +8 -4
  25. package/src/js/color-picker.js +84 -172
  26. package/src/js/color.js +125 -131
  27. package/src/js/util/getColorControls.js +3 -3
  28. package/src/js/util/getColorForm.js +0 -1
  29. package/src/js/util/getColorMenu.js +31 -33
  30. package/src/js/util/roundPart.js +9 -0
  31. package/src/js/util/setCSSProperties.js +12 -0
  32. package/src/js/util/setMarkup.js +122 -0
  33. package/src/js/util/tabindex.js +3 -0
  34. package/src/js/util/version.js +6 -0
  35. package/src/scss/color-picker.scss +35 -16
  36. package/types/cp.d.ts +48 -20
  37. package/src/js/util/templates.js +0 -10
@@ -1,2 +1,2 @@
1
- // ColorPicker v0.0.1alpha2 | thednp © 2022 | MIT-License
2
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).ColorPicker=e()}(this,(function(){"use strict";const t={};function e(e){const o=this,{type:r}=e;(t[r]?[...t[r]]:[]).forEach(t=>{const[a,s]=t;[...s].forEach(t=>{if(a===o){const[o,s]=t;o.apply(a,[e]),s&&s.once&&n(a,r,o,s)}})})}const o=(o,n,r,a)=>{t[n]||(t[n]=new Map);const s=t[n];s.has(o)||s.set(o,new Map);const i=s.get(o),{size:l}=i;i&&i.set(r,a),l||o.addEventListener(n,e,a)},n=(o,n,r,a)=>{const s=t[n],i=s&&s.get(o),l=i&&i.get(r),{options:c}=void 0!==l?l:{options:a};i&&i.has(r)&&i.delete(r),!s||i&&i.size||s.delete(o),s&&s.size||delete t[n],i&&i.size||o.removeEventListener(n,e,c)},r="ArrowDown",a="ArrowUp",s="ArrowLeft",i="ArrowRight",l="Enter",c="Space",{userAgentData:u}=navigator,h=u,{userAgent:g}=navigator,p=g,d=/iPhone|iPad|iPod|Android/i;let b=!1;b=h?h.brands.some(t=>d.test(t.brand)):d.test(p);const f=b;function m(t){return t instanceof HTMLElement?t.ownerDocument:t instanceof Window?t.document:window.document}function w(t,e){const o=getComputedStyle(t);return e in o?o[e]:""}let v=0,x=0;const $=new Map;function y(t,e){const{width:o,height:n,top:r,right:a,bottom:s,left:i}=t.getBoundingClientRect();let l=1,c=1;if(e&&t instanceof HTMLElement){const{offsetWidth:e,offsetHeight:r}=t;l=e>0&&Math.round(o)/e||1,c=r>0&&Math.round(n)/r||1}return{width:o/l,height:n/c,top:r/c,right:a/l,bottom:s/c,left:i/l,x:i/l,y:r/c}}const k=[Document,Element,HTMLElement],M=[Element,HTMLElement];function S(t,e){const o=k.some(t=>e instanceof t)?e:m();return M.some(e=>t instanceof e)?t:o.querySelector(t)}function A(t,e){return(e&&k.some(t=>e instanceof t)?e:m()).getElementsByClassName(t)}const H=(t,e)=>Object.assign(t,e);function L(t){if("string"==typeof t)return m().createElement(t);const{tagName:e}=t,o={...t},n=L(e);return delete o.tagName,H(n,o),n}function N(t,e){if("string"==typeof e)return m().createElementNS(t,e);const{tagName:o}=e,n={...e},r=N(t,o);return delete n.tagName,H(r,n),r}const E=new Map,P={set:(t,e,o)=>{const n=S(t);if(!n)return;E.has(e)||E.set(e,new Map);E.get(e).set(n,o)},getAllFor:t=>E.get(t)||null,get:(t,e)=>{const o=S(t),n=P.getAllFor(e);return o&&n&&n.get(o)||null},remove:(t,e)=>{const o=S(t),n=E.get(e);n&&o&&(n.delete(o),0===n.size&&E.delete(e))}},C=(t,e)=>{H(t.style,e)},T=(t,e)=>t.getAttribute(e);function R(t){return"true"===t||"false"!==t&&(Number.isNaN(+t)?""===t||"null"===t?null:t:+t)}const F=t=>Object.keys(t);const D=t=>t.focus();function O(t,e){return t.classList.contains(e)}function K(t,e){t.classList.add(e)}function I(t,e){t.classList.remove(e)}const V=(t,e,o)=>t.setAttribute(e,o),U=(t,e)=>t.removeAttribute(e),B={pickerLabel:"Colour Picker",appearanceLabel:"Colour Appearance",valueLabel:"Colour Value",toggleLabel:"Select Colour",presetsLabel:"Colour Presets",defaultsLabel:"Colour Defaults",formatLabel:"Format",alphaLabel:"Alpha",hexLabel:"Hexadecimal",hueLabel:"Hue",whitenessLabel:"Whiteness",blacknessLabel:"Blackness",saturationLabel:"Saturation",lightnessLabel:"Lightness",redLabel:"Red",greenLabel:"Green",blueLabel:"Blue"},_=["white","black","grey","red","orange","brown","gold","olive","yellow","lime","green","teal","cyan","blue","violet","magenta","pink"],j=["transparent","currentColor","inherit","revert","initial"];const W=["rgb","hex","hsl","hsb","hwb"],z="deg|rad|grad|turn",G=`[-\\+]?\\d*\\.?\\d+(?:${z})?`,X="(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)",Y=`(?:${X})|(?:${G})`,q=`[\\s|\\(]+(${Y})[,|\\s]+(${X})[,|\\s]+(${X})[,|\\s|\\/\\s]*(${X})?\\s*\\)?`,J={CSS_UNIT:new RegExp(Y),hwb:new RegExp("hwb"+q),rgb:new RegExp("rgb(?:a)?"+q),hsl:new RegExp("hsl(?:a)?"+q),hsv:new RegExp("hsv(?:a)?"+q),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/};function Z(t){return(""+t).includes(".")&&1===parseFloat(t)}function Q(t){return(""+t).includes("%")}function tt(t){return Boolean(J.CSS_UNIT.exec(String(t)))}function et(t,e){let o=t;return Z(o)&&(o="100%"),o=360===e?o:Math.min(e,Math.max(0,parseFloat(o))),function(t){return z.split("|").some(e=>(""+t).includes(e))}(t)&&(o=t.replace(new RegExp(z),"")),Q(o)&&(o=parseInt(String(o*e),10)/100),Math.abs(o-e)<1e-6?1:(o=360===e?(o<0?o%e+e:o%e)/parseFloat(String(e)):o%e/parseFloat(String(e)),o)}function ot(t){let e=parseFloat(""+t);return(Number.isNaN(e)||e<0||e>1)&&(e=1),e}function nt(t){return Math.min(1,Math.max(0,t))}function rt(t){const e=m(o).head;var o;C(e,{color:t});const n=w(e,"color");return C(e,{color:""}),n}function at(t){return Math.round(255*t).toString(16)}function st(t){return it(t)/255}function it(t){return parseInt(t,16)}function lt(t){return 1===t.length?"0"+t:String(t)}function ct(t,e,o){const n=t/255,r=e/255,a=o/255,s=Math.max(n,r,a),i=Math.min(n,r,a);let l=0,c=0;const u=(s+i)/2;if(s===i)c=0,l=0;else{const t=s-i;switch(c=u>.5?t/(2-s-i):t/(s+i),s){case n:l=(r-a)/t+(r<a?6:0);break;case r:l=(a-n)/t+2;break;case a:l=(n-r)/t+4}l/=6}return{h:l,s:c,l:u}}function ut(t,e,o){let n=o;return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*n*(e-t):n<.5?e:n<2/3?t+(e-t)*(2/3-n)*6:t}function ht(t,e,o){const n=t/255,r=e/255,a=o/255;let s=0,i=0;const l=Math.min(n,r,a),c=Math.max(n,r,a),u=1-c;if(c===l)return{h:0,w:l,b:u};n===l?(s=r-a,i=3):(s=r===l?a-n:n-r,i=r===l?5:1);const h=(i-s/(c-l))/6;return{h:1===h?0:h,w:l,b:u}}function gt(t,e,o){if(e+o>=1){const t=e/(e+o)*255;return{r:t,g:t,b:t}}let{r:n,g:r,b:a}=pt(t,1,.5);return[n,r,a]=[n,r,a].map(t=>t/255*(1-e-o)+e).map(t=>255*t),{r:n,g:r,b:a}}function pt(t,e,o){let n=0,r=0,a=0;if(0===e)r=o,a=o,n=o;else{const s=o<.5?o*(1+e):o+e-o*e,i=2*o-s;n=ut(i,s,t+1/3),r=ut(i,s,t),a=ut(i,s,t-1/3)}return[n,r,a]=[n,r,a].map(t=>255*t),{r:n,g:r,b:a}}function dt(t,e,o){const n=t/255,r=e/255,a=o/255,s=Math.max(n,r,a),i=Math.min(n,r,a);let l=0;const c=s,u=s-i,h=0===s?0:u/s;if(s===i)l=0;else{switch(s){case n:l=(r-a)/u+(r<a?6:0);break;case r:l=(a-n)/u+2;break;case a:l=(n-r)/u+4}l/=6}return{h:l,s:h,v:c}}function bt(t,e,o){const n=6*t,r=e,a=o,s=Math.floor(n),i=n-s,l=a*(1-r),c=a*(1-i*r),u=a*(1-(1-i)*r),h=s%6;return{r:255*[a,c,l,l,u,a][h],g:255*[u,a,a,c,l,l][h],b:255*[l,l,u,a,a,c][h]}}function ft(t,e,o,n){const r=[lt(Math.round(t).toString(16)),lt(Math.round(e).toString(16)),lt(Math.round(o).toString(16))];return n&&r[0].charAt(0)===r[0].charAt(1)&&r[1].charAt(0)===r[1].charAt(1)&&r[2].charAt(0)===r[2].charAt(1)?r[0].charAt(0)+r[1].charAt(0)+r[2].charAt(0):r.join("")}function mt(t,e,o,n,r){const a=[lt(Math.round(t).toString(16)),lt(Math.round(e).toString(16)),lt(Math.round(o).toString(16)),lt(at(n))];return r&&a[0].charAt(0)===a[0].charAt(1)&&a[1].charAt(0)===a[1].charAt(1)&&a[2].charAt(0)===a[2].charAt(1)&&a[3].charAt(0)===a[3].charAt(1)?a[0].charAt(0)+a[1].charAt(0)+a[2].charAt(0)+a[3].charAt(0):a.join("")}function wt(t){return{r:t>>16,g:(65280&t)>>8,b:255&t}}function vt(t){let e=t.trim().toLowerCase();if(0===e.length)return{r:0,g:0,b:0,a:0};let o=!1;if(function(t){return!["#",...W].some(e=>t.includes(e))&&!/[0-9]/.test(t)}(e))e=rt(e),o=!0;else if(j.includes(e)){const t="transparent"===e,o=t?0:255;return{r:o,g:o,b:o,a:t?0:1,format:"rgb"}}let[,n,r,a,s]=J.rgb.exec(e)||[];return n&&r&&a?{r:n,g:r,b:a,a:void 0!==s?s:1,format:"rgb"}:([,n,r,a,s]=J.hsl.exec(e)||[],n&&r&&a?{h:n,s:r,l:a,a:void 0!==s?s:1,format:"hsl"}:([,n,r,a,s]=J.hsv.exec(e)||[],n&&r&&a?{h:n,s:r,v:a,a:void 0!==s?s:1,format:"hsv"}:([,n,r,a,s]=J.hwb.exec(e)||[],n&&r&&a?{h:n,w:r,b:a,a:void 0!==s?s:1,format:"hwb"}:([,n,r,a,s]=J.hex8.exec(e)||[],n&&r&&a&&s?{r:it(n),g:it(r),b:it(a),a:st(s),format:o?"rgb":"hex"}:([,n,r,a]=J.hex6.exec(e)||[],n&&r&&a?{r:it(n),g:it(r),b:it(a),format:o?"rgb":"hex"}:([,n,r,a,s]=J.hex4.exec(e)||[],n&&r&&a&&s?{r:it(n+n),g:it(r+r),b:it(a+a),a:st(s+s),format:o?"rgb":"hex"}:([,n,r,a]=J.hex3.exec(e)||[],!!(n&&r&&a)&&{r:it(n+n),g:it(r+r),b:it(a+a),format:o?"rgb":"hex"})))))))}function xt(t){let e={r:0,g:0,b:0},o=t,n=1,r=null,a=null,s=null,i=null,l=null,c=null,u=!1,h="hex";return"string"==typeof t&&(o=vt(t),o&&(u=!0)),"object"==typeof o&&(tt(o.r)&&tt(o.g)&&tt(o.b)?(e={r:o.r,g:o.g,b:o.b},u=!0,h="rgb"):tt(o.h)&&tt(o.s)&&tt(o.v)?(({h:c,s:r,v:a}=o),c="number"==typeof c?c:et(c,360),r="number"==typeof r?r:et(r,100),a="number"==typeof a?a:et(a,100),e=bt(c,r,a),u=!0,h="hsv"):tt(o.h)&&tt(o.s)&&tt(o.l)?(({h:c,s:r,l:s}=o),c="number"==typeof c?c:et(c,360),r="number"==typeof r?r:et(r,100),s="number"==typeof s?s:et(s,100),e=pt(c,r,s),u=!0,h="hsl"):tt(o.h)&&tt(o.w)&&tt(o.b)&&(({h:c,w:i,b:l}=o),c="number"==typeof c?c:et(c,360),i="number"==typeof i?i:et(i,100),l="number"==typeof l?l:et(l,100),e=gt(c,i,l),u=!0,h="hwb"),tt(o.a)&&(n=o.a,n=Q(""+n)?et(n,100):n)),{ok:u,format:o.format||h,r:Math.min(255,Math.max(e.r,0)),g:Math.min(255,Math.max(e.g,0)),b:Math.min(255,Math.max(e.b,0)),a:ot(n)}}class $t{constructor(t,e){let o=t;const n=e&&W.includes(e)?e:"rgb";o instanceof $t&&(o=xt(o)),"number"==typeof o&&(o=wt(o));const{r:r,g:a,b:s,a:i,ok:l,format:c}=xt(o);this.originalInput=o,this.r=r,this.g=a,this.b=s,this.a=i,this.ok=l,this.format=n||c,r<1&&(this.r=Math.round(r)),a<1&&(this.g=Math.round(a)),s<1&&(this.b=Math.round(s))}get isValid(){return this.ok}get isDark(){return this.brightness<128}get luminance(){const{r:t,g:e,b:o}=this;let n=0,r=0,a=0;const s=t/255,i=e/255,l=o/255;return n=s<=.03928?s/12.92:((s+.055)/1.055)**2.4,r=i<=.03928?i/12.92:((i+.055)/1.055)**2.4,a=l<=.03928?l/12.92:((l+.055)/1.055)**2.4,.2126*n+.7152*r+.0722*a}get brightness(){const{r:t,g:e,b:o}=this;return(299*t+587*e+114*o)/1e3}toRgb(){const{r:t,g:e,b:o,a:n}=this,[r,a,s]=[t,e,o].map(t=>Math.round(t));return{r:r,g:a,b:s,a:Math.round(100*n)/100}}toRgbString(){const{r:t,g:e,b:o,a:n}=this.toRgb();return 1===n?`rgb(${t}, ${e}, ${o})`:`rgba(${t}, ${e}, ${o}, ${n})`}toRgbCSS4String(){const{r:t,g:e,b:o,a:n}=this.toRgb();return`rgb(${t} ${e} ${o}${1===n?"":` / ${Math.round(100*n)}%`})`}toHex(t){const{r:e,g:o,b:n,a:r}=this.toRgb();return 1===r?ft(e,o,n,t):mt(e,o,n,r,t)}toHexString(t){return"#"+this.toHex(t)}toHex8(t){const{r:e,g:o,b:n,a:r}=this.toRgb();return mt(e,o,n,r,t)}toHex8String(t){return"#"+this.toHex8(t)}toHsv(){const{r:t,g:e,b:o,a:n}=this.toRgb(),{h:r,s:a,v:s}=dt(t,e,o);return{h:r,s:a,v:s,a:n}}toHsl(){const{r:t,g:e,b:o,a:n}=this.toRgb(),{h:r,s:a,l:s}=ct(t,e,o);return{h:r,s:a,l:s,a:n}}toHslString(){let{h:t,s:e,l:o,a:n}=this.toHsl();return t=Math.round(360*t),e=Math.round(100*e),o=Math.round(100*o),n=Math.round(100*n)/100,1===n?`hsl(${t}, ${e}%, ${o}%)`:`hsla(${t}, ${e}%, ${o}%, ${n})`}toHslCSS4String(){let{h:t,s:e,l:o,a:n}=this.toHsl();t=Math.round(360*t),e=Math.round(100*e),o=Math.round(100*o),n=Math.round(100*n);return`hsl(${t}deg ${e}% ${o}%${n<100?` / ${Math.round(n)}%`:""})`}toHwb(){const{r:t,g:e,b:o,a:n}=this,{h:r,w:a,b:s}=ht(t,e,o);return{h:r,w:a,b:s,a:n}}toHwbString(){let{h:t,w:e,b:o,a:n}=this.toHwb();t=Math.round(360*t),e=Math.round(100*e),o=Math.round(100*o),n=Math.round(100*n);return`hwb(${t}deg ${e}% ${o}%${n<100?` / ${Math.round(n)}%`:""})`}setAlpha(t){return this.a=ot(t),this}saturate(t){if("number"!=typeof t)return this;const{h:e,s:o,l:n}=this.toHsl(),{r:r,g:a,b:s}=pt(e,nt(o+t/100),n);return H(this,{r:r,g:a,b:s}),this}desaturate(t){return"number"==typeof t?this.saturate(-t):this}greyscale(){return this.saturate(-100)}lighten(t){if("number"!=typeof t)return this;const{h:e,s:o,l:n}=this.toHsl(),{r:r,g:a,b:s}=pt(e,o,nt(n+t/100));return H(this,{r:r,g:a,b:s}),this}darken(t){return"number"==typeof t?this.lighten(-t):this}spin(t){if("number"!=typeof t)return this;const{h:e,s:o,l:n}=this.toHsl(),{r:r,g:a,b:s}=pt(nt((360*e+t)%360/360),o,n);return H(this,{r:r,g:a,b:s}),this}clone(){return new $t(this)}toString(t){const{format:e}=this;return"hex"===e?this.toHexString(t):"hsl"===e?this.toHslString():"hwb"===e?this.toHwbString():this.toRgbString()}}H($t,{ANGLES:z,CSS_ANGLE:G,CSS_INTEGER:"[-\\+]?\\d+%?",CSS_NUMBER:"[-\\+]?\\d*\\.\\d+%?",CSS_UNIT:X,CSS_UNIT2:Y,PERMISSIVE_MATCH:q,matchers:J,isOnePointZero:Z,isPercentage:Q,isValidCSSUnit:tt,pad2:lt,clamp01:nt,bound01:et,boundAlpha:ot,getRGBFromName:rt,convertHexToDecimal:st,convertDecimalToHex:at,rgbToHsl:ct,rgbToHex:ft,rgbToHsv:dt,rgbToHwb:ht,rgbaToHex:mt,hslToRgb:pt,hsvToRgb:bt,hueToRgb:ut,hwbToRgb:gt,parseIntFromHex:it,numberInputToObject:wt,stringInputToObject:vt,inputToRGB:xt,ObjectAssign:H});class yt{constructor(...t){let e=0,o=12,n=10,r=[.5];if(3===t.length)[e,o,n]=t;else{if(2!==t.length)throw TypeError("The ColorPalette requires minimum 2 arguments");[o,n]=t}const a=[],s=360/o,i=100/(n+(n%2?0:1))/100,l=Math.round((n-(n%2?1:0))/2);for(let t=0;t<l;t+=1)r=[...r,.5+i*(t+1)];for(let t=0;t<n-l-1;t+=1)r=[.5-i*(t+1),...r];for(let t=0;t<o;t+=1){const o=(e+t*s)%360/360;r.forEach(t=>{a.push(new $t({h:o,s:1,l:t}).toHexString())})}this.hue=e,this.hueSteps=o,this.lightSteps=n,this.colors=a}}function kt(t,e,o){const{input:n,format:r,componentLabels:a}=t,{defaultsLabel:s,presetsLabel:i}=a,l="color-options"===o,c=e instanceof yt,u=l?i:s;let h=c?e.colors:e;h=h instanceof Array?h:[];const g=h.length,{lightSteps:p}=c?e:{lightSteps:null};let d=p||Math.max(...[5,6,7,8,9,10].filter(t=>g>2*t&&!(g%t)));d=Number.isFinite(d)?d:5;const b=l&&g>d;let f=1;f=b&&g<27?2:f,f=g>=27?3:f,f=g>=36?4:f,f=g>=45?5:f;const m=b&&g>f*d;let w=o;w+=m?" scrollable":"",w+=b?" multiline":"";const v=b?"1px":"0.25rem";let x=b?1.75:2;x=g%10||!b?x:1.5;const $=(f-(g<27?1:2)||1)*x+"rem",y=`calc(${f} * ${x}rem + ${f-1} * ${v})`,k=`repeat(${d}, ${x}rem)`,M=`repeat(auto-fill, ${x}rem)`,S=L({tagName:"ul",className:w});if(V(S,"role","listbox"),V(S,"aria-label",""+u),l){if(m){const t="this.style.height=";V(S,"onmouseout",`${t}'${$}'`),V(S,"onmouseover",`${t}'${y}'`)}C(S,{height:m?$:"",gridTemplateColumns:k,gridTemplateRows:M,gap:v})}return h.forEach(t=>{const[e,o]=t.trim().split(":"),a=new $t(e,r).toString()===T(n,"value"),s=L({tagName:"li",className:"color-option"+(a?" active":""),innerText:""+(o||t)});V(s,"tabindex","0"),V(s,"data-value",""+e),V(s,"role","option"),V(s,"aria-selected",a?"true":"false"),l&&C(s,{width:x+"rem",height:x+"rem",backgroundColor:t}),S.append(s)}),S}function Mt(t){try{JSON.parse(t)}catch(t){return!1}return!0}const St={componentLabels:B,colorLabels:_,format:"rgb",colorPresets:void 0,colorKeywords:j};function At(t){const{input:e,parent:o,format:n,id:r,componentLabels:a,colorKeywords:s,colorPresets:i}=t,l=T(e,"value")||"#fff",{toggleLabel:c,pickerLabel:u,formatLabel:h,hexLabel:g}=a,p=j.includes(l)?"#fff":l;t.color=new $t(p,n);const d=f?" mobile":"",b="hex"===n?g:n.toUpperCase(),m=L({id:"picker-btn-"+r,tagName:"button",className:"picker-toggle btn-appearance"});V(m,"aria-expanded","false"),V(m,"aria-haspopup","true"),m.append(L({tagName:"span",className:"v-hidden",innerText:`${u}. ${h}: ${b}`}));const w=L({tagName:"div",className:"color-dropdown picker"+d});V(w,"aria-labelledby","picker-btn-"+r),V(w,"role","group");const v=function(t){const{format:e,componentLabels:o}=t,{hueLabel:n,alphaLabel:r,lightnessLabel:a,saturationLabel:s,whitenessLabel:i,blacknessLabel:l}=o,c="hsl"===e?360:100,u="hsl"===e?100:360;let h="hsl"===e?`${n} & ${a}`:`${a} & ${s}`;h="hwb"===e?`${i} & ${l}`:h;const g="hsl"===e?""+s:""+n,p=L({tagName:"div",className:"color-controls "+e});return[{i:1,c:"color-pointer",l:h,min:0,max:c},{i:2,c:"color-slider",l:g,min:0,max:u},{i:3,c:"color-slider",l:r,min:0,max:100}].forEach(t=>{const{i:e,c:o,l:n,min:r,max:a}=t,s=L({tagName:"div",className:"color-control"});V(s,"role","presentation"),s.append(L({tagName:"div",className:"visual-control visual-control"+e}));const i=L({tagName:"div",className:o+" knob",ariaLive:"polite"});V(i,"aria-label",n),V(i,"role","slider"),V(i,"tabindex","0"),V(i,"aria-valuemin",""+r),V(i,"aria-valuemax",""+a),s.append(i),p.append(s)}),p}(t),x=function(t){const{format:e,id:o,componentLabels:n}=t,r=L({tagName:"div",className:"color-form "+e});let a=["hex"];return"rgb"===e?a=["red","green","blue","alpha"]:"hsl"===e?a=["hue","saturation","lightness","alpha"]:"hwb"===e&&(a=["hue","whiteness","blackness","alpha"]),a.forEach(t=>{const[a]="hex"===e?["#"]:(s=t,s.toUpperCase()).split("");var s;const i=`color_${e}_${t}_${o}`,l=n[t+"Label"],c=L({tagName:"label"});V(c,"for",i),c.append(L({tagName:"span",ariaHidden:"true",innerText:a+":"}),L({tagName:"span",className:"v-hidden",innerText:l}));const u=L({tagName:"input",id:i,type:"hex"===e?"text":"number",value:"alpha"===t?"100":"0",className:"color-input "+t});V(u,"autocomplete","off"),V(u,"spellcheck","false");let h="100",g="1";"alpha"!==t&&("rgb"===e?(h="255",g="1"):"hue"===t&&(h="360",g="1")),H(u,{min:"0",max:h,step:g}),r.append(c,u)}),r}(t);if(w.append(v,x),e.before(m),o.append(w),s||i){const e=L({tagName:"div",className:"color-dropdown scrollable menu"+d});if(i instanceof Array&&i.length||i instanceof yt&&i.colors){const o=kt(t,i,"color-options");e.append(o)}if(s&&s.length){const o=kt(t,s,"color-defaults");e.append(o)}const n=L({tagName:"button",className:"menu-toggle btn-appearance"});V(n,"tabindex","-1"),V(n,"aria-expanded","false"),V(n,"aria-haspopup","true");const r=encodeURI("http://www.w3.org/2000/svg"),a=N(r,{tagName:"svg"});V(a,"xmlns",r),V(a,"viewBox","0 0 512 512"),V(a,"aria-hidden","true");const l=N(r,{tagName:"path"});V(l,"d","M98,158l157,156L411,158l27,27L255,368L71,185L98,158z"),V(l,"fill","#fff"),a.append(l),n.append(L({tagName:"span",className:"v-hidden",innerText:""+c}),a),o.append(n,e)}s&&j.includes(l)&&(t.value=l),V(e,"tabindex","-1")}function Ht(t,e){const r=e?o:n,{input:a,pickerToggle:s,menuToggle:i}=t;r(a,"focusin",t.showPicker),r(s,"click",t.togglePicker),r(a,"keydown",t.keyToggle),i&&r(i,"click",t.toggleMenu)}function Lt(t,e){const r=e?o:n,{input:a,colorMenu:s,parent:i}=t,l=m(a),c=function(t){if(null==t)return window;if(!(t instanceof Window)){const{ownerDocument:e}=t;return e&&e.defaultView||window}return t}(a),u="ontouchstart"in l?{down:"touchstart",move:"touchmove",up:"touchend"}:{down:"mousedown",move:"mousemove",up:"mouseup"};r(t.controls,u.down,t.pointerDown),t.controlKnobs.forEach(e=>r(e,"keydown",t.handleKnobs)),r(c,"scroll",t.handleScroll),r(c,"resize",t.update),[a,...t.inputs].forEach(e=>r(e,"change",t.changeHandler)),s&&(r(s,"click",t.menuClickHandler),r(s,"keydown",t.menuKeyHandler)),r(l,u.move,t.pointerMove),r(l,u.up,t.pointerUp),r(i,"focusout",t.handleFocusOut),r(c,"keyup",t.handleDismiss)}function Nt(t){var e,o;e=t.input,o=new CustomEvent("colorpicker.change"),e.dispatchEvent(o)}function Et(t){t&&["bottom","top"].forEach(e=>I(t,e))}function Pt(t,e){const{colorPicker:o,colorMenu:n,menuToggle:r,pickerToggle:a,parent:s}=t,i=e===o,l=i?n:o,c=i?r:a,u=i?a:r;O(s,"open")||K(s,"open"),l&&(I(l,"show"),Et(l)),K(e,"bottom"),e.offsetHeight,K(e,"show"),i&&t.update(),t.show(),V(u,"aria-expanded","true"),c&&V(c,"aria-expanded","false")}class Ct{constructor(t,e){const o=this,n=S(t);if(!n)throw new TypeError(`ColorPicker target ${t} cannot be found.`);o.input=n;const r=function t(e,o){return e?e.closest(o)||t(e.getRootNode().host,o):null}(n,".color-picker,color-picker");if(!r)throw new TypeError("ColorPicker requires a specific markup to work.");o.parent=r,o.id=function t(e,o){let n=o?v:x;if(o){const r=t(e),a=$.get(r)||new Map;$.has(r)||$.set(r,a),a.has(o)?n=a.get(o):(a.set(o,n),v+=1)}else{const t=e.id||e;$.has(t)?n=$.get(t):($.set(t,n),x+=1)}return n}(n,"color-picker"),o.dragElement=null,o.isOpen=!1,o.controlPositions={c1x:0,c1y:0,c2y:0,c3y:0},o.colorLabels={},o.colorKeywords=void 0,o.colorPresets=void 0;const{format:a,componentLabels:s,colorLabels:i,colorKeywords:l,colorPresets:c}=function(t,e,o,n){const r={...t.dataset},a={},s={};return F(r).forEach(t=>{const e=n&&t.includes(n)?t.replace(n,"").replace(/[A-Z]/,t=>t.toLowerCase()):t;s[e]=R(r[t])}),F(o).forEach(t=>{o[t]=R(o[t])}),F(e).forEach(n=>{a[n]=n in o?o[n]:n in s?s[n]:"title"===n?T(t,"title"):e[n]}),a}(this.isCE?r:n,St,e||{});let u=_;i instanceof Array&&17===i.length?u=i:i&&17===i.split(",").length&&(u=i.split(",")),_.forEach((t,e)=>{o.colorLabels[t]=u[e].trim()});const h=H({},B),g=s&&Mt(s)?JSON.parse(s):s||{};if(o.componentLabels=H(h,g),o.color=new $t("white",a),o.format=a,l instanceof Array?o.colorKeywords=l:"string"==typeof l&&l.length&&(o.colorKeywords=l.split(",")),c instanceof Array)o.colorPresets=c;else if("string"==typeof c&&c.length)if(Mt(c)){const{hue:t,hueSteps:e,lightSteps:n}=JSON.parse(c);o.colorPresets=new yt(t,e,n)}else o.colorPresets=c.split(",").map(t=>t.trim());o.showPicker=o.showPicker.bind(o),o.togglePicker=o.togglePicker.bind(o),o.toggleMenu=o.toggleMenu.bind(o),o.menuClickHandler=o.menuClickHandler.bind(o),o.menuKeyHandler=o.menuKeyHandler.bind(o),o.pointerDown=o.pointerDown.bind(o),o.pointerMove=o.pointerMove.bind(o),o.pointerUp=o.pointerUp.bind(o),o.update=o.update.bind(o),o.handleScroll=o.handleScroll.bind(o),o.handleFocusOut=o.handleFocusOut.bind(o),o.changeHandler=o.changeHandler.bind(o),o.handleDismiss=o.handleDismiss.bind(o),o.keyToggle=o.keyToggle.bind(o),o.handleKnobs=o.handleKnobs.bind(o),At(o);const[p,d]=A("color-dropdown",r);o.pickerToggle=S(".picker-toggle",r),o.menuToggle=S(".menu-toggle",r),o.colorPicker=p,o.colorMenu=d,o.inputs=[...A("color-input",r)];const[b]=A("color-controls",r);o.controls=b,o.controlKnobs=[...A("knob",b)],o.visuals=[...A("visual-control",b)],o.update(),Ht(o,!0),P.set(n,"color-picker",o)}get value(){return this.input.value}set value(t){this.input.value=t}get includeNonColor(){return this.colorKeywords instanceof Array&&this.colorKeywords.some(t=>j.includes(t))}get isCE(){return"color-picker"===this.parent.localName}get hex(){return this.color.toHex(!0)}get hsv(){return this.color.toHsv()}get hsl(){return this.color.toHsl()}get hwb(){return this.color.toHwb()}get rgb(){return this.color.toRgb()}get brightness(){return this.color.brightness}get luminance(){return this.color.luminance}get isDark(){const{color:t,brightness:e}=this;return e<120&&t.a>.33}get isValid(){const t=this.input.value;return""!==t&&new $t(t).isValid}updateVisuals(){const{format:t,controlPositions:e,visuals:o}=this,[n,r,a]=o,{offsetWidth:s,offsetHeight:i}=n,l="hsl"===t?e.c1x/s:e.c2y/i,{r:c,g:u,b:h}=$t.hslToRgb(l,1,.5),g="linear-gradient(rgb(255,255,255) 0%, rgb(255,255,255) 100%)",p=1-e.c3y/i,d=Math.round(100*p)/100;if("hsl"!==t){const t=new $t({h:l,s:1,l:.5,a:p}).toRgbString(),e="linear-gradient(\n rgb(255,0,0) 0%, rgb(255,255,0) 16.67%,\n rgb(0,255,0) 33.33%, rgb(0,255,255) 50%,\n rgb(0,0,255) 66.67%, rgb(255,0,255) 83.33%,\n rgb(255,0,0) 100%)";C(n,{background:`linear-gradient(rgba(0,0,0,0) 0%, rgba(0,0,0,${d}) 100%),\n linear-gradient(to right, rgba(255,255,255,${d}) 0%, ${t} 100%),\n ${g}`}),C(r,{background:e})}else{const t=Math.round(e.c2y/i*100),o=new $t({r:255,g:0,b:0,a:p}).saturate(-t).toRgbString(),a=new $t({r:255,g:255,b:0,a:p}).saturate(-t).toRgbString(),s=new $t({r:0,g:255,b:0,a:p}).saturate(-t).toRgbString(),l=new $t({r:0,g:255,b:255,a:p}).saturate(-t).toRgbString(),b=new $t({r:0,g:0,b:255,a:p}).saturate(-t).toRgbString(),f=new $t({r:255,g:0,b:255,a:p}).saturate(-t).toRgbString(),m=new $t({r:255,g:0,b:0,a:p}).saturate(-t).toRgbString();C(n,{background:`${`linear-gradient(rgba(255,255,255,${d}) 0%, rgba(255,255,255,0) 50%),\n linear-gradient(rgba(0,0,0,0) 50%, rgba(0,0,0,${d}) 100%)`},${`linear-gradient(to right,\n ${o} 0%, ${a} 16.67%, ${s} 33.33%, ${l} 50%,\n ${b} 66.67%, ${f} 83.33%, ${m} 100%)`},${g}`});const{r:w,g:v,b:x}=new $t({r:c,g:u,b:h}).greyscale().toRgb();C(r,{background:`linear-gradient(rgb(${c},${u},${h}) 0%, rgb(${w},${v},${x}) 100%)`})}C(a,{background:`linear-gradient(rgba(${c},${u},${h},1) 0%,rgba(${c},${u},${h},0) 100%)`})}handleFocusOut({relatedTarget:t}){t&&!this.parent.contains(t)&&this.hide(!0)}handleDismiss({code:t}){const e=this;e.isOpen&&"Escape"===t&&e.hide()}handleScroll(t){const{activeElement:e}=m(this.input);(f&&this.dragElement||e&&this.controlKnobs.includes(e))&&(t.stopPropagation(),t.preventDefault()),this.updateDropdownPosition()}menuKeyHandler(t){const{target:e,code:o}=t,{previousElementSibling:n,nextElementSibling:u,parentElement:h}=e,g=h&&O(h,"color-options"),p=[...h.children],d=g&&w(h,"grid-template-columns").split(" ").length,b=p.indexOf(e),f=b>-1&&d&&p[b-d],m=b>-1&&d&&p[b+d];[r,a,c].includes(o)&&t.preventDefault(),g?f&&o===a?D(f):m&&o===r?D(m):n&&o===s?D(n):u&&o===i&&D(u):n&&[s,a].includes(o)?D(n):u&&[i,r].includes(o)&&D(u),[l,c].includes(o)&&this.menuClickHandler({target:e})}menuClickHandler(t){const e=this,{target:o}=t,{colorMenu:n}=e,r=(T(o,"data-value")||"").trim();if(!r.length)return;const a=S("li.active",n);let s=j.includes(r)?"white":r;s="transparent"===r?"rgba(0,0,0,0)":r;const{r:i,g:l,b:c,a:u}=new $t(s);H(e.color,{r:i,g:l,b:c,a:u}),e.update(),a&&(I(a,"active"),U(a,"aria-selected")),a!==o&&(K(o,"active"),V(o,"aria-selected","true"),j.includes(r)&&(e.value=r),Nt(e))}pointerDown(t){const e=this,{type:o,target:n,touches:r,pageX:a,pageY:s}=t,{colorMenu:i,visuals:l,controlKnobs:c}=e,[u,h,g]=l,[p,d,b]=c,f=O(n,"visual-control")?n:S(".visual-control",n.parentElement),m=y(f),w="touchstart"===o?r[0].pageX:a,v="touchstart"===o?r[0].pageY:s,x=w-window.pageXOffset-m.left,$=v-window.pageYOffset-m.top;if(n===u||n===p?(e.dragElement=f,e.changeControl1(x,$)):n===h||n===d?(e.dragElement=f,e.changeControl2($)):n!==g&&n!==b||(e.dragElement=f,e.changeAlpha($)),i){const t=S("li.active",i);t&&(I(t,"active"),U(t,"aria-selected"))}t.preventDefault()}pointerUp({target:t}){const e=this,{parent:o}=e,n=m(o),r=null!==S(".color-picker,color-picker.open",n),a=n.getSelection();e.dragElement||a.toString().length||o.contains(t)||e.hide(r),e.dragElement=null}pointerMove(t){const e=this,{dragElement:o,visuals:n}=e,[r,a,s]=n,{type:i,touches:l,pageX:c,pageY:u}=t;if(!o)return;const h=y(o),g="touchmove"===i?l[0].pageX:c,p="touchmove"===i?l[0].pageY:u,d=g-window.pageXOffset-h.left,b=p-window.pageYOffset-h.top;o===r&&e.changeControl1(d,b),o===a&&e.changeControl2(b),o===s&&e.changeAlpha(b)}handleKnobs(t){const{target:e,code:o}=t,n=this;if(![a,r,s,i].includes(o))return;t.preventDefault();const{controlKnobs:l}=n,[c,u,h]=l,{activeElement:g}=m(c);if(l.find(t=>t===g)){let l=0,g=0;e===c?([s,i].includes(o)?n.controlPositions.c1x+=o===i?1:-1:[a,r].includes(o)&&(n.controlPositions.c1y+=o===r?1:-1),l=n.controlPositions.c1x,g=n.controlPositions.c1y,n.changeControl1(l,g)):e===u?(n.controlPositions.c2y+=[r,i].includes(o)?1:-1,g=n.controlPositions.c2y,n.changeControl2(g)):e===h&&(n.controlPositions.c3y+=[r,i].includes(o)?1:-1,g=n.controlPositions.c3y,n.changeAlpha(g)),n.handleScroll(t)}}changeHandler(){const t=this;let e;const{inputs:o,format:n,value:r,input:a,controlPositions:s,visuals:i}=t,{activeElement:l}=m(a),{offsetHeight:c}=i[0],[u,,,h]=o,[g,p,d,b]="rgb"===n?o.map(t=>parseFloat(t.value)/(t===h?100:1)):o.map(t=>parseFloat(t.value)/(t!==u?100:360)),f=t.includeNonColor&&j.includes(r),w=h?b:1-s.c3y/c;if(l===a||l&&o.includes(l)){e=l===a?f?"white":r:"hex"===n?u.value:"hsl"===n?{h:g,s:p,l:d,a:w}:"hwb"===n?{h:g,w:p,b:d,a:w}:{r:g,g:p,b:d,a:w};const{r:o,g:s,b:i,a:c}=new $t(e);H(t.color,{r:o,g:s,b:i,a:c}),t.setControlPositions(),t.updateAppearance(),t.updateInputs(),t.updateControls(),t.updateVisuals(),l===a&&f&&(t.value=r)}}changeControl1(t,e){let[o,n]=[0,0];const{format:r,controlPositions:a,visuals:s}=this,{offsetHeight:i,offsetWidth:l}=s[0];t>l?o=l:t>=0&&(o=t),e>i?n=i:e>=0&&(n=e);const c="hsl"===r?o/l:a.c2y/i,u="hsl"===r?1-a.c2y/i:o/l,h=1-n/i,g=1-a.c3y/i,p="hsl"===r?{h:c,s:u,l:h,a:g}:{h:c,s:u,v:h,a:g},{r:d,g:b,b:f,a:m}=new $t(p);H(this.color,{r:d,g:b,b:f,a:m}),this.controlPositions.c1x=o,this.controlPositions.c1y=n,this.updateAppearance(),this.updateInputs(),this.updateControls(),this.updateVisuals()}changeControl2(t){const{format:e,controlPositions:o,visuals:n}=this,{offsetHeight:r,offsetWidth:a}=n[0];let s=0;t>r?s=r:t>=0&&(s=t);const i="hsl"===e?o.c1x/a:s/r,l="hsl"===e?1-s/r:o.c1x/a,c=1-o.c1y/r,u=1-o.c3y/r,h="hsl"===e?{h:i,s:l,l:c,a:u}:{h:i,s:l,v:c,a:u},{r:g,g:p,b:d,a:b}=new $t(h);H(this.color,{r:g,g:p,b:d,a:b}),this.controlPositions.c2y=s,this.updateAppearance(),this.updateInputs(),this.updateControls(),this.updateVisuals()}changeAlpha(t){const{visuals:e}=this,{offsetHeight:o}=e[0];let n=0;t>o?n=o:t>=0&&(n=t);const r=1-n/o;this.color.setAlpha(r),this.controlPositions.c3y=n,this.updateAppearance(),this.updateInputs(),this.updateControls(),this.updateVisuals()}update(){this.updateDropdownPosition(),this.updateAppearance(),this.setControlPositions(),this.updateInputs(!0),this.updateControls(),this.updateVisuals()}updateDropdownPosition(){const{input:t,colorPicker:e,colorMenu:o}=this,n=y(t),{top:r,bottom:a}=n,{offsetHeight:s}=t,i=(l=t,m(l).documentElement).clientHeight;var l;const c=O(e,"show")?e:o;if(!c)return;const{offsetHeight:u}=c,h=i-a,g=r,p=r+u+s>i,d=r-u<0;(O(c,"bottom")||!d)&&h<g&&p?(I(c,"bottom"),K(c,"top")):(I(c,"top"),K(c,"bottom"))}setControlPositions(){const{format:t,visuals:e,color:o,hsl:n,hsv:r}=this,{offsetHeight:a,offsetWidth:s}=e[0],i=o.a,l=n.h,c="hsl"!==t?r.s:n.s,u="hsl"!==t?r.v:n.l;this.controlPositions.c1x="hsl"!==t?c*s:l*s,this.controlPositions.c1y=(1-u)*a,this.controlPositions.c2y="hsl"!==t?l*a:(1-c)*a,this.controlPositions.c3y=(1-i)*a}updateAppearance(){const t=this,{componentLabels:e,colorLabels:o,color:n,parent:r,hsl:a,hsv:s,hex:i,format:l,controlKnobs:c}=t,{appearanceLabel:u,hexLabel:h,valueLabel:g}=e,{r:p,g:d,b:b}=n.toRgb(),[f,m,w]=c,v=Math.round(360*a.h),x=n.a,$="hsl"===l?a.s:s.s,y=Math.round(100*$),k=Math.round(100*a.l),M=100*s.v;let S;if(100===k&&0===y)S=o.white;else if(0===k)S=o.black;else if(0===y)S=o.grey;else if(v<15||v>=345)S=o.red;else if(v>=15&&v<45)S=M>80&&y>80?o.orange:o.brown;else if(v>=45&&v<75){const t=v>=54&&v<75&&M<80;S=v>46&&v<54&&M<80&&y>90?o.gold:o.yellow,S=t?o.olive:S}else v>=75&&v<155?S=M<68?o.green:o.lime:v>=155&&v<175?S=o.teal:v>=175&&v<195?S=o.cyan:v>=195&&v<255?S=o.blue:v>=255&&v<270?S=o.violet:v>=270&&v<295?S=o.magenta:v>=295&&v<345&&(S=o.pink);let A=`${h} ${i.split("").join(" ")}`;if("hsl"===l)A=`HSL: ${v}°, ${y}%, ${k}%`,V(f,"aria-description",`${g}: ${A}. ${u}: ${S}.`),V(f,"aria-valuetext",`${v}° & ${k}%`),V(f,"aria-valuenow",""+v),V(m,"aria-valuetext",y+"%"),V(m,"aria-valuenow",""+y);else if("hwb"===l){const{hwb:e}=t,o=Math.round(100*e.w),n=Math.round(100*e.b);A=`HWB: ${v}°, ${o}%, ${n}%`,V(f,"aria-description",`${g}: ${A}. ${u}: ${S}.`),V(f,"aria-valuetext",`${o}% & ${n}%`),V(f,"aria-valuenow",""+o),V(m,"aria-valuetext",v+"%"),V(m,"aria-valuenow",""+v)}else A="rgb"===l?`RGB: ${p}, ${d}, ${b}`:A,V(m,"aria-description",`${g}: ${A}. ${u}: ${S}.`),V(f,"aria-valuetext",`${k}% & ${y}%`),V(f,"aria-valuenow",""+k),V(m,"aria-valuetext",v+"°"),V(m,"aria-valuenow",""+v);const H=Math.round(100*x);V(w,"aria-valuetext",H+"%"),V(w,"aria-valuenow",""+H);const L=n.toString();C(t.input,{backgroundColor:L}),t.isDark?(O(r,"txt-light")&&I(r,"txt-light"),O(r,"txt-dark")||K(r,"txt-dark")):(O(r,"txt-dark")&&I(r,"txt-dark"),O(r,"txt-light")||K(r,"txt-light"))}updateControls(){const{controlKnobs:t,controlPositions:e}=this,[o,n,r]=t;C(o,{transform:`translate3d(${e.c1x-4}px,${e.c1y-4}px,0)`}),C(n,{transform:`translate3d(0,${e.c2y-4}px,0)`}),C(r,{transform:`translate3d(0,${e.c3y-4}px,0)`})}updateInputs(t){const e=this,{value:o,format:n,inputs:r,color:a,hsl:s}=e,[i,l,c,u]=r,h=Math.round(100*a.a),g=Math.round(360*s.h);let p;if("hex"===n)p=e.color.toHexString(!0),i.value=e.hex;else if("hsl"===n){const t=Math.round(100*s.l),o=Math.round(100*s.s);p=e.color.toHslString(),i.value=""+g,l.value=""+o,c.value=""+t,u.value=""+h}else if("hwb"===n){const{w:t,b:o}=e.hwb,n=Math.round(100*t),r=Math.round(100*o);p=e.color.toHwbString(),i.value=""+g,l.value=""+n,c.value=""+r,u.value=""+h}else if("rgb"===n){const{r:t,g:o,b:n}=e.rgb;p=e.color.toRgbString(),i.value=""+t,l.value=""+o,c.value=""+n,u.value=""+h}e.value=""+p,t||p===o||Nt(e)}keyToggle(t){const e=this,{menuToggle:o}=e,{activeElement:n}=m(o),{code:r}=t;[l,c].includes(r)&&(o&&n===o||!n)&&(t.preventDefault(),n?e.toggleMenu():e.togglePicker(t))}togglePicker(t){t.preventDefault();const e=this,{colorPicker:o}=e;e.isOpen&&O(o,"show")?e.hide(!0):Pt(e,o)}showPicker(){const t=this,{colorPicker:e}=t;O(e,"show")||Pt(t,e)}toggleMenu(){const t=this,{colorMenu:e}=t;t.isOpen&&O(e,"show")?t.hide(!0):Pt(t,e)}show(){const t=this,{menuToggle:e}=t;t.isOpen||(Lt(t,!0),t.updateDropdownPosition(),t.isOpen=!0,V(t.input,"tabindex","0"),e&&V(e,"tabindex","0"))}hide(t){const e=this;if(e.isOpen){const{pickerToggle:o,menuToggle:n,colorPicker:r,colorMenu:a,parent:s,input:i}=e,l=O(r,"show"),c=l?r:a,u=l?o:n,h=c&&function(t){const e=w(t,"transitionProperty"),o=w(t,"transitionDuration"),n=o.includes("ms")?1:1e3,r=e&&"none"!==e?parseFloat(o)*n:0;return Number.isNaN(r)?0:r}(c);c&&(I(c,"show"),V(u,"aria-expanded","false"),setTimeout(()=>{Et(c),S(".show",s)||(I(s,"open"),Lt(e),e.isOpen=!1)},h)),e.isValid||(e.value=e.color.toString()),t||D(o),V(i,"tabindex","-1"),n&&V(n,"tabindex","-1")}}dispose(){const{input:t,parent:e}=this;this.hide(!0),Ht(this),[...e.children].forEach(e=>{e!==t&&e.remove()}),C(t,{backgroundColor:""}),["txt-light","txt-dark"].forEach(t=>I(e,t)),P.remove(t,"color-picker")}}return H(Ct,{Color:$t,Version:"0.0.1alpha2",getInstance:t=>{return e=t,o="color-picker",P.get(e,o);var e,o},init:t=>new Ct(t),selector:'[data-function="color-picker"]'}),Ct}));
1
+ // ColorPicker v0.0.2alpha1 | thednp © 2022 | MIT-License
2
+ !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).ColorPicker=e()}(this,(function(){"use strict";const t={};function e(e){const o=this,{type:r}=e;(t[r]?[...t[r]]:[]).forEach(t=>{const[s,a]=t;[...a].forEach(t=>{if(s===o){const[o,a]=t;o.apply(s,[e]),a&&a.once&&n(s,r,o,a)}})})}const o=(o,n,r,s)=>{t[n]||(t[n]=new Map);const a=t[n];a.has(o)||a.set(o,new Map);const i=a.get(o),{size:l}=i;i&&i.set(r,s),l||o.addEventListener(n,e,s)},n=(o,n,r,s)=>{const a=t[n],i=a&&a.get(o),l=i&&i.get(r),{options:c}=void 0!==l?l:{options:s};i&&i.has(r)&&i.delete(r),!a||i&&i.size||a.delete(o),a&&a.size||delete t[n],i&&i.size||o.removeEventListener(n,e,c)},r="ArrowDown",s="ArrowUp",a="ArrowLeft",i="ArrowRight",l="Enter",c="Space";function u(t){return t instanceof HTMLElement?t.ownerDocument:t instanceof Window?t.document:window.document}function h(t,e){const o=getComputedStyle(t);return e in o?o[e]:""}let g=0,p=0;const d=new Map;function b(t,e){const{width:o,height:n,top:r,right:s,bottom:a,left:i}=t.getBoundingClientRect();let l=1,c=1;if(e&&t instanceof HTMLElement){const{offsetWidth:e,offsetHeight:r}=t;l=e>0&&Math.round(o)/e||1,c=r>0&&Math.round(n)/r||1}return{width:o/l,height:n/c,top:r/c,right:s/l,bottom:a/c,left:i/l,x:i/l,y:r/c}}const f=[Document,Element,HTMLElement],m=[Element,HTMLElement];function w(t,e){const o=f.some(t=>e instanceof t)?e:u();return m.some(e=>t instanceof e)?t:o.querySelector(t)}function v(t,e){return(e&&f.some(t=>e instanceof t)?e:u()).getElementsByClassName(t)}const x=(t,e)=>Object.assign(t,e),$=new Map,y={set:(t,e,o)=>{const n=w(t);if(!n)return;$.has(e)||$.set(e,new Map);$.get(e).set(n,o)},getAllFor:t=>$.get(t)||null,get:(t,e)=>{const o=w(t),n=y.getAllFor(e);return o&&n&&n.get(o)||null},remove:(t,e)=>{const o=w(t),n=$.get(e);n&&o&&(n.delete(o),0===n.size&&$.delete(e))}},k=(t,e)=>{x(t.style,e)},S=(t,e)=>t.getAttribute(e);function H(t){return"true"===t||"false"!==t&&(Number.isNaN(+t)?""===t||"null"===t?null:t:+t)}const A=t=>Object.keys(t),E=t=>t.toLowerCase();const P=t=>t.focus();function L(t,e){return t.classList.contains(e)}function N(t,e){t.classList.add(e)}function C(t,e){t.classList.remove(e)}const M=(t,e,o)=>t.setAttribute(e,o),T=(t,e)=>t.removeAttribute(e),{head:R}=document,F=["transparent","currentColor","inherit","revert","initial"];function D(t){const e=Math.floor(t);return t-e<.5?e:Math.round(t)}const O=["rgb","hex","hsl","hsv","hwb"],K="[-\\+]?\\d*\\.?\\d+(?:deg|rad|grad|turn)?",I="(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)",V=`(?:${I})|(?:${K})`,U="(?:[,|\\s]+)",B=`(?:[\\s|\\(\\s|\\s\\(\\s]+)?(${V})${U}(${I})${U}(${I})(?:[,|\\/\\s]*)?(${I})?(?:[\\s|\\)\\s]+)?`,_={CSS_UNIT:new RegExp(V),hwb:new RegExp("hwb"+B),rgb:new RegExp("rgb(?:a)?"+B),hsl:new RegExp("hsl(?:a)?"+B),hsv:new RegExp("hsv(?:a)?"+B),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/};function j(t){return(""+t).includes(".")&&1===parseFloat(t)}function W(t){return(""+t).includes("%")}function z(t){return!F.includes(t)&&!["#",...O].some(e=>t.includes(e))&&["rgb(255, 255, 255)","rgb(0, 0, 0)"].every(e=>{k(R,{color:t});const o=h(R,"color");return k(R,{color:""}),o!==e})}function G(t){return Boolean(_.CSS_UNIT.exec(String(t)))}function X(t,e){let o=t;j(t)&&(o="100%");const n=W(o);return o=360===e?parseFloat(o):Math.min(e,Math.max(0,parseFloat(o))),n&&(o=o*e/100),Math.abs(o-e)<1e-6?1:(o=360===e?(o<0?o%e+e:o%e)/e:o%e/e,o)}function Y(t){let e=parseFloat(""+t);return(Number.isNaN(e)||e<0||e>1)&&(e=1),e}function q(t){return Math.min(1,Math.max(0,t))}function J(t){k(R,{color:t});const e=h(R,"color");return k(R,{color:""}),e}function Z(t){return D(255*t).toString(16)}function Q(t){return tt(t)/255}function tt(t){return parseInt(t,16)}function et(t){return 1===t.length?"0"+t:String(t)}function ot(t,e,o){const n=t/255,r=e/255,s=o/255,a=Math.max(n,r,s),i=Math.min(n,r,s);let l=0,c=0;const u=(a+i)/2;if(a===i)c=0,l=0;else{const t=a-i;switch(c=u>.5?t/(2-a-i):t/(a+i),a){case n:l=(r-s)/t+(r<s?6:0);break;case r:l=(s-n)/t+2;break;case s:l=(n-r)/t+4}l/=6}return{h:l,s:c,l:u}}function nt(t,e,o){let n=o;return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*n*(e-t):n<.5?e:n<2/3?t+(e-t)*(2/3-n)*6:t}function rt(t,e,o){let n=0,r=0,s=0;if(0===e)r=o,s=o,n=o;else{const a=o<.5?o*(1+e):o+e-o*e,i=2*o-a;n=nt(i,a,t+1/3),r=nt(i,a,t),s=nt(i,a,t-1/3)}return[n,r,s]=[n,r,s].map(t=>255*t),{r:n,g:r,b:s}}function st(t,e,o){const n=t/255,r=e/255,s=o/255;let a=0,i=0;const l=Math.min(n,r,s),c=Math.max(n,r,s),u=1-c;if(c===l)return{h:0,w:l,b:u};n===l?(a=r-s,i=3):(a=r===l?s-n:n-r,i=r===l?5:1);const h=(i-a/(c-l))/6;return{h:1===h?0:h,w:l,b:u}}function at(t,e,o){if(e+o>=1){const t=e/(e+o)*255;return{r:t,g:t,b:t}}let{r:n,g:r,b:s}=rt(t,1,.5);return[n,r,s]=[n,r,s].map(t=>t/255*(1-e-o)+e).map(t=>255*t),{r:n,g:r,b:s}}function it(t,e,o){const n=t/255,r=e/255,s=o/255,a=Math.max(n,r,s),i=Math.min(n,r,s);let l=0;const c=a,u=a-i,h=0===a?0:u/a;if(a===i)l=0;else{switch(a){case n:l=(r-s)/u+(r<s?6:0);break;case r:l=(s-n)/u+2;break;case s:l=(n-r)/u+4}l/=6}return{h:l,s:h,v:c}}function lt(t,e,o){const n=6*t,r=e,s=o,a=Math.floor(n),i=n-a,l=s*(1-r),c=s*(1-i*r),u=s*(1-(1-i)*r),h=a%6;let g=[s,c,l,l,u,s][h],p=[u,s,s,c,l,l][h],d=[l,l,u,s,s,c][h];return[g,p,d]=[g,p,d].map(t=>255*t),{r:g,g:p,b:d}}function ct(t,e,o,n){const r=[et(D(t).toString(16)),et(D(e).toString(16)),et(D(o).toString(16))];return n&&r[0].charAt(0)===r[0].charAt(1)&&r[1].charAt(0)===r[1].charAt(1)&&r[2].charAt(0)===r[2].charAt(1)?r[0].charAt(0)+r[1].charAt(0)+r[2].charAt(0):r.join("")}function ut(t,e,o,n,r){const s=[et(D(t).toString(16)),et(D(e).toString(16)),et(D(o).toString(16)),et(Z(n))];return r&&s[0].charAt(0)===s[0].charAt(1)&&s[1].charAt(0)===s[1].charAt(1)&&s[2].charAt(0)===s[2].charAt(1)&&s[3].charAt(0)===s[3].charAt(1)?s[0].charAt(0)+s[1].charAt(0)+s[2].charAt(0)+s[3].charAt(0):s.join("")}function ht(t){let e=E(t.trim());if(0===e.length)return{r:0,g:0,b:0,a:1};let o=!1;if(z(e))e=J(e),o=!0;else if(F.includes(e)){return{r:0,g:0,b:0,a:"transparent"===e?0:1,format:"rgb",ok:!0}}let[,n,r,s,a]=_.rgb.exec(e)||[];return n&&r&&s?{r:n,g:r,b:s,a:void 0!==a?a:1,format:"rgb"}:([,n,r,s,a]=_.hsl.exec(e)||[],n&&r&&s?{h:n,s:r,l:s,a:void 0!==a?a:1,format:"hsl"}:([,n,r,s,a]=_.hsv.exec(e)||[],n&&r&&s?{h:n,s:r,v:s,a:void 0!==a?a:1,format:"hsv"}:([,n,r,s,a]=_.hwb.exec(e)||[],n&&r&&s?{h:n,w:r,b:s,a:void 0!==a?a:1,format:"hwb"}:([,n,r,s,a]=_.hex8.exec(e)||[],n&&r&&s&&a?{r:tt(n),g:tt(r),b:tt(s),a:Q(a),format:o?"rgb":"hex"}:([,n,r,s]=_.hex6.exec(e)||[],n&&r&&s?{r:tt(n),g:tt(r),b:tt(s),format:o?"rgb":"hex"}:([,n,r,s,a]=_.hex4.exec(e)||[],n&&r&&s&&a?{r:tt(n+n),g:tt(r+r),b:tt(s+s),a:Q(a+a),format:o?"rgb":"hex"}:([,n,r,s]=_.hex3.exec(e)||[],!!(n&&r&&s)&&{r:tt(n+n),g:tt(r+r),b:tt(s+s),format:o?"rgb":"hex"})))))))}function gt(t){let e={r:0,g:0,b:0},o=t,n=1,r=null,s=null,a=null,i=null,l=null,c=null,u=null,h=null,g=!1;const p="object"==typeof o&&o.format;let d=p&&O.includes(p)?p:"rgb";return"string"==typeof t&&(o=ht(t),o&&(g=!0)),"object"==typeof o&&(G(o.r)&&G(o.g)&&G(o.b)?(({r:u,g:h,b:l}=o),[u,h,l]=[u,h,l].map(t=>255*X(t,W(t)?100:255)),e={r:u,g:h,b:l},g=!0,d="rgb"):G(o.h)&&G(o.s)&&G(o.v)?(({h:c,s:r,v:s}=o),c="number"==typeof c?c:X(c,360),r="number"==typeof r?r:X(r,100),s="number"==typeof s?s:X(s,100),e=lt(c,r,s),g=!0,d="hsv"):G(o.h)&&G(o.s)&&G(o.l)?(({h:c,s:r,l:a}=o),c="number"==typeof c?c:X(c,360),r="number"==typeof r?r:X(r,100),a="number"==typeof a?a:X(a,100),e=rt(c,r,a),g=!0,d="hsl"):G(o.h)&&G(o.w)&&G(o.b)&&(({h:c,w:i,b:l}=o),c="number"==typeof c?c:X(c,360),i="number"==typeof i?i:X(i,100),l="number"==typeof l?l:X(l,100),e=at(c,i,l),g=!0,d="hwb"),G(o.a)&&(n=o.a,n=W(""+n)||parseFloat(n)>1?X(n,100):n)),void 0===o&&(g=!0),{ok:g,format:d,r:Math.min(255,Math.max(e.r,0)),g:Math.min(255,Math.max(e.g,0)),b:Math.min(255,Math.max(e.b,0)),a:Y(n)}}class pt{constructor(t,e){let o=t;const n=e&&O.includes(e)?e:"rgb";if(o instanceof pt&&(o=gt(o)),"number"==typeof o){o=`#${2===(""+o).length?"0":"00"}${o}`}const{r:r,g:s,b:a,a:i,ok:l,format:c}=gt(o);this.originalInput=t,this.r=r,this.g=s,this.b=a,this.a=i,this.ok=l,this.format=n||c}get isValid(){return this.ok}get isDark(){return this.brightness<120}get luminance(){const{r:t,g:e,b:o}=this;let n=0,r=0,s=0;const a=t/255,i=e/255,l=o/255;return n=a<=.03928?a/12.92:((a+.055)/1.055)**2.4,r=i<=.03928?i/12.92:((i+.055)/1.055)**2.4,s=l<=.03928?l/12.92:((l+.055)/1.055)**2.4,.2126*n+.7152*r+.0722*s}get brightness(){const{r:t,g:e,b:o}=this;return(299*t+587*e+114*o)/1e3}toRgb(){const{r:t,g:e,b:o,a:n}=this;return{r:t,g:e,b:o,a:D(100*n)/100}}toRgbString(){const{r:t,g:e,b:o,a:n}=this.toRgb(),[r,s,a]=[t,e,o].map(D);return 1===n?`rgb(${r}, ${s}, ${a})`:`rgba(${r}, ${s}, ${a}, ${n})`}toRgbCSS4String(){const{r:t,g:e,b:o,a:n}=this.toRgb(),[r,s,a]=[t,e,o].map(D);return`rgb(${r} ${s} ${a}${1===n?"":` / ${D(100*n)}%`})`}toHex(t){const{r:e,g:o,b:n,a:r}=this.toRgb();return 1===r?ct(e,o,n,t):ut(e,o,n,r,t)}toHexString(t){return"#"+this.toHex(t)}toHex8(t){const{r:e,g:o,b:n,a:r}=this.toRgb();return ut(e,o,n,r,t)}toHex8String(t){return"#"+this.toHex8(t)}toHsv(){const{r:t,g:e,b:o,a:n}=this.toRgb(),{h:r,s:s,v:a}=it(t,e,o);return{h:r,s:s,v:a,a:n}}toHsl(){const{r:t,g:e,b:o,a:n}=this.toRgb(),{h:r,s:s,l:a}=ot(t,e,o);return{h:r,s:s,l:a,a:n}}toHslString(){let{h:t,s:e,l:o,a:n}=this.toHsl();return t=D(360*t),e=D(100*e),o=D(100*o),n=D(100*n)/100,1===n?`hsl(${t}, ${e}%, ${o}%)`:`hsla(${t}, ${e}%, ${o}%, ${n})`}toHslCSS4String(){let{h:t,s:e,l:o,a:n}=this.toHsl();t=D(360*t),e=D(100*e),o=D(100*o),n=D(100*n);return`hsl(${t}deg ${e}% ${o}%${n<100?` / ${D(n)}%`:""})`}toHwb(){const{r:t,g:e,b:o,a:n}=this,{h:r,w:s,b:a}=st(t,e,o);return{h:r,w:s,b:a,a:n}}toHwbString(){let{h:t,w:e,b:o,a:n}=this.toHwb();t=D(360*t),e=D(100*e),o=D(100*o),n=D(100*n);return`hwb(${t}deg ${e}% ${o}%${n<100?` / ${D(n)}%`:""})`}setAlpha(t){return this.a=Y(t),this}saturate(t){if("number"!=typeof t)return this;const{h:e,s:o,l:n}=this.toHsl(),{r:r,g:s,b:a}=rt(e,q(o+t/100),n);return x(this,{r:r,g:s,b:a}),this}desaturate(t){return"number"==typeof t?this.saturate(-t):this}greyscale(){return this.saturate(-100)}lighten(t){if("number"!=typeof t)return this;const{h:e,s:o,l:n}=this.toHsl(),{r:r,g:s,b:a}=rt(e,o,q(n+t/100));return x(this,{r:r,g:s,b:a}),this}darken(t){return"number"==typeof t?this.lighten(-t):this}spin(t){if("number"!=typeof t)return this;const{h:e,s:o,l:n}=this.toHsl(),{r:r,g:s,b:a}=rt(q((360*e+t)%360/360),o,n);return x(this,{r:r,g:s,b:a}),this}clone(){return new pt(this)}toString(t){const{format:e}=this;return"hex"===e?this.toHexString(t):"hsl"===e?this.toHslString():"hwb"===e?this.toHwbString():this.toRgbString()}}x(pt,{ANGLES:"deg|rad|grad|turn",CSS_ANGLE:K,CSS_INTEGER:"[-\\+]?\\d+%?",CSS_NUMBER:"[-\\+]?\\d*\\.\\d+%?",CSS_UNIT:I,CSS_UNIT2:V,PERMISSIVE_MATCH:B,matchers:_,isOnePointZero:j,isPercentage:W,isValidCSSUnit:G,isColorName:z,pad2:et,clamp01:q,bound01:X,boundAlpha:Y,getRGBFromName:J,convertHexToDecimal:Q,convertDecimalToHex:Z,rgbToHsl:ot,rgbToHex:ct,rgbToHsv:it,rgbToHwb:st,rgbaToHex:ut,hslToRgb:rt,hsvToRgb:lt,hueToRgb:nt,hwbToRgb:at,parseIntFromHex:tt,stringInputToObject:ht,inputToRGB:gt,roundPart:D,getElementStyle:h,setElementStyle:k,ObjectAssign:x});class dt{constructor(...t){let e=0,o=12,n=10,r=[.5];if(3===t.length)[e,o,n]=t;else{if(2!==t.length)throw TypeError("ColorPalette requires minimum 2 arguments");if([o,n]=t,[o,n].some(t=>t<1))throw TypeError("ColorPalette: when 2 arguments used, both must be larger than 0.")}const s=[],a=360/o,i=D((n-(n%2?1:0))/2),l=100/(n+(n%2?0:1))/100;let c=.25;c=[4,5].includes(n)?.2:c,c=[6,7].includes(n)?.15:c,c=[8,9].includes(n)?.11:c,c=[10,11].includes(n)?.09:c,c=[12,13].includes(n)?.075:c,c=n>13?l:c;for(let t=1;t<i+1;t+=1)r=[...r,.5+c*t];for(let t=1;t<n-i;t+=1)r=[.5-c*t,...r];for(let t=0;t<o;t+=1){const o=(e+t*a)%360/360;r.forEach(t=>{s.push(new pt({h:o,s:1,l:t}))})}this.hue=e,this.hueSteps=o,this.lightSteps=n,this.colors=s}}x(dt,{Color:pt});const bt={pickerLabel:"Colour Picker",appearanceLabel:"Colour Appearance",valueLabel:"Colour Value",toggleLabel:"Select Colour",presetsLabel:"Colour Presets",defaultsLabel:"Colour Defaults",formatLabel:"Format",alphaLabel:"Alpha",hexLabel:"Hexadecimal",hueLabel:"Hue",whitenessLabel:"Whiteness",blacknessLabel:"Blackness",saturationLabel:"Saturation",lightnessLabel:"Lightness",redLabel:"Red",greenLabel:"Green",blueLabel:"Blue"},ft=["white","black","grey","red","orange","brown","gold","olive","yellow","lime","green","teal","cyan","blue","violet","magenta","pink"];function mt(t){try{JSON.parse(t)}catch(t){return!1}return!0}const wt=t=>t.toUpperCase();function vt(t){if("string"==typeof t)return u().createElement(t);const{tagName:e}=t,o={...t},n=vt(e);return delete o.tagName,x(n,o),n}function xt(t,e){if("string"==typeof e)return u().createElementNS(t,e);const{tagName:o}=e,n={...e},r=xt(t,o);return delete n.tagName,x(r,n),r}function $t(t,e,o){const{input:n,format:r,componentLabels:s}=t,{defaultsLabel:a,presetsLabel:i}=s,l="color-options"===o,c=e instanceof dt,u=l?i:a;let h=c?e.colors:e;h=h instanceof Array?h:[];const g=h.length,{lightSteps:p}=c?e:{lightSteps:null},d=p||[9,10].find(t=>g>2*t&&!(g%t))||5,b=l&&g>d;let f=2;f=b&&g>=2*d?3:f,f=g>=3*d?4:f,f=g>=4*d?5:f;const m=f-(g<3*d?1:2),w=b&&g>m*d;let v=o;v+=w?" scrollable":"",v+=b?" multiline":"";const x=b?"1px":"0.25rem";let $=b?1.75:2;$=d>5&&b?1.5:$;const y=(m||1)*$+"rem",H=`calc(${f} * ${$}rem + ${f-1} * ${x})`,E=vt({tagName:"ul",className:v});var P,L;return M(E,"role","listbox"),M(E,"aria-label",u),w&&(P=E,A(L={"--grid-item-size":$+"rem","--grid-fit":d,"--grid-gap":x,"--grid-height":y,"--grid-hover-height":H}).forEach(t=>{P.style.setProperty(t,L[t])})),h.forEach(t=>{let[e,o]="string"==typeof t?t.trim().split(":"):[];t instanceof pt&&(e=t.toHexString(),o=e);const s=new pt(t instanceof pt?t:e,r).toString()===S(n,"value"),a=vt({tagName:"li",className:"color-option"+(s?" active":""),innerText:""+(o||e)});M(a,"tabindex","0"),M(a,"data-value",""+e),M(a,"role","option"),M(a,"aria-selected",s?"true":"false"),l&&k(a,{backgroundColor:e}),E.append(a)}),E}function yt(t){const{input:e,parent:o,format:n,id:r,componentLabels:s,colorKeywords:a,colorPresets:i}=t,l=S(e,"value")||"#fff",{toggleLabel:c,pickerLabel:u,formatLabel:h,hexLabel:g}=s,p=F.includes(l)?"#fff":l;t.color=new pt(p,n);const d="hex"===n?g:wt(n),b=vt({id:"picker-btn-"+r,tagName:"button",className:"picker-toggle btn-appearance"});M(b,"aria-expanded","false"),M(b,"aria-haspopup","true"),b.append(vt({tagName:"span",className:"v-hidden",innerText:`${u}. ${h}: ${d}`}));const f=vt({tagName:"div",className:"color-dropdown picker"});M(f,"aria-labelledby","picker-btn-"+r),M(f,"role","group");const m=function(t){const{format:e,componentLabels:o}=t,{hueLabel:n,alphaLabel:r,lightnessLabel:s,saturationLabel:a,whitenessLabel:i,blacknessLabel:l}=o,c="hsl"===e?360:100,u="hsl"===e?100:360;let h="hsl"===e?`${n} & ${s}`:`${s} & ${a}`;h="hwb"===e?`${i} & ${l}`:h;const g="hsl"===e?""+a:""+n,p=vt({tagName:"div",className:"color-controls "+e});return[{i:1,c:"color-pointer",l:h,min:0,max:c},{i:2,c:"color-slider",l:g,min:0,max:u},{i:3,c:"color-slider",l:r,min:0,max:100}].forEach(t=>{const{i:e,c:o,l:n,min:r,max:s}=t,a=vt({tagName:"div",className:"color-control"});M(a,"role","presentation"),a.append(vt({tagName:"div",className:"visual-control visual-control"+e}));const i=vt({tagName:"div",className:o+" knob",ariaLive:"polite"});M(i,"aria-label",n),M(i,"role","slider"),M(i,"tabindex","0"),M(i,"aria-valuemin",""+r),M(i,"aria-valuemax",""+s),a.append(i),p.append(a)}),p}(t),w=function(t){const{format:e,id:o,componentLabels:n}=t,r=vt({tagName:"div",className:"color-form "+e});let s=["hex"];return"rgb"===e?s=["red","green","blue","alpha"]:"hsl"===e?s=["hue","saturation","lightness","alpha"]:"hwb"===e&&(s=["hue","whiteness","blackness","alpha"]),s.forEach(t=>{const[s]="hex"===e?["#"]:wt(t).split(""),a=`color_${e}_${t}_${o}`,i=n[t+"Label"],l=vt({tagName:"label"});M(l,"for",a),l.append(vt({tagName:"span",ariaHidden:"true",innerText:s+":"}),vt({tagName:"span",className:"v-hidden",innerText:i}));const c=vt({tagName:"input",id:a,type:"hex"===e?"text":"number",value:"alpha"===t?"100":"0",className:"color-input "+t});M(c,"autocomplete","off"),M(c,"spellcheck","false");let u="100",h="1";"alpha"!==t&&("rgb"===e?(u="255",h="1"):"hue"===t&&(u="360",h="1")),x(c,{min:"0",max:u,step:h}),r.append(l,c)}),r}(t);if(f.append(m,w),e.before(b),o.append(f),a||i){const e=vt({tagName:"div",className:"color-dropdown scrollable menu"});if(i instanceof Array&&i.length||i instanceof dt&&i.colors){const o=$t(t,i,"color-options");e.append(o)}if(a&&a.length){const o=$t(t,a,"color-defaults");e.append(o)}const n=vt({tagName:"button",className:"menu-toggle btn-appearance"});M(n,"tabindex","-1"),M(n,"aria-expanded","false"),M(n,"aria-haspopup","true");const r=encodeURI("http://www.w3.org/2000/svg"),s=xt(r,{tagName:"svg"});M(s,"xmlns",r),M(s,"viewBox","0 0 512 512"),M(s,"aria-hidden","true");const l=xt(r,{tagName:"path"});M(l,"d","M98,158l157,156L411,158l27,27L255,368L71,185L98,158z"),M(l,"fill","#fff"),s.append(l),n.append(vt({tagName:"span",className:"v-hidden",innerText:""+c}),s),o.append(n,e)}a&&F.includes(l)&&(t.value=l),M(e,"tabindex","-1")}const kt={componentLabels:bt,colorLabels:ft,format:"rgb",colorPresets:!1,colorKeywords:!1};function St(t,e){const r=e?o:n,{input:s,pickerToggle:a,menuToggle:i}=t;r(s,"focusin",t.showPicker),r(a,"click",t.togglePicker),r(s,"keydown",t.keyToggle),i&&r(i,"click",t.toggleMenu)}function Ht(t,e){const r=e?o:n,{input:s,colorMenu:a,parent:i}=t,l=u(s),c=function(t){if(null==t)return window;if(!(t instanceof Window)){const{ownerDocument:e}=t;return e&&e.defaultView||window}return t}(s),h="ontouchstart"in l?{down:"touchstart",move:"touchmove",up:"touchend"}:{down:"mousedown",move:"mousemove",up:"mouseup"};r(t.controls,h.down,t.pointerDown),t.controlKnobs.forEach(e=>r(e,"keydown",t.handleKnobs)),r(c,"scroll",t.handleScroll),r(c,"resize",t.update),[s,...t.inputs].forEach(e=>r(e,"change",t.changeHandler)),a&&(r(a,"click",t.menuClickHandler),r(a,"keydown",t.menuKeyHandler)),r(l,h.move,t.pointerMove),r(l,h.up,t.pointerUp),r(i,"focusout",t.handleFocusOut),r(c,"keyup",t.handleDismiss)}function At(t){var e,o;e=t.input,o=new CustomEvent("colorpicker.change"),e.dispatchEvent(o)}function Et(t){t&&["bottom","top"].forEach(e=>C(t,e))}function Pt(t,e){const{colorPicker:o,colorMenu:n,menuToggle:r,pickerToggle:s,parent:a}=t,i=e===o,l=i?n:o,c=i?r:s,u=i?s:r;L(a,"open")||N(a,"open"),l&&(C(l,"show"),Et(l)),N(e,"bottom"),e.offsetHeight,N(e,"show"),i&&t.update(),t.isOpen||(Ht(t,!0),t.updateDropdownPosition(),t.isOpen=!0,M(t.input,"tabindex","0"),r&&M(r,"tabindex","0")),M(u,"aria-expanded","true"),c&&M(c,"aria-expanded","false")}class Lt{constructor(t,e){const o=this,n=w(t);if(!n)throw new TypeError(`ColorPicker target ${t} cannot be found.`);o.input=n;const r=function t(e,o){return e?e.closest(o)||t(e.getRootNode().host,o):null}(n,".color-picker,color-picker");if(!r)throw new TypeError("ColorPicker requires a specific markup to work.");o.parent=r,o.id=function t(e,o){let n=o?g:p;if(o){const r=t(e),s=d.get(r)||new Map;d.has(r)||d.set(r,s),s.has(o)?n=s.get(o):(s.set(o,n),g+=1)}else{const t=e.id||e;d.has(t)?n=d.get(t):(d.set(t,n),p+=1)}return n}(n,"color-picker"),o.dragElement=null,o.isOpen=!1,o.controlPositions={c1x:0,c1y:0,c2y:0,c3y:0},o.colorLabels={},o.colorKeywords=void 0,o.colorPresets=void 0;const{format:s,componentLabels:a,colorLabels:i,colorKeywords:l,colorPresets:c}=function(t,e,o,n){const r={...t.dataset},s={},a={};return A(r).forEach(t=>{const e=n&&t.includes(n)?t.replace(n,"").replace(/[A-Z]/,t=>E(t)):t;a[e]=H(r[t])}),A(o).forEach(t=>{o[t]=H(o[t])}),A(e).forEach(n=>{s[n]=n in o?o[n]:n in a?a[n]:"title"===n?S(t,"title"):e[n]}),s}(this.isCE?r:n,kt,e||{});let u=ft;i instanceof Array&&17===i.length?u=i:i&&17===i.split(",").length&&(u=i.split(",")),ft.forEach((t,e)=>{o.colorLabels[t]=u[e].trim()});const h=x({},bt),b=a&&mt(a)?JSON.parse(a):a||{};if(o.componentLabels=x(h,b),o.color=new pt("white",s),o.format=s,l instanceof Array?o.colorKeywords=l:"string"==typeof l&&l.length&&(o.colorKeywords=l.split(",")),c instanceof Array)o.colorPresets=c;else if("string"==typeof c&&c.length)if(mt(c)){const{hue:t,hueSteps:e,lightSteps:n}=JSON.parse(c);o.colorPresets=new dt(t,e,n)}else o.colorPresets=c.split(",").map(t=>t.trim());o.showPicker=o.showPicker.bind(o),o.togglePicker=o.togglePicker.bind(o),o.toggleMenu=o.toggleMenu.bind(o),o.menuClickHandler=o.menuClickHandler.bind(o),o.menuKeyHandler=o.menuKeyHandler.bind(o),o.pointerDown=o.pointerDown.bind(o),o.pointerMove=o.pointerMove.bind(o),o.pointerUp=o.pointerUp.bind(o),o.update=o.update.bind(o),o.handleScroll=o.handleScroll.bind(o),o.handleFocusOut=o.handleFocusOut.bind(o),o.changeHandler=o.changeHandler.bind(o),o.handleDismiss=o.handleDismiss.bind(o),o.keyToggle=o.keyToggle.bind(o),o.handleKnobs=o.handleKnobs.bind(o),yt(o);const[f,m]=v("color-dropdown",r);o.pickerToggle=w(".picker-toggle",r),o.menuToggle=w(".menu-toggle",r),o.colorPicker=f,o.colorMenu=m,o.inputs=[...v("color-input",r)];const[$]=v("color-controls",r);o.controls=$,o.controlKnobs=[...v("knob",$)],o.visuals=[...v("visual-control",$)],o.update(),St(o,!0),y.set(n,"color-picker",o)}get value(){return this.input.value}set value(t){this.input.value=t}get hasNonColor(){return this.colorKeywords instanceof Array&&this.colorKeywords.some(t=>F.includes(t))}get isCE(){return"color-picker"===this.parent.localName}get hex(){return this.color.toHex(!0)}get hsv(){return this.color.toHsv()}get hsl(){return this.color.toHsl()}get hwb(){return this.color.toHwb()}get rgb(){return this.color.toRgb()}get brightness(){return this.color.brightness}get luminance(){return this.color.luminance}get isDark(){const{color:t,brightness:e}=this;return e<120&&t.a>.33}get isValid(){const t=this.input.value;return""!==t&&new pt(t).isValid}updateVisuals(){const{format:t,controlPositions:e,visuals:o}=this,[n,r,s]=o,{offsetWidth:a,offsetHeight:i}=n,l="hsl"===t?e.c1x/a:e.c2y/i,{r:c,g:u,b:h}=pt.hslToRgb(l,1,.5),g="linear-gradient(rgb(255,255,255) 0%, rgb(255,255,255) 100%)",p=1-e.c3y/i,d=D(100*p)/100;if("hsl"!==t){const t=new pt({h:l,s:1,l:.5,a:p}).toRgbString(),e="linear-gradient(\n rgb(255,0,0) 0%, rgb(255,255,0) 16.67%,\n rgb(0,255,0) 33.33%, rgb(0,255,255) 50%,\n rgb(0,0,255) 66.67%, rgb(255,0,255) 83.33%,\n rgb(255,0,0) 100%)";k(n,{background:`linear-gradient(rgba(0,0,0,0) 0%, rgba(0,0,0,${d}) 100%),\n linear-gradient(to right, rgba(255,255,255,${d}) 0%, ${t} 100%),\n ${g}`}),k(r,{background:e})}else{const t=D(e.c2y/i*100),o=new pt({r:255,g:0,b:0,a:p}).saturate(-t).toRgbString(),s=new pt({r:255,g:255,b:0,a:p}).saturate(-t).toRgbString(),a=new pt({r:0,g:255,b:0,a:p}).saturate(-t).toRgbString(),l=new pt({r:0,g:255,b:255,a:p}).saturate(-t).toRgbString(),b=new pt({r:0,g:0,b:255,a:p}).saturate(-t).toRgbString(),f=new pt({r:255,g:0,b:255,a:p}).saturate(-t).toRgbString(),m=new pt({r:255,g:0,b:0,a:p}).saturate(-t).toRgbString();k(n,{background:`${`linear-gradient(rgba(255,255,255,${d}) 0%, rgba(255,255,255,0) 50%),\n linear-gradient(rgba(0,0,0,0) 50%, rgba(0,0,0,${d}) 100%)`},${`linear-gradient(to right,\n ${o} 0%, ${s} 16.67%, ${a} 33.33%, ${l} 50%,\n ${b} 66.67%, ${f} 83.33%, ${m} 100%)`},${g}`});const{r:w,g:v,b:x}=new pt({r:c,g:u,b:h}).greyscale().toRgb();k(r,{background:`linear-gradient(rgb(${c},${u},${h}) 0%, rgb(${w},${v},${x}) 100%)`})}k(s,{background:`linear-gradient(rgba(${c},${u},${h},1) 0%,rgba(${c},${u},${h},0) 100%)`})}handleFocusOut({relatedTarget:t}){t&&!this.parent.contains(t)&&this.hide(!0)}handleDismiss({code:t}){const e=this;e.isOpen&&"Escape"===t&&e.hide()}handleScroll(t){const{activeElement:e}=u(this.input);("touchmove"===t.type&&this.dragElement||e&&this.controlKnobs.includes(e))&&(t.stopPropagation(),t.preventDefault()),this.updateDropdownPosition()}menuKeyHandler(t){const{target:e,code:o}=t,{previousElementSibling:n,nextElementSibling:u,parentElement:g}=e,p=g&&L(g,"color-options"),d=[...g.children],b=p&&h(g,"grid-template-columns").split(" ").length,f=d.indexOf(e),m=f>-1&&b&&d[f-b],w=f>-1&&b&&d[f+b];[r,s,c].includes(o)&&t.preventDefault(),p?m&&o===s?P(m):w&&o===r?P(w):n&&o===a?P(n):u&&o===i&&P(u):n&&[a,s].includes(o)?P(n):u&&[i,r].includes(o)&&P(u),[l,c].includes(o)&&this.menuClickHandler({target:e})}menuClickHandler(t){const e=this,{target:o}=t,{colorMenu:n}=e,r=(S(o,"data-value")||"").trim();if(!r.length)return;const s=w("li.active",n);let a=F.includes(r)?"white":r;a="transparent"===r?"rgba(0,0,0,0)":r;const{r:i,g:l,b:c,a:u}=new pt(a);x(e.color,{r:i,g:l,b:c,a:u}),e.update(),s!==o&&(s&&(C(s,"active"),T(s,"aria-selected")),N(o,"active"),M(o,"aria-selected","true"),F.includes(r)&&(e.value=r),At(e))}pointerDown(t){const e=this,{type:o,target:n,touches:r,pageX:s,pageY:a}=t,{colorMenu:i,visuals:l,controlKnobs:c}=e,[u,h,g]=l,[p,d,f]=c,m=L(n,"visual-control")?n:w(".visual-control",n.parentElement),v=b(m),x="touchstart"===o?r[0].pageX:s,$="touchstart"===o?r[0].pageY:a,y=x-window.pageXOffset-v.left,k=$-window.pageYOffset-v.top;if(n===u||n===p?(e.dragElement=m,e.changeControl1(y,k)):n===h||n===d?(e.dragElement=m,e.changeControl2(k)):n!==g&&n!==f||(e.dragElement=m,e.changeAlpha(k)),i){const t=w("li.active",i);t&&(C(t,"active"),T(t,"aria-selected"))}t.preventDefault()}pointerUp({target:t}){const e=this,{parent:o}=e,n=u(o),r=null!==w(".color-picker,color-picker.open",n),s=n.getSelection();e.dragElement||s.toString().length||o.contains(t)||e.hide(r),e.dragElement=null}pointerMove(t){const e=this,{dragElement:o,visuals:n}=e,[r,s,a]=n,{type:i,touches:l,pageX:c,pageY:u}=t;if(!o)return;const h=b(o),g="touchmove"===i?l[0].pageX:c,p="touchmove"===i?l[0].pageY:u,d=g-window.pageXOffset-h.left,f=p-window.pageYOffset-h.top;o===r&&e.changeControl1(d,f),o===s&&e.changeControl2(f),o===a&&e.changeAlpha(f)}handleKnobs(t){const{target:e,code:o}=t,n=this;if(![s,r,a,i].includes(o))return;t.preventDefault();const{format:l,controlKnobs:c,visuals:h}=n,{offsetWidth:g,offsetHeight:p}=h[0],[d,b,f]=c,{activeElement:m}=u(d),w=p/("hsl"===l?100:360);if(c.find(t=>t===m)){let c=0,u=0;if(e===d){const t=g/("hsl"===l?360:100);[a,i].includes(o)?n.controlPositions.c1x+=o===i?t:-t:[s,r].includes(o)&&(n.controlPositions.c1y+=o===r?w:-w),c=n.controlPositions.c1x,u=n.controlPositions.c1y,n.changeControl1(c,u)}else e===b?(n.controlPositions.c2y+=[r,i].includes(o)?w:-w,u=n.controlPositions.c2y,n.changeControl2(u)):e===f&&(n.controlPositions.c3y+=[r,i].includes(o)?w:-w,u=n.controlPositions.c3y,n.changeAlpha(u));n.handleScroll(t)}}changeHandler(){const t=this;let e;const{inputs:o,format:n,value:r,input:s,controlPositions:a,visuals:i}=t,{activeElement:l}=u(s),{offsetHeight:c}=i[0],[h,,,g]=o,[p,d,b,f]="rgb"===n?o.map(t=>parseFloat(t.value)/(t===g?100:1)):o.map(t=>parseFloat(t.value)/(t!==h?100:360)),m=t.hasNonColor&&F.includes(r),w=g?f:1-a.c3y/c;if(l===s||l&&o.includes(l)){e=l===s?m?"white":r:"hex"===n?h.value:"hsl"===n?{h:p,s:d,l:b,a:w}:"hwb"===n?{h:p,w:d,b:b,a:w}:{r:p,g:d,b:b,a:w};const{r:o,g:a,b:i,a:c}=new pt(e);x(t.color,{r:o,g:a,b:i,a:c}),t.setControlPositions(),t.updateAppearance(),t.updateInputs(),t.updateControls(),t.updateVisuals(),l===s&&m&&(t.value=r)}}changeControl1(t,e){let[o,n]=[0,0];const{format:r,controlPositions:s,visuals:a}=this,{offsetHeight:i,offsetWidth:l}=a[0];t>l?o=l:t>=0&&(o=t),e>i?n=i:e>=0&&(n=e);const c="hsl"===r?o/l:s.c2y/i,u="hsl"===r?1-s.c2y/i:o/l,h=1-n/i,g=1-s.c3y/i,p="hsl"===r?{h:c,s:u,l:h,a:g}:{h:c,s:u,v:h,a:g},{r:d,g:b,b:f,a:m}=new pt(p);x(this.color,{r:d,g:b,b:f,a:m}),this.controlPositions.c1x=o,this.controlPositions.c1y=n,this.updateAppearance(),this.updateInputs(),this.updateControls(),this.updateVisuals()}changeControl2(t){const{format:e,controlPositions:o,visuals:n}=this,{offsetHeight:r,offsetWidth:s}=n[0];let a=0;t>r?a=r:t>=0&&(a=t);const i="hsl"===e?o.c1x/s:a/r,l="hsl"===e?1-a/r:o.c1x/s,c=1-o.c1y/r,u=1-o.c3y/r,h="hsl"===e?{h:i,s:l,l:c,a:u}:{h:i,s:l,v:c,a:u},{r:g,g:p,b:d,a:b}=new pt(h);x(this.color,{r:g,g:p,b:d,a:b}),this.controlPositions.c2y=a,this.updateAppearance(),this.updateInputs(),this.updateControls(),this.updateVisuals()}changeAlpha(t){const{visuals:e}=this,{offsetHeight:o}=e[0];let n=0;t>o?n=o:t>=0&&(n=t);const r=1-n/o;this.color.setAlpha(r),this.controlPositions.c3y=n,this.updateAppearance(),this.updateInputs(),this.updateControls(),this.updateVisuals()}update(){this.updateDropdownPosition(),this.updateAppearance(),this.setControlPositions(),this.updateInputs(!0),this.updateControls(),this.updateVisuals()}updateDropdownPosition(){const{input:t,colorPicker:e,colorMenu:o}=this,n=b(t),{top:r,bottom:s}=n,{offsetHeight:a}=t,i=(l=t,u(l).documentElement).clientHeight;var l;const c=L(e,"show")?e:o;if(!c)return;const{offsetHeight:h}=c,g=i-s,p=r,d=r+h+a>i,f=r-h<0;(L(c,"bottom")||!f)&&g<p&&d?(C(c,"bottom"),N(c,"top")):(C(c,"top"),N(c,"bottom"))}setControlPositions(){const{format:t,visuals:e,color:o,hsl:n,hsv:r}=this,{offsetHeight:s,offsetWidth:a}=e[0],i=o.a,l=n.h,c="hsl"!==t?r.s:n.s,u="hsl"!==t?r.v:n.l;this.controlPositions.c1x="hsl"!==t?c*a:l*a,this.controlPositions.c1y=(1-u)*s,this.controlPositions.c2y="hsl"!==t?l*s:(1-c)*s,this.controlPositions.c3y=(1-i)*s}updateAppearance(){const t=this,{componentLabels:e,colorLabels:o,color:n,parent:r,hsl:s,hsv:a,hex:i,format:l,controlKnobs:c}=t,{appearanceLabel:u,hexLabel:h,valueLabel:g}=e,{r:p,g:d,b:b}=n.toRgb(),[f,m,w]=c,v=D(360*s.h),x=n.a,$=D(100*("hsl"===l?s.s:a.s)),y=D(100*s.l),S=100*a.v;let H;if(100===y&&0===$)H=o.white;else if(0===y)H=o.black;else if(0===$)H=o.grey;else if(v<15||v>=345)H=o.red;else if(v>=15&&v<45)H=S>80&&$>80?o.orange:o.brown;else if(v>=45&&v<75){const t=v>=54&&v<75&&S<80;H=v>46&&v<54&&S<80&&$>90?o.gold:o.yellow,H=t?o.olive:H}else v>=75&&v<155?H=S<68?o.green:o.lime:v>=155&&v<175?H=o.teal:v>=175&&v<195?H=o.cyan:v>=195&&v<255?H=o.blue:v>=255&&v<270?H=o.violet:v>=270&&v<295?H=o.magenta:v>=295&&v<345&&(H=o.pink);let A=`${h} ${i.split("").join(" ")}`;if("hsl"===l)A=`HSL: ${v}°, ${$}%, ${y}%`,M(f,"aria-description",`${g}: ${A}. ${u}: ${H}.`),M(f,"aria-valuetext",`${v}° & ${y}%`),M(f,"aria-valuenow",""+v),M(m,"aria-valuetext",$+"%"),M(m,"aria-valuenow",""+$);else if("hwb"===l){const{hwb:e}=t,o=D(100*e.w),n=D(100*e.b);A=`HWB: ${v}°, ${o}%, ${n}%`,M(f,"aria-description",`${g}: ${A}. ${u}: ${H}.`),M(f,"aria-valuetext",`${o}% & ${n}%`),M(f,"aria-valuenow",""+o),M(m,"aria-valuetext",v+"%"),M(m,"aria-valuenow",""+v)}else A="rgb"===l?`RGB: ${p}, ${d}, ${b}`:A,M(m,"aria-description",`${g}: ${A}. ${u}: ${H}.`),M(f,"aria-valuetext",`${y}% & ${$}%`),M(f,"aria-valuenow",""+y),M(m,"aria-valuetext",v+"°"),M(m,"aria-valuenow",""+v);const E=D(100*x);M(w,"aria-valuetext",E+"%"),M(w,"aria-valuenow",""+E);const P=n.toString();k(t.input,{backgroundColor:P}),t.isDark?(L(r,"txt-light")&&C(r,"txt-light"),L(r,"txt-dark")||N(r,"txt-dark")):(L(r,"txt-dark")&&C(r,"txt-dark"),L(r,"txt-light")||N(r,"txt-light"))}updateControls(){const{controlKnobs:t,controlPositions:e}=this;let{c1x:o,c1y:n,c2y:r,c3y:s}=e;const[a,i,l]=t;[o,n,r,s]=[o,n,r,s].map(D),k(a,{transform:`translate3d(${o-4}px,${n-4}px,0)`}),k(i,{transform:`translate3d(0,${r-4}px,0)`}),k(l,{transform:`translate3d(0,${s-4}px,0)`})}updateInputs(t){const e=this,{value:o,format:n,inputs:r,color:s,hsl:a}=e,[i,l,c,u]=r,h=D(100*s.a),g=D(360*a.h);let p;if("hex"===n)p=e.color.toHexString(!0),i.value=e.hex;else if("hsl"===n){const t=D(100*a.l),o=D(100*a.s);p=e.color.toHslString(),i.value=""+g,l.value=""+o,c.value=""+t,u.value=""+h}else if("hwb"===n){const{w:t,b:o}=e.hwb,n=D(100*t),r=D(100*o);p=e.color.toHwbString(),i.value=""+g,l.value=""+n,c.value=""+r,u.value=""+h}else if("rgb"===n){let{r:t,g:o,b:n}=e.rgb;[t,o,n]=[t,o,n].map(D),p=e.color.toRgbString(),i.value=""+t,l.value=""+o,c.value=""+n,u.value=""+h}e.value=""+p,t||p===o||At(e)}keyToggle(t){const e=this,{menuToggle:o}=e,{activeElement:n}=u(o),{code:r}=t;[l,c].includes(r)&&(o&&n===o||!n)&&(t.preventDefault(),n?e.toggleMenu():e.togglePicker(t))}togglePicker(t){t.preventDefault();const e=this,{colorPicker:o}=e;e.isOpen&&L(o,"show")?e.hide(!0):Pt(e,o)}showPicker(){const t=this,{colorPicker:e}=t;["top","bottom"].some(t=>L(e,t))||Pt(t,e)}toggleMenu(){const t=this,{colorMenu:e}=t;t.isOpen&&L(e,"show")?t.hide(!0):Pt(t,e)}hide(t){const e=this;if(e.isOpen){const{pickerToggle:o,menuToggle:n,colorPicker:r,colorMenu:s,parent:a,input:i}=e,l=L(r,"show"),c=l?r:s,u=l?o:n,g=c&&function(t){const e=h(t,"transitionProperty"),o=h(t,"transitionDuration"),n=o.includes("ms")?1:1e3,r=e&&"none"!==e?parseFloat(o)*n:0;return Number.isNaN(r)?0:r}(c);c&&(C(c,"show"),M(u,"aria-expanded","false"),setTimeout(()=>{Et(c),w(".show",a)||(C(a,"open"),Ht(e),e.isOpen=!1)},g)),e.isValid||(e.value=e.color.toString()),t||P(o),M(i,"tabindex","-1"),n&&M(n,"tabindex","-1")}}dispose(){const{input:t,parent:e}=this;this.hide(!0),St(this),[...e.children].forEach(e=>{e!==t&&e.remove()}),T(t,"tabindex"),k(t,{backgroundColor:""}),["txt-light","txt-dark"].forEach(t=>C(e,t)),y.remove(t,"color-picker")}}return x(Lt,{Color:pt,ColorPalette:dt,Version:"0.0.2alpha1",getInstance:t=>{return e=t,o="color-picker",y.get(e,o);var e,o},init:t=>new Lt(t),selector:'[data-function="color-picker"]',roundPart:D,setElementStyle:k,setAttribute:M,getBoundingClientRect:b}),Lt}));