@melloware/coloris
Advanced tools
Comparing version 0.16.1 to 0.17.0
@@ -105,2 +105,17 @@ /** | ||
/** | ||
* Configuration for the optional close button on the color picker. | ||
*/ | ||
interface CloseButtonOptions { | ||
/** | ||
* Whether the close button is displayed when the color picker is opened. | ||
*/ | ||
show: boolean; | ||
/** | ||
* The label text shown on the close button. | ||
*/ | ||
label: string; | ||
} | ||
interface ColorisOptions { | ||
@@ -229,2 +244,10 @@ /** | ||
/** | ||
* Shows a close button and set its label. By default, no close button is | ||
* shown. | ||
* | ||
* @default undefined | ||
*/ | ||
closeButton?: CloseButtonOptions; | ||
/** | ||
* An array of the desired color swatches to display. If omitted or the | ||
@@ -231,0 +254,0 @@ * array is empty, the color swatches will be disabled. |
@@ -12,3 +12,3 @@ var Coloris = function () { | ||
var container, picker, colorArea, colorAreaDims, colorMarker, colorPreview, colorValue, clearButton, | ||
hueSlider, hueMarker, alphaSlider, alphaMarker, currentEl, currentFormat, oldColor; | ||
closeButton, hueSlider, hueMarker, alphaSlider, alphaMarker, currentEl, currentFormat, oldColor; | ||
@@ -35,5 +35,8 @@ // Default settings | ||
clearLabel: 'Clear', | ||
closeButton: false, | ||
closeLabel: 'Close', | ||
a11y: { | ||
open: 'Open color picker', | ||
close: 'Close color picker', | ||
clear: 'Clear the selected color', | ||
marker: 'Saturation: {s}. Brightness: {v}.', | ||
@@ -45,6 +48,6 @@ hueSlider: 'Hue slider', | ||
swatch: 'Color swatch', | ||
instruction: 'Saturation and brightness selector. Use up, down, left and right arrow keys to select.' } }; | ||
instruction: 'Saturation and brightness selector. Use up, down, left and right arrow keys to select.' | ||
} | ||
}; | ||
// Virtual instances cache | ||
@@ -63,5 +66,5 @@ var instances = {}; | ||
return; | ||
} | ||
}var _loop = function _loop() | ||
for (var key in options) { | ||
{ | ||
switch (key) { | ||
@@ -122,11 +125,11 @@ case 'el': | ||
case 'swatches': | ||
if (Array.isArray(options.swatches)) {(function () { | ||
var swatches = []; | ||
if (Array.isArray(options.swatches)) { | ||
var swatches = []; | ||
options.swatches.forEach(function (swatch, i) { | ||
swatches.push("<button type=\"button\" id=\"clr-swatch-" + i + "\" aria-labelledby=\"clr-swatch-label clr-swatch-" + i + "\" style=\"color: " + swatch + ";\">" + swatch + "</button>"); | ||
}); | ||
options.swatches.forEach(function (swatch, i) { | ||
swatches.push("<button type=\"button\" id=\"clr-swatch-" + i + "\" aria-labelledby=\"clr-swatch-label clr-swatch-" + i + "\" style=\"color: " + swatch + ";\">" + swatch + "</button>"); | ||
}); | ||
getEl('clr-swatches').innerHTML = swatches.length ? "<div>" + swatches.join('') + "</div>" : ''; | ||
settings.swatches = options.swatches.slice();})(); | ||
getEl('clr-swatches').innerHTML = swatches.length ? "<div>" + swatches.join('') + "</div>" : ''; | ||
settings.swatches = options.swatches.slice(); | ||
} | ||
@@ -172,2 +175,16 @@ break; | ||
break; | ||
case 'closeButton': | ||
settings.closeButton = !!options.closeButton; | ||
if (settings.closeButton) { | ||
picker.insertBefore(closeButton, colorPreview); | ||
} else { | ||
colorPreview.appendChild(closeButton); | ||
} | ||
break; | ||
case 'closeLabel': | ||
settings.closeLabel = options.closeLabel; | ||
closeButton.innerHTML = settings.closeLabel; | ||
break; | ||
case 'a11y': | ||
@@ -192,3 +209,4 @@ var labels = options.a11y; | ||
swatchLabel.innerHTML = settings.a11y.swatch; | ||
colorPreview.setAttribute('aria-label', settings.a11y.close); | ||
closeButton.setAttribute('aria-label', settings.a11y.close); | ||
clearButton.setAttribute('aria-label', settings.a11y.clear); | ||
hueSlider.setAttribute('aria-label', settings.a11y.hueSlider); | ||
@@ -202,3 +220,3 @@ alphaSlider.setAttribute('aria-label', settings.a11y.alphaSlider); | ||
} | ||
};for (var key in options) {_loop();} | ||
} | ||
@@ -241,5 +259,5 @@ | ||
// These options can only be set globally, not per instance | ||
var unsupportedOptions = ['el', 'wrap', 'inline', 'defaultColor', 'a11y'];var _loop = function _loop( | ||
var unsupportedOptions = ['el', 'wrap', 'inline', 'defaultColor', 'a11y'];var _loop2 = function _loop2() | ||
selector) { | ||
{ | ||
var options = instances[selector]; | ||
@@ -261,6 +279,6 @@ | ||
// Set the instance's options | ||
configure(options); | ||
return "break"; | ||
}};for (var selector in instances) {var _ret = _loop(selector);if (_ret === "break") break; | ||
} | ||
configure(options);return "break"; | ||
} | ||
};for (var selector in instances) {var _ret = _loop2();if (_ret === "break") break;} | ||
} | ||
@@ -397,4 +415,4 @@ } | ||
x: picker.offsetLeft + colorArea.offsetLeft + offset.x, | ||
y: picker.offsetTop + colorArea.offsetTop + offset.y }; | ||
y: picker.offsetTop + colorArea.offsetTop + offset.y | ||
}; | ||
} | ||
@@ -533,4 +551,4 @@ | ||
v: 100 - y / colorAreaDims.height * 100, | ||
a: alphaSlider.value / 100 }; | ||
a: alphaSlider.value / 100 | ||
}; | ||
var rgba = HSVAtoRGBA(hsva); | ||
@@ -567,4 +585,4 @@ | ||
pageX: event.changedTouches ? event.changedTouches[0].pageX : event.pageX, | ||
pageY: event.changedTouches ? event.changedTouches[0].pageY : event.pageY }; | ||
pageY: event.changedTouches ? event.changedTouches[0].pageY : event.pageY | ||
}; | ||
} | ||
@@ -585,10 +603,4 @@ | ||
x = x < 0 ? 0 : x > colorAreaDims.width ? colorAreaDims.width : x; | ||
y = y < 0 ? 0 : y > colorAreaDims.height ? colorAreaDims.height : y; | ||
setMarkerPosition(x, y); | ||
colorMarker.style.left = x + "px"; | ||
colorMarker.style.top = y + "px"; | ||
setColorAtPosition(x, y); | ||
// Prevent scrolling while dragging the marker | ||
@@ -602,3 +614,3 @@ event.preventDefault(); | ||
* @param {number} offsetX The horizontal amount to move. | ||
* * @param {number} offsetY The vertical amount to move. | ||
* @param {number} offsetY The vertical amount to move. | ||
*/ | ||
@@ -609,6 +621,24 @@ function moveMarkerOnKeydown(offsetX, offsetY) { | ||
setMarkerPosition(x, y); | ||
} | ||
/** | ||
* Set the color marker's position. | ||
* @param {number} x Left position. | ||
* @param {number} y Top position. | ||
*/ | ||
function setMarkerPosition(x, y) { | ||
// Make sure the marker doesn't go out of bounds | ||
x = x < 0 ? 0 : x > colorAreaDims.width ? colorAreaDims.width : x; | ||
y = y < 0 ? 0 : y > colorAreaDims.height ? colorAreaDims.height : y; | ||
// Set the position | ||
colorMarker.style.left = x + "px"; | ||
colorMarker.style.top = y + "px"; | ||
// Update the color | ||
setColorAtPosition(x, y); | ||
// Make sure the marker is focused | ||
colorMarker.focus(); | ||
} | ||
@@ -720,4 +750,4 @@ | ||
b: Math.round(blue * 255), | ||
a: hsva.a }; | ||
a: hsva.a | ||
}; | ||
} | ||
@@ -743,4 +773,4 @@ | ||
l: Math.round(lightness * 100), | ||
a: hsva.a }; | ||
a: hsva.a | ||
}; | ||
} | ||
@@ -777,4 +807,4 @@ | ||
v: Math.round(value * 100), | ||
a: rgba.a }; | ||
a: rgba.a | ||
}; | ||
} | ||
@@ -803,5 +833,5 @@ | ||
b: match[5] * 1, | ||
a: match[6] * 1 }; | ||
a: match[6] * 1 | ||
}; | ||
// Workaround to mitigate a Chromium bug where the alpha value is rounded incorrectly | ||
@@ -816,4 +846,4 @@ rgba.a = +rgba.a.toFixed(2); | ||
b: match[2], | ||
a: 1 }; | ||
a: 1 | ||
}; | ||
} | ||
@@ -920,5 +950,7 @@ | ||
'</div>' + | ||
'<div id="clr-swatches" class="clr-swatches"></div>' + ("<button type=\"button\" id=\"clr-clear\" class=\"clr-clear\">" + | ||
settings.clearLabel + "</button>") + ("<button type=\"button\" id=\"clr-color-preview\" class=\"clr-preview\" aria-label=\"" + | ||
settings.a11y.close + "\"></button>") + ("<span id=\"clr-open-label\" hidden>" + | ||
'<div id="clr-swatches" class="clr-swatches"></div>' + ("<button type=\"button\" id=\"clr-clear\" class=\"clr-clear\" aria-label=\"" + | ||
settings.a11y.clear + "\">" + settings.clearLabel + "</button>") + | ||
'<div id="clr-color-preview" class="clr-preview">' + ("<button type=\"button\" id=\"clr-close\" class=\"clr-close\" aria-label=\"" + | ||
settings.a11y.close + "\">" + settings.closeLabel + "</button>") + | ||
'</div>' + ("<span id=\"clr-open-label\" hidden>" + | ||
settings.a11y.open + "</span>") + ("<span id=\"clr-swatch-label\" hidden>" + | ||
@@ -934,2 +966,3 @@ settings.a11y.swatch + "</span>"); | ||
clearButton = getEl('clr-clear'); | ||
closeButton = getEl('clr-close'); | ||
colorPreview = getEl('clr-color-preview'); | ||
@@ -968,3 +1001,3 @@ colorValue = getEl('clr-color-value'); | ||
addListener(colorValue, 'change', function (event) { | ||
if (currentEl) { | ||
if (currentEl || settings.inline) { | ||
setColorFromStr(colorValue.value); | ||
@@ -980,3 +1013,3 @@ pickColor(); | ||
addListener(colorPreview, 'click', function (event) { | ||
addListener(closeButton, 'click', function (event) { | ||
pickColor(); | ||
@@ -1015,5 +1048,9 @@ closePicker(); | ||
addListener(document, 'keydown', function (event) { | ||
var navKeys = ['Tab', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight']; | ||
if (event.key === 'Escape') { | ||
closePicker(true); | ||
} else if (event.key === 'Tab') { | ||
// Display focus rings when using the keyboard | ||
} else if (navKeys.includes(event.key)) { | ||
picker.classList.add('clr-keyboard-nav'); | ||
@@ -1038,6 +1075,6 @@ } | ||
ArrowLeft: [-1, 0], | ||
ArrowRight: [1, 0] }; | ||
ArrowRight: [1, 0] | ||
}; | ||
if (Object.keys(movements).indexOf(event.key) !== -1) { | ||
if (Object.keys(movements).includes(event.key)) { | ||
moveMarkerOnKeydown.apply(void 0, movements[event.key]); | ||
@@ -1119,5 +1156,5 @@ event.preventDefault(); | ||
removeInstance: removeVirtualInstance, | ||
updatePosition: updatePickerPosition }; | ||
updatePosition: updatePickerPosition | ||
}; | ||
function Coloris(options) { | ||
@@ -1133,9 +1170,9 @@ DOMReady(function () { | ||
}); | ||
}var _loop2 = function _loop2( | ||
}var _loop3 = function _loop3(key) | ||
key) { | ||
{ | ||
Coloris[key] = function () {for (var _len = arguments.length, args = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {args[_key2] = arguments[_key2];} | ||
DOMReady(methods[key], args); | ||
};};for (var key in methods) {_loop2(key); | ||
} | ||
}; | ||
};for (var key in methods) {_loop3(key);} | ||
@@ -1142,0 +1179,0 @@ return Coloris; |
@@ -7,2 +7,2 @@ var Coloris=function(){ | ||
*/ | ||
return h=window,v=document,b=Math,B=v.createElement("canvas").getContext("2d"),O={el:"[data-coloris]",parent:"body",theme:"default",themeMode:"light",wrap:!0,margin:2,format:"hex",formatToggle:!(H={r:0,g:0,b:0,h:0,s:0,v:0,a:1}),swatches:[],swatchesOnly:!1,alpha:!0,forceAlpha:!1,focusInput:!0,selectInput:!1,inline:!1,defaultColor:"#000000",clearButton:!1,clearLabel:"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."}},N={},I="",j=!(_={}),void 0!==NodeList&&NodeList.prototype&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),($=function(){var r={init:X,set:n,wrap:s,close:l,setInstance:D,removeInstance:F,updatePosition:c};function e(e){U(function(){e&&("string"==typeof e?i:n)(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];U(r[l],t)}}(t);return e}()).coloris=$;function n(e){if("object"==typeof e)for(var t in e)switch(t){case"el":i(e.el),!1!==e.wrap&&s(e.el);break;case"parent":(y=v.querySelector(e.parent))&&(y.appendChild(g),O.parent=e.parent,y===v.body&&(y=null));break;case"themeMode":O.themeMode=e.themeMode,"auto"===e.themeMode&&h.matchMedia&&h.matchMedia("(prefers-color-scheme: dark)").matches&&(O.themeMode="dark");case"theme":e.theme&&(O.theme=e.theme),g.className="clr-picker clr-"+O.theme+" clr-"+O.themeMode,O.inline&&c();break;case"margin":e.margin*=1,O.margin=(isNaN(e.margin)?O:e).margin;break;case"wrap":e.el&&e.wrap&&s(e.el);break;case"formatToggle":O.formatToggle=!!e.formatToggle,f("clr-format").style.display=O.formatToggle?"block":"none",O.formatToggle&&(O.format="auto");break;case"swatches":Array.isArray(e.swatches)&&!function(){var a=[];e.swatches.forEach(function(e,t){a.push('<button type="button" id="clr-swatch-'+t+'" aria-labelledby="clr-swatch-label clr-swatch-'+t+'" style="color: '+e+';">'+e+"</button>")}),f("clr-swatches").innerHTML=a.length?"<div>"+a.join("")+"</div>":"",O.swatches=e.swatches.slice()}();break;case"swatchesOnly":O.swatchesOnly=!!e.swatchesOnly,g.setAttribute("data-minimal",O.swatchesOnly);break;case"alpha":O.alpha=!!e.alpha,g.setAttribute("data-alpha",O.alpha);break;case"inline":O.inline=!!e.inline,g.setAttribute("data-inline",O.inline),O.inline&&(a=e.defaultColor||O.defaultColor,M=R(a),c(),u(a));break;case"clearButton":"object"==typeof e.clearButton&&(e.clearButton.label&&(O.clearLabel=e.clearButton.label,E.innerHTML=O.clearLabel),e.clearButton=e.clearButton.show),O.clearButton=!!e.clearButton,E.style.display=O.clearButton?"block":"none";break;case"clearLabel":O.clearLabel=e.clearLabel,E.innerHTML=O.clearLabel;break;case"a11y":var a,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&&(a=f("clr-open-label"),l=f("clr-swatch-label"),a.innerHTML=O.a11y.open,l.innerHTML=O.a11y.swatch,x.setAttribute("aria-label",O.a11y.close),S.setAttribute("aria-label",O.a11y.hueSlider),C.setAttribute("aria-label",O.a11y.alphaSlider),L.setAttribute("aria-label",O.a11y.input),m.setAttribute("aria-label",O.a11y.instruction));default:O[t]=e[t]}}function D(e,t){"string"==typeof e&&"object"==typeof t&&(N[e]=t,j=!0)}function F(e){delete N[e],0===Object.keys(N).length&&(j=!1,e===I&&a())}function W(l){if(j){var e,r=["el","wrap","inline","defaultColor","a11y"];for(e in N)if("break"===function(e){var t=N[e];if(l.matches(e)){for(var a in I=e,_={},r.forEach(function(e){return delete t[e]}),t)_[a]=Array.isArray(O[a])?O[a].slice():O[a];return n(t),"break"}}(e))break}}function a(){0<Object.keys(_).length&&(n(_),I="",_={})}function i(e){r(v,"click",e,function(e){O.inline||(W(e.target),T=e.target,o=T.value,M=R(o),g.classList.add("clr-open"),c(),u(o),(O.focusInput||O.selectInput)&&L.focus({preventScroll:!0}),O.selectInput&&L.select(),T.dispatchEvent(new Event("open",{bubbles:!0})))}),r(v,"input",e,function(e){var t=e.target.parentNode;t.classList.contains("clr-field")&&(t.style.color=e.target.value)})}function c(){var e,t,a,l,r=y,n=h.scrollY,o=g.offsetWidth,i=g.offsetHeight,c={left:!1,top:!1},s={x:0,y:0};r&&(t=h.getComputedStyle(r),e=parseFloat(t.marginTop),t=parseFloat(t.borderTopWidth),(s=r.getBoundingClientRect()).y+=t+n),O.inline||(a=(t=T.getBoundingClientRect()).x,l=n+t.y+t.height+O.margin,r?(a-=s.x,l-=s.y,a+o>r.clientWidth&&(a+=t.width-o,c.left=!0),l+i>r.clientHeight-e&&i+O.margin<=t.top-(s.y-n)&&(l-=t.height+i+2*O.margin,c.top=!0),l+=r.scrollTop):(a+o>v.documentElement.clientWidth&&(a+=t.width-o,c.left=!0),l+i-n>v.documentElement.clientHeight&&i+O.margin<=t.top&&(l=n+t.y-i-O.margin,c.top=!0)),g.classList.toggle("clr-left",c.left),g.classList.toggle("clr-top",c.top),g.style.left=a+"px",g.style.top=l+"px"),w={width:m.offsetWidth,height:m.offsetHeight,x:g.offsetLeft+m.offsetLeft+s.x,y:g.offsetTop+m.offsetTop+s.y}}function s(e){v.querySelectorAll(e).forEach(function(e){var t,a=e.parentNode;a.classList.contains("clr-field")||((t=v.createElement("div")).innerHTML='<button type="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){var t;T&&!O.inline&&(t=T,e&&(T=null,o!==t.value&&(t.value=o,t.dispatchEvent(new Event("input",{bubbles:!0})))),setTimeout(function(){o!==t.value&&t.dispatchEvent(new Event("change",{bubbles:!0}))}),g.classList.remove("clr-open"),j&&a(),t.dispatchEvent(new Event("close",{bubbles:!0})),O.focusInput&&t.focus({preventScroll:!0}),T=null)}function u(e){var e=function(e){var t;B.fillStyle="#000",B.fillStyle=e,(e=/^((rgba)|rgb)[\D]+([\d.]+)[\D]+([\d.]+)[\D]+([\d.]+)[\D]*?([\d.]+|$)/i.exec(B.fillStyle))?(t={r:+e[3],g:+e[4],b:+e[5],a:+e[6]}).a=+t.a.toFixed(2):(e=B.fillStyle.replace("#","").match(/.{2}/g).map(function(e){return parseInt(e,16)}),t={r:e[0],g:e[1],b:e[2],a:1});return t}(e),t=function(e){var t=e.r/255,a=e.g/255,l=e.b/255,r=b.max(t,a,l),n=b.min(t,a,l),n=r-n,o=r,i=0,c=0;n&&(r===t&&(i=(a-l)/n),r===a&&(i=2+(l-t)/n),r===l&&(i=4+(t-a)/n),r&&(c=n/r));return{h:(i=b.floor(60*i))<0?i+360:i,s:b.round(100*c),v:b.round(100*o),a:e.a}}(e);q(t.s,t.v),d(e,t),S.value=t.h,g.style.color="hsl("+t.h+", 100%, 50%)",G.style.left=t.h/360*100+"%",k.style.left=w.width*t.s/100+"px",k.style.top=w.height-w.height*t.v/100+"px",C.value=100*t.a,A.style.left=100*t.a+"%"}function R(e){e=e.substring(0,3).toLowerCase();return"rgb"===e||"hsl"===e?e:"hex"}function p(e){e=void 0!==e?e:L.value,T&&(T.value=e,T.dispatchEvent(new Event("input",{bubbles:!0}))),v.dispatchEvent(new CustomEvent("coloris:pick",{detail:{color:e}}))}function Y(e,t){var a,l,r,n,o,e={h:+S.value,s:e/w.width*100,v:100-t/w.height*100,a:C.value/100},i=(i=(t=e).s/100,a=t.v/100,i*=a,l=t.h/60,r=i*(1-b.abs(l%2-1)),i+=a-=i,r+=a,l=b.floor(l)%6,n=[i,r,a,a,r,i][l],o=[r,i,i,r,a,a][l],a=[a,a,r,i,i,r][l],{r:b.round(255*n),g:b.round(255*o),b:b.round(255*a),a:t.a});q(e.s,e.v),d(i,e),p()}function q(e,t){var a=O.a11y.marker;e=+e.toFixed(1),t=+t.toFixed(1),a=(a=a.replace("{s}",e)).replace("{v}",t),k.setAttribute("aria-label",a)}function t(e){var t={pageX:((t=e).changedTouches?t.changedTouches[0]:t).pageX,pageY:(t.changedTouches?t.changedTouches[0]:t).pageY},a=t.pageX-w.x,t=t.pageY-w.y;y&&(t+=y.scrollTop),a=a<0?0:a>w.width?w.width:a,t=t<0?0:t>w.height?w.height:t,k.style.left=a+"px",k.style.top=t+"px",Y(a,t),e.preventDefault(),e.stopPropagation()}function d(e,t){void 0===t&&(t={});var a,l,r=O.format;for(a in e=void 0===e?{}:e)H[a]=e[a];for(l in t)H[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||O.forceAlpha)&&(e=255*e.a|0,r=e.toString(16),e<16&&(r="0"+r));return"#"+t+a+l+r}(H),i=o.substring(0,7);switch(k.style.color=i,A.parentNode.style.color=i,A.style.color=o,x.style.color=o,m.style.display="none",m.offsetHeight,m.style.display="",A.nextElementSibling.style.display="none",A.nextElementSibling.offsetHeight,A.nextElementSibling.style.display="","mixed"===r?r=1===H.a?"hex":"rgb":"auto"===r&&(r=M),r){case"hex":L.value=o;break;case"rgb":L.value=(n=H,!O.alpha||1===n.a&&!O.forceAlpha?"rgb("+n.r+", "+n.g+", "+n.b+")":"rgba("+n.r+", "+n.g+", "+n.b+", "+n.a+")");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=b.round((a-l)/b.min(l,1-l)*100));return{h:e.h,s:t||0,l:b.round(100*l),a:e.a}}(H),!O.alpha||1===n.a&&!O.forceAlpha?"hsl("+n.h+", "+n.s+"%, "+n.l+"%)":"hsla("+n.h+", "+n.s+"%, "+n.l+"%, "+n.a+")")}v.querySelector('.clr-format [value="'+r+'"]').checked=!0}function e(){var e=+S.value,t=+k.style.left.replace("px",""),a=+k.style.top.replace("px","");g.style.color="hsl("+e+", 100%, 50%)",G.style.left=e/360*100+"%",Y(t,a)}function P(){var e=C.value/100;A.style.left=100*e+"%",d({a:e}),p()}function X(){y=null,(g=v.createElement("div")).setAttribute("id","clr-picker"),g.className="clr-picker",g.innerHTML='<input id="clr-color-value" class="clr-color" type="text" value="" spellcheck="false" 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 type="button" id="clr-clear" class="clr-clear">'+O.clearLabel+'</button><button type="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>",v.body.appendChild(g),m=f("clr-color-area"),k=f("clr-color-marker"),E=f("clr-clear"),x=f("clr-color-preview"),L=f("clr-color-value"),S=f("clr-hue-slider"),G=f("clr-hue-marker"),C=f("clr-alpha-slider"),A=f("clr-alpha-marker"),i(O.el),s(O.el),r(g,"mousedown",function(e){g.classList.remove("clr-keyboard-nav"),e.stopPropagation()}),r(m,"mousedown",function(e){r(v,"mousemove",t)}),r(m,"touchstart",function(e){v.addEventListener("touchmove",t,{passive:!1})}),r(k,"mousedown",function(e){r(v,"mousemove",t)}),r(k,"touchstart",function(e){v.addEventListener("touchmove",t,{passive:!1})}),r(L,"change",function(e){T&&(u(L.value),p())}),r(E,"click",function(e){p(""),l()}),r(x,"click",function(e){p(),l()}),r(v,"click",".clr-format input",function(e){M=e.target.value,d(),p()}),r(g,"click",".clr-swatches button",function(e){u(e.target.textContent),p(),O.swatchesOnly&&l()}),r(v,"mouseup",function(e){v.removeEventListener("mousemove",t)}),r(v,"touchend",function(e){v.removeEventListener("touchmove",t)}),r(v,"mousedown",function(e){g.classList.remove("clr-keyboard-nav"),l()}),r(v,"keydown",function(e){"Escape"===e.key?l(!0):"Tab"===e.key&&g.classList.add("clr-keyboard-nav")}),r(v,"click",".clr-field button",function(e){j&&a(),e.target.nextElementSibling.dispatchEvent(new Event("click",{bubbles:!0}))}),r(k,"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=+k.style.left.replace("px","")+e,t=+k.style.top.replace("px","")+t,k.style.left=e+"px",k.style.top=t+"px",Y(e,t)}.apply(void 0,t[e.key]),e.preventDefault())}),r(m,"click",t),r(S,"input",e),r(C,"input",P)}function f(e){return v.getElementById(e)}function r(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 U(e,t){t=void 0!==t?t:[],"loading"!==v.readyState?e.apply(void 0,t):v.addEventListener("DOMContentLoaded",function(){e.apply(void 0,t)})}var h,v,b,y,g,m,w,k,x,L,E,S,G,C,A,T,M,o,B,H,O,N,I,_,j,$}(),_coloris=Coloris.coloris,_init=Coloris.init,_set=Coloris.set,_wrap=Coloris.wrap,_close=Coloris.close;export default Coloris;export{_coloris as coloris,_close as close,_init as init,_set as set,_wrap as wrap}; | ||
return h=window,b=document,v=Math,i=b.createElement("canvas").getContext("2d"),O={el:"[data-coloris]",parent:"body",theme:"default",themeMode:"light",wrap:!0,margin:2,format:"hex",formatToggle:!(H={r:0,g:0,b:0,h:0,s:0,v:0,a:1}),swatches:[],swatchesOnly:!1,alpha:!0,forceAlpha:!1,focusInput:!0,selectInput:!1,inline:!1,defaultColor:"#000000",clearButton:!1,clearLabel:"Clear",closeButton:!1,closeLabel:"Close",a11y:{open:"Open color picker",close:"Close color picker",clear:"Clear the selected color",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."}},N={},I="",D=!(_={}),void 0!==NodeList&&NodeList.prototype&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),(J=function(){var r={init:G,set:o,wrap:s,close:l,setInstance:j,removeInstance:F,updatePosition:c};function e(e){$(function(){e&&("string"==typeof e?W:o)(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];$(r[l],t)}}(t);return e}()).coloris=J;function o(n){if("object"==typeof n)for(var i in n)!function(){switch(i){case"el":W(n.el),!1!==n.wrap&&s(n.el);break;case"parent":(y=b.querySelector(n.parent))&&(y.appendChild(g),O.parent=n.parent,y===b.body)&&(y=null);break;case"themeMode":O.themeMode=n.themeMode,"auto"===n.themeMode&&h.matchMedia&&h.matchMedia("(prefers-color-scheme: dark)").matches&&(O.themeMode="dark");case"theme":n.theme&&(O.theme=n.theme),g.className="clr-picker clr-"+O.theme+" clr-"+O.themeMode,O.inline&&c();break;case"margin":n.margin*=1,O.margin=(isNaN(n.margin)?O:n).margin;break;case"wrap":n.el&&n.wrap&&s(n.el);break;case"formatToggle":O.formatToggle=!!n.formatToggle,f("clr-format").style.display=O.formatToggle?"block":"none",O.formatToggle&&(O.format="auto");break;case"swatches":var a;Array.isArray(n.swatches)&&(a=[],n.swatches.forEach(function(e,t){a.push('<button type="button" id="clr-swatch-'+t+'" aria-labelledby="clr-swatch-label clr-swatch-'+t+'" style="color: '+e+';">'+e+"</button>")}),f("clr-swatches").innerHTML=a.length?"<div>"+a.join("")+"</div>":"",O.swatches=n.swatches.slice());break;case"swatchesOnly":O.swatchesOnly=!!n.swatchesOnly,g.setAttribute("data-minimal",O.swatchesOnly);break;case"alpha":O.alpha=!!n.alpha,g.setAttribute("data-alpha",O.alpha);break;case"inline":O.inline=!!n.inline,g.setAttribute("data-inline",O.inline),O.inline&&(e=n.defaultColor||O.defaultColor,M=Y(e),c(),u(e));break;case"clearButton":"object"==typeof n.clearButton&&(n.clearButton.label&&(O.clearLabel=n.clearButton.label,E.innerHTML=O.clearLabel),n.clearButton=n.clearButton.show),O.clearButton=!!n.clearButton,E.style.display=O.clearButton?"block":"none";break;case"clearLabel":O.clearLabel=n.clearLabel,E.innerHTML=O.clearLabel;break;case"closeButton":O.closeButton=!!n.closeButton,O.closeButton?g.insertBefore(A,L):L.appendChild(A);break;case"closeLabel":O.closeLabel=n.closeLabel,A.innerHTML=O.closeLabel;break;case"a11y":var e,t,l=n.a11y,r=!1;if("object"==typeof l)for(var o in l)l[o]&&O.a11y[o]&&(O.a11y[o]=l[o],r=!0);r&&(e=f("clr-open-label"),t=f("clr-swatch-label"),e.innerHTML=O.a11y.open,t.innerHTML=O.a11y.swatch,A.setAttribute("aria-label",O.a11y.close),E.setAttribute("aria-label",O.a11y.clear),C.setAttribute("aria-label",O.a11y.hueSlider),S.setAttribute("aria-label",O.a11y.alphaSlider),x.setAttribute("aria-label",O.a11y.input),m.setAttribute("aria-label",O.a11y.instruction));default:O[i]=n[i]}}()}function j(e,t){"string"==typeof e&&"object"==typeof t&&(N[e]=t,D=!0)}function F(e){delete N[e],0===Object.keys(N).length&&(D=!1,e===I)&&a()}function R(a){if(D){var l,r=["el","wrap","inline","defaultColor","a11y"];for(l in N)if("break"===function(){var t=N[l];if(a.matches(l)){for(var e in I=l,_={},r.forEach(function(e){return delete t[e]}),t)_[e]=Array.isArray(O[e])?O[e].slice():O[e];return o(t),"break"}}())break}}function a(){0<Object.keys(_).length&&(o(_),I="",_={})}function W(e){r(b,"click",e,function(e){O.inline||(R(e.target),B=e.target,n=B.value,M=Y(n),g.classList.add("clr-open"),c(),u(n),(O.focusInput||O.selectInput)&&x.focus({preventScroll:!0}),O.selectInput&&x.select(),B.dispatchEvent(new Event("open",{bubbles:!0})))}),r(b,"input",e,function(e){var t=e.target.parentNode;t.classList.contains("clr-field")&&(t.style.color=e.target.value)})}function c(){var e,t,a,l,r=y,o=h.scrollY,n=g.offsetWidth,i=g.offsetHeight,c={left:!1,top:!1},s={x:0,y:0};r&&(t=h.getComputedStyle(r),e=parseFloat(t.marginTop),t=parseFloat(t.borderTopWidth),(s=r.getBoundingClientRect()).y+=t+o),O.inline||(a=(t=B.getBoundingClientRect()).x,l=o+t.y+t.height+O.margin,r?(a-=s.x,l-=s.y,a+n>r.clientWidth&&(a+=t.width-n,c.left=!0),l+i>r.clientHeight-e&&i+O.margin<=t.top-(s.y-o)&&(l-=t.height+i+2*O.margin,c.top=!0),l+=r.scrollTop):(a+n>b.documentElement.clientWidth&&(a+=t.width-n,c.left=!0),l+i-o>b.documentElement.clientHeight&&i+O.margin<=t.top&&(l=o+t.y-i-O.margin,c.top=!0)),g.classList.toggle("clr-left",c.left),g.classList.toggle("clr-top",c.top),g.style.left=a+"px",g.style.top=l+"px"),w={width:m.offsetWidth,height:m.offsetHeight,x:g.offsetLeft+m.offsetLeft+s.x,y:g.offsetTop+m.offsetTop+s.y}}function s(e){b.querySelectorAll(e).forEach(function(e){var t,a=e.parentNode;a.classList.contains("clr-field")||((t=b.createElement("div")).innerHTML='<button type="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){var t;B&&!O.inline&&(t=B,e&&(B=null,n!==t.value)&&(t.value=n,t.dispatchEvent(new Event("input",{bubbles:!0}))),setTimeout(function(){n!==t.value&&t.dispatchEvent(new Event("change",{bubbles:!0}))}),g.classList.remove("clr-open"),D&&a(),t.dispatchEvent(new Event("close",{bubbles:!0})),O.focusInput&&t.focus({preventScroll:!0}),B=null)}function u(e){var e=function(e){var t;i.fillStyle="#000",i.fillStyle=e,(e=/^((rgba)|rgb)[\D]+([\d.]+)[\D]+([\d.]+)[\D]+([\d.]+)[\D]*?([\d.]+|$)/i.exec(i.fillStyle))?(t={r:+e[3],g:+e[4],b:+e[5],a:+e[6]}).a=+t.a.toFixed(2):(e=i.fillStyle.replace("#","").match(/.{2}/g).map(function(e){return parseInt(e,16)}),t={r:e[0],g:e[1],b:e[2],a:1});return t}(e),t=function(e){var t=e.r/255,a=e.g/255,l=e.b/255,r=v.max(t,a,l),o=v.min(t,a,l),o=r-o,n=r,i=0,c=0;o&&(r===t&&(i=(a-l)/o),r===a&&(i=2+(l-t)/o),r===l&&(i=4+(t-a)/o),r)&&(c=o/r);return{h:(i=v.floor(60*i))<0?i+360:i,s:v.round(100*c),v:v.round(100*n),a:e.a}}(e);P(t.s,t.v),p(e,t),C.value=t.h,g.style.color="hsl("+t.h+", 100%, 50%)",z.style.left=t.h/360*100+"%",k.style.left=w.width*t.s/100+"px",k.style.top=w.height-w.height*t.v/100+"px",S.value=100*t.a,T.style.left=100*t.a+"%"}function Y(e){e=e.substring(0,3).toLowerCase();return"rgb"===e||"hsl"===e?e:"hex"}function d(e){e=void 0!==e?e:x.value,B&&(B.value=e,B.dispatchEvent(new Event("input",{bubbles:!0}))),b.dispatchEvent(new CustomEvent("coloris:pick",{detail:{color:e}}))}function q(e,t){var a,l,r,o,n,e={h:+C.value,s:e/w.width*100,v:100-t/w.height*100,a:S.value/100},i=(i=(t=e).s/100,a=t.v/100,i*=a,l=t.h/60,r=i*(1-v.abs(l%2-1)),i+=a-=i,r+=a,l=v.floor(l)%6,o=[i,r,a,a,r,i][l],n=[r,i,i,r,a,a][l],a=[a,a,r,i,i,r][l],{r:v.round(255*o),g:v.round(255*n),b:v.round(255*a),a:t.a});P(e.s,e.v),p(i,e),d()}function P(e,t){var a=O.a11y.marker;e=+e.toFixed(1),t=+t.toFixed(1),a=(a=a.replace("{s}",e)).replace("{v}",t),k.setAttribute("aria-label",a)}function t(e){var t={pageX:((t=e).changedTouches?t.changedTouches[0]:t).pageX,pageY:(t.changedTouches?t.changedTouches[0]:t).pageY},a=t.pageX-w.x,t=t.pageY-w.y;y&&(t+=y.scrollTop),U(a,t),e.preventDefault(),e.stopPropagation()}function U(e,t){e=e<0?0:e>w.width?w.width:e,t=t<0?0:t>w.height?w.height:t,k.style.left=e+"px",k.style.top=t+"px",q(e,t),k.focus()}function p(e,t){void 0===t&&(t={});var a,l,r=O.format;for(a in e=void 0===e?{}:e)H[a]=e[a];for(l in t)H[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||O.forceAlpha)&&(e=255*e.a|0,r=e.toString(16),e<16)&&(r="0"+r);return"#"+t+a+l+r}(H),i=n.substring(0,7);switch(k.style.color=i,T.parentNode.style.color=i,T.style.color=n,L.style.color=n,m.style.display="none",m.offsetHeight,m.style.display="",T.nextElementSibling.style.display="none",T.nextElementSibling.offsetHeight,T.nextElementSibling.style.display="","mixed"===r?r=1===H.a?"hex":"rgb":"auto"===r&&(r=M),r){case"hex":x.value=n;break;case"rgb":x.value=(o=H,!O.alpha||1===o.a&&!O.forceAlpha?"rgb("+o.r+", "+o.g+", "+o.b+")":"rgba("+o.r+", "+o.g+", "+o.b+", "+o.a+")");break;case"hsl":x.value=(o=function(e){var t,a=e.v/100,l=a*(1-e.s/100/2);0<l&&l<1&&(t=v.round((a-l)/v.min(l,1-l)*100));return{h:e.h,s:t||0,l:v.round(100*l),a:e.a}}(H),!O.alpha||1===o.a&&!O.forceAlpha?"hsl("+o.h+", "+o.s+"%, "+o.l+"%)":"hsla("+o.h+", "+o.s+"%, "+o.l+"%, "+o.a+")")}b.querySelector('.clr-format [value="'+r+'"]').checked=!0}function e(){var e=+C.value,t=+k.style.left.replace("px",""),a=+k.style.top.replace("px","");g.style.color="hsl("+e+", 100%, 50%)",z.style.left=e/360*100+"%",q(t,a)}function X(){var e=S.value/100;T.style.left=100*e+"%",p({a:e}),d()}function G(){y=null,(g=b.createElement("div")).setAttribute("id","clr-picker"),g.className="clr-picker",g.innerHTML='<input id="clr-color-value" class="clr-color" type="text" value="" spellcheck="false" 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 type="button" id="clr-clear" class="clr-clear" aria-label="'+O.a11y.clear+'">'+O.clearLabel+'</button><div id="clr-color-preview" class="clr-preview"><button type="button" id="clr-close" class="clr-close" aria-label="'+O.a11y.close+'">'+O.closeLabel+'</button></div><span id="clr-open-label" hidden>'+O.a11y.open+'</span><span id="clr-swatch-label" hidden>'+O.a11y.swatch+"</span>",b.body.appendChild(g),m=f("clr-color-area"),k=f("clr-color-marker"),E=f("clr-clear"),A=f("clr-close"),L=f("clr-color-preview"),x=f("clr-color-value"),C=f("clr-hue-slider"),z=f("clr-hue-marker"),S=f("clr-alpha-slider"),T=f("clr-alpha-marker"),W(O.el),s(O.el),r(g,"mousedown",function(e){g.classList.remove("clr-keyboard-nav"),e.stopPropagation()}),r(m,"mousedown",function(e){r(b,"mousemove",t)}),r(m,"touchstart",function(e){b.addEventListener("touchmove",t,{passive:!1})}),r(k,"mousedown",function(e){r(b,"mousemove",t)}),r(k,"touchstart",function(e){b.addEventListener("touchmove",t,{passive:!1})}),r(x,"change",function(e){(B||O.inline)&&(u(x.value),d())}),r(E,"click",function(e){d(""),l()}),r(A,"click",function(e){d(),l()}),r(b,"click",".clr-format input",function(e){M=e.target.value,p(),d()}),r(g,"click",".clr-swatches button",function(e){u(e.target.textContent),d(),O.swatchesOnly&&l()}),r(b,"mouseup",function(e){b.removeEventListener("mousemove",t)}),r(b,"touchend",function(e){b.removeEventListener("touchmove",t)}),r(b,"mousedown",function(e){g.classList.remove("clr-keyboard-nav"),l()}),r(b,"keydown",function(e){"Escape"===e.key?l(!0):["Tab","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key)&&g.classList.add("clr-keyboard-nav")}),r(b,"click",".clr-field button",function(e){D&&a(),e.target.nextElementSibling.dispatchEvent(new Event("click",{bubbles:!0}))}),r(k,"keydown",function(e){var t={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]};Object.keys(t).includes(e.key)&&(!function(e,t){U(+k.style.left.replace("px","")+e,+k.style.top.replace("px","")+t)}.apply(void 0,t[e.key]),e.preventDefault())}),r(m,"click",t),r(C,"input",e),r(S,"input",X)}function f(e){return b.getElementById(e)}function r(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 $(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 h,b,v,y,g,m,w,k,L,x,E,A,C,z,S,T,B,M,n,i,H,O,N,I,_,D,J}(),_coloris=Coloris.coloris,_init=Coloris.init,_set=Coloris.set,_wrap=Coloris.wrap,_close=Coloris.close;export default Coloris;export{_coloris as coloris,_close as close,_init as init,_set as set,_wrap as wrap}; |
@@ -53,3 +53,3 @@ // https://github.com/umdjs/umd/blob/master/templates/returnExports.js | ||
var container, picker, colorArea, colorAreaDims, colorMarker, colorPreview, colorValue, clearButton, | ||
hueSlider, hueMarker, alphaSlider, alphaMarker, currentEl, currentFormat, oldColor; | ||
closeButton, hueSlider, hueMarker, alphaSlider, alphaMarker, currentEl, currentFormat, oldColor; | ||
@@ -76,5 +76,8 @@ // Default settings | ||
clearLabel: 'Clear', | ||
closeButton: false, | ||
closeLabel: 'Close', | ||
a11y: { | ||
open: 'Open color picker', | ||
close: 'Close color picker', | ||
clear: 'Clear the selected color', | ||
marker: 'Saturation: {s}. Brightness: {v}.', | ||
@@ -86,6 +89,6 @@ hueSlider: 'Hue slider', | ||
swatch: 'Color swatch', | ||
instruction: 'Saturation and brightness selector. Use up, down, left and right arrow keys to select.' } }; | ||
instruction: 'Saturation and brightness selector. Use up, down, left and right arrow keys to select.' | ||
} | ||
}; | ||
// Virtual instances cache | ||
@@ -104,5 +107,5 @@ var instances = {}; | ||
return; | ||
} | ||
}var _loop = function _loop() | ||
for (var key in options) { | ||
{ | ||
switch (key) { | ||
@@ -163,11 +166,11 @@ case 'el': | ||
case 'swatches': | ||
if (Array.isArray(options.swatches)) {(function () { | ||
var swatches = []; | ||
if (Array.isArray(options.swatches)) { | ||
var swatches = []; | ||
options.swatches.forEach(function (swatch, i) { | ||
swatches.push("<button type=\"button\" id=\"clr-swatch-" + i + "\" aria-labelledby=\"clr-swatch-label clr-swatch-" + i + "\" style=\"color: " + swatch + ";\">" + swatch + "</button>"); | ||
}); | ||
options.swatches.forEach(function (swatch, i) { | ||
swatches.push("<button type=\"button\" id=\"clr-swatch-" + i + "\" aria-labelledby=\"clr-swatch-label clr-swatch-" + i + "\" style=\"color: " + swatch + ";\">" + swatch + "</button>"); | ||
}); | ||
getEl('clr-swatches').innerHTML = swatches.length ? "<div>" + swatches.join('') + "</div>" : ''; | ||
settings.swatches = options.swatches.slice();})(); | ||
getEl('clr-swatches').innerHTML = swatches.length ? "<div>" + swatches.join('') + "</div>" : ''; | ||
settings.swatches = options.swatches.slice(); | ||
} | ||
@@ -213,2 +216,16 @@ break; | ||
break; | ||
case 'closeButton': | ||
settings.closeButton = !!options.closeButton; | ||
if (settings.closeButton) { | ||
picker.insertBefore(closeButton, colorPreview); | ||
} else { | ||
colorPreview.appendChild(closeButton); | ||
} | ||
break; | ||
case 'closeLabel': | ||
settings.closeLabel = options.closeLabel; | ||
closeButton.innerHTML = settings.closeLabel; | ||
break; | ||
case 'a11y': | ||
@@ -233,3 +250,4 @@ var labels = options.a11y; | ||
swatchLabel.innerHTML = settings.a11y.swatch; | ||
colorPreview.setAttribute('aria-label', settings.a11y.close); | ||
closeButton.setAttribute('aria-label', settings.a11y.close); | ||
clearButton.setAttribute('aria-label', settings.a11y.clear); | ||
hueSlider.setAttribute('aria-label', settings.a11y.hueSlider); | ||
@@ -243,3 +261,3 @@ alphaSlider.setAttribute('aria-label', settings.a11y.alphaSlider); | ||
} | ||
};for (var key in options) {_loop();} | ||
} | ||
@@ -282,5 +300,5 @@ | ||
// These options can only be set globally, not per instance | ||
var unsupportedOptions = ['el', 'wrap', 'inline', 'defaultColor', 'a11y'];var _loop = function _loop( | ||
var unsupportedOptions = ['el', 'wrap', 'inline', 'defaultColor', 'a11y'];var _loop2 = function _loop2() | ||
selector) { | ||
{ | ||
var options = instances[selector]; | ||
@@ -302,6 +320,6 @@ | ||
// Set the instance's options | ||
configure(options); | ||
return "break"; | ||
}};for (var selector in instances) {var _ret = _loop(selector);if (_ret === "break") break; | ||
} | ||
configure(options);return "break"; | ||
} | ||
};for (var selector in instances) {var _ret = _loop2();if (_ret === "break") break;} | ||
} | ||
@@ -438,4 +456,4 @@ } | ||
x: picker.offsetLeft + colorArea.offsetLeft + offset.x, | ||
y: picker.offsetTop + colorArea.offsetTop + offset.y }; | ||
y: picker.offsetTop + colorArea.offsetTop + offset.y | ||
}; | ||
} | ||
@@ -574,4 +592,4 @@ | ||
v: 100 - y / colorAreaDims.height * 100, | ||
a: alphaSlider.value / 100 }; | ||
a: alphaSlider.value / 100 | ||
}; | ||
var rgba = HSVAtoRGBA(hsva); | ||
@@ -608,4 +626,4 @@ | ||
pageX: event.changedTouches ? event.changedTouches[0].pageX : event.pageX, | ||
pageY: event.changedTouches ? event.changedTouches[0].pageY : event.pageY }; | ||
pageY: event.changedTouches ? event.changedTouches[0].pageY : event.pageY | ||
}; | ||
} | ||
@@ -626,10 +644,4 @@ | ||
x = x < 0 ? 0 : x > colorAreaDims.width ? colorAreaDims.width : x; | ||
y = y < 0 ? 0 : y > colorAreaDims.height ? colorAreaDims.height : y; | ||
setMarkerPosition(x, y); | ||
colorMarker.style.left = x + "px"; | ||
colorMarker.style.top = y + "px"; | ||
setColorAtPosition(x, y); | ||
// Prevent scrolling while dragging the marker | ||
@@ -643,3 +655,3 @@ event.preventDefault(); | ||
* @param {number} offsetX The horizontal amount to move. | ||
* * @param {number} offsetY The vertical amount to move. | ||
* @param {number} offsetY The vertical amount to move. | ||
*/ | ||
@@ -650,6 +662,24 @@ function moveMarkerOnKeydown(offsetX, offsetY) { | ||
setMarkerPosition(x, y); | ||
} | ||
/** | ||
* Set the color marker's position. | ||
* @param {number} x Left position. | ||
* @param {number} y Top position. | ||
*/ | ||
function setMarkerPosition(x, y) { | ||
// Make sure the marker doesn't go out of bounds | ||
x = x < 0 ? 0 : x > colorAreaDims.width ? colorAreaDims.width : x; | ||
y = y < 0 ? 0 : y > colorAreaDims.height ? colorAreaDims.height : y; | ||
// Set the position | ||
colorMarker.style.left = x + "px"; | ||
colorMarker.style.top = y + "px"; | ||
// Update the color | ||
setColorAtPosition(x, y); | ||
// Make sure the marker is focused | ||
colorMarker.focus(); | ||
} | ||
@@ -761,4 +791,4 @@ | ||
b: Math.round(blue * 255), | ||
a: hsva.a }; | ||
a: hsva.a | ||
}; | ||
} | ||
@@ -784,4 +814,4 @@ | ||
l: Math.round(lightness * 100), | ||
a: hsva.a }; | ||
a: hsva.a | ||
}; | ||
} | ||
@@ -818,4 +848,4 @@ | ||
v: Math.round(value * 100), | ||
a: rgba.a }; | ||
a: rgba.a | ||
}; | ||
} | ||
@@ -844,5 +874,5 @@ | ||
b: match[5] * 1, | ||
a: match[6] * 1 }; | ||
a: match[6] * 1 | ||
}; | ||
// Workaround to mitigate a Chromium bug where the alpha value is rounded incorrectly | ||
@@ -857,4 +887,4 @@ rgba.a = +rgba.a.toFixed(2); | ||
b: match[2], | ||
a: 1 }; | ||
a: 1 | ||
}; | ||
} | ||
@@ -961,5 +991,7 @@ | ||
'</div>' + | ||
'<div id="clr-swatches" class="clr-swatches"></div>' + ("<button type=\"button\" id=\"clr-clear\" class=\"clr-clear\">" + | ||
settings.clearLabel + "</button>") + ("<button type=\"button\" id=\"clr-color-preview\" class=\"clr-preview\" aria-label=\"" + | ||
settings.a11y.close + "\"></button>") + ("<span id=\"clr-open-label\" hidden>" + | ||
'<div id="clr-swatches" class="clr-swatches"></div>' + ("<button type=\"button\" id=\"clr-clear\" class=\"clr-clear\" aria-label=\"" + | ||
settings.a11y.clear + "\">" + settings.clearLabel + "</button>") + | ||
'<div id="clr-color-preview" class="clr-preview">' + ("<button type=\"button\" id=\"clr-close\" class=\"clr-close\" aria-label=\"" + | ||
settings.a11y.close + "\">" + settings.closeLabel + "</button>") + | ||
'</div>' + ("<span id=\"clr-open-label\" hidden>" + | ||
settings.a11y.open + "</span>") + ("<span id=\"clr-swatch-label\" hidden>" + | ||
@@ -975,2 +1007,3 @@ settings.a11y.swatch + "</span>"); | ||
clearButton = getEl('clr-clear'); | ||
closeButton = getEl('clr-close'); | ||
colorPreview = getEl('clr-color-preview'); | ||
@@ -1009,3 +1042,3 @@ colorValue = getEl('clr-color-value'); | ||
addListener(colorValue, 'change', function (event) { | ||
if (currentEl) { | ||
if (currentEl || settings.inline) { | ||
setColorFromStr(colorValue.value); | ||
@@ -1021,3 +1054,3 @@ pickColor(); | ||
addListener(colorPreview, 'click', function (event) { | ||
addListener(closeButton, 'click', function (event) { | ||
pickColor(); | ||
@@ -1056,5 +1089,9 @@ closePicker(); | ||
addListener(document, 'keydown', function (event) { | ||
var navKeys = ['Tab', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight']; | ||
if (event.key === 'Escape') { | ||
closePicker(true); | ||
} else if (event.key === 'Tab') { | ||
// Display focus rings when using the keyboard | ||
} else if (navKeys.includes(event.key)) { | ||
picker.classList.add('clr-keyboard-nav'); | ||
@@ -1079,6 +1116,6 @@ } | ||
ArrowLeft: [-1, 0], | ||
ArrowRight: [1, 0] }; | ||
ArrowRight: [1, 0] | ||
}; | ||
if (Object.keys(movements).indexOf(event.key) !== -1) { | ||
if (Object.keys(movements).includes(event.key)) { | ||
moveMarkerOnKeydown.apply(void 0, movements[event.key]); | ||
@@ -1160,5 +1197,5 @@ event.preventDefault(); | ||
removeInstance: removeVirtualInstance, | ||
updatePosition: updatePickerPosition }; | ||
updatePosition: updatePickerPosition | ||
}; | ||
function Coloris(options) { | ||
@@ -1174,9 +1211,9 @@ DOMReady(function () { | ||
}); | ||
}var _loop2 = function _loop2( | ||
}var _loop3 = function _loop3(key) | ||
key) { | ||
{ | ||
Coloris[key] = function () {for (var _len = arguments.length, args = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {args[_key2] = arguments[_key2];} | ||
DOMReady(methods[key], args); | ||
};};for (var key in methods) {_loop2(key); | ||
} | ||
}; | ||
};for (var key in methods) {_loop3(key);} | ||
@@ -1183,0 +1220,0 @@ return Coloris; |
@@ -7,2 +7,2 @@ !function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():(e.Coloris=t(),"object"==typeof window&&e.Coloris.init())}("undefined"!=typeof self?self:void 0,function(){ | ||
*/ | ||
return h=window,b=document,v=Math,B=b.createElement("canvas").getContext("2d"),O={el:"[data-coloris]",parent:"body",theme:"default",themeMode:"light",wrap:!0,margin:2,format:"hex",formatToggle:!(H={r:0,g:0,b:0,h:0,s:0,v:0,a:1}),swatches:[],swatchesOnly:!1,alpha:!0,forceAlpha:!1,focusInput:!0,selectInput:!1,inline:!1,defaultColor:"#000000",clearButton:!1,clearLabel:"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."}},N={},j="",D=!(I={}),void 0!==NodeList&&NodeList.prototype&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),(z=function(){var r={init:U,set:n,wrap:s,close:l,setInstance:F,removeInstance:W,updatePosition:c};function e(e){G(function(){e&&("string"==typeof e?i:n)(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];G(r[l],t)}}(t);return e}()).coloris=z;function n(e){if("object"==typeof e)for(var t in e)switch(t){case"el":i(e.el),!1!==e.wrap&&s(e.el);break;case"parent":(y=b.querySelector(e.parent))&&(y.appendChild(m),O.parent=e.parent,y===b.body&&(y=null));break;case"themeMode":O.themeMode=e.themeMode,"auto"===e.themeMode&&h.matchMedia&&h.matchMedia("(prefers-color-scheme: dark)").matches&&(O.themeMode="dark");case"theme":e.theme&&(O.theme=e.theme),m.className="clr-picker clr-"+O.theme+" clr-"+O.themeMode,O.inline&&c();break;case"margin":e.margin*=1,O.margin=(isNaN(e.margin)?O:e).margin;break;case"wrap":e.el&&e.wrap&&s(e.el);break;case"formatToggle":O.formatToggle=!!e.formatToggle,f("clr-format").style.display=O.formatToggle?"block":"none",O.formatToggle&&(O.format="auto");break;case"swatches":Array.isArray(e.swatches)&&!function(){var a=[];e.swatches.forEach(function(e,t){a.push('<button type="button" id="clr-swatch-'+t+'" aria-labelledby="clr-swatch-label clr-swatch-'+t+'" style="color: '+e+';">'+e+"</button>")}),f("clr-swatches").innerHTML=a.length?"<div>"+a.join("")+"</div>":"",O.swatches=e.swatches.slice()}();break;case"swatchesOnly":O.swatchesOnly=!!e.swatchesOnly,m.setAttribute("data-minimal",O.swatchesOnly);break;case"alpha":O.alpha=!!e.alpha,m.setAttribute("data-alpha",O.alpha);break;case"inline":O.inline=!!e.inline,m.setAttribute("data-inline",O.inline),O.inline&&(a=e.defaultColor||O.defaultColor,M=Y(a),c(),u(a));break;case"clearButton":"object"==typeof e.clearButton&&(e.clearButton.label&&(O.clearLabel=e.clearButton.label,E.innerHTML=O.clearLabel),e.clearButton=e.clearButton.show),O.clearButton=!!e.clearButton,E.style.display=O.clearButton?"block":"none";break;case"clearLabel":O.clearLabel=e.clearLabel,E.innerHTML=O.clearLabel;break;case"a11y":var a,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&&(a=f("clr-open-label"),l=f("clr-swatch-label"),a.innerHTML=O.a11y.open,l.innerHTML=O.a11y.swatch,x.setAttribute("aria-label",O.a11y.close),S.setAttribute("aria-label",O.a11y.hueSlider),A.setAttribute("aria-label",O.a11y.alphaSlider),L.setAttribute("aria-label",O.a11y.input),g.setAttribute("aria-label",O.a11y.instruction));default:O[t]=e[t]}}function F(e,t){"string"==typeof e&&"object"==typeof t&&(N[e]=t,D=!0)}function W(e){delete N[e],0===Object.keys(N).length&&(D=!1,e===j&&a())}function R(l){if(D){var e,r=["el","wrap","inline","defaultColor","a11y"];for(e in N)if("break"===function(e){var t=N[e];if(l.matches(e)){for(var a in j=e,I={},r.forEach(function(e){return delete t[e]}),t)I[a]=Array.isArray(O[a])?O[a].slice():O[a];return n(t),"break"}}(e))break}}function a(){0<Object.keys(I).length&&(n(I),j="",I={})}function i(e){r(b,"click",e,function(e){O.inline||(R(e.target),C=e.target,o=C.value,M=Y(o),m.classList.add("clr-open"),c(),u(o),(O.focusInput||O.selectInput)&&L.focus({preventScroll:!0}),O.selectInput&&L.select(),C.dispatchEvent(new Event("open",{bubbles:!0})))}),r(b,"input",e,function(e){var t=e.target.parentNode;t.classList.contains("clr-field")&&(t.style.color=e.target.value)})}function c(){var e,t,a,l,r=y,n=h.scrollY,o=m.offsetWidth,i=m.offsetHeight,c={left:!1,top:!1},s={x:0,y:0};r&&(t=h.getComputedStyle(r),e=parseFloat(t.marginTop),t=parseFloat(t.borderTopWidth),(s=r.getBoundingClientRect()).y+=t+n),O.inline||(a=(t=C.getBoundingClientRect()).x,l=n+t.y+t.height+O.margin,r?(a-=s.x,l-=s.y,a+o>r.clientWidth&&(a+=t.width-o,c.left=!0),l+i>r.clientHeight-e&&i+O.margin<=t.top-(s.y-n)&&(l-=t.height+i+2*O.margin,c.top=!0),l+=r.scrollTop):(a+o>b.documentElement.clientWidth&&(a+=t.width-o,c.left=!0),l+i-n>b.documentElement.clientHeight&&i+O.margin<=t.top&&(l=n+t.y-i-O.margin,c.top=!0)),m.classList.toggle("clr-left",c.left),m.classList.toggle("clr-top",c.top),m.style.left=a+"px",m.style.top=l+"px"),w={width:g.offsetWidth,height:g.offsetHeight,x:m.offsetLeft+g.offsetLeft+s.x,y:m.offsetTop+g.offsetTop+s.y}}function s(e){b.querySelectorAll(e).forEach(function(e){var t,a=e.parentNode;a.classList.contains("clr-field")||((t=b.createElement("div")).innerHTML='<button type="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){var t;C&&!O.inline&&(t=C,e&&(C=null,o!==t.value&&(t.value=o,t.dispatchEvent(new Event("input",{bubbles:!0})))),setTimeout(function(){o!==t.value&&t.dispatchEvent(new Event("change",{bubbles:!0}))}),m.classList.remove("clr-open"),D&&a(),t.dispatchEvent(new Event("close",{bubbles:!0})),O.focusInput&&t.focus({preventScroll:!0}),C=null)}function u(e){var e=function(e){var t;B.fillStyle="#000",B.fillStyle=e,(e=/^((rgba)|rgb)[\D]+([\d.]+)[\D]+([\d.]+)[\D]+([\d.]+)[\D]*?([\d.]+|$)/i.exec(B.fillStyle))?(t={r:+e[3],g:+e[4],b:+e[5],a:+e[6]}).a=+t.a.toFixed(2):(e=B.fillStyle.replace("#","").match(/.{2}/g).map(function(e){return parseInt(e,16)}),t={r:e[0],g:e[1],b:e[2],a:1});return t}(e),t=function(e){var t=e.r/255,a=e.g/255,l=e.b/255,r=v.max(t,a,l),n=v.min(t,a,l),n=r-n,o=r,i=0,c=0;n&&(r===t&&(i=(a-l)/n),r===a&&(i=2+(l-t)/n),r===l&&(i=4+(t-a)/n),r&&(c=n/r));return{h:(i=v.floor(60*i))<0?i+360:i,s:v.round(100*c),v:v.round(100*o),a:e.a}}(e);P(t.s,t.v),p(e,t),S.value=t.h,m.style.color="hsl("+t.h+", 100%, 50%)",$.style.left=t.h/360*100+"%",k.style.left=w.width*t.s/100+"px",k.style.top=w.height-w.height*t.v/100+"px",A.value=100*t.a,T.style.left=100*t.a+"%"}function Y(e){e=e.substring(0,3).toLowerCase();return"rgb"===e||"hsl"===e?e:"hex"}function d(e){e=void 0!==e?e:L.value,C&&(C.value=e,C.dispatchEvent(new Event("input",{bubbles:!0}))),b.dispatchEvent(new CustomEvent("coloris:pick",{detail:{color:e}}))}function q(e,t){var a,l,r,n,o,e={h:+S.value,s:e/w.width*100,v:100-t/w.height*100,a:A.value/100},i=(i=(t=e).s/100,a=t.v/100,i*=a,l=t.h/60,r=i*(1-v.abs(l%2-1)),i+=a-=i,r+=a,l=v.floor(l)%6,n=[i,r,a,a,r,i][l],o=[r,i,i,r,a,a][l],a=[a,a,r,i,i,r][l],{r:v.round(255*n),g:v.round(255*o),b:v.round(255*a),a:t.a});P(e.s,e.v),p(i,e),d()}function P(e,t){var a=O.a11y.marker;e=+e.toFixed(1),t=+t.toFixed(1),a=(a=a.replace("{s}",e)).replace("{v}",t),k.setAttribute("aria-label",a)}function t(e){var t={pageX:((t=e).changedTouches?t.changedTouches[0]:t).pageX,pageY:(t.changedTouches?t.changedTouches[0]:t).pageY},a=t.pageX-w.x,t=t.pageY-w.y;y&&(t+=y.scrollTop),a=a<0?0:a>w.width?w.width:a,t=t<0?0:t>w.height?w.height:t,k.style.left=a+"px",k.style.top=t+"px",q(a,t),e.preventDefault(),e.stopPropagation()}function p(e,t){void 0===t&&(t={});var a,l,r=O.format;for(a in e=void 0===e?{}:e)H[a]=e[a];for(l in t)H[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||O.forceAlpha)&&(e=255*e.a|0,r=e.toString(16),e<16&&(r="0"+r));return"#"+t+a+l+r}(H),i=o.substring(0,7);switch(k.style.color=i,T.parentNode.style.color=i,T.style.color=o,x.style.color=o,g.style.display="none",g.offsetHeight,g.style.display="",T.nextElementSibling.style.display="none",T.nextElementSibling.offsetHeight,T.nextElementSibling.style.display="","mixed"===r?r=1===H.a?"hex":"rgb":"auto"===r&&(r=M),r){case"hex":L.value=o;break;case"rgb":L.value=(n=H,!O.alpha||1===n.a&&!O.forceAlpha?"rgb("+n.r+", "+n.g+", "+n.b+")":"rgba("+n.r+", "+n.g+", "+n.b+", "+n.a+")");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=v.round((a-l)/v.min(l,1-l)*100));return{h:e.h,s:t||0,l:v.round(100*l),a:e.a}}(H),!O.alpha||1===n.a&&!O.forceAlpha?"hsl("+n.h+", "+n.s+"%, "+n.l+"%)":"hsla("+n.h+", "+n.s+"%, "+n.l+"%, "+n.a+")")}b.querySelector('.clr-format [value="'+r+'"]').checked=!0}function e(){var e=+S.value,t=+k.style.left.replace("px",""),a=+k.style.top.replace("px","");m.style.color="hsl("+e+", 100%, 50%)",$.style.left=e/360*100+"%",q(t,a)}function X(){var e=A.value/100;T.style.left=100*e+"%",p({a:e}),d()}function U(){y=null,(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="" spellcheck="false" 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 type="button" id="clr-clear" class="clr-clear">'+O.clearLabel+'</button><button type="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),g=f("clr-color-area"),k=f("clr-color-marker"),E=f("clr-clear"),x=f("clr-color-preview"),L=f("clr-color-value"),S=f("clr-hue-slider"),$=f("clr-hue-marker"),A=f("clr-alpha-slider"),T=f("clr-alpha-marker"),i(O.el),s(O.el),r(m,"mousedown",function(e){m.classList.remove("clr-keyboard-nav"),e.stopPropagation()}),r(g,"mousedown",function(e){r(b,"mousemove",t)}),r(g,"touchstart",function(e){b.addEventListener("touchmove",t,{passive:!1})}),r(k,"mousedown",function(e){r(b,"mousemove",t)}),r(k,"touchstart",function(e){b.addEventListener("touchmove",t,{passive:!1})}),r(L,"change",function(e){C&&(u(L.value),d())}),r(E,"click",function(e){d(""),l()}),r(x,"click",function(e){d(),l()}),r(b,"click",".clr-format input",function(e){M=e.target.value,p(),d()}),r(m,"click",".clr-swatches button",function(e){u(e.target.textContent),d(),O.swatchesOnly&&l()}),r(b,"mouseup",function(e){b.removeEventListener("mousemove",t)}),r(b,"touchend",function(e){b.removeEventListener("touchmove",t)}),r(b,"mousedown",function(e){m.classList.remove("clr-keyboard-nav"),l()}),r(b,"keydown",function(e){"Escape"===e.key?l(!0):"Tab"===e.key&&m.classList.add("clr-keyboard-nav")}),r(b,"click",".clr-field button",function(e){D&&a(),e.target.nextElementSibling.dispatchEvent(new Event("click",{bubbles:!0}))}),r(k,"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=+k.style.left.replace("px","")+e,t=+k.style.top.replace("px","")+t,k.style.left=e+"px",k.style.top=t+"px",q(e,t)}.apply(void 0,t[e.key]),e.preventDefault())}),r(g,"click",t),r(S,"input",e),r(A,"input",X)}function f(e){return b.getElementById(e)}function r(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 G(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 h,b,v,y,m,g,w,k,x,L,E,S,$,A,T,C,M,o,B,H,O,N,j,I,D,z}); | ||
return h=window,b=document,v=Math,i=b.createElement("canvas").getContext("2d"),O={el:"[data-coloris]",parent:"body",theme:"default",themeMode:"light",wrap:!0,margin:2,format:"hex",formatToggle:!(H={r:0,g:0,b:0,h:0,s:0,v:0,a:1}),swatches:[],swatchesOnly:!1,alpha:!0,forceAlpha:!1,focusInput:!0,selectInput:!1,inline:!1,defaultColor:"#000000",clearButton:!1,clearLabel:"Clear",closeButton:!1,closeLabel:"Close",a11y:{open:"Open color picker",close:"Close color picker",clear:"Clear the selected color",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."}},N={},j="",D=!(I={}),void 0!==NodeList&&NodeList.prototype&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach),(K=function(){var r={init:$,set:n,wrap:s,close:l,setInstance:F,removeInstance:R,updatePosition:c};function e(e){z(function(){e&&("string"==typeof e?Y:n)(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];z(r[l],t)}}(t);return e}()).coloris=K;function n(o){if("object"==typeof o)for(var i in o)!function(){switch(i){case"el":Y(o.el),!1!==o.wrap&&s(o.el);break;case"parent":(y=b.querySelector(o.parent))&&(y.appendChild(m),O.parent=o.parent,y===b.body)&&(y=null);break;case"themeMode":O.themeMode=o.themeMode,"auto"===o.themeMode&&h.matchMedia&&h.matchMedia("(prefers-color-scheme: dark)").matches&&(O.themeMode="dark");case"theme":o.theme&&(O.theme=o.theme),m.className="clr-picker clr-"+O.theme+" clr-"+O.themeMode,O.inline&&c();break;case"margin":o.margin*=1,O.margin=(isNaN(o.margin)?O:o).margin;break;case"wrap":o.el&&o.wrap&&s(o.el);break;case"formatToggle":O.formatToggle=!!o.formatToggle,f("clr-format").style.display=O.formatToggle?"block":"none",O.formatToggle&&(O.format="auto");break;case"swatches":var a;Array.isArray(o.swatches)&&(a=[],o.swatches.forEach(function(e,t){a.push('<button type="button" id="clr-swatch-'+t+'" aria-labelledby="clr-swatch-label clr-swatch-'+t+'" style="color: '+e+';">'+e+"</button>")}),f("clr-swatches").innerHTML=a.length?"<div>"+a.join("")+"</div>":"",O.swatches=o.swatches.slice());break;case"swatchesOnly":O.swatchesOnly=!!o.swatchesOnly,m.setAttribute("data-minimal",O.swatchesOnly);break;case"alpha":O.alpha=!!o.alpha,m.setAttribute("data-alpha",O.alpha);break;case"inline":O.inline=!!o.inline,m.setAttribute("data-inline",O.inline),O.inline&&(e=o.defaultColor||O.defaultColor,M=q(e),c(),u(e));break;case"clearButton":"object"==typeof o.clearButton&&(o.clearButton.label&&(O.clearLabel=o.clearButton.label,E.innerHTML=O.clearLabel),o.clearButton=o.clearButton.show),O.clearButton=!!o.clearButton,E.style.display=O.clearButton?"block":"none";break;case"clearLabel":O.clearLabel=o.clearLabel,E.innerHTML=O.clearLabel;break;case"closeButton":O.closeButton=!!o.closeButton,O.closeButton?m.insertBefore(A,L):L.appendChild(A);break;case"closeLabel":O.closeLabel=o.closeLabel,A.innerHTML=O.closeLabel;break;case"a11y":var e,t,l=o.a11y,r=!1;if("object"==typeof l)for(var n in l)l[n]&&O.a11y[n]&&(O.a11y[n]=l[n],r=!0);r&&(e=f("clr-open-label"),t=f("clr-swatch-label"),e.innerHTML=O.a11y.open,t.innerHTML=O.a11y.swatch,A.setAttribute("aria-label",O.a11y.close),E.setAttribute("aria-label",O.a11y.clear),S.setAttribute("aria-label",O.a11y.hueSlider),T.setAttribute("aria-label",O.a11y.alphaSlider),x.setAttribute("aria-label",O.a11y.input),g.setAttribute("aria-label",O.a11y.instruction));default:O[i]=o[i]}}()}function F(e,t){"string"==typeof e&&"object"==typeof t&&(N[e]=t,D=!0)}function R(e){delete N[e],0===Object.keys(N).length&&(D=!1,e===j)&&a()}function W(a){if(D){var l,r=["el","wrap","inline","defaultColor","a11y"];for(l in N)if("break"===function(){var t=N[l];if(a.matches(l)){for(var e in j=l,I={},r.forEach(function(e){return delete t[e]}),t)I[e]=Array.isArray(O[e])?O[e].slice():O[e];return n(t),"break"}}())break}}function a(){0<Object.keys(I).length&&(n(I),j="",I={})}function Y(e){r(b,"click",e,function(e){O.inline||(W(e.target),B=e.target,o=B.value,M=q(o),m.classList.add("clr-open"),c(),u(o),(O.focusInput||O.selectInput)&&x.focus({preventScroll:!0}),O.selectInput&&x.select(),B.dispatchEvent(new Event("open",{bubbles:!0})))}),r(b,"input",e,function(e){var t=e.target.parentNode;t.classList.contains("clr-field")&&(t.style.color=e.target.value)})}function c(){var e,t,a,l,r=y,n=h.scrollY,o=m.offsetWidth,i=m.offsetHeight,c={left:!1,top:!1},s={x:0,y:0};r&&(t=h.getComputedStyle(r),e=parseFloat(t.marginTop),t=parseFloat(t.borderTopWidth),(s=r.getBoundingClientRect()).y+=t+n),O.inline||(a=(t=B.getBoundingClientRect()).x,l=n+t.y+t.height+O.margin,r?(a-=s.x,l-=s.y,a+o>r.clientWidth&&(a+=t.width-o,c.left=!0),l+i>r.clientHeight-e&&i+O.margin<=t.top-(s.y-n)&&(l-=t.height+i+2*O.margin,c.top=!0),l+=r.scrollTop):(a+o>b.documentElement.clientWidth&&(a+=t.width-o,c.left=!0),l+i-n>b.documentElement.clientHeight&&i+O.margin<=t.top&&(l=n+t.y-i-O.margin,c.top=!0)),m.classList.toggle("clr-left",c.left),m.classList.toggle("clr-top",c.top),m.style.left=a+"px",m.style.top=l+"px"),w={width:g.offsetWidth,height:g.offsetHeight,x:m.offsetLeft+g.offsetLeft+s.x,y:m.offsetTop+g.offsetTop+s.y}}function s(e){b.querySelectorAll(e).forEach(function(e){var t,a=e.parentNode;a.classList.contains("clr-field")||((t=b.createElement("div")).innerHTML='<button type="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){var t;B&&!O.inline&&(t=B,e&&(B=null,o!==t.value)&&(t.value=o,t.dispatchEvent(new Event("input",{bubbles:!0}))),setTimeout(function(){o!==t.value&&t.dispatchEvent(new Event("change",{bubbles:!0}))}),m.classList.remove("clr-open"),D&&a(),t.dispatchEvent(new Event("close",{bubbles:!0})),O.focusInput&&t.focus({preventScroll:!0}),B=null)}function u(e){var e=function(e){var t;i.fillStyle="#000",i.fillStyle=e,(e=/^((rgba)|rgb)[\D]+([\d.]+)[\D]+([\d.]+)[\D]+([\d.]+)[\D]*?([\d.]+|$)/i.exec(i.fillStyle))?(t={r:+e[3],g:+e[4],b:+e[5],a:+e[6]}).a=+t.a.toFixed(2):(e=i.fillStyle.replace("#","").match(/.{2}/g).map(function(e){return parseInt(e,16)}),t={r:e[0],g:e[1],b:e[2],a:1});return t}(e),t=function(e){var t=e.r/255,a=e.g/255,l=e.b/255,r=v.max(t,a,l),n=v.min(t,a,l),n=r-n,o=r,i=0,c=0;n&&(r===t&&(i=(a-l)/n),r===a&&(i=2+(l-t)/n),r===l&&(i=4+(t-a)/n),r)&&(c=n/r);return{h:(i=v.floor(60*i))<0?i+360:i,s:v.round(100*c),v:v.round(100*o),a:e.a}}(e);U(t.s,t.v),p(e,t),S.value=t.h,m.style.color="hsl("+t.h+", 100%, 50%)",J.style.left=t.h/360*100+"%",k.style.left=w.width*t.s/100+"px",k.style.top=w.height-w.height*t.v/100+"px",T.value=100*t.a,C.style.left=100*t.a+"%"}function q(e){e=e.substring(0,3).toLowerCase();return"rgb"===e||"hsl"===e?e:"hex"}function d(e){e=void 0!==e?e:x.value,B&&(B.value=e,B.dispatchEvent(new Event("input",{bubbles:!0}))),b.dispatchEvent(new CustomEvent("coloris:pick",{detail:{color:e}}))}function P(e,t){var a,l,r,n,o,e={h:+S.value,s:e/w.width*100,v:100-t/w.height*100,a:T.value/100},i=(i=(t=e).s/100,a=t.v/100,i*=a,l=t.h/60,r=i*(1-v.abs(l%2-1)),i+=a-=i,r+=a,l=v.floor(l)%6,n=[i,r,a,a,r,i][l],o=[r,i,i,r,a,a][l],a=[a,a,r,i,i,r][l],{r:v.round(255*n),g:v.round(255*o),b:v.round(255*a),a:t.a});U(e.s,e.v),p(i,e),d()}function U(e,t){var a=O.a11y.marker;e=+e.toFixed(1),t=+t.toFixed(1),a=(a=a.replace("{s}",e)).replace("{v}",t),k.setAttribute("aria-label",a)}function t(e){var t={pageX:((t=e).changedTouches?t.changedTouches[0]:t).pageX,pageY:(t.changedTouches?t.changedTouches[0]:t).pageY},a=t.pageX-w.x,t=t.pageY-w.y;y&&(t+=y.scrollTop),X(a,t),e.preventDefault(),e.stopPropagation()}function X(e,t){e=e<0?0:e>w.width?w.width:e,t=t<0?0:t>w.height?w.height:t,k.style.left=e+"px",k.style.top=t+"px",P(e,t),k.focus()}function p(e,t){void 0===t&&(t={});var a,l,r=O.format;for(a in e=void 0===e?{}:e)H[a]=e[a];for(l in t)H[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||O.forceAlpha)&&(e=255*e.a|0,r=e.toString(16),e<16)&&(r="0"+r);return"#"+t+a+l+r}(H),i=o.substring(0,7);switch(k.style.color=i,C.parentNode.style.color=i,C.style.color=o,L.style.color=o,g.style.display="none",g.offsetHeight,g.style.display="",C.nextElementSibling.style.display="none",C.nextElementSibling.offsetHeight,C.nextElementSibling.style.display="","mixed"===r?r=1===H.a?"hex":"rgb":"auto"===r&&(r=M),r){case"hex":x.value=o;break;case"rgb":x.value=(n=H,!O.alpha||1===n.a&&!O.forceAlpha?"rgb("+n.r+", "+n.g+", "+n.b+")":"rgba("+n.r+", "+n.g+", "+n.b+", "+n.a+")");break;case"hsl":x.value=(n=function(e){var t,a=e.v/100,l=a*(1-e.s/100/2);0<l&&l<1&&(t=v.round((a-l)/v.min(l,1-l)*100));return{h:e.h,s:t||0,l:v.round(100*l),a:e.a}}(H),!O.alpha||1===n.a&&!O.forceAlpha?"hsl("+n.h+", "+n.s+"%, "+n.l+"%)":"hsla("+n.h+", "+n.s+"%, "+n.l+"%, "+n.a+")")}b.querySelector('.clr-format [value="'+r+'"]').checked=!0}function e(){var e=+S.value,t=+k.style.left.replace("px",""),a=+k.style.top.replace("px","");m.style.color="hsl("+e+", 100%, 50%)",J.style.left=e/360*100+"%",P(t,a)}function G(){var e=T.value/100;C.style.left=100*e+"%",p({a:e}),d()}function $(){y=null,(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="" spellcheck="false" 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 type="button" id="clr-clear" class="clr-clear" aria-label="'+O.a11y.clear+'">'+O.clearLabel+'</button><div id="clr-color-preview" class="clr-preview"><button type="button" id="clr-close" class="clr-close" aria-label="'+O.a11y.close+'">'+O.closeLabel+'</button></div><span id="clr-open-label" hidden>'+O.a11y.open+'</span><span id="clr-swatch-label" hidden>'+O.a11y.swatch+"</span>",b.body.appendChild(m),g=f("clr-color-area"),k=f("clr-color-marker"),E=f("clr-clear"),A=f("clr-close"),L=f("clr-color-preview"),x=f("clr-color-value"),S=f("clr-hue-slider"),J=f("clr-hue-marker"),T=f("clr-alpha-slider"),C=f("clr-alpha-marker"),Y(O.el),s(O.el),r(m,"mousedown",function(e){m.classList.remove("clr-keyboard-nav"),e.stopPropagation()}),r(g,"mousedown",function(e){r(b,"mousemove",t)}),r(g,"touchstart",function(e){b.addEventListener("touchmove",t,{passive:!1})}),r(k,"mousedown",function(e){r(b,"mousemove",t)}),r(k,"touchstart",function(e){b.addEventListener("touchmove",t,{passive:!1})}),r(x,"change",function(e){(B||O.inline)&&(u(x.value),d())}),r(E,"click",function(e){d(""),l()}),r(A,"click",function(e){d(),l()}),r(b,"click",".clr-format input",function(e){M=e.target.value,p(),d()}),r(m,"click",".clr-swatches button",function(e){u(e.target.textContent),d(),O.swatchesOnly&&l()}),r(b,"mouseup",function(e){b.removeEventListener("mousemove",t)}),r(b,"touchend",function(e){b.removeEventListener("touchmove",t)}),r(b,"mousedown",function(e){m.classList.remove("clr-keyboard-nav"),l()}),r(b,"keydown",function(e){"Escape"===e.key?l(!0):["Tab","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e.key)&&m.classList.add("clr-keyboard-nav")}),r(b,"click",".clr-field button",function(e){D&&a(),e.target.nextElementSibling.dispatchEvent(new Event("click",{bubbles:!0}))}),r(k,"keydown",function(e){var t={ArrowUp:[0,-1],ArrowDown:[0,1],ArrowLeft:[-1,0],ArrowRight:[1,0]};Object.keys(t).includes(e.key)&&(!function(e,t){X(+k.style.left.replace("px","")+e,+k.style.top.replace("px","")+t)}.apply(void 0,t[e.key]),e.preventDefault())}),r(g,"click",t),r(S,"input",e),r(T,"input",G)}function f(e){return b.getElementById(e)}function r(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 z(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 h,b,v,y,m,g,w,k,L,x,E,A,S,J,T,C,B,M,o,i,H,O,N,j,I,D,K}); |
{ | ||
"name": "@melloware/coloris", | ||
"version": "0.16.1", | ||
"version": "0.17.0", | ||
"description": "A lightweight and elegant color picker.", | ||
@@ -63,3 +63,3 @@ "author": "Momo Bassit", | ||
"prepack": "gulp build", | ||
"test-npm": "node test-npm/run-tests.js" | ||
"test-npm": "gulp build && node test-npm/run-tests.js" | ||
}, | ||
@@ -66,0 +66,0 @@ "browserslist": "> 0.25%, not dead", |
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
139035
2792