@thednp/color-picker 0.0.1-alpha2 → 0.0.1-alpha3
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +31 -15
- package/dist/css/color-picker.css +37 -15
- package/dist/css/color-picker.min.css +2 -2
- package/dist/css/color-picker.rtl.css +37 -15
- package/dist/css/color-picker.rtl.min.css +2 -2
- package/dist/js/color-picker-element-esm.js +164 -135
- package/dist/js/color-picker-element-esm.min.js +2 -2
- package/dist/js/color-picker-element.js +164 -135
- package/dist/js/color-picker-element.min.js +2 -2
- package/dist/js/color-picker-esm.js +159 -133
- package/dist/js/color-picker-esm.min.js +2 -2
- package/dist/js/color-picker.js +159 -133
- package/dist/js/color-picker.min.js +2 -2
- package/package.json +1 -1
- package/src/js/color-palette.js +18 -9
- package/src/js/color-picker-element.js +7 -3
- package/src/js/color-picker.js +59 -48
- package/src/js/color.js +33 -34
- package/src/js/util/getColorControls.js +3 -3
- package/src/js/util/getColorForm.js +0 -1
- package/src/js/util/getColorMenu.js +21 -28
- package/src/js/util/roundPart.js +9 -0
- package/src/js/util/setCSSProperties.js +12 -0
- package/src/js/util/tabindex.js +3 -0
- package/src/scss/color-picker.scss +35 -12
- package/types/cp.d.ts +1 -3
@@ -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 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.1alpha3 | 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 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)).map(W),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,[r,s,a]=[t,e,n].map(t=>W(t));return{r:r,g:s,b:a,a:W(100*o)/100}}toRgbString(){const{r:t,g:e,b:n,a:o}=this.toRgb();return 1===o?`rgb(${t}, ${e}, ${n})`:`rgba(${t}, ${e}, ${n}, ${o})`}toRgbCSS4String(){const{r:t,g:e,b:n,a:o}=this.toRgb();return`rgb(${t} ${e} ${n}${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{controlKnobs:l}=o,[c,u,h]=l,{activeElement:g}=m(c);if(l.find(t=>t===g)){let l=0,g=0;e===c?([a,i].includes(n)?o.controlPositions.c1x+=n===i?1:-1:[s,r].includes(n)&&(o.controlPositions.c1y+=n===r?1:-1),l=o.controlPositions.c1x,g=o.controlPositions.c1y,o.changeControl1(l,g)):e===u?(o.controlPositions.c2y+=[r,i].includes(n)?1:-1,g=o.controlPositions.c2y,o.changeControl2(g)):e===h&&(o.controlPositions.c3y+=[r,i].includes(n)?1:-1,g=o.controlPositions.c3y,o.changeAlpha(g)),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,{c1x:n,c1y:o,c2y:r,c3y:s}=e,[a,i,l]=t;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){const{r:t,g:n,b:o}=e.rgb;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.1alpha3",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}));
|
package/package.json
CHANGED
package/src/js/color-palette.js
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import roundPart from './util/roundPart';
|
1
2
|
import Color from './color';
|
2
3
|
|
3
4
|
/**
|
@@ -12,8 +13,8 @@ export default class ColorPalette {
|
|
12
13
|
* The `hue` parameter is optional, which would be set to 0.
|
13
14
|
* @param {number[]} args represeinting hue, hueSteps, lightSteps
|
14
15
|
* * `args.hue` the starting Hue [0, 360]
|
15
|
-
* * `args.hueSteps` Hue Steps Count [5,
|
16
|
-
* * `args.lightSteps` Lightness Steps Count [
|
16
|
+
* * `args.hueSteps` Hue Steps Count [5, 24]
|
17
|
+
* * `args.lightSteps` Lightness Steps Count [5, 12]
|
17
18
|
*/
|
18
19
|
constructor(...args) {
|
19
20
|
let hue = 0;
|
@@ -26,24 +27,32 @@ export default class ColorPalette {
|
|
26
27
|
} else if (args.length === 2) {
|
27
28
|
[hueSteps, lightSteps] = args;
|
28
29
|
} else {
|
29
|
-
throw TypeError('
|
30
|
+
throw TypeError('ColorPalette requires minimum 2 arguments');
|
30
31
|
}
|
31
32
|
|
32
33
|
/** @type {string[]} */
|
33
34
|
const colors = [];
|
34
35
|
|
35
36
|
const hueStep = 360 / hueSteps;
|
36
|
-
const
|
37
|
-
const
|
37
|
+
const half = roundPart((lightSteps - (lightSteps % 2 ? 1 : 0)) / 2);
|
38
|
+
const estimatedStep = 100 / (lightSteps + (lightSteps % 2 ? 0 : 1)) / 100;
|
39
|
+
|
40
|
+
let lightStep = 0.25;
|
41
|
+
lightStep = [4, 5].includes(lightSteps) ? 0.2 : lightStep;
|
42
|
+
lightStep = [6, 7].includes(lightSteps) ? 0.15 : lightStep;
|
43
|
+
lightStep = [8, 9].includes(lightSteps) ? 0.11 : lightStep;
|
44
|
+
lightStep = [10, 11].includes(lightSteps) ? 0.09 : lightStep;
|
45
|
+
lightStep = [12, 13].includes(lightSteps) ? 0.075 : lightStep;
|
46
|
+
lightStep = lightSteps > 13 ? estimatedStep : lightStep;
|
38
47
|
|
39
48
|
// light tints
|
40
|
-
for (let i =
|
41
|
-
lightnessArray = [...lightnessArray, (0.5 + lightStep * (i
|
49
|
+
for (let i = 1; i < half + 1; i += 1) {
|
50
|
+
lightnessArray = [...lightnessArray, (0.5 + lightStep * (i))];
|
42
51
|
}
|
43
52
|
|
44
53
|
// dark tints
|
45
|
-
for (let i =
|
46
|
-
lightnessArray = [(0.5 - lightStep * (i
|
54
|
+
for (let i = 1; i < lightSteps - half; i += 1) {
|
55
|
+
lightnessArray = [(0.5 - lightStep * (i)), ...lightnessArray];
|
47
56
|
}
|
48
57
|
|
49
58
|
// feed `colors` Array
|
@@ -5,7 +5,8 @@ import setAttribute from 'shorter-js/src/attr/setAttribute';
|
|
5
5
|
import getAttribute from 'shorter-js/src/attr/getAttribute';
|
6
6
|
|
7
7
|
import Color from './color';
|
8
|
-
import ColorPicker from './color-picker';
|
8
|
+
import ColorPicker, { getColorPickerInstance } from './color-picker';
|
9
|
+
import ColorPalette from './color-palette';
|
9
10
|
import Version from './version';
|
10
11
|
|
11
12
|
let CPID = 0;
|
@@ -13,8 +14,9 @@ let CPID = 0;
|
|
13
14
|
/**
|
14
15
|
* `ColorPickerElement` Web Component.
|
15
16
|
* @example
|
16
|
-
* <
|
17
|
-
*
|
17
|
+
* <label for="UNIQUE_ID">Label</label>
|
18
|
+
* <color-picker data-format="hex" data-value="#075">
|
19
|
+
* <input id="UNIQUE_ID" type="text" class="color-preview btn-appearance">
|
18
20
|
* </color-picker>
|
19
21
|
*/
|
20
22
|
class ColorPickerElement extends HTMLElement {
|
@@ -95,6 +97,8 @@ class ColorPickerElement extends HTMLElement {
|
|
95
97
|
ObjectAssign(ColorPickerElement, {
|
96
98
|
Color,
|
97
99
|
ColorPicker,
|
100
|
+
ColorPalette,
|
101
|
+
getInstance: getColorPickerInstance,
|
98
102
|
Version,
|
99
103
|
});
|
100
104
|
|
package/src/js/color-picker.js
CHANGED
@@ -67,7 +67,9 @@ import getColorForm from './util/getColorForm';
|
|
67
67
|
import getColorControls from './util/getColorControls';
|
68
68
|
import getColorMenu from './util/getColorMenu';
|
69
69
|
import vHidden from './util/vHidden';
|
70
|
+
import tabIndex from './util/tabindex';
|
70
71
|
import isValidJSON from './util/isValidJSON';
|
72
|
+
import roundPart from './util/roundPart';
|
71
73
|
import Color from './color';
|
72
74
|
import ColorPalette from './color-palette';
|
73
75
|
import Version from './version';
|
@@ -81,15 +83,15 @@ const colorPickerDefaults = {
|
|
81
83
|
componentLabels: colorPickerLabels,
|
82
84
|
colorLabels: colorNames,
|
83
85
|
format: 'rgb',
|
84
|
-
colorPresets:
|
85
|
-
colorKeywords:
|
86
|
+
colorPresets: false,
|
87
|
+
colorKeywords: false,
|
86
88
|
};
|
87
89
|
|
88
90
|
// ColorPicker Static Methods
|
89
91
|
// ==========================
|
90
92
|
|
91
93
|
/** @type {CP.GetInstance<ColorPicker>} */
|
92
|
-
const getColorPickerInstance = (element) => getInstance(element, colorPickerString);
|
94
|
+
export const getColorPickerInstance = (element) => getInstance(element, colorPickerString);
|
93
95
|
|
94
96
|
/** @type {CP.InitCallback<ColorPicker>} */
|
95
97
|
const initColorPicker = (element) => new ColorPicker(element);
|
@@ -171,7 +173,7 @@ function initCallback(self) {
|
|
171
173
|
tagName: 'button',
|
172
174
|
className: 'menu-toggle btn-appearance',
|
173
175
|
});
|
174
|
-
setAttribute(presetsBtn,
|
176
|
+
setAttribute(presetsBtn, tabIndex, '-1');
|
175
177
|
setAttribute(presetsBtn, ariaExpanded, 'false');
|
176
178
|
setAttribute(presetsBtn, ariaHasPopup, 'true');
|
177
179
|
|
@@ -198,7 +200,7 @@ function initCallback(self) {
|
|
198
200
|
if (colorKeywords && nonColors.includes(colorValue)) {
|
199
201
|
self.value = colorValue;
|
200
202
|
}
|
201
|
-
setAttribute(input,
|
203
|
+
setAttribute(input, tabIndex, '-1');
|
202
204
|
}
|
203
205
|
|
204
206
|
/**
|
@@ -299,8 +301,19 @@ function showDropdown(self, dropdown) {
|
|
299
301
|
addClass(dropdown, 'bottom');
|
300
302
|
reflow(dropdown);
|
301
303
|
addClass(dropdown, 'show');
|
304
|
+
|
302
305
|
if (isPicker) self.update();
|
303
|
-
|
306
|
+
|
307
|
+
if (!self.isOpen) {
|
308
|
+
toggleEventsOnShown(self, true);
|
309
|
+
self.updateDropdownPosition();
|
310
|
+
self.isOpen = true;
|
311
|
+
setAttribute(self.input, tabIndex, '0');
|
312
|
+
if (menuToggle) {
|
313
|
+
setAttribute(menuToggle, tabIndex, '0');
|
314
|
+
}
|
315
|
+
}
|
316
|
+
|
304
317
|
setAttribute(nextBtn, ariaExpanded, 'true');
|
305
318
|
if (activeBtn) {
|
306
319
|
setAttribute(activeBtn, ariaExpanded, 'false');
|
@@ -470,7 +483,7 @@ export default class ColorPicker {
|
|
470
483
|
set value(v) { this.input.value = v; }
|
471
484
|
|
472
485
|
/** Check if the colour presets include any non-colour. */
|
473
|
-
get
|
486
|
+
get hasNonColor() {
|
474
487
|
return this.colorKeywords instanceof Array
|
475
488
|
&& this.colorKeywords.some((x) => nonColors.includes(x));
|
476
489
|
}
|
@@ -526,7 +539,7 @@ export default class ColorPicker {
|
|
526
539
|
const { r, g, b } = Color.hslToRgb(hue, 1, 0.5);
|
527
540
|
const whiteGrad = 'linear-gradient(rgb(255,255,255) 0%, rgb(255,255,255) 100%)';
|
528
541
|
const alpha = 1 - controlPositions.c3y / offsetHeight;
|
529
|
-
const roundA =
|
542
|
+
const roundA = roundPart((alpha * 100)) / 100;
|
530
543
|
|
531
544
|
if (format !== 'hsl') {
|
532
545
|
const fill = new Color({
|
@@ -544,7 +557,7 @@ export default class ColorPicker {
|
|
544
557
|
});
|
545
558
|
setElementStyle(v2, { background: hueGradient });
|
546
559
|
} else {
|
547
|
-
const saturation =
|
560
|
+
const saturation = roundPart((controlPositions.c2y / offsetHeight) * 100);
|
548
561
|
const fill0 = new Color({
|
549
562
|
r: 255, g: 0, b: 0, a: alpha,
|
550
563
|
}).saturate(-saturation).toRgbString();
|
@@ -699,12 +712,12 @@ export default class ColorPicker {
|
|
699
712
|
|
700
713
|
self.update();
|
701
714
|
|
702
|
-
if (currentActive) {
|
703
|
-
removeClass(currentActive, 'active');
|
704
|
-
removeAttribute(currentActive, ariaSelected);
|
705
|
-
}
|
706
|
-
|
707
715
|
if (currentActive !== target) {
|
716
|
+
if (currentActive) {
|
717
|
+
removeClass(currentActive, 'active');
|
718
|
+
removeAttribute(currentActive, ariaSelected);
|
719
|
+
}
|
720
|
+
|
708
721
|
addClass(target, 'active');
|
709
722
|
setAttribute(target, ariaSelected, 'true');
|
710
723
|
|
@@ -871,7 +884,7 @@ export default class ColorPicker {
|
|
871
884
|
const [v1, v2, v3, v4] = format === 'rgb'
|
872
885
|
? inputs.map((i) => parseFloat(i.value) / (i === i4 ? 100 : 1))
|
873
886
|
: inputs.map((i) => parseFloat(i.value) / (i !== i1 ? 100 : 360));
|
874
|
-
const isNonColorValue = self.
|
887
|
+
const isNonColorValue = self.hasNonColor && nonColors.includes(currentValue);
|
875
888
|
const alpha = i4 ? v4 : (1 - controlPositions.c3y / offsetHeight);
|
876
889
|
|
877
890
|
if (activeElement === input || (activeElement && inputs.includes(activeElement))) {
|
@@ -1130,11 +1143,11 @@ export default class ColorPicker {
|
|
1130
1143
|
} = componentLabels;
|
1131
1144
|
const { r, g, b } = color.toRgb();
|
1132
1145
|
const [knob1, knob2, knob3] = controlKnobs;
|
1133
|
-
const hue =
|
1146
|
+
const hue = roundPart(hsl.h * 360);
|
1134
1147
|
const alpha = color.a;
|
1135
1148
|
const saturationSource = format === 'hsl' ? hsl.s : hsv.s;
|
1136
|
-
const saturation =
|
1137
|
-
const lightness =
|
1149
|
+
const saturation = roundPart(saturationSource * 100);
|
1150
|
+
const lightness = roundPart(hsl.l * 100);
|
1138
1151
|
const hsvl = hsv.v * 100;
|
1139
1152
|
let colorName;
|
1140
1153
|
|
@@ -1181,8 +1194,8 @@ export default class ColorPicker {
|
|
1181
1194
|
setAttribute(knob2, ariaValueNow, `${saturation}`);
|
1182
1195
|
} else if (format === 'hwb') {
|
1183
1196
|
const { hwb } = self;
|
1184
|
-
const whiteness =
|
1185
|
-
const blackness =
|
1197
|
+
const whiteness = roundPart(hwb.w * 100);
|
1198
|
+
const blackness = roundPart(hwb.b * 100);
|
1186
1199
|
colorLabel = `HWB: ${hue}°, ${whiteness}%, ${blackness}%`;
|
1187
1200
|
setAttribute(knob1, ariaDescription, `${valueLabel}: ${colorLabel}. ${appearanceLabel}: ${colorName}.`);
|
1188
1201
|
setAttribute(knob1, ariaValueText, `${whiteness}% & ${blackness}%`);
|
@@ -1198,7 +1211,7 @@ export default class ColorPicker {
|
|
1198
1211
|
setAttribute(knob2, ariaValueNow, `${hue}`);
|
1199
1212
|
}
|
1200
1213
|
|
1201
|
-
const alphaValue =
|
1214
|
+
const alphaValue = roundPart(alpha * 100);
|
1202
1215
|
setAttribute(knob3, ariaValueText, `${alphaValue}%`);
|
1203
1216
|
setAttribute(knob3, ariaValueNow, `${alphaValue}`);
|
1204
1217
|
|
@@ -1221,10 +1234,14 @@ export default class ColorPicker {
|
|
1221
1234
|
/** Updates the control knobs actual positions. */
|
1222
1235
|
updateControls() {
|
1223
1236
|
const { controlKnobs, controlPositions } = this;
|
1237
|
+
const {
|
1238
|
+
c1x, c1y, c2y, c3y,
|
1239
|
+
} = controlPositions;
|
1224
1240
|
const [control1, control2, control3] = controlKnobs;
|
1225
|
-
|
1226
|
-
setElementStyle(
|
1227
|
-
setElementStyle(
|
1241
|
+
|
1242
|
+
setElementStyle(control1, { transform: `translate3d(${c1x - 4}px,${c1y - 4}px,0)` });
|
1243
|
+
setElementStyle(control2, { transform: `translate3d(0,${c2y - 4}px,0)` });
|
1244
|
+
setElementStyle(control3, { transform: `translate3d(0,${c3y - 4}px,0)` });
|
1228
1245
|
}
|
1229
1246
|
|
1230
1247
|
/**
|
@@ -1237,16 +1254,16 @@ export default class ColorPicker {
|
|
1237
1254
|
value: oldColor, format, inputs, color, hsl,
|
1238
1255
|
} = self;
|
1239
1256
|
const [i1, i2, i3, i4] = inputs;
|
1240
|
-
const alpha =
|
1241
|
-
const hue =
|
1257
|
+
const alpha = roundPart(color.a * 100);
|
1258
|
+
const hue = roundPart(hsl.h * 360);
|
1242
1259
|
let newColor;
|
1243
1260
|
|
1244
1261
|
if (format === 'hex') {
|
1245
1262
|
newColor = self.color.toHexString(true);
|
1246
1263
|
i1.value = self.hex;
|
1247
1264
|
} else if (format === 'hsl') {
|
1248
|
-
const lightness =
|
1249
|
-
const saturation =
|
1265
|
+
const lightness = roundPart(hsl.l * 100);
|
1266
|
+
const saturation = roundPart(hsl.s * 100);
|
1250
1267
|
newColor = self.color.toHslString();
|
1251
1268
|
i1.value = `${hue}`;
|
1252
1269
|
i2.value = `${saturation}`;
|
@@ -1254,8 +1271,8 @@ export default class ColorPicker {
|
|
1254
1271
|
i4.value = `${alpha}`;
|
1255
1272
|
} else if (format === 'hwb') {
|
1256
1273
|
const { w, b } = self.hwb;
|
1257
|
-
const whiteness =
|
1258
|
-
const blackness =
|
1274
|
+
const whiteness = roundPart(w * 100);
|
1275
|
+
const blackness = roundPart(b * 100);
|
1259
1276
|
|
1260
1277
|
newColor = self.color.toHwbString();
|
1261
1278
|
i1.value = `${hue}`;
|
@@ -1327,7 +1344,7 @@ export default class ColorPicker {
|
|
1327
1344
|
const self = this;
|
1328
1345
|
const { colorPicker } = self;
|
1329
1346
|
|
1330
|
-
if (!hasClass(colorPicker,
|
1347
|
+
if (!['top', 'bottom'].some((c) => hasClass(colorPicker, c))) {
|
1331
1348
|
showDropdown(self, colorPicker);
|
1332
1349
|
}
|
1333
1350
|
}
|
@@ -1344,21 +1361,6 @@ export default class ColorPicker {
|
|
1344
1361
|
}
|
1345
1362
|
}
|
1346
1363
|
|
1347
|
-
/** Shows the `ColorPicker` dropdown or the presets menu. */
|
1348
|
-
show() {
|
1349
|
-
const self = this;
|
1350
|
-
const { menuToggle } = self;
|
1351
|
-
if (!self.isOpen) {
|
1352
|
-
toggleEventsOnShown(self, true);
|
1353
|
-
self.updateDropdownPosition();
|
1354
|
-
self.isOpen = true;
|
1355
|
-
setAttribute(self.input, 'tabindex', '0');
|
1356
|
-
if (menuToggle) {
|
1357
|
-
setAttribute(menuToggle, 'tabindex', '0');
|
1358
|
-
}
|
1359
|
-
}
|
1360
|
-
}
|
1361
|
-
|
1362
1364
|
/**
|
1363
1365
|
* Hides the currently open `ColorPicker` dropdown.
|
1364
1366
|
* @param {boolean=} focusPrevented
|
@@ -1393,9 +1395,9 @@ export default class ColorPicker {
|
|
1393
1395
|
if (!focusPrevented) {
|
1394
1396
|
focus(pickerToggle);
|
1395
1397
|
}
|
1396
|
-
setAttribute(input,
|
1398
|
+
setAttribute(input, tabIndex, '-1');
|
1397
1399
|
if (menuToggle) {
|
1398
|
-
setAttribute(menuToggle,
|
1400
|
+
setAttribute(menuToggle, tabIndex, '-1');
|
1399
1401
|
}
|
1400
1402
|
}
|
1401
1403
|
}
|
@@ -1409,7 +1411,10 @@ export default class ColorPicker {
|
|
1409
1411
|
[...parent.children].forEach((el) => {
|
1410
1412
|
if (el !== input) el.remove();
|
1411
1413
|
});
|
1414
|
+
|
1415
|
+
removeAttribute(input, tabIndex);
|
1412
1416
|
setElementStyle(input, { backgroundColor: '' });
|
1417
|
+
|
1413
1418
|
['txt-light', 'txt-dark'].forEach((c) => removeClass(parent, c));
|
1414
1419
|
Data.remove(input, colorPickerString);
|
1415
1420
|
}
|
@@ -1417,8 +1422,14 @@ export default class ColorPicker {
|
|
1417
1422
|
|
1418
1423
|
ObjectAssign(ColorPicker, {
|
1419
1424
|
Color,
|
1425
|
+
ColorPalette,
|
1420
1426
|
Version,
|
1421
1427
|
getInstance: getColorPickerInstance,
|
1422
1428
|
init: initColorPicker,
|
1423
1429
|
selector: colorPickerSelector,
|
1430
|
+
// utils important for render
|
1431
|
+
roundPart,
|
1432
|
+
setElementStyle,
|
1433
|
+
setAttribute,
|
1434
|
+
getBoundingClientRect,
|
1424
1435
|
});
|