@cnvx/nodal 0.0.1 → 0.0.2
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 +21 -0
- package/README.md +217 -33
- package/dist/Diagram.svelte +4 -2
- package/dist/Diagram.svelte.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Nodal Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,58 +1,242 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 🦔 nodal
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Svelte 5 library for creating interactive node diagrams with customizable connections and layouts
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Goals
|
|
6
|
+
- Simple declarative API
|
|
7
|
+
- Static rendering by default
|
|
8
|
+
- SVG Rendering
|
|
9
|
+
- Fully typed
|
|
6
10
|
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
If you're seeing this, you've probably already done this step. Congrats!
|
|
11
|
+
## Installation
|
|
10
12
|
|
|
13
|
+
### JSR (JavaScript Registry)
|
|
11
14
|
```bash
|
|
12
|
-
#
|
|
13
|
-
|
|
15
|
+
# Deno
|
|
16
|
+
deno add @cnvx/nodal
|
|
14
17
|
|
|
15
|
-
#
|
|
16
|
-
npx
|
|
17
|
-
```
|
|
18
|
+
# npm
|
|
19
|
+
npx jsr add @cnvx/nodal
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
# Yarn
|
|
22
|
+
yarn dlx jsr add @cnvx/nodal
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
# pnpm
|
|
25
|
+
pnpm dlx jsr add @cnvx/nodal
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
# Bun
|
|
28
|
+
bunx jsr add @cnvx/nodal
|
|
29
|
+
```
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
```svelte
|
|
34
|
+
<script lang="ts">
|
|
35
|
+
import { DiagramController, DiagramNode } from 'nodal';
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<DiagramController class="w-full h-96 border rounded-lg">
|
|
39
|
+
<DiagramNode
|
|
40
|
+
id="start"
|
|
41
|
+
x={100}
|
|
42
|
+
y={100}
|
|
43
|
+
width={120}
|
|
44
|
+
height={60}
|
|
45
|
+
connect="end"
|
|
46
|
+
class="bg-blue-500 text-white rounded-lg flex items-center justify-center"
|
|
47
|
+
>
|
|
48
|
+
Start
|
|
49
|
+
</DiagramNode>
|
|
50
|
+
|
|
51
|
+
<DiagramNode
|
|
52
|
+
id="end"
|
|
53
|
+
x={300}
|
|
54
|
+
y={100}
|
|
55
|
+
width={120}
|
|
56
|
+
height={60}
|
|
57
|
+
class="bg-green-500 text-white rounded-lg flex items-center justify-center"
|
|
58
|
+
>
|
|
59
|
+
End
|
|
60
|
+
</DiagramNode>
|
|
61
|
+
</DiagramController>
|
|
28
62
|
```
|
|
29
63
|
|
|
30
|
-
|
|
64
|
+
## API Reference
|
|
65
|
+
|
|
66
|
+
### Components
|
|
67
|
+
|
|
68
|
+
#### `DiagramController`
|
|
69
|
+
The main container component that manages nodes and their connections.
|
|
70
|
+
|
|
71
|
+
**Props:**
|
|
72
|
+
- Standard HTML div attributes for styling and classes
|
|
73
|
+
|
|
74
|
+
#### `DiagramNode`
|
|
75
|
+
Individual nodes in the diagram.
|
|
76
|
+
|
|
77
|
+
**Props:**
|
|
78
|
+
- `id: string` - Unique identifier for the node
|
|
79
|
+
- `x: number` - X coordinate position
|
|
80
|
+
- `y: number` - Y coordinate position
|
|
81
|
+
- `width?: number` - Fixed width (optional if using autosize)
|
|
82
|
+
- `height?: number` - Fixed height (optional if using autosize)
|
|
83
|
+
- `connect?: string | DiagramEdgeParams | Array<string | DiagramEdgeParams>` - Outgoing connections
|
|
84
|
+
- `connectSource?: string | DiagramEdgeParams | Array<string | DiagramEdgeParams>` - Incoming connections
|
|
85
|
+
- `autosize?: boolean` - Auto-size to fit content
|
|
86
|
+
- `origin?: Vector2` - Origin point for positioning (default: center)
|
|
87
|
+
- `clientOnly?: boolean` - Render only on client side
|
|
88
|
+
- Standard HTML div attributes for styling
|
|
89
|
+
|
|
90
|
+
### Connection Types
|
|
91
|
+
|
|
92
|
+
#### Bezier Curves
|
|
93
|
+
Smooth curved connections perfect for organic layouts.
|
|
94
|
+
|
|
95
|
+
```svelte
|
|
96
|
+
<DiagramNode
|
|
97
|
+
connect={{
|
|
98
|
+
target: "destination",
|
|
99
|
+
pathGen: "bezier",
|
|
100
|
+
curvature: 0.5,
|
|
101
|
+
sourceAnchor: Anchor.CENTER_RIGHT,
|
|
102
|
+
targetAnchor: Anchor.CENTER_LEFT
|
|
103
|
+
}}
|
|
104
|
+
/>
|
|
105
|
+
```
|
|
31
106
|
|
|
32
|
-
|
|
107
|
+
#### Smooth Step
|
|
108
|
+
Right-angled connections with rounded corners, ideal for structured diagrams.
|
|
109
|
+
|
|
110
|
+
```svelte
|
|
111
|
+
<DiagramNode
|
|
112
|
+
connect={{
|
|
113
|
+
target: "destination",
|
|
114
|
+
pathGen: "smoothstep",
|
|
115
|
+
borderRadius: 10,
|
|
116
|
+
center: { x: 0.5, y: 0.3 }
|
|
117
|
+
}}
|
|
118
|
+
/>
|
|
119
|
+
```
|
|
33
120
|
|
|
34
|
-
|
|
121
|
+
### Anchoring System
|
|
35
122
|
|
|
36
|
-
|
|
37
|
-
npm run package
|
|
38
|
-
```
|
|
123
|
+
Use predefined anchor points for precise connection positioning:
|
|
39
124
|
|
|
40
|
-
|
|
125
|
+
```ts
|
|
126
|
+
import { Anchor } from 'nodal';
|
|
41
127
|
|
|
42
|
-
|
|
43
|
-
|
|
128
|
+
// Available anchors:
|
|
129
|
+
Anchor.TOP_LEFT // { x: 0, y: 0 }
|
|
130
|
+
Anchor.TOP_RIGHT // { x: 1, y: 0 }
|
|
131
|
+
Anchor.BOTTOM_LEFT // { x: 0, y: 1 }
|
|
132
|
+
Anchor.BOTTOM_RIGHT // { x: 1, y: 1 }
|
|
133
|
+
Anchor.CENTER_LEFT // { x: 0, y: 0.5 }
|
|
134
|
+
Anchor.CENTER_RIGHT // { x: 1, y: 0.5 }
|
|
135
|
+
Anchor.CENTER_TOP // { x: 0.5, y: 0 }
|
|
136
|
+
Anchor.CENTER_BOTTOM // { x: 0.5, y: 1 }
|
|
137
|
+
Anchor.CENTER_CENTER // { x: 0.5, y: 0.5 }
|
|
44
138
|
```
|
|
45
139
|
|
|
46
|
-
|
|
140
|
+
### Custom Edge Rendering
|
|
141
|
+
|
|
142
|
+
Create custom edge appearances with the `snippet` prop:
|
|
143
|
+
|
|
144
|
+
```svelte
|
|
145
|
+
<DiagramNode
|
|
146
|
+
connect={{
|
|
147
|
+
target: "destination",
|
|
148
|
+
snippet: (edge, path, extra) => `
|
|
149
|
+
<path
|
|
150
|
+
d="${path}"
|
|
151
|
+
stroke="#3b82f6"
|
|
152
|
+
stroke-width="3"
|
|
153
|
+
fill="none"
|
|
154
|
+
marker-end="url(#arrow)"
|
|
155
|
+
/>
|
|
156
|
+
`,
|
|
157
|
+
snippetExtraArg: { labelText: "Custom Edge" }
|
|
158
|
+
}}
|
|
159
|
+
/>
|
|
160
|
+
```
|
|
47
161
|
|
|
48
|
-
|
|
162
|
+
## Examples
|
|
49
163
|
|
|
50
|
-
|
|
164
|
+
### Basic Flow Diagram
|
|
165
|
+
```svelte
|
|
166
|
+
<script lang="ts">
|
|
167
|
+
import { DiagramController, DiagramNode } from 'nodal';
|
|
168
|
+
</script>
|
|
51
169
|
|
|
52
|
-
|
|
170
|
+
<DiagramController class="w-full h-96 bg-gray-50 rounded-lg">
|
|
171
|
+
<DiagramNode id="start" x={100} y={150} width={100} height={50} connect="process">
|
|
172
|
+
Start
|
|
173
|
+
</DiagramNode>
|
|
53
174
|
|
|
54
|
-
|
|
175
|
+
<DiagramNode id="process" x={250} y={150} width={100} height={50} connect="end">
|
|
176
|
+
Process
|
|
177
|
+
</DiagramNode>
|
|
55
178
|
|
|
56
|
-
|
|
57
|
-
|
|
179
|
+
<DiagramNode id="end" x={400} y={150} width={100} height={50}>
|
|
180
|
+
End
|
|
181
|
+
</DiagramNode>
|
|
182
|
+
</DiagramController>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Auto-Sizing Nodes
|
|
186
|
+
```svelte
|
|
187
|
+
<DiagramNode
|
|
188
|
+
id="dynamic"
|
|
189
|
+
x={200}
|
|
190
|
+
y={100}
|
|
191
|
+
autosize
|
|
192
|
+
connect="target"
|
|
193
|
+
class="bg-blue-500 text-white px-4 py-2 rounded"
|
|
194
|
+
>
|
|
195
|
+
This content determines the size
|
|
196
|
+
</DiagramNode>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Multiple Connections
|
|
200
|
+
```svelte
|
|
201
|
+
<DiagramNode
|
|
202
|
+
id="hub"
|
|
203
|
+
x={200}
|
|
204
|
+
y={200}
|
|
205
|
+
width={80}
|
|
206
|
+
height={80}
|
|
207
|
+
connect={[
|
|
208
|
+
{ target: "output1", pathGen: "bezier", curvature: 0.3 },
|
|
209
|
+
{ target: "output2", pathGen: "smoothstep", borderRadius: 15 },
|
|
210
|
+
"output3" // Simple string connection
|
|
211
|
+
]}
|
|
212
|
+
>
|
|
213
|
+
Hub
|
|
214
|
+
</DiagramNode>
|
|
58
215
|
```
|
|
216
|
+
|
|
217
|
+
## TypeScript Support
|
|
218
|
+
|
|
219
|
+
Full TypeScript support with comprehensive type definitions:
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
import type {
|
|
223
|
+
DiagramNodeType,
|
|
224
|
+
DiagramEdge,
|
|
225
|
+
DiagramEdgeParams,
|
|
226
|
+
Vector2
|
|
227
|
+
} from 'nodal';
|
|
228
|
+
|
|
229
|
+
const nodes: DiagramNodeType[] = [
|
|
230
|
+
{
|
|
231
|
+
id: "node1",
|
|
232
|
+
x: 100,
|
|
233
|
+
y: 100,
|
|
234
|
+
width: 120,
|
|
235
|
+
height: 60
|
|
236
|
+
}
|
|
237
|
+
];
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## License
|
|
241
|
+
|
|
242
|
+
MIT License - see LICENSE file for details.
|
package/dist/Diagram.svelte
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<script lang="ts" module>
|
|
2
|
-
|
|
2
|
+
const browser = !!globalThis?.window
|
|
3
|
+
const dev = globalThis.process?.env?.NODE_ENV && !globalThis.process.env.NODE_ENV.toLowerCase().startsWith('prod');
|
|
4
|
+
|
|
3
5
|
import { onMount, setContext, type Snippet } from "svelte";
|
|
4
6
|
import { SvelteMap } from "svelte/reactivity";
|
|
5
7
|
import {
|
|
@@ -14,7 +16,7 @@
|
|
|
14
16
|
vector2,
|
|
15
17
|
type Vector2,
|
|
16
18
|
Anchor,
|
|
17
|
-
} from "./diagram-lib";
|
|
19
|
+
} from "./diagram-lib.js";
|
|
18
20
|
import { draw } from "svelte/transition";
|
|
19
21
|
|
|
20
22
|
export interface DiagramNode {
|
package/dist/Diagram.svelte.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ export { default as Diagram } from './Diagram.svelte';
|
|
|
2
2
|
export { default as DiagramController } from './DiagramController.svelte';
|
|
3
3
|
export { default as DiagramNode } from './DiagramNode.svelte';
|
|
4
4
|
export { default as PrerenderDiagram } from './PrerenderDiagram.svelte';
|
|
5
|
-
export * from './diagram-lib';
|
|
5
|
+
export * from './diagram-lib.js';
|
|
6
6
|
export type { DiagramNode as DiagramNodeType, DiagramEdge, DiagramEdgeParams, DiagramProps } from './Diagram.svelte';
|
|
7
7
|
export type { DiagramNodeProps } from './DiagramNode.svelte';
|
package/dist/index.js
CHANGED
|
@@ -2,4 +2,4 @@ export { default as Diagram } from './Diagram.svelte';
|
|
|
2
2
|
export { default as DiagramController } from './DiagramController.svelte';
|
|
3
3
|
export { default as DiagramNode } from './DiagramNode.svelte';
|
|
4
4
|
export { default as PrerenderDiagram } from './PrerenderDiagram.svelte';
|
|
5
|
-
export * from './diagram-lib';
|
|
5
|
+
export * from './diagram-lib.js';
|