Table of contents
abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {}

Constructor

Constructs a new instance of the ShapeUtil class

Parameters
NameDescription

editor

Editor

Properties

migrations

static migrations?: LegacyMigrations | MigrationSequence | TLPropsMigrations

props

static props?: RecordProps<TLUnknownShape>

type

The type of the shape util, which should match the shape's type.

static type: string

canBeLaidOut

Whether the shape participates in stacking, aligning, and distributing.

canBeLaidOut: TLShapeUtilFlag<Shape>

canCrop

Whether the shape can be cropped.

canCrop: TLShapeUtilFlag<Shape>

canEdit

Whether the shape can be double clicked to edit.

canEdit: TLShapeUtilFlag<Shape>

canEditInReadOnly

Whether the shape can be edited in read-only mode.

canEditInReadOnly: TLShapeUtilFlag<Shape>

canResize

Whether the shape can be resized.

canResize: TLShapeUtilFlag<Shape>

canScroll

Whether the shape can be scrolled while editing.

canScroll: TLShapeUtilFlag<Shape>

canSnap

Whether the shape can be snapped to by another shape.

canSnap: TLShapeUtilFlag<Shape>

editor

editor: Editor

hideResizeHandles

Whether the shape should hide its resize handles when selected.

hideResizeHandles: TLShapeUtilFlag<Shape>

hideRotateHandle

Whether the shape should hide its rotation handles when selected.

hideRotateHandle: TLShapeUtilFlag<Shape>

hideSelectionBoundsBg

Whether the shape should hide its selection bounds background when selected.

hideSelectionBoundsBg: TLShapeUtilFlag<Shape>

hideSelectionBoundsFg

Whether the shape should hide its selection bounds foreground when selected.

hideSelectionBoundsFg: TLShapeUtilFlag<Shape>

isAspectRatioLocked

Whether the shape's aspect ratio is locked.

isAspectRatioLocked: TLShapeUtilFlag<Shape>

onBeforeCreate

A callback called just before a shape is created. This method provides a last chance to modify the created shape.

onBeforeCreate?: TLOnBeforeCreateHandler<Shape>
Example
onBeforeCreate = (next) => {
  return { ...next, x: next.x + 1 }
}
Parameters
NameDescription

next

The next shape.


onBeforeUpdate

A callback called just before a shape is updated. This method provides a last chance to modify the updated shape.

onBeforeUpdate?: TLOnBeforeUpdateHandler<Shape>
Example
onBeforeUpdate = (prev, next) => {
  if (prev.x === next.x) {
    return { ...next, x: next.x + 1 }
  }
}
Parameters
NameDescription

prev

The previous shape.

next

The next shape.


onChildrenChange

A callback called when a shape's children change.

onChildrenChange?: TLOnChildrenChangeHandler<Shape>
Parameters
NameDescription

shape

The shape.


onClick

A callback called when a shape is clicked.

onClick?: TLOnClickHandler<Shape>
Parameters
NameDescription

shape

The shape.


onDoubleClick

A callback called when a shape is double clicked.

onDoubleClick?: TLOnDoubleClickHandler<Shape>
Parameters
NameDescription

shape

The shape.


onDoubleClickEdge

A callback called when a shape's edge is double clicked.

onDoubleClickEdge?: TLOnDoubleClickHandler<Shape>
Parameters
NameDescription

shape

The shape.


onDoubleClickHandle

A callback called when a shape's handle is double clicked.

onDoubleClickHandle?: TLOnDoubleClickHandleHandler<Shape>
Parameters
NameDescription

shape

The shape.

handle

The handle that is double-clicked.


onDragShapesOut

A callback called when some other shapes are dragged out of this one.

onDragShapesOut?: TLOnDragHandler<Shape>
Parameters
NameDescription

shape

The shape.

shapes

The shapes that are being dragged out.


onDragShapesOver

A callback called when some other shapes are dragged over this one.

onDragShapesOver?: TLOnDragHandler<Shape>
Example
onDragShapesOver = (shape, shapes) => {
  this.editor.reparentShapes(shapes, shape.id)
}
Parameters
NameDescription

shape

The shape.

shapes

The shapes that are being dragged over this one.


onDropShapesOver

A callback called when some other shapes are dropped over this one.

onDropShapesOver?: TLOnDragHandler<Shape>
Parameters
NameDescription

shape

The shape.

shapes

The shapes that are being dropped over this one.


onEditEnd

A callback called when a shape finishes being editing.

onEditEnd?: TLOnEditEndHandler<Shape>
Parameters
NameDescription

shape

The shape.


onHandleDrag

A callback called when a shape's handle changes.

onHandleDrag?: TLOnHandleDragHandler<Shape>
Parameters
NameDescription

shape

The current shape.

info

An object containing the handle and whether the handle is 'precise' or not.


onResize

A callback called when a shape changes from a resize.

onResize?: TLOnResizeHandler<Shape>
Parameters
NameDescription

shape

The shape at the start of the resize.

info

Info about the resize.


onResizeEnd

A callback called when a shape finishes resizing.

onResizeEnd?: TLOnResizeEndHandler<Shape>
Parameters
NameDescription

initial

The shape at the start of the resize.

current

The current shape.


onResizeStart

A callback called when a shape starts being resized.

