@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.
- package/README.md +6 -175
- package/{declaration → dist}/CrossFlicking.d.ts +7 -2
- package/dist/Flicking.d.ts +1231 -0
- package/dist/camera/Camera.d.ts +324 -0
- package/{declaration → dist}/camera/mode/BoundCameraMode.d.ts +5 -4
- package/{declaration → dist}/camera/mode/CameraMode.d.ts +7 -6
- package/{declaration → dist}/camera/mode/CircularCameraMode.d.ts +9 -5
- package/{declaration → dist}/camera/mode/LinearCameraMode.d.ts +2 -4
- package/{declaration → dist}/cfc/getDefaultCameraTransform.d.ts +1 -1
- package/dist/cfc/withFlickingMethods.d.ts +15 -0
- package/{declaration/const/axes.d.ts → dist/constants/internal.d.ts} +8 -0
- package/dist/constants/values.d.ts +67 -0
- package/dist/control/AxesController.d.ts +186 -0
- package/dist/control/Control.d.ts +185 -0
- package/dist/control/FreeControl.d.ts +44 -0
- package/dist/control/SnapControl.d.ts +54 -0
- package/{declaration → dist}/control/StateMachine.d.ts +3 -0
- package/dist/control/StrictControl.d.ts +60 -0
- package/{declaration → dist}/control/states/AnimatingState.d.ts +12 -0
- package/{declaration → dist}/control/states/DisabledState.d.ts +12 -0
- package/{declaration → dist}/control/states/DraggingState.d.ts +12 -0
- package/{declaration → dist}/control/states/HoldingState.d.ts +12 -0
- package/{declaration → dist}/control/states/IdleState.d.ts +12 -0
- package/dist/control/states/State.d.ts +86 -0
- package/dist/core/AnchorPoint.d.ts +40 -0
- package/{declaration → dist}/core/AutoResizer.d.ts +6 -0
- package/dist/core/Viewport.d.ts +60 -0
- package/dist/core/VirtualManager.d.ts +84 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/panel/Panel.d.ts +298 -0
- package/dist/core/panel/VirtualPanel.d.ts +41 -0
- package/dist/core/panel/index.d.ts +5 -0
- package/{declaration → dist}/core/panel/provider/VanillaElementProvider.d.ts +3 -0
- package/{declaration → dist}/core/panel/provider/VirtualElementProvider.d.ts +3 -0
- package/dist/error/FlickingError.d.ts +25 -0
- package/dist/error/codes.d.ts +79 -0
- package/dist/error/groups.d.ts +94 -0
- package/dist/error/index.d.ts +4 -0
- package/dist/error/types.d.ts +516 -0
- package/dist/event/groups.d.ts +40 -0
- package/dist/event/index.d.ts +3 -0
- package/dist/event/names.d.ts +47 -0
- package/dist/event/types.d.ts +318 -0
- package/dist/flicking.cjs.js +5559 -7791
- package/dist/flicking.cjs.js.map +1 -1
- package/dist/flicking.esm.js +5637 -7699
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.js +6722 -8893
- package/dist/flicking.js.map +1 -1
- package/dist/flicking.min.js +1 -9
- package/dist/flicking.min.js.map +1 -1
- package/dist/flicking.pkgd.js +9661 -14086
- package/dist/flicking.pkgd.js.map +1 -1
- package/dist/flicking.pkgd.min.js +1 -9
- package/dist/flicking.pkgd.min.js.map +1 -1
- package/dist/index.d.ts +16 -0
- package/dist/reactive/index.d.ts +126 -0
- package/{declaration → dist}/renderer/ExternalRenderer.d.ts +3 -0
- package/dist/renderer/Renderer.d.ts +215 -0
- package/{declaration → dist}/renderer/VanillaRenderer.d.ts +6 -0
- package/{declaration → dist}/renderer/strategy/NormalRenderingStrategy.d.ts +5 -2
- package/{declaration → dist}/renderer/strategy/RenderingStrategy.d.ts +4 -1
- package/dist/types/external.d.ts +58 -0
- package/dist/types/params.d.ts +10 -0
- package/{declaration → dist}/utils.d.ts +7 -7
- package/package.json +35 -162
- package/src/CrossFlicking.ts +68 -96
- package/src/Flicking.ts +1051 -972
- package/src/camera/Camera.ts +217 -206
- package/src/camera/index.ts +2 -6
- package/src/camera/mode/BoundCameraMode.ts +38 -27
- package/src/camera/mode/CameraMode.ts +14 -12
- package/src/camera/mode/CircularCameraMode.ts +24 -16
- package/src/camera/mode/LinearCameraMode.ts +3 -1
- package/src/camera/mode/index.ts +4 -10
- package/src/cfc/getDefaultCameraTransform.ts +9 -11
- package/src/cfc/getRenderingPanels.ts +2 -4
- package/src/cfc/index.ts +4 -9
- package/src/cfc/sync.ts +11 -5
- package/src/cfc/withFlickingMethods.ts +6 -7
- package/src/{const/axes.ts → constants/internal.ts} +1 -0
- package/src/constants/values.ts +78 -0
- package/src/control/AxesController.ts +119 -110
- package/src/control/Control.ts +147 -180
- package/src/control/FreeControl.ts +36 -60
- package/src/control/SnapControl.ts +64 -68
- package/src/control/StateMachine.ts +14 -11
- package/src/control/StrictControl.ts +58 -73
- package/src/control/index.ts +9 -12
- package/src/control/states/AnimatingState.ts +8 -11
- package/src/control/states/DisabledState.ts +0 -5
- package/src/control/states/DraggingState.ts +8 -12
- package/src/control/states/HoldingState.ts +10 -15
- package/src/control/states/IdleState.ts +1 -6
- package/src/control/states/State.ts +46 -85
- package/src/core/AnchorPoint.ts +25 -23
- package/src/core/AutoResizer.ts +6 -15
- package/src/core/ResizeWatcher.ts +17 -16
- package/src/core/Viewport.ts +35 -46
- package/src/core/VirtualManager.ts +48 -36
- package/src/core/index.ts +6 -9
- package/src/core/panel/Panel.ts +190 -185
- package/src/core/panel/VirtualPanel.ts +17 -21
- package/src/core/panel/index.ts +4 -9
- package/src/core/panel/provider/VanillaElementProvider.ts +6 -2
- package/src/core/panel/provider/VirtualElementProvider.ts +6 -2
- package/src/core/panel/provider/index.ts +2 -7
- package/src/{core → error}/FlickingError.ts +5 -7
- package/src/error/codes.ts +164 -0
- package/src/error/groups.ts +124 -0
- package/src/error/index.ts +9 -0
- package/src/error/types.ts +535 -0
- package/src/event/groups.ts +61 -0
- package/src/event/index.ts +8 -0
- package/src/event/names.ts +52 -0
- package/src/event/types.ts +355 -0
- package/src/index.ts +9 -11
- package/src/index.umd.ts +9 -3
- package/src/reactive/index.ts +39 -74
- package/src/renderer/Renderer.ts +170 -115
- package/src/renderer/VanillaRenderer.ts +12 -9
- package/src/renderer/index.ts +4 -9
- package/src/renderer/strategy/NormalRenderingStrategy.ts +26 -22
- package/src/renderer/strategy/RenderingStrategy.ts +2 -1
- package/src/renderer/strategy/VirtualRenderingStrategy.ts +20 -13
- package/src/renderer/strategy/index.ts +4 -9
- package/src/types/external.ts +72 -0
- package/src/{type → types}/internal.ts +2 -5
- package/src/types/params.ts +15 -0
- package/src/utils.ts +37 -32
- package/CONTRIBUTING.md +0 -59
- package/NOTICE +0 -31
- package/core-packages-link.js +0 -75
- package/debug/reactive/index.html +0 -240
- package/declaration/Flicking.d.ts +0 -264
- package/declaration/camera/Camera.d.ts +0 -90
- package/declaration/cfc/withFlickingMethods.d.ts +0 -2
- package/declaration/const/error.d.ts +0 -34
- package/declaration/const/external.d.ts +0 -54
- package/declaration/control/AxesController.d.ts +0 -45
- package/declaration/control/Control.d.ts +0 -45
- package/declaration/control/FreeControl.d.ts +0 -14
- package/declaration/control/SnapControl.d.ts +0 -16
- package/declaration/control/StrictControl.d.ts +0 -20
- package/declaration/control/states/State.d.ts +0 -47
- package/declaration/core/AnchorPoint.d.ts +0 -15
- package/declaration/core/FlickingError.d.ts +0 -5
- package/declaration/core/Viewport.d.ts +0 -25
- package/declaration/core/VirtualManager.d.ts +0 -37
- package/declaration/core/index.d.ts +0 -6
- package/declaration/core/panel/Panel.d.ts +0 -89
- package/declaration/core/panel/VirtualPanel.d.ts +0 -19
- package/declaration/core/panel/index.d.ts +0 -5
- package/declaration/index.d.ts +0 -16
- package/declaration/reactive/index.d.ts +0 -25
- package/declaration/renderer/Renderer.d.ts +0 -60
- package/declaration/type/event.d.ts +0 -88
- package/declaration/type/external.d.ts +0 -31
- package/jsconfig.json +0 -5
- package/jsdoc-to-mdx.json +0 -7
- package/rollup.config.demo.js +0 -24
- package/rollup.config.dev.js +0 -12
- package/rollup.config.js +0 -57
- package/src/const/error.ts +0 -64
- package/src/const/external.ts +0 -138
- package/src/type/event.ts +0 -315
- package/src/type/external.ts +0 -78
- package/tsconfig.declaration.json +0 -17
- package/tsconfig.eslint.json +0 -10
- package/tsconfig.json +0 -23
- package/{declaration → dist}/camera/index.d.ts +0 -0
- package/{declaration → dist}/camera/mode/index.d.ts +2 -2
- package/{declaration → dist}/cfc/getRenderingPanels.d.ts +0 -0
- package/{declaration → dist}/cfc/index.d.ts +3 -3
- package/{declaration → dist}/cfc/sync.d.ts +0 -0
- package/{declaration → dist}/control/index.d.ts +7 -7
- package/{declaration → dist}/core/ResizeWatcher.d.ts +0 -0
- package/{declaration → dist}/core/panel/provider/ElementProvider.d.ts +0 -0
- package/{declaration → dist}/core/panel/provider/index.d.ts +0 -0
- package/{declaration → dist}/index.cjs.d.ts +0 -0
- package/{declaration → dist}/index.umd.d.ts +0 -0
- package/{declaration → dist}/renderer/index.d.ts +1 -1
- package/{declaration → dist}/renderer/strategy/VirtualRenderingStrategy.d.ts +1 -1
- package/{declaration → dist}/renderer/strategy/index.d.ts +1 -1
- /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
|
-
*
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
35
|
-
* @type {number}
|
|
36
|
-
* @default Infinity
|
|
31
|
+
* @defaultValue Infinity
|
|
37
32
|
*/
|
|
38
|
-
public get count() {
|
|
33
|
+
public get count(): number {
|
|
34
|
+
return this._count;
|
|
35
|
+
}
|
|
39
36
|
|
|
40
|
-
public set count(val: SnapControlOptions["count"]) {
|
|
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
|
-
* @
|
|
54
|
-
*
|
|
55
|
-
* @param
|
|
56
|
-
* @param
|
|
57
|
-
*
|
|
58
|
-
* @fires
|
|
59
|
-
* @
|
|
60
|
-
* @
|
|
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(
|
|
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 =
|
|
105
|
-
|
|
106
|
-
|
|
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 (
|
|
156
|
-
|
|
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 (
|
|
159
|
-
|
|
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 =
|
|
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 =
|
|
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(
|
|
226
|
-
|
|
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 {
|
|
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(
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
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
|
-
*
|
|
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
|
|
25
|
-
* @
|
|
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
|
-
* @
|
|
34
|
-
* @type {number}
|
|
35
|
-
* @default 1
|
|
32
|
+
* @defaultValue 1
|
|
36
33
|
*/
|
|
37
|
-
public get count() {
|
|
34
|
+
public get count(): number {
|
|
35
|
+
return this._count;
|
|
36
|
+
}
|
|
38
37
|
|
|
39
|
-
public set count(val: StrictControlOptions["count"]) {
|
|
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
|
-
* @
|
|
54
|
-
*
|
|
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
|
|
64
|
-
* @
|
|
65
|
-
* @
|
|
66
|
-
* @
|
|
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:
|
|
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
|
-
* @
|
|
157
|
-
*
|
|
158
|
-
* @param
|
|
159
|
-
* @param
|
|
160
|
-
*
|
|
161
|
-
* @fires
|
|
162
|
-
* @
|
|
163
|
-
* @
|
|
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(
|
|
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 =
|
|
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 =
|
|
225
|
-
|
|
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 =
|
|
228
|
-
|
|
229
|
-
|
|
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(
|
|
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
|
}
|
package/src/control/index.ts
CHANGED
|
@@ -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
|
|
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 "../../
|
|
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(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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 "../../
|
|
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(
|
|
43
|
-
|
|
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 (
|
|
56
|
+
} catch (_err) {
|
|
61
57
|
transitTo(STATE_TYPE.IDLE);
|
|
62
58
|
axesEvent.setTo({ [AXES.POSITION_KEY]: flicking.camera.position }, 0);
|
|
63
59
|
}
|