Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @okikio/animate

Index

Classes

Interfaces

Type aliases

Variables

Functions

Type aliases

TypeAnimationEvents

TypeAnimationEvents: "update" | "play" | "pause" | "begin" | "cancel" | "finish" | "error" | "stop" | "playstate-change"

TypeAnimationOptionTypes

TypeAnimationOptionTypes: TypeCallback | TypeComputedAnimationOptions

TypeAnimationTarget

TypeAnimationTarget: string | Node | NodeList | HTMLCollection | HTMLElement[] | TypeAnimationTarget[]

TypeCSSLikeKeyframe

TypeCSSLikeKeyframe: {}

Type declaration

TypeCSSPropertyValue

TypeCSSPropertyValue: (string | number)[]

TypeCallback

TypeCallback: (index?: number, total?: number, element?: HTMLElement) => TypeComputedAnimationOptions

Type declaration

TypeCallbackArgs

TypeCallbackArgs: [number, number, HTMLElement]

TypeColor

TypeColor: string | number | (string | number)[]

TypeComputedAnimationOptions

TypeComputedAnimationOptions: TypeGeneric | TypeGeneric[] | TypeKeyFrameOptionsType | KeyframeEffectOptions | ICSSComputedTransformableProperties

TypeComputedOptions

TypeComputedOptions: {}

Type declaration

TypeCustomEasingOptions

TypeCustomEasingOptions: { decimal?: number; duration?: number; easing?: string | TypeEasingFunction; numPoints?: number }

