@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 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
- # Svelte library
1
+ # 🦔 nodal
2
2
 
3
- Everything you need to build a Svelte library, powered by [`sv`](https://npmjs.com/package/sv).
3
+ A Svelte 5 library for creating interactive node diagrams with customizable connections and layouts
4
4
 
5
- Read more about creating a library [in the docs](https://svelte.dev/docs/kit/packaging).
5
+ ## Goals
6
+ - Simple declarative API
7
+ - Static rendering by default
8
+ - SVG Rendering
9
+ - Fully typed
6
10
 
7
- ## Creating a project
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
- # create a new project in the current directory
13
- npx sv create
15
+ # Deno
16
+ deno add @cnvx/nodal
14
17
 
15
- # create a new project in my-app
16
- npx sv create my-app
17
- ```
18
+ # npm
19
+ npx jsr add @cnvx/nodal
18
20
 
19
- ## Developing
21
+ # Yarn
22
+ yarn dlx jsr add @cnvx/nodal
20
23
 
21
- Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
24
+ # pnpm
25
+ pnpm dlx jsr add @cnvx/nodal
22
26
 
23
- ```bash
24
- npm run dev
27
+ # Bun
28
+ bunx jsr add @cnvx/nodal
29
+ ```
25
30
 
26
- # or start the server and open the app in a new browser tab
27
- npm run dev -- --open
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
- Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
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
- ## Building
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
- To build your library:
121
+ ### Anchoring System
35
122
 
36
- ```bash
37
- npm run package
38
- ```
123
+ Use predefined anchor points for precise connection positioning:
39
124
 
40
- To create a production version of your showcase app:
125
+ ```ts
126
+ import { Anchor } from 'nodal';
41
127
 
42
- ```bash
43
- npm run build
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
- You can preview the production build with `npm run preview`.
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
- > To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
162
+ ## Examples
49
163
 
50
- ## Publishing
164
+ ### Basic Flow Diagram
165
+ ```svelte
166
+ <script lang="ts">
167
+ import { DiagramController, DiagramNode } from 'nodal';
168
+ </script>
51
169
 
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/)).
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
- To publish your library to [npm](https://www.npmjs.com):
175
+ <DiagramNode id="process" x={250} y={150} width={100} height={50} connect="end">
176
+ Process
177
+ </DiagramNode>
55
178
 
56
- ```bash
57
- npm publish
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.
@@ -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.2",
5
6
  "scripts": {
6
7
  "dev": "vite dev",
7
8
  "build": "vite build && npm run prepack",