@graphty/graphty-element 2.3.0 → 2.3.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 (48) hide show
  1. package/dist/ai.js +115 -222
  2. package/dist/catalog.js +56 -55
  3. package/dist/chunks/{AiManager-Bd_r1Hei.js → AiManager-BBmGJbH4.js} +793 -654
  4. package/dist/chunks/{DataSource-bt0DhBjG.js → DataSource-OeN3NeyD.js} +1 -1
  5. package/dist/chunks/{GraphSession-iNyKm7Ds.js → GraphSession-Bef1AYw9.js} +2136 -2104
  6. package/dist/chunks/{GraphStyle-D0PXnZKu.js → GraphStyle-Cwr55SAE.js} +5 -2
  7. package/dist/chunks/{VoiceInputAdapter-DszYl6Ha.js → VoiceInputAdapter-Dr9Gcmds.js} +1 -1
  8. package/dist/chunks/{XRPivotCameraController-XtxbbZ-D.js → XRPivotCameraController-BbfgZWpS.js} +1 -1
  9. package/dist/chunks/algorithms-CpX56sUB.js +3482 -0
  10. package/dist/chunks/{capability-check-BqIEXcun.js → capability-check-Blhb2aBB.js} +1 -1
  11. package/dist/chunks/{detect-DM29BEaB.js → detect-Cqwshr9a.js} +1 -1
  12. package/dist/chunks/{format-detection-BEdmtvsy.js → format-detection-BXGO1lSn.js} +1 -1
  13. package/dist/chunks/{index-CD0_RJv-.js → index-C0mIoumR.js} +2258 -2129
  14. package/dist/chunks/optionsFromZod-17lkrAJs.js +2565 -0
  15. package/dist/chunks/paletteRegistry-x7WOEKZY.js +1153 -0
  16. package/dist/chunks/scales-BRwl51k8.js +3047 -0
  17. package/dist/custom-elements.json +1 -1
  18. package/dist/extend.js +42 -42
  19. package/dist/graphty-catalog.json +1 -1
  20. package/dist/graphty.bundle.js +25814 -25456
  21. package/dist/graphty.js +29 -29
  22. package/dist/schema.js +1 -1
  23. package/dist/session.d.ts +1 -1
  24. package/dist/session.js +28 -29
  25. package/dist/src/Graph.d.ts +33 -3
  26. package/dist/src/camera/builtins.d.ts +14 -1
  27. package/dist/src/camera/types.d.ts +7 -0
  28. package/dist/src/cameras/CameraManager.d.ts +13 -0
  29. package/dist/src/cameras/OrbitCameraController.d.ts +9 -0
  30. package/dist/src/catalog/types.d.ts +10 -0
  31. package/dist/src/config/GraphStyle.d.ts +5 -1
  32. package/dist/src/config/StyleTemplate.d.ts +2 -2
  33. package/dist/src/graphty-element.d.ts +11 -6
  34. package/dist/src/managers/StylePainter.d.ts +9 -0
  35. package/dist/src/managers/UpdateManager.d.ts +5 -0
  36. package/dist/src/session/results/index.d.ts +1 -1
  37. package/dist/src/session/results/statistics.d.ts +8 -1
  38. package/dist/src/session/results/types.d.ts +33 -0
  39. package/dist/src/session/selection/targets.d.ts +4 -1
  40. package/dist/src/session/styles/predicate.d.ts +26 -1
  41. package/dist/src/session/styles/repaint.d.ts +11 -0
  42. package/dist/src/session/styles/selector.d.ts +13 -1
  43. package/dist/src/session/styles/sources.d.ts +9 -0
  44. package/package.json +1 -1
  45. package/dist/chunks/Algorithm-RQ629NLb.js +0 -494
  46. package/dist/chunks/cameras-ii4vngYY.js +0 -435
  47. package/dist/chunks/paletteRegistry-DnWHQsAD.js +0 -3166
  48. package/dist/chunks/scales-DyuwlJKI.js +0 -6087
