Weave.js

WeaveBrushToolAction

Paint freeform strokes on the canvas

Overview

The WeaveBrushToolAction class that enables users to draw freeform strokes on the canvas using a brush tool. It lets users click and drag across the canvas to create a smooth, continuous path—perfect for sketching, annotating, or freehand drawing within a collaborative environment.

Each stroke is recorded as a WeaveLineNode, synchronized across all connected users in real time.

The class extends the WeaveAction class.

Name

This action name property value is brushTool.

Type

This node nodeType property value is stroke.

Import

import { WeaveBrushToolAction } from "@inditextech/weave-sdk";

Instantiation

new WeaveBrushToolAction(params?: WeaveBrushToolActionParams);

TypeScript types

type WeaveBrushToolActionProperties = {
  interpolationSteps: number; // Number of steps for interpolation
  simplifyTolerance: number; // Douglas-Peucker tolerance applied on stroke finalize
};

type WeaveBrushToolActionParams = {
  config: Partial<WeaveBrushToolActionProperties>;
};

Parameters

For WeaveBrushToolActionParams:

Property Type Required Description

config

Partial<WeaveBrushToolActionProperties>

Required

Config parameters for the tool.

For WeaveBrushToolActionProperties:

Property Type Required Default Description

interpolationSteps

number

10

Number of interpolation steps for smooth curve on touch devices.

simplifyTolerance

number

0.5

Tolerance, in canvas units, of the Douglas-Peucker simplification applied once when a stroke is finalized. While a stroke is being drawn every recorded sample is rendered; on release the point list is simplified before being persisted, so this value governs how much fidelity a finished stroke gives up. Lower values keep a finished stroke closer to the path drawn, at the cost of more points stored per stroke.

Default values

const BRUSH_TOOL_DEFAULT_CONFIG = {
  interpolationSteps: 10,
  simplifyTolerance: 0.5,
};