import type { NodeDef } from '../../NodeRegistry'; import { asNumber } from '../../values'; import { curvesOf, easingOfParams, easingParams, idleEasing } from '../easing'; import { num, withDefault } from '../shared'; import { easedShare } from '../../../model/animation'; import { LERP } from '../../../model/curve'; export const Lerp: NodeDef = { type: LERP, label: 'Lerp', category: 'data', description: 'Blends from a to b as t runs from 0 to 1, along the chosen easing – the same ones an animation ' + 'key offers. t is held in 0…1. Step stays at a until t reaches 1. Back, Elastic and a Curve ' + 'asset may overshoot b.', inputs: [withDefault(num('a'), 0), withDefault(num('b'), 1), withDefault(num('t'), 0)], outputs: [num('result')], params: easingParams(), idleParams: idleEasing, run: (_ctx, inputs, params, _def, _entry, lookup) => { const a = asNumber(inputs.a); const t = Math.min(Math.max(asNumber(inputs.t), 0), 1); const share = easedShare(easingOfParams(params), t, curvesOf(lookup)); return { outputs: { result: a + (asNumber(inputs.b) - a) * share } }; }, };