@graphty/graphty-element 2.3.0 → 2.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 (90) hide show
  1. package/AGENTS.md +4 -3
  2. package/dist/ai.js +115 -222
  3. package/dist/catalog.js +46 -44
  4. package/dist/chunks/{AiManager-Bd_r1Hei.js → AiManager-BD9XK30e.js} +793 -654
  5. package/dist/chunks/{DataSource-bt0DhBjG.js → DataSource-B8vf2uhW.js} +3 -3
  6. package/dist/chunks/{GraphSession-iNyKm7Ds.js → GraphSession-dcwOjGJh.js} +3028 -2918
  7. package/dist/chunks/{GraphStyle-D0PXnZKu.js → GraphStyle-Cwr55SAE.js} +5 -2
  8. package/dist/chunks/{GraphtyError-BwcnblTH.js → GraphtyError-B93WRH3e.js} +8 -6
  9. package/dist/chunks/{GraphtyLogger-5KEttFUo.js → GraphtyLogger-CqOVV13Y.js} +2 -2
  10. package/dist/chunks/{NodeStyle-DKj7HjMJ.js → NodeStyle-CtmA7dXi.js} +16 -14
  11. package/dist/chunks/{VoiceInputAdapter-DszYl6Ha.js → VoiceInputAdapter-D0tHHi9G.js} +1 -1
  12. package/dist/chunks/{XRPivotCameraController-XtxbbZ-D.js → XRPivotCameraController-DTfhvhHz.js} +2 -2
  13. package/dist/chunks/algorithms-BF0X6RPw.js +3627 -0
  14. package/dist/chunks/{capability-check-BqIEXcun.js → capability-check-BJzlK4oL.js} +1 -1
  15. package/dist/chunks/{detect-DM29BEaB.js → detect-vJxK7n0D.js} +2 -2
  16. package/dist/chunks/{format-detection-BEdmtvsy.js → format-detection-C80TLQ2e.js} +1 -1
  17. package/dist/chunks/{index-CD0_RJv-.js → index-2xkq7wyD.js} +11482 -10971
  18. package/dist/chunks/optionsFromZod-BuTOFgVM.js +2572 -0
  19. package/dist/chunks/paletteRegistry-A63C71Gn.js +1155 -0
  20. package/dist/chunks/{registry-CSba5QGJ.js → registry-jB46Gmeb.js} +1 -1
  21. package/dist/chunks/scales-B2d-7Bf0.js +3220 -0
  22. package/dist/chunks/{types-B7bX5c0K.js → types-C_c53VgR.js} +31 -26
  23. package/dist/commands.d.ts +4 -0
  24. package/dist/custom-elements.json +1 -1
  25. package/dist/extend.js +45 -45
  26. package/dist/graphty-catalog.json +245 -12
  27. package/dist/graphty.bundle.js +40762 -39403
  28. package/dist/graphty.js +33 -33
  29. package/dist/logging.js +2 -2
  30. package/dist/schema.d.ts +1 -1
  31. package/dist/schema.js +42 -40
  32. package/dist/session.d.ts +1 -1
  33. package/dist/session.js +29 -30
  34. package/dist/src/Graph.d.ts +112 -10
  35. package/dist/src/acceleration/AccelerationController.d.ts +14 -3
  36. package/dist/src/acceleration/types.d.ts +78 -0
  37. package/dist/src/algorithms/KCoreAlgorithm.d.ts +26 -0
  38. package/dist/src/algorithms/LinkPredictionAlgorithm.d.ts +41 -0
  39. package/dist/src/camera/builtins.d.ts +14 -1
  40. package/dist/src/camera/types.d.ts +7 -0
  41. package/dist/src/cameras/CameraManager.d.ts +13 -0
  42. package/dist/src/cameras/OrbitCameraController.d.ts +9 -0
  43. package/dist/src/catalog/algorithms.d.ts +5 -5
  44. package/dist/src/catalog/index.d.ts +2 -2
  45. package/dist/src/catalog/layouts.d.ts +7 -6
  46. package/dist/src/catalog/types.d.ts +87 -6
  47. package/dist/src/config/EdgeStyle.d.ts +35 -0
  48. package/dist/src/config/GraphStyle.d.ts +5 -1
  49. package/dist/src/config/StyleTemplate.d.ts +2 -2
  50. package/dist/src/config/index.d.ts +1 -1
  51. package/dist/src/data/GEXFDataSource.d.ts +23 -0
  52. package/dist/src/errors/codes.d.ts +14 -0
  53. package/dist/src/events.d.ts +30 -0
  54. package/dist/src/graphty-element.d.ts +77 -32
  55. package/dist/src/layout/GridLayoutEngine.d.ts +37 -0
  56. package/dist/src/layout/LayoutEngine.d.ts +7 -7
  57. package/dist/src/layout/NGraphLayoutEngine.d.ts +2 -0
  58. package/dist/src/layout/RadialLayoutEngine.d.ts +37 -0
  59. package/dist/src/layout/SimulationLayoutEngine.d.ts +12 -0
  60. package/dist/src/managers/DataManager.d.ts +69 -2
  61. package/dist/src/managers/EventManager.d.ts +10 -4
  62. package/dist/src/managers/GraphContext.d.ts +2 -1
  63. package/dist/src/managers/LayoutManager.d.ts +30 -3
  64. package/dist/src/managers/StylePainter.d.ts +9 -0
  65. package/dist/src/managers/UpdateManager.d.ts +5 -0
  66. package/dist/src/meshes/MeshCache.d.ts +18 -0
  67. package/dist/src/meshes/NodeEffects.d.ts +16 -11
  68. package/dist/src/meshes/NodeMesh.d.ts +2 -2
  69. package/dist/src/meshes/RichTextParser.d.ts +26 -0
  70. package/dist/src/meshes/RichTextRenderer.d.ts +0 -1
  71. package/dist/src/session/cost/estimate.d.ts +1 -1
  72. package/dist/src/session/layout.d.ts +3 -3
  73. package/dist/src/session/results/index.d.ts +1 -1
  74. package/dist/src/session/results/statistics.d.ts +8 -1
  75. package/dist/src/session/results/types.d.ts +33 -0
  76. package/dist/src/session/runs/RunsApi.d.ts +1 -1
  77. package/dist/src/session/selection/targets.d.ts +4 -1
  78. package/dist/src/session/styles/StylesApi.d.ts +6 -0
  79. package/dist/src/session/styles/intern.d.ts +26 -5
  80. package/dist/src/session/styles/predicate.d.ts +26 -1
  81. package/dist/src/session/styles/repaint.d.ts +13 -1
  82. package/dist/src/session/styles/selector.d.ts +13 -1
  83. package/dist/src/session/styles/sources.d.ts +9 -0
  84. package/dist/src/session/types.d.ts +6 -6
  85. package/dist/webgpu.js +2 -2
  86. package/package.json +6 -6
  87. package/dist/chunks/Algorithm-RQ629NLb.js +0 -494
  88. package/dist/chunks/cameras-ii4vngYY.js +0 -435
  89. package/dist/chunks/paletteRegistry-DnWHQsAD.js +0 -3166
  90. package/dist/chunks/scales-DyuwlJKI.js +0 -6087
