UNPKG

@thi.ng/ramp

Version:

Extensible keyframe interpolation/tweening of arbitrary, nested types

52 lines 1.87 kB
import type { Frame, IRamp, IReadonlyRamp, RampBounds, RampDomain, RampOpts } from "./api.js"; export type GroupImpl<T extends Record<string, any>> = { [P in keyof T]: IRamp<T[P]>; }; /** * Creates a new nested ramp from given object of otherwise independent child * ramps (which can be groups themselves). * * @remarks * Similar to {@link nested}, but different in that groups are merely views of * independent timelines, each with their own set of keyframes, interpolation * logic, time domain functions. * * Groups can have their own time domain function (given via `opts`, default: * {@link unconstrained}), which will be applied _prior_ to evaluating any child ramps. * * @example * ```ts tangle:../export/group.ts * import { group, hermite, linear } from "@thi.ng/ramp"; * * const example = group({ * // named, independent child ramps/timelines * a: linear([[0.1, 0], [0.5, -10]]), * b: hermite([[0, 100], [1, 200]]), * }); * * console.log(example.at(0.2)); * // { a: -2.5, b: 110.4 } * * // set new keyframe for `b` ramp * // (in TS need to cast to proper type first) * (<Ramp<number>>example.children.b).setStopAt(0.5, 200); * * console.log(example.at(0.2)); * // { a: -2.5, b: 135.2 } * ``` * * @param children * @param opts */ export declare const group: <T extends Record<string, any>>(children: GroupImpl<T>, opts?: Partial<RampOpts>) => Group<T>; export declare class Group<T extends Record<string, any>> implements IReadonlyRamp<T> { children: GroupImpl<T>; domain: RampDomain; protected childEntries: [keyof T, IReadonlyRamp<any>][]; constructor(children: GroupImpl<T>, opts?: Partial<RampOpts>); at(t: number): T; samples(n?: number, start?: number, end?: number): Iterable<Frame<T>>; bounds(): RampBounds<T>; timeBounds(): [number, number]; } //# sourceMappingURL=group.d.ts.map