@motion-core/motion-gpu 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -34
- package/dist/motion-gpu.css +295 -0
- package/dist/vue/FragCanvas.js +8 -0
- package/dist/vue/FragCanvas.js.map +1 -0
- package/dist/vue/FragCanvas.vue.d.ts +49 -0
- package/dist/vue/FragCanvas.vue.d.ts.map +1 -0
- package/dist/vue/FragCanvas.vue_vue_type_script_setup_true_lang.js +228 -0
- package/dist/vue/FragCanvas.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/vue/MotionGPUErrorOverlay.js +8 -0
- package/dist/vue/MotionGPUErrorOverlay.js.map +1 -0
- package/dist/vue/MotionGPUErrorOverlay.vue.d.ts +8 -0
- package/dist/vue/MotionGPUErrorOverlay.vue.d.ts.map +1 -0
- package/dist/vue/MotionGPUErrorOverlay.vue_vue_type_script_setup_true_lang.js +166 -0
- package/dist/vue/MotionGPUErrorOverlay.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/vue/Portal.js +7 -0
- package/dist/vue/Portal.js.map +1 -0
- package/dist/vue/Portal.vue.d.ts +18 -0
- package/dist/vue/Portal.vue.d.ts.map +1 -0
- package/dist/vue/Portal.vue_vue_type_script_setup_true_lang.js +29 -0
- package/dist/vue/Portal.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/vue/advanced.d.ts +12 -0
- package/dist/vue/advanced.d.ts.map +1 -0
- package/dist/vue/advanced.js +15 -0
- package/dist/vue/frame-context.d.ts +22 -0
- package/dist/vue/frame-context.d.ts.map +1 -0
- package/dist/vue/frame-context.js +38 -0
- package/dist/vue/frame-context.js.map +1 -0
- package/dist/vue/index.d.ts +21 -0
- package/dist/vue/index.d.ts.map +1 -0
- package/dist/vue/index.js +14 -0
- package/dist/vue/motiongpu-context.d.ts +81 -0
- package/dist/vue/motiongpu-context.d.ts.map +1 -0
- package/dist/vue/motiongpu-context.js +29 -0
- package/dist/vue/motiongpu-context.js.map +1 -0
- package/dist/vue/shims-vue.d.js +0 -0
- package/dist/vue/use-motiongpu-user-context.d.ts +44 -0
- package/dist/vue/use-motiongpu-user-context.d.ts.map +1 -0
- package/dist/vue/use-motiongpu-user-context.js +76 -0
- package/dist/vue/use-motiongpu-user-context.js.map +1 -0
- package/dist/vue/use-pointer.d.ts +94 -0
- package/dist/vue/use-pointer.d.ts.map +1 -0
- package/dist/vue/use-pointer.js +298 -0
- package/dist/vue/use-pointer.js.map +1 -0
- package/dist/vue/use-texture.d.ts +45 -0
- package/dist/vue/use-texture.d.ts.map +1 -0
- package/dist/vue/use-texture.js +135 -0
- package/dist/vue/use-texture.js.map +1 -0
- package/package.json +25 -7
- package/src/lib/vue/FragCanvas.vue +294 -0
- package/src/lib/vue/MotionGPUErrorOverlay.vue +518 -0
- package/src/lib/vue/Portal.vue +46 -0
- package/src/lib/vue/advanced.ts +32 -0
- package/src/lib/vue/frame-context.ts +96 -0
- package/src/lib/vue/index.ts +78 -0
- package/src/lib/vue/motiongpu-context.ts +97 -0
- package/src/lib/vue/shims-vue.d.ts +6 -0
- package/src/lib/vue/use-motiongpu-user-context.ts +145 -0
- package/src/lib/vue/use-pointer.ts +514 -0
- package/src/lib/vue/use-texture.ts +232 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue adapter entrypoint for MotionGPU.
|
|
3
|
+
*/
|
|
4
|
+
export { default as FragCanvas } from './FragCanvas.vue';
|
|
5
|
+
export { defineMaterial } from '../core/material.js';
|
|
6
|
+
export {
|
|
7
|
+
BlitPass,
|
|
8
|
+
CopyPass,
|
|
9
|
+
ShaderPass,
|
|
10
|
+
ComputePass,
|
|
11
|
+
PingPongComputePass
|
|
12
|
+
} from '../passes/index.js';
|
|
13
|
+
export { useMotionGPU } from './motiongpu-context.js';
|
|
14
|
+
export { useFrame } from './frame-context.js';
|
|
15
|
+
export { usePointer } from './use-pointer.js';
|
|
16
|
+
export { useTexture } from './use-texture.js';
|
|
17
|
+
export type {
|
|
18
|
+
FrameInvalidationToken,
|
|
19
|
+
FrameState,
|
|
20
|
+
OutputColorSpace,
|
|
21
|
+
AnyPass,
|
|
22
|
+
ComputePassLike,
|
|
23
|
+
RenderPass,
|
|
24
|
+
RenderPassContext,
|
|
25
|
+
RenderPassFlags,
|
|
26
|
+
RenderPassInputSlot,
|
|
27
|
+
RenderPassOutputSlot,
|
|
28
|
+
RenderMode,
|
|
29
|
+
RenderTarget,
|
|
30
|
+
RenderTargetDefinition,
|
|
31
|
+
RenderTargetDefinitionMap,
|
|
32
|
+
TextureData,
|
|
33
|
+
TextureDefinition,
|
|
34
|
+
TextureDefinitionMap,
|
|
35
|
+
TextureUpdateMode,
|
|
36
|
+
TextureMap,
|
|
37
|
+
TextureSource,
|
|
38
|
+
TextureValue,
|
|
39
|
+
TypedUniform,
|
|
40
|
+
UniformMat4Value,
|
|
41
|
+
UniformMap,
|
|
42
|
+
UniformType,
|
|
43
|
+
UniformValue
|
|
44
|
+
} from '../core/types.js';
|
|
45
|
+
export type {
|
|
46
|
+
LoadedTexture,
|
|
47
|
+
TextureDecodeOptions,
|
|
48
|
+
TextureLoadOptions
|
|
49
|
+
} from '../core/texture-loader.js';
|
|
50
|
+
export type {
|
|
51
|
+
FragMaterial,
|
|
52
|
+
FragMaterialInput,
|
|
53
|
+
MaterialIncludes,
|
|
54
|
+
MaterialDefineValue,
|
|
55
|
+
MaterialDefines,
|
|
56
|
+
TypedMaterialDefineValue
|
|
57
|
+
} from '../core/material.js';
|
|
58
|
+
export type { MotionGPUContext } from './motiongpu-context.js';
|
|
59
|
+
export type { UseFrameOptions, UseFrameResult } from './frame-context.js';
|
|
60
|
+
export type {
|
|
61
|
+
PointerClick,
|
|
62
|
+
PointerFrameRequestMode,
|
|
63
|
+
PointerKind,
|
|
64
|
+
PointerPoint,
|
|
65
|
+
PointerState,
|
|
66
|
+
UsePointerOptions,
|
|
67
|
+
UsePointerResult
|
|
68
|
+
} from './use-pointer.js';
|
|
69
|
+
export type { TextureUrlInput, UseTextureResult } from './use-texture.js';
|
|
70
|
+
export type {
|
|
71
|
+
StorageBufferAccess,
|
|
72
|
+
StorageBufferDefinition,
|
|
73
|
+
StorageBufferDefinitionMap,
|
|
74
|
+
StorageBufferType,
|
|
75
|
+
ComputePassContext
|
|
76
|
+
} from '../core/types.js';
|
|
77
|
+
export type { ComputePassOptions, ComputeDispatchContext } from '../passes/ComputePass.js';
|
|
78
|
+
export type { PingPongComputePassOptions } from '../passes/PingPongComputePass.js';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { inject, provide, type InjectionKey } from 'vue';
|
|
2
|
+
import type { RenderMode } from '../core/types.js';
|
|
3
|
+
import type { CurrentReadable, CurrentWritable } from '../core/current-value.js';
|
|
4
|
+
import type {
|
|
5
|
+
FrameProfilingSnapshot,
|
|
6
|
+
FrameRunTimings,
|
|
7
|
+
FrameScheduleSnapshot
|
|
8
|
+
} from '../core/frame-registry.js';
|
|
9
|
+
import type { MotionGPUScheduler as CoreMotionGPUScheduler } from '../core/scheduler-helpers.js';
|
|
10
|
+
|
|
11
|
+
export type MotionGPUScheduler = CoreMotionGPUScheduler;
|
|
12
|
+
export type { FrameProfilingSnapshot, FrameRunTimings, FrameScheduleSnapshot };
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Namespace identifier for user-owned context entries.
|
|
16
|
+
*/
|
|
17
|
+
export type MotionGPUUserNamespace = string | symbol;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Shared user context store exposed by `FragCanvas`.
|
|
21
|
+
*/
|
|
22
|
+
export type MotionGPUUserContext = CurrentWritable<Record<MotionGPUUserNamespace, unknown>>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Public `FragCanvas` runtime context available to composables and user components.
|
|
26
|
+
*/
|
|
27
|
+
export interface MotionGPUContext {
|
|
28
|
+
/**
|
|
29
|
+
* Underlying canvas element used by the renderer.
|
|
30
|
+
*/
|
|
31
|
+
canvas: HTMLCanvasElement | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Reactive canvas pixel size.
|
|
34
|
+
*/
|
|
35
|
+
size: CurrentReadable<{ width: number; height: number }>;
|
|
36
|
+
/**
|
|
37
|
+
* Device pixel ratio multiplier.
|
|
38
|
+
*/
|
|
39
|
+
dpr: CurrentWritable<number>;
|
|
40
|
+
/**
|
|
41
|
+
* Max frame delta clamp passed to scheduled callbacks.
|
|
42
|
+
*/
|
|
43
|
+
maxDelta: CurrentWritable<number>;
|
|
44
|
+
/**
|
|
45
|
+
* Scheduler render mode (`always`, `on-demand`, `manual`).
|
|
46
|
+
*/
|
|
47
|
+
renderMode: CurrentWritable<RenderMode>;
|
|
48
|
+
/**
|
|
49
|
+
* Global toggle for automatic rendering.
|
|
50
|
+
*/
|
|
51
|
+
autoRender: CurrentWritable<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Namespaced user context store shared within the canvas subtree.
|
|
54
|
+
*/
|
|
55
|
+
user: MotionGPUUserContext;
|
|
56
|
+
/**
|
|
57
|
+
* Marks current frame as invalidated.
|
|
58
|
+
*/
|
|
59
|
+
invalidate: () => void;
|
|
60
|
+
/**
|
|
61
|
+
* Requests one manual frame advance.
|
|
62
|
+
*/
|
|
63
|
+
advance: () => void;
|
|
64
|
+
/**
|
|
65
|
+
* Public scheduler API.
|
|
66
|
+
*/
|
|
67
|
+
scheduler: MotionGPUScheduler;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Vue injection key used to expose `FragCanvas` runtime state.
|
|
72
|
+
*/
|
|
73
|
+
export const motionGPUContextKey: InjectionKey<MotionGPUContext> = Symbol('motiongpu.context');
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Registers the motiongpu context in the current Vue component tree.
|
|
77
|
+
*
|
|
78
|
+
* @param context - Context payload to provide.
|
|
79
|
+
*/
|
|
80
|
+
export function provideMotionGPUContext(context: MotionGPUContext): void {
|
|
81
|
+
provide(motionGPUContextKey, context);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Returns the active motiongpu context.
|
|
86
|
+
*
|
|
87
|
+
* @returns Active context.
|
|
88
|
+
* @throws {Error} When called outside `<FragCanvas>`.
|
|
89
|
+
*/
|
|
90
|
+
export function useMotionGPU(): MotionGPUContext {
|
|
91
|
+
const context = inject(motionGPUContextKey, null);
|
|
92
|
+
if (!context) {
|
|
93
|
+
throw new Error('useMotionGPU must be used inside <FragCanvas>');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return context;
|
|
97
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { CurrentReadable } from '../core/current-value.js';
|
|
2
|
+
import { useMotionGPU, type MotionGPUUserNamespace } from './motiongpu-context.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Internal shape of the user context store.
|
|
6
|
+
*/
|
|
7
|
+
type UserContextStore = Record<MotionGPUUserNamespace, unknown>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Object-like context payload used by merge semantics.
|
|
11
|
+
*/
|
|
12
|
+
type UserContextEntry = Record<string, unknown>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Controls how a namespaced user context value behaves when already present.
|
|
16
|
+
*/
|
|
17
|
+
export interface SetMotionGPUUserContextOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Conflict strategy when namespace already exists:
|
|
20
|
+
* - `skip`: keep current value
|
|
21
|
+
* - `replace`: replace current value
|
|
22
|
+
* - `merge`: shallow merge object values, fallback to replace otherwise
|
|
23
|
+
*
|
|
24
|
+
* @default 'skip'
|
|
25
|
+
*/
|
|
26
|
+
existing?: 'merge' | 'replace' | 'skip';
|
|
27
|
+
/**
|
|
28
|
+
* How function inputs should be interpreted:
|
|
29
|
+
* - `factory`: call function and store its return value
|
|
30
|
+
* - `value`: store function itself
|
|
31
|
+
*
|
|
32
|
+
* @default 'factory'
|
|
33
|
+
*/
|
|
34
|
+
functionValue?: 'factory' | 'value';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Checks whether a value is a non-array object suitable for shallow merge.
|
|
39
|
+
*/
|
|
40
|
+
function isObjectEntry(value: unknown): value is UserContextEntry {
|
|
41
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Returns a read-only view of the entire motiongpu user context store.
|
|
46
|
+
*/
|
|
47
|
+
export function useMotionGPUUserContext<
|
|
48
|
+
UC extends UserContextStore = UserContextStore
|
|
49
|
+
>(): CurrentReadable<UC>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Reads a namespaced user context value as a reactive readable store.
|
|
53
|
+
*/
|
|
54
|
+
export function useMotionGPUUserContext<
|
|
55
|
+
UC extends UserContextStore = UserContextStore,
|
|
56
|
+
K extends keyof UC & MotionGPUUserNamespace = keyof UC & MotionGPUUserNamespace
|
|
57
|
+
>(namespace: K): CurrentReadable<UC[K] | undefined>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Read-only user context composable:
|
|
61
|
+
* - no args: returns full user context store
|
|
62
|
+
* - namespace: returns namespaced store view
|
|
63
|
+
*
|
|
64
|
+
* @param namespace - Optional namespace key.
|
|
65
|
+
*/
|
|
66
|
+
export function useMotionGPUUserContext<
|
|
67
|
+
UC extends UserContextStore = UserContextStore,
|
|
68
|
+
K extends keyof UC & MotionGPUUserNamespace = keyof UC & MotionGPUUserNamespace
|
|
69
|
+
>(namespace?: K): CurrentReadable<UC> | CurrentReadable<UC[K] | undefined> {
|
|
70
|
+
const userStore = useMotionGPU().user;
|
|
71
|
+
|
|
72
|
+
if (namespace === undefined) {
|
|
73
|
+
const allStore: CurrentReadable<UC> = {
|
|
74
|
+
get current() {
|
|
75
|
+
return userStore.current as UC;
|
|
76
|
+
},
|
|
77
|
+
subscribe(run) {
|
|
78
|
+
return userStore.subscribe((context) => run(context as UC));
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return allStore;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const scopedStore: CurrentReadable<UC[K] | undefined> = {
|
|
86
|
+
get current() {
|
|
87
|
+
return userStore.current[namespace] as UC[K] | undefined;
|
|
88
|
+
},
|
|
89
|
+
subscribe(run) {
|
|
90
|
+
return userStore.subscribe((context) => run(context[namespace] as UC[K] | undefined));
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return scopedStore;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Sets a namespaced user context value with explicit write semantics.
|
|
99
|
+
*
|
|
100
|
+
* Returns the effective value stored under the namespace.
|
|
101
|
+
*/
|
|
102
|
+
export function setMotionGPUUserContext<UCT = unknown>(
|
|
103
|
+
namespace: MotionGPUUserNamespace,
|
|
104
|
+
value: UCT | (() => UCT),
|
|
105
|
+
options?: SetMotionGPUUserContextOptions
|
|
106
|
+
): UCT | undefined {
|
|
107
|
+
const userStore = useMotionGPU().user;
|
|
108
|
+
const mode = options?.existing ?? 'skip';
|
|
109
|
+
const functionValueMode = options?.functionValue ?? 'factory';
|
|
110
|
+
let resolvedValue: UCT | undefined;
|
|
111
|
+
|
|
112
|
+
userStore.update((context) => {
|
|
113
|
+
const hasExisting = namespace in context;
|
|
114
|
+
if (hasExisting && mode === 'skip') {
|
|
115
|
+
resolvedValue = context[namespace] as UCT | undefined;
|
|
116
|
+
return context;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const nextValue =
|
|
120
|
+
typeof value === 'function' && functionValueMode === 'factory'
|
|
121
|
+
? (value as () => UCT)()
|
|
122
|
+
: (value as UCT);
|
|
123
|
+
if (hasExisting && mode === 'merge') {
|
|
124
|
+
const currentValue = context[namespace];
|
|
125
|
+
if (isObjectEntry(currentValue) && isObjectEntry(nextValue)) {
|
|
126
|
+
resolvedValue = {
|
|
127
|
+
...currentValue,
|
|
128
|
+
...nextValue
|
|
129
|
+
} as UCT;
|
|
130
|
+
return {
|
|
131
|
+
...context,
|
|
132
|
+
[namespace]: resolvedValue
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
resolvedValue = nextValue;
|
|
138
|
+
return {
|
|
139
|
+
...context,
|
|
140
|
+
[namespace]: nextValue
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return resolvedValue;
|
|
145
|
+
}
|