@zsherman/viz 0.0.0-stage → 0.1.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE +373 -0
  3. package/README.md +13 -2
  4. package/THIRD_PARTY_NOTICES.md +79 -0
  5. package/dist/dom/flow/flow.js +370 -0
  6. package/dist/dom/flow/flow.styles.js +158 -0
  7. package/dist/dom/flow/index.js +4 -0
  8. package/dist/dom/flow/layout.js +51 -0
  9. package/dist/dom/geo-map/geo-map.js +1037 -0
  10. package/dist/dom/geo-map/geo-map.styles.js +184 -0
  11. package/dist/dom/geo-map/geometry.js +231 -0
  12. package/dist/dom/geo-map/index.js +3 -0
  13. package/dist/dom/geo-map/types.js +0 -0
  14. package/dist/dom/geo-map/world.js +15 -0
  15. package/dist/dom/index.js +6 -0
  16. package/dist/solid/flow/flow.jsx +180 -0
  17. package/dist/solid/flow/flow.styles.jsx +158 -0
  18. package/dist/solid/flow/index.jsx +4 -0
  19. package/dist/solid/flow/layout.jsx +51 -0
  20. package/dist/solid/geo-map/geo-map.jsx +698 -0
  21. package/dist/solid/geo-map/geo-map.styles.jsx +184 -0
  22. package/dist/solid/geo-map/geometry.jsx +231 -0
  23. package/dist/solid/geo-map/index.jsx +3 -0
  24. package/dist/solid/geo-map/types.jsx +0 -0
  25. package/dist/solid/geo-map/world.jsx +15 -0
  26. package/dist/solid/index.jsx +6 -0
  27. package/dist/styles.css +1 -0
  28. package/dist/types/flow/flow.d.ts +92 -0
  29. package/dist/types/flow/flow.styles.d.ts +137 -0
  30. package/dist/types/flow/index.d.ts +6 -0
  31. package/dist/types/flow/layout.d.ts +47 -0
  32. package/dist/types/geo-map/geo-map.d.ts +70 -0
  33. package/dist/types/geo-map/geo-map.styles.d.ts +188 -0
  34. package/dist/types/geo-map/geometry.d.ts +116 -0
  35. package/dist/types/geo-map/index.d.ts +4 -0
  36. package/dist/types/geo-map/types.d.ts +103 -0
  37. package/dist/types/geo-map/world.d.ts +11 -0
  38. package/dist/types/index.d.ts +2 -0
  39. package/docs/api.json +297 -0
  40. package/docs/flow.md +255 -0
  41. package/docs/geo-map.md +320 -0
  42. package/docs/llms.txt +43 -0
  43. package/docs/search-index.json +64 -0
  44. package/package.json +66 -4
