diff --git a/konva.js b/konva.js index bd61e1f1..613deb2f 100644 --- a/konva.js +++ b/konva.js @@ -2,7 +2,7 @@ * Konva JavaScript Framework v2.0.3 * http://konvajs.github.io/ * Licensed under the MIT - * Date: Fri May 04 2018 + * Date: Mon May 07 2018 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) @@ -10636,6 +10636,7 @@ } else if (!dd || !dd.justDragged) { // don't set inDblClickWindow after dragging Konva.inDblClickWindow = true; + clearTimeout(this.dblTimeout); } else if (dd) { dd.justDragged = false; } @@ -10743,6 +10744,7 @@ // Konva.inDblClickWindow = false; } else { Konva.inDblClickWindow = true; + clearTimeout(this.dblTimeout); } this.dblTimeout = setTimeout(function() { @@ -18706,7 +18708,6 @@ * primitives and shapes. * @constructor * @memberof Konva - * @augments Konva.Container * @param {Object} config * @param {Boolean} [config.resizeEnabled] Default is true * @param {Boolean} [config.rotateEnabled] Default is true @@ -18716,33 +18717,6 @@ * @param {Number} [config.lineEnabled] Should we draw border? Default is true * @param {Boolean} [config.keepRatio] Should we keep ratio when we are moving edges? Default is true * @param {Array} [config.enabledHandlers] Array of names of enabled handles - * @param {Number} [config.x] - * @param {Number} [config.y] - * @param {Number} [config.width] - * @param {Number} [config.height] - * @param {Boolean} [config.visible] - * @param {Boolean} [config.listening] whether or not the node is listening for events - * @param {String} [config.id] unique id - * @param {String} [config.name] non-unique name - * @param {Number} [config.opacity] determines node opacity. Can be any number between 0 and 1 - * @param {Object} [config.scale] set scale - * @param {Number} [config.scaleX] set scale x - * @param {Number} [config.scaleY] set scale y - * @param {Number} [config.rotation] rotation in degrees - * @param {Object} [config.offset] offset from center point and rotation point - * @param {Number} [config.offsetX] set offset x - * @param {Number} [config.offsetY] set offset y - * @param {Boolean} [config.draggable] makes the node draggable. When stages are draggable, you can drag and drop - * the entire stage by dragging any portion of the stage - * @param {Number} [config.dragDistance] - * @param {Function} [config.dragBoundFunc] - * * @param {Object} [config.clip] set clip - * @param {Number} [config.clipX] set clip x - * @param {Number} [config.clipY] set clip y - * @param {Number} [config.clipWidth] set clip width - * @param {Number} [config.clipHeight] set clip height - * @param {Function} [config.clipFunc] set clip func - * @example * var transformer = new Konva.Transformer({ * node: rectangle, @@ -18801,6 +18775,14 @@ this.setNode(node); }, + /** + * attach transformer to a Konva.Node. Transformer will adapt it its size and listed events + * @method + * @memberof Konva.Transformer.prototype + * @returns {Konva.Transformer} + * @example + * transformer.attachTo(shape); + */ setNode: function(node) { if (this._node) { this.detach(); @@ -18816,19 +18798,27 @@ this._clearSelfAndDescendantCache('absoluteTransform'); }.bind(this) ); - // node.on(TRANSFORM_CHANGE_STR, this.requestUpdate.bind(this)); - // node.on('dragmove.resizer', this.requestUpdate.bind(this)); + // TODO: why do we need this? var elementsCreated = !!this.findOne('.top-left'); if (elementsCreated) { this.update(); } + return this; }, getNode: function() { return this._node; }, + /** + * detach transformer from a attached node + * @method + * @memberof Konva.Transformer.prototype + * @returns {Konva.Transformer} + * @example + * transformer.detach(); + */ detach: function() { if (this.getNode()) { this.getNode().off('.resizer'); @@ -19245,21 +19235,9 @@ this.update(); this.getLayer().batchDraw(); }, - - requestUpdate: function() { - if (this.timeout) { - return; - } - this.timeout = setTimeout( - function() { - this.timeout = null; - this.update(); - }.bind(this) - ); - }, - /** - * force update of Transformer + * force update of Konva.Transformer. + * Use it when you updated attached Konva.Group and now you need to reset transformer size * @method * @memberof Konva.Transformer.prototype */ @@ -19329,9 +19307,21 @@ visible: this.lineEnabled() }); }, + /** + * determine if transformer is in active transform + * @method + * @memberof Konva.Transformer.prototype + * @returns {Boolean} + */ isTransforming: function() { return this._transforming; }, + /** + * Stop active transform action + * @method + * @memberof Konva.Transformer.prototype + * @returns {Boolean} + */ stopTransform: function() { if (this._transforming) { this._removeEvents(); diff --git a/konva.min.js b/konva.min.js index 2597566e..d19b17cd 100644 --- a/konva.min.js +++ b/konva.min.js @@ -2,7 +2,7 @@ * Konva JavaScript Framework v2.0.3 * http://konvajs.github.io/ * Licensed under the MIT - * Date: Fri May 04 2018 + * Date: Mon May 07 2018 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) @@ -23,4 +23,4 @@ * @example * node.cache(); * node.filters([Konva.Filters.Sepia]); - */Konva.Filters.Sepia=function(t){var e,n,i,a,r,o,s,h,c,l=t.data,d=t.width,u=t.height,f=4*d;do{for(e=(u-1)*f,n=d;s=.393*(a=l[i=e+4*(n-1)])+.769*(r=l[i+1])+.189*(o=l[i+2]),h=.349*a+.686*r+.168*o,c=.272*a+.534*r+.131*o,l[i]=255this.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())},getTime:function(){return this._time},setPosition:function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},getPosition:function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},play:function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},reverse:function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},seek:function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},reset:function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},finish:function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},update:function(){this.setPosition(this.getPosition(this._time))},onEnterFrame:function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},pause:function(){this.state=1,this.fire("onPause")},getTimer:function(){return(new Date).getTime()}},Konva.Tween=function(t){var e,n,i=this,a=t.node,r=a._id,o=t.easing||Konva.Easings.Linear,s=!!t.yoyo;e=void 0===t.duration?1:0===t.duration?.001:t.duration,this.node=a,this._id=l++;var h=a.getLayer()||(a instanceof Konva.Stage?a.getLayers():null);for(n in h||Konva.Util.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new Konva.Animation(function(){i.tween.onEnterFrame()},h),this.tween=new d(n,function(t){i._tweenFunc(t)},o,0,1,1e3*e,s),this._addListeners(),Konva.Tween.attrs[r]||(Konva.Tween.attrs[r]={}),Konva.Tween.attrs[r][this._id]||(Konva.Tween.attrs[r][this._id]={}),Konva.Tween.tweens[r]||(Konva.Tween.tweens[r]={}),t)void 0===c[n]&&this._addAttr(n,t[n]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset},Konva.Tween.attrs={},Konva.Tween.tweens={},Konva.Tween.prototype={_addAttr:function(t,e){var n,i,a,r,o,s,h,c=this.node,l=c._id;if((a=Konva.Tween.tweens[l][t])&&delete Konva.Tween.attrs[l][a][t],n=c.getAttr(t),Konva.Util._isArray(e))for(i=[],o=Math.max(e.length,n.length),"points"===t&&e.length!==n.length&&(e.length>n.length?(h=n,n=Konva.Util._prepareArrayForTween(n,e,c.closed())):(s=e,e=Konva.Util._prepareArrayForTween(e,n,c.closed()))),r=0;r>>1,F=_.slice(0,w+1),T=this._getTextWidth(F)+y;T<=c?(K=w+1,C=F+(v?"…":""),b=T):x=w}if(!C)break;if(g){var P,A=_[C.length];0<(P=(" "===A||"-"===A)&&b<=c?C.length:Math.max(C.lastIndexOf(" "),C.lastIndexOf("-"))+1)&&(K=P,C=C.slice(0,K),b=this._getTextWidth(C))}if(this._addTextLine(C),n=Math.max(n,b),d+=i,!f||s&&le?v=Konva.Path.getPointOnLine(e,g.x,g.y,p.points[0],p.points[1],g.x,g.y):p=void 0;break;case"A":var o=p.points[4],s=p.points[5],h=p.points[4]+s;0===_?_=o+1e-8:np.pathLength?1e-8:e/p.pathLength:nthis.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())},getTime:function(){return this._time},setPosition:function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},getPosition:function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},play:function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},reverse:function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},seek:function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},reset:function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},finish:function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},update:function(){this.setPosition(this.getPosition(this._time))},onEnterFrame:function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},pause:function(){this.state=1,this.fire("onPause")},getTimer:function(){return(new Date).getTime()}},Konva.Tween=function(t){var e,n,i=this,a=t.node,r=a._id,o=t.easing||Konva.Easings.Linear,s=!!t.yoyo;e=void 0===t.duration?1:0===t.duration?.001:t.duration,this.node=a,this._id=l++;var h=a.getLayer()||(a instanceof Konva.Stage?a.getLayers():null);for(n in h||Konva.Util.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new Konva.Animation(function(){i.tween.onEnterFrame()},h),this.tween=new d(n,function(t){i._tweenFunc(t)},o,0,1,1e3*e,s),this._addListeners(),Konva.Tween.attrs[r]||(Konva.Tween.attrs[r]={}),Konva.Tween.attrs[r][this._id]||(Konva.Tween.attrs[r][this._id]={}),Konva.Tween.tweens[r]||(Konva.Tween.tweens[r]={}),t)void 0===c[n]&&this._addAttr(n,t[n]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset},Konva.Tween.attrs={},Konva.Tween.tweens={},Konva.Tween.prototype={_addAttr:function(t,e){var n,i,a,r,o,s,h,c=this.node,l=c._id;if((a=Konva.Tween.tweens[l][t])&&delete Konva.Tween.attrs[l][a][t],n=c.getAttr(t),Konva.Util._isArray(e))for(i=[],o=Math.max(e.length,n.length),"points"===t&&e.length!==n.length&&(e.length>n.length?(h=n,n=Konva.Util._prepareArrayForTween(n,e,c.closed())):(s=e,e=Konva.Util._prepareArrayForTween(e,n,c.closed()))),r=0;r>>1,F=_.slice(0,w+1),T=this._getTextWidth(F)+y;T<=c?(K=w+1,C=F+(v?"…":""),b=T):x=w}if(!C)break;if(g){var P,A=_[C.length];0<(P=(" "===A||"-"===A)&&b<=c?C.length:Math.max(C.lastIndexOf(" "),C.lastIndexOf("-"))+1)&&(K=P,C=C.slice(0,K),b=this._getTextWidth(C))}if(this._addTextLine(C),n=Math.max(n,b),d+=i,!f||s&&le?v=Konva.Path.getPointOnLine(e,g.x,g.y,p.points[0],p.points[1],g.x,g.y):p=void 0;break;case"A":var o=p.points[4],s=p.points[5],h=p.points[4]+s;0===_?_=o+1e-8:np.pathLength?1e-8:e/p.pathLength:n