Skip to main content

utils

import {...} from "@wangyaoshen/locus-core/lib/utils";

General utilities and helper functions.

Classes

Interfaces

Type Aliases



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 capitalizevalue: T: CapitalizeT

Parameters


createRef

public createRef(): ReferenceT

createRefArray

public createRefArray(): 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


createRefMap

public createRefMap(): 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


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

Mark the given function as deprecated.

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

public endScenescene: Scene: 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 makeRefobject: TObjectkey: TKey: ReferenceReceiverTObject[TKey]

Parameters


makeRefs

public makeRefs(): RefsPropertyT

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: Scene: 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(): LoggerConsole

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 flow.waitFor.

Examples


viaProxy

public viaProxyurl: string: string

Route the given url through a local proxy.

Examples

Parameters