Skip to main content

@twick/canvas - v0.15.0

Table of contents

Classes

Functions

Type Aliases

Variables

Functions

addTextElement

addTextElement(«destructured»): Textbox<{ left: Position = x; top: Position = y; originX: "center" = "center"; originY: "center" = "center"; angle: number ; fontSize: number ; fontFamily: string ; fontStyle: string ; fontWeight: string ; fill: string ; opacity: number ; width: number ; splitByGrapheme: false = false; textAlign: "left" | "center" | "right" ; stroke: string ; strokeWidth: number ; backgroundColor: undefined | string ; shadow: undefined | Shadow }, SerializedTextboxProps, ITextEvents>

Add a text element to the canvas. Creates and configures a Fabric.js Textbox object with specified properties including position, styling, interactive controls, and text wrapping support.

Parameters

NameType
«destructured»Object
› elementCanvasElement
› indexnumber
› canvasCanvas
› canvasMetadataCanvasMetadata

Returns

Textbox<{ left: Position = x; top: Position = y; originX: "center" = "center"; originY: "center" = "center"; angle: number ; fontSize: number ; fontFamily: string ; fontStyle: string ; fontWeight: string ; fill: string ; opacity: number ; width: number ; splitByGrapheme: false = false; textAlign: "left" | "center" | "right" ; stroke: string ; strokeWidth: number ; backgroundColor: undefined | string ; shadow: undefined | Shadow }, SerializedTextboxProps, ITextEvents>

The configured Fabric.js Textbox object with text wrapping enabled

Example

const textElement = addTextElement({
element: { id: "text1", props: { text: "Hello", x: 100, y: 100, width: 200 } },
index: 1,
canvas: fabricCanvas,
canvasMetadata: { scaleX: 1, scaleY: 1, width: 800, height: 600 }
});

Defined in

components/elements.tsx:51


addCaptionElement

addCaptionElement(«destructured»): Textbox<{ left: Position = x; top: Position = y; originX: "center" = "center"; originY: "center" = "center"; angle: number ; fontSize: number ; fontFamily: string ; fill: string = resolvedFill; fontWeight: string | number ; stroke: string ; opacity: number ; width: number ; splitByGrapheme: false = false; textAlign: "left" | "center" | "right" ; shadow: Shadow ; strokeWidth: number }, SerializedTextboxProps, ITextEvents>

Add a caption element to the canvas based on provided props. Creates a Fabric.js Textbox with caption-specific styling including shadows, positioning, font properties, and text wrapping (same as text element).

Parameters

NameTypeDefault value
«destructured»Objectundefined
› elementCanvasElementundefined
› indexnumberundefined
› canvasCanvasundefined
› captionPropsCaptionPropsundefined
› canvasMetadataCanvasMetadataundefined
› lockAspectRatio?booleanfalse

Returns

Textbox<{ left: Position = x; top: Position = y; originX: "center" = "center"; originY: "center" = "center"; angle: number ; fontSize: number ; fontFamily: string ; fill: string = resolvedFill; fontWeight: string | number ; stroke: string ; opacity: number ; width: number ; splitByGrapheme: false = false; textAlign: "left" | "center" | "right" ; shadow: Shadow ; strokeWidth: number }, SerializedTextboxProps, ITextEvents>

The configured Fabric.js Textbox caption object with wrapping enabled

Example

const captionElement = addCaptionElement({
element: { id: "caption1", props: { text: "Caption", x: 100, y: 100, width: 200 } },
index: 3,
canvas: fabricCanvas,
captionProps: { font: { size: 24, family: "Arial" } },
canvasMetadata: { scaleX: 1, scaleY: 1, width: 800, height: 600 }
});

Defined in

components/elements.tsx:239


addVideoElement

addVideoElement(«destructured»): Promise<undefined | Group | FabricImage<Partial<ImageProps>, SerializedImageProps, ObjectEvents>>

