akanjs 3.3.0-rc.43 → 3.3.0-rc.45
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 +1 -1
- package/types/ui/recipe/badgeRecipe.d.ts +2 -2
- package/types/ui/recipe/buttonRecipe.d.ts +2 -2
- package/types/ui/recipe/inputRecipe.d.ts +2 -2
- package/types/webkit/csrSlide.d.ts +3 -1
- package/types/webkit/scrollerTakesDrag.d.ts +1 -0
- package/types/webkit/useCsrRefs.d.ts +1 -1
- package/ui/DragAction.tsx +9 -4
- package/webkit/csrSlide.ts +15 -1
- package/webkit/scrollerTakesDrag.ts +3 -0
- package/webkit/useCsrNavigation.ts +3 -0
- package/webkit/useCsrTransitions.ts +5 -4
package/package.json
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
export declare const badgeRecipe: (variants?: Omit<({
|
|
3
3
|
size?: "lg" | "md" | "sm" | "xs" | undefined;
|
|
4
4
|
outline?: boolean | undefined;
|
|
5
|
-
variant?: "
|
|
5
|
+
variant?: "default" | "error" | "info" | "warning" | "success" | "primary" | "outline" | "secondary" | "accent" | "neutral" | undefined;
|
|
6
6
|
} & {
|
|
7
7
|
class?: import("tailwind-variants/lite").ClassValue;
|
|
8
8
|
className?: never;
|
|
9
9
|
}) | ({
|
|
10
10
|
size?: "lg" | "md" | "sm" | "xs" | undefined;
|
|
11
11
|
outline?: boolean | undefined;
|
|
12
|
-
variant?: "
|
|
12
|
+
variant?: "default" | "error" | "info" | "warning" | "success" | "primary" | "outline" | "secondary" | "accent" | "neutral" | undefined;
|
|
13
13
|
} & {
|
|
14
14
|
class?: never;
|
|
15
15
|
className?: import("tailwind-variants/lite").ClassValue;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export declare const buttonRecipe: (variants?: Omit<({
|
|
3
3
|
size?: "xl" | "lg" | "md" | "sm" | "xs" | "icon" | undefined;
|
|
4
4
|
outline?: boolean | undefined;
|
|
5
|
-
variant?: "
|
|
5
|
+
variant?: "default" | "link" | "info" | "warning" | "success" | "destructive" | "primary" | "outline" | "secondary" | "accent" | "neutral" | "ghost" | undefined;
|
|
6
6
|
shape?: "default" | "circle" | "square" | undefined;
|
|
7
7
|
} & {
|
|
8
8
|
class?: import("tailwind-variants/lite").ClassValue;
|
|
@@ -10,7 +10,7 @@ export declare const buttonRecipe: (variants?: Omit<({
|
|
|
10
10
|
}) | ({
|
|
11
11
|
size?: "xl" | "lg" | "md" | "sm" | "xs" | "icon" | undefined;
|
|
12
12
|
outline?: boolean | undefined;
|
|
13
|
-
variant?: "
|
|
13
|
+
variant?: "default" | "link" | "info" | "warning" | "success" | "destructive" | "primary" | "outline" | "secondary" | "accent" | "neutral" | "ghost" | undefined;
|
|
14
14
|
shape?: "default" | "circle" | "square" | undefined;
|
|
15
15
|
} & {
|
|
16
16
|
class?: never;
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
export declare const inputRecipe: (variants?: Omit<({
|
|
3
3
|
kind?: "field" | "select" | "area" | undefined;
|
|
4
4
|
size?: "xl" | "lg" | "md" | "sm" | "xs" | undefined;
|
|
5
|
-
tone?: "
|
|
5
|
+
tone?: "default" | "error" | "primary" | undefined;
|
|
6
6
|
} & {
|
|
7
7
|
class?: import("tailwind-variants/lite").ClassValue;
|
|
8
8
|
className?: never;
|
|
9
9
|
}) | ({
|
|
10
10
|
kind?: "field" | "select" | "area" | undefined;
|
|
11
11
|
size?: "xl" | "lg" | "md" | "sm" | "xs" | undefined;
|
|
12
|
-
tone?: "
|
|
12
|
+
tone?: "default" | "error" | "primary" | undefined;
|
|
13
13
|
} & {
|
|
14
14
|
class?: never;
|
|
15
15
|
className?: import("tailwind-variants/lite").ClassValue;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PathRoute } from "akanjs/client";
|
|
1
|
+
import type { Location, PathRoute } from "akanjs/client";
|
|
2
2
|
type FramePageState = PathRoute["pageState"];
|
|
3
3
|
type Keyframe = Record<string, string>;
|
|
4
4
|
export interface CsrSlideFrame {
|
|
@@ -19,6 +19,8 @@ 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;
|
|
23
|
+
static isStill(entryId: string | undefined): boolean;
|
|
22
24
|
static play(frame: CsrSlideFrame, { fromUnit, toUnit, duration, keep }: CsrSlidePlay): CsrSlide | null;
|
|
23
25
|
/** What each part's style is with the page `unit` px from its place: 0 shown, the frame's width gone right. */
|
|
24
26
|
static partsAt({ width, height, pageState, prevPageState }: CsrSlideFrame, unit: number): Record<string, Keyframe>;
|
|
@@ -17,8 +17,8 @@ export declare const useCsrRefs: () => {
|
|
|
17
17
|
pageContentRef: import("react").RefObject<HTMLDivElement | null>;
|
|
18
18
|
prevPageContentRef: import("react").RefObject<HTMLDivElement | null>;
|
|
19
19
|
onBack: import("react").RefObject<{
|
|
20
|
-
stack?: (() => Promise<void>) | undefined;
|
|
21
20
|
none?: (() => Promise<void>) | undefined;
|
|
21
|
+
stack?: (() => Promise<void>) | undefined;
|
|
22
22
|
fade?: (() => Promise<void>) | undefined;
|
|
23
23
|
bottomUp?: (() => Promise<void>) | undefined;
|
|
24
24
|
scaleOut?: (() => Promise<void>) | undefined;
|
package/ui/DragAction.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import type { ReactDOMAttributes } from "@use-gesture/react/dist/declarations/sr
|
|
|
5
5
|
import { cn } from "akanjs/client";
|
|
6
6
|
import { type ReactNode, useContext, useRef } from "react";
|
|
7
7
|
import { sharedContext } from "../client/sharedContext";
|
|
8
|
+
import { SWIPE_BACK_EDGE_PX } from "../webkit/scrollerTakesDrag";
|
|
8
9
|
import { animated } from "./animated";
|
|
9
10
|
|
|
10
11
|
interface DragActionContextType {
|
|
@@ -53,8 +54,12 @@ export const DragAction = ({ className, children, onClick, onLeft, onRight }: Dr
|
|
|
53
54
|
if (!action.current) onClick?.();
|
|
54
55
|
action.current = null;
|
|
55
56
|
},
|
|
56
|
-
onDrag: ({ down, movement: [mx],
|
|
57
|
+
onDrag: ({ down, movement: [mx], initial: [ix], cancel }) => {
|
|
57
58
|
if (!ref.current) return;
|
|
59
|
+
if (ix <= SWIPE_BACK_EDGE_PX) {
|
|
60
|
+
cancel();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
58
63
|
void api.start({
|
|
59
64
|
x: down ? mx : 0,
|
|
60
65
|
leftOpacity: mx > 0 && down ? mx / ref.current.clientWidth : 0,
|
|
@@ -64,8 +69,8 @@ export const DragAction = ({ className, children, onClick, onLeft, onRight }: Dr
|
|
|
64
69
|
});
|
|
65
70
|
action.current = mx > 0 ? "left" : mx < 0 ? "right" : null;
|
|
66
71
|
},
|
|
67
|
-
onDragEnd: ({ movement: [mx] }) => {
|
|
68
|
-
if (!ref.current) return;
|
|
72
|
+
onDragEnd: ({ movement: [mx], initial: [ix] }) => {
|
|
73
|
+
if (!ref.current || ix <= SWIPE_BACK_EDGE_PX) return;
|
|
69
74
|
void api.start({ x: 0, leftOpacity: 0, leftWidth: 0, rightOpacity: 0, rightWidth: 0 });
|
|
70
75
|
if (mx > ref.current.clientWidth / 2 && onLeft) onLeft();
|
|
71
76
|
if (mx < -ref.current.clientWidth / 2 && onRight) onRight();
|
|
@@ -75,7 +80,7 @@ export const DragAction = ({ className, children, onClick, onLeft, onRight }: Dr
|
|
|
75
80
|
);
|
|
76
81
|
return (
|
|
77
82
|
<DragActionContext.Provider value={{ bind, x, y, leftOpacity, leftWidth, rightOpacity, rightWidth, onClick }}>
|
|
78
|
-
<div ref={ref} className={cn("relative overflow-x-hidden", className)}>
|
|
83
|
+
<div ref={ref} data-akan-drag="x" className={cn("relative overflow-x-hidden", className)}>
|
|
79
84
|
{children}
|
|
80
85
|
</div>
|
|
81
86
|
</DragActionContext.Provider>
|
package/webkit/csrSlide.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import type { PathRoute } from "akanjs/client";
|
|
2
|
+
import type { Location, PathRoute } from "akanjs/client";
|
|
3
3
|
|
|
4
4
|
type FramePageState = PathRoute["pageState"];
|
|
5
5
|
type Keyframe = Record<string, string>;
|
|
@@ -43,6 +43,20 @@ export class CsrSlide {
|
|
|
43
43
|
return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
static #stillEntryId: string | null = null;
|
|
47
|
+
|
|
48
|
+
static holdStill(kind: "push" | "replace", from: Location, to: Location) {
|
|
49
|
+
const isStill =
|
|
50
|
+
kind === "replace" &&
|
|
51
|
+
from.pathRoute.pageState.transition === "none" &&
|
|
52
|
+
to.pathRoute.pageState.transition !== "none";
|
|
53
|
+
CsrSlide.#stillEntryId = isStill ? (to.entryId ?? null) : null;
|
|
54
|
+
return isStill;
|
|
55
|
+
}
|
|
56
|
+
static isStill(entryId: string | undefined) {
|
|
57
|
+
return !!entryId && entryId === CsrSlide.#stillEntryId;
|
|
58
|
+
}
|
|
59
|
+
|
|
46
60
|
static play(frame: CsrSlideFrame, { fromUnit, toUnit, duration, keep = false }: CsrSlidePlay): CsrSlide | null {
|
|
47
61
|
if (!CsrSlide.supported || duration <= 0) return null;
|
|
48
62
|
const from = CsrSlide.partsAt(frame, fromUnit);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
type DragAxis = "x" | "y";
|
|
2
2
|
|
|
3
|
+
export const SWIPE_BACK_EDGE_PX = 24;
|
|
4
|
+
|
|
3
5
|
const isScrollable = (overflow: string) => overflow === "auto" || overflow === "scroll";
|
|
4
6
|
|
|
5
7
|
const isReversed = (style: CSSStyleDeclaration, axis: DragAxis) =>
|
|
@@ -8,6 +10,7 @@ const isReversed = (style: CSSStyleDeclaration, axis: DragAxis) =>
|
|
|
8
10
|
: (style.flexDirection === "row-reverse") !== (style.direction === "rtl");
|
|
9
11
|
|
|
10
12
|
const takes = (node: Element, style: CSSStyleDeclaration, axis: DragAxis, movement: number) => {
|
|
13
|
+
if (node.getAttribute("data-akan-drag") === axis) return true;
|
|
11
14
|
if (!isScrollable(axis === "x" ? style.overflowX : style.overflowY)) return false;
|
|
12
15
|
const span = axis === "x" ? node.scrollWidth - node.clientWidth : node.scrollHeight - node.clientHeight;
|
|
13
16
|
if (span < 1) return false;
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { useCallback } from "react";
|
|
12
12
|
import { CsrStack } from "./CsrStack";
|
|
13
13
|
import { CsrPageReadiness } from "./csrPageReadiness";
|
|
14
|
+
import { CsrSlide } from "./csrSlide";
|
|
14
15
|
import type { CsrKeyboard } from "./useCsrKeyboard";
|
|
15
16
|
import type { CsrLocationState } from "./useCsrLocationState";
|
|
16
17
|
import { type CsrRefs, currentRouter } from "./useCsrRefs";
|
|
@@ -257,7 +258,9 @@ export const useCsrNavigation = (input: CsrNavigationInput) => {
|
|
|
257
258
|
? cached
|
|
258
259
|
: target;
|
|
259
260
|
const scrollTop = pageContentRef.current?.scrollTop ?? 0;
|
|
261
|
+
const isStill = CsrSlide.holdStill(kind, fromLocation, toLocation);
|
|
260
262
|
const slides =
|
|
263
|
+
!isStill &&
|
|
261
264
|
CsrStack.keyOf(toLocation) !== CsrStack.keyOf(fromLocation) &&
|
|
262
265
|
shouldPrepareFrameTransition(href) &&
|
|
263
266
|
toLocation.pathRoute.pageState.transition !== "none";
|
|
@@ -14,7 +14,7 @@ import { clamp } from "akanjs/common";
|
|
|
14
14
|
import { type RefObject, useCallback, useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
15
15
|
import { CsrSlide, type CsrSlideFrame } from "./csrSlide";
|
|
16
16
|
import { isDragLift } from "./isDragLift";
|
|
17
|
-
import { scrollerTakesDrag } from "./scrollerTakesDrag";
|
|
17
|
+
import { SWIPE_BACK_EDGE_PX, scrollerTakesDrag } from "./scrollerTakesDrag";
|
|
18
18
|
import { STACK_TRANSITION_DURATION_MS } from "./useFrameRuntime";
|
|
19
19
|
|
|
20
20
|
const linearEasing = (t: number) => t;
|
|
@@ -162,7 +162,7 @@ const usePlayOnForward = (
|
|
|
162
162
|
) => {
|
|
163
163
|
|
|
164
164
|
useLayoutEffect(() => {
|
|
165
|
-
if (history.current.type === "forward") {
|
|
165
|
+
if (history.current.type === "forward" && !CsrSlide.isStill(location.entryId)) {
|
|
166
166
|
void transUnit.start(transUnitRange[0], { immediate: true });
|
|
167
167
|
void transUnit.start(transUnitRange[1], { config });
|
|
168
168
|
} else void transUnit.start(transUnitRange[1], { immediate: true });
|
|
@@ -409,7 +409,7 @@ const useStackSlide = (
|
|
|
409
409
|
cancelSlide();
|
|
410
410
|
|
|
411
411
|
const isStack = frameRef.current.pageState.transition === "stack";
|
|
412
|
-
if (history.current.type !== "forward" || CsrSlide.isCalm || !isStack) {
|
|
412
|
+
if (history.current.type !== "forward" || CsrSlide.isCalm || !isStack || CsrSlide.isStill(location.entryId)) {
|
|
413
413
|
void transUnit.start(transUnitRange[1], { immediate: true });
|
|
414
414
|
return;
|
|
415
415
|
}
|
|
@@ -486,7 +486,8 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
486
486
|
const absY = Math.abs(my);
|
|
487
487
|
const isVertical = absY >= GESTURE_INTENT_THRESHOLD && absY > absX * GESTURE_AXIS_LOCK_RATIO;
|
|
488
488
|
const isHorizontal = absX >= GESTURE_INTENT_THRESHOLD && absX > absY * GESTURE_AXIS_LOCK_RATIO;
|
|
489
|
-
|
|
489
|
+
const yields = ix > SWIPE_BACK_EDGE_PX && scrollerTakesDrag(target, pageContentRef.current, "x", mx);
|
|
490
|
+
if (isVertical || (isHorizontal && yields)) {
|
|
490
491
|
gestureIntent.current = "scroll";
|
|
491
492
|
void transUnit.start(transUnitRange[1], { immediate: true });
|
|
492
493
|
cancel();
|