@egjs/flicking 4.13.1 → 4.13.2-beta.0
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 +1 -12
- package/declaration/control/Control.d.ts +1 -1
- package/declaration/core/AutoResizer.d.ts +0 -5
- package/dist/flicking.cjs.js +25 -202
- package/dist/flicking.cjs.js.map +1 -1
- package/dist/flicking.esm.js +25 -202
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.js +25 -202
- 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 +43 -205
- 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 +153 -522
- package/src/camera/mode/CameraMode.ts +1 -2
- package/src/control/Control.ts +1 -1
- package/src/control/SnapControl.ts +8 -1
- package/src/core/AutoResizer.ts +11 -110
- package/src/renderer/Renderer.ts +0 -13
- package/src/utils.ts +1 -6
- package/core-packages-link.js +0 -38
- package/debug/example/index.html +0 -82
|
@@ -33,9 +33,8 @@ abstract class CameraMode {
|
|
|
33
33
|
|
|
34
34
|
public findAnchorIncludePosition(position: number): AnchorPoint | null {
|
|
35
35
|
const anchors = this._flicking.camera.anchorPoints;
|
|
36
|
-
const anchorsIncludingPosition = anchors.filter(anchor => anchor.panel.includePosition(position, true));
|
|
37
36
|
|
|
38
|
-
return
|
|
37
|
+
return anchors.reduce((nearest: AnchorPoint | null, anchor) => {
|
|
39
38
|
if (!nearest) return anchor;
|
|
40
39
|
|
|
41
40
|
return Math.abs(nearest.position - position) < Math.abs(anchor.position - position)
|
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,12 @@ 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
|
-
|
|
113
|
+
// const targetPanel = targetAnchor.panel;
|
|
114
|
+
// const nextPosition = this._getPosition(targetPanel, DIRECTION.NEXT);
|
|
115
|
+
// const prevPosition = this._getPosition(targetPanel, DIRECTION.PREV);
|
|
116
|
+
|
|
117
|
+
// targetPosition = Math.abs(camera.position - nextPosition) < Math.abs(camera.position - prevPosition) ? nextPosition : prevPosition;
|
|
118
|
+
} else if (absPosDelta >= flicking.threshold && absPosDelta > 0 && anchorAtCamera === activeAnchor) {
|
|
113
119
|
// Move to the adjacent panel
|
|
114
120
|
targetAnchor = this._findAdjacentAnchor(position, posDelta, anchorAtCamera);
|
|
115
121
|
} else {
|
|
@@ -144,6 +150,7 @@ class SnapControl extends Control {
|
|
|
144
150
|
throw new FlickingError(ERROR.MESSAGE.POSITION_NOT_REACHABLE(position), ERROR.CODE.POSITION_NOT_REACHABLE);
|
|
145
151
|
}
|
|
146
152
|
|
|
153
|
+
// console.log("_findSnappedAnchor", anchorAtPosition);
|
|
147
154
|
if (!isFinite(count)) {
|
|
148
155
|
return anchorAtPosition;
|
|
149
156
|
}
|
package/src/core/AutoResizer.ts
CHANGED
|
@@ -2,13 +2,8 @@
|
|
|
2
2
|
* Copyright (c) 2015 NAVER Corp.
|
|
3
3
|
* egjs projects are licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
-
import { getElementSize, getStyle } from "../utils";
|
|
6
5
|
import Flicking from "../Flicking";
|
|
7
6
|
|
|
8
|
-
/**
|
|
9
|
-
* A component that detects size change and trigger resize method when the autoResize option is used
|
|
10
|
-
* @ko autoResize 옵션을 사용할 때 크기 변화를 감지하고 Flicking의 resize를 호출하는 컴포넌트
|
|
11
|
-
*/
|
|
12
7
|
class AutoResizer {
|
|
13
8
|
private _flicking: Flicking;
|
|
14
9
|
private _enabled: boolean;
|
|
@@ -16,9 +11,7 @@ class AutoResizer {
|
|
|
16
11
|
private _resizeTimer: number;
|
|
17
12
|
private _maxResizeDebounceTimer: number;
|
|
18
13
|
|
|
19
|
-
public get enabled() {
|
|
20
|
-
return this._enabled;
|
|
21
|
-
}
|
|
14
|
+
public get enabled() { return this._enabled; }
|
|
22
15
|
|
|
23
16
|
public constructor(flicking: Flicking) {
|
|
24
17
|
this._flicking = flicking;
|
|
@@ -43,15 +36,11 @@ class AutoResizer {
|
|
|
43
36
|
? new ResizeObserver(this._skipFirstResize)
|
|
44
37
|
: new ResizeObserver(this._onResize);
|
|
45
38
|
|
|
46
|
-
|
|
39
|
+
resizeObserver.observe(flicking.viewport.element);
|
|
47
40
|
|
|
48
|
-
this.
|
|
49
|
-
|
|
50
|
-
if (flicking.observePanelResize) {
|
|
51
|
-
this.observePanels();
|
|
52
|
-
}
|
|
41
|
+
this._resizeObserver = resizeObserver;
|
|
53
42
|
} else {
|
|
54
|
-
window.addEventListener("resize", this.
|
|
43
|
+
window.addEventListener("resize", this._onResize);
|
|
55
44
|
}
|
|
56
45
|
|
|
57
46
|
this._enabled = true;
|
|
@@ -59,44 +48,6 @@ class AutoResizer {
|
|
|
59
48
|
return this;
|
|
60
49
|
}
|
|
61
50
|
|
|
62
|
-
public observePanels(): this {
|
|
63
|
-
this._flicking.panels.forEach(panel => {
|
|
64
|
-
this.observe(panel.element);
|
|
65
|
-
});
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public unobservePanels(): this {
|
|
70
|
-
this._flicking.panels.forEach(panel => {
|
|
71
|
-
this.unobserve(panel.element);
|
|
72
|
-
});
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public observe(element: HTMLElement): this {
|
|
77
|
-
const resizeObserver = this._resizeObserver;
|
|
78
|
-
|
|
79
|
-
if (!resizeObserver) return this;
|
|
80
|
-
|
|
81
|
-
resizeObserver.observe(element);
|
|
82
|
-
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public unobserve(element: HTMLElement): this {
|
|
87
|
-
const resizeObserver = this._resizeObserver;
|
|
88
|
-
|
|
89
|
-
if (!resizeObserver) return this;
|
|
90
|
-
|
|
91
|
-
resizeObserver.unobserve(element);
|
|
92
|
-
|
|
93
|
-
if (this._flicking.observePanelResize) {
|
|
94
|
-
this.unobservePanels();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
51
|
public disable(): this {
|
|
101
52
|
if (!this._enabled) return this;
|
|
102
53
|
|
|
@@ -105,7 +56,7 @@ class AutoResizer {
|
|
|
105
56
|
resizeObserver.disconnect();
|
|
106
57
|
this._resizeObserver = null;
|
|
107
58
|
} else {
|
|
108
|
-
window.removeEventListener("resize", this.
|
|
59
|
+
window.removeEventListener("resize", this._onResize);
|
|
109
60
|
}
|
|
110
61
|
|
|
111
62
|
this._enabled = false;
|
|
@@ -113,64 +64,17 @@ class AutoResizer {
|
|
|
113
64
|
return this;
|
|
114
65
|
}
|
|
115
66
|
|
|
116
|
-
private
|
|
117
|
-
this._onResize([]);
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
private _onResize = (entries: ResizeObserverEntry[]) => {
|
|
67
|
+
private _onResize = () => {
|
|
121
68
|
const flicking = this._flicking;
|
|
122
69
|
const resizeDebounce = flicking.resizeDebounce;
|
|
123
70
|
const maxResizeDebounce = flicking.maxResizeDebounce;
|
|
124
71
|
|
|
125
|
-
const resizedViewportElement = flicking.element;
|
|
126
|
-
// 현재 구현에서 리사이즈 옵저빙 대상은 패널과 뷰포트 2개만 존재.
|
|
127
|
-
// 아래는 뷰포트만 변경되었을 때 동작해야하는 로직이 있으므로 아래와 같이 조건문을 건다.
|
|
128
|
-
// 패널 쪽에서는 리사이즈 감지에 resizeObserver를 사용하지 않는 경우가 없으므로 이 조건은 곧 뷰포트만 리사이즈가 된 경우를 의미한다.
|
|
129
|
-
const isResizedViewportOnly = entries.find(e => e.target === flicking.element) && entries.length === 1;
|
|
130
|
-
|
|
131
|
-
// 참고: resizeObserver를 사용하지 않은 경우에는 entries.length가 0으로 오는데 이 경우에는 그냥 항상 리사이즈가 진행되도록 한다.
|
|
132
|
-
// (vw, vh 등을 사용하는 경우 이상 동작이 발생할 여지가 있기 때문이다)
|
|
133
|
-
if (isResizedViewportOnly) {
|
|
134
|
-
// resize 이벤트가 발생했으나 이전과 width, height의 변화가 없다면 이후 로직을 진행하지 않는다.
|
|
135
|
-
const beforeSize = {
|
|
136
|
-
width: flicking.viewport.width,
|
|
137
|
-
height: flicking.viewport.height
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const afterSize = {
|
|
141
|
-
width: getElementSize({
|
|
142
|
-
el: resizedViewportElement,
|
|
143
|
-
horizontal: true,
|
|
144
|
-
useFractionalSize: this._flicking.useFractionalSize,
|
|
145
|
-
useOffset: false,
|
|
146
|
-
style: getStyle(resizedViewportElement)
|
|
147
|
-
}),
|
|
148
|
-
height: getElementSize({
|
|
149
|
-
el: resizedViewportElement,
|
|
150
|
-
horizontal: false,
|
|
151
|
-
useFractionalSize: this._flicking.useFractionalSize,
|
|
152
|
-
useOffset: false,
|
|
153
|
-
style: getStyle(resizedViewportElement)
|
|
154
|
-
})
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
if (
|
|
158
|
-
beforeSize.height === afterSize.height &&
|
|
159
|
-
beforeSize.width === afterSize.width
|
|
160
|
-
) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
72
|
if (resizeDebounce <= 0) {
|
|
166
73
|
void flicking.resize();
|
|
167
74
|
} else {
|
|
168
75
|
if (this._maxResizeDebounceTimer <= 0) {
|
|
169
76
|
if (maxResizeDebounce > 0 && maxResizeDebounce >= resizeDebounce) {
|
|
170
|
-
this._maxResizeDebounceTimer = window.setTimeout(
|
|
171
|
-
this._doScheduledResize,
|
|
172
|
-
maxResizeDebounce
|
|
173
|
-
);
|
|
77
|
+
this._maxResizeDebounceTimer = window.setTimeout(this._doScheduledResize, maxResizeDebounce);
|
|
174
78
|
}
|
|
175
79
|
}
|
|
176
80
|
|
|
@@ -179,10 +83,7 @@ class AutoResizer {
|
|
|
179
83
|
this._resizeTimer = 0;
|
|
180
84
|
}
|
|
181
85
|
|
|
182
|
-
this._resizeTimer = window.setTimeout(
|
|
183
|
-
this._doScheduledResize,
|
|
184
|
-
resizeDebounce
|
|
185
|
-
);
|
|
86
|
+
this._resizeTimer = window.setTimeout(this._doScheduledResize, resizeDebounce);
|
|
186
87
|
}
|
|
187
88
|
};
|
|
188
89
|
|
|
@@ -200,13 +101,13 @@ class AutoResizer {
|
|
|
200
101
|
private _skipFirstResize = (() => {
|
|
201
102
|
let isFirstResize = true;
|
|
202
103
|
|
|
203
|
-
return (
|
|
104
|
+
return (() => {
|
|
204
105
|
if (isFirstResize) {
|
|
205
106
|
isFirstResize = false;
|
|
206
107
|
return;
|
|
207
108
|
}
|
|
208
|
-
this._onResize(
|
|
209
|
-
};
|
|
109
|
+
this._onResize();
|
|
110
|
+
});
|
|
210
111
|
})();
|
|
211
112
|
}
|
|
212
113
|
|
package/src/renderer/Renderer.ts
CHANGED
|
@@ -335,19 +335,6 @@ abstract class Renderer {
|
|
|
335
335
|
// Update camera & control
|
|
336
336
|
this._updateCameraAndControl();
|
|
337
337
|
|
|
338
|
-
if (flicking.autoResize && flicking.useResizeObserver) {
|
|
339
|
-
panelsAdded.forEach((panel) => {
|
|
340
|
-
if (panel.element) {
|
|
341
|
-
flicking.autoResizer.observe(panel.element);
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
panelsRemoved.forEach((panel) => {
|
|
345
|
-
if (panel.element) {
|
|
346
|
-
flicking.autoResizer.unobserve(panel.element);
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
|
|
351
338
|
void this.render();
|
|
352
339
|
|
|
353
340
|
if (!flicking.animating) {
|
package/src/utils.ts
CHANGED
|
@@ -256,12 +256,7 @@ export const findIndex = <T>(array: T[], checker: (val: T) => boolean): number =
|
|
|
256
256
|
export const getProgress = (pos: number, prev: number, next: number) => (pos - prev) / (next - prev);
|
|
257
257
|
|
|
258
258
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
259
|
-
export const getStyle = (el: HTMLElement): CSSStyleDeclaration =>
|
|
260
|
-
if (!el) {
|
|
261
|
-
return {} as CSSStyleDeclaration;
|
|
262
|
-
}
|
|
263
|
-
return window.getComputedStyle(el) || (el as any).currentStyle as CSSStyleDeclaration;
|
|
264
|
-
};
|
|
259
|
+
export const getStyle = (el: HTMLElement): CSSStyleDeclaration => window.getComputedStyle(el) || (el as any).currentStyle as CSSStyleDeclaration;
|
|
265
260
|
|
|
266
261
|
export const setSize = (el: HTMLElement, { width, height }: Partial<{
|
|
267
262
|
width: number | string;
|
package/core-packages-link.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 프레임워크 컴포넌트를 디버깅할 때 코어 바닐라 로직을 수정하면서 확인할 필요가 있을 때,
|
|
5
|
-
* 이 스크립트를 이용하면 바닐라 로직 수정사항이 프레임워크 컴포넌트 로컬 데모환경에도 반영된다.
|
|
6
|
-
*
|
|
7
|
-
* 인자로 프레임워크 컴포넌트 패키지의 루트 디렉토리를 제공하면 된다.
|
|
8
|
-
*
|
|
9
|
-
* 사용 예시: node core-package-link.js react-flicking
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const { execSync } = require("child_process");
|
|
13
|
-
const path = require("path");
|
|
14
|
-
const fs = require("fs");
|
|
15
|
-
|
|
16
|
-
const args = process.argv.slice(2);
|
|
17
|
-
const targetDir = args[0];
|
|
18
|
-
|
|
19
|
-
if (!targetDir) {
|
|
20
|
-
console.error("❌ 디렉토리명을 인자로 입력하세요.");
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const fullPath = path.resolve(process.cwd(), 'packages', targetDir);
|
|
25
|
-
if (!fs.existsSync(fullPath)) {
|
|
26
|
-
console.error(`❌ 디렉토리 없음: ${fullPath}`);
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function run(cmd, cwd = process.cwd()) {
|
|
31
|
-
console.log(`\n▶️ Running: ${cmd} (in ${cwd})`);
|
|
32
|
-
execSync(cmd, { stdio: "inherit", cwd });
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
run("npm run build");
|
|
36
|
-
run("npm link");
|
|
37
|
-
run(`npm link '@egjs/flicking'`, fullPath);
|
|
38
|
-
run("npm run build", fullPath);
|
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>
|