Add a video frame as element into a Fabric.js image object and optionally groups it with a frame. Creates a video element by extracting a frame at the specified time and applying optional frame effects for enhanced visual presentation.

Parameters

NameType
«destructured»Object
› elementCanvasElement
› indexnumber
› canvasCanvas
› snapTimenumber
› canvasMetadataCanvasMetadata
› currentFrameEffect?FrameEffect

Returns

Promise<undefined | Group | FabricImage<Partial<ImageProps>, SerializedImageProps, ObjectEvents>>

A Fabric.js image object or a group with an image and frame

Example

const videoElement = await addVideoElement({
element: {
id: "video1",
props: { src: "video.mp4", x: 100, y: 100 }
},
index: 2,
canvas: fabricCanvas,
snapTime: 5.0,
canvasMetadata: { scaleX: 1, scaleY: 1, width: 800, height: 600 },
currentFrameEffect: { shape: "circle", radius: 50 }
});

Defined in

components/elements.tsx:380


addImageElement

addImageElement(«destructured»): Promise<undefined | Group | FabricImage<Partial<ImageProps>, SerializedImageProps, ObjectEvents>>

Add an image element to the canvas and optionally group it with a frame. Loads an image from URL and creates a Fabric.js image object with proper positioning, scaling, and optional frame effects.

Parameters

NameTypeDefault valueDescription
«destructured»Objectundefined-
› imageUrl?stringundefined-
› elementCanvasElementundefined-
› indexnumberundefined-
› canvasCanvasundefined-
› canvasMetadataCanvasMetadataundefined-
› currentFrameEffect?FrameEffectundefined-
› lockAspectRatio?booleantrueWhen true, resize keeps aspect ratio (uniform scaling). Default true for images.

Returns

Promise<undefined | Group | FabricImage<Partial<ImageProps>, SerializedImageProps, ObjectEvents>>

A Fabric.js image object or a group with an image and frame

Example

const imageElement = await addImageElement({
imageUrl: "https://example.com/image.jpg",
element: { id: "img1", props: { src: "image.jpg", width: 200, height: 150 } },
index: 4,
canvas: fabricCanvas,
canvasMetadata: { scaleX: 1, scaleY: 1, width: 800, height: 600 }
});

Defined in

components/elements.tsx:442


addRectElement

addRectElement(«destructured»): Rect<{ left: Position = x; top: Position = y; originX: "center" = "center"; originY: "center" = "center"; angle: number ; rx: number ; ry: number ; stroke: string ; strokeWidth: number ; fill: string ; opacity: number ; width: number ; height: number }, SerializedRectProps, ObjectEvents>

Add a rectangular element to the canvas. Creates a Fabric.js rectangle with specified properties including position, size, styling, and interactive controls.

Parameters

NameTypeDefault value
«destructured»Objectundefined
› elementCanvasElementundefined
› indexnumberundefined
› canvasCanvasundefined
› canvasMetadataCanvasMetadataundefined
› lockAspectRatio?booleanfalse

Returns

Rect<{ left: Position = x; top: Position = y; originX: "center" = "center"; originY: "center" = "center"; angle: number ; rx: number ; ry: number ; stroke: string ; strokeWidth: number ; fill: string ; opacity: number ; width: number ; height: number }, SerializedRectProps, ObjectEvents>

A Fabric.js Rect object configured with the specified properties

Example

const rectElement = addRectElement({
element: { id: "rect1", props: { width: 100, height: 50, x: 200, y: 150 } },
index: 6,
canvas: fabricCanvas,
canvasMetadata: { scaleX: 1, scaleY: 1, width: 800, height: 600 }
});

Defined in

components/elements.tsx:666


addBackgroundColor

addBackgroundColor(«destructured»): Rect<{ width: number = canvasMetadata.width; height: number = canvasMetadata.height; left: number ; top: number ; fill: string ; originX: "center" = "center"; originY: "center" = "center"; hasControls: false = false; hasBorders: false = false; selectable: false = false }, SerializedRectProps, ObjectEvents>

