Weave.js

WeaveStrokeSingleNode

Stroke V2 node API Reference

Overview

The WeaveStrokeSingleNode class represents a single stroke line on the Weave.js canvas. It is a versatile and essential node type for building tools like freehand drawing. It supports also define tips for both stroke ends as:

  • Arrow

  • Circle

  • Square

The class extends the WeaveNode class

Type

This node nodeType property value is stroke-single.

Import

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

Instantiation

new WeaveStrokeSingleNode(params?: WeaveStrokeSingleNodeParams);

TypeScript types

type WeaveStrokeSingleProperties = {
  transform?: WeaveNodeTransformerProperties;
  snapAngles: {
    angles: number[]; // Angles for snapping in degrees
    activateThreshold: number;
    releaseThreshold: number;
  };
};

type WeaveStrokeSingleNodeParams = {
  config: Partial<WeaveStrokeSingleProperties>;
};

type WeaveStrokeSingleNodeTipSideKeys =
  keyof typeof WEAVE_STROKE_SINGLE_NODE_TIP_SIDE;
type WeaveStrokeSingleNodeTipSide =
  (typeof WEAVE_STROKE_SINGLE_NODE_TIP_SIDE)[WeaveStrokeSingleNodeTipSideKeys];

Parameters

For WeaveStrokeSingleNodeParams:

Property Type Required Description

config

Partial<WeaveStrokeSingleProperties>

Required

Config parameters for the node.

For WeaveStrokeSingleProperties:

Property Type Required Default Description

snapAngles.angles

number

10

Array of angles (in degrees) to snap the line to when shift is pressed.

snapAngles.activateThreshold

number

5

Activation threshold for the angle snapping utility.

snapAngles.releaseThreshold

number

10

Release threshold for the angle snapping utility.

transform

object

check default values

Setup the transform properties for the line (if can be resized, rotated, anchors, etc.).

Default values

const WEAVE_STROKE_SINGLE_NODE_DEFAULT_CONFIG = {
  snapAngles: {
    angles: [0, 45, 90, 135, 180, 225, 270, 315],
    activateThreshold: 5,
    releaseThreshold: 10,
  },
};