@egjs/flicking 4.4.2 → 4.5.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 +8 -2
- package/declaration/camera/Camera.d.ts +26 -24
- package/declaration/camera/index.d.ts +2 -4
- package/declaration/camera/mode/BoundCameraMode.d.ts +13 -0
- package/declaration/camera/mode/CameraMode.d.ts +19 -0
- package/declaration/camera/mode/CircularCameraMode.d.ts +18 -0
- package/declaration/camera/mode/LinearCameraMode.d.ts +9 -0
- package/declaration/camera/mode/index.d.ts +6 -0
- package/declaration/const/external.d.ts +4 -0
- package/declaration/type/external.d.ts +1 -3
- package/dist/flicking.esm.js +1181 -1090
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.js +1184 -1092
- 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 +1183 -1091
- 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 +4 -3
- package/src/Flicking.ts +26 -15
- package/src/camera/Camera.ts +155 -70
- package/src/camera/index.ts +3 -7
- package/src/camera/{BoundCamera.ts → mode/BoundCameraMode.ts} +46 -43
- package/src/camera/mode/CameraMode.ts +77 -0
- package/src/camera/mode/CircularCameraMode.ts +171 -0
- package/src/camera/mode/LinearCameraMode.ts +23 -0
- package/src/camera/mode/index.ts +14 -0
- package/src/const/external.ts +12 -0
- package/declaration/camera/BoundCamera.d.ts +0 -9
- package/declaration/camera/CircularCamera.d.ts +0 -37
- package/declaration/camera/LinearCamera.d.ts +0 -5
- package/src/camera/CircularCamera.ts +0 -268
- package/src/camera/LinearCamera.ts +0 -35
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2015 NAVER Corp.
|
|
3
|
-
* egjs projects are licensed under the MIT license
|
|
4
|
-
*/
|
|
5
|
-
import Panel from "../core/panel/Panel";
|
|
6
|
-
import AnchorPoint from "../core/AnchorPoint";
|
|
7
|
-
import { DIRECTION } from "../const/external";
|
|
8
|
-
import { circulatePosition, getFlickingAttached } from "../utils";
|
|
9
|
-
import { ValueOf } from "../type/internal";
|
|
10
|
-
|
|
11
|
-
import Camera from "./Camera";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* A data of the position that changes order of the panel elements
|
|
15
|
-
* @ko 패널 엘리먼트 순서가 변경되는 좌표의 데이터
|
|
16
|
-
* @interface
|
|
17
|
-
* @property {Panel} panel Toggling panel<ko>순서를 변경할 패널</ko>
|
|
18
|
-
* @property {DIRECTION} direction Toggling position<ko>순서를 변경할 방향</ko>
|
|
19
|
-
* @property {boolean} toggled Whether the panel has toggled its position to `direction`<ko>`direction` 방향으로 패널 위치를 변경했는지 여부를 나타내는 값</ko>
|
|
20
|
-
*/
|
|
21
|
-
export interface TogglePoint {
|
|
22
|
-
panel: Panel;
|
|
23
|
-
direction: ValueOf<typeof DIRECTION>;
|
|
24
|
-
toggled: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* A {@link Camera} that connects the last panel and the first panel, enabling continuous loop
|
|
29
|
-
* @ko 첫번째 패널과 마지막 패널이 이어진 상태로, 무한히 회전할 수 있는 종류의 {@link Camera}
|
|
30
|
-
*/
|
|
31
|
-
class CircularCamera extends Camera {
|
|
32
|
-
private _circularOffset: number = 0;
|
|
33
|
-
private _circularEnabled: boolean = false;
|
|
34
|
-
|
|
35
|
-
public get offset() { return this._offset - this._circularOffset; }
|
|
36
|
-
public get controlParams() { return { range: this._range, position: this._position, circular: this._circularEnabled }; }
|
|
37
|
-
|
|
38
|
-
public getPrevAnchor(anchor: AnchorPoint): AnchorPoint | null {
|
|
39
|
-
if (!this._circularEnabled || anchor.index !== 0) return super.getPrevAnchor(anchor);
|
|
40
|
-
|
|
41
|
-
const anchors = this._anchors;
|
|
42
|
-
const rangeDiff = this.rangeDiff;
|
|
43
|
-
const lastAnchor = anchors[anchors.length - 1];
|
|
44
|
-
|
|
45
|
-
return new AnchorPoint({
|
|
46
|
-
index: lastAnchor.index,
|
|
47
|
-
position: lastAnchor.position - rangeDiff,
|
|
48
|
-
panel: lastAnchor.panel
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public getNextAnchor(anchor: AnchorPoint): AnchorPoint | null {
|
|
53
|
-
const anchors = this._anchors;
|
|
54
|
-
|
|
55
|
-
if (!this._circularEnabled || anchor.index !== anchors.length - 1) return super.getNextAnchor(anchor);
|
|
56
|
-
|
|
57
|
-
const rangeDiff = this.rangeDiff;
|
|
58
|
-
const firstAnchor = anchors[0];
|
|
59
|
-
|
|
60
|
-
return new AnchorPoint({
|
|
61
|
-
index: firstAnchor.index,
|
|
62
|
-
position: firstAnchor.position + rangeDiff,
|
|
63
|
-
panel: firstAnchor.panel
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public findAnchorIncludePosition(position: number): AnchorPoint | null {
|
|
68
|
-
if (!this._circularEnabled) return super.findAnchorIncludePosition(position);
|
|
69
|
-
|
|
70
|
-
const range = this._range;
|
|
71
|
-
const anchors = this._anchors;
|
|
72
|
-
const rangeDiff = this.rangeDiff;
|
|
73
|
-
const anchorCount = anchors.length;
|
|
74
|
-
const positionInRange = circulatePosition(position, range.min, range.max);
|
|
75
|
-
|
|
76
|
-
let anchorInRange: AnchorPoint | null = super.findAnchorIncludePosition(positionInRange);
|
|
77
|
-
|
|
78
|
-
if (anchorCount > 0 && (position === range.min || position === range.max)) {
|
|
79
|
-
const possibleAnchors = [
|
|
80
|
-
anchorInRange,
|
|
81
|
-
new AnchorPoint({
|
|
82
|
-
index: 0,
|
|
83
|
-
position: anchors[0].position + rangeDiff,
|
|
84
|
-
panel: anchors[0].panel
|
|
85
|
-
}),
|
|
86
|
-
new AnchorPoint({
|
|
87
|
-
index: anchorCount - 1,
|
|
88
|
-
position: anchors[anchorCount - 1].position - rangeDiff,
|
|
89
|
-
panel: anchors[anchorCount - 1].panel
|
|
90
|
-
})
|
|
91
|
-
].filter(anchor => !!anchor) as AnchorPoint[];
|
|
92
|
-
|
|
93
|
-
anchorInRange = possibleAnchors.reduce((nearest: AnchorPoint | null, anchor) => {
|
|
94
|
-
if (!nearest) return anchor;
|
|
95
|
-
|
|
96
|
-
return Math.abs(nearest.position - position) < Math.abs(anchor.position - position)
|
|
97
|
-
? nearest
|
|
98
|
-
: anchor;
|
|
99
|
-
}, null);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (!anchorInRange) return null;
|
|
103
|
-
|
|
104
|
-
if (position < range.min) {
|
|
105
|
-
const loopCount = -Math.floor((range.min - position) / rangeDiff) - 1;
|
|
106
|
-
|
|
107
|
-
return new AnchorPoint({
|
|
108
|
-
index: anchorInRange.index,
|
|
109
|
-
position: anchorInRange.position + rangeDiff * loopCount,
|
|
110
|
-
panel: anchorInRange.panel
|
|
111
|
-
});
|
|
112
|
-
} else if (position > range.max) {
|
|
113
|
-
const loopCount = Math.floor((position - range.max) / rangeDiff) + 1;
|
|
114
|
-
|
|
115
|
-
return new AnchorPoint({
|
|
116
|
-
index: anchorInRange.index,
|
|
117
|
-
position: anchorInRange.position + rangeDiff * loopCount,
|
|
118
|
-
panel: anchorInRange.panel
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return anchorInRange;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public clampToReachablePosition(position: number): number {
|
|
126
|
-
// Basically all position is reachable for circular camera
|
|
127
|
-
return this._circularEnabled
|
|
128
|
-
? position
|
|
129
|
-
: super.clampToReachablePosition(position);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
public canReach(panel: Panel): boolean {
|
|
133
|
-
if (panel.removed) return false;
|
|
134
|
-
|
|
135
|
-
return this._circularEnabled
|
|
136
|
-
// Always reachable on circular mode
|
|
137
|
-
? true
|
|
138
|
-
: super.canReach(panel);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
public canSee(panel: Panel): boolean {
|
|
142
|
-
const range = this._range;
|
|
143
|
-
const rangeDiff = this.rangeDiff;
|
|
144
|
-
const visibleRange = this.visibleRange;
|
|
145
|
-
const visibleInCurrentRange = super.canSee(panel);
|
|
146
|
-
|
|
147
|
-
if (!this._circularEnabled) {
|
|
148
|
-
return visibleInCurrentRange;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Check looped visible area for circular case
|
|
152
|
-
if (visibleRange.min < range.min) {
|
|
153
|
-
return visibleInCurrentRange || panel.isVisibleOnRange(visibleRange.min + rangeDiff, visibleRange.max + rangeDiff);
|
|
154
|
-
} else if (visibleRange.max > range.max) {
|
|
155
|
-
return visibleInCurrentRange || panel.isVisibleOnRange(visibleRange.min - rangeDiff, visibleRange.max - rangeDiff);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return visibleInCurrentRange;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Update {@link Camera#range range} of Camera
|
|
163
|
-
* @ko Camera의 {@link Camera#range range}를 업데이트합니다
|
|
164
|
-
* @chainable
|
|
165
|
-
* @throws {FlickingError}
|
|
166
|
-
* {@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} When {@link Camera#init init} is not called before
|
|
167
|
-
* <ko>{@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} {@link Camera#init init}이 이전에 호출되지 않은 경우</ko>
|
|
168
|
-
* @return {this}
|
|
169
|
-
*/
|
|
170
|
-
public updateRange() {
|
|
171
|
-
const flicking = getFlickingAttached(this._flicking);
|
|
172
|
-
const renderer = flicking.renderer;
|
|
173
|
-
|
|
174
|
-
const panels = renderer.panels;
|
|
175
|
-
if (panels.length <= 0) {
|
|
176
|
-
this._resetInternalValues();
|
|
177
|
-
return this;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const firstPanel = panels[0]!;
|
|
181
|
-
const lastPanel = panels[panels.length - 1]!;
|
|
182
|
-
const firstPanelPrev = firstPanel.range.min - firstPanel.margin.prev;
|
|
183
|
-
const lastPanelNext = lastPanel.range.max + lastPanel.margin.next;
|
|
184
|
-
|
|
185
|
-
const visibleSize = this.size;
|
|
186
|
-
const panelSizeSum = lastPanelNext - firstPanelPrev;
|
|
187
|
-
|
|
188
|
-
const canSetCircularMode = panels
|
|
189
|
-
.every(panel => panelSizeSum - panel.size >= visibleSize);
|
|
190
|
-
this._circularEnabled = canSetCircularMode;
|
|
191
|
-
|
|
192
|
-
if (canSetCircularMode) {
|
|
193
|
-
this._range = { min: firstPanelPrev, max: lastPanelNext };
|
|
194
|
-
|
|
195
|
-
panels.forEach(panel => panel.updateCircularToggleDirection());
|
|
196
|
-
} else {
|
|
197
|
-
this._range = { min: firstPanel.position, max: lastPanel.position };
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
this.updateOffset();
|
|
201
|
-
|
|
202
|
-
return this;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
public updateOffset() {
|
|
206
|
-
this._updateCircularOffset();
|
|
207
|
-
|
|
208
|
-
return super.updateOffset();
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
public lookAt(pos: number) {
|
|
212
|
-
const flicking = getFlickingAttached(this._flicking);
|
|
213
|
-
const prevPos = this._position;
|
|
214
|
-
|
|
215
|
-
if (pos === prevPos) return super.lookAt(pos);
|
|
216
|
-
|
|
217
|
-
const panels = flicking.renderer.panels;
|
|
218
|
-
const toggled = panels.map(panel => panel.toggle(prevPos, pos));
|
|
219
|
-
|
|
220
|
-
this._position = pos;
|
|
221
|
-
super.lookAt(pos);
|
|
222
|
-
|
|
223
|
-
if (toggled.some(isToggled => isToggled)) {
|
|
224
|
-
void flicking.renderer.render().then(() => {
|
|
225
|
-
this.updateOffset();
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
public applyTransform(): this {
|
|
231
|
-
const el = this._el;
|
|
232
|
-
const flicking = getFlickingAttached(this._flicking);
|
|
233
|
-
|
|
234
|
-
const actualPosition = this._position - this._alignPos - this._offset + this._circularOffset;
|
|
235
|
-
|
|
236
|
-
el.style[this._transform] = flicking.horizontal
|
|
237
|
-
? `translate(${-actualPosition}px)`
|
|
238
|
-
: `translate(0, ${-actualPosition}px)`;
|
|
239
|
-
|
|
240
|
-
return this;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
protected _resetInternalValues() {
|
|
244
|
-
super._resetInternalValues();
|
|
245
|
-
this._circularOffset = 0;
|
|
246
|
-
this._circularEnabled = false;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
private _calcPanelAreaSum(panels: Panel[]) {
|
|
250
|
-
return panels.reduce((sum: number, panel: Panel) => sum + panel.sizeIncludingMargin, 0);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
private _updateCircularOffset() {
|
|
254
|
-
if (!this._circularEnabled) {
|
|
255
|
-
this._circularOffset = 0;
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
const flicking = getFlickingAttached(this._flicking);
|
|
260
|
-
const toggled = flicking.panels.filter(panel => panel.toggled);
|
|
261
|
-
const toggledPrev = toggled.filter(panel => panel.toggleDirection === DIRECTION.PREV);
|
|
262
|
-
const toggledNext = toggled.filter(panel => panel.toggleDirection === DIRECTION.NEXT);
|
|
263
|
-
|
|
264
|
-
this._circularOffset = this._calcPanelAreaSum(toggledPrev) - this._calcPanelAreaSum(toggledNext);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export default CircularCamera;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2015 NAVER Corp.
|
|
3
|
-
* egjs projects are licensed under the MIT license
|
|
4
|
-
*/
|
|
5
|
-
import { getFlickingAttached } from "../utils";
|
|
6
|
-
|
|
7
|
-
import Camera from "./Camera";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A {@link Camera} that can move from the position of the first panel to the position of the last panel
|
|
11
|
-
* @ko 첫번째 패널의 좌표로부터 마지막 패널의 좌표로까지 이동할 수 있는 종류의 {@link Camera}
|
|
12
|
-
*/
|
|
13
|
-
class LinearCamera extends Camera {
|
|
14
|
-
/**
|
|
15
|
-
* Update {@link Camera#range range} of Camera
|
|
16
|
-
* @ko Camera의 {@link Camera#range range}를 업데이트합니다
|
|
17
|
-
* @chainable
|
|
18
|
-
* @throws {FlickingError}
|
|
19
|
-
* {@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} When {@link Camera#init init} is not called before
|
|
20
|
-
* <ko>{@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} {@link Camera#init init}이 이전에 호출되지 않은 경우</ko>
|
|
21
|
-
* @return {this}
|
|
22
|
-
*/
|
|
23
|
-
public updateRange() {
|
|
24
|
-
const flicking = getFlickingAttached(this._flicking);
|
|
25
|
-
const renderer = flicking.renderer;
|
|
26
|
-
|
|
27
|
-
const firstPanel = renderer.getPanel(0);
|
|
28
|
-
const lastPanel = renderer.getPanel(renderer.panelCount - 1);
|
|
29
|
-
|
|
30
|
-
this._range = { min: firstPanel?.position ?? 0, max: lastPanel?.position ?? 0 };
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export default LinearCamera;
|