Add a background color to the canvas. Creates a full-canvas rectangle with the specified background color that serves as the base layer for other elements.

Parameters

NameType
«destructured»Object
› elementCanvasElement
› indexnumber
› canvasCanvas
› canvasMetadataCanvasMetadata

Returns

Rect<{ width: number = canvasMetadata.width; height: number = canvasMetadata.height; left: number ; top: number ; fill: string ; originX: "center" = "center"; originY: "center" = "center"; hasControls: false = false; hasBorders: false = false; selectable: false = false }, SerializedRectProps, ObjectEvents>

A Fabric.js Rect object configured with the specified properties

Example

const bgElement = addBackgroundColor({
element: { id: "bg1", backgoundColor: "#ffffff" },
index: 0,
canvas: fabricCanvas,
canvasMetadata: { scaleX: 1, scaleY: 1, width: 800, height: 600 }
});

Defined in

components/elements.tsx:783


registerCanvasHandler

registerCanvasHandler(handler): void

Parameters

NameType
handlerCanvasElementHandler

Returns

void

Defined in

controllers/element.controller.ts:50


getCanvasHandler

getCanvasHandler(name): CanvasElementHandler | undefined

Parameters

NameType
namestring

Returns

CanvasElementHandler | undefined

Defined in

controllers/element.controller.ts:54


createCanvas

createCanvas(«destructured»): Object

Creates and initializes a Fabric.js canvas with specified configurations. Sets up a canvas with proper scaling, background, and interaction settings based on the provided video and canvas dimensions.

Parameters

NameType
«destructured»CanvasProps

Returns

Object

Object containing the initialized canvas and its metadata

NameType
canvasCanvas
canvasMetadataCanvasMetadata

Example

const { canvas, canvasMetadata } = createCanvas({
videoSize: { width: 1920, height: 1080 },
canvasSize: { width: 800, height: 600 },
canvasRef: canvasElement,
backgroundColor: "#000000",
selectionBorderColor: "#2563eb"
});

Defined in

helpers/canvas.util.ts:33


reorderElementsByZIndex

reorderElementsByZIndex(canvas): void

Reorders elements on the canvas based on their zIndex property. Sorts all canvas objects by their zIndex and re-adds them to maintain proper layering order for visual elements.

Parameters

NameTypeDescription
canvasCanvasThe Fabric.js canvas instance

Returns

void

Example

reorderElementsByZIndex(canvas);
// Elements are now properly layered based on zIndex

Defined in

helpers/canvas.util.ts:143


convertToCanvasPosition

convertToCanvasPosition(x, y, canvasMetadata): Position

Converts a position from the video coordinate space to the canvas coordinate space. Applies scaling and centering transformations to map video coordinates to the corresponding canvas pixel positions.

Parameters

NameTypeDescription
xnumberX-coordinate in video space
ynumberY-coordinate in video space
canvasMetadataCanvasMetadataMetadata containing canvas scaling and dimensions

Returns

Position

Object containing the corresponding position in canvas space

Example

const canvasPos = convertToCanvasPosition(100, 200, canvasMetadata);
// canvasPos = { x: 450, y: 500 }

Defined in

helpers/canvas.util.ts:272


convertToVideoPosition

convertToVideoPosition(x, y, canvasMetadata, videoSize): Position

Converts a position from the canvas coordinate space to the video coordinate space. Applies inverse scaling and centering transformations to map canvas coordinates back to the corresponding video coordinate positions.

Parameters

NameTypeDescription
xnumberX-coordinate in canvas space
ynumberY-coordinate in canvas space
canvasMetadataCanvasMetadataMetadata containing canvas scaling and dimensions
videoSizeDimensionsDimensions of the video

Returns

Position

