@react-hive/honey-layout 15.0.0 → 16.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,164 +0,0 @@
1
- interface UseHoneyRafFrameContext {
2
- /**
3
- * Immediately terminates the active `requestAnimationFrame` loop.
4
- *
5
- * This method is **safe to call synchronously from within the frame handler**
6
- * and is the **recommended mechanism** for ending frame-driven processes based on runtime conditions.
7
- *
8
- * Typical use cases:
9
- * - Inertia or momentum decay reaching a threshold
10
- * - Animation or transition completion
11
- * - Time- or state-based termination conditions
12
- */
13
- stop: () => void;
14
- }
15
- /**
16
- * Function invoked on every animation frame while the RAF loop is active.
17
- *
18
- * The handler is expected to be **side-effect driven** and may:
19
- * - Mutate refs
20
- * - Update React state
21
- * - Stop the RAF loop via `context.stop()`
22
- *
23
- * ⚠️ Referential stability
24
- * This handler **must be wrapped in `useCallback`** to avoid unnecessary
25
- * re-bindings and to ensure predictable behavior across renders.
26
- *
27
- * @param deltaTimeMs - Time delta in milliseconds since the previous frame.
28
- * This value is clamped to `maxDeltaMs` to prevent large
29
- * time steps caused by tab backgrounding, visibility changes,
30
- * or browser throttling.
31
- *
32
- * @param context - RAF lifecycle control context. See {@link UseHoneyRafFrameContext}.
33
- */
34
- export type UseHoneyRafOnFrameHandler = (deltaTimeMs: number, context: UseHoneyRafFrameContext) => void;
35
- /**
36
- * Configuration options for {@link useHoneyRafLoop}.
37
- */
38
- interface UseHoneyRafLoopOptions {
39
- /**
40
- * Automatically start the RAF loop on mount.
41
- *
42
- * This is useful for continuous loops (e.g. visualizers),
43
- * but should generally be disabled for gesture- or intent-driven animations.
44
- *
45
- * @default false
46
- */
47
- autoStart?: boolean;
48
- /**
49
- * Whether the RAF loop should automatically resume when the
50
- * document becomes visible again after being hidden.
51
- *
52
- * ⚠️ Important:
53
- * - Visibility changes will ALWAYS stop the RAF loop
54
- * - Resuming is **opt-in** and never happens implicitly
55
- *
56
- * This option should only be enabled for truly continuous
57
- * systems (e.g. game loops, live visualizations).
58
- *
59
- * It is intentionally disabled by default to avoid restarting
60
- * gesture-driven or state-sensitive animations with stale data.
61
- *
62
- * Requires `autoStart` to be enabled.
63
- *
64
- * @default false
65
- */
66
- resumeOnVisibility?: boolean;
67
- /**
68
- * Maximum allowed delta time between frames.
69
- *
70
- * This prevents physics, inertia, or animation logic from receiving large
71
- * time steps after backgrounding, tab switches, or frame drops.
72
- *
73
- * @default 32
74
- */
75
- maxDeltaMs?: number;
76
- /**
77
- * Optional error handler invoked when the RAF callback throws.
78
- *
79
- * When an error occurs:
80
- * - The RAF loop is immediately stopped
81
- * - `isRafLoopRunning` is set to `false`
82
- * - The error is passed to this handler
83
- *
84
- * @default undefined
85
- */
86
- onError?: (error: unknown) => void;
87
- }
88
- /**
89
- * Public control API returned by {@link useHoneyRafLoop}.
90
- */
91
- export interface HoneyRafLoopApi {
92
- /**
93
- * Indicates whether the RAF loop is currently running.
94
- */
95
- isRunning: boolean;
96
- /**
97
- * Starts the RAF loop.
98
- *
99
- * If the loop is already running, this call is ignored.
100
- */
101
- start: () => void;
102
- /**
103
- * Stops the RAF loop immediately.
104
- *
105
- * This method is safe to call:
106
- * - From user code
107
- * - From within the RAF frame handler
108
- */
109
- stop: () => void;
110
- }
111
- /**
112
- * A hook for running a controlled `requestAnimationFrame` loop.
113
- *
114
- * Features:
115
- * - Explicit RAF lifecycle control (`start` / `stop`)
116
- * - Delta time calculation with frame clamping
117
- * - Automatic cleanup on unmounting
118
- * - Conservative handling of tab visibility changes (mobile-safe)
119
- * - Safe error handling (stops loop on exception)
120
- *
121
- * Visibility behavior:
122
- * - The RAF loop is always stopped when the document becomes hidden
123
- * - Automatic resume is disabled by default and must be explicitly enabled
124
- *
125
- * This hook is designed for gesture handling, inertia, physics simulations,
126
- * and animation loops that must not trigger React re-renders on every frame.
127
- *
128
- * @param onFrame - Function invoked on each animation frame.
129
- * @param options - Optional configuration for the RAF loop.
130
- *
131
- * @returns Control helpers and RAF loop state.
132
- *
133
- * @example
134
- * ```ts
135
- * // Gesture-driven inertia (recommended usage)
136
- * // The RAF loop stops itself when motion decays.
137
- *
138
- * const velocityRef = useRef({ x: 12, y: 4 });
139
- *
140
- * const onFrame = useCallback<HoneyRafOnFrameHandler>(
141
- * (dtMs, { stop }) => {
142
- * velocityRef.current.x *= 0.94;
143
- * velocityRef.current.y *= 0.94;
144
- *
145
- * setPosition(p => ({
146
- * x: p.x + velocityRef.current.x,
147
- * y: p.y + velocityRef.current.y,
148
- * }));
149
- *
150
- * if (
151
- * Math.abs(velocityRef.current.x) < 0.1 &&
152
- * Math.abs(velocityRef.current.y) < 0.1
153
- * ) {
154
- * stop(); // terminate RAF loop
155
- * }
156
- * },
157
- * [],
158
- * );
159
- *
160
- * useHoneyRafLoop(onFrame);
161
- * ```
162
- */
163
- export declare const useHoneyRafLoop: (onFrame: UseHoneyRafOnFrameHandler, { autoStart, resumeOnVisibility, maxDeltaMs, onError, }?: UseHoneyRafLoopOptions) => HoneyRafLoopApi;
164
- export {};
@@ -1,45 +0,0 @@
1
- export type UseHoneyResizeHandler = () => void;
2
- interface UseHoneyResizeOptions {
3
- /**
4
- * Whether to invoke the resize handler immediately on mount.
5
- *
6
- * Useful when initial layout measurements should be performed
7
- * before any resize events occur.
8
- *
9
- * @default false
10
- */
11
- invokeOnMount?: boolean;
12
- /**
13
- * Throttle delay (in milliseconds) applied to the resize handler.
14
- *
15
- * When greater than `0`, the handler will be throttled using
16
- * `lodash.throttle` to reduce invocation frequency.
17
- *
18
- * @default 0
19
- */
20
- throttleTime?: number;
21
- /**
22
- * Enables or disables the resize listener.
23
- *
24
- * @default true
25
- */
26
- enabled?: boolean;
27
- }
28
- /**
29
- * A hook that subscribes to the window `resize` event and invokes a handler function in response.
30
- *
31
- * The handler can be optionally throttled to limit execution frequency, which is useful
32
- * for expensive layout calculations or DOM measurements.
33
- *
34
- * @example
35
- * ```ts
36
- * useHoneyResize(() => {
37
- * console.log('Window resized');
38
- * }, { throttleTime: 200 });
39
- * ```
40
- *
41
- * @param handler - Callback invoked when the window is resized.
42
- * @param options - Configuration options controlling invocation timing and performance.
43
- */
44
- export declare const useHoneyResize: (handler: UseHoneyResizeHandler, { invokeOnMount, throttleTime, enabled }?: UseHoneyResizeOptions) => void;
45
- export {};
@@ -1,19 +0,0 @@
1
- import type { UseHoneySyntheticScrollOptions } from './use-honey-synthetic-scroll';
2
- /**
3
- * Enables synthetic horizontal (X-axis) scrolling for a container element
4
- * using pointer-based drag interactions.
5
- *
6
- * This is a convenience wrapper around {@link useHoneySyntheticScroll} with
7
- * the axis fixed to `'x'`.
8
- *
9
- * All behavior, boundaries, and lifecycle guarantees are identical to the
10
- * base hook, but limited to horizontal movement only.
11
- *
12
- * @template Element - The HTML element type of the scrollable container.
13
- *
14
- * @param options - Configuration options forwarded to
15
- * {@link useHoneySyntheticScroll}, excluding the `axis` option.
16
- *
17
- * @returns A ref that must be attached to the scrollable container element.
18
- */
19
- export declare const useHoneySyntheticScrollX: <Element extends HTMLElement>(options?: Omit<UseHoneySyntheticScrollOptions<Element>, "axis">) => import("react").RefObject<import("..").Nullable<Element>>;
@@ -1,19 +0,0 @@
1
- import type { UseHoneySyntheticScrollOptions } from './use-honey-synthetic-scroll';
2
- /**
3
- * Enables synthetic vertical (Y-axis) scrolling for a container element
4
- * using pointer-based drag interactions.
5
- *
6
- * This is a convenience wrapper around {@link useHoneySyntheticScroll} with
7
- * the axis fixed to `'y'`.
8
- *
9
- * All behavior, boundaries, and lifecycle guarantees are identical to the
10
- * base hook, but limited to vertical movement only.
11
- *
12
- * @template Element - The HTML element type of the scrollable container.
13
- *
14
- * @param options - Configuration options forwarded to
15
- * {@link useHoneySyntheticScroll}, excluding the `axis` option.
16
- *
17
- * @returns A ref that must be attached to the scrollable container element.
18
- */
19
- export declare const useHoneySyntheticScrollY: <Element extends HTMLElement>(options?: Omit<UseHoneySyntheticScrollOptions<Element>, "axis">) => import("react").RefObject<import("..").Nullable<Element>>;
@@ -1,143 +0,0 @@
1
- import type { RefObject } from 'react';
2
- import type { Axis } from '@react-hive/honey-utils';
3
- import type { Nullable } from '../types';
4
- import type { UseHoneyDragHandlers } from './use-honey-drag';
5
- interface ResolveAxisTranslateOptions {
6
- /**
7
- * Drag delta for the axis (deltaX or deltaY).
8
- */
9
- delta: number;
10
- /**
11
- * Current translate value for the axis.
12
- */
13
- translate: number;
14
- /**
15
- * Visible container size for the axis (width or height).
16
- */
17
- containerSize: number;
18
- /**
19
- * Overflow size for the axis.
20
- */
21
- overflowSize: number;
22
- /**
23
- * Overscroll window percentage.
24
- */
25
- overscrollPct: number;
26
- }
27
- export declare const resolveAxisTranslate: ({ delta, translate, containerSize, overflowSize, overscrollPct, }: ResolveAxisTranslateOptions) => Nullable<number>;
28
- export interface UseHoneySyntheticScrollOptions<Element extends HTMLElement> extends Pick<UseHoneyDragHandlers<Element>, 'onStartDrag' | 'onEndDrag'> {
29
- /**
30
- * Axis along which synthetic scrolling is enabled.
31
- *
32
- * - `'x'` — horizontal only
33
- * - `'y'` — vertical only
34
- * - `'both'` — horizontal and vertical
35
- *
36
- * @default 'both'
37
- */
38
- axis?: Axis;
39
- /**
40
- * Percentage of the container size used as an overscroll buffer
41
- * on each enabled axis.
42
- *
43
- * This allows limited dragging beyond the natural content bounds
44
- * before movement is clamped.
45
- *
46
- * A value of `0` disables overscroll entirely.
47
- *
48
- * @default 0
49
- */
50
- overscrollPct?: number;
51
- /**
52
- * Controls how the hook applies scroll-related interaction styles
53
- * (`touch-action` and `overscroll-behavior`) to the container.
54
- *
55
- * Synthetic scrolling often requires restricting native browser scrolling
56
- * behavior to ensure consistent drag and wheel handling.
57
- *
58
- * However, in some embedded layouts (such as carousels placed inside a
59
- * vertically scrollable page), applying these styles can unintentionally
60
- * block natural page scrolling.
61
- *
62
- * ### Modes
63
- * - `'default'` — Applies restrictive interaction styles:
64
- * - `overscroll-behavior: contain`
65
- * - Axis-aware `touch-action` (`pan-y`, `pan-x`, or `none`)
66
- *
67
- * Recommended for standalone synthetic scroll containers.
68
- *
69
- * - `'embedded'` — Does not apply any interaction-blocking styles.
70
- *
71
- * Recommended when the container is integrated into another scrollable
72
- * context (e.g. horizontal carousel inside a page), where native scroll
73
- * chaining must remain intact.
74
- *
75
- * @default 'default'
76
- */
77
- scrollMode?: 'default' | 'embedded';
78
- /**
79
- * Whether to clear any applied translation transforms when the window resizes.
80
- *
81
- * Useful to keep the layout state consistent after dimension changes.
82
- *
83
- * @default true
84
- */
85
- resetOnResize?: boolean;
86
- /**
87
- * Enables synthetic scrolling driven by pointer-based scroll input,
88
- * such as mouse wheels and trackpads.
89
- *
90
- * When enabled, scroll input is intercepted and converted into bounded
91
- * translation using the same logic as drag gestures.
92
- *
93
- * When disabled, native scrolling behavior is preserved and no scroll
94
- * input is handled by this hook.
95
- *
96
- * @default true
97
- */
98
- enablePointerScroll?: boolean;
99
- /**
100
- * Master toggle for the synthetic scroll behavior.
101
- *
102
- * When `true`, the hook:
103
- * - Enables drag-based translation via {@link useHoneyDrag}.
104
- * - Optionally resets transforms on resize via {@link useHoneyResize}.
105
- * - Applies overscroll and touch-action styles.
106
- * - Intercepts wheel / trackpad scroll input if {@link enablePointerScroll} is enabled.
107
- *
108
- * When `false`, the hook becomes completely inert:
109
- * - No drag or wheel listeners are attached.
110
- * - No transforms are applied.
111
- * - Native scrolling behavior is preserved.
112
- *
113
- * Useful for conditionally disabling synthetic scrolling
114
- * (e.g. mobile layouts, reduced motion, or feature flags).
115
- *
116
- * @default true
117
- */
118
- enabled?: boolean;
119
- }
120
- /**
121
- * Enables synthetic scrolling for a container using pointer-based drag gestures.
122
- *
123
- * Instead of relying on native scrollbars, this hook translates the container
124
- * using CSS transforms in response to drag input.
125
- *
126
- * ### Key characteristics
127
- * - Dragging is only applied when content overflows the container on a given axis.
128
- * - Movement is clamped within calculated bounds, with optional overscroll allowance.
129
- * - Scroll position is stored purely in `transform: translate(...)`.
130
- * - Active transforms can be automatically cleared on window resize.
131
- *
132
- * ### Internals
133
- * - Uses {@link useHoneyDrag} to track mouse / touch movement.
134
- * - Uses {@link useHoneyResize} to optionally reset scroll state on resize.
135
- *
136
- * @template Element - The HTML element type of the scrollable container.
137
- *
138
- * @param options - Configuration controlling axes, boundaries, and lifecycle behavior.
139
- *
140
- * @returns A ref that must be attached to the scrollable container element.
141
- */
142
- export declare const useHoneySyntheticScroll: <Element extends HTMLElement>({ axis, overscrollPct, onStartDrag, onEndDrag, scrollMode, resetOnResize, enablePointerScroll, enabled, }?: UseHoneySyntheticScrollOptions<Element>) => RefObject<Nullable<Element>>;
143
- export {};
@@ -1,107 +0,0 @@
1
- /**
2
- * Timer operating mode.
3
- *
4
- * - `countdown` — decreases time until it reaches `targetTimeMs`
5
- * - `countup` — increases time until it reaches `targetTimeMs` (if provided)
6
- */
7
- type UseHoneyTimerMode = 'countdown' | 'countup';
8
- type UseHoneyTimerOnEndHandler = () => void;
9
- export interface UseHoneyTimerOptions {
10
- /**
11
- * Initial timer value in milliseconds.
12
- *
13
- * - Countdown: starting time
14
- * - Count-up: initial offset
15
- */
16
- initialTimeMs: number;
17
- /**
18
- * Target time in milliseconds.
19
- *
20
- * - Countdown: usually `0`
21
- * - Count-up: optional upper limit
22
- *
23
- * When reached, the timer stops and `onEnd` is invoked.
24
- *
25
- * @default 0
26
- */
27
- targetTimeMs?: number;
28
- /**
29
- * Direction in which the timer progresses.
30
- *
31
- * @default 'countdown'
32
- */
33
- mode?: UseHoneyTimerMode;
34
- /**
35
- * Whether the timer should automatically start on mount.
36
- *
37
- * @default false
38
- */
39
- autoStart?: boolean;
40
- /**
41
- * Optional callback invoked exactly once when the timer reaches the target time.
42
- */
43
- onEnd?: UseHoneyTimerOnEndHandler;
44
- }
45
- /**
46
- * Public control API returned by {@link useHoneyTimer}.
47
- */
48
- export interface UseHoneyTimerApi {
49
- /**
50
- * Current timer value in milliseconds.
51
- *
52
- * This value updates over time while the timer is running.
53
- */
54
- timeMs: number;
55
- /**
56
- * Indicates whether the timer is currently progressing.
57
- */
58
- isRunning: boolean;
59
- /**
60
- * Starts the timer from `initialTimeMs`, resetting any previous state.
61
- */
62
- start: () => void;
63
- /**
64
- * Pauses the timer while preserving the current time value.
65
- */
66
- pause: () => void;
67
- /**
68
- * Resumes the timer from its current time value.
69
- *
70
- * Has no effect if the timer is already running.
71
- */
72
- resume: () => void;
73
- /**
74
- * Resets the timer to a specific time value.
75
- *
76
- * @param timeMs - Optional new timer value. Defaults to `initialTimeMs`.
77
- */
78
- reset: (timeMs?: number) => void;
79
- }
80
- /**
81
- * A high-precision timer hook built on top of {@link useHoneyRafLoop}.
82
- *
83
- * Features:
84
- * - Frame-accurate time progression using `requestAnimationFrame`
85
- * - Supports countdown and count-up modes
86
- * - Explicit lifecycle control (start / pause / resume / reset)
87
- * - Drift-free timing using delta-based updates
88
- * - Safe completion handling via `onEnd`
89
- *
90
- * Architectural notes:
91
- * - Time progression is handled imperatively via refs to avoid stale closures and unnecessary re-renders.
92
- * - React state is updated only with the derived timer value.
93
- * - RAF lifecycle is fully delegated to `useHoneyRafLoop`.
94
- *
95
- * @example
96
- * ```ts
97
- * const timer = useHoneyTimer({
98
- * initialTimeMs: 10_000,
99
- * targetTimeMs: 0,
100
- * onEnd: () => console.log('Done'),
101
- * });
102
- *
103
- * timer.startTimer();
104
- * ```
105
- */
106
- export declare const useHoneyTimer: ({ initialTimeMs, targetTimeMs, mode, autoStart, onEnd, }: UseHoneyTimerOptions) => UseHoneyTimerApi;
107
- export {};