1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | (function (global, factory) {
|
10 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
11 | typeof define === 'function' && define.amd ? define(factory) :
|
12 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Flicking = factory());
|
13 | }(this, (function () { 'use strict';
|
14 |
|
15 | |
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | var extendStatics$2 = function (d, b) {
|
32 | extendStatics$2 = 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
38 | };
|
39 |
|
40 | return extendStatics$2(d, b);
|
41 | };
|
42 |
|
43 | function __extends$2(d, b) {
|
44 | if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
45 | extendStatics$2(d, b);
|
46 |
|
47 | function __() {
|
48 | this.constructor = d;
|
49 | }
|
50 |
|
51 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
52 | }
|
53 | var __assign$2 = function () {
|
54 | __assign$2 = Object.assign || function __assign(t) {
|
55 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
56 | s = arguments[i];
|
57 |
|
58 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
59 | }
|
60 |
|
61 | return t;
|
62 | };
|
63 |
|
64 | return __assign$2.apply(this, arguments);
|
65 | };
|
66 | function __awaiter(thisArg, _arguments, P, generator) {
|
67 | function adopt(value) {
|
68 | return value instanceof P ? value : new P(function (resolve) {
|
69 | resolve(value);
|
70 | });
|
71 | }
|
72 |
|
73 | return new (P || (P = Promise))(function (resolve, reject) {
|
74 | function fulfilled(value) {
|
75 | try {
|
76 | step(generator.next(value));
|
77 | } catch (e) {
|
78 | reject(e);
|
79 | }
|
80 | }
|
81 |
|
82 | function rejected(value) {
|
83 | try {
|
84 | step(generator["throw"](value));
|
85 | } catch (e) {
|
86 | reject(e);
|
87 | }
|
88 | }
|
89 |
|
90 | function step(result) {
|
91 | result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
92 | }
|
93 |
|
94 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
95 | });
|
96 | }
|
97 | function __generator(thisArg, body) {
|
98 | var _ = {
|
99 | label: 0,
|
100 | sent: function () {
|
101 | if (t[0] & 1) throw t[1];
|
102 | return t[1];
|
103 | },
|
104 | trys: [],
|
105 | ops: []
|
106 | },
|
107 | f,
|
108 | y,
|
109 | t,
|
110 | g;
|
111 | return g = {
|
112 | next: verb(0),
|
113 | "throw": verb(1),
|
114 | "return": verb(2)
|
115 | }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
116 | return this;
|
117 | }), g;
|
118 |
|
119 | function verb(n) {
|
120 | return function (v) {
|
121 | return step([n, v]);
|
122 | };
|
123 | }
|
124 |
|
125 | function step(op) {
|
126 | if (f) throw new TypeError("Generator is already executing.");
|
127 |
|
128 | while (_) try {
|
129 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
130 | if (y = 0, t) op = [op[0] & 2, t.value];
|
131 |
|
132 | switch (op[0]) {
|
133 | case 0:
|
134 | case 1:
|
135 | t = op;
|
136 | break;
|
137 |
|
138 | case 4:
|
139 | _.label++;
|
140 | return {
|
141 | value: op[1],
|
142 | done: false
|
143 | };
|
144 |
|
145 | case 5:
|
146 | _.label++;
|
147 | y = op[1];
|
148 | op = [0];
|
149 | continue;
|
150 |
|
151 | case 7:
|
152 | op = _.ops.pop();
|
153 |
|
154 | _.trys.pop();
|
155 |
|
156 | continue;
|
157 |
|
158 | default:
|
159 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
160 | _ = 0;
|
161 | continue;
|
162 | }
|
163 |
|
164 | if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
165 | _.label = op[1];
|
166 | break;
|
167 | }
|
168 |
|
169 | if (op[0] === 6 && _.label < t[1]) {
|
170 | _.label = t[1];
|
171 | t = op;
|
172 | break;
|
173 | }
|
174 |
|
175 | if (t && _.label < t[2]) {
|
176 | _.label = t[2];
|
177 |
|
178 | _.ops.push(op);
|
179 |
|
180 | break;
|
181 | }
|
182 |
|
183 | if (t[2]) _.ops.pop();
|
184 |
|
185 | _.trys.pop();
|
186 |
|
187 | continue;
|
188 | }
|
189 |
|
190 | op = body.call(thisArg, _);
|
191 | } catch (e) {
|
192 | op = [6, e];
|
193 | y = 0;
|
194 | } finally {
|
195 | f = t = 0;
|
196 | }
|
197 |
|
198 | if (op[0] & 5) throw op[1];
|
199 | return {
|
200 | value: op[0] ? op[1] : void 0,
|
201 | done: true
|
202 | };
|
203 | }
|
204 | }
|
205 | function __values$3(o) {
|
206 | var s = typeof Symbol === "function" && Symbol.iterator,
|
207 | m = s && o[s],
|
208 | i = 0;
|
209 | if (m) return m.call(o);
|
210 | if (o && typeof o.length === "number") return {
|
211 | next: function () {
|
212 | if (o && i >= o.length) o = void 0;
|
213 | return {
|
214 | value: o && o[i++],
|
215 | done: !o
|
216 | };
|
217 | }
|
218 | };
|
219 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
220 | }
|
221 | function __read$1(o, n) {
|
222 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
223 | if (!m) return o;
|
224 | var i = m.call(o),
|
225 | r,
|
226 | ar = [],
|
227 | e;
|
228 |
|
229 | try {
|
230 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
231 | } catch (error) {
|
232 | e = {
|
233 | error: error
|
234 | };
|
235 | } finally {
|
236 | try {
|
237 | if (r && !r.done && (m = i["return"])) m.call(i);
|
238 | } finally {
|
239 | if (e) throw e.error;
|
240 | }
|
241 | }
|
242 |
|
243 | return ar;
|
244 | }
|
245 | function __spreadArray(to, from) {
|
246 | for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i];
|
247 |
|
248 | return to;
|
249 | }
|
250 |
|
251 | |
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 | |
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 | function __values$2(o) {
|
274 | var s = typeof Symbol === "function" && Symbol.iterator,
|
275 | m = s && o[s],
|
276 | i = 0;
|
277 | if (m) return m.call(o);
|
278 | if (o && typeof o.length === "number") return {
|
279 | next: function () {
|
280 | if (o && i >= o.length) o = void 0;
|
281 | return {
|
282 | value: o && o[i++],
|
283 | done: !o
|
284 | };
|
285 | }
|
286 | };
|
287 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
288 | }
|
289 | function __read(o, n) {
|
290 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
291 | if (!m) return o;
|
292 | var i = m.call(o),
|
293 | r,
|
294 | ar = [],
|
295 | e;
|
296 |
|
297 | try {
|
298 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
299 | } catch (error) {
|
300 | e = {
|
301 | error: error
|
302 | };
|
303 | } finally {
|
304 | try {
|
305 | if (r && !r.done && (m = i["return"])) m.call(i);
|
306 | } finally {
|
307 | if (e) throw e.error;
|
308 | }
|
309 | }
|
310 |
|
311 | return ar;
|
312 | }
|
313 | function __spread() {
|
314 | for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
315 |
|
316 | return ar;
|
317 | }
|
318 |
|
319 | |
320 |
|
321 |
|
322 |
|
323 | var isUndefined$2 = function (value) {
|
324 | return typeof value === "undefined";
|
325 | };
|
326 |
|
327 | |
328 |
|
329 |
|
330 |
|
331 |
|
332 | var ComponentEvent =
|
333 |
|
334 | function () {
|
335 | |
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 | function ComponentEvent(eventType, props) {
|
342 | var e_1, _a;
|
343 |
|
344 | this.eventType = eventType;
|
345 | this._canceled = false;
|
346 | if (!props) return;
|
347 |
|
348 | try {
|
349 | for (var _b = __values$2(Object.keys(props)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
350 | var key = _c.value;
|
351 |
|
352 | this[key] = props[key];
|
353 | }
|
354 | } catch (e_1_1) {
|
355 | e_1 = {
|
356 | error: e_1_1
|
357 | };
|
358 | } finally {
|
359 | try {
|
360 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
361 | } finally {
|
362 | if (e_1) throw e_1.error;
|
363 | }
|
364 | }
|
365 | }
|
366 | |
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 | var __proto = ComponentEvent.prototype;
|
373 |
|
374 | __proto.stop = function () {
|
375 | this._canceled = true;
|
376 | };
|
377 | |
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 | __proto.isCanceled = function () {
|
385 | return this._canceled;
|
386 | };
|
387 |
|
388 | return ComponentEvent;
|
389 | }();
|
390 |
|
391 | |
392 |
|
393 |
|
394 |
|
395 |
|
396 | var Component$2 =
|
397 |
|
398 | function () {
|
399 | |
400 |
|
401 |
|
402 | function Component() {
|
403 | this._eventHandler = {};
|
404 | }
|
405 | |
406 |
|
407 |
|
408 |
|
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 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 | var __proto = Component.prototype;
|
449 |
|
450 | __proto.trigger = function (event) {
|
451 | var params = [];
|
452 |
|
453 | for (var _i = 1; _i < arguments.length; _i++) {
|
454 | params[_i - 1] = arguments[_i];
|
455 | }
|
456 |
|
457 | var eventName = event instanceof ComponentEvent ? event.eventType : event;
|
458 |
|
459 | var handlers = __spread(this._eventHandler[eventName] || []);
|
460 |
|
461 | if (handlers.length <= 0) {
|
462 | return this;
|
463 | }
|
464 |
|
465 | if (event instanceof ComponentEvent) {
|
466 | event.currentTarget = this;
|
467 | handlers.forEach(function (handler) {
|
468 | handler(event);
|
469 | });
|
470 | } else {
|
471 | handlers.forEach(function (handler) {
|
472 |
|
473 | handler.apply(void 0, __spread(params));
|
474 | });
|
475 | }
|
476 |
|
477 | return this;
|
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 | __proto.once = function (eventName, handlerToAttach) {
|
511 | var _this = this;
|
512 |
|
513 | if (typeof eventName === "object" && isUndefined$2(handlerToAttach)) {
|
514 | var eventHash = eventName;
|
515 |
|
516 | for (var key in eventHash) {
|
517 | this.once(key, eventHash[key]);
|
518 | }
|
519 |
|
520 | return this;
|
521 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
522 | var listener_1 = function () {
|
523 | var args = [];
|
524 |
|
525 | for (var _i = 0; _i < arguments.length; _i++) {
|
526 | args[_i] = arguments[_i];
|
527 | }
|
528 |
|
529 |
|
530 | handlerToAttach.apply(void 0, __spread(args));
|
531 |
|
532 | _this.off(eventName, listener_1);
|
533 | };
|
534 |
|
535 | this.on(eventName, listener_1);
|
536 | }
|
537 |
|
538 | return this;
|
539 | };
|
540 | |
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 | __proto.hasOn = function (eventName) {
|
561 | return !!this._eventHandler[eventName];
|
562 | };
|
563 | |
564 |
|
565 |
|
566 |
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 |
|
586 |
|
587 | __proto.on = function (eventName, handlerToAttach) {
|
588 | if (typeof eventName === "object" && isUndefined$2(handlerToAttach)) {
|
589 | var eventHash = eventName;
|
590 |
|
591 | for (var name in eventHash) {
|
592 | this.on(name, eventHash[name]);
|
593 | }
|
594 |
|
595 | return this;
|
596 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
597 | var handlerList = this._eventHandler[eventName];
|
598 |
|
599 | if (isUndefined$2(handlerList)) {
|
600 | this._eventHandler[eventName] = [];
|
601 | handlerList = this._eventHandler[eventName];
|
602 | }
|
603 |
|
604 | handlerList.push(handlerToAttach);
|
605 | }
|
606 |
|
607 | return this;
|
608 | };
|
609 | |
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 | __proto.off = function (eventName, handlerToDetach) {
|
634 | var e_1, _a;
|
635 |
|
636 |
|
637 | if (isUndefined$2(eventName)) {
|
638 | this._eventHandler = {};
|
639 | return this;
|
640 | }
|
641 |
|
642 |
|
643 | if (isUndefined$2(handlerToDetach)) {
|
644 | if (typeof eventName === "string") {
|
645 | delete this._eventHandler[eventName];
|
646 | return this;
|
647 | } else {
|
648 | var eventHash = eventName;
|
649 |
|
650 | for (var name in eventHash) {
|
651 | this.off(name, eventHash[name]);
|
652 | }
|
653 |
|
654 | return this;
|
655 | }
|
656 | }
|
657 |
|
658 |
|
659 | var handlerList = this._eventHandler[eventName];
|
660 |
|
661 | if (handlerList) {
|
662 | var idx = 0;
|
663 |
|
664 | try {
|
665 | for (var handlerList_1 = __values$2(handlerList), handlerList_1_1 = handlerList_1.next(); !handlerList_1_1.done; handlerList_1_1 = handlerList_1.next()) {
|
666 | var handlerFunction = handlerList_1_1.value;
|
667 |
|
668 | if (handlerFunction === handlerToDetach) {
|
669 | handlerList.splice(idx, 1);
|
670 |
|
671 | if (handlerList.length <= 0) {
|
672 | delete this._eventHandler[eventName];
|
673 | }
|
674 |
|
675 | break;
|
676 | }
|
677 |
|
678 | idx++;
|
679 | }
|
680 | } catch (e_1_1) {
|
681 | e_1 = {
|
682 | error: e_1_1
|
683 | };
|
684 | } finally {
|
685 | try {
|
686 | if (handlerList_1_1 && !handlerList_1_1.done && (_a = handlerList_1.return)) _a.call(handlerList_1);
|
687 | } finally {
|
688 | if (e_1) throw e_1.error;
|
689 | }
|
690 | }
|
691 | }
|
692 |
|
693 | return this;
|
694 | };
|
695 | |
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 | Component.VERSION = "3.0.1";
|
707 | return Component;
|
708 | }();
|
709 |
|
710 | |
711 |
|
712 |
|
713 |
|
714 |
|
715 | var ComponentEvent$1 = ComponentEvent;
|
716 |
|
717 | |
718 |
|
719 |
|
720 |
|
721 |
|
722 |
|
723 |
|
724 | |
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 | var CODE = {
|
747 | WRONG_TYPE: 0,
|
748 | ELEMENT_NOT_FOUND: 1,
|
749 | VAL_MUST_NOT_NULL: 2,
|
750 | NOT_ATTACHED_TO_FLICKING: 3,
|
751 | WRONG_OPTION: 4,
|
752 | INDEX_OUT_OF_RANGE: 5,
|
753 | POSITION_NOT_REACHABLE: 6,
|
754 | TRANSFORM_NOT_SUPPORTED: 7,
|
755 | STOP_CALLED_BY_USER: 8,
|
756 | ANIMATION_INTERRUPTED: 9,
|
757 | ANIMATION_ALREADY_PLAYING: 10,
|
758 | NOT_ALLOWED_IN_FRAMEWORK: 11,
|
759 | NOT_INITIALIZED: 12,
|
760 | NO_ACTIVE: 13
|
761 | };
|
762 | var MESSAGE = {
|
763 | WRONG_TYPE: function (wrongVal, correctTypes) {
|
764 | return wrongVal + "(" + typeof wrongVal + ") is not a " + correctTypes.map(function (type) {
|
765 | return "\"" + type + "\"";
|
766 | }).join(" or ") + ".";
|
767 | },
|
768 | ELEMENT_NOT_FOUND: function (selector) {
|
769 | return "Element with selector \"" + selector + "\" not found.";
|
770 | },
|
771 | VAL_MUST_NOT_NULL: function (val, name) {
|
772 | return name + " should be provided. Given: " + val;
|
773 | },
|
774 | NOT_ATTACHED_TO_FLICKING: function (name) {
|
775 | return name + " is not attached to the Flicking instance. \"init()\" should be called first.";
|
776 | },
|
777 | WRONG_OPTION: function (optionName, val) {
|
778 | return "Option \"" + optionName + "\" is not in correct format, given: " + val;
|
779 | },
|
780 | INDEX_OUT_OF_RANGE: function (val, min, max) {
|
781 | return "Index \"" + val + "\" is out of range: should be between " + min + " and " + max + ".";
|
782 | },
|
783 | POSITION_NOT_REACHABLE: function (position) {
|
784 | return "Position \"" + position + "\" is not reachable.";
|
785 | },
|
786 | TRANSFORM_NOT_SUPPORTED: "Browser does not support CSS transform.",
|
787 | STOP_CALLED_BY_USER: "Event stop() is called by user.",
|
788 | ANIMATION_INTERRUPTED: "Animation is interrupted by user input.",
|
789 | ANIMATION_ALREADY_PLAYING: "Animation is already playing.",
|
790 | NOT_ALLOWED_IN_FRAMEWORK: "This behavior is not allowed in the frameworks like React, Vue, or Angular.",
|
791 | NOT_INITIALIZED: "Flicking is not initialized yet, call init() first.",
|
792 | NO_ACTIVE: "There's no active panel that Flicking has selected. This may be due to the absence of any panels."
|
793 | };
|
794 |
|
795 | |
796 |
|
797 |
|
798 |
|
799 | |
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 | var EVENTS = {
|
823 | READY: "ready",
|
824 | BEFORE_RESIZE: "beforeResize",
|
825 | AFTER_RESIZE: "afterResize",
|
826 | HOLD_START: "holdStart",
|
827 | HOLD_END: "holdEnd",
|
828 | MOVE_START: "moveStart",
|
829 | MOVE: "move",
|
830 | MOVE_END: "moveEnd",
|
831 | WILL_CHANGE: "willChange",
|
832 | CHANGED: "changed",
|
833 | WILL_RESTORE: "willRestore",
|
834 | RESTORED: "restored",
|
835 | SELECT: "select",
|
836 | NEED_PANEL: "needPanel",
|
837 | VISIBLE_CHANGE: "visibleChange",
|
838 | REACH_EDGE: "reachEdge",
|
839 | PANEL_CHANGE: "panelChange"
|
840 | };
|
841 | |
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 |
|
848 |
|
849 |
|
850 | var ALIGN = {
|
851 | PREV: "prev",
|
852 | CENTER: "center",
|
853 | NEXT: "next"
|
854 | };
|
855 | |
856 |
|
857 |
|
858 |
|
859 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 |
|
866 | var DIRECTION = {
|
867 | PREV: "PREV",
|
868 | NEXT: "NEXT",
|
869 | NONE: null
|
870 | };
|
871 | |
872 |
|
873 |
|
874 |
|
875 |
|
876 |
|
877 |
|
878 |
|
879 |
|
880 |
|
881 |
|
882 |
|
883 | var MOVE_TYPE = {
|
884 | SNAP: "snap",
|
885 | FREE_SCROLL: "freeScroll",
|
886 | STRICT: "strict"
|
887 | };
|
888 |
|
889 | var Constants = {
|
890 | __proto__: null,
|
891 | EVENTS: EVENTS,
|
892 | ALIGN: ALIGN,
|
893 | DIRECTION: DIRECTION,
|
894 | MOVE_TYPE: MOVE_TYPE,
|
895 | ERROR_CODE: CODE
|
896 | };
|
897 |
|
898 | var merge$1 = function (target) {
|
899 | var sources = [];
|
900 |
|
901 | for (var _i = 1; _i < arguments.length; _i++) {
|
902 | sources[_i - 1] = arguments[_i];
|
903 | }
|
904 |
|
905 | sources.forEach(function (source) {
|
906 | Object.keys(source).forEach(function (key) {
|
907 | target[key] = source[key];
|
908 | });
|
909 | });
|
910 | return target;
|
911 | };
|
912 | var getElement = function (el, parent) {
|
913 | var targetEl = null;
|
914 |
|
915 | if (isString(el)) {
|
916 | var parentEl = parent ? parent : document;
|
917 | var queryResult = parentEl.querySelector(el);
|
918 |
|
919 | if (!queryResult) {
|
920 | throw new FlickingError(MESSAGE.ELEMENT_NOT_FOUND(el), CODE.ELEMENT_NOT_FOUND);
|
921 | }
|
922 |
|
923 | targetEl = queryResult;
|
924 | } else if (el && el.nodeType === Node.ELEMENT_NODE) {
|
925 | targetEl = el;
|
926 | }
|
927 |
|
928 | if (!targetEl) {
|
929 | throw new FlickingError(MESSAGE.WRONG_TYPE(el, ["HTMLElement", "string"]), CODE.WRONG_TYPE);
|
930 | }
|
931 |
|
932 | return targetEl;
|
933 | };
|
934 | var checkExistence = function (value, nameOnErrMsg) {
|
935 | if (value == null) {
|
936 | throw new FlickingError(MESSAGE.VAL_MUST_NOT_NULL(value, nameOnErrMsg), CODE.VAL_MUST_NOT_NULL);
|
937 | }
|
938 | };
|
939 | var clamp = function (x, min, max) {
|
940 | return Math.max(Math.min(x, max), min);
|
941 | };
|
942 | var getFlickingAttached = function (val, nameToThrowOnError) {
|
943 | if (!val) {
|
944 | throw new FlickingError(MESSAGE.NOT_ATTACHED_TO_FLICKING(nameToThrowOnError), CODE.NOT_ATTACHED_TO_FLICKING);
|
945 | }
|
946 |
|
947 | return val;
|
948 | };
|
949 | var toArray$3 = function (iterable) {
|
950 | return [].slice.call(iterable);
|
951 | };
|
952 | var parseAlign$1 = function (align, size) {
|
953 | var alignPoint;
|
954 |
|
955 | if (isString(align)) {
|
956 | switch (align) {
|
957 | case ALIGN.PREV:
|
958 | alignPoint = 0;
|
959 | break;
|
960 |
|
961 | case ALIGN.CENTER:
|
962 | alignPoint = 0.5 * size;
|
963 | break;
|
964 |
|
965 | case ALIGN.NEXT:
|
966 | alignPoint = size;
|
967 | break;
|
968 |
|
969 | default:
|
970 | alignPoint = parseArithmeticSize(align, size);
|
971 |
|
972 | if (alignPoint == null) {
|
973 | throw new FlickingError(MESSAGE.WRONG_OPTION("align", align), CODE.WRONG_OPTION);
|
974 | }
|
975 |
|
976 | }
|
977 | } else {
|
978 | alignPoint = align;
|
979 | }
|
980 |
|
981 | return alignPoint;
|
982 | };
|
983 | var parseBounce = function (bounce, size) {
|
984 | var parsedBounce;
|
985 |
|
986 | if (Array.isArray(bounce)) {
|
987 | parsedBounce = bounce.map(function (val) {
|
988 | return parseArithmeticSize(val, size);
|
989 | });
|
990 | } else {
|
991 | var parsedVal = parseArithmeticSize(bounce, size);
|
992 | parsedBounce = [parsedVal, parsedVal];
|
993 | }
|
994 |
|
995 | return parsedBounce.map(function (val) {
|
996 | if (val == null) {
|
997 | throw new FlickingError(MESSAGE.WRONG_OPTION("bounce", bounce), CODE.WRONG_OPTION);
|
998 | }
|
999 |
|
1000 | return val;
|
1001 | });
|
1002 | };
|
1003 | var parseArithmeticSize = function (cssValue, base) {
|
1004 | var parsed = parseArithmeticExpression(cssValue);
|
1005 | if (parsed == null) return null;
|
1006 | return parsed.percentage * base + parsed.absolute;
|
1007 | };
|
1008 | var parseArithmeticExpression = function (cssValue) {
|
1009 | var cssRegex = /(?:(\+|\-)\s*)?(\d+(?:\.\d+)?(%|px)?)/g;
|
1010 |
|
1011 | if (typeof cssValue === "number") {
|
1012 | return {
|
1013 | percentage: 0,
|
1014 | absolute: cssValue
|
1015 | };
|
1016 | }
|
1017 |
|
1018 | var parsed = {
|
1019 | percentage: 0,
|
1020 | absolute: 0
|
1021 | };
|
1022 | var idx = 0;
|
1023 | var matchResult = cssRegex.exec(cssValue);
|
1024 |
|
1025 | while (matchResult != null) {
|
1026 | var sign = matchResult[1];
|
1027 | var value = matchResult[2];
|
1028 | var unit = matchResult[3];
|
1029 | var parsedValue = parseFloat(value);
|
1030 |
|
1031 | if (idx <= 0) {
|
1032 | sign = sign || "+";
|
1033 | }
|
1034 |
|
1035 |
|
1036 | if (!sign) {
|
1037 | return null;
|
1038 | }
|
1039 |
|
1040 | var signMultiplier = sign === "+" ? 1 : -1;
|
1041 |
|
1042 | if (unit === "%") {
|
1043 | parsed.percentage += signMultiplier * (parsedValue / 100);
|
1044 | } else {
|
1045 | parsed.absolute += signMultiplier * parsedValue;
|
1046 | }
|
1047 |
|
1048 |
|
1049 | ++idx;
|
1050 | matchResult = cssRegex.exec(cssValue);
|
1051 | }
|
1052 |
|
1053 |
|
1054 | if (idx === 0) {
|
1055 | return null;
|
1056 | }
|
1057 |
|
1058 | return parsed;
|
1059 | };
|
1060 | var getDirection$1 = function (start, end) {
|
1061 | if (start === end) return DIRECTION.NONE;
|
1062 | return start < end ? DIRECTION.NEXT : DIRECTION.PREV;
|
1063 | };
|
1064 | var parseElement = function (element) {
|
1065 | if (!Array.isArray(element)) {
|
1066 | element = [element];
|
1067 | }
|
1068 |
|
1069 | var elements = [];
|
1070 | element.forEach(function (el) {
|
1071 | if (isString(el)) {
|
1072 | var tempDiv = document.createElement("div");
|
1073 | tempDiv.innerHTML = el;
|
1074 | elements.push.apply(elements, __spreadArray([], __read$1(toArray$3(tempDiv.children))));
|
1075 |
|
1076 | while (tempDiv.firstChild) {
|
1077 | tempDiv.removeChild(tempDiv.firstChild);
|
1078 | }
|
1079 | } else if (el && el.nodeType === Node.ELEMENT_NODE) {
|
1080 | elements.push(el);
|
1081 | } else {
|
1082 | throw new FlickingError(MESSAGE.WRONG_TYPE(el, ["HTMLElement", "string"]), CODE.WRONG_TYPE);
|
1083 | }
|
1084 | });
|
1085 | return elements;
|
1086 | };
|
1087 | var getMinusCompensatedIndex = function (idx, max) {
|
1088 | return idx < 0 ? clamp(idx + max, 0, max) : clamp(idx, 0, max);
|
1089 | };
|
1090 | var includes = function (array, target) {
|
1091 | var e_1, _a;
|
1092 |
|
1093 | try {
|
1094 | for (var array_1 = __values$3(array), array_1_1 = array_1.next(); !array_1_1.done; array_1_1 = array_1.next()) {
|
1095 | var val = array_1_1.value;
|
1096 | if (val === target) return true;
|
1097 | }
|
1098 | } catch (e_1_1) {
|
1099 | e_1 = {
|
1100 | error: e_1_1
|
1101 | };
|
1102 | } finally {
|
1103 | try {
|
1104 | if (array_1_1 && !array_1_1.done && (_a = array_1.return)) _a.call(array_1);
|
1105 | } finally {
|
1106 | if (e_1) throw e_1.error;
|
1107 | }
|
1108 | }
|
1109 |
|
1110 | return false;
|
1111 | };
|
1112 | var isString = function (val) {
|
1113 | return typeof val === "string";
|
1114 | };
|
1115 | var circulatePosition = function (pos, min, max) {
|
1116 | var size = max - min;
|
1117 |
|
1118 | if (pos < min) {
|
1119 | var offset = (min - pos) % size;
|
1120 | pos = max - offset;
|
1121 | } else if (pos > max) {
|
1122 | var offset = (pos - max) % size;
|
1123 | pos = min + offset;
|
1124 | }
|
1125 |
|
1126 | return pos;
|
1127 | };
|
1128 | var find$1 = function (array, checker) {
|
1129 | var e_2, _a;
|
1130 |
|
1131 | try {
|
1132 | for (var array_2 = __values$3(array), array_2_1 = array_2.next(); !array_2_1.done; array_2_1 = array_2.next()) {
|
1133 | var val = array_2_1.value;
|
1134 |
|
1135 | if (checker(val)) {
|
1136 | return val;
|
1137 | }
|
1138 | }
|
1139 | } catch (e_2_1) {
|
1140 | e_2 = {
|
1141 | error: e_2_1
|
1142 | };
|
1143 | } finally {
|
1144 | try {
|
1145 | if (array_2_1 && !array_2_1.done && (_a = array_2.return)) _a.call(array_2);
|
1146 | } finally {
|
1147 | if (e_2) throw e_2.error;
|
1148 | }
|
1149 | }
|
1150 |
|
1151 | return null;
|
1152 | };
|
1153 | var findIndex = function (array, checker) {
|
1154 | for (var idx = 0; idx < array.length; idx++) {
|
1155 | if (checker(array[idx])) {
|
1156 | return idx;
|
1157 | }
|
1158 | }
|
1159 |
|
1160 | return -1;
|
1161 | };
|
1162 | var getProgress = function (pos, prev, next) {
|
1163 | return (pos - prev) / (next - prev);
|
1164 | };
|
1165 |
|
1166 | var getStyle = function (el) {
|
1167 | return window.getComputedStyle(el) || el.currentStyle;
|
1168 | };
|
1169 | var isBetween = function (val, min, max) {
|
1170 | return val >= min && val <= max;
|
1171 | };
|
1172 | var circulateIndex = function (index, max) {
|
1173 | if (index >= max) {
|
1174 | return index % max;
|
1175 | } else if (index < 0) {
|
1176 | return getMinusCompensatedIndex((index + 1) % max - 1, max);
|
1177 | } else {
|
1178 | return index;
|
1179 | }
|
1180 | };
|
1181 | var setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
|
1182 | obj.__proto__ = proto;
|
1183 | return obj;
|
1184 | };
|
1185 |
|
1186 | |
1187 |
|
1188 |
|
1189 |
|
1190 | |
1191 |
|
1192 |
|
1193 |
|
1194 |
|
1195 |
|
1196 |
|
1197 |
|
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 |
|
1203 |
|
1204 |
|
1205 |
|
1206 |
|
1207 |
|
1208 |
|
1209 | var FlickingError = function (_super) {
|
1210 | __extends$2(FlickingError, _super);
|
1211 | |
1212 |
|
1213 |
|
1214 |
|
1215 |
|
1216 |
|
1217 | function FlickingError(message, code) {
|
1218 | var _this = _super.call(this, message) || this;
|
1219 |
|
1220 | setPrototypeOf(_this, FlickingError.prototype);
|
1221 | _this.name = "FlickingError";
|
1222 | _this.code = code;
|
1223 | return _this;
|
1224 | }
|
1225 |
|
1226 | return FlickingError;
|
1227 | }(Error);
|
1228 |
|
1229 | |
1230 |
|
1231 |
|
1232 |
|
1233 | |
1234 |
|
1235 |
|
1236 |
|
1237 |
|
1238 | var Viewport = function () {
|
1239 | |
1240 |
|
1241 |
|
1242 | function Viewport(el) {
|
1243 | this._el = el;
|
1244 | this._width = 0;
|
1245 | this._height = 0;
|
1246 | this._padding = {
|
1247 | left: 0,
|
1248 | right: 0,
|
1249 | top: 0,
|
1250 | bottom: 0
|
1251 | };
|
1252 | this._isBorderBoxSizing = false;
|
1253 | }
|
1254 |
|
1255 | var __proto = Viewport.prototype;
|
1256 | Object.defineProperty(__proto, "element", {
|
1257 | |
1258 |
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 | get: function () {
|
1264 | return this._el;
|
1265 | },
|
1266 | enumerable: false,
|
1267 | configurable: true
|
1268 | });
|
1269 | Object.defineProperty(__proto, "width", {
|
1270 | |
1271 |
|
1272 |
|
1273 |
|
1274 |
|
1275 |
|
1276 | get: function () {
|
1277 | return this._width - this._padding.left - this._padding.right;
|
1278 | },
|
1279 | enumerable: false,
|
1280 | configurable: true
|
1281 | });
|
1282 | Object.defineProperty(__proto, "height", {
|
1283 | |
1284 |
|
1285 |
|
1286 |
|
1287 |
|
1288 |
|
1289 | get: function () {
|
1290 | return this._height - this._padding.top - this._padding.bottom;
|
1291 | },
|
1292 | enumerable: false,
|
1293 | configurable: true
|
1294 | });
|
1295 | Object.defineProperty(__proto, "padding", {
|
1296 | |
1297 |
|
1298 |
|
1299 |
|
1300 |
|
1301 |
|
1302 |
|
1303 |
|
1304 |
|
1305 |
|
1306 | get: function () {
|
1307 | return this._padding;
|
1308 | },
|
1309 | enumerable: false,
|
1310 | configurable: true
|
1311 | });
|
1312 | |
1313 |
|
1314 |
|
1315 |
|
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 | __proto.setSize = function (_a) {
|
1323 | var width = _a.width,
|
1324 | height = _a.height;
|
1325 | var el = this._el;
|
1326 | var padding = this._padding;
|
1327 | var isBorderBoxSizing = this._isBorderBoxSizing;
|
1328 |
|
1329 | if (width != null) {
|
1330 | if (isString(width)) {
|
1331 | el.style.width = width;
|
1332 | } else {
|
1333 | var newWidth = isBorderBoxSizing ? width + padding.left + padding.right : width;
|
1334 | el.style.width = newWidth + "px";
|
1335 | }
|
1336 | }
|
1337 |
|
1338 | if (height != null) {
|
1339 | if (isString(height)) {
|
1340 | el.style.height = height;
|
1341 | } else {
|
1342 | var newHeight = isBorderBoxSizing ? height + padding.top + padding.bottom : height;
|
1343 | el.style.height = newHeight + "px";
|
1344 | }
|
1345 | }
|
1346 |
|
1347 | this.resize();
|
1348 | };
|
1349 | |
1350 |
|
1351 |
|
1352 |
|
1353 |
|
1354 |
|
1355 | __proto.resize = function () {
|
1356 | var el = this._el;
|
1357 | var elStyle = getStyle(el);
|
1358 | this._width = el.clientWidth;
|
1359 | this._height = el.clientHeight;
|
1360 | this._padding = {
|
1361 | left: parseFloat(elStyle.paddingLeft),
|
1362 | right: parseFloat(elStyle.paddingRight),
|
1363 | top: parseFloat(elStyle.paddingTop),
|
1364 | bottom: parseFloat(elStyle.paddingBottom)
|
1365 | };
|
1366 | this._isBorderBoxSizing = elStyle.boxSizing === "border-box";
|
1367 | };
|
1368 |
|
1369 | return Viewport;
|
1370 | }();
|
1371 |
|
1372 | |
1373 |
|
1374 |
|
1375 |
|
1376 |
|
1377 |
|
1378 | function _extends() {
|
1379 | _extends = Object.assign || function (target) {
|
1380 | for (var i = 1; i < arguments.length; i++) {
|
1381 | var source = arguments[i];
|
1382 |
|
1383 | for (var key in source) {
|
1384 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
1385 | target[key] = source[key];
|
1386 | }
|
1387 | }
|
1388 | }
|
1389 |
|
1390 | return target;
|
1391 | };
|
1392 |
|
1393 | return _extends.apply(this, arguments);
|
1394 | }
|
1395 |
|
1396 | function _inheritsLoose(subClass, superClass) {
|
1397 | subClass.prototype = Object.create(superClass.prototype);
|
1398 | subClass.prototype.constructor = subClass;
|
1399 | subClass.__proto__ = superClass;
|
1400 | }
|
1401 |
|
1402 | function _assertThisInitialized(self) {
|
1403 | if (self === void 0) {
|
1404 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
1405 | }
|
1406 |
|
1407 | return self;
|
1408 | }
|
1409 |
|
1410 | |
1411 |
|
1412 |
|
1413 |
|
1414 |
|
1415 |
|
1416 |
|
1417 |
|
1418 | var assign;
|
1419 |
|
1420 | if (typeof Object.assign !== 'function') {
|
1421 | assign = function assign(target) {
|
1422 | if (target === undefined || target === null) {
|
1423 | throw new TypeError('Cannot convert undefined or null to object');
|
1424 | }
|
1425 |
|
1426 | var output = Object(target);
|
1427 |
|
1428 | for (var index = 1; index < arguments.length; index++) {
|
1429 | var source = arguments[index];
|
1430 |
|
1431 | if (source !== undefined && source !== null) {
|
1432 | for (var nextKey in source) {
|
1433 | if (source.hasOwnProperty(nextKey)) {
|
1434 | output[nextKey] = source[nextKey];
|
1435 | }
|
1436 | }
|
1437 | }
|
1438 | }
|
1439 |
|
1440 | return output;
|
1441 | };
|
1442 | } else {
|
1443 | assign = Object.assign;
|
1444 | }
|
1445 |
|
1446 | var assign$1 = assign;
|
1447 |
|
1448 | var VENDOR_PREFIXES = ['', 'webkit', 'Moz', 'MS', 'ms', 'o'];
|
1449 | var TEST_ELEMENT = typeof document === "undefined" ? {
|
1450 | style: {}
|
1451 | } : document.createElement('div');
|
1452 | var TYPE_FUNCTION = 'function';
|
1453 | var round = Math.round,
|
1454 | abs = Math.abs;
|
1455 | var now = Date.now;
|
1456 |
|
1457 | |
1458 |
|
1459 |
|
1460 |
|
1461 |
|
1462 |
|
1463 |
|
1464 |
|
1465 | function prefixed(obj, property) {
|
1466 | var prefix;
|
1467 | var prop;
|
1468 | var camelProp = property[0].toUpperCase() + property.slice(1);
|
1469 | var i = 0;
|
1470 |
|
1471 | while (i < VENDOR_PREFIXES.length) {
|
1472 | prefix = VENDOR_PREFIXES[i];
|
1473 | prop = prefix ? prefix + camelProp : property;
|
1474 |
|
1475 | if (prop in obj) {
|
1476 | return prop;
|
1477 | }
|
1478 |
|
1479 | i++;
|
1480 | }
|
1481 |
|
1482 | return undefined;
|
1483 | }
|
1484 |
|
1485 |
|
1486 | var win$1;
|
1487 |
|
1488 | if (typeof window === "undefined") {
|
1489 |
|
1490 | win$1 = {};
|
1491 | } else {
|
1492 | win$1 = window;
|
1493 | }
|
1494 |
|
1495 | var PREFIXED_TOUCH_ACTION = prefixed(TEST_ELEMENT.style, 'touchAction');
|
1496 | var NATIVE_TOUCH_ACTION = PREFIXED_TOUCH_ACTION !== undefined;
|
1497 | function getTouchActionProps() {
|
1498 | if (!NATIVE_TOUCH_ACTION) {
|
1499 | return false;
|
1500 | }
|
1501 |
|
1502 | var touchMap = {};
|
1503 | var cssSupports = win$1.CSS && win$1.CSS.supports;
|
1504 | ['auto', 'manipulation', 'pan-y', 'pan-x', 'pan-x pan-y', 'none'].forEach(function (val) {
|
1505 |
|
1506 |
|
1507 | return touchMap[val] = cssSupports ? win$1.CSS.supports('touch-action', val) : true;
|
1508 | });
|
1509 | return touchMap;
|
1510 | }
|
1511 |
|
1512 | var TOUCH_ACTION_COMPUTE = 'compute';
|
1513 | var TOUCH_ACTION_AUTO = 'auto';
|
1514 | var TOUCH_ACTION_MANIPULATION = 'manipulation';
|
1515 |
|
1516 | var TOUCH_ACTION_NONE = 'none';
|
1517 | var TOUCH_ACTION_PAN_X = 'pan-x';
|
1518 | var TOUCH_ACTION_PAN_Y = 'pan-y';
|
1519 | var TOUCH_ACTION_MAP = getTouchActionProps();
|
1520 |
|
1521 | var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
|
1522 | var SUPPORT_TOUCH$1 = 'ontouchstart' in win$1;
|
1523 | var SUPPORT_POINTER_EVENTS$1 = prefixed(win$1, 'PointerEvent') !== undefined;
|
1524 | var SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH$1 && MOBILE_REGEX.test(navigator.userAgent);
|
1525 | var INPUT_TYPE_TOUCH = 'touch';
|
1526 | var INPUT_TYPE_PEN = 'pen';
|
1527 | var INPUT_TYPE_MOUSE = 'mouse';
|
1528 | var INPUT_TYPE_KINECT = 'kinect';
|
1529 | var COMPUTE_INTERVAL = 25;
|
1530 | var INPUT_START = 1;
|
1531 | var INPUT_MOVE = 2;
|
1532 | var INPUT_END = 4;
|
1533 | var INPUT_CANCEL = 8;
|
1534 | var DIRECTION_NONE = 1;
|
1535 | var DIRECTION_LEFT = 2;
|
1536 | var DIRECTION_RIGHT = 4;
|
1537 | var DIRECTION_UP = 8;
|
1538 | var DIRECTION_DOWN = 16;
|
1539 | var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT;
|
1540 | var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN;
|
1541 | var DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;
|
1542 | var PROPS_XY = ['x', 'y'];
|
1543 | var PROPS_CLIENT_XY = ['clientX', 'clientY'];
|
1544 |
|
1545 | |
1546 |
|
1547 |
|
1548 |
|
1549 |
|
1550 |
|
1551 |
|
1552 | function each(obj, iterator, context) {
|
1553 | var i;
|
1554 |
|
1555 | if (!obj) {
|
1556 | return;
|
1557 | }
|
1558 |
|
1559 | if (obj.forEach) {
|
1560 | obj.forEach(iterator, context);
|
1561 | } else if (obj.length !== undefined) {
|
1562 | i = 0;
|
1563 |
|
1564 | while (i < obj.length) {
|
1565 | iterator.call(context, obj[i], i, obj);
|
1566 | i++;
|
1567 | }
|
1568 | } else {
|
1569 | for (i in obj) {
|
1570 | obj.hasOwnProperty(i) && iterator.call(context, obj[i], i, obj);
|
1571 | }
|
1572 | }
|
1573 | }
|
1574 |
|
1575 | |
1576 |
|
1577 |
|
1578 |
|
1579 |
|
1580 |
|
1581 |
|
1582 |
|
1583 |
|
1584 | function boolOrFn(val, args) {
|
1585 | if (typeof val === TYPE_FUNCTION) {
|
1586 | return val.apply(args ? args[0] || undefined : undefined, args);
|
1587 | }
|
1588 |
|
1589 | return val;
|
1590 | }
|
1591 |
|
1592 | |
1593 |
|
1594 |
|
1595 |
|
1596 |
|
1597 |
|
1598 |
|
1599 | function inStr(str, find) {
|
1600 | return str.indexOf(find) > -1;
|
1601 | }
|
1602 |
|
1603 | |
1604 |
|
1605 |
|
1606 |
|
1607 |
|
1608 |
|
1609 |
|
1610 | function cleanTouchActions(actions) {
|
1611 |
|
1612 | if (inStr(actions, TOUCH_ACTION_NONE)) {
|
1613 | return TOUCH_ACTION_NONE;
|
1614 | }
|
1615 |
|
1616 | var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
|
1617 | var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y);
|
1618 |
|
1619 |
|
1620 |
|
1621 |
|
1622 | if (hasPanX && hasPanY) {
|
1623 | return TOUCH_ACTION_NONE;
|
1624 | }
|
1625 |
|
1626 |
|
1627 | if (hasPanX || hasPanY) {
|
1628 | return hasPanX ? TOUCH_ACTION_PAN_X : TOUCH_ACTION_PAN_Y;
|
1629 | }
|
1630 |
|
1631 |
|
1632 | if (inStr(actions, TOUCH_ACTION_MANIPULATION)) {
|
1633 | return TOUCH_ACTION_MANIPULATION;
|
1634 | }
|
1635 |
|
1636 | return TOUCH_ACTION_AUTO;
|
1637 | }
|
1638 |
|
1639 | |
1640 |
|
1641 |
|
1642 |
|
1643 |
|
1644 |
|
1645 |
|
1646 |
|
1647 |
|
1648 | var TouchAction =
|
1649 |
|
1650 | function () {
|
1651 | function TouchAction(manager, value) {
|
1652 | this.manager = manager;
|
1653 | this.set(value);
|
1654 | }
|
1655 | |
1656 |
|
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 |
|
1662 | var _proto = TouchAction.prototype;
|
1663 |
|
1664 | _proto.set = function set(value) {
|
1665 |
|
1666 | if (value === TOUCH_ACTION_COMPUTE) {
|
1667 | value = this.compute();
|
1668 | }
|
1669 |
|
1670 | if (NATIVE_TOUCH_ACTION && this.manager.element.style && TOUCH_ACTION_MAP[value]) {
|
1671 | this.manager.element.style[PREFIXED_TOUCH_ACTION] = value;
|
1672 | }
|
1673 |
|
1674 | this.actions = value.toLowerCase().trim();
|
1675 | };
|
1676 | |
1677 |
|
1678 |
|
1679 |
|
1680 |
|
1681 |
|
1682 | _proto.update = function update() {
|
1683 | this.set(this.manager.options.touchAction);
|
1684 | };
|
1685 | |
1686 |
|
1687 |
|
1688 |
|
1689 |
|
1690 |
|
1691 |
|
1692 | _proto.compute = function compute() {
|
1693 | var actions = [];
|
1694 | each(this.manager.recognizers, function (recognizer) {
|
1695 | if (boolOrFn(recognizer.options.enable, [recognizer])) {
|
1696 | actions = actions.concat(recognizer.getTouchAction());
|
1697 | }
|
1698 | });
|
1699 | return cleanTouchActions(actions.join(' '));
|
1700 | };
|
1701 | |
1702 |
|
1703 |
|
1704 |
|
1705 |
|
1706 |
|
1707 |
|
1708 | _proto.preventDefaults = function preventDefaults(input) {
|
1709 | var srcEvent = input.srcEvent;
|
1710 | var direction = input.offsetDirection;
|
1711 |
|
1712 | if (this.manager.session.prevented) {
|
1713 | srcEvent.preventDefault();
|
1714 | return;
|
1715 | }
|
1716 |
|
1717 | var actions = this.actions;
|
1718 | var hasNone = inStr(actions, TOUCH_ACTION_NONE) && !TOUCH_ACTION_MAP[TOUCH_ACTION_NONE];
|
1719 | var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_Y];
|
1720 | var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_X];
|
1721 |
|
1722 | if (hasNone) {
|
1723 |
|
1724 | var isTapPointer = input.pointers.length === 1;
|
1725 | var isTapMovement = input.distance < 2;
|
1726 | var isTapTouchTime = input.deltaTime < 250;
|
1727 |
|
1728 | if (isTapPointer && isTapMovement && isTapTouchTime) {
|
1729 | return;
|
1730 | }
|
1731 | }
|
1732 |
|
1733 | if (hasPanX && hasPanY) {
|
1734 |
|
1735 | return;
|
1736 | }
|
1737 |
|
1738 | if (hasNone || hasPanY && direction & DIRECTION_HORIZONTAL || hasPanX && direction & DIRECTION_VERTICAL) {
|
1739 | return this.preventSrc(srcEvent);
|
1740 | }
|
1741 | };
|
1742 | |
1743 |
|
1744 |
|
1745 |
|
1746 |
|
1747 |
|
1748 |
|
1749 | _proto.preventSrc = function preventSrc(srcEvent) {
|
1750 | this.manager.session.prevented = true;
|
1751 | srcEvent.preventDefault();
|
1752 | };
|
1753 |
|
1754 | return TouchAction;
|
1755 | }();
|
1756 |
|
1757 | |
1758 |
|
1759 |
|
1760 |
|
1761 |
|
1762 |
|
1763 |
|
1764 |
|
1765 | function hasParent(node, parent) {
|
1766 | while (node) {
|
1767 | if (node === parent) {
|
1768 | return true;
|
1769 | }
|
1770 |
|
1771 | node = node.parentNode;
|
1772 | }
|
1773 |
|
1774 | return false;
|
1775 | }
|
1776 |
|
1777 | |
1778 |
|
1779 |
|
1780 |
|
1781 |
|
1782 |
|
1783 |
|
1784 | function getCenter(pointers) {
|
1785 | var pointersLength = pointers.length;
|
1786 |
|
1787 | if (pointersLength === 1) {
|
1788 | return {
|
1789 | x: round(pointers[0].clientX),
|
1790 | y: round(pointers[0].clientY)
|
1791 | };
|
1792 | }
|
1793 |
|
1794 | var x = 0;
|
1795 | var y = 0;
|
1796 | var i = 0;
|
1797 |
|
1798 | while (i < pointersLength) {
|
1799 | x += pointers[i].clientX;
|
1800 | y += pointers[i].clientY;
|
1801 | i++;
|
1802 | }
|
1803 |
|
1804 | return {
|
1805 | x: round(x / pointersLength),
|
1806 | y: round(y / pointersLength)
|
1807 | };
|
1808 | }
|
1809 |
|
1810 | |
1811 |
|
1812 |
|
1813 |
|
1814 |
|
1815 |
|
1816 |
|
1817 | function simpleCloneInputData(input) {
|
1818 |
|
1819 |
|
1820 | var pointers = [];
|
1821 | var i = 0;
|
1822 |
|
1823 | while (i < input.pointers.length) {
|
1824 | pointers[i] = {
|
1825 | clientX: round(input.pointers[i].clientX),
|
1826 | clientY: round(input.pointers[i].clientY)
|
1827 | };
|
1828 | i++;
|
1829 | }
|
1830 |
|
1831 | return {
|
1832 | timeStamp: now(),
|
1833 | pointers: pointers,
|
1834 | center: getCenter(pointers),
|
1835 | deltaX: input.deltaX,
|
1836 | deltaY: input.deltaY
|
1837 | };
|
1838 | }
|
1839 |
|
1840 | |
1841 |
|
1842 |
|
1843 |
|
1844 |
|
1845 |
|
1846 |
|
1847 |
|
1848 |
|
1849 | function getDistance(p1, p2, props) {
|
1850 | if (!props) {
|
1851 | props = PROPS_XY;
|
1852 | }
|
1853 |
|
1854 | var x = p2[props[0]] - p1[props[0]];
|
1855 | var y = p2[props[1]] - p1[props[1]];
|
1856 | return Math.sqrt(x * x + y * y);
|
1857 | }
|
1858 |
|
1859 | |
1860 |
|
1861 |
|
1862 |
|
1863 |
|
1864 |
|
1865 |
|
1866 |
|
1867 |
|
1868 | function getAngle(p1, p2, props) {
|
1869 | if (!props) {
|
1870 | props = PROPS_XY;
|
1871 | }
|
1872 |
|
1873 | var x = p2[props[0]] - p1[props[0]];
|
1874 | var y = p2[props[1]] - p1[props[1]];
|
1875 | return Math.atan2(y, x) * 180 / Math.PI;
|
1876 | }
|
1877 |
|
1878 | |
1879 |
|
1880 |
|
1881 |
|
1882 |
|
1883 |
|
1884 |
|
1885 |
|
1886 | function getDirection(x, y) {
|
1887 | if (x === y) {
|
1888 | return DIRECTION_NONE;
|
1889 | }
|
1890 |
|
1891 | if (abs(x) >= abs(y)) {
|
1892 | return x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
1893 | }
|
1894 |
|
1895 | return y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
|
1896 | }
|
1897 |
|
1898 | function computeDeltaXY(session, input) {
|
1899 | var center = input.center;
|
1900 |
|
1901 |
|
1902 | var offset = session.offsetDelta || {};
|
1903 | var prevDelta = session.prevDelta || {};
|
1904 | var prevInput = session.prevInput || {};
|
1905 |
|
1906 | if (input.eventType === INPUT_START || prevInput.eventType === INPUT_END) {
|
1907 | prevDelta = session.prevDelta = {
|
1908 | x: prevInput.deltaX || 0,
|
1909 | y: prevInput.deltaY || 0
|
1910 | };
|
1911 | offset = session.offsetDelta = {
|
1912 | x: center.x,
|
1913 | y: center.y
|
1914 | };
|
1915 | }
|
1916 |
|
1917 | input.deltaX = prevDelta.x + (center.x - offset.x);
|
1918 | input.deltaY = prevDelta.y + (center.y - offset.y);
|
1919 | }
|
1920 |
|
1921 | |
1922 |
|
1923 |
|
1924 |
|
1925 |
|
1926 |
|
1927 |
|
1928 |
|
1929 | function getVelocity(deltaTime, x, y) {
|
1930 | return {
|
1931 | x: x / deltaTime || 0,
|
1932 | y: y / deltaTime || 0
|
1933 | };
|
1934 | }
|
1935 |
|
1936 | |
1937 |
|
1938 |
|
1939 |
|
1940 |
|
1941 |
|
1942 |
|
1943 |
|
1944 |
|
1945 | function getScale(start, end) {
|
1946 | return getDistance(end[0], end[1], PROPS_CLIENT_XY) / getDistance(start[0], start[1], PROPS_CLIENT_XY);
|
1947 | }
|
1948 |
|
1949 | |
1950 |
|
1951 |
|
1952 |
|
1953 |
|
1954 |
|
1955 |
|
1956 |
|
1957 | function getRotation(start, end) {
|
1958 | return getAngle(end[1], end[0], PROPS_CLIENT_XY) + getAngle(start[1], start[0], PROPS_CLIENT_XY);
|
1959 | }
|
1960 |
|
1961 | |
1962 |
|
1963 |
|
1964 |
|
1965 |
|
1966 |
|
1967 |
|
1968 | function computeIntervalInputData(session, input) {
|
1969 | var last = session.lastInterval || input;
|
1970 | var deltaTime = input.timeStamp - last.timeStamp;
|
1971 | var velocity;
|
1972 | var velocityX;
|
1973 | var velocityY;
|
1974 | var direction;
|
1975 |
|
1976 | if (input.eventType !== INPUT_CANCEL && (deltaTime > COMPUTE_INTERVAL || last.velocity === undefined)) {
|
1977 | var deltaX = input.deltaX - last.deltaX;
|
1978 | var deltaY = input.deltaY - last.deltaY;
|
1979 | var v = getVelocity(deltaTime, deltaX, deltaY);
|
1980 | velocityX = v.x;
|
1981 | velocityY = v.y;
|
1982 | velocity = abs(v.x) > abs(v.y) ? v.x : v.y;
|
1983 | direction = getDirection(deltaX, deltaY);
|
1984 | session.lastInterval = input;
|
1985 | } else {
|
1986 |
|
1987 | velocity = last.velocity;
|
1988 | velocityX = last.velocityX;
|
1989 | velocityY = last.velocityY;
|
1990 | direction = last.direction;
|
1991 | }
|
1992 |
|
1993 | input.velocity = velocity;
|
1994 | input.velocityX = velocityX;
|
1995 | input.velocityY = velocityY;
|
1996 | input.direction = direction;
|
1997 | }
|
1998 |
|
1999 | |
2000 |
|
2001 |
|
2002 |
|
2003 |
|
2004 |
|
2005 |
|
2006 | function computeInputData(manager, input) {
|
2007 | var session = manager.session;
|
2008 | var pointers = input.pointers;
|
2009 | var pointersLength = pointers.length;
|
2010 |
|
2011 | if (!session.firstInput) {
|
2012 | session.firstInput = simpleCloneInputData(input);
|
2013 | }
|
2014 |
|
2015 |
|
2016 | if (pointersLength > 1 && !session.firstMultiple) {
|
2017 | session.firstMultiple = simpleCloneInputData(input);
|
2018 | } else if (pointersLength === 1) {
|
2019 | session.firstMultiple = false;
|
2020 | }
|
2021 |
|
2022 | var firstInput = session.firstInput,
|
2023 | firstMultiple = session.firstMultiple;
|
2024 | var offsetCenter = firstMultiple ? firstMultiple.center : firstInput.center;
|
2025 | var center = input.center = getCenter(pointers);
|
2026 | input.timeStamp = now();
|
2027 | input.deltaTime = input.timeStamp - firstInput.timeStamp;
|
2028 | input.angle = getAngle(offsetCenter, center);
|
2029 | input.distance = getDistance(offsetCenter, center);
|
2030 | computeDeltaXY(session, input);
|
2031 | input.offsetDirection = getDirection(input.deltaX, input.deltaY);
|
2032 | var overallVelocity = getVelocity(input.deltaTime, input.deltaX, input.deltaY);
|
2033 | input.overallVelocityX = overallVelocity.x;
|
2034 | input.overallVelocityY = overallVelocity.y;
|
2035 | input.overallVelocity = abs(overallVelocity.x) > abs(overallVelocity.y) ? overallVelocity.x : overallVelocity.y;
|
2036 | input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
|
2037 | input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
|
2038 | input.maxPointers = !session.prevInput ? input.pointers.length : input.pointers.length > session.prevInput.maxPointers ? input.pointers.length : session.prevInput.maxPointers;
|
2039 | computeIntervalInputData(session, input);
|
2040 |
|
2041 | var target = manager.element;
|
2042 | var srcEvent = input.srcEvent;
|
2043 | var srcEventTarget;
|
2044 |
|
2045 | if (srcEvent.composedPath) {
|
2046 | srcEventTarget = srcEvent.composedPath()[0];
|
2047 | } else if (srcEvent.path) {
|
2048 | srcEventTarget = srcEvent.path[0];
|
2049 | } else {
|
2050 | srcEventTarget = srcEvent.target;
|
2051 | }
|
2052 |
|
2053 | if (hasParent(srcEventTarget, target)) {
|
2054 | target = srcEventTarget;
|
2055 | }
|
2056 |
|
2057 | input.target = target;
|
2058 | }
|
2059 |
|
2060 | |
2061 |
|
2062 |
|
2063 |
|
2064 |
|
2065 |
|
2066 |
|
2067 |
|
2068 | function inputHandler(manager, eventType, input) {
|
2069 | var pointersLen = input.pointers.length;
|
2070 | var changedPointersLen = input.changedPointers.length;
|
2071 | var isFirst = eventType & INPUT_START && pointersLen - changedPointersLen === 0;
|
2072 | var isFinal = eventType & (INPUT_END | INPUT_CANCEL) && pointersLen - changedPointersLen === 0;
|
2073 | input.isFirst = !!isFirst;
|
2074 | input.isFinal = !!isFinal;
|
2075 |
|
2076 | if (isFirst) {
|
2077 | manager.session = {};
|
2078 | }
|
2079 |
|
2080 |
|
2081 |
|
2082 | input.eventType = eventType;
|
2083 |
|
2084 | computeInputData(manager, input);
|
2085 |
|
2086 | manager.emit('hammer.input', input);
|
2087 | manager.recognize(input);
|
2088 | manager.session.prevInput = input;
|
2089 | }
|
2090 |
|
2091 | |
2092 |
|
2093 |
|
2094 |
|
2095 |
|
2096 |
|
2097 | function splitStr(str) {
|
2098 | return str.trim().split(/\s+/g);
|
2099 | }
|
2100 |
|
2101 | |
2102 |
|
2103 |
|
2104 |
|
2105 |
|
2106 |
|
2107 |
|
2108 |
|
2109 | function addEventListeners(target, types, handler) {
|
2110 | each(splitStr(types), function (type) {
|
2111 | target.addEventListener(type, handler, false);
|
2112 | });
|
2113 | }
|
2114 |
|
2115 | |
2116 |
|
2117 |
|
2118 |
|
2119 |
|
2120 |
|
2121 |
|
2122 |
|
2123 | function removeEventListeners(target, types, handler) {
|
2124 | each(splitStr(types), function (type) {
|
2125 | target.removeEventListener(type, handler, false);
|
2126 | });
|
2127 | }
|
2128 |
|
2129 | |
2130 |
|
2131 |
|
2132 |
|
2133 |
|
2134 |
|
2135 | function getWindowForElement(element) {
|
2136 | var doc = element.ownerDocument || element;
|
2137 | return doc.defaultView || doc.parentWindow || window;
|
2138 | }
|
2139 |
|
2140 | |
2141 |
|
2142 |
|
2143 |
|
2144 |
|
2145 |
|
2146 |
|
2147 |
|
2148 |
|
2149 | var Input =
|
2150 |
|
2151 | function () {
|
2152 | function Input(manager, callback) {
|
2153 | var self = this;
|
2154 | this.manager = manager;
|
2155 | this.callback = callback;
|
2156 | this.element = manager.element;
|
2157 | this.target = manager.options.inputTarget;
|
2158 |
|
2159 |
|
2160 | this.domHandler = function (ev) {
|
2161 | if (boolOrFn(manager.options.enable, [manager])) {
|
2162 | self.handler(ev);
|
2163 | }
|
2164 | };
|
2165 |
|
2166 | this.init();
|
2167 | }
|
2168 | |
2169 |
|
2170 |
|
2171 |
|
2172 |
|
2173 |
|
2174 |
|
2175 | var _proto = Input.prototype;
|
2176 |
|
2177 | _proto.handler = function handler() {};
|
2178 | |
2179 |
|
2180 |
|
2181 |
|
2182 |
|
2183 |
|
2184 | _proto.init = function init() {
|
2185 | this.evEl && addEventListeners(this.element, this.evEl, this.domHandler);
|
2186 | this.evTarget && addEventListeners(this.target, this.evTarget, this.domHandler);
|
2187 | this.evWin && addEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
|
2188 | };
|
2189 | |
2190 |
|
2191 |
|
2192 |
|
2193 |
|
2194 |
|
2195 | _proto.destroy = function destroy() {
|
2196 | this.evEl && removeEventListeners(this.element, this.evEl, this.domHandler);
|
2197 | this.evTarget && removeEventListeners(this.target, this.evTarget, this.domHandler);
|
2198 | this.evWin && removeEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
|
2199 | };
|
2200 |
|
2201 | return Input;
|
2202 | }();
|
2203 |
|
2204 | |
2205 |
|
2206 |
|
2207 |
|
2208 |
|
2209 |
|
2210 |
|
2211 |
|
2212 | function inArray(src, find, findByKey) {
|
2213 | if (src.indexOf && !findByKey) {
|
2214 | return src.indexOf(find);
|
2215 | } else {
|
2216 | var i = 0;
|
2217 |
|
2218 | while (i < src.length) {
|
2219 | if (findByKey && src[i][findByKey] == find || !findByKey && src[i] === find) {
|
2220 |
|
2221 | return i;
|
2222 | }
|
2223 |
|
2224 | i++;
|
2225 | }
|
2226 |
|
2227 | return -1;
|
2228 | }
|
2229 | }
|
2230 |
|
2231 | var POINTER_INPUT_MAP = {
|
2232 | pointerdown: INPUT_START,
|
2233 | pointermove: INPUT_MOVE,
|
2234 | pointerup: INPUT_END,
|
2235 | pointercancel: INPUT_CANCEL,
|
2236 | pointerout: INPUT_CANCEL
|
2237 | };
|
2238 |
|
2239 | var IE10_POINTER_TYPE_ENUM = {
|
2240 | 2: INPUT_TYPE_TOUCH,
|
2241 | 3: INPUT_TYPE_PEN,
|
2242 | 4: INPUT_TYPE_MOUSE,
|
2243 | 5: INPUT_TYPE_KINECT
|
2244 |
|
2245 | };
|
2246 | var POINTER_ELEMENT_EVENTS = 'pointerdown';
|
2247 | var POINTER_WINDOW_EVENTS = 'pointermove pointerup pointercancel';
|
2248 |
|
2249 | if (win$1.MSPointerEvent && !win$1.PointerEvent) {
|
2250 | POINTER_ELEMENT_EVENTS = 'MSPointerDown';
|
2251 | POINTER_WINDOW_EVENTS = 'MSPointerMove MSPointerUp MSPointerCancel';
|
2252 | }
|
2253 | |
2254 |
|
2255 |
|
2256 |
|
2257 |
|
2258 |
|
2259 |
|
2260 |
|
2261 | var PointerEventInput =
|
2262 |
|
2263 | function (_Input) {
|
2264 | _inheritsLoose(PointerEventInput, _Input);
|
2265 |
|
2266 | function PointerEventInput() {
|
2267 | var _this;
|
2268 |
|
2269 | var proto = PointerEventInput.prototype;
|
2270 | proto.evEl = POINTER_ELEMENT_EVENTS;
|
2271 | proto.evWin = POINTER_WINDOW_EVENTS;
|
2272 | _this = _Input.apply(this, arguments) || this;
|
2273 | _this.store = _this.manager.session.pointerEvents = [];
|
2274 | return _this;
|
2275 | }
|
2276 | |
2277 |
|
2278 |
|
2279 |
|
2280 |
|
2281 |
|
2282 |
|
2283 | var _proto = PointerEventInput.prototype;
|
2284 |
|
2285 | _proto.handler = function handler(ev) {
|
2286 | var store = this.store;
|
2287 | var removePointer = false;
|
2288 | var eventTypeNormalized = ev.type.toLowerCase().replace('ms', '');
|
2289 | var eventType = POINTER_INPUT_MAP[eventTypeNormalized];
|
2290 | var pointerType = IE10_POINTER_TYPE_ENUM[ev.pointerType] || ev.pointerType;
|
2291 | var isTouch = pointerType === INPUT_TYPE_TOUCH;
|
2292 |
|
2293 | var storeIndex = inArray(store, ev.pointerId, 'pointerId');
|
2294 |
|
2295 | if (eventType & INPUT_START && (ev.button === 0 || isTouch)) {
|
2296 | if (storeIndex < 0) {
|
2297 | store.push(ev);
|
2298 | storeIndex = store.length - 1;
|
2299 | }
|
2300 | } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
|
2301 | removePointer = true;
|
2302 | }
|
2303 |
|
2304 |
|
2305 | if (storeIndex < 0) {
|
2306 | return;
|
2307 | }
|
2308 |
|
2309 |
|
2310 | store[storeIndex] = ev;
|
2311 | this.callback(this.manager, eventType, {
|
2312 | pointers: store,
|
2313 | changedPointers: [ev],
|
2314 | pointerType: pointerType,
|
2315 | srcEvent: ev
|
2316 | });
|
2317 |
|
2318 | if (removePointer) {
|
2319 |
|
2320 | store.splice(storeIndex, 1);
|
2321 | }
|
2322 | };
|
2323 |
|
2324 | return PointerEventInput;
|
2325 | }(Input);
|
2326 |
|
2327 | |
2328 |
|
2329 |
|
2330 |
|
2331 |
|
2332 |
|
2333 | function toArray$2(obj) {
|
2334 | return Array.prototype.slice.call(obj, 0);
|
2335 | }
|
2336 |
|
2337 | |
2338 |
|
2339 |
|
2340 |
|
2341 |
|
2342 |
|
2343 |
|
2344 |
|
2345 |
|
2346 | function uniqueArray(src, key, sort) {
|
2347 | var results = [];
|
2348 | var values = [];
|
2349 | var i = 0;
|
2350 |
|
2351 | while (i < src.length) {
|
2352 | var val = key ? src[i][key] : src[i];
|
2353 |
|
2354 | if (inArray(values, val) < 0) {
|
2355 | results.push(src[i]);
|
2356 | }
|
2357 |
|
2358 | values[i] = val;
|
2359 | i++;
|
2360 | }
|
2361 |
|
2362 | if (sort) {
|
2363 | if (!key) {
|
2364 | results = results.sort();
|
2365 | } else {
|
2366 | results = results.sort(function (a, b) {
|
2367 | return a[key] > b[key];
|
2368 | });
|
2369 | }
|
2370 | }
|
2371 |
|
2372 | return results;
|
2373 | }
|
2374 |
|
2375 | var TOUCH_INPUT_MAP = {
|
2376 | touchstart: INPUT_START,
|
2377 | touchmove: INPUT_MOVE,
|
2378 | touchend: INPUT_END,
|
2379 | touchcancel: INPUT_CANCEL
|
2380 | };
|
2381 | var TOUCH_TARGET_EVENTS = 'touchstart touchmove touchend touchcancel';
|
2382 | |
2383 |
|
2384 |
|
2385 |
|
2386 |
|
2387 |
|
2388 |
|
2389 | var TouchInput =
|
2390 |
|
2391 | function (_Input) {
|
2392 | _inheritsLoose(TouchInput, _Input);
|
2393 |
|
2394 | function TouchInput() {
|
2395 | var _this;
|
2396 |
|
2397 | TouchInput.prototype.evTarget = TOUCH_TARGET_EVENTS;
|
2398 | _this = _Input.apply(this, arguments) || this;
|
2399 | _this.targetIds = {};
|
2400 |
|
2401 | return _this;
|
2402 | }
|
2403 |
|
2404 | var _proto = TouchInput.prototype;
|
2405 |
|
2406 | _proto.handler = function handler(ev) {
|
2407 | var type = TOUCH_INPUT_MAP[ev.type];
|
2408 | var touches = getTouches.call(this, ev, type);
|
2409 |
|
2410 | if (!touches) {
|
2411 | return;
|
2412 | }
|
2413 |
|
2414 | this.callback(this.manager, type, {
|
2415 | pointers: touches[0],
|
2416 | changedPointers: touches[1],
|
2417 | pointerType: INPUT_TYPE_TOUCH,
|
2418 | srcEvent: ev
|
2419 | });
|
2420 | };
|
2421 |
|
2422 | return TouchInput;
|
2423 | }(Input);
|
2424 |
|
2425 | function getTouches(ev, type) {
|
2426 | var allTouches = toArray$2(ev.touches);
|
2427 | var targetIds = this.targetIds;
|
2428 |
|
2429 | if (type & (INPUT_START | INPUT_MOVE) && allTouches.length === 1) {
|
2430 | targetIds[allTouches[0].identifier] = true;
|
2431 | return [allTouches, allTouches];
|
2432 | }
|
2433 |
|
2434 | var i;
|
2435 | var targetTouches;
|
2436 | var changedTouches = toArray$2(ev.changedTouches);
|
2437 | var changedTargetTouches = [];
|
2438 | var target = this.target;
|
2439 |
|
2440 | targetTouches = allTouches.filter(function (touch) {
|
2441 | return hasParent(touch.target, target);
|
2442 | });
|
2443 |
|
2444 | if (type === INPUT_START) {
|
2445 | i = 0;
|
2446 |
|
2447 | while (i < targetTouches.length) {
|
2448 | targetIds[targetTouches[i].identifier] = true;
|
2449 | i++;
|
2450 | }
|
2451 | }
|
2452 |
|
2453 |
|
2454 | i = 0;
|
2455 |
|
2456 | while (i < changedTouches.length) {
|
2457 | if (targetIds[changedTouches[i].identifier]) {
|
2458 | changedTargetTouches.push(changedTouches[i]);
|
2459 | }
|
2460 |
|
2461 |
|
2462 | if (type & (INPUT_END | INPUT_CANCEL)) {
|
2463 | delete targetIds[changedTouches[i].identifier];
|
2464 | }
|
2465 |
|
2466 | i++;
|
2467 | }
|
2468 |
|
2469 | if (!changedTargetTouches.length) {
|
2470 | return;
|
2471 | }
|
2472 |
|
2473 | return [
|
2474 | uniqueArray(targetTouches.concat(changedTargetTouches), 'identifier', true), changedTargetTouches];
|
2475 | }
|
2476 |
|
2477 | var MOUSE_INPUT_MAP = {
|
2478 | mousedown: INPUT_START,
|
2479 | mousemove: INPUT_MOVE,
|
2480 | mouseup: INPUT_END
|
2481 | };
|
2482 | var MOUSE_ELEMENT_EVENTS = 'mousedown';
|
2483 | var MOUSE_WINDOW_EVENTS = 'mousemove mouseup';
|
2484 | |
2485 |
|
2486 |
|
2487 |
|
2488 |
|
2489 |
|
2490 |
|
2491 | var MouseInput =
|
2492 |
|
2493 | function (_Input) {
|
2494 | _inheritsLoose(MouseInput, _Input);
|
2495 |
|
2496 | function MouseInput() {
|
2497 | var _this;
|
2498 |
|
2499 | var proto = MouseInput.prototype;
|
2500 | proto.evEl = MOUSE_ELEMENT_EVENTS;
|
2501 | proto.evWin = MOUSE_WINDOW_EVENTS;
|
2502 | _this = _Input.apply(this, arguments) || this;
|
2503 | _this.pressed = false;
|
2504 |
|
2505 | return _this;
|
2506 | }
|
2507 | |
2508 |
|
2509 |
|
2510 |
|
2511 |
|
2512 |
|
2513 |
|
2514 | var _proto = MouseInput.prototype;
|
2515 |
|
2516 | _proto.handler = function handler(ev) {
|
2517 | var eventType = MOUSE_INPUT_MAP[ev.type];
|
2518 |
|
2519 | if (eventType & INPUT_START && ev.button === 0) {
|
2520 | this.pressed = true;
|
2521 | }
|
2522 |
|
2523 | if (eventType & INPUT_MOVE && ev.which !== 1) {
|
2524 | eventType = INPUT_END;
|
2525 | }
|
2526 |
|
2527 |
|
2528 | if (!this.pressed) {
|
2529 | return;
|
2530 | }
|
2531 |
|
2532 | if (eventType & INPUT_END) {
|
2533 | this.pressed = false;
|
2534 | }
|
2535 |
|
2536 | this.callback(this.manager, eventType, {
|
2537 | pointers: [ev],
|
2538 | changedPointers: [ev],
|
2539 | pointerType: INPUT_TYPE_MOUSE,
|
2540 | srcEvent: ev
|
2541 | });
|
2542 | };
|
2543 |
|
2544 | return MouseInput;
|
2545 | }(Input);
|
2546 |
|
2547 | |
2548 |
|
2549 |
|
2550 |
|
2551 |
|
2552 |
|
2553 |
|
2554 |
|
2555 |
|
2556 |
|
2557 |
|
2558 | var DEDUP_TIMEOUT = 2500;
|
2559 | var DEDUP_DISTANCE = 25;
|
2560 |
|
2561 | function setLastTouch(eventData) {
|
2562 | var _eventData$changedPoi = eventData.changedPointers,
|
2563 | touch = _eventData$changedPoi[0];
|
2564 |
|
2565 | if (touch.identifier === this.primaryTouch) {
|
2566 | var lastTouch = {
|
2567 | x: touch.clientX,
|
2568 | y: touch.clientY
|
2569 | };
|
2570 | var lts = this.lastTouches;
|
2571 | this.lastTouches.push(lastTouch);
|
2572 |
|
2573 | var removeLastTouch = function removeLastTouch() {
|
2574 | var i = lts.indexOf(lastTouch);
|
2575 |
|
2576 | if (i > -1) {
|
2577 | lts.splice(i, 1);
|
2578 | }
|
2579 | };
|
2580 |
|
2581 | setTimeout(removeLastTouch, DEDUP_TIMEOUT);
|
2582 | }
|
2583 | }
|
2584 |
|
2585 | function recordTouches(eventType, eventData) {
|
2586 | if (eventType & INPUT_START) {
|
2587 | this.primaryTouch = eventData.changedPointers[0].identifier;
|
2588 | setLastTouch.call(this, eventData);
|
2589 | } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
|
2590 | setLastTouch.call(this, eventData);
|
2591 | }
|
2592 | }
|
2593 |
|
2594 | function isSyntheticEvent(eventData) {
|
2595 | var x = eventData.srcEvent.clientX;
|
2596 | var y = eventData.srcEvent.clientY;
|
2597 |
|
2598 | for (var i = 0; i < this.lastTouches.length; i++) {
|
2599 | var t = this.lastTouches[i];
|
2600 | var dx = Math.abs(x - t.x);
|
2601 | var dy = Math.abs(y - t.y);
|
2602 |
|
2603 | if (dx <= DEDUP_DISTANCE && dy <= DEDUP_DISTANCE) {
|
2604 | return true;
|
2605 | }
|
2606 | }
|
2607 |
|
2608 | return false;
|
2609 | }
|
2610 |
|
2611 | var TouchMouseInput =
|
2612 |
|
2613 | function () {
|
2614 | var TouchMouseInput =
|
2615 |
|
2616 | function (_Input) {
|
2617 | _inheritsLoose(TouchMouseInput, _Input);
|
2618 |
|
2619 | function TouchMouseInput(_manager, callback) {
|
2620 | var _this;
|
2621 |
|
2622 | _this = _Input.call(this, _manager, callback) || this;
|
2623 |
|
2624 | _this.handler = function (manager, inputEvent, inputData) {
|
2625 | var isTouch = inputData.pointerType === INPUT_TYPE_TOUCH;
|
2626 | var isMouse = inputData.pointerType === INPUT_TYPE_MOUSE;
|
2627 |
|
2628 | if (isMouse && inputData.sourceCapabilities && inputData.sourceCapabilities.firesTouchEvents) {
|
2629 | return;
|
2630 | }
|
2631 |
|
2632 |
|
2633 | if (isTouch) {
|
2634 | recordTouches.call(_assertThisInitialized(_assertThisInitialized(_this)), inputEvent, inputData);
|
2635 | } else if (isMouse && isSyntheticEvent.call(_assertThisInitialized(_assertThisInitialized(_this)), inputData)) {
|
2636 | return;
|
2637 | }
|
2638 |
|
2639 | _this.callback(manager, inputEvent, inputData);
|
2640 | };
|
2641 |
|
2642 | _this.touch = new TouchInput(_this.manager, _this.handler);
|
2643 | _this.mouse = new MouseInput(_this.manager, _this.handler);
|
2644 | _this.primaryTouch = null;
|
2645 | _this.lastTouches = [];
|
2646 | return _this;
|
2647 | }
|
2648 | |
2649 |
|
2650 |
|
2651 |
|
2652 |
|
2653 |
|
2654 |
|
2655 |
|
2656 |
|
2657 | var _proto = TouchMouseInput.prototype;
|
2658 |
|
2659 | |
2660 |
|
2661 |
|
2662 |
|
2663 | _proto.destroy = function destroy() {
|
2664 | this.touch.destroy();
|
2665 | this.mouse.destroy();
|
2666 | };
|
2667 |
|
2668 | return TouchMouseInput;
|
2669 | }(Input);
|
2670 |
|
2671 | return TouchMouseInput;
|
2672 | }();
|
2673 |
|
2674 | |
2675 |
|
2676 |
|
2677 |
|
2678 |
|
2679 |
|
2680 |
|
2681 |
|
2682 | function createInputInstance(manager) {
|
2683 | var Type;
|
2684 |
|
2685 | var inputClass = manager.options.inputClass;
|
2686 |
|
2687 | if (inputClass) {
|
2688 | Type = inputClass;
|
2689 | } else if (SUPPORT_POINTER_EVENTS$1) {
|
2690 | Type = PointerEventInput;
|
2691 | } else if (SUPPORT_ONLY_TOUCH) {
|
2692 | Type = TouchInput;
|
2693 | } else if (!SUPPORT_TOUCH$1) {
|
2694 | Type = MouseInput;
|
2695 | } else {
|
2696 | Type = TouchMouseInput;
|
2697 | }
|
2698 |
|
2699 | return new Type(manager, inputHandler);
|
2700 | }
|
2701 |
|
2702 | |
2703 |
|
2704 |
|
2705 |
|
2706 |
|
2707 |
|
2708 |
|
2709 |
|
2710 |
|
2711 |
|
2712 |
|
2713 | function invokeArrayArg(arg, fn, context) {
|
2714 | if (Array.isArray(arg)) {
|
2715 | each(arg, context[fn], context);
|
2716 | return true;
|
2717 | }
|
2718 |
|
2719 | return false;
|
2720 | }
|
2721 |
|
2722 | var STATE_POSSIBLE = 1;
|
2723 | var STATE_BEGAN = 2;
|
2724 | var STATE_CHANGED = 4;
|
2725 | var STATE_ENDED = 8;
|
2726 | var STATE_RECOGNIZED = STATE_ENDED;
|
2727 | var STATE_CANCELLED = 16;
|
2728 | var STATE_FAILED = 32;
|
2729 |
|
2730 | |
2731 |
|
2732 |
|
2733 |
|
2734 |
|
2735 | var _uniqueId = 1;
|
2736 | function uniqueId() {
|
2737 | return _uniqueId++;
|
2738 | }
|
2739 |
|
2740 | |
2741 |
|
2742 |
|
2743 |
|
2744 |
|
2745 |
|
2746 |
|
2747 | function getRecognizerByNameIfManager(otherRecognizer, recognizer) {
|
2748 | var manager = recognizer.manager;
|
2749 |
|
2750 | if (manager) {
|
2751 | return manager.get(otherRecognizer);
|
2752 | }
|
2753 |
|
2754 | return otherRecognizer;
|
2755 | }
|
2756 |
|
2757 | |
2758 |
|
2759 |
|
2760 |
|
2761 |
|
2762 |
|
2763 |
|
2764 | function stateStr(state) {
|
2765 | if (state & STATE_CANCELLED) {
|
2766 | return 'cancel';
|
2767 | } else if (state & STATE_ENDED) {
|
2768 | return 'end';
|
2769 | } else if (state & STATE_CHANGED) {
|
2770 | return 'move';
|
2771 | } else if (state & STATE_BEGAN) {
|
2772 | return 'start';
|
2773 | }
|
2774 |
|
2775 | return '';
|
2776 | }
|
2777 |
|
2778 | |
2779 |
|
2780 |
|
2781 |
|
2782 |
|
2783 |
|
2784 |
|
2785 |
|
2786 |
|
2787 |
|
2788 |
|
2789 |
|
2790 |
|
2791 |
|
2792 |
|
2793 |
|
2794 |
|
2795 |
|
2796 |
|
2797 |
|
2798 |
|
2799 |
|
2800 |
|
2801 |
|
2802 |
|
2803 |
|
2804 |
|
2805 |
|
2806 |
|
2807 | |
2808 |
|
2809 |
|
2810 |
|
2811 |
|
2812 |
|
2813 |
|
2814 |
|
2815 | var Recognizer =
|
2816 |
|
2817 | function () {
|
2818 | function Recognizer(options) {
|
2819 | if (options === void 0) {
|
2820 | options = {};
|
2821 | }
|
2822 |
|
2823 | this.options = _extends({
|
2824 | enable: true
|
2825 | }, options);
|
2826 | this.id = uniqueId();
|
2827 | this.manager = null;
|
2828 |
|
2829 | this.state = STATE_POSSIBLE;
|
2830 | this.simultaneous = {};
|
2831 | this.requireFail = [];
|
2832 | }
|
2833 | |
2834 |
|
2835 |
|
2836 |
|
2837 |
|
2838 |
|
2839 |
|
2840 |
|
2841 | var _proto = Recognizer.prototype;
|
2842 |
|
2843 | _proto.set = function set(options) {
|
2844 | assign$1(this.options, options);
|
2845 |
|
2846 | this.manager && this.manager.touchAction.update();
|
2847 | return this;
|
2848 | };
|
2849 | |
2850 |
|
2851 |
|
2852 |
|
2853 |
|
2854 |
|
2855 |
|
2856 |
|
2857 | _proto.recognizeWith = function recognizeWith(otherRecognizer) {
|
2858 | if (invokeArrayArg(otherRecognizer, 'recognizeWith', this)) {
|
2859 | return this;
|
2860 | }
|
2861 |
|
2862 | var simultaneous = this.simultaneous;
|
2863 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
2864 |
|
2865 | if (!simultaneous[otherRecognizer.id]) {
|
2866 | simultaneous[otherRecognizer.id] = otherRecognizer;
|
2867 | otherRecognizer.recognizeWith(this);
|
2868 | }
|
2869 |
|
2870 | return this;
|
2871 | };
|
2872 | |
2873 |
|
2874 |
|
2875 |
|
2876 |
|
2877 |
|
2878 |
|
2879 |
|
2880 | _proto.dropRecognizeWith = function dropRecognizeWith(otherRecognizer) {
|
2881 | if (invokeArrayArg(otherRecognizer, 'dropRecognizeWith', this)) {
|
2882 | return this;
|
2883 | }
|
2884 |
|
2885 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
2886 | delete this.simultaneous[otherRecognizer.id];
|
2887 | return this;
|
2888 | };
|
2889 | |
2890 |
|
2891 |
|
2892 |
|
2893 |
|
2894 |
|
2895 |
|
2896 |
|
2897 | _proto.requireFailure = function requireFailure(otherRecognizer) {
|
2898 | if (invokeArrayArg(otherRecognizer, 'requireFailure', this)) {
|
2899 | return this;
|
2900 | }
|
2901 |
|
2902 | var requireFail = this.requireFail;
|
2903 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
2904 |
|
2905 | if (inArray(requireFail, otherRecognizer) === -1) {
|
2906 | requireFail.push(otherRecognizer);
|
2907 | otherRecognizer.requireFailure(this);
|
2908 | }
|
2909 |
|
2910 | return this;
|
2911 | };
|
2912 | |
2913 |
|
2914 |
|
2915 |
|
2916 |
|
2917 |
|
2918 |
|
2919 |
|
2920 | _proto.dropRequireFailure = function dropRequireFailure(otherRecognizer) {
|
2921 | if (invokeArrayArg(otherRecognizer, 'dropRequireFailure', this)) {
|
2922 | return this;
|
2923 | }
|
2924 |
|
2925 | otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
|
2926 | var index = inArray(this.requireFail, otherRecognizer);
|
2927 |
|
2928 | if (index > -1) {
|
2929 | this.requireFail.splice(index, 1);
|
2930 | }
|
2931 |
|
2932 | return this;
|
2933 | };
|
2934 | |
2935 |
|
2936 |
|
2937 |
|
2938 |
|
2939 |
|
2940 |
|
2941 | _proto.hasRequireFailures = function hasRequireFailures() {
|
2942 | return this.requireFail.length > 0;
|
2943 | };
|
2944 | |
2945 |
|
2946 |
|
2947 |
|
2948 |
|
2949 |
|
2950 |
|
2951 |
|
2952 | _proto.canRecognizeWith = function canRecognizeWith(otherRecognizer) {
|
2953 | return !!this.simultaneous[otherRecognizer.id];
|
2954 | };
|
2955 | |
2956 |
|
2957 |
|
2958 |
|
2959 |
|
2960 |
|
2961 |
|
2962 |
|
2963 | _proto.emit = function emit(input) {
|
2964 | var self = this;
|
2965 | var state = this.state;
|
2966 |
|
2967 | function emit(event) {
|
2968 | self.manager.emit(event, input);
|
2969 | }
|
2970 |
|
2971 |
|
2972 | if (state < STATE_ENDED) {
|
2973 | emit(self.options.event + stateStr(state));
|
2974 | }
|
2975 |
|
2976 | emit(self.options.event);
|
2977 |
|
2978 | if (input.additionalEvent) {
|
2979 |
|
2980 | emit(input.additionalEvent);
|
2981 | }
|
2982 |
|
2983 |
|
2984 | if (state >= STATE_ENDED) {
|
2985 | emit(self.options.event + stateStr(state));
|
2986 | }
|
2987 | };
|
2988 | |
2989 |
|
2990 |
|
2991 |
|
2992 |
|
2993 |
|
2994 |
|
2995 |
|
2996 |
|
2997 | _proto.tryEmit = function tryEmit(input) {
|
2998 | if (this.canEmit()) {
|
2999 | return this.emit(input);
|
3000 | }
|
3001 |
|
3002 |
|
3003 | this.state = STATE_FAILED;
|
3004 | };
|
3005 | |
3006 |
|
3007 |
|
3008 |
|
3009 |
|
3010 |
|
3011 |
|
3012 | _proto.canEmit = function canEmit() {
|
3013 | var i = 0;
|
3014 |
|
3015 | while (i < this.requireFail.length) {
|
3016 | if (!(this.requireFail[i].state & (STATE_FAILED | STATE_POSSIBLE))) {
|
3017 | return false;
|
3018 | }
|
3019 |
|
3020 | i++;
|
3021 | }
|
3022 |
|
3023 | return true;
|
3024 | };
|
3025 | |
3026 |
|
3027 |
|
3028 |
|
3029 |
|
3030 |
|
3031 |
|
3032 | _proto.recognize = function recognize(inputData) {
|
3033 |
|
3034 |
|
3035 | var inputDataClone = assign$1({}, inputData);
|
3036 |
|
3037 | if (!boolOrFn(this.options.enable, [this, inputDataClone])) {
|
3038 | this.reset();
|
3039 | this.state = STATE_FAILED;
|
3040 | return;
|
3041 | }
|
3042 |
|
3043 |
|
3044 | if (this.state & (STATE_RECOGNIZED | STATE_CANCELLED | STATE_FAILED)) {
|
3045 | this.state = STATE_POSSIBLE;
|
3046 | }
|
3047 |
|
3048 | this.state = this.process(inputDataClone);
|
3049 |
|
3050 |
|
3051 | if (this.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED | STATE_CANCELLED)) {
|
3052 | this.tryEmit(inputDataClone);
|
3053 | }
|
3054 | };
|
3055 | |
3056 |
|
3057 |
|
3058 |
|
3059 |
|
3060 |
|
3061 |
|
3062 |
|
3063 |
|
3064 |
|
3065 |
|
3066 |
|
3067 | _proto.process = function process(inputData) {};
|
3068 |
|
3069 |
|
3070 | |
3071 |
|
3072 |
|
3073 |
|
3074 |
|
3075 |
|
3076 |
|
3077 |
|
3078 | _proto.getTouchAction = function getTouchAction() {};
|
3079 | |
3080 |
|
3081 |
|
3082 |
|
3083 |
|
3084 |
|
3085 |
|
3086 |
|
3087 | _proto.reset = function reset() {};
|
3088 |
|
3089 | return Recognizer;
|
3090 | }();
|
3091 |
|
3092 | |
3093 |
|
3094 |
|
3095 |
|
3096 |
|
3097 |
|
3098 |
|
3099 |
|
3100 |
|
3101 |
|
3102 |
|
3103 |
|
3104 | var TapRecognizer =
|
3105 |
|
3106 | function (_Recognizer) {
|
3107 | _inheritsLoose(TapRecognizer, _Recognizer);
|
3108 |
|
3109 | function TapRecognizer(options) {
|
3110 | var _this;
|
3111 |
|
3112 | if (options === void 0) {
|
3113 | options = {};
|
3114 | }
|
3115 |
|
3116 | _this = _Recognizer.call(this, _extends({
|
3117 | event: 'tap',
|
3118 | pointers: 1,
|
3119 | taps: 1,
|
3120 | interval: 300,
|
3121 |
|
3122 | time: 250,
|
3123 |
|
3124 | threshold: 9,
|
3125 |
|
3126 | posThreshold: 10
|
3127 | }, options)) || this;
|
3128 |
|
3129 |
|
3130 | _this.pTime = false;
|
3131 | _this.pCenter = false;
|
3132 | _this._timer = null;
|
3133 | _this._input = null;
|
3134 | _this.count = 0;
|
3135 | return _this;
|
3136 | }
|
3137 |
|
3138 | var _proto = TapRecognizer.prototype;
|
3139 |
|
3140 | _proto.getTouchAction = function getTouchAction() {
|
3141 | return [TOUCH_ACTION_MANIPULATION];
|
3142 | };
|
3143 |
|
3144 | _proto.process = function process(input) {
|
3145 | var _this2 = this;
|
3146 |
|
3147 | var options = this.options;
|
3148 | var validPointers = input.pointers.length === options.pointers;
|
3149 | var validMovement = input.distance < options.threshold;
|
3150 | var validTouchTime = input.deltaTime < options.time;
|
3151 | this.reset();
|
3152 |
|
3153 | if (input.eventType & INPUT_START && this.count === 0) {
|
3154 | return this.failTimeout();
|
3155 | }
|
3156 |
|
3157 |
|
3158 |
|
3159 | if (validMovement && validTouchTime && validPointers) {
|
3160 | if (input.eventType !== INPUT_END) {
|
3161 | return this.failTimeout();
|
3162 | }
|
3163 |
|
3164 | var validInterval = this.pTime ? input.timeStamp - this.pTime < options.interval : true;
|
3165 | var validMultiTap = !this.pCenter || getDistance(this.pCenter, input.center) < options.posThreshold;
|
3166 | this.pTime = input.timeStamp;
|
3167 | this.pCenter = input.center;
|
3168 |
|
3169 | if (!validMultiTap || !validInterval) {
|
3170 | this.count = 1;
|
3171 | } else {
|
3172 | this.count += 1;
|
3173 | }
|
3174 |
|
3175 | this._input = input;
|
3176 |
|
3177 |
|
3178 | var tapCount = this.count % options.taps;
|
3179 |
|
3180 | if (tapCount === 0) {
|
3181 |
|
3182 |
|
3183 | if (!this.hasRequireFailures()) {
|
3184 | return STATE_RECOGNIZED;
|
3185 | } else {
|
3186 | this._timer = setTimeout(function () {
|
3187 | _this2.state = STATE_RECOGNIZED;
|
3188 |
|
3189 | _this2.tryEmit();
|
3190 | }, options.interval);
|
3191 | return STATE_BEGAN;
|
3192 | }
|
3193 | }
|
3194 | }
|
3195 |
|
3196 | return STATE_FAILED;
|
3197 | };
|
3198 |
|
3199 | _proto.failTimeout = function failTimeout() {
|
3200 | var _this3 = this;
|
3201 |
|
3202 | this._timer = setTimeout(function () {
|
3203 | _this3.state = STATE_FAILED;
|
3204 | }, this.options.interval);
|
3205 | return STATE_FAILED;
|
3206 | };
|
3207 |
|
3208 | _proto.reset = function reset() {
|
3209 | clearTimeout(this._timer);
|
3210 | };
|
3211 |
|
3212 | _proto.emit = function emit() {
|
3213 | if (this.state === STATE_RECOGNIZED) {
|
3214 | this._input.tapCount = this.count;
|
3215 | this.manager.emit(this.options.event, this._input);
|
3216 | }
|
3217 | };
|
3218 |
|
3219 | return TapRecognizer;
|
3220 | }(Recognizer);
|
3221 |
|
3222 | |
3223 |
|
3224 |
|
3225 |
|
3226 |
|
3227 |
|
3228 |
|
3229 | var AttrRecognizer =
|
3230 |
|
3231 | function (_Recognizer) {
|
3232 | _inheritsLoose(AttrRecognizer, _Recognizer);
|
3233 |
|
3234 | function AttrRecognizer(options) {
|
3235 | if (options === void 0) {
|
3236 | options = {};
|
3237 | }
|
3238 |
|
3239 | return _Recognizer.call(this, _extends({
|
3240 | pointers: 1
|
3241 | }, options)) || this;
|
3242 | }
|
3243 | |
3244 |
|
3245 |
|
3246 |
|
3247 |
|
3248 |
|
3249 |
|
3250 |
|
3251 |
|
3252 | var _proto = AttrRecognizer.prototype;
|
3253 |
|
3254 | _proto.attrTest = function attrTest(input) {
|
3255 | var optionPointers = this.options.pointers;
|
3256 | return optionPointers === 0 || input.pointers.length === optionPointers;
|
3257 | };
|
3258 | |
3259 |
|
3260 |
|
3261 |
|
3262 |
|
3263 |
|
3264 |
|
3265 |
|
3266 |
|
3267 | _proto.process = function process(input) {
|
3268 | var state = this.state;
|
3269 | var eventType = input.eventType;
|
3270 | var isRecognized = state & (STATE_BEGAN | STATE_CHANGED);
|
3271 | var isValid = this.attrTest(input);
|
3272 |
|
3273 | if (isRecognized && (eventType & INPUT_CANCEL || !isValid)) {
|
3274 | return state | STATE_CANCELLED;
|
3275 | } else if (isRecognized || isValid) {
|
3276 | if (eventType & INPUT_END) {
|
3277 | return state | STATE_ENDED;
|
3278 | } else if (!(state & STATE_BEGAN)) {
|
3279 | return STATE_BEGAN;
|
3280 | }
|
3281 |
|
3282 | return state | STATE_CHANGED;
|
3283 | }
|
3284 |
|
3285 | return STATE_FAILED;
|
3286 | };
|
3287 |
|
3288 | return AttrRecognizer;
|
3289 | }(Recognizer);
|
3290 |
|
3291 | |
3292 |
|
3293 |
|
3294 |
|
3295 |
|
3296 |
|
3297 |
|
3298 | function directionStr(direction) {
|
3299 | if (direction === DIRECTION_DOWN) {
|
3300 | return 'down';
|
3301 | } else if (direction === DIRECTION_UP) {
|
3302 | return 'up';
|
3303 | } else if (direction === DIRECTION_LEFT) {
|
3304 | return 'left';
|
3305 | } else if (direction === DIRECTION_RIGHT) {
|
3306 | return 'right';
|
3307 | }
|
3308 |
|
3309 | return '';
|
3310 | }
|
3311 |
|
3312 | |
3313 |
|
3314 |
|
3315 |
|
3316 |
|
3317 |
|
3318 |
|
3319 |
|
3320 | var PanRecognizer =
|
3321 |
|
3322 | function (_AttrRecognizer) {
|
3323 | _inheritsLoose(PanRecognizer, _AttrRecognizer);
|
3324 |
|
3325 | function PanRecognizer(options) {
|
3326 | var _this;
|
3327 |
|
3328 | if (options === void 0) {
|
3329 | options = {};
|
3330 | }
|
3331 |
|
3332 | _this = _AttrRecognizer.call(this, _extends({
|
3333 | event: 'pan',
|
3334 | threshold: 10,
|
3335 | pointers: 1,
|
3336 | direction: DIRECTION_ALL
|
3337 | }, options)) || this;
|
3338 | _this.pX = null;
|
3339 | _this.pY = null;
|
3340 | return _this;
|
3341 | }
|
3342 |
|
3343 | var _proto = PanRecognizer.prototype;
|
3344 |
|
3345 | _proto.getTouchAction = function getTouchAction() {
|
3346 | var direction = this.options.direction;
|
3347 | var actions = [];
|
3348 |
|
3349 | if (direction & DIRECTION_HORIZONTAL) {
|
3350 | actions.push(TOUCH_ACTION_PAN_Y);
|
3351 | }
|
3352 |
|
3353 | if (direction & DIRECTION_VERTICAL) {
|
3354 | actions.push(TOUCH_ACTION_PAN_X);
|
3355 | }
|
3356 |
|
3357 | return actions;
|
3358 | };
|
3359 |
|
3360 | _proto.directionTest = function directionTest(input) {
|
3361 | var options = this.options;
|
3362 | var hasMoved = true;
|
3363 | var distance = input.distance;
|
3364 | var direction = input.direction;
|
3365 | var x = input.deltaX;
|
3366 | var y = input.deltaY;
|
3367 |
|
3368 | if (!(direction & options.direction)) {
|
3369 | if (options.direction & DIRECTION_HORIZONTAL) {
|
3370 | direction = x === 0 ? DIRECTION_NONE : x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
3371 | hasMoved = x !== this.pX;
|
3372 | distance = Math.abs(input.deltaX);
|
3373 | } else {
|
3374 | direction = y === 0 ? DIRECTION_NONE : y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
|
3375 | hasMoved = y !== this.pY;
|
3376 | distance = Math.abs(input.deltaY);
|
3377 | }
|
3378 | }
|
3379 |
|
3380 | input.direction = direction;
|
3381 | return hasMoved && distance > options.threshold && direction & options.direction;
|
3382 | };
|
3383 |
|
3384 | _proto.attrTest = function attrTest(input) {
|
3385 | return AttrRecognizer.prototype.attrTest.call(this, input) && (
|
3386 | this.state & STATE_BEGAN || !(this.state & STATE_BEGAN) && this.directionTest(input));
|
3387 | };
|
3388 |
|
3389 | _proto.emit = function emit(input) {
|
3390 | this.pX = input.deltaX;
|
3391 | this.pY = input.deltaY;
|
3392 | var direction = directionStr(input.direction);
|
3393 |
|
3394 | if (direction) {
|
3395 | input.additionalEvent = this.options.event + direction;
|
3396 | }
|
3397 |
|
3398 | _AttrRecognizer.prototype.emit.call(this, input);
|
3399 | };
|
3400 |
|
3401 | return PanRecognizer;
|
3402 | }(AttrRecognizer);
|
3403 |
|
3404 | |
3405 |
|
3406 |
|
3407 |
|
3408 |
|
3409 |
|
3410 |
|
3411 |
|
3412 | var SwipeRecognizer =
|
3413 |
|
3414 | function (_AttrRecognizer) {
|
3415 | _inheritsLoose(SwipeRecognizer, _AttrRecognizer);
|
3416 |
|
3417 | function SwipeRecognizer(options) {
|
3418 | if (options === void 0) {
|
3419 | options = {};
|
3420 | }
|
3421 |
|
3422 | return _AttrRecognizer.call(this, _extends({
|
3423 | event: 'swipe',
|
3424 | threshold: 10,
|
3425 | velocity: 0.3,
|
3426 | direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL,
|
3427 | pointers: 1
|
3428 | }, options)) || this;
|
3429 | }
|
3430 |
|
3431 | var _proto = SwipeRecognizer.prototype;
|
3432 |
|
3433 | _proto.getTouchAction = function getTouchAction() {
|
3434 | return PanRecognizer.prototype.getTouchAction.call(this);
|
3435 | };
|
3436 |
|
3437 | _proto.attrTest = function attrTest(input) {
|
3438 | var direction = this.options.direction;
|
3439 | var velocity;
|
3440 |
|
3441 | if (direction & (DIRECTION_HORIZONTAL | DIRECTION_VERTICAL)) {
|
3442 | velocity = input.overallVelocity;
|
3443 | } else if (direction & DIRECTION_HORIZONTAL) {
|
3444 | velocity = input.overallVelocityX;
|
3445 | } else if (direction & DIRECTION_VERTICAL) {
|
3446 | velocity = input.overallVelocityY;
|
3447 | }
|
3448 |
|
3449 | return _AttrRecognizer.prototype.attrTest.call(this, input) && direction & input.offsetDirection && input.distance > this.options.threshold && input.maxPointers === this.options.pointers && abs(velocity) > this.options.velocity && input.eventType & INPUT_END;
|
3450 | };
|
3451 |
|
3452 | _proto.emit = function emit(input) {
|
3453 | var direction = directionStr(input.offsetDirection);
|
3454 |
|
3455 | if (direction) {
|
3456 | this.manager.emit(this.options.event + direction, input);
|
3457 | }
|
3458 |
|
3459 | this.manager.emit(this.options.event, input);
|
3460 | };
|
3461 |
|
3462 | return SwipeRecognizer;
|
3463 | }(AttrRecognizer);
|
3464 |
|
3465 | |
3466 |
|
3467 |
|
3468 |
|
3469 |
|
3470 |
|
3471 |
|
3472 |
|
3473 | var PinchRecognizer =
|
3474 |
|
3475 | function (_AttrRecognizer) {
|
3476 | _inheritsLoose(PinchRecognizer, _AttrRecognizer);
|
3477 |
|
3478 | function PinchRecognizer(options) {
|
3479 | if (options === void 0) {
|
3480 | options = {};
|
3481 | }
|
3482 |
|
3483 | return _AttrRecognizer.call(this, _extends({
|
3484 | event: 'pinch',
|
3485 | threshold: 0,
|
3486 | pointers: 2
|
3487 | }, options)) || this;
|
3488 | }
|
3489 |
|
3490 | var _proto = PinchRecognizer.prototype;
|
3491 |
|
3492 | _proto.getTouchAction = function getTouchAction() {
|
3493 | return [TOUCH_ACTION_NONE];
|
3494 | };
|
3495 |
|
3496 | _proto.attrTest = function attrTest(input) {
|
3497 | return _AttrRecognizer.prototype.attrTest.call(this, input) && (Math.abs(input.scale - 1) > this.options.threshold || this.state & STATE_BEGAN);
|
3498 | };
|
3499 |
|
3500 | _proto.emit = function emit(input) {
|
3501 | if (input.scale !== 1) {
|
3502 | var inOut = input.scale < 1 ? 'in' : 'out';
|
3503 | input.additionalEvent = this.options.event + inOut;
|
3504 | }
|
3505 |
|
3506 | _AttrRecognizer.prototype.emit.call(this, input);
|
3507 | };
|
3508 |
|
3509 | return PinchRecognizer;
|
3510 | }(AttrRecognizer);
|
3511 |
|
3512 | |
3513 |
|
3514 |
|
3515 |
|
3516 |
|
3517 |
|
3518 |
|
3519 |
|
3520 | var RotateRecognizer =
|
3521 |
|
3522 | function (_AttrRecognizer) {
|
3523 | _inheritsLoose(RotateRecognizer, _AttrRecognizer);
|
3524 |
|
3525 | function RotateRecognizer(options) {
|
3526 | if (options === void 0) {
|
3527 | options = {};
|
3528 | }
|
3529 |
|
3530 | return _AttrRecognizer.call(this, _extends({
|
3531 | event: 'rotate',
|
3532 | threshold: 0,
|
3533 | pointers: 2
|
3534 | }, options)) || this;
|
3535 | }
|
3536 |
|
3537 | var _proto = RotateRecognizer.prototype;
|
3538 |
|
3539 | _proto.getTouchAction = function getTouchAction() {
|
3540 | return [TOUCH_ACTION_NONE];
|
3541 | };
|
3542 |
|
3543 | _proto.attrTest = function attrTest(input) {
|
3544 | return _AttrRecognizer.prototype.attrTest.call(this, input) && (Math.abs(input.rotation) > this.options.threshold || this.state & STATE_BEGAN);
|
3545 | };
|
3546 |
|
3547 | return RotateRecognizer;
|
3548 | }(AttrRecognizer);
|
3549 |
|
3550 | |
3551 |
|
3552 |
|
3553 |
|
3554 |
|
3555 |
|
3556 |
|
3557 |
|
3558 | var PressRecognizer =
|
3559 |
|
3560 | function (_Recognizer) {
|
3561 | _inheritsLoose(PressRecognizer, _Recognizer);
|
3562 |
|
3563 | function PressRecognizer(options) {
|
3564 | var _this;
|
3565 |
|
3566 | if (options === void 0) {
|
3567 | options = {};
|
3568 | }
|
3569 |
|
3570 | _this = _Recognizer.call(this, _extends({
|
3571 | event: 'press',
|
3572 | pointers: 1,
|
3573 | time: 251,
|
3574 |
|
3575 | threshold: 9
|
3576 | }, options)) || this;
|
3577 | _this._timer = null;
|
3578 | _this._input = null;
|
3579 | return _this;
|
3580 | }
|
3581 |
|
3582 | var _proto = PressRecognizer.prototype;
|
3583 |
|
3584 | _proto.getTouchAction = function getTouchAction() {
|
3585 | return [TOUCH_ACTION_AUTO];
|
3586 | };
|
3587 |
|
3588 | _proto.process = function process(input) {
|
3589 | var _this2 = this;
|
3590 |
|
3591 | var options = this.options;
|
3592 | var validPointers = input.pointers.length === options.pointers;
|
3593 | var validMovement = input.distance < options.threshold;
|
3594 | var validTime = input.deltaTime > options.time;
|
3595 | this._input = input;
|
3596 |
|
3597 |
|
3598 | if (!validMovement || !validPointers || input.eventType & (INPUT_END | INPUT_CANCEL) && !validTime) {
|
3599 | this.reset();
|
3600 | } else if (input.eventType & INPUT_START) {
|
3601 | this.reset();
|
3602 | this._timer = setTimeout(function () {
|
3603 | _this2.state = STATE_RECOGNIZED;
|
3604 |
|
3605 | _this2.tryEmit();
|
3606 | }, options.time);
|
3607 | } else if (input.eventType & INPUT_END) {
|
3608 | return STATE_RECOGNIZED;
|
3609 | }
|
3610 |
|
3611 | return STATE_FAILED;
|
3612 | };
|
3613 |
|
3614 | _proto.reset = function reset() {
|
3615 | clearTimeout(this._timer);
|
3616 | };
|
3617 |
|
3618 | _proto.emit = function emit(input) {
|
3619 | if (this.state !== STATE_RECOGNIZED) {
|
3620 | return;
|
3621 | }
|
3622 |
|
3623 | if (input && input.eventType & INPUT_END) {
|
3624 | this.manager.emit(this.options.event + "up", input);
|
3625 | } else {
|
3626 | this._input.timeStamp = now();
|
3627 | this.manager.emit(this.options.event, this._input);
|
3628 | }
|
3629 | };
|
3630 |
|
3631 | return PressRecognizer;
|
3632 | }(Recognizer);
|
3633 |
|
3634 | var defaults = {
|
3635 | |
3636 |
|
3637 |
|
3638 |
|
3639 |
|
3640 |
|
3641 |
|
3642 | domEvents: false,
|
3643 |
|
3644 | |
3645 |
|
3646 |
|
3647 |
|
3648 |
|
3649 |
|
3650 |
|
3651 | touchAction: TOUCH_ACTION_COMPUTE,
|
3652 |
|
3653 | |
3654 |
|
3655 |
|
3656 |
|
3657 |
|
3658 | enable: true,
|
3659 |
|
3660 | |
3661 |
|
3662 |
|
3663 |
|
3664 |
|
3665 |
|
3666 |
|
3667 |
|
3668 | inputTarget: null,
|
3669 |
|
3670 | |
3671 |
|
3672 |
|
3673 |
|
3674 |
|
3675 |
|
3676 | inputClass: null,
|
3677 |
|
3678 | |
3679 |
|
3680 |
|
3681 |
|
3682 |
|
3683 |
|
3684 | cssProps: {
|
3685 | |
3686 |
|
3687 |
|
3688 |
|
3689 |
|
3690 |
|
3691 | userSelect: "none",
|
3692 |
|
3693 | |
3694 |
|
3695 |
|
3696 |
|
3697 |
|
3698 |
|
3699 | touchSelect: "none",
|
3700 |
|
3701 | |
3702 |
|
3703 |
|
3704 |
|
3705 |
|
3706 |
|
3707 |
|
3708 |
|
3709 | touchCallout: "none",
|
3710 |
|
3711 | |
3712 |
|
3713 |
|
3714 |
|
3715 |
|
3716 |
|
3717 | contentZooming: "none",
|
3718 |
|
3719 | |
3720 |
|
3721 |
|
3722 |
|
3723 |
|
3724 |
|
3725 | userDrag: "none",
|
3726 |
|
3727 | |
3728 |
|
3729 |
|
3730 |
|
3731 |
|
3732 |
|
3733 |
|
3734 | tapHighlightColor: "rgba(0,0,0,0)"
|
3735 | }
|
3736 | };
|
3737 | |
3738 |
|
3739 |
|
3740 |
|
3741 |
|
3742 |
|
3743 |
|
3744 |
|
3745 | var preset = [[RotateRecognizer, {
|
3746 | enable: false
|
3747 | }], [PinchRecognizer, {
|
3748 | enable: false
|
3749 | }, ['rotate']], [SwipeRecognizer, {
|
3750 | direction: DIRECTION_HORIZONTAL
|
3751 | }], [PanRecognizer, {
|
3752 | direction: DIRECTION_HORIZONTAL
|
3753 | }, ['swipe']], [TapRecognizer], [TapRecognizer, {
|
3754 | event: 'doubletap',
|
3755 | taps: 2
|
3756 | }, ['tap']], [PressRecognizer]];
|
3757 |
|
3758 | var STOP = 1;
|
3759 | var FORCED_STOP = 2;
|
3760 | |
3761 |
|
3762 |
|
3763 |
|
3764 |
|
3765 |
|
3766 |
|
3767 | function toggleCssProps(manager, add) {
|
3768 | var element = manager.element;
|
3769 |
|
3770 | if (!element.style) {
|
3771 | return;
|
3772 | }
|
3773 |
|
3774 | var prop;
|
3775 | each(manager.options.cssProps, function (value, name) {
|
3776 | prop = prefixed(element.style, name);
|
3777 |
|
3778 | if (add) {
|
3779 | manager.oldCssProps[prop] = element.style[prop];
|
3780 | element.style[prop] = value;
|
3781 | } else {
|
3782 | element.style[prop] = manager.oldCssProps[prop] || "";
|
3783 | }
|
3784 | });
|
3785 |
|
3786 | if (!add) {
|
3787 | manager.oldCssProps = {};
|
3788 | }
|
3789 | }
|
3790 | |
3791 |
|
3792 |
|
3793 |
|
3794 |
|
3795 |
|
3796 |
|
3797 |
|
3798 | function triggerDomEvent(event, data) {
|
3799 | var gestureEvent = document.createEvent("Event");
|
3800 | gestureEvent.initEvent(event, true, true);
|
3801 | gestureEvent.gesture = data;
|
3802 | data.target.dispatchEvent(gestureEvent);
|
3803 | }
|
3804 | |
3805 |
|
3806 |
|
3807 |
|
3808 |
|
3809 |
|
3810 |
|
3811 |
|
3812 |
|
3813 | var Manager =
|
3814 |
|
3815 | function () {
|
3816 | function Manager(element, options) {
|
3817 | var _this = this;
|
3818 |
|
3819 | this.options = assign$1({}, defaults, options || {});
|
3820 | this.options.inputTarget = this.options.inputTarget || element;
|
3821 | this.handlers = {};
|
3822 | this.session = {};
|
3823 | this.recognizers = [];
|
3824 | this.oldCssProps = {};
|
3825 | this.element = element;
|
3826 | this.input = createInputInstance(this);
|
3827 | this.touchAction = new TouchAction(this, this.options.touchAction);
|
3828 | toggleCssProps(this, true);
|
3829 | each(this.options.recognizers, function (item) {
|
3830 | var recognizer = _this.add(new item[0](item[1]));
|
3831 |
|
3832 | item[2] && recognizer.recognizeWith(item[2]);
|
3833 | item[3] && recognizer.requireFailure(item[3]);
|
3834 | }, this);
|
3835 | }
|
3836 | |
3837 |
|
3838 |
|
3839 |
|
3840 |
|
3841 |
|
3842 |
|
3843 |
|
3844 | var _proto = Manager.prototype;
|
3845 |
|
3846 | _proto.set = function set(options) {
|
3847 | assign$1(this.options, options);
|
3848 |
|
3849 | if (options.touchAction) {
|
3850 | this.touchAction.update();
|
3851 | }
|
3852 |
|
3853 | if (options.inputTarget) {
|
3854 |
|
3855 | this.input.destroy();
|
3856 | this.input.target = options.inputTarget;
|
3857 | this.input.init();
|
3858 | }
|
3859 |
|
3860 | return this;
|
3861 | };
|
3862 | |
3863 |
|
3864 |
|
3865 |
|
3866 |
|
3867 |
|
3868 |
|
3869 |
|
3870 |
|
3871 | _proto.stop = function stop(force) {
|
3872 | this.session.stopped = force ? FORCED_STOP : STOP;
|
3873 | };
|
3874 | |
3875 |
|
3876 |
|
3877 |
|
3878 |
|
3879 |
|
3880 |
|
3881 |
|
3882 |
|
3883 | _proto.recognize = function recognize(inputData) {
|
3884 | var session = this.session;
|
3885 |
|
3886 | if (session.stopped) {
|
3887 | return;
|
3888 | }
|
3889 |
|
3890 |
|
3891 | this.touchAction.preventDefaults(inputData);
|
3892 | var recognizer;
|
3893 | var recognizers = this.recognizers;
|
3894 |
|
3895 |
|
3896 |
|
3897 | var curRecognizer = session.curRecognizer;
|
3898 |
|
3899 |
|
3900 | if (!curRecognizer || curRecognizer && curRecognizer.state & STATE_RECOGNIZED) {
|
3901 | session.curRecognizer = null;
|
3902 | curRecognizer = null;
|
3903 | }
|
3904 |
|
3905 | var i = 0;
|
3906 |
|
3907 | while (i < recognizers.length) {
|
3908 | recognizer = recognizers[i];
|
3909 |
|
3910 |
|
3911 |
|
3912 |
|
3913 |
|
3914 |
|
3915 | if (session.stopped !== FORCED_STOP && (
|
3916 | !curRecognizer || recognizer === curRecognizer ||
|
3917 | recognizer.canRecognizeWith(curRecognizer))) {
|
3918 |
|
3919 | recognizer.recognize(inputData);
|
3920 | } else {
|
3921 | recognizer.reset();
|
3922 | }
|
3923 |
|
3924 |
|
3925 |
|
3926 | if (!curRecognizer && recognizer.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED)) {
|
3927 | session.curRecognizer = recognizer;
|
3928 | curRecognizer = recognizer;
|
3929 | }
|
3930 |
|
3931 | i++;
|
3932 | }
|
3933 | };
|
3934 | |
3935 |
|
3936 |
|
3937 |
|
3938 |
|
3939 |
|
3940 |
|
3941 |
|
3942 | _proto.get = function get(recognizer) {
|
3943 | if (recognizer instanceof Recognizer) {
|
3944 | return recognizer;
|
3945 | }
|
3946 |
|
3947 | var recognizers = this.recognizers;
|
3948 |
|
3949 | for (var i = 0; i < recognizers.length; i++) {
|
3950 | if (recognizers[i].options.event === recognizer) {
|
3951 | return recognizers[i];
|
3952 | }
|
3953 | }
|
3954 |
|
3955 | return null;
|
3956 | };
|
3957 | |
3958 |
|
3959 |
|
3960 |
|
3961 |
|
3962 |
|
3963 |
|
3964 |
|
3965 | _proto.add = function add(recognizer) {
|
3966 | if (invokeArrayArg(recognizer, "add", this)) {
|
3967 | return this;
|
3968 | }
|
3969 |
|
3970 |
|
3971 | var existing = this.get(recognizer.options.event);
|
3972 |
|
3973 | if (existing) {
|
3974 | this.remove(existing);
|
3975 | }
|
3976 |
|
3977 | this.recognizers.push(recognizer);
|
3978 | recognizer.manager = this;
|
3979 | this.touchAction.update();
|
3980 | return recognizer;
|
3981 | };
|
3982 | |
3983 |
|
3984 |
|
3985 |
|
3986 |
|
3987 |
|
3988 |
|
3989 |
|
3990 | _proto.remove = function remove(recognizer) {
|
3991 | if (invokeArrayArg(recognizer, "remove", this)) {
|
3992 | return this;
|
3993 | }
|
3994 |
|
3995 | var targetRecognizer = this.get(recognizer);
|
3996 |
|
3997 | if (recognizer) {
|
3998 | var recognizers = this.recognizers;
|
3999 | var index = inArray(recognizers, targetRecognizer);
|
4000 |
|
4001 | if (index !== -1) {
|
4002 | recognizers.splice(index, 1);
|
4003 | this.touchAction.update();
|
4004 | }
|
4005 | }
|
4006 |
|
4007 | return this;
|
4008 | };
|
4009 | |
4010 |
|
4011 |
|
4012 |
|
4013 |
|
4014 |
|
4015 |
|
4016 |
|
4017 |
|
4018 | _proto.on = function on(events, handler) {
|
4019 | if (events === undefined || handler === undefined) {
|
4020 | return this;
|
4021 | }
|
4022 |
|
4023 | var handlers = this.handlers;
|
4024 | each(splitStr(events), function (event) {
|
4025 | handlers[event] = handlers[event] || [];
|
4026 | handlers[event].push(handler);
|
4027 | });
|
4028 | return this;
|
4029 | };
|
4030 | |
4031 |
|
4032 |
|
4033 |
|
4034 |
|
4035 |
|
4036 |
|
4037 |
|
4038 | _proto.off = function off(events, handler) {
|
4039 | if (events === undefined) {
|
4040 | return this;
|
4041 | }
|
4042 |
|
4043 | var handlers = this.handlers;
|
4044 | each(splitStr(events), function (event) {
|
4045 | if (!handler) {
|
4046 | delete handlers[event];
|
4047 | } else {
|
4048 | handlers[event] && handlers[event].splice(inArray(handlers[event], handler), 1);
|
4049 | }
|
4050 | });
|
4051 | return this;
|
4052 | };
|
4053 | |
4054 |
|
4055 |
|
4056 |
|
4057 |
|
4058 |
|
4059 |
|
4060 | _proto.emit = function emit(event, data) {
|
4061 |
|
4062 | if (this.options.domEvents) {
|
4063 | triggerDomEvent(event, data);
|
4064 | }
|
4065 |
|
4066 |
|
4067 | var handlers = this.handlers[event] && this.handlers[event].slice();
|
4068 |
|
4069 | if (!handlers || !handlers.length) {
|
4070 | return;
|
4071 | }
|
4072 |
|
4073 | data.type = event;
|
4074 |
|
4075 | data.preventDefault = function () {
|
4076 | data.srcEvent.preventDefault();
|
4077 | };
|
4078 |
|
4079 | var i = 0;
|
4080 |
|
4081 | while (i < handlers.length) {
|
4082 | handlers[i](data);
|
4083 | i++;
|
4084 | }
|
4085 | };
|
4086 | |
4087 |
|
4088 |
|
4089 |
|
4090 |
|
4091 |
|
4092 |
|
4093 | _proto.destroy = function destroy() {
|
4094 | this.element && toggleCssProps(this, false);
|
4095 | this.handlers = {};
|
4096 | this.session = {};
|
4097 | this.input.destroy();
|
4098 | this.element = null;
|
4099 | };
|
4100 |
|
4101 | return Manager;
|
4102 | }();
|
4103 |
|
4104 | var SINGLE_TOUCH_INPUT_MAP = {
|
4105 | touchstart: INPUT_START,
|
4106 | touchmove: INPUT_MOVE,
|
4107 | touchend: INPUT_END,
|
4108 | touchcancel: INPUT_CANCEL
|
4109 | };
|
4110 | var SINGLE_TOUCH_TARGET_EVENTS = 'touchstart';
|
4111 | var SINGLE_TOUCH_WINDOW_EVENTS = 'touchstart touchmove touchend touchcancel';
|
4112 | |
4113 |
|
4114 |
|
4115 |
|
4116 |
|
4117 |
|
4118 |
|
4119 | var SingleTouchInput =
|
4120 |
|
4121 | function (_Input) {
|
4122 | _inheritsLoose(SingleTouchInput, _Input);
|
4123 |
|
4124 | function SingleTouchInput() {
|
4125 | var _this;
|
4126 |
|
4127 | var proto = SingleTouchInput.prototype;
|
4128 | proto.evTarget = SINGLE_TOUCH_TARGET_EVENTS;
|
4129 | proto.evWin = SINGLE_TOUCH_WINDOW_EVENTS;
|
4130 | _this = _Input.apply(this, arguments) || this;
|
4131 | _this.started = false;
|
4132 | return _this;
|
4133 | }
|
4134 |
|
4135 | var _proto = SingleTouchInput.prototype;
|
4136 |
|
4137 | _proto.handler = function handler(ev) {
|
4138 | var type = SINGLE_TOUCH_INPUT_MAP[ev.type];
|
4139 |
|
4140 | if (type === INPUT_START) {
|
4141 | this.started = true;
|
4142 | }
|
4143 |
|
4144 | if (!this.started) {
|
4145 | return;
|
4146 | }
|
4147 |
|
4148 | var touches = normalizeSingleTouches.call(this, ev, type);
|
4149 |
|
4150 | if (type & (INPUT_END | INPUT_CANCEL) && touches[0].length - touches[1].length === 0) {
|
4151 | this.started = false;
|
4152 | }
|
4153 |
|
4154 | this.callback(this.manager, type, {
|
4155 | pointers: touches[0],
|
4156 | changedPointers: touches[1],
|
4157 | pointerType: INPUT_TYPE_TOUCH,
|
4158 | srcEvent: ev
|
4159 | });
|
4160 | };
|
4161 |
|
4162 | return SingleTouchInput;
|
4163 | }(Input);
|
4164 |
|
4165 | function normalizeSingleTouches(ev, type) {
|
4166 | var all = toArray$2(ev.touches);
|
4167 | var changed = toArray$2(ev.changedTouches);
|
4168 |
|
4169 | if (type & (INPUT_END | INPUT_CANCEL)) {
|
4170 | all = uniqueArray(all.concat(changed), 'identifier', true);
|
4171 | }
|
4172 |
|
4173 | return [all, changed];
|
4174 | }
|
4175 |
|
4176 | |
4177 |
|
4178 |
|
4179 |
|
4180 |
|
4181 |
|
4182 |
|
4183 |
|
4184 | function deprecate(method, name, message) {
|
4185 | var deprecationMessage = "DEPRECATED METHOD: " + name + "\n" + message + " AT \n";
|
4186 | return function () {
|
4187 | var e = new Error('get-stack-trace');
|
4188 | var stack = e && e.stack ? e.stack.replace(/^[^\(]+?[\n$]/gm, '').replace(/^\s+at\s+/gm, '').replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@') : 'Unknown Stack Trace';
|
4189 | var log = window.console && (window.console.warn || window.console.log);
|
4190 |
|
4191 | if (log) {
|
4192 | log.call(window.console, deprecationMessage, stack);
|
4193 | }
|
4194 |
|
4195 | return method.apply(this, arguments);
|
4196 | };
|
4197 | }
|
4198 |
|
4199 | |
4200 |
|
4201 |
|
4202 |
|
4203 |
|
4204 |
|
4205 |
|
4206 |
|
4207 |
|
4208 |
|
4209 | var extend = deprecate(function (dest, src, merge) {
|
4210 | var keys = Object.keys(src);
|
4211 | var i = 0;
|
4212 |
|
4213 | while (i < keys.length) {
|
4214 | if (!merge || merge && dest[keys[i]] === undefined) {
|
4215 | dest[keys[i]] = src[keys[i]];
|
4216 | }
|
4217 |
|
4218 | i++;
|
4219 | }
|
4220 |
|
4221 | return dest;
|
4222 | }, 'extend', 'Use `assign`.');
|
4223 |
|
4224 | |
4225 |
|
4226 |
|
4227 |
|
4228 |
|
4229 |
|
4230 |
|
4231 |
|
4232 |
|
4233 | var merge = deprecate(function (dest, src) {
|
4234 | return extend(dest, src, true);
|
4235 | }, 'merge', 'Use `assign`.');
|
4236 |
|
4237 | |
4238 |
|
4239 |
|
4240 |
|
4241 |
|
4242 |
|
4243 |
|
4244 |
|
4245 | function inherit(child, base, properties) {
|
4246 | var baseP = base.prototype;
|
4247 | var childP;
|
4248 | childP = child.prototype = Object.create(baseP);
|
4249 | childP.constructor = child;
|
4250 | childP._super = baseP;
|
4251 |
|
4252 | if (properties) {
|
4253 | assign$1(childP, properties);
|
4254 | }
|
4255 | }
|
4256 |
|
4257 | |
4258 |
|
4259 |
|
4260 |
|
4261 |
|
4262 |
|
4263 |
|
4264 | function bindFn(fn, context) {
|
4265 | return function boundFn() {
|
4266 | return fn.apply(context, arguments);
|
4267 | };
|
4268 | }
|
4269 |
|
4270 | |
4271 |
|
4272 |
|
4273 |
|
4274 |
|
4275 |
|
4276 |
|
4277 |
|
4278 | var Hammer =
|
4279 |
|
4280 | function () {
|
4281 | var Hammer =
|
4282 | |
4283 |
|
4284 |
|
4285 |
|
4286 | function Hammer(element, options) {
|
4287 | if (options === void 0) {
|
4288 | options = {};
|
4289 | }
|
4290 |
|
4291 | return new Manager(element, _extends({
|
4292 | recognizers: preset.concat()
|
4293 | }, options));
|
4294 | };
|
4295 |
|
4296 | Hammer.VERSION = "2.0.17-rc";
|
4297 | Hammer.DIRECTION_ALL = DIRECTION_ALL;
|
4298 | Hammer.DIRECTION_DOWN = DIRECTION_DOWN;
|
4299 | Hammer.DIRECTION_LEFT = DIRECTION_LEFT;
|
4300 | Hammer.DIRECTION_RIGHT = DIRECTION_RIGHT;
|
4301 | Hammer.DIRECTION_UP = DIRECTION_UP;
|
4302 | Hammer.DIRECTION_HORIZONTAL = DIRECTION_HORIZONTAL;
|
4303 | Hammer.DIRECTION_VERTICAL = DIRECTION_VERTICAL;
|
4304 | Hammer.DIRECTION_NONE = DIRECTION_NONE;
|
4305 | Hammer.DIRECTION_DOWN = DIRECTION_DOWN;
|
4306 | Hammer.INPUT_START = INPUT_START;
|
4307 | Hammer.INPUT_MOVE = INPUT_MOVE;
|
4308 | Hammer.INPUT_END = INPUT_END;
|
4309 | Hammer.INPUT_CANCEL = INPUT_CANCEL;
|
4310 | Hammer.STATE_POSSIBLE = STATE_POSSIBLE;
|
4311 | Hammer.STATE_BEGAN = STATE_BEGAN;
|
4312 | Hammer.STATE_CHANGED = STATE_CHANGED;
|
4313 | Hammer.STATE_ENDED = STATE_ENDED;
|
4314 | Hammer.STATE_RECOGNIZED = STATE_RECOGNIZED;
|
4315 | Hammer.STATE_CANCELLED = STATE_CANCELLED;
|
4316 | Hammer.STATE_FAILED = STATE_FAILED;
|
4317 | Hammer.Manager = Manager;
|
4318 | Hammer.Input = Input;
|
4319 | Hammer.TouchAction = TouchAction;
|
4320 | Hammer.TouchInput = TouchInput;
|
4321 | Hammer.MouseInput = MouseInput;
|
4322 | Hammer.PointerEventInput = PointerEventInput;
|
4323 | Hammer.TouchMouseInput = TouchMouseInput;
|
4324 | Hammer.SingleTouchInput = SingleTouchInput;
|
4325 | Hammer.Recognizer = Recognizer;
|
4326 | Hammer.AttrRecognizer = AttrRecognizer;
|
4327 | Hammer.Tap = TapRecognizer;
|
4328 | Hammer.Pan = PanRecognizer;
|
4329 | Hammer.Swipe = SwipeRecognizer;
|
4330 | Hammer.Pinch = PinchRecognizer;
|
4331 | Hammer.Rotate = RotateRecognizer;
|
4332 | Hammer.Press = PressRecognizer;
|
4333 | Hammer.on = addEventListeners;
|
4334 | Hammer.off = removeEventListeners;
|
4335 | Hammer.each = each;
|
4336 | Hammer.merge = merge;
|
4337 | Hammer.extend = extend;
|
4338 | Hammer.bindFn = bindFn;
|
4339 | Hammer.assign = assign$1;
|
4340 | Hammer.inherit = inherit;
|
4341 | Hammer.bindFn = bindFn;
|
4342 | Hammer.prefixed = prefixed;
|
4343 | Hammer.toArray = toArray$2;
|
4344 | Hammer.inArray = inArray;
|
4345 | Hammer.uniqueArray = uniqueArray;
|
4346 | Hammer.splitStr = splitStr;
|
4347 | Hammer.boolOrFn = boolOrFn;
|
4348 | Hammer.hasParent = hasParent;
|
4349 | Hammer.addEventListeners = addEventListeners;
|
4350 | Hammer.removeEventListeners = removeEventListeners;
|
4351 | Hammer.defaults = assign$1({}, defaults, {
|
4352 | preset: preset
|
4353 | });
|
4354 | return Hammer;
|
4355 | }();
|
4356 |
|
4357 |
|
4358 |
|
4359 | Hammer.defaults;
|
4360 |
|
4361 | |
4362 |
|
4363 |
|
4364 |
|
4365 |
|
4366 |
|
4367 |
|
4368 |
|
4369 | function some(arr, callback) {
|
4370 | var length = arr.length;
|
4371 |
|
4372 | for (var i = 0; i < length; ++i) {
|
4373 | if (callback(arr[i], i)) {
|
4374 | return true;
|
4375 | }
|
4376 | }
|
4377 |
|
4378 | return false;
|
4379 | }
|
4380 | function find(arr, callback) {
|
4381 | var length = arr.length;
|
4382 |
|
4383 | for (var i = 0; i < length; ++i) {
|
4384 | if (callback(arr[i], i)) {
|
4385 | return arr[i];
|
4386 | }
|
4387 | }
|
4388 |
|
4389 | return null;
|
4390 | }
|
4391 | function getUserAgent(agent) {
|
4392 | var userAgent = agent;
|
4393 |
|
4394 | if (typeof userAgent === "undefined") {
|
4395 | if (typeof navigator === "undefined" || !navigator) {
|
4396 | return "";
|
4397 | }
|
4398 |
|
4399 | userAgent = navigator.userAgent || "";
|
4400 | }
|
4401 |
|
4402 | return userAgent.toLowerCase();
|
4403 | }
|
4404 | function execRegExp(pattern, text) {
|
4405 | try {
|
4406 | return new RegExp(pattern, "g").exec(text);
|
4407 | } catch (e) {
|
4408 | return null;
|
4409 | }
|
4410 | }
|
4411 | function hasUserAgentData() {
|
4412 | if (typeof navigator === "undefined" || !navigator || !navigator.userAgentData) {
|
4413 | return false;
|
4414 | }
|
4415 |
|
4416 | var userAgentData = navigator.userAgentData;
|
4417 | var brands = userAgentData.brands || userAgentData.uaList;
|
4418 | return !!(brands && brands.length);
|
4419 | }
|
4420 | function findVersion(versionTest, userAgent) {
|
4421 | var result = execRegExp("(" + versionTest + ")((?:\\/|\\s|:)([0-9|\\.|_]+))", userAgent);
|
4422 | return result ? result[3] : "";
|
4423 | }
|
4424 | function convertVersion(text) {
|
4425 | return text.replace(/_/g, ".");
|
4426 | }
|
4427 | function findPreset(presets, userAgent) {
|
4428 | var userPreset = null;
|
4429 | var version = "-1";
|
4430 | some(presets, function (preset) {
|
4431 | var result = execRegExp("(" + preset.test + ")((?:\\/|\\s|:)([0-9|\\.|_]+))?", userAgent);
|
4432 |
|
4433 | if (!result || preset.brand) {
|
4434 | return false;
|
4435 | }
|
4436 |
|
4437 | userPreset = preset;
|
4438 | version = result[3] || "-1";
|
4439 |
|
4440 | if (preset.versionAlias) {
|
4441 | version = preset.versionAlias;
|
4442 | } else if (preset.versionTest) {
|
4443 | version = findVersion(preset.versionTest.toLowerCase(), userAgent) || version;
|
4444 | }
|
4445 |
|
4446 | version = convertVersion(version);
|
4447 | return true;
|
4448 | });
|
4449 | return {
|
4450 | preset: userPreset,
|
4451 | version: version
|
4452 | };
|
4453 | }
|
4454 | function findPresetBrand(presets, brands) {
|
4455 | var brandInfo = {
|
4456 | brand: "",
|
4457 | version: "-1"
|
4458 | };
|
4459 | some(presets, function (preset) {
|
4460 | var result = findBrand(brands, preset);
|
4461 |
|
4462 | if (!result) {
|
4463 | return false;
|
4464 | }
|
4465 |
|
4466 | brandInfo.brand = preset.id;
|
4467 | brandInfo.version = preset.versionAlias || result.version;
|
4468 | return brandInfo.version !== "-1";
|
4469 | });
|
4470 | return brandInfo;
|
4471 | }
|
4472 | function findBrand(brands, preset) {
|
4473 | return find(brands, function (_a) {
|
4474 | var brand = _a.brand;
|
4475 | return execRegExp("" + preset.test, brand.toLowerCase());
|
4476 | });
|
4477 | }
|
4478 |
|
4479 | var BROWSER_PRESETS = [{
|
4480 | test: "phantomjs",
|
4481 | id: "phantomjs"
|
4482 | }, {
|
4483 | test: "whale",
|
4484 | id: "whale"
|
4485 | }, {
|
4486 | test: "edgios|edge|edg",
|
4487 | id: "edge"
|
4488 | }, {
|
4489 | test: "msie|trident|windows phone",
|
4490 | id: "ie",
|
4491 | versionTest: "iemobile|msie|rv"
|
4492 | }, {
|
4493 | test: "miuibrowser",
|
4494 | id: "miui browser"
|
4495 | }, {
|
4496 | test: "samsungbrowser",
|
4497 | id: "samsung internet"
|
4498 | }, {
|
4499 | test: "samsung",
|
4500 | id: "samsung internet",
|
4501 | versionTest: "version"
|
4502 | }, {
|
4503 | test: "chrome|crios",
|
4504 | id: "chrome"
|
4505 | }, {
|
4506 | test: "firefox|fxios",
|
4507 | id: "firefox"
|
4508 | }, {
|
4509 | test: "android",
|
4510 | id: "android browser",
|
4511 | versionTest: "version"
|
4512 | }, {
|
4513 | test: "safari|iphone|ipad|ipod",
|
4514 | id: "safari",
|
4515 | versionTest: "version"
|
4516 | }];
|
4517 |
|
4518 | var CHROMIUM_PRESETS = [{
|
4519 | test: "(?=.*applewebkit/(53[0-7]|5[0-2]|[0-4]))(?=.*\\schrome)",
|
4520 | id: "chrome",
|
4521 | versionTest: "chrome"
|
4522 | }, {
|
4523 | test: "chromium",
|
4524 | id: "chrome"
|
4525 | }, {
|
4526 | test: "whale",
|
4527 | id: "chrome",
|
4528 | versionAlias: "-1",
|
4529 | brand: true
|
4530 | }];
|
4531 | var WEBKIT_PRESETS = [{
|
4532 | test: "applewebkit",
|
4533 | id: "webkit",
|
4534 | versionTest: "applewebkit|safari"
|
4535 | }];
|
4536 | var WEBVIEW_PRESETS = [{
|
4537 | test: "(?=(iphone|ipad))(?!(.*version))",
|
4538 | id: "webview"
|
4539 | }, {
|
4540 | test: "(?=(android|iphone|ipad))(?=.*(naver|daum|; wv))",
|
4541 | id: "webview"
|
4542 | }, {
|
4543 |
|
4544 | test: "webview",
|
4545 | id: "webview"
|
4546 | }];
|
4547 | var OS_PRESETS = [{
|
4548 | test: "windows phone",
|
4549 | id: "windows phone"
|
4550 | }, {
|
4551 | test: "windows 2000",
|
4552 | id: "window",
|
4553 | versionAlias: "5.0"
|
4554 | }, {
|
4555 | test: "windows nt",
|
4556 | id: "window"
|
4557 | }, {
|
4558 | test: "iphone|ipad|ipod",
|
4559 | id: "ios",
|
4560 | versionTest: "iphone os|cpu os"
|
4561 | }, {
|
4562 | test: "mac os x",
|
4563 | id: "mac"
|
4564 | }, {
|
4565 | test: "android",
|
4566 | id: "android"
|
4567 | }, {
|
4568 | test: "tizen",
|
4569 | id: "tizen"
|
4570 | }, {
|
4571 | test: "webos|web0s",
|
4572 | id: "webos"
|
4573 | }];
|
4574 |
|
4575 | function parseUserAgentData(osData) {
|
4576 | var userAgentData = navigator.userAgentData;
|
4577 | var brands = (userAgentData.uaList || userAgentData.brands).slice();
|
4578 | var isMobile = userAgentData.mobile || false;
|
4579 | var firstBrand = brands[0];
|
4580 | var browser = {
|
4581 | name: firstBrand.brand,
|
4582 | version: firstBrand.version,
|
4583 | majorVersion: -1,
|
4584 | webkit: false,
|
4585 | webkitVersion: "-1",
|
4586 | chromium: false,
|
4587 | chromiumVersion: "-1",
|
4588 | webview: !!findPresetBrand(WEBVIEW_PRESETS, brands).brand
|
4589 | };
|
4590 | var os = {
|
4591 | name: "unknown",
|
4592 | version: "-1",
|
4593 | majorVersion: -1
|
4594 | };
|
4595 | browser.webkit = !browser.chromium && some(WEBKIT_PRESETS, function (preset) {
|
4596 | return findBrand(brands, preset);
|
4597 | });
|
4598 | var chromiumBrand = findPresetBrand(CHROMIUM_PRESETS, brands);
|
4599 | browser.chromium = !!chromiumBrand.brand;
|
4600 | browser.chromiumVersion = chromiumBrand.version;
|
4601 |
|
4602 | if (!browser.chromium) {
|
4603 | var webkitBrand = findPresetBrand(WEBKIT_PRESETS, brands);
|
4604 | browser.webkit = !!webkitBrand.brand;
|
4605 | browser.webkitVersion = webkitBrand.version;
|
4606 | }
|
4607 |
|
4608 | if (osData) {
|
4609 | var platform_1 = osData.platform.toLowerCase();
|
4610 | var result = find(OS_PRESETS, function (preset) {
|
4611 | return new RegExp("" + preset.test, "g").exec(platform_1);
|
4612 | });
|
4613 | os.name = result ? result.id : platform_1;
|
4614 | os.version = osData.platformVersion;
|
4615 | }
|
4616 |
|
4617 | var browserBrand = findPresetBrand(BROWSER_PRESETS, brands);
|
4618 |
|
4619 | if (browserBrand.brand) {
|
4620 | browser.name = browserBrand.brand;
|
4621 | browser.version = osData ? osData.uaFullVersion : browserBrand.version;
|
4622 | }
|
4623 |
|
4624 | if (navigator.platform === "Linux armv8l") {
|
4625 | os.name = "android";
|
4626 | } else if (browser.webkit) {
|
4627 | os.name = isMobile ? "ios" : "mac";
|
4628 | }
|
4629 |
|
4630 | if (os.name === "ios" && browser.webview) {
|
4631 | browser.version = "-1";
|
4632 | }
|
4633 |
|
4634 | os.version = convertVersion(os.version);
|
4635 | browser.version = convertVersion(browser.version);
|
4636 | os.majorVersion = parseInt(os.version, 10);
|
4637 | browser.majorVersion = parseInt(browser.version, 10);
|
4638 | return {
|
4639 | browser: browser,
|
4640 | os: os,
|
4641 | isMobile: isMobile,
|
4642 | isHints: true
|
4643 | };
|
4644 | }
|
4645 |
|
4646 | function parseUserAgent(userAgent) {
|
4647 | var nextAgent = getUserAgent(userAgent);
|
4648 | var isMobile = !!/mobi/g.exec(nextAgent);
|
4649 | var browser = {
|
4650 | name: "unknown",
|
4651 | version: "-1",
|
4652 | majorVersion: -1,
|
4653 | webview: !!findPreset(WEBVIEW_PRESETS, nextAgent).preset,
|
4654 | chromium: false,
|
4655 | chromiumVersion: "-1",
|
4656 | webkit: false,
|
4657 | webkitVersion: "-1"
|
4658 | };
|
4659 | var os = {
|
4660 | name: "unknown",
|
4661 | version: "-1",
|
4662 | majorVersion: -1
|
4663 | };
|
4664 |
|
4665 | var _a = findPreset(BROWSER_PRESETS, nextAgent),
|
4666 | browserPreset = _a.preset,
|
4667 | browserVersion = _a.version;
|
4668 |
|
4669 | var _b = findPreset(OS_PRESETS, nextAgent),
|
4670 | osPreset = _b.preset,
|
4671 | osVersion = _b.version;
|
4672 |
|
4673 | var chromiumPreset = findPreset(CHROMIUM_PRESETS, nextAgent);
|
4674 | browser.chromium = !!chromiumPreset.preset;
|
4675 | browser.chromiumVersion = chromiumPreset.version;
|
4676 |
|
4677 | if (!browser.chromium) {
|
4678 | var webkitPreset = findPreset(WEBKIT_PRESETS, nextAgent);
|
4679 | browser.webkit = !!webkitPreset.preset;
|
4680 | browser.webkitVersion = webkitPreset.version;
|
4681 | }
|
4682 |
|
4683 | if (osPreset) {
|
4684 | os.name = osPreset.id;
|
4685 | os.version = osVersion;
|
4686 | os.majorVersion = parseInt(osVersion, 10);
|
4687 | }
|
4688 |
|
4689 | if (browserPreset) {
|
4690 | browser.name = browserPreset.id;
|
4691 | browser.version = browserVersion;
|
4692 |
|
4693 | if (browser.webview && os.name === "ios" && browser.name !== "safari") {
|
4694 | browser.webview = false;
|
4695 | }
|
4696 | }
|
4697 |
|
4698 | browser.majorVersion = parseInt(browser.version, 10);
|
4699 | return {
|
4700 | browser: browser,
|
4701 | os: os,
|
4702 | isMobile: isMobile,
|
4703 | isHints: false
|
4704 | };
|
4705 | }
|
4706 | |
4707 |
|
4708 |
|
4709 |
|
4710 |
|
4711 |
|
4712 |
|
4713 |
|
4714 |
|
4715 |
|
4716 |
|
4717 |
|
4718 | function agent(userAgent) {
|
4719 | if (typeof userAgent === "undefined" && hasUserAgentData()) {
|
4720 | return parseUserAgentData();
|
4721 | } else {
|
4722 | return parseUserAgent(userAgent);
|
4723 | }
|
4724 | }
|
4725 |
|
4726 | |
4727 |
|
4728 |
|
4729 |
|
4730 |
|
4731 |
|
4732 |
|
4733 |
|
4734 | |
4735 |
|
4736 |
|
4737 |
|
4738 |
|
4739 |
|
4740 |
|
4741 |
|
4742 |
|
4743 |
|
4744 |
|
4745 |
|
4746 |
|
4747 |
|
4748 | function __values$1(o) {
|
4749 | var s = typeof Symbol === "function" && Symbol.iterator,
|
4750 | m = s && o[s],
|
4751 | i = 0;
|
4752 | if (m) return m.call(o);
|
4753 | if (o && typeof o.length === "number") return {
|
4754 | next: function () {
|
4755 | if (o && i >= o.length) o = void 0;
|
4756 | return {
|
4757 | value: o && o[i++],
|
4758 | done: !o
|
4759 | };
|
4760 | }
|
4761 | };
|
4762 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
4763 | }
|
4764 |
|
4765 | |
4766 |
|
4767 |
|
4768 |
|
4769 |
|
4770 | function isUndefined$1(value) {
|
4771 | return typeof value === "undefined";
|
4772 | }
|
4773 | |
4774 |
|
4775 |
|
4776 |
|
4777 |
|
4778 |
|
4779 |
|
4780 | var Component$1 =
|
4781 |
|
4782 | function () {
|
4783 | |
4784 |
|
4785 |
|
4786 | function Component() {
|
4787 | |
4788 |
|
4789 |
|
4790 |
|
4791 | this.options = {};
|
4792 | this._eventHandler = {};
|
4793 | }
|
4794 | |
4795 |
|
4796 |
|
4797 |
|
4798 |
|
4799 |
|
4800 |
|
4801 |
|
4802 |
|
4803 |
|
4804 |
|
4805 |
|
4806 |
|
4807 |
|
4808 |
|
4809 |
|
4810 |
|
4811 |
|
4812 |
|
4813 |
|
4814 |
|
4815 |
|
4816 |
|
4817 |
|
4818 |
|
4819 |
|
4820 |
|
4821 |
|
4822 |
|
4823 |
|
4824 |
|
4825 |
|
4826 |
|
4827 | var __proto = Component.prototype;
|
4828 |
|
4829 | __proto.trigger = function (eventName) {
|
4830 | var _this = this;
|
4831 |
|
4832 | var params = [];
|
4833 |
|
4834 | for (var _i = 1; _i < arguments.length; _i++) {
|
4835 | params[_i - 1] = arguments[_i];
|
4836 | }
|
4837 |
|
4838 | var handlerList = this._eventHandler[eventName] || [];
|
4839 | var hasHandlerList = handlerList.length > 0;
|
4840 |
|
4841 | if (!hasHandlerList) {
|
4842 | return true;
|
4843 | }
|
4844 |
|
4845 | var customEvent = params[0] || {};
|
4846 | var restParams = params.slice(1);
|
4847 |
|
4848 | handlerList = handlerList.concat();
|
4849 | var isCanceled = false;
|
4850 |
|
4851 | customEvent.eventType = eventName;
|
4852 |
|
4853 | customEvent.stop = function () {
|
4854 | isCanceled = true;
|
4855 | };
|
4856 |
|
4857 | customEvent.currentTarget = this;
|
4858 | var arg = [customEvent];
|
4859 |
|
4860 | if (restParams.length >= 1) {
|
4861 | arg = arg.concat(restParams);
|
4862 | }
|
4863 |
|
4864 | handlerList.forEach(function (handler) {
|
4865 | handler.apply(_this, arg);
|
4866 | });
|
4867 | return !isCanceled;
|
4868 | };
|
4869 | |
4870 |
|
4871 |
|
4872 |
|
4873 |
|
4874 |
|
4875 |
|
4876 |
|
4877 |
|
4878 |
|
4879 |
|
4880 |
|
4881 |
|
4882 |
|
4883 |
|
4884 |
|
4885 |
|
4886 |
|
4887 |
|
4888 |
|
4889 |
|
4890 |
|
4891 |
|
4892 |
|
4893 |
|
4894 |
|
4895 | __proto.once = function (eventName, handlerToAttach) {
|
4896 | var _this = this;
|
4897 |
|
4898 | if (typeof eventName === "object" && isUndefined$1(handlerToAttach)) {
|
4899 | var eventHash = eventName;
|
4900 |
|
4901 | for (var key in eventHash) {
|
4902 | this.once(key, eventHash[key]);
|
4903 | }
|
4904 |
|
4905 | return this;
|
4906 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
4907 | var listener_1 = function () {
|
4908 | var args = [];
|
4909 |
|
4910 | for (var _i = 0; _i < arguments.length; _i++) {
|
4911 | args[_i] = arguments[_i];
|
4912 | }
|
4913 |
|
4914 | handlerToAttach.apply(_this, args);
|
4915 |
|
4916 | _this.off(eventName, listener_1);
|
4917 | };
|
4918 |
|
4919 | this.on(eventName, listener_1);
|
4920 | }
|
4921 |
|
4922 | return this;
|
4923 | };
|
4924 | |
4925 |
|
4926 |
|
4927 |
|
4928 |
|
4929 |
|
4930 |
|
4931 |
|
4932 |
|
4933 |
|
4934 |
|
4935 |
|
4936 |
|
4937 |
|
4938 |
|
4939 |
|
4940 | __proto.hasOn = function (eventName) {
|
4941 | return !!this._eventHandler[eventName];
|
4942 | };
|
4943 | |
4944 |
|
4945 |
|
4946 |
|
4947 |
|
4948 |
|
4949 |
|
4950 |
|
4951 |
|
4952 |
|
4953 |
|
4954 |
|
4955 |
|
4956 |
|
4957 |
|
4958 |
|
4959 |
|
4960 |
|
4961 |
|
4962 |
|
4963 | __proto.on = function (eventName, handlerToAttach) {
|
4964 | if (typeof eventName === "object" && isUndefined$1(handlerToAttach)) {
|
4965 | var eventHash = eventName;
|
4966 |
|
4967 | for (var name in eventHash) {
|
4968 | this.on(name, eventHash[name]);
|
4969 | }
|
4970 |
|
4971 | return this;
|
4972 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
4973 | var handlerList = this._eventHandler[eventName];
|
4974 |
|
4975 | if (isUndefined$1(handlerList)) {
|
4976 | this._eventHandler[eventName] = [];
|
4977 | handlerList = this._eventHandler[eventName];
|
4978 | }
|
4979 |
|
4980 | handlerList.push(handlerToAttach);
|
4981 | }
|
4982 |
|
4983 | return this;
|
4984 | };
|
4985 | |
4986 |
|
4987 |
|
4988 |
|
4989 |
|
4990 |
|
4991 |
|
4992 |
|
4993 |
|
4994 |
|
4995 |
|
4996 |
|
4997 |
|
4998 |
|
4999 |
|
5000 |
|
5001 |
|
5002 |
|
5003 |
|
5004 |
|
5005 | __proto.off = function (eventName, handlerToDetach) {
|
5006 | var e_1, _a;
|
5007 |
|
5008 |
|
5009 | if (isUndefined$1(eventName)) {
|
5010 | this._eventHandler = {};
|
5011 | return this;
|
5012 | }
|
5013 |
|
5014 |
|
5015 | if (isUndefined$1(handlerToDetach)) {
|
5016 | if (typeof eventName === "string") {
|
5017 | delete this._eventHandler[eventName];
|
5018 | return this;
|
5019 | } else {
|
5020 | var eventHash = eventName;
|
5021 |
|
5022 | for (var name in eventHash) {
|
5023 | this.off(name, eventHash[name]);
|
5024 | }
|
5025 |
|
5026 | return this;
|
5027 | }
|
5028 | }
|
5029 |
|
5030 |
|
5031 | var handlerList = this._eventHandler[eventName];
|
5032 |
|
5033 | if (handlerList) {
|
5034 | var idx = 0;
|
5035 |
|
5036 | try {
|
5037 | for (var handlerList_1 = __values$1(handlerList), handlerList_1_1 = handlerList_1.next(); !handlerList_1_1.done; handlerList_1_1 = handlerList_1.next()) {
|
5038 | var handlerFunction = handlerList_1_1.value;
|
5039 |
|
5040 | if (handlerFunction === handlerToDetach) {
|
5041 | handlerList.splice(idx, 1);
|
5042 | break;
|
5043 | }
|
5044 |
|
5045 | idx++;
|
5046 | }
|
5047 | } catch (e_1_1) {
|
5048 | e_1 = {
|
5049 | error: e_1_1
|
5050 | };
|
5051 | } finally {
|
5052 | try {
|
5053 | if (handlerList_1_1 && !handlerList_1_1.done && (_a = handlerList_1.return)) _a.call(handlerList_1);
|
5054 | } finally {
|
5055 | if (e_1) throw e_1.error;
|
5056 | }
|
5057 | }
|
5058 | }
|
5059 |
|
5060 | return this;
|
5061 | };
|
5062 | |
5063 |
|
5064 |
|
5065 |
|
5066 |
|
5067 |
|
5068 |
|
5069 |
|
5070 |
|
5071 |
|
5072 |
|
5073 | Component.VERSION = "2.2.2";
|
5074 | return Component;
|
5075 | }();
|
5076 |
|
5077 | |
5078 |
|
5079 |
|
5080 |
|
5081 |
|
5082 |
|
5083 |
|
5084 |
|
5085 |
|
5086 | |
5087 |
|
5088 |
|
5089 |
|
5090 |
|
5091 |
|
5092 |
|
5093 |
|
5094 |
|
5095 |
|
5096 |
|
5097 |
|
5098 |
|
5099 |
|
5100 |
|
5101 |
|
5102 | var extendStatics$1 = function (d, b) {
|
5103 | extendStatics$1 = Object.setPrototypeOf || {
|
5104 | __proto__: []
|
5105 | } instanceof Array && function (d, b) {
|
5106 | d.__proto__ = b;
|
5107 | } || function (d, b) {
|
5108 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
5109 | };
|
5110 |
|
5111 | return extendStatics$1(d, b);
|
5112 | };
|
5113 |
|
5114 | function __extends$1(d, b) {
|
5115 | extendStatics$1(d, b);
|
5116 |
|
5117 | function __() {
|
5118 | this.constructor = d;
|
5119 | }
|
5120 |
|
5121 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
5122 | }
|
5123 | var __assign$1 = function () {
|
5124 | __assign$1 = Object.assign || function __assign(t) {
|
5125 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5126 | s = arguments[i];
|
5127 |
|
5128 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
5129 | }
|
5130 |
|
5131 | return t;
|
5132 | };
|
5133 |
|
5134 | return __assign$1.apply(this, arguments);
|
5135 | };
|
5136 |
|
5137 | function getInsidePosition(destPos, range, circular, bounce) {
|
5138 | var toDestPos = destPos;
|
5139 | var targetRange = [circular[0] ? range[0] : bounce ? range[0] - bounce[0] : range[0], circular[1] ? range[1] : bounce ? range[1] + bounce[1] : range[1]];
|
5140 | toDestPos = Math.max(targetRange[0], toDestPos);
|
5141 | toDestPos = Math.min(targetRange[1], toDestPos);
|
5142 | return toDestPos;
|
5143 | }
|
5144 |
|
5145 | function isOutside(pos, range) {
|
5146 | return pos < range[0] || pos > range[1];
|
5147 | }
|
5148 | function getDuration(distance, deceleration) {
|
5149 | var duration = Math.sqrt(distance / deceleration * 2);
|
5150 |
|
5151 | return duration < 100 ? 0 : duration;
|
5152 | }
|
5153 | function isCircularable(destPos, range, circular) {
|
5154 | return circular[1] && destPos > range[1] || circular[0] && destPos < range[0];
|
5155 | }
|
5156 | function getCirculatedPos(pos, range, circular) {
|
5157 | var toPos = pos;
|
5158 | var min = range[0];
|
5159 | var max = range[1];
|
5160 | var length = max - min;
|
5161 |
|
5162 | if (circular[1] && pos > max) {
|
5163 |
|
5164 | toPos = (toPos - max) % length + min;
|
5165 | }
|
5166 |
|
5167 | if (circular[0] && pos < min) {
|
5168 |
|
5169 | toPos = (toPos - min) % length + max;
|
5170 | }
|
5171 |
|
5172 | return toPos;
|
5173 | }
|
5174 |
|
5175 |
|
5176 | var win;
|
5177 |
|
5178 | if (typeof window === "undefined") {
|
5179 |
|
5180 | win = {
|
5181 | navigator: {
|
5182 | userAgent: ""
|
5183 | }
|
5184 | };
|
5185 | } else {
|
5186 | win = window;
|
5187 | }
|
5188 |
|
5189 | function toArray$1(nodes) {
|
5190 |
|
5191 |
|
5192 | var el = [];
|
5193 |
|
5194 | for (var i = 0, len = nodes.length; i < len; i++) {
|
5195 | el.push(nodes[i]);
|
5196 | }
|
5197 |
|
5198 | return el;
|
5199 | }
|
5200 | function $(param, multi) {
|
5201 | if (multi === void 0) {
|
5202 | multi = false;
|
5203 | }
|
5204 |
|
5205 | var el;
|
5206 |
|
5207 | if (typeof param === "string") {
|
5208 |
|
5209 |
|
5210 | var match = param.match(/^<([a-z]+)\s*([^>]*)>/);
|
5211 |
|
5212 | if (match) {
|
5213 |
|
5214 | var dummy = document.createElement("div");
|
5215 | dummy.innerHTML = param;
|
5216 | el = toArray$1(dummy.childNodes);
|
5217 | } else {
|
5218 |
|
5219 | el = toArray$1(document.querySelectorAll(param));
|
5220 | }
|
5221 |
|
5222 | if (!multi) {
|
5223 | el = el.length >= 1 ? el[0] : undefined;
|
5224 | }
|
5225 | } else if (param === win) {
|
5226 |
|
5227 | el = param;
|
5228 | } else if (param.nodeName && (param.nodeType === 1 || param.nodeType === 9)) {
|
5229 |
|
5230 | el = param;
|
5231 | } else if ("jQuery" in win && param instanceof jQuery || param.constructor.prototype.jquery) {
|
5232 |
|
5233 | el = multi ? param.toArray() : param.get(0);
|
5234 | } else if (Array.isArray(param)) {
|
5235 | el = param.map(function (v) {
|
5236 | return $(v);
|
5237 | });
|
5238 |
|
5239 | if (!multi) {
|
5240 | el = el.length >= 1 ? el[0] : undefined;
|
5241 | }
|
5242 | }
|
5243 |
|
5244 | return el;
|
5245 | }
|
5246 | var raf = win.requestAnimationFrame || win.webkitRequestAnimationFrame;
|
5247 | var caf = win.cancelAnimationFrame || win.webkitCancelAnimationFrame;
|
5248 |
|
5249 | if (raf && !caf) {
|
5250 | var keyInfo_1 = {};
|
5251 | var oldraf_1 = raf;
|
5252 |
|
5253 | raf = function (callback) {
|
5254 | function wrapCallback(timestamp) {
|
5255 | if (keyInfo_1[key]) {
|
5256 | callback(timestamp);
|
5257 | }
|
5258 | }
|
5259 |
|
5260 | var key = oldraf_1(wrapCallback);
|
5261 | keyInfo_1[key] = true;
|
5262 | return key;
|
5263 | };
|
5264 |
|
5265 | caf = function (key) {
|
5266 | delete keyInfo_1[key];
|
5267 | };
|
5268 | } else if (!(raf && caf)) {
|
5269 | raf = function (callback) {
|
5270 | return win.setTimeout(function () {
|
5271 | callback(win.performance && win.performance.now && win.performance.now() || new Date().getTime());
|
5272 | }, 16);
|
5273 | };
|
5274 |
|
5275 | caf = win.clearTimeout;
|
5276 | }
|
5277 | |
5278 |
|
5279 |
|
5280 |
|
5281 |
|
5282 |
|
5283 |
|
5284 | function requestAnimationFrame(fp) {
|
5285 | return raf(fp);
|
5286 | }
|
5287 | |
5288 |
|
5289 |
|
5290 |
|
5291 |
|
5292 |
|
5293 |
|
5294 | function cancelAnimationFrame(key) {
|
5295 | caf(key);
|
5296 | }
|
5297 | function map(obj, callback) {
|
5298 | var tranformed = {};
|
5299 |
|
5300 | for (var k in obj) {
|
5301 | k && (tranformed[k] = callback(obj[k], k));
|
5302 | }
|
5303 |
|
5304 | return tranformed;
|
5305 | }
|
5306 | function filter(obj, callback) {
|
5307 | var filtered = {};
|
5308 |
|
5309 | for (var k in obj) {
|
5310 | k && callback(obj[k], k) && (filtered[k] = obj[k]);
|
5311 | }
|
5312 |
|
5313 | return filtered;
|
5314 | }
|
5315 | function every(obj, callback) {
|
5316 | for (var k in obj) {
|
5317 | if (k && !callback(obj[k], k)) {
|
5318 | return false;
|
5319 | }
|
5320 | }
|
5321 |
|
5322 | return true;
|
5323 | }
|
5324 | function equal(target, base) {
|
5325 | return every(target, function (v, k) {
|
5326 | return v === base[k];
|
5327 | });
|
5328 | }
|
5329 | var roundNumFunc = {};
|
5330 | function roundNumber(num, roundUnit) {
|
5331 |
|
5332 | if (!roundNumFunc[roundUnit]) {
|
5333 | roundNumFunc[roundUnit] = getRoundFunc(roundUnit);
|
5334 | }
|
5335 |
|
5336 | return roundNumFunc[roundUnit](num);
|
5337 | }
|
5338 | function roundNumbers(num, roundUnit) {
|
5339 | if (!num || !roundUnit) {
|
5340 | return num;
|
5341 | }
|
5342 |
|
5343 | var isNumber = typeof roundUnit === "number";
|
5344 | return map(num, function (value, key) {
|
5345 | return roundNumber(value, isNumber ? roundUnit : roundUnit[key]);
|
5346 | });
|
5347 | }
|
5348 | function getDecimalPlace(val) {
|
5349 | if (!isFinite(val)) {
|
5350 | return 0;
|
5351 | }
|
5352 |
|
5353 | var v = val + "";
|
5354 |
|
5355 | if (v.indexOf("e") >= 0) {
|
5356 |
|
5357 |
|
5358 | var p = 0;
|
5359 | var e = 1;
|
5360 |
|
5361 | while (Math.round(val * e) / e !== val) {
|
5362 | e *= 10;
|
5363 | p++;
|
5364 | }
|
5365 |
|
5366 | return p;
|
5367 | }
|
5368 |
|
5369 |
|
5370 |
|
5371 | return v.indexOf(".") >= 0 ? v.length - v.indexOf(".") - 1 : 0;
|
5372 | }
|
5373 | function inversePow(n) {
|
5374 |
|
5375 |
|
5376 | return 1 / Math.pow(10, n);
|
5377 | }
|
5378 | function getRoundFunc(v) {
|
5379 | var p = v < 1 ? Math.pow(10, getDecimalPlace(v)) : 1;
|
5380 | return function (n) {
|
5381 | if (v === 0) {
|
5382 | return 0;
|
5383 | }
|
5384 |
|
5385 | return Math.round(Math.round(n / v) * v * p) / p;
|
5386 | };
|
5387 | }
|
5388 |
|
5389 | function minMax(value, min, max) {
|
5390 | return Math.max(Math.min(value, max), min);
|
5391 | }
|
5392 |
|
5393 | var AnimationManager =
|
5394 |
|
5395 | function () {
|
5396 | function AnimationManager(_a) {
|
5397 | var options = _a.options,
|
5398 | itm = _a.itm,
|
5399 | em = _a.em,
|
5400 | axm = _a.axm;
|
5401 | this.options = options;
|
5402 | this.itm = itm;
|
5403 | this.em = em;
|
5404 | this.axm = axm;
|
5405 | this.animationEnd = this.animationEnd.bind(this);
|
5406 | }
|
5407 |
|
5408 | var __proto = AnimationManager.prototype;
|
5409 |
|
5410 | __proto.getDuration = function (depaPos, destPos, wishDuration) {
|
5411 | var _this = this;
|
5412 |
|
5413 | var duration;
|
5414 |
|
5415 | if (typeof wishDuration !== "undefined") {
|
5416 | duration = wishDuration;
|
5417 | } else {
|
5418 | var durations_1 = map(destPos, function (v, k) {
|
5419 | return getDuration(Math.abs(v - depaPos[k]), _this.options.deceleration);
|
5420 | });
|
5421 | duration = Object.keys(durations_1).reduce(function (max, v) {
|
5422 | return Math.max(max, durations_1[v]);
|
5423 | }, -Infinity);
|
5424 | }
|
5425 |
|
5426 | return minMax(duration, this.options.minimumDuration, this.options.maximumDuration);
|
5427 | };
|
5428 |
|
5429 | __proto.createAnimationParam = function (pos, duration, option) {
|
5430 | var depaPos = this.axm.get();
|
5431 | var destPos = pos;
|
5432 | var inputEvent = option && option.event || null;
|
5433 | return {
|
5434 | depaPos: depaPos,
|
5435 | destPos: destPos,
|
5436 | duration: minMax(duration, this.options.minimumDuration, this.options.maximumDuration),
|
5437 | delta: this.axm.getDelta(depaPos, destPos),
|
5438 | inputEvent: inputEvent,
|
5439 | input: option && option.input || null,
|
5440 | isTrusted: !!inputEvent,
|
5441 | done: this.animationEnd
|
5442 | };
|
5443 | };
|
5444 |
|
5445 | __proto.grab = function (axes, option) {
|
5446 | if (this._animateParam && axes.length) {
|
5447 | var orgPos_1 = this.axm.get(axes);
|
5448 | var pos = this.axm.map(orgPos_1, function (v, opt) {
|
5449 | return getCirculatedPos(v, opt.range, opt.circular);
|
5450 | });
|
5451 |
|
5452 | if (!every(pos, function (v, k) {
|
5453 | return orgPos_1[k] === v;
|
5454 | })) {
|
5455 | this.em.triggerChange(pos, false, orgPos_1, option, !!option);
|
5456 | }
|
5457 |
|
5458 | this._animateParam = null;
|
5459 | this._raf && cancelAnimationFrame(this._raf);
|
5460 | this._raf = null;
|
5461 | this.em.triggerAnimationEnd(!!(option && option.event));
|
5462 | }
|
5463 | };
|
5464 |
|
5465 | __proto.getEventInfo = function () {
|
5466 | if (this._animateParam && this._animateParam.input && this._animateParam.inputEvent) {
|
5467 | return {
|
5468 | input: this._animateParam.input,
|
5469 | event: this._animateParam.inputEvent
|
5470 | };
|
5471 | } else {
|
5472 | return null;
|
5473 | }
|
5474 | };
|
5475 |
|
5476 | __proto.restore = function (option) {
|
5477 | var pos = this.axm.get();
|
5478 | var destPos = this.axm.map(pos, function (v, opt) {
|
5479 | return Math.min(opt.range[1], Math.max(opt.range[0], v));
|
5480 | });
|
5481 | this.animateTo(destPos, this.getDuration(pos, destPos), option);
|
5482 | };
|
5483 |
|
5484 | __proto.animationEnd = function () {
|
5485 | var beforeParam = this.getEventInfo();
|
5486 | this._animateParam = null;
|
5487 |
|
5488 | var circularTargets = this.axm.filter(this.axm.get(), function (v, opt) {
|
5489 | return isCircularable(v, opt.range, opt.circular);
|
5490 | });
|
5491 | Object.keys(circularTargets).length > 0 && this.setTo(this.axm.map(circularTargets, function (v, opt) {
|
5492 | return getCirculatedPos(v, opt.range, opt.circular);
|
5493 | }));
|
5494 | this.itm.setInterrupt(false);
|
5495 | this.em.triggerAnimationEnd(!!beforeParam);
|
5496 |
|
5497 | if (this.axm.isOutside()) {
|
5498 | this.restore(beforeParam);
|
5499 | } else {
|
5500 | this.finish(!!beforeParam);
|
5501 | }
|
5502 | };
|
5503 |
|
5504 | __proto.finish = function (isTrusted) {
|
5505 | this._animateParam = null;
|
5506 | this.itm.setInterrupt(false);
|
5507 | this.em.triggerFinish(isTrusted);
|
5508 | };
|
5509 |
|
5510 | __proto.animateLoop = function (param, complete) {
|
5511 | if (param.duration) {
|
5512 | this._animateParam = __assign$1({}, param);
|
5513 | var info_1 = this._animateParam;
|
5514 | var self_1 = this;
|
5515 | var destPos_1 = info_1.destPos;
|
5516 | var prevPos_1 = info_1.depaPos;
|
5517 | var prevEasingPer_1 = 0;
|
5518 | var directions_1 = map(prevPos_1, function (value, key) {
|
5519 | return value <= destPos_1[key] ? 1 : -1;
|
5520 | });
|
5521 | var originalIntendedPos_1 = map(destPos_1, function (v) {
|
5522 | return v;
|
5523 | });
|
5524 | var prevTime_1 = new Date().getTime();
|
5525 | info_1.startTime = prevTime_1;
|
5526 |
|
5527 | (function loop() {
|
5528 | self_1._raf = null;
|
5529 | var currentTime = new Date().getTime();
|
5530 | var ratio = (currentTime - info_1.startTime) / param.duration;
|
5531 | var easingPer = self_1.easing(ratio);
|
5532 | var toPos = self_1.axm.map(prevPos_1, function (pos, options, key) {
|
5533 | var nextPos = ratio >= 1 ? destPos_1[key] : pos + info_1.delta[key] * (easingPer - prevEasingPer_1);
|
5534 |
|
5535 |
|
5536 |
|
5537 | var circulatedPos = getCirculatedPos(nextPos, options.range, options.circular);
|
5538 |
|
5539 | if (nextPos !== circulatedPos) {
|
5540 |
|
5541 | var rangeOffset = directions_1[key] * (options.range[1] - options.range[0]);
|
5542 | destPos_1[key] -= rangeOffset;
|
5543 | prevPos_1[key] -= rangeOffset;
|
5544 | }
|
5545 |
|
5546 | return circulatedPos;
|
5547 | });
|
5548 | var isCanceled = !self_1.em.triggerChange(toPos, false, prevPos_1);
|
5549 | prevPos_1 = toPos;
|
5550 | prevTime_1 = currentTime;
|
5551 | prevEasingPer_1 = easingPer;
|
5552 |
|
5553 | if (easingPer >= 1) {
|
5554 | destPos_1 = self_1.getFinalPos(destPos_1, originalIntendedPos_1);
|
5555 |
|
5556 | if (!equal(destPos_1, self_1.axm.get(Object.keys(destPos_1)))) {
|
5557 | self_1.em.triggerChange(destPos_1, true, prevPos_1);
|
5558 | }
|
5559 |
|
5560 | complete();
|
5561 | return;
|
5562 | } else if (isCanceled) {
|
5563 | self_1.finish(false);
|
5564 | } else {
|
5565 |
|
5566 | self_1._raf = requestAnimationFrame(loop);
|
5567 | }
|
5568 | })();
|
5569 | } else {
|
5570 | this.em.triggerChange(param.destPos, true);
|
5571 | complete();
|
5572 | }
|
5573 | };
|
5574 | |
5575 |
|
5576 |
|
5577 |
|
5578 |
|
5579 |
|
5580 |
|
5581 |
|
5582 |
|
5583 |
|
5584 |
|
5585 |
|
5586 |
|
5587 | __proto.getFinalPos = function (destPos, originalIntendedPos) {
|
5588 | var _this = this;
|
5589 |
|
5590 |
|
5591 | var ERROR_LIMIT = 0.000001;
|
5592 | var finalPos = map(destPos, function (value, key) {
|
5593 | if (value >= originalIntendedPos[key] - ERROR_LIMIT && value <= originalIntendedPos[key] + ERROR_LIMIT) {
|
5594 |
|
5595 | return originalIntendedPos[key];
|
5596 | } else {
|
5597 |
|
5598 | var roundUnit = _this.getRoundUnit(value, key);
|
5599 |
|
5600 | var result = roundNumber(value, roundUnit);
|
5601 | return result;
|
5602 | }
|
5603 | });
|
5604 | return finalPos;
|
5605 | };
|
5606 |
|
5607 | __proto.getRoundUnit = function (val, key) {
|
5608 | var roundUnit = this.options.round;
|
5609 |
|
5610 | var minRoundUnit = null;
|
5611 |
|
5612 |
|
5613 | if (!roundUnit) {
|
5614 |
|
5615 | var options = this.axm.getAxisOptions(key);
|
5616 | minRoundUnit = inversePow(Math.max(getDecimalPlace(options.range[0]), getDecimalPlace(options.range[1]), getDecimalPlace(val)));
|
5617 | }
|
5618 |
|
5619 | return minRoundUnit || roundUnit;
|
5620 | };
|
5621 |
|
5622 | __proto.getUserControll = function (param) {
|
5623 | var userWish = param.setTo();
|
5624 | userWish.destPos = this.axm.get(userWish.destPos);
|
5625 | userWish.duration = minMax(userWish.duration, this.options.minimumDuration, this.options.maximumDuration);
|
5626 | return userWish;
|
5627 | };
|
5628 |
|
5629 | __proto.animateTo = function (destPos, duration, option) {
|
5630 | var _this = this;
|
5631 |
|
5632 | var param = this.createAnimationParam(destPos, duration, option);
|
5633 |
|
5634 | var depaPos = __assign$1({}, param.depaPos);
|
5635 |
|
5636 | var retTrigger = this.em.triggerAnimationStart(param);
|
5637 |
|
5638 | var userWish = this.getUserControll(param);
|
5639 |
|
5640 | if (!retTrigger && this.axm.every(userWish.destPos, function (v, opt) {
|
5641 | return isCircularable(v, opt.range, opt.circular);
|
5642 | })) {
|
5643 | console.warn("You can't stop the 'animation' event when 'circular' is true.");
|
5644 | }
|
5645 |
|
5646 | if (retTrigger && !equal(userWish.destPos, depaPos)) {
|
5647 | var inputEvent = option && option.event || null;
|
5648 | this.animateLoop({
|
5649 | depaPos: depaPos,
|
5650 | destPos: userWish.destPos,
|
5651 | duration: userWish.duration,
|
5652 | delta: this.axm.getDelta(depaPos, userWish.destPos),
|
5653 | isTrusted: !!inputEvent,
|
5654 | inputEvent: inputEvent,
|
5655 | input: option && option.input || null
|
5656 | }, function () {
|
5657 | return _this.animationEnd();
|
5658 | });
|
5659 | }
|
5660 | };
|
5661 |
|
5662 | __proto.easing = function (p) {
|
5663 | return p > 1 ? 1 : this.options.easing(p);
|
5664 | };
|
5665 |
|
5666 | __proto.setTo = function (pos, duration) {
|
5667 | if (duration === void 0) {
|
5668 | duration = 0;
|
5669 | }
|
5670 |
|
5671 | var axes = Object.keys(pos);
|
5672 | this.grab(axes);
|
5673 | var orgPos = this.axm.get(axes);
|
5674 |
|
5675 | if (equal(pos, orgPos)) {
|
5676 | return this;
|
5677 | }
|
5678 |
|
5679 | this.itm.setInterrupt(true);
|
5680 | var movedPos = filter(pos, function (v, k) {
|
5681 | return orgPos[k] !== v;
|
5682 | });
|
5683 |
|
5684 | if (!Object.keys(movedPos).length) {
|
5685 | return this;
|
5686 | }
|
5687 |
|
5688 | movedPos = this.axm.map(movedPos, function (v, opt) {
|
5689 | var range = opt.range,
|
5690 | circular = opt.circular;
|
5691 |
|
5692 | if (circular && (circular[0] || circular[1])) {
|
5693 | return v;
|
5694 | } else {
|
5695 | return getInsidePosition(v, range, circular);
|
5696 | }
|
5697 | });
|
5698 |
|
5699 | if (equal(movedPos, orgPos)) {
|
5700 | return this;
|
5701 | }
|
5702 |
|
5703 | if (duration > 0) {
|
5704 | this.animateTo(movedPos, duration);
|
5705 | } else {
|
5706 | this.em.triggerChange(movedPos);
|
5707 | this.finish(false);
|
5708 | }
|
5709 |
|
5710 | return this;
|
5711 | };
|
5712 |
|
5713 | __proto.setBy = function (pos, duration) {
|
5714 | if (duration === void 0) {
|
5715 | duration = 0;
|
5716 | }
|
5717 |
|
5718 | return this.setTo(map(this.axm.get(Object.keys(pos)), function (v, k) {
|
5719 | return v + pos[k];
|
5720 | }), duration);
|
5721 | };
|
5722 |
|
5723 | return AnimationManager;
|
5724 | }();
|
5725 |
|
5726 | var EventManager =
|
5727 |
|
5728 | function () {
|
5729 | function EventManager(axes) {
|
5730 | this.axes = axes;
|
5731 | }
|
5732 | |
5733 |
|
5734 |
|
5735 |
|
5736 |
|
5737 |
|
5738 |
|
5739 |
|
5740 |
|
5741 |
|
5742 |
|
5743 |
|
5744 |
|
5745 |
|
5746 |
|
5747 |
|
5748 |
|
5749 |
|
5750 |
|
5751 |
|
5752 |
|
5753 |
|
5754 |
|
5755 |
|
5756 |
|
5757 |
|
5758 |
|
5759 |
|
5760 | var __proto = EventManager.prototype;
|
5761 |
|
5762 | __proto.triggerHold = function (pos, option) {
|
5763 | var roundPos = this.getRoundPos(pos).roundPos;
|
5764 | this.axes.trigger("hold", {
|
5765 | pos: roundPos,
|
5766 | input: option.input || null,
|
5767 | inputEvent: option.event || null,
|
5768 | isTrusted: true
|
5769 | });
|
5770 | };
|
5771 | |
5772 |
|
5773 |
|
5774 |
|
5775 |
|
5776 |
|
5777 |
|
5778 |
|
5779 |
|
5780 |
|
5781 |
|
5782 |
|
5783 |
|
5784 |
|
5785 |
|
5786 |
|
5787 |
|
5788 |
|
5789 |
|
5790 | |
5791 |
|
5792 |
|
5793 |
|
5794 |
|
5795 |
|
5796 |
|
5797 |
|
5798 |
|
5799 |
|
5800 |
|
5801 |
|
5802 |
|
5803 |
|
5804 |
|
5805 |
|
5806 |
|
5807 |
|
5808 |
|
5809 | |
5810 |
|
5811 |
|
5812 |
|
5813 |
|
5814 |
|
5815 |
|
5816 |
|
5817 |
|
5818 |
|
5819 |
|
5820 |
|
5821 |
|
5822 |
|
5823 |
|
5824 |
|
5825 |
|
5826 |
|
5827 |
|
5828 |
|
5829 |
|
5830 |
|
5831 |
|
5832 |
|
5833 |
|
5834 |
|
5835 |
|
5836 |
|
5837 |
|
5838 |
|
5839 |
|
5840 |
|
5841 |
|
5842 |
|
5843 |
|
5844 |
|
5845 |
|
5846 | __proto.triggerRelease = function (param) {
|
5847 | var _a = this.getRoundPos(param.destPos, param.depaPos),
|
5848 | roundPos = _a.roundPos,
|
5849 | roundDepa = _a.roundDepa;
|
5850 |
|
5851 | param.destPos = roundPos;
|
5852 | param.depaPos = roundDepa;
|
5853 | param.setTo = this.createUserControll(param.destPos, param.duration);
|
5854 | this.axes.trigger("release", param);
|
5855 | };
|
5856 | |
5857 |
|
5858 |
|
5859 |
|
5860 |
|
5861 |
|
5862 |
|
5863 |
|
5864 |
|
5865 |
|
5866 |
|
5867 |
|
5868 |
|
5869 |
|
5870 |
|
5871 |
|
5872 |
|
5873 |
|
5874 |
|
5875 |
|
5876 |
|
5877 |
|
5878 |
|
5879 |
|
5880 |
|
5881 |
|
5882 |
|
5883 |
|
5884 |
|
5885 |
|
5886 |
|
5887 |
|
5888 |
|
5889 |
|
5890 |
|
5891 |
|
5892 |
|
5893 |
|
5894 | __proto.triggerChange = function (pos, isAccurate, depaPos, option, holding) {
|
5895 | if (holding === void 0) {
|
5896 | holding = false;
|
5897 | }
|
5898 |
|
5899 | var am = this.am;
|
5900 | var axm = am.axm;
|
5901 | var eventInfo = am.getEventInfo();
|
5902 |
|
5903 | var _a = this.getRoundPos(pos, depaPos),
|
5904 | roundPos = _a.roundPos,
|
5905 | roundDepa = _a.roundDepa;
|
5906 |
|
5907 | var moveTo = axm.moveTo(roundPos, roundDepa);
|
5908 | var inputEvent = option && option.event || eventInfo && eventInfo.event || null;
|
5909 | var param = {
|
5910 | pos: moveTo.pos,
|
5911 | delta: moveTo.delta,
|
5912 | holding: holding,
|
5913 | inputEvent: inputEvent,
|
5914 | isTrusted: !!inputEvent,
|
5915 | input: option && option.input || eventInfo && eventInfo.input || null,
|
5916 | set: inputEvent ? this.createUserControll(moveTo.pos) : function () {}
|
5917 | };
|
5918 | var result = this.axes.trigger("change", param);
|
5919 | inputEvent && axm.set(param.set()["destPos"]);
|
5920 | return result;
|
5921 | };
|
5922 | |
5923 |
|
5924 |
|
5925 |
|
5926 |
|
5927 |
|
5928 |
|
5929 |
|
5930 |
|
5931 |
|
5932 |
|
5933 |
|
5934 |
|
5935 |
|
5936 |
|
5937 |
|
5938 |
|
5939 |
|
5940 |
|
5941 |
|
5942 |
|
5943 |
|
5944 |
|
5945 |
|
5946 |
|
5947 |
|
5948 |
|
5949 |
|
5950 |
|
5951 |
|
5952 |
|
5953 |
|
5954 |
|
5955 |
|
5956 |
|
5957 |
|
5958 |
|
5959 |
|
5960 | __proto.triggerAnimationStart = function (param) {
|
5961 | var _a = this.getRoundPos(param.destPos, param.depaPos),
|
5962 | roundPos = _a.roundPos,
|
5963 | roundDepa = _a.roundDepa;
|
5964 |
|
5965 | param.destPos = roundPos;
|
5966 | param.depaPos = roundDepa;
|
5967 | param.setTo = this.createUserControll(param.destPos, param.duration);
|
5968 | return this.axes.trigger("animationStart", param);
|
5969 | };
|
5970 | |
5971 |
|
5972 |
|
5973 |
|
5974 |
|
5975 |
|
5976 |
|
5977 |
|
5978 |
|
5979 |
|
5980 |
|
5981 |
|
5982 |
|
5983 |
|
5984 |
|
5985 |
|
5986 |
|
5987 |
|
5988 |
|
5989 |
|
5990 |
|
5991 |
|
5992 | __proto.triggerAnimationEnd = function (isTrusted) {
|
5993 | if (isTrusted === void 0) {
|
5994 | isTrusted = false;
|
5995 | }
|
5996 |
|
5997 | this.axes.trigger("animationEnd", {
|
5998 | isTrusted: isTrusted
|
5999 | });
|
6000 | };
|
6001 | |
6002 |
|
6003 |
|
6004 |
|
6005 |
|
6006 |
|
6007 |
|
6008 |
|
6009 |
|
6010 |
|
6011 |
|
6012 |
|
6013 |
|
6014 |
|
6015 |
|
6016 |
|
6017 |
|
6018 |
|
6019 |
|
6020 |
|
6021 |
|
6022 |
|
6023 | __proto.triggerFinish = function (isTrusted) {
|
6024 | if (isTrusted === void 0) {
|
6025 | isTrusted = false;
|
6026 | }
|
6027 |
|
6028 | this.axes.trigger("finish", {
|
6029 | isTrusted: isTrusted
|
6030 | });
|
6031 | };
|
6032 |
|
6033 | __proto.createUserControll = function (pos, duration) {
|
6034 | if (duration === void 0) {
|
6035 | duration = 0;
|
6036 | }
|
6037 |
|
6038 |
|
6039 | var userControl = {
|
6040 | destPos: __assign$1({}, pos),
|
6041 | duration: duration
|
6042 | };
|
6043 | return function (toPos, userDuration) {
|
6044 | toPos && (userControl.destPos = __assign$1({}, toPos));
|
6045 | userDuration !== undefined && (userControl.duration = userDuration);
|
6046 | return userControl;
|
6047 | };
|
6048 | };
|
6049 |
|
6050 | __proto.setAnimationManager = function (am) {
|
6051 | this.am = am;
|
6052 | };
|
6053 |
|
6054 | __proto.destroy = function () {
|
6055 | this.axes.off();
|
6056 | };
|
6057 |
|
6058 | __proto.getRoundPos = function (pos, depaPos) {
|
6059 |
|
6060 | var roundUnit = this.axes.options.round;
|
6061 |
|
6062 |
|
6063 |
|
6064 | return {
|
6065 | roundPos: roundNumbers(pos, roundUnit),
|
6066 | roundDepa: roundNumbers(depaPos, roundUnit)
|
6067 | };
|
6068 | };
|
6069 |
|
6070 | return EventManager;
|
6071 | }();
|
6072 |
|
6073 | var InterruptManager =
|
6074 |
|
6075 | function () {
|
6076 | function InterruptManager(options) {
|
6077 | this.options = options;
|
6078 | this._prevented = false;
|
6079 | }
|
6080 |
|
6081 | var __proto = InterruptManager.prototype;
|
6082 |
|
6083 | __proto.isInterrupting = function () {
|
6084 |
|
6085 | return this.options.interruptable || this._prevented;
|
6086 | };
|
6087 |
|
6088 | __proto.isInterrupted = function () {
|
6089 | return !this.options.interruptable && this._prevented;
|
6090 | };
|
6091 |
|
6092 | __proto.setInterrupt = function (prevented) {
|
6093 | !this.options.interruptable && (this._prevented = prevented);
|
6094 | };
|
6095 |
|
6096 | return InterruptManager;
|
6097 | }();
|
6098 |
|
6099 | var AxisManager =
|
6100 |
|
6101 | function () {
|
6102 | function AxisManager(axis, options) {
|
6103 | var _this = this;
|
6104 |
|
6105 | this.axis = axis;
|
6106 | this.options = options;
|
6107 |
|
6108 | this._complementOptions();
|
6109 |
|
6110 | this._pos = Object.keys(this.axis).reduce(function (acc, v) {
|
6111 | acc[v] = _this.axis[v].range[0];
|
6112 | return acc;
|
6113 | }, {});
|
6114 | }
|
6115 | |
6116 |
|
6117 |
|
6118 |
|
6119 |
|
6120 |
|
6121 | var __proto = AxisManager.prototype;
|
6122 |
|
6123 | __proto._complementOptions = function () {
|
6124 | var _this = this;
|
6125 |
|
6126 | Object.keys(this.axis).forEach(function (axis) {
|
6127 | _this.axis[axis] = __assign$1({
|
6128 | range: [0, 100],
|
6129 | bounce: [0, 0],
|
6130 | circular: [false, false]
|
6131 | }, _this.axis[axis]);
|
6132 | ["bounce", "circular"].forEach(function (v) {
|
6133 | var axisOption = _this.axis;
|
6134 | var key = axisOption[axis][v];
|
6135 |
|
6136 | if (/string|number|boolean/.test(typeof key)) {
|
6137 | axisOption[axis][v] = [key, key];
|
6138 | }
|
6139 | });
|
6140 | });
|
6141 | };
|
6142 |
|
6143 | __proto.getDelta = function (depaPos, destPos) {
|
6144 | var fullDepaPos = this.get(depaPos);
|
6145 | return map(this.get(destPos), function (v, k) {
|
6146 | return v - fullDepaPos[k];
|
6147 | });
|
6148 | };
|
6149 |
|
6150 | __proto.get = function (axes) {
|
6151 | var _this = this;
|
6152 |
|
6153 | if (axes && Array.isArray(axes)) {
|
6154 | return axes.reduce(function (acc, v) {
|
6155 | if (v && v in _this._pos) {
|
6156 | acc[v] = _this._pos[v];
|
6157 | }
|
6158 |
|
6159 | return acc;
|
6160 | }, {});
|
6161 | } else {
|
6162 | return __assign$1(__assign$1({}, this._pos), axes || {});
|
6163 | }
|
6164 | };
|
6165 |
|
6166 | __proto.moveTo = function (pos, depaPos) {
|
6167 | if (depaPos === void 0) {
|
6168 | depaPos = this._pos;
|
6169 | }
|
6170 |
|
6171 | var delta = map(this._pos, function (v, key) {
|
6172 | return key in pos && key in depaPos ? pos[key] - depaPos[key] : 0;
|
6173 | });
|
6174 | this.set(this.map(pos, function (v, opt) {
|
6175 | return opt ? getCirculatedPos(v, opt.range, opt.circular) : 0;
|
6176 | }));
|
6177 | return {
|
6178 | pos: __assign$1({}, this._pos),
|
6179 | delta: delta
|
6180 | };
|
6181 | };
|
6182 |
|
6183 | __proto.set = function (pos) {
|
6184 | for (var k in pos) {
|
6185 | if (k && k in this._pos) {
|
6186 | this._pos[k] = pos[k];
|
6187 | }
|
6188 | }
|
6189 | };
|
6190 |
|
6191 | __proto.every = function (pos, callback) {
|
6192 | var axisOptions = this.axis;
|
6193 | return every(pos, function (value, key) {
|
6194 | return callback(value, axisOptions[key], key);
|
6195 | });
|
6196 | };
|
6197 |
|
6198 | __proto.filter = function (pos, callback) {
|
6199 | var axisOptions = this.axis;
|
6200 | return filter(pos, function (value, key) {
|
6201 | return callback(value, axisOptions[key], key);
|
6202 | });
|
6203 | };
|
6204 |
|
6205 | __proto.map = function (pos, callback) {
|
6206 | var axisOptions = this.axis;
|
6207 | return map(pos, function (value, key) {
|
6208 | return callback(value, axisOptions[key], key);
|
6209 | });
|
6210 | };
|
6211 |
|
6212 | __proto.isOutside = function (axes) {
|
6213 | return !this.every(axes ? this.get(axes) : this._pos, function (v, opt) {
|
6214 | return !isOutside(v, opt.range);
|
6215 | });
|
6216 | };
|
6217 |
|
6218 | __proto.getAxisOptions = function (key) {
|
6219 | return this.axis[key];
|
6220 | };
|
6221 |
|
6222 | return AxisManager;
|
6223 | }();
|
6224 |
|
6225 | var InputObserver =
|
6226 |
|
6227 | function () {
|
6228 | function InputObserver(_a) {
|
6229 | var options = _a.options,
|
6230 | itm = _a.itm,
|
6231 | em = _a.em,
|
6232 | axm = _a.axm,
|
6233 | am = _a.am;
|
6234 | this.isOutside = false;
|
6235 | this.moveDistance = null;
|
6236 | this.isStopped = false;
|
6237 | this.options = options;
|
6238 | this.itm = itm;
|
6239 | this.em = em;
|
6240 | this.axm = axm;
|
6241 | this.am = am;
|
6242 | }
|
6243 |
|
6244 |
|
6245 | var __proto = InputObserver.prototype;
|
6246 |
|
6247 | __proto.atOutside = function (pos) {
|
6248 | var _this = this;
|
6249 |
|
6250 | if (this.isOutside) {
|
6251 | return this.axm.map(pos, function (v, opt) {
|
6252 | var tn = opt.range[0] - opt.bounce[0];
|
6253 | var tx = opt.range[1] + opt.bounce[1];
|
6254 | return v > tx ? tx : v < tn ? tn : v;
|
6255 | });
|
6256 | } else {
|
6257 |
|
6258 |
|
6259 | var initSlope_1 = this.am.easing(0.00001) / 0.00001;
|
6260 | return this.axm.map(pos, function (v, opt) {
|
6261 | var min = opt.range[0];
|
6262 | var max = opt.range[1];
|
6263 | var out = opt.bounce;
|
6264 | var circular = opt.circular;
|
6265 |
|
6266 | if (circular && (circular[0] || circular[1])) {
|
6267 | return v;
|
6268 | } else if (v < min) {
|
6269 |
|
6270 | return min - _this.am.easing((min - v) / (out[0] * initSlope_1)) * out[0];
|
6271 | } else if (v > max) {
|
6272 |
|
6273 | return max + _this.am.easing((v - max) / (out[1] * initSlope_1)) * out[1];
|
6274 | }
|
6275 |
|
6276 | return v;
|
6277 | });
|
6278 | }
|
6279 | };
|
6280 |
|
6281 | __proto.get = function (input) {
|
6282 | return this.axm.get(input.axes);
|
6283 | };
|
6284 |
|
6285 | __proto.hold = function (input, event) {
|
6286 | if (this.itm.isInterrupted() || !input.axes.length) {
|
6287 | return;
|
6288 | }
|
6289 |
|
6290 | var changeOption = {
|
6291 | input: input,
|
6292 | event: event
|
6293 | };
|
6294 | this.isStopped = false;
|
6295 | this.itm.setInterrupt(true);
|
6296 | this.am.grab(input.axes, changeOption);
|
6297 | !this.moveDistance && this.em.triggerHold(this.axm.get(), changeOption);
|
6298 | this.isOutside = this.axm.isOutside(input.axes);
|
6299 | this.moveDistance = this.axm.get(input.axes);
|
6300 | };
|
6301 |
|
6302 | __proto.change = function (input, event, offset) {
|
6303 | if (this.isStopped || !this.itm.isInterrupting() || this.axm.every(offset, function (v) {
|
6304 | return v === 0;
|
6305 | })) {
|
6306 | return;
|
6307 | }
|
6308 |
|
6309 | var depaPos = this.moveDistance || this.axm.get(input.axes);
|
6310 | var destPos;
|
6311 |
|
6312 | destPos = map(depaPos, function (v, k) {
|
6313 | return v + (offset[k] || 0);
|
6314 | });
|
6315 | this.moveDistance && (this.moveDistance = destPos);
|
6316 |
|
6317 | if (this.isOutside && this.axm.every(depaPos, function (v, opt) {
|
6318 | return !isOutside(v, opt.range);
|
6319 | })) {
|
6320 | this.isOutside = false;
|
6321 | }
|
6322 |
|
6323 | depaPos = this.atOutside(depaPos);
|
6324 | destPos = this.atOutside(destPos);
|
6325 | var isCanceled = !this.em.triggerChange(destPos, false, depaPos, {
|
6326 | input: input,
|
6327 | event: event
|
6328 | }, true);
|
6329 |
|
6330 | if (isCanceled) {
|
6331 | this.isStopped = true;
|
6332 | this.moveDistance = null;
|
6333 | this.am.finish(false);
|
6334 | }
|
6335 | };
|
6336 |
|
6337 | __proto.release = function (input, event, offset, inputDuration) {
|
6338 | if (this.isStopped || !this.itm.isInterrupting() || !this.moveDistance) {
|
6339 | return;
|
6340 | }
|
6341 |
|
6342 | var pos = this.axm.get(input.axes);
|
6343 | var depaPos = this.axm.get();
|
6344 | var destPos = this.axm.get(this.axm.map(offset, function (v, opt, k) {
|
6345 | if (opt.circular && (opt.circular[0] || opt.circular[1])) {
|
6346 | return pos[k] + v;
|
6347 | } else {
|
6348 | return getInsidePosition(pos[k] + v, opt.range, opt.circular, opt.bounce);
|
6349 | }
|
6350 | }));
|
6351 | var duration = this.am.getDuration(destPos, pos, inputDuration);
|
6352 |
|
6353 | if (duration === 0) {
|
6354 | destPos = __assign$1({}, depaPos);
|
6355 | }
|
6356 |
|
6357 |
|
6358 | var param = {
|
6359 | depaPos: depaPos,
|
6360 | destPos: destPos,
|
6361 | duration: duration,
|
6362 | delta: this.axm.getDelta(depaPos, destPos),
|
6363 | inputEvent: event,
|
6364 | input: input,
|
6365 | isTrusted: true
|
6366 | };
|
6367 | this.em.triggerRelease(param);
|
6368 | this.moveDistance = null;
|
6369 |
|
6370 | var userWish = this.am.getUserControll(param);
|
6371 | var isEqual = equal(userWish.destPos, depaPos);
|
6372 | var changeOption = {
|
6373 | input: input,
|
6374 | event: event
|
6375 | };
|
6376 |
|
6377 | if (isEqual || userWish.duration === 0) {
|
6378 | !isEqual && this.em.triggerChange(userWish.destPos, false, depaPos, changeOption, true);
|
6379 | this.itm.setInterrupt(false);
|
6380 |
|
6381 | if (this.axm.isOutside()) {
|
6382 | this.am.restore(changeOption);
|
6383 | } else {
|
6384 | this.em.triggerFinish(true);
|
6385 | }
|
6386 | } else {
|
6387 | this.am.animateTo(userWish.destPos, userWish.duration, changeOption);
|
6388 | }
|
6389 | };
|
6390 |
|
6391 | return InputObserver;
|
6392 | }();
|
6393 |
|
6394 |
|
6395 | var IOS_EDGE_THRESHOLD = 30;
|
6396 | var IS_IOS_SAFARI = "ontouchstart" in win && agent().browser.name === "safari";
|
6397 | var TRANSFORM = function () {
|
6398 | if (typeof document === "undefined") {
|
6399 | return "";
|
6400 | }
|
6401 |
|
6402 | var bodyStyle = (document.head || document.getElementsByTagName("head")[0]).style;
|
6403 | var target = ["transform", "webkitTransform", "msTransform", "mozTransform"];
|
6404 |
|
6405 | for (var i = 0, len = target.length; i < len; i++) {
|
6406 | if (target[i] in bodyStyle) {
|
6407 | return target[i];
|
6408 | }
|
6409 | }
|
6410 |
|
6411 | return "";
|
6412 | }();
|
6413 |
|
6414 | |
6415 |
|
6416 |
|
6417 |
|
6418 |
|
6419 |
|
6420 |
|
6421 |
|
6422 |
|
6423 |
|
6424 |
|
6425 |
|
6426 |
|
6427 |
|
6428 | |
6429 |
|
6430 |
|
6431 |
|
6432 |
|
6433 |
|
6434 |
|
6435 |
|
6436 |
|
6437 |
|
6438 |
|
6439 | |
6440 |
|
6441 |
|
6442 |
|
6443 |
|
6444 |
|
6445 |
|
6446 |
|
6447 |
|
6448 |
|
6449 |
|
6450 |
|
6451 |
|
6452 |
|
6453 |
|
6454 |
|
6455 |
|
6456 |
|
6457 |
|
6458 |
|
6459 |
|
6460 |
|
6461 |
|
6462 |
|
6463 |
|
6464 |
|
6465 |
|
6466 |
|
6467 |
|
6468 |
|
6469 |
|
6470 |
|
6471 |
|
6472 |
|
6473 |
|
6474 |
|
6475 |
|
6476 |
|
6477 |
|
6478 |
|
6479 |
|
6480 |
|
6481 |
|
6482 |
|
6483 |
|
6484 |
|
6485 |
|
6486 |
|
6487 |
|
6488 |
|
6489 |
|
6490 |
|
6491 |
|
6492 |
|
6493 |
|
6494 |
|
6495 |
|
6496 |
|
6497 |
|
6498 |
|
6499 |
|
6500 |
|
6501 |
|
6502 |
|
6503 |
|
6504 |
|
6505 |
|
6506 |
|
6507 |
|
6508 |
|
6509 | var Axes =
|
6510 |
|
6511 | function (_super) {
|
6512 | __extends$1(Axes, _super);
|
6513 |
|
6514 | function Axes(axis, options, startPos) {
|
6515 | if (axis === void 0) {
|
6516 | axis = {};
|
6517 | }
|
6518 |
|
6519 | if (options === void 0) {
|
6520 | options = {};
|
6521 | }
|
6522 |
|
6523 | var _this = _super.call(this) || this;
|
6524 |
|
6525 | _this.axis = axis;
|
6526 | _this._inputs = [];
|
6527 | _this.options = __assign$1({
|
6528 | easing: function easeOutCubic(x) {
|
6529 | return 1 - Math.pow(1 - x, 3);
|
6530 | },
|
6531 | interruptable: true,
|
6532 | maximumDuration: Infinity,
|
6533 | minimumDuration: 0,
|
6534 | deceleration: 0.0006,
|
6535 | round: null
|
6536 | }, options);
|
6537 | _this.itm = new InterruptManager(_this.options);
|
6538 | _this.axm = new AxisManager(_this.axis, _this.options);
|
6539 | _this.em = new EventManager(_this);
|
6540 | _this.am = new AnimationManager(_this);
|
6541 | _this.io = new InputObserver(_this);
|
6542 |
|
6543 | _this.em.setAnimationManager(_this.am);
|
6544 |
|
6545 | startPos && _this.em.triggerChange(startPos);
|
6546 | return _this;
|
6547 | }
|
6548 | |
6549 |
|
6550 |
|
6551 |
|
6552 |
|
6553 |
|
6554 |
|
6555 |
|
6556 |
|
6557 |
|
6558 |
|
6559 |
|
6560 |
|
6561 |
|
6562 |
|
6563 |
|
6564 |
|
6565 |
|
6566 |
|
6567 |
|
6568 |
|
6569 |
|
6570 |
|
6571 |
|
6572 |
|
6573 |
|
6574 | var __proto = Axes.prototype;
|
6575 |
|
6576 | __proto.connect = function (axes, inputType) {
|
6577 | var mapped;
|
6578 |
|
6579 | if (typeof axes === "string") {
|
6580 | mapped = axes.split(" ");
|
6581 | } else {
|
6582 | mapped = axes.concat();
|
6583 | }
|
6584 |
|
6585 |
|
6586 | if (~this._inputs.indexOf(inputType)) {
|
6587 | this.disconnect(inputType);
|
6588 | }
|
6589 |
|
6590 |
|
6591 | if ("hammer" in inputType) {
|
6592 | var targets = this._inputs.filter(function (v) {
|
6593 | return v.hammer && v.element === inputType.element;
|
6594 | });
|
6595 |
|
6596 | if (targets.length) {
|
6597 | inputType.hammer = targets[0].hammer;
|
6598 | }
|
6599 | }
|
6600 |
|
6601 | inputType.mapAxes(mapped);
|
6602 | inputType.connect(this.io);
|
6603 |
|
6604 | this._inputs.push(inputType);
|
6605 |
|
6606 | return this;
|
6607 | };
|
6608 | |
6609 |
|
6610 |
|
6611 |
|
6612 |
|
6613 |
|
6614 |
|
6615 |
|
6616 |
|
6617 |
|
6618 |
|
6619 |
|
6620 |
|
6621 |
|
6622 |
|
6623 |
|
6624 |
|
6625 |
|
6626 |
|
6627 |
|
6628 |
|
6629 |
|
6630 |
|
6631 |
|
6632 |
|
6633 |
|
6634 |
|
6635 |
|
6636 |
|
6637 | __proto.disconnect = function (inputType) {
|
6638 | if (inputType) {
|
6639 | var index = this._inputs.indexOf(inputType);
|
6640 |
|
6641 | if (index >= 0) {
|
6642 | this._inputs[index].disconnect();
|
6643 |
|
6644 | this._inputs.splice(index, 1);
|
6645 | }
|
6646 | } else {
|
6647 | this._inputs.forEach(function (v) {
|
6648 | return v.disconnect();
|
6649 | });
|
6650 |
|
6651 | this._inputs = [];
|
6652 | }
|
6653 |
|
6654 | return this;
|
6655 | };
|
6656 | |
6657 |
|
6658 |
|
6659 |
|
6660 |
|
6661 |
|
6662 |
|
6663 |
|
6664 |
|
6665 |
|
6666 |
|
6667 |
|
6668 |
|
6669 |
|
6670 |
|
6671 |
|
6672 |
|
6673 |
|
6674 |
|
6675 |
|
6676 |
|
6677 |
|
6678 |
|
6679 |
|
6680 | __proto.get = function (axes) {
|
6681 | return this.axm.get(axes);
|
6682 | };
|
6683 | |
6684 |
|
6685 |
|
6686 |
|
6687 |
|
6688 |
|
6689 |
|
6690 |
|
6691 |
|
6692 |
|
6693 |
|
6694 |
|
6695 |
|
6696 |
|
6697 |
|
6698 |
|
6699 |
|
6700 |
|
6701 |
|
6702 |
|
6703 |
|
6704 |
|
6705 |
|
6706 |
|
6707 |
|
6708 |
|
6709 |
|
6710 |
|
6711 |
|
6712 |
|
6713 | __proto.setTo = function (pos, duration) {
|
6714 | if (duration === void 0) {
|
6715 | duration = 0;
|
6716 | }
|
6717 |
|
6718 | this.am.setTo(pos, duration);
|
6719 | return this;
|
6720 | };
|
6721 | |
6722 |
|
6723 |
|
6724 |
|
6725 |
|
6726 |
|
6727 |
|
6728 |
|
6729 |
|
6730 |
|
6731 |
|
6732 |
|
6733 |
|
6734 |
|
6735 |
|
6736 |
|
6737 |
|
6738 |
|
6739 |
|
6740 |
|
6741 |
|
6742 |
|
6743 |
|
6744 |
|
6745 |
|
6746 |
|
6747 |
|
6748 |
|
6749 |
|
6750 |
|
6751 | __proto.setBy = function (pos, duration) {
|
6752 | if (duration === void 0) {
|
6753 | duration = 0;
|
6754 | }
|
6755 |
|
6756 | this.am.setBy(pos, duration);
|
6757 | return this;
|
6758 | };
|
6759 | |
6760 |
|
6761 |
|
6762 |
|
6763 |
|
6764 |
|
6765 |
|
6766 |
|
6767 |
|
6768 |
|
6769 |
|
6770 |
|
6771 |
|
6772 |
|
6773 |
|
6774 |
|
6775 |
|
6776 |
|
6777 |
|
6778 |
|
6779 |
|
6780 |
|
6781 |
|
6782 |
|
6783 |
|
6784 | __proto.isBounceArea = function (axes) {
|
6785 | return this.axm.isOutside(axes);
|
6786 | };
|
6787 | |
6788 |
|
6789 |
|
6790 |
|
6791 |
|
6792 |
|
6793 |
|
6794 | __proto.destroy = function () {
|
6795 | this.disconnect();
|
6796 | this.em.destroy();
|
6797 | };
|
6798 | |
6799 |
|
6800 |
|
6801 |
|
6802 |
|
6803 |
|
6804 |
|
6805 |
|
6806 |
|
6807 |
|
6808 |
|
6809 |
|
6810 | Axes.VERSION = "2.8.0";
|
6811 | |
6812 |
|
6813 |
|
6814 |
|
6815 |
|
6816 |
|
6817 |
|
6818 |
|
6819 |
|
6820 |
|
6821 |
|
6822 | Axes.TRANSFORM = TRANSFORM;
|
6823 | |
6824 |
|
6825 |
|
6826 |
|
6827 |
|
6828 |
|
6829 | Axes.DIRECTION_NONE = DIRECTION_NONE;
|
6830 | |
6831 |
|
6832 |
|
6833 |
|
6834 |
|
6835 |
|
6836 | Axes.DIRECTION_LEFT = DIRECTION_LEFT;
|
6837 | |
6838 |
|
6839 |
|
6840 |
|
6841 |
|
6842 |
|
6843 | Axes.DIRECTION_RIGHT = DIRECTION_RIGHT;
|
6844 | |
6845 |
|
6846 |
|
6847 |
|
6848 |
|
6849 |
|
6850 | Axes.DIRECTION_UP = DIRECTION_UP;
|
6851 | |
6852 |
|
6853 |
|
6854 |
|
6855 |
|
6856 |
|
6857 | Axes.DIRECTION_DOWN = DIRECTION_DOWN;
|
6858 | |
6859 |
|
6860 |
|
6861 |
|
6862 |
|
6863 |
|
6864 | Axes.DIRECTION_HORIZONTAL = DIRECTION_HORIZONTAL;
|
6865 | |
6866 |
|
6867 |
|
6868 |
|
6869 |
|
6870 |
|
6871 | Axes.DIRECTION_VERTICAL = DIRECTION_VERTICAL;
|
6872 | |
6873 |
|
6874 |
|
6875 |
|
6876 |
|
6877 |
|
6878 | Axes.DIRECTION_ALL = DIRECTION_ALL;
|
6879 | return Axes;
|
6880 | }(Component$1);
|
6881 |
|
6882 | var SUPPORT_POINTER_EVENTS = "PointerEvent" in win || "MSPointerEvent" in win;
|
6883 | var SUPPORT_TOUCH = ("ontouchstart" in win);
|
6884 | var UNIQUEKEY = "_EGJS_AXES_INPUTTYPE_";
|
6885 | function toAxis(source, offset) {
|
6886 | return offset.reduce(function (acc, v, i) {
|
6887 | if (source[i]) {
|
6888 | acc[source[i]] = v;
|
6889 | }
|
6890 |
|
6891 | return acc;
|
6892 | }, {});
|
6893 | }
|
6894 | function createHammer(element, options) {
|
6895 | try {
|
6896 |
|
6897 | return new Manager(element, __assign$1({}, options));
|
6898 | } catch (e) {
|
6899 | return null;
|
6900 | }
|
6901 | }
|
6902 | function convertInputType(inputType) {
|
6903 | if (inputType === void 0) {
|
6904 | inputType = [];
|
6905 | }
|
6906 |
|
6907 | var hasTouch = false;
|
6908 | var hasMouse = false;
|
6909 | var hasPointer = false;
|
6910 | inputType.forEach(function (v) {
|
6911 | switch (v) {
|
6912 | case "mouse":
|
6913 | hasMouse = true;
|
6914 | break;
|
6915 |
|
6916 | case "touch":
|
6917 | hasTouch = SUPPORT_TOUCH;
|
6918 | break;
|
6919 |
|
6920 | case "pointer":
|
6921 | hasPointer = SUPPORT_POINTER_EVENTS;
|
6922 |
|
6923 | }
|
6924 | });
|
6925 |
|
6926 | if (hasPointer) {
|
6927 | return PointerEventInput;
|
6928 | } else if (hasTouch && hasMouse) {
|
6929 | return TouchMouseInput;
|
6930 | } else if (hasTouch) {
|
6931 | return TouchInput;
|
6932 | } else if (hasMouse) {
|
6933 | return MouseInput;
|
6934 | }
|
6935 |
|
6936 | return null;
|
6937 | }
|
6938 |
|
6939 | function getDirectionByAngle(angle, thresholdAngle) {
|
6940 | if (thresholdAngle < 0 || thresholdAngle > 90) {
|
6941 | return DIRECTION_NONE;
|
6942 | }
|
6943 |
|
6944 | var toAngle = Math.abs(angle);
|
6945 | return toAngle > thresholdAngle && toAngle < 180 - thresholdAngle ? DIRECTION_VERTICAL : DIRECTION_HORIZONTAL;
|
6946 | }
|
6947 | function getNextOffset(speeds, deceleration) {
|
6948 | var normalSpeed = Math.sqrt(speeds[0] * speeds[0] + speeds[1] * speeds[1]);
|
6949 | var duration = Math.abs(normalSpeed / -deceleration);
|
6950 | return [speeds[0] / 2 * duration, speeds[1] / 2 * duration];
|
6951 | }
|
6952 | function useDirection(checkType, direction, userDirection) {
|
6953 | if (userDirection) {
|
6954 | return !!(direction === DIRECTION_ALL || direction & checkType && userDirection & checkType);
|
6955 | } else {
|
6956 | return !!(direction & checkType);
|
6957 | }
|
6958 | }
|
6959 | |
6960 |
|
6961 |
|
6962 |
|
6963 |
|
6964 |
|
6965 |
|
6966 |
|
6967 |
|
6968 |
|
6969 |
|
6970 |
|
6971 |
|
6972 | |
6973 |
|
6974 |
|
6975 |
|
6976 |
|
6977 |
|
6978 |
|
6979 |
|
6980 |
|
6981 |
|
6982 |
|
6983 |
|
6984 |
|
6985 |
|
6986 |
|
6987 |
|
6988 |
|
6989 |
|
6990 |
|
6991 |
|
6992 |
|
6993 |
|
6994 |
|
6995 |
|
6996 |
|
6997 | var PanInput =
|
6998 |
|
6999 | function () {
|
7000 | function PanInput(el, options) {
|
7001 | this.axes = [];
|
7002 | this.hammer = null;
|
7003 | this.element = null;
|
7004 | this.panRecognizer = null;
|
7005 | this.isRightEdge = false;
|
7006 | this.rightEdgeTimer = 0;
|
7007 | this.panFlag = false;
|
7008 | |
7009 |
|
7010 |
|
7011 |
|
7012 |
|
7013 |
|
7014 |
|
7015 |
|
7016 |
|
7017 | if (typeof Manager === "undefined") {
|
7018 | throw new Error("The Hammerjs must be loaded before eg.Axes.PanInput.\nhttp://hammerjs.github.io/");
|
7019 | }
|
7020 |
|
7021 | this.element = $(el);
|
7022 | this.options = __assign$1({
|
7023 | inputType: ["touch", "mouse", "pointer"],
|
7024 | scale: [1, 1],
|
7025 | thresholdAngle: 45,
|
7026 | threshold: 0,
|
7027 | iOSEdgeSwipeThreshold: IOS_EDGE_THRESHOLD,
|
7028 | releaseOnScroll: false,
|
7029 | hammerManagerOptions: {
|
7030 |
|
7031 |
|
7032 | cssProps: {
|
7033 | userSelect: "none",
|
7034 | touchSelect: "none",
|
7035 | touchCallout: "none",
|
7036 | userDrag: "none"
|
7037 | }
|
7038 | }
|
7039 | }, options);
|
7040 | this.onHammerInput = this.onHammerInput.bind(this);
|
7041 | this.onPanmove = this.onPanmove.bind(this);
|
7042 | this.onPanend = this.onPanend.bind(this);
|
7043 | }
|
7044 |
|
7045 | var __proto = PanInput.prototype;
|
7046 |
|
7047 | __proto.mapAxes = function (axes) {
|
7048 | var useHorizontal = !!axes[0];
|
7049 | var useVertical = !!axes[1];
|
7050 |
|
7051 | if (useHorizontal && useVertical) {
|
7052 | this._direction = DIRECTION_ALL;
|
7053 | } else if (useHorizontal) {
|
7054 | this._direction = DIRECTION_HORIZONTAL;
|
7055 | } else if (useVertical) {
|
7056 | this._direction = DIRECTION_VERTICAL;
|
7057 | } else {
|
7058 | this._direction = DIRECTION_NONE;
|
7059 | }
|
7060 |
|
7061 | this.axes = axes;
|
7062 | };
|
7063 |
|
7064 | __proto.connect = function (observer) {
|
7065 | var hammerOption = {
|
7066 | direction: this._direction,
|
7067 | threshold: this.options.threshold
|
7068 | };
|
7069 |
|
7070 | if (this.hammer) {
|
7071 |
|
7072 |
|
7073 | this.removeRecognizer();
|
7074 | this.dettachEvent();
|
7075 | } else {
|
7076 | var keyValue = this.element[UNIQUEKEY];
|
7077 |
|
7078 | if (!keyValue) {
|
7079 | keyValue = String(Math.round(Math.random() * new Date().getTime()));
|
7080 | }
|
7081 |
|
7082 | var inputClass = convertInputType(this.options.inputType);
|
7083 |
|
7084 | if (!inputClass) {
|
7085 | throw new Error("Wrong inputType parameter!");
|
7086 | }
|
7087 |
|
7088 | this.hammer = createHammer(this.element, __assign$1({
|
7089 | inputClass: inputClass
|
7090 | }, this.options.hammerManagerOptions));
|
7091 | this.element[UNIQUEKEY] = keyValue;
|
7092 | }
|
7093 |
|
7094 | this.panRecognizer = new PanRecognizer(hammerOption);
|
7095 | this.hammer.add(this.panRecognizer);
|
7096 | this.attachEvent(observer);
|
7097 | return this;
|
7098 | };
|
7099 |
|
7100 | __proto.disconnect = function () {
|
7101 | this.removeRecognizer();
|
7102 |
|
7103 | if (this.hammer) {
|
7104 | this.dettachEvent();
|
7105 | }
|
7106 |
|
7107 | this._direction = DIRECTION_NONE;
|
7108 | return this;
|
7109 | };
|
7110 | |
7111 |
|
7112 |
|
7113 |
|
7114 |
|
7115 |
|
7116 |
|
7117 | __proto.destroy = function () {
|
7118 | this.disconnect();
|
7119 |
|
7120 | if (this.hammer && this.hammer.recognizers.length === 0) {
|
7121 | this.hammer.destroy();
|
7122 | }
|
7123 |
|
7124 | delete this.element[UNIQUEKEY];
|
7125 | this.element = null;
|
7126 | this.hammer = null;
|
7127 | };
|
7128 | |
7129 |
|
7130 |
|
7131 |
|
7132 |
|
7133 |
|
7134 |
|
7135 |
|
7136 | __proto.enable = function () {
|
7137 | this.hammer && (this.hammer.get("pan").options.enable = true);
|
7138 | return this;
|
7139 | };
|
7140 | |
7141 |
|
7142 |
|
7143 |
|
7144 |
|
7145 |
|
7146 |
|
7147 |
|
7148 | __proto.disable = function () {
|
7149 | this.hammer && (this.hammer.get("pan").options.enable = false);
|
7150 | return this;
|
7151 | };
|
7152 | |
7153 |
|
7154 |
|
7155 |
|
7156 |
|
7157 |
|
7158 |
|
7159 |
|
7160 | __proto.isEnable = function () {
|
7161 | return !!(this.hammer && this.hammer.get("pan").options.enable);
|
7162 | };
|
7163 |
|
7164 | __proto.removeRecognizer = function () {
|
7165 | if (this.hammer && this.panRecognizer) {
|
7166 | this.hammer.remove(this.panRecognizer);
|
7167 | this.panRecognizer = null;
|
7168 | }
|
7169 | };
|
7170 |
|
7171 | __proto.onHammerInput = function (event) {
|
7172 | if (this.isEnable()) {
|
7173 | if (event.isFirst) {
|
7174 | this.panFlag = false;
|
7175 |
|
7176 | if (event.srcEvent.cancelable !== false) {
|
7177 | var edgeThreshold = this.options.iOSEdgeSwipeThreshold;
|
7178 | this.observer.hold(this, event);
|
7179 | this.isRightEdge = IS_IOS_SAFARI && event.center.x > window.innerWidth - edgeThreshold;
|
7180 | this.panFlag = true;
|
7181 | }
|
7182 | } else if (event.isFinal) {
|
7183 | this.onPanend(event);
|
7184 | }
|
7185 | }
|
7186 | };
|
7187 |
|
7188 | __proto.onPanmove = function (event) {
|
7189 | var _this = this;
|
7190 |
|
7191 | if (!this.panFlag) {
|
7192 | return;
|
7193 | }
|
7194 |
|
7195 | var _a = this.options,
|
7196 | iOSEdgeSwipeThreshold = _a.iOSEdgeSwipeThreshold,
|
7197 | releaseOnScroll = _a.releaseOnScroll;
|
7198 | var userDirection = getDirectionByAngle(event.angle, this.options.thresholdAngle);
|
7199 |
|
7200 | var prevInput = this.hammer.session.prevInput;
|
7201 |
|
7202 | if (releaseOnScroll && !event.srcEvent.cancelable) {
|
7203 | this.onPanend(__assign$1(__assign$1({}, event), {
|
7204 | velocityX: 0,
|
7205 | velocityY: 0,
|
7206 | offsetX: 0,
|
7207 | offsetY: 0
|
7208 | }));
|
7209 | return;
|
7210 | }
|
7211 |
|
7212 | if (prevInput && IS_IOS_SAFARI) {
|
7213 | var swipeLeftToRight = event.center.x < 0;
|
7214 |
|
7215 | if (swipeLeftToRight) {
|
7216 |
|
7217 | this.onPanend(__assign$1(__assign$1({}, prevInput), {
|
7218 | velocityX: 0,
|
7219 | velocityY: 0,
|
7220 | offsetX: 0,
|
7221 | offsetY: 0
|
7222 | }));
|
7223 | return;
|
7224 | } else if (this.isRightEdge) {
|
7225 | clearTimeout(this.rightEdgeTimer);
|
7226 |
|
7227 | var swipeRightToLeft = event.deltaX < -iOSEdgeSwipeThreshold;
|
7228 |
|
7229 | if (swipeRightToLeft) {
|
7230 | this.isRightEdge = false;
|
7231 | } else {
|
7232 |
|
7233 | this.rightEdgeTimer = window.setTimeout(function () {
|
7234 | _this.onPanend(__assign$1(__assign$1({}, prevInput), {
|
7235 | velocityX: 0,
|
7236 | velocityY: 0,
|
7237 | offsetX: 0,
|
7238 | offsetY: 0
|
7239 | }));
|
7240 | }, 100);
|
7241 | }
|
7242 | }
|
7243 | }
|
7244 |
|
7245 |
|
7246 |
|
7247 | if (prevInput) {
|
7248 | event.offsetX = event.deltaX - prevInput.deltaX;
|
7249 | event.offsetY = event.deltaY - prevInput.deltaY;
|
7250 | } else {
|
7251 | event.offsetX = 0;
|
7252 | event.offsetY = 0;
|
7253 | }
|
7254 |
|
7255 | var offset = this.getOffset([event.offsetX, event.offsetY], [useDirection(DIRECTION_HORIZONTAL, this._direction, userDirection), useDirection(DIRECTION_VERTICAL, this._direction, userDirection)]);
|
7256 | var prevent = offset.some(function (v) {
|
7257 | return v !== 0;
|
7258 | });
|
7259 |
|
7260 | if (prevent) {
|
7261 | var srcEvent = event.srcEvent;
|
7262 |
|
7263 | if (srcEvent.cancelable !== false) {
|
7264 | srcEvent.preventDefault();
|
7265 | }
|
7266 |
|
7267 | srcEvent.stopPropagation();
|
7268 | }
|
7269 |
|
7270 | event.preventSystemEvent = prevent;
|
7271 | prevent && this.observer.change(this, event, toAxis(this.axes, offset));
|
7272 | };
|
7273 |
|
7274 | __proto.onPanend = function (event) {
|
7275 | if (!this.panFlag) {
|
7276 | return;
|
7277 | }
|
7278 |
|
7279 | clearTimeout(this.rightEdgeTimer);
|
7280 | this.panFlag = false;
|
7281 | var offset = this.getOffset([Math.abs(event.velocityX) * (event.deltaX < 0 ? -1 : 1), Math.abs(event.velocityY) * (event.deltaY < 0 ? -1 : 1)], [useDirection(DIRECTION_HORIZONTAL, this._direction), useDirection(DIRECTION_VERTICAL, this._direction)]);
|
7282 | offset = getNextOffset(offset, this.observer.options.deceleration);
|
7283 | this.observer.release(this, event, toAxis(this.axes, offset));
|
7284 | };
|
7285 |
|
7286 | __proto.attachEvent = function (observer) {
|
7287 | this.observer = observer;
|
7288 | this.hammer.on("hammer.input", this.onHammerInput).on("panstart panmove", this.onPanmove);
|
7289 | };
|
7290 |
|
7291 | __proto.dettachEvent = function () {
|
7292 | this.hammer.off("hammer.input", this.onHammerInput).off("panstart panmove", this.onPanmove);
|
7293 | this.observer = null;
|
7294 | };
|
7295 |
|
7296 | __proto.getOffset = function (properties, direction) {
|
7297 | var offset = [0, 0];
|
7298 | var scale = this.options.scale;
|
7299 |
|
7300 | if (direction[0]) {
|
7301 | offset[0] = properties[0] * scale[0];
|
7302 | }
|
7303 |
|
7304 | if (direction[1]) {
|
7305 | offset[1] = properties[1] * scale[1];
|
7306 | }
|
7307 |
|
7308 | return offset;
|
7309 | };
|
7310 |
|
7311 | return PanInput;
|
7312 | }();
|
7313 |
|
7314 | var Axes$1 = Axes;
|
7315 |
|
7316 | |
7317 |
|
7318 |
|
7319 |
|
7320 | var EVENT = {
|
7321 | HOLD: "hold",
|
7322 | CHANGE: "change",
|
7323 | RELEASE: "release",
|
7324 | ANIMATION_END: "animationEnd",
|
7325 | FINISH: "finish"
|
7326 | };
|
7327 | |
7328 |
|
7329 |
|
7330 |
|
7331 |
|
7332 | var POSITION_KEY = "flick";
|
7333 |
|
7334 | var STATE_TYPE;
|
7335 |
|
7336 | (function (STATE_TYPE) {
|
7337 | STATE_TYPE[STATE_TYPE["IDLE"] = 0] = "IDLE";
|
7338 | STATE_TYPE[STATE_TYPE["HOLDING"] = 1] = "HOLDING";
|
7339 | STATE_TYPE[STATE_TYPE["DRAGGING"] = 2] = "DRAGGING";
|
7340 | STATE_TYPE[STATE_TYPE["ANIMATING"] = 3] = "ANIMATING";
|
7341 | STATE_TYPE[STATE_TYPE["DISABLED"] = 4] = "DISABLED";
|
7342 | })(STATE_TYPE || (STATE_TYPE = {}));
|
7343 | |
7344 |
|
7345 |
|
7346 |
|
7347 |
|
7348 |
|
7349 |
|
7350 | var State = function () {
|
7351 | function State() {
|
7352 | this._delta = 0;
|
7353 | this._targetPanel = null;
|
7354 | }
|
7355 |
|
7356 | var __proto = State.prototype;
|
7357 | Object.defineProperty(__proto, "delta", {
|
7358 | |
7359 |
|
7360 |
|
7361 |
|
7362 |
|
7363 |
|
7364 | get: function () {
|
7365 | return this._delta;
|
7366 | },
|
7367 | enumerable: false,
|
7368 | configurable: true
|
7369 | });
|
7370 | Object.defineProperty(__proto, "targetPanel", {
|
7371 | |
7372 |
|
7373 |
|
7374 |
|
7375 |
|
7376 |
|
7377 | get: function () {
|
7378 | return this._targetPanel;
|
7379 | },
|
7380 | set: function (val) {
|
7381 | this._targetPanel = val;
|
7382 | },
|
7383 | enumerable: false,
|
7384 | configurable: true
|
7385 | });
|
7386 | |
7387 |
|
7388 |
|
7389 |
|
7390 |
|
7391 |
|
7392 |
|
7393 | __proto.onEnter = function (prevState) {
|
7394 | this._delta = prevState._delta;
|
7395 | this._targetPanel = prevState._targetPanel;
|
7396 | };
|
7397 | |
7398 |
|
7399 |
|
7400 |
|
7401 |
|
7402 |
|
7403 |
|
7404 |
|
7405 |
|
7406 |
|
7407 |
|
7408 |
|
7409 | __proto.onHold = function (ctx) {
|
7410 | };
|
7411 | |
7412 |
|
7413 |
|
7414 |
|
7415 |
|
7416 |
|
7417 |
|
7418 |
|
7419 |
|
7420 |
|
7421 |
|
7422 |
|
7423 | __proto.onChange = function (ctx) {
|
7424 | };
|
7425 | |
7426 |
|
7427 |
|
7428 |
|
7429 |
|
7430 |
|
7431 |
|
7432 |
|
7433 |
|
7434 |
|
7435 |
|
7436 |
|
7437 | __proto.onRelease = function (ctx) {
|
7438 | };
|
7439 | |
7440 |
|
7441 |
|
7442 |
|
7443 |
|
7444 |
|
7445 |
|
7446 |
|
7447 |
|
7448 |
|
7449 |
|
7450 |
|
7451 | __proto.onAnimationEnd = function (ctx) {
|
7452 | };
|
7453 | |
7454 |
|
7455 |
|
7456 |
|
7457 |
|
7458 |
|
7459 |
|
7460 |
|
7461 |
|
7462 |
|
7463 |
|
7464 | __proto.onFinish = function (ctx) {
|
7465 | };
|
7466 |
|
7467 | __proto._moveToChangedPosition = function (ctx) {
|
7468 | var flicking = ctx.flicking,
|
7469 | axesEvent = ctx.axesEvent,
|
7470 | transitTo = ctx.transitTo;
|
7471 | var delta = axesEvent.delta[POSITION_KEY];
|
7472 |
|
7473 | if (!delta) {
|
7474 | return;
|
7475 | }
|
7476 |
|
7477 | this._delta += delta;
|
7478 | var camera = flicking.camera;
|
7479 | var prevPosition = camera.position;
|
7480 | var position = axesEvent.pos[POSITION_KEY];
|
7481 | var newPosition = flicking.circularEnabled ? circulatePosition(position, camera.range.min, camera.range.max) : position;
|
7482 | camera.lookAt(newPosition);
|
7483 | var moveEvent = new ComponentEvent$1(EVENTS.MOVE, {
|
7484 | isTrusted: axesEvent.isTrusted,
|
7485 | holding: this.holding,
|
7486 | direction: getDirection$1(0, axesEvent.delta[POSITION_KEY]),
|
7487 | axesEvent: axesEvent
|
7488 | });
|
7489 | flicking.trigger(moveEvent);
|
7490 |
|
7491 | if (moveEvent.isCanceled()) {
|
7492 |
|
7493 | camera.lookAt(prevPosition);
|
7494 | transitTo(STATE_TYPE.DISABLED);
|
7495 | }
|
7496 | };
|
7497 |
|
7498 | return State;
|
7499 | }();
|
7500 |
|
7501 | |
7502 |
|
7503 |
|
7504 |
|
7505 |
|
7506 |
|
7507 | var IdleState = function (_super) {
|
7508 | __extends$2(IdleState, _super);
|
7509 |
|
7510 | function IdleState() {
|
7511 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
7512 | |
7513 |
|
7514 |
|
7515 |
|
7516 |
|
7517 |
|
7518 |
|
7519 |
|
7520 | _this.holding = false;
|
7521 | |
7522 |
|
7523 |
|
7524 |
|
7525 |
|
7526 |
|
7527 |
|
7528 | _this.animating = false;
|
7529 | return _this;
|
7530 | }
|
7531 |
|
7532 | var __proto = IdleState.prototype;
|
7533 |
|
7534 | __proto.onEnter = function () {
|
7535 | this._delta = 0;
|
7536 | this._targetPanel = null;
|
7537 | };
|
7538 |
|
7539 | __proto.onHold = function (ctx) {
|
7540 |
|
7541 | var flicking = ctx.flicking,
|
7542 | axesEvent = ctx.axesEvent,
|
7543 | transitTo = ctx.transitTo;
|
7544 |
|
7545 | if (flicking.renderer.panelCount <= 0) {
|
7546 | transitTo(STATE_TYPE.DISABLED);
|
7547 | return;
|
7548 | }
|
7549 |
|
7550 | var holdStartEvent = new ComponentEvent$1(EVENTS.HOLD_START, {
|
7551 | axesEvent: axesEvent
|
7552 | });
|
7553 | flicking.trigger(holdStartEvent);
|
7554 |
|
7555 | if (holdStartEvent.isCanceled()) {
|
7556 | transitTo(STATE_TYPE.DISABLED);
|
7557 | } else {
|
7558 | transitTo(STATE_TYPE.HOLDING);
|
7559 | }
|
7560 | };
|
7561 |
|
7562 |
|
7563 | __proto.onChange = function (ctx) {
|
7564 | var flicking = ctx.flicking,
|
7565 | axesEvent = ctx.axesEvent,
|
7566 | transitTo = ctx.transitTo;
|
7567 | var controller = flicking.control.controller;
|
7568 | var animatingContext = controller.animatingContext;
|
7569 | var moveStartEvent = new ComponentEvent$1(EVENTS.MOVE_START, {
|
7570 | isTrusted: axesEvent.isTrusted,
|
7571 | holding: this.holding,
|
7572 | direction: getDirection$1(animatingContext.start, animatingContext.end),
|
7573 | axesEvent: axesEvent
|
7574 | });
|
7575 | flicking.trigger(moveStartEvent);
|
7576 |
|
7577 | if (moveStartEvent.isCanceled()) {
|
7578 | transitTo(STATE_TYPE.DISABLED);
|
7579 | } else {
|
7580 |
|
7581 | transitTo(STATE_TYPE.ANIMATING).onChange(ctx);
|
7582 | }
|
7583 | };
|
7584 |
|
7585 | return IdleState;
|
7586 | }(State);
|
7587 |
|
7588 | |
7589 |
|
7590 |
|
7591 |
|
7592 |
|
7593 |
|
7594 | var HoldingState = function (_super) {
|
7595 | __extends$2(HoldingState, _super);
|
7596 |
|
7597 | function HoldingState() {
|
7598 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
7599 | |
7600 |
|
7601 |
|
7602 |
|
7603 |
|
7604 |
|
7605 |
|
7606 |
|
7607 | _this.holding = true;
|
7608 | |
7609 |
|
7610 |
|
7611 |
|
7612 |
|
7613 |
|
7614 |
|
7615 | _this.animating = false;
|
7616 | _this._releaseEvent = null;
|
7617 | return _this;
|
7618 | }
|
7619 |
|
7620 | var __proto = HoldingState.prototype;
|
7621 |
|
7622 | __proto.onChange = function (ctx) {
|
7623 | var flicking = ctx.flicking,
|
7624 | axesEvent = ctx.axesEvent,
|
7625 | transitTo = ctx.transitTo;
|
7626 | var inputEvent = axesEvent.inputEvent;
|
7627 | var offset = flicking.horizontal ? inputEvent.offsetX : inputEvent.offsetY;
|
7628 | var moveStartEvent = new ComponentEvent$1(EVENTS.MOVE_START, {
|
7629 | isTrusted: axesEvent.isTrusted,
|
7630 | holding: this.holding,
|
7631 | direction: getDirection$1(0, -offset),
|
7632 | axesEvent: axesEvent
|
7633 | });
|
7634 | flicking.trigger(moveStartEvent);
|
7635 |
|
7636 | if (moveStartEvent.isCanceled()) {
|
7637 | transitTo(STATE_TYPE.DISABLED);
|
7638 | } else {
|
7639 |
|
7640 | transitTo(STATE_TYPE.DRAGGING).onChange(ctx);
|
7641 | }
|
7642 | };
|
7643 |
|
7644 | __proto.onRelease = function (ctx) {
|
7645 | var flicking = ctx.flicking,
|
7646 | axesEvent = ctx.axesEvent,
|
7647 | transitTo = ctx.transitTo;
|
7648 | flicking.trigger(new ComponentEvent$1(EVENTS.HOLD_END, {
|
7649 | axesEvent: axesEvent
|
7650 | }));
|
7651 |
|
7652 | if (axesEvent.delta.flick !== 0) {
|
7653 |
|
7654 |
|
7655 |
|
7656 |
|
7657 |
|
7658 | axesEvent.setTo({
|
7659 | flick: flicking.camera.position
|
7660 | }, 0);
|
7661 | transitTo(STATE_TYPE.IDLE);
|
7662 | return;
|
7663 | }
|
7664 |
|
7665 |
|
7666 |
|
7667 | this._releaseEvent = axesEvent;
|
7668 | };
|
7669 |
|
7670 | __proto.onFinish = function (ctx) {
|
7671 | var e_1, _a;
|
7672 |
|
7673 | var flicking = ctx.flicking,
|
7674 | transitTo = ctx.transitTo;
|
7675 |
|
7676 |
|
7677 | transitTo(STATE_TYPE.IDLE);
|
7678 |
|
7679 | if (!this._releaseEvent) {
|
7680 | return;
|
7681 | }
|
7682 |
|
7683 |
|
7684 |
|
7685 | var releaseEvent = this._releaseEvent;
|
7686 |
|
7687 |
|
7688 |
|
7689 | var srcEvent = releaseEvent.inputEvent.srcEvent;
|
7690 | var clickedElement;
|
7691 |
|
7692 | if (srcEvent.type === "touchend") {
|
7693 | var touchEvent = srcEvent;
|
7694 | var touch = touchEvent.changedTouches[0];
|
7695 | clickedElement = document.elementFromPoint(touch.clientX, touch.clientY);
|
7696 | } else {
|
7697 | clickedElement = srcEvent.target;
|
7698 | }
|
7699 |
|
7700 |
|
7701 |
|
7702 | var panels = flicking.renderer.panels;
|
7703 | var clickedPanel = null;
|
7704 |
|
7705 | try {
|
7706 | for (var panels_1 = __values$3(panels), panels_1_1 = panels_1.next(); !panels_1_1.done; panels_1_1 = panels_1.next()) {
|
7707 | var panel = panels_1_1.value;
|
7708 |
|
7709 | if (panel.contains(clickedElement)) {
|
7710 | clickedPanel = panel;
|
7711 | break;
|
7712 | }
|
7713 | }
|
7714 | } catch (e_1_1) {
|
7715 | e_1 = {
|
7716 | error: e_1_1
|
7717 | };
|
7718 | } finally {
|
7719 | try {
|
7720 | if (panels_1_1 && !panels_1_1.done && (_a = panels_1.return)) _a.call(panels_1);
|
7721 | } finally {
|
7722 | if (e_1) throw e_1.error;
|
7723 | }
|
7724 | }
|
7725 |
|
7726 | if (clickedPanel) {
|
7727 | var cameraPosition = flicking.camera.position;
|
7728 | var clickedPanelPosition = clickedPanel.position;
|
7729 | flicking.trigger(new ComponentEvent$1(EVENTS.SELECT, {
|
7730 | index: clickedPanel.index,
|
7731 | panel: clickedPanel,
|
7732 |
|
7733 | direction: getDirection$1(cameraPosition, clickedPanelPosition)
|
7734 | }));
|
7735 | }
|
7736 | };
|
7737 |
|
7738 | return HoldingState;
|
7739 | }(State);
|
7740 |
|
7741 | |
7742 |
|
7743 |
|
7744 |
|
7745 |
|
7746 |
|
7747 | var DraggingState = function (_super) {
|
7748 | __extends$2(DraggingState, _super);
|
7749 |
|
7750 | function DraggingState() {
|
7751 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
7752 | |
7753 |
|
7754 |
|
7755 |
|
7756 |
|
7757 |
|
7758 |
|
7759 |
|
7760 | _this.holding = true;
|
7761 | |
7762 |
|
7763 |
|
7764 |
|
7765 |
|
7766 |
|
7767 |
|
7768 | _this.animating = true;
|
7769 | return _this;
|
7770 | }
|
7771 |
|
7772 | var __proto = DraggingState.prototype;
|
7773 |
|
7774 | __proto.onChange = function (ctx) {
|
7775 | this._moveToChangedPosition(ctx);
|
7776 | };
|
7777 |
|
7778 | __proto.onRelease = function (ctx) {
|
7779 | var flicking = ctx.flicking,
|
7780 | axesEvent = ctx.axesEvent,
|
7781 | transitTo = ctx.transitTo;
|
7782 |
|
7783 |
|
7784 | flicking.trigger(new ComponentEvent$1(EVENTS.HOLD_END, {
|
7785 | axesEvent: axesEvent
|
7786 | }));
|
7787 |
|
7788 | if (flicking.renderer.panelCount <= 0) {
|
7789 |
|
7790 | transitTo(STATE_TYPE.IDLE);
|
7791 | return;
|
7792 | }
|
7793 |
|
7794 | transitTo(STATE_TYPE.ANIMATING);
|
7795 | var control = flicking.control;
|
7796 | var position = axesEvent.destPos[POSITION_KEY];
|
7797 | var duration = Math.max(axesEvent.duration, flicking.duration);
|
7798 | void control.moveToPosition(position, duration, axesEvent);
|
7799 | };
|
7800 |
|
7801 | return DraggingState;
|
7802 | }(State);
|
7803 |
|
7804 | |
7805 |
|
7806 |
|
7807 |
|
7808 |
|
7809 |
|
7810 | var AnimatingState = function (_super) {
|
7811 | __extends$2(AnimatingState, _super);
|
7812 |
|
7813 | function AnimatingState() {
|
7814 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
7815 | |
7816 |
|
7817 |
|
7818 |
|
7819 |
|
7820 |
|
7821 |
|
7822 |
|
7823 | _this.holding = false;
|
7824 | |
7825 |
|
7826 |
|
7827 |
|
7828 |
|
7829 |
|
7830 |
|
7831 | _this.animating = true;
|
7832 | return _this;
|
7833 | }
|
7834 |
|
7835 | var __proto = AnimatingState.prototype;
|
7836 |
|
7837 | __proto.onHold = function (ctx) {
|
7838 | var flicking = ctx.flicking,
|
7839 | axesEvent = ctx.axesEvent,
|
7840 | transitTo = ctx.transitTo;
|
7841 | this._delta = 0;
|
7842 | flicking.control.updateInput();
|
7843 | var holdStartEvent = new ComponentEvent$1(EVENTS.HOLD_START, {
|
7844 | axesEvent: axesEvent
|
7845 | });
|
7846 | flicking.trigger(holdStartEvent);
|
7847 |
|
7848 | if (holdStartEvent.isCanceled()) {
|
7849 | transitTo(STATE_TYPE.DISABLED);
|
7850 | } else {
|
7851 | transitTo(STATE_TYPE.DRAGGING);
|
7852 | }
|
7853 | };
|
7854 |
|
7855 | __proto.onChange = function (ctx) {
|
7856 | this._moveToChangedPosition(ctx);
|
7857 | };
|
7858 |
|
7859 | __proto.onFinish = function (ctx) {
|
7860 | var flicking = ctx.flicking,
|
7861 | axesEvent = ctx.axesEvent,
|
7862 | transitTo = ctx.transitTo;
|
7863 | var control = flicking.control;
|
7864 | var controller = control.controller;
|
7865 | var animatingContext = controller.animatingContext;
|
7866 | transitTo(STATE_TYPE.IDLE);
|
7867 | flicking.trigger(new ComponentEvent$1(EVENTS.MOVE_END, {
|
7868 | isTrusted: axesEvent.isTrusted,
|
7869 | direction: getDirection$1(animatingContext.start, animatingContext.end),
|
7870 | axesEvent: axesEvent
|
7871 | }));
|
7872 | control.setActive(this._targetPanel, control.activePanel, axesEvent.isTrusted);
|
7873 | };
|
7874 |
|
7875 | return AnimatingState;
|
7876 | }(State);
|
7877 |
|
7878 | |
7879 |
|
7880 |
|
7881 |
|
7882 |
|
7883 |
|
7884 | var DisabledState = function (_super) {
|
7885 | __extends$2(DisabledState, _super);
|
7886 |
|
7887 | function DisabledState() {
|
7888 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
7889 | |
7890 |
|
7891 |
|
7892 |
|
7893 |
|
7894 |
|
7895 |
|
7896 |
|
7897 | _this.holding = false;
|
7898 | |
7899 |
|
7900 |
|
7901 |
|
7902 |
|
7903 |
|
7904 |
|
7905 | _this.animating = true;
|
7906 | return _this;
|
7907 | }
|
7908 |
|
7909 | var __proto = DisabledState.prototype;
|
7910 |
|
7911 | __proto.onAnimationEnd = function (ctx) {
|
7912 | var transitTo = ctx.transitTo;
|
7913 | transitTo(STATE_TYPE.IDLE);
|
7914 | };
|
7915 |
|
7916 | __proto.onChange = function (ctx) {
|
7917 | var axesEvent = ctx.axesEvent,
|
7918 | transitTo = ctx.transitTo;
|
7919 |
|
7920 | axesEvent.stop();
|
7921 | transitTo(STATE_TYPE.IDLE);
|
7922 | };
|
7923 |
|
7924 | __proto.onRelease = function (ctx) {
|
7925 | var axesEvent = ctx.axesEvent,
|
7926 | transitTo = ctx.transitTo;
|
7927 |
|
7928 | if (axesEvent.delta.flick === 0) {
|
7929 | transitTo(STATE_TYPE.IDLE);
|
7930 | }
|
7931 | };
|
7932 |
|
7933 | return DisabledState;
|
7934 | }(State);
|
7935 |
|
7936 | |
7937 |
|
7938 |
|
7939 |
|
7940 | var StateMachine = function () {
|
7941 | function StateMachine() {
|
7942 | var _this = this;
|
7943 |
|
7944 | this.transitTo = function (nextStateType) {
|
7945 | var nextState;
|
7946 |
|
7947 | switch (nextStateType) {
|
7948 | case STATE_TYPE.IDLE:
|
7949 | nextState = new IdleState();
|
7950 | break;
|
7951 |
|
7952 | case STATE_TYPE.HOLDING:
|
7953 | nextState = new HoldingState();
|
7954 | break;
|
7955 |
|
7956 | case STATE_TYPE.DRAGGING:
|
7957 | nextState = new DraggingState();
|
7958 | break;
|
7959 |
|
7960 | case STATE_TYPE.ANIMATING:
|
7961 | nextState = new AnimatingState();
|
7962 | break;
|
7963 |
|
7964 | case STATE_TYPE.DISABLED:
|
7965 | nextState = new DisabledState();
|
7966 | break;
|
7967 | }
|
7968 |
|
7969 | nextState.onEnter(_this._state);
|
7970 | _this._state = nextState;
|
7971 | return _this._state;
|
7972 | };
|
7973 |
|
7974 | this._state = new IdleState();
|
7975 | }
|
7976 |
|
7977 | var __proto = StateMachine.prototype;
|
7978 | Object.defineProperty(__proto, "state", {
|
7979 | get: function () {
|
7980 | return this._state;
|
7981 | },
|
7982 | enumerable: false,
|
7983 | configurable: true
|
7984 | });
|
7985 |
|
7986 | __proto.fire = function (eventType, externalCtx) {
|
7987 | var currentState = this._state;
|
7988 |
|
7989 | var ctx = __assign$2(__assign$2({}, externalCtx), {
|
7990 | transitTo: this.transitTo
|
7991 | });
|
7992 |
|
7993 | switch (eventType) {
|
7994 | case EVENT.HOLD:
|
7995 | currentState.onHold(ctx);
|
7996 | break;
|
7997 |
|
7998 | case EVENT.CHANGE:
|
7999 | currentState.onChange(ctx);
|
8000 | break;
|
8001 |
|
8002 | case EVENT.RELEASE:
|
8003 | currentState.onRelease(ctx);
|
8004 | break;
|
8005 |
|
8006 | case EVENT.ANIMATION_END:
|
8007 | currentState.onAnimationEnd(ctx);
|
8008 | break;
|
8009 |
|
8010 | case EVENT.FINISH:
|
8011 | currentState.onFinish(ctx);
|
8012 | break;
|
8013 | }
|
8014 | };
|
8015 |
|
8016 | return StateMachine;
|
8017 | }();
|
8018 |
|
8019 | |
8020 |
|
8021 |
|
8022 |
|
8023 | |
8024 |
|
8025 |
|
8026 |
|
8027 |
|
8028 |
|
8029 | var AxesController = function () {
|
8030 |
|
8031 | function AxesController() {
|
8032 | var _this = this;
|
8033 |
|
8034 | this._onAxesHold = function () {
|
8035 | _this._dragged = false;
|
8036 | };
|
8037 |
|
8038 | this._onAxesChange = function () {
|
8039 | _this._dragged = true;
|
8040 | };
|
8041 |
|
8042 | this._preventClickWhenDragged = function (e) {
|
8043 | if (_this._dragged) {
|
8044 | e.preventDefault();
|
8045 | e.stopPropagation();
|
8046 | }
|
8047 |
|
8048 | _this._dragged = false;
|
8049 | };
|
8050 |
|
8051 | this._resetInternalValues();
|
8052 |
|
8053 | this._stateMachine = new StateMachine();
|
8054 | }
|
8055 |
|
8056 | var __proto = AxesController.prototype;
|
8057 | Object.defineProperty(__proto, "axes", {
|
8058 | |
8059 |
|
8060 |
|
8061 |
|
8062 |
|
8063 |
|
8064 |
|
8065 | get: function () {
|
8066 | return this._axes;
|
8067 | },
|
8068 | enumerable: false,
|
8069 | configurable: true
|
8070 | });
|
8071 | Object.defineProperty(__proto, "stateMachine", {
|
8072 | |
8073 |
|
8074 |
|
8075 | get: function () {
|
8076 | return this._stateMachine;
|
8077 | },
|
8078 | enumerable: false,
|
8079 | configurable: true
|
8080 | });
|
8081 | Object.defineProperty(__proto, "state", {
|
8082 | |
8083 |
|
8084 |
|
8085 |
|
8086 |
|
8087 | get: function () {
|
8088 | return this._stateMachine.state;
|
8089 | },
|
8090 | enumerable: false,
|
8091 | configurable: true
|
8092 | });
|
8093 | Object.defineProperty(__proto, "animatingContext", {
|
8094 | |
8095 |
|
8096 |
|
8097 |
|
8098 |
|
8099 |
|
8100 |
|
8101 |
|
8102 |
|
8103 | get: function () {
|
8104 | return this._animatingContext;
|
8105 | },
|
8106 | enumerable: false,
|
8107 | configurable: true
|
8108 | });
|
8109 | Object.defineProperty(__proto, "controlParams", {
|
8110 | |
8111 |
|
8112 |
|
8113 |
|
8114 |
|
8115 | get: function () {
|
8116 | var axes = this._axes;
|
8117 |
|
8118 | if (!axes) {
|
8119 | return {
|
8120 | range: {
|
8121 | min: 0,
|
8122 | max: 0
|
8123 | },
|
8124 | position: 0,
|
8125 | circular: false
|
8126 | };
|
8127 | }
|
8128 |
|
8129 | var axis = axes.axis[POSITION_KEY];
|
8130 | return {
|
8131 | range: {
|
8132 | min: axis.range[0],
|
8133 | max: axis.range[1]
|
8134 | },
|
8135 | circular: axis.circular[0],
|
8136 | position: this.position
|
8137 | };
|
8138 | },
|
8139 | enumerable: false,
|
8140 | configurable: true
|
8141 | });
|
8142 | Object.defineProperty(__proto, "enabled", {
|
8143 | |
8144 |
|
8145 |
|
8146 |
|
8147 |
|
8148 |
|
8149 | get: function () {
|
8150 | var _a, _b;
|
8151 |
|
8152 | return (_b = (_a = this._panInput) === null || _a === void 0 ? void 0 : _a.isEnable()) !== null && _b !== void 0 ? _b : false;
|
8153 | },
|
8154 | enumerable: false,
|
8155 | configurable: true
|
8156 | });
|
8157 | Object.defineProperty(__proto, "position", {
|
8158 | |
8159 |
|
8160 |
|
8161 |
|
8162 |
|
8163 |
|
8164 | get: function () {
|
8165 | var _a, _b;
|
8166 |
|
8167 | return (_b = (_a = this._axes) === null || _a === void 0 ? void 0 : _a.get([POSITION_KEY])[POSITION_KEY]) !== null && _b !== void 0 ? _b : 0;
|
8168 | },
|
8169 | enumerable: false,
|
8170 | configurable: true
|
8171 | });
|
8172 | Object.defineProperty(__proto, "range", {
|
8173 | |
8174 |
|
8175 |
|
8176 |
|
8177 |
|
8178 |
|
8179 | get: function () {
|
8180 | var _a, _b;
|
8181 |
|
8182 | return (_b = (_a = this._axes) === null || _a === void 0 ? void 0 : _a.axis[POSITION_KEY].range) !== null && _b !== void 0 ? _b : [0, 0];
|
8183 | },
|
8184 | enumerable: false,
|
8185 | configurable: true
|
8186 | });
|
8187 | Object.defineProperty(__proto, "bounce", {
|
8188 | |
8189 |
|
8190 |
|
8191 |
|
8192 |
|
8193 |
|
8194 | get: function () {
|
8195 | var _a;
|
8196 |
|
8197 | return (_a = this._axes) === null || _a === void 0 ? void 0 : _a.axis[POSITION_KEY].bounce;
|
8198 | },
|
8199 | enumerable: false,
|
8200 | configurable: true
|
8201 | });
|
8202 | |
8203 |
|
8204 |
|
8205 |
|
8206 |
|
8207 |
|
8208 |
|
8209 |
|
8210 | __proto.init = function (flicking) {
|
8211 | var _a;
|
8212 |
|
8213 | var _this = this;
|
8214 |
|
8215 | this._flicking = flicking;
|
8216 | this._axes = new Axes$1((_a = {}, _a[POSITION_KEY] = {
|
8217 | range: [0, 0],
|
8218 | circular: false,
|
8219 | bounce: [0, 0]
|
8220 | }, _a), {
|
8221 | deceleration: flicking.deceleration,
|
8222 | interruptable: flicking.interruptable,
|
8223 | easing: flicking.easing
|
8224 | });
|
8225 | this._panInput = new PanInput(flicking.viewport.element, {
|
8226 | inputType: flicking.inputType,
|
8227 | iOSEdgeSwipeThreshold: flicking.iOSEdgeSwipeThreshold,
|
8228 | scale: flicking.horizontal ? [-1, 0] : [0, -1],
|
8229 | releaseOnScroll: true
|
8230 | });
|
8231 | var axes = this._axes;
|
8232 | axes.connect(flicking.horizontal ? [POSITION_KEY, ""] : ["", POSITION_KEY], this._panInput);
|
8233 |
|
8234 | var _loop_1 = function (key) {
|
8235 | var eventType = EVENT[key];
|
8236 | axes.on(eventType, function (e) {
|
8237 | _this._stateMachine.fire(eventType, {
|
8238 | flicking: flicking,
|
8239 | axesEvent: e
|
8240 | });
|
8241 | });
|
8242 | };
|
8243 |
|
8244 | for (var key in EVENT) {
|
8245 | _loop_1(key);
|
8246 | }
|
8247 |
|
8248 | return this;
|
8249 | };
|
8250 | |
8251 |
|
8252 |
|
8253 |
|
8254 |
|
8255 |
|
8256 |
|
8257 | __proto.destroy = function () {
|
8258 | var _a;
|
8259 |
|
8260 | if (this._axes) {
|
8261 | this.removePreventClickHandler();
|
8262 |
|
8263 | this._axes.destroy();
|
8264 | }
|
8265 |
|
8266 | (_a = this._panInput) === null || _a === void 0 ? void 0 : _a.destroy();
|
8267 |
|
8268 | this._resetInternalValues();
|
8269 | };
|
8270 | |
8271 |
|
8272 |
|
8273 |
|
8274 |
|
8275 |
|
8276 |
|
8277 |
|
8278 | __proto.enable = function () {
|
8279 | var _a;
|
8280 |
|
8281 | (_a = this._panInput) === null || _a === void 0 ? void 0 : _a.enable();
|
8282 | return this;
|
8283 | };
|
8284 | |
8285 |
|
8286 |
|
8287 |
|
8288 |
|
8289 |
|
8290 |
|
8291 |
|
8292 | __proto.disable = function () {
|
8293 | var _a;
|
8294 |
|
8295 | (_a = this._panInput) === null || _a === void 0 ? void 0 : _a.disable();
|
8296 | return this;
|
8297 | };
|
8298 | |
8299 |
|
8300 |
|
8301 |
|
8302 |
|
8303 |
|
8304 |
|
8305 |
|
8306 |
|
8307 |
|
8308 |
|
8309 | __proto.update = function (controlParams) {
|
8310 | var _a;
|
8311 |
|
8312 | var flicking = getFlickingAttached(this._flicking, "Control");
|
8313 | var camera = flicking.camera;
|
8314 | var axes = this._axes;
|
8315 | var axis = axes.axis[POSITION_KEY];
|
8316 | axis.circular = [controlParams.circular, controlParams.circular];
|
8317 | axis.range = [controlParams.range.min, controlParams.range.max];
|
8318 | axis.bounce = parseBounce(flicking.bounce, camera.size);
|
8319 | axes.axm.set((_a = {}, _a[POSITION_KEY] = controlParams.position, _a));
|
8320 | return this;
|
8321 | };
|
8322 | |
8323 |
|
8324 |
|
8325 |
|
8326 |
|
8327 |
|
8328 |
|
8329 | __proto.addPreventClickHandler = function () {
|
8330 | var flicking = getFlickingAttached(this._flicking, "Control");
|
8331 | var axes = this._axes;
|
8332 | var cameraEl = flicking.camera.element;
|
8333 | axes.on(EVENT.HOLD, this._onAxesHold);
|
8334 | axes.on(EVENT.CHANGE, this._onAxesChange);
|
8335 | cameraEl.addEventListener("click", this._preventClickWhenDragged, true);
|
8336 | return this;
|
8337 | };
|
8338 | |
8339 |
|
8340 |
|
8341 |
|
8342 |
|
8343 |
|
8344 |
|
8345 | __proto.removePreventClickHandler = function () {
|
8346 | var flicking = getFlickingAttached(this._flicking, "Control");
|
8347 | var axes = this._axes;
|
8348 | var cameraEl = flicking.camera.element;
|
8349 | axes.off(EVENT.HOLD, this._onAxesHold);
|
8350 | axes.off(EVENT.CHANGE, this._onAxesChange);
|
8351 | cameraEl.removeEventListener("click", this._preventClickWhenDragged, true);
|
8352 | return this;
|
8353 | };
|
8354 | |
8355 |
|
8356 |
|
8357 |
|
8358 |
|
8359 |
|
8360 |
|
8361 |
|
8362 |
|
8363 |
|
8364 |
|
8365 |
|
8366 |
|
8367 |
|
8368 |
|
8369 |
|
8370 |
|
8371 |
|
8372 |
|
8373 |
|
8374 |
|
8375 |
|
8376 |
|
8377 | __proto.animateTo = function (position, duration, axesEvent) {
|
8378 | var _a;
|
8379 |
|
8380 | var _this = this;
|
8381 |
|
8382 | var axes = this._axes;
|
8383 |
|
8384 | if (!axes) {
|
8385 | return Promise.reject(new FlickingError(MESSAGE.NOT_ATTACHED_TO_FLICKING("Control"), CODE.NOT_ATTACHED_TO_FLICKING));
|
8386 | }
|
8387 |
|
8388 | var startPos = axes.get([POSITION_KEY])[POSITION_KEY];
|
8389 |
|
8390 | if (startPos === position) {
|
8391 | var flicking = getFlickingAttached(this._flicking, "Control");
|
8392 | flicking.camera.lookAt(position);
|
8393 | return Promise.resolve();
|
8394 | }
|
8395 |
|
8396 | this._animatingContext = {
|
8397 | start: startPos,
|
8398 | end: position,
|
8399 | offset: 0
|
8400 | };
|
8401 |
|
8402 | var animate = function () {
|
8403 | var _a, _b;
|
8404 |
|
8405 | var resetContext = function () {
|
8406 | _this._animatingContext = {
|
8407 | start: 0,
|
8408 | end: 0,
|
8409 | offset: 0
|
8410 | };
|
8411 | };
|
8412 |
|
8413 | axes.once(EVENT.FINISH, resetContext);
|
8414 |
|
8415 | if (axesEvent) {
|
8416 | axesEvent.setTo((_a = {}, _a[POSITION_KEY] = position, _a), duration);
|
8417 | } else {
|
8418 | axes.setTo((_b = {}, _b[POSITION_KEY] = position, _b), duration);
|
8419 | }
|
8420 | };
|
8421 |
|
8422 | if (duration === 0) {
|
8423 | var flicking = getFlickingAttached(this._flicking, "Control");
|
8424 | var camera = flicking.camera;
|
8425 | animate();
|
8426 | var newPos = flicking.circularEnabled ? circulatePosition(position, camera.range.min, camera.range.max) : position;
|
8427 | axes.axm.set((_a = {}, _a[POSITION_KEY] = newPos, _a));
|
8428 | return Promise.resolve();
|
8429 | } else {
|
8430 | return new Promise(function (resolve, reject) {
|
8431 | var animationFinishHandler = function () {
|
8432 | axes.off(EVENT.HOLD, interruptionHandler);
|
8433 | resolve();
|
8434 | };
|
8435 |
|
8436 | var interruptionHandler = function () {
|
8437 | axes.off(EVENT.FINISH, animationFinishHandler);
|
8438 | reject(new FlickingError(MESSAGE.ANIMATION_INTERRUPTED, CODE.ANIMATION_INTERRUPTED));
|
8439 | };
|
8440 |
|
8441 | axes.once(EVENT.FINISH, animationFinishHandler);
|
8442 | axes.once(EVENT.HOLD, interruptionHandler);
|
8443 | animate();
|
8444 | });
|
8445 | }
|
8446 | };
|
8447 |
|
8448 | __proto._resetInternalValues = function () {
|
8449 | this._flicking = null;
|
8450 | this._axes = null;
|
8451 | this._panInput = null;
|
8452 | this._animatingContext = {
|
8453 | start: 0,
|
8454 | end: 0,
|
8455 | offset: 0
|
8456 | };
|
8457 | this._dragged = false;
|
8458 | };
|
8459 |
|
8460 | return AxesController;
|
8461 | }();
|
8462 |
|
8463 | |
8464 |
|
8465 |
|
8466 |
|
8467 |
|
8468 | var Control$1 = function () {
|
8469 |
|
8470 | function Control() {
|
8471 | this._flicking = null;
|
8472 | this._controller = new AxesController();
|
8473 | this._activePanel = null;
|
8474 | }
|
8475 |
|
8476 | var __proto = Control.prototype;
|
8477 | Object.defineProperty(__proto, "controller", {
|
8478 | |
8479 |
|
8480 |
|
8481 |
|
8482 |
|
8483 |
|
8484 | get: function () {
|
8485 | return this._controller;
|
8486 | },
|
8487 | enumerable: false,
|
8488 | configurable: true
|
8489 | });
|
8490 | Object.defineProperty(__proto, "activeIndex", {
|
8491 | |
8492 |
|
8493 |
|
8494 |
|
8495 |
|
8496 |
|
8497 |
|
8498 | get: function () {
|
8499 | var _a, _b;
|
8500 |
|
8501 | return (_b = (_a = this._activePanel) === null || _a === void 0 ? void 0 : _a.index) !== null && _b !== void 0 ? _b : -1;
|
8502 | },
|
8503 | enumerable: false,
|
8504 | configurable: true
|
8505 | });
|
8506 | Object.defineProperty(__proto, "activePanel", {
|
8507 | |
8508 |
|
8509 |
|
8510 |
|
8511 |
|
8512 |
|
8513 | get: function () {
|
8514 | return this._activePanel;
|
8515 | },
|
8516 | enumerable: false,
|
8517 | configurable: true
|
8518 | });
|
8519 | Object.defineProperty(__proto, "animating", {
|
8520 | |
8521 |
|
8522 |
|
8523 |
|
8524 |
|
8525 |
|
8526 | get: function () {
|
8527 | return this._controller.state.animating;
|
8528 | },
|
8529 | enumerable: false,
|
8530 | configurable: true
|
8531 | });
|
8532 | Object.defineProperty(__proto, "holding", {
|
8533 | |
8534 |
|
8535 |
|
8536 |
|
8537 |
|
8538 |
|
8539 | get: function () {
|
8540 | return this._controller.state.holding;
|
8541 | },
|
8542 | enumerable: false,
|
8543 | configurable: true
|
8544 | });
|
8545 | |
8546 |
|
8547 |
|
8548 |
|
8549 |
|
8550 |
|
8551 |
|
8552 |
|
8553 | __proto.init = function (flicking) {
|
8554 | this._flicking = flicking;
|
8555 |
|
8556 | this._controller.init(flicking);
|
8557 |
|
8558 | return this;
|
8559 | };
|
8560 | |
8561 |
|
8562 |
|
8563 |
|
8564 |
|
8565 |
|
8566 |
|
8567 | __proto.destroy = function () {
|
8568 | this._controller.destroy();
|
8569 |
|
8570 | this._flicking = null;
|
8571 | this._activePanel = null;
|
8572 | };
|
8573 | |
8574 |
|
8575 |
|
8576 |
|
8577 |
|
8578 |
|
8579 |
|
8580 |
|
8581 | __proto.enable = function () {
|
8582 | this._controller.enable();
|
8583 |
|
8584 | return this;
|
8585 | };
|
8586 | |
8587 |
|
8588 |
|
8589 |
|
8590 |
|
8591 |
|
8592 |
|
8593 |
|
8594 | __proto.disable = function () {
|
8595 | this._controller.disable();
|
8596 |
|
8597 | return this;
|
8598 | };
|
8599 | |
8600 |
|
8601 |
|
8602 |
|
8603 |
|
8604 |
|
8605 |
|
8606 |
|
8607 |
|
8608 |
|
8609 |
|
8610 |
|
8611 | __proto.updatePosition = function (_progressInPanel) {
|
8612 | var flicking = getFlickingAttached(this._flicking, "Control");
|
8613 | var camera = flicking.camera;
|
8614 | var activePanel = this._activePanel;
|
8615 |
|
8616 | if (activePanel) {
|
8617 | camera.lookAt(camera.clampToReachablePosition(activePanel.position));
|
8618 | }
|
8619 | };
|
8620 | |
8621 |
|
8622 |
|
8623 |
|
8624 |
|
8625 |
|
8626 |
|
8627 |
|
8628 | __proto.updateInput = function () {
|
8629 | var flicking = getFlickingAttached(this._flicking, "Control");
|
8630 | var camera = flicking.camera;
|
8631 |
|
8632 | this._controller.update(camera.controlParams);
|
8633 |
|
8634 | return this;
|
8635 | };
|
8636 | |
8637 |
|
8638 |
|
8639 |
|
8640 |
|
8641 |
|
8642 |
|
8643 |
|
8644 | __proto.resetActive = function () {
|
8645 | this._activePanel = null;
|
8646 | return this;
|
8647 | };
|
8648 | |
8649 |
|
8650 |
|
8651 |
|
8652 |
|
8653 |
|
8654 |
|
8655 |
|
8656 |
|
8657 |
|
8658 |
|
8659 |
|
8660 |
|
8661 |
|
8662 |
|
8663 |
|
8664 |
|
8665 |
|
8666 |
|
8667 |
|
8668 |
|
8669 |
|
8670 |
|
8671 |
|
8672 |
|
8673 |
|
8674 |
|
8675 |
|
8676 |
|
8677 |
|
8678 |
|
8679 |
|
8680 |
|
8681 |
|
8682 |
|
8683 |
|
8684 |
|
8685 |
|
8686 |
|
8687 |
|
8688 | __proto.moveToPanel = function (panel, _a) {
|
8689 | var duration = _a.duration,
|
8690 | _b = _a.direction,
|
8691 | direction = _b === void 0 ? DIRECTION.NONE : _b,
|
8692 | axesEvent = _a.axesEvent;
|
8693 | return __awaiter(this, void 0, void 0, function () {
|
8694 | var flicking, camera, position, nearestAnchor, camPos_1, camRangeDiff, possiblePositions;
|
8695 | return __generator(this, function (_c) {
|
8696 | flicking = getFlickingAttached(this._flicking, "Control");
|
8697 | camera = flicking.camera;
|
8698 | position = panel.position;
|
8699 | nearestAnchor = camera.findNearestAnchor(position);
|
8700 |
|
8701 | if (panel.removed || !nearestAnchor) {
|
8702 | return [2
|
8703 |
|
8704 | , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(panel.position), CODE.POSITION_NOT_REACHABLE))];
|
8705 | }
|
8706 |
|
8707 | if (!camera.canReach(panel)) {
|
8708 |
|
8709 | position = nearestAnchor.position;
|
8710 | panel = nearestAnchor.panel;
|
8711 | } else if (flicking.circularEnabled) {
|
8712 | camPos_1 = this._controller.position;
|
8713 | camRangeDiff = camera.rangeDiff;
|
8714 | possiblePositions = [position, position + camRangeDiff, position - camRangeDiff].filter(function (pos) {
|
8715 | if (direction === DIRECTION.NONE) return true;
|
8716 | return direction === DIRECTION.PREV ? pos <= camPos_1 : pos >= camPos_1;
|
8717 | });
|
8718 | position = possiblePositions.reduce(function (nearestPosition, pos) {
|
8719 | if (Math.abs(camPos_1 - pos) < Math.abs(camPos_1 - nearestPosition)) {
|
8720 | return pos;
|
8721 | } else {
|
8722 | return nearestPosition;
|
8723 | }
|
8724 | }, Infinity);
|
8725 | }
|
8726 |
|
8727 | this._triggerIndexChangeEvent(panel, panel.position, axesEvent);
|
8728 |
|
8729 | return [2
|
8730 |
|
8731 | , this._animateToPosition({
|
8732 | position: position,
|
8733 | duration: duration,
|
8734 | newActivePanel: panel,
|
8735 | axesEvent: axesEvent
|
8736 | })];
|
8737 | });
|
8738 | });
|
8739 | };
|
8740 | |
8741 |
|
8742 |
|
8743 |
|
8744 |
|
8745 | __proto.setActive = function (newActivePanel, prevActivePanel, isTrusted) {
|
8746 | var _a;
|
8747 |
|
8748 | var flicking = getFlickingAttached(this._flicking, "Control");
|
8749 | this._activePanel = newActivePanel;
|
8750 | flicking.camera.updateAdaptiveHeight();
|
8751 |
|
8752 | if (newActivePanel !== prevActivePanel) {
|
8753 | flicking.trigger(new ComponentEvent$1(EVENTS.CHANGED, {
|
8754 | index: newActivePanel.index,
|
8755 | panel: newActivePanel,
|
8756 | prevIndex: (_a = prevActivePanel === null || prevActivePanel === void 0 ? void 0 : prevActivePanel.index) !== null && _a !== void 0 ? _a : -1,
|
8757 | prevPanel: prevActivePanel,
|
8758 | isTrusted: isTrusted,
|
8759 | direction: prevActivePanel ? getDirection$1(prevActivePanel.position, newActivePanel.position) : DIRECTION.NONE
|
8760 | }));
|
8761 | } else {
|
8762 | flicking.trigger(new ComponentEvent$1(EVENTS.RESTORED, {
|
8763 | isTrusted: isTrusted
|
8764 | }));
|
8765 | }
|
8766 | };
|
8767 |
|
8768 | __proto._triggerIndexChangeEvent = function (panel, position, axesEvent) {
|
8769 | var _a;
|
8770 |
|
8771 | var flicking = getFlickingAttached(this._flicking, "Control");
|
8772 | var triggeringEvent = panel !== this._activePanel ? EVENTS.WILL_CHANGE : EVENTS.WILL_RESTORE;
|
8773 | var camera = flicking.camera;
|
8774 | var activePanel = this._activePanel;
|
8775 | var event = new ComponentEvent$1(triggeringEvent, {
|
8776 | index: panel.index,
|
8777 | panel: panel,
|
8778 | isTrusted: (axesEvent === null || axesEvent === void 0 ? void 0 : axesEvent.isTrusted) || false,
|
8779 | direction: getDirection$1((_a = activePanel === null || activePanel === void 0 ? void 0 : activePanel.position) !== null && _a !== void 0 ? _a : camera.position, position)
|
8780 | });
|
8781 | flicking.trigger(event);
|
8782 |
|
8783 | if (event.isCanceled()) {
|
8784 | throw new FlickingError(MESSAGE.STOP_CALLED_BY_USER, CODE.STOP_CALLED_BY_USER);
|
8785 | }
|
8786 | };
|
8787 |
|
8788 | __proto._animateToPosition = function (_a) {
|
8789 | var position = _a.position,
|
8790 | duration = _a.duration,
|
8791 | newActivePanel = _a.newActivePanel,
|
8792 | axesEvent = _a.axesEvent;
|
8793 | return __awaiter(this, void 0, void 0, function () {
|
8794 | var flicking, animate, state;
|
8795 |
|
8796 | var _this = this;
|
8797 |
|
8798 | return __generator(this, function (_b) {
|
8799 | flicking = getFlickingAttached(this._flicking, "Control");
|
8800 |
|
8801 | animate = function () {
|
8802 | return _this._controller.animateTo(position, duration, axesEvent);
|
8803 | };
|
8804 |
|
8805 | state = this._controller.state;
|
8806 | state.targetPanel = newActivePanel;
|
8807 |
|
8808 | if (duration <= 0) {
|
8809 | return [2
|
8810 |
|
8811 | , animate()];
|
8812 | } else {
|
8813 | return [2
|
8814 |
|
8815 | , animate().then(function () {
|
8816 | return __awaiter(_this, void 0, void 0, function () {
|
8817 | return __generator(this, function (_a) {
|
8818 | switch (_a.label) {
|
8819 | case 0:
|
8820 | return [4
|
8821 |
|
8822 | , flicking.renderer.render()];
|
8823 |
|
8824 | case 1:
|
8825 | _a.sent();
|
8826 |
|
8827 | return [2
|
8828 |
|
8829 | ];
|
8830 | }
|
8831 | });
|
8832 | });
|
8833 | }).catch(function (err) {
|
8834 | if (axesEvent && err instanceof FlickingError && err.code === CODE.ANIMATION_INTERRUPTED) return;
|
8835 | throw err;
|
8836 | })];
|
8837 | }
|
8838 | });
|
8839 | });
|
8840 | };
|
8841 |
|
8842 | return Control;
|
8843 | }();
|
8844 |
|
8845 | |
8846 |
|
8847 |
|
8848 |
|
8849 | var AnchorPoint = function () {
|
8850 | |
8851 |
|
8852 |
|
8853 |
|
8854 |
|
8855 |
|
8856 | function AnchorPoint(_a) {
|
8857 | var index = _a.index,
|
8858 | position = _a.position,
|
8859 | panel = _a.panel;
|
8860 | this._index = index;
|
8861 | this._pos = position;
|
8862 | this._panel = panel;
|
8863 | }
|
8864 |
|
8865 | var __proto = AnchorPoint.prototype;
|
8866 | Object.defineProperty(__proto, "index", {
|
8867 | |
8868 |
|
8869 |
|
8870 |
|
8871 |
|
8872 |
|
8873 | get: function () {
|
8874 | return this._index;
|
8875 | },
|
8876 | enumerable: false,
|
8877 | configurable: true
|
8878 | });
|
8879 | Object.defineProperty(__proto, "position", {
|
8880 | |
8881 |
|
8882 |
|
8883 |
|
8884 |
|
8885 |
|
8886 | get: function () {
|
8887 | return this._pos;
|
8888 | },
|
8889 | enumerable: false,
|
8890 | configurable: true
|
8891 | });
|
8892 | Object.defineProperty(__proto, "panel", {
|
8893 | |
8894 |
|
8895 |
|
8896 |
|
8897 |
|
8898 |
|
8899 | get: function () {
|
8900 | return this._panel;
|
8901 | },
|
8902 | enumerable: false,
|
8903 | configurable: true
|
8904 | });
|
8905 | return AnchorPoint;
|
8906 | }();
|
8907 |
|
8908 | |
8909 |
|
8910 |
|
8911 |
|
8912 |
|
8913 | var SnapControl = function (_super) {
|
8914 | __extends$2(SnapControl, _super);
|
8915 |
|
8916 |
|
8917 |
|
8918 | function SnapControl(_a) {
|
8919 | var _b = _a === void 0 ? {} : _a,
|
8920 | _c = _b.count,
|
8921 | count = _c === void 0 ? Infinity : _c;
|
8922 |
|
8923 | var _this = _super.call(this) || this;
|
8924 |
|
8925 | _this._count = count;
|
8926 | return _this;
|
8927 | }
|
8928 |
|
8929 | var __proto = SnapControl.prototype;
|
8930 | Object.defineProperty(__proto, "count", {
|
8931 | |
8932 |
|
8933 |
|
8934 |
|
8935 |
|
8936 |
|
8937 | get: function () {
|
8938 | return this._count;
|
8939 | },
|
8940 | set: function (val) {
|
8941 | this._count = val;
|
8942 | },
|
8943 | enumerable: false,
|
8944 | configurable: true
|
8945 | });
|
8946 | |
8947 |
|
8948 |
|
8949 |
|
8950 |
|
8951 |
|
8952 |
|
8953 |
|
8954 |
|
8955 |
|
8956 |
|
8957 |
|
8958 |
|
8959 |
|
8960 |
|
8961 |
|
8962 |
|
8963 |
|
8964 |
|
8965 |
|
8966 |
|
8967 |
|
8968 |
|
8969 |
|
8970 |
|
8971 |
|
8972 |
|
8973 |
|
8974 |
|
8975 |
|
8976 |
|
8977 |
|
8978 |
|
8979 |
|
8980 |
|
8981 |
|
8982 |
|
8983 | __proto.moveToPosition = function (position, duration, axesEvent) {
|
8984 | return __awaiter(this, void 0, void 0, function () {
|
8985 | var flicking, camera, activeAnchor, anchorAtCamera, state, snapThreshold, posDelta, absPosDelta, snapDelta, targetAnchor;
|
8986 | return __generator(this, function (_a) {
|
8987 | flicking = getFlickingAttached(this._flicking, "Control");
|
8988 | camera = flicking.camera;
|
8989 | activeAnchor = camera.findActiveAnchor();
|
8990 | anchorAtCamera = camera.findNearestAnchor(camera.position);
|
8991 | state = flicking.control.controller.state;
|
8992 |
|
8993 | if (!activeAnchor || !anchorAtCamera) {
|
8994 | return [2
|
8995 |
|
8996 | , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE))];
|
8997 | }
|
8998 |
|
8999 | snapThreshold = this._calcSnapThreshold(position, activeAnchor);
|
9000 | posDelta = flicking.animating ? state.delta : position - camera.position;
|
9001 | absPosDelta = Math.abs(posDelta);
|
9002 | snapDelta = axesEvent && axesEvent.delta[POSITION_KEY] !== 0 ? Math.abs(axesEvent.delta[POSITION_KEY]) : absPosDelta;
|
9003 |
|
9004 | if (snapDelta >= snapThreshold && snapDelta > 0) {
|
9005 |
|
9006 | targetAnchor = this._findSnappedAnchor(position, anchorAtCamera);
|
9007 | } else if (absPosDelta >= flicking.threshold && absPosDelta > 0) {
|
9008 |
|
9009 | targetAnchor = this._findAdjacentAnchor(posDelta, anchorAtCamera);
|
9010 | } else {
|
9011 |
|
9012 | targetAnchor = anchorAtCamera;
|
9013 | }
|
9014 |
|
9015 | this._triggerIndexChangeEvent(targetAnchor.panel, position, axesEvent);
|
9016 |
|
9017 | return [2
|
9018 |
|
9019 | , this._animateToPosition({
|
9020 | position: camera.clampToReachablePosition(targetAnchor.position),
|
9021 | duration: duration,
|
9022 | newActivePanel: targetAnchor.panel,
|
9023 | axesEvent: axesEvent
|
9024 | })];
|
9025 | });
|
9026 | });
|
9027 | };
|
9028 |
|
9029 | __proto._findSnappedAnchor = function (position, anchorAtCamera) {
|
9030 | var flicking = getFlickingAttached(this._flicking, "Control");
|
9031 | var camera = flicking.camera;
|
9032 | var count = this._count;
|
9033 | var currentPos = camera.position;
|
9034 | var clampedPosition = camera.clampToReachablePosition(position);
|
9035 | var anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
|
9036 |
|
9037 | if (!anchorAtCamera || !anchorAtPosition) {
|
9038 | throw new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE);
|
9039 | }
|
9040 |
|
9041 | if (!isFinite(count)) {
|
9042 | return anchorAtPosition;
|
9043 | }
|
9044 |
|
9045 | var panelCount = flicking.panelCount;
|
9046 | var anchors = camera.anchorPoints;
|
9047 | var loopCount = Math.sign(position - currentPos) * Math.floor(Math.abs(position - currentPos) / camera.rangeDiff);
|
9048 |
|
9049 | if (position > currentPos && anchorAtPosition.index < anchorAtCamera.index || anchorAtPosition.position > anchorAtCamera.position && anchorAtPosition.index === anchorAtCamera.index) {
|
9050 | loopCount += 1;
|
9051 | } else if (position < currentPos && anchorAtPosition.index > anchorAtCamera.index || anchorAtPosition.position < anchorAtCamera.position && anchorAtPosition.index === anchorAtCamera.index) {
|
9052 | loopCount -= 1;
|
9053 | }
|
9054 |
|
9055 | var circularIndexOffset = loopCount * panelCount;
|
9056 | var anchorAtPositionIndex = anchorAtPosition.index + circularIndexOffset;
|
9057 |
|
9058 | if (Math.abs(anchorAtPositionIndex - anchorAtCamera.index) <= count) {
|
9059 | var anchor = anchors[anchorAtPosition.index];
|
9060 | return new AnchorPoint({
|
9061 | index: anchor.index,
|
9062 | position: anchor.position + loopCount * camera.rangeDiff,
|
9063 | panel: anchor.panel
|
9064 | });
|
9065 | }
|
9066 |
|
9067 | if (flicking.circularEnabled) {
|
9068 | var targetAnchor = anchors[circulateIndex(anchorAtCamera.index + Math.sign(position - currentPos) * count, panelCount)];
|
9069 | var loop = Math.floor(count / panelCount);
|
9070 |
|
9071 | if (position > currentPos && targetAnchor.index < anchorAtCamera.index) {
|
9072 | loop += 1;
|
9073 | } else if (position < currentPos && targetAnchor.index > anchorAtCamera.index) {
|
9074 | loop -= 1;
|
9075 | }
|
9076 |
|
9077 | return new AnchorPoint({
|
9078 | index: targetAnchor.index,
|
9079 | position: targetAnchor.position + loop * camera.rangeDiff,
|
9080 | panel: targetAnchor.panel
|
9081 | });
|
9082 | } else {
|
9083 | return anchors[clamp(anchorAtCamera.index + Math.sign(position - currentPos) * count, 0, anchors.length - 1)];
|
9084 | }
|
9085 | };
|
9086 |
|
9087 | __proto._findAdjacentAnchor = function (posDelta, anchorAtCamera) {
|
9088 | var _a;
|
9089 |
|
9090 | var flicking = getFlickingAttached(this._flicking, "Control");
|
9091 | var camera = flicking.camera;
|
9092 | var adjacentAnchor = (_a = posDelta > 0 ? camera.getNextAnchor(anchorAtCamera) : camera.getPrevAnchor(anchorAtCamera)) !== null && _a !== void 0 ? _a : anchorAtCamera;
|
9093 | return adjacentAnchor;
|
9094 | };
|
9095 |
|
9096 | __proto._calcSnapThreshold = function (position, activeAnchor) {
|
9097 | var isNextDirection = position > activeAnchor.position;
|
9098 | var panel = activeAnchor.panel;
|
9099 | var panelSize = panel.size;
|
9100 | var alignPos = panel.alignPosition;
|
9101 |
|
9102 | |
9103 |
|
9104 |
|
9105 |
|
9106 |
|
9107 |
|
9108 | return isNextDirection ? panelSize - alignPos + panel.margin.next : alignPos + panel.margin.prev;
|
9109 | };
|
9110 |
|
9111 | return SnapControl;
|
9112 | }(Control$1);
|
9113 |
|
9114 | |
9115 |
|
9116 |
|
9117 |
|
9118 |
|
9119 | var FreeControl = function (_super) {
|
9120 | __extends$2(FreeControl, _super);
|
9121 |
|
9122 |
|
9123 |
|
9124 | function FreeControl(_a) {
|
9125 | var _b = _a === void 0 ? {} : _a,
|
9126 | _c = _b.stopAtEdge,
|
9127 | stopAtEdge = _c === void 0 ? true : _c;
|
9128 |
|
9129 | var _this = _super.call(this) || this;
|
9130 |
|
9131 | _this._stopAtEdge = stopAtEdge;
|
9132 | return _this;
|
9133 | }
|
9134 |
|
9135 | var __proto = FreeControl.prototype;
|
9136 | Object.defineProperty(__proto, "stopAtEdge", {
|
9137 | |
9138 |
|
9139 |
|
9140 |
|
9141 |
|
9142 |
|
9143 | get: function () {
|
9144 | return this._stopAtEdge;
|
9145 | },
|
9146 | set: function (val) {
|
9147 | this._stopAtEdge = val;
|
9148 | },
|
9149 | enumerable: false,
|
9150 | configurable: true
|
9151 | });
|
9152 | |
9153 |
|
9154 |
|
9155 |
|
9156 |
|
9157 |
|
9158 |
|
9159 |
|
9160 |
|
9161 |
|
9162 |
|
9163 | __proto.updatePosition = function (progressInPanel) {
|
9164 | var flicking = getFlickingAttached(this._flicking, "Control");
|
9165 | var camera = flicking.camera;
|
9166 | var activePanel = this._activePanel;
|
9167 |
|
9168 | if (activePanel) {
|
9169 | var panelRange = activePanel.range;
|
9170 | var newPosition = panelRange.min + (panelRange.max - panelRange.min) * progressInPanel;
|
9171 | camera.lookAt(camera.clampToReachablePosition(newPosition));
|
9172 | }
|
9173 | };
|
9174 | |
9175 |
|
9176 |
|
9177 |
|
9178 |
|
9179 |
|
9180 |
|
9181 |
|
9182 |
|
9183 |
|
9184 |
|
9185 |
|
9186 |
|
9187 |
|
9188 |
|
9189 |
|
9190 |
|
9191 |
|
9192 |
|
9193 |
|
9194 |
|
9195 |
|
9196 |
|
9197 |
|
9198 |
|
9199 |
|
9200 |
|
9201 |
|
9202 |
|
9203 |
|
9204 |
|
9205 |
|
9206 |
|
9207 |
|
9208 |
|
9209 |
|
9210 |
|
9211 |
|
9212 | __proto.moveToPosition = function (position, duration, axesEvent) {
|
9213 | return __awaiter(this, void 0, void 0, function () {
|
9214 | var flicking, camera, targetPos, anchorAtPosition, targetPanel;
|
9215 | return __generator(this, function (_a) {
|
9216 | flicking = getFlickingAttached(this._flicking, "Control");
|
9217 | camera = flicking.camera;
|
9218 | targetPos = camera.clampToReachablePosition(position);
|
9219 | anchorAtPosition = camera.findAnchorIncludePosition(targetPos);
|
9220 |
|
9221 | if (!anchorAtPosition) {
|
9222 | return [2
|
9223 |
|
9224 | , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE))];
|
9225 | }
|
9226 |
|
9227 | targetPanel = anchorAtPosition.panel;
|
9228 |
|
9229 | if (targetPanel !== this._activePanel) {
|
9230 | this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
|
9231 | }
|
9232 |
|
9233 | return [2
|
9234 |
|
9235 | , this._animateToPosition({
|
9236 | position: this._stopAtEdge ? targetPos : position,
|
9237 | duration: duration,
|
9238 | newActivePanel: targetPanel,
|
9239 | axesEvent: axesEvent
|
9240 | })];
|
9241 | });
|
9242 | });
|
9243 | };
|
9244 |
|
9245 | return FreeControl;
|
9246 | }(Control$1);
|
9247 |
|
9248 | |
9249 |
|
9250 |
|
9251 |
|
9252 |
|
9253 | var StrictControl = function (_super) {
|
9254 | __extends$2(StrictControl, _super);
|
9255 |
|
9256 |
|
9257 |
|
9258 | function StrictControl(_a) {
|
9259 | var _b = _a === void 0 ? {} : _a,
|
9260 | _c = _b.count,
|
9261 | count = _c === void 0 ? 1 : _c;
|
9262 |
|
9263 | var _this = _super.call(this) || this;
|
9264 |
|
9265 | _this.setActive = function (newActivePanel, prevActivePanel, isTrusted) {
|
9266 | _super.prototype.setActive.call(_this, newActivePanel, prevActivePanel, isTrusted);
|
9267 |
|
9268 | _this.updateInput();
|
9269 | };
|
9270 |
|
9271 | _this._count = count;
|
9272 |
|
9273 | _this._resetIndexRange();
|
9274 |
|
9275 | return _this;
|
9276 | }
|
9277 |
|
9278 | var __proto = StrictControl.prototype;
|
9279 | Object.defineProperty(__proto, "count", {
|
9280 | |
9281 |
|
9282 |
|
9283 |
|
9284 |
|
9285 |
|
9286 | get: function () {
|
9287 | return this._count;
|
9288 | },
|
9289 | set: function (val) {
|
9290 | this._count = val;
|
9291 | },
|
9292 | enumerable: false,
|
9293 | configurable: true
|
9294 | });
|
9295 | |
9296 |
|
9297 |
|
9298 |
|
9299 |
|
9300 |
|
9301 | __proto.destroy = function () {
|
9302 | _super.prototype.destroy.call(this);
|
9303 |
|
9304 | this._resetIndexRange();
|
9305 | };
|
9306 | |
9307 |
|
9308 |
|
9309 |
|
9310 |
|
9311 |
|
9312 |
|
9313 |
|
9314 | __proto.updateInput = function () {
|
9315 | var _a;
|
9316 |
|
9317 | var flicking = getFlickingAttached(this._flicking, "Control");
|
9318 | var camera = flicking.camera;
|
9319 | var renderer = flicking.renderer;
|
9320 | var controller = this._controller;
|
9321 | var controlParams = camera.controlParams;
|
9322 | var count = this._count;
|
9323 | var activePanel = controller.state.animating ? (_a = camera.findNearestAnchor(camera.position)) === null || _a === void 0 ? void 0 : _a.panel : this._activePanel;
|
9324 |
|
9325 | if (!activePanel) {
|
9326 | controller.update(controlParams);
|
9327 |
|
9328 | this._resetIndexRange();
|
9329 |
|
9330 | return this;
|
9331 | }
|
9332 |
|
9333 | var cameraRange = controlParams.range;
|
9334 | var currentPos = activePanel.position;
|
9335 | var currentIndex = activePanel.index;
|
9336 | var panelCount = renderer.panelCount;
|
9337 | var prevPanelIndex = currentIndex - count;
|
9338 | var nextPanelIndex = currentIndex + count;
|
9339 |
|
9340 | if (prevPanelIndex < 0) {
|
9341 | prevPanelIndex = flicking.circularEnabled ? getMinusCompensatedIndex((prevPanelIndex + 1) % panelCount - 1, panelCount) : clamp(prevPanelIndex, 0, panelCount - 1);
|
9342 | }
|
9343 |
|
9344 | if (nextPanelIndex >= panelCount) {
|
9345 | nextPanelIndex = flicking.circularEnabled ? nextPanelIndex % panelCount : clamp(nextPanelIndex, 0, panelCount - 1);
|
9346 | }
|
9347 |
|
9348 | var prevPanel = renderer.panels[prevPanelIndex];
|
9349 | var nextPanel = renderer.panels[nextPanelIndex];
|
9350 | var prevPos = Math.max(prevPanel.position, cameraRange.min);
|
9351 | var nextPos = Math.min(nextPanel.position, cameraRange.max);
|
9352 |
|
9353 | if (prevPos > currentPos) {
|
9354 | prevPos -= camera.rangeDiff;
|
9355 | }
|
9356 |
|
9357 | if (nextPos < currentPos) {
|
9358 | nextPos += camera.rangeDiff;
|
9359 | }
|
9360 |
|
9361 | controlParams.range = {
|
9362 | min: prevPos,
|
9363 | max: nextPos
|
9364 | };
|
9365 |
|
9366 | if (controlParams.circular) {
|
9367 | if (controlParams.position < prevPos) {
|
9368 | controlParams.position += camera.rangeDiff;
|
9369 | }
|
9370 |
|
9371 | if (controlParams.position > nextPos) {
|
9372 | controlParams.position -= camera.rangeDiff;
|
9373 | }
|
9374 | }
|
9375 |
|
9376 | controlParams.circular = false;
|
9377 | controller.update(controlParams);
|
9378 | this._indexRange = {
|
9379 | min: prevPanel.index,
|
9380 | max: nextPanel.index
|
9381 | };
|
9382 | return this;
|
9383 | };
|
9384 | |
9385 |
|
9386 |
|
9387 |
|
9388 |
|
9389 |
|
9390 |
|
9391 |
|
9392 |
|
9393 |
|
9394 |
|
9395 |
|
9396 |
|
9397 |
|
9398 |
|
9399 |
|
9400 |
|
9401 |
|
9402 |
|
9403 |
|
9404 |
|
9405 |
|
9406 |
|
9407 |
|
9408 |
|
9409 |
|
9410 |
|
9411 |
|
9412 |
|
9413 |
|
9414 |
|
9415 |
|
9416 |
|
9417 |
|
9418 |
|
9419 |
|
9420 |
|
9421 |
|
9422 | __proto.moveToPosition = function (position, duration, axesEvent) {
|
9423 | return __awaiter(this, void 0, void 0, function () {
|
9424 | var flicking, camera, activePanel, axesRange, indexRange, cameraRange, clampedPosition, anchorAtPosition, prevPos, isOverThreshold, adjacentAnchor, targetPos, targetPanel, anchors, firstAnchor, lastAnchor, shouldBounceToFirst, shouldBounceToLast, targetAnchor;
|
9425 | return __generator(this, function (_a) {
|
9426 | flicking = getFlickingAttached(this._flicking, "Control");
|
9427 | camera = flicking.camera;
|
9428 | activePanel = this._activePanel;
|
9429 | axesRange = this._controller.range;
|
9430 | indexRange = this._indexRange;
|
9431 | cameraRange = camera.range;
|
9432 | clampedPosition = clamp(camera.clampToReachablePosition(position), axesRange[0], axesRange[1]);
|
9433 | anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
|
9434 |
|
9435 | if (!anchorAtPosition || !activePanel) {
|
9436 | return [2
|
9437 |
|
9438 | , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE))];
|
9439 | }
|
9440 |
|
9441 | prevPos = activePanel.position;
|
9442 | isOverThreshold = Math.abs(position - prevPos) >= flicking.threshold;
|
9443 | adjacentAnchor = position > prevPos ? camera.getNextAnchor(anchorAtPosition) : camera.getPrevAnchor(anchorAtPosition);
|
9444 | anchors = camera.anchorPoints;
|
9445 | firstAnchor = anchors[0];
|
9446 | lastAnchor = anchors[anchors.length - 1];
|
9447 | shouldBounceToFirst = position <= cameraRange.min && isBetween(firstAnchor.panel.index, indexRange.min, indexRange.max);
|
9448 | shouldBounceToLast = position >= cameraRange.max && isBetween(lastAnchor.panel.index, indexRange.min, indexRange.max);
|
9449 |
|
9450 | if (shouldBounceToFirst || shouldBounceToLast) {
|
9451 | targetAnchor = position < cameraRange.min ? firstAnchor : lastAnchor;
|
9452 | targetPanel = targetAnchor.panel;
|
9453 | targetPos = targetAnchor.position;
|
9454 | } else if (isOverThreshold && anchorAtPosition.position !== activePanel.position) {
|
9455 |
|
9456 | targetPanel = anchorAtPosition.panel;
|
9457 | targetPos = anchorAtPosition.position;
|
9458 | } else if (isOverThreshold && adjacentAnchor && isBetween(adjacentAnchor.index, indexRange.min, indexRange.max)) {
|
9459 |
|
9460 | targetPanel = adjacentAnchor.panel;
|
9461 | targetPos = adjacentAnchor.position;
|
9462 | } else {
|
9463 |
|
9464 | targetPos = camera.clampToReachablePosition(activePanel.position);
|
9465 | targetPanel = activePanel;
|
9466 | }
|
9467 |
|
9468 | this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
|
9469 |
|
9470 | return [2
|
9471 |
|
9472 | , this._animateToPosition({
|
9473 | position: targetPos,
|
9474 | duration: duration,
|
9475 | newActivePanel: targetPanel,
|
9476 | axesEvent: axesEvent
|
9477 | })];
|
9478 | });
|
9479 | });
|
9480 | };
|
9481 |
|
9482 | __proto._resetIndexRange = function () {
|
9483 | this._indexRange = {
|
9484 | min: 0,
|
9485 | max: 0
|
9486 | };
|
9487 | };
|
9488 |
|
9489 | return StrictControl;
|
9490 | }(Control$1);
|
9491 |
|
9492 | |
9493 |
|
9494 |
|
9495 |
|
9496 |
|
9497 | var Control = {
|
9498 | __proto__: null,
|
9499 | Control: Control$1,
|
9500 | SnapControl: SnapControl,
|
9501 | FreeControl: FreeControl,
|
9502 | StrictControl: StrictControl,
|
9503 | AxesController: AxesController,
|
9504 | State: State,
|
9505 | IdleState: IdleState,
|
9506 | HoldingState: HoldingState,
|
9507 | DraggingState: DraggingState,
|
9508 | AnimatingState: AnimatingState,
|
9509 | DisabledState: DisabledState,
|
9510 | StateMachine: StateMachine
|
9511 | };
|
9512 |
|
9513 | |
9514 |
|
9515 |
|
9516 |
|
9517 |
|
9518 | var Camera$1 = function () {
|
9519 |
|
9520 | function Camera(_a) {
|
9521 | var _this = this;
|
9522 |
|
9523 | var _b = _a === void 0 ? {} : _a,
|
9524 | _c = _b.align,
|
9525 | align = _c === void 0 ? ALIGN.CENTER : _c;
|
9526 |
|
9527 | this._checkTranslateSupport = function () {
|
9528 | var e_1, _a;
|
9529 |
|
9530 | var transforms = ["webkitTransform", "msTransform", "MozTransform", "OTransform", "transform"];
|
9531 | var supportedStyle = document.documentElement.style;
|
9532 | var transformName = "";
|
9533 |
|
9534 | try {
|
9535 | for (var transforms_1 = __values$3(transforms), transforms_1_1 = transforms_1.next(); !transforms_1_1.done; transforms_1_1 = transforms_1.next()) {
|
9536 | var prefixedTransform = transforms_1_1.value;
|
9537 |
|
9538 | if (prefixedTransform in supportedStyle) {
|
9539 | transformName = prefixedTransform;
|
9540 | }
|
9541 | }
|
9542 | } catch (e_1_1) {
|
9543 | e_1 = {
|
9544 | error: e_1_1
|
9545 | };
|
9546 | } finally {
|
9547 | try {
|
9548 | if (transforms_1_1 && !transforms_1_1.done && (_a = transforms_1.return)) _a.call(transforms_1);
|
9549 | } finally {
|
9550 | if (e_1) throw e_1.error;
|
9551 | }
|
9552 | }
|
9553 |
|
9554 | if (!transformName) {
|
9555 | throw new FlickingError(MESSAGE.TRANSFORM_NOT_SUPPORTED, CODE.TRANSFORM_NOT_SUPPORTED);
|
9556 | }
|
9557 |
|
9558 | _this._transform = transformName;
|
9559 | };
|
9560 |
|
9561 | this._flicking = null;
|
9562 |
|
9563 | this._resetInternalValues();
|
9564 |
|
9565 |
|
9566 | this._align = align;
|
9567 | }
|
9568 |
|
9569 | var __proto = Camera.prototype;
|
9570 | Object.defineProperty(__proto, "element", {
|
9571 |
|
9572 |
|
9573 | |
9574 |
|
9575 |
|
9576 |
|
9577 |
|
9578 |
|
9579 | get: function () {
|
9580 | return this._el;
|
9581 | },
|
9582 | enumerable: false,
|
9583 | configurable: true
|
9584 | });
|
9585 | Object.defineProperty(__proto, "position", {
|
9586 | |
9587 |
|
9588 |
|
9589 |
|
9590 |
|
9591 |
|
9592 | get: function () {
|
9593 | return this._position;
|
9594 | },
|
9595 | enumerable: false,
|
9596 | configurable: true
|
9597 | });
|
9598 | Object.defineProperty(__proto, "alignPosition", {
|
9599 | |
9600 |
|
9601 |
|
9602 |
|
9603 |
|
9604 |
|
9605 | get: function () {
|
9606 | return this._alignPos;
|
9607 | },
|
9608 | enumerable: false,
|
9609 | configurable: true
|
9610 | });
|
9611 | Object.defineProperty(__proto, "offset", {
|
9612 | |
9613 |
|
9614 |
|
9615 |
|
9616 |
|
9617 |
|
9618 |
|
9619 | get: function () {
|
9620 | return this._offset;
|
9621 | },
|
9622 | enumerable: false,
|
9623 | configurable: true
|
9624 | });
|
9625 | Object.defineProperty(__proto, "range", {
|
9626 | |
9627 |
|
9628 |
|
9629 |
|
9630 |
|
9631 |
|
9632 |
|
9633 |
|
9634 | get: function () {
|
9635 | return this._range;
|
9636 | },
|
9637 | enumerable: false,
|
9638 | configurable: true
|
9639 | });
|
9640 | Object.defineProperty(__proto, "rangeDiff", {
|
9641 | |
9642 |
|
9643 |
|
9644 |
|
9645 |
|
9646 |
|
9647 | get: function () {
|
9648 | return this._range.max - this._range.min;
|
9649 | },
|
9650 | enumerable: false,
|
9651 | configurable: true
|
9652 | });
|
9653 | Object.defineProperty(__proto, "visiblePanels", {
|
9654 | |
9655 |
|
9656 |
|
9657 |
|
9658 |
|
9659 |
|
9660 | get: function () {
|
9661 | return this._visiblePanels;
|
9662 | },
|
9663 | enumerable: false,
|
9664 | configurable: true
|
9665 | });
|
9666 | Object.defineProperty(__proto, "visibleRange", {
|
9667 | |
9668 |
|
9669 |
|
9670 |
|
9671 |
|
9672 |
|
9673 |
|
9674 |
|
9675 | get: function () {
|
9676 | return {
|
9677 | min: this._position - this._alignPos,
|
9678 | max: this._position - this._alignPos + this.size
|
9679 | };
|
9680 | },
|
9681 | enumerable: false,
|
9682 | configurable: true
|
9683 | });
|
9684 | Object.defineProperty(__proto, "anchorPoints", {
|
9685 | |
9686 |
|
9687 |
|
9688 |
|
9689 |
|
9690 |
|
9691 | get: function () {
|
9692 | return this._anchors;
|
9693 | },
|
9694 | enumerable: false,
|
9695 | configurable: true
|
9696 | });
|
9697 | Object.defineProperty(__proto, "controlParams", {
|
9698 | |
9699 |
|
9700 |
|
9701 |
|
9702 |
|
9703 |
|
9704 | get: function () {
|
9705 | return {
|
9706 | range: this._range,
|
9707 | position: this._position,
|
9708 | circular: false
|
9709 | };
|
9710 | },
|
9711 | enumerable: false,
|
9712 | configurable: true
|
9713 | });
|
9714 | Object.defineProperty(__proto, "atEdge", {
|
9715 | |
9716 |
|
9717 |
|
9718 |
|
9719 |
|
9720 |
|
9721 | get: function () {
|
9722 | return this._position <= this._range.min || this._position >= this._range.max;
|
9723 | },
|
9724 | enumerable: false,
|
9725 | configurable: true
|
9726 | });
|
9727 | Object.defineProperty(__proto, "size", {
|
9728 | |
9729 |
|
9730 |
|
9731 |
|
9732 |
|
9733 |
|
9734 | get: function () {
|
9735 | var flicking = this._flicking;
|
9736 | return flicking ? flicking.horizontal ? flicking.viewport.width : flicking.viewport.height : 0;
|
9737 | },
|
9738 | enumerable: false,
|
9739 | configurable: true
|
9740 | });
|
9741 | Object.defineProperty(__proto, "progress", {
|
9742 | |
9743 |
|
9744 |
|
9745 |
|
9746 |
|
9747 |
|
9748 |
|
9749 |
|
9750 | get: function () {
|
9751 | var flicking = this._flicking;
|
9752 | var position = this._position + this._offset;
|
9753 | var nearestAnchor = this.findNearestAnchor(this._position);
|
9754 |
|
9755 | if (!flicking || !nearestAnchor) {
|
9756 | return NaN;
|
9757 | }
|
9758 |
|
9759 | var nearestPanel = nearestAnchor.panel;
|
9760 | var panelPos = nearestPanel.position + nearestPanel.offset;
|
9761 | var bounceSize = flicking.control.controller.bounce;
|
9762 | var _a = this.range,
|
9763 | prevRange = _a.min,
|
9764 | nextRange = _a.max;
|
9765 | var rangeDiff = this.rangeDiff;
|
9766 |
|
9767 | if (position === panelPos) {
|
9768 | return nearestPanel.index;
|
9769 | }
|
9770 |
|
9771 | if (position < panelPos) {
|
9772 | var prevPanel = nearestPanel.prev();
|
9773 | var prevPosition = prevPanel ? prevPanel.position + prevPanel.offset : prevRange - bounceSize[0];
|
9774 |
|
9775 | if (prevPosition > panelPos) {
|
9776 | prevPosition -= rangeDiff;
|
9777 | }
|
9778 |
|
9779 | return nearestPanel.index - 1 + getProgress(position, prevPosition, panelPos);
|
9780 | } else {
|
9781 | var nextPanel = nearestPanel.next();
|
9782 | var nextPosition = nextPanel ? nextPanel.position + nextPanel.offset : nextRange + bounceSize[1];
|
9783 |
|
9784 | if (nextPosition < panelPos) {
|
9785 | nextPosition += rangeDiff;
|
9786 | }
|
9787 |
|
9788 | return nearestPanel.index + getProgress(position, panelPos, nextPosition);
|
9789 | }
|
9790 | },
|
9791 | enumerable: false,
|
9792 | configurable: true
|
9793 | });
|
9794 | Object.defineProperty(__proto, "align", {
|
9795 |
|
9796 |
|
9797 | |
9798 |
|
9799 |
|
9800 |
|
9801 |
|
9802 | get: function () {
|
9803 | return this._align;
|
9804 | },
|
9805 |
|
9806 | set: function (val) {
|
9807 | this._align = val;
|
9808 | },
|
9809 | enumerable: false,
|
9810 | configurable: true
|
9811 | });
|
9812 | |
9813 |
|
9814 |
|
9815 |
|
9816 |
|
9817 |
|
9818 |
|
9819 |
|
9820 |
|
9821 |
|
9822 |
|
9823 | __proto.init = function (flicking) {
|
9824 | this._flicking = flicking;
|
9825 | var viewportEl = flicking.viewport.element;
|
9826 | checkExistence(viewportEl.firstElementChild, "First element child of the viewport element");
|
9827 | this._el = viewportEl.firstElementChild;
|
9828 |
|
9829 | this._checkTranslateSupport();
|
9830 |
|
9831 | return this;
|
9832 | };
|
9833 | |
9834 |
|
9835 |
|
9836 |
|
9837 |
|
9838 |
|
9839 |
|
9840 | __proto.destroy = function () {
|
9841 | this._flicking = null;
|
9842 |
|
9843 | this._resetInternalValues();
|
9844 |
|
9845 | return this;
|
9846 | };
|
9847 | |
9848 |
|
9849 |
|
9850 |
|
9851 |
|
9852 |
|
9853 |
|
9854 |
|
9855 |
|
9856 |
|
9857 |
|
9858 | __proto.lookAt = function (pos) {
|
9859 | var prevPos = this._position;
|
9860 | this._position = pos;
|
9861 |
|
9862 | this._refreshVisiblePanels();
|
9863 |
|
9864 | this._checkNeedPanel();
|
9865 |
|
9866 | this._checkReachEnd(prevPos, pos);
|
9867 |
|
9868 | this._applyTransform();
|
9869 | };
|
9870 | |
9871 |
|
9872 |
|
9873 |
|
9874 |
|
9875 |
|
9876 |
|
9877 |
|
9878 |
|
9879 |
|
9880 | __proto.getPrevAnchor = function (anchor) {
|
9881 | return this._anchors[anchor.index - 1] || null;
|
9882 | };
|
9883 | |
9884 |
|
9885 |
|
9886 |
|
9887 |
|
9888 |
|
9889 |
|
9890 |
|
9891 |
|
9892 |
|
9893 | __proto.getNextAnchor = function (anchor) {
|
9894 | return this._anchors[anchor.index + 1] || null;
|
9895 | };
|
9896 | |
9897 |
|
9898 |
|
9899 |
|
9900 |
|
9901 |
|
9902 |
|
9903 |
|
9904 |
|
9905 |
|
9906 | __proto.getProgressInPanel = function (panel) {
|
9907 | var panelRange = panel.range;
|
9908 | return (this._position - panelRange.min) / (panelRange.max - panelRange.min);
|
9909 | };
|
9910 | |
9911 |
|
9912 |
|
9913 |
|
9914 |
|
9915 |
|
9916 |
|
9917 |
|
9918 |
|
9919 |
|
9920 | __proto.findAnchorIncludePosition = function (position) {
|
9921 | var anchors = this._anchors;
|
9922 | var anchorsIncludingPosition = anchors.filter(function (anchor) {
|
9923 | return anchor.panel.includePosition(position, true);
|
9924 | });
|
9925 | return anchorsIncludingPosition.reduce(function (nearest, anchor) {
|
9926 | if (!nearest) return anchor;
|
9927 | return Math.abs(nearest.position - position) < Math.abs(anchor.position - position) ? nearest : anchor;
|
9928 | }, null);
|
9929 | };
|
9930 | |
9931 |
|
9932 |
|
9933 |
|
9934 |
|
9935 |
|
9936 |
|
9937 |
|
9938 |
|
9939 |
|
9940 | __proto.findNearestAnchor = function (position) {
|
9941 | var anchors = this._anchors;
|
9942 | if (anchors.length <= 0) return null;
|
9943 | var prevDist = Infinity;
|
9944 |
|
9945 | for (var anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
|
9946 | var anchor = anchors[anchorIdx];
|
9947 | var dist = Math.abs(anchor.position - position);
|
9948 |
|
9949 | if (dist > prevDist) {
|
9950 |
|
9951 | return anchors[anchorIdx - 1];
|
9952 | }
|
9953 |
|
9954 | prevDist = dist;
|
9955 | }
|
9956 |
|
9957 |
|
9958 | return anchors[anchors.length - 1];
|
9959 | };
|
9960 | |
9961 |
|
9962 |
|
9963 |
|
9964 |
|
9965 |
|
9966 |
|
9967 | __proto.findActiveAnchor = function () {
|
9968 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
9969 | var activeIndex = flicking.control.activeIndex;
|
9970 | return find$1(this._anchors, function (anchor) {
|
9971 | return anchor.panel.index === activeIndex;
|
9972 | });
|
9973 | };
|
9974 | |
9975 |
|
9976 |
|
9977 |
|
9978 |
|
9979 |
|
9980 |
|
9981 |
|
9982 | __proto.clampToReachablePosition = function (position) {
|
9983 | var range = this._range;
|
9984 | return clamp(position, range.min, range.max);
|
9985 | };
|
9986 | |
9987 |
|
9988 |
|
9989 |
|
9990 |
|
9991 |
|
9992 |
|
9993 |
|
9994 | __proto.canReach = function (panel) {
|
9995 | var range = this._range;
|
9996 | if (panel.removed) return false;
|
9997 | var panelPos = panel.position;
|
9998 | return panelPos >= range.min && panelPos <= range.max;
|
9999 | };
|
10000 | |
10001 |
|
10002 |
|
10003 |
|
10004 |
|
10005 |
|
10006 |
|
10007 |
|
10008 | __proto.canSee = function (panel) {
|
10009 | var visibleRange = this.visibleRange;
|
10010 |
|
10011 | return panel.includeRange(visibleRange.min, visibleRange.max, false);
|
10012 | };
|
10013 | |
10014 |
|
10015 |
|
10016 |
|
10017 |
|
10018 |
|
10019 |
|
10020 |
|
10021 | __proto.updateAlignPos = function () {
|
10022 | var align = this._align;
|
10023 | var alignVal = typeof align === "object" ? align.camera : align;
|
10024 | this._alignPos = parseAlign$1(alignVal, this.size);
|
10025 | return this;
|
10026 | };
|
10027 | |
10028 |
|
10029 |
|
10030 |
|
10031 |
|
10032 |
|
10033 |
|
10034 |
|
10035 |
|
10036 |
|
10037 |
|
10038 | __proto.updateAnchors = function () {
|
10039 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
10040 | var panels = flicking.renderer.panels;
|
10041 | this._anchors = panels.map(function (panel, index) {
|
10042 | return new AnchorPoint({
|
10043 | index: index,
|
10044 | position: panel.position,
|
10045 | panel: panel
|
10046 | });
|
10047 | });
|
10048 | return this;
|
10049 | };
|
10050 | |
10051 |
|
10052 |
|
10053 |
|
10054 |
|
10055 |
|
10056 |
|
10057 |
|
10058 |
|
10059 |
|
10060 |
|
10061 | __proto.updateAdaptiveHeight = function () {
|
10062 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
10063 | var activePanel = flicking.control.activePanel;
|
10064 | if (!flicking.horizontal || !flicking.adaptive || !activePanel) return;
|
10065 | flicking.viewport.setSize({
|
10066 | height: activePanel.height
|
10067 | });
|
10068 | };
|
10069 |
|
10070 | __proto.updateOffset = function () {
|
10071 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
10072 | var unRenderedPanels = flicking.panels.filter(function (panel) {
|
10073 | return !panel.rendered;
|
10074 | });
|
10075 | var position = this._position;
|
10076 | this._offset = unRenderedPanels.filter(function (panel) {
|
10077 | return panel.position + panel.offset < position;
|
10078 | }).reduce(function (offset, panel) {
|
10079 | return offset + panel.sizeIncludingMargin;
|
10080 | }, 0);
|
10081 |
|
10082 | this._applyTransform();
|
10083 | };
|
10084 | |
10085 |
|
10086 |
|
10087 |
|
10088 |
|
10089 |
|
10090 |
|
10091 |
|
10092 | __proto.resetNeedPanelHistory = function () {
|
10093 | this._needPanelTriggered = {
|
10094 | prev: false,
|
10095 | next: false
|
10096 | };
|
10097 | return this;
|
10098 | };
|
10099 |
|
10100 | __proto._resetInternalValues = function () {
|
10101 | this._position = 0;
|
10102 | this._alignPos = 0;
|
10103 | this._offset = 0;
|
10104 | this._range = {
|
10105 | min: 0,
|
10106 | max: 0
|
10107 | };
|
10108 | this._visiblePanels = [];
|
10109 | this._anchors = [];
|
10110 | this._needPanelTriggered = {
|
10111 | prev: false,
|
10112 | next: false
|
10113 | };
|
10114 | };
|
10115 |
|
10116 | __proto._refreshVisiblePanels = function () {
|
10117 | var _this = this;
|
10118 |
|
10119 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
10120 | var panels = flicking.renderer.panels;
|
10121 | var newVisiblePanels = panels.filter(function (panel) {
|
10122 | return _this.canSee(panel);
|
10123 | });
|
10124 | var prevVisiblePanels = this._visiblePanels;
|
10125 | this._visiblePanels = newVisiblePanels;
|
10126 | var added = newVisiblePanels.filter(function (panel) {
|
10127 | return !includes(prevVisiblePanels, panel);
|
10128 | });
|
10129 | var removed = prevVisiblePanels.filter(function (panel) {
|
10130 | return !includes(newVisiblePanels, panel);
|
10131 | });
|
10132 |
|
10133 | if (added.length > 0 || removed.length > 0) {
|
10134 | void flicking.renderer.render().then(function () {
|
10135 | flicking.trigger(new ComponentEvent$1(EVENTS.VISIBLE_CHANGE, {
|
10136 | added: added,
|
10137 | removed: removed,
|
10138 | visiblePanels: newVisiblePanels
|
10139 | }));
|
10140 | });
|
10141 | }
|
10142 | };
|
10143 |
|
10144 | __proto._checkNeedPanel = function () {
|
10145 | var needPanelTriggered = this._needPanelTriggered;
|
10146 | if (needPanelTriggered.prev && needPanelTriggered.next) return;
|
10147 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
10148 | var panels = flicking.renderer.panels;
|
10149 |
|
10150 | if (panels.length <= 0) {
|
10151 | if (!needPanelTriggered.prev) {
|
10152 | flicking.trigger(new ComponentEvent$1(EVENTS.NEED_PANEL, {
|
10153 | direction: DIRECTION.PREV
|
10154 | }));
|
10155 | needPanelTriggered.prev = true;
|
10156 | }
|
10157 |
|
10158 | if (!needPanelTriggered.next) {
|
10159 | flicking.trigger(new ComponentEvent$1(EVENTS.NEED_PANEL, {
|
10160 | direction: DIRECTION.NEXT
|
10161 | }));
|
10162 | needPanelTriggered.next = true;
|
10163 | }
|
10164 |
|
10165 | return;
|
10166 | }
|
10167 |
|
10168 | var cameraPosition = this._position;
|
10169 | var cameraSize = this.size;
|
10170 | var cameraRange = this._range;
|
10171 | var needPanelThreshold = flicking.needPanelThreshold;
|
10172 | var cameraPrev = cameraPosition - this._alignPos;
|
10173 | var cameraNext = cameraPrev + cameraSize;
|
10174 | var firstPanel = panels[0];
|
10175 | var lastPanel = panels[panels.length - 1];
|
10176 |
|
10177 | if (!needPanelTriggered.prev) {
|
10178 | var firstPanelPrev = firstPanel.range.min;
|
10179 |
|
10180 | if (cameraPrev <= firstPanelPrev + needPanelThreshold || cameraPosition <= cameraRange.min + needPanelThreshold) {
|
10181 | flicking.trigger(new ComponentEvent$1(EVENTS.NEED_PANEL, {
|
10182 | direction: DIRECTION.PREV
|
10183 | }));
|
10184 | needPanelTriggered.prev = true;
|
10185 | }
|
10186 | }
|
10187 |
|
10188 | if (!needPanelTriggered.next) {
|
10189 | var lastPanelNext = lastPanel.range.max;
|
10190 |
|
10191 | if (cameraNext >= lastPanelNext - needPanelThreshold || cameraPosition >= cameraRange.max - needPanelThreshold) {
|
10192 | flicking.trigger(new ComponentEvent$1(EVENTS.NEED_PANEL, {
|
10193 | direction: DIRECTION.NEXT
|
10194 | }));
|
10195 | needPanelTriggered.next = true;
|
10196 | }
|
10197 | }
|
10198 | };
|
10199 |
|
10200 | __proto._checkReachEnd = function (prevPos, newPos) {
|
10201 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
10202 | var range = this._range;
|
10203 | var wasBetweenRange = prevPos > range.min && prevPos < range.max;
|
10204 | var isBetweenRange = newPos > range.min && newPos < range.max;
|
10205 | if (!wasBetweenRange || isBetweenRange) return;
|
10206 | var direction = newPos <= range.min ? DIRECTION.PREV : DIRECTION.NEXT;
|
10207 | flicking.trigger(new ComponentEvent$1(EVENTS.REACH_EDGE, {
|
10208 | direction: direction
|
10209 | }));
|
10210 | };
|
10211 |
|
10212 | __proto._applyTransform = function () {
|
10213 | var el = this._el;
|
10214 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
10215 | var actualPosition = this._position - this._alignPos - this._offset;
|
10216 | el.style[this._transform] = flicking.horizontal ? "translate(" + -actualPosition + "px)" : "translate(0, " + -actualPosition + "px)";
|
10217 | };
|
10218 |
|
10219 | return Camera;
|
10220 | }();
|
10221 |
|
10222 | |
10223 |
|
10224 |
|
10225 |
|
10226 |
|
10227 | var LinearCamera = function (_super) {
|
10228 | __extends$2(LinearCamera, _super);
|
10229 |
|
10230 | function LinearCamera() {
|
10231 | return _super !== null && _super.apply(this, arguments) || this;
|
10232 | }
|
10233 | |
10234 |
|
10235 |
|
10236 |
|
10237 |
|
10238 |
|
10239 |
|
10240 |
|
10241 |
|
10242 |
|
10243 |
|
10244 | var __proto = LinearCamera.prototype;
|
10245 |
|
10246 | __proto.updateRange = function () {
|
10247 | var _a, _b;
|
10248 |
|
10249 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
10250 | var renderer = flicking.renderer;
|
10251 | var firstPanel = renderer.getPanel(0);
|
10252 | var lastPanel = renderer.getPanel(renderer.panelCount - 1);
|
10253 | this._range = {
|
10254 | min: (_a = firstPanel === null || firstPanel === void 0 ? void 0 : firstPanel.position) !== null && _a !== void 0 ? _a : 0,
|
10255 | max: (_b = lastPanel === null || lastPanel === void 0 ? void 0 : lastPanel.position) !== null && _b !== void 0 ? _b : 0
|
10256 | };
|
10257 | return this;
|
10258 | };
|
10259 |
|
10260 | return LinearCamera;
|
10261 | }(Camera$1);
|
10262 |
|
10263 | |
10264 |
|
10265 |
|
10266 |
|
10267 |
|
10268 | var CircularCamera = function (_super) {
|
10269 | __extends$2(CircularCamera, _super);
|
10270 |
|
10271 | function CircularCamera() {
|
10272 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
10273 |
|
10274 | _this._circularOffset = 0;
|
10275 | _this._circularEnabled = false;
|
10276 | return _this;
|
10277 | }
|
10278 |
|
10279 | var __proto = CircularCamera.prototype;
|
10280 | Object.defineProperty(__proto, "offset", {
|
10281 | get: function () {
|
10282 | return this._offset - this._circularOffset;
|
10283 | },
|
10284 | enumerable: false,
|
10285 | configurable: true
|
10286 | });
|
10287 | Object.defineProperty(__proto, "controlParams", {
|
10288 | get: function () {
|
10289 | return {
|
10290 | range: this._range,
|
10291 | position: this._position,
|
10292 | circular: this._circularEnabled
|
10293 | };
|
10294 | },
|
10295 | enumerable: false,
|
10296 | configurable: true
|
10297 | });
|
10298 |
|
10299 | __proto.getPrevAnchor = function (anchor) {
|
10300 | if (!this._circularEnabled || anchor.index !== 0) return _super.prototype.getPrevAnchor.call(this, anchor);
|
10301 | var anchors = this._anchors;
|
10302 | var rangeDiff = this.rangeDiff;
|
10303 | var lastAnchor = anchors[anchors.length - 1];
|
10304 | return new AnchorPoint({
|
10305 | index: lastAnchor.index,
|
10306 | position: lastAnchor.position - rangeDiff,
|
10307 | panel: lastAnchor.panel
|
10308 | });
|
10309 | };
|
10310 |
|
10311 | __proto.getNextAnchor = function (anchor) {
|
10312 | var anchors = this._anchors;
|
10313 | if (!this._circularEnabled || anchor.index !== anchors.length - 1) return _super.prototype.getNextAnchor.call(this, anchor);
|
10314 | var rangeDiff = this.rangeDiff;
|
10315 | var firstAnchor = anchors[0];
|
10316 | return new AnchorPoint({
|
10317 | index: firstAnchor.index,
|
10318 | position: firstAnchor.position + rangeDiff,
|
10319 | panel: firstAnchor.panel
|
10320 | });
|
10321 | };
|
10322 |
|
10323 | __proto.findAnchorIncludePosition = function (position) {
|
10324 | if (!this._circularEnabled) return _super.prototype.findAnchorIncludePosition.call(this, position);
|
10325 | var range = this._range;
|
10326 | var positionInRange = circulatePosition(position, range.min, range.max);
|
10327 |
|
10328 | var anchorInRange = _super.prototype.findAnchorIncludePosition.call(this, positionInRange);
|
10329 |
|
10330 | if (!anchorInRange) return null;
|
10331 | var rangeDiff = this.rangeDiff;
|
10332 |
|
10333 | if (position < range.min) {
|
10334 | var loopCount = -Math.floor((range.min - position) / rangeDiff) - 1;
|
10335 | return new AnchorPoint({
|
10336 | index: anchorInRange.index,
|
10337 | position: anchorInRange.position + rangeDiff * loopCount,
|
10338 | panel: anchorInRange.panel
|
10339 | });
|
10340 | } else if (position > range.max) {
|
10341 | var loopCount = Math.floor((position - range.max) / rangeDiff) + 1;
|
10342 | return new AnchorPoint({
|
10343 | index: anchorInRange.index,
|
10344 | position: anchorInRange.position + rangeDiff * loopCount,
|
10345 | panel: anchorInRange.panel
|
10346 | });
|
10347 | }
|
10348 |
|
10349 | return anchorInRange;
|
10350 | };
|
10351 |
|
10352 | __proto.clampToReachablePosition = function (position) {
|
10353 |
|
10354 | return this._circularEnabled ? position : _super.prototype.clampToReachablePosition.call(this, position);
|
10355 | };
|
10356 |
|
10357 | __proto.canReach = function (panel) {
|
10358 | if (panel.removed) return false;
|
10359 | return this._circularEnabled
|
10360 | ? true : _super.prototype.canReach.call(this, panel);
|
10361 | };
|
10362 |
|
10363 | __proto.canSee = function (panel) {
|
10364 | var range = this._range;
|
10365 | var rangeDiff = this.rangeDiff;
|
10366 | var visibleRange = this.visibleRange;
|
10367 |
|
10368 | var visibleInCurrentRange = _super.prototype.canSee.call(this, panel);
|
10369 |
|
10370 | if (!this._circularEnabled) {
|
10371 | return visibleInCurrentRange;
|
10372 | }
|
10373 |
|
10374 |
|
10375 | if (visibleRange.min < range.min) {
|
10376 | return visibleInCurrentRange || panel.includeRange(visibleRange.min + rangeDiff, visibleRange.max + rangeDiff, false);
|
10377 | } else if (visibleRange.max > range.max) {
|
10378 | return visibleInCurrentRange || panel.includeRange(visibleRange.min - rangeDiff, visibleRange.max - rangeDiff, false);
|
10379 | }
|
10380 |
|
10381 | return visibleInCurrentRange;
|
10382 | };
|
10383 | |
10384 |
|
10385 |
|
10386 |
|
10387 |
|
10388 |
|
10389 |
|
10390 |
|
10391 |
|
10392 |
|
10393 |
|
10394 | __proto.updateRange = function () {
|
10395 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
10396 | var renderer = flicking.renderer;
|
10397 | var panels = renderer.panels;
|
10398 |
|
10399 | if (panels.length <= 0) {
|
10400 | this._resetInternalValues();
|
10401 |
|
10402 | return this;
|
10403 | }
|
10404 |
|
10405 | var firstPanel = panels[0];
|
10406 | var lastPanel = panels[panels.length - 1];
|
10407 | var firstPanelPrev = firstPanel.range.min - firstPanel.margin.prev;
|
10408 | var lastPanelNext = lastPanel.range.max + lastPanel.margin.next;
|
10409 | var visibleSize = this.size;
|
10410 | var panelSizeSum = lastPanelNext - firstPanelPrev;
|
10411 | var canSetCircularMode = panels.every(function (panel) {
|
10412 | return panelSizeSum - panel.size >= visibleSize;
|
10413 | });
|
10414 | this._circularEnabled = canSetCircularMode;
|
10415 |
|
10416 | if (canSetCircularMode) {
|
10417 | this._range = {
|
10418 | min: firstPanelPrev,
|
10419 | max: lastPanelNext
|
10420 | };
|
10421 | panels.forEach(function (panel) {
|
10422 | return panel.updateCircularToggleDirection();
|
10423 | });
|
10424 | } else {
|
10425 | this._range = {
|
10426 | min: firstPanel.position,
|
10427 | max: lastPanel.position
|
10428 | };
|
10429 | }
|
10430 |
|
10431 | this._updateCircularOffset();
|
10432 |
|
10433 | return this;
|
10434 | };
|
10435 |
|
10436 | __proto.lookAt = function (pos) {
|
10437 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
10438 | var prevPos = this._position;
|
10439 | if (pos === prevPos) return _super.prototype.lookAt.call(this, pos);
|
10440 | var panels = flicking.renderer.panels;
|
10441 | var toggled = panels.map(function (panel) {
|
10442 | return panel.toggle(prevPos, pos);
|
10443 | });
|
10444 | this._position = pos;
|
10445 |
|
10446 | if (toggled.some(function (isToggled) {
|
10447 | return isToggled;
|
10448 | })) {
|
10449 | this._updateCircularOffset();
|
10450 |
|
10451 | void flicking.renderer.render();
|
10452 | }
|
10453 |
|
10454 | return _super.prototype.lookAt.call(this, pos);
|
10455 | };
|
10456 |
|
10457 | __proto._applyTransform = function () {
|
10458 | var el = this._el;
|
10459 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
10460 | var actualPosition = this._position - this._alignPos - this._offset + this._circularOffset;
|
10461 | el.style[this._transform] = flicking.horizontal ? "translate(" + -actualPosition + "px)" : "translate(0, " + -actualPosition + "px)";
|
10462 | };
|
10463 |
|
10464 | __proto._resetInternalValues = function () {
|
10465 | _super.prototype._resetInternalValues.call(this);
|
10466 |
|
10467 | this._circularOffset = 0;
|
10468 | this._circularEnabled = false;
|
10469 | };
|
10470 |
|
10471 | __proto._calcPanelAreaSum = function (panels) {
|
10472 | return panels.reduce(function (sum, panel) {
|
10473 | return sum + panel.sizeIncludingMargin;
|
10474 | }, 0);
|
10475 | };
|
10476 |
|
10477 | __proto._updateCircularOffset = function () {
|
10478 | if (!this._circularEnabled) {
|
10479 | this._circularOffset = 0;
|
10480 | return;
|
10481 | }
|
10482 |
|
10483 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
10484 | var toggledPrev = [];
|
10485 | var toggledNext = [];
|
10486 | flicking.panels.filter(function (panel) {
|
10487 | return panel.toggled;
|
10488 | }).forEach(function (panel) {
|
10489 | if (panel.toggleDirection === DIRECTION.PREV) {
|
10490 | toggledPrev.push(panel);
|
10491 | } else {
|
10492 | toggledNext.push(panel);
|
10493 | }
|
10494 | });
|
10495 | this._circularOffset = this._calcPanelAreaSum(toggledPrev) - this._calcPanelAreaSum(toggledNext);
|
10496 | };
|
10497 |
|
10498 | return CircularCamera;
|
10499 | }(Camera$1);
|
10500 |
|
10501 | |
10502 |
|
10503 |
|
10504 |
|
10505 |
|
10506 | var BoundCamera = function (_super) {
|
10507 | __extends$2(BoundCamera, _super);
|
10508 |
|
10509 | function BoundCamera() {
|
10510 | return _super !== null && _super.apply(this, arguments) || this;
|
10511 | }
|
10512 | |
10513 |
|
10514 |
|
10515 |
|
10516 |
|
10517 |
|
10518 |
|
10519 |
|
10520 |
|
10521 |
|
10522 |
|
10523 | var __proto = BoundCamera.prototype;
|
10524 |
|
10525 | __proto.updateRange = function () {
|
10526 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
10527 | var renderer = flicking.renderer;
|
10528 | var alignPos = this._alignPos;
|
10529 | var firstPanel = renderer.getPanel(0);
|
10530 | var lastPanel = renderer.getPanel(renderer.panelCount - 1);
|
10531 |
|
10532 | if (!firstPanel || !lastPanel) {
|
10533 | this._range = {
|
10534 | min: 0,
|
10535 | max: 0
|
10536 | };
|
10537 | return this;
|
10538 | }
|
10539 |
|
10540 | var viewportSize = this.size;
|
10541 | var firstPanelPrev = firstPanel.range.min;
|
10542 | var lastPanelNext = lastPanel.range.max;
|
10543 | var panelAreaSize = lastPanelNext - firstPanelPrev;
|
10544 | var isBiggerThanViewport = viewportSize < panelAreaSize;
|
10545 | var firstPos = firstPanelPrev + alignPos;
|
10546 | var lastPos = lastPanelNext - viewportSize + alignPos;
|
10547 |
|
10548 | if (isBiggerThanViewport) {
|
10549 | this._range = {
|
10550 | min: firstPos,
|
10551 | max: lastPos
|
10552 | };
|
10553 | } else {
|
10554 | var align = this._align;
|
10555 | var alignVal = typeof align === "object" ? align.camera : align;
|
10556 | var pos = firstPos + parseAlign$1(alignVal, lastPos - firstPos);
|
10557 | this._range = {
|
10558 | min: pos,
|
10559 | max: pos
|
10560 | };
|
10561 | }
|
10562 |
|
10563 | return this;
|
10564 | };
|
10565 |
|
10566 | __proto.updateAnchors = function () {
|
10567 | var _this = this;
|
10568 |
|
10569 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
10570 | var panels = flicking.renderer.panels;
|
10571 |
|
10572 | if (panels.length <= 0) {
|
10573 | this._anchors = [];
|
10574 | return this;
|
10575 | }
|
10576 |
|
10577 | var range = this._range;
|
10578 | var reachablePanels = panels.filter(function (panel) {
|
10579 | return _this.canReach(panel);
|
10580 | });
|
10581 |
|
10582 | if (reachablePanels.length > 0) {
|
10583 | var shouldPrependBoundAnchor = reachablePanels[0].position !== range.min;
|
10584 | var shouldAppendBoundAnchor = reachablePanels[reachablePanels.length - 1].position !== range.max;
|
10585 | var indexOffset_1 = shouldPrependBoundAnchor ? 1 : 0;
|
10586 | var newAnchors = reachablePanels.map(function (panel, idx) {
|
10587 | return new AnchorPoint({
|
10588 | index: idx + indexOffset_1,
|
10589 | position: panel.position,
|
10590 | panel: panel
|
10591 | });
|
10592 | });
|
10593 |
|
10594 | if (shouldPrependBoundAnchor) {
|
10595 | newAnchors.splice(0, 0, new AnchorPoint({
|
10596 | index: 0,
|
10597 | position: range.min,
|
10598 | panel: panels[reachablePanels[0].index - 1]
|
10599 | }));
|
10600 | }
|
10601 |
|
10602 | if (shouldAppendBoundAnchor) {
|
10603 | newAnchors.push(new AnchorPoint({
|
10604 | index: newAnchors.length,
|
10605 | position: range.max,
|
10606 | panel: panels[reachablePanels[reachablePanels.length - 1].index + 1]
|
10607 | }));
|
10608 | }
|
10609 |
|
10610 | this._anchors = newAnchors;
|
10611 | } else if (range.min !== range.max) {
|
10612 |
|
10613 | var nearestPanelAtMin = this._findNearestPanel(range.min, panels);
|
10614 |
|
10615 | var panelAtMin = nearestPanelAtMin.index === panels.length - 1 ? nearestPanelAtMin.prev() : nearestPanelAtMin;
|
10616 | var panelAtMax = panelAtMin.next();
|
10617 | this._anchors = [new AnchorPoint({
|
10618 | index: 0,
|
10619 | position: range.min,
|
10620 | panel: panelAtMin
|
10621 | }), new AnchorPoint({
|
10622 | index: 1,
|
10623 | position: range.max,
|
10624 | panel: panelAtMax
|
10625 | })];
|
10626 | } else {
|
10627 | this._anchors = [new AnchorPoint({
|
10628 | index: 0,
|
10629 | position: range.min,
|
10630 | panel: this._findNearestPanel(range.min, panels)
|
10631 | })];
|
10632 | }
|
10633 |
|
10634 | return this;
|
10635 | };
|
10636 |
|
10637 | __proto.findAnchorIncludePosition = function (position) {
|
10638 | var range = this._range;
|
10639 | var anchors = this._anchors;
|
10640 | if (anchors.length <= 0) return null;
|
10641 |
|
10642 | if (position <= range.min) {
|
10643 | return anchors[0];
|
10644 | } else if (position >= range.max) {
|
10645 | return anchors[anchors.length - 1];
|
10646 | } else {
|
10647 | return _super.prototype.findAnchorIncludePosition.call(this, position);
|
10648 | }
|
10649 | };
|
10650 |
|
10651 | __proto._findNearestPanel = function (pos, panels) {
|
10652 | var prevDist = Infinity;
|
10653 |
|
10654 | for (var panelIdx = 0; panelIdx < panels.length; panelIdx++) {
|
10655 | var panel = panels[panelIdx];
|
10656 | var dist = Math.abs(panel.position - pos);
|
10657 |
|
10658 | if (dist > prevDist) {
|
10659 |
|
10660 | return panels[panelIdx - 1];
|
10661 | }
|
10662 |
|
10663 | prevDist = dist;
|
10664 | }
|
10665 |
|
10666 |
|
10667 | return panels[panels.length - 1];
|
10668 | };
|
10669 |
|
10670 | return BoundCamera;
|
10671 | }(Camera$1);
|
10672 |
|
10673 | |
10674 |
|
10675 |
|
10676 |
|
10677 |
|
10678 | var Camera = {
|
10679 | __proto__: null,
|
10680 | Camera: Camera$1,
|
10681 | LinearCamera: LinearCamera,
|
10682 | CircularCamera: CircularCamera,
|
10683 | BoundCamera: BoundCamera
|
10684 | };
|
10685 |
|
10686 | |
10687 |
|
10688 |
|
10689 |
|
10690 |
|
10691 |
|
10692 |
|
10693 |
|
10694 | |
10695 |
|
10696 |
|
10697 |
|
10698 |
|
10699 |
|
10700 |
|
10701 |
|
10702 |
|
10703 |
|
10704 |
|
10705 |
|
10706 |
|
10707 |
|
10708 | function __values(o) {
|
10709 | var s = typeof Symbol === "function" && Symbol.iterator,
|
10710 | m = s && o[s],
|
10711 | i = 0;
|
10712 | if (m) return m.call(o);
|
10713 | if (o && typeof o.length === "number") return {
|
10714 | next: function () {
|
10715 | if (o && i >= o.length) o = void 0;
|
10716 | return {
|
10717 | value: o && o[i++],
|
10718 | done: !o
|
10719 | };
|
10720 | }
|
10721 | };
|
10722 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
10723 | }
|
10724 |
|
10725 | |
10726 |
|
10727 |
|
10728 |
|
10729 |
|
10730 | function isUndefined(value) {
|
10731 | return typeof value === "undefined";
|
10732 | }
|
10733 | |
10734 |
|
10735 |
|
10736 |
|
10737 |
|
10738 |
|
10739 |
|
10740 | var Component =
|
10741 |
|
10742 | function () {
|
10743 | |
10744 |
|
10745 |
|
10746 | function Component() {
|
10747 | |
10748 |
|
10749 |
|
10750 |
|
10751 | this.options = {};
|
10752 | this._eventHandler = {};
|
10753 | }
|
10754 | |
10755 |
|
10756 |
|
10757 |
|
10758 |
|
10759 |
|
10760 |
|
10761 |
|
10762 |
|
10763 |
|
10764 |
|
10765 |
|
10766 |
|
10767 |
|
10768 |
|
10769 |
|
10770 |
|
10771 |
|
10772 |
|
10773 |
|
10774 |
|
10775 |
|
10776 |
|
10777 |
|
10778 |
|
10779 |
|
10780 |
|
10781 |
|
10782 |
|
10783 |
|
10784 |
|
10785 |
|
10786 |
|
10787 | var __proto = Component.prototype;
|
10788 |
|
10789 | __proto.trigger = function (eventName) {
|
10790 | var _this = this;
|
10791 |
|
10792 | var params = [];
|
10793 |
|
10794 | for (var _i = 1; _i < arguments.length; _i++) {
|
10795 | params[_i - 1] = arguments[_i];
|
10796 | }
|
10797 |
|
10798 | var handlerList = this._eventHandler[eventName] || [];
|
10799 | var hasHandlerList = handlerList.length > 0;
|
10800 |
|
10801 | if (!hasHandlerList) {
|
10802 | return true;
|
10803 | }
|
10804 |
|
10805 | var customEvent = params[0] || {};
|
10806 | var restParams = params.slice(1);
|
10807 |
|
10808 | handlerList = handlerList.concat();
|
10809 | var isCanceled = false;
|
10810 |
|
10811 | customEvent.eventType = eventName;
|
10812 |
|
10813 | customEvent.stop = function () {
|
10814 | isCanceled = true;
|
10815 | };
|
10816 |
|
10817 | customEvent.currentTarget = this;
|
10818 | var arg = [customEvent];
|
10819 |
|
10820 | if (restParams.length >= 1) {
|
10821 | arg = arg.concat(restParams);
|
10822 | }
|
10823 |
|
10824 | handlerList.forEach(function (handler) {
|
10825 | handler.apply(_this, arg);
|
10826 | });
|
10827 | return !isCanceled;
|
10828 | };
|
10829 | |
10830 |
|
10831 |
|
10832 |
|
10833 |
|
10834 |
|
10835 |
|
10836 |
|
10837 |
|
10838 |
|
10839 |
|
10840 |
|
10841 |
|
10842 |
|
10843 |
|
10844 |
|
10845 |
|
10846 |
|
10847 |
|
10848 |
|
10849 |
|
10850 |
|
10851 |
|
10852 |
|
10853 |
|
10854 |
|
10855 | __proto.once = function (eventName, handlerToAttach) {
|
10856 | var _this = this;
|
10857 |
|
10858 | if (typeof eventName === "object" && isUndefined(handlerToAttach)) {
|
10859 | var eventHash = eventName;
|
10860 |
|
10861 | for (var key in eventHash) {
|
10862 | this.once(key, eventHash[key]);
|
10863 | }
|
10864 |
|
10865 | return this;
|
10866 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
10867 | var listener_1 = function () {
|
10868 | var args = [];
|
10869 |
|
10870 | for (var _i = 0; _i < arguments.length; _i++) {
|
10871 | args[_i] = arguments[_i];
|
10872 | }
|
10873 |
|
10874 | handlerToAttach.apply(_this, args);
|
10875 |
|
10876 | _this.off(eventName, listener_1);
|
10877 | };
|
10878 |
|
10879 | this.on(eventName, listener_1);
|
10880 | }
|
10881 |
|
10882 | return this;
|
10883 | };
|
10884 | |
10885 |
|
10886 |
|
10887 |
|
10888 |
|
10889 |
|
10890 |
|
10891 |
|
10892 |
|
10893 |
|
10894 |
|
10895 |
|
10896 |
|
10897 |
|
10898 |
|
10899 |
|
10900 | __proto.hasOn = function (eventName) {
|
10901 | return !!this._eventHandler[eventName];
|
10902 | };
|
10903 | |
10904 |
|
10905 |
|
10906 |
|
10907 |
|
10908 |
|
10909 |
|
10910 |
|
10911 |
|
10912 |
|
10913 |
|
10914 |
|
10915 |
|
10916 |
|
10917 |
|
10918 |
|
10919 |
|
10920 |
|
10921 |
|
10922 |
|
10923 | __proto.on = function (eventName, handlerToAttach) {
|
10924 | if (typeof eventName === "object" && isUndefined(handlerToAttach)) {
|
10925 | var eventHash = eventName;
|
10926 |
|
10927 | for (var name in eventHash) {
|
10928 | this.on(name, eventHash[name]);
|
10929 | }
|
10930 |
|
10931 | return this;
|
10932 | } else if (typeof eventName === "string" && typeof handlerToAttach === "function") {
|
10933 | var handlerList = this._eventHandler[eventName];
|
10934 |
|
10935 | if (isUndefined(handlerList)) {
|
10936 | this._eventHandler[eventName] = [];
|
10937 | handlerList = this._eventHandler[eventName];
|
10938 | }
|
10939 |
|
10940 | handlerList.push(handlerToAttach);
|
10941 | }
|
10942 |
|
10943 | return this;
|
10944 | };
|
10945 | |
10946 |
|
10947 |
|
10948 |
|
10949 |
|
10950 |
|
10951 |
|
10952 |
|
10953 |
|
10954 |
|
10955 |
|
10956 |
|
10957 |
|
10958 |
|
10959 |
|
10960 |
|
10961 |
|
10962 |
|
10963 |
|
10964 |
|
10965 | __proto.off = function (eventName, handlerToDetach) {
|
10966 | var e_1, _a;
|
10967 |
|
10968 |
|
10969 | if (isUndefined(eventName)) {
|
10970 | this._eventHandler = {};
|
10971 | return this;
|
10972 | }
|
10973 |
|
10974 |
|
10975 | if (isUndefined(handlerToDetach)) {
|
10976 | if (typeof eventName === "string") {
|
10977 | delete this._eventHandler[eventName];
|
10978 | return this;
|
10979 | } else {
|
10980 | var eventHash = eventName;
|
10981 |
|
10982 | for (var name in eventHash) {
|
10983 | this.off(name, eventHash[name]);
|
10984 | }
|
10985 |
|
10986 | return this;
|
10987 | }
|
10988 | }
|
10989 |
|
10990 |
|
10991 | var handlerList = this._eventHandler[eventName];
|
10992 |
|
10993 | if (handlerList) {
|
10994 | var idx = 0;
|
10995 |
|
10996 | try {
|
10997 | for (var handlerList_1 = __values(handlerList), handlerList_1_1 = handlerList_1.next(); !handlerList_1_1.done; handlerList_1_1 = handlerList_1.next()) {
|
10998 | var handlerFunction = handlerList_1_1.value;
|
10999 |
|
11000 | if (handlerFunction === handlerToDetach) {
|
11001 | handlerList.splice(idx, 1);
|
11002 | break;
|
11003 | }
|
11004 |
|
11005 | idx++;
|
11006 | }
|
11007 | } catch (e_1_1) {
|
11008 | e_1 = {
|
11009 | error: e_1_1
|
11010 | };
|
11011 | } finally {
|
11012 | try {
|
11013 | if (handlerList_1_1 && !handlerList_1_1.done && (_a = handlerList_1.return)) _a.call(handlerList_1);
|
11014 | } finally {
|
11015 | if (e_1) throw e_1.error;
|
11016 | }
|
11017 | }
|
11018 | }
|
11019 |
|
11020 | return this;
|
11021 | };
|
11022 | |
11023 |
|
11024 |
|
11025 |
|
11026 |
|
11027 |
|
11028 |
|
11029 |
|
11030 |
|
11031 |
|
11032 |
|
11033 | Component.VERSION = "2.2.2";
|
11034 | return Component;
|
11035 | }();
|
11036 |
|
11037 | |
11038 |
|
11039 |
|
11040 |
|
11041 |
|
11042 |
|
11043 |
|
11044 |
|
11045 |
|
11046 | |
11047 |
|
11048 |
|
11049 |
|
11050 |
|
11051 |
|
11052 |
|
11053 |
|
11054 |
|
11055 |
|
11056 |
|
11057 |
|
11058 |
|
11059 |
|
11060 |
|
11061 |
|
11062 | var extendStatics = function (d, b) {
|
11063 | extendStatics = Object.setPrototypeOf || {
|
11064 | __proto__: []
|
11065 | } instanceof Array && function (d, b) {
|
11066 | d.__proto__ = b;
|
11067 | } || function (d, b) {
|
11068 | for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
11069 | };
|
11070 |
|
11071 | return extendStatics(d, b);
|
11072 | };
|
11073 |
|
11074 | function __extends(d, b) {
|
11075 | extendStatics(d, b);
|
11076 |
|
11077 | function __() {
|
11078 | this.constructor = d;
|
11079 | }
|
11080 |
|
11081 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
11082 | }
|
11083 | var __assign = function () {
|
11084 | __assign = Object.assign || function __assign(t) {
|
11085 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
11086 | s = arguments[i];
|
11087 |
|
11088 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
11089 | }
|
11090 |
|
11091 | return t;
|
11092 | };
|
11093 |
|
11094 | return __assign.apply(this, arguments);
|
11095 | };
|
11096 | function __spreadArrays() {
|
11097 | for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
11098 |
|
11099 | for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j];
|
11100 |
|
11101 | return r;
|
11102 | }
|
11103 |
|
11104 | |
11105 |
|
11106 |
|
11107 |
|
11108 |
|
11109 | var isWindow = typeof window !== "undefined";
|
11110 | var ua = isWindow ? window.navigator.userAgent : "";
|
11111 | var SUPPORT_COMPUTEDSTYLE = isWindow ? !!("getComputedStyle" in window) : false;
|
11112 | var IS_IE = /MSIE|Trident|Windows Phone|Edge/.test(ua);
|
11113 | var SUPPORT_ADDEVENTLISTENER = isWindow ? !!("addEventListener" in document) : false;
|
11114 | var WIDTH = "width";
|
11115 | var HEIGHT = "height";
|
11116 |
|
11117 | function getAttribute(el, name) {
|
11118 | return el.getAttribute(name) || "";
|
11119 | }
|
11120 | function toArray(arr) {
|
11121 | return [].slice.call(arr);
|
11122 | }
|
11123 | function hasSizeAttribute(target, prefix) {
|
11124 | if (prefix === void 0) {
|
11125 | prefix = "data-";
|
11126 | }
|
11127 |
|
11128 | return !!target.getAttribute(prefix + "width");
|
11129 | }
|
11130 | function hasLoadingAttribute(target) {
|
11131 | return "loading" in target && target.getAttribute("loading") === "lazy";
|
11132 | }
|
11133 | function hasSkipAttribute(target, prefix) {
|
11134 | if (prefix === void 0) {
|
11135 | prefix = "data-";
|
11136 | }
|
11137 |
|
11138 | return !!target.getAttribute(prefix + "skip");
|
11139 | }
|
11140 | function addEvent(element, type, handler) {
|
11141 | if (SUPPORT_ADDEVENTLISTENER) {
|
11142 | element.addEventListener(type, handler, false);
|
11143 | } else if (element.attachEvent) {
|
11144 | element.attachEvent("on" + type, handler);
|
11145 | } else {
|
11146 | element["on" + type] = handler;
|
11147 | }
|
11148 | }
|
11149 | function removeEvent(element, type, handler) {
|
11150 | if (element.removeEventListener) {
|
11151 | element.removeEventListener(type, handler, false);
|
11152 | } else if (element.detachEvent) {
|
11153 | element.detachEvent("on" + type, handler);
|
11154 | } else {
|
11155 | element["on" + type] = null;
|
11156 | }
|
11157 | }
|
11158 | function innerWidth(el) {
|
11159 | return getSize(el, "Width");
|
11160 | }
|
11161 | function innerHeight(el) {
|
11162 | return getSize(el, "Height");
|
11163 | }
|
11164 | function getStyles(el) {
|
11165 | return (SUPPORT_COMPUTEDSTYLE ? window.getComputedStyle(el) : el.currentStyle) || {};
|
11166 | }
|
11167 |
|
11168 | function getSize(el, name) {
|
11169 | var size = el["client" + name] || el["offset" + name];
|
11170 | return parseFloat(size || getStyles(el)[name.toLowerCase()]) || 0;
|
11171 | }
|
11172 |
|
11173 | function getContentElements(element, tags, prefix) {
|
11174 | var skipElements = toArray(element.querySelectorAll(__spreadArrays(["[" + prefix + "skip] [" + prefix + "width]"], tags.map(function (tag) {
|
11175 | return ["[" + prefix + "skip] " + tag, tag + "[" + prefix + "skip]", "[" + prefix + "width] " + tag].join(", ");
|
11176 | })).join(", ")));
|
11177 | return toArray(element.querySelectorAll("[" + prefix + "width], " + tags.join(", "))).filter(function (el) {
|
11178 | return skipElements.indexOf(el) === -1;
|
11179 | });
|
11180 | }
|
11181 |
|
11182 | |
11183 |
|
11184 |
|
11185 |
|
11186 |
|
11187 | var elements = [];
|
11188 | function addAutoSizer(element, prefix) {
|
11189 | !elements.length && addEvent(window, "resize", resizeAllAutoSizers);
|
11190 | element.__PREFIX__ = prefix;
|
11191 | elements.push(element);
|
11192 | resize(element);
|
11193 | }
|
11194 | function removeAutoSizer(element, prefix) {
|
11195 | var index = elements.indexOf(element);
|
11196 |
|
11197 | if (index < 0) {
|
11198 | return;
|
11199 | }
|
11200 |
|
11201 | var fixed = getAttribute(element, prefix + "fixed");
|
11202 | delete element.__PREFIX__;
|
11203 | element.style[fixed === HEIGHT ? WIDTH : HEIGHT] = "";
|
11204 | elements.splice(index, 1);
|
11205 | !elements.length && removeEvent(window, "resize", resizeAllAutoSizers);
|
11206 | }
|
11207 |
|
11208 | function resize(element, prefix) {
|
11209 | if (prefix === void 0) {
|
11210 | prefix = "data-";
|
11211 | }
|
11212 |
|
11213 | var elementPrefix = element.__PREFIX__ || prefix;
|
11214 | var dataWidth = parseInt(getAttribute(element, "" + elementPrefix + WIDTH), 10) || 0;
|
11215 | var dataHeight = parseInt(getAttribute(element, "" + elementPrefix + HEIGHT), 10) || 0;
|
11216 | var fixed = getAttribute(element, elementPrefix + "fixed");
|
11217 |
|
11218 | if (fixed === HEIGHT) {
|
11219 | var size = innerHeight(element) || dataHeight;
|
11220 | element.style[WIDTH] = dataWidth / dataHeight * size + "px";
|
11221 | } else {
|
11222 | var size = innerWidth(element) || dataWidth;
|
11223 | element.style[HEIGHT] = dataHeight / dataWidth * size + "px";
|
11224 | }
|
11225 | }
|
11226 |
|
11227 | function resizeAllAutoSizers() {
|
11228 | elements.forEach(function (element) {
|
11229 | resize(element);
|
11230 | });
|
11231 | }
|
11232 |
|
11233 | var Loader =
|
11234 |
|
11235 | function (_super) {
|
11236 | __extends(Loader, _super);
|
11237 |
|
11238 | function Loader(element, options) {
|
11239 | if (options === void 0) {
|
11240 | options = {};
|
11241 | }
|
11242 |
|
11243 | var _this = _super.call(this) || this;
|
11244 |
|
11245 | _this.isReady = false;
|
11246 | _this.isPreReady = false;
|
11247 | _this.hasDataSize = false;
|
11248 | _this.hasLoading = false;
|
11249 | _this.isSkip = false;
|
11250 |
|
11251 | _this.onCheck = function (e) {
|
11252 | _this.clear();
|
11253 |
|
11254 | if (e && e.type === "error") {
|
11255 | _this.onError(_this.element);
|
11256 | }
|
11257 |
|
11258 |
|
11259 | var withPreReady = !_this.hasDataSize && !_this.hasLoading;
|
11260 |
|
11261 | _this.onReady(withPreReady);
|
11262 | };
|
11263 |
|
11264 | _this.options = __assign({
|
11265 | prefix: "data-"
|
11266 | }, options);
|
11267 | _this.element = element;
|
11268 | _this.hasDataSize = hasSizeAttribute(element, _this.options.prefix);
|
11269 | _this.hasLoading = hasLoadingAttribute(element);
|
11270 | _this.isSkip = hasSkipAttribute(_this.element);
|
11271 | return _this;
|
11272 | }
|
11273 |
|
11274 | var __proto = Loader.prototype;
|
11275 |
|
11276 | __proto.check = function () {
|
11277 | if (this.isSkip || !this.checkElement()) {
|
11278 |
|
11279 | this.onAlreadyReady(true);
|
11280 | return false;
|
11281 | }
|
11282 |
|
11283 | if (this.hasDataSize) {
|
11284 | addAutoSizer(this.element, this.options.prefix);
|
11285 | }
|
11286 |
|
11287 | if (this.hasDataSize || this.hasLoading) {
|
11288 |
|
11289 | this.onAlreadyPreReady();
|
11290 | }
|
11291 |
|
11292 |
|
11293 | return true;
|
11294 | };
|
11295 |
|
11296 | __proto.addEvents = function () {
|
11297 | var _this = this;
|
11298 |
|
11299 | var element = this.element;
|
11300 | this.constructor.EVENTS.forEach(function (name) {
|
11301 | addEvent(element, name, _this.onCheck);
|
11302 | });
|
11303 | };
|
11304 |
|
11305 | __proto.clear = function () {
|
11306 | var _this = this;
|
11307 |
|
11308 | var element = this.element;
|
11309 | this.constructor.EVENTS.forEach(function (name) {
|
11310 | removeEvent(element, name, _this.onCheck);
|
11311 | });
|
11312 | this.removeAutoSizer();
|
11313 | };
|
11314 |
|
11315 | __proto.destroy = function () {
|
11316 | this.clear();
|
11317 | this.off();
|
11318 | };
|
11319 |
|
11320 | __proto.removeAutoSizer = function () {
|
11321 | if (this.hasDataSize) {
|
11322 |
|
11323 | var prefix = this.options.prefix;
|
11324 | removeAutoSizer(this.element, prefix);
|
11325 | }
|
11326 | };
|
11327 |
|
11328 | __proto.onError = function (target) {
|
11329 | this.trigger("error", {
|
11330 | element: this.element,
|
11331 | target: target
|
11332 | });
|
11333 | };
|
11334 |
|
11335 | __proto.onPreReady = function () {
|
11336 | if (this.isPreReady) {
|
11337 | return;
|
11338 | }
|
11339 |
|
11340 | this.isPreReady = true;
|
11341 | this.trigger("preReady", {
|
11342 | element: this.element,
|
11343 | hasLoading: this.hasLoading,
|
11344 | isSkip: this.isSkip
|
11345 | });
|
11346 | };
|
11347 |
|
11348 | __proto.onReady = function (withPreReady) {
|
11349 | if (this.isReady) {
|
11350 | return;
|
11351 | }
|
11352 |
|
11353 | withPreReady = !this.isPreReady && withPreReady;
|
11354 |
|
11355 | if (withPreReady) {
|
11356 | this.isPreReady = true;
|
11357 | }
|
11358 |
|
11359 | this.removeAutoSizer();
|
11360 | this.isReady = true;
|
11361 | this.trigger("ready", {
|
11362 | element: this.element,
|
11363 | withPreReady: withPreReady,
|
11364 | hasLoading: this.hasLoading,
|
11365 | isSkip: this.isSkip
|
11366 | });
|
11367 | };
|
11368 |
|
11369 | __proto.onAlreadyError = function (target) {
|
11370 | var _this = this;
|
11371 |
|
11372 | setTimeout(function () {
|
11373 | _this.onError(target);
|
11374 | });
|
11375 | };
|
11376 |
|
11377 | __proto.onAlreadyPreReady = function () {
|
11378 | var _this = this;
|
11379 |
|
11380 | setTimeout(function () {
|
11381 | _this.onPreReady();
|
11382 | });
|
11383 | };
|
11384 |
|
11385 | __proto.onAlreadyReady = function (withPreReady) {
|
11386 | var _this = this;
|
11387 |
|
11388 | setTimeout(function () {
|
11389 | _this.onReady(withPreReady);
|
11390 | });
|
11391 | };
|
11392 |
|
11393 | Loader.EVENTS = [];
|
11394 | return Loader;
|
11395 | }(Component);
|
11396 |
|
11397 | var ElementLoader =
|
11398 |
|
11399 | function (_super) {
|
11400 | __extends(ElementLoader, _super);
|
11401 |
|
11402 | function ElementLoader() {
|
11403 | return _super !== null && _super.apply(this, arguments) || this;
|
11404 | }
|
11405 |
|
11406 | var __proto = ElementLoader.prototype;
|
11407 |
|
11408 | __proto.setHasLoading = function (hasLoading) {
|
11409 | this.hasLoading = hasLoading;
|
11410 | };
|
11411 |
|
11412 | __proto.check = function () {
|
11413 | if (this.isSkip) {
|
11414 |
|
11415 | this.onAlreadyReady(true);
|
11416 | return false;
|
11417 | }
|
11418 |
|
11419 | if (this.hasDataSize) {
|
11420 | addAutoSizer(this.element, this.options.prefix);
|
11421 | this.onAlreadyPreReady();
|
11422 | } else {
|
11423 |
|
11424 | this.trigger("requestChildren");
|
11425 | }
|
11426 |
|
11427 | return true;
|
11428 | };
|
11429 |
|
11430 | __proto.checkElement = function () {
|
11431 | return true;
|
11432 | };
|
11433 |
|
11434 | __proto.destroy = function () {
|
11435 | this.clear();
|
11436 | this.trigger("requestDestroy");
|
11437 | this.off();
|
11438 | };
|
11439 |
|
11440 | __proto.onAlreadyPreReady = function () {
|
11441 |
|
11442 | _super.prototype.onAlreadyPreReady.call(this);
|
11443 |
|
11444 | this.trigger("reqeustReadyChildren");
|
11445 | };
|
11446 |
|
11447 | ElementLoader.EVENTS = [];
|
11448 | return ElementLoader;
|
11449 | }(Loader);
|
11450 |
|
11451 | |
11452 |
|
11453 |
|
11454 |
|
11455 |
|
11456 | var ImReadyManager =
|
11457 |
|
11458 | function (_super) {
|
11459 | __extends(ImReadyManager, _super);
|
11460 | |
11461 |
|
11462 |
|
11463 |
|
11464 |
|
11465 | function ImReadyManager(options) {
|
11466 | if (options === void 0) {
|
11467 | options = {};
|
11468 | }
|
11469 |
|
11470 | var _this = _super.call(this) || this;
|
11471 |
|
11472 | _this.readyCount = 0;
|
11473 | _this.preReadyCount = 0;
|
11474 | _this.totalCount = 0;
|
11475 | _this.totalErrorCount = 0;
|
11476 | _this.isPreReadyOver = true;
|
11477 | _this.elementInfos = [];
|
11478 | _this.options = __assign({
|
11479 | loaders: {},
|
11480 | prefix: "data-"
|
11481 | }, options);
|
11482 | return _this;
|
11483 | }
|
11484 | |
11485 |
|
11486 |
|
11487 |
|
11488 |
|
11489 |
|
11490 |
|
11491 |
|
11492 |
|
11493 |
|
11494 |
|
11495 |
|
11496 |
|
11497 |
|
11498 |
|
11499 |
|
11500 |
|
11501 |
|
11502 |
|
11503 |
|
11504 |
|
11505 |
|
11506 |
|
11507 |
|
11508 |
|
11509 |
|
11510 |
|
11511 |
|
11512 |
|
11513 | var __proto = ImReadyManager.prototype;
|
11514 |
|
11515 | __proto.check = function (elements) {
|
11516 | var _this = this;
|
11517 |
|
11518 | var prefix = this.options.prefix;
|
11519 | this.clear();
|
11520 | this.elementInfos = toArray(elements).map(function (element, index) {
|
11521 | var loader = _this.getLoader(element, {
|
11522 | prefix: prefix
|
11523 | });
|
11524 |
|
11525 | loader.check();
|
11526 | loader.on("error", function (e) {
|
11527 | _this.onError(index, e.target);
|
11528 | }).on("preReady", function (e) {
|
11529 | var info = _this.elementInfos[index];
|
11530 | info.hasLoading = e.hasLoading;
|
11531 | info.isSkip = e.isSkip;
|
11532 |
|
11533 | var isPreReady = _this.checkPreReady(index);
|
11534 |
|
11535 | _this.onPreReadyElement(index);
|
11536 |
|
11537 | isPreReady && _this.onPreReady();
|
11538 | }).on("ready", function (_a) {
|
11539 | var withPreReady = _a.withPreReady,
|
11540 | hasLoading = _a.hasLoading,
|
11541 | isSkip = _a.isSkip;
|
11542 | var info = _this.elementInfos[index];
|
11543 | info.hasLoading = hasLoading;
|
11544 | info.isSkip = isSkip;
|
11545 |
|
11546 | var isPreReady = withPreReady && _this.checkPreReady(index);
|
11547 |
|
11548 | var isReady = _this.checkReady(index);
|
11549 |
|
11550 |
|
11551 | withPreReady && _this.onPreReadyElement(index);
|
11552 |
|
11553 | _this.onReadyElement(index);
|
11554 |
|
11555 | isPreReady && _this.onPreReady();
|
11556 | isReady && _this.onReady();
|
11557 | });
|
11558 | return {
|
11559 | loader: loader,
|
11560 | element: element,
|
11561 | hasLoading: false,
|
11562 | hasError: false,
|
11563 | isPreReady: false,
|
11564 | isReady: false,
|
11565 | isSkip: false
|
11566 | };
|
11567 | });
|
11568 | var length = this.elementInfos.length;
|
11569 | this.totalCount = length;
|
11570 |
|
11571 | if (!length) {
|
11572 | setTimeout(function () {
|
11573 | _this.onPreReady();
|
11574 |
|
11575 | _this.onReady();
|
11576 | });
|
11577 | }
|
11578 |
|
11579 | return this;
|
11580 | };
|
11581 | |
11582 |
|
11583 |
|
11584 |
|
11585 |
|
11586 |
|
11587 | __proto.getTotalCount = function () {
|
11588 | return this.totalCount;
|
11589 | };
|
11590 | |
11591 |
|
11592 |
|
11593 |
|
11594 |
|
11595 |
|
11596 | __proto.isPreReady = function () {
|
11597 | return this.elementInfos.every(function (info) {
|
11598 | return info.isPreReady;
|
11599 | });
|
11600 | };
|
11601 | |
11602 |
|
11603 |
|
11604 |
|
11605 |
|
11606 |
|
11607 | __proto.isReady = function () {
|
11608 | return this.elementInfos.every(function (info) {
|
11609 | return info.isReady;
|
11610 | });
|
11611 | };
|
11612 | |
11613 |
|
11614 |
|
11615 |
|
11616 |
|
11617 |
|
11618 | __proto.hasError = function () {
|
11619 | return this.totalErrorCount > 0;
|
11620 | };
|
11621 | |
11622 |
|
11623 |
|
11624 |
|
11625 |
|
11626 |
|
11627 | __proto.clear = function () {
|
11628 | this.isPreReadyOver = false;
|
11629 | this.totalCount = 0;
|
11630 | this.preReadyCount = 0;
|
11631 | this.readyCount = 0;
|
11632 | this.totalErrorCount = 0;
|
11633 | this.elementInfos.forEach(function (info) {
|
11634 | if (!info.isReady && info.loader) {
|
11635 | info.loader.destroy();
|
11636 | }
|
11637 | });
|
11638 | this.elementInfos = [];
|
11639 | };
|
11640 | |
11641 |
|
11642 |
|
11643 |
|
11644 |
|
11645 |
|
11646 | __proto.destroy = function () {
|
11647 | this.clear();
|
11648 | this.off();
|
11649 | };
|
11650 |
|
11651 | __proto.getLoader = function (element, options) {
|
11652 | var _this = this;
|
11653 |
|
11654 | var tagName = element.tagName.toLowerCase();
|
11655 | var loaders = this.options.loaders;
|
11656 | var tags = Object.keys(loaders);
|
11657 |
|
11658 | if (loaders[tagName]) {
|
11659 | return new loaders[tagName](element, options);
|
11660 | }
|
11661 |
|
11662 | var loader = new ElementLoader(element, options);
|
11663 | var children = toArray(element.querySelectorAll(tags.join(", ")));
|
11664 | loader.setHasLoading(children.some(function (el) {
|
11665 | return hasLoadingAttribute(el);
|
11666 | }));
|
11667 | var withPreReady = false;
|
11668 | var childrenImReady = this.clone().on("error", function (e) {
|
11669 | loader.onError(e.target);
|
11670 | }).on("ready", function () {
|
11671 | loader.onReady(withPreReady);
|
11672 | });
|
11673 | loader.on("requestChildren", function () {
|
11674 |
|
11675 | var contentElements = getContentElements(element, tags, _this.options.prefix);
|
11676 | childrenImReady.check(contentElements).on("preReady", function (e) {
|
11677 | withPreReady = e.isReady;
|
11678 |
|
11679 | if (!withPreReady) {
|
11680 | loader.onPreReady();
|
11681 | }
|
11682 | });
|
11683 | }).on("reqeustReadyChildren", function () {
|
11684 |
|
11685 |
|
11686 |
|
11687 | childrenImReady.check(children);
|
11688 | }).on("requestDestroy", function () {
|
11689 | childrenImReady.destroy();
|
11690 | });
|
11691 | return loader;
|
11692 | };
|
11693 |
|
11694 | __proto.clone = function () {
|
11695 | return new ImReadyManager(__assign({}, this.options));
|
11696 | };
|
11697 |
|
11698 | __proto.checkPreReady = function (index) {
|
11699 | this.elementInfos[index].isPreReady = true;
|
11700 | ++this.preReadyCount;
|
11701 |
|
11702 | if (this.preReadyCount < this.totalCount) {
|
11703 | return false;
|
11704 | }
|
11705 |
|
11706 | return true;
|
11707 | };
|
11708 |
|
11709 | __proto.checkReady = function (index) {
|
11710 | this.elementInfos[index].isReady = true;
|
11711 | ++this.readyCount;
|
11712 |
|
11713 | if (this.readyCount < this.totalCount) {
|
11714 | return false;
|
11715 | }
|
11716 |
|
11717 | return true;
|
11718 | };
|
11719 |
|
11720 | __proto.onError = function (index, target) {
|
11721 | var info = this.elementInfos[index];
|
11722 | info.hasError = true;
|
11723 | |
11724 |
|
11725 |
|
11726 |
|
11727 |
|
11728 |
|
11729 |
|
11730 |
|
11731 |
|
11732 |
|
11733 |
|
11734 |
|
11735 |
|
11736 |
|
11737 |
|
11738 |
|
11739 |
|
11740 |
|
11741 |
|
11742 |
|
11743 |
|
11744 |
|
11745 |
|
11746 |
|
11747 |
|
11748 |
|
11749 |
|
11750 |
|
11751 |
|
11752 |
|
11753 |
|
11754 |
|
11755 | this.trigger("error", {
|
11756 | element: info.element,
|
11757 | index: index,
|
11758 | target: target,
|
11759 | errorCount: this.getErrorCount(),
|
11760 | totalErrorCount: ++this.totalErrorCount
|
11761 | });
|
11762 | };
|
11763 |
|
11764 | __proto.onPreReadyElement = function (index) {
|
11765 | var info = this.elementInfos[index];
|
11766 | |
11767 |
|
11768 |
|
11769 |
|
11770 |
|
11771 |
|
11772 |
|
11773 |
|
11774 |
|
11775 |
|
11776 |
|
11777 |
|
11778 |
|
11779 |
|
11780 |
|
11781 |
|
11782 |
|
11783 |
|
11784 |
|
11785 |
|
11786 |
|
11787 |
|
11788 |
|
11789 |
|
11790 |
|
11791 |
|
11792 |
|
11793 |
|
11794 |
|
11795 |
|
11796 |
|
11797 |
|
11798 |
|
11799 |
|
11800 |
|
11801 |
|
11802 |
|
11803 |
|
11804 | this.trigger("preReadyElement", {
|
11805 | element: info.element,
|
11806 | index: index,
|
11807 | preReadyCount: this.preReadyCount,
|
11808 | readyCount: this.readyCount,
|
11809 | totalCount: this.totalCount,
|
11810 | isPreReady: this.isPreReady(),
|
11811 | isReady: this.isReady(),
|
11812 | hasLoading: info.hasLoading,
|
11813 | isSkip: info.isSkip
|
11814 | });
|
11815 | };
|
11816 |
|
11817 | __proto.onPreReady = function () {
|
11818 | this.isPreReadyOver = true;
|
11819 | |
11820 |
|
11821 |
|
11822 |
|
11823 |
|
11824 |
|
11825 |
|
11826 |
|
11827 |
|
11828 |
|
11829 |
|
11830 |
|
11831 |
|
11832 |
|
11833 |
|
11834 |
|
11835 |
|
11836 |
|
11837 |
|
11838 |
|
11839 |
|
11840 |
|
11841 |
|
11842 |
|
11843 |
|
11844 |
|
11845 |
|
11846 |
|
11847 |
|
11848 |
|
11849 |
|
11850 | this.trigger("preReady", {
|
11851 | readyCount: this.readyCount,
|
11852 | totalCount: this.totalCount,
|
11853 | isReady: this.isReady(),
|
11854 | hasLoading: this.hasLoading()
|
11855 | });
|
11856 | };
|
11857 |
|
11858 | __proto.onReadyElement = function (index) {
|
11859 | var info = this.elementInfos[index];
|
11860 | |
11861 |
|
11862 |
|
11863 |
|
11864 |
|
11865 |
|
11866 |
|
11867 |
|
11868 |
|
11869 |
|
11870 |
|
11871 |
|
11872 |
|
11873 |
|
11874 |
|
11875 |
|
11876 |
|
11877 |
|
11878 |
|
11879 |
|
11880 |
|
11881 |
|
11882 |
|
11883 |
|
11884 |
|
11885 |
|
11886 |
|
11887 |
|
11888 |
|
11889 |
|
11890 |
|
11891 |
|
11892 |
|
11893 |
|
11894 |
|
11895 |
|
11896 |
|
11897 |
|
11898 |
|
11899 |
|
11900 |
|
11901 |
|
11902 | this.trigger("readyElement", {
|
11903 | index: index,
|
11904 | element: info.element,
|
11905 | hasError: info.hasError,
|
11906 | errorCount: this.getErrorCount(),
|
11907 | totalErrorCount: this.totalErrorCount,
|
11908 | preReadyCount: this.preReadyCount,
|
11909 | readyCount: this.readyCount,
|
11910 | totalCount: this.totalCount,
|
11911 | isPreReady: this.isPreReady(),
|
11912 | isReady: this.isReady(),
|
11913 | hasLoading: info.hasLoading,
|
11914 | isPreReadyOver: this.isPreReadyOver,
|
11915 | isSkip: info.isSkip
|
11916 | });
|
11917 | };
|
11918 |
|
11919 | __proto.onReady = function () {
|
11920 | |
11921 |
|
11922 |
|
11923 |
|
11924 |
|
11925 |
|
11926 |
|
11927 |
|
11928 |
|
11929 |
|
11930 |
|
11931 |
|
11932 |
|
11933 |
|
11934 |
|
11935 |
|
11936 |
|
11937 |
|
11938 |
|
11939 |
|
11940 |
|
11941 |
|
11942 |
|
11943 |
|
11944 |
|
11945 |
|
11946 |
|
11947 |
|
11948 |
|
11949 |
|
11950 |
|
11951 |
|
11952 |
|
11953 | this.trigger("ready", {
|
11954 | errorCount: this.getErrorCount(),
|
11955 | totalErrorCount: this.totalErrorCount,
|
11956 | totalCount: this.totalCount
|
11957 | });
|
11958 | };
|
11959 |
|
11960 | __proto.getErrorCount = function () {
|
11961 | return this.elementInfos.filter(function (info) {
|
11962 | return info.hasError;
|
11963 | }).length;
|
11964 | };
|
11965 |
|
11966 | __proto.hasLoading = function () {
|
11967 | return this.elementInfos.some(function (info) {
|
11968 | return info.hasLoading;
|
11969 | });
|
11970 | };
|
11971 |
|
11972 | return ImReadyManager;
|
11973 | }(Component);
|
11974 |
|
11975 | var ImageLoader =
|
11976 |
|
11977 | function (_super) {
|
11978 | __extends(ImageLoader, _super);
|
11979 |
|
11980 | function ImageLoader() {
|
11981 | return _super !== null && _super.apply(this, arguments) || this;
|
11982 | }
|
11983 |
|
11984 | var __proto = ImageLoader.prototype;
|
11985 |
|
11986 | __proto.checkElement = function () {
|
11987 | var element = this.element;
|
11988 | var src = element.getAttribute("src");
|
11989 |
|
11990 | if (element.complete) {
|
11991 | if (src) {
|
11992 |
|
11993 | if (!element.naturalWidth) {
|
11994 | this.onAlreadyError(element);
|
11995 | }
|
11996 |
|
11997 | return false;
|
11998 | } else {
|
11999 |
|
12000 | this.onAlreadyPreReady();
|
12001 | }
|
12002 | }
|
12003 |
|
12004 | this.addEvents();
|
12005 | IS_IE && element.setAttribute("src", src);
|
12006 | return true;
|
12007 | };
|
12008 |
|
12009 | ImageLoader.EVENTS = ["load", "error"];
|
12010 | return ImageLoader;
|
12011 | }(Loader);
|
12012 |
|
12013 | var VideoLoader =
|
12014 |
|
12015 | function (_super) {
|
12016 | __extends(VideoLoader, _super);
|
12017 |
|
12018 | function VideoLoader() {
|
12019 | return _super !== null && _super.apply(this, arguments) || this;
|
12020 | }
|
12021 |
|
12022 | var __proto = VideoLoader.prototype;
|
12023 |
|
12024 | __proto.checkElement = function () {
|
12025 | var element = this.element;
|
12026 |
|
12027 |
|
12028 |
|
12029 |
|
12030 |
|
12031 | if (element.readyState >= 1) {
|
12032 | return false;
|
12033 | }
|
12034 |
|
12035 | if (element.error) {
|
12036 | this.onAlreadyError(element);
|
12037 | return false;
|
12038 | }
|
12039 |
|
12040 | this.addEvents();
|
12041 | return true;
|
12042 | };
|
12043 |
|
12044 | VideoLoader.EVENTS = ["loadedmetadata", "error"];
|
12045 | return VideoLoader;
|
12046 | }(Loader);
|
12047 |
|
12048 | var ImReady =
|
12049 |
|
12050 | function (_super) {
|
12051 | __extends(ImReady, _super);
|
12052 |
|
12053 | function ImReady(options) {
|
12054 | if (options === void 0) {
|
12055 | options = {};
|
12056 | }
|
12057 |
|
12058 | return _super.call(this, __assign({
|
12059 | loaders: {
|
12060 | img: ImageLoader,
|
12061 | video: VideoLoader
|
12062 | }
|
12063 | }, options)) || this;
|
12064 | }
|
12065 |
|
12066 | return ImReady;
|
12067 | }(ImReadyManager);
|
12068 |
|
12069 | |
12070 |
|
12071 |
|
12072 |
|
12073 |
|
12074 |
|
12075 | var ImReady$1 = ImReady;
|
12076 |
|
12077 | |
12078 |
|
12079 |
|
12080 |
|
12081 |
|
12082 | var Renderer$1 = function () {
|
12083 | |
12084 |
|
12085 |
|
12086 |
|
12087 | function Renderer(_a) {
|
12088 | var _b = _a === void 0 ? {} : _a,
|
12089 | _c = _b.align,
|
12090 | align = _c === void 0 ? ALIGN.CENTER : _c;
|
12091 |
|
12092 | this._flicking = null;
|
12093 | this._panels = [];
|
12094 |
|
12095 | this._align = align;
|
12096 | }
|
12097 |
|
12098 | var __proto = Renderer.prototype;
|
12099 | Object.defineProperty(__proto, "panels", {
|
12100 |
|
12101 |
|
12102 | |
12103 |
|
12104 |
|
12105 |
|
12106 |
|
12107 |
|
12108 |
|
12109 | get: function () {
|
12110 | return this._panels;
|
12111 | },
|
12112 | enumerable: false,
|
12113 | configurable: true
|
12114 | });
|
12115 | Object.defineProperty(__proto, "panelCount", {
|
12116 | |
12117 |
|
12118 |
|
12119 |
|
12120 |
|
12121 |
|
12122 | get: function () {
|
12123 | return this._panels.length;
|
12124 | },
|
12125 | enumerable: false,
|
12126 | configurable: true
|
12127 | });
|
12128 | Object.defineProperty(__proto, "align", {
|
12129 |
|
12130 |
|
12131 | |
12132 |
|
12133 |
|
12134 |
|
12135 |
|
12136 | get: function () {
|
12137 | return this._align;
|
12138 | },
|
12139 |
|
12140 | set: function (val) {
|
12141 | this._align = val;
|
12142 |
|
12143 | var panelAlign = this._getPanelAlign();
|
12144 |
|
12145 | this._panels.forEach(function (panel) {
|
12146 | panel.align = panelAlign;
|
12147 | });
|
12148 | },
|
12149 | enumerable: false,
|
12150 | configurable: true
|
12151 | });
|
12152 | |
12153 |
|
12154 |
|
12155 |
|
12156 |
|
12157 |
|
12158 |
|
12159 |
|
12160 | __proto.init = function (flicking) {
|
12161 | this._flicking = flicking;
|
12162 |
|
12163 | this._collectPanels();
|
12164 |
|
12165 | return this;
|
12166 | };
|
12167 | |
12168 |
|
12169 |
|
12170 |
|
12171 |
|
12172 |
|
12173 |
|
12174 | __proto.destroy = function () {
|
12175 | this._flicking = null;
|
12176 | this._panels = [];
|
12177 | };
|
12178 | |
12179 |
|
12180 |
|
12181 |
|
12182 |
|
12183 |
|
12184 |
|
12185 |
|
12186 | __proto.getPanel = function (index) {
|
12187 | return this._panels[index] || null;
|
12188 | };
|
12189 | |
12190 |
|
12191 |
|
12192 |
|
12193 |
|
12194 |
|
12195 |
|
12196 |
|
12197 | __proto.updatePanelSize = function () {
|
12198 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
12199 |
|
12200 | if (flicking.panelsPerView > 0) {
|
12201 | this._updatePanelSizeByGrid(flicking);
|
12202 | } else {
|
12203 | flicking.panels.forEach(function (panel) {
|
12204 | return panel.resize();
|
12205 | });
|
12206 | }
|
12207 |
|
12208 | return this;
|
12209 | };
|
12210 | |
12211 |
|
12212 |
|
12213 |
|
12214 |
|
12215 |
|
12216 |
|
12217 |
|
12218 |
|
12219 |
|
12220 |
|
12221 | __proto.batchInsert = function () {
|
12222 | var _this = this;
|
12223 |
|
12224 | var items = [];
|
12225 |
|
12226 | for (var _i = 0; _i < arguments.length; _i++) {
|
12227 | items[_i] = arguments[_i];
|
12228 | }
|
12229 |
|
12230 | var panels = this._panels;
|
12231 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
12232 | var control = flicking.control;
|
12233 |
|
12234 | var align = this._getPanelAlign();
|
12235 |
|
12236 | var allPanelsInserted = items.reduce(function (addedPanels, item) {
|
12237 | var _a;
|
12238 |
|
12239 | var insertingIdx = getMinusCompensatedIndex(item.index, panels.length);
|
12240 | var panelsPushed = panels.slice(insertingIdx);
|
12241 | var panelsInserted = item.elements.map(function (el, idx) {
|
12242 | return _this._createPanel(el, {
|
12243 | index: insertingIdx + idx,
|
12244 | align: align,
|
12245 | flicking: flicking
|
12246 | });
|
12247 | });
|
12248 | panels.splice.apply(panels, __spreadArray([insertingIdx, 0], __read$1(panelsInserted)));
|
12249 |
|
12250 | _this._insertPanelElements(panelsInserted, (_a = panelsPushed[0]) !== null && _a !== void 0 ? _a : null);
|
12251 |
|
12252 |
|
12253 | panelsInserted.forEach(function (panel) {
|
12254 | return panel.resize();
|
12255 | });
|
12256 |
|
12257 | panelsPushed.forEach(function (panel) {
|
12258 | panel.increaseIndex(panelsInserted.length);
|
12259 | panel.updatePosition();
|
12260 | });
|
12261 | return __spreadArray(__spreadArray([], __read$1(addedPanels)), __read$1(panelsInserted));
|
12262 | }, []);
|
12263 | if (allPanelsInserted.length <= 0) return [];
|
12264 |
|
12265 | this._updateCameraAndControl();
|
12266 |
|
12267 | void this.render();
|
12268 |
|
12269 |
|
12270 | if (allPanelsInserted.length > 0 && !control.animating) {
|
12271 | void control.moveToPanel(control.activePanel || allPanelsInserted[0], {
|
12272 | duration: 0
|
12273 | }).catch(function () {
|
12274 | return void 0;
|
12275 | });
|
12276 | }
|
12277 |
|
12278 | flicking.camera.updateOffset();
|
12279 | flicking.trigger(new ComponentEvent$1(EVENTS.PANEL_CHANGE, {
|
12280 | added: allPanelsInserted,
|
12281 | removed: []
|
12282 | }));
|
12283 | this.checkPanelContentsReady(allPanelsInserted);
|
12284 | return allPanelsInserted;
|
12285 | };
|
12286 | |
12287 |
|
12288 |
|
12289 |
|
12290 |
|
12291 |
|
12292 |
|
12293 |
|
12294 |
|
12295 |
|
12296 |
|
12297 | __proto.batchRemove = function () {
|
12298 | var _this = this;
|
12299 |
|
12300 | var items = [];
|
12301 |
|
12302 | for (var _i = 0; _i < arguments.length; _i++) {
|
12303 | items[_i] = arguments[_i];
|
12304 | }
|
12305 |
|
12306 | var panels = this._panels;
|
12307 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
12308 | var camera = flicking.camera,
|
12309 | control = flicking.control;
|
12310 | var activePanel = control.activePanel;
|
12311 | var activeIndex = control.activeIndex;
|
12312 | var allPanelsRemoved = items.reduce(function (removed, item) {
|
12313 | var index = item.index,
|
12314 | deleteCount = item.deleteCount;
|
12315 | var removingIdx = getMinusCompensatedIndex(index, panels.length);
|
12316 | var panelsPulled = panels.slice(removingIdx + deleteCount);
|
12317 | var panelsRemoved = panels.splice(removingIdx, deleteCount);
|
12318 | if (panelsRemoved.length <= 0) return [];
|
12319 |
|
12320 | panelsPulled.forEach(function (panel) {
|
12321 | panel.decreaseIndex(panelsRemoved.length);
|
12322 | panel.updatePosition();
|
12323 | });
|
12324 |
|
12325 | _this._removePanelElements(panelsRemoved);
|
12326 |
|
12327 |
|
12328 | panelsRemoved.forEach(function (panel) {
|
12329 | return panel.destroy();
|
12330 | });
|
12331 |
|
12332 | _this._updateCameraAndControl();
|
12333 |
|
12334 | if (includes(panelsRemoved, activePanel)) {
|
12335 | control.resetActive();
|
12336 | }
|
12337 |
|
12338 | return __spreadArray(__spreadArray([], __read$1(removed)), __read$1(panelsRemoved));
|
12339 | }, []);
|
12340 | void this.render();
|
12341 |
|
12342 | if (allPanelsRemoved.length > 0 && !control.animating) {
|
12343 | var targetPanel = includes(allPanelsRemoved, activePanel) ? panels[activeIndex] || panels[panels.length - 1] : activePanel;
|
12344 |
|
12345 | if (targetPanel) {
|
12346 | void control.moveToPanel(targetPanel, {
|
12347 | duration: 0
|
12348 | }).catch(function () {
|
12349 | return void 0;
|
12350 | });
|
12351 | } else {
|
12352 |
|
12353 | camera.lookAt(0);
|
12354 | }
|
12355 | }
|
12356 |
|
12357 | flicking.camera.updateOffset();
|
12358 | flicking.trigger(new ComponentEvent$1(EVENTS.PANEL_CHANGE, {
|
12359 | added: [],
|
12360 | removed: allPanelsRemoved
|
12361 | }));
|
12362 | return allPanelsRemoved;
|
12363 | };
|
12364 | |
12365 |
|
12366 |
|
12367 |
|
12368 |
|
12369 | __proto.checkPanelContentsReady = function (checkingPanels) {
|
12370 | var _this = this;
|
12371 |
|
12372 | var resizeOnContentsReady = getFlickingAttached(this._flicking, "Renderer").resizeOnContentsReady;
|
12373 | var panels = this._panels;
|
12374 | if (!resizeOnContentsReady) return;
|
12375 |
|
12376 | var hasContents = function (panel) {
|
12377 | return !!panel.element.querySelector("img, video");
|
12378 | };
|
12379 |
|
12380 | checkingPanels = checkingPanels.filter(function (panel) {
|
12381 | return hasContents(panel);
|
12382 | });
|
12383 | if (checkingPanels.length <= 0) return;
|
12384 | var contentsReadyChecker = new ImReady$1();
|
12385 | checkingPanels.forEach(function (panel) {
|
12386 | panel.loading = true;
|
12387 | });
|
12388 | contentsReadyChecker.on("readyElement", function (e) {
|
12389 | var flicking = _this._flicking;
|
12390 |
|
12391 | if (!flicking) {
|
12392 |
|
12393 | contentsReadyChecker.destroy();
|
12394 | return;
|
12395 | }
|
12396 |
|
12397 | var panel = checkingPanels[e.index];
|
12398 | var camera = flicking.camera;
|
12399 | var control = flicking.control;
|
12400 | var prevProgressInPanel = control.activePanel ? camera.getProgressInPanel(control.activePanel) : 0;
|
12401 | panel.loading = false;
|
12402 | panel.resize();
|
12403 | panels.slice(panel.index + 1).forEach(function (panelBehind) {
|
12404 | return panelBehind.updatePosition();
|
12405 | });
|
12406 | if (!flicking.initialized) return;
|
12407 | camera.updateRange();
|
12408 | camera.updateAnchors();
|
12409 |
|
12410 | if (control.animating) ; else {
|
12411 | control.updatePosition(prevProgressInPanel);
|
12412 | control.updateInput();
|
12413 | }
|
12414 | });
|
12415 | contentsReadyChecker.on("preReady", function (e) {
|
12416 | if (_this._flicking) {
|
12417 | void _this.render();
|
12418 | }
|
12419 |
|
12420 | if (e.readyCount === e.totalCount) {
|
12421 | contentsReadyChecker.destroy();
|
12422 | }
|
12423 | });
|
12424 | contentsReadyChecker.on("ready", function () {
|
12425 | if (_this._flicking) {
|
12426 | void _this.render();
|
12427 | }
|
12428 |
|
12429 | contentsReadyChecker.destroy();
|
12430 | });
|
12431 | contentsReadyChecker.check(checkingPanels.map(function (panel) {
|
12432 | return panel.element;
|
12433 | }));
|
12434 | };
|
12435 |
|
12436 | __proto._getPanelAlign = function () {
|
12437 | var align = this._align;
|
12438 | return typeof align === "object" ? align.panel : align;
|
12439 | };
|
12440 |
|
12441 | __proto._updateCameraAndControl = function () {
|
12442 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
12443 | var camera = flicking.camera,
|
12444 | control = flicking.control;
|
12445 | camera.updateRange();
|
12446 | camera.updateAnchors();
|
12447 | camera.resetNeedPanelHistory();
|
12448 | control.updateInput();
|
12449 | };
|
12450 |
|
12451 | __proto._updateRenderingPanels = function () {
|
12452 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
12453 |
|
12454 | if (flicking.renderOnlyVisible) {
|
12455 | this._showOnlyVisiblePanels(flicking);
|
12456 | } else {
|
12457 | flicking.panels.forEach(function (panel) {
|
12458 | return panel.markForShow();
|
12459 | });
|
12460 | }
|
12461 | };
|
12462 |
|
12463 | __proto._showOnlyVisiblePanels = function (flicking) {
|
12464 | var panels = flicking.renderer.panels;
|
12465 | var camera = flicking.camera;
|
12466 | var visibleIndexes = camera.visiblePanels.reduce(function (visibles, panel) {
|
12467 | visibles[panel.index] = true;
|
12468 | return visibles;
|
12469 | }, {});
|
12470 | panels.forEach(function (panel) {
|
12471 | if (panel.index in visibleIndexes || panel.loading) {
|
12472 | panel.markForShow();
|
12473 | } else if (!flicking.holding) {
|
12474 |
|
12475 |
|
12476 | panel.markForHide();
|
12477 | }
|
12478 | });
|
12479 | camera.updateOffset();
|
12480 | };
|
12481 |
|
12482 | __proto._updatePanelSizeByGrid = function (flicking) {
|
12483 | var panels = flicking.panels;
|
12484 | var panelsPerView = flicking.panelsPerView;
|
12485 |
|
12486 | if (panelsPerView <= 0) {
|
12487 | throw new FlickingError(MESSAGE.WRONG_OPTION("panelsPerView", panelsPerView), CODE.WRONG_OPTION);
|
12488 | }
|
12489 |
|
12490 | if (panels.length <= 0) return;
|
12491 |
|
12492 | var firstPanel = panels[0];
|
12493 | firstPanel.resize();
|
12494 | var viewportSize = flicking.camera.size;
|
12495 | var gap = firstPanel.margin.prev + firstPanel.margin.next;
|
12496 | var panelSize = (viewportSize - gap * (panelsPerView - 1)) / panelsPerView;
|
12497 | var panelSizeObj = flicking.horizontal ? {
|
12498 | width: panelSize
|
12499 | } : {
|
12500 | height: panelSize
|
12501 | };
|
12502 | var firstPanelSizeObj = {
|
12503 | size: panelSize,
|
12504 | height: firstPanel.height,
|
12505 | margin: firstPanel.margin
|
12506 | };
|
12507 |
|
12508 | if (!flicking.noPanelStyleOverride) {
|
12509 | flicking.panels.forEach(function (panel) {
|
12510 | return panel.setSize(panelSizeObj);
|
12511 | });
|
12512 | }
|
12513 |
|
12514 | flicking.panels.forEach(function (panel) {
|
12515 | return panel.resize(firstPanelSizeObj);
|
12516 | });
|
12517 | };
|
12518 |
|
12519 | return Renderer;
|
12520 | }();
|
12521 |
|
12522 | var Panel = function () {
|
12523 | |
12524 |
|
12525 |
|
12526 |
|
12527 |
|
12528 |
|
12529 | function Panel(_a) {
|
12530 | var index = _a.index,
|
12531 | align = _a.align,
|
12532 | flicking = _a.flicking;
|
12533 | this._index = index;
|
12534 | this._flicking = flicking;
|
12535 | this._align = align;
|
12536 | this._removed = false;
|
12537 | this._loading = false;
|
12538 |
|
12539 | this._resetInternalStates();
|
12540 | }
|
12541 |
|
12542 | var __proto = Panel.prototype;
|
12543 | Object.defineProperty(__proto, "index", {
|
12544 | |
12545 |
|
12546 |
|
12547 |
|
12548 |
|
12549 |
|
12550 | get: function () {
|
12551 | return this._index;
|
12552 | },
|
12553 | enumerable: false,
|
12554 | configurable: true
|
12555 | });
|
12556 | Object.defineProperty(__proto, "position", {
|
12557 | |
12558 |
|
12559 |
|
12560 |
|
12561 |
|
12562 |
|
12563 | get: function () {
|
12564 | return this._pos + this._alignPos;
|
12565 | },
|
12566 | enumerable: false,
|
12567 | configurable: true
|
12568 | });
|
12569 | Object.defineProperty(__proto, "size", {
|
12570 | |
12571 |
|
12572 |
|
12573 |
|
12574 |
|
12575 |
|
12576 |
|
12577 |
|
12578 | get: function () {
|
12579 | return this._size;
|
12580 | },
|
12581 | enumerable: false,
|
12582 | configurable: true
|
12583 | });
|
12584 | Object.defineProperty(__proto, "sizeIncludingMargin", {
|
12585 | |
12586 |
|
12587 |
|
12588 |
|
12589 |
|
12590 |
|
12591 |
|
12592 |
|
12593 | get: function () {
|
12594 | return this._size + this._margin.prev + this._margin.next;
|
12595 | },
|
12596 | enumerable: false,
|
12597 | configurable: true
|
12598 | });
|
12599 | Object.defineProperty(__proto, "height", {
|
12600 | |
12601 |
|
12602 |
|
12603 |
|
12604 |
|
12605 |
|
12606 | get: function () {
|
12607 | return this._height;
|
12608 | },
|
12609 | enumerable: false,
|
12610 | configurable: true
|
12611 | });
|
12612 | Object.defineProperty(__proto, "margin", {
|
12613 | |
12614 |
|
12615 |
|
12616 |
|
12617 |
|
12618 |
|
12619 |
|
12620 |
|
12621 |
|
12622 |
|
12623 | get: function () {
|
12624 | return this._margin;
|
12625 | },
|
12626 | enumerable: false,
|
12627 | configurable: true
|
12628 | });
|
12629 | Object.defineProperty(__proto, "alignPosition", {
|
12630 | |
12631 |
|
12632 |
|
12633 |
|
12634 |
|
12635 |
|
12636 | get: function () {
|
12637 | return this._alignPos;
|
12638 | },
|
12639 | enumerable: false,
|
12640 | configurable: true
|
12641 | });
|
12642 | Object.defineProperty(__proto, "removed", {
|
12643 | |
12644 |
|
12645 |
|
12646 |
|
12647 |
|
12648 |
|
12649 | get: function () {
|
12650 | return this._removed;
|
12651 | },
|
12652 | enumerable: false,
|
12653 | configurable: true
|
12654 | });
|
12655 | Object.defineProperty(__proto, "loading", {
|
12656 | |
12657 |
|
12658 |
|
12659 |
|
12660 |
|
12661 |
|
12662 | get: function () {
|
12663 | return this._loading;
|
12664 | },
|
12665 | set: function (val) {
|
12666 | this._loading = val;
|
12667 | },
|
12668 | enumerable: false,
|
12669 | configurable: true
|
12670 | });
|
12671 | Object.defineProperty(__proto, "range", {
|
12672 | |
12673 |
|
12674 |
|
12675 |
|
12676 |
|
12677 |
|
12678 |
|
12679 |
|
12680 | get: function () {
|
12681 | return {
|
12682 | min: this._pos,
|
12683 | max: this._pos + this._size
|
12684 | };
|
12685 | },
|
12686 | enumerable: false,
|
12687 | configurable: true
|
12688 | });
|
12689 | Object.defineProperty(__proto, "toggled", {
|
12690 | |
12691 |
|
12692 |
|
12693 |
|
12694 |
|
12695 |
|
12696 | get: function () {
|
12697 | return this._toggled;
|
12698 | },
|
12699 | enumerable: false,
|
12700 | configurable: true
|
12701 | });
|
12702 | Object.defineProperty(__proto, "toggleDirection", {
|
12703 | |
12704 |
|
12705 |
|
12706 |
|
12707 |
|
12708 |
|
12709 | get: function () {
|
12710 | return this._toggleDirection;
|
12711 | },
|
12712 | enumerable: false,
|
12713 | configurable: true
|
12714 | });
|
12715 | Object.defineProperty(__proto, "offset", {
|
12716 | |
12717 |
|
12718 |
|
12719 |
|
12720 |
|
12721 |
|
12722 | get: function () {
|
12723 | var toggleDirection = this._toggleDirection;
|
12724 | var cameraRangeDiff = this._flicking.camera.rangeDiff;
|
12725 | return toggleDirection === DIRECTION.NONE || !this._toggled ? 0 : toggleDirection === DIRECTION.PREV ? -cameraRangeDiff : cameraRangeDiff;
|
12726 | },
|
12727 | enumerable: false,
|
12728 | configurable: true
|
12729 | });
|
12730 | Object.defineProperty(__proto, "progress", {
|
12731 | |
12732 |
|
12733 |
|
12734 |
|
12735 |
|
12736 |
|
12737 | get: function () {
|
12738 | var flicking = this._flicking;
|
12739 | return this.index - flicking.camera.progress;
|
12740 | },
|
12741 | enumerable: false,
|
12742 | configurable: true
|
12743 | });
|
12744 | Object.defineProperty(__proto, "outsetProgress", {
|
12745 | |
12746 |
|
12747 |
|
12748 |
|
12749 |
|
12750 |
|
12751 | get: function () {
|
12752 | var position = this.position + this.offset;
|
12753 | var alignPosition = this._alignPos;
|
12754 | var camera = this._flicking.camera;
|
12755 | var camPos = camera.position;
|
12756 |
|
12757 | if (camPos === position) {
|
12758 | return 0;
|
12759 | }
|
12760 |
|
12761 | if (camPos < position) {
|
12762 | var disappearPosNext = position + (camera.size - camera.alignPosition) + alignPosition;
|
12763 | return -getProgress(camPos, position, disappearPosNext);
|
12764 | } else {
|
12765 | var disappearPosPrev = position - (camera.alignPosition + this._size - alignPosition);
|
12766 | return 1 - getProgress(camPos, disappearPosPrev, position);
|
12767 | }
|
12768 | },
|
12769 | enumerable: false,
|
12770 | configurable: true
|
12771 | });
|
12772 | Object.defineProperty(__proto, "visibleRatio", {
|
12773 | |
12774 |
|
12775 |
|
12776 |
|
12777 |
|
12778 |
|
12779 | get: function () {
|
12780 | var range = this.range;
|
12781 | var size = this._size;
|
12782 | var offset = this.offset;
|
12783 | var visibleRange = this._flicking.camera.visibleRange;
|
12784 | var checkingRange = {
|
12785 | min: range.min + offset,
|
12786 | max: range.max + offset
|
12787 | };
|
12788 |
|
12789 | if (checkingRange.max <= visibleRange.min || checkingRange.min >= visibleRange.max) {
|
12790 | return 0;
|
12791 | }
|
12792 |
|
12793 | var visibleSize = size;
|
12794 |
|
12795 | if (visibleRange.min > checkingRange.min) {
|
12796 | visibleSize -= visibleRange.min - checkingRange.min;
|
12797 | }
|
12798 |
|
12799 | if (visibleRange.max < checkingRange.max) {
|
12800 | visibleSize -= checkingRange.max - visibleRange.max;
|
12801 | }
|
12802 |
|
12803 | return visibleSize / size;
|
12804 | },
|
12805 | enumerable: false,
|
12806 | configurable: true
|
12807 | });
|
12808 | Object.defineProperty(__proto, "align", {
|
12809 |
|
12810 |
|
12811 | |
12812 |
|
12813 |
|
12814 |
|
12815 |
|
12816 | get: function () {
|
12817 | return this._align;
|
12818 | },
|
12819 |
|
12820 | set: function (val) {
|
12821 | this._align = val;
|
12822 | },
|
12823 | enumerable: false,
|
12824 | configurable: true
|
12825 | });
|
12826 | |
12827 |
|
12828 |
|
12829 |
|
12830 |
|
12831 |
|
12832 |
|
12833 |
|
12834 | __proto.resize = function (cached) {
|
12835 | var el = this.element;
|
12836 | var elStyle = getStyle(el);
|
12837 | var flicking = this._flicking;
|
12838 | var horizontal = flicking.horizontal;
|
12839 |
|
12840 | if (cached) {
|
12841 | this._size = cached.size;
|
12842 | this._margin = __assign$2({}, cached.margin);
|
12843 | this._height = cached.height;
|
12844 | } else {
|
12845 | this._size = horizontal ? el.offsetWidth : el.offsetHeight;
|
12846 | this._margin = horizontal ? {
|
12847 | prev: parseFloat(elStyle.marginLeft || "0"),
|
12848 | next: parseFloat(elStyle.marginRight || "0")
|
12849 | } : {
|
12850 | prev: parseFloat(elStyle.marginTop || "0"),
|
12851 | next: parseFloat(elStyle.marginBottom || "0")
|
12852 | };
|
12853 | this._height = horizontal ? el.offsetHeight : this._size;
|
12854 | }
|
12855 |
|
12856 | this.updatePosition();
|
12857 |
|
12858 | this._updateAlignPos();
|
12859 |
|
12860 | return this;
|
12861 | };
|
12862 | |
12863 |
|
12864 |
|
12865 |
|
12866 |
|
12867 |
|
12868 |
|
12869 |
|
12870 |
|
12871 |
|
12872 |
|
12873 | __proto.setSize = function (_a) {
|
12874 | var width = _a.width,
|
12875 | height = _a.height;
|
12876 | var el = this.element;
|
12877 |
|
12878 | if (width != null) {
|
12879 | if (isString(width)) {
|
12880 | el.style.width = width;
|
12881 | } else {
|
12882 | el.style.width = width + "px";
|
12883 | }
|
12884 | }
|
12885 |
|
12886 | if (height != null) {
|
12887 | if (isString(height)) {
|
12888 | el.style.height = height;
|
12889 | } else {
|
12890 | el.style.height = height + "px";
|
12891 | }
|
12892 | }
|
12893 |
|
12894 | return this;
|
12895 | };
|
12896 | |
12897 |
|
12898 |
|
12899 |
|
12900 |
|
12901 |
|
12902 |
|
12903 |
|
12904 | __proto.contains = function (element) {
|
12905 | var _a;
|
12906 |
|
12907 | return !!((_a = this.element) === null || _a === void 0 ? void 0 : _a.contains(element));
|
12908 | };
|
12909 | |
12910 |
|
12911 |
|
12912 |
|
12913 |
|
12914 |
|
12915 |
|
12916 | __proto.destroy = function () {
|
12917 | this._resetInternalStates();
|
12918 |
|
12919 | this._removed = true;
|
12920 | };
|
12921 | |
12922 |
|
12923 |
|
12924 |
|
12925 |
|
12926 |
|
12927 |
|
12928 |
|
12929 |
|
12930 | __proto.includePosition = function (pos, includeMargin) {
|
12931 | if (includeMargin === void 0) {
|
12932 | includeMargin = false;
|
12933 | }
|
12934 |
|
12935 | return this.includeRange(pos, pos, includeMargin);
|
12936 | };
|
12937 | |
12938 |
|
12939 |
|
12940 |
|
12941 |
|
12942 |
|
12943 |
|
12944 |
|
12945 |
|
12946 |
|
12947 | __proto.includeRange = function (min, max, includeMargin) {
|
12948 | if (includeMargin === void 0) {
|
12949 | includeMargin = false;
|
12950 | }
|
12951 |
|
12952 | var margin = this._margin;
|
12953 | var panelRange = this.range;
|
12954 |
|
12955 | if (includeMargin) {
|
12956 | panelRange.min -= margin.prev;
|
12957 | panelRange.max += margin.next;
|
12958 | }
|
12959 |
|
12960 | return max >= panelRange.min && min <= panelRange.max;
|
12961 | };
|
12962 | |
12963 |
|
12964 |
|
12965 |
|
12966 |
|
12967 |
|
12968 |
|
12969 |
|
12970 | __proto.focus = function (duration) {
|
12971 | return this._flicking.moveTo(this._index, duration);
|
12972 | };
|
12973 | |
12974 |
|
12975 |
|
12976 |
|
12977 |
|
12978 |
|
12979 |
|
12980 |
|
12981 |
|
12982 | __proto.prev = function () {
|
12983 | var index = this._index;
|
12984 | var flicking = this._flicking;
|
12985 | var renderer = flicking.renderer;
|
12986 | var panelCount = renderer.panelCount;
|
12987 | if (panelCount === 1) return null;
|
12988 | return flicking.circularEnabled ? renderer.getPanel(index === 0 ? panelCount - 1 : index - 1) : renderer.getPanel(index - 1);
|
12989 | };
|
12990 | |
12991 |
|
12992 |
|
12993 |
|
12994 |
|
12995 |
|
12996 |
|
12997 |
|
12998 |
|
12999 | __proto.next = function () {
|
13000 | var index = this._index;
|
13001 | var flicking = this._flicking;
|
13002 | var renderer = flicking.renderer;
|
13003 | var panelCount = renderer.panelCount;
|
13004 | if (panelCount === 1) return null;
|
13005 | return flicking.circularEnabled ? renderer.getPanel(index === panelCount - 1 ? 0 : index + 1) : renderer.getPanel(index + 1);
|
13006 | };
|
13007 | |
13008 |
|
13009 |
|
13010 |
|
13011 |
|
13012 |
|
13013 |
|
13014 |
|
13015 |
|
13016 |
|
13017 | __proto.increaseIndex = function (val) {
|
13018 | this._index += Math.max(val, 0);
|
13019 | return this;
|
13020 | };
|
13021 | |
13022 |
|
13023 |
|
13024 |
|
13025 |
|
13026 |
|
13027 |
|
13028 |
|
13029 |
|
13030 |
|
13031 | __proto.decreaseIndex = function (val) {
|
13032 | this._index -= Math.max(val, 0);
|
13033 | return this;
|
13034 | };
|
13035 | |
13036 |
|
13037 |
|
13038 |
|
13039 |
|
13040 | __proto.updatePosition = function () {
|
13041 | var prevPanel = this._flicking.renderer.panels[this._index - 1];
|
13042 | this._pos = prevPanel ? prevPanel.range.max + prevPanel.margin.next + this._margin.prev : this._margin.prev;
|
13043 | return this;
|
13044 | };
|
13045 | |
13046 |
|
13047 |
|
13048 |
|
13049 |
|
13050 |
|
13051 | __proto.toggle = function (prevPos, newPos) {
|
13052 | var toggleDirection = this._toggleDirection;
|
13053 | var togglePosition = this._togglePosition;
|
13054 | if (toggleDirection === DIRECTION.NONE || newPos === prevPos) return false;
|
13055 | var prevToggled = this._toggled;
|
13056 |
|
13057 | if (newPos > prevPos) {
|
13058 | if (togglePosition >= prevPos && togglePosition <= newPos) {
|
13059 | this._toggled = toggleDirection === DIRECTION.NEXT;
|
13060 | }
|
13061 | } else {
|
13062 | if (togglePosition <= prevPos && togglePosition >= newPos) {
|
13063 | this._toggled = toggleDirection !== DIRECTION.NEXT;
|
13064 | }
|
13065 | }
|
13066 |
|
13067 | return prevToggled !== this._toggled;
|
13068 | };
|
13069 | |
13070 |
|
13071 |
|
13072 |
|
13073 |
|
13074 | __proto.updateCircularToggleDirection = function () {
|
13075 | var flicking = this._flicking;
|
13076 |
|
13077 | if (!flicking.circularEnabled) {
|
13078 | this._toggleDirection = DIRECTION.NONE;
|
13079 | this._toggled = false;
|
13080 | return this;
|
13081 | }
|
13082 |
|
13083 | var camera = flicking.camera;
|
13084 | var camRange = camera.range;
|
13085 | var camAlignPosition = camera.alignPosition;
|
13086 | var camVisibleRange = camera.visibleRange;
|
13087 | var camVisibleSize = camVisibleRange.max - camVisibleRange.min;
|
13088 | var minimumVisible = camRange.min - camAlignPosition;
|
13089 | var maximumVisible = camRange.max - camAlignPosition + camVisibleSize;
|
13090 | var shouldBeVisibleAtMin = this.includeRange(maximumVisible - camVisibleSize, maximumVisible, false);
|
13091 | var shouldBeVisibleAtMax = this.includeRange(minimumVisible, minimumVisible + camVisibleSize, false);
|
13092 | this._toggled = false;
|
13093 |
|
13094 | if (shouldBeVisibleAtMin) {
|
13095 | this._toggleDirection = DIRECTION.PREV;
|
13096 | this._togglePosition = this.range.max + camRange.min - camRange.max + camAlignPosition;
|
13097 | this.toggle(Infinity, camera.position);
|
13098 | } else if (shouldBeVisibleAtMax) {
|
13099 | this._toggleDirection = DIRECTION.NEXT;
|
13100 | this._togglePosition = this.range.min + camRange.max - camVisibleSize + camAlignPosition;
|
13101 | this.toggle(-Infinity, camera.position);
|
13102 | } else {
|
13103 | this._toggleDirection = DIRECTION.NONE;
|
13104 | this._togglePosition = 0;
|
13105 | }
|
13106 |
|
13107 | return this;
|
13108 | };
|
13109 |
|
13110 | __proto._updateAlignPos = function () {
|
13111 | this._alignPos = parseAlign$1(this._align, this._size);
|
13112 | };
|
13113 |
|
13114 | __proto._resetInternalStates = function () {
|
13115 | this._size = 0;
|
13116 | this._pos = 0;
|
13117 | this._margin = {
|
13118 | prev: 0,
|
13119 | next: 0
|
13120 | };
|
13121 | this._height = 0;
|
13122 | this._alignPos = 0;
|
13123 | this._toggled = false;
|
13124 | this._togglePosition = 0;
|
13125 | this._toggleDirection = DIRECTION.NONE;
|
13126 | };
|
13127 |
|
13128 | return Panel;
|
13129 | }();
|
13130 |
|
13131 | |
13132 |
|
13133 |
|
13134 |
|
13135 |
|
13136 | var ElementPanel = function (_super) {
|
13137 | __extends$2(ElementPanel, _super);
|
13138 | |
13139 |
|
13140 |
|
13141 |
|
13142 |
|
13143 |
|
13144 |
|
13145 |
|
13146 |
|
13147 | function ElementPanel(options) {
|
13148 | var _this = _super.call(this, options) || this;
|
13149 |
|
13150 | _this._el = options.el;
|
13151 | _this._rendered = true;
|
13152 | return _this;
|
13153 | }
|
13154 |
|
13155 | var __proto = ElementPanel.prototype;
|
13156 | Object.defineProperty(__proto, "element", {
|
13157 | |
13158 |
|
13159 |
|
13160 |
|
13161 |
|
13162 |
|
13163 | get: function () {
|
13164 | return this._el;
|
13165 | },
|
13166 | enumerable: false,
|
13167 | configurable: true
|
13168 | });
|
13169 | Object.defineProperty(__proto, "rendered", {
|
13170 | get: function () {
|
13171 | return this._rendered;
|
13172 | },
|
13173 | enumerable: false,
|
13174 | configurable: true
|
13175 | });
|
13176 |
|
13177 | __proto.markForShow = function () {
|
13178 | this._rendered = true;
|
13179 | };
|
13180 |
|
13181 | __proto.markForHide = function () {
|
13182 | this._rendered = false;
|
13183 | };
|
13184 |
|
13185 | return ElementPanel;
|
13186 | }(Panel);
|
13187 |
|
13188 | |
13189 |
|
13190 |
|
13191 |
|
13192 | var VanillaRenderer = function (_super) {
|
13193 | __extends$2(VanillaRenderer, _super);
|
13194 |
|
13195 | function VanillaRenderer() {
|
13196 | return _super !== null && _super.apply(this, arguments) || this;
|
13197 | }
|
13198 |
|
13199 |
|
13200 | var __proto = VanillaRenderer.prototype;
|
13201 |
|
13202 | __proto.render = function () {
|
13203 | return __awaiter(this, void 0, void 0, function () {
|
13204 | var flicking, cameraEl, wasRenderedPanels, renderingPanels;
|
13205 | return __generator(this, function (_a) {
|
13206 | flicking = getFlickingAttached(this._flicking, "Renderer");
|
13207 | cameraEl = flicking.camera.element;
|
13208 | wasRenderedPanels = this._panels.filter(function (panel) {
|
13209 | return panel.element.parentElement === cameraEl;
|
13210 | });
|
13211 |
|
13212 | this._updateRenderingPanels();
|
13213 |
|
13214 | renderingPanels = this._getRenderingPanelsByOrder();
|
13215 |
|
13216 | this._removePanelElements(wasRenderedPanels.filter(function (panel) {
|
13217 | return !panel.rendered;
|
13218 | }));
|
13219 |
|
13220 | this._insertPanelElements(renderingPanels.filter(function (panel) {
|
13221 | return panel.element.parentElement !== cameraEl;
|
13222 | }), null);
|
13223 |
|
13224 | this._resetPanelElementOrder(renderingPanels);
|
13225 |
|
13226 | return [2
|
13227 |
|
13228 | ];
|
13229 | });
|
13230 | });
|
13231 | };
|
13232 |
|
13233 |
|
13234 | __proto.forceRenderAllPanels = function () {
|
13235 | return __awaiter(this, void 0, void 0, function () {
|
13236 | var flicking, camera, cameraElement, fragment;
|
13237 | return __generator(this, function (_a) {
|
13238 | flicking = getFlickingAttached(this._flicking, "Renderer");
|
13239 | camera = flicking.camera;
|
13240 | cameraElement = camera.element;
|
13241 | fragment = document.createDocumentFragment();
|
13242 |
|
13243 | this._panels.forEach(function (panel) {
|
13244 | return fragment.appendChild(panel.element);
|
13245 | });
|
13246 |
|
13247 | this._removeAllChildsFromCamera();
|
13248 |
|
13249 | cameraElement.appendChild(fragment);
|
13250 | return [2
|
13251 |
|
13252 | ];
|
13253 | });
|
13254 | });
|
13255 | };
|
13256 |
|
13257 | __proto._collectPanels = function () {
|
13258 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
13259 | var cameraElement = flicking.camera.element;
|
13260 |
|
13261 | toArray$3(cameraElement.childNodes).forEach(function (node) {
|
13262 | if (node.nodeType === Node.TEXT_NODE) {
|
13263 | cameraElement.removeChild(node);
|
13264 | }
|
13265 | });
|
13266 |
|
13267 | var align = this._getPanelAlign();
|
13268 |
|
13269 | var cameraChilds = toArray$3(cameraElement.children);
|
13270 | this._panels = cameraChilds.map(function (el, index) {
|
13271 | return new ElementPanel({
|
13272 | flicking: flicking,
|
13273 | el: el,
|
13274 | index: index,
|
13275 | align: align
|
13276 | });
|
13277 | });
|
13278 | };
|
13279 |
|
13280 | __proto._createPanel = function (el, options) {
|
13281 | return new ElementPanel(__assign$2({
|
13282 | el: el
|
13283 | }, options));
|
13284 | };
|
13285 |
|
13286 | __proto._insertPanelElements = function (panels, nextSibling) {
|
13287 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
13288 | var camera = flicking.camera;
|
13289 | var cameraElement = camera.element;
|
13290 | var nextSiblingElement = (nextSibling === null || nextSibling === void 0 ? void 0 : nextSibling.element) || null;
|
13291 | var fragment = document.createDocumentFragment();
|
13292 | panels.forEach(function (panel) {
|
13293 | return fragment.appendChild(panel.element);
|
13294 | });
|
13295 | cameraElement.insertBefore(fragment, nextSiblingElement);
|
13296 | return this;
|
13297 | };
|
13298 |
|
13299 | __proto._removePanelElements = function (panels) {
|
13300 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
13301 | var cameraElement = flicking.camera.element;
|
13302 | panels.forEach(function (panel) {
|
13303 | cameraElement.removeChild(panel.element);
|
13304 | });
|
13305 | return this;
|
13306 | };
|
13307 |
|
13308 | __proto._resetPanelElementOrder = function (panels) {
|
13309 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
13310 | var cameraEl = flicking.camera.element;
|
13311 |
|
13312 | var reversedPanels = __spreadArray([], __read$1(panels)).reverse();
|
13313 |
|
13314 | reversedPanels.forEach(function (panel, idx) {
|
13315 | var nextPanel = reversedPanels[idx - 1];
|
13316 | var nextPanelEl = nextPanel ? nextPanel.element : null;
|
13317 |
|
13318 | if (panel.element.nextElementSibling !== nextPanelEl) {
|
13319 | cameraEl.insertBefore(panel.element, nextPanelEl);
|
13320 | }
|
13321 | });
|
13322 | };
|
13323 |
|
13324 | __proto._removeAllChildsFromCamera = function () {
|
13325 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
13326 | var cameraElement = flicking.camera.element;
|
13327 |
|
13328 | while (cameraElement.firstChild) {
|
13329 | cameraElement.removeChild(cameraElement.firstChild);
|
13330 | }
|
13331 | };
|
13332 |
|
13333 | __proto._getRenderingPanelsByOrder = function () {
|
13334 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
13335 | var panels = flicking.renderer.panels;
|
13336 | return panels.filter(function (panel) {
|
13337 | return panel.rendered;
|
13338 | }).sort(function (a, b) {
|
13339 | return a.position + a.offset - (b.position + b.offset);
|
13340 | });
|
13341 | };
|
13342 |
|
13343 | return VanillaRenderer;
|
13344 | }(Renderer$1);
|
13345 |
|
13346 | |
13347 |
|
13348 |
|
13349 |
|
13350 | var ExternalRenderer = function (_super) {
|
13351 | __extends$2(ExternalRenderer, _super);
|
13352 |
|
13353 | function ExternalRenderer() {
|
13354 | return _super !== null && _super.apply(this, arguments) || this;
|
13355 | }
|
13356 |
|
13357 |
|
13358 | var __proto = ExternalRenderer.prototype;
|
13359 |
|
13360 | __proto._insertPanelElements = function (panels, nextSibling) {
|
13361 | };
|
13362 |
|
13363 |
|
13364 | __proto._removePanelElements = function (panels) {
|
13365 | };
|
13366 |
|
13367 | return ExternalRenderer;
|
13368 | }(Renderer$1);
|
13369 |
|
13370 | |
13371 |
|
13372 |
|
13373 |
|
13374 |
|
13375 | var Renderer = {
|
13376 | __proto__: null,
|
13377 | Renderer: Renderer$1,
|
13378 | VanillaRenderer: VanillaRenderer,
|
13379 | ExternalRenderer: ExternalRenderer
|
13380 | };
|
13381 |
|
13382 | |
13383 |
|
13384 |
|
13385 |
|
13386 |
|
13387 |
|
13388 |
|
13389 | var Flicking = function (_super) {
|
13390 | __extends$2(Flicking, _super);
|
13391 | |
13392 |
|
13393 |
|
13394 |
|
13395 |
|
13396 |
|
13397 |
|
13398 |
|
13399 |
|
13400 |
|
13401 |
|
13402 |
|
13403 |
|
13404 |
|
13405 |
|
13406 |
|
13407 |
|
13408 |
|
13409 |
|
13410 |
|
13411 |
|
13412 |
|
13413 |
|
13414 |
|
13415 |
|
13416 |
|
13417 |
|
13418 |
|
13419 |
|
13420 |
|
13421 | function Flicking(root, _a) {
|
13422 | var _b = _a === void 0 ? {} : _a,
|
13423 | _c = _b.align,
|
13424 | align = _c === void 0 ? ALIGN.CENTER : _c,
|
13425 | _d = _b.defaultIndex,
|
13426 | defaultIndex = _d === void 0 ? 0 : _d,
|
13427 | _e = _b.horizontal,
|
13428 | horizontal = _e === void 0 ? true : _e,
|
13429 | _f = _b.circular,
|
13430 | circular = _f === void 0 ? false : _f,
|
13431 | _g = _b.bound,
|
13432 | bound = _g === void 0 ? false : _g,
|
13433 | _h = _b.adaptive,
|
13434 | adaptive = _h === void 0 ? false : _h,
|
13435 | _j = _b.panelsPerView,
|
13436 | panelsPerView = _j === void 0 ? -1 : _j,
|
13437 | _k = _b.noPanelStyleOverride,
|
13438 | noPanelStyleOverride = _k === void 0 ? false : _k,
|
13439 | _l = _b.resizeOnContentsReady,
|
13440 | resizeOnContentsReady = _l === void 0 ? false : _l,
|
13441 | _m = _b.needPanelThreshold,
|
13442 | needPanelThreshold = _m === void 0 ? 0 : _m,
|
13443 | _o = _b.preventEventsBeforeInit,
|
13444 | preventEventsBeforeInit = _o === void 0 ? true : _o,
|
13445 | _p = _b.deceleration,
|
13446 | deceleration = _p === void 0 ? 0.0075 : _p,
|
13447 | _q = _b.duration,
|
13448 | duration = _q === void 0 ? 500 : _q,
|
13449 | _r = _b.easing,
|
13450 | easing = _r === void 0 ? function (x) {
|
13451 | return 1 - Math.pow(1 - x, 3);
|
13452 | } : _r,
|
13453 | _s = _b.inputType,
|
13454 | inputType = _s === void 0 ? ["mouse", "touch"] : _s,
|
13455 | _t = _b.moveType,
|
13456 | moveType = _t === void 0 ? "snap" : _t,
|
13457 | _u = _b.threshold,
|
13458 | threshold = _u === void 0 ? 40 : _u,
|
13459 | _v = _b.interruptable,
|
13460 | interruptable = _v === void 0 ? true : _v,
|
13461 | _w = _b.bounce,
|
13462 | bounce = _w === void 0 ? "20%" : _w,
|
13463 | _x = _b.iOSEdgeSwipeThreshold,
|
13464 | iOSEdgeSwipeThreshold = _x === void 0 ? 30 : _x,
|
13465 | _y = _b.preventClickOnDrag,
|
13466 | preventClickOnDrag = _y === void 0 ? true : _y,
|
13467 | _z = _b.disableOnInit,
|
13468 | disableOnInit = _z === void 0 ? false : _z,
|
13469 | _0 = _b.renderOnlyVisible,
|
13470 | renderOnlyVisible = _0 === void 0 ? false : _0,
|
13471 | _1 = _b.autoInit,
|
13472 | autoInit = _1 === void 0 ? true : _1,
|
13473 | _2 = _b.autoResize,
|
13474 | autoResize = _2 === void 0 ? true : _2,
|
13475 | _3 = _b.renderExternal,
|
13476 | renderExternal = _3 === void 0 ? null : _3;
|
13477 |
|
13478 | var _this = _super.call(this) || this;
|
13479 |
|
13480 |
|
13481 | _this._initialized = false;
|
13482 | _this._plugins = [];
|
13483 |
|
13484 | _this._align = align;
|
13485 | _this._defaultIndex = defaultIndex;
|
13486 | _this._horizontal = horizontal;
|
13487 | _this._circular = circular;
|
13488 | _this._bound = bound;
|
13489 | _this._adaptive = adaptive;
|
13490 | _this._panelsPerView = panelsPerView;
|
13491 | _this._noPanelStyleOverride = noPanelStyleOverride;
|
13492 | _this._resizeOnContentsReady = resizeOnContentsReady;
|
13493 | _this._needPanelThreshold = needPanelThreshold;
|
13494 | _this._preventEventsBeforeInit = preventEventsBeforeInit;
|
13495 | _this._deceleration = deceleration;
|
13496 | _this._duration = duration;
|
13497 | _this._easing = easing;
|
13498 | _this._inputType = inputType;
|
13499 | _this._moveType = moveType;
|
13500 | _this._threshold = threshold;
|
13501 | _this._interruptable = interruptable;
|
13502 | _this._bounce = bounce;
|
13503 | _this._iOSEdgeSwipeThreshold = iOSEdgeSwipeThreshold;
|
13504 | _this._preventClickOnDrag = preventClickOnDrag;
|
13505 | _this._disableOnInit = disableOnInit;
|
13506 | _this._renderOnlyVisible = renderOnlyVisible;
|
13507 | _this._autoResize = autoResize;
|
13508 | _this._autoInit = autoInit;
|
13509 | _this._renderExternal = renderExternal;
|
13510 |
|
13511 | _this._viewport = new Viewport(getElement(root));
|
13512 | _this._renderer = _this._createRenderer();
|
13513 | _this._camera = _this._createCamera();
|
13514 | _this._control = _this._createControl();
|
13515 | _this.resize = _this.resize.bind(_this);
|
13516 |
|
13517 | if (_this._autoInit) {
|
13518 | void _this.init();
|
13519 | }
|
13520 |
|
13521 | return _this;
|
13522 | }
|
13523 |
|
13524 | var __proto = Flicking.prototype;
|
13525 | Object.defineProperty(__proto, "control", {
|
13526 |
|
13527 |
|
13528 | |
13529 |
|
13530 |
|
13531 |
|
13532 |
|
13533 |
|
13534 |
|
13535 |
|
13536 |
|
13537 |
|
13538 | get: function () {
|
13539 | return this._control;
|
13540 | },
|
13541 | enumerable: false,
|
13542 | configurable: true
|
13543 | });
|
13544 | Object.defineProperty(__proto, "camera", {
|
13545 | |
13546 |
|
13547 |
|
13548 |
|
13549 |
|
13550 |
|
13551 |
|
13552 |
|
13553 |
|
13554 |
|
13555 |
|
13556 | get: function () {
|
13557 | return this._camera;
|
13558 | },
|
13559 | enumerable: false,
|
13560 | configurable: true
|
13561 | });
|
13562 | Object.defineProperty(__proto, "renderer", {
|
13563 | |
13564 |
|
13565 |
|
13566 |
|
13567 |
|
13568 |
|
13569 |
|
13570 |
|
13571 |
|
13572 |
|
13573 | get: function () {
|
13574 | return this._renderer;
|
13575 | },
|
13576 | enumerable: false,
|
13577 | configurable: true
|
13578 | });
|
13579 | Object.defineProperty(__proto, "viewport", {
|
13580 | |
13581 |
|
13582 |
|
13583 |
|
13584 |
|
13585 |
|
13586 |
|
13587 | get: function () {
|
13588 | return this._viewport;
|
13589 | },
|
13590 | enumerable: false,
|
13591 | configurable: true
|
13592 | });
|
13593 | Object.defineProperty(__proto, "initialized", {
|
13594 |
|
13595 |
|
13596 | |
13597 |
|
13598 |
|
13599 |
|
13600 |
|
13601 |
|
13602 |
|
13603 |
|
13604 |
|
13605 | get: function () {
|
13606 | return this._initialized;
|
13607 | },
|
13608 | enumerable: false,
|
13609 | configurable: true
|
13610 | });
|
13611 | Object.defineProperty(__proto, "circularEnabled", {
|
13612 | |
13613 |
|
13614 |
|
13615 |
|
13616 |
|
13617 |
|
13618 |
|
13619 |
|
13620 |
|
13621 | get: function () {
|
13622 | return this._camera.controlParams.circular;
|
13623 | },
|
13624 | enumerable: false,
|
13625 | configurable: true
|
13626 | });
|
13627 | Object.defineProperty(__proto, "index", {
|
13628 | |
13629 |
|
13630 |
|
13631 |
|
13632 |
|
13633 |
|
13634 |
|
13635 | get: function () {
|
13636 | return this._control.activeIndex;
|
13637 | },
|
13638 | enumerable: false,
|
13639 | configurable: true
|
13640 | });
|
13641 | Object.defineProperty(__proto, "element", {
|
13642 | |
13643 |
|
13644 |
|
13645 |
|
13646 |
|
13647 |
|
13648 | get: function () {
|
13649 | return this._viewport.element;
|
13650 | },
|
13651 | enumerable: false,
|
13652 | configurable: true
|
13653 | });
|
13654 | Object.defineProperty(__proto, "currentPanel", {
|
13655 | |
13656 |
|
13657 |
|
13658 |
|
13659 |
|
13660 |
|
13661 |
|
13662 | get: function () {
|
13663 | return this._control.activePanel;
|
13664 | },
|
13665 | enumerable: false,
|
13666 | configurable: true
|
13667 | });
|
13668 | Object.defineProperty(__proto, "panels", {
|
13669 | |
13670 |
|
13671 |
|
13672 |
|
13673 |
|
13674 |
|
13675 |
|
13676 | get: function () {
|
13677 | return this._renderer.panels;
|
13678 | },
|
13679 | enumerable: false,
|
13680 | configurable: true
|
13681 | });
|
13682 | Object.defineProperty(__proto, "panelCount", {
|
13683 | |
13684 |
|
13685 |
|
13686 |
|
13687 |
|
13688 |
|
13689 | get: function () {
|
13690 | return this._renderer.panelCount;
|
13691 | },
|
13692 | enumerable: false,
|
13693 | configurable: true
|
13694 | });
|
13695 | Object.defineProperty(__proto, "visiblePanels", {
|
13696 | |
13697 |
|
13698 |
|
13699 |
|
13700 |
|
13701 |
|
13702 |
|
13703 | get: function () {
|
13704 | return this._camera.visiblePanels;
|
13705 | },
|
13706 | enumerable: false,
|
13707 | configurable: true
|
13708 | });
|
13709 | Object.defineProperty(__proto, "animating", {
|
13710 | |
13711 |
|
13712 |
|
13713 |
|
13714 |
|
13715 |
|
13716 | get: function () {
|
13717 | return this._control.animating;
|
13718 | },
|
13719 | enumerable: false,
|
13720 | configurable: true
|
13721 | });
|
13722 | Object.defineProperty(__proto, "holding", {
|
13723 | |
13724 |
|
13725 |
|
13726 |
|
13727 |
|
13728 |
|
13729 | get: function () {
|
13730 | return this._control.holding;
|
13731 | },
|
13732 | enumerable: false,
|
13733 | configurable: true
|
13734 | });
|
13735 | Object.defineProperty(__proto, "activePlugins", {
|
13736 | |
13737 |
|
13738 |
|
13739 |
|
13740 |
|
13741 |
|
13742 | get: function () {
|
13743 | return this._plugins;
|
13744 | },
|
13745 | enumerable: false,
|
13746 | configurable: true
|
13747 | });
|
13748 | Object.defineProperty(__proto, "align", {
|
13749 |
|
13750 |
|
13751 |
|
13752 | |
13753 |
|
13754 |
|
13755 |
|
13756 |
|
13757 |
|
13758 |
|
13759 |
|
13760 |
|
13761 |
|
13762 |
|
13763 |
|
13764 |
|
13765 |
|
13766 |
|
13767 |
|
13768 |
|
13769 |
|
13770 |
|
13771 |
|
13772 |
|
13773 |
|
13774 |
|
13775 |
|
13776 |
|
13777 |
|
13778 |
|
13779 | get: function () {
|
13780 | return this._align;
|
13781 | },
|
13782 |
|
13783 |
|
13784 | set: function (val) {
|
13785 | this._align = val;
|
13786 | this._renderer.align = val;
|
13787 | this._camera.align = val;
|
13788 | },
|
13789 | enumerable: false,
|
13790 | configurable: true
|
13791 | });
|
13792 | Object.defineProperty(__proto, "defaultIndex", {
|
13793 | |
13794 |
|
13795 |
|
13796 |
|
13797 |
|
13798 |
|
13799 | get: function () {
|
13800 | return this._defaultIndex;
|
13801 | },
|
13802 | set: function (val) {
|
13803 | this._defaultIndex = val;
|
13804 | },
|
13805 | enumerable: false,
|
13806 | configurable: true
|
13807 | });
|
13808 | Object.defineProperty(__proto, "horizontal", {
|
13809 | |
13810 |
|
13811 |
|
13812 |
|
13813 |
|
13814 |
|
13815 | get: function () {
|
13816 | return this._horizontal;
|
13817 | },
|
13818 | set: function (val) {
|
13819 | this._horizontal = val;
|
13820 | },
|
13821 | enumerable: false,
|
13822 | configurable: true
|
13823 | });
|
13824 | Object.defineProperty(__proto, "circular", {
|
13825 | |
13826 |
|
13827 |
|
13828 |
|
13829 |
|
13830 |
|
13831 | get: function () {
|
13832 | return this._circular;
|
13833 | },
|
13834 | set: function (val) {
|
13835 | this._circular = val;
|
13836 | },
|
13837 | enumerable: false,
|
13838 | configurable: true
|
13839 | });
|
13840 | Object.defineProperty(__proto, "bound", {
|
13841 | |
13842 |
|
13843 |
|
13844 |
|
13845 |
|
13846 |
|
13847 |
|
13848 |
|
13849 | get: function () {
|
13850 | return this._bound;
|
13851 | },
|
13852 | set: function (val) {
|
13853 | this._bound = val;
|
13854 | },
|
13855 | enumerable: false,
|
13856 | configurable: true
|
13857 | });
|
13858 | Object.defineProperty(__proto, "adaptive", {
|
13859 | |
13860 |
|
13861 |
|
13862 |
|
13863 |
|
13864 |
|
13865 | get: function () {
|
13866 | return this._adaptive;
|
13867 | },
|
13868 | set: function (val) {
|
13869 | this._adaptive = val;
|
13870 | },
|
13871 | enumerable: false,
|
13872 | configurable: true
|
13873 | });
|
13874 | Object.defineProperty(__proto, "panelsPerView", {
|
13875 | |
13876 |
|
13877 |
|
13878 |
|
13879 |
|
13880 |
|
13881 | get: function () {
|
13882 | return this._panelsPerView;
|
13883 | },
|
13884 | set: function (val) {
|
13885 | this._panelsPerView = val;
|
13886 | },
|
13887 | enumerable: false,
|
13888 | configurable: true
|
13889 | });
|
13890 | Object.defineProperty(__proto, "noPanelStyleOverride", {
|
13891 | |
13892 |
|
13893 |
|
13894 |
|
13895 |
|
13896 |
|
13897 |
|
13898 |
|
13899 | get: function () {
|
13900 | return this._noPanelStyleOverride;
|
13901 | },
|
13902 | set: function (val) {
|
13903 | this._noPanelStyleOverride = val;
|
13904 | },
|
13905 | enumerable: false,
|
13906 | configurable: true
|
13907 | });
|
13908 | Object.defineProperty(__proto, "resizeOnContentsReady", {
|
13909 | |
13910 |
|
13911 |
|
13912 |
|
13913 |
|
13914 |
|
13915 |
|
13916 |
|
13917 | get: function () {
|
13918 | return this._resizeOnContentsReady;
|
13919 | },
|
13920 | set: function (val) {
|
13921 | this._resizeOnContentsReady = val;
|
13922 | },
|
13923 | enumerable: false,
|
13924 | configurable: true
|
13925 | });
|
13926 | Object.defineProperty(__proto, "needPanelThreshold", {
|
13927 |
|
13928 |
|
13929 | |
13930 |
|
13931 |
|
13932 |
|
13933 |
|
13934 |
|
13935 | get: function () {
|
13936 | return this._needPanelThreshold;
|
13937 | },
|
13938 |
|
13939 | set: function (val) {
|
13940 | this._needPanelThreshold = val;
|
13941 | },
|
13942 | enumerable: false,
|
13943 | configurable: true
|
13944 | });
|
13945 | Object.defineProperty(__proto, "preventEventsBeforeInit", {
|
13946 | |
13947 |
|
13948 |
|
13949 |
|
13950 |
|
13951 |
|
13952 | get: function () {
|
13953 | return this._preventEventsBeforeInit;
|
13954 | },
|
13955 | set: function (val) {
|
13956 | this._preventEventsBeforeInit = val;
|
13957 | },
|
13958 | enumerable: false,
|
13959 | configurable: true
|
13960 | });
|
13961 | Object.defineProperty(__proto, "deceleration", {
|
13962 |
|
13963 |
|
13964 | |
13965 |
|
13966 |
|
13967 |
|
13968 |
|
13969 |
|
13970 | get: function () {
|
13971 | return this._deceleration;
|
13972 | },
|
13973 |
|
13974 | set: function (val) {
|
13975 | this._deceleration = val;
|
13976 | },
|
13977 | enumerable: false,
|
13978 | configurable: true
|
13979 | });
|
13980 | Object.defineProperty(__proto, "easing", {
|
13981 | |
13982 |
|
13983 |
|
13984 |
|
13985 |
|
13986 |
|
13987 |
|
13988 | get: function () {
|
13989 | return this._easing;
|
13990 | },
|
13991 | set: function (val) {
|
13992 | this._easing = val;
|
13993 | },
|
13994 | enumerable: false,
|
13995 | configurable: true
|
13996 | });
|
13997 | Object.defineProperty(__proto, "duration", {
|
13998 | |
13999 |
|
14000 |
|
14001 |
|
14002 |
|
14003 |
|
14004 | get: function () {
|
14005 | return this._duration;
|
14006 | },
|
14007 | set: function (val) {
|
14008 | this._duration = val;
|
14009 | },
|
14010 | enumerable: false,
|
14011 | configurable: true
|
14012 | });
|
14013 | Object.defineProperty(__proto, "inputType", {
|
14014 |
|
14015 |
|
14016 | |
14017 |
|
14018 |
|
14019 |
|
14020 |
|
14021 |
|
14022 |
|
14023 |
|
14024 | get: function () {
|
14025 | return this._inputType;
|
14026 | },
|
14027 |
|
14028 | set: function (val) {
|
14029 | this._inputType = val;
|
14030 | },
|
14031 | enumerable: false,
|
14032 | configurable: true
|
14033 | });
|
14034 | Object.defineProperty(__proto, "moveType", {
|
14035 | |
14036 |
|
14037 |
|
14038 |
|
14039 |
|
14040 |
|
14041 |
|
14042 |
|
14043 |
|
14044 |
|
14045 |
|
14046 |
|
14047 |
|
14048 |
|
14049 |
|
14050 |
|
14051 |
|
14052 |
|
14053 |
|
14054 |
|
14055 |
|
14056 |
|
14057 |
|
14058 |
|
14059 |
|
14060 |
|
14061 |
|
14062 |
|
14063 |
|
14064 |
|
14065 | get: function () {
|
14066 | return this._moveType;
|
14067 | },
|
14068 | set: function (val) {
|
14069 | this._moveType = val;
|
14070 | },
|
14071 | enumerable: false,
|
14072 | configurable: true
|
14073 | });
|
14074 | Object.defineProperty(__proto, "threshold", {
|
14075 | |
14076 |
|
14077 |
|
14078 |
|
14079 |
|
14080 |
|
14081 | get: function () {
|
14082 | return this._threshold;
|
14083 | },
|
14084 | set: function (val) {
|
14085 | this._threshold = val;
|
14086 | },
|
14087 | enumerable: false,
|
14088 | configurable: true
|
14089 | });
|
14090 | Object.defineProperty(__proto, "interruptable", {
|
14091 | |
14092 |
|
14093 |
|
14094 |
|
14095 |
|
14096 |
|
14097 | get: function () {
|
14098 | return this._interruptable;
|
14099 | },
|
14100 | set: function (val) {
|
14101 | this._interruptable = val;
|
14102 | },
|
14103 | enumerable: false,
|
14104 | configurable: true
|
14105 | });
|
14106 | Object.defineProperty(__proto, "bounce", {
|
14107 | |
14108 |
|
14109 |
|
14110 |
|
14111 |
|
14112 |
|
14113 |
|
14114 |
|
14115 |
|
14116 |
|
14117 |
|
14118 |
|
14119 |
|
14120 |
|
14121 |
|
14122 |
|
14123 |
|
14124 |
|
14125 |
|
14126 |
|
14127 |
|
14128 |
|
14129 |
|
14130 |
|
14131 |
|
14132 |
|
14133 |
|
14134 |
|
14135 |
|
14136 |
|
14137 |
|
14138 | get: function () {
|
14139 | return this._bounce;
|
14140 | },
|
14141 | set: function (val) {
|
14142 | this._bounce = val;
|
14143 | },
|
14144 | enumerable: false,
|
14145 | configurable: true
|
14146 | });
|
14147 | Object.defineProperty(__proto, "iOSEdgeSwipeThreshold", {
|
14148 | |
14149 |
|
14150 |
|
14151 |
|
14152 |
|
14153 |
|
14154 | get: function () {
|
14155 | return this._iOSEdgeSwipeThreshold;
|
14156 | },
|
14157 | set: function (val) {
|
14158 | this._iOSEdgeSwipeThreshold = val;
|
14159 | },
|
14160 | enumerable: false,
|
14161 | configurable: true
|
14162 | });
|
14163 | Object.defineProperty(__proto, "preventClickOnDrag", {
|
14164 | |
14165 |
|
14166 |
|
14167 |
|
14168 |
|
14169 |
|
14170 | get: function () {
|
14171 | return this._preventClickOnDrag;
|
14172 | },
|
14173 | set: function (val) {
|
14174 | var prevVal = this._preventClickOnDrag;
|
14175 | if (val === prevVal) return;
|
14176 | var controller = this._control.controller;
|
14177 |
|
14178 | if (val) {
|
14179 | controller.addPreventClickHandler();
|
14180 | } else {
|
14181 | controller.removePreventClickHandler();
|
14182 | }
|
14183 |
|
14184 | this._preventClickOnDrag = val;
|
14185 | },
|
14186 | enumerable: false,
|
14187 | configurable: true
|
14188 | });
|
14189 | Object.defineProperty(__proto, "disableOnInit", {
|
14190 | |
14191 |
|
14192 |
|
14193 |
|
14194 |
|
14195 |
|
14196 | get: function () {
|
14197 | return this._disableOnInit;
|
14198 | },
|
14199 | set: function (val) {
|
14200 | this._disableOnInit = val;
|
14201 | },
|
14202 | enumerable: false,
|
14203 | configurable: true
|
14204 | });
|
14205 | Object.defineProperty(__proto, "renderOnlyVisible", {
|
14206 |
|
14207 |
|
14208 | |
14209 |
|
14210 |
|
14211 |
|
14212 |
|
14213 |
|
14214 | get: function () {
|
14215 | return this._renderOnlyVisible;
|
14216 | },
|
14217 |
|
14218 | set: function (val) {
|
14219 | this._renderOnlyVisible = val;
|
14220 | },
|
14221 | enumerable: false,
|
14222 | configurable: true
|
14223 | });
|
14224 | Object.defineProperty(__proto, "autoInit", {
|
14225 |
|
14226 |
|
14227 | |
14228 |
|
14229 |
|
14230 |
|
14231 |
|
14232 |
|
14233 |
|
14234 | get: function () {
|
14235 | return this._autoInit;
|
14236 | },
|
14237 | enumerable: false,
|
14238 | configurable: true
|
14239 | });
|
14240 | Object.defineProperty(__proto, "autoResize", {
|
14241 | |
14242 |
|
14243 |
|
14244 |
|
14245 |
|
14246 |
|
14247 |
|
14248 |
|
14249 | get: function () {
|
14250 | return this._autoResize;
|
14251 | },
|
14252 |
|
14253 | set: function (val) {
|
14254 | this._autoResize = val;
|
14255 | },
|
14256 | enumerable: false,
|
14257 | configurable: true
|
14258 | });
|
14259 | Object.defineProperty(__proto, "renderExternal", {
|
14260 | |
14261 |
|
14262 |
|
14263 |
|
14264 |
|
14265 |
|
14266 |
|
14267 |
|
14268 | get: function () {
|
14269 | return this._renderExternal;
|
14270 | },
|
14271 | enumerable: false,
|
14272 | configurable: true
|
14273 | });
|
14274 | |
14275 |
|
14276 |
|
14277 |
|
14278 |
|
14279 |
|
14280 |
|
14281 |
|
14282 |
|
14283 | __proto.init = function () {
|
14284 | return __awaiter(this, void 0, void 0, function () {
|
14285 | var camera, renderer, control, originalTrigger, preventEventsBeforeInit;
|
14286 |
|
14287 | var _this = this;
|
14288 |
|
14289 | return __generator(this, function (_a) {
|
14290 | switch (_a.label) {
|
14291 | case 0:
|
14292 | if (this._initialized) return [2
|
14293 |
|
14294 | ];
|
14295 | camera = this._camera;
|
14296 | renderer = this._renderer;
|
14297 | control = this._control;
|
14298 | originalTrigger = this.trigger;
|
14299 | preventEventsBeforeInit = this._preventEventsBeforeInit;
|
14300 | camera.init(this);
|
14301 | renderer.init(this);
|
14302 | control.init(this);
|
14303 |
|
14304 | if (preventEventsBeforeInit) {
|
14305 | this.trigger = function () {
|
14306 | return _this;
|
14307 | };
|
14308 | }
|
14309 |
|
14310 | return [4
|
14311 |
|
14312 | , this.resize()];
|
14313 |
|
14314 | case 1:
|
14315 | _a.sent();
|
14316 |
|
14317 |
|
14318 | return [4
|
14319 |
|
14320 | , this._moveToInitialPanel()];
|
14321 |
|
14322 | case 2:
|
14323 |
|
14324 | _a.sent();
|
14325 |
|
14326 | if (this._autoResize) {
|
14327 | window.addEventListener("resize", this.resize);
|
14328 | }
|
14329 |
|
14330 | if (this._preventClickOnDrag) {
|
14331 | control.controller.addPreventClickHandler();
|
14332 | }
|
14333 |
|
14334 | if (this._disableOnInit) {
|
14335 | this.disableInput();
|
14336 | }
|
14337 |
|
14338 | renderer.checkPanelContentsReady(renderer.panels);
|
14339 |
|
14340 | this._plugins.forEach(function (plugin) {
|
14341 | return plugin.init(_this);
|
14342 | });
|
14343 |
|
14344 |
|
14345 | this._initialized = true;
|
14346 |
|
14347 | if (preventEventsBeforeInit) {
|
14348 | this.trigger = originalTrigger;
|
14349 | }
|
14350 |
|
14351 | this.trigger(new ComponentEvent$1(EVENTS.READY));
|
14352 | return [2
|
14353 |
|
14354 | ];
|
14355 | }
|
14356 | });
|
14357 | });
|
14358 | };
|
14359 | |
14360 |
|
14361 |
|
14362 |
|
14363 |
|
14364 |
|
14365 |
|
14366 | __proto.destroy = function () {
|
14367 | this.off();
|
14368 | window.removeEventListener("resize", this.resize);
|
14369 |
|
14370 | this._control.destroy();
|
14371 |
|
14372 | this._camera.destroy();
|
14373 |
|
14374 | this._renderer.destroy();
|
14375 |
|
14376 | this._plugins.forEach(function (plugin) {
|
14377 | return plugin.destroy();
|
14378 | });
|
14379 |
|
14380 | this._initialized = false;
|
14381 | };
|
14382 | |
14383 |
|
14384 |
|
14385 |
|
14386 |
|
14387 |
|
14388 |
|
14389 |
|
14390 |
|
14391 |
|
14392 |
|
14393 |
|
14394 |
|
14395 |
|
14396 |
|
14397 |
|
14398 |
|
14399 |
|
14400 |
|
14401 |
|
14402 |
|
14403 |
|
14404 |
|
14405 |
|
14406 |
|
14407 |
|
14408 |
|
14409 |
|
14410 |
|
14411 |
|
14412 |
|
14413 |
|
14414 |
|
14415 |
|
14416 |
|
14417 | __proto.prev = function (duration) {
|
14418 | var _a, _b, _c;
|
14419 |
|
14420 | if (duration === void 0) {
|
14421 | duration = this._duration;
|
14422 | }
|
14423 |
|
14424 | return this.moveTo((_c = (_b = (_a = this._control.activePanel) === null || _a === void 0 ? void 0 : _a.prev()) === null || _b === void 0 ? void 0 : _b.index) !== null && _c !== void 0 ? _c : -1, duration, DIRECTION.PREV);
|
14425 | };
|
14426 | |
14427 |
|
14428 |
|
14429 |
|
14430 |
|
14431 |
|
14432 |
|
14433 |
|
14434 |
|
14435 |
|
14436 |
|
14437 |
|
14438 |
|
14439 |
|
14440 |
|
14441 |
|
14442 |
|
14443 |
|
14444 |
|
14445 |
|
14446 |
|
14447 |
|
14448 |
|
14449 |
|
14450 |
|
14451 |
|
14452 |
|
14453 |
|
14454 |
|
14455 |
|
14456 |
|
14457 |
|
14458 |
|
14459 |
|
14460 |
|
14461 |
|
14462 | __proto.next = function (duration) {
|
14463 | var _a, _b, _c;
|
14464 |
|
14465 | if (duration === void 0) {
|
14466 | duration = this._duration;
|
14467 | }
|
14468 |
|
14469 | return this.moveTo((_c = (_b = (_a = this._control.activePanel) === null || _a === void 0 ? void 0 : _a.next()) === null || _b === void 0 ? void 0 : _b.index) !== null && _c !== void 0 ? _c : this._renderer.panelCount, duration, DIRECTION.NEXT);
|
14470 | };
|
14471 | |
14472 |
|
14473 |
|
14474 |
|
14475 |
|
14476 |
|
14477 |
|
14478 |
|
14479 |
|
14480 |
|
14481 |
|
14482 |
|
14483 |
|
14484 |
|
14485 |
|
14486 |
|
14487 |
|
14488 |
|
14489 |
|
14490 |
|
14491 |
|
14492 |
|
14493 |
|
14494 |
|
14495 |
|
14496 |
|
14497 |
|
14498 |
|
14499 |
|
14500 |
|
14501 |
|
14502 |
|
14503 |
|
14504 |
|
14505 |
|
14506 |
|
14507 |
|
14508 |
|
14509 | __proto.moveTo = function (index, duration, direction) {
|
14510 | if (duration === void 0) {
|
14511 | duration = this._duration;
|
14512 | }
|
14513 |
|
14514 | if (direction === void 0) {
|
14515 | direction = DIRECTION.NONE;
|
14516 | }
|
14517 |
|
14518 | var renderer = this._renderer;
|
14519 | var panelCount = renderer.panelCount;
|
14520 | var panel = renderer.getPanel(index);
|
14521 |
|
14522 | if (!panel) {
|
14523 | return Promise.reject(new FlickingError(MESSAGE.INDEX_OUT_OF_RANGE(index, 0, panelCount - 1), CODE.INDEX_OUT_OF_RANGE));
|
14524 | }
|
14525 |
|
14526 | if (this._control.animating) {
|
14527 | return Promise.reject(new FlickingError(MESSAGE.ANIMATION_ALREADY_PLAYING, CODE.ANIMATION_ALREADY_PLAYING));
|
14528 | }
|
14529 |
|
14530 | return this._control.moveToPanel(panel, {
|
14531 | duration: duration,
|
14532 | direction: direction
|
14533 | });
|
14534 | };
|
14535 | |
14536 |
|
14537 |
|
14538 |
|
14539 |
|
14540 |
|
14541 |
|
14542 |
|
14543 |
|
14544 |
|
14545 |
|
14546 |
|
14547 |
|
14548 |
|
14549 | __proto.getPanel = function (index) {
|
14550 | return this._renderer.getPanel(index);
|
14551 | };
|
14552 | |
14553 |
|
14554 |
|
14555 |
|
14556 |
|
14557 |
|
14558 |
|
14559 | __proto.enableInput = function () {
|
14560 | this._control.enable();
|
14561 |
|
14562 | return this;
|
14563 | };
|
14564 | |
14565 |
|
14566 |
|
14567 |
|
14568 |
|
14569 |
|
14570 |
|
14571 | __proto.disableInput = function () {
|
14572 | this._control.disable();
|
14573 |
|
14574 | return this;
|
14575 | };
|
14576 | |
14577 |
|
14578 |
|
14579 |
|
14580 |
|
14581 |
|
14582 |
|
14583 |
|
14584 |
|
14585 |
|
14586 |
|
14587 |
|
14588 |
|
14589 | __proto.getStatus = function (_a) {
|
14590 | var _b, _c;
|
14591 |
|
14592 | var _d = _a === void 0 ? {} : _a,
|
14593 | _e = _d.index,
|
14594 | index = _e === void 0 ? true : _e,
|
14595 | _f = _d.position,
|
14596 | position = _f === void 0 ? true : _f,
|
14597 | _g = _d.includePanelHTML,
|
14598 | includePanelHTML = _g === void 0 ? false : _g,
|
14599 | _h = _d.visiblePanelsOnly,
|
14600 | visiblePanelsOnly = _h === void 0 ? false : _h;
|
14601 |
|
14602 | var camera = this._camera;
|
14603 | var panels = visiblePanelsOnly ? this.visiblePanels : this.panels;
|
14604 | var status = {
|
14605 | panels: panels.map(function (panel) {
|
14606 | var panelInfo = {
|
14607 | index: panel.index
|
14608 | };
|
14609 |
|
14610 | if (includePanelHTML) {
|
14611 | panelInfo.html = panel.element.outerHTML;
|
14612 | }
|
14613 |
|
14614 | return panelInfo;
|
14615 | })
|
14616 | };
|
14617 |
|
14618 | if (index) {
|
14619 | status.index = this.index;
|
14620 | }
|
14621 |
|
14622 | if (position) {
|
14623 | var nearestAnchor = camera.findNearestAnchor(camera.position);
|
14624 |
|
14625 | if (nearestAnchor) {
|
14626 | status.position = {
|
14627 | panel: nearestAnchor.panel.index,
|
14628 | progressInPanel: camera.getProgressInPanel(nearestAnchor.panel)
|
14629 | };
|
14630 | }
|
14631 | }
|
14632 |
|
14633 | if (visiblePanelsOnly) {
|
14634 | var visiblePanels = this.visiblePanels;
|
14635 | status.visibleOffset = (_c = (_b = visiblePanels[0]) === null || _b === void 0 ? void 0 : _b.index) !== null && _c !== void 0 ? _c : 0;
|
14636 | }
|
14637 |
|
14638 | return status;
|
14639 | };
|
14640 | |
14641 |
|
14642 |
|
14643 |
|
14644 |
|
14645 |
|
14646 |
|
14647 |
|
14648 | __proto.setStatus = function (status) {
|
14649 | var _a;
|
14650 |
|
14651 | if (!this._initialized) {
|
14652 | throw new FlickingError(MESSAGE.NOT_INITIALIZED, CODE.NOT_INITIALIZED);
|
14653 | }
|
14654 |
|
14655 | var index = status.index,
|
14656 | position = status.position,
|
14657 | visibleOffset = status.visibleOffset,
|
14658 | panels = status.panels;
|
14659 | var renderer = this._renderer;
|
14660 | var control = this._control;
|
14661 |
|
14662 | if (((_a = panels[0]) === null || _a === void 0 ? void 0 : _a.html) && !this._renderExternal) {
|
14663 | renderer.batchRemove({
|
14664 | index: 0,
|
14665 | deleteCount: this.panels.length
|
14666 | });
|
14667 | renderer.batchInsert({
|
14668 | index: 0,
|
14669 | elements: parseElement(panels.map(function (panel) {
|
14670 | return panel.html;
|
14671 | }))
|
14672 | });
|
14673 | }
|
14674 |
|
14675 | if (index) {
|
14676 | var panelIndex = visibleOffset ? index - visibleOffset : index;
|
14677 | void this.moveTo(panelIndex, 0).catch(function () {
|
14678 | return void 0;
|
14679 | });
|
14680 | }
|
14681 |
|
14682 | if (position && this._moveType === MOVE_TYPE.FREE_SCROLL) {
|
14683 | var panel = position.panel,
|
14684 | progressInPanel = position.progressInPanel;
|
14685 | var panelIndex = visibleOffset ? panel - visibleOffset : panel;
|
14686 | var panelRange = renderer.panels[panelIndex].range;
|
14687 | var newCameraPos = panelRange.min + (panelRange.max - panelRange.min) * progressInPanel;
|
14688 | void control.moveToPosition(newCameraPos, 0).catch(function () {
|
14689 | return void 0;
|
14690 | });
|
14691 | }
|
14692 | };
|
14693 | |
14694 |
|
14695 |
|
14696 |
|
14697 |
|
14698 |
|
14699 |
|
14700 |
|
14701 |
|
14702 | __proto.addPlugins = function () {
|
14703 | var _a;
|
14704 |
|
14705 | var _this = this;
|
14706 |
|
14707 | var plugins = [];
|
14708 |
|
14709 | for (var _i = 0; _i < arguments.length; _i++) {
|
14710 | plugins[_i] = arguments[_i];
|
14711 | }
|
14712 |
|
14713 | if (this._initialized) {
|
14714 | plugins.forEach(function (item) {
|
14715 | return item.init(_this);
|
14716 | });
|
14717 | }
|
14718 |
|
14719 | (_a = this._plugins).push.apply(_a, __spreadArray([], __read$1(plugins)));
|
14720 |
|
14721 | return this;
|
14722 | };
|
14723 | |
14724 |
|
14725 |
|
14726 |
|
14727 |
|
14728 |
|
14729 |
|
14730 |
|
14731 |
|
14732 | __proto.removePlugins = function () {
|
14733 | var _this = this;
|
14734 |
|
14735 | var plugins = [];
|
14736 |
|
14737 | for (var _i = 0; _i < arguments.length; _i++) {
|
14738 | plugins[_i] = arguments[_i];
|
14739 | }
|
14740 |
|
14741 | plugins.forEach(function (item) {
|
14742 | var foundIndex = findIndex(_this._plugins, function (val) {
|
14743 | return val === item;
|
14744 | });
|
14745 |
|
14746 | if (foundIndex >= 0) {
|
14747 | item.destroy();
|
14748 |
|
14749 | _this._plugins.splice(foundIndex, 1);
|
14750 | }
|
14751 | });
|
14752 | return this;
|
14753 | };
|
14754 | |
14755 |
|
14756 |
|
14757 |
|
14758 |
|
14759 |
|
14760 |
|
14761 |
|
14762 |
|
14763 |
|
14764 | __proto.resize = function () {
|
14765 | return __awaiter(this, void 0, void 0, function () {
|
14766 | var viewport, renderer, camera, control, activePanel, prevWidth, prevHeight, prevProgressInPanel, newWidth, newHeight, sizeChanged;
|
14767 | return __generator(this, function (_a) {
|
14768 | switch (_a.label) {
|
14769 | case 0:
|
14770 | viewport = this._viewport;
|
14771 | renderer = this._renderer;
|
14772 | camera = this._camera;
|
14773 | control = this._control;
|
14774 | activePanel = control.activePanel;
|
14775 | prevWidth = viewport.width;
|
14776 | prevHeight = viewport.height;
|
14777 | prevProgressInPanel = activePanel ? camera.getProgressInPanel(activePanel) : 0;
|
14778 | this.trigger(new ComponentEvent$1(EVENTS.BEFORE_RESIZE, {
|
14779 | width: prevWidth,
|
14780 | height: prevHeight,
|
14781 | element: viewport.element
|
14782 | }));
|
14783 | viewport.resize();
|
14784 | return [4
|
14785 |
|
14786 | , renderer.forceRenderAllPanels()];
|
14787 |
|
14788 | case 1:
|
14789 | _a.sent();
|
14790 |
|
14791 |
|
14792 | renderer.updatePanelSize();
|
14793 | camera.updateAlignPos();
|
14794 | camera.updateRange();
|
14795 | camera.updateAnchors();
|
14796 | return [4
|
14797 |
|
14798 | , renderer.render()];
|
14799 |
|
14800 | case 2:
|
14801 | _a.sent();
|
14802 |
|
14803 | if (control.animating) ; else {
|
14804 | control.updatePosition(prevProgressInPanel);
|
14805 | control.updateInput();
|
14806 | }
|
14807 |
|
14808 | newWidth = viewport.width;
|
14809 | newHeight = viewport.height;
|
14810 | sizeChanged = newWidth !== prevWidth || newHeight !== prevHeight;
|
14811 | this.trigger(new ComponentEvent$1(EVENTS.AFTER_RESIZE, {
|
14812 | width: viewport.width,
|
14813 | height: viewport.height,
|
14814 | prev: {
|
14815 | width: prevWidth,
|
14816 | height: prevHeight
|
14817 | },
|
14818 | sizeChanged: sizeChanged,
|
14819 | element: viewport.element
|
14820 | }));
|
14821 | return [2
|
14822 |
|
14823 | ];
|
14824 | }
|
14825 | });
|
14826 | });
|
14827 | };
|
14828 | |
14829 |
|
14830 |
|
14831 |
|
14832 |
|
14833 |
|
14834 |
|
14835 |
|
14836 |
|
14837 |
|
14838 |
|
14839 |
|
14840 |
|
14841 |
|
14842 |
|
14843 |
|
14844 |
|
14845 |
|
14846 |
|
14847 |
|
14848 |
|
14849 |
|
14850 | __proto.append = function (element) {
|
14851 | return this.insert(this._renderer.panelCount, element);
|
14852 | };
|
14853 | |
14854 |
|
14855 |
|
14856 |
|
14857 |
|
14858 |
|
14859 |
|
14860 |
|
14861 |
|
14862 |
|
14863 |
|
14864 |
|
14865 |
|
14866 |
|
14867 |
|
14868 |
|
14869 |
|
14870 |
|
14871 |
|
14872 |
|
14873 |
|
14874 |
|
14875 |
|
14876 | __proto.prepend = function (element) {
|
14877 | return this.insert(0, element);
|
14878 | };
|
14879 | |
14880 |
|
14881 |
|
14882 |
|
14883 |
|
14884 |
|
14885 |
|
14886 |
|
14887 |
|
14888 |
|
14889 |
|
14890 |
|
14891 |
|
14892 |
|
14893 |
|
14894 |
|
14895 |
|
14896 |
|
14897 |
|
14898 |
|
14899 |
|
14900 |
|
14901 | __proto.insert = function (index, element) {
|
14902 | if (this._renderExternal) {
|
14903 | throw new FlickingError(MESSAGE.NOT_ALLOWED_IN_FRAMEWORK, CODE.NOT_ALLOWED_IN_FRAMEWORK);
|
14904 | }
|
14905 |
|
14906 | return this._renderer.batchInsert({
|
14907 | index: index,
|
14908 | elements: parseElement(element)
|
14909 | });
|
14910 | };
|
14911 | |
14912 |
|
14913 |
|
14914 |
|
14915 |
|
14916 |
|
14917 |
|
14918 |
|
14919 |
|
14920 |
|
14921 |
|
14922 | __proto.remove = function (index, deleteCount) {
|
14923 | if (deleteCount === void 0) {
|
14924 | deleteCount = 1;
|
14925 | }
|
14926 |
|
14927 | if (this._renderExternal) {
|
14928 | throw new FlickingError(MESSAGE.NOT_ALLOWED_IN_FRAMEWORK, CODE.NOT_ALLOWED_IN_FRAMEWORK);
|
14929 | }
|
14930 |
|
14931 | return this._renderer.batchRemove({
|
14932 | index: index,
|
14933 | deleteCount: deleteCount
|
14934 | });
|
14935 | };
|
14936 |
|
14937 | __proto._createControl = function () {
|
14938 | var _a;
|
14939 |
|
14940 | var moveType = this._moveType;
|
14941 | var moveTypes = Object.keys(MOVE_TYPE).map(function (key) {
|
14942 | return MOVE_TYPE[key];
|
14943 | });
|
14944 | var moveTypeStr = Array.isArray(moveType) ? moveType[0] : moveType;
|
14945 | var moveTypeOptions = Array.isArray(moveType) ? (_a = moveType[1]) !== null && _a !== void 0 ? _a : {} : {};
|
14946 |
|
14947 | if (!includes(moveTypes, moveTypeStr)) {
|
14948 | throw new FlickingError(MESSAGE.WRONG_OPTION("moveType", JSON.stringify(moveType)), CODE.WRONG_OPTION);
|
14949 | }
|
14950 |
|
14951 | switch (moveTypeStr) {
|
14952 | case MOVE_TYPE.SNAP:
|
14953 | return new SnapControl(moveTypeOptions);
|
14954 |
|
14955 | case MOVE_TYPE.FREE_SCROLL:
|
14956 | return new FreeControl(moveTypeOptions);
|
14957 |
|
14958 | case MOVE_TYPE.STRICT:
|
14959 | return new StrictControl(moveTypeOptions);
|
14960 | }
|
14961 | };
|
14962 |
|
14963 | __proto._createCamera = function () {
|
14964 | var cameraOption = {
|
14965 | align: this._align
|
14966 | };
|
14967 |
|
14968 | if (this._circular) {
|
14969 | if (this._bound) {
|
14970 |
|
14971 | console.warn("\"circular\" and \"bound\" option cannot be used together, ignoring bound.");
|
14972 | }
|
14973 |
|
14974 | return new CircularCamera(cameraOption);
|
14975 | } else if (this._bound) {
|
14976 | return new BoundCamera(cameraOption);
|
14977 | } else {
|
14978 | return new LinearCamera(cameraOption);
|
14979 | }
|
14980 | };
|
14981 |
|
14982 | __proto._createRenderer = function () {
|
14983 | var rendererOptions = {
|
14984 | align: this._align
|
14985 | };
|
14986 | var renderExternal = this._renderExternal;
|
14987 | return renderExternal ? new renderExternal.renderer(__assign$2(__assign$2({}, rendererOptions), renderExternal.rendererOptions)) : new VanillaRenderer(rendererOptions);
|
14988 | };
|
14989 |
|
14990 | __proto._moveToInitialPanel = function () {
|
14991 | return __awaiter(this, void 0, void 0, function () {
|
14992 | var renderer, control, initialPanel;
|
14993 | return __generator(this, function (_a) {
|
14994 | renderer = this._renderer;
|
14995 | control = this._control;
|
14996 | initialPanel = renderer.getPanel(this._defaultIndex) || renderer.getPanel(0);
|
14997 | if (!initialPanel) return [2
|
14998 |
|
14999 | ];
|
15000 | control.setActive(initialPanel, null, false);
|
15001 | return [2
|
15002 |
|
15003 | , control.moveToPanel(initialPanel, {
|
15004 | duration: 0
|
15005 | })];
|
15006 | });
|
15007 | });
|
15008 | };
|
15009 | |
15010 |
|
15011 |
|
15012 |
|
15013 |
|
15014 |
|
15015 |
|
15016 |
|
15017 |
|
15018 |
|
15019 |
|
15020 |
|
15021 | Flicking.VERSION = "4.3.0";
|
15022 | return Flicking;
|
15023 | }(Component$2);
|
15024 |
|
15025 | |
15026 |
|
15027 |
|
15028 |
|
15029 |
|
15030 | var ExternalPanel = function (_super) {
|
15031 | __extends$2(ExternalPanel, _super);
|
15032 | |
15033 |
|
15034 |
|
15035 |
|
15036 |
|
15037 |
|
15038 |
|
15039 |
|
15040 |
|
15041 | function ExternalPanel(options) {
|
15042 | var _this = _super.call(this, options) || this;
|
15043 |
|
15044 | _this._externalComponent = options.externalComponent;
|
15045 | return _this;
|
15046 | }
|
15047 |
|
15048 | return ExternalPanel;
|
15049 | }(Panel);
|
15050 |
|
15051 | |
15052 |
|
15053 |
|
15054 |
|
15055 |
|
15056 | var Core = {
|
15057 | __proto__: null,
|
15058 | Viewport: Viewport,
|
15059 | FlickingError: FlickingError,
|
15060 | AnchorPoint: AnchorPoint,
|
15061 | Panel: Panel,
|
15062 | ElementPanel: ElementPanel,
|
15063 | ExternalPanel: ExternalPanel
|
15064 | };
|
15065 |
|
15066 | |
15067 |
|
15068 |
|
15069 |
|
15070 |
|
15071 |
|
15072 |
|
15073 |
|
15074 |
|
15075 |
|
15076 |
|
15077 |
|
15078 |
|
15079 |
|
15080 |
|
15081 |
|
15082 | var withFlickingMethods = function (prototype, flickingName) {
|
15083 | [Component$2.prototype, Flicking.prototype].forEach(function (proto) {
|
15084 | Object.getOwnPropertyNames(proto).filter(function (name) {
|
15085 | return !prototype[name] && !name.startsWith("_") && name !== "constructor";
|
15086 | }).forEach(function (name) {
|
15087 | var descriptor = Object.getOwnPropertyDescriptor(proto, name);
|
15088 |
|
15089 | if (descriptor.value) {
|
15090 |
|
15091 | Object.defineProperty(prototype, name, {
|
15092 | value: function () {
|
15093 | var _a;
|
15094 |
|
15095 | var args = [];
|
15096 |
|
15097 | for (var _i = 0; _i < arguments.length; _i++) {
|
15098 | args[_i] = arguments[_i];
|
15099 | }
|
15100 |
|
15101 | return (_a = descriptor.value).call.apply(_a, __spreadArray([this[flickingName]], __read$1(args)));
|
15102 | }
|
15103 | });
|
15104 | } else {
|
15105 | var getterDescriptor = {};
|
15106 |
|
15107 | if (descriptor.get) {
|
15108 | getterDescriptor.get = function () {
|
15109 | var _a;
|
15110 |
|
15111 | return (_a = descriptor.get) === null || _a === void 0 ? void 0 : _a.call(this[flickingName]);
|
15112 | };
|
15113 | }
|
15114 |
|
15115 | if (descriptor.set) {
|
15116 | getterDescriptor.set = function () {
|
15117 | var _a;
|
15118 |
|
15119 | var args = [];
|
15120 |
|
15121 | for (var _i = 0; _i < arguments.length; _i++) {
|
15122 | args[_i] = arguments[_i];
|
15123 | }
|
15124 |
|
15125 | return (_a = descriptor.set) === null || _a === void 0 ? void 0 : _a.call.apply(_a, __spreadArray([this[flickingName]], __read$1(args)));
|
15126 | };
|
15127 | }
|
15128 |
|
15129 | Object.defineProperty(prototype, name, getterDescriptor);
|
15130 | }
|
15131 | });
|
15132 | });
|
15133 | };
|
15134 |
|
15135 | var sync = (function (flicking, diffResult, rendered) {
|
15136 | var renderer = flicking.renderer;
|
15137 | var panels = renderer.panels;
|
15138 |
|
15139 | if (diffResult.removed.length > 0) {
|
15140 | var endIdx_1 = -1;
|
15141 | var prevIdx_1 = -1;
|
15142 | diffResult.removed.forEach(function (removedIdx) {
|
15143 | if (endIdx_1 < 0) {
|
15144 | endIdx_1 = removedIdx;
|
15145 | }
|
15146 |
|
15147 | if (prevIdx_1 >= 0 && removedIdx !== prevIdx_1 - 1) {
|
15148 | batchRemove(renderer, prevIdx_1, endIdx_1 + 1);
|
15149 | endIdx_1 = removedIdx;
|
15150 | prevIdx_1 = removedIdx;
|
15151 | } else {
|
15152 | prevIdx_1 = removedIdx;
|
15153 | }
|
15154 | });
|
15155 | batchRemove(renderer, prevIdx_1, endIdx_1 + 1);
|
15156 | }
|
15157 |
|
15158 | diffResult.ordered.forEach(function (_a) {
|
15159 | var _b = __read$1(_a, 2),
|
15160 | prevIdx = _b[0],
|
15161 | newIdx = _b[1];
|
15162 |
|
15163 | var prevPanel = panels[prevIdx];
|
15164 | var indexDiff = newIdx - prevIdx;
|
15165 |
|
15166 | if (indexDiff > 0) {
|
15167 | var middlePanels = panels.slice(prevIdx + 1, newIdx + 1);
|
15168 | prevPanel.increaseIndex(indexDiff);
|
15169 | middlePanels.forEach(function (panel) {
|
15170 | return panel.decreaseIndex(1);
|
15171 | });
|
15172 | } else {
|
15173 | var middlePanels = panels.slice(newIdx, prevIdx);
|
15174 | prevPanel.decreaseIndex(-indexDiff);
|
15175 | middlePanels.forEach(function (panel) {
|
15176 | return panel.increaseIndex(1);
|
15177 | });
|
15178 | }
|
15179 |
|
15180 |
|
15181 | prevPanel.resize();
|
15182 | });
|
15183 |
|
15184 | if (diffResult.ordered.length > 0) {
|
15185 | panels.sort(function (panel1, panel2) {
|
15186 | return panel1.index - panel2.index;
|
15187 | });
|
15188 | }
|
15189 |
|
15190 | if (diffResult.added.length > 0) {
|
15191 | var startIdx_1 = -1;
|
15192 | var prevIdx_2 = -1;
|
15193 | diffResult.added.forEach(function (addedIdx, idx) {
|
15194 | if (startIdx_1 < 0) {
|
15195 | startIdx_1 = idx;
|
15196 | }
|
15197 |
|
15198 | if (prevIdx_2 >= 0 && addedIdx !== prevIdx_2 + 1) {
|
15199 | batchInsert(renderer, diffResult, rendered, startIdx_1, idx + 1);
|
15200 | startIdx_1 = -1;
|
15201 | prevIdx_2 = -1;
|
15202 | } else {
|
15203 | prevIdx_2 = addedIdx;
|
15204 | }
|
15205 | });
|
15206 |
|
15207 | if (startIdx_1 >= 0) {
|
15208 | batchInsert(renderer, diffResult, rendered, startIdx_1);
|
15209 | }
|
15210 | }
|
15211 | });
|
15212 |
|
15213 | var batchInsert = function (renderer, diffResult, rendered, startIdx, endIdx) {
|
15214 | renderer.batchInsert.apply(renderer, __spreadArray([], __read$1(diffResult.added.slice(startIdx, endIdx).map(function (index, elIdx) {
|
15215 | return {
|
15216 | index: index,
|
15217 | elements: [rendered[elIdx + diffResult.prevList.length]]
|
15218 | };
|
15219 | }))));
|
15220 | };
|
15221 |
|
15222 | var batchRemove = function (renderer, startIdx, endIdx) {
|
15223 | var removed = renderer.panels.slice(startIdx, endIdx);
|
15224 | renderer.batchRemove({
|
15225 | index: startIdx,
|
15226 | deleteCount: removed.length
|
15227 | });
|
15228 | };
|
15229 |
|
15230 | var getRenderingPanels = (function (flicking, diffResult) {
|
15231 | var removedPanels = diffResult.removed.reduce(function (map, idx) {
|
15232 | map[idx] = true;
|
15233 | return map;
|
15234 | }, {});
|
15235 | var maintainedMap = diffResult.maintained.reduce(function (map, _a) {
|
15236 | var _b = __read$1(_a, 2),
|
15237 | prev = _b[0],
|
15238 | current = _b[1];
|
15239 |
|
15240 | map[prev] = current;
|
15241 | return map;
|
15242 | }, {});
|
15243 | return __spreadArray(__spreadArray([], __read$1(flicking.panels.filter(function (panel) {
|
15244 | return !removedPanels[panel.index];
|
15245 | })
|
15246 | .sort(function (panel1, panel2) {
|
15247 | return panel1.position + panel1.offset - (panel2.position + panel2.offset);
|
15248 | }).map(function (panel) {
|
15249 | return diffResult.list[maintainedMap[panel.index]];
|
15250 | }))), __read$1(diffResult.added.map(function (idx) {
|
15251 | return diffResult.list[idx];
|
15252 | })));
|
15253 | });
|
15254 |
|
15255 | var getDefaultCameraTransform = (function (align, horizontal, firstPanelSize) {
|
15256 | if (align === void 0) {
|
15257 | align = ALIGN.CENTER;
|
15258 | }
|
15259 |
|
15260 | if (horizontal === void 0) {
|
15261 | horizontal = true;
|
15262 | }
|
15263 |
|
15264 | var cameraAlign = getCameraAlign(align);
|
15265 | var panelAlign = getPanelAlign(align);
|
15266 | if (panelAlign == null) return "";
|
15267 | var camPosition = "calc(" + cameraAlign + " - (" + (firstPanelSize || "0px") + " * " + panelAlign.percentage + ") - " + panelAlign.absolute + "px)";
|
15268 | return horizontal ? "translate(" + camPosition + ")" : "translate(0, " + camPosition + ")";
|
15269 | });
|
15270 |
|
15271 | var getCameraAlign = function (align) {
|
15272 | var alignVal = typeof align === "object" ? align.camera : align;
|
15273 | return parseAlign(alignVal);
|
15274 | };
|
15275 |
|
15276 | var getPanelAlign = function (align) {
|
15277 | var alignVal = typeof align === "object" ? align.panel : align;
|
15278 | return parseArithmeticExpression(parseAlign(alignVal));
|
15279 | };
|
15280 |
|
15281 | var parseAlign = function (alignVal) {
|
15282 | if (typeof alignVal === "number") {
|
15283 | return alignVal + "px";
|
15284 | }
|
15285 |
|
15286 | switch (alignVal) {
|
15287 | case ALIGN.CENTER:
|
15288 | return "50%";
|
15289 |
|
15290 | case ALIGN.NEXT:
|
15291 | return "100%";
|
15292 |
|
15293 | case ALIGN.PREV:
|
15294 | return "0%";
|
15295 |
|
15296 | default:
|
15297 | return alignVal;
|
15298 | }
|
15299 | };
|
15300 |
|
15301 | var CFC = {
|
15302 | __proto__: null,
|
15303 | withFlickingMethods: withFlickingMethods,
|
15304 | sync: sync,
|
15305 | getRenderingPanels: getRenderingPanels,
|
15306 | getDefaultCameraTransform: getDefaultCameraTransform
|
15307 | };
|
15308 |
|
15309 | |
15310 |
|
15311 |
|
15312 |
|
15313 | merge$1(Flicking, Core);
|
15314 | merge$1(Flicking, Camera);
|
15315 | merge$1(Flicking, Control);
|
15316 | merge$1(Flicking, Renderer);
|
15317 | merge$1(Flicking, Constants);
|
15318 | merge$1(Flicking, CFC);
|
15319 |
|
15320 | return Flicking;
|
15321 |
|
15322 | })));
|
15323 |
|