@thednp/color-picker 0.0.1 → 0.0.2-alpha1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -0
- package/dist/css/color-picker.css +1 -1
- package/dist/css/color-picker.min.css +1 -1
- package/dist/css/color-picker.rtl.css +1 -1
- package/dist/css/color-picker.rtl.min.css +1 -1
- package/dist/js/color-esm.js +1178 -0
- package/dist/js/color-esm.min.js +2 -0
- package/dist/js/color-palette-esm.js +1252 -0
- package/dist/js/color-palette-esm.min.js +2 -0
- package/dist/js/color-palette.js +1260 -0
- package/dist/js/color-palette.min.js +2 -0
- package/dist/js/color-picker-element-esm.js +287 -319
- package/dist/js/color-picker-element-esm.min.js +2 -2
- package/dist/js/color-picker-element.js +289 -321
- package/dist/js/color-picker-element.min.js +2 -2
- package/dist/js/color-picker-esm.js +520 -552
- package/dist/js/color-picker-esm.min.js +2 -2
- package/dist/js/color-picker.js +522 -554
- package/dist/js/color-picker.min.js +2 -2
- package/dist/js/color.js +1186 -0
- package/dist/js/color.min.js +2 -0
- package/package.json +19 -3
- package/src/js/color-palette.js +10 -3
- package/src/js/color-picker-element.js +1 -1
- package/src/js/color-picker.js +7 -120
- package/src/js/color.js +88 -91
- package/src/js/util/getColorMenu.js +12 -7
- package/src/js/util/setMarkup.js +122 -0
- package/src/js/util/version.js +6 -0
- package/types/cp.d.ts +47 -17
- package/src/js/util/templates.js +0 -10
@@ -1,2 +1,2 @@
|
|
1
|
-
// ColorPicker v0.0.
|
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 n=this,{type:r}=e;(t[r]?[...t[r]]:[]).forEach(t=>{const[s,a]=t;[...a].forEach(t=>{if(s===n){const[n,a]=t;n.apply(s,[e]),a&&a.once&&o(s,r,n,a)}})})}const n=(n,o,r,s)=>{t[o]||(t[o]=new Map);const a=t[o];a.has(n)||a.set(n,new Map);const i=a.get(n),{size:l}=i;i&&i.set(r,s),l||n.addEventListener(o,e,s)},o=(n,o,r,s)=>{const a=t[o],i=a&&a.get(n),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(n),a&&a.size||delete t[o],i&&i.size||n.removeEventListener(o,e,c)},r="ArrowDown",s="ArrowUp",a="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 n=getComputedStyle(t);return e in n?n[e]:""}let v=0,x=0;const $=new Map;function y(t,e){const{width:n,height:o,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(n)/e||1,c=r>0&&Math.round(o)/r||1}return{width:n/l,height:o/c,top:r/c,right:s/l,bottom:a/c,left:i/l,x:i/l,y:r/c}}const k=[Document,Element,HTMLElement],S=[Element,HTMLElement];function A(t,e){const n=k.some(t=>e instanceof t)?e:m();return S.some(e=>t instanceof e)?t:n.querySelector(t)}function H(t,e){return(e&&k.some(t=>e instanceof t)?e:m()).getElementsByClassName(t)}const P=(t,e)=>Object.assign(t,e);function E(t){if("string"==typeof t)return m().createElement(t);const{tagName:e}=t,n={...t},o=E(e);return delete n.tagName,P(o,n),o}function L(t,e){if("string"==typeof e)return m().createElementNS(t,e);const{tagName:n}=e,o={...e},r=L(t,n);return delete o.tagName,P(r,o),r}const N=new Map,C={set:(t,e,n)=>{const o=A(t);if(!o)return;N.has(e)||N.set(e,new Map);N.get(e).set(o,n)},getAllFor:t=>N.get(t)||null,get:(t,e)=>{const n=A(t),o=C.getAllFor(e);return n&&o&&o.get(n)||null},remove:(t,e)=>{const n=A(t),o=N.get(e);o&&n&&(o.delete(n),0===o.size&&N.delete(e))}},M=t=>Object.keys(t),T=(t,e)=>P(t.style,e),R=(t,e)=>t.getAttribute(e);function F(t){return"true"===t||"false"!==t&&(Number.isNaN(+t)?""===t||"null"===t?null:t:+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,n)=>t.setAttribute(e,n),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"];function W(t){const e=Math.floor(t);return t-e<.5?e:Math.round(t)}const z=["rgb","hex","hsl","hsb","hwb"],G="deg|rad|grad|turn",X=`[-\\+]?\\d*\\.?\\d+(?:${G})?`,Y="(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)",q=`(?:${Y})|(?:${X})`,J=`[\\s|\\(]+(${q})[,|\\s]+(${Y})[,|\\s]+(${Y})[,|\\s|\\/\\s]*(${Y})?\\s*\\)?`,Z={CSS_UNIT:new RegExp(q),hwb:new RegExp("hwb"+J),rgb:new RegExp("rgb(?:a)?"+J),hsl:new RegExp("hsl(?:a)?"+J),hsv:new RegExp("hsv(?:a)?"+J),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 Q(t){return(""+t).includes(".")&&1===parseFloat(t)}function tt(t){return(""+t).includes("%")}function et(t){return Boolean(Z.CSS_UNIT.exec(String(t)))}function nt(t,e){let n=t;return Q(n)&&(n="100%"),n=360===e?n:Math.min(e,Math.max(0,parseFloat(n))),function(t){return G.split("|").some(e=>(""+t).includes(e))}(t)&&(n=t.replace(new RegExp(G),"")),tt(n)&&(n=parseInt(String(n*e),10)/100),Math.abs(n-e)<1e-6?1:(n=360===e?(n<0?n%e+e:n%e)/parseFloat(String(e)):n%e/parseFloat(String(e)),n)}function ot(t){let e=parseFloat(""+t);return(Number.isNaN(e)||e<0||e>1)&&(e=1),e}function rt(t){return Math.min(1,Math.max(0,t))}function st(t){const e=m(n).head;var n;T(e,{color:t});const o=w(e,"color");return T(e,{color:""}),o}function at(t){return W(255*t).toString(16)}function it(t){return lt(t)/255}function lt(t){return parseInt(t,16)}function ct(t){return 1===t.length?"0"+t:String(t)}function ut(t,e,n){const o=t/255,r=e/255,s=n/255,a=Math.max(o,r,s),i=Math.min(o,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 o:l=(r-s)/t+(r<s?6:0);break;case r:l=(s-o)/t+2;break;case s:l=(o-r)/t+4}l/=6}return{h:l,s:c,l:u}}function ht(t,e,n){let o=n;return o<0&&(o+=1),o>1&&(o-=1),o<1/6?t+6*o*(e-t):o<.5?e:o<2/3?t+(e-t)*(2/3-o)*6:t}function gt(t,e,n){const o=t/255,r=e/255,s=n/255;let a=0,i=0;const l=Math.min(o,r,s),c=Math.max(o,r,s),u=1-c;if(c===l)return{h:0,w:l,b:u};o===l?(a=r-s,i=3):(a=r===l?s-o:o-r,i=r===l?5:1);const h=(i-a/(c-l))/6;return{h:1===h?0:h,w:l,b:u}}function pt(t,e,n){if(e+n>=1){const t=e/(e+n)*255;return{r:t,g:t,b:t}}let{r:o,g:r,b:s}=dt(t,1,.5);return[o,r,s]=[o,r,s].map(t=>t/255*(1-e-n)+e).map(t=>255*t),{r:o,g:r,b:s}}function dt(t,e,n){let o=0,r=0,s=0;if(0===e)r=n,s=n,o=n;else{const a=n<.5?n*(1+e):n+e-n*e,i=2*n-a;o=ht(i,a,t+1/3),r=ht(i,a,t),s=ht(i,a,t-1/3)}return[o,r,s]=[o,r,s].map(t=>255*t),{r:o,g:r,b:s}}function bt(t,e,n){const o=t/255,r=e/255,s=n/255,a=Math.max(o,r,s),i=Math.min(o,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 o:l=(r-s)/u+(r<s?6:0);break;case r:l=(s-o)/u+2;break;case s:l=(o-r)/u+4}l/=6}return{h:l,s:h,v:c}}function ft(t,e,n){const o=6*t,r=e,s=n,a=Math.floor(o),i=o-a,l=s*(1-r),c=s*(1-i*r),u=s*(1-(1-i)*r),h=a%6;return{r:255*[s,c,l,l,u,s][h],g:255*[u,s,s,c,l,l][h],b:255*[l,l,u,s,s,c][h]}}function mt(t,e,n,o){const r=[ct(W(t).toString(16)),ct(W(e).toString(16)),ct(W(n).toString(16))];return o&&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 wt(t,e,n,o,r){const s=[ct(W(t).toString(16)),ct(W(e).toString(16)),ct(W(n).toString(16)),ct(at(o))];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 vt(t){return{r:t>>16,g:(65280&t)>>8,b:255&t}}function xt(t){let e=t.trim().toLowerCase();if(0===e.length)return{r:0,g:0,b:0,a:0};let n=!1;if(function(t){return!["#",...z].some(e=>t.includes(e))&&!/[0-9]/.test(t)}(e))e=st(e),n=!0;else if(j.includes(e)){const t="transparent"===e,n=t?0:255;return{r:n,g:n,b:n,a:t?0:1,format:"rgb"}}let[,o,r,s,a]=Z.rgb.exec(e)||[];return o&&r&&s?{r:o,g:r,b:s,a:void 0!==a?a:1,format:"rgb"}:([,o,r,s,a]=Z.hsl.exec(e)||[],o&&r&&s?{h:o,s:r,l:s,a:void 0!==a?a:1,format:"hsl"}:([,o,r,s,a]=Z.hsv.exec(e)||[],o&&r&&s?{h:o,s:r,v:s,a:void 0!==a?a:1,format:"hsv"}:([,o,r,s,a]=Z.hwb.exec(e)||[],o&&r&&s?{h:o,w:r,b:s,a:void 0!==a?a:1,format:"hwb"}:([,o,r,s,a]=Z.hex8.exec(e)||[],o&&r&&s&&a?{r:lt(o),g:lt(r),b:lt(s),a:it(a),format:n?"rgb":"hex"}:([,o,r,s]=Z.hex6.exec(e)||[],o&&r&&s?{r:lt(o),g:lt(r),b:lt(s),format:n?"rgb":"hex"}:([,o,r,s,a]=Z.hex4.exec(e)||[],o&&r&&s&&a?{r:lt(o+o),g:lt(r+r),b:lt(s+s),a:it(a+a),format:n?"rgb":"hex"}:([,o,r,s]=Z.hex3.exec(e)||[],!!(o&&r&&s)&&{r:lt(o+o),g:lt(r+r),b:lt(s+s),format:n?"rgb":"hex"})))))))}function $t(t){let e={r:0,g:0,b:0},n=t,o=1,r=null,s=null,a=null,i=null,l=null,c=null,u=null,h=null,g=!1,p="hex";return"string"==typeof t&&(n=xt(t),n&&(g=!0)),"object"==typeof n&&(et(n.r)&&et(n.g)&&et(n.b)?(({r:u,g:h,b:l}=n),[u,h,l]=[u,h,l].map(t=>255*nt(t,tt(t)?100:255)),e={r:u,g:h,b:l},g=!0,p="rgb"):et(n.h)&&et(n.s)&&et(n.v)?(({h:c,s:r,v:s}=n),c="number"==typeof c?c:nt(c,360),r="number"==typeof r?r:nt(r,100),s="number"==typeof s?s:nt(s,100),e=ft(c,r,s),g=!0,p="hsv"):et(n.h)&&et(n.s)&&et(n.l)?(({h:c,s:r,l:a}=n),c="number"==typeof c?c:nt(c,360),r="number"==typeof r?r:nt(r,100),a="number"==typeof a?a:nt(a,100),e=dt(c,r,a),g=!0,p="hsl"):et(n.h)&&et(n.w)&&et(n.b)&&(({h:c,w:i,b:l}=n),c="number"==typeof c?c:nt(c,360),i="number"==typeof i?i:nt(i,100),l="number"==typeof l?l:nt(l,100),e=pt(c,i,l),g=!0,p="hwb"),et(n.a)&&(o=n.a,o=tt(""+o)?nt(o,100):o)),{ok:g,format:n.format||p,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(o)}}class yt{constructor(t,e){let n=t;const o=e&&z.includes(e)?e:"rgb";n instanceof yt&&(n=$t(n)),"number"==typeof n&&(n=vt(n));const{r:r,g:s,b:a,a:i,ok:l,format:c}=$t(n);this.originalInput=n,this.r=r,this.g=s,this.b=a,this.a=i,this.ok=l,this.format=o||c}get isValid(){return this.ok}get isDark(){return this.brightness<120}get luminance(){const{r:t,g:e,b:n}=this;let o=0,r=0,s=0;const a=t/255,i=e/255,l=n/255;return o=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*o+.7152*r+.0722*s}get brightness(){const{r:t,g:e,b:n}=this;return(299*t+587*e+114*n)/1e3}toRgb(){const{r:t,g:e,b:n,a:o}=this;return{r:t,g:e,b:n,a:W(100*o)/100}}toRgbString(){const{r:t,g:e,b:n,a:o}=this.toRgb(),[r,s,a]=[t,e,n].map(W);return 1===o?`rgb(${r}, ${s}, ${a})`:`rgba(${r}, ${s}, ${a}, ${o})`}toRgbCSS4String(){const{r:t,g:e,b:n,a:o}=this.toRgb(),[r,s,a]=[t,e,n].map(W);return`rgb(${r} ${s} ${a}${1===o?"":` / ${W(100*o)}%`})`}toHex(t){const{r:e,g:n,b:o,a:r}=this.toRgb();return 1===r?mt(e,n,o,t):wt(e,n,o,r,t)}toHexString(t){return"#"+this.toHex(t)}toHex8(t){const{r:e,g:n,b:o,a:r}=this.toRgb();return wt(e,n,o,r,t)}toHex8String(t){return"#"+this.toHex8(t)}toHsv(){const{r:t,g:e,b:n,a:o}=this.toRgb(),{h:r,s:s,v:a}=bt(t,e,n);return{h:r,s:s,v:a,a:o}}toHsl(){const{r:t,g:e,b:n,a:o}=this.toRgb(),{h:r,s:s,l:a}=ut(t,e,n);return{h:r,s:s,l:a,a:o}}toHslString(){let{h:t,s:e,l:n,a:o}=this.toHsl();return t=W(360*t),e=W(100*e),n=W(100*n),o=W(100*o)/100,1===o?`hsl(${t}, ${e}%, ${n}%)`:`hsla(${t}, ${e}%, ${n}%, ${o})`}toHslCSS4String(){let{h:t,s:e,l:n,a:o}=this.toHsl();t=W(360*t),e=W(100*e),n=W(100*n),o=W(100*o);return`hsl(${t}deg ${e}% ${n}%${o<100?` / ${W(o)}%`:""})`}toHwb(){const{r:t,g:e,b:n,a:o}=this,{h:r,w:s,b:a}=gt(t,e,n);return{h:r,w:s,b:a,a:o}}toHwbString(){let{h:t,w:e,b:n,a:o}=this.toHwb();t=W(360*t),e=W(100*e),n=W(100*n),o=W(100*o);return`hwb(${t}deg ${e}% ${n}%${o<100?` / ${W(o)}%`:""})`}setAlpha(t){return this.a=ot(t),this}saturate(t){if("number"!=typeof t)return this;const{h:e,s:n,l:o}=this.toHsl(),{r:r,g:s,b:a}=dt(e,rt(n+t/100),o);return P(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:n,l:o}=this.toHsl(),{r:r,g:s,b:a}=dt(e,n,rt(o+t/100));return P(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:n,l:o}=this.toHsl(),{r:r,g:s,b:a}=dt(rt((360*e+t)%360/360),n,o);return P(this,{r:r,g:s,b:a}),this}clone(){return new yt(this)}toString(t){const{format:e}=this;return"hex"===e?this.toHexString(t):"hsl"===e?this.toHslString():"hwb"===e?this.toHwbString():this.toRgbString()}}P(yt,{ANGLES:G,CSS_ANGLE:X,CSS_INTEGER:"[-\\+]?\\d+%?",CSS_NUMBER:"[-\\+]?\\d*\\.\\d+%?",CSS_UNIT:Y,CSS_UNIT2:q,PERMISSIVE_MATCH:J,matchers:Z,isOnePointZero:Q,isPercentage:tt,isValidCSSUnit:et,pad2:ct,clamp01:rt,bound01:nt,boundAlpha:ot,getRGBFromName:st,convertHexToDecimal:it,convertDecimalToHex:at,rgbToHsl:ut,rgbToHex:mt,rgbToHsv:bt,rgbToHwb:gt,rgbaToHex:wt,hslToRgb:dt,hsvToRgb:ft,hueToRgb:ht,hwbToRgb:pt,parseIntFromHex:lt,numberInputToObject:vt,stringInputToObject:xt,inputToRGB:$t,roundPart:W,ObjectAssign:P});class kt{constructor(...t){let e=0,n=12,o=10,r=[.5];if(3===t.length)[e,n,o]=t;else{if(2!==t.length)throw TypeError("ColorPalette requires minimum 2 arguments");[n,o]=t}const s=[],a=360/n,i=W((o-(o%2?1:0))/2),l=100/(o+(o%2?0:1))/100;let c=.25;c=[4,5].includes(o)?.2:c,c=[6,7].includes(o)?.15:c,c=[8,9].includes(o)?.11:c,c=[10,11].includes(o)?.09:c,c=[12,13].includes(o)?.075:c,c=o>13?l:c;for(let t=1;t<i+1;t+=1)r=[...r,.5+c*t];for(let t=1;t<o-i;t+=1)r=[.5-c*t,...r];for(let t=0;t<n;t+=1){const n=(e+t*a)%360/360;r.forEach(t=>{s.push(new yt({h:n,s:1,l:t}).toHexString())})}this.hue=e,this.hueSteps=n,this.lightSteps=o,this.colors=s}}function St(t,e,n){const{input:o,format:r,componentLabels:s}=t,{defaultsLabel:a,presetsLabel:i}=s,l="color-options"===n,c=e instanceof kt,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=n;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",k=`calc(${f} * ${$}rem + ${f-1} * ${x})`,S=E({tagName:"ul",className:v});var A,H;return V(S,"role","listbox"),V(S,"aria-label",u),w&&(A=S,M(H={"--grid-item-size":$+"rem","--grid-fit":d,"--grid-gap":x,"--grid-height":y,"--grid-hover-height":k}).forEach(t=>{A.style.setProperty(t,H[t])})),h.forEach(t=>{const[e,n]=t.trim().split(":"),s=new yt(e,r).toString()===R(o,"value"),a=E({tagName:"li",className:"color-option"+(s?" active":""),innerText:""+(n||t)});V(a,"tabindex","0"),V(a,"data-value",""+e),V(a,"role","option"),V(a,"aria-selected",s?"true":"false"),l&&T(a,{backgroundColor:t}),S.append(a)}),S}function At(t){try{JSON.parse(t)}catch(t){return!1}return!0}const Ht={componentLabels:B,colorLabels:_,format:"rgb",colorPresets:!1,colorKeywords:!1};function Pt(t){const{input:e,parent:n,format:o,id:r,componentLabels:s,colorKeywords:a,colorPresets:i}=t,l=R(e,"value")||"#fff",{toggleLabel:c,pickerLabel:u,formatLabel:h,hexLabel:g}=s,p=j.includes(l)?"#fff":l;t.color=new yt(p,o);const d=f?" mobile":"",b="hex"===o?g:o.toUpperCase(),m=E({id:"picker-btn-"+r,tagName:"button",className:"picker-toggle btn-appearance"});V(m,"aria-expanded","false"),V(m,"aria-haspopup","true"),m.append(E({tagName:"span",className:"v-hidden",innerText:`${u}. ${h}: ${b}`}));const w=E({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:n}=t,{hueLabel:o,alphaLabel:r,lightnessLabel:s,saturationLabel:a,whitenessLabel:i,blacknessLabel:l}=n,c="hsl"===e?360:100,u="hsl"===e?100:360;let h="hsl"===e?`${o} & ${s}`:`${s} & ${a}`;h="hwb"===e?`${i} & ${l}`:h;const g="hsl"===e?""+a:""+o,p=E({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:n,l:o,min:r,max:s}=t,a=E({tagName:"div",className:"color-control"});V(a,"role","presentation"),a.append(E({tagName:"div",className:"visual-control visual-control"+e}));const i=E({tagName:"div",className:n+" knob",ariaLive:"polite"});V(i,"aria-label",o),V(i,"role","slider"),V(i,"tabindex","0"),V(i,"aria-valuemin",""+r),V(i,"aria-valuemax",""+s),a.append(i),p.append(a)}),p}(t),x=function(t){const{format:e,id:n,componentLabels:o}=t,r=E({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?["#"]:(a=t,a.toUpperCase()).split("");var a;const i=`color_${e}_${t}_${n}`,l=o[t+"Label"],c=E({tagName:"label"});V(c,"for",i),c.append(E({tagName:"span",ariaHidden:"true",innerText:s+":"}),E({tagName:"span",className:"v-hidden",innerText:l}));const u=E({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")),P(u,{min:"0",max:h,step:g}),r.append(c,u)}),r}(t);if(w.append(v,x),e.before(m),n.append(w),a||i){const e=E({tagName:"div",className:"color-dropdown scrollable menu"+d});if(i instanceof Array&&i.length||i instanceof kt&&i.colors){const n=St(t,i,"color-options");e.append(n)}if(a&&a.length){const n=St(t,a,"color-defaults");e.append(n)}const o=E({tagName:"button",className:"menu-toggle btn-appearance"});V(o,"tabindex","-1"),V(o,"aria-expanded","false"),V(o,"aria-haspopup","true");const r=encodeURI("http://www.w3.org/2000/svg"),s=L(r,{tagName:"svg"});V(s,"xmlns",r),V(s,"viewBox","0 0 512 512"),V(s,"aria-hidden","true");const l=L(r,{tagName:"path"});V(l,"d","M98,158l157,156L411,158l27,27L255,368L71,185L98,158z"),V(l,"fill","#fff"),s.append(l),o.append(E({tagName:"span",className:"v-hidden",innerText:""+c}),s),n.append(o,e)}a&&j.includes(l)&&(t.value=l),V(e,"tabindex","-1")}function Et(t,e){const r=e?n:o,{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 Lt(t,e){const r=e?n:o,{input:s,colorMenu:a,parent:i}=t,l=m(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),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),[s,...t.inputs].forEach(e=>r(e,"change",t.changeHandler)),a&&(r(a,"click",t.menuClickHandler),r(a,"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,n;e=t.input,n=new CustomEvent("colorpicker.change"),e.dispatchEvent(n)}function Ct(t){t&&["bottom","top"].forEach(e=>I(t,e))}function Mt(t,e){const{colorPicker:n,colorMenu:o,menuToggle:r,pickerToggle:s,parent:a}=t,i=e===n,l=i?o:n,c=i?r:s,u=i?s:r;O(a,"open")||K(a,"open"),l&&(I(l,"show"),Ct(l)),K(e,"bottom"),e.offsetHeight,K(e,"show"),i&&t.update(),t.isOpen||(Lt(t,!0),t.updateDropdownPosition(),t.isOpen=!0,V(t.input,"tabindex","0"),r&&V(r,"tabindex","0")),V(u,"aria-expanded","true"),c&&V(c,"aria-expanded","false")}class Tt{constructor(t,e){const n=this,o=A(t);if(!o)throw new TypeError(`ColorPicker target ${t} cannot be found.`);n.input=o;const r=function t(e,n){return e?e.closest(n)||t(e.getRootNode().host,n):null}(o,".color-picker,color-picker");if(!r)throw new TypeError("ColorPicker requires a specific markup to work.");n.parent=r,n.id=function t(e,n){let o=n?v:x;if(n){const r=t(e),s=$.get(r)||new Map;$.has(r)||$.set(r,s),s.has(n)?o=s.get(n):(s.set(n,o),v+=1)}else{const t=e.id||e;$.has(t)?o=$.get(t):($.set(t,o),x+=1)}return o}(o,"color-picker"),n.dragElement=null,n.isOpen=!1,n.controlPositions={c1x:0,c1y:0,c2y:0,c3y:0},n.colorLabels={},n.colorKeywords=void 0,n.colorPresets=void 0;const{format:s,componentLabels:a,colorLabels:i,colorKeywords:l,colorPresets:c}=function(t,e,n,o){const r={...t.dataset},s={},a={};return M(r).forEach(t=>{const e=o&&t.includes(o)?t.replace(o,"").replace(/[A-Z]/,t=>t.toLowerCase()):t;a[e]=F(r[t])}),M(n).forEach(t=>{n[t]=F(n[t])}),M(e).forEach(o=>{s[o]=o in n?n[o]:o in a?a[o]:"title"===o?R(t,"title"):e[o]}),s}(this.isCE?r:o,Ht,e||{});let u=_;i instanceof Array&&17===i.length?u=i:i&&17===i.split(",").length&&(u=i.split(",")),_.forEach((t,e)=>{n.colorLabels[t]=u[e].trim()});const h=P({},B),g=a&&At(a)?JSON.parse(a):a||{};if(n.componentLabels=P(h,g),n.color=new yt("white",s),n.format=s,l instanceof Array?n.colorKeywords=l:"string"==typeof l&&l.length&&(n.colorKeywords=l.split(",")),c instanceof Array)n.colorPresets=c;else if("string"==typeof c&&c.length)if(At(c)){const{hue:t,hueSteps:e,lightSteps:o}=JSON.parse(c);n.colorPresets=new kt(t,e,o)}else n.colorPresets=c.split(",").map(t=>t.trim());n.showPicker=n.showPicker.bind(n),n.togglePicker=n.togglePicker.bind(n),n.toggleMenu=n.toggleMenu.bind(n),n.menuClickHandler=n.menuClickHandler.bind(n),n.menuKeyHandler=n.menuKeyHandler.bind(n),n.pointerDown=n.pointerDown.bind(n),n.pointerMove=n.pointerMove.bind(n),n.pointerUp=n.pointerUp.bind(n),n.update=n.update.bind(n),n.handleScroll=n.handleScroll.bind(n),n.handleFocusOut=n.handleFocusOut.bind(n),n.changeHandler=n.changeHandler.bind(n),n.handleDismiss=n.handleDismiss.bind(n),n.keyToggle=n.keyToggle.bind(n),n.handleKnobs=n.handleKnobs.bind(n),Pt(n);const[p,d]=H("color-dropdown",r);n.pickerToggle=A(".picker-toggle",r),n.menuToggle=A(".menu-toggle",r),n.colorPicker=p,n.colorMenu=d,n.inputs=[...H("color-input",r)];const[b]=H("color-controls",r);n.controls=b,n.controlKnobs=[...H("knob",b)],n.visuals=[...H("visual-control",b)],n.update(),Et(n,!0),C.set(o,"color-picker",n)}get value(){return this.input.value}set value(t){this.input.value=t}get hasNonColor(){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 yt(t).isValid}updateVisuals(){const{format:t,controlPositions:e,visuals:n}=this,[o,r,s]=n,{offsetWidth:a,offsetHeight:i}=o,l="hsl"===t?e.c1x/a:e.c2y/i,{r:c,g:u,b:h}=yt.hslToRgb(l,1,.5),g="linear-gradient(rgb(255,255,255) 0%, rgb(255,255,255) 100%)",p=1-e.c3y/i,d=W(100*p)/100;if("hsl"!==t){const t=new yt({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%)";T(o,{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}`}),T(r,{background:e})}else{const t=W(e.c2y/i*100),n=new yt({r:255,g:0,b:0,a:p}).saturate(-t).toRgbString(),s=new yt({r:255,g:255,b:0,a:p}).saturate(-t).toRgbString(),a=new yt({r:0,g:255,b:0,a:p}).saturate(-t).toRgbString(),l=new yt({r:0,g:255,b:255,a:p}).saturate(-t).toRgbString(),b=new yt({r:0,g:0,b:255,a:p}).saturate(-t).toRgbString(),f=new yt({r:255,g:0,b:255,a:p}).saturate(-t).toRgbString(),m=new yt({r:255,g:0,b:0,a:p}).saturate(-t).toRgbString();T(o,{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 ${n} 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 yt({r:c,g:u,b:h}).greyscale().toRgb();T(r,{background:`linear-gradient(rgb(${c},${u},${h}) 0%, rgb(${w},${v},${x}) 100%)`})}T(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}=m(this.input);(f&&this.dragElement||e&&this.controlKnobs.includes(e))&&(t.stopPropagation(),t.preventDefault()),this.updateDropdownPosition()}menuKeyHandler(t){const{target:e,code:n}=t,{previousElementSibling:o,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,s,c].includes(n)&&t.preventDefault(),g?f&&n===s?D(f):m&&n===r?D(m):o&&n===a?D(o):u&&n===i&&D(u):o&&[a,s].includes(n)?D(o):u&&[i,r].includes(n)&&D(u),[l,c].includes(n)&&this.menuClickHandler({target:e})}menuClickHandler(t){const e=this,{target:n}=t,{colorMenu:o}=e,r=(R(n,"data-value")||"").trim();if(!r.length)return;const s=A("li.active",o);let a=j.includes(r)?"white":r;a="transparent"===r?"rgba(0,0,0,0)":r;const{r:i,g:l,b:c,a:u}=new yt(a);P(e.color,{r:i,g:l,b:c,a:u}),e.update(),s!==n&&(s&&(I(s,"active"),U(s,"aria-selected")),K(n,"active"),V(n,"aria-selected","true"),j.includes(r)&&(e.value=r),Nt(e))}pointerDown(t){const e=this,{type:n,target:o,touches:r,pageX:s,pageY:a}=t,{colorMenu:i,visuals:l,controlKnobs:c}=e,[u,h,g]=l,[p,d,b]=c,f=O(o,"visual-control")?o:A(".visual-control",o.parentElement),m=y(f),w="touchstart"===n?r[0].pageX:s,v="touchstart"===n?r[0].pageY:a,x=w-window.pageXOffset-m.left,$=v-window.pageYOffset-m.top;if(o===u||o===p?(e.dragElement=f,e.changeControl1(x,$)):o===h||o===d?(e.dragElement=f,e.changeControl2($)):o!==g&&o!==b||(e.dragElement=f,e.changeAlpha($)),i){const t=A("li.active",i);t&&(I(t,"active"),U(t,"aria-selected"))}t.preventDefault()}pointerUp({target:t}){const e=this,{parent:n}=e,o=m(n),r=null!==A(".color-picker,color-picker.open",o),s=o.getSelection();e.dragElement||s.toString().length||n.contains(t)||e.hide(r),e.dragElement=null}pointerMove(t){const e=this,{dragElement:n,visuals:o}=e,[r,s,a]=o,{type:i,touches:l,pageX:c,pageY:u}=t;if(!n)return;const h=y(n),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;n===r&&e.changeControl1(d,b),n===s&&e.changeControl2(b),n===a&&e.changeAlpha(b)}handleKnobs(t){const{target:e,code:n}=t,o=this;if(![s,r,a,i].includes(n))return;t.preventDefault();const{format:l,controlKnobs:c,visuals:u}=o,{offsetWidth:h,offsetHeight:g}=u[0],[p,d,b]=c,{activeElement:f}=m(p),w=g/("hsl"===l?100:360);if(c.find(t=>t===f)){let c=0,u=0;if(e===p){const t=h/("hsl"===l?360:100);[a,i].includes(n)?o.controlPositions.c1x+=n===i?t:-t:[s,r].includes(n)&&(o.controlPositions.c1y+=n===r?w:-w),c=o.controlPositions.c1x,u=o.controlPositions.c1y,o.changeControl1(c,u)}else e===d?(o.controlPositions.c2y+=[r,i].includes(n)?w:-w,u=o.controlPositions.c2y,o.changeControl2(u)):e===b&&(o.controlPositions.c3y+=[r,i].includes(n)?w:-w,u=o.controlPositions.c3y,o.changeAlpha(u));o.handleScroll(t)}}changeHandler(){const t=this;let e;const{inputs:n,format:o,value:r,input:s,controlPositions:a,visuals:i}=t,{activeElement:l}=m(s),{offsetHeight:c}=i[0],[u,,,h]=n,[g,p,d,b]="rgb"===o?n.map(t=>parseFloat(t.value)/(t===h?100:1)):n.map(t=>parseFloat(t.value)/(t!==u?100:360)),f=t.hasNonColor&&j.includes(r),w=h?b:1-a.c3y/c;if(l===s||l&&n.includes(l)){e=l===s?f?"white":r:"hex"===o?u.value:"hsl"===o?{h:g,s:p,l:d,a:w}:"hwb"===o?{h:g,w:p,b:d,a:w}:{r:g,g:p,b:d,a:w};const{r:n,g:a,b:i,a:c}=new yt(e);P(t.color,{r:n,g:a,b:i,a:c}),t.setControlPositions(),t.updateAppearance(),t.updateInputs(),t.updateControls(),t.updateVisuals(),l===s&&f&&(t.value=r)}}changeControl1(t,e){let[n,o]=[0,0];const{format:r,controlPositions:s,visuals:a}=this,{offsetHeight:i,offsetWidth:l}=a[0];t>l?n=l:t>=0&&(n=t),e>i?o=i:e>=0&&(o=e);const c="hsl"===r?n/l:s.c2y/i,u="hsl"===r?1-s.c2y/i:n/l,h=1-o/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 yt(p);P(this.color,{r:d,g:b,b:f,a:m}),this.controlPositions.c1x=n,this.controlPositions.c1y=o,this.updateAppearance(),this.updateInputs(),this.updateControls(),this.updateVisuals()}changeControl2(t){const{format:e,controlPositions:n,visuals:o}=this,{offsetHeight:r,offsetWidth:s}=o[0];let a=0;t>r?a=r:t>=0&&(a=t);const i="hsl"===e?n.c1x/s:a/r,l="hsl"===e?1-a/r:n.c1x/s,c=1-n.c1y/r,u=1-n.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 yt(h);P(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:n}=e[0];let o=0;t>n?o=n:t>=0&&(o=t);const r=1-o/n;this.color.setAlpha(r),this.controlPositions.c3y=o,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:n}=this,o=y(t),{top:r,bottom:s}=o,{offsetHeight:a}=t,i=(l=t,m(l).documentElement).clientHeight;var l;const c=O(e,"show")?e:n;if(!c)return;const{offsetHeight:u}=c,h=i-s,g=r,p=r+u+a>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:n,hsl:o,hsv:r}=this,{offsetHeight:s,offsetWidth:a}=e[0],i=n.a,l=o.h,c="hsl"!==t?r.s:o.s,u="hsl"!==t?r.v:o.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:n,color:o,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}=o.toRgb(),[f,m,w]=c,v=W(360*s.h),x=o.a,$=W(100*("hsl"===l?s.s:a.s)),y=W(100*s.l),k=100*a.v;let S;if(100===y&&0===$)S=n.white;else if(0===y)S=n.black;else if(0===$)S=n.grey;else if(v<15||v>=345)S=n.red;else if(v>=15&&v<45)S=k>80&&$>80?n.orange:n.brown;else if(v>=45&&v<75){const t=v>=54&&v<75&&k<80;S=v>46&&v<54&&k<80&&$>90?n.gold:n.yellow,S=t?n.olive:S}else v>=75&&v<155?S=k<68?n.green:n.lime:v>=155&&v<175?S=n.teal:v>=175&&v<195?S=n.cyan:v>=195&&v<255?S=n.blue:v>=255&&v<270?S=n.violet:v>=270&&v<295?S=n.magenta:v>=295&&v<345&&(S=n.pink);let A=`${h} ${i.split("").join(" ")}`;if("hsl"===l)A=`HSL: ${v}°, ${$}%, ${y}%`,V(f,"aria-description",`${g}: ${A}. ${u}: ${S}.`),V(f,"aria-valuetext",`${v}° & ${y}%`),V(f,"aria-valuenow",""+v),V(m,"aria-valuetext",$+"%"),V(m,"aria-valuenow",""+$);else if("hwb"===l){const{hwb:e}=t,n=W(100*e.w),o=W(100*e.b);A=`HWB: ${v}°, ${n}%, ${o}%`,V(f,"aria-description",`${g}: ${A}. ${u}: ${S}.`),V(f,"aria-valuetext",`${n}% & ${o}%`),V(f,"aria-valuenow",""+n),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",`${y}% & ${$}%`),V(f,"aria-valuenow",""+y),V(m,"aria-valuetext",v+"°"),V(m,"aria-valuenow",""+v);const H=W(100*x);V(w,"aria-valuetext",H+"%"),V(w,"aria-valuenow",""+H);const P=o.toString();T(t.input,{backgroundColor:P}),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;let{c1x:n,c1y:o,c2y:r,c3y:s}=e;const[a,i,l]=t;[n,o,r,s]=[n,o,r,s].map(W),T(a,{transform:`translate3d(${n-4}px,${o-4}px,0)`}),T(i,{transform:`translate3d(0,${r-4}px,0)`}),T(l,{transform:`translate3d(0,${s-4}px,0)`})}updateInputs(t){const e=this,{value:n,format:o,inputs:r,color:s,hsl:a}=e,[i,l,c,u]=r,h=W(100*s.a),g=W(360*a.h);let p;if("hex"===o)p=e.color.toHexString(!0),i.value=e.hex;else if("hsl"===o){const t=W(100*a.l),n=W(100*a.s);p=e.color.toHslString(),i.value=""+g,l.value=""+n,c.value=""+t,u.value=""+h}else if("hwb"===o){const{w:t,b:n}=e.hwb,o=W(100*t),r=W(100*n);p=e.color.toHwbString(),i.value=""+g,l.value=""+o,c.value=""+r,u.value=""+h}else if("rgb"===o){let{r:t,g:n,b:o}=e.rgb;[t,n,o]=[t,n,o].map(W),p=e.color.toRgbString(),i.value=""+t,l.value=""+n,c.value=""+o,u.value=""+h}e.value=""+p,t||p===n||Nt(e)}keyToggle(t){const e=this,{menuToggle:n}=e,{activeElement:o}=m(n),{code:r}=t;[l,c].includes(r)&&(n&&o===n||!o)&&(t.preventDefault(),o?e.toggleMenu():e.togglePicker(t))}togglePicker(t){t.preventDefault();const e=this,{colorPicker:n}=e;e.isOpen&&O(n,"show")?e.hide(!0):Mt(e,n)}showPicker(){const t=this,{colorPicker:e}=t;["top","bottom"].some(t=>O(e,t))||Mt(t,e)}toggleMenu(){const t=this,{colorMenu:e}=t;t.isOpen&&O(e,"show")?t.hide(!0):Mt(t,e)}hide(t){const e=this;if(e.isOpen){const{pickerToggle:n,menuToggle:o,colorPicker:r,colorMenu:s,parent:a,input:i}=e,l=O(r,"show"),c=l?r:s,u=l?n:o,h=c&&function(t){const e=w(t,"transitionProperty"),n=w(t,"transitionDuration"),o=n.includes("ms")?1:1e3,r=e&&"none"!==e?parseFloat(n)*o:0;return Number.isNaN(r)?0:r}(c);c&&(I(c,"show"),V(u,"aria-expanded","false"),setTimeout(()=>{Ct(c),A(".show",a)||(I(a,"open"),Lt(e),e.isOpen=!1)},h)),e.isValid||(e.value=e.color.toString()),t||D(n),V(i,"tabindex","-1"),o&&V(o,"tabindex","-1")}}dispose(){const{input:t,parent:e}=this;this.hide(!0),Et(this),[...e.children].forEach(e=>{e!==t&&e.remove()}),U(t,"tabindex"),T(t,{backgroundColor:""}),["txt-light","txt-dark"].forEach(t=>I(e,t)),C.remove(t,"color-picker")}}return P(Tt,{Color:yt,ColorPalette:kt,Version:"0.0.1",getInstance:t=>{return e=t,n="color-picker",C.get(e,n);var e,n},init:t=>new Tt(t),selector:'[data-function="color-picker"]',roundPart:W,setElementStyle:T,setAttribute:V,getBoundingClientRect:y}),Tt}));
|
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}));
|