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 +21 -0
- package/README.md +75 -0
- package/dist/components/CircularCarousel/CircularCarousel.d.ts +9 -0
- package/dist/components/CircularCarousel/CircularCarouselTriggers.d.ts +3 -0
- package/dist/components/CircularCarousel/constants.d.ts +12 -0
- package/dist/components/CircularCarousel/context.d.ts +3 -0
- package/dist/components/CircularCarousel/index.d.ts +4 -0
- package/dist/components/CircularCarousel/types.d.ts +43 -0
- package/dist/components/CircularCarousel/utils.d.ts +6 -0
- package/dist/components/LinearCarousel/LinearCarousel.d.ts +9 -0
- package/dist/components/LinearCarousel/LinearCarouselTriggers.d.ts +3 -0
- package/dist/components/LinearCarousel/constants.d.ts +11 -0
- package/dist/components/LinearCarousel/context.d.ts +3 -0
- package/dist/components/LinearCarousel/index.d.ts +4 -0
- package/dist/components/LinearCarousel/types.d.ts +43 -0
- package/dist/components/LinearCarousel/utils.d.ts +2 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/index.d.ts +3 -0
- package/dist/react-three-components.js +438 -0
- package/dist/types.d.ts +2 -0
- package/package.json +79 -0
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,75 @@
|
|
|
1
|
+
# React + TypeScript + Vite
|
|
2
|
+
|
|
3
|
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
|
4
|
+
|
|
5
|
+
Currently, two official plugins are available:
|
|
6
|
+
|
|
7
|
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
|
|
8
|
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
9
|
+
|
|
10
|
+
## React Compiler
|
|
11
|
+
|
|
12
|
+
The React Compiler is enabled on this template. See [this documentation](https://react.dev/learn/react-compiler) for more information.
|
|
13
|
+
|
|
14
|
+
Note: This will impact Vite dev & build performances.
|
|
15
|
+
|
|
16
|
+
## Expanding the ESLint configuration
|
|
17
|
+
|
|
18
|
+
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
export default defineConfig([
|
|
22
|
+
globalIgnores(['dist']),
|
|
23
|
+
{
|
|
24
|
+
files: ['**/*.{ts,tsx}'],
|
|
25
|
+
extends: [
|
|
26
|
+
// Other configs...
|
|
27
|
+
|
|
28
|
+
// Remove tseslint.configs.recommended and replace with this
|
|
29
|
+
tseslint.configs.recommendedTypeChecked,
|
|
30
|
+
// Alternatively, use this for stricter rules
|
|
31
|
+
tseslint.configs.strictTypeChecked,
|
|
32
|
+
// Optionally, add this for stylistic rules
|
|
33
|
+
tseslint.configs.stylisticTypeChecked,
|
|
34
|
+
|
|
35
|
+
// Other configs...
|
|
36
|
+
],
|
|
37
|
+
languageOptions: {
|
|
38
|
+
parserOptions: {
|
|
39
|
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
40
|
+
tsconfigRootDir: import.meta.dirname,
|
|
41
|
+
},
|
|
42
|
+
// other options...
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
])
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
// eslint.config.js
|
|
52
|
+
import reactX from 'eslint-plugin-react-x'
|
|
53
|
+
import reactDom from 'eslint-plugin-react-dom'
|
|
54
|
+
|
|
55
|
+
export default defineConfig([
|
|
56
|
+
globalIgnores(['dist']),
|
|
57
|
+
{
|
|
58
|
+
files: ['**/*.{ts,tsx}'],
|
|
59
|
+
extends: [
|
|
60
|
+
// Other configs...
|
|
61
|
+
// Enable lint rules for React
|
|
62
|
+
reactX.configs['recommended-typescript'],
|
|
63
|
+
// Enable lint rules for React DOM
|
|
64
|
+
reactDom.configs.recommended,
|
|
65
|
+
],
|
|
66
|
+
languageOptions: {
|
|
67
|
+
parserOptions: {
|
|
68
|
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
69
|
+
tsconfigRootDir: import.meta.dirname,
|
|
70
|
+
},
|
|
71
|
+
// other options...
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
])
|
|
75
|
+
```
|
|
@@ -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,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,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,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,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";
|
package/dist/index.d.ts
ADDED
|
@@ -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
|
+
};
|
package/dist/types.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "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": "https://github.com/juniorxsound/react-three-components"
|
|
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
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": ">=18",
|
|
45
|
+
"react-dom": ">=18",
|
|
46
|
+
"three": ">=0.150.0",
|
|
47
|
+
"@react-three/fiber": ">=8",
|
|
48
|
+
"@react-spring/web": ">=9",
|
|
49
|
+
"@use-gesture/react": ">=10"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@react-three/drei": "^10.7.7",
|
|
53
|
+
"@react-three/fiber": "^9.5.0",
|
|
54
|
+
"@react-spring/web": "^10.0.3",
|
|
55
|
+
"@use-gesture/react": "^10.3.1",
|
|
56
|
+
"react": "^19.2.0",
|
|
57
|
+
"react-dom": "^19.2.0",
|
|
58
|
+
"three": "^0.182.0",
|
|
59
|
+
"@eslint/js": "^9.39.1",
|
|
60
|
+
"@react-three/test-renderer": "^9.1.0",
|
|
61
|
+
"@storybook/addon-essentials": "^8.6.14",
|
|
62
|
+
"@storybook/react": "^8.6.15",
|
|
63
|
+
"@storybook/react-vite": "^8.6.15",
|
|
64
|
+
"@types/node": "^24.10.1",
|
|
65
|
+
"@types/react": "^19.2.5",
|
|
66
|
+
"@types/react-dom": "^19.2.3",
|
|
67
|
+
"@vitejs/plugin-react": "^5.1.1",
|
|
68
|
+
"babel-plugin-react-compiler": "^1.0.0",
|
|
69
|
+
"eslint": "^9.39.1",
|
|
70
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
71
|
+
"eslint-plugin-react-refresh": "^0.4.24",
|
|
72
|
+
"globals": "^16.5.0",
|
|
73
|
+
"storybook": "^8.6.15",
|
|
74
|
+
"typescript": "~5.9.3",
|
|
75
|
+
"typescript-eslint": "^8.46.4",
|
|
76
|
+
"vite": "^6.4.1",
|
|
77
|
+
"vitest": "^4.0.18"
|
|
78
|
+
}
|
|
79
|
+
}
|