@egjs/flicking 4.12.1-beta.3 → 4.12.1-beta.4
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/Flicking.d.ts +2 -3
- package/declaration/control/Control.d.ts +1 -1
- package/dist/flicking.cjs.js +20 -45
- package/dist/flicking.cjs.js.map +1 -1
- package/dist/flicking.esm.js +20 -45
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.js +20 -45
- 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 +38 -48
- 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 +2 -2
- package/src/Flicking.ts +200 -449
- package/src/control/Control.ts +1 -1
- package/src/control/SnapControl.ts +12 -6
- package/src/core/AutoResizer.ts +11 -40
- package/debug/example/index.html +0 -82
package/src/control/Control.ts
CHANGED
|
@@ -397,7 +397,7 @@ abstract class Control {
|
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
399
|
|
|
400
|
-
|
|
400
|
+
protected _getPosition(panel: Panel, direction: ValueOf<typeof DIRECTION> = DIRECTION.NONE) {
|
|
401
401
|
const flicking = getFlickingAttached(this._flicking);
|
|
402
402
|
const camera = flicking.camera;
|
|
403
403
|
|
|
@@ -9,6 +9,7 @@ import AnchorPoint from "../core/AnchorPoint";
|
|
|
9
9
|
import { circulateIndex, clamp, getFlickingAttached } from "../utils";
|
|
10
10
|
import * as AXES from "../const/axes";
|
|
11
11
|
import * as ERROR from "../const/error";
|
|
12
|
+
import { DIRECTION } from "../const/external";
|
|
12
13
|
|
|
13
14
|
import Control from "./Control";
|
|
14
15
|
|
|
@@ -109,7 +110,7 @@ class SnapControl extends Control {
|
|
|
109
110
|
if (snapDelta >= snapThreshold && snapDelta > 0) {
|
|
110
111
|
// Move to anchor at position
|
|
111
112
|
targetAnchor = this._findSnappedAnchor(position, anchorAtCamera);
|
|
112
|
-
} else if (absPosDelta >= flicking.threshold && absPosDelta > 0) {
|
|
113
|
+
} else if (absPosDelta >= flicking.threshold && absPosDelta > 0 && anchorAtCamera === activeAnchor) {
|
|
113
114
|
// Move to the adjacent panel
|
|
114
115
|
targetAnchor = this._findAdjacentAnchor(position, posDelta, anchorAtCamera);
|
|
115
116
|
} else {
|
|
@@ -120,12 +121,16 @@ class SnapControl extends Control {
|
|
|
120
121
|
});
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
|
|
124
|
+
const nextPanel = targetAnchor.panel;
|
|
125
|
+
const direction = (posDelta === 0 || activeAnchor === targetAnchor) ? DIRECTION.NONE : (posDelta > 0 ? DIRECTION.NEXT : DIRECTION.PREV);
|
|
126
|
+
const nextPosition = this._getPosition(nextPanel, direction);
|
|
127
|
+
|
|
128
|
+
this._triggerIndexChangeEvent(nextPanel, position, axesEvent);
|
|
124
129
|
|
|
125
130
|
return this._animateToPosition({
|
|
126
|
-
position: camera.clampToReachablePosition(
|
|
131
|
+
position: camera.clampToReachablePosition(nextPosition),
|
|
127
132
|
duration,
|
|
128
|
-
newActivePanel:
|
|
133
|
+
newActivePanel: nextPanel,
|
|
129
134
|
axesEvent
|
|
130
135
|
});
|
|
131
136
|
}
|
|
@@ -138,14 +143,15 @@ class SnapControl extends Control {
|
|
|
138
143
|
const currentPos = camera.position;
|
|
139
144
|
|
|
140
145
|
const clampedPosition = camera.clampToReachablePosition(position);
|
|
146
|
+
const nearestAnchor = camera.findNearestAnchor(clampedPosition);
|
|
141
147
|
const anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
|
|
142
148
|
|
|
143
|
-
if (!anchorAtCamera || !anchorAtPosition) {
|
|
149
|
+
if (!anchorAtCamera || !anchorAtPosition || !nearestAnchor) {
|
|
144
150
|
throw new FlickingError(ERROR.MESSAGE.POSITION_NOT_REACHABLE(position), ERROR.CODE.POSITION_NOT_REACHABLE);
|
|
145
151
|
}
|
|
146
152
|
|
|
147
153
|
if (!isFinite(count)) {
|
|
148
|
-
return
|
|
154
|
+
return nearestAnchor;
|
|
149
155
|
}
|
|
150
156
|
|
|
151
157
|
const panelCount = flicking.panelCount;
|
package/src/core/AutoResizer.ts
CHANGED
|
@@ -11,9 +11,7 @@ class AutoResizer {
|
|
|
11
11
|
private _resizeTimer: number;
|
|
12
12
|
private _maxResizeDebounceTimer: number;
|
|
13
13
|
|
|
14
|
-
public get enabled() {
|
|
15
|
-
return this._enabled;
|
|
16
|
-
}
|
|
14
|
+
public get enabled() { return this._enabled; }
|
|
17
15
|
|
|
18
16
|
public constructor(flicking: Flicking) {
|
|
19
17
|
this._flicking = flicking;
|
|
@@ -35,14 +33,14 @@ class AutoResizer {
|
|
|
35
33
|
const viewportSizeNot0 = viewport.width !== 0 || viewport.height !== 0;
|
|
36
34
|
|
|
37
35
|
const resizeObserver = viewportSizeNot0
|
|
38
|
-
? new ResizeObserver(
|
|
39
|
-
: new ResizeObserver(
|
|
36
|
+
? new ResizeObserver(this._skipFirstResize)
|
|
37
|
+
: new ResizeObserver(this._onResize);
|
|
40
38
|
|
|
41
39
|
resizeObserver.observe(flicking.viewport.element);
|
|
42
40
|
|
|
43
41
|
this._resizeObserver = resizeObserver;
|
|
44
42
|
} else {
|
|
45
|
-
window.addEventListener("resize",
|
|
43
|
+
window.addEventListener("resize", this._onResize);
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
this._enabled = true;
|
|
@@ -58,7 +56,7 @@ class AutoResizer {
|
|
|
58
56
|
resizeObserver.disconnect();
|
|
59
57
|
this._resizeObserver = null;
|
|
60
58
|
} else {
|
|
61
|
-
window.removeEventListener("resize",
|
|
59
|
+
window.removeEventListener("resize", this._onResize);
|
|
62
60
|
}
|
|
63
61
|
|
|
64
62
|
this._enabled = false;
|
|
@@ -66,41 +64,17 @@ class AutoResizer {
|
|
|
66
64
|
return this;
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
private _onResize = (
|
|
67
|
+
private _onResize = () => {
|
|
70
68
|
const flicking = this._flicking;
|
|
71
69
|
const resizeDebounce = flicking.resizeDebounce;
|
|
72
70
|
const maxResizeDebounce = flicking.maxResizeDebounce;
|
|
73
71
|
|
|
74
|
-
if (entries.length) {
|
|
75
|
-
const resizeEntryInfo = entries[0].contentRect;
|
|
76
|
-
const beforeSize = {
|
|
77
|
-
width: flicking.viewport.width,
|
|
78
|
-
height: flicking.viewport.height
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const afterSize = {
|
|
82
|
-
width: resizeEntryInfo.width,
|
|
83
|
-
height: resizeEntryInfo.height
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// resize 이벤트가 발생했으나 이전과 width, height의 변화가 없다면 이후 로직을 진행하지 않는다.
|
|
87
|
-
if (
|
|
88
|
-
beforeSize.height === afterSize.height &&
|
|
89
|
-
beforeSize.width === afterSize.width
|
|
90
|
-
) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
72
|
if (resizeDebounce <= 0) {
|
|
96
73
|
void flicking.resize();
|
|
97
74
|
} else {
|
|
98
75
|
if (this._maxResizeDebounceTimer <= 0) {
|
|
99
76
|
if (maxResizeDebounce > 0 && maxResizeDebounce >= resizeDebounce) {
|
|
100
|
-
this._maxResizeDebounceTimer = window.setTimeout(
|
|
101
|
-
this._doScheduledResize,
|
|
102
|
-
maxResizeDebounce
|
|
103
|
-
);
|
|
77
|
+
this._maxResizeDebounceTimer = window.setTimeout(this._doScheduledResize, maxResizeDebounce);
|
|
104
78
|
}
|
|
105
79
|
}
|
|
106
80
|
|
|
@@ -109,10 +83,7 @@ class AutoResizer {
|
|
|
109
83
|
this._resizeTimer = 0;
|
|
110
84
|
}
|
|
111
85
|
|
|
112
|
-
this._resizeTimer = window.setTimeout(
|
|
113
|
-
this._doScheduledResize,
|
|
114
|
-
resizeDebounce
|
|
115
|
-
);
|
|
86
|
+
this._resizeTimer = window.setTimeout(this._doScheduledResize, resizeDebounce);
|
|
116
87
|
}
|
|
117
88
|
};
|
|
118
89
|
|
|
@@ -130,13 +101,13 @@ class AutoResizer {
|
|
|
130
101
|
private _skipFirstResize = (() => {
|
|
131
102
|
let isFirstResize = true;
|
|
132
103
|
|
|
133
|
-
return (
|
|
104
|
+
return (() => {
|
|
134
105
|
if (isFirstResize) {
|
|
135
106
|
isFirstResize = false;
|
|
136
107
|
return;
|
|
137
108
|
}
|
|
138
|
-
this._onResize(
|
|
139
|
-
};
|
|
109
|
+
this._onResize();
|
|
110
|
+
});
|
|
140
111
|
})();
|
|
141
112
|
}
|
|
142
113
|
|
package/debug/example/index.html
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<title>Flicking Basic Demo</title>
|
|
7
|
-
<link rel="stylesheet" href="../../dist/flicking.css" />
|
|
8
|
-
<style>
|
|
9
|
-
.flicking-viewport {
|
|
10
|
-
width: 500px;
|
|
11
|
-
height: 300px;
|
|
12
|
-
margin: 0 auto;
|
|
13
|
-
}
|
|
14
|
-
.panel {
|
|
15
|
-
width: 200px;
|
|
16
|
-
height: 300px;
|
|
17
|
-
margin-right: 10px;
|
|
18
|
-
display: flex;
|
|
19
|
-
align-items: center;
|
|
20
|
-
justify-content: center;
|
|
21
|
-
font-size: 24px;
|
|
22
|
-
color: white;
|
|
23
|
-
}
|
|
24
|
-
.navigation {
|
|
25
|
-
text-align: center;
|
|
26
|
-
margin-top: 20px;
|
|
27
|
-
}
|
|
28
|
-
.navigation button {
|
|
29
|
-
margin: 0 5px;
|
|
30
|
-
padding: 5px 10px;
|
|
31
|
-
}
|
|
32
|
-
</style>
|
|
33
|
-
</head>
|
|
34
|
-
<body>
|
|
35
|
-
<div class="flicking-viewport">
|
|
36
|
-
<div class="flicking-camera">
|
|
37
|
-
<div class="panel" style="background-color: #f44336">Panel 1</div>
|
|
38
|
-
<div class="panel" style="background-color: #2196f3">Panel 2</div>
|
|
39
|
-
<div class="panel" style="background-color: #4caf50">Panel 3</div>
|
|
40
|
-
<div class="panel" style="background-color: #ffc107">Panel 4</div>
|
|
41
|
-
<div class="panel" style="background-color: #9c27b0">Panel 5</div>
|
|
42
|
-
</div>
|
|
43
|
-
</div>
|
|
44
|
-
<div class="navigation">
|
|
45
|
-
<button id="prev">Previous</button>
|
|
46
|
-
<button id="next">Next</button>
|
|
47
|
-
</div>
|
|
48
|
-
|
|
49
|
-
<script src="../../dist/flicking.pkgd.js"></script>
|
|
50
|
-
<script>
|
|
51
|
-
document.addEventListener("DOMContentLoaded", () => {
|
|
52
|
-
const flicking = new Flicking(".flicking-viewport", {
|
|
53
|
-
circular: false,
|
|
54
|
-
moveType: "snap",
|
|
55
|
-
align: "center",
|
|
56
|
-
defaultIndex: 0,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// Navigation buttons
|
|
60
|
-
const prevButton = document.getElementById("prev");
|
|
61
|
-
const nextButton = document.getElementById("next");
|
|
62
|
-
|
|
63
|
-
prevButton.addEventListener("click", () => {
|
|
64
|
-
flicking.prev();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
nextButton.addEventListener("click", () => {
|
|
68
|
-
flicking.next();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// Update button states based on current index
|
|
72
|
-
flicking.on("moveEnd", () => {
|
|
73
|
-
prevButton.disabled = flicking.index === 0;
|
|
74
|
-
nextButton.disabled = flicking.index === flicking.panels.length - 1;
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// Initial button state
|
|
78
|
-
prevButton.disabled = true;
|
|
79
|
-
});
|
|
80
|
-
</script>
|
|
81
|
-
</body>
|
|
82
|
-
</html>
|