1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | (function (global, factory) {
|
10 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@egjs/agent'), require('@egjs/component'), require('@cfcs/core')) :
|
11 | typeof define === 'function' && define.amd ? define(['@egjs/agent', '@egjs/component', '@cfcs/core'], factory) :
|
12 | (global.eg = global.eg || {}, global.eg.Axes = factory(global.eg.agent,global.Component,global.core));
|
13 | }(this, (function (getAgent,Component,core) { 'use strict';
|
14 |
|
15 | |
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | var extendStatics = function (d, b) {
|
32 | extendStatics = Object.setPrototypeOf || {
|
33 | __proto__: []
|
34 | } instanceof Array && function (d, b) {
|
35 | d.__proto__ = b;
|
36 | } || function (d, b) {
|
37 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
38 | };
|
39 |
|
40 | return extendStatics(d, b);
|
41 | };
|
42 |
|
43 | function __extends(d, b) {
|
44 | extendStatics(d, b);
|
45 |
|
46 | function __() {
|
47 | this.constructor = d;
|
48 | }
|
49 |
|
50 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
51 | }
|
52 | var __assign = function () {
|
53 | __assign = Object.assign || function __assign(t) {
|
54 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
55 | s = arguments[i];
|
56 |
|
57 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
58 | }
|
59 |
|
60 | return t;
|
61 | };
|
62 |
|
63 | return __assign.apply(this, arguments);
|
64 | };
|
65 | function __decorate(decorators, target, key, desc) {
|
66 | var c = arguments.length,
|
67 | r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
68 | d;
|
69 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
70 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
71 | }
|
72 |
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | var win;
|
80 |
|
81 | if (typeof window === "undefined") {
|
82 |
|
83 | win = {
|
84 | navigator: {
|
85 | userAgent: ""
|
86 | }
|
87 | };
|
88 | } else {
|
89 | win = window;
|
90 | }
|
91 |
|
92 | |
93 |
|
94 |
|
95 |
|
96 | var DIRECTION_NONE = 1;
|
97 | var DIRECTION_LEFT = 2;
|
98 | var DIRECTION_RIGHT = 4;
|
99 | var DIRECTION_HORIZONTAL = 2 | 4;
|
100 | var DIRECTION_UP = 8;
|
101 | var DIRECTION_DOWN = 16;
|
102 | var DIRECTION_VERTICAL = 8 | 16;
|
103 | var DIRECTION_ALL = 2 | 4 | 8 | 16;
|
104 | var MOUSE_LEFT = "left";
|
105 | var MOUSE_RIGHT = "right";
|
106 | var MOUSE_MIDDLE = "middle";
|
107 | var ANY = "any";
|
108 | var NONE = "none";
|
109 | var SHIFT = "shift";
|
110 | var CTRL = "ctrl";
|
111 | var ALT = "alt";
|
112 | var META = "meta";
|
113 | var VELOCITY_INTERVAL = 16;
|
114 | var AXES_METHODS = ["connect", "disconnect", "get", "setTo", "setBy", "setOptions", "setAxis", "stopAnimation", "updateAnimation", "isBounceArea"];
|
115 | var AXES_EVENTS = ["hold", "release", "change", "animationStart", "animationEnd", "finish"];
|
116 | var IOS_EDGE_THRESHOLD = 30;
|
117 | var IS_IOS_SAFARI = "ontouchstart" in win && getAgent().browser.name === "safari";
|
118 | var TRANSFORM = function () {
|
119 | if (typeof document === "undefined") {
|
120 | return "";
|
121 | }
|
122 |
|
123 | var bodyStyle = (document.head || document.getElementsByTagName("head")[0]).style;
|
124 | var target = ["transform", "webkitTransform", "msTransform", "mozTransform"];
|
125 |
|
126 | for (var i = 0, len = target.length; i < len; i++) {
|
127 | if (target[i] in bodyStyle) {
|
128 | return target[i];
|
129 | }
|
130 | }
|
131 |
|
132 | return "";
|
133 | }();
|
134 | var PREVENT_DRAG_CSSPROPS = {
|
135 | "user-select": "none",
|
136 | "-webkit-user-drag": "none"
|
137 | };
|
138 |
|
139 | var toArray = function (nodes) {
|
140 |
|
141 |
|
142 | var el = [];
|
143 |
|
144 | for (var i = 0, len = nodes.length; i < len; i++) {
|
145 | el.push(nodes[i]);
|
146 | }
|
147 |
|
148 | return el;
|
149 | };
|
150 | var $ = function (param, multi) {
|
151 | if (multi === void 0) {
|
152 | multi = false;
|
153 | }
|
154 |
|
155 | var el;
|
156 |
|
157 | if (typeof param === "string") {
|
158 |
|
159 |
|
160 | var match = param.match(/^<([a-z]+)\s*([^>]*)>/);
|
161 |
|
162 | if (match) {
|
163 |
|
164 | var dummy = document.createElement("div");
|
165 | dummy.innerHTML = param;
|
166 | el = toArray(dummy.childNodes);
|
167 | } else {
|
168 |
|
169 | el = toArray(document.querySelectorAll(param));
|
170 | }
|
171 |
|
172 | if (!multi) {
|
173 | el = el.length >= 1 ? el[0] : undefined;
|
174 | }
|
175 | } else if (param === win) {
|
176 |
|
177 | el = param;
|
178 | } else if ("value" in param || "current" in param) {
|
179 | el = param.value || param.current;
|
180 | } else if (param.nodeName && (param.nodeType === 1 || param.nodeType === 9)) {
|
181 |
|
182 | el = param;
|
183 | } else if ("jQuery" in win && param instanceof jQuery || param.constructor.prototype.jquery) {
|
184 |
|
185 | el = multi ? param.toArray() : param.get(0);
|
186 | } else if (Array.isArray(param)) {
|
187 | el = param.map(function (v) {
|
188 | return $(v);
|
189 | });
|
190 |
|
191 | if (!multi) {
|
192 | el = el.length >= 1 ? el[0] : undefined;
|
193 | }
|
194 | }
|
195 |
|
196 | return el;
|
197 | };
|
198 | var raf = win.requestAnimationFrame || win.webkitRequestAnimationFrame;
|
199 | var caf = win.cancelAnimationFrame || win.webkitCancelAnimationFrame;
|
200 |
|
201 | if (raf && !caf) {
|
202 | var keyInfo_1 = {};
|
203 | var oldraf_1 = raf;
|
204 |
|
205 | raf = function (callback) {
|
206 | var wrapCallback = function (timestamp) {
|
207 | if (keyInfo_1[key]) {
|
208 | callback(timestamp);
|
209 | }
|
210 | };
|
211 |
|
212 | var key = oldraf_1(wrapCallback);
|
213 | keyInfo_1[key] = true;
|
214 | return key;
|
215 | };
|
216 |
|
217 | caf = function (key) {
|
218 | delete keyInfo_1[key];
|
219 | };
|
220 | } else if (!(raf && caf)) {
|
221 | raf = function (callback) {
|
222 | return win.setTimeout(function () {
|
223 | callback(win.performance && win.performance.now && win.performance.now() || new Date().getTime());
|
224 | }, 16);
|
225 | };
|
226 |
|
227 | caf = win.clearTimeout;
|
228 | }
|
229 | |
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 | var requestAnimationFrame = function (fp) {
|
237 | return raf(fp);
|
238 | };
|
239 | |
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 | var cancelAnimationFrame = function (key) {
|
247 | caf(key);
|
248 | };
|
249 | var map = function (obj, callback) {
|
250 | var tranformed = {};
|
251 |
|
252 | for (var k in obj) {
|
253 | if (k) {
|
254 | tranformed[k] = callback(obj[k], k);
|
255 | }
|
256 | }
|
257 |
|
258 | return tranformed;
|
259 | };
|
260 | var filter = function (obj, callback) {
|
261 | var filtered = {};
|
262 |
|
263 | for (var k in obj) {
|
264 | if (k && callback(obj[k], k)) {
|
265 | filtered[k] = obj[k];
|
266 | }
|
267 | }
|
268 |
|
269 | return filtered;
|
270 | };
|
271 | var every = function (obj, callback) {
|
272 | for (var k in obj) {
|
273 | if (k && !callback(obj[k], k)) {
|
274 | return false;
|
275 | }
|
276 | }
|
277 |
|
278 | return true;
|
279 | };
|
280 | var equal = function (target, base) {
|
281 | return every(target, function (v, k) {
|
282 | return v === base[k];
|
283 | });
|
284 | };
|
285 | var roundNumFunc = {};
|
286 | var roundNumber = function (num, roundUnit) {
|
287 |
|
288 | if (!roundNumFunc[roundUnit]) {
|
289 | roundNumFunc[roundUnit] = getRoundFunc(roundUnit);
|
290 | }
|
291 |
|
292 | return roundNumFunc[roundUnit](num);
|
293 | };
|
294 | var roundNumbers = function (num, roundUnit) {
|
295 | if (!num || !roundUnit) {
|
296 | return num;
|
297 | }
|
298 |
|
299 | return map(num, function (value, key) {
|
300 | return roundNumber(value, typeof roundUnit === "number" ? roundUnit : roundUnit[key]);
|
301 | });
|
302 | };
|
303 | var getDecimalPlace = function (val) {
|
304 | if (!isFinite(val)) {
|
305 | return 0;
|
306 | }
|
307 |
|
308 | var v = "".concat(val);
|
309 |
|
310 | if (v.indexOf("e") >= 0) {
|
311 |
|
312 |
|
313 | var p = 0;
|
314 | var e = 1;
|
315 |
|
316 | while (Math.round(val * e) / e !== val) {
|
317 | e *= 10;
|
318 | p++;
|
319 | }
|
320 |
|
321 | return p;
|
322 | }
|
323 |
|
324 |
|
325 |
|
326 | return v.indexOf(".") >= 0 ? v.length - v.indexOf(".") - 1 : 0;
|
327 | };
|
328 | var inversePow = function (n) {
|
329 |
|
330 |
|
331 | return 1 / Math.pow(10, n);
|
332 | };
|
333 | var getRoundFunc = function (v) {
|
334 | var p = v < 1 ? Math.pow(10, getDecimalPlace(v)) : 1;
|
335 | return function (n) {
|
336 | if (v === 0) {
|
337 | return 0;
|
338 | }
|
339 |
|
340 | return Math.round(Math.round(n / v) * v * p) / p;
|
341 | };
|
342 | };
|
343 | var getAngle = function (posX, posY) {
|
344 | return Math.atan2(posY, posX) * 180 / Math.PI;
|
345 | };
|
346 | var isCssPropsFromAxes = function (originalCssProps) {
|
347 | var same = true;
|
348 | Object.keys(PREVENT_DRAG_CSSPROPS).forEach(function (prop) {
|
349 | if (!originalCssProps || originalCssProps[prop] !== PREVENT_DRAG_CSSPROPS[prop]) {
|
350 | same = false;
|
351 | }
|
352 | });
|
353 | return same;
|
354 | };
|
355 | var getDirection = function (useHorizontal, useVertical) {
|
356 | if (useHorizontal && useVertical) {
|
357 | return DIRECTION_ALL;
|
358 | } else if (useHorizontal) {
|
359 | return DIRECTION_HORIZONTAL;
|
360 | } else if (useVertical) {
|
361 | return DIRECTION_VERTICAL;
|
362 | } else {
|
363 | return DIRECTION_NONE;
|
364 | }
|
365 | };
|
366 | var useDirection = function (checkType, direction, userDirection) {
|
367 | if (userDirection) {
|
368 | return !!(direction === DIRECTION_ALL || direction & checkType && userDirection & checkType);
|
369 | } else {
|
370 | return !!(direction & checkType);
|
371 | }
|
372 | };
|
373 | var setCssProps = function (element, option, direction) {
|
374 | var _a;
|
375 |
|
376 | var touchActionMap = (_a = {}, _a[DIRECTION_NONE] = "auto", _a[DIRECTION_ALL] = "none", _a[DIRECTION_VERTICAL] = "pan-x", _a[DIRECTION_HORIZONTAL] = "pan-y", _a);
|
377 | var oldCssProps = {};
|
378 |
|
379 | if (element && element.style) {
|
380 | var touchAction = option.touchAction ? option.touchAction : touchActionMap[direction];
|
381 |
|
382 | var newCssProps_1 = __assign(__assign({}, PREVENT_DRAG_CSSPROPS), {
|
383 | "touch-action": element.style["touch-action"] === "none" ? "none" : touchAction
|
384 | });
|
385 |
|
386 | Object.keys(newCssProps_1).forEach(function (prop) {
|
387 | oldCssProps[prop] = element.style[prop];
|
388 | element.style[prop] = newCssProps_1[prop];
|
389 | });
|
390 | }
|
391 |
|
392 | return oldCssProps;
|
393 | };
|
394 | var revertCssProps = function (element, originalCssProps) {
|
395 | if (element && element.style && originalCssProps) {
|
396 | Object.keys(originalCssProps).forEach(function (prop) {
|
397 | element.style[prop] = originalCssProps[prop];
|
398 | });
|
399 | }
|
400 |
|
401 | return;
|
402 | };
|
403 |
|
404 | var EventManager =
|
405 |
|
406 | function () {
|
407 | function EventManager(_axes) {
|
408 | this._axes = _axes;
|
409 | }
|
410 | |
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 | var __proto = EventManager.prototype;
|
440 |
|
441 | __proto.hold = function (pos, option) {
|
442 | var roundPos = this._getRoundPos(pos).roundPos;
|
443 |
|
444 | this._axes.trigger(new Component.ComponentEvent("hold", {
|
445 | pos: roundPos,
|
446 | input: option.input || null,
|
447 | inputEvent: option.event || null,
|
448 | isTrusted: true
|
449 | }));
|
450 | };
|
451 | |
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 | |
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 | |
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 | __proto.triggerRelease = function (param) {
|
529 | var _a = this._getRoundPos(param.destPos, param.depaPos),
|
530 | roundPos = _a.roundPos,
|
531 | roundDepa = _a.roundDepa;
|
532 |
|
533 | param.destPos = roundPos;
|
534 | param.depaPos = roundDepa;
|
535 | param.setTo = this._createUserControll(param.destPos, param.duration);
|
536 |
|
537 | this._axes.trigger(new Component.ComponentEvent("release", __assign(__assign({}, param), {
|
538 | bounceRatio: this._getBounceRatio(roundPos)
|
539 | })));
|
540 | };
|
541 | |
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 | __proto.triggerChange = function (pos, depaPos, option, holding) {
|
582 | var _this = this;
|
583 |
|
584 | if (holding === void 0) {
|
585 | holding = false;
|
586 | }
|
587 |
|
588 | var animationManager = this.animationManager;
|
589 | var axisManager = animationManager.axisManager;
|
590 | var eventInfo = animationManager.getEventInfo();
|
591 |
|
592 | var _a = this._getRoundPos(pos, depaPos),
|
593 | roundPos = _a.roundPos,
|
594 | roundDepa = _a.roundDepa;
|
595 |
|
596 | var moveTo = axisManager.moveTo(roundPos, roundDepa);
|
597 | var inputEvent = (option === null || option === void 0 ? void 0 : option.event) || (eventInfo === null || eventInfo === void 0 ? void 0 : eventInfo.event) || null;
|
598 | var param = {
|
599 | pos: moveTo.pos,
|
600 | delta: moveTo.delta,
|
601 | bounceRatio: this._getBounceRatio(moveTo.pos),
|
602 | holding: holding,
|
603 | inputEvent: inputEvent,
|
604 | isTrusted: !!inputEvent,
|
605 | input: (option === null || option === void 0 ? void 0 : option.input) || (eventInfo === null || eventInfo === void 0 ? void 0 : eventInfo.input) || null,
|
606 | set: inputEvent ? this._createUserControll(moveTo.pos) : function () {}
|
607 |
|
608 | };
|
609 | var event = new Component.ComponentEvent("change", param);
|
610 |
|
611 | this._axes.trigger(event);
|
612 |
|
613 | Object.keys(moveTo.pos).forEach(function (axis) {
|
614 | var p = moveTo.pos[axis];
|
615 | core.getObserver(_this._axes, axis, p).current = p;
|
616 | });
|
617 |
|
618 | if (inputEvent) {
|
619 | axisManager.set(param.set().destPos);
|
620 | }
|
621 |
|
622 | return !event.isCanceled();
|
623 | };
|
624 | |
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 | __proto.triggerAnimationStart = function (param) {
|
664 | var _a = this._getRoundPos(param.destPos, param.depaPos),
|
665 | roundPos = _a.roundPos,
|
666 | roundDepa = _a.roundDepa;
|
667 |
|
668 | param.destPos = roundPos;
|
669 | param.depaPos = roundDepa;
|
670 | param.setTo = this._createUserControll(param.destPos, param.duration);
|
671 | var event = new Component.ComponentEvent("animationStart", param);
|
672 |
|
673 | this._axes.trigger(event);
|
674 |
|
675 | return !event.isCanceled();
|
676 | };
|
677 | |
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 |
|
700 | __proto.triggerAnimationEnd = function (isTrusted) {
|
701 | if (isTrusted === void 0) {
|
702 | isTrusted = false;
|
703 | }
|
704 |
|
705 | this._axes.trigger(new Component.ComponentEvent("animationEnd", {
|
706 | isTrusted: isTrusted
|
707 | }));
|
708 | };
|
709 | |
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 |
|
718 |
|
719 |
|
720 |
|
721 |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 | __proto.triggerFinish = function (isTrusted) {
|
733 | if (isTrusted === void 0) {
|
734 | isTrusted = false;
|
735 | }
|
736 |
|
737 | this._axes.trigger(new Component.ComponentEvent("finish", {
|
738 | isTrusted: isTrusted
|
739 | }));
|
740 | };
|
741 |
|
742 | __proto.setAnimationManager = function (animationManager) {
|
743 | this.animationManager = animationManager;
|
744 | };
|
745 |
|
746 | __proto.destroy = function () {
|
747 | this._axes.off();
|
748 | };
|
749 |
|
750 | __proto._createUserControll = function (pos, duration) {
|
751 | if (duration === void 0) {
|
752 | duration = 0;
|
753 | }
|
754 |
|
755 |
|
756 | var userControl = {
|
757 | destPos: __assign({}, pos),
|
758 | duration: duration
|
759 | };
|
760 | return function (toPos, userDuration) {
|
761 | if (toPos) {
|
762 | userControl.destPos = __assign({}, toPos);
|
763 | }
|
764 |
|
765 | if (userDuration !== undefined) {
|
766 | userControl.duration = userDuration;
|
767 | }
|
768 |
|
769 | return userControl;
|
770 | };
|
771 | };
|
772 |
|
773 | __proto._getRoundPos = function (pos, depaPos) {
|
774 |
|
775 | var roundUnit = this._axes.options.round;
|
776 |
|
777 |
|
778 |
|
779 | return {
|
780 | roundPos: roundNumbers(pos, roundUnit),
|
781 | roundDepa: roundNumbers(depaPos, roundUnit)
|
782 | };
|
783 | };
|
784 |
|
785 | __proto._getBounceRatio = function (pos) {
|
786 | return this._axes.axisManager.map(pos, function (v, opt) {
|
787 | if (v < opt.range[0] && opt.bounce[0] !== 0) {
|
788 | return (opt.range[0] - v) / opt.bounce[0];
|
789 | } else if (v > opt.range[1] && opt.bounce[1] !== 0) {
|
790 | return (v - opt.range[1]) / opt.bounce[1];
|
791 | } else {
|
792 | return 0;
|
793 | }
|
794 | });
|
795 | };
|
796 |
|
797 | return EventManager;
|
798 | }();
|
799 |
|
800 | var InterruptManager =
|
801 |
|
802 | function () {
|
803 | function InterruptManager(_options) {
|
804 | this._options = _options;
|
805 | this._prevented = false;
|
806 | }
|
807 |
|
808 | var __proto = InterruptManager.prototype;
|
809 |
|
810 | __proto.isInterrupting = function () {
|
811 |
|
812 | return this._options.interruptable || this._prevented;
|
813 | };
|
814 |
|
815 | __proto.isInterrupted = function () {
|
816 | return !this._options.interruptable && this._prevented;
|
817 | };
|
818 |
|
819 | __proto.setInterrupt = function (prevented) {
|
820 | if (!this._options.interruptable) {
|
821 | this._prevented = prevented;
|
822 | }
|
823 | };
|
824 |
|
825 | return InterruptManager;
|
826 | }();
|
827 |
|
828 | |
829 |
|
830 |
|
831 |
|
832 | var getInsidePosition = function (destPos, range, circular, bounce) {
|
833 | var toDestPos = destPos;
|
834 | var targetRange = [circular[0] ? range[0] : bounce ? range[0] - bounce[0] : range[0], circular[1] ? range[1] : bounce ? range[1] + bounce[1] : range[1]];
|
835 | toDestPos = Math.max(targetRange[0], toDestPos);
|
836 | toDestPos = Math.min(targetRange[1], toDestPos);
|
837 | return toDestPos;
|
838 | };
|
839 |
|
840 | var isOutside = function (pos, range) {
|
841 | return pos < range[0] || pos > range[1];
|
842 | };
|
843 |
|
844 | var isEndofBounce = function (pos, range, bounce, circular) {
|
845 | return !circular[0] && pos === range[0] - bounce[0] || !circular[1] && pos === range[1] + bounce[1];
|
846 | };
|
847 | var getDuration = function (distance, deceleration) {
|
848 | var duration = Math.sqrt(distance / deceleration * 2);
|
849 |
|
850 | return duration < 100 ? 0 : duration;
|
851 | };
|
852 | var isCircularable = function (destPos, range, circular) {
|
853 | return circular[1] && destPos > range[1] || circular[0] && destPos < range[0];
|
854 | };
|
855 | var getCirculatedPos = function (pos, range, circular) {
|
856 | var toPos = pos;
|
857 | var min = range[0];
|
858 | var max = range[1];
|
859 | var length = max - min;
|
860 |
|
861 | if (circular[1] && pos > max) {
|
862 |
|
863 | toPos = (toPos - max) % length + min;
|
864 | }
|
865 |
|
866 | if (circular[0] && pos < min) {
|
867 |
|
868 | toPos = (toPos - min) % length + max;
|
869 | }
|
870 |
|
871 | return toPos;
|
872 | };
|
873 |
|
874 | var AxisManager =
|
875 |
|
876 | function () {
|
877 | function AxisManager(_axis) {
|
878 | var _this = this;
|
879 |
|
880 | this._axis = _axis;
|
881 |
|
882 | this._complementOptions();
|
883 |
|
884 | this._pos = Object.keys(this._axis).reduce(function (pos, v) {
|
885 | pos[v] = _this._axis[v].startPos;
|
886 | return pos;
|
887 | }, {});
|
888 | }
|
889 |
|
890 | var __proto = AxisManager.prototype;
|
891 |
|
892 | __proto.getDelta = function (depaPos, destPos) {
|
893 | var fullDepaPos = this.get(depaPos);
|
894 | return map(this.get(destPos), function (v, k) {
|
895 | return v - fullDepaPos[k];
|
896 | });
|
897 | };
|
898 |
|
899 | __proto.get = function (axes) {
|
900 | var _this = this;
|
901 |
|
902 | if (axes && Array.isArray(axes)) {
|
903 | return axes.reduce(function (acc, v) {
|
904 | if (v && v in _this._pos) {
|
905 | acc[v] = _this._pos[v];
|
906 | }
|
907 |
|
908 | return acc;
|
909 | }, {});
|
910 | } else {
|
911 | return __assign(__assign({}, this._pos), axes || {});
|
912 | }
|
913 | };
|
914 |
|
915 | __proto.moveTo = function (pos, depaPos) {
|
916 | if (depaPos === void 0) {
|
917 | depaPos = this._pos;
|
918 | }
|
919 |
|
920 | var delta = map(this._pos, function (v, key) {
|
921 | return key in pos && key in depaPos ? pos[key] - depaPos[key] : 0;
|
922 | });
|
923 | this.set(this.map(pos, function (v, opt) {
|
924 | return opt ? getCirculatedPos(v, opt.range, opt.circular) : 0;
|
925 | }));
|
926 | return {
|
927 | pos: __assign({}, this._pos),
|
928 | delta: delta
|
929 | };
|
930 | };
|
931 |
|
932 | __proto.set = function (pos) {
|
933 | for (var k in pos) {
|
934 | if (k && k in this._pos) {
|
935 | this._pos[k] = pos[k];
|
936 | }
|
937 | }
|
938 | };
|
939 |
|
940 | __proto.every = function (pos, callback) {
|
941 | var axisOptions = this._axis;
|
942 | return every(pos, function (value, key) {
|
943 | return callback(value, axisOptions[key], key);
|
944 | });
|
945 | };
|
946 |
|
947 | __proto.filter = function (pos, callback) {
|
948 | var axisOptions = this._axis;
|
949 | return filter(pos, function (value, key) {
|
950 | return callback(value, axisOptions[key], key);
|
951 | });
|
952 | };
|
953 |
|
954 | __proto.map = function (pos, callback) {
|
955 | var axisOptions = this._axis;
|
956 | return map(pos, function (value, key) {
|
957 | return callback(value, axisOptions[key], key);
|
958 | });
|
959 | };
|
960 |
|
961 | __proto.isOutside = function (axes) {
|
962 | return !this.every(axes ? this.get(axes) : this._pos, function (v, opt) {
|
963 | return !isOutside(v, opt.range);
|
964 | });
|
965 | };
|
966 |
|
967 | __proto.getAxisOptions = function (key) {
|
968 | return this._axis[key];
|
969 | };
|
970 |
|
971 | __proto.setAxis = function (axis) {
|
972 | var _this = this;
|
973 |
|
974 | Object.keys(axis).forEach(function (key) {
|
975 | if (!_this._axis[key]) {
|
976 | throw new Error("Axis ".concat(key, " does not exist in Axes instance"));
|
977 | }
|
978 |
|
979 | _this._axis[key] = __assign(__assign({}, _this._axis[key]), axis[key]);
|
980 | });
|
981 |
|
982 | this._complementOptions();
|
983 | };
|
984 | |
985 |
|
986 |
|
987 |
|
988 |
|
989 |
|
990 | __proto._complementOptions = function () {
|
991 | var _this = this;
|
992 |
|
993 | Object.keys(this._axis).forEach(function (axis) {
|
994 | _this._axis[axis] = __assign({
|
995 | range: [0, 100],
|
996 | startPos: _this._axis[axis].range[0],
|
997 | bounce: [0, 0],
|
998 | circular: [false, false]
|
999 | }, _this._axis[axis]);
|
1000 | ["bounce", "circular"].forEach(function (v) {
|
1001 | var axisOption = _this._axis;
|
1002 | var key = axisOption[axis][v];
|
1003 |
|
1004 | if (/string|number|boolean/.test(typeof key)) {
|
1005 | axisOption[axis][v] = [key, key];
|
1006 | }
|
1007 | });
|
1008 | });
|
1009 | };
|
1010 |
|
1011 | return AxisManager;
|
1012 | }();
|
1013 |
|
1014 | var SUPPORT_TOUCH = ("ontouchstart" in win);
|
1015 | var SUPPORT_POINTER = ("PointerEvent" in win);
|
1016 | var SUPPORT_MSPOINTER = ("MSPointerEvent" in win);
|
1017 | var SUPPORT_POINTER_EVENTS = SUPPORT_POINTER || SUPPORT_MSPOINTER;
|
1018 | var isValidKey = function (event, inputKey) {
|
1019 | if (!inputKey || inputKey.indexOf(ANY) > -1 || inputKey.indexOf(NONE) > -1 && !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey || inputKey.indexOf(SHIFT) > -1 && event.shiftKey || inputKey.indexOf(CTRL) > -1 && event.ctrlKey || inputKey.indexOf(ALT) > -1 && event.altKey || inputKey.indexOf(META) > -1 && event.metaKey) {
|
1020 | return true;
|
1021 | }
|
1022 |
|
1023 | return false;
|
1024 | };
|
1025 |
|
1026 | var EventInput =
|
1027 |
|
1028 | function () {
|
1029 | function EventInput() {
|
1030 | var _this = this;
|
1031 |
|
1032 | this._stopContextMenu = function (event) {
|
1033 | event.preventDefault();
|
1034 | win.removeEventListener("contextmenu", _this._stopContextMenu);
|
1035 | };
|
1036 | }
|
1037 |
|
1038 | var __proto = EventInput.prototype;
|
1039 |
|
1040 | __proto.extendEvent = function (event) {
|
1041 | var _a;
|
1042 |
|
1043 | var prevEvent = this.prevEvent;
|
1044 |
|
1045 | var center = this._getCenter(event);
|
1046 |
|
1047 | var movement = prevEvent ? this._getMovement(event) : {
|
1048 | x: 0,
|
1049 | y: 0
|
1050 | };
|
1051 | var scale = prevEvent ? this._getScale(event) : 1;
|
1052 | var angle = prevEvent ? getAngle(center.x - prevEvent.center.x, center.y - prevEvent.center.y) : 0;
|
1053 | var deltaX = prevEvent ? prevEvent.deltaX + movement.x : movement.x;
|
1054 | var deltaY = prevEvent ? prevEvent.deltaY + movement.y : movement.y;
|
1055 | var offsetX = movement.x;
|
1056 | var offsetY = movement.y;
|
1057 | var latestInterval = this._latestInterval;
|
1058 | var timeStamp = Date.now();
|
1059 | var deltaTime = latestInterval ? timeStamp - latestInterval.timestamp : 0;
|
1060 | var velocityX = prevEvent ? prevEvent.velocityX : 0;
|
1061 | var velocityY = prevEvent ? prevEvent.velocityY : 0;
|
1062 |
|
1063 | if (!latestInterval || deltaTime >= VELOCITY_INTERVAL) {
|
1064 | if (latestInterval) {
|
1065 | _a = [(deltaX - latestInterval.deltaX) / deltaTime, (deltaY - latestInterval.deltaY) / deltaTime], velocityX = _a[0], velocityY = _a[1];
|
1066 | }
|
1067 |
|
1068 | this._latestInterval = {
|
1069 | timestamp: timeStamp,
|
1070 | deltaX: deltaX,
|
1071 | deltaY: deltaY
|
1072 | };
|
1073 | }
|
1074 |
|
1075 | return {
|
1076 | srcEvent: event,
|
1077 | scale: scale,
|
1078 | angle: angle,
|
1079 | center: center,
|
1080 | deltaX: deltaX,
|
1081 | deltaY: deltaY,
|
1082 | offsetX: offsetX,
|
1083 | offsetY: offsetY,
|
1084 | velocityX: velocityX,
|
1085 | velocityY: velocityY,
|
1086 | preventSystemEvent: true
|
1087 | };
|
1088 | };
|
1089 |
|
1090 | __proto._getDistance = function (start, end) {
|
1091 | var x = end.clientX - start.clientX;
|
1092 | var y = end.clientY - start.clientY;
|
1093 | return Math.sqrt(x * x + y * y);
|
1094 | };
|
1095 |
|
1096 | __proto._getButton = function (event) {
|
1097 | var buttonCodeMap = {
|
1098 | 1: MOUSE_LEFT,
|
1099 | 2: MOUSE_RIGHT,
|
1100 | 4: MOUSE_MIDDLE
|
1101 | };
|
1102 | var button = this._isTouchEvent(event) ? MOUSE_LEFT : buttonCodeMap[event.buttons];
|
1103 | return button ? button : null;
|
1104 | };
|
1105 |
|
1106 | __proto._isTouchEvent = function (event) {
|
1107 | return event.type && event.type.indexOf("touch") > -1;
|
1108 | };
|
1109 |
|
1110 | __proto._isValidButton = function (button, inputButton) {
|
1111 | return inputButton.indexOf(button) > -1;
|
1112 | };
|
1113 |
|
1114 | __proto._isValidEvent = function (event, inputKey, inputButton) {
|
1115 | return (!inputKey || isValidKey(event, inputKey)) && (!inputButton || this._isValidButton(this._getButton(event), inputButton));
|
1116 | };
|
1117 |
|
1118 | __proto._preventMouseButton = function (event, button) {
|
1119 | if (button === MOUSE_RIGHT) {
|
1120 | win.addEventListener("contextmenu", this._stopContextMenu);
|
1121 | } else if (button === MOUSE_MIDDLE) {
|
1122 | event.preventDefault();
|
1123 | }
|
1124 | };
|
1125 |
|
1126 | return EventInput;
|
1127 | }();
|
1128 |
|
1129 | var MouseEventInput =
|
1130 |
|
1131 | function (_super) {
|
1132 | __extends(MouseEventInput, _super);
|
1133 |
|
1134 | function MouseEventInput() {
|
1135 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
1136 |
|
1137 | _this.start = ["mousedown"];
|
1138 | _this.move = ["mousemove"];
|
1139 | _this.end = ["mouseup"];
|
1140 | return _this;
|
1141 | }
|
1142 |
|
1143 | var __proto = MouseEventInput.prototype;
|
1144 |
|
1145 | __proto.onEventStart = function (event, inputKey, inputButton) {
|
1146 | var button = this._getButton(event);
|
1147 |
|
1148 | if (!this._isValidEvent(event, inputKey, inputButton)) {
|
1149 | return null;
|
1150 | }
|
1151 |
|
1152 | this._preventMouseButton(event, button);
|
1153 |
|
1154 | return this.extendEvent(event);
|
1155 | };
|
1156 |
|
1157 | __proto.onEventMove = function (event, inputKey, inputButton) {
|
1158 | if (!this._isValidEvent(event, inputKey, inputButton)) {
|
1159 | return null;
|
1160 | }
|
1161 |
|
1162 | return this.extendEvent(event);
|
1163 | };
|
1164 |
|
1165 | __proto.onEventEnd = function () {
|
1166 | return;
|
1167 | };
|
1168 |
|
1169 | __proto.onRelease = function () {
|
1170 | this.prevEvent = null;
|
1171 | return;
|
1172 | };
|
1173 |
|
1174 | __proto.getTouches = function (event, inputButton) {
|
1175 | if (inputButton) {
|
1176 | var buttonCodeMap = {
|
1177 | 1: MOUSE_LEFT,
|
1178 | 2: MOUSE_MIDDLE,
|
1179 | 3: MOUSE_RIGHT
|
1180 | };
|
1181 | return this._isValidButton(buttonCodeMap[event.which], inputButton) && this.end.indexOf(event.type) === -1 ? 1 : 0;
|
1182 | }
|
1183 |
|
1184 | return 0;
|
1185 | };
|
1186 |
|
1187 | __proto._getScale = function () {
|
1188 | return 1;
|
1189 | };
|
1190 |
|
1191 | __proto._getCenter = function (event) {
|
1192 | return {
|
1193 | x: event.clientX,
|
1194 | y: event.clientY
|
1195 | };
|
1196 | };
|
1197 |
|
1198 | __proto._getMovement = function (event) {
|
1199 | var prev = this.prevEvent.srcEvent;
|
1200 | return {
|
1201 | x: event.clientX - prev.clientX,
|
1202 | y: event.clientY - prev.clientY
|
1203 | };
|
1204 | };
|
1205 |
|
1206 | return MouseEventInput;
|
1207 | }(EventInput);
|
1208 |
|
1209 | var TouchEventInput =
|
1210 |
|
1211 | function (_super) {
|
1212 | __extends(TouchEventInput, _super);
|
1213 |
|
1214 | function TouchEventInput() {
|
1215 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
1216 |
|
1217 | _this.start = ["touchstart"];
|
1218 | _this.move = ["touchmove"];
|
1219 | _this.end = ["touchend", "touchcancel"];
|
1220 | return _this;
|
1221 | }
|
1222 |
|
1223 | var __proto = TouchEventInput.prototype;
|
1224 |
|
1225 | __proto.onEventStart = function (event, inputKey) {
|
1226 | this._baseTouches = event.touches;
|
1227 |
|
1228 | if (!this._isValidEvent(event, inputKey)) {
|
1229 | return null;
|
1230 | }
|
1231 |
|
1232 | return this.extendEvent(event);
|
1233 | };
|
1234 |
|
1235 | __proto.onEventMove = function (event, inputKey) {
|
1236 | if (!this._isValidEvent(event, inputKey)) {
|
1237 | return null;
|
1238 | }
|
1239 |
|
1240 | return this.extendEvent(event);
|
1241 | };
|
1242 |
|
1243 | __proto.onEventEnd = function (event) {
|
1244 | this._baseTouches = event.touches;
|
1245 | return;
|
1246 | };
|
1247 |
|
1248 | __proto.onRelease = function () {
|
1249 | this.prevEvent = null;
|
1250 | this._baseTouches = null;
|
1251 | return;
|
1252 | };
|
1253 |
|
1254 | __proto.getTouches = function (event) {
|
1255 | return event.touches.length;
|
1256 | };
|
1257 |
|
1258 | __proto._getScale = function (event) {
|
1259 | if (event.touches.length !== 2 || this._baseTouches.length < 2) {
|
1260 | return null;
|
1261 | }
|
1262 |
|
1263 | return this._getDistance(event.touches[0], event.touches[1]) / this._getDistance(this._baseTouches[0], this._baseTouches[1]);
|
1264 | };
|
1265 |
|
1266 | __proto._getCenter = function (event) {
|
1267 | return {
|
1268 | x: event.touches[0].clientX,
|
1269 | y: event.touches[0].clientY
|
1270 | };
|
1271 | };
|
1272 |
|
1273 | __proto._getMovement = function (event) {
|
1274 | var prev = this.prevEvent.srcEvent;
|
1275 |
|
1276 | if (event.touches[0].identifier !== prev.touches[0].identifier) {
|
1277 | return {
|
1278 | x: 0,
|
1279 | y: 0
|
1280 | };
|
1281 | }
|
1282 |
|
1283 | return {
|
1284 | x: event.touches[0].clientX - prev.touches[0].clientX,
|
1285 | y: event.touches[0].clientY - prev.touches[0].clientY
|
1286 | };
|
1287 | };
|
1288 |
|
1289 | return TouchEventInput;
|
1290 | }(EventInput);
|
1291 |
|
1292 | var PointerEventInput =
|
1293 |
|
1294 | function (_super) {
|
1295 | __extends(PointerEventInput, _super);
|
1296 |
|
1297 | function PointerEventInput() {
|
1298 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
1299 |
|
1300 | _this.start = SUPPORT_POINTER ? ["pointerdown"] : ["MSPointerDown"];
|
1301 | _this.move = SUPPORT_POINTER ? ["pointermove"] : ["MSPointerMove"];
|
1302 | _this.end = SUPPORT_POINTER ? ["pointerup", "pointercancel"] : ["MSPointerUp", "MSPointerCancel"];
|
1303 |
|
1304 | _this._firstInputs = [];
|
1305 | _this._recentInputs = [];
|
1306 | return _this;
|
1307 | }
|
1308 |
|
1309 | var __proto = PointerEventInput.prototype;
|
1310 |
|
1311 | __proto.onEventStart = function (event, inputKey, inputButton) {
|
1312 | var button = this._getButton(event);
|
1313 |
|
1314 | if (!this._isValidEvent(event, inputKey, inputButton)) {
|
1315 | return null;
|
1316 | }
|
1317 |
|
1318 | this._preventMouseButton(event, button);
|
1319 |
|
1320 | this._updatePointerEvent(event);
|
1321 |
|
1322 | return this.extendEvent(event);
|
1323 | };
|
1324 |
|
1325 | __proto.onEventMove = function (event, inputKey, inputButton) {
|
1326 | if (!this._isValidEvent(event, inputKey, inputButton)) {
|
1327 | return null;
|
1328 | }
|
1329 |
|
1330 | this._updatePointerEvent(event);
|
1331 |
|
1332 | return this.extendEvent(event);
|
1333 | };
|
1334 |
|
1335 | __proto.onEventEnd = function (event) {
|
1336 | this._removePointerEvent(event);
|
1337 | };
|
1338 |
|
1339 | __proto.onRelease = function () {
|
1340 | this.prevEvent = null;
|
1341 | this._firstInputs = [];
|
1342 | this._recentInputs = [];
|
1343 | return;
|
1344 | };
|
1345 |
|
1346 | __proto.getTouches = function () {
|
1347 | return this._recentInputs.length;
|
1348 | };
|
1349 |
|
1350 | __proto._getScale = function () {
|
1351 | if (this._recentInputs.length !== 2) {
|
1352 | return null;
|
1353 | }
|
1354 |
|
1355 | return this._getDistance(this._recentInputs[0], this._recentInputs[1]) / this._getDistance(this._firstInputs[0], this._firstInputs[1]);
|
1356 | };
|
1357 |
|
1358 | __proto._getCenter = function (event) {
|
1359 | return {
|
1360 | x: event.clientX,
|
1361 | y: event.clientY
|
1362 | };
|
1363 | };
|
1364 |
|
1365 | __proto._getMovement = function (event) {
|
1366 | var prev = this.prevEvent.srcEvent;
|
1367 |
|
1368 | if (event.pointerId !== prev.pointerId) {
|
1369 | return {
|
1370 | x: 0,
|
1371 | y: 0
|
1372 | };
|
1373 | }
|
1374 |
|
1375 | return {
|
1376 | x: event.clientX - prev.clientX,
|
1377 | y: event.clientY - prev.clientY
|
1378 | };
|
1379 | };
|
1380 |
|
1381 | __proto._updatePointerEvent = function (event) {
|
1382 | var _this = this;
|
1383 |
|
1384 | var addFlag = false;
|
1385 |
|
1386 | this._recentInputs.forEach(function (e, i) {
|
1387 | if (e.pointerId === event.pointerId) {
|
1388 | addFlag = true;
|
1389 | _this._recentInputs[i] = event;
|
1390 | }
|
1391 | });
|
1392 |
|
1393 | if (!addFlag) {
|
1394 | this._firstInputs.push(event);
|
1395 |
|
1396 | this._recentInputs.push(event);
|
1397 | }
|
1398 | };
|
1399 |
|
1400 | __proto._removePointerEvent = function (event) {
|
1401 | this._firstInputs = this._firstInputs.filter(function (x) {
|
1402 | return x.pointerId !== event.pointerId;
|
1403 | });
|
1404 | this._recentInputs = this._recentInputs.filter(function (x) {
|
1405 | return x.pointerId !== event.pointerId;
|
1406 | });
|
1407 | };
|
1408 |
|
1409 | return PointerEventInput;
|
1410 | }(EventInput);
|
1411 |
|
1412 | var TouchMouseEventInput =
|
1413 |
|
1414 | function (_super) {
|
1415 | __extends(TouchMouseEventInput, _super);
|
1416 |
|
1417 | function TouchMouseEventInput() {
|
1418 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
1419 |
|
1420 | _this.start = ["mousedown", "touchstart"];
|
1421 | _this.move = ["mousemove", "touchmove"];
|
1422 | _this.end = ["mouseup", "touchend", "touchcancel"];
|
1423 | return _this;
|
1424 | }
|
1425 |
|
1426 | var __proto = TouchMouseEventInput.prototype;
|
1427 |
|
1428 | __proto.onEventStart = function (event, inputKey, inputButton) {
|
1429 | var button = this._getButton(event);
|
1430 |
|
1431 | if (this._isTouchEvent(event)) {
|
1432 | this._baseTouches = event.touches;
|
1433 | }
|
1434 |
|
1435 | if (!this._isValidEvent(event, inputKey, inputButton)) {
|
1436 | return null;
|
1437 | }
|
1438 |
|
1439 | this._preventMouseButton(event, button);
|
1440 |
|
1441 | return this.extendEvent(event);
|
1442 | };
|
1443 |
|
1444 | __proto.onEventMove = function (event, inputKey, inputButton) {
|
1445 | if (!this._isValidEvent(event, inputKey, inputButton)) {
|
1446 | return null;
|
1447 | }
|
1448 |
|
1449 | return this.extendEvent(event);
|
1450 | };
|
1451 |
|
1452 | __proto.onEventEnd = function (event) {
|
1453 | if (this._isTouchEvent(event)) {
|
1454 | this._baseTouches = event.touches;
|
1455 | }
|
1456 |
|
1457 | return;
|
1458 | };
|
1459 |
|
1460 | __proto.onRelease = function () {
|
1461 | this.prevEvent = null;
|
1462 | this._baseTouches = null;
|
1463 | return;
|
1464 | };
|
1465 |
|
1466 | __proto.getTouches = function (event) {
|
1467 | return this._isTouchEvent(event) ? event.touches.length : 0;
|
1468 | };
|
1469 |
|
1470 | __proto._getScale = function (event) {
|
1471 | if (this._isTouchEvent(event)) {
|
1472 | if (event.touches.length !== 2 || this._baseTouches.length < 2) {
|
1473 | return 1;
|
1474 | }
|
1475 |
|
1476 | return this._getDistance(event.touches[0], event.touches[1]) / this._getDistance(this._baseTouches[0], this._baseTouches[1]);
|
1477 | }
|
1478 |
|
1479 | return this.prevEvent.scale;
|
1480 | };
|
1481 |
|
1482 | __proto._getCenter = function (event) {
|
1483 | if (this._isTouchEvent(event)) {
|
1484 | return {
|
1485 | x: event.touches[0].clientX,
|
1486 | y: event.touches[0].clientY
|
1487 | };
|
1488 | }
|
1489 |
|
1490 | return {
|
1491 | x: event.clientX,
|
1492 | y: event.clientY
|
1493 | };
|
1494 | };
|
1495 |
|
1496 | __proto._getMovement = function (event) {
|
1497 | var _this = this;
|
1498 |
|
1499 | var prev = this.prevEvent.srcEvent;
|
1500 |
|
1501 | var _a = [event, prev].map(function (e) {
|
1502 | if (_this._isTouchEvent(e)) {
|
1503 | return {
|
1504 | id: e.touches[0].identifier,
|
1505 | x: e.touches[0].clientX,
|
1506 | y: e.touches[0].clientY
|
1507 | };
|
1508 | }
|
1509 |
|
1510 | return {
|
1511 | id: null,
|
1512 | x: e.clientX,
|
1513 | y: e.clientY
|
1514 | };
|
1515 | }),
|
1516 | nextSpot = _a[0],
|
1517 | prevSpot = _a[1];
|
1518 |
|
1519 | return nextSpot.id === prevSpot.id ? {
|
1520 | x: nextSpot.x - prevSpot.x,
|
1521 | y: nextSpot.y - prevSpot.y
|
1522 | } : {
|
1523 | x: 0,
|
1524 | y: 0
|
1525 | };
|
1526 | };
|
1527 |
|
1528 | return TouchMouseEventInput;
|
1529 | }(EventInput);
|
1530 |
|
1531 | var toAxis = function (source, offset) {
|
1532 | return offset.reduce(function (acc, v, i) {
|
1533 | if (source[i]) {
|
1534 | acc[source[i]] = v;
|
1535 | }
|
1536 |
|
1537 | return acc;
|
1538 | }, {});
|
1539 | };
|
1540 | var convertInputType = function (inputType) {
|
1541 | if (inputType === void 0) {
|
1542 | inputType = [];
|
1543 | }
|
1544 |
|
1545 | var hasTouch = false;
|
1546 | var hasMouse = false;
|
1547 | var hasPointer = false;
|
1548 | inputType.forEach(function (v) {
|
1549 | switch (v) {
|
1550 | case "mouse":
|
1551 | hasMouse = true;
|
1552 | break;
|
1553 |
|
1554 | case "touch":
|
1555 | hasTouch = SUPPORT_TOUCH;
|
1556 | break;
|
1557 |
|
1558 | case "pointer":
|
1559 | hasPointer = SUPPORT_POINTER_EVENTS;
|
1560 |
|
1561 | }
|
1562 | });
|
1563 |
|
1564 | if (hasPointer) {
|
1565 | return new PointerEventInput();
|
1566 | } else if (hasTouch && hasMouse) {
|
1567 | return new TouchMouseEventInput();
|
1568 | } else if (hasTouch) {
|
1569 | return new TouchEventInput();
|
1570 | } else if (hasMouse) {
|
1571 | return new MouseEventInput();
|
1572 | }
|
1573 |
|
1574 | return null;
|
1575 | };
|
1576 | function getAddEventOptions(eventName) {
|
1577 |
|
1578 |
|
1579 | return eventName.indexOf("touch") > -1 ? {
|
1580 | passive: false
|
1581 | } : false;
|
1582 | }
|
1583 |
|
1584 | var InputObserver =
|
1585 |
|
1586 | function () {
|
1587 | function InputObserver(_a) {
|
1588 | var options = _a.options,
|
1589 | interruptManager = _a.interruptManager,
|
1590 | eventManager = _a.eventManager,
|
1591 | axisManager = _a.axisManager,
|
1592 | animationManager = _a.animationManager;
|
1593 | this._isOutside = false;
|
1594 | this._moveDistance = null;
|
1595 | this._isStopped = false;
|
1596 | this.options = options;
|
1597 | this._interruptManager = interruptManager;
|
1598 | this._eventManager = eventManager;
|
1599 | this._axisManager = axisManager;
|
1600 | this._animationManager = animationManager;
|
1601 | }
|
1602 |
|
1603 | var __proto = InputObserver.prototype;
|
1604 |
|
1605 | __proto.get = function (input) {
|
1606 | return this._axisManager.get(input.axes);
|
1607 | };
|
1608 |
|
1609 | __proto.hold = function (input, event) {
|
1610 | if (this._interruptManager.isInterrupted() || !input.axes.length) {
|
1611 | return;
|
1612 | }
|
1613 |
|
1614 | var changeOption = {
|
1615 | input: input,
|
1616 | event: event
|
1617 | };
|
1618 | this._isStopped = false;
|
1619 |
|
1620 | this._interruptManager.setInterrupt(true);
|
1621 |
|
1622 | this._animationManager.stopAnimation(changeOption);
|
1623 |
|
1624 | if (!this._moveDistance) {
|
1625 | this._eventManager.hold(this._axisManager.get(), changeOption);
|
1626 | }
|
1627 |
|
1628 | this._isOutside = this._axisManager.isOutside(input.axes);
|
1629 | this._moveDistance = this._axisManager.get(input.axes);
|
1630 | };
|
1631 |
|
1632 | __proto.change = function (input, event, offset, useAnimation) {
|
1633 | if (this._isStopped || !this._interruptManager.isInterrupting() || this._axisManager.every(offset, function (v) {
|
1634 | return v === 0;
|
1635 | })) {
|
1636 | return;
|
1637 | }
|
1638 |
|
1639 | var nativeEvent = event.srcEvent ? event.srcEvent : event;
|
1640 |
|
1641 | if (nativeEvent.__childrenAxesAlreadyChanged) {
|
1642 | return;
|
1643 | }
|
1644 |
|
1645 | var depaPos = this._moveDistance || this._axisManager.get(input.axes);
|
1646 |
|
1647 | var destPos;
|
1648 |
|
1649 | destPos = map(depaPos, function (v, k) {
|
1650 | return v + (offset[k] || 0);
|
1651 | });
|
1652 |
|
1653 | if (this._moveDistance) {
|
1654 | this._moveDistance = this._axisManager.map(destPos, function (v, _a) {
|
1655 | var circular = _a.circular,
|
1656 | range = _a.range;
|
1657 | return circular && (circular[0] || circular[1]) ? getCirculatedPos(v, range, circular) : v;
|
1658 | });
|
1659 | }
|
1660 |
|
1661 |
|
1662 | if (this._isOutside && this._axisManager.every(depaPos, function (v, opt) {
|
1663 | return !isOutside(v, opt.range);
|
1664 | })) {
|
1665 | this._isOutside = false;
|
1666 | }
|
1667 |
|
1668 | depaPos = this._atOutside(depaPos);
|
1669 | destPos = this._atOutside(destPos);
|
1670 |
|
1671 | if (!this.options.nested || !this._isEndofAxis(offset, depaPos, destPos)) {
|
1672 | nativeEvent.__childrenAxesAlreadyChanged = true;
|
1673 | }
|
1674 |
|
1675 | var changeOption = {
|
1676 | input: input,
|
1677 | event: event
|
1678 | };
|
1679 |
|
1680 | if (useAnimation) {
|
1681 | var duration = this._animationManager.getDuration(destPos, depaPos);
|
1682 |
|
1683 | this._animationManager.animateTo(destPos, duration, changeOption);
|
1684 | } else {
|
1685 | var isCanceled = !this._eventManager.triggerChange(destPos, depaPos, changeOption, true);
|
1686 |
|
1687 | if (isCanceled) {
|
1688 | this._isStopped = true;
|
1689 | this._moveDistance = null;
|
1690 |
|
1691 | this._animationManager.finish(false);
|
1692 | }
|
1693 | }
|
1694 | };
|
1695 |
|
1696 | __proto.release = function (input, event, velocity, inputDuration) {
|
1697 | if (this._isStopped || !this._interruptManager.isInterrupting() || !this._moveDistance) {
|
1698 | return;
|
1699 | }
|
1700 |
|
1701 | var nativeEvent = event.srcEvent ? event.srcEvent : event;
|
1702 |
|
1703 | if (nativeEvent.__childrenAxesAlreadyReleased) {
|
1704 | velocity = velocity.map(function () {
|
1705 | return 0;
|
1706 | });
|
1707 | }
|
1708 |
|
1709 | var pos = this._axisManager.get(input.axes);
|
1710 |
|
1711 | var depaPos = this._axisManager.get();
|
1712 |
|
1713 | var displacement = this._animationManager.getDisplacement(velocity);
|
1714 |
|
1715 | var offset = toAxis(input.axes, displacement);
|
1716 |
|
1717 | var destPos = this._axisManager.get(this._axisManager.map(offset, function (v, opt, k) {
|
1718 | if (opt.circular && (opt.circular[0] || opt.circular[1])) {
|
1719 | return pos[k] + v;
|
1720 | } else {
|
1721 | return getInsidePosition(pos[k] + v, opt.range, opt.circular, opt.bounce);
|
1722 | }
|
1723 | }));
|
1724 |
|
1725 | nativeEvent.__childrenAxesAlreadyReleased = true;
|
1726 |
|
1727 | var duration = this._animationManager.getDuration(destPos, pos, inputDuration);
|
1728 |
|
1729 | if (duration === 0) {
|
1730 | destPos = __assign({}, depaPos);
|
1731 | }
|
1732 |
|
1733 |
|
1734 | var param = {
|
1735 | depaPos: depaPos,
|
1736 | destPos: destPos,
|
1737 | duration: duration,
|
1738 | delta: this._axisManager.getDelta(depaPos, destPos),
|
1739 | inputEvent: event,
|
1740 | input: input,
|
1741 | isTrusted: true
|
1742 | };
|
1743 |
|
1744 | this._eventManager.triggerRelease(param);
|
1745 |
|
1746 | this._moveDistance = null;
|
1747 |
|
1748 | var userWish = this._animationManager.getUserControl(param);
|
1749 |
|
1750 | var isEqual = equal(userWish.destPos, depaPos);
|
1751 | var changeOption = {
|
1752 | input: input,
|
1753 | event: event
|
1754 | };
|
1755 |
|
1756 | if (isEqual || userWish.duration === 0) {
|
1757 | if (!isEqual) {
|
1758 | this._eventManager.triggerChange(userWish.destPos, depaPos, changeOption, true);
|
1759 | }
|
1760 |
|
1761 | this._interruptManager.setInterrupt(false);
|
1762 |
|
1763 | if (this._axisManager.isOutside()) {
|
1764 | this._animationManager.restore(changeOption);
|
1765 | } else {
|
1766 | this._eventManager.triggerFinish(true);
|
1767 | }
|
1768 | } else {
|
1769 | this._animationManager.animateTo(userWish.destPos, userWish.duration, changeOption);
|
1770 | }
|
1771 | };
|
1772 |
|
1773 |
|
1774 | __proto._atOutside = function (pos) {
|
1775 | var _this = this;
|
1776 |
|
1777 | if (this._isOutside) {
|
1778 | return this._axisManager.map(pos, function (v, opt) {
|
1779 | var tn = opt.range[0] - opt.bounce[0];
|
1780 | var tx = opt.range[1] + opt.bounce[1];
|
1781 | return v > tx ? tx : v < tn ? tn : v;
|
1782 | });
|
1783 | } else {
|
1784 | return this._axisManager.map(pos, function (v, opt) {
|
1785 | var min = opt.range[0];
|
1786 | var max = opt.range[1];
|
1787 | var out = opt.bounce;
|
1788 | var circular = opt.circular;
|
1789 |
|
1790 | if (circular[0] && v < min || circular[1] && v > max) {
|
1791 | return v;
|
1792 | } else if (v < min) {
|
1793 |
|
1794 | return min - _this._animationManager.interpolate(min - v, out[0]);
|
1795 | } else if (v > max) {
|
1796 |
|
1797 | return max + _this._animationManager.interpolate(v - max, out[1]);
|
1798 | }
|
1799 |
|
1800 | return v;
|
1801 | });
|
1802 | }
|
1803 | };
|
1804 |
|
1805 | __proto._isEndofAxis = function (offset, depaPos, destPos) {
|
1806 | return this._axisManager.every(depaPos, function (value, option, key) {
|
1807 | return offset[key] === 0 || depaPos[key] === destPos[key] && isEndofBounce(value, option.range, option.bounce, option.circular);
|
1808 | });
|
1809 | };
|
1810 |
|
1811 | return InputObserver;
|
1812 | }();
|
1813 |
|
1814 | var clamp = function (value, min, max) {
|
1815 | return Math.max(Math.min(value, max), min);
|
1816 | };
|
1817 |
|
1818 | var AnimationManager =
|
1819 |
|
1820 | function () {
|
1821 | function AnimationManager(_a) {
|
1822 | var options = _a.options,
|
1823 | interruptManager = _a.interruptManager,
|
1824 | eventManager = _a.eventManager,
|
1825 | axisManager = _a.axisManager;
|
1826 | this._options = options;
|
1827 | this.interruptManager = interruptManager;
|
1828 | this.eventManager = eventManager;
|
1829 | this.axisManager = axisManager;
|
1830 | this.animationEnd = this.animationEnd.bind(this);
|
1831 | }
|
1832 |
|
1833 | var __proto = AnimationManager.prototype;
|
1834 |
|
1835 | __proto.getDuration = function (depaPos, destPos, wishDuration) {
|
1836 | var _this = this;
|
1837 |
|
1838 | var duration;
|
1839 |
|
1840 | if (typeof wishDuration !== "undefined") {
|
1841 | duration = wishDuration;
|
1842 | } else {
|
1843 | var durations_1 = map(destPos, function (v, k) {
|
1844 | return getDuration(Math.abs(v - depaPos[k]), _this._options.deceleration);
|
1845 | });
|
1846 | duration = Object.keys(durations_1).reduce(function (max, v) {
|
1847 | return Math.max(max, durations_1[v]);
|
1848 | }, -Infinity);
|
1849 | }
|
1850 |
|
1851 | return clamp(duration, this._options.minimumDuration, this._options.maximumDuration);
|
1852 | };
|
1853 |
|
1854 | __proto.getDisplacement = function (velocity) {
|
1855 | var totalVelocity = Math.pow(velocity.reduce(function (total, v) {
|
1856 | return total + v * v;
|
1857 | }, 0), 1 / velocity.length);
|
1858 | var duration = Math.abs(totalVelocity / -this._options.deceleration);
|
1859 | return velocity.map(function (v) {
|
1860 | return v / 2 * duration;
|
1861 | });
|
1862 | };
|
1863 |
|
1864 | __proto.stopAnimation = function (option) {
|
1865 | if (this._animateParam) {
|
1866 | var orgPos_1 = this.axisManager.get();
|
1867 | var pos = this.axisManager.map(orgPos_1, function (v, opt) {
|
1868 | return getCirculatedPos(v, opt.range, opt.circular);
|
1869 | });
|
1870 |
|
1871 | if (!every(pos, function (v, k) {
|
1872 | return orgPos_1[k] === v;
|
1873 | })) {
|
1874 | this.eventManager.triggerChange(pos, orgPos_1, option, !!option);
|
1875 | }
|
1876 |
|
1877 | this._animateParam = null;
|
1878 |
|
1879 | if (this._raf) {
|
1880 | cancelAnimationFrame(this._raf);
|
1881 | }
|
1882 |
|
1883 | this._raf = null;
|
1884 | this.eventManager.triggerAnimationEnd(!!(option === null || option === void 0 ? void 0 : option.event));
|
1885 | }
|
1886 | };
|
1887 |
|
1888 | __proto.getEventInfo = function () {
|
1889 | if (this._animateParam && this._animateParam.input && this._animateParam.inputEvent) {
|
1890 | return {
|
1891 | input: this._animateParam.input,
|
1892 | event: this._animateParam.inputEvent
|
1893 | };
|
1894 | } else {
|
1895 | return null;
|
1896 | }
|
1897 | };
|
1898 |
|
1899 | __proto.restore = function (option) {
|
1900 | var pos = this.axisManager.get();
|
1901 | var destPos = this.axisManager.map(pos, function (v, opt) {
|
1902 | return Math.min(opt.range[1], Math.max(opt.range[0], v));
|
1903 | });
|
1904 | this.stopAnimation();
|
1905 | this.animateTo(destPos, this.getDuration(pos, destPos), option);
|
1906 | };
|
1907 |
|
1908 | __proto.animationEnd = function () {
|
1909 | var beforeParam = this.getEventInfo();
|
1910 | this._animateParam = null;
|
1911 |
|
1912 | var circularTargets = this.axisManager.filter(this.axisManager.get(), function (v, opt) {
|
1913 | return isCircularable(v, opt.range, opt.circular);
|
1914 | });
|
1915 |
|
1916 | if (Object.keys(circularTargets).length > 0) {
|
1917 | this.setTo(this.axisManager.map(circularTargets, function (v, opt) {
|
1918 | return getCirculatedPos(v, opt.range, opt.circular);
|
1919 | }));
|
1920 | }
|
1921 |
|
1922 | this.interruptManager.setInterrupt(false);
|
1923 | this.eventManager.triggerAnimationEnd(!!beforeParam);
|
1924 |
|
1925 | if (this.axisManager.isOutside()) {
|
1926 | this.restore(beforeParam);
|
1927 | } else {
|
1928 | this.finish(!!beforeParam);
|
1929 | }
|
1930 | };
|
1931 |
|
1932 | __proto.finish = function (isTrusted) {
|
1933 | this._animateParam = null;
|
1934 | this.interruptManager.setInterrupt(false);
|
1935 | this.eventManager.triggerFinish(isTrusted);
|
1936 | };
|
1937 |
|
1938 | __proto.getUserControl = function (param) {
|
1939 | var userWish = param.setTo();
|
1940 | userWish.destPos = this.axisManager.get(userWish.destPos);
|
1941 | userWish.duration = clamp(userWish.duration, this._options.minimumDuration, this._options.maximumDuration);
|
1942 | return userWish;
|
1943 | };
|
1944 |
|
1945 | __proto.animateTo = function (destPos, duration, option) {
|
1946 | var _this = this;
|
1947 |
|
1948 | this.stopAnimation();
|
1949 |
|
1950 | var param = this._createAnimationParam(destPos, duration, option);
|
1951 |
|
1952 | var depaPos = __assign({}, param.depaPos);
|
1953 |
|
1954 | var retTrigger = this.eventManager.triggerAnimationStart(param);
|
1955 |
|
1956 | var userWish = this.getUserControl(param);
|
1957 |
|
1958 | if (!retTrigger && this.axisManager.every(userWish.destPos, function (v, opt) {
|
1959 | return isCircularable(v, opt.range, opt.circular);
|
1960 | })) {
|
1961 | console.warn("You can't stop the 'animation' event when 'circular' is true.");
|
1962 | }
|
1963 |
|
1964 | if (retTrigger && !equal(userWish.destPos, depaPos)) {
|
1965 | var inputEvent = (option === null || option === void 0 ? void 0 : option.event) || null;
|
1966 |
|
1967 | this._animateLoop({
|
1968 | depaPos: depaPos,
|
1969 | destPos: userWish.destPos,
|
1970 | duration: userWish.duration,
|
1971 | delta: this.axisManager.getDelta(depaPos, userWish.destPos),
|
1972 | isTrusted: !!inputEvent,
|
1973 | inputEvent: inputEvent,
|
1974 | input: (option === null || option === void 0 ? void 0 : option.input) || null
|
1975 | }, function () {
|
1976 | return _this.animationEnd();
|
1977 | });
|
1978 | }
|
1979 | };
|
1980 |
|
1981 | __proto.setTo = function (pos, duration) {
|
1982 | if (duration === void 0) {
|
1983 | duration = 0;
|
1984 | }
|
1985 |
|
1986 | var axes = Object.keys(pos);
|
1987 | var orgPos = this.axisManager.get(axes);
|
1988 |
|
1989 | if (equal(pos, orgPos)) {
|
1990 | return this;
|
1991 | }
|
1992 |
|
1993 | this.interruptManager.setInterrupt(true);
|
1994 | var movedPos = filter(pos, function (v, k) {
|
1995 | return orgPos[k] !== v;
|
1996 | });
|
1997 |
|
1998 | if (!Object.keys(movedPos).length) {
|
1999 | return this;
|
2000 | }
|
2001 |
|
2002 | movedPos = this.axisManager.map(movedPos, function (v, opt) {
|
2003 | var range = opt.range,
|
2004 | circular = opt.circular;
|
2005 |
|
2006 | if (circular && (circular[0] || circular[1])) {
|
2007 | return v;
|
2008 | } else {
|
2009 | return getInsidePosition(v, range, circular);
|
2010 | }
|
2011 | });
|
2012 |
|
2013 | if (equal(movedPos, orgPos)) {
|
2014 | return this;
|
2015 | }
|
2016 |
|
2017 | if (duration > 0) {
|
2018 | this.animateTo(movedPos, duration);
|
2019 | } else {
|
2020 | this.stopAnimation();
|
2021 | this.eventManager.triggerChange(movedPos);
|
2022 | this.finish(false);
|
2023 | }
|
2024 |
|
2025 | return this;
|
2026 | };
|
2027 |
|
2028 | __proto.setBy = function (pos, duration) {
|
2029 | if (duration === void 0) {
|
2030 | duration = 0;
|
2031 | }
|
2032 |
|
2033 | return this.setTo(map(this.axisManager.get(Object.keys(pos)), function (v, k) {
|
2034 | return v + pos[k];
|
2035 | }), duration);
|
2036 | };
|
2037 |
|
2038 | __proto._createAnimationParam = function (pos, duration, option) {
|
2039 | var depaPos = this.axisManager.get();
|
2040 | var destPos = pos;
|
2041 | var inputEvent = (option === null || option === void 0 ? void 0 : option.event) || null;
|
2042 | return {
|
2043 | depaPos: depaPos,
|
2044 | destPos: destPos,
|
2045 | duration: clamp(duration, this._options.minimumDuration, this._options.maximumDuration),
|
2046 | delta: this.axisManager.getDelta(depaPos, destPos),
|
2047 | inputEvent: inputEvent,
|
2048 | input: (option === null || option === void 0 ? void 0 : option.input) || null,
|
2049 | isTrusted: !!inputEvent,
|
2050 | done: this.animationEnd
|
2051 | };
|
2052 | };
|
2053 |
|
2054 | __proto._animateLoop = function (param, complete) {
|
2055 | var _this = this;
|
2056 |
|
2057 | if (param.duration) {
|
2058 | this._animateParam = __assign(__assign({}, param), {
|
2059 | startTime: new Date().getTime()
|
2060 | });
|
2061 | var originalIntendedPos_1 = map(param.destPos, function (v) {
|
2062 | return v;
|
2063 | });
|
2064 |
|
2065 | var state_1 = this._initState(this._animateParam);
|
2066 |
|
2067 | var loop_1 = function () {
|
2068 | _this._raf = null;
|
2069 | var animateParam = _this._animateParam;
|
2070 |
|
2071 | var nextState = _this._getNextState(state_1);
|
2072 |
|
2073 | var isCanceled = !_this.eventManager.triggerChange(nextState.pos, state_1.pos);
|
2074 | state_1 = nextState;
|
2075 |
|
2076 | if (nextState.finished) {
|
2077 | animateParam.destPos = _this._getFinalPos(animateParam.destPos, originalIntendedPos_1);
|
2078 |
|
2079 | if (!equal(animateParam.destPos, _this.axisManager.get(Object.keys(animateParam.destPos)))) {
|
2080 | _this.eventManager.triggerChange(animateParam.destPos, nextState.pos);
|
2081 | }
|
2082 |
|
2083 | complete();
|
2084 | return;
|
2085 | } else if (isCanceled) {
|
2086 | _this.finish(false);
|
2087 | } else {
|
2088 | _this._raf = requestAnimationFrame(loop_1);
|
2089 | }
|
2090 | };
|
2091 |
|
2092 | loop_1();
|
2093 | } else {
|
2094 | this.eventManager.triggerChange(param.destPos);
|
2095 | complete();
|
2096 | }
|
2097 | };
|
2098 | |
2099 |
|
2100 |
|
2101 |
|
2102 |
|
2103 |
|
2104 |
|
2105 |
|
2106 |
|
2107 |
|
2108 |
|
2109 |
|
2110 | __proto._getFinalPos = function (destPos, originalIntendedPos) {
|
2111 | var _this = this;
|
2112 |
|
2113 |
|
2114 |
|
2115 | var ERROR_LIMIT = 0.000001;
|
2116 | var finalPos = map(destPos, function (value, key) {
|
2117 | if (value >= originalIntendedPos[key] - ERROR_LIMIT && value <= originalIntendedPos[key] + ERROR_LIMIT) {
|
2118 |
|
2119 | return originalIntendedPos[key];
|
2120 | } else {
|
2121 |
|
2122 | var roundUnit = _this._getRoundUnit(value, key);
|
2123 |
|
2124 | var result = roundNumber(value, roundUnit);
|
2125 | return result;
|
2126 | }
|
2127 | });
|
2128 | return finalPos;
|
2129 | };
|
2130 |
|
2131 | __proto._getRoundUnit = function (val, key) {
|
2132 | var roundUnit = this._options.round;
|
2133 |
|
2134 | var minRoundUnit = null;
|
2135 |
|
2136 |
|
2137 | if (!roundUnit) {
|
2138 |
|
2139 | var options = this.axisManager.getAxisOptions(key);
|
2140 | minRoundUnit = inversePow(Math.max(getDecimalPlace(options.range[0]), getDecimalPlace(options.range[1]), getDecimalPlace(val)));
|
2141 | }
|
2142 |
|
2143 | return minRoundUnit || roundUnit;
|
2144 | };
|
2145 |
|
2146 | return AnimationManager;
|
2147 | }();
|
2148 |
|
2149 | var EasingManager =
|
2150 |
|
2151 | function (_super) {
|
2152 | __extends(EasingManager, _super);
|
2153 |
|
2154 | function EasingManager() {
|
2155 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
2156 |
|
2157 | _this._useDuration = true;
|
2158 | return _this;
|
2159 | }
|
2160 |
|
2161 | var __proto = EasingManager.prototype;
|
2162 |
|
2163 | __proto.interpolate = function (displacement, threshold) {
|
2164 | var initSlope = this._easing(0.00001) / 0.00001;
|
2165 | return this._easing(displacement / (threshold * initSlope)) * threshold;
|
2166 | };
|
2167 |
|
2168 | __proto.updateAnimation = function (options) {
|
2169 | var _a;
|
2170 |
|
2171 | var animateParam = this._animateParam;
|
2172 |
|
2173 | if (!animateParam) {
|
2174 | return;
|
2175 | }
|
2176 |
|
2177 | var diffTime = new Date().getTime() - animateParam.startTime;
|
2178 | var pos = (options === null || options === void 0 ? void 0 : options.destPos) || animateParam.destPos;
|
2179 | var duration = (_a = options === null || options === void 0 ? void 0 : options.duration) !== null && _a !== void 0 ? _a : animateParam.duration;
|
2180 |
|
2181 | if ((options === null || options === void 0 ? void 0 : options.restart) || duration <= diffTime) {
|
2182 | this.setTo(pos, duration - diffTime);
|
2183 | return;
|
2184 | }
|
2185 |
|
2186 | if (options === null || options === void 0 ? void 0 : options.destPos) {
|
2187 | var currentPos = this.axisManager.get();
|
2188 |
|
2189 |
|
2190 |
|
2191 |
|
2192 | this._initialEasingPer = this._prevEasingPer;
|
2193 | animateParam.delta = this.axisManager.getDelta(currentPos, pos);
|
2194 | animateParam.destPos = pos;
|
2195 | }
|
2196 |
|
2197 | if (options === null || options === void 0 ? void 0 : options.duration) {
|
2198 | var ratio = (diffTime + this._durationOffset) / animateParam.duration;
|
2199 |
|
2200 |
|
2201 |
|
2202 | this._durationOffset = ratio * duration - diffTime;
|
2203 | animateParam.duration = duration;
|
2204 | }
|
2205 | };
|
2206 |
|
2207 | __proto._initState = function (info) {
|
2208 | this._initialEasingPer = 0;
|
2209 | this._prevEasingPer = 0;
|
2210 | this._durationOffset = 0;
|
2211 | return {
|
2212 | pos: info.depaPos,
|
2213 | easingPer: 0,
|
2214 | finished: false
|
2215 | };
|
2216 | };
|
2217 |
|
2218 | __proto._getNextState = function (prevState) {
|
2219 | var _this = this;
|
2220 |
|
2221 | var animateParam = this._animateParam;
|
2222 | var prevPos = prevState.pos;
|
2223 | var destPos = animateParam.destPos;
|
2224 | var directions = map(prevPos, function (value, key) {
|
2225 | return value <= destPos[key] ? 1 : -1;
|
2226 | });
|
2227 | var diffTime = new Date().getTime() - animateParam.startTime;
|
2228 | var ratio = (diffTime + this._durationOffset) / animateParam.duration;
|
2229 |
|
2230 | var easingPer = this._easing(ratio);
|
2231 |
|
2232 | var toPos = this.axisManager.map(prevPos, function (pos, options, key) {
|
2233 | var nextPos = ratio >= 1 ? destPos[key] : pos + animateParam.delta[key] * (easingPer - _this._prevEasingPer) / (1 - _this._initialEasingPer);
|
2234 |
|
2235 |
|
2236 |
|
2237 | var circulatedPos = getCirculatedPos(nextPos, options.range, options.circular);
|
2238 |
|
2239 | if (nextPos !== circulatedPos) {
|
2240 |
|
2241 | var rangeOffset = directions[key] * (options.range[1] - options.range[0]);
|
2242 | destPos[key] -= rangeOffset;
|
2243 | prevPos[key] -= rangeOffset;
|
2244 | }
|
2245 |
|
2246 | return circulatedPos;
|
2247 | });
|
2248 | this._prevEasingPer = easingPer;
|
2249 | return {
|
2250 | pos: toPos,
|
2251 | easingPer: easingPer,
|
2252 | finished: easingPer >= 1
|
2253 | };
|
2254 | };
|
2255 |
|
2256 | __proto._easing = function (p) {
|
2257 | return p > 1 ? 1 : this._options.easing(p);
|
2258 | };
|
2259 |
|
2260 | return EasingManager;
|
2261 | }(AnimationManager);
|
2262 |
|
2263 | |
2264 |
|
2265 |
|
2266 |
|
2267 |
|
2268 |
|
2269 |
|
2270 |
|
2271 |
|
2272 |
|
2273 |
|
2274 |
|
2275 |
|
2276 |
|
2277 |
|
2278 | |
2279 |
|
2280 |
|
2281 |
|
2282 |
|
2283 |
|
2284 |
|
2285 |
|
2286 |
|
2287 |
|
2288 |
|
2289 |
|
2290 |
|
2291 |
|
2292 |
|
2293 |
|
2294 |
|
2295 |
|
2296 |
|
2297 | |
2298 |
|
2299 |
|
2300 |
|
2301 |
|
2302 |
|
2303 |
|
2304 |
|
2305 |
|
2306 |
|
2307 |
|
2308 |
|
2309 |
|
2310 |
|
2311 |
|
2312 |
|
2313 |
|
2314 |
|
2315 |
|
2316 |
|
2317 |
|
2318 |
|
2319 |
|
2320 |
|
2321 |
|
2322 |
|
2323 |
|
2324 |
|
2325 |
|
2326 |
|
2327 |
|
2328 |
|
2329 |
|
2330 |
|
2331 |
|
2332 |
|
2333 |
|
2334 |
|
2335 |
|
2336 |
|
2337 |
|
2338 |
|
2339 |
|
2340 |
|
2341 |
|
2342 |
|
2343 |
|
2344 |
|
2345 |
|
2346 |
|
2347 |
|
2348 |
|
2349 |
|
2350 |
|
2351 |
|
2352 |
|
2353 |
|
2354 |
|
2355 |
|
2356 |
|
2357 |
|
2358 |
|
2359 |
|
2360 |
|
2361 |
|
2362 |
|
2363 |
|
2364 |
|
2365 |
|
2366 |
|
2367 | var Axes =
|
2368 |
|
2369 | function (_super) {
|
2370 | __extends(Axes, _super);
|
2371 | |
2372 |
|
2373 |
|
2374 |
|
2375 |
|
2376 | function Axes(axis, options, startPos) {
|
2377 | if (axis === void 0) {
|
2378 | axis = {};
|
2379 | }
|
2380 |
|
2381 | if (options === void 0) {
|
2382 | options = {};
|
2383 | }
|
2384 |
|
2385 | if (startPos === void 0) {
|
2386 | startPos = {};
|
2387 | }
|
2388 |
|
2389 | var _this = _super.call(this) || this;
|
2390 |
|
2391 | _this.axis = axis;
|
2392 | _this._inputs = [];
|
2393 | _this.options = __assign({
|
2394 | easing: function (x) {
|
2395 | return 1 - Math.pow(1 - x, 3);
|
2396 | },
|
2397 | interruptable: true,
|
2398 | maximumDuration: Infinity,
|
2399 | minimumDuration: 0,
|
2400 | deceleration: 0.0006,
|
2401 | round: null,
|
2402 | nested: false
|
2403 | }, options);
|
2404 | Object.keys(startPos).forEach(function (key) {
|
2405 | _this.axis[key].startPos = startPos[key];
|
2406 | });
|
2407 | _this.interruptManager = new InterruptManager(_this.options);
|
2408 | _this.axisManager = new AxisManager(_this.axis);
|
2409 | _this.eventManager = new EventManager(_this);
|
2410 | _this.animationManager = new EasingManager(_this);
|
2411 | _this.inputObserver = new InputObserver(_this);
|
2412 |
|
2413 | _this.eventManager.setAnimationManager(_this.animationManager);
|
2414 |
|
2415 | _this.eventManager.triggerChange(_this.axisManager.get());
|
2416 |
|
2417 | return _this;
|
2418 | }
|
2419 | |
2420 |
|
2421 |
|
2422 |
|
2423 |
|
2424 |
|
2425 |
|
2426 |
|
2427 |
|
2428 |
|
2429 |
|
2430 |
|
2431 |
|
2432 |
|
2433 |
|
2434 |
|
2435 |
|
2436 |
|
2437 |
|
2438 |
|
2439 |
|
2440 |
|
2441 |
|
2442 |
|
2443 |
|
2444 |
|
2445 |
|
2446 | var __proto = Axes.prototype;
|
2447 |
|
2448 | __proto.connect = function (axes, inputType) {
|
2449 | var mapped;
|
2450 |
|
2451 | if (typeof axes === "string") {
|
2452 | mapped = axes.split(" ");
|
2453 | } else {
|
2454 | mapped = axes.concat();
|
2455 | }
|
2456 |
|
2457 |
|
2458 | if (~this._inputs.indexOf(inputType)) {
|
2459 | this.disconnect(inputType);
|
2460 | }
|
2461 |
|
2462 | inputType.mapAxes(mapped);
|
2463 | inputType.connect(this.inputObserver);
|
2464 |
|
2465 | this._inputs.push(inputType);
|
2466 |
|
2467 | return this;
|
2468 | };
|
2469 | |
2470 |
|
2471 |
|
2472 |
|
2473 |
|
2474 |
|
2475 |
|
2476 |
|
2477 |
|
2478 |
|
2479 |
|
2480 |
|
2481 |
|
2482 |
|
2483 |
|
2484 |
|
2485 |
|
2486 |
|
2487 |
|
2488 |
|
2489 |
|
2490 |
|
2491 |
|
2492 |
|
2493 |
|
2494 |
|
2495 |
|
2496 |
|
2497 |
|
2498 |
|
2499 | __proto.disconnect = function (inputType) {
|
2500 | if (inputType) {
|
2501 | var index = this._inputs.indexOf(inputType);
|
2502 |
|
2503 | if (index >= 0) {
|
2504 | this._inputs[index].disconnect();
|
2505 |
|
2506 | this._inputs.splice(index, 1);
|
2507 | }
|
2508 | } else {
|
2509 | this._inputs.forEach(function (v) {
|
2510 | return v.disconnect();
|
2511 | });
|
2512 |
|
2513 | this._inputs = [];
|
2514 | }
|
2515 |
|
2516 | return this;
|
2517 | };
|
2518 | |
2519 |
|
2520 |
|
2521 |
|
2522 |
|
2523 |
|
2524 |
|
2525 |
|
2526 |
|
2527 |
|
2528 |
|
2529 |
|
2530 |
|
2531 |
|
2532 |
|
2533 |
|
2534 |
|
2535 |
|
2536 |
|
2537 |
|
2538 |
|
2539 |
|
2540 |
|
2541 |
|
2542 |
|
2543 | __proto.get = function (axes) {
|
2544 | return this.axisManager.get(axes);
|
2545 | };
|
2546 | |
2547 |
|
2548 |
|
2549 |
|
2550 |
|
2551 |
|
2552 |
|
2553 |
|
2554 |
|
2555 |
|
2556 |
|
2557 |
|
2558 |
|
2559 |
|
2560 |
|
2561 |
|
2562 |
|
2563 |
|
2564 |
|
2565 |
|
2566 |
|
2567 |
|
2568 |
|
2569 |
|
2570 |
|
2571 |
|
2572 |
|
2573 |
|
2574 |
|
2575 |
|
2576 |
|
2577 | __proto.setTo = function (pos, duration) {
|
2578 | if (duration === void 0) {
|
2579 | duration = 0;
|
2580 | }
|
2581 |
|
2582 | this.animationManager.setTo(pos, duration);
|
2583 | return this;
|
2584 | };
|
2585 | |
2586 |
|
2587 |
|
2588 |
|
2589 |
|
2590 |
|
2591 |
|
2592 |
|
2593 |
|
2594 |
|
2595 |
|
2596 |
|
2597 |
|
2598 |
|
2599 |
|
2600 |
|
2601 |
|
2602 |
|
2603 |
|
2604 |
|
2605 |
|
2606 |
|
2607 |
|
2608 |
|
2609 |
|
2610 |
|
2611 |
|
2612 |
|
2613 |
|
2614 |
|
2615 |
|
2616 | __proto.setBy = function (pos, duration) {
|
2617 | if (duration === void 0) {
|
2618 | duration = 0;
|
2619 | }
|
2620 |
|
2621 | this.animationManager.setBy(pos, duration);
|
2622 | return this;
|
2623 | };
|
2624 | |
2625 |
|
2626 |
|
2627 |
|
2628 |
|
2629 |
|
2630 |
|
2631 |
|
2632 |
|
2633 |
|
2634 |
|
2635 |
|
2636 |
|
2637 |
|
2638 |
|
2639 |
|
2640 |
|
2641 |
|
2642 |
|
2643 |
|
2644 |
|
2645 |
|
2646 |
|
2647 |
|
2648 |
|
2649 |
|
2650 |
|
2651 |
|
2652 | __proto.setOptions = function (options) {
|
2653 | this.options = __assign(__assign({}, this.options), options);
|
2654 | return this;
|
2655 | };
|
2656 | |
2657 |
|
2658 |
|
2659 |
|
2660 |
|
2661 |
|
2662 |
|
2663 |
|
2664 |
|
2665 |
|
2666 |
|
2667 |
|
2668 |
|
2669 |
|
2670 |
|
2671 |
|
2672 |
|
2673 |
|
2674 |
|
2675 |
|
2676 |
|
2677 |
|
2678 |
|
2679 |
|
2680 |
|
2681 |
|
2682 |
|
2683 |
|
2684 | __proto.setAxis = function (axis) {
|
2685 | this.axisManager.setAxis(axis);
|
2686 | return this;
|
2687 | };
|
2688 | |
2689 |
|
2690 |
|
2691 |
|
2692 |
|
2693 |
|
2694 |
|
2695 |
|
2696 |
|
2697 |
|
2698 |
|
2699 |
|
2700 |
|
2701 |
|
2702 |
|
2703 |
|
2704 |
|
2705 |
|
2706 |
|
2707 |
|
2708 | __proto.stopAnimation = function () {
|
2709 | this.animationManager.stopAnimation();
|
2710 | this.animationManager.finish(false);
|
2711 | return this;
|
2712 | };
|
2713 | |
2714 |
|
2715 |
|
2716 |
|
2717 |
|
2718 |
|
2719 |
|
2720 |
|
2721 |
|
2722 |
|
2723 |
|
2724 |
|
2725 |
|
2726 |
|
2727 |
|
2728 |
|
2729 |
|
2730 |
|
2731 |
|
2732 |
|
2733 |
|
2734 |
|
2735 |
|
2736 |
|
2737 |
|
2738 |
|
2739 |
|
2740 |
|
2741 |
|
2742 |
|
2743 | __proto.updateAnimation = function (options) {
|
2744 | this.animationManager.updateAnimation(options);
|
2745 | return this;
|
2746 | };
|
2747 | |
2748 |
|
2749 |
|
2750 |
|
2751 |
|
2752 |
|
2753 |
|
2754 |
|
2755 |
|
2756 |
|
2757 |
|
2758 |
|
2759 |
|
2760 |
|
2761 |
|
2762 |
|
2763 |
|
2764 |
|
2765 |
|
2766 |
|
2767 |
|
2768 |
|
2769 |
|
2770 |
|
2771 |
|
2772 |
|
2773 | __proto.isBounceArea = function (axes) {
|
2774 | return this.axisManager.isOutside(axes);
|
2775 | };
|
2776 | |
2777 |
|
2778 |
|
2779 |
|
2780 |
|
2781 |
|
2782 | __proto.destroy = function () {
|
2783 | this.disconnect();
|
2784 | this.eventManager.destroy();
|
2785 | };
|
2786 | |
2787 |
|
2788 |
|
2789 |
|
2790 |
|
2791 |
|
2792 |
|
2793 |
|
2794 |
|
2795 |
|
2796 |
|
2797 |
|
2798 |
|
2799 |
|
2800 | Axes.VERSION = "3.8.3";
|
2801 |
|
2802 |
|
2803 | |
2804 |
|
2805 |
|
2806 |
|
2807 |
|
2808 |
|
2809 |
|
2810 |
|
2811 |
|
2812 |
|
2813 |
|
2814 |
|
2815 |
|
2816 | Axes.TRANSFORM = TRANSFORM;
|
2817 | |
2818 |
|
2819 |
|
2820 |
|
2821 |
|
2822 |
|
2823 | Axes.DIRECTION_NONE = DIRECTION_NONE;
|
2824 | |
2825 |
|
2826 |
|
2827 |
|
2828 |
|
2829 |
|
2830 | Axes.DIRECTION_LEFT = DIRECTION_LEFT;
|
2831 | |
2832 |
|
2833 |
|
2834 |
|
2835 |
|
2836 |
|
2837 | Axes.DIRECTION_RIGHT = DIRECTION_RIGHT;
|
2838 | |
2839 |
|
2840 |
|
2841 |
|
2842 |
|
2843 |
|
2844 | Axes.DIRECTION_UP = DIRECTION_UP;
|
2845 | |
2846 |
|
2847 |
|
2848 |
|
2849 |
|
2850 |
|
2851 | Axes.DIRECTION_DOWN = DIRECTION_DOWN;
|
2852 | |
2853 |
|
2854 |
|
2855 |
|
2856 |
|
2857 |
|
2858 | Axes.DIRECTION_HORIZONTAL = DIRECTION_HORIZONTAL;
|
2859 | |
2860 |
|
2861 |
|
2862 |
|
2863 |
|
2864 |
|
2865 | Axes.DIRECTION_VERTICAL = DIRECTION_VERTICAL;
|
2866 | |
2867 |
|
2868 |
|
2869 |
|
2870 |
|
2871 |
|
2872 | Axes.DIRECTION_ALL = DIRECTION_ALL;
|
2873 | Axes = __decorate([core.ReactiveSubscribe], Axes);
|
2874 | return Axes;
|
2875 | }(Component);
|
2876 |
|
2877 | |
2878 |
|
2879 |
|
2880 |
|
2881 |
|
2882 | var getDirectionByAngle = function (angle, thresholdAngle) {
|
2883 | if (thresholdAngle < 0 || thresholdAngle > 90) {
|
2884 | return DIRECTION_NONE;
|
2885 | }
|
2886 |
|
2887 | var toAngle = Math.abs(angle);
|
2888 | return toAngle > thresholdAngle && toAngle < 180 - thresholdAngle ? DIRECTION_VERTICAL : DIRECTION_HORIZONTAL;
|
2889 | };
|
2890 | |
2891 |
|
2892 |
|
2893 |
|
2894 |
|
2895 |
|
2896 |
|
2897 |
|
2898 |
|
2899 |
|
2900 |
|
2901 |
|
2902 |
|
2903 |
|
2904 |
|
2905 |
|
2906 |
|
2907 |
|
2908 |
|
2909 |
|
2910 |
|
2911 |
|
2912 |
|
2913 |
|
2914 |
|
2915 |
|
2916 |
|
2917 |
|
2918 |
|
2919 |
|
2920 |
|
2921 |
|
2922 |
|
2923 |
|
2924 |
|
2925 |
|
2926 |
|
2927 |
|
2928 |
|
2929 |
|
2930 | |
2931 |
|
2932 |
|
2933 |
|
2934 |
|
2935 |
|
2936 |
|
2937 |
|
2938 |
|
2939 |
|
2940 |
|
2941 |
|
2942 |
|
2943 |
|
2944 |
|
2945 |
|
2946 |
|
2947 |
|
2948 |
|
2949 |
|
2950 |
|
2951 |
|
2952 |
|
2953 |
|
2954 |
|
2955 | var PanInput =
|
2956 |
|
2957 | function () {
|
2958 | |
2959 |
|
2960 |
|
2961 | function PanInput(el, options) {
|
2962 | var _this = this;
|
2963 |
|
2964 | this.axes = [];
|
2965 | this.element = null;
|
2966 | this._enabled = false;
|
2967 | this._activeEvent = null;
|
2968 | this._atRightEdge = false;
|
2969 | this._rightEdgeTimer = 0;
|
2970 | this._dragged = false;
|
2971 | this._isOverThreshold = false;
|
2972 |
|
2973 | this._preventClickWhenDragged = function (e) {
|
2974 | if (_this._dragged) {
|
2975 | e.preventDefault();
|
2976 | e.stopPropagation();
|
2977 | }
|
2978 |
|
2979 | _this._dragged = false;
|
2980 | };
|
2981 |
|
2982 | this._voidFunction = function () {};
|
2983 |
|
2984 | this.element = $(el);
|
2985 | this.options = __assign({
|
2986 | inputType: ["touch", "mouse", "pointer"],
|
2987 | inputKey: [ANY],
|
2988 | inputButton: [MOUSE_LEFT],
|
2989 | scale: [1, 1],
|
2990 | thresholdAngle: 45,
|
2991 | threshold: 0,
|
2992 | preventClickOnDrag: false,
|
2993 | iOSEdgeSwipeThreshold: IOS_EDGE_THRESHOLD,
|
2994 | releaseOnScroll: false,
|
2995 | touchAction: null
|
2996 | }, options);
|
2997 | this._onPanstart = this._onPanstart.bind(this);
|
2998 | this._onPanmove = this._onPanmove.bind(this);
|
2999 | this._onPanend = this._onPanend.bind(this);
|
3000 | }
|
3001 |
|
3002 | var __proto = PanInput.prototype;
|
3003 |
|
3004 | __proto.mapAxes = function (axes) {
|
3005 | this._direction = getDirection(!!axes[0], !!axes[1]);
|
3006 | this.axes = axes;
|
3007 | };
|
3008 |
|
3009 | __proto.connect = function (observer) {
|
3010 | if (this._activeEvent) {
|
3011 | this._detachElementEvent();
|
3012 |
|
3013 | this._detachWindowEvent(this._activeEvent);
|
3014 | }
|
3015 |
|
3016 | this._attachElementEvent(observer);
|
3017 |
|
3018 | this._originalCssProps = setCssProps(this.element, this.options, this._direction);
|
3019 | return this;
|
3020 | };
|
3021 |
|
3022 | __proto.disconnect = function () {
|
3023 | this._detachElementEvent();
|
3024 |
|
3025 | this._detachWindowEvent(this._activeEvent);
|
3026 |
|
3027 | if (!isCssPropsFromAxes(this._originalCssProps)) {
|
3028 | revertCssProps(this.element, this._originalCssProps);
|
3029 | }
|
3030 |
|
3031 | this._direction = DIRECTION_NONE;
|
3032 | return this;
|
3033 | };
|
3034 | |
3035 |
|
3036 |
|
3037 |
|
3038 |
|
3039 |
|
3040 | __proto.destroy = function () {
|
3041 | this.disconnect();
|
3042 | this.element = null;
|
3043 | };
|
3044 | |
3045 |
|
3046 |
|
3047 |
|
3048 |
|
3049 |
|
3050 |
|
3051 | __proto.enable = function () {
|
3052 | this._enabled = true;
|
3053 | return this;
|
3054 | };
|
3055 | |
3056 |
|
3057 |
|
3058 |
|
3059 |
|
3060 |
|
3061 |
|
3062 | __proto.disable = function () {
|
3063 | this._enabled = false;
|
3064 | return this;
|
3065 | };
|
3066 | |
3067 |
|
3068 |
|
3069 |
|
3070 |
|
3071 |
|
3072 |
|
3073 | __proto.isEnabled = function () {
|
3074 | return this._enabled;
|
3075 | };
|
3076 | |
3077 |
|
3078 |
|
3079 |
|
3080 |
|
3081 |
|
3082 |
|
3083 | __proto.release = function () {
|
3084 | var activeEvent = this._activeEvent;
|
3085 | var prevEvent = activeEvent.prevEvent;
|
3086 | activeEvent.onRelease();
|
3087 |
|
3088 | this._observer.release(this, prevEvent, [0, 0]);
|
3089 |
|
3090 | this._detachWindowEvent(activeEvent);
|
3091 |
|
3092 | return this;
|
3093 | };
|
3094 |
|
3095 | __proto._onPanstart = function (event) {
|
3096 | var _a = this.options,
|
3097 | inputKey = _a.inputKey,
|
3098 | inputButton = _a.inputButton;
|
3099 | var activeEvent = this._activeEvent;
|
3100 | var panEvent = activeEvent.onEventStart(event, inputKey, inputButton);
|
3101 |
|
3102 | if (!panEvent || !this._enabled || activeEvent.getTouches(event, inputButton) > 1) {
|
3103 | return;
|
3104 | }
|
3105 |
|
3106 | if (panEvent.srcEvent.cancelable !== false) {
|
3107 | var edgeThreshold = this.options.iOSEdgeSwipeThreshold;
|
3108 | this._dragged = false;
|
3109 | this._isOverThreshold = false;
|
3110 |
|
3111 | this._observer.hold(this, panEvent);
|
3112 |
|
3113 | this._atRightEdge = IS_IOS_SAFARI && panEvent.center.x > window.innerWidth - edgeThreshold;
|
3114 |
|
3115 | this._attachWindowEvent(activeEvent);
|
3116 |
|
3117 | activeEvent.prevEvent = panEvent;
|
3118 | }
|
3119 | };
|
3120 |
|
3121 | __proto._onPanmove = function (event) {
|
3122 | var _this = this;
|
3123 |
|
3124 | var _a = this.options,
|
3125 | iOSEdgeSwipeThreshold = _a.iOSEdgeSwipeThreshold,
|
3126 | preventClickOnDrag = _a.preventClickOnDrag,
|
3127 | releaseOnScroll = _a.releaseOnScroll,
|
3128 | inputKey = _a.inputKey,
|
3129 | inputButton = _a.inputButton,
|
3130 | threshold = _a.threshold,
|
3131 | thresholdAngle = _a.thresholdAngle;
|
3132 | var activeEvent = this._activeEvent;
|
3133 | var panEvent = activeEvent.onEventMove(event, inputKey, inputButton);
|
3134 | var touches = activeEvent.getTouches(event, inputButton);
|
3135 |
|
3136 | if (touches === 0 || releaseOnScroll && panEvent && !panEvent.srcEvent.cancelable) {
|
3137 | this._onPanend(event);
|
3138 |
|
3139 | return;
|
3140 | }
|
3141 |
|
3142 | if (!panEvent || !this._enabled || touches > 1) {
|
3143 | return;
|
3144 | }
|
3145 |
|
3146 | var userDirection = getDirectionByAngle(panEvent.angle, thresholdAngle);
|
3147 | var useHorizontal = useDirection(DIRECTION_HORIZONTAL, this._direction, userDirection);
|
3148 | var useVertical = useDirection(DIRECTION_VERTICAL, this._direction, userDirection);
|
3149 |
|
3150 | if (activeEvent.prevEvent && IS_IOS_SAFARI) {
|
3151 | var swipeLeftToRight = panEvent.center.x < 0;
|
3152 |
|
3153 | if (swipeLeftToRight) {
|
3154 |
|
3155 | this.release();
|
3156 | return;
|
3157 | } else if (this._atRightEdge) {
|
3158 | clearTimeout(this._rightEdgeTimer);
|
3159 |
|
3160 | var swipeRightToLeft = panEvent.deltaX < -iOSEdgeSwipeThreshold;
|
3161 |
|
3162 | if (swipeRightToLeft) {
|
3163 | this._atRightEdge = false;
|
3164 | } else {
|
3165 |
|
3166 | this._rightEdgeTimer = window.setTimeout(function () {
|
3167 | return _this.release();
|
3168 | }, 100);
|
3169 | }
|
3170 | }
|
3171 | }
|
3172 |
|
3173 | var distance = this._getDistance([panEvent.deltaX, panEvent.deltaY], [useHorizontal, useVertical]);
|
3174 |
|
3175 | var offset = this._getOffset([panEvent.offsetX, panEvent.offsetY], [useHorizontal, useVertical]);
|
3176 |
|
3177 | var prevent = offset.some(function (v) {
|
3178 | return v !== 0;
|
3179 | });
|
3180 |
|
3181 | if (prevent) {
|
3182 | if (panEvent.srcEvent.cancelable !== false) {
|
3183 | panEvent.srcEvent.preventDefault();
|
3184 | }
|
3185 |
|
3186 | panEvent.srcEvent.stopPropagation();
|
3187 | }
|
3188 |
|
3189 | panEvent.preventSystemEvent = prevent;
|
3190 |
|
3191 | if (prevent && (this._isOverThreshold || distance >= threshold)) {
|
3192 | this._dragged = preventClickOnDrag;
|
3193 | this._isOverThreshold = true;
|
3194 |
|
3195 | this._observer.change(this, panEvent, toAxis(this.axes, offset));
|
3196 | }
|
3197 |
|
3198 | activeEvent.prevEvent = panEvent;
|
3199 | };
|
3200 |
|
3201 | __proto._onPanend = function (event) {
|
3202 | var inputButton = this.options.inputButton;
|
3203 | var activeEvent = this._activeEvent;
|
3204 | activeEvent.onEventEnd(event);
|
3205 |
|
3206 | if (!this._enabled || activeEvent.getTouches(event, inputButton) !== 0) {
|
3207 | return;
|
3208 | }
|
3209 |
|
3210 | this._detachWindowEvent(activeEvent);
|
3211 |
|
3212 | clearTimeout(this._rightEdgeTimer);
|
3213 | var prevEvent = activeEvent.prevEvent;
|
3214 | var velocity = this._isOverThreshold ? this._getOffset([Math.abs(prevEvent.velocityX) * (prevEvent.offsetX < 0 ? -1 : 1), Math.abs(prevEvent.velocityY) * (prevEvent.offsetY < 0 ? -1 : 1)], [useDirection(DIRECTION_HORIZONTAL, this._direction), useDirection(DIRECTION_VERTICAL, this._direction)]) : [0, 0];
|
3215 | activeEvent.onRelease();
|
3216 |
|
3217 | this._observer.release(this, prevEvent, velocity);
|
3218 | };
|
3219 |
|
3220 | __proto._attachWindowEvent = function (activeEvent) {
|
3221 | var _this = this;
|
3222 |
|
3223 | activeEvent === null || activeEvent === void 0 ? void 0 : activeEvent.move.forEach(function (event) {
|
3224 | window.addEventListener(event, _this._onPanmove, getAddEventOptions(event));
|
3225 | });
|
3226 | activeEvent === null || activeEvent === void 0 ? void 0 : activeEvent.end.forEach(function (event) {
|
3227 | window.addEventListener(event, _this._onPanend, getAddEventOptions(event));
|
3228 | });
|
3229 | };
|
3230 |
|
3231 | __proto._detachWindowEvent = function (activeEvent) {
|
3232 | var _this = this;
|
3233 |
|
3234 | activeEvent === null || activeEvent === void 0 ? void 0 : activeEvent.move.forEach(function (event) {
|
3235 | window.removeEventListener(event, _this._onPanmove);
|
3236 | });
|
3237 | activeEvent === null || activeEvent === void 0 ? void 0 : activeEvent.end.forEach(function (event) {
|
3238 | window.removeEventListener(event, _this._onPanend);
|
3239 | });
|
3240 | };
|
3241 |
|
3242 | __proto._getOffset = function (properties, direction) {
|
3243 | var scale = this.options.scale;
|
3244 | return [direction[0] ? properties[0] * scale[0] : 0, direction[1] ? properties[1] * scale[1] : 0];
|
3245 | };
|
3246 |
|
3247 | __proto._getDistance = function (delta, direction) {
|
3248 | return Math.sqrt(Number(direction[0]) * Math.pow(delta[0], 2) + Number(direction[1]) * Math.pow(delta[1], 2));
|
3249 | };
|
3250 |
|
3251 | __proto._attachElementEvent = function (observer) {
|
3252 | var _this = this;
|
3253 |
|
3254 | var activeEvent = convertInputType(this.options.inputType);
|
3255 | var element = this.element;
|
3256 |
|
3257 | if (!activeEvent) {
|
3258 | return;
|
3259 | }
|
3260 |
|
3261 | if (!element) {
|
3262 | throw new Error("Element to connect input does not exist.");
|
3263 | }
|
3264 |
|
3265 | this._observer = observer;
|
3266 | this._enabled = true;
|
3267 | this._activeEvent = activeEvent;
|
3268 | element.addEventListener("click", this._preventClickWhenDragged, true);
|
3269 | activeEvent.start.forEach(function (event) {
|
3270 | element.addEventListener(event, _this._onPanstart);
|
3271 | });
|
3272 |
|
3273 | activeEvent.move.forEach(function (event) {
|
3274 | element.addEventListener(event, _this._voidFunction);
|
3275 | });
|
3276 | };
|
3277 |
|
3278 | __proto._detachElementEvent = function () {
|
3279 | var _this = this;
|
3280 |
|
3281 | var activeEvent = this._activeEvent;
|
3282 | var element = this.element;
|
3283 |
|
3284 | if (element) {
|
3285 | element.removeEventListener("click", this._preventClickWhenDragged, true);
|
3286 | activeEvent === null || activeEvent === void 0 ? void 0 : activeEvent.start.forEach(function (event) {
|
3287 | element.removeEventListener(event, _this._onPanstart);
|
3288 | });
|
3289 | activeEvent === null || activeEvent === void 0 ? void 0 : activeEvent.move.forEach(function (event) {
|
3290 | element.removeEventListener(event, _this._voidFunction);
|
3291 | });
|
3292 | }
|
3293 |
|
3294 | this._enabled = false;
|
3295 | this._observer = null;
|
3296 | };
|
3297 |
|
3298 | return PanInput;
|
3299 | }();
|
3300 |
|
3301 | |
3302 |
|
3303 |
|
3304 |
|
3305 |
|
3306 |
|
3307 |
|
3308 |
|
3309 |
|
3310 |
|
3311 |
|
3312 |
|
3313 |
|
3314 |
|
3315 |
|
3316 |
|
3317 |
|
3318 |
|
3319 |
|
3320 |
|
3321 |
|
3322 |
|
3323 |
|
3324 |
|
3325 | var RotatePanInput =
|
3326 |
|
3327 | function (_super) {
|
3328 | __extends(RotatePanInput, _super);
|
3329 | |
3330 |
|
3331 |
|
3332 |
|
3333 |
|
3334 | function RotatePanInput(el, options) {
|
3335 | var _this = _super.call(this, el, options) || this;
|
3336 |
|
3337 | _this._prevQuadrant = null;
|
3338 | _this._lastDiff = 0;
|
3339 | return _this;
|
3340 | }
|
3341 |
|
3342 | var __proto = RotatePanInput.prototype;
|
3343 |
|
3344 | __proto.mapAxes = function (axes) {
|
3345 | this._direction = Axes.DIRECTION_ALL;
|
3346 | this.axes = axes;
|
3347 | };
|
3348 |
|
3349 | __proto._onPanstart = function (event) {
|
3350 | var _a = this.options,
|
3351 | inputKey = _a.inputKey,
|
3352 | inputButton = _a.inputButton;
|
3353 | var activeEvent = this._activeEvent;
|
3354 | var panEvent = activeEvent.onEventStart(event, inputKey, inputButton);
|
3355 |
|
3356 | if (!panEvent || !this.isEnabled()) {
|
3357 | return;
|
3358 | }
|
3359 |
|
3360 | var rect = this.element.getBoundingClientRect();
|
3361 |
|
3362 | this._observer.hold(this, panEvent);
|
3363 |
|
3364 | this._attachWindowEvent(activeEvent);
|
3365 |
|
3366 |
|
3367 | this._coefficientForDistanceToAngle = 360 / (rect.width * Math.PI);
|
3368 |
|
3369 |
|
3370 | this._rotateOrigin = [rect.left + (rect.width - 1) / 2, rect.top + (rect.height - 1) / 2];
|
3371 |
|
3372 | this._prevAngle = null;
|
3373 |
|
3374 | this._triggerChange(panEvent);
|
3375 |
|
3376 | activeEvent.prevEvent = panEvent;
|
3377 | };
|
3378 |
|
3379 | __proto._onPanmove = function (event) {
|
3380 | var _a = this.options,
|
3381 | inputKey = _a.inputKey,
|
3382 | inputButton = _a.inputButton;
|
3383 | var activeEvent = this._activeEvent;
|
3384 | var panEvent = activeEvent.onEventMove(event, inputKey, inputButton);
|
3385 |
|
3386 | if (!panEvent || !this.isEnabled()) {
|
3387 | return;
|
3388 | }
|
3389 |
|
3390 | if (panEvent.srcEvent.cancelable !== false) {
|
3391 | panEvent.srcEvent.preventDefault();
|
3392 | }
|
3393 |
|
3394 | panEvent.srcEvent.stopPropagation();
|
3395 |
|
3396 | this._triggerChange(panEvent);
|
3397 |
|
3398 | activeEvent.prevEvent = panEvent;
|
3399 | };
|
3400 |
|
3401 | __proto._onPanend = function (event) {
|
3402 | var activeEvent = this._activeEvent;
|
3403 | activeEvent.onEventEnd(event);
|
3404 |
|
3405 | if (!this.isEnabled()) {
|
3406 | return;
|
3407 | }
|
3408 |
|
3409 | var prevEvent = activeEvent.prevEvent;
|
3410 |
|
3411 | this._triggerChange(prevEvent);
|
3412 |
|
3413 | var vx = prevEvent.velocityX;
|
3414 | var vy = prevEvent.velocityY;
|
3415 | var velocity = Math.sqrt(vx * vx + vy * vy) * (this._lastDiff > 0 ? -1 : 1);
|
3416 |
|
3417 | activeEvent.onRelease();
|
3418 |
|
3419 | this._observer.release(this, prevEvent, [velocity * this._coefficientForDistanceToAngle]);
|
3420 |
|
3421 | this._detachWindowEvent(activeEvent);
|
3422 | };
|
3423 |
|
3424 | __proto._triggerChange = function (event) {
|
3425 | var _a = this._getPosFromOrigin(event.center.x, event.center.y),
|
3426 | x = _a.x,
|
3427 | y = _a.y;
|
3428 |
|
3429 | var angle = getAngle(x, y);
|
3430 | var positiveAngle = angle < 0 ? 360 + angle : angle;
|
3431 |
|
3432 | var quadrant = this._getQuadrant(event.center.x, event.center.y);
|
3433 |
|
3434 | var diff = this._getDifference(this._prevAngle, positiveAngle, this._prevQuadrant, quadrant);
|
3435 |
|
3436 | this._prevAngle = positiveAngle;
|
3437 | this._prevQuadrant = quadrant;
|
3438 |
|
3439 | if (diff === 0) {
|
3440 | return;
|
3441 | }
|
3442 |
|
3443 | this._lastDiff = diff;
|
3444 |
|
3445 | this._observer.change(this, event, toAxis(this.axes, [-diff]));
|
3446 |
|
3447 | };
|
3448 |
|
3449 | __proto._getDifference = function (prevAngle, angle, prevQuadrant, quadrant) {
|
3450 | var diff;
|
3451 |
|
3452 | if (prevAngle === null) {
|
3453 | diff = 0;
|
3454 | } else if (prevQuadrant === 1 && quadrant === 4) {
|
3455 | diff = -prevAngle - (360 - angle);
|
3456 | } else if (prevQuadrant === 4 && quadrant === 1) {
|
3457 | diff = 360 - prevAngle + angle;
|
3458 | } else {
|
3459 | diff = angle - prevAngle;
|
3460 | }
|
3461 |
|
3462 | return diff;
|
3463 | };
|
3464 |
|
3465 | __proto._getPosFromOrigin = function (posX, posY) {
|
3466 | return {
|
3467 | x: posX - this._rotateOrigin[0],
|
3468 | y: this._rotateOrigin[1] - posY
|
3469 | };
|
3470 | };
|
3471 |
|
3472 | __proto._getQuadrant = function (posX, posY) {
|
3473 | |
3474 |
|
3475 |
|
3476 |
|
3477 |
|
3478 |
|
3479 |
|
3480 |
|
3481 |
|
3482 | var _a = this._getPosFromOrigin(posX, posY),
|
3483 | x = _a.x,
|
3484 | y = _a.y;
|
3485 |
|
3486 | var q = 0;
|
3487 |
|
3488 | if (x >= 0 && y >= 0) {
|
3489 | q = 1;
|
3490 | } else if (x < 0 && y >= 0) {
|
3491 | q = 2;
|
3492 | } else if (x < 0 && y < 0) {
|
3493 | q = 3;
|
3494 | } else if (x >= 0 && y < 0) {
|
3495 | q = 4;
|
3496 | }
|
3497 |
|
3498 | return q;
|
3499 | };
|
3500 |
|
3501 | return RotatePanInput;
|
3502 | }(PanInput);
|
3503 |
|
3504 | |
3505 |
|
3506 |
|
3507 |
|
3508 |
|
3509 |
|
3510 |
|
3511 |
|
3512 |
|
3513 |
|
3514 |
|
3515 |
|
3516 |
|
3517 | |
3518 |
|
3519 |
|
3520 |
|
3521 |
|
3522 |
|
3523 |
|
3524 |
|
3525 |
|
3526 |
|
3527 |
|
3528 |
|
3529 |
|
3530 |
|
3531 |
|
3532 |
|
3533 | var PinchInput =
|
3534 |
|
3535 | function () {
|
3536 | |
3537 |
|
3538 |
|
3539 | function PinchInput(el, options) {
|
3540 | this.axes = [];
|
3541 | this.element = null;
|
3542 | this._pinchFlag = false;
|
3543 | this._enabled = false;
|
3544 | this._activeEvent = null;
|
3545 | this._isOverThreshold = false;
|
3546 | this.element = $(el);
|
3547 | this.options = __assign({
|
3548 | scale: 1,
|
3549 | threshold: 0,
|
3550 | inputType: ["touch", "pointer"],
|
3551 | touchAction: "none"
|
3552 | }, options);
|
3553 | this._onPinchStart = this._onPinchStart.bind(this);
|
3554 | this._onPinchMove = this._onPinchMove.bind(this);
|
3555 | this._onPinchEnd = this._onPinchEnd.bind(this);
|
3556 | }
|
3557 |
|
3558 | var __proto = PinchInput.prototype;
|
3559 |
|
3560 | __proto.mapAxes = function (axes) {
|
3561 | this.axes = axes;
|
3562 | };
|
3563 |
|
3564 | __proto.connect = function (observer) {
|
3565 | if (this._activeEvent) {
|
3566 | this._detachEvent();
|
3567 | }
|
3568 |
|
3569 | this._attachEvent(observer);
|
3570 |
|
3571 | this._originalCssProps = setCssProps(this.element, this.options, DIRECTION_ALL);
|
3572 | return this;
|
3573 | };
|
3574 |
|
3575 | __proto.disconnect = function () {
|
3576 | this._detachEvent();
|
3577 |
|
3578 | if (!isCssPropsFromAxes(this._originalCssProps)) {
|
3579 | revertCssProps(this.element, this._originalCssProps);
|
3580 | }
|
3581 |
|
3582 | return this;
|
3583 | };
|
3584 | |
3585 |
|
3586 |
|
3587 |
|
3588 |
|
3589 |
|
3590 | __proto.destroy = function () {
|
3591 | this.disconnect();
|
3592 | this.element = null;
|
3593 | };
|
3594 | |
3595 |
|
3596 |
|
3597 |
|
3598 |
|
3599 |
|
3600 |
|
3601 | __proto.enable = function () {
|
3602 | this._enabled = true;
|
3603 | return this;
|
3604 | };
|
3605 | |
3606 |
|
3607 |
|
3608 |
|
3609 |
|
3610 |
|
3611 |
|
3612 | __proto.disable = function () {
|
3613 | this._enabled = false;
|
3614 | return this;
|
3615 | };
|
3616 | |
3617 |
|
3618 |
|
3619 |
|
3620 |
|
3621 |
|
3622 |
|
3623 | __proto.isEnabled = function () {
|
3624 | return this._enabled;
|
3625 | };
|
3626 |
|
3627 | __proto._onPinchStart = function (event) {
|
3628 | var activeEvent = this._activeEvent;
|
3629 | var pinchEvent = activeEvent.onEventStart(event);
|
3630 |
|
3631 | if (!pinchEvent || !this._enabled || activeEvent.getTouches(event) !== 2) {
|
3632 | return;
|
3633 | }
|
3634 |
|
3635 | this._baseValue = this._observer.get(this)[this.axes[0]];
|
3636 |
|
3637 | this._observer.hold(this, event);
|
3638 |
|
3639 | this._pinchFlag = true;
|
3640 | this._isOverThreshold = false;
|
3641 | activeEvent.prevEvent = pinchEvent;
|
3642 | };
|
3643 |
|
3644 | __proto._onPinchMove = function (event) {
|
3645 | var threshold = this.options.threshold;
|
3646 | var activeEvent = this._activeEvent;
|
3647 | var pinchEvent = activeEvent.onEventMove(event);
|
3648 |
|
3649 | if (!pinchEvent || !this._pinchFlag || !this._enabled || activeEvent.getTouches(event) !== 2) {
|
3650 | return;
|
3651 | }
|
3652 |
|
3653 | var distance = this._getDistance(pinchEvent.scale);
|
3654 |
|
3655 | var offset = this._getOffset(pinchEvent.scale, activeEvent.prevEvent.scale);
|
3656 |
|
3657 | if (this._isOverThreshold || distance >= threshold) {
|
3658 | this._isOverThreshold = true;
|
3659 |
|
3660 | this._observer.change(this, event, toAxis(this.axes, [offset]));
|
3661 | }
|
3662 |
|
3663 | activeEvent.prevEvent = pinchEvent;
|
3664 | };
|
3665 |
|
3666 | __proto._onPinchEnd = function (event) {
|
3667 | var activeEvent = this._activeEvent;
|
3668 | activeEvent.onEventEnd(event);
|
3669 |
|
3670 | if (!this._pinchFlag || !this._enabled || activeEvent.getTouches(event) >= 2) {
|
3671 | return;
|
3672 | }
|
3673 |
|
3674 | activeEvent.onRelease();
|
3675 |
|
3676 | this._observer.release(this, event, [0], 0);
|
3677 |
|
3678 | this._baseValue = null;
|
3679 | this._pinchFlag = false;
|
3680 | };
|
3681 |
|
3682 | __proto._attachEvent = function (observer) {
|
3683 | var _this = this;
|
3684 |
|
3685 | var activeEvent = convertInputType(this.options.inputType);
|
3686 | var element = this.element;
|
3687 |
|
3688 | if (!activeEvent) {
|
3689 | return;
|
3690 | }
|
3691 |
|
3692 | if (!element) {
|
3693 | throw new Error("Element to connect input does not exist.");
|
3694 | }
|
3695 |
|
3696 | this._observer = observer;
|
3697 | this._enabled = true;
|
3698 | this._activeEvent = activeEvent;
|
3699 | activeEvent.start.forEach(function (event) {
|
3700 | element.addEventListener(event, _this._onPinchStart, false);
|
3701 | });
|
3702 | activeEvent.move.forEach(function (event) {
|
3703 | element.addEventListener(event, _this._onPinchMove, false);
|
3704 | });
|
3705 | activeEvent.end.forEach(function (event) {
|
3706 | element.addEventListener(event, _this._onPinchEnd, false);
|
3707 | });
|
3708 | };
|
3709 |
|
3710 | __proto._detachEvent = function () {
|
3711 | var _this = this;
|
3712 |
|
3713 | var activeEvent = this._activeEvent;
|
3714 | var element = this.element;
|
3715 |
|
3716 | if (element) {
|
3717 | activeEvent === null || activeEvent === void 0 ? void 0 : activeEvent.start.forEach(function (event) {
|
3718 | element.removeEventListener(event, _this._onPinchStart, false);
|
3719 | });
|
3720 | activeEvent === null || activeEvent === void 0 ? void 0 : activeEvent.move.forEach(function (event) {
|
3721 | element.removeEventListener(event, _this._onPinchMove, false);
|
3722 | });
|
3723 | activeEvent === null || activeEvent === void 0 ? void 0 : activeEvent.end.forEach(function (event) {
|
3724 | element.removeEventListener(event, _this._onPinchEnd, false);
|
3725 | });
|
3726 | }
|
3727 |
|
3728 | this._enabled = false;
|
3729 | this._observer = null;
|
3730 | };
|
3731 |
|
3732 | __proto._getOffset = function (pinchScale, prev) {
|
3733 | if (prev === void 0) {
|
3734 | prev = 1;
|
3735 | }
|
3736 |
|
3737 | return this._baseValue * (pinchScale - prev) * this.options.scale;
|
3738 | };
|
3739 |
|
3740 | __proto._getDistance = function (pinchScale) {
|
3741 | return Math.abs(pinchScale - 1);
|
3742 | };
|
3743 |
|
3744 | return PinchInput;
|
3745 | }();
|
3746 |
|
3747 | |
3748 |
|
3749 |
|
3750 |
|
3751 |
|
3752 |
|
3753 |
|
3754 |
|
3755 |
|
3756 |
|
3757 |
|
3758 |
|
3759 |
|
3760 |
|
3761 |
|
3762 |
|
3763 |
|
3764 |
|
3765 |
|
3766 |
|
3767 |
|
3768 |
|
3769 | |
3770 |
|
3771 |
|
3772 |
|
3773 |
|
3774 |
|
3775 |
|
3776 |
|
3777 |
|
3778 |
|
3779 |
|
3780 |
|
3781 |
|
3782 |
|
3783 |
|
3784 |
|
3785 |
|
3786 |
|
3787 |
|
3788 |
|
3789 |
|
3790 |
|
3791 |
|
3792 |
|
3793 | var WheelInput =
|
3794 |
|
3795 | function () {
|
3796 | |
3797 |
|
3798 |
|
3799 | function WheelInput(el, options) {
|
3800 | this.axes = [];
|
3801 | this.element = null;
|
3802 | this._enabled = false;
|
3803 | this._holding = false;
|
3804 | this._timer = null;
|
3805 | this.element = $(el);
|
3806 | this.options = __assign({
|
3807 | inputKey: [ANY],
|
3808 | scale: 1,
|
3809 | releaseDelay: 300,
|
3810 | useNormalized: true,
|
3811 | useAnimation: false
|
3812 | }, options);
|
3813 | this._onWheel = this._onWheel.bind(this);
|
3814 | }
|
3815 |
|
3816 | var __proto = WheelInput.prototype;
|
3817 |
|
3818 | __proto.mapAxes = function (axes) {
|
3819 |
|
3820 | this._direction = getDirection(!!axes[1], !!axes[0]);
|
3821 | this.axes = axes;
|
3822 | };
|
3823 |
|
3824 | __proto.connect = function (observer) {
|
3825 | this._detachEvent();
|
3826 |
|
3827 | this._attachEvent(observer);
|
3828 |
|
3829 | return this;
|
3830 | };
|
3831 |
|
3832 | __proto.disconnect = function () {
|
3833 | this._detachEvent();
|
3834 |
|
3835 | return this;
|
3836 | };
|
3837 | |
3838 |
|
3839 |
|
3840 |
|
3841 |
|
3842 |
|
3843 | __proto.destroy = function () {
|
3844 | this.disconnect();
|
3845 | this.element = null;
|
3846 | };
|
3847 | |
3848 |
|
3849 |
|
3850 |
|
3851 |
|
3852 |
|
3853 |
|
3854 | __proto.enable = function () {
|
3855 | this._enabled = true;
|
3856 | return this;
|
3857 | };
|
3858 | |
3859 |
|
3860 |
|
3861 |
|
3862 |
|
3863 |
|
3864 |
|
3865 | __proto.disable = function () {
|
3866 | this._enabled = false;
|
3867 | return this;
|
3868 | };
|
3869 | |
3870 |
|
3871 |
|
3872 |
|
3873 |
|
3874 |
|
3875 |
|
3876 | __proto.isEnabled = function () {
|
3877 | return this._enabled;
|
3878 | };
|
3879 |
|
3880 | __proto._onWheel = function (event) {
|
3881 | var _this = this;
|
3882 |
|
3883 | if (!this._enabled || !isValidKey(event, this.options.inputKey)) {
|
3884 | return;
|
3885 | }
|
3886 |
|
3887 | var offset = this._getOffset([event.deltaY, event.deltaX], [useDirection(DIRECTION_VERTICAL, this._direction), useDirection(DIRECTION_HORIZONTAL, this._direction)]);
|
3888 |
|
3889 | if (offset[0] === 0 && offset[1] === 0) {
|
3890 | return;
|
3891 | }
|
3892 |
|
3893 | event.preventDefault();
|
3894 |
|
3895 | if (!this._holding) {
|
3896 | this._observer.hold(this, event);
|
3897 |
|
3898 | this._holding = true;
|
3899 | }
|
3900 |
|
3901 | this._observer.change(this, event, toAxis(this.axes, offset), this.options.useAnimation);
|
3902 |
|
3903 | clearTimeout(this._timer);
|
3904 | this._timer = setTimeout(function () {
|
3905 | if (_this._holding) {
|
3906 | _this._holding = false;
|
3907 |
|
3908 | _this._observer.release(_this, event, [0]);
|
3909 | }
|
3910 | }, this.options.releaseDelay);
|
3911 | };
|
3912 |
|
3913 | __proto._getOffset = function (properties, direction) {
|
3914 | var scale = this.options.scale;
|
3915 | var useNormalized = this.options.useNormalized;
|
3916 | return [direction[0] && properties[0] ? (properties[0] > 0 ? -1 : 1) * (useNormalized ? 1 : Math.abs(properties[0])) * scale : 0, direction[1] && properties[1] ? (properties[1] > 0 ? -1 : 1) * (useNormalized ? 1 : Math.abs(properties[1])) * scale : 0];
|
3917 | };
|
3918 |
|
3919 | __proto._attachEvent = function (observer) {
|
3920 | var element = this.element;
|
3921 |
|
3922 | if (!element) {
|
3923 | throw new Error("Element to connect input does not exist.");
|
3924 | }
|
3925 |
|
3926 | this._observer = observer;
|
3927 | element.addEventListener("wheel", this._onWheel);
|
3928 | this._enabled = true;
|
3929 | };
|
3930 |
|
3931 | __proto._detachEvent = function () {
|
3932 | var element = this.element;
|
3933 |
|
3934 | if (element) {
|
3935 | this.element.removeEventListener("wheel", this._onWheel);
|
3936 | }
|
3937 |
|
3938 | this._enabled = false;
|
3939 | this._observer = null;
|
3940 |
|
3941 | if (this._timer) {
|
3942 | clearTimeout(this._timer);
|
3943 | this._timer = null;
|
3944 | }
|
3945 | };
|
3946 |
|
3947 | return WheelInput;
|
3948 | }();
|
3949 |
|
3950 | var KEY_LEFT_ARROW = 37;
|
3951 | var KEY_A = 65;
|
3952 | var KEY_UP_ARROW = 38;
|
3953 | var KEY_W = 87;
|
3954 | var KEY_RIGHT_ARROW = 39;
|
3955 | var KEY_D = 68;
|
3956 | var KEY_DOWN_ARROW = 40;
|
3957 | var KEY_S = 83;
|
3958 |
|
3959 |
|
3960 | var DIRECTION_REVERSE = -1;
|
3961 | var DIRECTION_FORWARD = 1;
|
3962 | var DIRECTION_HORIZONTAL$1 = -1;
|
3963 | var DIRECTION_VERTICAL$1 = 1;
|
3964 | var DELAY = 80;
|
3965 | |
3966 |
|
3967 |
|
3968 |
|
3969 |
|
3970 |
|
3971 |
|
3972 |
|
3973 | |
3974 |
|
3975 |
|
3976 |
|
3977 |
|
3978 |
|
3979 |
|
3980 |
|
3981 |
|
3982 |
|
3983 |
|
3984 |
|
3985 |
|
3986 |
|
3987 |
|
3988 |
|
3989 |
|
3990 | var MoveKeyInput =
|
3991 |
|
3992 | function () {
|
3993 | |
3994 |
|
3995 |
|
3996 | function MoveKeyInput(el, options) {
|
3997 | this.axes = [];
|
3998 | this.element = null;
|
3999 | this._enabled = false;
|
4000 | this._holding = false;
|
4001 | this._timer = null;
|
4002 | this.element = $(el);
|
4003 | this.options = __assign({
|
4004 | scale: [1, 1]
|
4005 | }, options);
|
4006 | this._onKeydown = this._onKeydown.bind(this);
|
4007 | this._onKeyup = this._onKeyup.bind(this);
|
4008 | }
|
4009 |
|
4010 | var __proto = MoveKeyInput.prototype;
|
4011 |
|
4012 | __proto.mapAxes = function (axes) {
|
4013 | this.axes = axes;
|
4014 | };
|
4015 |
|
4016 | __proto.connect = function (observer) {
|
4017 | this._detachEvent();
|
4018 |
|
4019 |
|
4020 | if (this.element.getAttribute("tabindex") !== "0") {
|
4021 | this.element.setAttribute("tabindex", "0");
|
4022 | }
|
4023 |
|
4024 | this._attachEvent(observer);
|
4025 |
|
4026 | return this;
|
4027 | };
|
4028 |
|
4029 | __proto.disconnect = function () {
|
4030 | this._detachEvent();
|
4031 |
|
4032 | return this;
|
4033 | };
|
4034 | |
4035 |
|
4036 |
|
4037 |
|
4038 |
|
4039 |
|
4040 | __proto.destroy = function () {
|
4041 | this.disconnect();
|
4042 | this.element = null;
|
4043 | };
|
4044 | |
4045 |
|
4046 |
|
4047 |
|
4048 |
|
4049 |
|
4050 |
|
4051 | __proto.enable = function () {
|
4052 | this._enabled = true;
|
4053 | return this;
|
4054 | };
|
4055 | |
4056 |
|
4057 |
|
4058 |
|
4059 |
|
4060 |
|
4061 |
|
4062 | __proto.disable = function () {
|
4063 | this._enabled = false;
|
4064 | return this;
|
4065 | };
|
4066 | |
4067 |
|
4068 |
|
4069 |
|
4070 |
|
4071 |
|
4072 |
|
4073 | __proto.isEnabled = function () {
|
4074 | return this._enabled;
|
4075 | };
|
4076 |
|
4077 | __proto._onKeydown = function (event) {
|
4078 | if (!this._enabled) {
|
4079 | return;
|
4080 | }
|
4081 |
|
4082 | var isMoveKey = true;
|
4083 | var direction = DIRECTION_FORWARD;
|
4084 | var move = DIRECTION_HORIZONTAL$1;
|
4085 |
|
4086 | switch (event.keyCode) {
|
4087 | case KEY_LEFT_ARROW:
|
4088 | case KEY_A:
|
4089 | direction = DIRECTION_REVERSE;
|
4090 | break;
|
4091 |
|
4092 | case KEY_RIGHT_ARROW:
|
4093 | case KEY_D:
|
4094 | break;
|
4095 |
|
4096 | case KEY_DOWN_ARROW:
|
4097 | case KEY_S:
|
4098 | direction = DIRECTION_REVERSE;
|
4099 | move = DIRECTION_VERTICAL$1;
|
4100 | break;
|
4101 |
|
4102 | case KEY_UP_ARROW:
|
4103 | case KEY_W:
|
4104 | move = DIRECTION_VERTICAL$1;
|
4105 | break;
|
4106 |
|
4107 | default:
|
4108 | isMoveKey = false;
|
4109 | }
|
4110 |
|
4111 | if (move === DIRECTION_HORIZONTAL$1 && !this.axes[0] || move === DIRECTION_VERTICAL$1 && !this.axes[1]) {
|
4112 | isMoveKey = false;
|
4113 | }
|
4114 |
|
4115 | if (!isMoveKey) {
|
4116 | return;
|
4117 | }
|
4118 |
|
4119 | event.preventDefault();
|
4120 | var offsets = move === DIRECTION_HORIZONTAL$1 ? [+this.options.scale[0] * direction, 0] : [0, +this.options.scale[1] * direction];
|
4121 |
|
4122 | if (!this._holding) {
|
4123 | this._observer.hold(this, event);
|
4124 |
|
4125 | this._holding = true;
|
4126 | }
|
4127 |
|
4128 | clearTimeout(this._timer);
|
4129 |
|
4130 | this._observer.change(this, event, toAxis(this.axes, offsets));
|
4131 | };
|
4132 |
|
4133 | __proto._onKeyup = function (event) {
|
4134 | var _this = this;
|
4135 |
|
4136 | if (!this._holding) {
|
4137 | return;
|
4138 | }
|
4139 |
|
4140 | clearTimeout(this._timer);
|
4141 | this._timer = setTimeout(function () {
|
4142 | _this._observer.release(_this, event, [0, 0]);
|
4143 |
|
4144 | _this._holding = false;
|
4145 | }, DELAY);
|
4146 | };
|
4147 |
|
4148 | __proto._attachEvent = function (observer) {
|
4149 | var element = this.element;
|
4150 |
|
4151 | if (!element) {
|
4152 | throw new Error("Element to connect input does not exist.");
|
4153 | }
|
4154 |
|
4155 | this._observer = observer;
|
4156 | element.addEventListener("keydown", this._onKeydown, false);
|
4157 | element.addEventListener("keypress", this._onKeydown, false);
|
4158 | element.addEventListener("keyup", this._onKeyup, false);
|
4159 | this._enabled = true;
|
4160 | };
|
4161 |
|
4162 | __proto._detachEvent = function () {
|
4163 | var element = this.element;
|
4164 |
|
4165 | if (element) {
|
4166 | element.removeEventListener("keydown", this._onKeydown, false);
|
4167 | element.removeEventListener("keypress", this._onKeydown, false);
|
4168 | element.removeEventListener("keyup", this._onKeyup, false);
|
4169 | }
|
4170 |
|
4171 | this._enabled = false;
|
4172 | this._observer = null;
|
4173 | };
|
4174 |
|
4175 | return MoveKeyInput;
|
4176 | }();
|
4177 |
|
4178 | |
4179 |
|
4180 |
|
4181 |
|
4182 | var REACTIVE_AXES = {
|
4183 | methods: AXES_METHODS,
|
4184 | events: AXES_EVENTS,
|
4185 | created: function (data) {
|
4186 | return new Axes(data.axis, data.options);
|
4187 | },
|
4188 | on: function (instance, name, callback) {
|
4189 | instance.on(name, callback);
|
4190 | },
|
4191 | off: function (instance, name, callback) {
|
4192 | instance.off(name, callback);
|
4193 | },
|
4194 | destroy: function (instance) {
|
4195 | instance.destroy();
|
4196 | }
|
4197 | };
|
4198 |
|
4199 | |
4200 |
|
4201 |
|
4202 |
|
4203 |
|
4204 | var modules = ({
|
4205 | default: Axes,
|
4206 | PanInput: PanInput,
|
4207 | RotatePanInput: RotatePanInput,
|
4208 | PinchInput: PinchInput,
|
4209 | WheelInput: WheelInput,
|
4210 | MoveKeyInput: MoveKeyInput,
|
4211 | AXES_METHODS: AXES_METHODS,
|
4212 | AXES_EVENTS: AXES_EVENTS,
|
4213 | REACTIVE_AXES: REACTIVE_AXES
|
4214 | });
|
4215 |
|
4216 | |
4217 |
|
4218 |
|
4219 |
|
4220 |
|
4221 | for (var name in modules) {
|
4222 | Axes[name] = modules[name];
|
4223 | }
|
4224 |
|
4225 | return Axes;
|
4226 |
|
4227 | })));
|
4228 |
|