Used to reveal a WebimatorConnectorElement that was hidden.

A "clip" is the smallest building block of a timeline. It is essentially a [DOM element, effect] pair, where a "DOM element" is some HTML element on the page and the effect is the animation effect that will be applied to it (asynchronously).

The AnimClip class is abstract, meaning it cannot be instantiated. But it has several subclasses such as EntranceClip, MotionClip, TransitionClip, etc. Webimator provides convenient factory functions that can be used to create such clips—the factory functions can be obtained from Webimator.createAnimationClipFactories. Examples are shown below.

Generally (with some exceptions), using a clip factory function follows this format: const clip = <factory func>(<some element>, <effect name>, [<effect options>], {<optional clip configuration>});

"<some element>" here must be of type WebimatorConnectorElement (our custom <wbmtr-connector> HTML element).

Note that ConnectorEntranceClips are merely for entering connectors, not setting their endpoints. A connector's endpoints must be set (using a ConnectorSetterClip), and then a ConnectorEntranceClip can be used to draw the connector.

// retrieve connector entrance clip factory function;
const { ConnectorEntrance } = webimator.createAnimationClipFactories();

// select connector elements from the DOM
const topConnector = document.querySelector('.connector--thick');
const middleConnector = document.querySelector('.connector--skinny');
const verticalConnector = document.querySelector('.connector--red');
const bottomConnector = document.querySelector('.connector--dashed');

// A = element, B = effect name, C = effect options, D = configuration (optional)

// create connector entrance clips using factory function
// A B C D
const clip1 = ConnectorEntrance(topConnector, '~fade-in', [], {duration: 2000, playbackRate: 2});
// A B C
const clip2 = ConnectorEntrance(middleConnector, '~trace', ['from-A']);
// A B C D
const clip3 = ConnectorEntrance(verticalConnector, '~trace', ['from-bottom'], {delay: 500});
// A B C
const clip4 = ConnectorEntrance(bottomConnector, '~appear', []);

// play clips (all will play at the same time because they are asynchronous)
clip1.play(); // topConnector fades in
clip2.play(); // middleConnector is drawn from its point A to its point B
clip3.play(); // verticalConnector is draw starting from whichever endpoint is lower
clip4.play(); // bottomConnector appears instantly

Type Parameters

Hierarchy (view full)

Structure

The DOM element that is to be animated.

Properties

animation: WebimatorAnimation = ...
effectGenerator: TEffectGenerator
effectName: string
effectOptions: Parameters<TEffectGenerator extends KeyframesGenerator<unknown>
    ? TEffectGenerator<TEffectGenerator>["generateKeyframes"]
    : TEffectGenerator extends KeyframesGeneratorsGenerator<unknown>
        ? TEffectGenerator<TEffectGenerator>["generateKeyframeGenerators"]
        : TEffectGenerator extends RafMutatorsGenerator<unknown>
            ? TEffectGenerator<TEffectGenerator>["generateRafMutators"]
            : TEffectGenerator extends RafMutatorsGeneratorsGenerator<unknown>
                ? TEffectGenerator<TEffectGenerator>["generateRafMutatorGenerators"]
                : never> = ...
generateError: ClipErrorGenerator = ...
id: number

Number that uniquely identifies the clip from other clips. Automatically generated.

inProgress: boolean = false
isPaused: boolean = false
isRunning: boolean = false

Property Getter Methods

Accessors

Playback Methods

