Removes the given AbstractComponents from the image.

Example:

import { Editor, Erase, uniteCommands, Color4, Path, Stroke, Rect2, pathToRenderable } from 'js-draw';

const editor = new Editor(document.body);
editor.addToolbar();

// Add a large number of strokes
const commands = [];
for (let x = -20; x < 20; x++) {
  for (let y = 0; y < 60; y++) {
    const stroke = new Stroke([
      pathToRenderable(
        Path.fromString(`m${x * 5},${y * 5}l1,1`),
        { fill: Color4.transparent, stroke: {width: 2, color: Color4.ofRGB(x / 10, y / 10, 0.5)}} )
      ]);
    commands.push(editor.image.addElement(stroke));
  }
}
await editor.dispatch(uniteCommands(commands, 100));

---visible---
// Given some editor...

// Find all elements intersecting the rectangle with top left (-10,-30) and
// (width,height)=(50,100).
const elems = editor.image.getElementsIntersectingRegion(
	new Rect2(-10, -30, 50, 100)
);

// Create a command that erases [elems] when applied
const eraseElemsCmd = new Erase(elems);

// Apply the command (and make it undoable)
editor.dispatch(eraseElemsCmd);

Hierarchy (view full)

Constructors

Properties

empty: (Anonymous class) = ...

Methods

  • Convert this command to an object that can be passed to JSON.stringify.

    Do not rely on the stability of the optupt of this function — it can change form without a major version increase.

    Returns Record<string | symbol, any>

  • Returns {
        data:
            | string
            | number
            | any[]
            | Record<string, any>;
        id: string;
        loadSaveData: LoadSaveDataTable;
        name: string;
        zIndex: number;
    }[]

  • Register a deserialization callback. This must be called at least once for every subclass of SerializableCommand.

    Parameters

    • commandTypeId: string
    • deserialize: DeserializationCallback

    Returns void

OpenSource licenses