@melloware/coloris
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -64,2 +64,3 @@ // https://github.com/umdjs/umd/blob/master/templates/returnExports.js | ||
format: 'hex', | ||
formatToggle: false, | ||
swatches: [], | ||
@@ -78,2 +79,3 @@ alpha: true, | ||
input: 'Color value field', | ||
format: 'Color format', | ||
swatch: 'Color swatch', | ||
@@ -122,2 +124,8 @@ instruction: 'Saturation and brightness selector. Use up, down, left and right arrow keys to select.' } }; | ||
break; | ||
case 'formatToggle': | ||
getEl('clr-format').style.display = options.formatToggle ? 'block' : 'none'; | ||
if (options.formatToggle) { | ||
settings.format = 'auto'; | ||
} | ||
break; | ||
case 'swatches': | ||
@@ -498,2 +506,5 @@ if (Array.isArray(options.swatches)) {(function () { | ||
// Select the current format in the format switcher | ||
document.querySelector(".clr-format [value=\"" + format + "\"]").checked = true; | ||
} | ||
@@ -731,2 +742,14 @@ | ||
'</div>' + | ||
'<div id="clr-format" class="clr-format">' + | ||
'<fieldset class="clr-segmented">' + ("<legend>" + | ||
settings.a11y.format + "</legend>") + | ||
'<input id="clr-f1" type="radio" name="clr-format" value="hex">' + | ||
'<label for="clr-f1">Hex</label>' + | ||
'<input id="clr-f2" type="radio" name="clr-format" value="rgb">' + | ||
'<label for="clr-f2">RGB</label>' + | ||
'<input id="clr-f3" type="radio" name="clr-format" value="hsl">' + | ||
'<label for="clr-f3">HSL</label>' + | ||
'<span></span>' + | ||
'</fieldset>' + | ||
'</div>' + | ||
'<div id="clr-swatches" class="clr-swatches"></div>' + ("<button id=\"clr-clear\" class=\"clr-clear\">" + | ||
@@ -792,2 +815,8 @@ settings.clearButton.label + "</button>") + ("<button id=\"clr-color-preview\" class=\"clr-preview\" aria-label=\"" + | ||
addListener(document, 'click', '.clr-format input', function (event) { | ||
currentFormat = event.target.value; | ||
updateColor(); | ||
pickColor(); | ||
}); | ||
addListener(picker, 'click', '.clr-swatches button', function (event) { | ||
@@ -794,0 +823,0 @@ setColorFromStr(event.target.textContent); |
@@ -7,2 +7,2 @@ !function(e,t){"function"==typeof define&&define.amd?define("@melloware/coloris",[],t):"object"==typeof module&&module.exports?module.exports.Coloris=t():(e.Coloris=t(),"object"==typeof window&&e.Coloris.init())}("undefined"!=typeof self?self:void 0,function(){ | ||
*/ | ||
return y=window,b=document,g=Math,D=b.createElement("canvas").getContext("2d"),O={el:"[data-coloris]",parent:null,theme:"light",wrap:!0,margin:2,format:"hex",swatches:[],alpha:!0,clearButton:{show:!(j={r:0,g:0,b:0,h:0,s:0,v:0,a:1}),label:"Clear"},a11y:{open:"Open color picker",close:"Close color picker",marker:"Saturation: {s}. Brightness: {v}.",hueSlider:"Hue slider",alphaSlider:"Opacity slider",input:"Color value field",swatch:"Color swatch",instruction:"Saturation and brightness selector. Use up, down, left and right arrow keys to select."}},void 0!==NodeList&&NodeList.prototype&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),function(){var r={init:d,set:a,wrap:c,close:l};function e(e){v(function(){e&&("string"==typeof e?i:a)(e)})}for(var t in r)!function(l){e[l]=function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];v(r[l],t)}}(t);return e}();function a(e){if("object"==typeof e)for(var t in e)switch(t){case"el":i(e.el),!1!==e.wrap&&c(e.el);break;case"parent":O.parent=b.querySelector(e.parent),O.parent&&O.parent.appendChild(m);break;case"theme":m.className="clr-picker clr-"+e.theme.split("-").join(" clr-");break;case"margin":e.margin*=1,O.margin=(isNaN(e.margin)?O:e).margin;break;case"wrap":e.el&&e.wrap&&c(e.el);break;case"format":O.format=e.format;break;case"swatches":Array.isArray(e.swatches)&&function(){var a=[];e.swatches.forEach(function(e,t){a.push('<button id="clr-swatch-'+t+'" aria-labelledby="clr-swatch-label clr-swatch-'+t+'" style="color: '+e+';">'+e+"</button>")}),a.length&&(h("clr-swatches").innerHTML="<div>"+a.join("")+"</div>")}();break;case"alpha":O.alpha=!!e.alpha,m.setAttribute("data-alpha",O.alpha);break;case"clearButton":var a="none";e.clearButton.show&&(a="block"),e.clearButton.label&&(S.innerHTML=e.clearButton.label),S.style.display=a;break;case"a11y":var l,r=e.a11y,n=!1;if("object"==typeof r)for(var o in r)r[o]&&O.a11y[o]&&(O.a11y[o]=r[o],n=!0);n&&(l=h("clr-open-label"),a=h("clr-swatch-label"),l.innerHTML=O.a11y.open,a.innerHTML=O.a11y.swatch,E.setAttribute("aria-label",O.a11y.close),A.setAttribute("aria-label",O.a11y.hueSlider),T.setAttribute("aria-label",O.a11y.alphaSlider),L.setAttribute("aria-label",O.a11y.input),w.setAttribute("aria-label",O.a11y.instruction))}}function i(e){f(b,"click",e,function(e){var t=O.parent,a=e.target.getBoundingClientRect(),l=y.scrollY,r={left:!1,top:!1},n={x:0,y:0},o=a.x,i=l+a.y+a.height+O.margin;B=e.target,M=B.value,N=function(e){e=e.substring(0,3).toLowerCase();return"rgb"!==e&&"hsl"!==e?"hex":e}(M),m.classList.add("clr-open");var c,s=m.offsetWidth,u=m.offsetHeight;t?(c=y.getComputedStyle(t),e=parseFloat(c.marginTop),c=parseFloat(c.borderTopWidth),(n=t.getBoundingClientRect()).y+=c+l,o-=n.x,i-=n.y,o+s>t.clientWidth&&(o+=a.width-s,r.left=!0),i+u>t.clientHeight-e&&(i-=a.height+u+2*O.margin,r.top=!0),i+=t.scrollTop):(o+s>b.documentElement.clientWidth&&(o+=a.width-s,r.left=!0),i+u-l>b.documentElement.clientHeight&&(i=l+a.y-u-O.margin,r.top=!0)),m.classList.toggle("clr-left",r.left),m.classList.toggle("clr-top",r.top),m.style.left=o+"px",m.style.top=i+"px",k={width:w.offsetWidth,height:w.offsetHeight,x:m.offsetLeft+w.offsetLeft+n.x,y:m.offsetTop+w.offsetTop+n.y},p(M),L.focus({preventScroll:!0})}),f(b,"input",e,function(e){var t=e.target.parentNode;t.classList.contains("clr-field")&&(t.style.color=e.target.value)})}function c(e){b.querySelectorAll(e).forEach(function(e){var t,a=e.parentNode;a.classList.contains("clr-field")||((t=b.createElement("div")).innerHTML='<button aria-labelledby="clr-open-label"></button>',a.insertBefore(t,e),t.setAttribute("class","clr-field"),t.style.color=e.value,t.appendChild(e))})}function l(e){B&&(e&&M!==B.value&&(B.value=M,B.dispatchEvent(new Event("input",{bubbles:!0}))),M!==B.value&&B.dispatchEvent(new Event("change",{bubbles:!0})),m.classList.remove("clr-open"),B.focus({preventScroll:!0}),B=null)}function p(e){var t=function(e){D.fillStyle="#000",D.fillStyle=e,e=(e=/^((rgba)|rgb)[\D]+([\d.]+)[\D]+([\d.]+)[\D]+([\d.]+)[\D]*?([\d.]+|$)/i.exec(D.fillStyle))?{r:+e[3],g:+e[4],b:+e[5],a:+e[6]}:(e=D.fillStyle.replace("#","").match(/.{2}/g).map(function(e){return parseInt(e,16)}),{r:e[0],g:e[1],b:e[2],a:1});return e}(e),e=function(e){var t=e.r/255,a=e.g/255,l=e.b/255,r=g.max(t,a,l),n=g.min(t,a,l),o=r-n,i=r,c=0,n=0;o&&(r===t&&(c=(a-l)/o),r===a&&(c=2+(l-t)/o),r===l&&(c=4+(t-a)/o),r&&(n=o/r));return{h:(c=g.floor(60*c))<0?c+360:c,s:g.round(100*n),v:g.round(100*i),a:e.a}}(t);o(e.s,e.v),s(t,e),A.value=e.h,m.style.color="hsl("+e.h+", 100%, 50%)",C.style.left=e.h/360*100+"%",x.style.left=k.width*e.s/100+"px",x.style.top=k.height-k.height*e.v/100+"px",T.value=100*e.a,H.style.left=100*e.a+"%"}function r(e){B&&(B.value=void 0!==e?e:L.value,B.dispatchEvent(new Event("input",{bubbles:!0})))}function n(e,t){e={h:+A.value,s:e/k.width*100,v:100-t/k.height*100,a:T.value/100},t=function(e){var t=e.s/100,a=e.v/100,l=t*a,r=e.h/60,n=l*(1-g.abs(r%2-1)),o=a-l;l+=o,n+=o;t=g.floor(r)%6,a=[l,n,o,o,n,l][t],r=[n,l,l,n,o,o][t],t=[o,o,n,l,l,n][t];return{r:g.round(255*a),g:g.round(255*r),b:g.round(255*t),a:e.a}}(e);o(e.s,e.v),s(t,e),r()}function o(e,t){var a=O.a11y.marker;e=+e.toFixed(1),t=+t.toFixed(1),a=(a=a.replace("{s}",e)).replace("{v}",t),x.setAttribute("aria-label",a)}function t(e){var t={pageX:((a=e).changedTouches?a.changedTouches[0]:a).pageX,pageY:(a.changedTouches?a.changedTouches[0]:a).pageY},a=t.pageX-k.x,t=t.pageY-k.y;O.parent&&(t+=O.parent.scrollTop),a=a<0?0:a>k.width?k.width:a,t=t<0?0:t>k.height?k.height:t,x.style.left=a+"px",x.style.top=t+"px",n(a,t),e.preventDefault(),e.stopPropagation()}function s(e,t){void 0===t&&(t={});var a,l,r=O.format;for(a in e=void 0===e?{}:e)j[a]=e[a];for(l in t)j[l]=t[l];var n,o=function(e){var t=e.r.toString(16),a=e.g.toString(16),l=e.b.toString(16),r="";e.r<16&&(t="0"+t);e.g<16&&(a="0"+a);e.b<16&&(l="0"+l);O.alpha&&e.a<1&&(e=255*e.a|0,r=e.toString(16),e<16&&(r="0"+r));return"#"+t+a+l+r}(j),i=o.substring(0,7);switch(x.style.color=i,H.parentNode.style.color=i,H.style.color=o,E.style.color=o,w.style.display="none",w.offsetHeight,w.style.display="",H.nextElementSibling.style.display="none",H.nextElementSibling.offsetHeight,H.nextElementSibling.style.display="","mixed"===r?r=1===j.a?"hex":"rgb":"auto"===r&&(r=N),r){case"hex":L.value=o;break;case"rgb":L.value=(n=j,O.alpha&&1!==n.a?"rgba("+n.r+", "+n.g+", "+n.b+", "+n.a+")":"rgb("+n.r+", "+n.g+", "+n.b+")");break;case"hsl":L.value=(n=function(e){var t,a=e.v/100,l=a*(1-e.s/100/2);0<l&&l<1&&(t=g.round((a-l)/g.min(l,1-l)*100));return{h:e.h,s:t||0,l:g.round(100*l),a:e.a}}(j),O.alpha&&1!==n.a?"hsla("+n.h+", "+n.s+"%, "+n.l+"%, "+n.a+")":"hsl("+n.h+", "+n.s+"%, "+n.l+"%)")}}function e(){var e=+A.value,t=+x.style.left.replace("px",""),a=+x.style.top.replace("px","");m.style.color="hsl("+e+", 100%, 50%)",C.style.left=e/360*100+"%",n(t,a)}function u(){var e=T.value/100;H.style.left=100*e+"%",s({a:e}),r()}function d(){(m=b.createElement("div")).setAttribute("id","clr-picker"),m.className="clr-picker",m.innerHTML='<input id="clr-color-value" class="clr-color" type="text" value="" aria-label="'+O.a11y.input+'"><div id="clr-color-area" class="clr-gradient" role="application" aria-label="'+O.a11y.instruction+'"><div id="clr-color-marker" class="clr-marker" tabindex="0"></div></div><div class="clr-hue"><input id="clr-hue-slider" type="range" min="0" max="360" step="1" aria-label="'+O.a11y.hueSlider+'"><div id="clr-hue-marker"></div></div><div class="clr-alpha"><input id="clr-alpha-slider" type="range" min="0" max="100" step="1" aria-label="'+O.a11y.alphaSlider+'"><div id="clr-alpha-marker"></div><span></span></div><div id="clr-swatches" class="clr-swatches"></div><button id="clr-clear" class="clr-clear">'+O.clearButton.label+'</button><button id="clr-color-preview" class="clr-preview" aria-label="'+O.a11y.close+'"></button><span id="clr-open-label" hidden>'+O.a11y.open+'</span><span id="clr-swatch-label" hidden>'+O.a11y.swatch+"</span>",b.body.appendChild(m),w=h("clr-color-area"),x=h("clr-color-marker"),S=h("clr-clear"),E=h("clr-color-preview"),L=h("clr-color-value"),A=h("clr-hue-slider"),C=h("clr-hue-marker"),T=h("clr-alpha-slider"),H=h("clr-alpha-marker"),i(O.el),c(O.el),f(m,"mousedown",function(e){m.classList.remove("clr-keyboard-nav"),e.stopPropagation()}),f(w,"mousedown",function(e){f(b,"mousemove",t)}),f(w,"touchstart",function(e){b.addEventListener("touchmove",t,{passive:!1})}),f(x,"mousedown",function(e){f(b,"mousemove",t)}),f(x,"touchstart",function(e){b.addEventListener("touchmove",t,{passive:!1})}),f(L,"change",function(e){p(L.value),r()}),f(S,"click",function(e){r(""),l()}),f(E,"click",function(e){r(),l()}),f(m,"click",".clr-swatches button",function(e){p(e.target.textContent),r()}),f(b,"mouseup",function(e){b.removeEventListener("mousemove",t)}),f(b,"touchend",function(e){b.removeEventListener("touchmove",t)}),f(b,"mousedown",function(e){m.classList.remove("clr-keyboard-nav"),l()}),f(b,"keydown",function(e){"Escape"===e.key?l(!0):"Tab"===e.key&&m.classList.add("clr-keyboard-nav")}),f(b,"click",".clr-field button",function(e){e.target.nextElementSibling.dispatchEvent(new Event("click",{bubbles:!0}))}),f(x,"keydown",function(e){var t={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]};-1!==Object.keys(t).indexOf(e.key)&&(!function(e,t){e=+x.style.left.replace("px","")+e,t=+x.style.top.replace("px","")+t,x.style.left=e+"px",x.style.top=t+"px",n(e,t)}.apply(void 0,t[e.key]),e.preventDefault())}),f(w,"click",t),f(A,"input",e),f(T,"input",u)}function h(e){return b.getElementById(e)}function f(e,t,a,l){var r=Element.prototype.matches||Element.prototype.msMatchesSelector;"string"==typeof a?e.addEventListener(t,function(e){r.call(e.target,a)&&l.call(e.target,e)}):(l=a,e.addEventListener(t,l))}function v(e,t){t=void 0!==t?t:[],"loading"!==b.readyState?e.apply(void 0,t):b.addEventListener("DOMContentLoaded",function(){e.apply(void 0,t)})}var y,b,g,m,w,k,x,E,L,S,A,C,T,H,B,N,M,D,j,O}); | ||
return y=window,b=document,g=Math,D=b.createElement("canvas").getContext("2d"),O={el:"[data-coloris]",parent:null,theme:"light",wrap:!0,margin:2,format:"hex",formatToggle:!(j={r:0,g:0,b:0,h:0,s:0,v:0,a:1}),swatches:[],alpha:!0,clearButton:{show:!1,label:"Clear"},a11y:{open:"Open color picker",close:"Close color picker",marker:"Saturation: {s}. Brightness: {v}.",hueSlider:"Hue slider",alphaSlider:"Opacity slider",input:"Color value field",format:"Color format",swatch:"Color swatch",instruction:"Saturation and brightness selector. Use up, down, left and right arrow keys to select."}},void 0!==NodeList&&NodeList.prototype&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),function(){var r={init:d,set:a,wrap:c,close:l};function e(e){v(function(){e&&("string"==typeof e?i:a)(e)})}for(var t in r)!function(l){e[l]=function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];v(r[l],t)}}(t);return e}();function a(e){if("object"==typeof e)for(var t in e)switch(t){case"el":i(e.el),!1!==e.wrap&&c(e.el);break;case"parent":O.parent=b.querySelector(e.parent),O.parent&&O.parent.appendChild(m);break;case"theme":m.className="clr-picker clr-"+e.theme.split("-").join(" clr-");break;case"margin":e.margin*=1,O.margin=(isNaN(e.margin)?O:e).margin;break;case"wrap":e.el&&e.wrap&&c(e.el);break;case"format":O.format=e.format;break;case"formatToggle":f("clr-format").style.display=e.formatToggle?"block":"none",e.formatToggle&&(O.format="auto");break;case"swatches":Array.isArray(e.swatches)&&function(){var a=[];e.swatches.forEach(function(e,t){a.push('<button id="clr-swatch-'+t+'" aria-labelledby="clr-swatch-label clr-swatch-'+t+'" style="color: '+e+';">'+e+"</button>")}),a.length&&(f("clr-swatches").innerHTML="<div>"+a.join("")+"</div>")}();break;case"alpha":O.alpha=!!e.alpha,m.setAttribute("data-alpha",O.alpha);break;case"clearButton":var a="none";e.clearButton.show&&(a="block"),e.clearButton.label&&(S.innerHTML=e.clearButton.label),S.style.display=a;break;case"a11y":var l,r=e.a11y,o=!1;if("object"==typeof r)for(var n in r)r[n]&&O.a11y[n]&&(O.a11y[n]=r[n],o=!0);o&&(l=f("clr-open-label"),a=f("clr-swatch-label"),l.innerHTML=O.a11y.open,a.innerHTML=O.a11y.swatch,E.setAttribute("aria-label",O.a11y.close),T.setAttribute("aria-label",O.a11y.hueSlider),C.setAttribute("aria-label",O.a11y.alphaSlider),L.setAttribute("aria-label",O.a11y.input),w.setAttribute("aria-label",O.a11y.instruction))}}function i(e){h(b,"click",e,function(e){var t=O.parent,a=e.target.getBoundingClientRect(),l=y.scrollY,r={left:!1,top:!1},o={x:0,y:0},n=a.x,i=l+a.y+a.height+O.margin;B=e.target,M=B.value,N=function(e){e=e.substring(0,3).toLowerCase();return"rgb"!==e&&"hsl"!==e?"hex":e}(M),m.classList.add("clr-open");var c,s=m.offsetWidth,u=m.offsetHeight;t?(c=y.getComputedStyle(t),e=parseFloat(c.marginTop),c=parseFloat(c.borderTopWidth),(o=t.getBoundingClientRect()).y+=c+l,n-=o.x,i-=o.y,n+s>t.clientWidth&&(n+=a.width-s,r.left=!0),i+u>t.clientHeight-e&&(i-=a.height+u+2*O.margin,r.top=!0),i+=t.scrollTop):(n+s>b.documentElement.clientWidth&&(n+=a.width-s,r.left=!0),i+u-l>b.documentElement.clientHeight&&(i=l+a.y-u-O.margin,r.top=!0)),m.classList.toggle("clr-left",r.left),m.classList.toggle("clr-top",r.top),m.style.left=n+"px",m.style.top=i+"px",k={width:w.offsetWidth,height:w.offsetHeight,x:m.offsetLeft+w.offsetLeft+o.x,y:m.offsetTop+w.offsetTop+o.y},p(M),L.focus({preventScroll:!0})}),h(b,"input",e,function(e){var t=e.target.parentNode;t.classList.contains("clr-field")&&(t.style.color=e.target.value)})}function c(e){b.querySelectorAll(e).forEach(function(e){var t,a=e.parentNode;a.classList.contains("clr-field")||((t=b.createElement("div")).innerHTML='<button aria-labelledby="clr-open-label"></button>',a.insertBefore(t,e),t.setAttribute("class","clr-field"),t.style.color=e.value,t.appendChild(e))})}function l(e){B&&(e&&M!==B.value&&(B.value=M,B.dispatchEvent(new Event("input",{bubbles:!0}))),M!==B.value&&B.dispatchEvent(new Event("change",{bubbles:!0})),m.classList.remove("clr-open"),B.focus({preventScroll:!0}),B=null)}function p(e){var t=function(e){D.fillStyle="#000",D.fillStyle=e,e=(e=/^((rgba)|rgb)[\D]+([\d.]+)[\D]+([\d.]+)[\D]+([\d.]+)[\D]*?([\d.]+|$)/i.exec(D.fillStyle))?{r:+e[3],g:+e[4],b:+e[5],a:+e[6]}:(e=D.fillStyle.replace("#","").match(/.{2}/g).map(function(e){return parseInt(e,16)}),{r:e[0],g:e[1],b:e[2],a:1});return e}(e),e=function(e){var t=e.r/255,a=e.g/255,l=e.b/255,r=g.max(t,a,l),o=g.min(t,a,l),n=r-o,i=r,c=0,o=0;n&&(r===t&&(c=(a-l)/n),r===a&&(c=2+(l-t)/n),r===l&&(c=4+(t-a)/n),r&&(o=n/r));return{h:(c=g.floor(60*c))<0?c+360:c,s:g.round(100*o),v:g.round(100*i),a:e.a}}(t);n(e.s,e.v),s(t,e),T.value=e.h,m.style.color="hsl("+e.h+", 100%, 50%)",A.style.left=e.h/360*100+"%",x.style.left=k.width*e.s/100+"px",x.style.top=k.height-k.height*e.v/100+"px",C.value=100*e.a,H.style.left=100*e.a+"%"}function r(e){B&&(B.value=void 0!==e?e:L.value,B.dispatchEvent(new Event("input",{bubbles:!0})))}function o(e,t){e={h:+T.value,s:e/k.width*100,v:100-t/k.height*100,a:C.value/100},t=function(e){var t=e.s/100,a=e.v/100,l=t*a,r=e.h/60,o=l*(1-g.abs(r%2-1)),n=a-l;l+=n,o+=n;t=g.floor(r)%6,a=[l,o,n,n,o,l][t],r=[o,l,l,o,n,n][t],t=[n,n,o,l,l,o][t];return{r:g.round(255*a),g:g.round(255*r),b:g.round(255*t),a:e.a}}(e);n(e.s,e.v),s(t,e),r()}function n(e,t){var a=O.a11y.marker;e=+e.toFixed(1),t=+t.toFixed(1),a=(a=a.replace("{s}",e)).replace("{v}",t),x.setAttribute("aria-label",a)}function t(e){var t={pageX:((a=e).changedTouches?a.changedTouches[0]:a).pageX,pageY:(a.changedTouches?a.changedTouches[0]:a).pageY},a=t.pageX-k.x,t=t.pageY-k.y;O.parent&&(t+=O.parent.scrollTop),a=a<0?0:a>k.width?k.width:a,t=t<0?0:t>k.height?k.height:t,x.style.left=a+"px",x.style.top=t+"px",o(a,t),e.preventDefault(),e.stopPropagation()}function s(e,t){void 0===t&&(t={});var a,l,r=O.format;for(a in e=void 0===e?{}:e)j[a]=e[a];for(l in t)j[l]=t[l];var o,n=function(e){var t=e.r.toString(16),a=e.g.toString(16),l=e.b.toString(16),r="";e.r<16&&(t="0"+t);e.g<16&&(a="0"+a);e.b<16&&(l="0"+l);O.alpha&&e.a<1&&(e=255*e.a|0,r=e.toString(16),e<16&&(r="0"+r));return"#"+t+a+l+r}(j),i=n.substring(0,7);switch(x.style.color=i,H.parentNode.style.color=i,H.style.color=n,E.style.color=n,w.style.display="none",w.offsetHeight,w.style.display="",H.nextElementSibling.style.display="none",H.nextElementSibling.offsetHeight,H.nextElementSibling.style.display="","mixed"===r?r=1===j.a?"hex":"rgb":"auto"===r&&(r=N),r){case"hex":L.value=n;break;case"rgb":L.value=(o=j,O.alpha&&1!==o.a?"rgba("+o.r+", "+o.g+", "+o.b+", "+o.a+")":"rgb("+o.r+", "+o.g+", "+o.b+")");break;case"hsl":L.value=(o=function(e){var t,a=e.v/100,l=a*(1-e.s/100/2);0<l&&l<1&&(t=g.round((a-l)/g.min(l,1-l)*100));return{h:e.h,s:t||0,l:g.round(100*l),a:e.a}}(j),O.alpha&&1!==o.a?"hsla("+o.h+", "+o.s+"%, "+o.l+"%, "+o.a+")":"hsl("+o.h+", "+o.s+"%, "+o.l+"%)")}b.querySelector('.clr-format [value="'+r+'"]').checked=!0}function e(){var e=+T.value,t=+x.style.left.replace("px",""),a=+x.style.top.replace("px","");m.style.color="hsl("+e+", 100%, 50%)",A.style.left=e/360*100+"%",o(t,a)}function u(){var e=C.value/100;H.style.left=100*e+"%",s({a:e}),r()}function d(){(m=b.createElement("div")).setAttribute("id","clr-picker"),m.className="clr-picker",m.innerHTML='<input id="clr-color-value" class="clr-color" type="text" value="" aria-label="'+O.a11y.input+'"><div id="clr-color-area" class="clr-gradient" role="application" aria-label="'+O.a11y.instruction+'"><div id="clr-color-marker" class="clr-marker" tabindex="0"></div></div><div class="clr-hue"><input id="clr-hue-slider" type="range" min="0" max="360" step="1" aria-label="'+O.a11y.hueSlider+'"><div id="clr-hue-marker"></div></div><div class="clr-alpha"><input id="clr-alpha-slider" type="range" min="0" max="100" step="1" aria-label="'+O.a11y.alphaSlider+'"><div id="clr-alpha-marker"></div><span></span></div><div id="clr-format" class="clr-format"><fieldset class="clr-segmented"><legend>'+O.a11y.format+'</legend><input id="clr-f1" type="radio" name="clr-format" value="hex"><label for="clr-f1">Hex</label><input id="clr-f2" type="radio" name="clr-format" value="rgb"><label for="clr-f2">RGB</label><input id="clr-f3" type="radio" name="clr-format" value="hsl"><label for="clr-f3">HSL</label><span></span></fieldset></div><div id="clr-swatches" class="clr-swatches"></div><button id="clr-clear" class="clr-clear">'+O.clearButton.label+'</button><button id="clr-color-preview" class="clr-preview" aria-label="'+O.a11y.close+'"></button><span id="clr-open-label" hidden>'+O.a11y.open+'</span><span id="clr-swatch-label" hidden>'+O.a11y.swatch+"</span>",b.body.appendChild(m),w=f("clr-color-area"),x=f("clr-color-marker"),S=f("clr-clear"),E=f("clr-color-preview"),L=f("clr-color-value"),T=f("clr-hue-slider"),A=f("clr-hue-marker"),C=f("clr-alpha-slider"),H=f("clr-alpha-marker"),i(O.el),c(O.el),h(m,"mousedown",function(e){m.classList.remove("clr-keyboard-nav"),e.stopPropagation()}),h(w,"mousedown",function(e){h(b,"mousemove",t)}),h(w,"touchstart",function(e){b.addEventListener("touchmove",t,{passive:!1})}),h(x,"mousedown",function(e){h(b,"mousemove",t)}),h(x,"touchstart",function(e){b.addEventListener("touchmove",t,{passive:!1})}),h(L,"change",function(e){p(L.value),r()}),h(S,"click",function(e){r(""),l()}),h(E,"click",function(e){r(),l()}),h(b,"click",".clr-format input",function(e){N=e.target.value,s(),r()}),h(m,"click",".clr-swatches button",function(e){p(e.target.textContent),r()}),h(b,"mouseup",function(e){b.removeEventListener("mousemove",t)}),h(b,"touchend",function(e){b.removeEventListener("touchmove",t)}),h(b,"mousedown",function(e){m.classList.remove("clr-keyboard-nav"),l()}),h(b,"keydown",function(e){"Escape"===e.key?l(!0):"Tab"===e.key&&m.classList.add("clr-keyboard-nav")}),h(b,"click",".clr-field button",function(e){e.target.nextElementSibling.dispatchEvent(new Event("click",{bubbles:!0}))}),h(x,"keydown",function(e){var t={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]};-1!==Object.keys(t).indexOf(e.key)&&(!function(e,t){e=+x.style.left.replace("px","")+e,t=+x.style.top.replace("px","")+t,x.style.left=e+"px",x.style.top=t+"px",o(e,t)}.apply(void 0,t[e.key]),e.preventDefault())}),h(w,"click",t),h(T,"input",e),h(C,"input",u)}function f(e){return b.getElementById(e)}function h(e,t,a,l){var r=Element.prototype.matches||Element.prototype.msMatchesSelector;"string"==typeof a?e.addEventListener(t,function(e){r.call(e.target,a)&&l.call(e.target,e)}):(l=a,e.addEventListener(t,l))}function v(e,t){t=void 0!==t?t:[],"loading"!==b.readyState?e.apply(void 0,t):b.addEventListener("DOMContentLoaded",function(){e.apply(void 0,t)})}var y,b,g,m,w,k,x,E,L,S,T,A,C,H,B,N,M,D,j,O}); |
{ | ||
"name": "@melloware/coloris", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "A lightweight and elegant color picker.", | ||
@@ -18,3 +18,3 @@ "author": "Momo Bassit", | ||
"type": "git", | ||
"url": "https://github.com/melloware/Coloris.git" | ||
"url": "https://github.com/melloware/coloris-npm.git" | ||
}, | ||
@@ -21,0 +21,0 @@ "bugs": { |
@@ -0,1 +1,4 @@ | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
[![npm version](https://badge.fury.io/js/@melloware%2Fcoloris.svg)](https://badge.fury.io/js/@melloware%2Fcoloris) | ||
![Maven](https://img.shields.io/maven-central/v/org.webjars.npm/melloware__coloris) | ||
@@ -80,2 +83,14 @@ # Coloris NPM | ||
### Java / Maven | ||
The colorpicker can also be downloaded as a Java JAR for use in Java web applicatons: | ||
```xml | ||
<dependency> | ||
<groupId>org.webjars.npm</groupId> | ||
<artifactId>melloware__coloris</artifactId> | ||
<version>0.6.0</version> | ||
</dependency> | ||
``` | ||
### Options | ||
@@ -82,0 +97,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73244
1418
237