Custom Easing has 3 properties they are easing (all the easings from #easing are supported on top of custom easing functions, like spring, bounce, etc...), numPoints (the size of the Array the Custom Easing function should create), and decimal (the number of decimal places of the values within said Array).

Properties Default Value
easing spring(1, 100, 10, 0)
numPoints 50
decimal 3

Type declaration

  • Optional decimal?: number
  • Optional duration?: number
  • Optional easing?: string | TypeEasingFunction

    By default, Custom Easing support easing functions, in the form,

    constant accelerate decelerate accelerate-decelerate decelerate-accelerate
    linear ease-in / in ease-out / out ease-in-out / in-out ease-out-in / out-in
    ease in-sine out-sine in-out-sine out-in-sine
    steps in-quad out-quad in-out-quad out-in-quad
    step-start in-cubic out-cubic in-out-cubic out-in-cubic
    step-end in-quart out-quart in-out-quart out-in-quart
    in-quint out-quint in-out-quint out-in-quint
    in-expo out-expo in-out-expo out-in-expo
    in-circ out-circ in-out-circ out-in-circ
    in-back out-back in-out-back out-in-back
    in-bounce out-bounce in-out-bounce out-in-bounce
    in-elastic out-elastic in-out-elastic out-in-elastic
    spring / spring-in spring-out spring-in-out spring-out-in

    All Elastic easing's can be configured using theses parameters,

    *-elastic(amplitude, period)

    Each parameter comes with these defaults

    Parameter Default Value
    amplitude 1
    period 0.5

    All Spring easing's can be configured using theses parameters,

    spring-*(mass, stiffness, damping, velocity)

    Each parameter comes with these defaults

    Parameter Default Value
    mass 1
    stiffness 100
    damping 10
    velocity 0

    You can create your own custom cubic-bezier easing curves. Similar to css you type cubic-bezier(...) with 4 numbers representing the shape of the bezier curve, for example, cubic-bezier(0.47, 0, 0.745, 0.715) this is the bezier curve for in-sine.

    Note: the easing property supports the original values and functions for easing as well, for example, steps(1), and etc... are supported.

    Note: you can also use camelCase when defining easing functions, e.g. inOutCubic to represent in-out-cubic

  • Optional numPoints?: number

TypeEasingFunction

TypeEasingFunction: (t: number, params?: (string | number)[], duration?: number) => number

Type declaration

    • (t: number, params?: (string | number)[], duration?: number): number
    • The format to use when defining custom easing functions

      Parameters

      • t: number
      • Optional params: (string | number)[]
      • Optional duration: number

      Returns number

TypeGeneric

TypeGeneric: boolean | object | string | number

TypeKeyFrameOptionsType

TypeKeyFrameOptionsType: TypeCSSLikeKeyframe | Keyframe[] | PropertyIndexedKeyframes

TypePlayStates

TypePlayStates: "idle" | "running" | "paused" | "finished"

TypeRGBAFunction

TypeRGBAFunction: (color: TypeColor) => number[]

Type declaration

TypeSingleValueCSSProperty

TypeSingleValueCSSProperty: string | number | TypeCSSPropertyValue

Variables

Const ALL_TIMING_KEYS

ALL_TIMING_KEYS: string[] = ...

Const CSSPXDataType

CSSPXDataType: string = ...

Common CSS Property names with the units "px" as an acceptable value

Const DefaultAnimationOptions

DefaultAnimationOptions: IAnimationOptions = ...

The default options for every Animate instance

{
  keyframes: [],

  loop: 1,
  delay: 0,
  speed: 1,
  endDelay: 0,
  easing: "ease",
  autoplay: true,
  duration: 1000,
  fillMode: "none",
  direction: "normal",
  padEndDelay: false,
  timeline: document.timeline,
  extend: {}
}

Const EASINGS

EASINGS: { in: string; in-back: string; in-circ: string; in-cubic: string; in-expo: string; in-out: string; in-out-back: string; in-out-circ: string; in-out-cubic: string; in-out-expo: string; in-out-quad: string; in-out-quart: string; in-out-quint: string; in-out-sine: string; in-quad: string; in-quart: string; in-quint: string; in-sine: string; out: string; out-back: string; out-circ: string; out-cubic: string; out-expo: string; out-quad: string; out-quart: string; out-quint: string; out-sine: string } = ...

Read More about easings on MDN

{
    "in": "ease-in",
    "out": "ease-out",
    "in-out": "ease-in-out",

    // Sine
    "in-sine": "cubic-bezier(0.47, 0, 0.745, 0.715)",
    "out-sine": "cubic-bezier(0.39, 0.575, 0.565, 1)",
    "in-out-sine": "cubic-bezier(0.445, 0.05, 0.55, 0.95)",

    // Quad
    "in-quad": "cubic-bezier(0.55, 0.085, 0.68, 0.53)",
    "out-quad": "cubic-bezier(0.25, 0.46, 0.45, 0.94)",
    "in-out-quad": "cubic-bezier(0.455, 0.03, 0.515, 0.955)",

    // Cubic
    "in-cubic": "cubic-bezier(0.55, 0.055, 0.675, 0.19)",
    "out-cubic": "cubic-bezier(0.215, 0.61, 0.355, 1)",
    "in-out-cubic": "cubic-bezier(0.645, 0.045, 0.355, 1)",

    // Quart
    "in-quart": "cubic-bezier(0.895, 0.03, 0.685, 0.22)",
    "out-quart": "cubic-bezier(0.165, 0.84, 0.44, 1)",
    "in-out-quart": "cubic-bezier(0.77, 0, 0.175, 1)",

    // Quint
    "in-quint": "cubic-bezier(0.755, 0.05, 0.855, 0.06)",
    "out-quint": "cubic-bezier(0.23, 1, 0.32, 1)",
    "in-out-quint": "cubic-bezier(0.86, 0, 0.07, 1)",

    // Expo
    "in-expo": "cubic-bezier(0.95, 0.05, 0.795, 0.035)",
    "out-expo": "cubic-bezier(0.19, 1, 0.22, 1)",
    "in-out-expo": "cubic-bezier(1, 0, 0, 1)",

    // Circ
    "in-circ": "cubic-bezier(0.6, 0.04, 0.98, 0.335)",
    "out-circ": "cubic-bezier(0.075, 0.82, 0.165, 1)",
    "in-out-circ": "cubic-bezier(0.785, 0.135, 0.15, 0.86)",

    // Back
    "in-back": "cubic-bezier(0.6, -0.28, 0.735, 0.045)",
    "out-back": "cubic-bezier(0.175, 0.885, 0.32, 1.275)",
    "in-out-back": "cubic-bezier(0.68, -0.55, 0.265, 1.55)"
}

Type declaration

  • in: string
  • in-back: string
  • in-circ: string
  • in-cubic: string
  • in-expo: string
  • in-out: string
  • in-out-back: string
  • in-out-circ: string
  • in-out-cubic: string
  • in-out-expo: string
  • in-out-quad: string
  • in-out-quart: string
  • in-out-quint: string
  • in-out-sine: string
  • in-quad: string
  • in-quart: string
  • in-quint: string
  • in-sine: string
  • out: string
  • out-back: string
  • out-circ: string
  • out-cubic: string
  • out-expo: string
  • out-quad: string
  • out-quart: string
  • out-quint: string
  • out-sine: string

Const EFFECTS

EFFECTS: {} = {}

I don't really want to put in the effort to create a complete list, so instead just look through the animate.css github and copy and paste the effects you need, into using a CSS Keyframe style JSON object, make sure to read the documentation for KeyframeParse

I suggest @shoelace-style/animations for all your animate.css needs.

or

if you just need some quick effects go to github.com/wellyshen/use-web-animations/ and copy the keyframes array for the effect you want, remember to say thank you to @wellyshen for all his hardwork, 😂.

internal

Type declaration

Const EasingDurationCache

EasingDurationCache: Map<string | TypeEasingFunction, number> = ...

Cache the durations at set easing parameters

Let EasingFunctionKeys

EasingFunctionKeys: string[] = ...

Const EasingFunctions

EasingFunctions: {} = ...

The default list of easing functions, do note this is different from {@link EASING}

Type declaration

Const EasingKeys

EasingKeys: string[] = ...

The keys of EASINGS

remark

"in", "out", "in-out", "in-sine", "out-sine", "in-out-sine", "in-quad", "out-quad", "in-out-quad", "in-cubic", "out-cubic", "in-out-cubic", "in-quart", "out-quart", "in-out-quart", "in-quint", "out-quint", "in-out-quint", "in-expo", "out-expo", "in-out-expo", "in-circ", "out-circ", "in-out-circ", "in-back", "out-back", "in-out-back"

Const FUNCTION_SUPPORTED_TIMING_KEYS

FUNCTION_SUPPORTED_TIMING_KEYS: string[] = ...

Const INTINITE_LOOP_LIMIT

INTINITE_LOOP_LIMIT: 10000 = 10000

The threshold for an infinite loop

Const NOT_FUNCTION_SUPPORTED_TIMING_KEYS

NOT_FUNCTION_SUPPORTED_TIMING_KEYS: string[] = ...

Const TransformFunctionNames

TransformFunctionNames: string[] = ...

Store all the supported transform functions as an Array

Const TransformFunctions

TransformFunctions: ITransformFunctions = ...

Details how to compute each transform function

Const TweenCache

TweenCache: Map<any, any> = ...

Cache calculated tween points for commonly used easing functions

Let UIDCount

UIDCount: number = 0

Keeps track of all the empty tween elements

Functions

Const ApplyCustomEasing

  • Applies the same custom easings to all properties of the object and returns an object with each property having an array of custom eased values

    If you use the spring or spring-in easings it will also return the optimal duration as a key in the object it returns. If you set duration to a number, it will prioritize that duration over optimal duration given by the spring easings.

    Read more about CustomEasing

    e.g.

    import { animate, ApplyCustomEasing } from "@okikio/animate";
    animate({
         target: "div",
    
         ...ApplyCustomEasing({
           border: ["1px solid red", "3 dashed green", "2 solid black"],
           translateX: [0, 250],
           rotate: ["0turn", 1, 0, 0.5],
           "background-color": ["#616aff", "white"],
    
           // You don't need to enter any parameters, you can just use the default values
           easing: "spring",
    
           // You can change the size of Array for the CustomEasing function to generate  
           numPoints: 200,
    
           // The number of decimal places to round, final values in the generated Array
           decimal: 5,
           
           // You can also set the duration from here.
           // When using spring animations, the duration you set here is not nesscary,
           // since by default springs will try to determine the most appropriate duration for the spring animation.
           // But the duration value here will override `spring` easings optimal duration value
           duration: 3000
         })
    })
    

    Parameters

    Returns {}

Const Back

  • Back(t: number, params?: (string | number)[], duration?: number): number

Const Bezier

  • Bezier(t: number, params?: (string | number)[], duration?: number): number

Const Bounce

  • Bounce(t: number, params?: (string | number)[], duration?: number): number

Const CSSArrValue

Const CSSValue

Const Circ

  • Circ(t: number, params?: (string | number)[], duration?: number): number

Const ComplexEasingSyntax

  • ComplexEasingSyntax(ease: string): string

Const ComplexStrtoArr

  • ComplexStrtoArr(str: string): string[]
  • Converts "10px solid red #555 rgba(255, 0,5,6, 7) " to [ '10px', 'solid', 'red', '#555', 'rgba(255, 0,5,6, 7)' ]

    Parameters

    • str: string

    Returns string[]

Const Cubic

  • Cubic(t: number, params?: (string | number)[], duration?: number): number

Const CustomEasing

  • Generates an Array of values using easing functions which in turn create the effect of custom easing. To use this properly make sure to set the easing animation option to "linear". Check out a demo of CustomEasing at https://codepen.io/okikio/pen/abJMWNy?editors=0010

    Custom Easing has 3 properties they are easing (all the easings from EasingFunctions are supported on top of custom easing functions like spring, bounce, etc...), numPoints (the size of the Array the Custom Easing function should create), and decimal (the number of decimal places of the values within said Array).

    Properties Default Value
    easing spring(1, 100, 10, 0)
    numPoints 50
    decimal 3

    By default, Custom Easing support easing functions, in the form,

    constant accelerate decelerate accelerate-decelerate decelerate-accelerate
    linear ease-in / in ease-out / out ease-in-out / in-out ease-out-in / out-in
    ease in-sine out-sine in-out-sine out-in-sine
    steps in-quad out-quad in-out-quad out-in-quad
    step-start in-cubic out-cubic in-out-cubic out-in-cubic
    step-end in-quart out-quart in-out-quart out-in-quart
    in-quint out-quint in-out-quint out-in-quint
    in-expo out-expo in-out-expo out-in-expo
    in-circ out-circ in-out-circ out-in-circ
    in-back out-back in-out-back out-in-back
    in-bounce out-bounce in-out-bounce out-in-bounce
    in-elastic out-elastic in-out-elastic out-in-elastic
    spring / spring-in spring-out spring-in-out spring-out-in

    All Elastic easing's can be configured using theses parameters,

    *-elastic(amplitude, period)

    Each parameter comes with these defaults

    Parameter Default Value
    amplitude 1
    period 0.5

    All Spring easing's can be configured using theses parameters,

    spring-*(mass, stiffness, damping, velocity)

    Each parameter comes with these defaults

    Parameter Default Value
    mass 1
    stiffness 100
    damping 10
    velocity 0

    You can create your own custom cubic-bezier easing curves. Similar to css you type cubic-bezier(...) with 4 numbers representing the shape of the bezier curve, for example, cubic-bezier(0.47, 0, 0.745, 0.715) this is the bezier curve for in-sine.

    Note: the easing property supports the original values and functions for easing as well, for example, steps(1), and etc... are supported.

    Note: you can also use camelCase when defining easing functions, e.g. inOutCubic to represent in-out-cubic

    e.g.

    import { animate, CustomEasing, EaseOut, Quad } from "@okikio/animate"; 
    animate({
      target: "div",
    
      // Notice how only, the first value in the Array uses the "px" unit
      border: CustomEasing(["1px solid red", "3 dashed green", "2 solid black"], {
          // This is a custom easing function
          easing: EaseOut(Quad)
      }),
    
      translateX: CustomEasing([0, 250], {
          easing: "linear",
    
          // You can change the size of Array for the CustomEasing function to generate  
          numPoints: 200,
    
          // The number of decimal places to round, final values in the generated Array
          decimal: 5,
      }),
    
      // You can set the easing without an object
      // Also, if units are detected in the values Array, 
      // the unit of the first value in the values Array are
      // applied to other values in the values Array, even if they
      // have prior units 
      rotate: CustomEasing(["0turn", 1, 0, 0.5], "out"),
      "background-color": CustomEasing(["#616aff", "white"]),
          easing: "linear"
      }),
    
      // TIP... Use linear easing for the proper effect
      easing: "linear"
    })
    

    Parameters

    Returns any[]

