/* jCanvas v16.07.03 Copyright 2016 Caleb Evans Released under the MIT license */ (function(g,U,J){"object"===typeof module&&"object"===typeof module.exports?module.exports=function(g,U){return J(g,U)}:J(g,U)})("undefined"!==typeof window?window.jQuery:{},"undefined"!==typeof window?window:this,function(g,U){function J(d){for(var c in d)d.hasOwnProperty(c)&&(this[c]=d[c]);return this}function na(){Z(this,na.baseDefaults)}function ja(d){return"string"===aa(d)}function va(d){return!isNaN(wa(d))&&!isNaN(ba(d))}function L(d){return d&&d.getContext?d.getContext("2d"):null}function ka(d){var c, a,b;for(c in d)d.hasOwnProperty(c)&&(b=d[c],a=aa(b),"string"===a&&va(b)&&"text"!==c&&(d[c]=ba(b)));void 0!==d.text&&(d.text=String(d.text))}function la(d){d=Z({},d);d.masks=d.masks.slice(0);return d}function fa(d,c){var a;d.save();a=la(c.transforms);c.savedTransforms.push(a)}function xa(d,c,a,b){a[b]&&(da(a[b])?c[b]=a[b].call(d,a):c[b]=a[b])}function R(d,c,a){xa(d,c,a,"fillStyle");xa(d,c,a,"strokeStyle");c.lineWidth=a.strokeWidth;a.rounded?c.lineCap=c.lineJoin="round":(c.lineCap=a.strokeCap,c.lineJoin= a.strokeJoin,c.miterLimit=a.miterLimit);a.strokeDash||(a.strokeDash=[]);c.setLineDash&&c.setLineDash(a.strokeDash);c.webkitLineDash=a.strokeDash;c.lineDashOffset=c.webkitLineDashOffset=c.mozDashOffset=a.strokeDashOffset;c.shadowOffsetX=a.shadowX;c.shadowOffsetY=a.shadowY;c.shadowBlur=a.shadowBlur;c.shadowColor=a.shadowColor;c.globalAlpha=a.opacity;c.globalCompositeOperation=a.compositing;a.imageSmoothing&&(c.imageSmoothingEnabled=c.mozImageSmoothingEnabled=a.imageSmoothingEnabled)}function ya(d,c, a){a.mask&&(a.autosave&&fa(d,c),d.clip(),c.transforms.masks.push(a._args))}function W(d,c,a){a.closed&&c.closePath();a.shadowStroke&&0!==a.strokeWidth?(c.stroke(),c.fill(),c.shadowColor="transparent",c.shadowBlur=0,c.stroke()):(c.fill(),"transparent"!==a.fillStyle&&(c.shadowColor="transparent"),0!==a.strokeWidth&&c.stroke());a.closed||c.closePath();a._transformed&&c.restore();a.mask&&(d=H(d),ya(c,d,a))}function Q(d,c,a,b,f){a._toRad=a.inDegrees?E/180:1;a._transformed=!0;c.save();a.fromCenter||a._centered|| void 0===b||(void 0===f&&(f=b),a.x+=b/2,a.y+=f/2,a._centered=!0);a.rotate&&za(c,a,null);1===a.scale&&1===a.scaleX&&1===a.scaleY||Aa(c,a,null);(a.translate||a.translateX||a.translateY)&&Ba(c,a,null)}function H(d){var c=ca.dataCache,a;c._canvas===d&&c._data?a=c._data:(a=g.data(d,"jCanvas"),a||(a={canvas:d,layers:[],layer:{names:{},groups:{}},eventHooks:{},intersecting:[],lastIntersected:null,cursor:g(d).css("cursor"),drag:{layer:null,dragging:!1},event:{type:null,x:null,y:null},events:{},transforms:la(oa), savedTransforms:[],animating:!1,animated:null,pixelRatio:1,scaled:!1},g.data(d,"jCanvas",a)),c._canvas=d,c._data=a);return a}function Ca(d,c,a){for(var b in Y.events)Y.events.hasOwnProperty(b)&&(a[b]||a.cursors&&a.cursors[b])&&Da(d,c,a,b);c.events.mouseout||(d.bind("mouseout.jCanvas",function(){var a=c.drag.layer,b;a&&(c.drag={},O(d,c,a,"dragcancel"));for(b=0;ba&&(d.now[a]=Xa(d.now[a]));1!==d.start[3]||1!==d.end[3]?d.now="rgba( "+d.now.join(",")+" )":(d.now.slice(0,3),d.now="rgb( "+d.now.join(",")+" )");d.elem.nodeName?d.elem.style[d.prop]=d.now:d.elem[d.prop]=d.now}function Ya(d){X.touchEvents[d]&&(d=X.touchEvents[d]);return d}function Za(d){Y.events[d]=function(c,a){function b(a){h.x=a.offsetX;h.y=a.offsetY;h.type=f;h.event= a;c.drawLayers({resetFire:!0});a.preventDefault()}var f,e,h;h=a.event;f="mouseover"===d||"mouseout"===d?"mousemove":d;e=Ya(f);a.events[f]||(e!==f?c.bind(f+".jCanvas "+e+".jCanvas",b):c.bind(f+".jCanvas",b),a.events[f]=!0)}}function T(d,c,a){var b,f,e,h;if(a=a._args)d=H(d),b=d.event,null!==b.x&&null!==b.y&&(e=b.x*d.pixelRatio,h=b.y*d.pixelRatio,f=c.isPointInPath(e,h)||c.isPointInStroke&&c.isPointInStroke(e,h)),c=d.transforms,a.eventX=b.x,a.eventY=b.y,a.event=b.event,b=d.transforms.rotate,e=a.eventX, h=a.eventY,0!==b?(a._eventX=e*M(-b)-h*P(-b),a._eventY=h*M(-b)+e*P(-b)):(a._eventX=e,a._eventY=h),a._eventX/=c.scaleX,a._eventY/=c.scaleY,f&&d.intersecting.push(a),a.intersects=!!f}function za(d,c,a){c._toRad=c.inDegrees?E/180:1;d.translate(c.x,c.y);d.rotate(c.rotate*c._toRad);d.translate(-c.x,-c.y);a&&(a.rotate+=c.rotate*c._toRad)}function Aa(d,c,a){1!==c.scale&&(c.scaleX=c.scaleY=c.scale);d.translate(c.x,c.y);d.scale(c.scaleX,c.scaleY);d.translate(-c.x,-c.y);a&&(a.scaleX*=c.scaleX,a.scaleY*=c.scaleY)} function Ba(d,c,a){c.translate&&(c.translateX=c.translateY=c.translate);d.translate(c.translateX,c.translateY);a&&(a.translateX+=c.translateX,a.translateY+=c.translateY)}function Ja(d){for(;0>d;)d+=2*E;return d}function Ka(d,c,a,b){var f,e,h,g,p,v,z;a===b?z=v=0:(v=a.x,z=a.y);b.inDegrees||360!==b.end||(b.end=2*E);b.start*=a._toRad;b.end*=a._toRad;b.start-=E/2;b.end-=E/2;p=E/180;b.ccw&&(p*=-1);f=b.x+b.radius*M(b.start+p);e=b.y+b.radius*P(b.start+p);h=b.x+b.radius*M(b.start);g=b.y+b.radius*P(b.start); ga(d,c,a,b,f,e,h,g);c.arc(b.x+v,b.y+z,b.radius,b.start,b.end,b.ccw);f=b.x+b.radius*M(b.end+p);p=b.y+b.radius*P(b.end+p);e=b.x+b.radius*M(b.end);h=b.y+b.radius*P(b.end);ha(d,c,a,b,e,h,f,p)}function La(d,c,a,b,f,e,h,g){var p,v;b.arrowRadius&&!a.closed&&(v=$a(g-e,h-f),v-=E,d=a.strokeWidth*M(v),p=a.strokeWidth*P(v),a=h+b.arrowRadius*M(v+b.arrowAngle/2),f=g+b.arrowRadius*P(v+b.arrowAngle/2),e=h+b.arrowRadius*M(v-b.arrowAngle/2),b=g+b.arrowRadius*P(v-b.arrowAngle/2),c.moveTo(a-d,f-p),c.lineTo(h-d,g-p), c.lineTo(e-d,b-p),c.moveTo(h-d,g-p),c.lineTo(h+d,g+p),c.moveTo(h,g))}function ga(d,c,a,b,f,e,h,g){b._arrowAngleConverted||(b.arrowAngle*=a._toRad,b._arrowAngleConverted=!0);b.startArrow&&La(d,c,a,b,f,e,h,g)}function ha(d,c,a,b,f,e,h,g){b._arrowAngleConverted||(b.arrowAngle*=a._toRad,b._arrowAngleConverted=!0);b.endArrow&&La(d,c,a,b,f,e,h,g)}function Ma(d,c,a,b){var f,e,h;f=2;ga(d,c,a,b,b.x2+a.x,b.y2+a.y,b.x1+a.x,b.y1+a.y);for(void 0!==b.x1&&void 0!==b.y1&&c.moveTo(b.x1+a.x,b.y1+a.y);;)if(e=b["x"+ f],h=b["y"+f],void 0!==e&&void 0!==h)c.lineTo(e+a.x,h+a.y),f+=1;else break;--f;ha(d,c,a,b,b["x"+(f-1)]+a.x,b["y"+(f-1)]+a.y,b["x"+f]+a.x,b["y"+f]+a.y)}function Na(d,c,a,b){var f,e,h,g,p;f=2;ga(d,c,a,b,b.cx1+a.x,b.cy1+a.y,b.x1+a.x,b.y1+a.y);for(void 0!==b.x1&&void 0!==b.y1&&c.moveTo(b.x1+a.x,b.y1+a.y);;)if(e=b["x"+f],h=b["y"+f],g=b["cx"+(f-1)],p=b["cy"+(f-1)],void 0!==e&&void 0!==h&&void 0!==g&&void 0!==p)c.quadraticCurveTo(g+a.x,p+a.y,e+a.x,h+a.y),f+=1;else break;--f;ha(d,c,a,b,b["cx"+(f-1)]+a.x, b["cy"+(f-1)]+a.y,b["x"+f]+a.x,b["y"+f]+a.y)}function Oa(d,c,a,b){var f,e,h,g,p,v,z,D;f=2;e=1;ga(d,c,a,b,b.cx1+a.x,b.cy1+a.y,b.x1+a.x,b.y1+a.y);for(void 0!==b.x1&&void 0!==b.y1&&c.moveTo(b.x1+a.x,b.y1+a.y);;)if(h=b["x"+f],g=b["y"+f],p=b["cx"+e],v=b["cy"+e],z=b["cx"+(e+1)],D=b["cy"+(e+1)],void 0!==h&&void 0!==g&&void 0!==p&&void 0!==v&&void 0!==z&&void 0!==D)c.bezierCurveTo(p+a.x,v+a.y,z+a.x,D+a.y,h+a.x,g+a.y),f+=1,e+=2;else break;--f;e-=2;ha(d,c,a,b,b["cx"+(e+1)]+a.x,b["cy"+(e+1)]+a.y,b["x"+f]+a.x, b["y"+f]+a.y)}function Pa(d,c,a){c*=d._toRad;c-=E/2;return a*M(c)}function Qa(d,c,a){c*=d._toRad;c-=E/2;return a*P(c)}function Ra(d,c,a,b){var f,e,h,g,p,v,z;a===b?p=g=0:(g=a.x,p=a.y);f=1;e=g=v=b.x+g;h=p=z=b.y+p;ga(d,c,a,b,e+Pa(a,b.a1,b.l1),h+Qa(a,b.a1,b.l1),e,h);for(void 0!==b.x&&void 0!==b.y&&c.moveTo(e,h);;)if(e=b["a"+f],h=b["l"+f],void 0!==e&&void 0!==h)g=v,p=z,v+=Pa(a,e,h),z+=Qa(a,e,h),c.lineTo(v,z),f+=1;else break;ha(d,c,a,b,g,p,v,z)}function sa(d,c,a){isNaN(wa(a.fontSize))||(a.fontSize+="px"); c.font=a.fontStyle+" "+a.fontSize+" "+a.fontFamily}function ta(d,c,a,b){var f,e;f=ca.propCache;if(f.text===a.text&&f.fontStyle===a.fontStyle&&f.fontSize===a.fontSize&&f.fontFamily===a.fontFamily&&f.maxWidth===a.maxWidth&&f.lineHeight===a.lineHeight)a.width=f.width,a.height=f.height;else{a.width=c.measureText(b[0]).width;for(e=1;ea.width&&(a.width=f);c=d.style.fontSize;d.style.fontSize=a.fontSize;a.height=ba(g.css(d,"fontSize"))*b.length*a.lineHeight;d.style.fontSize= c}}function Sa(d,c){var a=c.maxWidth,b=String(c.text).split("\n"),f=[],e,h,g,p,v;for(g=0;ga&&(""!==h&&e.push(h),h=""),h+=v[p],p!==v.length-1&&(h+=" ");e.push(h)}f=f.concat(e.join("\n").replace(/( (\n))|( $)/gi,"$2").split("\n"))}return f}var Ia=U.document,Ta=U.Image,ab=U.getComputedStyle,ea=U.Math,wa=U.Number,ba=U.parseFloat,ma,Z=g.extend,ia=g.inArray, aa=function(d){return Object.prototype.toString.call(d).slice(8,-1).toLowerCase()},da=g.isFunction,Ga=g.isPlainObject,E=ea.PI,Xa=ea.round,bb=ea.abs,P=ea.sin,M=ea.cos,$a=ea.atan2,ua=U.Array.prototype.slice,cb=g.event.fix,X={},ca={dataCache:{},propCache:{},imageCache:{}},oa={rotate:0,scaleX:1,scaleY:1,translateX:0,translateY:0,masks:[]},V={},Ua="mousedown mousemove mouseup mouseover mouseout touchstart touchmove touchend".split(" "),Y={events:{},eventHooks:{},future:{}};na.baseDefaults={align:"center", arrowAngle:90,arrowRadius:0,autosave:!0,baseline:"middle",bringToFront:!1,ccw:!1,closed:!1,compositing:"source-over",concavity:0,cornerRadius:0,count:1,cropFromCenter:!0,crossOrigin:null,cursors:null,disableEvents:!1,draggable:!1,dragGroups:null,groups:null,data:null,dx:null,dy:null,end:360,eventX:null,eventY:null,fillStyle:"transparent",fontStyle:"normal",fontSize:"12pt",fontFamily:"sans-serif",fromCenter:!0,height:null,imageSmoothing:!0,inDegrees:!0,intangible:!1,index:null,letterSpacing:null,lineHeight:1, layer:!1,mask:!1,maxWidth:null,miterLimit:10,name:null,opacity:1,r1:null,r2:null,radius:0,repeat:"repeat",respectAlign:!1,restrictDragToAxis:null,rotate:0,rounded:!1,scale:1,scaleX:1,scaleY:1,shadowBlur:0,shadowColor:"transparent",shadowStroke:!1,shadowX:0,shadowY:0,sHeight:null,sides:0,source:"",spread:0,start:0,strokeCap:"butt",strokeDash:null,strokeDashOffset:0,strokeJoin:"miter",strokeStyle:"transparent",strokeWidth:1,sWidth:null,sx:null,sy:null,text:"",translate:0,translateX:0,translateY:0,type:null, visible:!0,width:null,x:0,y:0};ma=new na;J.prototype=ma;Y.extend=function(d){d.name&&(d.props&&Z(ma,d.props),g.fn[d.name]=function a(b){var f,e,h,g;for(e=0;ed&&(d=c.length+d),b=c[d];else if("regexp"===f)for(a=0;ac&&(c=e.length+c),h.index=c,O(a,f,h,"move");return this};g.fn.removeLayer=function(d){var c,a,b,f,e;for(a=0;am.width&&(F=B,B=t,t=F),0>m.height&&(F=r,r=l,l=F),0>t-B-2*x&&(x=(t-B)/2),0>l-r-2*x&&(x=(l-r)/2),D.moveTo(B+x,r),D.lineTo(t-x,r),D.arc(t-x,r+x,x,3*E/2,2*E, !1),D.lineTo(t,l-x),D.arc(t-x,l-x,x,0,E/2,!1),D.lineTo(B+x,l),D.arc(B+x,l-x,x,E/2,E,!1),D.lineTo(B,r+x),D.arc(B+x,r+x,x,E,3*E/2,!1),m.closed=!0):D.rect(B,r,m.width,m.height)),T(this[z],D,m),W(this[z],D,m));return this};g.fn.drawArc=function v(g){var D,m,B;for(D=0;Dq.sy-q.sHeight/2&&(q.sy=q.sHeight/2),q.sy+q.sHeight/2>I.height&&(q.sy=I.height-q.sHeight/2),0>q.sx-q.sWidth/2&&(q.sx=q.sWidth/2),q.sx+q.sWidth/2>I.width&&(q.sx=I.width-q.sWidth/2),Q(k,n,q,q.width,q.height),R(k,n,q),n.drawImage(I, q.sx-q.sWidth/2,q.sy-q.sHeight/2,q.sWidth,q.sHeight,q.x-q.width/2,q.y-q.height/2,q.width,q.height)):(Q(k,n,q,q.width,q.height),R(k,n,q),n.drawImage(I,q.x-q.width/2,q.y-q.height/2,q.width,q.height));n.beginPath();n.rect(q.x-q.width/2,q.y-q.height/2,q.width,q.height);T(k,n,q);n.closePath();q._transformed&&n.restore();ya(n,y,q);q.layer?O(w,y,u,"load"):q.load&&q.load.call(w[0],u);q.layer&&(u._masks=y.transforms.masks.slice(0),q._next&&w.drawLayers({clear:!1,resetFire:!0,index:q._next}))}}var k,w,C,u, G,S,I,E,M,P=ca.imageCache;for(w=0;w")[0],C.width=w.width,C.height=w.height,y=L(C),G.call(C,y),A()):(y=G.getContext,G.src||y?C=G:(C=new Ta,G.match(/^data:/i)||(C.crossOrigin=w.crossOrigin),C.src=G),C.complete||y?A():(C.onload=A,C.src=C.src))):u=null;return u};g.fn.createGradient=function(g){var A,n=[],k,w,C,u,G,H,I;g=new J(g);if(A=L(this[0])){g.x1=g.x1||0;g.y1=g.y1||0;g.x2=g.x2||0;g.y2=g.y2||0;A=null!==g.r1&&null!==g.r2?A.createRadialGradient(g.x1,g.y1,g.r1,g.x2,g.y2,g.r2):A.createLinearGradient(g.x1, g.y1,g.x2,g.y2);for(u=1;void 0!==g["c"+u];u+=1)void 0!==g["s"+u]?n.push(g["s"+u]):n.push(null);k=n.length;null===n[0]&&(n[0]=0);null===n[k-1]&&(n[k-1]=1);for(u=0;uC&&(n[G]=n[u])}else null===n[u]&&(I+=1,n[u]=w+(C-w)/H*I);A.addColorStop(n[u],g["c"+(u+1)])}}else A=null;return A};g.fn.setPixels=function A(g){var k,w,C,u,G,H,I,E,M;for(w=0;w")[0].getContext;Z(Y,{defaults:ma,setGlobalProps:R,transformShape:Q,detectEvents:T,closePath:W,setCanvasFont:sa,measureText:ta});g.jCanvas=Y;g.jCanvasObject=J});