/
colorjoe.min.js
4 lines (4 loc) · 19 KB
/
colorjoe.min.js
1
2
3
4
/*! colorjoe - v0.7.2 - 2012-12-06
* http://bebraw.github.com/colorjoe/
* Copyright (c) 2012 Juho Vepsalainen; Licensed MIT */
function ONECOLOR(e){if(Object.prototype.toString.apply(e)==="[object Array]")return e.length===4?new ONECOLOR.RGB(e[0]/255,e[1]/255,e[2]/255,e[3]/255):new ONECOLOR[e[0]](e.slice(1,e.length));if(typeof e=="string"){var t=e.toLowerCase();namedColors[t]&&(e="#"+namedColors[t]);var n=e.match(cssColorRegExp);if(n){var r=n[1].toUpperCase(),i=undef(n[8])?n[8]:parseFloat(n[8]),s=r[0]==="H",o=n[3]?100:s?360:255,u=n[5]||s?100:255,a=n[7]||s?100:255;if(undef(ONECOLOR[r]))throw new Error("one.color."+r+" is not installed.");return new ONECOLOR[r](parseFloat(n[2])/o,parseFloat(n[4])/u,parseFloat(n[6])/a,i)}e.length<6&&(e=e.replace(/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/i,"$1$1$2$2$3$3"));var f=e.match(/^#?([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/i);if(f)return new ONECOLOR.RGB(parseInt(f[1],16)/255,parseInt(f[2],16)/255,parseInt(f[3],16)/255)}else{if(typeof e=="object"&&e.isColor)return e;if(!isNaN(e))return new ONECOLOR.RGB((e&255)/255,((e&65280)>>8)/255,((e&16711680)>>16)/255)}return!1}function installColorSpace(e,t,n){function o(e,t){var n={};n[t.toLowerCase()]=new Function("return this.rgb()."+t.toLowerCase()+"();"),ONECOLOR[t].propertyNames.forEach(function(e,r){n[e]=n[e==="black"?"k":e[0]]=new Function("value","isDelta","return this."+t.toLowerCase()+"()."+e+"(value, isDelta);")});for(var r in n)n.hasOwnProperty(r)&&ONECOLOR[e].prototype[r]===undefined&&(ONECOLOR[e].prototype[r]=n[r])}ONECOLOR[e]=new Function(t.join(","),"if (Object.prototype.toString.apply("+t[0]+") === '[object Array]') {"+t.map(function(e,n){return e+"="+t[0]+"["+n+"];"}).reverse().join("")+"}"+"if ("+t.filter(function(e){return e!=="alpha"}).map(function(e){return"isNaN("+e+")"}).join("||")+"){"+'throw new Error("['+e+']: Invalid color: ("+'+t.join('+","+')+'+")");}'+t.map(function(e){return e==="hue"?"this._hue=hue<0?hue-Math.floor(hue):hue%1":e==="alpha"?"this._alpha=(isNaN(alpha)||alpha>1)?1:(alpha<0?0:alpha);":"this._"+e+"="+e+"<0?0:("+e+">1?1:"+e+")"}).join(";")+";"),ONECOLOR[e].propertyNames=t;var r=ONECOLOR[e].prototype;["valueOf","hex","css","cssa"].forEach(function(t){r[t]=r[t]||(e==="RGB"?r.hex:new Function("return this.rgb()."+t+"();"))}),r.isColor=!0,r.equals=function(n,r){undef(r)&&(r=1e-10),n=n[e.toLowerCase()]();for(var i=0;i<t.length;i+=1)if(Math.abs(this["_"+t[i]]-n["_"+t[i]])>r)return!1;return!0},r.toJSON=new Function("return ['"+e+"', "+t.map(function(e){return"this._"+e},this).join(", ")+"];");for(var i in n)if(n.hasOwnProperty(i)){var s=i.match(/^from(.*)$/);s?ONECOLOR[s[1].toUpperCase()].prototype[e.toLowerCase()]=n[i]:r[i]=n[i]}r[e.toLowerCase()]=function(){return this},r.toString=new Function('return "[one.color.'+e+':"+'+t.map(function(e,n){return'" '+t[n]+'="+this._'+e}).join("+")+'+"]";'),t.forEach(function(e,n){r[e]=r[e==="black"?"k":e[0]]=new Function("value","isDelta","if (typeof value === 'undefined') {return this._"+e+";"+"}"+"if (isDelta) {"+"return new this.constructor("+t.map(function(t,n){return"this._"+t+(e===t?"+value":"")}).join(", ")+");"+"}"+"return new this.constructor("+t.map(function(t,n){return e===t?"value":"this._"+t}).join(", ")+");")}),installedColorSpaces.forEach(function(t){o(e,t),o(t,e)}),installedColorSpaces.push(e)}function gs(){var e=this.rgb(),t=e._red*.3+e._green*.59+e._blue*.11;return new ONECOLOR.RGB(t,t,t,this._alpha)}(function(e,t){typeof define=="function"&&define.amd?define(t):e.drag=t()})(this,function(){function e(e,t){if(!e){console.warn("drag is missing elem!");return}o()?u(e,t,"touchstart","touchmove","touchend"):u(e,t,"mousedown","mousemove","mouseup")}function t(t){var n=i(t["class"]||"",t.parent),s=i("pointer",n);return i("shape shape1",s),i("shape shape2",s),i("bg bg1",n),i("bg bg2",n),e(n,r(t.cbs,s)),{background:n,pointer:s}}function n(t){var n=i(t["class"],t.parent),s=i("pointer",n);return i("shape",s),i("bg",n),e(n,r(t.cbs,s)),{background:n,pointer:s}}function r(e,t){function i(e){return function(n){n.pointer=t,e(n)}}var n={};for(var r in e)n[r]=i(e[r]);return n}function i(e,t){return s("div",e,t)}function s(e,t,n){var r=document.createElement(e);return t&&(r.className=t),n.appendChild(r),r}function o(){return typeof window.ontouchstart!="undefined"}function u(e,t,n,r,i){var s=!1;t=l(t);var o=t.begin,u=t.change,c=t.end;a(e,n,function(t){function l(){s=!1,f(document,r,n),f(document,i,l),p(c,e,t)}s=!0;var n=d(p,u,e);a(document,r,n),a(document,i,l),p(o,e,t)})}function a(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent&&e.attachEvent("on"+t,n)}function f(e,t,n){e.removeEventListener?e.removeEventListener(t,n,!1):e.detachEvent&&e.detachEvent("on"+t,n)}function l(e){if(!e){var t,n;return{begin:function(e){t={x:e.elem.offsetLeft,y:e.elem.offsetTop},n=e.cursor},change:function(e){c(e.elem,"left",t.x+e.cursor.x-n.x+"px"),c(e.elem,"top",t.y+e.cursor.y-n.y+"px")},end:h}}return{begin:e.begin||h,change:e.change||h,end:e.end||h}}function c(e,t,n){e.style[t]=n}function h(){}function p(e,t,n){n.preventDefault();var r=v(t),i=t.clientWidth,s=t.clientHeight,o={x:m(t,n),y:g(t,n)},u=(o.x-r.x)/i,a=(o.y-r.y)/s;e({x:isNaN(u)?0:u,y:isNaN(a)?0:a,cursor:o,elem:t,e:n})}function d(e){var t=Array.prototype.slice,n=t.apply(arguments,[1]);return function(){return e.apply(null,n.concat(t.apply(arguments)))}}function v(e){var t=0,n=0;if(e.offsetParent)do t+=e.offsetLeft,n+=e.offsetTop;while(e=e.offsetParent);return{x:t,y:n}}function m(e,t){if(b(e)){var n=parseInt(w(document.body,"marginLeft"),10)-y(e,"scrollLeft")+window.pageXOffset+e.style.marginLeft;return t.clientX-n}if(t.pageX)return t.pageX;if(t.clientX)return t.clientX+document.body.scrollLeft}function g(e,t){if(b(e)){var n=parseInt(w(document.body,"marginTop"),10)-y(e,"scrollTop")+window.pageYOffset+e.style.marginTop;return t.clientY-n}if(t.pageY)return t.pageY;if(t.clientY)return t.clientY+document.body.scrollTop}function y(e,t){var n=0;while(e.nodeName!="HTML")n+=e[t],e=e.parentNode;return n}function b(e){while(e.nodeName!="HTML"&&E(e,"position")!="fixed")e=e.parentNode;return e.nodeName=="HTML"?!1:!0}function w(e,t){return e.currentStyle?e.currentStyle[t]:document.defaultView&&document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(e,"")[t]:e.style[t]}function E(e,t){var n;return window.getComputedStyle?n=window.getComputedStyle(e,null):n=e.currentStyle,n[t]}return e.xyslider=t,e.slider=n,e});var installedColorSpaces=[],namedColors={},undef=function(e){return typeof e=="undefined"},channelRegExp=/\s*(\.\d+|\d+(?:\.\d+)?)(%)?\s*/,alphaChannelRegExp=/\s*(\.\d+|\d+(?:\.\d+)?)\s*/,cssColorRegExp=new RegExp("^(rgb|hsl|hsv)a?\\("+channelRegExp.source+","+channelRegExp.source+","+channelRegExp.source+"(?:,"+alphaChannelRegExp.source+")?"+"\\)$","i");ONECOLOR.installMethod=function(e,t){installedColorSpaces.forEach(function(n){ONECOLOR[n].prototype[e]=t})},installColorSpace("RGB",["red","green","blue","alpha"],{hex:function(){var e=(Math.round(255*this._red)*65536+Math.round(255*this._green)*256+Math.round(255*this._blue)).toString(16);return"#"+"00000".substr(0,6-e.length)+e},css:function(){return"rgb("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+")"},cssa:function(){return"rgba("+Math.round(255*this._red)+","+Math.round(255*this._green)+","+Math.round(255*this._blue)+","+this._alpha+")"}}),typeof module!="undefined"?module.exports=ONECOLOR:typeof define=="function"&&!undef(define.amd)?define([],function(){return ONECOLOR}):typeof jQuery!="undefined"&&undef(jQuery.color)?jQuery.color=ONECOLOR:(one=window.one||{},one.color=ONECOLOR),namedColors={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgrey:"a9a9a9",darkgreen:"006400",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",grey:"808080",green:"008000",greenyellow:"adff2f",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgrey:"d3d3d3",lightgreen:"90ee90",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370d8",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"d87093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},installColorSpace("HSV",["hue","saturation","value","alpha"],{rgb:function(){var e=this._hue,t=this._saturation,n=this._value,r=Math.min(5,Math.floor(e*6)),i=e*6-r,s=n*(1-t),o=n*(1-i*t),u=n*(1-(1-i)*t),a,f,l;switch(r){case 0:a=n,f=u,l=s;break;case 1:a=o,f=n,l=s;break;case 2:a=s,f=n,l=u;break;case 3:a=s,f=o,l=n;break;case 4:a=u,f=s,l=n;break;case 5:a=n,f=s,l=o}return new ONECOLOR.RGB(a,f,l,this._alpha)},hsl:function(){var e=(2-this._saturation)*this._value,t=this._saturation*this._value,n=e<=1?e:2-e,r;return n<1e-9?r=0:r=t/n,new ONECOLOR.HSL(this._hue,r,e/2,this._alpha)},fromRgb:function(){var e=this._red,t=this._green,n=this._blue,r=Math.max(e,t,n),i=Math.min(e,t,n),s=r-i,o,u=r===0?0:s/r,a=r;if(s===0)o=0;else switch(r){case e:o=(t-n)/s/6+(t<n?1:0);break;case t:o=(n-e)/s/6+1/3;break;case n:o=(e-t)/s/6+2/3}return new ONECOLOR.HSV(o,u,a,this._alpha)}}),installColorSpace("HSL",["hue","saturation","lightness","alpha"],{hsv:function(){var e=this._lightness*2,t=this._saturation*(e<=1?e:2-e),n;return e+t<1e-9?n=0:n=2*t/(e+t),new ONECOLOR.HSV(this._hue,n,(e+t)/2,this._alpha)},rgb:function(){return this.hsv().rgb()},fromRgb:function(){return this.hsv().hsl()}}),installColorSpace("CMYK",["cyan","magenta","yellow","black","alpha"],{rgb:function(){return new ONECOLOR.RGB(1-this._cyan*(1-this._black)-this._black,1-this._magenta*(1-this._black)-this._black,1-this._yellow*(1-this._black)-this._black,this._alpha)},fromRgb:function(){var e=this._red,t=this._green,n=this._blue,r=1-e,i=1-t,s=1-n,o=1;return e||t||n?(o=Math.min(r,Math.min(i,s)),r=(r-o)/(1-o),i=(i-o)/(1-o),s=(s-o)/(1-o)):o=1,new ONECOLOR.CMYK(r,i,s,o,this._alpha)}}),ONECOLOR.installMethod("clearer",function(e){return this.alpha(isNaN(e)?-0.1:-e,!0)}),ONECOLOR.installMethod("darken",function(e){return this.lightness(isNaN(e)?-0.1:-e,!0)}),ONECOLOR.installMethod("desaturate",function(e){return this.saturation(isNaN(e)?-0.1:-e,!0)}),ONECOLOR.installMethod("greyscale",gs),ONECOLOR.installMethod("grayscale",gs),ONECOLOR.installMethod("lighten",function(e){return this.lightness(isNaN(e)?.1:e,!0)}),ONECOLOR.installMethod("mix",function(e,t){e=ONECOLOR(e).rgb(),t=1-(isNaN(t)?.5:t);var n=t*2-1,r=this._alpha-e._alpha,i=((n*r===-1?n:(n+r)/(1+n*r))+1)/2,s=1-i,o=this.rgb();return new ONECOLOR.RGB(o._red*i+e._red*s,o._green*i+e._green*s,o._blue*i+e._blue*s,o._alpha*t+e._alpha*(1-t))}),ONECOLOR.installMethod("negate",function(){var e=this.rgb();return new ONECOLOR.RGB(1-e._red,1-e._green,1-e._blue,this._alpha)}),ONECOLOR.installMethod("opaquer",function(e){return this.alpha(isNaN(e)?.1:e,!0)}),ONECOLOR.installMethod("rotate",function(e){return this.hue((e||0)/360,!0)}),ONECOLOR.installMethod("saturate",function(e){return this.saturation(isNaN(e)?.1:e,!0)}),ONECOLOR.installMethod("toAlpha",function(e){var t=this.rgb(),n=ONECOLOR(e).rgb(),r=1e-10,i=new ONECOLOR.RGB(0,0,0,t._alpha),s=["_red","_green","_blue"];return s.forEach(function(e){t[e]<r?i[e]=t[e]:t[e]>n[e]?i[e]=(t[e]-n[e])/(1-n[e]):t[e]>n[e]?i[e]=(n[e]-t[e])/n[e]:i[e]=0}),i._red>i._green?i._red>i._blue?t._alpha=i._red:t._alpha=i._blue:i._green>i._blue?t._alpha=i._green:t._alpha=i._blue,t._alpha<r?t:(s.forEach(function(e){t[e]=(t[e]-n[e])/t._alpha+n[e]}),t._alpha*=i._alpha,t)}),function(e,t){typeof exports=="object"?module.exports=t():typeof define=="function"&&define.amd?define(t):e.elemutils=t()}(this,function(){function t(e,t,n){var r=document.createElement(e);return r.className=t,n.appendChild(r),r}function n(e){var t=Array.prototype.slice,n=t.apply(arguments,[1]);return function(){return e.apply(null,n.concat(t.apply(arguments)))}}function r(t,n,r,o){var u=e(t,r),a=i(n,u),f=s("text",u,o);return{label:a,input:f}}function i(e,n){var r=t("label","",n);return r.innerHTML=e,r}function s(e,n,r){var i=t("input","",n);return i.type=e,r&&(i.maxLength=r),i}function o(e,t){e.style.left=f(t*100,0,100)+"%"}function u(e,t){e.style.top=f(t*100,0,100)+"%"}function a(e,t){e.style.background=t}function f(e,t,n){return Math.min(Math.max(e,t),n)}var e=n(t,"div");return{clamp:f,e:t,div:e,partial:n,labelInput:r,X:o,Y:u,BG:a}}),function(e,t){typeof define=="function"&&define.amd?define(["./elemutils","./drag"],t):e.colorjoeextras=t(e.elemutils,e.drag)}(this,function(e,t){function n(t){var n=e.div("currentColorContainer",t),r=e.div("currentColor",n);return{change:function(t){e.BG(r,t.cssa())}}}function r(t,n,r){function h(){var e=[i];c.forEach(function(t){e.push(t.e.input.value/s)}),f||e.push(n.getAlpha()),n.set(e)}var i=r.space,s=r.limit||255,o=r.fix>=0?r.fix:0,u=(""+s).length+o;u=o?u+1:u;var a=i.split(""),f=i[i.length-1]=="A";i=f?i.slice(0,-1):i;if(["RGB","HSL","HSV","CMYK"].indexOf(i)<0)return console.warn("Invalid field names",i);var l=e.div("colorFields",t),c=a.map(function(t,n){t=t.toLowerCase();var r=e.labelInput("color "+t,t,l,u);return r.input.onkeyup=h,{name:t,e:r}});return{change:function(e){c.forEach(function(t){t.e.input.value=(e[t.name]()*s).toFixed(o)})}}}function i(n,r){function s(t){var n=e.clamp(t.y,0,1);e.Y(t.pointer,n),r.setAlpha(1-n)}var i=t.slider({parent:n,"class":"oned alpha",cbs:{begin:s,change:s}});return{change:function(t){e.Y(i.pointer,1-t.alpha())}}}function s(t,n,r){var i=e.labelInput("hex",r.label||"",t,7);return i.input.value="#",i.input.onkeyup=function(e){var t=e.keyCode||e.which,r=e.target.value;r=r[0]=="#"?r:"#"+r,r=u(r,7,"0"),t==13&&n.set(r)},i.input.onblur=function(e){n.set(e.target.value)},{change:function(e){i.input.value=i.input.value[0]=="#"?"#":"",i.input.value+=e.hex().slice(1)}}}function o(t,n,r){var i=e.e("a",r["class"]||"close",t);i.href="#",i.innerHTML=r.label||"Close",i.onclick=function(e){e.preventDefault(),n.hide()}}function u(e,t,n){var r=e;for(var i=e.length,s=t;i<t;i++)r+=n;return r}return{currentColor:n,fields:r,hex:s,alpha:i,close:o}}),function(e,t){typeof define=="function"&&define.amd?define(["./onecolor","./drag","./elemutils","./extras"],t):e.colorjoe=t(e.ONECOLOR,e.drag,e.elemutils,e.colorjoeextras)}(this,function(e,t,n,r){function o(t,r){n.BG(t,(new e.HSV(r,1,1)).cssa())}function u(e){function o(e){h=i.xy(h,{x:n.clamp(e.x,0,1),y:n.clamp(e.y,0,1)},s,u),m()}function l(e){h=i.z(h,n.clamp(e.y,0,1),s,u),m()}function m(e){e=p(e)?e:[];var t=v.change,n;for(var r=0,i=t.length;r<i;r++)n=t[r],e.indexOf(n.name)==-1&&n.fn(h)}function g(){if(c.equals(h))return;for(var e=0,t=v.done.length;e<t;e++)v.done[e](h);c=h}if(!e.e)return console.warn("colorjoe: missing element");var r=d(e.e)?document.getElementById(e.e):e.e;r.className="colorPicker";var i=e.cbs,s=t.xyslider({parent:r,"class":"twod",cbs:{begin:o,change:o,end:g}}),u=t.slider({parent:r,"class":"oned",cbs:{begin:l,change:l,end:g}}),c=a(e.color),h=i.init(c,s,u),v={change:[],done:[]},y={e:r,update:function(e){return m(e),this},hide:function(){return r.style.display="none",this},show:function(){return r.style.display="",this},get:function(){return h},set:function(e){var t=this.get();return h=i.init(a(e),s,u),t.equals(h)||this.update(),this},getAlpha:function(){return h.alpha()},setAlpha:function(e){return h=h.alpha(e),this.update(),this},on:function(e,t,n){return e=="change"||e=="done"?v[e].push({name:n,fn:t}):console.warn('Passed invalid evt name "'+e+'" to colorjoe.on'),this},removeAllListeners:function(e){if(e)delete v[e];else for(var t in v)delete v[t];return this}};return f(r,y,e.extras),m(),y}function a(t){if(!v(t))return e("black");if(t.isColor)return t;var n=e(t);return n?n:(v(t)&&console.warn("Passed invalid color to colorjoe, using black instead"),e("black"))}function f(e,t,r){if(!r)return;var s=n.div("extras",e),o,u,a;r.forEach(function(e,n){p(e)?(u=e[0],a=e.length>1?e[1]:{}):(u=e,a={}),extra=u in i._extras?i._extras[u]:null;if(extra){o=extra(s,l(t,u+n),a);for(var r in o)t.on(r,o[r],u)}})}function l(e,t){var n=c(e);return n.update=function(){e.update([t])},n}function c(e){var t={};for(var n in e)t[n]=e[n];return t}function h(e,t){return t.map(e).filter(g).length==t.length}function p(e){return Object.prototype.toString.call(e)==="[object Array]"}function d(e){return typeof e=="string"}function v(e){return typeof e!="undefined"}function m(e){return typeof e=="function"}function g(e){return e}var i=function(e){return h(m,[e.init,e.xy,e.z])?function(t,n,r){return u({e:t,color:n,cbs:e,extras:r})}:console.warn("colorjoe: missing cb")};i.rgb=i({init:function(t,n,r){var i=e(t).hsl();return this.xy(i,{x:i.saturation(),y:1-i.value()},n,r),this.z(i,i.hue(),n,r),i},xy:function(e,t,r,i){return n.X(r.pointer,t.x),n.Y(r.pointer,t.y),e.saturation(t.x).value(1-t.y)},z:function(e,t,r,i){return n.Y(i.pointer,t),o(r.background,t),e.hue(t)}}),i.hsl=i({init:function(t,n,r){var i=e(t).hsl();return this.xy(i,{x:i.hue(),y:1-i.saturation()},n,r),this.z(i,1-i.lightness(),n,r),i},xy:function(e,t,r,i){return n.X(r.pointer,t.x),n.Y(r.pointer,t.y),o(i.background,t.x),e.hue(t.x).saturation(1-t.y)},z:function(e,t,r,i){return n.Y(i.pointer,t),e.lightness(1-t)}}),i._extras={},i.registerExtra=function(e,t){e in i._extras&&console.warn('Extra "'+e+'"has been registered already!'),i._extras[e]=t};for(var s in r)i.registerExtra(s,r[s]);return i});