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