Documentation
    Preparing search index...

    Interface ValueAdapter<T>

    How one value type is duplicated, assigned, and interpolated.

    Implementations are stateless singletons, so an adapter can be shared by every binding and track in an application.

    interface ValueAdapter<T> {
        kind: ValueKind;
        mutatesInPlace: boolean;
        add(a: T, b: T, weight: number, out: T): T;
        clone(value: T): T;
        copy(source: T, target: T): T;
        lerp(a: T, b: T, t: number, out: T): T;
    }

    Type Parameters

    • T
    Index
    kind: ValueKind

    Discriminator; also what a diagnostic prints when a binding is dumped.

    mutatesInPlace: boolean

    true when ValueAdapter.copy and ValueAdapter.lerp write through their target/out argument (reference types), false when they ignore it and the result flows purely by return value (primitives and discrete values). See this module's header.

    • Adds b * weight onto a (PH-9 layered / additive animation).

      Continuous kinds are arithmetic: numbers, vectors, and colours compute a + b * weight. Quaternions treat b as a delta from identity and compose a * slerp(identity, b, weight). Step kinds (boolean, discrete) cannot add — they return a and ignore b and weight.

      Same out contract as ValueAdapter.lerp: callers must use the return value; out may alias a and must not alias b for the in-place kinds that write through it.

      Parameters

      • a: T
      • b: T
      • weight: number
      • out: T

      Returns T

    • Returns an independent copy of value — the only allocating method in this module, used at setup (capturing a tween's start value) and never per frame. For mutatesInPlace: false adapters there is nothing to allocate and the value itself is returned.

      Parameters

      • value: T

      Returns T

    • Assigns source to target and returns the effective value: the mutated target for in-place adapters, source itself otherwise. Callers must use the return value.

      Parameters

      • source: T
      • target: T

      Returns T

    • Interpolates from a to b by t and returns the effective value: the mutated out for in-place adapters, the computed value otherwise. Callers must use the return value.

      t is not clamped — values outside [0, 1] extrapolate for the continuous kinds, exactly as @fourjs/math does — and the step kinds hold a for every t < 1. Endpoint exactness at t = 1 is not guaranteed in floating point for the continuous kinds (they compute a + (b - a) * t, matching @fourjs/math); a tween that must land precisely assigns the end value at completion instead of lerping to it.

      Parameters

      • a: T
      • b: T
      • t: number
      • out: T

      Returns T