88import { globals , scope } from '../core/globals.js' ;
99import { doc , win , noop , maxValue , compositionTypes } from '../core/consts.js' ;
1010import { parseTargets } from '../core/targets.js' ;
11- import { isUnd , isObj , isArr , now , atan2 , round , max , snap , clamp , abs , sqrt , cos , sin , isFnc } from '../core/helpers.js' ;
11+ import { isUnd , isObj , isArr , now , atan2 , round , max , snap , clamp , isNum , abs , sqrt , cos , sin , isFnc } from '../core/helpers.js' ;
1212import { setValue } from '../core/values.js' ;
1313import { mapRange } from '../utils/number.js' ;
1414import { Timer } from '../timer/timer.js' ;
@@ -24,6 +24,7 @@ import { get, set } from '../utils/target.js';
2424 * DOMTarget,
2525 * DOMTargetSelector,
2626 * DraggableCursorParams,
27+ * DraggableDragThresholdParams,
2728 * TargetsParam,
2829 * DraggableParams,
2930 * EasingFunction,
@@ -154,7 +155,7 @@ class Transforms {
154155}
155156
156157/**
157- * @template {Array<Number>|DOMTargetSelector|String|Number|Boolean|Function|DraggableCursorParams} T
158+ * @template {Array<Number>|DOMTargetSelector|String|Number|Boolean|Function|DraggableCursorParams|DraggableDragThresholdParams } T
158159 * @param {T | ((draggable: Draggable) => T) } value
159160 * @param {Draggable } draggable
160161 * @return {T }
@@ -208,6 +209,8 @@ class Draggable {
208209 /** @type {Number } */
209210 this . dragSpeed = 0 ;
210211 /** @type {Number } */
212+ this . dragThreshold = 3 ;
213+ /** @type {Number } */
211214 this . maxVelocity = 0 ;
212215 /** @type {Number } */
213216 this . minVelocity = 0 ;
@@ -625,6 +628,16 @@ class Draggable {
625628 if ( onHover ) cursorStyles . onHover = onHover ;
626629 if ( onGrab ) cursorStyles . onGrab = onGrab ;
627630 }
631+ const parsedDragThreshold = parseDraggableFunctionParameter ( params . dragThreshold , this ) ;
632+ const dragThreshold = { mouse : 3 , touch : 7 } ;
633+ if ( isNum ( parsedDragThreshold ) ) {
634+ dragThreshold . mouse = parsedDragThreshold ;
635+ dragThreshold . touch = parsedDragThreshold ;
636+ } else if ( parsedDragThreshold ) {
637+ const { mouse, touch } = parsedDragThreshold ;
638+ if ( ! isUnd ( mouse ) ) dragThreshold . mouse = mouse ;
639+ if ( ! isUnd ( touch ) ) dragThreshold . touch = touch ;
640+ }
628641 this . containerArray = isArr ( container ) ? container : null ;
629642 this . $container = /** @type {HTMLElement } */ ( container && ! this . containerArray ? parseTargets ( /** @type {DOMTarget } */ ( container ) ) [ 0 ] : doc . body ) ;
630643 this . useWin = this . $container === doc . body ;
@@ -639,6 +652,7 @@ class Draggable {
639652 this . scrollSpeed = setValue ( parseDraggableFunctionParameter ( params . scrollSpeed , this ) , 1.5 ) ;
640653 this . scrollThreshold = setValue ( parseDraggableFunctionParameter ( params . scrollThreshold , this ) , 20 ) ;
641654 this . dragSpeed = setValue ( parseDraggableFunctionParameter ( params . dragSpeed , this ) , 1 ) ;
655+ this . dragThreshold = this . isFinePointer ? dragThreshold . mouse : dragThreshold . touch ;
642656 this . minVelocity = setValue ( parseDraggableFunctionParameter ( params . minVelocity , this ) , 0 ) ;
643657 this . maxVelocity = setValue ( parseDraggableFunctionParameter ( params . maxVelocity , this ) , 50 ) ;
644658 this . velocityMultiplier = setValue ( parseDraggableFunctionParameter ( params . velocityMultiplier , this ) , 1 ) ;
@@ -940,8 +954,7 @@ class Draggable {
940954 this . $trigger . addEventListener ( 'touchend' , preventDefault ) ;
941955
942956 // Don't check for a miminim distance move if already dragging
943- if ( this . dragged || ( ! this . disabled [ 0 ] && abs ( movedX ) > 3 ) || ( ! this . disabled [ 1 ] && abs ( movedY ) > 3 ) ) {
944-
957+ if ( this . dragged || ( ! this . disabled [ 0 ] && abs ( movedX ) > this . dragThreshold ) || ( ! this . disabled [ 1 ] && abs ( movedY ) > this . dragThreshold ) ) {
945958 this . updateTicker . resume ( ) ;
946959 this . pointer [ 2 ] = this . pointer [ 0 ] ;
947960 this . pointer [ 3 ] = this . pointer [ 1 ] ;
0 commit comments