akanjs 3.3.0-rc.49 → 3.3.0-rc.50

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.3.0-rc.49",
3
+ "version": "3.3.0-rc.50",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -19,7 +19,11 @@ export declare class CsrSlide {
19
19
  private constructor();
20
20
  static get supported(): boolean;
21
21
  static get isCalm(): boolean;
22
- static holdStill(kind: "push" | "replace", from: Location, to: Location): boolean;
22
+ static settleMove(kind: "push" | "replace", from: Location, to: Location): boolean;
23
+ /** How an entry moves: its own page's transition, or that of the page it took the place of. */
24
+ static motionOf(location: Location): "none" | "stack" | "fade" | "bottomUp" | "scaleOut";
25
+ /** Whether an entry swipes back: its own page's `gesture`, or that of the page it took the place of. */
26
+ static swipesBack(location: Location): boolean;
23
27
  static isStill(entryId: string | undefined): boolean;
24
28
  static play(frame: CsrSlideFrame, { fromUnit, toUnit, duration, keep }: CsrSlidePlay): CsrSlide | null;
25
29
  /** What each part's style is with the page `unit` px from its place: 0 shown, the frame's width gone right. */
package/ui/System/CSR.tsx CHANGED
@@ -27,6 +27,7 @@ import {
27
27
  } from "react";
28
28
  import { createPortal } from "react-dom";
29
29
  import { AgentActivity } from "../../vendor/use-agentic";
30
+ import { CsrSlide } from "../../webkit/csrSlide";
30
31
  import { NativeSplash } from "../../webkit/nativeSplash";
31
32
  import { NativeUpdates } from "../../webkit/nativeUpdates";
32
33
  import { RenderLayer } from "../../webkit/RenderLayer";
@@ -462,7 +463,7 @@ const CSRPageContainer = ({ entry, prefix, layoutStyle }: CSRPageContainerProps)
462
463
 
463
464
  const isLeftInPlace =
464
465
  pageType === "prev" &&
465
- currentLocation.pathRoute.pageState.transition === "none" &&
466
+ CsrSlide.motionOf(currentLocation) === "none" &&
466
467
  (csr.phase === "idle" || csr.pendingLocation?.pathRoute.pageState.transition === "none");
467
468
  const activity: PageActivity =
468
469
  pageType === "cached" || (pageType === "prev" && csr.isBackgrounded) || isLeftInPlace ? "hidden" : pageType;
@@ -498,7 +499,7 @@ const CSRPageContainer = ({ entry, prefix, layoutStyle }: CSRPageContainerProps)
498
499
  pageType === "current" && "relative isolate overflow-x-hidden bg-background shadow-inner",
499
500
  (pageType === "prev" || pageType === "pending") &&
500
501
  "pointer-events-none isolate h-screen w-screen overflow-hidden",
501
- pathRoute.pageState.gesture && pageClassName,
502
+ CsrSlide.swipesBack(location) && pageClassName,
502
503
  )}
503
504
  style={page?.contentStyle}
504
505
  pageType={pageType}
@@ -51,6 +51,7 @@ import {
51
51
  } from "react";
52
52
  import { NativeThemeColor } from "../../client/nativeThemeColor";
53
53
  import { readRscRoutePatch, subscribeRscRoutePatch } from "../../client/rscRoutePatch";
54
+ import { CsrSlide } from "../../webkit/csrSlide";
54
55
  import { FrameRootVars } from "../../webkit/FrameRootVars";
55
56
  import { useTransitionStore } from "../../webkit/useTransitionStore";
56
57
  import { getFrameCssVars, isResponsiveFrame } from "./Common";
