@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.
package/dist/flicking.js CHANGED
@@ -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
  (function (global, factory) {
10
10
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@egjs/component'), require('@egjs/axes'), require('@egjs/imready')) :
@@ -1913,6 +1913,8 @@ version: 4.6.0
1913
1913
  };
1914
1914
 
1915
1915
  __proto.onRelease = function (ctx) {
1916
+ var _a;
1917
+
1916
1918
  var flicking = ctx.flicking,
1917
1919
  axesEvent = ctx.axesEvent,
1918
1920
  transitTo = ctx.transitTo; // Update last position to cope with Axes's animating behavior
@@ -1932,7 +1934,13 @@ version: 4.6.0
1932
1934
  var control = flicking.control;
1933
1935
  var position = axesEvent.destPos[POSITION_KEY];
1934
1936
  var duration = Math.max(axesEvent.duration, flicking.duration);
1935
- void control.moveToPosition(position, duration, axesEvent);
1937
+
1938
+ try {
1939
+ void control.moveToPosition(position, duration, axesEvent);
1940
+ } catch (err) {
1941
+ transitTo(STATE_TYPE.IDLE);
1942
+ axesEvent.setTo((_a = {}, _a[POSITION_KEY] = flicking.camera.position, _a), 0);
1943
+ }
1936
1944
  };
1937
1945
 
1938
1946
  return DraggingState;
@@ -2008,7 +2016,11 @@ version: 4.6.0
2008
2016
  direction: getDirection(animatingContext.start, animatingContext.end),
2009
2017
  axesEvent: axesEvent
2010
2018
  }));
2011
- control.setActive(this._targetPanel, control.activePanel, axesEvent.isTrusted);
2019
+ var targetPanel = this._targetPanel;
2020
+
2021
+ if (targetPanel) {
2022
+ control.setActive(targetPanel, control.activePanel, axesEvent.isTrusted);
2023
+ }
2012
2024
  };
2013
2025
 
2014
2026
  return AnimatingState;
@@ -2763,7 +2775,7 @@ version: 4.6.0
2763
2775
  */
2764
2776
 
2765
2777
 
