@capgo/capacitor-transitions 8.0.2 → 8.0.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/vue/index.js CHANGED
@@ -829,12 +829,15 @@ var TransitionController = class {
829
829
  animation.pause();
830
830
  animation.currentTime = 0;
831
831
  }
832
+ const animationDurations = animations.map((animation) => this.getAnimationDuration(animation, duration));
832
833
  this.currentAnimations = animations;
833
834
  this.interactiveBackTransition = {
834
835
  enteringState,
835
836
  leavingState,
836
837
  animations,
837
- duration
838
+ animationDurations,
839
+ duration,
840
+ progress: 0
838
841
  };
839
842
  return true;
840
843
  }
@@ -847,9 +850,12 @@ var TransitionController = class {
847
850
  return;
848
851
  }
849
852
  const progress = Math.max(0, Math.min(step, 0.9999));
850
- for (const animation of transition.animations) {
851
- const duration = this.getAnimationDuration(animation, transition.duration);
852
- animation.pause();
853
+ if (Math.abs(progress - transition.progress) < 5e-4) {
854
+ return;
855
+ }
856
+ transition.progress = progress;
857
+ for (const [index, animation] of transition.animations.entries()) {
858
+ const duration = transition.animationDurations[index] ?? transition.duration;
853
859
  animation.currentTime = duration * progress;
854
860
  }
855
861
  }
@@ -1028,15 +1034,16 @@ var TransitionController = class {
1028
1034
  return;
1029
1035
  }
