@rasamjs/connectors
v0.4.0
Published
Attached straight and elbow connectors for rasam SVG drawings.
Readme
@rasamjs/connectors
The optional editor adapter packages connector services and registered straight/elbow tools, including live paint and input cleanup.
Attached straight and elbow lines and marker arrows for rasam SVG drawings. Core is
the only runtime peer. Version 0.3.0 requires @rasamjs/core@^0.3.0 for named ports,
loose-end persistence and indexed routing. Source manifests stay private between releases.
npm install @rasamjs/core@^0.3.0 @rasamjs/connectors@^0.3.0The custom routing option, added in 0.3.0,
lets an app supply its own polyline routing without a second path write.
The unreleased reroute(path) method lets external routing dependencies, such as
obstacles, refresh geometry inside the current edit. See the same API section for
its return value and history behavior.
import { SVG } from '@rasamjs/core';
import { Connectors } from '@rasamjs/connectors';
import { ConnectorTool } from '@rasamjs/connectors/tool';
const drawing = SVG(host, { width: 700, height: 500 });
const a = drawing.rect({ x: 40, y: 40, width: 80, height: 50 });
const b = drawing.rect({ x: 300, y: 180, width: 80, height: 50 });
const connectors = new Connectors(drawing);
const path = connectors.create({
start: { target: a, anchor: 'right' },
end: { target: b, anchor: 'auto' },
routing: 'elbow',
});
const tool = new ConnectorTool(connectors, { routing: 'straight' });
tool.enabled = true;Ends can also attach to a component's named ports, { target: chip, port: 'p3' }, and
connectors.links(chip) lists the connectors on it. Deleting a target keeps its
connectors, with a loose end where it was.
Moving or resizing an endpoint, or its parent, updates the connector inside the same model operation and change group. History records one undo step for a move and all its attached lines. Replay restores stored geometry without routing again.
The optional tool previews on an overlay, shows side anchors on hover, and writes
one connector on release. Escape, pointer cancellation and blur discard the preview.
The playground exposes Connector (C) and Elbow connector (Shift+C) tools.
Attachments are typed references on ordinary paths, so saved SVG, clones, imports, clipboard and history retain them. No custom element registration is needed. Both entries can be imported without a document. See API.md for anchor coordinates, lifecycle, routing limits and persistence behavior.
bun run --cwd packages/connectors test
bun run --cwd packages/connectors test:browser
bun run --cwd packages/connectors typecheck
bun run --cwd packages/connectors build
bun run --cwd packages/connectors bench