Object containing the corresponding position in video space

Example

const videoPos = convertToVideoPosition(450, 500, canvasMetadata, videoSize);
// videoPos = { x: 100, y: 200 }

Defined in

helpers/canvas.util.ts:331


getCurrentFrameEffect

getCurrentFrameEffect(item, seekTime): any

Retrieves the current frame effect for a given seek time. Searches through the item's frame effects to find the one that is active at the specified seek time based on start and end time ranges.

Parameters

NameTypeDescription
itemanyThe item containing frame effects
seekTimenumberThe current time to match against frame effects

Returns

any

The current frame effect active at the given seek time, or undefined if none found

Example

const currentEffect = getCurrentFrameEffect(videoElement, 5.5);
// Returns the frame effect active at 5.5 seconds, if any

Defined in

helpers/canvas.util.ts:374


useTwickCanvas

useTwickCanvas(«destructured»): Object

Custom hook to manage a Fabric.js canvas and associated operations. Provides functionality for canvas initialization, element management, and event handling for interactive canvas operations.

Parameters

NameTypeDefault value
«destructured»Objectundefined
› onCanvasReady?(canvas: Canvas) => voidundefined
› onCanvasOperation?(operation: string, data: any) => voidundefined
› enableShiftAxisLock?booleanfalse

Returns

Object

Object containing canvas-related functions and state

NameType
twickCanvasnull | Canvas
buildCanvas(props: BuildCanvasOptions) => void
resizeCanvas(canvasSize: ResizeCanvasOptions) => void
setBackgroundColor(color: string) => void
onVideoSizeChange(videoSize: Dimensions) => void
addWatermarkToCanvas(__namedParameters: AddWatermarkToCanvasOptions) => void
addElementToCanvas(options: AddElementToCanvasOptions) => Promise<void>
setCanvasElements(options: SetCanvasElementsOptions) => Promise<void>
bringToFront(elementId: string) => boolean
sendToBack(elementId: string) => boolean
bringForward(elementId: string) => boolean
sendBackward(elementId: string) => boolean

Example

const { twickCanvas, buildCanvas, addElementToCanvas } = useTwickCanvas({
onCanvasReady: (canvas) => console.log('Canvas ready:', canvas),
onCanvasOperation: (operation, data) => console.log('Operation:', operation, data)
});

Defined in

hooks/use-twick-canvas.ts:43

Type Aliases

CanvasProps

Ƭ CanvasProps: Object

Configuration properties for creating and initializing a canvas. Defines the video and canvas dimensions, styling options, and interaction settings.

Example

const canvasProps: CanvasProps = {
videoSize: { width: 1920, height: 1080 },
canvasSize: { width: 800, height: 600 },
canvasRef: canvasElement,
backgroundColor: "#000000",
selectionBorderColor: "#2563eb",
selectionLineWidth: 2,
uniScaleTransform: true,
enableRetinaScaling: true,
touchZoomThreshold: 10
};

Type declaration

NameTypeDescription
videoSizeDimensionsDimensions of the video content
canvasSizeDimensionsDimensions of the canvas element
canvasRefHTMLCanvasElement | stringReference to the HTML canvas element or selector string
backgroundColor?stringBackground color of the canvas
selectionBorderColor?stringBorder color for selected objects
selectionLineWidth?numberWidth of the selection border
uniScaleTransform?booleanEnsures uniform scaling of objects
enableRetinaScaling?booleanEnables retina scaling for higher DPI displays
touchZoomThreshold?numberThreshold for touch zoom interactions
lockAspectRatio?booleanDefault lock aspect ratio when resizing elements (uniform scaling). Can be overridden per element via props.lockAspectRatio.

Defined in

types.ts:28


CanvasMetadata

Ƭ CanvasMetadata: Object

Metadata about the canvas including dimensions and scaling factors. Contains calculated values for coordinate transformations between video and canvas spaces.

Example

