var Kinetic={};(function(root){var PI_OVER_180=Math.PI/180;Kinetic={version:'5.1.0',stages:[],idCounter:0,ids:{},names:{},shapes:{},listenClickTap:false,inDblClickWindow:false,enableTrace:false,traceArrMax:100,dblClickWindow:400,pixelRatio:undefined,dragDistance:0,angleDeg:true,UA:(function(){var userAgent=(root.navigator&&root.navigator.userAgent)||'';var ua=userAgent.toLowerCase(),match=/(chrome)[ \/]([\w.]+)/.exec(ua)||/(webkit)[ \/]([\w.]+)/.exec(ua)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua)||/(msie) ([\w.]+)/.exec(ua)||ua.indexOf('compatible')<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua)||[],mobile=!!(userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i));return{browser:match[1]||'',version:match[2]||'0',mobile:mobile};})(),Filters:{},Node:function(config){this._init(config);},Shape:function(config){this.__init(config);},Container:function(config){this.__init(config);},Stage:function(config){this.___init(config);},BaseLayer:function(config){this.___init(config);},Layer:function(config){this.____init(config);},FastLayer:function(config){this.____init(config);},Group:function(config){this.___init(config);},isDragging:function(){var dd=Kinetic.DD;if(!dd){return false;} else{return dd.isDragging;}},isDragReady:function(){var dd=Kinetic.DD;if(!dd){return false;} else{return!!dd.node;}},_addId:function(node,id){if(id!==undefined){this.ids[id]=node;}},_removeId:function(id){if(id!==undefined){delete this.ids[id];}},_addName:function(node,name){if(name!==undefined){if(this.names[name]===undefined){this.names[name]=[];} this.names[name].push(node);}},_removeName:function(name,_id){if(name!==undefined){var nodes=this.names[name];if(nodes!==undefined){for(var n=0;n');var KineticJS=factory();Kinetic.document=doc;Kinetic.window=Kinetic.document.createWindow();Kinetic.window.Image=Canvas.Image;Kinetic.root=root;Kinetic._nodeCanvas=Canvas;module.exports=KineticJS;return;} else if(typeof define==='function'&&define.amd){define(factory);} Kinetic.document=document;Kinetic.window=window;Kinetic.root=root;}((1,eval)('this'),function(){return Kinetic;}));;(function(){Kinetic.Collection=function(){var args=[].slice.call(arguments),length=args.length,i=0;this.length=length;for(;i0;},createCanvasElement:function(){var canvas=Kinetic.document.createElement('canvas');canvas.style=canvas.style||{};return canvas;},isBrowser:function(){return(typeof exports!=='object');},_isInDocument:function(el){while(el=el.parentNode){if(el==Kinetic.document){return true;}} return false;},_simplifyArray:function(arr){var retArr=[],len=arr.length,util=Kinetic.Util,n,val;for(n=0;n>16)&255,g:(bigint>>8)&255,b:bigint&255};},getRandomColor:function(){var randColor=(Math.random()*0xFFFFFF<<0).toString(16);while(randColor.length<6){randColor=ZERO+randColor;} return HASH+randColor;},get:function(val,def){if(val===undefined){return def;} else{return val;}},getRGB:function(color){var rgb;if(color in COLORS){rgb=COLORS[color];return{r:rgb[0],g:rgb[1],b:rgb[2]};} else if(color[0]===HASH){return this._hexToRgb(color.substring(1));} else if(color.substr(0,4)===RGB_PAREN){rgb=RGB_REGEX.exec(color.replace(/ /g,''));return{r:parseInt(rgb[1],10),g:parseInt(rgb[2],10),b:parseInt(rgb[3],10)};} else{return{r:0,g:0,b:0};}},_merge:function(o1,o2){var retObj=this._clone(o2);for(var key in o1){if(this._isObject(o1[key])){retObj[key]=this._merge(o1[key],retObj[key]);} else{retObj[key]=o1[key];}} return retObj;},cloneObject:function(obj){var retObj={};for(var key in obj){if(this._isObject(obj[key])){retObj[key]=this.cloneObject(obj[key]);} else if(this._isArray(obj[key])){retObj[key]=this.cloneArray(obj[key]);}else{retObj[key]=obj[key];}} return retObj;},cloneArray:function(arr){return arr.slice(0);},_degToRad:function(deg){return deg*PI_OVER_DEG180;},_radToDeg:function(rad){return rad*DEG180_OVER_PI;},_capitalize:function(str){return str.charAt(0).toUpperCase()+str.slice(1);},error:function(str){throw new Error(KINETIC_ERROR+str);},warn:function(str){if(Kinetic.root.console&&console.warn){console.warn(KINETIC_WARNING+str);}},extend:function(c1,c2){for(var key in c2.prototype){if(!(key in c1.prototype)){c1.prototype[key]=c2.prototype[key];}}},addMethods:function(constructor,methods){var key;for(key in methods){constructor.prototype[key]=methods[key];}},_getControlPoints:function(x0,y0,x1,y1,x2,y2,t){var d01=Math.sqrt(Math.pow(x1-x0,2)+Math.pow(y1-y0,2)),d12=Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2)),fa=t*d01/(d01+d12),fb=t*d12/(d01+d12),p1x=x1-fa*(x2-x0),p1y=y1-fa*(y2-y0),p2x=x1+fb*(x2-x0),p2y=y1+fb*(y2-y0);return[p1x,p1y,p2x,p2y];},_expandPoints:function(p,tension){var len=p.length,allPoints=[],n,cp;for(n=2;n=Kinetic.traceArrMax){traceArr.shift();}},reset:function(){var pixelRatio=this.getCanvas().getPixelRatio();this.setTransform(1*pixelRatio,0,0,1*pixelRatio,0,0);},getCanvas:function(){return this.canvas;},clear:function(bounds){var canvas=this.getCanvas();if(bounds){this.clearRect(bounds.x||0,bounds.y||0,bounds.width||0,bounds.height||0);} else{this.clearRect(0,0,canvas.getWidth(),canvas.getHeight());}},_applyLineCap:function(shape){var lineCap=shape.getLineCap();if(lineCap){this.setAttr('lineCap',lineCap);}},_applyOpacity:function(shape){var absOpacity=shape.getAbsoluteOpacity();if(absOpacity!==1){this.setAttr('globalAlpha',absOpacity);}},_applyLineJoin:function(shape){var lineJoin=shape.getLineJoin();if(lineJoin){this.setAttr('lineJoin',lineJoin);}},setAttr:function(attr,val){this._context[attr]=val;},arc:function(){var a=arguments;this._context.arc(a[0],a[1],a[2],a[3],a[4],a[5]);},beginPath:function(){this._context.beginPath();},bezierCurveTo:function(){var a=arguments;this._context.bezierCurveTo(a[0],a[1],a[2],a[3],a[4],a[5]);},clearRect:function(){var a=arguments;this._context.clearRect(a[0],a[1],a[2],a[3]);},clip:function(){this._context.clip();},closePath:function(){this._context.closePath();},createImageData:function(){var a=arguments;if(a.length===2){return this._context.createImageData(a[0],a[1]);} else if(a.length===1){return this._context.createImageData(a[0]);}},createLinearGradient:function(){var a=arguments;return this._context.createLinearGradient(a[0],a[1],a[2],a[3]);},createPattern:function(){var a=arguments;return this._context.createPattern(a[0],a[1]);},createRadialGradient:function(){var a=arguments;return this._context.createRadialGradient(a[0],a[1],a[2],a[3],a[4],a[5]);},drawImage:function(){var a=arguments,_context=this._context;if(a.length===3){_context.drawImage(a[0],a[1],a[2]);} else if(a.length===5){_context.drawImage(a[0],a[1],a[2],a[3],a[4]);} else if(a.length===9){_context.drawImage(a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8]);}},fill:function(){this._context.fill();},fillText:function(){var a=arguments;this._context.fillText(a[0],a[1],a[2]);},getImageData:function(){var a=arguments;return this._context.getImageData(a[0],a[1],a[2],a[3]);},lineTo:function(){var a=arguments;this._context.lineTo(a[0],a[1]);},moveTo:function(){var a=arguments;this._context.moveTo(a[0],a[1]);},rect:function(){var a=arguments;this._context.rect(a[0],a[1],a[2],a[3]);},putImageData:function(){var a=arguments;this._context.putImageData(a[0],a[1],a[2]);},quadraticCurveTo:function(){var a=arguments;this._context.quadraticCurveTo(a[0],a[1],a[2],a[3]);},restore:function(){this._context.restore();},rotate:function(){var a=arguments;this._context.rotate(a[0]);},save:function(){this._context.save();},scale:function(){var a=arguments;this._context.scale(a[0],a[1]);},setLineDash:function(){var a=arguments,_context=this._context;if(this._context.setLineDash){_context.setLineDash(a[0]);} else if('mozDash'in _context){_context.mozDash=a[0];} else if('webkitLineDash'in _context){_context.webkitLineDash=a[0];} },setTransform:function(){var a=arguments;this._context.setTransform(a[0],a[1],a[2],a[3],a[4],a[5]);},stroke:function(){this._context.stroke();},strokeText:function(){var a=arguments;this._context.strokeText(a[0],a[1],a[2]);},transform:function(){var a=arguments;this._context.transform(a[0],a[1],a[2],a[3],a[4],a[5]);},translate:function(){var a=arguments;this._context.translate(a[0],a[1]);},_enableTrace:function(){var that=this,len=CONTEXT_METHODS.length,_simplifyArray=Kinetic.Util._simplifyArray,origSetter=this.setAttr,n,args;var func=function(methodName){var origMethod=that[methodName],ret;that[methodName]=function(){args=_simplifyArray(Array.prototype.slice.call(arguments,0));ret=origMethod.apply(that,arguments);that._trace({method:methodName,args:args});return ret;};};for(n=0;n255){return 255;} else if(val<0){return 0;} else{return Math.round(val);}},alphaComponent:function(val){if(val>1){return 1;} else if(val<0.0001){return 0.0001;} else{return val;}}};})();;(function(){var ABSOLUTE_OPACITY='absoluteOpacity',ABSOLUTE_TRANSFORM='absoluteTransform',BEFORE='before',CHANGE='Change',CHILDREN='children',DOT='.',EMPTY_STRING='',GET='get',ID='id',KINETIC='kinetic',LISTENING='listening',MOUSEENTER='mouseenter',MOUSELEAVE='mouseleave',NAME='name',SET='set',SHAPE='Shape',SPACE=' ',STAGE='stage',TRANSFORM='transform',UPPER_STAGE='Stage',VISIBLE='visible',CLONE_BLACK_LIST=['id'],TRANSFORM_CHANGE_STR=['xChange.kinetic','yChange.kinetic','scaleXChange.kinetic','scaleYChange.kinetic','skewXChange.kinetic','skewYChange.kinetic','rotationChange.kinetic','offsetXChange.kinetic','offsetYChange.kinetic','transformsEnabledChange.kinetic'].join(SPACE);Kinetic.Util.addMethods(Kinetic.Node,{_init:function(config){var that=this;this._id=Kinetic.idCounter++;this.eventListeners={};this.attrs={};this._cache={};this._filterUpToDate=false;this.setAttrs(config);this.on(TRANSFORM_CHANGE_STR,function(){this._clearCache(TRANSFORM);that._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);});this.on('visibleChange.kinetic',function(){that._clearSelfAndDescendantCache(VISIBLE);});this.on('listeningChange.kinetic',function(){that._clearSelfAndDescendantCache(LISTENING);});this.on('opacityChange.kinetic',function(){that._clearSelfAndDescendantCache(ABSOLUTE_OPACITY);});},_clearCache:function(attr){if(attr){delete this._cache[attr];} else{this._cache={};}},_getCache:function(attr,privateGetter){var cache=this._cache[attr];if(cache===undefined){this._cache[attr]=privateGetter.call(this);} return this._cache[attr];},_clearSelfAndDescendantCache:function(attr){this._clearCache(attr);if(this.children){this.getChildren().each(function(node){node._clearSelfAndDescendantCache(attr);});}},clearCache:function(){delete this._cache.canvas;this._filterUpToDate=false;return this;},cache:function(config){var conf=config||{},x=conf.x||0,y=conf.y||0,width=conf.width||this.width(),height=conf.height||this.height(),drawBorder=conf.drawBorder||false,layer=this.getLayer();if(width===0||height===0){Kinetic.Util.warn('Width or height of caching configuration equals 0. Cache is ignored.');return;} var cachedSceneCanvas=new Kinetic.SceneCanvas({pixelRatio:1,width:width,height:height}),cachedFilterCanvas=new Kinetic.SceneCanvas({pixelRatio:1,width:width,height:height}),cachedHitCanvas=new Kinetic.HitCanvas({width:width,height:height}),origTransEnabled=this.transformsEnabled(),origX=this.x(),origY=this.y(),sceneContext=cachedSceneCanvas.getContext(),hitContext=cachedHitCanvas.getContext();this.clearCache();sceneContext.save();hitContext.save();if(drawBorder){sceneContext.save();sceneContext.beginPath();sceneContext.rect(0,0,width,height);sceneContext.closePath();sceneContext.setAttr('strokeStyle','red');sceneContext.setAttr('lineWidth',5);sceneContext.stroke();sceneContext.restore();} sceneContext.translate(x*-1,y*-1);hitContext.translate(x*-1,y*-1);if(this.nodeType==='Shape'){sceneContext.translate(this.x()*-1,this.y()*-1);hitContext.translate(this.x()*-1,this.y()*-1);} this.drawScene(cachedSceneCanvas,this);this.drawHit(cachedHitCanvas,this);sceneContext.restore();hitContext.restore();this._cache.canvas={scene:cachedSceneCanvas,filter:cachedFilterCanvas,hit:cachedHitCanvas};return this;},_drawCachedSceneCanvas:function(context){context.save();this.getLayer()._applyTransform(this,context);context.drawImage(this._getCachedSceneCanvas()._canvas,0,0);context.restore();},_getCachedSceneCanvas:function(){var filters=this.filters(),cachedCanvas=this._cache.canvas,sceneCanvas=cachedCanvas.scene,filterCanvas=cachedCanvas.filter,filterContext=filterCanvas.getContext(),len,imageData,n,filter;if(filters){if(!this._filterUpToDate){try{len=filters.length;filterContext.clear();filterContext.drawImage(sceneCanvas._canvas,0,0);imageData=filterContext.getImageData(0,0,filterCanvas.getWidth(),filterCanvas.getHeight());for(n=0;n0&&nodes[0].getDepth()<=depth){addChildren(nodes);}} if(that.nodeType!==UPPER_STAGE){addChildren(that.getStage().getChildren());} return index;},getDepth:function(){var depth=0,parent=this.parent;while(parent){depth++;parent=parent.parent;} return depth;},setPosition:function(pos){this.setX(pos.x);this.setY(pos.y);return this;},getPosition:function(){return{x:this.getX(),y:this.getY()};},getAbsolutePosition:function(){var absoluteMatrix=this.getAbsoluteTransform().getMatrix(),absoluteTransform=new Kinetic.Transform(),offset=this.offset();absoluteTransform.m=absoluteMatrix.slice();absoluteTransform.translate(offset.x,offset.y);return absoluteTransform.getTranslation();},setAbsolutePosition:function(pos){var origTrans=this._clearTransform(),it;this.attrs.x=origTrans.x;this.attrs.y=origTrans.y;delete origTrans.x;delete origTrans.y;it=this.getAbsoluteTransform();it.invert();it.translate(pos.x,pos.y);pos={x:this.attrs.x+it.getTranslation().x,y:this.attrs.y+it.getTranslation().y};this.setPosition({x:pos.x,y:pos.y});this._setTransform(origTrans);return this;},_setTransform:function(trans){var key;for(key in trans){this.attrs[key]=trans[key];} this._clearCache(TRANSFORM);this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);},_clearTransform:function(){var trans={x:this.getX(),y:this.getY(),rotation:this.getRotation(),scaleX:this.getScaleX(),scaleY:this.getScaleY(),offsetX:this.getOffsetX(),offsetY:this.getOffsetY(),skewX:this.getSkewX(),skewY:this.getSkewY()};this.attrs.x=0;this.attrs.y=0;this.attrs.rotation=0;this.attrs.scaleX=1;this.attrs.scaleY=1;this.attrs.offsetX=0;this.attrs.offsetY=0;this.attrs.skewX=0;this.attrs.skewY=0;this._clearCache(TRANSFORM);this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);return trans;},move:function(change){var changeX=change.x,changeY=change.y,x=this.getX(),y=this.getY();if(changeX!==undefined){x+=changeX;} if(changeY!==undefined){y+=changeY;} this.setPosition({x:x,y:y});return this;},_eachAncestorReverse:function(func,top){var family=[],parent=this.getParent(),len,n;if(top&&top._id===this._id){func(this);return true;} family.unshift(this);while(parent&&(!top||parent._id!==top._id)){family.unshift(parent);parent=parent.parent;} len=family.length;for(n=0;n0){this.parent.children.splice(index,1);this.parent.children.splice(index-1,0,this);this.parent._setChildrenIndices();return true;} return false;},moveToBottom:function(){if(!this.parent){Kinetic.Util.warn('Node has no parent. moveToBottom function is ignored.');return;} var index=this.index;if(index>0){this.parent.children.splice(index,1);this.parent.children.unshift(this);this.parent._setChildrenIndices();return true;} return false;},setZIndex:function(zIndex){if(!this.parent){Kinetic.Util.warn('Node has no parent. zIndex parameter is ignored.');return;} var index=this.index;this.parent.children.splice(index,1);this.parent.children.splice(zIndex,0,this);this.parent._setChildrenIndices();return this;},getAbsoluteOpacity:function(){return this._getCache(ABSOLUTE_OPACITY,this._getAbsoluteOpacity);},_getAbsoluteOpacity:function(){var absOpacity=this.getOpacity();if(this.getParent()){absOpacity*=this.getParent().getAbsoluteOpacity();} return absOpacity;},moveTo:function(newContainer){Kinetic.Node.prototype.remove.call(this);newContainer.add(this);return this;},toObject:function(){var type=Kinetic.Util,obj={},attrs=this.getAttrs(),key,val,getter,defaultValue;obj.attrs={};for(key in attrs){val=attrs[key];if(!type._isFunction(val)&&!type._isElement(val)&&!(type._isObject(val)&&type._hasMethods(val))){getter=this[key];delete attrs[key];defaultValue=getter?getter.call(this):null;attrs[key]=val;if(defaultValue!==val){obj.attrs[key]=val;}}} obj.className=this.getClassName();return obj;},toJSON:function(){return JSON.stringify(this.toObject());},getParent:function(){return this.parent;},getLayer:function(){var parent=this.getParent();return parent?parent.getLayer():null;},getStage:function(){return this._getCache(STAGE,this._getStage);},_getStage:function(){var parent=this.getParent();if(parent){return parent.getStage();} else{return undefined;}},fire:function(eventType,evt,bubble){if(bubble){this._fireAndBubble(eventType,evt||{});} else{this._fire(eventType,evt||{});} return this;},getAbsoluteTransform:function(top){if(top){return this._getAbsoluteTransform(top);} else{return this._getCache(ABSOLUTE_TRANSFORM,this._getAbsoluteTransform);}},_getAbsoluteTransform:function(top){var at=new Kinetic.Transform(),transformsEnabled,trans;this._eachAncestorReverse(function(node){transformsEnabled=node.transformsEnabled();trans=node.getTransform();if(transformsEnabled==='all'){at.multiply(trans);} else if(transformsEnabled==='position'){at.translate(node.x(),node.y());}},top);return at;},getTransform:function(){return this._getCache(TRANSFORM,this._getTransform);},_getTransform:function(){var m=new Kinetic.Transform(),x=this.getX(),y=this.getY(),rotation=Kinetic.getAngle(this.getRotation()),scaleX=this.getScaleX(),scaleY=this.getScaleY(),skewX=this.getSkewX(),skewY=this.getSkewY(),offsetX=this.getOffsetX(),offsetY=this.getOffsetY();if(x!==0||y!==0){m.translate(x,y);} if(rotation!==0){m.rotate(rotation);} if(skewX!==0||skewY!==0){m.skew(skewX,skewY);} if(scaleX!==1||scaleY!==1){m.scale(scaleX,scaleY);} if(offsetX!==0||offsetY!==0){m.translate(-1*offsetX,-1*offsetY);} return m;},clone:function(obj){var className=this.getClassName(),attrs=Kinetic.Util.cloneObject(this.attrs),key,allListeners,len,n,listener;for(var i in CLONE_BLACK_LIST){var blockAttr=CLONE_BLACK_LIST[i];delete attrs[blockAttr];} for(key in obj){attrs[key]=obj[key];} var node=new Kinetic[className](attrs);for(key in this.eventListeners){allListeners=this.eventListeners[key];len=allListeners.length;for(n=0;n>shg_sum;if(pa!==0) {pa=255/pa;pixels[yi]=((r_sum*mul_sum)>>shg_sum)*pa;pixels[yi+1]=((g_sum*mul_sum)>>shg_sum)*pa;pixels[yi+2]=((b_sum*mul_sum)>>shg_sum)*pa;}else{pixels[yi]=pixels[yi+1]=pixels[yi+2]=0;} r_sum-=r_out_sum;g_sum-=g_out_sum;b_sum-=b_out_sum;a_sum-=a_out_sum;r_out_sum-=stackIn.r;g_out_sum-=stackIn.g;b_out_sum-=stackIn.b;a_out_sum-=stackIn.a;p=(yw+((p=x+radius+1)>shg_sum;if(pa>0) {pa=255/pa;pixels[p]=((r_sum*mul_sum)>>shg_sum)*pa;pixels[p+1]=((g_sum*mul_sum)>>shg_sum)*pa;pixels[p+2]=((b_sum*mul_sum)>>shg_sum)*pa;}else{pixels[p]=pixels[p+1]=pixels[p+2]=0;} r_sum-=r_out_sum;g_sum-=g_out_sum;b_sum-=b_out_sum;a_sum-=a_out_sum;r_out_sum-=stackIn.r;g_out_sum-=stackIn.g;b_out_sum-=stackIn.b;a_out_sum-=stackIn.a;p=(x+(((p=y+radiusPlus1)0){filterGaussBlurRGBA(imageData,radius);}};Kinetic.Factory.addGetterSetter(Kinetic.Node,'blurRadius',0,null,Kinetic.Factory.afterSetFilter);})();;(function(){function pixelAt(idata,x,y){var idx=(y*idata.width+x)*4;var d=[];d.push(idata.data[idx++],idata.data[idx++],idata.data[idx++],idata.data[idx++]);return d;} function rgbDistance(p1,p2){return Math.sqrt(Math.pow(p1[0]-p2[0],2)+Math.pow(p1[1]-p2[1],2)+Math.pow(p1[2]-p2[2],2));} function rgbMean(pTab){var m=[0,0,0];for(var i=0;i=0&&scy=0&&scx=0&&scy=0&&scx=255*4)?255:0;}} return maskResult;} function smoothEdgeMask(mask,sw,sh){var weights=[1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9];var side=Math.round(Math.sqrt(weights.length));var halfSide=Math.floor(side/2);var maskResult=[];for(var y=0;y=0&&scy=0&&scx255){return 255;} else if(val<0){return 0;} else{return Math.round(val);}});Kinetic.Factory.addGetterSetter(Kinetic.Node,'green',0,function(val){this._filterUpToDate=false;if(val>255){return 255;} else if(val<0){return 0;} else{return Math.round(val);}});Kinetic.Factory.addGetterSetter(Kinetic.Node,'blue',0,Kinetic.Validators.RGBComponent,Kinetic.Factory.afterSetFilter);})();;(function(){Kinetic.Filters.HSV=function(imageData){var data=imageData.data,nPixels=data.length,v=Math.pow(2,this.value()),s=Math.pow(2,this.saturation()),h=Math.abs((this.hue())+360)%360,i;var vsu=v*s*Math.cos(h*Math.PI/180),vsw=v*s*Math.sin(h*Math.PI/180);var rr=0.299*v+0.701*vsu+0.167*vsw,rg=0.587*v-0.587*vsu+0.330*vsw,rb=0.114*v-0.114*vsu-0.497*vsw;var gr=0.299*v-0.299*vsu-0.328*vsw,gg=0.587*v+0.413*vsu+0.035*vsw,gb=0.114*v-0.114*vsu+0.293*vsw;var br=0.299*v-0.300*vsu+1.250*vsw,bg=0.587*v-0.586*vsu-1.050*vsw,bb=0.114*v+0.886*vsu-0.200*vsw;var r,g,b,a;for(i=0;ih){otherY=0;} var offsetYOther=(y-1+otherY)*w*4;var x=w;do{var offset=offsetY+(x-1)*4;var otherX=dirX;if(x+otherX<1){otherX=0;} if(x+otherX>w){otherX=0;} var offsetOther=offsetYOther+(x-1+otherX)*4;var dR=data[offset]-data[offsetOther];var dG=data[offset+1]-data[offsetOther+1];var dB=data[offset+2]-data[offsetOther+2];var dif=dR;var absDif=dif>0?dif:-dif;var absG=dG>0?dG:-dG;var absB=dB>0?dB:-dB;if(absG>absDif){dif=dG;} if(absB>absDif){dif=dB;} dif*=strength;if(blend){var r=data[offset]+dif;var g=data[offset+1]+dif;var b=data[offset+2]+dif;data[offset]=(r>255)?255:(r<0?0:r);data[offset+1]=(g>255)?255:(g<0?0:g);data[offset+2]=(b>255)?255:(b<0?0:b);}else{var grey=greyLevel-dif;if(grey<0){grey=0;}else if(grey>255){grey=255;} data[offset]=data[offset+1]=data[offset+2]=grey;}}while(--x);}while(--y);};Kinetic.Factory.addGetterSetter(Kinetic.Node,'embossStrength',0.5,null,Kinetic.Factory.afterSetFilter);Kinetic.Factory.addGetterSetter(Kinetic.Node,'embossWhiteLevel',0.5,null,Kinetic.Factory.afterSetFilter);Kinetic.Factory.addGetterSetter(Kinetic.Node,'embossDirection','top-left',null,Kinetic.Factory.afterSetFilter);Kinetic.Factory.addGetterSetter(Kinetic.Node,'embossBlend',false,null,Kinetic.Factory.afterSetFilter);})();;(function(){function remap(fromValue,fromMin,fromMax,toMin,toMax){var fromRange=fromMax-fromMin,toRange=toMax-toMin,toValue;if(fromRange===0){return toMin+toRange/2;} if(toRange===0){return toMin;} toValue=(fromValue-fromMin)/fromRange;toValue=(toRange*toValue)+toMin;return toValue;} Kinetic.Filters.Enhance=function(imageData){var data=imageData.data,nSubPixels=data.length,rMin=data[0],rMax=rMin,r,gMin=data[1],gMax=gMin,g,bMin=data[2],bMax=bMin,b,aMin=data[3],aMax=aMin,i;var enhanceAmount=this.enhance();if(enhanceAmount===0){return;} for(i=0;irMax){rMax=r;} g=data[i+1];if(ggMax){gMax=g;} b=data[i+2];if(bbMax){bMax=b;} } if(rMax===rMin){rMax=255;rMin=0;} if(gMax===gMin){gMax=255;gMin=0;} if(bMax===bMin){bMax=255;bMin=0;} if(aMax===aMin){aMax=255;aMin=0;} var rMid,rGoalMax,rGoalMin,gMid,gGoalMax,gGoalMin,bMid,bGoalMax,aGoalMin,aMid,aGoalMax,bGoalMin;if(enhanceAmount>0){rGoalMax=rMax+enhanceAmount*(255-rMax);rGoalMin=rMin-enhanceAmount*(rMin-0);gGoalMax=gMax+enhanceAmount*(255-gMax);gGoalMin=gMin-enhanceAmount*(gMin-0);bGoalMax=bMax+enhanceAmount*(255-bMax);bGoalMin=bMin-enhanceAmount*(bMin-0);aGoalMax=aMax+enhanceAmount*(255-aMax);aGoalMin=aMin-enhanceAmount*(aMin-0);}else{rMid=(rMax+rMin)*0.5;rGoalMax=rMax+enhanceAmount*(rMax-rMid);rGoalMin=rMin+enhanceAmount*(rMin-rMid);gMid=(gMax+gMin)*0.5;gGoalMax=gMax+enhanceAmount*(gMax-gMid);gGoalMin=gMin+enhanceAmount*(gMin-gMid);bMid=(bMax+bMin)*0.5;bGoalMax=bMax+enhanceAmount*(bMax-bMid);bGoalMin=bMin+enhanceAmount*(bMin-bMid);aMid=(aMax+aMin)*0.5;aGoalMax=aMax+enhanceAmount*(aMax-aMid);aGoalMin=aMin+enhanceAmount*(aMin-aMid);} for(i=0;i=width){continue;} for(y=yBinStart;y=height){continue;} i=(width*y+x)*4;red+=imageData[i+0];green+=imageData[i+1];blue+=imageData[i+2];alpha+=imageData[i+3];pixelsInBin+=1;}} red=red/pixelsInBin;green=green/pixelsInBin;blue=blue/pixelsInBin;for(x=xBinStart;x=width){continue;} for(y=yBinStart;y=height){continue;} i=(width*y+x)*4;imageData[i+0]=red;imageData[i+1]=green;imageData[i+2]=blue;imageData[i+3]=alpha;}}}}};Kinetic.Factory.addGetterSetter(Kinetic.Node,'pixelSize',8,null,Kinetic.Factory.afterSetFilter);})();;(function(){Kinetic.Filters.Threshold=function(imageData){var level=this.threshold()*255,data=imageData.data,len=data.length,i;for(i=0;i255?255:r;data[offset+1]=g>255?255:g;data[offset+2]=b>255?255:b;data[offset+3]=data[offset+3];}while(--x);}while(--y);};})();;(function(){Kinetic.Filters.Solarize=function(imageData){var data=imageData.data,w=imageData.width,h=imageData.height,w4=w*4,y=h;do{var offsetY=(y-1)*w4;var x=w;do{var offset=offsetY+(x-1)*4;var r=data[offset];var g=data[offset+1];var b=data[offset+2];if(r>127){r=255-r;} if(g>127){g=255-g;} if(b>127){b=255-b;} data[offset]=r;data[offset+1]=g;data[offset+2]=b;}while(--x);}while(--y);};})();;(function(){var ToPolar=function(src,dst,opt){var srcPixels=src.data,dstPixels=dst.data,xSize=src.width,ySize=src.height,xMid=opt.polarCenterX||xSize/2,yMid=opt.polarCenterY||ySize/2,i,x,y,r=0,g=0,b=0,a=0;var rad,rMax=Math.sqrt(xMid*xMid+yMid*yMid);x=xSize-xMid;y=ySize-yMid;rad=Math.sqrt(x*x+y*y);rMax=(rad>rMax)?rad:rMax;var rSize=ySize,tSize=xSize,radius,theta;var conversion=360/tSize*Math.PI/180,sin,cos;for(theta=0;thetarMax)?rad:rMax;var rSize=ySize,tSize=xSize,radius,theta,phaseShift=opt.polarRotation||0;var x1,y1;for(x=0;xxSize){xStart=sectionSize;xEnd=0;xDelta=-1;} for(y=0;y0){lays=layers;} else{lays=[layers];} this.layers=lays;},getLayers:function(){return this.layers;},addLayer:function(layer){var layers=this.layers,len,n;if(layers){len=layers.length;for(n=0;nBATCH_DRAW_STOP_TIME_DIFF){that.batchAnim.stop();}},this);} this.lastBatchDrawTime=now();if(!this.batchAnim.isRunning()){this.draw();this.batchAnim.start();}};Kinetic.Stage.prototype.batchDraw=function(){this.getChildren().each(function(layer){layer.batchDraw();});};})((1,eval)('this'));;(function(){var blacklist={node:1,duration:1,easing:1,onFinish:1,yoyo:1},PAUSED=1,PLAYING=2,REVERSING=3,idCounter=0;Kinetic.Tween=function(config){var that=this,node=config.node,nodeId=node._id,duration=config.duration||1,easing=config.easing||Kinetic.Easings.Linear,yoyo=!!config.yoyo,key;this.node=node;this._id=idCounter++;this.anim=new Kinetic.Animation(function(){that.tween.onEnterFrame();},node.getLayer());this.tween=new Tween(key,function(i){that._tweenFunc(i);},easing,0,1,duration*1000,yoyo);this._addListeners();if(!Kinetic.Tween.attrs[nodeId]){Kinetic.Tween.attrs[nodeId]={};} if(!Kinetic.Tween.attrs[nodeId][this._id]){Kinetic.Tween.attrs[nodeId][this._id]={};} if(!Kinetic.Tween.tweens[nodeId]){Kinetic.Tween.tweens[nodeId]={};} for(key in config){if(blacklist[key]===undefined){this._addAttr(key,config[key]);}} this.reset();this.onFinish=config.onFinish;this.onReset=config.onReset;};Kinetic.Tween.attrs={};Kinetic.Tween.tweens={};Kinetic.Tween.prototype={_addAttr:function(key,end){var node=this.node,nodeId=node._id,start,diff,tweenId,n,len;tweenId=Kinetic.Tween.tweens[nodeId][key];if(tweenId){delete Kinetic.Tween.attrs[nodeId][tweenId][key];} start=node.getAttr(key);if(Kinetic.Util._isArray(end)){diff=[];len=end.length;for(n=0;nthis.duration){if(this.yoyo){this._time=this.duration;this.reverse();} else{this.finish();}} else if(t<0){if(this.yoyo){this._time=0;this.play();} else{this.reset();}} else{this._time=t;this.update();}},getTime:function(){return this._time;},setPosition:function(p){this.prevPos=this._pos;this.propFunc(p);this._pos=p;},getPosition:function(t){if(t===undefined){t=this._time;} return this.func(t,this.begin,this._change,this.duration);},play:function(){this.state=PLAYING;this._startTime=this.getTimer()-this._time;this.onEnterFrame();this.fire('onPlay');},reverse:function(){this.state=REVERSING;this._time=this.duration-this._time;this._startTime=this.getTimer()-this._time;this.onEnterFrame();this.fire('onReverse');},seek:function(t){this.pause();this._time=t;this.update();this.fire('onSeek');},reset:function(){this.pause();this._time=0;this.update();this.fire('onReset');},finish:function(){this.pause();this._time=this.duration;this.update();this.fire('onFinish');},update:function(){this.setPosition(this.getPosition(this._time));},onEnterFrame:function(){var t=this.getTimer()-this._startTime;if(this.state===PLAYING){this.setTime(t);} else if(this.state===REVERSING){this.setTime(this.duration-t);}},pause:function(){this.state=PAUSED;this.fire('onPause');},getTimer:function(){return new Date().getTime();}};Kinetic.Easings={'BackEaseIn':function(t,b,c,d){var s=1.70158;return c*(t/=d)*t*((s+1)*t-s)+b;},'BackEaseOut':function(t,b,c,d){var s=1.70158;return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b;},'BackEaseInOut':function(t,b,c,d){var s=1.70158;if((t/=d/2)<1){return c/2*(t*t*(((s*=(1.525))+1)*t-s))+b;} return c/2*((t-=2)*t*(((s*=(1.525))+1)*t+s)+2)+b;},'ElasticEaseIn':function(t,b,c,d,a,p){var s=0;if(t===0){return b;} if((t/=d)==1){return b+c;} if(!p){p=d*0.3;} if(!a||a0;},removeChildren:function(){var children=Kinetic.Collection.toCollection(this.children);var child;for(var i=0;i1){for(var i=0;i0;},destroy:function(){Kinetic.Node.prototype.destroy.call(this);delete Kinetic.shapes[this.colorKey];},_useBufferCanvas:function(){return(this.hasShadow()||this.getAbsoluteOpacity()!==1)&&this.hasFill()&&this.hasStroke()&&this.getStage();},drawScene:function(can,top){var layer=this.getLayer(),canvas=can||layer.getCanvas(),context=canvas.getContext(),cachedCanvas=this._cache.canvas,drawFunc=this.sceneFunc(),hasShadow=this.hasShadow(),stage,bufferCanvas,bufferContext;if(this.isVisible()){if(cachedCanvas){this._drawCachedSceneCanvas(context);} else if(drawFunc){context.save();if(this._useBufferCanvas()){stage=this.getStage();bufferCanvas=stage.bufferCanvas;bufferContext=bufferCanvas.getContext();bufferContext.clear();bufferContext.save();bufferContext._applyLineJoin(this);layer._applyTransform(this,bufferContext,top);drawFunc.call(this,bufferContext);bufferContext.restore();if(hasShadow){context.save();context._applyShadow(this);context.drawImage(bufferCanvas._canvas,0,0);context.restore();} context._applyOpacity(this);context.drawImage(bufferCanvas._canvas,0,0);} else{context._applyLineJoin(this);layer._applyTransform(this,context,top);if(hasShadow){context.save();context._applyShadow(this);drawFunc.call(this,context);context.restore();} context._applyOpacity(this);drawFunc.call(this,context);} context.restore();}} return this;},drawHit:function(can,top){var layer=this.getLayer(),canvas=can||layer.hitCanvas,context=canvas.getContext(),drawFunc=this.hitFunc()||this.sceneFunc(),cachedCanvas=this._cache.canvas,cachedHitCanvas=cachedCanvas&&cachedCanvas.hit;if(this.shouldDrawHit()){if(cachedHitCanvas){this._drawCachedHitCanvas(context);} else if(drawFunc){context.save();context._applyLineJoin(this);layer._applyTransform(this,context,top);drawFunc.call(this,context);context.restore();}} return this;},drawHitFromCache:function(alphaThreshold){var threshold=alphaThreshold||0,cachedCanvas=this._cache.canvas,sceneCanvas=this._getCachedSceneCanvas(),sceneContext=sceneCanvas.getContext(),hitCanvas=cachedCanvas.hit,hitContext=hitCanvas.getContext(),width=sceneCanvas.getWidth(),height=sceneCanvas.getHeight(),sceneImageData,sceneData,hitImageData,hitData,len,rgbColorKey,i,alpha;hitContext.clear();try{sceneImageData=sceneContext.getImageData(0,0,width,height);sceneData=sceneImageData.data;hitImageData=hitContext.getImageData(0,0,width,height);hitData=hitImageData.data;len=sceneData.length;rgbColorKey=Kinetic.Util._hexToRgb(this.colorKey);for(i=0;ithreshold){hitData[i]=rgbColorKey.r;hitData[i+1]=rgbColorKey.g;hitData[i+2]=rgbColorKey.b;hitData[i+3]=255;}} hitContext.putImageData(hitImageData,0,0);} catch(e){Kinetic.Util.warn('Unable to draw hit graph from cached scene canvas. '+e.message);} return this;},});Kinetic.Util.extend(Kinetic.Shape,Kinetic.Node);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'stroke');Kinetic.Factory.addGetterSetter(Kinetic.Shape,'strokeRed',0,Kinetic.Validators.RGBComponent);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'strokeGreen',0,Kinetic.Validators.RGBComponent);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'strokeBlue',0,Kinetic.Validators.RGBComponent);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'strokeAlpha',1,Kinetic.Validators.alphaComponent);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'strokeWidth',2);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'lineJoin');Kinetic.Factory.addGetterSetter(Kinetic.Shape,'lineCap');Kinetic.Factory.addGetterSetter(Kinetic.Shape,'sceneFunc');Kinetic.Factory.addGetterSetter(Kinetic.Shape,'hitFunc');Kinetic.Factory.addGetterSetter(Kinetic.Shape,'dash');Kinetic.Factory.addGetterSetter(Kinetic.Shape,'shadowColor');Kinetic.Factory.addGetterSetter(Kinetic.Shape,'shadowRed',0,Kinetic.Validators.RGBComponent);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'shadowGreen',0,Kinetic.Validators.RGBComponent);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'shadowBlue',0,Kinetic.Validators.RGBComponent);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'shadowAlpha',1,Kinetic.Validators.alphaComponent);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'shadowBlur');Kinetic.Factory.addGetterSetter(Kinetic.Shape,'shadowOpacity');Kinetic.Factory.addComponentsGetterSetter(Kinetic.Shape,'shadowOffset',['x','y']);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'shadowOffsetX',0);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'shadowOffsetY',0);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillPatternImage');Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fill');Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillRed',0,Kinetic.Validators.RGBComponent);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillGreen',0,Kinetic.Validators.RGBComponent);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillBlue',0,Kinetic.Validators.RGBComponent);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillAlpha',1,Kinetic.Validators.alphaComponent);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillPatternX',0);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillPatternY',0);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillLinearGradientColorStops');Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillRadialGradientStartRadius',0);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillRadialGradientEndRadius',0);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillRadialGradientColorStops');Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillPatternRepeat','repeat');Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillEnabled',true);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'strokeEnabled',true);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'shadowEnabled',true);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'dashEnabled',true);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'strokeScaleEnabled',true);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillPriority','color');Kinetic.Factory.addComponentsGetterSetter(Kinetic.Shape,'fillPatternOffset',['x','y']);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillPatternOffsetX',0);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillPatternOffsetY',0);Kinetic.Factory.addComponentsGetterSetter(Kinetic.Shape,'fillPatternScale',['x','y']);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillPatternScaleX',1);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillPatternScaleY',1);Kinetic.Factory.addComponentsGetterSetter(Kinetic.Shape,'fillLinearGradientStartPoint',['x','y']);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillLinearGradientStartPointX',0);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillLinearGradientStartPointY',0);Kinetic.Factory.addComponentsGetterSetter(Kinetic.Shape,'fillLinearGradientEndPoint',['x','y']);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillLinearGradientEndPointX',0);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillLinearGradientEndPointY',0);Kinetic.Factory.addComponentsGetterSetter(Kinetic.Shape,'fillRadialGradientStartPoint',['x','y']);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillRadialGradientStartPointX',0);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillRadialGradientStartPointY',0);Kinetic.Factory.addComponentsGetterSetter(Kinetic.Shape,'fillRadialGradientEndPoint',['x','y']);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillRadialGradientEndPointX',0);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillRadialGradientEndPointY',0);Kinetic.Factory.addGetterSetter(Kinetic.Shape,'fillPatternRotation',0);Kinetic.Factory.backCompat(Kinetic.Shape,{dashArray:'dash',getDashArray:'getDash',setDashArray:'getDash',drawFunc:'sceneFunc',getDrawFunc:'getSceneFunc',setDrawFunc:'setSceneFunc',drawHitFunc:'hitFunc',getDrawHitFunc:'getHitFunc',setDrawHitFunc:'setHitFunc'});Kinetic.Collection.mapMethods(Kinetic.Shape);})();;(function(){var STAGE='Stage',STRING='string',PX='px',MOUSEOUT='mouseout',MOUSELEAVE='mouseleave',MOUSEOVER='mouseover',MOUSEENTER='mouseenter',MOUSEMOVE='mousemove',MOUSEDOWN='mousedown',MOUSEUP='mouseup',CLICK='click',DBL_CLICK='dblclick',TOUCHSTART='touchstart',TOUCHEND='touchend',TAP='tap',DBL_TAP='dbltap',TOUCHMOVE='touchmove',CONTENT_MOUSEOUT='contentMouseout',CONTENT_MOUSELEAVE='contentMouseleave',CONTENT_MOUSEOVER='contentMouseover',CONTENT_MOUSEENTER='contentMouseenter',CONTENT_MOUSEMOVE='contentMousemove',CONTENT_MOUSEDOWN='contentMousedown',CONTENT_MOUSEUP='contentMouseup',CONTENT_CLICK='contentClick',CONTENT_DBL_CLICK='contentDblclick',CONTENT_TOUCHSTART='contentTouchstart',CONTENT_TOUCHEND='contentTouchend',CONTENT_TAP='contentTap',CONTENT_DBL_TAP='contentDbltap',CONTENT_TOUCHMOVE='contentTouchmove',DIV='div',RELATIVE='relative',INLINE_BLOCK='inline-block',KINETICJS_CONTENT='kineticjs-content',SPACE=' ',UNDERSCORE='_',CONTAINER='container',EMPTY_STRING='',EVENTS=[MOUSEDOWN,MOUSEMOVE,MOUSEUP,MOUSEOUT,TOUCHSTART,TOUCHMOVE,TOUCHEND,MOUSEOVER],eventsLength=EVENTS.length;function addEvent(ctx,eventName){ctx.content.addEventListener(eventName,function(evt){ctx[UNDERSCORE+eventName](evt);},false);} Kinetic.Util.addMethods(Kinetic.Stage,{___init:function(config){this.nodeType=STAGE;Kinetic.Container.call(this,config);this._id=Kinetic.idCounter++;this._buildDOM();this._bindContentEvents();this._enableNestedTransforms=false;Kinetic.stages.push(this);},_validateAdd:function(child){if(child.getType()!=='Layer'){Kinetic.Util.error('You may only add layers to the stage.');}},setContainer:function(container){if(typeof container===STRING){var id=container;container=Kinetic.document.getElementById(container);if(!container){throw'Can not find container in document with id '+id;}} this._setAttr(CONTAINER,container);return this;},shouldDrawHit:function(){return true;},draw:function(){Kinetic.Node.prototype.draw.call(this);return this;},setHeight:function(height){Kinetic.Node.prototype.setHeight.call(this,height);this._resizeDOM();return this;},setWidth:function(width){Kinetic.Node.prototype.setWidth.call(this,width);this._resizeDOM();return this;},clear:function(){var layers=this.children,len=layers.length,n;for(n=0;n-1){Kinetic.stages.splice(index,1);}},getPointerPosition:function(){return this.pointerPos;},getStage:function(){return this;},getContent:function(){return this.content;},toDataURL:function(config){config=config||{};var mimeType=config.mimeType||null,quality=config.quality||null,x=config.x||0,y=config.y||0,canvas=new Kinetic.SceneCanvas({width:config.width||this.getWidth(),height:config.height||this.getHeight(),pixelRatio:1}),_context=canvas.getContext()._context,layers=this.children;if(x||y){_context.translate(-1*x,-1*y);} function drawLayer(n){var layer=layers[n],layerUrl=layer.toDataURL(),imageObj=new Kinetic.window.Image();imageObj.onload=function(){_context.drawImage(imageObj,0,0);if(n=0;n--){shape=layers[n].getIntersection(pos);if(shape){return shape;}} return null;},_resizeDOM:function(){if(this.content){var width=this.getWidth(),height=this.getHeight(),layers=this.getChildren(),len=layers.length,n,layer;this.content.style.width=width+PX;this.content.style.height=height+PX;this.bufferCanvas.setSize(width,height);this.bufferHitCanvas.setSize(width,height);for(n=0;n1){for(var i=0;i0){touch=evt.touches[0];x=touch.clientX-contentPosition.left;y=touch.clientY-contentPosition.top;}} else{if(offsetX!==undefined){x=offsetX;y=evt.offsetY;} else if(Kinetic.UA.browser==='mozilla'){x=evt.layerX;y=evt.layerY;} else if(clientX!==undefined&&contentPosition){x=clientX-contentPosition.left;y=evt.clientY-contentPosition.top;}} if(x!==null&&y!==null){this.pointerPos={x:x,y:y};}},_getContentPosition:function(){var rect=this.content.getBoundingClientRect?this.content.getBoundingClientRect():{top:0,left:0};return{top:rect.top,left:rect.left};},_buildDOM:function(){var container=this.getContainer();if(!container){if(Kinetic.Util.isBrowser()){throw'Stage has not container. But container is required';}else{container=Kinetic.document.createElement(DIV);}} container.innerHTML=EMPTY_STRING;this.content=Kinetic.document.createElement(DIV);this.content.style.position=RELATIVE;this.content.style.display=INLINE_BLOCK;this.content.className=KINETICJS_CONTENT;this.content.setAttribute('role','presentation');container.appendChild(this.content);this.bufferCanvas=new Kinetic.SceneCanvas({pixelRatio:1});this.bufferHitCanvas=new Kinetic.HitCanvas();this._resizeDOM();},_onContent:function(typesStr,handler){var types=typesStr.split(SPACE),len=types.length,n,baseEvent;for(n=0;n0){return{antialiased:true};} else{return{};}},drawScene:function(can,top){var layer=this.getLayer(),canvas=can||(layer&&layer.getCanvas());this._fire(BEFORE_DRAW,{node:this});if(this.getClearBeforeDraw()){canvas.getContext().clear();} Kinetic.Container.prototype.drawScene.call(this,canvas,top);this._fire(DRAW,{node:this});return this;},_applyTransform:function(shape,context,top){var m=shape.getAbsoluteTransform(top).getMatrix();context.transform(m[0],m[1],m[2],m[3],m[4],m[5]);},drawHit:function(can,top){var layer=this.getLayer(),canvas=can||(layer&&layer.hitCanvas);if(layer&&layer.getClearBeforeDraw()){layer.getHitCanvas().getContext().clear();} Kinetic.Container.prototype.drawHit.call(this,canvas,top);return this;},clear:function(bounds){this.getContext().clear(bounds);this.getHitCanvas().getContext().clear(bounds);return this;},setVisible:function(visible){Kinetic.Node.prototype.setVisible.call(this,visible);if(visible){this.getCanvas()._canvas.style.display='block';this.hitCanvas._canvas.style.display='block';} else{this.getCanvas()._canvas.style.display='none';this.hitCanvas._canvas.style.display='none';} return this;},enableHitGraph:function(){this.setHitGraphEnabled(true);return this;},disableHitGraph:function(){this.setHitGraphEnabled(false);return this;}});Kinetic.Util.extend(Kinetic.Layer,Kinetic.BaseLayer);Kinetic.Factory.addGetterSetter(Kinetic.Layer,'hitGraphEnabled',true);Kinetic.Collection.mapMethods(Kinetic.Layer);})();;(function(){var HASH='#',BEFORE_DRAW='beforeDraw',DRAW='draw';Kinetic.Util.addMethods(Kinetic.FastLayer,{____init:function(config){this.nodeType='Layer';this.canvas=new Kinetic.SceneCanvas();Kinetic.BaseLayer.call(this,config);},_validateAdd:function(child){var type=child.getType();if(type!=='Shape'){Kinetic.Util.error('You may only add shapes to a fast layer.');}},_setCanvasSize:function(width,height){this.canvas.setSize(width,height);},hitGraphEnabled:function(){return false;},getIntersection:function(){return null;},drawScene:function(can){var layer=this.getLayer(),canvas=can||(layer&&layer.getCanvas());if(this.getClearBeforeDraw()){canvas.getContext().clear();} Kinetic.Container.prototype.drawScene.call(this,canvas);return this;},_applyTransform:function(shape,context,top){if(!top||top._id!==this._id){var m=shape.getTransform().getMatrix();context.transform(m[0],m[1],m[2],m[3],m[4],m[5]);}},draw:function(){this.drawScene();return this;},clear:function(bounds){this.getContext().clear(bounds);return this;},setVisible:function(visible){Kinetic.Node.prototype.setVisible.call(this,visible);if(visible){this.getCanvas()._canvas.style.display='block';} else{this.getCanvas()._canvas.style.display='none';} return this;}});Kinetic.Util.extend(Kinetic.FastLayer,Kinetic.BaseLayer);Kinetic.Collection.mapMethods(Kinetic.FastLayer);})();;(function(){Kinetic.Util.addMethods(Kinetic.Group,{___init:function(config){this.nodeType='Group';Kinetic.Container.call(this,config);},_validateAdd:function(child){var type=child.getType();if(type!=='Group'&&type!=='Shape'){Kinetic.Util.error('You may only add groups and shapes to groups.');}}});Kinetic.Util.extend(Kinetic.Group,Kinetic.Container);Kinetic.Collection.mapMethods(Kinetic.Group);})();;(function(){Kinetic.Rect=function(config){this.___init(config);};Kinetic.Rect.prototype={___init:function(config){Kinetic.Shape.call(this,config);this.className='Rect';this.sceneFunc(this._sceneFunc);},_sceneFunc:function(context){var cornerRadius=this.getCornerRadius(),width=this.getWidth(),height=this.getHeight();context.beginPath();if(!cornerRadius){context.rect(0,0,width,height);} else{context.moveTo(cornerRadius,0);context.lineTo(width-cornerRadius,0);context.arc(width-cornerRadius,cornerRadius,cornerRadius,Math.PI*3/2,0,false);context.lineTo(width,height-cornerRadius);context.arc(width-cornerRadius,height-cornerRadius,cornerRadius,0,Math.PI/2,false);context.lineTo(cornerRadius,height);context.arc(cornerRadius,height-cornerRadius,cornerRadius,Math.PI/2,Math.PI,false);context.lineTo(0,cornerRadius);context.arc(cornerRadius,cornerRadius,cornerRadius,Math.PI,Math.PI*3/2,false);} context.closePath();context.fillStrokeShape(this);}};Kinetic.Util.extend(Kinetic.Rect,Kinetic.Shape);Kinetic.Factory.addGetterSetter(Kinetic.Rect,'cornerRadius',0);Kinetic.Collection.mapMethods(Kinetic.Rect);})();;(function(){var PIx2=(Math.PI*2)-0.0001,CIRCLE='Circle';Kinetic.Circle=function(config){this.___init(config);};Kinetic.Circle.prototype={___init:function(config){Kinetic.Shape.call(this,config);this.className=CIRCLE;this.sceneFunc(this._sceneFunc);},_sceneFunc:function(context){context.beginPath();context.arc(0,0,this.getRadius(),0,PIx2,false);context.closePath();context.fillStrokeShape(this);},getWidth:function(){return this.getRadius()*2;},getHeight:function(){return this.getRadius()*2;},setWidth:function(width){Kinetic.Node.prototype.setWidth.call(this,width);this.setRadius(width/2);},setHeight:function(height){Kinetic.Node.prototype.setHeight.call(this,height);this.setRadius(height/2);}};Kinetic.Util.extend(Kinetic.Circle,Kinetic.Shape);Kinetic.Factory.addGetterSetter(Kinetic.Circle,'radius',0);Kinetic.Collection.mapMethods(Kinetic.Circle);})();;(function(){var PIx2=(Math.PI*2)-0.0001,ELLIPSE='Ellipse';Kinetic.Ellipse=function(config){this.___init(config);};Kinetic.Ellipse.prototype={___init:function(config){Kinetic.Shape.call(this,config);this.className=ELLIPSE;this.sceneFunc(this._sceneFunc);},_sceneFunc:function(context){var r=this.getRadius(),rx=r.x,ry=r.y;context.beginPath();context.save();if(rx!==ry){context.scale(1,ry/rx);} context.arc(0,0,rx,0,PIx2,false);context.restore();context.closePath();context.fillStrokeShape(this);},getWidth:function(){return this.getRadius().x*2;},getHeight:function(){return this.getRadius().y*2;},setWidth:function(width){Kinetic.Node.prototype.setWidth.call(this,width);this.setRadius({x:width/2});},setHeight:function(height){Kinetic.Node.prototype.setHeight.call(this,height);this.setRadius({y:height/2});}};Kinetic.Util.extend(Kinetic.Ellipse,Kinetic.Shape);Kinetic.Factory.addComponentsGetterSetter(Kinetic.Ellipse,'radius',['x','y']);Kinetic.Factory.addGetterSetter(Kinetic.Ellipse,'radiusX',0);Kinetic.Factory.addGetterSetter(Kinetic.Ellipse,'radiusY',0);Kinetic.Collection.mapMethods(Kinetic.Ellipse);})();;(function(){var PIx2=(Math.PI*2)-0.0001;Kinetic.Ring=function(config){this.___init(config);};Kinetic.Ring.prototype={___init:function(config){Kinetic.Shape.call(this,config);this.className='Ring';this.sceneFunc(this._sceneFunc);},_sceneFunc:function(context){context.beginPath();context.arc(0,0,this.getInnerRadius(),0,PIx2,false);context.moveTo(this.getOuterRadius(),0);context.arc(0,0,this.getOuterRadius(),PIx2,0,true);context.closePath();context.fillStrokeShape(this);},getWidth:function(){return this.getOuterRadius()*2;},getHeight:function(){return this.getOuterRadius()*2;},setWidth:function(width){Kinetic.Node.prototype.setWidth.call(this,width);this.setOuterRadius(width/2);},setHeight:function(height){Kinetic.Node.prototype.setHeight.call(this,height);this.setOuterRadius(height/2);}};Kinetic.Util.extend(Kinetic.Ring,Kinetic.Shape);Kinetic.Factory.addGetterSetter(Kinetic.Ring,'innerRadius',0);Kinetic.Factory.addGetterSetter(Kinetic.Ring,'outerRadius',0);Kinetic.Collection.mapMethods(Kinetic.Ring);})();;(function(){Kinetic.Wedge=function(config){this.___init(config);};Kinetic.Wedge.prototype={___init:function(config){Kinetic.Shape.call(this,config);this.className='Wedge';this.sceneFunc(this._sceneFunc);},_sceneFunc:function(context){context.beginPath();context.arc(0,0,this.getRadius(),0,Kinetic.getAngle(this.getAngle()),this.getClockwise());context.lineTo(0,0);context.closePath();context.fillStrokeShape(this);}};Kinetic.Util.extend(Kinetic.Wedge,Kinetic.Shape);Kinetic.Factory.addGetterSetter(Kinetic.Wedge,'radius',0);Kinetic.Factory.addGetterSetter(Kinetic.Wedge,'angle',0);Kinetic.Factory.addGetterSetter(Kinetic.Wedge,'clockwise',false);Kinetic.Factory.backCompat(Kinetic.Wedge,{angleDeg:'angle',getAngleDeg:'getAngle',setAngleDeg:'setAngle'});Kinetic.Collection.mapMethods(Kinetic.Wedge);})();;(function(){var PI_OVER_180=Math.PI/180;Kinetic.Arc=function(config){this.___init(config);};Kinetic.Arc.prototype={___init:function(config){Kinetic.Shape.call(this,config);this.className='Arc';this.sceneFunc(this._sceneFunc);},_sceneFunc:function(context){var angle=Kinetic.getAngle(this.angle()),clockwise=this.clockwise();context.beginPath();context.arc(0,0,this.getOuterRadius(),0,angle,clockwise);context.arc(0,0,this.getInnerRadius(),angle,0,!clockwise);context.closePath();context.fillStrokeShape(this);}};Kinetic.Util.extend(Kinetic.Arc,Kinetic.Shape);Kinetic.Factory.addGetterSetter(Kinetic.Arc,'innerRadius',0);Kinetic.Factory.addGetterSetter(Kinetic.Arc,'outerRadius',0);Kinetic.Factory.addGetterSetter(Kinetic.Arc,'angle',0);Kinetic.Factory.addGetterSetter(Kinetic.Arc,'clockwise',false);Kinetic.Collection.mapMethods(Kinetic.Arc);})();;(function(){var IMAGE='Image';Kinetic.Image=function(config){this.___init(config);};Kinetic.Image.prototype={___init:function(config){Kinetic.Shape.call(this,config);this.className=IMAGE;this.sceneFunc(this._sceneFunc);this.hitFunc(this._hitFunc);},_useBufferCanvas:function(){return(this.hasShadow()||this.getAbsoluteOpacity()!==1)&&this.hasStroke();},_sceneFunc:function(context){var width=this.getWidth(),height=this.getHeight(),image=this.getImage(),crop,cropWidth,cropHeight,params;if(image){crop=this.getCrop();cropWidth=crop.width;cropHeight=crop.height;if(cropWidth&&cropHeight){params=[image,crop.x,crop.y,cropWidth,cropHeight,0,0,width,height];}else{params=[image,0,0,width,height];}} context.beginPath();context.rect(0,0,width,height);context.closePath();context.fillStrokeShape(this);if(image){context.drawImage.apply(context,params);}},_hitFunc:function(context){var width=this.getWidth(),height=this.getHeight();context.beginPath();context.rect(0,0,width,height);context.closePath();context.fillStrokeShape(this);},getWidth:function(){var image=this.getImage();return this.attrs.width||(image?image.width:0);},getHeight:function(){var image=this.getImage();return this.attrs.height||(image?image.height:0);}};Kinetic.Util.extend(Kinetic.Image,Kinetic.Shape);Kinetic.Factory.addGetterSetter(Kinetic.Image,'image');Kinetic.Factory.addComponentsGetterSetter(Kinetic.Image,'crop',['x','y','width','height']);Kinetic.Factory.addGetterSetter(Kinetic.Image,'cropX',0);Kinetic.Factory.addGetterSetter(Kinetic.Image,'cropY',0);Kinetic.Factory.addGetterSetter(Kinetic.Image,'cropWidth',0);Kinetic.Factory.addGetterSetter(Kinetic.Image,'cropHeight',0);Kinetic.Collection.mapMethods(Kinetic.Image);})();;(function(){var AUTO='auto',CENTER='center',CHANGE_KINETIC='Change.kinetic',CONTEXT_2D='2d',DASH='-',EMPTY_STRING='',LEFT='left',TEXT='text',TEXT_UPPER='Text',MIDDLE='middle',NORMAL='normal',PX_SPACE='px ',SPACE=' ',RIGHT='right',WORD='word',CHAR='char',NONE='none',ATTR_CHANGE_LIST=['fontFamily','fontSize','fontStyle','fontVariant','padding','align','lineHeight','text','width','height','wrap'],attrChangeListLen=ATTR_CHANGE_LIST.length,dummyContext=Kinetic.Util.createCanvasElement().getContext(CONTEXT_2D);Kinetic.Text=function(config){this.___init(config);};function _fillFunc(context){context.fillText(this.partialText,0,0);} function _strokeFunc(context){context.strokeText(this.partialText,0,0);} Kinetic.Text.prototype={___init:function(config){var that=this;if(config.width===undefined){config.width=AUTO;} if(config.height===undefined){config.height=AUTO;} Kinetic.Shape.call(this,config);this._fillFunc=_fillFunc;this._strokeFunc=_strokeFunc;this.className=TEXT_UPPER;for(var n=0;nmaxWidth){while(line.length>0){var low=0,high=line.length,match='',matchWidth=0;while(low>>1,substr=line.slice(0,mid+1),substrWidth=this._getTextWidth(substr);if(substrWidth<=maxWidth){low=mid+1;match=substr;matchWidth=substrWidth;}else{high=mid;}} if(match){if(wrapAtWord){var wrapIndex=Math.max(match.lastIndexOf(SPACE),match.lastIndexOf(DASH))+1;if(wrapIndex>0){low=wrapIndex;match=match.slice(0,low);matchWidth=this._getTextWidth(match);}} this._addTextLine(match,matchWidth);textWidth=Math.max(textWidth,matchWidth);currentHeightPx+=lineHeightPx;if(!shouldWrap||(fixedHeight&¤tHeightPx+lineHeightPx>maxHeightPx)){break;} line=line.slice(low);if(line.length>0){lineWidth=this._getTextWidth(line);if(lineWidth<=maxWidth){this._addTextLine(line,lineWidth);currentHeightPx+=lineHeightPx;textWidth=Math.max(textWidth,lineWidth);break;}}}else{break;}}}else{this._addTextLine(line,lineWidth);currentHeightPx+=lineHeightPx;textWidth=Math.max(textWidth,lineWidth);} if(fixedHeight&¤tHeightPx+lineHeightPx>maxHeightPx){break;}} dummyContext.restore();this.textHeight=fontSize;this.textWidth=textWidth;}};Kinetic.Util.extend(Kinetic.Text,Kinetic.Shape);Kinetic.Factory.addGetterSetter(Kinetic.Text,'fontFamily','Arial');Kinetic.Factory.addGetterSetter(Kinetic.Text,'fontSize',12);Kinetic.Factory.addGetterSetter(Kinetic.Text,'fontStyle',NORMAL);Kinetic.Factory.addGetterSetter(Kinetic.Text,'fontVariant',NORMAL);Kinetic.Factory.addGetterSetter(Kinetic.Text,'padding',0);Kinetic.Factory.addGetterSetter(Kinetic.Text,'align',LEFT);Kinetic.Factory.addGetterSetter(Kinetic.Text,'lineHeight',1);Kinetic.Factory.addGetterSetter(Kinetic.Text,'wrap',WORD);Kinetic.Factory.addGetter(Kinetic.Text,'text',EMPTY_STRING);Kinetic.Factory.addOverloadedGetterSetter(Kinetic.Text,'text');Kinetic.Collection.mapMethods(Kinetic.Text);})();;(function(){Kinetic.Line=function(config){this.___init(config);};Kinetic.Line.prototype={___init:function(config){Kinetic.Shape.call(this,config);this.className='Line';this.on('pointsChange.kinetic tensionChange.kinetic closedChange.kinetic',function(){this._clearCache('tensionPoints');});this.sceneFunc(this._sceneFunc);},_sceneFunc:function(context){var points=this.getPoints(),length=points.length,tension=this.getTension(),closed=this.getClosed(),tp,len,n;context.beginPath();context.moveTo(points[0],points[1]);if(tension!==0&&length>4){tp=this.getTensionPoints();len=tp.length;n=closed?0:4;if(!closed){context.quadraticCurveTo(tp[0],tp[1],tp[2],tp[3]);} while(nry)?rx:ry;var scaleX=(rx>ry)?1:rx/ry;var scaleY=(rx>ry)?ry/rx:1;context.translate(cx,cy);context.rotate(psi);context.scale(scaleX,scaleY);context.arc(0,0,r,theta,theta+dTheta,1-fs);context.scale(1/scaleX,1/scaleY);context.rotate(-psi);context.translate(-cx,-cy);break;case'z':context.closePath();closedPath=true;break;}} if(closedPath){context.fillStrokeShape(this);} else{context.strokeShape(this);}}};Kinetic.Util.extend(Kinetic.Path,Kinetic.Shape);Kinetic.Path.getLineLength=function(x1,y1,x2,y2){return Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));};Kinetic.Path.getPointOnLine=function(dist,P1x,P1y,P2x,P2y,fromX,fromY){if(fromX===undefined){fromX=P1x;} if(fromY===undefined){fromY=P1y;} var m=(P2y-P1y)/((P2x-P1x)+0.00000001);var run=Math.sqrt(dist*dist/(1+m*m));if(P2x0&&p[0]===''){p.shift();} for(var i=0;i0){if(isNaN(p[0])){break;} var cmd=null;var points=[];var startX=cpx,startY=cpy;var prevCmd,ctlPtx,ctlPty;var rx,ry,psi,fa,fs,x1,y1;switch(c){case'l':cpx+=p.shift();cpy+=p.shift();cmd='L';points.push(cpx,cpy);break;case'L':cpx=p.shift();cpy=p.shift();points.push(cpx,cpy);break;case'm':var dx=p.shift();var dy=p.shift();cpx+=dx;cpy+=dy;cmd='M';if(ca.length>2&&ca[ca.length-1].command==='z'){for(var idx=ca.length-2;idx>=0;idx--){if(ca[idx].command==='M'){cpx=ca[idx].points[0]+dx;cpy=ca[idx].points[1]+dy;break;}}} points.push(cpx,cpy);c='l';break;case'M':cpx=p.shift();cpy=p.shift();cmd='M';points.push(cpx,cpy);c='L';break;case'h':cpx+=p.shift();cmd='L';points.push(cpx,cpy);break;case'H':cpx=p.shift();cmd='L';points.push(cpx,cpy);break;case'v':cpy+=p.shift();cmd='L';points.push(cpx,cpy);break;case'V':cpy=p.shift();cmd='L';points.push(cpx,cpy);break;case'C':points.push(p.shift(),p.shift(),p.shift(),p.shift());cpx=p.shift();cpy=p.shift();points.push(cpx,cpy);break;case'c':points.push(cpx+p.shift(),cpy+p.shift(),cpx+p.shift(),cpy+p.shift());cpx+=p.shift();cpy+=p.shift();cmd='C';points.push(cpx,cpy);break;case'S':ctlPtx=cpx;ctlPty=cpy;prevCmd=ca[ca.length-1];if(prevCmd.command==='C'){ctlPtx=cpx+(cpx-prevCmd.points[2]);ctlPty=cpy+(cpy-prevCmd.points[3]);} points.push(ctlPtx,ctlPty,p.shift(),p.shift());cpx=p.shift();cpy=p.shift();cmd='C';points.push(cpx,cpy);break;case's':ctlPtx=cpx;ctlPty=cpy;prevCmd=ca[ca.length-1];if(prevCmd.command==='C'){ctlPtx=cpx+(cpx-prevCmd.points[2]);ctlPty=cpy+(cpy-prevCmd.points[3]);} points.push(ctlPtx,ctlPty,cpx+p.shift(),cpy+p.shift());cpx+=p.shift();cpy+=p.shift();cmd='C';points.push(cpx,cpy);break;case'Q':points.push(p.shift(),p.shift());cpx=p.shift();cpy=p.shift();points.push(cpx,cpy);break;case'q':points.push(cpx+p.shift(),cpy+p.shift());cpx+=p.shift();cpy+=p.shift();cmd='Q';points.push(cpx,cpy);break;case'T':ctlPtx=cpx;ctlPty=cpy;prevCmd=ca[ca.length-1];if(prevCmd.command==='Q'){ctlPtx=cpx+(cpx-prevCmd.points[0]);ctlPty=cpy+(cpy-prevCmd.points[1]);} cpx=p.shift();cpy=p.shift();cmd='Q';points.push(ctlPtx,ctlPty,cpx,cpy);break;case't':ctlPtx=cpx;ctlPty=cpy;prevCmd=ca[ca.length-1];if(prevCmd.command==='Q'){ctlPtx=cpx+(cpx-prevCmd.points[0]);ctlPty=cpy+(cpy-prevCmd.points[1]);} cpx+=p.shift();cpy+=p.shift();cmd='Q';points.push(ctlPtx,ctlPty,cpx,cpy);break;case'A':rx=p.shift();ry=p.shift();psi=p.shift();fa=p.shift();fs=p.shift();x1=cpx;y1=cpy;cpx=p.shift();cpy=p.shift();cmd='A';points=this.convertEndpointToCenterParameterization(x1,y1,cpx,cpy,fa,fs,rx,ry,psi);break;case'a':rx=p.shift();ry=p.shift();psi=p.shift();fa=p.shift();fs=p.shift();x1=cpx;y1=cpy;cpx+=p.shift();cpy+=p.shift();cmd='A';points=this.convertEndpointToCenterParameterization(x1,y1,cpx,cpy,fa,fs,rx,ry,psi);break;} ca.push({command:cmd||c,points:points,start:{x:startX,y:startY},pathLength:this.calcLength(startX,startY,cmd||c,points)});} if(c==='z'||c==='Z'){ca.push({command:'z',points:[],start:undefined,pathLength:0});}} return ca;};Kinetic.Path.calcLength=function(x,y,cmd,points){var len,p1,p2,t;var path=Kinetic.Path;switch(cmd){case'L':return path.getLineLength(x,y,points[0],points[1]);case'C':len=0.0;p1=path.getPointOnCubicBezier(0,x,y,points[0],points[1],points[2],points[3],points[4],points[5]);for(t=0.01;t<=1;t+=0.01){p2=path.getPointOnCubicBezier(t,x,y,points[0],points[1],points[2],points[3],points[4],points[5]);len+=path.getLineLength(p1.x,p1.y,p2.x,p2.y);p1=p2;} return len;case'Q':len=0.0;p1=path.getPointOnQuadraticBezier(0,x,y,points[0],points[1],points[2],points[3]);for(t=0.01;t<=1;t+=0.01){p2=path.getPointOnQuadraticBezier(t,x,y,points[0],points[1],points[2],points[3]);len+=path.getLineLength(p1.x,p1.y,p2.x,p2.y);p1=p2;} return len;case'A':len=0.0;var start=points[4];var dTheta=points[5];var end=points[4]+dTheta;var inc=Math.PI/180.0;if(Math.abs(start-end)end;t-=inc){p2=path.getPointOnEllipticalArc(points[0],points[1],points[2],points[3],t,0);len+=path.getLineLength(p1.x,p1.y,p2.x,p2.y);p1=p2;}} else{for(t=start+inc;t1){rx*=Math.sqrt(lambda);ry*=Math.sqrt(lambda);} var f=Math.sqrt((((rx*rx)*(ry*ry))-((rx*rx)*(yp*yp))-((ry*ry)*(xp*xp)))/((rx*rx)*(yp*yp)+(ry*ry)*(xp*xp)));if(fa===fs){f*=-1;} if(isNaN(f)){f=0;} var cxp=f*rx*yp/ry;var cyp=f*-ry*xp/rx;var cx=(x1+x2)/2.0+Math.cos(psi)*cxp-Math.sin(psi)*cyp;var cy=(y1+y2)/2.0+Math.sin(psi)*cxp+Math.cos(psi)*cyp;var vMag=function(v){return Math.sqrt(v[0]*v[0]+v[1]*v[1]);};var vRatio=function(u,v){return(u[0]*v[0]+u[1]*v[1])/(vMag(u)*vMag(v));};var vAngle=function(u,v){return(u[0]*v[1]=1){dTheta=0;} if(fs===0&&dTheta>0){dTheta=dTheta-2*Math.PI;} if(fs===1&&dTheta<0){dTheta=dTheta+2*Math.PI;} return[cx,cy,rx,ry,theta,dTheta,psi,fs];};Kinetic.Factory.addGetterSetter(Kinetic.Path,'data');Kinetic.Collection.mapMethods(Kinetic.Path);})();;(function(){var EMPTY_STRING='',NORMAL='normal';Kinetic.TextPath=function(config){this.___init(config);};function _fillFunc(context){context.fillText(this.partialText,0,0);} function _strokeFunc(context){context.strokeText(this.partialText,0,0);} Kinetic.TextPath.prototype={___init:function(config){var that=this;this.dummyCanvas=Kinetic.Util.createCanvasElement();this.dataArray=[];Kinetic.Shape.call(this,config);this._fillFunc=_fillFunc;this._strokeFunc=_strokeFunc;this._fillFuncHit=_fillFunc;this._strokeFuncHit=_strokeFunc;this.className='TextPath';this.dataArray=Kinetic.Path.parsePathData(this.attrs.data);this.on('dataChange.kinetic',function(){that.dataArray=Kinetic.Path.parsePathData(this.attrs.data);});this.on('textChange.kinetic textStroke.kinetic textStrokeWidth.kinetic',that._setTextData);that._setTextData();this.sceneFunc(this._sceneFunc);},_sceneFunc:function(context){context.setAttr('font',this._getContextFont());context.setAttr('textBaseline','middle');context.setAttr('textAlign','left');context.save();var glyphInfo=this.glyphInfo;for(var i=0;i0){pIndex=i;return pathData[i];} else if(pathData[i].command=='M'){p0={x:pathData[i].points[0],y:pathData[i].points[1]};}} return{};};var findSegmentToFitCharacter=function(c){var glyphWidth=that._getTextSize(c).width;var currLen=0;var attempts=0;p1=undefined;while(Math.abs(glyphWidth-currLen)/glyphWidth>0.01&&attempts<25){attempts++;var cumulativePathLength=currLen;while(pathCmd===undefined){pathCmd=getNextPathSegment();if(pathCmd&&cumulativePathLength+pathCmd.pathLengthglyphWidth){p1=Kinetic.Path.getPointOnLine(glyphWidth,p0.x,p0.y,pathCmd.points[0],pathCmd.points[1],p0.x,p0.y);} else{pathCmd=undefined;} break;case'A':var start=pathCmd.points[4];var dTheta=pathCmd.points[5];var end=pathCmd.points[4]+dTheta;if(currentT===0){currentT=start+0.00000001;} else if(glyphWidth>currLen){currentT+=(Math.PI/180.0)*dTheta/Math.abs(dTheta);} else{currentT-=Math.PI/360.0*dTheta/Math.abs(dTheta);} if(dTheta<0&¤tT=0&¤tT>end){currentT=end;needNewSegment=true;} p1=Kinetic.Path.getPointOnEllipticalArc(pathCmd.points[0],pathCmd.points[1],pathCmd.points[2],pathCmd.points[3],currentT,pathCmd.points[6]);break;case'C':if(currentT===0){if(glyphWidth>pathCmd.pathLength){currentT=0.00000001;} else{currentT=glyphWidth/pathCmd.pathLength;}} else if(glyphWidth>currLen){currentT+=(glyphWidth-currLen)/pathCmd.pathLength;} else{currentT-=(currLen-glyphWidth)/pathCmd.pathLength;} if(currentT>1.0){currentT=1.0;needNewSegment=true;} p1=Kinetic.Path.getPointOnCubicBezier(currentT,pathCmd.start.x,pathCmd.start.y,pathCmd.points[0],pathCmd.points[1],pathCmd.points[2],pathCmd.points[3],pathCmd.points[4],pathCmd.points[5]);break;case'Q':if(currentT===0){currentT=glyphWidth/pathCmd.pathLength;} else if(glyphWidth>currLen){currentT+=(glyphWidth-currLen)/pathCmd.pathLength;} else{currentT-=(currLen-glyphWidth)/pathCmd.pathLength;} if(currentT>1.0){currentT=1.0;needNewSegment=true;} p1=Kinetic.Path.getPointOnQuadraticBezier(currentT,pathCmd.start.x,pathCmd.start.y,pathCmd.points[0],pathCmd.points[1],pathCmd.points[2],pathCmd.points[3]);break;} if(p1!==undefined){currLen=Kinetic.Path.getLineLength(p0.x,p0.y,p1.x,p1.y);} if(needNewSegment){needNewSegment=false;pathCmd=undefined;}}};for(var i=0;i