From 8db3bead13441a5882d8689dfc6a9f09c82375d9 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Wed, 25 Mar 2026 16:47:22 +0100 Subject: feat: masks, properties refactor, shaders, storage migrations, and more --- apps/web/src/lib/animation/interpolation.ts | 71 +++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 15 deletions(-) (limited to 'apps/web/src/lib/animation/interpolation.ts') diff --git a/apps/web/src/lib/animation/interpolation.ts b/apps/web/src/lib/animation/interpolation.ts index 7a6fc6cf..c5b9ea80 100644 --- a/apps/web/src/lib/animation/interpolation.ts +++ b/apps/web/src/lib/animation/interpolation.ts @@ -5,7 +5,10 @@ import type { DiscreteValue, DiscreteAnimationChannel, NumberAnimationChannel, -} from "@/types/animation"; + VectorAnimationChannel, + VectorValue, +} from "@/lib/animation/types"; +import { isVectorValue } from "./vector-channel"; import { TIME_EPSILON_SECONDS } from "@/constants/animation-constants"; function byTimeAscending({ @@ -59,12 +62,7 @@ function parseHexColor({ const green = parseHexChannel({ hex: `${greenHex}${greenHex}` }); const blue = parseHexChannel({ hex: `${blueHex}${blueHex}` }); const alpha = parseHexChannel({ hex: `${alphaHex}${alphaHex}` }); - if ( - red === null || - green === null || - blue === null || - alpha === null - ) { + if (red === null || green === null || blue === null || alpha === null) { return null; } @@ -77,12 +75,7 @@ function parseHexColor({ const blue = parseHexChannel({ hex: rawHex.slice(4, 6) }); const alphaHex = rawHex.length === 8 ? rawHex.slice(6, 8) : "ff"; const alpha = parseHexChannel({ hex: alphaHex }); - if ( - red === null || - green === null || - blue === null || - alpha === null - ) { + if (red === null || green === null || blue === null || alpha === null) { return null; } @@ -177,7 +170,10 @@ export function normalizeChannel({ } as TChannel; } -function evaluateChannelValueAtTime({ +function evaluateChannelValueAtTime< + TKeyframe extends { time: number; value: TValue }, + TValue, +>({ keyframes, time, fallbackValue, @@ -214,7 +210,11 @@ function evaluateChannelValueAtTime { + if (leftKeyframe.interpolation === "hold") { + return leftKeyframe.value; + } + + return { + x: + leftKeyframe.value.x + + (rightKeyframe.value.x - leftKeyframe.value.x) * progress, + y: + leftKeyframe.value.y + + (rightKeyframe.value.y - leftKeyframe.value.y) * progress, + }; + }, + }); +} + function getDiscreteValueAtTime({ channel, time, @@ -358,6 +388,17 @@ export function getChannelValueAtTime({ }); } + if (channel.valueKind === "vector") { + if (!isVectorValue(fallbackValue)) { + return fallbackValue; + } + return getVectorChannelValueAtTime({ + channel, + time, + fallbackValue: fallbackValue as VectorValue, + }); + } + if (typeof fallbackValue !== "string" && typeof fallbackValue !== "boolean") { return fallbackValue; } -- cgit v1.3.1