@cnvx/nodal 0.0.1 → 0.0.3

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 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,222 @@
1
- # Svelte library
1
+ # 🦔 nodal
2
+
3
+ A Svelte 5 library for creating interactive node diagrams with customizable connections and layouts
4
+
5
+ ## Goals
6
+ - Simple declarative API
7
+ - Static rendering by default
8
+ - SVG Rendering
9
+ - Fully typed
10
+
11
+ ## Quick Start
12
+
13
+ ```svelte
14
+ <script lang="ts">
15
+ import { DiagramController, DiagramNode } from 'nodal';
16
+ </script>
17
+
18
+ <DiagramController class="w-full h-96 border rounded-lg">
19
+ <DiagramNode
20
+ id="start"
21
+ x={100}
22
+ y={100}
23
+ width={120}
24
+ height={60}
25
+ connect="end"
26
+ class="bg-blue-500 text-white rounded-lg flex items-center justify-center"
27
+ >
28
+ Start
29
+ </DiagramNode>
30
+
31
+ <DiagramNode
32
+ id="end"
33
+ x={300}
34
+ y={100}
35
+ width={120}
36
+ height={60}
37
+ class="bg-green-500 text-white rounded-lg flex items-center justify-center"
38
+ >
39
+ End
40
+ </DiagramNode>
41
+ </DiagramController>
42
+ ```
2
43
 
