@lovo/matter-react 0.3.0 → 0.4.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/CHANGELOG.md +14 -0
- package/README.md +9 -5
- package/dist/index.cjs +183 -174
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +91 -83
- package/dist/index.d.ts +91 -83
- package/dist/index.js +184 -175
- package/dist/index.js.map +1 -1
- package/package.json +29 -29
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode, CSSProperties, DependencyList } from 'react';
|
|
3
|
-
import { Scene, Camera } from 'three';
|
|
4
|
-
import { Node, MeshBasicNodeMaterial } from 'three/webgpu';
|
|
5
3
|
import { ShaderNodeObject } from 'three/tsl';
|
|
6
|
-
import {
|
|
4
|
+
import { Node, MeshBasicNodeMaterial } from 'three/webgpu';
|
|
5
|
+
import { Vec2, CursorInputOptions, GpuRenderer, FrameScheduler } from '@lovo/matter';
|
|
6
|
+
import { Scene, Camera } from 'three';
|
|
7
|
+
|
|
8
|
+
interface FallbackBoundaryProps {
|
|
9
|
+
/** Rendered until WebGPU/WebGL is available on the client. */
|
|
10
|
+
fallback?: ReactNode;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Render `fallback` until the component mounts on the client. Gates the
|
|
15
|
+
* children behind client-only mounting so SSR/no-WebGPU users see a
|
|
16
|
+
* sensible static placeholder rather than a flash of nothing.
|
|
17
|
+
*/
|
|
18
|
+
declare function FallbackBoundary({ fallback, children }: FallbackBoundaryProps): react_jsx_runtime.JSX.Element;
|
|
7
19
|
|
|
8
|
-
|
|
20
|
+
type MonitorAnchor = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
21
|
+
interface ShaderMonitorProps {
|
|
22
|
+
anchor?: MonitorAnchor;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Dev-only overlay that displays the current scene's FPS, tick count, and
|
|
26
|
+
* paused/idle state. Reads from the surrounding `<ShaderScene>` via context
|
|
27
|
+
* and subscribes to its scheduler. Renders nothing useful if mounted outside
|
|
28
|
+
* a scene.
|
|
29
|
+
*/
|
|
30
|
+
declare function ShaderMonitor({ anchor }: ShaderMonitorProps): react_jsx_runtime.JSX.Element;
|
|
31
|
+
|
|
32
|
+
interface ShaderSceneProps {
|
|
9
33
|
children?: ReactNode;
|
|
10
34
|
/** Rendered server-side and during WebGPU init. Default: empty. */
|
|
11
35
|
fallback?: ReactNode;
|
|
@@ -17,37 +41,31 @@ interface MatterSceneProps {
|
|
|
17
41
|
/**
|
|
18
42
|
* Owns a canvas, a Three.js renderer (WebGPU + WebGL2 fallback), an
|
|
19
43
|
* orthographic camera covering the canvas, an empty Scene, and a
|
|
20
|
-
*
|
|
44
|
+
* FrameScheduler. Children consume these via useShaderContext().
|
|
21
45
|
*/
|
|
22
|
-
declare function
|
|
46
|
+
declare function ShaderScene(props: ShaderSceneProps): react_jsx_runtime.JSX.Element;
|
|
23
47
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
scene: Scene;
|
|
28
|
-
camera: Camera;
|
|
29
|
-
scheduler: MatterScheduler;
|
|
30
|
-
registerOverlay: (transform: OverlayTransform) => () => void;
|
|
48
|
+
interface AnimatableSignal<T> {
|
|
49
|
+
get(): T;
|
|
50
|
+
on(event: 'change', cb: (value: T) => void): () => void;
|
|
31
51
|
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Read the matter scene context. Returns null when called outside a
|
|
35
|
-
* <MatterScene>; useShaderMaterial and similar hooks check this and
|
|
36
|
-
* auto-provision a scene if missing (auto-wrap behavior).
|
|
37
|
-
*/
|
|
38
|
-
declare function useMatterContext(): MatterContextValue | null;
|
|
39
|
-
|
|
40
|
-
/** A TSL fragment that produces a color. Accept any Node or TSL-wrapped node. */
|
|
41
|
-
type ColorTSL = Node | ShaderNodeObject<Node>;
|
|
52
|
+
type AnimatableProp<T> = T | AnimatableSignal<T>;
|
|
42
53
|
/**
|
|
43
|
-
* Bind
|
|
44
|
-
*
|
|
54
|
+
* Bind an AnimatableProp<T> to a TSL uniform. Plain values create a
|
|
55
|
+
* static uniform that updates only when the prop changes (React render
|
|
56
|
+
* path). Signals subscribe via .on('change') and write into the uniform
|
|
57
|
+
* imperatively without re-rendering.
|
|
45
58
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
59
|
+
* Returns a chainable TSL node with `.value: T` exposed for callers that
|
|
60
|
+
* need to read the current uniform value imperatively (e.g., to compute
|
|
61
|
+
* derived JS-side math). The runtime object is a UniformNode<T>; we
|
|
62
|
+
* present it as `ShaderNodeObject<Node> & { value: T }` because TSL's
|
|
63
|
+
* generic invariance blocks the more precise type from flowing through
|
|
64
|
+
* downstream consumers like OverlayTransform.
|
|
49
65
|
*/
|
|
50
|
-
declare function
|
|
66
|
+
declare function useAnimatableUniform<T>(value: AnimatableProp<T>): ShaderNodeObject<Node> & {
|
|
67
|
+
value: T;
|
|
68
|
+
};
|
|
51
69
|
|
|
52
70
|
interface CursorSignal {
|
|
53
71
|
/** Current smoothed cursor position (Vec2 in 0..1 viewport space). */
|
|
@@ -56,7 +74,7 @@ interface CursorSignal {
|
|
|
56
74
|
on(event: 'change', cb: (value: Vec2) => void): () => void;
|
|
57
75
|
}
|
|
58
76
|
/**
|
|
59
|
-
* React wrapper for CursorInput. Auto-attaches to the parent <
|
|
77
|
+
* React wrapper for CursorInput. Auto-attaches to the parent <ShaderScene>'s
|
|
60
78
|
* scheduler if available; otherwise creates a free-running rAF tick.
|
|
61
79
|
*
|
|
62
80
|
* Lifecycle is in a single effect so React 19 Strict Mode's intentional
|
|
@@ -66,6 +84,38 @@ interface CursorSignal {
|
|
|
66
84
|
*/
|
|
67
85
|
declare function useCursor(opts?: CursorInputOptions): CursorSignal;
|
|
68
86
|
|
|
87
|
+
type OverlayTransform = (input: ShaderNodeObject<Node>) => ShaderNodeObject<Node>;
|
|
88
|
+
interface ShaderContextValue {
|
|
89
|
+
renderer: GpuRenderer;
|
|
90
|
+
scene: Scene;
|
|
91
|
+
camera: Camera;
|
|
92
|
+
scheduler: FrameScheduler;
|
|
93
|
+
registerOverlay: (transform: OverlayTransform) => () => void;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Read the shader scene context. Returns null when called outside a
|
|
98
|
+
* <ShaderScene>; useShaderMaterial and similar hooks check this.
|
|
99
|
+
*/
|
|
100
|
+
declare function useShaderContext(): ShaderContextValue | null;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Register a TSL transform as an overlay pass on the parent <ShaderScene>.
|
|
104
|
+
*
|
|
105
|
+
* The transform takes the "color so far" — base scene + any earlier
|
|
106
|
+
* overlays as a TSL vec4 node — and returns a modified vec4. Registration
|
|
107
|
+
* happens on mount; unregistration on unmount. The hook re-registers
|
|
108
|
+
* whenever any value in `deps` changes (useEffect semantics): use this
|
|
109
|
+
* for structural changes (e.g., a `mode: 'additive' | 'subtractive'`
|
|
110
|
+
* toggle) that swap the transform function itself. Uniforms captured
|
|
111
|
+
* inside the transform mutate in place, so uniform value changes do
|
|
112
|
+
* NOT need to be in deps.
|
|
113
|
+
*
|
|
114
|
+
* When called outside a <ShaderScene> provider, this hook is a no-op.
|
|
115
|
+
* Matches the existing useShaderContext convention.
|
|
116
|
+
*/
|
|
117
|
+
declare function useOverlayPass(transform: OverlayTransform, deps: DependencyList): void;
|
|
118
|
+
|
|
69
119
|
type ResizeValue = readonly [width: number, height: number, dpr: number];
|
|
70
120
|
interface ResizeSignal {
|
|
71
121
|
/** Current size in CSS pixels + devicePixelRatio. */
|
|
@@ -73,7 +123,7 @@ interface ResizeSignal {
|
|
|
73
123
|
on(event: 'change', cb: (value: ResizeValue) => void): () => void;
|
|
74
124
|
}
|
|
75
125
|
/**
|
|
76
|
-
* Track the parent <
|
|
126
|
+
* Track the parent <ShaderScene>'s canvas size + DPR. Exposes an AnimatableSignal
|
|
77
127
|
* that components can pass into a TSL uniform to make pixel-aware effects
|
|
78
128
|
* (e.g., DotField's pixel-spacing math).
|
|
79
129
|
*
|
|
@@ -92,7 +142,7 @@ interface ScrollSignal {
|
|
|
92
142
|
on(event: 'change', cb: (value: ScrollValue) => void): () => void;
|
|
93
143
|
}
|
|
94
144
|
/**
|
|
95
|
-
* Track window scroll position. Exposes
|
|
145
|
+
* Track window scroll position. Exposes an AnimatableSignal of `[scrollY, progress]`
|
|
96
146
|
* where `progress` is `scrollY / max(documentHeight - innerHeight, 1)` clamped
|
|
97
147
|
* to [0, 1]. Listener is rAF-throttled and `passive: true` so it never blocks
|
|
98
148
|
* scrolling.
|
|
@@ -113,47 +163,17 @@ interface ScrollSignal {
|
|
|
113
163
|
*/
|
|
114
164
|
declare function useScroll(): ScrollSignal;
|
|
115
165
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
on(event: 'change', cb: (value: T) => void): () => void;
|
|
119
|
-
}
|
|
120
|
-
type AnimatableProp<T> = T | MatterSignal<T>;
|
|
121
|
-
/**
|
|
122
|
-
* Bind an AnimatableProp<T> to a TSL uniform. Plain values create a
|
|
123
|
-
* static uniform that updates only when the prop changes (React render
|
|
124
|
-
* path). Signals subscribe via .on('change') and write into the uniform
|
|
125
|
-
* imperatively without re-rendering.
|
|
126
|
-
*/
|
|
127
|
-
declare function useAnimatableUniform<T>(value: AnimatableProp<T>): ShaderNodeObject<Node>;
|
|
128
|
-
|
|
166
|
+
/** A TSL fragment that produces a color. Accept any Node or TSL-wrapped node. */
|
|
167
|
+
type ColorTSL = Node | ShaderNodeObject<Node>;
|
|
129
168
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* The transform takes the "color so far" — base scene + any earlier
|
|
133
|
-
* overlays as a TSL vec4 node — and returns a modified vec4. Registration
|
|
134
|
-
* happens on mount; unregistration on unmount. The hook re-registers
|
|
135
|
-
* whenever any value in `deps` changes (useEffect semantics): use this
|
|
136
|
-
* for structural changes (e.g., a `mode: 'additive' | 'subtractive'`
|
|
137
|
-
* toggle) that swap the transform function itself. Uniforms captured
|
|
138
|
-
* inside the transform mutate in place, so uniform value changes do
|
|
139
|
-
* NOT need to be in deps.
|
|
169
|
+
* Bind a TSL color expression to a NodeMaterial. Returns the material;
|
|
170
|
+
* caller is responsible for adding it to a mesh and disposing when done.
|
|
140
171
|
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
declare function useOverlayPass(transform: OverlayTransform, deps: DependencyList): void;
|
|
145
|
-
|
|
146
|
-
interface FallbackBoundaryProps {
|
|
147
|
-
/** Rendered until WebGPU/WebGL is available on the client. */
|
|
148
|
-
fallback?: ReactNode;
|
|
149
|
-
children: ReactNode;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Render `fallback` until the component mounts on the client. Gates the
|
|
153
|
-
* children behind client-only mounting so SSR/no-WebGPU users see a
|
|
154
|
-
* sensible static placeholder rather than a flash of nothing.
|
|
172
|
+
* The TSL fragment is computed once via `useMemo` and re-applied if the
|
|
173
|
+
* factory function changes. For dynamic uniforms, mutate `.value` on the
|
|
174
|
+
* uniform nodes — don't recreate the TSL fragment per render.
|
|
155
175
|
*/
|
|
156
|
-
declare function
|
|
176
|
+
declare function useShaderMaterial(build: () => ColorTSL): MeshBasicNodeMaterial;
|
|
157
177
|
|
|
158
178
|
/**
|
|
159
179
|
* Opt a component out of the rAF loop while it has no dynamic uniforms.
|
|
@@ -168,16 +188,4 @@ declare function FallbackBoundary({ fallback, children }: FallbackBoundaryProps)
|
|
|
168
188
|
*/
|
|
169
189
|
declare function useStaticHint(hint: boolean): void;
|
|
170
190
|
|
|
171
|
-
type MonitorAnchor
|
|
172
|
-
interface MatterMonitorProps {
|
|
173
|
-
anchor?: MonitorAnchor;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Dev-only overlay that displays the current scene's FPS, tick count, and
|
|
177
|
-
* paused/idle state. Reads from the surrounding `<MatterScene>` via context
|
|
178
|
-
* and subscribes to its scheduler. Renders nothing useful if mounted outside
|
|
179
|
-
* a scene.
|
|
180
|
-
*/
|
|
181
|
-
declare function MatterMonitor({ anchor }: MatterMonitorProps): react_jsx_runtime.JSX.Element;
|
|
182
|
-
|
|
183
|
-
export { type AnimatableProp, type CursorSignal, FallbackBoundary, type FallbackBoundaryProps, type MatterContextValue, MatterMonitor, type MatterMonitorProps, MatterScene, type MatterSceneProps, type MatterSignal, type MonitorAnchor, type OverlayTransform, type ResizeSignal, type ResizeValue, type ScrollSignal, type ScrollValue, useAnimatableUniform, useCursor, useMatterContext, useOverlayPass, useResize, useScroll, useShaderMaterial, useStaticHint };
|
|
191
|
+
export { type AnimatableProp, type AnimatableSignal, type CursorSignal, FallbackBoundary, type FallbackBoundaryProps, type MonitorAnchor, type OverlayTransform, type ResizeSignal, type ResizeValue, type ScrollSignal, type ScrollValue, type ShaderContextValue, ShaderMonitor, type ShaderMonitorProps, ShaderScene, type ShaderSceneProps, useAnimatableUniform, useCursor, useOverlayPass, useResize, useScroll, useShaderContext, useShaderMaterial, useStaticHint };
|