@egjs/flicking 4.15.0 → 4.16.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 (185) hide show
  1. package/README.md +6 -175
  2. package/{declaration → dist}/CrossFlicking.d.ts +7 -2
  3. package/dist/Flicking.d.ts +1231 -0
  4. package/dist/camera/Camera.d.ts +324 -0
  5. package/{declaration → dist}/camera/mode/BoundCameraMode.d.ts +5 -4
  6. package/{declaration → dist}/camera/mode/CameraMode.d.ts +7 -6
  7. package/{declaration → dist}/camera/mode/CircularCameraMode.d.ts +9 -5
  8. package/{declaration → dist}/camera/mode/LinearCameraMode.d.ts +2 -4
  9. package/{declaration → dist}/cfc/getDefaultCameraTransform.d.ts +1 -1
  10. package/dist/cfc/withFlickingMethods.d.ts +15 -0
  11. package/{declaration/const/axes.d.ts → dist/constants/internal.d.ts} +8 -0
  12. package/dist/constants/values.d.ts +67 -0
  13. package/dist/control/AxesController.d.ts +186 -0
  14. package/dist/control/Control.d.ts +185 -0
  15. package/dist/control/FreeControl.d.ts +44 -0
  16. package/dist/control/SnapControl.d.ts +54 -0
  17. package/{declaration → dist}/control/StateMachine.d.ts +3 -0
  18. package/dist/control/StrictControl.d.ts +60 -0
  19. package/{declaration → dist}/control/states/AnimatingState.d.ts +12 -0
  20. package/{declaration → dist}/control/states/DisabledState.d.ts +12 -0
  21. package/{declaration → dist}/control/states/DraggingState.d.ts +12 -0
  22. package/{declaration → dist}/control/states/HoldingState.d.ts +12 -0
  23. package/{declaration → dist}/control/states/IdleState.d.ts +12 -0
  24. package/dist/control/states/State.d.ts +86 -0
  25. package/dist/core/AnchorPoint.d.ts +40 -0
  26. package/{declaration → dist}/core/AutoResizer.d.ts +6 -0
  27. package/dist/core/Viewport.d.ts +60 -0
  28. package/dist/core/VirtualManager.d.ts +84 -0
  29. package/dist/core/index.d.ts +6 -0
  30. package/dist/core/panel/Panel.d.ts +298 -0
  31. package/dist/core/panel/VirtualPanel.d.ts +41 -0
  32. package/dist/core/panel/index.d.ts +5 -0
  33. package/{declaration → dist}/core/panel/provider/VanillaElementProvider.d.ts +3 -0
  34. package/{declaration → dist}/core/panel/provider/VirtualElementProvider.d.ts +3 -0
  35. package/dist/error/FlickingError.d.ts +25 -0
  36. package/dist/error/codes.d.ts +79 -0
  37. package/dist/error/groups.d.ts +94 -0
  38. package/dist/error/index.d.ts +4 -0
  39. package/dist/error/types.d.ts +516 -0
  40. package/dist/event/groups.d.ts +40 -0
  41. package/dist/event/index.d.ts +3 -0
  42. package/dist/event/names.d.ts +47 -0
  43. package/dist/event/types.d.ts +318 -0
  44. package/dist/flicking.cjs.js +5559 -7791
  45. package/dist/flicking.cjs.js.map +1 -1
  46. package/dist/flicking.esm.js +5637 -7699
  47. package/dist/flicking.esm.js.map +1 -1
  48. package/dist/flicking.js +6722 -8893
  49. package/dist/flicking.js.map +1 -1
  50. package/dist/flicking.min.js +1 -9
  51. package/dist/flicking.min.js.map +1 -1
  52. package/dist/flicking.pkgd.js +9661 -14086
  53. package/dist/flicking.pkgd.js.map +1 -1
  54. package/dist/flicking.pkgd.min.js +1 -9
  55. package/dist/flicking.pkgd.min.js.map +1 -1
  56. package/dist/index.d.ts +16 -0
  57. package/dist/reactive/index.d.ts +126 -0
  58. package/{declaration → dist}/renderer/ExternalRenderer.d.ts +3 -0
  59. package/dist/renderer/Renderer.d.ts +215 -0
  60. package/{declaration → dist}/renderer/VanillaRenderer.d.ts +6 -0
  61. package/{declaration → dist}/renderer/strategy/NormalRenderingStrategy.d.ts +5 -2
  62. package/{declaration → dist}/renderer/strategy/RenderingStrategy.d.ts +4 -1
  63. package/dist/types/external.d.ts +58 -0
  64. package/dist/types/params.d.ts +10 -0
  65. package/{declaration → dist}/utils.d.ts +7 -7
  66. package/package.json +35 -162
  67. package/src/CrossFlicking.ts +68 -96
  68. package/src/Flicking.ts +1051 -972
  69. package/src/camera/Camera.ts +217 -206
  70. package/src/camera/index.ts +2 -6
  71. package/src/camera/mode/BoundCameraMode.ts +38 -27
  72. package/src/camera/mode/CameraMode.ts +14 -12
  73. package/src/camera/mode/CircularCameraMode.ts +24 -16
  74. package/src/camera/mode/LinearCameraMode.ts +3 -1
  75. package/src/camera/mode/index.ts +4 -10
  76. package/src/cfc/getDefaultCameraTransform.ts +9 -11
  77. package/src/cfc/getRenderingPanels.ts +2 -4
  78. package/src/cfc/index.ts +4 -9
  79. package/src/cfc/sync.ts +11 -5
  80. package/src/cfc/withFlickingMethods.ts +6 -7
  81. package/src/{const/axes.ts → constants/internal.ts} +1 -0
  82. package/src/constants/values.ts +78 -0
  83. package/src/control/AxesController.ts +119 -110
  84. package/src/control/Control.ts +147 -180
  85. package/src/control/FreeControl.ts +36 -60
  86. package/src/control/SnapControl.ts +64 -68
  87. package/src/control/StateMachine.ts +14 -11
  88. package/src/control/StrictControl.ts +58 -73
  89. package/src/control/index.ts +9 -12
  90. package/src/control/states/AnimatingState.ts +8 -11
  91. package/src/control/states/DisabledState.ts +0 -5
  92. package/src/control/states/DraggingState.ts +8 -12
  93. package/src/control/states/HoldingState.ts +10 -15
  94. package/src/control/states/IdleState.ts +1 -6
  95. package/src/control/states/State.ts +46 -85
  96. package/src/core/AnchorPoint.ts +25 -23
  97. package/src/core/AutoResizer.ts +6 -15
  98. package/src/core/ResizeWatcher.ts +17 -16
  99. package/src/core/Viewport.ts +35 -46
  100. package/src/core/VirtualManager.ts +48 -36
  101. package/src/core/index.ts +6 -9
  102. package/src/core/panel/Panel.ts +190 -185
  103. package/src/core/panel/VirtualPanel.ts +17 -21
  104. package/src/core/panel/index.ts +4 -9
  105. package/src/core/panel/provider/VanillaElementProvider.ts +6 -2
  106. package/src/core/panel/provider/VirtualElementProvider.ts +6 -2
  107. package/src/core/panel/provider/index.ts +2 -7
  108. package/src/{core → error}/FlickingError.ts +5 -7
  109. package/src/error/codes.ts +164 -0
  110. package/src/error/groups.ts +124 -0
  111. package/src/error/index.ts +9 -0
  112. package/src/error/types.ts +535 -0
  113. package/src/event/groups.ts +61 -0
  114. package/src/event/index.ts +8 -0
  115. package/src/event/names.ts +52 -0
  116. package/src/event/types.ts +355 -0
  117. package/src/index.ts +9 -11
  118. package/src/index.umd.ts +9 -3
  119. package/src/reactive/index.ts +39 -74
  120. package/src/renderer/Renderer.ts +170 -115
  121. package/src/renderer/VanillaRenderer.ts +12 -9
  122. package/src/renderer/index.ts +4 -9
  123. package/src/renderer/strategy/NormalRenderingStrategy.ts +26 -22
  124. package/src/renderer/strategy/RenderingStrategy.ts +2 -1
  125. package/src/renderer/strategy/VirtualRenderingStrategy.ts +20 -13
  126. package/src/renderer/strategy/index.ts +4 -9
  127. package/src/types/external.ts +72 -0
  128. package/src/{type → types}/internal.ts +2 -5
  129. package/src/types/params.ts +15 -0
  130. package/src/utils.ts +37 -32
  131. package/CONTRIBUTING.md +0 -59
  132. package/NOTICE +0 -31
  133. package/core-packages-link.js +0 -75
  134. package/debug/reactive/index.html +0 -240
  135. package/declaration/Flicking.d.ts +0 -264
  136. package/declaration/camera/Camera.d.ts +0 -90
  137. package/declaration/cfc/withFlickingMethods.d.ts +0 -2
  138. package/declaration/const/error.d.ts +0 -34
  139. package/declaration/const/external.d.ts +0 -54
  140. package/declaration/control/AxesController.d.ts +0 -45
  141. package/declaration/control/Control.d.ts +0 -45
  142. package/declaration/control/FreeControl.d.ts +0 -14
  143. package/declaration/control/SnapControl.d.ts +0 -16
  144. package/declaration/control/StrictControl.d.ts +0 -20
  145. package/declaration/control/states/State.d.ts +0 -47
  146. package/declaration/core/AnchorPoint.d.ts +0 -15
  147. package/declaration/core/FlickingError.d.ts +0 -5
  148. package/declaration/core/Viewport.d.ts +0 -25
  149. package/declaration/core/VirtualManager.d.ts +0 -37
  150. package/declaration/core/index.d.ts +0 -6
  151. package/declaration/core/panel/Panel.d.ts +0 -89
  152. package/declaration/core/panel/VirtualPanel.d.ts +0 -19
  153. package/declaration/core/panel/index.d.ts +0 -5
  154. package/declaration/index.d.ts +0 -16
  155. package/declaration/reactive/index.d.ts +0 -25
  156. package/declaration/renderer/Renderer.d.ts +0 -60
  157. package/declaration/type/event.d.ts +0 -88
  158. package/declaration/type/external.d.ts +0 -31
  159. package/jsconfig.json +0 -5
  160. package/jsdoc-to-mdx.json +0 -7
  161. package/rollup.config.demo.js +0 -24
  162. package/rollup.config.dev.js +0 -12
  163. package/rollup.config.js +0 -57
  164. package/src/const/error.ts +0 -64
  165. package/src/const/external.ts +0 -138
  166. package/src/type/event.ts +0 -315
  167. package/src/type/external.ts +0 -78
  168. package/tsconfig.declaration.json +0 -17
  169. package/tsconfig.eslint.json +0 -10
  170. package/tsconfig.json +0 -23
  171. package/{declaration → dist}/camera/index.d.ts +0 -0
  172. package/{declaration → dist}/camera/mode/index.d.ts +2 -2
  173. package/{declaration → dist}/cfc/getRenderingPanels.d.ts +0 -0
  174. package/{declaration → dist}/cfc/index.d.ts +3 -3
  175. package/{declaration → dist}/cfc/sync.d.ts +0 -0
  176. package/{declaration → dist}/control/index.d.ts +7 -7
  177. package/{declaration → dist}/core/ResizeWatcher.d.ts +0 -0
  178. package/{declaration → dist}/core/panel/provider/ElementProvider.d.ts +0 -0
  179. package/{declaration → dist}/core/panel/provider/index.d.ts +0 -0
  180. package/{declaration → dist}/index.cjs.d.ts +0 -0
  181. package/{declaration → dist}/index.umd.d.ts +0 -0
  182. package/{declaration → dist}/renderer/index.d.ts +1 -1
  183. package/{declaration → dist}/renderer/strategy/VirtualRenderingStrategy.d.ts +1 -1
  184. package/{declaration → dist}/renderer/strategy/index.d.ts +1 -1
  185. /package/{declaration/type → dist/types}/internal.d.ts +0 -0
