@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.
@@ -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() :
@@ -8325,6 +8325,8 @@ version: 4.6.0
8325
8325
  };
8326
8326
 
8327
8327
  __proto.onRelease = function (ctx) {
8328
+ var _a;
8329
+
8328
8330
  var flicking = ctx.flicking,
8329
8331
  axesEvent = ctx.axesEvent,
8330
8332
  transitTo = ctx.transitTo; // Update last position to cope with Axes's animating behavior
@@ -8344,7 +8346,13 @@ version: 4.6.0
8344
8346
  var control = flicking.control;
8345
8347
  var position = axesEvent.destPos[POSITION_KEY];
8346
8348
  var duration = Math.max(axesEvent.duration, flicking.duration);
8347
- void control.moveToPosition(position, duration, axesEvent);
8349
+
8350
+ try {
8351
+ void control.moveToPosition(position, duration, axesEvent);
8352
+ } catch (err) {
8353
+ transitTo(STATE_TYPE.IDLE);
8354
+ axesEvent.setTo((_a = {}, _a[POSITION_KEY] = flicking.camera.position, _a), 0);
8355
+ }
8348
8356
  };
8349
8357
 
8350
8358
  return DraggingState;
@@ -8420,7 +8428,11 @@ version: 4.6.0
8420
8428
  direction: getDirection$1(animatingContext.start, animatingContext.end),
8421
8429
  axesEvent: axesEvent
8422
8430
  }));
8423
- control.setActive(this._targetPanel, control.activePanel, axesEvent.isTrusted);
8431
+ var targetPanel = this._targetPanel;
8432
+
8433
+ if (targetPanel) {
8434
+ control.setActive(targetPanel, control.activePanel, axesEvent.isTrusted);
8435
+ }
8424
8436
  };
8425
8437
 
8426
8438
  return AnimatingState;
@@ -9175,7 +9187,7 @@ version: 4.6.0
9175
9187
  */
9176
9188
 
9177
9189
 
