@daybrush/drag
Advanced tools
Comparing version 0.14.0-rc2 to 0.14.0-rc3
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/drag.git | ||
version: 0.14.0-rc2 | ||
version: 0.14.0-rc3 | ||
*/ | ||
@@ -276,3 +276,3 @@ 'use strict'; | ||
var elements = [].slice.call(targets); | ||
var elements = [].concat(targets); | ||
this.options = __assign({ | ||
@@ -279,0 +279,0 @@ container: elements.length > 1 ? window : elements[0], |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/drag.git | ||
version: 0.14.0-rc2 | ||
version: 0.14.0-rc3 | ||
*/ | ||
@@ -274,3 +274,3 @@ import { removeEvent, addEvent } from '@daybrush/utils'; | ||
var elements = [].slice.call(targets); | ||
var elements = [].concat(targets); | ||
this.options = __assign({ | ||
@@ -277,0 +277,0 @@ container: elements.length > 1 ? window : elements[0], |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/drag.git | ||
version: 0.14.0-rc2 | ||
version: 0.14.0-rc3 | ||
*/ | ||
@@ -323,3 +323,3 @@ (function (global, factory) { | ||
var elements = [].slice.call(targets); | ||
var elements = [].concat(targets); | ||
this.options = __assign({ | ||
@@ -326,0 +326,0 @@ container: elements.length > 1 ? window : elements[0], |
@@ -7,5 +7,5 @@ /* | ||
repository: git+https://github.com/daybrush/drag.git | ||
version: 0.14.0-rc2 | ||
version: 0.14.0-rc3 | ||
*/ | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t=t||self).Dragger=i()}(this,function(){"use strict";var u=function(){return(u=Object.assign||function(t){for(var i,n=1,s=arguments.length;n<s;n++)for(var e in i=arguments[n])Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e]);return t}).apply(this,arguments)};function f(t,i,n,s){var e=D(t),a=D(i),r=D(s);return p(h(s[0],c(e,r)),h(s[0],c(a,r)),n[0])}function l(t){return t.touches?d(t.touches):[e(t)]}function p(t,i,n){var s=t.clientX,e=t.clientY;return{clientX:s,clientY:e,deltaX:s-i.clientX,deltaY:e-i.clientY,distX:s-n.clientX,distY:e-n.clientY}}function g(t){return Math.sqrt(Math.pow(t[0].clientX-t[1].clientX,2)+Math.pow(t[0].clientY-t[1].clientY,2))}function v(t,n,s){return t.map(function(t,i){return p(t,n[i],s[i])})}function d(t){for(var i=Math.min(t.length,2),n=[],s=0;s<i;++s)n.push(e(t[s]));return n}function e(t){return{clientX:t.clientX,clientY:t.clientY}}function D(t){return 1===t.length?t[0]:{clientX:(t[0].clientX+t[1].clientX)/2,clientY:(t[0].clientY+t[1].clientY)/2}}function h(t,i){return{clientX:t.clientX+i.clientX,clientY:t.clientY+i.clientY}}function c(t,i){return{clientX:t.clientX-i.clientX,clientY:t.clientY-i.clientY}}function C(t,i,n,s){t.addEventListener(i,n,s)}function m(t,i,n){t.removeEventListener(i,n)}var n=function(){function t(t,i){var o=this;void 0===i&&(i={}),this.options={},this.flag=!1,this.pinchFlag=!1,this.datas={},this.isDrag=!1,this.isPinch=!1,this.isMouse=!1,this.isTouch=!1,this.prevClients=[],this.startClients=[],this.movement=0,this.startPinchClients=[],this.startDistance=0,this.customDist=[0,0],this.targets=[],this.onDragStart=function(t){if(o.flag||!1!==t.cancelable){var i=o.options,n=i.container,s=i.pinchOutside,e=i.dragstart,a=i.preventRightClick,r=o.isTouch;if(!o.flag&&r&&s&&C(n,"touchstart",o.onDragStart),o.flag&&r&&s&&m(n,"touchstart",o.onDragStart),function(t){return t.touches&&2<=t.touches.length}(t)){if(!o.flag&&t.touches.length!==t.changedTouches.length)return;o.pinchFlag||o.onPinchStart(t)}if(!o.flag){var h=o.startClients[0]?o.startClients:l(t);o.customDist=[0,0],o.flag=!0,o.isDrag=!1,o.startClients=h,o.prevClients=h,o.datas={};var c=p(h[o.movement=0],o.prevClients[0],o.startClients[0]);(a&&3===t.which||!1===(e&&e(u({type:"dragstart",datas:o.datas,inputEvent:t},c))))&&(o.startClients=[],o.prevClients=[],o.flag=!1),o.flag&&t.preventDefault()}}},this.onDrag=function(t,i){if(o.flag){var n=l(t);o.pinchFlag&&o.onPinch(t,n);var s=o.move([0,0],t,n);if(s&&(s.deltaX||s.deltaY)){var e=o.options.drag;e&&e(u({},s,{isScroll:!!i,inputEvent:t}))}}},this.onDragEnd=function(t){if(o.flag){var i=o.options,n=i.dragend,s=i.pinchOutside,e=i.container;o.isTouch&&s&&m(e,"touchstart",o.onDragStart),o.pinchFlag&&o.onPinchEnd(t),o.flag=!1;var a=o.prevClients,r=o.startClients,h=o.pinchFlag?f(a,a,r,o.startPinchClients):p(a[0],a[0],r[0]);o.startClients=[],o.prevClients=[],n&&n(u({type:"dragend",datas:o.datas,isDrag:o.isDrag,inputEvent:t},h))}};var n=[].slice.call(t);this.options=u({container:1<n.length?window:n[0],preventRightClick:!0,preventDefault:!0,pinchThreshold:0,events:["touch","mouse"]},i);var s=this.options,e=s.container,a=s.events;if(this.isTouch=-1<a.indexOf("touch"),this.isMouse=-1<a.indexOf("mouse"),this.customDist=[0,0],this.targets=n,this.isMouse&&(n.forEach(function(t){C(t,"mousedown",o.onDragStart)}),C(e,"mousemove",this.onDrag),C(e,"mouseup",this.onDragEnd)),this.isTouch){var r={passive:!1};n.forEach(function(t){C(t,"touchstart",o.onDragStart,r)}),C(e,"touchmove",this.onDrag,r),C(e,"touchend",this.onDragEnd,r),C(e,"touchcancel",this.onDragEnd,r)}}var i=t.prototype;return i.isDragging=function(){return this.isDrag},i.isFlag=function(){return this.flag},i.isPinching=function(){return this.isPinch},i.scrollBy=function(i,n,t,s){void 0===s&&(s=!0),this.flag&&(this.startClients.forEach(function(t){t.clientX-=i,t.clientY-=n}),this.prevClients.forEach(function(t){t.clientX-=i,t.clientY-=n}),s&&this.onDrag(t,!0))},i.move=function(t,i,n){var s=t[0],e=t[1];void 0===n&&(n=this.prevClients);var a=this.customDist,r=this.prevClients,h=this.startClients,c=this.pinchFlag?f(n,r,h,this.startPinchClients):p(n[0],r[0],h[0]);a[0]+=s,a[1]+=e,c.deltaX+=s,c.deltaY+=e;var o=c.deltaX,l=c.deltaY;return c.distX+=a[0],c.distY+=a[1],this.movement+=Math.sqrt(o*o+l*l),this.prevClients=n,this.isDrag=!0,u({type:"drag",datas:this.datas},c,{isDrag:this.isDrag,isPinch:this.isPinch,isScroll:!1,inputEvent:i})},i.onPinchStart=function(t){var i,n,s=this.options,e=s.pinchstart,a=s.pinchThreshold;if(!(this.isDrag&&this.movement>a)){var r=d(t.changedTouches);if(this.pinchFlag=!0,(i=this.startClients).push.apply(i,r),(n=this.prevClients).push.apply(n,r),this.startDistance=g(this.prevClients),this.startPinchClients=this.prevClients.slice(),e){var h=this.prevClients,c=D(h),o=p(c,c,c);e(u({type:"pinchstart",datas:this.datas,touches:v(h,h,h)},o,{inputEvent:t}))}}},i.onPinch=function(t,i){if(this.flag&&this.pinchFlag&&!(i.length<2)){this.isPinch=!0;var n=this.options.pinch;if(n){var s=this.prevClients,e=this.startClients,a=p(D(i),D(s),D(e)),r=g(i);n(u({type:"pinch",datas:this.datas,touches:v(i,s,e),scale:r/this.startDistance,distance:r},a,{inputEvent:t}))}}},i.onPinchEnd=function(t){if(this.flag&&this.pinchFlag){var i=this.isPinch;this.isPinch=!1,this.pinchFlag=!1;var n=this.options.pinchend;if(n){var s=this.prevClients,e=this.startClients,a=p(D(s),D(s),D(e));n(u({type:"pinchend",datas:this.datas,isPinch:i,touches:v(s,s,e)},a,{inputEvent:t})),this.isPinch=!1,this.pinchFlag=!1}}},i.unset=function(){var i=this,t=this.targets,n=this.options.container;this.isMouse&&(t.forEach(function(t){m(t,"mousedown",i.onDragStart)}),m(n,"mousemove",this.onDrag),m(n,"mouseup",this.onDragEnd)),this.isTouch&&(t.forEach(function(t){m(t,"touchstart",i.onDragStart)}),m(n,"touchstart",this.onDragStart),m(n,"touchmove",this.onDrag),m(n,"touchend",this.onDragEnd),m(n,"touchcancel",this.onDragEnd))},t}();var t={default:n,drag:function(t,i){return new n(t,i)}};for(var i in t)n[i]=t[i];return n}); | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t=t||self).Dragger=i()}(this,function(){"use strict";var u=function(){return(u=Object.assign||function(t){for(var i,n=1,s=arguments.length;n<s;n++)for(var e in i=arguments[n])Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e]);return t}).apply(this,arguments)};function f(t,i,n,s){var e=D(t),a=D(i),r=D(s);return p(h(s[0],c(e,r)),h(s[0],c(a,r)),n[0])}function l(t){return t.touches?d(t.touches):[e(t)]}function p(t,i,n){var s=t.clientX,e=t.clientY;return{clientX:s,clientY:e,deltaX:s-i.clientX,deltaY:e-i.clientY,distX:s-n.clientX,distY:e-n.clientY}}function g(t){return Math.sqrt(Math.pow(t[0].clientX-t[1].clientX,2)+Math.pow(t[0].clientY-t[1].clientY,2))}function v(t,n,s){return t.map(function(t,i){return p(t,n[i],s[i])})}function d(t){for(var i=Math.min(t.length,2),n=[],s=0;s<i;++s)n.push(e(t[s]));return n}function e(t){return{clientX:t.clientX,clientY:t.clientY}}function D(t){return 1===t.length?t[0]:{clientX:(t[0].clientX+t[1].clientX)/2,clientY:(t[0].clientY+t[1].clientY)/2}}function h(t,i){return{clientX:t.clientX+i.clientX,clientY:t.clientY+i.clientY}}function c(t,i){return{clientX:t.clientX-i.clientX,clientY:t.clientY-i.clientY}}function C(t,i,n,s){t.addEventListener(i,n,s)}function m(t,i,n){t.removeEventListener(i,n)}var n=function(){function t(t,i){var o=this;void 0===i&&(i={}),this.options={},this.flag=!1,this.pinchFlag=!1,this.datas={},this.isDrag=!1,this.isPinch=!1,this.isMouse=!1,this.isTouch=!1,this.prevClients=[],this.startClients=[],this.movement=0,this.startPinchClients=[],this.startDistance=0,this.customDist=[0,0],this.targets=[],this.onDragStart=function(t){if(o.flag||!1!==t.cancelable){var i=o.options,n=i.container,s=i.pinchOutside,e=i.dragstart,a=i.preventRightClick,r=o.isTouch;if(!o.flag&&r&&s&&C(n,"touchstart",o.onDragStart),o.flag&&r&&s&&m(n,"touchstart",o.onDragStart),function(t){return t.touches&&2<=t.touches.length}(t)){if(!o.flag&&t.touches.length!==t.changedTouches.length)return;o.pinchFlag||o.onPinchStart(t)}if(!o.flag){var h=o.startClients[0]?o.startClients:l(t);o.customDist=[0,0],o.flag=!0,o.isDrag=!1,o.startClients=h,o.prevClients=h,o.datas={};var c=p(h[o.movement=0],o.prevClients[0],o.startClients[0]);(a&&3===t.which||!1===(e&&e(u({type:"dragstart",datas:o.datas,inputEvent:t},c))))&&(o.startClients=[],o.prevClients=[],o.flag=!1),o.flag&&t.preventDefault()}}},this.onDrag=function(t,i){if(o.flag){var n=l(t);o.pinchFlag&&o.onPinch(t,n);var s=o.move([0,0],t,n);if(s&&(s.deltaX||s.deltaY)){var e=o.options.drag;e&&e(u({},s,{isScroll:!!i,inputEvent:t}))}}},this.onDragEnd=function(t){if(o.flag){var i=o.options,n=i.dragend,s=i.pinchOutside,e=i.container;o.isTouch&&s&&m(e,"touchstart",o.onDragStart),o.pinchFlag&&o.onPinchEnd(t),o.flag=!1;var a=o.prevClients,r=o.startClients,h=o.pinchFlag?f(a,a,r,o.startPinchClients):p(a[0],a[0],r[0]);o.startClients=[],o.prevClients=[],n&&n(u({type:"dragend",datas:o.datas,isDrag:o.isDrag,inputEvent:t},h))}};var n=[].concat(t);this.options=u({container:1<n.length?window:n[0],preventRightClick:!0,preventDefault:!0,pinchThreshold:0,events:["touch","mouse"]},i);var s=this.options,e=s.container,a=s.events;if(this.isTouch=-1<a.indexOf("touch"),this.isMouse=-1<a.indexOf("mouse"),this.customDist=[0,0],this.targets=n,this.isMouse&&(n.forEach(function(t){C(t,"mousedown",o.onDragStart)}),C(e,"mousemove",this.onDrag),C(e,"mouseup",this.onDragEnd)),this.isTouch){var r={passive:!1};n.forEach(function(t){C(t,"touchstart",o.onDragStart,r)}),C(e,"touchmove",this.onDrag,r),C(e,"touchend",this.onDragEnd,r),C(e,"touchcancel",this.onDragEnd,r)}}var i=t.prototype;return i.isDragging=function(){return this.isDrag},i.isFlag=function(){return this.flag},i.isPinching=function(){return this.isPinch},i.scrollBy=function(i,n,t,s){void 0===s&&(s=!0),this.flag&&(this.startClients.forEach(function(t){t.clientX-=i,t.clientY-=n}),this.prevClients.forEach(function(t){t.clientX-=i,t.clientY-=n}),s&&this.onDrag(t,!0))},i.move=function(t,i,n){var s=t[0],e=t[1];void 0===n&&(n=this.prevClients);var a=this.customDist,r=this.prevClients,h=this.startClients,c=this.pinchFlag?f(n,r,h,this.startPinchClients):p(n[0],r[0],h[0]);a[0]+=s,a[1]+=e,c.deltaX+=s,c.deltaY+=e;var o=c.deltaX,l=c.deltaY;return c.distX+=a[0],c.distY+=a[1],this.movement+=Math.sqrt(o*o+l*l),this.prevClients=n,this.isDrag=!0,u({type:"drag",datas:this.datas},c,{isDrag:this.isDrag,isPinch:this.isPinch,isScroll:!1,inputEvent:i})},i.onPinchStart=function(t){var i,n,s=this.options,e=s.pinchstart,a=s.pinchThreshold;if(!(this.isDrag&&this.movement>a)){var r=d(t.changedTouches);if(this.pinchFlag=!0,(i=this.startClients).push.apply(i,r),(n=this.prevClients).push.apply(n,r),this.startDistance=g(this.prevClients),this.startPinchClients=this.prevClients.slice(),e){var h=this.prevClients,c=D(h),o=p(c,c,c);e(u({type:"pinchstart",datas:this.datas,touches:v(h,h,h)},o,{inputEvent:t}))}}},i.onPinch=function(t,i){if(this.flag&&this.pinchFlag&&!(i.length<2)){this.isPinch=!0;var n=this.options.pinch;if(n){var s=this.prevClients,e=this.startClients,a=p(D(i),D(s),D(e)),r=g(i);n(u({type:"pinch",datas:this.datas,touches:v(i,s,e),scale:r/this.startDistance,distance:r},a,{inputEvent:t}))}}},i.onPinchEnd=function(t){if(this.flag&&this.pinchFlag){var i=this.isPinch;this.isPinch=!1,this.pinchFlag=!1;var n=this.options.pinchend;if(n){var s=this.prevClients,e=this.startClients,a=p(D(s),D(s),D(e));n(u({type:"pinchend",datas:this.datas,isPinch:i,touches:v(s,s,e)},a,{inputEvent:t})),this.isPinch=!1,this.pinchFlag=!1}}},i.unset=function(){var i=this,t=this.targets,n=this.options.container;this.isMouse&&(t.forEach(function(t){m(t,"mousedown",i.onDragStart)}),m(n,"mousemove",this.onDrag),m(n,"mouseup",this.onDragEnd)),this.isTouch&&(t.forEach(function(t){m(t,"touchstart",i.onDragStart)}),m(n,"touchstart",this.onDragStart),m(n,"touchmove",this.onDrag),m(n,"touchend",this.onDragEnd),m(n,"touchcancel",this.onDragEnd))},t}();var t={default:n,drag:function(t,i){return new n(t,i)}};for(var i in t)n[i]=t[i];return n}); | ||
//# sourceMappingURL=drag.min.js.map |
{ | ||
"name": "@daybrush/drag", | ||
"version": "0.14.0-rc2", | ||
"version": "0.14.0-rc3", | ||
"description": "You can set up drag events in any browser.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/drag.cjs.js", |
@@ -31,3 +31,3 @@ import { DragOptions, Client, Position, OnDrag } from "./types"; | ||
constructor(targets: Array<Element | Window> | Element | Window, options: DragOptions = {}) { | ||
const elements = [].slice.call(targets) as Array<Element | Window> ; | ||
const elements = [].concat(targets as any) as Array<Element | Window> ; | ||
this.options = { | ||
@@ -34,0 +34,0 @@ container: elements.length > 1 ? window : elements[0], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
189218