@egjs/flicking 4.11.3 → 4.12.0-beta.1

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.
Files changed (78) hide show
  1. package/declaration/CrossFlicking.d.ts +29 -0
  2. package/declaration/Flicking.d.ts +244 -240
  3. package/declaration/camera/Camera.d.ts +89 -89
  4. package/declaration/camera/index.d.ts +4 -4
  5. package/declaration/camera/mode/BoundCameraMode.d.ts +13 -13
  6. package/declaration/camera/mode/CameraMode.d.ts +20 -20
  7. package/declaration/camera/mode/CircularCameraMode.d.ts +19 -19
  8. package/declaration/camera/mode/LinearCameraMode.d.ts +9 -9
  9. package/declaration/camera/mode/index.d.ts +6 -6
  10. package/declaration/cfc/getDefaultCameraTransform.d.ts +3 -3
  11. package/declaration/cfc/getRenderingPanels.d.ts +4 -4
  12. package/declaration/cfc/index.d.ts +5 -5
  13. package/declaration/cfc/sync.d.ts +4 -4
  14. package/declaration/cfc/withFlickingMethods.d.ts +2 -2
  15. package/declaration/const/axes.d.ts +8 -8
  16. package/declaration/const/error.d.ts +34 -34
  17. package/declaration/const/external.d.ts +52 -48
  18. package/declaration/control/AxesController.d.ts +44 -44
  19. package/declaration/control/Control.d.ts +45 -45
  20. package/declaration/control/FreeControl.d.ts +14 -14
  21. package/declaration/control/SnapControl.d.ts +16 -16
  22. package/declaration/control/StateMachine.d.ts +14 -14
  23. package/declaration/control/StrictControl.d.ts +20 -20
  24. package/declaration/control/index.d.ts +14 -14
  25. package/declaration/control/states/AnimatingState.d.ts +9 -9
  26. package/declaration/control/states/DisabledState.d.ts +9 -9
  27. package/declaration/control/states/DraggingState.d.ts +8 -8
  28. package/declaration/control/states/HoldingState.d.ts +10 -10
  29. package/declaration/control/states/IdleState.d.ts +9 -9
  30. package/declaration/control/states/State.d.ts +47 -47
  31. package/declaration/core/AnchorPoint.d.ts +15 -15
  32. package/declaration/core/AutoResizer.d.ts +16 -16
  33. package/declaration/core/FlickingError.d.ts +5 -5
  34. package/declaration/core/ResizeWatcher.d.ts +33 -33
  35. package/declaration/core/Viewport.d.ts +25 -25
  36. package/declaration/core/VirtualManager.d.ts +37 -37
  37. package/declaration/core/index.d.ts +6 -6
  38. package/declaration/core/panel/Panel.d.ts +89 -89
  39. package/declaration/core/panel/VirtualPanel.d.ts +19 -19
  40. package/declaration/core/panel/index.d.ts +5 -5
  41. package/declaration/core/panel/provider/ElementProvider.d.ts +8 -8
  42. package/declaration/core/panel/provider/VanillaElementProvider.d.ts +12 -12
  43. package/declaration/core/panel/provider/VirtualElementProvider.d.ts +15 -15
  44. package/declaration/core/panel/provider/index.d.ts +5 -5
  45. package/declaration/index.cjs.d.ts +3 -3
  46. package/declaration/index.d.ts +14 -13
  47. package/declaration/index.umd.d.ts +2 -2
  48. package/declaration/renderer/ExternalRenderer.d.ts +7 -7
  49. package/declaration/renderer/Renderer.d.ts +59 -59
  50. package/declaration/renderer/VanillaRenderer.d.ts +10 -10
  51. package/declaration/renderer/index.d.ts +6 -6
  52. package/declaration/renderer/strategy/NormalRenderingStrategy.d.ts +23 -23
  53. package/declaration/renderer/strategy/RenderingStrategy.d.ts +15 -15
  54. package/declaration/renderer/strategy/VirtualRenderingStrategy.d.ts +17 -17
  55. package/declaration/renderer/strategy/index.d.ts +5 -5
  56. package/declaration/type/event.d.ts +88 -88
  57. package/declaration/type/external.d.ts +31 -31
  58. package/declaration/type/internal.d.ts +13 -13
  59. package/declaration/utils.d.ts +45 -45
  60. package/dist/flicking.cjs.js +252 -39
  61. package/dist/flicking.cjs.js.map +1 -1
  62. package/dist/flicking.esm.js +249 -40
  63. package/dist/flicking.esm.js.map +1 -1
  64. package/dist/flicking.js +255 -39
  65. package/dist/flicking.js.map +1 -1
  66. package/dist/flicking.min.js +2 -2
  67. package/dist/flicking.min.js.map +1 -1
  68. package/dist/flicking.pkgd.js +255 -39
  69. package/dist/flicking.pkgd.js.map +1 -1
  70. package/dist/flicking.pkgd.min.js +2 -2
  71. package/dist/flicking.pkgd.min.js.map +1 -1
  72. package/package.json +1 -1
  73. package/src/CrossFlicking.ts +252 -0
  74. package/src/Flicking.ts +24 -2
  75. package/src/const/external.ts +12 -0
  76. package/src/control/AxesController.ts +1 -1
  77. package/src/index.ts +2 -0
  78. package/src/index.umd.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egjs/flicking",
