@egjs/flicking 4.4.2 → 4.6.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/TODO.md +3 -0
- package/declaration/Flicking.d.ts +15 -2
- package/declaration/camera/Camera.d.ts +28 -26
- 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/control/StrictControl.d.ts +1 -0
- package/declaration/core/AutoResizer.d.ts +3 -0
- package/declaration/core/ResizeWatcher.d.ts +33 -0
- package/declaration/renderer/Renderer.d.ts +13 -0
- package/declaration/type/external.d.ts +1 -3
- package/{css → dist/css}/flicking-inline.css +20 -13
- package/dist/css/flicking-inline.min.css +1 -0
- package/dist/css/flicking.css +44 -0
- package/dist/css/flicking.min.css +1 -0
- package/dist/flicking.esm.js +1491 -1251
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.js +1494 -1253
- 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 +1466 -1225
- 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 +17 -7
- package/sass/flicking-inline.sass +30 -0
- package/sass/flicking.sass +23 -0
- package/src/Flicking.ts +127 -35
- package/src/camera/Camera.ts +162 -81
- 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/cfc/sync.ts +29 -23
- package/src/cfc/withFlickingMethods.ts +3 -2
- package/src/const/external.ts +12 -0
- package/src/control/StrictControl.ts +10 -0
- package/src/core/AutoResizer.ts +33 -0
- package/src/core/ResizeWatcher.ts +133 -0
- package/src/renderer/Renderer.ts +92 -43
- package/css/flicking.css +0 -28
- 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/dist/flicking-inline.css +0 -2
- package/dist/flicking-inline.css.map +0 -1
- package/dist/flicking.css +0 -2
- package/dist/flicking.css.map +0 -1
- package/src/camera/CircularCamera.ts +0 -268
- package/src/camera/LinearCamera.ts +0 -35
package/src/renderer/Renderer.ts
CHANGED
|
@@ -27,6 +27,7 @@ abstract class Renderer {
|
|
|
27
27
|
// Internal States
|
|
28
28
|
protected _flicking: Flicking | null;
|
|
29
29
|
protected _panels: Panel[];
|
|
30
|
+
protected _rendering: boolean;
|
|
30
31
|
|
|
31
32
|
// Options
|
|
32
33
|
protected _align: NonNullable<RendererOptions["align"]>;
|
|
@@ -41,6 +42,14 @@ abstract class Renderer {
|
|
|
41
42
|
* @see Panel
|
|
42
43
|
*/
|
|
43
44
|
public get panels() { return this._panels; }
|
|
45
|
+
/**
|
|
46
|
+
* A boolean value indicating whether rendering is in progress
|
|
47
|
+
* @ko 현재 렌더링이 시작되어 끝나기 전까지의 상태인지의 여부
|
|
48
|
+
* @type {boolean}
|
|
49
|
+
* @readonly
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
public get rendering() { return this._rendering; }
|
|
44
53
|
/**
|
|
45
54
|
* Count of panels
|
|
46
55
|
* @ko 전체 패널의 개수
|
|
@@ -80,6 +89,7 @@ abstract class Renderer {
|
|
|
80
89
|
}: RendererOptions) {
|
|
81
90
|
this._flicking = null;
|
|
82
91
|
this._panels = [];
|
|
92
|
+
this._rendering = false;
|
|
83
93
|
|
|
84
94
|
// Bind options
|
|
85
95
|
this._align = align;
|
|
@@ -182,10 +192,28 @@ abstract class Renderer {
|
|
|
182
192
|
elements: any[];
|
|
183
193
|
hasDOMInElements: boolean;
|
|
184
194
|
}>): Panel[] {
|
|
195
|
+
const allPanelsInserted = this.batchInsertDefer(...items);
|
|
196
|
+
|
|
197
|
+
if (allPanelsInserted.length <= 0) return [];
|
|
198
|
+
|
|
199
|
+
this.updateAfterPanelChange(allPanelsInserted, []);
|
|
200
|
+
|
|
201
|
+
return allPanelsInserted;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Defers update
|
|
206
|
+
* camera position & others will be updated after calling updateAfterPanelChange
|
|
207
|
+
* @internal
|
|
208
|
+
*/
|
|
209
|
+
public batchInsertDefer(...items: Array<{
|
|
210
|
+
index: number;
|
|
211
|
+
elements: any[];
|
|
212
|
+
hasDOMInElements: boolean;
|
|
213
|
+
}>) {
|
|
185
214
|
const panels = this._panels;
|
|
186
215
|
const flicking = getFlickingAttached(this._flicking);
|
|
187
216
|
|
|
188
|
-
const { control } = flicking;
|
|
189
217
|
const prevFirstPanel = panels[0];
|
|
190
218
|
const align = parsePanelAlign(this._align);
|
|
191
219
|
|
|
@@ -219,30 +247,6 @@ abstract class Renderer {
|
|
|
219
247
|
return [...addedPanels, ...panelsInserted];
|
|
220
248
|
}, []);
|
|
221
249
|
|
|
222
|
-
if (allPanelsInserted.length <= 0) return [];
|
|
223
|
-
|
|
224
|
-
// Update camera & control
|
|
225
|
-
this._updateCameraAndControl();
|
|
226
|
-
|
|
227
|
-
void this.render();
|
|
228
|
-
|
|
229
|
-
// Move to the first panel added if no panels existed
|
|
230
|
-
// FIXME: fix for animating case
|
|
231
|
-
if (allPanelsInserted.length > 0 && !control.animating) {
|
|
232
|
-
void control.moveToPanel(control.activePanel || allPanelsInserted[0], {
|
|
233
|
-
duration: 0
|
|
234
|
-
}).catch(() => void 0);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
flicking.camera.updateOffset();
|
|
238
|
-
|
|
239
|
-
flicking.trigger(new ComponentEvent(EVENTS.PANEL_CHANGE, {
|
|
240
|
-
added: allPanelsInserted,
|
|
241
|
-
removed: []
|
|
242
|
-
}));
|
|
243
|
-
|
|
244
|
-
this.checkPanelContentsReady(allPanelsInserted);
|
|
245
|
-
|
|
246
250
|
return allPanelsInserted;
|
|
247
251
|
}
|
|
248
252
|
|
|
@@ -257,13 +261,35 @@ abstract class Renderer {
|
|
|
257
261
|
* @param {boolean} [items.hasDOMInElements=1] Whether it contains actual DOM elements. If set to true, renderer will remove them from the camera element<ko>내부에 실제 DOM 엘리먼트들을 포함하고 있는지 여부. true로 설정할 경우, 렌더러는 해당 엘리먼트들을 카메라 엘리먼트 내부에서 제거합니다</ko>
|
|
258
262
|
* @return An array of removed panels<ko>제거된 패널들의 배열</ko>
|
|
259
263
|
*/
|
|
260
|
-
public batchRemove(...items: Array<{
|
|
264
|
+
public batchRemove(...items: Array<{
|
|
265
|
+
index: number;
|
|
266
|
+
deleteCount: number;
|
|
267
|
+
hasDOMInElements: boolean;
|
|
268
|
+
}>): Panel[] {
|
|
269
|
+
const allPanelsRemoved = this.batchRemoveDefer(...items);
|
|
270
|
+
|
|
271
|
+
if (allPanelsRemoved.length <= 0) return [];
|
|
272
|
+
|
|
273
|
+
this.updateAfterPanelChange([], allPanelsRemoved);
|
|
274
|
+
|
|
275
|
+
return allPanelsRemoved;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Defers update
|
|
280
|
+
* camera position & others will be updated after calling updateAfterPanelChange
|
|
281
|
+
* @internal
|
|
282
|
+
*/
|
|
283
|
+
public batchRemoveDefer(...items: Array<{
|
|
284
|
+
index: number;
|
|
285
|
+
deleteCount: number;
|
|
286
|
+
hasDOMInElements: boolean;
|
|
287
|
+
}>) {
|
|
261
288
|
const panels = this._panels;
|
|
262
289
|
const flicking = getFlickingAttached(this._flicking);
|
|
263
290
|
|
|
264
|
-
const {
|
|
291
|
+
const { control } = flicking;
|
|
265
292
|
const activePanel = control.activePanel;
|
|
266
|
-
const activeIndex = control.activeIndex;
|
|
267
293
|
|
|
268
294
|
const allPanelsRemoved = items.reduce((removed, item) => {
|
|
269
295
|
const { index, deleteCount } = item;
|
|
@@ -294,35 +320,56 @@ abstract class Renderer {
|
|
|
294
320
|
return [...removed, ...panelsRemoved];
|
|
295
321
|
}, []);
|
|
296
322
|
|
|
323
|
+
return allPanelsRemoved;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* @internal
|
|
328
|
+
*/
|
|
329
|
+
public updateAfterPanelChange(panelsAdded: Panel[], panelsRemoved: Panel[]) {
|
|
330
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
331
|
+
const { camera, control } = flicking;
|
|
332
|
+
const panels = this._panels;
|
|
333
|
+
const activePanel = control.activePanel;
|
|
334
|
+
|
|
297
335
|
// Update camera & control
|
|
298
336
|
this._updateCameraAndControl();
|
|
299
337
|
|
|
300
338
|
void this.render();
|
|
301
339
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
340
|
+
if (!activePanel || activePanel.removed) {
|
|
341
|
+
if (panels.length <= 0) {
|
|
342
|
+
// All panels removed
|
|
343
|
+
camera.lookAt(0);
|
|
344
|
+
} else {
|
|
345
|
+
let targetIndex = activePanel?.index ?? 0;
|
|
346
|
+
if (targetIndex > panels.length - 1) {
|
|
347
|
+
targetIndex = panels.length - 1;
|
|
348
|
+
}
|
|
307
349
|
|
|
308
|
-
|
|
309
|
-
void control.moveToPanel(targetPanel, {
|
|
350
|
+
void control.moveToPanel(panels[targetIndex], {
|
|
310
351
|
duration: 0
|
|
311
352
|
}).catch(() => void 0);
|
|
312
|
-
} else {
|
|
313
|
-
// All panels removed
|
|
314
|
-
camera.lookAt(0);
|
|
315
353
|
}
|
|
354
|
+
} else {
|
|
355
|
+
void control.moveToPanel(control.activePanel!, {
|
|
356
|
+
duration: 0
|
|
357
|
+
}).catch(() => void 0);
|
|
316
358
|
}
|
|
317
359
|
|
|
318
360
|
flicking.camera.updateOffset();
|
|
319
361
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
362
|
+
if (panelsAdded.length > 0 || panelsRemoved.length > 0) {
|
|
363
|
+
flicking.trigger(new ComponentEvent(EVENTS.PANEL_CHANGE, {
|
|
364
|
+
added: panelsAdded,
|
|
365
|
+
removed: panelsRemoved
|
|
366
|
+
}));
|
|
324
367
|
|
|
325
|
-
|
|
368
|
+
this.checkPanelContentsReady([
|
|
369
|
+
...panelsAdded,
|
|
370
|
+
...panelsRemoved
|
|
371
|
+
]);
|
|
372
|
+
}
|
|
326
373
|
}
|
|
327
374
|
|
|
328
375
|
/**
|
|
@@ -367,6 +414,7 @@ abstract class Renderer {
|
|
|
367
414
|
if (!flicking.initialized) return;
|
|
368
415
|
|
|
369
416
|
camera.updateRange();
|
|
417
|
+
camera.updateOffset();
|
|
370
418
|
camera.updateAnchors();
|
|
371
419
|
|
|
372
420
|
if (control.animating) {
|
|
@@ -402,6 +450,7 @@ abstract class Renderer {
|
|
|
402
450
|
const { camera, control } = flicking;
|
|
403
451
|
|
|
404
452
|
camera.updateRange();
|
|
453
|
+
camera.updateOffset();
|
|
405
454
|
camera.updateAnchors();
|
|
406
455
|
camera.resetNeedPanelHistory();
|
|
407
456
|
control.updateInput();
|
package/css/flicking.css
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
.flicking-viewport {
|
|
2
|
-
position: relative;
|
|
3
|
-
overflow: hidden;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
.flicking-camera {
|
|
7
|
-
width: 100%;
|
|
8
|
-
height: 100%;
|
|
9
|
-
display: flex;
|
|
10
|
-
position: relative;
|
|
11
|
-
flex-direction: row;
|
|
12
|
-
z-index: 1;
|
|
13
|
-
}
|
|
14
|
-
.flicking-camera>* {
|
|
15
|
-
flex-shrink: 0;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
.flicking-viewport.vertical {
|
|
19
|
-
display: inline-flex;
|
|
20
|
-
}
|
|
21
|
-
.flicking-viewport.vertical>.flicking-camera {
|
|
22
|
-
display: inline-flex;
|
|
23
|
-
flex-direction: column;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.flicking-viewport.flicking-hidden .flicking-camera > * {
|
|
27
|
-
visibility: hidden;
|
|
28
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import AnchorPoint from "../core/AnchorPoint";
|
|
2
|
-
import Camera from "./Camera";
|
|
3
|
-
declare class BoundCamera extends Camera {
|
|
4
|
-
updateRange(): this;
|
|
5
|
-
updateAnchors(): this;
|
|
6
|
-
findAnchorIncludePosition(position: number): AnchorPoint | null;
|
|
7
|
-
private _findNearestPanel;
|
|
8
|
-
}
|
|
9
|
-
export default BoundCamera;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import Panel from "../core/panel/Panel";
|
|
2
|
-
import AnchorPoint from "../core/AnchorPoint";
|
|
3
|
-
import { DIRECTION } from "../const/external";
|
|
4
|
-
import { ValueOf } from "../type/internal";
|
|
5
|
-
import Camera from "./Camera";
|
|
6
|
-
export interface TogglePoint {
|
|
7
|
-
panel: Panel;
|
|
8
|
-
direction: ValueOf<typeof DIRECTION>;
|
|
9
|
-
toggled: boolean;
|
|
10
|
-
}
|
|
11
|
-
declare class CircularCamera extends Camera {
|
|
12
|
-
private _circularOffset;
|
|
13
|
-
private _circularEnabled;
|
|
14
|
-
get offset(): number;
|
|
15
|
-
get controlParams(): {
|
|
16
|
-
range: {
|
|
17
|
-
min: number;
|
|
18
|
-
max: number;
|
|
19
|
-
};
|
|
20
|
-
position: number;
|
|
21
|
-
circular: boolean;
|
|
22
|
-
};
|
|
23
|
-
getPrevAnchor(anchor: AnchorPoint): AnchorPoint | null;
|
|
24
|
-
getNextAnchor(anchor: AnchorPoint): AnchorPoint | null;
|
|
25
|
-
findAnchorIncludePosition(position: number): AnchorPoint | null;
|
|
26
|
-
clampToReachablePosition(position: number): number;
|
|
27
|
-
canReach(panel: Panel): boolean;
|
|
28
|
-
canSee(panel: Panel): boolean;
|
|
29
|
-
updateRange(): this;
|
|
30
|
-
updateOffset(): this;
|
|
31
|
-
lookAt(pos: number): void;
|
|
32
|
-
applyTransform(): this;
|
|
33
|
-
protected _resetInternalValues(): void;
|
|
34
|
-
private _calcPanelAreaSum;
|
|
35
|
-
private _updateCircularOffset;
|
|
36
|
-
}
|
|
37
|
-
export default CircularCamera;
|
package/dist/flicking-inline.css
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
.flicking-viewport{position:relative;overflow:hidden}.flicking-viewport:not(.vertical){width:100%;height:100%}.flicking-camera{width:100%;height:100%;position:relative;z-index:1;white-space:nowrap;will-change:transform}.flicking-camera>*{display:inline-block;white-space:normal;vertical-align:top}.flicking-viewport.vertical,.flicking-viewport.vertical>.flicking-camera{display:inline-block}.flicking-viewport.vertical.middle>.flicking-camera>*{vertical-align:middle}.flicking-viewport.vertical.bottom>.flicking-camera>*{vertical-align:bottom}.flicking-viewport.vertical>.flicking-camera>*{display:block}.flicking-viewport.flicking-hidden>.flicking-camera>*{visibility:hidden}
|
|
2
|
-
/*# sourceMappingURL=flicking-inline.css.map */
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["<input css 1>"],"names":[],"mappings":"AAAA,mBAAmB,iBAAiB,CAAC,eAAe,CAAC,kCAAkC,UAAU,CAAC,WAAW,CAAC,iBAAiB,UAAU,CAAC,WAAW,CAAC,iBAAiB,CAAC,SAAS,CAAC,kBAAkB,CAAC,qBAAqB,CAAC,mBAAmB,oBAAoB,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,yEAAyE,oBAAoB,CAAC,sDAAsD,qBAAqB,CAAC,sDAAsD,qBAAqB,CAAC,+CAA+C,aAAa,CAAC,sDAAsD,iBAAiB","file":"flicking-inline.css","sourcesContent":[".flicking-viewport{position:relative;overflow:hidden}.flicking-viewport:not(.vertical){width:100%;height:100%}.flicking-camera{width:100%;height:100%;position:relative;z-index:1;white-space:nowrap;will-change:transform}.flicking-camera>*{display:inline-block;white-space:normal;vertical-align:top}.flicking-viewport.vertical,.flicking-viewport.vertical>.flicking-camera{display:inline-block}.flicking-viewport.vertical.middle>.flicking-camera>*{vertical-align:middle}.flicking-viewport.vertical.bottom>.flicking-camera>*{vertical-align:bottom}.flicking-viewport.vertical>.flicking-camera>*{display:block}.flicking-viewport.flicking-hidden>.flicking-camera>*{visibility:hidden}"]}
|
package/dist/flicking.css
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
.flicking-viewport{position:relative;overflow:hidden}.flicking-camera{width:100%;height:100%;display:-webkit-box;display:-ms-flexbox;display:flex;position:relative;-webkit-box-orient:horizontal;-webkit-box-direction:normal;-ms-flex-direction:row;flex-direction:row;z-index:1}.flicking-camera>*{-ms-flex-negative:0;flex-shrink:0}.flicking-viewport.vertical{display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex}.flicking-viewport.vertical>.flicking-camera{display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column}.flicking-viewport.flicking-hidden .flicking-camera>*{visibility:hidden}
|
|
2
|
-
/*# sourceMappingURL=flicking.css.map */
|
package/dist/flicking.css.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["<input css 2>"],"names":[],"mappings":"AAAA,mBAAmB,iBAAiB,CAAC,eAAe,CAAC,iBAAiB,UAAU,CAAC,WAAW,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,YAAY,CAAC,iBAAiB,CAAC,6BAA6B,CAAC,4BAA4B,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,SAAS,CAAC,mBAAmB,mBAAmB,CAAC,aAAa,CAAC,4BAA4B,0BAA0B,CAAC,0BAA0B,CAAC,mBAAmB,CAAC,6CAA6C,0BAA0B,CAAC,0BAA0B,CAAC,mBAAmB,CAAC,2BAA2B,CAAC,4BAA4B,CAAC,yBAAyB,CAAC,qBAAqB,CAAC,sDAAsD,iBAAiB","file":"flicking.css","sourcesContent":[".flicking-viewport{position:relative;overflow:hidden}.flicking-camera{width:100%;height:100%;display:-webkit-box;display:-ms-flexbox;display:flex;position:relative;-webkit-box-orient:horizontal;-webkit-box-direction:normal;-ms-flex-direction:row;flex-direction:row;z-index:1}.flicking-camera>*{-ms-flex-negative:0;flex-shrink:0}.flicking-viewport.vertical{display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex}.flicking-viewport.vertical>.flicking-camera{display:-webkit-inline-box;display:-ms-inline-flexbox;display:inline-flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column}.flicking-viewport.flicking-hidden .flicking-camera>*{visibility:hidden}"]}
|
|
@@ -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;
|