@thednp/color-picker 0.0.1-alpha3 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/css/color-picker.css +3 -2
- package/dist/css/color-picker.min.css +2 -2
- package/dist/css/color-picker.rtl.css +3 -2
- package/dist/css/color-picker.rtl.min.css +2 -2
- package/dist/js/color-picker-element-esm.js +32 -20
- package/dist/js/color-picker-element-esm.min.js +2 -2
- package/dist/js/color-picker-element.js +32 -20
- package/dist/js/color-picker-element.min.js +2 -2
- package/dist/js/color-picker-esm.js +32 -20
- package/dist/js/color-picker-esm.min.js +2 -2
- package/dist/js/color-picker.js +32 -20
- package/dist/js/color-picker.min.js +2 -2
- package/package.json +1 -1
- package/src/js/color-picker.js +21 -7
- package/src/js/color.js +9 -11
- package/src/scss/color-picker.scss +3 -7
package/dist/js/color-picker.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
* ColorPicker v0.0.
|
2
|
+
* ColorPicker v0.0.1 (http://thednp.github.io/color-picker)
|
3
3
|
* Copyright 2022 © thednp
|
4
4
|
* Licensed under MIT (https://github.com/thednp/color-picker/blob/master/LICENSE)
|
5
5
|
*/
|
@@ -1714,9 +1714,9 @@
|
|
1714
1714
|
if (typeof color === 'object') {
|
1715
1715
|
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
|
1716
1716
|
({ r, g, b } = color);
|
1717
|
-
|
1718
|
-
|
1719
|
-
rgb = { r, g, b };
|
1717
|
+
// RGB values now are all in [0, 255] range
|
1718
|
+
[r, g, b] = [r, g, b].map((n) => bound01(n, isPercentage(n) ? 100 : 255) * 255);
|
1719
|
+
rgb = { r, g, b };
|
1720
1720
|
ok = true;
|
1721
1721
|
format = 'rgb';
|
1722
1722
|
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
|
@@ -1871,13 +1871,9 @@
|
|
1871
1871
|
const {
|
1872
1872
|
r, g, b, a,
|
1873
1873
|
} = this;
|
1874
|
-
const [R, G, B] = [r, g, b].map((x) => roundPart(x));
|
1875
1874
|
|
1876
1875
|
return {
|
1877
|
-
r:
|
1878
|
-
g: G,
|
1879
|
-
b: B,
|
1880
|
-
a: roundPart(a * 100) / 100,
|
1876
|
+
r, g, b, a: roundPart(a * 100) / 100,
|
1881
1877
|
};
|
1882
1878
|
}
|
1883
1879
|
|
@@ -1891,10 +1887,11 @@
|
|
1891
1887
|
const {
|
1892
1888
|
r, g, b, a,
|
1893
1889
|
} = this.toRgb();
|
1890
|
+
const [R, G, B] = [r, g, b].map(roundPart);
|
1894
1891
|
|
1895
1892
|
return a === 1
|
1896
|
-
? `rgb(${
|
1897
|
-
: `rgba(${
|
1893
|
+
? `rgb(${R}, ${G}, ${B})`
|
1894
|
+
: `rgba(${R}, ${G}, ${B}, ${a})`;
|
1898
1895
|
}
|
1899
1896
|
|
1900
1897
|
/**
|
@@ -1907,9 +1904,10 @@
|
|
1907
1904
|
const {
|
1908
1905
|
r, g, b, a,
|
1909
1906
|
} = this.toRgb();
|
1907
|
+
const [R, G, B] = [r, g, b].map(roundPart);
|
1910
1908
|
const A = a === 1 ? '' : ` / ${roundPart(a * 100)}%`;
|
1911
1909
|
|
1912
|
-
return `rgb(${
|
1910
|
+
return `rgb(${R} ${G} ${B}${A})`;
|
1913
1911
|
}
|
1914
1912
|
|
1915
1913
|
/**
|
@@ -2367,7 +2365,7 @@
|
|
2367
2365
|
return true;
|
2368
2366
|
}
|
2369
2367
|
|
2370
|
-
var version = "0.0.
|
2368
|
+
var version = "0.0.1";
|
2371
2369
|
|
2372
2370
|
// @ts-ignore
|
2373
2371
|
|
@@ -3138,30 +3136,41 @@
|
|
3138
3136
|
if (![keyArrowUp, keyArrowDown, keyArrowLeft, keyArrowRight].includes(code)) return;
|
3139
3137
|
e.preventDefault();
|
3140
3138
|
|
3141
|
-
const { controlKnobs } = self;
|
3139
|
+
const { format, controlKnobs, visuals } = self;
|
3140
|
+
const { offsetWidth, offsetHeight } = visuals[0];
|
3142
3141
|
const [c1, c2, c3] = controlKnobs;
|
3143
3142
|
const { activeElement } = getDocument(c1);
|
3144
3143
|
const currentKnob = controlKnobs.find((x) => x === activeElement);
|
3144
|
+
const yRatio = offsetHeight / (format === 'hsl' ? 100 : 360);
|
3145
3145
|
|
3146
3146
|
if (currentKnob) {
|
3147
3147
|
let offsetX = 0;
|
3148
3148
|
let offsetY = 0;
|
3149
|
+
|
3149
3150
|
if (target === c1) {
|
3151
|
+
const xRatio = offsetWidth / (format === 'hsl' ? 360 : 100);
|
3152
|
+
|
3150
3153
|
if ([keyArrowLeft, keyArrowRight].includes(code)) {
|
3151
|
-
self.controlPositions.c1x += code === keyArrowRight ?
|
3154
|
+
self.controlPositions.c1x += code === keyArrowRight ? xRatio : -xRatio;
|
3152
3155
|
} else if ([keyArrowUp, keyArrowDown].includes(code)) {
|
3153
|
-
self.controlPositions.c1y += code === keyArrowDown ?
|
3156
|
+
self.controlPositions.c1y += code === keyArrowDown ? yRatio : -yRatio;
|
3154
3157
|
}
|
3155
3158
|
|
3156
3159
|
offsetX = self.controlPositions.c1x;
|
3157
3160
|
offsetY = self.controlPositions.c1y;
|
3158
3161
|
self.changeControl1(offsetX, offsetY);
|
3159
3162
|
} else if (target === c2) {
|
3160
|
-
self.controlPositions.c2y += [keyArrowDown, keyArrowRight].includes(code)
|
3163
|
+
self.controlPositions.c2y += [keyArrowDown, keyArrowRight].includes(code)
|
3164
|
+
? yRatio
|
3165
|
+
: -yRatio;
|
3166
|
+
|
3161
3167
|
offsetY = self.controlPositions.c2y;
|
3162
3168
|
self.changeControl2(offsetY);
|
3163
3169
|
} else if (target === c3) {
|
3164
|
-
self.controlPositions.c3y += [keyArrowDown, keyArrowRight].includes(code)
|
3170
|
+
self.controlPositions.c3y += [keyArrowDown, keyArrowRight].includes(code)
|
3171
|
+
? yRatio
|
3172
|
+
: -yRatio;
|
3173
|
+
|
3165
3174
|
offsetY = self.controlPositions.c3y;
|
3166
3175
|
self.changeAlpha(offsetY);
|
3167
3176
|
}
|
@@ -3533,10 +3542,12 @@
|
|
3533
3542
|
/** Updates the control knobs actual positions. */
|
3534
3543
|
updateControls() {
|
3535
3544
|
const { controlKnobs, controlPositions } = this;
|
3536
|
-
|
3545
|
+
let {
|
3537
3546
|
c1x, c1y, c2y, c3y,
|
3538
3547
|
} = controlPositions;
|
3539
3548
|
const [control1, control2, control3] = controlKnobs;
|
3549
|
+
// round control positions
|
3550
|
+
[c1x, c1y, c2y, c3y] = [c1x, c1y, c2y, c3y].map(roundPart);
|
3540
3551
|
|
3541
3552
|
setElementStyle(control1, { transform: `translate3d(${c1x - 4}px,${c1y - 4}px,0)` });
|
3542
3553
|
setElementStyle(control2, { transform: `translate3d(0,${c2y - 4}px,0)` });
|
@@ -3579,7 +3590,8 @@
|
|
3579
3590
|
i3.value = `${blackness}`;
|
3580
3591
|
i4.value = `${alpha}`;
|
3581
3592
|
} else if (format === 'rgb') {
|
3582
|
-
|
3593
|
+
let { r, g, b } = self.rgb;
|
3594
|
+
[r, g, b] = [r, g, b].map(roundPart);
|
3583
3595
|
|
3584
3596
|
newColor = self.color.toRgbString();
|
3585
3597
|
i1.value = `${r}`;
|
@@ -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)).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}));
|
1
|
+
// ColorPicker v0.0.1 | 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)),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}));
|
package/package.json
CHANGED
package/src/js/color-picker.js
CHANGED
@@ -839,30 +839,41 @@ export default class ColorPicker {
|
|
839
839
|
if (![keyArrowUp, keyArrowDown, keyArrowLeft, keyArrowRight].includes(code)) return;
|
840
840
|
e.preventDefault();
|
841
841
|
|
842
|
-
const { controlKnobs } = self;
|
842
|
+
const { format, controlKnobs, visuals } = self;
|
843
|
+
const { offsetWidth, offsetHeight } = visuals[0];
|
843
844
|
const [c1, c2, c3] = controlKnobs;
|
844
845
|
const { activeElement } = getDocument(c1);
|
845
846
|
const currentKnob = controlKnobs.find((x) => x === activeElement);
|
847
|
+
const yRatio = offsetHeight / (format === 'hsl' ? 100 : 360);
|
846
848
|
|
847
849
|
if (currentKnob) {
|
848
850
|
let offsetX = 0;
|
849
851
|
let offsetY = 0;
|
852
|
+
|
850
853
|
if (target === c1) {
|
854
|
+
const xRatio = offsetWidth / (format === 'hsl' ? 360 : 100);
|
855
|
+
|
851
856
|
if ([keyArrowLeft, keyArrowRight].includes(code)) {
|
852
|
-
self.controlPositions.c1x += code === keyArrowRight ?
|
857
|
+
self.controlPositions.c1x += code === keyArrowRight ? xRatio : -xRatio;
|
853
858
|
} else if ([keyArrowUp, keyArrowDown].includes(code)) {
|
854
|
-
self.controlPositions.c1y += code === keyArrowDown ?
|
859
|
+
self.controlPositions.c1y += code === keyArrowDown ? yRatio : -yRatio;
|
855
860
|
}
|
856
861
|
|
857
862
|
offsetX = self.controlPositions.c1x;
|
858
863
|
offsetY = self.controlPositions.c1y;
|
859
864
|
self.changeControl1(offsetX, offsetY);
|
860
865
|
} else if (target === c2) {
|
861
|
-
self.controlPositions.c2y += [keyArrowDown, keyArrowRight].includes(code)
|
866
|
+
self.controlPositions.c2y += [keyArrowDown, keyArrowRight].includes(code)
|
867
|
+
? yRatio
|
868
|
+
: -yRatio;
|
869
|
+
|
862
870
|
offsetY = self.controlPositions.c2y;
|
863
871
|
self.changeControl2(offsetY);
|
864
872
|
} else if (target === c3) {
|
865
|
-
self.controlPositions.c3y += [keyArrowDown, keyArrowRight].includes(code)
|
873
|
+
self.controlPositions.c3y += [keyArrowDown, keyArrowRight].includes(code)
|
874
|
+
? yRatio
|
875
|
+
: -yRatio;
|
876
|
+
|
866
877
|
offsetY = self.controlPositions.c3y;
|
867
878
|
self.changeAlpha(offsetY);
|
868
879
|
}
|
@@ -1234,10 +1245,12 @@ export default class ColorPicker {
|
|
1234
1245
|
/** Updates the control knobs actual positions. */
|
1235
1246
|
updateControls() {
|
1236
1247
|
const { controlKnobs, controlPositions } = this;
|
1237
|
-
|
1248
|
+
let {
|
1238
1249
|
c1x, c1y, c2y, c3y,
|
1239
1250
|
} = controlPositions;
|
1240
1251
|
const [control1, control2, control3] = controlKnobs;
|
1252
|
+
// round control positions
|
1253
|
+
[c1x, c1y, c2y, c3y] = [c1x, c1y, c2y, c3y].map(roundPart);
|
1241
1254
|
|
1242
1255
|
setElementStyle(control1, { transform: `translate3d(${c1x - 4}px,${c1y - 4}px,0)` });
|
1243
1256
|
setElementStyle(control2, { transform: `translate3d(0,${c2y - 4}px,0)` });
|
@@ -1280,7 +1293,8 @@ export default class ColorPicker {
|
|
1280
1293
|
i3.value = `${blackness}`;
|
1281
1294
|
i4.value = `${alpha}`;
|
1282
1295
|
} else if (format === 'rgb') {
|
1283
|
-
|
1296
|
+
let { r, g, b } = self.rgb;
|
1297
|
+
[r, g, b] = [r, g, b].map(roundPart);
|
1284
1298
|
|
1285
1299
|
newColor = self.color.toRgbString();
|
1286
1300
|
i1.value = `${r}`;
|
package/src/js/color.js
CHANGED
@@ -631,9 +631,9 @@ function inputToRGB(input) {
|
|
631
631
|
if (typeof color === 'object') {
|
632
632
|
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
|
633
633
|
({ r, g, b } = color);
|
634
|
-
|
635
|
-
|
636
|
-
rgb = { r, g, b };
|
634
|
+
// RGB values now are all in [0, 255] range
|
635
|
+
[r, g, b] = [r, g, b].map((n) => bound01(n, isPercentage(n) ? 100 : 255) * 255);
|
636
|
+
rgb = { r, g, b };
|
637
637
|
ok = true;
|
638
638
|
format = 'rgb';
|
639
639
|
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
|
@@ -788,13 +788,9 @@ export default class Color {
|
|
788
788
|
const {
|
789
789
|
r, g, b, a,
|
790
790
|
} = this;
|
791
|
-
const [R, G, B] = [r, g, b].map((x) => roundPart(x));
|
792
791
|
|
793
792
|
return {
|
794
|
-
r:
|
795
|
-
g: G,
|
796
|
-
b: B,
|
797
|
-
a: roundPart(a * 100) / 100,
|
793
|
+
r, g, b, a: roundPart(a * 100) / 100,
|
798
794
|
};
|
799
795
|
}
|
800
796
|
|
@@ -808,10 +804,11 @@ export default class Color {
|
|
808
804
|
const {
|
809
805
|
r, g, b, a,
|
810
806
|
} = this.toRgb();
|
807
|
+
const [R, G, B] = [r, g, b].map(roundPart);
|
811
808
|
|
812
809
|
return a === 1
|
813
|
-
? `rgb(${
|
814
|
-
: `rgba(${
|
810
|
+
? `rgb(${R}, ${G}, ${B})`
|
811
|
+
: `rgba(${R}, ${G}, ${B}, ${a})`;
|
815
812
|
}
|
816
813
|
|
817
814
|
/**
|
@@ -824,9 +821,10 @@ export default class Color {
|
|
824
821
|
const {
|
825
822
|
r, g, b, a,
|
826
823
|
} = this.toRgb();
|
824
|
+
const [R, G, B] = [r, g, b].map(roundPart);
|
827
825
|
const A = a === 1 ? '' : ` / ${roundPart(a * 100)}%`;
|
828
826
|
|
829
|
-
return `rgb(${
|
827
|
+
return `rgb(${R} ${G} ${B}${A})`;
|
830
828
|
}
|
831
829
|
|
832
830
|
/**
|
@@ -180,11 +180,9 @@ color-picker:focus,
|
|
180
180
|
display: none;
|
181
181
|
flex-wrap: wrap;
|
182
182
|
flex-flow: column;
|
183
|
-
// max-height: 160px;
|
184
183
|
margin: 0;
|
185
|
-
// overflow-y: auto;
|
186
184
|
list-style: none;
|
187
|
-
padding-inline: 0;
|
185
|
+
padding-inline: 0; // Firefox
|
188
186
|
}
|
189
187
|
|
190
188
|
.color-dropdown.menu .color-defaults,
|
@@ -258,7 +256,6 @@ color-picker:focus,
|
|
258
256
|
height: var(--grid-item-size);
|
259
257
|
overflow: hidden;
|
260
258
|
text-indent: 2.1rem;
|
261
|
-
// background: #eee;
|
262
259
|
}
|
263
260
|
.color-options .color-option:active,
|
264
261
|
.color-options .color-option:focus {
|
@@ -309,7 +306,6 @@ color-picker:focus,
|
|
309
306
|
flex-direction: row;
|
310
307
|
flex-wrap: wrap;
|
311
308
|
align-items: center;
|
312
|
-
// max-width: fit-content;
|
313
309
|
padding: .25rem 0 0;
|
314
310
|
font: 12px sans-serif;
|
315
311
|
}
|
@@ -396,8 +392,9 @@ color-picker:focus,
|
|
396
392
|
user-select: none;
|
397
393
|
background-color: #000;
|
398
394
|
border: 1px solid #fff;
|
395
|
+
border-radius: 5px;
|
399
396
|
outline: none;
|
400
|
-
|
397
|
+
will-change: transform;
|
401
398
|
}
|
402
399
|
.knob:hover {
|
403
400
|
box-shadow: 0 0 0 6px rgba(255,255,255,.5);
|
@@ -413,7 +410,6 @@ color-picker:focus,
|
|
413
410
|
width: 7px;
|
414
411
|
background-color: transparent;
|
415
412
|
border: 0;
|
416
|
-
border-radius: 5px;
|
417
413
|
}
|
418
414
|
|
419
415
|
.txt-dark .color-pointer {
|