@egjs/flicking 4.6.1 → 4.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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.1
7
+ version: 4.6.2
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.1
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.1
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.1
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.1
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.1
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.1
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,56 @@ version: 4.6.1
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
+ }
3606
+
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
+
3618
+ if (shouldBounceToFirst || shouldBounceToLast) {
3619
+ // In bounce area
3620
+ var targetAnchor = position < cameraRange.min ? firstAnchor : lastAnchor;
3621
+ targetPanel = targetAnchor.panel;
3622
+ targetPos = targetAnchor.position;
3623
+ } else if (isOverThreshold && anchorAtPosition.position !== activePanel.position) {
3624
+ // Move to anchor at position
3625
+ targetPanel = anchorAtPosition.panel;
3626
+ targetPos = anchorAtPosition.position;
3627
+ } else if (isOverThreshold && adjacentAnchor && isBetween(adjacentAnchor.index, indexRange.min, indexRange.max)) {
3628
+ // Move to adjacent anchor
3629
+ targetPanel = adjacentAnchor.panel;
3630
+ targetPos = adjacentAnchor.position;
3631
+ } else {
3632
+ // Restore to active panel
3633
+ targetPos = camera.clampToReachablePosition(activePanel.position);
3634
+ targetPanel = activePanel;
3635
+ }
3642
3636
 
3643
- this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
3637
+ this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
3644
3638
 
3645
- return [2
3646
- /*return*/
3647
- , this._animateToPosition({
3648
- position: targetPos,
3649
- duration: duration,
3650
- newActivePanel: targetPanel,
3651
- axesEvent: axesEvent
3652
- })];
3653
- });
3639
+ return this._animateToPosition({
3640
+ position: targetPos,
3641
+ duration: duration,
3642
+ newActivePanel: targetPanel,
3643
+ axesEvent: axesEvent
3654
3644
  });
3655
3645
  };
3656
3646
 
@@ -5332,29 +5322,31 @@ version: 4.6.1
5332
5322
 
5333
5323
  void this.render();
5334
5324
 
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;
5325
+ if (!flicking.animating) {
5326
+ if (!activePanel || activePanel.removed) {
5327
+ if (panels.length <= 0) {
5328
+ // All panels removed
5329
+ camera.lookAt(0);
5330
+ } else {
5331
+ var targetIndex = (_a = activePanel === null || activePanel === void 0 ? void 0 : activePanel.index) !== null && _a !== void 0 ? _a : 0;
5341
5332
 
5342
- if (targetIndex > panels.length - 1) {
5343
- targetIndex = panels.length - 1;
5344
- }
5333
+ if (targetIndex > panels.length - 1) {
5334
+ targetIndex = panels.length - 1;
5335
+ }
5345
5336
 
5346
- void control.moveToPanel(panels[targetIndex], {
5337
+ void control.moveToPanel(panels[targetIndex], {
5338
+ duration: 0
5339
+ }).catch(function () {
5340
+ return void 0;
5341
+ });
5342
+ }
5343
+ } else {
5344
+ void control.moveToPanel(activePanel, {
5347
5345
  duration: 0
5348
5346
  }).catch(function () {
5349
5347
  return void 0;
5350
5348
  });
5351
5349
  }
5352
- } else {
5353
- void control.moveToPanel(control.activePanel, {
5354
- duration: 0
5355
- }).catch(function () {
5356
- return void 0;
5357
- });
5358
5350
  }
5359
5351
 
5360
5352
  flicking.camera.updateOffset();
@@ -8477,7 +8469,7 @@ version: 4.6.1
8477
8469
  */
8478
8470
 
8479
8471
 
8480
- Flicking.VERSION = "4.6.1";
8472
+ Flicking.VERSION = "4.6.2";
8481
8473
  return Flicking;
8482
8474
  }(Component);
8483
8475
 
@@ -8648,7 +8640,9 @@ version: 4.6.1
8648
8640
  }
8649
8641
  }
8650
8642
 
8651
- renderer.updateAfterPanelChange(added, removed);
8643
+ if (diffResult.added.length > 0 || diffResult.removed.length > 0) {
8644
+ renderer.updateAfterPanelChange(added, removed);
8645
+ }
8652
8646
  });
8653
8647
 
8654
8648
  var batchInsert = function (renderer, diffResult, addedElements, startIdx, endIdx) {