@motion-core/motion-gpu
Version:
Framework-agnostic WebGPU runtime for fullscreen WGSL shaders with explicit Svelte, React, and Vue adapter entrypoints.
61 lines (60 loc) • 1.69 kB
JavaScript
//#region src/lib/core/motiongpu-context.ts
function createMotionGPUUserContextReadable(userStore, namespace) {
if (namespace === void 0) return {
get current() {
return userStore.current;
},
subscribe(run) {
return userStore.subscribe((context) => run(context));
}
};
return {
get current() {
return userStore.current[namespace];
},
subscribe(run) {
return userStore.subscribe((context) => run(context[namespace]));
}
};
}
function isObjectEntry(value) {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
/**
* Applies the shared skip, merge and replace semantics to a user context store.
*/
function setMotionGPUUserContextValue(userStore, namespace, value, options) {
const mode = options?.existing ?? "skip";
const functionValueMode = options?.functionValue ?? "factory";
let resolvedValue;
userStore.update((context) => {
const hasExisting = namespace in context;
if (hasExisting && mode === "skip") {
resolvedValue = context[namespace];
return context;
}
const nextValue = typeof value === "function" && functionValueMode === "factory" ? value() : value;
if (hasExisting && mode === "merge") {
const currentValue = context[namespace];
if (isObjectEntry(currentValue) && isObjectEntry(nextValue)) {
resolvedValue = {
...currentValue,
...nextValue
};
return {
...context,
[namespace]: resolvedValue
};
}
}
resolvedValue = nextValue;
return {
...context,
[namespace]: nextValue
};
});
return resolvedValue;
}
//#endregion
export { createMotionGPUUserContextReadable, setMotionGPUUserContextValue };
//# sourceMappingURL=motiongpu-context.js.map