2766
- __proto.updatePosition = function (_progressInPanel) {
2778
+ __proto.updatePosition = function (progressInPanel) {
2767
2779
  var flicking = getFlickingAttached(this._flicking);
2768
2780
  var camera = flicking.camera;
2769
2781
  var activePanel = this._activePanel;
@@ -3139,48 +3151,41 @@ version: 4.6.0
3139
3151
  */
3140
3152
 
3141
3153
  __proto.moveToPosition = function (position, duration, axesEvent) {
3142
- return __awaiter(this, void 0, void 0, function () {
3143
- var flicking, camera, activeAnchor, anchorAtCamera, state, snapThreshold, posDelta, absPosDelta, snapDelta, targetAnchor;
3144
- return __generator(this, function (_a) {
3145
- flicking = getFlickingAttached(this._flicking);
3146
- camera = flicking.camera;
3147
- activeAnchor = camera.findActiveAnchor();
3148
- anchorAtCamera = camera.findNearestAnchor(camera.position);
3149
- state = flicking.control.controller.state;
3154
+ var flicking = getFlickingAttached(this._flicking);
3155
+ var camera = flicking.camera;
3156
+ var activeAnchor = camera.findActiveAnchor();
3157
+ var anchorAtCamera = camera.findNearestAnchor(camera.position);
3158
+ var state = flicking.control.controller.state;
3150
3159
 
3151
- if (!activeAnchor || !anchorAtCamera) {
3152
- return [2
3153
- /*return*/
3154
- , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE))];
3155
- }
3160
+ if (!activeAnchor || !anchorAtCamera) {
3161
+ return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
3162
+ }
3156
3163
 
3157
- snapThreshold = this._calcSnapThreshold(position, activeAnchor);
3158
- posDelta = flicking.animating ? state.delta : position - camera.position;
3159
- absPosDelta = Math.abs(posDelta);
3160
- snapDelta = axesEvent && axesEvent.delta[POSITION_KEY] !== 0 ? Math.abs(axesEvent.delta[POSITION_KEY]) : absPosDelta;
3161
-
3162
- if (snapDelta >= snapThreshold && snapDelta > 0) {
3163
- // Move to anchor at position
3164
- targetAnchor = this._findSnappedAnchor(position, anchorAtCamera);
3165
- } else if (absPosDelta >= flicking.threshold && absPosDelta > 0) {
3166
- // Move to the adjacent panel
3167
- targetAnchor = this._findAdjacentAnchor(posDelta, anchorAtCamera);
3168
- } else {
3169
- // Restore to active panel
3170
- targetAnchor = anchorAtCamera;
3171
- }
3164
+ var snapThreshold = this._calcSnapThreshold(position, activeAnchor);
3172
3165
 
3173
- this._triggerIndexChangeEvent(targetAnchor.panel, position, axesEvent);
3166
+ var posDelta = flicking.animating ? state.delta : position - camera.position;
3167
+ var absPosDelta = Math.abs(posDelta);
3168
+ var snapDelta = axesEvent && axesEvent.delta[POSITION_KEY] !== 0 ? Math.abs(axesEvent.delta[POSITION_KEY]) : absPosDelta;
3169
+ var targetAnchor;
3174
3170
 
3175
- return [2
3176
- /*return*/
3177
- , this._animateToPosition({
3178
- position: camera.clampToReachablePosition(targetAnchor.position),
3179
- duration: duration,
3180
- newActivePanel: targetAnchor.panel,
3181
- axesEvent: axesEvent
3182
- })];
3183
- });
3171
+ if (snapDelta >= snapThreshold && snapDelta > 0) {
3172
+ // Move to anchor at position
3173
+ targetAnchor = this._findSnappedAnchor(position, anchorAtCamera);
3174
+ } else if (absPosDelta >= flicking.threshold && absPosDelta > 0) {
3175
+ // Move to the adjacent panel
3176
+ targetAnchor = this._findAdjacentAnchor(posDelta, anchorAtCamera);
3177
+ } else {
3178
+ // Restore to active panel
3179
+ targetAnchor = anchorAtCamera;
3180
+ }
3181
+
3182
+ this._triggerIndexChangeEvent(targetAnchor.panel, position, axesEvent);
3183
+
3184
+ return this._animateToPosition({
3185
+ position: camera.clampToReachablePosition(targetAnchor.position),
3186
+ duration: duration,
3187
+ newActivePanel: targetAnchor.panel,
3188
+ axesEvent: axesEvent
3184
3189
  });
3185
3190
  };
3186
3191
 
@@ -3369,35 +3374,26 @@ version: 4.6.0
3369
3374
 
3370
3375
 
3371
3376
  __proto.moveToPosition = function (position, duration, axesEvent) {
3372
- return __awaiter(this, void 0, void 0, function () {
3373
- var flicking, camera, targetPos, anchorAtPosition, targetPanel;
3374
- return __generator(this, function (_a) {
3375
- flicking = getFlickingAttached(this._flicking);
3376
- camera = flicking.camera;
3377
- targetPos = camera.clampToReachablePosition(position);
3378
- anchorAtPosition = camera.findAnchorIncludePosition(targetPos);
3377
+ var flicking = getFlickingAttached(this._flicking);
3378
+ var camera = flicking.camera;
3379
+ var targetPos = camera.clampToReachablePosition(position);
3380
+ var anchorAtPosition = camera.findAnchorIncludePosition(targetPos);
3379
3381
 
3380
- if (!anchorAtPosition) {
3381
- return [2
3382
- /*return*/
3383
- , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE))];
3384
- }
3382
+ if (!anchorAtPosition) {
3383
+ return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
3384
+ }
3385
3385
 
3386
- targetPanel = anchorAtPosition.panel; // Trigger only change event
3386
+ var targetPanel = anchorAtPosition.panel; // Trigger only change event
3387
3387
 
3388
- if (targetPanel !== this._activePanel) {
3389
- this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
3390
- }
3388
+ if (targetPanel !== this._activePanel) {
3389
+ this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
3390
+ }
3391
3391
 
3392
- return [2
3393
- /*return*/
3394
- , this._animateToPosition({
3395
- position: this._stopAtEdge ? targetPos : position,
3396
- duration: duration,
3397
- newActivePanel: targetPanel,
3398
- axesEvent: axesEvent
3399
- })];
3400
- });
3392
+ return this._animateToPosition({
3393
+ position: this._stopAtEdge ? targetPos : position,
3394
+ duration: duration,
3395
+ newActivePanel: targetPanel,
3396
+ axesEvent: axesEvent
3401
3397
  });
3402
3398
  };
3403
3399
 
@@ -3595,62 +3591,57 @@ version: 4.6.0
3595
3591
 
3596
3592
 
3597
3593
  __proto.moveToPosition = function (position, duration, axesEvent) {
3598
- return __awaiter(this, void 0, void 0, function () {
3599
- var flicking, camera, activePanel, axesRange, indexRange, cameraRange, clampedPosition, anchorAtPosition, prevPos, isOverThreshold, adjacentAnchor, targetPos, targetPanel, anchors, firstAnchor, lastAnchor, shouldBounceToFirst, shouldBounceToLast, targetAnchor;
3600
- return __generator(this, function (_a) {
3601
- flicking = getFlickingAttached(this._flicking);
3602
- camera = flicking.camera;
3603
- activePanel = this._activePanel;
3604
- axesRange = this._controller.range;
3605
- indexRange = this._indexRange;
3606
- cameraRange = camera.range;
3607
- clampedPosition = clamp(camera.clampToReachablePosition(position), axesRange[0], axesRange[1]);
3608
- anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
3609
-
3610
- if (!anchorAtPosition || !activePanel) {
3611
- return [2
3612
- /*return*/
3613
- , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE))];
3614
- }
3594
+ var flicking = getFlickingAttached(this._flicking);
3595
+ var camera = flicking.camera;
3596
+ var activePanel = this._activePanel;
3597
+ var axesRange = this._controller.range;
3598
+ var indexRange = this._indexRange;
3599
+ var cameraRange = camera.range;
3600
+ var clampedPosition = clamp(camera.clampToReachablePosition(position), axesRange[0], axesRange[1]);
3601
+ var anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
3615
3602
 
3616
- prevPos = activePanel.position;
3617
- isOverThreshold = Math.abs(position - prevPos) >= flicking.threshold;
3618
- adjacentAnchor = position > prevPos ? camera.getNextAnchor(anchorAtPosition) : camera.getPrevAnchor(anchorAtPosition);
3619
- anchors = camera.anchorPoints;
3620
- firstAnchor = anchors[0];
3621
- lastAnchor = anchors[anchors.length - 1];
3622
- shouldBounceToFirst = position <= cameraRange.min && isBetween(firstAnchor.panel.index, indexRange.min, indexRange.max);
3623
- shouldBounceToLast = position >= cameraRange.max && isBetween(lastAnchor.panel.index, indexRange.min, indexRange.max);
3624
-
3625
- if (shouldBounceToFirst || shouldBounceToLast) {
3626
- targetAnchor = position < cameraRange.min ? firstAnchor : lastAnchor;
3627
- targetPanel = targetAnchor.panel;
3628
- targetPos = targetAnchor.position;
3629
- } else if (isOverThreshold && anchorAtPosition.position !== activePanel.position) {
3630
- // Move to anchor at position
3631
- targetPanel = anchorAtPosition.panel;
3632
- targetPos = anchorAtPosition.position;
3633
- } else if (isOverThreshold && adjacentAnchor && isBetween(adjacentAnchor.index, indexRange.min, indexRange.max)) {
3634
- // Move to adjacent anchor
3635
- targetPanel = adjacentAnchor.panel;
3636
- targetPos = adjacentAnchor.position;
3637
- } else {
3638
- // Restore to active panel
3639
- targetPos = camera.clampToReachablePosition(activePanel.position);
3640
- targetPanel = activePanel;
3641
- }
3603
+ if (!anchorAtPosition || !activePanel) {
3604
+ return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
3605
+ }
3642
3606
 
3643
- this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
3607
+ var prevPos = activePanel.position;
3608
+ var isOverThreshold = Math.abs(position - prevPos) >= flicking.threshold;
3609
+ var adjacentAnchor = position > prevPos ? camera.getNextAnchor(anchorAtPosition) : camera.getPrevAnchor(anchorAtPosition);
3610
+ var targetPos;
3611
+ var targetPanel;
3612
+ var anchors = camera.anchorPoints;
3613
+ var firstAnchor = anchors[0];
3614
+ var lastAnchor = anchors[anchors.length - 1];
3615
+ var shouldBounceToFirst = position <= cameraRange.min && isBetween(firstAnchor.panel.index, indexRange.min, indexRange.max);
3616
+ var shouldBounceToLast = position >= cameraRange.max && isBetween(lastAnchor.panel.index, indexRange.min, indexRange.max);
3617
+ var isAdjacent = adjacentAnchor && (indexRange.min <= indexRange.max ? isBetween(adjacentAnchor.index, indexRange.min, indexRange.max) : adjacentAnchor.index >= indexRange.min || adjacentAnchor.index <= indexRange.max);
3618
+
3619
+ if (shouldBounceToFirst || shouldBounceToLast) {
3620
+ // In bounce area
3621
+ var targetAnchor = position < cameraRange.min ? firstAnchor : lastAnchor;
3622
+ targetPanel = targetAnchor.panel;
3623
+ targetPos = targetAnchor.position;
3624
+ } else if (isOverThreshold && anchorAtPosition.position !== activePanel.position) {
3625
+ // Move to anchor at position
3626
+ targetPanel = anchorAtPosition.panel;
3627
+ targetPos = anchorAtPosition.position;
3628
+ } else if (isOverThreshold && isAdjacent) {
3629
+ // Move to adjacent anchor
3630
+ targetPanel = adjacentAnchor.panel;
3631
+ targetPos = adjacentAnchor.position;
3632
+ } else {
3633
+ // Restore to active panel
3634
+ targetPos = camera.clampToReachablePosition(activePanel.position);
3635
+ targetPanel = activePanel;
3636
+ }
3644
3637
 
3645
- return [2
3646
- /*return*/
3647
- , this._animateToPosition({
3648
- position: targetPos,
3649
- duration: duration,
3650
- newActivePanel: targetPanel,
3651
- axesEvent: axesEvent
3652
- })];
3653
- });
3638
+ this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
3639
+
3640
+ return this._animateToPosition({
3641
+ position: targetPos,
3642
+ duration: duration,
3643
+ newActivePanel: targetPanel,
3644
+ axesEvent: axesEvent
3654
3645
  });
3655
3646
  };
3656
3647
 
@@ -3721,6 +3712,27 @@ version: 4.6.0
3721
3712
  }, null);
