@egjs/flicking-plugins 4.7.0 → 4.8.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,19 @@
1
- import Flicking from "@egjs/flicking";
2
- import Pagination from "../Pagination";
3
- export interface RendererOptions {
4
- flicking: Flicking;
5
- pagination: Pagination;
6
- wrapper: HTMLElement;
7
- }
8
- declare abstract class Renderer {
9
- protected _flicking: Flicking;
10
- protected _pagination: Pagination;
11
- protected _wrapper: HTMLElement;
12
- constructor({ flicking, pagination, wrapper }: RendererOptions);
13
- abstract destroy(): void;
14
- abstract render(): void;
15
- abstract update(index: number): void;
16
- protected _createBulletFromString(html: string, index: number): HTMLElement;
17
- protected _addBulletEvents(bullet: HTMLElement, index: number): void;
18
- }
19
- export default Renderer;
1
+ import Flicking from "@egjs/flicking";
2
+ import Pagination from "../Pagination";
3
+ export interface RendererOptions {
4
+ flicking: Flicking;
5
+ pagination: Pagination;
6
+ wrapper: HTMLElement;
7
+ }
8
+ declare abstract class Renderer {
9
+ protected _flicking: Flicking;
10
+ protected _pagination: Pagination;
11
+ protected _wrapper: HTMLElement;
12
+ constructor({ flicking, pagination, wrapper }: RendererOptions);
13
+ abstract destroy(): void;
14
+ abstract render(): void;
15
+ abstract update(index: number): void;
16
+ protected _createBulletFromString(html: string, index: number): HTMLElement;
17
+ protected _addBulletEvents(bullet: HTMLElement, index: number): void;
18
+ }
19
+ export default Renderer;
@@ -1,12 +1,12 @@
1
- import Renderer from "./Renderer";
2
- declare class ScrollBulletRenderer extends Renderer {
3
- private _bullets;
4
- private _bulletSize;
5
- private _previousIndex;
6
- private _sliderIndex;
7
- destroy(): void;
8
- render(): void;
9
- update(index: number): void;
10
- moveTo: (index: number) => void;
11
- }
12
- export default ScrollBulletRenderer;
1
+ import Renderer from "./Renderer";
2
+ declare class ScrollBulletRenderer extends Renderer {
3
+ private _bullets;
4
+ private _bulletSize;
5
+ private _previousIndex;
6
+ private _sliderIndex;
7
+ destroy(): void;
8
+ render(): void;
9
+ update(index: number): void;
10
+ moveTo: (index: number) => void;
11
+ }
12
+ export default ScrollBulletRenderer;
@@ -1,9 +1,9 @@
1
- interface ScrollContext {
2
- total: number;
3
- prevIndex: number;
4
- sliderIndex: number;
5
- direction: "NEXT" | "PREV";
6
- bullets: HTMLElement[];
7
- moveTo: (index: number) => void;
8
- }
9
- export default ScrollContext;
1
+ interface ScrollContext {
2
+ total: number;
3
+ prevIndex: number;
4
+ sliderIndex: number;
5
+ direction: "NEXT" | "PREV";
6
+ bullets: HTMLElement[];
7
+ moveTo: (index: number) => void;
8
+ }
9
+ export default ScrollContext;
@@ -1,3 +1,3 @@
1
- export declare const addClass: (el: HTMLElement, className: string) => void;
2
- export declare const removeClass: (el: HTMLElement, className: string) => void;
3
- export declare const getElement: (selector: string, parent: HTMLElement, pluginName: string) => HTMLElement;
1
+ export declare const addClass: (el: HTMLElement, className: string) => void;
2
+ export declare const removeClass: (el: HTMLElement, className: string) => void;
3
+ export declare const getElement: (selector: string, parent: HTMLElement, pluginName: string) => HTMLElement;
@@ -4,26 +4,26 @@ name: @egjs/flicking-plugins
4
4
  license: MIT
5
5
  author: NAVER Corp.
6
6
  repository: https://github.com/naver/egjs-flicking-plugins
7
- version: 4.7.0
7
+ version: 4.8.0-beta.0
8
8
  */