const metadata: CanvasMetadata = {
width: 800,
height: 600,
aspectRatio: 1.33,
scaleX: 0.416,
scaleY: 0.556
};

Type declaration

NameTypeDescription
widthnumberWidth of the canvas in pixels
heightnumberHeight of the canvas in pixels
aspectRationumberAspect ratio of the canvas (width / height)
scaleXnumberHorizontal scaling factor from video to canvas
scaleYnumberVertical scaling factor from video to canvas

Defined in

types.ts:66


FrameEffect

Ƭ FrameEffect: Object

Frame effect configuration for canvas elements. Defines visual effects that can be applied to elements during specific time ranges.

Example

const frameEffect: FrameEffect = {
s: 0,
e: 5,
props: {
shape: "circle",
radius: 50,
rotation: 45,
framePosition: { x: 100, y: 100 },
frameSize: [200, 200]
}
};

Type declaration

NameTypeDescription
snumberStart time of the effect in seconds
enumberEnd time of the effect in seconds
props{ shape?: "circle" | "rect" ; radius?: number ; rotation?: number ; framePosition?: { x: number ; y: number } ; frameSize?: [number, number] }Effect properties and configuration
props.shape?"circle" | "rect"Shape type for the frame effect
props.radius?numberRadius for circular effects
props.rotation?numberRotation angle in degrees
props.framePosition?{ x: number ; y: number }Position of the frame effect
props.framePosition.xnumberX coordinate
props.framePosition.ynumberY coordinate
props.frameSize?[number, number]Size of the frame effect [width, height]

Defined in

types.ts:98


CanvasElement

Ƭ CanvasElement: Object

Canvas element configuration for various element types. Defines the structure for text, image, video, and other elements on the canvas.

Example

const canvasElement: CanvasElement = {
id: "element-1",
type: "text",
props: {
text: "Hello World",
x: 100,
y: 100,
fontSize: 48
},
s: 0,
e: 10,
frameEffects: [frameEffect]
};

Type declaration

NameTypeDescription
idstringUnique identifier for the element
typestringType of element (text, image, video, etc.)
propsCanvasElementPropsElement properties and styling
s?numberStart time of the element in seconds
e?numberEnd time of the element in seconds
t?stringText content for text elements
frameEffects?FrameEffect[]Array of frame effects applied to the element
timelineType?stringType of timeline element
backgoundColor?stringBackground color for the element
objectFit?"contain" | "cover" | "fill" | "none"Object fit mode for media elements
frame?{ size?: [number, number] ; rotation?: number ; scaleX?: number ; scaleY?: number ; stroke?: string ; lineWidth?: number ; radius?: number ; x: number ; y: number }Frame configuration for the element
frame.size?[number, number]Size of the frame [width, height]
frame.rotation?numberRotation angle in degrees
frame.scaleX?numberHorizontal scale factor
frame.scaleY?numberVertical scale factor
frame.stroke?stringStroke color
frame.lineWidth?numberStroke line width
frame.radius?numberCorner radius for rounded rectangles
frame.xnumberX coordinate
frame.ynumberY coordinate
zIndex?numberLayering order on the canvas (higher = on top). Updated by bring to front / send to back.

Defined in

types.ts:144


CanvasElementProps

Ƭ CanvasElementProps: Object

Properties for canvas elements including styling, positioning, and media attributes. Comprehensive type definition covering all possible element properties.

Example

const elementProps: CanvasElementProps = {
src: "image.jpg",
text: "Sample Text",
x: 100,
y: 100,
rotation: 45,
scaleX: 1.5,
scaleY: 1.5,
opacity: 0.8,
fontSize: 48,
fontFamily: "Arial",
fill: "#FFFFFF",
stroke: "#000000"
};

Type declaration

