1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | import Component, { ComponentEvent } from '@egjs/component';
|
10 | import Axes, { PanInput } from '@egjs/axes';
|
11 | import ImReady from '@egjs/imready';
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | var extendStatics = function (d, b) {
|
30 | extendStatics = Object.setPrototypeOf || {
|
31 | __proto__: []
|
32 | } instanceof Array && function (d, b) {
|
33 | d.__proto__ = b;
|
34 | } || function (d, b) {
|
35 | for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
36 | };
|
37 |
|
38 | return extendStatics(d, b);
|
39 | };
|
40 |
|
41 | function __extends(d, b) {
|
42 | if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
43 | extendStatics(d, b);
|
44 |
|
45 | function __() {
|
46 | this.constructor = d;
|
47 | }
|
48 |
|
49 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
50 | }
|
51 | var __assign = function () {
|
52 | __assign = Object.assign || function __assign(t) {
|
53 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
54 | s = arguments[i];
|
55 |
|
56 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
57 | }
|
58 |
|
59 | return t;
|
60 | };
|
61 |
|
62 | return __assign.apply(this, arguments);
|
63 | };
|
64 | function __awaiter(thisArg, _arguments, P, generator) {
|
65 | function adopt(value) {
|
66 | return value instanceof P ? value : new P(function (resolve) {
|
67 | resolve(value);
|
68 | });
|
69 | }
|
70 |
|
71 | return new (P || (P = Promise))(function (resolve, reject) {
|
72 | function fulfilled(value) {
|
73 | try {
|
74 | step(generator.next(value));
|
75 | } catch (e) {
|
76 | reject(e);
|
77 | }
|
78 | }
|
79 |
|
80 | function rejected(value) {
|
81 | try {
|
82 | step(generator["throw"](value));
|
83 | } catch (e) {
|
84 | reject(e);
|
85 | }
|
86 | }
|
87 |
|
88 | function step(result) {
|
89 | result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
90 | }
|
91 |
|
92 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
93 | });
|
94 | }
|
95 | function __generator(thisArg, body) {
|
96 | var _ = {
|
97 | label: 0,
|
98 | sent: function () {
|
99 | if (t[0] & 1) throw t[1];
|
100 | return t[1];
|
101 | },
|
102 | trys: [],
|
103 | ops: []
|
104 | },
|
105 | f,
|
106 | y,
|
107 | t,
|
108 | g;
|
109 | return g = {
|
110 | next: verb(0),
|
111 | "throw": verb(1),
|
112 | "return": verb(2)
|
113 | }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
114 | return this;
|
115 | }), g;
|
116 |
|
117 | function verb(n) {
|
118 | return function (v) {
|
119 | return step([n, v]);
|
120 | };
|
121 | }
|
122 |
|
123 | function step(op) {
|
124 | if (f) throw new TypeError("Generator is already executing.");
|
125 |
|
126 | while (_) try {
|
127 | 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;
|
128 | if (y = 0, t) op = [op[0] & 2, t.value];
|
129 |
|
130 | switch (op[0]) {
|
131 | case 0:
|
132 | case 1:
|
133 | t = op;
|
134 | break;
|
135 |
|
136 | case 4:
|
137 | _.label++;
|
138 | return {
|
139 | value: op[1],
|
140 | done: false
|
141 | };
|
142 |
|
143 | case 5:
|
144 | _.label++;
|
145 | y = op[1];
|
146 | op = [0];
|
147 | continue;
|
148 |
|
149 | case 7:
|
150 | op = _.ops.pop();
|
151 |
|
152 | _.trys.pop();
|
153 |
|
154 | continue;
|
155 |
|
156 | default:
|
157 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
158 | _ = 0;
|
159 | continue;
|
160 | }
|
161 |
|
162 | if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
163 | _.label = op[1];
|
164 | break;
|
165 | }
|
166 |
|
167 | if (op[0] === 6 && _.label < t[1]) {
|
168 | _.label = t[1];
|
169 | t = op;
|
170 | break;
|
171 | }
|
172 |
|
173 | if (t && _.label < t[2]) {
|
174 | _.label = t[2];
|
175 |
|
176 | _.ops.push(op);
|
177 |
|
178 | break;
|
179 | }
|
180 |
|
181 | if (t[2]) _.ops.pop();
|
182 |
|
183 | _.trys.pop();
|
184 |
|
185 | continue;
|
186 | }
|
187 |
|
188 | op = body.call(thisArg, _);
|
189 | } catch (e) {
|
190 | op = [6, e];
|
191 | y = 0;
|
192 | } finally {
|
193 | f = t = 0;
|
194 | }
|
195 |
|
196 | if (op[0] & 5) throw op[1];
|
197 | return {
|
198 | value: op[0] ? op[1] : void 0,
|
199 | done: true
|
200 | };
|
201 | }
|
202 | }
|
203 | function __values(o) {
|
204 | var s = typeof Symbol === "function" && Symbol.iterator,
|
205 | m = s && o[s],
|
206 | i = 0;
|
207 | if (m) return m.call(o);
|
208 | if (o && typeof o.length === "number") return {
|
209 | next: function () {
|
210 | if (o && i >= o.length) o = void 0;
|
211 | return {
|
212 | value: o && o[i++],
|
213 | done: !o
|
214 | };
|
215 | }
|
216 | };
|
217 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
218 | }
|
219 | function __read(o, n) {
|
220 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
221 | if (!m) return o;
|
222 | var i = m.call(o),
|
223 | r,
|
224 | ar = [],
|
225 | e;
|
226 |
|
227 | try {
|
228 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
229 | } catch (error) {
|
230 | e = {
|
231 | error: error
|
232 | };
|
233 | } finally {
|
234 | try {
|
235 | if (r && !r.done && (m = i["return"])) m.call(i);
|
236 | } finally {
|
237 | if (e) throw e.error;
|
238 | }
|
239 | }
|
240 |
|
241 | return ar;
|
242 | }
|
243 | function __spreadArray(to, from) {
|
244 | for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i];
|
245 |
|
246 | return to;
|
247 | }
|
248 |
|
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 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 | var CODE = {
|
279 | WRONG_TYPE: 0,
|
280 | ELEMENT_NOT_FOUND: 1,
|
281 | VAL_MUST_NOT_NULL: 2,
|
282 | NOT_ATTACHED_TO_FLICKING: 3,
|
283 | WRONG_OPTION: 4,
|
284 | INDEX_OUT_OF_RANGE: 5,
|
285 | POSITION_NOT_REACHABLE: 6,
|
286 | TRANSFORM_NOT_SUPPORTED: 7,
|
287 | STOP_CALLED_BY_USER: 8,
|
288 | ANIMATION_INTERRUPTED: 9,
|
289 | ANIMATION_ALREADY_PLAYING: 10,
|
290 | NOT_ALLOWED_IN_FRAMEWORK: 11,
|
291 | NOT_INITIALIZED: 12,
|
292 | NO_ACTIVE: 13
|
293 | };
|
294 | var MESSAGE = {
|
295 | WRONG_TYPE: function (wrongVal, correctTypes) {
|
296 | return wrongVal + "(" + typeof wrongVal + ") is not a " + correctTypes.map(function (type) {
|
297 | return "\"" + type + "\"";
|
298 | }).join(" or ") + ".";
|
299 | },
|
300 | ELEMENT_NOT_FOUND: function (selector) {
|
301 | return "Element with selector \"" + selector + "\" not found.";
|
302 | },
|
303 | VAL_MUST_NOT_NULL: function (val, name) {
|
304 | return name + " should be provided. Given: " + val;
|
305 | },
|
306 | NOT_ATTACHED_TO_FLICKING: function (name) {
|
307 | return name + " is not attached to the Flicking instance. \"init()\" should be called first.";
|
308 | },
|
309 | WRONG_OPTION: function (optionName, val) {
|
310 | return "Option \"" + optionName + "\" is not in correct format, given: " + val;
|
311 | },
|
312 | INDEX_OUT_OF_RANGE: function (val, min, max) {
|
313 | return "Index \"" + val + "\" is out of range: should be between " + min + " and " + max + ".";
|
314 | },
|
315 | POSITION_NOT_REACHABLE: function (position) {
|
316 | return "Position \"" + position + "\" is not reachable.";
|
317 | },
|
318 | TRANSFORM_NOT_SUPPORTED: "Browser does not support CSS transform.",
|
319 | STOP_CALLED_BY_USER: "Event stop() is called by user.",
|
320 | ANIMATION_INTERRUPTED: "Animation is interrupted by user input.",
|
321 | ANIMATION_ALREADY_PLAYING: "Animation is already playing.",
|
322 | NOT_ALLOWED_IN_FRAMEWORK: "This behavior is not allowed in the frameworks like React, Vue, or Angular.",
|
323 | NOT_INITIALIZED: "Flicking is not initialized yet, call init() first.",
|
324 | NO_ACTIVE: "There's no active panel that Flicking has selected. This may be due to the absence of any panels."
|
325 | };
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 | var EVENTS = {
|
355 | READY: "ready",
|
356 | BEFORE_RESIZE: "beforeResize",
|
357 | AFTER_RESIZE: "afterResize",
|
358 | HOLD_START: "holdStart",
|
359 | HOLD_END: "holdEnd",
|
360 | MOVE_START: "moveStart",
|
361 | MOVE: "move",
|
362 | MOVE_END: "moveEnd",
|
363 | WILL_CHANGE: "willChange",
|
364 | CHANGED: "changed",
|
365 | WILL_RESTORE: "willRestore",
|
366 | RESTORED: "restored",
|
367 | SELECT: "select",
|
368 | NEED_PANEL: "needPanel",
|
369 | VISIBLE_CHANGE: "visibleChange",
|
370 | REACH_EDGE: "reachEdge",
|
371 | PANEL_CHANGE: "panelChange"
|
372 | };
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 | var ALIGN = {
|
383 | PREV: "prev",
|
384 | CENTER: "center",
|
385 | NEXT: "next"
|
386 | };
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 | var DIRECTION = {
|
399 | PREV: "PREV",
|
400 | NEXT: "NEXT",
|
401 | NONE: null
|
402 | };
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 | var MOVE_TYPE = {
|
416 | SNAP: "snap",
|
417 | FREE_SCROLL: "freeScroll",
|
418 | STRICT: "strict"
|
419 | };
|
420 |
|
421 | var getElement = function (el, parent) {
|
422 | var targetEl = null;
|
423 |
|
424 | if (isString(el)) {
|
425 | var parentEl = parent ? parent : document;
|
426 | var queryResult = parentEl.querySelector(el);
|
427 |
|
428 | if (!queryResult) {
|
429 | throw new FlickingError(MESSAGE.ELEMENT_NOT_FOUND(el), CODE.ELEMENT_NOT_FOUND);
|
430 | }
|
431 |
|
432 | targetEl = queryResult;
|
433 | } else if (el && el.nodeType === Node.ELEMENT_NODE) {
|
434 | targetEl = el;
|
435 | }
|
436 |
|
437 | if (!targetEl) {
|
438 | throw new FlickingError(MESSAGE.WRONG_TYPE(el, ["HTMLElement", "string"]), CODE.WRONG_TYPE);
|
439 | }
|
440 |
|
441 | return targetEl;
|
442 | };
|
443 | var checkExistence = function (value, nameOnErrMsg) {
|
444 | if (value == null) {
|
445 | throw new FlickingError(MESSAGE.VAL_MUST_NOT_NULL(value, nameOnErrMsg), CODE.VAL_MUST_NOT_NULL);
|
446 | }
|
447 | };
|
448 | var clamp = function (x, min, max) {
|
449 | return Math.max(Math.min(x, max), min);
|
450 | };
|
451 | var getFlickingAttached = function (val, nameToThrowOnError) {
|
452 | if (!val) {
|
453 | throw new FlickingError(MESSAGE.NOT_ATTACHED_TO_FLICKING(nameToThrowOnError), CODE.NOT_ATTACHED_TO_FLICKING);
|
454 | }
|
455 |
|
456 | return val;
|
457 | };
|
458 | var toArray = function (iterable) {
|
459 | return [].slice.call(iterable);
|
460 | };
|
461 | var parseAlign$1 = function (align, size) {
|
462 | var alignPoint;
|
463 |
|
464 | if (isString(align)) {
|
465 | switch (align) {
|
466 | case ALIGN.PREV:
|
467 | alignPoint = 0;
|
468 | break;
|
469 |
|
470 | case ALIGN.CENTER:
|
471 | alignPoint = 0.5 * size;
|
472 | break;
|
473 |
|
474 | case ALIGN.NEXT:
|
475 | alignPoint = size;
|
476 | break;
|
477 |
|
478 | default:
|
479 | alignPoint = parseArithmeticSize(align, size);
|
480 |
|
481 | if (alignPoint == null) {
|
482 | throw new FlickingError(MESSAGE.WRONG_OPTION("align", align), CODE.WRONG_OPTION);
|
483 | }
|
484 |
|
485 | }
|
486 | } else {
|
487 | alignPoint = align;
|
488 | }
|
489 |
|
490 | return alignPoint;
|
491 | };
|
492 | var parseBounce = function (bounce, size) {
|
493 | var parsedBounce;
|
494 |
|
495 | if (Array.isArray(bounce)) {
|
496 | parsedBounce = bounce.map(function (val) {
|
497 | return parseArithmeticSize(val, size);
|
498 | });
|
499 | } else {
|
500 | var parsedVal = parseArithmeticSize(bounce, size);
|
501 | parsedBounce = [parsedVal, parsedVal];
|
502 | }
|
503 |
|
504 | return parsedBounce.map(function (val) {
|
505 | if (val == null) {
|
506 | throw new FlickingError(MESSAGE.WRONG_OPTION("bounce", bounce), CODE.WRONG_OPTION);
|
507 | }
|
508 |
|
509 | return val;
|
510 | });
|
511 | };
|
512 | var parseArithmeticSize = function (cssValue, base) {
|
513 | var parsed = parseArithmeticExpression(cssValue);
|
514 | if (parsed == null) return null;
|
515 | return parsed.percentage * base + parsed.absolute;
|
516 | };
|
517 | var parseArithmeticExpression = function (cssValue) {
|
518 | var cssRegex = /(?:(\+|\-)\s*)?(\d+(?:\.\d+)?(%|px)?)/g;
|
519 |
|
520 | if (typeof cssValue === "number") {
|
521 | return {
|
522 | percentage: 0,
|
523 | absolute: cssValue
|
524 | };
|
525 | }
|
526 |
|
527 | var parsed = {
|
528 | percentage: 0,
|
529 | absolute: 0
|
530 | };
|
531 | var idx = 0;
|
532 | var matchResult = cssRegex.exec(cssValue);
|
533 |
|
534 | while (matchResult != null) {
|
535 | var sign = matchResult[1];
|
536 | var value = matchResult[2];
|
537 | var unit = matchResult[3];
|
538 | var parsedValue = parseFloat(value);
|
539 |
|
540 | if (idx <= 0) {
|
541 | sign = sign || "+";
|
542 | }
|
543 |
|
544 |
|
545 | if (!sign) {
|
546 | return null;
|
547 | }
|
548 |
|
549 | var signMultiplier = sign === "+" ? 1 : -1;
|
550 |
|
551 | if (unit === "%") {
|
552 | parsed.percentage += signMultiplier * (parsedValue / 100);
|
553 | } else {
|
554 | parsed.absolute += signMultiplier * parsedValue;
|
555 | }
|
556 |
|
557 |
|
558 | ++idx;
|
559 | matchResult = cssRegex.exec(cssValue);
|
560 | }
|
561 |
|
562 |
|
563 | if (idx === 0) {
|
564 | return null;
|
565 | }
|
566 |
|
567 | return parsed;
|
568 | };
|
569 | var getDirection = function (start, end) {
|
570 | if (start === end) return DIRECTION.NONE;
|
571 | return start < end ? DIRECTION.NEXT : DIRECTION.PREV;
|
572 | };
|
573 | var parseElement = function (element) {
|
574 | if (!Array.isArray(element)) {
|
575 | element = [element];
|
576 | }
|
577 |
|
578 | var elements = [];
|
579 | element.forEach(function (el) {
|
580 | if (isString(el)) {
|
581 | var tempDiv = document.createElement("div");
|
582 | tempDiv.innerHTML = el;
|
583 | elements.push.apply(elements, __spreadArray([], __read(toArray(tempDiv.children))));
|
584 |
|
585 | while (tempDiv.firstChild) {
|
586 | tempDiv.removeChild(tempDiv.firstChild);
|
587 | }
|
588 | } else if (el && el.nodeType === Node.ELEMENT_NODE) {
|
589 | elements.push(el);
|
590 | } else {
|
591 | throw new FlickingError(MESSAGE.WRONG_TYPE(el, ["HTMLElement", "string"]), CODE.WRONG_TYPE);
|
592 | }
|
593 | });
|
594 | return elements;
|
595 | };
|
596 | var getMinusCompensatedIndex = function (idx, max) {
|
597 | return idx < 0 ? clamp(idx + max, 0, max) : clamp(idx, 0, max);
|
598 | };
|
599 | var includes = function (array, target) {
|
600 | var e_1, _a;
|
601 |
|
602 | try {
|
603 | for (var array_1 = __values(array), array_1_1 = array_1.next(); !array_1_1.done; array_1_1 = array_1.next()) {
|
604 | var val = array_1_1.value;
|
605 | if (val === target) return true;
|
606 | }
|
607 | } catch (e_1_1) {
|
608 | e_1 = {
|
609 | error: e_1_1
|
610 | };
|
611 | } finally {
|
612 | try {
|
613 | if (array_1_1 && !array_1_1.done && (_a = array_1.return)) _a.call(array_1);
|
614 | } finally {
|
615 | if (e_1) throw e_1.error;
|
616 | }
|
617 | }
|
618 |
|
619 | return false;
|
620 | };
|
621 | var isString = function (val) {
|
622 | return typeof val === "string";
|
623 | };
|
624 | var circulatePosition = function (pos, min, max) {
|
625 | var size = max - min;
|
626 |
|
627 | if (pos < min) {
|
628 | var offset = (min - pos) % size;
|
629 | pos = max - offset;
|
630 | } else if (pos > max) {
|
631 | var offset = (pos - max) % size;
|
632 | pos = min + offset;
|
633 | }
|
634 |
|
635 | return pos;
|
636 | };
|
637 | var find = function (array, checker) {
|
638 | var e_2, _a;
|
639 |
|
640 | try {
|
641 | for (var array_2 = __values(array), array_2_1 = array_2.next(); !array_2_1.done; array_2_1 = array_2.next()) {
|
642 | var val = array_2_1.value;
|
643 |
|
644 | if (checker(val)) {
|
645 | return val;
|
646 | }
|
647 | }
|
648 | } catch (e_2_1) {
|
649 | e_2 = {
|
650 | error: e_2_1
|
651 | };
|
652 | } finally {
|
653 | try {
|
654 | if (array_2_1 && !array_2_1.done && (_a = array_2.return)) _a.call(array_2);
|
655 | } finally {
|
656 | if (e_2) throw e_2.error;
|
657 | }
|
658 | }
|
659 |
|
660 | return null;
|
661 | };
|
662 | var findIndex = function (array, checker) {
|
663 | for (var idx = 0; idx < array.length; idx++) {
|
664 | if (checker(array[idx])) {
|
665 | return idx;
|
666 | }
|
667 | }
|
668 |
|
669 | return -1;
|
670 | };
|
671 | var getProgress = function (pos, prev, next) {
|
672 | return (pos - prev) / (next - prev);
|
673 | };
|
674 |
|
675 | var getStyle = function (el) {
|
676 | return window.getComputedStyle(el) || el.currentStyle;
|
677 | };
|
678 | var isBetween = function (val, min, max) {
|
679 | return val >= min && val <= max;
|
680 | };
|
681 | var circulateIndex = function (index, max) {
|
682 | if (index >= max) {
|
683 | return index % max;
|
684 | } else if (index < 0) {
|
685 | return getMinusCompensatedIndex((index + 1) % max - 1, max);
|
686 | } else {
|
687 | return index;
|
688 | }
|
689 | };
|
690 | var setPrototypeOf = Object.setPrototypeOf || function (obj, proto) {
|
691 | obj.__proto__ = proto;
|
692 | return obj;
|
693 | };
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 |
|
718 | var FlickingError = function (_super) {
|
719 | __extends(FlickingError, _super);
|
720 | |
721 |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 | function FlickingError(message, code) {
|
727 | var _this = _super.call(this, message) || this;
|
728 |
|
729 | setPrototypeOf(_this, FlickingError.prototype);
|
730 | _this.name = "FlickingError";
|
731 | _this.code = code;
|
732 | return _this;
|
733 | }
|
734 |
|
735 | return FlickingError;
|
736 | }(Error);
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 | var Viewport = function () {
|
748 | |
749 |
|
750 |
|
751 | function Viewport(el) {
|
752 | this._el = el;
|
753 | this._width = 0;
|
754 | this._height = 0;
|
755 | this._padding = {
|
756 | left: 0,
|
757 | right: 0,
|
758 | top: 0,
|
759 | bottom: 0
|
760 | };
|
761 | this._isBorderBoxSizing = false;
|
762 | }
|
763 |
|
764 | var __proto = Viewport.prototype;
|
765 | Object.defineProperty(__proto, "element", {
|
766 | |
767 |
|
768 |
|
769 |
|
770 |
|
771 |
|
772 | get: function () {
|
773 | return this._el;
|
774 | },
|
775 | enumerable: false,
|
776 | configurable: true
|
777 | });
|
778 | Object.defineProperty(__proto, "width", {
|
779 | |
780 |
|
781 |
|
782 |
|
783 |
|
784 |
|
785 | get: function () {
|
786 | return this._width - this._padding.left - this._padding.right;
|
787 | },
|
788 | enumerable: false,
|
789 | configurable: true
|
790 | });
|
791 | Object.defineProperty(__proto, "height", {
|
792 | |
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 | get: function () {
|
799 | return this._height - this._padding.top - this._padding.bottom;
|
800 | },
|
801 | enumerable: false,
|
802 | configurable: true
|
803 | });
|
804 | Object.defineProperty(__proto, "padding", {
|
805 | |
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 | get: function () {
|
816 | return this._padding;
|
817 | },
|
818 | enumerable: false,
|
819 | configurable: true
|
820 | });
|
821 | |
822 |
|
823 |
|
824 |
|
825 |
|
826 |
|
827 |
|
828 |
|
829 |
|
830 |
|
831 | __proto.setSize = function (_a) {
|
832 | var width = _a.width,
|
833 | height = _a.height;
|
834 | var el = this._el;
|
835 | var padding = this._padding;
|
836 | var isBorderBoxSizing = this._isBorderBoxSizing;
|
837 |
|
838 | if (width != null) {
|
839 | if (isString(width)) {
|
840 | el.style.width = width;
|
841 | } else {
|
842 | var newWidth = isBorderBoxSizing ? width + padding.left + padding.right : width;
|
843 | el.style.width = newWidth + "px";
|
844 | }
|
845 | }
|
846 |
|
847 | if (height != null) {
|
848 | if (isString(height)) {
|
849 | el.style.height = height;
|
850 | } else {
|
851 | var newHeight = isBorderBoxSizing ? height + padding.top + padding.bottom : height;
|
852 | el.style.height = newHeight + "px";
|
853 | }
|
854 | }
|
855 |
|
856 | this.resize();
|
857 | };
|
858 | |
859 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 | __proto.resize = function () {
|
865 | var el = this._el;
|
866 | var elStyle = getStyle(el);
|
867 | this._width = el.clientWidth;
|
868 | this._height = el.clientHeight;
|
869 | this._padding = {
|
870 | left: parseFloat(elStyle.paddingLeft),
|
871 | right: parseFloat(elStyle.paddingRight),
|
872 | top: parseFloat(elStyle.paddingTop),
|
873 | bottom: parseFloat(elStyle.paddingBottom)
|
874 | };
|
875 | this._isBorderBoxSizing = elStyle.boxSizing === "border-box";
|
876 | };
|
877 |
|
878 | return Viewport;
|
879 | }();
|
880 |
|
881 |
|
882 |
|
883 |
|
884 |
|
885 | var EVENT = {
|
886 | HOLD: "hold",
|
887 | CHANGE: "change",
|
888 | RELEASE: "release",
|
889 | ANIMATION_END: "animationEnd",
|
890 | FINISH: "finish"
|
891 | };
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 | var POSITION_KEY = "flick";
|
898 |
|
899 | var STATE_TYPE;
|
900 |
|
901 | (function (STATE_TYPE) {
|
902 | STATE_TYPE[STATE_TYPE["IDLE"] = 0] = "IDLE";
|
903 | STATE_TYPE[STATE_TYPE["HOLDING"] = 1] = "HOLDING";
|
904 | STATE_TYPE[STATE_TYPE["DRAGGING"] = 2] = "DRAGGING";
|
905 | STATE_TYPE[STATE_TYPE["ANIMATING"] = 3] = "ANIMATING";
|
906 | STATE_TYPE[STATE_TYPE["DISABLED"] = 4] = "DISABLED";
|
907 | })(STATE_TYPE || (STATE_TYPE = {}));
|
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 | var State = function () {
|
916 | function State() {
|
917 | this._delta = 0;
|
918 | this._targetPanel = null;
|
919 | }
|
920 |
|
921 | var __proto = State.prototype;
|
922 | Object.defineProperty(__proto, "delta", {
|
923 | |
924 |
|
925 |
|
926 |
|
927 |
|
928 |
|
929 | get: function () {
|
930 | return this._delta;
|
931 | },
|
932 | enumerable: false,
|
933 | configurable: true
|
934 | });
|
935 | Object.defineProperty(__proto, "targetPanel", {
|
936 | |
937 |
|
938 |
|
939 |
|
940 |
|
941 |
|
942 | get: function () {
|
943 | return this._targetPanel;
|
944 | },
|
945 | set: function (val) {
|
946 | this._targetPanel = val;
|
947 | },
|
948 | enumerable: false,
|
949 | configurable: true
|
950 | });
|
951 | |
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 |
|
958 | __proto.onEnter = function (prevState) {
|
959 | this._delta = prevState._delta;
|
960 | this._targetPanel = prevState._targetPanel;
|
961 | };
|
962 | |
963 |
|
964 |
|
965 |
|
966 |
|
967 |
|
968 |
|
969 |
|
970 |
|
971 |
|
972 |
|
973 |
|
974 | __proto.onHold = function (ctx) {
|
975 | };
|
976 | |
977 |
|
978 |
|
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 |
|
985 |
|
986 |
|
987 |
|
988 | __proto.onChange = function (ctx) {
|
989 | };
|
990 | |
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 |
|
999 |
|
1000 |
|
1001 |
|
1002 | __proto.onRelease = function (ctx) {
|
1003 | };
|
1004 | |
1005 |
|
1006 |
|
1007 |
|
1008 |
|
1009 |
|
1010 |
|
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 | __proto.onAnimationEnd = function (ctx) {
|
1017 | };
|
1018 | |
1019 |
|
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 | __proto.onFinish = function (ctx) {
|
1030 | };
|
1031 |
|
1032 | __proto._moveToChangedPosition = function (ctx) {
|
1033 | var flicking = ctx.flicking,
|
1034 | axesEvent = ctx.axesEvent,
|
1035 | transitTo = ctx.transitTo;
|
1036 | var delta = axesEvent.delta[POSITION_KEY];
|
1037 |
|
1038 | if (!delta) {
|
1039 | return;
|
1040 | }
|
1041 |
|
1042 | this._delta += delta;
|
1043 | var camera = flicking.camera;
|
1044 | var prevPosition = camera.position;
|
1045 | var position = axesEvent.pos[POSITION_KEY];
|
1046 | var newPosition = flicking.circularEnabled ? circulatePosition(position, camera.range.min, camera.range.max) : position;
|
1047 | camera.lookAt(newPosition);
|
1048 | var moveEvent = new ComponentEvent(EVENTS.MOVE, {
|
1049 | isTrusted: axesEvent.isTrusted,
|
1050 | holding: this.holding,
|
1051 | direction: getDirection(0, axesEvent.delta[POSITION_KEY]),
|
1052 | axesEvent: axesEvent
|
1053 | });
|
1054 | flicking.trigger(moveEvent);
|
1055 |
|
1056 | if (moveEvent.isCanceled()) {
|
1057 |
|
1058 | camera.lookAt(prevPosition);
|
1059 | transitTo(STATE_TYPE.DISABLED);
|
1060 | }
|
1061 | };
|
1062 |
|
1063 | return State;
|
1064 | }();
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 | var IdleState = function (_super) {
|
1073 | __extends(IdleState, _super);
|
1074 |
|
1075 | function IdleState() {
|
1076 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
1077 | |
1078 |
|
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 | _this.holding = false;
|
1086 | |
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 | _this.animating = false;
|
1094 | return _this;
|
1095 | }
|
1096 |
|
1097 | var __proto = IdleState.prototype;
|
1098 |
|
1099 | __proto.onEnter = function () {
|
1100 | this._delta = 0;
|
1101 | this._targetPanel = null;
|
1102 | };
|
1103 |
|
1104 | __proto.onHold = function (ctx) {
|
1105 |
|
1106 | var flicking = ctx.flicking,
|
1107 | axesEvent = ctx.axesEvent,
|
1108 | transitTo = ctx.transitTo;
|
1109 |
|
1110 | if (flicking.renderer.panelCount <= 0) {
|
1111 | transitTo(STATE_TYPE.DISABLED);
|
1112 | return;
|
1113 | }
|
1114 |
|
1115 | var holdStartEvent = new ComponentEvent(EVENTS.HOLD_START, {
|
1116 | axesEvent: axesEvent
|
1117 | });
|
1118 | flicking.trigger(holdStartEvent);
|
1119 |
|
1120 | if (holdStartEvent.isCanceled()) {
|
1121 | transitTo(STATE_TYPE.DISABLED);
|
1122 | } else {
|
1123 | transitTo(STATE_TYPE.HOLDING);
|
1124 | }
|
1125 | };
|
1126 |
|
1127 |
|
1128 | __proto.onChange = function (ctx) {
|
1129 | var flicking = ctx.flicking,
|
1130 | axesEvent = ctx.axesEvent,
|
1131 | transitTo = ctx.transitTo;
|
1132 | var controller = flicking.control.controller;
|
1133 | var animatingContext = controller.animatingContext;
|
1134 | var moveStartEvent = new ComponentEvent(EVENTS.MOVE_START, {
|
1135 | isTrusted: axesEvent.isTrusted,
|
1136 | holding: this.holding,
|
1137 | direction: getDirection(animatingContext.start, animatingContext.end),
|
1138 | axesEvent: axesEvent
|
1139 | });
|
1140 | flicking.trigger(moveStartEvent);
|
1141 |
|
1142 | if (moveStartEvent.isCanceled()) {
|
1143 | transitTo(STATE_TYPE.DISABLED);
|
1144 | } else {
|
1145 |
|
1146 | transitTo(STATE_TYPE.ANIMATING).onChange(ctx);
|
1147 | }
|
1148 | };
|
1149 |
|
1150 | return IdleState;
|
1151 | }(State);
|
1152 |
|
1153 |
|
1154 |
|
1155 |
|
1156 |
|
1157 |
|
1158 |
|
1159 | var HoldingState = function (_super) {
|
1160 | __extends(HoldingState, _super);
|
1161 |
|
1162 | function HoldingState() {
|
1163 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
1164 | |
1165 |
|
1166 |
|
1167 |
|
1168 |
|
1169 |
|
1170 |
|
1171 |
|
1172 | _this.holding = true;
|
1173 | |
1174 |
|
1175 |
|
1176 |
|
1177 |
|
1178 |
|
1179 |
|
1180 | _this.animating = false;
|
1181 | _this._releaseEvent = null;
|
1182 | return _this;
|
1183 | }
|
1184 |
|
1185 | var __proto = HoldingState.prototype;
|
1186 |
|
1187 | __proto.onChange = function (ctx) {
|
1188 | var flicking = ctx.flicking,
|
1189 | axesEvent = ctx.axesEvent,
|
1190 | transitTo = ctx.transitTo;
|
1191 | var inputEvent = axesEvent.inputEvent;
|
1192 | var offset = flicking.horizontal ? inputEvent.offsetX : inputEvent.offsetY;
|
1193 | var moveStartEvent = new ComponentEvent(EVENTS.MOVE_START, {
|
1194 | isTrusted: axesEvent.isTrusted,
|
1195 | holding: this.holding,
|
1196 | direction: getDirection(0, -offset),
|
1197 | axesEvent: axesEvent
|
1198 | });
|
1199 | flicking.trigger(moveStartEvent);
|
1200 |
|
1201 | if (moveStartEvent.isCanceled()) {
|
1202 | transitTo(STATE_TYPE.DISABLED);
|
1203 | } else {
|
1204 |
|
1205 | transitTo(STATE_TYPE.DRAGGING).onChange(ctx);
|
1206 | }
|
1207 | };
|
1208 |
|
1209 | __proto.onRelease = function (ctx) {
|
1210 | var flicking = ctx.flicking,
|
1211 | axesEvent = ctx.axesEvent,
|
1212 | transitTo = ctx.transitTo;
|
1213 | flicking.trigger(new ComponentEvent(EVENTS.HOLD_END, {
|
1214 | axesEvent: axesEvent
|
1215 | }));
|
1216 |
|
1217 | if (axesEvent.delta.flick !== 0) {
|
1218 |
|
1219 |
|
1220 |
|
1221 |
|
1222 |
|
1223 | axesEvent.setTo({
|
1224 | flick: flicking.camera.position
|
1225 | }, 0);
|
1226 | transitTo(STATE_TYPE.IDLE);
|
1227 | return;
|
1228 | }
|
1229 |
|
1230 |
|
1231 |
|
1232 | this._releaseEvent = axesEvent;
|
1233 | };
|
1234 |
|
1235 | __proto.onFinish = function (ctx) {
|
1236 | var e_1, _a;
|
1237 |
|
1238 | var flicking = ctx.flicking,
|
1239 | transitTo = ctx.transitTo;
|
1240 |
|
1241 |
|
1242 | transitTo(STATE_TYPE.IDLE);
|
1243 |
|
1244 | if (!this._releaseEvent) {
|
1245 | return;
|
1246 | }
|
1247 |
|
1248 |
|
1249 |
|
1250 | var releaseEvent = this._releaseEvent;
|
1251 |
|
1252 |
|
1253 |
|
1254 | var srcEvent = releaseEvent.inputEvent.srcEvent;
|
1255 | var clickedElement;
|
1256 |
|
1257 | if (srcEvent.type === "touchend") {
|
1258 | var touchEvent = srcEvent;
|
1259 | var touch = touchEvent.changedTouches[0];
|
1260 | clickedElement = document.elementFromPoint(touch.clientX, touch.clientY);
|
1261 | } else {
|
1262 | clickedElement = srcEvent.target;
|
1263 | }
|
1264 |
|
1265 |
|
1266 |
|
1267 | var panels = flicking.renderer.panels;
|
1268 | var clickedPanel = null;
|
1269 |
|
1270 | try {
|
1271 | for (var panels_1 = __values(panels), panels_1_1 = panels_1.next(); !panels_1_1.done; panels_1_1 = panels_1.next()) {
|
1272 | var panel = panels_1_1.value;
|
1273 |
|
1274 | if (panel.contains(clickedElement)) {
|
1275 | clickedPanel = panel;
|
1276 | break;
|
1277 | }
|
1278 | }
|
1279 | } catch (e_1_1) {
|
1280 | e_1 = {
|
1281 | error: e_1_1
|
1282 | };
|
1283 | } finally {
|
1284 | try {
|
1285 | if (panels_1_1 && !panels_1_1.done && (_a = panels_1.return)) _a.call(panels_1);
|
1286 | } finally {
|
1287 | if (e_1) throw e_1.error;
|
1288 | }
|
1289 | }
|
1290 |
|
1291 | if (clickedPanel) {
|
1292 | var cameraPosition = flicking.camera.position;
|
1293 | var clickedPanelPosition = clickedPanel.position;
|
1294 | flicking.trigger(new ComponentEvent(EVENTS.SELECT, {
|
1295 | index: clickedPanel.index,
|
1296 | panel: clickedPanel,
|
1297 |
|
1298 | direction: getDirection(cameraPosition, clickedPanelPosition)
|
1299 | }));
|
1300 | }
|
1301 | };
|
1302 |
|
1303 | return HoldingState;
|
1304 | }(State);
|
1305 |
|
1306 |
|
1307 |
|
1308 |
|
1309 |
|
1310 |
|
1311 |
|
1312 | var DraggingState = function (_super) {
|
1313 | __extends(DraggingState, _super);
|
1314 |
|
1315 | function DraggingState() {
|
1316 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
1317 | |
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 |
|
1323 |
|
1324 |
|
1325 | _this.holding = true;
|
1326 | |
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 | _this.animating = true;
|
1334 | return _this;
|
1335 | }
|
1336 |
|
1337 | var __proto = DraggingState.prototype;
|
1338 |
|
1339 | __proto.onChange = function (ctx) {
|
1340 | this._moveToChangedPosition(ctx);
|
1341 | };
|
1342 |
|
1343 | __proto.onRelease = function (ctx) {
|
1344 | var flicking = ctx.flicking,
|
1345 | axesEvent = ctx.axesEvent,
|
1346 | transitTo = ctx.transitTo;
|
1347 |
|
1348 |
|
1349 | flicking.trigger(new ComponentEvent(EVENTS.HOLD_END, {
|
1350 | axesEvent: axesEvent
|
1351 | }));
|
1352 |
|
1353 | if (flicking.renderer.panelCount <= 0) {
|
1354 |
|
1355 | transitTo(STATE_TYPE.IDLE);
|
1356 | return;
|
1357 | }
|
1358 |
|
1359 | transitTo(STATE_TYPE.ANIMATING);
|
1360 | var control = flicking.control;
|
1361 | var position = axesEvent.destPos[POSITION_KEY];
|
1362 | var duration = Math.max(axesEvent.duration, flicking.duration);
|
1363 | void control.moveToPosition(position, duration, axesEvent);
|
1364 | };
|
1365 |
|
1366 | return DraggingState;
|
1367 | }(State);
|
1368 |
|
1369 |
|
1370 |
|
1371 |
|
1372 |
|
1373 |
|
1374 |
|
1375 | var AnimatingState = function (_super) {
|
1376 | __extends(AnimatingState, _super);
|
1377 |
|
1378 | function AnimatingState() {
|
1379 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
1380 | |
1381 |
|
1382 |
|
1383 |
|
1384 |
|
1385 |
|
1386 |
|
1387 |
|
1388 | _this.holding = false;
|
1389 | |
1390 |
|
1391 |
|
1392 |
|
1393 |
|
1394 |
|
1395 |
|
1396 | _this.animating = true;
|
1397 | return _this;
|
1398 | }
|
1399 |
|
1400 | var __proto = AnimatingState.prototype;
|
1401 |
|
1402 | __proto.onHold = function (ctx) {
|
1403 | var flicking = ctx.flicking,
|
1404 | axesEvent = ctx.axesEvent,
|
1405 | transitTo = ctx.transitTo;
|
1406 | this._delta = 0;
|
1407 | flicking.control.updateInput();
|
1408 | var holdStartEvent = new ComponentEvent(EVENTS.HOLD_START, {
|
1409 | axesEvent: axesEvent
|
1410 | });
|
1411 | flicking.trigger(holdStartEvent);
|
1412 |
|
1413 | if (holdStartEvent.isCanceled()) {
|
1414 | transitTo(STATE_TYPE.DISABLED);
|
1415 | } else {
|
1416 | transitTo(STATE_TYPE.DRAGGING);
|
1417 | }
|
1418 | };
|
1419 |
|
1420 | __proto.onChange = function (ctx) {
|
1421 | this._moveToChangedPosition(ctx);
|
1422 | };
|
1423 |
|
1424 | __proto.onFinish = function (ctx) {
|
1425 | var flicking = ctx.flicking,
|
1426 | axesEvent = ctx.axesEvent,
|
1427 | transitTo = ctx.transitTo;
|
1428 | var control = flicking.control;
|
1429 | var controller = control.controller;
|
1430 | var animatingContext = controller.animatingContext;
|
1431 | transitTo(STATE_TYPE.IDLE);
|
1432 | flicking.trigger(new ComponentEvent(EVENTS.MOVE_END, {
|
1433 | isTrusted: axesEvent.isTrusted,
|
1434 | direction: getDirection(animatingContext.start, animatingContext.end),
|
1435 | axesEvent: axesEvent
|
1436 | }));
|
1437 | control.setActive(this._targetPanel, control.activePanel, axesEvent.isTrusted);
|
1438 | };
|
1439 |
|
1440 | return AnimatingState;
|
1441 | }(State);
|
1442 |
|
1443 |
|
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 | var DisabledState = function (_super) {
|
1450 | __extends(DisabledState, _super);
|
1451 |
|
1452 | function DisabledState() {
|
1453 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
1454 | |
1455 |
|
1456 |
|
1457 |
|
1458 |
|
1459 |
|
1460 |
|
1461 |
|
1462 | _this.holding = false;
|
1463 | |
1464 |
|
1465 |
|
1466 |
|
1467 |
|
1468 |
|
1469 |
|
1470 | _this.animating = true;
|
1471 | return _this;
|
1472 | }
|
1473 |
|
1474 | var __proto = DisabledState.prototype;
|
1475 |
|
1476 | __proto.onAnimationEnd = function (ctx) {
|
1477 | var transitTo = ctx.transitTo;
|
1478 | transitTo(STATE_TYPE.IDLE);
|
1479 | };
|
1480 |
|
1481 | __proto.onChange = function (ctx) {
|
1482 | var axesEvent = ctx.axesEvent,
|
1483 | transitTo = ctx.transitTo;
|
1484 |
|
1485 | axesEvent.stop();
|
1486 | transitTo(STATE_TYPE.IDLE);
|
1487 | };
|
1488 |
|
1489 | __proto.onRelease = function (ctx) {
|
1490 | var axesEvent = ctx.axesEvent,
|
1491 | transitTo = ctx.transitTo;
|
1492 |
|
1493 | if (axesEvent.delta.flick === 0) {
|
1494 | transitTo(STATE_TYPE.IDLE);
|
1495 | }
|
1496 | };
|
1497 |
|
1498 | return DisabledState;
|
1499 | }(State);
|
1500 |
|
1501 |
|
1502 |
|
1503 |
|
1504 |
|
1505 | var StateMachine = function () {
|
1506 | function StateMachine() {
|
1507 | var _this = this;
|
1508 |
|
1509 | this.transitTo = function (nextStateType) {
|
1510 | var nextState;
|
1511 |
|
1512 | switch (nextStateType) {
|
1513 | case STATE_TYPE.IDLE:
|
1514 | nextState = new IdleState();
|
1515 | break;
|
1516 |
|
1517 | case STATE_TYPE.HOLDING:
|
1518 | nextState = new HoldingState();
|
1519 | break;
|
1520 |
|
1521 | case STATE_TYPE.DRAGGING:
|
1522 | nextState = new DraggingState();
|
1523 | break;
|
1524 |
|
1525 | case STATE_TYPE.ANIMATING:
|
1526 | nextState = new AnimatingState();
|
1527 | break;
|
1528 |
|
1529 | case STATE_TYPE.DISABLED:
|
1530 | nextState = new DisabledState();
|
1531 | break;
|
1532 | }
|
1533 |
|
1534 | nextState.onEnter(_this._state);
|
1535 | _this._state = nextState;
|
1536 | return _this._state;
|
1537 | };
|
1538 |
|
1539 | this._state = new IdleState();
|
1540 | }
|
1541 |
|
1542 | var __proto = StateMachine.prototype;
|
1543 | Object.defineProperty(__proto, "state", {
|
1544 | get: function () {
|
1545 | return this._state;
|
1546 | },
|
1547 | enumerable: false,
|
1548 | configurable: true
|
1549 | });
|
1550 |
|
1551 | __proto.fire = function (eventType, externalCtx) {
|
1552 | var currentState = this._state;
|
1553 |
|
1554 | var ctx = __assign(__assign({}, externalCtx), {
|
1555 | transitTo: this.transitTo
|
1556 | });
|
1557 |
|
1558 | switch (eventType) {
|
1559 | case EVENT.HOLD:
|
1560 | currentState.onHold(ctx);
|
1561 | break;
|
1562 |
|
1563 | case EVENT.CHANGE:
|
1564 | currentState.onChange(ctx);
|
1565 | break;
|
1566 |
|
1567 | case EVENT.RELEASE:
|
1568 | currentState.onRelease(ctx);
|
1569 | break;
|
1570 |
|
1571 | case EVENT.ANIMATION_END:
|
1572 | currentState.onAnimationEnd(ctx);
|
1573 | break;
|
1574 |
|
1575 | case EVENT.FINISH:
|
1576 | currentState.onFinish(ctx);
|
1577 | break;
|
1578 | }
|
1579 | };
|
1580 |
|
1581 | return StateMachine;
|
1582 | }();
|
1583 |
|
1584 |
|
1585 |
|
1586 |
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 |
|
1592 |
|
1593 |
|
1594 | var AxesController = function () {
|
1595 |
|
1596 | function AxesController() {
|
1597 | var _this = this;
|
1598 |
|
1599 | this._onAxesHold = function () {
|
1600 | _this._dragged = false;
|
1601 | };
|
1602 |
|
1603 | this._onAxesChange = function () {
|
1604 | _this._dragged = true;
|
1605 | };
|
1606 |
|
1607 | this._preventClickWhenDragged = function (e) {
|
1608 | if (_this._dragged) {
|
1609 | e.preventDefault();
|
1610 | e.stopPropagation();
|
1611 | }
|
1612 |
|
1613 | _this._dragged = false;
|
1614 | };
|
1615 |
|
1616 | this._resetInternalValues();
|
1617 |
|
1618 | this._stateMachine = new StateMachine();
|
1619 | }
|
1620 |
|
1621 | var __proto = AxesController.prototype;
|
1622 | Object.defineProperty(__proto, "axes", {
|
1623 | |
1624 |
|
1625 |
|
1626 |
|
1627 |
|
1628 |
|
1629 |
|
1630 | get: function () {
|
1631 | return this._axes;
|
1632 | },
|
1633 | enumerable: false,
|
1634 | configurable: true
|
1635 | });
|
1636 | Object.defineProperty(__proto, "stateMachine", {
|
1637 | |
1638 |
|
1639 |
|
1640 | get: function () {
|
1641 | return this._stateMachine;
|
1642 | },
|
1643 | enumerable: false,
|
1644 | configurable: true
|
1645 | });
|
1646 | Object.defineProperty(__proto, "state", {
|
1647 | |
1648 |
|
1649 |
|
1650 |
|
1651 |
|
1652 | get: function () {
|
1653 | return this._stateMachine.state;
|
1654 | },
|
1655 | enumerable: false,
|
1656 | configurable: true
|
1657 | });
|
1658 | Object.defineProperty(__proto, "animatingContext", {
|
1659 | |
1660 |
|
1661 |
|
1662 |
|
1663 |
|
1664 |
|
1665 |
|
1666 |
|
1667 |
|
1668 | get: function () {
|
1669 | return this._animatingContext;
|
1670 | },
|
1671 | enumerable: false,
|
1672 | configurable: true
|
1673 | });
|
1674 | Object.defineProperty(__proto, "controlParams", {
|
1675 | |
1676 |
|
1677 |
|
1678 |
|
1679 |
|
1680 | get: function () {
|
1681 | var axes = this._axes;
|
1682 |
|
1683 | if (!axes) {
|
1684 | return {
|
1685 | range: {
|
1686 | min: 0,
|
1687 | max: 0
|
1688 | },
|
1689 | position: 0,
|
1690 | circular: false
|
1691 | };
|
1692 | }
|
1693 |
|
1694 | var axis = axes.axis[POSITION_KEY];
|
1695 | return {
|
1696 | range: {
|
1697 | min: axis.range[0],
|
1698 | max: axis.range[1]
|
1699 | },
|
1700 | circular: axis.circular[0],
|
1701 | position: this.position
|
1702 | };
|
1703 | },
|
1704 | enumerable: false,
|
1705 | configurable: true
|
1706 | });
|
1707 | Object.defineProperty(__proto, "enabled", {
|
1708 | |
1709 |
|
1710 |
|
1711 |
|
1712 |
|
1713 |
|
1714 | get: function () {
|
1715 | var _a, _b;
|
1716 |
|
1717 | return (_b = (_a = this._panInput) === null || _a === void 0 ? void 0 : _a.isEnable()) !== null && _b !== void 0 ? _b : false;
|
1718 | },
|
1719 | enumerable: false,
|
1720 | configurable: true
|
1721 | });
|
1722 | Object.defineProperty(__proto, "position", {
|
1723 | |
1724 |
|
1725 |
|
1726 |
|
1727 |
|
1728 |
|
1729 | get: function () {
|
1730 | var _a, _b;
|
1731 |
|
1732 | return (_b = (_a = this._axes) === null || _a === void 0 ? void 0 : _a.get([POSITION_KEY])[POSITION_KEY]) !== null && _b !== void 0 ? _b : 0;
|
1733 | },
|
1734 | enumerable: false,
|
1735 | configurable: true
|
1736 | });
|
1737 | Object.defineProperty(__proto, "range", {
|
1738 | |
1739 |
|
1740 |
|
1741 |
|
1742 |
|
1743 |
|
1744 | get: function () {
|
1745 | var _a, _b;
|
1746 |
|
1747 | return (_b = (_a = this._axes) === null || _a === void 0 ? void 0 : _a.axis[POSITION_KEY].range) !== null && _b !== void 0 ? _b : [0, 0];
|
1748 | },
|
1749 | enumerable: false,
|
1750 | configurable: true
|
1751 | });
|
1752 | Object.defineProperty(__proto, "bounce", {
|
1753 | |
1754 |
|
1755 |
|
1756 |
|
1757 |
|
1758 |
|
1759 | get: function () {
|
1760 | var _a;
|
1761 |
|
1762 | return (_a = this._axes) === null || _a === void 0 ? void 0 : _a.axis[POSITION_KEY].bounce;
|
1763 | },
|
1764 | enumerable: false,
|
1765 | configurable: true
|
1766 | });
|
1767 | |
1768 |
|
1769 |
|
1770 |
|
1771 |
|
1772 |
|
1773 |
|
1774 |
|
1775 | __proto.init = function (flicking) {
|
1776 | var _a;
|
1777 |
|
1778 | var _this = this;
|
1779 |
|
1780 | this._flicking = flicking;
|
1781 | this._axes = new Axes((_a = {}, _a[POSITION_KEY] = {
|
1782 | range: [0, 0],
|
1783 | circular: false,
|
1784 | bounce: [0, 0]
|
1785 | }, _a), {
|
1786 | deceleration: flicking.deceleration,
|
1787 | interruptable: flicking.interruptable,
|
1788 | easing: flicking.easing
|
1789 | });
|
1790 | this._panInput = new PanInput(flicking.viewport.element, {
|
1791 | inputType: flicking.inputType,
|
1792 | iOSEdgeSwipeThreshold: flicking.iOSEdgeSwipeThreshold,
|
1793 | scale: flicking.horizontal ? [-1, 0] : [0, -1],
|
1794 | releaseOnScroll: true
|
1795 | });
|
1796 | var axes = this._axes;
|
1797 | axes.connect(flicking.horizontal ? [POSITION_KEY, ""] : ["", POSITION_KEY], this._panInput);
|
1798 |
|
1799 | var _loop_1 = function (key) {
|
1800 | var eventType = EVENT[key];
|
1801 | axes.on(eventType, function (e) {
|
1802 | _this._stateMachine.fire(eventType, {
|
1803 | flicking: flicking,
|
1804 | axesEvent: e
|
1805 | });
|
1806 | });
|
1807 | };
|
1808 |
|
1809 | for (var key in EVENT) {
|
1810 | _loop_1(key);
|
1811 | }
|
1812 |
|
1813 | return this;
|
1814 | };
|
1815 | |
1816 |
|
1817 |
|
1818 |
|
1819 |
|
1820 |
|
1821 |
|
1822 | __proto.destroy = function () {
|
1823 | var _a;
|
1824 |
|
1825 | if (this._axes) {
|
1826 | this.removePreventClickHandler();
|
1827 |
|
1828 | this._axes.destroy();
|
1829 | }
|
1830 |
|
1831 | (_a = this._panInput) === null || _a === void 0 ? void 0 : _a.destroy();
|
1832 |
|
1833 | this._resetInternalValues();
|
1834 | };
|
1835 | |
1836 |
|
1837 |
|
1838 |
|
1839 |
|
1840 |
|
1841 |
|
1842 |
|
1843 | __proto.enable = function () {
|
1844 | var _a;
|
1845 |
|
1846 | (_a = this._panInput) === null || _a === void 0 ? void 0 : _a.enable();
|
1847 | return this;
|
1848 | };
|
1849 | |
1850 |
|
1851 |
|
1852 |
|
1853 |
|
1854 |
|
1855 |
|
1856 |
|
1857 | __proto.disable = function () {
|
1858 | var _a;
|
1859 |
|
1860 | (_a = this._panInput) === null || _a === void 0 ? void 0 : _a.disable();
|
1861 | return this;
|
1862 | };
|
1863 | |
1864 |
|
1865 |
|
1866 |
|
1867 |
|
1868 |
|
1869 |
|
1870 |
|
1871 |
|
1872 |
|
1873 |
|
1874 | __proto.update = function (controlParams) {
|
1875 | var _a;
|
1876 |
|
1877 | var flicking = getFlickingAttached(this._flicking, "Control");
|
1878 | var camera = flicking.camera;
|
1879 | var axes = this._axes;
|
1880 | var axis = axes.axis[POSITION_KEY];
|
1881 | axis.circular = [controlParams.circular, controlParams.circular];
|
1882 | axis.range = [controlParams.range.min, controlParams.range.max];
|
1883 | axis.bounce = parseBounce(flicking.bounce, camera.size);
|
1884 | axes.axm.set((_a = {}, _a[POSITION_KEY] = controlParams.position, _a));
|
1885 | return this;
|
1886 | };
|
1887 | |
1888 |
|
1889 |
|
1890 |
|
1891 |
|
1892 |
|
1893 |
|
1894 | __proto.addPreventClickHandler = function () {
|
1895 | var flicking = getFlickingAttached(this._flicking, "Control");
|
1896 | var axes = this._axes;
|
1897 | var cameraEl = flicking.camera.element;
|
1898 | axes.on(EVENT.HOLD, this._onAxesHold);
|
1899 | axes.on(EVENT.CHANGE, this._onAxesChange);
|
1900 | cameraEl.addEventListener("click", this._preventClickWhenDragged, true);
|
1901 | return this;
|
1902 | };
|
1903 | |
1904 |
|
1905 |
|
1906 |
|
1907 |
|
1908 |
|
1909 |
|
1910 | __proto.removePreventClickHandler = function () {
|
1911 | var flicking = getFlickingAttached(this._flicking, "Control");
|
1912 | var axes = this._axes;
|
1913 | var cameraEl = flicking.camera.element;
|
1914 | axes.off(EVENT.HOLD, this._onAxesHold);
|
1915 | axes.off(EVENT.CHANGE, this._onAxesChange);
|
1916 | cameraEl.removeEventListener("click", this._preventClickWhenDragged, true);
|
1917 | return this;
|
1918 | };
|
1919 | |
1920 |
|
1921 |
|
1922 |
|
1923 |
|
1924 |
|
1925 |
|
1926 |
|
1927 |
|
1928 |
|
1929 |
|
1930 |
|
1931 |
|
1932 |
|
1933 |
|
1934 |
|
1935 |
|
1936 |
|
1937 |
|
1938 |
|
1939 |
|
1940 |
|
1941 |
|
1942 | __proto.animateTo = function (position, duration, axesEvent) {
|
1943 | var _a;
|
1944 |
|
1945 | var _this = this;
|
1946 |
|
1947 | var axes = this._axes;
|
1948 |
|
1949 | if (!axes) {
|
1950 | return Promise.reject(new FlickingError(MESSAGE.NOT_ATTACHED_TO_FLICKING("Control"), CODE.NOT_ATTACHED_TO_FLICKING));
|
1951 | }
|
1952 |
|
1953 | var startPos = axes.get([POSITION_KEY])[POSITION_KEY];
|
1954 |
|
1955 | if (startPos === position) {
|
1956 | var flicking = getFlickingAttached(this._flicking, "Control");
|
1957 | flicking.camera.lookAt(position);
|
1958 | return Promise.resolve();
|
1959 | }
|
1960 |
|
1961 | this._animatingContext = {
|
1962 | start: startPos,
|
1963 | end: position,
|
1964 | offset: 0
|
1965 | };
|
1966 |
|
1967 | var animate = function () {
|
1968 | var _a, _b;
|
1969 |
|
1970 | var resetContext = function () {
|
1971 | _this._animatingContext = {
|
1972 | start: 0,
|
1973 | end: 0,
|
1974 | offset: 0
|
1975 | };
|
1976 | };
|
1977 |
|
1978 | axes.once(EVENT.FINISH, resetContext);
|
1979 |
|
1980 | if (axesEvent) {
|
1981 | axesEvent.setTo((_a = {}, _a[POSITION_KEY] = position, _a), duration);
|
1982 | } else {
|
1983 | axes.setTo((_b = {}, _b[POSITION_KEY] = position, _b), duration);
|
1984 | }
|
1985 | };
|
1986 |
|
1987 | if (duration === 0) {
|
1988 | var flicking = getFlickingAttached(this._flicking, "Control");
|
1989 | var camera = flicking.camera;
|
1990 | animate();
|
1991 | var newPos = flicking.circularEnabled ? circulatePosition(position, camera.range.min, camera.range.max) : position;
|
1992 | axes.axm.set((_a = {}, _a[POSITION_KEY] = newPos, _a));
|
1993 | return Promise.resolve();
|
1994 | } else {
|
1995 | return new Promise(function (resolve, reject) {
|
1996 | var animationFinishHandler = function () {
|
1997 | axes.off(EVENT.HOLD, interruptionHandler);
|
1998 | resolve();
|
1999 | };
|
2000 |
|
2001 | var interruptionHandler = function () {
|
2002 | axes.off(EVENT.FINISH, animationFinishHandler);
|
2003 | reject(new FlickingError(MESSAGE.ANIMATION_INTERRUPTED, CODE.ANIMATION_INTERRUPTED));
|
2004 | };
|
2005 |
|
2006 | axes.once(EVENT.FINISH, animationFinishHandler);
|
2007 | axes.once(EVENT.HOLD, interruptionHandler);
|
2008 | animate();
|
2009 | });
|
2010 | }
|
2011 | };
|
2012 |
|
2013 | __proto._resetInternalValues = function () {
|
2014 | this._flicking = null;
|
2015 | this._axes = null;
|
2016 | this._panInput = null;
|
2017 | this._animatingContext = {
|
2018 | start: 0,
|
2019 | end: 0,
|
2020 | offset: 0
|
2021 | };
|
2022 | this._dragged = false;
|
2023 | };
|
2024 |
|
2025 | return AxesController;
|
2026 | }();
|
2027 |
|
2028 |
|
2029 |
|
2030 |
|
2031 |
|
2032 |
|
2033 | var Control = function () {
|
2034 |
|
2035 | function Control() {
|
2036 | this._flicking = null;
|
2037 | this._controller = new AxesController();
|
2038 | this._activePanel = null;
|
2039 | }
|
2040 |
|
2041 | var __proto = Control.prototype;
|
2042 | Object.defineProperty(__proto, "controller", {
|
2043 | |
2044 |
|
2045 |
|
2046 |
|
2047 |
|
2048 |
|
2049 | get: function () {
|
2050 | return this._controller;
|
2051 | },
|
2052 | enumerable: false,
|
2053 | configurable: true
|
2054 | });
|
2055 | Object.defineProperty(__proto, "activeIndex", {
|
2056 | |
2057 |
|
2058 |
|
2059 |
|
2060 |
|
2061 |
|
2062 |
|
2063 | get: function () {
|
2064 | var _a, _b;
|
2065 |
|
2066 | return (_b = (_a = this._activePanel) === null || _a === void 0 ? void 0 : _a.index) !== null && _b !== void 0 ? _b : -1;
|
2067 | },
|
2068 | enumerable: false,
|
2069 | configurable: true
|
2070 | });
|
2071 | Object.defineProperty(__proto, "activePanel", {
|
2072 | |
2073 |
|
2074 |
|
2075 |
|
2076 |
|
2077 |
|
2078 | get: function () {
|
2079 | return this._activePanel;
|
2080 | },
|
2081 | enumerable: false,
|
2082 | configurable: true
|
2083 | });
|
2084 | Object.defineProperty(__proto, "animating", {
|
2085 | |
2086 |
|
2087 |
|
2088 |
|
2089 |
|
2090 |
|
2091 | get: function () {
|
2092 | return this._controller.state.animating;
|
2093 | },
|
2094 | enumerable: false,
|
2095 | configurable: true
|
2096 | });
|
2097 | Object.defineProperty(__proto, "holding", {
|
2098 | |
2099 |
|
2100 |
|
2101 |
|
2102 |
|
2103 |
|
2104 | get: function () {
|
2105 | return this._controller.state.holding;
|
2106 | },
|
2107 | enumerable: false,
|
2108 | configurable: true
|
2109 | });
|
2110 | |
2111 |
|
2112 |
|
2113 |
|
2114 |
|
2115 |
|
2116 |
|
2117 |
|
2118 | __proto.init = function (flicking) {
|
2119 | this._flicking = flicking;
|
2120 |
|
2121 | this._controller.init(flicking);
|
2122 |
|
2123 | return this;
|
2124 | };
|
2125 | |
2126 |
|
2127 |
|
2128 |
|
2129 |
|
2130 |
|
2131 |
|
2132 | __proto.destroy = function () {
|
2133 | this._controller.destroy();
|
2134 |
|
2135 | this._flicking = null;
|
2136 | this._activePanel = null;
|
2137 | };
|
2138 | |
2139 |
|
2140 |
|
2141 |
|
2142 |
|
2143 |
|
2144 |
|
2145 |
|
2146 | __proto.enable = function () {
|
2147 | this._controller.enable();
|
2148 |
|
2149 | return this;
|
2150 | };
|
2151 | |
2152 |
|
2153 |
|
2154 |
|
2155 |
|
2156 |
|
2157 |
|
2158 |
|
2159 | __proto.disable = function () {
|
2160 | this._controller.disable();
|
2161 |
|
2162 | return this;
|
2163 | };
|
2164 | |
2165 |
|
2166 |
|
2167 |
|
2168 |
|
2169 |
|
2170 |
|
2171 |
|
2172 |
|
2173 |
|
2174 |
|
2175 |
|
2176 | __proto.updatePosition = function (_progressInPanel) {
|
2177 | var flicking = getFlickingAttached(this._flicking, "Control");
|
2178 | var camera = flicking.camera;
|
2179 | var activePanel = this._activePanel;
|
2180 |
|
2181 | if (activePanel) {
|
2182 | camera.lookAt(camera.clampToReachablePosition(activePanel.position));
|
2183 | }
|
2184 | };
|
2185 | |
2186 |
|
2187 |
|
2188 |
|
2189 |
|
2190 |
|
2191 |
|
2192 |
|
2193 | __proto.updateInput = function () {
|
2194 | var flicking = getFlickingAttached(this._flicking, "Control");
|
2195 | var camera = flicking.camera;
|
2196 |
|
2197 | this._controller.update(camera.controlParams);
|
2198 |
|
2199 | return this;
|
2200 | };
|
2201 | |
2202 |
|
2203 |
|
2204 |
|
2205 |
|
2206 |
|
2207 |
|
2208 |
|
2209 | __proto.resetActive = function () {
|
2210 | this._activePanel = null;
|
2211 | return this;
|
2212 | };
|
2213 | |
2214 |
|
2215 |
|
2216 |
|
2217 |
|
2218 |
|
2219 |
|
2220 |
|
2221 |
|
2222 |
|
2223 |
|
2224 |
|
2225 |
|
2226 |
|
2227 |
|
2228 |
|
2229 |
|
2230 |
|
2231 |
|
2232 |
|
2233 |
|
2234 |
|
2235 |
|
2236 |
|
2237 |
|
2238 |
|
2239 |
|
2240 |
|
2241 |
|
2242 |
|
2243 |
|
2244 |
|
2245 |
|
2246 |
|
2247 |
|
2248 |
|
2249 |
|
2250 |
|
2251 |
|
2252 |
|
2253 | __proto.moveToPanel = function (panel, _a) {
|
2254 | var duration = _a.duration,
|
2255 | _b = _a.direction,
|
2256 | direction = _b === void 0 ? DIRECTION.NONE : _b,
|
2257 | axesEvent = _a.axesEvent;
|
2258 | return __awaiter(this, void 0, void 0, function () {
|
2259 | var flicking, camera, position, nearestAnchor, camPos_1, camRangeDiff, possiblePositions;
|
2260 | return __generator(this, function (_c) {
|
2261 | flicking = getFlickingAttached(this._flicking, "Control");
|
2262 | camera = flicking.camera;
|
2263 | position = panel.position;
|
2264 | nearestAnchor = camera.findNearestAnchor(position);
|
2265 |
|
2266 | if (panel.removed || !nearestAnchor) {
|
2267 | return [2
|
2268 |
|
2269 | , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(panel.position), CODE.POSITION_NOT_REACHABLE))];
|
2270 | }
|
2271 |
|
2272 | if (!camera.canReach(panel)) {
|
2273 |
|
2274 | position = nearestAnchor.position;
|
2275 | panel = nearestAnchor.panel;
|
2276 | } else if (flicking.circularEnabled) {
|
2277 | camPos_1 = this._controller.position;
|
2278 | camRangeDiff = camera.rangeDiff;
|
2279 | possiblePositions = [position, position + camRangeDiff, position - camRangeDiff].filter(function (pos) {
|
2280 | if (direction === DIRECTION.NONE) return true;
|
2281 | return direction === DIRECTION.PREV ? pos <= camPos_1 : pos >= camPos_1;
|
2282 | });
|
2283 | position = possiblePositions.reduce(function (nearestPosition, pos) {
|
2284 | if (Math.abs(camPos_1 - pos) < Math.abs(camPos_1 - nearestPosition)) {
|
2285 | return pos;
|
2286 | } else {
|
2287 | return nearestPosition;
|
2288 | }
|
2289 | }, Infinity);
|
2290 | }
|
2291 |
|
2292 | this._triggerIndexChangeEvent(panel, panel.position, axesEvent);
|
2293 |
|
2294 | return [2
|
2295 |
|
2296 | , this._animateToPosition({
|
2297 | position: position,
|
2298 | duration: duration,
|
2299 | newActivePanel: panel,
|
2300 | axesEvent: axesEvent
|
2301 | })];
|
2302 | });
|
2303 | });
|
2304 | };
|
2305 | |
2306 |
|
2307 |
|
2308 |
|
2309 |
|
2310 | __proto.setActive = function (newActivePanel, prevActivePanel, isTrusted) {
|
2311 | var _a;
|
2312 |
|
2313 | var flicking = getFlickingAttached(this._flicking, "Control");
|
2314 | this._activePanel = newActivePanel;
|
2315 | flicking.camera.updateAdaptiveHeight();
|
2316 |
|
2317 | if (newActivePanel !== prevActivePanel) {
|
2318 | flicking.trigger(new ComponentEvent(EVENTS.CHANGED, {
|
2319 | index: newActivePanel.index,
|
2320 | panel: newActivePanel,
|
2321 | prevIndex: (_a = prevActivePanel === null || prevActivePanel === void 0 ? void 0 : prevActivePanel.index) !== null && _a !== void 0 ? _a : -1,
|
2322 | prevPanel: prevActivePanel,
|
2323 | isTrusted: isTrusted,
|
2324 | direction: prevActivePanel ? getDirection(prevActivePanel.position, newActivePanel.position) : DIRECTION.NONE
|
2325 | }));
|
2326 | } else {
|
2327 | flicking.trigger(new ComponentEvent(EVENTS.RESTORED, {
|
2328 | isTrusted: isTrusted
|
2329 | }));
|
2330 | }
|
2331 | };
|
2332 |
|
2333 | __proto._triggerIndexChangeEvent = function (panel, position, axesEvent) {
|
2334 | var _a;
|
2335 |
|
2336 | var flicking = getFlickingAttached(this._flicking, "Control");
|
2337 | var triggeringEvent = panel !== this._activePanel ? EVENTS.WILL_CHANGE : EVENTS.WILL_RESTORE;
|
2338 | var camera = flicking.camera;
|
2339 | var activePanel = this._activePanel;
|
2340 | var event = new ComponentEvent(triggeringEvent, {
|
2341 | index: panel.index,
|
2342 | panel: panel,
|
2343 | isTrusted: (axesEvent === null || axesEvent === void 0 ? void 0 : axesEvent.isTrusted) || false,
|
2344 | direction: getDirection((_a = activePanel === null || activePanel === void 0 ? void 0 : activePanel.position) !== null && _a !== void 0 ? _a : camera.position, position)
|
2345 | });
|
2346 | flicking.trigger(event);
|
2347 |
|
2348 | if (event.isCanceled()) {
|
2349 | throw new FlickingError(MESSAGE.STOP_CALLED_BY_USER, CODE.STOP_CALLED_BY_USER);
|
2350 | }
|
2351 | };
|
2352 |
|
2353 | __proto._animateToPosition = function (_a) {
|
2354 | var position = _a.position,
|
2355 | duration = _a.duration,
|
2356 | newActivePanel = _a.newActivePanel,
|
2357 | axesEvent = _a.axesEvent;
|
2358 | return __awaiter(this, void 0, void 0, function () {
|
2359 | var flicking, animate, state;
|
2360 |
|
2361 | var _this = this;
|
2362 |
|
2363 | return __generator(this, function (_b) {
|
2364 | flicking = getFlickingAttached(this._flicking, "Control");
|
2365 |
|
2366 | animate = function () {
|
2367 | return _this._controller.animateTo(position, duration, axesEvent);
|
2368 | };
|
2369 |
|
2370 | state = this._controller.state;
|
2371 | state.targetPanel = newActivePanel;
|
2372 |
|
2373 | if (duration <= 0) {
|
2374 | return [2
|
2375 |
|
2376 | , animate()];
|
2377 | } else {
|
2378 | return [2
|
2379 |
|
2380 | , animate().then(function () {
|
2381 | return __awaiter(_this, void 0, void 0, function () {
|
2382 | return __generator(this, function (_a) {
|
2383 | switch (_a.label) {
|
2384 | case 0:
|
2385 | return [4
|
2386 |
|
2387 | , flicking.renderer.render()];
|
2388 |
|
2389 | case 1:
|
2390 | _a.sent();
|
2391 |
|
2392 | return [2
|
2393 |
|
2394 | ];
|
2395 | }
|
2396 | });
|
2397 | });
|
2398 | }).catch(function (err) {
|
2399 | if (axesEvent && err instanceof FlickingError && err.code === CODE.ANIMATION_INTERRUPTED) return;
|
2400 | throw err;
|
2401 | })];
|
2402 | }
|
2403 | });
|
2404 | });
|
2405 | };
|
2406 |
|
2407 | return Control;
|
2408 | }();
|
2409 |
|
2410 |
|
2411 |
|
2412 |
|
2413 |
|
2414 | var AnchorPoint = function () {
|
2415 | |
2416 |
|
2417 |
|
2418 |
|
2419 |
|
2420 |
|
2421 | function AnchorPoint(_a) {
|
2422 | var index = _a.index,
|
2423 | position = _a.position,
|
2424 | panel = _a.panel;
|
2425 | this._index = index;
|
2426 | this._pos = position;
|
2427 | this._panel = panel;
|
2428 | }
|
2429 |
|
2430 | var __proto = AnchorPoint.prototype;
|
2431 | Object.defineProperty(__proto, "index", {
|
2432 | |
2433 |
|
2434 |
|
2435 |
|
2436 |
|
2437 |
|
2438 | get: function () {
|
2439 | return this._index;
|
2440 | },
|
2441 | enumerable: false,
|
2442 | configurable: true
|
2443 | });
|
2444 | Object.defineProperty(__proto, "position", {
|
2445 | |
2446 |
|
2447 |
|
2448 |
|
2449 |
|
2450 |
|
2451 | get: function () {
|
2452 | return this._pos;
|
2453 | },
|
2454 | enumerable: false,
|
2455 | configurable: true
|
2456 | });
|
2457 | Object.defineProperty(__proto, "panel", {
|
2458 | |
2459 |
|
2460 |
|
2461 |
|
2462 |
|
2463 |
|
2464 | get: function () {
|
2465 | return this._panel;
|
2466 | },
|
2467 | enumerable: false,
|
2468 | configurable: true
|
2469 | });
|
2470 | return AnchorPoint;
|
2471 | }();
|
2472 |
|
2473 |
|
2474 |
|
2475 |
|
2476 |
|
2477 |
|
2478 | var SnapControl = function (_super) {
|
2479 | __extends(SnapControl, _super);
|
2480 |
|
2481 |
|
2482 |
|
2483 | function SnapControl(_a) {
|
2484 | var _b = _a === void 0 ? {} : _a,
|
2485 | _c = _b.count,
|
2486 | count = _c === void 0 ? Infinity : _c;
|
2487 |
|
2488 | var _this = _super.call(this) || this;
|
2489 |
|
2490 | _this._count = count;
|
2491 | return _this;
|
2492 | }
|
2493 |
|
2494 | var __proto = SnapControl.prototype;
|
2495 | Object.defineProperty(__proto, "count", {
|
2496 | |
2497 |
|
2498 |
|
2499 |
|
2500 |
|
2501 |
|
2502 | get: function () {
|
2503 | return this._count;
|
2504 | },
|
2505 | set: function (val) {
|
2506 | this._count = val;
|
2507 | },
|
2508 | enumerable: false,
|
2509 | configurable: true
|
2510 | });
|
2511 | |
2512 |
|
2513 |
|
2514 |
|
2515 |
|
2516 |
|
2517 |
|
2518 |
|
2519 |
|
2520 |
|
2521 |
|
2522 |
|
2523 |
|
2524 |
|
2525 |
|
2526 |
|
2527 |
|
2528 |
|
2529 |
|
2530 |
|
2531 |
|
2532 |
|
2533 |
|
2534 |
|
2535 |
|
2536 |
|
2537 |
|
2538 |
|
2539 |
|
2540 |
|
2541 |
|
2542 |
|
2543 |
|
2544 |
|
2545 |
|
2546 |
|
2547 |
|
2548 | __proto.moveToPosition = function (position, duration, axesEvent) {
|
2549 | return __awaiter(this, void 0, void 0, function () {
|
2550 | var flicking, camera, activeAnchor, anchorAtCamera, state, snapThreshold, posDelta, absPosDelta, snapDelta, targetAnchor;
|
2551 | return __generator(this, function (_a) {
|
2552 | flicking = getFlickingAttached(this._flicking, "Control");
|
2553 | camera = flicking.camera;
|
2554 | activeAnchor = camera.findActiveAnchor();
|
2555 | anchorAtCamera = camera.findNearestAnchor(camera.position);
|
2556 | state = flicking.control.controller.state;
|
2557 |
|
2558 | if (!activeAnchor || !anchorAtCamera) {
|
2559 | return [2
|
2560 |
|
2561 | , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE))];
|
2562 | }
|
2563 |
|
2564 | snapThreshold = this._calcSnapThreshold(position, activeAnchor);
|
2565 | posDelta = flicking.animating ? state.delta : position - camera.position;
|
2566 | absPosDelta = Math.abs(posDelta);
|
2567 | snapDelta = axesEvent && axesEvent.delta[POSITION_KEY] !== 0 ? Math.abs(axesEvent.delta[POSITION_KEY]) : absPosDelta;
|
2568 |
|
2569 | if (snapDelta >= snapThreshold && snapDelta > 0) {
|
2570 |
|
2571 | targetAnchor = this._findSnappedAnchor(position, anchorAtCamera);
|
2572 | } else if (absPosDelta >= flicking.threshold && absPosDelta > 0) {
|
2573 |
|
2574 | targetAnchor = this._findAdjacentAnchor(posDelta, anchorAtCamera);
|
2575 | } else {
|
2576 |
|
2577 | targetAnchor = anchorAtCamera;
|
2578 | }
|
2579 |
|
2580 | this._triggerIndexChangeEvent(targetAnchor.panel, position, axesEvent);
|
2581 |
|
2582 | return [2
|
2583 |
|
2584 | , this._animateToPosition({
|
2585 | position: camera.clampToReachablePosition(targetAnchor.position),
|
2586 | duration: duration,
|
2587 | newActivePanel: targetAnchor.panel,
|
2588 | axesEvent: axesEvent
|
2589 | })];
|
2590 | });
|
2591 | });
|
2592 | };
|
2593 |
|
2594 | __proto._findSnappedAnchor = function (position, anchorAtCamera) {
|
2595 | var flicking = getFlickingAttached(this._flicking, "Control");
|
2596 | var camera = flicking.camera;
|
2597 | var count = this._count;
|
2598 | var currentPos = camera.position;
|
2599 | var clampedPosition = camera.clampToReachablePosition(position);
|
2600 | var anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
|
2601 |
|
2602 | if (!anchorAtCamera || !anchorAtPosition) {
|
2603 | throw new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE);
|
2604 | }
|
2605 |
|
2606 | if (!isFinite(count)) {
|
2607 | return anchorAtPosition;
|
2608 | }
|
2609 |
|
2610 | var panelCount = flicking.panelCount;
|
2611 | var anchors = camera.anchorPoints;
|
2612 | var loopCount = Math.sign(position - currentPos) * Math.floor(Math.abs(position - currentPos) / camera.rangeDiff);
|
2613 |
|
2614 | if (position > currentPos && anchorAtPosition.index < anchorAtCamera.index || anchorAtPosition.position > anchorAtCamera.position && anchorAtPosition.index === anchorAtCamera.index) {
|
2615 | loopCount += 1;
|
2616 | } else if (position < currentPos && anchorAtPosition.index > anchorAtCamera.index || anchorAtPosition.position < anchorAtCamera.position && anchorAtPosition.index === anchorAtCamera.index) {
|
2617 | loopCount -= 1;
|
2618 | }
|
2619 |
|
2620 | var circularIndexOffset = loopCount * panelCount;
|
2621 | var anchorAtPositionIndex = anchorAtPosition.index + circularIndexOffset;
|
2622 |
|
2623 | if (Math.abs(anchorAtPositionIndex - anchorAtCamera.index) <= count) {
|
2624 | var anchor = anchors[anchorAtPosition.index];
|
2625 | return new AnchorPoint({
|
2626 | index: anchor.index,
|
2627 | position: anchor.position + loopCount * camera.rangeDiff,
|
2628 | panel: anchor.panel
|
2629 | });
|
2630 | }
|
2631 |
|
2632 | if (flicking.circularEnabled) {
|
2633 | var targetAnchor = anchors[circulateIndex(anchorAtCamera.index + Math.sign(position - currentPos) * count, panelCount)];
|
2634 | var loop = Math.floor(count / panelCount);
|
2635 |
|
2636 | if (position > currentPos && targetAnchor.index < anchorAtCamera.index) {
|
2637 | loop += 1;
|
2638 | } else if (position < currentPos && targetAnchor.index > anchorAtCamera.index) {
|
2639 | loop -= 1;
|
2640 | }
|
2641 |
|
2642 | return new AnchorPoint({
|
2643 | index: targetAnchor.index,
|
2644 | position: targetAnchor.position + loop * camera.rangeDiff,
|
2645 | panel: targetAnchor.panel
|
2646 | });
|
2647 | } else {
|
2648 | return anchors[clamp(anchorAtCamera.index + Math.sign(position - currentPos) * count, 0, anchors.length - 1)];
|
2649 | }
|
2650 | };
|
2651 |
|
2652 | __proto._findAdjacentAnchor = function (posDelta, anchorAtCamera) {
|
2653 | var _a;
|
2654 |
|
2655 | var flicking = getFlickingAttached(this._flicking, "Control");
|
2656 | var camera = flicking.camera;
|
2657 | var adjacentAnchor = (_a = posDelta > 0 ? camera.getNextAnchor(anchorAtCamera) : camera.getPrevAnchor(anchorAtCamera)) !== null && _a !== void 0 ? _a : anchorAtCamera;
|
2658 | return adjacentAnchor;
|
2659 | };
|
2660 |
|
2661 | __proto._calcSnapThreshold = function (position, activeAnchor) {
|
2662 | var isNextDirection = position > activeAnchor.position;
|
2663 | var panel = activeAnchor.panel;
|
2664 | var panelSize = panel.size;
|
2665 | var alignPos = panel.alignPosition;
|
2666 |
|
2667 | |
2668 |
|
2669 |
|
2670 |
|
2671 |
|
2672 |
|
2673 | return isNextDirection ? panelSize - alignPos + panel.margin.next : alignPos + panel.margin.prev;
|
2674 | };
|
2675 |
|
2676 | return SnapControl;
|
2677 | }(Control);
|
2678 |
|
2679 |
|
2680 |
|
2681 |
|
2682 |
|
2683 |
|
2684 | var FreeControl = function (_super) {
|
2685 | __extends(FreeControl, _super);
|
2686 |
|
2687 |
|
2688 |
|
2689 | function FreeControl(_a) {
|
2690 | var _b = _a === void 0 ? {} : _a,
|
2691 | _c = _b.stopAtEdge,
|
2692 | stopAtEdge = _c === void 0 ? true : _c;
|
2693 |
|
2694 | var _this = _super.call(this) || this;
|
2695 |
|
2696 | _this._stopAtEdge = stopAtEdge;
|
2697 | return _this;
|
2698 | }
|
2699 |
|
2700 | var __proto = FreeControl.prototype;
|
2701 | Object.defineProperty(__proto, "stopAtEdge", {
|
2702 | |
2703 |
|
2704 |
|
2705 |
|
2706 |
|
2707 |
|
2708 | get: function () {
|
2709 | return this._stopAtEdge;
|
2710 | },
|
2711 | set: function (val) {
|
2712 | this._stopAtEdge = val;
|
2713 | },
|
2714 | enumerable: false,
|
2715 | configurable: true
|
2716 | });
|
2717 | |
2718 |
|
2719 |
|
2720 |
|
2721 |
|
2722 |
|
2723 |
|
2724 |
|
2725 |
|
2726 |
|
2727 |
|
2728 | __proto.updatePosition = function (progressInPanel) {
|
2729 | var flicking = getFlickingAttached(this._flicking, "Control");
|
2730 | var camera = flicking.camera;
|
2731 | var activePanel = this._activePanel;
|
2732 |
|
2733 | if (activePanel) {
|
2734 | var panelRange = activePanel.range;
|
2735 | var newPosition = panelRange.min + (panelRange.max - panelRange.min) * progressInPanel;
|
2736 | camera.lookAt(camera.clampToReachablePosition(newPosition));
|
2737 | }
|
2738 | };
|
2739 | |
2740 |
|
2741 |
|
2742 |
|
2743 |
|
2744 |
|
2745 |
|
2746 |
|
2747 |
|
2748 |
|
2749 |
|
2750 |
|
2751 |
|
2752 |
|
2753 |
|
2754 |
|
2755 |
|
2756 |
|
2757 |
|
2758 |
|
2759 |
|
2760 |
|
2761 |
|
2762 |
|
2763 |
|
2764 |
|
2765 |
|
2766 |
|
2767 |
|
2768 |
|
2769 |
|
2770 |
|
2771 |
|
2772 |
|
2773 |
|
2774 |
|
2775 |
|
2776 |
|
2777 | __proto.moveToPosition = function (position, duration, axesEvent) {
|
2778 | return __awaiter(this, void 0, void 0, function () {
|
2779 | var flicking, camera, targetPos, anchorAtPosition, targetPanel;
|
2780 | return __generator(this, function (_a) {
|
2781 | flicking = getFlickingAttached(this._flicking, "Control");
|
2782 | camera = flicking.camera;
|
2783 | targetPos = camera.clampToReachablePosition(position);
|
2784 | anchorAtPosition = camera.findAnchorIncludePosition(targetPos);
|
2785 |
|
2786 | if (!anchorAtPosition) {
|
2787 | return [2
|
2788 |
|
2789 | , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE))];
|
2790 | }
|
2791 |
|
2792 | targetPanel = anchorAtPosition.panel;
|
2793 |
|
2794 | if (targetPanel !== this._activePanel) {
|
2795 | this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
|
2796 | }
|
2797 |
|
2798 | return [2
|
2799 |
|
2800 | , this._animateToPosition({
|
2801 | position: this._stopAtEdge ? targetPos : position,
|
2802 | duration: duration,
|
2803 | newActivePanel: targetPanel,
|
2804 | axesEvent: axesEvent
|
2805 | })];
|
2806 | });
|
2807 | });
|
2808 | };
|
2809 |
|
2810 | return FreeControl;
|
2811 | }(Control);
|
2812 |
|
2813 |
|
2814 |
|
2815 |
|
2816 |
|
2817 |
|
2818 | var StrictControl = function (_super) {
|
2819 | __extends(StrictControl, _super);
|
2820 |
|
2821 |
|
2822 |
|
2823 | function StrictControl(_a) {
|
2824 | var _b = _a === void 0 ? {} : _a,
|
2825 | _c = _b.count,
|
2826 | count = _c === void 0 ? 1 : _c;
|
2827 |
|
2828 | var _this = _super.call(this) || this;
|
2829 |
|
2830 | _this.setActive = function (newActivePanel, prevActivePanel, isTrusted) {
|
2831 | _super.prototype.setActive.call(_this, newActivePanel, prevActivePanel, isTrusted);
|
2832 |
|
2833 | _this.updateInput();
|
2834 | };
|
2835 |
|
2836 | _this._count = count;
|
2837 |
|
2838 | _this._resetIndexRange();
|
2839 |
|
2840 | return _this;
|
2841 | }
|
2842 |
|
2843 | var __proto = StrictControl.prototype;
|
2844 | Object.defineProperty(__proto, "count", {
|
2845 | |
2846 |
|
2847 |
|
2848 |
|
2849 |
|
2850 |
|
2851 | get: function () {
|
2852 | return this._count;
|
2853 | },
|
2854 | set: function (val) {
|
2855 | this._count = val;
|
2856 | },
|
2857 | enumerable: false,
|
2858 | configurable: true
|
2859 | });
|
2860 | |
2861 |
|
2862 |
|
2863 |
|
2864 |
|
2865 |
|
2866 | __proto.destroy = function () {
|
2867 | _super.prototype.destroy.call(this);
|
2868 |
|
2869 | this._resetIndexRange();
|
2870 | };
|
2871 | |
2872 |
|
2873 |
|
2874 |
|
2875 |
|
2876 |
|
2877 |
|
2878 |
|
2879 | __proto.updateInput = function () {
|
2880 | var _a;
|
2881 |
|
2882 | var flicking = getFlickingAttached(this._flicking, "Control");
|
2883 | var camera = flicking.camera;
|
2884 | var renderer = flicking.renderer;
|
2885 | var controller = this._controller;
|
2886 | var controlParams = camera.controlParams;
|
2887 | var count = this._count;
|
2888 | var activePanel = controller.state.animating ? (_a = camera.findNearestAnchor(camera.position)) === null || _a === void 0 ? void 0 : _a.panel : this._activePanel;
|
2889 |
|
2890 | if (!activePanel) {
|
2891 | controller.update(controlParams);
|
2892 |
|
2893 | this._resetIndexRange();
|
2894 |
|
2895 | return this;
|
2896 | }
|
2897 |
|
2898 | var cameraRange = controlParams.range;
|
2899 | var currentPos = activePanel.position;
|
2900 | var currentIndex = activePanel.index;
|
2901 | var panelCount = renderer.panelCount;
|
2902 | var prevPanelIndex = currentIndex - count;
|
2903 | var nextPanelIndex = currentIndex + count;
|
2904 |
|
2905 | if (prevPanelIndex < 0) {
|
2906 | prevPanelIndex = flicking.circularEnabled ? getMinusCompensatedIndex((prevPanelIndex + 1) % panelCount - 1, panelCount) : clamp(prevPanelIndex, 0, panelCount - 1);
|
2907 | }
|
2908 |
|
2909 | if (nextPanelIndex >= panelCount) {
|
2910 | nextPanelIndex = flicking.circularEnabled ? nextPanelIndex % panelCount : clamp(nextPanelIndex, 0, panelCount - 1);
|
2911 | }
|
2912 |
|
2913 | var prevPanel = renderer.panels[prevPanelIndex];
|
2914 | var nextPanel = renderer.panels[nextPanelIndex];
|
2915 | var prevPos = Math.max(prevPanel.position, cameraRange.min);
|
2916 | var nextPos = Math.min(nextPanel.position, cameraRange.max);
|
2917 |
|
2918 | if (prevPos > currentPos) {
|
2919 | prevPos -= camera.rangeDiff;
|
2920 | }
|
2921 |
|
2922 | if (nextPos < currentPos) {
|
2923 | nextPos += camera.rangeDiff;
|
2924 | }
|
2925 |
|
2926 | controlParams.range = {
|
2927 | min: prevPos,
|
2928 | max: nextPos
|
2929 | };
|
2930 |
|
2931 | if (controlParams.circular) {
|
2932 | if (controlParams.position < prevPos) {
|
2933 | controlParams.position += camera.rangeDiff;
|
2934 | }
|
2935 |
|
2936 | if (controlParams.position > nextPos) {
|
2937 | controlParams.position -= camera.rangeDiff;
|
2938 | }
|
2939 | }
|
2940 |
|
2941 | controlParams.circular = false;
|
2942 | controller.update(controlParams);
|
2943 | this._indexRange = {
|
2944 | min: prevPanel.index,
|
2945 | max: nextPanel.index
|
2946 | };
|
2947 | return this;
|
2948 | };
|
2949 | |
2950 |
|
2951 |
|
2952 |
|
2953 |
|
2954 |
|
2955 |
|
2956 |
|
2957 |
|
2958 |
|
2959 |
|
2960 |
|
2961 |
|
2962 |
|
2963 |
|
2964 |
|
2965 |
|
2966 |
|
2967 |
|
2968 |
|
2969 |
|
2970 |
|
2971 |
|
2972 |
|
2973 |
|
2974 |
|
2975 |
|
2976 |
|
2977 |
|
2978 |
|
2979 |
|
2980 |
|
2981 |
|
2982 |
|
2983 |
|
2984 |
|
2985 |
|
2986 |
|
2987 | __proto.moveToPosition = function (position, duration, axesEvent) {
|
2988 | return __awaiter(this, void 0, void 0, function () {
|
2989 | var flicking, camera, activePanel, axesRange, indexRange, cameraRange, clampedPosition, anchorAtPosition, prevPos, isOverThreshold, adjacentAnchor, targetPos, targetPanel, anchors, firstAnchor, lastAnchor, shouldBounceToFirst, shouldBounceToLast, targetAnchor;
|
2990 | return __generator(this, function (_a) {
|
2991 | flicking = getFlickingAttached(this._flicking, "Control");
|
2992 | camera = flicking.camera;
|
2993 | activePanel = this._activePanel;
|
2994 | axesRange = this._controller.range;
|
2995 | indexRange = this._indexRange;
|
2996 | cameraRange = camera.range;
|
2997 | clampedPosition = clamp(camera.clampToReachablePosition(position), axesRange[0], axesRange[1]);
|
2998 | anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
|
2999 |
|
3000 | if (!anchorAtPosition || !activePanel) {
|
3001 | return [2
|
3002 |
|
3003 | , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE))];
|
3004 | }
|
3005 |
|
3006 | prevPos = activePanel.position;
|
3007 | isOverThreshold = Math.abs(position - prevPos) >= flicking.threshold;
|
3008 | adjacentAnchor = position > prevPos ? camera.getNextAnchor(anchorAtPosition) : camera.getPrevAnchor(anchorAtPosition);
|
3009 | anchors = camera.anchorPoints;
|
3010 | firstAnchor = anchors[0];
|
3011 | lastAnchor = anchors[anchors.length - 1];
|
3012 | shouldBounceToFirst = position <= cameraRange.min && isBetween(firstAnchor.panel.index, indexRange.min, indexRange.max);
|
3013 | shouldBounceToLast = position >= cameraRange.max && isBetween(lastAnchor.panel.index, indexRange.min, indexRange.max);
|
3014 |
|
3015 | if (shouldBounceToFirst || shouldBounceToLast) {
|
3016 | targetAnchor = position < cameraRange.min ? firstAnchor : lastAnchor;
|
3017 | targetPanel = targetAnchor.panel;
|
3018 | targetPos = targetAnchor.position;
|
3019 | } else if (isOverThreshold && anchorAtPosition.position !== activePanel.position) {
|
3020 |
|
3021 | targetPanel = anchorAtPosition.panel;
|
3022 | targetPos = anchorAtPosition.position;
|
3023 | } else if (isOverThreshold && adjacentAnchor && isBetween(adjacentAnchor.index, indexRange.min, indexRange.max)) {
|
3024 |
|
3025 | targetPanel = adjacentAnchor.panel;
|
3026 | targetPos = adjacentAnchor.position;
|
3027 | } else {
|
3028 |
|
3029 | targetPos = camera.clampToReachablePosition(activePanel.position);
|
3030 | targetPanel = activePanel;
|
3031 | }
|
3032 |
|
3033 | this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
|
3034 |
|
3035 | return [2
|
3036 |
|
3037 | , this._animateToPosition({
|
3038 | position: targetPos,
|
3039 | duration: duration,
|
3040 | newActivePanel: targetPanel,
|
3041 | axesEvent: axesEvent
|
3042 | })];
|
3043 | });
|
3044 | });
|
3045 | };
|
3046 |
|
3047 | __proto._resetIndexRange = function () {
|
3048 | this._indexRange = {
|
3049 | min: 0,
|
3050 | max: 0
|
3051 | };
|
3052 | };
|
3053 |
|
3054 | return StrictControl;
|
3055 | }(Control);
|
3056 |
|
3057 |
|
3058 |
|
3059 |
|
3060 |
|
3061 |
|
3062 | var Camera = function () {
|
3063 |
|
3064 | function Camera(_a) {
|
3065 | var _this = this;
|
3066 |
|
3067 | var _b = _a === void 0 ? {} : _a,
|
3068 | _c = _b.align,
|
3069 | align = _c === void 0 ? ALIGN.CENTER : _c;
|
3070 |
|
3071 | this._checkTranslateSupport = function () {
|
3072 | var e_1, _a;
|
3073 |
|
3074 | var transforms = ["webkitTransform", "msTransform", "MozTransform", "OTransform", "transform"];
|
3075 | var supportedStyle = document.documentElement.style;
|
3076 | var transformName = "";
|
3077 |
|
3078 | try {
|
3079 | for (var transforms_1 = __values(transforms), transforms_1_1 = transforms_1.next(); !transforms_1_1.done; transforms_1_1 = transforms_1.next()) {
|
3080 | var prefixedTransform = transforms_1_1.value;
|
3081 |
|
3082 | if (prefixedTransform in supportedStyle) {
|
3083 | transformName = prefixedTransform;
|
3084 | }
|
3085 | }
|
3086 | } catch (e_1_1) {
|
3087 | e_1 = {
|
3088 | error: e_1_1
|
3089 | };
|
3090 | } finally {
|
3091 | try {
|
3092 | if (transforms_1_1 && !transforms_1_1.done && (_a = transforms_1.return)) _a.call(transforms_1);
|
3093 | } finally {
|
3094 | if (e_1) throw e_1.error;
|
3095 | }
|
3096 | }
|
3097 |
|
3098 | if (!transformName) {
|
3099 | throw new FlickingError(MESSAGE.TRANSFORM_NOT_SUPPORTED, CODE.TRANSFORM_NOT_SUPPORTED);
|
3100 | }
|
3101 |
|
3102 | _this._transform = transformName;
|
3103 | };
|
3104 |
|
3105 | this._flicking = null;
|
3106 |
|
3107 | this._resetInternalValues();
|
3108 |
|
3109 |
|
3110 | this._align = align;
|
3111 | }
|
3112 |
|
3113 | var __proto = Camera.prototype;
|
3114 | Object.defineProperty(__proto, "element", {
|
3115 |
|
3116 |
|
3117 | |
3118 |
|
3119 |
|
3120 |
|
3121 |
|
3122 |
|
3123 | get: function () {
|
3124 | return this._el;
|
3125 | },
|
3126 | enumerable: false,
|
3127 | configurable: true
|
3128 | });
|
3129 | Object.defineProperty(__proto, "position", {
|
3130 | |
3131 |
|
3132 |
|
3133 |
|
3134 |
|
3135 |
|
3136 | get: function () {
|
3137 | return this._position;
|
3138 | },
|
3139 | enumerable: false,
|
3140 | configurable: true
|
3141 | });
|
3142 | Object.defineProperty(__proto, "alignPosition", {
|
3143 | |
3144 |
|
3145 |
|
3146 |
|
3147 |
|
3148 |
|
3149 | get: function () {
|
3150 | return this._alignPos;
|
3151 | },
|
3152 | enumerable: false,
|
3153 | configurable: true
|
3154 | });
|
3155 | Object.defineProperty(__proto, "offset", {
|
3156 | |
3157 |
|
3158 |
|
3159 |
|
3160 |
|
3161 |
|
3162 |
|
3163 | get: function () {
|
3164 | return this._offset;
|
3165 | },
|
3166 | enumerable: false,
|
3167 | configurable: true
|
3168 | });
|
3169 | Object.defineProperty(__proto, "range", {
|
3170 | |
3171 |
|
3172 |
|
3173 |
|
3174 |
|
3175 |
|
3176 |
|
3177 |
|
3178 | get: function () {
|
3179 | return this._range;
|
3180 | },
|
3181 | enumerable: false,
|
3182 | configurable: true
|
3183 | });
|
3184 | Object.defineProperty(__proto, "rangeDiff", {
|
3185 | |
3186 |
|
3187 |
|
3188 |
|
3189 |
|
3190 |
|
3191 | get: function () {
|
3192 | return this._range.max - this._range.min;
|
3193 | },
|
3194 | enumerable: false,
|
3195 | configurable: true
|
3196 | });
|
3197 | Object.defineProperty(__proto, "visiblePanels", {
|
3198 | |
3199 |
|
3200 |
|
3201 |
|
3202 |
|
3203 |
|
3204 | get: function () {
|
3205 | return this._visiblePanels;
|
3206 | },
|
3207 | enumerable: false,
|
3208 | configurable: true
|
3209 | });
|
3210 | Object.defineProperty(__proto, "visibleRange", {
|
3211 | |
3212 |
|
3213 |
|
3214 |
|
3215 |
|
3216 |
|
3217 |
|
3218 |
|
3219 | get: function () {
|
3220 | return {
|
3221 | min: this._position - this._alignPos,
|
3222 | max: this._position - this._alignPos + this.size
|
3223 | };
|
3224 | },
|
3225 | enumerable: false,
|
3226 | configurable: true
|
3227 | });
|
3228 | Object.defineProperty(__proto, "anchorPoints", {
|
3229 | |
3230 |
|
3231 |
|
3232 |
|
3233 |
|
3234 |
|
3235 | get: function () {
|
3236 | return this._anchors;
|
3237 | },
|
3238 | enumerable: false,
|
3239 | configurable: true
|
3240 | });
|
3241 | Object.defineProperty(__proto, "controlParams", {
|
3242 | |
3243 |
|
3244 |
|
3245 |
|
3246 |
|
3247 |
|
3248 | get: function () {
|
3249 | return {
|
3250 | range: this._range,
|
3251 | position: this._position,
|
3252 | circular: false
|
3253 | };
|
3254 | },
|
3255 | enumerable: false,
|
3256 | configurable: true
|
3257 | });
|
3258 | Object.defineProperty(__proto, "atEdge", {
|
3259 | |
3260 |
|
3261 |
|
3262 |
|
3263 |
|
3264 |
|
3265 | get: function () {
|
3266 | return this._position <= this._range.min || this._position >= this._range.max;
|
3267 | },
|
3268 | enumerable: false,
|
3269 | configurable: true
|
3270 | });
|
3271 | Object.defineProperty(__proto, "size", {
|
3272 | |
3273 |
|
3274 |
|
3275 |
|
3276 |
|
3277 |
|
3278 | get: function () {
|
3279 | var flicking = this._flicking;
|
3280 | return flicking ? flicking.horizontal ? flicking.viewport.width : flicking.viewport.height : 0;
|
3281 | },
|
3282 | enumerable: false,
|
3283 | configurable: true
|
3284 | });
|
3285 | Object.defineProperty(__proto, "progress", {
|
3286 | |
3287 |
|
3288 |
|
3289 |
|
3290 |
|
3291 |
|
3292 |
|
3293 |
|
3294 | get: function () {
|
3295 | var flicking = this._flicking;
|
3296 | var position = this._position + this._offset;
|
3297 | var nearestAnchor = this.findNearestAnchor(this._position);
|
3298 |
|
3299 | if (!flicking || !nearestAnchor) {
|
3300 | return NaN;
|
3301 | }
|
3302 |
|
3303 | var nearestPanel = nearestAnchor.panel;
|
3304 | var panelPos = nearestPanel.position + nearestPanel.offset;
|
3305 | var bounceSize = flicking.control.controller.bounce;
|
3306 | var _a = this.range,
|
3307 | prevRange = _a.min,
|
3308 | nextRange = _a.max;
|
3309 | var rangeDiff = this.rangeDiff;
|
3310 |
|
3311 | if (position === panelPos) {
|
3312 | return nearestPanel.index;
|
3313 | }
|
3314 |
|
3315 | if (position < panelPos) {
|
3316 | var prevPanel = nearestPanel.prev();
|
3317 | var prevPosition = prevPanel ? prevPanel.position + prevPanel.offset : prevRange - bounceSize[0];
|
3318 |
|
3319 | if (prevPosition > panelPos) {
|
3320 | prevPosition -= rangeDiff;
|
3321 | }
|
3322 |
|
3323 | return nearestPanel.index - 1 + getProgress(position, prevPosition, panelPos);
|
3324 | } else {
|
3325 | var nextPanel = nearestPanel.next();
|
3326 | var nextPosition = nextPanel ? nextPanel.position + nextPanel.offset : nextRange + bounceSize[1];
|
3327 |
|
3328 | if (nextPosition < panelPos) {
|
3329 | nextPosition += rangeDiff;
|
3330 | }
|
3331 |
|
3332 | return nearestPanel.index + getProgress(position, panelPos, nextPosition);
|
3333 | }
|
3334 | },
|
3335 | enumerable: false,
|
3336 | configurable: true
|
3337 | });
|
3338 | Object.defineProperty(__proto, "align", {
|
3339 |
|
3340 |
|
3341 | |
3342 |
|
3343 |
|
3344 |
|
3345 |
|
3346 | get: function () {
|
3347 | return this._align;
|
3348 | },
|
3349 |
|
3350 | set: function (val) {
|
3351 | this._align = val;
|
3352 | },
|
3353 | enumerable: false,
|
3354 | configurable: true
|
3355 | });
|
3356 | |
3357 |
|
3358 |
|
3359 |
|
3360 |
|
3361 |
|
3362 |
|
3363 |
|
3364 |
|
3365 |
|
3366 |
|
3367 | __proto.init = function (flicking) {
|
3368 | this._flicking = flicking;
|
3369 | var viewportEl = flicking.viewport.element;
|
3370 | checkExistence(viewportEl.firstElementChild, "First element child of the viewport element");
|
3371 | this._el = viewportEl.firstElementChild;
|
3372 |
|
3373 | this._checkTranslateSupport();
|
3374 |
|
3375 | return this;
|
3376 | };
|
3377 | |
3378 |
|
3379 |
|
3380 |
|
3381 |
|
3382 |
|
3383 |
|
3384 | __proto.destroy = function () {
|
3385 | this._flicking = null;
|
3386 |
|
3387 | this._resetInternalValues();
|
3388 |
|
3389 | return this;
|
3390 | };
|
3391 | |
3392 |
|
3393 |
|
3394 |
|
3395 |
|
3396 |
|
3397 |
|
3398 |
|
3399 |
|
3400 |
|
3401 |
|
3402 | __proto.lookAt = function (pos) {
|
3403 | var prevPos = this._position;
|
3404 | this._position = pos;
|
3405 |
|
3406 | this._refreshVisiblePanels();
|
3407 |
|
3408 | this._checkNeedPanel();
|
3409 |
|
3410 | this._checkReachEnd(prevPos, pos);
|
3411 |
|
3412 | this._applyTransform();
|
3413 | };
|
3414 | |
3415 |
|
3416 |
|
3417 |
|
3418 |
|
3419 |
|
3420 |
|
3421 |
|
3422 |
|
3423 |
|
3424 | __proto.getPrevAnchor = function (anchor) {
|
3425 | return this._anchors[anchor.index - 1] || null;
|
3426 | };
|
3427 | |
3428 |
|
3429 |
|
3430 |
|
3431 |
|
3432 |
|
3433 |
|
3434 |
|
3435 |
|
3436 |
|
3437 | __proto.getNextAnchor = function (anchor) {
|
3438 | return this._anchors[anchor.index + 1] || null;
|
3439 | };
|
3440 | |
3441 |
|
3442 |
|
3443 |
|
3444 |
|
3445 |
|
3446 |
|
3447 |
|
3448 |
|
3449 |
|
3450 | __proto.getProgressInPanel = function (panel) {
|
3451 | var panelRange = panel.range;
|
3452 | return (this._position - panelRange.min) / (panelRange.max - panelRange.min);
|
3453 | };
|
3454 | |
3455 |
|
3456 |
|
3457 |
|
3458 |
|
3459 |
|
3460 |
|
3461 |
|
3462 |
|
3463 |
|
3464 | __proto.findAnchorIncludePosition = function (position) {
|
3465 | var anchors = this._anchors;
|
3466 | var anchorsIncludingPosition = anchors.filter(function (anchor) {
|
3467 | return anchor.panel.includePosition(position, true);
|
3468 | });
|
3469 | return anchorsIncludingPosition.reduce(function (nearest, anchor) {
|
3470 | if (!nearest) return anchor;
|
3471 | return Math.abs(nearest.position - position) < Math.abs(anchor.position - position) ? nearest : anchor;
|
3472 | }, null);
|
3473 | };
|
3474 | |
3475 |
|
3476 |
|
3477 |
|
3478 |
|
3479 |
|
3480 |
|
3481 |
|
3482 |
|
3483 |
|
3484 | __proto.findNearestAnchor = function (position) {
|
3485 | var anchors = this._anchors;
|
3486 | if (anchors.length <= 0) return null;
|
3487 | var prevDist = Infinity;
|
3488 |
|
3489 | for (var anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
|
3490 | var anchor = anchors[anchorIdx];
|
3491 | var dist = Math.abs(anchor.position - position);
|
3492 |
|
3493 | if (dist > prevDist) {
|
3494 |
|
3495 | return anchors[anchorIdx - 1];
|
3496 | }
|
3497 |
|
3498 | prevDist = dist;
|
3499 | }
|
3500 |
|
3501 |
|
3502 | return anchors[anchors.length - 1];
|
3503 | };
|
3504 | |
3505 |
|
3506 |
|
3507 |
|
3508 |
|
3509 |
|
3510 |
|
3511 | __proto.findActiveAnchor = function () {
|
3512 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
3513 | var activeIndex = flicking.control.activeIndex;
|
3514 | return find(this._anchors, function (anchor) {
|
3515 | return anchor.panel.index === activeIndex;
|
3516 | });
|
3517 | };
|
3518 | |
3519 |
|
3520 |
|
3521 |
|
3522 |
|
3523 |
|
3524 |
|
3525 |
|
3526 | __proto.clampToReachablePosition = function (position) {
|
3527 | var range = this._range;
|
3528 | return clamp(position, range.min, range.max);
|
3529 | };
|
3530 | |
3531 |
|
3532 |
|
3533 |
|
3534 |
|
3535 |
|
3536 |
|
3537 |
|
3538 | __proto.canReach = function (panel) {
|
3539 | var range = this._range;
|
3540 | if (panel.removed) return false;
|
3541 | var panelPos = panel.position;
|
3542 | return panelPos >= range.min && panelPos <= range.max;
|
3543 | };
|
3544 | |
3545 |
|
3546 |
|
3547 |
|
3548 |
|
3549 |
|
3550 |
|
3551 |
|
3552 | __proto.canSee = function (panel) {
|
3553 | var visibleRange = this.visibleRange;
|
3554 |
|
3555 | return panel.includeRange(visibleRange.min, visibleRange.max, false);
|
3556 | };
|
3557 | |
3558 |
|
3559 |
|
3560 |
|
3561 |
|
3562 |
|
3563 |
|
3564 |
|
3565 | __proto.updateAlignPos = function () {
|
3566 | var align = this._align;
|
3567 | var alignVal = typeof align === "object" ? align.camera : align;
|
3568 | this._alignPos = parseAlign$1(alignVal, this.size);
|
3569 | return this;
|
3570 | };
|
3571 | |
3572 |
|
3573 |
|
3574 |
|
3575 |
|
3576 |
|
3577 |
|
3578 |
|
3579 |
|
3580 |
|
3581 |
|
3582 | __proto.updateAnchors = function () {
|
3583 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
3584 | var panels = flicking.renderer.panels;
|
3585 | this._anchors = panels.map(function (panel, index) {
|
3586 | return new AnchorPoint({
|
3587 | index: index,
|
3588 | position: panel.position,
|
3589 | panel: panel
|
3590 | });
|
3591 | });
|
3592 | return this;
|
3593 | };
|
3594 | |
3595 |
|
3596 |
|
3597 |
|
3598 |
|
3599 |
|
3600 |
|
3601 |
|
3602 |
|
3603 |
|
3604 |
|
3605 | __proto.updateAdaptiveHeight = function () {
|
3606 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
3607 | var activePanel = flicking.control.activePanel;
|
3608 | if (!flicking.horizontal || !flicking.adaptive || !activePanel) return;
|
3609 | flicking.viewport.setSize({
|
3610 | height: activePanel.height
|
3611 | });
|
3612 | };
|
3613 |
|
3614 | __proto.updateOffset = function () {
|
3615 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
3616 | var unRenderedPanels = flicking.panels.filter(function (panel) {
|
3617 | return !panel.rendered;
|
3618 | });
|
3619 | var position = this._position;
|
3620 | this._offset = unRenderedPanels.filter(function (panel) {
|
3621 | return panel.position + panel.offset < position;
|
3622 | }).reduce(function (offset, panel) {
|
3623 | return offset + panel.sizeIncludingMargin;
|
3624 | }, 0);
|
3625 |
|
3626 | this._applyTransform();
|
3627 | };
|
3628 | |
3629 |
|
3630 |
|
3631 |
|
3632 |
|
3633 |
|
3634 |
|
3635 |
|
3636 | __proto.resetNeedPanelHistory = function () {
|
3637 | this._needPanelTriggered = {
|
3638 | prev: false,
|
3639 | next: false
|
3640 | };
|
3641 | return this;
|
3642 | };
|
3643 |
|
3644 | __proto._resetInternalValues = function () {
|
3645 | this._position = 0;
|
3646 | this._alignPos = 0;
|
3647 | this._offset = 0;
|
3648 | this._range = {
|
3649 | min: 0,
|
3650 | max: 0
|
3651 | };
|
3652 | this._visiblePanels = [];
|
3653 | this._anchors = [];
|
3654 | this._needPanelTriggered = {
|
3655 | prev: false,
|
3656 | next: false
|
3657 | };
|
3658 | };
|
3659 |
|
3660 | __proto._refreshVisiblePanels = function () {
|
3661 | var _this = this;
|
3662 |
|
3663 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
3664 | var panels = flicking.renderer.panels;
|
3665 | var newVisiblePanels = panels.filter(function (panel) {
|
3666 | return _this.canSee(panel);
|
3667 | });
|
3668 | var prevVisiblePanels = this._visiblePanels;
|
3669 | this._visiblePanels = newVisiblePanels;
|
3670 | var added = newVisiblePanels.filter(function (panel) {
|
3671 | return !includes(prevVisiblePanels, panel);
|
3672 | });
|
3673 | var removed = prevVisiblePanels.filter(function (panel) {
|
3674 | return !includes(newVisiblePanels, panel);
|
3675 | });
|
3676 |
|
3677 | if (added.length > 0 || removed.length > 0) {
|
3678 | void flicking.renderer.render().then(function () {
|
3679 | flicking.trigger(new ComponentEvent(EVENTS.VISIBLE_CHANGE, {
|
3680 | added: added,
|
3681 | removed: removed,
|
3682 | visiblePanels: newVisiblePanels
|
3683 | }));
|
3684 | });
|
3685 | }
|
3686 | };
|
3687 |
|
3688 | __proto._checkNeedPanel = function () {
|
3689 | var needPanelTriggered = this._needPanelTriggered;
|
3690 | if (needPanelTriggered.prev && needPanelTriggered.next) return;
|
3691 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
3692 | var panels = flicking.renderer.panels;
|
3693 |
|
3694 | if (panels.length <= 0) {
|
3695 | if (!needPanelTriggered.prev) {
|
3696 | flicking.trigger(new ComponentEvent(EVENTS.NEED_PANEL, {
|
3697 | direction: DIRECTION.PREV
|
3698 | }));
|
3699 | needPanelTriggered.prev = true;
|
3700 | }
|
3701 |
|
3702 | if (!needPanelTriggered.next) {
|
3703 | flicking.trigger(new ComponentEvent(EVENTS.NEED_PANEL, {
|
3704 | direction: DIRECTION.NEXT
|
3705 | }));
|
3706 | needPanelTriggered.next = true;
|
3707 | }
|
3708 |
|
3709 | return;
|
3710 | }
|
3711 |
|
3712 | var cameraPosition = this._position;
|
3713 | var cameraSize = this.size;
|
3714 | var cameraRange = this._range;
|
3715 | var needPanelThreshold = flicking.needPanelThreshold;
|
3716 | var cameraPrev = cameraPosition - this._alignPos;
|
3717 | var cameraNext = cameraPrev + cameraSize;
|
3718 | var firstPanel = panels[0];
|
3719 | var lastPanel = panels[panels.length - 1];
|
3720 |
|
3721 | if (!needPanelTriggered.prev) {
|
3722 | var firstPanelPrev = firstPanel.range.min;
|
3723 |
|
3724 | if (cameraPrev <= firstPanelPrev + needPanelThreshold || cameraPosition <= cameraRange.min + needPanelThreshold) {
|
3725 | flicking.trigger(new ComponentEvent(EVENTS.NEED_PANEL, {
|
3726 | direction: DIRECTION.PREV
|
3727 | }));
|
3728 | needPanelTriggered.prev = true;
|
3729 | }
|
3730 | }
|
3731 |
|
3732 | if (!needPanelTriggered.next) {
|
3733 | var lastPanelNext = lastPanel.range.max;
|
3734 |
|
3735 | if (cameraNext >= lastPanelNext - needPanelThreshold || cameraPosition >= cameraRange.max - needPanelThreshold) {
|
3736 | flicking.trigger(new ComponentEvent(EVENTS.NEED_PANEL, {
|
3737 | direction: DIRECTION.NEXT
|
3738 | }));
|
3739 | needPanelTriggered.next = true;
|
3740 | }
|
3741 | }
|
3742 | };
|
3743 |
|
3744 | __proto._checkReachEnd = function (prevPos, newPos) {
|
3745 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
3746 | var range = this._range;
|
3747 | var wasBetweenRange = prevPos > range.min && prevPos < range.max;
|
3748 | var isBetweenRange = newPos > range.min && newPos < range.max;
|
3749 | if (!wasBetweenRange || isBetweenRange) return;
|
3750 | var direction = newPos <= range.min ? DIRECTION.PREV : DIRECTION.NEXT;
|
3751 | flicking.trigger(new ComponentEvent(EVENTS.REACH_EDGE, {
|
3752 | direction: direction
|
3753 | }));
|
3754 | };
|
3755 |
|
3756 | __proto._applyTransform = function () {
|
3757 | var el = this._el;
|
3758 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
3759 | var actualPosition = this._position - this._alignPos - this._offset;
|
3760 | el.style[this._transform] = flicking.horizontal ? "translate(" + -actualPosition + "px)" : "translate(0, " + -actualPosition + "px)";
|
3761 | };
|
3762 |
|
3763 | return Camera;
|
3764 | }();
|
3765 |
|
3766 |
|
3767 |
|
3768 |
|
3769 |
|
3770 |
|
3771 | var LinearCamera = function (_super) {
|
3772 | __extends(LinearCamera, _super);
|
3773 |
|
3774 | function LinearCamera() {
|
3775 | return _super !== null && _super.apply(this, arguments) || this;
|
3776 | }
|
3777 | |
3778 |
|
3779 |
|
3780 |
|
3781 |
|
3782 |
|
3783 |
|
3784 |
|
3785 |
|
3786 |
|
3787 |
|
3788 | var __proto = LinearCamera.prototype;
|
3789 |
|
3790 | __proto.updateRange = function () {
|
3791 | var _a, _b;
|
3792 |
|
3793 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
3794 | var renderer = flicking.renderer;
|
3795 | var firstPanel = renderer.getPanel(0);
|
3796 | var lastPanel = renderer.getPanel(renderer.panelCount - 1);
|
3797 | this._range = {
|
3798 | min: (_a = firstPanel === null || firstPanel === void 0 ? void 0 : firstPanel.position) !== null && _a !== void 0 ? _a : 0,
|
3799 | max: (_b = lastPanel === null || lastPanel === void 0 ? void 0 : lastPanel.position) !== null && _b !== void 0 ? _b : 0
|
3800 | };
|
3801 | return this;
|
3802 | };
|
3803 |
|
3804 | return LinearCamera;
|
3805 | }(Camera);
|
3806 |
|
3807 |
|
3808 |
|
3809 |
|
3810 |
|
3811 |
|
3812 | var CircularCamera = function (_super) {
|
3813 | __extends(CircularCamera, _super);
|
3814 |
|
3815 | function CircularCamera() {
|
3816 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
3817 |
|
3818 | _this._circularOffset = 0;
|
3819 | _this._circularEnabled = false;
|
3820 | return _this;
|
3821 | }
|
3822 |
|
3823 | var __proto = CircularCamera.prototype;
|
3824 | Object.defineProperty(__proto, "offset", {
|
3825 | get: function () {
|
3826 | return this._offset - this._circularOffset;
|
3827 | },
|
3828 | enumerable: false,
|
3829 | configurable: true
|
3830 | });
|
3831 | Object.defineProperty(__proto, "controlParams", {
|
3832 | get: function () {
|
3833 | return {
|
3834 | range: this._range,
|
3835 | position: this._position,
|
3836 | circular: this._circularEnabled
|
3837 | };
|
3838 | },
|
3839 | enumerable: false,
|
3840 | configurable: true
|
3841 | });
|
3842 |
|
3843 | __proto.getPrevAnchor = function (anchor) {
|
3844 | if (!this._circularEnabled || anchor.index !== 0) return _super.prototype.getPrevAnchor.call(this, anchor);
|
3845 | var anchors = this._anchors;
|
3846 | var rangeDiff = this.rangeDiff;
|
3847 | var lastAnchor = anchors[anchors.length - 1];
|
3848 | return new AnchorPoint({
|
3849 | index: lastAnchor.index,
|
3850 | position: lastAnchor.position - rangeDiff,
|
3851 | panel: lastAnchor.panel
|
3852 | });
|
3853 | };
|
3854 |
|
3855 | __proto.getNextAnchor = function (anchor) {
|
3856 | var anchors = this._anchors;
|
3857 | if (!this._circularEnabled || anchor.index !== anchors.length - 1) return _super.prototype.getNextAnchor.call(this, anchor);
|
3858 | var rangeDiff = this.rangeDiff;
|
3859 | var firstAnchor = anchors[0];
|
3860 | return new AnchorPoint({
|
3861 | index: firstAnchor.index,
|
3862 | position: firstAnchor.position + rangeDiff,
|
3863 | panel: firstAnchor.panel
|
3864 | });
|
3865 | };
|
3866 |
|
3867 | __proto.findAnchorIncludePosition = function (position) {
|
3868 | if (!this._circularEnabled) return _super.prototype.findAnchorIncludePosition.call(this, position);
|
3869 | var range = this._range;
|
3870 | var positionInRange = circulatePosition(position, range.min, range.max);
|
3871 |
|
3872 | var anchorInRange = _super.prototype.findAnchorIncludePosition.call(this, positionInRange);
|
3873 |
|
3874 | if (!anchorInRange) return null;
|
3875 | var rangeDiff = this.rangeDiff;
|
3876 |
|
3877 | if (position < range.min) {
|
3878 | var loopCount = -Math.floor((range.min - position) / rangeDiff) - 1;
|
3879 | return new AnchorPoint({
|
3880 | index: anchorInRange.index,
|
3881 | position: anchorInRange.position + rangeDiff * loopCount,
|
3882 | panel: anchorInRange.panel
|
3883 | });
|
3884 | } else if (position > range.max) {
|
3885 | var loopCount = Math.floor((position - range.max) / rangeDiff) + 1;
|
3886 | return new AnchorPoint({
|
3887 | index: anchorInRange.index,
|
3888 | position: anchorInRange.position + rangeDiff * loopCount,
|
3889 | panel: anchorInRange.panel
|
3890 | });
|
3891 | }
|
3892 |
|
3893 | return anchorInRange;
|
3894 | };
|
3895 |
|
3896 | __proto.clampToReachablePosition = function (position) {
|
3897 |
|
3898 | return this._circularEnabled ? position : _super.prototype.clampToReachablePosition.call(this, position);
|
3899 | };
|
3900 |
|
3901 | __proto.canReach = function (panel) {
|
3902 | if (panel.removed) return false;
|
3903 | return this._circularEnabled
|
3904 | ? true : _super.prototype.canReach.call(this, panel);
|
3905 | };
|
3906 |
|
3907 | __proto.canSee = function (panel) {
|
3908 | var range = this._range;
|
3909 | var rangeDiff = this.rangeDiff;
|
3910 | var visibleRange = this.visibleRange;
|
3911 |
|
3912 | var visibleInCurrentRange = _super.prototype.canSee.call(this, panel);
|
3913 |
|
3914 | if (!this._circularEnabled) {
|
3915 | return visibleInCurrentRange;
|
3916 | }
|
3917 |
|
3918 |
|
3919 | if (visibleRange.min < range.min) {
|
3920 | return visibleInCurrentRange || panel.includeRange(visibleRange.min + rangeDiff, visibleRange.max + rangeDiff, false);
|
3921 | } else if (visibleRange.max > range.max) {
|
3922 | return visibleInCurrentRange || panel.includeRange(visibleRange.min - rangeDiff, visibleRange.max - rangeDiff, false);
|
3923 | }
|
3924 |
|
3925 | return visibleInCurrentRange;
|
3926 | };
|
3927 | |
3928 |
|
3929 |
|
3930 |
|
3931 |
|
3932 |
|
3933 |
|
3934 |
|
3935 |
|
3936 |
|
3937 |
|
3938 | __proto.updateRange = function () {
|
3939 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
3940 | var renderer = flicking.renderer;
|
3941 | var panels = renderer.panels;
|
3942 |
|
3943 | if (panels.length <= 0) {
|
3944 | this._resetInternalValues();
|
3945 |
|
3946 | return this;
|
3947 | }
|
3948 |
|
3949 | var firstPanel = panels[0];
|
3950 | var lastPanel = panels[panels.length - 1];
|
3951 | var firstPanelPrev = firstPanel.range.min - firstPanel.margin.prev;
|
3952 | var lastPanelNext = lastPanel.range.max + lastPanel.margin.next;
|
3953 | var visibleSize = this.size;
|
3954 | var panelSizeSum = lastPanelNext - firstPanelPrev;
|
3955 | var canSetCircularMode = panels.every(function (panel) {
|
3956 | return panelSizeSum - panel.size >= visibleSize;
|
3957 | });
|
3958 | this._circularEnabled = canSetCircularMode;
|
3959 |
|
3960 | if (canSetCircularMode) {
|
3961 | this._range = {
|
3962 | min: firstPanelPrev,
|
3963 | max: lastPanelNext
|
3964 | };
|
3965 | panels.forEach(function (panel) {
|
3966 | return panel.updateCircularToggleDirection();
|
3967 | });
|
3968 | } else {
|
3969 | this._range = {
|
3970 | min: firstPanel.position,
|
3971 | max: lastPanel.position
|
3972 | };
|
3973 | }
|
3974 |
|
3975 | this._updateCircularOffset();
|
3976 |
|
3977 | return this;
|
3978 | };
|
3979 |
|
3980 | __proto.lookAt = function (pos) {
|
3981 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
3982 | var prevPos = this._position;
|
3983 | if (pos === prevPos) return _super.prototype.lookAt.call(this, pos);
|
3984 | var panels = flicking.renderer.panels;
|
3985 | var toggled = panels.map(function (panel) {
|
3986 | return panel.toggle(prevPos, pos);
|
3987 | });
|
3988 | this._position = pos;
|
3989 |
|
3990 | if (toggled.some(function (isToggled) {
|
3991 | return isToggled;
|
3992 | })) {
|
3993 | this._updateCircularOffset();
|
3994 |
|
3995 | void flicking.renderer.render();
|
3996 | }
|
3997 |
|
3998 | return _super.prototype.lookAt.call(this, pos);
|
3999 | };
|
4000 |
|
4001 | __proto._applyTransform = function () {
|
4002 | var el = this._el;
|
4003 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
4004 | var actualPosition = this._position - this._alignPos - this._offset + this._circularOffset;
|
4005 | el.style[this._transform] = flicking.horizontal ? "translate(" + -actualPosition + "px)" : "translate(0, " + -actualPosition + "px)";
|
4006 | };
|
4007 |
|
4008 | __proto._resetInternalValues = function () {
|
4009 | _super.prototype._resetInternalValues.call(this);
|
4010 |
|
4011 | this._circularOffset = 0;
|
4012 | this._circularEnabled = false;
|
4013 | };
|
4014 |
|
4015 | __proto._calcPanelAreaSum = function (panels) {
|
4016 | return panels.reduce(function (sum, panel) {
|
4017 | return sum + panel.sizeIncludingMargin;
|
4018 | }, 0);
|
4019 | };
|
4020 |
|
4021 | __proto._updateCircularOffset = function () {
|
4022 | if (!this._circularEnabled) {
|
4023 | this._circularOffset = 0;
|
4024 | return;
|
4025 | }
|
4026 |
|
4027 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
4028 | var toggledPrev = [];
|
4029 | var toggledNext = [];
|
4030 | flicking.panels.filter(function (panel) {
|
4031 | return panel.toggled;
|
4032 | }).forEach(function (panel) {
|
4033 | if (panel.toggleDirection === DIRECTION.PREV) {
|
4034 | toggledPrev.push(panel);
|
4035 | } else {
|
4036 | toggledNext.push(panel);
|
4037 | }
|
4038 | });
|
4039 | this._circularOffset = this._calcPanelAreaSum(toggledPrev) - this._calcPanelAreaSum(toggledNext);
|
4040 | };
|
4041 |
|
4042 | return CircularCamera;
|
4043 | }(Camera);
|
4044 |
|
4045 |
|
4046 |
|
4047 |
|
4048 |
|
4049 |
|
4050 | var BoundCamera = function (_super) {
|
4051 | __extends(BoundCamera, _super);
|
4052 |
|
4053 | function BoundCamera() {
|
4054 | return _super !== null && _super.apply(this, arguments) || this;
|
4055 | }
|
4056 | |
4057 |
|
4058 |
|
4059 |
|
4060 |
|
4061 |
|
4062 |
|
4063 |
|
4064 |
|
4065 |
|
4066 |
|
4067 | var __proto = BoundCamera.prototype;
|
4068 |
|
4069 | __proto.updateRange = function () {
|
4070 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
4071 | var renderer = flicking.renderer;
|
4072 | var alignPos = this._alignPos;
|
4073 | var firstPanel = renderer.getPanel(0);
|
4074 | var lastPanel = renderer.getPanel(renderer.panelCount - 1);
|
4075 |
|
4076 | if (!firstPanel || !lastPanel) {
|
4077 | this._range = {
|
4078 | min: 0,
|
4079 | max: 0
|
4080 | };
|
4081 | return this;
|
4082 | }
|
4083 |
|
4084 | var viewportSize = this.size;
|
4085 | var firstPanelPrev = firstPanel.range.min;
|
4086 | var lastPanelNext = lastPanel.range.max;
|
4087 | var panelAreaSize = lastPanelNext - firstPanelPrev;
|
4088 | var isBiggerThanViewport = viewportSize < panelAreaSize;
|
4089 | var firstPos = firstPanelPrev + alignPos;
|
4090 | var lastPos = lastPanelNext - viewportSize + alignPos;
|
4091 |
|
4092 | if (isBiggerThanViewport) {
|
4093 | this._range = {
|
4094 | min: firstPos,
|
4095 | max: lastPos
|
4096 | };
|
4097 | } else {
|
4098 | var align = this._align;
|
4099 | var alignVal = typeof align === "object" ? align.camera : align;
|
4100 | var pos = firstPos + parseAlign$1(alignVal, lastPos - firstPos);
|
4101 | this._range = {
|
4102 | min: pos,
|
4103 | max: pos
|
4104 | };
|
4105 | }
|
4106 |
|
4107 | return this;
|
4108 | };
|
4109 |
|
4110 | __proto.updateAnchors = function () {
|
4111 | var _this = this;
|
4112 |
|
4113 | var flicking = getFlickingAttached(this._flicking, "Camera");
|
4114 | var panels = flicking.renderer.panels;
|
4115 |
|
4116 | if (panels.length <= 0) {
|
4117 | this._anchors = [];
|
4118 | return this;
|
4119 | }
|
4120 |
|
4121 | var range = this._range;
|
4122 | var reachablePanels = panels.filter(function (panel) {
|
4123 | return _this.canReach(panel);
|
4124 | });
|
4125 |
|
4126 | if (reachablePanels.length > 0) {
|
4127 | var shouldPrependBoundAnchor = reachablePanels[0].position !== range.min;
|
4128 | var shouldAppendBoundAnchor = reachablePanels[reachablePanels.length - 1].position !== range.max;
|
4129 | var indexOffset_1 = shouldPrependBoundAnchor ? 1 : 0;
|
4130 | var newAnchors = reachablePanels.map(function (panel, idx) {
|
4131 | return new AnchorPoint({
|
4132 | index: idx + indexOffset_1,
|
4133 | position: panel.position,
|
4134 | panel: panel
|
4135 | });
|
4136 | });
|
4137 |
|
4138 | if (shouldPrependBoundAnchor) {
|
4139 | newAnchors.splice(0, 0, new AnchorPoint({
|
4140 | index: 0,
|
4141 | position: range.min,
|
4142 | panel: panels[reachablePanels[0].index - 1]
|
4143 | }));
|
4144 | }
|
4145 |
|
4146 | if (shouldAppendBoundAnchor) {
|
4147 | newAnchors.push(new AnchorPoint({
|
4148 | index: newAnchors.length,
|
4149 | position: range.max,
|
4150 | panel: panels[reachablePanels[reachablePanels.length - 1].index + 1]
|
4151 | }));
|
4152 | }
|
4153 |
|
4154 | this._anchors = newAnchors;
|
4155 | } else if (range.min !== range.max) {
|
4156 |
|
4157 | var nearestPanelAtMin = this._findNearestPanel(range.min, panels);
|
4158 |
|
4159 | var panelAtMin = nearestPanelAtMin.index === panels.length - 1 ? nearestPanelAtMin.prev() : nearestPanelAtMin;
|
4160 | var panelAtMax = panelAtMin.next();
|
4161 | this._anchors = [new AnchorPoint({
|
4162 | index: 0,
|
4163 | position: range.min,
|
4164 | panel: panelAtMin
|
4165 | }), new AnchorPoint({
|
4166 | index: 1,
|
4167 | position: range.max,
|
4168 | panel: panelAtMax
|
4169 | })];
|
4170 | } else {
|
4171 | this._anchors = [new AnchorPoint({
|
4172 | index: 0,
|
4173 | position: range.min,
|
4174 | panel: this._findNearestPanel(range.min, panels)
|
4175 | })];
|
4176 | }
|
4177 |
|
4178 | return this;
|
4179 | };
|
4180 |
|
4181 | __proto.findAnchorIncludePosition = function (position) {
|
4182 | var range = this._range;
|
4183 | var anchors = this._anchors;
|
4184 | if (anchors.length <= 0) return null;
|
4185 |
|
4186 | if (position <= range.min) {
|
4187 | return anchors[0];
|
4188 | } else if (position >= range.max) {
|
4189 | return anchors[anchors.length - 1];
|
4190 | } else {
|
4191 | return _super.prototype.findAnchorIncludePosition.call(this, position);
|
4192 | }
|
4193 | };
|
4194 |
|
4195 | __proto._findNearestPanel = function (pos, panels) {
|
4196 | var prevDist = Infinity;
|
4197 |
|
4198 | for (var panelIdx = 0; panelIdx < panels.length; panelIdx++) {
|
4199 | var panel = panels[panelIdx];
|
4200 | var dist = Math.abs(panel.position - pos);
|
4201 |
|
4202 | if (dist > prevDist) {
|
4203 |
|
4204 | return panels[panelIdx - 1];
|
4205 | }
|
4206 |
|
4207 | prevDist = dist;
|
4208 | }
|
4209 |
|
4210 |
|
4211 | return panels[panels.length - 1];
|
4212 | };
|
4213 |
|
4214 | return BoundCamera;
|
4215 | }(Camera);
|
4216 |
|
4217 |
|
4218 |
|
4219 |
|
4220 |
|
4221 |
|
4222 | var Renderer = function () {
|
4223 | |
4224 |
|
4225 |
|
4226 |
|
4227 | function Renderer(_a) {
|
4228 | var _b = _a === void 0 ? {} : _a,
|
4229 | _c = _b.align,
|
4230 | align = _c === void 0 ? ALIGN.CENTER : _c;
|
4231 |
|
4232 | this._flicking = null;
|
4233 | this._panels = [];
|
4234 |
|
4235 | this._align = align;
|
4236 | }
|
4237 |
|
4238 | var __proto = Renderer.prototype;
|
4239 | Object.defineProperty(__proto, "panels", {
|
4240 |
|
4241 |
|
4242 | |
4243 |
|
4244 |
|
4245 |
|
4246 |
|
4247 |
|
4248 |
|
4249 | get: function () {
|
4250 | return this._panels;
|
4251 | },
|
4252 | enumerable: false,
|
4253 | configurable: true
|
4254 | });
|
4255 | Object.defineProperty(__proto, "panelCount", {
|
4256 | |
4257 |
|
4258 |
|
4259 |
|
4260 |
|
4261 |
|
4262 | get: function () {
|
4263 | return this._panels.length;
|
4264 | },
|
4265 | enumerable: false,
|
4266 | configurable: true
|
4267 | });
|
4268 | Object.defineProperty(__proto, "align", {
|
4269 |
|
4270 |
|
4271 | |
4272 |
|
4273 |
|
4274 |
|
4275 |
|
4276 | get: function () {
|
4277 | return this._align;
|
4278 | },
|
4279 |
|
4280 | set: function (val) {
|
4281 | this._align = val;
|
4282 |
|
4283 | var panelAlign = this._getPanelAlign();
|
4284 |
|
4285 | this._panels.forEach(function (panel) {
|
4286 | panel.align = panelAlign;
|
4287 | });
|
4288 | },
|
4289 | enumerable: false,
|
4290 | configurable: true
|
4291 | });
|
4292 | |
4293 |
|
4294 |
|
4295 |
|
4296 |
|
4297 |
|
4298 |
|
4299 |
|
4300 | __proto.init = function (flicking) {
|
4301 | this._flicking = flicking;
|
4302 |
|
4303 | this._collectPanels();
|
4304 |
|
4305 | return this;
|
4306 | };
|
4307 | |
4308 |
|
4309 |
|
4310 |
|
4311 |
|
4312 |
|
4313 |
|
4314 | __proto.destroy = function () {
|
4315 | this._flicking = null;
|
4316 | this._panels = [];
|
4317 | };
|
4318 | |
4319 |
|
4320 |
|
4321 |
|
4322 |
|
4323 |
|
4324 |
|
4325 |
|
4326 | __proto.getPanel = function (index) {
|
4327 | return this._panels[index] || null;
|
4328 | };
|
4329 | |
4330 |
|
4331 |
|
4332 |
|
4333 |
|
4334 |
|
4335 |
|
4336 |
|
4337 | __proto.updatePanelSize = function () {
|
4338 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
4339 |
|
4340 | if (flicking.panelsPerView > 0) {
|
4341 | this._updatePanelSizeByGrid(flicking);
|
4342 | } else {
|
4343 | flicking.panels.forEach(function (panel) {
|
4344 | return panel.resize();
|
4345 | });
|
4346 | }
|
4347 |
|
4348 | return this;
|
4349 | };
|
4350 | |
4351 |
|
4352 |
|
4353 |
|
4354 |
|
4355 |
|
4356 |
|
4357 |
|
4358 |
|
4359 |
|
4360 |
|
4361 | __proto.batchInsert = function () {
|
4362 | var _this = this;
|
4363 |
|
4364 | var items = [];
|
4365 |
|
4366 | for (var _i = 0; _i < arguments.length; _i++) {
|
4367 | items[_i] = arguments[_i];
|
4368 | }
|
4369 |
|
4370 | var panels = this._panels;
|
4371 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
4372 | var control = flicking.control;
|
4373 |
|
4374 | var align = this._getPanelAlign();
|
4375 |
|
4376 | var allPanelsInserted = items.reduce(function (addedPanels, item) {
|
4377 | var _a;
|
4378 |
|
4379 | var insertingIdx = getMinusCompensatedIndex(item.index, panels.length);
|
4380 | var panelsPushed = panels.slice(insertingIdx);
|
4381 | var panelsInserted = item.elements.map(function (el, idx) {
|
4382 | return _this._createPanel(el, {
|
4383 | index: insertingIdx + idx,
|
4384 | align: align,
|
4385 | flicking: flicking
|
4386 | });
|
4387 | });
|
4388 | panels.splice.apply(panels, __spreadArray([insertingIdx, 0], __read(panelsInserted)));
|
4389 |
|
4390 | _this._insertPanelElements(panelsInserted, (_a = panelsPushed[0]) !== null && _a !== void 0 ? _a : null);
|
4391 |
|
4392 |
|
4393 | panelsInserted.forEach(function (panel) {
|
4394 | return panel.resize();
|
4395 | });
|
4396 |
|
4397 | panelsPushed.forEach(function (panel) {
|
4398 | panel.increaseIndex(panelsInserted.length);
|
4399 | panel.updatePosition();
|
4400 | });
|
4401 | return __spreadArray(__spreadArray([], __read(addedPanels)), __read(panelsInserted));
|
4402 | }, []);
|
4403 | if (allPanelsInserted.length <= 0) return [];
|
4404 |
|
4405 | this._updateCameraAndControl();
|
4406 |
|
4407 | void this.render();
|
4408 |
|
4409 |
|
4410 | if (allPanelsInserted.length > 0 && !control.animating) {
|
4411 | void control.moveToPanel(control.activePanel || allPanelsInserted[0], {
|
4412 | duration: 0
|
4413 | }).catch(function () {
|
4414 | return void 0;
|
4415 | });
|
4416 | }
|
4417 |
|
4418 | flicking.camera.updateOffset();
|
4419 | flicking.trigger(new ComponentEvent(EVENTS.PANEL_CHANGE, {
|
4420 | added: allPanelsInserted,
|
4421 | removed: []
|
4422 | }));
|
4423 | this.checkPanelContentsReady(allPanelsInserted);
|
4424 | return allPanelsInserted;
|
4425 | };
|
4426 | |
4427 |
|
4428 |
|
4429 |
|
4430 |
|
4431 |
|
4432 |
|
4433 |
|
4434 |
|
4435 |
|
4436 |
|
4437 | __proto.batchRemove = function () {
|
4438 | var _this = this;
|
4439 |
|
4440 | var items = [];
|
4441 |
|
4442 | for (var _i = 0; _i < arguments.length; _i++) {
|
4443 | items[_i] = arguments[_i];
|
4444 | }
|
4445 |
|
4446 | var panels = this._panels;
|
4447 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
4448 | var camera = flicking.camera,
|
4449 | control = flicking.control;
|
4450 | var activePanel = control.activePanel;
|
4451 | var activeIndex = control.activeIndex;
|
4452 | var allPanelsRemoved = items.reduce(function (removed, item) {
|
4453 | var index = item.index,
|
4454 | deleteCount = item.deleteCount;
|
4455 | var removingIdx = getMinusCompensatedIndex(index, panels.length);
|
4456 | var panelsPulled = panels.slice(removingIdx + deleteCount);
|
4457 | var panelsRemoved = panels.splice(removingIdx, deleteCount);
|
4458 | if (panelsRemoved.length <= 0) return [];
|
4459 |
|
4460 | panelsPulled.forEach(function (panel) {
|
4461 | panel.decreaseIndex(panelsRemoved.length);
|
4462 | panel.updatePosition();
|
4463 | });
|
4464 |
|
4465 | _this._removePanelElements(panelsRemoved);
|
4466 |
|
4467 |
|
4468 | panelsRemoved.forEach(function (panel) {
|
4469 | return panel.destroy();
|
4470 | });
|
4471 |
|
4472 | _this._updateCameraAndControl();
|
4473 |
|
4474 | if (includes(panelsRemoved, activePanel)) {
|
4475 | control.resetActive();
|
4476 | }
|
4477 |
|
4478 | return __spreadArray(__spreadArray([], __read(removed)), __read(panelsRemoved));
|
4479 | }, []);
|
4480 | void this.render();
|
4481 |
|
4482 | if (allPanelsRemoved.length > 0 && !control.animating) {
|
4483 | var targetPanel = includes(allPanelsRemoved, activePanel) ? panels[activeIndex] || panels[panels.length - 1] : activePanel;
|
4484 |
|
4485 | if (targetPanel) {
|
4486 | void control.moveToPanel(targetPanel, {
|
4487 | duration: 0
|
4488 | }).catch(function () {
|
4489 | return void 0;
|
4490 | });
|
4491 | } else {
|
4492 |
|
4493 | camera.lookAt(0);
|
4494 | }
|
4495 | }
|
4496 |
|
4497 | flicking.camera.updateOffset();
|
4498 | flicking.trigger(new ComponentEvent(EVENTS.PANEL_CHANGE, {
|
4499 | added: [],
|
4500 | removed: allPanelsRemoved
|
4501 | }));
|
4502 | return allPanelsRemoved;
|
4503 | };
|
4504 | |
4505 |
|
4506 |
|
4507 |
|
4508 |
|
4509 | __proto.checkPanelContentsReady = function (checkingPanels) {
|
4510 | var _this = this;
|
4511 |
|
4512 | var resizeOnContentsReady = getFlickingAttached(this._flicking, "Renderer").resizeOnContentsReady;
|
4513 | var panels = this._panels;
|
4514 | if (!resizeOnContentsReady) return;
|
4515 |
|
4516 | var hasContents = function (panel) {
|
4517 | return !!panel.element.querySelector("img, video");
|
4518 | };
|
4519 |
|
4520 | checkingPanels = checkingPanels.filter(function (panel) {
|
4521 | return hasContents(panel);
|
4522 | });
|
4523 | if (checkingPanels.length <= 0) return;
|
4524 | var contentsReadyChecker = new ImReady();
|
4525 | checkingPanels.forEach(function (panel) {
|
4526 | panel.loading = true;
|
4527 | });
|
4528 | contentsReadyChecker.on("readyElement", function (e) {
|
4529 | var flicking = _this._flicking;
|
4530 |
|
4531 | if (!flicking) {
|
4532 |
|
4533 | contentsReadyChecker.destroy();
|
4534 | return;
|
4535 | }
|
4536 |
|
4537 | var panel = checkingPanels[e.index];
|
4538 | var camera = flicking.camera;
|
4539 | var control = flicking.control;
|
4540 | var prevProgressInPanel = control.activePanel ? camera.getProgressInPanel(control.activePanel) : 0;
|
4541 | panel.loading = false;
|
4542 | panel.resize();
|
4543 | panels.slice(panel.index + 1).forEach(function (panelBehind) {
|
4544 | return panelBehind.updatePosition();
|
4545 | });
|
4546 | if (!flicking.initialized) return;
|
4547 | camera.updateRange();
|
4548 | camera.updateAnchors();
|
4549 |
|
4550 | if (control.animating) ; else {
|
4551 | control.updatePosition(prevProgressInPanel);
|
4552 | control.updateInput();
|
4553 | }
|
4554 | });
|
4555 | contentsReadyChecker.on("preReady", function (e) {
|
4556 | if (_this._flicking) {
|
4557 | void _this.render();
|
4558 | }
|
4559 |
|
4560 | if (e.readyCount === e.totalCount) {
|
4561 | contentsReadyChecker.destroy();
|
4562 | }
|
4563 | });
|
4564 | contentsReadyChecker.on("ready", function () {
|
4565 | if (_this._flicking) {
|
4566 | void _this.render();
|
4567 | }
|
4568 |
|
4569 | contentsReadyChecker.destroy();
|
4570 | });
|
4571 | contentsReadyChecker.check(checkingPanels.map(function (panel) {
|
4572 | return panel.element;
|
4573 | }));
|
4574 | };
|
4575 |
|
4576 | __proto._getPanelAlign = function () {
|
4577 | var align = this._align;
|
4578 | return typeof align === "object" ? align.panel : align;
|
4579 | };
|
4580 |
|
4581 | __proto._updateCameraAndControl = function () {
|
4582 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
4583 | var camera = flicking.camera,
|
4584 | control = flicking.control;
|
4585 | camera.updateRange();
|
4586 | camera.updateAnchors();
|
4587 | camera.resetNeedPanelHistory();
|
4588 | control.updateInput();
|
4589 | };
|
4590 |
|
4591 | __proto._updateRenderingPanels = function () {
|
4592 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
4593 |
|
4594 | if (flicking.renderOnlyVisible) {
|
4595 | this._showOnlyVisiblePanels(flicking);
|
4596 | } else {
|
4597 | flicking.panels.forEach(function (panel) {
|
4598 | return panel.markForShow();
|
4599 | });
|
4600 | }
|
4601 | };
|
4602 |
|
4603 | __proto._showOnlyVisiblePanels = function (flicking) {
|
4604 | var panels = flicking.renderer.panels;
|
4605 | var camera = flicking.camera;
|
4606 | var visibleIndexes = camera.visiblePanels.reduce(function (visibles, panel) {
|
4607 | visibles[panel.index] = true;
|
4608 | return visibles;
|
4609 | }, {});
|
4610 | panels.forEach(function (panel) {
|
4611 | if (panel.index in visibleIndexes || panel.loading) {
|
4612 | panel.markForShow();
|
4613 | } else if (!flicking.holding) {
|
4614 |
|
4615 |
|
4616 | panel.markForHide();
|
4617 | }
|
4618 | });
|
4619 | camera.updateOffset();
|
4620 | };
|
4621 |
|
4622 | __proto._updatePanelSizeByGrid = function (flicking) {
|
4623 | var panels = flicking.panels;
|
4624 | var panelsPerView = flicking.panelsPerView;
|
4625 |
|
4626 | if (panelsPerView <= 0) {
|
4627 | throw new FlickingError(MESSAGE.WRONG_OPTION("panelsPerView", panelsPerView), CODE.WRONG_OPTION);
|
4628 | }
|
4629 |
|
4630 | if (panels.length <= 0) return;
|
4631 |
|
4632 | var firstPanel = panels[0];
|
4633 | firstPanel.resize();
|
4634 | var viewportSize = flicking.camera.size;
|
4635 | var gap = firstPanel.margin.prev + firstPanel.margin.next;
|
4636 | var panelSize = (viewportSize - gap * (panelsPerView - 1)) / panelsPerView;
|
4637 | var panelSizeObj = flicking.horizontal ? {
|
4638 | width: panelSize
|
4639 | } : {
|
4640 | height: panelSize
|
4641 | };
|
4642 | var firstPanelSizeObj = {
|
4643 | size: panelSize,
|
4644 | height: firstPanel.height,
|
4645 | margin: firstPanel.margin
|
4646 | };
|
4647 |
|
4648 | if (!flicking.noPanelStyleOverride) {
|
4649 | flicking.panels.forEach(function (panel) {
|
4650 | return panel.setSize(panelSizeObj);
|
4651 | });
|
4652 | }
|
4653 |
|
4654 | flicking.panels.forEach(function (panel) {
|
4655 | return panel.resize(firstPanelSizeObj);
|
4656 | });
|
4657 | };
|
4658 |
|
4659 | return Renderer;
|
4660 | }();
|
4661 |
|
4662 | var Panel = function () {
|
4663 | |
4664 |
|
4665 |
|
4666 |
|
4667 |
|
4668 |
|
4669 | function Panel(_a) {
|
4670 | var index = _a.index,
|
4671 | align = _a.align,
|
4672 | flicking = _a.flicking;
|
4673 | this._index = index;
|
4674 | this._flicking = flicking;
|
4675 | this._align = align;
|
4676 | this._removed = false;
|
4677 | this._loading = false;
|
4678 |
|
4679 | this._resetInternalStates();
|
4680 | }
|
4681 |
|
4682 | var __proto = Panel.prototype;
|
4683 | Object.defineProperty(__proto, "index", {
|
4684 | |
4685 |
|
4686 |
|
4687 |
|
4688 |
|
4689 |
|
4690 | get: function () {
|
4691 | return this._index;
|
4692 | },
|
4693 | enumerable: false,
|
4694 | configurable: true
|
4695 | });
|
4696 | Object.defineProperty(__proto, "position", {
|
4697 | |
4698 |
|
4699 |
|
4700 |
|
4701 |
|
4702 |
|
4703 | get: function () {
|
4704 | return this._pos + this._alignPos;
|
4705 | },
|
4706 | enumerable: false,
|
4707 | configurable: true
|
4708 | });
|
4709 | Object.defineProperty(__proto, "size", {
|
4710 | |
4711 |
|
4712 |
|
4713 |
|
4714 |
|
4715 |
|
4716 |
|
4717 |
|
4718 | get: function () {
|
4719 | return this._size;
|
4720 | },
|
4721 | enumerable: false,
|
4722 | configurable: true
|
4723 | });
|
4724 | Object.defineProperty(__proto, "sizeIncludingMargin", {
|
4725 | |
4726 |
|
4727 |
|
4728 |
|
4729 |
|
4730 |
|
4731 |
|
4732 |
|
4733 | get: function () {
|
4734 | return this._size + this._margin.prev + this._margin.next;
|
4735 | },
|
4736 | enumerable: false,
|
4737 | configurable: true
|
4738 | });
|
4739 | Object.defineProperty(__proto, "height", {
|
4740 | |
4741 |
|
4742 |
|
4743 |
|
4744 |
|
4745 |
|
4746 | get: function () {
|
4747 | return this._height;
|
4748 | },
|
4749 | enumerable: false,
|
4750 | configurable: true
|
4751 | });
|
4752 | Object.defineProperty(__proto, "margin", {
|
4753 | |
4754 |
|
4755 |
|
4756 |
|
4757 |
|
4758 |
|
4759 |
|
4760 |
|
4761 |
|
4762 |
|
4763 | get: function () {
|
4764 | return this._margin;
|
4765 | },
|
4766 | enumerable: false,
|
4767 | configurable: true
|
4768 | });
|
4769 | Object.defineProperty(__proto, "alignPosition", {
|
4770 | |
4771 |
|
4772 |
|
4773 |
|
4774 |
|
4775 |
|
4776 | get: function () {
|
4777 | return this._alignPos;
|
4778 | },
|
4779 | enumerable: false,
|
4780 | configurable: true
|
4781 | });
|
4782 | Object.defineProperty(__proto, "removed", {
|
4783 | |
4784 |
|
4785 |
|
4786 |
|
4787 |
|
4788 |
|
4789 | get: function () {
|
4790 | return this._removed;
|
4791 | },
|
4792 | enumerable: false,
|
4793 | configurable: true
|
4794 | });
|
4795 | Object.defineProperty(__proto, "loading", {
|
4796 | |
4797 |
|
4798 |
|
4799 |
|
4800 |
|
4801 |
|
4802 | get: function () {
|
4803 | return this._loading;
|
4804 | },
|
4805 | set: function (val) {
|
4806 | this._loading = val;
|
4807 | },
|
4808 | enumerable: false,
|
4809 | configurable: true
|
4810 | });
|
4811 | Object.defineProperty(__proto, "range", {
|
4812 | |
4813 |
|
4814 |
|
4815 |
|
4816 |
|
4817 |
|
4818 |
|
4819 |
|
4820 | get: function () {
|
4821 | return {
|
4822 | min: this._pos,
|
4823 | max: this._pos + this._size
|
4824 | };
|
4825 | },
|
4826 | enumerable: false,
|
4827 | configurable: true
|
4828 | });
|
4829 | Object.defineProperty(__proto, "toggled", {
|
4830 | |
4831 |
|
4832 |
|
4833 |
|
4834 |
|
4835 |
|
4836 | get: function () {
|
4837 | return this._toggled;
|
4838 | },
|
4839 | enumerable: false,
|
4840 | configurable: true
|
4841 | });
|
4842 | Object.defineProperty(__proto, "toggleDirection", {
|
4843 | |
4844 |
|
4845 |
|
4846 |
|
4847 |
|
4848 |
|
4849 | get: function () {
|
4850 | return this._toggleDirection;
|
4851 | },
|
4852 | enumerable: false,
|
4853 | configurable: true
|
4854 | });
|
4855 | Object.defineProperty(__proto, "offset", {
|
4856 | |
4857 |
|
4858 |
|
4859 |
|
4860 |
|
4861 |
|
4862 | get: function () {
|
4863 | var toggleDirection = this._toggleDirection;
|
4864 | var cameraRangeDiff = this._flicking.camera.rangeDiff;
|
4865 | return toggleDirection === DIRECTION.NONE || !this._toggled ? 0 : toggleDirection === DIRECTION.PREV ? -cameraRangeDiff : cameraRangeDiff;
|
4866 | },
|
4867 | enumerable: false,
|
4868 | configurable: true
|
4869 | });
|
4870 | Object.defineProperty(__proto, "progress", {
|
4871 | |
4872 |
|
4873 |
|
4874 |
|
4875 |
|
4876 |
|
4877 | get: function () {
|
4878 | var flicking = this._flicking;
|
4879 | return this.index - flicking.camera.progress;
|
4880 | },
|
4881 | enumerable: false,
|
4882 | configurable: true
|
4883 | });
|
4884 | Object.defineProperty(__proto, "outsetProgress", {
|
4885 | |
4886 |
|
4887 |
|
4888 |
|
4889 |
|
4890 |
|
4891 | get: function () {
|
4892 | var position = this.position + this.offset;
|
4893 | var alignPosition = this._alignPos;
|
4894 | var camera = this._flicking.camera;
|
4895 | var camPos = camera.position;
|
4896 |
|
4897 | if (camPos === position) {
|
4898 | return 0;
|
4899 | }
|
4900 |
|
4901 | if (camPos < position) {
|
4902 | var disappearPosNext = position + (camera.size - camera.alignPosition) + alignPosition;
|
4903 | return -getProgress(camPos, position, disappearPosNext);
|
4904 | } else {
|
4905 | var disappearPosPrev = position - (camera.alignPosition + this._size - alignPosition);
|
4906 | return 1 - getProgress(camPos, disappearPosPrev, position);
|
4907 | }
|
4908 | },
|
4909 | enumerable: false,
|
4910 | configurable: true
|
4911 | });
|
4912 | Object.defineProperty(__proto, "visibleRatio", {
|
4913 | |
4914 |
|
4915 |
|
4916 |
|
4917 |
|
4918 |
|
4919 | get: function () {
|
4920 | var range = this.range;
|
4921 | var size = this._size;
|
4922 | var offset = this.offset;
|
4923 | var visibleRange = this._flicking.camera.visibleRange;
|
4924 | var checkingRange = {
|
4925 | min: range.min + offset,
|
4926 | max: range.max + offset
|
4927 | };
|
4928 |
|
4929 | if (checkingRange.max <= visibleRange.min || checkingRange.min >= visibleRange.max) {
|
4930 | return 0;
|
4931 | }
|
4932 |
|
4933 | var visibleSize = size;
|
4934 |
|
4935 | if (visibleRange.min > checkingRange.min) {
|
4936 | visibleSize -= visibleRange.min - checkingRange.min;
|
4937 | }
|
4938 |
|
4939 | if (visibleRange.max < checkingRange.max) {
|
4940 | visibleSize -= checkingRange.max - visibleRange.max;
|
4941 | }
|
4942 |
|
4943 | return visibleSize / size;
|
4944 | },
|
4945 | enumerable: false,
|
4946 | configurable: true
|
4947 | });
|
4948 | Object.defineProperty(__proto, "align", {
|
4949 |
|
4950 |
|
4951 | |
4952 |
|
4953 |
|
4954 |
|
4955 |
|
4956 | get: function () {
|
4957 | return this._align;
|
4958 | },
|
4959 |
|
4960 | set: function (val) {
|
4961 | this._align = val;
|
4962 | },
|
4963 | enumerable: false,
|
4964 | configurable: true
|
4965 | });
|
4966 | |
4967 |
|
4968 |
|
4969 |
|
4970 |
|
4971 |
|
4972 |
|
4973 |
|
4974 | __proto.resize = function (cached) {
|
4975 | var el = this.element;
|
4976 | var elStyle = getStyle(el);
|
4977 | var flicking = this._flicking;
|
4978 | var horizontal = flicking.horizontal;
|
4979 |
|
4980 | if (cached) {
|
4981 | this._size = cached.size;
|
4982 | this._margin = __assign({}, cached.margin);
|
4983 | this._height = cached.height;
|
4984 | } else {
|
4985 | this._size = horizontal ? el.offsetWidth : el.offsetHeight;
|
4986 | this._margin = horizontal ? {
|
4987 | prev: parseFloat(elStyle.marginLeft || "0"),
|
4988 | next: parseFloat(elStyle.marginRight || "0")
|
4989 | } : {
|
4990 | prev: parseFloat(elStyle.marginTop || "0"),
|
4991 | next: parseFloat(elStyle.marginBottom || "0")
|
4992 | };
|
4993 | this._height = horizontal ? el.offsetHeight : this._size;
|
4994 | }
|
4995 |
|
4996 | this.updatePosition();
|
4997 |
|
4998 | this._updateAlignPos();
|
4999 |
|
5000 | return this;
|
5001 | };
|
5002 | |
5003 |
|
5004 |
|
5005 |
|
5006 |
|
5007 |
|
5008 |
|
5009 |
|
5010 |
|
5011 |
|
5012 |
|
5013 | __proto.setSize = function (_a) {
|
5014 | var width = _a.width,
|
5015 | height = _a.height;
|
5016 | var el = this.element;
|
5017 |
|
5018 | if (width != null) {
|
5019 | if (isString(width)) {
|
5020 | el.style.width = width;
|
5021 | } else {
|
5022 | el.style.width = width + "px";
|
5023 | }
|
5024 | }
|
5025 |
|
5026 | if (height != null) {
|
5027 | if (isString(height)) {
|
5028 | el.style.height = height;
|
5029 | } else {
|
5030 | el.style.height = height + "px";
|
5031 | }
|
5032 | }
|
5033 |
|
5034 | return this;
|
5035 | };
|
5036 | |
5037 |
|
5038 |
|
5039 |
|
5040 |
|
5041 |
|
5042 |
|
5043 |
|
5044 | __proto.contains = function (element) {
|
5045 | var _a;
|
5046 |
|
5047 | return !!((_a = this.element) === null || _a === void 0 ? void 0 : _a.contains(element));
|
5048 | };
|
5049 | |
5050 |
|
5051 |
|
5052 |
|
5053 |
|
5054 |
|
5055 |
|
5056 | __proto.destroy = function () {
|
5057 | this._resetInternalStates();
|
5058 |
|
5059 | this._removed = true;
|
5060 | };
|
5061 | |
5062 |
|
5063 |
|
5064 |
|
5065 |
|
5066 |
|
5067 |
|
5068 |
|
5069 |
|
5070 | __proto.includePosition = function (pos, includeMargin) {
|
5071 | if (includeMargin === void 0) {
|
5072 | includeMargin = false;
|
5073 | }
|
5074 |
|
5075 | return this.includeRange(pos, pos, includeMargin);
|
5076 | };
|
5077 | |
5078 |
|
5079 |
|
5080 |
|
5081 |
|
5082 |
|
5083 |
|
5084 |
|
5085 |
|
5086 |
|
5087 | __proto.includeRange = function (min, max, includeMargin) {
|
5088 | if (includeMargin === void 0) {
|
5089 | includeMargin = false;
|
5090 | }
|
5091 |
|
5092 | var margin = this._margin;
|
5093 | var panelRange = this.range;
|
5094 |
|
5095 | if (includeMargin) {
|
5096 | panelRange.min -= margin.prev;
|
5097 | panelRange.max += margin.next;
|
5098 | }
|
5099 |
|
5100 | return max >= panelRange.min && min <= panelRange.max;
|
5101 | };
|
5102 | |
5103 |
|
5104 |
|
5105 |
|
5106 |
|
5107 |
|
5108 |
|
5109 |
|
5110 | __proto.focus = function (duration) {
|
5111 | return this._flicking.moveTo(this._index, duration);
|
5112 | };
|
5113 | |
5114 |
|
5115 |
|
5116 |
|
5117 |
|
5118 |
|
5119 |
|
5120 |
|
5121 |
|
5122 | __proto.prev = function () {
|
5123 | var index = this._index;
|
5124 | var flicking = this._flicking;
|
5125 | var renderer = flicking.renderer;
|
5126 | var panelCount = renderer.panelCount;
|
5127 | if (panelCount === 1) return null;
|
5128 | return flicking.circularEnabled ? renderer.getPanel(index === 0 ? panelCount - 1 : index - 1) : renderer.getPanel(index - 1);
|
5129 | };
|
5130 | |
5131 |
|
5132 |
|
5133 |
|
5134 |
|
5135 |
|
5136 |
|
5137 |
|
5138 |
|
5139 | __proto.next = function () {
|
5140 | var index = this._index;
|
5141 | var flicking = this._flicking;
|
5142 | var renderer = flicking.renderer;
|
5143 | var panelCount = renderer.panelCount;
|
5144 | if (panelCount === 1) return null;
|
5145 | return flicking.circularEnabled ? renderer.getPanel(index === panelCount - 1 ? 0 : index + 1) : renderer.getPanel(index + 1);
|
5146 | };
|
5147 | |
5148 |
|
5149 |
|
5150 |
|
5151 |
|
5152 |
|
5153 |
|
5154 |
|
5155 |
|
5156 |
|
5157 | __proto.increaseIndex = function (val) {
|
5158 | this._index += Math.max(val, 0);
|
5159 | return this;
|
5160 | };
|
5161 | |
5162 |
|
5163 |
|
5164 |
|
5165 |
|
5166 |
|
5167 |
|
5168 |
|
5169 |
|
5170 |
|
5171 | __proto.decreaseIndex = function (val) {
|
5172 | this._index -= Math.max(val, 0);
|
5173 | return this;
|
5174 | };
|
5175 | |
5176 |
|
5177 |
|
5178 |
|
5179 |
|
5180 | __proto.updatePosition = function () {
|
5181 | var prevPanel = this._flicking.renderer.panels[this._index - 1];
|
5182 | this._pos = prevPanel ? prevPanel.range.max + prevPanel.margin.next + this._margin.prev : this._margin.prev;
|
5183 | return this;
|
5184 | };
|
5185 | |
5186 |
|
5187 |
|
5188 |
|
5189 |
|
5190 |
|
5191 | __proto.toggle = function (prevPos, newPos) {
|
5192 | var toggleDirection = this._toggleDirection;
|
5193 | var togglePosition = this._togglePosition;
|
5194 | if (toggleDirection === DIRECTION.NONE || newPos === prevPos) return false;
|
5195 | var prevToggled = this._toggled;
|
5196 |
|
5197 | if (newPos > prevPos) {
|
5198 | if (togglePosition >= prevPos && togglePosition <= newPos) {
|
5199 | this._toggled = toggleDirection === DIRECTION.NEXT;
|
5200 | }
|
5201 | } else {
|
5202 | if (togglePosition <= prevPos && togglePosition >= newPos) {
|
5203 | this._toggled = toggleDirection !== DIRECTION.NEXT;
|
5204 | }
|
5205 | }
|
5206 |
|
5207 | return prevToggled !== this._toggled;
|
5208 | };
|
5209 | |
5210 |
|
5211 |
|
5212 |
|
5213 |
|
5214 | __proto.updateCircularToggleDirection = function () {
|
5215 | var flicking = this._flicking;
|
5216 |
|
5217 | if (!flicking.circularEnabled) {
|
5218 | this._toggleDirection = DIRECTION.NONE;
|
5219 | this._toggled = false;
|
5220 | return this;
|
5221 | }
|
5222 |
|
5223 | var camera = flicking.camera;
|
5224 | var camRange = camera.range;
|
5225 | var camAlignPosition = camera.alignPosition;
|
5226 | var camVisibleRange = camera.visibleRange;
|
5227 | var camVisibleSize = camVisibleRange.max - camVisibleRange.min;
|
5228 | var minimumVisible = camRange.min - camAlignPosition;
|
5229 | var maximumVisible = camRange.max - camAlignPosition + camVisibleSize;
|
5230 | var shouldBeVisibleAtMin = this.includeRange(maximumVisible - camVisibleSize, maximumVisible, false);
|
5231 | var shouldBeVisibleAtMax = this.includeRange(minimumVisible, minimumVisible + camVisibleSize, false);
|
5232 | this._toggled = false;
|
5233 |
|
5234 | if (shouldBeVisibleAtMin) {
|
5235 | this._toggleDirection = DIRECTION.PREV;
|
5236 | this._togglePosition = this.range.max + camRange.min - camRange.max + camAlignPosition;
|
5237 | this.toggle(Infinity, camera.position);
|
5238 | } else if (shouldBeVisibleAtMax) {
|
5239 | this._toggleDirection = DIRECTION.NEXT;
|
5240 | this._togglePosition = this.range.min + camRange.max - camVisibleSize + camAlignPosition;
|
5241 | this.toggle(-Infinity, camera.position);
|
5242 | } else {
|
5243 | this._toggleDirection = DIRECTION.NONE;
|
5244 | this._togglePosition = 0;
|
5245 | }
|
5246 |
|
5247 | return this;
|
5248 | };
|
5249 |
|
5250 | __proto._updateAlignPos = function () {
|
5251 | this._alignPos = parseAlign$1(this._align, this._size);
|
5252 | };
|
5253 |
|
5254 | __proto._resetInternalStates = function () {
|
5255 | this._size = 0;
|
5256 | this._pos = 0;
|
5257 | this._margin = {
|
5258 | prev: 0,
|
5259 | next: 0
|
5260 | };
|
5261 | this._height = 0;
|
5262 | this._alignPos = 0;
|
5263 | this._toggled = false;
|
5264 | this._togglePosition = 0;
|
5265 | this._toggleDirection = DIRECTION.NONE;
|
5266 | };
|
5267 |
|
5268 | return Panel;
|
5269 | }();
|
5270 |
|
5271 |
|
5272 |
|
5273 |
|
5274 |
|
5275 |
|
5276 | var ElementPanel = function (_super) {
|
5277 | __extends(ElementPanel, _super);
|
5278 | |
5279 |
|
5280 |
|
5281 |
|
5282 |
|
5283 |
|
5284 |
|
5285 |
|
5286 |
|
5287 | function ElementPanel(options) {
|
5288 | var _this = _super.call(this, options) || this;
|
5289 |
|
5290 | _this._el = options.el;
|
5291 | _this._rendered = true;
|
5292 | return _this;
|
5293 | }
|
5294 |
|
5295 | var __proto = ElementPanel.prototype;
|
5296 | Object.defineProperty(__proto, "element", {
|
5297 | |
5298 |
|
5299 |
|
5300 |
|
5301 |
|
5302 |
|
5303 | get: function () {
|
5304 | return this._el;
|
5305 | },
|
5306 | enumerable: false,
|
5307 | configurable: true
|
5308 | });
|
5309 | Object.defineProperty(__proto, "rendered", {
|
5310 | get: function () {
|
5311 | return this._rendered;
|
5312 | },
|
5313 | enumerable: false,
|
5314 | configurable: true
|
5315 | });
|
5316 |
|
5317 | __proto.markForShow = function () {
|
5318 | this._rendered = true;
|
5319 | };
|
5320 |
|
5321 | __proto.markForHide = function () {
|
5322 | this._rendered = false;
|
5323 | };
|
5324 |
|
5325 | return ElementPanel;
|
5326 | }(Panel);
|
5327 |
|
5328 |
|
5329 |
|
5330 |
|
5331 |
|
5332 | var VanillaRenderer = function (_super) {
|
5333 | __extends(VanillaRenderer, _super);
|
5334 |
|
5335 | function VanillaRenderer() {
|
5336 | return _super !== null && _super.apply(this, arguments) || this;
|
5337 | }
|
5338 |
|
5339 |
|
5340 | var __proto = VanillaRenderer.prototype;
|
5341 |
|
5342 | __proto.render = function () {
|
5343 | return __awaiter(this, void 0, void 0, function () {
|
5344 | var flicking, cameraEl, wasRenderedPanels, renderingPanels;
|
5345 | return __generator(this, function (_a) {
|
5346 | flicking = getFlickingAttached(this._flicking, "Renderer");
|
5347 | cameraEl = flicking.camera.element;
|
5348 | wasRenderedPanels = this._panels.filter(function (panel) {
|
5349 | return panel.element.parentElement === cameraEl;
|
5350 | });
|
5351 |
|
5352 | this._updateRenderingPanels();
|
5353 |
|
5354 | renderingPanels = this._getRenderingPanelsByOrder();
|
5355 |
|
5356 | this._removePanelElements(wasRenderedPanels.filter(function (panel) {
|
5357 | return !panel.rendered;
|
5358 | }));
|
5359 |
|
5360 | this._insertPanelElements(renderingPanels.filter(function (panel) {
|
5361 | return panel.element.parentElement !== cameraEl;
|
5362 | }), null);
|
5363 |
|
5364 | this._resetPanelElementOrder(renderingPanels);
|
5365 |
|
5366 | return [2
|
5367 |
|
5368 | ];
|
5369 | });
|
5370 | });
|
5371 | };
|
5372 |
|
5373 |
|
5374 | __proto.forceRenderAllPanels = function () {
|
5375 | return __awaiter(this, void 0, void 0, function () {
|
5376 | var flicking, camera, cameraElement, fragment;
|
5377 | return __generator(this, function (_a) {
|
5378 | flicking = getFlickingAttached(this._flicking, "Renderer");
|
5379 | camera = flicking.camera;
|
5380 | cameraElement = camera.element;
|
5381 | fragment = document.createDocumentFragment();
|
5382 |
|
5383 | this._panels.forEach(function (panel) {
|
5384 | return fragment.appendChild(panel.element);
|
5385 | });
|
5386 |
|
5387 | this._removeAllChildsFromCamera();
|
5388 |
|
5389 | cameraElement.appendChild(fragment);
|
5390 | return [2
|
5391 |
|
5392 | ];
|
5393 | });
|
5394 | });
|
5395 | };
|
5396 |
|
5397 | __proto._collectPanels = function () {
|
5398 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
5399 | var cameraElement = flicking.camera.element;
|
5400 |
|
5401 | toArray(cameraElement.childNodes).forEach(function (node) {
|
5402 | if (node.nodeType === Node.TEXT_NODE) {
|
5403 | cameraElement.removeChild(node);
|
5404 | }
|
5405 | });
|
5406 |
|
5407 | var align = this._getPanelAlign();
|
5408 |
|
5409 | var cameraChilds = toArray(cameraElement.children);
|
5410 | this._panels = cameraChilds.map(function (el, index) {
|
5411 | return new ElementPanel({
|
5412 | flicking: flicking,
|
5413 | el: el,
|
5414 | index: index,
|
5415 | align: align
|
5416 | });
|
5417 | });
|
5418 | };
|
5419 |
|
5420 | __proto._createPanel = function (el, options) {
|
5421 | return new ElementPanel(__assign({
|
5422 | el: el
|
5423 | }, options));
|
5424 | };
|
5425 |
|
5426 | __proto._insertPanelElements = function (panels, nextSibling) {
|
5427 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
5428 | var camera = flicking.camera;
|
5429 | var cameraElement = camera.element;
|
5430 | var nextSiblingElement = (nextSibling === null || nextSibling === void 0 ? void 0 : nextSibling.element) || null;
|
5431 | var fragment = document.createDocumentFragment();
|
5432 | panels.forEach(function (panel) {
|
5433 | return fragment.appendChild(panel.element);
|
5434 | });
|
5435 | cameraElement.insertBefore(fragment, nextSiblingElement);
|
5436 | return this;
|
5437 | };
|
5438 |
|
5439 | __proto._removePanelElements = function (panels) {
|
5440 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
5441 | var cameraElement = flicking.camera.element;
|
5442 | panels.forEach(function (panel) {
|
5443 | cameraElement.removeChild(panel.element);
|
5444 | });
|
5445 | return this;
|
5446 | };
|
5447 |
|
5448 | __proto._resetPanelElementOrder = function (panels) {
|
5449 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
5450 | var cameraEl = flicking.camera.element;
|
5451 |
|
5452 | var reversedPanels = __spreadArray([], __read(panels)).reverse();
|
5453 |
|
5454 | reversedPanels.forEach(function (panel, idx) {
|
5455 | var nextPanel = reversedPanels[idx - 1];
|
5456 | var nextPanelEl = nextPanel ? nextPanel.element : null;
|
5457 |
|
5458 | if (panel.element.nextElementSibling !== nextPanelEl) {
|
5459 | cameraEl.insertBefore(panel.element, nextPanelEl);
|
5460 | }
|
5461 | });
|
5462 | };
|
5463 |
|
5464 | __proto._removeAllChildsFromCamera = function () {
|
5465 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
5466 | var cameraElement = flicking.camera.element;
|
5467 |
|
5468 | while (cameraElement.firstChild) {
|
5469 | cameraElement.removeChild(cameraElement.firstChild);
|
5470 | }
|
5471 | };
|
5472 |
|
5473 | __proto._getRenderingPanelsByOrder = function () {
|
5474 | var flicking = getFlickingAttached(this._flicking, "Renderer");
|
5475 | var panels = flicking.renderer.panels;
|
5476 | return panels.filter(function (panel) {
|
5477 | return panel.rendered;
|
5478 | }).sort(function (a, b) {
|
5479 | return a.position + a.offset - (b.position + b.offset);
|
5480 | });
|
5481 | };
|
5482 |
|
5483 | return VanillaRenderer;
|
5484 | }(Renderer);
|
5485 |
|
5486 |
|
5487 |
|
5488 |
|
5489 |
|
5490 | var ExternalRenderer = function (_super) {
|
5491 | __extends(ExternalRenderer, _super);
|
5492 |
|
5493 | function ExternalRenderer() {
|
5494 | return _super !== null && _super.apply(this, arguments) || this;
|
5495 | }
|
5496 |
|
5497 |
|
5498 | var __proto = ExternalRenderer.prototype;
|
5499 |
|
5500 | __proto._insertPanelElements = function (panels, nextSibling) {
|
5501 | };
|
5502 |
|
5503 |
|
5504 | __proto._removePanelElements = function (panels) {
|
5505 | };
|
5506 |
|
5507 | return ExternalRenderer;
|
5508 | }(Renderer);
|
5509 |
|
5510 |
|
5511 |
|
5512 |
|
5513 |
|
5514 |
|
5515 |
|
5516 |
|
5517 | var Flicking = function (_super) {
|
5518 | __extends(Flicking, _super);
|
5519 | |
5520 |
|
5521 |
|
5522 |
|
5523 |
|
5524 |
|
5525 |
|
5526 |
|
5527 |
|
5528 |
|
5529 |
|
5530 |
|
5531 |
|
5532 |
|
5533 |
|
5534 |
|
5535 |
|
5536 |
|
5537 |
|
5538 |
|
5539 |
|
5540 |
|
5541 |
|
5542 |
|
5543 |
|
5544 |
|
5545 |
|
5546 |
|
5547 |
|
5548 |
|
5549 | function Flicking(root, _a) {
|
5550 | var _b = _a === void 0 ? {} : _a,
|
5551 | _c = _b.align,
|
5552 | align = _c === void 0 ? ALIGN.CENTER : _c,
|
5553 | _d = _b.defaultIndex,
|
5554 | defaultIndex = _d === void 0 ? 0 : _d,
|
5555 | _e = _b.horizontal,
|
5556 | horizontal = _e === void 0 ? true : _e,
|
5557 | _f = _b.circular,
|
5558 | circular = _f === void 0 ? false : _f,
|
5559 | _g = _b.bound,
|
5560 | bound = _g === void 0 ? false : _g,
|
5561 | _h = _b.adaptive,
|
5562 | adaptive = _h === void 0 ? false : _h,
|
5563 | _j = _b.panelsPerView,
|
5564 | panelsPerView = _j === void 0 ? -1 : _j,
|
5565 | _k = _b.noPanelStyleOverride,
|
5566 | noPanelStyleOverride = _k === void 0 ? false : _k,
|
5567 | _l = _b.resizeOnContentsReady,
|
5568 | resizeOnContentsReady = _l === void 0 ? false : _l,
|
5569 | _m = _b.needPanelThreshold,
|
5570 | needPanelThreshold = _m === void 0 ? 0 : _m,
|
5571 | _o = _b.preventEventsBeforeInit,
|
5572 | preventEventsBeforeInit = _o === void 0 ? true : _o,
|
5573 | _p = _b.deceleration,
|
5574 | deceleration = _p === void 0 ? 0.0075 : _p,
|
5575 | _q = _b.duration,
|
5576 | duration = _q === void 0 ? 500 : _q,
|
5577 | _r = _b.easing,
|
5578 | easing = _r === void 0 ? function (x) {
|
5579 | return 1 - Math.pow(1 - x, 3);
|
5580 | } : _r,
|
5581 | _s = _b.inputType,
|
5582 | inputType = _s === void 0 ? ["mouse", "touch"] : _s,
|
5583 | _t = _b.moveType,
|
5584 | moveType = _t === void 0 ? "snap" : _t,
|
5585 | _u = _b.threshold,
|
5586 | threshold = _u === void 0 ? 40 : _u,
|
5587 | _v = _b.interruptable,
|
5588 | interruptable = _v === void 0 ? true : _v,
|
5589 | _w = _b.bounce,
|
5590 | bounce = _w === void 0 ? "20%" : _w,
|
5591 | _x = _b.iOSEdgeSwipeThreshold,
|
5592 | iOSEdgeSwipeThreshold = _x === void 0 ? 30 : _x,
|
5593 | _y = _b.preventClickOnDrag,
|
5594 | preventClickOnDrag = _y === void 0 ? true : _y,
|
5595 | _z = _b.disableOnInit,
|
5596 | disableOnInit = _z === void 0 ? false : _z,
|
5597 | _0 = _b.renderOnlyVisible,
|
5598 | renderOnlyVisible = _0 === void 0 ? false : _0,
|
5599 | _1 = _b.autoInit,
|
5600 | autoInit = _1 === void 0 ? true : _1,
|
5601 | _2 = _b.autoResize,
|
5602 | autoResize = _2 === void 0 ? true : _2,
|
5603 | _3 = _b.renderExternal,
|
5604 | renderExternal = _3 === void 0 ? null : _3;
|
5605 |
|
5606 | var _this = _super.call(this) || this;
|
5607 |
|
5608 |
|
5609 | _this._initialized = false;
|
5610 | _this._plugins = [];
|
5611 |
|
5612 | _this._align = align;
|
5613 | _this._defaultIndex = defaultIndex;
|
5614 | _this._horizontal = horizontal;
|
5615 | _this._circular = circular;
|
5616 | _this._bound = bound;
|
5617 | _this._adaptive = adaptive;
|
5618 | _this._panelsPerView = panelsPerView;
|
5619 | _this._noPanelStyleOverride = noPanelStyleOverride;
|
5620 | _this._resizeOnContentsReady = resizeOnContentsReady;
|
5621 | _this._needPanelThreshold = needPanelThreshold;
|
5622 | _this._preventEventsBeforeInit = preventEventsBeforeInit;
|
5623 | _this._deceleration = deceleration;
|
5624 | _this._duration = duration;
|
5625 | _this._easing = easing;
|
5626 | _this._inputType = inputType;
|
5627 | _this._moveType = moveType;
|
5628 | _this._threshold = threshold;
|
5629 | _this._interruptable = interruptable;
|
5630 | _this._bounce = bounce;
|
5631 | _this._iOSEdgeSwipeThreshold = iOSEdgeSwipeThreshold;
|
5632 | _this._preventClickOnDrag = preventClickOnDrag;
|
5633 | _this._disableOnInit = disableOnInit;
|
5634 | _this._renderOnlyVisible = renderOnlyVisible;
|
5635 | _this._autoResize = autoResize;
|
5636 | _this._autoInit = autoInit;
|
5637 | _this._renderExternal = renderExternal;
|
5638 |
|
5639 | _this._viewport = new Viewport(getElement(root));
|
5640 | _this._renderer = _this._createRenderer();
|
5641 | _this._camera = _this._createCamera();
|
5642 | _this._control = _this._createControl();
|
5643 | _this.resize = _this.resize.bind(_this);
|
5644 |
|
5645 | if (_this._autoInit) {
|
5646 | void _this.init();
|
5647 | }
|
5648 |
|
5649 | return _this;
|
5650 | }
|
5651 |
|
5652 | var __proto = Flicking.prototype;
|
5653 | Object.defineProperty(__proto, "control", {
|
5654 |
|
5655 |
|
5656 | |
5657 |
|
5658 |
|
5659 |
|
5660 |
|
5661 |
|
5662 |
|
5663 |
|
5664 |
|
5665 |
|
5666 | get: function () {
|
5667 | return this._control;
|
5668 | },
|
5669 | enumerable: false,
|
5670 | configurable: true
|
5671 | });
|
5672 | Object.defineProperty(__proto, "camera", {
|
5673 | |
5674 |
|
5675 |
|
5676 |
|
5677 |
|
5678 |
|
5679 |
|
5680 |
|
5681 |
|
5682 |
|
5683 |
|
5684 | get: function () {
|
5685 | return this._camera;
|
5686 | },
|
5687 | enumerable: false,
|
5688 | configurable: true
|
5689 | });
|
5690 | Object.defineProperty(__proto, "renderer", {
|
5691 | |
5692 |
|
5693 |
|
5694 |
|
5695 |
|
5696 |
|
5697 |
|
5698 |
|
5699 |
|
5700 |
|
5701 | get: function () {
|
5702 | return this._renderer;
|
5703 | },
|
5704 | enumerable: false,
|
5705 | configurable: true
|
5706 | });
|
5707 | Object.defineProperty(__proto, "viewport", {
|
5708 | |
5709 |
|
5710 |
|
5711 |
|
5712 |
|
5713 |
|
5714 |
|
5715 | get: function () {
|
5716 | return this._viewport;
|
5717 | },
|
5718 | enumerable: false,
|
5719 | configurable: true
|
5720 | });
|
5721 | Object.defineProperty(__proto, "initialized", {
|
5722 |
|
5723 |
|
5724 | |
5725 |
|
5726 |
|
5727 |
|
5728 |
|
5729 |
|
5730 |
|
5731 |
|
5732 |
|
5733 | get: function () {
|
5734 | return this._initialized;
|
5735 | },
|
5736 | enumerable: false,
|
5737 | configurable: true
|
5738 | });
|
5739 | Object.defineProperty(__proto, "circularEnabled", {
|
5740 | |
5741 |
|
5742 |
|
5743 |
|
5744 |
|
5745 |
|
5746 |
|
5747 |
|
5748 |
|
5749 | get: function () {
|
5750 | return this._camera.controlParams.circular;
|
5751 | },
|
5752 | enumerable: false,
|
5753 | configurable: true
|
5754 | });
|
5755 | Object.defineProperty(__proto, "index", {
|
5756 | |
5757 |
|
5758 |
|
5759 |
|
5760 |
|
5761 |
|
5762 |
|
5763 | get: function () {
|
5764 | return this._control.activeIndex;
|
5765 | },
|
5766 | enumerable: false,
|
5767 | configurable: true
|
5768 | });
|
5769 | Object.defineProperty(__proto, "element", {
|
5770 | |
5771 |
|
5772 |
|
5773 |
|
5774 |
|
5775 |
|
5776 | get: function () {
|
5777 | return this._viewport.element;
|
5778 | },
|
5779 | enumerable: false,
|
5780 | configurable: true
|
5781 | });
|
5782 | Object.defineProperty(__proto, "currentPanel", {
|
5783 | |
5784 |
|
5785 |
|
5786 |
|
5787 |
|
5788 |
|
5789 |
|
5790 | get: function () {
|
5791 | return this._control.activePanel;
|
5792 | },
|
5793 | enumerable: false,
|
5794 | configurable: true
|
5795 | });
|
5796 | Object.defineProperty(__proto, "panels", {
|
5797 | |
5798 |
|
5799 |
|
5800 |
|
5801 |
|
5802 |
|
5803 |
|
5804 | get: function () {
|
5805 | return this._renderer.panels;
|
5806 | },
|
5807 | enumerable: false,
|
5808 | configurable: true
|
5809 | });
|
5810 | Object.defineProperty(__proto, "panelCount", {
|
5811 | |
5812 |
|
5813 |
|
5814 |
|
5815 |
|
5816 |
|
5817 | get: function () {
|
5818 | return this._renderer.panelCount;
|
5819 | },
|
5820 | enumerable: false,
|
5821 | configurable: true
|
5822 | });
|
5823 | Object.defineProperty(__proto, "visiblePanels", {
|
5824 | |
5825 |
|
5826 |
|
5827 |
|
5828 |
|
5829 |
|
5830 |
|
5831 | get: function () {
|
5832 | return this._camera.visiblePanels;
|
5833 | },
|
5834 | enumerable: false,
|
5835 | configurable: true
|
5836 | });
|
5837 | Object.defineProperty(__proto, "animating", {
|
5838 | |
5839 |
|
5840 |
|
5841 |
|
5842 |
|
5843 |
|
5844 | get: function () {
|
5845 | return this._control.animating;
|
5846 | },
|
5847 | enumerable: false,
|
5848 | configurable: true
|
5849 | });
|
5850 | Object.defineProperty(__proto, "holding", {
|
5851 | |
5852 |
|
5853 |
|
5854 |
|
5855 |
|
5856 |
|
5857 | get: function () {
|
5858 | return this._control.holding;
|
5859 | },
|
5860 | enumerable: false,
|
5861 | configurable: true
|
5862 | });
|
5863 | Object.defineProperty(__proto, "activePlugins", {
|
5864 | |
5865 |
|
5866 |
|
5867 |
|
5868 |
|
5869 |
|
5870 | get: function () {
|
5871 | return this._plugins;
|
5872 | },
|
5873 | enumerable: false,
|
5874 | configurable: true
|
5875 | });
|
5876 | Object.defineProperty(__proto, "align", {
|
5877 |
|
5878 |
|
5879 |
|
5880 | |
5881 |
|
5882 |
|
5883 |
|
5884 |
|
5885 |
|
5886 |
|
5887 |
|
5888 |
|
5889 |
|
5890 |
|
5891 |
|
5892 |
|
5893 |
|
5894 |
|
5895 |
|
5896 |
|
5897 |
|
5898 |
|
5899 |
|
5900 |
|
5901 |
|
5902 |
|
5903 |
|
5904 |
|
5905 |
|
5906 |
|
5907 | get: function () {
|
5908 | return this._align;
|
5909 | },
|
5910 |
|
5911 |
|
5912 | set: function (val) {
|
5913 | this._align = val;
|
5914 | this._renderer.align = val;
|
5915 | this._camera.align = val;
|
5916 | },
|
5917 | enumerable: false,
|
5918 | configurable: true
|
5919 | });
|
5920 | Object.defineProperty(__proto, "defaultIndex", {
|
5921 | |
5922 |
|
5923 |
|
5924 |
|
5925 |
|
5926 |
|
5927 | get: function () {
|
5928 | return this._defaultIndex;
|
5929 | },
|
5930 | set: function (val) {
|
5931 | this._defaultIndex = val;
|
5932 | },
|
5933 | enumerable: false,
|
5934 | configurable: true
|
5935 | });
|
5936 | Object.defineProperty(__proto, "horizontal", {
|
5937 | |
5938 |
|
5939 |
|
5940 |
|
5941 |
|
5942 |
|
5943 | get: function () {
|
5944 | return this._horizontal;
|
5945 | },
|
5946 | set: function (val) {
|
5947 | this._horizontal = val;
|
5948 | },
|
5949 | enumerable: false,
|
5950 | configurable: true
|
5951 | });
|
5952 | Object.defineProperty(__proto, "circular", {
|
5953 | |
5954 |
|
5955 |
|
5956 |
|
5957 |
|
5958 |
|
5959 | get: function () {
|
5960 | return this._circular;
|
5961 | },
|
5962 | set: function (val) {
|
5963 | this._circular = val;
|
5964 | },
|
5965 | enumerable: false,
|
5966 | configurable: true
|
5967 | });
|
5968 | Object.defineProperty(__proto, "bound", {
|
5969 | |
5970 |
|
5971 |
|
5972 |
|
5973 |
|
5974 |
|
5975 |
|
5976 |
|
5977 | get: function () {
|
5978 | return this._bound;
|
5979 | },
|
5980 | set: function (val) {
|
5981 | this._bound = val;
|
5982 | },
|
5983 | enumerable: false,
|
5984 | configurable: true
|
5985 | });
|
5986 | Object.defineProperty(__proto, "adaptive", {
|
5987 | |
5988 |
|
5989 |
|
5990 |
|
5991 |
|
5992 |
|
5993 | get: function () {
|
5994 | return this._adaptive;
|
5995 | },
|
5996 | set: function (val) {
|
5997 | this._adaptive = val;
|
5998 | },
|
5999 | enumerable: false,
|
6000 | configurable: true
|
6001 | });
|
6002 | Object.defineProperty(__proto, "panelsPerView", {
|
6003 | |
6004 |
|
6005 |
|
6006 |
|
6007 |
|
6008 |
|
6009 | get: function () {
|
6010 | return this._panelsPerView;
|
6011 | },
|
6012 | set: function (val) {
|
6013 | this._panelsPerView = val;
|
6014 | },
|
6015 | enumerable: false,
|
6016 | configurable: true
|
6017 | });
|
6018 | Object.defineProperty(__proto, "noPanelStyleOverride", {
|
6019 | |
6020 |
|
6021 |
|
6022 |
|
6023 |
|
6024 |
|
6025 |
|
6026 |
|
6027 | get: function () {
|
6028 | return this._noPanelStyleOverride;
|
6029 | },
|
6030 | set: function (val) {
|
6031 | this._noPanelStyleOverride = val;
|
6032 | },
|
6033 | enumerable: false,
|
6034 | configurable: true
|
6035 | });
|
6036 | Object.defineProperty(__proto, "resizeOnContentsReady", {
|
6037 | |
6038 |
|
6039 |
|
6040 |
|
6041 |
|
6042 |
|
6043 |
|
6044 |
|
6045 | get: function () {
|
6046 | return this._resizeOnContentsReady;
|
6047 | },
|
6048 | set: function (val) {
|
6049 | this._resizeOnContentsReady = val;
|
6050 | },
|
6051 | enumerable: false,
|
6052 | configurable: true
|
6053 | });
|
6054 | Object.defineProperty(__proto, "needPanelThreshold", {
|
6055 |
|
6056 |
|
6057 | |
6058 |
|
6059 |
|
6060 |
|
6061 |
|
6062 |
|
6063 | get: function () {
|
6064 | return this._needPanelThreshold;
|
6065 | },
|
6066 |
|
6067 | set: function (val) {
|
6068 | this._needPanelThreshold = val;
|
6069 | },
|
6070 | enumerable: false,
|
6071 | configurable: true
|
6072 | });
|
6073 | Object.defineProperty(__proto, "preventEventsBeforeInit", {
|
6074 | |
6075 |
|
6076 |
|
6077 |
|
6078 |
|
6079 |
|
6080 | get: function () {
|
6081 | return this._preventEventsBeforeInit;
|
6082 | },
|
6083 | set: function (val) {
|
6084 | this._preventEventsBeforeInit = val;
|
6085 | },
|
6086 | enumerable: false,
|
6087 | configurable: true
|
6088 | });
|
6089 | Object.defineProperty(__proto, "deceleration", {
|
6090 |
|
6091 |
|
6092 | |
6093 |
|
6094 |
|
6095 |
|
6096 |
|
6097 |
|
6098 | get: function () {
|
6099 | return this._deceleration;
|
6100 | },
|
6101 |
|
6102 | set: function (val) {
|
6103 | this._deceleration = val;
|
6104 | },
|
6105 | enumerable: false,
|
6106 | configurable: true
|
6107 | });
|
6108 | Object.defineProperty(__proto, "easing", {
|
6109 | |
6110 |
|
6111 |
|
6112 |
|
6113 |
|
6114 |
|
6115 |
|
6116 | get: function () {
|
6117 | return this._easing;
|
6118 | },
|
6119 | set: function (val) {
|
6120 | this._easing = val;
|
6121 | },
|
6122 | enumerable: false,
|
6123 | configurable: true
|
6124 | });
|
6125 | Object.defineProperty(__proto, "duration", {
|
6126 | |
6127 |
|
6128 |
|
6129 |
|
6130 |
|
6131 |
|
6132 | get: function () {
|
6133 | return this._duration;
|
6134 | },
|
6135 | set: function (val) {
|
6136 | this._duration = val;
|
6137 | },
|
6138 | enumerable: false,
|
6139 | configurable: true
|
6140 | });
|
6141 | Object.defineProperty(__proto, "inputType", {
|
6142 |
|
6143 |
|
6144 | |
6145 |
|
6146 |
|
6147 |
|
6148 |
|
6149 |
|
6150 |
|
6151 |
|
6152 | get: function () {
|
6153 | return this._inputType;
|
6154 | },
|
6155 |
|
6156 | set: function (val) {
|
6157 | this._inputType = val;
|
6158 | },
|
6159 | enumerable: false,
|
6160 | configurable: true
|
6161 | });
|
6162 | Object.defineProperty(__proto, "moveType", {
|
6163 | |
6164 |
|
6165 |
|
6166 |
|
6167 |
|
6168 |
|
6169 |
|
6170 |
|
6171 |
|
6172 |
|
6173 |
|
6174 |
|
6175 |
|
6176 |
|
6177 |
|
6178 |
|
6179 |
|
6180 |
|
6181 |
|
6182 |
|
6183 |
|
6184 |
|
6185 |
|
6186 |
|
6187 |
|
6188 |
|
6189 |
|
6190 |
|
6191 |
|
6192 |
|
6193 | get: function () {
|
6194 | return this._moveType;
|
6195 | },
|
6196 | set: function (val) {
|
6197 | this._moveType = val;
|
6198 | },
|
6199 | enumerable: false,
|
6200 | configurable: true
|
6201 | });
|
6202 | Object.defineProperty(__proto, "threshold", {
|
6203 | |
6204 |
|
6205 |
|
6206 |
|
6207 |
|
6208 |
|
6209 | get: function () {
|
6210 | return this._threshold;
|
6211 | },
|
6212 | set: function (val) {
|
6213 | this._threshold = val;
|
6214 | },
|
6215 | enumerable: false,
|
6216 | configurable: true
|
6217 | });
|
6218 | Object.defineProperty(__proto, "interruptable", {
|
6219 | |
6220 |
|
6221 |
|
6222 |
|
6223 |
|
6224 |
|
6225 | get: function () {
|
6226 | return this._interruptable;
|
6227 | },
|
6228 | set: function (val) {
|
6229 | this._interruptable = val;
|
6230 | },
|
6231 | enumerable: false,
|
6232 | configurable: true
|
6233 | });
|
6234 | Object.defineProperty(__proto, "bounce", {
|
6235 | |
6236 |
|
6237 |
|
6238 |
|
6239 |
|
6240 |
|
6241 |
|
6242 |
|
6243 |
|
6244 |
|
6245 |
|
6246 |
|
6247 |
|
6248 |
|
6249 |
|
6250 |
|
6251 |
|
6252 |
|
6253 |
|
6254 |
|
6255 |
|
6256 |
|
6257 |
|
6258 |
|
6259 |
|
6260 |
|
6261 |
|
6262 |
|
6263 |
|
6264 |
|
6265 |
|
6266 | get: function () {
|
6267 | return this._bounce;
|
6268 | },
|
6269 | set: function (val) {
|
6270 | this._bounce = val;
|
6271 | },
|
6272 | enumerable: false,
|
6273 | configurable: true
|
6274 | });
|
6275 | Object.defineProperty(__proto, "iOSEdgeSwipeThreshold", {
|
6276 | |
6277 |
|
6278 |
|
6279 |
|
6280 |
|
6281 |
|
6282 | get: function () {
|
6283 | return this._iOSEdgeSwipeThreshold;
|
6284 | },
|
6285 | set: function (val) {
|
6286 | this._iOSEdgeSwipeThreshold = val;
|
6287 | },
|
6288 | enumerable: false,
|
6289 | configurable: true
|
6290 | });
|
6291 | Object.defineProperty(__proto, "preventClickOnDrag", {
|
6292 | |
6293 |
|
6294 |
|
6295 |
|
6296 |
|
6297 |
|
6298 | get: function () {
|
6299 | return this._preventClickOnDrag;
|
6300 | },
|
6301 | set: function (val) {
|
6302 | var prevVal = this._preventClickOnDrag;
|
6303 | if (val === prevVal) return;
|
6304 | var controller = this._control.controller;
|
6305 |
|
6306 | if (val) {
|
6307 | controller.addPreventClickHandler();
|
6308 | } else {
|
6309 | controller.removePreventClickHandler();
|
6310 | }
|
6311 |
|
6312 | this._preventClickOnDrag = val;
|
6313 | },
|
6314 | enumerable: false,
|
6315 | configurable: true
|
6316 | });
|
6317 | Object.defineProperty(__proto, "disableOnInit", {
|
6318 | |
6319 |
|
6320 |
|
6321 |
|
6322 |
|
6323 |
|
6324 | get: function () {
|
6325 | return this._disableOnInit;
|
6326 | },
|
6327 | set: function (val) {
|
6328 | this._disableOnInit = val;
|
6329 | },
|
6330 | enumerable: false,
|
6331 | configurable: true
|
6332 | });
|
6333 | Object.defineProperty(__proto, "renderOnlyVisible", {
|
6334 |
|
6335 |
|
6336 | |
6337 |
|
6338 |
|
6339 |
|
6340 |
|
6341 |
|
6342 | get: function () {
|
6343 | return this._renderOnlyVisible;
|
6344 | },
|
6345 |
|
6346 | set: function (val) {
|
6347 | this._renderOnlyVisible = val;
|
6348 | },
|
6349 | enumerable: false,
|
6350 | configurable: true
|
6351 | });
|
6352 | Object.defineProperty(__proto, "autoInit", {
|
6353 |
|
6354 |
|
6355 | |
6356 |
|
6357 |
|
6358 |
|
6359 |
|
6360 |
|
6361 |
|
6362 | get: function () {
|
6363 | return this._autoInit;
|
6364 | },
|
6365 | enumerable: false,
|
6366 | configurable: true
|
6367 | });
|
6368 | Object.defineProperty(__proto, "autoResize", {
|
6369 | |
6370 |
|
6371 |
|
6372 |
|
6373 |
|
6374 |
|
6375 |
|
6376 |
|
6377 | get: function () {
|
6378 | return this._autoResize;
|
6379 | },
|
6380 |
|
6381 | set: function (val) {
|
6382 | this._autoResize = val;
|
6383 | },
|
6384 | enumerable: false,
|
6385 | configurable: true
|
6386 | });
|
6387 | Object.defineProperty(__proto, "renderExternal", {
|
6388 | |
6389 |
|
6390 |
|
6391 |
|
6392 |
|
6393 |
|
6394 |
|
6395 |
|
6396 | get: function () {
|
6397 | return this._renderExternal;
|
6398 | },
|
6399 | enumerable: false,
|
6400 | configurable: true
|
6401 | });
|
6402 | |
6403 |
|
6404 |
|
6405 |
|
6406 |
|
6407 |
|
6408 |
|
6409 |
|
6410 |
|
6411 | __proto.init = function () {
|
6412 | return __awaiter(this, void 0, void 0, function () {
|
6413 | var camera, renderer, control, originalTrigger, preventEventsBeforeInit;
|
6414 |
|
6415 | var _this = this;
|
6416 |
|
6417 | return __generator(this, function (_a) {
|
6418 | switch (_a.label) {
|
6419 | case 0:
|
6420 | if (this._initialized) return [2
|
6421 |
|
6422 | ];
|
6423 | camera = this._camera;
|
6424 | renderer = this._renderer;
|
6425 | control = this._control;
|
6426 | originalTrigger = this.trigger;
|
6427 | preventEventsBeforeInit = this._preventEventsBeforeInit;
|
6428 | camera.init(this);
|
6429 | renderer.init(this);
|
6430 | control.init(this);
|
6431 |
|
6432 | if (preventEventsBeforeInit) {
|
6433 | this.trigger = function () {
|
6434 | return _this;
|
6435 | };
|
6436 | }
|
6437 |
|
6438 | return [4
|
6439 |
|
6440 | , this.resize()];
|
6441 |
|
6442 | case 1:
|
6443 | _a.sent();
|
6444 |
|
6445 |
|
6446 | return [4
|
6447 |
|
6448 | , this._moveToInitialPanel()];
|
6449 |
|
6450 | case 2:
|
6451 |
|
6452 | _a.sent();
|
6453 |
|
6454 | if (this._autoResize) {
|
6455 | window.addEventListener("resize", this.resize);
|
6456 | }
|
6457 |
|
6458 | if (this._preventClickOnDrag) {
|
6459 | control.controller.addPreventClickHandler();
|
6460 | }
|
6461 |
|
6462 | if (this._disableOnInit) {
|
6463 | this.disableInput();
|
6464 | }
|
6465 |
|
6466 | renderer.checkPanelContentsReady(renderer.panels);
|
6467 |
|
6468 | this._plugins.forEach(function (plugin) {
|
6469 | return plugin.init(_this);
|
6470 | });
|
6471 |
|
6472 |
|
6473 | this._initialized = true;
|
6474 |
|
6475 | if (preventEventsBeforeInit) {
|
6476 | this.trigger = originalTrigger;
|
6477 | }
|
6478 |
|
6479 | this.trigger(new ComponentEvent(EVENTS.READY));
|
6480 | return [2
|
6481 |
|
6482 | ];
|
6483 | }
|
6484 | });
|
6485 | });
|
6486 | };
|
6487 | |
6488 |
|
6489 |
|
6490 |
|
6491 |
|
6492 |
|
6493 |
|
6494 | __proto.destroy = function () {
|
6495 | this.off();
|
6496 | window.removeEventListener("resize", this.resize);
|
6497 |
|
6498 | this._control.destroy();
|
6499 |
|
6500 | this._camera.destroy();
|
6501 |
|
6502 | this._renderer.destroy();
|
6503 |
|
6504 | this._plugins.forEach(function (plugin) {
|
6505 | return plugin.destroy();
|
6506 | });
|
6507 |
|
6508 | this._initialized = false;
|
6509 | };
|
6510 | |
6511 |
|
6512 |
|
6513 |
|
6514 |
|
6515 |
|
6516 |
|
6517 |
|
6518 |
|
6519 |
|
6520 |
|
6521 |
|
6522 |
|
6523 |
|
6524 |
|
6525 |
|
6526 |
|
6527 |
|
6528 |
|
6529 |
|
6530 |
|
6531 |
|
6532 |
|
6533 |
|
6534 |
|
6535 |
|
6536 |
|
6537 |
|
6538 |
|
6539 |
|
6540 |
|
6541 |
|
6542 |
|
6543 |
|
6544 |
|
6545 | __proto.prev = function (duration) {
|
6546 | var _a, _b, _c;
|
6547 |
|
6548 | if (duration === void 0) {
|
6549 | duration = this._duration;
|
6550 | }
|
6551 |
|
6552 | 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);
|
6553 | };
|
6554 | |
6555 |
|
6556 |
|
6557 |
|
6558 |
|
6559 |
|
6560 |
|
6561 |
|
6562 |
|
6563 |
|
6564 |
|
6565 |
|
6566 |
|
6567 |
|
6568 |
|
6569 |
|
6570 |
|
6571 |
|
6572 |
|
6573 |
|
6574 |
|
6575 |
|
6576 |
|
6577 |
|
6578 |
|
6579 |
|
6580 |
|
6581 |
|
6582 |
|
6583 |
|
6584 |
|
6585 |
|
6586 |
|
6587 |
|
6588 |
|
6589 |
|
6590 | __proto.next = function (duration) {
|
6591 | var _a, _b, _c;
|
6592 |
|
6593 | if (duration === void 0) {
|
6594 | duration = this._duration;
|
6595 | }
|
6596 |
|
6597 | 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);
|
6598 | };
|
6599 | |
6600 |
|
6601 |
|
6602 |
|
6603 |
|
6604 |
|
6605 |
|
6606 |
|
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.moveTo = function (index, duration, direction) {
|
6638 | if (duration === void 0) {
|
6639 | duration = this._duration;
|
6640 | }
|
6641 |
|
6642 | if (direction === void 0) {
|
6643 | direction = DIRECTION.NONE;
|
6644 | }
|
6645 |
|
6646 | var renderer = this._renderer;
|
6647 | var panelCount = renderer.panelCount;
|
6648 | var panel = renderer.getPanel(index);
|
6649 |
|
6650 | if (!panel) {
|
6651 | return Promise.reject(new FlickingError(MESSAGE.INDEX_OUT_OF_RANGE(index, 0, panelCount - 1), CODE.INDEX_OUT_OF_RANGE));
|
6652 | }
|
6653 |
|
6654 | if (this._control.animating) {
|
6655 | return Promise.reject(new FlickingError(MESSAGE.ANIMATION_ALREADY_PLAYING, CODE.ANIMATION_ALREADY_PLAYING));
|
6656 | }
|
6657 |
|
6658 | return this._control.moveToPanel(panel, {
|
6659 | duration: duration,
|
6660 | direction: direction
|
6661 | });
|
6662 | };
|
6663 | |
6664 |
|
6665 |
|
6666 |
|
6667 |
|
6668 |
|
6669 |
|
6670 |
|
6671 |
|
6672 |
|
6673 |
|
6674 |
|
6675 |
|
6676 |
|
6677 | __proto.getPanel = function (index) {
|
6678 | return this._renderer.getPanel(index);
|
6679 | };
|
6680 | |
6681 |
|
6682 |
|
6683 |
|
6684 |
|
6685 |
|
6686 |
|
6687 | __proto.enableInput = function () {
|
6688 | this._control.enable();
|
6689 |
|
6690 | return this;
|
6691 | };
|
6692 | |
6693 |
|
6694 |
|
6695 |
|
6696 |
|
6697 |
|
6698 |
|
6699 | __proto.disableInput = function () {
|
6700 | this._control.disable();
|
6701 |
|
6702 | return this;
|
6703 | };
|
6704 | |
6705 |
|
6706 |
|
6707 |
|
6708 |
|
6709 |
|
6710 |
|
6711 |
|
6712 |
|
6713 |
|
6714 |
|
6715 |
|
6716 |
|
6717 | __proto.getStatus = function (_a) {
|
6718 | var _b, _c;
|
6719 |
|
6720 | var _d = _a === void 0 ? {} : _a,
|
6721 | _e = _d.index,
|
6722 | index = _e === void 0 ? true : _e,
|
6723 | _f = _d.position,
|
6724 | position = _f === void 0 ? true : _f,
|
6725 | _g = _d.includePanelHTML,
|
6726 | includePanelHTML = _g === void 0 ? false : _g,
|
6727 | _h = _d.visiblePanelsOnly,
|
6728 | visiblePanelsOnly = _h === void 0 ? false : _h;
|
6729 |
|
6730 | var camera = this._camera;
|
6731 | var panels = visiblePanelsOnly ? this.visiblePanels : this.panels;
|
6732 | var status = {
|
6733 | panels: panels.map(function (panel) {
|
6734 | var panelInfo = {
|
6735 | index: panel.index
|
6736 | };
|
6737 |
|
6738 | if (includePanelHTML) {
|
6739 | panelInfo.html = panel.element.outerHTML;
|
6740 | }
|
6741 |
|
6742 | return panelInfo;
|
6743 | })
|
6744 | };
|
6745 |
|
6746 | if (index) {
|
6747 | status.index = this.index;
|
6748 | }
|
6749 |
|
6750 | if (position) {
|
6751 | var nearestAnchor = camera.findNearestAnchor(camera.position);
|
6752 |
|
6753 | if (nearestAnchor) {
|
6754 | status.position = {
|
6755 | panel: nearestAnchor.panel.index,
|
6756 | progressInPanel: camera.getProgressInPanel(nearestAnchor.panel)
|
6757 | };
|
6758 | }
|
6759 | }
|
6760 |
|
6761 | if (visiblePanelsOnly) {
|
6762 | var visiblePanels = this.visiblePanels;
|
6763 | status.visibleOffset = (_c = (_b = visiblePanels[0]) === null || _b === void 0 ? void 0 : _b.index) !== null && _c !== void 0 ? _c : 0;
|
6764 | }
|
6765 |
|
6766 | return status;
|
6767 | };
|
6768 | |
6769 |
|
6770 |
|
6771 |
|
6772 |
|
6773 |
|
6774 |
|
6775 |
|
6776 | __proto.setStatus = function (status) {
|
6777 | var _a;
|
6778 |
|
6779 | if (!this._initialized) {
|
6780 | throw new FlickingError(MESSAGE.NOT_INITIALIZED, CODE.NOT_INITIALIZED);
|
6781 | }
|
6782 |
|
6783 | var index = status.index,
|
6784 | position = status.position,
|
6785 | visibleOffset = status.visibleOffset,
|
6786 | panels = status.panels;
|
6787 | var renderer = this._renderer;
|
6788 | var control = this._control;
|
6789 |
|
6790 | if (((_a = panels[0]) === null || _a === void 0 ? void 0 : _a.html) && !this._renderExternal) {
|
6791 | renderer.batchRemove({
|
6792 | index: 0,
|
6793 | deleteCount: this.panels.length
|
6794 | });
|
6795 | renderer.batchInsert({
|
6796 | index: 0,
|
6797 | elements: parseElement(panels.map(function (panel) {
|
6798 | return panel.html;
|
6799 | }))
|
6800 | });
|
6801 | }
|
6802 |
|
6803 | if (index) {
|
6804 | var panelIndex = visibleOffset ? index - visibleOffset : index;
|
6805 | void this.moveTo(panelIndex, 0).catch(function () {
|
6806 | return void 0;
|
6807 | });
|
6808 | }
|
6809 |
|
6810 | if (position && this._moveType === MOVE_TYPE.FREE_SCROLL) {
|
6811 | var panel = position.panel,
|
6812 | progressInPanel = position.progressInPanel;
|
6813 | var panelIndex = visibleOffset ? panel - visibleOffset : panel;
|
6814 | var panelRange = renderer.panels[panelIndex].range;
|
6815 | var newCameraPos = panelRange.min + (panelRange.max - panelRange.min) * progressInPanel;
|
6816 | void control.moveToPosition(newCameraPos, 0).catch(function () {
|
6817 | return void 0;
|
6818 | });
|
6819 | }
|
6820 | };
|
6821 | |
6822 |
|
6823 |
|
6824 |
|
6825 |
|
6826 |
|
6827 |
|
6828 |
|
6829 |
|
6830 | __proto.addPlugins = function () {
|
6831 | var _a;
|
6832 |
|
6833 | var _this = this;
|
6834 |
|
6835 | var plugins = [];
|
6836 |
|
6837 | for (var _i = 0; _i < arguments.length; _i++) {
|
6838 | plugins[_i] = arguments[_i];
|
6839 | }
|
6840 |
|
6841 | if (this._initialized) {
|
6842 | plugins.forEach(function (item) {
|
6843 | return item.init(_this);
|
6844 | });
|
6845 | }
|
6846 |
|
6847 | (_a = this._plugins).push.apply(_a, __spreadArray([], __read(plugins)));
|
6848 |
|
6849 | return this;
|
6850 | };
|
6851 | |
6852 |
|
6853 |
|
6854 |
|
6855 |
|
6856 |
|
6857 |
|
6858 |
|
6859 |
|
6860 | __proto.removePlugins = function () {
|
6861 | var _this = this;
|
6862 |
|
6863 | var plugins = [];
|
6864 |
|
6865 | for (var _i = 0; _i < arguments.length; _i++) {
|
6866 | plugins[_i] = arguments[_i];
|
6867 | }
|
6868 |
|
6869 | plugins.forEach(function (item) {
|
6870 | var foundIndex = findIndex(_this._plugins, function (val) {
|
6871 | return val === item;
|
6872 | });
|
6873 |
|
6874 | if (foundIndex >= 0) {
|
6875 | item.destroy();
|
6876 |
|
6877 | _this._plugins.splice(foundIndex, 1);
|
6878 | }
|
6879 | });
|
6880 | return this;
|
6881 | };
|
6882 | |
6883 |
|
6884 |
|
6885 |
|
6886 |
|
6887 |
|
6888 |
|
6889 |
|
6890 |
|
6891 |
|
6892 | __proto.resize = function () {
|
6893 | return __awaiter(this, void 0, void 0, function () {
|
6894 | var viewport, renderer, camera, control, activePanel, prevWidth, prevHeight, prevProgressInPanel, newWidth, newHeight, sizeChanged;
|
6895 | return __generator(this, function (_a) {
|
6896 | switch (_a.label) {
|
6897 | case 0:
|
6898 | viewport = this._viewport;
|
6899 | renderer = this._renderer;
|
6900 | camera = this._camera;
|
6901 | control = this._control;
|
6902 | activePanel = control.activePanel;
|
6903 | prevWidth = viewport.width;
|
6904 | prevHeight = viewport.height;
|
6905 | prevProgressInPanel = activePanel ? camera.getProgressInPanel(activePanel) : 0;
|
6906 | this.trigger(new ComponentEvent(EVENTS.BEFORE_RESIZE, {
|
6907 | width: prevWidth,
|
6908 | height: prevHeight,
|
6909 | element: viewport.element
|
6910 | }));
|
6911 | viewport.resize();
|
6912 | return [4
|
6913 |
|
6914 | , renderer.forceRenderAllPanels()];
|
6915 |
|
6916 | case 1:
|
6917 | _a.sent();
|
6918 |
|
6919 |
|
6920 | renderer.updatePanelSize();
|
6921 | camera.updateAlignPos();
|
6922 | camera.updateRange();
|
6923 | camera.updateAnchors();
|
6924 | return [4
|
6925 |
|
6926 | , renderer.render()];
|
6927 |
|
6928 | case 2:
|
6929 | _a.sent();
|
6930 |
|
6931 | if (control.animating) ; else {
|
6932 | control.updatePosition(prevProgressInPanel);
|
6933 | control.updateInput();
|
6934 | }
|
6935 |
|
6936 | newWidth = viewport.width;
|
6937 | newHeight = viewport.height;
|
6938 | sizeChanged = newWidth !== prevWidth || newHeight !== prevHeight;
|
6939 | this.trigger(new ComponentEvent(EVENTS.AFTER_RESIZE, {
|
6940 | width: viewport.width,
|
6941 | height: viewport.height,
|
6942 | prev: {
|
6943 | width: prevWidth,
|
6944 | height: prevHeight
|
6945 | },
|
6946 | sizeChanged: sizeChanged,
|
6947 | element: viewport.element
|
6948 | }));
|
6949 | return [2
|
6950 |
|
6951 | ];
|
6952 | }
|
6953 | });
|
6954 | });
|
6955 | };
|
6956 | |
6957 |
|
6958 |
|
6959 |
|
6960 |
|
6961 |
|
6962 |
|
6963 |
|
6964 |
|
6965 |
|
6966 |
|
6967 |
|
6968 |
|
6969 |
|
6970 |
|
6971 |
|
6972 |
|
6973 |
|
6974 |
|
6975 |
|
6976 |
|
6977 |
|
6978 | __proto.append = function (element) {
|
6979 | return this.insert(this._renderer.panelCount, element);
|
6980 | };
|
6981 | |
6982 |
|
6983 |
|
6984 |
|
6985 |
|
6986 |
|
6987 |
|
6988 |
|
6989 |
|
6990 |
|
6991 |
|
6992 |
|
6993 |
|
6994 |
|
6995 |
|
6996 |
|
6997 |
|
6998 |
|
6999 |
|
7000 |
|
7001 |
|
7002 |
|
7003 |
|
7004 | __proto.prepend = function (element) {
|
7005 | return this.insert(0, element);
|
7006 | };
|
7007 | |
7008 |
|
7009 |
|
7010 |
|
7011 |
|
7012 |
|
7013 |
|
7014 |
|
7015 |
|
7016 |
|
7017 |
|
7018 |
|
7019 |
|
7020 |
|
7021 |
|
7022 |
|
7023 |
|
7024 |
|
7025 |
|
7026 |
|
7027 |
|
7028 |
|
7029 | __proto.insert = function (index, element) {
|
7030 | if (this._renderExternal) {
|
7031 | throw new FlickingError(MESSAGE.NOT_ALLOWED_IN_FRAMEWORK, CODE.NOT_ALLOWED_IN_FRAMEWORK);
|
7032 | }
|
7033 |
|
7034 | return this._renderer.batchInsert({
|
7035 | index: index,
|
7036 | elements: parseElement(element)
|
7037 | });
|
7038 | };
|
7039 | |
7040 |
|
7041 |
|
7042 |
|
7043 |
|
7044 |
|
7045 |
|
7046 |
|
7047 |
|
7048 |
|
7049 |
|
7050 | __proto.remove = function (index, deleteCount) {
|
7051 | if (deleteCount === void 0) {
|
7052 | deleteCount = 1;
|
7053 | }
|
7054 |
|
7055 | if (this._renderExternal) {
|
7056 | throw new FlickingError(MESSAGE.NOT_ALLOWED_IN_FRAMEWORK, CODE.NOT_ALLOWED_IN_FRAMEWORK);
|
7057 | }
|
7058 |
|
7059 | return this._renderer.batchRemove({
|
7060 | index: index,
|
7061 | deleteCount: deleteCount
|
7062 | });
|
7063 | };
|
7064 |
|
7065 | __proto._createControl = function () {
|
7066 | var _a;
|
7067 |
|
7068 | var moveType = this._moveType;
|
7069 | var moveTypes = Object.keys(MOVE_TYPE).map(function (key) {
|
7070 | return MOVE_TYPE[key];
|
7071 | });
|
7072 | var moveTypeStr = Array.isArray(moveType) ? moveType[0] : moveType;
|
7073 | var moveTypeOptions = Array.isArray(moveType) ? (_a = moveType[1]) !== null && _a !== void 0 ? _a : {} : {};
|
7074 |
|
7075 | if (!includes(moveTypes, moveTypeStr)) {
|
7076 | throw new FlickingError(MESSAGE.WRONG_OPTION("moveType", JSON.stringify(moveType)), CODE.WRONG_OPTION);
|
7077 | }
|
7078 |
|
7079 | switch (moveTypeStr) {
|
7080 | case MOVE_TYPE.SNAP:
|
7081 | return new SnapControl(moveTypeOptions);
|
7082 |
|
7083 | case MOVE_TYPE.FREE_SCROLL:
|
7084 | return new FreeControl(moveTypeOptions);
|
7085 |
|
7086 | case MOVE_TYPE.STRICT:
|
7087 | return new StrictControl(moveTypeOptions);
|
7088 | }
|
7089 | };
|
7090 |
|
7091 | __proto._createCamera = function () {
|
7092 | var cameraOption = {
|
7093 | align: this._align
|
7094 | };
|
7095 |
|
7096 | if (this._circular) {
|
7097 | if (this._bound) {
|
7098 |
|
7099 | console.warn("\"circular\" and \"bound\" option cannot be used together, ignoring bound.");
|
7100 | }
|
7101 |
|
7102 | return new CircularCamera(cameraOption);
|
7103 | } else if (this._bound) {
|
7104 | return new BoundCamera(cameraOption);
|
7105 | } else {
|
7106 | return new LinearCamera(cameraOption);
|
7107 | }
|
7108 | };
|
7109 |
|
7110 | __proto._createRenderer = function () {
|
7111 | var rendererOptions = {
|
7112 | align: this._align
|
7113 | };
|
7114 | var renderExternal = this._renderExternal;
|
7115 | return renderExternal ? new renderExternal.renderer(__assign(__assign({}, rendererOptions), renderExternal.rendererOptions)) : new VanillaRenderer(rendererOptions);
|
7116 | };
|
7117 |
|
7118 | __proto._moveToInitialPanel = function () {
|
7119 | return __awaiter(this, void 0, void 0, function () {
|
7120 | var renderer, control, initialPanel;
|
7121 | return __generator(this, function (_a) {
|
7122 | renderer = this._renderer;
|
7123 | control = this._control;
|
7124 | initialPanel = renderer.getPanel(this._defaultIndex) || renderer.getPanel(0);
|
7125 | if (!initialPanel) return [2
|
7126 |
|
7127 | ];
|
7128 | control.setActive(initialPanel, null, false);
|
7129 | return [2
|
7130 |
|
7131 | , control.moveToPanel(initialPanel, {
|
7132 | duration: 0
|
7133 | })];
|
7134 | });
|
7135 | });
|
7136 | };
|
7137 | |
7138 |
|
7139 |
|
7140 |
|
7141 |
|
7142 |
|
7143 |
|
7144 |
|
7145 |
|
7146 |
|
7147 |
|
7148 |
|
7149 | Flicking.VERSION = "4.3.0";
|
7150 | return Flicking;
|
7151 | }(Component);
|
7152 |
|
7153 |
|
7154 |
|
7155 |
|
7156 |
|
7157 |
|
7158 | var ExternalPanel = function (_super) {
|
7159 | __extends(ExternalPanel, _super);
|
7160 | |
7161 |
|
7162 |
|
7163 |
|
7164 |
|
7165 |
|
7166 |
|
7167 |
|
7168 |
|
7169 | function ExternalPanel(options) {
|
7170 | var _this = _super.call(this, options) || this;
|
7171 |
|
7172 | _this._externalComponent = options.externalComponent;
|
7173 | return _this;
|
7174 | }
|
7175 |
|
7176 | return ExternalPanel;
|
7177 | }(Panel);
|
7178 |
|
7179 |
|
7180 |
|
7181 |
|
7182 |
|
7183 |
|
7184 |
|
7185 |
|
7186 |
|
7187 |
|
7188 |
|
7189 |
|
7190 |
|
7191 |
|
7192 |
|
7193 |
|
7194 |
|
7195 | var withFlickingMethods = function (prototype, flickingName) {
|
7196 | [Component.prototype, Flicking.prototype].forEach(function (proto) {
|
7197 | Object.getOwnPropertyNames(proto).filter(function (name) {
|
7198 | return !prototype[name] && !name.startsWith("_") && name !== "constructor";
|
7199 | }).forEach(function (name) {
|
7200 | var descriptor = Object.getOwnPropertyDescriptor(proto, name);
|
7201 |
|
7202 | if (descriptor.value) {
|
7203 |
|
7204 | Object.defineProperty(prototype, name, {
|
7205 | value: function () {
|
7206 | var _a;
|
7207 |
|
7208 | var args = [];
|
7209 |
|
7210 | for (var _i = 0; _i < arguments.length; _i++) {
|
7211 | args[_i] = arguments[_i];
|
7212 | }
|
7213 |
|
7214 | return (_a = descriptor.value).call.apply(_a, __spreadArray([this[flickingName]], __read(args)));
|
7215 | }
|
7216 | });
|
7217 | } else {
|
7218 | var getterDescriptor = {};
|
7219 |
|
7220 | if (descriptor.get) {
|
7221 | getterDescriptor.get = function () {
|
7222 | var _a;
|
7223 |
|
7224 | return (_a = descriptor.get) === null || _a === void 0 ? void 0 : _a.call(this[flickingName]);
|
7225 | };
|
7226 | }
|
7227 |
|
7228 | if (descriptor.set) {
|
7229 | getterDescriptor.set = function () {
|
7230 | var _a;
|
7231 |
|
7232 | var args = [];
|
7233 |
|
7234 | for (var _i = 0; _i < arguments.length; _i++) {
|
7235 | args[_i] = arguments[_i];
|
7236 | }
|
7237 |
|
7238 | return (_a = descriptor.set) === null || _a === void 0 ? void 0 : _a.call.apply(_a, __spreadArray([this[flickingName]], __read(args)));
|
7239 | };
|
7240 | }
|
7241 |
|
7242 | Object.defineProperty(prototype, name, getterDescriptor);
|
7243 | }
|
7244 | });
|
7245 | });
|
7246 | };
|
7247 |
|
7248 | var sync = (function (flicking, diffResult, rendered) {
|
7249 | var renderer = flicking.renderer;
|
7250 | var panels = renderer.panels;
|
7251 |
|
7252 | if (diffResult.removed.length > 0) {
|
7253 | var endIdx_1 = -1;
|
7254 | var prevIdx_1 = -1;
|
7255 | diffResult.removed.forEach(function (removedIdx) {
|
7256 | if (endIdx_1 < 0) {
|
7257 | endIdx_1 = removedIdx;
|
7258 | }
|
7259 |
|
7260 | if (prevIdx_1 >= 0 && removedIdx !== prevIdx_1 - 1) {
|
7261 | batchRemove(renderer, prevIdx_1, endIdx_1 + 1);
|
7262 | endIdx_1 = removedIdx;
|
7263 | prevIdx_1 = removedIdx;
|
7264 | } else {
|
7265 | prevIdx_1 = removedIdx;
|
7266 | }
|
7267 | });
|
7268 | batchRemove(renderer, prevIdx_1, endIdx_1 + 1);
|
7269 | }
|
7270 |
|
7271 | diffResult.ordered.forEach(function (_a) {
|
7272 | var _b = __read(_a, 2),
|
7273 | prevIdx = _b[0],
|
7274 | newIdx = _b[1];
|
7275 |
|
7276 | var prevPanel = panels[prevIdx];
|
7277 | var indexDiff = newIdx - prevIdx;
|
7278 |
|
7279 | if (indexDiff > 0) {
|
7280 | var middlePanels = panels.slice(prevIdx + 1, newIdx + 1);
|
7281 | prevPanel.increaseIndex(indexDiff);
|
7282 | middlePanels.forEach(function (panel) {
|
7283 | return panel.decreaseIndex(1);
|
7284 | });
|
7285 | } else {
|
7286 | var middlePanels = panels.slice(newIdx, prevIdx);
|
7287 | prevPanel.decreaseIndex(-indexDiff);
|
7288 | middlePanels.forEach(function (panel) {
|
7289 | return panel.increaseIndex(1);
|
7290 | });
|
7291 | }
|
7292 |
|
7293 |
|
7294 | prevPanel.resize();
|
7295 | });
|
7296 |
|
7297 | if (diffResult.ordered.length > 0) {
|
7298 | panels.sort(function (panel1, panel2) {
|
7299 | return panel1.index - panel2.index;
|
7300 | });
|
7301 | }
|
7302 |
|
7303 | if (diffResult.added.length > 0) {
|
7304 | var startIdx_1 = -1;
|
7305 | var prevIdx_2 = -1;
|
7306 | diffResult.added.forEach(function (addedIdx, idx) {
|
7307 | if (startIdx_1 < 0) {
|
7308 | startIdx_1 = idx;
|
7309 | }
|
7310 |
|
7311 | if (prevIdx_2 >= 0 && addedIdx !== prevIdx_2 + 1) {
|
7312 | batchInsert(renderer, diffResult, rendered, startIdx_1, idx + 1);
|
7313 | startIdx_1 = -1;
|
7314 | prevIdx_2 = -1;
|
7315 | } else {
|
7316 | prevIdx_2 = addedIdx;
|
7317 | }
|
7318 | });
|
7319 |
|
7320 | if (startIdx_1 >= 0) {
|
7321 | batchInsert(renderer, diffResult, rendered, startIdx_1);
|
7322 | }
|
7323 | }
|
7324 | });
|
7325 |
|
7326 | var batchInsert = function (renderer, diffResult, rendered, startIdx, endIdx) {
|
7327 | renderer.batchInsert.apply(renderer, __spreadArray([], __read(diffResult.added.slice(startIdx, endIdx).map(function (index, elIdx) {
|
7328 | return {
|
7329 | index: index,
|
7330 | elements: [rendered[elIdx + diffResult.prevList.length]]
|
7331 | };
|
7332 | }))));
|
7333 | };
|
7334 |
|
7335 | var batchRemove = function (renderer, startIdx, endIdx) {
|
7336 | var removed = renderer.panels.slice(startIdx, endIdx);
|
7337 | renderer.batchRemove({
|
7338 | index: startIdx,
|
7339 | deleteCount: removed.length
|
7340 | });
|
7341 | };
|
7342 |
|
7343 | var getRenderingPanels = (function (flicking, diffResult) {
|
7344 | var removedPanels = diffResult.removed.reduce(function (map, idx) {
|
7345 | map[idx] = true;
|
7346 | return map;
|
7347 | }, {});
|
7348 | var maintainedMap = diffResult.maintained.reduce(function (map, _a) {
|
7349 | var _b = __read(_a, 2),
|
7350 | prev = _b[0],
|
7351 | current = _b[1];
|
7352 |
|
7353 | map[prev] = current;
|
7354 | return map;
|
7355 | }, {});
|
7356 | return __spreadArray(__spreadArray([], __read(flicking.panels.filter(function (panel) {
|
7357 | return !removedPanels[panel.index];
|
7358 | })
|
7359 | .sort(function (panel1, panel2) {
|
7360 | return panel1.position + panel1.offset - (panel2.position + panel2.offset);
|
7361 | }).map(function (panel) {
|
7362 | return diffResult.list[maintainedMap[panel.index]];
|
7363 | }))), __read(diffResult.added.map(function (idx) {
|
7364 | return diffResult.list[idx];
|
7365 | })));
|
7366 | });
|
7367 |
|
7368 | var getDefaultCameraTransform = (function (align, horizontal, firstPanelSize) {
|
7369 | if (align === void 0) {
|
7370 | align = ALIGN.CENTER;
|
7371 | }
|
7372 |
|
7373 | if (horizontal === void 0) {
|
7374 | horizontal = true;
|
7375 | }
|
7376 |
|
7377 | var cameraAlign = getCameraAlign(align);
|
7378 | var panelAlign = getPanelAlign(align);
|
7379 | if (panelAlign == null) return "";
|
7380 | var camPosition = "calc(" + cameraAlign + " - (" + (firstPanelSize || "0px") + " * " + panelAlign.percentage + ") - " + panelAlign.absolute + "px)";
|
7381 | return horizontal ? "translate(" + camPosition + ")" : "translate(0, " + camPosition + ")";
|
7382 | });
|
7383 |
|
7384 | var getCameraAlign = function (align) {
|
7385 | var alignVal = typeof align === "object" ? align.camera : align;
|
7386 | return parseAlign(alignVal);
|
7387 | };
|
7388 |
|
7389 | var getPanelAlign = function (align) {
|
7390 | var alignVal = typeof align === "object" ? align.panel : align;
|
7391 | return parseArithmeticExpression(parseAlign(alignVal));
|
7392 | };
|
7393 |
|
7394 | var parseAlign = function (alignVal) {
|
7395 | if (typeof alignVal === "number") {
|
7396 | return alignVal + "px";
|
7397 | }
|
7398 |
|
7399 | switch (alignVal) {
|
7400 | case ALIGN.CENTER:
|
7401 | return "50%";
|
7402 |
|
7403 | case ALIGN.NEXT:
|
7404 | return "100%";
|
7405 |
|
7406 | case ALIGN.PREV:
|
7407 | return "0%";
|
7408 |
|
7409 | default:
|
7410 | return alignVal;
|
7411 | }
|
7412 | };
|
7413 |
|
7414 |
|
7415 |
|
7416 |
|
7417 |
|
7418 |
|
7419 | export { ALIGN, AnchorPoint, AnimatingState, AxesController, BoundCamera, Camera, CircularCamera, Control, DIRECTION, DisabledState, DraggingState, CODE as ERROR_CODE, EVENTS, ElementPanel, ExternalPanel, ExternalRenderer, FlickingError, FreeControl, HoldingState, IdleState, LinearCamera, MOVE_TYPE, Panel, Renderer, SnapControl, State, StateMachine, StrictControl, VanillaRenderer, Viewport, Flicking as default, getDefaultCameraTransform, getRenderingPanels, sync, withFlickingMethods };
|
7420 |
|