@egjs/flicking 4.2.4 → 4.4.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/README.md +1 -1
- package/declaration/Flicking.d.ts +24 -11
- package/declaration/camera/Camera.d.ts +5 -4
- package/declaration/camera/CircularCamera.d.ts +3 -2
- package/declaration/const/error.d.ts +3 -1
- package/declaration/const/external.d.ts +5 -0
- package/declaration/control/Control.d.ts +2 -2
- package/declaration/control/FreeControl.d.ts +1 -1
- package/declaration/control/StrictControl.d.ts +1 -1
- package/declaration/control/states/State.d.ts +2 -1
- package/declaration/core/AutoResizer.d.ts +13 -0
- package/declaration/core/VirtualManager.d.ts +37 -0
- package/declaration/core/index.d.ts +2 -1
- package/declaration/core/panel/ExternalPanel.d.ts +9 -5
- package/declaration/core/panel/Panel.d.ts +17 -10
- package/declaration/core/panel/VirtualPanel.d.ts +19 -0
- package/declaration/core/panel/index.d.ts +4 -3
- package/declaration/core/panel/provider/ElementProvider.d.ts +7 -0
- package/declaration/core/panel/provider/ExternalElementProvider.d.ts +8 -0
- package/declaration/core/panel/provider/VanillaElementProvider.d.ts +10 -0
- package/declaration/core/panel/provider/VirtualElementProvider.d.ts +13 -0
- package/declaration/core/panel/provider/index.d.ts +6 -0
- package/declaration/index.d.ts +11 -1
- package/declaration/renderer/ExternalRenderer.d.ts +1 -0
- package/declaration/renderer/Renderer.d.ts +18 -13
- package/declaration/renderer/VanillaRenderer.d.ts +2 -7
- package/declaration/renderer/index.d.ts +1 -0
- package/declaration/renderer/strategy/NormalRenderingStrategy.d.ts +25 -0
- package/declaration/renderer/strategy/RenderingStrategy.d.ts +15 -0
- package/declaration/renderer/strategy/VirtualRenderingStrategy.d.ts +17 -0
- package/declaration/renderer/strategy/index.d.ts +5 -0
- package/declaration/utils.d.ts +7 -1
- package/dist/flicking.esm.js +4649 -3767
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.js +4689 -3783
- 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 +4359 -2062
- 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 -1
- package/src/Flicking.ts +148 -30
- package/src/camera/BoundCamera.ts +2 -2
- package/src/camera/Camera.ts +59 -36
- package/src/camera/CircularCamera.ts +54 -29
- package/src/camera/LinearCamera.ts +1 -1
- package/src/cfc/getRenderingPanels.ts +6 -1
- package/src/cfc/sync.ts +2 -2
- package/src/const/error.ts +6 -3
- package/src/const/external.ts +6 -0
- package/src/control/AxesController.ts +17 -9
- package/src/control/Control.ts +37 -39
- package/src/control/FreeControl.ts +4 -4
- package/src/control/SnapControl.ts +3 -3
- package/src/control/StrictControl.ts +4 -4
- package/src/control/states/AnimatingState.ts +6 -3
- package/src/control/states/State.ts +4 -2
- package/src/core/AutoResizer.ts +81 -0
- package/src/core/VirtualManager.ts +188 -0
- package/src/core/index.ts +3 -1
- package/src/core/panel/ExternalPanel.ts +23 -15
- package/src/core/panel/Panel.ts +68 -60
- package/src/core/panel/VirtualPanel.ts +110 -0
- package/src/core/panel/index.ts +5 -4
- package/src/core/panel/provider/ElementProvider.ts +13 -0
- package/src/core/panel/provider/ExternalElementProvider.ts +15 -0
- package/src/core/panel/provider/VanillaElementProvider.ts +40 -0
- package/src/core/panel/provider/VirtualElementProvider.ts +45 -0
- package/src/core/panel/provider/index.ts +18 -0
- package/src/index.ts +12 -1
- package/src/index.umd.ts +2 -0
- package/src/renderer/ExternalRenderer.ts +36 -4
- package/src/renderer/Renderer.ts +174 -69
- package/src/renderer/VanillaRenderer.ts +28 -86
- package/src/renderer/index.ts +2 -0
- package/src/renderer/strategy/NormalRenderingStrategy.ts +109 -0
- package/src/renderer/strategy/RenderingStrategy.ts +21 -0
- package/src/renderer/strategy/VirtualRenderingStrategy.ts +110 -0
- package/src/renderer/strategy/index.ts +17 -0
- package/src/utils.ts +36 -2
- package/declaration/core/panel/ElementPanel.d.ts +0 -14
- package/declaration/exports.d.ts +0 -10
- package/src/core/panel/ElementPanel.ts +0 -52
- package/src/exports.ts +0 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@egjs/flicking",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.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",
|
|
@@ -140,6 +140,7 @@
|
|
|
140
140
|
"dependencies": {
|
|
141
141
|
"@egjs/axes": "^2.8.0",
|
|
142
142
|
"@egjs/component": "^3.0.1",
|
|
143
|
+
"@egjs/imready": "^1.1.3",
|
|
143
144
|
"@egjs/list-differ": "^1.0.0"
|
|
144
145
|
},
|
|
145
146
|
"husky": {
|
package/src/Flicking.ts
CHANGED
|
@@ -6,10 +6,13 @@ import Component, { ComponentEvent } from "@egjs/component";
|
|
|
6
6
|
|
|
7
7
|
import FlickingError from "./core/FlickingError";
|
|
8
8
|
import Viewport from "./core/Viewport";
|
|
9
|
+
import AutoResizer from "./core/AutoResizer";
|
|
9
10
|
import { Panel } from "./core/panel";
|
|
11
|
+
import { VanillaElementProvider } from "./core/panel/provider";
|
|
12
|
+
import VirtualManager, { VirtualOptions } from "./core/VirtualManager";
|
|
10
13
|
import { Control, SnapControl, SnapControlOptions, FreeControl, StrictControl, FreeControlOptions, StrictControlOptions } from "./control";
|
|
11
14
|
import { BoundCamera, Camera, CircularCamera, LinearCamera } from "./camera";
|
|
12
|
-
import { Renderer, VanillaRenderer, ExternalRenderer } from "./renderer";
|
|
15
|
+
import { Renderer, VanillaRenderer, ExternalRenderer, RendererOptions, NormalRenderingStrategy, VirtualRenderingStrategy } from "./renderer";
|
|
13
16
|
import { EVENTS, ALIGN, MOVE_TYPE, DIRECTION } from "./const/external";
|
|
14
17
|
import * as ERROR from "./const/error";
|
|
15
18
|
import { findIndex, getElement, includes, parseElement } from "./utils";
|
|
@@ -53,6 +56,7 @@ export interface FlickingOptions {
|
|
|
53
56
|
adaptive: boolean;
|
|
54
57
|
panelsPerView: number;
|
|
55
58
|
noPanelStyleOverride: boolean;
|
|
59
|
+
resizeOnContentsReady: boolean;
|
|
56
60
|
// EVENT
|
|
57
61
|
needPanelThreshold: number;
|
|
58
62
|
preventEventsBeforeInit: boolean;
|
|
@@ -71,12 +75,14 @@ export interface FlickingOptions {
|
|
|
71
75
|
disableOnInit: boolean;
|
|
72
76
|
// PERFORMANCE
|
|
73
77
|
renderOnlyVisible: boolean;
|
|
78
|
+
virtual: VirtualOptions | null;
|
|
74
79
|
// OTHERS
|
|
75
80
|
autoInit: boolean;
|
|
76
81
|
autoResize: boolean;
|
|
82
|
+
useResizeObserver: boolean;
|
|
77
83
|
renderExternal: {
|
|
78
|
-
renderer:
|
|
79
|
-
rendererOptions:
|
|
84
|
+
renderer: new (options: RendererOptions) => ExternalRenderer;
|
|
85
|
+
rendererOptions: RendererOptions;
|
|
80
86
|
} | null;
|
|
81
87
|
}
|
|
82
88
|
|
|
@@ -101,9 +107,11 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
101
107
|
|
|
102
108
|
// Core components
|
|
103
109
|
private _viewport: Viewport;
|
|
110
|
+
private _autoResizer: AutoResizer;
|
|
104
111
|
private _camera: Camera;
|
|
105
112
|
private _control: Control;
|
|
106
113
|
private _renderer: Renderer;
|
|
114
|
+
private _virtualManager: VirtualManager;
|
|
107
115
|
|
|
108
116
|
// Options
|
|
109
117
|
private _align: FlickingOptions["align"];
|
|
@@ -114,6 +122,8 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
114
122
|
private _adaptive: FlickingOptions["adaptive"];
|
|
115
123
|
private _panelsPerView: FlickingOptions["panelsPerView"];
|
|
116
124
|
private _noPanelStyleOverride: FlickingOptions["noPanelStyleOverride"];
|
|
125
|
+
private _resizeOnContentsReady: FlickingOptions["resizeOnContentsReady"];
|
|
126
|
+
private _virtual: FlickingOptions["virtual"];
|
|
117
127
|
|
|
118
128
|
private _needPanelThreshold: FlickingOptions["needPanelThreshold"];
|
|
119
129
|
private _preventEventsBeforeInit: FlickingOptions["preventEventsBeforeInit"];
|
|
@@ -133,8 +143,9 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
133
143
|
|
|
134
144
|
private _renderOnlyVisible: FlickingOptions["renderOnlyVisible"];
|
|
135
145
|
|
|
136
|
-
private _autoResize: FlickingOptions["autoResize"];
|
|
137
146
|
private _autoInit: FlickingOptions["autoInit"];
|
|
147
|
+
private _autoResize: FlickingOptions["autoResize"];
|
|
148
|
+
private _useResizeObserver: FlickingOptions["useResizeObserver"];
|
|
138
149
|
private _renderExternal: FlickingOptions["renderExternal"];
|
|
139
150
|
|
|
140
151
|
// Internal State
|
|
@@ -205,6 +216,16 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
205
216
|
* @readonly
|
|
206
217
|
*/
|
|
207
218
|
public get circularEnabled() { return this._camera.controlParams.circular; }
|
|
219
|
+
/**
|
|
220
|
+
* Whether the `virtual` option is enabled.
|
|
221
|
+
* The {@link Flicking#virtual virtual} option can't be enabled when {@link Flicking#panelsPerView panelsPerView} is less or equal than zero.
|
|
222
|
+
* @ko {@link Flicking#virtual virtual} 옵션이 활성화되었는지 여부를 나타내는 멤버 변수.
|
|
223
|
+
* {@link Flicking#virtual virtual} 옵션은 {@link Flicking#panelsPerView panelsPerView} 옵션의 값이 0보다 같거나 작으면 비활성화됩니다.
|
|
224
|
+
* @type {boolean}
|
|
225
|
+
* @default false
|
|
226
|
+
* @readonly
|
|
227
|
+
*/
|
|
228
|
+
public get virtualEnabled() { return this._panelsPerView > 0 && this._virtual != null; }
|
|
208
229
|
/**
|
|
209
230
|
* Index number of the {@link Flicking#currentPanel currentPanel}
|
|
210
231
|
* @ko {@link Flicking#currentPanel currentPanel}의 인덱스 번호
|
|
@@ -356,6 +377,15 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
356
377
|
* @default false
|
|
357
378
|
*/
|
|
358
379
|
public get noPanelStyleOverride() { return this._noPanelStyleOverride; }
|
|
380
|
+
/**
|
|
381
|
+
* Enabling this option will automatically call {@link Flicking#resize} when all image/video inside panels are loaded.
|
|
382
|
+
* This can be useful when you have contents inside Flicking that changes its size when it's loaded
|
|
383
|
+
* @ko 이 옵션을 활성화할 경우, Flicking 패널 내부의 이미지/비디오들이 로드되었을 때 자동으로 {@link Flicking#resize}를 호출합니다.
|
|
384
|
+
* 이 동작은 Flicking 내부에 로드 전/후로 크기가 변하는 콘텐츠를 포함하고 있을 때 유용하게 사용하실 수 있습니다.
|
|
385
|
+
* @type {boolean}
|
|
386
|
+
* @default false
|
|
387
|
+
*/
|
|
388
|
+
public get resizeOnContentsReady() { return this._resizeOnContentsReady; }
|
|
359
389
|
// EVENTS
|
|
360
390
|
/**
|
|
361
391
|
* A Threshold from viewport edge before triggering `needPanel` event
|
|
@@ -504,12 +534,45 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
504
534
|
public get disableOnInit() { return this._disableOnInit; }
|
|
505
535
|
// PERFORMANCE
|
|
506
536
|
/**
|
|
507
|
-
* Whether to render visible panels only. This can dramatically increase performance when there're many panels
|
|
508
|
-
* @ko 보이는 패널만 렌더링할지 여부를 설정합니다. 패널이 많을 경우에 퍼포먼스를 크게 향상시킬 수
|
|
537
|
+
* Whether to render visible panels only. This can dramatically increase performance when there're many panels
|
|
538
|
+
* @ko 보이는 패널만 렌더링할지 여부를 설정합니다. 패널이 많을 경우에 퍼포먼스를 크게 향상시킬 수 있습니다
|
|
509
539
|
* @type {boolean}
|
|
510
540
|
* @default false
|
|
511
541
|
*/
|
|
512
542
|
public get renderOnlyVisible() { return this._renderOnlyVisible; }
|
|
543
|
+
/**
|
|
544
|
+
* By enabling this option, it will reduce memory consumption by restricting the number of DOM elements to `panelsPerView + 1`
|
|
545
|
+
* Must be used with `panelsPerview`.
|
|
546
|
+
* After Flicking's initialized, this property can be used to add/remove the panel count.
|
|
547
|
+
* @ko 이 옵션을 활성화할 경우 패널 엘리먼트의 개수를 `panelsPerView + 1` 개로 고정함으로써, 메모리 사용량을 줄일 수 있습니다.
|
|
548
|
+
* `panelsPerView` 옵션과 함께 사용되어야만 합니다.
|
|
549
|
+
* Flicking 초기화 이후에, 이 프로퍼티는 렌더링하는 패널의 개수를 추가/제거하기 위해 사용될 수 있습니다.
|
|
550
|
+
* @type {VirtualManager}
|
|
551
|
+
* @property {function} renderPanel A rendering function for the panel element's innerHTML<ko>패널 엘리먼트의 innerHTML을 렌더링하는 함수</ko>
|
|
552
|
+
* @property {number} initialPanelCount Initial panel count to render<ko>최초로 렌더링할 패널의 개수</ko>
|
|
553
|
+
* @property {boolean} [cache=false] Whether to cache rendered panel's innerHTML<ko>렌더링된 패널의 innerHTML 정보를 캐시할지 여부</ko>
|
|
554
|
+
* @property {string} [panelClass="flicking-panel"] The class name that will be applied to rendered panel elements<ko>렌더링되는 패널 엘리먼트에 적용될 클래스 이름</ko>
|
|
555
|
+
* @example
|
|
556
|
+
* ```ts
|
|
557
|
+
* import Flicking, { VirtualPanel } from "@egjs/flicking";
|
|
558
|
+
*
|
|
559
|
+
* const flicking = new Flicking("#some_el", {
|
|
560
|
+
* panelsPerView: 3,
|
|
561
|
+
* virtual: {
|
|
562
|
+
* renderPanel: (panel: VirtualPanel, index: number) => `Panel ${index}`,
|
|
563
|
+
* initialPanelCount: 100
|
|
564
|
+
* }
|
|
565
|
+
* });
|
|
566
|
+
*
|
|
567
|
+
* // Add 100 virtual panels (at the end)
|
|
568
|
+
* flicking.virtual.append(100);
|
|
569
|
+
*
|
|
570
|
+
* // Remove 100 virtual panels from 0 to 100
|
|
571
|
+
* flicking.virtual.remove(0, 100);
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
public get virtual() { return this._virtualManager; }
|
|
575
|
+
|
|
513
576
|
// OTHERS
|
|
514
577
|
/**
|
|
515
578
|
* Call {@link Flicking#init init()} automatically when creating Flicking's instance
|
|
@@ -520,14 +583,19 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
520
583
|
*/
|
|
521
584
|
public get autoInit() { return this._autoInit; }
|
|
522
585
|
/**
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
* @ko Flicking의 {@link Flicking#resize resize} 메소드를 window의 resize 이벤트 핸들러로 등록합니다.
|
|
526
|
-
* 설정시 window 창 크기 및 orientation 변경에 의해 자동으로 {@link Flicking#resize resize}를 호출합니다.
|
|
586
|
+
* Whether to automatically call {@link Flicking#resize resize()} when the viewport element(.flicking-viewport)'s size is changed
|
|
587
|
+
* @ko 뷰포트 엘리먼트(.flicking-viewport)의 크기 변경시 {@link Flicking#resize resize()} 메소드를 자동으로 호출할지 여부를 설정합니다
|
|
527
588
|
* @type {boolean}
|
|
528
589
|
* @default true
|
|
529
590
|
*/
|
|
530
591
|
public get autoResize() { return this._autoResize; }
|
|
592
|
+
/**
|
|
593
|
+
* Whether to listen {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver ResizeObserver}'s event instead of Window's {@link https://developer.mozilla.org/ko/docs/Web/API/Window/resize_event resize} event when using the `autoResize` option
|
|
594
|
+
* @ko autoResize 옵션 사용시 {@link https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver ResizeObserver}의 이벤트를 Window객체의 {@link https://developer.mozilla.org/ko/docs/Web/API/Window/resize_event resize} 이벤트 대신 수신할지 여부를 설정합니다
|
|
595
|
+
* @type {boolean}
|
|
596
|
+
* @default true
|
|
597
|
+
*/
|
|
598
|
+
public get useResizeObserver() { return this._useResizeObserver; }
|
|
531
599
|
/**
|
|
532
600
|
* This is an option for the frameworks(React, Vue, Angular, ...). Don't set it as it's automatically managed by Flicking.
|
|
533
601
|
* @ko 프레임워크(React, Vue, Angular, ...)에서만 사용하는 옵션으로, 자동으로 설정되므로 따로 사용하실 필요 없습니다!
|
|
@@ -553,6 +621,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
553
621
|
public set adaptive(val: FlickingOptions["adaptive"]) { this._adaptive = val; }
|
|
554
622
|
public set panelsPerView(val: FlickingOptions["panelsPerView"]) { this._panelsPerView = val; }
|
|
555
623
|
public set noPanelStyleOverride(val: FlickingOptions["noPanelStyleOverride"]) { this._noPanelStyleOverride = val; }
|
|
624
|
+
public set resizeOnContentsReady(val: FlickingOptions["resizeOnContentsReady"]) { this._resizeOnContentsReady = val; }
|
|
556
625
|
// EVENTS
|
|
557
626
|
public set needPanelThreshold(val: FlickingOptions["needPanelThreshold"]) { this._needPanelThreshold = val; }
|
|
558
627
|
public set preventEventsBeforeInit(val: FlickingOptions["preventEventsBeforeInit"]) { this._preventEventsBeforeInit = val; }
|
|
@@ -587,7 +656,23 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
587
656
|
// PERFORMANCE
|
|
588
657
|
public set renderOnlyVisible(val: FlickingOptions["renderOnlyVisible"]) { this._renderOnlyVisible = val; }
|
|
589
658
|
// OTHERS
|
|
590
|
-
public set autoResize(val: FlickingOptions["autoResize"]) {
|
|
659
|
+
public set autoResize(val: FlickingOptions["autoResize"]) {
|
|
660
|
+
this._autoResize = val;
|
|
661
|
+
|
|
662
|
+
if (val) {
|
|
663
|
+
this._autoResizer.enable();
|
|
664
|
+
} else {
|
|
665
|
+
this._autoResizer.disable();
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
public set useResizeObserver(val: FlickingOptions["useResizeObserver"]) {
|
|
670
|
+
this._useResizeObserver = val;
|
|
671
|
+
|
|
672
|
+
if (this._autoResize) {
|
|
673
|
+
this._autoResizer.enable();
|
|
674
|
+
}
|
|
675
|
+
}
|
|
591
676
|
|
|
592
677
|
/**
|
|
593
678
|
* @param root A root HTMLElement to initialize Flicking on it. When it's a typeof `string`, it should be a css selector string
|
|
@@ -626,6 +711,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
626
711
|
adaptive = false,
|
|
627
712
|
panelsPerView = -1,
|
|
628
713
|
noPanelStyleOverride = false,
|
|
714
|
+
resizeOnContentsReady = false,
|
|
629
715
|
needPanelThreshold = 0,
|
|
630
716
|
preventEventsBeforeInit = true,
|
|
631
717
|
deceleration = 0.0075,
|
|
@@ -640,8 +726,10 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
640
726
|
preventClickOnDrag = true,
|
|
641
727
|
disableOnInit = false,
|
|
642
728
|
renderOnlyVisible = false,
|
|
729
|
+
virtual = null,
|
|
643
730
|
autoInit = true,
|
|
644
731
|
autoResize = true,
|
|
732
|
+
useResizeObserver = true,
|
|
645
733
|
renderExternal = null
|
|
646
734
|
}: Partial<FlickingOptions> = {}) {
|
|
647
735
|
super();
|
|
@@ -659,6 +747,8 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
659
747
|
this._adaptive = adaptive;
|
|
660
748
|
this._panelsPerView = panelsPerView;
|
|
661
749
|
this._noPanelStyleOverride = noPanelStyleOverride;
|
|
750
|
+
this._resizeOnContentsReady = resizeOnContentsReady;
|
|
751
|
+
this._virtual = virtual;
|
|
662
752
|
this._needPanelThreshold = needPanelThreshold;
|
|
663
753
|
this._preventEventsBeforeInit = preventEventsBeforeInit;
|
|
664
754
|
this._deceleration = deceleration;
|
|
@@ -673,17 +763,18 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
673
763
|
this._preventClickOnDrag = preventClickOnDrag;
|
|
674
764
|
this._disableOnInit = disableOnInit;
|
|
675
765
|
this._renderOnlyVisible = renderOnlyVisible;
|
|
676
|
-
this._autoResize = autoResize;
|
|
677
766
|
this._autoInit = autoInit;
|
|
767
|
+
this._autoResize = autoResize;
|
|
768
|
+
this._useResizeObserver = useResizeObserver;
|
|
678
769
|
this._renderExternal = renderExternal;
|
|
679
770
|
|
|
680
771
|
// Create core components
|
|
681
772
|
this._viewport = new Viewport(getElement(root));
|
|
773
|
+
this._autoResizer = new AutoResizer(this);
|
|
682
774
|
this._renderer = this._createRenderer();
|
|
683
775
|
this._camera = this._createCamera();
|
|
684
776
|
this._control = this._createControl();
|
|
685
|
-
|
|
686
|
-
this.resize = this.resize.bind(this);
|
|
777
|
+
this._virtualManager = new VirtualManager(this, virtual);
|
|
687
778
|
|
|
688
779
|
if (this._autoInit) {
|
|
689
780
|
void this.init();
|
|
@@ -704,10 +795,12 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
704
795
|
const camera = this._camera;
|
|
705
796
|
const renderer = this._renderer;
|
|
706
797
|
const control = this._control;
|
|
798
|
+
const virtualManager = this._virtualManager;
|
|
707
799
|
const originalTrigger = this.trigger;
|
|
708
800
|
const preventEventsBeforeInit = this._preventEventsBeforeInit;
|
|
709
801
|
|
|
710
802
|
camera.init(this);
|
|
803
|
+
virtualManager.init();
|
|
711
804
|
renderer.init(this);
|
|
712
805
|
control.init(this);
|
|
713
806
|
|
|
@@ -721,7 +814,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
721
814
|
await this._moveToInitialPanel();
|
|
722
815
|
|
|
723
816
|
if (this._autoResize) {
|
|
724
|
-
|
|
817
|
+
this._autoResizer.enable();
|
|
725
818
|
}
|
|
726
819
|
if (this._preventClickOnDrag) {
|
|
727
820
|
control.controller.addPreventClickHandler();
|
|
@@ -729,6 +822,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
729
822
|
if (this._disableOnInit) {
|
|
730
823
|
this.disableInput();
|
|
731
824
|
}
|
|
825
|
+
renderer.checkPanelContentsReady(renderer.panels);
|
|
732
826
|
|
|
733
827
|
this._plugins.forEach(plugin => plugin.init(this));
|
|
734
828
|
|
|
@@ -748,11 +842,9 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
748
842
|
* @return {void}
|
|
749
843
|
*/
|
|
750
844
|
public destroy(): void {
|
|
751
|
-
if (!this._initialized) return;
|
|
752
|
-
|
|
753
845
|
this.off();
|
|
754
|
-
window.removeEventListener("resize", this.resize);
|
|
755
846
|
|
|
847
|
+
this._autoResizer.disable();
|
|
756
848
|
this._control.destroy();
|
|
757
849
|
this._camera.destroy();
|
|
758
850
|
this._renderer.destroy();
|
|
@@ -938,7 +1030,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
938
1030
|
* @param {boolean} [options.includePanelHTML=false] Include panel's `outerHTML` to the returning status<ko>패널의 `outerHTML`을 반환값에 포함시킵니다</ko>
|
|
939
1031
|
* @param {boolean} [options.visiblePanelsOnly=false] Include only {@link Flicking#visiblePanel visiblePanel}'s HTML. This option is available only when the `includePanelHTML` is true
|
|
940
1032
|
* <ko>현재 보이는 패널({@link Flicking#visiblePanel visiblePanel})의 HTML만 반환합니다. `includePanelHTML`이 `true`일 경우에만 동작합니다.</ko>
|
|
941
|
-
* @return {
|
|
1033
|
+
* @return {Status} An object with current status value information<ko>현재 상태값 정보를 가진 객체.</ko>
|
|
942
1034
|
*/
|
|
943
1035
|
public getStatus({
|
|
944
1036
|
index = true,
|
|
@@ -1013,8 +1105,8 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
1013
1105
|
|
|
1014
1106
|
// Can't add/remove panels on external rendering
|
|
1015
1107
|
if (panels[0]?.html && !this._renderExternal) {
|
|
1016
|
-
renderer.batchRemove({ index: 0, deleteCount: this.panels.length });
|
|
1017
|
-
renderer.batchInsert({ index: 0, elements: parseElement(panels.map(panel => panel.html!)) });
|
|
1108
|
+
renderer.batchRemove({ index: 0, deleteCount: this.panels.length, hasDOMInElements: true });
|
|
1109
|
+
renderer.batchInsert({ index: 0, elements: parseElement(panels.map(panel => panel.html!)), hasDOMInElements: true });
|
|
1018
1110
|
}
|
|
1019
1111
|
|
|
1020
1112
|
if (index) {
|
|
@@ -1112,7 +1204,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
1112
1204
|
if (control.animating) {
|
|
1113
1205
|
// TODO:
|
|
1114
1206
|
} else {
|
|
1115
|
-
|
|
1207
|
+
control.updatePosition(prevProgressInPanel);
|
|
1116
1208
|
control.updateInput();
|
|
1117
1209
|
}
|
|
1118
1210
|
|
|
@@ -1206,7 +1298,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
1206
1298
|
throw new FlickingError(ERROR.MESSAGE.NOT_ALLOWED_IN_FRAMEWORK, ERROR.CODE.NOT_ALLOWED_IN_FRAMEWORK);
|
|
1207
1299
|
}
|
|
1208
1300
|
|
|
1209
|
-
return this._renderer.batchInsert({ index, elements: parseElement(element) });
|
|
1301
|
+
return this._renderer.batchInsert({ index, elements: parseElement(element), hasDOMInElements: true });
|
|
1210
1302
|
}
|
|
1211
1303
|
|
|
1212
1304
|
/**
|
|
@@ -1223,7 +1315,7 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
1223
1315
|
throw new FlickingError(ERROR.MESSAGE.NOT_ALLOWED_IN_FRAMEWORK, ERROR.CODE.NOT_ALLOWED_IN_FRAMEWORK);
|
|
1224
1316
|
}
|
|
1225
1317
|
|
|
1226
|
-
return this._renderer.batchRemove({ index, deleteCount });
|
|
1318
|
+
return this._renderer.batchRemove({ index, deleteCount, hasDOMInElements: true });
|
|
1227
1319
|
}
|
|
1228
1320
|
|
|
1229
1321
|
private _createControl(): Control {
|
|
@@ -1269,15 +1361,39 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
1269
1361
|
}
|
|
1270
1362
|
|
|
1271
1363
|
private _createRenderer(): Renderer {
|
|
1272
|
-
const rendererOptions = {
|
|
1273
|
-
align: this._align
|
|
1274
|
-
};
|
|
1275
|
-
|
|
1276
1364
|
const renderExternal = this._renderExternal;
|
|
1277
1365
|
|
|
1366
|
+
if (this._virtual && this._panelsPerView <= 0) {
|
|
1367
|
+
// eslint-disable-next-line no-console
|
|
1368
|
+
console.warn("\"virtual\" and \"panelsPerView\" option should be used together, ignoring virtual.");
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1278
1371
|
return renderExternal
|
|
1279
|
-
?
|
|
1280
|
-
:
|
|
1372
|
+
? this._createExternalRenderer()
|
|
1373
|
+
: this._createVanillaRenderer();
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
private _createVanillaRenderer(): VanillaRenderer {
|
|
1377
|
+
const virtual = this.virtualEnabled;
|
|
1378
|
+
|
|
1379
|
+
return new VanillaRenderer({
|
|
1380
|
+
align: this._align,
|
|
1381
|
+
strategy: virtual
|
|
1382
|
+
? new VirtualRenderingStrategy()
|
|
1383
|
+
: new NormalRenderingStrategy({
|
|
1384
|
+
providerCtor: VanillaElementProvider,
|
|
1385
|
+
panelCtor: Panel
|
|
1386
|
+
})
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
private _createExternalRenderer(): ExternalRenderer {
|
|
1391
|
+
const {
|
|
1392
|
+
renderer,
|
|
1393
|
+
rendererOptions
|
|
1394
|
+
} = this._renderExternal!;
|
|
1395
|
+
|
|
1396
|
+
return new (renderer)({ align: this._align, ...rendererOptions });
|
|
1281
1397
|
}
|
|
1282
1398
|
|
|
1283
1399
|
private async _moveToInitialPanel(): Promise<void> {
|
|
@@ -1287,6 +1403,8 @@ class Flicking extends Component<FlickingEvents> {
|
|
|
1287
1403
|
|
|
1288
1404
|
if (!initialPanel) return;
|
|
1289
1405
|
|
|
1406
|
+
control.setActive(initialPanel, null, false);
|
|
1407
|
+
|
|
1290
1408
|
return control.moveToPanel(initialPanel, {
|
|
1291
1409
|
duration: 0
|
|
1292
1410
|
});
|
|
@@ -23,7 +23,7 @@ class BoundCamera extends Camera {
|
|
|
23
23
|
* @return {this}
|
|
24
24
|
*/
|
|
25
25
|
public updateRange() {
|
|
26
|
-
const flicking = getFlickingAttached(this._flicking
|
|
26
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
27
27
|
const renderer = flicking.renderer;
|
|
28
28
|
const alignPos = this._alignPos;
|
|
29
29
|
|
|
@@ -61,7 +61,7 @@ class BoundCamera extends Camera {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
public updateAnchors(): this {
|
|
64
|
-
const flicking = getFlickingAttached(this._flicking
|
|
64
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
65
65
|
const panels = flicking.renderer.panels;
|
|
66
66
|
|
|
67
67
|
if (panels.length <= 0) {
|
package/src/camera/Camera.ts
CHANGED
|
@@ -10,7 +10,7 @@ import Panel from "../core/panel/Panel";
|
|
|
10
10
|
import AnchorPoint from "../core/AnchorPoint";
|
|
11
11
|
import * as ERROR from "../const/error";
|
|
12
12
|
import { ALIGN, DIRECTION, EVENTS } from "../const/external";
|
|
13
|
-
import { checkExistence, clamp, find, getFlickingAttached, getProgress, includes, parseAlign } from "../utils";
|
|
13
|
+
import { checkExistence, clamp, find, getFlickingAttached, getProgress, includes, parseAlign, toArray } from "../utils";
|
|
14
14
|
|
|
15
15
|
export interface CameraOptions {
|
|
16
16
|
align: FlickingOptions["align"];
|
|
@@ -38,12 +38,19 @@ abstract class Camera {
|
|
|
38
38
|
|
|
39
39
|
// Internal states getter
|
|
40
40
|
/**
|
|
41
|
-
* The camera(`.flicking-camera`)
|
|
42
|
-
* @ko 카메라(`.flicking-camera`)
|
|
41
|
+
* The camera element(`.flicking-camera`)
|
|
42
|
+
* @ko 카메라 엘리먼트(`.flicking-camera`)
|
|
43
43
|
* @type {HTMLElement}
|
|
44
44
|
* @readonly
|
|
45
45
|
*/
|
|
46
46
|
public get element() { return this._el; }
|
|
47
|
+
/**
|
|
48
|
+
* An array of the child elements of the camera element(`.flicking-camera`)
|
|
49
|
+
* @ko 카메라 엘리먼트(`.flicking-camera`)의 자식 엘리먼트 배열
|
|
50
|
+
* @type {HTMLElement[]}
|
|
51
|
+
* @readonly
|
|
52
|
+
*/
|
|
53
|
+
public get children() { return toArray(this._el.children) as HTMLElement[]; }
|
|
47
54
|
/**
|
|
48
55
|
* Current position of the camera
|
|
49
56
|
* @ko Camera의 현재 좌표
|
|
@@ -271,14 +278,14 @@ abstract class Camera {
|
|
|
271
278
|
* <ko>{@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} {@link Camera#init init}이 이전에 호출되지 않은 경우</ko>
|
|
272
279
|
* @return {this}
|
|
273
280
|
*/
|
|
274
|
-
public
|
|
281
|
+
public lookAt(pos: number): void {
|
|
275
282
|
const prevPos = this._position;
|
|
276
283
|
|
|
277
284
|
this._position = pos;
|
|
278
|
-
|
|
285
|
+
this._refreshVisiblePanels();
|
|
279
286
|
this._checkNeedPanel();
|
|
280
287
|
this._checkReachEnd(prevPos, pos);
|
|
281
|
-
this.
|
|
288
|
+
this.applyTransform();
|
|
282
289
|
}
|
|
283
290
|
|
|
284
291
|
/**
|
|
@@ -376,7 +383,7 @@ abstract class Camera {
|
|
|
376
383
|
* @return {AnchorPoint | null}
|
|
377
384
|
*/
|
|
378
385
|
public findActiveAnchor(): AnchorPoint | null {
|
|
379
|
-
const flicking = getFlickingAttached(this._flicking
|
|
386
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
380
387
|
const activeIndex = flicking.control.activeIndex;
|
|
381
388
|
|
|
382
389
|
return find(this._anchors, anchor => anchor.panel.index === activeIndex);
|
|
@@ -418,7 +425,7 @@ abstract class Camera {
|
|
|
418
425
|
public canSee(panel: Panel): boolean {
|
|
419
426
|
const visibleRange = this.visibleRange;
|
|
420
427
|
// Should not include margin, as we don't declare what the margin is visible as what the panel is visible.
|
|
421
|
-
return panel.
|
|
428
|
+
return panel.isVisibleOnRange(visibleRange.min, visibleRange.max);
|
|
422
429
|
}
|
|
423
430
|
|
|
424
431
|
/**
|
|
@@ -449,7 +456,7 @@ abstract class Camera {
|
|
|
449
456
|
* @return {this}
|
|
450
457
|
*/
|
|
451
458
|
public updateAnchors(): this {
|
|
452
|
-
const flicking = getFlickingAttached(this._flicking
|
|
459
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
453
460
|
const panels = flicking.renderer.panels;
|
|
454
461
|
|
|
455
462
|
this._anchors = panels.map((panel, index) => new AnchorPoint({
|
|
@@ -471,7 +478,7 @@ abstract class Camera {
|
|
|
471
478
|
* @return {this}
|
|
472
479
|
*/
|
|
473
480
|
public updateAdaptiveHeight() {
|
|
474
|
-
const flicking = getFlickingAttached(this._flicking
|
|
481
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
475
482
|
const activePanel = flicking.control.activePanel;
|
|
476
483
|
|
|
477
484
|
if (!flicking.horizontal || !flicking.adaptive || !activePanel) return;
|
|
@@ -481,16 +488,24 @@ abstract class Camera {
|
|
|
481
488
|
});
|
|
482
489
|
}
|
|
483
490
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
491
|
+
/**
|
|
492
|
+
* Update current offset of the camera
|
|
493
|
+
* @ko 현재 카메라의 오프셋을 업데이트합니다
|
|
494
|
+
* @chainable
|
|
495
|
+
* @return {this}
|
|
496
|
+
*/
|
|
497
|
+
public updateOffset(): this {
|
|
498
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
487
499
|
const position = this._position;
|
|
500
|
+
const unRenderedPanels = flicking.panels.filter(panel => !panel.rendered);
|
|
488
501
|
|
|
489
502
|
this._offset = unRenderedPanels
|
|
490
503
|
.filter(panel => panel.position + panel.offset < position)
|
|
491
504
|
.reduce((offset, panel) => offset + panel.sizeIncludingMargin, 0);
|
|
492
505
|
|
|
493
|
-
this.
|
|
506
|
+
this.applyTransform();
|
|
507
|
+
|
|
508
|
+
return this;
|
|
494
509
|
}
|
|
495
510
|
|
|
496
511
|
/**
|
|
@@ -504,6 +519,25 @@ abstract class Camera {
|
|
|
504
519
|
return this;
|
|
505
520
|
}
|
|
506
521
|
|
|
522
|
+
/**
|
|
523
|
+
* Apply "transform" style with the current position to camera element
|
|
524
|
+
* @ko 현재 위치를 기준으로한 transform 스타일을 카메라 엘리먼트에 적용합니다.
|
|
525
|
+
* @chainable
|
|
526
|
+
* @return {this}
|
|
527
|
+
*/
|
|
528
|
+
public applyTransform(): this {
|
|
529
|
+
const el = this._el;
|
|
530
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
531
|
+
|
|
532
|
+
const actualPosition = this._position - this._alignPos - this._offset;
|
|
533
|
+
|
|
534
|
+
el.style[this._transform] = flicking.horizontal
|
|
535
|
+
? `translate(${-actualPosition}px)`
|
|
536
|
+
: `translate(0, ${-actualPosition}px)`;
|
|
537
|
+
|
|
538
|
+
return this;
|
|
539
|
+
}
|
|
540
|
+
|
|
507
541
|
protected _resetInternalValues() {
|
|
508
542
|
this._position = 0;
|
|
509
543
|
this._alignPos = 0;
|
|
@@ -514,8 +548,8 @@ abstract class Camera {
|
|
|
514
548
|
this._needPanelTriggered = { prev: false, next: false };
|
|
515
549
|
}
|
|
516
550
|
|
|
517
|
-
protected
|
|
518
|
-
const flicking = getFlickingAttached(this._flicking
|
|
551
|
+
protected _refreshVisiblePanels() {
|
|
552
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
519
553
|
const panels = flicking.renderer.panels;
|
|
520
554
|
|
|
521
555
|
const newVisiblePanels = panels.filter(panel => this.canSee(panel));
|
|
@@ -526,13 +560,13 @@ abstract class Camera {
|
|
|
526
560
|
const removed: Panel[] = prevVisiblePanels.filter(panel => !includes(newVisiblePanels, panel));
|
|
527
561
|
|
|
528
562
|
if (added.length > 0 || removed.length > 0) {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
})
|
|
563
|
+
void flicking.renderer.render().then(() => {
|
|
564
|
+
flicking.trigger(new ComponentEvent(EVENTS.VISIBLE_CHANGE, {
|
|
565
|
+
added,
|
|
566
|
+
removed,
|
|
567
|
+
visiblePanels: newVisiblePanels
|
|
568
|
+
}));
|
|
569
|
+
});
|
|
536
570
|
}
|
|
537
571
|
}
|
|
538
572
|
|
|
@@ -541,7 +575,7 @@ abstract class Camera {
|
|
|
541
575
|
|
|
542
576
|
if (needPanelTriggered.prev && needPanelTriggered.next) return;
|
|
543
577
|
|
|
544
|
-
const flicking = getFlickingAttached(this._flicking
|
|
578
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
545
579
|
const panels = flicking.renderer.panels;
|
|
546
580
|
|
|
547
581
|
if (panels.length <= 0) {
|
|
@@ -588,7 +622,7 @@ abstract class Camera {
|
|
|
588
622
|
}
|
|
589
623
|
|
|
590
624
|
protected _checkReachEnd(prevPos: number, newPos: number): void {
|
|
591
|
-
const flicking = getFlickingAttached(this._flicking
|
|
625
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
592
626
|
const range = this._range;
|
|
593
627
|
|
|
594
628
|
const wasBetweenRange = prevPos > range.min && prevPos < range.max;
|
|
@@ -603,17 +637,6 @@ abstract class Camera {
|
|
|
603
637
|
}));
|
|
604
638
|
}
|
|
605
639
|
|
|
606
|
-
protected _applyTransform(): void {
|
|
607
|
-
const el = this._el;
|
|
608
|
-
const flicking = getFlickingAttached(this._flicking, "Camera");
|
|
609
|
-
|
|
610
|
-
const actualPosition = this._position - this._alignPos - this._offset;
|
|
611
|
-
|
|
612
|
-
el.style[this._transform] = flicking.horizontal
|
|
613
|
-
? `translate(${-actualPosition}px)`
|
|
614
|
-
: `translate(0, ${-actualPosition}px)`;
|
|
615
|
-
}
|
|
616
|
-
|
|
617
640
|
protected _checkTranslateSupport = () => {
|
|
618
641
|
const transforms = ["webkitTransform", "msTransform", "MozTransform", "OTransform", "transform"];
|
|
619
642
|
|