Skip to main content

Tools

This is the API reference for all drawing tool classes and tool configurations in Kritzel. Every tool handles user interactions on the canvas and can be registered and configured via the editor.

Base Tool​

KritzelBaseTool is the abstract base class for all tools in Kritzel. All specific tool implementations extend this class and inherit its properties and lifecycle hooks.

Properties​

PropertyTypeDescription
classstringIdentifier used for object serialization and deserialization
toolTypeKritzelToolTypeType key identifying the tool type across builds ('base', 'selection', 'brush', 'line', 'shape', 'text', 'image', 'eraser')
namestringHuman-readable name of the tool

Methods​

onActivate​

Called when the tool becomes the active tool.

onActivate()

onDeactivate​

Called when the tool is deactivated.

onDeactivate()

handlePointerDown​

Handles pointer down events (mouse click, touch start, pen down).

handlePointerDown(event: PointerEvent)

handlePointerMove​

Handles pointer move events (mouse move, touch move, pen move).

handlePointerMove(event: PointerEvent)

handlePointerUp​

Handles pointer up events (mouse release, touch end, pen up).

handlePointerUp(event: PointerEvent)

handleWheel​

Handles mouse wheel events for zooming or panning.

handleWheel(event: WheelEvent)

serialize​

Serializes the tool state to a plain object.

serialize()

deserialize​

Restores the tool state from a serialized object.

deserialize(object: any)

Selection Tool​

KritzelSelectionTool enables selecting, moving, resizing, and rotating objects on the canvas. It manages selection handles, multi-selection bounding boxes, and object transformations.

Properties​

PropertyTypeDescription
toolType'selection'Type identifier for the selection tool
selectionHandlerKritzelSelectionHandlerHandler for selection box and multi-select logic
moveHandlerKritzelMoveHandlerHandler for dragging and moving selected objects
resizeHandlerKritzelResizeHandlerHandler for resizing selected objects
rotationHandlerKritzelRotationHandlerHandler for rotating selected objects
hoverHandlerKritzelHoverHandlerHandler for object hover highlighting
lineHandleHandlerKritzelLineHandleHandlerHandler for manipulating line endpoint anchors
paletteThemeAwareColor[]Active color palette available for modifying selected objects

Methods​

hasSelection​

Checks if any objects are currently selected.

hasSelection()

getSelectedObjects​

Returns an array of currently selected objects.

getSelectedObjects()

Brush Tool​

KritzelBrushTool handles freehand drawing on the canvas, creating vector KritzelPath objects as the pointer moves.

Properties​

PropertyTypeDescription
toolType'brush'Type identifier for the brush tool
colorThemeAwareColorStroke color of the brush
sizenumberStroke width in pixels
opacitynumberOpacity of the stroke (0–1)
paletteThemeAwareColor[]Available color palette presets
sizesnumber[]Available stroke size presets

Configuration​

Toolbar items can configure initial settings for the brush tool using KritzelBrushToolConfig:

PropertyTypeDescription
colorThemeAwareColorInitial stroke color
sizenumberInitial stroke size in pixels
opacitynumberOptional initial opacity (0–1)
paletteThemeAwareColor[]Color palette options shown in tool configuration
sizesnumber[]Optional stroke size presets

Line Tool​

KritzelLineTool creates straight or curved KritzelLine objects with optional arrowheads by dragging from a start point to an end point.

Properties​

PropertyTypeDescription
toolType'line'Type identifier for the line tool
colorThemeAwareColorLine stroke color
sizenumberLine stroke width in pixels
opacitynumberLine opacity (0–1)
paletteThemeAwareColor[]Available color palette presets
sizesnumber[]Available line stroke size presets
arrowsLineArrowConfigArrowhead configurations for start and end points

Configuration​

Toolbar items configure initial line settings using KritzelLineToolConfig:

PropertyTypeDescription
colorThemeAwareColorInitial line stroke color
sizenumberInitial stroke width in pixels
opacitynumberOptional initial opacity (0–1)
paletteThemeAwareColor[]Color palette options
sizesnumber[]Optional stroke size presets
arrowsLineArrowConfigOptional initial arrowhead styles ('triangle', 'open', 'diamond', 'circle')

Shape Tool​

KritzelShapeTool creates geometric KritzelShape objects (rectangles, ellipses, triangles) by dragging across the canvas.

Properties​

PropertyTypeDescription
toolType'shape'Type identifier for the shape tool
shapeTypeShapeTypeActive shape geometry (Rectangle, Ellipse, Triangle)
fillColorThemeAwareColorShape background fill color
strokeColorThemeAwareColorShape border stroke color
strokeWidthnumberBorder stroke width in pixels
opacitynumberShape opacity (0–1)
fontFamilystringFont family for optional embedded text
fontSizenumberFont size in points for embedded text
fontColorThemeAwareColorFont color for embedded text
paletteThemeAwareColor[]Available color palette presets
sizesnumber[]Available border width presets

Configuration​

Toolbar items configure initial shape settings using KritzelShapeToolConfig:

PropertyTypeDescription
shapeTypeShapeTypeInitial shape type (Rectangle, Ellipse, Triangle)
fillColorThemeAwareColorInitial fill color
strokeColorThemeAwareColorInitial stroke color
strokeWidthnumberInitial stroke width in pixels
opacitynumberOptional initial opacity (0–1)
fontColorThemeAwareColorInitial font color for embedded text
fontSizenumberInitial font size for embedded text
fontFamilystringInitial font family for embedded text
paletteThemeAwareColor[]Color palette options
sizesnumber[]Optional stroke width presets

Text Tool​

KritzelTextTool places and edits rich text KritzelText objects on the canvas using an inline ProseMirror editor.

Properties​

PropertyTypeDescription
toolType'text'Type identifier for the text tool
fontFamilystringActive font family name
fontSizenumberActive font size in points
fontColorThemeAwareColorActive font color
opacitynumberText opacity (0–1)
paletteThemeAwareColor[]Available font color palette presets
sizesnumber[]Available font size presets

Configuration​

Toolbar items configure initial text tool settings using KritzelTextToolConfig:

PropertyTypeDescription
colorThemeAwareColorInitial font color
sizenumberInitial font size in points
opacitynumberOptional initial opacity (0–1)
fontFamilystringInitial font family name
availableFontsKritzelFontRegistration[]Optional array of registered fonts available in the tool UI
paletteThemeAwareColor[]Color palette options
sizesnumber[]Optional font size presets

Image Tool​

KritzelImageTool handles uploading and inserting raster KritzelImage objects onto the canvas via a native file picker dialog.

Properties​

PropertyTypeDescription
toolType'image'Type identifier for the image tool
fileInputHTMLInputElement | nullHidden HTML file input element used to select image files
maxCompressionSizenumberMaximum width/height dimension in pixels for automatic image compression
multiImportOffsetnumberStagger offset in world units applied when importing multiple images at once

Eraser Tool​

KritzelEraserTool removes objects or path segments touched by the eraser during drag gestures.

Properties​

PropertyTypeDescription
toolType'eraser'Type identifier for the eraser tool