@egjs/flicking 4.3.0 → 4.4.2

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 (78) hide show
  1. package/README.md +1 -2
  2. package/declaration/Flicking.d.ts +23 -11
  3. package/declaration/camera/Camera.d.ts +3 -2
  4. package/declaration/camera/CircularCamera.d.ts +2 -1
  5. package/declaration/const/error.d.ts +3 -1
  6. package/declaration/const/external.d.ts +5 -0
  7. package/declaration/core/AutoResizer.d.ts +13 -0
  8. package/declaration/core/VirtualManager.d.ts +37 -0
  9. package/declaration/core/index.d.ts +2 -1
  10. package/declaration/core/panel/Panel.d.ts +13 -7
  11. package/declaration/core/panel/VirtualPanel.d.ts +19 -0
  12. package/declaration/core/panel/index.d.ts +4 -4
  13. package/declaration/core/panel/provider/ElementProvider.d.ts +8 -0
  14. package/declaration/core/panel/provider/VanillaElementProvider.d.ts +12 -0
  15. package/declaration/core/panel/provider/VirtualElementProvider.d.ts +15 -0
  16. package/declaration/core/panel/provider/index.d.ts +5 -0
  17. package/declaration/index.d.ts +11 -1
  18. package/declaration/renderer/ExternalRenderer.d.ts +1 -1
  19. package/declaration/renderer/Renderer.d.ts +17 -12
  20. package/declaration/renderer/VanillaRenderer.d.ts +2 -7
  21. package/declaration/renderer/index.d.ts +1 -0
  22. package/declaration/renderer/strategy/NormalRenderingStrategy.d.ts +23 -0
  23. package/declaration/renderer/strategy/RenderingStrategy.d.ts +15 -0
  24. package/declaration/renderer/strategy/VirtualRenderingStrategy.d.ts +17 -0
  25. package/declaration/renderer/strategy/index.d.ts +5 -0
  26. package/declaration/utils.d.ts +7 -1
  27. package/dist/flicking.esm.js +1401 -421
  28. package/dist/flicking.esm.js.map +1 -1
  29. package/dist/flicking.js +1429 -425
  30. package/dist/flicking.js.map +1 -1
  31. package/dist/flicking.min.js +2 -2
  32. package/dist/flicking.min.js.map +1 -1
  33. package/dist/flicking.pkgd.js +8683 -8061
  34. package/dist/flicking.pkgd.js.map +1 -1
  35. package/dist/flicking.pkgd.min.js +2 -2
  36. package/dist/flicking.pkgd.min.js.map +1 -1
  37. package/package.json +9 -22
  38. package/src/Flicking.ts +146 -30
  39. package/src/camera/BoundCamera.ts +2 -2
  40. package/src/camera/Camera.ts +50 -27
  41. package/src/camera/CircularCamera.ts +52 -27
  42. package/src/camera/LinearCamera.ts +1 -1
  43. package/src/cfc/sync.ts +10 -5
  44. package/src/const/error.ts +6 -3
  45. package/src/const/external.ts +6 -0
  46. package/src/control/AxesController.ts +11 -6
  47. package/src/control/Control.ts +6 -6
  48. package/src/control/FreeControl.ts +2 -2
  49. package/src/control/SnapControl.ts +3 -3
  50. package/src/control/StrictControl.ts +2 -2
  51. package/src/core/AutoResizer.ts +81 -0
  52. package/src/core/Viewport.ts +4 -4
  53. package/src/core/VirtualManager.ts +188 -0
  54. package/src/core/index.ts +3 -1
  55. package/src/core/panel/Panel.ts +54 -34
  56. package/src/core/panel/VirtualPanel.ts +110 -0
  57. package/src/core/panel/index.ts +5 -7
  58. package/src/core/panel/provider/ElementProvider.ts +14 -0
  59. package/src/core/panel/provider/VanillaElementProvider.ts +45 -0
  60. package/src/core/panel/provider/VirtualElementProvider.ts +48 -0
  61. package/src/core/panel/provider/index.ts +16 -0
  62. package/src/index.ts +12 -1
  63. package/src/index.umd.ts +2 -0
  64. package/src/renderer/ExternalRenderer.ts +7 -7
  65. package/src/renderer/Renderer.ts +106 -65
  66. package/src/renderer/VanillaRenderer.ts +28 -86
  67. package/src/renderer/index.ts +2 -0
  68. package/src/renderer/strategy/NormalRenderingStrategy.ts +106 -0
  69. package/src/renderer/strategy/RenderingStrategy.ts +21 -0
  70. package/src/renderer/strategy/VirtualRenderingStrategy.ts +110 -0
  71. package/src/renderer/strategy/index.ts +17 -0
  72. package/src/utils.ts +36 -2
  73. package/declaration/core/panel/ElementPanel.d.ts +0 -14
  74. package/declaration/core/panel/ExternalPanel.d.ts +0 -9
  75. package/declaration/exports.d.ts +0 -10
  76. package/src/core/panel/ElementPanel.ts +0 -52
  77. package/src/core/panel/ExternalPanel.ts +0 -32
  78. package/src/exports.ts +0 -16
