@capgo/capacitor-transitions 8.0.3 → 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.
@@ -4,6 +4,8 @@
4
4
  */
5
5
  /** Direction of the navigation transition */
6
6
  type TransitionDirection = 'forward' | 'back' | 'root' | 'none';
7
+ /** Navigation stack action to record independently from the animation direction */
8
+ type NavigationAction = 'forward' | 'back' | 'root' | 'none';
7
9
  /** Platform-specific animation styles */
8
10
  type TransitionPlatform = 'ios' | 'android' | 'auto';
9
11
  /** Whether the edge swipe-back gesture is enabled, disabled, or native-detected */
@@ -20,6 +22,8 @@ interface TransitionConfig {
20
22
  easing?: TransitionEasing;
21
23
  /** Direction of transition */
22
24
  direction?: TransitionDirection;
25
+ /** Navigation stack action (default: follows direction, except 'none' keeps push behavior for compatibility) */
26
+ navigationAction?: NavigationAction;
23
27
  /** Which elements to animate (default: 'all') */
24
28
  targets?: TransitionTarget[];
25
29
  /** Custom animation keyframes for entering element */
@@ -186,6 +190,7 @@ declare class TransitionController {
186
190
  * Main navigation method
187
191
  */
188
192
  navigate(enteringEl: HTMLElement, config?: TransitionConfig): Promise<TransitionResult>;
193
+ private resolveNavigationAction;
189
194
  /**
190
195
  * Navigate between two known page states
191
196
  */
@@ -262,6 +267,10 @@ declare function getController(): TransitionController;
262
267
  */
263
268
  declare function getDirection(): TransitionDirection;
264
269
  declare function setDirection(direction: TransitionDirection): void;
270
+ /**
271
+ * Set the navigation action and animation direction for the next router navigation.
272
+ */
273
+ declare function setNavigation(action: NavigationAction, direction?: TransitionDirection): void;
265
274
  /**
266
275
  * Set up a router outlet element
267
276
  * Call this in onMounted with a ref to the cap-router-outlet element
@@ -332,4 +341,4 @@ declare function setupPage(element: HTMLElement, callbacks?: {
332
341
  */
333
342
  declare function createTransitionNavigate(navigate: (to: string) => void): (to: string, direction?: TransitionDirection) => void;
334
343
 
335
- export { type NavigationEvent, type SwipeGestureOption, TransitionController, type TransitionDirection, type TransitionGlobalConfig, createTransitionNavigate, getController, getDirection, initTransitions, setDirection, setupPage, setupRouterOutlet };
344
+ export { type NavigationAction, type NavigationEvent, type SwipeGestureOption, TransitionController, type TransitionDirection, type TransitionGlobalConfig, createTransitionNavigate, getController, getDirection, initTransitions, setDirection, setNavigation, setupPage, setupRouterOutlet };
@@ -4,6 +4,8 @@
4
4
  */
5
5
  /** Direction of the navigation transition */
6
6
  type TransitionDirection = 'forward' | 'back' | 'root' | 'none';
7
+ /** Navigation stack action to record independently from the animation direction */
8
+ type NavigationAction = 'forward' | 'back' | 'root' | 'none';
7
9
  /** Platform-specific animation styles */
8
10
  type TransitionPlatform = 'ios' | 'android' | 'auto';
9
11
  /** Whether the edge swipe-back gesture is enabled, disabled, or native-detected */
@@ -20,6 +22,8 @@ interface TransitionConfig {
20
22
  easing?: TransitionEasing;
21
23
  /** Direction of transition */
22
24
  direction?: TransitionDirection;
25
+ /** Navigation stack action (default: follows direction, except 'none' keeps push behavior for compatibility) */
26
+ navigationAction?: NavigationAction;
23
27
  /** Which elements to animate (default: 'all') */
24
28
  targets?: TransitionTarget[];
25
29
  /** Custom animation keyframes for entering element */
@@ -186,6 +190,7 @@ declare class TransitionController {
186
190
  * Main navigation method
187
191
  */
188
192
  navigate(enteringEl: HTMLElement, config?: TransitionConfig): Promise<TransitionResult>;
193
+ private resolveNavigationAction;
189
194
  /**
190
195
  * Navigate between two known page states
191
196
  */
@@ -262,6 +267,10 @@ declare function getController(): TransitionController;
262
267
  */
263
268
  declare function getDirection(): TransitionDirection;
264
269
  declare function setDirection(direction: TransitionDirection): void;
270
+ /**
271
+ * Set the navigation action and animation direction for the next router navigation.
272
+ */
273
+ declare function setNavigation(action: NavigationAction, direction?: TransitionDirection): void;
265
274
  /**
266
275
  * Set up a router outlet element
267
276
  * Call this in onMounted with a ref to the cap-router-outlet element
@@ -332,4 +341,4 @@ declare function setupPage(element: HTMLElement, callbacks?: {
332
341
  */
333
342
  declare function createTransitionNavigate(navigate: (to: string) => void): (to: string, direction?: TransitionDirection) => void;
334
343
 
335
- export { type NavigationEvent, type SwipeGestureOption, TransitionController, type TransitionDirection, type TransitionGlobalConfig, createTransitionNavigate, getController, getDirection, initTransitions, setDirection, setupPage, setupRouterOutlet };
344
+ export { type NavigationAction, type NavigationEvent, type SwipeGestureOption, TransitionController, type TransitionDirection, type TransitionGlobalConfig, createTransitionNavigate, getController, getDirection, initTransitions, setDirection, setNavigation, setupPage, setupRouterOutlet };
package/dist/vue/index.js CHANGED
@@ -26,11 +26,27 @@ __export(index_exports, {
26
26
  getDirection: () => getDirection,
27
27
  initTransitions: () => initTransitions,
28
28
  setDirection: () => setDirection,
29
+ setNavigation: () => setNavigation,
29
30
  setupPage: () => setupPage,
30
31
  setupRouterOutlet: () => setupRouterOutlet
31
32
  });
32
33
  module.exports = __toCommonJS(index_exports);
33
34
 
35
+ // src/core/navigation.ts
36
+ function getDefaultNavigationDirection(action) {
37
+ return action;
38
+ }
39
+ function setOutletDirectionIntent(outlet, direction) {
40
+ const element = outlet;
41
+ element.dataset.direction = direction;
42
+ delete element.dataset.navigationAction;
43
+ }
44
+ function setOutletNavigationIntent(outlet, action, direction = getDefaultNavigationDirection(action)) {
45
+ const element = outlet;
46
+ element.dataset.navigationAction = action;
47
+ element.dataset.direction = direction;
48
+ }
49
+
34
50
  // src/core/animations.ts
35
51
  var IOS_EASING = "cubic-bezier(0.32, 0.72, 0, 1)";
36
52
  var ANDROID_EASING = "cubic-bezier(0.36, 0.66, 0.04, 1)";
@@ -905,19 +921,24 @@ var TransitionController = class {
905
921
  * Replace all pages with a new root
906
922
  */
907
923
  async setRoot(enteringEl, config = {}) {
908
- return this.navigate(enteringEl, { ...config, direction: "root" });
924
+ return this.navigate(enteringEl, {
925
+ ...config,
926
+ direction: config.direction ?? "root",
927
+ navigationAction: "root"
928
+ });
909
929
  }
910
930
  /**
911
931
  * Main navigation method
912
932
  */
913
933
  async navigate(enteringEl, config = {}) {
914
934
  const direction = config.direction || "forward";
935
+ const navigationAction = this.resolveNavigationAction(direction, config.navigationAction);
915
936
  const enteringState = this.createPageState(enteringEl);
916
937
  const leavingState = this.currentPage;
917
938
  return this.navigateWithStates(enteringState, leavingState, config, () => {
918
- if (direction === "root") {
939
+ if (navigationAction === "root") {
919
940
  this.pageStack = [enteringState];
920
- } else if (direction === "back" && this.pageStack.length > 0) {
941
+ } else if (navigationAction === "back" && this.pageStack.length > 0) {
921
942
  this.pageStack.pop();
922
943
  const staleEnteringState = this.pageStack.pop();
923
944
  if (staleEnteringState && staleEnteringState.element !== enteringState.element) {
@@ -925,11 +946,27 @@ var TransitionController = class {
925
946
  this.lifecycleCallbacks.delete(staleEnteringState.id);
926
947
  }
927
948
  this.pageStack.push(enteringState);
949
+ } else if (navigationAction === "none" && this.pageStack.length > 0) {
950
+ const staleState = this.pageStack.pop();
951
+ if (staleState && staleState.element !== enteringState.element) {
952
+ staleState.element.remove();
953
+ this.lifecycleCallbacks.delete(staleState.id);
954
+ }
955
+ this.pageStack.push(enteringState);
928
956
  } else {
929
957
  this.pageStack.push(enteringState);
930
958
  }
931
959
  });
932
960
  }
961
+ resolveNavigationAction(direction, navigationAction) {
962
+ if (navigationAction) {
963
+ return navigationAction;
964
+ }
965
+ if (direction === "root" || direction === "back") {
966
+ return direction;
967
+ }
968
+ return "forward";
969
+ }
933
970
  /**
934
971
  * Navigate between two known page states
935
972
  */
@@ -1405,20 +1442,29 @@ var CapRouterOutlet = class extends HTMLElement {
1405
1442
  */
1406
1443
  async handleNewPage(page) {
1407
1444
  const outletDirection = this.dataset.direction;
1445
+ const outletNavigationAction = this.dataset.navigationAction;
1408
1446
  const explicitDirection = page.dataset.direction || outletDirection;
1447
+ const explicitNavigationAction = page.dataset.navigationAction || outletNavigationAction;
1409
1448
  const direction = this.resolveNavigationDirection(explicitDirection);
1410
1449
  if (outletDirection) {
1411
1450
  delete this.dataset.direction;
1412
1451
  }
1452
+ if (outletNavigationAction) {
1453
+ delete this.dataset.navigationAction;
1454
+ }
1413
1455
  const skipTransition = this.skipNextHistoryBackTransition && direction === "back";
1414
1456
  this.skipNextHistoryBackTransition = false;
1415
1457
  const hadPageBefore = this.controller.stack.length > 0;
1416
1458
  this.stylePageForTransition(page);
1417
1459
  this.pendingPage = page;
1418
1460
  try {
1419
- const result = await this.controller.navigate(page, { direction, duration: skipTransition ? 0 : void 0 });
1461
+ const result = await this.controller.navigate(page, {
1462
+ direction,
1463
+ navigationAction: explicitNavigationAction,
1464
+ duration: skipTransition ? 0 : void 0
1465
+ });
1420
1466
  if (result.success) {
1421
- this.recordCompletedNavigation(direction, { hadPageBefore });
1467
+ this.recordCompletedNavigation(explicitNavigationAction ?? direction, { hadPageBefore });
1422
1468
  }
1423
1469
  } finally {
1424
1470
  this.pendingPage = null;
@@ -1547,6 +1593,12 @@ var CapRouterOutlet = class extends HTMLElement {
1547
1593
  this.updateSwipeGestureListeners();
1548
1594
  }
1549
1595
  }
1596
+ /**
1597
+ * Set the navigation stack action and animation direction for the next router-driven navigation.
1598
+ */
1599
+ setNavigation(action, direction = getDefaultNavigationDirection(action)) {
1600
+ setOutletNavigationIntent(this, action, direction);
1601
+ }
1550
1602
  /**
1551
1603
  * Get the transition controller for advanced usage
1552
1604
  */
@@ -1945,7 +1997,7 @@ var CapRouterOutlet = class extends HTMLElement {
1945
1997
  }
1946
1998
  if (shouldUseHistory) {
1947
1999
  this.skipNextHistoryBackTransition = true;
1948
- this.dataset.direction = "back";
2000
+ setOutletDirectionIntent(this, "back");
1949
2001
  window.history.back();
1950
2002
  return;
1951
2003
  }
@@ -2381,7 +2433,15 @@ function setDirection(direction) {
2381
2433
  globalDirection = direction;
2382
2434
  if (typeof document !== "undefined") {
2383
2435
  for (const outlet of document.querySelectorAll("cap-router-outlet")) {
2384
- outlet.dataset.direction = direction;
2436
+ setOutletDirectionIntent(outlet, direction);
2437
+ }
2438
+ }
2439
+ }
2440
+ function setNavigation(action, direction = getDefaultNavigationDirection(action)) {
2441
+ globalDirection = direction;
2442
+ if (typeof document !== "undefined") {
2443
+ for (const outlet of document.querySelectorAll("cap-router-outlet")) {
2444
+ setOutletNavigationIntent(outlet, action, direction);
2385
2445
  }
2386
2446
  }
2387
2447
  }
@@ -2431,6 +2491,7 @@ function createTransitionNavigate(navigate) {
2431
2491
  getDirection,
2432
2492
  initTransitions,
2433
2493
  setDirection,
2494
+ setNavigation,
2434
2495
  setupPage,
2435
2496
  setupRouterOutlet
2436
2497
  });