Animations

Function animateHTML(inputFrames, options)

Turns keyframe objects into a giant string of HTML and CSS that renders the animation.

Parameter inputFrames

An array of objects conforming to the following TypeScript type:

type InputFrame = {
  code: string;
  ranges?: InputRange[];
  decorations?: InputDecoration[];
};
12345
type InputFrame = {
  code: string;
  ranges?: InputRange[];
  decorations?: InputDecoration[];
};

Each object represents one keyframe in the resulting animation.

Parameter options

An object conforming to the following TypeScript type:

type InputOptions = {
  language: LanguageDefinition;
  tabSize: number;
  rootClassSeed?: number;
  debugOverride?: boolean;
  theme?: Theme;
};
1234567
type InputOptions = {
  language: LanguageDefinition;
  tabSize: number;
  rootClassSeed?: number;
  debugOverride?: boolean;
  theme?: Theme;
};

Return value

A string of HTML containing the animation, expressed as a <div> and a <style> element.

You can jump between keyframes by switching between the classes frame0, frame1, frameN etc. on the element with the class cm-animation or use the Code.Movie runtime element to get a more high-level API and UI.

Function fromStringsToScene(inputFrames, inputOptions)

Turns keyframe objects into a SceneData object that contains the animation information. Only useful if you need to read or modify the resulting SceneData object before turning it into HTML and CSS.

Parameter inputFrames

Same as the fist parameter to animateHTML(inputFrames, options).

Parameter inputOptions

An object conforming to the following TypeScript type:

type InputOptions = {
  language: LanguageDefinition;
  tabSize: number;
};
1234
type InputOptions = {
  language: LanguageDefinition;
  tabSize: number;
};

Return value

A SceneData object. Contains the language definition, animation information and some metadata. Usually passed straight to toAnimationHTML(). The exact object interface may change at any time. Use with caution.

Function toAnimationHTML(sceneData, animationOptions)

Turns scene data and animation options into a giant string of HTML and CSS that renders the animation. Only useful when you use fromStringsToScene() instead of the more convenient animateHTML().

Parameter sceneData

The animation information object generated by fromStringsToScene().

Parameter animationOptions

An object conforming to the following TypeScript type:

type AnimationOptions = {
  rootClassSeed?: number;
  debugOverride?: boolean;
  theme?: Theme;
};
12345
type AnimationOptions = {
  rootClassSeed?: number;
  debugOverride?: boolean;
  theme?: Theme;
};

Return value

Same as animateHTML(inputFrames, options) (a huge string of HTML and CSS containing the finished animation).