@vizij/orchestrator-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,113 @@
1
+ import { InitInput as InitInput$1, GraphRegistrationInput as GraphRegistrationInput$1, MergedGraphRegistrationConfig as MergedGraphRegistrationConfig$1, MergeStrategyOptions as MergeStrategyOptions$1, MergeConflictStrategy as MergeConflictStrategy$1, AnimationRegistrationConfig as AnimationRegistrationConfig$1, Value, Shape, OrchestratorFrame as OrchestratorFrame$1, WriteOpJSON, ConflictLog, GraphRegistrationConfig as GraphRegistrationConfig$1, GraphSubscriptions as GraphSubscriptions$1, AnimationSetup as AnimationSetup$1, listOrchestrationFixtures, loadOrchestrationDescriptor, loadOrchestrationJson, loadOrchestrationBundle } from '@vizij/orchestrator-wasm';
2
+ export { Orchestrator as OrchestratorRuntime, AnimationRegistrationConfig as WasmAnimationRegistration, AnimationSetup as WasmAnimationSetup, ConflictLog as WasmConflictLog, GraphRegistrationInput as WasmGraphRegistration, GraphRegistrationConfig as WasmGraphRegistrationConfig, GraphSubscriptions as WasmGraphSubscriptions, MergeConflictStrategy as WasmMergeConflictStrategy, MergeStrategyOptions as WasmMergeStrategyOptions, MergedGraphRegistrationConfig as WasmMergedGraphRegistrationConfig, OrchestratorFrame as WasmOrchestratorFrame, Shape as WasmShape, Value as WasmValue, createOrchestrator as createOrchestratorRuntime, init as initOrchestratorWasm, listOrchestrationFixtures, loadOrchestrationBundle, loadOrchestrationDescriptor, loadOrchestrationJson } from '@vizij/orchestrator-wasm';
3
+ import React from 'react';
4
+
5
+ /**
6
+ * Shared type definitions for the orchestrator React integration.
7
+ * These mirror the public wasm surface while layering on React-specific details.
8
+ */
9
+
10
+ /** Values emitted by the orchestrator writes leverage the wasm union. */
11
+ type ValueJSON = Value;
12
+ /** Optional shape metadata describing the serialized value structure. */
13
+ type ShapeJSON = Shape;
14
+ /** Individual write units emitted from the orchestrator frame merge. */
15
+ type WriteOp = WriteOpJSON & {
16
+ player?: number | string;
17
+ };
18
+ type OrchestratorTimings = OrchestratorFrame$1["timings_ms"] & {
19
+ animations_ms?: number;
20
+ graphs_ms?: number;
21
+ };
22
+ type OrchestratorFrame = Omit<OrchestratorFrame$1, "merged_writes"> & {
23
+ merged_writes: WriteOp[];
24
+ };
25
+ type OrchestratorConflict = ConflictLog;
26
+ type InitInput = InitInput$1 | {
27
+ url?: string;
28
+ };
29
+ type PrebindResolver = (path: string) => string | number | null | undefined;
30
+ type CreateOrchOptions = {
31
+ schedule?: "SinglePass" | "TwoPass" | "RateDecoupled";
32
+ };
33
+ type ControllerId = string;
34
+ type GraphRegistrationInput = GraphRegistrationInput$1;
35
+ type GraphRegistrationConfig = GraphRegistrationConfig$1;
36
+ type GraphSubscriptions = GraphSubscriptions$1;
37
+ /**
38
+ * Extended merge conflict strategies recognised by the wasm bridge.
39
+ * Older builds only exposed "error" | "namespace" | "blend", so we
40
+ * widen the union with the newer additive and weighted blend aliases.
41
+ */
42
+ type MergeConflictStrategy = MergeConflictStrategy$1 | "blend_equal" | "blend_equal_weights" | "add" | "sum" | "blend-sum" | "additive" | "default-blend" | "blend-default" | "blend-weights" | "weights";
43
+ type MergeStrategyOptions = Omit<MergeStrategyOptions$1, "outputs" | "intermediate"> & {
44
+ outputs?: MergeConflictStrategy;
45
+ intermediate?: MergeConflictStrategy;
46
+ };
47
+ type MergedGraphRegistrationConfig = Omit<MergedGraphRegistrationConfig$1, "strategy"> & {
48
+ strategy?: MergeStrategyOptions;
49
+ };
50
+ type AnimationRegistrationConfig = AnimationRegistrationConfig$1;
51
+ type AnimationSetup = AnimationSetup$1;
52
+ type OrchestratorReactCtx = {
53
+ ready: boolean;
54
+ createOrchestrator: (opts?: CreateOrchOptions) => Promise<void>;
55
+ registerGraph: (cfg: GraphRegistrationInput) => ControllerId;
56
+ registerMergedGraph: (cfg: MergedGraphRegistrationConfig) => ControllerId;
57
+ registerAnimation: (cfg: AnimationRegistrationConfig) => ControllerId;
58
+ prebind?: (resolver: PrebindResolver) => void;
59
+ setInput: (path: string, value: ValueJSON, shape?: ShapeJSON) => void;
60
+ removeInput: (path: string) => boolean;
61
+ step: (dt: number) => OrchestratorFrame | null;
62
+ listControllers: () => {
63
+ graphs: ControllerId[];
64
+ anims: ControllerId[];
65
+ };
66
+ removeGraph: (id: ControllerId) => boolean;
67
+ removeAnimation: (id: ControllerId) => boolean;
68
+ getLatestFrame: () => OrchestratorFrame | null;
69
+ subscribeToPath: (path: string, cb: () => void) => () => void;
70
+ getPathSnapshot: (path: string) => ValueJSON | undefined;
71
+ subscribeToFrame: (cb: () => void) => () => void;
72
+ getFrameSnapshot: () => OrchestratorFrame | null;
73
+ normalizeGraphSpec?: (spec: object | string) => Promise<object>;
74
+ abiVersion?: () => Promise<number>;
75
+ };
76
+
77
+ type OrchestratorProviderProps = {
78
+ children: React.ReactNode;
79
+ /** Optional init() input forwarded to the wasm layer. */
80
+ initInput?: InitInput;
81
+ /** Automatically create a runtime orchestration instance on mount. Defaults to true. */
82
+ autoCreate?: boolean;
83
+ /** Options passed to the wasm createOrchestrator helper when auto-creating. */
84
+ createOptions?: CreateOrchOptions;
85
+ /**
86
+ * Start a requestAnimationFrame loop once ready. Defaults to false so tests and
87
+ * demos can opt-in to manual stepping.
88
+ */
89
+ autostart?: boolean;
90
+ };
91
+ declare function OrchestratorProvider({ children, initInput, autoCreate, createOptions, autostart, }: OrchestratorProviderProps): JSX.Element;
92
+
93
+ declare function useOrchestrator(): OrchestratorReactCtx;
94
+
95
+ declare function useOrchTarget(path?: string | null): ValueJSON | undefined;
96
+
97
+ declare function useOrchFrame(): OrchestratorFrame | null;
98
+
99
+ declare function valueAsNumber(value: ValueJSON | undefined): number | undefined;
100
+ declare function valueAsVec3(value: ValueJSON | undefined): [number, number, number] | undefined;
101
+ declare function valueAsBool(value: ValueJSON | undefined): boolean | undefined;
102
+
103
+ /**
104
+ * Standardised access to embedded orchestration samples for quick-start demos and tests.
105
+ */
106
+ declare const samples: {
107
+ readonly list: typeof listOrchestrationFixtures;
108
+ readonly load: typeof loadOrchestrationDescriptor;
109
+ readonly loadJson: typeof loadOrchestrationJson;
110
+ readonly loadBundle: typeof loadOrchestrationBundle;
111
+ };
112
+
113
+ export { type AnimationRegistrationConfig, type AnimationSetup, type ControllerId, type CreateOrchOptions, type GraphRegistrationConfig, type GraphRegistrationInput, type GraphSubscriptions, type InitInput, type MergeConflictStrategy, type MergeStrategyOptions, type MergedGraphRegistrationConfig, type OrchestratorConflict, type OrchestratorFrame, OrchestratorProvider, type OrchestratorProviderProps, type OrchestratorReactCtx, type OrchestratorTimings, type PrebindResolver, type ShapeJSON, type ValueJSON, type WriteOp, samples, useOrchFrame, useOrchTarget, useOrchestrator, valueAsBool, valueAsNumber, valueAsVec3 };
package/dist/index.js ADDED
@@ -0,0 +1,534 @@
1
+ // src/index.ts
2
+ import {
3
+ listOrchestrationFixtures,
4
+ loadOrchestrationBundle,
5
+ loadOrchestrationDescriptor,
6
+ loadOrchestrationJson
7
+ } from "@vizij/orchestrator-wasm";
8
+
9
+ // src/OrchestratorProvider.tsx
10
+ import {
11
+ useCallback,
12
+ useEffect,
13
+ useMemo,
14
+ useRef,
15
+ useState
16
+ } from "react";
17
+ import {
18
+ init as initOrchestratorWasm,
19
+ createOrchestrator as createOrchestratorWasm,
20
+ abi_version as orchestratorAbiVersion
21
+ } from "@vizij/orchestrator-wasm";
22
+
23
+ // src/context.ts
24
+ import { createContext } from "react";
25
+ var OrchestratorContext = createContext(
26
+ null
27
+ );
28
+
29
+ // src/OrchestratorProvider.tsx
30
+ import { jsx } from "react/jsx-runtime";
31
+ function normalizeInitInput(input) {
32
+ if (input == null) {
33
+ return void 0;
34
+ }
35
+ if (typeof input === "string") {
36
+ return input;
37
+ }
38
+ if (typeof Uint8Array !== "undefined" && input instanceof Uint8Array) {
39
+ return input;
40
+ }
41
+ if (typeof URL !== "undefined" && input instanceof URL) {
42
+ return input;
43
+ }
44
+ if (typeof input === "object" && "url" in input && typeof input.url === "string") {
45
+ return input.url;
46
+ }
47
+ return void 0;
48
+ }
49
+ function normalizeTypedPath(path) {
50
+ if (typeof path !== "string") {
51
+ throw new Error("Typed paths must be provided as strings.");
52
+ }
53
+ const trimmed = path.trim();
54
+ if (trimmed.length === 0) {
55
+ throw new Error("Typed paths must not be empty.");
56
+ }
57
+ if (/\s/.test(trimmed)) {
58
+ throw new Error(
59
+ "Typed paths may not contain whitespace. Use '/' to separate namespace segments."
60
+ );
61
+ }
62
+ return trimmed;
63
+ }
64
+ var noopUnsubscribe = () => {
65
+ };
66
+ function OrchestratorProvider({
67
+ children,
68
+ initInput,
69
+ autoCreate = true,
70
+ createOptions,
71
+ autostart = false
72
+ }) {
73
+ const mountedRef = useRef(true);
74
+ useEffect(
75
+ () => () => {
76
+ mountedRef.current = false;
77
+ },
78
+ []
79
+ );
80
+ const initPromiseRef = useRef(null);
81
+ const orchestratorRef = useRef(null);
82
+ const createPromiseRef = useRef(null);
83
+ const latestFrameRef = useRef(null);
84
+ const pathCacheRef = useRef(/* @__PURE__ */ new Map());
85
+ const pathSubscribersRef = useRef(/* @__PURE__ */ new Map());
86
+ const frameSubscribersRef = useRef(/* @__PURE__ */ new Set());
87
+ const [ready, setReady] = useState(false);
88
+ const [initError, setInitError] = useState(null);
89
+ const ensureInit = useCallback(() => {
90
+ if (!initPromiseRef.current) {
91
+ const resolved = normalizeInitInput(initInput);
92
+ initPromiseRef.current = initOrchestratorWasm(resolved).catch((err) => {
93
+ setInitError(err instanceof Error ? err : new Error(String(err)));
94
+ throw err;
95
+ });
96
+ }
97
+ return initPromiseRef.current;
98
+ }, [initInput]);
99
+ const applyFrame = useCallback((frame) => {
100
+ latestFrameRef.current = frame;
101
+ if (frame) {
102
+ const cache = pathCacheRef.current;
103
+ const subscribers = pathSubscribersRef.current;
104
+ for (const write of frame.merged_writes) {
105
+ let pathKey = write.path;
106
+ try {
107
+ pathKey = normalizeTypedPath(write.path);
108
+ } catch (err) {
109
+ console.warn(
110
+ "@vizij/orchestrator-react: received write with invalid path",
111
+ write.path,
112
+ err
113
+ );
114
+ }
115
+ cache.set(pathKey, write.value);
116
+ const listeners = subscribers.get(pathKey);
117
+ if (listeners) {
118
+ listeners.forEach((listener) => listener());
119
+ }
120
+ }
121
+ }
122
+ frameSubscribersRef.current.forEach((listener) => listener());
123
+ }, []);
124
+ const ensureOrchestrator = useCallback(
125
+ async (opts) => {
126
+ if (orchestratorRef.current) {
127
+ return orchestratorRef.current;
128
+ }
129
+ if (!createPromiseRef.current) {
130
+ createPromiseRef.current = (async () => {
131
+ await ensureInit();
132
+ const instance = await createOrchestratorWasm(
133
+ opts ?? createOptions ?? void 0
134
+ );
135
+ orchestratorRef.current = instance;
136
+ if (mountedRef.current) {
137
+ setReady(true);
138
+ }
139
+ return instance;
140
+ })();
141
+ }
142
+ return createPromiseRef.current;
143
+ },
144
+ [createOptions, ensureInit]
145
+ );
146
+ const requireOrchestrator = useCallback(() => {
147
+ const instance = orchestratorRef.current;
148
+ if (!instance) {
149
+ throw new Error(
150
+ "Orchestrator not created yet. Call createOrchestrator() first."
151
+ );
152
+ }
153
+ return instance;
154
+ }, []);
155
+ const stepRuntime = useCallback(
156
+ (dt) => {
157
+ if (!Number.isFinite(dt)) {
158
+ throw new Error("step(dt) requires a finite number of seconds.");
159
+ }
160
+ const instance = orchestratorRef.current;
161
+ if (!instance) {
162
+ return null;
163
+ }
164
+ const frame = instance.step(dt);
165
+ if (frame) {
166
+ applyFrame(frame);
167
+ return frame;
168
+ }
169
+ return null;
170
+ },
171
+ [applyFrame]
172
+ );
173
+ const createOrchestratorFn = useCallback(
174
+ async (opts) => {
175
+ await ensureOrchestrator(opts);
176
+ },
177
+ [ensureOrchestrator]
178
+ );
179
+ const registerGraph = useCallback(
180
+ (cfg) => {
181
+ const instance = requireOrchestrator();
182
+ return instance.registerGraph(cfg);
183
+ },
184
+ [requireOrchestrator]
185
+ );
186
+ const registerMergedGraph = useCallback(
187
+ (cfg) => {
188
+ const instance = requireOrchestrator();
189
+ return instance.registerMergedGraph(cfg);
190
+ },
191
+ [requireOrchestrator]
192
+ );
193
+ const registerAnimation = useCallback(
194
+ (cfg) => {
195
+ const instance = requireOrchestrator();
196
+ return instance.registerAnimation(cfg);
197
+ },
198
+ [requireOrchestrator]
199
+ );
200
+ const prebind = useCallback(
201
+ (resolver) => {
202
+ const instance = requireOrchestrator();
203
+ instance.prebind(resolver);
204
+ },
205
+ [requireOrchestrator]
206
+ );
207
+ const setInput = useCallback(
208
+ (path, value, shape) => {
209
+ const normalizedPath = normalizeTypedPath(path);
210
+ const instance = requireOrchestrator();
211
+ instance.setInput(normalizedPath, value, shape);
212
+ pathCacheRef.current.set(normalizedPath, value);
213
+ const listeners = pathSubscribersRef.current.get(normalizedPath);
214
+ if (listeners) {
215
+ listeners.forEach((listener) => {
216
+ try {
217
+ listener();
218
+ } catch (err) {
219
+ console.error(
220
+ "@vizij/orchestrator-react: setInput listener error",
221
+ err
222
+ );
223
+ }
224
+ });
225
+ }
226
+ },
227
+ [requireOrchestrator]
228
+ );
229
+ const removeInput = useCallback(
230
+ (path) => {
231
+ const normalizedPath = normalizeTypedPath(path);
232
+ const instance = requireOrchestrator();
233
+ const removed = instance.removeInput(normalizedPath);
234
+ if (removed) {
235
+ pathCacheRef.current.delete(normalizedPath);
236
+ const listeners = pathSubscribersRef.current.get(normalizedPath);
237
+ if (listeners) {
238
+ listeners.forEach((listener) => listener());
239
+ }
240
+ }
241
+ return removed;
242
+ },
243
+ [requireOrchestrator]
244
+ );
245
+ const listControllers = useCallback(() => {
246
+ const instance = orchestratorRef.current;
247
+ if (!instance) {
248
+ return { graphs: [], anims: [] };
249
+ }
250
+ const result = instance.listControllers();
251
+ const graphs = Array.isArray(result?.graphs) ? result?.graphs : [];
252
+ const anims = Array.isArray(result?.anims) ? result?.anims : [];
253
+ return { graphs, anims };
254
+ }, []);
255
+ const removeGraph = useCallback(
256
+ (id) => {
257
+ const instance = requireOrchestrator();
258
+ return instance.removeGraph(id);
259
+ },
260
+ [requireOrchestrator]
261
+ );
262
+ const removeAnimation = useCallback(
263
+ (id) => {
264
+ const instance = requireOrchestrator();
265
+ return instance.removeAnimation(id);
266
+ },
267
+ [requireOrchestrator]
268
+ );
269
+ const normalizeGraphSpec = useCallback(
270
+ async (spec) => {
271
+ const instance = await ensureOrchestrator();
272
+ if (typeof instance.normalizeGraphSpec !== "function") {
273
+ throw new Error(
274
+ "@vizij/orchestrator-wasm does not expose normalizeGraphSpec(). Update to a compatible version."
275
+ );
276
+ }
277
+ return await instance.normalizeGraphSpec(spec);
278
+ },
279
+ [ensureOrchestrator]
280
+ );
281
+ const abiVersion = useCallback(async () => {
282
+ await ensureInit();
283
+ return orchestratorAbiVersion();
284
+ }, [ensureInit]);
285
+ const getLatestFrame = useCallback(() => latestFrameRef.current, []);
286
+ const getFrameSnapshot = useCallback(() => latestFrameRef.current, []);
287
+ const subscribeToFrame = useCallback((cb) => {
288
+ const listeners = frameSubscribersRef.current;
289
+ listeners.add(cb);
290
+ return () => {
291
+ listeners.delete(cb);
292
+ };
293
+ }, []);
294
+ const getPathSnapshot = useCallback((path) => {
295
+ try {
296
+ const normalizedPath = normalizeTypedPath(path);
297
+ return pathCacheRef.current.get(normalizedPath);
298
+ } catch {
299
+ return void 0;
300
+ }
301
+ }, []);
302
+ const subscribeToPath = useCallback((path, cb) => {
303
+ if (!path) {
304
+ return noopUnsubscribe;
305
+ }
306
+ let normalizedPath;
307
+ try {
308
+ normalizedPath = normalizeTypedPath(path);
309
+ } catch (err) {
310
+ console.error(
311
+ "@vizij/orchestrator-react: subscribeToPath received invalid path",
312
+ path,
313
+ err
314
+ );
315
+ return noopUnsubscribe;
316
+ }
317
+ let listeners = pathSubscribersRef.current.get(normalizedPath);
318
+ if (!listeners) {
319
+ listeners = /* @__PURE__ */ new Set();
320
+ pathSubscribersRef.current.set(normalizedPath, listeners);
321
+ }
322
+ listeners.add(cb);
323
+ return () => {
324
+ const current = pathSubscribersRef.current.get(normalizedPath);
325
+ if (!current) return;
326
+ current.delete(cb);
327
+ if (current.size === 0) {
328
+ pathSubscribersRef.current.delete(normalizedPath);
329
+ }
330
+ };
331
+ }, []);
332
+ useEffect(() => {
333
+ let cancelled = false;
334
+ ensureInit().catch((err) => {
335
+ if (!cancelled) {
336
+ console.error("@vizij/orchestrator-react: failed to init wasm", err);
337
+ }
338
+ });
339
+ return () => {
340
+ cancelled = true;
341
+ };
342
+ }, [ensureInit]);
343
+ useEffect(() => {
344
+ if (!autoCreate) {
345
+ return;
346
+ }
347
+ let cancelled = false;
348
+ ensureOrchestrator().catch((err) => {
349
+ if (!cancelled) {
350
+ console.error(
351
+ "@vizij/orchestrator-react: failed to create orchestrator",
352
+ err
353
+ );
354
+ }
355
+ }).finally(() => {
356
+ if (!cancelled && mountedRef.current && autoCreate && orchestratorRef.current) {
357
+ setReady(true);
358
+ }
359
+ });
360
+ return () => {
361
+ cancelled = true;
362
+ };
363
+ }, [autoCreate, ensureOrchestrator]);
364
+ useEffect(() => {
365
+ if (!autostart || !ready) {
366
+ return;
367
+ }
368
+ const globalObj = typeof globalThis !== "undefined" ? globalThis : {};
369
+ const request = globalObj.requestAnimationFrame?.bind(globalObj);
370
+ const cancel = globalObj.cancelAnimationFrame?.bind(globalObj);
371
+ if (!request || !cancel) {
372
+ console.warn(
373
+ "@vizij/orchestrator-react: autostart is enabled but requestAnimationFrame is unavailable."
374
+ );
375
+ return;
376
+ }
377
+ let rafId = null;
378
+ let lastTs = 0;
379
+ const loop = (timestamp) => {
380
+ if (!mountedRef.current) {
381
+ return;
382
+ }
383
+ if (lastTs === 0) {
384
+ lastTs = timestamp;
385
+ }
386
+ const dt = Math.max(0, (timestamp - lastTs) / 1e3);
387
+ lastTs = timestamp;
388
+ stepRuntime(dt || 0);
389
+ rafId = request(loop);
390
+ };
391
+ rafId = request(loop);
392
+ return () => {
393
+ if (rafId !== null) {
394
+ cancel(rafId);
395
+ }
396
+ };
397
+ }, [autostart, ready, stepRuntime]);
398
+ useEffect(() => {
399
+ if (initError) {
400
+ console.error("@vizij/orchestrator-react: init error", initError);
401
+ }
402
+ }, [initError]);
403
+ const contextValue = useMemo(
404
+ () => ({
405
+ ready,
406
+ createOrchestrator: createOrchestratorFn,
407
+ registerGraph,
408
+ registerMergedGraph,
409
+ registerAnimation,
410
+ prebind,
411
+ setInput,
412
+ removeInput,
413
+ step: stepRuntime,
414
+ listControllers,
415
+ removeGraph,
416
+ removeAnimation,
417
+ getLatestFrame,
418
+ subscribeToPath,
419
+ getPathSnapshot,
420
+ subscribeToFrame,
421
+ getFrameSnapshot,
422
+ normalizeGraphSpec,
423
+ abiVersion
424
+ }),
425
+ [
426
+ ready,
427
+ createOrchestratorFn,
428
+ registerGraph,
429
+ registerMergedGraph,
430
+ registerAnimation,
431
+ prebind,
432
+ setInput,
433
+ removeInput,
434
+ stepRuntime,
435
+ listControllers,
436
+ removeGraph,
437
+ removeAnimation,
438
+ getLatestFrame,
439
+ subscribeToPath,
440
+ getPathSnapshot,
441
+ subscribeToFrame,
442
+ getFrameSnapshot,
443
+ normalizeGraphSpec,
444
+ abiVersion
445
+ ]
446
+ );
447
+ return /* @__PURE__ */ jsx(OrchestratorContext.Provider, { value: contextValue, children });
448
+ }
449
+
450
+ // src/hooks/useOrchestrator.ts
451
+ import { useContext } from "react";
452
+ function useOrchestrator() {
453
+ const ctx = useContext(OrchestratorContext);
454
+ if (!ctx) {
455
+ throw new Error(
456
+ "useOrchestrator must be used within an OrchestratorProvider."
457
+ );
458
+ }
459
+ return ctx;
460
+ }
461
+
462
+ // src/hooks/useOrchTarget.ts
463
+ import { useSyncExternalStore } from "react";
464
+ function useOrchTarget(path) {
465
+ const ctx = useOrchestrator();
466
+ return useSyncExternalStore(
467
+ (cb) => {
468
+ if (!path) {
469
+ return () => {
470
+ };
471
+ }
472
+ return ctx.subscribeToPath(path, cb);
473
+ },
474
+ () => path ? ctx.getPathSnapshot(path) : void 0,
475
+ () => path ? ctx.getPathSnapshot(path) : void 0
476
+ );
477
+ }
478
+
479
+ // src/hooks/useOrchFrame.ts
480
+ import { useSyncExternalStore as useSyncExternalStore2 } from "react";
481
+ function useOrchFrame() {
482
+ const ctx = useOrchestrator();
483
+ return useSyncExternalStore2(
484
+ (cb) => ctx.subscribeToFrame(cb),
485
+ () => ctx.getFrameSnapshot(),
486
+ () => ctx.getFrameSnapshot()
487
+ );
488
+ }
489
+
490
+ // src/valueHelpers.ts
491
+ import {
492
+ valueAsNumber as sharedValueAsNumber,
493
+ valueAsVec3 as sharedValueAsVec3,
494
+ valueAsBool as sharedValueAsBool
495
+ } from "@vizij/value-json";
496
+ function valueAsNumber(value) {
497
+ return sharedValueAsNumber(value);
498
+ }
499
+ function valueAsVec3(value) {
500
+ return sharedValueAsVec3(value);
501
+ }
502
+ function valueAsBool(value) {
503
+ return sharedValueAsBool(value);
504
+ }
505
+
506
+ // src/index.ts
507
+ import {
508
+ init,
509
+ createOrchestrator,
510
+ Orchestrator
511
+ } from "@vizij/orchestrator-wasm";
512
+ var samples = {
513
+ list: listOrchestrationFixtures,
514
+ load: loadOrchestrationDescriptor,
515
+ loadJson: loadOrchestrationJson,
516
+ loadBundle: loadOrchestrationBundle
517
+ };
518
+ export {
519
+ OrchestratorProvider,
520
+ Orchestrator as OrchestratorRuntime,
521
+ createOrchestrator as createOrchestratorRuntime,
522
+ init as initOrchestratorWasm,
523
+ listOrchestrationFixtures,
524
+ loadOrchestrationBundle,
525
+ loadOrchestrationDescriptor,
526
+ loadOrchestrationJson,
527
+ samples,
528
+ useOrchFrame,
529
+ useOrchTarget,
530
+ useOrchestrator,
531
+ valueAsBool,
532
+ valueAsNumber,
533
+ valueAsVec3
534
+ };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@vizij/orchestrator-react",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.cjs"
12
+ }
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/vizij-ai/vizij-web",
17
+ "directory": "packages/@vizij/orchestrator-react"
18
+ },
19
+ "types": "dist/index.d.ts",
20
+ "sideEffects": false,
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "dev": "tsup src/index.ts --format esm,cjs --dts --watch --external react,@vizij/orchestrator-wasm,@vizij/value-json",
27
+ "build": "tsup src/index.ts --format esm,cjs --dts --external react,@vizij/orchestrator-wasm,@vizij/value-json",
28
+ "typecheck": "tsc -p tsconfig.json --noEmit",
29
+ "lint": "pnpm --filter \"$npm_package_name\" exec eslint --ext .js,.jsx,.ts,.tsx -- .",
30
+ "lint:fix": "pnpm --filter \"$npm_package_name\" exec eslint --ext .js,.jsx,.ts,.tsx --fix -- .",
31
+ "prettier:check": "prettier --check .",
32
+ "prettier:write": "prettier --write .",
33
+ "test": "vitest --run --passWithNoTests",
34
+ "clean": "rm -rf dist coverage tsconfig.tsbuildinfo",
35
+ "reset": "rm -rf node_modules",
36
+ "reset:hard": "pnpm run reset && rm -f pnpm-lock.yaml package-lock.json yarn.lock",
37
+ "prepack": "pnpm run build && pnpm run test && pnpm run typecheck"
38
+ },
39
+ "dependencies": {
40
+ "@vizij/orchestrator-wasm": "^0.2.3",
41
+ "@vizij/value-json": "^0.1.0"
42
+ },
43
+ "peerDependencies": {
44
+ "react": ">=18",
45
+ "react-dom": ">=18"
46
+ },
47
+ "devDependencies": {
48
+ "@testing-library/react": "^14.3.1",
49
+ "@types/react": "^18.2.0",
50
+ "jsdom": "^24.1.3",
51
+ "typescript": "^5.5.0",
52
+ "vitest": "^3.2.4",
53
+ "prettier": "^3.4.2",
54
+ "react-dom": "^18.2.0",
55
+ "tsup": "^8.0.1"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ }
60
+ }