@egjs/flicking 4.6.0 → 4.6.3

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.
@@ -11,6 +11,7 @@ declare abstract class CameraMode {
11
11
  };
12
12
  getAnchors(): AnchorPoint[];
13
13
  findAnchorIncludePosition(position: number): AnchorPoint | null;
14
+ findNearestAnchor(position: number): AnchorPoint | null;
14
15
  clampToReachablePosition(position: number): number;
15
16
  getCircularOffset(): number;
16
17
  canReach(panel: Panel): boolean;
@@ -8,6 +8,7 @@ declare class CircularCameraMode extends CameraMode {
8
8
  max: number;
9
9
  };
10
10
  getAnchors(): AnchorPoint[];
11
+ findNearestAnchor(position: number): AnchorPoint | null;
11
12
  findAnchorIncludePosition(position: number): AnchorPoint | null;
12
13
  getCircularOffset(): number;
13
14
  clampToReachablePosition(position: number): number;
@@ -19,7 +19,7 @@ declare abstract class Control {
19
19
  destroy(): void;
20
20
  enable(): this;
21
21
  disable(): this;
22
- updatePosition(_progressInPanel: number): void;
22
+ updatePosition(progressInPanel: number): void;
23
23
  updateInput(): this;
24
24
  resetActive(): this;
25
25
  moveToPanel(panel: Panel, { duration, direction, axesEvent }: {
File without changes
@@ -4,7 +4,7 @@ name: @egjs/flicking
4
4
  license: MIT
5
5
  author: NAVER Corp.
6
6
  repository: https://github.com/naver/egjs-flicking
7
- version: 4.6.0
7
+ version: 4.6.3
8
8
  */
9
9
  import Component, { ComponentEvent } from '@egjs/component';
10
10
  import Axes, { PanInput } from '@egjs/axes';
@@ -1868,6 +1868,8 @@ function (_super) {
1868
1868
  };
1869
1869
 
1870
1870
  __proto.onRelease = function (ctx) {
1871
+ var _a;
1872
+
1871
1873
  var flicking = ctx.flicking,
1872
1874
  axesEvent = ctx.axesEvent,
1873
1875
  transitTo = ctx.transitTo; // Update last position to cope with Axes's animating behavior
@@ -1887,7 +1889,13 @@ function (_super) {
1887
1889
  var control = flicking.control;
1888
1890
  var position = axesEvent.destPos[POSITION_KEY];
1889
1891
  var duration = Math.max(axesEvent.duration, flicking.duration);
1890
- void control.moveToPosition(position, duration, axesEvent);
1892
+
1893
+ try {
1894
+ void control.moveToPosition(position, duration, axesEvent);
1895
+ } catch (err) {
1896
+ transitTo(STATE_TYPE.IDLE);
1897
+ axesEvent.setTo((_a = {}, _a[POSITION_KEY] = flicking.camera.position, _a), 0);
1898
+ }
1891
1899
  };
1892
1900
 
1893
1901
  return DraggingState;
@@ -1963,7 +1971,11 @@ function (_super) {
1963
1971
  direction: getDirection(animatingContext.start, animatingContext.end),
1964
1972
  axesEvent: axesEvent
1965
1973
  }));
1966
- control.setActive(this._targetPanel, control.activePanel, axesEvent.isTrusted);
1974
+ var targetPanel = this._targetPanel;
1975
+
1976
+ if (targetPanel) {
1977
+ control.setActive(targetPanel, control.activePanel, axesEvent.isTrusted);
1978
+ }
1967
1979
  };
1968
1980
 
1969
1981
  return AnimatingState;
@@ -2718,7 +2730,7 @@ function () {
2718
2730
  */
2719
2731
 
2720
2732
 
2721
- __proto.updatePosition = function (_progressInPanel) {
2733
+ __proto.updatePosition = function (progressInPanel) {
2722
2734
  var flicking = getFlickingAttached(this._flicking);
2723
2735
  var camera = flicking.camera;
2724
2736
  var activePanel = this._activePanel;
@@ -3094,48 +3106,41 @@ function (_super) {
3094
3106
  */
3095
3107
 
3096
3108
  __proto.moveToPosition = function (position, duration, axesEvent) {
3097
- return __awaiter(this, void 0, void 0, function () {
3098
- var flicking, camera, activeAnchor, anchorAtCamera, state, snapThreshold, posDelta, absPosDelta, snapDelta, targetAnchor;
3099
- return __generator(this, function (_a) {
3100
- flicking = getFlickingAttached(this._flicking);
3101
- camera = flicking.camera;
3102
- activeAnchor = camera.findActiveAnchor();
3103
- anchorAtCamera = camera.findNearestAnchor(camera.position);
3104
- state = flicking.control.controller.state;
3109
+ var flicking = getFlickingAttached(this._flicking);
3110
+ var camera = flicking.camera;
3111
+ var activeAnchor = camera.findActiveAnchor();
3112
+ var anchorAtCamera = camera.findNearestAnchor(camera.position);
3113
+ var state = flicking.control.controller.state;
3105
3114
 
3106
- if (!activeAnchor || !anchorAtCamera) {
3107
- return [2
3108
- /*return*/
3109
- , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE))];
3110
- }
3115
+ if (!activeAnchor || !anchorAtCamera) {
3116
+ return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
3117
+ }
3111
3118
 
3112
- snapThreshold = this._calcSnapThreshold(position, activeAnchor);
3113
- posDelta = flicking.animating ? state.delta : position - camera.position;
3114
- absPosDelta = Math.abs(posDelta);
3115
- snapDelta = axesEvent && axesEvent.delta[POSITION_KEY] !== 0 ? Math.abs(axesEvent.delta[POSITION_KEY]) : absPosDelta;
3116
-
3117
- if (snapDelta >= snapThreshold && snapDelta > 0) {
3118
- // Move to anchor at position
3119
- targetAnchor = this._findSnappedAnchor(position, anchorAtCamera);
3120
- } else if (absPosDelta >= flicking.threshold && absPosDelta > 0) {
3121
- // Move to the adjacent panel
3122
- targetAnchor = this._findAdjacentAnchor(posDelta, anchorAtCamera);
3123
- } else {
3124
- // Restore to active panel
3125
- targetAnchor = anchorAtCamera;
3126
- }
3119
+ var snapThreshold = this._calcSnapThreshold(position, activeAnchor);
3127
3120
 
3128
- this._triggerIndexChangeEvent(targetAnchor.panel, position, axesEvent);
3121
+ var posDelta = flicking.animating ? state.delta : position - camera.position;
3122
+ var absPosDelta = Math.abs(posDelta);
3123
+ var snapDelta = axesEvent && axesEvent.delta[POSITION_KEY] !== 0 ? Math.abs(axesEvent.delta[POSITION_KEY]) : absPosDelta;
3124
+ var targetAnchor;
3129
3125
 
3130
- return [2
3131
- /*return*/
3132
- , this._animateToPosition({
3133
- position: camera.clampToReachablePosition(targetAnchor.position),
3134
- duration: duration,
3135
- newActivePanel: targetAnchor.panel,
3136
- axesEvent: axesEvent
3137
- })];
3138
- });
3126
+ if (snapDelta >= snapThreshold && snapDelta > 0) {
3127
+ // Move to anchor at position
3128
+ targetAnchor = this._findSnappedAnchor(position, anchorAtCamera);
3129
+ } else if (absPosDelta >= flicking.threshold && absPosDelta > 0) {
3130
+ // Move to the adjacent panel
3131
+ targetAnchor = this._findAdjacentAnchor(posDelta, anchorAtCamera);
3132
+ } else {
3133
+ // Restore to active panel
3134
+ targetAnchor = anchorAtCamera;
3135
+ }
3136
+
3137
+ this._triggerIndexChangeEvent(targetAnchor.panel, position, axesEvent);
3138
+
3139
+ return this._animateToPosition({
3140
+ position: camera.clampToReachablePosition(targetAnchor.position),
3141
+ duration: duration,
3142
+ newActivePanel: targetAnchor.panel,
3143
+ axesEvent: axesEvent
3139
3144
  });
3140
3145
  };
3141
3146
 
@@ -3324,35 +3329,26 @@ function (_super) {
3324
3329
 
3325
3330
 
3326
3331
  __proto.moveToPosition = function (position, duration, axesEvent) {
3327
- return __awaiter(this, void 0, void 0, function () {
3328
- var flicking, camera, targetPos, anchorAtPosition, targetPanel;
3329
- return __generator(this, function (_a) {
3330
- flicking = getFlickingAttached(this._flicking);
3331
- camera = flicking.camera;
3332
- targetPos = camera.clampToReachablePosition(position);
3333
- anchorAtPosition = camera.findAnchorIncludePosition(targetPos);
3332
+ var flicking = getFlickingAttached(this._flicking);
3333
+ var camera = flicking.camera;
3334
+ var targetPos = camera.clampToReachablePosition(position);
3335
+ var anchorAtPosition = camera.findAnchorIncludePosition(targetPos);
3334
3336
 
3335
- if (!anchorAtPosition) {
3336
- return [2
3337
- /*return*/
3338
- , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE))];
3339
- }
3337
+ if (!anchorAtPosition) {
3338
+ return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
3339
+ }
3340
3340
 
3341
- targetPanel = anchorAtPosition.panel; // Trigger only change event
3341
+ var targetPanel = anchorAtPosition.panel; // Trigger only change event
3342
3342
 
3343
- if (targetPanel !== this._activePanel) {
3344
- this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
3345
- }
3343
+ if (targetPanel !== this._activePanel) {
3344
+ this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
3345
+ }
3346
3346
 
3347
- return [2
3348
- /*return*/
3349
- , this._animateToPosition({
3350
- position: this._stopAtEdge ? targetPos : position,
3351
- duration: duration,
3352
- newActivePanel: targetPanel,
3353
- axesEvent: axesEvent
3354
- })];
3355
- });
3347
+ return this._animateToPosition({
3348
+ position: this._stopAtEdge ? targetPos : position,
3349
+ duration: duration,
3350
+ newActivePanel: targetPanel,
3351
+ axesEvent: axesEvent
3356
3352
  });
3357
3353
  };
3358
3354
 
@@ -3550,62 +3546,57 @@ function (_super) {
3550
3546
 
3551
3547
 
3552
3548
  __proto.moveToPosition = function (position, duration, axesEvent) {
3553
- return __awaiter(this, void 0, void 0, function () {
3554
- var flicking, camera, activePanel, axesRange, indexRange, cameraRange, clampedPosition, anchorAtPosition, prevPos, isOverThreshold, adjacentAnchor, targetPos, targetPanel, anchors, firstAnchor, lastAnchor, shouldBounceToFirst, shouldBounceToLast, targetAnchor;
3555
- return __generator(this, function (_a) {
3556
- flicking = getFlickingAttached(this._flicking);
3557
- camera = flicking.camera;
3558
- activePanel = this._activePanel;
3559
- axesRange = this._controller.range;
3560
- indexRange = this._indexRange;
3561
- cameraRange = camera.range;
3562
- clampedPosition = clamp(camera.clampToReachablePosition(position), axesRange[0], axesRange[1]);
3563
- anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
3564
-
3565
- if (!anchorAtPosition || !activePanel) {
3566
- return [2
3567
- /*return*/
3568
- , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE))];
3569
- }
3549
+ var flicking = getFlickingAttached(this._flicking);
3550
+ var camera = flicking.camera;
3551
+ var activePanel = this._activePanel;
3552
+ var axesRange = this._controller.range;
3553
+ var indexRange = this._indexRange;
3554
+ var cameraRange = camera.range;
3555
+ var clampedPosition = clamp(camera.clampToReachablePosition(position), axesRange[0], axesRange[1]);
3556
+ var anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
3570
3557
 
3571
- prevPos = activePanel.position;
3572
- isOverThreshold = Math.abs(position - prevPos) >= flicking.threshold;
3573
- adjacentAnchor = position > prevPos ? camera.getNextAnchor(anchorAtPosition) : camera.getPrevAnchor(anchorAtPosition);
3574
- anchors = camera.anchorPoints;
3575
- firstAnchor = anchors[0];
3576
- lastAnchor = anchors[anchors.length - 1];
3577
- shouldBounceToFirst = position <= cameraRange.min && isBetween(firstAnchor.panel.index, indexRange.min, indexRange.max);
3578
- shouldBounceToLast = position >= cameraRange.max && isBetween(lastAnchor.panel.index, indexRange.min, indexRange.max);
3579
-
3580
- if (shouldBounceToFirst || shouldBounceToLast) {
3581
- targetAnchor = position < cameraRange.min ? firstAnchor : lastAnchor;
3582
- targetPanel = targetAnchor.panel;
3583
- targetPos = targetAnchor.position;
3584
- } else if (isOverThreshold && anchorAtPosition.position !== activePanel.position) {
3585
- // Move to anchor at position
3586
- targetPanel = anchorAtPosition.panel;
3587
- targetPos = anchorAtPosition.position;
3588
- } else if (isOverThreshold && adjacentAnchor && isBetween(adjacentAnchor.index, indexRange.min, indexRange.max)) {
3589
- // Move to adjacent anchor
3590
- targetPanel = adjacentAnchor.panel;
3591
- targetPos = adjacentAnchor.position;
3592
- } else {
3593
- // Restore to active panel
3594
- targetPos = camera.clampToReachablePosition(activePanel.position);
3595
- targetPanel = activePanel;
3596
- }
3558
+ if (!anchorAtPosition || !activePanel) {
3559
+ return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
3560
+ }
3597
3561
 
3598
- this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
3562
+ var prevPos = activePanel.position;
3563
+ var isOverThreshold = Math.abs(position - prevPos) >= flicking.threshold;
3564
+ var adjacentAnchor = position > prevPos ? camera.getNextAnchor(anchorAtPosition) : camera.getPrevAnchor(anchorAtPosition);
3565
+ var targetPos;
3566
+ var targetPanel;
3567
+ var anchors = camera.anchorPoints;
3568
+ var firstAnchor = anchors[0];
3569
+ var lastAnchor = anchors[anchors.length - 1];
3570
+ var shouldBounceToFirst = position <= cameraRange.min && isBetween(firstAnchor.panel.index, indexRange.min, indexRange.max);
3571
+ var shouldBounceToLast = position >= cameraRange.max && isBetween(lastAnchor.panel.index, indexRange.min, indexRange.max);
3572
+ var isAdjacent = adjacentAnchor && (indexRange.min <= indexRange.max ? isBetween(adjacentAnchor.index, indexRange.min, indexRange.max) : adjacentAnchor.index >= indexRange.min || adjacentAnchor.index <= indexRange.max);
3573
+
3574
+ if (shouldBounceToFirst || shouldBounceToLast) {
3575
+ // In bounce area
3576
+ var targetAnchor = position < cameraRange.min ? firstAnchor : lastAnchor;
3577
+ targetPanel = targetAnchor.panel;
3578
+ targetPos = targetAnchor.position;
3579
+ } else if (isOverThreshold && anchorAtPosition.position !== activePanel.position) {
3580
+ // Move to anchor at position
3581
+ targetPanel = anchorAtPosition.panel;
3582
+ targetPos = anchorAtPosition.position;
3583
+ } else if (isOverThreshold && isAdjacent) {
3584
+ // Move to adjacent anchor
3585
+ targetPanel = adjacentAnchor.panel;
3586
+ targetPos = adjacentAnchor.position;
3587
+ } else {
3588
+ // Restore to active panel
3589
+ targetPos = camera.clampToReachablePosition(activePanel.position);
3590
+ targetPanel = activePanel;
3591
+ }
3599
3592
 
3600
- return [2
3601
- /*return*/
3602
- , this._animateToPosition({
3603
- position: targetPos,
3604
- duration: duration,
3605
- newActivePanel: targetPanel,
3606
- axesEvent: axesEvent
3607
- })];
3608
- });
3593
+ this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
3594
+
3595
+ return this._animateToPosition({
3596
+ position: targetPos,
3597
+ duration: duration,
3598
+ newActivePanel: targetPanel,
3599
+ axesEvent: axesEvent
3609
3600
  });
3610
3601
  };
3611
3602
 
@@ -3655,6 +3646,27 @@ function () {
3655
3646
  }, null);
3656
3647
  };
3657
3648
 
3649
+ __proto.findNearestAnchor = function (position) {
3650
+ var anchors = this._flicking.camera.anchorPoints;
3651
+ if (anchors.length <= 0) return null;
3652
+ var prevDist = Infinity;
3653
+
3654
+ for (var anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
3655
+ var anchor = anchors[anchorIdx];
3656
+ var dist = Math.abs(anchor.position - position);
3657
+
3658
+ if (dist > prevDist) {
3659
+ // Return previous anchor
3660
+ return anchors[anchorIdx - 1];
3661
+ }
3662
+
3663
+ prevDist = dist;
3664
+ } // Return last anchor
3665
+
3666
+
3667
+ return anchors[anchors.length - 1];
3668
+ };
3669
+
3658
3670
  __proto.clampToReachablePosition = function (position) {
3659
3671
  var camera = this._flicking.camera;
3660
3672
  var range = camera.range;
@@ -3784,6 +3796,28 @@ function (_super) {
3784
3796
  });
3785
3797
  };
3786
3798
 
3799
+ __proto.findNearestAnchor = function (position) {
3800
+ var camera = this._flicking.camera;
3801
+ var anchors = camera.anchorPoints;
3802
+ if (anchors.length <= 0) return null;
3803
+ var camRange = camera.range;
3804
+ var minDist = Infinity;
3805
+ var minDistIndex = -1;
3806
+
3807
+ for (var anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
3808
+ var anchor = anchors[anchorIdx];
3809
+ var dist = Math.min(Math.abs(anchor.position - position), Math.abs(anchor.position - camRange.min + camRange.max - position), Math.abs(position - camRange.min + camRange.max - anchor.position));
3810
+
3811
+ if (dist < minDist) {
3812
+ minDist = dist;
3813
+ minDistIndex = anchorIdx;
3814
+ }
3815
+ } // Return last anchor
3816
+
3817
+
3818
+ return anchors[minDistIndex];
3819
+ };
3820
+
3787
3821
  __proto.findAnchorIncludePosition = function (position) {
3788
3822
  var camera = this._flicking.camera;
3789
3823
  var range = camera.range;
@@ -4552,24 +4586,7 @@ function () {
4552
4586
 
4553
4587
 
4554
4588
  __proto.findNearestAnchor = function (position) {
4555
- var anchors = this._anchors;
4556
- if (anchors.length <= 0) return null;
4557
- var prevDist = Infinity;
4558
-
4559
- for (var anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
4560
- var anchor = anchors[anchorIdx];
4561
- var dist = Math.abs(anchor.position - position);
4562
-
4563
- if (dist > prevDist) {
4564
- // Return previous anchor
4565
- return anchors[anchorIdx - 1];
4566
- }
4567
-
4568
- prevDist = dist;
4569
- } // Return last anchor
4570
-
4571
-
4572
- return anchors[anchors.length - 1];
4589
+ return this._mode.findNearestAnchor(position);
4573
4590
  };
4574
4591
  /**
4575
4592
  * Return {@link AnchorPoint} that matches {@link Flicking#currentPanel}
@@ -5253,29 +5270,31 @@ function () {
5253
5270
 
5254
5271
  void this.render();
5255
5272
 
5256
- if (!activePanel || activePanel.removed) {
5257
- if (panels.length <= 0) {
5258
- // All panels removed
5259
- camera.lookAt(0);
5260
- } else {
5261
- var targetIndex = (_a = activePanel === null || activePanel === void 0 ? void 0 : activePanel.index) !== null && _a !== void 0 ? _a : 0;
5273
+ if (!flicking.animating) {
5274
+ if (!activePanel || activePanel.removed) {
5275
+ if (panels.length <= 0) {
5276
+ // All panels removed
5277
+ camera.lookAt(0);
5278
+ } else {
5279
+ var targetIndex = (_a = activePanel === null || activePanel === void 0 ? void 0 : activePanel.index) !== null && _a !== void 0 ? _a : 0;
5262
5280
 
5263
- if (targetIndex > panels.length - 1) {
5264
- targetIndex = panels.length - 1;
5265
- }
5281
+ if (targetIndex > panels.length - 1) {
5282
+ targetIndex = panels.length - 1;
5283
+ }
5266
5284
 
5267
- void control.moveToPanel(panels[targetIndex], {
5285
+ void control.moveToPanel(panels[targetIndex], {
5286
+ duration: 0
5287
+ }).catch(function () {
5288
+ return void 0;
5289
+ });
5290
+ }
5291
+ } else {
5292
+ void control.moveToPanel(activePanel, {
5268
5293
  duration: 0
5269
5294
  }).catch(function () {
5270
5295
  return void 0;
5271
5296
  });
5272
5297
  }
5273
- } else {
5274
- void control.moveToPanel(control.activePanel, {
5275
- duration: 0
5276
- }).catch(function () {
5277
- return void 0;
5278
- });
5279
5298
  }
5280
5299
 
5281
5300
  flicking.camera.updateOffset();
@@ -8384,7 +8403,7 @@ function (_super) {
8384
8403
  */
8385
8404
 
8386
8405
 
8387
- Flicking.VERSION = "4.6.0";
8406
+ Flicking.VERSION = "4.6.3";
8388
8407
  return Flicking;
8389
8408
  }(Component);
8390
8409
 
@@ -8538,7 +8557,9 @@ var sync = (function (flicking, diffResult, rendered) {
8538
8557
  }
8539
8558
  }
8540
8559
 
8541
- renderer.updateAfterPanelChange(added, removed);
8560
+ if (diffResult.added.length > 0 || diffResult.removed.length > 0) {
8561
+ renderer.updateAfterPanelChange(added, removed);
8562
+ }
8542
8563
  });
8543
8564
 
8544
8565
  var batchInsert = function (renderer, diffResult, addedElements, startIdx, endIdx) {