@@ -68,12 +68,38 @@ class CircularCamera extends Camera {
68
68
  if (!this._circularEnabled) return super.findAnchorIncludePosition(position);
69
69
 
70
70
  const range = this._range;
71
+ const anchors = this._anchors;
72
+ const rangeDiff = this.rangeDiff;
73
+ const anchorCount = anchors.length;
71
74
  const positionInRange = circulatePosition(position, range.min, range.max);
72
- const anchorInRange = super.findAnchorIncludePosition(positionInRange);
73
75
 
74
- if (!anchorInRange) return null;
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
+ }
75
101
 
76
- const rangeDiff = this.rangeDiff;
102
+ if (!anchorInRange) return null;
77
103
 
78
104
  if (position < range.min) {
79
105
  const loopCount = -Math.floor((range.min - position) / rangeDiff) - 1;
@@ -124,9 +150,9 @@ class CircularCamera extends Camera {
124
150
 
125
151
  // Check looped visible area for circular case
126
152
  if (visibleRange.min < range.min) {
127
- return visibleInCurrentRange || panel.includeRange(visibleRange.min + rangeDiff, visibleRange.max + rangeDiff, false);
153
+ return visibleInCurrentRange || panel.isVisibleOnRange(visibleRange.min + rangeDiff, visibleRange.max + rangeDiff);
128
154
  } else if (visibleRange.max > range.max) {
129
- return visibleInCurrentRange || panel.includeRange(visibleRange.min - rangeDiff, visibleRange.max - rangeDiff, false);
155
+ return visibleInCurrentRange || panel.isVisibleOnRange(visibleRange.min - rangeDiff, visibleRange.max - rangeDiff);
130
156
  }
131
157
 
132
158
  return visibleInCurrentRange;
@@ -142,7 +168,7 @@ class CircularCamera extends Camera {
142
168
  * @return {this}
143
169
  */
144
170
  public updateRange() {
145
- const flicking = getFlickingAttached(this._flicking, "Camera");
171
+ const flicking = getFlickingAttached(this._flicking);
146
172
  const renderer = flicking.renderer;
147
173
 
148
174
  const panels = renderer.panels;
@@ -171,13 +197,19 @@ class CircularCamera extends Camera {
171
197
  this._range = { min: firstPanel.position, max: lastPanel.position };
172
198
  }
173
199
 
174
- this._updateCircularOffset();
200
+ this.updateOffset();
175
201
 
176
202
  return this;
177
203
  }
178
204
 
205
+ public updateOffset() {
206
+ this._updateCircularOffset();
207
+
208
+ return super.updateOffset();
209
+ }
210
+
179
211
  public lookAt(pos: number) {
180
- const flicking = getFlickingAttached(this._flicking, "Camera");
212
+ const flicking = getFlickingAttached(this._flicking);
181
213
  const prevPos = this._position;
182
214
 
183
215
  if (pos === prevPos) return super.lookAt(pos);
@@ -186,24 +218,26 @@ class CircularCamera extends Camera {
186
218
  const toggled = panels.map(panel => panel.toggle(prevPos, pos));
187
219
 
188
220
  this._position = pos;
221
+ super.lookAt(pos);
189
222
 
190
223
  if (toggled.some(isToggled => isToggled)) {
191
- this._updateCircularOffset();
192
- void flicking.renderer.render();
224
+ void flicking.renderer.render().then(() => {
225
+ this.updateOffset();
226
+ });
193
227
  }
194
-
195
- return super.lookAt(pos);
196
228
  }
197
229
 
198
- protected _applyTransform(): void {
230
+ public applyTransform(): this {
199
231
  const el = this._el;
200
- const flicking = getFlickingAttached(this._flicking, "Camera");
232
+ const flicking = getFlickingAttached(this._flicking);
201
233
 
202
234
  const actualPosition = this._position - this._alignPos - this._offset + this._circularOffset;
203
235
 
204
236
  el.style[this._transform] = flicking.horizontal
205
237
  ? `translate(${-actualPosition}px)`
206
238
  : `translate(0, ${-actualPosition}px)`;
239
+
240
+ return this;
207
241
  }
208
242
 
209
243
  protected _resetInternalValues() {
@@ -222,19 +256,10 @@ class CircularCamera extends Camera {
222
256
  return;
223
257
  }
224
258
 
225
- const flicking = getFlickingAttached(this._flicking, "Camera");
226
- const toggledPrev: Panel[] = [];
227
- const toggledNext: Panel[] = [];
228
-
229
- flicking.panels
230
- .filter(panel => panel.toggled)
231
- .forEach(panel => {
232
- if (panel.toggleDirection === DIRECTION.PREV) {
233
- toggledPrev.push(panel);
234
- } else {
235
- toggledNext.push(panel);
236
- }
237
- });
259
+ const flicking = getFlickingAttached(this._flicking);
260
+ const toggled = flicking.panels.filter(panel => panel.toggled);
261
+ const toggledPrev = toggled.filter(panel => panel.toggleDirection === DIRECTION.PREV);
262
+ const toggledNext = toggled.filter(panel => panel.toggleDirection === DIRECTION.NEXT);
238
263
 
239
264
  this._circularOffset = this._calcPanelAreaSum(toggledPrev) - this._calcPanelAreaSum(toggledNext);
240
265
  }
@@ -21,7 +21,7 @@ class LinearCamera extends Camera {
21
21
  * @return {this}
22
22
  */
23
23
  public updateRange() {
24
- const flicking = getFlickingAttached(this._flicking, "Camera");
24
+ const flicking = getFlickingAttached(this._flicking);
25
25
  const renderer = flicking.renderer;
26
26
 
27
27
  const firstPanel = renderer.getPanel(0);
package/src/cfc/sync.ts CHANGED
@@ -6,6 +6,7 @@ import Renderer from "../renderer/Renderer";
6
6
  export default (flicking: Flicking, diffResult: DiffResult<any>, rendered: any[]) => {
7
7
  const renderer = flicking.renderer;
8
8
  const panels = renderer.panels;
9
+ const prevList = [...diffResult.prevList];
9
10
 
10
11
  if (diffResult.removed.length > 0) {
11
12
  let endIdx = -1;
@@ -24,6 +25,8 @@ export default (flicking: Flicking, diffResult: DiffResult<any>, rendered: any[]
24
25
  } else {
25
26
  prevIdx = removedIdx;
26
27
  }
28
+
29
+ prevList.splice(removedIdx, 1);
27
30
  });
28
31
 
29
32
  batchRemove(renderer, prevIdx, endIdx + 1);
@@ -56,13 +59,15 @@ export default (flicking: Flicking, diffResult: DiffResult<any>, rendered: any[]
56
59
  let startIdx = -1;
57
60
  let prevIdx = -1;
58
61
 
62
+ const addedElements = rendered.slice(prevList.length);
63
+
59
64
  diffResult.added.forEach((addedIdx, idx) => {
60
65
  if (startIdx < 0) {
61
66
  startIdx = idx;
62
67
  }
63
68
 
64
69
  if (prevIdx >= 0 && addedIdx !== prevIdx + 1) {
65
- batchInsert(renderer, diffResult, rendered, startIdx, idx + 1);
70
+ batchInsert(renderer, diffResult, addedElements, startIdx, idx + 1);
66
71
 
67
72
  startIdx = -1;
68
73
  prevIdx = -1;
@@ -72,20 +77,20 @@ export default (flicking: Flicking, diffResult: DiffResult<any>, rendered: any[]
72
77
  });
73
78
 
74
79
  if (startIdx >= 0) {
75
- batchInsert(renderer, diffResult, rendered, startIdx);
80
+ batchInsert(renderer, diffResult, addedElements, startIdx);
76
81
  }
77
82
  }
78
83
  };
79
84
 
80
- const batchInsert = (renderer: Renderer, diffResult: DiffResult<any>, rendered: any[], startIdx: number, endIdx?: number) => {
85
+ const batchInsert = (renderer: Renderer, diffResult: DiffResult<any>, addedElements: any[], startIdx: number, endIdx?: number) => {
81
86
  renderer.batchInsert(
82
- ...diffResult.added.slice(startIdx, endIdx).map((index, elIdx) => ({ index, elements: [rendered[elIdx + diffResult.prevList.length]] }))
87
+ ...diffResult.added.slice(startIdx, endIdx).map((index, elIdx) => ({ index, elements: [addedElements[elIdx]], hasDOMInElements: false }))
83
88
  );
84
89
  };
85
90
 
86
91
  const batchRemove = (renderer: Renderer, startIdx: number, endIdx?: number) => {
87
92
  const removed = renderer.panels.slice(startIdx, endIdx);
88
93
 
89
- renderer.batchRemove({ index: startIdx, deleteCount: removed.length });
94
+ renderer.batchRemove({ index: startIdx, deleteCount: removed.length, hasDOMInElements: false });
90
95
  };
91
96
 
@@ -25,6 +25,7 @@
25
25
  * <ko>프레임워크(React, Angular, Vue ...)에서 사용 불가능한 메소드를 호출했을 경우</ko>
26
26
  * @property {number} NOT_INITIALIZED When the {@link Flicking#init} is not called before but is needed<ko>{@link Flicking#init}의 호출이 필요하나, 아직 호출되지 않았을 경우</ko>
27
27
  * @property {number} NO_ACTIVE When there're no active panel that flicking has selected. This may be due to the absence of any panels<ko>현재 Flicking이 선택한 패널이 없을 경우. 일반적으로 패널이 하나도 없는 경우에 발생할 수 있습니다</ko>
28
+ * @property {number} NOT_ALLOWED_IN_VIRTUAL When the non-allowed method is called while the virtual option is enabled<ko>virtual 옵션이 활성화된 상태에서 사용 불가능한 메소드가 호출되었을 경우</ko>
28
29
  */
29
30
  export const CODE = {
30
31
  WRONG_TYPE: 0,
@@ -40,14 +41,15 @@ export const CODE = {
40
41
  ANIMATION_ALREADY_PLAYING: 10,
41
42
  NOT_ALLOWED_IN_FRAMEWORK: 11,
42
43
  NOT_INITIALIZED: 12,
43
- NO_ACTIVE: 13
44
+ NO_ACTIVE: 13,
45
+ NOT_ALLOWED_IN_VIRTUAL: 14
44
46
  } as const;
45
47
 
46
48
  export const MESSAGE = {
47
49
  WRONG_TYPE: (wrongVal: any, correctTypes: string[]) => `${wrongVal}(${typeof wrongVal}) is not a ${correctTypes.map(type => `"${type}"`).join(" or ")}.`,
48
50
  ELEMENT_NOT_FOUND: (selector: string) => `Element with selector "${selector}" not found.`,
49
51
  VAL_MUST_NOT_NULL: (val: any, name: string) => `${name} should be provided. Given: ${val}`,
50
- NOT_ATTACHED_TO_FLICKING: (name: string) => `${name} is not attached to the Flicking instance. "init()" should be called first.`,
52
+ NOT_ATTACHED_TO_FLICKING: "This module is not attached to the Flicking instance. \"init()\" should be called first.",
51
53
  WRONG_OPTION: (optionName: string, val: any) => `Option "${optionName}" is not in correct format, given: ${val}`,
52
54
  INDEX_OUT_OF_RANGE: (val: number, min: number, max: number) => `Index "${val}" is out of range: should be between ${min} and ${max}.`,
53
55
  POSITION_NOT_REACHABLE: (position: number) => `Position "${position}" is not reachable.`,
@@ -57,5 +59,6 @@ export const MESSAGE = {
57
59
  ANIMATION_ALREADY_PLAYING: "Animation is already playing.",
58
60
  NOT_ALLOWED_IN_FRAMEWORK: "This behavior is not allowed in the frameworks like React, Vue, or Angular.",
59
61
  NOT_INITIALIZED: "Flicking is not initialized yet, call init() first.",
60
- NO_ACTIVE: "There's no active panel that Flicking has selected. This may be due to the absence of any panels."
62
+ NO_ACTIVE: "There's no active panel that Flicking has selected. This may be due to the absence of any panels.",
63
+ NOT_ALLOWED_IN_VIRTUAL: "This behavior is not allowed when the virtual option is enabled"
61
64
  } as const;
@@ -92,3 +92,9 @@ export const MOVE_TYPE = {
92
92
  FREE_SCROLL: "freeScroll",
93
93
  STRICT: "strict"
94
94
  } as const;
95
+
96
+ export const CLASS = {
97
+ VERTICAL: "vertical",
98
+ HIDDEN: "flicking-hidden",
99
+ DEFAULT_VIRTUAL: "flicking-panel"
100
+ };
@@ -211,7 +211,7 @@ class AxesController {
211
211
  * @return {this}
212
212
  */
213
213
  public update(controlParams: ControlParams): this {
214
- const flicking = getFlickingAttached(this._flicking, "Control");
214
+ const flicking = getFlickingAttached(this._flicking);
215
215
  const camera = flicking.camera;
216
216
  const axes = this._axes!;
217
217
  const axis = axes.axis[AXES.POSITION_KEY];
@@ -231,7 +231,7 @@ class AxesController {
231
231
  * @return {this}
232
232
  */
233
233
  public addPreventClickHandler(): this {
234
- const flicking = getFlickingAttached(this._flicking, "Control");
234
+ const flicking = getFlickingAttached(this._flicking);
235
235
  const axes = this._axes!;
236
236
  const cameraEl = flicking.camera.element;
237
237
 
@@ -248,7 +248,7 @@ class AxesController {
248
248
  * @return {this}
249
249
  */
250
250
  public removePreventClickHandler(): this {
251
- const flicking = getFlickingAttached(this._flicking, "Control");
251
+ const flicking = getFlickingAttached(this._flicking);
252
252
  const axes = this._axes!;
253
253
  const cameraEl = flicking.camera.element;
254
254
 
@@ -282,17 +282,22 @@ class AxesController {
282
282
  */
283
283
  public animateTo(position: number, duration: number, axesEvent?: OnRelease): Promise<void> {
284
284
  const axes = this._axes;
285
+ const state = this._stateMachine.state;
285
286
 
286
287
  if (!axes) {
287
- return Promise.reject(new FlickingError(ERROR.MESSAGE.NOT_ATTACHED_TO_FLICKING("Control"), ERROR.CODE.NOT_ATTACHED_TO_FLICKING));
288
+ return Promise.reject(new FlickingError(ERROR.MESSAGE.NOT_ATTACHED_TO_FLICKING, ERROR.CODE.NOT_ATTACHED_TO_FLICKING));
288
289
  }
289
290
 
290
291
  const startPos = axes.get([AXES.POSITION_KEY])[AXES.POSITION_KEY];
291
292
 
292
293
  if (startPos === position) {
293
- const flicking = getFlickingAttached(this._flicking, "Control");
294
+ const flicking = getFlickingAttached(this._flicking);
294
295
 
295
296
  flicking.camera.lookAt(position);
297
+
298
+ if (state.targetPanel) {
299
+ flicking.control.setActive(state.targetPanel, flicking.control.activePanel, axesEvent?.isTrusted ?? false);
300
+ }
296
301
  return Promise.resolve();
297
302
  }
298
303
 
@@ -317,7 +322,7 @@ class AxesController {
317
322
  };
318
323
 
319
324
  if (duration === 0) {
320
- const flicking = getFlickingAttached(this._flicking, "Control");
325
+ const flicking = getFlickingAttached(this._flicking);
321
326
  const camera = flicking.camera;
322
327
 
323
328
  animate();
@@ -172,7 +172,7 @@ abstract class Control {
172
172
  * @return {Promise<void>}
173
173
  */
174
174
  public updatePosition(_progressInPanel: number): void { // eslint-disable-line @typescript-eslint/no-unused-vars
175
- const flicking = getFlickingAttached(this._flicking, "Control");
175
+ const flicking = getFlickingAttached(this._flicking);
176
176
  const camera = flicking.camera;
177
177
  const activePanel = this._activePanel;
178
178
 
@@ -188,7 +188,7 @@ abstract class Control {
188
188
  * @return {this}
189
189
  */
190
190
  public updateInput(): this {
191
- const flicking = getFlickingAttached(this._flicking, "Control");
191
+ const flicking = getFlickingAttached(this._flicking);
192
192
  const camera = flicking.camera;
193
193
 
194
194
  this._controller.update(camera.controlParams);
@@ -255,7 +255,7 @@ abstract class Control {
255
255
  direction?: ValueOf<typeof DIRECTION>;
256
256
  axesEvent?: OnRelease;
257
257
  }) {
258
- const flicking = getFlickingAttached(this._flicking, "Control");
258
+ const flicking = getFlickingAttached(this._flicking);
259
259
  const camera = flicking.camera;
260
260
 
261
261
  let position = panel.position;
@@ -299,7 +299,7 @@ abstract class Control {
299
299
  * @internal
300
300
  */
301
301
  public setActive(newActivePanel: Panel, prevActivePanel: Panel | null, isTrusted: boolean) {
302
- const flicking = getFlickingAttached(this._flicking, "Control");
302
+ const flicking = getFlickingAttached(this._flicking);
303
303
 
304
304
  this._activePanel = newActivePanel;
305
305
 
@@ -322,7 +322,7 @@ abstract class Control {
322
322
  }
323
323
 
324
324
  protected _triggerIndexChangeEvent(panel: Panel, position: number, axesEvent?: OnRelease): void {
325
- const flicking = getFlickingAttached(this._flicking, "Control");
325
+ const flicking = getFlickingAttached(this._flicking);
326
326
  const triggeringEvent = panel !== this._activePanel ? EVENTS.WILL_CHANGE : EVENTS.WILL_RESTORE;
327
327
  const camera = flicking.camera;
328
328
  const activePanel = this._activePanel;
@@ -351,7 +351,7 @@ abstract class Control {
351
351
  newActivePanel: Panel;
352
352
  axesEvent?: OnRelease;
353
353
  }) {
354
- const flicking = getFlickingAttached(this._flicking, "Control");
354
+ const flicking = getFlickingAttached(this._flicking);
355
355
  const animate = () => this._controller.animateTo(position, duration, axesEvent);
356
356
  const state = this._controller.state;
357
357
 
@@ -58,7 +58,7 @@ class FreeControl extends Control {
58
58
  * @return {Promise<void>}
59
59
  */
60
60
  public updatePosition(progressInPanel: number): void {
61
- const flicking = getFlickingAttached(this._flicking, "Control");
61
+ const flicking = getFlickingAttached(this._flicking);
62
62
  const camera = flicking.camera;
63
63
  const activePanel = this._activePanel;
64
64
 
@@ -107,7 +107,7 @@ class FreeControl extends Control {
107
107
  * @return {Promise<void>} A Promise which will be resolved after reaching the target position<ko>해당 좌표 도달시에 resolve되는 Promise</ko>
108
108
  */
109
109
  public async moveToPosition(position: number, duration: number, axesEvent?: OnRelease) {
110
- const flicking = getFlickingAttached(this._flicking, "Control");
110
+ const flicking = getFlickingAttached(this._flicking);
111
111
 
112
112
  const camera = flicking.camera;
113
113
  const targetPos = camera.clampToReachablePosition(position);
@@ -85,7 +85,7 @@ class SnapControl extends Control {
85
85
  * @return {Promise<void>} A Promise which will be resolved after reaching the target position<ko>해당 좌표 도달시에 resolve되는 Promise</ko>
86
86
  */
87
87
  public async moveToPosition(position: number, duration: number, axesEvent?: OnRelease) {
88
- const flicking = getFlickingAttached(this._flicking, "Control");
88
+ const flicking = getFlickingAttached(this._flicking);
89
89
  const camera = flicking.camera;
90
90
  const activeAnchor = camera.findActiveAnchor();
91
91
  const anchorAtCamera = camera.findNearestAnchor(camera.position);
@@ -128,7 +128,7 @@ class SnapControl extends Control {
128
128
  }
129
129
 
130
130
  private _findSnappedAnchor(position: number, anchorAtCamera: AnchorPoint): AnchorPoint {
131
- const flicking = getFlickingAttached(this._flicking, "Control");
131
+ const flicking = getFlickingAttached(this._flicking);
132
132
  const camera = flicking.camera;
133
133
  const count = this._count;
134
134
 
@@ -191,7 +191,7 @@ class SnapControl extends Control {
191
191
  }
192
192
 
193
193
  private _findAdjacentAnchor(posDelta: number, anchorAtCamera: AnchorPoint): AnchorPoint {
194
- const flicking = getFlickingAttached(this._flicking, "Control");
194
+ const flicking = getFlickingAttached(this._flicking);
195
195
  const camera = flicking.camera;
196
196
  const adjacentAnchor = (posDelta > 0 ? camera.getNextAnchor(anchorAtCamera) : camera.getPrevAnchor(anchorAtCamera)) ?? anchorAtCamera;
197
197
 
@@ -66,7 +66,7 @@ class StrictControl extends Control {
66
66
  * @return {this}
67
67
  */
68
68
  public updateInput(): this {
69
- const flicking = getFlickingAttached(this._flicking, "Control");
69
+ const flicking = getFlickingAttached(this._flicking);
70
70
  const camera = flicking.camera;
71
71
  const renderer = flicking.renderer;
72
72
  const controller = this._controller;
@@ -178,7 +178,7 @@ class StrictControl extends Control {
178
178
  * @return {Promise<void>} A Promise which will be resolved after reaching the target position<ko>해당 좌표 도달시에 resolve되는 Promise</ko>
179
179
  */
180
180
  public async moveToPosition(position: number, duration: number, axesEvent?: OnRelease) {
181
- const flicking = getFlickingAttached(this._flicking, "Control");
181
+ const flicking = getFlickingAttached(this._flicking);
182
182
  const camera = flicking.camera;
183
183
  const activePanel = this._activePanel;
184
184
  const axesRange = this._controller.range;
@@ -0,0 +1,81 @@
1
+ /*
2
+ * Copyright (c) 2015 NAVER Corp.
3
+ * egjs projects are licensed under the MIT license
4
+ */
5
+ import Flicking from "../Flicking";
6
+
7
+ class AutoResizer {
8
+ private _flicking: Flicking;
9
+ private _enabled: boolean;
10
+ private _resizeObserver: ResizeObserver | null;
11
+
12
+ public get enabled() { return this._enabled; }
13
+
14
+ public constructor(flicking: Flicking) {
15
+ this._flicking = flicking;
16
+ this._enabled = false;
17
+ this._resizeObserver = null;
18
+ }
19
+
20
+ public enable(): this {
21
+ const flicking = this._flicking;
22
+ const viewport = flicking.viewport;
23
+
24
+ if (this._enabled) {
25
+ this.disable();
26
+ }
27
+
28
+ if (flicking.useResizeObserver && !!window.ResizeObserver) {
29
+ const viewportSizeNot0 = viewport.width !== 0 || viewport.height !== 0;
30
+
31
+ const resizeObserver = viewportSizeNot0
32
+ ? new ResizeObserver(this._skipFirstResize)
33
+ : new ResizeObserver(this._onResize);
34
+
35
+ resizeObserver.observe(flicking.viewport.element);
36
+
37
+ this._resizeObserver = resizeObserver;
38
+ } else {
39
+ window.addEventListener("resize", this._onResize);
40
+ }
41
+
42
+ this._enabled = true;
43
+
44
+ return this;
45
+ }
46
+
47
+ public disable(): this {
48
+ if (!this._enabled) return this;
49
+
50
+ const resizeObserver = this._resizeObserver;
51
+ if (resizeObserver) {
52
+ resizeObserver.disconnect();
53
+ this._resizeObserver = null;
54
+ } else {
55
+ window.removeEventListener("resize", this._onResize);
56
+ }
57
+
58
+ this._enabled = false;
59
+
60
+ return this;
61
+ }
62
+
63
+ private _onResize = () => {
64
+ void this._flicking.resize();
65
+ };
66
+
67
+ // eslint-disable-next-line @typescript-eslint/member-ordering
68
+ private _skipFirstResize = (() => {
69
+ let isFirstResize = true;
70
+
71
+ return (() => {
72
+ if (isFirstResize) {
73
+ isFirstResize = false;
74
+ return;
75
+ }
76
+ this._onResize();
77
+ });
78
+ })();
79
+ }
80
+
81
+ export default AutoResizer;
@@ -124,10 +124,10 @@ class Viewport {
124
124
  this._width = el.clientWidth;
125
125
  this._height = el.clientHeight;
126
126
  this._padding = {
127
- left: parseFloat(elStyle.paddingLeft),
128
- right: parseFloat(elStyle.paddingRight),
129
- top: parseFloat(elStyle.paddingTop),
130
- bottom: parseFloat(elStyle.paddingBottom)
127
+ left: elStyle.paddingLeft ? parseFloat(elStyle.paddingLeft) : 0,
128
+ right: elStyle.paddingRight ? parseFloat(elStyle.paddingRight) : 0,
129
+ top: elStyle.paddingTop ? parseFloat(elStyle.paddingTop) : 0,
130
+ bottom: elStyle.paddingBottom ? parseFloat(elStyle.paddingBottom) : 0
131
131
  };
132
132
  this._isBorderBoxSizing = elStyle.boxSizing === "border-box";
133
133
  }