vyuh_diagram_core 2.14.0
vyuh_diagram_core: ^2.14.0 copied to clipboard
Transactions, editor state, and history for Vyuh Diagram.
vyuh_diagram_core
The pure Dart engine of Vyuh Diagram: controller, verbs, undo and redo, rules and extensions.
Vyuh Diagram · Docs · Examples · API reference
Everything a diagram does, without Flutter: servers, agents and command-line
tools use the same controller and verbs as the canvas. A Diagram holds the
document, its DiagramConfiguration, one history and its participants; each
DiagramController is one actor on it, with its own selection and undo.
Typed selection properties, connected creation and diagnostic repairs use the
same controller admission and history. resolvedElementById(id) observes a
single live identity, including preview geometry.
Install #
dart pub add vyuh_diagram_core --hosted-url https://pub.vyuh.tech
Register your registry token first with dart pub token add https://pub.vyuh.tech;
see package access.
Usage #
import 'package:vyuh_diagram_codec_json/vyuh_diagram_codec_json.dart';
import 'package:vyuh_diagram_core/vyuh_diagram_core.dart';
final controller = DiagramController(
configuration: DiagramConfiguration(extensions: [GridExtension(snap: true)]),
);
final a = controller.createShape(Shapes.rectangle, at: DiagramPoint.zero, text: 'A').requireId();
final b = controller.createShape(Shapes.rectangle, at: const DiagramPoint(240, 0), text: 'B').requireId();
controller.connect(a, b);
final json = controller.save(DiagramJsonCodec.new);
controller.select([a, b]);
controller.properties().require(ShapeProperties.fill)
.set(const DiagramColor(0xff2457ff)).requireAllowed();
Fields expose shared, mixed and unavailable states, intersect constraints and
check their captured revision. Declare kind-owned properties through
ShapeDefinition.properties in extension_api.dart. Diagnostics and property
fields belong to the main application import. See the
controller API.
Every verb returns an EditResult; batch makes several verbs one undo step.
Another actor, such as an agent, joins with
DiagramController(diagram: controller.diagram, participant: DiagramParticipant.agent(id: 'agent', name: 'Agent')).
Key options #
DiagramConfiguration configures a diagram once, shared by every controller
on it:
| Option | Purpose |
|---|---|
extensions |
The installed extensions, each with its own options. |
bounds |
CanvasBounds.infinite (default) or CanvasBounds.fit(padding:). |
fonts, defaultFontFamily |
The font families offered, and the family text uses by default. |
rules |
DiagramRules(beforeChange:, canCreate:, canConnect:) admission rules. |
license |
The license token that removes the canvas attribution. |
Read an extension's options with controller.options<T>() and change them
with controller.setOptions(value), such as GridOptions.
Extension authors also import extension_api.dart; engine internals are in
adapter.dart, test helpers in testing.dart and native headless text in
vyuh_diagram_pango.dart.
Learn more #
License #
Licensed under the Apache License, Version 2.0. Third-party materials retain their own licenses and notices.