@@ -3,86 +3,59 @@
3
3
  * egjs projects are licensed under the MIT license
4
4
  */
5
5
  import { OnRelease } from "@egjs/axes";
6
-
7
- import FlickingError from "../core/FlickingError";
6
+ import * as AXES from "../constants/internal";
8
7
  import AnchorPoint from "../core/AnchorPoint";
8
+ import * as ERROR from "../error/codes";
9
+ import FlickingError from "../error/FlickingError";
9
10
  import { circulateIndex, clamp, getFlickingAttached } from "../utils";
10
- import * as AXES from "../const/axes";
11
- import * as ERROR from "../const/error";
12
11
 
13
12
  import Control from "./Control";
14
13
 
15
14
  /**
16
- * An options for the {@link SnapControl}
17
- * @ko {@link SnapControl} 생성시 사용되는 옵션
18
- * @interface
19
- * @property {number} count Maximum number of panels can go after release<ko>입력 중단 이후 통과하여 이동할 수 있는 패널의 최대 갯수</ko>
15
+ * Options for the {@link SnapControl}
20
16
  */
21
17
  export interface SnapControlOptions {
18
+ /** Maximum number of panels can go after release */
22
19
  count: number;
23
20
  }
24
21
 
25
22
  /**
26
23
  * A {@link Control} that uses a release momentum to choose destination panel
27
- * @ko 입력을 중단한 시점의 가속도에 영향받아 도달할 패널을 계산하는 이동 방식을 사용하는 {@link Control}
24
+ * @public
28
25
  */
