@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
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { getFlickingAttached, toArray } from "../utils";
|
|
6
6
|
import Panel, { PanelOptions } from "../core/panel/Panel";
|
|
7
|
-
import ElementPanel from "../core/panel/ElementPanel";
|
|
8
7
|
|
|
9
8
|
import Renderer from "./Renderer";
|
|
10
9
|
|
|
@@ -14,112 +13,55 @@ import Renderer from "./Renderer";
|
|
|
14
13
|
class VanillaRenderer extends Renderer {
|
|
15
14
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
16
15
|
public async render() {
|
|
17
|
-
const flicking = getFlickingAttached(this._flicking
|
|
18
|
-
const
|
|
19
|
-
const wasRenderedPanels = this._panels.filter(panel => panel.element.parentElement === cameraEl);
|
|
20
|
-
|
|
21
|
-
this._updateRenderingPanels();
|
|
22
|
-
const renderingPanels = this._getRenderingPanelsByOrder();
|
|
23
|
-
|
|
24
|
-
this._removePanelElements(wasRenderedPanels.filter(panel => !panel.rendered));
|
|
25
|
-
this._insertPanelElements(renderingPanels.filter(panel => panel.element.parentElement !== cameraEl), null);
|
|
26
|
-
this._resetPanelElementOrder(renderingPanels);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
30
|
-
public async forceRenderAllPanels() {
|
|
31
|
-
const flicking = getFlickingAttached(this._flicking, "Renderer");
|
|
32
|
-
const camera = flicking.camera;
|
|
33
|
-
const cameraElement = camera.element;
|
|
34
|
-
const fragment = document.createDocumentFragment();
|
|
35
|
-
|
|
36
|
-
this._panels.forEach(panel => fragment.appendChild(panel.element));
|
|
16
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
17
|
+
const strategy = this._strategy;
|
|
37
18
|
|
|
38
|
-
|
|
19
|
+
strategy.updateRenderingPanels(flicking);
|
|
20
|
+
strategy.renderPanels(flicking);
|
|
39
21
|
|
|
40
|
-
|
|
22
|
+
this._resetPanelElementOrder();
|
|
41
23
|
}
|
|
42
24
|
|
|
43
25
|
protected _collectPanels() {
|
|
44
|
-
const flicking = getFlickingAttached(this._flicking
|
|
45
|
-
|
|
46
|
-
const cameraElement = flicking.camera.element;
|
|
47
|
-
|
|
48
|
-
// Remove all text nodes in the camera element
|
|
49
|
-
toArray(cameraElement.childNodes).forEach(node => {
|
|
50
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
51
|
-
cameraElement.removeChild(node);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const align = this._getPanelAlign();
|
|
56
|
-
const cameraChilds = toArray(cameraElement.children);
|
|
57
|
-
|
|
58
|
-
this._panels = cameraChilds.map(
|
|
59
|
-
(el: HTMLElement, index: number) => new ElementPanel({ flicking, el, index, align })
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
protected _createPanel(el: HTMLElement, options: PanelOptions): ElementPanel {
|
|
64
|
-
return new ElementPanel({ el, ...options });
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
protected _insertPanelElements(panels: Panel[], nextSibling: Panel | null) {
|
|
68
|
-
const flicking = getFlickingAttached(this._flicking, "Renderer");
|
|
26
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
69
27
|
const camera = flicking.camera;
|
|
70
|
-
const cameraElement = camera.element;
|
|
71
|
-
const nextSiblingElement = nextSibling?.element || null;
|
|
72
|
-
const fragment = document.createDocumentFragment();
|
|
73
|
-
|
|
74
|
-
panels.forEach(panel => fragment.appendChild(panel.element));
|
|
75
|
-
cameraElement.insertBefore(fragment, nextSiblingElement);
|
|
76
28
|
|
|
77
|
-
|
|
29
|
+
this._removeAllTextNodes();
|
|
30
|
+
this._panels = this._strategy.collectPanels(flicking, camera.children);
|
|
78
31
|
}
|
|
79
32
|
|
|
80
|
-
protected
|
|
81
|
-
|
|
82
|
-
const cameraElement = flicking.camera.element;
|
|
83
|
-
|
|
84
|
-
panels.forEach(panel => {
|
|
85
|
-
cameraElement.removeChild(panel.element);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
return this;
|
|
33
|
+
protected _createPanel(el: HTMLElement, options: Omit<PanelOptions, "elementProvider">): Panel {
|
|
34
|
+
return this._strategy.createPanel(el, options);
|
|
89
35
|
}
|
|
90
36
|
|
|
91
|
-
private _resetPanelElementOrder(
|
|
92
|
-
const flicking = getFlickingAttached(this._flicking
|
|
37
|
+
private _resetPanelElementOrder() {
|
|
38
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
93
39
|
const cameraEl = flicking.camera.element;
|
|
94
40
|
|
|
95
41
|
// We're using reversed panels here as last panel should be the last element of camera element
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
42
|
+
const reversedElements = this._strategy
|
|
43
|
+
.getRenderingElementsByOrder(flicking)
|
|
44
|
+
.reverse();
|
|
45
|
+
|
|
46
|
+
reversedElements.forEach((el, idx) => {
|
|
47
|
+
const nextEl = reversedElements[idx - 1] ? reversedElements[idx - 1] : null;
|
|
100
48
|
|
|
101
|
-
if (
|
|
102
|
-
cameraEl.insertBefore(
|
|
49
|
+
if (el.nextElementSibling !== nextEl) {
|
|
50
|
+
cameraEl.insertBefore(el, nextEl);
|
|
103
51
|
}
|
|
104
52
|
});
|
|
105
53
|
}
|
|
106
54
|
|
|
107
|
-
private
|
|
108
|
-
const flicking = getFlickingAttached(this._flicking
|
|
55
|
+
private _removeAllTextNodes() {
|
|
56
|
+
const flicking = getFlickingAttached(this._flicking);
|
|
109
57
|
const cameraElement = flicking.camera.element;
|
|
110
58
|
|
|
111
|
-
// Remove
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
private _getRenderingPanelsByOrder(): Panel[] {
|
|
118
|
-
const flicking = getFlickingAttached(this._flicking, "Renderer");
|
|
119
|
-
const panels = flicking.renderer.panels;
|
|
120
|
-
|
|
121
|
-
return panels.filter(panel => panel.rendered)
|
|
122
|
-
.sort((a, b) => (a.position + a.offset) - (b.position + b.offset));
|
|
59
|
+
// Remove all text nodes in the camera element
|
|
60
|
+
toArray(cameraElement.childNodes).forEach(node => {
|
|
61
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
62
|
+
cameraElement.removeChild(node);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
123
65
|
}
|
|
124
66
|
}
|
|
125
67
|
|
package/src/renderer/index.ts
CHANGED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2015 NAVER Corp.
|
|
3
|
+
* egjs projects are licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import Flicking from "../../Flicking";
|
|
6
|
+
import Panel, { PanelOptions } from "../../core/panel/Panel";
|
|
7
|
+
import ElementProvider from "../../core/panel/provider/ElementProvider";
|
|
8
|
+
import { DIRECTION } from "../../const/external";
|
|
9
|
+
import { parsePanelAlign } from "../../utils";
|
|
10
|
+
|
|
11
|
+
import RenderingStrategy from "./RenderingStrategy";
|
|
12
|
+
|
|
13
|
+
export interface NormalRenderingStrategyOptions {
|
|
14
|
+
providerCtor: new (...args: any) => ElementProvider;
|
|
15
|
+
panelCtor: new (options: PanelOptions) => Panel;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class NormalRenderingStrategy implements RenderingStrategy {
|
|
20
|
+
private _providerCtor: NormalRenderingStrategyOptions["providerCtor"];
|
|
21
|
+
private _panelCtor: NormalRenderingStrategyOptions["panelCtor"];
|
|
22
|
+
|
|
23
|
+
public constructor({ providerCtor, panelCtor }: NormalRenderingStrategyOptions) {
|
|
24
|
+
this._providerCtor = providerCtor;
|
|
25
|
+
this._panelCtor = panelCtor;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public renderPanels() {
|
|
29
|
+
// DO_NOTHING
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public getRenderingIndexesByOrder(flicking: Flicking) {
|
|
33
|
+
const renderedPanels = flicking.renderer.panels.filter(panel => panel.rendered);
|
|
34
|
+
const toggledPrev = renderedPanels.filter(panel => panel.toggled && panel.toggleDirection === DIRECTION.PREV);
|
|
35
|
+
const toggledNext = renderedPanels.filter(panel => panel.toggled && panel.toggleDirection === DIRECTION.NEXT);
|
|
36
|
+
const notToggled = renderedPanels.filter(panel => !panel.toggled);
|
|
37
|
+
|
|
38
|
+
return [...toggledPrev, ...notToggled, ...toggledNext].map(panel => panel.index);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public getRenderingElementsByOrder(flicking: Flicking) {
|
|
42
|
+
const panels = flicking.panels;
|
|
43
|
+
|
|
44
|
+
return this.getRenderingIndexesByOrder(flicking).map(index => panels[index].element);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public updateRenderingPanels(flicking: Flicking) {
|
|
48
|
+
if (flicking.renderOnlyVisible) {
|
|
49
|
+
this._showOnlyVisiblePanels(flicking);
|
|
50
|
+
} else {
|
|
51
|
+
flicking.panels.forEach(panel => panel.markForShow());
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public collectPanels(
|
|
56
|
+
flicking: Flicking,
|
|
57
|
+
elements: any[]
|
|
58
|
+
) {
|
|
59
|
+
const align = parsePanelAlign(flicking.renderer.align);
|
|
60
|
+
|
|
61
|
+
return elements.map((el, index) => new this._panelCtor({
|
|
62
|
+
index,
|
|
63
|
+
elementProvider: new this._providerCtor(el),
|
|
64
|
+
align,
|
|
65
|
+
flicking
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public createPanel(
|
|
70
|
+
element: any,
|
|
71
|
+
options: Omit<PanelOptions, "elementProvider">
|
|
72
|
+
) {
|
|
73
|
+
return new this._panelCtor({
|
|
74
|
+
...options,
|
|
75
|
+
elementProvider: new this._providerCtor(element)
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public updatePanelSizes(flicking: Flicking, size: Partial<{
|
|
80
|
+
width: number | string;
|
|
81
|
+
height: number | string;
|
|
82
|
+
}>) {
|
|
83
|
+
flicking.panels.forEach(panel => panel.setSize(size));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private _showOnlyVisiblePanels(flicking: Flicking) {
|
|
87
|
+
const panels = flicking.renderer.panels;
|
|
88
|
+
const camera = flicking.camera;
|
|
89
|
+
|
|
90
|
+
const visibleIndexes = camera.visiblePanels.reduce((visibles, panel) => {
|
|
91
|
+
visibles[panel.index] = true;
|
|
92
|
+
return visibles;
|
|
93
|
+
}, {});
|
|
94
|
+
|
|
95
|
+
panels.forEach(panel => {
|
|
96
|
+
if (panel.index in visibleIndexes || panel.loading) {
|
|
97
|
+
panel.markForShow();
|
|
98
|
+
} else if (!flicking.holding) {
|
|
99
|
+
// During the input sequence,
|
|
100
|
+
// Do not remove panel elements as it won't trigger touchend event.
|
|
101
|
+
panel.markForHide();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
camera.updateOffset();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export default NormalRenderingStrategy;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2015 NAVER Corp.
|
|
3
|
+
* egjs projects are licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import Flicking from "../../Flicking";
|
|
6
|
+
import Panel, { PanelOptions } from "../../core/panel/Panel";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
interface RenderingStrategy {
|
|
12
|
+
renderPanels(flicking: Flicking): void;
|
|
13
|
+
getRenderingIndexesByOrder(flicking: Flicking): number[];
|
|
14
|
+
getRenderingElementsByOrder(flicking: Flicking): HTMLElement[];
|
|
15
|
+
updateRenderingPanels(flicking: Flicking): void;
|
|
16
|
+
createPanel(element: any, options: Omit<PanelOptions, "elementProvider">): Panel;
|
|
17
|
+
collectPanels(flicking: Flicking, elements: any[]): Panel[];
|
|
18
|
+
updatePanelSizes(flicking: Flicking, size: Partial<{ width: number | string; height: number | string }>): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default RenderingStrategy;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2015 NAVER Corp.
|
|
3
|
+
* egjs projects are licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import Flicking from "../../Flicking";
|
|
6
|
+
import { PanelOptions } from "../../core/panel/Panel";
|
|
7
|
+
import VirtualPanel from "../../core/panel/VirtualPanel";
|
|
8
|
+
import VirtualElementProvider from "../../core/panel/provider/VirtualElementProvider";
|
|
9
|
+
import { parsePanelAlign, range, setSize } from "../../utils";
|
|
10
|
+
|
|
11
|
+
import RenderingStrategy from "./RenderingStrategy";
|
|
12
|
+
|
|
13
|
+
class VirtualRenderingStrategy implements RenderingStrategy {
|
|
14
|
+
public renderPanels(flicking: Flicking) {
|
|
15
|
+
const virtualManager = flicking.virtual;
|
|
16
|
+
const visiblePanels = flicking.visiblePanels as VirtualPanel[];
|
|
17
|
+
const invisibleIndexes = range(flicking.panelsPerView + 1);
|
|
18
|
+
|
|
19
|
+
visiblePanels.forEach(panel => {
|
|
20
|
+
const elementIndex = panel.elementIndex;
|
|
21
|
+
|
|
22
|
+
panel.render();
|
|
23
|
+
|
|
24
|
+
virtualManager.show(elementIndex);
|
|
25
|
+
invisibleIndexes[elementIndex] = -1;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
invisibleIndexes
|
|
29
|
+
.filter(val => val >= 0)
|
|
30
|
+
.forEach(idx => {
|
|
31
|
+
virtualManager.hide(idx);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public getRenderingIndexesByOrder(flicking: Flicking) {
|
|
36
|
+
const virtualManager = flicking.virtual;
|
|
37
|
+
const visiblePanels = [...flicking.visiblePanels]
|
|
38
|
+
.filter(panel => panel.rendered)
|
|
39
|
+
.sort((panel1, panel2) => {
|
|
40
|
+
return (panel1.position + panel1.offset) - (panel2.position + panel2.offset);
|
|
41
|
+
}) as VirtualPanel[];
|
|
42
|
+
|
|
43
|
+
if (visiblePanels.length <= 0) return virtualManager.elements.map((_, idx) => idx);
|
|
44
|
+
|
|
45
|
+
const visibleIndexes = visiblePanels.map(panel => panel.elementIndex);
|
|
46
|
+
const invisibleIndexes = virtualManager.elements
|
|
47
|
+
.map((el, idx) => ({ ...el, idx }))
|
|
48
|
+
.filter(el => !el.visible)
|
|
49
|
+
.map(el => el.idx);
|
|
50
|
+
|
|
51
|
+
return [...visibleIndexes, ...invisibleIndexes];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public getRenderingElementsByOrder(flicking: Flicking) {
|
|
55
|
+
const virtualManager = flicking.virtual;
|
|
56
|
+
const elements = virtualManager.elements;
|
|
57
|
+
|
|
58
|
+
return this.getRenderingIndexesByOrder(flicking).map(index => elements[index].nativeElement);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public updateRenderingPanels(flicking: Flicking) {
|
|
62
|
+
const panels = flicking.renderer.panels;
|
|
63
|
+
const camera = flicking.camera;
|
|
64
|
+
|
|
65
|
+
const visibleIndexes = camera.visiblePanels.reduce((visibles, panel) => {
|
|
66
|
+
visibles[panel.index] = true;
|
|
67
|
+
return visibles;
|
|
68
|
+
}, {});
|
|
69
|
+
|
|
70
|
+
panels.forEach(panel => {
|
|
71
|
+
if (panel.index in visibleIndexes || panel.loading) {
|
|
72
|
+
panel.markForShow();
|
|
73
|
+
} else {
|
|
74
|
+
panel.markForHide();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
camera.updateOffset();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public collectPanels(flicking: Flicking) {
|
|
82
|
+
const align = parsePanelAlign(flicking.renderer.align);
|
|
83
|
+
|
|
84
|
+
return range(flicking.virtual.initialPanelCount).map(index => new VirtualPanel({
|
|
85
|
+
index,
|
|
86
|
+
elementProvider: new VirtualElementProvider(flicking),
|
|
87
|
+
align,
|
|
88
|
+
flicking
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public createPanel(_el: any, options: PanelOptions) {
|
|
93
|
+
return new VirtualPanel({
|
|
94
|
+
...options,
|
|
95
|
+
elementProvider: new VirtualElementProvider(options.flicking)
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public updatePanelSizes(flicking: Flicking, size: Partial<{
|
|
100
|
+
width: number | string;
|
|
101
|
+
height: number | string;
|
|
102
|
+
}>) {
|
|
103
|
+
flicking.virtual.elements.forEach(el => {
|
|
104
|
+
setSize(el.nativeElement, size);
|
|
105
|
+
});
|
|
106
|
+
flicking.panels.forEach(panel => panel.setSize(size));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export default VirtualRenderingStrategy;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2015 NAVER Corp.
|
|
3
|
+
* egjs projects are licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import RenderingStrategy from "./RenderingStrategy";
|
|
6
|
+
import NormalRenderingStrategy, { NormalRenderingStrategyOptions } from "./NormalRenderingStrategy";
|
|
7
|
+
import VirtualRenderingStrategy from "./VirtualRenderingStrategy";
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
NormalRenderingStrategy,
|
|
11
|
+
VirtualRenderingStrategy
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type {
|
|
15
|
+
RenderingStrategy,
|
|
16
|
+
NormalRenderingStrategyOptions
|
|
17
|
+
};
|
package/src/utils.ts
CHANGED
|
@@ -49,9 +49,9 @@ export const checkExistence = (value: any, nameOnErrMsg: string) => {
|
|
|
49
49
|
|
|
50
50
|
export const clamp = (x: number, min: number, max: number) => Math.max(Math.min(x, max), min);
|
|
51
51
|
|
|
52
|
-
export const getFlickingAttached = (val: Flicking | null
|
|
52
|
+
export const getFlickingAttached = (val: Flicking | null): Flicking => {
|
|
53
53
|
if (!val) {
|
|
54
|
-
throw new FlickingError(ERROR.MESSAGE.NOT_ATTACHED_TO_FLICKING
|
|
54
|
+
throw new FlickingError(ERROR.MESSAGE.NOT_ATTACHED_TO_FLICKING, ERROR.CODE.NOT_ATTACHED_TO_FLICKING);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
return val;
|
|
@@ -163,6 +163,10 @@ export const parseArithmeticExpression = (cssValue: number | string): { percenta
|
|
|
163
163
|
|
|
164
164
|
export const parseCSSSizeValue = (val: string | number): string => isString(val) ? val : `${val}px`;
|
|
165
165
|
|
|
166
|
+
export const parsePanelAlign = (align: FlickingOptions["align"]) => typeof align === "object"
|
|
167
|
+
? (align as { panel: string | number }).panel
|
|
168
|
+
: align;
|
|
169
|
+
|
|
166
170
|
export const getDirection = (start: number, end: number): ValueOf<typeof DIRECTION> => {
|
|
167
171
|
if (start === end) return DIRECTION.NONE;
|
|
168
172
|
return start < end ? DIRECTION.NEXT : DIRECTION.PREV;
|
|
@@ -254,6 +258,26 @@ export const getProgress = (pos: number, prev: number, next: number) => (pos - p
|
|
|
254
258
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
255
259
|
export const getStyle = (el: HTMLElement): CSSStyleDeclaration => window.getComputedStyle(el) || (el as any).currentStyle as CSSStyleDeclaration;
|
|
256
260
|
|
|
261
|
+
export const setSize = (el: HTMLElement, { width, height }: Partial<{
|
|
262
|
+
width: number | string;
|
|
263
|
+
height: number | string;
|
|
264
|
+
}>) => {
|
|
265
|
+
if (width != null) {
|
|
266
|
+
if (isString(width)) {
|
|
267
|
+
el.style.width = width;
|
|
268
|
+
} else {
|
|
269
|
+
el.style.width = `${width}px`;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (height != null) {
|
|
273
|
+
if (isString(height)) {
|
|
274
|
+
el.style.height = height;
|
|
275
|
+
} else {
|
|
276
|
+
el.style.height = `${height}px`;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
|
|
257
281
|
export const isBetween = (val: number, min: number, max: number) => val >= min && val <= max;
|
|
258
282
|
|
|
259
283
|
export const circulateIndex = (index: number, max: number): number => {
|
|
@@ -266,6 +290,16 @@ export const circulateIndex = (index: number, max: number): number => {
|
|
|
266
290
|
}
|
|
267
291
|
};
|
|
268
292
|
|
|
293
|
+
export const range = (end: number): number[] => {
|
|
294
|
+
const arr = new Array(end);
|
|
295
|
+
|
|
296
|
+
for (let i = 0; i < end; i++) {
|
|
297
|
+
arr[i] = i;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return arr;
|
|
301
|
+
};
|
|
302
|
+
|
|
269
303
|
export const setPrototypeOf = Object.setPrototypeOf || ((obj, proto) => {
|
|
270
304
|
obj.__proto__ = proto;
|
|
271
305
|
return obj;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import Panel, { PanelOptions } from "./Panel";
|
|
2
|
-
export interface ElementPanelOptions extends PanelOptions {
|
|
3
|
-
el: HTMLElement;
|
|
4
|
-
}
|
|
5
|
-
declare class ElementPanel extends Panel {
|
|
6
|
-
private _el;
|
|
7
|
-
private _rendered;
|
|
8
|
-
get element(): HTMLElement;
|
|
9
|
-
get rendered(): boolean;
|
|
10
|
-
constructor(options: ElementPanelOptions);
|
|
11
|
-
markForShow(): void;
|
|
12
|
-
markForHide(): void;
|
|
13
|
-
}
|
|
14
|
-
export default ElementPanel;
|
package/declaration/exports.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { FlickingOptions, FlickingEvents } from "./Flicking";
|
|
2
|
-
export * from "./core";
|
|
3
|
-
export * from "./camera";
|
|
4
|
-
export * from "./control";
|
|
5
|
-
export * from "./renderer";
|
|
6
|
-
export * from "./const/external";
|
|
7
|
-
export * from "./type/event";
|
|
8
|
-
export * from "./type/external";
|
|
9
|
-
export * from "./cfc";
|
|
10
|
-
export type { FlickingOptions, FlickingEvents };
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2015 NAVER Corp.
|
|
3
|
-
* egjs projects are licensed under the MIT license
|
|
4
|
-
*/
|
|
5
|
-
import Panel, { PanelOptions } from "./Panel";
|
|
6
|
-
|
|
7
|
-
export interface ElementPanelOptions extends PanelOptions {
|
|
8
|
-
el: HTMLElement;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* An slide data component that holds information of a single HTMLElement
|
|
13
|
-
* @ko 슬라이드 데이터 컴포넌트로, 단일 HTMLElement의 정보를 갖고 있습니다
|
|
14
|
-
*/
|
|
15
|
-
class ElementPanel extends Panel {
|
|
16
|
-
private _el: HTMLElement;
|
|
17
|
-
private _rendered: boolean;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* `HTMLElement` that panel's referencing
|
|
21
|
-
* @ko 패널이 참조하고 있는 `HTMLElement`
|
|
22
|
-
* @type {HTMLElement}
|
|
23
|
-
* @readonly
|
|
24
|
-
*/
|
|
25
|
-
public get element() { return this._el; }
|
|
26
|
-
|
|
27
|
-
public get rendered() { return this._rendered; }
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @param {object} options An options object<ko>옵션 오브젝트</ko>
|
|
31
|
-
* @param {HTMLElement} [options.el] A `HTMLElement` panel's referencing<ko>패널이 참조하는 `HTMLElement`</ko>
|
|
32
|
-
* @param {number} [options.index] An initial index of the panel<ko>패널의 초기 인덱스</ko>
|
|
33
|
-
* @param {Constants.ALIGN | string | number} [options.align] An initial {@link Flicking#align align} value of the panel<ko>패널의 초기 {@link Flicking#align align}값</ko>
|
|
34
|
-
* @param {Flicking} [options.flicking] A Flicking instance panel's referencing<ko>패널이 참조하는 {@link Flicking} 인스턴스</ko>
|
|
35
|
-
*/
|
|
36
|
-
public constructor(options: ElementPanelOptions) {
|
|
37
|
-
super(options);
|
|
38
|
-
|
|
39
|
-
this._el = options.el;
|
|
40
|
-
this._rendered = true;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public markForShow() {
|
|
44
|
-
this._rendered = true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public markForHide() {
|
|
48
|
-
this._rendered = false;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export default ElementPanel;
|
package/src/exports.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2015 NAVER Corp.
|
|
3
|
-
* egjs projects are licensed under the MIT license
|
|
4
|
-
*/
|
|
5
|
-
import type { FlickingOptions, FlickingEvents } from "./Flicking";
|
|
6
|
-
|
|
7
|
-
export * from "./core";
|
|
8
|
-
export * from "./camera";
|
|
9
|
-
export * from "./control";
|
|
10
|
-
export * from "./renderer";
|
|
11
|
-
export * from "./const/external";
|
|
12
|
-
export * from "./type/event";
|
|
13
|
-
export * from "./type/external";
|
|
14
|
-
export * from "./cfc";
|
|
15
|
-
|
|
16
|
-
export type { FlickingOptions, FlickingEvents };
|