@@ -0,0 +1,1153 @@
1
+ import { q as b, G as F } from "./GraphtyLogger-5KEttFUo.js";
2
+ import { a as T, b as D, d as k } from "./types-B7bX5c0K.js";
3
+ import { remapArray as S, INVALID_INDEX as N } from "@graphty/graph-format";
4
+ import { z as O } from "zod/v4";
5
+ import { G as g } from "./GraphtyError-BwcnblTH.js";
6
+ import { c as v } from "./common-DWNKjpH_.js";
7
+ const f = b({
8
+ kind: "format",
9
+ idOf: (i) => i.descriptor.id,
10
+ descriptorOf: (i) => i.descriptor,
11
+ implementationOf: (i) => i.descriptor,
12
+ builtInIds: () => T
13
+ });
14
+ function it(i, t) {
15
+ f.register(i, t);
16
+ }
17
+ function st() {
18
+ return f.entries();
19
+ }
20
+ function L() {
21
+ return f.descriptors();
22
+ }
23
+ function $(i) {
24
+ return f.byId(i);
25
+ }
26
+ function rt() {
27
+ f.clearForTesting();
28
+ }
29
+ const M = {
30
+ "edge-list": "Edge List",
31
+ "node-list": "Node List",
32
+ "adjacency-list": "Adjacency List",
33
+ neo4j: "Neo4j Export",
34
+ gephi: "Gephi Export",
35
+ cytoscape: "Cytoscape Export",
36
+ generic: "Generic"
37
+ }, R = [
38
+ {
39
+ name: "delimiter",
40
+ plainName: "Column Separator",
41
+ technicalName: "delimiter",
42
+ type: "string",
43
+ description: "The character between one column and the next. Worked out from the first line (comma, tab, semicolon or pipe) when it is not set."
44
+ },
45
+ {
46
+ name: "variant",
47
+ plainName: "File Shape",
48
+ technicalName: "variant",
49
+ type: "enum",
50
+ values: Object.entries(M).map(([i, t]) => ({ value: i, label: t })),
51
+ description: "Which CSV shape to read. Worked out from the header row when it is not set."
52
+ },
53
+ {
54
+ name: "idColumn",
55
+ plainName: "Node Id Column",
56
+ technicalName: "idColumn",
57
+ type: "string",
58
+ description: "The column holding each node's identity, when the file lists nodes."
59
+ }
60
+ ], h = [
61
+ {
62
+ name: "edgeSource",
63
+ plainName: "Edge Start Field",
64
+ technicalName: "edgeSource",
65
+ type: "string",
66
+ description: "Where to find the node an edge starts at. Left unset, the element looks for source, then src, then from."
67
+ },
68
+ {
69
+ name: "edgeTarget",
70
+ plainName: "Edge End Field",
71
+ technicalName: "edgeTarget",
72
+ type: "string",
73
+ description: "Where to find the node an edge ends at. Left unset, the element looks for target, then dst, then to."
74
+ }
75
+ ], j = [
76
+ {
77
+ name: "nodeIdPath",
78
+ plainName: "Node Id Field",
79
+ technicalName: "nodeIdPath",
80
+ type: "string",
81
+ description: "An expression selecting each node's identity out of the node record."
82
+ }
83
+ ], _ = [
84
+ {
85
+ id: "json",
86
+ plainName: "JSON",
87
+ extensions: [".json"],
88
+ mimeTypes: ["application/json"],
89
+ canImport: !0,
90
+ canExport: !1,
91
+ options: [...j, ...h]
92
+ },
93
+ {
94
+ id: "csv",
95
+ plainName: "CSV",
96
+ extensions: [".csv", ".tsv", ".tab", ".edges", ".edgelist"],
97
+ mimeTypes: ["text/csv", "text/tab-separated-values", "text/plain"],
98
+ canImport: !0,
99
+ canExport: !1,
100
+ options: [...R, ...h]
101
+ },
102
+ {
103
+ id: "graphml",
104
+ plainName: "GraphML",
105
+ extensions: [".graphml", ".xml"],
106
+ mimeTypes: ["application/graphml+xml", "application/xml", "text/xml"],
107
+ canImport: !0,
108
+ canExport: !1,
109
+ options: h
110
+ },
111
+ {
112
+ id: "gexf",
113
+ plainName: "GEXF",
114
+ // ".xml" is claimed here as well as by GraphML because both formats are XML and both are
115
+ // routinely saved under the generic extension. Two claimants is what lets detection ask
116
+ // each one's content sniffer which of them the file actually is, instead of a private
117
+ // branch inside the detector hard-coding the two namespace strings -- which is the same
118
+ // route a third party's XML dialect now takes.
119
+ extensions: [".gexf", ".xml"],
120
+ mimeTypes: ["application/gexf+xml", "application/xml", "text/xml"],
121
+ canImport: !0,
122
+ canExport: !1,
123
+ options: h
124
+ },
125
+ {
126
+ id: "gml",
127
+ plainName: "GML",
128
+ extensions: [".gml"],
129
+ mimeTypes: ["text/plain"],
130
+ canImport: !0,
131
+ canExport: !1,
132
+ options: h
133
+ },
134
+ {
135
+ id: "dot",
136
+ plainName: "DOT",
137
+ extensions: [".dot", ".gv"],
138
+ mimeTypes: ["text/vnd.graphviz", "text/plain"],
139
+ canImport: !0,
140
+ canExport: !1,
141
+ options: h
142
+ },
143
+ {
144
+ id: "pajek",
145
+ plainName: "Pajek NET",
146
+ extensions: [".net", ".paj"],
147
+ mimeTypes: ["text/plain"],
148
+ canImport: !0,
149
+ canExport: !1,
150
+ options: h
151
+ }
152
+ ], nt = [
153
+ { id: "sif", reason: "No data source reads the Cytoscape simple interaction format." },
154
+ { id: "cx2", reason: "No data source reads the Cytoscape Exchange format." }
155
+ ];
156
+ function ot(i) {
157
+ return _.find((t) => t.id === i) ?? $(i)?.descriptor;
158
+ }
159
+ function at(i) {
160
+ const t = i.toLowerCase();
161
+ return [..._, ...L()].filter(
162
+ (e) => e.extensions.includes(t)
163
+ );
164
+ }
165
+ const m = b({
166
+ kind: "layout",
167
+ idOf: (i) => i.descriptor.id,
168
+ descriptorOf: (i) => i.descriptor,
169
+ implementationOf: (i) => i.descriptor,
170
+ builtInIds: () => D
171
+ });
172
+ function z(i, t) {
173
+ m.register(i, t);
174
+ }
175
+ function lt() {
176
+ return m.descriptors();
177
+ }
178
+ function ct(i) {
179
+ return m.byId(i);
180
+ }
181
+ function ht() {
182
+ m.clearForTesting();
183
+ }
184
+ const o = 3, B = 1024;
185
+ function p(i, t) {
186
+ if (!Number.isInteger(i) || i < 0)
187
+ throw new RangeError(`ElementPositions: ${t} must be a non-negative integer, found ${String(i)}`);
188
+ return i;
189
+ }
190
+ function d(i) {
191
+ return Number.isFinite(Math.fround(i));
192
+ }
193
+ class x {
194
+ /**
195
+ * Allocate the backing array, every row unplaced and unpinned.
196
+ * @param capacity - rows to reserve before the first growth; a non-negative integer
197
+ */
198
+ constructor(t = B) {
199
+ this.components = o, this.rows = 0, p(t, "capacity");
200
+ const e = Math.max(1, t);
201
+ this.array = new Float32Array(o * e), this.array.fill(Number.NaN), this.pins = new Uint8Array(e);
202
+ }
203
+ /**
204
+ * Rows the backing array can hold without reallocating.
205
+ * @returns the current capacity in rows
206
+ */
207
+ get capacity() {
208
+ return this.array.length / o;
209
+ }
210
+ /**
211
+ * Rows currently in use. Equals the last snapshot's nodeCount.
212
+ * @returns the live row count
213
+ */
214
+ get count() {
215
+ return this.rows;
216
+ }
217
+ /**
218
+ * How many live rows carry real coordinates, by the same test {@link ElementPositions.isPlaced}
219
+ * applies one row at a time.
220
+ *
221
+ * The question behind it is "did the file that loaded this graph place every node?", which is
222
+ * what decides whether the Keep Positions arrangement can be used at all: a fixed layout over a
223
+ * graph where half the rows are NaN draws half a picture. Compare it against
224
+ * {@link ElementPositions.count} to answer that -- equal means every node has somewhere to go.
225
+ *
226
+ * COUNTED ON EVERY READ, and it has to be. The array is lent to the snapshot as a mutable
227
+ * column, so a layout, a drag and a GPU readback all write coordinates without passing through
228
+ * this class; a counter kept up to date by `write()` would miss every one of those and would be
229
+ * most wrong exactly while a layout was running, which is when somebody is asking. The scan is
230
+ * one f32 read per node and touches only the x lane.
231
+ *
232
+ * This is deliberately NOT on `GraphStatistics`. Those are memoised against the snapshot they
233
+ * were computed from, and how many nodes carry a coordinate changes while a layout runs WITHIN
234
+ * one snapshot, so a cached answer would be stale in the one moment it mattered.
235
+ * @returns how many rows in `[0, count)` carry a storable x
236
+ */
237
+ get placedCount() {
238
+ let t = 0;
239
+ for (let e = 0; e < o * this.rows; e += o)
240
+ this.hasStorableX(e) && t++;
241
+ return t;
242
+ }
243
+ /**
244
+ * The exact view to hand to `snapshot.nodes.set("position", ...)`.
245
+ *
246
+ * Bounded by the LIVE ROW COUNT, like every other row accessor here. `subarray` CLAMPS rather
247
+ * than throwing, so without a check a caller that forgot to `grow()` first would get a short
248
+ * array: E_COLUMN_LENGTH from inside graph-format if it is attached, and a layout that silently
249
+ * places only the first `count` nodes if it is not. Bounding by the CAPACITY instead would hand
250
+ * out a writable window over the spare rows -- rows this class reports unplaced, whose NaN fill
251
+ * every later `grow()` and `remap()` depends on, and whose contents the next growth erases.
252
+ * @param nodeCount - the snapshot's node count
253
+ * @returns a subarray of length `3 * nodeCount` over the same buffer
254
+ * @throws RangeError when `nodeCount` is not a non-negative integer, or exceeds the live count
255
+ */
256
+ view(t) {
257
+ if (p(t, "nodeCount"), t > this.rows)
258
+ throw new RangeError(
259
+ `ElementPositions: view(${t}) needs ${t} live rows but only ${this.rows} exist; call grow(${t}) first`
260
+ );
261
+ return this.array.subarray(0, o * t);
262
+ }
263
+ /**
264
+ * Prefix-stable growth: existing rows keep their coordinates, EVERY row at or above the new
265
+ * count is unplaced -- including the spare capacity, which a later grow() will hand out.
266
+ *
267
+ * Past the capacity this REPLACES the array object; see the staleness contract on the class.
268
+ * @param nodeCount - the new row count; may be smaller than the current one (append-only
269
+ * builders never shrink, but a caller that does gets a truncation, not a throw). `grow(0)`
270
+ * is how a dataset is discarded while the reserve is kept
271
+ * @throws RangeError when `nodeCount` is not a non-negative integer
272
+ */
273
+ grow(t) {
274
+ if (p(t, "nodeCount"), t > this.capacity) {
275
+ const e = Math.max(this.capacity * 2, t), s = new Float32Array(o * e);
276
+ s.set(this.array), s.fill(Number.NaN, o * this.rows), this.array = s;
277
+ const r = new Uint8Array(e);
278
+ r.set(this.pins), r.fill(0, this.rows), this.pins = r;
279
+ } else t > this.rows ? (this.array.fill(Number.NaN, o * this.rows, o * t), this.pins.fill(0, this.rows, t)) : t < this.rows && (this.array.fill(Number.NaN, o * t, o * this.rows), this.pins.fill(0, t, this.rows));
280
+ this.rows = t;
281
+ }
282
+ /**
283
+ * Apply a freeze report's `nodeRemap` (previous index space -> new index or INVALID_INDEX).
284
+ *
285
+ * `remapArray` ALLOCATES, so this replaces the array object and collapses the capacity to
286
+ * exactly `nodeCount` (PLAN DECISION 3: a removal is rare and never per frame, so paying one
287
+ * reallocation on the next growth is cheaper than copying the remapped rows a second time into
288
+ * a re-reserved array). Every holder of the old object is stale afterwards, which is why
289
+ * GraphStore re-attaches the column on every freeze and emits `snapshot-replaced`.
290
+ * @param nodeRemap - the report's nodeRemap
291
+ * @param nodeCount - the new snapshot's node count
292
+ * @throws RangeError when `nodeCount` is not a non-negative integer
293
+ */
294
+ remap(t, e) {
295
+ p(e, "nodeCount"), this.array = S(this.array, t, e, Number.NaN, o), this.pins = S(this.pins, t, e, 0, 1), this.rows = e;
296
+ }
297
+ /**
298
+ * Whether the reader has fixed this row's node in place.
299
+ *
300
+ * A row outside the live count is UNPINNED, never pinned, for the same reason
301
+ * {@link ElementPositions.isPlaced} answers false there: a node with no row is a node the
302
+ * graph builder has not taken, and answering "pinned" for one would freeze a node that does
303
+ * not exist yet and that nothing could release.
304
+ * @param index - node index
305
+ * @returns true when the row is inside the live count AND carries a pin
306
+ */
307
+ isPinned(t) {
308
+ return !Number.isInteger(t) || t < 0 || t >= this.rows ? !1 : this.pins[t] === 1;
309
+ }
310
+ /**
311
+ * Record or release a pin, GROWING the lane to reach the row.
312
+ *
313
+ * It grows rather than throwing for the same reason `LayoutEngine.writeNodePosition` does: a
314
+ * node's index is handed out the moment the graph builder takes its record, but its row only
315
+ * appears when the graph is next frozen, and a reader who drags a node in between would
316
+ * otherwise have the pin thrown away in silence.
317
+ *
318
+ * It REFUSES rather than throwing for an index that is not a row number at all -- the
319
+ * `INVALID_INDEX` a record the builder would not take carries for its whole life, or a
320
+ * negative or fractional number. Pinning happens from a pointer gesture, and a throw on that
321
+ * path takes the frame with it.
322
+ * @param index - node index
323
+ * @param pinned - true to pin, false to release
324
+ * @returns true when the lane was written, false when the index names no row
325
+ */
326
+ setPinned(t, e) {
327
+ return t === N || !Number.isInteger(t) || t < 0 ? !1 : (t >= this.rows && this.grow(t + 1), this.pins[t] = e ? 1 : 0, !0);
328
+ }
329
+ /**
330
+ * How many live rows are pinned.
331
+ * @returns the count of pinned rows in `[0, count)`
332
+ */
333
+ get pinnedCount() {
334
+ let t = 0;
335
+ for (let e = 0; e < this.rows; e++)
336
+ this.pins[e] === 1 && t++;
337
+ return t;
338
+ }
339
+ /**
340
+ * The exact view to hand to `snapshot.nodes.set("graphty.pinned", ...)`.
341
+ *
342
+ * Bounded by the live row count, like {@link ElementPositions.view} and for the same reasons.
343
+ * @param nodeCount - the snapshot's node count
344
+ * @returns a subarray of length `nodeCount` over the same buffer
345
+ * @throws RangeError when `nodeCount` is not a non-negative integer, or exceeds the live count
346
+ */
347
+ pinnedView(t) {
348
+ if (p(t, "nodeCount"), t > this.rows)
349
+ throw new RangeError(
350
+ `ElementPositions: pinnedView(${t}) needs ${t} live rows but only ${this.rows} exist; call grow(${t}) first`
351
+ );
352
+ return this.pins.subarray(0, t);
353
+ }
354
+ /**
355
+ * Report whether a row carries real coordinates.
356
+ *
357
+ * A row outside the live count is UNPLACED, never placed: this predicate is used to decide
358
+ * whether an importer seed may be written, and answering "placed" for a row that does not
359
+ * exist is how a coordinate gets thrown away without an error. So is a row whose x is an
360
+ * infinity, which only a writer that bypassed `write()` -- that is, one writing through the
361
+ * column this array is lent to -- can produce; see the class comment.
362
+ * @param index - node index
363
+ * @returns true when the row is inside the live count AND carries a storable x
364
+ */
365
+ isPlaced(t) {
366
+ return !Number.isInteger(t) || t < 0 || t >= this.rows ? !1 : this.hasStorableX(o * t);
367
+ }
368
+ /**
369
+ * Read one row into a caller-supplied object (14.4 rule 7: never return a shared vector).
370
+ * @param index - node index
371
+ * @param out - the object to fill
372
+ * @param out.x - receives the scene-unit x
373
+ * @param out.y - receives the scene-unit y
374
+ * @param out.z - receives the scene-unit z
375
+ * @throws RangeError when `index` is not an integer in `[0, count)`
376
+ */
377
+ read(t, e) {
378
+ const s = this.rowBase(t);
379
+ e.x = this.array[s] ?? Number.NaN, e.y = this.array[s + 1] ?? Number.NaN, e.z = this.array[s + 2] ?? Number.NaN;
380
+ }
381
+ /**
382
+ * Write one row.
383
+ *
384
+ * This is the ONE choke point every layout, every drag and (from E1) every GPU readback goes
385
+ * through, so it is where an unstorable coordinate is stopped. NaN is this class's unplaced
386
+ * marker: letting one in through here would unplace a placed node from the inside, and an
387
+ * infinity would be stored and then reported placed. The test is `isStorableCoordinate`, NOT
388
+ * `Number.isFinite`, because the array is f32: a finite double of 1e39 passes `isFinite` and
389
+ * lands as Infinity. A caller holding such a coordinate has a bug upstream and must drop the
390
+ * update, not hand it on.
391
+ * @param index - node index
392
+ * @param x - scene-unit x
393
+ * @param y - scene-unit y
394
+ * @param z - scene-unit z
395
+ * @throws RangeError when `index` is not an integer in `[0, count)`. A node added since the
396
+ * last freeze has no row yet: freeze first (which grows this array), then write
397
+ * @throws RangeError when any component is NaN, an infinity, or a double that overflows f32
398
+ */
399
+ write(t, e, s, r) {
400
+ const n = this.rowBase(t);
401
+ if (!d(e) || !d(s) || !d(r))
402
+ throw new RangeError(
403
+ `ElementPositions: row ${String(t)} was written the unstorable coordinate (${String(e)}, ${String(s)}, ${String(r)}); NaN is this class's UNPLACED marker, and an infinity -- including one an f32 overflow produces -- poisons the scene bounds`
404
+ );
405
+ this.array[n] = e, this.array[n + 1] = s, this.array[n + 2] = r;
406
+ }
407
+ /**
408
+ * Write a row ONLY when it is unplaced. This is how importer-seeded coordinates reach a new
409
+ * node without overwriting anything a layout or a drag already produced.
410
+ *
411
+ * `false` means exactly one thing -- the row was ALREADY PLACED, by the same test `isPlaced()`
412
+ * applies. A row that does not exist yet throws instead of returning `false`, so a caller that
413
+ * seeds before growing finds out rather than losing the coordinate.
414
+ * @param index - node index
415
+ * @param x - scene-unit x
416
+ * @param y - scene-unit y
417
+ * @param z - scene-unit z
418
+ * @returns true when the row was written, false when it was already placed
419
+ * @throws RangeError when `index` is not an integer in `[0, count)`
420
+ * @throws RangeError when any component is NaN, an infinity, or a double that overflows f32,
421
+ * through `write()`
422
+ */
423
+ fillUnplaced(t, e, s, r) {
424
+ const n = this.rowBase(t);
425
+ return this.hasStorableX(n) ? !1 : (this.write(t, e, s, r), !0);
426
+ }
427
+ /**
428
+ * Whether the row at this offset carries a storable x, which is the one test "placed" means.
429
+ * @param base - the array offset of the row's x component
430
+ * @returns true when the stored x is neither NaN nor an infinity
431
+ */
432
+ hasStorableX(t) {
433
+ return d(this.array[t] ?? Number.NaN);
434
+ }
435
+ /**
436
+ * The array offset of a live row, rejecting anything else.
437
+ * @param index - node index
438
+ * @returns the offset of the row's x component
439
+ */
440
+ rowBase(t) {
441
+ if (!Number.isInteger(t) || t < 0 || t >= this.rows)
442
+ throw new RangeError(
443
+ t === N ? "ElementPositions: INVALID_INDEX is the graph-format 'no node' sentinel, not a row" : `ElementPositions: row ${String(t)} is outside the live range [0, ${this.rows})`
444
+ );
445
+ return o * t;
446
+ }
447
+ }
448
+ const l = /* @__PURE__ */ new Map(), C = Object.freeze([
449
+ "arf",
450
+ "bfs",
451
+ "bipartite",
452
+ "circular",
453
+ "d3",
454
+ "fixed",
455
+ "forceatlas2",
456
+ "kamada-kawai",
457
+ "multipartite",
458
+ "ngraph",
459
+ "planar",
460
+ "random",
461
+ "shell",
462
+ "spectral",
463
+ "spiral",
464
+ "spring",
465
+ "spring-electrical"
466
+ ]), W = F.getLogger(["graphty", "layout"]), P = 1e-6;
467
+ function G(i, t) {
468
+ return JSON.stringify([i, t]);
469
+ }
470
+ const U = 10;
471
+ function A(i) {
472
+ return new g({
473
+ code: "E_DUPLICATE_PLUGIN",
474
+ message: `"${i}" is a layout engine the element ships, and a built-in name may not be taken: a saved document that named it yesterday has to mean the same thing today`,
475
+ source: "registry",
476
+ details: { kind: "layout", name: i, builtIn: !0 }
477
+ });
478
+ }
479
+ const E = class E {
480
+ constructor() {
481
+ this.positionArrayAttached = !1;
482
+ }
483
+ /**
484
+ * Add multiple nodes to the layout engine
485
+ * @param nodes - Array of nodes to add
486
+ */
487
+ addNodes(t) {
488
+ for (const e of t)
489
+ this.addNode(e);
490
+ }
491
+ /**
492
+ * Add multiple edges to the layout engine
493
+ * @param edges - Array of edges to add
494
+ */
495
+ addEdges(t) {
496
+ for (const e of t)
497
+ this.addEdge(e);
498
+ }
499
+ /**
500
+ * Take a node out of the layout, before the element disposes the mesh that drew it.
501
+ *
502
+ * Declared here, with a default that does nothing, because it used to be duck-typed by the
503
+ * element's data manager and implemented by none of the seventeen engines that ship here: an
504
+ * author learned it existed by reading the element's source, and got no worked example. An
505
+ * engine that keeps its own node list must override this, or it holds every removed node --
506
+ * and everything that node references -- for as long as the engine lives.
507
+ * @param _n - the node leaving the graph
508
+ */
509
+ removeNode(t) {
510
+ }
511
+ /**
512
+ * The edge half of {@link LayoutEngine.removeNode}, with the same default and the same reason.
513
+ * @param _e - the edge leaving the graph
514
+ */
515
+ removeEdge(t) {
516
+ }
517
+ /**
518
+ * Settle nodes that reached the graph after this layout was already running.
519
+ *
520
+ * THE DEFAULT IS THE ELEMENT'S OWN FALLBACK -- up to ten steps, stopping early if the engine
521
+ * settles -- so a simulation behaves exactly as it did before the hook was declared, and an
522
+ * engine that can place a newcomer without re-running the whole simulation overrides it. It
523
+ * lives on the base class rather than in the manager because the manager cannot tell "did not
524
+ * implement it" from "implemented it as a deliberate no-op", and the difference decides
525
+ * whether ten steps run.
526
+ * @param _nodes - the nodes that have just arrived
527
+ */
528
+ updatePositions(t) {
529
+ for (let e = 0; e < U; e++) {
530
+ if (this.isSettled)
531
+ return;
532
+ this.step();
533
+ }
534
+ }
535
+ /**
536
+ * Release whatever this engine holds. The element calls it when the reader switches layouts
537
+ * and when the graph is torn down, and never uses the engine again afterwards.
538
+ *
539
+ * Declared with a do-nothing default for the same reason as {@link LayoutEngine.removeNode}:
540
+ * it was duck-typed, undeclared and unimplemented by every engine here.
541
+ */
542
+ dispose() {
543
+ }
544
+ /**
545
+ * The array this engine publishes node coordinates into.
546
+ *
547
+ * Allocated on demand, so reading it is enough to make an engine that has never been handed an
548
+ * element's array produce one of its own.
549
+ * @returns the position array in use
550
+ */
551
+ get nodePositions() {
552
+ return this.positionArray ??= new x(0), this.positionArray;
553
+ }
554
+ /**
555
+ * Hand this engine the array it must publish into, and stop it adopting any other.
556
+ *
557
+ * This is how a host says "these coordinates are mine": the engine writes into the array the
558
+ * host already lends to its snapshots, so a layout, a drag and a GPU readback all land in the
559
+ * one place and a re-freeze loses none of them.
560
+ * @param positions - the element-owned array
561
+ */
562
+ attachPositions(t) {
563
+ this.positionArray = t, this.positionArrayAttached = !0;
564
+ }
565
+ /**
566
+ * Copy every node's current coordinates out of the engine and into the position array.
567
+ *
568
+ * Engines call this at the end of a step, so that by the time anything draws, the array is the
569
+ * answer rather than a copy of it. The default walks the engine's own nodes through
570
+ * {@link LayoutEngine.getNodePosition}, which is correct for any engine but allocates one
571
+ * object per node; an engine that can read its own state without allocating overrides it, and
572
+ * an engine that already writes straight into the array overrides it to do nothing.
573
+ */
574
+ publishPositions() {
575
+ for (const t of this.nodes) {
576
+ const e = this.getNodePosition(t);
577
+ this.writeNodePosition(t, e.x, e.y, e.z ?? 0);
578
+ }
579
+ }
580
+ /**
581
+ * Read a node's published coordinates into an object the CALLER owns.
582
+ *
583
+ * The point of the out parameter is that a renderer can pass the vector it is about to draw
584
+ * with and allocate nothing per node per frame. A row that no engine has placed answers false
585
+ * and leaves `out` untouched, so the caller keeps whatever it had rather than being handed a
586
+ * NaN or an origin it cannot tell from a real coordinate.
587
+ * @param n - the node to read
588
+ * @param out - the object to fill; a Babylon `Vector3` is one, which is the point
589
+ * @param out.x - receives the scene-unit x
590
+ * @param out.y - receives the scene-unit y
591
+ * @param out.z - receives the scene-unit z
592
+ * @returns true when the node has a placed row
593
+ */
594
+ readNodePosition(t, e) {
595
+ const s = this.positionsFor(t);
596
+ return s.isPlaced(t.index) ? (s.read(t.index, e), !0) : !1;
597
+ }
598
+ /**
599
+ * Publish one node's coordinates, growing the array to reach its row.
600
+ *
601
+ * Three things are silently skipped rather than thrown, because this runs inside a layout step
602
+ * and a throw there kills the frame: a node with no row in the graph (`INVALID_INDEX`, which a
603
+ * record whose id the graph builder would not take carries for its whole life), a node whose
604
+ * index is not a row number at all, and a coordinate that cannot be stored. That last one is
605
+ * the important one -- a force layout that divided by a zero distance produces NaN, and an
606
+ * overflow of the f32 the array stores produces an infinity. Either one, written, would make
607
+ * the row read back as a place: the mesh vanishes and the scene bounds and camera framing go
608
+ * with it. Left alone, the row stays unplaced and the node keeps the coordinates it had.
609
+ *
610
+ * The array is GROWN to reach the row rather than the write being refused. A node's index is
611
+ * handed out the moment its record is taken, but its row only appears when the graph is next
612
+ * frozen, and a layout that ran in between would otherwise be thrown away in silence. Growth is
613
+ * prefix-stable and fills what it adds with NaN, so it cannot disturb a row anything else
614
+ * placed; the one thing it does change is that a node this engine placed before the first
615
+ * freeze counts as placed, which is what makes a file's own coordinates yield to it.
616
+ *
617
+ * A PINNED ROW REFUSES A LAYOUT STEP. This is the whole of "a pin is meaningful under every
618
+ * arrangement": twelve of the element's seventeen engines implement `pin()` as a no-op and
619
+ * `setNodePosition` as a no-op too, so before this guard a reader who dragged a node under a
620
+ * static layout watched it snap back the next time the layout recomputed. One refusal here
621
+ * covers every engine, including one written by a third party that has never heard of pinning,
622
+ * because every engine reaches the shared array through this method.
623
+ *
624
+ * A DRAG IS NOT A LAYOUT STEP. `intent: "placement"` writes straight through, so a reader can
625
+ * move a pinned node and have it stay where they put it; without that distinction the guard
626
+ * would make a pinned node undraggable, which is the opposite of what a pin is for. The
627
+ * default is `"layout"` so that an engine written before the parameter existed -- a plugin's
628
+ * step loop -- is guarded without knowing it, and only the placement paths have to opt out.
629
+ * @param n - the node being placed
630
+ * @param x - scene-unit x
631
+ * @param y - scene-unit y
632
+ * @param z - scene-unit z
633
+ * @param intent - `"layout"` for a simulation step, `"placement"` for a drag or a replay
634
+ * @returns true when the row was written
635
+ */
636
+ writeNodePosition(t, e, s, r, n = "layout") {
637
+ const { index: a } = t;
638
+ if (a === N || !Number.isInteger(a) || a < 0 || !d(e) || !d(s) || !d(r))
639
+ return !1;
640
+ const c = this.positionsFor(t);
641
+ return n === "layout" && c.isPinned(a) ? !1 : (a >= c.count && c.grow(a + 1), c.write(a, e, s, r), !0);
642
+ }
643
+ /**
644
+ * The weight of every ordered endpoint pair this batch of edges covers, or null when the
645
+ * graph's weights carry no information.
646
+ *
647
+ * WHY A PAIR AND NOT AN EDGE. `@graphty/layout`'s one weight channel is
648
+ * `graph.getEdgeData(source, target, attr)`, which is asked by endpoint pair, and both layout
649
+ * functions that read it write the answer into a matrix cell -- `A[i][j]` in ForceAtlas2,
650
+ * `distances[s][t]` in Kamada-Kawai. There is no cell for a second edge between the same two
651
+ * nodes, so parallel edges are SUMMED into one number rather than left to last-writer-wins,
652
+ * where the order the file happened to list them in would decide the arrangement. Summing is
653
+ * also what the element does when it simplifies a multigraph for an algorithm, so a graph's
654
+ * weights mean the same thing to a layout and to a metric.
655
+ *
656
+ * READ ONCE PER LAYOUT COMPUTATION, not per frame and not per edge: the weights come from the
657
+ * current snapshot's edge list, indexed by the same logical edge index `Edge.index` holds.
658
+ *
659
+ * NULL MEANS "DO NOT ATTACH A CALLBACK". graph-format stores an all-ones graph with no weight
660
+ * column at all, and a graph whose every weight is 1 carries no information a layout could
661
+ * arrange by -- so the caller leaves `getEdgeData` off the graph object entirely and the
662
+ * arrangement is bit-identical to the one the same seed produced before weights existed.
663
+ *
664
+ * THIS IS A SLIGHTLY NARROWER QUESTION THAN `statistics().weighted`, deliberately. The status
665
+ * chip asks whether the SNAPSHOT's weight column carries anything but ones; this asks it of
666
+ * the edges this engine is actually about to arrange. They answer differently only when the
667
+ * engine holds a strict subset of the graph's edges whose weights are all 1, and there the
668
+ * narrower answer is the correct one: a layout cannot be moved by a weight on an edge it is
669
+ * not laying out. A consumer who sees "weighted" on the status bar and an unmoved arrangement
670
+ * is looking at that case.
671
+ * @param edges - the edges this engine is about to lay out
672
+ * @returns pair key (see {@link pairWeightKey}) to summed weight, or null
673
+ */
674
+ pairWeights(t) {
675
+ if (t.length === 0)
676
+ return null;
677
+ const s = t[0].parentGraph?.getDataManager?.()?.getSnapshot?.()?.edgeList().weights ?? null;
678
+ if (s === null)
679
+ return null;
680
+ const r = /* @__PURE__ */ new Map();
681
+ let n = !1;
682
+ for (const a of t) {
683
+ const c = a.index >= 0 && a.index < s.length ? s[a.index] : 1;
684
+ c !== 1 && (n = !0);
685
+ const I = G(a.srcId, a.dstId);
686
+ r.set(I, (r.get(I) ?? 0) + c);
687
+ }
688
+ return n ? r : null;
689
+ }
690
+ /**
691
+ * Say once, per layout computation, how many pairs were clamped off zero.
692
+ *
693
+ * ONCE PER RUN AND NOT PER EDGE: a graph whose weights are all zero would otherwise produce
694
+ * one line per edge, which buries every other message in the run it happened during. It is
695
+ * reported at all because a clamp changes the picture -- a zero-weight edge is drawn as the
696
+ * weakest connection the solver can express rather than as no connection -- and the record
697
+ * that carried the zero is the reader's, not the element's, so they are the one who can fix
698
+ * it.
699
+ * @param layout - the layout name, for the message
700
+ * @param weights - the pair weights about to be handed to the layout function
701
+ */
702
+ reportClampedWeights(t, e) {
703
+ let s = 0;
704
+ for (const r of e.values())
705
+ r < P && s++;
706
+ s > 0 && W.warn("Edge weights at or below zero were clamped before the layout read them", {
707
+ layout: t,
708
+ clamped: s,
709
+ epsilon: P
710
+ });
711
+ }
712
+ /**
713
+ * The array to use for this node: the one its own graph owns, unless a host attached one.
714
+ *
715
+ * Resolved on every call rather than cached, because the element REPLACES its array when a
716
+ * dataset is discarded -- the store and everything keyed into it is thrown away and rebuilt --
717
+ * and an engine outlives that. A cached reference would keep publishing into the array of a
718
+ * graph that no longer exists, which is invisible: every write succeeds and nothing draws.
719
+ * @param n - the node being published or read
720
+ * @returns the array to write to and read from
721
+ */
722
+ positionsFor(t) {
723
+ if (!this.positionArrayAttached) {
724
+ const e = t.parentGraph?.getDataManager?.()?.positions;
725
+ e instanceof x && (this.positionArray = e);
726
+ }
727
+ return this.nodePositions;
728
+ }
729
+ /**
730
+ * Get the type identifier for this layout engine
731
+ * @returns The layout engine type string
732
+ */
733
+ get type() {
734
+ return this.constructor.type;
735
+ }
736
+ /**
737
+ * File a layout engine class under the name it declares, and publish what it says about
738
+ * itself to the catalogue.
739
+ *
740
+ * WHAT CHANGED AND WHY. This used to read `cls.type` through a cast and put the class in a
741
+ * map, which meant a class with no `static type` registered under the string "undefined", a
742
+ * second class under a taken name silently replaced the first, and a registered engine
743
+ * reached no catalogue at all -- so a third party's layout could run but could never be
744
+ * offered by a picker, described in a reader's language, or found by `layoutIdForEngine`.
745
+ *
746
+ * A third party's class must declare a `static descriptor` whose `id` equals its
747
+ * `static type`. The element's own seventeen are the one exemption, because their arrangements
748
+ * are authored centrally in the layout catalogue where several engines may sit behind one
749
+ * public name.
750
+ * @param cls - The layout engine class.
751
+ * @returns The same class, so a declaration can register itself in one expression.
752
+ * @throws A `GraphtyError` with `E_BAD_COMMAND` when the class declares no `static type`, no
753
+ * `static descriptor`, or a descriptor whose `id` disagrees with its `static type`; or with
754
+ * `E_DUPLICATE_PLUGIN` when the name or the descriptor id is one the element itself ships.
755
+ */
756
+ static register(t) {
757
+ const e = t, { type: s, descriptor: r } = e;
758
+ if (typeof s != "string" || s === "")
759
+ throw new g({
760
+ code: "E_BAD_COMMAND",
761
+ message: "a layout engine is filed under its `static type`, and this class declares none",
762
+ source: "registry",
763
+ details: { kind: "layout", field: "type" }
764
+ });
765
+ if (l.get(s) === t)
766
+ return t;
767
+ const n = C.includes(s);
768
+ if (r === void 0) {
769
+ if (!n)
770
+ throw new g({
771
+ code: "E_BAD_COMMAND",
772
+ message: `the layout "${s}" declares no \`static descriptor\`, so nothing could offer it: a picker reads the catalogue, and an engine the catalogue does not carry is reachable only by a consumer who already knows its name`,
773
+ source: "registry",
774
+ details: { kind: "layout", name: s, field: "descriptor" }
775
+ });
776
+ if (l.has(s))
777
+ throw A(s);
778
+ return l.set(s, t), t;
779
+ }
780
+ if (n)
781
+ throw A(s);
782
+ if (r.id !== s)
783
+ throw new g({
784
+ code: "E_BAD_COMMAND",
785
+ message: `the layout "${s}" describes itself as "${r.id}". A layout has ONE key: the name \`setLayout\` takes and the name the catalogue publishes are the same string, so nothing has to be named twice and a saved document means one thing`,
786
+ source: "registry",
787
+ details: { kind: "layout", name: s, field: "descriptor.id", id: r.id }
788
+ });
789
+ return z({
790
+ descriptor: { ...r, honoursWeights: e.honoursWeights ?? !1 },
791
+ type: s
792
+ }), l.set(s, t), t;
793
+ }
794
+ /**
795
+ * Get a layout engine instance by type
796
+ * @param type - The layout engine type identifier
797
+ * @param opts - Configuration options for the layout engine
798
+ * @returns A new layout engine instance or null if type not found
799
+ */
800
+ static get(t, e = {}) {
801
+ const s = l.get(t);
802
+ return s ? new s(e) : null;
803
+ }
804
+ /**
805
+ * Get dimension-specific options for this layout
806
+ * @param dimension - The desired dimension (2 or 3)
807
+ * @returns Options object for the dimension or null if unsupported
808
+ */
809
+ static getOptionsForDimension(t) {
810
+ return t > this.maxDimensions ? null : {};
811
+ }
812
+ /**
813
+ * Get dimension-specific options for a layout by type
814
+ * @param type - The layout engine type identifier
815
+ * @param dimension - The desired dimension (2 or 3)
816
+ * @returns Options object for the dimension or null if type not found or unsupported
817
+ */
818
+ static getOptionsForDimensionByType(t, e) {
819
+ const s = l.get(t);
820
+ return s ? s.getOptionsForDimension(e) : null;
821
+ }
822
+ /**
823
+ * Get the Zod-based options schema for this layout
824
+ * @returns The options schema, or an empty object if no schema defined
825
+ */
826
+ static getZodOptionsSchema() {
827
+ return this.zodOptionsSchema ?? {};
828
+ }
829
+ /**
830
+ * Check if this layout has a Zod-based options schema
831
+ * @returns true if the layout has options defined
832
+ */
833
+ static hasZodOptions() {
834
+ return this.zodOptionsSchema !== void 0 && Object.keys(this.zodOptionsSchema).length > 0;
835
+ }
836
+ /**
837
+ * Get a list of all registered layout types
838
+ * @returns Array of registered layout type identifiers
839
+ */
840
+ static getRegisteredTypes() {
841
+ return Array.from(l.keys());
842
+ }
843
+ /**
844
+ * Get a layout class by type
845
+ * @param type - The layout engine type identifier
846
+ * @returns The layout engine class or null if not found
847
+ */
848
+ static getClass(t) {
849
+ return l.get(t) ?? null;
850
+ }
851
+ };
852
+ E.honoursWeights = !1;
853
+ let w = E;
854
+ const V = O.looseObject({
855
+ scalingFactor: O.number().default(100)
856
+ });
857
+ class dt extends w {
858
+ /**
859
+ * Create a simple layout engine
860
+ * @param opts - Configuration options including scalingFactor
861
+ */
862
+ constructor(t = {}) {
863
+ super(), this._nodes = [], this._edges = [], this.stale = !0, this.positions = {}, this.scalingFactor = 100, this.isSettled = !0;
864
+ const e = V.parse(t);
865
+ this.scalingFactor = e.scalingFactor;
866
+ }
867
+ /**
868
+ * Get dimension-specific options for simple layouts
869
+ * @param dimension - The desired dimension (2 or 3)
870
+ * @returns Options object with dim parameter or null if unsupported
871
+ */
872
+ static getOptionsForDimension(t) {
873
+ return t > this.maxDimensions ? null : { dim: t };
874
+ }
875
+ // basic functionality
876
+ /**
877
+ * Initialize the layout engine
878
+ *
879
+ * Simple layouts compute positions synchronously and don't require initialization.
880
+ */
881
+ async init() {
882
+ }
883
+ /**
884
+ * Add a node to the layout and mark positions as stale
885
+ * @param n - The node to add
886
+ */
887
+ addNode(t) {
888
+ this._nodes.push(t), this.stale = !0;
889
+ }
890
+ /**
891
+ * Add an edge to the layout and mark positions as stale
892
+ * @param e - The edge to add
893
+ */
894
+ addEdge(t) {
895
+ this._edges.push(t), this.stale = !0;
896
+ }
897
+ /**
898
+ * Get the position of a node, computing layout if stale
899
+ *
900
+ * The coordinates come from the shared position array, which `SimpleLayoutEngine.refresh`
901
+ * fills from `positions` as soon as the layout is recomputed. They are the same numbers the
902
+ * record holds, rounded to the f32 the array stores -- so an arrangement never moves, but a
903
+ * coordinate may differ in its last digit or two from the double the layout function returned.
904
+ * A node with no row falls back to the record, which is every node in an engine driven by hand.
905
+ * @param n - The node to get position for
906
+ * @returns The node's position coordinates
907
+ */
908
+ getNodePosition(t) {
909
+ return this.refresh(), this.publishedOr(t, t.id);
910
+ }
911
+ /**
912
+ * Record where the reader has just put a node.
913
+ *
914
+ * A static layout recomputes every coordinate from scratch, so it has no per-node state a
915
+ * placement could live in -- which is why this used to do nothing at all, and why a drag
916
+ * under any of the fourteen static arrangements was discarded by the next `refresh()`. The
917
+ * placement is written into the SHARED array instead, with `"placement"` intent so that it
918
+ * lands even on a pinned row, and into the computed record so that a read which falls back to
919
+ * the record (a node with no row of its own) answers the same.
920
+ * @param n - the node that moved
921
+ * @param p - where it moved to
922
+ */
923
+ setNodePosition(t, e) {
924
+ const s = e.z ?? 0;
925
+ this.writeNodePosition(t, e.x, e.y, s, "placement"), this.positions[t.id] = [e.x / this.scalingFactor, e.y / this.scalingFactor, s / this.scalingFactor];
926
+ }
927
+ /**
928
+ * Get the position of an edge based on its endpoints
929
+ * @param e - The edge to get position for
930
+ * @returns The edge's source and destination positions
931
+ */
932
+ getEdgePosition(t) {
933
+ return this.refresh(), {
934
+ src: this.publishedOr(t.srcNode, t.srcId),
935
+ dst: this.publishedOr(t.dstNode, t.dstId)
936
+ };
937
+ }
938
+ /**
939
+ * Copy the computed layout into the shared position array, recomputing it first if it is stale.
940
+ */
941
+ publishPositions() {
942
+ if (this.stale) {
943
+ this.refresh();
944
+ return;
945
+ }
946
+ this.publishRecord();
947
+ }
948
+ // for animated layouts
949
+ /**
950
+ * Step the layout animation
951
+ *
952
+ * Simple layouts are static and don't animate, so stepping has no effect.
953
+ */
954
+ step() {
955
+ }
956
+ /**
957
+ * Take a node out of the layout.
958
+ *
959
+ * WITHOUT THIS the engine holds the removed node -- and through it the node's Babylon mesh,
960
+ * its data record and its endpoints -- for as long as the engine lives, and the frame loop
961
+ * keeps walking it, so a node the reader deleted still draws at wherever it last was.
962
+ *
963
+ * The computed record is left alone and the layout is marked stale instead. Every layout
964
+ * function here returns a WHOLE new record, which `doLayout` assigns over the old one, and
965
+ * `refresh()` runs before any read -- so the removed node's entry is gone by the time anything
966
+ * could read it, without this method having to reach into a keyed object by a computed name.
967
+ * @param n - the node leaving the graph
968
+ */
969
+ removeNode(t) {
970
+ const e = this._nodes.indexOf(t);
971
+ e >= 0 && this._nodes.splice(e, 1), this.stale = !0;
972
+ }
973
+ /**
974
+ * The edge half of {@link SimpleLayoutEngine.removeNode}, with the same reason.
975
+ * @param e - the edge leaving the graph
976
+ */
977
+ removeEdge(t) {
978
+ const e = this._edges.indexOf(t);
979
+ e >= 0 && this._edges.splice(e, 1), this.stale = !0;
980
+ }
981
+ /**
982
+ * Pin a node in place
983
+ *
984
+ * A static layout has nothing of its own to hold still -- it recomputes every position from
985
+ * scratch -- so the pin is kept by the element's position array instead, and
986
+ * `writeNodePosition` refuses to move a pinned row. That is what makes a
987
+ * pin mean something under all fourteen of these engines, none of which could hold one.
988
+ */
989
+ pin() {
990
+ }
991
+ /**
992
+ * Unpin a node
993
+ *
994
+ * The element's position array holds the pin; see {@link SimpleLayoutEngine.pin}.
995
+ */
996
+ unpin() {
997
+ }
998
+ // properties
999
+ /**
1000
+ * Get all nodes in the layout
1001
+ * @returns Iterable of nodes
1002
+ */
1003
+ get nodes() {
1004
+ return this._nodes;
1005
+ }
1006
+ /**
1007
+ * Get all edges in the layout
1008
+ * @returns Iterable of edges
1009
+ */
1010
+ get edges() {
1011
+ return this._edges;
1012
+ }
1013
+ /**
1014
+ * Recompute the layout when it is stale, and publish what it produced.
1015
+ *
1016
+ * A simple layout is computed once and then held, so this is the ONE place the shared array is
1017
+ * filled: every reader below goes through here first, which is why a node added after the last
1018
+ * read still gets a row before anything asks for its coordinates.
1019
+ */
1020
+ refresh() {
1021
+ this.stale && (this.doLayout(), this.stale = !1, this.publishRecord());
1022
+ }
1023
+ /**
1024
+ * Write the computed record into the shared array, scaled to scene units.
1025
+ *
1026
+ * A node the layout function returned nothing for is LEFT UNPLACED rather than published at
1027
+ * the origin: the two are indistinguishable once stored, and the origin is a place a reader
1028
+ * would draw at.
1029
+ */
1030
+ publishRecord() {
1031
+ for (const t of this._nodes) {
1032
+ const e = this.positions[t.id];
1033
+ !e || e.length === 0 || this.writeNodePosition(
1034
+ t,
1035
+ e[0] * this.scalingFactor,
1036
+ e[1] * this.scalingFactor,
1037
+ (e[2] ?? 0) * this.scalingFactor
1038
+ );
1039
+ }
1040
+ }
1041
+ /**
1042
+ * A node's published row, or the computed record when it has no row of its own.
1043
+ *
1044
+ * The fallback is not a rare path: an engine driven directly -- by a test, or by a host that
1045
+ * keeps no graph -- has nodes whose index is `INVALID_INDEX`, and none of them is ever
1046
+ * published. Both branches produce the same arrangement; only the rounding differs.
1047
+ * @param n - the node, when the caller has one
1048
+ * @param id - the node's id, which is how the computed record is keyed
1049
+ * @returns a fresh coordinate triple
1050
+ */
1051
+ publishedOr(t, e) {
1052
+ const s = { x: 0, y: 0, z: 0 };
1053
+ return t !== void 0 && this.readNodePosition(t, s) ? s : X(this.positions[e], this.scalingFactor);
1054
+ }
1055
+ }
1056
+ function X(i, t) {
1057
+ if (!i || i.length === 0)
1058
+ return { x: 0, y: 0, z: 0 };
1059
+ const e = i[0] * t, s = i[1] * t, r = (i[2] ?? 0) * t;
1060
+ return { x: e, y: s, z: r };
1061
+ }
1062
+ const K = /^#[0-9a-f]{6}$/i;
1063
+ function q(i) {
1064
+ if (typeof i != "string" || i.trim() === "")
1065
+ return null;
1066
+ try {
1067
+ const t = v(i.trim());
1068
+ if (t === void 0)
1069
+ return null;
1070
+ const e = t.length === 9 ? t.slice(0, 7) : t;
1071
+ return K.test(e) ? e.toUpperCase() : null;
1072
+ } catch {
1073
+ return null;
1074
+ }
1075
+ }
1076
+ function H(i) {
1077
+ return JSON.stringify([i.id, i.kind, i.colors, i.capacity, i.colorblindSafe]);
1078
+ }
1079
+ const y = b({
1080
+ kind: "palette",
1081
+ idOf: (i) => i.id,
1082
+ descriptorOf: (i) => i,
1083
+ implementationOf: H,
1084
+ builtInIds: () => k
1085
+ });
1086
+ function u(i, t, e) {
1087
+ throw new g({
1088
+ code: "E_BAD_COMMAND",
1089
+ message: e,
1090
+ source: "registry",
1091
+ details: { kind: "palette", name: typeof i == "string" ? i : "", field: t }
1092
+ });
1093
+ }
1094
+ function ut(i, t) {
1095
+ typeof i != "object" && u("", "descriptor", "registerPalette takes a palette descriptor"), (i.plainName === void 0 || i.plainName === "") && u(i.id, "plainName", `the palette "${String(i.id)}" was registered without a plain name`), i.kind !== "sequential" && i.kind !== "diverging" && i.kind !== "categorical" && u(
1096
+ i.id,
1097
+ "kind",
1098
+ `the palette "${String(i.id)}" must be sequential, diverging or categorical`
1099
+ ), (!Array.isArray(i.colors) || i.colors.length === 0) && u(i.id, "colors", `the palette "${String(i.id)}" was registered with no colours`);
1100
+ const e = [];
1101
+ for (const r of i.colors) {
1102
+ const n = q(r);
1103
+ n === null && u(i.id, "colors", `"${String(r)}" in the palette "${String(i.id)}" is not a colour`), e.push(n);
1104
+ }
1105
+ const s = i.kind === "categorical" ? e.length : null;
1106
+ i.capacity !== void 0 && i.capacity !== s && u(
1107
+ i.id,
1108
+ "capacity",
1109
+ `the palette "${String(i.id)}" is ${i.kind}, so its capacity is ${s === null ? "null" : String(s)} rather than ${String(i.capacity)}`
1110
+ ), y.register(
1111
+ Object.freeze({
1112
+ ...i,
1113
+ colors: Object.freeze(e),
1114
+ capacity: s,
1115
+ colorblindSafe: Object.freeze(i.colorblindSafe ?? [])
1116
+ }),
1117
+ t
1118
+ );
1119
+ }
1120
+ function pt() {
1121
+ return y.descriptors();
1122
+ }
1123
+ function gt(i) {
1124
+ return y.byId(i);
1125
+ }
1126
+ function ft() {
1127
+ y.clearForTesting();
1128
+ }
1129
+ export {
1130
+ x as E,
1131
+ _ as F,
1132
+ w as L,
1133
+ o as P,
1134
+ V as S,
1135
+ nt as U,
1136
+ P as W,
1137
+ dt as a,
1138
+ ht as b,
1139
+ rt as c,
1140
+ ft as d,
1141
+ L as e,
1142
+ lt as f,
1143
+ pt as g,
1144
+ st as h,
1145
+ ot as i,
1146
+ at as j,
1147
+ G as k,
1148
+ ct as l,
1149
+ gt as m,
1150
+ d as n,
1151
+ it as p,
1152
+ ut as r
1153
+ };