@@ -0,0 +1,1155 @@
1
+ import { q as b, G as F } from "./GraphtyLogger-CqOVV13Y.js";
2
+ import { a as T, b as D, d as k } from "./types-C_c53VgR.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-B93WRH3e.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
+ "grid",
457
+ "kamada-kawai",
458
+ "multipartite",
459
+ "ngraph",
460
+ "planar",
461
+ "radial",
462
+ "random",
463
+ "shell",
464
+ "spectral",
465
+ "spiral",
466
+ "spring",
467
+ "spring-electrical"
468
+ ]), W = F.getLogger(["graphty", "layout"]), P = 1e-6;
469
+ function G(i, t) {
470
+ return JSON.stringify([i, t]);
471
+ }
472
+ const U = 10;
473
+ function A(i) {
474
+ return new g({
475
+ code: "E_DUPLICATE_PLUGIN",
476
+ 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`,
477
+ source: "registry",
478
+ details: { kind: "layout", name: i, builtIn: !0 }
479
+ });
480
+ }
481
+ const E = class E {
482
+ constructor() {
483
+ this.positionArrayAttached = !1;
484
+ }
485
+ /**
486
+ * Add multiple nodes to the layout engine
487
+ * @param nodes - Array of nodes to add
488
+ */
489
+ addNodes(t) {
490
+ for (const e of t)
491
+ this.addNode(e);
492
+ }
493
+ /**
494
+ * Add multiple edges to the layout engine
495
+ * @param edges - Array of edges to add
496
+ */
497
+ addEdges(t) {
498
+ for (const e of t)
499
+ this.addEdge(e);
500
+ }
501
+ /**
502
+ * Take a node out of the layout, before the element disposes the mesh that drew it.
503
+ *
504
+ * Declared here, with a default that does nothing, because it used to be duck-typed by the
505
+ * element's data manager and implemented by none of the nineteen engines that ship here: an
506
+ * author learned it existed by reading the element's source, and got no worked example. An
507
+ * engine that keeps its own node list must override this, or it holds every removed node --
508
+ * and everything that node references -- for as long as the engine lives.
509
+ * @param _n - the node leaving the graph
510
+ */
511
+ removeNode(t) {
512
+ }
513
+ /**
514
+ * The edge half of {@link LayoutEngine.removeNode}, with the same default and the same reason.
515
+ * @param _e - the edge leaving the graph
516
+ */
517
+ removeEdge(t) {
518
+ }
519
+ /**
520
+ * Settle nodes that reached the graph after this layout was already running.
521
+ *
522
+ * THE DEFAULT IS THE ELEMENT'S OWN FALLBACK -- up to ten steps, stopping early if the engine
523
+ * settles -- so a simulation behaves exactly as it did before the hook was declared, and an
524
+ * engine that can place a newcomer without re-running the whole simulation overrides it. It
525
+ * lives on the base class rather than in the manager because the manager cannot tell "did not
526
+ * implement it" from "implemented it as a deliberate no-op", and the difference decides
527
+ * whether ten steps run.
528
+ * @param _nodes - the nodes that have just arrived
529
+ */
530
+ updatePositions(t) {
531
+ for (let e = 0; e < U; e++) {
532
+ if (this.isSettled)
533
+ return;
534
+ this.step();
535
+ }
536
+ }
537
+ /**
538
+ * Release whatever this engine holds. The element calls it when the reader switches layouts
539
+ * and when the graph is torn down, and never uses the engine again afterwards.
540
+ *
541
+ * Declared with a do-nothing default for the same reason as {@link LayoutEngine.removeNode}:
542
+ * it was duck-typed, undeclared and unimplemented by every engine here.
543
+ */
544
+ dispose() {
545
+ }
546
+ /**
547
+ * The array this engine publishes node coordinates into.
548
+ *
549
+ * Allocated on demand, so reading it is enough to make an engine that has never been handed an
550
+ * element's array produce one of its own.
551
+ * @returns the position array in use
552
+ */
553
+ get nodePositions() {
554
+ return this.positionArray ??= new x(0), this.positionArray;
555
+ }
556
+ /**
557
+ * Hand this engine the array it must publish into, and stop it adopting any other.
558
+ *
559
+ * This is how a host says "these coordinates are mine": the engine writes into the array the
560
+ * host already lends to its snapshots, so a layout, a drag and a GPU readback all land in the
561
+ * one place and a re-freeze loses none of them.
562
+ * @param positions - the element-owned array
563
+ */
564
+ attachPositions(t) {
565
+ this.positionArray = t, this.positionArrayAttached = !0;
566
+ }
567
+ /**
568
+ * Copy every node's current coordinates out of the engine and into the position array.
569
+ *
570
+ * Engines call this at the end of a step, so that by the time anything draws, the array is the
571
+ * answer rather than a copy of it. The default walks the engine's own nodes through
572
+ * {@link LayoutEngine.getNodePosition}, which is correct for any engine but allocates one
573
+ * object per node; an engine that can read its own state without allocating overrides it, and
574
+ * an engine that already writes straight into the array overrides it to do nothing.
575
+ */
576
+ publishPositions() {
577
+ for (const t of this.nodes) {
578
+ const e = this.getNodePosition(t);
579
+ this.writeNodePosition(t, e.x, e.y, e.z ?? 0);
580
+ }
581
+ }
582
+ /**
583
+ * Read a node's published coordinates into an object the CALLER owns.
584
+ *
585
+ * The point of the out parameter is that a renderer can pass the vector it is about to draw
586
+ * with and allocate nothing per node per frame. A row that no engine has placed answers false
587
+ * and leaves `out` untouched, so the caller keeps whatever it had rather than being handed a
588
+ * NaN or an origin it cannot tell from a real coordinate.
589
+ * @param n - the node to read
590
+ * @param out - the object to fill; a Babylon `Vector3` is one, which is the point
591
+ * @param out.x - receives the scene-unit x
592
+ * @param out.y - receives the scene-unit y
593
+ * @param out.z - receives the scene-unit z
594
+ * @returns true when the node has a placed row
595
+ */
596
+ readNodePosition(t, e) {
597
+ const s = this.positionsFor(t);
598
+ return s.isPlaced(t.index) ? (s.read(t.index, e), !0) : !1;
599
+ }
600
+ /**
601
+ * Publish one node's coordinates, growing the array to reach its row.
602
+ *
603
+ * Three things are silently skipped rather than thrown, because this runs inside a layout step
604
+ * and a throw there kills the frame: a node with no row in the graph (`INVALID_INDEX`, which a
605
+ * record whose id the graph builder would not take carries for its whole life), a node whose
606
+ * index is not a row number at all, and a coordinate that cannot be stored. That last one is
607
+ * the important one -- a force layout that divided by a zero distance produces NaN, and an
608
+ * overflow of the f32 the array stores produces an infinity. Either one, written, would make
609
+ * the row read back as a place: the mesh vanishes and the scene bounds and camera framing go
610
+ * with it. Left alone, the row stays unplaced and the node keeps the coordinates it had.
611
+ *
612
+ * The array is GROWN to reach the row rather than the write being refused. A node's index is
613
+ * handed out the moment its record is taken, but its row only appears when the graph is next
614
+ * frozen, and a layout that ran in between would otherwise be thrown away in silence. Growth is
615
+ * prefix-stable and fills what it adds with NaN, so it cannot disturb a row anything else
616
+ * placed; the one thing it does change is that a node this engine placed before the first
617
+ * freeze counts as placed, which is what makes a file's own coordinates yield to it.
618
+ *
619
+ * A PINNED ROW REFUSES A LAYOUT STEP. This is the whole of "a pin is meaningful under every
620
+ * arrangement": fourteen of the element's nineteen engines implement `pin()` as a no-op and
621
+ * `setNodePosition` as a no-op too, so before this guard a reader who dragged a node under a
622
+ * static layout watched it snap back the next time the layout recomputed. One refusal here
623
+ * covers every engine, including one written by a third party that has never heard of pinning,
624
+ * because every engine reaches the shared array through this method.
625
+ *
626
+ * A DRAG IS NOT A LAYOUT STEP. `intent: "placement"` writes straight through, so a reader can
627
+ * move a pinned node and have it stay where they put it; without that distinction the guard
628
+ * would make a pinned node undraggable, which is the opposite of what a pin is for. The
629
+ * default is `"layout"` so that an engine written before the parameter existed -- a plugin's
630
+ * step loop -- is guarded without knowing it, and only the placement paths have to opt out.
631
+ * @param n - the node being placed
632
+ * @param x - scene-unit x
633
+ * @param y - scene-unit y
634
+ * @param z - scene-unit z
635
+ * @param intent - `"layout"` for a simulation step, `"placement"` for a drag or a replay
636
+ * @returns true when the row was written
637
+ */
638
+ writeNodePosition(t, e, s, r, n = "layout") {
639
+ const { index: a } = t;
640
+ if (a === N || !Number.isInteger(a) || a < 0 || !d(e) || !d(s) || !d(r))
641
+ return !1;
642
+ const c = this.positionsFor(t);
643
+ return n === "layout" && c.isPinned(a) ? !1 : (a >= c.count && c.grow(a + 1), c.write(a, e, s, r), !0);
644
+ }
645
+ /**
646
+ * The weight of every ordered endpoint pair this batch of edges covers, or null when the
647
+ * graph's weights carry no information.
648
+ *
649
+ * WHY A PAIR AND NOT AN EDGE. `@graphty/layout`'s one weight channel is
650
+ * `graph.getEdgeData(source, target, attr)`, which is asked by endpoint pair, and both layout
651
+ * functions that read it write the answer into a matrix cell -- `A[i][j]` in ForceAtlas2,
652
+ * `distances[s][t]` in Kamada-Kawai. There is no cell for a second edge between the same two
653
+ * nodes, so parallel edges are SUMMED into one number rather than left to last-writer-wins,
654
+ * where the order the file happened to list them in would decide the arrangement. Summing is
655
+ * also what the element does when it simplifies a multigraph for an algorithm, so a graph's
656
+ * weights mean the same thing to a layout and to a metric.
657
+ *
658
+ * READ ONCE PER LAYOUT COMPUTATION, not per frame and not per edge: the weights come from the
659
+ * current snapshot's edge list, indexed by the same logical edge index `Edge.index` holds.
660
+ *
661
+ * NULL MEANS "DO NOT ATTACH A CALLBACK". graph-format stores an all-ones graph with no weight
662
+ * column at all, and a graph whose every weight is 1 carries no information a layout could
663
+ * arrange by -- so the caller leaves `getEdgeData` off the graph object entirely and the
664
+ * arrangement is bit-identical to the one the same seed produced before weights existed.
665
+ *
666
+ * THIS IS A SLIGHTLY NARROWER QUESTION THAN `statistics().weighted`, deliberately. The status
667
+ * chip asks whether the SNAPSHOT's weight column carries anything but ones; this asks it of
668
+ * the edges this engine is actually about to arrange. They answer differently only when the
669
+ * engine holds a strict subset of the graph's edges whose weights are all 1, and there the
670
+ * narrower answer is the correct one: a layout cannot be moved by a weight on an edge it is
671
+ * not laying out. A consumer who sees "weighted" on the status bar and an unmoved arrangement
672
+ * is looking at that case.
673
+ * @param edges - the edges this engine is about to lay out
674
+ * @returns pair key (see {@link pairWeightKey}) to summed weight, or null
675
+ */
676
+ pairWeights(t) {
677
+ if (t.length === 0)
678
+ return null;
679
+ const s = t[0].parentGraph?.getDataManager?.()?.getSnapshot?.()?.edgeList().weights ?? null;
680
+ if (s === null)
681
+ return null;
682
+ const r = /* @__PURE__ */ new Map();
683
+ let n = !1;
684
+ for (const a of t) {
685
+ const c = a.index >= 0 && a.index < s.length ? s[a.index] : 1;
686
+ c !== 1 && (n = !0);
687
+ const I = G(a.srcId, a.dstId);
688
+ r.set(I, (r.get(I) ?? 0) + c);
689
+ }
690
+ return n ? r : null;
691
+ }
692
+ /**
693
+ * Say once, per layout computation, how many pairs were clamped off zero.
694
+ *
695
+ * ONCE PER RUN AND NOT PER EDGE: a graph whose weights are all zero would otherwise produce
696
+ * one line per edge, which buries every other message in the run it happened during. It is
697
+ * reported at all because a clamp changes the picture -- a zero-weight edge is drawn as the
698
+ * weakest connection the solver can express rather than as no connection -- and the record
699
+ * that carried the zero is the reader's, not the element's, so they are the one who can fix
700
+ * it.
701
+ * @param layout - the layout name, for the message
702
+ * @param weights - the pair weights about to be handed to the layout function
703
+ */
704
+ reportClampedWeights(t, e) {
705
+ let s = 0;
706
+ for (const r of e.values())
707
+ r < P && s++;
708
+ s > 0 && W.warn("Edge weights at or below zero were clamped before the layout read them", {
709
+ layout: t,
710
+ clamped: s,
711
+ epsilon: P
712
+ });
713
+ }
714
+ /**
715
+ * The array to use for this node: the one its own graph owns, unless a host attached one.
716
+ *
717
+ * Resolved on every call rather than cached, because the element REPLACES its array when a
718
+ * dataset is discarded -- the store and everything keyed into it is thrown away and rebuilt --
719
+ * and an engine outlives that. A cached reference would keep publishing into the array of a
720
+ * graph that no longer exists, which is invisible: every write succeeds and nothing draws.
721
+ * @param n - the node being published or read
722
+ * @returns the array to write to and read from
723
+ */
724
+ positionsFor(t) {
725
+ if (!this.positionArrayAttached) {
726
+ const e = t.parentGraph?.getDataManager?.()?.positions;
727
+ e instanceof x && (this.positionArray = e);
728
+ }
729
+ return this.nodePositions;
730
+ }
731
+ /**
732
+ * Get the type identifier for this layout engine
733
+ * @returns The layout engine type string
734
+ */
735
+ get type() {
736
+ return this.constructor.type;
737
+ }
738
+ /**
739
+ * File a layout engine class under the name it declares, and publish what it says about
740
+ * itself to the catalogue.
741
+ *
742
+ * WHAT CHANGED AND WHY. This used to read `cls.type` through a cast and put the class in a
743
+ * map, which meant a class with no `static type` registered under the string "undefined", a
744
+ * second class under a taken name silently replaced the first, and a registered engine
745
+ * reached no catalogue at all -- so a third party's layout could run but could never be
746
+ * offered by a picker, described in a reader's language, or found by `layoutIdForEngine`.
747
+ *
748
+ * A third party's class must declare a `static descriptor` whose `id` equals its
749
+ * `static type`. The element's own nineteen are the one exemption, because their arrangements
750
+ * are authored centrally in the layout catalogue where several engines may sit behind one
751
+ * public name.
752
+ * @param cls - The layout engine class.
753
+ * @returns The same class, so a declaration can register itself in one expression.
754
+ * @throws A `GraphtyError` with `E_BAD_COMMAND` when the class declares no `static type`, no
755
+ * `static descriptor`, or a descriptor whose `id` disagrees with its `static type`; or with
756
+ * `E_DUPLICATE_PLUGIN` when the name or the descriptor id is one the element itself ships.
757
+ */
758
+ static register(t) {
759
+ const e = t, { type: s, descriptor: r } = e;
760
+ if (typeof s != "string" || s === "")
761
+ throw new g({
762
+ code: "E_BAD_COMMAND",
763
+ message: "a layout engine is filed under its `static type`, and this class declares none",
764
+ source: "registry",
765
+ details: { kind: "layout", field: "type" }
766
+ });
767
+ if (l.get(s) === t)
768
+ return t;
769
+ const n = C.includes(s);
770
+ if (r === void 0) {
771
+ if (!n)
772
+ throw new g({
773
+ code: "E_BAD_COMMAND",
774
+ 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`,
775
+ source: "registry",
776
+ details: { kind: "layout", name: s, field: "descriptor" }
777
+ });
778
+ if (l.has(s))
779
+ throw A(s);
780
+ return l.set(s, t), t;
781
+ }
782
+ if (n)
783
+ throw A(s);
784
+ if (r.id !== s)
785
+ throw new g({
786
+ code: "E_BAD_COMMAND",
787
+ 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`,
788
+ source: "registry",
789
+ details: { kind: "layout", name: s, field: "descriptor.id", id: r.id }
790
+ });
791
+ return z({
792
+ descriptor: { ...r, honoursWeights: e.honoursWeights ?? !1 },
793
+ type: s
794
+ }), l.set(s, t), t;
795
+ }
796
+ /**
797
+ * Get a layout engine instance by type
798
+ * @param type - The layout engine type identifier
799
+ * @param opts - Configuration options for the layout engine
800
+ * @returns A new layout engine instance or null if type not found
801
+ */
802
+ static get(t, e = {}) {
803
+ const s = l.get(t);
804
+ return s ? new s(e) : null;
805
+ }
806
+ /**
807
+ * Get dimension-specific options for this layout
808
+ * @param dimension - The desired dimension (2 or 3)
809
+ * @returns Options object for the dimension or null if unsupported
810
+ */
811
+ static getOptionsForDimension(t) {
812
+ return t > this.maxDimensions ? null : {};
813
+ }
814
+ /**
815
+ * Get dimension-specific options for a layout by type
816
+ * @param type - The layout engine type identifier
817
+ * @param dimension - The desired dimension (2 or 3)
818
+ * @returns Options object for the dimension or null if type not found or unsupported
819
+ */
820
+ static getOptionsForDimensionByType(t, e) {
821
+ const s = l.get(t);
822
+ return s ? s.getOptionsForDimension(e) : null;
823
+ }
824
+ /**
825
+ * Get the Zod-based options schema for this layout
826
+ * @returns The options schema, or an empty object if no schema defined
827
+ */
828
+ static getZodOptionsSchema() {
829
+ return this.zodOptionsSchema ?? {};
830
+ }
831
+ /**
832
+ * Check if this layout has a Zod-based options schema
833
+ * @returns true if the layout has options defined
834
+ */
835
+ static hasZodOptions() {
836
+ return this.zodOptionsSchema !== void 0 && Object.keys(this.zodOptionsSchema).length > 0;
837
+ }
838
+ /**
839
+ * Get a list of all registered layout types
840
+ * @returns Array of registered layout type identifiers
841
+ */
842
+ static getRegisteredTypes() {
843
+ return Array.from(l.keys());
844
+ }
845
+ /**
846
+ * Get a layout class by type
847
+ * @param type - The layout engine type identifier
848
+ * @returns The layout engine class or null if not found
849
+ */
850
+ static getClass(t) {
851
+ return l.get(t) ?? null;
852
+ }
853
+ };
854
+ E.honoursWeights = !1;
855
+ let w = E;
856
+ const V = O.looseObject({
857
+ scalingFactor: O.number().default(100)
858
+ });
859
+ class dt extends w {
860
+ /**
861
+ * Create a simple layout engine
862
+ * @param opts - Configuration options including scalingFactor
863
+ */
864
+ constructor(t = {}) {
865
+ super(), this._nodes = [], this._edges = [], this.stale = !0, this.positions = {}, this.scalingFactor = 100, this.isSettled = !0;
866
+ const e = V.parse(t);
867
+ this.scalingFactor = e.scalingFactor;
868
+ }
869
+ /**
870
+ * Get dimension-specific options for simple layouts
871
+ * @param dimension - The desired dimension (2 or 3)
872
+ * @returns Options object with dim parameter or null if unsupported
873
+ */
874
+ static getOptionsForDimension(t) {
875
+ return t > this.maxDimensions ? null : { dim: t };
876
+ }
877
+ // basic functionality
878
+ /**
879
+ * Initialize the layout engine
880
+ *
881
+ * Simple layouts compute positions synchronously and don't require initialization.
882
+ */
883
+ async init() {
884
+ }
885
+ /**
886
+ * Add a node to the layout and mark positions as stale
887
+ * @param n - The node to add
888
+ */
889
+ addNode(t) {
890
+ this._nodes.push(t), this.stale = !0;
891
+ }
892
+ /**
893
+ * Add an edge to the layout and mark positions as stale
894
+ * @param e - The edge to add
895
+ */
896
+ addEdge(t) {
897
+ this._edges.push(t), this.stale = !0;
898
+ }
899
+ /**
900
+ * Get the position of a node, computing layout if stale
901
+ *
902
+ * The coordinates come from the shared position array, which `SimpleLayoutEngine.refresh`
903
+ * fills from `positions` as soon as the layout is recomputed. They are the same numbers the
904
+ * record holds, rounded to the f32 the array stores -- so an arrangement never moves, but a
905
+ * coordinate may differ in its last digit or two from the double the layout function returned.
906
+ * A node with no row falls back to the record, which is every node in an engine driven by hand.
907
+ * @param n - The node to get position for
908
+ * @returns The node's position coordinates
909
+ */
910
+ getNodePosition(t) {
911
+ return this.refresh(), this.publishedOr(t, t.id);
912
+ }
913
+ /**
914
+ * Record where the reader has just put a node.
915
+ *
916
+ * A static layout recomputes every coordinate from scratch, so it has no per-node state a
917
+ * placement could live in -- which is why this used to do nothing at all, and why a drag
918
+ * under any of the fourteen static arrangements was discarded by the next `refresh()`. The
919
+ * placement is written into the SHARED array instead, with `"placement"` intent so that it
920
+ * lands even on a pinned row, and into the computed record so that a read which falls back to
921
+ * the record (a node with no row of its own) answers the same.
922
+ * @param n - the node that moved
923
+ * @param p - where it moved to
924
+ */
925
+ setNodePosition(t, e) {
926
+ const s = e.z ?? 0;
927
+ this.writeNodePosition(t, e.x, e.y, s, "placement"), this.positions[t.id] = [e.x / this.scalingFactor, e.y / this.scalingFactor, s / this.scalingFactor];
928
+ }
929
+ /**
930
+ * Get the position of an edge based on its endpoints
931
+ * @param e - The edge to get position for
932
+ * @returns The edge's source and destination positions
933
+ */
934
+ getEdgePosition(t) {
935
+ return this.refresh(), {
936
+ src: this.publishedOr(t.srcNode, t.srcId),
937
+ dst: this.publishedOr(t.dstNode, t.dstId)
938
+ };
939
+ }
940
+ /**
941
+ * Copy the computed layout into the shared position array, recomputing it first if it is stale.
942
+ */
943
+ publishPositions() {
944
+ if (this.stale) {
945
+ this.refresh();
946
+ return;
947
+ }
948
+ this.publishRecord();
949
+ }
950
+ // for animated layouts
951
+ /**
952
+ * Step the layout animation
953
+ *
954
+ * Simple layouts are static and don't animate, so stepping has no effect.
955
+ */
956
+ step() {
957
+ }
958
+ /**
959
+ * Take a node out of the layout.
960
+ *
961
+ * WITHOUT THIS the engine holds the removed node -- and through it the node's Babylon mesh,
962
+ * its data record and its endpoints -- for as long as the engine lives, and the frame loop
963
+ * keeps walking it, so a node the reader deleted still draws at wherever it last was.
964
+ *
965
+ * The computed record is left alone and the layout is marked stale instead. Every layout
966
+ * function here returns a WHOLE new record, which `doLayout` assigns over the old one, and
967
+ * `refresh()` runs before any read -- so the removed node's entry is gone by the time anything
968
+ * could read it, without this method having to reach into a keyed object by a computed name.
969
+ * @param n - the node leaving the graph
970
+ */
971
+ removeNode(t) {
972
+ const e = this._nodes.indexOf(t);
973
+ e >= 0 && this._nodes.splice(e, 1), this.stale = !0;
974
+ }
975
+ /**
976
+ * The edge half of {@link SimpleLayoutEngine.removeNode}, with the same reason.
977
+ * @param e - the edge leaving the graph
978
+ */
979
+ removeEdge(t) {
980
+ const e = this._edges.indexOf(t);
981
+ e >= 0 && this._edges.splice(e, 1), this.stale = !0;
982
+ }
983
+ /**
984
+ * Pin a node in place
985
+ *
986
+ * A static layout has nothing of its own to hold still -- it recomputes every position from
987
+ * scratch -- so the pin is kept by the element's position array instead, and
988
+ * `writeNodePosition` refuses to move a pinned row. That is what makes a
989
+ * pin mean something under all fourteen of these engines, none of which could hold one.
990
+ */
991
+ pin() {
992
+ }
993
+ /**
994
+ * Unpin a node
995
+ *
996
+ * The element's position array holds the pin; see {@link SimpleLayoutEngine.pin}.
997
+ */
998
+ unpin() {
999
+ }
1000
+ // properties
1001
+ /**
1002
+ * Get all nodes in the layout
1003
+ * @returns Iterable of nodes
1004
+ */
1005
+ get nodes() {
1006
+ return this._nodes;
1007
+ }
1008
+ /**
1009
+ * Get all edges in the layout
1010
+ * @returns Iterable of edges
1011
+ */
1012
+ get edges() {
1013
+ return this._edges;
1014
+ }
1015
+ /**
1016
+ * Recompute the layout when it is stale, and publish what it produced.
1017
+ *
1018
+ * A simple layout is computed once and then held, so this is the ONE place the shared array is
1019
+ * filled: every reader below goes through here first, which is why a node added after the last
1020
+ * read still gets a row before anything asks for its coordinates.
1021
+ */
1022
+ refresh() {
1023
+ this.stale && (this.doLayout(), this.stale = !1, this.publishRecord());
1024
+ }
1025
+ /**
1026
+ * Write the computed record into the shared array, scaled to scene units.
1027
+ *
1028
+ * A node the layout function returned nothing for is LEFT UNPLACED rather than published at
1029
+ * the origin: the two are indistinguishable once stored, and the origin is a place a reader
1030
+ * would draw at.
1031
+ */
1032
+ publishRecord() {
1033
+ for (const t of this._nodes) {
1034
+ const e = this.positions[t.id];
1035
+ !e || e.length === 0 || this.writeNodePosition(
1036
+ t,
1037
+ e[0] * this.scalingFactor,
1038
+ e[1] * this.scalingFactor,
1039
+ (e[2] ?? 0) * this.scalingFactor
1040
+ );
1041
+ }
1042
+ }
1043
+ /**
1044
+ * A node's published row, or the computed record when it has no row of its own.
1045
+ *
1046
+ * The fallback is not a rare path: an engine driven directly -- by a test, or by a host that
1047
+ * keeps no graph -- has nodes whose index is `INVALID_INDEX`, and none of them is ever
1048
+ * published. Both branches produce the same arrangement; only the rounding differs.
1049
+ * @param n - the node, when the caller has one
1050
+ * @param id - the node's id, which is how the computed record is keyed
1051
+ * @returns a fresh coordinate triple
1052
+ */
1053
+ publishedOr(t, e) {
1054
+ const s = { x: 0, y: 0, z: 0 };
1055
+ return t !== void 0 && this.readNodePosition(t, s) ? s : X(this.positions[e], this.scalingFactor);
1056
+ }
1057
+ }
1058
+ function X(i, t) {
1059
+ if (!i || i.length === 0)
1060
+ return { x: 0, y: 0, z: 0 };
1061
+ const e = i[0] * t, s = i[1] * t, r = (i[2] ?? 0) * t;
1062
+ return { x: e, y: s, z: r };
1063
+ }
1064
+ const K = /^#[0-9a-f]{6}$/i;
1065
+ function q(i) {
1066
+ if (typeof i != "string" || i.trim() === "")
1067
+ return null;
1068
+ try {
1069
+ const t = v(i.trim());
1070
+ if (t === void 0)
1071
+ return null;
1072
+ const e = t.length === 9 ? t.slice(0, 7) : t;
1073
+ return K.test(e) ? e.toUpperCase() : null;
1074
+ } catch {
1075
+ return null;
1076
+ }
1077
+ }
1078
+ function H(i) {
1079
+ return JSON.stringify([i.id, i.kind, i.colors, i.capacity, i.colorblindSafe]);
1080
+ }
1081
+ const y = b({
1082
+ kind: "palette",
1083
+ idOf: (i) => i.id,
1084
+ descriptorOf: (i) => i,
1085
+ implementationOf: H,
1086
+ builtInIds: () => k
1087
+ });
1088
+ function u(i, t, e) {
1089
+ throw new g({
1090
+ code: "E_BAD_COMMAND",
1091
+ message: e,
1092
+ source: "registry",
1093
+ details: { kind: "palette", name: typeof i == "string" ? i : "", field: t }
1094
+ });
1095
+ }
1096
+ function ut(i, t) {
1097
+ 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(
1098
+ i.id,
1099
+ "kind",
1100
+ `the palette "${String(i.id)}" must be sequential, diverging or categorical`
1101
+ ), (!Array.isArray(i.colors) || i.colors.length === 0) && u(i.id, "colors", `the palette "${String(i.id)}" was registered with no colours`);
1102
+ const e = [];
1103
+ for (const r of i.colors) {
1104
+ const n = q(r);
1105
+ n === null && u(i.id, "colors", `"${String(r)}" in the palette "${String(i.id)}" is not a colour`), e.push(n);
1106
+ }
1107
+ const s = i.kind === "categorical" ? e.length : null;
1108
+ i.capacity !== void 0 && i.capacity !== s && u(
1109
+ i.id,
1110
+ "capacity",
1111
+ `the palette "${String(i.id)}" is ${i.kind}, so its capacity is ${s === null ? "null" : String(s)} rather than ${String(i.capacity)}`
1112
+ ), y.register(
1113
+ Object.freeze({
1114
+ ...i,
1115
+ colors: Object.freeze(e),
1116
+ capacity: s,
1117
+ colorblindSafe: Object.freeze(i.colorblindSafe ?? [])
1118
+ }),
1119
+ t
1120
+ );
1121
+ }
1122
+ function pt() {
1123
+ return y.descriptors();
1124
+ }
1125
+ function gt(i) {
1126
+ return y.byId(i);
1127
+ }
1128
+ function ft() {
1129
+ y.clearForTesting();
1130
+ }
1131
+ export {
1132
+ x as E,
1133
+ _ as F,
1134
+ w as L,
1135
+ o as P,
1136
+ V as S,
1137
+ nt as U,
1138
+ P as W,
1139
+ dt as a,
1140
+ ht as b,
1141
+ rt as c,
1142
+ ft as d,
1143
+ L as e,
1144
+ lt as f,
1145
+ pt as g,
1146
+ st as h,
1147
+ ot as i,
1148
+ at as j,
1149
+ G as k,
1150
+ ct as l,
1151
+ gt as m,
1152
+ d as n,
1153
+ it as p,
1154
+ ut as r
1155
+ };