Interface EffectGenerator<TClipContext, TConfig>

Object representing an entry in an EffectGeneratorBank. It consists of 3 properties:

The configuration options that are allowed to be set in defaultConfig or immutableConfig depend on AnimClip.categoryImmutableConfig. For example, ExitClip.categoryImmutableConfig contains commitStyles: false, so the commitStyles option is unavailable in defaultConfig and immutableConfig for any entries in the exit effects bank.

interface EffectGenerator<TClipContext, TConfig> {
    defaultConfig?: Partial<TConfig>;
    generateKeyframeGenerators?: ((...effectOptions: unknown[]) => StripDuplicateMethodAutocompletion<{
        backwardGenerator?: (() => Keyframes);
        forwardGenerator: (() => Keyframes);
    }>) & Function;
    generateKeyframes: undefined | ((...effectOptions: unknown[]) => {
        backwardFrames?: Keyframes;
        forwardFrames: Keyframes;
    }) & Function;
    generateRafMutatorGenerators?: ((...effectOptions: unknown[]) => StripDuplicateMethodAutocompletion<{
        backwardGenerator: (() => (() => void));
        forwardGenerator: (() => (() => void));
    }>) & Function;
    generateRafMutators?: ((...effectOptions: unknown[]) => StripDuplicateMethodAutocompletion<{
        backwardMutator: (() => void);
        forwardMutator: (() => void);
    }>) & Function;
    immutableConfig?: Partial<TConfig>;
}

Type Parameters

  • TClipContext extends unknown = unknown
  • TConfig extends unknown = unknown

Properties

defaultConfig?: Partial<TConfig>

Default configuration options that are appropriate for the effect (and can be overwritten).

generateKeyframeGenerators?: ((...effectOptions: unknown[]) => StripDuplicateMethodAutocompletion<{
    backwardGenerator?: (() => Keyframes);
    forwardGenerator: (() => Keyframes);
}>) & Function

Type declaration

    • (...effectOptions): StripDuplicateMethodAutocompletion<{
          backwardGenerator?: (() => Keyframes);
          forwardGenerator: (() => Keyframes);
      }>
    • Runs itself exactly once (creating a closure) and returns up to 2 callback functions that each return one set of Keyframes.

      Parameters

      • Rest...effectOptions: unknown[]

        parameters used to set the behavior for the specific animation effect

      Returns StripDuplicateMethodAutocompletion<{
          backwardGenerator?: (() => Keyframes);
          forwardGenerator: (() => Keyframes);
      }>

      An object containing 2 possible callback functions that each generate (return) one set of Keyframes.

      • forwardGenerator will run every time the clip is played
      • backwardGenerator (optional) will run every time the clip is rewound
        • If backwardGenerator is omitted, forwardGenerator will be used, and the resulting keyframes will be reversed
      const clipFactories = webimator.createAnimationClipFactories({
      customExitEffects: {
      // a custom animation effect for flying out to the left side of the screen
      flyOutLeft: {
      generateKeyframeGenerators() {
      const computeTranslationStr = () => {
      const orthogonalDistance = -(this.domElem.getBoundingClientRect().right);
      const translationString = `${orthogonalDistance}px 0px`;
      return translationString;
      }

      return {
      forwardGenerator: () => {
      return [
      {translate: computeTranslationStr()}
      ];
      },
      // backwardGenerator could have been omitted because the result of running forwardGenerator()
      // again and reversing the keyframes produces the same desired rewinding effect in this case
      backwardGenerator: () => {
      return [
      {translate: computeTranslationStr()},
      {translate: `0 0`}
      ];
      }
      };
      },

      immutableConfig: {
      // this means that the translation is added onto the element's position instead of replacing it
      composite: 'accumulate',
      }
      },
      }
      });

      const element = document.querySelector('.some-element');
      const ext = clipFactories.Exit(element, 'flyOutLeft', []);
      ext.play().then(ext.rewind);
generateKeyframes: undefined | ((...effectOptions: unknown[]) => {
    backwardFrames?: Keyframes;
    forwardFrames: Keyframes;
}) & Function
generateRafMutatorGenerators?: ((...effectOptions: unknown[]) => StripDuplicateMethodAutocompletion<{
    backwardGenerator: (() => (() => void));
    forwardGenerator: (() => (() => void));
}>) & Function

