@juniorxsound/react-three-components 0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 juniorxsound
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.
package/README.md ADDED
@@ -0,0 +1,244 @@
1
+ # @juniorxsound/react-three-components
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@juniorxsound/react-three-components.svg)](https://www.npmjs.com/package/@juniorxsound/react-three-components)
4
+ [![CI](https://github.com/juniorxsound/react-three-components/actions/workflows/ci.yml/badge.svg)](https://github.com/juniorxsound/react-three-components/actions/workflows/ci.yml)
5
+ [![license](https://img.shields.io/npm/l/@juniorxsound/react-three-components.svg)](https://github.com/juniorxsound/react-three-components/blob/main/LICENSE)
6
+
7
+ 3D carousel components for React Three Fiber with gesture support.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @juniorxsound/react-three-components
13
+ ```
14
+
15
+ ### Peer Dependencies
16
+
17
+ This library requires the following peer dependencies:
18
+
19
+ ```bash
20
+ npm install react react-dom three @react-three/fiber @react-spring/web @use-gesture/react
21
+ ```
22
+
23
+ ## Components
24
+
25
+ ### CircularCarousel
26
+
27
+ A 3D carousel that arranges items in a circle and rotates around an axis.
28
+
29
+ ```tsx
30
+ import { Canvas } from "@react-three/fiber";
31
+ import { CircularCarousel, useCarouselContext } from "@juniorxsound/react-three-components";
32
+
33
+ function Item({ index }: { index: number }) {
34
+ const { activeIndex } = useCarouselContext();
35
+ const isActive = index === activeIndex;
36
+
37
+ return (
38
+ <mesh>
39
+ <boxGeometry args={[1, 1, 1]} />
40
+ <meshStandardMaterial color={isActive ? "hotpink" : "gray"} />
41
+ </mesh>
42
+ );
43
+ }
44
+
45
+ function App() {
46
+ return (
47
+ <Canvas>
48
+ <CircularCarousel radius={3} onIndexChange={(i) => console.log(i)}>
49
+ <Item index={0} />
50
+ <Item index={1} />
51
+ <Item index={2} />
52
+ <Item index={3} />
53
+ </CircularCarousel>
54
+ </Canvas>
55
+ );
56
+ }
57
+ ```
58
+
59
+ #### Props
60
+
61
+ | Prop | Type | Default | Description |
62
+ |------|------|---------|-------------|
63
+ | `children` | `ReactNode` | required | Carousel items |
64
+ | `radius` | `number` | `3` | Distance from center to items |
65
+ | `axis` | `"x" \| "y" \| "z"` | `"y"` | Rotation axis |
66
+ | `index` | `number` | - | Controlled active index |
67
+ | `defaultIndex` | `number` | `0` | Initial index (uncontrolled) |
68
+ | `onIndexChange` | `(index: number) => void` | - | Called when index changes |
69
+ | `dragEnabled` | `boolean` | `true` | Enable drag gestures |
70
+ | `dragSensitivity` | `number` | auto | Drag sensitivity |
71
+ | `dragAxis` | `"x" \| "y"` | `"x"` | Drag gesture axis |
72
+ | `dragConfig` | `DragConfig` | - | Additional drag options |
73
+
74
+ #### Ref Methods
75
+
76
+ ```tsx
77
+ const ref = useRef<CircularCarouselRef>(null);
78
+
79
+ ref.current.next(); // Go to next item
80
+ ref.current.prev(); // Go to previous item
81
+ ref.current.goTo(2); // Go to specific index
82
+ ```
83
+
84
+ #### With Navigation Triggers
85
+
86
+ ```tsx
87
+ <CircularCarousel>
88
+ <Item index={0} />
89
+ <Item index={1} />
90
+ <Item index={2} />
91
+
92
+ <CircularCarousel.PrevTrigger position={[-2, 0, 0]}>
93
+ <mesh><boxGeometry /><meshBasicMaterial color="blue" /></mesh>
94
+ </CircularCarousel.PrevTrigger>
95
+
96
+ <CircularCarousel.NextTrigger position={[2, 0, 0]}>
97
+ <mesh><boxGeometry /><meshBasicMaterial color="red" /></mesh>
98
+ </CircularCarousel.NextTrigger>
99
+ </CircularCarousel>
100
+ ```
101
+
102
+ ---
103
+
104
+ ### LinearCarousel
105
+
106
+ A carousel that slides items linearly (horizontally or vertically).
107
+
108
+ ```tsx
109
+ import { Canvas } from "@react-three/fiber";
110
+ import { LinearCarousel, useLinearCarouselContext } from "@juniorxsound/react-three-components";
111
+
112
+ function Item({ index }: { index: number }) {
113
+ const { activeIndex } = useLinearCarouselContext();
114
+ const isActive = index === activeIndex;
115
+
116
+ return (
117
+ <mesh scale={isActive ? 1.2 : 1}>
118
+ <planeGeometry args={[2, 1.5]} />
119
+ <meshBasicMaterial color={isActive ? "hotpink" : "gray"} />
120
+ </mesh>
121
+ );
122
+ }
123
+
124
+ function App() {
125
+ return (
126
+ <Canvas>
127
+ <LinearCarousel gap={0.5} direction="horizontal">
128
+ <Item index={0} />
129
+ <Item index={1} />
130
+ <Item index={2} />
131
+ <Item index={3} />
132
+ </LinearCarousel>
133
+ </Canvas>
134
+ );
135
+ }
136
+ ```
137
+
138
+ #### Props
139
+
140
+ | Prop | Type | Default | Description |
141
+ |------|------|---------|-------------|
142
+ | `children` | `ReactNode` | required | Carousel items |
143
+ | `gap` | `number` | `0.2` | Space between items |
144
+ | `direction` | `"horizontal" \| "vertical"` | `"horizontal"` | Slide direction |
145
+ | `index` | `number` | - | Controlled active index |
146
+ | `defaultIndex` | `number` | `0` | Initial index (uncontrolled) |
147
+ | `onIndexChange` | `(index: number) => void` | - | Called when index changes |
148
+ | `dragEnabled` | `boolean` | `true` | Enable drag gestures |
149
+ | `dragSensitivity` | `number` | `150` | Drag sensitivity |
150
+ | `dragAxis` | `"x" \| "y"` | auto | Drag axis (derived from direction) |
151
+ | `dragConfig` | `DragConfig` | - | Additional drag options |
152
+
153
+ #### Ref Methods
154
+
155
+ ```tsx
156
+ const ref = useRef<LinearCarouselRef>(null);
157
+
158
+ ref.current.next(); // Go to next item (bounded)
159
+ ref.current.prev(); // Go to previous item (bounded)
160
+ ref.current.goTo(2); // Go to specific index
161
+ ```
162
+
163
+ > Note: LinearCarousel is bounded (doesn't wrap around), unlike CircularCarousel which loops infinitely.
164
+
165
+ #### With Navigation Triggers
166
+
167
+ ```tsx
168
+ <LinearCarousel>
169
+ <Item index={0} />
170
+ <Item index={1} />
171
+ <Item index={2} />
172
+
173
+ <LinearCarousel.PrevTrigger position={[-3, 0, 0]}>
174
+ <PrevButton />
175
+ </LinearCarousel.PrevTrigger>
176
+
177
+ <LinearCarousel.NextTrigger position={[3, 0, 0]}>
178
+ <NextButton />
179
+ </LinearCarousel.NextTrigger>
180
+ </LinearCarousel>
181
+ ```
182
+
183
+ ---
184
+
185
+ ## Context Hooks
186
+
187
+ Access carousel state from any child component:
188
+
189
+ ```tsx
190
+ // For CircularCarousel
191
+ import { useCarouselContext } from "@juniorxsound/react-three-components";
192
+
193
+ const { activeIndex, count, next, prev, goTo } = useCarouselContext();
194
+
195
+ // For LinearCarousel
196
+ import { useLinearCarouselContext } from "@juniorxsound/react-three-components";
197
+
198
+ const { activeIndex, count, next, prev, goTo } = useLinearCarouselContext();
199
+ ```
200
+
201
+ ## DragConfig
202
+
203
+ Fine-tune drag behavior:
204
+
205
+ ```tsx
206
+ <CircularCarousel
207
+ dragConfig={{
208
+ axis: "x", // Constrain to axis
209
+ threshold: 10, // Pixels before drag starts
210
+ rubberband: 0.2, // Elastic effect at bounds
211
+ touchAction: "pan-y", // CSS touch-action
212
+ pointer: { touch: true }, // Pointer options
213
+ }}
214
+ >
215
+ ```
216
+
217
+ ## Contributing
218
+
219
+ ### Development
220
+
221
+ ```bash
222
+ nvm use # Switch to Node 24 (uses .nvmrc)
223
+ npm install # Install dependencies
224
+ npm run dev # Start Storybook dev server
225
+ npm run test # Run tests in watch mode
226
+ npm run lint # Run ESLint
227
+ npm run build # Build the library
228
+ ```
229
+
230
+ ### Releasing
231
+
232
+ This package uses [npm trusted publishers](https://docs.npmjs.com/trusted-publishers) for secure, token-free publishing.
233
+
234
+ ```bash
235
+ npm run release:patch # 0.1.0 → 0.1.1
236
+ npm run release:minor # 0.1.0 → 0.2.0
237
+ npm run release:major # 0.1.0 → 1.0.0
238
+ ```
239
+
240
+ Then create a GitHub Release from the tag - this triggers automatic npm publish with provenance.
241
+
242
+ ## License
243
+
244
+ MIT
@@ -0,0 +1,9 @@
1
+ import { type ForwardRefExoticComponent, type RefAttributes } from "react";
2
+ import { CircularCarouselNextTrigger, CircularCarouselPrevTrigger } from "./CircularCarouselTriggers";
3
+ import type { CircularCarouselProps, CircularCarouselRef } from "./types";
4
+ type CircularCarouselComponent = ForwardRefExoticComponent<CircularCarouselProps & RefAttributes<CircularCarouselRef>> & {
5
+ NextTrigger: typeof CircularCarouselNextTrigger;
6
+ PrevTrigger: typeof CircularCarouselPrevTrigger;
7
+ };
8
+ export declare const CircularCarousel: CircularCarouselComponent;
9
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { GroupProps } from "../../types";
2
+ export declare function CircularCarouselNextTrigger(props: GroupProps): import("react/jsx-runtime").JSX.Element;
3
+ export declare function CircularCarouselPrevTrigger(props: GroupProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,12 @@
1
+ export declare const TAU: number;
2
+ export declare const DEFAULT_RADIUS = 3;
3
+ export declare const DEFAULT_AXIS: "y";
4
+ export declare const DEFAULT_DRAG_SENSITIVITY_FACTOR = 280;
5
+ export declare const SPRING_CONFIG: {
6
+ readonly tension: 200;
7
+ readonly friction: 25;
8
+ };
9
+ export declare const DRAG_SPRING_CONFIG: {
10
+ readonly tension: 400;
11
+ readonly friction: 50;
12
+ };
@@ -0,0 +1,3 @@
1
+ import type { CarouselContextValue } from "./types";
2
+ export declare const CarouselContext: import("react").Context<CarouselContextValue | null>;
3
+ export declare function useCarouselContext(): CarouselContextValue;
@@ -0,0 +1,4 @@
1
+ export { CircularCarousel } from "./CircularCarousel";
2
+ export { CircularCarouselNextTrigger, CircularCarouselPrevTrigger, } from "./CircularCarouselTriggers";
3
+ export { useCarouselContext } from "./context";
4
+ export type { CircularCarouselProps, CircularCarouselRef, CarouselContextValue, DragConfig, } from "./types";
@@ -0,0 +1,43 @@
1
+ import type { ReactNode } from "react";
2
+ export type DragConfig = {
3
+ /** Axis to constrain drag movement. Default: "x" */
4
+ axis?: "x" | "y";
5
+ /** Pointer options for drag gesture */
6
+ pointer?: {
7
+ touch?: boolean;
8
+ capture?: boolean;
9
+ keys?: boolean;
10
+ };
11
+ /** Touch action CSS property. Default: "none" */
12
+ touchAction?: string;
13
+ /** Threshold in pixels before drag starts */
14
+ threshold?: number;
15
+ /** Rubberband effect when dragging past bounds (0-1) */
16
+ rubberband?: boolean | number;
17
+ };
18
+ export type CircularCarouselProps = {
19
+ children: ReactNode;
20
+ radius?: number;
21
+ axis?: "x" | "y" | "z";
22
+ index?: number;
23
+ defaultIndex?: number;
24
+ onIndexChange?: (index: number) => void;
25
+ dragEnabled?: boolean;
26
+ dragSensitivity?: number;
27
+ /** Axis for drag gesture. Default: "x" */
28
+ dragAxis?: "x" | "y";
29
+ /** Additional drag gesture configuration */
30
+ dragConfig?: DragConfig;
31
+ };
32
+ export type CircularCarouselRef = {
33
+ next(): void;
34
+ prev(): void;
35
+ goTo(index: number): void;
36
+ };
37
+ export type CarouselContextValue = {
38
+ activeIndex: number;
39
+ count: number;
40
+ next: () => void;
41
+ prev: () => void;
42
+ goTo: (index: number) => void;
43
+ };
@@ -0,0 +1,6 @@
1
+ export declare function clamp(value: number, min: number, max: number): number;
2
+ export declare function getItemTransform(index: number, count: number, radius: number, axis: "x" | "y" | "z"): {
3
+ position: readonly [number, 0, number] | readonly [0, number, number] | readonly [number, number, 0];
4
+ rotation: readonly [0, number, 0] | readonly [number, 0, 0] | readonly [0, 0, number];
5
+ };
6
+ export declare function calculateShortestPath(currentOffset: number, targetLogical: number): number;
@@ -0,0 +1,9 @@
1
+ import { type ForwardRefExoticComponent, type RefAttributes } from "react";
2
+ import { LinearCarouselNextTrigger, LinearCarouselPrevTrigger } from "./LinearCarouselTriggers";
3
+ import type { LinearCarouselProps, LinearCarouselRef } from "./types";
4
+ type LinearCarouselComponent = ForwardRefExoticComponent<LinearCarouselProps & RefAttributes<LinearCarouselRef>> & {
5
+ NextTrigger: typeof LinearCarouselNextTrigger;
6
+ PrevTrigger: typeof LinearCarouselPrevTrigger;
7
+ };
8
+ export declare const LinearCarousel: LinearCarouselComponent;
9
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { GroupProps } from "../../types";
2
+ export declare function LinearCarouselNextTrigger(props: GroupProps): import("react/jsx-runtime").JSX.Element;
3
+ export declare function LinearCarouselPrevTrigger(props: GroupProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,11 @@
1
+ export declare const DEFAULT_GAP = 0.5;
2
+ export declare const DEFAULT_DIRECTION: "horizontal";
3
+ export declare const DEFAULT_DRAG_SENSITIVITY = 150;
4
+ export declare const SPRING_CONFIG: {
5
+ readonly tension: 200;
6
+ readonly friction: 25;
7
+ };
8
+ export declare const DRAG_SPRING_CONFIG: {
9
+ readonly tension: 400;
10
+ readonly friction: 50;
11
+ };
@@ -0,0 +1,3 @@
1
+ import type { LinearCarouselContextValue } from "./types";
2
+ export declare const LinearCarouselContext: import("react").Context<LinearCarouselContextValue | null>;
3
+ export declare function useLinearCarouselContext(): LinearCarouselContextValue;
@@ -0,0 +1,4 @@
1
+ export { LinearCarousel } from "./LinearCarousel";
2
+ export { LinearCarouselNextTrigger, LinearCarouselPrevTrigger, } from "./LinearCarouselTriggers";
3
+ export { useLinearCarouselContext } from "./context";
4
+ export type { LinearCarouselProps, LinearCarouselRef, LinearCarouselContextValue, DragConfig as LinearDragConfig, } from "./types";
@@ -0,0 +1,43 @@
1
+ import type { ReactNode } from "react";
2
+ export type DragConfig = {
3
+ /** Axis to constrain drag movement */
4
+ axis?: "x" | "y";
5
+ /** Pointer options for drag gesture */
6
+ pointer?: {
7
+ touch?: boolean;
8
+ capture?: boolean;
9
+ keys?: boolean;
10
+ };
11
+ /** Touch action CSS property. Default: "none" */
12
+ touchAction?: string;
13
+ /** Threshold in pixels before drag starts */
14
+ threshold?: number;
15
+ /** Rubberband effect when dragging past bounds (0-1) */
16
+ rubberband?: boolean | number;
17
+ };
18
+ export type LinearCarouselProps = {
19
+ children: ReactNode;
20
+ gap?: number;
21
+ direction?: "horizontal" | "vertical";
22
+ index?: number;
23
+ defaultIndex?: number;
24
+ onIndexChange?: (index: number) => void;
25
+ dragEnabled?: boolean;
26
+ dragSensitivity?: number;
27
+ /** Axis for drag gesture. Default: derived from direction ("x" for horizontal, "y" for vertical) */
28
+ dragAxis?: "x" | "y";
29
+ /** Additional drag gesture configuration */
30
+ dragConfig?: DragConfig;
31
+ };
32
+ export type LinearCarouselRef = {
33
+ next(): void;
34
+ prev(): void;
35
+ goTo(index: number): void;
36
+ };
37
+ export type LinearCarouselContextValue = {
38
+ activeIndex: number;
39
+ count: number;
40
+ next: () => void;
41
+ prev: () => void;
42
+ goTo: (index: number) => void;
43
+ };
@@ -0,0 +1,2 @@
1
+ export declare function clamp(value: number, min: number, max: number): number;
2
+ export declare function getItemPosition(index: number, gap: number, direction: "horizontal" | "vertical"): readonly [number, number, number];
@@ -0,0 +1,4 @@
1
+ export { CircularCarousel, CircularCarouselNextTrigger, CircularCarouselPrevTrigger, useCarouselContext, } from "./CircularCarousel";
2
+ export type { CircularCarouselProps, CircularCarouselRef, CarouselContextValue, DragConfig, } from "./CircularCarousel";
3
+ export { LinearCarousel, LinearCarouselNextTrigger, LinearCarouselPrevTrigger, useLinearCarouselContext, } from "./LinearCarousel";
4
+ export type { LinearCarouselProps, LinearCarouselRef, LinearCarouselContextValue, } from "./LinearCarousel";
@@ -0,0 +1,3 @@
1
+ export { CircularCarousel, CircularCarouselNextTrigger, CircularCarouselPrevTrigger, useCarouselContext, LinearCarousel, LinearCarouselNextTrigger, LinearCarouselPrevTrigger, useLinearCarouselContext, } from "./components";
2
+ export type { CircularCarouselProps, CircularCarouselRef, CarouselContextValue, LinearCarouselProps, LinearCarouselRef, LinearCarouselContextValue, DragConfig, } from "./components";
3
+ export type { GroupProps } from "./types";
@@ -0,0 +1,438 @@
1
+ import { jsx as D, jsxs as bt } from "react/jsx-runtime";
2
+ import Ot, { createContext as dt, useContext as St, forwardRef as Pt, useState as Dt, useRef as N, useMemo as et, Children as Lt, isValidElement as rt, useCallback as E, useImperativeHandle as Mt, useEffect as nt } from "react";
3
+ import { useThree as Ft, useFrame as Gt } from "@react-three/fiber";
4
+ import { useSpring as Ut } from "@react-spring/web";
5
+ import { useDrag as kt } from "@use-gesture/react";
6
+ const S = 2 * Math.PI, zt = 3, jt = "y", Bt = 280, Z = {
7
+ tension: 200,
8
+ friction: 25
9
+ }, Wt = {
10
+ tension: 400,
11
+ friction: 50
12
+ };
13
+ function mt(c, t, u) {
14
+ return Math.max(t, Math.min(u, c));
15
+ }
16
+ function Xt(c, t, u, r) {
17
+ const o = c / t * S, l = Math.cos(o) * u, s = Math.sin(o) * u, I = r === "y" ? [s, 0, l] : r === "x" ? [0, l, s] : [l, s, 0], $ = r === "y" ? [0, Math.PI + o, 0] : r === "x" ? [Math.PI + o, 0, 0] : [0, 0, Math.PI + o];
18
+ return {
19
+ position: I,
20
+ rotation: $
21
+ };
22
+ }
23
+ function pt(c, t) {
24
+ const u = Math.round((c - t) / S);
25
+ return t + u * S;
26
+ }
27
+ const wt = dt(null);
28
+ function $t() {
29
+ const c = St(wt);
30
+ if (!c)
31
+ throw new Error("CircularCarousel compound components must be used within CircularCarousel");
32
+ return c;
33
+ }
34
+ var C = { exports: {} }, ht = {};
35
+ /**
36
+ * @license React
37
+ * react-compiler-runtime.production.js
38
+ *
39
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
40
+ *
41
+ * This source code is licensed under the MIT license found in the
42
+ * LICENSE file in the root directory of this source tree.
43
+ */
44
+ var It;
45
+ function Jt() {
46
+ if (It) return ht;
47
+ It = 1;
48
+ var c = Ot.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
49
+ return ht.c = function(t) {
50
+ return c.H.useMemoCache(t);
51
+ }, ht;
52
+ }
53
+ var Rt = {};
54
+ /**
55
+ * @license React
56
+ * react-compiler-runtime.development.js
57
+ *
58
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
59
+ *
60
+ * This source code is licensed under the MIT license found in the
61
+ * LICENSE file in the root directory of this source tree.
62
+ */
63
+ var xt;
64
+ function Kt() {
65
+ return xt || (xt = 1, process.env.NODE_ENV !== "production" && (function() {
66
+ var c = Ot.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
67
+ Rt.c = function(t) {
68
+ var u = c.H;
69
+ return u === null && console.error(
70
+ `Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
71
+ 1. You might have mismatching versions of React and the renderer (such as React DOM)
72
+ 2. You might be breaking the Rules of Hooks
73
+ 3. You might have more than one copy of React in the same app
74
+ See https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.`
75
+ ), u.useMemoCache(t);
76
+ };
77
+ })()), Rt;
78
+ }
79
+ var At;
80
+ function Qt() {
81
+ return At || (At = 1, process.env.NODE_ENV === "production" ? C.exports = Jt() : C.exports = Kt()), C.exports;
82
+ }
83
+ var ot = Qt();
84
+ function vt(c) {
85
+ const t = ot.c(9), {
86
+ next: u
87
+ } = $t();
88
+ let r, o;
89
+ t[0] !== c ? ({
90
+ children: r,
91
+ ...o
92
+ } = c, t[0] = c, t[1] = r, t[2] = o) : (r = t[1], o = t[2]);
93
+ let l;
94
+ t[3] !== u ? (l = () => u(), t[3] = u, t[4] = l) : l = t[4];
95
+ let s;
96
+ return t[5] !== r || t[6] !== o || t[7] !== l ? (s = /* @__PURE__ */ D("group", { onClick: l, ...o, children: r }), t[5] = r, t[6] = o, t[7] = l, t[8] = s) : s = t[8], s;
97
+ }
98
+ function _t(c) {
99
+ const t = ot.c(9), {
100
+ prev: u
101
+ } = $t();
102
+ let r, o;
103
+ t[0] !== c ? ({
104
+ children: r,
105
+ ...o
106
+ } = c, t[0] = c, t[1] = r, t[2] = o) : (r = t[1], o = t[2]);
107
+ let l;
108
+ t[3] !== u ? (l = () => u(), t[3] = u, t[4] = l) : l = t[4];
109
+ let s;
110
+ return t[5] !== r || t[6] !== o || t[7] !== l ? (s = /* @__PURE__ */ D("group", { onClick: l, ...o, children: r }), t[5] = r, t[6] = o, t[7] = l, t[8] = s) : s = t[8], s;
111
+ }
112
+ const Tt = Pt(function({
113
+ children: t,
114
+ radius: u = zt,
115
+ axis: r = jt,
116
+ index: o,
117
+ defaultIndex: l = 0,
118
+ onIndexChange: s,
119
+ dragEnabled: I = !0,
120
+ dragSensitivity: $,
121
+ dragAxis: X = "x",
122
+ dragConfig: a
123
+ }, st) {
124
+ const [ct, q] = Dt(l), x = o !== void 0, R = x ? o : ct, p = N(R);
125
+ p.current = R;
126
+ const H = et(() => Lt.toArray(t), [t]), Y = H.filter((i) => rt(i) && i.type !== vt && i.type !== _t), ut = H.filter((i) => rt(i) && (i.type === vt || i.type === _t)), n = Y.length, P = N(null), y = n > 0 ? S / n : S, it = $ ?? Bt / y, [{
127
+ offset: lt
128
+ }, V] = Ut(() => ({
129
+ offset: 0
130
+ })), v = N(V);
131
+ v.current = V;
132
+ const z = N(!1), A = N(0), j = N(0), _ = E((i) => {
133
+ const e = mt(i, 0, n - 1);
134
+ if (e === p.current) return;
135
+ p.current = e, x || q(e), s == null || s(e);
136
+ const f = -(e / n) * S, m = pt(A.current, f);
137
+ v.current.start({
138
+ offset: m,
139
+ config: Z
140
+ });
141
+ }, [n, x, s]), b = E(() => {
142
+ n !== 0 && _((p.current + 1) % n);
143
+ }, [n, _]), O = E(() => {
144
+ n !== 0 && _((p.current - 1 + n) % n);
145
+ }, [n, _]), d = E((i) => _(i), [_]);
146
+ Mt(st, () => ({
147
+ next: b,
148
+ prev: O,
149
+ goTo: d
150
+ }), [b, O, d]), nt(() => {
151
+ if (!z.current && n > 0) {
152
+ const i = -(R / n) * S, e = A.current, m = e === 0 && R !== 0 ? i : pt(e, i);
153
+ v.current.start({
154
+ offset: m,
155
+ config: Z
156
+ });
157
+ }
158
+ }, [R, n]);
159
+ const {
160
+ gl: h
161
+ } = Ft();
162
+ kt(({
163
+ active: i,
164
+ movement: [e, f],
165
+ first: m,
166
+ last: K,
167
+ event: ft
168
+ }) => {
169
+ z.current = i;
170
+ const G = ft, U = X === "x" ? e : f;
171
+ if (i && m && G.pointerId != null && (h.domElement.setPointerCapture(G.pointerId), h.domElement.style.cursor = "grabbing", j.current = A.current), !i && K && G.pointerId != null) {
172
+ try {
173
+ h.domElement.releasePointerCapture(G.pointerId);
174
+ } catch {
175
+ }
176
+ h.domElement.style.cursor = "grab";
177
+ }
178
+ const B = m ? A.current : j.current, k = Number(U), L = Number.isFinite(k) ? mt(k / it, -y, y) : 0;
179
+ if (i)
180
+ v.current.start({
181
+ offset: B + L,
182
+ config: Wt
183
+ });
184
+ else {
185
+ const M = p.current, W = (M - 1 + n) % n, Q = (M + 1) % n, w = B + L;
186
+ let T = (Math.round(-w / S * n) % n + n) % n;
187
+ T !== W && T !== M && T !== Q && (T = L > 0 ? Q : L < 0 ? W : M);
188
+ const F = mt(T, 0, n - 1);
189
+ if (n === 0 || !Number.isFinite(F)) {
190
+ v.current.start({
191
+ offset: B,
192
+ config: Z
193
+ });
194
+ return;
195
+ }
196
+ p.current = F, x || q(F), s == null || s(F);
197
+ const Yt = -(F / n) * S, Vt = pt(w, Yt);
198
+ v.current.start({
199
+ offset: Vt,
200
+ config: Z
201
+ });
202
+ }
203
+ }, {
204
+ target: h.domElement,
205
+ enabled: I,
206
+ pointer: (a == null ? void 0 : a.pointer) ?? {
207
+ touch: !0,
208
+ capture: !0
209
+ },
210
+ axis: (a == null ? void 0 : a.axis) ?? X,
211
+ touchAction: (a == null ? void 0 : a.touchAction) ?? "none",
212
+ threshold: a == null ? void 0 : a.threshold,
213
+ rubberband: a == null ? void 0 : a.rubberband
214
+ }), nt(() => {
215
+ if (!I) return;
216
+ const i = h.domElement, e = i.style.touchAction, f = i.style.cursor;
217
+ return i.style.touchAction = "none", i.style.cursor = "grab", () => {
218
+ i.style.touchAction = e, i.style.cursor = f;
219
+ };
220
+ }, [I, h.domElement]), Gt(() => {
221
+ if (!P.current) return;
222
+ const i = lt.get();
223
+ A.current = i, P.current.rotation[r] = i;
224
+ });
225
+ const J = E((i) => Xt(i, n, u, r), [n, u, r]), at = et(() => ({
226
+ activeIndex: R,
227
+ count: n,
228
+ next: b,
229
+ prev: O,
230
+ goTo: d
231
+ }), [R, n, b, O, d]);
232
+ return /* @__PURE__ */ bt(wt.Provider, { value: at, children: [
233
+ /* @__PURE__ */ D("group", { ref: P, children: Y.map((i, e) => {
234
+ const {
235
+ position: f,
236
+ rotation: m
237
+ } = J(e);
238
+ return /* @__PURE__ */ D("group", { position: f, rotation: m, children: i }, i.key ?? e);
239
+ }) }),
240
+ ut
241
+ ] });
242
+ });
243
+ Tt.NextTrigger = vt;
244
+ Tt.PrevTrigger = _t;
245
+ const ue = Tt, Zt = 0.5, Ct = "horizontal", gt = 150, g = {
246
+ tension: 200,
247
+ friction: 25
248
+ }, te = {
249
+ tension: 400,
250
+ friction: 50
251
+ };
252
+ function tt(c, t, u) {
253
+ return Math.max(t, Math.min(u, c));
254
+ }
255
+ function ee(c, t, u) {
256
+ const r = c * (1 + t);
257
+ return u === "horizontal" ? [r, 0, 0] : [0, r, 0];
258
+ }
259
+ const qt = dt(null);
260
+ function Ht() {
261
+ const c = St(qt);
262
+ if (!c)
263
+ throw new Error("LinearCarousel compound components must be used within LinearCarousel");
264
+ return c;
265
+ }
266
+ function yt(c) {
267
+ const t = ot.c(9), {
268
+ next: u
269
+ } = Ht();
270
+ let r, o;
271
+ t[0] !== c ? ({
272
+ children: r,
273
+ ...o
274
+ } = c, t[0] = c, t[1] = r, t[2] = o) : (r = t[1], o = t[2]);
275
+ let l;
276
+ t[3] !== u ? (l = () => u(), t[3] = u, t[4] = l) : l = t[4];
277
+ let s;
278
+ return t[5] !== r || t[6] !== o || t[7] !== l ? (s = /* @__PURE__ */ D("group", { onClick: l, ...o, children: r }), t[5] = r, t[6] = o, t[7] = l, t[8] = s) : s = t[8], s;
279
+ }
280
+ function Nt(c) {
281
+ const t = ot.c(9), {
282
+ prev: u
283
+ } = Ht();
284
+ let r, o;
285
+ t[0] !== c ? ({
286
+ children: r,
287
+ ...o
288
+ } = c, t[0] = c, t[1] = r, t[2] = o) : (r = t[1], o = t[2]);
289
+ let l;
290
+ t[3] !== u ? (l = () => u(), t[3] = u, t[4] = l) : l = t[4];
291
+ let s;
292
+ return t[5] !== r || t[6] !== o || t[7] !== l ? (s = /* @__PURE__ */ D("group", { onClick: l, ...o, children: r }), t[5] = r, t[6] = o, t[7] = l, t[8] = s) : s = t[8], s;
293
+ }
294
+ const Et = Pt(function({
295
+ children: t,
296
+ gap: u = Zt,
297
+ direction: r = Ct,
298
+ index: o,
299
+ defaultIndex: l = 0,
300
+ onIndexChange: s,
301
+ dragEnabled: I = !0,
302
+ dragSensitivity: $,
303
+ dragAxis: X,
304
+ dragConfig: a
305
+ }, st) {
306
+ const [ct, q] = Dt(l), x = o !== void 0, R = x ? o : ct, p = N(R);
307
+ p.current = R;
308
+ const H = et(() => Lt.toArray(t), [t]), Y = H.filter((e) => rt(e) && e.type !== yt && e.type !== Nt), ut = H.filter((e) => rt(e) && (e.type === yt || e.type === Nt)), n = Y.length, P = N(null), y = 1 + u, it = $ ?? gt, [{
309
+ offset: lt
310
+ }, V] = Ut(() => ({
311
+ offset: 0
312
+ })), v = N(V);
313
+ v.current = V;
314
+ const z = N(!1), A = N(0), j = N(0), _ = E((e) => {
315
+ const f = tt(e, 0, n - 1);
316
+ if (f === p.current) return;
317
+ p.current = f, x || q(f), s == null || s(f);
318
+ const m = -f * y;
319
+ v.current.start({
320
+ offset: m,
321
+ config: g
322
+ });
323
+ }, [n, x, s, y]), b = E(() => {
324
+ if (n === 0) return;
325
+ const e = Math.min(p.current + 1, n - 1);
326
+ _(e);
327
+ }, [n, _]), O = E(() => {
328
+ if (n === 0) return;
329
+ const e = Math.max(p.current - 1, 0);
330
+ _(e);
331
+ }, [n, _]), d = E((e) => _(e), [_]);
332
+ Mt(st, () => ({
333
+ next: b,
334
+ prev: O,
335
+ goTo: d
336
+ }), [b, O, d]), nt(() => {
337
+ if (!z.current && n > 0) {
338
+ const e = -R * y;
339
+ v.current.start({
340
+ offset: e,
341
+ config: g
342
+ });
343
+ }
344
+ }, [R, n, y]);
345
+ const {
346
+ gl: h
347
+ } = Ft(), J = X ?? (r === "horizontal" ? "x" : "y");
348
+ kt(({
349
+ active: e,
350
+ movement: [f, m],
351
+ first: K,
352
+ last: ft,
353
+ event: G
354
+ }) => {
355
+ z.current = e;
356
+ const U = G, B = J === "x" ? f : m;
357
+ if (e && K && U.pointerId != null && (h.domElement.setPointerCapture(U.pointerId), h.domElement.style.cursor = "grabbing", j.current = A.current), !e && ft && U.pointerId != null) {
358
+ try {
359
+ h.domElement.releasePointerCapture(U.pointerId);
360
+ } catch {
361
+ }
362
+ h.domElement.style.cursor = "grab";
363
+ }
364
+ const k = K ? A.current : j.current, L = Number(B), M = Number.isFinite(L) ? tt(L / it, -y, y) : 0;
365
+ if (e)
366
+ v.current.start({
367
+ offset: k + M,
368
+ config: te
369
+ });
370
+ else {
371
+ const W = p.current, Q = k + M;
372
+ let w = Math.round(-Q / y);
373
+ w = tt(w, W - 1, W + 1);
374
+ const T = tt(w, 0, n - 1);
375
+ if (n === 0 || !Number.isFinite(T)) {
376
+ v.current.start({
377
+ offset: k,
378
+ config: g
379
+ });
380
+ return;
381
+ }
382
+ p.current = T, x || q(T), s == null || s(T);
383
+ const F = -T * y;
384
+ v.current.start({
385
+ offset: F,
386
+ config: g
387
+ });
388
+ }
389
+ }, {
390
+ target: h.domElement,
391
+ enabled: I,
392
+ pointer: (a == null ? void 0 : a.pointer) ?? {
393
+ touch: !0,
394
+ capture: !0
395
+ },
396
+ axis: (a == null ? void 0 : a.axis) ?? J,
397
+ touchAction: (a == null ? void 0 : a.touchAction) ?? "none",
398
+ threshold: a == null ? void 0 : a.threshold,
399
+ rubberband: a == null ? void 0 : a.rubberband
400
+ }), nt(() => {
401
+ if (!I) return;
402
+ const e = h.domElement, f = e.style.touchAction, m = e.style.cursor;
403
+ return e.style.touchAction = "none", e.style.cursor = "grab", () => {
404
+ e.style.touchAction = f, e.style.cursor = m;
405
+ };
406
+ }, [I, h.domElement]), Gt(() => {
407
+ if (!P.current) return;
408
+ const e = lt.get();
409
+ A.current = e, r === "horizontal" ? P.current.position.x = e : P.current.position.y = e;
410
+ });
411
+ const at = E((e) => ee(e, u, r), [u, r]), i = et(() => ({
412
+ activeIndex: R,
413
+ count: n,
414
+ next: b,
415
+ prev: O,
416
+ goTo: d
417
+ }), [R, n, b, O, d]);
418
+ return /* @__PURE__ */ bt(qt.Provider, { value: i, children: [
419
+ /* @__PURE__ */ D("group", { ref: P, children: Y.map((e, f) => {
420
+ const m = at(f);
421
+ return /* @__PURE__ */ D("group", { position: [...m], children: e }, e.key ?? f);
422
+ }) }),
423
+ ut
424
+ ] });
425
+ });
426
+ Et.NextTrigger = yt;
427
+ Et.PrevTrigger = Nt;
428
+ const ie = Et;
429
+ export {
430
+ ue as CircularCarousel,
431
+ vt as CircularCarouselNextTrigger,
432
+ _t as CircularCarouselPrevTrigger,
433
+ ie as LinearCarousel,
434
+ yt as LinearCarouselNextTrigger,
435
+ Nt as LinearCarouselPrevTrigger,
436
+ $t as useCarouselContext,
437
+ Ht as useLinearCarouselContext
438
+ };
@@ -0,0 +1,2 @@
1
+ import type { ThreeElements } from "@react-three/fiber";
2
+ export type GroupProps = ThreeElements["group"];
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@juniorxsound/react-three-components",
3
+ "version": "0.1.0",
4
+ "description": "3D carousel components for React Three Fiber",
5
+ "author": "juniorxsound",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/juniorxsound/react-three-components.git"
10
+ },
11
+ "keywords": [
12
+ "react",
13
+ "three",
14
+ "threejs",
15
+ "r3f",
16
+ "react-three-fiber",
17
+ "carousel",
18
+ "3d"
19
+ ],
20
+ "type": "module",
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "sideEffects": false,
25
+ "main": "./dist/react-three-components.js",
26
+ "module": "./dist/react-three-components.js",
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "import": "./dist/react-three-components.js",
31
+ "types": "./dist/index.d.ts"
32
+ }
33
+ },
34
+ "scripts": {
35
+ "dev": "storybook dev -p 6006",
36
+ "build": "tsc && vite build && tsc -p tsconfig.build.json",
37
+ "build:storybook": "storybook build",
38
+ "lint": "eslint .",
39
+ "storybook": "storybook dev -p 6006",
40
+ "test": "vitest",
41
+ "test:run": "vitest run",
42
+ "release:patch": "npm run lint && npm run test:run && npm run build && npm version patch -m 'Release %s' && git push && git push --tags",
43
+ "release:minor": "npm run lint && npm run test:run && npm run build && npm version minor -m 'Release %s' && git push && git push --tags",
44
+ "release:major": "npm run lint && npm run test:run && npm run build && npm version major -m 'Release %s' && git push && git push --tags"
45
+ },
46
+ "peerDependencies": {
47
+ "react": ">=18",
48
+ "react-dom": ">=18",
49
+ "three": ">=0.150.0",
50
+ "@react-three/fiber": ">=8",
51
+ "@react-spring/web": ">=9",
52
+ "@use-gesture/react": ">=10"
53
+ },
54
+ "devDependencies": {
55
+ "@react-three/drei": "^10.7.7",
56
+ "@react-three/fiber": "^9.5.0",
57
+ "@react-spring/web": "^10.0.3",
58
+ "@use-gesture/react": "^10.3.1",
59
+ "react": "^19.2.0",
60
+ "react-dom": "^19.2.0",
61
+ "three": "^0.182.0",
62
+ "@eslint/js": "^9.39.1",
63
+ "@react-three/test-renderer": "^9.1.0",
64
+ "@storybook/addon-essentials": "^8.6.14",
65
+ "@storybook/react": "^8.6.15",
66
+ "@storybook/react-vite": "^8.6.15",
67
+ "@types/node": "^24.10.1",
68
+ "@types/react": "^19.2.5",
69
+ "@types/react-dom": "^19.2.3",
70
+ "@vitejs/plugin-react": "^5.1.1",
71
+ "babel-plugin-react-compiler": "^1.0.0",
72
+ "eslint": "^9.39.1",
73
+ "eslint-plugin-react-hooks": "^7.0.1",
74
+ "eslint-plugin-react-refresh": "^0.4.24",
75
+ "globals": "^16.5.0",
76
+ "storybook": "^8.6.15",
77
+ "typescript": "~5.9.3",
78
+ "typescript-eslint": "^8.46.4",
79
+ "vite": "^6.4.1",
80
+ "vitest": "^4.0.18"
81
+ }
82
+ }