Timing Event Methods

  • Pauses the animation clip when it reaches the specified time in the specified direction, only unpausing after the specified array of Promise objects is resolved.

    • If the clip is part of a structure (like a sequence), the entire structure is paused as well.

    Parameters

    • direction: "forward" | "backward"

      the direction the animation will be going when the clip is paused

    • phase:
          | "delayPhase"
          | "activePhase"
          | "endDelayPhase"
          | "whole"

      the phase of the animation to place the blocks in

    • timePosition:
          | number
          | "end"
          | `${number}%`
          | "beginning"

      the time position within the phase when the roadblocks should be encountered

    • promises: (Promise<unknown> | (() => Promise<unknown>))[]

      an array of promises or functions that return promises that block the clip's playback until resolved

    Returns void

    async function wait(milliseconds: number) { // Promise-based timer
    return new Promise(resolve => setTimeout(resolve, milliseconds));
    }

    const square = document.querySelector('.square');
    const { Entrance } = webimator.createAnimationClipFactories();
    const ent = Entrance(square, '~fade-in', []);

    // adds 1 roadblock that will pause the clip once the clip is 15% through the delay phase
    ent.addRoadblocks('forward', 'activePhase', '15%', [function(){ return wait(2000); }]);
    // adds 2 more roadblocks at the same point.
    const someOtherPromise = Promise.resolve(); // instantly resolved promise
    ent.addRoadblocks('forward', 'activePhase', '15%', [function(){ return wait(3000); }, someOtherPromise]);
    // adds 1 roadblock at 40% into the endDelay phase
    ent.addRoadblocks('forward', 'endDelayPhase', '40%', [new Promise(resolve => {})]);

    ent.play();
    // ↑ Once ent is 15% through the active phase, it will pause and handle its roadblocks.
    // "wait(2000)" resolves after 2 seconds.
    // "wait(3000)" resolves after 3 seconds.
    // someOtherPromise blocks the clip's playback. Presumably, its resolver is eventually called from somewhere outside.
    // Once someOtherPromise is resolved, there are no more roadblocks at this point, so playback is resumed.
    // Once ent is 40% through the endDelay phase, it will pause and handle its roadblocks
    // The newly created promise obviously has no way to be resolved, so the clip is unfortunately stuck.
  • Returns a Promise that is resolved when the animation clip reaches the specified time in the specified direction.

    Parameters

    • direction: "forward" | "backward"

      the direction the animation will be going when the Promise is resolved

    • phase:
          | "delayPhase"
          | "activePhase"
          | "endDelayPhase"
          | "whole"

      the phase of the animation where the Promise will be resolved

    • timePosition:
          | number
          | "end"
          | `${number}%`
          | "beginning"

      the time position within the phase when the Promise will be resolved

    Returns Promise<void>

    a Promise that is resolved at the specific time point of the animation.

    async function testFunc() {
    const { Entrance } = webimator.createAnimationClipFactories();
    const square = document.querySelector('.square');
    const ent = Entrance(square, '~fade-in', []);
    // wait until ent is played and gets 1/5 of the way through the active phase of the animation
    await ent.generateTimePromise('forward', 'activePhase', '20%');
    console.log('1/5 done playing!');
    }

    testFunc();
    async function testFunc() {
    const { Entrance } = webimator.createAnimationClipFactories();
    const square = document.querySelector('.square');
    const ent = Entrance(square, '~fade-in', []);
    // wait until ent is eventually rewound and gets 4/5 of the way through rewinding the active phase of the animation
    await ent.generateTimePromise('backward', 'activePhase', '20%');
    console.log('4/5 done rewinding!');
    }

    testFunc();

