@egjs/flicking 4.3.1 → 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 +20 -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/ExternalPanel.d.ts +9 -5
- package/declaration/core/panel/Panel.d.ts +13 -7
- 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 +17 -12
- 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 +4583 -3686
- package/dist/flicking.esm.js.map +1 -1
- package/dist/flicking.js +4596 -3674
- 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 +10626 -9704
- 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 +1 -1
- package/src/Flicking.ts +130 -27
- package/src/camera/BoundCamera.ts +2 -2
- package/src/camera/Camera.ts +49 -26
- package/src/camera/CircularCamera.ts +23 -24
- 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 +11 -6
- package/src/control/Control.ts +6 -6
- 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/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 +54 -34
- 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 +106 -65
- 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
|
@@ -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 };
|