@@ -0,0 +1,370 @@
1
+ import { styles } from "./flow.styles.js";
2
+ import { className, createComponent, effect, getNextElement, getNextMarker, insert, memo, mergeProps, readShallow, scope, setAttribute, style, template } from "@solidjs/web";
3
+ import * as stylex from "@stylexjs/stylex";
4
+ import { Background, BaseEdge, Controls, Handle, MiniMap, SolidFlow, getBezierPath } from "@dschz/solid-flow";
5
+ import { Icon } from "@zsherman/kit/icon";
6
+ import { CircleAlert, CircleCheck, CircleDashed, TriangleAlert } from "@zsherman/kit/icons";
7
+ import { useMessages } from "@zsherman/kit/locale-provider";
8
+ import { Spinner } from "@zsherman/kit/spinner";
9
+ import { VisuallyHidden } from "@zsherman/kit/text";
10
+ import { Show, merge, omit } from "solid-js";
11
+ // src/flow/flow.tsx
12
+ /**
13
+ * Flow: a graph of steps and the data or work moving between them (an ETL pipeline, a deploy, a service
14
+ * map), on @dschz/solid-flow (xyflow's engine for Solid 2). The kit's look comes from three places: the
15
+ * `--xy-*` variables mapped to tokens (src/styles.css), the step node and edge here (StyleX), and themed
16
+ * background, controls and minimap. `readOnly` (the default) is the admin view: pan, zoom and select only.
17
+ */
18
+ var _tmpl$ = /* @__PURE__ */ template(`<div data-slot=flow-node><!$><!/><!$><!/><span><span data-slot=flow-node-title><!$><!/><!$><!/></span><!$><!/></span><!$><!/><!$><!/>`);
19
+ var _tmpl$2 = /* @__PURE__ */ template(`<span data-slot=flow-node-icon aria-hidden=true>`);
20
+ var _tmpl$3 = /* @__PURE__ */ template(`<span data-slot=flow-node-description>`);
21
+ var _tmpl$4 = /* @__PURE__ */ template(`<span data-slot=flow-node-meta>`);
22
+ var _tmpl$5 = /* @__PURE__ */ template(`<div data-slot=flow>`);
23
+ const STATUS_ICONS = {
24
+ pending: CircleDashed,
25
+ success: CircleCheck,
26
+ warning: TriangleAlert,
27
+ error: CircleAlert
28
+ };
29
+ const STATUS_WORDS = {
30
+ pending: "Pending",
31
+ running: "Running",
32
+ success: "Succeeded",
33
+ warning: "Warning",
34
+ error: "Failed"
35
+ };
36
+ const nodeClass = {
37
+ pending: stylex.props(styles.node, styles.pending).className,
38
+ running: stylex.props(styles.node, styles.running).className,
39
+ success: stylex.props(styles.node, styles.success).className,
40
+ warning: stylex.props(styles.node, styles.warning).className,
41
+ error: stylex.props(styles.node, styles.error).className,
42
+ plain: stylex.props(styles.node, styles.plain).className
43
+ };
44
+ const cx = {
45
+ icon: stylex.props(styles.icon).className,
46
+ iconSvg: stylex.props(styles.iconSvg).className,
47
+ body: stylex.props(styles.body).className,
48
+ title: stylex.props(styles.title).className,
49
+ description: stylex.props(styles.description).className,
50
+ meta: stylex.props(styles.meta).className,
51
+ handle: stylex.props(styles.handle).className,
52
+ handleHidden: stylex.props(styles.handle, styles.handleHidden).className,
53
+ edge: stylex.props(styles.edge).className,
54
+ edgeFlowing: stylex.props(styles.edge, styles.flowing).className
55
+ };
56
+ const EDGE_TONES = {
57
+ neutral: "var(--sui-border-strong)",
58
+ accent: "var(--sui-accent)",
59
+ success: "var(--sui-success)",
60
+ warning: "var(--sui-warning)",
61
+ danger: "var(--sui-danger)"
62
+ };
63
+ /**
64
+ * The step node (node type `"step"`): its status icon (the kit Spinner while running), title, description
65
+ * and meta, with its status said before the title for screen readers ("Failed: Load to warehouse"). Handles
66
+ * sit on the sides `layoutFlow` gives it (left and right by default); they show only where connecting is on.
67
+ */
68
+ function FlowNode(props) {
69
+ const messages = useMessages("trace");
70
+ const word = (status) => messages()?.status?.[status] ?? STATUS_WORDS[status];
71
+ const status = () => props.data.status;
72
+ var _el$ = getNextElement(_tmpl$);
73
+ var _el$2 = _el$.firstChild;
74
+ var [_el$3, _el$4] = getNextMarker(_el$2.nextSibling);
75
+ var _el$5 = _el$3.nextSibling;
76
+ var [_el$6, _el$7] = getNextMarker(_el$5.nextSibling);
77
+ var _el$8 = _el$6.nextSibling;
78
+ var _el$9 = _el$8.firstChild;
79
+ var _el$10 = _el$9.firstChild;
80
+ var [_el$11, _el$12] = getNextMarker(_el$10.nextSibling);
81
+ var _el$13 = _el$11.nextSibling;
82
+ var [_el$14, _el$15] = getNextMarker(_el$13.nextSibling);
83
+ var _el$16 = _el$9.nextSibling;
84
+ var [_el$17, _el$18] = getNextMarker(_el$16.nextSibling);
85
+ var _el$19 = _el$8.nextSibling;
86
+ var [_el$20, _el$21] = getNextMarker(_el$19.nextSibling);
87
+ var _el$22 = _el$20.nextSibling;
88
+ var [_el$23, _el$24] = getNextMarker(_el$22.nextSibling);
89
+ insert(_el$, createComponent(Handle, {
90
+ type: "target",
91
+ get position() {
92
+ return props.targetPosition ?? "left";
93
+ },
94
+ get isConnectable() {
95
+ return props.isConnectable;
96
+ },
97
+ get "class"() {
98
+ return memo(() => {
99
+ return !!props.isConnectable;
100
+ })() ? cx.handle : cx.handleHidden;
101
+ }
102
+ }), _el$3, _el$4);
103
+ insert(_el$, scope((() => {
104
+ var _c$ = memo(() => {
105
+ return !!(status() || props.data.icon);
106
+ });
107
+ return () => {
108
+ return _c$() ? (() => {
109
+ var _el$25 = getNextElement(_tmpl$2);
110
+ insert(_el$25, scope((() => {
111
+ var _c$2 = memo(() => {
112
+ return !!(status() === "running" && !props.data.icon);
113
+ });
114
+ return () => {
115
+ return _c$2() ? createComponent(Spinner, {
116
+ decorative: true,
117
+ style: { "--spinner-size": "1rem" }
118
+ }) : createComponent(Icon, {
119
+ get icon() {
120
+ return props.data.icon ?? STATUS_ICONS[status() ?? "pending"];
121
+ },
122
+ get "class"() {
123
+ return cx.iconSvg;
124
+ }
125
+ });
126
+ };
127
+ })()));
128
+ effect(() => readShallow(cx.icon), (_v$, _$p) => {
129
+ className(_el$25, _v$, _$p);
130
+ });
131
+ return _el$25;
132
+ })() : void 0;
133
+ };
134
+ })()), _el$6, _el$7);
135
+ insert(_el$9, createComponent(Show, {
136
+ get when() {
137
+ return status();
138
+ },
139
+ children: (s) => createComponent(VisuallyHidden, { get children() {
140
+ return `${word(s())}: `;
141
+ } })
142
+ }), _el$11, _el$12);
143
+ insert(_el$9, scope(() => {
144
+ return props.data.title;
145
+ }), _el$14, _el$15);
146
+ insert(_el$8, createComponent(Show, {
147
+ get when() {
148
+ return props.data.description;
149
+ },
150
+ children: (text) => (() => {
151
+ var _el$26 = getNextElement(_tmpl$3);
152
+ insert(_el$26, scope(() => {
153
+ return text();
154
+ }));
155
+ effect(() => readShallow(cx.description), (_v$, _$p) => {
156
+ className(_el$26, _v$, _$p);
157
+ });
158
+ return _el$26;
159
+ })()
160
+ }), _el$17, _el$18);
161
+ insert(_el$, createComponent(Show, {
162
+ get when() {
163
+ return props.data.meta;
164
+ },
165
+ children: (text) => (() => {
166
+ var _el$27 = getNextElement(_tmpl$4);
167
+ insert(_el$27, scope(() => {
168
+ return text();
169
+ }));
170
+ effect(() => readShallow(cx.meta), (_v$, _$p) => {
171
+ className(_el$27, _v$, _$p);
172
+ });
173
+ return _el$27;
174
+ })()
175
+ }), _el$20, _el$21);
176
+ insert(_el$, createComponent(Handle, {
177
+ type: "source",
178
+ get position() {
179
+ return props.sourcePosition ?? "right";
180
+ },
181
+ get isConnectable() {
182
+ return props.isConnectable;
183
+ },
184
+ get "class"() {
185
+ return memo(() => {
186
+ return !!props.isConnectable;
187
+ })() ? cx.handle : cx.handleHidden;
188
+ }
189
+ }), _el$23, _el$24);
190
+ effect(() => {
191
+ return {
192
+ e: status(),
193
+ t: readShallow(nodeClass[status() ?? "plain"]),
194
+ a: readShallow(cx.body),
195
+ o: readShallow(cx.title)
196
+ };
197
+ }, ({ e, t, a, o }, _p$) => {
198
+ e !== _p$?.e && setAttribute(_el$, "data-status", e);
199
+ className(_el$, t, _p$?.t);
200
+ className(_el$8, a, _p$?.a);
201
+ className(_el$9, o, _p$?.o);
202
+ });
203
+ return _el$;
204
+ }
205
+ /**
206
+ * The kit edge (edge type `"flow"`): a curve in the edge's tone, with dashes moving source to target when
207
+ * `data.flowing` (they stop under reduced motion).
208
+ */
209
+ function FlowEdge(props) {
210
+ const path = () => getBezierPath({
211
+ sourceX: props.sourceX,
212
+ sourceY: props.sourceY,
213
+ sourcePosition: props.sourcePosition,
214
+ targetX: props.targetX,
215
+ targetY: props.targetY,
216
+ targetPosition: props.targetPosition
217
+ });
218
+ return createComponent(BaseEdge, {
219
+ get path() {
220
+ return path()[0];
221
+ },
222
+ get labelX() {
223
+ return path()[1];
224
+ },
225
+ get labelY() {
226
+ return path()[2];
227
+ },
228
+ get label() {
229
+ return props.label;
230
+ },
231
+ get markerEnd() {
232
+ return props.markerEnd;
233
+ },
234
+ "data-slot": "flow-edge",
235
+ get "data-flowing"() {
236
+ return props.data?.flowing ? "" : void 0;
237
+ },
238
+ get "class"() {
239
+ return memo(() => {
240
+ return !!props.data?.flowing;
241
+ })() ? cx.edgeFlowing : cx.edge;
242
+ },
243
+ get style() {
244
+ return { "--flow-edge-color": EDGE_TONES[props.data?.tone ?? "neutral"] };
245
+ }
246
+ });
247
+ }
248
+ const NODE_TYPES = { step: FlowNode };
249
+ const EDGE_TYPES = { flow: FlowEdge };
250
+ /**
251
+ * A pannable, zoomable graph of nodes and edges, themed by the kit: step nodes (`type: "step"`, with a status,
252
+ * an icon, a title, a description and meta) and kit edges (`type: "flow"`, the default; `data.flowing` for
253
+ * moving data) beside your own node and edge types. Nodes and edges are solid-flow's: pass stores from
254
+ * `createNodeStore` / `createEdgeStore` to control them, or `defaultNodes` / `defaultEdges`; `layoutFlow`
255
+ * places nodes that come without positions.
256
+ *
257
+ * @example
258
+ * <Flow label="Nightly ETL" defaultNodes={layoutFlow(nodes, edges)} defaultEdges={edges} height={360} />
259
+ */
260
+ function Flow(props) {
261
+ const rest = omit(props, "label", "readOnly", "height", "controls", "minimap", "background", "class", "style", "children", "nodeTypes", "edgeTypes");
262
+ const readOnly = () => props.readOnly !== false;
263
+ const flowProps = merge({
264
+ get nodesDraggable() {
265
+ return !readOnly();
266
+ },
267
+ get nodesConnectable() {
268
+ return !readOnly();
269
+ },
270
+ get zoomOnScroll() {
271
+ return !readOnly();
272
+ },
273
+ get deleteKey() {
274
+ return readOnly() ? null : void 0;
275
+ },
276
+ elementsSelectable: true,
277
+ fitView: true,
278
+ minZoom: .1,
279
+ proOptions: { hideAttribution: true },
280
+ defaultEdgeOptions: { type: "flow" }
281
+ }, rest);
282
+ const rootStyle = () => ({
283
+ ...props.height === void 0 ? {} : { height: typeof props.height === "number" ? `${props.height}px` : props.height },
284
+ ...props.style
285
+ });
286
+ var _el$28 = getNextElement(_tmpl$5);
287
+ insert(_el$28, createComponent(SolidFlow, mergeProps(flowProps, {
288
+ get "aria-label"() {
289
+ return props.label;
290
+ },
291
+ get nodeTypes() {
292
+ return {
293
+ ...NODE_TYPES,
294
+ ...props.nodeTypes
295
+ };
296
+ },
297
+ get edgeTypes() {
298
+ return {
299
+ ...EDGE_TYPES,
300
+ ...props.edgeTypes
301
+ };
302
+ },
303
+ get children() {
304
+ return [
305
+ createComponent(Show, {
306
+ get when() {
307
+ return props.background !== false;
308
+ },
309
+ get children() {
310
+ return createComponent(FlowBackground, {});
311
+ }
312
+ }),
313
+ createComponent(Show, {
314
+ get when() {
315
+ return props.controls !== false;
316
+ },
317
+ get children() {
318
+ return createComponent(FlowControls, {});
319
+ }
320
+ }),
321
+ createComponent(Show, {
322
+ get when() {
323
+ return props.minimap;
324
+ },
325
+ get children() {
326
+ return createComponent(FlowMiniMap, {});
327
+ }
328
+ }),
329
+ memo(() => {
330
+ return props.children;
331
+ })
332
+ ];
333
+ }
334
+ })));
335
+ effect(() => {
336
+ return {
337
+ e: readOnly() ? "" : void 0,
338
+ t: readShallow([stylex.props(styles.root, props.height === void 0 && styles.aspect).className, props.class]),
339
+ a: readShallow(rootStyle())
340
+ };
341
+ }, ({ e, t, a }, _p$) => {
342
+ e !== _p$?.e && setAttribute(_el$28, "data-readonly", e);
343
+ className(_el$28, t, _p$?.t);
344
+ style(_el$28, a, _p$?.a);
345
+ });
346
+ return _el$28;
347
+ }
348
+ /** The dot grid behind the graph, in the kit's border color. */
349
+ function FlowBackground(props) {
350
+ return createComponent(Background, mergeProps({
351
+ variant: "dots",
352
+ gap: 20,
353
+ size: 1.5
354
+ }, props));
355
+ }
356
+ /** Zoom in, zoom out and fit, in the kit's button colors (the `--xy-controls-*` variables). */
357
+ function FlowControls(props) {
358
+ return createComponent(Controls, mergeProps({ showLock: false }, props));
359
+ }
360
+ /** A minimap of the graph in the corner, in the kit's surface and border colors. */
361
+ function FlowMiniMap(props) {
362
+ return createComponent(MiniMap, mergeProps({
363
+ pannable: true,
364
+ zoomable: true,
365
+ ariaLabel: "Minimap",
366
+ width: 160,
367
+ height: 100
368
+ }, props));
369
+ }
370
+ export { Flow, FlowBackground, FlowControls, FlowEdge, FlowMiniMap, FlowNode };
@@ -0,0 +1,158 @@
1
+ import "@stylexjs/stylex";
2
+ // src/flow/flow.styles.ts
3
+ const styles = {
4
+ root: {
5
+ kB7OPa: "x9f619",
6
+ kVAEAm: "x1n2onr6",
7
+ kzqmXN: "xh8yej3",
8
+ k7Eaqz: "xeuugli",
9
+ kVQacm: "xb3r6kr",
10
+ kMzoRj: "xmkeg23",
11
+ ksu8eU: "x1y0btm7",
12
+ kVAM5u: "x1wpxzwl",
13
+ kaIpWk: "x1oiwymw",
14
+ kWkggS: "xm9f0jk",
15
+ kMv6JI: "x13rcfk",
16
+ kGuDYH: "x409pna",
17
+ kMwMTN: "x1yjpjgc",
18
+ $$css: true
19
+ },
20
+ aspect: {
21
+ kOBAk4: "x186iv6y",
22
+ $$css: true
23
+ },
24
+ node: {
25
+ kB7OPa: "x9f619",
26
+ k1xSpc: "x78zum5",
27
+ kGNEyG: "x6s0dn4",
28
+ kOIVth: "x8rwxmg",
29
+ kzqmXN: "xh8yej3",
30
+ kZKoxP: "x5yr21d",
31
+ k7Eaqz: "xeuugli",
32
+ kg3NbH: "xxobuei",
33
+ k8WAf4: "xqy2vlu",
34
+ kMzoRj: "xmkeg23",
35
+ ksu8eU: "x1y0btm7",
36
+ kVAM5u: "x1vl23hm x1w1tqly",
37
+ kaIpWk: "x1ttroej",
38
+ kWkggS: "xm9f0jk",
39
+ kGVxlE: "x1ca8aof xuhup3a",
40
+ k3XXqK: "x1t137rt x1894zjx x131agne",
41
+ kMeerF: "x1de99jn",
42
+ kjBf7l: "x1g21a3s",
43
+ kMwMTN: "x1yjpjgc",
44
+ k9WMMc: "x1yc453h",
45
+ kLWn49: "xau0z5x",
46
+ k1ekBW: "xkdsq27",
47
+ kIyJzY: "xctwqe3 x12w9bfk",
48
+ $$css: true
49
+ },
50
+ pending: {
51
+ "--flow-ink": "xdzv0v4",
52
+ "--flow-node-edge": "x1w067c4",
53
+ $$css: true
54
+ },
55
+ running: {
56
+ "--flow-ink": "x1hgq7sz",
57
+ "--flow-node-edge": "x26i07e",
58
+ $$css: true
59
+ },
60
+ success: {
61
+ "--flow-ink": "xbfl7yv",
62
+ "--flow-node-edge": "x1w067c4",
63
+ $$css: true
64
+ },
65
+ warning: {
66
+ "--flow-ink": "xmdc92d",
67
+ "--flow-node-edge": "x1dbrlxx",
68
+ $$css: true
69
+ },
70
+ error: {
71
+ "--flow-ink": "x1x3owhy",
72
+ "--flow-node-edge": "x18kdt69",
73
+ $$css: true
74
+ },
75
+ plain: {
76
+ "--flow-ink": "x1lxbday",
77
+ "--flow-node-edge": "x1v79dzn",
78
+ $$css: true
79
+ },
80
+ icon: {
81
+ k1xSpc: "x3nfvp2",
82
+ kmuXW: "x2lah0s",
83
+ kGNEyG: "x6s0dn4",
84
+ kjj79g: "xl56j7k",
85
+ kzqmXN: "xcdlrvm",
86
+ kZKoxP: "x1l36t39",
87
+ kMwMTN: "x1eitvad xs5hli",
88
+ $$css: true
89
+ },
90
+ iconSvg: {
91
+ kzqmXN: "xcdlrvm",
92
+ kZKoxP: "x1l36t39",
93
+ $$css: true
94
+ },
95
+ body: {
96
+ k1xSpc: "x78zum5",
97
+ kXwgrk: "xdt5ytf",
98
+ kOIVth: "xpowot6",
99
+ kUk6DE: "x12lumcd",
100
+ k7Eaqz: "xeuugli",
101
+ $$css: true
102
+ },
103
+ title: {
104
+ kVQacm: "xb3r6kr",
105
+ kg5iWk: "xlyipyv",
106
+ khDVqt: "xuxw1ft",
107
+ k63SB2: "x1vmg6u2",
108
+ $$css: true
109
+ },
110
+ description: {
111
+ kVQacm: "xb3r6kr",
112
+ kg5iWk: "xlyipyv",
113
+ khDVqt: "xuxw1ft",
114
+ kGuDYH: "xb5fjo1",
115
+ kMwMTN: "xe2mk2a",
116
+ $$css: true
117
+ },
118
+ meta: {
119
+ kmuXW: "x2lah0s",
120
+ kGuDYH: "xb5fjo1",
121
+ kMwMTN: "xe2mk2a",
122
+ kcqcaj: "xss6m8b",
123
+ $$css: true
124
+ },
125
+ handle: {
126
+ kzqmXN: "x1xc55vz",
127
+ kZKoxP: "xdk7pt",
128
+ k7Eaqz: "x11inojt",
129
+ kAzted: "x16suv20",
130
+ kMzoRj: "xmkeg23",
131
+ ksu8eU: "x1y0btm7",
132
+ kVAM5u: "x1xfin0c",
133
+ kaIpWk: "x1dg1y8n",
134
+ kWkggS: "xm9f0jk",
135
+ $$css: true
136
+ },
137
+ handleHidden: {
138
+ kSiTet: "xg01cxk",
139
+ kfzvcC: "x47corl",
140
+ $$css: true
141
+ },
142
+ edge: {
143
+ kDwRjp: "xbh8q5q",
144
+ kjVXCG: "xbf09jc x8jos32",
145
+ kfJifR: "xhr4kjn",
146
+ kAXs8y: "x1kzknox",
147
+ $$css: true
148
+ },
149
+ flowing: {
150
+ k5rJSQ: "x1o3yjxk",
151
+ kKVMdj: "x10xa9bi x1aquc0h",
152
+ k44tkh: "xemfg65",
153
+ kyAemX: "x1esw782",
154
+ ko0y90: "xa4qsjk",
155
+ $$css: true
156
+ }
157
+ };
158
+ export { styles };
@@ -0,0 +1,4 @@
1
+ import { Flow, FlowBackground, FlowControls, FlowEdge, FlowMiniMap, FlowNode } from "./flow.js";
2
+ import { layoutFlow } from "./layout.js";
3
+ import { BaseEdge, Handle, Panel, Position, createEdgeStore, createNodeStore, getBezierPath, getSmoothStepPath, getStraightPath, useSolidFlow } from "@dschz/solid-flow";
4
+ export { BaseEdge, Flow, FlowBackground, FlowControls, FlowEdge, FlowMiniMap, FlowNode, Handle, Panel, Position, createEdgeStore, createNodeStore, getBezierPath, getSmoothStepPath, getStraightPath, layoutFlow, useSolidFlow };
@@ -0,0 +1,51 @@
1
+ import { Position } from "@dschz/solid-flow";
2
+ import { Graph, layout } from "@dagrejs/dagre";
3
+ // src/flow/layout.ts
4
+ /**
5
+ * Auto layout for flows that arrive without positions (a pipeline from an API, a service graph): dagre's
6
+ * layered layout (`@dagrejs/dagre`, MIT) ranks the nodes along the edges, left to right or top to bottom,
7
+ * and places each node so edges cross as little as they can. Pure: nodes in, nodes with positions out.
8
+ */
9
+ /**
10
+ * The nodes with `position` set by dagre (each node's top left, so a fit view frames them), and their handles
11
+ * on the sides the graph flows through (`targetPosition` left and `sourcePosition` right going `"LR"`; top
12
+ * and bottom going `"TB"`). Edges naming a node that isn't there are left out of the layout. The input isn't
13
+ * changed.
14
+ */
15
+ function layoutFlow(nodes, edges, options = {}) {
16
+ const direction = options.direction ?? "LR";
17
+ const fallbackWidth = options.nodeWidth ?? 200;
18
+ const fallbackHeight = options.nodeHeight ?? 56;
19
+ const graph = new Graph();
20
+ graph.setGraph({
21
+ rankdir: direction,
22
+ ranksep: options.rankGap ?? 72,
23
+ nodesep: options.nodeGap ?? 24,
24
+ marginx: 0,
25
+ marginy: 0
26
+ });
27
+ graph.setDefaultEdgeLabel(() => ({}));
28
+ const size = (node) => ({
29
+ width: node.width ?? node.measured?.width ?? fallbackWidth,
30
+ height: node.height ?? node.measured?.height ?? fallbackHeight
31
+ });
32
+ for (const node of nodes) graph.setNode(node.id, size(node));
33
+ const ids = new Set(nodes.map((n) => n.id));
34
+ for (const edge of edges) if (ids.has(edge.source) && ids.has(edge.target) && edge.source !== edge.target) graph.setEdge(edge.source, edge.target);
35
+ layout(graph);
36
+ const horizontal = direction === "LR";
37
+ return nodes.map((node) => {
38
+ const placed = graph.node(node.id);
39
+ const { width, height } = size(node);
40
+ return {
41
+ ...node,
42
+ position: {
43
+ x: Math.round(placed.x - width / 2),
44
+ y: Math.round(placed.y - height / 2)
45
+ },
46
+ sourcePosition: horizontal ? Position.Right : Position.Bottom,
47
+ targetPosition: horizontal ? Position.Left : Position.Top
48
+ };
49
+ });
50
+ }
51
+ export { layoutFlow };