Const CustomEasingOptions

Const EaseInOut

Const EaseOut

Const EaseOutIn

Const EasingPts

Const Elastic

  • Elastic(t: number, params?: (string | number)[], duration?: number): number

Const Expo

  • Expo(t: number, params?: (string | number)[], duration?: number): number

Const GetEase

  • GetEase(ease?: string): string
  • Converts users input into a usable easing function string

    Parameters

    • ease: string = "ease"

      easing functions; EasingKeys, cubic-bezier, steps, linear, etc...

    Returns string

    an easing function that KeyframeEffect can accept

Const GetEasingFunction

  • Re-maps a number from one range to another. Numbers outside the range are not clamped to 0 and 1, because out-of-range values are often intentional and useful.

    Parameters

    • ease: string

    Returns TypeEasingFunction

Const KeyframeParse

  • KeyframeParse(input: object): Keyframe[]
  • Allows you to quickly convert CSS like JSON into keyframes

    example
    let keyframes = KeyframeParse({
        "from, 50%, to": {
            opacity: 1
        },
    
        "25%, 0.7": {
            opacity: 0
        }
    });
    
    console.log(keyframes);
    //= [
    //=   { opacity: 1, offset: 0 },
    //=   { opacity: 0, offset: 0.25 },
    //=   { opacity: 1, offset: 0.5 },
    //=   { opacity: 0, offset: 0.7 },
    //=   { opacity: 1, offset: 1 }
    //= ]
    

    Parameters

    • input: object

      CSS style JSON; check the example to understand what I mean

    Returns Keyframe[]