9
- import { EVENTS, DIRECTION, FlickingError, clamp } from '@egjs/flicking';
9
+ import { EVENTS, MOVE_TYPE, DIRECTION, FlickingError, clamp } from '@egjs/flicking';
10
10
 
11
- /**
12
- * You can apply parallax effect while panel is moving.
13
- * @ko 패널들을 움직이면서 parallax 효과를 부여할 수 있습니다.
14
- * @memberof Flicking.Plugins
11
+ /**
12
+ * You can apply parallax effect while panel is moving.
13
+ * @ko 패널들을 움직이면서 parallax 효과를 부여할 수 있습니다.
14
+ * @memberof Flicking.Plugins
15
15
  */
16
16
 
17
17
  var Parallax =
18
18
  /*#__PURE__*/
19
19
  function () {
20
- /**
21
- * @param {string} selector Selector of the element to apply parallax effect<ko> Parallax 효과를 적용할 엘리먼트의 선택자 </ko>
22
- * @param {number} scale Effect amplication scale<ko>효과 증폭도</ko>
23
- * @example
24
- * ```ts
25
- * flicking.addPlugins(new Parallax("img", 1));
26
- * ```
20
+ /**
21
+ * @param {string} selector Selector of the element to apply parallax effect<ko> Parallax 효과를 적용할 엘리먼트의 선택자 </ko>
22
+ * @param {number} scale Effect amplication scale<ko>효과 증폭도</ko>
23
+ * @example
24
+ * ```ts
25
+ * flicking.addPlugins(new Parallax("img", 1));
26
+ * ```
27
27
  */
28
28
  function Parallax(selector, scale) {
29
29
  var _this = this;
@@ -110,22 +110,22 @@ function () {
110
110
  return Parallax;
111
111
  }();
112
112
 
113
- /**
114
- * You can apply fade in / out effect while panel is moving.
115
- * @ko 패널들을 움직이면서 fade in / out 효과를 부여할 수 있습니다.
116
- * @memberof Flicking.Plugins
113
+ /**
114
+ * You can apply fade in / out effect while panel is moving.
115
+ * @ko 패널들을 움직이면서 fade in / out 효과를 부여할 수 있습니다.
116
+ * @memberof Flicking.Plugins
117
117
  */
118
118
 
119
119
  var Fade =
120
120
  /*#__PURE__*/
121
121
  function () {
122
- /**
123
- * @param - The selector of the element to which the fade effect is to be applied. If the selector is blank, it applies to panel element. <ko>Fade 효과를 적용할 대상의 선택자. 선택자가 공백이면 패널 엘리먼트에 적용된다.</ko>
124
- * @param - Effect amplication scale<ko>효과 증폭도</ko>
125
- * @example
126
- * ```ts
127
- * flicking.addPlugins(new Fade("p", 1));
128
- * ```
122
+ /**
123
+ * @param - The selector of the element to which the fade effect is to be applied. If the selector is blank, it applies to panel element. <ko>Fade 효과를 적용할 대상의 선택자. 선택자가 공백이면 패널 엘리먼트에 적용된다.</ko>
124
+ * @param - Effect amplication scale<ko>효과 증폭도</ko>
125
+ * @example
126
+ * ```ts
127
+ * flicking.addPlugins(new Fade("p", 1));
128
+ * ```
129
129
  */
130
130
  function Fade(selector, scale) {
131
131
  var _this = this;
@@ -212,26 +212,26 @@ function () {
212
212
  return Fade;
213
213
  }();
214
214
 
215
- /**
216
- * Plugin that allow you to automatically move to the next/previous panel, on a specific time basis
217
- * @ko 일정 시간마다, 자동으로 다음/이전 패널로 넘어가도록 할 수 있는 플러그인
218
- * @memberof Flicking.Plugins
215
+ /**
216
+ * Plugin that allow you to automatically move to the next/previous panel, on a specific time basis
217
+ * @ko 일정 시간마다, 자동으로 다음/이전 패널로 넘어가도록 할 수 있는 플러그인
218
+ * @memberof Flicking.Plugins
219
219
  */
220
220
 
221
221
  var AutoPlay =
222
222
  /*#__PURE__*/
223
223
  function () {
224
- /**
225
- * @param {AutoPlayOptions} options Options for the AutoPlay instance.<ko>AutoPlay 옵션</ko>
226
- * @param {number} options.duration Time to wait before moving on to the next panel.<ko>다음 패널로 움직이기까지 대기 시간</ko>
227
- * @param {number | undefined} options.animationDuration Duration of animation of moving to the next panel. If undefined, duration option of the Flicking instance is used instead.<ko>패널이 움직이는 애니메이션의 지속 시간, undefined라면 Flicking 인스턴스의 duration 값을 사용한다</ko>
228
- * @param {"PREV" | "NEXT"} options.direction The direction in which the panel moves.<ko>패널이 움직이는 방향</ko>
229
- * @param {boolean} options.stopOnHover Whether to stop when mouse hover upon the element.<ko>엘리먼트에 마우스를 올렸을 때 AutoPlay를 정지할지 여부</ko>
230
- * @param {number} options.delayAfterHover If stopOnHover is true, the amount of time to wait before moving on to the next panel when mouse leaves the element.<ko>stopOnHover를 사용한다면 마우스가 엘리먼트로부터 나간 뒤 다음 패널로 움직이기까지 대기 시간</ko>
231
- * @example
232
- * ```ts
233
- * flicking.addPlugins(new AutoPlay({ duration: 2000, direction: "NEXT" }));
234
- * ```
224
+ /**
225
+ * @param {AutoPlayOptions} options Options for the AutoPlay instance.<ko>AutoPlay 옵션</ko>
226
+ * @param {number} options.duration Time to wait before moving on to the next panel.<ko>다음 패널로 움직이기까지 대기 시간</ko>
227
+ * @param {number | undefined} options.animationDuration Duration of animation of moving to the next panel. If undefined, duration option of the Flicking instance is used instead.<ko>패널이 움직이는 애니메이션의 지속 시간, undefined라면 Flicking 인스턴스의 duration 값을 사용한다</ko>
228
+ * @param {"PREV" | "NEXT"} options.direction The direction in which the panel moves.<ko>패널이 움직이는 방향</ko>
229
+ * @param {boolean} options.stopOnHover Whether to stop when mouse hover upon the element.<ko>엘리먼트에 마우스를 올렸을 때 AutoPlay를 정지할지 여부</ko>
230
+ * @param {number} options.delayAfterHover If stopOnHover is true, the amount of time to wait before moving on to the next panel when mouse leaves the element.<ko>stopOnHover를 사용한다면 마우스가 엘리먼트로부터 나간 뒤 다음 패널로 움직이기까지 대기 시간</ko>
231
+ * @example
232
+ * ```ts
233
+ * flicking.addPlugins(new AutoPlay({ duration: 2000, direction: "NEXT" }));
234
+ * ```
235
235
  */
236
236
  function AutoPlay(_a) {
237
237
  var _this = this;
@@ -400,12 +400,61 @@ function () {
400
400
 
401
401
  this._playing = true;
402
402
  this._timerId = window.setTimeout(function () {
403
+ var _a, _b;
404
+
405
+ var animationDuration = _this._animationDuration || flicking.duration;
406
+ var moveType = flicking.moveType; // for freeScroll
407
+
408
+ if (moveType === MOVE_TYPE.FREE_SCROLL || (moveType === null || moveType === void 0 ? void 0 : moveType[0]) === MOVE_TYPE.FREE_SCROLL) {
409
+ var range = flicking.camera.range;
410
+ var cameraPosition = flicking.camera.position;
411
+ var currentPanel = flicking.currentPanel;
412
+ var prevPanel = currentPanel.prev();
413
+ var nextPanel = currentPanel.next();
414
+ var currentPosition = currentPanel.position;
415
+ var nextPosition = (_a = nextPanel === null || nextPanel === void 0 ? void 0 : nextPanel.position) !== null && _a !== void 0 ? _a : range.max;
416
+ var prevPosition = (_b = prevPanel === null || prevPanel === void 0 ? void 0 : prevPanel.position) !== null && _b !== void 0 ? _b : range.min; // circular: prev (last) > cur (0) => prev(-1) < cur(0)
417
+
418
+ if (prevPosition > currentPosition) {
419
+ prevPosition = range.min - (range.max - prevPosition);
420
+ } // current (last) > next (0)
421
+
422
+
423
+ if (nextPosition < currentPosition) {
424
+ nextPosition += range.max;
425
+ }
426
+
427
+ if (direction === DIRECTION.NEXT) {
428
+ // prev - cur - camera - next
429
+ var size = nextPosition - currentPosition;
430
+ var restSize = nextPosition - cameraPosition;
431
+
432
+ if (cameraPosition < currentPosition) {
433
+ // prev - camera - cur - next
434
+ restSize = nextPosition - cameraPosition;
435
+ }
436
+
437
+ animationDuration *= restSize / size;
438
+ } else {
439
+ // prev - caemra - cur - next
440
+ var size = currentPosition - prevPosition;
441
+ var restSize = cameraPosition - prevPosition;
442
+
443
+ if (cameraPosition > currentPosition) {
444
+ // prev - cur - camera - next
445
+ restSize = cameraPosition - prevPosition;
446
+ }
447
+
448
+ animationDuration *= restSize / size;
449
+ }
450
+ }
451
+
403
452
  if (direction === DIRECTION.NEXT) {
404
- flicking.next(_this._animationDuration).catch(function () {
453
+ flicking.next(animationDuration).catch(function () {
405
454
  return void 0;
406
455
  });
407
456
  } else {
408
- flicking.prev(_this._animationDuration).catch(function () {
457
+ flicking.prev(animationDuration).catch(function () {
409
458
  return void 0;
410
459
  });
411
460
  }
@@ -488,10 +537,10 @@ var getElement = function (selector, parent, pluginName) {
488
537
  return el;
489
538
  };
490
539
 
491
- /**
492
- * A plugin to easily create prev/right arrow button of Flicking
493
- * @ko 이전/다음 버튼을 쉽게 만들 수 있는 플러그인
494
- * @memberof Flicking.Plugins
540
+ /**
541
+ * A plugin to easily create prev/right arrow button of Flicking
542
+ * @ko 이전/다음 버튼을 쉽게 만들 수 있는 플러그인
543
+ * @memberof Flicking.Plugins
495
544
  */
496
545
 
497
546
  var Arrow =
@@ -512,7 +561,9 @@ function () {
512
561
  _g = _b.moveCount,
513
562
  moveCount = _g === void 0 ? 1 : _g,
514
563
  _h = _b.moveByViewportSize,
515
- moveByViewportSize = _h === void 0 ? false : _h;
564
+ moveByViewportSize = _h === void 0 ? false : _h,
565
+ _j = _b.interruptable,
566
+ interruptable = _j === void 0 ? false : _j;
516
567
  /* Internal Values */
517
568
 
518
569
 
@@ -524,9 +575,16 @@ function () {
524
575
 
525
576
  this._onPrevClick = function () {
526
577
  var flicking = _this._flicking;
578
+ var index = flicking.animating ? _this._nextIndex : flicking.index;
579
+ var currentPanel = flicking.animating ? flicking.panels[_this._nextIndex] : flicking.currentPanel;
527
580
  var camera = flicking.camera;
528
581
  var anchorPoints = camera.anchorPoints;
529
- if (flicking.animating || anchorPoints.length <= 0) return;
582
+ if (flicking.animating && !_this.interruptable || anchorPoints.length <= 0) return;
583
+
584
+ if (flicking.animating) {
585
+ flicking.stopAnimation();
586
+ }
587
+
530
588
  var firstAnchor = anchorPoints[0];
531
589
  var moveCount = _this._moveCount;
532
590
 
@@ -534,26 +592,33 @@ function () {
534
592
  flicking.control.moveToPosition(camera.position - camera.size, flicking.duration).catch(_this._onCatch);
535
593
  } else {
536
594
  if (flicking.circularEnabled) {
537
- var targetPanel = flicking.currentPanel;
595
+ var targetPanel = currentPanel;
538
596
 
539
597
  for (var i = 0; i < moveCount; i++) {
540
598
  targetPanel = targetPanel.prev();
541
599
  }
542
600
 
543
601
  targetPanel.focus().catch(_this._onCatch);
544
- } else if (flicking.index > firstAnchor.panel.index) {
545
- flicking.moveTo(Math.max(flicking.index - moveCount, firstAnchor.panel.index)).catch(_this._onCatch);
602
+ } else if (index > firstAnchor.panel.index) {
603
+ flicking.moveTo(Math.max(index - moveCount, firstAnchor.panel.index)).catch(_this._onCatch);
546
604
  } else if (camera.position > camera.range.min) {
547
- flicking.moveTo(flicking.index).catch(_this._onCatch);
605
+ flicking.moveTo(index).catch(_this._onCatch);
548
606
  }
549
607
  }
550
608
  };
551
609
 
552
610
  this._onNextClick = function () {
553
611
  var flicking = _this._flicking;
612
+ var index = flicking.animating ? _this._nextIndex : flicking.index;
613
+ var currentPanel = flicking.animating ? flicking.panels[_this._nextIndex] : flicking.currentPanel;
554
614
  var camera = flicking.camera;
555
615
  var anchorPoints = camera.anchorPoints;
556
- if (flicking.animating || anchorPoints.length <= 0) return;
616
+ if (flicking.animating && !_this.interruptable || anchorPoints.length <= 0) return;
617
+
618
+ if (flicking.animating) {
619
+ flicking.stopAnimation();
620
+ }
621
+
557
622
  var lastAnchor = anchorPoints[anchorPoints.length - 1];
558
623
  var moveCount = _this._moveCount;
559
624
 
@@ -561,17 +626,17 @@ function () {
561
626
  flicking.control.moveToPosition(camera.position + camera.size, flicking.duration).catch(_this._onCatch);
562
627
  } else {
563
628
  if (flicking.circularEnabled) {
564
- var targetPanel = flicking.currentPanel;
629
+ var targetPanel = currentPanel;
565
630
 
566
631
  for (var i = 0; i < moveCount; i++) {
567
632
  targetPanel = targetPanel.next();
568
633
  }
569
634
 
570
635
  targetPanel.focus().catch(_this._onCatch);
571
- } else if (flicking.index < lastAnchor.panel.index) {
572
- flicking.moveTo(Math.min(flicking.index + moveCount, lastAnchor.panel.index)).catch(_this._onCatch);
636
+ } else if (index < lastAnchor.panel.index) {
637
+ flicking.moveTo(Math.min(index + moveCount, lastAnchor.panel.index)).catch(_this._onCatch);
573
638
  } else if (camera.position > camera.range.min) {
574
- flicking.moveTo(flicking.index).catch(_this._onCatch);
639
+ flicking.moveTo(index).catch(_this._onCatch);
575
640
  }
576
641
  }
577
642
  };
@@ -588,6 +653,10 @@ function () {
588
653
  }
589
654
  };
590
655
 
656
+ this._onWillChange = function (e) {
657
+ _this._nextIndex = e.index;
658
+ };
659
+
591
660
  this._onCatch = function (err) {
592
661
  if (err instanceof FlickingError) return;
593
662
  throw err;
@@ -599,6 +668,7 @@ function () {
599
668
  this._disabledClass = disabledClass;
600
669
  this._moveCount = moveCount;
601
670
  this._moveByViewportSize = moveByViewportSize;
671
+ this._interruptable = interruptable;
602
672
  }
603
673
 
604
674
  var __proto = Arrow.prototype;
@@ -676,6 +746,16 @@ function () {
676
746
  enumerable: false,
677
747
  configurable: true
678
748
  });
749
+ Object.defineProperty(__proto, "interruptable", {
750
+ get: function () {
751
+ return this._interruptable;
752
+ },
753
+ set: function (val) {
754
+ this._interruptable = val;
755
+ },
756
+ enumerable: false,
757
+ configurable: true
758
+ });
679
759
 
680
760
  __proto.init = function (flicking) {
681
761
  var _this = this;
@@ -686,6 +766,7 @@ function () {
686
766
 
687
767
  this._flicking = flicking;
688
768
  flicking.on(EVENTS.MOVE, this._onAnimation);
769
+ flicking.on(EVENTS.WILL_CHANGE, this._onWillChange);
689
770
  var parentEl = this._parentEl ? this._parentEl : flicking.element;
690
771
  var prevEl = getElement(this._prevElSelector, parentEl, "Arrow");
691
772
  var nextEl = getElement(this._nextElSelector, parentEl, "Arrow");
@@ -714,6 +795,7 @@ function () {
714
795
  }
715
796
 
716
797
  flicking.off(EVENTS.MOVE, this._onAnimation);
798
+ flicking.off(EVENTS.WILL_CHANGE, this._onWillChange);
717
799
  var prevEl = this._prevEl;
718
800
  var nextEl = this._nextEl;
719
801
  [BROWSER.MOUSE_DOWN, BROWSER.TOUCH_START].forEach(function (evt) {
@@ -754,10 +836,10 @@ function () {
754
836
  return Arrow;
755
837
  }();
756
838
 
757
- /**
758
- * Plugin for synchronizing multiple flickings
759
- * @ko 다양한 형태로 Flicking들이 같이 움직이게 할 수 있습니다.
760
- * @memberof Flicking.Plugins
839
+ /**
840
+ * Plugin for synchronizing multiple flickings
841
+ * @ko 다양한 형태로 Flicking들이 같이 움직이게 할 수 있습니다.
842
+ * @memberof Flicking.Plugins
761
843
  */
762
844
 
763
845
  var Sync =
@@ -1004,24 +1086,24 @@ function () {
1004
1086
  }();
1005
1087
 
1006
1088
  /* eslint-disable no-underscore-dangle */
1007
- /**
1008
- * You can apply perspective effect while panel is moving.
1009
- * @ko 패널들을 움직이면서 입체감을 부여할 수 있습니다.
1010
- * @memberof Flicking.Plugins
1089
+ /**
1090
+ * You can apply perspective effect while panel is moving.
1091
+ * @ko 패널들을 움직이면서 입체감을 부여할 수 있습니다.
1092
+ * @memberof Flicking.Plugins
1011
1093
  */
1012
1094
 
1013
1095
  var Perspective =
1014
1096
  /*#__PURE__*/
1015
1097
  function () {
1016
- /**
1017
- * @param - The selector of the element to which the perspective effect is to be applied. If the selector is blank, it applies to panel element. <ko>입체 효과를 적용할 대상의 선택자. 선택자가 공백이면 패널 엘리먼트에 적용된다.</ko>
1018
- * @param - Effect amplication scale.<ko>효과 증폭도</ko>
1019
- * @param - Effect amplication rotate.<ko>회전 증폭도</ko>
1020
- * @param - The value of perspective CSS property. <ko>css perspective 속성 값</ko>
1021
- * @example
1022
- * ```ts
1023
- * flicking.addPlugins(new Perspective({ selector: "p", scale: 1, rotate: 1, perspective = 1000 }));
1024
- * ```
1098
+ /**
1099
+ * @param - The selector of the element to which the perspective effect is to be applied. If the selector is blank, it applies to panel element. <ko>입체 효과를 적용할 대상의 선택자. 선택자가 공백이면 패널 엘리먼트에 적용된다.</ko>
1100
+ * @param - Effect amplication scale.<ko>효과 증폭도</ko>
1101
+ * @param - Effect amplication rotate.<ko>회전 증폭도</ko>
1102
+ * @param - The value of perspective CSS property. <ko>css perspective 속성 값</ko>
1103
+ * @example
1104
+ * ```ts
1105
+ * flicking.addPlugins(new Perspective({ selector: "p", scale: 1, rotate: 1, perspective = 1000 }));
1106
+ * ```
1025
1107
  */
1026
1108
  function Perspective(_a) {
1027
1109
  var _this = this;
@@ -1558,8 +1640,8 @@ function (_super) {
1558
1640
  return ScrollBulletRenderer;
1559
1641
  }(Renderer);
1560
1642
 
1561
- /**
1562
- * @memberof Flicking.Plugins
1643
+ /**
1644
+ * @memberof Flicking.Plugins
1563
1645
  */
1564
1646
 
1565
1647
  var Pagination =
@@ -1819,8 +1901,8 @@ function () {
1819
1901
  return Pagination;
1820
1902
  }();
1821
1903
 
1822
- /**
1823
- * @namespace Flicking
1904
+ /**
1905
+ * @namespace Flicking
1824
1906
  */
1825
1907
 
1826
1908
  export { ARROW, Arrow, AutoPlay, Fade, PAGINATION, Pagination, Parallax, Perspective, SYNC, Sync };