@egjs/flicking 4.2.5 → 4.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +1 -1
  2. package/declaration/Flicking.d.ts +27 -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 +17 -10
  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 +18 -13
  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 +1616 -562
  28. package/dist/flicking.esm.js.map +1 -1
  29. package/dist/flicking.js +1571 -494
  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 +8733 -6647
  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 +10 -22
  38. package/src/Flicking.ts +163 -32
  39. package/src/camera/BoundCamera.ts +2 -2
  40. package/src/camera/Camera.ts +49 -26
  41. package/src/camera/CircularCamera.ts +52 -27
  42. package/src/camera/LinearCamera.ts +1 -1
  43. package/src/cfc/sync.ts +2 -2
  44. package/src/const/error.ts +6 -3
  45. package/src/const/external.ts +6 -0
  46. package/src/control/AxesController.ts +15 -8
  47. package/src/control/Control.ts +7 -7
  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 +68 -60
  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 +173 -68
  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
@@ -10,7 +10,7 @@ import Panel from "../core/panel/Panel";
10
10
  import AnchorPoint from "../core/AnchorPoint";
11
11
  import * as ERROR from "../const/error";
12
12
  import { ALIGN, DIRECTION, EVENTS } from "../const/external";
13
- import { checkExistence, clamp, find, getFlickingAttached, getProgress, includes, parseAlign } from "../utils";
13
+ import { checkExistence, clamp, find, getFlickingAttached, getProgress, includes, parseAlign, toArray } from "../utils";
14
14
 
