Skip to content

armgit / anime

Public Imported from GitHub
0

JavaScript animation engine

Set default touch dragTreshold to 7

Julian Garnier01352234e24e
diff --git a/dist/modules/draggable/draggable.cjs b/dist/modules/draggable/draggable.cjs
index 5dcc95c5..3de5b3cc 100644
--- a/dist/modules/draggable/draggable.cjs
+++ b/dist/modules/draggable/draggable.cjs
@@ -26,6 +26,7 @@ var target = require('../utils/target.cjs');
* DOMTarget,
* DOMTargetSelector,
* DraggableCursorParams,
+ * DraggableDragThresholdParams,
* TargetsParam,
* DraggableParams,
* EasingFunction,
@@ -156,7 +157,7 @@ class Transforms {
}
/**
- * @template {Array<Number>|DOMTargetSelector|String|Number|Boolean|Function|DraggableCursorParams} T
+ * @template {Array<Number>|DOMTargetSelector|String|Number|Boolean|Function|DraggableCursorParams|DraggableDragThresholdParams} T
* @param {T | ((draggable: Draggable) => T)} value
* @param {Draggable} draggable
* @return {T}
@@ -210,6 +211,8 @@ class Draggable {
/** @type {Number} */
this.dragSpeed = 0;
/** @type {Number} */
+ this.dragThreshold = 3;
+ /** @type {Number} */
this.maxVelocity = 0;
/** @type {Number} */
this.minVelocity = 0;
@@ -627,6 +630,16 @@ class Draggable {
if (onHover) cursorStyles.onHover = onHover;
if (onGrab) cursorStyles.onGrab = onGrab;
}
+ const parsedDragThreshold = parseDraggableFunctionParameter(params.dragThreshold, this);
+ const dragThreshold = { mouse: 3, touch: 7 };
+ if (helpers.isNum(parsedDragThreshold)) {
+ dragThreshold.mouse = parsedDragThreshold;
+ dragThreshold.touch = parsedDragThreshold;
+ } else if (parsedDragThreshold) {
+ const { mouse, touch } = parsedDragThreshold;
+ if (!helpers.isUnd(mouse)) dragThreshold.mouse = mouse;
+ if (!helpers.isUnd(touch)) dragThreshold.touch = touch;
+ }
this.containerArray = helpers.isArr(container) ? container : null;
this.$container = /** @type {HTMLElement} */(container && !this.containerArray ? targets.parseTargets(/** @type {DOMTarget} */(container))[0] : consts.doc.body);
this.useWin = this.$container === consts.doc.body;
@@ -641,6 +654,7 @@ class Draggable {
this.scrollSpeed = values.setValue(parseDraggableFunctionParameter(params.scrollSpeed, this), 1.5);
this.scrollThreshold = values.setValue(parseDraggableFunctionParameter(params.scrollThreshold, this), 20);
this.dragSpeed = values.setValue(parseDraggableFunctionParameter(params.dragSpeed, this), 1);
+ this.dragThreshold = this.isFinePointer ? dragThreshold.mouse : dragThreshold.touch;
this.minVelocity = values.setValue(parseDraggableFunctionParameter(params.minVelocity, this), 0);
this.maxVelocity = values.setValue(parseDraggableFunctionParameter(params.maxVelocity, this), 50);
this.velocityMultiplier = values.setValue(parseDraggableFunctionParameter(params.velocityMultiplier, this), 1);
@@ -942,8 +956,7 @@ class Draggable {
this.$trigger.addEventListener('touchend', preventDefault);
// Don't check for a miminim distance move if already dragging
- if (this.dragged || (!this.disabled[0] && helpers.abs(movedX) > 3) || (!this.disabled[1] && helpers.abs(movedY) > 3)) {
-
+ if (this.dragged || (!this.disabled[0] && helpers.abs(movedX) > this.dragThreshold) || (!this.disabled[1] && helpers.abs(movedY) > this.dragThreshold)) {
this.updateTicker.resume();
this.pointer[2] = this.pointer[0];
this.pointer[3] = this.pointer[1];
diff --git a/dist/modules/draggable/draggable.d.ts b/dist/modules/draggable/draggable.d.ts
index 2bbd0b0f..99feaabe 100644
--- a/dist/modules/draggable/draggable.d.ts
+++ b/dist/modules/draggable/draggable.d.ts
@@ -30,6 +30,8 @@ export class Draggable {
/** @type {Number} */
dragSpeed: number;
/** @type {Number} */
+ dragThreshold: number;
+ /** @type {Number} */
maxVelocity: number;
/** @type {Number} */
minVelocity: number;
diff --git a/dist/modules/draggable/draggable.js b/dist/modules/draggable/draggable.js
index 2c732b41..9e5ad9af 100644
--- a/dist/modules/draggable/draggable.js
+++ b/dist/modules/draggable/draggable.js
@@ -8,7 +8,7 @@
import { globals, scope } from '../core/globals.js';
import { doc, win, noop, maxValue, compositionTypes } from '../core/consts.js';
import { parseTargets } from '../core/targets.js';
-import { isUnd, isObj, isArr, now, atan2, round, max, snap, clamp, abs, sqrt, cos, sin, isFnc } from '../core/helpers.js';
+import { isUnd, isObj, isArr, now, atan2, round, max, snap, clamp, isNum, abs, sqrt, cos, sin, isFnc } from '../core/helpers.js';
import { setValue } from '../core/values.js';
import { mapRange } from '../utils/number.js';
import { Timer } from '../timer/timer.js';
@@ -24,6 +24,7 @@ import { get, set } from '../utils/target.js';
* DOMTarget,
* DOMTargetSelector,
* DraggableCursorParams,
+ * DraggableDragThresholdParams,
* TargetsParam,
* DraggableParams,
* EasingFunction,
@@ -154,7 +155,7 @@ class Transforms {
}
/**
- * @template {Array<Number>|DOMTargetSelector|String|Number|Boolean|Function|DraggableCursorParams} T
+ * @template {Array<Number>|DOMTargetSelector|String|Number|Boolean|Function|DraggableCursorParams|DraggableDragThresholdParams} T
* @param {T | ((draggable: Draggable) => T)} value
* @param {Draggable} draggable
* @return {T}
@@ -208,6 +209,8 @@ class Draggable {
/** @type {Number} */
this.dragSpeed = 0;
/** @type {Number} */
+ this.dragThreshold = 3;
+ /** @type {Number} */
this.maxVelocity = 0;
/** @type {Number} */
this.minVelocity = 0;
@@ -625,6 +628,16 @@ class Draggable {
if (onHover) cursorStyles.onHover = onHover;
if (onGrab) cursorStyles.onGrab = onGrab;
}
+ const parsedDragThreshold = parseDraggableFunctionParameter(params.dragThreshold, this);
+ const dragThreshold = { mouse: 3, touch: 7 };
+ if (isNum(parsedDragThreshold)) {
+ dragThreshold.mouse = parsedDragThreshold;
+ dragThreshold.touch = parsedDragThreshold;
+ } else if (parsedDragThreshold) {
+ const { mouse, touch } = parsedDragThreshold;
+ if (!isUnd(mouse)) dragThreshold.mouse = mouse;
+ if (!isUnd(touch)) dragThreshold.touch = touch;
+ }
this.containerArray = isArr(container) ? container : null;
this.$container = /** @type {HTMLElement} */(container && !this.containerArray ? parseTargets(/** @type {DOMTarget} */(container))[0] : doc.body);
this.useWin = this.$container === doc.body;
@@ -639,6 +652,7 @@ class Draggable {
this.scrollSpeed = setValue(parseDraggableFunctionParameter(params.scrollSpeed, this), 1.5);
this.scrollThreshold = setValue(parseDraggableFunctionParameter(params.scrollThreshold, this), 20);
this.dragSpeed = setValue(parseDraggableFunctionParameter(params.dragSpeed, this), 1);
+ this.dragThreshold = this.isFinePointer ? dragThreshold.mouse : dragThreshold.touch;
this.minVelocity = setValue(parseDraggableFunctionParameter(params.minVelocity, this), 0);
this.maxVelocity = setValue(parseDraggableFunctionParameter(params.maxVelocity, this), 50);
this.velocityMultiplier = setValue(parseDraggableFunctionParameter(params.velocityMultiplier, this), 1);
@@ -940,8 +954,7 @@ class Draggable {
this.$trigger.addEventListener('touchend', preventDefault);
// Don't check for a miminim distance move if already dragging
- if (this.dragged || (!this.disabled[0] && abs(movedX) > 3) || (!this.disabled[1] && abs(movedY) > 3)) {
-
+ if (this.dragged || (!this.disabled[0] && abs(movedX) > this.dragThreshold) || (!this.disabled[1] && abs(movedY) > this.dragThreshold)) {
this.updateTicker.resume();
this.pointer[2] = this.pointer[0];
this.pointer[3] = this.pointer[1];
diff --git a/dist/modules/types/index.d.ts b/dist/modules/types/index.d.ts
index e5b903f9..15d28141 100644
--- a/dist/modules/types/index.d.ts
+++ b/dist/modules/types/index.d.ts
@@ -340,6 +340,10 @@ export type DraggableCursorParams = {
onHover?: string;
onGrab?: string;
};
+export type DraggableDragThresholdParams = {
+ mouse?: number;
+ touch?: number;
+};
export type DraggableParams = {
trigger?: DOMTargetSelector;
container?: DOMTargetSelector | Array<number> | ((draggable: Draggable) => DOMTargetSelector | Array<number>);
@@ -351,6 +355,7 @@ export type DraggableParams = {
containerFriction?: number | ((draggable: Draggable) => number);
releaseContainerFriction?: number | ((draggable: Draggable) => number);
dragSpeed?: number | ((draggable: Draggable) => number);
+ dragThreshold?: number | DraggableDragThresholdParams | ((draggable: Draggable) => number | DraggableDragThresholdParams);
scrollSpeed?: number | ((draggable: Draggable) => number);
scrollThreshold?: number | ((draggable: Draggable) => number);
minVelocity?: number | ((draggable: Draggable) => number);
diff --git a/examples/draggable-playground/index.js b/examples/draggable-playground/index.js
index 69c31513..e4709ebb 100644
--- a/examples/draggable-playground/index.js
+++ b/examples/draggable-playground/index.js
@@ -205,7 +205,7 @@ const flickDraggable = createDraggable(flickData, {
y: false,
onGrab: () => animate(flickData, { speedX: 0, duration: 500 }),
onRelease: () => animate(flickData, { speedX: 2, duration: 500 }),
- releaseStiffness: 10,
+ releaseDamping: 10,
});
createTimer({
diff --git a/src/draggable/draggable.js b/src/draggable/draggable.js
index 248b43f8..300be680 100644
--- a/src/draggable/draggable.js
+++ b/src/draggable/draggable.js
@@ -681,7 +681,7 @@ export class Draggable {
if (onGrab) cursorStyles.onGrab = onGrab;
}
const parsedDragThreshold = parseDraggableFunctionParameter(params.dragThreshold, this);
- const dragThreshold = { mouse: 3, touch: 8 };
+ const dragThreshold = { mouse: 3, touch: 7 };
if (isNum(parsedDragThreshold)) {
dragThreshold.mouse = parsedDragThreshold;
dragThreshold.touch = parsedDragThreshold;