MIDI.js/build/MIDI.min.js

1 line
64 KiB
JavaScript
Raw Normal View History

2012-11-21 11:12:37 +01:00
if(typeof Color=="undefined")var Color={};typeof Color.Space=="undefined"&&(Color.Space={}),function(){"use strict";var useEval=!1,functions={},shortcuts={"HEX24>HSL":"HEX24>RGB>HSL","HEX32>HSLA":"HEX32>RGBA>HSLA","HEX24>CMYK":"HEX24>RGB>CMY>CMYK","RGB>CMYK":"RGB>CMY>CMYK"},root=Color.Space=function(color,route){shortcuts[route]&&(route=shortcuts[route]);var r=route.split(">");if(typeof color=="object"&&color[0]>=0){var type=r[0],tmp={};for(var i=0;i<type.length;i++){var str=type.substr(i,1);tmp[str]=color[i]}color=tmp}if(functions[route])return functions[route](color);var f="color";for(var pos=1,key=r[0];pos<r.length;pos++)pos>1&&(key=key.substr(key.indexOf("_")+1)),key+=(pos===0?"":"_")+r[pos],color=root[key](color),useEval&&(f="Color.Space."+key+"("+f+")");return useEval&&(functions[route]=eval("(function(color) { return "+f+" })")),color};root.RGB_W3=function(e){return"rgb("+(e.R>>0)+","+(e.G>>0)+","+(e.B>>0)+")"},root.RGBA_W3=function(e){var t=typeof e.A=="number"?e.A/255:1;return"rgba("+(e.R>>0)+","+(e.G>>0)+","+(e.B>>0)+","+t+")"},root.W3_RGB=function(e){var e=e.substr(4,e.length-5).split(",");return{R:parseInt(e[0]),G:parseInt(e[1]),B:parseInt(e[2])}},root.W3_RGBA=function(e){var e=e.substr(5,e.length-6).split(",");return{R:parseInt(e[0]),G:parseInt(e[1]),B:parseInt(e[2]),A:parseFloat(e[3])*255}},root.HSL_W3=function(e){return"hsl("+(e.H+.5>>0)+","+(e.S+.5>>0)+"%,"+(e.L+.5>>0)+"%)"},root.HSLA_W3=function(e){var t=typeof e.A=="number"?e.A/255:1;return"hsla("+(e.H+.5>>0)+","+(e.S+.5>>0)+"%,"+(e.L+.5>>0)+"%,"+t+")"},root.W3_HSL=function(e){var e=e.substr(4,e.length-5).split(",");return{H:parseInt(e[0]),S:parseInt(e[1]),L:parseInt(e[2])}},root.W3_HSLA=function(e){var e=e.substr(5,e.length-6).split(",");return{H:parseInt(e[0]),S:parseInt(e[1]),L:parseInt(e[2]),A:parseFloat(e[3])*255}},root.W3_HEX=root.W3_HEX24=function(e){return e.substr(0,1)==="#"&&(e=e.substr(1)),e.length===3&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),parseInt("0x"+e)},root.W3_HEX32=function(e){return e.substr(0,1)==="#"&&(e=e.substr(1)),e.length===6?parseInt("0xFF"+e):parseInt("0x"+e)},root.HEX_W3=root.HEX24_W3=function(e,t){t||(t=6),e||(e=0);var n=e.toString(16),r=n.length;while(r<t)n="0"+n,r++;var r=n.length;while(r>t)n=n.substr(1),r--;return"#"+n},root.HEX32_W3=function(e){return root.HEX_W3(e,8)},root.HEX_RGB=root.HEX24_RGB=function(e){return{R:e>>16,G:e>>8&255,B:e&255}},root.HEX32_RGBA=function(e){return{R:e>>>16&255,G:e>>>8&255,B:e&255,A:e>>>24}},root.RGBA_HEX32=function(e){return(e.A<<24|e.R<<16|e.G<<8|e.B)>>>0},root.RGB_HEX24=root.RGB_HEX=function(e){return e.R<0&&(e.R=0),e.G<0&&(e.G=0),e.B<0&&(e.B=0),e.R>255&&(e.R=255),e.G>255&&(e.G=255),e.B>255&&(e.B=255),e.R<<16|e.G<<8|e.B},root.RGB_CMY=function(e){return{C:1-e.R/255,M:1-e.G/255,Y:1-e.B/255}},root.RGBA_HSLA=root.RGB_HSL=function(e){var t=e.R/255,n=e.G/255,r=e.B/255,i=Math.min(t,n,r),s=Math.max(t,n,r),o=s-i,u,a,f=(s+i)/2;if(o===0)u=0,a=0;else{f<.5?a=o/(s+i):a=o/(2-s-i);var l=((s-t)/6+o/2)/o,c=((s-n)/6+o/2)/o,h=((s-r)/6+o/2)/o;t===s?u=h-c:n===s?u=1/3+l-h:r===s&&(u=2/3+c-l),u<0&&(u+=1),u>1&&(u-=1)}return{H:u*360,S:a*100,L:f*100,A:e.A}},root.RGBA_HSVA=root.RGB_HSV=function(e){var t=e.R/255,n=e.G/255,r=e.B/255,i=Math.min(t,n,r),s=Math.max(t,n,r),o=s-i,u,a,f=s;if(o===0)u=0,a=0;else{a=o/s;var l=((s-t)/6+o/2)/o,c=((s-n)/6+o/2)/o,h=((s-r)/6+o/2)/o;t===s?u=h-c:n===s?u=1/3+l-h:r===s&&(u=2/3+c-l),u<0&&(u+=1),u>1&&(u-=1)}return{H:u*360,S:a*100,V:f*100,A:e.A}},root.CMY_RGB=function(e){return{R:Math.max(0,(1-e.C)*255),G:Math.max(0,(1-e.M)*255),B:Math.max(0,(1-e.Y)*255)}},root.CMY_CMYK=function(e){var t=e.C,n=e.M,r=e.Y,i=Math.min(r,Math.min(n,Math.min(t,1)));return t=Math.round((t-i)/(1-i)*100),n=Math.round((n-i)/(1-i)*100),r=Math.round((r-i)/(1-i)*100),i=Math.round(i*100),{C:t,M:n,Y:r,K:i}},root.CMYK_CMY=function(e){return{C:e.C*(1-e.K)+e.K,M:e.M*(1-e.K)+e.K,Y:e.Y*(1-e.K)+e.K}},root.HSLA_RGBA=root.HSL_RGB=function(e){var t=e.H/360,n=e.S/100,r=e.L/100,i,s,o,u,a,f;return n===0?i=s=o=r:(r<.5?a=r*(1+n):a=r+n-n*r,u=2*r-a,f=t+1/3,f<0&&(f+=1),f>1&&(f-=1),6*f<1?i=u+(a-u)*6*f:2*f<1?i=a:3*f<2?i=u+(a-u)*(2/3-f)*6:i=u,f=