Type declaration

    • (...effectOptions): StripDuplicateMethodAutocompletion<{
          backwardGenerator: (() => (() => void));
          forwardGenerator: (() => (() => void));
      }>
    • Runs itself exactly once (creating a closure) and returns 2 function that each return one function. Those final returned functions are run every frame (using requestAnimationFrame behind the scenes), so if a property of the animated element is changed using AnimClip.computeTween, it will look like a smooth animation.

      Parameters

      • Rest...effectOptions: unknown[]

        parameters used to set the behavior for the specific animation effect

      Returns StripDuplicateMethodAutocompletion<{
          backwardGenerator: (() => (() => void));
          forwardGenerator: (() => (() => void));
      }>

      An object containing 2 callback functions that each generate (return) one function.

      • forwardGenerator will run every time the clip is played, producing a function that will be used in a loop
      • backwardGenerator will run every time the clip is rewound, producing a function that will be used in a loop
      const clipFactories = webimator.createAnimationClipFactories({
      customMotionEffects: {
      // a custom animation for scrolling to a specific point on the page.
      // when rewinding, the current scroll position is computed on the spot so that
      // it can smoothly scroll from THERE to the initial position.
      scrollToImproved: {
      generateRafMutatorGenerators(yPosition: number) {
      const initialPosition = this.domElem.scrollTop;

      return {
      forwardGenerator: () => {
      const forwardMutator = () => {
      this.domElem.scrollTo({
      top: this.computeTween(initialPosition, yPosition),
      behavior: 'instant'
      });
      };
      return forwardMutator;
      },

      backwardGenerator: () => {
      const backwardMutator = () => {
      const currentPosition = this.domElem.scrollTop;
      this.domElem.scrollTo({
      top: this.computeTween(currentPosition, initialPosition),
      behavior: 'instant'
      });
      };
      return backwardMutator;
      }
      };
      }
      },
      }
      });

      const element = document.querySelector('.some-element');
      const mot = clipFactories.Motion(element, 'scrollToImproved', [1020]);
      mot.play().then(mot.rewind);
generateRafMutators?: ((...effectOptions: unknown[]) => StripDuplicateMethodAutocompletion<{
    backwardMutator: (() => void);
    forwardMutator: (() => void);
}>) & Function

Type declaration

    • (...effectOptions): StripDuplicateMethodAutocompletion<{
          backwardMutator: (() => void);
          forwardMutator: (() => void);
      }>
    • Runs every time the clip is played, returning 2 functions each time. These functions are run every frame (using requestAnimationFrame behind the scenes), so if a property of the animated element is changed using AnimClip.computeTween, it will look like a smooth animation.

      Parameters

      • Rest...effectOptions: unknown[]

        parameters used to set the behavior for the specific animation effect

      Returns StripDuplicateMethodAutocompletion<{
          backwardMutator: (() => void);
          forwardMutator: (() => void);
      }>

      An object containing 2 functions.

      • forwardMutator is used for the clip's animation when the clip is played
      • backwardKeyframes is used for the clip's animation when the clip is rewound
      const clipFactories = webimator.createAnimationClipFactories({
      customMotionEffects: {
      // a custom animation for scrolling to a specific position (but when
      // rewinding, it will snap to yPosition before scrolling to the initial position, which
      // may feel janky. This could be solved with generateRafMutatorGenerators())
      scrollTo: {
      generateRafMutators(yPosition: number) {
      const initialPosition = this.domElem.scrollTop;

      return {
      forwardMutator: () => {
      this.domElem.scrollTo({
      top: this.computeTween(initialPosition, yPosition),
      behavior: 'instant'
      });
      },
      backwardMutator: () => {
      this.domElem.scrollTo({
      top: this.computeTween(yPosition, initialPosition),
      behavior: 'instant'
      });
      }
      };
      }
      },
      }
      });

      const element = document.querySelector('.some-element');
      const mot = clipFactories.Motion(element, 'scrollTo', [1020]);
      mot.play().then(mot.rewind);
immutableConfig?: Partial<TConfig>

default configuration options for the effect that cannot be overwritten (but cannot be overwritten).