utils
import {...} from "@motion-canvas/core/lib/utils";
General utilities and helper functions.
Classes
Interfaces
Type Aliases
ReferenceArray
Type Parameters
ReferenceMap
Type Parameters
RefsProperty
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
name: string
capitalize
Type Parameters
T extends string
Parameters
createRef
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
payload: any
The payload to log
deprecate
Mark the given function as deprecated.
Type Parameters
Parameters
fn: ...args: TArgs => TReturn
The function to deprecate.
message: string
The log message.
remarks?: string
The optional log remarks.
endPlayback
public endPlaybackplayback: PlaybackStatus: void
Parameters
endScene
Parameters
endThread
Parameters
errorToLog
public errorToLogerror: any: LogPayload
Parameters
error: any
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
options?: CanvasRenderingContext2DSettings
canvas: HTMLCanvasElement = ...
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
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[]
Create an array containing a range of numbers.
Examples
Parameters
length: number
The length of the array.
startPlayback
public startPlaybackplayback: PlaybackStatus: void
Parameters
startScene
Parameters
startThread
Parameters
useContext
public useContextcallback: ctx: CanvasRenderingContext2D => void: () => void
Provide a function to access the Context2D before the scene is rendered.
Parameters
callback: ctx: CanvasRenderingContext2D => void
The function that will be provided the context before render.
useContextAfter
public useContextAftercallback: ctx: CanvasRenderingContext2D => void: () => void
Provide a function to access the Context2D after the scene is rendered.
Parameters
callback: ctx: CanvasRenderingContext2D => void
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
usePlayback
public usePlayback(): PlaybackStatus
Get a reference to the playback status.
useRandom
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
url: string