@motion-core/motion-gpu 0.4.1 → 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 +1 -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 +1 -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 +1 -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 +1 -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 +1 -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 +1 -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 +1 -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 +96 -13
- 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 +1 -0
- package/dist/svelte/FragCanvas.svelte.d.ts.map +1 -0
- 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 +12 -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/FragCanvas.tsx +345 -0
- package/src/lib/react/MotionGPUErrorOverlay.tsx +392 -0
- package/src/lib/react/Portal.tsx +34 -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
|
@@ -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"}
|
|
@@ -1,162 +1,142 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createCurrentWritable
|
|
3
|
-
import { isAbortError, loadTexturesFromUrls } from
|
|
4
|
-
import {
|
|
1
|
+
import { toMotionGPUErrorReport } from "../core/error-report.js";
|
|
2
|
+
import { createCurrentWritable } from "../core/current-value.js";
|
|
3
|
+
import { isAbortError, loadTexturesFromUrls } from "../core/texture-loader.js";
|
|
4
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
5
|
+
//#region src/lib/react/use-texture.ts
|
|
5
6
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
* Normalizes unknown thrown values to an `Error` instance.
|
|
8
|
+
*/
|
|
8
9
|
function toError(error) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
return new Error('Unknown texture loading error');
|
|
10
|
+
if (error instanceof Error) return error;
|
|
11
|
+
return /* @__PURE__ */ new Error("Unknown texture loading error");
|
|
13
12
|
}
|
|
14
13
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
* Releases GPU-side resources for a list of loaded textures.
|
|
15
|
+
*/
|
|
17
16
|
function disposeTextures(list) {
|
|
18
|
-
|
|
19
|
-
texture.dispose();
|
|
20
|
-
}
|
|
17
|
+
for (const texture of list ?? []) texture.dispose();
|
|
21
18
|
}
|
|
22
19
|
function mergeAbortSignals(primary, secondary) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
primary.addEventListener('abort', abort, { once: true });
|
|
47
|
-
secondary.addEventListener('abort', abort, { once: true });
|
|
48
|
-
return {
|
|
49
|
-
signal: fallback.signal,
|
|
50
|
-
dispose: cleanup
|
|
51
|
-
};
|
|
20
|
+
if (!secondary) return {
|
|
21
|
+
signal: primary,
|
|
22
|
+
dispose: () => {}
|
|
23
|
+
};
|
|
24
|
+
if (typeof AbortSignal.any === "function") return {
|
|
25
|
+
signal: AbortSignal.any([primary, secondary]),
|
|
26
|
+
dispose: () => {}
|
|
27
|
+
};
|
|
28
|
+
const fallback = new AbortController();
|
|
29
|
+
let disposed = false;
|
|
30
|
+
const cleanup = () => {
|
|
31
|
+
if (disposed) return;
|
|
32
|
+
disposed = true;
|
|
33
|
+
primary.removeEventListener("abort", abort);
|
|
34
|
+
secondary.removeEventListener("abort", abort);
|
|
35
|
+
};
|
|
36
|
+
const abort = () => fallback.abort();
|
|
37
|
+
primary.addEventListener("abort", abort, { once: true });
|
|
38
|
+
secondary.addEventListener("abort", abort, { once: true });
|
|
39
|
+
return {
|
|
40
|
+
signal: fallback.signal,
|
|
41
|
+
dispose: cleanup
|
|
42
|
+
};
|
|
52
43
|
}
|
|
53
44
|
/**
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
void load();
|
|
148
|
-
return () => {
|
|
149
|
-
disposedRef.current = true;
|
|
150
|
-
requestVersionRef.current += 1;
|
|
151
|
-
activeControllerRef.current?.abort();
|
|
152
|
-
disposeTextures(texturesRef.current.current);
|
|
153
|
-
};
|
|
154
|
-
}, [load]);
|
|
155
|
-
return {
|
|
156
|
-
textures: texturesRef.current,
|
|
157
|
-
loading: loadingRef.current,
|
|
158
|
-
error: errorRef.current,
|
|
159
|
-
errorReport: errorReportRef.current,
|
|
160
|
-
reload: load
|
|
161
|
-
};
|
|
45
|
+
* Loads textures from URLs and exposes reactive loading/error state.
|
|
46
|
+
*
|
|
47
|
+
* @param urlInput - URLs array or lazy URL provider.
|
|
48
|
+
* @param options - Loader options passed to URL fetch/decode pipeline.
|
|
49
|
+
* @returns Reactive texture loading state with reload support.
|
|
50
|
+
*/
|
|
51
|
+
function useTexture(urlInput, options = {}) {
|
|
52
|
+
const texturesRef = useRef(createCurrentWritable(null));
|
|
53
|
+
const loadingRef = useRef(createCurrentWritable(true));
|
|
54
|
+
const errorRef = useRef(createCurrentWritable(null));
|
|
55
|
+
const errorReportRef = useRef(createCurrentWritable(null));
|
|
56
|
+
const activeControllerRef = useRef(null);
|
|
57
|
+
const runningLoadRef = useRef(null);
|
|
58
|
+
const reloadQueuedRef = useRef(false);
|
|
59
|
+
const requestVersionRef = useRef(0);
|
|
60
|
+
const disposedRef = useRef(false);
|
|
61
|
+
const optionsRef = useRef(options);
|
|
62
|
+
const urlInputRef = useRef(urlInput);
|
|
63
|
+
optionsRef.current = options;
|
|
64
|
+
urlInputRef.current = urlInput;
|
|
65
|
+
const getUrls = useCallback(() => {
|
|
66
|
+
const currentInput = urlInputRef.current;
|
|
67
|
+
return typeof currentInput === "function" ? currentInput() : currentInput;
|
|
68
|
+
}, []);
|
|
69
|
+
const executeLoad = useCallback(async () => {
|
|
70
|
+
if (disposedRef.current) return;
|
|
71
|
+
const version = ++requestVersionRef.current;
|
|
72
|
+
const controller = new AbortController();
|
|
73
|
+
activeControllerRef.current = controller;
|
|
74
|
+
loadingRef.current.set(true);
|
|
75
|
+
errorRef.current.set(null);
|
|
76
|
+
errorReportRef.current.set(null);
|
|
77
|
+
const previous = texturesRef.current.current;
|
|
78
|
+
const mergedSignal = mergeAbortSignals(controller.signal, optionsRef.current.signal);
|
|
79
|
+
try {
|
|
80
|
+
const loaded = await loadTexturesFromUrls(getUrls(), {
|
|
81
|
+
...optionsRef.current,
|
|
82
|
+
signal: mergedSignal.signal
|
|
83
|
+
});
|
|
84
|
+
if (disposedRef.current || version !== requestVersionRef.current) {
|
|
85
|
+
disposeTextures(loaded);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
texturesRef.current.set(loaded);
|
|
89
|
+
disposeTextures(previous);
|
|
90
|
+
} catch (nextError) {
|
|
91
|
+
if (disposedRef.current || version !== requestVersionRef.current) return;
|
|
92
|
+
if (isAbortError(nextError)) return;
|
|
93
|
+
disposeTextures(previous);
|
|
94
|
+
texturesRef.current.set(null);
|
|
95
|
+
const normalizedError = toError(nextError);
|
|
96
|
+
errorRef.current.set(normalizedError);
|
|
97
|
+
errorReportRef.current.set(toMotionGPUErrorReport(normalizedError, "initialization"));
|
|
98
|
+
} finally {
|
|
99
|
+
if (!disposedRef.current && version === requestVersionRef.current) loadingRef.current.set(false);
|
|
100
|
+
if (activeControllerRef.current === controller) activeControllerRef.current = null;
|
|
101
|
+
mergedSignal.dispose();
|
|
102
|
+
}
|
|
103
|
+
}, [getUrls]);
|
|
104
|
+
const runLoadLoop = useCallback(async () => {
|
|
105
|
+
do {
|
|
106
|
+
reloadQueuedRef.current = false;
|
|
107
|
+
await executeLoad();
|
|
108
|
+
} while (reloadQueuedRef.current && !disposedRef.current);
|
|
109
|
+
}, [executeLoad]);
|
|
110
|
+
const load = useCallback(() => {
|
|
111
|
+
activeControllerRef.current?.abort();
|
|
112
|
+
if (runningLoadRef.current) {
|
|
113
|
+
reloadQueuedRef.current = true;
|
|
114
|
+
return runningLoadRef.current;
|
|
115
|
+
}
|
|
116
|
+
const trackedPending = runLoadLoop().finally(() => {
|
|
117
|
+
if (runningLoadRef.current === trackedPending) runningLoadRef.current = null;
|
|
118
|
+
});
|
|
119
|
+
runningLoadRef.current = trackedPending;
|
|
120
|
+
return trackedPending;
|
|
121
|
+
}, [runLoadLoop]);
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
load();
|
|
124
|
+
return () => {
|
|
125
|
+
disposedRef.current = true;
|
|
126
|
+
requestVersionRef.current += 1;
|
|
127
|
+
activeControllerRef.current?.abort();
|
|
128
|
+
disposeTextures(texturesRef.current.current);
|
|
129
|
+
};
|
|
130
|
+
}, [load]);
|
|
131
|
+
return {
|
|
132
|
+
textures: texturesRef.current,
|
|
133
|
+
loading: loadingRef.current,
|
|
134
|
+
error: errorRef.current,
|
|
135
|
+
errorReport: errorReportRef.current,
|
|
136
|
+
reload: load
|
|
137
|
+
};
|
|
162
138
|
}
|
|
139
|
+
//#endregion
|
|
140
|
+
export { useTexture };
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=use-texture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-texture.js","names":[],"sources":["../../src/lib/react/use-texture.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport {\n\tcreateCurrentWritable as currentWritable,\n\ttype CurrentReadable\n} from '../core/current-value.js';\nimport {\n\tisAbortError,\n\tloadTexturesFromUrls,\n\ttype LoadedTexture,\n\ttype TextureLoadOptions\n} from '../core/texture-loader.js';\nimport { toMotionGPUErrorReport, type MotionGPUErrorReport } from '../core/error-report.js';\n\n/**\n * Reactive state returned by `useTexture`.\n */\nexport interface UseTextureResult {\n\t/**\n\t * Loaded textures or `null` when unavailable/failed.\n\t */\n\ttextures: CurrentReadable<LoadedTexture[] | null>;\n\t/**\n\t * `true` while an active load request is running.\n\t */\n\tloading: CurrentReadable<boolean>;\n\t/**\n\t * Last loading error.\n\t */\n\terror: CurrentReadable<Error | null>;\n\t/**\n\t * Last loading error normalized to MotionGPU diagnostics report shape.\n\t */\n\terrorReport: CurrentReadable<MotionGPUErrorReport | null>;\n\t/**\n\t * Reloads all textures using current URL input.\n\t */\n\treload: () => Promise<void>;\n}\n\n/**\n * Supported URL input variants for `useTexture`.\n */\nexport type TextureUrlInput = string[] | (() => string[]);\n\n/**\n * Normalizes unknown thrown values to an `Error` instance.\n */\nfunction toError(error: unknown): Error {\n\tif (error instanceof Error) {\n\t\treturn error;\n\t}\n\n\treturn new Error('Unknown texture loading error');\n}\n\n/**\n * Releases GPU-side resources for a list of loaded textures.\n */\nfunction disposeTextures(list: LoadedTexture[] | null): void {\n\tfor (const texture of list ?? []) {\n\t\ttexture.dispose();\n\t}\n}\n\ninterface MergedAbortSignal {\n\tsignal: AbortSignal;\n\tdispose: () => void;\n}\n\nfunction mergeAbortSignals(\n\tprimary: AbortSignal,\n\tsecondary: AbortSignal | undefined\n): MergedAbortSignal {\n\tif (!secondary) {\n\t\treturn {\n\t\t\tsignal: primary,\n\t\t\tdispose: () => {}\n\t\t};\n\t}\n\n\tif (typeof AbortSignal.any === 'function') {\n\t\treturn {\n\t\t\tsignal: AbortSignal.any([primary, secondary]),\n\t\t\tdispose: () => {}\n\t\t};\n\t}\n\n\tconst fallback = new AbortController();\n\tlet disposed = false;\n\tconst cleanup = (): void => {\n\t\tif (disposed) {\n\t\t\treturn;\n\t\t}\n\t\tdisposed = true;\n\t\tprimary.removeEventListener('abort', abort);\n\t\tsecondary.removeEventListener('abort', abort);\n\t};\n\tconst abort = (): void => fallback.abort();\n\n\tprimary.addEventListener('abort', abort, { once: true });\n\tsecondary.addEventListener('abort', abort, { once: true });\n\n\treturn {\n\t\tsignal: fallback.signal,\n\t\tdispose: cleanup\n\t};\n}\n\n/**\n * Loads textures from URLs and exposes reactive loading/error state.\n *\n * @param urlInput - URLs array or lazy URL provider.\n * @param options - Loader options passed to URL fetch/decode pipeline.\n * @returns Reactive texture loading state with reload support.\n */\nexport function useTexture(\n\turlInput: TextureUrlInput,\n\toptions: TextureLoadOptions = {}\n): UseTextureResult {\n\tconst texturesRef = useRef(currentWritable<LoadedTexture[] | null>(null));\n\tconst loadingRef = useRef(currentWritable(true));\n\tconst errorRef = useRef(currentWritable<Error | null>(null));\n\tconst errorReportRef = useRef(currentWritable<MotionGPUErrorReport | null>(null));\n\tconst activeControllerRef = useRef<AbortController | null>(null);\n\tconst runningLoadRef = useRef<Promise<void> | null>(null);\n\tconst reloadQueuedRef = useRef(false);\n\tconst requestVersionRef = useRef(0);\n\tconst disposedRef = useRef(false);\n\tconst optionsRef = useRef(options);\n\tconst urlInputRef = useRef(urlInput);\n\n\toptionsRef.current = options;\n\turlInputRef.current = urlInput;\n\n\tconst getUrls = useCallback((): string[] => {\n\t\tconst currentInput = urlInputRef.current;\n\t\treturn typeof currentInput === 'function' ? currentInput() : currentInput;\n\t}, []);\n\n\tconst executeLoad = useCallback(async (): Promise<void> => {\n\t\tif (disposedRef.current) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst version = ++requestVersionRef.current;\n\t\tconst controller = new AbortController();\n\t\tactiveControllerRef.current = controller;\n\t\tloadingRef.current.set(true);\n\t\terrorRef.current.set(null);\n\t\terrorReportRef.current.set(null);\n\n\t\tconst previous = texturesRef.current.current;\n\t\tconst mergedSignal = mergeAbortSignals(controller.signal, optionsRef.current.signal);\n\t\ttry {\n\t\t\tconst loaded = await loadTexturesFromUrls(getUrls(), {\n\t\t\t\t...optionsRef.current,\n\t\t\t\tsignal: mergedSignal.signal\n\t\t\t});\n\t\t\tif (disposedRef.current || version !== requestVersionRef.current) {\n\t\t\t\tdisposeTextures(loaded);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\ttexturesRef.current.set(loaded);\n\t\t\tdisposeTextures(previous);\n\t\t} catch (nextError) {\n\t\t\tif (disposedRef.current || version !== requestVersionRef.current) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (isAbortError(nextError)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tdisposeTextures(previous);\n\t\t\ttexturesRef.current.set(null);\n\t\t\tconst normalizedError = toError(nextError);\n\t\t\terrorRef.current.set(normalizedError);\n\t\t\terrorReportRef.current.set(toMotionGPUErrorReport(normalizedError, 'initialization'));\n\t\t} finally {\n\t\t\tif (!disposedRef.current && version === requestVersionRef.current) {\n\t\t\t\tloadingRef.current.set(false);\n\t\t\t}\n\t\t\tif (activeControllerRef.current === controller) {\n\t\t\t\tactiveControllerRef.current = null;\n\t\t\t}\n\t\t\tmergedSignal.dispose();\n\t\t}\n\t}, [getUrls]);\n\n\tconst runLoadLoop = useCallback(async (): Promise<void> => {\n\t\tdo {\n\t\t\treloadQueuedRef.current = false;\n\t\t\tawait executeLoad();\n\t\t} while (reloadQueuedRef.current && !disposedRef.current);\n\t}, [executeLoad]);\n\n\tconst load = useCallback((): Promise<void> => {\n\t\tactiveControllerRef.current?.abort();\n\t\tif (runningLoadRef.current) {\n\t\t\treloadQueuedRef.current = true;\n\t\t\treturn runningLoadRef.current;\n\t\t}\n\n\t\tconst pending = runLoadLoop();\n\t\tconst trackedPending = pending.finally(() => {\n\t\t\tif (runningLoadRef.current === trackedPending) {\n\t\t\t\trunningLoadRef.current = null;\n\t\t\t}\n\t\t});\n\t\trunningLoadRef.current = trackedPending;\n\t\treturn trackedPending;\n\t}, [runLoadLoop]);\n\n\tuseEffect(() => {\n\t\tvoid load();\n\n\t\treturn () => {\n\t\t\tdisposedRef.current = true;\n\t\t\trequestVersionRef.current += 1;\n\t\t\tactiveControllerRef.current?.abort();\n\t\t\tdisposeTextures(texturesRef.current.current);\n\t\t};\n\t}, [load]);\n\n\treturn {\n\t\ttextures: texturesRef.current,\n\t\tloading: loadingRef.current,\n\t\terror: errorRef.current,\n\t\terrorReport: errorReportRef.current,\n\t\treload: load\n\t};\n}\n"],"mappings":";;;;;;;;AA+CA,SAAS,QAAQ,OAAuB;AACvC,KAAI,iBAAiB,MACpB,QAAO;AAGR,wBAAO,IAAI,MAAM,gCAAgC;;;;;AAMlD,SA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Ac,CAAC,EAAE,wBAAwB,CAAC;IAC1C,gBAAgB,CAAC,EAAE,mBAAmB,CAAC;IACvC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,aAAa,CAAC,EAAE,OAAO,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAChD,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACjD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,oBAAoB,EAAE,KAAK,IAAI,CAAC;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAiNF,QAAA,MAAM,UAAU,2CAAwC,CAAC;AACzD,KAAK,UAAU,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;AAChD,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MotionGPUErrorOverlay.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/svelte/MotionGPUErrorOverlay.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAIhE,UAAU,KAAK;IACd,MAAM,EAAE,oBAAoB,CAAC;CAC7B;AAkFF,QAAA,MAAM,qBAAqB,2CAAwC,CAAC;AACpE,KAAK,qBAAqB,GAAG,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACtE,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Portal.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/svelte/Portal.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGrC,UAAU,KAAK;IACd,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AA+BF,QAAA,MAAM,MAAM,2CAAwC,CAAC;AACrD,KAAK,MAAM,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC;AACxC,eAAe,MAAM,CAAC"}
|
|
@@ -9,3 +9,4 @@ export type { MotionGPUUserContext, MotionGPUUserNamespace } from './motiongpu-c
|
|
|
9
9
|
export type { FrameProfilingSnapshot, FrameKey, FrameTaskInvalidation, FrameTaskInvalidationToken, FrameRunTimings, FrameScheduleSnapshot, FrameStage, FrameStageCallback, FrameTimingStats, FrameTask } from '../core/frame-registry.js';
|
|
10
10
|
export type { SetMotionGPUUserContextOptions } from './use-motiongpu-user-context.js';
|
|
11
11
|
export type { RenderPassContext, RenderTarget, UniformLayout, UniformLayoutEntry } from '../core/types.js';
|
|
12
|
+
//# sourceMappingURL=advanced.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/lib/svelte/advanced.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AACnG,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AACnG,YAAY,EACX,2BAA2B,EAC3B,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAC3F,YAAY,EACX,sBAAsB,EACtB,QAAQ,EACR,qBAAqB,EACrB,0BAA0B,EAC1B,eAAe,EACf,qBAAqB,EACrB,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,EACT,MAAM,2BAA2B,CAAC;AACnC,YAAY,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AACtF,YAAY,EACX,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,MAAM,kBAAkB,CAAC"}
|
package/dist/svelte/advanced.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 { applySchedulerPreset, captureSchedulerDebugSnapshot } from "../core/scheduler-helpers.js";
|
|
6
|
+
import { useMotionGPU } from "./motiongpu-context.js";
|
|
7
|
+
import { useFrame } from "./frame-context.js";
|
|
8
|
+
import { useTexture } from "./use-texture.js";
|
|
9
|
+
import { FragCanvas } from "./index.js";
|
|
10
|
+
import { setMotionGPUUserContext, useMotionGPUUserContext } from "./use-motiongpu-user-context.js";
|
|
11
|
+
export { BlitPass, CopyPass, FragCanvas, ShaderPass, applySchedulerPreset, captureSchedulerDebugSnapshot, defineMaterial, setMotionGPUUserContext, useFrame, useMotionGPU, useMotionGPUUserContext, useTexture };
|
|
@@ -12,3 +12,4 @@ export declare function useFrame(callback: FrameCallback, options?: UseFrameOpti
|
|
|
12
12
|
* Registers a frame callback with an explicit task key.
|
|
13
13
|
*/
|
|
14
14
|
export declare function useFrame(key: FrameKey, callback: FrameCallback, options?: UseFrameOptions): UseFrameResult;
|
|
15
|
+
//# sourceMappingURL=frame-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-context.d.ts","sourceRoot":"","sources":["../../src/lib/svelte/frame-context.ts"],"names":[],"mappings":"AACA,OAAO,EACN,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,MAAM,2BAA2B,CAAC;AAOnC,OAAO,EACN,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACb,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,CAElE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC;AAE7F;;GAEG;AACH,wBAAgB,QAAQ,CACvB,GAAG,EAAE,QAAQ,EACb,QAAQ,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC"}
|