between.js
Version:
Lightweight ES6 JavaScript tweening engine
2 lines (1 loc) • 23.4 kB
JavaScript
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("between")):"function"==typeof define&&define.amd?define(["between"],n):(r.Between=r.Between||{},r.Between._plugins=r.Between._plugins||{},r.Between._plugins.color=n(null))}(this,function(r){"use strict";function n(r,n){return r(n={exports:{}},n.exports),n.exports}r=r&&r.hasOwnProperty("default")?r.default:r;var u={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},o=n(function(r){var l=Array.prototype.concat,i=Array.prototype.slice,n=r.exports=function(r){for(var n,e=[],t=0,a=r.length;t<a;t++){var o=r[t];(n=o)&&"string"!=typeof n&&(n instanceof Array||Array.isArray(n)||0<=n.length&&(n.splice instanceof Function||Object.getOwnPropertyDescriptor(n,n.length-1)&&"String"!==n.constructor.name))?e=l.call(e,i.call(o)):e.push(o)}return e};n.wrap=function(r){return function(){return r(n(arguments))}}}),c=n(function(r){var n={};for(var e in u)u.hasOwnProperty(e)&&(n[u[e]]=e);var t=r.exports={to:{}};function l(r,n,e){return Math.min(Math.max(n,r),e)}function a(r){var n=r.toString(16).toUpperCase();return n.length<2?"0"+n:n}t.get=function(r){var n,e;switch(r.substring(0,3).toLowerCase()){case"hsl":n=t.get.hsl(r),e="hsl";break;case"hwb":n=t.get.hwb(r),e="hwb";break;default:n=t.get.rgb(r),e="rgb"}return n?{model:e,value:n}:null},t.get.rgb=function(r){if(!r)return null;var n,e,t,a=[0,0,0,1];if(n=r.match(/^#([a-f0-9]{6})([a-f0-9]{2})?$/i)){for(t=n[2],n=n[1],e=0;e<3;e++){var o=2*e;a[e]=parseInt(n.slice(o,o+2),16)}t&&(a[3]=Math.round(parseInt(t,16)/255*100)/100)}else if(n=r.match(/^#([a-f0-9]{3,4})$/i)){for(t=(n=n[1])[3],e=0;e<3;e++)a[e]=parseInt(n[e]+n[e],16);t&&(a[3]=Math.round(parseInt(t+t,16)/255*100)/100)}else if(n=r.match(/^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/)){for(e=0;e<3;e++)a[e]=parseInt(n[e+1],0);n[4]&&(a[3]=parseFloat(n[4]))}else{if(!(n=r.match(/^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/)))return(n=r.match(/(\D+)/))?"transparent"===n[1]?[0,0,0,0]:(a=u[n[1]])?(a[3]=1,a):null:null;for(e=0;e<3;e++)a[e]=Math.round(2.55*parseFloat(n[e+1]));n[4]&&(a[3]=parseFloat(n[4]))}for(e=0;e<3;e++)a[e]=l(a[e],0,255);return a[3]=l(a[3],0,1),a},t.get.hsl=function(r){if(!r)return null;var n=r.match(/^hsla?\(\s*([+-]?\d*[\.]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/);if(n){var e=parseFloat(n[4]);return[(parseFloat(n[1])%360+360)%360,l(parseFloat(n[2]),0,100),l(parseFloat(n[3]),0,100),l(isNaN(e)?1:e,0,1)]}return null},t.get.hwb=function(r){if(!r)return null;var n=r.match(/^hwb\(\s*([+-]?\d*[\.]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/);if(n){var e=parseFloat(n[4]);return[(parseFloat(n[1])%360+360)%360,l(parseFloat(n[2]),0,100),l(parseFloat(n[3]),0,100),l(isNaN(e)?1:e,0,1)]}return null},t.to.hex=function(){var r=o(arguments);return"#"+a(r[0])+a(r[1])+a(r[2])+(r[3]<1?a(Math.round(255*r[3])):"")},t.to.rgb=function(){var r=o(arguments);return r.length<4||1===r[3]?"rgb("+Math.round(r[0])+", "+Math.round(r[1])+", "+Math.round(r[2])+")":"rgba("+Math.round(r[0])+", "+Math.round(r[1])+", "+Math.round(r[2])+", "+r[3]+")"},t.to.rgb.percent=function(){var r=o(arguments),n=Math.round(r[0]/255*100),e=Math.round(r[1]/255*100),t=Math.round(r[2]/255*100);return r.length<4||1===r[3]?"rgb("+n+"%, "+e+"%, "+t+"%)":"rgba("+n+"%, "+e+"%, "+t+"%, "+r[3]+")"},t.to.hsl=function(){var r=o(arguments);return r.length<4||1===r[3]?"hsl("+r[0]+", "+r[1]+"%, "+r[2]+"%)":"hsla("+r[0]+", "+r[1]+"%, "+r[2]+"%, "+r[3]+")"},t.to.hwb=function(){var r=o(arguments),n="";return 4<=r.length&&1!==r[3]&&(n=", "+r[3]),"hwb("+r[0]+", "+r[1]+"%, "+r[2]+"%"+n+")"},t.to.keyword=function(r){return n[r.slice(0,3)]}}),s=(c.to,n(function(r){var s={};for(var n in u)u.hasOwnProperty(n)&&(s[u[n]]=n);var l=r.exports={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};for(var e in l)if(l.hasOwnProperty(e)){if(!("channels"in l[e]))throw new Error("missing channels property: "+e);if(!("labels"in l[e]))throw new Error("missing channel labels property: "+e);if(l[e].labels.length!==l[e].channels)throw new Error("channel and label counts mismatch: "+e);var t=l[e].channels,a=l[e].labels;delete l[e].channels,delete l[e].labels,Object.defineProperty(l[e],"channels",{value:t}),Object.defineProperty(l[e],"labels",{value:a})}l.rgb.hsl=function(r){var n,e,t=r[0]/255,a=r[1]/255,o=r[2]/255,l=Math.min(t,a,o),i=Math.max(t,a,o),h=i-l;return i===l?n=0:t===i?n=(a-o)/h:a===i?n=2+(o-t)/h:o===i&&(n=4+(t-a)/h),(n=Math.min(60*n,360))<0&&(n+=360),e=(l+i)/2,[n,100*(i===l?0:e<=.5?h/(i+l):h/(2-i-l)),100*e]},l.rgb.hsv=function(r){var n,e,t=r[0],a=r[1],o=r[2],l=Math.min(t,a,o),i=Math.max(t,a,o),h=i-l;return e=0===i?0:h/i*1e3/10,i===l?n=0:t===i?n=(a-o)/h:a===i?n=2+(o-t)/h:o===i&&(n=4+(t-a)/h),(n=Math.min(60*n,360))<0&&(n+=360),[n,e,i/255*1e3/10]},l.rgb.hwb=function(r){var n=r[0],e=r[1],t=r[2];return[l.rgb.hsl(r)[0],100*(1/255*Math.min(n,Math.min(e,t))),100*(t=1-1/255*Math.max(n,Math.max(e,t)))]},l.rgb.cmyk=function(r){var n,e=r[0]/255,t=r[1]/255,a=r[2]/255;return[100*((1-e-(n=Math.min(1-e,1-t,1-a)))/(1-n)||0),100*((1-t-n)/(1-n)||0),100*((1-a-n)/(1-n)||0),100*n]},l.rgb.keyword=function(r){var n=s[r];if(n)return n;var e,t,a,o=1/0;for(var l in u)if(u.hasOwnProperty(l)){var i=u[l],h=(t=r,a=i,Math.pow(t[0]-a[0],2)+Math.pow(t[1]-a[1],2)+Math.pow(t[2]-a[2],2));h<o&&(o=h,e=l)}return e},l.keyword.rgb=function(r){return u[r]},l.rgb.xyz=function(r){var n=r[0]/255,e=r[1]/255,t=r[2]/255;return[100*(.4124*(n=.04045<n?Math.pow((n+.055)/1.055,2.4):n/12.92)+.3576*(e=.04045<e?Math.pow((e+.055)/1.055,2.4):e/12.92)+.1805*(t=.04045<t?Math.pow((t+.055)/1.055,2.4):t/12.92)),100*(.2126*n+.7152*e+.0722*t),100*(.0193*n+.1192*e+.9505*t)]},l.rgb.lab=function(r){var n=l.rgb.xyz(r),e=n[0],t=n[1],a=n[2];return t/=100,a/=108.883,e=.008856<(e/=95.047)?Math.pow(e,1/3):7.787*e+16/116,[116*(t=.008856<t?Math.pow(t,1/3):7.787*t+16/116)-16,500*(e-t),200*(t-(a=.008856<a?Math.pow(a,1/3):7.787*a+16/116))]},l.hsl.rgb=function(r){var n,e,t,a,o,l=r[0]/360,i=r[1]/100,h=r[2]/100;if(0===i)return[o=255*h,o,o];n=2*h-(e=h<.5?h*(1+i):h+i-h*i),a=[0,0,0];for(var s=0;s<3;s++)(t=l+1/3*-(s-1))<0&&t++,1<t&&t--,o=6*t<1?n+6*(e-n)*t:2*t<1?e:3*t<2?n+(e-n)*(2/3-t)*6:n,a[s]=255*o;return a},l.hsl.hsv=function(r){var n=r[0],e=r[1]/100,t=r[2]/100,a=e,o=Math.max(t,.01);return e*=(t*=2)<=1?t:2-t,a*=o<=1?o:2-o,[n,100*(0===t?2*a/(o+a):2*e/(t+e)),100*((t+e)/2)]},l.hsv.rgb=function(r){var n=r[0]/60,e=r[1]/100,t=r[2]/100,a=Math.floor(n)%6,o=n-Math.floor(n),l=255*t*(1-e),i=255*t*(1-e*o),h=255*t*(1-e*(1-o));switch(t*=255,a){case 0:return[t,h,l];case 1:return[i,t,l];case 2:return[l,t,h];case 3:return[l,i,t];case 4:return[h,l,t];case 5:return[t,l,i]}},l.hsv.hsl=function(r){var n,e,t,a=r[0],o=r[1]/100,l=r[2]/100,i=Math.max(l,.01);return t=(2-o)*l,e=o*i,[a,100*(e=(e/=(n=(2-o)*i)<=1?n:2-n)||0),100*(t/=2)]},l.hwb.rgb=function(r){var n,e,t,a,o,l,i,h=r[0]/360,s=r[1]/100,u=r[2]/100,c=s+u;switch(1<c&&(s/=c,u/=c),t=6*h-(n=Math.floor(6*h)),0!=(1&n)&&(t=1-t),a=s+t*((e=1-u)-s),n){default:case 6:case 0:o=e,l=a,i=s;break;case 1:o=a,l=e,i=s;break;case 2:o=s,l=e,i=a;break;case 3:o=s,l=a,i=e;break;case 4:o=a,l=s,i=e;break;case 5:o=e,l=s,i=a}return[255*o,255*l,255*i]},l.cmyk.rgb=function(r){var n=r[0]/100,e=r[1]/100,t=r[2]/100,a=r[3]/100;return[255*(1-Math.min(1,n*(1-a)+a)),255*(1-Math.min(1,e*(1-a)+a)),255*(1-Math.min(1,t*(1-a)+a))]},l.xyz.rgb=function(r){var n,e,t,a=r[0]/100,o=r[1]/100,l=r[2]/100;return e=-.9689*a+1.8758*o+.0415*l,t=.0557*a+-.204*o+1.057*l,n=.0031308<(n=3.2406*a+-1.5372*o+-.4986*l)?1.055*Math.pow(n,1/2.4)-.055:12.92*n,e=.0031308<e?1.055*Math.pow(e,1/2.4)-.055:12.92*e,t=.0031308<t?1.055*Math.pow(t,1/2.4)-.055:12.92*t,[255*(n=Math.min(Math.max(0,n),1)),255*(e=Math.min(Math.max(0,e),1)),255*(t=Math.min(Math.max(0,t),1))]},l.xyz.lab=function(r){var n=r[0],e=r[1],t=r[2];return e/=100,t/=108.883,n=.008856<(n/=95.047)?Math.pow(n,1/3):7.787*n+16/116,[116*(e=.008856<e?Math.pow(e,1/3):7.787*e+16/116)-16,500*(n-e),200*(e-(t=.008856<t?Math.pow(t,1/3):7.787*t+16/116))]},l.lab.xyz=function(r){var n,e,t,a=r[0];n=r[1]/500+(e=(a+16)/116),t=e-r[2]/200;var o=Math.pow(e,3),l=Math.pow(n,3),i=Math.pow(t,3);return e=.008856<o?o:(e-16/116)/7.787,n=.008856<l?l:(n-16/116)/7.787,t=.008856<i?i:(t-16/116)/7.787,[n*=95.047,e*=100,t*=108.883]},l.lab.lch=function(r){var n,e=r[0],t=r[1],a=r[2];return(n=360*Math.atan2(a,t)/2/Math.PI)<0&&(n+=360),[e,Math.sqrt(t*t+a*a),n]},l.lch.lab=function(r){var n,e=r[0],t=r[1];return n=r[2]/360*2*Math.PI,[e,t*Math.cos(n),t*Math.sin(n)]},l.rgb.ansi16=function(r){var n=r[0],e=r[1],t=r[2],a=1 in arguments?arguments[1]:l.rgb.hsv(r)[2];if(0===(a=Math.round(a/50)))return 30;var o=30+(Math.round(t/255)<<2|Math.round(e/255)<<1|Math.round(n/255));return 2===a&&(o+=60),o},l.hsv.ansi16=function(r){return l.rgb.ansi16(l.hsv.rgb(r),r[2])},l.rgb.ansi256=function(r){var n=r[0],e=r[1],t=r[2];return n===e&&e===t?n<8?16:248<n?231:Math.round((n-8)/247*24)+232:16+36*Math.round(n/255*5)+6*Math.round(e/255*5)+Math.round(t/255*5)},l.ansi16.rgb=function(r){var n=r%10;if(0===n||7===n)return 50<r&&(n+=3.5),[n=n/10.5*255,n,n];var e=.5*(1+~~(50<r));return[(1&n)*e*255,(n>>1&1)*e*255,(n>>2&1)*e*255]},l.ansi256.rgb=function(r){if(232<=r){var n=10*(r-232)+8;return[n,n,n]}var e;return r-=16,[Math.floor(r/36)/5*255,Math.floor((e=r%36)/6)/5*255,e%6/5*255]},l.rgb.hex=function(r){var n=(((255&Math.round(r[0]))<<16)+((255&Math.round(r[1]))<<8)+(255&Math.round(r[2]))).toString(16).toUpperCase();return"000000".substring(n.length)+n},l.hex.rgb=function(r){var n=r.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!n)return[0,0,0];var e=n[0];3===n[0].length&&(e=e.split("").map(function(r){return r+r}).join(""));var t=parseInt(e,16);return[t>>16&255,t>>8&255,255&t]},l.rgb.hcg=function(r){var n,e=r[0]/255,t=r[1]/255,a=r[2]/255,o=Math.max(Math.max(e,t),a),l=Math.min(Math.min(e,t),a),i=o-l;return n=i<=0?0:o===e?(t-a)/i%6:o===t?2+(a-e)/i:4+(e-t)/i+4,n/=6,[360*(n%=1),100*i,100*(i<1?l/(1-i):0)]},l.hsl.hcg=function(r){var n=r[1]/100,e=r[2]/100,t=1,a=0;return(t=e<.5?2*n*e:2*n*(1-e))<1&&(a=(e-.5*t)/(1-t)),[r[0],100*t,100*a]},l.hsv.hcg=function(r){var n=r[1]/100,e=r[2]/100,t=n*e,a=0;return t<1&&(a=(e-t)/(1-t)),[r[0],100*t,100*a]},l.hcg.rgb=function(r){var n=r[0]/360,e=r[1]/100,t=r[2]/100;if(0===e)return[255*t,255*t,255*t];var a,o=[0,0,0],l=n%1*6,i=l%1,h=1-i;switch(Math.floor(l)){case 0:o[0]=1,o[1]=i,o[2]=0;break;case 1:o[0]=h,o[1]=1,o[2]=0;break;case 2:o[0]=0,o[1]=1,o[2]=i;break;case 3:o[0]=0,o[1]=h,o[2]=1;break;case 4:o[0]=i,o[1]=0,o[2]=1;break;default:o[0]=1,o[1]=0,o[2]=h}return a=(1-e)*t,[255*(e*o[0]+a),255*(e*o[1]+a),255*(e*o[2]+a)]},l.hcg.hsv=function(r){var n=r[1]/100,e=n+r[2]/100*(1-n),t=0;return 0<e&&(t=n/e),[r[0],100*t,100*e]},l.hcg.hsl=function(r){var n=r[1]/100,e=r[2]/100*(1-n)+.5*n,t=0;return 0<e&&e<.5?t=n/(2*e):.5<=e&&e<1&&(t=n/(2*(1-e))),[r[0],100*t,100*e]},l.hcg.hwb=function(r){var n=r[1]/100,e=n+r[2]/100*(1-n);return[r[0],100*(e-n),100*(1-e)]},l.hwb.hcg=function(r){var n=r[1]/100,e=1-r[2]/100,t=e-n,a=0;return t<1&&(a=(e-t)/(1-t)),[r[0],100*t,100*a]},l.apple.rgb=function(r){return[r[0]/65535*255,r[1]/65535*255,r[2]/65535*255]},l.rgb.apple=function(r){return[r[0]/255*65535,r[1]/255*65535,r[2]/255*65535]},l.gray.rgb=function(r){return[r[0]/100*255,r[0]/100*255,r[0]/100*255]},l.gray.hsl=l.gray.hsv=function(r){return[0,0,r[0]]},l.gray.hwb=function(r){return[0,100,r[0]]},l.gray.cmyk=function(r){return[0,0,0,r[0]]},l.gray.lab=function(r){return[r[0],0,0]},l.gray.hex=function(r){var n=255&Math.round(r[0]/100*255),e=((n<<16)+(n<<8)+n).toString(16).toUpperCase();return"000000".substring(e.length)+e},l.rgb.gray=function(r){return[(r[0]+r[1]+r[2])/3/255*100]}}));s.rgb,s.hsl,s.hsv,s.hwb,s.cmyk,s.xyz,s.lab,s.lch,s.hex,s.keyword,s.ansi16,s.ansi256,s.hcg,s.apple,s.gray;function h(r){var n=function(){for(var r={},n=Object.keys(s),e=n.length,t=0;t<e;t++)r[n[t]]={distance:-1,parent:null};return r}(),e=[r];for(n[r].distance=0;e.length;)for(var t=e.pop(),a=Object.keys(s[t]),o=a.length,l=0;l<o;l++){var i=a[l],h=n[i];-1===h.distance&&(h.distance=n[t].distance+1,h.parent=t,e.unshift(i))}return n}function l(n,e){return function(r){return e(n(r))}}function f(r,n){for(var e=[n[r].parent,r],t=s[n[r].parent][r],a=n[r].parent;n[a].parent;)e.unshift(n[a].parent),t=l(s[n[a].parent][a],t),a=n[a].parent;return t.conversion=e,t}var g={};Object.keys(s).forEach(function(l){g[l]={},Object.defineProperty(g[l],"channels",{value:s[l].channels}),Object.defineProperty(g[l],"labels",{value:s[l].labels});var i=function(r){for(var n=h(r),e={},t=Object.keys(n),a=t.length,o=0;o<a;o++){var l=t[o];null!==n[l].parent&&(e[l]=f(l,n))}return e}(l);Object.keys(i).forEach(function(r){var a,n,e,t,o=i[r];g[l][r]=(n=function(r){if(null==r)return r;1<arguments.length&&(r=Array.prototype.slice.call(arguments));var n=a(r);if("object"==typeof n)for(var e=n.length,t=0;t<e;t++)n[t]=Math.round(n[t]);return n},"conversion"in(a=o)&&(n.conversion=a.conversion),n),g[l][r].raw=(t=function(r){return null==r?r:(1<arguments.length&&(r=Array.prototype.slice.call(arguments)),e(r))},"conversion"in(e=o)&&(t.conversion=e.conversion),t)})});var b=g,p=[].slice,v=["keyword","gray","hex"],d={};Object.keys(b).forEach(function(r){d[p.call(b[r].labels).sort().join("")]=r});var m={};function y(r,n){if(!(this instanceof y))return new y(r,n);if(n&&n in v&&(n=null),n&&!(n in b))throw new Error("Unknown model: "+n);var e,t;if(r)if(r instanceof y)this.model=r.model,this.color=r.color.slice(),this.valpha=r.valpha;else if("string"==typeof r){var a=c.get(r);if(null===a)throw new Error("Unable to parse color from string: "+r);this.model=a.model,t=b[this.model].channels,this.color=a.value.slice(0,t),this.valpha="number"==typeof a.value[t]?a.value[t]:1}else if(r.length){this.model=n||"rgb",t=b[this.model].channels;var o=p.call(r,0,t);this.color=w(o,t),this.valpha="number"==typeof r[t]?r[t]:1}else if("number"==typeof r)r&=16777215,this.model="rgb",this.color=[r>>16&255,r>>8&255,255&r],this.valpha=1;else{this.valpha=1;var l=Object.keys(r);"alpha"in r&&(l.splice(l.indexOf("alpha"),1),this.valpha="number"==typeof r.alpha?r.alpha:0);var i=l.sort().join("");if(!(i in d))throw new Error("Unable to parse color from object: "+JSON.stringify(r));this.model=d[i];var h=b[this.model].labels,s=[];for(e=0;e<h.length;e++)s.push(r[h[e]]);this.color=w(s)}else this.model="rgb",this.color=[0,0,0],this.valpha=1;if(m[this.model])for(t=b[this.model].channels,e=0;e<t;e++){var u=m[this.model][e];u&&(this.color[e]=u(this.color[e]))}this.valpha=Math.max(0,Math.min(1,this.valpha)),Object.freeze&&Object.freeze(this)}function e(e,t,a){return(e=Array.isArray(e)?e:[e]).forEach(function(r){(m[r]||(m[r]=[]))[t]=a}),e=e[0],function(r){var n;return arguments.length?(a&&(r=a(r)),(n=this[e]()).color[t]=r):(n=this[e]().color[t],a&&(n=a(n))),n}}function t(n){return function(r){return Math.max(0,Math.min(n,r))}}function w(r,n){for(var e=0;e<n;e++)"number"!=typeof r[e]&&(r[e]=0);return r}y.prototype={toString:function(){return this.string()},toJSON:function(){return this[this.model]()},string:function(r){var n=this.model in c.to?this:this.rgb(),e=1===(n=n.round("number"==typeof r?r:1)).valpha?n.color:n.color.concat(this.valpha);return c.to[n.model](e)},percentString:function(r){var n=this.rgb().round("number"==typeof r?r:1),e=1===n.valpha?n.color:n.color.concat(this.valpha);return c.to.rgb.percent(e)},array:function(){return 1===this.valpha?this.color.slice():this.color.concat(this.valpha)},object:function(){for(var r={},n=b[this.model].channels,e=b[this.model].labels,t=0;t<n;t++)r[e[t]]=this.color[t];return 1!==this.valpha&&(r.alpha=this.valpha),r},unitArray:function(){var r=this.rgb().color;return r[0]/=255,r[1]/=255,r[2]/=255,1!==this.valpha&&r.push(this.valpha),r},unitObject:function(){var r=this.rgb().object();return r.r/=255,r.g/=255,r.b/=255,1!==this.valpha&&(r.alpha=this.valpha),r},round:function(r){return r=Math.max(r||0,0),new y(this.color.map((e=r,function(r){return n=e,Number(r.toFixed(n));var n})).concat(this.valpha),this.model);var e},alpha:function(r){return arguments.length?new y(this.color.concat(Math.max(0,Math.min(1,r))),this.model):this.valpha},red:e("rgb",0,t(255)),green:e("rgb",1,t(255)),blue:e("rgb",2,t(255)),hue:e(["hsl","hsv","hsl","hwb","hcg"],0,function(r){return(r%360+360)%360}),saturationl:e("hsl",1,t(100)),lightness:e("hsl",2,t(100)),saturationv:e("hsv",1,t(100)),value:e("hsv",2,t(100)),chroma:e("hcg",1,t(100)),gray:e("hcg",2,t(100)),white:e("hwb",1,t(100)),wblack:e("hwb",2,t(100)),cyan:e("cmyk",0,t(100)),magenta:e("cmyk",1,t(100)),yellow:e("cmyk",2,t(100)),black:e("cmyk",3,t(100)),x:e("xyz",0,t(100)),y:e("xyz",1,t(100)),z:e("xyz",2,t(100)),l:e("lab",0,t(100)),a:e("lab",1),b:e("lab",2),keyword:function(r){return arguments.length?new y(r):b[this.model].keyword(this.color)},hex:function(r){return arguments.length?new y(r):c.to.hex(this.rgb().round().color)},rgbNumber:function(){var r=this.rgb().color;return(255&r[0])<<16|(255&r[1])<<8|255&r[2]},luminosity:function(){for(var r=this.rgb().color,n=[],e=0;e<r.length;e++){var t=r[e]/255;n[e]=t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4)}return.2126*n[0]+.7152*n[1]+.0722*n[2]},contrast:function(r){var n=this.luminosity(),e=r.luminosity();return e<n?(n+.05)/(e+.05):(e+.05)/(n+.05)},level:function(r){var n=this.contrast(r);return 7.1<=n?"AAA":4.5<=n?"AA":""},isDark:function(){var r=this.rgb().color;return(299*r[0]+587*r[1]+114*r[2])/1e3<128},isLight:function(){return!this.isDark()},negate:function(){for(var r=this.rgb(),n=0;n<3;n++)r.color[n]=255-r.color[n];return r},lighten:function(r){var n=this.hsl();return n.color[2]+=n.color[2]*r,n},darken:function(r){var n=this.hsl();return n.color[2]-=n.color[2]*r,n},saturate:function(r){var n=this.hsl();return n.color[1]+=n.color[1]*r,n},desaturate:function(r){var n=this.hsl();return n.color[1]-=n.color[1]*r,n},whiten:function(r){var n=this.hwb();return n.color[1]+=n.color[1]*r,n},blacken:function(r){var n=this.hwb();return n.color[2]+=n.color[2]*r,n},grayscale:function(){var r=this.rgb().color,n=.3*r[0]+.59*r[1]+.11*r[2];return y.rgb(n,n,n)},fade:function(r){return this.alpha(this.valpha-this.valpha*r)},opaquer:function(r){return this.alpha(this.valpha+this.valpha*r)},rotate:function(r){var n=this.hsl(),e=n.color[0];return e=(e=(e+r)%360)<0?360+e:e,n.color[0]=e,n},mix:function(r,n){var e=r.rgb(),t=this.rgb(),a=void 0===n?.5:n,o=2*a-1,l=e.alpha()-t.alpha(),i=((o*l==-1?o:(o+l)/(1+o*l))+1)/2,h=1-i;return y.rgb(i*e.red()+h*t.red(),i*e.green()+h*t.green(),i*e.blue()+h*t.blue(),e.alpha()*a+t.alpha()*(1-a))}},Object.keys(b).forEach(function(e){if(-1===v.indexOf(e)){var t=b[e].channels;y.prototype[e]=function(){if(this.model===e)return new y(this);if(arguments.length)return new y(arguments,e);var r,n="number"==typeof arguments[t]?t:this.valpha;return new y((r=b[this.model][e].raw(this.color),Array.isArray(r)?r:[r]).concat(n),e)},y[e]=function(r){return"number"==typeof r&&(r=w(p.call(arguments),t)),new y(r,e)}}});var M=y;var k=function(r,n,e){return r*(1-e)+n*e};return{name:"color",test:function(r){return"string"==typeof r&&(0<=r.indexOf("rgb")||0<=r.indexOf("#")||0<=r.indexOf("hsl")||c.get.rgb(r))},initialize:function(r,n){return{data:{format:(0<=r.indexOf("rgba")?"rgba":0<=r.indexOf("rgb")&&"rgb")||0<=r.indexOf("#")&&"hex"||M(r).model},startValue:M(r).rgb(),destValue:M(n).rgb()}},interpolate:function(r,n,e,t){var a=k(r.color[0],n.color[0],e),o=k(r.color[1],n.color[1],e),l=k(r.color[2],n.color[2],e),i=k(r.valpha,n.valpha,e),h=M.rgb(a,o,l,i)["rgba"===t.format?"rgb":t.format]();return"string"==typeof h?h:h.string()}}});