3722
3713
  };
3723
3714
 
3715
+ __proto.findNearestAnchor = function (position) {
3716
+ var anchors = this._flicking.camera.anchorPoints;
3717
+ if (anchors.length <= 0) return null;
3718
+ var prevDist = Infinity;
3719
+
3720
+ for (var anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
3721
+ var anchor = anchors[anchorIdx];
3722
+ var dist = Math.abs(anchor.position - position);
3723
+
3724
+ if (dist > prevDist) {
3725
+ // Return previous anchor
3726
+ return anchors[anchorIdx - 1];
3727
+ }
3728
+
3729
+ prevDist = dist;
3730
+ } // Return last anchor
3731
+
3732
+
3733
+ return anchors[anchors.length - 1];
3734
+ };
3735
+
3724
3736
  __proto.clampToReachablePosition = function (position) {
3725
3737
  var camera = this._flicking.camera;
3726
3738
  var range = camera.range;
@@ -3850,6 +3862,28 @@ version: 4.6.0
3850
3862
  });
3851
3863
  };
3852
3864
 
3865
+ __proto.findNearestAnchor = function (position) {
3866
+ var camera = this._flicking.camera;
3867
+ var anchors = camera.anchorPoints;
3868
+ if (anchors.length <= 0) return null;
3869
+ var camRange = camera.range;
3870
+ var minDist = Infinity;
3871
+ var minDistIndex = -1;
3872
+
3873
+ for (var anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
3874
+ var anchor = anchors[anchorIdx];
3875
+ 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));
3876
+
3877
+ if (dist < minDist) {
3878
+ minDist = dist;
3879
+ minDistIndex = anchorIdx;
3880
+ }
3881
+ } // Return last anchor
3882
+
3883
+
3884
+ return anchors[minDistIndex];
3885
+ };
3886
+
3853
3887
  __proto.findAnchorIncludePosition = function (position) {
3854
3888
  var camera = this._flicking.camera;
3855
3889
  var range = camera.range;
@@ -4618,24 +4652,7 @@ version: 4.6.0
4618
4652
 
4619
4653
 
4620
4654
  __proto.findNearestAnchor = function (position) {
4621
- var anchors = this._anchors;
4622
- if (anchors.length <= 0) return null;
4623
- var prevDist = Infinity;
4624
-
4625
- for (var anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
4626
- var anchor = anchors[anchorIdx];
4627
- var dist = Math.abs(anchor.position - position);
4628
-
4629
- if (dist > prevDist) {
4630
- // Return previous anchor
4631
- return anchors[anchorIdx - 1];
4632
- }
4633
-
4634
- prevDist = dist;
4635
- } // Return last anchor
4636
-
4637
-
4638
- return anchors[anchors.length - 1];
4655
+ return this._mode.findNearestAnchor(position);
4639
4656
  };
4640
4657
  /**
4641
4658
  * Return {@link AnchorPoint} that matches {@link Flicking#currentPanel}
@@ -5332,29 +5349,31 @@ version: 4.6.0
5332
5349
 
5333
5350
  void this.render();
5334
5351
 
5335
- if (!activePanel || activePanel.removed) {
5336
- if (panels.length <= 0) {
5337
- // All panels removed
5338
- camera.lookAt(0);
5339
- } else {
5340
- var targetIndex = (_a = activePanel === null || activePanel === void 0 ? void 0 : activePanel.index) !== null && _a !== void 0 ? _a : 0;
5352
+ if (!flicking.animating) {
5353
+ if (!activePanel || activePanel.removed) {
5354
+ if (panels.length <= 0) {
5355
+ // All panels removed
5356
+ camera.lookAt(0);
5357
+ } else {
5358
+ var targetIndex = (_a = activePanel === null || activePanel === void 0 ? void 0 : activePanel.index) !== null && _a !== void 0 ? _a : 0;
5341
5359
 
5342
- if (targetIndex > panels.length - 1) {
5343
- targetIndex = panels.length - 1;
5344
- }
5360
+ if (targetIndex > panels.length - 1) {
5361
+ targetIndex = panels.length - 1;
5362
+ }
5345
5363
 
5346
- void control.moveToPanel(panels[targetIndex], {
5364
+ void control.moveToPanel(panels[targetIndex], {
5365
+ duration: 0
5366
+ }).catch(function () {
5367
+ return void 0;
5368
+ });
5369
+ }
5370
+ } else {
5371
+ void control.moveToPanel(activePanel, {
5347
5372
  duration: 0
5348
5373
  }).catch(function () {
5349
5374
  return void 0;
5350
5375
  });
5351
5376
  }
5352
- } else {
5353
- void control.moveToPanel(control.activePanel, {
5354
- duration: 0
5355
- }).catch(function () {
5356
- return void 0;
5357
- });
5358
5377
  }
5359
5378
 
5360
5379
  flicking.camera.updateOffset();
@@ -8477,7 +8496,7 @@ version: 4.6.0
8477
8496
  */
8478
8497
 
8479
8498
 
8480
- Flicking.VERSION = "4.6.0";
8499
+ Flicking.VERSION = "4.6.3";
8481
8500
  return Flicking;
8482
8501
  }(Component);
8483
8502
 
@@ -8648,7 +8667,9 @@ version: 4.6.0
8648
8667
  }
8649
8668
  }
8650
8669
 
8651
- renderer.updateAfterPanelChange(added, removed);
8670
+ if (diffResult.added.length > 0 || diffResult.removed.length > 0) {
8671
+ renderer.updateAfterPanelChange(added, removed);
8672
+ }
8652
8673
  });
8653
8674
 
8654
8675
  var batchInsert = function (renderer, diffResult, addedElements, startIdx, endIdx) {