@@ -206,7 +207,8 @@ export const ClientPathWrapper = ({
206
207
  useLayoutEffect(() => {
207
208
  if (activity === "current") FrameRootVars.mirror(frameCssVars, responsiveFrame);
208
209
  }, [activity, frameCssKey, responsiveFrame]);
209
- const bindProps = bind && pageType !== "pending" && pathRoute.pageState.gesture && gestureEnabled ? bind() : {};
210
+ const swipesBack = location ? CsrSlide.swipesBack(location) : pathRoute.pageState.gesture;
211
+ const bindProps = bind && pageType !== "pending" && swipesBack && gestureEnabled ? bind() : {};
210
212
  useEffect(() => {
211
213
  debugFrame("pathWrapper.mount", { path: pathRoute.path, pageType, href });
212
214
  return () => debugFrame("pathWrapper.unmount", { path: pathRoute.path, pageType, href });
@@ -45,14 +45,35 @@ export class CsrSlide {
45
45
 
46
46
  static #stillEntryId: string | null = null;
47
47
 
48
- static holdStill(kind: "push" | "replace", from: Location, to: Location) {
48
+ static settleMove(kind: "push" | "replace", from: Location, to: Location) {
49
49
  const isStill =
50
50
  kind === "replace" &&
51
51
  from.pathRoute.pageState.transition === "none" &&
52
52
  to.pathRoute.pageState.transition !== "none";
53
53
  CsrSlide.#stillEntryId = isStill ? (to.entryId ?? null) : null;
54
+
55
+ if (kind === "replace" && to.entryId && to.pathRoute.pageState.transition === "none") {
56
+ const motion = CsrSlide.#motionAt(from);
57
+ if (motion.transition === "none") CsrSlide.#motions.delete(to.entryId);
58
+ else CsrSlide.#motions.set(to.entryId, motion);
59
+ }
54
60
  return isStill;
55
61
  }
62
+
63
+ static readonly #motions = new Map<string, Pick<FramePageState, "transition" | "gesture">>();
64
+ static #motionAt({ entryId, pathRoute: { pageState } }: Location) {
65
+ return (
66
+ (entryId && CsrSlide.#motions.get(entryId)) || { transition: pageState.transition, gesture: pageState.gesture }
67
+ );
68
+ }
69
+ /** How an entry moves: its own page's transition, or that of the page it took the place of. */
70
+ static motionOf(location: Location) {
71
+ return CsrSlide.#motionAt(location).transition;
72
+ }
73
+ /** Whether an entry swipes back: its own page's `gesture`, or that of the page it took the place of. */
74
+ static swipesBack(location: Location) {
75
+ return CsrSlide.#motionAt(location).gesture;
76
+ }
56
77
  static isStill(entryId: string | undefined) {
57
78
  return !!entryId && entryId === CsrSlide.#stillEntryId;
58
79
  }
@@ -190,14 +190,11 @@ const useFrameTransitionStart = ({
190
190
  const shouldPrepareFrameTransition = useCallback(
191
191
  (nextHref?: string) => {
192
192
  if (keyboardFrame.visible) return true;
193
- if (!nextHref) return resolvedLocation.pathRoute.pageState.transition !== "none";
193
+ if (!nextHref) return CsrSlide.motionOf(resolvedLocation) !== "none";
194
194
  const nextLocation = getLocation(nextHref);
195
- return (
196
- resolvedLocation.pathRoute.pageState.transition !== "none" ||
197
- nextLocation.pathRoute.pageState.transition !== "none"
198
- );
195
+ return CsrSlide.motionOf(resolvedLocation) !== "none" || nextLocation.pathRoute.pageState.transition !== "none";
199
196
  },
200
- [getLocation, keyboardFrame.visible, resolvedLocation.pathRoute.pageState.transition],
197
+ [getLocation, keyboardFrame.visible, resolvedLocation],
201
198
  );
202
199
  const startFrameTransition = useCallback(async () => {
203
200
  const snapshot = new Map(pageStateByPathRef.current);
@@ -254,7 +251,7 @@ export const useCsrNavigation = (input: CsrNavigationInput) => {
254
251
  ? cached
255
252
  : target;
256
253
  const scrollTop = pageContentRef.current?.scrollTop ?? 0;
257
- const isStill = CsrSlide.holdStill(kind, fromLocation, toLocation);
254
+ const isStill = CsrSlide.settleMove(kind, fromLocation, toLocation);
258
255
  const slides =
259
256
  !isStill &&
260
257
  CsrStack.keyOf(toLocation) !== CsrStack.keyOf(fromLocation) &&
@@ -2,6 +2,7 @@
2
2
  import { router as clientRouter, getAuthToken, type UseCsrTransition } from "akanjs/client";
3
3
  import { useCallback, useEffect, useRef, useState } from "react";
4
4
  import { CsrStack } from "./CsrStack";
5
+ import { CsrSlide } from "./csrSlide";
5
6
  import { type NativeBackProgress, NativeNavigation } from "./nativeNavigation";
6
7
  import { NativeUpdates } from "./nativeUpdates";
7
8
  import type { CsrKeyboard } from "./useCsrKeyboard";
@@ -66,7 +67,7 @@ export const useCsrStackLifecycle = ({
66
67
  backFollow.current = csrTransition;
67
68
  const followBack = useCallback(({ phase, progress }: NativeBackProgress) => {
68
69
  const { transUnit, transUnitRange } = backFollow.current;
69
- const transition = getCurrentLocation().pathRoute.pageState.transition;
70
+ const transition = CsrSlide.motionOf(getCurrentLocation());
70
71
  if (transition === "none" || history.current.idx === 0 || nativeBackStateRef.current.keyboardVisible) return;
71
72
  const [hidden, shown] = transUnitRange;
72
73
  if (phase === "cancelled") {
@@ -18,6 +18,7 @@ import {
18
18
  import { isNativeApp, openExternalUrl } from "akanjs/client/native";
19
19
  import { useCallback, useMemo, useState } from "react";
20
20
  import { CsrRefresh } from "./csrRefresh";
21
+ import { CsrSlide } from "./csrSlide";
21
22
  import { NativeNavigation } from "./nativeNavigation";
22
23
  import { useCsrKeyboard } from "./useCsrKeyboard";
23
24
  import { type CsrLocationState, useCsrLocationState } from "./useCsrLocationState";
@@ -93,7 +94,7 @@ const useCsrRouter = ({
93
94
 
94
95
  broadcastSyncNavigation("back", getSyncRouteHref(targetLocation));
95
96
  if (shouldPrepareFrameTransition()) await startFrameTransition();
96
- await playBack(location.pathRoute.pageState.transition);
97
+ await playBack(CsrSlide.motionOf(location));
97
98
  const scrollTop = pageContentRef.current?.scrollTop ?? 0;
98
99
  setHistoryBack({ type: "back", location, scrollTop, scrollToTop });
99
100
  settle(getPrevLocation());
@@ -142,7 +143,7 @@ const useCsrRouter = ({
142
143
  } else {
143
144
  const location = getCurrentLocation();
144
145
  if (shouldPrepareFrameTransition(href)) await startFrameTransition();
145
- if (!isUaAnimated) await playBack(location.pathRoute.pageState.transition);
146
+ if (!isUaAnimated) await playBack(CsrSlide.motionOf(location));
146
147
  setHistoryBack({ type: "popBack", location, scrollTop });
147
148
  settle(getPrevLocation());
148
149
  }
@@ -246,7 +247,7 @@ export const useCsrValues = (rootRouteGuide: RouteGuide, pathRoutes: PathRoute[]
246
247
  keyboardFrame.animationDuration,
247
248
  keyboardFrame.animationEasing,
248
249
  ]);
249
- const csrTransition = useCsrTransitionMap[resolvedLocation.pathRoute.pageState.transition];
250
+ const csrTransition = useCsrTransitionMap[CsrSlide.motionOf(resolvedLocation)];
250
251
  const page: PageTransition | null =
251
252
  contentResizeStyle && csrTransition.page
252
253
  ? { ...csrTransition.page, contentStyle: { ...csrTransition.page.contentStyle, ...contentResizeStyle } }