1030
1036
  if (releaseDuration <= 0) {
1031
- for (const animation of transition.animations) {
1032
- const duration = this.getAnimationDuration(animation, transition.duration);
1037
+ transition.progress = targetProgress;
1038
+ for (const [index, animation] of transition.animations.entries()) {
1039
+ const duration = transition.animationDurations[index] ?? transition.duration;
1033
1040
  animation.pause();
1034
1041
  animation.currentTime = duration * targetProgress;
1035
1042
  }
1036
1043
  return;
1037
1044
  }
1038
- const finished = transition.animations.map((animation) => {
1039
- const duration = this.getAnimationDuration(animation, transition.duration);
1045
+ const finished = transition.animations.map((animation, index) => {
1046
+ const duration = transition.animationDurations[index] ?? transition.duration;
1040
1047
  const currentTime = typeof animation.currentTime === "number" ? animation.currentTime : 0;
1041
1048
  const targetTime = duration * targetProgress;
1042
1049
  const distance = Math.abs(targetTime - currentTime);
@@ -1049,6 +1056,7 @@ var TransitionController = class {
1049
1056
  return animation.finished.catch(() => void 0);
1050
1057
  });
1051
1058
  await Promise.all(finished);
1059
+ transition.progress = targetProgress;
1052
1060
  }
1053
1061
  /**
1054
1062
  * Resolve configured easing presets after platform/direction are known.
@@ -1238,6 +1246,8 @@ var CapRouterOutlet = class extends HTMLElement {
1238
1246
  pendingPage = null;
1239
1247
  ignoredNodes = /* @__PURE__ */ new WeakSet();
1240
1248
  swipeGesturePointer = null;
1249
+ swipeGestureFrame = 0;
1250
+ swipeGesturePendingStep = null;
1241
1251
  swipeGestureListenersActive = false;
1242
1252
  skipNextHistoryBackTransition = false;
1243
1253
  swipeBackDepth = 0;
@@ -1280,6 +1290,7 @@ var CapRouterOutlet = class extends HTMLElement {
1280
1290
  this.style.width = "100%";
1281
1291
  this.style.height = "100%";
1282
1292
  this.style.overflow = "hidden";
1293
+ this.style.overscrollBehaviorX = "contain";
1283
1294
  this.lastNavigationHref = this.getCurrentNavigationHref();
1284
1295
  this.lastNavigationPosition = this.getCurrentNavigationPosition();
1285
1296
  this.ownerDocument.defaultView?.addEventListener("popstate", this.handleHistoryPopState);
@@ -1587,6 +1598,10 @@ var CapRouterOutlet = class extends HTMLElement {
1587
1598
  this.removeEventListener("pointerup", this.handleSwipeGesturePointerEnd);
1588
1599
  this.removeEventListener("pointercancel", this.handleSwipeGesturePointerCancel);
1589
1600
  this.swipeGestureListenersActive = false;
1601
+ this.clearQueuedSwipeGestureStep();
1602
+ if (this.swipeGesturePointer?.transitionStarted) {
1603
+ this.controller.cancelInteractiveBack();
1604
+ }
1590
1605
  this.swipeGesturePointer = null;
1591
1606
  }
1592
1607
  isSwipeGestureEnabled() {
@@ -1779,12 +1794,14 @@ var CapRouterOutlet = class extends HTMLElement {
1779
1794
  if (!this.canStartSwipeGesture(event)) {
1780
1795
  return;
1781
1796
  }
1797
+ const width = Math.max(this.getBoundingClientRect().width, 1);
1782
1798
  this.swipeGesturePointer = {
1783
1799
  pointerId: event.pointerId,
1784
1800
  startX: event.clientX,
1785
1801
  startY: event.clientY,
1786
1802
  currentX: event.clientX,
1787
1803
  currentY: event.clientY,
1804
+ width,
1788
1805
  startTime: performance.now(),
1789
1806
  dragging: false,
1790
1807
  transitionStarted: false
@@ -1831,8 +1848,7 @@ var CapRouterOutlet = class extends HTMLElement {
1831
1848
  return;
1832
1849
  }
1833
1850
  if (event.cancelable) event.preventDefault();
1834
- const width = Math.max(this.getBoundingClientRect().width, 1);
1835
- this.controller.stepInteractiveBack(deltaX / width);
1851
+ this.queueSwipeGestureStep(deltaX / pointer.width);
1836
1852
  }
1837
1853
  };
1838
1854
  handleSwipeGesturePointerEnd = (event) => {
@@ -1845,12 +1861,17 @@ var CapRouterOutlet = class extends HTMLElement {
1845
1861
  const deltaX = this.getSwipeGestureDeltaX(pointer);
1846
1862
  const elapsed = Math.max(performance.now() - pointer.startTime, 1);
1847
1863
  const velocityX = deltaX / elapsed;
1848
- const width = Math.max(this.getBoundingClientRect().width, 1);
1864
+ const width = pointer.width;
1849
1865
  const step = deltaX / width;
1850
1866
  const shouldCommit = pointer.dragging && pointer.transitionStarted && velocityX >= 0 && (velocityX > this.swipeGestureMinimumVelocity || deltaX > width / 2);
1851
1867
  const missing = shouldCommit ? 1 - step : step;
1852
1868
  const missingDistance = Math.max(missing, 0) * width;
1853
1869
  const releaseDuration = missingDistance > 5 && Math.abs(velocityX) > 0 ? Math.min(missingDistance / Math.abs(velocityX), 540) : 0;
1870
+ if (pointer.transitionStarted) {
1871
+ this.flushQueuedSwipeGestureStep();
1872
+ } else {
1873
+ this.clearQueuedSwipeGestureStep();
1874
+ }
1854
1875
  this.releaseSwipeGesturePointer(event.pointerId);
1855
1876
  void this.finishSwipeGestureBack(shouldCommit, releaseDuration);
1856
1877
  };
@@ -1858,6 +1879,7 @@ var CapRouterOutlet = class extends HTMLElement {
1858
1879
  this.cancelSwipeGesture(event.pointerId);
1859
1880
  };
1860
1881
  cancelSwipeGesturePointer(pointerId) {
1882
+ this.clearQueuedSwipeGestureStep();
1861
1883
  this.releaseSwipeGesturePointer(pointerId);
1862
1884
  }
1863
1885
  releaseSwipeGesturePointer(pointerId) {
@@ -1876,10 +1898,44 @@ var CapRouterOutlet = class extends HTMLElement {
1876
1898
  return;
1877
1899
  }
1878
1900
  this.releaseSwipeGesturePointer(pointerId);
1901
+ this.clearQueuedSwipeGestureStep();
1879
1902
  if (pointer.transitionStarted) {
1880
1903
  void this.finishSwipeGestureBack(false, 0);
1881
1904
  }
1882
1905
  }
1906
+ queueSwipeGestureStep(step) {
1907
+ this.swipeGesturePendingStep = step;
1908
+ if (this.swipeGestureFrame !== 0) {
1909
+ return;
1910
+ }
1911
+ const win = this.ownerDocument.defaultView;
1912
+ if (!win) {
1913
+ this.flushQueuedSwipeGestureStep();
1914
+ return;
1915
+ }
1916
+ this.swipeGestureFrame = win.requestAnimationFrame(() => {
1917
+ this.swipeGestureFrame = 0;
1918
+ this.flushQueuedSwipeGestureStep();
1919
+ });
1920
+ }
1921
+ flushQueuedSwipeGestureStep() {
1922
+ const step = this.swipeGesturePendingStep;
1923
+ this.swipeGesturePendingStep = null;
1924
+ if (this.swipeGestureFrame !== 0) {
1925
+ this.ownerDocument.defaultView?.cancelAnimationFrame(this.swipeGestureFrame);
1926
+ this.swipeGestureFrame = 0;
1927
+ }
1928
+ if (step !== null) {
1929
+ this.controller.stepInteractiveBack(step);
1930
+ }
1931
+ }
1932
+ clearQueuedSwipeGestureStep() {
1933
+ if (this.swipeGestureFrame !== 0) {
1934
+ this.ownerDocument.defaultView?.cancelAnimationFrame(this.swipeGestureFrame);
1935
+ this.swipeGestureFrame = 0;
1936
+ }
1937
+ this.swipeGesturePendingStep = null;
1938
+ }
1883
1939
  async finishSwipeGestureBack(shouldComplete, releaseDuration) {
1884
1940
  const canComplete = shouldComplete && this.getSwipeBackDestination() !== null;
1885
1941
  const shouldUseHistory = canComplete && typeof window !== "undefined" && window.history.length > 1;