@cnvx/nodal 0.4.0 → 0.5.1
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/dist/BaseEdge.svelte +3 -3
- package/dist/BaseEdge.svelte.d.ts +1 -1
- package/dist/Surface.svelte +15 -8
- package/dist/Surface.svelte.d.ts +3 -2
- package/dist/index.d.ts +1 -0
- package/dist/svelte-actions.js +19 -1
- package/package.json +1 -1
package/dist/BaseEdge.svelte
CHANGED
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
|
|
4
4
|
export interface NodalEdgeProps {
|
|
5
5
|
edge: SurfaceEdge;
|
|
6
|
-
|
|
6
|
+
d: string;
|
|
7
7
|
}
|
|
8
8
|
</script>
|
|
9
9
|
|
|
10
10
|
<script lang="ts">
|
|
11
|
-
const { edge,
|
|
11
|
+
const { edge, d }: NodalEdgeProps = $props();
|
|
12
12
|
</script>
|
|
13
13
|
|
|
14
14
|
<path
|
|
15
|
-
d
|
|
15
|
+
{d}
|
|
16
16
|
fill="none"
|
|
17
17
|
stroke-width="2"
|
|
18
18
|
stroke="currentColor"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SurfaceEdge } from "./Surface.svelte";
|
|
2
2
|
export interface NodalEdgeProps {
|
|
3
3
|
edge: SurfaceEdge;
|
|
4
|
-
|
|
4
|
+
d: string;
|
|
5
5
|
}
|
|
6
6
|
declare const BaseEdge: import("svelte").Component<NodalEdgeProps, {}, "">;
|
|
7
7
|
type BaseEdge = ReturnType<typeof BaseEdge>;
|
package/dist/Surface.svelte
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
getNodeAnchorWithBoundingClientRect,
|
|
18
18
|
} from "./layout-utils.js";
|
|
19
19
|
import { fade } from "svelte/transition";
|
|
20
|
+
import type { ComponentProps } from "svelte";
|
|
20
21
|
|
|
21
22
|
type PathGenParams =
|
|
22
23
|
| {
|
|
@@ -30,12 +31,13 @@
|
|
|
30
31
|
center?: Vector2;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
|
-
export type SurfaceEdgeParams =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
export type SurfaceEdgeParams<C extends typeof BaseEdge = typeof BaseEdge> =
|
|
35
|
+
{
|
|
36
|
+
component?: C | [C, Omit<ComponentProps<C>, "d" | "edge">];
|
|
37
|
+
sourceAnchor?: Vector2;
|
|
38
|
+
targetAnchor?: Vector2;
|
|
39
|
+
svgPathAttributes?: HTMLAttributes<SVGPathElement>;
|
|
40
|
+
} & PathGenParams;
|
|
39
41
|
|
|
40
42
|
// export type SurfaceEdge = {
|
|
41
43
|
|
|
@@ -253,9 +255,14 @@
|
|
|
253
255
|
{#if svg}
|
|
254
256
|
<g in:fade={{ duration: fadeInDuration }}>
|
|
255
257
|
{#each edges.values() as edge}
|
|
256
|
-
{#each generateEdgePath(edge) as
|
|
258
|
+
{#each generateEdgePath(edge) as d}
|
|
257
259
|
{@const EdgeComponent = edge.component ?? BaseEdge}
|
|
258
|
-
|
|
260
|
+
{#if Array.isArray(EdgeComponent)}
|
|
261
|
+
{@const [EdgeComp, edgeProps] = EdgeComponent}
|
|
262
|
+
<EdgeComp {d} {edge} {...edgeProps} />
|
|
263
|
+
{:else}
|
|
264
|
+
<EdgeComponent {d} {edge} />
|
|
265
|
+
{/if}
|
|
259
266
|
{/each}
|
|
260
267
|
{/each}
|
|
261
268
|
</g>
|
package/dist/Surface.svelte.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { type Vector2 } from "./diagram-lib.js";
|
|
|
4
4
|
import type { HTMLAttributes } from "svelte/elements";
|
|
5
5
|
import type { Writable } from "svelte/store";
|
|
6
6
|
import { getNodeAnchorFast } from "./layout-utils.js";
|
|
7
|
+
import type { ComponentProps } from "svelte";
|
|
7
8
|
type PathGenParams = {
|
|
8
9
|
pathGen?: "bezier";
|
|
9
10
|
curvature?: number;
|
|
@@ -13,8 +14,8 @@ type PathGenParams = {
|
|
|
13
14
|
borderRadius?: number;
|
|
14
15
|
center?: Vector2;
|
|
15
16
|
};
|
|
16
|
-
export type SurfaceEdgeParams = {
|
|
17
|
-
component?:
|
|
17
|
+
export type SurfaceEdgeParams<C extends typeof BaseEdge = typeof BaseEdge> = {
|
|
18
|
+
component?: C | [C, Omit<ComponentProps<C>, "d" | "edge">];
|
|
18
19
|
sourceAnchor?: Vector2;
|
|
19
20
|
targetAnchor?: Vector2;
|
|
20
21
|
svgPathAttributes?: HTMLAttributes<SVGPathElement>;
|
package/dist/index.d.ts
CHANGED
package/dist/svelte-actions.js
CHANGED
|
@@ -2,6 +2,22 @@ import { mount } from "svelte";
|
|
|
2
2
|
import { SvelteMap } from "svelte/reactivity";
|
|
3
3
|
import { writable } from "svelte/store";
|
|
4
4
|
import Surface from "./Surface.svelte";
|
|
5
|
+
let elementIdCounter = 0;
|
|
6
|
+
function getElementId(el) {
|
|
7
|
+
if (el.id)
|
|
8
|
+
return `#${el.id}`;
|
|
9
|
+
if (!el.dataset.nodalUid) {
|
|
10
|
+
el.dataset.nodalUid = `nodal-${elementIdCounter++}`;
|
|
11
|
+
}
|
|
12
|
+
return `[data-nodal-uid="${el.dataset.nodalUid}"]`;
|
|
13
|
+
}
|
|
14
|
+
function getEdgeEndpointKey(endpoint) {
|
|
15
|
+
if (typeof endpoint === "string")
|
|
16
|
+
return endpoint;
|
|
17
|
+
if (endpoint instanceof HTMLElement)
|
|
18
|
+
return getElementId(endpoint);
|
|
19
|
+
return endpoint.map(e => typeof e === "string" ? e : getElementId(e)).join(",");
|
|
20
|
+
}
|
|
5
21
|
function drawCall(surface) {
|
|
6
22
|
// console.debug("Drawing nodal surface edges...");
|
|
7
23
|
const connections = surface.querySelectorAll("[data-nodal-connected='true']");
|
|
@@ -28,7 +44,9 @@ function drawCall(surface) {
|
|
|
28
44
|
...edge,
|
|
29
45
|
};
|
|
30
46
|
}
|
|
31
|
-
|
|
47
|
+
const sourceKey = getEdgeEndpointKey(edgeDef.source);
|
|
48
|
+
const targetKey = getEdgeEndpointKey(edgeDef.target);
|
|
49
|
+
surface._nodalSurface.internals.edges.set(`${sourceKey}->${targetKey}`, edgeDef);
|
|
32
50
|
});
|
|
33
51
|
});
|
|
34
52
|
}
|