@egjs/flicking-plugins 4.1.0 → 4.2.3
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/declaration/Sync.d.ts +37 -0
- package/declaration/const.d.ts +6 -0
- package/declaration/index.d.ts +3 -1
- package/dist/plugins.esm.js +276 -9
- package/dist/plugins.esm.js.map +1 -1
- package/dist/plugins.js +276 -7
- package/dist/plugins.js.map +1 -1
- package/dist/plugins.min.js +2 -2
- package/dist/plugins.min.js.map +1 -1
- package/package.json +4 -3
- package/src/Sync.ts +236 -0
- package/src/const.ts +7 -0
- package/src/index.ts +8 -1
- package/src/pagination/renderer/ScrollBulletRenderer.ts +17 -6
|
@@ -0,0 +1,37 @@
|
|
|
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;
|
|
6
|
+
synchronizedFlickingOptions: SychronizableFlickingOptions[];
|
|
7
|
+
}
|
|
8
|
+
export interface SychronizableFlickingOptions {
|
|
9
|
+
flicking: Flicking;
|
|
10
|
+
isClickable?: boolean;
|
|
11
|
+
isSlidable?: boolean;
|
|
12
|
+
activeClass?: string;
|
|
13
|
+
}
|
|
14
|
+
declare class Sync implements Plugin {
|
|
15
|
+
private _flicking;
|
|
16
|
+
private _type;
|
|
17
|
+
private _synchronizedFlickingOptions;
|
|
18
|
+
get type(): SyncOptions["type"];
|
|
19
|
+
get synchronizedFlickingOptions(): SyncOptions["synchronizedFlickingOptions"];
|
|
20
|
+
set type(val: SyncOptions["type"]);
|
|
21
|
+
set synchronizedFlickingOptions(val: SyncOptions["synchronizedFlickingOptions"]);
|
|
22
|
+
constructor({ type, synchronizedFlickingOptions }?: Partial<SyncOptions>);
|
|
23
|
+
init(flicking: Flicking): void;
|
|
24
|
+
destroy(): void;
|
|
25
|
+
update(): void;
|
|
26
|
+
private _preventEvent;
|
|
27
|
+
private _addEvents;
|
|
28
|
+
private _removeEvents;
|
|
29
|
+
private _onIndexChange;
|
|
30
|
+
private _onMove;
|
|
31
|
+
private _onMoveStart;
|
|
32
|
+
private _onMoveEnd;
|
|
33
|
+
private _onSelect;
|
|
34
|
+
private _synchronizeByIndex;
|
|
35
|
+
private _updateClass;
|
|
36
|
+
}
|
|
37
|
+
export default Sync;
|
package/declaration/const.d.ts
CHANGED
package/declaration/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ 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, { SyncOptions, SychronizableFlickingOptions } from "./Sync";
|
|
5
6
|
export * from "./pagination";
|
|
6
|
-
export { Parallax, Fade, AutoPlay, Arrow };
|
|
7
|
+
export { Parallax, Fade, AutoPlay, Arrow, Sync };
|
|
8
|
+
export type { SyncOptions, SychronizableFlickingOptions };
|
|
7
9
|
export * from "./const";
|
package/dist/plugins.esm.js
CHANGED
|
@@ -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.
|
|
7
|
+
version: 4.2.3
|
|
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.
|
|
@@ -398,6 +398,12 @@ var PAGINATION = {
|
|
|
398
398
|
SCROLL: "scroll"
|
|
399
399
|
}
|
|
400
400
|
};
|
|
401
|
+
var SYNC = {
|
|
402
|
+
TYPE: {
|
|
403
|
+
CAMERA: "camera",
|
|
404
|
+
INDEX: "index"
|
|
405
|
+
}
|
|
406
|
+
};
|
|
401
407
|
|
|
402
408
|
var addClass = function (el, className) {
|
|
403
409
|
if (el.classList) {
|
|
@@ -690,6 +696,255 @@ function () {
|
|
|
690
696
|
return Arrow;
|
|
691
697
|
}();
|
|
692
698
|
|
|
699
|
+
/**
|
|
700
|
+
* Plugin for synchronizing multiple flickings
|
|
701
|
+
* @ko 다양한 형태로 Flicking들이 같이 움직이게 할 수 있습니다.
|
|
702
|
+
* @memberof Flicking.Plugins
|
|
703
|
+
*/
|
|
704
|
+
|
|
705
|
+
var Sync =
|
|
706
|
+
/*#__PURE__*/
|
|
707
|
+
function () {
|
|
708
|
+
/** */
|
|
709
|
+
function Sync(_a) {
|
|
710
|
+
var _this = this;
|
|
711
|
+
|
|
712
|
+
var _b = _a === void 0 ? {} : _a,
|
|
713
|
+
_c = _b.type,
|
|
714
|
+
type = _c === void 0 ? SYNC.TYPE.CAMERA : _c,
|
|
715
|
+
_d = _b.synchronizedFlickingOptions,
|
|
716
|
+
synchronizedFlickingOptions = _d === void 0 ? [] : _d;
|
|
717
|
+
/* Internal Values */
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
this._flicking = null;
|
|
721
|
+
|
|
722
|
+
this._addEvents = function () {
|
|
723
|
+
var type = _this._type;
|
|
724
|
+
var synced = _this._synchronizedFlickingOptions;
|
|
725
|
+
synced.forEach(function (_a) {
|
|
726
|
+
var flicking = _a.flicking,
|
|
727
|
+
isSlidable = _a.isSlidable,
|
|
728
|
+
isClickable = _a.isClickable;
|
|
729
|
+
|
|
730
|
+
if (type === SYNC.TYPE.CAMERA) {
|
|
731
|
+
flicking.on(EVENTS.MOVE, _this._onMove);
|
|
732
|
+
flicking.on(EVENTS.MOVE_START, _this._onMoveStart);
|
|
733
|
+
flicking.on(EVENTS.MOVE_END, _this._onMoveEnd);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
if (type === SYNC.TYPE.INDEX && isSlidable) {
|
|
737
|
+
flicking.on(EVENTS.WILL_CHANGE, _this._onIndexChange);
|
|
738
|
+
flicking.on(EVENTS.WILL_RESTORE, _this._onIndexChange);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
if (isClickable) {
|
|
742
|
+
flicking.on(EVENTS.SELECT, _this._onSelect);
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
this._removeEvents = function () {
|
|
748
|
+
var type = _this._type;
|
|
749
|
+
var synced = _this._synchronizedFlickingOptions;
|
|
750
|
+
synced.forEach(function (_a) {
|
|
751
|
+
var flicking = _a.flicking,
|
|
752
|
+
isSlidable = _a.isSlidable,
|
|
753
|
+
isClickable = _a.isClickable;
|
|
754
|
+
|
|
755
|
+
if (type === SYNC.TYPE.CAMERA) {
|
|
756
|
+
flicking.off(EVENTS.MOVE, _this._onMove);
|
|
757
|
+
flicking.off(EVENTS.MOVE_START, _this._onMoveStart);
|
|
758
|
+
flicking.off(EVENTS.MOVE_END, _this._onMoveEnd);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
if (type === SYNC.TYPE.INDEX && isSlidable) {
|
|
762
|
+
flicking.off(EVENTS.WILL_CHANGE, _this._onIndexChange);
|
|
763
|
+
flicking.off(EVENTS.WILL_RESTORE, _this._onIndexChange);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
if (isClickable) {
|
|
767
|
+
flicking.off(EVENTS.SELECT, _this._onSelect);
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
this._onIndexChange = function (e) {
|
|
773
|
+
var flicking = e.currentTarget;
|
|
774
|
+
|
|
775
|
+
if (!flicking.initialized) {
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
_this._synchronizeByIndex(flicking, e.index);
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
this._onMove = function (e) {
|
|
783
|
+
var camera = e.currentTarget.camera;
|
|
784
|
+
var progress = (camera.position - camera.range.min) / camera.rangeDiff;
|
|
785
|
+
|
|
786
|
+
_this._synchronizedFlickingOptions.forEach(function (_a) {
|
|
787
|
+
var flicking = _a.flicking;
|
|
788
|
+
if (flicking === e.currentTarget) return;
|
|
789
|
+
var targetPosition = 0;
|
|
790
|
+
|
|
791
|
+
if (camera.position < camera.range.min) {
|
|
792
|
+
targetPosition = camera.position;
|
|
793
|
+
} else if (camera.position > camera.range.max) {
|
|
794
|
+
targetPosition = flicking.camera.range.max + camera.position - camera.range.max;
|
|
795
|
+
} else {
|
|
796
|
+
targetPosition = flicking.camera.range.min + flicking.camera.rangeDiff * progress;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
void flicking.camera.lookAt(targetPosition);
|
|
800
|
+
});
|
|
801
|
+
};
|
|
802
|
+
|
|
803
|
+
this._onMoveStart = function (e) {
|
|
804
|
+
_this._synchronizedFlickingOptions.forEach(function (_a) {
|
|
805
|
+
var flicking = _a.flicking;
|
|
806
|
+
|
|
807
|
+
if (flicking !== e.currentTarget) {
|
|
808
|
+
flicking.disableInput();
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
this._onMoveEnd = function (e) {
|
|
814
|
+
_this._synchronizedFlickingOptions.forEach(function (_a) {
|
|
815
|
+
var flicking = _a.flicking;
|
|
816
|
+
|
|
817
|
+
if (flicking !== e.currentTarget) {
|
|
818
|
+
flicking.enableInput();
|
|
819
|
+
flicking.control.updateInput();
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
this._onSelect = function (e) {
|
|
825
|
+
void e.currentTarget.moveTo(e.index).catch(function () {
|
|
826
|
+
return void 0;
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
_this._synchronizeByIndex(e.currentTarget, e.index);
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
this._synchronizeByIndex = function (activeFlicking, index) {
|
|
833
|
+
var synchronizedFlickingOptions = _this._synchronizedFlickingOptions;
|
|
834
|
+
|
|
835
|
+
_this._preventEvent(function () {
|
|
836
|
+
synchronizedFlickingOptions.forEach(function (options) {
|
|
837
|
+
// Active class should be applied same to the Flicking which triggered event
|
|
838
|
+
_this._updateClass(options, index);
|
|
839
|
+
|
|
840
|
+
var flicking = options.flicking;
|
|
841
|
+
if (flicking === activeFlicking) return;
|
|
842
|
+
var targetIndex = clamp(index, 0, flicking.panels.length);
|
|
843
|
+
|
|
844
|
+
if (flicking.animating) {
|
|
845
|
+
// Reserve moveTo once previous animation is finished
|
|
846
|
+
flicking.once(EVENTS.MOVE_END, function () {
|
|
847
|
+
void flicking.moveTo(targetIndex).catch(function () {
|
|
848
|
+
return void 0;
|
|
849
|
+
});
|
|
850
|
+
});
|
|
851
|
+
} else {
|
|
852
|
+
void flicking.moveTo(targetIndex);
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
});
|
|
856
|
+
};
|
|
857
|
+
|
|
858
|
+
this._updateClass = function (_a, index) {
|
|
859
|
+
var flicking = _a.flicking,
|
|
860
|
+
activeClass = _a.activeClass;
|
|
861
|
+
if (!activeClass) return;
|
|
862
|
+
flicking.panels.forEach(function (panel) {
|
|
863
|
+
if (panel.index === index) {
|
|
864
|
+
addClass(panel.element, activeClass);
|
|
865
|
+
} else {
|
|
866
|
+
removeClass(panel.element, activeClass);
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
this._type = type;
|
|
872
|
+
this._synchronizedFlickingOptions = synchronizedFlickingOptions;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
var __proto = Sync.prototype;
|
|
876
|
+
Object.defineProperty(__proto, "type", {
|
|
877
|
+
get: function () {
|
|
878
|
+
return this._type;
|
|
879
|
+
},
|
|
880
|
+
set: function (val) {
|
|
881
|
+
this._type = val;
|
|
882
|
+
},
|
|
883
|
+
enumerable: false,
|
|
884
|
+
configurable: true
|
|
885
|
+
});
|
|
886
|
+
Object.defineProperty(__proto, "synchronizedFlickingOptions", {
|
|
887
|
+
get: function () {
|
|
888
|
+
return this._synchronizedFlickingOptions;
|
|
889
|
+
},
|
|
890
|
+
set: function (val) {
|
|
891
|
+
this._synchronizedFlickingOptions = val;
|
|
892
|
+
},
|
|
893
|
+
enumerable: false,
|
|
894
|
+
configurable: true
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
__proto.init = function (flicking) {
|
|
898
|
+
var _this = this;
|
|
899
|
+
|
|
900
|
+
var synced = this._synchronizedFlickingOptions;
|
|
901
|
+
|
|
902
|
+
if (this._flicking) {
|
|
903
|
+
this.destroy();
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
this._flicking = flicking;
|
|
907
|
+
|
|
908
|
+
this._addEvents();
|
|
909
|
+
|
|
910
|
+
synced.forEach(function (options) {
|
|
911
|
+
var syncedFlicking = options.flicking;
|
|
912
|
+
|
|
913
|
+
_this._updateClass(options, syncedFlicking.defaultIndex);
|
|
914
|
+
});
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
__proto.destroy = function () {
|
|
918
|
+
var flicking = this._flicking;
|
|
919
|
+
|
|
920
|
+
if (!flicking) {
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
this._removeEvents();
|
|
925
|
+
|
|
926
|
+
this._flicking = null;
|
|
927
|
+
};
|
|
928
|
+
|
|
929
|
+
__proto.update = function () {
|
|
930
|
+
var _this = this;
|
|
931
|
+
|
|
932
|
+
this._synchronizedFlickingOptions.forEach(function (options) {
|
|
933
|
+
_this._updateClass(options, options.flicking.index);
|
|
934
|
+
});
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
__proto._preventEvent = function (fn) {
|
|
938
|
+
this._removeEvents();
|
|
939
|
+
|
|
940
|
+
fn();
|
|
941
|
+
|
|
942
|
+
this._addEvents();
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
return Sync;
|
|
946
|
+
}();
|
|
947
|
+
|
|
693
948
|
/*! *****************************************************************************
|
|
694
949
|
Copyright (c) Microsoft Corporation.
|
|
695
950
|
|
|
@@ -944,26 +1199,38 @@ function (_super) {
|
|
|
944
1199
|
var anchorOffset = anchorPoints[0].panel.index;
|
|
945
1200
|
var activeIndex = index - anchorOffset;
|
|
946
1201
|
if (anchorPoints.length <= 0) return;
|
|
947
|
-
var bulletClass = pagination.classPrefix + "-" + PAGINATION.BULLET_SUFFIX;
|
|
948
1202
|
var bulletActiveClass = pagination.classPrefix + "-" + PAGINATION.BULLET_ACTIVE_SUFFIX;
|
|
1203
|
+
var prevClassPrefix = pagination.classPrefix + "-" + PAGINATION.SCROLL_PREV_SUFFIX;
|
|
1204
|
+
var nextClassPrefix = pagination.classPrefix + "-" + PAGINATION.SCROLL_NEXT_SUFFIX;
|
|
949
1205
|
|
|
950
1206
|
var bulletPrevClass = function (offset) {
|
|
951
|
-
return
|
|
1207
|
+
return "" + prevClassPrefix + (offset > 1 ? offset : "");
|
|
952
1208
|
};
|
|
953
1209
|
|
|
954
1210
|
var bulletNextClass = function (offset) {
|
|
955
|
-
return
|
|
1211
|
+
return "" + nextClassPrefix + (offset > 1 ? offset : "");
|
|
956
1212
|
};
|
|
957
1213
|
|
|
1214
|
+
var prevClassRegex = new RegExp("^" + prevClassPrefix);
|
|
1215
|
+
var nextClassRegex = new RegExp("^" + nextClassPrefix);
|
|
958
1216
|
bullets.forEach(function (bullet, idx) {
|
|
959
1217
|
var indexOffset = idx - activeIndex;
|
|
1218
|
+
var classList = bullet.className.split(" ");
|
|
1219
|
+
|
|
1220
|
+
for (var _i = 0, classList_1 = classList; _i < classList_1.length; _i++) {
|
|
1221
|
+
var className = classList_1[_i];
|
|
1222
|
+
|
|
1223
|
+
if (className === bulletActiveClass || prevClassRegex.test(className) || nextClassRegex.test(className)) {
|
|
1224
|
+
removeClass(bullet, className);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
960
1227
|
|
|
961
1228
|
if (indexOffset === 0) {
|
|
962
|
-
bullet
|
|
1229
|
+
addClass(bullet, bulletActiveClass);
|
|
963
1230
|
} else if (indexOffset > 0) {
|
|
964
|
-
bullet
|
|
1231
|
+
addClass(bullet, bulletNextClass(Math.abs(indexOffset)));
|
|
965
1232
|
} else {
|
|
966
|
-
bullet
|
|
1233
|
+
addClass(bullet, bulletPrevClass(Math.abs(indexOffset)));
|
|
967
1234
|
}
|
|
968
1235
|
});
|
|
969
1236
|
pagination.scrollOnChange(activeIndex, {
|
|
@@ -1230,5 +1497,5 @@ function () {
|
|
|
1230
1497
|
* @namespace Flicking
|
|
1231
1498
|
*/
|
|
1232
1499
|
|
|
1233
|
-
export { ARROW, Arrow, AutoPlay, Fade, PAGINATION, Pagination, Parallax };
|
|
1500
|
+
export { ARROW, Arrow, AutoPlay, Fade, PAGINATION, Pagination, Parallax, SYNC, Sync };
|
|
1234
1501
|
//# sourceMappingURL=plugins.esm.js.map
|