swipefeed 1.0.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.
- package/LICENSE +22 -0
- package/README.md +203 -0
- package/dist/__tests__/SwipeDeck.browser.test.d.ts +1 -0
- package/dist/__tests__/SwipeDeck.gestures.test.d.ts +1 -0
- package/dist/__tests__/SwipeDeck.preload.test.d.ts +1 -0
- package/dist/__tests__/SwipeDeck.props.test.d.ts +1 -0
- package/dist/__tests__/gestures.test.d.ts +1 -0
- package/dist/__tests__/useKeyboard.test.d.ts +1 -0
- package/dist/__tests__/useScrollTo.test.d.ts +1 -0
- package/dist/__tests__/useSwipeDeck.browser.test.d.ts +1 -0
- package/dist/__tests__/useSwipeDeck.callbacks.test.d.ts +1 -0
- package/dist/__tests__/useSwipeDeck.loop.test.d.ts +1 -0
- package/dist/__tests__/useSwipeDeck.test.d.ts +1 -0
- package/dist/__tests__/useSwipeItem.test.d.ts +1 -0
- package/dist/__tests__/useVirtualizer.test.d.ts +1 -0
- package/dist/__tests__/useWheel.continuous.test.d.ts +1 -0
- package/dist/__tests__/useWheel.dampening.test.d.ts +1 -0
- package/dist/__tests__/useWheel.test.d.ts +1 -0
- package/dist/__tests__/useWheel.tracking.test.d.ts +1 -0
- package/dist/__tests__/useWindowSize.test.d.ts +1 -0
- package/dist/__tests__/utils.test.d.ts +1 -0
- package/dist/__tests__/wheel.test.d.ts +1 -0
- package/dist/components/SwipeDeck.d.ts +5 -0
- package/dist/hooks/useGestures.d.ts +32 -0
- package/dist/hooks/useKeyboard.d.ts +18 -0
- package/dist/hooks/useScrollTo.d.ts +9 -0
- package/dist/hooks/useSwipeDeck.d.ts +2 -0
- package/dist/hooks/useSwipeItem.d.ts +3 -0
- package/dist/hooks/useVirtualizer.d.ts +24 -0
- package/dist/hooks/useWheel.d.ts +23 -0
- package/dist/hooks/useWindowSize.d.ts +4 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +907 -0
- package/dist/index.js.map +19 -0
- package/dist/stories/SwipeDeck.stories.d.ts +19 -0
- package/dist/types.d.ts +122 -0
- package/dist/utils/clamp.d.ts +1 -0
- package/dist/utils/debounce.d.ts +4 -0
- package/dist/utils/prefersReducedMotion.d.ts +1 -0
- package/dist/utils/raf.d.ts +5 -0
- package/package.json +95 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Brian Sunter
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# swipefeed
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
[**Documentation**](https://briansunter.github.io/swipefeed/docs/) | [**Live Example**](https://briansunter.github.io/swipefeed/example/)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Headless React primitives for building TikTok/Reels-style swipe feeds. Ships a render-prop component (`SwipeDeck`) and a hook (`useSwipeDeck`) that wire up native scroll-snap, TanStack virtualization, gesture/wheel/keyboard inputs, accessibility, and programmatic controls.
|
|
10
|
+
|
|
11
|
+
## Highlights
|
|
12
|
+
|
|
13
|
+
- Headless: bring your own markup/styles; spread provided props for behavior.
|
|
14
|
+
- Works vertically or horizontally with LTR/RTL awareness.
|
|
15
|
+
- Virtualization via `@tanstack/react-virtual` with auto measurement and overscan tuning.
|
|
16
|
+
- Input support: pointer drag/flick, discrete wheel paging with heavy dampening, keyboard (global or scoped).
|
|
17
|
+
- Controlled or uncontrolled index, loopable navigation, programmatic `prev/next/scrollTo`.
|
|
18
|
+
- Accessibility-first: focusable `role="feed"` viewport, per-item `role="article"`, `aria-label`, `aria-busy`, snap alignment.
|
|
19
|
+
- Reduced-motion aware (`prefers-reduced-motion` uses instant scrolling).
|
|
20
|
+
- End-reached callbacks for infinite loading triggers.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
Using your preferred package manager:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
bun add swipefeed
|
|
28
|
+
# or
|
|
29
|
+
npm install swipefeed
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Peer dependencies: `react@^19`, `react-dom@^19`.
|
|
33
|
+
|
|
34
|
+
## Quick start (component)
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import { SwipeDeck } from "swipefeed";
|
|
38
|
+
|
|
39
|
+
function Feed({ items }) {
|
|
40
|
+
return (
|
|
41
|
+
<SwipeDeck items={items} className="w-full h-screen overflow-hidden">
|
|
42
|
+
{({ item, isActive, props }) => (
|
|
43
|
+
<section
|
|
44
|
+
{...props}
|
|
45
|
+
style={{ height: "100vh" }} // make each slide fill the viewport
|
|
46
|
+
>
|
|
47
|
+
<VideoPlayer video={item} playing={isActive} />
|
|
48
|
+
</section>
|
|
49
|
+
)}
|
|
50
|
+
</SwipeDeck>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quick start (hook)
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import { useSwipeDeck } from "swipefeed";
|
|
59
|
+
|
|
60
|
+
function CustomLayout({ items }) {
|
|
61
|
+
const deck = useSwipeDeck({ items, orientation: "horizontal", direction: "rtl" });
|
|
62
|
+
const viewportProps = deck.getViewportProps();
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div {...viewportProps} style={{ ...viewportProps.style, height: "100vh" }}>
|
|
66
|
+
<div style={{ width: deck.totalSize, position: "relative" }}>
|
|
67
|
+
{deck.virtualItems.map((virtual) => {
|
|
68
|
+
const props = deck.getItemProps(virtual.index);
|
|
69
|
+
return (
|
|
70
|
+
<article key={virtual.key} {...props}>
|
|
71
|
+
{items[virtual.index].title}
|
|
72
|
+
</article>
|
|
73
|
+
);
|
|
74
|
+
})}
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Styling essentials
|
|
82
|
+
|
|
83
|
+
- Give the viewport a fixed height/width (e.g., `h-screen`); items are absolutely positioned with transforms supplied by `getItemProps`.
|
|
84
|
+
- Native scroll-snap is applied for you; keep `overflow: auto` on the viewport (default from `getViewportProps`).
|
|
85
|
+
- For full-screen feeds, ensure `html, body, #root` stretch to 100%.
|
|
86
|
+
|
|
87
|
+
## API reference
|
|
88
|
+
|
|
89
|
+
### `<SwipeDeck>` props
|
|
90
|
+
|
|
91
|
+
Extends `SwipeDeckOptions<T>` plus:
|
|
92
|
+
|
|
93
|
+
- `as`: custom element/component for the viewport (default `"div"`).
|
|
94
|
+
- `children(context)`: render prop; receives `{ item, index, isActive, props }`.
|
|
95
|
+
- `className`, `style`: forwarded to the viewport.
|
|
96
|
+
- `ref`: imperative handle (`SwipeDeckHandle`) with `prev`, `next`, `scrollTo`, `getState`.
|
|
97
|
+
|
|
98
|
+
### `SwipeDeckOptions<T>`
|
|
99
|
+
|
|
100
|
+
- `items` **(required)**: readonly array of items.
|
|
101
|
+
- `orientation`: `"vertical"` (default) | `"horizontal"`.
|
|
102
|
+
- `direction`: `"ltr"` (default) | `"rtl"` (affects horizontal gestures/wheel/keyboard).
|
|
103
|
+
- `defaultIndex`: initial index for uncontrolled mode (default `0`).
|
|
104
|
+
- `index`: controlled index. When set, you must manage updates via `onIndexChange`.
|
|
105
|
+
- `onIndexChange(index, source)`: fires on any navigation. `source` is one of `"user:gesture" | "user:wheel" | "user:keyboard" | "programmatic" | "snap"`.
|
|
106
|
+
- `loop`: wrap navigation at ends (default `false`).
|
|
107
|
+
- `gesture`: `{ threshold, flickVelocity, lockAxis, ignoreWhileAnimating }` (defaults `10`, `0.1`, `true`, `true`).
|
|
108
|
+
- `wheel`: `{ discretePaging, threshold, debounce, cooldown }` (defaults `true`, `100`, `120ms`, `800ms`) with aggressive dampening to prevent multi-item jumps.
|
|
109
|
+
- `keyboard`: `{ enabled, global, bindings }` (default enabled, scoped to viewport). Bindings default to arrows + Home/End + Page keys; RTL flips horizontal intent.
|
|
110
|
+
- `keyboardNavigation`: boolean shorthand to disable keyboard entirely (default `true`).
|
|
111
|
+
- `virtual`: `{ overscan, estimatedSize, getItemKey }` (defaults `5`, auto-measured viewport size, `index` key). Backed by `@tanstack/react-virtual`.
|
|
112
|
+
- `endReachedThreshold`: number of items from ends to trigger `onEndReached` (default `3`).
|
|
113
|
+
- `onEndReached({ distanceFromEnd, direction })`: called when within threshold from start or end.
|
|
114
|
+
- `ariaLabel`: label for the feed (default `"Swipe feed"`).
|
|
115
|
+
- `visibility`: reserved for future visibility strategies (currently unused).
|
|
116
|
+
- `onItemActive`, `onItemInactive`: reserved hooks for future activation callbacks (currently no-ops).
|
|
117
|
+
|
|
118
|
+
### Render context (`children`)
|
|
119
|
+
|
|
120
|
+
- `item`: the data item.
|
|
121
|
+
- `index`: item index.
|
|
122
|
+
- `isActive`: whether the item is currently centered/active.
|
|
123
|
+
- `props`: spread onto your item element (includes refs, transforms, snap styles, data attributes).
|
|
124
|
+
|
|
125
|
+
### Imperative handle (`SwipeDeckHandle`)
|
|
126
|
+
|
|
127
|
+
- `prev()`, `next()`
|
|
128
|
+
- `scrollTo(index, { behavior })`
|
|
129
|
+
- `getState()`: `{ index, isAnimating, canPrev, canNext }`
|
|
130
|
+
|
|
131
|
+
### `useSwipeDeck` return shape
|
|
132
|
+
|
|
133
|
+
- State: `index`, `isAnimating`, `canPrev`, `canNext`, `items`, `orientation`.
|
|
134
|
+
- Actions: `prev()`, `next()`, `scrollTo(index, { behavior })`.
|
|
135
|
+
- Layout: `virtualItems` (offset/size/key/measureElement), `totalSize`.
|
|
136
|
+
- Props helpers: `getViewportProps()`, `getItemProps(index)`.
|
|
137
|
+
|
|
138
|
+
### Helper hook
|
|
139
|
+
|
|
140
|
+
- `useWindowSize()`: throttled window dimensions `{ width, height }`.
|
|
141
|
+
|
|
142
|
+
## Virtualization behavior
|
|
143
|
+
|
|
144
|
+
- Always uses `@tanstack/react-virtual` under the hood for consistent offsets, even for small lists.
|
|
145
|
+
- If `virtual.estimatedSize` is omitted, the viewport is measured via `ResizeObserver` and used as the estimate, keeping slides at viewport size by default.
|
|
146
|
+
- `virtual.getItemKey` lets you provide stable keys (otherwise the index is used).
|
|
147
|
+
- `virtual.overscan` tunes how many items render around the viewport (default `5`).
|
|
148
|
+
|
|
149
|
+
## Input handling
|
|
150
|
+
|
|
151
|
+
- **Gestures**: pointer drag + flick with threshold/velocity detection, axis locking, and optional ignore-during-animation.
|
|
152
|
+
- **Wheel**: discrete paging with direction locking, debounce, cooldown, and delta caps to prevent multi-item jumps on trackpads.
|
|
153
|
+
- **Keyboard**: arrow/Home/End/PageUp/PageDown; can be global or scoped to the viewport; RTL-aware for horizontal decks.
|
|
154
|
+
- **Programmatic**: `scrollTo` chooses `smooth` vs `instant` based on `prefers-reduced-motion`, and temporarily disables snap while animating to avoid fights with CSS snap.
|
|
155
|
+
|
|
156
|
+
## Accessibility
|
|
157
|
+
|
|
158
|
+
- Viewport: `role="feed"`, `aria-label`, `aria-busy` while animating, focusable (`tabIndex=0`), native scroll-snap, `touch-action` set per axis.
|
|
159
|
+
- Items: `role="article"` with `aria-label` that includes index/length; snap alignment applied on each item.
|
|
160
|
+
- RTL-aware keyboard/wheel for horizontal feeds.
|
|
161
|
+
|
|
162
|
+
## End reached & looping
|
|
163
|
+
|
|
164
|
+
- `onEndReached` fires both near the start and near the end when within `endReachedThreshold` items.
|
|
165
|
+
- `loop` wraps navigation for gestures, wheel, keyboard, and programmatic calls.
|
|
166
|
+
|
|
167
|
+
## Example app
|
|
168
|
+
|
|
169
|
+
A TikTok-style vertical feed using YouTube iframes lives in `example/`.
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
bun install # installs root + workspace deps
|
|
173
|
+
bun run build # optional: build the library once
|
|
174
|
+
cd example
|
|
175
|
+
bun run dev # starts Vite on http://localhost:5173
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Key bits: render prop usage, global keyboard navigation, gesture swipe, mute button overlay, and custom chrome.
|
|
179
|
+
|
|
180
|
+
## Scripts (root)
|
|
181
|
+
|
|
182
|
+
- `bun run build` – bundle `src/` to `dist/` with sourcemaps.
|
|
183
|
+
- `bun run docs:api` – generate markdown API docs in `docs/api`.
|
|
184
|
+
- `bun run docs:site` – generate HTML TypeDoc site to `site/docs` (default theme).
|
|
185
|
+
- `bun run example:build:site` – build the Vite example with `base=/example/`.
|
|
186
|
+
- `bun run site:prepare` – rebuild docs+example into `site/` for GitHub Pages.
|
|
187
|
+
- `bun run test` – Vitest (jsdom) unit suite.
|
|
188
|
+
- `bun run test:browser` – Vitest browser runner (wheel/scroll integration).
|
|
189
|
+
- `bun run test:coverage`, `bun run test:browser:coverage`, `bun run coverage:merge` – coverage reports/merge.
|
|
190
|
+
- `bun run lint` / `bun run format` – Biome lint/format.
|
|
191
|
+
- `bun run typecheck` – TypeScript.
|
|
192
|
+
- `bun run storybook` / `bun run storybook:build` – Storybook dev/build.
|
|
193
|
+
|
|
194
|
+
## GitHub Pages (docs + example)
|
|
195
|
+
|
|
196
|
+
- Build locally: `bun run site:prepare` (produces `site/docs` for API HTML, `site/example` for the Vite demo).
|
|
197
|
+
- Deploy via CI: push to `master` and the Pages workflow builds both sections and publishes `site/` to the `gh-pages` branch (docs at `/docs/`, example at `/swipefeed/example/` by default).
|
|
198
|
+
- If you fork/rename the repo or use a custom Pages root, set `VITE_BASE=/<your-repo>/example/` when running `example:build:site` or adjust the workflow accordingly.
|
|
199
|
+
|
|
200
|
+
## Notes & limitations
|
|
201
|
+
|
|
202
|
+
- `visibility`, `onItemActive`, and `onItemInactive` options are present for future parity with the design spec but are not wired yet.
|
|
203
|
+
- Ensure your viewport has a defined size; virtualization and snap rely on it.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Direction, Orientation } from "../types";
|
|
2
|
+
type UseGesturesParams = {
|
|
3
|
+
orientation: Orientation;
|
|
4
|
+
direction: Direction;
|
|
5
|
+
threshold: number;
|
|
6
|
+
flickVelocity: number;
|
|
7
|
+
lockAxis: boolean;
|
|
8
|
+
ignoreWhileAnimating: boolean;
|
|
9
|
+
loop: boolean;
|
|
10
|
+
getIndex: () => number;
|
|
11
|
+
maxIndex: number;
|
|
12
|
+
onRequestIndexChange: (nextIndex: number) => void;
|
|
13
|
+
setAnimating: (value: boolean) => void;
|
|
14
|
+
isAnimating: boolean;
|
|
15
|
+
onDragStart?: (evt: React.PointerEvent) => void;
|
|
16
|
+
onDrag?: (delta: number, evt: React.PointerEvent) => void;
|
|
17
|
+
onDragEnd?: () => void;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Pointer/touch gestures (drag + flick). Mirrors the spec:
|
|
21
|
+
* IDLE -> DRAGGING -> SETTLING with threshold + velocity decision.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useGestures(params: UseGesturesParams): {
|
|
24
|
+
isDragging: boolean;
|
|
25
|
+
handlers: {
|
|
26
|
+
onPointerDown: (evt: React.PointerEvent) => void;
|
|
27
|
+
onPointerMove: (evt: React.PointerEvent) => void;
|
|
28
|
+
onPointerUp: () => void;
|
|
29
|
+
onPointerCancel: () => void;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import type { Direction, KeyboardConfig, Orientation } from "../types";
|
|
3
|
+
type UseKeyboardParams = {
|
|
4
|
+
orientation: Orientation;
|
|
5
|
+
direction: Direction;
|
|
6
|
+
config?: KeyboardConfig;
|
|
7
|
+
onPrev: () => void;
|
|
8
|
+
onNext: () => void;
|
|
9
|
+
onFirst?: () => void;
|
|
10
|
+
onLast?: () => void;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Keyboard navigation: arrow keys, Home/End, PageUp/PageDown.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useKeyboard(params: UseKeyboardParams): {
|
|
16
|
+
onKeyDown: (evt: KeyboardEvent | React.KeyboardEvent) => void;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ScrollBehavior } from "../types";
|
|
2
|
+
type UseScrollToParams = {
|
|
3
|
+
getViewport: () => HTMLElement | null;
|
|
4
|
+
setAnimating?: (value: boolean) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare function useScrollTo({ getViewport, setAnimating }: UseScrollToParams): {
|
|
7
|
+
scrollToIndex: (offset: number, behavior?: ScrollBehavior) => void;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { VirtualConfig, SwipeDeckVirtualItem, Orientation } from "../types";
|
|
2
|
+
type UseVirtualizerParams<T> = {
|
|
3
|
+
items: readonly T[];
|
|
4
|
+
virtual: VirtualConfig | undefined;
|
|
5
|
+
getScrollElement: () => HTMLElement | null;
|
|
6
|
+
orientation?: Orientation;
|
|
7
|
+
};
|
|
8
|
+
type VirtualizerResult = {
|
|
9
|
+
virtualItems: SwipeDeckVirtualItem[];
|
|
10
|
+
totalSize: number;
|
|
11
|
+
getItemOffset: (index: number) => number;
|
|
12
|
+
getItemSize: (index: number) => number;
|
|
13
|
+
scrollToIndex: (index: number, options?: {
|
|
14
|
+
align?: 'start' | 'center' | 'end' | 'auto';
|
|
15
|
+
behavior?: 'auto' | 'smooth';
|
|
16
|
+
}) => void;
|
|
17
|
+
containerSize: number;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Simplified adapter using @tanstack/react-virtual
|
|
21
|
+
* Auto-detects viewport size when estimatedSize is not provided.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useVirtualizer<T>(params: UseVirtualizerParams<T>): VirtualizerResult;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Direction, Orientation } from "../types";
|
|
2
|
+
export type UseWheelParams = {
|
|
3
|
+
orientation: Orientation;
|
|
4
|
+
direction: Direction;
|
|
5
|
+
discretePaging: boolean;
|
|
6
|
+
threshold: number;
|
|
7
|
+
debounce: number;
|
|
8
|
+
cooldown?: number;
|
|
9
|
+
onRequestIndexChange: (delta: 1 | -1) => void;
|
|
10
|
+
viewport: HTMLElement | null;
|
|
11
|
+
onDragStart?: () => void;
|
|
12
|
+
onDrag?: (delta: number) => void;
|
|
13
|
+
onDragEnd?: () => void;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Wheel handler supporting discrete paging (TikTok-like) or continuous tracking.
|
|
17
|
+
*
|
|
18
|
+
* Aggressively prevents multi-video scrolling:
|
|
19
|
+
* - Long cooldown period after each navigation
|
|
20
|
+
* - Capped delta per event to prevent large jumps (smooths jerky mouse wheels)
|
|
21
|
+
* - Direction locking during a scroll gesture
|
|
22
|
+
*/
|
|
23
|
+
export declare function useWheel(params: UseWheelParams): void;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { useSwipeDeck } from "./hooks/useSwipeDeck";
|
|
2
|
+
export { useWindowSize } from "./hooks/useWindowSize";
|
|
3
|
+
export { useSwipeItem } from "./hooks/useSwipeItem";
|
|
4
|
+
export { SwipeDeck } from "./components/SwipeDeck";
|
|
5
|
+
export type { SwipeDeckOptions, SwipeDeckAPI, SwipeDeckState, SwipeDeckActions, SwipeDeckVirtualItem, SwipeDeckProps, SwipeDeckHandle, SwipeDeckRenderContext, IndexChangeSource, Orientation, Direction, ScrollBehavior, } from "./types";
|