@draftably/runtime 0.1.0 → 0.3.0

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/graph.js ADDED
@@ -0,0 +1,669 @@
1
+ import { c as se, a as re, b as S, q as F, p as ae, d as de, e as le, f as ce, v as ue, g as N, r as pe } from "./compile-Csfz4rk4.js";
2
+ const _ = /^[A-Za-z_][A-Za-z0-9_.-]*$/;
3
+ function H(e, t) {
4
+ const n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = new Set(e.filter((r) => _.test(r)));
5
+ let d = 0;
6
+ for (const r of e) {
7
+ if (typeof r != "string" || !r) throw Error(`Every ${t} needs a string id.`);
8
+ if (n.has(r)) throw Error(`Duplicate ${t} id "${r}".`);
9
+ let p = r;
10
+ if (!_.test(r)) {
11
+ do
12
+ p = `_${d++}`;
13
+ while (s.has(p));
14
+ s.add(p);
15
+ }
16
+ n.set(r, p), o.set(p, r);
17
+ }
18
+ return {
19
+ of: (r, p) => {
20
+ const c = n.get(r);
21
+ if (!c) throw Error(`${p} refers to unknown id "${r}".`);
22
+ return c;
23
+ },
24
+ back: (r) => o.get(r) ?? r
25
+ };
26
+ }
27
+ function G(e) {
28
+ const t = new Set(e.flatMap((o) => o.id ? [o.id] : []));
29
+ let n = 0;
30
+ return e.map((o) => {
31
+ if (o.id) return o.id;
32
+ let s;
33
+ do
34
+ s = `e${++n}`;
35
+ while (t.has(s));
36
+ return s;
37
+ });
38
+ }
39
+ const he = (e) => e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`);
40
+ function M(e, t, n = {}) {
41
+ return {
42
+ kind: "statement",
43
+ command: e,
44
+ args: t,
45
+ attrs: Object.entries(n).filter(([, o]) => o !== void 0 && o !== "").map(([o, s]) => [
46
+ o,
47
+ typeof s == "string" && !/^[\w.-]+$/.test(s) ? F(s) : S(String(s))
48
+ ]),
49
+ line: 0
50
+ };
51
+ }
52
+ function A(e, t, n) {
53
+ const o = t.startsWith("engine:") ? t.slice(7) : void 0;
54
+ return M("layout", o ? [S(e)] : [S(e), S(t)], {
55
+ ...o ? { engine: o } : {},
56
+ ...n
57
+ });
58
+ }
59
+ function U(e) {
60
+ if (!e.length) return { x: 0, y: 0, width: 0, height: 0 };
61
+ const t = Math.min(...e.map((o) => o.x)), n = Math.min(...e.map((o) => o.y));
62
+ return {
63
+ x: t,
64
+ y: n,
65
+ width: Math.max(...e.map((o) => o.x + o.width)) - t,
66
+ height: Math.max(...e.map((o) => o.y + o.height)) - n
67
+ };
68
+ }
69
+ const ge = 1200;
70
+ function fe(e, t, n, o = "auto") {
71
+ if (o === "full")
72
+ return { ...N(e, t, n, { previous: [] }), quality: "full" };
73
+ const s = N(e, t, n, { previous: [], quick: !0 }), { edges: d, crossings: r, lanePairs: p, shared: c } = s.result.report, y = d * (1 + r + p + (c ? 1 : 0));
74
+ return o === "quick" || y > ge ? { ...s, quality: "quick" } : { ...N(e, t, n, { previous: [] }), quality: "full" };
75
+ }
76
+ function K(e, t, n, o) {
77
+ const { vg: s, rects: d } = ue(e), r = fe(e, s, d, t), p = new Map([...e.graph.nodes, ...e.graph.groups].map((u) => [u.id, u.parentId])), c = new Map(e.graph.edges.map((u) => [u.id, u])), y = (u) => {
78
+ const w = d.get(u), m = p.get(u);
79
+ return { x: w.x, y: w.y, width: w.w, height: w.h, ...m ? { parent: n(m) } : {} };
80
+ }, f = Object.fromEntries(s.nodes.map((u) => [n(u.id), y(u.id)])), i = Object.fromEntries(s.groups.map((u) => [n(u.id), y(u.id)])), l = Object.fromEntries(
81
+ r.routes.map((u) => [
82
+ o(u.id),
83
+ {
84
+ source: n(c.get(u.id)?.from ?? u.from),
85
+ target: n(c.get(u.id)?.to ?? u.to),
86
+ sourceSide: u.fromSide,
87
+ targetSide: u.toSide,
88
+ points: u.points,
89
+ path: u.path,
90
+ label: u.label ? {
91
+ x: u.label.x - u.label.w / 2,
92
+ y: u.label.y - u.label.h / 2,
93
+ width: u.label.w,
94
+ height: u.label.h
95
+ } : null,
96
+ blocked: u.blocked
97
+ }
98
+ ])
99
+ ), a = [...Object.values(f), ...Object.values(i)];
100
+ for (const u of Object.values(l))
101
+ u.label && a.push(u.label), a.push(U(u.points.map((w) => ({ ...w, width: 0, height: 0 }))));
102
+ const g = Object.values(l).filter((u) => u.blocked).length;
103
+ return {
104
+ nodes: f,
105
+ groups: i,
106
+ edges: l,
107
+ bounds: U(a),
108
+ quality: r.quality,
109
+ warnings: g ? [`${g} line${g > 1 ? "s" : ""} found no clear way.`] : []
110
+ };
111
+ }
112
+ function ye(e, t, n) {
113
+ let o = e;
114
+ for (const s of t)
115
+ n(s) !== s && (o = o.replace(new RegExp(`\\b${s}\\b`, "g"), `"${n(s)}"`));
116
+ return o;
117
+ }
118
+ function be(e, t) {
119
+ const n = (o, s, d, r) => {
120
+ if (o === void 0 || !Number.isFinite(o)) return;
121
+ const p = Math.round(Math.min(d, Math.max(s, o)));
122
+ return p !== Math.round(o) && t.push(`Node "${e.id}" ${r} ${o} is outside ${s}–${d}; drawn at ${p}.`), p;
123
+ };
124
+ return { width: n(e.width, 40, 1200, "width"), height: n(e.height, 24, 1200, "height") };
125
+ }
126
+ function Z(e) {
127
+ const t = e.groups ?? [], n = e.nodes ?? [], o = e.edges ?? [], s = G(o), d = H([...t.map((a) => a.id), ...n.map((a) => a.id)], "node or group"), r = H(s, "edge"), p = d.of, { quality: c, ...y } = e.routing ?? {}, f = [], i = [
128
+ ...t.map(
129
+ (a) => M("group", [S(p(a.id, "group")), F(a.label ?? a.id)], {
130
+ in: a.parent && p(a.parent, `Group "${a.id}"`),
131
+ fold: e.fold === "never" ? "never" : void 0
132
+ })
133
+ ),
134
+ ...n.map(
135
+ (a) => M("node", [S(p(a.id, "node")), F(a.label ?? a.id)], {
136
+ in: a.parent && p(a.parent, `Node "${a.id}"`),
137
+ shape: a.shape
138
+ })
139
+ ),
140
+ ...o.map(
141
+ (a, g) => M(
142
+ "edge",
143
+ [
144
+ S(r.of(s[g], "edge")),
145
+ S(p(a.source, `Edge "${s[g]}"`)),
146
+ S("->"),
147
+ S(p(a.target, `Edge "${s[g]}"`)),
148
+ ...a.label ? [F(a.label)] : []
149
+ ],
150
+ { kind: a.dashed ? "async" : void 0, from: a.sourceSide, to: a.targetSide }
151
+ )
152
+ ),
153
+ // A file with no layout line spaces its root flow 48px apart; a layout line without `gap=`
154
+ // only 28px, too tight for a line into a group below its title band.
155
+ A("root", e.arrange ?? "flow", {
156
+ gap: e.gap ?? ((e.arrange ?? "flow") === "flow" ? 48 : void 0),
157
+ direction: e.direction,
158
+ fit: e.fit,
159
+ fold: e.fold === "never" ? "never" : void 0
160
+ }),
161
+ ...t.filter((a) => a.arrange || a.direction || a.gap).map(
162
+ (a) => A(p(a.id, "group"), a.arrange ?? "column", {
163
+ gap: a.gap,
164
+ direction: a.direction
165
+ })
166
+ ),
167
+ ...n.flatMap((a) => {
168
+ const { width: g, height: u } = be(a, f);
169
+ return g || u ? [
170
+ M("size", [S(p(a.id, "node"))], {
171
+ width: g ?? 176,
172
+ height: u ?? "auto"
173
+ })
174
+ ] : [];
175
+ }),
176
+ ...Object.keys(y).length ? [
177
+ M(
178
+ "routing",
179
+ [],
180
+ Object.fromEntries(Object.entries(y).map(([a, g]) => [he(a), g]))
181
+ )
182
+ ] : []
183
+ ];
184
+ return { draft: ae({ lines: i }), model: de({ lines: i }), quality: c, objects: d, lines: r, warnings: f };
185
+ }
186
+ function J({ draft: e, model: t, quality: n, objects: o, lines: s, warnings: d }, r) {
187
+ const p = K(le(r), n, o.back, s.back);
188
+ return {
189
+ ...p,
190
+ draft: e,
191
+ warnings: [
192
+ ...d,
193
+ ...t.warnings.map((c) => c.message),
194
+ // A caller's size is the host's to fill: whether draftably's text fits it says nothing.
195
+ ...r.diagnostics.filter((c) => c.level !== "info" && c.code !== "text-overflow").map((c) => ye(c.message, c.ids, o.back)),
196
+ ...p.warnings
197
+ ]
198
+ };
199
+ }
200
+ async function T(e) {
201
+ const t = Z(e);
202
+ return J(t, await re(t.draft));
203
+ }
204
+ function Q(e) {
205
+ const t = Z(e);
206
+ if (t.model.layouts.some((n) => n.engine || n.fit))
207
+ throw Error("layoutSync cannot run layout engines or fit; use layout().");
208
+ return J(t, se(t.draft));
209
+ }
210
+ function W(e) {
211
+ const t = ce(), n = e.groups ?? [], o = /* @__PURE__ */ new Set(), { quality: s, ...d } = e.routing ?? {}, r = G(e.edges);
212
+ t.settings.routing = { ...t.settings.routing, ...d };
213
+ for (const i of [...n, ...e.nodes]) {
214
+ if (o.has(i.id)) throw Error(`Duplicate node or group id "${i.id}".`);
215
+ o.add(i.id);
216
+ }
217
+ const p = (i, l) => {
218
+ if (i !== void 0 && !o.has(i)) throw Error(`${l} refers to unknown id "${i}".`);
219
+ };
220
+ for (const i of n)
221
+ p(i.parent, `Group "${i.id}"`), t.graph.groups.push({
222
+ id: i.id,
223
+ title: i.label ?? "",
224
+ ...i.parent ? { parentId: i.parent } : {}
225
+ }), t.layout.containers[i.id] = { direction: "inherit", padding: 0, manualSize: !0 };
226
+ for (const i of e.nodes)
227
+ p(i.parent, `Node "${i.id}"`), t.graph.nodes.push({ id: i.id, title: "", ...i.parent ? { parentId: i.parent } : {} }), t.styles[i.id] = { shape: i.shape ?? "box", color: "auto", icon: "" };
228
+ for (const i of [...n, ...e.nodes])
229
+ t.layout.nodes[i.id] = { x: i.x, y: i.y, w: i.width, h: i.height };
230
+ e.edges.forEach((i, l) => {
231
+ const a = r[l];
232
+ p(i.source, `Edge "${a}"`), p(i.target, `Edge "${a}"`), t.graph.edges.push({
233
+ id: a,
234
+ from: i.source,
235
+ to: i.target,
236
+ label: i.label ?? "",
237
+ directed: !0,
238
+ emphasis: !1,
239
+ dashed: !!i.dashed
240
+ }), t.layout.edges[a] = {
241
+ ...i.sourceSide ? { fromSide: i.sourceSide } : {},
242
+ ...i.targetSide ? { toSide: i.targetSide } : {}
243
+ };
244
+ });
245
+ const {
246
+ edges: c,
247
+ quality: y,
248
+ warnings: f
249
+ } = K(
250
+ t,
251
+ s,
252
+ (i) => i,
253
+ (i) => i
254
+ );
255
+ return { edges: c, quality: y, warnings: f };
256
+ }
257
+ const we = /* @__PURE__ */ new Set(["left", "right", "top", "bottom"]), B = (e) => e && we.has(e) ? e : void 0, E = (e) => typeof e == "number" && e > 0 ? e : void 0, k = (e) => e.parentId ?? e.parentNode, R = (e) => typeof e.data?.label == "string" ? e.data.label : e.id, V = (e) => {
258
+ const t = typeof e.style == "object" ? e.style : void 0;
259
+ return {
260
+ width: E(e.measured?.width) ?? E(e.width) ?? E(t?.width),
261
+ height: E(e.measured?.height) ?? E(e.height) ?? E(t?.height)
262
+ };
263
+ }, X = (e) => /* @__PURE__ */ new Set([
264
+ ...e.flatMap((t) => k(t) ? [k(t)] : []),
265
+ ...e.filter((t) => t.type === "group").map((t) => t.id)
266
+ ]);
267
+ function Y({ nodes: e, edges: t }, n = {}) {
268
+ const o = X(e);
269
+ return {
270
+ groups: e.filter((s) => o.has(s.id)).map((s) => ({ id: s.id, label: R(s), parent: k(s) })),
271
+ nodes: e.filter((s) => !o.has(s.id)).map((s) => {
272
+ const { width: d, height: r } = V(s);
273
+ return {
274
+ id: s.id,
275
+ label: R(s),
276
+ parent: k(s),
277
+ shape: n.shape?.(s),
278
+ ...d ? { width: d } : {},
279
+ ...r ? { height: r } : {}
280
+ };
281
+ }),
282
+ edges: t.map((s) => ({
283
+ id: s.id,
284
+ source: s.source,
285
+ target: s.target,
286
+ label: typeof s.label == "string" ? s.label : void 0,
287
+ dashed: s.animated,
288
+ sourceSide: B(s.sourceHandle),
289
+ targetSide: B(s.targetHandle)
290
+ }))
291
+ };
292
+ }
293
+ function ee(e, t) {
294
+ return e.map((n) => {
295
+ const o = t[n.id], s = o ? {
296
+ path: o.path,
297
+ points: o.points,
298
+ label: o.label,
299
+ sourceSide: o.sourceSide,
300
+ targetSide: o.targetSide,
301
+ blocked: o.blocked
302
+ } : {
303
+ path: "",
304
+ points: [],
305
+ label: null,
306
+ sourceSide: "right",
307
+ targetSide: "left",
308
+ blocked: !0
309
+ };
310
+ return { ...n, type: n.type ?? "draftably", data: { ...n.data, draftably: s } };
311
+ });
312
+ }
313
+ function me({ nodes: e, edges: t }, n, o = !1) {
314
+ const s = (d) => n.nodes[d] ?? n.groups[d];
315
+ return {
316
+ nodes: e.map((d) => {
317
+ const r = s(d.id), p = k(d) ? s(k(d)) : void 0;
318
+ if (!r) return d;
319
+ const c = { width: r.width, height: r.height };
320
+ return {
321
+ ...d,
322
+ position: { x: r.x - (p?.x ?? 0), y: r.y - (p?.y ?? 0) },
323
+ ...c,
324
+ ...o || typeof d.style == "string" ? {} : { style: { ...d.style, ...c } }
325
+ };
326
+ }),
327
+ edges: ee(t, n.edges)
328
+ };
329
+ }
330
+ function xe({ nodes: e, edges: t }, n = {}) {
331
+ const o = new Map(e.map((c) => [c.id, c])), s = X(e), d = (c) => {
332
+ const y = k(c) ? o.get(k(c)) : void 0, f = y ? d(y) : { x: 0, y: 0 };
333
+ return { x: f.x + (c.position?.x ?? 0), y: f.y + (c.position?.y ?? 0) };
334
+ }, r = e.flatMap((c) => {
335
+ const { width: y, height: f } = V(c);
336
+ return y && f ? [{ n: c, box: { ...d(c), width: y, height: f } }] : [];
337
+ }), p = new Set(r.map((c) => c.n.id));
338
+ return {
339
+ groups: r.filter(({ n: c }) => s.has(c.id)).map(({ n: c, box: y }) => ({ id: c.id, label: R(c), parent: k(c), ...y })),
340
+ nodes: r.filter(({ n: c }) => !s.has(c.id)).map(({ n: c, box: y }) => ({
341
+ id: c.id,
342
+ parent: k(c),
343
+ shape: n.shape?.(c),
344
+ ...y
345
+ })),
346
+ edges: Y({ nodes: [], edges: t }).edges.filter(
347
+ (c) => p.has(c.source) && p.has(c.target)
348
+ )
349
+ };
350
+ }
351
+ function Se(e, t) {
352
+ return ee(e, t.edges).map(
353
+ (n, o) => t.edges[n.id] || !e[o].data?.draftably ? n : e[o]
354
+ );
355
+ }
356
+ const P = (e, t) => Object.fromEntries(Object.entries(e).map(([n, o]) => [n, t(o)]));
357
+ function te(e, t, n, o, s = e.bounds) {
358
+ return {
359
+ ...e,
360
+ bounds: s,
361
+ nodes: P(e.nodes, t),
362
+ groups: P(e.groups, t),
363
+ edges: P(e.edges, (d) => {
364
+ const r = d.points.map(n);
365
+ return {
366
+ ...d,
367
+ points: r,
368
+ path: pe(r, 6),
369
+ label: d.label && t(d.label),
370
+ sourceSide: o(d.sourceSide),
371
+ targetSide: o(d.targetSide)
372
+ };
373
+ })
374
+ };
375
+ }
376
+ function oe(e) {
377
+ const t = -e.bounds.x, n = -e.bounds.y;
378
+ return !t && !n ? e : te(
379
+ e,
380
+ (o) => ({ ...o, x: o.x + t, y: o.y + n }),
381
+ (o) => ({ x: o.x + t, y: o.y + n }),
382
+ (o) => o,
383
+ { ...e.bounds, x: 0, y: 0 }
384
+ );
385
+ }
386
+ const ke = { left: "right", right: "left", top: "bottom", bottom: "top" };
387
+ function D(e, t) {
388
+ const n = t === "x" ? "width" : "height", o = 2 * e.bounds[t] + e.bounds[n], s = t === "x" ? ["left", "right"] : ["top", "bottom"];
389
+ return te(
390
+ e,
391
+ (d) => ({ ...d, [t]: o - d[t] - d[n] }),
392
+ (d) => ({ ...d, [t]: o - d[t] }),
393
+ (d) => s.includes(d) ? ke[d] : d
394
+ );
395
+ }
396
+ function j(e, t) {
397
+ return e?.[`elk.${t}`] ?? e?.[`org.eclipse.elk.${t}`] ?? e?.[t];
398
+ }
399
+ const C = (e) => e.replace(/^(org\.eclipse\.)?elk\./, ""), $e = /* @__PURE__ */ new Set([
400
+ "algorithm",
401
+ "direction",
402
+ "spacing.nodeNode",
403
+ "layered.spacing.nodeNodeBetweenLayers",
404
+ "port.side",
405
+ "hierarchyHandling",
406
+ "edgeRouting",
407
+ "portConstraints",
408
+ "nodeSize.constraints",
409
+ "nodeLabels.placement"
410
+ ]), Oe = {
411
+ NORTH: "top",
412
+ SOUTH: "bottom",
413
+ EAST: "right",
414
+ WEST: "left"
415
+ };
416
+ function Ee(e, t) {
417
+ const n = [], o = [], s = [], d = [], r = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), y = { ...t, ...e.layoutOptions }, f = (h) => {
418
+ for (const b of Object.keys(h ?? {})) $e.has(C(b)) || r.add(C(b));
419
+ };
420
+ f(y);
421
+ const i = { nodes: n, groups: o, edges: s, fold: "never" }, l = j(y, "direction");
422
+ let a;
423
+ l === "DOWN" || l === "UP" ? i.direction = "down" : (l === "RIGHT" || l === "LEFT") && (i.direction = "right"), l === "LEFT" && (a = "x"), l === "UP" && (a = "y");
424
+ const g = Number(
425
+ j(y, "layered.spacing.nodeNodeBetweenLayers") ?? j(y, "spacing.nodeNode")
426
+ );
427
+ g > 0 && (i.gap = Math.min(300, Math.max(8, g)));
428
+ const u = j(y, "algorithm");
429
+ u && /force|stress/.test(u) ? i.arrange = "engine:stress" : u && /mrtree/.test(u) ? i.arrange = "engine:tree" : u && /rectpacking|box/.test(u) && (i.arrange = "engine:grid");
430
+ const w = (h, b) => {
431
+ for (const x of h.ports ?? [])
432
+ f(x.layoutOptions), p.set(x.id, { node: h.id, side: Oe[j(x.layoutOptions, "port.side") ?? ""] });
433
+ if (h !== e) {
434
+ f(h.layoutOptions);
435
+ const x = h.labels?.[0]?.text ?? h.id;
436
+ h.children?.length ? o.push({ id: h.id, label: x, parent: b, arrange: "flow" }) : n.push({
437
+ id: h.id,
438
+ label: x,
439
+ parent: b,
440
+ ...h.width ? { width: h.width } : {},
441
+ ...h.height ? { height: h.height } : {}
442
+ });
443
+ }
444
+ for (const x of h.children ?? []) w(x, h === e ? void 0 : h.id);
445
+ };
446
+ w(e);
447
+ const m = (h) => p.get(h) ?? { node: h, side: void 0 }, $ = (h) => {
448
+ for (const b of h.edges ?? []) {
449
+ f(b.layoutOptions);
450
+ const x = b.sources.flatMap((L) => b.targets.map((O) => [m(L), m(O)])), I = x.map((L, O) => x.length > 1 ? `${b.id}#${O}` : b.id);
451
+ c.set(b.id, I), x.forEach(
452
+ ([L, O], ne) => s.push({
453
+ id: I[ne],
454
+ source: L.node,
455
+ target: O.node,
456
+ label: b.labels?.[0]?.text,
457
+ sourceSide: L.side,
458
+ targetSide: O.side
459
+ })
460
+ );
461
+ }
462
+ for (const b of h.children ?? []) $(b);
463
+ };
464
+ return $(e), r.size && d.push(`These ELK options are not used: ${[...r].sort().join(", ")}.`), { graph: i, warnings: d, pieces: c, mirror: a };
465
+ }
466
+ function ve(e, t, { pieces: n }) {
467
+ const o = /* @__PURE__ */ new Map([[e.id, { x: 0, y: 0 }]]), s = /* @__PURE__ */ new Map(), d = (l, a) => {
468
+ const g = l === e ? void 0 : t.nodes[l.id] ?? t.groups[l.id], u = g ? { x: g.x, y: g.y } : a;
469
+ o.set(l.id, u);
470
+ for (const m of l.children ?? []) s.set(m.id, l.id);
471
+ const w = l.children?.map((m) => d(m, u));
472
+ return {
473
+ ...l,
474
+ ...l === e ? {
475
+ x: 0,
476
+ y: 0,
477
+ width: t.bounds.x + t.bounds.width,
478
+ height: t.bounds.y + t.bounds.height
479
+ } : { x: u.x - a.x, y: u.y - a.y, width: g?.width, height: g?.height },
480
+ ...w ? { children: w } : {}
481
+ };
482
+ }, r = d(e, { x: 0, y: 0 }), p = /* @__PURE__ */ new Map(), c = (l) => {
483
+ for (const a of l.ports ?? []) p.set(a.id, l.id);
484
+ l.children?.forEach(c);
485
+ };
486
+ c(e);
487
+ const y = (l) => {
488
+ const a = [];
489
+ for (let g = s.get(p.get(l) ?? l); g; g = s.get(g)) a.push(g);
490
+ return a;
491
+ }, f = (l) => {
492
+ const a = y(l.sources[0]), g = new Set(y(l.targets[0]));
493
+ return a.find((u) => g.has(u)) ?? e.id;
494
+ }, i = (l) => ({
495
+ ...l,
496
+ ...l.edges ? {
497
+ edges: l.edges.map((a) => {
498
+ const g = f(a), u = o.get(g) ?? { x: 0, y: 0 }, w = (h) => ({ x: h.x - u.x, y: h.y - u.y }), m = (n.get(a.id) ?? [a.id]).map((h) => t.edges[h]).filter(Boolean), $ = m[0]?.label;
499
+ return {
500
+ ...a,
501
+ container: g,
502
+ sections: m.map((h, b) => ({
503
+ id: `${a.id}_s${b}`,
504
+ startPoint: w(h.points[0]),
505
+ endPoint: w(h.points.at(-1)),
506
+ bendPoints: h.points.slice(1, -1).map(w),
507
+ incomingShape: h.source,
508
+ outgoingShape: h.target
509
+ })),
510
+ ...a.labels?.length && $ ? {
511
+ labels: a.labels.map(
512
+ (h, b) => b ? h : { ...h, ...w($), width: $.width, height: $.height }
513
+ )
514
+ } : {}
515
+ };
516
+ })
517
+ } : {},
518
+ ...l.children ? { children: l.children.map(i) } : {}
519
+ });
520
+ return i(r);
521
+ }
522
+ async function ie(e, t, n) {
523
+ const o = Ee(e, t), s = await T({ ...o.graph, ...n }), d = oe(o.mirror ? D(s, o.mirror) : s);
524
+ return d.warnings.unshift(...o.warnings), { elk: ve(e, d, o), result: d };
525
+ }
526
+ class Le {
527
+ constructor(t = {}) {
528
+ this.options = t;
529
+ }
530
+ /** Warnings from the last `layout` call, such as ELK options that were not used. */
531
+ warnings = [];
532
+ async layout(t, n = {}) {
533
+ const { elk: o, result: s } = await ie(t, {
534
+ ...this.options.defaultLayoutOptions,
535
+ ...n.layoutOptions
536
+ });
537
+ return this.warnings = s.warnings, o;
538
+ }
539
+ knownLayoutAlgorithms() {
540
+ return Promise.resolve([{ id: "draftably.flow", name: "Draftably flow" }]);
541
+ }
542
+ terminateWorker() {
543
+ }
544
+ }
545
+ const v = (e) => typeof e == "number" && e > 0 ? e : void 0, q = (e) => typeof e == "string" ? e : void 0;
546
+ function je(e, t = {}) {
547
+ const n = e.nodes(), o = (i) => e.parent?.(i) || void 0, s = new Set(n.filter((i) => e.children?.(i)?.length)), d = e.graph() ?? {}, r = q(d.rankdir)?.toUpperCase() ?? "TB", p = e.edges(), c = (i) => `${i.v}->${i.w}${i.name ? `:${i.name}` : ""}`, y = {
548
+ // dagre never folds a long drawing into rows, and its clusters flow like the rest.
549
+ fold: "never",
550
+ direction: r === "LR" || r === "RL" ? "right" : "down",
551
+ ...v(d.ranksep) ? { gap: Math.min(300, Math.max(8, v(d.ranksep))) } : {},
552
+ groups: n.filter((i) => s.has(i)).map((i) => ({
553
+ id: i,
554
+ label: q(e.node(i)?.label) ?? i,
555
+ parent: o(i),
556
+ arrange: "flow"
557
+ })),
558
+ nodes: n.filter((i) => !s.has(i)).map((i) => {
559
+ const l = e.node(i) ?? {};
560
+ return {
561
+ id: i,
562
+ label: q(l.label) ?? i,
563
+ parent: o(i),
564
+ ...v(l.width) ? { width: v(l.width) } : {},
565
+ ...v(l.height) ? { height: v(l.height) } : {}
566
+ };
567
+ }),
568
+ edges: p.map((i) => ({
569
+ id: c(i),
570
+ source: i.v,
571
+ target: i.w,
572
+ label: q(e.edge(i)?.label)
573
+ })),
574
+ routing: t.routing
575
+ };
576
+ let f = Q(y);
577
+ r === "BT" && (f = D(f, "y")), r === "RL" && (f = D(f, "x")), f = oe(f);
578
+ for (const i of n) {
579
+ const l = f.nodes[i] ?? f.groups[i], a = e.node(i);
580
+ !l || !a || Object.assign(a, {
581
+ x: l.x + l.width / 2,
582
+ y: l.y + l.height / 2,
583
+ width: l.width,
584
+ height: l.height
585
+ });
586
+ }
587
+ for (const i of p) {
588
+ const l = f.edges[c(i)], a = e.edge(i);
589
+ !l || !a || Object.assign(a, {
590
+ points: l.points.map((g) => ({ x: g.x, y: g.y })),
591
+ ...l.label ? { x: l.label.x + l.label.width / 2, y: l.label.y + l.label.height / 2 } : {}
592
+ });
593
+ }
594
+ return Object.assign(d, { width: f.bounds.width, height: f.bounds.height }), f;
595
+ }
596
+ function z(e) {
597
+ this.options = e;
598
+ }
599
+ z.prototype.run = function() {
600
+ const e = this.options, t = e.eles.nodes(), n = (r) => {
601
+ const p = r.data("label");
602
+ return typeof p == "string" ? p : r.id();
603
+ }, o = (r) => r.parent().length ? r.parent().id() : void 0, s = {
604
+ direction: e.direction,
605
+ gap: e.gap,
606
+ routing: e.routing,
607
+ groups: t.filter((r) => r.isParent()).map((r) => ({ id: r.id(), label: n(r), parent: o(r) })),
608
+ nodes: t.filter((r) => !r.isParent()).map((r) => ({
609
+ id: r.id(),
610
+ label: n(r),
611
+ parent: o(r),
612
+ width: r.outerWidth(),
613
+ height: r.outerHeight()
614
+ })),
615
+ edges: e.eles.edges().map((r) => ({
616
+ id: r.id(),
617
+ source: r.source().id(),
618
+ target: r.target().id(),
619
+ label: typeof r.data("label") == "string" ? r.data("label") : void 0
620
+ }))
621
+ }, d = Q(s);
622
+ return this.result = d, t.layoutPositions(this, { fit: !0, padding: 30, animate: !1, ...e }, (r) => {
623
+ const p = d.nodes[r.id()] ?? d.groups[r.id()];
624
+ return p ? { x: p.x + p.width / 2, y: p.y + p.height / 2 } : { x: 0, y: 0 };
625
+ }), this;
626
+ };
627
+ z.prototype.stop = function() {
628
+ return this;
629
+ };
630
+ function qe(e) {
631
+ e("layout", "draftably", z);
632
+ }
633
+ async function Fe(e) {
634
+ if ("elk" in e) {
635
+ const { elk: t, ...n } = e;
636
+ return ie(t, void 0, n);
637
+ }
638
+ for (const t of ["reactFlow", "svelteFlow"])
639
+ if (t in e) {
640
+ const {
641
+ [t]: n,
642
+ shape: o,
643
+ ...s
644
+ } = e, d = await T({ ...Y(n, { shape: o }), ...s });
645
+ return { [t]: me(n, d, t === "svelteFlow"), result: d };
646
+ }
647
+ return T(e);
648
+ }
649
+ function Ne(e) {
650
+ for (const t of ["reactFlow", "svelteFlow"])
651
+ if (t in e) {
652
+ const {
653
+ [t]: n,
654
+ shape: o,
655
+ routing: s
656
+ } = e, d = W({ ...xe(n, { shape: o }), routing: s });
657
+ return { [t]: { nodes: n.nodes, edges: Se(n.edges, d) }, result: d };
658
+ }
659
+ return W(e);
660
+ }
661
+ export {
662
+ ge as AUTO_FULL_LIMIT,
663
+ Le as DraftablyELK,
664
+ je as dagreLayout,
665
+ qe as draftablyLayout,
666
+ Fe as layout,
667
+ Q as layoutSync,
668
+ Ne as route
669
+ };
package/dist/index.js CHANGED
@@ -1,9 +1,10 @@
1
- import { r, v as e } from "./render-BOAZBzVa.js";
2
- import { f as i, a as v } from "./render-BOAZBzVa.js";
1
+ import { r, v as e } from "./render-Dgo42PR4.js";
2
+ import { a as i } from "./render-Dgo42PR4.js";
3
+ import { h as v } from "./compile-Csfz4rk4.js";
3
4
  const t = r, a = e;
4
5
  export {
5
- i as fontMetricsVersion,
6
+ v as fontMetricsVersion,
6
7
  t as renderSvg,
7
- v as runtimeVersion,
8
+ i as runtimeVersion,
8
9
  a as validate
9
10
  };