From 6fbe48e5835a00defa5b54336648de346d9ed376 Mon Sep 17 00:00:00 2001 From: Anton Lavrenov Date: Mon, 17 Feb 2020 19:51:18 -0500 Subject: [PATCH] allow cloning id --- .eslintrc | 2 +- konva.js | 17 ++++++----------- konva.min.js | 4 ++-- src/Node.ts | 20 ++++---------------- test/unit/Node-test.js | 2 +- 5 files changed, 14 insertions(+), 31 deletions(-) diff --git a/.eslintrc b/.eslintrc index 850fbaa1..1fe78c9a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -158,7 +158,7 @@ "max-len": [2, 320, 4], "max-nested-callbacks": [2, 2], "max-params": [1, 8], - "max-statements": [1, 60], + "max-statements": [1, 260], "new-cap": 0, "new-parens": 2, "newline-after-var": 0, diff --git a/konva.js b/konva.js index c731a84d..af943ab3 100644 --- a/konva.js +++ b/konva.js @@ -8,7 +8,7 @@ * Konva JavaScript Framework v4.1.5 * http://konvajs.org/ * Licensed under the MIT - * Date: Sun Feb 16 2020 + * Date: Mon Feb 17 2020 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) @@ -2515,7 +2515,7 @@ } }; // CONSTANTS - var ABSOLUTE_OPACITY = 'absoluteOpacity', ABSOLUTE_TRANSFORM = 'absoluteTransform', ABSOLUTE_SCALE = 'absoluteScale', CANVAS = 'canvas', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER = 'mouseenter', MOUSELEAVE = 'mouseleave', NAME = 'name', SET$1 = 'set', SHAPE = 'Shape', SPACE = ' ', STAGE = 'stage', TRANSFORM = 'transform', UPPER_STAGE = 'Stage', VISIBLE = 'visible', CLONE_BLACK_LIST = ['id'], TRANSFORM_CHANGE_STR = [ + var ABSOLUTE_OPACITY = 'absoluteOpacity', ABSOLUTE_TRANSFORM = 'absoluteTransform', ABSOLUTE_SCALE = 'absoluteScale', CANVAS = 'canvas', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER = 'mouseenter', MOUSELEAVE = 'mouseleave', NAME = 'name', SET$1 = 'set', SHAPE = 'Shape', SPACE = ' ', STAGE = 'stage', TRANSFORM = 'transform', UPPER_STAGE = 'Stage', VISIBLE = 'visible', TRANSFORM_CHANGE_STR = [ 'xChange.konva', 'yChange.konva', 'scaleXChange.konva', @@ -3990,11 +3990,6 @@ Node.prototype.clone = function (obj) { // instantiate new node var attrs = Util.cloneObject(this.attrs), key, allListeners, len, n, listener; - // filter black attrs - for (var i in CLONE_BLACK_LIST) { - var blockAttr = CLONE_BLACK_LIST[i]; - delete attrs[blockAttr]; - } // apply attr overrides for (key in obj) { attrs[key] = obj[key]; @@ -4345,10 +4340,10 @@ this._fire(eventType, evt); // simulate event bubbling var stopBubble = (eventType === MOUSEENTER || eventType === MOUSELEAVE) && - (compareShape && - compareShape.isAncestorOf && - compareShape.isAncestorOf(this) && - !compareShape.isAncestorOf(this.parent)); + compareShape && + compareShape.isAncestorOf && + compareShape.isAncestorOf(this) && + !compareShape.isAncestorOf(this.parent); if (((evt && !evt.cancelBubble) || !evt) && this.parent && this.parent.isListening() && diff --git a/konva.min.js b/konva.min.js index db983e94..332c9336 100644 --- a/konva.min.js +++ b/konva.min.js @@ -3,10 +3,10 @@ * Konva JavaScript Framework v4.1.5 * http://konvajs.org/ * Licensed under the MIT - * Date: Sun Feb 16 2020 + * Date: Mon Feb 17 2020 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) * * @license - */var e=Math.PI/180;function t(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)||[],n=!!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:function(t){var e=t.indexOf("msie ");if(0>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 p?{r:(e=p[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=u.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",O._namedColorToRBA(t)||O._hex3ColorToRGBA(t)||O._hex6ColorToRGBA(t)||O._rgbColorToRGBA(t)||O._rgbaColorToRGBA(t)||O._hslColorToRGBA(t)},_namedColorToRBA:function(t){var e=p[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}},_hslColorToRGBA:function(t){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(t)){var e=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(t),i=(e[0],e.slice(1)),n=Number(i[0])/360,r=Number(i[1])/100,o=Number(i[2])/100,a=void 0,s=void 0,h=void 0;if(0==r)return h=255*o,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};for(var l=2*o-(a=o<.5?o*(1+r):o+r-o*r),d=[0,0,0],c=0;c<3;c++)(s=n+1/3*-(c-1))<0&&s++,1t.x+t.width||e.x+e.widtht.y+t.height||e.y+e.heighte.length){var a=e;e=t,t=a}for(n=0;n=this.parent.children.length)&&O.warn("Unexpected value "+t+" for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to "+(this.parent.children.length-1)+".");var e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this},pt.prototype.getAbsoluteOpacity=function(){return this._getCache(J,this._getAbsoluteOpacity)},pt.prototype._getAbsoluteOpacity=function(){var t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t},pt.prototype.moveTo=function(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this},pt.prototype.toObject=function(){var t,e,i,n={},r=this.getAttrs();for(t in n.attrs={},r)e=r[t],O.isObject(e)&&!O._isPlainObject(e)&&!O._isArray(e)||(i="function"==typeof this[t]&&this[t],delete r[t],(i?i.call(this):null)!==(r[t]=e)&&(n.attrs[t]=e));return n.className=this.getClassName(),O._prepareToStringify(n)},pt.prototype.toJSON=function(){return JSON.stringify(this.toObject())},pt.prototype.getParent=function(){return this.parent},pt.prototype.findAncestors=function(t,e,i){var n=[];e&&this._isMatch(t)&&n.push(this);for(var r=this.parent;r;){if(r===i)return n;r._isMatch(t)&&n.push(r),r=r.parent}return n},pt.prototype.isAncestorOf=function(t){return!1},pt.prototype.findAncestor=function(t,e,i){return this.findAncestors(t,e,i)[0]},pt.prototype._isMatch=function(t){if(!t)return!1;if("function"==typeof t)return t(this);var e,i,n=t.replace(/ /g,"").split(","),r=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())},Re.prototype.getTime=function(){return this._time},Re.prototype.setPosition=function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},Re.prototype.getPosition=function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},Re.prototype.play=function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},Re.prototype.reverse=function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},Re.prototype.seek=function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},Re.prototype.reset=function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},Re.prototype.finish=function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},Re.prototype.update=function(){this.setPosition(this.getPosition(this._time))},Re.prototype.onEnterFrame=function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},Re.prototype.pause=function(){this.state=1,this.fire("onPause")},Re.prototype.getTimer=function(){return(new Date).getTime()},Re);function Re(t,e,i,n,r,o,a){this.prop=t,this.propFunc=e,this.begin=n,this._pos=n,this.duration=o,this._change=0,this.prevPos=0,this.yoyo=a,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=i,this._change=r-this.begin,this.pause()}var Oe=(Le.prototype._addAttr=function(t,e){var i,n,r,o,a,s,h,l,d=this.node,c=d._id;if((r=Le.tweens[c][t])&&delete Le.attrs[c][r][t],i=d.getAttr(t),O._isArray(e))if(n=[],a=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(h=i,i=O._prepareArrayForTween(i,e,d.closed())):(s=e,e=O._prepareArrayForTween(e,i,d.closed()))),0===t.indexOf("fill"))for(o=0;othis.dataArray[i].pathLength;)t-=this.dataArray[i].pathLength,++i;if(i===n)return{x:(e=this.dataArray[i-1].points.slice(-2))[0],y:e[1]};if(t<.01)return{x:(e=this.dataArray[i].points.slice(0,2))[0],y:e[1]};var r=this.dataArray[i],o=r.points;switch(r.command){case"L":return ui.getPointOnLine(t,r.start.x,r.start.y,o[0],o[1]);case"C":return ui.getPointOnCubicBezier(t/r.pathLength,r.start.x,r.start.y,o[0],o[1],o[2],o[3],o[4],o[5]);case"Q":return ui.getPointOnQuadraticBezier(t/r.pathLength,r.start.x,r.start.y,o[0],o[1],o[2],o[3]);case"A":var a=o[0],s=o[1],h=o[2],l=o[3],d=o[4],c=o[5],p=o[6];return d+=c*t/r.pathLength,ui.getPointOnEllipticalArc(a,s,h,l,d,p)}return null},ui.getLineLength=function(t,e,i,n){return Math.sqrt((i-t)*(i-t)+(n-e)*(n-e))},ui.getPointOnLine=function(t,e,i,n,r,o,a){void 0===o&&(o=e),void 0===a&&(a=i);var s=(r-i)/(n-e+1e-8),h=Math.sqrt(t*t/(1+s*s));n>>1,k=_.slice(0,1+P),T=this._getTextWidth(k)+v;T<=l?(b=1+P,w=k+(g?"…":""),C=T):x=P}if(!w)break;if(f){var A,M=_[w.length];0<(A=(" "===M||"-"===M)&&C<=l?w.length:Math.max(w.lastIndexOf(" "),w.lastIndexOf("-"))+1)&&(b=A,w=w.slice(0,b),C=this._getTextWidth(w))}if(w=w.trimRight(),this._addTextLine(w),i=Math.max(i,C),c+=n,!u||s&&de?g=pi.getPointOnLine(e,f.x,f.y,v.points[0],v.points[1],f.x,f.y):v=void 0;break;case"A":var a=v.points[4],s=v.points[5],h=v.points[4]+s;0===m?m=a+1e-8:iv.pathLength?1e-8:e/v.pathLength:ithis.findOne(".bottom-right").x()?-1:1,l=this.findOne(".top-left").y()>this.findOne(".bottom-right").y()?-1:1;e=n*this.cos*h,i=n*this.sin*l,this.findOne(".top-left").x(this.findOne(".bottom-right").x()-e-2*s),this.findOne(".top-left").y(this.findOne(".bottom-right").y()-i-2*s)}}else if("top-center"===this._movingAnchorName)this.findOne(".top-left").y(r.y());else if("top-right"===this._movingAnchorName){a&&(n=Math.sqrt(Math.pow(r.x()-this.findOne(".bottom-left").x()-2*s,2)+Math.pow(this.findOne(".bottom-left").y()-r.y()-2*s,2)),h=this.findOne(".top-right").x()this.findOne(".bottom-left").y()?-1:1,e=n*this.cos*h,i=n*this.sin*l,this.findOne(".top-right").x(e+s),this.findOne(".top-right").y(this.findOne(".bottom-left").y()-i-2*s));var d=r.position();this.findOne(".top-left").y(d.y),this.findOne(".bottom-right").x(d.x)}else if("middle-left"===this._movingAnchorName)this.findOne(".top-left").x(r.x());else if("middle-right"===this._movingAnchorName)this.findOne(".bottom-right").x(r.x());else if("bottom-left"===this._movingAnchorName)a&&(n=Math.sqrt(Math.pow(this.findOne(".top-right").x()-r.x()-2*s,2)+Math.pow(r.y()-this.findOne(".top-right").y()-2*s,2)),h=this.findOne(".top-right").x()this.findOne(".bottom-right").x()?-1:1,l=this.findOne(".top-left").y()>this.findOne(".bottom-right").y()?-1:1,e=n*this.cos*h,i=n*this.sin*l,this.findOne(".bottom-right").x(e+s),this.findOne(".bottom-right").y(i+s));else if("rotater"===this._movingAnchorName){var c=this._getNodeRect();e=r.x()-c.width/2,i=-r.y()+c.height/2;var p=Math.atan2(-i,e)+Math.PI/2;c.height<0&&(p-=Math.PI);for(var u=R.getAngle(this.rotation()),f=O._radToDeg(u)+O._radToDeg(p),g=R.getAngle(this.getNode().rotation()),v=O._degToRad(f),y=this.rotationSnaps(),m=0;m>N,0!==C?(C=255/C,k[s]=(l*z>>N)*C,k[s+1]=(d*z>>N)*C,k[s+2]=(c*z>>N)*C):k[s]=k[s+1]=k[s+2]=0,l-=u,d-=f,c-=g,p-=v,u-=F.r,f-=F.g,g-=F.b,v-=F.a,o=h+((o=i+e+1)>N,0>N)*C,k[o+1]=(d*z>>N)*C,k[o+2]=(c*z>>N)*C):k[o]=k[o+1]=k[o+2]=0,l-=u,d-=f,c-=g,p-=v,u-=F.r,f-=F.g,g-=F.b,v-=F.a,o=i+((o=n+O)>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 p?{r:(e=p[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=u.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",O._namedColorToRBA(t)||O._hex3ColorToRGBA(t)||O._hex6ColorToRGBA(t)||O._rgbColorToRGBA(t)||O._rgbaColorToRGBA(t)||O._hslColorToRGBA(t)},_namedColorToRBA:function(t){var e=p[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}},_hslColorToRGBA:function(t){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(t)){var e=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(t),i=(e[0],e.slice(1)),n=Number(i[0])/360,r=Number(i[1])/100,o=Number(i[2])/100,a=void 0,s=void 0,h=void 0;if(0==r)return h=255*o,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};for(var l=2*o-(a=o<.5?o*(1+r):o+r-o*r),d=[0,0,0],c=0;c<3;c++)(s=n+1/3*-(c-1))<0&&s++,1t.x+t.width||e.x+e.widtht.y+t.height||e.y+e.heighte.length){var a=e;e=t,t=a}for(n=0;n=this.parent.children.length)&&O.warn("Unexpected value "+t+" for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to "+(this.parent.children.length-1)+".");var e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this},ct.prototype.getAbsoluteOpacity=function(){return this._getCache(J,this._getAbsoluteOpacity)},ct.prototype._getAbsoluteOpacity=function(){var t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t},ct.prototype.moveTo=function(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this},ct.prototype.toObject=function(){var t,e,i,n={},r=this.getAttrs();for(t in n.attrs={},r)e=r[t],O.isObject(e)&&!O._isPlainObject(e)&&!O._isArray(e)||(i="function"==typeof this[t]&&this[t],delete r[t],(i?i.call(this):null)!==(r[t]=e)&&(n.attrs[t]=e));return n.className=this.getClassName(),O._prepareToStringify(n)},ct.prototype.toJSON=function(){return JSON.stringify(this.toObject())},ct.prototype.getParent=function(){return this.parent},ct.prototype.findAncestors=function(t,e,i){var n=[];e&&this._isMatch(t)&&n.push(this);for(var r=this.parent;r;){if(r===i)return n;r._isMatch(t)&&n.push(r),r=r.parent}return n},ct.prototype.isAncestorOf=function(t){return!1},ct.prototype.findAncestor=function(t,e,i){return this.findAncestors(t,e,i)[0]},ct.prototype._isMatch=function(t){if(!t)return!1;if("function"==typeof t)return t(this);var e,i,n=t.replace(/ /g,"").split(","),r=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())},Ge.prototype.getTime=function(){return this._time},Ge.prototype.setPosition=function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},Ge.prototype.getPosition=function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},Ge.prototype.play=function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},Ge.prototype.reverse=function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},Ge.prototype.seek=function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},Ge.prototype.reset=function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},Ge.prototype.finish=function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},Ge.prototype.update=function(){this.setPosition(this.getPosition(this._time))},Ge.prototype.onEnterFrame=function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},Ge.prototype.pause=function(){this.state=1,this.fire("onPause")},Ge.prototype.getTimer=function(){return(new Date).getTime()},Ge);function Ge(t,e,i,n,r,o,a){this.prop=t,this.propFunc=e,this.begin=n,this._pos=n,this.duration=o,this._change=0,this.prevPos=0,this.yoyo=a,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=i,this._change=r-this.begin,this.pause()}var Re=(Oe.prototype._addAttr=function(t,e){var i,n,r,o,a,s,h,l,d=this.node,c=d._id;if((r=Oe.tweens[c][t])&&delete Oe.attrs[c][r][t],i=d.getAttr(t),O._isArray(e))if(n=[],a=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(h=i,i=O._prepareArrayForTween(i,e,d.closed())):(s=e,e=O._prepareArrayForTween(e,i,d.closed()))),0===t.indexOf("fill"))for(o=0;othis.dataArray[i].pathLength;)t-=this.dataArray[i].pathLength,++i;if(i===n)return{x:(e=this.dataArray[i-1].points.slice(-2))[0],y:e[1]};if(t<.01)return{x:(e=this.dataArray[i].points.slice(0,2))[0],y:e[1]};var r=this.dataArray[i],o=r.points;switch(r.command){case"L":return pi.getPointOnLine(t,r.start.x,r.start.y,o[0],o[1]);case"C":return pi.getPointOnCubicBezier(t/r.pathLength,r.start.x,r.start.y,o[0],o[1],o[2],o[3],o[4],o[5]);case"Q":return pi.getPointOnQuadraticBezier(t/r.pathLength,r.start.x,r.start.y,o[0],o[1],o[2],o[3]);case"A":var a=o[0],s=o[1],h=o[2],l=o[3],d=o[4],c=o[5],p=o[6];return d+=c*t/r.pathLength,pi.getPointOnEllipticalArc(a,s,h,l,d,p)}return null},pi.getLineLength=function(t,e,i,n){return Math.sqrt((i-t)*(i-t)+(n-e)*(n-e))},pi.getPointOnLine=function(t,e,i,n,r,o,a){void 0===o&&(o=e),void 0===a&&(a=i);var s=(r-i)/(n-e+1e-8),h=Math.sqrt(t*t/(1+s*s));n>>1,k=_.slice(0,1+P),T=this._getTextWidth(k)+v;T<=l?(b=1+P,w=k+(g?"…":""),C=T):x=P}if(!w)break;if(f){var A,M=_[w.length];0<(A=(" "===M||"-"===M)&&C<=l?w.length:Math.max(w.lastIndexOf(" "),w.lastIndexOf("-"))+1)&&(b=A,w=w.slice(0,b),C=this._getTextWidth(w))}if(w=w.trimRight(),this._addTextLine(w),i=Math.max(i,C),c+=n,!u||s&&de?g=ci.getPointOnLine(e,f.x,f.y,v.points[0],v.points[1],f.x,f.y):v=void 0;break;case"A":var a=v.points[4],s=v.points[5],h=v.points[4]+s;0===m?m=a+1e-8:iv.pathLength?1e-8:e/v.pathLength:ithis.findOne(".bottom-right").x()?-1:1,l=this.findOne(".top-left").y()>this.findOne(".bottom-right").y()?-1:1;e=n*this.cos*h,i=n*this.sin*l,this.findOne(".top-left").x(this.findOne(".bottom-right").x()-e-2*s),this.findOne(".top-left").y(this.findOne(".bottom-right").y()-i-2*s)}}else if("top-center"===this._movingAnchorName)this.findOne(".top-left").y(r.y());else if("top-right"===this._movingAnchorName){a&&(n=Math.sqrt(Math.pow(r.x()-this.findOne(".bottom-left").x()-2*s,2)+Math.pow(this.findOne(".bottom-left").y()-r.y()-2*s,2)),h=this.findOne(".top-right").x()this.findOne(".bottom-left").y()?-1:1,e=n*this.cos*h,i=n*this.sin*l,this.findOne(".top-right").x(e+s),this.findOne(".top-right").y(this.findOne(".bottom-left").y()-i-2*s));var d=r.position();this.findOne(".top-left").y(d.y),this.findOne(".bottom-right").x(d.x)}else if("middle-left"===this._movingAnchorName)this.findOne(".top-left").x(r.x());else if("middle-right"===this._movingAnchorName)this.findOne(".bottom-right").x(r.x());else if("bottom-left"===this._movingAnchorName)a&&(n=Math.sqrt(Math.pow(this.findOne(".top-right").x()-r.x()-2*s,2)+Math.pow(r.y()-this.findOne(".top-right").y()-2*s,2)),h=this.findOne(".top-right").x()this.findOne(".bottom-right").x()?-1:1,l=this.findOne(".top-left").y()>this.findOne(".bottom-right").y()?-1:1,e=n*this.cos*h,i=n*this.sin*l,this.findOne(".bottom-right").x(e+s),this.findOne(".bottom-right").y(i+s));else if("rotater"===this._movingAnchorName){var c=this._getNodeRect();e=r.x()-c.width/2,i=-r.y()+c.height/2;var p=Math.atan2(-i,e)+Math.PI/2;c.height<0&&(p-=Math.PI);for(var u=R.getAngle(this.rotation()),f=O._radToDeg(u)+O._radToDeg(p),g=R.getAngle(this.getNode().rotation()),v=O._degToRad(f),y=this.rotationSnaps(),m=0;m>N,0!==C?(C=255/C,k[s]=(l*z>>N)*C,k[s+1]=(d*z>>N)*C,k[s+2]=(c*z>>N)*C):k[s]=k[s+1]=k[s+2]=0,l-=u,d-=f,c-=g,p-=v,u-=F.r,f-=F.g,g-=F.b,v-=F.a,o=h+((o=i+e+1)>N,0>N)*C,k[o+1]=(d*z>>N)*C,k[o+2]=(c*z>>N)*C):k[o]=k[o+1]=k[o+2]=0,l-=u,d-=f,c-=g,p-=v,u-=F.r,f-=F.g,g-=F.b,v-=F.a,o=i+((o=n+O) { } } _getAbsoluteTransform(top?: Node) { - var at; // we we need position relative to an ancestor, we will iterate for all if (top) { @@ -1691,10 +1690,7 @@ export abstract class Node { if (transformsEnabled === 'all') { at.multiply(node.getTransform()); } else if (transformsEnabled === 'position') { - at.translate( - node.x() - node.offsetX(), - node.y() - node.offsetY() - ); + at.translate(node.x() - node.offsetX(), node.y() - node.offsetY()); } }, top); return at; @@ -1710,10 +1706,7 @@ export abstract class Node { if (transformsEnabled === 'all') { at.multiply(this.getTransform()); } else if (transformsEnabled === 'position') { - at.translate( - this.x() - this.offsetX(), - this.y() - this.offsetY() - ); + at.translate(this.x() - this.offsetX(), this.y() - this.offsetY()); } return at; } @@ -1844,11 +1837,6 @@ export abstract class Node { len, n, listener; - // filter black attrs - for (var i in CLONE_BLACK_LIST) { - var blockAttr = CLONE_BLACK_LIST[i]; - delete attrs[blockAttr]; - } // apply attr overrides for (key in obj) { attrs[key] = obj[key]; @@ -2244,10 +2232,10 @@ export abstract class Node { // simulate event bubbling var stopBubble = (eventType === MOUSEENTER || eventType === MOUSELEAVE) && - (compareShape && + compareShape && compareShape.isAncestorOf && compareShape.isAncestorOf(this) && - !compareShape.isAncestorOf(this.parent)); + !compareShape.isAncestorOf(this.parent); if ( ((evt && !evt.cancelBubble) || !evt) && this.parent && diff --git a/test/unit/Node-test.js b/test/unit/Node-test.js index 9e00417c..c24a07df 100644 --- a/test/unit/Node-test.js +++ b/test/unit/Node-test.js @@ -560,7 +560,7 @@ suite('Node', function() { assert.equal(rect.getShadowColor(), 'black'); assert.equal(clone.getShadowColor(), 'black'); - assert.equal(clone.id() == '', true, 'do not clone id'); + assert.equal(clone.id() === 'myRect', true, 'clone id'); clone.setShadowColor('green');