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