@mocanvas/editor · class
declare class OverlayManager extends EditorManagerThe registry of canvas overlays.
v5 draws the brush, the scribbles, the snap lines, the handles and the shape indicators into one 2D canvas above the scene rather than as React elements. This manager is what owns those painters: it holds the utils, decides the order they paint in, and answers which overlay the pointer is over — the thing a tool needs in order to let a click land on a handle rather than on the shape behind it.
Reach it as editor.overlays. Utils are ordinary OverlayUtil
subclasses; register them at construction or with register.
Methods · 14
constructor(editor: Editor, utils?: readonly TLAnyOverlayUtilConstructor[])dispose(): voidgetActiveOverlayEntries(): OverlayEntry[]The same, paired with the util each one came from.
getCurrentOverlays(): TLOverlay[]The overlays that want drawing right now, back to front.
A util that says it is not active contributes nothing, and one that names no overlays contributes a single implicit overlay with its own type as the id — enough for a util that only paints and is never pointed at.
getHoveredOverlay(): TLOverlay | undefinedThe hovered overlay, or undefined when nothing is hovered.
getHoveredOverlayId(): string | nullId of the hovered overlay, or null.
getOverlayAtPoint(point: VecLike, margin?: number): OverlayEntry | undefinedThe topmost overlay under a page-space point, or undefined.
Front-to-back, so the overlay painted last is the one that answers — the same rule the eye applies.
getOverlayGeometry(overlay: TLOverlay): Geometry2d | undefinedThe geometry an overlay can be pointed at through, if it has any.
getOverlayUtilsInZOrder(): OverlayUtil<Editor>[]Every util, back to front. Painting in this order and hit-testing in the reverse of it is what makes the topmost overlay the one you click.
registerUtil(Util: TLAnyOverlayUtilConstructor): OverlayUtil<Editor>Add an overlay util. Registering a type that is already present replaces
it — which is how an app overrides one of the built-ins — and disposes the
one it displaced.
render(ctx: CanvasRenderingContext2D): voidPaint every active overlay into ctx, back to front.
ctx arrives in screen space; applying the camera is each util's own job,
because some overlays live in screen space (a handle, a brush outline) and
some in page space (a shape indicator).
renderMinimap(ctx: CanvasRenderingContext2D): voidThe minimap pass: only utils that opt in by implementing renderMinimap.
setHoveredOverlay(overlay: TLOverlay | string | null): thisSet (or clear, with null) the hovered overlay.
unregisterUtil(type: string): voidRemove an overlay util by type.
Properties · 1
getOverlayUtil<U extends OverlayUtil<Editor> = OverlayUtil<Editor>>(type: string): U | undefinedThe util registered under type, or undefined.
Mentioned here
mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.