9178
- __proto.updatePosition = function (_progressInPanel) {
9190
+ __proto.updatePosition = function (progressInPanel) {
9179
9191
  var flicking = getFlickingAttached(this._flicking);
9180
9192
  var camera = flicking.camera;
9181
9193
  var activePanel = this._activePanel;
@@ -9551,48 +9563,41 @@ version: 4.6.0
9551
9563
  */
9552
9564
 
9553
9565
  __proto.moveToPosition = function (position, duration, axesEvent) {
9554
- return __awaiter(this, void 0, void 0, function () {
9555
- var flicking, camera, activeAnchor, anchorAtCamera, state, snapThreshold, posDelta, absPosDelta, snapDelta, targetAnchor;
9556
- return __generator(this, function (_a) {
9557
- flicking = getFlickingAttached(this._flicking);
9558
- camera = flicking.camera;
9559
- activeAnchor = camera.findActiveAnchor();
9560
- anchorAtCamera = camera.findNearestAnchor(camera.position);
9561
- state = flicking.control.controller.state;
9566
+ var flicking = getFlickingAttached(this._flicking);
9567
+ var camera = flicking.camera;
9568
+ var activeAnchor = camera.findActiveAnchor();
9569
+ var anchorAtCamera = camera.findNearestAnchor(camera.position);
9570
+ var state = flicking.control.controller.state;
9562
9571
 
9563
- if (!activeAnchor || !anchorAtCamera) {
9564
- return [2
9565
- /*return*/
9566
- , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE))];
9567
- }
9572
+ if (!activeAnchor || !anchorAtCamera) {
9573
+ return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
9574
+ }
9568
9575
 
9569
- snapThreshold = this._calcSnapThreshold(position, activeAnchor);
9570
- posDelta = flicking.animating ? state.delta : position - camera.position;
9571
- absPosDelta = Math.abs(posDelta);
9572
- snapDelta = axesEvent && axesEvent.delta[POSITION_KEY] !== 0 ? Math.abs(axesEvent.delta[POSITION_KEY]) : absPosDelta;
9573
-
9574
- if (snapDelta >= snapThreshold && snapDelta > 0) {
9575
- // Move to anchor at position
9576
- targetAnchor = this._findSnappedAnchor(position, anchorAtCamera);
9577
- } else if (absPosDelta >= flicking.threshold && absPosDelta > 0) {
9578
- // Move to the adjacent panel
9579
- targetAnchor = this._findAdjacentAnchor(posDelta, anchorAtCamera);
9580
- } else {
9581
- // Restore to active panel
9582
- targetAnchor = anchorAtCamera;
9583
- }
9576
+ var snapThreshold = this._calcSnapThreshold(position, activeAnchor);
9584
9577
 
9585
- this._triggerIndexChangeEvent(targetAnchor.panel, position, axesEvent);
9578
+ var posDelta = flicking.animating ? state.delta : position - camera.position;
9579
+ var absPosDelta = Math.abs(posDelta);
9580
+ var snapDelta = axesEvent && axesEvent.delta[POSITION_KEY] !== 0 ? Math.abs(axesEvent.delta[POSITION_KEY]) : absPosDelta;
9581
+ var targetAnchor;
9586
9582
 
9587
- return [2
9588
- /*return*/
9589
- , this._animateToPosition({
9590
- position: camera.clampToReachablePosition(targetAnchor.position),
9591
- duration: duration,
9592
- newActivePanel: targetAnchor.panel,
9593
- axesEvent: axesEvent
9594
- })];
9595
- });
9583
+ if (snapDelta >= snapThreshold && snapDelta > 0) {
9584
+ // Move to anchor at position
9585
+ targetAnchor = this._findSnappedAnchor(position, anchorAtCamera);
9586
+ } else if (absPosDelta >= flicking.threshold && absPosDelta > 0) {
9587
+ // Move to the adjacent panel
9588
+ targetAnchor = this._findAdjacentAnchor(posDelta, anchorAtCamera);
9589
+ } else {
9590
+ // Restore to active panel
9591
+ targetAnchor = anchorAtCamera;
9592
+ }
9593
+
9594
+ this._triggerIndexChangeEvent(targetAnchor.panel, position, axesEvent);
9595
+
9596
+ return this._animateToPosition({
9597
+ position: camera.clampToReachablePosition(targetAnchor.position),
9598
+ duration: duration,
9599
+ newActivePanel: targetAnchor.panel,
9600
+ axesEvent: axesEvent
9596
9601
  });
9597
9602
  };
9598
9603
 
@@ -9781,35 +9786,26 @@ version: 4.6.0
9781
9786
 
9782
9787
 
9783
9788
  __proto.moveToPosition = function (position, duration, axesEvent) {
9784
- return __awaiter(this, void 0, void 0, function () {
9785
- var flicking, camera, targetPos, anchorAtPosition, targetPanel;
9786
- return __generator(this, function (_a) {
9787
- flicking = getFlickingAttached(this._flicking);
9788
- camera = flicking.camera;
9789
- targetPos = camera.clampToReachablePosition(position);
9790
- anchorAtPosition = camera.findAnchorIncludePosition(targetPos);
9789
+ var flicking = getFlickingAttached(this._flicking);
9790
+ var camera = flicking.camera;
9791
+ var targetPos = camera.clampToReachablePosition(position);
9792
+ var anchorAtPosition = camera.findAnchorIncludePosition(targetPos);
9791
9793
 
9792
- if (!anchorAtPosition) {
9793
- return [2
9794
- /*return*/
9795
- , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE))];
9796
- }
9794
+ if (!anchorAtPosition) {
9795
+ return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
9796
+ }
9797
9797
 
9798
- targetPanel = anchorAtPosition.panel; // Trigger only change event
9798
+ var targetPanel = anchorAtPosition.panel; // Trigger only change event
9799
9799
 
9800
- if (targetPanel !== this._activePanel) {
9801
- this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
9802
- }
9800
+ if (targetPanel !== this._activePanel) {
9801
+ this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
9802
+ }
9803
9803
 
9804
- return [2
9805
- /*return*/
9806
- , this._animateToPosition({
9807
- position: this._stopAtEdge ? targetPos : position,
9808
- duration: duration,
9809
- newActivePanel: targetPanel,
9810
- axesEvent: axesEvent
9811
- })];
9812
- });
9804
+ return this._animateToPosition({
9805
+ position: this._stopAtEdge ? targetPos : position,
9806
+ duration: duration,
9807
+ newActivePanel: targetPanel,
9808
+ axesEvent: axesEvent
9813
9809
  });
9814
9810
  };
9815
9811
 
@@ -10007,62 +10003,57 @@ version: 4.6.0
10007
10003
 
10008
10004
 
10009
10005
  __proto.moveToPosition = function (position, duration, axesEvent) {
10010
- return __awaiter(this, void 0, void 0, function () {
10011
- var flicking, camera, activePanel, axesRange, indexRange, cameraRange, clampedPosition, anchorAtPosition, prevPos, isOverThreshold, adjacentAnchor, targetPos, targetPanel, anchors, firstAnchor, lastAnchor, shouldBounceToFirst, shouldBounceToLast, targetAnchor;
10012
- return __generator(this, function (_a) {
10013
- flicking = getFlickingAttached(this._flicking);
10014
- camera = flicking.camera;
10015
- activePanel = this._activePanel;
10016
- axesRange = this._controller.range;
10017
- indexRange = this._indexRange;
10018
- cameraRange = camera.range;
10019
- clampedPosition = clamp(camera.clampToReachablePosition(position), axesRange[0], axesRange[1]);
10020
- anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
10021
-
10022
- if (!anchorAtPosition || !activePanel) {
10023
- return [2
10024
- /*return*/
10025
- , Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE))];
10026
- }
10006
+ var flicking = getFlickingAttached(this._flicking);
10007
+ var camera = flicking.camera;
10008
+ var activePanel = this._activePanel;
10009
+ var axesRange = this._controller.range;
10010
+ var indexRange = this._indexRange;
10011
+ var cameraRange = camera.range;
10012
+ var clampedPosition = clamp(camera.clampToReachablePosition(position), axesRange[0], axesRange[1]);
10013
+ var anchorAtPosition = camera.findAnchorIncludePosition(clampedPosition);
10027
10014
 
10028
- prevPos = activePanel.position;
10029
- isOverThreshold = Math.abs(position - prevPos) >= flicking.threshold;
10030
- adjacentAnchor = position > prevPos ? camera.getNextAnchor(anchorAtPosition) : camera.getPrevAnchor(anchorAtPosition);
10031
- anchors = camera.anchorPoints;
10032
- firstAnchor = anchors[0];
10033
- lastAnchor = anchors[anchors.length - 1];
10034
- shouldBounceToFirst = position <= cameraRange.min && isBetween(firstAnchor.panel.index, indexRange.min, indexRange.max);
10035
- shouldBounceToLast = position >= cameraRange.max && isBetween(lastAnchor.panel.index, indexRange.min, indexRange.max);
10036
-
10037
- if (shouldBounceToFirst || shouldBounceToLast) {
10038
- targetAnchor = position < cameraRange.min ? firstAnchor : lastAnchor;
10039
- targetPanel = targetAnchor.panel;
10040
- targetPos = targetAnchor.position;
10041
- } else if (isOverThreshold && anchorAtPosition.position !== activePanel.position) {
10042
- // Move to anchor at position
10043
- targetPanel = anchorAtPosition.panel;
10044
- targetPos = anchorAtPosition.position;
10045
- } else if (isOverThreshold && adjacentAnchor && isBetween(adjacentAnchor.index, indexRange.min, indexRange.max)) {
10046
- // Move to adjacent anchor
10047
- targetPanel = adjacentAnchor.panel;
10048
- targetPos = adjacentAnchor.position;
10049
- } else {
10050
- // Restore to active panel
10051
- targetPos = camera.clampToReachablePosition(activePanel.position);
10052
- targetPanel = activePanel;
10053
- }
10015
+ if (!anchorAtPosition || !activePanel) {
10016
+ return Promise.reject(new FlickingError(MESSAGE.POSITION_NOT_REACHABLE(position), CODE.POSITION_NOT_REACHABLE));
10017
+ }
10054
10018
 
10055
- this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
10019
+ var prevPos = activePanel.position;
10020
+ var isOverThreshold = Math.abs(position - prevPos) >= flicking.threshold;
10021
+ var adjacentAnchor = position > prevPos ? camera.getNextAnchor(anchorAtPosition) : camera.getPrevAnchor(anchorAtPosition);
10022
+ var targetPos;
10023
+ var targetPanel;
10024
+ var anchors = camera.anchorPoints;
10025
+ var firstAnchor = anchors[0];
10026
+ var lastAnchor = anchors[anchors.length - 1];
10027
+ var shouldBounceToFirst = position <= cameraRange.min && isBetween(firstAnchor.panel.index, indexRange.min, indexRange.max);
10028
+ var shouldBounceToLast = position >= cameraRange.max && isBetween(lastAnchor.panel.index, indexRange.min, indexRange.max);
10029
+ var isAdjacent = adjacentAnchor && (indexRange.min <= indexRange.max ? isBetween(adjacentAnchor.index, indexRange.min, indexRange.max) : adjacentAnchor.index >= indexRange.min || adjacentAnchor.index <= indexRange.max);
10030
+
10031
+ if (shouldBounceToFirst || shouldBounceToLast) {
10032
+ // In bounce area
10033
+ var targetAnchor = position < cameraRange.min ? firstAnchor : lastAnchor;
10034
+ targetPanel = targetAnchor.panel;
10035
+ targetPos = targetAnchor.position;
10036
+ } else if (isOverThreshold && anchorAtPosition.position !== activePanel.position) {
10037
+ // Move to anchor at position
10038
+ targetPanel = anchorAtPosition.panel;
10039
+ targetPos = anchorAtPosition.position;
10040
+ } else if (isOverThreshold && isAdjacent) {
10041
+ // Move to adjacent anchor
10042
+ targetPanel = adjacentAnchor.panel;
10043
+ targetPos = adjacentAnchor.position;
10044
+ } else {
10045
+ // Restore to active panel
10046
+ targetPos = camera.clampToReachablePosition(activePanel.position);
10047
+ targetPanel = activePanel;
10048
+ }
10056
10049
 
10057
- return [2
10058
- /*return*/
10059
- , this._animateToPosition({
10060
- position: targetPos,
10061
- duration: duration,
10062
- newActivePanel: targetPanel,
10063
- axesEvent: axesEvent
10064
- })];
10065
- });
10050
+ this._triggerIndexChangeEvent(targetPanel, position, axesEvent);
10051
+
10052
+ return this._animateToPosition({
10053
+ position: targetPos,
10054
+ duration: duration,
10055
+ newActivePanel: targetPanel,
10056
+ axesEvent: axesEvent
10066
10057
  });
10067
10058
  };
10068
10059
 
@@ -10133,6 +10124,27 @@ version: 4.6.0
10133
10124
  }, null);
