From aad98bcdbe81c4f81905baaa2c0228942299a2fd Mon Sep 17 00:00:00 2001 From: Kushagra Gour Date: Wed, 17 May 2017 10:14:54 +0530 Subject: [PATCH] add unminified inlet js without slider code. fixes #115 --- src/lib/inlet.min.js | 1147 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 1146 insertions(+), 1 deletion(-) diff --git a/src/lib/inlet.min.js b/src/lib/inlet.min.js index 32d184d..de4b11c 100644 --- a/src/lib/inlet.min.js +++ b/src/lib/inlet.min.js @@ -1,2 +1,1147 @@ // Generated by CoffeeScript 1.10.0 -((function(){var a,b,c,d,e,f,g,h,i,j,k,l,m=[].slice;g=function(a,b,c){return c=c<0?c+1:c>1?c-1:c,c*6<1?a+(b-a)*c*6:c*2<1?b:c*3<2?a+(b-a)*(.66666-c)*6:a},f=function(a,b,c){var d,e;return e=c<=.5?c*(b+1):c+b-c*b,d=c*2-e,{r:g(d,e,a+.33333),g:g(d,e,a),b:g(d,e,a-.33333)}},k=function(a,b,c){var d,e,f,g,h,i,j;return g=Math.max(a,b,c),h=Math.min(a,b,c),d=g-h,j=g+h,e=h===g?0:a===g?(60*(b-c)/d+360)%360:b===g?60*(c-a)/d+120:60*(a-b)/d+240,f=j/2,i=f===0?0:f===1?1:f<=.5?d/j:d/(2-j),{h:e,s:i,l:f}},e=function(a,b,c,e){return e!=null?"hsla("+d(Math.round(a*180/Math.PI),360)+","+Math.round(b*100)+"%,"+Math.round(c*100)+"%,"+e+")":"hsl("+d(Math.round(a*180/Math.PI),360)+","+Math.round(b*100)+"%,"+Math.round(c*100)+"%)"},c=function(a){var b,c,d,e,f,g;return g=document.createElement("span"),document.body.appendChild(g),g.style.backgroundColor=a,f=getComputedStyle(g).backgroundColor,document.body.removeChild(g),d=/^rgb\((\d+), (\d+), (\d+)\)$/.exec(f),d||(d=/^rgba\((\d+), (\d+), (\d+), ([\d.]+)\)$/.exec(f)),e=parseInt(d[1]),c=parseInt(d[2]),b=parseInt(d[3]),d[4]?{r:e/255,g:c/255,b:b/255,a:parseFloat(d[4])}:{r:e/255,g:c/255,b:b/255}},h=function(a){var b,c;return c=document.createElement("span"),document.body.appendChild(c),c.style.backgroundColor=a,b=c.style.backgroundColor.length>0,c.remove(),b},l=function(a,b){var c,d;for(c in b)d=b[c],a.style[c]=d;return a},d=function(a,b){return a%=b,a<0&&(a+=b),a},i=function(a,b,c){return b+(c-b)*Math.min(1,Math.max(0,a))},a=function(){function a(a,b,c){var d,e,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y;this.radius=a,this.width=b,this.lightness=c,r=this.radius,w=this.width,e=this.canvas=document.createElement("canvas"),e.width=e.height=r*2,g=e.getContext("2d"),o=g.createImageData(e.width,e.height),i=o.data;for(y=n=0,s=e.height;0<=s?ns;y=0<=s?++n:--n)for(x=p=0,t=e.width;0<=t?pt;x=0<=t?++p:--p){k=y-r,j=x-r,h=Math.sqrt(k*k+j*j);if(h>r+1.5)continue;h-=10,v=Math.max(0,Math.min(1,h/(r-w/2-10))),m=Math.atan2(k,j)/(Math.PI*2),u=f(m,v,this.lightness),q=u.r,l=u.g,d=u.b,i[(y*e.width+x)*4+0]=q*255,i[(y*e.width+x)*4+1]=l*255,i[(y*e.width+x)*4+2]=d*255,i[(y*e.width+x)*4+3]=255}g.putImageData(o,0,0)}return a.prototype.drawHSLCircle=function(a,b){var c,d,e,f;return a.width=a.height=2*this.radius,c=a.getContext("2d"),f=this.width,e=this.radius,d=i(b,f,e),c.save(),c.fillStyle="rgba(0,0,0,0.3)",c.beginPath(),c.arc(e,e,e,0,Math.PI*2),c.fill(),c.fillStyle="black",c.beginPath(),c.arc(e,e,d,0,Math.PI*2),c.arc(e,e,d-f,0,Math.PI*2,!0),c.fill(),c.globalCompositeOperation="source-in",c.drawImage(this.canvas,0,0),c.restore()},a}(),j=function(a){return typeof a=="string"&&(a=c(a)),a.r!=null&&a.g!=null&&a.b!=null?(a=k(a.r,a.g,a.b),a.h=a.h*Math.PI/180):a.h!=null&&a.s!=null&&a.l!=null&&(a.h=a.h*Math.PI/180),a},b=function(){function s(a){this.color=j(a),this.refColor=this.color,this.el=p(),this.circleContainer=this.el.appendChild(g.call(this)),this.lSlider=this.el.appendChild(o.call(this)),this.colorPreview=this.el.appendChild(h.call(this)),b.call(this),this.setLightness(this.color.l)}var b,g,h,n,o,p,q,r;return q=80,r=25,s.prototype.setHue=function(a){var b,c,d;return this.color.h=a,d=i(this.color.s,r,q)-r/2,c=q-r/2,l(this.hueKnob,{left:Math.round(c+Math.cos(a)*d+6-1)+"px",top:Math.round(c+Math.sin(a)*d+6-1)+"px"}),this.colorPreview.style.backgroundColor=this.lKnob.style.backgroundColor=this.hueKnob.style.backgroundColor=e(this.color.h,this.color.s,this.color.l),b=e(this.color.h,this.color.s,.5),this.lSlider.style.backgroundImage="-webkit-linear-gradient(bottom, black, "+b+" 50%, white)",this.lSlider.style.backgroundImage="-moz-linear-gradient(bottom, black, "+b+" 50%, white)",this.emit("changed")},s.prototype.setSaturation=function(a){return this.color.s=a,this.circle.drawHSLCircle(this.circleCanvas,a),this.setHue(this.color.h)},s.prototype.setLightness=function(b){return this.color.l=b,this.circle=new a(q,r,b),this.lKnob.style.top=(1-b)*this.lSlider._height-11+"px",this.setSaturation(this.color.s)},s.prototype.setHSL=function(a,b,c){return this.color.h=d(a,360)*Math.PI/180,this.color.s=Math.max(0,Math.min(1,b)),c=Math.max(0,Math.min(1,c)),this.setLightness(c)},s.prototype.getHSL=function(){return{h:d(this.color.h*180/Math.PI,360),s:this.color.s,l:this.color.l}},s.prototype.setRGB=function(a,b,c){var d,e,f,g;return f=k(a,b,c),d=f.h,g=f.s,e=f.l,this.setHSL(d,g,e)},s.prototype.getRGB=function(){return f(this.color.h/(Math.PI*2),this.color.s,this.color.l)},s.prototype.getCSS=function(){return e(this.color.h,this.color.s,this.color.l)},s.prototype.setCSS=function(a){var b,d,e,f;return f=c(a),e=f.r,d=f.g,b=f.b,this.setRGB(e,d,b)},s.prototype.on=function(a,b){var c;return this._listeners==null&&(this._listeners={}),((c=this._listeners)[a]!=null?c[a]:c[a]=[]).push(b)},s.prototype.emit=function(){var a,b,c,d,e,f,g,h;b=arguments[0],a=2<=arguments.length?m.call(arguments,1):[];if(this._listeners){g=(f=this._listeners[b])!=null?f:[],h=[];for(c=0,e=g.length;c=7*Math.PI/8||h<=-7*Math.PI/8)return a.style.cursor="ew-resize";if(Math.PI/8<=h&&h<3*Math.PI/8||-7*Math.PI/8HSL":"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;i1&&(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(a){return"rgb("+(a.R>>0)+","+(a.G>>0)+","+(a.B>>0)+")"},root.RGBA_W3=function(a){var b=typeof a.A=="number"?a.A/255:1;return"rgba("+(a.R>>0)+","+(a.G>>0)+","+(a.B>>0)+","+b+")"},root.W3_RGB=function(a){return a=a.substr(4,a.length-5).split(","),{R:parseInt(a[0],10),G:parseInt(a[1],10),B:parseInt(a[2],10)}},root.W3_RGBA=function(a){return a=a.substr(5,a.length-6).split(","),{R:parseInt(a[0],10),G:parseInt(a[1],10),B:parseInt(a[2],10),A:parseFloat(a[3])*255}},root.HSL_W3=function(a){return"hsl("+(a.H+.5>>0)+","+(a.S+.5>>0)+"%,"+(a.L+.5>>0)+"%)"},root.HSLA_W3=function(a){var b=typeof a.A=="number"?a.A/255:1;return"hsla("+(a.H+.5>>0)+","+(a.S+.5>>0)+"%,"+(a.L+.5>>0)+"%,"+b+")"},root.W3_HSL=function(a){var b=a.indexOf("(")+1,c=a.indexOf(")");return a=a.substr(b,c-b).split(","),{H:parseInt(a[0],10),S:parseInt(a[1],10),L:parseInt(a[2],10)}},root.W3_HSLA=function(a){var b=a.indexOf("(")+1,c=a.indexOf(")");return a=a.substr(b,c-b).split(","),{H:parseInt(a[0],10),S:parseInt(a[1],10),L:parseInt(a[2],10),A:parseFloat(a[3],10)*255}},root.W3_HEX=root.W3_HEX24=function(a){return a.substr(0,1)==="#"&&(a=a.substr(1)),a.length===3&&(a=a[0]+a[0]+a[1]+a[1]+a[2]+a[2]),parseInt("0x"+a,16)},root.W3_HEX32=function(a){return a.substr(0,1)==="#"&&(a=a.substr(1)),a.length===6?parseInt("0xFF"+a,10):parseInt("0x"+a,16)},root.HEX_W3=root.HEX24_W3=function(a,b){b||(b=6),a||(a=0);var c,d=a.toString(16);c=d.length;while(cb)d=d.substr(1),c--;return"#"+d},root.HEX32_W3=function(a){return root.HEX_W3(a,8)},root.HEX_RGB=root.HEX24_RGB=function(a){return{R:a>>16,G:a>>8&255,B:a&255}},root.HEX32_RGBA=function(a){return{R:a>>>16&255,G:a>>>8&255,B:a&255,A:a>>>24}},root.RGBA_HEX32=function(a){return(a.A<<24|a.R<<16|a.G<<8|a.B)>>>0},root.RGB_HEX24=root.RGB_HEX=function(a){return a.R<0&&(a.R=0),a.G<0&&(a.G=0),a.B<0&&(a.B=0),a.R>255&&(a.R=255),a.G>255&&(a.G=255),a.B>255&&(a.B=255),a.R<<16|a.G<<8|a.B},root.RGB_CMY=function(a){return{C:1-a.R/255,M:1-a.G/255,Y:1-a.B/255}},root.RGBA_HSLA=root.RGB_HSL=function(a){var b=a.R/255,c=a.G/255,d=a.B/255,e=Math.min(b,c,d),f=Math.max(b,c,d),g=f-e,h,i,j=(f+e)/2;if(g===0)h=0,i=0;else{j<.5?i=g/(f+e):i=g/(2-f-e);var k=((f-b)/6+g/2)/g,l=((f-c)/6+g/2)/g,m=((f-d)/6+g/2)/g;b===f?h=m-l:c===f?h=1/3+k-m:d===f&&(h=2/3+l-k),h<0&&(h+=1),h>1&&(h-=1)}return{H:h*360,S:i*100,L:j*100,A:a.A}},root.RGBA_HSVA=root.RGB_HSV=function(a){var b=a.R/255,c=a.G/255,d=a.B/255,e=Math.min(b,c,d),f=Math.max(b,c,d),g=f-e,h,i,j=f;if(g===0)h=0,i=0;else{i=g/f;var k=((f-b)/6+g/2)/g,l=((f-c)/6+g/2)/g,m=((f-d)/6+g/2)/g;b===f?h=m-l:c===f?h=1/3+k-m:d===f&&(h=2/3+l-k),h<0&&(h+=1),h>1&&(h-=1)}return{H:h*360,S:i*100,V:j*100,A:a.A}},root.CMY_RGB=function(a){return{R:Math.max(0,(1-a.C)*255),G:Math.max(0,(1-a.M)*255),B:Math.max(0,(1-a.Y)*255)}},root.CMY_CMYK=function(a){var b=a.C,c=a.M,d=a.Y,e=Math.min(d,Math.min(c,Math.min(b,1)));return b=Math.round((b-e)/(1-e)*100),c=Math.round((c-e)/(1-e)*100),d=Math.round((d-e)/(1-e)*100),e=Math.round(e*100),{C:b,M:c,Y:d,K:e}},root.CMYK_CMY=function(a){return{C:a.C*(1-a.K)+a.K,M:a.M*(1-a.K)+a.K,Y:a.Y*(1-a.K)+a.K}},root.HSLA_RGBA=root.HSL_RGB=function(a){var b=a.H/360,c=a.S/100,d=a.L/100,e,f,g,h,i,j;return c===0?e=f=g=d:(d<.5?i=d*(1+c):i=d+c-c*d,h=2*d-i,j=b+1/3,j<0&&(j+=1),j>1&&(j-=1),6*j<1?e=h+(i-h)*6*j:2*j<1?e=i:3*j<2?e=h+(i-h)*(2/3-j)*6:e=h,j=b,j<0&&(j+=1),j>1&&(j-=1),6*j<1?f=h+(i-h)*6*j:2*j<1?f=i:3*j<2?f=h+(i-h)*(2/3-j)*6:f=h,j=b-1/3,j<0&&(j+=1),j>1&&(j-=1),6*j<1?g=h+(i-h)*6*j:2*j<1?g=i:3*j<2?g=h+(i-h)*(2/3-j)*6:g=h),{R:e*255,G:f*255,B:g*255,A:a.A}},root.HSVA_RGBA=root.HSV_RGB=function(a){var b=a.H/360,c=a.S/100,d=a.V/100,e,f,g,h,i,j;if(c===0)e=f=g=Math.round(d*255);else{b>=1&&(b=0),b=6*b,h=b-Math.floor(b),i=Math.round(255*d*(1-c)),g=Math.round(255*d*(1-c*h)),j=Math.round(255*d*(1-c*(1-h))),d=Math.round(255*d);switch(Math.floor(b)){case 0:e=d,f=j,g=i;break;case 1:e=g,f=d,g=i;break;case 2:e=i,f=d,g=j;break;case 3:e=i,f=g,g=d;break;case 4:e=j,f=i,g=d;break;case 5:e=d,f=i,g=g}}return{R:e,G:f,B:g,A:a.A}}}(),Inlet=function(){function a(a,c){function w(a){var b=String(g.checked),c=d.getCursor(!0),e=L(c,"boolean");if(!e)return;var f={line:c.line,ch:e.start},h={line:c.line,ch:e.end};d.replaceRange(b,f,h)}function z(a){var b=String(e.value),c=d.getCursor(!0),f=L(c,"number");if(!f)return;var g={line:c.line,ch:f.start},h={line:c.line,ch:f.end};d.dragging=!0,d.replaceRange(b,g,h)}function A(a){e.value=0;var b=d.getCursor(!0),c=L(b,"number");if(!c)return;var f=parseFloat(c.string),g=K(f);e.setAttribute("value",f),e.setAttribute("step",g.step),e.setAttribute("min",g.min),e.setAttribute("max",g.max),e.value=f,d.dragging=!1}function C(a){if(a.target===B||a.target===x||a.target===e||a.target===v||a.target===g)return;x.style.visibility="hidden",v.style.visibility="hidden"}function H(){arguments.length==1?event=arguments[0]:event=arguments[1];if(event.keyCode==D||event.keyCode==G){if(x.style.visibility==="visible")return e.stepDown(1),z(),!0;event.altKey&&J()}else if(event.keyCode==F||event.keyCode==E){if(x.style.visibility==="visible")return e.stepUp(1),z(),!0;event.altKey&&J()}else x.style.visibility="hidden"}function J(a){if(d.somethingSelected())return;B=a.target;var c=d.getCursor(!0),h=d.getTokenAt(c);cursorOffset=d.cursorCoords(!0,"page");var o=d.cursorCoords(!0,p).left,q=L(c,"number"),r=L(c,"hsl"),s=L(c,"hex"),t=L(c,"rgb"),u=L(c,"boolean"),y=cursorOffset.top-i;cursorOffset.topHSL>RGB>HEX24>W3"),I(picked,"hex")})}else if(r){var A=r.string;f=new thistle.Picker(A),f.setCSS(A),f.presentModal(z,y),f.on("changed",function(){picked=f.getCSS(),I(picked,"hsl")})}else if(t){var A=t.string;f=new thistle.Picker(A),f.setCSS(A),f.presentModal(z,y),f.on("changed",function(){picked=f.getCSS(),picked=Color.Space(picked,"W3>HSL>RGB>W3"),I(picked,"rgb")})}else if(q){e.value=0;var C=parseFloat(q.string),D=K(C);e.setAttribute("value",C),e.setAttribute("step",D.step),e.setAttribute("min",D.min),e.setAttribute("max",D.max),e.value=C;var E=cursorOffset.top-m,F=window.getComputedStyle(x),G=b(F.width),H=o-G/2+n;x.style.top=E-10+"px",x.style.left=H+"px",x.style.visibility="visible"}else if(u){var J=cursorOffset.top-m,M=window.getComputedStyle(v),N=b(M.width),O=o-N/2+n,C=JSON.parse(u.string);C?(v.removeChild(g),g=document.createElement("input"),g.className="checkbox",g.setAttribute("type","checkbox"),g.setAttribute("checked","checked"),g.addEventListener("change",w),v.appendChild(g)):(v.removeChild(g),g=document.createElement("input"),g.className="checkbox",g.setAttribute("type","checkbox"),g.addEventListener("change",w),v.appendChild(g)),v.style.top=J-3+"px",v.style.left=O+"px",v.style.visibility="visible"}}function K(a){var b,c,d,e;return a===0?b=[-100,100]:b=[-a*3,a*5],b[0]20?c=1:c=(max-min)/200,{min:min,max:max,step:c}}function L(a,b){if(!b)return;var c;switch(b.toLowerCase()){case"boolean":c=/true|false/g;break;case"hsl":c=/hsla?\(\s*(\d{1,3})\s*,\s*(\d{1,3}\%)\s*,\s*(\d{1,3}\%)\s*(?:\s*,\s*(\d+(?:\.\d+)?)\s*)?\)/g;break;case"rgb":c=/rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)/g;break;case"hex":c=/#[a-fA-F0-9]{3,6}/g;break;case"number":c=/[-]?\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g;break;default:throw new Error("invalid match selection")}var e=d.getLine(a.line),f=c.exec(e);while(f){var g=f[0],h=g.length,i=f.index,j=f.index+h;if(a.ch>=i&&a.ch<=j)return f=null,{start:i,end:j,string:g};f=c.exec(e)}return}var d=a,e,f,g;c||(c={}),c.picker||(c.picker={}),c.slider||(c.slider={}),c.clicker||(c.clicker={});var h=c.container||document.body,i=c.picker.topOffset||220,j=c.picker.bottomOffset||16,k=c.picker.topBoundary||250,l=c.picker.leftOffset||75,m=c.slider.yOffset||15,n=c.slider.xOffset||0,o=c.slider.width,p=c.horizontalMode||"page",q=c.fixedContainer,r=c.slider.callback||function(a){},s=c.picker.callback||function(a){},t=c.clicker.callback||function(a){},u=d.getWrapperElement();u.addEventListener("mouseup",J),document.body.addEventListener("mouseup",C),d.setOption("onKeyEvent",H);var v=document.createElement("div");v.className="inlet_clicker",v.style.visibility="hidden",v.style.position="absolute",h.appendChild(v);var g=document.createElement("input");g.className="checkbox",g.setAttribute("type","checkbox"),g.addEventListener("change",w),v.appendChild(g);var x=document.createElement("div");x.className="inlet_slider",x.style.visibility="hidden",o&&(x.style.width=o),q?x.style.position="fixed":x.style.position="absolute",x.style.top=0,h.appendChild(x);var e=document.createElement("input");e.className="range",e.setAttribute("type","range"),e.addEventListener("input",z),e.addEventListener("change",z);var y=navigator.userAgent.toLowerCase().indexOf("firefox")>-1;y||e.addEventListener("mouseup",A),x.appendChild(e);var B,D=37,E=38,F=39,G=40,I=function(a,b){var c=d.getCursor();if(!b)return;var e=L(c,b),f={line:c.line,ch:e.start},g={line:c.line,ch:e.end};d.picking=!0,d.replaceRange(a,f,g),setTimeout(function(){d.picking=!1},100)};f=new thistle.Picker("#ffffff")}function b(a){var b=0;return a.length>2&&(b=parseFloat(a.slice(0,a.length-2))),b||(b=0),b}function c(a){var b=0,c=0;while(a&&!isNaN(a.offsetLeft)&&!isNaN(a.offsetTop))b+=a.offsetLeft-a.scrollLeft,c+=a.offsetTop-a.scrollTop,a=a.offsetParent;return{top:c,left:b}}return a}(); \ No newline at end of file +((function() { + var HSLCircle, Picker, cssColorToRGB, fmod, hslToCSS, hslToRGB, hueToRGB, isValidCSSColor, map, normalizeColor, rgbToHSL, style, slice = [].slice; + hueToRGB = function(m1, m2, h) { + h = h < 0 ? h + 1 : h > 1 ? h - 1 : h; + if (h * 6 < 1) { + return m1 + (m2 - m1) * h * 6; + } + if (h * 2 < 1) { + return m2; + } + if (h * 3 < 2) { + return m1 + (m2 - m1) * (.66666 - h) * 6; + } + return m1; + }; + hslToRGB = function(h, s, l) { + var m1, m2; + m2 = l <= .5 ? l * (s + 1) : l + s - l * s; + m1 = l * 2 - m2; + return { + r: hueToRGB(m1, m2, h + .33333), + g: hueToRGB(m1, m2, h), + b: hueToRGB(m1, m2, h - .33333) + }; + }; + rgbToHSL = function(r, g, b) { + var diff, h, l, max, min, s, sum; + max = Math.max(r, g, b); + min = Math.min(r, g, b); + diff = max - min; + sum = max + min; + h = min === max ? 0 : r === max ? (60 * (g - b) / diff + 360) % 360 : g === max ? 60 * (b - r) / diff + 120 : 60 * (r - g) / diff + 240; + l = sum / 2; + s = l === 0 ? 0 : l === 1 ? 1 : l <= .5 ? diff / sum : diff / (2 - sum); + return { + h: h, + s: s, + l: l + }; + }; + hslToCSS = function(h, s, l, a) { + if (a != null) { + return "hsla(" + fmod(Math.round(h * 180 / Math.PI), 360) + "," + Math.round(s * 100) + "%," + Math.round(l * 100) + "%," + a + ")"; + } else { + return "hsl(" + fmod(Math.round(h * 180 / Math.PI), 360) + "," + Math.round(s * 100) + "%," + Math.round(l * 100) + "%)"; + } + }; + cssColorToRGB = function(cssColor) { + var b, g, m, r, rgb, s; + s = document.createElement("span"); + document.body.appendChild(s); + s.style.backgroundColor = cssColor; + rgb = getComputedStyle(s).backgroundColor; + document.body.removeChild(s); + m = /^rgb\((\d+), (\d+), (\d+)\)$/.exec(rgb); + if (!m) { + m = /^rgba\((\d+), (\d+), (\d+), ([\d.]+)\)$/.exec(rgb); + } + r = parseInt(m[1]); + g = parseInt(m[2]); + b = parseInt(m[3]); + if (m[4]) { + return { + r: r / 255, + g: g / 255, + b: b / 255, + a: parseFloat(m[4]) + }; + } + return { + r: r / 255, + g: g / 255, + b: b / 255 + }; + }; + isValidCSSColor = function(cssColor) { + var ret, s; + s = document.createElement("span"); + document.body.appendChild(s); + s.style.backgroundColor = cssColor; + ret = s.style.backgroundColor.length > 0; + s.remove(); + return ret; + }; + style = function(tag, styles) { + var n, v; + for (n in styles) { + v = styles[n]; + tag.style[n] = v; + } + return tag; + }; + fmod = function(x, m) { + x = x % m; + if (x < 0) { + x += m; + } + return x; + }; + map = function(v, min, max) { + return min + (max - min) * Math.min(1, Math.max(0, v)); + }; + HSLCircle = function() { + function HSLCircle(radius1, width1, lightness) { + var b, canvas, ctx, d, data, dx, dy, g, h, i, imgdata, j, r, radius, ref, ref1, ref2, s, width, x, y; + this.radius = radius1; + this.width = width1; + this.lightness = lightness; + radius = this.radius; + width = this.width; + canvas = this.canvas = document.createElement("canvas"); + canvas.width = canvas.height = radius * 2; + ctx = canvas.getContext("2d"); + imgdata = ctx.createImageData(canvas.width, canvas.height); + data = imgdata.data; + for (y = i = 0, ref = canvas.height; 0 <= ref ? i < ref : i > ref; y = 0 <= ref ? ++i : --i) { + for (x = j = 0, ref1 = canvas.width; 0 <= ref1 ? j < ref1 : j > ref1; x = 0 <= ref1 ? ++j : --j) { + dy = y - radius; + dx = x - radius; + d = Math.sqrt(dy * dy + dx * dx); + if (d > radius + 1.5) { + continue; + } + d -= 10; + s = Math.max(0, Math.min(1, d / (radius - width / 2 - 10))); + h = Math.atan2(dy, dx) / (Math.PI * 2); + ref2 = hslToRGB(h, s, this.lightness), r = ref2.r, g = ref2.g, b = ref2.b; + data[(y * canvas.width + x) * 4 + 0] = r * 255; + data[(y * canvas.width + x) * 4 + 1] = g * 255; + data[(y * canvas.width + x) * 4 + 2] = b * 255; + data[(y * canvas.width + x) * 4 + 3] = 255; + } + } + ctx.putImageData(imgdata, 0, 0); + } + HSLCircle.prototype.drawHSLCircle = function(canvas, saturation) { + var ctx, highlighted_r, radius, width; + canvas.width = canvas.height = 2 * this.radius; + ctx = canvas.getContext("2d"); + width = this.width; + radius = this.radius; + highlighted_r = map(saturation, width, radius); + ctx.save(); + ctx.fillStyle = "rgba(0,0,0,0.3)"; + ctx.beginPath(); + ctx.arc(radius, radius, radius, 0, Math.PI * 2); + ctx.fill(); + ctx.fillStyle = "black"; + ctx.beginPath(); + ctx.arc(radius, radius, highlighted_r, 0, Math.PI * 2); + ctx.arc(radius, radius, highlighted_r - width, 0, Math.PI * 2, true); + ctx.fill(); + ctx.globalCompositeOperation = "source-in"; + ctx.drawImage(this.canvas, 0, 0); + return ctx.restore(); + }; + return HSLCircle; + }(); + normalizeColor = function(color) { + if (typeof color === "string") { + color = cssColorToRGB(color); + } + if (color.r != null && color.g != null && color.b != null) { + color = rgbToHSL(color.r, color.g, color.b); + color.h = color.h * Math.PI / 180; + } else if (color.h != null && color.s != null && color.l != null) { + color.h = color.h * Math.PI / 180; + } + return color; + }; + Picker = function() { + var attachEvents, makeCircle, makeColorPreview, makeKnob, makeLightnessSlider, makeRoot, radius, width; + radius = 80; + width = 25; + function Picker(color) { + this.color = normalizeColor(color); + this.refColor = this.color; + this.el = makeRoot(); + this.circleContainer = this.el.appendChild(makeCircle.call(this)); + this.lSlider = this.el.appendChild(makeLightnessSlider.call(this)); + this.colorPreview = this.el.appendChild(makeColorPreview.call(this)); + attachEvents.call(this); + this.setLightness(this.color.l); + } + Picker.prototype.setHue = function(h) { + var b, oR, r; + this.color.h = h; + r = map(this.color.s, width, radius) - width / 2; + oR = radius - width / 2; + style(this.hueKnob, { + left: Math.round(oR + Math.cos(h) * r + 6 - 1) + "px", + top: Math.round(oR + Math.sin(h) * r + 6 - 1) + "px" + }); + this.colorPreview.style.backgroundColor = this.lKnob.style.backgroundColor = this.hueKnob.style.backgroundColor = hslToCSS(this.color.h, this.color.s, this.color.l); + b = hslToCSS(this.color.h, this.color.s, .5); + this.lSlider.style.backgroundImage = "-webkit-linear-gradient(bottom, black, " + b + " 50%, white)"; + this.lSlider.style.backgroundImage = "-moz-linear-gradient(bottom, black, " + b + " 50%, white)"; + return this.emit("changed"); + }; + Picker.prototype.setSaturation = function(s) { + this.color.s = s; + this.circle.drawHSLCircle(this.circleCanvas, s); + return this.setHue(this.color.h); + }; + Picker.prototype.setLightness = function(l) { + this.color.l = l; + this.circle = new HSLCircle(radius, width, l); + this.lKnob.style.top = (1 - l) * this.lSlider._height - 11 + "px"; + return this.setSaturation(this.color.s); + }; + Picker.prototype.setHSL = function(h, s, l) { + this.color.h = fmod(h, 360) * Math.PI / 180; + this.color.s = Math.max(0, Math.min(1, s)); + l = Math.max(0, Math.min(1, l)); + return this.setLightness(l); + }; + Picker.prototype.getHSL = function() { + return { + h: fmod(this.color.h * 180 / Math.PI, 360), + s: this.color.s, + l: this.color.l + }; + }; + Picker.prototype.setRGB = function(r, g, b) { + var h, l, ref, s; + ref = rgbToHSL(r, g, b), h = ref.h, s = ref.s, l = ref.l; + return this.setHSL(h, s, l); + }; + Picker.prototype.getRGB = function() { + return hslToRGB(this.color.h / (Math.PI * 2), this.color.s, this.color.l); + }; + Picker.prototype.getCSS = function() { + return hslToCSS(this.color.h, this.color.s, this.color.l); + }; + Picker.prototype.setCSS = function(css) { + var b, g, r, ref; + ref = cssColorToRGB(css), r = ref.r, g = ref.g, b = ref.b; + return this.setRGB(r, g, b); + }; + Picker.prototype.on = function(e, l) { + var base; + if (this._listeners == null) { + this._listeners = {}; + } + return ((base = this._listeners)[e] != null ? base[e] : base[e] = []).push(l); + }; + Picker.prototype.emit = function() { + var args, e, i, l, len, ref, ref1, results; + e = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : []; + if (this._listeners) { + ref1 = (ref = this._listeners[e]) != null ? ref : []; + results = []; + for (i = 0, len = ref1.length; i < len; i++) { + l = ref1[i]; + results.push(l.call.apply(l, [ this ].concat(slice.call(args)))); + } + return results; + } + }; + Picker.prototype.removeListener = function(e, l) { + var k; + if (this._listeners[e]) { + return this._listeners[e] = function() { + var i, len, ref, results; + ref = this._listeners[e]; + results = []; + for (i = 0, len = ref.length; i < len; i++) { + k = ref[i]; + if (k !== l) { + results.push(k); + } + } + return results; + }.call(this); + } + }; + attachEvents = function() { + var c, updateCursor; + this.lKnob.onmousedown = function(_this) { + return function(e) { + var move, up; + document.documentElement.style.cursor = "pointer"; + window.addEventListener("mousemove", move = function(e) { + var r, y; + r = _this.lSlider.getBoundingClientRect(); + y = e.clientY - r.top; + return _this.setLightness(Math.max(0, Math.min(1, 1 - y / _this.lSlider._height))); + }); + window.addEventListener("mouseup", up = function(e) { + window.removeEventListener("mousemove", move); + window.removeEventListener("mouseup", up); + window.removeEventListener("blur", up); + return document.documentElement.style.cursor = ""; + }); + window.addEventListener("blur", up); + e.preventDefault(); + return e.stopPropagation(); + }; + }(this); + c = this.circleContainer; + updateCursor = function(_this) { + return function(e) { + var d, dx, dy, r, t, x, y; + x = e.layerX; + y = e.layerY; + dx = x - radius; + dy = y - radius; + d = Math.sqrt(dx * dx + dy * dy); + t = Math.atan2(dy, dx); + r = map(_this.color.s, width, radius); + if (r - width < d && d < r) { + if (-Math.PI / 8 < t && t < Math.PI / 8 || t >= 7 * Math.PI / 8 || t <= -7 * Math.PI / 8) { + return c.style.cursor = "ew-resize"; + } else if (Math.PI / 8 <= t && t < 3 * Math.PI / 8 || -7 * Math.PI / 8 < t && t <= -5 * Math.PI / 8) { + return c.style.cursor = "nwse-resize"; + } else if (3 * Math.PI / 8 <= t && t < 5 * Math.PI / 8 || -5 * Math.PI / 8 < t && t <= -3 * Math.PI / 8) { + return c.style.cursor = "ns-resize"; + } else if (5 * Math.PI / 8 <= t && t < 7 * Math.PI / 8 || -3 * Math.PI / 8 < t && t <= -Math.PI / 8) { + return c.style.cursor = "nesw-resize"; + } + } else { + return c.style.cursor = ""; + } + }; + }(this); + c.addEventListener("mouseover", function(e) { + var move, out; + updateCursor(e); + c.addEventListener("mousemove", move = function(e) { + return updateCursor(e); + }); + c.addEventListener("mouseout", out = function(e) { + c.style.cursor = ""; + c.removeEventListener("mousemove", move); + c.removeEventListener("mouseout", out); + return window.removeEventListener("blur", out); + }); + return window.addEventListener("blur", out); + }); + c.addEventListener("mousedown", function(_this) { + return function(e) { + var d, dx, dy, move, r, t, up, x, y; + e.preventDefault(); + x = e.layerX; + y = e.layerY; + dx = x - radius; + dy = y - radius; + d = Math.sqrt(dx * dx + dy * dy); + t = Math.atan2(dy, dx); + r = map(_this.color.s, width, radius); + if (!(r - width < d && d < r)) { + return; + } + document.documentElement.style.cursor = c.style.cursor; + window.addEventListener("mousemove", move = function(e) { + var cx, cy, s; + r = _this.circleCanvas.getBoundingClientRect(); + cx = r.left + r.width / 2; + cy = r.top + r.height / 2; + dx = e.clientX - cx; + dy = e.clientY - cy; + d = Math.sqrt(dx * dx + dy * dy); + d -= 10; + s = Math.max(0, Math.min(1, d / (radius - width / 2 - 10))); + return _this.setSaturation(s); + }); + window.addEventListener("mouseup", up = function(e) { + window.removeEventListener("mousemove", move); + window.removeEventListener("mouseup", up); + window.removeEventListener("blur", up); + return document.documentElement.style.cursor = ""; + }); + return window.addEventListener("blur", up); + }; + }(this)); + return this.hueKnob.onmousedown = function(_this) { + return function(e) { + var move, up; + document.documentElement.style.cursor = "pointer"; + window.addEventListener("mousemove", move = function(e) { + var cx, cy, r; + r = _this.circleCanvas.getBoundingClientRect(); + cx = r.left + r.width / 2; + cy = r.top + r.height / 2; + return _this.setHue(Math.atan2(e.clientY - cy, e.clientX - cx)); + }); + window.addEventListener("mouseup", up = function(e) { + window.removeEventListener("mousemove", move); + window.removeEventListener("mouseup", up); + window.removeEventListener("blur", up); + return document.documentElement.style.cursor = ""; + }); + window.addEventListener("blur", up); + e.preventDefault(); + return e.stopPropagation(); + }; + }(this); + }; + makeRoot = function() { + var div; + div = document.createElement("div"); + div.className = "picker"; + style(div, { + display: "inline-block", + background: "hsl(0, 0%, 97%)", + padding: "6px", + borderRadius: "6px", + boxShadow: "1px 1px 5px hsla(0, 0%, 39%, 0.2), hsla(0, 0%, 100%, 0.9) 0px 0px 1em 0.3em inset", + border: "1px solid hsla(0, 0%, 59%, 0.2)", + position: "absolute", + backgroundImage: "-webkit-linear-gradient(left top, hsla(0, 0%, 0%, 0.05) 25%, transparent 25%, transparent 50%, hsla(0, 0%, 0%, 0.05) 50%, hsla(0, 0%, 0%, 0.05) 75%, transparent 75%, transparent)", + backgroundSize: "40px 40px" + }); + style(div, { + backgroundImage: "-moz-linear-gradient(left top, hsla(0, 0%, 0%, 0.05) 25%, transparent 25%, transparent 50%, hsla(0, 0%, 0%, 0.05) 50%, hsla(0, 0%, 0%, 0.05) 75%, transparent 75%, transparent)", + zIndex: "1000" + }); + return div; + }; + makeCircle = function() { + var circleContainer, k; + circleContainer = document.createElement("div"); + style(circleContainer, { + display: "inline-block", + width: radius * 2 + "px", + height: radius * 2 + "px", + borderRadius: radius + "px", + boxShadow: "0px 0px 7px rgba(0,0,0,0.3)" + }); + circleContainer.appendChild(this.circleCanvas = document.createElement("canvas")); + this.hueKnob = k = makeKnob(27); + circleContainer.appendChild(k); + return circleContainer; + }; + makeLightnessSlider = function() { + var k, lSlider; + lSlider = document.createElement("div"); + style(lSlider, { + display: "inline-block", + width: "20px", + height: radius * 2 - 22 + "px", + marginLeft: "6px", + borderRadius: "10px", + boxShadow: "hsla(0, 100%, 100%, 0.1) 0 1px 2px 1px inset, hsla(0, 100%, 100%, 0.2) 0 1px inset, hsla(0, 0%, 0%, 0.4) 0 -1px 1px inset, hsla(0, 0%, 0%, 0.4) 0 1px 1px", + position: "relative", + top: "-11px" + }); + lSlider._height = radius * 2 - 22; + this.lKnob = k = makeKnob(22); + style(k, { + left: "-1px" + }); + lSlider.appendChild(k); + return lSlider; + }; + makeColorPreview = function() { + var colorPreview, originalColor, originalColorTransparent; + colorPreview = document.createElement("div"); + originalColor = hslToCSS(this.refColor.h, this.refColor.s, this.refColor.l); + originalColorTransparent = hslToCSS(this.refColor.h, this.refColor.s, this.refColor.l, 0); + style(colorPreview, { + boxShadow: "hsla(0, 0%, 0%, 0.5) 0 1px 5px, hsla(0, 100%, 100%, 0.4) 0 1px 1px inset, hsla(0, 0%, 0%, 0.3) 0 -1px 1px inset", + height: "25px", + marginTop: "6px", + borderRadius: "3px", + backgroundImage: "-webkit-linear-gradient(-20deg, " + originalColorTransparent + ", " + originalColorTransparent + " 69%, " + originalColor + " 70%, " + originalColor + ")" + }); + style(colorPreview, { + backgroundImage: "-moz-linear-gradient(-20deg, " + originalColorTransparent + ", " + originalColorTransparent + " 69%, " + originalColor + " 70%, " + originalColor + ")" + }); + return colorPreview; + }; + makeKnob = function(size) { + var el; + el = document.createElement("div"); + el.className = "knob"; + style(el, { + position: "absolute", + width: size + "px", + height: size + "px", + backgroundColor: "red", + borderRadius: Math.floor(size / 2) + "px", + cursor: "pointer", + backgroundImage: "-webkit-gradient(radial, 50% 0%, 0, 50% 0%, 15, color-stop(0%, rgba(255, 255, 255, 0.8)), color-stop(100%, rgba(255, 255, 255, 0.2)))", + boxShadow: "white 0px 1px 1px inset, rgba(0, 0, 0, 0.4) 0px -1px 1px inset, rgba(0, 0, 0, 0.4) 0px 1px 4px 0px, rgba(0, 0, 0, 0.6) 0 0 2px" + }); + style(el, { + backgroundImage: "radial-gradient(circle at center top, rgba(255,255,255,0.8), rgba(255, 255, 255, 0.2) 15px" + }); + return el; + }; + Picker.prototype.presentModal = function(x, y) { + var modalFrame; + style(this.el, { + left: x + "px", + top: y - 10 + "px", + opacity: "0", + webkitTransition: "0.15s", + MozTransition: "0.15s" + }); + modalFrame = document.createElement("div"); + modalFrame.style.position = "fixed"; + modalFrame.style.top = modalFrame.style.left = modalFrame.style.bottom = modalFrame.style.right = "0"; + modalFrame.style.zIndex = "999"; + modalFrame.onclick = function(_this) { + return function() { + var end; + document.body.removeChild(modalFrame); + _this.el.style.top = y + 10 + "px"; + _this.el.style.opacity = 0; + end = function() { + document.body.removeChild(_this.el); + _this.el.removeEventListener("webkitTransitionEnd", end); + return _this.el.removeEventListener("transitionend", end); + }; + _this.el.addEventListener("webkitTransitionEnd", end); + _this.el.addEventListener("transitionend", end); + return _this.emit("closed"); + }; + }(this); + document.body.appendChild(modalFrame); + document.body.appendChild(this.el); + this.el.offsetHeight; + this.el.style.opacity = "1"; + this.el.style.top = y + "px"; + return this; + }; + Picker.prototype.presentModalBeneath = function(el) { + var elPos, x, y; + elPos = el.getBoundingClientRect(); + x = elPos.left + window.scrollX; + y = elPos.bottom + window.scrollY + 4; + return this.presentModal(x, y); + }; + return Picker; + }(); + window.thistle = { + Picker: Picker, + isValidCSSColor: isValidCSSColor + }; +})).call(this); + +if (typeof Color === "undefined") var Color = {}; + +if (typeof Color.Space === "undefined") Color.Space = {}; + +(function() { + "use strict"; + var useEval = false; + var functions = {}; + var shortcuts = { + "HEX24>HSL": "HEX24>RGB>HSL", + "HEX32>HSLA": "HEX32>RGBA>HSLA", + "HEX24>CMYK": "HEX24>RGB>CMY>CMYK", + "RGB>CMYK": "RGB>CMY>CMYK" + }; + var root = Color.Space = function(color, route) { + if (shortcuts[route]) { + route = shortcuts[route]; + } + var r = route.split(">"); + if (typeof color === "object" && color[0] >= 0) { + var type = r[0]; + var 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++) { + if (pos > 1) { + key = key.substr(key.indexOf("_") + 1); + } + key += (pos === 0 ? "" : "_") + r[pos]; + color = root[key](color); + if (useEval) { + f = "Color.Space." + key + "(" + f + ")"; + } + } + if (useEval) { + functions[route] = eval("(function(color) { return " + f + " })"); + } + return color; + }; + root.RGB_W3 = function(o) { + return "rgb(" + (o.R >> 0) + "," + (o.G >> 0) + "," + (o.B >> 0) + ")"; + }; + root.RGBA_W3 = function(o) { + var alpha = typeof o.A === "number" ? o.A / 255 : 1; + return "rgba(" + (o.R >> 0) + "," + (o.G >> 0) + "," + (o.B >> 0) + "," + alpha + ")"; + }; + root.W3_RGB = function(o) { + o = o.substr(4, o.length - 5).split(","); + return { + R: parseInt(o[0], 10), + G: parseInt(o[1], 10), + B: parseInt(o[2], 10) + }; + }; + root.W3_RGBA = function(o) { + o = o.substr(5, o.length - 6).split(","); + return { + R: parseInt(o[0], 10), + G: parseInt(o[1], 10), + B: parseInt(o[2], 10), + A: parseFloat(o[3]) * 255 + }; + }; + root.HSL_W3 = function(o) { + return "hsl(" + (o.H + .5 >> 0) + "," + (o.S + .5 >> 0) + "%," + (o.L + .5 >> 0) + "%)"; + }; + root.HSLA_W3 = function(o) { + var alpha = typeof o.A === "number" ? o.A / 255 : 1; + return "hsla(" + (o.H + .5 >> 0) + "," + (o.S + .5 >> 0) + "%," + (o.L + .5 >> 0) + "%," + alpha + ")"; + }; + root.W3_HSL = function(o) { + var start = o.indexOf("(") + 1; + var end = o.indexOf(")"); + o = o.substr(start, end - start).split(","); + return { + H: parseInt(o[0], 10), + S: parseInt(o[1], 10), + L: parseInt(o[2], 10) + }; + }; + root.W3_HSLA = function(o) { + var start = o.indexOf("(") + 1; + var end = o.indexOf(")"); + o = o.substr(start, end - start).split(","); + return { + H: parseInt(o[0], 10), + S: parseInt(o[1], 10), + L: parseInt(o[2], 10), + A: parseFloat(o[3], 10) * 255 + }; + }; + root.W3_HEX = root.W3_HEX24 = function(o) { + if (o.substr(0, 1) === "#") o = o.substr(1); + if (o.length === 3) o = o[0] + o[0] + o[1] + o[1] + o[2] + o[2]; + return parseInt("0x" + o, 16); + }; + root.W3_HEX32 = function(o) { + if (o.substr(0, 1) === "#") o = o.substr(1); + if (o.length === 6) { + return parseInt("0xFF" + o, 10); + } else { + return parseInt("0x" + o, 16); + } + }; + root.HEX_W3 = root.HEX24_W3 = function(o, maxLength) { + if (!maxLength) maxLength = 6; + if (!o) o = 0; + var n; + var z = o.toString(16); + n = z.length; + while (n < maxLength) { + z = "0" + z; + n++; + } + n = z.length; + while (n > maxLength) { + z = z.substr(1); + n--; + } + return "#" + z; + }; + root.HEX32_W3 = function(o) { + return root.HEX_W3(o, 8); + }; + root.HEX_RGB = root.HEX24_RGB = function(o) { + return { + R: o >> 16, + G: o >> 8 & 255, + B: o & 255 + }; + }; + root.HEX32_RGBA = function(o) { + return { + R: o >>> 16 & 255, + G: o >>> 8 & 255, + B: o & 255, + A: o >>> 24 + }; + }; + root.RGBA_HEX32 = function(o) { + return (o.A << 24 | o.R << 16 | o.G << 8 | o.B) >>> 0; + }; + root.RGB_HEX24 = root.RGB_HEX = function(o) { + if (o.R < 0) o.R = 0; + if (o.G < 0) o.G = 0; + if (o.B < 0) o.B = 0; + if (o.R > 255) o.R = 255; + if (o.G > 255) o.G = 255; + if (o.B > 255) o.B = 255; + return o.R << 16 | o.G << 8 | o.B; + }; + root.RGB_CMY = function(o) { + return { + C: 1 - o.R / 255, + M: 1 - o.G / 255, + Y: 1 - o.B / 255 + }; + }; + root.RGBA_HSLA = root.RGB_HSL = function(o) { + var _R = o.R / 255, _G = o.G / 255, _B = o.B / 255, min = Math.min(_R, _G, _B), max = Math.max(_R, _G, _B), D = max - min, H, S, L = (max + min) / 2; + if (D === 0) { + H = 0; + S = 0; + } else { + if (L < .5) S = D / (max + min); else S = D / (2 - max - min); + var DR = ((max - _R) / 6 + D / 2) / D; + var DG = ((max - _G) / 6 + D / 2) / D; + var DB = ((max - _B) / 6 + D / 2) / D; + if (_R === max) H = DB - DG; else if (_G === max) H = 1 / 3 + DR - DB; else if (_B === max) H = 2 / 3 + DG - DR; + if (H < 0) H += 1; + if (H > 1) H -= 1; + } + return { + H: H * 360, + S: S * 100, + L: L * 100, + A: o.A + }; + }; + root.RGBA_HSVA = root.RGB_HSV = function(o) { + var _R = o.R / 255, _G = o.G / 255, _B = o.B / 255, min = Math.min(_R, _G, _B), max = Math.max(_R, _G, _B), D = max - min, H, S, V = max; + if (D === 0) { + H = 0; + S = 0; + } else { + S = D / max; + var DR = ((max - _R) / 6 + D / 2) / D; + var DG = ((max - _G) / 6 + D / 2) / D; + var DB = ((max - _B) / 6 + D / 2) / D; + if (_R === max) H = DB - DG; else if (_G === max) H = 1 / 3 + DR - DB; else if (_B === max) H = 2 / 3 + DG - DR; + if (H < 0) H += 1; + if (H > 1) H -= 1; + } + return { + H: H * 360, + S: S * 100, + V: V * 100, + A: o.A + }; + }; + root.CMY_RGB = function(o) { + return { + R: Math.max(0, (1 - o.C) * 255), + G: Math.max(0, (1 - o.M) * 255), + B: Math.max(0, (1 - o.Y) * 255) + }; + }; + root.CMY_CMYK = function(o) { + var C = o.C; + var M = o.M; + var Y = o.Y; + var K = Math.min(Y, Math.min(M, Math.min(C, 1))); + C = Math.round((C - K) / (1 - K) * 100); + M = Math.round((M - K) / (1 - K) * 100); + Y = Math.round((Y - K) / (1 - K) * 100); + K = Math.round(K * 100); + return { + C: C, + M: M, + Y: Y, + K: K + }; + }; + root.CMYK_CMY = function(o) { + return { + C: o.C * (1 - o.K) + o.K, + M: o.M * (1 - o.K) + o.K, + Y: o.Y * (1 - o.K) + o.K + }; + }; + root.HSLA_RGBA = root.HSL_RGB = function(o) { + var H = o.H / 360; + var S = o.S / 100; + var L = o.L / 100; + var R, G, B; + var temp1, temp2, temp3; + if (S === 0) { + R = G = B = L; + } else { + if (L < .5) temp2 = L * (1 + S); else temp2 = L + S - S * L; + temp1 = 2 * L - temp2; + temp3 = H + 1 / 3; + if (temp3 < 0) temp3 += 1; + if (temp3 > 1) temp3 -= 1; + if (6 * temp3 < 1) R = temp1 + (temp2 - temp1) * 6 * temp3; else if (2 * temp3 < 1) R = temp2; else if (3 * temp3 < 2) R = temp1 + (temp2 - temp1) * (2 / 3 - temp3) * 6; else R = temp1; + temp3 = H; + if (temp3 < 0) temp3 += 1; + if (temp3 > 1) temp3 -= 1; + if (6 * temp3 < 1) G = temp1 + (temp2 - temp1) * 6 * temp3; else if (2 * temp3 < 1) G = temp2; else if (3 * temp3 < 2) G = temp1 + (temp2 - temp1) * (2 / 3 - temp3) * 6; else G = temp1; + temp3 = H - 1 / 3; + if (temp3 < 0) temp3 += 1; + if (temp3 > 1) temp3 -= 1; + if (6 * temp3 < 1) B = temp1 + (temp2 - temp1) * 6 * temp3; else if (2 * temp3 < 1) B = temp2; else if (3 * temp3 < 2) B = temp1 + (temp2 - temp1) * (2 / 3 - temp3) * 6; else B = temp1; + } + return { + R: R * 255, + G: G * 255, + B: B * 255, + A: o.A + }; + }; + root.HSVA_RGBA = root.HSV_RGB = function(o) { + var H = o.H / 360; + var S = o.S / 100; + var V = o.V / 100; + var R, G, B, D, A, C; + if (S === 0) { + R = G = B = Math.round(V * 255); + } else { + if (H >= 1) H = 0; + H = 6 * H; + D = H - Math.floor(H); + A = Math.round(255 * V * (1 - S)); + B = Math.round(255 * V * (1 - S * D)); + C = Math.round(255 * V * (1 - S * (1 - D))); + V = Math.round(255 * V); + switch (Math.floor(H)) { + case 0: + R = V; + G = C; + B = A; + break; + case 1: + R = B; + G = V; + B = A; + break; + case 2: + R = A; + G = V; + B = C; + break; + case 3: + R = A; + G = B; + B = V; + break; + case 4: + R = C; + G = A; + B = V; + break; + case 5: + R = V; + G = A; + B = B; + break; + } + } + return { + R: R, + G: G, + B: B, + A: o.A + }; + }; +})(); + +Inlet = function() { + function inlet(ed, options) { + var editor = ed; + var slider; + var picker; + var clicker; + if (!options) options = {}; + if (!options.picker) options.picker = {}; + if (!options.slider) options.slider = {}; + if (!options.clicker) options.clicker = {}; + var container = options.container || document.body; + var topOffset = options.picker.topOffset || 220; + var bottomOffset = options.picker.bottomOffset || 16; + var topBoundary = options.picker.topBoundary || 250; + var leftOffset = options.picker.leftOffset || 75; + var yOffset = options.slider.yOffset || 15; + var xOffset = options.slider.xOffset || 0; + var sliderWidth = options.slider.width; + var horizontalMode = options.horizontalMode || "page"; + var fixedContainer = options.fixedContainer; + var sliderCB = options.slider.callback || function(active) {}; + var pickerCB = options.picker.callback || function(active) {}; + var clickerCB = options.clicker.callback || function(active) {}; + var wrapper = editor.getWrapperElement(); + wrapper.addEventListener("mouseup", onClick); + document.body.addEventListener("mouseup", windowOnClick); + editor.setOption("onKeyEvent", onKeyDown); + var clickerDiv = document.createElement("div"); + clickerDiv.className = "inlet_clicker"; + clickerDiv.style.visibility = "hidden"; + clickerDiv.style.position = "absolute"; + container.appendChild(clickerDiv); + var clicker = document.createElement("input"); + clicker.className = "checkbox"; + clicker.setAttribute("type", "checkbox"); + clicker.addEventListener("change", onClicker); + clickerDiv.appendChild(clicker); + function onClicker(event) { + var value = String(clicker.checked); + var cursor = editor.getCursor(true); + var boolean = getMatch(cursor, "boolean"); + if (!boolean) return; + var start = { + line: cursor.line, + ch: boolean.start + }; + var end = { + line: cursor.line, + ch: boolean.end + }; + editor.replaceRange(value, start, end); + } + var sliderDiv = document.createElement("div"); + sliderDiv.className = "inlet_slider"; + sliderDiv.style.visibility = "hidden"; + if (sliderWidth) { + sliderDiv.style.width = sliderWidth; + } + if (fixedContainer) { + sliderDiv.style.position = "fixed"; + } else { + sliderDiv.style.position = "absolute"; + } + sliderDiv.style.top = 0; + // container.appendChild(sliderDiv); + + + var clickTarget; + function windowOnClick(evt) { + if (evt.target === clickTarget || evt.target === clickerDiv || evt.target === clicker) return; + clickerDiv.style.visibility = "hidden"; + } + var LEFT = 37; + var UP = 38; + var RIGHT = 39; + var DOWN = 40; + function onKeyDown() { + if (arguments.length == 1) { + event = arguments[0]; + } else { + event = arguments[1]; + } + if (event.keyCode == LEFT || event.keyCode == DOWN) { + if (event.altKey) { + onClick(); + } else {} + } else if (event.keyCode == RIGHT || event.keyCode == UP) { + if (event.altKey) { + onClick(); + } else {} + } + } + var pickerCallback = function(color, type) { + var cursor = editor.getCursor(); + if (!type) return; + var match = getMatch(cursor, type); + var start = { + line: cursor.line, + ch: match.start + }; + var end = { + line: cursor.line, + ch: match.end + }; + editor.picking = true; + editor.replaceRange(color, start, end); + setTimeout(function() { + editor.picking = false; + }, 100); + }; + picker = new thistle.Picker("#ffffff"); + function onClick(ev) { + if (editor.somethingSelected()) { + return; + } + clickTarget = ev.target; + var cursor = editor.getCursor(true); + var token = editor.getTokenAt(cursor); + cursorOffset = editor.cursorCoords(true, "page"); + var leftBase = editor.cursorCoords(true, horizontalMode).left; + var numberMatch = getMatch(cursor, "number"); + var hslMatch = getMatch(cursor, "hsl"); + var hexMatch = getMatch(cursor, "hex"); + var rgbMatch = getMatch(cursor, "rgb"); + var booleanMatch = getMatch(cursor, "boolean"); + var pickerTop = cursorOffset.top - topOffset; + if (cursorOffset.top < topBoundary) { + pickerTop = cursorOffset.top + bottomOffset; + } + var pickerLeft = leftBase - leftOffset; + clickerDiv.style.visibility = "hidden"; + if (hexMatch) { + var color = hexMatch.string; + picker = new thistle.Picker(color); + picker.setCSS(color); + picker.presentModal(pickerLeft, pickerTop); + picker.on("changed", function() { + picked = picker.getCSS(); + picked = Color.Space(picked, "W3>HSL>RGB>HEX24>W3"); + pickerCallback(picked, "hex"); + }); + } else if (hslMatch) { + var color = hslMatch.string; + picker = new thistle.Picker(color); + picker.setCSS(color); + picker.presentModal(pickerLeft, pickerTop); + picker.on("changed", function() { + picked = picker.getCSS(); + pickerCallback(picked, "hsl"); + }); + } else if (rgbMatch) { + var color = rgbMatch.string; + picker = new thistle.Picker(color); + picker.setCSS(color); + picker.presentModal(pickerLeft, pickerTop); + picker.on("changed", function() { + picked = picker.getCSS(); + picked = Color.Space(picked, "W3>HSL>RGB>W3"); + pickerCallback(picked, "rgb"); + }); + } else if (booleanMatch) { + var clickerTop = cursorOffset.top - yOffset; + var clickerStyle = window.getComputedStyle(clickerDiv); + var clickerWidth = getPixels(clickerStyle.width); + var clickerLeft = leftBase - clickerWidth / 2 + xOffset; + var value = JSON.parse(booleanMatch.string); + if (value) { + clickerDiv.removeChild(clicker); + clicker = document.createElement("input"); + clicker.className = "checkbox"; + clicker.setAttribute("type", "checkbox"); + clicker.setAttribute("checked", "checked"); + clicker.addEventListener("change", onClicker); + clickerDiv.appendChild(clicker); + } else { + clickerDiv.removeChild(clicker); + clicker = document.createElement("input"); + clicker.className = "checkbox"; + clicker.setAttribute("type", "checkbox"); + clicker.addEventListener("change", onClicker); + clickerDiv.appendChild(clicker); + } + clickerDiv.style.top = clickerTop - 3 + "px"; + clickerDiv.style.left = clickerLeft + "px"; + clickerDiv.style.visibility = "visible"; + } else {} + } + function getSliderRange(value) { + var range, step, sliderMin, sliderMax; + if (value === 0) { + range = [ -100, 100 ]; + } else { + range = [ -value * 3, value * 5 ]; + } + if (range[0] < range[1]) { + min = range[0]; + max = range[1]; + } else { + min = range[1]; + max = range[0]; + } + if (max - min > 20) { + step = 1; + } else { + step = (max - min) / 200; + } + return { + min: min, + max: max, + step: step + }; + } + function getMatch(cursor, type) { + if (!type) return; + var re; + switch (type.toLowerCase()) { + case "boolean": + re = /true|false/g; + break; + case "hsl": + re = /hsla?\(\s*(\d{1,3})\s*,\s*(\d{1,3}\%)\s*,\s*(\d{1,3}\%)\s*(?:\s*,\s*(\d+(?:\.\d+)?)\s*)?\)/g; + break; + case "rgb": + re = /rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)/g; + break; + case "hex": + re = /#[a-fA-F0-9]{3,6}/g; + break; + case "number": + re = /[-]?\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g; + break; + default: + throw new Error("invalid match selection"); + return; + } + var line = editor.getLine(cursor.line); + var match = re.exec(line); + while (match) { + var val = match[0]; + var len = val.length; + var start = match.index; + var end = match.index + len; + if (cursor.ch >= start && cursor.ch <= end) { + match = null; + return { + start: start, + end: end, + string: val + }; + } + match = re.exec(line); + } + return; + } + } + function getPixels(style) { + var pix = 0; + if (style.length > 2) { + pix = parseFloat(style.slice(0, style.length - 2)); + } + if (!pix) pix = 0; + return pix; + } + function getOffset(el) { + var _x = 0; + var _y = 0; + while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) { + _x += el.offsetLeft - el.scrollLeft; + _y += el.offsetTop - el.scrollTop; + el = el.offsetParent; + } + return { + top: _y, + left: _x + }; + } + return inlet; +}();