@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.
@@ -0,0 +1,123 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { StoredAnimation, Config, OutputsWithDerivatives, Value as Value$1, Inputs, InstanceUpdate, AnimationInfo, PlayerInfo, InstanceInfo, BakingConfig, BakedAnimationData, BakedAnimationBundle, listAnimationFixtures, loadAnimationFixture, loadAnimationJson, resolveAnimationPath } from '@vizij/animation-wasm';
4
+ export { listAnimationFixtures, loadAnimationFixture, loadAnimationJson, resolveAnimationPath } from '@vizij/animation-wasm';
5
+ import { NormalizedTransform } from '@vizij/value-json';
6
+
7
+ type Value = Value$1;
8
+ type InstanceSpec = {
9
+ playerName: string;
10
+ /** Which animation index in `animations` array to attach; defaults to 0 */
11
+ animIndex?: number;
12
+ /** Optional raw InstanceCfg JSON; pass-through to engine.addInstance */
13
+ cfg?: unknown;
14
+ };
15
+ type AnimationProviderProps = {
16
+ children: ReactNode;
17
+ /** One or more StoredAnimation objects to load on mount (and when identity changes) */
18
+ animations: StoredAnimation[] | StoredAnimation;
19
+ /**
20
+ * Instances to create on mount. If omitted, a single player "default" with the 0th animation is created.
21
+ * Example: [{ playerName: "demo", animIndex: 0 }]
22
+ */
23
+ instances?: InstanceSpec[];
24
+ /**
25
+ * Optional: Prebind resolver mapping canonical target paths to keys.
26
+ * Return string | number | null/undefined. Numbers will be coerced to string in the WASM layer.
27
+ */
28
+ prebind?: (path: string) => string | number | null | undefined;
29
+ /** Start an internal RAF loop that calls engine.update(dt) each frame */
30
+ autostart?: boolean;
31
+ /** Throttle UI notifications (Hz). Default: notify every frame while autostarting */
32
+ updateHz?: number;
33
+ /** Optional engine configuration for Engine constructor. Changing this re-initializes the Engine. */
34
+ engineConfig?: Config;
35
+ /** Optional callback to receive raw Outputs each update (includes events and derivatives). */
36
+ onOutputs?: (out: OutputsWithDerivatives) => void;
37
+ };
38
+ type AnimationContextValue = {
39
+ ready: boolean;
40
+ /** Subscribe to changes for a given resolved target key; returns unsubscribe */
41
+ subscribeToKey: (key: string, cb: () => void) => () => void;
42
+ /** Snapshot accessor for latest Value of a given resolved target key */
43
+ getKeySnapshot: (key: string) => Value | undefined;
44
+ /** Subscribe to derivative changes for a resolved target key */
45
+ subscribeToDerivativeKey: (key: string, cb: () => void) => () => void;
46
+ /** Snapshot accessor for latest derivative of a given resolved target key */
47
+ getKeyDerivativeSnapshot: (key: string) => Value | undefined;
48
+ /** Subscribe to per-player key changes */
49
+ subscribeToPlayerKey: (player: string | number, key: string, cb: () => void) => () => void;
50
+ /** Snapshot accessor for per-player key */
51
+ getPlayerKeySnapshot: (player: string | number, key: string) => Value | undefined;
52
+ /** Subscribe to per-player derivative changes */
53
+ subscribeToPlayerDerivative: (player: string | number, key: string, cb: () => void) => () => void;
54
+ /** Snapshot accessor for per-player derivatives */
55
+ getPlayerDerivativeSnapshot: (player: string | number, key: string) => Value | undefined;
56
+ /** Get latest values grouped by player name */
57
+ getLatestValuesByPlayer: () => Record<string, Record<string, Value>>;
58
+ /** Get latest derivatives grouped by player name */
59
+ getLatestDerivativesByPlayer: () => Record<string, Record<string, Value>>;
60
+ /** Manual step; useful when autostart=false */
61
+ step: (dt: number, inputs?: Inputs) => void;
62
+ /** Reload animations and instances at runtime */
63
+ reload: (animations: StoredAnimation[] | StoredAnimation, instances?: InstanceSpec[]) => void;
64
+ /** Append one or more animations without resetting existing state; returns new AnimIds (numbers) */
65
+ addAnimations: (animations: StoredAnimation[] | StoredAnimation) => number[];
66
+ /** Ensure a player exists with this name; returns PlayerId (number) */
67
+ addPlayer: (name: string) => number;
68
+ /** Add one or more instances to players; resolves animation by index or explicit id */
69
+ addInstances: (specs: {
70
+ playerName: string;
71
+ animIndexOrId: number;
72
+ cfg?: unknown;
73
+ }[]) => {
74
+ playerName: string;
75
+ instId: number;
76
+ }[];
77
+ /** Get instance ids for a given player (local cache; prefer listInstances for engine truth) */
78
+ getInstances: (playerName: string) => number[];
79
+ /** Apply instance-level updates immediately */
80
+ updateInstances: (updates: InstanceUpdate[]) => void;
81
+ /** Enumerate engine state (authoritative) */
82
+ listAnimations: () => AnimationInfo[];
83
+ listPlayers: () => PlayerInfo[];
84
+ listInstances: (player: string | number) => InstanceInfo[];
85
+ /** Keys currently associated with a player's instances */
86
+ listPlayerKeys: (player: string | number) => string[];
87
+ /** Removals */
88
+ removePlayer: (player: string | number) => boolean;
89
+ removeInstances: (specs: {
90
+ playerName: string;
91
+ instId: number;
92
+ }[]) => {
93
+ playerName: string;
94
+ instId: number;
95
+ }[];
96
+ unloadAnimations: (animIds: number[]) => number[];
97
+ /** Baking helpers */
98
+ bakeAnimation: (animIndexOrId: number, cfg?: BakingConfig) => BakedAnimationData | null;
99
+ bakeAnimationWithDerivatives: (animIndexOrId: number, cfg?: BakingConfig) => BakedAnimationBundle | null;
100
+ /** Optional: expose player name to id mapping for controls */
101
+ players: Record<string, number>;
102
+ };
103
+
104
+ declare function AnimationProvider({ children, animations, instances, prebind, autostart, updateHz, engineConfig, onOutputs, }: AnimationProviderProps): react_jsx_runtime.JSX.Element;
105
+
106
+ declare function useAnimation(): AnimationContextValue;
107
+
108
+ declare function useAnimTarget(key?: string): Value | undefined;
109
+
110
+ declare function useAnimDerivative(key?: string): Value | undefined;
111
+
112
+ declare function valueAsNumber(v: Value | undefined): number | undefined;
113
+ declare function valueAsNumericArray(v: Value | undefined, fallback?: number): number[] | undefined;
114
+ declare function valueAsTransform(v: Value | undefined): NormalizedTransform | undefined;
115
+
116
+ declare const samples: {
117
+ readonly list: typeof listAnimationFixtures;
118
+ readonly load: typeof loadAnimationFixture;
119
+ readonly loadJson: typeof loadAnimationJson;
120
+ readonly resolvePath: typeof resolveAnimationPath;
121
+ };
122
+
123
+ export { AnimationProvider, type Value, samples, useAnimDerivative, useAnimTarget, useAnimation, valueAsNumber, valueAsNumericArray, valueAsTransform };
@@ -0,0 +1,123 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { StoredAnimation, Config, OutputsWithDerivatives, Value as Value$1, Inputs, InstanceUpdate, AnimationInfo, PlayerInfo, InstanceInfo, BakingConfig, BakedAnimationData, BakedAnimationBundle, listAnimationFixtures, loadAnimationFixture, loadAnimationJson, resolveAnimationPath } from '@vizij/animation-wasm';
4
+ export { listAnimationFixtures, loadAnimationFixture, loadAnimationJson, resolveAnimationPath } from '@vizij/animation-wasm';
5
+ import { NormalizedTransform } from '@vizij/value-json';
6
+
7
+ type Value = Value$1;
8
+ type InstanceSpec = {
9
+ playerName: string;
10
+ /** Which animation index in `animations` array to attach; defaults to 0 */
11
+ animIndex?: number;
12
+ /** Optional raw InstanceCfg JSON; pass-through to engine.addInstance */
13
+ cfg?: unknown;
14
+ };
15
+ type AnimationProviderProps = {
16
+ children: ReactNode;
17
+ /** One or more StoredAnimation objects to load on mount (and when identity changes) */
18
+ animations: StoredAnimation[] | StoredAnimation;
19
+ /**
20
+ * Instances to create on mount. If omitted, a single player "default" with the 0th animation is created.
21
+ * Example: [{ playerName: "demo", animIndex: 0 }]
22
+ */
23
+ instances?: InstanceSpec[];
24
+ /**
25
+ * Optional: Prebind resolver mapping canonical target paths to keys.
26
+ * Return string | number | null/undefined. Numbers will be coerced to string in the WASM layer.
27
+ */
28
+ prebind?: (path: string) => string | number | null | undefined;
29
+ /** Start an internal RAF loop that calls engine.update(dt) each frame */
30
+ autostart?: boolean;
31
+ /** Throttle UI notifications (Hz). Default: notify every frame while autostarting */
32
+ updateHz?: number;
33
+ /** Optional engine configuration for Engine constructor. Changing this re-initializes the Engine. */
34
+ engineConfig?: Config;
35
+ /** Optional callback to receive raw Outputs each update (includes events and derivatives). */
36
+ onOutputs?: (out: OutputsWithDerivatives) => void;
37
+ };
38
+ type AnimationContextValue = {
39
+ ready: boolean;
40
+ /** Subscribe to changes for a given resolved target key; returns unsubscribe */
41
+ subscribeToKey: (key: string, cb: () => void) => () => void;
42
+ /** Snapshot accessor for latest Value of a given resolved target key */
43
+ getKeySnapshot: (key: string) => Value | undefined;
44
+ /** Subscribe to derivative changes for a resolved target key */
45
+ subscribeToDerivativeKey: (key: string, cb: () => void) => () => void;
46
+ /** Snapshot accessor for latest derivative of a given resolved target key */
47
+ getKeyDerivativeSnapshot: (key: string) => Value | undefined;
48
+ /** Subscribe to per-player key changes */
49
+ subscribeToPlayerKey: (player: string | number, key: string, cb: () => void) => () => void;
50
+ /** Snapshot accessor for per-player key */
51
+ getPlayerKeySnapshot: (player: string | number, key: string) => Value | undefined;
52
+ /** Subscribe to per-player derivative changes */
53
+ subscribeToPlayerDerivative: (player: string | number, key: string, cb: () => void) => () => void;
54
+ /** Snapshot accessor for per-player derivatives */
55
+ getPlayerDerivativeSnapshot: (player: string | number, key: string) => Value | undefined;
56
+ /** Get latest values grouped by player name */
57
+ getLatestValuesByPlayer: () => Record<string, Record<string, Value>>;
58
+ /** Get latest derivatives grouped by player name */
59
+ getLatestDerivativesByPlayer: () => Record<string, Record<string, Value>>;
60
+ /** Manual step; useful when autostart=false */
61
+ step: (dt: number, inputs?: Inputs) => void;
62
+ /** Reload animations and instances at runtime */
63
+ reload: (animations: StoredAnimation[] | StoredAnimation, instances?: InstanceSpec[]) => void;
64
+ /** Append one or more animations without resetting existing state; returns new AnimIds (numbers) */
65
+ addAnimations: (animations: StoredAnimation[] | StoredAnimation) => number[];
66
+ /** Ensure a player exists with this name; returns PlayerId (number) */
67
+ addPlayer: (name: string) => number;
68
+ /** Add one or more instances to players; resolves animation by index or explicit id */
69
+ addInstances: (specs: {
70
+ playerName: string;
71
+ animIndexOrId: number;
72
+ cfg?: unknown;
73
+ }[]) => {
74
+ playerName: string;
75
+ instId: number;
76
+ }[];
77
+ /** Get instance ids for a given player (local cache; prefer listInstances for engine truth) */
78
+ getInstances: (playerName: string) => number[];
79
+ /** Apply instance-level updates immediately */
80
+ updateInstances: (updates: InstanceUpdate[]) => void;
81
+ /** Enumerate engine state (authoritative) */
82
+ listAnimations: () => AnimationInfo[];
83
+ listPlayers: () => PlayerInfo[];
84
+ listInstances: (player: string | number) => InstanceInfo[];
85
+ /** Keys currently associated with a player's instances */
86
+ listPlayerKeys: (player: string | number) => string[];
87
+ /** Removals */
88
+ removePlayer: (player: string | number) => boolean;
89
+ removeInstances: (specs: {
90
+ playerName: string;
91
+ instId: number;
92
+ }[]) => {
93
+ playerName: string;
94
+ instId: number;
95
+ }[];
96
+ unloadAnimations: (animIds: number[]) => number[];
97
+ /** Baking helpers */
98
+ bakeAnimation: (animIndexOrId: number, cfg?: BakingConfig) => BakedAnimationData | null;
99
+ bakeAnimationWithDerivatives: (animIndexOrId: number, cfg?: BakingConfig) => BakedAnimationBundle | null;
100
+ /** Optional: expose player name to id mapping for controls */
101
+ players: Record<string, number>;
102
+ };
103
+
104
+ declare function AnimationProvider({ children, animations, instances, prebind, autostart, updateHz, engineConfig, onOutputs, }: AnimationProviderProps): react_jsx_runtime.JSX.Element;
105
+
106
+ declare function useAnimation(): AnimationContextValue;
107
+
108
+ declare function useAnimTarget(key?: string): Value | undefined;
109
+
110
+ declare function useAnimDerivative(key?: string): Value | undefined;
111
+
112
+ declare function valueAsNumber(v: Value | undefined): number | undefined;
113
+ declare function valueAsNumericArray(v: Value | undefined, fallback?: number): number[] | undefined;
114
+ declare function valueAsTransform(v: Value | undefined): NormalizedTransform | undefined;
115
+
116
+ declare const samples: {
117
+ readonly list: typeof listAnimationFixtures;
118
+ readonly load: typeof loadAnimationFixture;
119
+ readonly loadJson: typeof loadAnimationJson;
120
+ readonly resolvePath: typeof resolveAnimationPath;
121
+ };
122
+
123
+ export { AnimationProvider, type Value, samples, useAnimDerivative, useAnimTarget, useAnimation, valueAsNumber, valueAsNumericArray, valueAsTransform };