react-two.js 0.2.3 → 0.8.22-r.1
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/README.md +104 -13
- package/dist/ArcSegment.d.ts +3 -2
- package/dist/Circle.d.ts +3 -2
- package/dist/Context.d.ts +8 -8
- package/dist/Ellipse.d.ts +3 -2
- package/dist/Events.d.ts +97 -0
- package/dist/Group.d.ts +2 -1
- package/dist/Image.d.ts +4 -2
- package/dist/ImageSequence.d.ts +4 -3
- package/dist/Line.d.ts +3 -2
- package/dist/Path.d.ts +3 -3
- package/dist/Points.d.ts +3 -2
- package/dist/Polygon.d.ts +3 -2
- package/dist/Properties.d.ts +1 -0
- package/dist/Provider.d.ts +3 -1
- package/dist/Rectangle.d.ts +3 -2
- package/dist/RoundedRectangle.d.ts +3 -2
- package/dist/SVG.d.ts +18 -0
- package/dist/Sprite.d.ts +4 -3
- package/dist/Star.d.ts +3 -2
- package/dist/Text.d.ts +4 -3
- package/dist/Texture.d.ts +1 -1
- package/dist/main.d.ts +1 -0
- package/dist/react-two-main.es.js +893 -416
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -10,16 +10,16 @@ npm install react-two.js react react-dom two.js
|
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
```jsx
|
|
13
|
-
import { Canvas,
|
|
13
|
+
import { Canvas, Rectangle, useFrame } from 'react-two.js'
|
|
14
14
|
|
|
15
|
-
function
|
|
15
|
+
function RotatingRectangle() {
|
|
16
16
|
const ref = useRef()
|
|
17
17
|
useFrame((t) => ref.current.rotation = t * 0.5)
|
|
18
|
-
return <
|
|
18
|
+
return <Rectangle ref={ref} radius={50} fill="#00AEFF" />
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
<Canvas width={800} height={600}>
|
|
22
|
-
<
|
|
21
|
+
<Canvas width={800} height={600} autostart={true}>
|
|
22
|
+
<RotatingRectangle />
|
|
23
23
|
</Canvas>
|
|
24
24
|
```
|
|
25
25
|
|
|
@@ -71,7 +71,7 @@ npm install react-two.js react react-dom two.js
|
|
|
71
71
|
- Two.js v0.8.21+
|
|
72
72
|
|
|
73
73
|
> [!IMPORTANT]
|
|
74
|
-
> react-two.js is a React renderer, it must pair with a major version of React,
|
|
74
|
+
> react-two.js is a React renderer, it must pair with a major version of React, like react-dom.
|
|
75
75
|
|
|
76
76
|
## First Steps
|
|
77
77
|
|
|
@@ -87,7 +87,7 @@ function App() {
|
|
|
87
87
|
<Canvas
|
|
88
88
|
width={800}
|
|
89
89
|
height={600}
|
|
90
|
-
type="
|
|
90
|
+
type="SVGRenderer"
|
|
91
91
|
autostart={true}
|
|
92
92
|
>
|
|
93
93
|
{/* Your scene goes here */}
|
|
@@ -96,12 +96,31 @@ function App() {
|
|
|
96
96
|
}
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
+
> [!IMPORTANT]
|
|
100
|
+
> **Canvas Children Restrictions:** Similar to [react-three-fiber](https://github.com/pmndrs/react-three-fiber), the `<Canvas>` component only accepts react-two.js components as children. DOM elements like `<div>` or `<span>` cannot be used inside Canvas. Place UI elements outside the Canvas:
|
|
101
|
+
>
|
|
102
|
+
> ```jsx
|
|
103
|
+
> // ✅ Correct
|
|
104
|
+
> <div>
|
|
105
|
+
> <Canvas>
|
|
106
|
+
> <Circle radius={50} />
|
|
107
|
+
> </Canvas>
|
|
108
|
+
> <div className="controls">UI here</div>
|
|
109
|
+
> </div>
|
|
110
|
+
>
|
|
111
|
+
> // ❌ Incorrect - will trigger warnings
|
|
112
|
+
> <Canvas>
|
|
113
|
+
> <div>This will warn</div>
|
|
114
|
+
> <Circle radius={50} />
|
|
115
|
+
> </Canvas>
|
|
116
|
+
> ```
|
|
117
|
+
|
|
99
118
|
### Adding Shapes
|
|
100
119
|
|
|
101
120
|
All Two.js primitives are available as React components:
|
|
102
121
|
|
|
103
122
|
```jsx
|
|
104
|
-
<Canvas width={800} height={600}>
|
|
123
|
+
<Canvas width={800} height={600} autostart={true}>
|
|
105
124
|
<Circle radius={50} fill="#00AEFF" x={400} y={300} />
|
|
106
125
|
<Rectangle width={100} height={60} stroke="#FF0000" linewidth={3} />
|
|
107
126
|
<Polygon sides={6} radius={40} fill="#00FF00" />
|
|
@@ -114,9 +133,9 @@ The `useFrame` hook runs on every frame, perfect for animations:
|
|
|
114
133
|
|
|
115
134
|
```jsx
|
|
116
135
|
import { useRef } from 'react'
|
|
117
|
-
import {
|
|
136
|
+
import { Rectangle, useFrame } from 'react-two.js'
|
|
118
137
|
|
|
119
|
-
function
|
|
138
|
+
function AnimatedRectangle() {
|
|
120
139
|
const ref = useRef()
|
|
121
140
|
|
|
122
141
|
useFrame((elapsed) => {
|
|
@@ -124,7 +143,7 @@ function AnimatedCircle() {
|
|
|
124
143
|
ref.current.scale = 1 + Math.sin(elapsed) * 0.2
|
|
125
144
|
})
|
|
126
145
|
|
|
127
|
-
return <
|
|
146
|
+
return <Rectangle ref={ref} width={50} height={50} fill="#00AEFF" />
|
|
128
147
|
}
|
|
129
148
|
```
|
|
130
149
|
|
|
@@ -136,9 +155,10 @@ Use `useTwo` to access the underlying Two.js instance:
|
|
|
136
155
|
import { useTwo } from 'react-two.js'
|
|
137
156
|
|
|
138
157
|
function Component() {
|
|
139
|
-
const {
|
|
158
|
+
const { two, width, height } = useTwo()
|
|
140
159
|
|
|
141
160
|
useEffect(() => {
|
|
161
|
+
two.play();
|
|
142
162
|
console.log('Canvas size:', width, height)
|
|
143
163
|
console.log('Two.js instance:', instance)
|
|
144
164
|
}, [])
|
|
@@ -169,6 +189,7 @@ function Component() {
|
|
|
169
189
|
- **`<Text>`** — Text rendering
|
|
170
190
|
|
|
171
191
|
#### Advanced
|
|
192
|
+
- **`<SVG>`** — Load and interpret SVG files or inline SVG markup
|
|
172
193
|
- **`<Image>`** - Basic image class inspired by Figma
|
|
173
194
|
- **`<Sprite>`** — Animated sprite sheets
|
|
174
195
|
- **`<ImageSequence>`** — Animated image sequence
|
|
@@ -228,7 +249,7 @@ import { useRef } from 'react'
|
|
|
228
249
|
import { Circle, RefCircle } from 'react-two.js'
|
|
229
250
|
|
|
230
251
|
function Component() {
|
|
231
|
-
const circleRef = useRef<RefCircle>(null)
|
|
252
|
+
const circleRef = useRef<RefCircle | null>(null)
|
|
232
253
|
|
|
233
254
|
useEffect(() => {
|
|
234
255
|
if (circleRef.current) {
|
|
@@ -287,11 +308,81 @@ function () {
|
|
|
287
308
|
}
|
|
288
309
|
```
|
|
289
310
|
|
|
311
|
+
### Loading SVG Files
|
|
312
|
+
|
|
313
|
+
Load external SVG files or use inline SVG markup with the `<SVG>` component:
|
|
314
|
+
|
|
315
|
+
```jsx
|
|
316
|
+
import { SVG } from 'react-two.js'
|
|
317
|
+
|
|
318
|
+
// Load from external URL
|
|
319
|
+
function Logo() {
|
|
320
|
+
return (
|
|
321
|
+
<SVG
|
|
322
|
+
src="/assets/logo.svg"
|
|
323
|
+
x={100}
|
|
324
|
+
y={100}
|
|
325
|
+
onLoad={(group, svg) => {
|
|
326
|
+
console.log('SVG loaded with', group.children.length, 'objects')
|
|
327
|
+
}}
|
|
328
|
+
onError={(error) => {
|
|
329
|
+
console.error('Failed to load SVG:', error)
|
|
330
|
+
}}
|
|
331
|
+
/>
|
|
332
|
+
)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Use inline SVG markup
|
|
336
|
+
function Icon() {
|
|
337
|
+
return (
|
|
338
|
+
<SVG
|
|
339
|
+
content={`
|
|
340
|
+
<svg viewBox="0 0 100 100">
|
|
341
|
+
<circle cx="50" cy="50" r="40" fill="#FF6B6B" />
|
|
342
|
+
<circle cx="35" cy="40" r="8" fill="white" />
|
|
343
|
+
<circle cx="65" cy="40" r="8" fill="white" />
|
|
344
|
+
</svg>
|
|
345
|
+
`}
|
|
346
|
+
x={200}
|
|
347
|
+
y={200}
|
|
348
|
+
scale={0.5}
|
|
349
|
+
/>
|
|
350
|
+
)
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Animate loaded SVG
|
|
354
|
+
function AnimatedIcon() {
|
|
355
|
+
const svgRef = useRef()
|
|
356
|
+
|
|
357
|
+
useFrame((elapsed) => {
|
|
358
|
+
if (svgRef.current) {
|
|
359
|
+
svgRef.current.rotation = Math.sin(elapsed) * 0.5
|
|
360
|
+
svgRef.current.scale = 1 + Math.sin(elapsed * 2) * 0.1
|
|
361
|
+
}
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
return <SVG ref={svgRef} src="/icon.svg" x={400} y={300} />
|
|
365
|
+
}
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
**SVG Props:**
|
|
369
|
+
- `src` — URL to external .svg file
|
|
370
|
+
- `content` — Inline SVG markup string
|
|
371
|
+
- `x`, `y` — Position
|
|
372
|
+
- `scale`, `rotation` — Transform properties
|
|
373
|
+
- `onLoad(group, svg)` — Callback when SVG loads successfully
|
|
374
|
+
- `onError(error)` — Callback when loading fails
|
|
375
|
+
- All Two.js Group properties (fill, stroke, opacity, etc.)
|
|
376
|
+
|
|
377
|
+
> [!NOTE]
|
|
378
|
+
> The SVG component uses Two.js's `load()` method which supports a subset of SVG 1.1 features. Complex SVG features like filters, animations (SMIL), and some advanced elements may not be fully supported. Refer to [Two.js SVG documentation](https://two.js.org/docs/two/#two-interpret) for details on supported features.
|
|
379
|
+
|
|
290
380
|
## Learn More
|
|
291
381
|
|
|
292
382
|
- **[Two.js Documentation](https://two.js.org/docs/)** — Complete Two.js API reference
|
|
293
383
|
- **[Two.js Examples](https://two.js.org/examples/)** — Interactive examples and demos
|
|
294
384
|
- **[Two.js Repository](https://github.com/jonobr1/two.js)** — Source code and issues
|
|
385
|
+
- **[Two.js Tutor on ChatGPT](https://chatgpt.com/g/g-hkcTX8uPm-two-js-tutor)** - Talk to a custom ChatGPT trained on Two.js and react-two.js
|
|
295
386
|
|
|
296
387
|
## Development
|
|
297
388
|
|
package/dist/ArcSegment.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ArcSegment as Instance } from 'two.js/src/shapes/arc-segment';
|
|
3
|
+
import { type EventHandlers } from './Properties';
|
|
3
4
|
export type RefArcSegment = Instance;
|
|
4
5
|
export declare const ArcSegment: React.ForwardRefExoticComponent<{
|
|
6
|
+
visible?: boolean | undefined;
|
|
5
7
|
renderer?: {
|
|
6
8
|
type: "element" | "group" | "path" | "text" | "points" | string;
|
|
7
9
|
elem?: SVGGElement | SVGPathElement | SVGTextElement | SVGPatternElement | SVGDefsElement | SVGGradientElement | SVGLinearGradientElement | SVGRadialGradientElement | SVGImageElement | SVGClipPathElement | SVGStopElement | SVGPatternElement;
|
|
@@ -21,7 +23,6 @@ export declare const ArcSegment: React.ForwardRefExoticComponent<{
|
|
|
21
23
|
stroke?: string | import("two.js/src/effects/gradient").Gradient | import("two.js/src/effects/texture").Texture | undefined;
|
|
22
24
|
linewidth?: number | undefined;
|
|
23
25
|
opacity?: number | undefined;
|
|
24
|
-
visible?: boolean | undefined;
|
|
25
26
|
cap?: import("two.js/src/path").CapProperties | undefined;
|
|
26
27
|
join?: import("two.js/src/path").JoinProperties | undefined;
|
|
27
28
|
miter?: number | undefined;
|
|
@@ -42,6 +43,6 @@ export declare const ArcSegment: React.ForwardRefExoticComponent<{
|
|
|
42
43
|
x?: number;
|
|
43
44
|
y?: number;
|
|
44
45
|
resolution?: number;
|
|
45
|
-
} & {
|
|
46
|
+
} & Partial<EventHandlers> & {
|
|
46
47
|
children?: React.ReactNode | undefined;
|
|
47
48
|
} & React.RefAttributes<Instance>>;
|
package/dist/Circle.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Circle as Instance } from 'two.js/src/shapes/circle';
|
|
3
|
+
import { type EventHandlers } from './Properties';
|
|
3
4
|
export type RefCircle = Instance;
|
|
4
5
|
export declare const Circle: React.ForwardRefExoticComponent<{
|
|
6
|
+
visible?: boolean | undefined;
|
|
5
7
|
renderer?: {
|
|
6
8
|
type: "element" | "group" | "path" | "text" | "points" | string;
|
|
7
9
|
elem?: SVGGElement | SVGPathElement | SVGTextElement | SVGPatternElement | SVGDefsElement | SVGGradientElement | SVGLinearGradientElement | SVGRadialGradientElement | SVGImageElement | SVGClipPathElement | SVGStopElement | SVGPatternElement;
|
|
@@ -21,7 +23,6 @@ export declare const Circle: React.ForwardRefExoticComponent<{
|
|
|
21
23
|
stroke?: string | import("two.js/src/effects/gradient").Gradient | import("two.js/src/effects/texture").Texture | undefined;
|
|
22
24
|
linewidth?: number | undefined;
|
|
23
25
|
opacity?: number | undefined;
|
|
24
|
-
visible?: boolean | undefined;
|
|
25
26
|
cap?: import("two.js/src/path").CapProperties | undefined;
|
|
26
27
|
join?: import("two.js/src/path").JoinProperties | undefined;
|
|
27
28
|
miter?: number | undefined;
|
|
@@ -39,6 +40,6 @@ export declare const Circle: React.ForwardRefExoticComponent<{
|
|
|
39
40
|
x?: number;
|
|
40
41
|
y?: number;
|
|
41
42
|
resolution?: number;
|
|
42
|
-
} & {
|
|
43
|
+
} & Partial<EventHandlers> & {
|
|
43
44
|
children?: React.ReactNode | undefined;
|
|
44
45
|
} & React.RefAttributes<Instance>>;
|
package/dist/Context.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import Two from 'two.js';
|
|
2
2
|
import type { Group } from 'two.js/src/group';
|
|
3
|
-
|
|
3
|
+
import type { Shape } from 'two.js/src/shape';
|
|
4
|
+
import type { EventHandlers } from './Events';
|
|
5
|
+
export interface TwoContext {
|
|
4
6
|
two: Two | null;
|
|
5
7
|
parent: Group | null;
|
|
6
8
|
width: number;
|
|
7
9
|
height: number;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
height: number;
|
|
14
|
-
};
|
|
10
|
+
registerEventShape: (shape: Shape | Group, handlers: Partial<EventHandlers>, parent?: Group) => void;
|
|
11
|
+
unregisterEventShape: (shape: Shape | Group) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const Context: import("react").Context<TwoContext>;
|
|
14
|
+
export declare const useTwo: () => TwoContext;
|
|
15
15
|
export declare const useFrame: (callback: (elapsed: number, frameDelta: number) => void, deps?: unknown[]) => void;
|
package/dist/Ellipse.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Ellipse as Instance } from 'two.js/src/shapes/ellipse';
|
|
3
|
+
import { type EventHandlers } from './Properties';
|
|
3
4
|
export type RefEllipse = Instance;
|
|
4
5
|
export declare const Ellipse: React.ForwardRefExoticComponent<{
|
|
6
|
+
visible?: boolean | undefined;
|
|
5
7
|
renderer?: {
|
|
6
8
|
type: "element" | "group" | "path" | "text" | "points" | string;
|
|
7
9
|
elem?: SVGGElement | SVGPathElement | SVGTextElement | SVGPatternElement | SVGDefsElement | SVGGradientElement | SVGLinearGradientElement | SVGRadialGradientElement | SVGImageElement | SVGClipPathElement | SVGStopElement | SVGPatternElement;
|
|
@@ -21,7 +23,6 @@ export declare const Ellipse: React.ForwardRefExoticComponent<{
|
|
|
21
23
|
stroke?: string | import("two.js/src/effects/gradient").Gradient | import("two.js/src/effects/texture").Texture | undefined;
|
|
22
24
|
linewidth?: number | undefined;
|
|
23
25
|
opacity?: number | undefined;
|
|
24
|
-
visible?: boolean | undefined;
|
|
25
26
|
cap?: import("two.js/src/path").CapProperties | undefined;
|
|
26
27
|
join?: import("two.js/src/path").JoinProperties | undefined;
|
|
27
28
|
miter?: number | undefined;
|
|
@@ -40,6 +41,6 @@ export declare const Ellipse: React.ForwardRefExoticComponent<{
|
|
|
40
41
|
x?: number;
|
|
41
42
|
y?: number;
|
|
42
43
|
resolution?: number;
|
|
43
|
-
} & {
|
|
44
|
+
} & Partial<EventHandlers> & {
|
|
44
45
|
children?: React.ReactNode | undefined;
|
|
45
46
|
} & React.RefAttributes<Instance | null>>;
|
package/dist/Events.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event system for react-two.js
|
|
3
|
+
* Implements R3F-style event handlers using Two.js hit testing
|
|
4
|
+
*/
|
|
5
|
+
import Two from 'two.js';
|
|
6
|
+
import type { Shape } from 'two.js/src/shape';
|
|
7
|
+
import type { Group } from 'two.js/src/group';
|
|
8
|
+
/**
|
|
9
|
+
* Event object passed to event handlers
|
|
10
|
+
* Similar to React Three Fiber's ThreeEvent
|
|
11
|
+
*/
|
|
12
|
+
export interface TwoEvent<T = Shape> {
|
|
13
|
+
/** The original DOM event */
|
|
14
|
+
nativeEvent: PointerEvent | MouseEvent | WheelEvent;
|
|
15
|
+
/** The shape that was directly hit */
|
|
16
|
+
target: T;
|
|
17
|
+
/** The shape that has the event handler (may be ancestor due to bubbling) */
|
|
18
|
+
currentTarget: T;
|
|
19
|
+
/** The point in Two.js coordinate space (center origin) */
|
|
20
|
+
point: {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
};
|
|
24
|
+
/** Stop event from bubbling to parent groups */
|
|
25
|
+
stopPropagation: () => void;
|
|
26
|
+
/** Whether propagation was stopped */
|
|
27
|
+
stopped: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Event handler function type
|
|
31
|
+
*/
|
|
32
|
+
export type EventHandler<T = Shape> = (event: TwoEvent<T>) => void;
|
|
33
|
+
/**
|
|
34
|
+
* All supported event handlers (matching R3F API)
|
|
35
|
+
*/
|
|
36
|
+
export interface EventHandlers {
|
|
37
|
+
onClick?: EventHandler;
|
|
38
|
+
onContextMenu?: EventHandler;
|
|
39
|
+
onDoubleClick?: EventHandler;
|
|
40
|
+
onWheel?: EventHandler;
|
|
41
|
+
onPointerDown?: EventHandler;
|
|
42
|
+
onPointerUp?: EventHandler;
|
|
43
|
+
onPointerOver?: EventHandler;
|
|
44
|
+
onPointerOut?: EventHandler;
|
|
45
|
+
onPointerEnter?: EventHandler;
|
|
46
|
+
onPointerLeave?: EventHandler;
|
|
47
|
+
onPointerMove?: EventHandler;
|
|
48
|
+
onPointerCancel?: EventHandler;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Event handler names for iteration
|
|
52
|
+
*/
|
|
53
|
+
export declare const EVENT_HANDLER_NAMES: readonly ["onClick", "onContextMenu", "onDoubleClick", "onWheel", "onPointerDown", "onPointerUp", "onPointerOver", "onPointerOut", "onPointerEnter", "onPointerLeave", "onPointerMove", "onPointerCancel"];
|
|
54
|
+
/**
|
|
55
|
+
* Shape registration entry for event system
|
|
56
|
+
*/
|
|
57
|
+
export interface EventShape {
|
|
58
|
+
shape: Shape | Group;
|
|
59
|
+
handlers: Partial<EventHandlers>;
|
|
60
|
+
parent?: Group;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Convert DOM event coordinates to Two.js coordinate space
|
|
64
|
+
* Two.js uses center origin (0,0 at center of canvas)
|
|
65
|
+
*/
|
|
66
|
+
export declare function getCanvasCoordinates(nativeEvent: PointerEvent | MouseEvent, canvas: HTMLElement, two: Two): {
|
|
67
|
+
x: number;
|
|
68
|
+
y: number;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Convert DOM event coordinates to world-space coordinates for hit testing
|
|
72
|
+
* World-space uses top-left origin (same as DOM but relative to canvas)
|
|
73
|
+
*/
|
|
74
|
+
export declare function getWorldCoordinates(nativeEvent: PointerEvent | MouseEvent, canvas: HTMLElement): {
|
|
75
|
+
x: number;
|
|
76
|
+
y: number;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Create a TwoEvent object from a DOM event
|
|
80
|
+
*/
|
|
81
|
+
export declare function createTwoEvent<T extends Shape | Group>(nativeEvent: PointerEvent | MouseEvent | WheelEvent, target: T, currentTarget: T, point: {
|
|
82
|
+
x: number;
|
|
83
|
+
y: number;
|
|
84
|
+
}): TwoEvent<T>;
|
|
85
|
+
/**
|
|
86
|
+
* Check if a shape contains a point using Two.js hit testing
|
|
87
|
+
*/
|
|
88
|
+
export declare function hitTest(shape: Shape | Group, x: number, y: number): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Get all shapes at a point, sorted by depth (front to back)
|
|
91
|
+
* Uses scene graph traversal to maintain z-order
|
|
92
|
+
*/
|
|
93
|
+
export declare function getShapesAtPoint(shapes: Map<Shape | Group, EventShape>, x: number, y: number): Array<Shape | Group>;
|
|
94
|
+
/**
|
|
95
|
+
* Get the parent hierarchy for event bubbling
|
|
96
|
+
*/
|
|
97
|
+
export declare function getParentHierarchy(shape: Shape | Group, shapes: Map<Shape | Group, EventShape>): Array<Shape | Group>;
|
package/dist/Group.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Group as Instance } from 'two.js/src/group';
|
|
3
|
+
import { type EventHandlers } from './Properties';
|
|
3
4
|
export type RefGroup = Instance;
|
|
4
5
|
export declare const Group: React.ForwardRefExoticComponent<{
|
|
5
6
|
renderer?: {
|
|
@@ -29,6 +30,6 @@ export declare const Group: React.ForwardRefExoticComponent<{
|
|
|
29
30
|
} & {
|
|
30
31
|
x?: number;
|
|
31
32
|
y?: number;
|
|
32
|
-
} & {
|
|
33
|
+
} & Partial<EventHandlers> & {
|
|
33
34
|
children?: React.ReactNode | undefined;
|
|
34
35
|
} & React.RefAttributes<Instance>>;
|
package/dist/Image.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Image as Instance } from 'two.js/src/effects/image';
|
|
3
3
|
import type { Texture } from 'two.js/src/effects/texture';
|
|
4
|
+
import { type EventHandlers } from './Properties';
|
|
4
5
|
export type RefImage = Instance;
|
|
5
6
|
export declare const Image: React.ForwardRefExoticComponent<{
|
|
7
|
+
visible?: boolean | undefined;
|
|
6
8
|
renderer?: {
|
|
7
9
|
type: "element" | "group" | "path" | "text" | "points" | string;
|
|
8
10
|
elem?: SVGGElement | SVGPathElement | SVGTextElement | SVGPatternElement | SVGDefsElement | SVGGradientElement | SVGLinearGradientElement | SVGRadialGradientElement | SVGImageElement | SVGClipPathElement | SVGStopElement | SVGPatternElement;
|
|
@@ -22,7 +24,6 @@ export declare const Image: React.ForwardRefExoticComponent<{
|
|
|
22
24
|
stroke?: string | import("two.js/src/effects/gradient").Gradient | Texture | undefined;
|
|
23
25
|
linewidth?: number | undefined;
|
|
24
26
|
opacity?: number | undefined;
|
|
25
|
-
visible?: boolean | undefined;
|
|
26
27
|
cap?: import("two.js/src/path").CapProperties | undefined;
|
|
27
28
|
join?: import("two.js/src/path").JoinProperties | undefined;
|
|
28
29
|
miter?: number | undefined;
|
|
@@ -43,7 +44,8 @@ export declare const Image: React.ForwardRefExoticComponent<{
|
|
|
43
44
|
x?: number;
|
|
44
45
|
y?: number;
|
|
45
46
|
mode?: string;
|
|
47
|
+
src?: string | Texture;
|
|
46
48
|
texture?: Texture;
|
|
47
|
-
} & {
|
|
49
|
+
} & Partial<EventHandlers> & {
|
|
48
50
|
children?: React.ReactNode | undefined;
|
|
49
51
|
} & React.RefAttributes<Instance>>;
|
package/dist/ImageSequence.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ImageSequence as Instance } from 'two.js/src/effects/image-sequence';
|
|
3
3
|
import type { Texture } from 'two.js/src/effects/texture';
|
|
4
|
+
import { type EventHandlers } from './Properties';
|
|
4
5
|
export type RefImageSequence = Instance;
|
|
5
6
|
export declare const ImageSequence: React.ForwardRefExoticComponent<{
|
|
7
|
+
visible?: boolean | undefined;
|
|
6
8
|
renderer?: {
|
|
7
9
|
type: "element" | "group" | "path" | "text" | "points" | string;
|
|
8
10
|
elem?: SVGGElement | SVGPathElement | SVGTextElement | SVGPatternElement | SVGDefsElement | SVGGradientElement | SVGLinearGradientElement | SVGRadialGradientElement | SVGImageElement | SVGClipPathElement | SVGStopElement | SVGPatternElement;
|
|
@@ -22,7 +24,6 @@ export declare const ImageSequence: React.ForwardRefExoticComponent<{
|
|
|
22
24
|
stroke?: string | import("two.js/src/effects/gradient").Gradient | Texture | undefined;
|
|
23
25
|
linewidth?: number | undefined;
|
|
24
26
|
opacity?: number | undefined;
|
|
25
|
-
visible?: boolean | undefined;
|
|
26
27
|
cap?: import("two.js/src/path").CapProperties | undefined;
|
|
27
28
|
join?: import("two.js/src/path").JoinProperties | undefined;
|
|
28
29
|
miter?: number | undefined;
|
|
@@ -41,10 +42,10 @@ export declare const ImageSequence: React.ForwardRefExoticComponent<{
|
|
|
41
42
|
frameRate?: number | undefined;
|
|
42
43
|
index?: number | undefined;
|
|
43
44
|
} & {
|
|
44
|
-
|
|
45
|
+
src?: string | string[] | Texture | Texture[];
|
|
45
46
|
x?: number;
|
|
46
47
|
y?: number;
|
|
47
48
|
autoPlay?: boolean;
|
|
48
|
-
} & {
|
|
49
|
+
} & Partial<EventHandlers> & {
|
|
49
50
|
children?: React.ReactNode | undefined;
|
|
50
51
|
} & React.RefAttributes<Instance>>;
|
package/dist/Line.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Line as Instance } from 'two.js/src/shapes/line';
|
|
3
|
+
import { type EventHandlers } from './Properties';
|
|
3
4
|
export type RefLine = Instance;
|
|
4
5
|
export declare const Line: React.ForwardRefExoticComponent<{
|
|
6
|
+
visible?: boolean | undefined;
|
|
5
7
|
renderer?: {
|
|
6
8
|
type: "element" | "group" | "path" | "text" | "points" | string;
|
|
7
9
|
elem?: SVGGElement | SVGPathElement | SVGTextElement | SVGPatternElement | SVGDefsElement | SVGGradientElement | SVGLinearGradientElement | SVGRadialGradientElement | SVGImageElement | SVGClipPathElement | SVGStopElement | SVGPatternElement;
|
|
@@ -21,7 +23,6 @@ export declare const Line: React.ForwardRefExoticComponent<{
|
|
|
21
23
|
stroke?: string | import("two.js/src/effects/gradient").Gradient | import("two.js/src/effects/texture").Texture | undefined;
|
|
22
24
|
linewidth?: number | undefined;
|
|
23
25
|
opacity?: number | undefined;
|
|
24
|
-
visible?: boolean | undefined;
|
|
25
26
|
cap?: import("two.js/src/path").CapProperties | undefined;
|
|
26
27
|
join?: import("two.js/src/path").JoinProperties | undefined;
|
|
27
28
|
miter?: number | undefined;
|
|
@@ -41,6 +42,6 @@ export declare const Line: React.ForwardRefExoticComponent<{
|
|
|
41
42
|
y1?: number;
|
|
42
43
|
x2?: number;
|
|
43
44
|
y2?: number;
|
|
44
|
-
} & {
|
|
45
|
+
} & Partial<EventHandlers> & {
|
|
45
46
|
children?: React.ReactNode | undefined;
|
|
46
47
|
} & React.RefAttributes<Instance>>;
|
package/dist/Path.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Path as Instance } from 'two.js/src/path';
|
|
3
|
-
import { ShapeProps } from './Properties';
|
|
3
|
+
import { ShapeProps, type EventHandlers } from './Properties';
|
|
4
4
|
export type PathProps = ShapeProps | 'fill' | 'stroke' | 'linewidth' | 'opacity' | 'visible' | 'cap' | 'join' | 'miter' | 'closed' | 'curved' | 'automatic' | 'beginning' | 'ending' | 'dashes' | 'vertices';
|
|
5
5
|
export type RefPath = Instance;
|
|
6
6
|
export declare const Path: React.ForwardRefExoticComponent<{
|
|
7
|
+
visible?: boolean | undefined;
|
|
7
8
|
renderer?: {
|
|
8
9
|
type: "element" | "group" | "path" | "text" | "points" | string;
|
|
9
10
|
elem?: SVGGElement | SVGPathElement | SVGTextElement | SVGPatternElement | SVGDefsElement | SVGGradientElement | SVGLinearGradientElement | SVGRadialGradientElement | SVGImageElement | SVGClipPathElement | SVGStopElement | SVGPatternElement;
|
|
@@ -23,7 +24,6 @@ export declare const Path: React.ForwardRefExoticComponent<{
|
|
|
23
24
|
stroke?: string | import("two.js/src/effects/gradient").Gradient | import("two.js/src/effects/texture").Texture | undefined;
|
|
24
25
|
linewidth?: number | undefined;
|
|
25
26
|
opacity?: number | undefined;
|
|
26
|
-
visible?: boolean | undefined;
|
|
27
27
|
cap?: import("two.js/src/path").CapProperties | undefined;
|
|
28
28
|
join?: import("two.js/src/path").JoinProperties | undefined;
|
|
29
29
|
miter?: number | undefined;
|
|
@@ -40,6 +40,6 @@ export declare const Path: React.ForwardRefExoticComponent<{
|
|
|
40
40
|
manual?: boolean;
|
|
41
41
|
x?: number;
|
|
42
42
|
y?: number;
|
|
43
|
-
} & {
|
|
43
|
+
} & Partial<EventHandlers> & {
|
|
44
44
|
children?: React.ReactNode | undefined;
|
|
45
45
|
} & React.RefAttributes<Instance>>;
|
package/dist/Points.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Points as Instance } from 'two.js/src/shapes/points';
|
|
3
|
+
import { type EventHandlers } from './Properties';
|
|
3
4
|
export type RefPoints = Instance;
|
|
4
5
|
export declare const Points: React.ForwardRefExoticComponent<{
|
|
6
|
+
visible?: boolean | undefined;
|
|
5
7
|
renderer?: {
|
|
6
8
|
type: "element" | "group" | "path" | "text" | "points" | string;
|
|
7
9
|
elem?: SVGGElement | SVGPathElement | SVGTextElement | SVGPatternElement | SVGDefsElement | SVGGradientElement | SVGLinearGradientElement | SVGRadialGradientElement | SVGImageElement | SVGClipPathElement | SVGStopElement | SVGPatternElement;
|
|
@@ -21,7 +23,6 @@ export declare const Points: React.ForwardRefExoticComponent<{
|
|
|
21
23
|
stroke?: string | import("two.js/src/effects/gradient").Gradient | import("two.js/src/effects/texture").Texture | undefined;
|
|
22
24
|
linewidth?: number | undefined;
|
|
23
25
|
opacity?: number | undefined;
|
|
24
|
-
visible?: boolean | undefined;
|
|
25
26
|
beginning?: number | undefined;
|
|
26
27
|
ending?: number | undefined;
|
|
27
28
|
dashes?: (number[] & {
|
|
@@ -33,6 +34,6 @@ export declare const Points: React.ForwardRefExoticComponent<{
|
|
|
33
34
|
} & {
|
|
34
35
|
x?: number;
|
|
35
36
|
y?: number;
|
|
36
|
-
} & {
|
|
37
|
+
} & Partial<EventHandlers> & {
|
|
37
38
|
children?: React.ReactNode | undefined;
|
|
38
39
|
} & React.RefAttributes<Instance>>;
|
package/dist/Polygon.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Polygon as Instance } from 'two.js/src/shapes/polygon';
|
|
3
|
+
import { type EventHandlers } from './Properties';
|
|
3
4
|
export type RefPolygon = Instance;
|
|
4
5
|
export declare const Polygon: React.ForwardRefExoticComponent<{
|
|
6
|
+
visible?: boolean | undefined;
|
|
5
7
|
renderer?: {
|
|
6
8
|
type: "element" | "group" | "path" | "text" | "points" | string;
|
|
7
9
|
elem?: SVGGElement | SVGPathElement | SVGTextElement | SVGPatternElement | SVGDefsElement | SVGGradientElement | SVGLinearGradientElement | SVGRadialGradientElement | SVGImageElement | SVGClipPathElement | SVGStopElement | SVGPatternElement;
|
|
@@ -21,7 +23,6 @@ export declare const Polygon: React.ForwardRefExoticComponent<{
|
|
|
21
23
|
stroke?: string | import("two.js/src/effects/gradient").Gradient | import("two.js/src/effects/texture").Texture | undefined;
|
|
22
24
|
linewidth?: number | undefined;
|
|
23
25
|
opacity?: number | undefined;
|
|
24
|
-
visible?: boolean | undefined;
|
|
25
26
|
cap?: import("two.js/src/path").CapProperties | undefined;
|
|
26
27
|
join?: import("two.js/src/path").JoinProperties | undefined;
|
|
27
28
|
miter?: number | undefined;
|
|
@@ -41,6 +42,6 @@ export declare const Polygon: React.ForwardRefExoticComponent<{
|
|
|
41
42
|
x?: number;
|
|
42
43
|
y?: number;
|
|
43
44
|
radius?: number;
|
|
44
|
-
} & {
|
|
45
|
+
} & Partial<EventHandlers> & {
|
|
45
46
|
children?: React.ReactNode | undefined;
|
|
46
47
|
} & React.RefAttributes<Instance>>;
|
package/dist/Properties.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type { EventHandlers, EventHandler, TwoEvent } from './Events';
|
|
1
2
|
export type ElementProps = 'renderer' | 'id' | 'className';
|
|
2
3
|
export type ShapeProps = ElementProps | 'position' | 'rotation' | 'scale' | 'skewX' | 'skewY' | 'matrix' | 'worldMatrix';
|
|
3
4
|
export type GradientProps = ElementProps | 'spread' | 'units' | 'stops';
|
package/dist/Provider.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import React from 'react';
|
|
|
2
2
|
import Two from 'two.js';
|
|
3
3
|
type TwoConstructorProps = ConstructorParameters<typeof Two>[0];
|
|
4
4
|
type TwoConstructorPropsKeys = NonNullable<TwoConstructorProps>;
|
|
5
|
-
type ComponentProps = React.PropsWithChildren<TwoConstructorPropsKeys
|
|
5
|
+
type ComponentProps = React.PropsWithChildren<TwoConstructorPropsKeys & {
|
|
6
|
+
onPointerMissed?: (event: PointerEvent) => void;
|
|
7
|
+
}>;
|
|
6
8
|
export declare const Provider: React.FC<ComponentProps>;
|
|
7
9
|
export {};
|
package/dist/Rectangle.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Rectangle as Instance } from 'two.js/src/shapes/rectangle';
|
|
3
3
|
import { PathProps } from './Path';
|
|
4
|
+
import { type EventHandlers } from './Properties';
|
|
4
5
|
export type RectangleProps = PathProps | 'width' | 'height';
|
|
5
6
|
export type RefRectangle = Instance;
|
|
6
7
|
export declare const Rectangle: React.ForwardRefExoticComponent<{
|
|
8
|
+
visible?: boolean | undefined;
|
|
7
9
|
renderer?: {
|
|
8
10
|
type: "element" | "group" | "path" | "text" | "points" | string;
|
|
9
11
|
elem?: SVGGElement | SVGPathElement | SVGTextElement | SVGPatternElement | SVGDefsElement | SVGGradientElement | SVGLinearGradientElement | SVGRadialGradientElement | SVGImageElement | SVGClipPathElement | SVGStopElement | SVGPatternElement;
|
|
@@ -23,7 +25,6 @@ export declare const Rectangle: React.ForwardRefExoticComponent<{
|
|
|
23
25
|
stroke?: string | import("two.js/src/effects/gradient").Gradient | import("two.js/src/effects/texture").Texture | undefined;
|
|
24
26
|
linewidth?: number | undefined;
|
|
25
27
|
opacity?: number | undefined;
|
|
26
|
-
visible?: boolean | undefined;
|
|
27
28
|
cap?: import("two.js/src/path").CapProperties | undefined;
|
|
28
29
|
join?: import("two.js/src/path").JoinProperties | undefined;
|
|
29
30
|
miter?: number | undefined;
|
|
@@ -41,6 +42,6 @@ export declare const Rectangle: React.ForwardRefExoticComponent<{
|
|
|
41
42
|
} & {
|
|
42
43
|
x?: number;
|
|
43
44
|
y?: number;
|
|
44
|
-
} & {
|
|
45
|
+
} & Partial<EventHandlers> & {
|
|
45
46
|
children?: React.ReactNode | undefined;
|
|
46
47
|
} & React.RefAttributes<Instance>>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { RoundedRectangle as Instance } from 'two.js/src/shapes/rounded-rectangle';
|
|
3
|
+
import { type EventHandlers } from './Properties';
|
|
3
4
|
export type RefRoundedRectangle = Instance;
|
|
4
5
|
export declare const RoundedRectangle: React.ForwardRefExoticComponent<{
|
|
6
|
+
visible?: boolean | undefined;
|
|
5
7
|
renderer?: {
|
|
6
8
|
type: "element" | "group" | "path" | "text" | "points" | string;
|
|
7
9
|
elem?: SVGGElement | SVGPathElement | SVGTextElement | SVGPatternElement | SVGDefsElement | SVGGradientElement | SVGLinearGradientElement | SVGRadialGradientElement | SVGImageElement | SVGClipPathElement | SVGStopElement | SVGPatternElement;
|
|
@@ -21,7 +23,6 @@ export declare const RoundedRectangle: React.ForwardRefExoticComponent<{
|
|
|
21
23
|
stroke?: string | import("two.js/src/effects/gradient").Gradient | import("two.js/src/effects/texture").Texture | undefined;
|
|
22
24
|
linewidth?: number | undefined;
|
|
23
25
|
opacity?: number | undefined;
|
|
24
|
-
visible?: boolean | undefined;
|
|
25
26
|
cap?: import("two.js/src/path").CapProperties | undefined;
|
|
26
27
|
join?: import("two.js/src/path").JoinProperties | undefined;
|
|
27
28
|
miter?: number | undefined;
|
|
@@ -40,6 +41,6 @@ export declare const RoundedRectangle: React.ForwardRefExoticComponent<{
|
|
|
40
41
|
} & {
|
|
41
42
|
x?: number;
|
|
42
43
|
y?: number;
|
|
43
|
-
} & {
|
|
44
|
+
} & Partial<EventHandlers> & {
|
|
44
45
|
children?: React.ReactNode | undefined;
|
|
45
46
|
} & React.RefAttributes<Instance>>;
|