15
15
  export interface CameraOptions {
16
16
  align: FlickingOptions["align"];
@@ -38,12 +38,19 @@ abstract class Camera {
38
38
 
39
39
  // Internal states getter
40
40
  /**
41
- * The camera(`.flicking-camera`) element
42
- * @ko 카메라(`.flicking-camera`) 엘리먼트
41
+ * The camera element(`.flicking-camera`)
42
+ * @ko 카메라 엘리먼트(`.flicking-camera`)
43
43
  * @type {HTMLElement}
44
44
  * @readonly
45
45
  */
46
46
  public get element() { return this._el; }
47
+ /**
48
+ * An array of the child elements of the camera element(`.flicking-camera`)
49
+ * @ko 카메라 엘리먼트(`.flicking-camera`)의 자식 엘리먼트 배열
50
+ * @type {HTMLElement[]}
51
+ * @readonly
52
+ */
53
+ public get children() { return toArray(this._el.children) as HTMLElement[]; }
47
54
  /**
48
55
  * Current position of the camera
49
56
  * @ko Camera의 현재 좌표
@@ -278,7 +285,7 @@ abstract class Camera {
278
285
  this._refreshVisiblePanels();
279
286
  this._checkNeedPanel();
280
287
  this._checkReachEnd(prevPos, pos);
281
- this._applyTransform();
288
+ this.applyTransform();
282
289
  }
283
290
 
284
291
  /**
@@ -376,7 +383,7 @@ abstract class Camera {
376
383
  * @return {AnchorPoint | null}
377
384
  */
378
385
  public findActiveAnchor(): AnchorPoint | null {
379
- const flicking = getFlickingAttached(this._flicking, "Camera");
386
+ const flicking = getFlickingAttached(this._flicking);
380
387
  const activeIndex = flicking.control.activeIndex;
381
388
 
382
389
  return find(this._anchors, anchor => anchor.panel.index === activeIndex);
@@ -418,7 +425,7 @@ abstract class Camera {
418
425
  public canSee(panel: Panel): boolean {
419
426
  const visibleRange = this.visibleRange;
420
427
  // Should not include margin, as we don't declare what the margin is visible as what the panel is visible.
421
- return panel.includeRange(visibleRange.min, visibleRange.max, false);
428
+ return panel.isVisibleOnRange(visibleRange.min, visibleRange.max);
422
429
  }
423
430
 
424
431
  /**
@@ -449,7 +456,7 @@ abstract class Camera {
449
456
  * @return {this}
450
457
  */
451
458
  public updateAnchors(): this {
452
- const flicking = getFlickingAttached(this._flicking, "Camera");
459
+ const flicking = getFlickingAttached(this._flicking);
453
460
  const panels = flicking.renderer.panels;
454
461
 
455
462
  this._anchors = panels.map((panel, index) => new AnchorPoint({
@@ -471,7 +478,7 @@ abstract class Camera {
471
478
  * @return {this}
472
479
  */
473
480
  public updateAdaptiveHeight() {
474
- const flicking = getFlickingAttached(this._flicking, "Camera");
481
+ const flicking = getFlickingAttached(this._flicking);
475
482
  const activePanel = flicking.control.activePanel;
476
483
 
477
484
  if (!flicking.horizontal || !flicking.adaptive || !activePanel) return;
@@ -481,16 +488,24 @@ abstract class Camera {
481
488
  });
482
489
  }
483
490
 
484
- public updateOffset() {
485
- const flicking = getFlickingAttached(this._flicking, "Camera");
486
- const unRenderedPanels = flicking.panels.filter(panel => !panel.rendered);
491
+ /**
492
+ * Update current offset of the camera
493
+ * @ko 현재 카메라의 오프셋을 업데이트합니다
494
+ * @chainable
495
+ * @return {this}
496
+ */
497
+ public updateOffset(): this {
498
+ const flicking = getFlickingAttached(this._flicking);
487
499
  const position = this._position;
500
+ const unRenderedPanels = flicking.panels.filter(panel => !panel.rendered);
488
501
 
489
502
  this._offset = unRenderedPanels
490
503
  .filter(panel => panel.position + panel.offset < position)
491
504
  .reduce((offset, panel) => offset + panel.sizeIncludingMargin, 0);
492
505
 
493
- this._applyTransform();
506
+ this.applyTransform();
507
+
508
+ return this;
494
509
  }
495
510
 
496
511
  /**
@@ -504,6 +519,25 @@ abstract class Camera {
504
519
  return this;
505
520
  }
506
521
 
522
+ /**
523
+ * Apply "transform" style with the current position to camera element
524
+ * @ko 현재 위치를 기준으로한 transform 스타일을 카메라 엘리먼트에 적용합니다.
525
+ * @chainable
526
+ * @return {this}
527
+ */
528
+ public applyTransform(): this {
529
+ const el = this._el;
530
+ const flicking = getFlickingAttached(this._flicking);
531
+
532
+ const actualPosition = this._position - this._alignPos - this._offset;
533
+
534
+ el.style[this._transform] = flicking.horizontal
535
+ ? `translate(${-actualPosition}px)`
536
+ : `translate(0, ${-actualPosition}px)`;
537
+
538
+ return this;
539
+ }
540
+
507
541
  protected _resetInternalValues() {
508
542
  this._position = 0;
509
543
  this._alignPos = 0;
@@ -515,7 +549,7 @@ abstract class Camera {
515
549
  }
516
550
 
517
551
  protected _refreshVisiblePanels() {
518
- const flicking = getFlickingAttached(this._flicking, "Camera");
552
+ const flicking = getFlickingAttached(this._flicking);
519
553
  const panels = flicking.renderer.panels;
520
554
 
521
555
  const newVisiblePanels = panels.filter(panel => this.canSee(panel));
@@ -541,7 +575,7 @@ abstract class Camera {
541
575
 
542
576
  if (needPanelTriggered.prev && needPanelTriggered.next) return;
543
577
 
544
- const flicking = getFlickingAttached(this._flicking, "Camera");
578
+ const flicking = getFlickingAttached(this._flicking);
545
579
  const panels = flicking.renderer.panels;
546
580
 
547
581
  if (panels.length <= 0) {
@@ -588,7 +622,7 @@ abstract class Camera {
588
622
  }
589
623
 
590
624
  protected _checkReachEnd(prevPos: number, newPos: number): void {
591
- const flicking = getFlickingAttached(this._flicking, "Camera");
625
+ const flicking = getFlickingAttached(this._flicking);
592
626
  const range = this._range;
593
627
 
594
628
  const wasBetweenRange = prevPos > range.min && prevPos < range.max;
@@ -603,17 +637,6 @@ abstract class Camera {
603
637
  }));
604
638
  }
605
639
 
606
- protected _applyTransform(): void {
607
- const el = this._el;
608
- const flicking = getFlickingAttached(this._flicking, "Camera");
609
-
610
- const actualPosition = this._position - this._alignPos - this._offset;
611
-
612
- el.style[this._transform] = flicking.horizontal
613
- ? `translate(${-actualPosition}px)`
614
- : `translate(0, ${-actualPosition}px)`;
615
- }
616
-
617
640
  protected _checkTranslateSupport = () => {
618
641
  const transforms = ["webkitTransform", "msTransform", "MozTransform", "OTransform", "transform"];
619
642
 
@@ -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
@@ -79,13 +79,13 @@ export default (flicking: Flicking, diffResult: DiffResult<any>, rendered: any[]
79
79
 
80
80
  const batchInsert = (renderer: Renderer, diffResult: DiffResult<any>, rendered: any[], startIdx: number, endIdx?: number) => {
81
81
  renderer.batchInsert(
82
- ...diffResult.added.slice(startIdx, endIdx).map((index, elIdx) => ({ index, elements: [rendered[elIdx + diffResult.prevList.length]] }))
82
+ ...diffResult.added.slice(startIdx, endIdx).map((index, elIdx) => ({ index, elements: [rendered[elIdx + diffResult.prevList.length]], hasDOMInElements: false }))
83
83
  );
84
84
  };
85
85
 
86
86
  const batchRemove = (renderer: Renderer, startIdx: number, endIdx?: number) => {
87
87
  const removed = renderer.panels.slice(startIdx, endIdx);
88
88
 
89
- renderer.batchRemove({ index: startIdx, deleteCount: removed.length });
89
+ renderer.batchRemove({ index: startIdx, deleteCount: removed.length, hasDOMInElements: false });
90
90
  };
91
91
 
@@ -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
+ };
@@ -167,9 +167,11 @@ class AxesController {
167
167
  * @return {void}
168
168
  */
169
169
  public destroy(): void {
170
- this.removePreventClickHandler();
170
+ if (this._axes) {
171
+ this.removePreventClickHandler();
172
+ this._axes.destroy();
173
+ }
171
174
 
172
- this._axes?.destroy();
173
175
  this._panInput?.destroy();
174
176
 
175
177
  this._resetInternalValues();
@@ -209,7 +211,7 @@ class AxesController {
209
211
  * @return {this}
210
212
  */
211
213
  public update(controlParams: ControlParams): this {
212
- const flicking = getFlickingAttached(this._flicking, "Control");
214
+ const flicking = getFlickingAttached(this._flicking);
213
215
  const camera = flicking.camera;
214
216
  const axes = this._axes!;
215
217
  const axis = axes.axis[AXES.POSITION_KEY];
@@ -229,7 +231,7 @@ class AxesController {
229
231
  * @return {this}
230
232
  */
231
233
  public addPreventClickHandler(): this {
232
- const flicking = getFlickingAttached(this._flicking, "Control");
234
+ const flicking = getFlickingAttached(this._flicking);
233
235
  const axes = this._axes!;
234
236
  const cameraEl = flicking.camera.element;
235
237
 
@@ -246,7 +248,7 @@ class AxesController {
246
248
  * @return {this}
247
249
  */
248
250
  public removePreventClickHandler(): this {
249
- const flicking = getFlickingAttached(this._flicking, "Control");
251
+ const flicking = getFlickingAttached(this._flicking);
250
252
  const axes = this._axes!;
251
253
  const cameraEl = flicking.camera.element;
252
254
 
@@ -280,17 +282,22 @@ class AxesController {
280
282
  */
281
283
  public animateTo(position: number, duration: number, axesEvent?: OnRelease): Promise<void> {
282
284
  const axes = this._axes;
285
+ const state = this._stateMachine.state;
283
286
 
284
287
  if (!axes) {
285
- 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));
286
289
  }
287
290
 
288
291
  const startPos = axes.get([AXES.POSITION_KEY])[AXES.POSITION_KEY];
289
292
 
290
293
  if (startPos === position) {
291
- const flicking = getFlickingAttached(this._flicking, "Control");
294
+ const flicking = getFlickingAttached(this._flicking);
292
295
 
293
296
  flicking.camera.lookAt(position);
297
+
298
+ if (state.targetPanel) {
299
+ flicking.control.setActive(state.targetPanel, flicking.control.activePanel, axesEvent?.isTrusted ?? false);
300
+ }
294
301
  return Promise.resolve();
295
302
  }
296
303
 
@@ -315,7 +322,7 @@ class AxesController {
315
322
  };
316
323
 
317
324
  if (duration === 0) {
318
- const flicking = getFlickingAttached(this._flicking, "Control");
325
+ const flicking = getFlickingAttached(this._flicking);
319
326
  const camera = flicking.camera;
320
327
 
321
328
  animate();
@@ -171,8 +171,8 @@ abstract class Control {
171
171
  * @chainable
172
172
  * @return {Promise<void>}
173
173
  */
174
- public updatePosition(_progressInPanel: number): void { // eslint-disable-line @typescript-eslint/no-unused-vars
175
- const flicking = getFlickingAttached(this._flicking, "Control");
174
+ public updatePosition(_progressInPanel: number): void { // eslint-disable-line @typescript-eslint/no-unused-vars
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
  }