Configuration

  • get categoryDefaultConfig(): {
        commitsStyles: false;
        composite: "replace";
        cssClasses: {
            toAddOnFinish: [];
            toAddOnStart: [];
            toRemoveOnFinish: [];
            toRemoveOnStart: [];
        };
        delay: 0;
        duration: 500;
        easing: "linear";
        endDelay: 0;
        hideNowType: null;
        playbackRate: 1;
        runGeneratorsNow: false;
        startsNextClipToo: false;
        startsWithPrevious: false;
    }
  • The default configuration for clips in a specific effect category, which includes any additional configuration options that are specific to the effect category.

    • This never changes, and it available mostly just for reference. Consider it a static property.
    • This does NOT include any default configuration from effect generators or configurations passed in from clip factory functions.

    Returns {
        commitsStyles: false;
        composite: "replace";
        cssClasses: {
            toAddOnFinish: [];
            toAddOnStart: [];
            toRemoveOnFinish: [];
            toRemoveOnStart: [];
        };
        delay: 0;
        duration: 500;
        easing: "linear";
        endDelay: 0;
        hideNowType: null;
        playbackRate: 1;
        runGeneratorsNow: false;
        startsNextClipToo: false;
        startsWithPrevious: false;
    }

    • commitsStyles: false
    • composite: "replace"
    • cssClasses: {
          toAddOnFinish: [];
          toAddOnStart: [];
          toRemoveOnFinish: [];
          toRemoveOnStart: [];
      }
      • ReadonlytoAddOnFinish: []
      • ReadonlytoAddOnStart: []
      • ReadonlytoRemoveOnFinish: []
      • ReadonlytoRemoveOnStart: []
    • delay: 0
    • duration: 500
    • easing: "linear"
    • endDelay: 0
    • hideNowType: null
    • playbackRate: 1
    • runGeneratorsNow: false
    • startsNextClipToo: false
    • startsWithPrevious: false
  • get categoryImmutableConfig(): {
        commitsStyles: false;
    }
  • The unchangeable default configuration for clips in a specific effect category.

    • This never changes, and it is available mostly just for reference. Consider it a static property.
    • This does NOT include any immutable configuration from effect generators.

    Returns {
        commitsStyles: false;
    }

    • commitsStyles: false
  • get immutableConfig(): this["categoryImmutableConfig"] & TEffectGenerator["immutableConfig"]
  • All the unchangeable default configuration settings for the clip (both category-specific immutable configurations and immutable configurations that come from the specific effect generator).

    Returns this["categoryImmutableConfig"] & TEffectGenerator["immutableConfig"]

  • get baseDefaultConfig(): {
        commitsStyles: true;
        composite: "replace";
        cssClasses: {
            toAddOnFinish: [];
            toAddOnStart: [];
            toRemoveOnFinish: [];
            toRemoveOnStart: [];
        };
        delay: 0;
        duration: 500;
        easing: "linear";
        endDelay: 0;
        playbackRate: 1;
        runGeneratorsNow: false;
        startsNextClipToo: false;
        startsWithPrevious: false;
    }
  • The base default configuration for any animation clip before any category-specific configuration, effect generator configuration, or configuration passed in through clip factory functions are applied.

    Returns {
        commitsStyles: true;
        composite: "replace";
        cssClasses: {
            toAddOnFinish: [];
            toAddOnStart: [];
            toRemoveOnFinish: [];
            toRemoveOnStart: [];
        };
        delay: 0;
        duration: 500;
        easing: "linear";
        endDelay: 0;
        playbackRate: 1;
        runGeneratorsNow: false;
        startsNextClipToo: false;
        startsWithPrevious: false;
    }

    • ReadonlycommitsStyles: true
    • Readonlycomposite: "replace"
    • ReadonlycssClasses: {
          toAddOnFinish: [];
          toAddOnStart: [];
          toRemoveOnFinish: [];
          toRemoveOnStart: [];
      }
      • ReadonlytoAddOnFinish: []
      • ReadonlytoAddOnStart: []
      • ReadonlytoRemoveOnFinish: []
      • ReadonlytoRemoveOnStart: []
    • Readonlydelay: 0
    • Readonlyduration: 500
    • Readonlyeasing: "linear"
    • ReadonlyendDelay: 0
    • ReadonlyplaybackRate: 1
    • ReadonlyrunGeneratorsNow: false
    • ReadonlystartsNextClipToo: false
    • ReadonlystartsWithPrevious: false

Helper Methods

  • Calculates the value partway between two fixed numbers (an initial value and a final value) based on the progress of the animation.

    • Intended for use inside effect generator functions that utilize RAF loops.

    Parameters

    • initialVal: number

      the starting value

    • finalVal: number

      the ending value

    Returns number

    the number that is a percentage of the way between initialVal and finalVal based on the percentage of completion of the animation (playing or rewinding).

    const {Entrance} = webimator.createAnimationClipFactories({
    customEntranceEffects: {
    rotate: {
    generateRafMutators(degrees: number) {
    return {
    // when playing, keep computing the value between 0 and 'degrees'
    forwardMutator: () => { this.domElem.style.rotate = this.computeTween(0, degrees)+'deg'; },
    // when rewinding, keep computing the value between 'degrees' and 0
    backwardMutator: () => { this.domElem.style.rotate = this.computeTween(degrees, 0)+'deg'; }
    };
    }
    }
    },
    });

    const someElement = document.querySelector('.some-element');

    (async () => {
    await Entrance(someElement, 'rotate', [360], {duration: 2000}).play();
    // ↑ At 1.5 seconds (or 1500ms), the animation is 1.5/2 = 75% done playing.
    // Thus, computeTween(0, 360) at that exactly moment would...
    // return the value 75% of the way between 0 and 360 (= 270).
    // Therefore, at 1.5 seconds of playing, someElement's rotation is set to "270deg".

    await Entrance(someElement, 'rotate', [360], {duration: 2000}).rewind();
    // ↑ At 0.5 seconds (or 500ms), the animation is 0.5/2 = 25% done rewinding.
    // Thus, computeTween(360, 0) at that exactly moment would...
    // return the value 25% of the way between 360 and 0 (= 270).
    // Therefore, at 0.5 seconds of rewinding, someElement's rotation is set to "270deg".
    })();

Methods