Skip to main content

utils

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

General utilities and helper functions.

Classes

Interfaces

Type Aliases

ReferenceArray

type ReferenceArrayT = T[]ReferenceT

Type Parameters


ReferenceMap

type ReferenceMapT = MapstringReferenceTRecordstringReferenceTpublic ()

Type Parameters


RefsProperty

type RefsPropertyTValue = TValue extends config: refs?: infer TReference => void ? 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


createRefArray

public createRefArrayT(): ReferenceArrayT

Create an array of references.

The returned object is both an array and a reference that can be passed directly to the ref property of a node.

Examples

Type Parameters


createRefMap

public createRefMapT(): ReferenceMapT

Create a group of references.

The returned object lets you easily create multiple references to the same type without initializing them individually.

You can retrieve references by accessing the object's properties. If the reference for a given property does not exist, it will be created automatically.

Examples

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: ...args: TArgs => TReturnmessage: stringremarks?: string: ...args: TArgs => TReturn

Mark the given function as deprecated.

Type Parameters

Parameters


endPlayback

public endPlaybackplayback: PlaybackStatus: void

Parameters


endScene

public endScenescene: Sceneunknown: void

Parameters


endThread

public endThreadthread: Thread: void

Parameters


errorToLog

public errorToLogerror: any: LogPayload

Parameters


experimentalLog

public experimentalLogmessage: stringremarks?: string: 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 config: refs?: any => void(): RefsPropertyT

Type Parameters

  • T extends config: refs?: any => void

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: ctx: CanvasRenderingContext2D => void: () => void

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

Parameters


useContextAfter

public useContextAftercallback: ctx: CanvasRenderingContext2D => void: () => void

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

Parameters


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