diff --git a/CHANGELOG.md b/CHANGELOG.md index a9d6ea38..cbeae372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Default value for `dragDistance` is changed to 3px. - Fix rare error throw on drag +- Caching with height = 0 or width = 0 with throw async error. Caching will be ignored. ## [1.6.8][2017-08-19] diff --git a/gulpfile.js b/gulpfile.js index e7f20e6f..35ae6c91 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -151,7 +151,7 @@ gulp.task('inspect', function() { // // generate documentation gulp.task('api', function() { - return gulp.src('./src/**/*.js').pipe( + return gulp.src('./konva.js').pipe( jsdoc({ opts: { destination: './api' diff --git a/konva.js b/konva.js index fcba1d70..fbc7f4b0 100644 --- a/konva.js +++ b/konva.js @@ -2,7 +2,7 @@ * Konva JavaScript Framework v1.6.8 * http://konvajs.github.io/ * Licensed under the MIT or GPL Version 2 licenses. - * Date: Sat Aug 26 2017 + * Date: Tue Sep 05 2017 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - 2017 by Anton Lavrenov (Konva) @@ -2527,7 +2527,13 @@ drawBorder = conf.drawBorder || false; if (!width || !height) { - throw new Error('Width or height of caching configuration equals 0.'); + // make throw async, because we don't need to stop funcion + setTimeout(function() { + Konva.Util.throw( + 'Width or height of caching configuration equals 0. Caching is ignored.' + ); + }); + return; } width += offset * 2; @@ -2537,10 +2543,10 @@ y -= offset; var cachedSceneCanvas = new Konva.SceneCanvas({ - pixelRatio: pixelRatio, - width: width, - height: height - }), + pixelRatio: pixelRatio, + width: width, + height: height + }), cachedFilterCanvas = new Konva.SceneCanvas({ pixelRatio: pixelRatio, width: width, @@ -2684,7 +2690,8 @@ context.restore(); }, _drawCachedHitCanvas: function(context) { - var cachedCanvas = this._cache.canvas, hitCanvas = cachedCanvas.hit; + var cachedCanvas = this._cache.canvas, + hitCanvas = cachedCanvas.hit; context.save(); context.translate(this._cache.canvas.x, this._cache.canvas.y); context.drawImage(hitCanvas._canvas, 0, 0); @@ -3012,7 +3019,8 @@ * }) */ getAncestors: function() { - var parent = this.getParent(), ancestors = new Konva.Collection(); + var parent = this.getParent(), + ancestors = new Konva.Collection(); while (parent) { ancestors.push(parent); @@ -3086,7 +3094,8 @@ return this._getCache(LISTENING, this._isListening); }, _isListening: function() { - var listening = this.getListening(), parent = this.getParent(); + var listening = this.getListening(), + parent = this.getParent(); // the following conditions are a simplification of the truth table above. // please modify carefully @@ -3123,7 +3132,8 @@ return this._getCache(VISIBLE, this._isVisible); }, _isVisible: function() { - var visible = this.getVisible(), parent = this.getParent(); + var visible = this.getVisible(), + parent = this.getParent(); // the following conditions are a simplification of the truth table above. // please modify carefully @@ -3191,7 +3201,13 @@ * @returns {Integer} */ getAbsoluteZIndex: function() { - var depth = this.getDepth(), that = this, index = 0, nodes, len, n, child; + var depth = this.getDepth(), + that = this, + index = 0, + nodes, + len, + n, + child; function addChildren(children) { nodes = []; @@ -3228,7 +3244,8 @@ * @returns {Integer} */ getDepth: function() { - var depth = 0, parent = this.parent; + var depth = 0, + parent = this.parent; while (parent) { depth++; @@ -3276,7 +3293,8 @@ * @returns {Konva.Node} */ setAbsolutePosition: function(pos) { - var origTrans = this._clearTransform(), it; + var origTrans = this._clearTransform(), + it; // don't clear translation this.attrs.x = origTrans.x; @@ -3371,7 +3389,10 @@ return this; }, _eachAncestorReverse: function(func, top) { - var family = [], parent = this.getParent(), len, n; + var family = [], + parent = this.getParent(), + len, + n; // if top node is defined, and this node is top node, // there's no need to build a family tree. just execute @@ -3432,7 +3453,8 @@ Konva.Util.warn('Node has no parent. moveUp function is ignored.'); return false; } - var index = this.index, len = this.parent.getChildren().length; + var index = this.index, + len = this.parent.getChildren().length; if (index < len - 1) { this.parent.children.splice(index, 1); this.parent.children.splice(index + 1, 0, this); @@ -3545,7 +3567,12 @@ * @returns {Object} */ toObject: function() { - var obj = {}, attrs = this.getAttrs(), key, val, getter, defaultValue; + var obj = {}, + attrs = this.getAttrs(), + key, + val, + getter, + defaultValue; obj.attrs = {}; @@ -3747,7 +3774,9 @@ } }, _getAbsoluteTransform: function(top) { - var at = new Konva.Transform(), transformsEnabled, trans; + var at = new Konva.Transform(), + transformsEnabled, + trans; // start with stage and traverse downwards to self this._eachAncestorReverse(function(node) { @@ -3788,7 +3817,8 @@ parent = parent.getParent(); } - var scaleX = 1, scaleY = 1; + var scaleX = 1, + scaleY = 1; // start with stage and traverse downwards to self this._eachAncestorReverse(function(node) { @@ -3904,10 +3934,10 @@ y = config.y || 0, pixelRatio = config.pixelRatio || 1, canvas = new Konva.SceneCanvas({ - width: config.width || - this.getWidth() || - (stage ? stage.getWidth() : 0), - height: config.height || + width: + config.width || this.getWidth() || (stage ? stage.getWidth() : 0), + height: + config.height || this.getHeight() || (stage ? stage.getHeight() : 0), pixelRatio: pixelRatio @@ -3963,7 +3993,8 @@ */ toDataURL: function(config) { config = config || {}; - var mimeType = config.mimeType || null, quality = config.quality || null; + var mimeType = config.mimeType || null, + quality = config.quality || null; return this._toKonvaCanvas(config).toDataURL(mimeType, quality); }, /** @@ -4050,7 +4081,9 @@ : []; }, _off: function(type, name) { - var evtListeners = this.eventListeners[type], i, evtName; + var evtListeners = this.eventListeners[type], + i, + evtName; for (i = 0; i < evtListeners.length; i++) { evtName = evtListeners[i].name; @@ -4175,7 +4208,8 @@ * node.setAttr('x', 5); */ setAttr: function(attr, val) { - var method = SET + Konva.Util._capitalize(attr), func = this[method]; + var method = SET + Konva.Util._capitalize(attr), + func = this[method]; if (Konva.Util._isFunction(func)) { func.call(this, val); @@ -4264,7 +4298,8 @@ } }, _fire: function(eventType, evt) { - var events = this.eventListeners[eventType], i; + var events = this.eventListeners[eventType], + i; evt = evt || {}; evt.currentTarget = this; diff --git a/konva.min.js b/konva.min.js index 9f5191f9..73459be3 100644 --- a/konva.min.js +++ b/konva.min.js @@ -2,7 +2,7 @@ * Konva JavaScript Framework v1.6.8 * http://konvajs.github.io/ * Licensed under the MIT or GPL Version 2 licenses. - * Date: Sat Aug 26 2017 + * Date: Tue Sep 05 2017 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - 2017 by Anton Lavrenov (Konva) @@ -26,7 +26,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -!function(t){"use strict";var e=Math.PI/180,n={version:"1.6.8",stages:[],idCounter:0,ids:{},names:{},shapes:{},listenClickTap:!1,inDblClickWindow:!1,enableTrace:!1,traceArrMax:100,dblClickWindow:400,pixelRatio:void 0,dragDistance:3,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);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 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=void 0!==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)"function"==typeof define&&define.amd&&define(function(){return n}),n.document=document,n.window=window;else{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=new r("").window,n.document=n.window.document,n.window.Image=a.Image,n._nodeCanvas=a,n.isNode=!0}module.exports=n}}("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.isNode?new Konva._nodeCanvas: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="0"+t;return"#"+t},get:function(t,e){return void 0===t?e:t},getRGB:function(t){var e;return t in n?(e=n[t],{r:e[0],g:e[1],b:e[2]}):"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=i.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=n[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("Konva error: "+t)},error:function(t){console.error("Konva error: "+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)),c=o*s/(s+h),l=o*h/(s+h);return[n-c*(a-t),i-c*(r-e),n+l*(a-t),i+l*(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+l*(n-t))-a)*(o-a)+((s=e+l*(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),c=h[0],l=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;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="Shape",n=["id"],i=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(" "),a=["scaleXChange.konva","scaleYChange.konva"].join(" ");t.Node=function(t){this._init(t)},t.Util.addMethods(t.Node,{_init:function(e){var n=this;this._id=t.idCounter++,this.eventListeners={},this.attrs={},this._cache={},this._filterUpToDate=!1,this._isUnderCache=!1,this.setAttrs(e),this.on(i,function(){this._clearCache("transform"),n._clearSelfAndDescendantCache("absoluteTransform")}),this.on(a,function(){n._clearSelfAndDescendantCache("absoluteScale")}),this.on("visibleChange.konva",function(){n._clearSelfAndDescendantCache("visible")}),this.on("listeningChange.konva",function(){n._clearSelfAndDescendantCache("listening")}),this.on("opacityChange.konva",function(){n._clearSelfAndDescendantCache("absoluteOpacity")})},_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(e){var n=e||{},i=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()}),a=n.width||i.width,r=n.height||i.height,o=n.pixelRatio,s=n.x||i.x,h=n.y||i.y,c=n.offset||0,l=n.drawBorder||!1;if(!a||!r)throw new Error("Width or height of caching configuration equals 0.");a+=2*c,r+=2*c,s-=c,h-=c;var d=new t.SceneCanvas({pixelRatio:o,width:a,height:r}),u=new t.SceneCanvas({pixelRatio:o,width:a,height:r}),f=new t.HitCanvas({pixelRatio:1,width:a,height:r}),v=d.getContext(),g=f.getContext();return f.isCache=!0,this.clearCache(),v.save(),g.save(),v.translate(-s,-h),g.translate(-s,-h),this._isUnderCache=!0,this._clearSelfAndDescendantCache("absoluteOpacity"),this._clearSelfAndDescendantCache("absoluteScale"),this.drawScene(d,this,!0),this.drawHit(f,this,!0),this._isUnderCache=!1,v.restore(),g.restore(),l&&(v.save(),v.beginPath(),v.rect(0,0,a,r),v.closePath(),v.setAttr("strokeStyle","red"),v.setAttr("lineWidth",5),v.stroke(),v.restore()),this._cache.canvas={scene:d,filter:u,hit:f,x:s,y:h},this},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,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&&n[0].getDepth()<=o&&t(n)}var n,i,a,r,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("transform"),this._clearSelfAndDescendantCache("absoluteTransform")},_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("transform"),this._clearSelfAndDescendantCache("absoluteTransform"),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("absoluteOpacity",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]=(f*H>>W)*T,A[l+2]=(v*H>>W)*T):A[l]=A[l+1]=A[l+2]=0,u-=p,f-=m,v-=_,g-=y,p-=E.r,m-=E.g,_-=E.b,y-=E.a,h=d+((h=r+n+1)>W,T>0?(T=255/T,A[h]=(u*H>>W)*T,A[h+1]=(f*H>>W)*T,A[h+2]=(v*H>>W)*T):A[h]=A[h+1]=A[h+2]=0,u-=p,f-=m,v-=_,g-=y,p-=E.r,m-=E.g,_-=E.b,y-=E.a,h=r+((h=o+L)0&&n(t,e)},t.Factory.addGetterSetter(t.Node,"blurRadius",0,null,t.Factory.afterSetFilter)}(Konva),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&&f=0&&v=0&&f=0&&v=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&&f=0&&v255?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),f=.299*h+.701*d+.167*u,v=.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,S=.587*h-.586*d-1.05*u,K=.114*h+.886*d-.2*u;for(e=0;ec&&(f=0);var v=(d-1+f)*h*4,g=h;do{var p=u+4*(g-1),m=o;g+m<1&&(m=0),g+m>h&&(m=0);var _=v+4*(g-1+m),y=s[p]-s[_],S=s[p+1]-s[_+1],K=s[p+2]-s[_+2],C=y,x=C>0?C:-C,w=S>0?S:-S,b=K>0?K:-K;if(w>x&&(C=S),b>x&&(C=K),C*=e,a){var F=s[p]+C,T=s[p+1]+C,P=s[p+2]+C;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-C;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],f=u,v=this.enhance();if(0!==v){for(r=0;rc&&(c=n),(i=o[r+1])d&&(d=i),(a=o[r+2])f&&(f=a);c===h&&(c=255,h=0),d===l&&(d=255,l=0),f===u&&(f=255,u=0);var g,p,m,_,y,S,K,C,x;for(v>0?(p=c+v*(255-c),m=h-v*(h-0),y=d+v*(255-d),S=l-v*(l-0),C=f+v*(255-f),x=u-v*(u-0)):(p=c+v*(c-(g=.5*(c+h))),m=h+v*(h-g),y=d+v*(d-(_=.5*(d+l))),S=l+v*(l-_),C=f+v*(f-(K=.5*(f+u))),x=u+v*(u-K)),r=0;r=p))for(n=l;n=m||(a+=t[(i=4*(p*n+e))+0],r+=t[i+1],o+=t[i+2],s+=t[i+3],v+=1);for(a/=v,r/=v,o/=v,e=h;e=p))for(n=l;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 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=void 0!==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)"function"==typeof define&&define.amd&&define(function(){return n}),n.document=document,n.window=window;else{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=new r("").window,n.document=n.window.document,n.window.Image=a.Image,n._nodeCanvas=a,n.isNode=!0}module.exports=n}}("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.isNode?new Konva._nodeCanvas: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="0"+t;return"#"+t},get:function(t,e){return void 0===t?e:t},getRGB:function(t){var e;return t in n?(e=n[t],{r:e[0],g:e[1],b:e[2]}):"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=i.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=n[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("Konva error: "+t)},error:function(t){console.error("Konva error: "+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)),c=o*s/(s+h),l=o*h/(s+h);return[n-c*(a-t),i-c*(r-e),n+l*(a-t),i+l*(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+l*(n-t))-a)*(o-a)+((s=e+l*(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),c=h[0],l=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;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="Shape",n=["id"],i=["xChange.konva","yChange.konva","scaleXChange.konva","scaleYChange.konva","skewXChange.konva","skewYChange.konva","rotationChange.konva","offsetXChange.konva","offsetYChange.konva","transformsEnabledChange.konva"].join(" "),a=["scaleXChange.konva","scaleYChange.konva"].join(" ");t.Node=function(t){this._init(t)},t.Util.addMethods(t.Node,{_init:function(e){var n=this;this._id=t.idCounter++,this.eventListeners={},this.attrs={},this._cache={},this._filterUpToDate=!1,this._isUnderCache=!1,this.setAttrs(e),this.on(i,function(){this._clearCache("transform"),n._clearSelfAndDescendantCache("absoluteTransform")}),this.on(a,function(){n._clearSelfAndDescendantCache("absoluteScale")}),this.on("visibleChange.konva",function(){n._clearSelfAndDescendantCache("visible")}),this.on("listeningChange.konva",function(){n._clearSelfAndDescendantCache("listening")}),this.on("opacityChange.konva",function(){n._clearSelfAndDescendantCache("absoluteOpacity")})},_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(e){var n=e||{},i=this.getClientRect({skipTransform:!0,relativeTo:this.getParent()}),a=n.width||i.width,r=n.height||i.height,o=n.pixelRatio,s=n.x||i.x,h=n.y||i.y,c=n.offset||0,l=n.drawBorder||!1;{if(a&&r){a+=2*c,r+=2*c,s-=c,h-=c;var d=new t.SceneCanvas({pixelRatio:o,width:a,height:r}),u=new t.SceneCanvas({pixelRatio:o,width:a,height:r}),f=new t.HitCanvas({pixelRatio:1,width:a,height:r}),v=d.getContext(),g=f.getContext();return f.isCache=!0,this.clearCache(),v.save(),g.save(),v.translate(-s,-h),g.translate(-s,-h),this._isUnderCache=!0,this._clearSelfAndDescendantCache("absoluteOpacity"),this._clearSelfAndDescendantCache("absoluteScale"),this.drawScene(d,this,!0),this.drawHit(f,this,!0),this._isUnderCache=!1,v.restore(),g.restore(),l&&(v.save(),v.beginPath(),v.rect(0,0,a,r),v.closePath(),v.setAttr("strokeStyle","red"),v.setAttr("lineWidth",5),v.stroke(),v.restore()),this._cache.canvas={scene:d,filter:u,hit:f,x:s,y:h},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,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&&n[0].getDepth()<=o&&t(n)}var n,i,a,r,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("transform"),this._clearSelfAndDescendantCache("absoluteTransform")},_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("transform"),this._clearSelfAndDescendantCache("absoluteTransform"),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("absoluteOpacity",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]=(f*H>>W)*T,A[l+2]=(v*H>>W)*T):A[l]=A[l+1]=A[l+2]=0,u-=p,f-=m,v-=_,g-=y,p-=E.r,m-=E.g,_-=E.b,y-=E.a,h=d+((h=r+n+1)>W,T>0?(T=255/T,A[h]=(u*H>>W)*T,A[h+1]=(f*H>>W)*T,A[h+2]=(v*H>>W)*T):A[h]=A[h+1]=A[h+2]=0,u-=p,f-=m,v-=_,g-=y,p-=E.r,m-=E.g,_-=E.b,y-=E.a,h=r+((h=o+L)0&&n(t,e)},t.Factory.addGetterSetter(t.Node,"blurRadius",0,null,t.Factory.afterSetFilter)}(Konva),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&&f=0&&v=0&&f=0&&v=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&&f=0&&v255?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),f=.299*h+.701*d+.167*u,v=.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,S=.587*h-.586*d-1.05*u,K=.114*h+.886*d-.2*u;for(e=0;ec&&(f=0);var v=(d-1+f)*h*4,g=h;do{var p=u+4*(g-1),m=o;g+m<1&&(m=0),g+m>h&&(m=0);var _=v+4*(g-1+m),y=s[p]-s[_],S=s[p+1]-s[_+1],K=s[p+2]-s[_+2],C=y,x=C>0?C:-C,w=S>0?S:-S,b=K>0?K:-K;if(w>x&&(C=S),b>x&&(C=K),C*=e,a){var F=s[p]+C,T=s[p+1]+C,P=s[p+2]+C;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-C;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],f=u,v=this.enhance();if(0!==v){for(r=0;rc&&(c=n),(i=o[r+1])d&&(d=i),(a=o[r+2])f&&(f=a);c===h&&(c=255,h=0),d===l&&(d=255,l=0),f===u&&(f=255,u=0);var g,p,m,_,y,S,K,C,x;for(v>0?(p=c+v*(255-c),m=h-v*(h-0),y=d+v*(255-d),S=l-v*(l-0),C=f+v*(255-f),x=u-v*(u-0)):(p=c+v*(c-(g=.5*(c+h))),m=h+v*(h-g),y=d+v*(d-(_=.5*(d+l))),S=l+v*(l-_),C=f+v*(f-(K=.5*(f+u))),x=u+v*(u-K)),r=0;r=p))for(n=l;n=m||(a+=t[(i=4*(p*n+e))+0],r+=t[i+1],o+=t[i+2],s+=t[i+3],v+=1);for(a/=v,r/=v,o/=v,e=h;e=p))for(n=l;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;e