webchalk-animate - v0.31.0
    Preparing search index...

    An object containing up to 4 callback functions that will be called to produce the effect for an animation clip. Returned by PresetEffectDefinition.buildFrameGenerators.

    • keyframesGenerator_play will run every time the clip is played, producing a Keyframes object.
    • keyframesGenerator_rewind will run every time the clip is rewound, producing a Keyframes object.
      • If the backward generator is omitted, the forward generator will be used again instead, and the result will just be played in reverse. It is up to you to check whether the animation effect is valid if this shortcut is taken.
    • mutatorGenerator_play will run every time the clip is played, producing a Mutator function.
    • mutatorGenerator_rewind will run every time the clip is rewound, producing a Mutator function.
      • If the backward generator is omitted, the backward generator will be used again instead, and the result will just be reversed. It is up to you to check whether the animation effect is valid if this shortcut is taken.
    interface EffectFrameGeneratorSet {
        keyframesGenerator_play?: () => Keyframes & Function;
        keyframesGenerator_rewind?: () => Keyframes & Function;
        mutatorGenerator_play?: () => Mutator & Function;
        mutatorGenerator_rewind?: () => Mutator & Function;
        nestedEffectFrameGeneratorSets?: NestedEffectFrameGeneratorSet[];
        reverseKeyframesEffect?: boolean;
        reverseMutatorEffect?: boolean;
    }

    Hierarchy

    • StripDuplicateMethodAutocompletion<
          {
              keyframesGenerator_play?: () => Keyframes;
              keyframesGenerator_rewind?: () => Keyframes;
              mutatorGenerator_play?: () => Mutator;
              mutatorGenerator_rewind?: () => Mutator;
              nestedEffectFrameGeneratorSets?: NestedEffectFrameGeneratorSet[];
              reverseKeyframesEffect?: boolean;
              reverseMutatorEffect?: boolean;
          },
      >
      • EffectFrameGeneratorSet
    Index

    Properties

    nestedEffectFrameGeneratorSets?: NestedEffectFrameGeneratorSet[]

    An array containing NestedEffectFrameGeneratorSets, which can be used to create additional frame generators for animating other elements (for example, animating a secondary element in a swap animation, or animating the children of this.domElem)

    Keyframes Generators

    keyframesGenerator_play?: () => Keyframes & Function

    Performs any necessary operations/computations and then returns keyframes (Keyframes).

    Keyframes, either in the form of a PropertyIndexedKeyframes object or—more commonly—an array of Keyframe objects.

    const clipFactories = webchalk.createAnimationClipFactories({
    additionalEntranceEffectBank: {
    // -----------------------------------------------------------------
    // ----------------------------EXAMPLE 1----------------------------
    // -----------------------------------------------------------------
    // Let us pretend you made this preset entrance animation effect named 'zoomIn'.
    // For this animation, you wrote the forward keyframes generator and
    // then verified that the desired rewinding effect is exactly equivalent
    // to playing the keyframes produced by keyframesGenerator_play() in reverse,
    // so you omit keyframesGenerator_rewind.
    zoomIn: {
    buildFrameGenerators(initialScale: number) {
    // return EffectFrameGeneratorSet
    return {
    keyframesGenerator_play: () => {
    console.log('About to return keyframes!');
    // return Keyframes (Keyframe[])
    return [
    {scale: initialScale, opacity: 0}, // Keyframe 1
    {} // Keyframe 2
    ];
    },
    // keyframesGenerator_rewind() can be omitted in this case because
    // the reversal of the forward keyframes is exactly equivalent.
    // It is written below for demonstration purposes but commented out.
    // -----------------------------------------------------------------------
    // keyframesGenerator_rewind: () => {
    // // return Keyframes (Keyframe[])
    // return [
    // {}, // Keyframe 1
    // {scale: initialScale, opacity: 0} // Keyframe 2
    // ];
    // },
    };
    }
    },
    },

    additionalMotionEffectBank: {
    // -----------------------------------------------------------------
    // ----------------------------EXAMPLE 2----------------------------
    // -----------------------------------------------------------------
    // Let us pretend you made this preset animation effect for moving an element rightward.
    // For this animation, you wrote the forward keyframes generator and then
    // checked to see if the desired rewinding effect could be achieved by just reusing
    // keyframesGenerator_play() and reversing the result. You realize that this effect is NOT
    // a candidate for that shortcut, so you write backwardKeyframesEffect.
    translateRight: {
    buildFrameGenerators(numPixels: number) {
    // a helper function you wrote that will exist within a closure scoped to buildFrameGenerators()
    const createTranslationString = () => {
    if (numPixels <= 0) { throw RangeError(`Number of pixels must exceed 0.`) }
    const translationString = `${numPixels}px`;
    return translationString;
    }

    // return EffectFrameGeneratorSet
    return {
    keyframesGenerator_play: () => {
    // return Keyframes (Keyframe[])
    return [
    {translate: createTranslationString()} // Keyframe
    ];
    },
    // keyframesGenerator_rewind() must be specified because reversing the keyframes produced
    // by keyframesGenerator_play() would not have the intended effect (because of
    // {composite: accumulate}, trying to simply use the reversal of
    // {translate: createTranslationString()} from keyframesGenerator_play() would actually
    // cause the target element to jump an additional numPixels pixels to the right
    // before sliding left, which is not the intended rewinding effect).
    keyframesGenerator_rewind: () => {
    // return Keyframes (Keyframe[])
    return [
    {translate: '-'+createTranslationString()}, // Keyframe
    ];
    },
    };
    },
    immutableConfig: {
    // this means that the translation is added onto the element's position
    // instead of replacing it
    composite: 'accumulate',
    },
    howOftenBuildGenerators: 'on-first-play-only',
    },
    }
    });

    const element = document.querySelector('.some-element');
    (async () => {
    const ent = clipFactories.Entrance(element, 'zoomIn', [0.2]);
    await ent.play();
    // ↑ keyframesGenerator_play() will run and produce the Keyframe array
    // [{scale: initialScale, opacity: 0}, {scale: 1, opacity: 1}].
    // That Keyframe array is used for the animation effect as the clip plays forward.

    await ent.rewind();
    // ↑ Since keyframesGenerator_rewind() was not set, the clip will run keyframesGenerator_play()
    // again and just use its effect in reverse when rewinding (which would be exactly equivalent
    // to specifying keyframesGenerator_rewind() and having it return
    // [{}, {scale: initialScale, opacity: 0}]).
    // In other words, keyframesGenerator_play() will run again to produce the Keyframe array
    // [{scale: initialScale, opacity: 0}, {}], then
    // the Keyframe array is used for the animation effect but set to go in reverse,
    // and the effect is used as the clip rewinds.

    const mot = clipFactories.Motion(element, 'translateRight', [756]);
    await mot.play();
    // ↑ keyframesGenerator_play() will run and produce the Keyframes array [{translate: '756px'}].
    // That Keyframe array is used for the animation effect as the clip plays.

    await mot.rewind();
    // ↑ backwardFramesGenerator() will run and produce the Keyframe array [{translate: '-756px'}].
    // That Keyframe array is used for the animation effect as the clip rewinds.
    })();
    keyframesGenerator_rewind?: () => Keyframes & Function

    Performs any necessary operations/computations and then returns keyframes (Keyframes).

    Keyframes, either in the form of a PropertyIndexedKeyframes object or—more commonly—an array of Keyframe objects.

    const clipFactories = webchalk.createAnimationClipFactories({
    additionalEntranceEffectBank: {
    // -----------------------------------------------------------------
    // ----------------------------EXAMPLE 1----------------------------
    // -----------------------------------------------------------------
    // Let us pretend you made this preset entrance animation effect named 'zoomIn'.
    // For this animation, you wrote the forward keyframes generator and
    // then verified that the desired rewinding effect is exactly equivalent
    // to playing the keyframes produced by keyframesGenerator_play() in reverse,
    // so you omit keyframesGenerator_rewind.
    zoomIn: {
    buildFrameGenerators(initialScale: number) {
    // return EffectFrameGeneratorSet
    return {
    keyframesGenerator_play: () => {
    console.log('About to return keyframes!');
    // return Keyframes (Keyframe[])
    return [
    {scale: initialScale, opacity: 0}, // Keyframe 1
    {} // Keyframe 2
    ];
    },
    // keyframesGenerator_rewind() can be omitted in this case because
    // the reversal of the forward keyframes is exactly equivalent.
    // It is written below for demonstration purposes but commented out.
    // -----------------------------------------------------------------------
    // keyframesGenerator_rewind: () => {
    // // return Keyframes (Keyframe[])
    // return [
    // {}, // Keyframe 1
    // {scale: initialScale, opacity: 0} // Keyframe 2
    // ];
    // },
    };
    }
    },
    },

    additionalMotionEffectBank: {
    // -----------------------------------------------------------------
    // ----------------------------EXAMPLE 2----------------------------
    // -----------------------------------------------------------------
    // Let us pretend you made this preset animation effect for moving an element rightward.
    // For this animation, you wrote the forward keyframes generator and then
    // checked to see if the desired rewinding effect could be achieved by just reusing
    // keyframesGenerator_play() and reversing the result. You realize that this effect is NOT
    // a candidate for that shortcut, so you write backwardKeyframesEffect.
    translateRight: {
    buildFrameGenerators(numPixels: number) {
    // a helper function you wrote that will exist within a closure scoped to buildFrameGenerators()
    const createTranslationString = () => {
    if (numPixels <= 0) { throw RangeError(`Number of pixels must exceed 0.`) }
    const translationString = `${numPixels}px`;
    return translationString;
    }

    // return EffectFrameGeneratorSet
    return {
    keyframesGenerator_play: () => {
    // return Keyframes (Keyframe[])
    return [
    {translate: createTranslationString()} // Keyframe
    ];
    },
    // keyframesGenerator_rewind() must be specified because reversing the keyframes produced
    // by keyframesGenerator_play() would not have the intended effect (because of
    // {composite: accumulate}, trying to simply use the reversal of
    // {translate: createTranslationString()} from keyframesGenerator_play() would actually
    // cause the target element to jump an additional numPixels pixels to the right
    // before sliding left, which is not the intended rewinding effect).
    keyframesGenerator_rewind: () => {
    // return Keyframes (Keyframe[])
    return [
    {translate: '-'+createTranslationString()}, // Keyframe
    ];
    },
    };
    },
    immutableConfig: {
    // this means that the translation is added onto the element's position
    // instead of replacing it
    composite: 'accumulate',
    },
    howOftenBuildGenerators: 'on-first-play-only',
    },
    }
    });

    const element = document.querySelector('.some-element');
    (async () => {
    const ent = clipFactories.Entrance(element, 'zoomIn', [0.2]);
    await ent.play();
    // ↑ keyframesGenerator_play() will run and produce the Keyframe array
    // [{scale: initialScale, opacity: 0}, {scale: 1, opacity: 1}].
    // That Keyframe array is used for the animation effect as the clip plays forward.

    await ent.rewind();
    // ↑ Since keyframesGenerator_rewind() was not set, the clip will run keyframesGenerator_play()
    // again and just use its effect in reverse when rewinding (which would be exactly equivalent
    // to specifying keyframesGenerator_rewind() and having it return
    // [{}, {scale: initialScale, opacity: 0}]).
    // In other words, keyframesGenerator_play() will run again to produce the Keyframe array
    // [{scale: initialScale, opacity: 0}, {}], then
    // the Keyframe array is used for the animation effect but set to go in reverse,
    // and the effect is used as the clip rewinds.

    const mot = clipFactories.Motion(element, 'translateRight', [756]);
    await mot.play();
    // ↑ keyframesGenerator_play() will run and produce the Keyframes array [{translate: '756px'}].
    // That Keyframe array is used for the animation effect as the clip plays.

    await mot.rewind();
    // ↑ backwardFramesGenerator() will run and produce the Keyframe array [{translate: '-756px'}].
    // That Keyframe array is used for the animation effect as the clip rewinds.
    })();
    reverseKeyframesEffect?: boolean

    If true, the effect specified by the keyframes generators will be reversed.

    • This is convenient when you want to create the opposite of another previously defined effect.
    • This also applies to all keyframe generators within EffectFrameGeneratorSet.nestedEffectFrameGeneratorSet | nestedEffectFrameGeneratorSet.

    Mutator Generators

    mutatorGenerator_play?: () => Mutator & Function

    Performs any necessary operations/computations and then returns a function that will be run on every frame.

    A function that presumably mutates the target element in some way (possibly with the help of AnimClip.computeTween) and will automatically be run on every frame. Since it will be run on every frame, it will create the illusion of a smooth animation.

    const clipFactories = webchalk.createAnimationClipFactories({
    additionalMotionEffectBank: {
    // a preset animation effect for scrolling to a specific point on the page.
    scrollTo: {
    buildFrameGenerators(yPosition: number) {
    const initialPosition = this.domElem.scrollTop;

    // return EffectFrameGeneratorSet
    return {
    // The mutation is to use the scrollTo() method on the element.
    // Thanks to computeTween(), there will be a smooth scroll
    // from initialPosition to yPosition
    mutatorGenerator_play: () => {
    // return Mutator
    return () => {
    this.domElem.scrollTo({
    top: this.computeTween(initialPosition, yPosition),
    behavior: 'instant'
    });
    };
    },

    // The forward mutation loop is not invertible because reversing it requires
    // re-computing the element's scroll position at the time of rewinding
    // (which may have since changed for any number of reasons, including user
    // scrolling, size changes, etc.). So we must define mutatorGenerator_rewind()
    // to do exactly that.
    mutatorGenerator_rewind: () => {
    // return Mutator
    return () => {
    const currentPosition = this.domElem.scrollTop;
    this.domElem.scrollTo({
    top: this.computeTween(currentPosition, initialPosition),
    behavior: 'instant'
    });
    };
    },
    };
    }
    },
    }
    });

    const element = document.querySelector('.some-element');
    const mot = clipFactories.Motion(element, 'scrollTo', [1020]);
    mot.play().then(mot.rewind);
    mutatorGenerator_rewind?: () => Mutator & Function

    Performs any necessary operations/computations and then returns a function that will be run on every frame.

    A function that presumably mutates the target element in some way (possibly with the help of AnimClip.computeTween) and will automatically be run on every frame. Since it will be run on every frame, it will create the illusion of a smooth animation.

    const clipFactories = webchalk.createAnimationClipFactories({
    additionalMotionEffectBank: {
    // a preset animation effect for scrolling to a specific point on the page.
    scrollTo: {
    buildFrameGenerators(yPosition: number) {
    const initialPosition = this.domElem.scrollTop;

    // return EffectFrameGeneratorSet
    return {
    // The mutation is to use the scrollTo() method on the element.
    // Thanks to computeTween(), there will be a smooth scroll
    // from initialPosition to yPosition
    mutatorGenerator_play: () => {
    // return Mutator
    return () => {
    this.domElem.scrollTo({
    top: this.computeTween(initialPosition, yPosition),
    behavior: 'instant'
    });
    };
    },

    // The forward mutation loop is not invertible because reversing it requires
    // re-computing the element's scroll position at the time of rewinding
    // (which may have since changed for any number of reasons, including user
    // scrolling, size changes, etc.). So we must define mutatorGenerator_rewind()
    // to do exactly that.
    mutatorGenerator_rewind: () => {
    // return Mutator
    return () => {
    const currentPosition = this.domElem.scrollTop;
    this.domElem.scrollTo({
    top: this.computeTween(currentPosition, initialPosition),
    behavior: 'instant'
    });
    };
    },
    };
    }
    },
    }
    });

    const element = document.querySelector('.some-element');
    const mot = clipFactories.Motion(element, 'scrollTo', [1020]);
    mot.play().then(mot.rewind);
    reverseMutatorEffect?: boolean

    If true, the effect specified by the mutator generators will be reversed.

    • This is convenient when you want to create the opposite of another previously defined effect.
    • This also applies to all mutator generators within EffectFrameGeneratorSet.nestedEffectFrameGeneratorSet | nestedEffectFrameGeneratorSet.