diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-03-25 16:47:22 +0100 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-03-29 15:48:22 +0200 |
| commit | 8db3bead13441a5882d8689dfc6a9f09c82375d9 (patch) | |
| tree | e9d0cafa93904ffcbec3188c37961bcc16c6422d /apps/web/src/lib/animation/effect-param-channel.ts | |
| parent | 39ea298a9ccba3104c549c0ca079c231981811f5 (diff) | |
| download | opencut-8db3bead13441a5882d8689dfc6a9f09c82375d9.tar.gz | |
feat: masks, properties refactor, shaders, storage migrations, and more
Diffstat (limited to 'apps/web/src/lib/animation/effect-param-channel.ts')
| -rw-r--r-- | apps/web/src/lib/animation/effect-param-channel.ts | 55 |
1 files changed, 47 insertions, 8 deletions
diff --git a/apps/web/src/lib/animation/effect-param-channel.ts b/apps/web/src/lib/animation/effect-param-channel.ts index 07efe4d8..323d9f54 100644 --- a/apps/web/src/lib/animation/effect-param-channel.ts +++ b/apps/web/src/lib/animation/effect-param-channel.ts @@ -1,8 +1,10 @@ -import type { Effect, EffectParamValues } from "@/types/effects"; +import type { ParamValues } from "@/lib/params"; +import type { Effect } from "@/lib/effects/types"; import type { ElementAnimations, + EffectParamPath, NumberAnimationChannel, -} from "@/types/animation"; +} from "@/lib/animation/types"; import { getChannel, removeKeyframe, @@ -11,19 +13,56 @@ import { } from "./keyframes"; import { getChannelValueAtTime } from "./interpolation"; -const EFFECT_PARAM_PATH_PREFIX = "effects."; -const EFFECT_PARAM_PATH_SUFFIX = ".params."; +export const EFFECT_PARAM_PATH_PREFIX = "effects."; +export const EFFECT_PARAM_PATH_SUFFIX = ".params."; -function buildEffectParamPath({ +export function buildEffectParamPath({ effectId, paramKey, }: { effectId: string; paramKey: string; -}): string { +}): EffectParamPath { return `${EFFECT_PARAM_PATH_PREFIX}${effectId}${EFFECT_PARAM_PATH_SUFFIX}${paramKey}`; } +export function isEffectParamPath({ + propertyPath, +}: { + propertyPath: string; +}): propertyPath is EffectParamPath { + return ( + propertyPath.startsWith(EFFECT_PARAM_PATH_PREFIX) && + propertyPath.includes(EFFECT_PARAM_PATH_SUFFIX) + ); +} + +export function parseEffectParamPath({ + propertyPath, +}: { + propertyPath: string; +}): { effectId: string; paramKey: string } | null { + if (!isEffectParamPath({ propertyPath })) { + return null; + } + + const withoutPrefix = propertyPath.slice(EFFECT_PARAM_PATH_PREFIX.length); + const separatorIndex = withoutPrefix.indexOf(EFFECT_PARAM_PATH_SUFFIX); + if (separatorIndex <= 0) { + return null; + } + + const effectId = withoutPrefix.slice(0, separatorIndex); + const paramKey = withoutPrefix.slice( + separatorIndex + EFFECT_PARAM_PATH_SUFFIX.length, + ); + if (!effectId || !paramKey) { + return null; + } + + return { effectId, paramKey }; +} + export function resolveEffectParamsAtTime({ effect, animations, @@ -32,8 +71,8 @@ export function resolveEffectParamsAtTime({ effect: Effect; animations: ElementAnimations | undefined; localTime: number; -}): EffectParamValues { - const resolved: EffectParamValues = {}; +}): ParamValues { + const resolved: ParamValues = {}; for (const [paramKey, staticValue] of Object.entries(effect.params)) { const path = buildEffectParamPath({ effectId: effect.id, paramKey }); |
