akanjs 3.3.0-rc.36 → 3.3.0-rc.37

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.36",
3
+ "version": "3.3.0-rc.37",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -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?: "error" | "default" | "info" | "warning" | "success" | "primary" | "outline" | "secondary" | "accent" | "neutral" | undefined;
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?: "error" | "default" | "info" | "warning" | "success" | "primary" | "outline" | "secondary" | "accent" | "neutral" | undefined;
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?: "link" | "default" | "info" | "warning" | "success" | "destructive" | "primary" | "outline" | "secondary" | "accent" | "neutral" | "ghost" | undefined;
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?: "link" | "default" | "info" | "warning" | "success" | "destructive" | "primary" | "outline" | "secondary" | "accent" | "neutral" | "ghost" | undefined;
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?: "error" | "default" | "primary" | undefined;
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?: "error" | "default" | "primary" | undefined;
12
+ tone?: "default" | "error" | "primary" | undefined;
13
13
  } & {
14
14
  class?: never;
15
15
  className?: import("tailwind-variants/lite").ClassValue;
@@ -0,0 +1,3 @@
1
+ type DragAxis = "x" | "y";
2
+ export declare const scrollerTakesDrag: (target: EventTarget | null, frame: Element | null, axis: DragAxis, movement: number) => boolean;
3
+ export {};
@@ -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;
@@ -0,0 +1,31 @@
1
+ type DragAxis = "x" | "y";
2
+
3
+ const isScrollable = (overflow: string) => overflow === "auto" || overflow === "scroll";
4
+
5
+ const isReversed = (style: CSSStyleDeclaration, axis: DragAxis) =>
6
+ axis === "y"
7
+ ? style.flexDirection === "column-reverse"
8
+ : (style.flexDirection === "row-reverse") !== (style.direction === "rtl");
9
+
10
+ const takes = (node: Element, style: CSSStyleDeclaration, axis: DragAxis, movement: number) => {
11
+ if (!isScrollable(axis === "x" ? style.overflowX : style.overflowY)) return false;
12
+ const span = axis === "x" ? node.scrollWidth - node.clientWidth : node.scrollHeight - node.clientHeight;
13
+ if (span < 1) return false;
14
+
15
+ const offset = Math.abs(axis === "x" ? node.scrollLeft : node.scrollTop);
16
+ const fromStart = isReversed(style, axis) ? span - offset : offset;
17
+ return movement > 0 ? fromStart >= 1 : span - fromStart >= 1;
18
+ };
19
+
20
+ export const scrollerTakesDrag = (
21
+ target: EventTarget | null,
22
+ frame: Element | null,
23
+ axis: DragAxis,
24
+ movement: number,
25
+ ) => {
26
+ for (let node = target instanceof Element ? target : null; node; node = node.parentElement) {
27
+ if (takes(node, getComputedStyle(node), axis, movement)) return true;
28
+ if (node === frame) return false;
29
+ }
30
+ return false;
31
+ };
@@ -14,6 +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
18
  import { STACK_TRANSITION_DURATION_MS } from "./useFrameRuntime";
18
19
 
19
20
  const linearEasing = (t: number) => t;
@@ -469,7 +470,7 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
469
470
  const dragOriginRef = useRef(0);
470
471
 
471
472
  const pageBind = useDrag(
472
- ({ first, last, movement: [mx, my], velocity: [vx], direction: [dx], initial: [ix], cancel, event }) => {
473
+ ({ first, last, movement: [mx, my], velocity: [vx], direction: [dx], initial: [ix], cancel, event, target }) => {
473
474
  if (first) {
474
475
  gestureIntent.current = "pending";
475
476
  stackBackConfigRef.current = null;
@@ -483,13 +484,15 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
483
484
  if (gestureIntent.current === "pending") {
484
485
  const absX = Math.abs(mx);
485
486
  const absY = Math.abs(my);
486
- if (absY >= GESTURE_INTENT_THRESHOLD && absY > absX * GESTURE_AXIS_LOCK_RATIO) {
487
+ const isVertical = absY >= GESTURE_INTENT_THRESHOLD && absY > absX * GESTURE_AXIS_LOCK_RATIO;
488
+ const isHorizontal = absX >= GESTURE_INTENT_THRESHOLD && absX > absY * GESTURE_AXIS_LOCK_RATIO;
489
+ if (isVertical || (isHorizontal && scrollerTakesDrag(target, pageContentRef.current, "x", mx))) {
487
490
  gestureIntent.current = "scroll";
488
491
  void transUnit.start(transUnitRange[1], { immediate: true });
489
492
  cancel();
490
493
  return;
491
494
  }
492
- if (absX < GESTURE_INTENT_THRESHOLD || absX <= absY * GESTURE_AXIS_LOCK_RATIO) return;
495
+ if (!isHorizontal) return;
493
496
  gestureIntent.current = "gesture";
494
497
  dragOriginRef.current = holdSlide();
495
498
  lockPageScroll();
@@ -499,6 +502,7 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
499
502
  cancel();
500
503
  return;
501
504
  }
505
+ if (event.cancelable) event.preventDefault();
502
506
  const unit = dragOriginRef.current + mx;
503
507
  if (unit < transUnitRange[1]) void transUnit.start(transUnitRange[1], { immediate: true });
504
508
  else if (unit > transUnitRange[0]) void transUnit.start(transUnitRange[0], { immediate: true });
@@ -521,8 +525,8 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
521
525
  });
522
526
  }
523
527
  },
524
-
525
- { filterTaps: true, pointer: { capture: false } },
528
+
529
+ { filterTaps: true, pointer: { touch: true, capture: false }, eventOptions: { passive: false } },
526
530
  );
527
531
 
528
532
  return {
@@ -573,7 +577,7 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
573
577
  };
574
578
 
575
579
  const useBottomUpTrans = (routeState: RouteState): UseCsrTransition => {
576
- const { clientHeight, location, prevLocation, onBack } = routeState;
580
+ const { clientHeight, location, prevLocation, onBack, pageContentRef } = routeState;
577
581
  const spring = useSlideSpring(clientHeight);
578
582
  const { transUnit, transUnitRange, transProgress } = spring;
579
583
  const initThreshold = useMemo(() => Math.floor(clientHeight / 3), [clientHeight]);
@@ -588,11 +592,12 @@ const useBottomUpTrans = (routeState: RouteState): UseCsrTransition => {
588
592
  usePlayOnForward(spring, routeState, { duration: 220, easing: linearEasing });
589
593
 
590
594
  const pageBind = useDrag(
591
- ({ first, last, movement: [, my], initial: [, iy], cancel, event }) => {
592
- if (iy > initThreshold) {
595
+ ({ first, last, movement: [, my], initial: [, iy], cancel, event, target }) => {
596
+ if (iy > initThreshold || (first && scrollerTakesDrag(target, pageContentRef.current, "y", my))) {
593
597
  cancel();
594
598
  return;
595
599
  }
600
+ if (event.cancelable) event.preventDefault();
596
601
  if (first) void Device.getDevice().hideKeyboard();
597
602
  if (my < transUnitRange[1]) void transUnit.start(transUnitRange[1], { immediate: true });
598
603
  else if (my > transUnitRange[0]) void transUnit.start(transUnitRange[0], { immediate: true });
@@ -605,7 +610,13 @@ const useBottomUpTrans = (routeState: RouteState): UseCsrTransition => {
605
610
  clientRouter.back();
606
611
  void clientRouter.navigation().catch(() => transUnit.start(transUnitRange[1]));
607
612
  },
608
- { axis: "y", filterTaps: true, threshold: 10, pointer: { capture: false } },
613
+ {
614
+ axis: "y",
615
+ filterTaps: true,
616
+ threshold: 10,
617
+ pointer: { touch: true, capture: false },
618
+ eventOptions: { passive: false },
619
+ },
609
620
  );
610
621
 
611
622
  return {