@cnvx/nodal 0.1.3 → 0.1.4
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/Diagram.svelte
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
browser,
|
|
15
15
|
dev,
|
|
16
16
|
} from "./diagram-lib.js";
|
|
17
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
17
18
|
|
|
18
19
|
export interface DiagramNodeDef {
|
|
19
20
|
id: string;
|
|
@@ -61,6 +62,7 @@
|
|
|
61
62
|
edges: SvelteMap<string, DiagramEdgeDef>;
|
|
62
63
|
children: Snippet;
|
|
63
64
|
scaleToFit?: boolean;
|
|
65
|
+
figureAttributes: HTMLAttributes<HTMLElement>;
|
|
64
66
|
};
|
|
65
67
|
|
|
66
68
|
// const getNodeOrigin = (node: DiagramNode) => node.origin ?? vector2(0.0, 0.5);
|
|
@@ -74,7 +76,8 @@
|
|
|
74
76
|
</script>
|
|
75
77
|
|
|
76
78
|
<script lang="ts">
|
|
77
|
-
let { nodes, edges, children, scaleToFit }: DiagramProps =
|
|
79
|
+
let { nodes, edges, children, scaleToFit, figureAttributes }: DiagramProps =
|
|
80
|
+
$props();
|
|
78
81
|
export function generateCurvePath(
|
|
79
82
|
x1: number,
|
|
80
83
|
y1: number,
|
|
@@ -95,7 +98,7 @@
|
|
|
95
98
|
return normaliseAngle(raw);
|
|
96
99
|
}
|
|
97
100
|
|
|
98
|
-
// CRUCIAL TO
|
|
101
|
+
// CRUCIAL TO INVERT THE Y DIRECTION SINCE IT GOES FROM
|
|
99
102
|
// NEGATIVE TO POSITIVE!!!!!!!!!!!!!
|
|
100
103
|
const leaveAngle = Math.atan2(y1 - y2, x2 - x1);
|
|
101
104
|
const arriveAngle = leaveAngle + Math.PI;
|
|
@@ -293,6 +296,7 @@
|
|
|
293
296
|
aria-label="Diagram"
|
|
294
297
|
aria-hidden={!dev}
|
|
295
298
|
inert={!dev}
|
|
299
|
+
{...figureAttributes}
|
|
296
300
|
role="img"
|
|
297
301
|
style="position:relative;width:{width}px;height:{height}px;overflow:visible;user-select:none;transform:scale({scale});transform-origin:center center;"
|
|
298
302
|
>
|
package/dist/Diagram.svelte.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Snippet } from "svelte";
|
|
2
2
|
import { SvelteMap } from "svelte/reactivity";
|
|
3
3
|
import { type Vector2 } from "./diagram-lib.js";
|
|
4
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
4
5
|
export interface DiagramNodeDef {
|
|
5
6
|
id: string;
|
|
6
7
|
x: number;
|
|
@@ -36,6 +37,7 @@ export type DiagramProps = {
|
|
|
36
37
|
edges: SvelteMap<string, DiagramEdgeDef>;
|
|
37
38
|
children: Snippet;
|
|
38
39
|
scaleToFit?: boolean;
|
|
40
|
+
figureAttributes: HTMLAttributes<HTMLElement>;
|
|
39
41
|
};
|
|
40
42
|
declare const Diagram: import("svelte").Component<DiagramProps, {
|
|
41
43
|
generateCurvePath: (x1: number, y1: number, x2: number, y2: number, edge: DiagramEdgeDef) => string;
|
|
@@ -20,12 +20,14 @@
|
|
|
20
20
|
eagerLoad = false,
|
|
21
21
|
scaleToFit = false,
|
|
22
22
|
rootMargin = "100px", // start a bit before it enters the viewport
|
|
23
|
+
figureAttributes = { inert: true, "aria-hidden": true },
|
|
23
24
|
...rest
|
|
24
25
|
}: {
|
|
25
26
|
children: Snippet;
|
|
26
27
|
eagerLoad?: boolean;
|
|
27
28
|
scaleToFit?: boolean;
|
|
28
29
|
rootMargin?: string;
|
|
30
|
+
figureAttributes: HTMLAttributes<HTMLElement>;
|
|
29
31
|
} & HTMLAttributes<HTMLDivElement> = $props();
|
|
30
32
|
|
|
31
33
|
const nodes = new SvelteMap<string, DiagramNodeDef>();
|
|
@@ -87,11 +89,11 @@
|
|
|
87
89
|
|
|
88
90
|
{#if shouldRender}
|
|
89
91
|
<!-- first pass: register all the nodes and edges -->
|
|
90
|
-
<PrerenderDiagram {nodes} {edges} {children} />
|
|
92
|
+
<PrerenderDiagram {nodes} {edges} {children} {figureAttributes} />
|
|
91
93
|
|
|
92
94
|
<!-- second pass: render with computed positions -->
|
|
93
95
|
<div {...rest}>
|
|
94
|
-
<Diagram {nodes} {edges} {scaleToFit}>
|
|
96
|
+
<Diagram {nodes} {edges} {scaleToFit} {figureAttributes}>
|
|
95
97
|
{@render children()}
|
|
96
98
|
</Diagram>
|
|
97
99
|
</div>
|
|
@@ -5,6 +5,7 @@ type $$ComponentProps = {
|
|
|
5
5
|
eagerLoad?: boolean;
|
|
6
6
|
scaleToFit?: boolean;
|
|
7
7
|
rootMargin?: string;
|
|
8
|
+
figureAttributes: HTMLAttributes<HTMLElement>;
|
|
8
9
|
} & HTMLAttributes<HTMLDivElement>;
|
|
9
10
|
declare const DiagramController: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
10
11
|
type DiagramController = ReturnType<typeof DiagramController>;
|