@egjs/flicking-plugins 4.2.1 → 4.3.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.
@@ -0,0 +1,28 @@
1
+ import Flicking, { Plugin } from "@egjs/flicking";
2
+ interface PerspectiveOptions {
3
+ selector: string;
4
+ scale: number;
5
+ rotate: number;
6
+ perspective: number;
7
+ }
8
+ declare class Perspective implements Plugin {
9
+ private _flicking;
10
+ private _selector;
11
+ private _scale;
12
+ private _rotate;
13
+ private _perspective;
14
+ get selector(): string;
15
+ get scale(): number;
16
+ get rotate(): number;
17
+ get perspective(): number;
18
+ set selector(val: string);
19
+ set scale(val: number);
20
+ set rotate(val: number);
21
+ set perspective(val: number);
22
+ constructor({ selector, scale, rotate, perspective }?: Partial<PerspectiveOptions>);
23
+ init(flicking: Flicking): void;
24
+ destroy(): void;
25
+ update: () => void;
26
+ private _onMove;
27
+ }
28
+ export default Perspective;
@@ -1,9 +1,11 @@
1
- import Flicking, { Plugin } from "@egjs/flicking";
2
- interface SyncOptions {
3
- type: "camera" | "index";
1
+ import Flicking from "@egjs/flicking";
2
+ import type { Plugin } from "@egjs/flicking";
3
+ import { SYNC } from "./const";
4
+ export interface SyncOptions {
5
+ type: typeof SYNC.TYPE.CAMERA | typeof SYNC.TYPE.INDEX;
4
6
  synchronizedFlickingOptions: SychronizableFlickingOptions[];
5
7
  }
6
- interface SychronizableFlickingOptions {
8
+ export interface SychronizableFlickingOptions {
7
9
  flicking: Flicking;
8
10
  isClickable?: boolean;
9
11
  isSlidable?: boolean;
@@ -28,8 +30,8 @@ declare class Sync implements Plugin {
28
30
  private _onMove;
29
31
  private _onMoveStart;
30
32
  private _onMoveEnd;
33
+ private _onSelect;
31
34
  private _synchronizeByIndex;
32
35
  private _updateClass;
33
- private _findNearsetPanel;
34
36
  }
35
37
  export default Sync;
@@ -2,7 +2,9 @@ import Parallax from "./Parallax";
2
2
  import Fade from "./Fade";
3
3
  import AutoPlay from "./AutoPlay";
4
4
  import Arrow from "./Arrow";
5
- import Sync from "./Sync";
5
+ import Sync, { SyncOptions, SychronizableFlickingOptions } from "./Sync";
6
+ import Perspective from "./Perspective";
6
7
  export * from "./pagination";
7
- export { Parallax, Fade, AutoPlay, Arrow, Sync };
8
+ export { Parallax, Fade, AutoPlay, Arrow, Sync, Perspective };
9
+ export type { SyncOptions, SychronizableFlickingOptions };
8
10
  export * from "./const";
@@ -4,9 +4,9 @@ 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.2.1
7
+ version: 4.3.0
8
8
  */
9
- import { EVENTS, DIRECTION, FlickingError } from '@egjs/flicking';
9
+ import { EVENTS, DIRECTION, FlickingError, clamp } from '@egjs/flicking';
10
10
 
11
11
  /**
12
12
  * You can apply parallax effect while panel is moving.
@@ -102,6 +102,8 @@ function () {
102
102
 
103
103
  this._flicking.off(EVENTS.MOVE, this._onMove);
104
104
 
105
+ this._flicking.off(EVENTS.AFTER_RESIZE, this.update);
106
+
105
107
  this._flicking = null;
106
108
  };
107
109
 
@@ -199,6 +201,8 @@ function () {
199
201
 
200
202
  this._flicking.off(EVENTS.MOVE, this._onMove);
201
203
 
204
+ this._flicking.off(EVENTS.AFTER_RESIZE, this.update);
205
+
202
206
  this._flicking = null;
203
207
  };
204
208
 
@@ -406,6 +410,8 @@ var SYNC = {
406
410
  };
407
411
 
408
412
  var addClass = function (el, className) {
413
+ if (!el) return;
414
+
409
415
  if (el.classList) {
410
416
  el.classList.add(className);
411
417
  } else {
@@ -417,6 +423,8 @@ var addClass = function (el, className) {
417
423
  }
418
424
  };
419
425
  var removeClass = function (el, className) {
426
+ if (!el) return;
427
+
420
428
  if (el.classList) {
421
429
  el.classList.remove(className);
422
430
  } else {
@@ -636,8 +644,12 @@ function () {
636
644
  var prevEl = getElement(this._prevElSelector, parentEl, "Arrow");
637
645
  var nextEl = getElement(this._nextElSelector, parentEl, "Arrow");
638
646
  [BROWSER.MOUSE_DOWN, BROWSER.TOUCH_START].forEach(function (evt) {
639
- prevEl.addEventListener(evt, _this._preventInputPropagation);
640
- nextEl.addEventListener(evt, _this._preventInputPropagation);
647
+ prevEl.addEventListener(evt, _this._preventInputPropagation, {
648
+ passive: true
649
+ });
650
+ nextEl.addEventListener(evt, _this._preventInputPropagation, {
651
+ passive: true
652
+ });
641
653
  });
642
654
  prevEl.addEventListener(BROWSER.CLICK, this._onPrevClick);
643
655
  nextEl.addEventListener(BROWSER.CLICK, this._onNextClick);
@@ -719,46 +731,52 @@ function () {
719
731
 
720
732
  this._flicking = null;
721
733
 
722
- this._addEvents = function (synchronizedFlickingOptions) {
723
- synchronizedFlickingOptions.forEach(function (_a) {
734
+ this._addEvents = function () {
735
+ var type = _this._type;
736
+ var synced = _this._synchronizedFlickingOptions;
737
+ synced.forEach(function (_a) {
724
738
  var flicking = _a.flicking,
725
739
  isSlidable = _a.isSlidable,
726
740
  isClickable = _a.isClickable;
727
741
 
728
- if (_this._type === "camera") {
742
+ if (type === SYNC.TYPE.CAMERA) {
729
743
  flicking.on(EVENTS.MOVE, _this._onMove);
730
744
  flicking.on(EVENTS.MOVE_START, _this._onMoveStart);
731
745
  flicking.on(EVENTS.MOVE_END, _this._onMoveEnd);
732
746
  }
733
747
 
734
- if (_this._type === "index" && isSlidable) {
748
+ if (type === SYNC.TYPE.INDEX && isSlidable) {
735
749
  flicking.on(EVENTS.WILL_CHANGE, _this._onIndexChange);
750
+ flicking.on(EVENTS.WILL_RESTORE, _this._onIndexChange);
736
751
  }
737
752
 
738
753
  if (isClickable) {
739
- flicking.on(EVENTS.SELECT, _this._onIndexChange);
754
+ flicking.on(EVENTS.SELECT, _this._onSelect);
740
755
  }
741
756
  });
742
757
  };
743
758
 
744
- this._removeEvents = function (synchronizedFlickingOptions) {
745
- synchronizedFlickingOptions.forEach(function (_a) {
759
+ this._removeEvents = function () {
760
+ var type = _this._type;
761
+ var synced = _this._synchronizedFlickingOptions;
762
+ synced.forEach(function (_a) {
746
763
  var flicking = _a.flicking,
747
764
  isSlidable = _a.isSlidable,
748
765
  isClickable = _a.isClickable;
749
766
 
750
- if (_this._type === "camera") {
767
+ if (type === SYNC.TYPE.CAMERA) {
751
768
  flicking.off(EVENTS.MOVE, _this._onMove);
752
769
  flicking.off(EVENTS.MOVE_START, _this._onMoveStart);
753
770
  flicking.off(EVENTS.MOVE_END, _this._onMoveEnd);
754
771
  }
755
772
 
756
- if (_this._type === "index" && isSlidable) {
773
+ if (type === SYNC.TYPE.INDEX && isSlidable) {
757
774
  flicking.off(EVENTS.WILL_CHANGE, _this._onIndexChange);
775
+ flicking.off(EVENTS.WILL_RESTORE, _this._onIndexChange);
758
776
  }
759
777
 
760
778
  if (isClickable) {
761
- flicking.off(EVENTS.SELECT, _this._onIndexChange);
779
+ flicking.off(EVENTS.SELECT, _this._onSelect);
762
780
  }
763
781
  });
764
782
  };
@@ -779,16 +797,18 @@ function () {
779
797
 
780
798
  _this._synchronizedFlickingOptions.forEach(function (_a) {
781
799
  var flicking = _a.flicking;
800
+ if (flicking === e.currentTarget) return;
801
+ var targetPosition = 0;
782
802
 
783
- if (flicking !== e.currentTarget) {
784
- if (camera.position < camera.range.min) {
785
- void flicking.camera.lookAt(camera.position);
786
- } else if (camera.position > camera.range.max) {
787
- void flicking.camera.lookAt(flicking.camera.range.max + camera.position - camera.range.max);
788
- } else {
789
- void flicking.camera.lookAt(flicking.camera.range.min + flicking.camera.rangeDiff * progress);
790
- }
803
+ if (camera.position < camera.range.min) {
804
+ targetPosition = camera.position;
805
+ } else if (camera.position > camera.range.max) {
806
+ targetPosition = flicking.camera.range.max + camera.position - camera.range.max;
807
+ } else {
808
+ targetPosition = flicking.camera.range.min + flicking.camera.rangeDiff * progress;
791
809
  }
810
+
811
+ void flicking.camera.lookAt(targetPosition);
792
812
  });
793
813
  };
794
814
 
@@ -813,59 +833,53 @@ function () {
813
833
  });
814
834
  };
815
835
 
816
- this._synchronizeByIndex = function (activeFlicking, index) {
817
- var synchronizedFlickingOptions = _this._synchronizedFlickingOptions;
818
- var activePanel = activeFlicking.panels.find(function (panel) {
819
- return panel.index === index;
836
+ this._onSelect = function (e) {
837
+ void e.currentTarget.moveTo(e.index).catch(function () {
838
+ return void 0;
820
839
  });
821
- var lastPanel = activeFlicking.panels[activeFlicking.panels.length - 1];
822
840
 
823
- if (!activePanel) {
824
- return;
825
- }
826
-
827
- _this._preventEvent(function () {
828
- synchronizedFlickingOptions.forEach(function (_a) {
829
- var flicking = _a.flicking,
830
- activeClass = _a.activeClass; // calculate new target flicking position with active flicking size and target flicking size
841
+ _this._synchronizeByIndex(e.currentTarget, e.index);
842
+ };
831
843
 
832
- var targetLastPanel = flicking.panels[flicking.panels.length - 1];
833
- var targetPos = activePanel.position / (lastPanel.position + lastPanel.size / 2) * (targetLastPanel.position + targetLastPanel.size / 2);
834
- flicking.control.moveToPosition(targetPos, 500).catch(function () {
835
- return void 0;
836
- });
844
+ this._synchronizeByIndex = function (activeFlicking, index) {
845
+ var synchronizedFlickingOptions = _this._synchronizedFlickingOptions;
837
846
 
838
- if (activeClass) {
839
- _this._updateClass({
840
- flicking: flicking,
841
- activeClass: activeClass
842
- }, targetPos);
847
+ _this._preventEvent(function () {
848
+ synchronizedFlickingOptions.forEach(function (options) {
849
+ // Active class should be applied same to the Flicking which triggered event
850
+ _this._updateClass(options, index);
851
+
852
+ var flicking = options.flicking;
853
+ if (flicking === activeFlicking) return;
854
+ var targetIndex = clamp(index, 0, flicking.panels.length);
855
+
856
+ if (flicking.animating) {
857
+ // Reserve moveTo once previous animation is finished
858
+ flicking.once(EVENTS.MOVE_END, function () {
859
+ void flicking.moveTo(targetIndex).catch(function () {
860
+ return void 0;
861
+ });
862
+ });
863
+ } else {
864
+ void flicking.moveTo(targetIndex);
843
865
  }
844
866
  });
845
867
  });
846
868
  };
847
869
 
848
- this._updateClass = function (synchronizedFlickingOption, pos) {
849
- var target = _this._findNearsetPanel(synchronizedFlickingOption.flicking, pos);
850
-
851
- synchronizedFlickingOption.flicking.panels.forEach(function (panel) {
852
- return panel.index === target.index ? addClass(panel.element, synchronizedFlickingOption.activeClass) : removeClass(panel.element, synchronizedFlickingOption.activeClass);
870
+ this._updateClass = function (_a, index) {
871
+ var flicking = _a.flicking,
872
+ activeClass = _a.activeClass;
873
+ if (!activeClass) return;
874
+ flicking.panels.forEach(function (panel) {
875
+ if (panel.index === index) {
876
+ addClass(panel.element, activeClass);
877
+ } else {
878
+ removeClass(panel.element, activeClass);
879
+ }
853
880
  });
854
881
  };
855
882
 
856
- this._findNearsetPanel = function (flicking, pos) {
857
- var nearsetIndex = flicking.panels.reduce(function (nearest, panel, index) {
858
- return Math.abs(panel.position - pos) <= nearest.range ? {
859
- index: index,
860
- range: Math.abs(panel.position - pos)
861
- } : nearest;
862
- }, {
863
- index: 0,
864
- range: Infinity
865
- }).index;
866
- return flicking.panels[nearsetIndex];
867
- };
868
-
869
883
  this._type = type;
870
884
  this._synchronizedFlickingOptions = synchronizedFlickingOptions;
871
885
  }
@@ -876,11 +890,7 @@ function () {
876
890
  return this._type;
877
891
  },
878
892
  set: function (val) {
879
- var _this = this;
880
-
881
- this._preventEvent(function () {
882
- _this._type = val;
883
- });
893
+ this._type = val;
884
894
  },
885
895
  enumerable: false,
886
896
  configurable: true
@@ -890,11 +900,7 @@ function () {
890
900
  return this._synchronizedFlickingOptions;
891
901
  },
892
902
  set: function (val) {
893
- var _this = this;
894
-
895
- this._preventEvent(function () {
896
- _this._synchronizedFlickingOptions = val;
897
- });
903
+ this._synchronizedFlickingOptions = val;
898
904
  },
899
905
  enumerable: false,
900
906
  configurable: true
@@ -903,16 +909,20 @@ function () {
903
909
  __proto.init = function (flicking) {
904
910
  var _this = this;
905
911
 
912
+ var synced = this._synchronizedFlickingOptions;
913
+
906
914
  if (this._flicking) {
907
915
  this.destroy();
908
916
  }
909
917
 
910
918
  this._flicking = flicking;
911
919
 
912
- this._addEvents(this._synchronizedFlickingOptions);
920
+ this._addEvents();
921
+
922
+ synced.forEach(function (options) {
923
+ var syncedFlicking = options.flicking;
913
924
 
914
- this._synchronizedFlickingOptions.forEach(function (synchronizedFlickingOption) {
915
- _this._updateClass(synchronizedFlickingOption, 0);
925
+ _this._updateClass(options, syncedFlicking.defaultIndex);
916
926
  });
917
927
  };
918
928
 
@@ -923,7 +933,7 @@ function () {
923
933
  return;
924
934
  }
925
935
 
926
- this._removeEvents(this._synchronizedFlickingOptions);
936
+ this._removeEvents();
927
937
 
928
938
  this._flicking = null;
929
939
  };
@@ -931,28 +941,157 @@ function () {
931
941
  __proto.update = function () {
932
942
  var _this = this;
933
943
 
934
- this._synchronizedFlickingOptions.forEach(function (_a) {
935
- var flicking = _a.flicking,
936
- activeClass = _a.activeClass;
937
-
938
- _this._updateClass({
939
- flicking: flicking,
940
- activeClass: activeClass
941
- }, flicking.camera.position);
944
+ this._synchronizedFlickingOptions.forEach(function (options) {
945
+ _this._updateClass(options, options.flicking.index);
942
946
  });
943
947
  };
944
948
 
945
949
  __proto._preventEvent = function (fn) {
946
- this._removeEvents(this._synchronizedFlickingOptions);
950
+ this._removeEvents();
947
951
 
948
952
  fn();
949
953
 
950
- this._addEvents(this._synchronizedFlickingOptions);
954
+ this._addEvents();
951
955
  };
952
956
 
953
957
  return Sync;
954
958
  }();
955
959
 
960
+ /* eslint-disable no-underscore-dangle */
961
+ /**
962
+ * You can apply perspective effect while panel is moving.
963
+ * @ko 패널들을 움직이면서 입체감을 부여할 수 있습니다.
964
+ * @memberof Flicking.Plugins
965
+ */
966
+
967
+ var Perspective =
968
+ /*#__PURE__*/
969
+ function () {
970
+ /**
971
+ * @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>
972
+ * @param - Effect amplication scale.<ko>효과 증폭도</ko>
973
+ * @param - Effect amplication rotate.<ko>회전 증폭도</ko>
974
+ * @param - The value of perspective CSS property. <ko>css perspective 속성 값</ko>
975
+ * @example
976
+ * ```ts
977
+ * flicking.addPlugins(new Perspective({ selector: "p", scale: 1, rotate: 1, perspective = 1000 }));
978
+ * ```
979
+ */
980
+ function Perspective(_a) {
981
+ var _this = this;
982
+
983
+ var _b = _a === void 0 ? {} : _a,
984
+ _c = _b.selector,
985
+ selector = _c === void 0 ? "" : _c,
986
+ _d = _b.scale,
987
+ scale = _d === void 0 ? 1 : _d,
988
+ _e = _b.rotate,
989
+ rotate = _e === void 0 ? 1 : _e,
990
+ _f = _b.perspective,
991
+ perspective = _f === void 0 ? 1000 : _f;
992
+
993
+ this.update = function () {
994
+ _this._onMove();
995
+ };
996
+
997
+ this._onMove = function () {
998
+ var flicking = _this._flicking;
999
+ var selector = _this._selector;
1000
+ var scale = _this._scale;
1001
+ var rotate = _this._rotate;
1002
+ var perspective = _this._perspective;
1003
+ if (!flicking) return;
1004
+ var horizontal = flicking.horizontal;
1005
+ var panels = flicking.visiblePanels;
1006
+ panels.forEach(function (panel) {
1007
+ var progress = panel.outsetProgress;
1008
+ var el = panel.element;
1009
+ var target = selector ? el.querySelector(selector) : el;
1010
+ var panelScale = 1 / (Math.abs(progress * scale) + 1);
1011
+ var rotateDegree = progress > 0 ? Math.min(90, progress * 100 * rotate) : Math.max(-90, progress * 100 * rotate);
1012
+
1013
+ var _a = horizontal ? [0, rotateDegree] : [rotateDegree, 0],
1014
+ rotateX = _a[0],
1015
+ rotateY = _a[1];
1016
+
1017
+ target.style.transform = "perspective(" + perspective + "px) rotateX(" + rotateX + "deg) rotateY(" + rotateY + "deg) scale(" + panelScale + ")";
1018
+ });
1019
+ };
1020
+
1021
+ this._flicking = null;
1022
+ this._selector = selector;
1023
+ this._scale = scale;
1024
+ this._rotate = rotate;
1025
+ this._perspective = perspective;
1026
+ }
1027
+
1028
+ var __proto = Perspective.prototype;
1029
+ Object.defineProperty(__proto, "selector", {
1030
+ get: function () {
1031
+ return this._selector;
1032
+ },
1033
+ set: function (val) {
1034
+ this._selector = val;
1035
+ },
1036
+ enumerable: false,
1037
+ configurable: true
1038
+ });
1039
+ Object.defineProperty(__proto, "scale", {
1040
+ get: function () {
1041
+ return this._scale;
1042
+ },
1043
+ set: function (val) {
1044
+ this._scale = val;
1045
+ },
1046
+ enumerable: false,
1047
+ configurable: true
1048
+ });
1049
+ Object.defineProperty(__proto, "rotate", {
1050
+ get: function () {
1051
+ return this._rotate;
1052
+ },
1053
+ set: function (val) {
1054
+ this._rotate = val;
1055
+ },
1056
+ enumerable: false,
1057
+ configurable: true
1058
+ });
1059
+ Object.defineProperty(__proto, "perspective", {
1060
+ get: function () {
1061
+ return this._perspective;
1062
+ },
1063
+ set: function (val) {
1064
+ this._perspective = val;
1065
+ },
1066
+ enumerable: false,
1067
+ configurable: true
1068
+ });
1069
+
1070
+ __proto.init = function (flicking) {
1071
+ if (this._flicking) {
1072
+ this.destroy();
1073
+ }
1074
+
1075
+ this._flicking = flicking;
1076
+ flicking.on(EVENTS.MOVE, this._onMove);
1077
+ flicking.on(EVENTS.AFTER_RESIZE, this.update);
1078
+
1079
+ this._onMove();
1080
+ };
1081
+
1082
+ __proto.destroy = function () {
1083
+ if (!this._flicking) return;
1084
+
1085
+ this._flicking.off(EVENTS.MOVE, this._onMove);
1086
+
1087
+ this._flicking.off(EVENTS.AFTER_RESIZE, this.update);
1088
+
1089
+ this._flicking = null;
1090
+ };
1091
+
1092
+ return Perspective;
1093
+ }();
1094
+
956
1095
  /*! *****************************************************************************
957
1096
  Copyright (c) Microsoft Corporation.
958
1097
 
@@ -1056,6 +1195,8 @@ function (_super) {
1056
1195
  });
1057
1196
  bullet.addEventListener(BROWSER.TOUCH_START, function (e) {
1058
1197
  e.stopPropagation();
1198
+ }, {
1199
+ passive: true
1059
1200
  });
1060
1201
  bullet.addEventListener(BROWSER.CLICK, function () {
1061
1202
  flicking.moveTo(anchorPoint.panel.index).catch(function (err) {
@@ -1178,6 +1319,8 @@ function (_super) {
1178
1319
  });
1179
1320
  bullet.addEventListener(BROWSER.TOUCH_START, function (e) {
1180
1321
  e.stopPropagation();
1322
+ }, {
1323
+ passive: true
1181
1324
  });
1182
1325
  bullet.addEventListener(BROWSER.CLICK, function () {
1183
1326
  flicking.moveTo(anchorPoint.panel.index).catch(function (err) {
@@ -1505,5 +1648,5 @@ function () {
1505
1648
  * @namespace Flicking
1506
1649
  */
1507
1650
 
1508
- export { ARROW, Arrow, AutoPlay, Fade, PAGINATION, Pagination, Parallax, SYNC, Sync };
1651
+ export { ARROW, Arrow, AutoPlay, Fade, PAGINATION, Pagination, Parallax, Perspective, SYNC, Sync };
1509
1652
  //# sourceMappingURL=plugins.esm.js.map