onResizeStart?: TLOnResizeStartHandler<Shape>
Parameters
NameDescription

shape

The shape.


onRotate

A callback called when a shape changes from a rotation.

onRotate?: TLOnRotateHandler<Shape>
Parameters
NameDescription

initial

The shape at the start of the rotation.

current

The current shape.


onRotateEnd

A callback called when a shape finishes rotating.

onRotateEnd?: TLOnRotateEndHandler<Shape>
Parameters
NameDescription

initial

The shape at the start of the rotation.

current

The current shape.


onRotateStart

A callback called when a shape starts being rotated.

onRotateStart?: TLOnRotateStartHandler<Shape>
Parameters
NameDescription

shape

The shape.


onTranslate

A callback called when a shape changes from a translation.

onTranslate?: TLOnTranslateHandler<Shape>
Parameters
NameDescription

initial

The shape at the start of the translation.

current

The current shape.


onTranslateEnd

A callback called when a shape finishes translating.

onTranslateEnd?: TLOnTranslateEndHandler<Shape>
Parameters
NameDescription

initial

The shape at the start of the translation.

current

The current shape.


onTranslateStart

A callback called when a shape starts being translated.

onTranslateStart?: TLOnTranslateStartHandler<Shape>
Parameters
NameDescription

shape

The shape.


Methods

canBind()

Whether the shape can be bound to. See TLShapeUtilCanBindOpts for details.

canBind(opts: TLShapeUtilCanBindOpts<Shape>): boolean
Parameters
NameDescription

opts

TLShapeUtilCanBindOpts<Shape>
Returns
boolean

canDropShapes()

Get whether the shape can receive children of a given type.

canDropShapes(shape: Shape, shapes: TLShape[]): boolean
Parameters
NameDescription

shape

Shape

The shape type.

shapes

TLShape[]

The shapes that are being dropped.

Returns
boolean

canReceiveNewChildrenOfType()

Get whether the shape can receive children of a given type.

canReceiveNewChildrenOfType(shape: Shape, type: TLShape['type']): boolean
Parameters
NameDescription

shape

Shape

type

TLShape['type']

The shape type.

Returns
boolean

component()

Get a JSX element for the shape (as an HTML element).

abstract component(shape: Shape): any
Parameters
NameDescription

shape

Shape

The shape.

Returns
any

getBoundsSnapGeometry()

Get the geometry to use when snapping to this this shape in translate/resize operations. See BoundsSnapGeometry for details.

getBoundsSnapGeometry(shape: Shape): BoundsSnapGeometry
Parameters
NameDescription

shape

Shape
Returns
BoundsSnapGeometry

getCanvasSvgDefs()

Return elements to be added to the <defs> section of the canvases SVG context. This can be used to define SVG content (e.g. patterns & masks) that can be referred to by ID from svg elements returned by component.

Each def should have a unique key. If multiple defs from different shapes all have the same key, only one will be used.

getCanvasSvgDefs(): TLShapeUtilCanvasSvgDef[]

getDefaultProps()

Get the default props for a shape.

abstract getDefaultProps(): Shape['props']

getGeometry()

Get the shape's geometry.

abstract getGeometry(shape: Shape): Geometry2d
Parameters
NameDescription

shape

Shape

The shape.

Returns
Geometry2d

getHandles()

Get an array of handle models for the shape. This is an optional method.

getHandles?(shape: Shape): TLHandle[]
Example
util.getHandles?.(myShape)
Parameters
NameDescription

shape

Shape

The shape.

Returns
TLHandle[]

getHandleSnapGeometry()

Get the geometry to use when snapping handles to this shape. See HandleSnapGeometry for details.

getHandleSnapGeometry(shape: Shape): HandleSnapGeometry
Parameters
NameDescription

shape

Shape
Returns
HandleSnapGeometry

getInterpolatedProps()

Get the interpolated props for an animating shape. This is an optional method.

getInterpolatedProps?(
  startShape: Shape,
  endShape: Shape,
  progress: number
): Shape['props']
Example
util.getInterpolatedProps?.(startShape, endShape, t)
Parameters
NameDescription

startShape

Shape

The initial shape.

endShape

Shape

The initial shape.

progress

number

The normalized progress between zero (start) and 1 (end).

Returns
Shape['props']

indicator()

Get JSX describing the shape's indicator (as an SVG element).

abstract indicator(shape: Shape): any
Parameters
NameDescription

shape

Shape

The shape.

Returns
any

toBackgroundSvg()

Get the shape's background layer as an SVG object.

toBackgroundSvg?(
  shape: Shape,
  ctx: SvgExportContext
): null | Promise<null | ReactElement> | ReactElement
Parameters
NameDescription

shape

Shape

The shape.

ctx

SvgExportContext

ctx - The export context for the SVG - used for adding e.g. <def>s

Returns
null | Promise<null | ReactElement> | ReactElement

An SVG element.


toSvg()

Get the shape as an SVG object.

toSvg?(
  shape: Shape,
  ctx: SvgExportContext
): null | Promise<null | ReactElement> | ReactElement
Parameters
NameDescription

shape

Shape

The shape.

ctx

SvgExportContext

The export context for the SVG - used for adding e.g. <def>s

Returns
null | Promise<null | ReactElement> | ReactElement

An SVG element.


ScribbleManagerSnapManager