From 2ee0cc2528c878db3deaba9358a42b83a33986ed Mon Sep 17 00:00:00 2001 From: Anton Lavrenov Date: Mon, 5 Feb 2018 12:32:48 +0700 Subject: [PATCH] fixes --- konva.js | 26 ++++++++++++++++---------- konva.min.js | 4 ++-- src/shapes/Transformer.js | 26 ++++++++++++++++---------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/konva.js b/konva.js index 848ca35a..5dc7b7a7 100644 --- a/konva.js +++ b/konva.js @@ -18482,6 +18482,8 @@ window.addEventListener('touchmove', this.handleMouseMove); window.addEventListener('mouseup', this.handleMouseUp); window.addEventListener('touchend', this.handleMouseUp); + + this._transforming = true; }, handleMouseMove: function(e) { @@ -18642,12 +18644,19 @@ }, handleMouseUp: function() { - this.fire('transformend'); - this._el.fire('transformend'); - window.removeEventListener('mousemove', this.handleMouseMove); - window.removeEventListener('touchmove', this.handleMouseMove); - window.removeEventListener('mouseup', this.handleMouseUp); - window.removeEventListener('touchend', this.handleMouseUp); + this._removeEvents(); + }, + + _removeEvents: function() { + if (this._transforming) { + this.fire('transformend'); + this._el.fire('transformend'); + window.removeEventListener('mousemove', this.handleMouseMove); + window.removeEventListener('touchmove', this.handleMouseMove); + window.removeEventListener('mouseup', this.handleMouseUp); + window.removeEventListener('touchend', this.handleMouseUp); + } + this._transforming = false; }, _getAttrs: function() { @@ -18771,10 +18780,7 @@ destroy: function() { Konva.Group.prototype.destroy.call(this); this._el.off('.resizer'); - window.removeEventListener('mousemove', this.handleMouseMove); - window.removeEventListener('touchmove', this.handleMouseMove); - window.removeEventListener('mouseup', this.handleMouseUp); - window.removeEventListener('touchend', this.handleMouseUp); + this._removeEvents(); } }; Konva.Util.extend(Konva.Transformer, Konva.Group); diff --git a/konva.min.js b/konva.min.js index f20f6372..d34021ab 100644 --- a/konva.min.js +++ b/konva.min.js @@ -26,7 +26,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -!function(){"use strict";var t=Math.PI/180,e={version:"1.7.6",stages:[],idCounter:0,ids:{},names:{},shapes:{},listenClickTap:!1,inDblClickWindow:!1,isBrowser:"undefined"!=typeof window&&("[object Window]"==={}.toString.call(window)||"[object global]"==={}.toString.call(window)),enableTrace:!1,traceArrMax:100,dblClickWindow:400,pixelRatio:void 0,dragDistance:3,angleDeg:!0,showWarnings:!0,Filters:{},isDragging:function(){var t=e.DD;return!!t&&t.isDragging},isDragReady:function(){var t=e.DD;return!!t&&!!t.node},_addId:function(t,e){void 0!==e&&(this.ids[e]=t)},_removeId:function(t){void 0!==t&&delete this.ids[t]},_addName:function(t,e){e&&(this.names[e]||(this.names[e]=[]),this.names[e].push(t))},_removeName:function(t,e){if(t){var n=this.names[t];if(n){for(var i=0;i0)return parseInt(t.substring(e+5,t.indexOf(".",e)),10);if(t.indexOf("trident/")>0){var n=t.indexOf("rv:");return parseInt(t.substring(n+3,t.indexOf(".",n)),10)}var i=t.indexOf("edge/");return i>0&&parseInt(t.substring(i+5,t.indexOf(".",i)),10)},_parseUA:function(t){var n=t.toLowerCase(),i=/(chrome)[ /]([\w.]+)/.exec(n)||/(webkit)[ /]([\w.]+)/.exec(n)||/(opera)(?:.*version|)[ /]([\w.]+)/.exec(n)||/(msie) ([\w.]+)/.exec(n)||n.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(n)||[],a=!!t.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i),r=!!t.match(/IEMobile/i);return{browser:i[1]||"",version:i[2]||"0",isIE:e._detectIE(n),mobile:a,ieMobile:r}},UA:void 0},n="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{};e.UA=e._parseUA(n.navigator&&n.navigator.userAgent||""),n.Konva&&console.error("Konva instance is already exist in current eviroment. Please use only one instance."),n.Konva=e,e.global=n,e.window=n,e.document=n.document,"object"==typeof exports?module.exports=e:"function"==typeof define&&define.amd&&define(function(){return e})}(),function(){"use strict";Konva.Collection=function(){var t=[].slice.call(arguments),e=t.length,n=0;for(this.length=e;n0},isValidSelector:function(t){if("string"!=typeof t)return!1;var e=t[0];return"#"===e||"."===e||e===e.toUpperCase()},createCanvasElement:function(){var t=Konva.isBrowser?Konva.document.createElement("canvas"):new Konva._nodeCanvas;try{t.style=t.style||{}}catch(t){}return t},_isInDocument:function(t){for(;t=t.parentNode;)if(t==Konva.document)return!0;return!1},_simplifyArray:function(t){var e,n,i=[],a=t.length,r=Konva.Util;for(e=0;e>16&255,g:e>>8&255,b:255&e}},getRandomColor:function(){for(var t=(16777215*Math.random()<<0).toString(16);t.length<6;)t="0"+t;return"#"+t},get:function(t,e){return void 0===t?e:t},getRGB:function(t){var e;return t in i?(e=i[t],{r:e[0],g:e[1],b:e[2]}):"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=a.exec(t.replace(/ /g,"")),{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10)}):{r:0,g:0,b:0}},colorToRGBA:function(t){return t=t||"black",Konva.Util._namedColorToRBA(t)||Konva.Util._hex3ColorToRGBA(t)||Konva.Util._hex6ColorToRGBA(t)||Konva.Util._rgbColorToRGBA(t)||Konva.Util._rgbaColorToRGBA(t)},_namedColorToRBA:function(t){var e=i[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA:function(t){if(0===t.indexOf("rgb(")){var e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA:function(t){if(0===t.indexOf("rgba(")){var e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex6ColorToRGBA:function(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex3ColorToRGBA:function(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_merge:function(t,e){var n=this._clone(e);for(var i in t)this._isObject(t[i])?n[i]=this._merge(t[i],n[i]):n[i]=t[i];return n},cloneObject:function(t){var e={};for(var n in t)this._isObject(t[n])?e[n]=this.cloneObject(t[n]):this._isArray(t[n])?e[n]=this.cloneArray(t[n]):e[n]=t[n];return e},cloneArray:function(t){return t.slice(0)},_degToRad:function(e){return e*t},_radToDeg:function(t){return t*e},_capitalize:function(t){return t.charAt(0).toUpperCase()+t.slice(1)},throw:function(t){throw new Error(n+t)},error:function(t){console.error(n+t)},warn:function(t){Konva.global.console&&console.warn&&Konva.showWarnings&&console.warn("Konva warning: "+t)},extend:function(t,e){function n(){this.constructor=t}n.prototype=e.prototype;var i=t.prototype;t.prototype=new n;for(var a in i)i.hasOwnProperty(a)&&(t.prototype[a]=i[a]);t.__super__=e.prototype,t.super=e},addMethods:function(t,e){var n;for(n in e)t.prototype[n]=e[n]},_getControlPoints:function(t,e,n,i,a,r,o){var s=Math.sqrt(Math.pow(n-t,2)+Math.pow(i-e,2)),h=Math.sqrt(Math.pow(a-n,2)+Math.pow(r-i,2)),l=o*s/(s+h),c=o*h/(s+h);return[n-l*(a-t),i-l*(r-e),n+c*(a-t),i+c*(r-e)]},_expandPoints:function(t,e){var n,i,a=t.length,r=[];for(n=2;n1?(o=n,s=i,h=(n-a)*(n-a)+(i-r)*(i-r)):h=((o=t+c*(n-t))-a)*(o-a)+((s=e+c*(i-e))-r)*(s-r)}return[o,s,h]},_getProjectionToLine:function(t,e,n){var i=Konva.Util.cloneObject(t),a=Number.MAX_VALUE;return e.forEach(function(r,o){if(n||o!==e.length-1){var s=e[(o+1)%e.length],h=Konva.Util._getProjectionToSegment(r.x,r.y,s.x,s.y,t.x,t.y),l=h[0],c=h[1],d=h[2];de.length){var o=e;e=t,t=o}for(i=0;i=Konva.traceArrMax&&e.shift()},reset:function(){var t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)},getCanvas:function(){return this.canvas},clear:function(t){var e=this.getCanvas();t?this.clearRect(t.x||0,t.y||0,t.width||0,t.height||0):this.clearRect(0,0,e.getWidth()/e.pixelRatio,e.getHeight()/e.pixelRatio)},_applyLineCap:function(t){var e=t.getLineCap();e&&this.setAttr("lineCap",e)},_applyOpacity:function(t){var e=t.getAbsoluteOpacity();1!==e&&this.setAttr("globalAlpha",e)},_applyLineJoin:function(t){var e=t.getLineJoin();e&&this.setAttr("lineJoin",e)},setAttr:function(t,e){this._context[t]=e},arc:function(){var t=arguments;this._context.arc(t[0],t[1],t[2],t[3],t[4],t[5])},beginPath:function(){this._context.beginPath()},bezierCurveTo:function(){var t=arguments;this._context.bezierCurveTo(t[0],t[1],t[2],t[3],t[4],t[5])},clearRect:function(){var t=arguments;this._context.clearRect(t[0],t[1],t[2],t[3])},clip:function(){this._context.clip()},closePath:function(){this._context.closePath()},createImageData:function(){var t=arguments;return 2===t.length?this._context.createImageData(t[0],t[1]):1===t.length?this._context.createImageData(t[0]):void 0},createLinearGradient:function(){var t=arguments;return this._context.createLinearGradient(t[0],t[1],t[2],t[3])},createPattern:function(){var t=arguments;return this._context.createPattern(t[0],t[1])},createRadialGradient:function(){var t=arguments;return this._context.createRadialGradient(t[0],t[1],t[2],t[3],t[4],t[5])},drawImage:function(){var t=arguments,e=this._context;3===t.length?e.drawImage(t[0],t[1],t[2]):5===t.length?e.drawImage(t[0],t[1],t[2],t[3],t[4]):9===t.length&&e.drawImage(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8])},isPointInPath:function(t,e){return this._context.isPointInPath(t,e)},fill:function(){this._context.fill()},fillRect:function(t,e,n,i){this._context.fillRect(t,e,n,i)},strokeRect:function(t,e,n,i){this._context.strokeRect(t,e,n,i)},fillText:function(){var t=arguments;this._context.fillText(t[0],t[1],t[2])},measureText:function(t){return this._context.measureText(t)},getImageData:function(){var t=arguments;return this._context.getImageData(t[0],t[1],t[2],t[3])},lineTo:function(){var t=arguments;this._context.lineTo(t[0],t[1])},moveTo:function(){var t=arguments;this._context.moveTo(t[0],t[1])},rect:function(){var t=arguments;this._context.rect(t[0],t[1],t[2],t[3])},putImageData:function(){var t=arguments;this._context.putImageData(t[0],t[1],t[2])},quadraticCurveTo:function(){var t=arguments;this._context.quadraticCurveTo(t[0],t[1],t[2],t[3])},restore:function(){this._context.restore()},rotate:function(){var t=arguments;this._context.rotate(t[0])},save:function(){this._context.save()},scale:function(){var t=arguments;this._context.scale(t[0],t[1])},setLineDash:function(){var t=arguments,e=this._context;this._context.setLineDash?e.setLineDash(t[0]):"mozDash"in e?e.mozDash=t[0]:"webkitLineDash"in e&&(e.webkitLineDash=t[0])},getLineDash:function(){return this._context.getLineDash()},setTransform:function(){var t=arguments;this._context.setTransform(t[0],t[1],t[2],t[3],t[4],t[5])},stroke:function(){this._context.stroke()},strokeText:function(){var t=arguments;this._context.strokeText(t[0],t[1],t[2])},transform:function(){var t=arguments;this._context.transform(t[0],t[1],t[2],t[3],t[4],t[5])},translate:function(){var t=arguments;this._context.translate(t[0],t[1])},_enableTrace:function(){var e,n,i=this,a=t.length,r=Konva.Util._simplifyArray,o=this.setAttr,s=function(t){var e,a=i[t];i[t]=function(){return n=r(Array.prototype.slice.call(arguments,0)),e=a.apply(i,arguments),i._trace({method:t,args:n}),e}};for(e=0;e255?255:t<0?0:Math.round(t)},alphaComponent:function(t){return t>1?1:t<1e-4?1e-4:t}}}(),function(t){"use strict";var e="absoluteOpacity",n="absoluteTransform",i="absoluteScale",a="listening",r="Shape",o="transform",s=["id"],h=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(" "),l=["scaleXChange.konva","scaleYChange.konva"].join(" ");t.Node=function(t){this._init(t)},t.Util.addMethods(t.Node,{_init:function(r){var s=this;this._id=t.idCounter++,this.eventListeners={},this.attrs={},this._cache={},this._filterUpToDate=!1,this._isUnderCache=!1,this.setAttrs(r),this.on(h,function(){this._clearCache(o),s._clearSelfAndDescendantCache(n)}),this.on(l,function(){s._clearSelfAndDescendantCache(i)}),this.on("visibleChange.konva",function(){s._clearSelfAndDescendantCache("visible")}),this.on("listeningChange.konva",function(){s._clearSelfAndDescendantCache(a)}),this.on("opacityChange.konva",function(){s._clearSelfAndDescendantCache(e)})},_clearCache:function(t){t?delete this._cache[t]:this._cache={}},_getCache:function(t,e){return void 0===this._cache[t]&&(this._cache[t]=e.call(this)),this._cache[t]},_clearSelfAndDescendantCache:function(t){this._clearCache(t),this.children&&this.getChildren().each(function(e){e._clearSelfAndDescendantCache(t)})},clearCache:function(){return delete this._cache.canvas,this._filterUpToDate=!1,this},cache:function(n){var a=n||{},r=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()}),o=a.width||r.width,s=a.height||r.height,h=a.pixelRatio,l=a.x||r.x,c=a.y||r.y,d=a.offset||0,u=a.drawBorder||!1;{if(o&&s){o+=2*d,s+=2*d,l-=d,c-=d;var f=new t.SceneCanvas({pixelRatio:h,width:o,height:s}),g=new t.SceneCanvas({pixelRatio:h,width:o,height:s}),v=new t.HitCanvas({pixelRatio:1,width:o,height:s}),p=f.getContext(),m=v.getContext();return v.isCache=!0,this.clearCache(),p.save(),m.save(),p.translate(-l,-c),m.translate(-l,-c),this._isUnderCache=!0,this._clearSelfAndDescendantCache(e),this._clearSelfAndDescendantCache(i),this.drawScene(f,this,!0),this.drawHit(v,this,!0),this._isUnderCache=!1,p.restore(),m.restore(),u&&(p.save(),p.beginPath(),p.rect(0,0,o,s),p.closePath(),p.setAttr("strokeStyle","red"),p.setAttr("lineWidth",5),p.stroke(),p.restore()),this._cache.canvas={scene:f,filter:g,hit:v,x:l,y:c},this}setTimeout(function(){t.Util.throw("Width or height of caching configuration equals 0. Caching is ignored.")})}},getClientRect:function(){throw new Error('abstract "getClientRect" method call')},_transformedRect:function(t,e){var n,i,a,r,o=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}],s=this.getAbsoluteTransform(e);return o.forEach(function(t){var e=s.point(t);void 0===n&&(n=a=e.x,i=r=e.y),n=Math.min(n,e.x),i=Math.min(i,e.y),a=Math.max(a,e.x),r=Math.max(r,e.y)}),{x:n,y:i,width:a-n,height:r-i}},_drawCachedSceneCanvas:function(t){t.save(),t._applyOpacity(this),t._applyGlobalCompositeOperation(this),t.translate(this._cache.canvas.x,this._cache.canvas.y);var e=this._getCachedSceneCanvas(),n=e.pixelRatio;t.drawImage(e._canvas,0,0,e.width/n,e.height/n),t.restore()},_drawCachedHitCanvas:function(t){var e=this._cache.canvas.hit;t.save(),t.translate(this._cache.canvas.x,this._cache.canvas.y),t.drawImage(e._canvas,0,0),t.restore()},_getCachedSceneCanvas:function(){var e,n,i,a,r=this.filters(),o=this._cache.canvas,s=o.scene,h=o.filter,l=h.getContext();if(r){if(!this._filterUpToDate){var c=s.pixelRatio;try{for(e=r.length,l.clear(),l.drawImage(s._canvas,0,0,s.getWidth()/c,s.getHeight()/c),n=l.getImageData(0,0,h.getWidth(),h.getHeight()),i=0;i0&&e[0].getDepth()<=o&&t(e)}var e,n,i,a,o=this.getDepth(),s=this,h=0;return"Stage"!==s.nodeType&&t(s.getStage().getChildren()),h},getDepth:function(){for(var t=0,e=this.parent;e;)t++,e=e.parent;return t},setPosition:function(t){return this.setX(t.x),this.setY(t.y),this},getPosition:function(){return{x:this.getX(),y:this.getY()}},getAbsolutePosition:function(e){var n=this.getAbsoluteTransform(e).getMatrix(),i=new t.Transform,a=this.offset();return i.m=n.slice(),i.translate(a.x,a.y),i.getTranslation()},setAbsolutePosition:function(t){var e,n=this._clearTransform();return this.attrs.x=n.x,this.attrs.y=n.y,delete n.x,delete n.y,(e=this.getAbsoluteTransform()).invert(),e.translate(t.x,t.y),t={x:this.attrs.x+e.getTranslation().x,y:this.attrs.y+e.getTranslation().y},this.setPosition({x:t.x,y:t.y}),this._setTransform(n),this},_setTransform:function(t){var e;for(e in t)this.attrs[e]=t[e];this._clearCache(o),this._clearSelfAndDescendantCache(n)},_clearTransform:function(){var t={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()};return 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(o),this._clearSelfAndDescendantCache(n),t},move:function(t){var e=t.x,n=t.y,i=this.getX(),a=this.getY();return void 0!==e&&(i+=e),void 0!==n&&(a+=n),this.setPosition({x:i,y:a}),this},_eachAncestorReverse:function(t,e){var n,i,a=[],r=this.getParent();if(e&&e._id===this._id)return t(this),!0;for(a.unshift(this);r&&(!e||r._id!==e._id);)a.unshift(r),r=r.parent;for(n=a.length,i=0;i0&&(this.parent.children.splice(e,1),this.parent.children.splice(e-1,0,this),this.parent._setChildrenIndices(),!0)},moveToBottom:function(){if(!this.parent)return t.Util.warn("Node has no parent. moveToBottom function is ignored."),!1;var e=this.index;return e>0&&(this.parent.children.splice(e,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0)},setZIndex:function(e){if(!this.parent)return t.Util.warn("Node has no parent. zIndex parameter is ignored."),!1;var n=this.index;return this.parent.children.splice(n,1),this.parent.children.splice(e,0,this),this.parent._setChildrenIndices(),this},getAbsoluteOpacity:function(){return this._getCache(e,this._getAbsoluteOpacity)},_getAbsoluteOpacity:function(){var t=this.getOpacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=this.getParent().getAbsoluteOpacity()),t},moveTo:function(t){return this.getParent()!==t&&((this.__originalRemove||this.remove).call(this),t.add(this)),this},toObject:function(){var e,n,i,a,r={},o=this.getAttrs();r.attrs={};for(e in o)n=o[e],i=this[e],delete o[e],a=i?i.call(this):null,o[e]=n,a!==n&&(r.attrs[e]=n);return r.className=this.getClassName(),t.Util._prepareToStringify(r)},toJSON:function(){return JSON.stringify(this.toObject())},getParent:function(){return this.parent},findAncestors:function(t,e,n){var i=[];e&&this._isMatch(t)&&i.push(this);for(var a=this.parent;a;){if(a===n)return i;a._isMatch(t)&&i.push(a),a=a.parent}return i},findAncestor:function(t,e,n){return this.findAncestors(t,e,n)[0]},_isMatch:function(e){if(!e)return!1;var n,i,a=e.replace(/ /g,"").split(","),r=a.length;for(n=0;n0&&function(t,a){var r,o,s,h,l,c,d,u,f,g,v,p,m,_,y,S,K,x,C,w,b,F,T,P,A=t.data,M=t.width,k=t.height,G=a+a+1,D=M-1,R=k-1,L=a+1,O=L*(L+1)/2,I=new e,U=null,N=I,E=null,B=null,H=n[a],z=i[a];for(s=1;s>z,0!==T?(T=255/T,A[c]=(u*H>>z)*T,A[c+1]=(f*H>>z)*T,A[c+2]=(g*H>>z)*T):A[c]=A[c+1]=A[c+2]=0,u-=p,f-=m,g-=_,v-=y,p-=E.r,m-=E.g,_-=E.b,y-=E.a,h=d+((h=r+a+1)>z,T>0?(T=255/T,A[h]=(u*H>>z)*T,A[h+1]=(f*H>>z)*T,A[h+2]=(g*H>>z)*T):A[h]=A[h+1]=A[h+2]=0,u-=p,f-=m,g-=_,v-=y,p-=E.r,m-=E.g,_-=E.b,y-=E.a,h=r+((h=o+L)=0&&f=0&&g=0&&f=0&&g=1020?255:0}return o}(i=function(t,e,n){for(var i=[1,1,1,1,0,1,1,1,1],a=Math.round(Math.sqrt(i.length)),r=Math.floor(a/2),o=[],s=0;s=0&&f=0&&g255?255:t<0?0:Math.round(t)}),Konva.Factory.addGetterSetter(Konva.Node,"green",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),Konva.Factory.addGetterSetter(Konva.Node,"blue",0,Konva.Validators.RGBComponent,Konva.Factory.afterSetFilter)}(),function(){"use strict";Konva.Filters.RGBA=function(t){var e,n,i=t.data,a=i.length,r=this.red(),o=this.green(),s=this.blue(),h=this.alpha();for(e=0;e255?255:t<0?0:Math.round(t)}),Konva.Factory.addGetterSetter(Konva.Node,"green",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),Konva.Factory.addGetterSetter(Konva.Node,"blue",0,Konva.Validators.RGBComponent,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"alpha",1,function(t){return this._filterUpToDate=!1,t>1?1:t<0?0:t})}(),function(){"use strict";Konva.Filters.HSV=function(t){var e,n,i,a,r,o=t.data,s=o.length,h=Math.pow(2,this.value()),l=Math.pow(2,this.saturation()),c=Math.abs(this.hue()+360)%360,d=h*l*Math.cos(c*Math.PI/180),u=h*l*Math.sin(c*Math.PI/180),f=.299*h+.701*d+.167*u,g=.587*h-.587*d+.33*u,v=.114*h-.114*d-.497*u,p=.299*h-.299*d-.328*u,m=.587*h+.413*d+.035*u,_=.114*h-.114*d+.293*u,y=.299*h-.3*d+1.25*u,S=.587*h-.586*d-1.05*u,K=.114*h+.886*d-.2*u;for(e=0;el&&(f=0);var g=(d-1+f)*h*4,v=h;do{var p=u+4*(v-1),m=o;v+m<1&&(m=0),v+m>h&&(m=0);var _=g+4*(v-1+m),y=s[p]-s[_],S=s[p+1]-s[_+1],K=s[p+2]-s[_+2],x=y,C=x>0?x:-x;if((S>0?S:-S)>C&&(x=S),(K>0?K:-K)>C&&(x=K),x*=e,a){var w=s[p]+x,b=s[p+1]+x,F=s[p+2]+x;s[p]=w>255?255:w<0?0:w,s[p+1]=b>255?255:b<0?0:b,s[p+2]=F>255?255:F<0?0:F}else{var T=n-x;T<0?T=0:T>255&&(T=255),s[p]=s[p+1]=s[p+2]=T}}while(--v)}while(--d)},Konva.Factory.addGetterSetter(Konva.Node,"embossStrength",.5,null,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"embossWhiteLevel",.5,null,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"embossDirection","top-left",null,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"embossBlend",!1,null,Konva.Factory.afterSetFilter)}(),function(){"use strict";function t(t,e,n,i,a){var r,o=n-e,s=a-i;return 0===o?i+s/2:0===s?i:(r=(t-e)/o,r=s*r+i)}Konva.Filters.Enhance=function(e){var n,i,a,r,o=e.data,s=o.length,h=o[0],l=h,c=o[1],d=c,u=o[2],f=u,g=this.enhance();if(0!==g){for(r=0;rl&&(l=n),(i=o[r+1])d&&(d=i),(a=o[r+2])f&&(f=a);l===h&&(l=255,h=0),d===c&&(d=255,c=0),f===u&&(f=255,u=0);var v,p,m,_,y,S,K,x,C;for(g>0?(p=l+g*(255-l),m=h-g*(h-0),y=d+g*(255-d),S=c-g*(c-0),x=f+g*(255-f),C=u-g*(u-0)):(p=l+g*(l-(v=.5*(l+h))),m=h+g*(h-v),y=d+g*(d-(_=.5*(d+c))),S=c+g*(c-_),x=f+g*(f-(K=.5*(f+u))),C=u+g*(u-K)),r=0;r=p))for(n=c;n=m||(a+=t[(i=4*(p*n+e))+0],r+=t[i+1],o+=t[i+2],s+=t[i+3],g+=1);for(a/=g,r/=g,o/=g,e=h;e=p))for(n=c;n=m||(t[(i=4*(p*n+e))+0]=a,t[i+1]=r,t[i+2]=o,t[i+3]=s)}},Konva.Factory.addGetterSetter(Konva.Node,"pixelSize",8,null,Konva.Factory.afterSetFilter)}(),function(){"use strict";Konva.Filters.Threshold=function(t){var e,n=255*this.threshold(),i=t.data,a=i.length;for(e=0;e0)return parseInt(t.substring(e+5,t.indexOf(".",e)),10);if(t.indexOf("trident/")>0){var n=t.indexOf("rv:");return parseInt(t.substring(n+3,t.indexOf(".",n)),10)}var i=t.indexOf("edge/");return i>0&&parseInt(t.substring(i+5,t.indexOf(".",i)),10)},_parseUA:function(t){var n=t.toLowerCase(),i=/(chrome)[ /]([\w.]+)/.exec(n)||/(webkit)[ /]([\w.]+)/.exec(n)||/(opera)(?:.*version|)[ /]([\w.]+)/.exec(n)||/(msie) ([\w.]+)/.exec(n)||n.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(n)||[],a=!!t.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i),r=!!t.match(/IEMobile/i);return{browser:i[1]||"",version:i[2]||"0",isIE:e._detectIE(n),mobile:a,ieMobile:r}},UA:void 0},n="undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{};e.UA=e._parseUA(n.navigator&&n.navigator.userAgent||""),n.Konva&&console.error("Konva instance is already exist in current eviroment. Please use only one instance."),n.Konva=e,e.global=n,e.window=n,e.document=n.document,"object"==typeof exports?module.exports=e:"function"==typeof define&&define.amd&&define(function(){return e})}(),function(){"use strict";Konva.Collection=function(){var t=[].slice.call(arguments),e=t.length,n=0;for(this.length=e;n0},isValidSelector:function(t){if("string"!=typeof t)return!1;var e=t[0];return"#"===e||"."===e||e===e.toUpperCase()},createCanvasElement:function(){var t=Konva.isBrowser?Konva.document.createElement("canvas"):new Konva._nodeCanvas;try{t.style=t.style||{}}catch(t){}return t},_isInDocument:function(t){for(;t=t.parentNode;)if(t==Konva.document)return!0;return!1},_simplifyArray:function(t){var e,n,i=[],a=t.length,r=Konva.Util;for(e=0;e>16&255,g:e>>8&255,b:255&e}},getRandomColor:function(){for(var t=(16777215*Math.random()<<0).toString(16);t.length<6;)t="0"+t;return"#"+t},get:function(t,e){return void 0===t?e:t},getRGB:function(t){var e;return t in i?(e=i[t],{r:e[0],g:e[1],b:e[2]}):"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=a.exec(t.replace(/ /g,"")),{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10)}):{r:0,g:0,b:0}},colorToRGBA:function(t){return t=t||"black",Konva.Util._namedColorToRBA(t)||Konva.Util._hex3ColorToRGBA(t)||Konva.Util._hex6ColorToRGBA(t)||Konva.Util._rgbColorToRGBA(t)||Konva.Util._rgbaColorToRGBA(t)},_namedColorToRBA:function(t){var e=i[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA:function(t){if(0===t.indexOf("rgb(")){var e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA:function(t){if(0===t.indexOf("rgba(")){var e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex6ColorToRGBA:function(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex3ColorToRGBA:function(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_merge:function(t,e){var n=this._clone(e);for(var i in t)this._isObject(t[i])?n[i]=this._merge(t[i],n[i]):n[i]=t[i];return n},cloneObject:function(t){var e={};for(var n in t)this._isObject(t[n])?e[n]=this.cloneObject(t[n]):this._isArray(t[n])?e[n]=this.cloneArray(t[n]):e[n]=t[n];return e},cloneArray:function(t){return t.slice(0)},_degToRad:function(e){return e*t},_radToDeg:function(t){return t*e},_capitalize:function(t){return t.charAt(0).toUpperCase()+t.slice(1)},throw:function(t){throw new Error(n+t)},error:function(t){console.error(n+t)},warn:function(t){Konva.global.console&&console.warn&&Konva.showWarnings&&console.warn("Konva warning: "+t)},extend:function(t,e){function n(){this.constructor=t}n.prototype=e.prototype;var i=t.prototype;t.prototype=new n;for(var a in i)i.hasOwnProperty(a)&&(t.prototype[a]=i[a]);t.__super__=e.prototype,t.super=e},addMethods:function(t,e){var n;for(n in e)t.prototype[n]=e[n]},_getControlPoints:function(t,e,n,i,a,r,o){var s=Math.sqrt(Math.pow(n-t,2)+Math.pow(i-e,2)),h=Math.sqrt(Math.pow(a-n,2)+Math.pow(r-i,2)),l=o*s/(s+h),c=o*h/(s+h);return[n-l*(a-t),i-l*(r-e),n+c*(a-t),i+c*(r-e)]},_expandPoints:function(t,e){var n,i,a=t.length,r=[];for(n=2;n1?(o=n,s=i,h=(n-a)*(n-a)+(i-r)*(i-r)):h=((o=t+c*(n-t))-a)*(o-a)+((s=e+c*(i-e))-r)*(s-r)}return[o,s,h]},_getProjectionToLine:function(t,e,n){var i=Konva.Util.cloneObject(t),a=Number.MAX_VALUE;return e.forEach(function(r,o){if(n||o!==e.length-1){var s=e[(o+1)%e.length],h=Konva.Util._getProjectionToSegment(r.x,r.y,s.x,s.y,t.x,t.y),l=h[0],c=h[1],d=h[2];de.length){var o=e;e=t,t=o}for(i=0;i=Konva.traceArrMax&&e.shift()},reset:function(){var t=this.getCanvas().getPixelRatio();this.setTransform(1*t,0,0,1*t,0,0)},getCanvas:function(){return this.canvas},clear:function(t){var e=this.getCanvas();t?this.clearRect(t.x||0,t.y||0,t.width||0,t.height||0):this.clearRect(0,0,e.getWidth()/e.pixelRatio,e.getHeight()/e.pixelRatio)},_applyLineCap:function(t){var e=t.getLineCap();e&&this.setAttr("lineCap",e)},_applyOpacity:function(t){var e=t.getAbsoluteOpacity();1!==e&&this.setAttr("globalAlpha",e)},_applyLineJoin:function(t){var e=t.getLineJoin();e&&this.setAttr("lineJoin",e)},setAttr:function(t,e){this._context[t]=e},arc:function(){var t=arguments;this._context.arc(t[0],t[1],t[2],t[3],t[4],t[5])},beginPath:function(){this._context.beginPath()},bezierCurveTo:function(){var t=arguments;this._context.bezierCurveTo(t[0],t[1],t[2],t[3],t[4],t[5])},clearRect:function(){var t=arguments;this._context.clearRect(t[0],t[1],t[2],t[3])},clip:function(){this._context.clip()},closePath:function(){this._context.closePath()},createImageData:function(){var t=arguments;return 2===t.length?this._context.createImageData(t[0],t[1]):1===t.length?this._context.createImageData(t[0]):void 0},createLinearGradient:function(){var t=arguments;return this._context.createLinearGradient(t[0],t[1],t[2],t[3])},createPattern:function(){var t=arguments;return this._context.createPattern(t[0],t[1])},createRadialGradient:function(){var t=arguments;return this._context.createRadialGradient(t[0],t[1],t[2],t[3],t[4],t[5])},drawImage:function(){var t=arguments,e=this._context;3===t.length?e.drawImage(t[0],t[1],t[2]):5===t.length?e.drawImage(t[0],t[1],t[2],t[3],t[4]):9===t.length&&e.drawImage(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8])},isPointInPath:function(t,e){return this._context.isPointInPath(t,e)},fill:function(){this._context.fill()},fillRect:function(t,e,n,i){this._context.fillRect(t,e,n,i)},strokeRect:function(t,e,n,i){this._context.strokeRect(t,e,n,i)},fillText:function(){var t=arguments;this._context.fillText(t[0],t[1],t[2])},measureText:function(t){return this._context.measureText(t)},getImageData:function(){var t=arguments;return this._context.getImageData(t[0],t[1],t[2],t[3])},lineTo:function(){var t=arguments;this._context.lineTo(t[0],t[1])},moveTo:function(){var t=arguments;this._context.moveTo(t[0],t[1])},rect:function(){var t=arguments;this._context.rect(t[0],t[1],t[2],t[3])},putImageData:function(){var t=arguments;this._context.putImageData(t[0],t[1],t[2])},quadraticCurveTo:function(){var t=arguments;this._context.quadraticCurveTo(t[0],t[1],t[2],t[3])},restore:function(){this._context.restore()},rotate:function(){var t=arguments;this._context.rotate(t[0])},save:function(){this._context.save()},scale:function(){var t=arguments;this._context.scale(t[0],t[1])},setLineDash:function(){var t=arguments,e=this._context;this._context.setLineDash?e.setLineDash(t[0]):"mozDash"in e?e.mozDash=t[0]:"webkitLineDash"in e&&(e.webkitLineDash=t[0])},getLineDash:function(){return this._context.getLineDash()},setTransform:function(){var t=arguments;this._context.setTransform(t[0],t[1],t[2],t[3],t[4],t[5])},stroke:function(){this._context.stroke()},strokeText:function(){var t=arguments;this._context.strokeText(t[0],t[1],t[2])},transform:function(){var t=arguments;this._context.transform(t[0],t[1],t[2],t[3],t[4],t[5])},translate:function(){var t=arguments;this._context.translate(t[0],t[1])},_enableTrace:function(){var e,n,i=this,a=t.length,r=Konva.Util._simplifyArray,o=this.setAttr,s=function(t){var e,a=i[t];i[t]=function(){return n=r(Array.prototype.slice.call(arguments,0)),e=a.apply(i,arguments),i._trace({method:t,args:n}),e}};for(e=0;e255?255:t<0?0:Math.round(t)},alphaComponent:function(t){return t>1?1:t<1e-4?1e-4:t}}}(),function(t){"use strict";var e="absoluteOpacity",n="absoluteTransform",i="absoluteScale",a="listening",r="Shape",o="transform",s=["id"],h=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(" "),l=["scaleXChange.konva","scaleYChange.konva"].join(" ");t.Node=function(t){this._init(t)},t.Util.addMethods(t.Node,{_init:function(r){var s=this;this._id=t.idCounter++,this.eventListeners={},this.attrs={},this._cache={},this._filterUpToDate=!1,this._isUnderCache=!1,this.setAttrs(r),this.on(h,function(){this._clearCache(o),s._clearSelfAndDescendantCache(n)}),this.on(l,function(){s._clearSelfAndDescendantCache(i)}),this.on("visibleChange.konva",function(){s._clearSelfAndDescendantCache("visible")}),this.on("listeningChange.konva",function(){s._clearSelfAndDescendantCache(a)}),this.on("opacityChange.konva",function(){s._clearSelfAndDescendantCache(e)})},_clearCache:function(t){t?delete this._cache[t]:this._cache={}},_getCache:function(t,e){return void 0===this._cache[t]&&(this._cache[t]=e.call(this)),this._cache[t]},_clearSelfAndDescendantCache:function(t){this._clearCache(t),this.children&&this.getChildren().each(function(e){e._clearSelfAndDescendantCache(t)})},clearCache:function(){return delete this._cache.canvas,this._filterUpToDate=!1,this},cache:function(n){var a=n||{},r=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()}),o=a.width||r.width,s=a.height||r.height,h=a.pixelRatio,l=a.x||r.x,c=a.y||r.y,d=a.offset||0,u=a.drawBorder||!1;{if(o&&s){o+=2*d,s+=2*d,l-=d,c-=d;var f=new t.SceneCanvas({pixelRatio:h,width:o,height:s}),g=new t.SceneCanvas({pixelRatio:h,width:o,height:s}),v=new t.HitCanvas({pixelRatio:1,width:o,height:s}),p=f.getContext(),m=v.getContext();return v.isCache=!0,this.clearCache(),p.save(),m.save(),p.translate(-l,-c),m.translate(-l,-c),this._isUnderCache=!0,this._clearSelfAndDescendantCache(e),this._clearSelfAndDescendantCache(i),this.drawScene(f,this,!0),this.drawHit(v,this,!0),this._isUnderCache=!1,p.restore(),m.restore(),u&&(p.save(),p.beginPath(),p.rect(0,0,o,s),p.closePath(),p.setAttr("strokeStyle","red"),p.setAttr("lineWidth",5),p.stroke(),p.restore()),this._cache.canvas={scene:f,filter:g,hit:v,x:l,y:c},this}setTimeout(function(){t.Util.throw("Width or height of caching configuration equals 0. Caching is ignored.")})}},getClientRect:function(){throw new Error('abstract "getClientRect" method call')},_transformedRect:function(t,e){var n,i,a,r,o=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}],s=this.getAbsoluteTransform(e);return o.forEach(function(t){var e=s.point(t);void 0===n&&(n=a=e.x,i=r=e.y),n=Math.min(n,e.x),i=Math.min(i,e.y),a=Math.max(a,e.x),r=Math.max(r,e.y)}),{x:n,y:i,width:a-n,height:r-i}},_drawCachedSceneCanvas:function(t){t.save(),t._applyOpacity(this),t._applyGlobalCompositeOperation(this),t.translate(this._cache.canvas.x,this._cache.canvas.y);var e=this._getCachedSceneCanvas(),n=e.pixelRatio;t.drawImage(e._canvas,0,0,e.width/n,e.height/n),t.restore()},_drawCachedHitCanvas:function(t){var e=this._cache.canvas.hit;t.save(),t.translate(this._cache.canvas.x,this._cache.canvas.y),t.drawImage(e._canvas,0,0),t.restore()},_getCachedSceneCanvas:function(){var e,n,i,a,r=this.filters(),o=this._cache.canvas,s=o.scene,h=o.filter,l=h.getContext();if(r){if(!this._filterUpToDate){var c=s.pixelRatio;try{for(e=r.length,l.clear(),l.drawImage(s._canvas,0,0,s.getWidth()/c,s.getHeight()/c),n=l.getImageData(0,0,h.getWidth(),h.getHeight()),i=0;i0&&e[0].getDepth()<=o&&t(e)}var e,n,i,a,o=this.getDepth(),s=this,h=0;return"Stage"!==s.nodeType&&t(s.getStage().getChildren()),h},getDepth:function(){for(var t=0,e=this.parent;e;)t++,e=e.parent;return t},setPosition:function(t){return this.setX(t.x),this.setY(t.y),this},getPosition:function(){return{x:this.getX(),y:this.getY()}},getAbsolutePosition:function(e){var n=this.getAbsoluteTransform(e).getMatrix(),i=new t.Transform,a=this.offset();return i.m=n.slice(),i.translate(a.x,a.y),i.getTranslation()},setAbsolutePosition:function(t){var e,n=this._clearTransform();return this.attrs.x=n.x,this.attrs.y=n.y,delete n.x,delete n.y,(e=this.getAbsoluteTransform()).invert(),e.translate(t.x,t.y),t={x:this.attrs.x+e.getTranslation().x,y:this.attrs.y+e.getTranslation().y},this.setPosition({x:t.x,y:t.y}),this._setTransform(n),this},_setTransform:function(t){var e;for(e in t)this.attrs[e]=t[e];this._clearCache(o),this._clearSelfAndDescendantCache(n)},_clearTransform:function(){var t={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()};return 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(o),this._clearSelfAndDescendantCache(n),t},move:function(t){var e=t.x,n=t.y,i=this.getX(),a=this.getY();return void 0!==e&&(i+=e),void 0!==n&&(a+=n),this.setPosition({x:i,y:a}),this},_eachAncestorReverse:function(t,e){var n,i,a=[],r=this.getParent();if(e&&e._id===this._id)return t(this),!0;for(a.unshift(this);r&&(!e||r._id!==e._id);)a.unshift(r),r=r.parent;for(n=a.length,i=0;i0&&(this.parent.children.splice(e,1),this.parent.children.splice(e-1,0,this),this.parent._setChildrenIndices(),!0)},moveToBottom:function(){if(!this.parent)return t.Util.warn("Node has no parent. moveToBottom function is ignored."),!1;var e=this.index;return e>0&&(this.parent.children.splice(e,1),this.parent.children.unshift(this),this.parent._setChildrenIndices(),!0)},setZIndex:function(e){if(!this.parent)return t.Util.warn("Node has no parent. zIndex parameter is ignored."),!1;var n=this.index;return this.parent.children.splice(n,1),this.parent.children.splice(e,0,this),this.parent._setChildrenIndices(),this},getAbsoluteOpacity:function(){return this._getCache(e,this._getAbsoluteOpacity)},_getAbsoluteOpacity:function(){var t=this.getOpacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=this.getParent().getAbsoluteOpacity()),t},moveTo:function(t){return this.getParent()!==t&&((this.__originalRemove||this.remove).call(this),t.add(this)),this},toObject:function(){var e,n,i,a,r={},o=this.getAttrs();r.attrs={};for(e in o)n=o[e],i=this[e],delete o[e],a=i?i.call(this):null,o[e]=n,a!==n&&(r.attrs[e]=n);return r.className=this.getClassName(),t.Util._prepareToStringify(r)},toJSON:function(){return JSON.stringify(this.toObject())},getParent:function(){return this.parent},findAncestors:function(t,e,n){var i=[];e&&this._isMatch(t)&&i.push(this);for(var a=this.parent;a;){if(a===n)return i;a._isMatch(t)&&i.push(a),a=a.parent}return i},findAncestor:function(t,e,n){return this.findAncestors(t,e,n)[0]},_isMatch:function(e){if(!e)return!1;var n,i,a=e.replace(/ /g,"").split(","),r=a.length;for(n=0;n0&&function(t,a){var r,o,s,h,l,c,d,u,f,g,v,p,m,_,y,S,K,x,C,b,w,F,T,P,A=t.data,M=t.width,k=t.height,G=a+a+1,D=M-1,R=k-1,L=a+1,O=L*(L+1)/2,I=new e,N=null,U=I,E=null,B=null,H=n[a],z=i[a];for(s=1;s>z,0!==T?(T=255/T,A[c]=(u*H>>z)*T,A[c+1]=(f*H>>z)*T,A[c+2]=(g*H>>z)*T):A[c]=A[c+1]=A[c+2]=0,u-=p,f-=m,g-=_,v-=y,p-=E.r,m-=E.g,_-=E.b,y-=E.a,h=d+((h=r+a+1)>z,T>0?(T=255/T,A[h]=(u*H>>z)*T,A[h+1]=(f*H>>z)*T,A[h+2]=(g*H>>z)*T):A[h]=A[h+1]=A[h+2]=0,u-=p,f-=m,g-=_,v-=y,p-=E.r,m-=E.g,_-=E.b,y-=E.a,h=r+((h=o+L)=0&&f=0&&g=0&&f=0&&g=1020?255:0}return o}(i=function(t,e,n){for(var i=[1,1,1,1,0,1,1,1,1],a=Math.round(Math.sqrt(i.length)),r=Math.floor(a/2),o=[],s=0;s=0&&f=0&&g255?255:t<0?0:Math.round(t)}),Konva.Factory.addGetterSetter(Konva.Node,"green",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),Konva.Factory.addGetterSetter(Konva.Node,"blue",0,Konva.Validators.RGBComponent,Konva.Factory.afterSetFilter)}(),function(){"use strict";Konva.Filters.RGBA=function(t){var e,n,i=t.data,a=i.length,r=this.red(),o=this.green(),s=this.blue(),h=this.alpha();for(e=0;e255?255:t<0?0:Math.round(t)}),Konva.Factory.addGetterSetter(Konva.Node,"green",0,function(t){return this._filterUpToDate=!1,t>255?255:t<0?0:Math.round(t)}),Konva.Factory.addGetterSetter(Konva.Node,"blue",0,Konva.Validators.RGBComponent,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"alpha",1,function(t){return this._filterUpToDate=!1,t>1?1:t<0?0:t})}(),function(){"use strict";Konva.Filters.HSV=function(t){var e,n,i,a,r,o=t.data,s=o.length,h=Math.pow(2,this.value()),l=Math.pow(2,this.saturation()),c=Math.abs(this.hue()+360)%360,d=h*l*Math.cos(c*Math.PI/180),u=h*l*Math.sin(c*Math.PI/180),f=.299*h+.701*d+.167*u,g=.587*h-.587*d+.33*u,v=.114*h-.114*d-.497*u,p=.299*h-.299*d-.328*u,m=.587*h+.413*d+.035*u,_=.114*h-.114*d+.293*u,y=.299*h-.3*d+1.25*u,S=.587*h-.586*d-1.05*u,K=.114*h+.886*d-.2*u;for(e=0;el&&(f=0);var g=(d-1+f)*h*4,v=h;do{var p=u+4*(v-1),m=o;v+m<1&&(m=0),v+m>h&&(m=0);var _=g+4*(v-1+m),y=s[p]-s[_],S=s[p+1]-s[_+1],K=s[p+2]-s[_+2],x=y,C=x>0?x:-x;if((S>0?S:-S)>C&&(x=S),(K>0?K:-K)>C&&(x=K),x*=e,a){var b=s[p]+x,w=s[p+1]+x,F=s[p+2]+x;s[p]=b>255?255:b<0?0:b,s[p+1]=w>255?255:w<0?0:w,s[p+2]=F>255?255:F<0?0:F}else{var T=n-x;T<0?T=0:T>255&&(T=255),s[p]=s[p+1]=s[p+2]=T}}while(--v)}while(--d)},Konva.Factory.addGetterSetter(Konva.Node,"embossStrength",.5,null,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"embossWhiteLevel",.5,null,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"embossDirection","top-left",null,Konva.Factory.afterSetFilter),Konva.Factory.addGetterSetter(Konva.Node,"embossBlend",!1,null,Konva.Factory.afterSetFilter)}(),function(){"use strict";function t(t,e,n,i,a){var r,o=n-e,s=a-i;return 0===o?i+s/2:0===s?i:(r=(t-e)/o,r=s*r+i)}Konva.Filters.Enhance=function(e){var n,i,a,r,o=e.data,s=o.length,h=o[0],l=h,c=o[1],d=c,u=o[2],f=u,g=this.enhance();if(0!==g){for(r=0;rl&&(l=n),(i=o[r+1])d&&(d=i),(a=o[r+2])f&&(f=a);l===h&&(l=255,h=0),d===c&&(d=255,c=0),f===u&&(f=255,u=0);var v,p,m,_,y,S,K,x,C;for(g>0?(p=l+g*(255-l),m=h-g*(h-0),y=d+g*(255-d),S=c-g*(c-0),x=f+g*(255-f),C=u-g*(u-0)):(p=l+g*(l-(v=.5*(l+h))),m=h+g*(h-v),y=d+g*(d-(_=.5*(d+c))),S=c+g*(c-_),x=f+g*(f-(K=.5*(f+u))),C=u+g*(u-K)),r=0;r=p))for(n=c;n=m||(a+=t[(i=4*(p*n+e))+0],r+=t[i+1],o+=t[i+2],s+=t[i+3],g+=1);for(a/=g,r/=g,o/=g,e=h;e=p))for(n=c;n=m||(t[(i=4*(p*n+e))+0]=a,t[i+1]=r,t[i+2]=o,t[i+3]=s)}},Konva.Factory.addGetterSetter(Konva.Node,"pixelSize",8,null,Konva.Factory.afterSetFilter)}(),function(){"use strict";Konva.Filters.Threshold=function(t){var e,n=255*this.threshold(),i=t.data,a=i.length;for(e=0;e255?255:s,c[i+1]=h>255?255:h,c[i+2]=l>255?255:l,c[i+3]=c[i+3]}while(--n)}while(--u)}}(),function(){"use strict";Konva.Filters.Solarize=function(t){var e=t.data,n=t.width,i=4*n,a=t.height;do{var r=(a-1)*i,o=n;do{var s=r+4*(o-1),h=e[s],l=e[s+1],c=e[s+2];h>127&&(h=255-h),l>127&&(l=255-l),c>127&&(c=255-c),e[s]=h,e[s+1]=l,e[s+2]=c}while(--o)}while(--a)}}(),function(){"use strict";Konva.Filters.Kaleidoscope=function(t){var e,n,i,a,r,o,s,h,l,c=t.width,d=t.height,u=Math.round(this.kaleidoscopePower()),f=Math.round(this.kaleidoscopeAngle()),g=Math.floor(c*(f%360)/360);if(!(u<1)){var v=Konva.Util.createCanvasElement();v.width=c,v.height=d;var p=v.getContext("2d").getImageData(0,0,c,d);!function(t,e,n){var i,a,r,o,s=t.data,h=e.data,l=t.width,c=t.height,d=n.polarCenterX||l/2,u=n.polarCenterY||c/2,f=0,g=0,v=0,p=0,m=Math.sqrt(d*d+u*u);a=l-d,r=c-u,m=(o=Math.sqrt(a*a+r*r))>m?o:m;var _,y,S,K,x=c,C=l,w=360/C*Math.PI/180;for(y=0;yc&&(y=_,S=0,K=-1),n=0;ny?h:y;var S,K,x,C=u,w=d,b=n.polarRotation||0;for(a=0;a255?255:r,o=o<0?0:o>255?255:o,s=s<0?0:s>255?255:s,i[e]=r,i[e+1]=o,i[e+2]=s},t.Factory.addGetterSetter(t.Node,"contrast",0,null,t.Factory.afterSetFilter)}(Konva),function(){"use strict";Konva.Container=function(t){this.__init(t)},Konva.Util.addMethods(Konva.Container,{__init:function(t){this.children=new Konva.Collection,Konva.Node.call(this,t)},getChildren:function(t){if(!t)return this.children;var e=new Konva.Collection;return this.children.each(function(n){t(n)&&e.push(n)}),e},hasChildren:function(){return this.getChildren().length>0},removeChildren:function(){for(var t,e=Konva.Collection.toCollection(this.children),n=0;n1){for(var e=0;e0},destroy:function(){return t.Node.prototype.destroy.call(this),delete t.shapes[this.colorKey],this},_useBufferCanvas:function(t){return!t&&this.perfectDrawEnabled()&&1!==this.getAbsoluteOpacity()&&this.hasFill()&&this.hasStroke()&&this.getStage()||this.perfectDrawEnabled()&&this.hasShadow()&&1!==this.getAbsoluteOpacity()&&this.hasFill()&&this.hasStroke()&&this.getStage()},getSelfRect:function(){var t=this.getSize();return{x:this._centroid?Math.round(-t.width/2):0,y:this._centroid?Math.round(-t.height/2):0,width:t.width,height:t.height}},getClientRect:function(t){var e=(t=t||{}).skipTransform,n=t.relativeTo,i=this.getSelfRect(),a=this.hasStroke()&&this.strokeWidth()||0,r=i.width+a,o=i.height+a,s=this.hasShadow()?this.shadowOffsetX():0,h=this.hasShadow()?this.shadowOffsetY():0,l=r+Math.abs(s),c=o+Math.abs(h),d=this.hasShadow()&&this.shadowBlur()||0,u=l+2*d,f=c+2*d,g=0;Math.round(a/2)!==a/2&&(g=1);var v={width:u+g,height:f+g,x:-Math.round(a/2+d)+Math.min(s,0)+i.x,y:-Math.round(a/2+d)+Math.min(h,0)+i.y};return e?v:this._transformedRect(v,n)},drawScene:function(t,e,n,i){var a,r,o,s=this.getLayer(),h=t||s.getCanvas(),l=h.getContext(),c=this._cache.canvas,d=this.sceneFunc(),u=this.hasShadow(),f=this.hasStroke();if(!this.isVisible())return this;if(c)return l.save(),s._applyTransform(this,l,e),this._drawCachedSceneCanvas(l),l.restore(),this;if(!d)return this;if(l.save(),this._useBufferCanvas(n)&&!i){if(a=this.getStage(),r=a.bufferCanvas,(o=r.getContext()).clear(),o.save(),o._applyLineJoin(this),!n)if(s)s._applyTransform(this,o,e);else{var g=this.getAbsoluteTransform(e).getMatrix();l.transform(g[0],g[1],g[2],g[3],g[4],g[5])}d.call(this,o),o.restore();var v=r.pixelRatio;u&&!h.hitCanvas?(l.save(),l._applyShadow(this),l._applyOpacity(this),l._applyGlobalCompositeOperation(this),l.drawImage(r._canvas,0,0,r.width/v,r.height/v),l.restore()):(l._applyOpacity(this),l._applyGlobalCompositeOperation(this),l.drawImage(r._canvas,0,0,r.width/v,r.height/v))}else{if(l._applyLineJoin(this),!n)if(s)s._applyTransform(this,l,e);else{var p=this.getAbsoluteTransform(e).getMatrix();l.transform(p[0],p[1],p[2],p[3],p[4],p[5])}u&&f&&!h.hitCanvas?(l.save(),n||(l._applyOpacity(this),l._applyGlobalCompositeOperation(this)),l._applyShadow(this),d.call(this,l),l.restore(),this.hasFill()&&this.getShadowForStrokeEnabled()&&d.call(this,l)):u&&!h.hitCanvas?(l.save(),n||(l._applyOpacity(this),l._applyGlobalCompositeOperation(this)),l._applyShadow(this),d.call(this,l),l.restore()):(n||(l._applyOpacity(this),l._applyGlobalCompositeOperation(this)),d.call(this,l))}return l.restore(),this},drawHit:function(t,e,n){var i=this.getLayer(),a=t||i.hitCanvas,r=a.getContext(),o=this.hitFunc()||this.sceneFunc(),s=this._cache.canvas,h=s&&s.hit;if(!this.shouldDrawHit(a))return this;if(i&&i.clearHitCache(),h)return r.save(),i._applyTransform(this,r,e),this._drawCachedHitCanvas(r),r.restore(),this;if(!o)return this;if(r.save(),r._applyLineJoin(this),!n)if(i)i._applyTransform(this,r,e);else{var l=this.getAbsoluteTransform(e).getMatrix();r.transform(l[0],l[1],l[2],l[3],l[4],l[5])}return o.call(this,r),r.restore(),this},drawHitFromCache:function(e){var n,i,a,r,o,s=e||0,h=this._cache.canvas,l=this._getCachedSceneCanvas(),c=h.hit,d=c.getContext(),u=c.getWidth(),f=c.getHeight();d.clear(),d.drawImage(l._canvas,0,0,u,f);try{for(a=(i=(n=d.getImageData(0,0,u,f)).data).length,r=t.Util._hexToRgb(this.colorKey),o=0;os?(i[o]=r.r,i[o+1]=r.g,i[o+2]=r.b,i[o+3]=255):i[o+3]=0;d.putImageData(n,0,0)}catch(e){t.Util.error("Unable to draw hit graph from cached scene canvas. "+e.message)}return this}}),t.Util.extend(t.Shape,t.Node),t.Factory.addGetterSetter(t.Shape,"stroke"),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeRed",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeGreen",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeBlue",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeAlpha",1,t.Validators.alphaComponent),t.Factory.addGetterSetter(t.Shape,"strokeWidth",2),t.Factory.addGetterSetter(t.Shape,"strokeHitEnabled",!0),t.Factory.addGetterSetter(t.Shape,"perfectDrawEnabled",!0),t.Factory.addGetterSetter(t.Shape,"shadowForStrokeEnabled",!0),t.Factory.addGetterSetter(t.Shape,"lineJoin"),t.Factory.addGetterSetter(t.Shape,"lineCap"),t.Factory.addGetterSetter(t.Shape,"sceneFunc"),t.Factory.addGetterSetter(t.Shape,"hitFunc"),t.Factory.addGetterSetter(t.Shape,"dash"),t.Factory.addGetterSetter(t.Shape,"dashOffset",0),t.Factory.addGetterSetter(t.Shape,"shadowColor"),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowRed",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowGreen",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowBlue",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowAlpha",1,t.Validators.alphaComponent),t.Factory.addGetterSetter(t.Shape,"shadowBlur"),t.Factory.addGetterSetter(t.Shape,"shadowOpacity"),t.Factory.addComponentsGetterSetter(t.Shape,"shadowOffset",["x","y"]),t.Factory.addGetterSetter(t.Shape,"shadowOffsetX",0),t.Factory.addGetterSetter(t.Shape,"shadowOffsetY",0),t.Factory.addGetterSetter(t.Shape,"fillPatternImage"),t.Factory.addGetterSetter(t.Shape,"fill"),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillRed",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillGreen",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillBlue",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillAlpha",1,t.Validators.alphaComponent),t.Factory.addGetterSetter(t.Shape,"fillPatternX",0),t.Factory.addGetterSetter(t.Shape,"fillPatternY",0),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientColorStops"),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientStartRadius",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientEndRadius",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientColorStops"),t.Factory.addGetterSetter(t.Shape,"fillPatternRepeat","repeat"),t.Factory.addGetterSetter(t.Shape,"fillEnabled",!0),t.Factory.addGetterSetter(t.Shape,"strokeEnabled",!0),t.Factory.addGetterSetter(t.Shape,"shadowEnabled",!0),t.Factory.addGetterSetter(t.Shape,"dashEnabled",!0),t.Factory.addGetterSetter(t.Shape,"strokeScaleEnabled",!0),t.Factory.addGetterSetter(t.Shape,"fillPriority","color"),t.Factory.addComponentsGetterSetter(t.Shape,"fillPatternOffset",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillPatternOffsetX",0),t.Factory.addGetterSetter(t.Shape,"fillPatternOffsetY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillPatternScale",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillPatternScaleX",1),t.Factory.addGetterSetter(t.Shape,"fillPatternScaleY",1),t.Factory.addComponentsGetterSetter(t.Shape,"fillLinearGradientStartPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientStartPointX",0),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientStartPointY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillLinearGradientEndPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientEndPointX",0),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientEndPointY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillRadialGradientStartPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientStartPointX",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientStartPointY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillRadialGradientEndPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientEndPointX",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientEndPointY",0),t.Factory.addGetterSetter(t.Shape,"fillPatternRotation",0),t.Factory.backCompat(t.Shape,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"}),t.Collection.mapMethods(t.Shape)}(Konva),function(){"use strict";function t(t,e){t.content.addEventListener(e,function(n){t[a+e](n)},!1)}var e="mouseout",n="mouseleave",i="touchstart",a="_",r=["mousedown","mousemove","mouseup",e,i,"touchmove","touchend","mouseover","wheel","contextmenu"],o=r.length;Konva.Stage=function(t){this.___init(t)},Konva.Util.addMethods(Konva.Stage,{___init:function(t){this.nodeType="Stage",Konva.Container.call(this,t),this._id=Konva.idCounter++,this._buildDOM(),this._bindContentEvents(),this._enableNestedTransforms=!1,Konva.stages.push(this)},_validateAdd:function(t){"Layer"!==t.getType()&&Konva.Util.throw("You may only add layers to the stage.")},setContainer:function(t){if("string"==typeof t){if("."===t.charAt(0)){var e=t.slice(1);t=Konva.document.getElementsByClassName(e)[0]}else{var n;n="#"!==t.charAt(0)?t:t.slice(1),t=Konva.document.getElementById(n)}if(!t)throw"Can not find container in document with id "+n}return this._setAttr("container",t),this},shouldDrawHit:function(){return!0},draw:function(){return Konva.Node.prototype.draw.call(this),this},setHeight:function(t){return Konva.Node.prototype.setHeight.call(this,t),this._resizeDOM(),this},setWidth:function(t){return Konva.Node.prototype.setWidth.call(this,t),this._resizeDOM(),this},clear:function(){var t,e=this.children,n=e.length;for(t=0;t-1&&Konva.stages.splice(e,1),this},getPointerPosition:function(){return this.pointerPos},getStage:function(){return this},getContent:function(){return this.content},toDataURL:function(t){var e=(t=t||{}).mimeType||null,n=t.quality||null,i=t.x||0,a=t.y||0,r=new Konva.SceneCanvas({width:t.width||this.getWidth(),height:t.height||this.getHeight(),pixelRatio:t.pixelRatio}),o=r.getContext()._context,s=this.children;(i||a)&&o.translate(-1*i,-1*a),s.each(function(t){var e=t.getCanvas().getWidth(),n=t.getCanvas().getHeight(),i=t.getCanvas().getPixelRatio();o.drawImage(t.getCanvas()._canvas,0,0,e/i,n/i)});var h=r.toDataURL(e,n);return t.callback&&t.callback(h),h},toImage:function(t){var e=t.callback;t.callback=function(t){Konva.Util._getImage(t,function(t){e(t)})},this.toDataURL(t)},getIntersection:function(t,e){var n,i,a=this.getChildren();for(n=a.length-1;n>=0;n--)if(i=a[n].getIntersection(t,e))return i;return null},_resizeDOM:function(){if(this.content){var t,e,n=this.getWidth(),i=this.getHeight(),a=this.getChildren(),r=a.length;for(this.content.style.width=n+"px",this.content.style.height=i+"px",this.bufferCanvas.setSize(n,i),this.bufferHitCanvas.setSize(n,i),t=0;t1){for(var e=0;e0){var a=t.touches[0];n=a.clientX-e.left,i=a.clientY-e.top}}else n=t.clientX-e.left,i=t.clientY-e.top;null!==n&&null!==i&&(this.pointerPos={x:n,y:i})},_getContentPosition:function(){var t=this.content.getBoundingClientRect?this.content.getBoundingClientRect():{top:0,left:0};return{top:t.top,left:t.left}},_buildDOM:function(){if(this.bufferCanvas=new Konva.SceneCanvas,this.bufferHitCanvas=new Konva.HitCanvas({pixelRatio:1}),Konva.isBrowser){var t=this.getContainer();if(!t)throw"Stage has no container. A container is required.";t.innerHTML="",this.content=Konva.document.createElement("div"),this.content.style.position="relative",this.content.className="konvajs-content",this.content.setAttribute("role","presentation"),t.appendChild(this.content),this._resizeDOM()}},_onContent:function(t,e){var n,i,a=t.split(" "),r=a.length;for(n=0;n0?{antialiased:!0}:{}},drawScene:function(t,e){var n=this.getLayer(),i=t||n&&n.getCanvas();return this._fire("beforeDraw",{node:this}),this.getClearBeforeDraw()&&i.getContext().clear(),Konva.Container.prototype.drawScene.call(this,i,e),this._fire("draw",{node:this}),this},drawHit:function(t,e){var n=this.getLayer(),i=t||n&&n.hitCanvas;return n&&n.getClearBeforeDraw()&&n.getHitCanvas().getContext().clear(),Konva.Container.prototype.drawHit.call(this,i,e),this.imageData=null,this},clear:function(t){return Konva.BaseLayer.prototype.clear.call(this,t),this.getHitCanvas().getContext().clear(t),this.imageData=null,this},setVisible:function(t){return Konva.Node.prototype.setVisible.call(this,t),t?(this.getCanvas()._canvas.style.display="block",this.hitCanvas._canvas.style.display="block"):(this.getCanvas()._canvas.style.display="none",this.hitCanvas._canvas.style.display="none"),this},enableHitGraph:function(){return this.setHitGraphEnabled(!0),this},disableHitGraph:function(){return this.setHitGraphEnabled(!1),this},setSize:function(t,e){return Konva.BaseLayer.prototype.setSize.call(this,t,e),this.hitCanvas.setSize(t,e),this}}),Konva.Util.extend(Konva.Layer,Konva.BaseLayer),Konva.Factory.addGetterSetter(Konva.Layer,"hitGraphEnabled",!0),Konva.Collection.mapMethods(Konva.Layer)}(),function(){"use strict";Konva.FastLayer=function(t){this.____init(t)},Konva.Util.addMethods(Konva.FastLayer,{____init:function(t){this.nodeType="Layer",this.canvas=new Konva.SceneCanvas,Konva.BaseLayer.call(this,t)},_validateAdd:function(t){"Shape"!==t.getType()&&Konva.Util.throw("You may only add shapes to a fast layer.")},_setCanvasSize:function(t,e){this.canvas.setSize(t,e)},hitGraphEnabled:function(){return!1},getIntersection:function(){return null},drawScene:function(t){var e=this.getLayer(),n=t||e&&e.getCanvas();return this.getClearBeforeDraw()&&n.getContext().clear(),Konva.Container.prototype.drawScene.call(this,n),this},draw:function(){return this.drawScene(),this},setVisible:function(t){return Konva.Node.prototype.setVisible.call(this,t),this.getCanvas()._canvas.style.display=t?"block":"none",this}}),Konva.Util.extend(Konva.FastLayer,Konva.BaseLayer),Konva.Collection.mapMethods(Konva.FastLayer)}(),function(){"use strict";Konva.Group=function(t){this.___init(t)},Konva.Util.addMethods(Konva.Group,{___init:function(t){this.nodeType="Group",Konva.Container.call(this,t)},_validateAdd:function(t){var e=t.getType();"Group"!==e&&"Shape"!==e&&Konva.Util.throw("You may only add groups and shapes to groups.")}}),Konva.Util.extend(Konva.Group,Konva.Container),Konva.Collection.mapMethods(Konva.Group)}(),function(t){"use strict";function e(){return i.apply(t.global,arguments)}var n=t.global.performance&&t.global.performance.now?function(){return t.global.performance.now()}:function(){return(new Date).getTime()},i=t.global.requestAnimationFrame||t.global.webkitRequestAnimationFrame||t.global.mozRequestAnimationFrame||t.global.oRequestAnimationFrame||t.global.msRequestAnimationFrame||function(t){setTimeout(t,1e3/60)};t.Animation=function(e,i){var a=t.Animation;this.func=e,this.setLayers(i),this.id=a.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:n()}},t.Animation.prototype={setLayers:function(t){var e=[];return e=t?t.length>0?t:[t]:[],this.layers=e,this},getLayers:function(){return this.layers},addLayer:function(t){var e,n=this.layers,i=n.length;for(e=0;ethis.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())},getTime:function(){return this._time},setPosition:function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},getPosition:function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},play:function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},reverse:function(){this.state=3,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;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},pause:function(){this.state=1,this.fire("onPause")},getTimer:function(){return(new Date).getTime()}},Konva.Tween=function(n){var a,r,o=this,s=n.node,h=s._id,l=n.easing||Konva.Easings.Linear,c=!!n.yoyo;a=void 0===n.duration?1:0===n.duration?.001:n.duration,this.node=s,this._id=e++;var d=s.getLayer()||(s instanceof Konva.Stage?s.getLayers():null);d||Konva.Util.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new Konva.Animation(function(){o.tween.onEnterFrame()},d),this.tween=new i(r,function(t){o._tweenFunc(t)},l,0,1,1e3*a,c),this._addListeners(),Konva.Tween.attrs[h]||(Konva.Tween.attrs[h]={}),Konva.Tween.attrs[h][this._id]||(Konva.Tween.attrs[h][this._id]={}),Konva.Tween.tweens[h]||(Konva.Tween.tweens[h]={});for(r in n)void 0===t[r]&&this._addAttr(r,n[r]);this.reset(),this.onFinish=n.onFinish,this.onReset=n.onReset},Konva.Tween.attrs={},Konva.Tween.tweens={},Konva.Tween.prototype={_addAttr:function(t,e){var i,a,r,o,s,h,l,c=this.node,d=c._id;if((r=Konva.Tween.tweens[d][t])&&delete Konva.Tween.attrs[d][r][t],i=c.getAttr(t),Konva.Util._isArray(e))for(a=[],s=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(l=i,i=Konva.Util._prepareArrayForTween(i,e,c.closed())):(h=e,e=Konva.Util._prepareArrayForTween(e,i,c.closed()))),o=0;oc)for(;_.length>0;){for(var S=0,K=_.length,x="",C=0;S>>1,b=_.slice(0,w+1),F=this._getTextWidth(b);F<=c?(S=w+1,x=b,C=F):K=w}if(!x)break;if(v){var T=Math.max(x.lastIndexOf(" "),x.lastIndexOf("-"))+1;T>0&&(S=T,x=x.slice(0,S),C=this._getTextWidth(x))}if(this._addTextLine(x),i=Math.max(i,C),u+=a,!g||h&&u+a>d)break;if((_=_.slice(S)).length>0&&(y=this._getTextWidth(_))<=c){this._addTextLine(_),u+=a,i=Math.max(i,y);break}}else this._addTextLine(_),u+=a,i=Math.max(i,y);if(h&&u+a>d)break}t().restore(),this.textHeight=n,this.textWidth=i}},Konva.Util.extend(Konva.Text,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Text,"fontFamily","Arial"),Konva.Factory.addGetterSetter(Konva.Text,"fontSize",12),Konva.Factory.addGetterSetter(Konva.Text,"fontStyle","normal"),Konva.Factory.addGetterSetter(Konva.Text,"fontVariant","normal"),Konva.Factory.addGetterSetter(Konva.Text,"padding",0),Konva.Factory.addGetterSetter(Konva.Text,"align","left"),Konva.Factory.addGetterSetter(Konva.Text,"lineHeight",1),Konva.Factory.addGetterSetter(Konva.Text,"wrap","word"),Konva.Factory.addGetterSetter(Konva.Text,"letterSpacing",0),Konva.Factory.addGetter(Konva.Text,"text",""),Konva.Factory.addOverloadedGetterSetter(Konva.Text,"text"),Konva.Factory.addGetterSetter(Konva.Text,"textDecoration",""),Konva.Collection.mapMethods(Konva.Text)}(),function(){"use strict";Konva.Line=function(t){this.___init(t)},Konva.Line.prototype={___init:function(t){Konva.Shape.call(this,t),this.className="Line",this.on("pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva",function(){this._clearCache("tensionPoints")}),this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e,n,i,a=this.getPoints(),r=a.length,o=this.getTension(),s=this.getClosed(),h=this.getBezier();if(r){if(t.beginPath(),t.moveTo(a[0],a[1]),0!==o&&r>4){for(n=(e=this.getTensionPoints()).length,i=s?0:4,s||t.quadraticCurveTo(e[0],e[1],e[2],e[3]);ih?s:h,g=s>h?1:s/h,v=s>h?h/s:1;t.translate(r,o),t.rotate(d),t.scale(g,v),t.arc(0,0,f,l,l+c,1-u),t.scale(1/g,1/v),t.rotate(-d),t.translate(-r,-o);break;case"z":t.closePath()}}t.fillStrokeShape(this)},getSelfRect:function(){var t=[];this.dataArray.forEach(function(e){t=t.concat(e.points)});for(var e,n,i=t[0],a=t[0],r=t[1],o=t[1],s=0;s0&&""===c[0]&&c.shift();for(var d=0;d0&&!isNaN(c[0]);){var u,f,g,v,p,m,_,y,S,K,x=null,C=[],w=o,b=s;switch(l){case"l":o+=c.shift(),s+=c.shift(),x="L",C.push(o,s);break;case"L":o=c.shift(),s=c.shift(),C.push(o,s);break;case"m":var F=c.shift(),T=c.shift();if(o+=F,s+=T,x="M",r.length>2&&"z"===r[r.length-1].command)for(var P=r.length-2;P>=0;P--)if("M"===r[P].command){o=r[P].points[0]+F,s=r[P].points[1]+T;break}C.push(o,s),l="l";break;case"M":o=c.shift(),s=c.shift(),x="M",C.push(o,s),l="L";break;case"h":o+=c.shift(),x="L",C.push(o,s);break;case"H":o=c.shift(),x="L",C.push(o,s);break;case"v":s+=c.shift(),x="L",C.push(o,s);break;case"V":s=c.shift(),x="L",C.push(o,s);break;case"C":C.push(c.shift(),c.shift(),c.shift(),c.shift()),o=c.shift(),s=c.shift(),C.push(o,s);break;case"c":C.push(o+c.shift(),s+c.shift(),o+c.shift(),s+c.shift()),o+=c.shift(),s+=c.shift(),x="C",C.push(o,s);break;case"S":f=o,g=s,"C"===(u=r[r.length-1]).command&&(f=o+(o-u.points[2]),g=s+(s-u.points[3])),C.push(f,g,c.shift(),c.shift()),o=c.shift(),s=c.shift(),x="C",C.push(o,s);break;case"s":f=o,g=s,"C"===(u=r[r.length-1]).command&&(f=o+(o-u.points[2]),g=s+(s-u.points[3])),C.push(f,g,o+c.shift(),s+c.shift()),o+=c.shift(),s+=c.shift(),x="C",C.push(o,s);break;case"Q":C.push(c.shift(),c.shift()),o=c.shift(),s=c.shift(),C.push(o,s);break;case"q":C.push(o+c.shift(),s+c.shift()),o+=c.shift(),s+=c.shift(),x="Q",C.push(o,s);break;case"T":f=o,g=s,"Q"===(u=r[r.length-1]).command&&(f=o+(o-u.points[0]),g=s+(s-u.points[1])),o=c.shift(),s=c.shift(),x="Q",C.push(f,g,o,s);break;case"t":f=o,g=s,"Q"===(u=r[r.length-1]).command&&(f=o+(o-u.points[0]),g=s+(s-u.points[1])),o+=c.shift(),s+=c.shift(),x="Q",C.push(f,g,o,s);break;case"A":v=c.shift(),p=c.shift(),m=c.shift(),_=c.shift(),y=c.shift(),S=o,K=s,o=c.shift(),s=c.shift(),x="A",C=this.convertEndpointToCenterParameterization(S,K,o,s,_,y,v,p,m);break;case"a":v=c.shift(),p=c.shift(),m=c.shift(),_=c.shift(),y=c.shift(),S=o,K=s,o+=c.shift(),s+=c.shift(),x="A",C=this.convertEndpointToCenterParameterization(S,K,o,s,_,y,v,p,m)}r.push({command:x||l,points:C,start:{x:w,y:b},pathLength:this.calcLength(w,b,x||l,C)})}"z"!==l&&"Z"!==l||r.push({command:"z",points:[],start:void 0,pathLength:0})}return r},Konva.Path.calcLength=function(t,e,n,i){var a,r,o,s,h=Konva.Path;switch(n){case"L":return h.getLineLength(t,e,i[0],i[1]);case"C":for(a=0,r=h.getPointOnCubicBezier(0,t,e,i[0],i[1],i[2],i[3],i[4],i[5]),s=.01;s<=1;s+=.01)o=h.getPointOnCubicBezier(s,t,e,i[0],i[1],i[2],i[3],i[4],i[5]),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;return a;case"Q":for(a=0,r=h.getPointOnQuadraticBezier(0,t,e,i[0],i[1],i[2],i[3]),s=.01;s<=1;s+=.01)o=h.getPointOnQuadraticBezier(s,t,e,i[0],i[1],i[2],i[3]),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;return a;case"A":a=0;var l=i[4],c=i[5],d=i[4]+c,u=Math.PI/180;if(Math.abs(l-d)d;s-=u)o=h.getPointOnEllipticalArc(i[0],i[1],i[2],i[3],s,0),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;else for(s=l+u;s1&&(o*=Math.sqrt(u),s*=Math.sqrt(u));var f=Math.sqrt((o*o*(s*s)-o*o*(d*d)-s*s*(c*c))/(o*o*(d*d)+s*s*(c*c)));a===r&&(f*=-1),isNaN(f)&&(f=0);var g=f*o*d/s,v=f*-s*c/o,p=(t+n)/2+Math.cos(l)*g-Math.sin(l)*v,m=(e+i)/2+Math.sin(l)*g+Math.cos(l)*v,_=function(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])},y=function(t,e){return(t[0]*e[0]+t[1]*e[1])/(_(t)*_(e))},S=function(t,e){return(t[0]*e[1]=1&&(w=0),0===r&&w>0&&(w-=2*Math.PI),1===r&&w<0&&(w+=2*Math.PI),[p,m,o,s,K,w,l,r]},Konva.Factory.addGetterSetter(Konva.Path,"data"),Konva.Collection.mapMethods(Konva.Path)}(),function(){"use strict";function t(t){t.fillText(this.partialText,0,0)}function e(t){t.strokeText(this.partialText,0,0)}Konva.TextPath=function(t){this.___init(t)},Konva.TextPath.prototype={___init:function(n){var i=this;this.dummyCanvas=Konva.Util.createCanvasElement(),this.dataArray=[],Konva.Shape.call(this,n),this._fillFunc=t,this._strokeFunc=e,this._fillFuncHit=t,this._strokeFuncHit=e,this.className="TextPath",this.dataArray=Konva.Path.parsePathData(this.attrs.data),this.on("dataChange.konva",function(){i.dataArray=Konva.Path.parsePathData(this.attrs.data),i._setTextData()}),this.on("textChange.konva alignChange.konva letterSpacingChange.konva",i._setTextData),i._setTextData(),this.sceneFunc(this._sceneFunc),this.hitFunc(this._hitFunc)},_sceneFunc:function(t){t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",this.getTextBaseline()),t.setAttr("textAlign","left"),t.save();var e=this.textDecoration(),n=this.fill(),i=this.fontSize(),a=this.glyphInfo;"underline"===e&&t.beginPath();for(var r=0;r=1){var n=e[0].p0;t.moveTo(n.x,n.y)}for(var i=0;i0&&(r+=t.dataArray[o].pathLength);var s=0;"center"===i&&(s=Math.max(0,r/2-a/2)),"right"===i&&(s=Math.max(0,r-a));for(var h,l,c,d=this.getText().split(""),u=this.getText().split(" ").length-1,f=-1,g=0,v=function(){g=0;for(var e=t.dataArray,n=f+1;n0)return f=n,e[n];"M"===e[n].command&&(h={x:e[n].points[0],y:e[n].points[1]})}return{}},p=function(e){var o=t._getTextSize(e).width+n;" "===e&&"justify"===i&&(o+=(r-a)/u);var s=0,d=0;for(l=void 0;Math.abs(o-s)/o>.01&&d<25;){d++;for(var f=s;void 0===c;)(c=v())&&f+c.pathLengtho?l=Konva.Path.getPointOnLine(o,h.x,h.y,c.points[0],c.points[1],h.x,h.y):c=void 0;break;case"A":var m=c.points[4],_=c.points[5],y=c.points[4]+_;0===g?g=m+1e-8:o>s?g+=Math.PI/180*_/Math.abs(_):g-=Math.PI/360*_/Math.abs(_),(_<0&&g=0&&g>y)&&(g=y,p=!0),l=Konva.Path.getPointOnEllipticalArc(c.points[0],c.points[1],c.points[2],c.points[3],g,c.points[6]);break;case"C":0===g?g=o>c.pathLength?1e-8:o/c.pathLength:o>s?g+=(o-s)/c.pathLength:g-=(s-o)/c.pathLength,g>1&&(g=1,p=!0),l=Konva.Path.getPointOnCubicBezier(g,c.start.x,c.start.y,c.points[0],c.points[1],c.points[2],c.points[3],c.points[4],c.points[5]);break;case"Q":0===g?g=o/c.pathLength:o>s?g+=(o-s)/c.pathLength:g-=(s-o)/c.pathLength,g>1&&(g=1,p=!0),l=Konva.Path.getPointOnQuadraticBezier(g,c.start.x,c.start.y,c.points[0],c.points[1],c.points[2],c.points[3])}void 0!==l&&(s=Konva.Path.getLineLength(h.x,h.y,l.x,l.y)),p&&(p=!1,c=void 0)}},m=t._getTextSize("C").width+n,_=0;_=0}),this.findOne(".top-center").setAttrs({x:n/2,y:0,visible:r&&a.indexOf("top-center")>=0}),this.findOne(".top-right").setAttrs({x:n,y:0,visible:r&&a.indexOf("top-right")>=0}),this.findOne(".middle-left").setAttrs({x:0,y:i/2,visible:r&&a.indexOf("middle-left")>=0}),this.findOne(".middle-right").setAttrs({x:n,y:i/2,visible:r&&a.indexOf("middle-right")>=0}),this.findOne(".bottom-left").setAttrs({x:0,y:i,visible:r&&a.indexOf("bottom-left")>=0}),this.findOne(".bottom-center").setAttrs({x:n/2,y:i,visible:r&&a.indexOf("bottom-center")>=0}),this.findOne(".bottom-right").setAttrs({x:n,y:i,visible:r&&a.indexOf("bottom-right")>=0}),this.findOne(".rotater").setAttrs({x:n/2,y:-this.rotateHandlerOffset(),visible:this.rotateEnabled()}),this.findOne(".back").setAttrs({width:n,height:i,visible:this.lineEnabled()})},destroy:function(){t.Group.prototype.destroy.call(this),this._el.off(".resizer"),window.removeEventListener("mousemove",this.handleMouseMove),window.removeEventListener("touchmove",this.handleMouseMove),window.removeEventListener("mouseup",this.handleMouseUp),window.removeEventListener("touchend",this.handleMouseUp)}},t.Util.extend(t.Transformer,t.Group),t.Factory.addGetterSetter(t.Transformer,"enabledResizers",i),t.Factory.addGetterSetter(t.Transformer,"enabledResizers",i,function(e){return e instanceof Array||t.Util.warn("enabledResizers value should be an array"),e instanceof Array&&e.forEach(function(e){-1===i.indexOf("name")&&t.Util.warn("Unknown resizer name: "+e+". Available names are: "+i.join(", "))}),e||[]}),t.Factory.addGetterSetter(t.Transformer,"resizeEnabled",!0),t.Factory.addGetterSetter(t.Transformer,"rotateEnabled",!0),t.Factory.addGetterSetter(t.Transformer,"rotationSnaps",[]),t.Factory.addGetterSetter(t.Transformer,"rotateHandlerOffset",50),t.Factory.addGetterSetter(t.Transformer,"lineEnabled",!0),t.Collection.mapMethods(t.Transformer)}(Konva); \ No newline at end of file +Konva.Filters.Sepia=function(t){var e,n,i,a,r,o,s,h,l,c=t.data,d=t.width,u=t.height,f=4*d;do{e=(u-1)*f,n=d;do{s=.393*(a=c[i=e+4*(n-1)])+.769*(r=c[i+1])+.189*(o=c[i+2]),h=.349*a+.686*r+.168*o,l=.272*a+.534*r+.131*o,c[i]=s>255?255:s,c[i+1]=h>255?255:h,c[i+2]=l>255?255:l,c[i+3]=c[i+3]}while(--n)}while(--u)}}(),function(){"use strict";Konva.Filters.Solarize=function(t){var e=t.data,n=t.width,i=4*n,a=t.height;do{var r=(a-1)*i,o=n;do{var s=r+4*(o-1),h=e[s],l=e[s+1],c=e[s+2];h>127&&(h=255-h),l>127&&(l=255-l),c>127&&(c=255-c),e[s]=h,e[s+1]=l,e[s+2]=c}while(--o)}while(--a)}}(),function(){"use strict";Konva.Filters.Kaleidoscope=function(t){var e,n,i,a,r,o,s,h,l,c=t.width,d=t.height,u=Math.round(this.kaleidoscopePower()),f=Math.round(this.kaleidoscopeAngle()),g=Math.floor(c*(f%360)/360);if(!(u<1)){var v=Konva.Util.createCanvasElement();v.width=c,v.height=d;var p=v.getContext("2d").getImageData(0,0,c,d);!function(t,e,n){var i,a,r,o,s=t.data,h=e.data,l=t.width,c=t.height,d=n.polarCenterX||l/2,u=n.polarCenterY||c/2,f=0,g=0,v=0,p=0,m=Math.sqrt(d*d+u*u);a=l-d,r=c-u,m=(o=Math.sqrt(a*a+r*r))>m?o:m;var _,y,S,K,x=c,C=l,b=360/C*Math.PI/180;for(y=0;yc&&(y=_,S=0,K=-1),n=0;ny?h:y;var S,K,x,C=u,b=d,w=n.polarRotation||0;for(a=0;a255?255:r,o=o<0?0:o>255?255:o,s=s<0?0:s>255?255:s,i[e]=r,i[e+1]=o,i[e+2]=s},t.Factory.addGetterSetter(t.Node,"contrast",0,null,t.Factory.afterSetFilter)}(Konva),function(){"use strict";Konva.Container=function(t){this.__init(t)},Konva.Util.addMethods(Konva.Container,{__init:function(t){this.children=new Konva.Collection,Konva.Node.call(this,t)},getChildren:function(t){if(!t)return this.children;var e=new Konva.Collection;return this.children.each(function(n){t(n)&&e.push(n)}),e},hasChildren:function(){return this.getChildren().length>0},removeChildren:function(){for(var t,e=Konva.Collection.toCollection(this.children),n=0;n1){for(var e=0;e0},destroy:function(){return t.Node.prototype.destroy.call(this),delete t.shapes[this.colorKey],this},_useBufferCanvas:function(t){return!t&&this.perfectDrawEnabled()&&1!==this.getAbsoluteOpacity()&&this.hasFill()&&this.hasStroke()&&this.getStage()||this.perfectDrawEnabled()&&this.hasShadow()&&1!==this.getAbsoluteOpacity()&&this.hasFill()&&this.hasStroke()&&this.getStage()},getSelfRect:function(){var t=this.getSize();return{x:this._centroid?Math.round(-t.width/2):0,y:this._centroid?Math.round(-t.height/2):0,width:t.width,height:t.height}},getClientRect:function(t){var e=(t=t||{}).skipTransform,n=t.relativeTo,i=this.getSelfRect(),a=this.hasStroke()&&this.strokeWidth()||0,r=i.width+a,o=i.height+a,s=this.hasShadow()?this.shadowOffsetX():0,h=this.hasShadow()?this.shadowOffsetY():0,l=r+Math.abs(s),c=o+Math.abs(h),d=this.hasShadow()&&this.shadowBlur()||0,u=l+2*d,f=c+2*d,g=0;Math.round(a/2)!==a/2&&(g=1);var v={width:u+g,height:f+g,x:-Math.round(a/2+d)+Math.min(s,0)+i.x,y:-Math.round(a/2+d)+Math.min(h,0)+i.y};return e?v:this._transformedRect(v,n)},drawScene:function(t,e,n,i){var a,r,o,s=this.getLayer(),h=t||s.getCanvas(),l=h.getContext(),c=this._cache.canvas,d=this.sceneFunc(),u=this.hasShadow(),f=this.hasStroke();if(!this.isVisible())return this;if(c)return l.save(),s._applyTransform(this,l,e),this._drawCachedSceneCanvas(l),l.restore(),this;if(!d)return this;if(l.save(),this._useBufferCanvas(n)&&!i){if(a=this.getStage(),r=a.bufferCanvas,(o=r.getContext()).clear(),o.save(),o._applyLineJoin(this),!n)if(s)s._applyTransform(this,o,e);else{var g=this.getAbsoluteTransform(e).getMatrix();l.transform(g[0],g[1],g[2],g[3],g[4],g[5])}d.call(this,o),o.restore();var v=r.pixelRatio;u&&!h.hitCanvas?(l.save(),l._applyShadow(this),l._applyOpacity(this),l._applyGlobalCompositeOperation(this),l.drawImage(r._canvas,0,0,r.width/v,r.height/v),l.restore()):(l._applyOpacity(this),l._applyGlobalCompositeOperation(this),l.drawImage(r._canvas,0,0,r.width/v,r.height/v))}else{if(l._applyLineJoin(this),!n)if(s)s._applyTransform(this,l,e);else{var p=this.getAbsoluteTransform(e).getMatrix();l.transform(p[0],p[1],p[2],p[3],p[4],p[5])}u&&f&&!h.hitCanvas?(l.save(),n||(l._applyOpacity(this),l._applyGlobalCompositeOperation(this)),l._applyShadow(this),d.call(this,l),l.restore(),this.hasFill()&&this.getShadowForStrokeEnabled()&&d.call(this,l)):u&&!h.hitCanvas?(l.save(),n||(l._applyOpacity(this),l._applyGlobalCompositeOperation(this)),l._applyShadow(this),d.call(this,l),l.restore()):(n||(l._applyOpacity(this),l._applyGlobalCompositeOperation(this)),d.call(this,l))}return l.restore(),this},drawHit:function(t,e,n){var i=this.getLayer(),a=t||i.hitCanvas,r=a.getContext(),o=this.hitFunc()||this.sceneFunc(),s=this._cache.canvas,h=s&&s.hit;if(!this.shouldDrawHit(a))return this;if(i&&i.clearHitCache(),h)return r.save(),i._applyTransform(this,r,e),this._drawCachedHitCanvas(r),r.restore(),this;if(!o)return this;if(r.save(),r._applyLineJoin(this),!n)if(i)i._applyTransform(this,r,e);else{var l=this.getAbsoluteTransform(e).getMatrix();r.transform(l[0],l[1],l[2],l[3],l[4],l[5])}return o.call(this,r),r.restore(),this},drawHitFromCache:function(e){var n,i,a,r,o,s=e||0,h=this._cache.canvas,l=this._getCachedSceneCanvas(),c=h.hit,d=c.getContext(),u=c.getWidth(),f=c.getHeight();d.clear(),d.drawImage(l._canvas,0,0,u,f);try{for(a=(i=(n=d.getImageData(0,0,u,f)).data).length,r=t.Util._hexToRgb(this.colorKey),o=0;os?(i[o]=r.r,i[o+1]=r.g,i[o+2]=r.b,i[o+3]=255):i[o+3]=0;d.putImageData(n,0,0)}catch(e){t.Util.error("Unable to draw hit graph from cached scene canvas. "+e.message)}return this}}),t.Util.extend(t.Shape,t.Node),t.Factory.addGetterSetter(t.Shape,"stroke"),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeRed",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeGreen",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeBlue",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"strokeAlpha",1,t.Validators.alphaComponent),t.Factory.addGetterSetter(t.Shape,"strokeWidth",2),t.Factory.addGetterSetter(t.Shape,"strokeHitEnabled",!0),t.Factory.addGetterSetter(t.Shape,"perfectDrawEnabled",!0),t.Factory.addGetterSetter(t.Shape,"shadowForStrokeEnabled",!0),t.Factory.addGetterSetter(t.Shape,"lineJoin"),t.Factory.addGetterSetter(t.Shape,"lineCap"),t.Factory.addGetterSetter(t.Shape,"sceneFunc"),t.Factory.addGetterSetter(t.Shape,"hitFunc"),t.Factory.addGetterSetter(t.Shape,"dash"),t.Factory.addGetterSetter(t.Shape,"dashOffset",0),t.Factory.addGetterSetter(t.Shape,"shadowColor"),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowRed",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowGreen",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowBlue",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"shadowAlpha",1,t.Validators.alphaComponent),t.Factory.addGetterSetter(t.Shape,"shadowBlur"),t.Factory.addGetterSetter(t.Shape,"shadowOpacity"),t.Factory.addComponentsGetterSetter(t.Shape,"shadowOffset",["x","y"]),t.Factory.addGetterSetter(t.Shape,"shadowOffsetX",0),t.Factory.addGetterSetter(t.Shape,"shadowOffsetY",0),t.Factory.addGetterSetter(t.Shape,"fillPatternImage"),t.Factory.addGetterSetter(t.Shape,"fill"),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillRed",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillGreen",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillBlue",0,t.Validators.RGBComponent),t.Factory.addDeprecatedGetterSetter(t.Shape,"fillAlpha",1,t.Validators.alphaComponent),t.Factory.addGetterSetter(t.Shape,"fillPatternX",0),t.Factory.addGetterSetter(t.Shape,"fillPatternY",0),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientColorStops"),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientStartRadius",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientEndRadius",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientColorStops"),t.Factory.addGetterSetter(t.Shape,"fillPatternRepeat","repeat"),t.Factory.addGetterSetter(t.Shape,"fillEnabled",!0),t.Factory.addGetterSetter(t.Shape,"strokeEnabled",!0),t.Factory.addGetterSetter(t.Shape,"shadowEnabled",!0),t.Factory.addGetterSetter(t.Shape,"dashEnabled",!0),t.Factory.addGetterSetter(t.Shape,"strokeScaleEnabled",!0),t.Factory.addGetterSetter(t.Shape,"fillPriority","color"),t.Factory.addComponentsGetterSetter(t.Shape,"fillPatternOffset",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillPatternOffsetX",0),t.Factory.addGetterSetter(t.Shape,"fillPatternOffsetY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillPatternScale",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillPatternScaleX",1),t.Factory.addGetterSetter(t.Shape,"fillPatternScaleY",1),t.Factory.addComponentsGetterSetter(t.Shape,"fillLinearGradientStartPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientStartPointX",0),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientStartPointY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillLinearGradientEndPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientEndPointX",0),t.Factory.addGetterSetter(t.Shape,"fillLinearGradientEndPointY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillRadialGradientStartPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientStartPointX",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientStartPointY",0),t.Factory.addComponentsGetterSetter(t.Shape,"fillRadialGradientEndPoint",["x","y"]),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientEndPointX",0),t.Factory.addGetterSetter(t.Shape,"fillRadialGradientEndPointY",0),t.Factory.addGetterSetter(t.Shape,"fillPatternRotation",0),t.Factory.backCompat(t.Shape,{dashArray:"dash",getDashArray:"getDash",setDashArray:"getDash",drawFunc:"sceneFunc",getDrawFunc:"getSceneFunc",setDrawFunc:"setSceneFunc",drawHitFunc:"hitFunc",getDrawHitFunc:"getHitFunc",setDrawHitFunc:"setHitFunc"}),t.Collection.mapMethods(t.Shape)}(Konva),function(){"use strict";function t(t,e){t.content.addEventListener(e,function(n){t[a+e](n)},!1)}var e="mouseout",n="mouseleave",i="touchstart",a="_",r=["mousedown","mousemove","mouseup",e,i,"touchmove","touchend","mouseover","wheel","contextmenu"],o=r.length;Konva.Stage=function(t){this.___init(t)},Konva.Util.addMethods(Konva.Stage,{___init:function(t){this.nodeType="Stage",Konva.Container.call(this,t),this._id=Konva.idCounter++,this._buildDOM(),this._bindContentEvents(),this._enableNestedTransforms=!1,Konva.stages.push(this)},_validateAdd:function(t){"Layer"!==t.getType()&&Konva.Util.throw("You may only add layers to the stage.")},setContainer:function(t){if("string"==typeof t){if("."===t.charAt(0)){var e=t.slice(1);t=Konva.document.getElementsByClassName(e)[0]}else{var n;n="#"!==t.charAt(0)?t:t.slice(1),t=Konva.document.getElementById(n)}if(!t)throw"Can not find container in document with id "+n}return this._setAttr("container",t),this},shouldDrawHit:function(){return!0},draw:function(){return Konva.Node.prototype.draw.call(this),this},setHeight:function(t){return Konva.Node.prototype.setHeight.call(this,t),this._resizeDOM(),this},setWidth:function(t){return Konva.Node.prototype.setWidth.call(this,t),this._resizeDOM(),this},clear:function(){var t,e=this.children,n=e.length;for(t=0;t-1&&Konva.stages.splice(e,1),this},getPointerPosition:function(){return this.pointerPos},getStage:function(){return this},getContent:function(){return this.content},toDataURL:function(t){var e=(t=t||{}).mimeType||null,n=t.quality||null,i=t.x||0,a=t.y||0,r=new Konva.SceneCanvas({width:t.width||this.getWidth(),height:t.height||this.getHeight(),pixelRatio:t.pixelRatio}),o=r.getContext()._context,s=this.children;(i||a)&&o.translate(-1*i,-1*a),s.each(function(t){var e=t.getCanvas().getWidth(),n=t.getCanvas().getHeight(),i=t.getCanvas().getPixelRatio();o.drawImage(t.getCanvas()._canvas,0,0,e/i,n/i)});var h=r.toDataURL(e,n);return t.callback&&t.callback(h),h},toImage:function(t){var e=t.callback;t.callback=function(t){Konva.Util._getImage(t,function(t){e(t)})},this.toDataURL(t)},getIntersection:function(t,e){var n,i,a=this.getChildren();for(n=a.length-1;n>=0;n--)if(i=a[n].getIntersection(t,e))return i;return null},_resizeDOM:function(){if(this.content){var t,e,n=this.getWidth(),i=this.getHeight(),a=this.getChildren(),r=a.length;for(this.content.style.width=n+"px",this.content.style.height=i+"px",this.bufferCanvas.setSize(n,i),this.bufferHitCanvas.setSize(n,i),t=0;t1){for(var e=0;e0){var a=t.touches[0];n=a.clientX-e.left,i=a.clientY-e.top}}else n=t.clientX-e.left,i=t.clientY-e.top;null!==n&&null!==i&&(this.pointerPos={x:n,y:i})},_getContentPosition:function(){var t=this.content.getBoundingClientRect?this.content.getBoundingClientRect():{top:0,left:0};return{top:t.top,left:t.left}},_buildDOM:function(){if(this.bufferCanvas=new Konva.SceneCanvas,this.bufferHitCanvas=new Konva.HitCanvas({pixelRatio:1}),Konva.isBrowser){var t=this.getContainer();if(!t)throw"Stage has no container. A container is required.";t.innerHTML="",this.content=Konva.document.createElement("div"),this.content.style.position="relative",this.content.className="konvajs-content",this.content.setAttribute("role","presentation"),t.appendChild(this.content),this._resizeDOM()}},_onContent:function(t,e){var n,i,a=t.split(" "),r=a.length;for(n=0;n0?{antialiased:!0}:{}},drawScene:function(t,e){var n=this.getLayer(),i=t||n&&n.getCanvas();return this._fire("beforeDraw",{node:this}),this.getClearBeforeDraw()&&i.getContext().clear(),Konva.Container.prototype.drawScene.call(this,i,e),this._fire("draw",{node:this}),this},drawHit:function(t,e){var n=this.getLayer(),i=t||n&&n.hitCanvas;return n&&n.getClearBeforeDraw()&&n.getHitCanvas().getContext().clear(),Konva.Container.prototype.drawHit.call(this,i,e),this.imageData=null,this},clear:function(t){return Konva.BaseLayer.prototype.clear.call(this,t),this.getHitCanvas().getContext().clear(t),this.imageData=null,this},setVisible:function(t){return Konva.Node.prototype.setVisible.call(this,t),t?(this.getCanvas()._canvas.style.display="block",this.hitCanvas._canvas.style.display="block"):(this.getCanvas()._canvas.style.display="none",this.hitCanvas._canvas.style.display="none"),this},enableHitGraph:function(){return this.setHitGraphEnabled(!0),this},disableHitGraph:function(){return this.setHitGraphEnabled(!1),this},setSize:function(t,e){return Konva.BaseLayer.prototype.setSize.call(this,t,e),this.hitCanvas.setSize(t,e),this}}),Konva.Util.extend(Konva.Layer,Konva.BaseLayer),Konva.Factory.addGetterSetter(Konva.Layer,"hitGraphEnabled",!0),Konva.Collection.mapMethods(Konva.Layer)}(),function(){"use strict";Konva.FastLayer=function(t){this.____init(t)},Konva.Util.addMethods(Konva.FastLayer,{____init:function(t){this.nodeType="Layer",this.canvas=new Konva.SceneCanvas,Konva.BaseLayer.call(this,t)},_validateAdd:function(t){"Shape"!==t.getType()&&Konva.Util.throw("You may only add shapes to a fast layer.")},_setCanvasSize:function(t,e){this.canvas.setSize(t,e)},hitGraphEnabled:function(){return!1},getIntersection:function(){return null},drawScene:function(t){var e=this.getLayer(),n=t||e&&e.getCanvas();return this.getClearBeforeDraw()&&n.getContext().clear(),Konva.Container.prototype.drawScene.call(this,n),this},draw:function(){return this.drawScene(),this},setVisible:function(t){return Konva.Node.prototype.setVisible.call(this,t),this.getCanvas()._canvas.style.display=t?"block":"none",this}}),Konva.Util.extend(Konva.FastLayer,Konva.BaseLayer),Konva.Collection.mapMethods(Konva.FastLayer)}(),function(){"use strict";Konva.Group=function(t){this.___init(t)},Konva.Util.addMethods(Konva.Group,{___init:function(t){this.nodeType="Group",Konva.Container.call(this,t)},_validateAdd:function(t){var e=t.getType();"Group"!==e&&"Shape"!==e&&Konva.Util.throw("You may only add groups and shapes to groups.")}}),Konva.Util.extend(Konva.Group,Konva.Container),Konva.Collection.mapMethods(Konva.Group)}(),function(t){"use strict";function e(){return i.apply(t.global,arguments)}var n=t.global.performance&&t.global.performance.now?function(){return t.global.performance.now()}:function(){return(new Date).getTime()},i=t.global.requestAnimationFrame||t.global.webkitRequestAnimationFrame||t.global.mozRequestAnimationFrame||t.global.oRequestAnimationFrame||t.global.msRequestAnimationFrame||function(t){setTimeout(t,1e3/60)};t.Animation=function(e,i){var a=t.Animation;this.func=e,this.setLayers(i),this.id=a.animIdCounter++,this.frame={time:0,timeDiff:0,lastTime:n()}},t.Animation.prototype={setLayers:function(t){var e=[];return e=t?t.length>0?t:[t]:[],this.layers=e,this},getLayers:function(){return this.layers},addLayer:function(t){var e,n=this.layers,i=n.length;for(e=0;ethis.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())},getTime:function(){return this._time},setPosition:function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},getPosition:function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},play:function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},reverse:function(){this.state=3,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;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},pause:function(){this.state=1,this.fire("onPause")},getTimer:function(){return(new Date).getTime()}},Konva.Tween=function(n){var a,r,o=this,s=n.node,h=s._id,l=n.easing||Konva.Easings.Linear,c=!!n.yoyo;a=void 0===n.duration?1:0===n.duration?.001:n.duration,this.node=s,this._id=e++;var d=s.getLayer()||(s instanceof Konva.Stage?s.getLayers():null);d||Konva.Util.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new Konva.Animation(function(){o.tween.onEnterFrame()},d),this.tween=new i(r,function(t){o._tweenFunc(t)},l,0,1,1e3*a,c),this._addListeners(),Konva.Tween.attrs[h]||(Konva.Tween.attrs[h]={}),Konva.Tween.attrs[h][this._id]||(Konva.Tween.attrs[h][this._id]={}),Konva.Tween.tweens[h]||(Konva.Tween.tweens[h]={});for(r in n)void 0===t[r]&&this._addAttr(r,n[r]);this.reset(),this.onFinish=n.onFinish,this.onReset=n.onReset},Konva.Tween.attrs={},Konva.Tween.tweens={},Konva.Tween.prototype={_addAttr:function(t,e){var i,a,r,o,s,h,l,c=this.node,d=c._id;if((r=Konva.Tween.tweens[d][t])&&delete Konva.Tween.attrs[d][r][t],i=c.getAttr(t),Konva.Util._isArray(e))for(a=[],s=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(l=i,i=Konva.Util._prepareArrayForTween(i,e,c.closed())):(h=e,e=Konva.Util._prepareArrayForTween(e,i,c.closed()))),o=0;oc)for(;_.length>0;){for(var S=0,K=_.length,x="",C=0;S>>1,w=_.slice(0,b+1),F=this._getTextWidth(w);F<=c?(S=b+1,x=w,C=F):K=b}if(!x)break;if(v){var T=Math.max(x.lastIndexOf(" "),x.lastIndexOf("-"))+1;T>0&&(S=T,x=x.slice(0,S),C=this._getTextWidth(x))}if(this._addTextLine(x),i=Math.max(i,C),u+=a,!g||h&&u+a>d)break;if((_=_.slice(S)).length>0&&(y=this._getTextWidth(_))<=c){this._addTextLine(_),u+=a,i=Math.max(i,y);break}}else this._addTextLine(_),u+=a,i=Math.max(i,y);if(h&&u+a>d)break}t().restore(),this.textHeight=n,this.textWidth=i}},Konva.Util.extend(Konva.Text,Konva.Shape),Konva.Factory.addGetterSetter(Konva.Text,"fontFamily","Arial"),Konva.Factory.addGetterSetter(Konva.Text,"fontSize",12),Konva.Factory.addGetterSetter(Konva.Text,"fontStyle","normal"),Konva.Factory.addGetterSetter(Konva.Text,"fontVariant","normal"),Konva.Factory.addGetterSetter(Konva.Text,"padding",0),Konva.Factory.addGetterSetter(Konva.Text,"align","left"),Konva.Factory.addGetterSetter(Konva.Text,"lineHeight",1),Konva.Factory.addGetterSetter(Konva.Text,"wrap","word"),Konva.Factory.addGetterSetter(Konva.Text,"letterSpacing",0),Konva.Factory.addGetter(Konva.Text,"text",""),Konva.Factory.addOverloadedGetterSetter(Konva.Text,"text"),Konva.Factory.addGetterSetter(Konva.Text,"textDecoration",""),Konva.Collection.mapMethods(Konva.Text)}(),function(){"use strict";Konva.Line=function(t){this.___init(t)},Konva.Line.prototype={___init:function(t){Konva.Shape.call(this,t),this.className="Line",this.on("pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva",function(){this._clearCache("tensionPoints")}),this.sceneFunc(this._sceneFunc)},_sceneFunc:function(t){var e,n,i,a=this.getPoints(),r=a.length,o=this.getTension(),s=this.getClosed(),h=this.getBezier();if(r){if(t.beginPath(),t.moveTo(a[0],a[1]),0!==o&&r>4){for(n=(e=this.getTensionPoints()).length,i=s?0:4,s||t.quadraticCurveTo(e[0],e[1],e[2],e[3]);ih?s:h,g=s>h?1:s/h,v=s>h?h/s:1;t.translate(r,o),t.rotate(d),t.scale(g,v),t.arc(0,0,f,l,l+c,1-u),t.scale(1/g,1/v),t.rotate(-d),t.translate(-r,-o);break;case"z":t.closePath()}}t.fillStrokeShape(this)},getSelfRect:function(){var t=[];this.dataArray.forEach(function(e){t=t.concat(e.points)});for(var e,n,i=t[0],a=t[0],r=t[1],o=t[1],s=0;s0&&""===c[0]&&c.shift();for(var d=0;d0&&!isNaN(c[0]);){var u,f,g,v,p,m,_,y,S,K,x=null,C=[],b=o,w=s;switch(l){case"l":o+=c.shift(),s+=c.shift(),x="L",C.push(o,s);break;case"L":o=c.shift(),s=c.shift(),C.push(o,s);break;case"m":var F=c.shift(),T=c.shift();if(o+=F,s+=T,x="M",r.length>2&&"z"===r[r.length-1].command)for(var P=r.length-2;P>=0;P--)if("M"===r[P].command){o=r[P].points[0]+F,s=r[P].points[1]+T;break}C.push(o,s),l="l";break;case"M":o=c.shift(),s=c.shift(),x="M",C.push(o,s),l="L";break;case"h":o+=c.shift(),x="L",C.push(o,s);break;case"H":o=c.shift(),x="L",C.push(o,s);break;case"v":s+=c.shift(),x="L",C.push(o,s);break;case"V":s=c.shift(),x="L",C.push(o,s);break;case"C":C.push(c.shift(),c.shift(),c.shift(),c.shift()),o=c.shift(),s=c.shift(),C.push(o,s);break;case"c":C.push(o+c.shift(),s+c.shift(),o+c.shift(),s+c.shift()),o+=c.shift(),s+=c.shift(),x="C",C.push(o,s);break;case"S":f=o,g=s,"C"===(u=r[r.length-1]).command&&(f=o+(o-u.points[2]),g=s+(s-u.points[3])),C.push(f,g,c.shift(),c.shift()),o=c.shift(),s=c.shift(),x="C",C.push(o,s);break;case"s":f=o,g=s,"C"===(u=r[r.length-1]).command&&(f=o+(o-u.points[2]),g=s+(s-u.points[3])),C.push(f,g,o+c.shift(),s+c.shift()),o+=c.shift(),s+=c.shift(),x="C",C.push(o,s);break;case"Q":C.push(c.shift(),c.shift()),o=c.shift(),s=c.shift(),C.push(o,s);break;case"q":C.push(o+c.shift(),s+c.shift()),o+=c.shift(),s+=c.shift(),x="Q",C.push(o,s);break;case"T":f=o,g=s,"Q"===(u=r[r.length-1]).command&&(f=o+(o-u.points[0]),g=s+(s-u.points[1])),o=c.shift(),s=c.shift(),x="Q",C.push(f,g,o,s);break;case"t":f=o,g=s,"Q"===(u=r[r.length-1]).command&&(f=o+(o-u.points[0]),g=s+(s-u.points[1])),o+=c.shift(),s+=c.shift(),x="Q",C.push(f,g,o,s);break;case"A":v=c.shift(),p=c.shift(),m=c.shift(),_=c.shift(),y=c.shift(),S=o,K=s,o=c.shift(),s=c.shift(),x="A",C=this.convertEndpointToCenterParameterization(S,K,o,s,_,y,v,p,m);break;case"a":v=c.shift(),p=c.shift(),m=c.shift(),_=c.shift(),y=c.shift(),S=o,K=s,o+=c.shift(),s+=c.shift(),x="A",C=this.convertEndpointToCenterParameterization(S,K,o,s,_,y,v,p,m)}r.push({command:x||l,points:C,start:{x:b,y:w},pathLength:this.calcLength(b,w,x||l,C)})}"z"!==l&&"Z"!==l||r.push({command:"z",points:[],start:void 0,pathLength:0})}return r},Konva.Path.calcLength=function(t,e,n,i){var a,r,o,s,h=Konva.Path;switch(n){case"L":return h.getLineLength(t,e,i[0],i[1]);case"C":for(a=0,r=h.getPointOnCubicBezier(0,t,e,i[0],i[1],i[2],i[3],i[4],i[5]),s=.01;s<=1;s+=.01)o=h.getPointOnCubicBezier(s,t,e,i[0],i[1],i[2],i[3],i[4],i[5]),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;return a;case"Q":for(a=0,r=h.getPointOnQuadraticBezier(0,t,e,i[0],i[1],i[2],i[3]),s=.01;s<=1;s+=.01)o=h.getPointOnQuadraticBezier(s,t,e,i[0],i[1],i[2],i[3]),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;return a;case"A":a=0;var l=i[4],c=i[5],d=i[4]+c,u=Math.PI/180;if(Math.abs(l-d)d;s-=u)o=h.getPointOnEllipticalArc(i[0],i[1],i[2],i[3],s,0),a+=h.getLineLength(r.x,r.y,o.x,o.y),r=o;else for(s=l+u;s1&&(o*=Math.sqrt(u),s*=Math.sqrt(u));var f=Math.sqrt((o*o*(s*s)-o*o*(d*d)-s*s*(c*c))/(o*o*(d*d)+s*s*(c*c)));a===r&&(f*=-1),isNaN(f)&&(f=0);var g=f*o*d/s,v=f*-s*c/o,p=(t+n)/2+Math.cos(l)*g-Math.sin(l)*v,m=(e+i)/2+Math.sin(l)*g+Math.cos(l)*v,_=function(t){return Math.sqrt(t[0]*t[0]+t[1]*t[1])},y=function(t,e){return(t[0]*e[0]+t[1]*e[1])/(_(t)*_(e))},S=function(t,e){return(t[0]*e[1]=1&&(b=0),0===r&&b>0&&(b-=2*Math.PI),1===r&&b<0&&(b+=2*Math.PI),[p,m,o,s,K,b,l,r]},Konva.Factory.addGetterSetter(Konva.Path,"data"),Konva.Collection.mapMethods(Konva.Path)}(),function(){"use strict";function t(t){t.fillText(this.partialText,0,0)}function e(t){t.strokeText(this.partialText,0,0)}Konva.TextPath=function(t){this.___init(t)},Konva.TextPath.prototype={___init:function(n){var i=this;this.dummyCanvas=Konva.Util.createCanvasElement(),this.dataArray=[],Konva.Shape.call(this,n),this._fillFunc=t,this._strokeFunc=e,this._fillFuncHit=t,this._strokeFuncHit=e,this.className="TextPath",this.dataArray=Konva.Path.parsePathData(this.attrs.data),this.on("dataChange.konva",function(){i.dataArray=Konva.Path.parsePathData(this.attrs.data),i._setTextData()}),this.on("textChange.konva alignChange.konva letterSpacingChange.konva",i._setTextData),i._setTextData(),this.sceneFunc(this._sceneFunc),this.hitFunc(this._hitFunc)},_sceneFunc:function(t){t.setAttr("font",this._getContextFont()),t.setAttr("textBaseline",this.getTextBaseline()),t.setAttr("textAlign","left"),t.save();var e=this.textDecoration(),n=this.fill(),i=this.fontSize(),a=this.glyphInfo;"underline"===e&&t.beginPath();for(var r=0;r=1){var n=e[0].p0;t.moveTo(n.x,n.y)}for(var i=0;i0&&(r+=t.dataArray[o].pathLength);var s=0;"center"===i&&(s=Math.max(0,r/2-a/2)),"right"===i&&(s=Math.max(0,r-a));for(var h,l,c,d=this.getText().split(""),u=this.getText().split(" ").length-1,f=-1,g=0,v=function(){g=0;for(var e=t.dataArray,n=f+1;n0)return f=n,e[n];"M"===e[n].command&&(h={x:e[n].points[0],y:e[n].points[1]})}return{}},p=function(e){var o=t._getTextSize(e).width+n;" "===e&&"justify"===i&&(o+=(r-a)/u);var s=0,d=0;for(l=void 0;Math.abs(o-s)/o>.01&&d<25;){d++;for(var f=s;void 0===c;)(c=v())&&f+c.pathLengtho?l=Konva.Path.getPointOnLine(o,h.x,h.y,c.points[0],c.points[1],h.x,h.y):c=void 0;break;case"A":var m=c.points[4],_=c.points[5],y=c.points[4]+_;0===g?g=m+1e-8:o>s?g+=Math.PI/180*_/Math.abs(_):g-=Math.PI/360*_/Math.abs(_),(_<0&&g=0&&g>y)&&(g=y,p=!0),l=Konva.Path.getPointOnEllipticalArc(c.points[0],c.points[1],c.points[2],c.points[3],g,c.points[6]);break;case"C":0===g?g=o>c.pathLength?1e-8:o/c.pathLength:o>s?g+=(o-s)/c.pathLength:g-=(s-o)/c.pathLength,g>1&&(g=1,p=!0),l=Konva.Path.getPointOnCubicBezier(g,c.start.x,c.start.y,c.points[0],c.points[1],c.points[2],c.points[3],c.points[4],c.points[5]);break;case"Q":0===g?g=o/c.pathLength:o>s?g+=(o-s)/c.pathLength:g-=(s-o)/c.pathLength,g>1&&(g=1,p=!0),l=Konva.Path.getPointOnQuadraticBezier(g,c.start.x,c.start.y,c.points[0],c.points[1],c.points[2],c.points[3])}void 0!==l&&(s=Konva.Path.getLineLength(h.x,h.y,l.x,l.y)),p&&(p=!1,c=void 0)}},m=t._getTextSize("C").width+n,_=0;_=0}),this.findOne(".top-center").setAttrs({x:n/2,y:0,visible:r&&a.indexOf("top-center")>=0}),this.findOne(".top-right").setAttrs({x:n,y:0,visible:r&&a.indexOf("top-right")>=0}),this.findOne(".middle-left").setAttrs({x:0,y:i/2,visible:r&&a.indexOf("middle-left")>=0}),this.findOne(".middle-right").setAttrs({x:n,y:i/2,visible:r&&a.indexOf("middle-right")>=0}),this.findOne(".bottom-left").setAttrs({x:0,y:i,visible:r&&a.indexOf("bottom-left")>=0}),this.findOne(".bottom-center").setAttrs({x:n/2,y:i,visible:r&&a.indexOf("bottom-center")>=0}),this.findOne(".bottom-right").setAttrs({x:n,y:i,visible:r&&a.indexOf("bottom-right")>=0}),this.findOne(".rotater").setAttrs({x:n/2,y:-this.rotateHandlerOffset(),visible:this.rotateEnabled()}),this.findOne(".back").setAttrs({width:n,height:i,visible:this.lineEnabled()})},destroy:function(){t.Group.prototype.destroy.call(this),this._el.off(".resizer"),this._removeEvents()}},t.Util.extend(t.Transformer,t.Group),t.Factory.addGetterSetter(t.Transformer,"enabledResizers",i),t.Factory.addGetterSetter(t.Transformer,"enabledResizers",i,function(e){return e instanceof Array||t.Util.warn("enabledResizers value should be an array"),e instanceof Array&&e.forEach(function(e){-1===i.indexOf("name")&&t.Util.warn("Unknown resizer name: "+e+". Available names are: "+i.join(", "))}),e||[]}),t.Factory.addGetterSetter(t.Transformer,"resizeEnabled",!0),t.Factory.addGetterSetter(t.Transformer,"rotateEnabled",!0),t.Factory.addGetterSetter(t.Transformer,"rotationSnaps",[]),t.Factory.addGetterSetter(t.Transformer,"rotateHandlerOffset",50),t.Factory.addGetterSetter(t.Transformer,"lineEnabled",!0),t.Collection.mapMethods(t.Transformer)}(Konva); \ No newline at end of file diff --git a/src/shapes/Transformer.js b/src/shapes/Transformer.js index 3d2a3db5..2c6aac95 100644 --- a/src/shapes/Transformer.js +++ b/src/shapes/Transformer.js @@ -151,6 +151,8 @@ window.addEventListener('touchmove', this.handleMouseMove); window.addEventListener('mouseup', this.handleMouseUp); window.addEventListener('touchend', this.handleMouseUp); + + this._transforming = true; }, handleMouseMove: function(e) { @@ -311,12 +313,19 @@ }, handleMouseUp: function() { - this.fire('transformend'); - this._el.fire('transformend'); - window.removeEventListener('mousemove', this.handleMouseMove); - window.removeEventListener('touchmove', this.handleMouseMove); - window.removeEventListener('mouseup', this.handleMouseUp); - window.removeEventListener('touchend', this.handleMouseUp); + this._removeEvents(); + }, + + _removeEvents: function() { + if (this._transforming) { + this.fire('transformend'); + this._el.fire('transformend'); + window.removeEventListener('mousemove', this.handleMouseMove); + window.removeEventListener('touchmove', this.handleMouseMove); + window.removeEventListener('mouseup', this.handleMouseUp); + window.removeEventListener('touchend', this.handleMouseUp); + } + this._transforming = false; }, _getAttrs: function() { @@ -440,10 +449,7 @@ destroy: function() { Konva.Group.prototype.destroy.call(this); this._el.off('.resizer'); - window.removeEventListener('mousemove', this.handleMouseMove); - window.removeEventListener('touchmove', this.handleMouseMove); - window.removeEventListener('mouseup', this.handleMouseUp); - window.removeEventListener('touchend', this.handleMouseUp); + this._removeEvents(); } }; Konva.Util.extend(Konva.Transformer, Konva.Group);