diff --git a/CHANGELOG.md b/CHANGELOG.md index e9a8deb6..9f0c013b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Fixed "calling remove() for dragging shape will throw an error" - Fixed wrong opacity level for cached group with opacity - More consistent shadows on HDPI screens +- Fixed memory leak for nodes with several names ## [1.2.2][2016-09-15] diff --git a/konva.js b/konva.js index 0ed4d53b..5ed4ee3d 100644 --- a/konva.js +++ b/konva.js @@ -3,7 +3,7 @@ * Konva JavaScript Framework v1.2.2 * http://konvajs.github.io/ * Licensed under the MIT or GPL Version 2 licenses. - * Date: Wed Dec 14 2016 + * Date: Tue Jan 10 2017 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva) @@ -2899,7 +2899,13 @@ destroy: function() { // remove from ids and names hashes Konva._removeId(this.getId()); - Konva._removeName(this.getName(), this._id); + + // remove all names + var names = (this.getName() || '').split(/\s/g); + for(var i = 0; i < names.length; i++) { + var subname = names[i]; + Konva._removeName(subname, this._id); + } this.remove(); return this; diff --git a/konva.min.js b/konva.min.js index 8c2f0d92..8d500372 100644 --- a/konva.min.js +++ b/konva.min.js @@ -2,7 +2,7 @@ * Konva JavaScript Framework v1.2.2 * http://konvajs.github.io/ * Licensed under the MIT or GPL Version 2 licenses. - * Date: Wed Dec 14 2016 + * Date: Tue Jan 10 2017 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva) @@ -27,7 +27,7 @@ * THE SOFTWARE. */ !function(t){"use strict";var e=Math.PI/180,n={version:"1.2.2",stages:[],idCounter:0,ids:{},names:{},shapes:{},listenClickTap:!1,inDblClickWindow:!1,enableTrace:!1,traceArrMax:100,dblClickWindow:400,pixelRatio:void 0,dragDistance:0,angleDeg:!0,showWarnings:!0,Filters:{},isDragging:function(){var t=n.DD;return!!t&&t.isDragging},isDragReady:function(){var t=n.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);var n=t.indexOf("trident/");if(n>0){var i=t.indexOf("rv:");return parseInt(t.substring(i+3,t.indexOf(".",i)),10)}var a=t.indexOf("edge/");return a>0&&parseInt(t.substring(a+5,t.indexOf(".",a)),10)},_parseUA:function(t){var e=t.toLowerCase(),i=/(chrome)[ \/]([\w.]+)/.exec(e)||/(webkit)[ \/]([\w.]+)/.exec(e)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(e)||/(msie) ([\w.]+)/.exec(e)||e.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(e)||[],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:n._detectIE(e),mobile:a,ieMobile:r}},UA:void 0},i="undefined"!=typeof t?t:"undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope?self:{};if(n.UA=n._parseUA(i.navigator&&i.navigator.userAgent||""),i.Konva&&console.error("Konva instance is already exist in current eviroment. Please use only one instance."),i.Konva=n,n.global=i,"object"==typeof exports){if(i.window&&i.window.document)n.document=i.window.document,n.window=i.window;else{var a=require("canvas"),r=require("jsdom").jsdom;n.window=r("").defaultView,n.document=n.window.document,n.window.Image=a.Image,n._nodeCanvas=a}return void(module.exports=n)}"function"==typeof define&&define.amd&&define(function(){return n}),n.document=document,n.window=window}("undefined"!=typeof global?global:window),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.document.createElement("canvas");try{t.style=t.style||{}}catch(t){}return t},isBrowser:function(){return"object"!=typeof exports},_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=h+t;return o+t},get:function(t,e){return void 0===t?e:t},getRGB:function(t){var e;return t in u?(e=u[t],{r:e[0],g:e[1],b:e[2]}):t[0]===o?this._hexToRgb(t.substring(1)):t.substr(0,4)===d?(e=v.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=u[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA:function(t){if(0===t.indexOf("rgb(")){t=t.match(/rgb\(([^)]+)\)/)[1];var e=t.split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA:function(t){if(0===t.indexOf("rgba(")){t=t.match(/rgba\(([^)]+)\)/)[1];var e=t.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(t){return t*a},_radToDeg:function(t){return t*r},_capitalize:function(t){return t.charAt(0).toUpperCase()+t.slice(1)},throw:function(t){throw new Error(l+t)},error:function(t){console.error(l+t)},warn:function(t){Konva.global.console&&console.warn&&Konva.showWarnings&&console.warn(c+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)),c=o*s/(s+h),l=o*h/(s+h),d=n-c*(a-t),u=i-c*(r-e),v=n+l*(a-t),f=i+l*(r-e);return[d,u,v,f]},_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)):(o=t+l*(n-t),s=e+l*(i-e),h=(o-a)*(o-a)+(s-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),c=h[0],l=h[1],d=h[2];de.length){var o=e;e=t,t=o}for(i=0;i=Konva.traceArrMax&&n.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 t,e,n=this,i=h.length,a=Konva.Util._simplifyArray,r=this.setAttr,o=function(t){var i,r=n[t];n[t]=function(){return e=a(Array.prototype.slice.call(arguments,0)),i=r.apply(n,arguments),n._trace({method:t,args:e}),i}};for(t=0;t255?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="Change",r="children",o=".",s="",h="get",c="id",l="konva",d="listening",u="mouseenter",v="mouseleave",f="name",g="set",p="Shape",m=" ",_="stage",y="transform",K="Stage",S="visible",x=["id"],C=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(m),w=["scaleXChange.konva","scaleYChange.konva"].join(m);t.Node=function(t){this._init(t)},t.Util.addMethods(t.Node,{_init:function(a){var r=this;this._id=t.idCounter++,this.eventListeners={},this.attrs={},this._cache={},this._filterUpToDate=!1,this._isUnderCache=!1,this.setAttrs(a),this.on(C,function(){this._clearCache(y),r._clearSelfAndDescendantCache(n)}),this.on(w,function(){r._clearSelfAndDescendantCache(i)}),this.on("visibleChange.konva",function(){r._clearSelfAndDescendantCache(S)}),this.on("listeningChange.konva",function(){r._clearSelfAndDescendantCache(d)}),this.on("opacityChange.konva",function(){r._clearSelfAndDescendantCache(e)})},_clearCache:function(t){t?delete this._cache[t]:this._cache={}},_getCache:function(t,e){var n=this._cache[t];return void 0===n&&(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(!0),o=a.width||r.width,s=a.height||r.height,h=a.pixelRatio,c=a.x||r.x,l=a.y||r.y,d=a.offset||0,u=a.drawBorder||!1;if(!o||!s)throw new Error("Width or height of caching configuration equals 0.");o+=2*d,s+=2*d,c-=d,l-=d;var v=new t.SceneCanvas({pixelRatio:h,width:o,height:s}),f=new t.SceneCanvas({pixelRatio:h,width:o,height:s}),g=new t.HitCanvas({pixelRatio:1,width:o,height:s}),p=v.getContext(),m=g.getContext();return g.isCache=!0,this.clearCache(),p.save(),m.save(),p.translate(-c,-l),m.translate(-c,-l),this._isUnderCache=!0,this._clearSelfAndDescendantCache(e),this._clearSelfAndDescendantCache(i),this.drawScene(v,this,!0),this.drawHit(g,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:v,filter:f,hit:g,x:c,y:l},this},getClientRect:function(){throw new Error('abstract "getClientRect" method call')},_transformedRect:function(t){var e,n,i,a,r=[{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}],o=this.getTransform();return r.forEach(function(t){var r=o.point(t);void 0===e&&(e=i=r.x,n=a=r.y),e=Math.min(e,r.x),n=Math.min(n,r.y),i=Math.max(i,r.x),a=Math.max(a,r.y)}),{x:e,y:n,width:i-e,height:a-n}},_drawCachedSceneCanvas:function(t){t.save(),t._applyOpacity(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,n=e.hit;t.save(),t.translate(this._cache.canvas.x,this._cache.canvas.y),t.drawImage(n._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,c=h.getContext();if(r){if(!this._filterUpToDate){var l=s.pixelRatio;try{for(e=r.length,c.clear(),c.drawImage(s._canvas,0,0,s.getWidth()/l,s.getHeight()/l),n=c.getImageData(0,0,h.getWidth(),h.getHeight()),i=0;i0&&e[0].getDepth()<=r&&t(e)}var e,n,i,a,r=this.getDepth(),o=this,s=0;return o.nodeType!==K&&t(o.getStage().getChildren()),s},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(),e.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(y),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(y),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;n>W,0!==T?(T=255/T,A[l]=(u*H>>W)*T,A[l+1]=(v*H>>W)*T,A[l+2]=(f*H>>W)*T):A[l]=A[l+1]=A[l+2]=0,u-=p,v-=m,f-=_,g-=y,p-=E.r,m-=E.g,_-=E.b,y-=E.a,h=d+((h=r+a+1)>W,T>0?(T=255/T,A[h]=(u*H>>W)*T,A[h+1]=(v*H>>W)*T,A[h+2]=(f*H>>W)*T):A[h]=A[h+1]=A[h+2]=0,u-=p,v-=m,f-=_,g-=y,p-=E.r,m-=E.g,_-=E.b,y-=E.a,h=r+((h=o+L)0&&e(t,n)},Konva.Factory.addGetterSetter(Konva.Node,"blurRadius",0,null,Konva.Factory.afterSetFilter)}(),function(){"use strict";function t(t,e,n){var i=4*(n*t.width+e),a=[];return a.push(t.data[i++],t.data[i++],t.data[i++],t.data[i++]),a}function e(t,e){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2)+Math.pow(t[2]-e[2],2))}function n(t){for(var e=[0,0,0],n=0;n=0&&v=0&&f=0&&v=0&&f=1020?255:0}return o}function s(t,e,n){for(var i=[1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9],a=Math.round(Math.sqrt(i.length)),r=Math.floor(a/2),o=[],s=0;s=0&&v=0&&f255?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()),c=Math.pow(2,this.saturation()),l=Math.abs(this.hue()+360)%360,d=h*c*Math.cos(l*Math.PI/180),u=h*c*Math.sin(l*Math.PI/180),v=.299*h+.701*d+.167*u,f=.587*h-.587*d+.33*u,g=.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,K=.587*h-.586*d-1.05*u,S=.114*h+.886*d-.2*u;for(e=0;ec&&(v=0);var f=(d-1+v)*h*4,g=h;do{var p=u+4*(g-1),m=o;g+m<1&&(m=0),g+m>h&&(m=0);var _=f+4*(g-1+m),y=s[p]-s[_],K=s[p+1]-s[_+1],S=s[p+2]-s[_+2],x=y,C=x>0?x:-x,w=K>0?K:-K,b=S>0?S:-S;if(w>C&&(x=K),b>C&&(x=S),x*=e,a){var F=s[p]+x,T=s[p+1]+x,P=s[p+2]+x;s[p]=F>255?255:F<0?0:F,s[p+1]=T>255?255:T<0?0:T,s[p+2]=P>255?255:P<0?0:P}else{var A=n-x;A<0?A=0:A>255&&(A=255),s[p]=s[p+1]=s[p+2]=A}}while(--g)}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],c=h,l=o[1],d=l,u=o[2],v=u,f=this.enhance();if(0!==f){for(r=0;rc&&(c=n),i=o[r+1],id&&(d=i),a=o[r+2],av&&(v=a);c===h&&(c=255,h=0),d===l&&(d=255,l=0),v===u&&(v=255,u=0);var g,p,m,_,y,K,S,x,C;for(f>0?(p=c+f*(255-c),m=h-f*(h-0),y=d+f*(255-d),K=l-f*(l-0),x=v+f*(255-v),C=u-f*(u-0)):(g=.5*(c+h),p=c+f*(c-g),m=h+f*(h-g),_=.5*(d+l),y=d+f*(d-_),K=l+f*(l-_),S=.5*(v+u),x=v+f*(v-S),C=u+f*(u-S)),r=0;r=p))for(n=l;n=m||(i=4*(p*n+e),a+=t[i+0],r+=t[i+1],o+=t[i+2],s+=t[i+3],f+=1);for(a/=f,r/=f,o/=f,e=h;e=p))for(n=l;n=m||(i=4*(p*n+e),t[i+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&&e[0].getDepth()<=r&&t(e)}var e,n,i,a,r=this.getDepth(),o=this,s=0;return o.nodeType!==K&&t(o.getStage().getChildren()),s},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(),e.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(y),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(y),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;n>W,0!==T?(T=255/T,A[l]=(u*H>>W)*T,A[l+1]=(v*H>>W)*T,A[l+2]=(f*H>>W)*T):A[l]=A[l+1]=A[l+2]=0,u-=p,v-=m,f-=_,g-=y,p-=E.r,m-=E.g,_-=E.b,y-=E.a,h=d+((h=r+a+1)>W,T>0?(T=255/T,A[h]=(u*H>>W)*T,A[h+1]=(v*H>>W)*T,A[h+2]=(f*H>>W)*T):A[h]=A[h+1]=A[h+2]=0,u-=p,v-=m,f-=_,g-=y,p-=E.r,m-=E.g,_-=E.b,y-=E.a,h=r+((h=o+L)0&&e(t,n)},Konva.Factory.addGetterSetter(Konva.Node,"blurRadius",0,null,Konva.Factory.afterSetFilter)}(),function(){"use strict";function t(t,e,n){var i=4*(n*t.width+e),a=[];return a.push(t.data[i++],t.data[i++],t.data[i++],t.data[i++]),a}function e(t,e){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2)+Math.pow(t[2]-e[2],2))}function n(t){for(var e=[0,0,0],n=0;n=0&&v=0&&f=0&&v=0&&f=1020?255:0}return o}function s(t,e,n){for(var i=[1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9,1/9],a=Math.round(Math.sqrt(i.length)),r=Math.floor(a/2),o=[],s=0;s=0&&v=0&&f255?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()),c=Math.pow(2,this.saturation()),l=Math.abs(this.hue()+360)%360,d=h*c*Math.cos(l*Math.PI/180),u=h*c*Math.sin(l*Math.PI/180),v=.299*h+.701*d+.167*u,f=.587*h-.587*d+.33*u,g=.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,K=.587*h-.586*d-1.05*u,S=.114*h+.886*d-.2*u;for(e=0;ec&&(v=0);var f=(d-1+v)*h*4,g=h;do{var p=u+4*(g-1),m=o;g+m<1&&(m=0),g+m>h&&(m=0);var _=f+4*(g-1+m),y=s[p]-s[_],K=s[p+1]-s[_+1],S=s[p+2]-s[_+2],x=y,C=x>0?x:-x,w=K>0?K:-K,b=S>0?S:-S;if(w>C&&(x=K),b>C&&(x=S),x*=e,a){var F=s[p]+x,T=s[p+1]+x,P=s[p+2]+x;s[p]=F>255?255:F<0?0:F,s[p+1]=T>255?255:T<0?0:T,s[p+2]=P>255?255:P<0?0:P}else{var A=n-x;A<0?A=0:A>255&&(A=255),s[p]=s[p+1]=s[p+2]=A}}while(--g)}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],c=h,l=o[1],d=l,u=o[2],v=u,f=this.enhance();if(0!==f){for(r=0;rc&&(c=n),i=o[r+1],id&&(d=i),a=o[r+2],av&&(v=a);c===h&&(c=255,h=0),d===l&&(d=255,l=0),v===u&&(v=255,u=0);var g,p,m,_,y,K,S,x,C;for(f>0?(p=c+f*(255-c),m=h-f*(h-0),y=d+f*(255-d),K=l-f*(l-0),x=v+f*(255-v),C=u-f*(u-0)):(g=.5*(c+h),p=c+f*(c-g),m=h+f*(h-g),_=.5*(d+l),y=d+f*(d-_),K=l+f*(l-_),S=.5*(v+u),x=v+f*(v-S),C=u+f*(u-S)),r=0;r=p))for(n=l;n=m||(i=4*(p*n+e),a+=t[i+0],r+=t[i+1],o+=t[i+2],s+=t[i+3],f+=1);for(a/=f,r/=f,o/=f,e=h;e=p))for(n=l;n=m||(i=4*(p*n+e),t[i+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;e