animejs 4.1.2 → 4.2.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -8
- package/{lib → dist/bundles}/anime.esm.js +6549 -6265
- package/dist/bundles/anime.esm.min.js +7 -0
- package/dist/bundles/anime.umd.js +8621 -0
- package/dist/bundles/anime.umd.min.js +7 -0
- package/dist/modules/animatable/animatable.cjs +150 -0
- package/dist/modules/animatable/animatable.d.ts +28 -0
- package/dist/modules/animatable/animatable.js +147 -0
- package/dist/modules/animatable/index.cjs +15 -0
- package/dist/modules/animatable/index.d.ts +1 -0
- package/dist/modules/animatable/index.js +8 -0
- package/dist/modules/animation/additive.cjs +82 -0
- package/dist/modules/animation/additive.d.ts +15 -0
- package/dist/modules/animation/additive.js +79 -0
- package/dist/modules/animation/animation.cjs +660 -0
- package/dist/modules/animation/animation.d.ts +47 -0
- package/dist/modules/animation/animation.js +657 -0
- package/dist/modules/animation/composition.cjs +383 -0
- package/dist/modules/animation/composition.d.ts +10 -0
- package/dist/modules/animation/composition.js +377 -0
- package/dist/modules/animation/index.cjs +15 -0
- package/dist/modules/animation/index.d.ts +1 -0
- package/dist/modules/animation/index.js +8 -0
- package/dist/modules/core/clock.cjs +110 -0
- package/dist/modules/core/clock.d.ts +51 -0
- package/dist/modules/core/clock.js +108 -0
- package/dist/modules/core/colors.cjs +102 -0
- package/dist/modules/core/colors.d.ts +2 -0
- package/dist/modules/core/colors.js +100 -0
- package/dist/modules/core/consts.cjs +154 -0
- package/dist/modules/core/consts.d.ts +59 -0
- package/dist/modules/core/consts.js +121 -0
- package/dist/modules/core/globals.cjs +77 -0
- package/dist/modules/core/globals.d.ts +29 -0
- package/dist/modules/core/globals.js +72 -0
- package/dist/modules/core/helpers.cjs +304 -0
- package/dist/modules/core/helpers.d.ts +43 -0
- package/dist/modules/core/helpers.js +261 -0
- package/dist/modules/core/render.cjs +389 -0
- package/dist/modules/core/render.d.ts +4 -0
- package/dist/modules/core/render.js +386 -0
- package/dist/modules/core/styles.cjs +116 -0
- package/dist/modules/core/styles.d.ts +5 -0
- package/dist/modules/core/styles.js +113 -0
- package/dist/modules/core/targets.cjs +136 -0
- package/dist/modules/core/targets.d.ts +118 -0
- package/dist/modules/core/targets.js +132 -0
- package/dist/modules/core/transforms.cjs +49 -0
- package/dist/modules/core/transforms.d.ts +2 -0
- package/dist/modules/core/transforms.js +47 -0
- package/dist/modules/core/units.cjs +67 -0
- package/dist/modules/core/units.d.ts +3 -0
- package/dist/modules/core/units.js +65 -0
- package/dist/modules/core/values.cjs +215 -0
- package/dist/modules/core/values.d.ts +14 -0
- package/dist/modules/core/values.js +205 -0
- package/dist/modules/draggable/draggable.cjs +1226 -0
- package/dist/modules/draggable/draggable.d.ts +272 -0
- package/dist/modules/draggable/draggable.js +1223 -0
- package/dist/modules/draggable/index.cjs +15 -0
- package/dist/modules/draggable/index.d.ts +1 -0
- package/dist/modules/draggable/index.js +8 -0
- package/dist/modules/easings/cubic-bezier.cjs +64 -0
- package/dist/modules/easings/cubic-bezier.d.ts +2 -0
- package/dist/modules/easings/cubic-bezier.js +62 -0
- package/dist/modules/easings/eases.cjs +149 -0
- package/dist/modules/easings/eases.d.ts +111 -0
- package/dist/modules/easings/eases.js +146 -0
- package/dist/modules/easings/index.cjs +24 -0
- package/dist/modules/easings/index.d.ts +6 -0
- package/dist/modules/easings/index.js +13 -0
- package/dist/modules/easings/irregular.cjs +41 -0
- package/dist/modules/easings/irregular.d.ts +2 -0
- package/dist/modules/easings/irregular.js +39 -0
- package/dist/modules/easings/linear.cjs +59 -0
- package/dist/modules/easings/linear.d.ts +2 -0
- package/dist/modules/easings/linear.js +57 -0
- package/dist/modules/easings/none.cjs +19 -0
- package/dist/modules/easings/none.d.ts +8 -0
- package/dist/modules/easings/none.js +17 -0
- package/dist/modules/easings/parser.cjs +59 -0
- package/dist/modules/easings/parser.d.ts +21 -0
- package/dist/modules/easings/parser.js +55 -0
- package/dist/modules/easings/steps.cjs +30 -0
- package/dist/modules/easings/steps.d.ts +2 -0
- package/dist/modules/easings/steps.js +28 -0
- package/dist/modules/engine/engine.cjs +168 -0
- package/dist/modules/engine/engine.d.ts +21 -0
- package/dist/modules/engine/engine.js +166 -0
- package/dist/modules/engine/index.cjs +14 -0
- package/dist/modules/engine/index.d.ts +1 -0
- package/dist/modules/engine/index.js +8 -0
- package/dist/modules/events/index.cjs +16 -0
- package/dist/modules/events/index.d.ts +1 -0
- package/dist/modules/events/index.js +8 -0
- package/dist/modules/events/scroll.cjs +936 -0
- package/dist/modules/events/scroll.d.ts +189 -0
- package/dist/modules/events/scroll.js +932 -0
- package/dist/modules/index.cjs +103 -0
- package/dist/modules/index.d.ts +19 -0
- package/dist/modules/index.js +42 -0
- package/dist/modules/scope/index.cjs +15 -0
- package/dist/modules/scope/index.d.ts +1 -0
- package/dist/modules/scope/index.js +8 -0
- package/dist/modules/scope/scope.cjs +254 -0
- package/dist/modules/scope/scope.d.ts +115 -0
- package/dist/modules/scope/scope.js +251 -0
- package/dist/modules/spring/index.cjs +15 -0
- package/dist/modules/spring/index.d.ts +1 -0
- package/dist/modules/spring/index.js +8 -0
- package/dist/modules/spring/spring.cjs +133 -0
- package/dist/modules/spring/spring.d.ts +37 -0
- package/dist/modules/spring/spring.js +130 -0
- package/dist/modules/svg/drawable.cjs +119 -0
- package/dist/modules/svg/drawable.d.ts +3 -0
- package/dist/modules/svg/drawable.js +117 -0
- package/dist/modules/svg/helpers.cjs +30 -0
- package/dist/modules/svg/helpers.d.ts +2 -0
- package/dist/modules/svg/helpers.js +28 -0
- package/dist/modules/svg/index.cjs +18 -0
- package/dist/modules/svg/index.d.ts +3 -0
- package/dist/modules/svg/index.js +10 -0
- package/dist/modules/svg/morphto.cjs +58 -0
- package/dist/modules/svg/morphto.d.ts +3 -0
- package/dist/modules/svg/morphto.js +56 -0
- package/dist/modules/svg/motionpath.cjs +79 -0
- package/dist/modules/svg/motionpath.d.ts +7 -0
- package/dist/modules/svg/motionpath.js +77 -0
- package/dist/modules/text/index.cjs +16 -0
- package/dist/modules/text/index.d.ts +1 -0
- package/dist/modules/text/index.js +8 -0
- package/dist/modules/text/split.cjs +488 -0
- package/dist/modules/text/split.d.ts +62 -0
- package/dist/modules/text/split.js +484 -0
- package/dist/modules/timeline/index.cjs +15 -0
- package/dist/modules/timeline/index.d.ts +1 -0
- package/dist/modules/timeline/index.js +8 -0
- package/dist/modules/timeline/position.cjs +72 -0
- package/dist/modules/timeline/position.d.ts +3 -0
- package/dist/modules/timeline/position.js +70 -0
- package/dist/modules/timeline/timeline.cjs +312 -0
- package/dist/modules/timeline/timeline.d.ts +163 -0
- package/dist/modules/timeline/timeline.js +309 -0
- package/dist/modules/timer/index.cjs +15 -0
- package/dist/modules/timer/index.d.ts +1 -0
- package/dist/modules/timer/index.js +8 -0
- package/dist/modules/timer/timer.cjs +491 -0
- package/dist/modules/timer/timer.d.ts +141 -0
- package/dist/modules/timer/timer.js +488 -0
- package/dist/modules/types/index.d.ts +387 -0
- package/dist/modules/utils/chainable.cjs +190 -0
- package/dist/modules/utils/chainable.d.ts +135 -0
- package/dist/modules/utils/chainable.js +177 -0
- package/dist/modules/utils/index.cjs +43 -0
- package/dist/modules/utils/index.d.ts +5 -0
- package/dist/modules/utils/index.js +14 -0
- package/dist/modules/utils/number.cjs +97 -0
- package/dist/modules/utils/number.d.ts +9 -0
- package/dist/modules/utils/number.js +85 -0
- package/dist/modules/utils/random.cjs +77 -0
- package/dist/modules/utils/random.d.ts +22 -0
- package/dist/modules/utils/random.js +72 -0
- package/dist/modules/utils/stagger.cjs +122 -0
- package/dist/modules/utils/stagger.d.ts +30 -0
- package/dist/modules/utils/stagger.js +120 -0
- package/dist/modules/utils/target.cjs +130 -0
- package/dist/modules/utils/target.d.ts +126 -0
- package/dist/modules/utils/target.js +125 -0
- package/dist/modules/utils/time.cjs +57 -0
- package/dist/modules/utils/time.d.ts +5 -0
- package/dist/modules/utils/time.js +54 -0
- package/dist/modules/waapi/composition.cjs +89 -0
- package/dist/modules/waapi/composition.d.ts +4 -0
- package/dist/modules/waapi/composition.js +86 -0
- package/dist/modules/waapi/index.cjs +15 -0
- package/dist/modules/waapi/index.d.ts +1 -0
- package/dist/modules/waapi/index.js +8 -0
- package/dist/modules/waapi/waapi.cjs +473 -0
- package/dist/modules/waapi/waapi.d.ts +114 -0
- package/dist/modules/waapi/waapi.js +470 -0
- package/package.json +130 -33
- package/lib/anime.cjs +0 -9
- package/lib/anime.esm.min.js +0 -9
- package/lib/anime.iife.js +0 -9
- package/lib/anime.iife.min.js +0 -9
- package/lib/anime.min.cjs +0 -9
- package/lib/anime.umd.js +0 -9
- package/lib/anime.umd.min.js +0 -9
- package/lib/gui/index.js +0 -6341
- package/types/index.d.ts +0 -1081
- package/types/index.js +0 -7407
|
@@ -0,0 +1,1226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anime.js - draggable - CJS
|
|
3
|
+
* @version v4.2.0
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @copyright 2025 - Julian Garnier
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
var globals = require('../core/globals.cjs');
|
|
11
|
+
var consts = require('../core/consts.cjs');
|
|
12
|
+
var targets = require('../core/targets.cjs');
|
|
13
|
+
var helpers = require('../core/helpers.cjs');
|
|
14
|
+
var values = require('../core/values.cjs');
|
|
15
|
+
var number = require('../utils/number.cjs');
|
|
16
|
+
var timer = require('../timer/timer.cjs');
|
|
17
|
+
var animation = require('../animation/animation.cjs');
|
|
18
|
+
var composition = require('../animation/composition.cjs');
|
|
19
|
+
var animatable = require('../animatable/animatable.cjs');
|
|
20
|
+
var eases = require('../easings/eases.cjs');
|
|
21
|
+
var spring = require('../spring/spring.cjs');
|
|
22
|
+
var target = require('../utils/target.cjs');
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @import {
|
|
26
|
+
* DOMTarget,
|
|
27
|
+
* DOMTargetSelector,
|
|
28
|
+
* DraggableCursorParams,
|
|
29
|
+
* TargetsParam,
|
|
30
|
+
* DraggableParams,
|
|
31
|
+
* EasingFunction,
|
|
32
|
+
* Callback,
|
|
33
|
+
* AnimatableParams,
|
|
34
|
+
* DraggableAxisParam,
|
|
35
|
+
* AnimatableObject,
|
|
36
|
+
* EasingParam,
|
|
37
|
+
* } from '../types/index.js'
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @import {
|
|
42
|
+
* Spring,
|
|
43
|
+
* } from '../spring/spring.js'
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {Event} e
|
|
48
|
+
*/
|
|
49
|
+
const preventDefault = e => {
|
|
50
|
+
if (e.cancelable) e.preventDefault();
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
class DOMProxy {
|
|
54
|
+
/** @param {Object} el */
|
|
55
|
+
constructor(el) {
|
|
56
|
+
this.el = el;
|
|
57
|
+
this.zIndex = 0;
|
|
58
|
+
this.parentElement = null;
|
|
59
|
+
this.classList = {
|
|
60
|
+
add: consts.noop,
|
|
61
|
+
remove: consts.noop,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get x() { return this.el.x || 0 };
|
|
66
|
+
set x(v) { this.el.x = v; };
|
|
67
|
+
|
|
68
|
+
get y() { return this.el.y || 0 };
|
|
69
|
+
set y(v) { this.el.y = v; };
|
|
70
|
+
|
|
71
|
+
get width() { return this.el.width || 0 };
|
|
72
|
+
set width(v) { this.el.width = v; };
|
|
73
|
+
|
|
74
|
+
get height() { return this.el.height || 0 };
|
|
75
|
+
set height(v) { this.el.height = v; };
|
|
76
|
+
|
|
77
|
+
getBoundingClientRect() {
|
|
78
|
+
return {
|
|
79
|
+
top: this.y,
|
|
80
|
+
right: this.x,
|
|
81
|
+
bottom: this.y + this.height,
|
|
82
|
+
left: this.x + this.width,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
class Transforms {
|
|
88
|
+
/**
|
|
89
|
+
* @param {DOMTarget|DOMProxy} $el
|
|
90
|
+
*/
|
|
91
|
+
constructor($el) {
|
|
92
|
+
this.$el = $el;
|
|
93
|
+
this.inlineTransforms = [];
|
|
94
|
+
this.point = new DOMPoint();
|
|
95
|
+
this.inversedMatrix = this.getMatrix().inverse();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @param {Number} x
|
|
100
|
+
* @param {Number} y
|
|
101
|
+
* @return {DOMPoint}
|
|
102
|
+
*/
|
|
103
|
+
normalizePoint(x, y) {
|
|
104
|
+
this.point.x = x;
|
|
105
|
+
this.point.y = y;
|
|
106
|
+
return this.point.matrixTransform(this.inversedMatrix);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @callback TraverseParentsCallback
|
|
111
|
+
* @param {DOMTarget} $el
|
|
112
|
+
* @param {Number} i
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @param {TraverseParentsCallback} cb
|
|
117
|
+
*/
|
|
118
|
+
traverseUp(cb) {
|
|
119
|
+
let $el = /** @type {DOMTarget|Document} */(this.$el.parentElement), i = 0;
|
|
120
|
+
while ($el && $el !== consts.doc) {
|
|
121
|
+
cb(/** @type {DOMTarget} */($el), i);
|
|
122
|
+
$el = /** @type {DOMTarget} */($el.parentElement);
|
|
123
|
+
i++;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
getMatrix() {
|
|
128
|
+
const matrix = new DOMMatrix();
|
|
129
|
+
this.traverseUp($el => {
|
|
130
|
+
const transformValue = getComputedStyle($el).transform;
|
|
131
|
+
if (transformValue) {
|
|
132
|
+
const elMatrix = new DOMMatrix(transformValue);
|
|
133
|
+
matrix.preMultiplySelf(elMatrix);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
return matrix;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
remove() {
|
|
140
|
+
this.traverseUp(($el, i) => {
|
|
141
|
+
this.inlineTransforms[i] = $el.style.transform;
|
|
142
|
+
$el.style.transform = 'none';
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
revert() {
|
|
147
|
+
this.traverseUp(($el, i) => {
|
|
148
|
+
const ct = this.inlineTransforms[i];
|
|
149
|
+
if (ct === '') {
|
|
150
|
+
$el.style.removeProperty('transform');
|
|
151
|
+
} else {
|
|
152
|
+
$el.style.transform = ct;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @template {Array<Number>|DOMTargetSelector|String|Number|Boolean|Function|DraggableCursorParams} T
|
|
160
|
+
* @param {T | ((draggable: Draggable) => T)} value
|
|
161
|
+
* @param {Draggable} draggable
|
|
162
|
+
* @return {T}
|
|
163
|
+
*/
|
|
164
|
+
const parseDraggableFunctionParameter = (value, draggable) => value && helpers.isFnc(value) ? /** @type {Function} */(value)(draggable) : /** @type {T} */(value);
|
|
165
|
+
|
|
166
|
+
let zIndex = 0;
|
|
167
|
+
|
|
168
|
+
class Draggable {
|
|
169
|
+
/**
|
|
170
|
+
* @param {TargetsParam} target
|
|
171
|
+
* @param {DraggableParams} [parameters]
|
|
172
|
+
*/
|
|
173
|
+
constructor(target$1, parameters = {}) {
|
|
174
|
+
if (!target$1) return;
|
|
175
|
+
if (globals.scope.current) globals.scope.current.register(this);
|
|
176
|
+
const paramX = parameters.x;
|
|
177
|
+
const paramY = parameters.y;
|
|
178
|
+
const trigger = parameters.trigger;
|
|
179
|
+
const modifier = parameters.modifier;
|
|
180
|
+
const ease = parameters.releaseEase;
|
|
181
|
+
const customEase = ease && eases.parseEase(ease);
|
|
182
|
+
const hasSpring = !helpers.isUnd(ease) && !helpers.isUnd(/** @type {Spring} */(ease).ease);
|
|
183
|
+
const xProp = /** @type {String} */(helpers.isObj(paramX) && !helpers.isUnd(/** @type {Object} */(paramX).mapTo) ? /** @type {Object} */(paramX).mapTo : 'translateX');
|
|
184
|
+
const yProp = /** @type {String} */(helpers.isObj(paramY) && !helpers.isUnd(/** @type {Object} */(paramY).mapTo) ? /** @type {Object} */(paramY).mapTo : 'translateY');
|
|
185
|
+
const container = parseDraggableFunctionParameter(parameters.container, this);
|
|
186
|
+
this.containerArray = helpers.isArr(container) ? container : null;
|
|
187
|
+
this.$container = /** @type {HTMLElement} */(container && !this.containerArray ? targets.parseTargets(/** @type {DOMTarget} */(container))[0] : consts.doc.body);
|
|
188
|
+
this.useWin = this.$container === consts.doc.body;
|
|
189
|
+
/** @type {Window | HTMLElement} */
|
|
190
|
+
this.$scrollContainer = this.useWin ? consts.win : this.$container;
|
|
191
|
+
this.$target = /** @type {HTMLElement} */(helpers.isObj(target$1) ? new DOMProxy(target$1) : targets.parseTargets(target$1)[0]);
|
|
192
|
+
this.$trigger = /** @type {HTMLElement} */(targets.parseTargets(trigger ? trigger : target$1)[0]);
|
|
193
|
+
this.fixed = target.get(this.$target, 'position') === 'fixed';
|
|
194
|
+
// Refreshable parameters
|
|
195
|
+
this.isFinePointer = true;
|
|
196
|
+
/** @type {[Number, Number, Number, Number]} */
|
|
197
|
+
this.containerPadding = [0, 0, 0, 0];
|
|
198
|
+
/** @type {Number} */
|
|
199
|
+
this.containerFriction = 0;
|
|
200
|
+
/** @type {Number} */
|
|
201
|
+
this.releaseContainerFriction = 0;
|
|
202
|
+
/** @type {Number|Array<Number>} */
|
|
203
|
+
this.snapX = 0;
|
|
204
|
+
/** @type {Number|Array<Number>} */
|
|
205
|
+
this.snapY = 0;
|
|
206
|
+
/** @type {Number} */
|
|
207
|
+
this.scrollSpeed = 0;
|
|
208
|
+
/** @type {Number} */
|
|
209
|
+
this.scrollThreshold = 0;
|
|
210
|
+
/** @type {Number} */
|
|
211
|
+
this.dragSpeed = 0;
|
|
212
|
+
/** @type {Number} */
|
|
213
|
+
this.maxVelocity = 0;
|
|
214
|
+
/** @type {Number} */
|
|
215
|
+
this.minVelocity = 0;
|
|
216
|
+
/** @type {Number} */
|
|
217
|
+
this.velocityMultiplier = 0;
|
|
218
|
+
/** @type {Boolean|DraggableCursorParams} */
|
|
219
|
+
this.cursor = false;
|
|
220
|
+
/** @type {Spring} */
|
|
221
|
+
this.releaseXSpring = hasSpring ? /** @type {Spring} */(ease) : spring.createSpring({
|
|
222
|
+
mass: values.setValue(parameters.releaseMass, 1),
|
|
223
|
+
stiffness: values.setValue(parameters.releaseStiffness, 80),
|
|
224
|
+
damping: values.setValue(parameters.releaseDamping, 20),
|
|
225
|
+
});
|
|
226
|
+
/** @type {Spring} */
|
|
227
|
+
this.releaseYSpring = hasSpring ? /** @type {Spring} */(ease) : spring.createSpring({
|
|
228
|
+
mass: values.setValue(parameters.releaseMass, 1),
|
|
229
|
+
stiffness: values.setValue(parameters.releaseStiffness, 80),
|
|
230
|
+
damping: values.setValue(parameters.releaseDamping, 20),
|
|
231
|
+
});
|
|
232
|
+
/** @type {EasingFunction} */
|
|
233
|
+
this.releaseEase = customEase || eases.eases.outQuint;
|
|
234
|
+
/** @type {Boolean} */
|
|
235
|
+
this.hasReleaseSpring = hasSpring;
|
|
236
|
+
/** @type {Callback<this>} */
|
|
237
|
+
this.onGrab = parameters.onGrab || consts.noop;
|
|
238
|
+
/** @type {Callback<this>} */
|
|
239
|
+
this.onDrag = parameters.onDrag || consts.noop;
|
|
240
|
+
/** @type {Callback<this>} */
|
|
241
|
+
this.onRelease = parameters.onRelease || consts.noop;
|
|
242
|
+
/** @type {Callback<this>} */
|
|
243
|
+
this.onUpdate = parameters.onUpdate || consts.noop;
|
|
244
|
+
/** @type {Callback<this>} */
|
|
245
|
+
this.onSettle = parameters.onSettle || consts.noop;
|
|
246
|
+
/** @type {Callback<this>} */
|
|
247
|
+
this.onSnap = parameters.onSnap || consts.noop;
|
|
248
|
+
/** @type {Callback<this>} */
|
|
249
|
+
this.onResize = parameters.onResize || consts.noop;
|
|
250
|
+
/** @type {Callback<this>} */
|
|
251
|
+
this.onAfterResize = parameters.onAfterResize || consts.noop;
|
|
252
|
+
/** @type {[Number, Number]} */
|
|
253
|
+
this.disabled = [0, 0];
|
|
254
|
+
/** @type {AnimatableParams} */
|
|
255
|
+
const animatableParams = {};
|
|
256
|
+
if (modifier) animatableParams.modifier = modifier;
|
|
257
|
+
if (helpers.isUnd(paramX) || paramX === true) {
|
|
258
|
+
animatableParams[xProp] = 0;
|
|
259
|
+
} else if (helpers.isObj(paramX)) {
|
|
260
|
+
const paramXObject = /** @type {DraggableAxisParam} */(paramX);
|
|
261
|
+
const animatableXParams = {};
|
|
262
|
+
if (paramXObject.modifier) animatableXParams.modifier = paramXObject.modifier;
|
|
263
|
+
if (paramXObject.composition) animatableXParams.composition = paramXObject.composition;
|
|
264
|
+
animatableParams[xProp] = animatableXParams;
|
|
265
|
+
} else if (paramX === false) {
|
|
266
|
+
animatableParams[xProp] = 0;
|
|
267
|
+
this.disabled[0] = 1;
|
|
268
|
+
}
|
|
269
|
+
if (helpers.isUnd(paramY) || paramY === true) {
|
|
270
|
+
animatableParams[yProp] = 0;
|
|
271
|
+
} else if (helpers.isObj(paramY)) {
|
|
272
|
+
const paramYObject = /** @type {DraggableAxisParam} */(paramY);
|
|
273
|
+
const animatableYParams = {};
|
|
274
|
+
if (paramYObject.modifier) animatableYParams.modifier = paramYObject.modifier;
|
|
275
|
+
if (paramYObject.composition) animatableYParams.composition = paramYObject.composition;
|
|
276
|
+
animatableParams[yProp] = animatableYParams;
|
|
277
|
+
} else if (paramY === false) {
|
|
278
|
+
animatableParams[yProp] = 0;
|
|
279
|
+
this.disabled[1] = 1;
|
|
280
|
+
}
|
|
281
|
+
/** @type {AnimatableObject} */
|
|
282
|
+
this.animate = /** @type {AnimatableObject} */(new animatable.Animatable(this.$target, animatableParams));
|
|
283
|
+
// Internal props
|
|
284
|
+
this.xProp = xProp;
|
|
285
|
+
this.yProp = yProp;
|
|
286
|
+
this.destX = 0;
|
|
287
|
+
this.destY = 0;
|
|
288
|
+
this.deltaX = 0;
|
|
289
|
+
this.deltaY = 0;
|
|
290
|
+
this.scroll = {x: 0, y: 0};
|
|
291
|
+
/** @type {[Number, Number, Number, Number]} */
|
|
292
|
+
this.coords = [this.x, this.y, 0, 0]; // x, y, temp x, temp y
|
|
293
|
+
/** @type {[Number, Number]} */
|
|
294
|
+
this.snapped = [0, 0]; // x, y
|
|
295
|
+
/** @type {[Number, Number, Number, Number, Number, Number, Number, Number]} */
|
|
296
|
+
this.pointer = [0, 0, 0, 0, 0, 0, 0, 0]; // x1, y1, x2, y2, temp x1, temp y1, temp x2, temp y2
|
|
297
|
+
/** @type {[Number, Number]} */
|
|
298
|
+
this.scrollView = [0, 0]; // w, h
|
|
299
|
+
/** @type {[Number, Number, Number, Number]} */
|
|
300
|
+
this.dragArea = [0, 0, 0, 0]; // x, y, w, h
|
|
301
|
+
/** @type {[Number, Number, Number, Number]} */
|
|
302
|
+
this.containerBounds = [-consts.maxValue, consts.maxValue, consts.maxValue, -consts.maxValue]; // t, r, b, l
|
|
303
|
+
/** @type {[Number, Number, Number, Number]} */
|
|
304
|
+
this.scrollBounds = [0, 0, 0, 0]; // t, r, b, l
|
|
305
|
+
/** @type {[Number, Number, Number, Number]} */
|
|
306
|
+
this.targetBounds = [0, 0, 0, 0]; // t, r, b, l
|
|
307
|
+
/** @type {[Number, Number]} */
|
|
308
|
+
this.window = [0, 0]; // w, h
|
|
309
|
+
/** @type {[Number, Number, Number]} */
|
|
310
|
+
this.velocityStack = [0, 0, 0];
|
|
311
|
+
/** @type {Number} */
|
|
312
|
+
this.velocityStackIndex = 0;
|
|
313
|
+
/** @type {Number} */
|
|
314
|
+
this.velocityTime = helpers.now();
|
|
315
|
+
/** @type {Number} */
|
|
316
|
+
this.velocity = 0;
|
|
317
|
+
/** @type {Number} */
|
|
318
|
+
this.angle = 0;
|
|
319
|
+
/** @type {JSAnimation} */
|
|
320
|
+
this.cursorStyles = null;
|
|
321
|
+
/** @type {JSAnimation} */
|
|
322
|
+
this.triggerStyles = null;
|
|
323
|
+
/** @type {JSAnimation} */
|
|
324
|
+
this.bodyStyles = null;
|
|
325
|
+
/** @type {JSAnimation} */
|
|
326
|
+
this.targetStyles = null;
|
|
327
|
+
/** @type {JSAnimation} */
|
|
328
|
+
this.touchActionStyles = null;
|
|
329
|
+
this.transforms = new Transforms(this.$target);
|
|
330
|
+
this.overshootCoords = { x: 0, y: 0 };
|
|
331
|
+
this.overshootTicker = new timer.Timer({
|
|
332
|
+
autoplay: false,
|
|
333
|
+
onUpdate: () => {
|
|
334
|
+
this.updated = true;
|
|
335
|
+
this.manual = true;
|
|
336
|
+
// Use a duration of 1 to prevent the animatable from completing immediately to prevent issues with onSettle()
|
|
337
|
+
// https://github.com/juliangarnier/anime/issues/1045
|
|
338
|
+
if (!this.disabled[0]) this.animate[this.xProp](this.overshootCoords.x, 1);
|
|
339
|
+
if (!this.disabled[1]) this.animate[this.yProp](this.overshootCoords.y, 1);
|
|
340
|
+
},
|
|
341
|
+
onComplete: () => {
|
|
342
|
+
this.manual = false;
|
|
343
|
+
if (!this.disabled[0]) this.animate[this.xProp](this.overshootCoords.x, 0);
|
|
344
|
+
if (!this.disabled[1]) this.animate[this.yProp](this.overshootCoords.y, 0);
|
|
345
|
+
},
|
|
346
|
+
}, null, 0).init();
|
|
347
|
+
this.updateTicker = new timer.Timer({ autoplay: false, onUpdate: () => this.update() }, null,0,).init();
|
|
348
|
+
this.contained = !helpers.isUnd(container);
|
|
349
|
+
this.manual = false;
|
|
350
|
+
this.grabbed = false;
|
|
351
|
+
this.dragged = false;
|
|
352
|
+
this.updated = false;
|
|
353
|
+
this.released = false;
|
|
354
|
+
this.canScroll = false;
|
|
355
|
+
this.enabled = false;
|
|
356
|
+
this.initialized = false;
|
|
357
|
+
this.activeProp = this.disabled[1] ? xProp : yProp;
|
|
358
|
+
this.animate.callbacks.onRender = () => {
|
|
359
|
+
const hasUpdated = this.updated;
|
|
360
|
+
const hasMoved = this.grabbed && hasUpdated;
|
|
361
|
+
const hasReleased = !hasMoved && this.released;
|
|
362
|
+
const x = this.x;
|
|
363
|
+
const y = this.y;
|
|
364
|
+
const dx = x - this.coords[2];
|
|
365
|
+
const dy = y - this.coords[3];
|
|
366
|
+
this.deltaX = dx;
|
|
367
|
+
this.deltaY = dy;
|
|
368
|
+
this.coords[2] = x;
|
|
369
|
+
this.coords[3] = y;
|
|
370
|
+
// Check if dx or dy are not 0 to check if the draggable has actually moved
|
|
371
|
+
// https://github.com/juliangarnier/anime/issues/1032
|
|
372
|
+
if (hasUpdated && (dx || dy)) {
|
|
373
|
+
this.onUpdate(this);
|
|
374
|
+
}
|
|
375
|
+
if (!hasReleased) {
|
|
376
|
+
this.updated = false;
|
|
377
|
+
} else {
|
|
378
|
+
this.computeVelocity(dx, dy);
|
|
379
|
+
this.angle = helpers.atan2(dy, dx);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
this.animate.callbacks.onComplete = () => {
|
|
383
|
+
if ((!this.grabbed && this.released)) {
|
|
384
|
+
// Set released to false before calling onSettle to avoid recursion
|
|
385
|
+
this.released = false;
|
|
386
|
+
}
|
|
387
|
+
if (!this.manual) {
|
|
388
|
+
this.deltaX = 0;
|
|
389
|
+
this.deltaY = 0;
|
|
390
|
+
this.velocity = 0;
|
|
391
|
+
this.velocityStack[0] = 0;
|
|
392
|
+
this.velocityStack[1] = 0;
|
|
393
|
+
this.velocityStack[2] = 0;
|
|
394
|
+
this.velocityStackIndex = 0;
|
|
395
|
+
this.onSettle(this);
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
this.resizeTicker = new timer.Timer({
|
|
399
|
+
autoplay: false,
|
|
400
|
+
duration: 150 * globals.globals.timeScale,
|
|
401
|
+
onComplete: () => {
|
|
402
|
+
this.onResize(this);
|
|
403
|
+
this.refresh();
|
|
404
|
+
this.onAfterResize(this);
|
|
405
|
+
},
|
|
406
|
+
}).init();
|
|
407
|
+
this.parameters = parameters;
|
|
408
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
409
|
+
if (this.initialized) {
|
|
410
|
+
this.resizeTicker.restart();
|
|
411
|
+
} else {
|
|
412
|
+
this.initialized = true;
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
this.enable();
|
|
416
|
+
this.refresh();
|
|
417
|
+
this.resizeObserver.observe(this.$container);
|
|
418
|
+
if (!helpers.isObj(target$1)) this.resizeObserver.observe(this.$target);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* @param {Number} dx
|
|
423
|
+
* @param {Number} dy
|
|
424
|
+
* @return {Number}
|
|
425
|
+
*/
|
|
426
|
+
computeVelocity(dx, dy) {
|
|
427
|
+
const prevTime = this.velocityTime;
|
|
428
|
+
const curTime = helpers.now();
|
|
429
|
+
const elapsed = curTime - prevTime;
|
|
430
|
+
if (elapsed < 17) return this.velocity;
|
|
431
|
+
this.velocityTime = curTime;
|
|
432
|
+
const velocityStack = this.velocityStack;
|
|
433
|
+
const vMul = this.velocityMultiplier;
|
|
434
|
+
const minV = this.minVelocity;
|
|
435
|
+
const maxV = this.maxVelocity;
|
|
436
|
+
const vi = this.velocityStackIndex;
|
|
437
|
+
velocityStack[vi] = helpers.round(helpers.clamp((helpers.sqrt(dx * dx + dy * dy) / elapsed) * vMul, minV, maxV), 5);
|
|
438
|
+
const velocity = helpers.max(velocityStack[0], velocityStack[1], velocityStack[2]);
|
|
439
|
+
this.velocity = velocity;
|
|
440
|
+
this.velocityStackIndex = (vi + 1) % 3;
|
|
441
|
+
return velocity;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* @param {Number} x
|
|
446
|
+
* @param {Boolean} [muteUpdateCallback]
|
|
447
|
+
* @return {this}
|
|
448
|
+
*/
|
|
449
|
+
setX(x, muteUpdateCallback = false) {
|
|
450
|
+
if (this.disabled[0]) return;
|
|
451
|
+
const v = helpers.round(x, 5);
|
|
452
|
+
this.overshootTicker.pause();
|
|
453
|
+
this.manual = true;
|
|
454
|
+
this.updated = !muteUpdateCallback;
|
|
455
|
+
this.destX = v;
|
|
456
|
+
this.snapped[0] = helpers.snap(v, this.snapX);
|
|
457
|
+
this.animate[this.xProp](v, 0);
|
|
458
|
+
this.manual = false;
|
|
459
|
+
return this;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* @param {Number} y
|
|
464
|
+
* @param {Boolean} [muteUpdateCallback]
|
|
465
|
+
* @return {this}
|
|
466
|
+
*/
|
|
467
|
+
setY(y, muteUpdateCallback = false) {
|
|
468
|
+
if (this.disabled[1]) return;
|
|
469
|
+
const v = helpers.round(y, 5);
|
|
470
|
+
this.overshootTicker.pause();
|
|
471
|
+
this.manual = true;
|
|
472
|
+
this.updated = !muteUpdateCallback;
|
|
473
|
+
this.destY = v;
|
|
474
|
+
this.snapped[1] = helpers.snap(v, this.snapY);
|
|
475
|
+
this.animate[this.yProp](v, 0);
|
|
476
|
+
this.manual = false;
|
|
477
|
+
return this;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
get x() {
|
|
481
|
+
return helpers.round(/** @type {Number} */(this.animate[this.xProp]()), globals.globals.precision);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
set x(x) {
|
|
485
|
+
this.setX(x, false);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
get y() {
|
|
489
|
+
return helpers.round(/** @type {Number} */(this.animate[this.yProp]()), globals.globals.precision);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
set y(y) {
|
|
493
|
+
this.setY(y, false);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
get progressX() {
|
|
497
|
+
return number.mapRange(this.x, this.containerBounds[3], this.containerBounds[1], 0, 1);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
set progressX(x) {
|
|
501
|
+
this.setX(number.mapRange(x, 0, 1, this.containerBounds[3], this.containerBounds[1]), false);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
get progressY() {
|
|
505
|
+
return number.mapRange(this.y, this.containerBounds[0], this.containerBounds[2], 0, 1);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
set progressY(y) {
|
|
509
|
+
this.setY(number.mapRange(y, 0, 1, this.containerBounds[0], this.containerBounds[2]), false);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
updateScrollCoords() {
|
|
513
|
+
const sx = helpers.round(this.useWin ? consts.win.scrollX : this.$container.scrollLeft, 0);
|
|
514
|
+
const sy = helpers.round(this.useWin ? consts.win.scrollY : this.$container.scrollTop, 0);
|
|
515
|
+
const [ cpt, cpr, cpb, cpl ] = this.containerPadding;
|
|
516
|
+
const threshold = this.scrollThreshold;
|
|
517
|
+
this.scroll.x = sx;
|
|
518
|
+
this.scroll.y = sy;
|
|
519
|
+
this.scrollBounds[0] = sy - this.targetBounds[0] + cpt - threshold;
|
|
520
|
+
this.scrollBounds[1] = sx - this.targetBounds[1] - cpr + threshold;
|
|
521
|
+
this.scrollBounds[2] = sy - this.targetBounds[2] - cpb + threshold;
|
|
522
|
+
this.scrollBounds[3] = sx - this.targetBounds[3] + cpl - threshold;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
updateBoundingValues() {
|
|
526
|
+
const $container = this.$container;
|
|
527
|
+
// Return early if no $container defined to prevents error when reading scrollWidth / scrollHeight
|
|
528
|
+
// https://github.com/juliangarnier/anime/issues/1064
|
|
529
|
+
if (!$container) return;
|
|
530
|
+
const cx = this.x;
|
|
531
|
+
const cy = this.y;
|
|
532
|
+
const cx2 = this.coords[2];
|
|
533
|
+
const cy2 = this.coords[3];
|
|
534
|
+
// Prevents interfering with the scroll area in cases the target is outside of the container
|
|
535
|
+
// Make sure the temp coords are also adjuset to prevents wrong delta calculation on updates
|
|
536
|
+
this.coords[2] = 0;
|
|
537
|
+
this.coords[3] = 0;
|
|
538
|
+
this.setX(0, true);
|
|
539
|
+
this.setY(0, true);
|
|
540
|
+
this.transforms.remove();
|
|
541
|
+
const iw = this.window[0] = consts.win.innerWidth;
|
|
542
|
+
const ih = this.window[1] = consts.win.innerHeight;
|
|
543
|
+
const uw = this.useWin;
|
|
544
|
+
const sw = $container.scrollWidth;
|
|
545
|
+
const sh = $container.scrollHeight;
|
|
546
|
+
const fx = this.fixed;
|
|
547
|
+
const transformContainerRect = $container.getBoundingClientRect();
|
|
548
|
+
const [ cpt, cpr, cpb, cpl ] = this.containerPadding;
|
|
549
|
+
this.dragArea[0] = uw ? 0 : transformContainerRect.left;
|
|
550
|
+
this.dragArea[1] = uw ? 0 : transformContainerRect.top;
|
|
551
|
+
this.scrollView[0] = uw ? helpers.clamp(sw, iw, sw) : sw;
|
|
552
|
+
this.scrollView[1] = uw ? helpers.clamp(sh, ih, sh) : sh;
|
|
553
|
+
this.updateScrollCoords();
|
|
554
|
+
const { width, height, left, top, right, bottom } = $container.getBoundingClientRect();
|
|
555
|
+
this.dragArea[2] = helpers.round(uw ? helpers.clamp(width, iw, iw) : width, 0);
|
|
556
|
+
this.dragArea[3] = helpers.round(uw ? helpers.clamp(height, ih, ih) : height, 0);
|
|
557
|
+
const containerOverflow = target.get($container, 'overflow');
|
|
558
|
+
const visibleOverflow = containerOverflow === 'visible';
|
|
559
|
+
const hiddenOverflow = containerOverflow === 'hidden';
|
|
560
|
+
this.canScroll = fx ? false :
|
|
561
|
+
this.contained &&
|
|
562
|
+
(($container === consts.doc.body && visibleOverflow) || (!hiddenOverflow && !visibleOverflow)) &&
|
|
563
|
+
(sw > this.dragArea[2] + cpl - cpr || sh > this.dragArea[3] + cpt - cpb) &&
|
|
564
|
+
(!this.containerArray || (this.containerArray && !helpers.isArr(this.containerArray)));
|
|
565
|
+
if (this.contained) {
|
|
566
|
+
const sx = this.scroll.x;
|
|
567
|
+
const sy = this.scroll.y;
|
|
568
|
+
const canScroll = this.canScroll;
|
|
569
|
+
const targetRect = this.$target.getBoundingClientRect();
|
|
570
|
+
const hiddenLeft = canScroll ? uw ? 0 : $container.scrollLeft : 0;
|
|
571
|
+
const hiddenTop = canScroll ? uw ? 0 : $container.scrollTop : 0;
|
|
572
|
+
const hiddenRight = canScroll ? this.scrollView[0] - hiddenLeft - width : 0;
|
|
573
|
+
const hiddenBottom = canScroll ? this.scrollView[1] - hiddenTop - height : 0;
|
|
574
|
+
this.targetBounds[0] = helpers.round((targetRect.top + sy) - (uw ? 0 : top), 0);
|
|
575
|
+
this.targetBounds[1] = helpers.round((targetRect.right + sx) - (uw ? iw : right), 0);
|
|
576
|
+
this.targetBounds[2] = helpers.round((targetRect.bottom + sy) - (uw ? ih : bottom), 0);
|
|
577
|
+
this.targetBounds[3] = helpers.round((targetRect.left + sx) - (uw ? 0 : left), 0);
|
|
578
|
+
if (this.containerArray) {
|
|
579
|
+
this.containerBounds[0] = this.containerArray[0] + cpt;
|
|
580
|
+
this.containerBounds[1] = this.containerArray[1] - cpr;
|
|
581
|
+
this.containerBounds[2] = this.containerArray[2] - cpb;
|
|
582
|
+
this.containerBounds[3] = this.containerArray[3] + cpl;
|
|
583
|
+
} else {
|
|
584
|
+
this.containerBounds[0] = -helpers.round(targetRect.top - (fx ? helpers.clamp(top, 0, ih) : top) + hiddenTop - cpt, 0);
|
|
585
|
+
this.containerBounds[1] = -helpers.round(targetRect.right - (fx ? helpers.clamp(right, 0, iw) : right) - hiddenRight + cpr, 0);
|
|
586
|
+
this.containerBounds[2] = -helpers.round(targetRect.bottom - (fx ? helpers.clamp(bottom, 0, ih) : bottom) - hiddenBottom + cpb, 0);
|
|
587
|
+
this.containerBounds[3] = -helpers.round(targetRect.left - (fx ? helpers.clamp(left, 0, iw) : left) + hiddenLeft - cpl, 0);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
this.transforms.revert();
|
|
591
|
+
// Restore coordinates
|
|
592
|
+
this.coords[2] = cx2;
|
|
593
|
+
this.coords[3] = cy2;
|
|
594
|
+
this.setX(cx, true);
|
|
595
|
+
this.setY(cy, true);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* @param {Array} bounds
|
|
600
|
+
* @param {Number} x
|
|
601
|
+
* @param {Number} y
|
|
602
|
+
* @return {Number}
|
|
603
|
+
*/
|
|
604
|
+
isOutOfBounds(bounds, x, y) {
|
|
605
|
+
// Returns 0 if not OB, 1 if x is OB, 2 if y is OB, 3 if both x and y are OB
|
|
606
|
+
if (!this.contained) return 0;
|
|
607
|
+
const [ bt, br, bb, bl ] = bounds;
|
|
608
|
+
const [ dx, dy ] = this.disabled;
|
|
609
|
+
const obx = !dx && x < bl || !dx && x > br;
|
|
610
|
+
const oby = !dy && y < bt || !dy && y > bb;
|
|
611
|
+
return obx && !oby ? 1 : !obx && oby ? 2 : obx && oby ? 3 : 0;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
refresh() {
|
|
615
|
+
const params = this.parameters;
|
|
616
|
+
const paramX = params.x;
|
|
617
|
+
const paramY = params.y;
|
|
618
|
+
const container = parseDraggableFunctionParameter(params.container, this);
|
|
619
|
+
const cp = parseDraggableFunctionParameter(params.containerPadding, this) || 0;
|
|
620
|
+
const containerPadding = /** @type {[Number, Number, Number, Number]} */(helpers.isArr(cp) ? cp : [cp, cp, cp, cp]);
|
|
621
|
+
const cx = this.x;
|
|
622
|
+
const cy = this.y;
|
|
623
|
+
const parsedCursorStyles = parseDraggableFunctionParameter(params.cursor, this);
|
|
624
|
+
const cursorStyles = { onHover: 'grab', onGrab: 'grabbing' };
|
|
625
|
+
if (parsedCursorStyles) {
|
|
626
|
+
const { onHover, onGrab } = /** @type {DraggableCursorParams} */(parsedCursorStyles);
|
|
627
|
+
if (onHover) cursorStyles.onHover = onHover;
|
|
628
|
+
if (onGrab) cursorStyles.onGrab = onGrab;
|
|
629
|
+
}
|
|
630
|
+
this.containerArray = helpers.isArr(container) ? container : null;
|
|
631
|
+
this.$container = /** @type {HTMLElement} */(container && !this.containerArray ? targets.parseTargets(/** @type {DOMTarget} */(container))[0] : consts.doc.body);
|
|
632
|
+
this.useWin = this.$container === consts.doc.body;
|
|
633
|
+
/** @type {Window | HTMLElement} */
|
|
634
|
+
this.$scrollContainer = this.useWin ? consts.win : this.$container;
|
|
635
|
+
this.isFinePointer = matchMedia('(pointer:fine)').matches;
|
|
636
|
+
this.containerPadding = values.setValue(containerPadding, [0, 0, 0, 0]);
|
|
637
|
+
this.containerFriction = helpers.clamp(values.setValue(parseDraggableFunctionParameter(params.containerFriction, this), .8), 0, 1);
|
|
638
|
+
this.releaseContainerFriction = helpers.clamp(values.setValue(parseDraggableFunctionParameter(params.releaseContainerFriction, this), this.containerFriction), 0, 1);
|
|
639
|
+
this.snapX = parseDraggableFunctionParameter(helpers.isObj(paramX) && !helpers.isUnd(paramX.snap) ? paramX.snap : params.snap, this);
|
|
640
|
+
this.snapY = parseDraggableFunctionParameter(helpers.isObj(paramY) && !helpers.isUnd(paramY.snap) ? paramY.snap : params.snap, this);
|
|
641
|
+
this.scrollSpeed = values.setValue(parseDraggableFunctionParameter(params.scrollSpeed, this), 1.5);
|
|
642
|
+
this.scrollThreshold = values.setValue(parseDraggableFunctionParameter(params.scrollThreshold, this), 20);
|
|
643
|
+
this.dragSpeed = values.setValue(parseDraggableFunctionParameter(params.dragSpeed, this), 1);
|
|
644
|
+
this.minVelocity = values.setValue(parseDraggableFunctionParameter(params.minVelocity, this), 0);
|
|
645
|
+
this.maxVelocity = values.setValue(parseDraggableFunctionParameter(params.maxVelocity, this), 50);
|
|
646
|
+
this.velocityMultiplier = values.setValue(parseDraggableFunctionParameter(params.velocityMultiplier, this), 1);
|
|
647
|
+
this.cursor = parsedCursorStyles === false ? false : cursorStyles;
|
|
648
|
+
this.updateBoundingValues();
|
|
649
|
+
|
|
650
|
+
// const ob = this.isOutOfBounds(this.containerBounds, this.x, this.y);
|
|
651
|
+
// if (ob === 1 || ob === 3) this.progressX = px;
|
|
652
|
+
// if (ob === 2 || ob === 3) this.progressY = py;
|
|
653
|
+
|
|
654
|
+
// if (this.initialized && this.contained) {
|
|
655
|
+
// if (this.progressX !== px) this.progressX = px;
|
|
656
|
+
// if (this.progressY !== py) this.progressY = py;
|
|
657
|
+
// }
|
|
658
|
+
|
|
659
|
+
const [ bt, br, bb, bl ] = this.containerBounds;
|
|
660
|
+
this.setX(helpers.clamp(cx, bl, br), true);
|
|
661
|
+
this.setY(helpers.clamp(cy, bt, bb), true);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
update() {
|
|
665
|
+
this.updateScrollCoords();
|
|
666
|
+
if (this.canScroll) {
|
|
667
|
+
const [ cpt, cpr, cpb, cpl ] = this.containerPadding;
|
|
668
|
+
const [ sw, sh ] = this.scrollView;
|
|
669
|
+
const daw = this.dragArea[2];
|
|
670
|
+
const dah = this.dragArea[3];
|
|
671
|
+
const csx = this.scroll.x;
|
|
672
|
+
const csy = this.scroll.y;
|
|
673
|
+
const nsw = this.$container.scrollWidth;
|
|
674
|
+
const nsh = this.$container.scrollHeight;
|
|
675
|
+
const csw = this.useWin ? helpers.clamp(nsw, this.window[0], nsw) : nsw;
|
|
676
|
+
const csh = this.useWin ? helpers.clamp(nsh, this.window[1], nsh) : nsh;
|
|
677
|
+
const swd = sw - csw;
|
|
678
|
+
const shd = sh - csh;
|
|
679
|
+
// Handle cases where the scrollarea dimensions changes during drag
|
|
680
|
+
if (this.dragged && swd > 0) {
|
|
681
|
+
this.coords[0] -= swd;
|
|
682
|
+
this.scrollView[0] = csw;
|
|
683
|
+
}
|
|
684
|
+
if (this.dragged && shd > 0) {
|
|
685
|
+
this.coords[1] -= shd;
|
|
686
|
+
this.scrollView[1] = csh;
|
|
687
|
+
}
|
|
688
|
+
// Handle autoscroll when target is at the edges of the scroll bounds
|
|
689
|
+
const s = this.scrollSpeed * 10;
|
|
690
|
+
const threshold = this.scrollThreshold;
|
|
691
|
+
const [ x, y ] = this.coords;
|
|
692
|
+
const [ st, sr, sb, sl ] = this.scrollBounds;
|
|
693
|
+
const t = helpers.round(helpers.clamp((y - st + cpt) / threshold, -1, 0) * s, 0);
|
|
694
|
+
const r = helpers.round(helpers.clamp((x - sr - cpr) / threshold, 0, 1) * s, 0);
|
|
695
|
+
const b = helpers.round(helpers.clamp((y - sb - cpb) / threshold, 0, 1) * s, 0);
|
|
696
|
+
const l = helpers.round(helpers.clamp((x - sl + cpl) / threshold, -1, 0) * s, 0);
|
|
697
|
+
if (t || b || l || r) {
|
|
698
|
+
const [nx, ny] = this.disabled;
|
|
699
|
+
let scrollX = csx;
|
|
700
|
+
let scrollY = csy;
|
|
701
|
+
if (!nx) {
|
|
702
|
+
scrollX = helpers.round(helpers.clamp(csx + (l || r), 0, sw - daw), 0);
|
|
703
|
+
this.coords[0] -= csx - scrollX;
|
|
704
|
+
}
|
|
705
|
+
if (!ny) {
|
|
706
|
+
scrollY = helpers.round(helpers.clamp(csy + (t || b), 0, sh - dah), 0);
|
|
707
|
+
this.coords[1] -= csy - scrollY;
|
|
708
|
+
}
|
|
709
|
+
// Note: Safari mobile requires to use different scroll methods depending if using the window or not
|
|
710
|
+
if (this.useWin) {
|
|
711
|
+
this.$scrollContainer.scrollBy(-(csx - scrollX), -(csy - scrollY));
|
|
712
|
+
} else {
|
|
713
|
+
this.$scrollContainer.scrollTo(scrollX, scrollY);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
const [ ct, cr, cb, cl ] = this.containerBounds;
|
|
718
|
+
const [ px1, py1, px2, py2, px3, py3 ] = this.pointer;
|
|
719
|
+
this.coords[0] += (px1 - px3) * this.dragSpeed;
|
|
720
|
+
this.coords[1] += (py1 - py3) * this.dragSpeed;
|
|
721
|
+
this.pointer[4] = px1;
|
|
722
|
+
this.pointer[5] = py1;
|
|
723
|
+
const [ cx, cy ] = this.coords;
|
|
724
|
+
const [ sx, sy ] = this.snapped;
|
|
725
|
+
const cf = (1 - this.containerFriction) * this.dragSpeed;
|
|
726
|
+
this.setX(cx > cr ? cr + (cx - cr) * cf : cx < cl ? cl + (cx - cl) * cf : cx, false);
|
|
727
|
+
this.setY(cy > cb ? cb + (cy - cb) * cf : cy < ct ? ct + (cy - ct) * cf : cy, false);
|
|
728
|
+
this.computeVelocity(px1 - px3, py1 - py3);
|
|
729
|
+
this.angle = helpers.atan2(py1 - py2, px1 - px2);
|
|
730
|
+
const [ nsx, nsy ] = this.snapped;
|
|
731
|
+
if (nsx !== sx && this.snapX || nsy !== sy && this.snapY) {
|
|
732
|
+
this.onSnap(this);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
stop() {
|
|
737
|
+
this.updateTicker.pause();
|
|
738
|
+
this.overshootTicker.pause();
|
|
739
|
+
// Pauses the in bounds onRelease animations
|
|
740
|
+
for (let prop in this.animate.animations) this.animate.animations[prop].pause();
|
|
741
|
+
composition.removeTargetsFromRenderable([this], null, 'x');
|
|
742
|
+
composition.removeTargetsFromRenderable([this], null, 'y');
|
|
743
|
+
composition.removeTargetsFromRenderable([this], null, 'progressX');
|
|
744
|
+
composition.removeTargetsFromRenderable([this], null, 'progressY');
|
|
745
|
+
composition.removeTargetsFromRenderable([this.scroll]); // Removes any active animations on the container scroll
|
|
746
|
+
composition.removeTargetsFromRenderable([this.overshootCoords]); // Removes active overshoot animations
|
|
747
|
+
return this;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* @param {Number} [duration]
|
|
752
|
+
* @param {Number} [gap]
|
|
753
|
+
* @param {EasingParam} [ease]
|
|
754
|
+
* @return {this}
|
|
755
|
+
*/
|
|
756
|
+
scrollInView(duration, gap = 0, ease = eases.eases.inOutQuad) {
|
|
757
|
+
this.updateScrollCoords();
|
|
758
|
+
const x = this.destX;
|
|
759
|
+
const y = this.destY;
|
|
760
|
+
const scroll = this.scroll;
|
|
761
|
+
const scrollBounds = this.scrollBounds;
|
|
762
|
+
const canScroll = this.canScroll;
|
|
763
|
+
if (!this.containerArray && this.isOutOfBounds(scrollBounds, x, y)) {
|
|
764
|
+
const [ st, sr, sb, sl ] = scrollBounds;
|
|
765
|
+
const t = helpers.round(helpers.clamp(y - st, -consts.maxValue, 0), 0);
|
|
766
|
+
const r = helpers.round(helpers.clamp(x - sr, 0, consts.maxValue), 0);
|
|
767
|
+
const b = helpers.round(helpers.clamp(y - sb, 0, consts.maxValue), 0);
|
|
768
|
+
const l = helpers.round(helpers.clamp(x - sl, -consts.maxValue, 0), 0);
|
|
769
|
+
new animation.JSAnimation(scroll, {
|
|
770
|
+
x: helpers.round(scroll.x + (l ? l - gap : r ? r + gap : 0), 0),
|
|
771
|
+
y: helpers.round(scroll.y + (t ? t - gap : b ? b + gap : 0), 0),
|
|
772
|
+
duration: helpers.isUnd(duration) ? 350 * globals.globals.timeScale : duration,
|
|
773
|
+
ease,
|
|
774
|
+
onUpdate: () => {
|
|
775
|
+
this.canScroll = false;
|
|
776
|
+
this.$scrollContainer.scrollTo(scroll.x, scroll.y);
|
|
777
|
+
}
|
|
778
|
+
}).init().then(() => {
|
|
779
|
+
this.canScroll = canScroll;
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
return this;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
handleHover() {
|
|
786
|
+
if (this.isFinePointer && this.cursor && !this.cursorStyles) {
|
|
787
|
+
this.cursorStyles = target.set(this.$trigger, {
|
|
788
|
+
cursor: /** @type {DraggableCursorParams} */(this.cursor).onHover
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* @param {Number} [duration]
|
|
795
|
+
* @param {Number} [gap]
|
|
796
|
+
* @param {EasingParam} [ease]
|
|
797
|
+
* @return {this}
|
|
798
|
+
*/
|
|
799
|
+
animateInView(duration, gap = 0, ease = eases.eases.inOutQuad) {
|
|
800
|
+
this.stop();
|
|
801
|
+
this.updateBoundingValues();
|
|
802
|
+
const x = this.x;
|
|
803
|
+
const y = this.y;
|
|
804
|
+
const [ cpt, cpr, cpb, cpl ] = this.containerPadding;
|
|
805
|
+
const bt = this.scroll.y - this.targetBounds[0] + cpt + gap;
|
|
806
|
+
const br = this.scroll.x - this.targetBounds[1] - cpr - gap;
|
|
807
|
+
const bb = this.scroll.y - this.targetBounds[2] - cpb - gap;
|
|
808
|
+
const bl = this.scroll.x - this.targetBounds[3] + cpl + gap;
|
|
809
|
+
const ob = this.isOutOfBounds([bt, br, bb, bl], x, y);
|
|
810
|
+
if (ob) {
|
|
811
|
+
const [ disabledX, disabledY ] = this.disabled;
|
|
812
|
+
const destX = helpers.clamp(helpers.snap(x, this.snapX), bl, br);
|
|
813
|
+
const destY = helpers.clamp(helpers.snap(y, this.snapY), bt, bb);
|
|
814
|
+
const dur = helpers.isUnd(duration) ? 350 * globals.globals.timeScale : duration;
|
|
815
|
+
if (!disabledX && (ob === 1 || ob === 3)) this.animate[this.xProp](destX, dur, ease);
|
|
816
|
+
if (!disabledY && (ob === 2 || ob === 3)) this.animate[this.yProp](destY, dur, ease);
|
|
817
|
+
}
|
|
818
|
+
return this;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* @param {MouseEvent|TouchEvent} e
|
|
823
|
+
*/
|
|
824
|
+
handleDown(e) {
|
|
825
|
+
const $eTarget = /** @type {HTMLElement} */(e.target);
|
|
826
|
+
if (this.grabbed || /** @type {HTMLInputElement} */($eTarget).type === 'range') return;
|
|
827
|
+
|
|
828
|
+
e.stopPropagation();
|
|
829
|
+
|
|
830
|
+
this.grabbed = true;
|
|
831
|
+
this.released = false;
|
|
832
|
+
this.stop();
|
|
833
|
+
this.updateBoundingValues();
|
|
834
|
+
const touches = /** @type {TouchEvent} */(e).changedTouches;
|
|
835
|
+
const eventX = touches ? touches[0].clientX : /** @type {MouseEvent} */(e).clientX;
|
|
836
|
+
const eventY = touches ? touches[0].clientY : /** @type {MouseEvent} */(e).clientY;
|
|
837
|
+
const { x, y } = this.transforms.normalizePoint(eventX, eventY);
|
|
838
|
+
const [ ct, cr, cb, cl ] = this.containerBounds;
|
|
839
|
+
const cf = (1 - this.containerFriction) * this.dragSpeed;
|
|
840
|
+
const cx = this.x;
|
|
841
|
+
const cy = this.y;
|
|
842
|
+
this.coords[0] = this.coords[2] = !cf ? cx : cx > cr ? cr + (cx - cr) / cf : cx < cl ? cl + (cx - cl) / cf : cx;
|
|
843
|
+
this.coords[1] = this.coords[3] = !cf ? cy : cy > cb ? cb + (cy - cb) / cf : cy < ct ? ct + (cy - ct) / cf : cy;
|
|
844
|
+
this.pointer[0] = x;
|
|
845
|
+
this.pointer[1] = y;
|
|
846
|
+
this.pointer[2] = x;
|
|
847
|
+
this.pointer[3] = y;
|
|
848
|
+
this.pointer[4] = x;
|
|
849
|
+
this.pointer[5] = y;
|
|
850
|
+
this.pointer[6] = x;
|
|
851
|
+
this.pointer[7] = y;
|
|
852
|
+
this.deltaX = 0;
|
|
853
|
+
this.deltaY = 0;
|
|
854
|
+
this.velocity = 0;
|
|
855
|
+
this.velocityStack[0] = 0;
|
|
856
|
+
this.velocityStack[1] = 0;
|
|
857
|
+
this.velocityStack[2] = 0;
|
|
858
|
+
this.velocityStackIndex = 0;
|
|
859
|
+
this.angle = 0;
|
|
860
|
+
if (this.targetStyles) {
|
|
861
|
+
this.targetStyles.revert();
|
|
862
|
+
this.targetStyles = null;
|
|
863
|
+
}
|
|
864
|
+
const z = /** @type {Number} */(target.get(this.$target, 'zIndex', false));
|
|
865
|
+
zIndex = (z > zIndex ? z : zIndex) + 1;
|
|
866
|
+
this.targetStyles = target.set(this.$target, { zIndex });
|
|
867
|
+
if (this.triggerStyles) {
|
|
868
|
+
this.triggerStyles.revert();
|
|
869
|
+
this.triggerStyles = null;
|
|
870
|
+
}
|
|
871
|
+
if (this.cursorStyles) {
|
|
872
|
+
this.cursorStyles.revert();
|
|
873
|
+
this.cursorStyles = null;
|
|
874
|
+
}
|
|
875
|
+
if (this.isFinePointer && this.cursor) {
|
|
876
|
+
this.bodyStyles = target.set(consts.doc.body, {
|
|
877
|
+
cursor: /** @type {DraggableCursorParams} */(this.cursor).onGrab
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
this.scrollInView(100, 0, eases.eases.out(3));
|
|
881
|
+
this.onGrab(this);
|
|
882
|
+
|
|
883
|
+
consts.doc.addEventListener('touchmove', this);
|
|
884
|
+
consts.doc.addEventListener('touchend', this);
|
|
885
|
+
consts.doc.addEventListener('touchcancel', this);
|
|
886
|
+
consts.doc.addEventListener('mousemove', this);
|
|
887
|
+
consts.doc.addEventListener('mouseup', this);
|
|
888
|
+
consts.doc.addEventListener('selectstart', this);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* @param {MouseEvent|TouchEvent} e
|
|
893
|
+
*/
|
|
894
|
+
handleMove(e) {
|
|
895
|
+
if (!this.grabbed) return;
|
|
896
|
+
const touches = /** @type {TouchEvent} */(e).changedTouches;
|
|
897
|
+
const eventX = touches ? touches[0].clientX : /** @type {MouseEvent} */(e).clientX;
|
|
898
|
+
const eventY = touches ? touches[0].clientY : /** @type {MouseEvent} */(e).clientY;
|
|
899
|
+
const { x, y } = this.transforms.normalizePoint(eventX, eventY);
|
|
900
|
+
const movedX = x - this.pointer[6];
|
|
901
|
+
const movedY = y - this.pointer[7];
|
|
902
|
+
|
|
903
|
+
let $parent = /** @type {HTMLElement} */(e.target);
|
|
904
|
+
let isAtTop = false;
|
|
905
|
+
let isAtBottom = false;
|
|
906
|
+
let canTouchScroll = false;
|
|
907
|
+
|
|
908
|
+
while (touches && $parent && $parent !== this.$trigger) {
|
|
909
|
+
const overflowY = target.get($parent, 'overflow-y');
|
|
910
|
+
if (overflowY !== 'hidden' && overflowY !== 'visible') {
|
|
911
|
+
const { scrollTop, scrollHeight, clientHeight } = $parent;
|
|
912
|
+
if (scrollHeight > clientHeight) {
|
|
913
|
+
canTouchScroll = true;
|
|
914
|
+
isAtTop = scrollTop <= 3;
|
|
915
|
+
isAtBottom = scrollTop >= (scrollHeight - clientHeight) - 3;
|
|
916
|
+
break;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
$parent = $parent.parentElement;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
if (canTouchScroll && ((!isAtTop && !isAtBottom) || (isAtTop && movedY < 0) || (isAtBottom && movedY > 0))) {
|
|
923
|
+
|
|
924
|
+
this.pointer[0] = x;
|
|
925
|
+
this.pointer[1] = y;
|
|
926
|
+
this.pointer[2] = x;
|
|
927
|
+
this.pointer[3] = y;
|
|
928
|
+
this.pointer[4] = x;
|
|
929
|
+
this.pointer[5] = y;
|
|
930
|
+
this.pointer[6] = x;
|
|
931
|
+
this.pointer[7] = y;
|
|
932
|
+
|
|
933
|
+
} else {
|
|
934
|
+
|
|
935
|
+
preventDefault(e);
|
|
936
|
+
|
|
937
|
+
// Needed to prevents click on handleUp
|
|
938
|
+
if (!this.triggerStyles) this.triggerStyles = target.set(this.$trigger, { pointerEvents: 'none' });
|
|
939
|
+
// Needed to prevent page scroll while dragging on touch devvice
|
|
940
|
+
this.$trigger.addEventListener('touchstart', preventDefault, { passive: false });
|
|
941
|
+
this.$trigger.addEventListener('touchmove', preventDefault, { passive: false });
|
|
942
|
+
this.$trigger.addEventListener('touchend', preventDefault);
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
if ((!this.disabled[0] && helpers.abs(movedX) > 3) || (!this.disabled[1] && helpers.abs(movedY) > 3)) {
|
|
946
|
+
|
|
947
|
+
this.updateTicker.resume();
|
|
948
|
+
this.pointer[2] = this.pointer[0];
|
|
949
|
+
this.pointer[3] = this.pointer[1];
|
|
950
|
+
this.pointer[0] = x;
|
|
951
|
+
this.pointer[1] = y;
|
|
952
|
+
this.dragged = true;
|
|
953
|
+
this.released = false;
|
|
954
|
+
this.onDrag(this);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
handleUp() {
|
|
960
|
+
|
|
961
|
+
if (!this.grabbed) return;
|
|
962
|
+
|
|
963
|
+
this.updateTicker.pause();
|
|
964
|
+
|
|
965
|
+
if (this.triggerStyles) {
|
|
966
|
+
this.triggerStyles.revert();
|
|
967
|
+
this.triggerStyles = null;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
if (this.bodyStyles) {
|
|
971
|
+
this.bodyStyles.revert();
|
|
972
|
+
this.bodyStyles = null;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
const [ disabledX, disabledY ] = this.disabled;
|
|
976
|
+
const [ px1, py1, px2, py2, px3, py3 ] = this.pointer;
|
|
977
|
+
const [ ct, cr, cb, cl ] = this.containerBounds;
|
|
978
|
+
const [ sx, sy ] = this.snapped;
|
|
979
|
+
const springX = this.releaseXSpring;
|
|
980
|
+
const springY = this.releaseYSpring;
|
|
981
|
+
const releaseEase = this.releaseEase;
|
|
982
|
+
const hasReleaseSpring = this.hasReleaseSpring;
|
|
983
|
+
const overshootCoords = this.overshootCoords;
|
|
984
|
+
const cx = this.x;
|
|
985
|
+
const cy = this.y;
|
|
986
|
+
const pv = this.computeVelocity(px1 - px3, py1 - py3);
|
|
987
|
+
const pa = this.angle = helpers.atan2(py1 - py2, px1 - px2);
|
|
988
|
+
const ds = pv * 150;
|
|
989
|
+
const cf = (1 - this.releaseContainerFriction) * this.dragSpeed;
|
|
990
|
+
const nx = cx + (helpers.cos(pa) * ds);
|
|
991
|
+
const ny = cy + (helpers.sin(pa) * ds);
|
|
992
|
+
const bx = nx > cr ? cr + (nx - cr) * cf : nx < cl ? cl + (nx - cl) * cf : nx;
|
|
993
|
+
const by = ny > cb ? cb + (ny - cb) * cf : ny < ct ? ct + (ny - ct) * cf : ny;
|
|
994
|
+
const dx = this.destX = helpers.clamp(helpers.round(helpers.snap(bx, this.snapX), 5), cl, cr);
|
|
995
|
+
const dy = this.destY = helpers.clamp(helpers.round(helpers.snap(by, this.snapY), 5), ct, cb);
|
|
996
|
+
const ob = this.isOutOfBounds(this.containerBounds, nx, ny);
|
|
997
|
+
|
|
998
|
+
let durationX = 0;
|
|
999
|
+
let durationY = 0;
|
|
1000
|
+
let easeX = releaseEase;
|
|
1001
|
+
let easeY = releaseEase;
|
|
1002
|
+
let longestReleaseDuration = 0;
|
|
1003
|
+
|
|
1004
|
+
overshootCoords.x = cx;
|
|
1005
|
+
overshootCoords.y = cy;
|
|
1006
|
+
|
|
1007
|
+
if (!disabledX) {
|
|
1008
|
+
const directionX = dx === cr ? cx > cr ? -1 : 1 : cx < cl ? -1 : 1;
|
|
1009
|
+
const distanceX = helpers.round(cx - dx, 0);
|
|
1010
|
+
springX.velocity = disabledY && hasReleaseSpring ? distanceX ? (ds * directionX) / helpers.abs(distanceX) : 0 : pv;
|
|
1011
|
+
const { ease, duration, restDuration } = springX;
|
|
1012
|
+
durationX = cx === dx ? 0 : hasReleaseSpring ? duration : duration - (restDuration * globals.globals.timeScale);
|
|
1013
|
+
if (hasReleaseSpring) easeX = ease;
|
|
1014
|
+
if (durationX > longestReleaseDuration) longestReleaseDuration = durationX;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
if (!disabledY) {
|
|
1018
|
+
const directionY = dy === cb ? cy > cb ? -1 : 1 : cy < ct ? -1 : 1;
|
|
1019
|
+
const distanceY = helpers.round(cy - dy, 0);
|
|
1020
|
+
springY.velocity = disabledX && hasReleaseSpring ? distanceY ? (ds * directionY) / helpers.abs(distanceY) : 0 : pv;
|
|
1021
|
+
const { ease, duration, restDuration } = springY;
|
|
1022
|
+
durationY = cy === dy ? 0 : hasReleaseSpring ? duration : duration - (restDuration * globals.globals.timeScale);
|
|
1023
|
+
if (hasReleaseSpring) easeY = ease;
|
|
1024
|
+
if (durationY > longestReleaseDuration) longestReleaseDuration = durationY;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
if (!hasReleaseSpring && ob && cf && (durationX || durationY)) {
|
|
1028
|
+
|
|
1029
|
+
const composition = consts.compositionTypes.blend;
|
|
1030
|
+
|
|
1031
|
+
new animation.JSAnimation(overshootCoords, {
|
|
1032
|
+
x: { to: bx, duration: durationX * .65 },
|
|
1033
|
+
y: { to: by, duration: durationY * .65 },
|
|
1034
|
+
ease: releaseEase,
|
|
1035
|
+
composition,
|
|
1036
|
+
}).init();
|
|
1037
|
+
|
|
1038
|
+
new animation.JSAnimation(overshootCoords, {
|
|
1039
|
+
x: { to: dx, duration: durationX },
|
|
1040
|
+
y: { to: dy, duration: durationY },
|
|
1041
|
+
ease: releaseEase,
|
|
1042
|
+
composition,
|
|
1043
|
+
}).init();
|
|
1044
|
+
|
|
1045
|
+
this.overshootTicker.stretch(helpers.max(durationX, durationY)).restart();
|
|
1046
|
+
|
|
1047
|
+
} else {
|
|
1048
|
+
|
|
1049
|
+
if (!disabledX) this.animate[this.xProp](dx, durationX, easeX);
|
|
1050
|
+
if (!disabledY) this.animate[this.yProp](dy, durationY, easeY);
|
|
1051
|
+
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
this.scrollInView(longestReleaseDuration, this.scrollThreshold, releaseEase);
|
|
1055
|
+
|
|
1056
|
+
let hasSnapped = false;
|
|
1057
|
+
|
|
1058
|
+
if (dx !== sx) {
|
|
1059
|
+
this.snapped[0] = dx;
|
|
1060
|
+
if (this.snapX) hasSnapped = true;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
if (dy !== sy && this.snapY) {
|
|
1064
|
+
this.snapped[1] = dy;
|
|
1065
|
+
if (this.snapY) hasSnapped = true;
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
if (hasSnapped) this.onSnap(this);
|
|
1069
|
+
|
|
1070
|
+
this.grabbed = false;
|
|
1071
|
+
this.dragged = false;
|
|
1072
|
+
this.updated = true;
|
|
1073
|
+
this.released = true;
|
|
1074
|
+
|
|
1075
|
+
// It's important to trigger the callback after the release animations to be able to cancel them
|
|
1076
|
+
this.onRelease(this);
|
|
1077
|
+
|
|
1078
|
+
this.$trigger.removeEventListener('touchstart', preventDefault);
|
|
1079
|
+
this.$trigger.removeEventListener('touchmove', preventDefault);
|
|
1080
|
+
this.$trigger.removeEventListener('touchend', preventDefault);
|
|
1081
|
+
|
|
1082
|
+
consts.doc.removeEventListener('touchmove', this);
|
|
1083
|
+
consts.doc.removeEventListener('touchend', this);
|
|
1084
|
+
consts.doc.removeEventListener('touchcancel', this);
|
|
1085
|
+
consts.doc.removeEventListener('mousemove', this);
|
|
1086
|
+
consts.doc.removeEventListener('mouseup', this);
|
|
1087
|
+
consts.doc.removeEventListener('selectstart', this);
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
reset() {
|
|
1091
|
+
this.stop();
|
|
1092
|
+
this.resizeTicker.pause();
|
|
1093
|
+
this.grabbed = false;
|
|
1094
|
+
this.dragged = false;
|
|
1095
|
+
this.updated = false;
|
|
1096
|
+
this.released = false;
|
|
1097
|
+
this.canScroll = false;
|
|
1098
|
+
this.setX(0, true);
|
|
1099
|
+
this.setY(0, true);
|
|
1100
|
+
this.coords[0] = 0;
|
|
1101
|
+
this.coords[1] = 0;
|
|
1102
|
+
this.pointer[0] = 0;
|
|
1103
|
+
this.pointer[1] = 0;
|
|
1104
|
+
this.pointer[2] = 0;
|
|
1105
|
+
this.pointer[3] = 0;
|
|
1106
|
+
this.pointer[4] = 0;
|
|
1107
|
+
this.pointer[5] = 0;
|
|
1108
|
+
this.pointer[6] = 0;
|
|
1109
|
+
this.pointer[7] = 0;
|
|
1110
|
+
this.velocity = 0;
|
|
1111
|
+
this.velocityStack[0] = 0;
|
|
1112
|
+
this.velocityStack[1] = 0;
|
|
1113
|
+
this.velocityStack[2] = 0;
|
|
1114
|
+
this.velocityStackIndex = 0;
|
|
1115
|
+
this.angle = 0;
|
|
1116
|
+
return this;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
enable() {
|
|
1120
|
+
if (!this.enabled) {
|
|
1121
|
+
this.enabled = true;
|
|
1122
|
+
this.$target.classList.remove('is-disabled');
|
|
1123
|
+
this.touchActionStyles = target.set(this.$trigger, {
|
|
1124
|
+
touchAction: this.disabled[0] ? 'pan-x' : this.disabled[1] ? 'pan-y' : 'none'
|
|
1125
|
+
});
|
|
1126
|
+
this.$trigger.addEventListener('touchstart', this, { passive: true });
|
|
1127
|
+
this.$trigger.addEventListener('mousedown', this, { passive: true });
|
|
1128
|
+
this.$trigger.addEventListener('mouseenter', this);
|
|
1129
|
+
}
|
|
1130
|
+
return this;
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
disable() {
|
|
1134
|
+
this.enabled = false;
|
|
1135
|
+
this.grabbed = false;
|
|
1136
|
+
this.dragged = false;
|
|
1137
|
+
this.updated = false;
|
|
1138
|
+
this.released = false;
|
|
1139
|
+
this.canScroll = false;
|
|
1140
|
+
this.touchActionStyles.revert();
|
|
1141
|
+
if (this.cursorStyles) {
|
|
1142
|
+
this.cursorStyles.revert();
|
|
1143
|
+
this.cursorStyles = null;
|
|
1144
|
+
}
|
|
1145
|
+
if (this.triggerStyles) {
|
|
1146
|
+
this.triggerStyles.revert();
|
|
1147
|
+
this.triggerStyles = null;
|
|
1148
|
+
}
|
|
1149
|
+
if (this.bodyStyles) {
|
|
1150
|
+
this.bodyStyles.revert();
|
|
1151
|
+
this.bodyStyles = null;
|
|
1152
|
+
}
|
|
1153
|
+
if (this.targetStyles) {
|
|
1154
|
+
this.targetStyles.revert();
|
|
1155
|
+
this.targetStyles = null;
|
|
1156
|
+
}
|
|
1157
|
+
this.$target.classList.add('is-disabled');
|
|
1158
|
+
this.$trigger.removeEventListener('touchstart', this);
|
|
1159
|
+
this.$trigger.removeEventListener('mousedown', this);
|
|
1160
|
+
this.$trigger.removeEventListener('mouseenter', this);
|
|
1161
|
+
consts.doc.removeEventListener('touchmove', this);
|
|
1162
|
+
consts.doc.removeEventListener('touchend', this);
|
|
1163
|
+
consts.doc.removeEventListener('touchcancel', this);
|
|
1164
|
+
consts.doc.removeEventListener('mousemove', this);
|
|
1165
|
+
consts.doc.removeEventListener('mouseup', this);
|
|
1166
|
+
consts.doc.removeEventListener('selectstart', this);
|
|
1167
|
+
return this;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
revert() {
|
|
1171
|
+
this.reset();
|
|
1172
|
+
this.disable();
|
|
1173
|
+
this.$target.classList.remove('is-disabled');
|
|
1174
|
+
this.updateTicker.revert();
|
|
1175
|
+
this.overshootTicker.revert();
|
|
1176
|
+
this.resizeTicker.revert();
|
|
1177
|
+
this.animate.revert();
|
|
1178
|
+
this.resizeObserver.disconnect();
|
|
1179
|
+
return this;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* @param {Event} e
|
|
1184
|
+
*/
|
|
1185
|
+
handleEvent(e) {
|
|
1186
|
+
switch (e.type) {
|
|
1187
|
+
case 'mousedown':
|
|
1188
|
+
this.handleDown(/** @type {MouseEvent} */(e));
|
|
1189
|
+
break;
|
|
1190
|
+
case 'touchstart':
|
|
1191
|
+
this.handleDown(/** @type {TouchEvent} */(e));
|
|
1192
|
+
break;
|
|
1193
|
+
case 'mousemove':
|
|
1194
|
+
this.handleMove(/** @type {MouseEvent} */(e));
|
|
1195
|
+
break;
|
|
1196
|
+
case 'touchmove':
|
|
1197
|
+
this.handleMove(/** @type {TouchEvent} */(e));
|
|
1198
|
+
break;
|
|
1199
|
+
case 'mouseup':
|
|
1200
|
+
this.handleUp();
|
|
1201
|
+
break;
|
|
1202
|
+
case 'touchend':
|
|
1203
|
+
this.handleUp();
|
|
1204
|
+
break;
|
|
1205
|
+
case 'touchcancel':
|
|
1206
|
+
this.handleUp();
|
|
1207
|
+
break;
|
|
1208
|
+
case 'mouseenter':
|
|
1209
|
+
this.handleHover();
|
|
1210
|
+
break;
|
|
1211
|
+
case 'selectstart':
|
|
1212
|
+
preventDefault(e);
|
|
1213
|
+
break;
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
/**
|
|
1219
|
+
* @param {TargetsParam} target
|
|
1220
|
+
* @param {DraggableParams} [parameters]
|
|
1221
|
+
* @return {Draggable}
|
|
1222
|
+
*/
|
|
1223
|
+
const createDraggable = (target, parameters) => new Draggable(target, parameters);
|
|
1224
|
+
|
|
1225
|
+
exports.Draggable = Draggable;
|
|
1226
|
+
exports.createDraggable = createDraggable;
|