NameTypeDescription
src?stringSource URL for media elements
text?stringText content for text elements
rotation?numberRotation angle in degrees
scaleX?numberHorizontal scale factor
scaleY?numberVertical scale factor
size?[number, number]Size array [width, height]
x?numberX coordinate position
y?numberY coordinate position
radius?numberCorner radius for rounded shapes
opacity?numberOpacity value (0-1)
width?numberWidth in pixels
maxWidth?numberMaximum width in pixels
height?numberHeight in pixels
textWrap?booleanWhether text should wrap
textAlign?"left" | "center" | "right"Text alignment
pos?{ x: number ; y: number }Position object with x, y coordinates
pos.xnumberX coordinate
pos.ynumberY coordinate
shadow?{ color: string ; blur: number ; offsetX: number ; offsetY?: number }Shadow configuration
shadow.colorstringShadow color
shadow.blurnumberShadow blur radius
shadow.offsetXnumberShadow X offset
shadow.offsetY?numberShadow Y offset
font?{ family?: string ; size?: number ; style?: string ; weight?: string }Font configuration object
font.family?stringFont family
font.size?numberFont size in pixels
font.style?stringFont style
font.weight?stringFont weight
fontFamily?stringFont family name
fontSize?numberFont size in pixels
fontStyle?stringFont style (normal, italic, etc.)
fontWeight?stringFont weight (normal, bold, etc.)
fill?stringFill color
stroke?stringStroke color
strokeWidth?numberStroke width
lineWidth?numberLine width for strokes
shadowColor?stringShadow color
shadowBlur?numberShadow blur radius
shadowOffset?[number, number]Shadow offset [x, y]
backgroundColor?stringBackground color for text elements
backgroundOpacity?numberBackground opacity for text elements (0-1)
playbackRate?numberPlayback rate for video elements
time?numberCurrent time for video elements
lockAspectRatio?booleanWhen true, resize preserves aspect ratio (uniform scaling). When false, allows non-uniform scale.

Defined in

types.ts:212


CaptionProps

Ƭ CaptionProps: Object

Properties specific to caption elements. Defines styling and positioning for caption text with background and highlight options.

Example

const captionProps: CaptionProps = {
font: {
family: "Arial",
size: 48,
fill: "#FFFFFF"
},
pos: {
x: 100,
y: 100
},
color: {
text: "#FFFFFF",
background: "#000000",
highlight: "#FFFF00"
}
};

Type declaration

NameTypeDescription
font?{ family?: string ; size?: number ; fill?: string ; weight?: string ; style?: string }Font configuration for caption text
font.family?stringFont family
font.size?numberFont size in pixels
font.fill?stringText fill color
font.weight?stringFont weight
font.style?stringFont style
opacity?numberOpacity value (0-1)
stroke?stringStroke color
lineWidth?numberStroke width
shadowColor?stringShadow color
shadowBlur?numberShadow blur radius
shadowOffset?[number, number]Shadow offset [x, y]
xnumberX coordinate
ynumberY coordinate
colors?{ text?: string ; highlight?: string ; bgColor?: string }Color configuration for caption styling (alias: use when from track/element)
colors.text?stringText color
colors.highlight?stringHighlight color
colors.bgColor?stringBackground color
color?{ text?: string ; background?: string ; highlight?: string }Color configuration for caption styling (alias: use when from canvas)
color.text?stringText color
color.background?stringBackground color
color.highlight?stringHighlight color
applyToAll?boolean-

Defined in

types.ts:330


BuildCanvasOptions

Ƭ BuildCanvasOptions: CanvasProps & { forceBuild?: boolean }

Options for buildCanvas from useTwickCanvas. CanvasProps plus optional forceBuild to recreate the canvas even when dimensions match.

Defined in

types.ts:385


AddElementToCanvasOptions

Ƭ AddElementToCanvasOptions: Object

Options for addElementToCanvas from useTwickCanvas.

Type declaration