29
26
  class SnapControl extends Control {
30
27
  private _count: SnapControlOptions["count"];
31
28
 
32
29
  /**
33
30
  * Maximum number of panels can go after release
34
- * @ko 입력 중단 이후 통과하여 이동할 수 있는 패널의 최대 갯수
35
- * @type {number}
36
- * @default Infinity
31
+ * @defaultValue Infinity
37
32
  */
38
- public get count() { return this._count; }
33
+ public get count(): number {
34
+ return this._count;
35
+ }
39
36
 
40
- public set count(val: SnapControlOptions["count"]) { this._count = val; }
37
+ public set count(val: SnapControlOptions["count"]) {
38
+ this._count = val;
39
+ }
41
40
 
42
- /** */
43
- public constructor({
44
- count = Infinity
45
- }: Partial<SnapControlOptions> = {}) {
41
+ public constructor(options: Partial<SnapControlOptions> = {}) {
46
42
  super();
47
43
 
44
+ const { count = Infinity } = options;
45
+
48
46
  this._count = count;
49
47
  }
50
48
 
51
49
  /**
52
50
  * Move {@link Camera} to the given position
53
- * @ko {@link Camera}를 주어진 좌표로 이동합니다
54
- * @param {number} position The target position to move<ko>이동할 좌표</ko>
55
- * @param {number} duration Duration of the panel movement animation (unit: ms).<ko>패널 이동 애니메이션 진행 시간 (단위: ms)</ko>
56
- * @param {object} [axesEvent] {@link https://naver.github.io/egjs-axes/release/latest/doc/eg.Axes.html#event:release release} event of {@link https://naver.github.io/egjs-axes/ Axes}
57
- * <ko>{@link https://naver.github.io/egjs-axes/ Axes} {@link https://naver.github.io/egjs-axes/release/latest/doc/eg.Axes.html#event:release release} 이벤트</ko>
58
- * @fires Flicking#moveStart
59
- * @fires Flicking#move
60
- * @fires Flicking#moveEnd
61
- * @fires Flicking#willChange
62
- * @fires Flicking#changed
63
- * @fires Flicking#willRestore
64
- * @fires Flicking#restored
65
- * @fires Flicking#needPanel
66
- * @fires Flicking#visibleChange
67
- * @fires Flicking#reachEdge
68
- * @throws {FlickingError}
69
- * |code|condition|
70
- * |---|---|
71
- * |{@link ERROR_CODE POSITION_NOT_REACHABLE}|When the given panel is already removed or not in the Camera's {@link Camera#range range}|
72
- * |{@link ERROR_CODE NOT_ATTACHED_TO_FLICKING}|When {@link Control#init init} is not called before|
73
- * |{@link ERROR_CODE ANIMATION_INTERRUPTED}|When the animation is interrupted by user input|
74
- * |{@link ERROR_CODE STOP_CALLED_BY_USER}|When the animation is interrupted by user input|
75
- * <ko>
76
- *
77
- * |code|condition|
78
- * |---|---|
79
- * |{@link ERROR_CODE POSITION_NOT_REACHABLE}|주어진 패널이 제거되었거나, Camera의 {@link Camera#range range} 밖에 있을 경우|
80
- * |{@link ERROR_CODE NOT_ATTACHED_TO_FLICKING}|{@link Control#init init}이 이전에 호출되지 않은 경우|
81
- * |{@link ERROR_CODE ANIMATION_INTERRUPTED}|사용자 입력에 의해 애니메이션이 중단된 경우|
82
- * |{@link ERROR_CODE STOP_CALLED_BY_USER}|발생된 이벤트들 중 하나라도 `stop()`이 호출된 경우|
83
- *
84
- * </ko>
85
- * @return {Promise<void>} A Promise which will be resolved after reaching the target position<ko>해당 좌표 도달시에 resolve되는 Promise</ko>
51
+ * @remarks
52
+ * This method calculates the snap target based on the release momentum and threshold settings.
53
+ * @param position - The target position to move
54
+ * @param duration - Duration of the panel movement animation (unit: ms)
55
+ * @param axesEvent - {@link https://naver.github.io/egjs-axes/docs/api/Axes#event-release | release} event of {@link https://naver.github.io/egjs-axes/ | Axes}
56
+ * @fires {@link MovementEvents}
57
+ * @throws {@link MovementErrors}
58
+ * @returns A Promise which will be resolved after reaching the target position
86
59
  */
87
60
  public moveToPosition(position: number, duration: number, axesEvent?: OnRelease) {
88
61
  const flicking = getFlickingAttached(this._flicking);
@@ -92,18 +65,19 @@ class SnapControl extends Control {
92
65
  const state = this._controller.state;
93
66
 
94
67
  if (!activeAnchor || !anchorAtCamera) {
95
- return Promise.reject(new FlickingError(ERROR.MESSAGE.POSITION_NOT_REACHABLE(position), ERROR.CODE.POSITION_NOT_REACHABLE));
68
+ return Promise.reject(
69
+ new FlickingError(ERROR.MESSAGE.POSITION_NOT_REACHABLE(position), ERROR.CODE.POSITION_NOT_REACHABLE)
70
+ );
96
71
  }
97
72
 
98
73
  const snapThreshold = this._calcSnapThreshold(flicking.threshold, position, activeAnchor);
99
74
 
100
- const posDelta = flicking.animating
101
- ? state.delta
102
- : position - camera.position;
75
+ const posDelta = flicking.animating ? state.delta : position - camera.position;
103
76
  const absPosDelta = Math.abs(posDelta);
104
- const snapDelta = axesEvent && axesEvent.delta[AXES.POSITION_KEY] !== 0
105
- ? Math.abs(axesEvent.delta[AXES.POSITION_KEY])
106
- : absPosDelta;
77
+ const snapDelta =
78
+ axesEvent && axesEvent.delta[AXES.POSITION_KEY] !== 0
79
+ ? Math.abs(axesEvent.delta[AXES.POSITION_KEY])
80
+ : absPosDelta;
107
81
  let targetAnchor: AnchorPoint;
108
82
 
109
83
  if (snapDelta >= snapThreshold && snapDelta > 0) {
@@ -130,6 +104,11 @@ class SnapControl extends Control {
130
104
  });
131
105
  }
132
106
 
107
+ /**
108
+ * @internal
109
+ * @privateRemarks
110
+ * Finds the anchor point to snap to based on the target position and count option.
111
+ */
133
112
  private _findSnappedAnchor(position: number, anchorAtCamera: AnchorPoint): AnchorPoint {
134
113
  const flicking = getFlickingAttached(this._flicking);
135
114
  const camera = flicking.camera;
@@ -144,7 +123,7 @@ class SnapControl extends Control {
144
123
  throw new FlickingError(ERROR.MESSAGE.POSITION_NOT_REACHABLE(position), ERROR.CODE.POSITION_NOT_REACHABLE);
145
124
  }
146
125
 
147
- if (!isFinite(count)) {
126
+ if (!Number.isFinite(count)) {
148
127
  return anchorAtPosition;
149
128
  }
150
129
 
@@ -152,11 +131,15 @@ class SnapControl extends Control {
152
131
  const anchors = camera.anchorPoints;
153
132
 
154
133
  let loopCount = Math.sign(position - currentPos) * Math.floor(Math.abs(position - currentPos) / camera.rangeDiff);
155
- if ((position > currentPos && anchorAtPosition.index < anchorAtCamera.index)
156
- || (anchorAtPosition.position > anchorAtCamera.position && anchorAtPosition.index === anchorAtCamera.index)) {
134
+ if (
135
+ (position > currentPos && anchorAtPosition.index < anchorAtCamera.index) ||
136
+ (anchorAtPosition.position > anchorAtCamera.position && anchorAtPosition.index === anchorAtCamera.index)
137
+ ) {
157
138
  loopCount += 1;
158
- } else if ((position < currentPos && anchorAtPosition.index > anchorAtCamera.index)
159
- || (anchorAtPosition.position < anchorAtCamera.position && anchorAtPosition.index === anchorAtCamera.index)) {
139
+ } else if (
140
+ (position < currentPos && anchorAtPosition.index > anchorAtCamera.index) ||
141
+ (anchorAtPosition.position < anchorAtCamera.position && anchorAtPosition.index === anchorAtCamera.index)
142
+ ) {
160
143
  loopCount -= 1;
161
144
  }
162
145
 
@@ -174,7 +157,8 @@ class SnapControl extends Control {
174
157
  }
175
158
 
176
159
  if (flicking.circularEnabled) {
177
- const targetAnchor = anchors[circulateIndex(anchorAtCamera.index + Math.sign(position - currentPos) * count, panelCount)];
160
+ const targetAnchor =
161
+ anchors[circulateIndex(anchorAtCamera.index + Math.sign(position - currentPos) * count, panelCount)];
178
162
  let loop = Math.floor(count / panelCount);
179
163
 
180
164
  if (position > currentPos && targetAnchor.index < anchorAtCamera.index) {
@@ -193,6 +177,11 @@ class SnapControl extends Control {
193
177
  }
194
178
  }
195
179
 
180
+ /**
181
+ * @internal
182
+ * @privateRemarks
183
+ * Finds the adjacent anchor point based on the movement direction.
184
+ */
196
185
  private _findAdjacentAnchor(position: number, posDelta: number, anchorAtCamera: AnchorPoint): AnchorPoint {
197
186
  const flicking = getFlickingAttached(this._flicking);
198
187
  const camera = flicking.camera;
@@ -205,11 +194,17 @@ class SnapControl extends Control {
205
194
  }
206
195
  }
207
196
 
208
- const adjacentAnchor = (posDelta > 0 ? camera.getNextAnchor(anchorAtCamera) : camera.getPrevAnchor(anchorAtCamera)) ?? anchorAtCamera;
197
+ const adjacentAnchor =
198
+ (posDelta > 0 ? camera.getNextAnchor(anchorAtCamera) : camera.getPrevAnchor(anchorAtCamera)) ?? anchorAtCamera;
209
199
 
210
200
  return adjacentAnchor;
211
201
  }
212
202
 
203
+ /**
204
+ * @internal
205
+ * @privateRemarks
206
+ * Calculates the snap threshold based on the panel size and alignment.
207
+ */
213
208
  private _calcSnapThreshold(threshold: number, position: number, activeAnchor: AnchorPoint): number {
214
209
  const isNextDirection = position > activeAnchor.position;
215
210
  const panel = activeAnchor.panel;
@@ -222,9 +217,10 @@ class SnapControl extends Control {
222
217
  * |<------>|<------------>|
223
218
  * [ |<-Anchor ]
224
219
  */
225
- return Math.max(threshold, isNextDirection
226
- ? panelSize - alignPos + panel.margin.next
227
- : alignPos + panel.margin.prev);
220
+ return Math.max(
221
+ threshold,
222
+ isNextDirection ? panelSize - alignPos + panel.margin.next : alignPos + panel.margin.prev
223
+ );
228
224
  }
229
225
  }
230
226
 
@@ -3,15 +3,13 @@
3
3
  * egjs projects are licensed under the MIT license
4
4
  */
5
5
  import { AxesEvents } from "@egjs/axes";
6
-
6
+ import * as AXES from "../constants/internal";
7
7
  import Flicking from "../Flicking";
8
- import * as AXES from "../const/axes";
9
-
10
- import IdleState from "./states/IdleState";
11
- import HoldingState from "./states/HoldingState";
12
- import DraggingState from "./states/DraggingState";
13
8
  import AnimatingState from "./states/AnimatingState";
14
9
  import DisabledState from "./states/DisabledState";
10
+ import DraggingState from "./states/DraggingState";
11
+ import HoldingState from "./states/HoldingState";
12
+ import IdleState from "./states/IdleState";
15
13
  import State, { STATE_TYPE } from "./states/State";
16
14
 
17
15
  /**
@@ -20,16 +18,21 @@ import State, { STATE_TYPE } from "./states/State";
20
18
  class StateMachine {
21
19
  private _state: State;
22
20
 
23
- public get state(): State { return this._state; }
21
+ public get state(): State {
22
+ return this._state;
23
+ }
24
24
 
25
25
  public constructor() {
26
26
  this._state = new IdleState();
27
27
  }
28
28
 
29
- public fire(eventType: keyof AxesEvents, externalCtx: {
30
- flicking: Flicking;
31
- axesEvent: any;
32
- }) {
29
+ public fire(
30
+ eventType: keyof AxesEvents,
31
+ externalCtx: {
32
+ flicking: Flicking;
33
+ axesEvent: any;
34
+ }
35
+ ) {
33
36
  const currentState = this._state;
34
37
  const ctx = { ...externalCtx, transitTo: this.transitTo };
35
38
 
@@ -5,24 +5,23 @@
5
5
  import { OnRelease } from "@egjs/axes";
6
6
 
7
7
  import Panel from "../core/panel/Panel";
8
- import FlickingError from "../core/FlickingError";
8
+ import * as ERROR from "../error/codes";
9
+ import FlickingError from "../error/FlickingError";
9
10
  import { clamp, getFlickingAttached, getMinusCompensatedIndex, isBetween } from "../utils";
10
- import * as ERROR from "../const/error";
11
11
 
12
- import Control from "./Control";
12
+ import Control, { MoveToPanelParams } from "./Control";
13
13
  /**
14
- * An options for the {@link StrictControl}
15
- * @ko {@link StrictControl} 생성시 사용되는 옵션
16
- * @interface
17
- * @property {number} count Maximum number of panels that can be moved at a time<ko>최대로 움직일 수 있는 패널의 개수</ko>
14
+ * Options for the {@link StrictControl}
18
15
  */
19
16
  export interface StrictControlOptions {
17
+ /** Maximum number of panels that can be moved at a time */
20
18
  count: number;
21
19
  }
22
20
 
23
21
  /**
24
- * A {@link Control} that allow you to select the maximum number of panels to move at a time
25
- * @ko 한번에 최대로 이동할 패널의 개수를 선택 가능한 {@link Control}
22
+ * A {@link Control} that allows you to select the maximum number of panels to move at a time
23
+ * @since 4.2.0
24
+ * @public
26
25
  */
27
26
  class StrictControl extends Control {
28
27
  private _count: number;
@@ -30,28 +29,29 @@ class StrictControl extends Control {
30
29
 
31
30
  /**
32
31
  * Maximum number of panels that can be moved at a time
33
- * @ko 최대로 움직일 수 있는 패널의 개수
34
- * @type {number}
35
- * @default 1
32
+ * @defaultValue 1
36
33
  */
37
- public get count() { return this._count; }
34
+ public get count(): number {
35
+ return this._count;
36
+ }
38
37
 
39
- public set count(val: StrictControlOptions["count"]) { this._count = val; }
38
+ public set count(val: StrictControlOptions["count"]) {
39
+ this._count = val;
40
+ }
40
41
 
41
- /** */
42
- public constructor({
43
- count = 1
44
- }: Partial<StrictControlOptions> = {}) {
42
+ public constructor(options: Partial<StrictControlOptions> = {}) {
45
43
  super();
46
44
 
45
+ const { count = 1 } = options;
46
+
47
47
  this._count = count;
48
48
  this._resetIndexRange();
49
49
  }
50
50
 
51
51
  /**
52
52
  * Destroy Control and return to initial state
53
- * @ko Control을 초기 상태로 되돌립니다
54
- * @return {void}
53
+ * @remarks
54
+ * This method also resets the index range used for movement constraints.
55
55
  */
56
56
  public destroy() {
57
57
  super.destroy();
@@ -60,10 +60,10 @@ class StrictControl extends Control {
60
60
  }
61
61
 
62
62
  /**
63
- * Update {@link Control#controller controller}'s state
64
- * @ko {@link Control#controller controller}의 내부 상태를 갱신합니다
65
- * @chainable
66
- * @return {this}
63
+ * Update {@link Control.controller | controller}'s state
64
+ * @remarks
65
+ * StrictControl limits the movement range based on the {@link StrictControlOptions.count | count} option.
66
+ * @returns The current instance for method chaining
67
67
  */
68
68
  public updateInput(): this {
69
69
  const flicking = getFlickingAttached(this._flicking);
@@ -93,7 +93,7 @@ class StrictControl extends Control {
93
93
 
94
94
  if (prevPanelIndex < 0) {
95
95
  prevPanelIndex = flicking.circularEnabled
96
- ? getMinusCompensatedIndex((prevPanelIndex + 1) % panelCount - 1, panelCount)
96
+ ? getMinusCompensatedIndex(((prevPanelIndex + 1) % panelCount) - 1, panelCount)
97
97
  : clamp(prevPanelIndex, 0, panelCount - 1);
98
98
  }
99
99
  if (nextPanelIndex >= panelCount) {
@@ -141,7 +141,7 @@ class StrictControl extends Control {
141
141
  return this;
142
142
  }
143
143
 
144
- public async moveToPanel(panel: Panel, options: Parameters<Control["moveToPanel"]>[1]): Promise<void> {
144
+ public async moveToPanel(panel: Panel, options: MoveToPanelParams): Promise<void> {
145
145
  const flicking = getFlickingAttached(this._flicking);
146
146
  const camera = flicking.camera;
147
147
  const controller = this._controller;
@@ -153,41 +153,16 @@ class StrictControl extends Control {
153
153
 
154
154
  /**
155
155
  * Move {@link Camera} to the given position
156
- * @ko {@link Camera}를 주어진 좌표로 이동합니다
157
- * @param {number} position The target position to move<ko>이동할 좌표</ko>
158
- * @param {number} duration Duration of the panel movement animation (unit: ms).<ko>패널 이동 애니메이션 진행 시간 (단위: ms)</ko>
159
- * @param {object} [axesEvent] {@link https://naver.github.io/egjs-axes/release/latest/doc/eg.Axes.html#event:release release} event of {@link https://naver.github.io/egjs-axes/ Axes}
160
- * <ko>{@link https://naver.github.io/egjs-axes/ Axes} {@link https://naver.github.io/egjs-axes/release/latest/doc/eg.Axes.html#event:release release} 이벤트</ko>
161
- * @fires Flicking#moveStart
162
- * @fires Flicking#move
163
- * @fires Flicking#moveEnd
164
- * @fires Flicking#willChange
165
- * @fires Flicking#changed
166
- * @fires Flicking#willRestore
167
- * @fires Flicking#restored
168
- * @fires Flicking#needPanel
169
- * @fires Flicking#visibleChange
170
- * @fires Flicking#reachEdge
171
- * @throws {FlickingError}
172
- * |code|condition|
173
- * |---|---|
174
- * |{@link ERROR_CODE POSITION_NOT_REACHABLE}|When the given panel is already removed or not in the Camera's {@link Camera#range range}|
175
- * |{@link ERROR_CODE NOT_ATTACHED_TO_FLICKING}|When {@link Control#init init} is not called before|
176
- * |{@link ERROR_CODE ANIMATION_INTERRUPTED}|When the animation is interrupted by user input|
177
- * |{@link ERROR_CODE STOP_CALLED_BY_USER}|When the animation is interrupted by user input|
178
- * <ko>
179
- *
180
- * |code|condition|
181
- * |---|---|
182
- * |{@link ERROR_CODE POSITION_NOT_REACHABLE}|주어진 패널이 제거되었거나, Camera의 {@link Camera#range range} 밖에 있을 경우|
183
- * |{@link ERROR_CODE NOT_ATTACHED_TO_FLICKING}|{@link Control#init init}이 이전에 호출되지 않은 경우|
184
- * |{@link ERROR_CODE ANIMATION_INTERRUPTED}|사용자 입력에 의해 애니메이션이 중단된 경우|
185
- * |{@link ERROR_CODE STOP_CALLED_BY_USER}|발생된 이벤트들 중 하나라도 `stop()`이 호출된 경우|
186
- *
187
- * </ko>
188
- * @return {Promise<void>} A Promise which will be resolved after reaching the target position<ko>해당 좌표 도달시에 resolve되는 Promise</ko>
156
+ * @remarks
157
+ * StrictControl restricts movement to panels within the allowed index range based on the count option.
158
+ * @param position - The target position to move
159
+ * @param duration - Duration of the panel movement animation (unit: ms)
160
+ * @param axesEvent - {@link https://naver.github.io/egjs-axes/docs/api/Axes#event-release | release} event of {@link https://naver.github.io/egjs-axes/ | Axes}
161
+ * @fires {@link MovementEvents}
162
+ * @throws {@link MovementErrors}
163
+ * @returns A Promise which will be resolved after reaching the target position
189
164
  */
190
- public moveToPosition(position: number, duration: number, axesEvent?: OnRelease) {
165
+ public moveToPosition(position: number, duration: number, axesEvent?: OnRelease): Promise<void> {
191
166
  const flicking = getFlickingAttached(this._flicking);
192
167
  const camera = flicking.camera;
193
168
  const currentPanel = this._nextPanel ?? this._activePanel;
@@ -200,18 +175,17 @@ class StrictControl extends Control {
200
175
  const anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
201
176
 
202
177
  if (!anchorAtPosition || !currentPanel) {
203
- return Promise.reject(new FlickingError(ERROR.MESSAGE.POSITION_NOT_REACHABLE(position), ERROR.CODE.POSITION_NOT_REACHABLE));
178
+ return Promise.reject(
179
+ new FlickingError(ERROR.MESSAGE.POSITION_NOT_REACHABLE(position), ERROR.CODE.POSITION_NOT_REACHABLE)
180
+ );
204
181
  }
205
182
 
206
183
  const prevPos = currentPanel.position;
207
- const posDelta = flicking.animating
208
- ? state.delta
209
- : position - camera.position;
184
+ const posDelta = flicking.animating ? state.delta : position - camera.position;
210
185
 
211
186
  const isOverThreshold = Math.abs(posDelta) >= flicking.threshold;
212
- const adjacentAnchor = (position > prevPos)
213
- ? camera.getNextAnchor(anchorAtPosition)
214
- : camera.getPrevAnchor(anchorAtPosition);
187
+ const adjacentAnchor =
188
+ position > prevPos ? camera.getNextAnchor(anchorAtPosition) : camera.getPrevAnchor(anchorAtPosition);
215
189
 
216
190
  let targetPos: number;
217
191
  let targetPanel: Panel;
@@ -221,12 +195,16 @@ class StrictControl extends Control {
221
195
  const lastAnchor = anchors[anchors.length - 1];
222
196
 
223
197
  // position이 bounce으로 인하여 범위를 넘어가야 동작하도록 변경
224
- const shouldBounceToFirst = position < cameraRange.min && isBetween(firstAnchor.panel.index, indexRange.min, indexRange.max);
225
- const shouldBounceToLast = position > cameraRange.max && isBetween(lastAnchor.panel.index, indexRange.min, indexRange.max);
198
+ const shouldBounceToFirst =
199
+ position < cameraRange.min && isBetween(firstAnchor.panel.index, indexRange.min, indexRange.max);
200
+ const shouldBounceToLast =
201
+ position > cameraRange.max && isBetween(lastAnchor.panel.index, indexRange.min, indexRange.max);
226
202
 
227
- const isAdjacent = adjacentAnchor && (indexRange.min <= indexRange.max
228
- ? isBetween(adjacentAnchor.index, indexRange.min, indexRange.max)
229
- : adjacentAnchor.index >= indexRange.min || adjacentAnchor.index <= indexRange.max);
203
+ const isAdjacent =
204
+ adjacentAnchor &&
205
+ (indexRange.min <= indexRange.max
206
+ ? isBetween(adjacentAnchor.index, indexRange.min, indexRange.max)
207
+ : adjacentAnchor.index >= indexRange.min || adjacentAnchor.index <= indexRange.max);
230
208
 
231
209
  if (shouldBounceToFirst || shouldBounceToLast) {
232
210
  // In bounce area
@@ -246,7 +224,9 @@ class StrictControl extends Control {
246
224
  // Fallback to nearest panel from current camera
247
225
  const anchorAtCamera = camera.findNearestAnchor(camera.position);
248
226
  if (!anchorAtCamera) {
249
- return Promise.reject(new FlickingError(ERROR.MESSAGE.POSITION_NOT_REACHABLE(position), ERROR.CODE.POSITION_NOT_REACHABLE));
227
+ return Promise.reject(
228
+ new FlickingError(ERROR.MESSAGE.POSITION_NOT_REACHABLE(position), ERROR.CODE.POSITION_NOT_REACHABLE)
229
+ );
250
230
  }
251
231
  return this.moveToPanel(anchorAtCamera.panel, {
252
232
  duration,
@@ -269,6 +249,11 @@ class StrictControl extends Control {
269
249
  this.updateInput();
270
250
  };
271
251
 
252
+ /**
253
+ * @internal
254
+ * @privateRemarks
255
+ * Resets the index range to default values.
256
+ */
272
257
  private _resetIndexRange() {
273
258
  this._indexRange = { min: 0, max: 0 };
274
259
  }
@@ -2,18 +2,19 @@
2
2
  * Copyright (c) 2015 NAVER Corp.
3
3
  * egjs projects are licensed under the MIT license
4
4
  */
5
+
6
+ import AxesController from "./AxesController";
5
7
  import Control from "./Control";
6
- import SnapControl, { SnapControlOptions } from "./SnapControl";
7
8
  import FreeControl, { FreeControlOptions } from "./FreeControl";
9
+ import SnapControl, { SnapControlOptions } from "./SnapControl";
10
+ import StateMachine from "./StateMachine";
8
11
  import StrictControl, { StrictControlOptions } from "./StrictControl";
9
- import AxesController from "./AxesController";
10
- import State from "./states/State";
11
- import IdleState from "./states/IdleState";
12
- import HoldingState from "./states/HoldingState";
13
- import DraggingState from "./states/DraggingState";
14
12
  import AnimatingState from "./states/AnimatingState";
15
13
  import DisabledState from "./states/DisabledState";
16
- import StateMachine from "./StateMachine";
14
+ import DraggingState from "./states/DraggingState";
15
+ import HoldingState from "./states/HoldingState";
16
+ import IdleState from "./states/IdleState";
17
+ import State from "./states/State";
17
18
 
18
19
  export {
19
20
  Control,
@@ -30,8 +31,4 @@ export {
30
31
  StateMachine
31
32
  };
32
33
 
33
- export type {
34
- SnapControlOptions,
35
- FreeControlOptions,
36
- StrictControlOptions
37
- };
34
+ export type { SnapControlOptions, FreeControlOptions, StrictControlOptions };
@@ -4,28 +4,23 @@
4
4
  */
5
5
  import { ComponentEvent } from "@egjs/component";
6
6
 
7
- import { EVENTS } from "../../const/external";
7
+ import { EVENTS } from "../../event/names";
8
8
  import { getDirection } from "../../utils";
9
9
 
10
10
  import State, { STATE_TYPE } from "./State";
11
11
 
12
12
  /**
13
13
  * A state that activates when Flicking's animating by user input or method call
14
- * @ko 사용자 입력이나 메소드 호출에 의해 Flicking의 애니메이션이 동작중인 상태
15
14
  * @internal
16
15
  */
17
16
  class AnimatingState extends State {
18
17
  /**
19
18
  * Whether user is clicking or touching
20
- * @ko 현재 사용자가 클릭/터치중인지 여부
21
- * @type {false}
22
19
  * @readonly
23
20
  */
24
21
  public readonly holding = false;
25
22
  /**
26
23
  * Whether Flicking's animating
27
- * @ko 현재 애니메이션 동작 여부
28
- * @type {true}
29
24
  * @readonly
30
25
  */
31
26
  public readonly animating = true;
@@ -65,11 +60,13 @@ class AnimatingState extends State {
65
60
 
66
61
  transitTo(STATE_TYPE.IDLE);
67
62
 
68
- flicking.trigger(new ComponentEvent(EVENTS.MOVE_END, {
69
- isTrusted: axesEvent.isTrusted,
70
- direction: getDirection(animatingContext.start, animatingContext.end),
71
- axesEvent
72
- }));
63
+ flicking.trigger(
64
+ new ComponentEvent(EVENTS.MOVE_END, {
65
+ isTrusted: axesEvent.isTrusted,
66
+ direction: getDirection(animatingContext.start, animatingContext.end),
67
+ axesEvent
68
+ })
69
+ );
73
70
 
74
71
  const targetPanel = this._targetPanel;
75
72
  if (targetPanel) {
@@ -6,21 +6,16 @@ import State, { STATE_TYPE } from "./State";
6
6
 
7
7
  /**
8
8
  * A state that activates when Flicking is stopped by event's `stop` method
9
- * @ko 이벤트의 `stop`호출에 의해 Flicking이 정지된 상태
10
9
  * @internal
11
10
  */
12
11
  class DisabledState extends State {
13
12
  /**
14
13
  * Whether user is clicking or touching
15
- * @ko 현재 사용자가 클릭/터치중인지 여부
16
- * @type {false}
17
14
  * @readonly
18
15
  */
19
16
  public readonly holding = false;
20
17
  /**
21
18
  * Whether Flicking's animating
22
- * @ko 현재 애니메이션 동작 여부
23
- * @type {true}
24
19
  * @readonly
25
20
  */
26
21
  public readonly animating = true;
@@ -3,29 +3,23 @@
3
3
  * egjs projects are licensed under the MIT license
4
4
  */
5
5
  import { ComponentEvent } from "@egjs/component";
6
-
7
- import { EVENTS } from "../../const/external";
8
- import * as AXES from "../../const/axes";
6
+ import * as AXES from "../../constants/internal";
7
+ import { EVENTS } from "../../event/names";
9
8
 
10
9
  import State, { STATE_TYPE } from "./State";
11
10
 
12
11
  /**
13
12
  * A state that activates when user's dragging the Flicking area
14
- * @ko 사용자가 드래깅중인 상태
15
13
  * @internal
16
14
  */
17
15
  class DraggingState extends State {
18
16
  /**
19
17
  * Whether user is clicking or touching
20
- * @ko 현재 사용자가 클릭/터치중인지 여부
21
- * @type {true}
22
18
  * @readonly
23
19
  */
24
20
  public readonly holding = true;
25
21
  /**
26
22
  * Whether Flicking's animating
27
- * @ko 현재 애니메이션 동작 여부
28
- * @type {true}
29
23
  * @readonly
30
24
  */
31
25
  public readonly animating = true;
@@ -39,9 +33,11 @@ class DraggingState extends State {
39
33
 
40
34
  // Update last position to cope with Axes's animating behavior
41
35
  // Axes uses start position when animation start
42
- flicking.trigger(new ComponentEvent(EVENTS.HOLD_END, {
43
- axesEvent
44
- }));
36
+ flicking.trigger(
37
+ new ComponentEvent(EVENTS.HOLD_END, {
38
+ axesEvent
39
+ })
40
+ );
45
41
 
46
42
  if (flicking.renderer.panelCount <= 0) {
47
43
  // There're no panels
@@ -57,7 +53,7 @@ class DraggingState extends State {
57
53
 
58
54
  try {
59
55
  void control.moveToPosition(position, duration, axesEvent);
60
- } catch (err) {
56
+ } catch (_err) {
61
57
  transitTo(STATE_TYPE.IDLE);
62
58
  axesEvent.setTo({ [AXES.POSITION_KEY]: flicking.camera.position }, 0);
63
59
  }