10134
10125
  };
10135
10126
 
10127
+ __proto.findNearestAnchor = function (position) {
10128
+ var anchors = this._flicking.camera.anchorPoints;
10129
+ if (anchors.length <= 0) return null;
10130
+ var prevDist = Infinity;
10131
+
10132
+ for (var anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
10133
+ var anchor = anchors[anchorIdx];
10134
+ var dist = Math.abs(anchor.position - position);
10135
+
10136
+ if (dist > prevDist) {
10137
+ // Return previous anchor
10138
+ return anchors[anchorIdx - 1];
10139
+ }
10140
+
10141
+ prevDist = dist;
10142
+ } // Return last anchor
10143
+
10144
+
10145
+ return anchors[anchors.length - 1];
10146
+ };
10147
+
10136
10148
  __proto.clampToReachablePosition = function (position) {
10137
10149
  var camera = this._flicking.camera;
10138
10150
  var range = camera.range;
@@ -10262,6 +10274,28 @@ version: 4.6.0
10262
10274
  });
10263
10275
  };
10264
10276
 
10277
+ __proto.findNearestAnchor = function (position) {
10278
+ var camera = this._flicking.camera;
10279
+ var anchors = camera.anchorPoints;
10280
+ if (anchors.length <= 0) return null;
10281
+ var camRange = camera.range;
10282
+ var minDist = Infinity;
10283
+ var minDistIndex = -1;
10284
+
10285
+ for (var anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
10286
+ var anchor = anchors[anchorIdx];
10287
+ 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));
10288
+
10289
+ if (dist < minDist) {
10290
+ minDist = dist;
10291
+ minDistIndex = anchorIdx;
10292
+ }
10293
+ } // Return last anchor
10294
+
10295
+
10296
+ return anchors[minDistIndex];
10297
+ };
10298
+
10265
10299
  __proto.findAnchorIncludePosition = function (position) {
10266
10300
  var camera = this._flicking.camera;
10267
10301
  var range = camera.range;
@@ -11030,24 +11064,7 @@ version: 4.6.0
11030
11064
 
11031
11065
 
11032
11066
  __proto.findNearestAnchor = function (position) {
11033
- var anchors = this._anchors;
11034
- if (anchors.length <= 0) return null;
11035
- var prevDist = Infinity;
11036
-
11037
- for (var anchorIdx = 0; anchorIdx < anchors.length; anchorIdx++) {
11038
- var anchor = anchors[anchorIdx];
11039
- var dist = Math.abs(anchor.position - position);
11040
-
11041
- if (dist > prevDist) {
11042
- // Return previous anchor
11043
- return anchors[anchorIdx - 1];
11044
- }
11045
-
11046
- prevDist = dist;
11047
- } // Return last anchor
11048
-
11049
-
11050
- return anchors[anchors.length - 1];
11067
+ return this._mode.findNearestAnchor(position);
11051
11068
  };
11052
11069
  /**
11053
11070
  * Return {@link AnchorPoint} that matches {@link Flicking#currentPanel}
@@ -12751,29 +12768,31 @@ version: 4.6.0
12751
12768
 
12752
12769
  void this.render();
12753
12770
 
12754
- if (!activePanel || activePanel.removed) {
12755
- if (panels.length <= 0) {
12756
- // All panels removed
12757
- camera.lookAt(0);
12758
- } else {
12759
- var targetIndex = (_a = activePanel === null || activePanel === void 0 ? void 0 : activePanel.index) !== null && _a !== void 0 ? _a : 0;
12771
+ if (!flicking.animating) {
12772
+ if (!activePanel || activePanel.removed) {
12773
+ if (panels.length <= 0) {
12774
+ // All panels removed
12775
+ camera.lookAt(0);
12776
+ } else {
12777
+ var targetIndex = (_a = activePanel === null || activePanel === void 0 ? void 0 : activePanel.index) !== null && _a !== void 0 ? _a : 0;
12760
12778
 
12761
- if (targetIndex > panels.length - 1) {
12762
- targetIndex = panels.length - 1;
12763
- }
12779
+ if (targetIndex > panels.length - 1) {
12780
+ targetIndex = panels.length - 1;
12781
+ }
12764
12782
 
12765
- void control.moveToPanel(panels[targetIndex], {
12783
+ void control.moveToPanel(panels[targetIndex], {
12784
+ duration: 0
12785
+ }).catch(function () {
12786
+ return void 0;
12787
+ });
12788
+ }
12789
+ } else {
12790
+ void control.moveToPanel(activePanel, {
12766
12791
  duration: 0
12767
12792
  }).catch(function () {
12768
12793
  return void 0;
12769
12794
  });
12770
12795
  }
12771
- } else {
12772
- void control.moveToPanel(control.activePanel, {
12773
- duration: 0
12774
- }).catch(function () {
12775
- return void 0;
12776
- });
12777
12796
  }
12778
12797
 
12779
12798
  flicking.camera.updateOffset();
@@ -15896,7 +15915,7 @@ version: 4.6.0
15896
15915
  */
15897
15916
 
15898
15917
 
15899
- Flicking.VERSION = "4.6.0";
15918
+ Flicking.VERSION = "4.6.3";
15900
15919
  return Flicking;
15901
15920
  }(Component$1);
15902
15921
 
@@ -16067,7 +16086,9 @@ version: 4.6.0
16067
16086
  }
16068
16087
  }
16069
16088
 
16070
- renderer.updateAfterPanelChange(added, removed);
16089
+ if (diffResult.added.length > 0 || diffResult.removed.length > 0) {
16090
+ renderer.updateAfterPanelChange(added, removed);
16091
+ }
16071
16092
  });
16072
16093
 
16073
16094
  var batchInsert = function (renderer, diffResult, addedElements, startIdx, endIdx) {