@motion-core/motion-gpu 0.4.0 → 0.4.2
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/dist/advanced.d.ts +1 -0
- package/dist/advanced.d.ts.map +1 -0
- package/dist/advanced.js +12 -6
- package/dist/core/advanced.d.ts +1 -0
- package/dist/core/advanced.d.ts.map +1 -0
- package/dist/core/advanced.js +12 -5
- package/dist/core/current-value.d.ts +1 -0
- package/dist/core/current-value.d.ts.map +1 -0
- package/dist/core/current-value.js +35 -34
- package/dist/core/current-value.js.map +1 -0
- package/dist/core/error-diagnostics.d.ts +1 -0
- package/dist/core/error-diagnostics.d.ts.map +1 -0
- package/dist/core/error-diagnostics.js +70 -137
- package/dist/core/error-diagnostics.js.map +1 -0
- package/dist/core/error-report.d.ts +1 -0
- package/dist/core/error-report.d.ts.map +1 -0
- package/dist/core/error-report.js +184 -233
- package/dist/core/error-report.js.map +1 -0
- package/dist/core/frame-registry.d.ts +1 -0
- package/dist/core/frame-registry.d.ts.map +1 -0
- package/dist/core/frame-registry.js +546 -662
- package/dist/core/frame-registry.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +11 -12
- package/dist/core/material-preprocess.d.ts +1 -0
- package/dist/core/material-preprocess.d.ts.map +1 -0
- package/dist/core/material-preprocess.js +128 -151
- package/dist/core/material-preprocess.js.map +1 -0
- package/dist/core/material.d.ts +1 -0
- package/dist/core/material.d.ts.map +1 -0
- package/dist/core/material.js +263 -317
- package/dist/core/material.js.map +1 -0
- package/dist/core/recompile-policy.d.ts +1 -0
- package/dist/core/recompile-policy.d.ts.map +1 -0
- package/dist/core/recompile-policy.js +18 -13
- package/dist/core/recompile-policy.js.map +1 -0
- package/dist/core/render-graph.d.ts +1 -0
- package/dist/core/render-graph.d.ts.map +1 -0
- package/dist/core/render-graph.js +61 -68
- package/dist/core/render-graph.js.map +1 -0
- package/dist/core/render-targets.d.ts +2 -0
- package/dist/core/render-targets.d.ts.map +1 -0
- package/dist/core/render-targets.js +52 -53
- package/dist/core/render-targets.js.map +1 -0
- package/dist/core/renderer.d.ts +1 -0
- package/dist/core/renderer.d.ts.map +1 -0
- package/dist/core/renderer.js +942 -1081
- package/dist/core/renderer.js.map +1 -0
- package/dist/core/runtime-loop.d.ts +2 -0
- package/dist/core/runtime-loop.d.ts.map +1 -0
- package/dist/core/runtime-loop.js +305 -362
- package/dist/core/runtime-loop.js.map +1 -0
- package/dist/core/scheduler-helpers.d.ts +1 -0
- package/dist/core/scheduler-helpers.d.ts.map +1 -0
- package/dist/core/scheduler-helpers.js +52 -51
- package/dist/core/scheduler-helpers.js.map +1 -0
- package/dist/core/shader.d.ts +1 -0
- package/dist/core/shader.d.ts.map +1 -0
- package/dist/core/shader.js +92 -117
- package/dist/core/shader.js.map +1 -0
- package/dist/core/texture-loader.d.ts +1 -0
- package/dist/core/texture-loader.d.ts.map +1 -0
- package/dist/core/texture-loader.js +205 -273
- package/dist/core/texture-loader.js.map +1 -0
- package/dist/core/textures.d.ts +2 -0
- package/dist/core/textures.d.ts.map +1 -0
- package/dist/core/textures.js +106 -116
- package/dist/core/textures.js.map +1 -0
- package/dist/core/types.d.ts +2 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +0 -4
- package/dist/core/uniforms.d.ts +1 -0
- package/dist/core/uniforms.d.ts.map +1 -0
- package/dist/core/uniforms.js +170 -191
- package/dist/core/uniforms.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -6
- package/dist/passes/BlitPass.d.ts +1 -0
- package/dist/passes/BlitPass.d.ts.map +1 -0
- package/dist/passes/BlitPass.js +23 -18
- package/dist/passes/BlitPass.js.map +1 -0
- package/dist/passes/CopyPass.d.ts +2 -0
- package/dist/passes/CopyPass.d.ts.map +1 -0
- package/dist/passes/CopyPass.js +58 -52
- package/dist/passes/CopyPass.js.map +1 -0
- package/dist/passes/FullscreenPass.d.ts +2 -0
- package/dist/passes/FullscreenPass.d.ts.map +1 -0
- package/dist/passes/FullscreenPass.js +127 -130
- package/dist/passes/FullscreenPass.js.map +1 -0
- package/dist/passes/ShaderPass.d.ts +1 -0
- package/dist/passes/ShaderPass.d.ts.map +1 -0
- package/dist/passes/ShaderPass.js +40 -37
- package/dist/passes/ShaderPass.js.map +1 -0
- package/dist/passes/index.d.ts +1 -0
- package/dist/passes/index.d.ts.map +1 -0
- package/dist/passes/index.js +4 -3
- package/dist/react/FragCanvas.d.ts +2 -0
- package/dist/react/FragCanvas.d.ts.map +1 -0
- package/dist/react/FragCanvas.js +234 -211
- package/dist/react/FragCanvas.js.map +1 -0
- package/dist/react/MotionGPUErrorOverlay.d.ts +1 -0
- package/dist/react/MotionGPUErrorOverlay.d.ts.map +1 -0
- package/dist/react/MotionGPUErrorOverlay.js +384 -48
- package/dist/react/MotionGPUErrorOverlay.js.map +1 -0
- package/dist/react/Portal.d.ts +1 -0
- package/dist/react/Portal.d.ts.map +1 -0
- package/dist/react/Portal.js +18 -21
- package/dist/react/Portal.js.map +1 -0
- package/dist/react/advanced.d.ts +1 -0
- package/dist/react/advanced.d.ts.map +1 -0
- package/dist/react/advanced.js +12 -6
- package/dist/react/frame-context.d.ts +1 -0
- package/dist/react/frame-context.d.ts.map +1 -0
- package/dist/react/frame-context.js +88 -94
- package/dist/react/frame-context.js.map +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +10 -9
- package/dist/react/motiongpu-context.d.ts +1 -0
- package/dist/react/motiongpu-context.d.ts.map +1 -0
- package/dist/react/motiongpu-context.js +18 -15
- package/dist/react/motiongpu-context.js.map +1 -0
- package/dist/react/use-motiongpu-user-context.d.ts +1 -0
- package/dist/react/use-motiongpu-user-context.d.ts.map +1 -0
- package/dist/react/use-motiongpu-user-context.js +83 -82
- package/dist/react/use-motiongpu-user-context.js.map +1 -0
- package/dist/react/use-texture.d.ts +1 -0
- package/dist/react/use-texture.d.ts.map +1 -0
- package/dist/react/use-texture.js +132 -152
- package/dist/react/use-texture.js.map +1 -0
- package/dist/svelte/FragCanvas.svelte.d.ts +2 -0
- package/dist/svelte/FragCanvas.svelte.d.ts.map +1 -0
- package/dist/svelte/MotionGPUErrorOverlay.svelte +17 -20
- package/dist/svelte/MotionGPUErrorOverlay.svelte.d.ts +1 -0
- package/dist/svelte/MotionGPUErrorOverlay.svelte.d.ts.map +1 -0
- package/dist/svelte/Portal.svelte.d.ts +1 -0
- package/dist/svelte/Portal.svelte.d.ts.map +1 -0
- package/dist/svelte/advanced.d.ts +1 -0
- package/dist/svelte/advanced.d.ts.map +1 -0
- package/dist/svelte/advanced.js +11 -6
- package/dist/svelte/frame-context.d.ts +1 -0
- package/dist/svelte/frame-context.d.ts.map +1 -0
- package/dist/svelte/frame-context.js +27 -27
- package/dist/svelte/frame-context.js.map +1 -0
- package/dist/svelte/index.d.ts +1 -0
- package/dist/svelte/index.d.ts.map +1 -0
- package/dist/svelte/index.js +10 -9
- package/dist/svelte/motiongpu-context.d.ts +1 -0
- package/dist/svelte/motiongpu-context.d.ts.map +1 -0
- package/dist/svelte/motiongpu-context.js +24 -21
- package/dist/svelte/motiongpu-context.js.map +1 -0
- package/dist/svelte/use-motiongpu-user-context.d.ts +1 -0
- package/dist/svelte/use-motiongpu-user-context.d.ts.map +1 -0
- package/dist/svelte/use-motiongpu-user-context.js +69 -70
- package/dist/svelte/use-motiongpu-user-context.js.map +1 -0
- package/dist/svelte/use-texture.d.ts +1 -0
- package/dist/svelte/use-texture.d.ts.map +1 -0
- package/dist/svelte/use-texture.js +125 -147
- package/dist/svelte/use-texture.js.map +1 -0
- package/package.json +15 -7
- package/src/lib/advanced.ts +6 -0
- package/src/lib/core/advanced.ts +12 -0
- package/src/lib/core/current-value.ts +64 -0
- package/src/lib/core/error-diagnostics.ts +236 -0
- package/src/lib/core/error-report.ts +406 -0
- package/src/lib/core/frame-registry.ts +1189 -0
- package/src/lib/core/index.ts +77 -0
- package/src/lib/core/material-preprocess.ts +284 -0
- package/src/lib/core/material.ts +667 -0
- package/src/lib/core/recompile-policy.ts +31 -0
- package/src/lib/core/render-graph.ts +143 -0
- package/src/lib/core/render-targets.ts +107 -0
- package/src/lib/core/renderer.ts +1547 -0
- package/src/lib/core/runtime-loop.ts +458 -0
- package/src/lib/core/scheduler-helpers.ts +136 -0
- package/src/lib/core/shader.ts +258 -0
- package/src/lib/core/texture-loader.ts +476 -0
- package/src/lib/core/textures.ts +235 -0
- package/src/lib/core/types.ts +582 -0
- package/src/lib/core/uniforms.ts +282 -0
- package/src/lib/index.ts +6 -0
- package/src/lib/passes/BlitPass.ts +54 -0
- package/src/lib/passes/CopyPass.ts +80 -0
- package/src/lib/passes/FullscreenPass.ts +173 -0
- package/src/lib/passes/ShaderPass.ts +88 -0
- package/src/lib/passes/index.ts +3 -0
- package/src/lib/react/MotionGPUErrorOverlay.tsx +392 -0
- package/src/lib/react/advanced.ts +36 -0
- package/src/lib/react/frame-context.ts +169 -0
- package/src/lib/react/index.ts +51 -0
- package/src/lib/react/motiongpu-context.ts +88 -0
- package/src/lib/react/use-motiongpu-user-context.ts +186 -0
- package/src/lib/react/use-texture.ts +233 -0
- package/src/lib/svelte/FragCanvas.svelte +249 -0
- package/src/lib/svelte/MotionGPUErrorOverlay.svelte +382 -0
- package/src/lib/svelte/Portal.svelte +31 -0
- package/src/lib/svelte/advanced.ts +32 -0
- package/src/lib/svelte/frame-context.ts +87 -0
- package/src/lib/svelte/index.ts +51 -0
- package/src/lib/svelte/motiongpu-context.ts +97 -0
- package/src/lib/svelte/use-motiongpu-user-context.ts +145 -0
- package/src/lib/svelte/use-texture.ts +232 -0
- package/dist/react/MotionGPUErrorOverlay.tsx +0 -129
- /package/{dist → src/lib}/react/FragCanvas.tsx +0 -0
- /package/{dist → src/lib}/react/Portal.tsx +0 -0
|
@@ -1,98 +1,92 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { createCurrentWritable } from "../core/current-value.js";
|
|
2
|
+
import { useMotionGPU } from "./motiongpu-context.js";
|
|
3
|
+
import { createContext, useContext, useEffect, useRef } from "react";
|
|
4
|
+
//#region src/lib/react/frame-context.ts
|
|
4
5
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
* Placeholder stage used before a frame task registration becomes available.
|
|
7
|
+
*/
|
|
8
|
+
var PENDING_STAGE_KEY = Symbol("motiongpu-react-pending-stage");
|
|
8
9
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
* React context container for the active frame registry.
|
|
11
|
+
*/
|
|
12
|
+
var FrameRegistryReactContext = createContext(null);
|
|
12
13
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
get task() {
|
|
88
|
-
return taskRef.current;
|
|
89
|
-
},
|
|
90
|
-
start: () => {
|
|
91
|
-
registrationRef.current?.start();
|
|
92
|
-
},
|
|
93
|
-
stop: () => {
|
|
94
|
-
registrationRef.current?.stop();
|
|
95
|
-
},
|
|
96
|
-
started: startedStore
|
|
97
|
-
};
|
|
14
|
+
* Registers a callback in the active frame registry and auto-unsubscribes on unmount.
|
|
15
|
+
*
|
|
16
|
+
* @param keyOrCallback - Task key or callback for auto-key registration.
|
|
17
|
+
* @param callbackOrOptions - Callback (keyed overload) or options (auto-key overload).
|
|
18
|
+
* @param maybeOptions - Optional registration options for keyed overload.
|
|
19
|
+
* Registration key/options are frozen on first render; subsequent renders do not re-register.
|
|
20
|
+
* @returns Registration control API with task, start/stop controls and started state.
|
|
21
|
+
* @throws {Error} When called outside `<FragCanvas>`.
|
|
22
|
+
* @throws {Error} When callback is missing in keyed overload.
|
|
23
|
+
*/
|
|
24
|
+
function useFrame(keyOrCallback, callbackOrOptions, maybeOptions) {
|
|
25
|
+
const registry = useContext(FrameRegistryReactContext);
|
|
26
|
+
if (!registry) throw new Error("useFrame must be used inside <FragCanvas>");
|
|
27
|
+
const motiongpu = useMotionGPU();
|
|
28
|
+
const resolved = typeof keyOrCallback === "function" ? {
|
|
29
|
+
key: void 0,
|
|
30
|
+
callback: keyOrCallback,
|
|
31
|
+
options: callbackOrOptions
|
|
32
|
+
} : {
|
|
33
|
+
key: keyOrCallback,
|
|
34
|
+
callback: callbackOrOptions,
|
|
35
|
+
options: maybeOptions
|
|
36
|
+
};
|
|
37
|
+
if (typeof resolved.callback !== "function") throw new Error("useFrame requires a callback");
|
|
38
|
+
const callbackRef = useRef(resolved.callback);
|
|
39
|
+
callbackRef.current = resolved.callback;
|
|
40
|
+
const registrationConfigRef = useRef(null);
|
|
41
|
+
if (!registrationConfigRef.current) registrationConfigRef.current = {
|
|
42
|
+
key: resolved.key,
|
|
43
|
+
options: resolved.options
|
|
44
|
+
};
|
|
45
|
+
const registrationConfig = registrationConfigRef.current;
|
|
46
|
+
const registrationRef = useRef(null);
|
|
47
|
+
const taskRef = useRef({
|
|
48
|
+
key: registrationConfig.key !== void 0 ? registrationConfig.key : Symbol("motiongpu-react-pending-task-key"),
|
|
49
|
+
stage: PENDING_STAGE_KEY
|
|
50
|
+
});
|
|
51
|
+
const startedStore = useRef(createCurrentWritable(false)).current;
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const wrappedCallback = (state) => {
|
|
54
|
+
callbackRef.current(state);
|
|
55
|
+
};
|
|
56
|
+
const registration = registrationConfig.key === void 0 ? registry.register(wrappedCallback, registrationConfig.options) : registry.register(registrationConfig.key, wrappedCallback, registrationConfig.options);
|
|
57
|
+
registrationRef.current = registration;
|
|
58
|
+
taskRef.current = registration.task;
|
|
59
|
+
const unsubscribeStarted = registration.started.subscribe((value) => {
|
|
60
|
+
startedStore.set(value);
|
|
61
|
+
});
|
|
62
|
+
return () => {
|
|
63
|
+
unsubscribeStarted();
|
|
64
|
+
registration.unsubscribe();
|
|
65
|
+
if (registrationRef.current === registration) registrationRef.current = null;
|
|
66
|
+
startedStore.set(false);
|
|
67
|
+
};
|
|
68
|
+
}, [
|
|
69
|
+
registrationConfig,
|
|
70
|
+
registry,
|
|
71
|
+
startedStore
|
|
72
|
+
]);
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
motiongpu.invalidate();
|
|
75
|
+
}, [motiongpu, resolved.callback]);
|
|
76
|
+
return {
|
|
77
|
+
get task() {
|
|
78
|
+
return taskRef.current;
|
|
79
|
+
},
|
|
80
|
+
start: () => {
|
|
81
|
+
registrationRef.current?.start();
|
|
82
|
+
},
|
|
83
|
+
stop: () => {
|
|
84
|
+
registrationRef.current?.stop();
|
|
85
|
+
},
|
|
86
|
+
started: startedStore
|
|
87
|
+
};
|
|
98
88
|
}
|
|
89
|
+
//#endregion
|
|
90
|
+
export { FrameRegistryReactContext, useFrame };
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=frame-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-context.js","names":[],"sources":["../../src/lib/react/frame-context.ts"],"sourcesContent":["import { createContext, useContext, useEffect, useRef } from 'react';\nimport { createCurrentWritable } from '../core/current-value.js';\nimport { useMotionGPU } from './motiongpu-context.js';\nimport type {\n\tFrameCallback,\n\tFrameKey,\n\tFrameProfilingSnapshot,\n\tFrameRegistry,\n\tFrameRunTimings,\n\tFrameScheduleSnapshot,\n\tFrameStage,\n\tFrameStageCallback,\n\tFrameTask,\n\tFrameTaskInvalidation,\n\tFrameTaskInvalidationToken,\n\tUseFrameOptions,\n\tUseFrameResult\n} from '../core/frame-registry.js';\n\n/**\n * Placeholder stage used before a frame task registration becomes available.\n */\nconst PENDING_STAGE_KEY = Symbol('motiongpu-react-pending-stage');\n\n/**\n * React context container for the active frame registry.\n */\nexport const FrameRegistryReactContext = createContext<FrameRegistry | null>(null);\n\nexport type {\n\tFrameCallback,\n\tFrameKey,\n\tFrameProfilingSnapshot,\n\tFrameRegistry,\n\tFrameRunTimings,\n\tFrameScheduleSnapshot,\n\tFrameStage,\n\tFrameStageCallback,\n\tFrameTask,\n\tFrameTaskInvalidation,\n\tFrameTaskInvalidationToken,\n\tUseFrameOptions,\n\tUseFrameResult\n};\n\n/**\n * Registers a frame callback using an auto-generated task key.\n */\nexport function useFrame(callback: FrameCallback, options?: UseFrameOptions): UseFrameResult;\n\n/**\n * Registers a frame callback with an explicit task key.\n */\nexport function useFrame(\n\tkey: FrameKey,\n\tcallback: FrameCallback,\n\toptions?: UseFrameOptions\n): UseFrameResult;\n\n/**\n * Registers a callback in the active frame registry and auto-unsubscribes on unmount.\n *\n * @param keyOrCallback - Task key or callback for auto-key registration.\n * @param callbackOrOptions - Callback (keyed overload) or options (auto-key overload).\n * @param maybeOptions - Optional registration options for keyed overload.\n * Registration key/options are frozen on first render; subsequent renders do not re-register.\n * @returns Registration control API with task, start/stop controls and started state.\n * @throws {Error} When called outside `<FragCanvas>`.\n * @throws {Error} When callback is missing in keyed overload.\n */\nexport function useFrame(\n\tkeyOrCallback: FrameKey | FrameCallback,\n\tcallbackOrOptions?: FrameCallback | UseFrameOptions,\n\tmaybeOptions?: UseFrameOptions\n): UseFrameResult {\n\tconst registry = useContext(FrameRegistryReactContext);\n\tif (!registry) {\n\t\tthrow new Error('useFrame must be used inside <FragCanvas>');\n\t}\n\tconst motiongpu = useMotionGPU();\n\n\tconst resolved =\n\t\ttypeof keyOrCallback === 'function'\n\t\t\t? {\n\t\t\t\t\tkey: undefined,\n\t\t\t\t\tcallback: keyOrCallback,\n\t\t\t\t\toptions: callbackOrOptions as UseFrameOptions | undefined\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tkey: keyOrCallback,\n\t\t\t\t\tcallback: callbackOrOptions as FrameCallback,\n\t\t\t\t\toptions: maybeOptions\n\t\t\t\t};\n\tif (typeof resolved.callback !== 'function') {\n\t\tthrow new Error('useFrame requires a callback');\n\t}\n\n\tconst callbackRef = useRef(resolved.callback);\n\tcallbackRef.current = resolved.callback;\n\tconst registrationConfigRef = useRef<{\n\t\tkey: FrameKey | undefined;\n\t\toptions: UseFrameOptions | undefined;\n\t} | null>(null);\n\tif (!registrationConfigRef.current) {\n\t\tregistrationConfigRef.current = {\n\t\t\tkey: resolved.key,\n\t\t\toptions: resolved.options\n\t\t};\n\t}\n\tconst registrationConfig = registrationConfigRef.current;\n\n\tconst registrationRef = useRef<{\n\t\ttask: FrameTask;\n\t\tstart: () => void;\n\t\tstop: () => void;\n\t\tstarted: UseFrameResult['started'];\n\t\tunsubscribe: () => void;\n\t} | null>(null);\n\tconst taskRef = useRef<FrameTask>({\n\t\tkey:\n\t\t\tregistrationConfig.key !== undefined\n\t\t\t\t? registrationConfig.key\n\t\t\t\t: Symbol('motiongpu-react-pending-task-key'),\n\t\tstage: PENDING_STAGE_KEY\n\t});\n\tconst startedStoreRef = useRef(createCurrentWritable(false));\n\tconst startedStore = startedStoreRef.current;\n\n\tuseEffect(() => {\n\t\tconst wrappedCallback: FrameCallback = (state) => {\n\t\t\tcallbackRef.current(state);\n\t\t};\n\t\tconst registration =\n\t\t\tregistrationConfig.key === undefined\n\t\t\t\t? registry.register(wrappedCallback, registrationConfig.options)\n\t\t\t\t: registry.register(registrationConfig.key, wrappedCallback, registrationConfig.options);\n\t\tregistrationRef.current = registration;\n\t\ttaskRef.current = registration.task;\n\t\tconst unsubscribeStarted = registration.started.subscribe((value) => {\n\t\t\tstartedStore.set(value);\n\t\t});\n\n\t\treturn () => {\n\t\t\tunsubscribeStarted();\n\t\t\tregistration.unsubscribe();\n\t\t\tif (registrationRef.current === registration) {\n\t\t\t\tregistrationRef.current = null;\n\t\t\t}\n\t\t\tstartedStore.set(false);\n\t\t};\n\t}, [registrationConfig, registry, startedStore]);\n\n\tuseEffect(() => {\n\t\tmotiongpu.invalidate();\n\t}, [motiongpu, resolved.callback]);\n\n\treturn {\n\t\tget task() {\n\t\t\treturn taskRef.current;\n\t\t},\n\t\tstart: () => {\n\t\t\tregistrationRef.current?.start();\n\t\t},\n\t\tstop: () => {\n\t\t\tregistrationRef.current?.stop();\n\t\t},\n\t\tstarted: startedStore\n\t};\n}\n"],"mappings":";;;;;;;AAsBA,IAAM,oBAAoB,OAAO,gCAAgC;;;;AAKjE,IAAa,4BAA4B,cAAoC,KAAK;;;;;;;;;;;;AA2ClF,SAAgB,SACf,eACA,mBACA,cACiB;CACjB,MAAM,WAAW,WAAW,0BAA0B;AACtD,KAAI,CAAC,SACJ,OAAM,IAAI,MAAM,4CAA4C;CAE7D,MAAM,YAAY,cAAc;CAEhC,MAAM,WACL,OAAO,kBAAkB,aACtB;EACA,KAAK;EACL,UAAU;EACV,SAAS;EACT,GACA;EACA,KAAK;EACL,UAAU;EACV,SAAS;EACT;AACJ,KAAI,OAAO,SAAS,aAAa,WAChC,OAAM,IAAI,MAAM,+BAA+B;CAGhD,MAAM,cAAc,OAAO,SAAS,SAAS;AAC7C,aAAY,UAAU,SAAS;CAC/B,MAAM,wBAAwB,OAGpB,KAAK;AACf,KAAI,CAAC,sBAAsB,QAC1B,uBAAsB,UAAU;EAC/B,KAAK,SAAS;EACd,SAAS,SAAS;EAClB;CAEF,MAAM,qBAAqB,sBAAsB;CAEjD,MAAM,kBAAkB,OAMd,KAAK;CACf,MAAM,UAAU,OAAkB;EACjC,KACC,mBAAmB,QAAQ,SACxB,mBAAmB,MACnB,OAAO,mCAAmC;EAC9C,OAAO;EACP,CAAC;CAEF,MAAM,eADkB,OAAO,sBAAsB,MAAM,CAAC,CACvB;AAErC,iBAAgB;EACf,MAAM,mBAAkC,UAAU;AACjD,eAAY,QAAQ,MAAM;;EAE3B,MAAM,eACL,mBAAmB,QAAQ,SACxB,SAAS,SAAS,iBAAiB,mBAAmB,QAAQ,GAC9D,SAAS,SAAS,mBAAmB,KAAK,iBAAiB,mBAAmB,QAAQ;AAC1F,kBAAgB,UAAU;AAC1B,UAAQ,UAAU,aAAa;EAC/B,MAAM,qBAAqB,aAAa,QAAQ,WAAW,UAAU;AACpE,gBAAa,IAAI,MAAM;IACtB;AAEF,eAAa;AACZ,uBAAoB;AACpB,gBAAa,aAAa;AAC1B,OAAI,gBAAgB,YAAY,aAC/B,iBAAgB,UAAU;AAE3B,gBAAa,IAAI,MAAM;;IAEtB;EAAC;EAAoB;EAAU;EAAa,CAAC;AAEhD,iBAAgB;AACf,YAAU,YAAY;IACpB,CAAC,WAAW,SAAS,SAAS,CAAC;AAElC,QAAO;EACN,IAAI,OAAO;AACV,UAAO,QAAQ;;EAEhB,aAAa;AACZ,mBAAgB,SAAS,OAAO;;EAEjC,YAAY;AACX,mBAAgB,SAAS,MAAM;;EAEhC,SAAS;EACT"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -13,3 +13,4 @@ export type { FragMaterial, FragMaterialInput, MaterialIncludes, MaterialDefineV
|
|
|
13
13
|
export type { MotionGPUContext } from './motiongpu-context.js';
|
|
14
14
|
export type { UseFrameOptions, UseFrameResult } from './frame-context.js';
|
|
15
15
|
export type { TextureUrlInput, UseTextureResult } from './use-texture.js';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/react/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,YAAY,EACX,sBAAsB,EACtB,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,UAAU,EACV,YAAY,EACZ,sBAAsB,EACtB,yBAAyB,EACzB,WAAW,EACX,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,YAAY,EACZ,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACX,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACX,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,wBAAwB,EACxB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC1E,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/react/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { defineMaterial } from "../core/material.js";
|
|
2
|
+
import { BlitPass } from "../passes/BlitPass.js";
|
|
3
|
+
import { CopyPass } from "../passes/CopyPass.js";
|
|
4
|
+
import { ShaderPass } from "../passes/ShaderPass.js";
|
|
5
|
+
import "../passes/index.js";
|
|
6
|
+
import { useMotionGPU } from "./motiongpu-context.js";
|
|
7
|
+
import { useFrame } from "./frame-context.js";
|
|
8
|
+
import { FragCanvas } from "./FragCanvas.js";
|
|
9
|
+
import { useTexture } from "./use-texture.js";
|
|
10
|
+
export { BlitPass, CopyPass, FragCanvas, ShaderPass, defineMaterial, useFrame, useMotionGPU, useTexture };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motiongpu-context.d.ts","sourceRoot":"","sources":["../../src/lib/react/motiongpu-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,KAAK,EACX,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,kBAAkB,IAAI,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEjG;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC;;OAEG;IACH,MAAM,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACtC;;OAEG;IACH,IAAI,EAAE,eAAe,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACzD;;OAEG;IACH,GAAG,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAC7B;;OAEG;IACH,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IAClC;;OAEG;IACH,UAAU,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC;IACxC;;OAEG;IACH,UAAU,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IACrC;;OAEG;IACH,IAAI,EAAE,oBAAoB,CAAC;IAC3B;;OAEG;IACH,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB;;OAEG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB;;OAEG;IACH,SAAS,EAAE,kBAAkB,CAAC;CAC9B;AAED,MAAM,MAAM,kBAAkB,GAAG,sBAAsB,CAAC;AACxD,YAAY,EAAE,sBAAsB,EAAE,eAAe,EAAE,qBAAqB,EAAE,CAAC;AAE/E;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,MAAM,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,eAAe,CAAC,MAAM,CAAC,sBAAsB,EAAE,OAAO,CAAC,CAAC,CAAC;AAE5F;;GAEG;AACH,eAAO,MAAM,qBAAqB,kDAA+C,CAAC;AAElF;;;;;GAKG;AACH,wBAAgB,YAAY,IAAI,gBAAgB,CAO/C"}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { createContext, useContext } from
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
//#region src/lib/react/motiongpu-context.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
* Internal React context container.
|
|
5
|
+
*/
|
|
6
|
+
var MotionGPUReactContext = createContext(null);
|
|
6
7
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
return context;
|
|
8
|
+
* Returns active MotionGPU runtime context.
|
|
9
|
+
*
|
|
10
|
+
* @returns Active context.
|
|
11
|
+
* @throws {Error} When called outside `<FragCanvas>`.
|
|
12
|
+
*/
|
|
13
|
+
function useMotionGPU() {
|
|
14
|
+
const context = useContext(MotionGPUReactContext);
|
|
15
|
+
if (!context) throw new Error("useMotionGPU must be used inside <FragCanvas>");
|
|
16
|
+
return context;
|
|
18
17
|
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { MotionGPUReactContext, useMotionGPU };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=motiongpu-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"motiongpu-context.js","names":[],"sources":["../../src/lib/react/motiongpu-context.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\nimport type { RenderMode } from '../core/types.js';\nimport type { CurrentReadable, CurrentWritable } from '../core/current-value.js';\nimport type {\n\tFrameProfilingSnapshot,\n\tFrameRunTimings,\n\tFrameScheduleSnapshot\n} from '../core/frame-registry.js';\nimport type { MotionGPUScheduler as CoreMotionGPUScheduler } from '../core/scheduler-helpers.js';\n\n/**\n * React context payload exposed by `<FragCanvas>`.\n */\nexport interface MotionGPUContext {\n\t/**\n\t * Underlying canvas element used by the renderer.\n\t */\n\tcanvas: HTMLCanvasElement | undefined;\n\t/**\n\t * Reactive canvas pixel size.\n\t */\n\tsize: CurrentReadable<{ width: number; height: number }>;\n\t/**\n\t * Device pixel ratio multiplier.\n\t */\n\tdpr: CurrentWritable<number>;\n\t/**\n\t * Max frame delta clamp passed to scheduled callbacks.\n\t */\n\tmaxDelta: CurrentWritable<number>;\n\t/**\n\t * Scheduler render mode (`always`, `on-demand`, `manual`).\n\t */\n\trenderMode: CurrentWritable<RenderMode>;\n\t/**\n\t * Global toggle for automatic rendering.\n\t */\n\tautoRender: CurrentWritable<boolean>;\n\t/**\n\t * Namespaced user context store shared within the canvas subtree.\n\t */\n\tuser: MotionGPUUserContext;\n\t/**\n\t * Marks current frame as invalidated.\n\t */\n\tinvalidate: () => void;\n\t/**\n\t * Requests one manual frame advance.\n\t */\n\tadvance: () => void;\n\t/**\n\t * Public scheduler API.\n\t */\n\tscheduler: MotionGPUScheduler;\n}\n\nexport type MotionGPUScheduler = CoreMotionGPUScheduler;\nexport type { FrameProfilingSnapshot, FrameRunTimings, FrameScheduleSnapshot };\n\n/**\n * Namespace identifier for user-owned context entries.\n */\nexport type MotionGPUUserNamespace = string | symbol;\n\n/**\n * Shared user context store exposed by `FragCanvas`.\n */\nexport type MotionGPUUserContext = CurrentWritable<Record<MotionGPUUserNamespace, unknown>>;\n\n/**\n * Internal React context container.\n */\nexport const MotionGPUReactContext = createContext<MotionGPUContext | null>(null);\n\n/**\n * Returns active MotionGPU runtime context.\n *\n * @returns Active context.\n * @throws {Error} When called outside `<FragCanvas>`.\n */\nexport function useMotionGPU(): MotionGPUContext {\n\tconst context = useContext(MotionGPUReactContext);\n\tif (!context) {\n\t\tthrow new Error('useMotionGPU must be used inside <FragCanvas>');\n\t}\n\n\treturn context;\n}\n"],"mappings":";;;;;AAwEA,IAAa,wBAAwB,cAAuC,KAAK;;;;;;;AAQjF,SAAgB,eAAiC;CAChD,MAAM,UAAU,WAAW,sBAAsB;AACjD,KAAI,CAAC,QACJ,OAAM,IAAI,MAAM,gDAAgD;AAGjE,QAAO"}
|
|
@@ -47,3 +47,4 @@ export declare function useSetMotionGPUUserContext(): <UCT = unknown>(namespace:
|
|
|
47
47
|
*/
|
|
48
48
|
export declare function setMotionGPUUserContext<UCT = unknown>(namespace: MotionGPUUserNamespace, value: UCT | (() => UCT), options?: SetMotionGPUUserContextOptions): UCT | undefined;
|
|
49
49
|
export {};
|
|
50
|
+
//# sourceMappingURL=use-motiongpu-user-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-motiongpu-user-context.d.ts","sourceRoot":"","sources":["../../src/lib/react/use-motiongpu-user-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAGN,KAAK,sBAAsB,EAC3B,MAAM,wBAAwB,CAAC;AAEhC;;GAEG;AACH,KAAK,gBAAgB,GAAG,MAAM,CAAC,sBAAsB,EAAE,OAAO,CAAC,CAAC;AAOhE;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC9C;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;IACxC;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;CACpC;AA2DD;;GAEG;AACH,wBAAgB,uBAAuB,CACtC,EAAE,SAAS,gBAAgB,GAAG,gBAAgB,KAC1C,eAAe,CAAC,EAAE,CAAC,CAAC;AAEzB;;GAEG;AACH,wBAAgB,uBAAuB,CACtC,EAAE,SAAS,gBAAgB,GAAG,gBAAgB,EAC9C,CAAC,SAAS,MAAM,EAAE,GAAG,sBAAsB,GAAG,MAAM,EAAE,GAAG,sBAAsB,EAC9E,SAAS,EAAE,CAAC,GAAG,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AA8CpD;;;;GAIG;AACH,wBAAgB,0BAA0B,KAGvC,GAAG,uBACQ,sBAAsB,SAC1B,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,YACd,8BAA8B,KACtC,GAAG,GAAG,SAAS,CAGnB;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,GAAG,OAAO,EACpD,SAAS,EAAE,sBAAsB,EACjC,KAAK,EAAE,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EACxB,OAAO,CAAC,EAAE,8BAA8B,GACtC,GAAG,GAAG,SAAS,CAEjB"}
|
|
@@ -1,94 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useMotionGPU } from "./motiongpu-context.js";
|
|
2
|
+
import { useCallback, useMemo } from "react";
|
|
3
|
+
//#region src/lib/react/use-motiongpu-user-context.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
* Checks whether a value is a non-array object suitable for shallow merge.
|
|
6
|
+
*/
|
|
6
7
|
function isObjectEntry(value) {
|
|
7
|
-
|
|
8
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
* Sets a namespaced user context value in the provided user store.
|
|
12
|
+
*
|
|
13
|
+
* Returns the effective value stored under the namespace.
|
|
14
|
+
*/
|
|
14
15
|
function setMotionGPUUserContextInStore(userStore, namespace, value, options) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
return resolvedValue;
|
|
16
|
+
const mode = options?.existing ?? "skip";
|
|
17
|
+
const functionValueMode = options?.functionValue ?? "factory";
|
|
18
|
+
let resolvedValue;
|
|
19
|
+
userStore.update((context) => {
|
|
20
|
+
const hasExisting = namespace in context;
|
|
21
|
+
if (hasExisting && mode === "skip") {
|
|
22
|
+
resolvedValue = context[namespace];
|
|
23
|
+
return context;
|
|
24
|
+
}
|
|
25
|
+
const nextValue = typeof value === "function" && functionValueMode === "factory" ? value() : value;
|
|
26
|
+
if (hasExisting && mode === "merge") {
|
|
27
|
+
const currentValue = context[namespace];
|
|
28
|
+
if (isObjectEntry(currentValue) && isObjectEntry(nextValue)) {
|
|
29
|
+
resolvedValue = {
|
|
30
|
+
...currentValue,
|
|
31
|
+
...nextValue
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
...context,
|
|
35
|
+
[namespace]: resolvedValue
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
resolvedValue = nextValue;
|
|
40
|
+
return {
|
|
41
|
+
...context,
|
|
42
|
+
[namespace]: nextValue
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
return resolvedValue;
|
|
47
46
|
}
|
|
48
47
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
return scopedStore;
|
|
48
|
+
* Read-only user context hook:
|
|
49
|
+
* - no args: returns full user context store
|
|
50
|
+
* - namespace: returns namespaced store view
|
|
51
|
+
*
|
|
52
|
+
* @param namespace - Optional namespace key.
|
|
53
|
+
*/
|
|
54
|
+
function useMotionGPUUserContext(namespace) {
|
|
55
|
+
const userStore = useMotionGPU().user;
|
|
56
|
+
const allStore = useMemo(() => ({
|
|
57
|
+
get current() {
|
|
58
|
+
return userStore.current;
|
|
59
|
+
},
|
|
60
|
+
subscribe(run) {
|
|
61
|
+
return userStore.subscribe((context) => run(context));
|
|
62
|
+
}
|
|
63
|
+
}), [userStore]);
|
|
64
|
+
const scopedStore = useMemo(() => ({
|
|
65
|
+
get current() {
|
|
66
|
+
return userStore.current[namespace];
|
|
67
|
+
},
|
|
68
|
+
subscribe(run) {
|
|
69
|
+
return userStore.subscribe((context) => run(context[namespace]));
|
|
70
|
+
}
|
|
71
|
+
}), [namespace, userStore]);
|
|
72
|
+
if (namespace === void 0) return allStore;
|
|
73
|
+
return scopedStore;
|
|
77
74
|
}
|
|
78
75
|
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
* Returns a stable setter bound to the active MotionGPU user context store.
|
|
77
|
+
*
|
|
78
|
+
* @returns Setter function that preserves namespace write semantics.
|
|
79
|
+
*/
|
|
80
|
+
function useSetMotionGPUUserContext() {
|
|
81
|
+
const userStore = useMotionGPU().user;
|
|
82
|
+
return useCallback((namespace, value, options) => setMotionGPUUserContextInStore(userStore, namespace, value, options), [userStore]);
|
|
86
83
|
}
|
|
87
84
|
/**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
85
|
+
* Sets a namespaced user context value with explicit write semantics.
|
|
86
|
+
*
|
|
87
|
+
* Returns the effective value stored under the namespace.
|
|
88
|
+
*/
|
|
89
|
+
function setMotionGPUUserContext(namespace, value, options) {
|
|
90
|
+
return setMotionGPUUserContextInStore(useMotionGPU().user, namespace, value, options);
|
|
94
91
|
}
|
|
92
|
+
//#endregion
|
|
93
|
+
export { setMotionGPUUserContext, useMotionGPUUserContext, useSetMotionGPUUserContext };
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=use-motiongpu-user-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-motiongpu-user-context.js","names":[],"sources":["../../src/lib/react/use-motiongpu-user-context.ts"],"sourcesContent":["import { useCallback, useMemo } from 'react';\nimport type { CurrentReadable } from '../core/current-value.js';\nimport {\n\tuseMotionGPU,\n\ttype MotionGPUUserContext,\n\ttype MotionGPUUserNamespace\n} from './motiongpu-context.js';\n\n/**\n * Internal shape of the user context store.\n */\ntype UserContextStore = Record<MotionGPUUserNamespace, unknown>;\n\n/**\n * Object-like context payload used by merge semantics.\n */\ntype UserContextEntry = Record<string, unknown>;\n\n/**\n * Controls how a namespaced user context value behaves when already present.\n */\nexport interface SetMotionGPUUserContextOptions {\n\t/**\n\t * Conflict strategy when namespace already exists:\n\t * - `skip`: keep current value\n\t * - `replace`: replace current value\n\t * - `merge`: shallow merge object values, fallback to replace otherwise\n\t *\n\t * @default 'skip'\n\t */\n\texisting?: 'merge' | 'replace' | 'skip';\n\t/**\n\t * How function inputs should be interpreted:\n\t * - `factory`: call function and store its return value\n\t * - `value`: store function itself\n\t *\n\t * @default 'factory'\n\t */\n\tfunctionValue?: 'factory' | 'value';\n}\n\n/**\n * Checks whether a value is a non-array object suitable for shallow merge.\n */\nfunction isObjectEntry(value: unknown): value is UserContextEntry {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Sets a namespaced user context value in the provided user store.\n *\n * Returns the effective value stored under the namespace.\n */\nfunction setMotionGPUUserContextInStore<UCT = unknown>(\n\tuserStore: MotionGPUUserContext,\n\tnamespace: MotionGPUUserNamespace,\n\tvalue: UCT | (() => UCT),\n\toptions?: SetMotionGPUUserContextOptions\n): UCT | undefined {\n\tconst mode = options?.existing ?? 'skip';\n\tconst functionValueMode = options?.functionValue ?? 'factory';\n\tlet resolvedValue: UCT | undefined;\n\n\tuserStore.update((context) => {\n\t\tconst hasExisting = namespace in context;\n\t\tif (hasExisting && mode === 'skip') {\n\t\t\tresolvedValue = context[namespace] as UCT | undefined;\n\t\t\treturn context;\n\t\t}\n\n\t\tconst nextValue =\n\t\t\ttypeof value === 'function' && functionValueMode === 'factory'\n\t\t\t\t? (value as () => UCT)()\n\t\t\t\t: (value as UCT);\n\t\tif (hasExisting && mode === 'merge') {\n\t\t\tconst currentValue = context[namespace];\n\t\t\tif (isObjectEntry(currentValue) && isObjectEntry(nextValue)) {\n\t\t\t\tresolvedValue = {\n\t\t\t\t\t...currentValue,\n\t\t\t\t\t...nextValue\n\t\t\t\t} as UCT;\n\t\t\t\treturn {\n\t\t\t\t\t...context,\n\t\t\t\t\t[namespace]: resolvedValue\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tresolvedValue = nextValue;\n\t\treturn {\n\t\t\t...context,\n\t\t\t[namespace]: nextValue\n\t\t};\n\t});\n\n\treturn resolvedValue;\n}\n\n/**\n * Returns a read-only view of the entire motiongpu user context store.\n */\nexport function useMotionGPUUserContext<\n\tUC extends UserContextStore = UserContextStore\n>(): CurrentReadable<UC>;\n\n/**\n * Reads a namespaced user context value as a reactive readable store.\n */\nexport function useMotionGPUUserContext<\n\tUC extends UserContextStore = UserContextStore,\n\tK extends keyof UC & MotionGPUUserNamespace = keyof UC & MotionGPUUserNamespace\n>(namespace: K): CurrentReadable<UC[K] | undefined>;\n\n/**\n * Read-only user context hook:\n * - no args: returns full user context store\n * - namespace: returns namespaced store view\n *\n * @param namespace - Optional namespace key.\n */\nexport function useMotionGPUUserContext<\n\tUC extends UserContextStore = UserContextStore,\n\tK extends keyof UC & MotionGPUUserNamespace = keyof UC & MotionGPUUserNamespace\n>(namespace?: K): CurrentReadable<UC> | CurrentReadable<UC[K] | undefined> {\n\tconst userStore = useMotionGPU().user;\n\tconst allStore = useMemo<CurrentReadable<UC>>(\n\t\t() => ({\n\t\t\tget current() {\n\t\t\t\treturn userStore.current as UC;\n\t\t\t},\n\t\t\tsubscribe(run) {\n\t\t\t\treturn userStore.subscribe((context) => run(context as UC));\n\t\t\t}\n\t\t}),\n\t\t[userStore]\n\t);\n\tconst scopedStore = useMemo<CurrentReadable<UC[K] | undefined>>(\n\t\t() => ({\n\t\t\tget current() {\n\t\t\t\treturn userStore.current[namespace as MotionGPUUserNamespace] as UC[K] | undefined;\n\t\t\t},\n\t\t\tsubscribe(run) {\n\t\t\t\treturn userStore.subscribe((context) =>\n\t\t\t\t\trun(context[namespace as MotionGPUUserNamespace] as UC[K] | undefined)\n\t\t\t\t);\n\t\t\t}\n\t\t}),\n\t\t[namespace, userStore]\n\t);\n\n\tif (namespace === undefined) {\n\t\treturn allStore;\n\t}\n\n\treturn scopedStore;\n}\n\n/**\n * Returns a stable setter bound to the active MotionGPU user context store.\n *\n * @returns Setter function that preserves namespace write semantics.\n */\nexport function useSetMotionGPUUserContext() {\n\tconst userStore = useMotionGPU().user;\n\treturn useCallback(\n\t\t<UCT = unknown>(\n\t\t\tnamespace: MotionGPUUserNamespace,\n\t\t\tvalue: UCT | (() => UCT),\n\t\t\toptions?: SetMotionGPUUserContextOptions\n\t\t): UCT | undefined => setMotionGPUUserContextInStore(userStore, namespace, value, options),\n\t\t[userStore]\n\t);\n}\n\n/**\n * Sets a namespaced user context value with explicit write semantics.\n *\n * Returns the effective value stored under the namespace.\n */\nexport function setMotionGPUUserContext<UCT = unknown>(\n\tnamespace: MotionGPUUserNamespace,\n\tvalue: UCT | (() => UCT),\n\toptions?: SetMotionGPUUserContextOptions\n): UCT | undefined {\n\treturn setMotionGPUUserContextInStore(useMotionGPU().user, namespace, value, options);\n}\n"],"mappings":";;;;;;AA4CA,SAAS,cAAc,OAA2C;AACjE,QAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;;;;;;AAQ5E,SAAS,+BACR,WACA,WACA,OACA,SACkB;CAClB,MAAM,OAAO,SAAS,YAAY;CAClC,MAAM,oBAAoB,SAAS,iBAAiB;CACpD,IAAI;AAEJ,WAAU,QAAQ,YAAY;EAC7B,MAAM,cAAc,aAAa;AACjC,MAAI,eAAe,SAAS,QAAQ;AACnC,mBAAgB,QAAQ;AACxB,UAAO;;EAGR,MAAM,YACL,OAAO,UAAU,cAAc,sBAAsB,YACjD,OAAqB,GACrB;AACL,MAAI,eAAe,SAAS,SAAS;GACpC,MAAM,eAAe,QAAQ;AAC7B,OAAI,cAAc,aAAa,IAAI,cAAc,UAAU,EAAE;AAC5D,oBAAgB;KACf,GAAG;KACH,GAAG;KACH;AACD,WAAO;KACN,GAAG;MACF,YAAY;KACb;;;AAIH,kBAAgB;AAChB,SAAO;GACN,GAAG;IACF,YAAY;GACb;GACA;AAEF,QAAO;;;;;;;;;AAyBR,SAAgB,wBAGd,WAAyE;CAC1E,MAAM,YAAY,cAAc,CAAC;CACjC,MAAM,WAAW,eACT;EACN,IAAI,UAAU;AACb,UAAO,UAAU;;EAElB,UAAU,KAAK;AACd,UAAO,UAAU,WAAW,YAAY,IAAI,QAAc,CAAC;;EAE5D,GACD,CAAC,UAAU,CACX;CACD,MAAM,cAAc,eACZ;EACN,IAAI,UAAU;AACb,UAAO,UAAU,QAAQ;;EAE1B,UAAU,KAAK;AACd,UAAO,UAAU,WAAW,YAC3B,IAAI,QAAQ,WAA0D,CACtE;;EAEF,GACD,CAAC,WAAW,UAAU,CACtB;AAED,KAAI,cAAc,OACjB,QAAO;AAGR,QAAO;;;;;;;AAQR,SAAgB,6BAA6B;CAC5C,MAAM,YAAY,cAAc,CAAC;AACjC,QAAO,aAEL,WACA,OACA,YACqB,+BAA+B,WAAW,WAAW,OAAO,QAAQ,EAC1F,CAAC,UAAU,CACX;;;;;;;AAQF,SAAgB,wBACf,WACA,OACA,SACkB;AAClB,QAAO,+BAA+B,cAAc,CAAC,MAAM,WAAW,OAAO,QAAQ"}
|
|
@@ -38,3 +38,4 @@ export type TextureUrlInput = string[] | (() => string[]);
|
|
|
38
38
|
* @returns Reactive texture loading state with reload support.
|
|
39
39
|
*/
|
|
40
40
|
export declare function useTexture(urlInput: TextureUrlInput, options?: TextureLoadOptions): UseTextureResult;
|
|
41
|
+
//# sourceMappingURL=use-texture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-texture.d.ts","sourceRoot":"","sources":["../../src/lib/react/use-texture.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,KAAK,eAAe,EACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAGN,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAA0B,KAAK,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE5F;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC;;OAEG;IACH,QAAQ,EAAE,eAAe,CAAC,aAAa,EAAE,GAAG,IAAI,CAAC,CAAC;IAClD;;OAEG;IACH,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC;IAClC;;OAEG;IACH,KAAK,EAAE,eAAe,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IACrC;;OAEG;IACH,WAAW,EAAE,eAAe,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAC;IAC1D;;OAEG;IACH,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,EAAE,GAAG,CAAC,MAAM,MAAM,EAAE,CAAC,CAAC;AAkE1D;;;;;;GAMG;AACH,wBAAgB,UAAU,CACzB,QAAQ,EAAE,eAAe,EACzB,OAAO,GAAE,kBAAuB,GAC9B,gBAAgB,CAkHlB"}
|