@capgo/capacitor-transitions 8.0.4 → 8.1.0

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.
@@ -1,3 +1,18 @@
1
+ // src/core/navigation.ts
2
+ function getDefaultNavigationDirection(action) {
3
+ return action;
4
+ }
5
+ function setOutletDirectionIntent(outlet, direction) {
6
+ const element = outlet;
7
+ element.dataset.direction = direction;
8
+ delete element.dataset.navigationAction;
9
+ }
10
+ function setOutletNavigationIntent(outlet, action, direction = getDefaultNavigationDirection(action)) {
11
+ const element = outlet;
12
+ element.dataset.navigationAction = action;
13
+ element.dataset.direction = direction;
14
+ }
15
+
1
16
  // src/core/animations.ts
2
17
  var IOS_EASING = "cubic-bezier(0.32, 0.72, 0, 1)";
3
18
  var ANDROID_EASING = "cubic-bezier(0.36, 0.66, 0.04, 1)";
@@ -872,19 +887,24 @@ var TransitionController = class {
872
887
  * Replace all pages with a new root
873
888
  */
874
889
  async setRoot(enteringEl, config = {}) {
875
- return this.navigate(enteringEl, { ...config, direction: "root" });
890
+ return this.navigate(enteringEl, {
891
+ ...config,
892
+ direction: config.direction ?? "root",
893
+ navigationAction: "root"
894
+ });
876
895
  }
877
896
  /**
878
897
  * Main navigation method
879
898
  */
880
899
  async navigate(enteringEl, config = {}) {
881
900
  const direction = config.direction || "forward";
901
+ const navigationAction = this.resolveNavigationAction(direction, config.navigationAction);
882
902
  const enteringState = this.createPageState(enteringEl);
883
903
  const leavingState = this.currentPage;
884
904
  return this.navigateWithStates(enteringState, leavingState, config, () => {
885
- if (direction === "root") {
905
+ if (navigationAction === "root") {
886
906
  this.pageStack = [enteringState];
887
- } else if (direction === "back" && this.pageStack.length > 0) {
907
+ } else if (navigationAction === "back" && this.pageStack.length > 0) {
888
908
  this.pageStack.pop();
889
909
  const staleEnteringState = this.pageStack.pop();
890
910
  if (staleEnteringState && staleEnteringState.element !== enteringState.element) {
@@ -892,11 +912,27 @@ var TransitionController = class {
892
912
  this.lifecycleCallbacks.delete(staleEnteringState.id);
893
913
  }
894
914
  this.pageStack.push(enteringState);
915
+ } else if (navigationAction === "none" && this.pageStack.length > 0) {
916
+ const staleState = this.pageStack.pop();
917
+ if (staleState && staleState.element !== enteringState.element) {
918
+ staleState.element.remove();
919
+ this.lifecycleCallbacks.delete(staleState.id);
920
+ }
921
+ this.pageStack.push(enteringState);
895
922
  } else {
896
923
  this.pageStack.push(enteringState);
897
924
  }
898
925
  });
899
926
  }
927
+ resolveNavigationAction(direction, navigationAction) {
928
+ if (navigationAction) {
929
+ return navigationAction;
930
+ }
931
+ if (direction === "root" || direction === "back") {
932
+ return direction;
933
+ }
934
+ return "forward";
935
+ }
900
936
  /**
901
937
  * Navigate between two known page states
902
938
  */
@@ -1372,20 +1408,29 @@ var CapRouterOutlet = class extends HTMLElement {
1372
1408
  */
1373
1409
  async handleNewPage(page2) {
1374
1410
  const outletDirection = this.dataset.direction;
1411
+ const outletNavigationAction = this.dataset.navigationAction;
1375
1412
  const explicitDirection = page2.dataset.direction || outletDirection;
1413
+ const explicitNavigationAction = page2.dataset.navigationAction || outletNavigationAction;
1376
1414
  const direction = this.resolveNavigationDirection(explicitDirection);
1377
1415
  if (outletDirection) {
1378
1416
  delete this.dataset.direction;
1379
1417
  }
1418
+ if (outletNavigationAction) {
1419
+ delete this.dataset.navigationAction;
1420
+ }
1380
1421
  const skipTransition = this.skipNextHistoryBackTransition && direction === "back";
1381
1422
  this.skipNextHistoryBackTransition = false;
1382
1423
  const hadPageBefore = this.controller.stack.length > 0;
1383
1424
  this.stylePageForTransition(page2);
1384
1425
  this.pendingPage = page2;
1385
1426
  try {
1386
- const result = await this.controller.navigate(page2, { direction, duration: skipTransition ? 0 : void 0 });
1427
+ const result = await this.controller.navigate(page2, {
1428
+ direction,
1429
+ navigationAction: explicitNavigationAction,
1430
+ duration: skipTransition ? 0 : void 0
1431
+ });
1387
1432
  if (result.success) {
1388
- this.recordCompletedNavigation(direction, { hadPageBefore });
1433
+ this.recordCompletedNavigation(explicitNavigationAction ?? direction, { hadPageBefore });
1389
1434
  }
1390
1435
  } finally {
1391
1436
  this.pendingPage = null;
@@ -1514,6 +1559,12 @@ var CapRouterOutlet = class extends HTMLElement {
1514
1559
  this.updateSwipeGestureListeners();
1515
1560
  }
1516
1561
  }
1562
+ /**
1563
+ * Set the navigation stack action and animation direction for the next router-driven navigation.
1564
+ */
1565
+ setNavigation(action, direction = getDefaultNavigationDirection(action)) {
1566
+ setOutletNavigationIntent(this, action, direction);
1567
+ }
1517
1568
  /**
1518
1569
  * Get the transition controller for advanced usage
1519
1570
  */
@@ -1912,7 +1963,7 @@ var CapRouterOutlet = class extends HTMLElement {
1912
1963
  }
1913
1964
  if (shouldUseHistory) {
1914
1965
  this.skipNextHistoryBackTransition = true;
1915
- this.dataset.direction = "back";
1966
+ setOutletDirectionIntent(this, "back");
1916
1967
  window.history.back();
1917
1968
  return;
1918
1969
  }
@@ -2348,7 +2399,15 @@ function setDirection(direction) {
2348
2399
  globalDirection = direction;
2349
2400
  if (typeof document !== "undefined") {
2350
2401
  for (const outlet of document.querySelectorAll("cap-router-outlet")) {
2351
- outlet.dataset.direction = direction;
2402
+ setOutletDirectionIntent(outlet, direction);
2403
+ }
2404
+ }
2405
+ }
2406
+ function setNavigation(action, direction = getDefaultNavigationDirection(action)) {
2407
+ globalDirection = direction;
2408
+ if (typeof document !== "undefined") {
2409
+ for (const outlet of document.querySelectorAll("cap-router-outlet")) {
2410
+ setOutletNavigationIntent(outlet, action, direction);
2352
2411
  }
2353
2412
  }
2354
2413
  }
@@ -2427,6 +2486,7 @@ export {
2427
2486
  navigateWithTransition,
2428
2487
  page,
2429
2488
  routerOutlet,
2430
- setDirection
2489
+ setDirection,
2490
+ setNavigation
2431
2491
  };
2432
2492
  //# sourceMappingURL=index.mjs.map