Const ParseCSSProperties

  • ParseCSSProperties(obj: object): {}

Const ParseTransformableCSSKeyframes

Const ParseTransformableCSSProperties

  • Removes the need for the full transform statement in order to use translate, rotate, scale, skew, or perspective including their X, Y, Z, and 3d varients Also, adds the ability to use single string or number values for transform functions

    Note: the transform animation option will override all transform function properties

    Note: the order of where/when you define transform function matters, for example, depending on the order you define translate, and rotate, you can create change the radius of the rotation

    example
    ParseTransformableCSSProperties({
         // It will automatically add the "px" units for you, or you can write a string with the units you want
         translate3d: [
             "25, 35, 60%",
             [50, "60px", 70],
             ["70", 50]
         ],
         translate: "25, 35, 60%",
         translateX: [50, "60px", "70"],
         translateY: ["50, 60", "60"], // Note: this will actually result in an error, make sure to pay attention to where you are putting strings and commas
         translateZ: 0,
         perspective: 0,
         opacity: "0, 5",
         scale: [
             [1, "2"],
             ["2", 1]
         ],
         rotate3d: [
             [1, 2, 5, "3deg"], // The last value in the array must be a string with units for rotate3d
             [2, "4", 6, "45turn"],
             ["2", "4", "6", "-1rad"]
         ],
    
         // Units are required for non transform CSS properties
         // String won't be split into array, they will be wrappeed in an Array
         // It will transform border-left to camelCase "borderLeft"
         "border-left": 50,
         "offset-rotate": "10, 20",
         margin: 5,
    
         // When writing in this formation you must specify the units
         padding: "5px 6px 7px"
    })
    
    //= {
    //=   transform: [
    //=       // `translateY(50, 60)` will actually result in an error
    //=       'translate(25px) translate3d(25px, 35px, 60%) translateX(50px) translateY(50, 60) translateZ(0px) rotate3d(1, 2, 5, 3deg) scale(1, 2) perspective(0px)',
    //=       'translate(35px) translate3d(50px, 60px, 70px) translateX(60px) translateY(60px) rotate3d(2, 4, 6, 45turn) scale(2, 1)',
    //=       'translate(60%) translate3d(70px, 50px) translateX(70px) rotate3d(2, 4, 6, -1rad)'
    //=   ],
    //=   opacity: [ '0', '5' ],
    //=   borderLeft: ["50px"],
    //=
    //=   // Notice the "deg"
    //=   offsetRotate: ["10deg", "20deg"],
    //=   margin: ["5px"],
    //=   padding: ["5px 6px 7px"]
    //= }
    

    Parameters

    Returns { transform: string[] } & {}

    an object with a properly formatted transform and opactity, as well as other unformatted CSS properties

    
    

