@egjs/flicking 4.5.1 → 4.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egjs/flicking",
3
- "version": "4.5.1",
3
+ "version": "4.6.0",
4
4
  "description": "Everyday 30 million people experience. It's reliable, flexible and extendable carousel.",
5
5
  "main": "dist/flicking.js",
6
6
  "module": "dist/flicking.esm.js",
@@ -9,7 +9,14 @@
9
9
  "types": "declaration/index.d.ts",
10
10
  "scripts": {
11
11
  "start": "concurrently \"rollup -w --config ./rollup.config.dev.js\" \"http-serve\"",
12
- "build": "rm -rf ./dist ./declaration && rollup -c && npm run declaration && npm run css && npm run printsizes",
12
+ "build": "run-s build:bundle build:declaration build:css printsizes",
13
+ "build:bundle": "rm -rf ./dist && rollup -c",
14
+ "build:declaration": "rm -rf ./declaration && tsc -p tsconfig.declaration.json",
15
+ "build:css": "run-s build:css-clear build:sass build:css-prefix build:css-min",
16
+ "build:css-clear": "rm -rf ./dist/css",
17
+ "build:sass": "node-sass sass/ -o dist/css/ -x --output-style expanded",
18
+ "build:css-prefix": "postcss dist/css/*.css --replace --use autoprefixer --no-map",
19
+ "build:css-min": "postcss dist/css/*.css --ext .min.css --use postcss-clean -d dist/css/ --no-map",
13
20
  "declaration": "rm -rf declaration && tsc -p tsconfig.declaration.json",
14
21
  "css": "postcss css/*.css --use autoprefixer postcss-clean -d dist/ -m",
15
22
  "printsizes": "print-sizes ./dist --exclude=\\.map",
@@ -83,7 +90,7 @@
83
90
  "@typescript-eslint/eslint-plugin": "^4.18.0",
84
91
  "@typescript-eslint/eslint-plugin-tslint": "^4.18.0",
85
92
  "@typescript-eslint/parser": "^4.18.0",
86
- "autoprefixer": "^9.8.5",
93
+ "autoprefixer": "^9.8.8",
87
94
  "babel-loader": "^8.2.2",
88
95
  "babel-preset-env": "^1.7.0",
89
96
  "concurrently": "^6.0.0",
@@ -103,8 +110,10 @@
103
110
  "husky": "^1.3.1",
104
111
  "jsdoc-to-mdx": "^1.0.5",
105
112
  "karma-typescript-es6-transform": "^5.5.2",
113
+ "node-sass": "^7.0.1",
114
+ "npm-run-all": "^4.1.5",
106
115
  "postcss-clean": "^1.2.2",
107
- "postcss-cli": "^7.1.1",
116
+ "postcss-cli": "^7.1.2",
108
117
  "print-coveralls": "^1.2.2",
109
118
  "print-sizes": "0.0.3",
110
119
  "pvu": "^0.6.1",
@@ -0,0 +1,30 @@
1
+ .flicking-viewport
2
+ position: relative
3
+ overflow: hidden
4
+ &:not(.vertical)
5
+ width: 100%
6
+ height: 100%
7
+ &.vertical,
8
+ &.vertical>.flicking-camera
9
+ display: inline-block
10
+ &.vertical
11
+ &.middle>.flicking-camera>*
12
+ vertical-align: middle
13
+ &.bottom>.flicking-camera>*
14
+ vertical-align: bottom
15
+ >.flicking-camera>*
16
+ display: block
17
+ &.flicking-hidden>.flicking-camera>*
18
+ visibility: hidden
19
+
20
+ .flicking-camera
21
+ width: 100%
22
+ height: 100%
23
+ position: relative
24
+ z-index: 1
25
+ white-space: nowrap
26
+ will-change: transform
27
+ >*
28
+ display: inline-block
29
+ white-space: normal
30
+ vertical-align: top
@@ -0,0 +1,23 @@
1
+ .flicking-viewport
2
+ position: relative
3
+ overflow: hidden
4
+ &.vertical
5
+ display: inline-flex
6
+ >.flicking-camera
7
+ display: inline-flex
8
+ flex-direction: column
9
+ &.flicking-hidden
10
+ >.flicking-camera
11
+ >*
12
+ visibility: hidden
13
+
14
+ .flicking-camera
15
+ width: 100%
16
+ height: 100%
17
+ display: flex
18
+ position: relative
19
+ flex-direction: row
20
+ z-index: 1
21
+ will-change: transform
22
+ >*
23
+ flex-shrink: 0
package/src/Flicking.ts CHANGED
@@ -58,13 +58,16 @@ export interface FlickingOptions {
58
58
  panelsPerView: number;
59
59
  noPanelStyleOverride: boolean;
60
60
  resizeOnContentsReady: boolean;
61
+
61
62
  // EVENT
62
63
  needPanelThreshold: number;
63
64
  preventEventsBeforeInit: boolean;
65
+
64
66
  // ANIMATION
65
67
  deceleration: number;
66
68
  duration: number;
67
69
  easing: (x: number) => number;
70
+
68
71
  // INPUT
69
72
  inputType: string[];
70
73
  moveType: ValueOf<typeof MOVE_TYPE> | MoveTypeOptions<ValueOf<typeof MOVE_TYPE>>;
@@ -74,14 +77,19 @@ export interface FlickingOptions {
74
77
  iOSEdgeSwipeThreshold: number;
75
78
  preventClickOnDrag: boolean;
76
79
  disableOnInit: boolean;
80
+
77
81
  // PERFORMANCE
78
82
  renderOnlyVisible: boolean;
79
83
  virtual: VirtualOptions | null;
84
+
80
85
  // OTHERS
81
86
  autoInit: boolean;
82
87
  autoResize: boolean;
83
88
  useResizeObserver: boolean;
89
+ resizeDebounce: number;
90
+ maxResizeDebounce: number;
84
91
  externalRenderer: ExternalRenderer | null;
92
+
85
93
  // @deprecated
86
94
  renderExternal: {
87
95
  renderer: new (options: RendererOptions) => ExternalRenderer;
@@ -150,6 +158,8 @@ class Flicking extends Component<FlickingEvents> {
150
158
  private _autoInit: FlickingOptions["autoInit"];
151
159
  private _autoResize: FlickingOptions["autoResize"];
152
160
  private _useResizeObserver: FlickingOptions["useResizeObserver"];
161
+ private _resizeDebounce: FlickingOptions["resizeDebounce"];
162
+ private _maxResizeDebounce: FlickingOptions["maxResizeDebounce"];
153
163
  private _externalRenderer: FlickingOptions["externalRenderer"];
154
164
  private _renderExternal: FlickingOptions["renderExternal"];
155
165
 
@@ -613,6 +623,26 @@ class Flicking extends Component<FlickingEvents> {
613
623
  * @default true
614
624
  */
615
625
  public get useResizeObserver() { return this._useResizeObserver; }
626
+ /**
627
+ * Delays size recalculation from `autoResize` by the given time in milisecond.
628
+ * If the size is changed again while being delayed, it cancels the previous one and delays from the beginning again.
629
+ * This can increase performance by preventing `resize` being called too often.
630
+ * @ko `autoResize` 설정시에 호출되는 크기 재계산을 주어진 시간(단위: ms)만큼 지연시킵니다.
631
+ * 지연시키는 도중 크기가 다시 변경되었을 경우, 이전 것을 취소하고 주어진 시간만큼 다시 지연시킵니다.
632
+ * 이를 통해 `resize`가 너무 많이 호출되는 것을 방지하여 성능을 향상시킬 수 있습니다.
633
+ * @type {number}
634
+ * @default 0
635
+ */
636
+ public get resizeDebounce() { return this._resizeDebounce; }
637
+ /**
638
+ * The maximum time for size recalculation delay when using `resizeDebounce`, in milisecond.
639
+ * This guarantees that size recalculation is performed at least once every (n)ms.
640
+ * @ko `resizeDebounce` 사용시에 크기 재계산이 지연되는 최대 시간을 지정합니다. (단위: ms)
641
+ * 이를 통해, 적어도 (n)ms에 한번은 크기 재계산을 수행하는 것을 보장할 수 있습니다.
642
+ * @type {number}
643
+ * @default 100
644
+ */
645
+ public get maxResizeDebounce() { return this._maxResizeDebounce; }
616
646
  /**
617
647
  * This is an option for the frameworks(React, Vue, Angular, ...). Don't set it as it's automatically managed by Flicking.
618
648
  * @ko 프레임워크(React, Vue, Angular, ...)에서만 사용하는 옵션으로, 자동으로 설정되므로 따로 사용하실 필요 없습니다!
@@ -756,6 +786,8 @@ class Flicking extends Component<FlickingEvents> {
756
786
  autoInit = true,
757
787
  autoResize = true,
758
788
  useResizeObserver = true,
789
+ resizeDebounce = 0,
790
+ maxResizeDebounce = 100,
759
791
  externalRenderer = null,
760
792
  renderExternal = null
761
793
  }: Partial<FlickingOptions> = {}) {
@@ -794,6 +826,8 @@ class Flicking extends Component<FlickingEvents> {
794
826
  this._autoInit = autoInit;
795
827
  this._autoResize = autoResize;
796
828
  this._useResizeObserver = useResizeObserver;
829
+ this._resizeDebounce = resizeDebounce;
830
+ this._maxResizeDebounce = maxResizeDebounce;
797
831
  this._externalRenderer = externalRenderer;
798
832
  this._renderExternal = renderExternal;
799
833
 
@@ -816,10 +850,10 @@ class Flicking extends Component<FlickingEvents> {
816
850
  * @ko Flicking을 초기화하고, 디폴트 인덱스로 이동합니다
817
851
  * 이 메소드는 `autoInit` 옵션이 true(default)일 경우 Flicking이 생성될 때 자동으로 호출됩니다
818
852
  * @fires Flicking#ready
819
- * @return {this}
853
+ * @return {Promise<void>}
820
854
  */
821
- public async init(): Promise<void> {
822
- if (this._initialized) return;
855
+ public init(): Promise<void> {
856
+ if (this._initialized) return Promise.resolve();
823
857
 
824
858
  const camera = this._camera;
825
859
  const renderer = this._renderer;
@@ -828,7 +862,7 @@ class Flicking extends Component<FlickingEvents> {
828
862
  const originalTrigger = this.trigger;
829
863
  const preventEventsBeforeInit = this._preventEventsBeforeInit;
830
864
 
831
- camera.init(this);
865
+ camera.init();
832
866
  virtualManager.init();
833
867
  renderer.init(this);
834
868
  control.init(this);
@@ -837,10 +871,10 @@ class Flicking extends Component<FlickingEvents> {
837
871
  this.trigger = () => this;
838
872
  }
839
873
 
840
- await this.resize();
874
+ this._initialResize();
841
875
 
842
876
  // Look at initial panel
843
- await this._moveToInitialPanel();
877
+ this._moveToInitialPanel();
844
878
 
845
879
  if (this._autoResize) {
846
880
  this._autoResizer.enable();
@@ -853,16 +887,15 @@ class Flicking extends Component<FlickingEvents> {
853
887
  }
854
888
  renderer.checkPanelContentsReady(renderer.panels);
855
889
 
856
- this._plugins.forEach(plugin => plugin.init(this));
857
-
858
- // Done initializing & emit ready event
859
- this._initialized = true;
860
- if (preventEventsBeforeInit) {
861
- this.trigger = originalTrigger;
862
- }
863
- this.trigger(new ComponentEvent(EVENTS.READY));
864
-
865
- return;
890
+ return renderer.render().then(() => {
891
+ // Done initializing & emit ready event
892
+ this._plugins.forEach(plugin => plugin.init(this));
893
+ this._initialized = true;
894
+ if (preventEventsBeforeInit) {
895
+ this.trigger = originalTrigger;
896
+ }
897
+ this.trigger(new ComponentEvent(EVENTS.READY));
898
+ });
866
899
  }
867
900
 
868
901
  /**
@@ -1379,7 +1412,7 @@ class Flicking extends Component<FlickingEvents> {
1379
1412
  console.warn("\"circular\" and \"bound\" option cannot be used together, ignoring bound.");
1380
1413
  }
1381
1414
 
1382
- return new Camera({
1415
+ return new Camera(this, {
1383
1416
  align: this._align
1384
1417
  });
1385
1418
  }
@@ -1420,18 +1453,66 @@ class Flicking extends Component<FlickingEvents> {
1420
1453
  });
1421
1454
  }
1422
1455
 
1423
- private async _moveToInitialPanel(): Promise<void> {
1456
+ private _moveToInitialPanel(): void {
1424
1457
  const renderer = this._renderer;
1425
1458
  const control = this._control;
1459
+ const camera = this._camera;
1426
1460
  const initialPanel = renderer.getPanel(this._defaultIndex) || renderer.getPanel(0);
1427
1461
 
1428
1462
  if (!initialPanel) return;
1429
1463
 
1464
+ const nearestAnchor = camera.findNearestAnchor(initialPanel.position);
1430
1465
  control.setActive(initialPanel, null, false);
1431
1466
 
1432
- return control.moveToPanel(initialPanel, {
1433
- duration: 0
1434
- });
1467
+ if (!nearestAnchor) {
1468
+ throw new FlickingError(ERROR.MESSAGE.POSITION_NOT_REACHABLE(initialPanel.position), ERROR.CODE.POSITION_NOT_REACHABLE);
1469
+ }
1470
+
1471
+ let position = initialPanel.position;
1472
+
1473
+ if (!camera.canReach(initialPanel)) {
1474
+ position = nearestAnchor.position;
1475
+ }
1476
+
1477
+ camera.lookAt(position);
1478
+ control.updateInput();
1479
+ camera.updateOffset();
1480
+ }
1481
+
1482
+ private _initialResize() {
1483
+ const viewport = this._viewport;
1484
+ const renderer = this._renderer;
1485
+ const camera = this._camera;
1486
+ const control = this._control;
1487
+
1488
+ this.trigger(new ComponentEvent(EVENTS.BEFORE_RESIZE, {
1489
+ width: 0,
1490
+ height: 0,
1491
+ element: viewport.element
1492
+ }));
1493
+
1494
+ viewport.resize();
1495
+ renderer.updatePanelSize();
1496
+ camera.updateAlignPos();
1497
+ camera.updateRange();
1498
+ camera.updateAnchors();
1499
+ camera.updateOffset();
1500
+ control.updateInput();
1501
+
1502
+ const newWidth = viewport.width;
1503
+ const newHeight = viewport.height;
1504
+ const sizeChanged = newWidth !== 0 || newHeight !== 0;
1505
+
1506
+ this.trigger(new ComponentEvent(EVENTS.AFTER_RESIZE, {
1507
+ width: viewport.width,
1508
+ height: viewport.height,
1509
+ prev: {
1510
+ width: 0,
1511
+ height: 0
1512
+ },
1513
+ sizeChanged,
1514
+ element: viewport.element
1515
+ }));
1435
1516
  }
1436
1517
  }
1437
1518
 
@@ -27,7 +27,7 @@ class Camera {
27
27
  private _align: FlickingOptions["align"];
28
28
 
29
29
  // Internal states
30
- private _flicking: Flicking | null;
30
+ private _flicking: Flicking;
31
31
  private _mode: CameraMode;
32
32
  private _el: HTMLElement;
33
33
  private _transform: string;
@@ -231,10 +231,10 @@ class Camera {
231
231
  }
232
232
 
233
233
  /** */
234
- public constructor({
234
+ public constructor(flicking: Flicking, {
235
235
  align = ALIGN.CENTER
236
236
  }: Partial<CameraOptions> = {}) {
237
- this._flicking = null;
237
+ this._flicking = flicking;
238
238
  this._resetInternalValues();
239
239
 
240
240
  // Options
@@ -244,17 +244,13 @@ class Camera {
244
244
  /**
245
245
  * Initialize Camera
246
246
  * @ko Camera를 초기화합니다
247
- * @param {Flicking} flicking An instance of {@link Flicking}<ko>Flicking의 인스턴스</ko>
248
- * @chainable
249
247
  * @throws {FlickingError}
250
248
  * {@link ERROR_CODE VAL_MUST_NOT_NULL} If the camera element(`.flicking-camera`) does not exist inside viewport element
251
249
  * <ko>{@link ERROR_CODE VAL_MUST_NOT_NULL} 뷰포트 엘리먼트 내부에 카메라 엘리먼트(`.flicking-camera`)가 존재하지 않을 경우</ko>
252
250
  * @return {this}
253
251
  */
254
- public init(flicking: Flicking): this {
255
- this._flicking = flicking;
256
-
257
- const viewportEl = flicking.viewport.element;
252
+ public init(): this {
253
+ const viewportEl = this._flicking.viewport.element;
258
254
 
259
255
  checkExistence(viewportEl.firstElementChild, "First element child of the viewport element");
260
256
  this._el = viewportEl.firstElementChild as HTMLElement;
@@ -271,7 +267,6 @@ class Camera {
271
267
  * @return {void}
272
268
  */
273
269
  public destroy(): this {
274
- this._flicking = null;
275
270
  this._resetInternalValues();
276
271
  return this;
277
272
  }
@@ -294,12 +289,13 @@ class Camera {
294
289
  this._refreshVisiblePanels();
295
290
  this._checkNeedPanel();
296
291
  this._checkReachEnd(prevPos, pos);
297
- this.applyTransform();
298
292
 
299
293
  if (toggled) {
300
294
  void flicking.renderer.render().then(() => {
301
295
  this.updateOffset();
302
296
  });
297
+ } else {
298
+ this.applyTransform();
303
299
  }
304
300
  }
305
301
 
@@ -476,8 +472,6 @@ class Camera {
476
472
  panels.forEach(panel => panel.updateCircularToggleDirection());
477
473
  }
478
474
 
479
- this.updateOffset();
480
-
481
475
  return this;
482
476
  }
483
477
 
@@ -570,12 +564,14 @@ class Camera {
570
564
  /**
571
565
  * Apply "transform" style with the current position to camera element
572
566
  * @ko 현재 위치를 기준으로한 transform 스타일을 카메라 엘리먼트에 적용합니다.
573
- * @chainable
574
567
  * @return {this}
575
568
  */
576
569
  public applyTransform(): this {
577
570
  const el = this._el;
578
571
  const flicking = getFlickingAttached(this._flicking);
572
+ const renderer = flicking.renderer;
573
+
574
+ if (renderer.rendering) return this;
579
575
 
580
576
  const actualPosition = this._position - this._alignPos - this._offset + this._circularOffset;
581
577
 
package/src/cfc/sync.ts CHANGED
@@ -2,12 +2,16 @@ import { DiffResult } from "@egjs/list-differ";
2
2
 
3
3
  import Flicking from "../Flicking";
4
4
  import Renderer from "../renderer/Renderer";
5
+ import Panel from "../core/panel/Panel";
5
6
 
6
7
  export default (flicking: Flicking, diffResult: DiffResult<any>, rendered: any[]) => {
7
8
  const renderer = flicking.renderer;
8
9
  const panels = renderer.panels;
9
10
  const prevList = [...diffResult.prevList];
10
11
 
12
+ const added: Panel[] = [];
13
+ const removed: Panel[] = [];
14
+
11
15
  if (diffResult.removed.length > 0) {
12
16
  let endIdx = -1;
13
17
  let prevIdx = -1;
@@ -18,7 +22,7 @@ export default (flicking: Flicking, diffResult: DiffResult<any>, rendered: any[]
18
22
  }
19
23
 
20
24
  if (prevIdx >= 0 && removedIdx !== prevIdx - 1) {
21
- batchRemove(renderer, prevIdx, endIdx + 1);
25
+ removed.push(...batchRemove(renderer, prevIdx, endIdx + 1));
22
26
 
23
27
  endIdx = removedIdx;
24
28
  prevIdx = removedIdx;
@@ -29,30 +33,30 @@ export default (flicking: Flicking, diffResult: DiffResult<any>, rendered: any[]
29
33
  prevList.splice(removedIdx, 1);
30
34
  });
31
35
 
32
- batchRemove(renderer, prevIdx, endIdx + 1);
36
+ removed.push(...batchRemove(renderer, prevIdx, endIdx + 1));
33
37
  }
34
38
 
35
- diffResult.ordered.forEach(([prevIdx, newIdx]) => {
36
- const prevPanel = panels[prevIdx];
37
- const indexDiff = newIdx - prevIdx;
38
-
39
- if (indexDiff > 0) {
40
- const middlePanels = panels.slice(prevIdx + 1, newIdx + 1);
41
-
42
- prevPanel.increaseIndex(indexDiff);
43
- middlePanels.forEach(panel => panel.decreaseIndex(1));
44
- } else {
45
- const middlePanels = panels.slice(newIdx, prevIdx);
46
-
47
- prevPanel.decreaseIndex(-indexDiff);
48
- middlePanels.forEach(panel => panel.increaseIndex(1));
49
- }
50
- // Update position
51
- prevPanel.resize();
39
+ diffResult.ordered.forEach(([from, to]) => {
40
+ const prevPanel = panels.splice(from, 1)[0];
41
+ panels.splice(to, 0, prevPanel);
52
42
  });
53
43
 
54
44
  if (diffResult.ordered.length > 0) {
45
+ panels.forEach((panel, idx) => {
46
+ const indexDiff = idx - panel.index;
47
+
48
+ if (indexDiff > 0) {
49
+ panel.increaseIndex(indexDiff);
50
+ } else {
51
+ panel.decreaseIndex(-indexDiff);
52
+ }
53
+ });
54
+
55
55
  panels.sort((panel1, panel2) => panel1.index - panel2.index);
56
+
57
+ panels.forEach(panel => {
58
+ panel.updatePosition();
59
+ });
56
60
  }
57
61
 
58
62
  if (diffResult.added.length > 0) {
@@ -67,7 +71,7 @@ export default (flicking: Flicking, diffResult: DiffResult<any>, rendered: any[]
67
71
  }
68
72
 
69
73
  if (prevIdx >= 0 && addedIdx !== prevIdx + 1) {
70
- batchInsert(renderer, diffResult, addedElements, startIdx, idx + 1);
74
+ added.push(...batchInsert(renderer, diffResult, addedElements, startIdx, idx + 1));
71
75
 
72
76
  startIdx = -1;
73
77
  prevIdx = -1;
@@ -77,13 +81,15 @@ export default (flicking: Flicking, diffResult: DiffResult<any>, rendered: any[]
77
81
  });
78
82
 
79
83
  if (startIdx >= 0) {
80
- batchInsert(renderer, diffResult, addedElements, startIdx);
84
+ added.push(...batchInsert(renderer, diffResult, addedElements, startIdx));
81
85
  }
82
86
  }
87
+
88
+ renderer.updateAfterPanelChange(added, removed);
83
89
  };
84
90
 
85
91
  const batchInsert = (renderer: Renderer, diffResult: DiffResult<any>, addedElements: any[], startIdx: number, endIdx?: number) => {
86
- renderer.batchInsert(
92
+ return renderer.batchInsertDefer(
87
93
  ...diffResult.added.slice(startIdx, endIdx).map((index, elIdx) => ({ index, elements: [addedElements[elIdx]], hasDOMInElements: false }))
88
94
  );
89
95
  };
@@ -91,6 +97,6 @@ const batchInsert = (renderer: Renderer, diffResult: DiffResult<any>, addedEleme
91
97
  const batchRemove = (renderer: Renderer, startIdx: number, endIdx?: number) => {
92
98
  const removed = renderer.panels.slice(startIdx, endIdx);
93
99
 
94
- renderer.batchRemove({ index: startIdx, deleteCount: removed.length, hasDOMInElements: false });
100
+ return renderer.batchRemoveDefer({ index: startIdx, deleteCount: removed.length, hasDOMInElements: false });
95
101
  };
96
102
 
@@ -19,7 +19,7 @@ import Flicking from "../Flicking";
19
19
  */
20
20
  const withFlickingMethods = (prototype: any, flickingName: string) => {
21
21
  [Component.prototype, Flicking.prototype].forEach(proto => {
22
- Object.getOwnPropertyNames(proto).filter(name => !prototype[name] && !name.startsWith("_") && name !== "constructor")
22
+ Object.getOwnPropertyNames(proto).filter(name => !prototype[name] && name.indexOf("_") !== 0 && name !== "constructor")
23
23
  .forEach((name: string) => {
24
24
  const descriptor = Object.getOwnPropertyDescriptor(proto, name)!;
25
25
 
@@ -8,6 +8,8 @@ class AutoResizer {
8
8
  private _flicking: Flicking;
9
9
  private _enabled: boolean;
10
10
  private _resizeObserver: ResizeObserver | null;
11
+ private _resizeTimer: number;
12
+ private _maxResizeDebounceTimer: number;
11
13
 
12
14
  public get enabled() { return this._enabled; }
13
15
 
@@ -15,6 +17,8 @@ class AutoResizer {
15
17
  this._flicking = flicking;
16
18
  this._enabled = false;
17
19
  this._resizeObserver = null;
20
+ this._resizeTimer = -1;
21
+ this._maxResizeDebounceTimer = -1;
18
22
  }
19
23
 
20
24
  public enable(): this {
@@ -61,6 +65,35 @@ class AutoResizer {
61
65
  }
62
66
 
63
67
  private _onResize = () => {
68
+ const flicking = this._flicking;
69
+ const resizeDebounce = flicking.resizeDebounce;
70
+ const maxResizeDebounce = flicking.maxResizeDebounce;
71
+
72
+ if (resizeDebounce <= 0) {
73
+ void flicking.resize();
74
+ } else {
75
+ if (this._maxResizeDebounceTimer <= 0) {
76
+ if (maxResizeDebounce > 0 && maxResizeDebounce >= resizeDebounce) {
77
+ this._maxResizeDebounceTimer = window.setTimeout(this._doScheduledResize, maxResizeDebounce);
78
+ }
79
+ }
80
+
81
+ if (this._resizeTimer > 0) {
82
+ clearTimeout(this._resizeTimer);
83
+ this._resizeTimer = 0;
84
+ }
85
+
86
+ this._resizeTimer = window.setTimeout(this._doScheduledResize, resizeDebounce);
87
+ }
88
+ };
89
+
90
+ private _doScheduledResize = () => {
91
+ clearTimeout(this._resizeTimer);
92
+ clearTimeout(this._maxResizeDebounceTimer);
93
+
94
+ this._maxResizeDebounceTimer = -1;
95
+ this._resizeTimer = -1;
96
+
64
97
  void this._flicking.resize();
65
98
  };
66
99