Weave.js

WeaveStrokeNode

Stroke node API Reference

Overview

The WeaveStrokeNode class represents a multi-point continuous line or path on the Weave.js canvas. It is a versatile and essential node type for building tools like freehand drawing.

Built on top of Konva’s Shape class shape under the hood, the WeaveStrokeNode offers full control over the line’s geometry, style, and behavior—all synchronized in real time across users.

The class extends the WeaveNode class

Type

This node nodeType property value is stroke.

Import

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

Instantiation

new WeaveStrokeNode(params?: WeaveStrokeNodeParams);

TypeScript types

type WeaveNodeTransformerProperties = Konva.TransformerConfig;

type WeaveStrokeProperties = {
  splineResolution: number; // Minimum subdivisions per curved spline span
  splineTargetEdge: number; // Target rendered edge length, in canvas units
  splineMaxSteps: number; // Upper bound on subdivisions for a single span
  resamplingSpacing: number; // Spacing for resampling points
  isEraser?: boolean; // Whether the stroke is an eraser
  transform?: WeaveNodeTransformerProperties;
};

type WeaveStrokeNodeParams = {
  config: Partial<WeaveStrokeProperties>;
};

type WeaveStrokePoint = {
  x: number;
  y: number;
  pressure: number;
};

Parameters

For WeaveStrokeNodeParams:

Property Type Required Description

config

Partial<WeaveStrokeProperties>

Required

Config parameters for the node.

For WeaveStrokeProperties:

Property Type Required Default Description

splineResolution

number

8

Minimum number of subdivisions used for a curved span of the smoothed curve. Longer spans are subdivided further, by arc length, so that rendered smoothness does not depend on how far apart the recorded points happen to be.

splineTargetEdge

number

1

Target length, in canvas units, of a single rendered edge. Lower values produce a smoother silhouette at the cost of proportionally more rendered vertices.

splineMaxSteps

number

48

Upper bound on the subdivisions used for one span, so an unusually long span cannot inflate the vertex count without limit.

resamplingSpacing

number

2

Minimum spacing between the control points fed to the spline. Applied after simplification, so it mainly guards against duplicate and near-duplicate samples.

isEraser

boolean

false

Whether the stroke behaves as an eraser.

splineResolution and resamplingSpacing were previously accepted but ignored — the renderer used hardcoded values regardless. They now take effect, so a node that passed non-default values will render differently than it did before.

Default values

const WEAVE_STROKE_NODE_DEFAULT_CONFIG = {
  splineResolution: 8,
  splineTargetEdge: 1,
  splineMaxSteps: 48,
  resamplingSpacing: 2,
  isEraser: false,
};

Stroke look

A stroke can carry a look attribute that says how it is drawn. The look is saved with the stroke, so every viewer and every export draws it the same way. A stroke without a look, or with a look whose version is not 1, is drawn exactly as in earlier releases.

type WeaveStrokeLook = {
  version: 1;
  outline: 'legacy' | 'round' | 'freehand';
  curve: 'uniform' | 'centripetal' | 'none';
  pressureInterp: 'catmullRom' | 'linear';
  zoomAware: boolean;
  spacingPx: number;
  edgePx: number;
  caps: 'separate' | 'merged';
  width: { min: number; max: number; gamma: number; taperStart: number; taperEnd: number };
};

Missing or invalid fields fall back to the legacy values, and numbers are clamped to a safe range.

Field Effect

outline

legacy is the offset ribbon of earlier releases. round draws the union of the tangent quads between neighbours, merged into one polygon where the path bends only slightly, with a disc at every real bend and at the ends, in one fill. Turns, reversals and ends are round and a translucent colour stays uniform. freehand currently draws like round; it has no outline of its own yet.

curve

uniform is the earlier Catmull-Rom curve. centripetal does not overshoot or form cusps when points are unevenly spaced. none joins the points with straight edges.

pressureInterp

linear never leaves the range of the two neighbouring pressures. catmullRom is smooth and clamped to that range.

zoomAware

Spacing and subdivision are in screen pixels, so no facet shows at high zoom. Tapers are measured in screen pixels too.

caps

With the legacy outline, separate draws the round ends over the fill, as before. merged puts them in the same fill, so a translucent colour is not darker at the ends.

width

Half-width is the stroke width times a fraction between min and max, following pressure raised to gamma, narrowing over taperStart and taperEnd. The defaults reproduce the earlier width.

Viewer-side preview

const stroke = weave.getNodeHandler<WeaveStrokeNode>('stroke');
stroke.setLookPreview({ version: 1, outline: 'round' });  // draw every stroke with this look
stroke.setLookPreview(null);                              // back to the saved looks

The preview only changes how this screen draws. It does not change any saved stroke and other users do not see it.