diff --git a/konva.js b/konva.js index f1859160..68c8fb4a 100644 --- a/konva.js +++ b/konva.js @@ -29,35 +29,6 @@ /* comment */ }.toString()); var dblClickWindow = 400; - /** - * returns whether or not drag and drop is currently active - * @method - * @memberof Konva - */ - var isDragging = function () { - var dd = getGlobalKonva()['DD']; - // if DD is not included with the build, then - // drag and drop is not even possible - if (dd) { - return dd.isDragging; - } - return false; - }; - /** - * returns whether or not a drag and drop operation is ready, but may - * not necessarily have started - * @method - * @memberof Konva - */ - var isDragReady = function () { - var dd = getGlobalKonva()['DD']; - // if DD is not included with the build, then - // drag and drop is not even possible - if (dd) { - return !!dd.node; - } - return false; - }; var getAngle = function (angle) { return getGlobalKonva().angleDeg ? angle * PI_OVER_180 : angle; }; @@ -5008,8 +4979,8 @@ child: child }); // if node under drag we need to update drag animation - if (getGlobalKonva().DD && child.isDragging()) { - getGlobalKonva().DD.anim.setLayers(child.getLayer()); + if (child.isDragging()) { + DD.anim.setLayers(child.getLayer()); } // chainable return this; @@ -5328,11 +5299,8 @@ }; Container.prototype.shouldDrawHit = function (canvas) { var layer = this.getLayer(); - var dd = getGlobalKonva().DD; - var layerUnderDrag = dd && - getGlobalKonva().isDragging() && - getGlobalKonva() - .DD.anim.getLayers() + var layerUnderDrag = DD.isDragging && + DD.anim.getLayers() .indexOf(layer) !== -1; return ((canvas && canvas.isCache) || (layer && layer.hitGraphEnabled() && this.isVisible() && !layerUnderDrag)); @@ -5798,7 +5766,7 @@ Stage.prototype._mouseout = function (evt) { this.setPointersPositions(evt); var targetShape = this.targetShape; - if (targetShape && !getGlobalKonva().isDragging()) { + if (targetShape && !DD.isDragging) { targetShape._fireAndBubble(MOUSEOUT, { evt: evt }); targetShape._fireAndBubble(MOUSELEAVE$1, { evt: evt }); this.targetShape = null; @@ -5813,11 +5781,11 @@ } this.setPointersPositions(evt); var shape; - if (!getGlobalKonva().isDragging()) { + if (!DD.isDragging) { shape = this.getIntersection(this.getPointerPosition()); if (shape && shape.isListening()) { var differentTarget = !this.targetShape || this.targetShape !== shape; - if (!getGlobalKonva().isDragging() && differentTarget) { + if (!DD.isDragging && differentTarget) { if (this.targetShape) { this.targetShape._fireAndBubble(MOUSEOUT, { evt: evt }, shape); this.targetShape._fireAndBubble(MOUSELEAVE$1, { evt: evt }, shape); @@ -5835,7 +5803,7 @@ * if no shape was detected, clear target shape and try * to run mouseout from previous target shape */ - if (this.targetShape && !getGlobalKonva().isDragging()) { + if (this.targetShape && !DD.isDragging) { this.targetShape._fireAndBubble(MOUSEOUT, { evt: evt }); this.targetShape._fireAndBubble(MOUSELEAVE$1, { evt: evt }); this._fire(MOUSEOVER, { @@ -6046,7 +6014,7 @@ Stage.prototype._touchmove = function (evt) { this.setPointersPositions(evt); var dd = getGlobalKonva().DD, shape; - if (!getGlobalKonva().isDragging()) { + if (!DD.isDragging) { shape = this.getIntersection(this.getPointerPosition()); if (shape && shape.isListening()) { shape._fireAndBubble(TOUCHMOVE, { evt: evt }); @@ -6065,7 +6033,7 @@ this._fire(CONTENT_TOUCHMOVE, { evt: evt }); } if (dd) { - if (getGlobalKonva().isDragging() && + if (DD.isDragging && getGlobalKonva().DD.node.preventDefault() && evt.cancelable) { evt.preventDefault(); @@ -16946,6 +16914,7 @@ * @returns {Number} */ + var DD$1 = DD; var enableTrace = false; // TODO: move that to stage? var listenClickTap = false; @@ -17002,6 +16971,23 @@ * Konva.dragButtons = [0, 2]; */ var dragButtons = [0, 1]; + /** + * returns whether or not drag and drop is currently active + * @method + * @memberof Konva + */ + var isDragging = function () { + return DD.isDragging; + }; + /** + * returns whether or not a drag and drop operation is ready, but may + * not necessarily have started + * @method + * @memberof Konva + */ + var isDragReady = function () { + return !!DD.node; + }; /** * @namespace Filters * @memberof Konva @@ -17029,6 +17015,7 @@ }; var Konva = ({ + DD: DD$1, enableTrace: enableTrace, listenClickTap: listenClickTap, inDblClickWindow: inDblClickWindow, @@ -17037,6 +17024,8 @@ angleDeg: angleDeg, showWarnings: showWarnings, dragButtons: dragButtons, + isDragging: isDragging, + isDragReady: isDragReady, Filters: Filters, Collection: Collection, Util: Util, @@ -17049,7 +17038,6 @@ Layer: Layer, FastLayer: FastLayer, Group: Group, - DD: DD, Shape: Shape, shapes: shapes, Animation: Animation, @@ -17077,10 +17065,7 @@ isBrowser: isBrowser, isUnminified: isUnminified, dblClickWindow: dblClickWindow, - isDragging: isDragging, - isDragReady: isDragReady, getAngle: getAngle, - _detectIE: _detectIE, _parseUA: _parseUA, glob: glob, UA: UA, diff --git a/konva.min.js b/konva.min.js index 1897e936..0b9ec460 100644 --- a/konva.min.js +++ b/konva.min.js @@ -9,4 +9,4 @@ * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) * * @license - */var e=Math.PI/180,n="undefined"!=typeof window&&("[object Window]"==={}.toString.call(window)||"[object global]"==={}.toString.call(window)),t=/comment/.test(function(){}.toString()),L=function(t){return D().angleDeg?t*e:t},a=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=f.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)},_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}},haveIntersection:function(t,e){return!(e.x>t.x+t.width||e.x+e.widtht.y+t.height||e.y+e.heighte.length){var o=e;e=t,t=o}for(r=0;r=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},s.prototype.getAbsoluteOpacity=function(){return this._getCache(V,this._getAbsoluteOpacity)},s.prototype._getAbsoluteOpacity=function(){var t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=this.getParent().getAbsoluteOpacity()),t},s.prototype.moveTo=function(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this},s.prototype.toObject=function(){var t,e,i,r={},n=this.getAttrs();for(t in r.attrs={},n)e=n[t],O.isObject(e)&&!O._isPlainObject(e)&&!O._isArray(e)||(i="function"==typeof this[t]&&this[t],delete n[t],(i?i.call(this):null)!==(n[t]=e)&&(r.attrs[t]=e));return r.className=this.getClassName(),O._prepareToStringify(r)},s.prototype.toJSON=function(){return JSON.stringify(this.toObject())},s.prototype.getParent=function(){return this.parent},s.prototype.findAncestors=function(t,e,i){var r=[];e&&this._isMatch(t)&&r.push(this);for(var n=this.parent;n;){if(n===i)return r;n._isMatch(t)&&r.push(n),n=n.parent}return r},s.prototype.isAncestorOf=function(t){return!1},s.prototype.findAncestor=function(t,e,i){return this.findAncestors(t,e,i)[0]},s.prototype._isMatch=function(t){if(!t)return!1;var e,i,r=t.replace(/ /g,"").split(","),n=r.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())},t.prototype.getTime=function(){return this._time},t.prototype.setPosition=function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},t.prototype.getPosition=function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},t.prototype.play=function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},t.prototype.reverse=function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},t.prototype.seek=function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},t.prototype.reset=function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},t.prototype.finish=function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},t.prototype.update=function(){this.setPosition(this.getPosition(this._time))},t.prototype.onEnterFrame=function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},t.prototype.pause=function(){this.state=1,this.fire("onPause")},t.prototype.getTimer=function(){return(new Date).getTime()},t}(),Xt=function(){function p(t){var e,i,r=this,n=t.node,a=n._id,o=t.easing||jt.Linear,s=!!t.yoyo;e=void 0===t.duration?.3:0===t.duration?.001:t.duration,this.node=n,this._id=Ht++;var h=n.getLayer()||(n instanceof D().Stage?n.getLayers():null);for(i in h||O.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new R(function(){r.tween.onEnterFrame()},h),this.tween=new Yt(i,function(t){r._tweenFunc(t)},o,0,1,1e3*e,s),this._addListeners(),p.attrs[a]||(p.attrs[a]={}),p.attrs[a][this._id]||(p.attrs[a][this._id]={}),p.tweens[a]||(p.tweens[a]={}),t)void 0===zt[i]&&this._addAttr(i,t[i]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset}return p.prototype._addAttr=function(t,e){var i,r,n,a,o,s,h,l,d=this.node,c=d._id;if((n=p.tweens[c][t])&&delete p.attrs[c][n][t],i=d.getAttr(t),O._isArray(e))if(r=[],o=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(a=0;athis.dataArray[i].pathLength;)t-=this.dataArray[i].pathLength,++i;if(i===r)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 n=this.dataArray[i],a=n.points;switch(n.command){case"L":return p.getPointOnLine(t,n.start.x,n.start.y,a[0],a[1]);case"C":return p.getPointOnCubicBezier(t/n.pathLength,n.start.x,n.start.y,a[0],a[1],a[2],a[3],a[4],a[5]);case"Q":return p.getPointOnQuadraticBezier(t/n.pathLength,n.start.x,n.start.y,a[0],a[1],a[2],a[3]);case"A":var o=a[0],s=a[1],h=a[2],l=a[3],d=a[4],c=a[5],u=a[6];return d+=c*t/n.pathLength,p.getPointOnEllipticalArc(o,s,h,l,d,u)}return null},p.getLineLength=function(t,e,i,r){return Math.sqrt((i-t)*(i-t)+(r-e)*(r-e))},p.getPointOnLine=function(t,e,i,r,n,a,o){void 0===a&&(a=e),void 0===o&&(o=i);var s=(n-i)/(r-e+1e-8),h=Math.sqrt(t*t/(1+s*s));r>>1,P=_.slice(0,k+1),T=this._getTextWidth(P)+v;T<=l?(S=k+1,w=P+(g?"…":""),C=T):x=k}if(!w)break;if(f){var M,A=_[w.length];0<(M=(" "===A||"-"===A)&&C<=l?w.length:Math.max(w.lastIndexOf(" "),w.lastIndexOf("-"))+1)&&(S=M,w=w.slice(0,S),C=this._getTextWidth(w))}if(w=w.trimRight(),this._addTextLine(w),i=Math.max(i,C),c+=r,!p||s&&de?g=oe.getPointOnLine(e,f.x,f.y,v.points[0],v.points[1],f.x,f.y):v=void 0;break;case"A":var o=v.points[4],s=v.points[5],h=v.points[4]+s;0===m?m=o+1e-8:iv.pathLength?1e-8:e/v.pathLength:i>V,0!==C?(C=255/C,P[s]=(l*B>>V)*C,P[s+1]=(d*B>>V)*C,P[s+2]=(c*B>>V)*C):P[s]=P[s+1]=P[s+2]=0,l-=p,d-=f,c-=g,u-=v,p-=F.r,f-=F.g,g-=F.b,v-=F.a,a=h+((a=i+e+1)>V,0>V)*C,P[a+1]=(d*B>>V)*C,P[a+2]=(c*B>>V)*C):P[a]=P[a+1]=P[a+2]=0,l-=p,d-=f,c-=g,u-=v,p-=F.r,f-=F.g,g-=F.b,v-=F.a,a=i+((a=r+L)>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 u?{r:(e=u[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=p.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",D._namedColorToRBA(t)||D._hex3ColorToRGBA(t)||D._hex6ColorToRGBA(t)||D._rgbColorToRGBA(t)||D._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(")){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}},haveIntersection:function(t,e){return!(e.x>t.x+t.width||e.x+e.widtht.y+t.height||e.y+e.heighte.length){var o=e;e=t,t=o}for(r=0;r=this.parent.children.length)&&D.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},s.prototype.getAbsoluteOpacity=function(){return this._getCache(B,this._getAbsoluteOpacity)},s.prototype._getAbsoluteOpacity=function(){var t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=this.getParent().getAbsoluteOpacity()),t},s.prototype.moveTo=function(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this},s.prototype.toObject=function(){var t,e,i,r={},n=this.getAttrs();for(t in r.attrs={},n)e=n[t],D.isObject(e)&&!D._isPlainObject(e)&&!D._isArray(e)||(i="function"==typeof this[t]&&this[t],delete n[t],(i?i.call(this):null)!==(n[t]=e)&&(r.attrs[t]=e));return r.className=this.getClassName(),D._prepareToStringify(r)},s.prototype.toJSON=function(){return JSON.stringify(this.toObject())},s.prototype.getParent=function(){return this.parent},s.prototype.findAncestors=function(t,e,i){var r=[];e&&this._isMatch(t)&&r.push(this);for(var n=this.parent;n;){if(n===i)return r;n._isMatch(t)&&r.push(n),n=n.parent}return r},s.prototype.isAncestorOf=function(t){return!1},s.prototype.findAncestor=function(t,e,i){return this.findAncestors(t,e,i)[0]},s.prototype._isMatch=function(t){if(!t)return!1;var e,i,r=t.replace(/ /g,"").split(","),n=r.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())},t.prototype.getTime=function(){return this._time},t.prototype.setPosition=function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},t.prototype.getPosition=function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},t.prototype.play=function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},t.prototype.reverse=function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},t.prototype.seek=function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},t.prototype.reset=function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},t.prototype.finish=function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},t.prototype.update=function(){this.setPosition(this.getPosition(this._time))},t.prototype.onEnterFrame=function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},t.prototype.pause=function(){this.state=1,this.fire("onPause")},t.prototype.getTimer=function(){return(new Date).getTime()},t}(),Yt=function(){function p(t){var e,i,r=this,n=t.node,a=n._id,o=t.easing||Xt.Linear,s=!!t.yoyo;e=void 0===t.duration?.3:0===t.duration?.001:t.duration,this.node=n,this._id=zt++;var h=n.getLayer()||(n instanceof O().Stage?n.getLayers():null);for(i in h||D.error("Tween constructor have `node` that is not in a layer. Please add node into layer first."),this.anim=new G(function(){r.tween.onEnterFrame()},h),this.tween=new Wt(i,function(t){r._tweenFunc(t)},o,0,1,1e3*e,s),this._addListeners(),p.attrs[a]||(p.attrs[a]={}),p.attrs[a][this._id]||(p.attrs[a][this._id]={}),p.tweens[a]||(p.tweens[a]={}),t)void 0===Vt[i]&&this._addAttr(i,t[i]);this.reset(),this.onFinish=t.onFinish,this.onReset=t.onReset}return p.prototype._addAttr=function(t,e){var i,r,n,a,o,s,h,l,d=this.node,c=d._id;if((n=p.tweens[c][t])&&delete p.attrs[c][n][t],i=d.getAttr(t),D._isArray(e))if(r=[],o=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(h=i,i=D._prepareArrayForTween(i,e,d.closed())):(s=e,e=D._prepareArrayForTween(e,i,d.closed()))),0===t.indexOf("fill"))for(a=0;athis.dataArray[i].pathLength;)t-=this.dataArray[i].pathLength,++i;if(i===r)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 n=this.dataArray[i],a=n.points;switch(n.command){case"L":return p.getPointOnLine(t,n.start.x,n.start.y,a[0],a[1]);case"C":return p.getPointOnCubicBezier(t/n.pathLength,n.start.x,n.start.y,a[0],a[1],a[2],a[3],a[4],a[5]);case"Q":return p.getPointOnQuadraticBezier(t/n.pathLength,n.start.x,n.start.y,a[0],a[1],a[2],a[3]);case"A":var o=a[0],s=a[1],h=a[2],l=a[3],d=a[4],c=a[5],u=a[6];return d+=c*t/n.pathLength,p.getPointOnEllipticalArc(o,s,h,l,d,u)}return null},p.getLineLength=function(t,e,i,r){return Math.sqrt((i-t)*(i-t)+(r-e)*(r-e))},p.getPointOnLine=function(t,e,i,r,n,a,o){void 0===a&&(a=e),void 0===o&&(o=i);var s=(n-i)/(r-e+1e-8),h=Math.sqrt(t*t/(1+s*s));r>>1,P=_.slice(0,k+1),T=this._getTextWidth(P)+v;T<=l?(S=k+1,w=P+(g?"…":""),C=T):x=k}if(!w)break;if(f){var M,A=_[w.length];0<(M=(" "===A||"-"===A)&&C<=l?w.length:Math.max(w.lastIndexOf(" "),w.lastIndexOf("-"))+1)&&(S=M,w=w.slice(0,S),C=this._getTextWidth(w))}if(w=w.trimRight(),this._addTextLine(w),i=Math.max(i,C),c+=r,!p||s&&de?g=ae.getPointOnLine(e,f.x,f.y,v.points[0],v.points[1],f.x,f.y):v=void 0;break;case"A":var o=v.points[4],s=v.points[5],h=v.points[4]+s;0===m?m=o+1e-8:iv.pathLength?1e-8:e/v.pathLength:i>V,0!==C?(C=255/C,P[s]=(l*B>>V)*C,P[s+1]=(d*B>>V)*C,P[s+2]=(c*B>>V)*C):P[s]=P[s+1]=P[s+2]=0,l-=p,d-=f,c-=g,u-=v,p-=F.r,f-=F.g,g-=F.b,v-=F.a,a=h+((a=i+e+1)>V,0>V)*C,P[a+1]=(d*B>>V)*C,P[a+2]=(c*B>>V)*C):P[a]=P[a+1]=P[a+2]=0,l-=p,d-=f,c-=g,u-=v,p-=F.r,f-=F.g,g-=F.b,v-=F.a,a=i+((a=r+L) 0) { // IE 10 or older => return version number @@ -89,6 +57,7 @@ export const _detectIE = function(ua) { // other browser return false; }; + export const _parseUA = function(userAgent) { var ua = userAgent.toLowerCase(), // jQuery UA regex diff --git a/src/Stage.ts b/src/Stage.ts index 1b2fdf24..8e8b10d9 100644 --- a/src/Stage.ts +++ b/src/Stage.ts @@ -6,6 +6,7 @@ import { SceneCanvas, HitCanvas } from './Canvas'; import { GetSet, Vector2d } from './types'; import { Shape } from './Shape'; import { BaseLayer } from './BaseLayer'; +import { DD } from './DragAndDrop'; // CONSTANTS var STAGE = 'Stage', @@ -379,7 +380,7 @@ export class Stage extends Container { this.setPointersPositions(evt); var targetShape = this.targetShape; - if (targetShape && !getGlobalKonva().isDragging()) { + if (targetShape && !DD.isDragging) { targetShape._fireAndBubble(MOUSEOUT, { evt: evt }); targetShape._fireAndBubble(MOUSELEAVE, { evt: evt }); this.targetShape = null; @@ -396,11 +397,11 @@ export class Stage extends Container { this.setPointersPositions(evt); var shape; - if (!getGlobalKonva().isDragging()) { + if (!DD.isDragging) { shape = this.getIntersection(this.getPointerPosition()); if (shape && shape.isListening()) { var differentTarget = !this.targetShape || this.targetShape !== shape; - if (!getGlobalKonva().isDragging() && differentTarget) { + if (!DD.isDragging && differentTarget) { if (this.targetShape) { this.targetShape._fireAndBubble(MOUSEOUT, { evt: evt }, shape); this.targetShape._fireAndBubble(MOUSELEAVE, { evt: evt }, shape); @@ -416,7 +417,7 @@ export class Stage extends Container { * if no shape was detected, clear target shape and try * to run mouseout from previous target shape */ - if (this.targetShape && !getGlobalKonva().isDragging()) { + if (this.targetShape && !DD.isDragging) { this.targetShape._fireAndBubble(MOUSEOUT, { evt: evt }); this.targetShape._fireAndBubble(MOUSELEAVE, { evt: evt }); this._fire(MOUSEOVER, { @@ -653,7 +654,7 @@ export class Stage extends Container { this.setPointersPositions(evt); var dd = getGlobalKonva().DD, shape; - if (!getGlobalKonva().isDragging()) { + if (!DD.isDragging) { shape = this.getIntersection(this.getPointerPosition()); if (shape && shape.isListening()) { shape._fireAndBubble(TOUCHMOVE, { evt: evt }); @@ -672,7 +673,7 @@ export class Stage extends Container { } if (dd) { if ( - getGlobalKonva().isDragging() && + DD.isDragging && getGlobalKonva().DD.node.preventDefault() && evt.cancelable ) { diff --git a/src/internals.ts b/src/internals.ts index 7812bf08..172b83db 100644 --- a/src/internals.ts +++ b/src/internals.ts @@ -11,7 +11,9 @@ export { FastLayer } from './FastLayer'; export { Group } from './Group'; -export { DD } from './DragAndDrop'; +import { DD as dd } from './DragAndDrop'; + +export const DD = dd; export { Shape, shapes } from './Shape'; export { Animation } from './Animation'; @@ -78,7 +80,23 @@ export const showWarnings = true; */ export const dragButtons = [0, 1]; -// export default KonvaInternals; +/** + * returns whether or not drag and drop is currently active + * @method + * @memberof Konva + */ +export const isDragging = function() { + return dd.isDragging; +}; +/** + * returns whether or not a drag and drop operation is ready, but may + * not necessarily have started + * @method + * @memberof Konva + */ +export const isDragReady = function() { + return !!dd.node; +}; // shapes export { Arc } from './shapes/Arc';