Const Quad

  • Quad(t: number, params?: (string | number)[], duration?: number): number
  • Easing Functions from anime.js, they are tried and true, so, its better to use them instead of other alternatives

    Parameters

    • t: number
    • Optional params: (string | number)[]
    • Optional duration: number

    Returns number

Const Quart

  • Quart(t: number, params?: (string | number)[], duration?: number): number

Const Quint

  • Quint(t: number, params?: (string | number)[], duration?: number): number

Const Sine

  • Sine(t: number, params?: (string | number)[], duration?: number): number

Const Spring

  • Spring(t: number, params?: (string | number)[], duration?: number): number

Const SpringEasing

  • Returns an array containing [easing pts, duration], it's meant to be a self enclosed way to create spring easing. Springs have an optimal duration; using getEasingDuration() we are able to have the determine the optimal duration for a spring with given parameters.

    By default it will only give the optimal duration for spring or spring-in easing, this is to avoid infinite loops caused by the getEasingDuration() function.

    Internally the SpringEasing uses CustomEasing, read more on it, to understand how the SpringEasing function works.

    e.g.

    import { animate, SpringEasing } from "@okikio/animate";
    
    // `duration` is the optimal duration for the spring with the set parameters
    let [translateX, duration] = SpringEasing([0, 250], "spring(5, 100, 10, 1)");
    // or
    // `duration` is 5000 here
    let [translateX, duration] = SpringEasing([0, 250], { 
         easing: "spring(5, 100, 10, 1)",
         numPoints: 50,
         duration: 5000,
         decimal: 3
    });
    
    animate({
         target: "div",
         translateX,
         duration
    });
    

    Parameters

    Returns (number | any[])[]

