@samatawy/diagrams 0.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/LICENSE +15 -0
- package/README.md +107 -0
- package/dist/index.cjs +11163 -0
- package/dist/index.d.cts +4240 -0
- package/dist/index.d.ts +4240 -0
- package/dist/index.js +11130 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Sam Atawy
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# @samatawy/diagrams
|
|
2
|
+
|
|
3
|
+
Browser-first TypeScript toolkit for diagram editing, model manipulation, and viewport operations.
|
|
4
|
+
|
|
5
|
+
It includes a reusable diagram model, node adapters, Canvas-based rendering primitives, and an embeddable editor shell that you can extend for your own application.
|
|
6
|
+
|
|
7
|
+
## Status
|
|
8
|
+
|
|
9
|
+
This package is being published as a first public draft.
|
|
10
|
+
|
|
11
|
+
- Ready for evaluation, prototypes, and internal tooling.
|
|
12
|
+
- Not yet recommended for production workloads.
|
|
13
|
+
- Expect API refinements while customization points stabilize.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @samatawy/diagrams
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## What This Package Is
|
|
22
|
+
|
|
23
|
+
- A typed diagram model with nodes, connections, layers, styles, and serialization.
|
|
24
|
+
- A browser editor runtime (`DiagramEditView`, `DiagramEditor`, toolbars, controls).
|
|
25
|
+
- Viewport helpers for zoom, pan, and fit operations.
|
|
26
|
+
- Extension points via node adapters and registries.
|
|
27
|
+
|
|
28
|
+
## Core Features
|
|
29
|
+
|
|
30
|
+
- Diagram create/open/save/export flows.
|
|
31
|
+
- Selection, move, resize, rotate, align, distribute.
|
|
32
|
+
- Stroke/fill/font/shadow editing controls.
|
|
33
|
+
- Connection anchors and arrow support.
|
|
34
|
+
- Grid visibility and snap-to-grid support.
|
|
35
|
+
- Undo/redo history.
|
|
36
|
+
- SVG/Canvas-friendly data model and rendering pipeline.
|
|
37
|
+
|
|
38
|
+
## Typical Use Cases
|
|
39
|
+
|
|
40
|
+
- Workflow or process editors.
|
|
41
|
+
- Architecture and topology sketching tools.
|
|
42
|
+
- Domain-specific visual designers.
|
|
43
|
+
- Internal operational dashboards that need lightweight diagram editing.
|
|
44
|
+
|
|
45
|
+
## Browser Usage
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { DiagramEditor } from '@samatawy/diagrams';
|
|
49
|
+
|
|
50
|
+
const host = document.getElementById('editor-host')!;
|
|
51
|
+
const editor = new DiagramEditor(host);
|
|
52
|
+
|
|
53
|
+
const diagram = editor.getDiagramView();
|
|
54
|
+
diagram.setTool('rectangle');
|
|
55
|
+
diagram.newNode(40, 40);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Node Usage (Model/Transforms)
|
|
59
|
+
|
|
60
|
+
The model and transform utilities can be used in Node.js workflows (for generation, conversion, tests, or automation) without mounting the browser editor UI.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { createDiagram, upsertNode, connectNodes } from '@samatawy/diagrams';
|
|
64
|
+
|
|
65
|
+
let doc = createDiagram('pipeline');
|
|
66
|
+
|
|
67
|
+
doc = upsertNode(doc, {
|
|
68
|
+
id: 'start',
|
|
69
|
+
label: 'Start',
|
|
70
|
+
width: 140,
|
|
71
|
+
height: 52,
|
|
72
|
+
position: { x: 24, y: 24 },
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
doc = upsertNode(doc, {
|
|
76
|
+
id: 'next',
|
|
77
|
+
label: 'Next',
|
|
78
|
+
width: 140,
|
|
79
|
+
height: 52,
|
|
80
|
+
position: { x: 240, y: 24 },
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
doc = connectNodes(doc, { id: 'start-next', from: 'start', to: 'next' });
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Customization
|
|
87
|
+
|
|
88
|
+
You can tailor the editor for your own product:
|
|
89
|
+
|
|
90
|
+
- Register custom node adapters and icons.
|
|
91
|
+
- Override toolbar layouts and actions.
|
|
92
|
+
- Provide custom file dialog handlers for open/save/export.
|
|
93
|
+
- Style and wire custom UI controls around `DiagramEditView`.
|
|
94
|
+
|
|
95
|
+
## Documentation And Demo
|
|
96
|
+
|
|
97
|
+
- API docs (GitHub Pages): https://samatawy.github.io/diagrams/
|
|
98
|
+
- Hosted demos: https://samatawy.github.io/diagrams/demo/
|
|
99
|
+
|
|
100
|
+
## Development Scripts
|
|
101
|
+
|
|
102
|
+
- `npm run lint`
|
|
103
|
+
- `npm run test`
|
|
104
|
+
- `npm run build`
|
|
105
|
+
- `npm run docs`
|
|
106
|
+
- `npm run site`
|
|
107
|
+
|