@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@egjs/flicking",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "Everyday 30 million people experience. It's reliable, flexible and extendable carousel.",
|
|
5
5
|
"main": "dist/flicking.js",
|
|
6
6
|
"module": "dist/flicking.esm.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"jsdoc:watch": "npm-watch jsdoc",
|
|
23
23
|
"docs:build": "jsdoc-to-mdx -c ./jsdoc-to-mdx.json",
|
|
24
24
|
"docs:version": "node ./config/docs-version-up",
|
|
25
|
-
"docs:release": "npm run docs:build && npm run docs:version &&
|
|
25
|
+
"docs:release": "npm run docs:build && npm run docs:version && npm run build --prefix docs",
|
|
26
26
|
"demo:prebuild-version": "cpx 'dist/**/*' docs/build/release/$npm_package_version/dist --clean",
|
|
27
27
|
"demo:prebuild-latest": "cpx 'dist/**/*' docs/build/release/latest/dist --clean",
|
|
28
28
|
"demo:deploy": "npm run docs:release && npm run build && npm run demo:prebuild-version && npm run demo:prebuild-latest && gh-pages -d docs/build/ --add --remote upstream",
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"@rollup/plugin-replace": "^2.4.1",
|
|
80
80
|
"@types/fs-extra": "^9.0.11",
|
|
81
81
|
"@types/node": "^14.14.35",
|
|
82
|
+
"@types/resize-observer-browser": "^0.1.6",
|
|
82
83
|
"@typescript-eslint/eslint-plugin": "^4.18.0",
|
|
83
84
|
"@typescript-eslint/eslint-plugin-tslint": "^4.18.0",
|
|
84
85
|
"@typescript-eslint/parser": "^4.18.0",
|
|
@@ -121,7 +122,7 @@
|
|
|
121
122
|
"tslib": "^2.1.0",
|
|
122
123
|
"tslint": "^5.12.1",
|
|
123
124
|
"ttypescript": "^1.5.12",
|
|
124
|
-
"typescript": "^
|
|
125
|
+
"typescript": "^3.9.10",
|
|
125
126
|
"typescript-transform-paths": "^2.2.3"
|
|
126
127
|
},
|
|
127
128
|
"dependencies": {
|
package/src/Flicking.ts
CHANGED
|
@@ -11,9 +11,9 @@ import { Panel } from "./core/panel";
|
|
|
11
11
|
import { VanillaElementProvider } from "./core/panel/provider";
|
|
12
12
|
import VirtualManager, { VirtualOptions } from "./core/VirtualManager";
|
|
13
13
|
import { Control, SnapControl, SnapControlOptions, FreeControl, StrictControl, FreeControlOptions, StrictControlOptions } from "./control";
|
|
14
|
-
import {
|
|
14
|
+
import { Camera } from "./camera";
|
|
15
15
|
import { Renderer, VanillaRenderer, ExternalRenderer, RendererOptions, NormalRenderingStrategy, VirtualRenderingStrategy } from "./renderer";
|
|
16
|
-
import { EVENTS, ALIGN, MOVE_TYPE, DIRECTION } from "./const/external";
|
|
16
|
+
import { EVENTS, ALIGN, MOVE_TYPE, DIRECTION, CIRCULAR_FALLBACK } from "./const/external";
|
|
17
17
|
import * as ERROR from "./const/error";
|
|
18
18
|
import { findIndex, getElement, includes, parseElement } from "./utils";
|
|
19
19
|
import { HoldStartEvent, HoldEndEvent, MoveStartEvent, SelectEvent, MoveEvent, MoveEndEvent, WillChangeEvent, WillRestoreEvent, NeedPanelEvent, VisibleChangeEvent, ReachEdgeEvent, ReadyEvent, AfterResizeEvent, BeforeResizeEvent, ChangedEvent, RestoredEvent, PanelChangeEvent } from "./type/event";
|
|
@@ -52,6 +52,7 @@ export interface FlickingOptions {
|
|
|
52
52
|
defaultIndex: number;
|
|
53
53
|
horizontal: boolean;
|
|
54
54
|
circular: boolean;
|
|
55
|
+
circularFallback: LiteralUnion<ValueOf<typeof CIRCULAR_FALLBACK>>;
|
|
55
56
|
bound: boolean;
|
|
56
57
|
adaptive: boolean;
|
|
57
58
|
panelsPerView: number;
|
|
@@ -120,6 +121,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
120
121
|
private _defaultIndex: FlickingOptions["defaultIndex"];
|
|
121
122
|
private _horizontal: FlickingOptions["horizontal"];
|
|
122
123
|
private _circular: FlickingOptions["circular"];
|
|
124
|
+
private _circularFallback: FlickingOptions["circularFallback"];
|
|
123
125
|
private _bound: FlickingOptions["bound"];
|
|
124
126
|
private _adaptive: FlickingOptions["adaptive"];
|
|
125
127
|
private _panelsPerView: FlickingOptions["panelsPerView"];
|
|
@@ -218,7 +220,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
218
220
|
* @default false
|
|
219
221
|
* @readonly
|
|
220
222
|
*/
|
|
221
|
-
public get circularEnabled() { return this._camera.
|
|
223
|
+
public get circularEnabled() { return this._camera.circularEnabled; }
|
|
222
224
|
/**
|
|
223
225
|
* Whether the `virtual` option is enabled.
|
|
224
226
|
* The {@link Flicking#virtual virtual} option can't be enabled when {@link Flicking#panelsPerView panelsPerView} is less or equal than zero.
|
|
@@ -348,6 +350,18 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
348
350
|
* @default false
|
|
349
351
|
*/
|
|
350
352
|
public get circular() { return this._circular; }
|
|
353
|
+
/**
|
|
354
|
+
* Set panel control mode for the case when circular cannot be enabled.
|
|
355
|
+
* "linear" will set the view's range from the top of the first panel to the top of the last panel.
|
|
356
|
+
* "bound" will prevent the view from going out of the first/last panel, so it won't show empty spaces before/after the first/last panel.
|
|
357
|
+
* @ko 순환 모드 사용 불가능시 사용할 패널 조작 범위 설정 방식을 변경합니다.
|
|
358
|
+
* "linear" 사용시 시점이 첫번째 엘리먼트 위에서부터 마지막 엘리먼트 위까지 움직일 수 있도록 설정합니다.
|
|
359
|
+
* "bound" 사용시 시점이 첫번째 엘리먼트와 마지막 엘리먼트의 끝과 끝 사이에서 움직일 수 있도록 설정합니다.
|
|
360
|
+
* @see CIRCULAR_FALLBACK
|
|
361
|
+
* @type {string}
|
|
362
|
+
* @default "linear"
|
|
363
|
+
*/
|
|
364
|
+
public get circularFallback() { return this._circularFallback; }
|
|
351
365
|
/**
|
|
352
366
|
* Prevent the view(camera element) from going out of the first/last panel, so it won't show empty spaces before/after the first/last panel
|
|
353
367
|
* Only can be enabled when `circular=false`
|
|
@@ -718,6 +732,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
718
732
|
defaultIndex = 0,
|
|
719
733
|
horizontal = true,
|
|
720
734
|
circular = false,
|
|
735
|
+
circularFallback = CIRCULAR_FALLBACK.LINEAR,
|
|
721
736
|
bound = false,
|
|
722
737
|
adaptive = false,
|
|
723
738
|
panelsPerView = -1,
|
|
@@ -755,6 +770,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
755
770
|
this._defaultIndex = defaultIndex;
|
|
756
771
|
this._horizontal = horizontal;
|
|
757
772
|
this._circular = circular;
|
|
773
|
+
this._circularFallback = circularFallback;
|
|
758
774
|
this._bound = bound;
|
|
759
775
|
this._adaptive = adaptive;
|
|
760
776
|
this._panelsPerView = panelsPerView;
|
|
@@ -1358,19 +1374,14 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
1358
1374
|
}
|
|
1359
1375
|
|
|
1360
1376
|
private _createCamera(): Camera {
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
if (this._bound) {
|
|
1365
|
-
// eslint-disable-next-line no-console
|
|
1366
|
-
console.warn("\"circular\" and \"bound\" option cannot be used together, ignoring bound.");
|
|
1367
|
-
}
|
|
1368
|
-
return new CircularCamera(cameraOption);
|
|
1369
|
-
} else if (this._bound) {
|
|
1370
|
-
return new BoundCamera(cameraOption);
|
|
1371
|
-
} else {
|
|
1372
|
-
return new LinearCamera(cameraOption);
|
|
1377
|
+
if (this._circular && this._bound) {
|
|
1378
|
+
// eslint-disable-next-line no-console
|
|
1379
|
+
console.warn("\"circular\" and \"bound\" option cannot be used together, ignoring bound.");
|
|
1373
1380
|
}
|
|
1381
|
+
|
|
1382
|
+
return new Camera({
|
|
1383
|
+
align: this._align
|
|
1384
|
+
});
|
|
1374
1385
|
}
|
|
1375
1386
|
|
|
1376
1387
|
private _createRenderer(): Renderer {
|
package/src/camera/Camera.ts
CHANGED
|
@@ -9,8 +9,10 @@ import FlickingError from "../core/FlickingError";
|
|
|
9
9
|
import Panel from "../core/panel/Panel";
|
|
10
10
|
import AnchorPoint from "../core/AnchorPoint";
|
|
11
11
|
import * as ERROR from "../const/error";
|
|
12
|
-
import { ALIGN, DIRECTION, EVENTS } from "../const/external";
|
|
13
|
-
import { checkExistence,
|
|
12
|
+
import { ALIGN, CIRCULAR_FALLBACK, DIRECTION, EVENTS } from "../const/external";
|
|
13
|
+
import { checkExistence, find, getFlickingAttached, getProgress, includes, parseAlign, toArray } from "../utils";
|
|
14
|
+
|
|
15
|
+
import { CameraMode, BoundCameraMode, CircularCameraMode, LinearCameraMode } from "./mode";
|
|
14
16
|
|
|
15
17
|
export interface CameraOptions {
|
|
16
18
|
align: FlickingOptions["align"];
|
|
@@ -20,21 +22,24 @@ export interface CameraOptions {
|
|
|
20
22
|
* A component that manages actual movement inside the viewport
|
|
21
23
|
* @ko 뷰포트 내에서의 실제 움직임을 담당하는 컴포넌트
|
|
22
24
|
*/
|
|
23
|
-
|
|
25
|
+
class Camera {
|
|
24
26
|
// Options
|
|
25
|
-
|
|
27
|
+
private _align: FlickingOptions["align"];
|
|
26
28
|
|
|
27
29
|
// Internal states
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
private _flicking: Flicking | null;
|
|
31
|
+
private _mode: CameraMode;
|
|
32
|
+
private _el: HTMLElement;
|
|
33
|
+
private _transform: string;
|
|
34
|
+
private _position: number;
|
|
35
|
+
private _alignPos: number;
|
|
36
|
+
private _offset: number;
|
|
37
|
+
private _circularOffset: number;
|
|
38
|
+
private _circularEnabled: boolean;
|
|
39
|
+
private _range: { min: number; max: number };
|
|
40
|
+
private _visiblePanels: Panel[];
|
|
41
|
+
private _anchors: AnchorPoint[];
|
|
42
|
+
private _needPanelTriggered: { prev: boolean; next: boolean };
|
|
38
43
|
|
|
39
44
|
// Internal states getter
|
|
40
45
|
/**
|
|
@@ -72,7 +77,23 @@ abstract class Camera {
|
|
|
72
77
|
* @default 0
|
|
73
78
|
* @readonly
|
|
74
79
|
*/
|
|
75
|
-
public get offset() { return this._offset; }
|
|
80
|
+
public get offset() { return this._offset - this._circularOffset; }
|
|
81
|
+
/**
|
|
82
|
+
* Whether the `circular` option is enabled.
|
|
83
|
+
* The {@link Flicking#circular circular} option can't be enabled when sum of the panel sizes are too small.
|
|
84
|
+
* @ko {@link Flicking#circular circular} 옵션이 활성화되었는지 여부를 나타내는 멤버 변수.
|
|
85
|
+
* {@link Flicking#circular circular} 옵션은 패널의 크기의 합이 충분하지 않을 경우 비활성화됩니다.
|
|
86
|
+
* @type {boolean}
|
|
87
|
+
* @default false
|
|
88
|
+
* @readonly
|
|
89
|
+
*/
|
|
90
|
+
public get circularEnabled() { return this._circularEnabled; }
|
|
91
|
+
/**
|
|
92
|
+
* A current camera mode
|
|
93
|
+
* @type {CameraMode}
|
|
94
|
+
* @readonly
|
|
95
|
+
*/
|
|
96
|
+
public get mode() { return this._mode; }
|
|
76
97
|
/**
|
|
77
98
|
* A range that Camera's {@link Camera#position position} can reach
|
|
78
99
|
* @ko Camera의 {@link Camera#position position}이 도달 가능한 범위
|
|
@@ -118,7 +139,7 @@ abstract class Camera {
|
|
|
118
139
|
* @type {ControlParams}
|
|
119
140
|
* @readonly
|
|
120
141
|
*/
|
|
121
|
-
public get controlParams() { return { range: this._range, position: this._position, circular:
|
|
142
|
+
public get controlParams() { return { range: this._range, position: this._position, circular: this._circularEnabled }; }
|
|
122
143
|
/**
|
|
123
144
|
* A Boolean value indicating whether Camera's over the minimum or maximum position reachable
|
|
124
145
|
* @ko 현재 카메라가 도달 가능한 범위의 최소 혹은 최대점을 넘어섰는지를 나타냅니다
|
|
@@ -220,22 +241,6 @@ abstract class Camera {
|
|
|
220
241
|
this._align = align;
|
|
221
242
|
}
|
|
222
243
|
|
|
223
|
-
/**
|
|
224
|
-
* Update {@link Camera#range range} of Camera
|
|
225
|
-
* @ko Camera의 {@link Camera#range range}를 업데이트합니다
|
|
226
|
-
* @method
|
|
227
|
-
* @abstract
|
|
228
|
-
* @memberof Camera
|
|
229
|
-
* @instance
|
|
230
|
-
* @name updateRange
|
|
231
|
-
* @chainable
|
|
232
|
-
* @throws {FlickingError}
|
|
233
|
-
* {@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} When {@link Camera#init init} is not called before
|
|
234
|
-
* <ko>{@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} {@link Camera#init init}이 이전에 호출되지 않은 경우</ko>
|
|
235
|
-
* @return {this}
|
|
236
|
-
*/
|
|
237
|
-
public abstract updateRange(): this;
|
|
238
|
-
|
|
239
244
|
/**
|
|
240
245
|
* Initialize Camera
|
|
241
246
|
* @ko Camera를 초기화합니다
|
|
@@ -255,6 +260,8 @@ abstract class Camera {
|
|
|
255
260
|
this._el = viewportEl.firstElementChild as HTMLElement;
|
|
256
261
|
this._checkTranslateSupport();
|
|
257
262
|
|
|
263
|
+
this._updateMode();
|
|
264
|
+
|
|
258
265
|
return this;
|
|
259
266
|
}
|
|
260
267
|
|
|
@@ -279,13 +286,21 @@ abstract class Camera {
|
|
|
279
286
|
* @return {this}
|
|
280
287
|
*/
|
|
281
288
|
public lookAt(pos: number): void {
|
|
289
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
282
290
|
const prevPos = this._position;
|
|
283
291
|
|
|
284
292
|
this._position = pos;
|
|
293
|
+
const toggled = this._togglePanels(prevPos, pos);
|
|
285
294
|
this._refreshVisiblePanels();
|
|
286
295
|
this._checkNeedPanel();
|
|
287
296
|
this._checkReachEnd(prevPos, pos);
|
|
288
297
|
this.applyTransform();
|
|
298
|
+
|
|
299
|
+
if (toggled) {
|
|
300
|
+
void flicking.renderer.render().then(() => {
|
|
301
|
+
this.updateOffset();
|
|
302
|
+
});
|
|
303
|
+
}
|
|
289
304
|
}
|
|
290
305
|
|
|
291
306
|
/**
|
|
@@ -297,7 +312,19 @@ abstract class Camera {
|
|
|
297
312
|
* @return {AnchorPoint | null} The previous {@link AnchorPoint}<ko>이전 {@link AnchorPoint}</ko>
|
|
298
313
|
*/
|
|
299
314
|
public getPrevAnchor(anchor: AnchorPoint): AnchorPoint | null {
|
|
300
|
-
|
|
315
|
+
if (!this._circularEnabled || anchor.index !== 0) {
|
|
316
|
+
return this._anchors[anchor.index - 1] || null;
|
|
317
|
+
} else {
|
|
318
|
+
const anchors = this._anchors;
|
|
319
|
+
const rangeDiff = this.rangeDiff;
|
|
320
|
+
const lastAnchor = anchors[anchors.length - 1];
|
|
321
|
+
|
|
322
|
+
return new AnchorPoint({
|
|
323
|
+
index: lastAnchor.index,
|
|
324
|
+
position: lastAnchor.position - rangeDiff,
|
|
325
|
+
panel: lastAnchor.panel
|
|
326
|
+
});
|
|
327
|
+
}
|
|
301
328
|
}
|
|
302
329
|
|
|
303
330
|
/**
|
|
@@ -309,7 +336,20 @@ abstract class Camera {
|
|
|
309
336
|
* @return {AnchorPoint | null} The next {@link AnchorPoint}<ko>다음 {@link AnchorPoint}</ko>
|
|
310
337
|
*/
|
|
311
338
|
public getNextAnchor(anchor: AnchorPoint): AnchorPoint | null {
|
|
312
|
-
|
|
339
|
+
const anchors = this._anchors;
|
|
340
|
+
|
|
341
|
+
if (!this._circularEnabled || anchor.index !== anchors.length - 1) {
|
|
342
|
+
return anchors[anchor.index + 1] || null;
|
|
343
|
+
} else {
|
|
344
|
+
const rangeDiff = this.rangeDiff;
|
|
345
|
+
const firstAnchor = anchors[0];
|
|
346
|
+
|
|
347
|
+
return new AnchorPoint({
|
|
348
|
+
index: firstAnchor.index,
|
|
349
|
+
position: firstAnchor.position + rangeDiff,
|
|
350
|
+
panel: firstAnchor.panel
|
|
351
|
+
});
|
|
352
|
+
}
|
|
313
353
|
}
|
|
314
354
|
|
|
315
355
|
/**
|
|
@@ -335,16 +375,7 @@ abstract class Camera {
|
|
|
335
375
|
* @return {AnchorPoint | null} The {@link AnchorPoint} that includes the given position<ko>해당 좌표를 포함하는 {@link AnchorPoint}</ko>
|
|
336
376
|
*/
|
|
337
377
|
public findAnchorIncludePosition(position: number): AnchorPoint | null {
|
|
338
|
-
|
|
339
|
-
const anchorsIncludingPosition = anchors.filter(anchor => anchor.panel.includePosition(position, true));
|
|
340
|
-
|
|
341
|
-
return anchorsIncludingPosition.reduce((nearest: AnchorPoint | null, anchor) => {
|
|
342
|
-
if (!nearest) return anchor;
|
|
343
|
-
|
|
344
|
-
return Math.abs(nearest.position - position) < Math.abs(anchor.position - position)
|
|
345
|
-
? nearest
|
|
346
|
-
: anchor;
|
|
347
|
-
}, null);
|
|
378
|
+
return this._mode.findAnchorIncludePosition(position);
|
|
348
379
|
}
|
|
349
380
|
|
|
350
381
|
/**
|
|
@@ -396,8 +427,7 @@ abstract class Camera {
|
|
|
396
427
|
* @return {number} A clamped position<ko>범위 제한된 좌표</ko>
|
|
397
428
|
*/
|
|
398
429
|
public clampToReachablePosition(position: number): number {
|
|
399
|
-
|
|
400
|
-
return clamp(position, range.min, range.max);
|
|
430
|
+
return this._mode.clampToReachablePosition(position);
|
|
401
431
|
}
|
|
402
432
|
|
|
403
433
|
/**
|
|
@@ -407,13 +437,7 @@ abstract class Camera {
|
|
|
407
437
|
* @return {boolean} Whether the panel's inside Camera's range<ko>도달 가능한 범위 내에 해당 패널이 존재하는지 여부</ko>
|
|
408
438
|
*/
|
|
409
439
|
public canReach(panel: Panel): boolean {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
if (panel.removed) return false;
|
|
413
|
-
|
|
414
|
-
const panelPos = panel.position;
|
|
415
|
-
|
|
416
|
-
return panelPos >= range.min && panelPos <= range.max;
|
|
440
|
+
return this._mode.canReach(panel);
|
|
417
441
|
}
|
|
418
442
|
|
|
419
443
|
/**
|
|
@@ -423,9 +447,38 @@ abstract class Camera {
|
|
|
423
447
|
* @return Whether the panel element is visible at the current position<ko>현재 위치에서 해당 패널 엘리먼트가 보이는지 여부</ko>
|
|
424
448
|
*/
|
|
425
449
|
public canSee(panel: Panel): boolean {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
450
|
+
return this._mode.canSee(panel);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Update {@link Camera#range range} of Camera
|
|
455
|
+
* @ko Camera의 {@link Camera#range range}를 업데이트합니다
|
|
456
|
+
* @method
|
|
457
|
+
* @abstract
|
|
458
|
+
* @memberof Camera
|
|
459
|
+
* @instance
|
|
460
|
+
* @name updateRange
|
|
461
|
+
* @chainable
|
|
462
|
+
* @throws {FlickingError}
|
|
463
|
+
* {@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} When {@link Camera#init init} is not called before
|
|
464
|
+
* <ko>{@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} {@link Camera#init init}이 이전에 호출되지 않은 경우</ko>
|
|
465
|
+
* @return {this}
|
|
466
|
+
*/
|
|
467
|
+
public updateRange() {
|
|
468
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
469
|
+
const renderer = flicking.renderer;
|
|
470
|
+
const panels = renderer.panels;
|
|
471
|
+
|
|
472
|
+
this._updateMode();
|
|
473
|
+
this._range = this._mode.getRange();
|
|
474
|
+
|
|
475
|
+
if (this._circularEnabled) {
|
|
476
|
+
panels.forEach(panel => panel.updateCircularToggleDirection());
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
this.updateOffset();
|
|
480
|
+
|
|
481
|
+
return this;
|
|
429
482
|
}
|
|
430
483
|
|
|
431
484
|
/**
|
|
@@ -456,14 +509,7 @@ abstract class Camera {
|
|
|
456
509
|
* @return {this}
|
|
457
510
|
*/
|
|
458
511
|
public updateAnchors(): this {
|
|
459
|
-
|
|
460
|
-
const panels = flicking.renderer.panels;
|
|
461
|
-
|
|
462
|
-
this._anchors = panels.map((panel, index) => new AnchorPoint({
|
|
463
|
-
index,
|
|
464
|
-
position: panel.position,
|
|
465
|
-
panel
|
|
466
|
-
}));
|
|
512
|
+
this._anchors = this._mode.getAnchors();
|
|
467
513
|
|
|
468
514
|
return this;
|
|
469
515
|
}
|
|
@@ -503,6 +549,8 @@ abstract class Camera {
|
|
|
503
549
|
.filter(panel => panel.position + panel.offset < position)
|
|
504
550
|
.reduce((offset, panel) => offset + panel.sizeIncludingMargin, 0);
|
|
505
551
|
|
|
552
|
+
this._circularOffset = this._mode.getCircularOffset();
|
|
553
|
+
|
|
506
554
|
this.applyTransform();
|
|
507
555
|
|
|
508
556
|
return this;
|
|
@@ -529,7 +577,7 @@ abstract class Camera {
|
|
|
529
577
|
const el = this._el;
|
|
530
578
|
const flicking = getFlickingAttached(this._flicking);
|
|
531
579
|
|
|
532
|
-
const actualPosition = this._position - this._alignPos - this._offset;
|
|
580
|
+
const actualPosition = this._position - this._alignPos - this._offset + this._circularOffset;
|
|
533
581
|
|
|
534
582
|
el.style[this._transform] = flicking.horizontal
|
|
535
583
|
? `translate(${-actualPosition}px)`
|
|
@@ -538,17 +586,19 @@ abstract class Camera {
|
|
|
538
586
|
return this;
|
|
539
587
|
}
|
|
540
588
|
|
|
541
|
-
|
|
589
|
+
private _resetInternalValues() {
|
|
542
590
|
this._position = 0;
|
|
543
591
|
this._alignPos = 0;
|
|
544
592
|
this._offset = 0;
|
|
593
|
+
this._circularOffset = 0;
|
|
594
|
+
this._circularEnabled = false;
|
|
545
595
|
this._range = { min: 0, max: 0 };
|
|
546
596
|
this._visiblePanels = [];
|
|
547
597
|
this._anchors = [];
|
|
548
598
|
this._needPanelTriggered = { prev: false, next: false };
|
|
549
599
|
}
|
|
550
600
|
|
|
551
|
-
|
|
601
|
+
private _refreshVisiblePanels() {
|
|
552
602
|
const flicking = getFlickingAttached(this._flicking);
|
|
553
603
|
const panels = flicking.renderer.panels;
|
|
554
604
|
|
|
@@ -570,7 +620,7 @@ abstract class Camera {
|
|
|
570
620
|
}
|
|
571
621
|
}
|
|
572
622
|
|
|
573
|
-
|
|
623
|
+
private _checkNeedPanel(): void {
|
|
574
624
|
const needPanelTriggered = this._needPanelTriggered;
|
|
575
625
|
|
|
576
626
|
if (needPanelTriggered.prev && needPanelTriggered.next) return;
|
|
@@ -621,7 +671,7 @@ abstract class Camera {
|
|
|
621
671
|
}
|
|
622
672
|
}
|
|
623
673
|
|
|
624
|
-
|
|
674
|
+
private _checkReachEnd(prevPos: number, newPos: number): void {
|
|
625
675
|
const flicking = getFlickingAttached(this._flicking);
|
|
626
676
|
const range = this._range;
|
|
627
677
|
|
|
@@ -637,7 +687,7 @@ abstract class Camera {
|
|
|
637
687
|
}));
|
|
638
688
|
}
|
|
639
689
|
|
|
640
|
-
|
|
690
|
+
private _checkTranslateSupport = () => {
|
|
641
691
|
const transforms = ["webkitTransform", "msTransform", "MozTransform", "OTransform", "transform"];
|
|
642
692
|
|
|
643
693
|
const supportedStyle = document.documentElement.style;
|
|
@@ -654,6 +704,41 @@ abstract class Camera {
|
|
|
654
704
|
|
|
655
705
|
this._transform = transformName;
|
|
656
706
|
};
|
|
707
|
+
|
|
708
|
+
private _updateMode() {
|
|
709
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
710
|
+
|
|
711
|
+
if (flicking.circular) {
|
|
712
|
+
const circularMode = new CircularCameraMode(flicking);
|
|
713
|
+
const canSetCircularMode = circularMode.checkAvailability();
|
|
714
|
+
|
|
715
|
+
if (canSetCircularMode) {
|
|
716
|
+
this._mode = circularMode;
|
|
717
|
+
} else {
|
|
718
|
+
const fallbackMode = flicking.circularFallback;
|
|
719
|
+
|
|
720
|
+
this._mode = fallbackMode === CIRCULAR_FALLBACK.BOUND
|
|
721
|
+
? new BoundCameraMode(flicking)
|
|
722
|
+
: new LinearCameraMode(flicking);
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
this._circularEnabled = canSetCircularMode;
|
|
726
|
+
} else {
|
|
727
|
+
this._mode = flicking.bound
|
|
728
|
+
? new BoundCameraMode(flicking)
|
|
729
|
+
: new LinearCameraMode(flicking);
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
private _togglePanels(prevPos: number, pos: number): boolean {
|
|
734
|
+
if (pos === prevPos) return false;
|
|
735
|
+
|
|
736
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
737
|
+
const panels = flicking.renderer.panels;
|
|
738
|
+
const toggled = panels.map(panel => panel.toggle(prevPos, pos));
|
|
739
|
+
|
|
740
|
+
return toggled.some(isToggled => isToggled);
|
|
741
|
+
}
|
|
657
742
|
}
|
|
658
743
|
|
|
659
744
|
export default Camera;
|
package/src/camera/index.ts
CHANGED
|
@@ -3,17 +3,13 @@
|
|
|
3
3
|
* egjs projects are licensed under the MIT license
|
|
4
4
|
*/
|
|
5
5
|
import Camera, { CameraOptions } from "./Camera";
|
|
6
|
-
import LinearCamera from "./LinearCamera";
|
|
7
|
-
import CircularCamera from "./CircularCamera";
|
|
8
|
-
import BoundCamera from "./BoundCamera";
|
|
9
6
|
|
|
10
7
|
export {
|
|
11
|
-
Camera
|
|
12
|
-
LinearCamera,
|
|
13
|
-
CircularCamera,
|
|
14
|
-
BoundCamera
|
|
8
|
+
Camera
|
|
15
9
|
};
|
|
16
10
|
|
|
17
11
|
export type {
|
|
18
12
|
CameraOptions
|
|
19
13
|
};
|
|
14
|
+
|
|
15
|
+
export * from "./mode";
|