Const Steps

  • Steps(t: number, params?: (string | number)[], duration?: number): number

Const UnitDEG

  • UnitDEG(value: string | number): string

Const UnitDEGCSSValue

Const UnitLess

  • UnitLess(value: string | number): string

Const UnitLessCSSValue

Const UnitPX

  • UnitPX(value: string | number): string

Const UnitPXCSSValue

Const addCSSUnit

  • addCSSUnit(unit?: string): (value: string | number) => string
  • Returns a closure Function, which adds a unit to numbers but simply returns strings with no edits assuming the value has a unit if it's a string

    Parameters

    • unit: string = ""

      the default unit to give the CSS Value

    Returns (value: string | number) => string

    if value already has a unit (we assume the value has a unit if it's a string), we return it; else return the value plus the default unit

      • (value: string | number): string
      • Parameters

        • value: string | number

        Returns string

Const animate

Const camelCase

  • camelCase(str: string): string

Const computeOption

Const convertToDash

  • convertToDash(str: string): string

Const createEmptyEl

  • createEmptyEl(): HTMLDivElement

Const createTransformProperty

  • createTransformProperty(transformFnNames: string[], arr: any[]): string

Const easein

  • easein(t: number, params?: (string | number)[], duration?: number): number
  • The default ease-in easing function

    Parameters

    • t: number
    • Optional params: (string | number)[]
    • Optional duration: number

    Returns number

Const flatten

  • flatten(arr: any[]): any[]
  • Merges 2-dimensional Arrays into a single 1-dimensional array

    Parameters

    • arr: any[]

    Returns any[]

Const getEasingDuration

  • The spring easing function will only look smooth at certain durations, with certain parameters. This functions returns the optimal duration to create a smooth springy animation based on physics

    Note: it can also be used to determine the optimal duration of other types of easing function, but be careful of "in-" easing functions, because of the nature of the function it can sometimes create an infinite loop, I suggest only using getEasingDuration for spring, specifically "out-spring" and "spring"

    Parameters

    Returns number

Const getElements

  • getElements(selector: string | Node): Node[]

Const getTargets

Const interpolateColor

  • interpolateColor(t: number, values: TypeColor[], decimal?: number): number[]
  • Use the color-rgba npm package, to convert all color formats to an Array of rgba values, e.g. [red, green, blue, alpha]. Then, use the interpolateNumber functions to interpolate over the array

    Note: the red, green, and blue colors are rounded to intergers with no decimal places, while the alpha color gets rounded to a specific decimal place

    Make sure to read interpolateNumber.

    Parameters

    • t: number
    • values: TypeColor[]
    • decimal: number = 3

    Returns number[]

Const interpolateComplex

  • interpolateComplex(t: number, values: TypeColor[], decimal?: number): any

Const interpolateNumber

  • interpolateNumber(t: number, values: number[], decimal?: number): number
  • Given an Array of numbers, estimate the resulting number, at a t value between 0 to 1 Based on d3.interpolateBasis [https://github.com/d3/d3-interpolate#interpolateBasis], check out the link above for more detail.

    Basic interpolation works by scaling t from 0 - 1, to some start number and end number, in this case lets use 0 as our start number and 100 as our end number, so, basic interpolation would interpolate between 0 to 100.

    If we use a t of 0.5, the interpolated value between 0 to 100, is 50. interpolateNumber takes it further, by allowing you to interpolate with more than 2 values, it allows for multiple values.

    E.g. Given an Array of values [0, 100, 0], and a t of 0.5, the interpolated value would become 100.

    Parameters

    • t: number
    • values: number[]
    • decimal: number = 3

    Returns number

Const interpolateString

  • interpolateString(t: number, values: (string | number)[], decimal?: number): string
  • Functions the same way interpolateNumber works. Convert strings to numbers, and then interpolates the numbers, at the end if there are units on the first value in the values array, it will use that unit for the interpolated result.

    Make sure to read interpolateNumber.

    Parameters

    • t: number
    • values: (string | number)[]
    • decimal: number = 3

    Returns string

Const interpolateUsingIndex

  • interpolateUsingIndex(t: number, values: (string | number)[]): string | number
  • Given an Array of values, find a value using t (t goes from 0 to 1), by using t to estimate the index of said value in the array of values

    Parameters

    • t: number
    • values: (string | number)[]

    Returns string | number

Const isNumberLike

  • isNumberLike(num: string | number): boolean
  • If a value can be converted to a valid number, then it's most likely a number

    Parameters

    • num: string | number

    Returns boolean

Const isValid

  • isValid(value: any): boolean
  • Checks if a value is valid/truthy; it counts empty arrays and strings as falsey, as well as null, undefined, and NaN, everything else is valid

    Note: 0 counts as valid

    Parameters

    • value: any

      anything

    Returns boolean

    true or false

Const limit

  • limit(value: number, min: number, max: number): number

Const mapAnimationOptions

Const mapObject

  • mapObject(obj: object, fn: (value: any, key: any, obj: any) => any): {}
  • Acts like array.map(...) but for functions

    Parameters

    • obj: object
    • fn: (value: any, key: any, obj: any) => any
        • (value: any, key: any, obj: any): any
        • Parameters

          • value: any
          • key: any
          • obj: any

          Returns any

    Returns {}

Const omit

  • omit(keys: string[], obj: {}): {}
  • Return a copy of the object without the keys specified in the keys argument

    Parameters

    • keys: string[]

      arrays of keys to remove from the object

    • obj: {}

      the object in question

      • [key: string]: any

    Returns {}

    a copy of the object without certain keys

Const parseEasingParameters

  • parseEasingParameters(str: string): (string | number)[]
  • Convert easing parameters to Array of numbers, e.g. "spring(2, 500)" to [2, 500]

    Parameters

    • str: string

    Returns (string | number)[]

Const parseOffset

  • parseOffset(input: string | number): number
  • Convert the words "from", and "to" as well as percentage or numbers to offset value between 0 and 1

    Parameters

    • input: string | number

    Returns number

Const parseOptions

Const pick

  • pick(keys: string[], obj: {}): {}
  • Return a copy of the object with only the keys specified in the keys argument

    Parameters

    • keys: string[]

      arrays of keys to keep from the object

    • obj: {}

      the object in question

      • [key: string]: any

    Returns {}

    a copy of the object with only certain keys

Const registerEasingFunction

Const registerEasingFunctions

  • registerEasingFunctions(...obj: {}[]): void

Const scale

  • scale(t: number, start: number, end: number): number

Const toArr

  • toArr(input: any): any[]
  • Convert the input to an array For strings split them at commas For array do nothing For everything else wrap the input in an array

    Parameters

    • input: any

    Returns any[]

Const toFixed

  • toFixed(value: number, decimal: number): number

Const toStr

  • toStr(input: any): string

Const transpose

  • transpose(...args: any[]): any[]
  • Flips the rows and columns of 2-dimensional arrays

    Read more on underscorejs.org & lodash.com

    example
    transpose(
         ['moe', 'larry', 'curly'],
         [30, 40, 50],
         [true, false, false]
    );
    // [
    //     ["moe", 30, true],
    //     ["larry", 40, false],
    //     ["curly", 50, false]
    // ]
    

    Parameters

    • Rest ...args: any[]

    Returns any[]

    returns the new array of grouped elements

Const trim

  • trim(str: string): string
  • Convert value to string, then trim any extra white space and line terminator characters from the string.

    Parameters

    • str: string

    Returns string

Const tween

Const tweenAttr

  • Uses the change in opacity (from the tween function) to interpolate the value of other elements

    e.g.

    import { tweenAttr } from "@okikio/animate";
    import { interpolate } from "polymorph-js";
    
    let startPath = usingPolymorphPathEl.getAttribute("d");
    let endPath = "M12 3v10.55c-.59-.34-1.27-.55-2-.55-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4V7h4V3h-6z";
    
    // This is an svg path interpolate function
    // If used in tandem with `tweenAttr`, you can create morphing animations
    let morph = interpolate([startPath, endPath], {
         addPoints: 0,
         origin: { x: 0, y: 0 },
         optimize: "fill",
         precision: 3
    });
    
    // `tweenAttr` supports all Animation Options.
    // The first argument in Animation Options callbacks are set to the progress of the animation beteen 0 and 1, while the other arguments are moved 1 right
    
    // So, animation options can look like this 
    // `(progress: number, i: number, len: number, el: HTMLElement) => {
    //   return progress;
    // }`
    
    tweenAttr({
         target: "svg path",
         d: progress => morph(progress)
    });
    
    // `tweenAttr` can automatically choose between custom easing functions and or normal easings
    tweenAttr({
         target: ".div",
         targets: ".el",
         width: 250,
         height: ["500px", 600],
         easing: "spring"
    
    // If you want to update styles instead of attributes, 
    // you can change this to "style"
    }, "style");
    

    Read more about tween

    Parameters

    Returns DestroyableAnimate

Generated using TypeDoc