@egjs/flicking 4.3.1 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +1 -2
  2. package/declaration/Flicking.d.ts +30 -12
  3. package/declaration/camera/Camera.d.ts +29 -26
  4. package/declaration/camera/index.d.ts +2 -4
  5. package/declaration/camera/mode/BoundCameraMode.d.ts +13 -0
  6. package/declaration/camera/mode/CameraMode.d.ts +19 -0
  7. package/declaration/camera/mode/CircularCameraMode.d.ts +18 -0
  8. package/declaration/camera/mode/LinearCameraMode.d.ts +9 -0
  9. package/declaration/camera/mode/index.d.ts +6 -0
  10. package/declaration/const/error.d.ts +3 -1
  11. package/declaration/const/external.d.ts +9 -0
  12. package/declaration/core/AutoResizer.d.ts +13 -0
  13. package/declaration/core/VirtualManager.d.ts +37 -0
  14. package/declaration/core/index.d.ts +2 -1
  15. package/declaration/core/panel/Panel.d.ts +13 -7
  16. package/declaration/core/panel/VirtualPanel.d.ts +19 -0
  17. package/declaration/core/panel/index.d.ts +4 -4
  18. package/declaration/core/panel/provider/ElementProvider.d.ts +8 -0
  19. package/declaration/core/panel/provider/VanillaElementProvider.d.ts +12 -0
  20. package/declaration/core/panel/provider/VirtualElementProvider.d.ts +15 -0
  21. package/declaration/core/panel/provider/index.d.ts +5 -0
  22. package/declaration/index.d.ts +11 -1
  23. package/declaration/renderer/ExternalRenderer.d.ts +1 -1
  24. package/declaration/renderer/Renderer.d.ts +17 -12
  25. package/declaration/renderer/VanillaRenderer.d.ts +2 -7
  26. package/declaration/renderer/index.d.ts +1 -0
  27. package/declaration/renderer/strategy/NormalRenderingStrategy.d.ts +23 -0
  28. package/declaration/renderer/strategy/RenderingStrategy.d.ts +15 -0
  29. package/declaration/renderer/strategy/VirtualRenderingStrategy.d.ts +17 -0
  30. package/declaration/renderer/strategy/index.d.ts +5 -0
  31. package/declaration/type/external.d.ts +1 -3
  32. package/declaration/utils.d.ts +7 -1
  33. package/dist/flicking.esm.js +2526 -1475
  34. package/dist/flicking.esm.js.map +1 -1
  35. package/dist/flicking.js +2561 -1485
  36. package/dist/flicking.js.map +1 -1
  37. package/dist/flicking.min.js +2 -2
  38. package/dist/flicking.min.js.map +1 -1
  39. package/dist/flicking.pkgd.js +9006 -8312
  40. package/dist/flicking.pkgd.js.map +1 -1
  41. package/dist/flicking.pkgd.min.js +2 -2
  42. package/dist/flicking.pkgd.min.js.map +1 -1
  43. package/package.json +12 -24
  44. package/src/Flicking.ts +172 -45
  45. package/src/camera/Camera.ts +201 -93
  46. package/src/camera/index.ts +3 -7
  47. package/src/camera/{BoundCamera.ts → mode/BoundCameraMode.ts} +46 -43
  48. package/src/camera/mode/CameraMode.ts +77 -0
  49. package/src/camera/mode/CircularCameraMode.ts +171 -0
  50. package/src/camera/mode/LinearCameraMode.ts +23 -0
  51. package/src/camera/mode/index.ts +14 -0
  52. package/src/cfc/sync.ts +10 -5
  53. package/src/const/error.ts +6 -3
  54. package/src/const/external.ts +18 -0
  55. package/src/control/AxesController.ts +11 -6
  56. package/src/control/Control.ts +6 -6
  57. package/src/control/FreeControl.ts +2 -2
  58. package/src/control/SnapControl.ts +3 -3
  59. package/src/control/StrictControl.ts +2 -2
  60. package/src/core/AutoResizer.ts +81 -0
  61. package/src/core/Viewport.ts +4 -4
  62. package/src/core/VirtualManager.ts +188 -0
  63. package/src/core/index.ts +3 -1
  64. package/src/core/panel/Panel.ts +54 -34
  65. package/src/core/panel/VirtualPanel.ts +110 -0
  66. package/src/core/panel/index.ts +5 -7
  67. package/src/core/panel/provider/ElementProvider.ts +14 -0
  68. package/src/core/panel/provider/VanillaElementProvider.ts +45 -0
  69. package/src/core/panel/provider/VirtualElementProvider.ts +48 -0
  70. package/src/core/panel/provider/index.ts +16 -0
  71. package/src/index.ts +12 -1
  72. package/src/index.umd.ts +2 -0
  73. package/src/renderer/ExternalRenderer.ts +7 -7
  74. package/src/renderer/Renderer.ts +106 -65
  75. package/src/renderer/VanillaRenderer.ts +28 -86
  76. package/src/renderer/index.ts +2 -0
  77. package/src/renderer/strategy/NormalRenderingStrategy.ts +106 -0
  78. package/src/renderer/strategy/RenderingStrategy.ts +21 -0
  79. package/src/renderer/strategy/VirtualRenderingStrategy.ts +110 -0
  80. package/src/renderer/strategy/index.ts +17 -0
  81. package/src/utils.ts +36 -2
  82. package/declaration/camera/BoundCamera.d.ts +0 -9
  83. package/declaration/camera/CircularCamera.d.ts +0 -36
  84. package/declaration/camera/LinearCamera.d.ts +0 -5
  85. package/declaration/core/panel/ElementPanel.d.ts +0 -14
  86. package/declaration/core/panel/ExternalPanel.d.ts +0 -9
  87. package/declaration/exports.d.ts +0 -10
  88. package/src/camera/CircularCamera.ts +0 -269
  89. package/src/camera/LinearCamera.ts +0 -35
  90. package/src/core/panel/ElementPanel.ts +0 -52
  91. package/src/core/panel/ExternalPanel.ts +0 -32
  92. 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, nameToThrowOnError: string): Flicking => {
52
+ export const getFlickingAttached = (val: Flicking | null): Flicking => {
53
53
  if (!val) {
54
- throw new FlickingError(ERROR.MESSAGE.NOT_ATTACHED_TO_FLICKING(nameToThrowOnError), ERROR.CODE.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,9 +0,0 @@
1
- import AnchorPoint from "../core/AnchorPoint";
2
- import Camera from "./Camera";
3
- declare class BoundCamera extends Camera {
4
- updateRange(): this;
5
- updateAnchors(): this;
6
- findAnchorIncludePosition(position: number): AnchorPoint | null;
7
- private _findNearestPanel;
8
- }
9
- export default BoundCamera;
@@ -1,36 +0,0 @@
1
- import Panel from "../core/panel/Panel";
2
- import AnchorPoint from "../core/AnchorPoint";
3
- import { DIRECTION } from "../const/external";
4
- import { ValueOf } from "../type/internal";
5
- import Camera from "./Camera";
6
- export interface TogglePoint {
7
- panel: Panel;
8
- direction: ValueOf<typeof DIRECTION>;
9
- toggled: boolean;
10
- }
11
- declare class CircularCamera extends Camera {
12
- private _circularOffset;
13
- private _circularEnabled;
14
- get offset(): number;
15
- get controlParams(): {
16
- range: {
17
- min: number;
18
- max: number;
19
- };
20
- position: number;
21
- circular: boolean;
22
- };
23
- getPrevAnchor(anchor: AnchorPoint): AnchorPoint | null;
24
- getNextAnchor(anchor: AnchorPoint): AnchorPoint | null;
25
- findAnchorIncludePosition(position: number): AnchorPoint | null;
26
- clampToReachablePosition(position: number): number;
27
- canReach(panel: Panel): boolean;
28
- canSee(panel: Panel): boolean;
29
- updateRange(): this;
30
- lookAt(pos: number): void;
31
- protected _applyTransform(): void;
32
- protected _resetInternalValues(): void;
33
- private _calcPanelAreaSum;
34
- private _updateCircularOffset;
35
- }
36
- export default CircularCamera;
@@ -1,5 +0,0 @@
1
- import Camera from "./Camera";
2
- declare class LinearCamera extends Camera {
3
- updateRange(): this;
4
- }
5
- export default LinearCamera;
@@ -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;
@@ -1,9 +0,0 @@
1
- import Panel, { PanelOptions } from "./Panel";
2
- export interface ExternalPanelOptions<T> extends PanelOptions {
3
- externalComponent: T;
4
- }
5
- declare abstract class ExternalPanel<T = any> extends Panel {
6
- protected _externalComponent: T;
7
- constructor(options: ExternalPanelOptions<T>);
8
- }
9
- export default ExternalPanel;
@@ -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,269 +0,0 @@
1
- /*
2
- * Copyright (c) 2015 NAVER Corp.
3
- * egjs projects are licensed under the MIT license
4
- */
5
- import Panel from "../core/panel/Panel";
6
- import AnchorPoint from "../core/AnchorPoint";
7
- import { DIRECTION } from "../const/external";
8
- import { circulatePosition, getFlickingAttached } from "../utils";
9
- import { ValueOf } from "../type/internal";
10
-
11
- import Camera from "./Camera";
12
-
13
- /**
14
- * A data of the position that changes order of the panel elements
15
- * @ko 패널 엘리먼트 순서가 변경되는 좌표의 데이터
16
- * @interface
17
- * @property {Panel} panel Toggling panel<ko>순서를 변경할 패널</ko>
18
- * @property {DIRECTION} direction Toggling position<ko>순서를 변경할 방향</ko>
19
- * @property {boolean} toggled Whether the panel has toggled its position to `direction`<ko>`direction` 방향으로 패널 위치를 변경했는지 여부를 나타내는 값</ko>
20
- */
21
- export interface TogglePoint {
22
- panel: Panel;
23
- direction: ValueOf<typeof DIRECTION>;
24
- toggled: boolean;
25
- }
26
-
27
- /**
28
- * A {@link Camera} that connects the last panel and the first panel, enabling continuous loop
29
- * @ko 첫번째 패널과 마지막 패널이 이어진 상태로, 무한히 회전할 수 있는 종류의 {@link Camera}
30
- */
31
- class CircularCamera extends Camera {
32
- private _circularOffset: number = 0;
33
- private _circularEnabled: boolean = false;
34
-
35
- public get offset() { return this._offset - this._circularOffset; }
36
- public get controlParams() { return { range: this._range, position: this._position, circular: this._circularEnabled }; }
37
-
38
- public getPrevAnchor(anchor: AnchorPoint): AnchorPoint | null {
39
- if (!this._circularEnabled || anchor.index !== 0) return super.getPrevAnchor(anchor);
40
-
41
- const anchors = this._anchors;
42
- const rangeDiff = this.rangeDiff;
43
- const lastAnchor = anchors[anchors.length - 1];
44
-
45
- return new AnchorPoint({
46
- index: lastAnchor.index,
47
- position: lastAnchor.position - rangeDiff,
48
- panel: lastAnchor.panel
49
- });
50
- }
51
-
52
- public getNextAnchor(anchor: AnchorPoint): AnchorPoint | null {
53
- const anchors = this._anchors;
54
-
55
- if (!this._circularEnabled || anchor.index !== anchors.length - 1) return super.getNextAnchor(anchor);
56
-
57
- const rangeDiff = this.rangeDiff;
58
- const firstAnchor = anchors[0];
59
-
60
- return new AnchorPoint({
61
- index: firstAnchor.index,
62
- position: firstAnchor.position + rangeDiff,
63
- panel: firstAnchor.panel
64
- });
65
- }
66
-
67
- public findAnchorIncludePosition(position: number): AnchorPoint | null {
68
- if (!this._circularEnabled) return super.findAnchorIncludePosition(position);
69
-
70
- const range = this._range;
71
- const anchors = this._anchors;
72
- const rangeDiff = this.rangeDiff;
73
- const anchorCount = anchors.length;
74
- const positionInRange = circulatePosition(position, range.min, range.max);
75
-
76
- let anchorInRange: AnchorPoint | null = super.findAnchorIncludePosition(positionInRange);
77
-
78
- if (anchorCount > 0 && (position === range.min || position === range.max)) {
79
- const possibleAnchors = [
80
- anchorInRange,
81
- new AnchorPoint({
82
- index: 0,
83
- position: anchors[0].position + rangeDiff,
84
- panel: anchors[0].panel
85
- }),
86
- new AnchorPoint({
87
- index: anchorCount - 1,
88
- position: anchors[anchorCount - 1].position - rangeDiff,
89
- panel: anchors[anchorCount - 1].panel
90
- })
91
- ].filter(anchor => !!anchor) as AnchorPoint[];
92
-
93
- anchorInRange = possibleAnchors.reduce((nearest: AnchorPoint | null, anchor) => {
94
- if (!nearest) return anchor;
95
-
96
- return Math.abs(nearest.position - position) < Math.abs(anchor.position - position)
97
- ? nearest
98
- : anchor;
99
- }, null);
100
- }
101
-
102
- if (!anchorInRange) return null;
103
-
104
- if (position < range.min) {
105
- const loopCount = -Math.floor((range.min - position) / rangeDiff) - 1;
106
-
107
- return new AnchorPoint({
108
- index: anchorInRange.index,
109
- position: anchorInRange.position + rangeDiff * loopCount,
110
- panel: anchorInRange.panel
111
- });
112
- } else if (position > range.max) {
113
- const loopCount = Math.floor((position - range.max) / rangeDiff) + 1;
114
-
115
- return new AnchorPoint({
116
- index: anchorInRange.index,
117
- position: anchorInRange.position + rangeDiff * loopCount,
118
- panel: anchorInRange.panel
119
- });
120
- }
121
-
122
- return anchorInRange;
123
- }
124
-
125
- public clampToReachablePosition(position: number): number {
126
- // Basically all position is reachable for circular camera
127
- return this._circularEnabled
128
- ? position
129
- : super.clampToReachablePosition(position);
130
- }
131
-
132
- public canReach(panel: Panel): boolean {
133
- if (panel.removed) return false;
134
-
135
- return this._circularEnabled
136
- // Always reachable on circular mode
137
- ? true
138
- : super.canReach(panel);
139
- }
140
-
141
- public canSee(panel: Panel): boolean {
142
- const range = this._range;
143
- const rangeDiff = this.rangeDiff;
144
- const visibleRange = this.visibleRange;
145
- const visibleInCurrentRange = super.canSee(panel);
146
-
147
- if (!this._circularEnabled) {
148
- return visibleInCurrentRange;
149
- }
150
-
151
- // Check looped visible area for circular case
152
- if (visibleRange.min < range.min) {
153
- return visibleInCurrentRange || panel.includeRange(visibleRange.min + rangeDiff, visibleRange.max + rangeDiff, false);
154
- } else if (visibleRange.max > range.max) {
155
- return visibleInCurrentRange || panel.includeRange(visibleRange.min - rangeDiff, visibleRange.max - rangeDiff, false);
156
- }
157
-
158
- return visibleInCurrentRange;
159
- }
160
-
161
- /**
162
- * Update {@link Camera#range range} of Camera
163
- * @ko Camera의 {@link Camera#range range}를 업데이트합니다
164
- * @chainable
165
- * @throws {FlickingError}
166
- * {@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} When {@link Camera#init init} is not called before
167
- * <ko>{@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} {@link Camera#init init}이 이전에 호출되지 않은 경우</ko>
168
- * @return {this}
169
- */
170
- public updateRange() {
171
- const flicking = getFlickingAttached(this._flicking, "Camera");
172
- const renderer = flicking.renderer;
173
-
174
- const panels = renderer.panels;
175
- if (panels.length <= 0) {
176
- this._resetInternalValues();
177
- return this;
178
- }
179
-
180
- const firstPanel = panels[0]!;
181
- const lastPanel = panels[panels.length - 1]!;
182
- const firstPanelPrev = firstPanel.range.min - firstPanel.margin.prev;
183
- const lastPanelNext = lastPanel.range.max + lastPanel.margin.next;
184
-
185
- const visibleSize = this.size;
186
- const panelSizeSum = lastPanelNext - firstPanelPrev;
187
-
188
- const canSetCircularMode = panels
189
- .every(panel => panelSizeSum - panel.size >= visibleSize);
190
- this._circularEnabled = canSetCircularMode;
191
-
192
- if (canSetCircularMode) {
193
- this._range = { min: firstPanelPrev, max: lastPanelNext };
194
-
195
- panels.forEach(panel => panel.updateCircularToggleDirection());
196
- } else {
197
- this._range = { min: firstPanel.position, max: lastPanel.position };
198
- }
199
-
200
- this._updateCircularOffset();
201
-
202
- return this;
203
- }
204
-
205
- public lookAt(pos: number) {
206
- const flicking = getFlickingAttached(this._flicking, "Camera");
207
- const prevPos = this._position;
208
-
209
- if (pos === prevPos) return super.lookAt(pos);
210
-
211
- const panels = flicking.renderer.panels;
212
- const toggled = panels.map(panel => panel.toggle(prevPos, pos));
213
-
214
- this._position = pos;
215
-
216
- if (toggled.some(isToggled => isToggled)) {
217
- this._updateCircularOffset();
218
- void flicking.renderer.render();
219
- }
220
-
221
- return super.lookAt(pos);
222
- }
223
-
224
- protected _applyTransform(): void {
225
- const el = this._el;
226
- const flicking = getFlickingAttached(this._flicking, "Camera");
227
-
228
- const actualPosition = this._position - this._alignPos - this._offset + this._circularOffset;
229
-
230
- el.style[this._transform] = flicking.horizontal
231
- ? `translate(${-actualPosition}px)`
232
- : `translate(0, ${-actualPosition}px)`;
233
- }
234
-
235
- protected _resetInternalValues() {
236
- super._resetInternalValues();
237
- this._circularOffset = 0;
238
- this._circularEnabled = false;
239
- }
240
-
241
- private _calcPanelAreaSum(panels: Panel[]) {
242
- return panels.reduce((sum: number, panel: Panel) => sum + panel.sizeIncludingMargin, 0);
243
- }
244
-
245
- private _updateCircularOffset() {
246
- if (!this._circularEnabled) {
247
- this._circularOffset = 0;
248
- return;
249
- }
250
-
251
- const flicking = getFlickingAttached(this._flicking, "Camera");
252
- const toggledPrev: Panel[] = [];
253
- const toggledNext: Panel[] = [];
254
-
255
- flicking.panels
256
- .filter(panel => panel.toggled)
257
- .forEach(panel => {
258
- if (panel.toggleDirection === DIRECTION.PREV) {
259
- toggledPrev.push(panel);
260
- } else {
261
- toggledNext.push(panel);
262
- }
263
- });
264
-
265
- this._circularOffset = this._calcPanelAreaSum(toggledPrev) - this._calcPanelAreaSum(toggledNext);
266
- }
267
- }
268
-
269
- export default CircularCamera;
@@ -1,35 +0,0 @@
1
- /*
2
- * Copyright (c) 2015 NAVER Corp.
3
- * egjs projects are licensed under the MIT license
4
- */
5
- import { getFlickingAttached } from "../utils";
6
-
7
- import Camera from "./Camera";
8
-
9
- /**
10
- * A {@link Camera} that can move from the position of the first panel to the position of the last panel
11
- * @ko 첫번째 패널의 좌표로부터 마지막 패널의 좌표로까지 이동할 수 있는 종류의 {@link Camera}
12
- */
13
- class LinearCamera extends Camera {
14
- /**
15
- * Update {@link Camera#range range} of Camera
16
- * @ko Camera의 {@link Camera#range range}를 업데이트합니다
17
- * @chainable
18
- * @throws {FlickingError}
19
- * {@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} When {@link Camera#init init} is not called before
20
- * <ko>{@link ERROR_CODE NOT_ATTACHED_TO_FLICKING} {@link Camera#init init}이 이전에 호출되지 않은 경우</ko>
21
- * @return {this}
22
- */
23
- public updateRange() {
24
- const flicking = getFlickingAttached(this._flicking, "Camera");
25
- const renderer = flicking.renderer;
26
-
27
- const firstPanel = renderer.getPanel(0);
28
- const lastPanel = renderer.getPanel(renderer.panelCount - 1);
29
-
30
- this._range = { min: firstPanel?.position ?? 0, max: lastPanel?.position ?? 0 };
31
- return this;
32
- }
33
- }
34
-
35
- export default LinearCamera;
@@ -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;
@@ -1,32 +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 ExternalPanelOptions<T> extends PanelOptions {
8
- externalComponent: T;
9
- }
10
-
11
- /**
12
- * An slide data component that holds information of a single HTMLElement
13
- * @ko 슬라이드 데이터 컴포넌트로, 단일 HTMLElement의 정보를 갖고 있습니다
14
- */
15
- abstract class ExternalPanel<T = any> extends Panel {
16
- protected _externalComponent: T;
17
-
18
- /**
19
- * @param {object} options An options object<ko>옵션 오브젝트</ko>
20
- * @param {HTMLElement} [options.el] A `HTMLElement` panel's referencing<ko>패널이 참조하는 `HTMLElement`</ko>
21
- * @param {number} [options.index] An initial index of the panel<ko>패널의 초기 인덱스</ko>
22
- * @param {Constants.ALIGN | string | number} [options.align] An initial {@link Flicking#align align} value of the panel<ko>패널의 초기 {@link Flicking#align align}값</ko>
23
- * @param {Flicking} [options.flicking] A Flicking instance panel's referencing<ko>패널이 참조하는 {@link Flicking} 인스턴스</ko>
24
- */
25
- public constructor(options: ExternalPanelOptions<T>) {
26
- super(options);
27
-
28
- this._externalComponent = options.externalComponent;
29
- }
30
- }
31
-
32
- export default ExternalPanel;