bpmn-canvas 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,8 +3,7 @@
3
3
  [![CI](https://github.com/dphseven/bpmn-canvas/actions/workflows/ci.yml/badge.svg)](https://github.com/dphseven/bpmn-canvas/actions/workflows/ci.yml)
4
4
  [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
5
5
  [![npm version](https://img.shields.io/npm/v/bpmn-canvas.svg)](https://www.npmjs.com/package/bpmn-canvas)
6
- [![Tests](https://img.shields.io/badge/tests-143%20passed-brightgreen.svg)](https://github.com/dphseven/bpmn-canvas/actions)
7
- [![Coverage](https://img.shields.io/badge/coverage-80%25-brightgreen.svg)](https://github.com/dphseven/bpmn-canvas)
6
+ [![codecov](https://codecov.io/gh/dphseven/bpmn-canvas/branch/main/graph/badge.svg)](https://codecov.io/gh/dphseven/bpmn-canvas)
8
7
  [![Dependencies](https://img.shields.io/badge/dependencies-0-success.svg)](package.json)
9
8
 
10
9
  > A lightweight, zero-dependency workflow canvas and diagram modeler inspired by BPMN 2.0, built with native DOM + SVG architecture.
@@ -14,22 +13,43 @@
14
13
  ## Key Features
15
14
 
16
15
  - **Zero-Dependency Native DOM + SVG Architecture**
17
- Built entirely on standard browser APIs with zero runtime dependencies. Nodes render as native HTML elements for crisp typography and instant CSS styling, while connectors render as scalable SVG vector paths with high-DPI clarity
16
+ Built entirely on standard browser APIs with zero runtime dependencies. Nodes render as native HTML elements for crisp typography and instant CSS styling, while connectors render as scalable SVG vector paths with high-DPI clarity.
18
17
 
19
- - **BPMN-Inspired Semantics Without the XML Bloat**
20
- Model familiar BPMN concepts—activities, tasks, gateways, boundary event docking, and expandable subprocesses—without wrestling with rigid 5,000-line XML schemas. Diagrams serialize cleanly to and from predictable, human-readable JSON that stores directly in PostgreSQL JSONB, MongoDB, or REST APIs
18
+ - **Dual-Mode Interoperability: BPMN 2.0 XML & Clean JSON**
19
+ Full bidirectional import/export for standard BPMN 2.0 XML with non-destructive Bezier curve preservation and BPMNDI waypoints, alongside clean, database-ready JSON.
21
20
 
22
- - **Modular & Headless-Friendly by Design**
23
- Architected on Single Responsibility Principles with decoupled subsystems (`BpmnCanvas`, `NodeTypeRegistry`, `Palette`, `Inspector`, `HistoryManager`, and `SelectionManager`). Embed the complete out-of-the-box studio, or mount just the canvas engine and control it from your own custom React, Vue, or Angular panels
21
+ - **Built for AI Agents (`SemanticAdapter`)**
22
+ Ingest declarative workflows without coordinates, stream debounced telemetry diffs tailored for LLMs, direct visual attention with highlights/focus, and lint BPMN semantics.
24
23
 
25
- - **Design System First (CSS Variable Theming)**
26
- Every visual element is styled via standard CSS custom properties (`--bg-canvas`, `--border-focus`, `--accent-primary`, etc.). Seamlessly switch between dark mode, light mode, or custom enterprise palettes with zero canvas re-rendering
24
+ - **Zero-Dependency Auto-Arrange Layout Engine (`AutoLayoutManager`)**
25
+ Built-in hierarchical Sugiyama-style layout engine tailored for BPMN 2.0 workflows with boundary event docking, subprocess nesting, and automatic fit-view.
27
26
 
28
- - **Reactive Event Bus & Transactional Commands**
29
- Comprehensive, typed-like event catalog (`canvas.on()`, `once()`, `off()`) for fine-grained workflow telemetry. Full programmatic manipulation API (`updateNode`, `updateEdge`, `splitEdgeWithNode`) with atomic batching (`canvas.batch()`) to bundle compound operations into single undo/redo steps
27
+ - **High-Fidelity Diagram Image Export (`ImageExporter`)**
28
+ Client-side diagram export to standalone vector SVG, high-resolution PNG, and JPEG with custom padding and theme background styling.
30
29
 
31
- - **Production-Grade Interaction Engine**
32
- Includes smart Bezier and orthogonal Manhattan connector routing, boundary event snapping, automatic downstream node displacement on subprocess expansion, multi-node marquee selection, and animated token simulation for previewing execution paths
30
+ - **Extensible Plugin & Capability Architecture (`NodeTypeRegistry`)**
31
+ Fine-grained node capabilities, custom HTML/SVG renderers, dynamic port configurations, custom connection rules, and custom element factories.
32
+
33
+ - **Headless & Framework-Agnostic**
34
+ Embed the complete out-of-the-box studio or mount the headless canvas engine directly into React, Vue, Svelte, or vanilla JS apps.
35
+
36
+ ---
37
+
38
+ ## Feature Comparison
39
+
40
+ | Feature / Capability | `bpmn-canvas` | `bpmn-js` | `React Flow` / `xyflow` |
41
+ | :--------------------------------- | :-----------------------------------: | :------------------------------: | :------------------------------: |
42
+ | **Runtime Dependencies** | **0 (Zero)** | Heavy (Diagram-js, etc.) | React / Svelte bound |
43
+ | **Framework Agnostic** | ✅<br/>(Vanilla, React, Vue, Svelte) | ⚠️<br/>(DOM wrapper needed) | ❌<br/>(React/Svelte only) |
44
+ | **BPMN 2.0 XML (Bidirectional)** | ✅<br/>Full (preserves Bezier) | ✅<br/>Native | ❌<br/>(DIY) |
45
+ | **Clean JSON Serialization** | ✅<br/>Native JSON | ❌<br/>(XML-centric) | ✅<br/>Plain JSON |
46
+ | **AI / Agentic Adapter** | ✅<br/>Built-in (`SemanticAdapter`) | ❌<br/>None | ❌<br/>(DIY) |
47
+ | **Built-in Auto-Layout** | ✅<br/>Zero-dep DAG engine | ⚠️<br/>(Requires external layout) | ⚠️<br/>(Requires external layout) |
48
+ | **Boundary Events & Subprocesses** | ✅<br/>Automatic docking/nesting | ✅<br/>Yes | ❌<br/>(DIY manual positioning) |
49
+ | **Client-Side Image Export** | ✅<br/>SVG, PNG, JPEG, XML, JSON | ⚠️<br/>XML/SVG (PNG via plugin) | ⚠️<br/>Manual via html-to-image |
50
+ | **CSS Variable Theming** | ✅<br/>Native light/dark design tokens | ❌<br/>Canvas/inline heavy | ✅<br/>CSS Variables |
51
+
52
+ ---
33
53
 
34
54
  ## Installation
35
55
 
@@ -70,11 +90,11 @@ import { BpmnCanvas } from 'bpmn-canvas';
70
90
  const container = document.getElementById('canvas-container');
71
91
  const canvas = new BpmnCanvas(container, {
72
92
  snapToGrid: true,
73
- gridSize: 24,
93
+ gridSize: 24,
74
94
  defaultRouting: 'bezier' // or 'orthogonal'
75
95
  });
76
96
 
77
- // Add BPMN-inspired workflow nodes
97
+ // Add BPMN workflow nodes
78
98
  const start = canvas.addNode({
79
99
  type: 'start-event',
80
100
  x: 100,
@@ -101,6 +121,216 @@ canvas.addEdge({ sourceId: start.id, targetId: task.id });
101
121
  canvas.addEdge({ sourceId: task.id, targetId: end.id });
102
122
  ```
103
123
 
124
+ ---
125
+
126
+ ## Core Concepts & Architecture
127
+
128
+ `bpmn-canvas` separates visual modeling concerns into focused, decoupled subsystems:
129
+
130
+ ```mermaid
131
+ flowchart TD
132
+ Canvas["BpmnCanvas<br/><b>(Viewport, Projections & Orchestration)</b>"]
133
+
134
+ Entities["Node & Edge Entities<br/><i>(DOM/SVG Render & Lifecycle)</i>"]
135
+ Registry["NodeTypeRegistry<br/><i>(Shape Catalog, Rules & Capabilities)</i>"]
136
+ History["HistoryManager<br/><i>(Transactional Undo/Redo)</i>"]
137
+ Selection["SelectionManager<br/><i>(Marquee & Multi-Select)</i>"]
138
+ Layout["AutoLayoutManager<br/><i>(Topological & Hierarchical Layout)</i>"]
139
+ Xml["BpmnXmlSerializer<br/><i>(BPMN 2.0 XML & DI Serializer)</i>"]
140
+ Exporter["ImageExporter<br/><i>(SVG, PNG & JPEG Export)</i>"]
141
+ Semantic["SemanticAdapter<br/><i>(AI Agentic Layer & Telemetry)</i>"]
142
+ Panels["Palette & Inspector<br/><i>(Companion UI Panels)</i>"]
143
+
144
+ Canvas --> Entities
145
+ Canvas --> Registry
146
+ Canvas --> History
147
+ Canvas --> Selection
148
+ Canvas --> Layout
149
+ Canvas --> Xml
150
+ Canvas --> Exporter
151
+ Canvas --> Semantic
152
+ Canvas -.->|Events| Panels
153
+ ```
154
+
155
+ - **`BpmnCanvas`**: Core viewport engine. Manages DOM container lifecycle, zoom/pan transforms, coordinate mapping (`clientToCanvas`), connector rendering, and user capabilities (e.g. `readOnly`, `allowDrag`).
156
+ - **`Node` & `Edge` Entities**: Stateful graph primitives. Nodes manage DOM element rendering, port anchors, and boundary docking; Edges manage SVG path calculation, routing strategies (Bezier/orthogonal), and animated token simulation.
157
+ - **`AutoLayoutManager`**: Zero-dependency layout engine. Implements hierarchical DAG layout for BPMN workflows with boundary event preservation and container nesting.
158
+ - **`BpmnXmlSerializer`**: Full BPMN 2.0 XML bidirectional parser and serializer with diagram interchange (BPMNDI) and bezier curve preservation.
159
+ - **`ImageExporter`**: Client-side diagram export engine generating vector SVG, high-DPI PNG, or JPEG images.
160
+ - **`SemanticAdapter`**: Agentic collaboration bridge translating visual canvas states into compact semantic graphs, telemetry streams, and linter diagnostics for AI agents.
161
+ - **`NodeTypeRegistry`**: Extensible element type catalog defining categories, icons, default dimensions, capabilities, custom renderers, and connection rules.
162
+ - **`HistoryManager`**: Transactional undo/redo engine capturing debounced property modifications and atomic compound operations executed via `canvas.batch()`.
163
+ - **`SelectionManager`**: Encapsulates single-selection, multi-select modifier clicks, and background marquee box sweeps.
164
+ - **`Palette` & `Inspector`**: Standalone companion UI panels communicating with the canvas via standard event bus subscriptions.
165
+
166
+ ---
167
+
168
+ ## Feature Guides & Recipes
169
+
170
+ ### 1. Auto-Arrange Layout Engine
171
+
172
+ Reorganize any diagram into a clean, hierarchical DAG with a single call:
173
+
174
+ ```javascript
175
+ // Auto-layout with default horizontal orientation and auto-fit
176
+ canvas.autoArrange();
177
+
178
+ // Customize layout options
179
+ canvas.autoArrange({
180
+ direction: 'LR', // 'LR' (Left-to-Right) or 'TB' (Top-to-Bottom)
181
+ horizontalGap: 120, // Horizontal spacing between rank columns (px)
182
+ verticalGap: 80, // Vertical spacing between parallel rows (px)
183
+ startX: 80, // Starting X offset
184
+ startY: 120, // Starting Y offset
185
+ fitView: true // Automatically zoom-to-fit after layout
186
+ });
187
+ ```
188
+
189
+ ### 2. BPMN 2.0 XML & JSON Serialization
190
+
191
+ Seamlessly interchange workflows with enterprise BPMN suites (Camunda, bpmn-js, Signavio) or persist directly as lightweight JSON:
192
+
193
+ ```javascript
194
+ // Export standard BPMN 2.0 XML (preserves Bezier curves and BPMNDI layout)
195
+ const xmlString = canvas.exportToBpmnXml();
196
+
197
+ // Import standard BPMN 2.0 XML
198
+ canvas.importFromBpmnXml(xmlString, { autoFit: true });
199
+
200
+ // Export lightweight JSON (ideal for databases or REST APIs)
201
+ const jsonPayload = canvas.exportToJson();
202
+
203
+ // Import lightweight JSON
204
+ canvas.importFromJson(jsonPayload);
205
+ ```
206
+
207
+ ### 3. Diagram Image Export (SVG, PNG, JPEG)
208
+
209
+ Render and download high-resolution diagram graphics directly in the browser:
210
+
211
+ ```javascript
212
+ // Export as PNG Blob
213
+ const pngBlob = await canvas.exportImage('png', {
214
+ padding: 40,
215
+ background: '#18181b', // or 'transparent'
216
+ pixelRatio: 2 // High-DPI export
217
+ });
218
+
219
+ // Download helper
220
+ const url = URL.createObjectURL(pngBlob);
221
+ const link = document.createElement('a');
222
+ link.download = 'workflow.png';
223
+ link.href = url;
224
+ link.click();
225
+ URL.revokeObjectURL(url);
226
+
227
+ // Export as standalone vector SVG
228
+ const svgBlob = await canvas.exportImage('svg', { padding: 40 });
229
+
230
+ // Export as JPEG
231
+ const jpegBlob = await canvas.exportImage('jpeg', { quality: 0.95 });
232
+ ```
233
+
234
+ ### 4. AI-Agentic Integration (`SemanticAdapter`)
235
+
236
+ Build AI-powered workflow automation, copilots, or autonomous workflow agents:
237
+
238
+ ```javascript
239
+ // 1. Ingest declarative workflow graphs without manual coordinates
240
+ canvas.applySemanticGraph({
241
+ direction: 'LR',
242
+ nodes: [
243
+ { id: 'start', type: 'start-event', label: 'Invoice Received' },
244
+ { id: 'ocr', type: 'service-task', label: 'Extract OCR Data' },
245
+ { id: 'check', type: 'exclusive-gateway', label: 'Amount > $5k?' },
246
+ { id: 'approval', type: 'user-task', label: 'Manager Approval' },
247
+ { id: 'pay', type: 'service-task', label: 'Process Payment' },
248
+ { id: 'end', type: 'end-event', label: 'Invoice Settled' }
249
+ ],
250
+ edges: [
251
+ { source: 'start', target: 'ocr' },
252
+ { source: 'ocr', target: 'check' },
253
+ { source: 'check', target: 'approval', label: 'Yes' },
254
+ { source: 'check', target: 'pay', label: 'No' },
255
+ { source: 'approval', target: 'pay' },
256
+ { source: 'pay', target: 'end' }
257
+ ]
258
+ });
259
+
260
+ // 2. Extract token-efficient semantic snapshot for LLM context prompts
261
+ const snapshot = canvas.getSemanticSnapshot();
262
+
263
+ // 3. Subscribe to debounced semantic telemetry diffs
264
+ const unsubTelemetry = canvas.onSemanticTelemetry((diff) => {
265
+ console.log('Semantic graph changes for agent context:', diff.summary);
266
+ // diff.summary provides concise Markdown lines ideal for LLM prompts
267
+ });
268
+
269
+ // 4. Validate workflow with built-in BPMN 2.0 Semantic Linter
270
+ const report = canvas.validateWorkflow();
271
+ if (!report.valid) {
272
+ console.warn('Workflow violations:', report.errors, report.warnings);
273
+ }
274
+
275
+ // 5. Direct visual attention
276
+ canvas.highlightNodes(['ocr'], { color: '#6366f1', badge: 'AI Processing' });
277
+ canvas.focusNode('ocr');
278
+ canvas.clearHighlights();
279
+
280
+ // 6. Graph reasoning and traversal
281
+ const upstream = canvas.getUpstreamNodes('pay');
282
+ const paths = canvas.findPaths('start', 'end');
283
+ const simResult = canvas.simulatePath({ startId: 'start' });
284
+ ```
285
+
286
+ ### 5. Custom Node Types & Extensibility
287
+
288
+ Extend the shape catalog with custom icons, badges, capabilities, custom renderers, and connection validation rules:
289
+
290
+ ```javascript
291
+ import { NodeTypeRegistry, BpmnCanvas } from 'bpmn-canvas';
292
+
293
+ const registry = new NodeTypeRegistry();
294
+
295
+ // 1. Register custom element type with capabilities
296
+ registry.register('ai-agent-task', {
297
+ label: 'AI Agent Task',
298
+ category: 'activities',
299
+ badge: 'AI Agent',
300
+ icon: '🤖',
301
+ width: 140,
302
+ height: 80,
303
+ capabilities: {
304
+ allowIncoming: true,
305
+ allowOutgoing: true,
306
+ customPorts: ['top', 'bottom', 'left', 'right']
307
+ }
308
+ });
309
+
310
+ // 2. Register custom SVG/DOM node renderer
311
+ registry.registerRenderer('ai-agent-task', (node, container) => {
312
+ container.innerHTML = `
313
+ <div class="custom-agent-node">
314
+ <span class="agent-icon">🤖</span>
315
+ <span class="agent-label">${node.label}</span>
316
+ </div>
317
+ `;
318
+ });
319
+
320
+ // 3. Register custom connection validation rules
321
+ registry.registerConnectionRule((sourceNode, targetNode, context) => {
322
+ if (sourceNode.type === 'end-event') {
323
+ return { valid: false, message: 'End events cannot have outgoing flows' };
324
+ }
325
+ return { valid: true };
326
+ });
327
+
328
+ // Mount canvas using the custom registry
329
+ const canvas = new BpmnCanvas(container, { registry });
330
+ ```
331
+
332
+ ---
333
+
104
334
  ## Framework Integration
105
335
 
106
336
  Because `bpmn-canvas` mounts directly onto any standard DOM element, it drops seamlessly into modern component lifecycles:
@@ -173,64 +403,11 @@ onMounted(() => {
173
403
  <div bind:this={container} style="width: 100%; height: 100vh;" />
174
404
  ```
175
405
 
176
- ## Core Concepts & Architecture
177
-
178
- `bpmn-canvas` separates visual modeling concerns into focused, decoupled subsystems:
179
-
180
- ```mermaid
181
- flowchart TD
182
- Canvas["BpmnCanvas<br/><b>(Viewport, Projections & Orchestration)</b>"]
183
-
184
- Entities["Node & Edge Entities<br/><i>(DOM/SVG Render & Lifecycle)</i>"]
185
- Registry["NodeTypeRegistry<br/><i>(Shape Catalog & Geometry)</i>"]
186
- History["HistoryManager<br/><i>(Transactional Undo/Redo)</i>"]
187
- Selection["SelectionManager<br/><i>(Marquee & Multi-Select)</i>"]
188
- Panels["Palette & Inspector<br/><i>(Companion UI Panels)</i>"]
189
-
190
- Canvas --> Entities
191
- Canvas --> Registry
192
- Canvas --> History
193
- Canvas --> Selection
194
- Canvas -.->|Events| Panels
195
- ```
196
-
197
- - **`BpmnCanvas`**: Core viewport engine. Manages DOM container lifecycle, zoom/pan transforms, coordinate mapping (`clientToCanvas`), connector rendering, and user capabilities (e.g. `readOnly`, `allowDrag`)
198
- - **`Node` & `Edge` Entities**: Stateful graph primitives. Nodes manage DOM element rendering, port anchors, and boundary docking; Edges manage SVG path calculation, routing strategies (Bezier/orthogonal), and animated token simulation
199
- - **`NodeTypeRegistry`**: The extensible element type catalog. Defines shape categories, icons, badges, SVG geometry, and default dimensions
200
- - **`HistoryManager`**: Transactional undo/redo engine. Captures debounced property modifications and atomic compound operations executed via `canvas.batch()`
201
- - **`SelectionManager`**: Encapsulates single-selection, multi-select modifier clicks, and background marquee box sweeps
202
- - **`Palette` & `Inspector`**: Standalone companion UI panels that communicate with the canvas via standard event bus subscriptions
203
-
204
406
  ---
205
407
 
206
- ### Custom Node Type Extension
408
+ ## Event Catalog
207
409
 
208
- You can register custom domain shapes with custom icons, badges, and default dimensions directly into the registry:
209
-
210
- ```javascript
211
- import { NodeTypeRegistry } from 'bpmn-canvas';
212
-
213
- const registry = new NodeTypeRegistry();
214
-
215
- registry.register('ai-agent-task', {
216
- label: 'AI Agent Task',
217
- category: 'activities',
218
- badge: 'AI Agent',
219
- icon: '🤖',
220
- width: 130,
221
- height: 80,
222
- ports: ['top', 'bottom', 'left', 'right']
223
- });
224
-
225
- // Pass custom or shared registry to your canvas instance
226
- const canvas = new BpmnCanvas(container, { registry });
227
- ```
228
-
229
- ---
230
-
231
- ### Event System
232
-
233
- The canvas and companion panels provide a unified, typed-like event bus with automatic teardown functions:
410
+ The canvas provides a typed-like event bus with automatic unsubscribe functions:
234
411
 
235
412
  ```javascript
236
413
  // Subscribe to any canvas event
@@ -238,66 +415,70 @@ const unsub = canvas.on('node:add', (node) => {
238
415
  console.log('Added node:', node.id, node.type);
239
416
  });
240
417
 
241
- // One-time listener
242
- canvas.once('simulation:start', () => {
243
- console.log('Token animation commenced');
244
- });
245
-
246
418
  // Clean up when component unmounts
247
419
  unsub();
248
420
  ```
249
421
 
250
- #### Event Catalog
251
-
252
- | Event Name | Description | Payload |
253
- | :-------------------------- | :------------------------------------------------------- | :---------------------------------------------------------------------------------- |
254
- | `node:add` | Fired when a node is added | `BpmnNode` |
255
- | `node:remove` | Fired when a node is removed | `nodeId` |
256
- | `node:update` | Fired when node properties, label, or position change | `BpmnNode` |
257
- | `node:labelChange` | Fired when node label text is committed | `{ node, label }` |
258
- | `edge:add` | Fired when an edge is added | `BpmnEdge` |
259
- | `edge:remove` | Fired when an edge is removed | `edgeId` |
260
- | `edge:update` | Fired when edge properties or routing change | `BpmnEdge` |
261
- | `edge:reconnect` | Fired when an edge is reconnected to new endpoints | `{ edge, updates }` |
262
- | `edge:split` | Fired when an edge is split by a dropped node | `{ edgeId, nodeId, edge1, edge2 }` |
263
- | `selection:change` | Fired when selection state changes | `{ type: 'node'\|'edge'\|'multi'\|'none', item?, items? }` |
264
- | `palette:dragstart` | Fired when user starts dragging an item from the palette | `{ type, element, grabOffsetX, grabOffsetY, event }` |
265
- | `palette:drop` | Fired when an item from the palette is dropped on canvas | `{ type, node, position, isBoundary, splitEdgeId?, parentId?, hostNodeId?, event }` |
266
- | `palette:filterChange` | Fired when palette filters are modified | `{ filter }` |
267
- | `palette:itemRegister` | Fired when a custom item is registered on palette | `{ category, itemDef }` |
268
- | `history:change` | Fired on undo/redo availability change | `{ canUndo, canRedo }` |
269
- | `viewport:change` | Fired on zoom or pan adjustments | `{ zoom, panX, panY }` |
270
- | `batch:complete` | Fired when an atomic batch operation completes | `{ preBatchState, postBatchState }` |
271
- | `simulation:start` / `stop` | Fired when token simulation begins or ends | `void` |
422
+ | Event Name | Description | Payload |
423
+ | :---------------------- | :------------------------------------------------------- | :---------------------------------------------------------------------------------- |
424
+ | `node:add` | Fired when a node is added | `BpmnNode` |
425
+ | `node:remove` | Fired when a node is removed | `nodeId` |
426
+ | `node:update` | Fired when node properties, label, or position change | `BpmnNode` |
427
+ | `node:labelChange` | Fired when node label text is committed | `{ node, label }` |
428
+ | `edge:add` | Fired when an edge is added | `BpmnEdge` |
429
+ | `edge:remove` | Fired when an edge is removed | `edgeId` |
430
+ | `edge:update` | Fired when edge properties or routing change | `BpmnEdge` |
431
+ | `edge:reconnect` | Fired when an edge is reconnected to new endpoints | `{ edge, updates }` |
432
+ | `edge:split` | Fired when an edge is split by a dropped node | `{ edgeId, nodeId, edge1, edge2 }` |
433
+ | `selection:change` | Fired when selection state changes | `{ type: 'node'\|'edge'\|'multi'\|'none', item?, items? }` |
434
+ | `palette:dragstart` | Fired when user starts dragging an item from the palette | `{ type, element, grabOffsetX, grabOffsetY, event }` |
435
+ | `palette:drop` | Fired when an item from the palette is dropped on canvas | `{ type, node, position, isBoundary, splitEdgeId?, parentId?, hostNodeId?, event }` |
436
+ | `palette:filterChange` | Fired when palette filters are modified | `{ filter }` |
437
+ | `palette:itemRegister` | Fired when a custom item is registered on palette | `{ category, itemDef }` |
438
+ | `history:change` | Fired on undo/redo availability change | `{ canUndo, canRedo }` |
439
+ | `viewport:change` | Fired on zoom or pan adjustments | `{ zoom, panX, panY }` |
440
+ | `batch:complete` | Fired when an atomic batch operation completes | `{ preBatchState, postBatchState }` |
441
+ | `canvas:autoarrange` | Fired when auto-layout is executed | `{ options, changed }` |
442
+ | `canvas:export` | Fired when diagram image export completes | `{ format, size, options }` |
443
+ | `connection:rejected` | Fired when a connection rule rejects an edge | `{ sourceId, targetId, reason }` |
444
+ | `theme:change` | Fired when canvas color theme is toggled | `{ themeClass }` |
445
+ | `data:load` | Fired when a new diagram data payload is loaded | `data` |
446
+ | `simulation:start/stop` | Fired when token simulation begins or ends | `void` |
272
447
 
273
448
  ---
274
449
 
275
- ## Programmatic Command API
276
-
277
- External systems and headless integrations can fully inspect and manipulate the workflow graph programmatically:
450
+ ## Programmatic API Overview
278
451
 
279
452
  ```javascript
280
453
  import { BpmnCanvas } from 'bpmn-canvas';
281
454
 
282
455
  const canvas = new BpmnCanvas(document.getElementById('canvas-container'));
283
456
 
284
- // 1. Transactional Batch Execution (Single Undo Step)
457
+ // Transactional Batch Execution (Single Undo Step)
285
458
  canvas.batch(() => {
286
459
  const start = canvas.addNode({ type: 'start-event', x: 100, y: 150 });
287
460
  const task = canvas.addNode({ type: 'user-task', x: 260, y: 135, label: 'Review Order' });
288
- const edge = canvas.addEdge({ sourceId: start.id, targetId: task.id });
461
+ canvas.addEdge({ sourceId: start.id, targetId: task.id });
289
462
  });
290
463
 
291
- // 2. Granular Updates & Queries
464
+ // Granular Graph Queries & Updates
292
465
  const node = canvas.getNode('some-node-id');
293
466
  canvas.updateNode('some-node-id', { label: 'Updated Label', x: 300 });
294
467
  canvas.updateEdge('some-edge-id', { animated: true });
295
468
  canvas.removeNode('some-node-id');
296
469
  canvas.removeEdge('some-edge-id');
297
470
 
298
- // 3. Diagram Serialization
299
- const workflowJson = canvas.exportToJson();
300
- canvas.importFromJson(workflowJson);
471
+ // Viewport Controls
472
+ canvas.fitView();
473
+ canvas.centerNode('some-node-id');
474
+ canvas.setZoom(1.2);
475
+ canvas.panTo(0, 0);
476
+
477
+ // Layout & Interoperability
478
+ canvas.autoArrange({ direction: 'LR', fitView: true });
479
+ const xml = canvas.exportToBpmnXml();
480
+ canvas.importFromBpmnXml(xml);
481
+ const blob = await canvas.exportImage('png');
301
482
  ```
302
483
 
303
484
  ---
@@ -320,6 +501,37 @@ canvas.importFromJson(workflowJson);
320
501
 
321
502
  ---
322
503
 
504
+ ## Package Exports
505
+
506
+ The `bpmn-canvas` package exports the following modules and primitives:
507
+
508
+ ```javascript
509
+ import {
510
+ BpmnCanvas, // Main canvas viewport orchestrator
511
+ BpmnNode, // Node entity
512
+ BpmnEdge, // Edge entity
513
+ Router, // Bezier and orthogonal Manhattan edge router
514
+ Palette, // Drag-and-drop element palette component
515
+ Inspector, // Property inspector side panel
516
+ NodeTypeRegistry, // Extensible shape catalog, rules, and capabilities
517
+ HistoryManager, // Transactional undo/redo engine
518
+ SelectionManager, // Single and multi-element selection manager
519
+ AutoLayoutManager, // Zero-dependency hierarchical layout engine
520
+ BpmnXmlSerializer, // BPMN 2.0 XML bidirectional parser and serializer
521
+ BPMN_NAMESPACES, // Standard BPMN 2.0 XML schema namespace URIs
522
+ ImageExporter, // SVG, PNG, and JPEG export engine (via canvas.exportImage)
523
+ SemanticAdapter, // AI-Agentic collaboration, telemetry, and linter layer
524
+ SimulationEngine, // Token animation and path execution simulator
525
+ SubprocessLayoutManager, // Container expansion and child displacement engine
526
+ NodeRenderer, // DOM node element renderer
527
+ InlineEditor, // Double-click inline typography editor
528
+ geometry, // Coordinate transformations and vector math utilities
529
+ types // TypeScript-style interface and contract definitions
530
+ } from 'bpmn-canvas';
531
+ ```
532
+
533
+ ---
534
+
323
535
  ## Contributing
324
536
 
325
537
  We welcome contributions, bug reports, and enhancements!
@@ -341,14 +553,14 @@ npm test
341
553
  npm run test:watch
342
554
 
343
555
  # Check test coverage (enforcing >= 80% coverage)
344
- npx vitest run --coverage
556
+ npm run coverage
345
557
  ```
346
558
 
347
559
  ### License
348
560
  This project is licensed under the [Apache License, Version 2.0](LICENSE).
349
561
 
350
562
  ### Acknowledgements
351
- - **[OMG (Object Management Group)](https://www.omg.org/bpmn/)**: For the BPMN 2.0 (Business Process Model and Notation) standard and visual specification that guides the shapes, semantics, and connection rules in this library
352
- - **[bpmn.io / bpmn-js (Camunda)](https://bpmn.io/)**: For pioneering modern, open-source web-based BPMN modeling and setting the benchmark for browser diagramming ergonomics
353
- - **Modern Canvas & Node Graph Pioneers**: Architectural patterns and interaction models inspired by modern visual node graphs such as [React Flow / xyflow](https://reactflow.dev/) and [LiteGraph](https://github.com/jagenjo/litegraph.js)
354
- - **Google Fonts**: For the clean UI typography powered by [Inter](https://fonts.google.com/specimen/Inter)
563
+ - **[OMG (Object Management Group)](https://www.omg.org/bpmn/)**: For the BPMN 2.0 (Business Process Model and Notation) standard and visual specification that guides the shapes, semantics, and connection rules in this library.
564
+ - **[bpmn.io / bpmn-js (Camunda)](https://bpmn.io/)**: For pioneering modern, open-source web-based BPMN modeling and setting the benchmark for browser diagramming ergonomics.
565
+ - **Modern Canvas & Node Graph Pioneers**: Architectural patterns and interaction models inspired by modern visual node graphs such as [React Flow / xyflow](https://reactflow.dev/) and [LiteGraph](https://github.com/jagenjo/litegraph.js).
566
+ - **Google Fonts**: For the clean UI typography powered by [Inter](https://fonts.google.com/specimen/Inter).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bpmn-canvas",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "A lightweight, zero-dependency workflow canvas and diagram modeler inspired by BPMN 2.0, built with native DOM + SVG architecture.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -49,4 +49,3 @@
49
49
  "vitest": "^5.0.5"
50
50
  }
51
51
  }
52
-