@egjs/flicking 4.2.5 → 4.4.1
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 +27 -11
- package/declaration/camera/Camera.d.ts +3 -2
- package/declaration/camera/CircularCamera.d.ts +2 -1
- package/declaration/const/error.d.ts +3 -1
- package/declaration/const/external.d.ts +5 -0
- 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/Panel.d.ts +17 -10
- package/declaration/core/panel/VirtualPanel.d.ts +19 -0
- package/declaration/core/panel/index.d.ts +4 -4
- package/declaration/core/panel/provider/ElementProvider.d.ts +8 -0
- package/declaration/core/panel/provider/VanillaElementProvider.d.ts +12 -0
- package/declaration/core/panel/provider/VirtualElementProvider.d.ts +15 -0
- package/declaration/core/panel/provider/index.d.ts +5 -0
- package/declaration/index.d.ts +11 -1
- package/declaration/renderer/ExternalRenderer.d.ts +1 -1
- 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 +23 -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 +1616 -562
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.js +1571 -494
- 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 +8733 -6647
- 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 +10 -22
- package/src/Flicking.ts +163 -32
- package/src/camera/BoundCamera.ts +2 -2
- package/src/camera/Camera.ts +49 -26
- package/src/camera/CircularCamera.ts +52 -27
- package/src/camera/LinearCamera.ts +1 -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 +15 -8
- package/src/control/Control.ts +7 -7
- package/src/control/FreeControl.ts +2 -2
- package/src/control/SnapControl.ts +3 -3
- package/src/control/StrictControl.ts +2 -2
- package/src/core/AutoResizer.ts +81 -0
- package/src/core/Viewport.ts +4 -4
- package/src/core/VirtualManager.ts +188 -0
- package/src/core/index.ts +3 -1
- package/src/core/panel/Panel.ts +68 -60
- package/src/core/panel/VirtualPanel.ts +110 -0
- package/src/core/panel/index.ts +5 -7
- package/src/core/panel/provider/ElementProvider.ts +14 -0
- package/src/core/panel/provider/VanillaElementProvider.ts +45 -0
- package/src/core/panel/provider/VirtualElementProvider.ts +48 -0
- package/src/core/panel/provider/index.ts +16 -0
- package/src/index.ts +12 -1
- package/src/index.umd.ts +2 -0
- package/src/renderer/ExternalRenderer.ts +7 -7
- package/src/renderer/Renderer.ts +173 -68
- package/src/renderer/VanillaRenderer.ts +28 -86
- package/src/renderer/index.ts +2 -0
- package/src/renderer/strategy/NormalRenderingStrategy.ts +106 -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/core/panel/ExternalPanel.d.ts +0 -9
- package/declaration/exports.d.ts +0 -10
- package/src/core/panel/ElementPanel.ts +0 -52
- package/src/core/panel/ExternalPanel.ts +0 -32
- package/src/exports.ts +0 -16
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2015 NAVER Corp.
|
|
3
|
+
* egjs projects are licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import Flicking from "../../../Flicking";
|
|
7
|
+
import VirtualPanel from "../VirtualPanel";
|
|
8
|
+
|
|
9
|
+
import ElementProvider from "./ElementProvider";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
class VirtualElementProvider implements ElementProvider {
|
|
15
|
+
private _flicking: Flicking;
|
|
16
|
+
private _panel: VirtualPanel;
|
|
17
|
+
|
|
18
|
+
public get element() { return this._virtualElement.nativeElement; }
|
|
19
|
+
public get rendered() { return this._virtualElement.visible; }
|
|
20
|
+
|
|
21
|
+
private get _virtualElement() {
|
|
22
|
+
const flicking = this._flicking;
|
|
23
|
+
const elIndex = this._panel.elementIndex;
|
|
24
|
+
const virtualElements = flicking.virtual.elements;
|
|
25
|
+
|
|
26
|
+
return virtualElements[elIndex];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public constructor(flicking: Flicking) {
|
|
30
|
+
this._flicking = flicking;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public init(panel: VirtualPanel) {
|
|
34
|
+
this._panel = panel;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public show(): void {
|
|
38
|
+
// DO_NOTHING
|
|
39
|
+
// Actual element visibility is controlled by VirtualManager
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public hide(): void {
|
|
43
|
+
// DO_NOTHING
|
|
44
|
+
// Actual element visibility is controlled by VirtualManager
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default VirtualElementProvider;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2015 NAVER Corp.
|
|
3
|
+
* egjs projects are licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import ElementProvider from "./ElementProvider";
|
|
6
|
+
import VanillaElementProvider from "./VanillaElementProvider";
|
|
7
|
+
import VirtualElementProvider from "./VirtualElementProvider";
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
VanillaElementProvider,
|
|
11
|
+
VirtualElementProvider
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type {
|
|
15
|
+
ElementProvider
|
|
16
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,18 @@
|
|
|
3
3
|
* egjs projects are licensed under the MIT license
|
|
4
4
|
*/
|
|
5
5
|
import Flicking from "./Flicking";
|
|
6
|
+
import type { FlickingOptions, FlickingEvents } from "./Flicking";
|
|
6
7
|
|
|
7
|
-
export * from "./
|
|
8
|
+
export * from "./core";
|
|
9
|
+
export * from "./camera";
|
|
10
|
+
export * from "./control";
|
|
11
|
+
export * from "./renderer";
|
|
12
|
+
export * from "./const/external";
|
|
13
|
+
export * from "./cfc";
|
|
14
|
+
export * from "./utils";
|
|
15
|
+
|
|
16
|
+
export * from "./type/event";
|
|
17
|
+
export * from "./type/external";
|
|
18
|
+
export type { FlickingOptions, FlickingEvents };
|
|
8
19
|
|
|
9
20
|
export default Flicking;
|
package/src/index.umd.ts
CHANGED
|
@@ -9,6 +9,7 @@ import * as Control from "./control";
|
|
|
9
9
|
import * as Renderer from "./renderer";
|
|
10
10
|
import * as Constants from "./const/external";
|
|
11
11
|
import * as CFC from "./cfc";
|
|
12
|
+
import * as Utils from "./utils";
|
|
12
13
|
import { merge } from "./utils";
|
|
13
14
|
|
|
14
15
|
merge(Flicking, Core);
|
|
@@ -17,5 +18,6 @@ merge(Flicking, Control);
|
|
|
17
18
|
merge(Flicking, Renderer);
|
|
18
19
|
merge(Flicking, Constants);
|
|
19
20
|
merge(Flicking, CFC);
|
|
21
|
+
merge(Flicking, Utils);
|
|
20
22
|
|
|
21
23
|
export default Flicking;
|
|
@@ -7,18 +7,18 @@ import Panel from "../core/panel/Panel";
|
|
|
7
7
|
import Renderer from "./Renderer";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* @internal
|
|
11
11
|
*/
|
|
12
12
|
abstract class ExternalRenderer extends Renderer {
|
|
13
|
-
|
|
14
|
-
protected
|
|
15
|
-
// DO NOTHING
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
14
|
+
protected _removePanelElements(panels: Panel[]): void {
|
|
15
|
+
// DO NOTHING, overrided to prevent an unexpected error
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// DO NOTHING
|
|
18
|
+
protected _removeAllChildsFromCamera(): void {
|
|
19
|
+
// DO NOTHING, overrided to prevent an unexpected error
|
|
21
20
|
}
|
|
21
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export default ExternalRenderer;
|
package/src/renderer/Renderer.ts
CHANGED
|
@@ -3,16 +3,20 @@
|
|
|
3
3
|
* egjs projects are licensed under the MIT license
|
|
4
4
|
*/
|
|
5
5
|
import { ComponentEvent } from "@egjs/component";
|
|
6
|
+
import ImReady from "@egjs/imready";
|
|
6
7
|
|
|
7
8
|
import Flicking, { FlickingOptions } from "../Flicking";
|
|
8
9
|
import Panel, { PanelOptions } from "../core/panel/Panel";
|
|
9
10
|
import FlickingError from "../core/FlickingError";
|
|
10
11
|
import { ALIGN, EVENTS } from "../const/external";
|
|
11
12
|
import * as ERROR from "../const/error";
|
|
12
|
-
import { getFlickingAttached, getMinusCompensatedIndex, includes } from "../utils";
|
|
13
|
+
import { getFlickingAttached, getMinusCompensatedIndex, includes, parsePanelAlign } from "../utils";
|
|
14
|
+
|
|
15
|
+
import RenderingStrategy from "./strategy/RenderingStrategy";
|
|
13
16
|
|
|
14
17
|
export interface RendererOptions {
|
|
15
|
-
align
|
|
18
|
+
align?: FlickingOptions["align"];
|
|
19
|
+
strategy: RenderingStrategy;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
/**
|
|
@@ -25,7 +29,8 @@ abstract class Renderer {
|
|
|
25
29
|
protected _panels: Panel[];
|
|
26
30
|
|
|
27
31
|
// Options
|
|
28
|
-
protected _align: RendererOptions["align"]
|
|
32
|
+
protected _align: NonNullable<RendererOptions["align"]>;
|
|
33
|
+
protected _strategy: RendererOptions["strategy"];
|
|
29
34
|
|
|
30
35
|
// Internal states Getter
|
|
31
36
|
/**
|
|
@@ -43,6 +48,10 @@ abstract class Renderer {
|
|
|
43
48
|
* @readonly
|
|
44
49
|
*/
|
|
45
50
|
public get panelCount() { return this._panels.length; }
|
|
51
|
+
/**
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
public get strategy() { return this._strategy; }
|
|
46
55
|
|
|
47
56
|
// Options Getter
|
|
48
57
|
/**
|
|
@@ -53,25 +62,28 @@ abstract class Renderer {
|
|
|
53
62
|
public get align() { return this._align; }
|
|
54
63
|
|
|
55
64
|
// Options Setter
|
|
56
|
-
public set align(val: RendererOptions["align"]) {
|
|
65
|
+
public set align(val: NonNullable<RendererOptions["align"]>) {
|
|
57
66
|
this._align = val;
|
|
58
67
|
|
|
59
|
-
const panelAlign =
|
|
68
|
+
const panelAlign = parsePanelAlign(val);
|
|
60
69
|
this._panels.forEach(panel => { panel.align = panelAlign; });
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
/**
|
|
64
73
|
* @param {object} options An options object<ko>옵션 오브젝트</ko>
|
|
65
|
-
* @param {Constants.ALIGN | string | number} [options.align] An {@link Flicking#align align} value that will be applied to all panels<ko>전체 패널에 적용될 {@link Flicking#align align} 값</ko>
|
|
74
|
+
* @param {Constants.ALIGN | string | number} [options.align="center"] An {@link Flicking#align align} value that will be applied to all panels<ko>전체 패널에 적용될 {@link Flicking#align align} 값</ko>
|
|
75
|
+
* @param {object} [options.strategy] An instance of RenderingStrategy(internal module)<ko>RenderingStrategy의 인스턴스(내부 모듈)</ko>
|
|
66
76
|
*/
|
|
67
77
|
public constructor({
|
|
68
|
-
align = ALIGN.CENTER
|
|
69
|
-
|
|
78
|
+
align = ALIGN.CENTER,
|
|
79
|
+
strategy
|
|
80
|
+
}: RendererOptions) {
|
|
70
81
|
this._flicking = null;
|
|
71
82
|
this._panels = [];
|
|
72
83
|
|
|
73
84
|
// Bind options
|
|
74
85
|
this._align = align;
|
|
86
|
+
this._strategy = strategy;
|
|
75
87
|
}
|
|
76
88
|
|
|
77
89
|
/**
|
|
@@ -86,12 +98,9 @@ abstract class Renderer {
|
|
|
86
98
|
* @return {this}
|
|
87
99
|
*/
|
|
88
100
|
public abstract render(): Promise<void>;
|
|
89
|
-
public abstract forceRenderAllPanels(): Promise<void>;
|
|
90
101
|
|
|
91
102
|
protected abstract _collectPanels(): void;
|
|
92
|
-
protected abstract _createPanel(el: any, options: PanelOptions): Panel;
|
|
93
|
-
protected abstract _insertPanelElements(panels: Panel[], nextSibling: Panel | null): void;
|
|
94
|
-
protected abstract _removePanelElements(panels: Panel[]): void;
|
|
103
|
+
protected abstract _createPanel(el: any, options: Omit<PanelOptions, "elementProvider">): Panel;
|
|
95
104
|
|
|
96
105
|
/**
|
|
97
106
|
* Initialize Renderer
|
|
@@ -127,6 +136,12 @@ abstract class Renderer {
|
|
|
127
136
|
return this._panels[index] || null;
|
|
128
137
|
}
|
|
129
138
|
|
|
139
|
+
public forceRenderAllPanels(): Promise<void> {
|
|
140
|
+
this._panels.forEach(panel => panel.markForShow());
|
|
141
|
+
|
|
142
|
+
return Promise.resolve();
|
|
143
|
+
}
|
|
144
|
+
|
|
130
145
|
/**
|
|
131
146
|
* Update all panel sizes
|
|
132
147
|
* @ko 모든 패널의 크기를 업데이트합니다
|
|
@@ -134,10 +149,16 @@ abstract class Renderer {
|
|
|
134
149
|
* @return {this}
|
|
135
150
|
*/
|
|
136
151
|
public updatePanelSize(): this {
|
|
137
|
-
const flicking = getFlickingAttached(this._flicking
|
|
152
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
153
|
+
const panels = this._panels;
|
|
154
|
+
|
|
155
|
+
if (panels.length <= 0) return this;
|
|
138
156
|
|
|
139
157
|
if (flicking.panelsPerView > 0) {
|
|
140
|
-
|
|
158
|
+
const firstPanel = panels[0];
|
|
159
|
+
firstPanel.resize();
|
|
160
|
+
|
|
161
|
+
this._updatePanelSizeByGrid(firstPanel, panels);
|
|
141
162
|
} else {
|
|
142
163
|
flicking.panels.forEach(panel => panel.resize());
|
|
143
164
|
}
|
|
@@ -150,19 +171,23 @@ abstract class Renderer {
|
|
|
150
171
|
* This will increase index of panels after by the number of panels added
|
|
151
172
|
* @ko 주어진 인덱스에 새로운 패널들을 추가합니다
|
|
152
173
|
* 해당 인덱스보다 같거나 큰 인덱스를 가진 기존 패널들은 추가한 패널의 개수만큼 인덱스가 증가합니다.
|
|
153
|
-
* @param {
|
|
154
|
-
* @param {
|
|
174
|
+
* @param {Array<object>} items An array of items to insert<ko>추가할 아이템들의 배열</ko>
|
|
175
|
+
* @param {number} [items.index] Index to insert new panels at<ko>새로 패널들을 추가할 인덱스</ko>
|
|
176
|
+
* @param {any[]} [items.elements] An array of element or framework component with element in it<ko>엘리먼트의 배열 혹은 프레임워크에서 엘리먼트를 포함한 컴포넌트들의 배열</ko>
|
|
177
|
+
* @param {boolean} [items.hasDOMInElements] Whether it contains actual DOM elements. If set to true, renderer will add them to the camera element<ko>내부에 실제 DOM 엘리먼트들을 포함하고 있는지 여부. true로 설정할 경우, 렌더러는 해당 엘리먼트들을 카메라 엘리먼트 내부에 추가합니다</ko>
|
|
155
178
|
* @return {Panel[]} An array of prepended panels<ko>추가된 패널들의 배열</ko>
|
|
156
179
|
*/
|
|
157
180
|
public batchInsert(...items: Array<{
|
|
158
181
|
index: number;
|
|
159
182
|
elements: any[];
|
|
183
|
+
hasDOMInElements: boolean;
|
|
160
184
|
}>): Panel[] {
|
|
161
185
|
const panels = this._panels;
|
|
162
|
-
const flicking = getFlickingAttached(this._flicking
|
|
186
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
163
187
|
|
|
164
188
|
const { control } = flicking;
|
|
165
|
-
const
|
|
189
|
+
const prevFirstPanel = panels[0];
|
|
190
|
+
const align = parsePanelAlign(this._align);
|
|
166
191
|
|
|
167
192
|
const allPanelsInserted = items.reduce((addedPanels, item) => {
|
|
168
193
|
const insertingIdx = getMinusCompensatedIndex(item.index, panels.length);
|
|
@@ -171,18 +196,24 @@ abstract class Renderer {
|
|
|
171
196
|
|
|
172
197
|
panels.splice(insertingIdx, 0, ...panelsInserted);
|
|
173
198
|
|
|
174
|
-
|
|
175
|
-
|
|
199
|
+
if (item.hasDOMInElements) {
|
|
200
|
+
// Insert the actual elements as camera element's children
|
|
201
|
+
this._insertPanelElements(panelsInserted, panelsPushed[0] ?? null);
|
|
202
|
+
}
|
|
176
203
|
|
|
177
204
|
// Resize the newly added panels
|
|
178
|
-
|
|
205
|
+
if (flicking.panelsPerView > 0) {
|
|
206
|
+
const firstPanel = prevFirstPanel || panelsInserted[0].resize();
|
|
179
207
|
|
|
180
|
-
|
|
208
|
+
this._updatePanelSizeByGrid(firstPanel, panelsInserted);
|
|
209
|
+
} else {
|
|
210
|
+
panelsInserted.forEach(panel => panel.resize());
|
|
211
|
+
}
|
|
181
212
|
|
|
182
213
|
// Update panel indexes & positions
|
|
183
214
|
panelsPushed.forEach(panel => {
|
|
184
215
|
panel.increaseIndex(panelsInserted.length);
|
|
185
|
-
panel.
|
|
216
|
+
panel.updatePosition();
|
|
186
217
|
});
|
|
187
218
|
|
|
188
219
|
return [...addedPanels, ...panelsInserted];
|
|
@@ -210,6 +241,8 @@ abstract class Renderer {
|
|
|
210
241
|
removed: []
|
|
211
242
|
}));
|
|
212
243
|
|
|
244
|
+
this.checkPanelContentsReady(allPanelsInserted);
|
|
245
|
+
|
|
213
246
|
return allPanelsInserted;
|
|
214
247
|
}
|
|
215
248
|
|
|
@@ -218,13 +251,15 @@ abstract class Renderer {
|
|
|
218
251
|
* This will decrease index of panels after by the number of panels removed
|
|
219
252
|
* @ko 주어진 인덱스의 패널을 제거합니다
|
|
220
253
|
* 해당 인덱스보다 큰 인덱스를 가진 기존 패널들은 제거한 패널의 개수만큼 인덱스가 감소합니다
|
|
221
|
-
* @param {
|
|
222
|
-
* @param {number} [
|
|
254
|
+
* @param {Array<object>} items An array of items to remove<ko>제거할 아이템들의 배열</ko>
|
|
255
|
+
* @param {number} [items.index] Index of panel to remove<ko>제거할 패널의 인덱스</ko>
|
|
256
|
+
* @param {number} [items.deleteCount=1] Number of panels to remove from index<ko>`index` 이후로 제거할 패널의 개수</ko>
|
|
257
|
+
* @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>
|
|
223
258
|
* @return An array of removed panels<ko>제거된 패널들의 배열</ko>
|
|
224
259
|
*/
|
|
225
|
-
public batchRemove(...items: Array<{ index: number; deleteCount: number }>): Panel[] {
|
|
260
|
+
public batchRemove(...items: Array<{ index: number; deleteCount: number; hasDOMInElements: boolean }>): Panel[] {
|
|
226
261
|
const panels = this._panels;
|
|
227
|
-
const flicking = getFlickingAttached(this._flicking
|
|
262
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
228
263
|
|
|
229
264
|
const { camera, control } = flicking;
|
|
230
265
|
const activePanel = control.activePanel;
|
|
@@ -240,20 +275,18 @@ abstract class Renderer {
|
|
|
240
275
|
if (panelsRemoved.length <= 0) return [];
|
|
241
276
|
|
|
242
277
|
// Update panel indexes & positions
|
|
243
|
-
const removedSize = this._getPanelSizeSum(panelsRemoved);
|
|
244
278
|
panelsPulled.forEach(panel => {
|
|
245
279
|
panel.decreaseIndex(panelsRemoved.length);
|
|
246
|
-
panel.
|
|
280
|
+
panel.updatePosition();
|
|
247
281
|
});
|
|
248
282
|
|
|
249
|
-
|
|
283
|
+
if (item.hasDOMInElements) {
|
|
284
|
+
this._removePanelElements(panelsRemoved);
|
|
285
|
+
}
|
|
250
286
|
|
|
251
287
|
// Remove panel elements
|
|
252
288
|
panelsRemoved.forEach(panel => panel.destroy());
|
|
253
289
|
|
|
254
|
-
// Update camera & control
|
|
255
|
-
this._updateCameraAndControl();
|
|
256
|
-
|
|
257
290
|
if (includes(panelsRemoved, activePanel)) {
|
|
258
291
|
control.resetActive();
|
|
259
292
|
}
|
|
@@ -261,6 +294,9 @@ abstract class Renderer {
|
|
|
261
294
|
return [...removed, ...panelsRemoved];
|
|
262
295
|
}, []);
|
|
263
296
|
|
|
297
|
+
// Update camera & control
|
|
298
|
+
this._updateCameraAndControl();
|
|
299
|
+
|
|
264
300
|
void this.render();
|
|
265
301
|
|
|
266
302
|
// FIXME: fix for animating case
|
|
@@ -289,25 +325,80 @@ abstract class Renderer {
|
|
|
289
325
|
return allPanelsRemoved;
|
|
290
326
|
}
|
|
291
327
|
|
|
292
|
-
|
|
293
|
-
|
|
328
|
+
/**
|
|
329
|
+
* @internal
|
|
330
|
+
*/
|
|
331
|
+
public checkPanelContentsReady(checkingPanels: Panel[]) {
|
|
332
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
333
|
+
const resizeOnContentsReady = flicking.resizeOnContentsReady;
|
|
334
|
+
const panels = this._panels;
|
|
335
|
+
|
|
336
|
+
if (!resizeOnContentsReady || flicking.virtualEnabled) return;
|
|
294
337
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
338
|
+
const hasContents = (panel: Panel) => !!panel.element.querySelector("img, video");
|
|
339
|
+
checkingPanels = checkingPanels.filter(panel => hasContents(panel));
|
|
340
|
+
|
|
341
|
+
if (checkingPanels.length <= 0) return;
|
|
299
342
|
|
|
300
|
-
|
|
301
|
-
const firstPanel = panels[0];
|
|
302
|
-
const lastPanel = panels[panels.length - 1];
|
|
343
|
+
const contentsReadyChecker = new ImReady();
|
|
303
344
|
|
|
304
|
-
|
|
345
|
+
checkingPanels.forEach(panel => {
|
|
346
|
+
panel.loading = true;
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
contentsReadyChecker.on("readyElement", e => {
|
|
350
|
+
if (!this._flicking) {
|
|
351
|
+
// Renderer's destroy() is called before
|
|
352
|
+
contentsReadyChecker.destroy();
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const panel = checkingPanels[e.index];
|
|
357
|
+
const camera = flicking.camera;
|
|
358
|
+
const control = flicking.control;
|
|
359
|
+
const prevProgressInPanel = control.activePanel
|
|
360
|
+
? camera.getProgressInPanel(control.activePanel)
|
|
361
|
+
: 0;
|
|
305
362
|
|
|
306
|
-
|
|
363
|
+
panel.loading = false;
|
|
364
|
+
panel.resize();
|
|
365
|
+
panels.slice(panel.index + 1).forEach(panelBehind => panelBehind.updatePosition());
|
|
366
|
+
|
|
367
|
+
if (!flicking.initialized) return;
|
|
368
|
+
|
|
369
|
+
camera.updateRange();
|
|
370
|
+
camera.updateAnchors();
|
|
371
|
+
|
|
372
|
+
if (control.animating) {
|
|
373
|
+
// TODO: Need Axes update
|
|
374
|
+
} else {
|
|
375
|
+
control.updatePosition(prevProgressInPanel);
|
|
376
|
+
control.updateInput();
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
contentsReadyChecker.on("preReady", e => {
|
|
381
|
+
if (this._flicking) {
|
|
382
|
+
void this.render();
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (e.readyCount === e.totalCount) {
|
|
386
|
+
contentsReadyChecker.destroy();
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
contentsReadyChecker.on("ready", () => {
|
|
391
|
+
if (this._flicking) {
|
|
392
|
+
void this.render();
|
|
393
|
+
}
|
|
394
|
+
contentsReadyChecker.destroy();
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
contentsReadyChecker.check(checkingPanels.map(panel => panel.element));
|
|
307
398
|
}
|
|
308
399
|
|
|
309
400
|
protected _updateCameraAndControl() {
|
|
310
|
-
const flicking = getFlickingAttached(this._flicking
|
|
401
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
311
402
|
const { camera, control } = flicking;
|
|
312
403
|
|
|
313
404
|
camera.updateRange();
|
|
@@ -316,16 +407,6 @@ abstract class Renderer {
|
|
|
316
407
|
control.updateInput();
|
|
317
408
|
}
|
|
318
409
|
|
|
319
|
-
protected _updateRenderingPanels(): void {
|
|
320
|
-
const flicking = getFlickingAttached(this._flicking, "Renderer");
|
|
321
|
-
|
|
322
|
-
if (flicking.renderOnlyVisible) {
|
|
323
|
-
this._showOnlyVisiblePanels(flicking);
|
|
324
|
-
} else {
|
|
325
|
-
flicking.panels.forEach(panel => panel.markForShow());
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
410
|
protected _showOnlyVisiblePanels(flicking: Flicking) {
|
|
330
411
|
const panels = flicking.renderer.panels;
|
|
331
412
|
const camera = flicking.camera;
|
|
@@ -336,7 +417,7 @@ abstract class Renderer {
|
|
|
336
417
|
}, {});
|
|
337
418
|
|
|
338
419
|
panels.forEach(panel => {
|
|
339
|
-
if (panel.index in visibleIndexes) {
|
|
420
|
+
if (panel.index in visibleIndexes || panel.loading) {
|
|
340
421
|
panel.markForShow();
|
|
341
422
|
} else if (!flicking.holding) {
|
|
342
423
|
// During the input sequence,
|
|
@@ -344,12 +425,10 @@ abstract class Renderer {
|
|
|
344
425
|
panel.markForHide();
|
|
345
426
|
}
|
|
346
427
|
});
|
|
347
|
-
|
|
348
|
-
camera.updateOffset();
|
|
349
428
|
}
|
|
350
429
|
|
|
351
|
-
protected _updatePanelSizeByGrid(
|
|
352
|
-
const
|
|
430
|
+
protected _updatePanelSizeByGrid(referencePanel: Panel, panels: Panel[]) {
|
|
431
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
353
432
|
const panelsPerView = flicking.panelsPerView;
|
|
354
433
|
|
|
355
434
|
if (panelsPerView <= 0) {
|
|
@@ -357,12 +436,8 @@ abstract class Renderer {
|
|
|
357
436
|
}
|
|
358
437
|
if (panels.length <= 0) return;
|
|
359
438
|
|
|
360
|
-
// resize only the first panel
|
|
361
|
-
const firstPanel = panels[0];
|
|
362
|
-
firstPanel.resize();
|
|
363
|
-
|
|
364
439
|
const viewportSize = flicking.camera.size;
|
|
365
|
-
const gap =
|
|
440
|
+
const gap = referencePanel.margin.prev + referencePanel.margin.next;
|
|
366
441
|
|
|
367
442
|
const panelSize = (viewportSize - gap * (panelsPerView - 1)) / panelsPerView;
|
|
368
443
|
const panelSizeObj = flicking.horizontal
|
|
@@ -370,16 +445,46 @@ abstract class Renderer {
|
|
|
370
445
|
: { height: panelSize };
|
|
371
446
|
const firstPanelSizeObj = {
|
|
372
447
|
size: panelSize,
|
|
373
|
-
height:
|
|
374
|
-
margin:
|
|
448
|
+
height: referencePanel.height,
|
|
449
|
+
margin: referencePanel.margin
|
|
375
450
|
};
|
|
376
451
|
|
|
377
452
|
if (!flicking.noPanelStyleOverride) {
|
|
378
|
-
|
|
453
|
+
this._strategy.updatePanelSizes(flicking, panelSizeObj);
|
|
379
454
|
}
|
|
380
455
|
|
|
381
456
|
flicking.panels.forEach(panel => panel.resize(firstPanelSizeObj));
|
|
382
457
|
}
|
|
458
|
+
|
|
459
|
+
protected _removeAllChildsFromCamera() {
|
|
460
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
461
|
+
const cameraElement = flicking.camera.element;
|
|
462
|
+
|
|
463
|
+
// Remove other elements
|
|
464
|
+
while (cameraElement.firstChild) {
|
|
465
|
+
cameraElement.removeChild(cameraElement.firstChild);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
protected _insertPanelElements(panels: Panel[], nextSibling: Panel | null = null) {
|
|
470
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
471
|
+
const camera = flicking.camera;
|
|
472
|
+
const cameraElement = camera.element;
|
|
473
|
+
const nextSiblingElement = nextSibling?.element || null;
|
|
474
|
+
const fragment = document.createDocumentFragment();
|
|
475
|
+
|
|
476
|
+
panels.forEach(panel => fragment.appendChild(panel.element));
|
|
477
|
+
cameraElement.insertBefore(fragment, nextSiblingElement);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
protected _removePanelElements(panels: Panel[]) {
|
|
481
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
482
|
+
const cameraElement = flicking.camera.element;
|
|
483
|
+
|
|
484
|
+
panels.forEach(panel => {
|
|
485
|
+
cameraElement.removeChild(panel.element);
|
|
486
|
+
});
|
|
487
|
+
}
|
|
383
488
|
}
|
|
384
489
|
|
|
385
490
|
export default Renderer;
|