@egjs/flicking 4.6.2 → 4.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/declaration/camera/mode/CameraMode.d.ts +1 -0
- package/declaration/camera/mode/CircularCameraMode.d.ts +1 -0
- package/dist/flicking.esm.js +48 -21
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.js +48 -21
- package/dist/flicking.js.map +1 -1
- package/dist/flicking.min.js +2 -2
- package/dist/flicking.min.js.map +1 -1
- package/dist/flicking.pkgd.js +48 -21
- package/dist/flicking.pkgd.js.map +1 -1
- package/dist/flicking.pkgd.min.js +2 -2
- package/dist/flicking.pkgd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/camera/Camera.ts +1 -19
- package/src/camera/mode/CameraMode.ts +22 -0
- package/src/camera/mode/CircularCameraMode.ts +27 -0
- package/src/control/StrictControl.ts +7 -3
package/package.json
CHANGED
package/src/camera/Camera.ts
CHANGED
|
@@ -383,25 +383,7 @@ class Camera {
|
|
|
383
383
|
* @return {AnchorPoint | null} The {@link AnchorPoint} nearest to the given position<ko>해당 좌표에 가장 인접한 {@link AnchorPoint}</ko>
|
|
384
384
|
*/
|
|
385
385
|
public findNearestAnchor(position: number): AnchorPoint | null {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
if (anchors.length <= 0) return null;
|
|
389
|
-
|
|
390
|
-
let prevDist = Infinity;
|
|
391
|
-
for (let anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
|
|
392
|
-
const anchor = anchors[anchorIdx];
|
|
393
|
-
const dist = Math.abs(anchor.position - position);
|
|
394
|
-
|
|
395
|
-
if (dist > prevDist) {
|
|
396
|
-
// Return previous anchor
|
|
397
|
-
return anchors[anchorIdx - 1];
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
prevDist = dist;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
// Return last anchor
|
|
404
|
-
return anchors[anchors.length - 1];
|
|
386
|
+
return this._mode.findNearestAnchor(position);
|
|
405
387
|
}
|
|
406
388
|
|
|
407
389
|
/**
|
|
@@ -44,6 +44,28 @@ abstract class CameraMode {
|
|
|
44
44
|
}, null);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
public findNearestAnchor(position: number): AnchorPoint | null {
|
|
48
|
+
const anchors = this._flicking.camera.anchorPoints;
|
|
49
|
+
|
|
50
|
+
if (anchors.length <= 0) return null;
|
|
51
|
+
|
|
52
|
+
let prevDist = Infinity;
|
|
53
|
+
for (let anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
|
|
54
|
+
const anchor = anchors[anchorIdx];
|
|
55
|
+
const dist = Math.abs(anchor.position - position);
|
|
56
|
+
|
|
57
|
+
if (dist > prevDist) {
|
|
58
|
+
// Return previous anchor
|
|
59
|
+
return anchors[anchorIdx - 1];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
prevDist = dist;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Return last anchor
|
|
66
|
+
return anchors[anchors.length - 1];
|
|
67
|
+
}
|
|
68
|
+
|
|
47
69
|
public clampToReachablePosition(position: number): number {
|
|
48
70
|
const camera = this._flicking.camera;
|
|
49
71
|
const range = camera.range;
|
|
@@ -64,6 +64,33 @@ class CircularCameraMode extends CameraMode {
|
|
|
64
64
|
}));
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
public findNearestAnchor(position: number): AnchorPoint | null {
|
|
68
|
+
const camera = this._flicking.camera;
|
|
69
|
+
const anchors = camera.anchorPoints;
|
|
70
|
+
|
|
71
|
+
if (anchors.length <= 0) return null;
|
|
72
|
+
|
|
73
|
+
const camRange = camera.range;
|
|
74
|
+
let minDist = Infinity;
|
|
75
|
+
let minDistIndex = -1;
|
|
76
|
+
for (let anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
|
|
77
|
+
const anchor = anchors[anchorIdx];
|
|
78
|
+
const dist = Math.min(
|
|
79
|
+
Math.abs(anchor.position - position),
|
|
80
|
+
Math.abs(anchor.position - camRange.min + camRange.max - position),
|
|
81
|
+
Math.abs(position - camRange.min + camRange.max - anchor.position)
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (dist < minDist) {
|
|
85
|
+
minDist = dist;
|
|
86
|
+
minDistIndex = anchorIdx;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Return last anchor
|
|
91
|
+
return anchors[minDistIndex];
|
|
92
|
+
}
|
|
93
|
+
|
|
67
94
|
public findAnchorIncludePosition(position: number): AnchorPoint | null {
|
|
68
95
|
const camera = this._flicking.camera;
|
|
69
96
|
const range = camera.range;
|
|
@@ -219,6 +219,10 @@ class StrictControl extends Control {
|
|
|
219
219
|
const shouldBounceToFirst = position <= cameraRange.min && isBetween(firstAnchor.panel.index, indexRange.min, indexRange.max);
|
|
220
220
|
const shouldBounceToLast = position >= cameraRange.max && isBetween(lastAnchor.panel.index, indexRange.min, indexRange.max);
|
|
221
221
|
|
|
222
|
+
const isAdjacent = adjacentAnchor && (indexRange.min <= indexRange.max
|
|
223
|
+
? isBetween(adjacentAnchor.index, indexRange.min, indexRange.max)
|
|
224
|
+
: adjacentAnchor.index >= indexRange.min || adjacentAnchor.index <= indexRange.max);
|
|
225
|
+
|
|
222
226
|
if (shouldBounceToFirst || shouldBounceToLast) {
|
|
223
227
|
// In bounce area
|
|
224
228
|
const targetAnchor = position < cameraRange.min ? firstAnchor : lastAnchor;
|
|
@@ -229,10 +233,10 @@ class StrictControl extends Control {
|
|
|
229
233
|
// Move to anchor at position
|
|
230
234
|
targetPanel = anchorAtPosition.panel;
|
|
231
235
|
targetPos = anchorAtPosition.position;
|
|
232
|
-
} else if (isOverThreshold &&
|
|
236
|
+
} else if (isOverThreshold && isAdjacent) {
|
|
233
237
|
// Move to adjacent anchor
|
|
234
|
-
targetPanel = adjacentAnchor
|
|
235
|
-
targetPos = adjacentAnchor
|
|
238
|
+
targetPanel = adjacentAnchor!.panel;
|
|
239
|
+
targetPos = adjacentAnchor!.position;
|
|
236
240
|
} else {
|
|
237
241
|
// Restore to active panel
|
|
238
242
|
targetPos = camera.clampToReachablePosition(activePanel.position);
|