Skip to main content

utils

import {...} from "@motion-canvas/core/lib/utils";

General utilities and helper functions.

Classes

Interfaces

Type Aliases

RefsProperty

type RefsPropertyTValue = TValue extends public () ? TReference : never

Type Parameters

Variables

DEG2RAD

const DEG2RAD: number = ...

A constant for converting degrees to radians

Examples


RAD2DEG

const RAD2DEG: number = ...

A constant for converting radians to degrees

Examples

Functions

beginSlide

public beginSlidename: string: ThreadGenerator

Parameters


capitalize

public capitalizeT extends stringvalue: T: CapitalizeT

Type Parameters

  • T extends string

Parameters


createRef

public createRefT(): ReferenceT

Type Parameters


debug

public debugpayload: any: void

Logs a debug message with an arbitrary payload.

This method is a shortcut for calling useLogger().debug() which allows you to more easily log non-string values as well.

Examples

Parameters


deprecate

public deprecateTArgs extends any[]TReturnfn: public ()message: stringremarks?: string: public ()

Mark the given function as deprecated.

Type Parameters

Parameters

  • fn: public ()

    The function to deprecate.

  • message: string

    The log message.

  • remarks?: string

    The optional log remarks.


endPlayback

public endPlaybackplayback: PlaybackStatus: void

Parameters


endScene

public endScenescene: Sceneunknown: void

Parameters


endThread

public endThreadthread: Thread: void

Parameters


errorToLog

public errorToLogerror: any: LogPayload

Parameters


finishScene

public finishScene(): void

Mark the current scene as ready to transition out.

Usually used together with transitions. When a scene is marked as finished, the transition will start but the scene generator will continue running.


getContext

public getContextoptions?: CanvasRenderingContext2DSettingscanvas: HTMLCanvasElement = ...: CanvasRenderingContext2D

Parameters


isProxyEnabled

public isProxyEnabled(): boolean

Check if the proxy is enabled via the plugin by checking for import.meta.env.VITE_MC_PROXY_ENABLED

The value can either be 'true' of 'false' (as strings) if present, or be undefined if not run from a vite context or run without the MC Plugin.


makeRef

public makeRefTObjectTKey extends stringnumbersymbolobject: TObjectkey: TKey: ReferenceReceiverTObject[TKey]

Type Parameters

Parameters


makeRefs

public makeRefsT extends public ()(): RefsPropertyT

Type Parameters

  • T extends public ()

range

public rangelength: number: number[]
public rangefrom: numberto: number: number[]
public rangefrom: numberto: numberstep: number: number[]

Create an array containing a range of numbers.

Examples

Parameters

  • length: number

    The length of the array.


startPlayback

public startPlaybackplayback: PlaybackStatus: void

Parameters


startScene

public startScenescene: Sceneunknown: void

Parameters


startThread

public startThreadthread: Thread: void

Parameters


useContext

public useContextcallback: public (): public ()

Provide a function to access the Context2D before the scene is rendered.

Parameters

  • callback: public ()

    The function that will be provided the context before render.


useContextAfter

public useContextAftercallback: public (): public ()

Provide a function to access the Context2D after the scene is rendered.

Parameters

  • callback: public ()

    The function that will be provided the context after render.


useDuration

public useDurationname: string: number

Register a time event and get its duration in seconds.

This can be used to better specify when an animation should start as well as how long this animation should take

Examples

Parameters

  • name: string

    The name of the event.


useLogger

public useLogger(): ConsoleLogger

usePlayback

public usePlayback(): PlaybackStatus

Get a reference to the playback status.


useRandom

public useRandom(): Random
public useRandomseed: numberfixed?: boolean: Random

Get the random number generator for the current scene.


useScene

public useScene(): Scene

Get a reference to the current scene.


useThread

public useThread(): Thread

Get a reference to the current thread.


useTime

public useTime(): number

Get the real time since the start of the animation.

The returned value accounts for offsets caused by functions such as waitFor.

Examples


viaProxy

public viaProxyurl: string: string

Route the given url through a local proxy.

Examples

Parameters