@vizij/animation-react 0.0.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 +221 -0
- package/dist/index.cjs +919 -0
- package/dist/index.d.cts +123 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.js +893 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# @vizij/animation-react
|
|
2
|
+
|
|
3
|
+
> **React provider and hooks for Vizij’s animation WASM runtime.**
|
|
4
|
+
|
|
5
|
+
This package wraps `@vizij/animation-wasm` with React-friendly primitives so applications can load animations, manage players/instances, stream outputs, and bake results using idiomatic hooks.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
1. [Overview](#overview)
|
|
12
|
+
2. [Installation](#installation)
|
|
13
|
+
3. [Peer Dependencies](#peer-dependencies)
|
|
14
|
+
4. [Quick Start](#quick-start)
|
|
15
|
+
5. [Provider & Context](#provider--context)
|
|
16
|
+
6. [Hooks](#hooks)
|
|
17
|
+
7. [Helpers](#helpers)
|
|
18
|
+
8. [Development & Testing](#development--testing)
|
|
19
|
+
9. [Publishing](#publishing)
|
|
20
|
+
10. [Related Packages](#related-packages)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Overview
|
|
25
|
+
|
|
26
|
+
- Initialises `@vizij/animation-wasm` automatically and manages the wasm engine lifecycle.
|
|
27
|
+
- Loads one or more `StoredAnimation` clips, creates players/instances, and keeps them in sync with React state.
|
|
28
|
+
- Provides fine-grained subscriptions (`useAnimTarget`) backed by `useSyncExternalStore`.
|
|
29
|
+
- Supports manual or automatic playback (`autostart` with RAF or manual stepping via `step`).
|
|
30
|
+
- Exposes helpers for value coercion (`valueAsNumber`, `valueAsTransform`, etc.).
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# pnpm
|
|
38
|
+
pnpm add @vizij/animation-react @vizij/animation-wasm react react-dom
|
|
39
|
+
|
|
40
|
+
# npm
|
|
41
|
+
npm install @vizij/animation-react @vizij/animation-wasm react react-dom
|
|
42
|
+
|
|
43
|
+
# yarn
|
|
44
|
+
yarn add @vizij/animation-react @vizij/animation-wasm react react-dom
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
During local development with linked WASM packages, ensure your bundler preserves symlinks and excludes `@vizij/animation-wasm` from pre-bundling (see the [`vizij-web` README](../../README.md#local-wasm-development) for a Vite example).
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Peer Dependencies
|
|
52
|
+
|
|
53
|
+
- `react >= 18`
|
|
54
|
+
- `react-dom >= 18`
|
|
55
|
+
- `@vizij/animation-wasm` (keep the version in sync with the `vizij-rs` publish)
|
|
56
|
+
|
|
57
|
+
When working from source, update these ranges before cutting a release so downstream apps do not end up with duplicate React copies or mismatched WASM ABIs.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Quick Start
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import {
|
|
65
|
+
AnimationProvider,
|
|
66
|
+
useAnimTarget,
|
|
67
|
+
valueAsNumber,
|
|
68
|
+
} from "@vizij/animation-react";
|
|
69
|
+
|
|
70
|
+
const storedAnimation = {
|
|
71
|
+
name: "Scalar Ramp",
|
|
72
|
+
duration: 2000,
|
|
73
|
+
tracks: [
|
|
74
|
+
{
|
|
75
|
+
id: "scalar",
|
|
76
|
+
animatableId: "demo/scalar",
|
|
77
|
+
points: [
|
|
78
|
+
{ id: "k0", stamp: 0.0, value: 0 },
|
|
79
|
+
{ id: "k1", stamp: 1.0, value: 1 },
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
groups: {},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
function Panel() {
|
|
87
|
+
const value = useAnimTarget("demo/scalar");
|
|
88
|
+
const num = valueAsNumber(value);
|
|
89
|
+
return <div>Value: {num?.toFixed(3) ?? "…"}</div>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function App() {
|
|
93
|
+
return (
|
|
94
|
+
<AnimationProvider
|
|
95
|
+
animations={storedAnimation}
|
|
96
|
+
prebind={(path) => path} // canonical path -> subscription key
|
|
97
|
+
autostart
|
|
98
|
+
updateHz={60}
|
|
99
|
+
>
|
|
100
|
+
<Panel />
|
|
101
|
+
</AnimationProvider>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Provider & Context
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
import { AnimationProvider, useAnimation } from "@vizij/animation-react";
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`AnimationProvider` props:
|
|
115
|
+
|
|
116
|
+
| Prop | Type | Description |
|
|
117
|
+
| ------------ | ---------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
118
|
+
| `animations` | `StoredAnimation / StoredAnimation[]` | Clips to load on mount (reloaded when identity changes). |
|
|
119
|
+
| `instances` | `InstanceSpec[]` _(optional)_ | Preconfigured instances; defaults to a single player/instance using the first animation. |
|
|
120
|
+
| `prebind` | `(path: string) => string \| number \| null \| undefined` _(optional)_ | Resolver from canonical target paths to subscription keys. |
|
|
121
|
+
| `autostart` | `boolean` _(default: `true`)_ | When true, starts a `requestAnimationFrame` loop. If false, call `step(dt)` manually. |
|
|
122
|
+
| `updateHz` | `number` _(optional)_ | Throttle subscriber notifications while the simulation still runs every frame. |
|
|
123
|
+
|
|
124
|
+
`useAnimation()` returns the provider context:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
type AnimationContext = {
|
|
128
|
+
ready: boolean;
|
|
129
|
+
subscribeToKey(key: string, cb: () => void): () => void;
|
|
130
|
+
getKeySnapshot(key: string): ValueJSON | undefined;
|
|
131
|
+
step(dtSeconds: number, inputs?: Inputs): void;
|
|
132
|
+
reload(
|
|
133
|
+
animations: StoredAnimation | StoredAnimation[],
|
|
134
|
+
instances?: InstanceSpec[],
|
|
135
|
+
): void;
|
|
136
|
+
players: Record<string, number>; // player name -> PlayerId
|
|
137
|
+
};
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Use `step` when `autostart` is disabled (e.g., timeline scrubbing tools).
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Hooks
|
|
145
|
+
|
|
146
|
+
| Hook | Description |
|
|
147
|
+
| ----------------------------- | ---------------------------------------------------------------------------------- |
|
|
148
|
+
| `useAnimation()` | Access the provider context (throws if used outside `AnimationProvider`). |
|
|
149
|
+
| `useAnimTarget(key?: string)` | Subscribe to a resolved target key; returns the latest `ValueJSON` or `undefined`. |
|
|
150
|
+
|
|
151
|
+
`useAnimTarget` is built on `useSyncExternalStore`, so components re-render only when the requested key changes.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Helpers
|
|
156
|
+
|
|
157
|
+
The package re-exports value coercion helpers from `@vizij/value-json`:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
import {
|
|
161
|
+
valueAsNumber,
|
|
162
|
+
valueAsNumericArray,
|
|
163
|
+
valueAsTransform,
|
|
164
|
+
valueAsQuat,
|
|
165
|
+
valueAsVec3,
|
|
166
|
+
valueAsColorRgba,
|
|
167
|
+
valueAsBool,
|
|
168
|
+
valueAsText,
|
|
169
|
+
} from "@vizij/animation-react";
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Use them to format engine values for UI or to feed other subsystems.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Development & Testing
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
pnpm --filter "@vizij/animation-react" build
|
|
180
|
+
pnpm --filter "@vizij/animation-react" test
|
|
181
|
+
pnpm --filter "@vizij/animation-react" typecheck
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Vitest mocks the wasm binding to keep tests fast; end-to-end checks can be exercised via demo apps (e.g., `apps/demo-animation-studio`) after linking local builds.
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Publishing
|
|
189
|
+
|
|
190
|
+
This package is published via the repository-wide workflow at [`.github/workflows/publish-npm.yml`](../../../.github/workflows/publish-npm.yml). To cut a release:
|
|
191
|
+
|
|
192
|
+
1. Generate a changeset and apply version bumps:
|
|
193
|
+
```bash
|
|
194
|
+
pnpm changeset
|
|
195
|
+
pnpm version:packages
|
|
196
|
+
```
|
|
197
|
+
2. Verify the package locally:
|
|
198
|
+
```bash
|
|
199
|
+
pnpm install
|
|
200
|
+
pnpm --filter "@vizij/animation-react" build
|
|
201
|
+
pnpm --filter "@vizij/animation-react" test
|
|
202
|
+
pnpm --filter "@vizij/animation-react" typecheck
|
|
203
|
+
pnpm --filter "@vizij/animation-react" exec npm pack --dry-run
|
|
204
|
+
```
|
|
205
|
+
3. Tag the commit using the `npm-animation-react-vX.Y.Z` pattern and push the tag:
|
|
206
|
+
```bash
|
|
207
|
+
git tag npm-animation-react-v0.3.0
|
|
208
|
+
git push origin npm-animation-react-v0.3.0
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
The workflow builds with the latest linked dependencies, runs tests, and publishes with provenance metadata if the job succeeds.
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Related Packages
|
|
216
|
+
|
|
217
|
+
- [`@vizij/animation-wasm`](../../../vizij-rs/npm/@vizij/animation-wasm/README.md) – WASM binding used internally.
|
|
218
|
+
- [`vizij-animation-core`](../../../vizij-rs/crates/animation/vizij-animation-core/README.md) – underlying animation engine.
|
|
219
|
+
- [`@vizij/node-graph-react`](../@vizij/node-graph-react/README.md) / [`@vizij/orchestrator-react`](../@vizij/orchestrator-react/README.md) – complementary React bindings.
|
|
220
|
+
|
|
221
|
+
Questions or feature requests? Open an issue—smooth React integration keeps Vizij animations easy to use. 🎬
|