NameTypeDescription
elementCanvasElementThe canvas element to add
indexnumberZ-index / layer order
reorder?booleanWhether to reorder canvas objects by zIndex after adding (default true)
seekTime?numberSeek time for video/frame snap (optional)
captionProps?anyCaption styling (optional)
lockAspectRatio?booleanWhen true, element resize keeps aspect ratio (optional)

Defined in

types.ts:393


SetCanvasElementsOptions

Ƭ SetCanvasElementsOptions: Object

Options for setCanvasElements from useTwickCanvas.

Type declaration

NameTypeDescription
elementsCanvasElement[]Canvas elements to set
watermark?CanvasElementOptional watermark element
seekTime?numberSeek time for video/frame snap (default 0)
captionProps?anyCaption styling (optional)
cleanAndAdd?booleanWhen true, clear canvas before adding (default false)
lockAspectRatio?booleanWhen true, element resize keeps aspect ratio (optional)

Defined in

types.ts:411


AddWatermarkToCanvasOptions

Ƭ AddWatermarkToCanvasOptions: Object

Options for addWatermarkToCanvas from useTwickCanvas.

Type declaration

NameTypeDescription
elementCanvasElementThe watermark canvas element to add

Defined in

types.ts:429


ResizeCanvasOptions

Ƭ ResizeCanvasOptions: Object

Options for resizeCanvas from useTwickCanvas.

Type declaration

NameTypeDescription
canvasSizeDimensionsNew canvas dimensions (e.g. from ResizeObserver)
videoSize?DimensionsOptional video dimensions; defaults to current video size ref

Defined in

types.ts:437


CanvasElementAddParams

Ƭ CanvasElementAddParams: Object

Parameters passed to a canvas element handler when adding an element.

Type declaration

NameTypeDescription
elementCanvasElement-
indexnumber-
canvasCanvas-
canvasMetadataCanvasMetadata-
seekTime?number-
captionProps?CaptionProps | null-
elementFrameMapRef?{ current: Record<string, FrameEffect | undefined> }-
elementFrameMapRef.currentRecord<string, FrameEffect | undefined>-
getCurrentFrameEffect?(item: CanvasElement, seekTime: number) => FrameEffect | undefined-
watermarkPropsRef?{ current: any }Used by watermark handler to store props for WATERMARK_UPDATED
watermarkPropsRef.currentany-
lockAspectRatio?booleanWhen true, resize keeps aspect ratio (uniform scaling). Overridable by element.props.lockAspectRatio.

Defined in

types.ts:447


CanvasElementUpdateContext

Ƭ CanvasElementUpdateContext: Object

Context passed when updating element state from a Fabric object (e.g. after transform).

Type declaration

NameType
canvasMetadataCanvasMetadata
videoSize{ width: number ; height: number }
videoSize.widthnumber
videoSize.heightnumber
elementFrameMapRef{ current: Record<string, FrameEffect | undefined> }
elementFrameMapRef.currentRecord<string, FrameEffect | undefined>
captionPropsRef{ current: CaptionProps | null }
captionPropsRef.currentCaptionProps | null
watermarkPropsRef{ current: any }
watermarkPropsRef.currentany

Defined in

types.ts:465


CanvasElementUpdateResult

Ƭ CanvasElementUpdateResult: Object

Result of updateFromFabricObject; tells the hook which operation to emit. When operation is CAPTION_PROPS_UPDATED, payload is { element, props }. When operation is WATERMARK_UPDATED, payload is WatermarkUpdatePayload.

Type declaration

NameType
elementCanvasElement
operation?string
payload?any

Defined in

types.ts:478


WatermarkUpdatePayload

Ƭ WatermarkUpdatePayload: Object

Canonical payload for WATERMARK_UPDATED. Matches timeline WatermarkJSON shape so video-editor can apply via setWatermark() and panel can update type/props.

Type declaration

NameType
position{ x: number ; y: number }
position.xnumber
position.ynumber
rotation?number
opacity?number
props?Record<string, unknown>

