Skip to main content

Canvas Object Types

All objects on the canvas extend KritzelBaseObject. Each tool creates a specific object type when the user draws on the canvas.

Base Properties

Every object inherits these properties from KritzelBaseObject:

PropertyTypeDefaultDescription
idstringauto-generated UUIDUnique identifier
workspaceIdstringID of the workspace this object belongs to
xnumberX position in world coordinates
ynumberY position in world coordinates
widthnumberWidth in world units
heightnumberHeight in world units
rotationnumber0Rotation in radians
opacitynumber1Opacity (0–1)
zIndexnumber0Z-order layer
scalenumberObject scale
backgroundColorThemeAwareColorBackground color
borderColorThemeAwareColorBorder color
borderWidthnumber0Border width
paddingnumber0Padding
isVisiblebooleantrueVisibility flag
isSelectedbooleanfalseWhether the object is selected
isHoveredbooleanfalseWhether the object is hovered
isEditablebooleanfalseWhether the object is in edit mode
isInteractivebooleanfalseWhether the object responds to interaction

Computed Properties

PropertyTypeDescription
centerXnumberCenter X coordinate
centerYnumberCenter Y coordinate
totalWidthnumberWidth including padding and borders
totalHeightnumberHeight including padding and borders
boundingBoxKritzelBoundingBoxAxis-aligned bounding box
rotatedBoundingBoxKritzelBoundingBoxBounding box accounting for rotation
rotatedPolygonKritzelPolygonFour corners of the rotated rectangle
transformationMatrixDOMMatrixFull transformation matrix
rotationDegreesnumberRotation converted to degrees

Key Methods

MethodDescription
serialize()Converts the object to a plain serializable representation
deserialize(data)Restores the object from serialized data
clone()Creates a deep copy of the object
hitTest(x, y)Tests if a world-coordinate point intersects this object
hitTestPolygon(polygon)Tests if a polygon intersects this object
isInViewport(viewport)Tests if the object is visible in the given viewport

Object Types

KritzelPath

Freehand brush strokes. Rendered as SVG paths using the perfect-freehand library.

  • Created by: KritzelBrushTool
  • Removed by: KritzelEraserTool

KritzelLine

Straight lines and arrows with configurable start/end arrowheads.

  • Created by: KritzelLineTool
  • Supports anchor snapping to other objects (connecting lines to shapes)
  • Arrowhead styles: triangle, open, diamond, circle

KritzelShape

Geometric shapes: rectangle, ellipse, or triangle.

  • Created by: KritzelShapeTool
  • Can contain editable text
  • Shape type is determined by the ShapeType enum
enum ShapeType {
Rectangle = 'rectangle',
Ellipse = 'ellipse',
Triangle = 'triangle',
}

KritzelText

Rich text object powered by ProseMirror.

  • Created by: KritzelTextTool
  • Supports font family, size, and color configuration

KritzelImage

Raster image object.

  • Created by: KritzelImageTool
  • Supports resizing while maintaining aspect ratio

KritzelGroup

Permanent grouping of multiple objects.

  • Created via group() method
  • Dissolved via ungroup() method
  • Children move, resize, and rotate as a unit

KritzelCustomElement

User-defined custom HTML element on the canvas.

  • Allows embedding arbitrary HTML content as a canvas object
  • Participates in selection, movement, and z-ordering like any other object

Working with Objects Programmatically

const editor = document.querySelector('kritzel-editor');

// Get all objects
const objects = await editor.getAllObjects();

// Find objects by type
const paths = await editor.findObjects(obj => obj.__class__ === 'KritzelPath');
const shapes = await editor.findObjects(obj => obj.__class__ === 'KritzelShape');

// Get a specific object
const obj = await editor.getObjectById('some-id');

// Update an object
await editor.updateObject(obj, { opacity: 0.5, rotation: Math.PI / 4 });

// Remove an object
await editor.removeObject(obj);

// Center viewport on an object
await editor.centerObjectInViewport(obj);