3
- "version": "4.11.3",
3
+ "version": "4.12.0-beta.1",
4
4
  "description": "Everyday 30 million people experience. It's reliable, flexible and extendable carousel.",
5
5
  "main": "dist/flicking.cjs.js",
6
6
  "module": "dist/flicking.esm.js",
@@ -0,0 +1,252 @@
1
+ /*
2
+ * Copyright (c) 2015 NAVER Corp.
3
+ * egjs projects are licensed under the MIT license
4
+ */
5
+
6
+ import Flicking, { FlickingOptions } from "./Flicking";
7
+ import { ChangedEvent, MoveEndEvent, MoveEvent } from "./type/event";
8
+ import { LiteralUnion, ValueOf } from "./type/internal";
9
+ import { EVENTS, MOVE_DIRECTION } from "./const/external";
10
+
11
+ /**
12
+ * @interface
13
+ */
14
+ export interface CrossFlickingEvents {
15
+ // FlickingEvent 들을 확장하자...
16
+ }
17
+
18
+ /**
19
+ * @interface
20
+ */
21
+ export interface CrossFlickingOptions {
22
+ verticalOptions: FlickingOptions | undefined;
23
+ // 한쪽 움직이면 다른 한쪽 움직임을 막을지 여부
24
+ // 이전 패널 기억 여부
25
+ }
26
+
27
+ /**
28
+ * Flicking Status returned by {@link Flicking#getStatus}
29
+ * @ko {@link Flicking#getStatus}에 의해 반환된 Flicking 상태 객체
30
+ * @interface
31
+ * @property {number} index An index of the active panel<ko>활성화된 패널의 인덱스</ko>
32
+ * @property {object} position A info to restore camera {@link Camera#position position}<ko>카메라 {@link Camera#position position}을 설정하기 위한 정보들</ko>
33
+ * @property {number} [position.panel] An index of the panel camera is located at<ko>카메라가 위치한 패널의 인덱스</ko>
34
+ * @property {number} [position.progressInPanel] A progress of the camera position inside the panel<ko>패널 내에서의 카메라 위치의 진행도</ko>
35
+ * @property {number} visibleOffset An offset to visible panel's original index. This value is available only when `visiblePanelsOnly` is `true`
36
+ * <ko>현재 보이는 패널들을 저장했을 때, 원래의 인덱스 대비 offset. `visiblePanelsOnly` 옵션을 사용했을 때만 사용 가능합니다</ko>
37
+ * @property {object[]} panels A data array of panels<ko>패널의 정보를 담은 배열</ko>
38
+ * @property {index} [panels.index] An index of the panel<ko>패널의 인덱스</ko>
39
+ * @property {string | undefined} [panels.html] An `outerHTML` of the panel element<ko>패널 엘리먼트의 `outerHTML`</ko>
40
+ */
41
+ export interface VerticalState {
42
+ start: number;
43
+ end: number;
44
+ element: HTMLElement;
45
+ }
46
+
47
+ /**
48
+ * @extends Component
49
+ * @support {"ie": "9+(with polyfill)", "ch" : "latest", "ff" : "latest", "sf" : "latest", "edge" : "latest", "ios" : "7+", "an" : "4.X+"}
50
+ * @requires {@link https://github.com/naver/egjs-component|@egjs/component}
51
+ * @requires {@link https://github.com/naver/egjs-axes|@egjs/axes}
52
+ */
53
+ export class CrossFlicking extends Flicking {
54
+ // Core components
55
+ private _verticalFlicking: Flicking[];
56
+
57
+ // Options
58
+ private _verticalOptions: CrossFlickingOptions["verticalOptions"];
59
+
60
+ // Internal State
61
+ private _verticalState: VerticalState[];
62
+
63
+ private _moveDirection: LiteralUnion<ValueOf<typeof MOVE_DIRECTION>> | null;
64
+ private _nextIndex: number;
65
+
66
+ // Components
67
+ /**
68
+ * Change active panel index on mouse/touch hold while animating.
69
+ * `index` of the `willChange`/`willRestore` event will be used as new index.
70
+ * @ko 애니메이션 도중 마우스/터치 입력시 현재 활성화된 패널의 인덱스를 변경합니다.
71
+ * `willChange`/`willRestore` 이벤트의 `index`값이 새로운 인덱스로 사용될 것입니다.
72
+ * @type {FlickingOptions}
73
+ * @default undefined
74
+ * @see {@link https://naver.github.io/egjs-flicking/Options#changeonhold changeOnHold ( Options )}
75
+ */
76
+ public get verticalOptions() {
77
+ return this._verticalOptions;
78
+ }
79
+
80
+ // Options Setter
81
+ // UI / LAYOUT
82
+ // public set align(val: FlickingOptions["align"]) {
83
+ // this._align = val;
84
+ // }
85
+
86
+ public constructor(
87
+ root: HTMLElement | string,
88
+ { verticalOptions = undefined }: Partial<CrossFlickingOptions> = {}
89
+ ) {
90
+ super(root);
91
+
92
+ // Internal states
93
+ this._verticalState = [];
94
+ this._moveDirection = null;
95
+ this._nextIndex = 0;
96
+
97
+ // Bind options
98
+ this._verticalOptions = verticalOptions;
99
+
100
+ // Create core components
101
+ // this._viewport = new Viewport(this, getElement(root));
102
+ }
103
+
104
+ /**
105
+ * Initialize Flicking and move to the default index
106
+ * This is automatically called on Flicking's constructor when `autoInit` is true(default)
107
+ * @ko Flicking을 초기화하고, 디폴트 인덱스로 이동합니다
108
+ * 이 메소드는 `autoInit` 옵션이 true(default)일 경우 Flicking이 생성될 때 자동으로 호출됩니다
109
+ * @fires Flicking#ready
110
+ * @return {Promise<void>}
111
+ */
112
+ public init(): Promise<void> {
113
+ return super.init().then(() => {
114
+ // data-index로 분류하기 전에 임시로 모든 children에 대해 vertical flicking으로 해보자.
115
+ // camera.children들에 대해 갯수 세기
116
+ let verticalPanels = ``;
117
+ this._verticalState = this.camera.children.reduce(
118
+ (state: VerticalState[], child: HTMLElement) => {
119
+ const start = state.length ? +state[state.length - 1].end + 1 : 0;
120
+ verticalPanels += child.children[0].innerHTML;
121
+ return [
122
+ ...state,
123
+ {
124
+ start,
125
+ end: start + child.children[0].children.length - 1,
126
+ element: child,
127
+ },
128
+ ];
129
+ },
130
+ []
131
+ );
132
+ this.camera.children.forEach((child) => {
133
+ child.children[0].innerHTML = verticalPanels;
134
+ });
135
+ this._verticalFlicking = this.camera.children.map((child, i) => {
136
+ return new Flicking(child, {
137
+ ...this.verticalOptions,
138
+ horizontal: false,
139
+ panelsPerView: 1,
140
+ defaultIndex: this._verticalState[i].start,
141
+ });
142
+ });
143
+
144
+ this.on(EVENTS.HOLD_START, this._onHorizontalHoldStart);
145
+ this.on(EVENTS.MOVE, this._onHorizontalMove);
146
+ this.on(EVENTS.MOVE_END, this._onHorizontalMoveEnd);
147
+
148
+ this._verticalFlicking.forEach((child) => {
149
+ child.on(EVENTS.HOLD_START, this._onVerticalHoldStart);
150
+ child.on(EVENTS.MOVE, this._onVerticalMove);
151
+ child.on(EVENTS.MOVE_END, this._onVerticalMoveEnd);
152
+ child.on(EVENTS.CHANGED, this._onVerticalChanged);
153
+ });
154
+ });
155
+ }
156
+
157
+ private _syncToCategory(index: number, outerIndex: number): void {
158
+ this.stopAnimation();
159
+ this._verticalFlicking.forEach((child, i) => {
160
+ const { start, end } = this._verticalState[i];
161
+
162
+ if (start <= index && end >= index && outerIndex !== i) {
163
+ child.stopAnimation();
164
+ void child.moveTo(index, 0);
165
+ void this.moveTo(i, 0);
166
+ }
167
+ });
168
+ }
169
+
170
+ private _onHorizontalHoldStart = (): void => {
171
+ this.dragThreshold = 10;
172
+ this._moveDirection = null;
173
+ };
174
+
175
+ private _onHorizontalMove = (e: MoveEvent): void => {
176
+ if (e.isTrusted && !this._moveDirection) {
177
+ this._verticalFlicking.forEach((child) => {
178
+ child.dragThreshold = Infinity;
179
+ });
180
+ this._moveDirection = MOVE_DIRECTION.HORIZONTAL;
181
+ }
182
+ };
183
+
184
+ private _onHorizontalMoveEnd = (e: MoveEndEvent): void => {
185
+ const visiblePanels = this.visiblePanels;
186
+
187
+ this._verticalFlicking.forEach((child) => {
188
+ child.dragThreshold = 10;
189
+ });
190
+ this._moveDirection = null;
191
+
192
+ if (visiblePanels.length > 1) {
193
+ this._nextIndex =
194
+ e.direction === "NEXT"
195
+ ? visiblePanels[1].index
196
+ : visiblePanels[0].index;
197
+ } else {
198
+ this._nextIndex = visiblePanels[0].index;
199
+ }
200
+
201
+ this._verticalFlicking.forEach((child, i) => {
202
+ if (this._nextIndex !== i) {
203
+ const { start, end } = this._verticalState[i];
204
+
205
+ if (child.index < start) {
206
+ child.stopAnimation();
207
+ void child.moveTo(start, 0);
208
+ } else if (child.index > end) {
209
+ child.stopAnimation();
210
+ void child.moveTo(end, 0);
211
+ }
212
+ }
213
+ });
214
+
215
+ if (e.isTrusted) {
216
+ this._syncToCategory(
217
+ this._verticalFlicking[this._nextIndex].index,
218
+ this._nextIndex
219
+ );
220
+ }
221
+ };
222
+
223
+ private _onVerticalHoldStart = (): void => {
224
+ this._verticalFlicking.forEach((child) => {
225
+ child.dragThreshold = 10;
226
+ });
227
+ this._moveDirection = null;
228
+ };
229
+
230
+ private _onVerticalMove = (e: MoveEvent): void => {
231
+ if (e.isTrusted && !this._moveDirection) {
232
+ this.dragThreshold = Infinity;
233
+ this._moveDirection = MOVE_DIRECTION.VERTICAL;
234
+ }
235
+ };
236
+
237
+ private _onVerticalMoveEnd = (): void => {
238
+ this.dragThreshold = 10;
239
+ this._moveDirection = null;
240
+ };
241
+
242
+ private _onVerticalChanged = (e: ChangedEvent): void => {
243
+ // this.visiblePanels.length 가 2보다 크다면 가로 방향 Flicking이 조작 중이라는 것을 의미합니다.
244
+ // 이 경우 가로 방향 Flicking의 이동이 완전히 끝난 뒤 _onHorizontalMoveEnd 에서 syncToCategory할 것이므로 여기서는 하지 않습니다.
245
+ if (
246
+ this.visiblePanels.length < 2 &&
247
+ this._verticalFlicking[this.index] === e.currentTarget
248
+ ) {
249
+ this._syncToCategory(e.index, this.index);
250
+ }
251
+ };
252
+ }
package/src/Flicking.ts CHANGED
@@ -73,6 +73,7 @@ export interface FlickingOptions {
73
73
  inputType: string[];
74
74
  moveType: ValueOf<typeof MOVE_TYPE> | MoveTypeOptions<ValueOf<typeof MOVE_TYPE>>;
75
75
  threshold: number;
76
+ dragThreshold: number;
76
77
  interruptable: boolean;
77
78
  bounce: number | string | [number | string, number | string];
78
79
  iOSEdgeSwipeThreshold: number;
@@ -152,6 +153,7 @@ class Flicking extends Component<FlickingEvents> {
152
153
  private _inputType: FlickingOptions["inputType"];
153
154
  private _moveType: FlickingOptions["moveType"];
154
155
  private _threshold: FlickingOptions["threshold"];
156
+ private _dragThreshold: FlickingOptions["dragThreshold"];
155
157
  private _interruptable: FlickingOptions["interruptable"];
156
158
  private _bounce: FlickingOptions["bounce"];
157
159
  private _iOSEdgeSwipeThreshold: FlickingOptions["iOSEdgeSwipeThreshold"];
@@ -350,7 +352,7 @@ class Flicking extends Component<FlickingEvents> {
350
352
  public get align() { return this._align; }
351
353
  /**
352
354
  * Index of the panel to move when Flicking's {@link Flicking#init init()} is called. A zero-based integer
353
- * @ko Flicking의 {@link Flicking#init init()}이 호출될 때 이동할 디폴트 패널의 인덱스로, 0부터 시작하는 정수입니다
355
+ * @ko Flicking의 {@link Flicking#init init()}이 호출될 때 이동할 디폴트 패널의 인덱스로, 0부터 시작하는 정수입니다.
354
356
  * @type {number}
355
357
  * @default 0
356
358
  * @see {@link https://naver.github.io/egjs-flicking/Options#defaultindex defaultIndex ( Options )}
@@ -528,12 +530,20 @@ class Flicking extends Component<FlickingEvents> {
528
530
  public get moveType() { return this._moveType; }
529
531
  /**
530
532
  * Movement threshold to change panel (unit: px). It should be dragged above the threshold to change the current panel.
531
- * @ko 패널 변경을 위한 이동 임계값 (단위: px). 주어진 값 이상으로 스크롤해야만 패널 변경이 가능하다.
533
+ * @ko 패널 변경을 위한 이동 임계값 (단위: px). 주어진 값 이상으로 스크롤해야만 패널 변경이 가능합니다.
532
534
  * @type {number}
533
535
  * @default 40
534
536
  * @see {@link https://naver.github.io/egjs-flicking/Options#threshold Threshold ( Options )}
535
537
  */
536
538
  public get threshold() { return this._threshold; }
539
+ /**
540
+ * Minimal distance of user input before recognizing (unit: px). It should be dragged above the dragThreshold to move the panel.
541
+ * @ko 사용자의 입력을 인식하기 위한 최소한의 거리 (단위: px). 주어진 값 이상으로 스크롤해야만 패널이 움직입니다.
542
+ * @type {number}
543
+ * @default 1
544
+ * @see {@link https://naver.github.io/egjs-flicking/Options#dragThreshold dragThreshold ( Options )}
545
+ */
546
+ public get dragThreshold() { return this._dragThreshold; }
537
547
  /**
538
548
  * Set animation to be interruptable by click/touch.
539
549
  * @ko 사용자의 클릭/터치로 인해 애니메이션을 도중에 멈출 수 있도록 설정합니다.
@@ -845,6 +855,16 @@ class Flicking extends Component<FlickingEvents> {
845
855
  }
846
856
 
847
857
  public set threshold(val: FlickingOptions["threshold"]) { this._threshold = val; }
858
+
859
+ public set dragThreshold(val: FlickingOptions["dragThreshold"]) {
860
+ this._dragThreshold = val;
861
+ const panInput = this._control.controller.panInput;
862
+
863
+ if (panInput) {
864
+ panInput.options.threshold = val;
865
+ }
866
+ }
867
+
848
868
  public set interruptable(val: FlickingOptions["interruptable"]) {
849
869
  this._interruptable = val;
850
870
 
@@ -969,6 +989,7 @@ class Flicking extends Component<FlickingEvents> {
969
989
  inputType = ["mouse", "touch"],
970
990
  moveType = "snap",
971
991
  threshold = 40,
992
+ dragThreshold = 1,
972
993
  interruptable = true,
973
994
  bounce = "20%",
974
995
  iOSEdgeSwipeThreshold = 30,
@@ -1014,6 +1035,7 @@ class Flicking extends Component<FlickingEvents> {
1014
1035
  this._inputType = inputType;
1015
1036
  this._moveType = moveType;
1016
1037
  this._threshold = threshold;
1038
+ this._dragThreshold = dragThreshold;
1017
1039
  this._interruptable = interruptable;
1018
1040
  this._bounce = bounce;
1019
1041
  this._iOSEdgeSwipeThreshold = iOSEdgeSwipeThreshold;
@@ -122,3 +122,15 @@ export const ORDER = {
122
122
  LTR: "ltr",
123
123
  RTL: "rtl"
124
124
  } as const;
125
+
126
+ /**
127
+ * An object that contains the direction that {@link Flicking} is moving
128
+ * @ko {@link Flicking}이 움직이는 방향을 담고 있는 객체
129
+ * @type {object}
130
+ * @property {"horizontal"} HORIZONTAL horizontal<ko>수평 방향</ko>
131
+ * @property {"vertical"} VERTICAL vertical<ko>수직 방향</ko>
132
+ */
133
+ export const MOVE_DIRECTION = {
134
+ HORIZONTAL: "horizontal",
135
+ VERTICAL: "vertical"
136
+ } as const;
@@ -148,7 +148,7 @@ class AxesController {
148
148
  });
149
149
  this._panInput = new PanInput(flicking.viewport.element, {
150
150
  inputType: flicking.inputType,
151
- threshold: 1,
151
+ threshold: flicking.dragThreshold,
152
152
  iOSEdgeSwipeThreshold: flicking.iOSEdgeSwipeThreshold,
153
153
  preventDefaultOnDrag: flicking.preventDefaultOnDrag,
154
154
  scale: flicking.horizontal ? [flicking.camera.panelOrder === ORDER.RTL ? 1 : -1, 0] : [0, -1],
package/src/index.ts CHANGED
@@ -5,6 +5,8 @@
5
5
  import Flicking from "./Flicking";
6
6
  import type { FlickingOptions, FlickingEvents } from "./Flicking";
7
7
 
8
+ export * from "./CrossFlicking";
9
+
8
10
  export * from "./core";
9
11
  export * from "./camera";
10
12
  export * from "./control";
package/src/index.umd.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  * egjs projects are licensed under the MIT license
4
4
  */
5
5
  import Flicking from "./Flicking";
6
+ import * as CrossFlicking from "./CrossFlicking";
6
7
  import * as Core from "./core";
7
8
  import * as Camera from "./camera";
8
9
  import * as Control from "./control";
@@ -19,5 +20,6 @@ merge(Flicking, Renderer);
19
20
  merge(Flicking, Constants);
20
21
  merge(Flicking, CFC);
21
22
  merge(Flicking, Utils);
23
+ merge(Flicking, CrossFlicking);
22
24
 
23
25
  export default Flicking;