Defined in

types.ts:488


CanvasElementHandler

Ƭ CanvasElementHandler: Object

Handler for a canvas element type. Register with ElementController for scalable dispatch.

Type declaration

NameType
namestring
add(params: CanvasElementAddParams) => Promise<void>
updateFromFabricObject?(object: any, element: CanvasElement, context: CanvasElementUpdateContext) => CanvasElementUpdateResult | null

Defined in

types.ts:498

Variables

disabledControl

Const disabledControl: Control

Disabled control for canvas elements. Creates a control that appears disabled and doesn't perform any actions when interacted with. Useful for showing non-interactive control points.

Example

import { disabledControl } from '@twick/canvas';

// Apply to a canvas object
object.setControlsVisibility({
mt: false, // Disable top control
mb: false, // Disable bottom control
ml: false, // Disable left control
mr: false, // Disable right control
bl: disabledControl, // Use disabled control for bottom-left
});

Defined in

components/element-controls.tsx:22


rotateControl

Const rotateControl: Control

Rotation control for canvas elements. Creates a control that allows rotation of canvas objects with snapping functionality for precise angle adjustments.

Example

import { rotateControl } from '@twick/canvas';

// Apply to a canvas object
object.setControlsVisibility({
mtr: rotateControl, // Use custom rotate control for top-right
});

// Enable rotation
object.set({
hasRotatingPoint: true,
lockRotation: false
});

Defined in

components/element-controls.tsx:71


elementController

Const elementController: ElementController

Defined in

controllers/element.controller.ts:33


CANVAS_OPERATIONS

Const CANVAS_OPERATIONS: Object

Canvas operation constants for tracking canvas state changes. Defines the different types of operations that can occur on canvas elements.

Example

import { CANVAS_OPERATIONS } from '@twick/canvas';

function handleCanvasOperation(operation) {
switch (operation) {
case CANVAS_OPERATIONS.ITEM_ADDED:
console.log('New item added to canvas');
break;
case CANVAS_OPERATIONS.ITEM_UPDATED:
console.log('Item updated on canvas');
break;
}
}

Type declaration

NameTypeDescription
ITEM_SELECTEDstringAn item has been selected on the canvas
ITEM_UPDATEDstringAn item has been updated/modified on the canvas
ITEM_DELETEDstringAn item has been deleted from the canvas
ITEM_ADDEDstringA new item has been added to the canvas
ITEM_GROUPEDstringItems have been grouped together
ITEM_UNGROUPEDstringItems have been ungrouped
CAPTION_PROPS_UPDATEDstringCaption properties have been updated
WATERMARK_UPDATEDstringWatermark has been updated
ADDED_NEW_ELEMENTstringA new element was added via drop on canvas; payload is { element }
Z_ORDER_CHANGEDstringZ-order changed (bring to front / send to back). Payload is { elementId, direction }. Timeline should reorder tracks.

Defined in

helpers/constants.ts:97


ELEMENT_TYPES

Const ELEMENT_TYPES: Object

Element type constants for canvas elements. Defines the different types of elements that can be added to the canvas.

Example

import { ELEMENT_TYPES } from '@twick/canvas';

if (element.type === ELEMENT_TYPES.TEXT) {
// Handle text element
} else if (element.type === ELEMENT_TYPES.IMAGE) {
// Handle image element
}

Type declaration

NameTypeDescription
TEXT"text"Text element type
CAPTION"caption"Caption element type
IMAGE"image"Image element type
VIDEO"video"Video element type
RECT"rect"Rectangle element type
CIRCLE"circle"Circle element type
ICON"icon"Icon element type
ARROW"arrow"Arrow annotation element type
LINE"line"Line annotation / shape element type
BACKGROUND_COLOR"backgroundColor"Background color element type
EFFECT"effect"Global / adjustment-layer style effect element

Defined in

helpers/constants.ts:135