3
- Everything you need to build a Svelte library, powered by [`sv`](https://npmjs.com/package/sv).
44
+ ## API Reference
45
+
46
+ ### Components
47
+
48
+ #### `DiagramController`
49
+ The main container component that manages nodes and their connections.
50
+
51
+ **Props:**
52
+ - Standard HTML div attributes for styling and classes
53
+
54
+ #### `DiagramNode`
55
+ Individual nodes in the diagram.
56
+
57
+ **Props:**
58
+ - `id: string` - Unique identifier for the node
59
+ - `x: number` - X coordinate position
60
+ - `y: number` - Y coordinate position
61
+ - `width?: number` - Fixed width (optional if using autosize)
62
+ - `height?: number` - Fixed height (optional if using autosize)
63
+ - `connect?: string | DiagramEdgeParams | Array<string | DiagramEdgeParams>` - Outgoing connections
64
+ - `connectSource?: string | DiagramEdgeParams | Array<string | DiagramEdgeParams>` - Incoming connections
65
+ - `autosize?: boolean` - Auto-size to fit content
66
+ - `origin?: Vector2` - Origin point for positioning (default: center)
67
+ - `clientOnly?: boolean` - Render only on client side
68
+ - Standard HTML div attributes for styling
69
+
70
+ ### Connection Types
71
+
72
+ #### Bezier Curves
73
+ Smooth curved connections perfect for organic layouts.
74
+
75
+ ```svelte
76
+ <DiagramNode
77
+ connect={{
78
+ target: "destination",
79
+ pathGen: "bezier",
80
+ curvature: 0.5,
81
+ sourceAnchor: Anchor.CENTER_RIGHT,
82
+ targetAnchor: Anchor.CENTER_LEFT
83
+ }}
84
+ />
85
+ ```
4
86
 
5
- Read more about creating a library [in the docs](https://svelte.dev/docs/kit/packaging).
87
+ #### Smooth Step
88
+ Right-angled connections with rounded corners, ideal for structured diagrams.
89
+
90
+ ```svelte
91
+ <DiagramNode
92
+ connect={{
93
+ target: "destination",
94
+ pathGen: "smoothstep",
95
+ borderRadius: 10,
96
+ center: { x: 0.5, y: 0.3 }
97
+ }}
98
+ />
99
+ ```
6
100
 
7
- ## Creating a project
101
+ ### Anchoring System
8
102
 
9
- If you're seeing this, you've probably already done this step. Congrats!
103
+ Use predefined anchor points for precise connection positioning:
10
104
 
11
- ```bash
12
- # create a new project in the current directory
13
- npx sv create
105
+ ```ts
106
+ import { Anchor } from 'nodal';
14
107
 
15
- # create a new project in my-app
16
- npx sv create my-app
108
+ // Available anchors:
109
+ Anchor.TOP_LEFT // { x: 0, y: 0 }
110
+ Anchor.TOP_RIGHT // { x: 1, y: 0 }
111
+ Anchor.BOTTOM_LEFT // { x: 0, y: 1 }
112
+ Anchor.BOTTOM_RIGHT // { x: 1, y: 1 }
113
+ Anchor.CENTER_LEFT // { x: 0, y: 0.5 }
114
+ Anchor.CENTER_RIGHT // { x: 1, y: 0.5 }
115
+ Anchor.CENTER_TOP // { x: 0.5, y: 0 }
116
+ Anchor.CENTER_BOTTOM // { x: 0.5, y: 1 }
117
+ Anchor.CENTER_CENTER // { x: 0.5, y: 0.5 }
17
118
  ```
18
119
 
19
- ## Developing
20
-
21
- Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
22
-
23
- ```bash
24
- npm run dev
25
-
26
- # or start the server and open the app in a new browser tab
27
- npm run dev -- --open
120
+ ### Custom Edge Rendering
121
+
122
+ Create custom edge appearances with the `snippet` prop:
123
+
124
+ ```svelte
125
+ <DiagramNode
126
+ connect={{
127
+ target: "destination",
128
+ snippet: (edge, path, extra) => `
129
+ <path
130
+ d="${path}"
131
+ stroke="#3b82f6"
132
+ stroke-width="3"
133
+ fill="none"
134
+ marker-end="url(#arrow)"
135
+ />
136
+ `,
137
+ snippetExtraArg: { labelText: "Custom Edge" }
138
+ }}
139
+ />
28
140
  ```
29
141
 
30
- Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
142
+ ## Examples
31
143
 
32
- ## Building
144
+ ### Basic Flow Diagram
145
+ ```svelte
146
+ <script lang="ts">
147
+ import { DiagramController, DiagramNode } from 'nodal';
148
+ </script>
33
149
 
34
- To build your library:
150
+ <DiagramController class="w-full h-96 bg-gray-50 rounded-lg">
151
+ <DiagramNode id="start" x={100} y={150} width={100} height={50} connect="process">
152
+ Start
153
+ </DiagramNode>
35
154
 
36
- ```bash
37
- npm run package
38
- ```
155
+ <DiagramNode id="process" x={250} y={150} width={100} height={50} connect="end">
156
+ Process
157
+ </DiagramNode>
39
158
 
40
- To create a production version of your showcase app:
41
-
42
- ```bash
43
- npm run build
159
+ <DiagramNode id="end" x={400} y={150} width={100} height={50}>
160
+ End
161
+ </DiagramNode>
162
+ </DiagramController>
44
163
  ```
45
164
 
46
- You can preview the production build with `npm run preview`.
47
-
48
- > To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
165
+ ### Auto-Sizing Nodes
166
+ ```svelte
167
+ <DiagramNode
168
+ id="dynamic"
169
+ x={200}
170
+ y={100}
171
+ autosize
172
+ connect="target"
173
+ class="bg-blue-500 text-white px-4 py-2 rounded"
174
+ >
175
+ This content determines the size
176
+ </DiagramNode>
177
+ ```
49
178
 
50
- ## Publishing
179
+ ### Multiple Connections
180
+ ```svelte
181
+ <DiagramNode
182
+ id="hub"
183
+ x={200}
184
+ y={200}
185
+ width={80}
186
+ height={80}
187
+ connect={[
188
+ { target: "output1", pathGen: "bezier", curvature: 0.3 },
189
+ { target: "output2", pathGen: "smoothstep", borderRadius: 15 },
190
+ "output3" // Simple string connection
191
+ ]}
192
+ >
193
+ Hub
194
+ </DiagramNode>
195
+ ```
51
196
 
52
- Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
197
+ ## TypeScript Support
198
+
199
+ Full TypeScript support with comprehensive type definitions:
200
+
201
+ ```ts
202
+ import type {
203
+ DiagramNodeType,
204
+ DiagramEdge,
205
+ DiagramEdgeParams,
206
+ Vector2
207
+ } from 'nodal';
208
+
209
+ const nodes: DiagramNodeType[] = [
210
+ {
211
+ id: "node1",
212
+ x: 100,
213
+ y: 100,
214
+ width: 120,
215
+ height: 60
216
+ }
217
+ ];
218
+ ```
53
219
 
54
- To publish your library to [npm](https://www.npmjs.com):
220
+ ## License
55
221
 
56
- ```bash
57
- npm publish
58
- ```
222
+ MIT License - see LICENSE file for details.
@@ -1,5 +1,7 @@
1
1
  <script lang="ts" module>
2
- import { browser, dev } from "$app/environment";
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 {
@@ -1,6 +1,6 @@
1
1
  import { type Snippet } from "svelte";
2
2
  import { SvelteMap } from "svelte/reactivity";
3
- import { type Vector2 } from "./diagram-lib";
3
+ import { type Vector2 } from "./diagram-lib.js";
4
4
  export interface DiagramNode {
5
5
  id: string;
6
6
  x: number;
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';
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@cnvx/nodal",
3
3
  "private": false,
4
- "version": "0.0.1",
4
+ "license": "MIT",
5
+ "version": "0.0.3",
5
6
  "scripts": {
6
7
  "dev": "vite dev",
7
8
  "build": "vite build && npm run prepack",
@@ -59,7 +60,19 @@
59
60
  "vitest": "^3.2.3",
60
61
  "vitest-browser-svelte": "^0.1.0"
61
62
  },
62
- "keywords": [
63
- "svelte"
64
- ]
63
+ "keywords": [
64
+ "svelte",
65
+ "diagram",
66
+ "nodes",
67
+ "graph",
68
+ "visualization",
69
+ "flow-chart",
70
+ "connections",
71
+ "bezier",
72
+ "smoothstep"
73
+ ],
74
+ "repository": {
75
+ "type": "git",
76
+ "url": "https://github.com/Convex-Works/nodal.git"
77
+ }
65
78
  }