kaabalah 6.8.0 → 6.9.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 (145) hide show
  1. package/dist/astrology/index.d.mts +8 -2
  2. package/dist/astrology/index.d.ts +8 -2
  3. package/dist/astrology/index.js +56 -52
  4. package/dist/astrology/index.mjs +1 -1
  5. package/dist/{chunk-WLML6SVX.js → chunk-3C235FNN.js} +23 -10
  6. package/dist/chunk-3C235FNN.js.map +1 -0
  7. package/dist/{chunk-LQX6PW35.js → chunk-47BAJUYW.js} +70 -103
  8. package/dist/chunk-47BAJUYW.js.map +1 -0
  9. package/dist/{chunk-SHKAAZHT.mjs → chunk-7LIIEUJB.mjs} +67 -43
  10. package/dist/chunk-7LIIEUJB.mjs.map +1 -0
  11. package/dist/{chunk-SYLFUBAB.js → chunk-CW6QDSMF.js} +41 -34
  12. package/dist/chunk-CW6QDSMF.js.map +1 -0
  13. package/dist/{chunk-K33NFXSD.js → chunk-FCAIGKB5.js} +163 -139
  14. package/dist/chunk-FCAIGKB5.js.map +1 -0
  15. package/dist/{chunk-36XZ5WR2.js → chunk-M2FTEWY2.js} +991 -985
  16. package/dist/chunk-M2FTEWY2.js.map +1 -0
  17. package/dist/{chunk-5K4OQ4UB.mjs → chunk-NOZKIUGP.mjs} +60 -43
  18. package/dist/chunk-NOZKIUGP.mjs.map +1 -0
  19. package/dist/{chunk-QS5XAAAG.mjs → chunk-OSMB2MJR.mjs} +23 -16
  20. package/dist/chunk-OSMB2MJR.mjs.map +1 -0
  21. package/dist/{chunk-7YU7TRCG.mjs → chunk-PEHDLSUH.mjs} +11 -7
  22. package/dist/chunk-PEHDLSUH.mjs.map +1 -0
  23. package/dist/{chunk-VJ6RW5H4.js → chunk-Q7YAKPBH.js} +63 -42
  24. package/dist/chunk-Q7YAKPBH.js.map +1 -0
  25. package/dist/{chunk-3UJPBUY4.mjs → chunk-RAQDVWNK.mjs} +9 -12
  26. package/dist/chunk-RAQDVWNK.mjs.map +1 -0
  27. package/dist/{chunk-BEFGGHIJ.js → chunk-SWWLTDR6.js} +11 -6
  28. package/dist/chunk-SWWLTDR6.js.map +1 -0
  29. package/dist/{chunk-5HXSHALQ.mjs → chunk-THD4XOYR.mjs} +16 -4
  30. package/dist/chunk-THD4XOYR.mjs.map +1 -0
  31. package/dist/{chunk-UZ42PN5T.js → chunk-UNXDDLZS.js} +10 -13
  32. package/dist/chunk-UNXDDLZS.js.map +1 -0
  33. package/dist/{chunk-6N5YC2WD.mjs → chunk-X5HGLMEF.mjs} +20 -53
  34. package/dist/chunk-X5HGLMEF.mjs.map +1 -0
  35. package/dist/{chunk-ITESL6GR.mjs → chunk-Y3TLBFPD.mjs} +982 -976
  36. package/dist/chunk-Y3TLBFPD.mjs.map +1 -0
  37. package/dist/cli.js +8991 -6144
  38. package/dist/cli.js.map +1 -1
  39. package/dist/core/index.d.mts +3 -3
  40. package/dist/core/index.d.ts +3 -3
  41. package/dist/core/index.js +65 -49
  42. package/dist/core/index.mjs +2 -2
  43. package/dist/{correspondence-model-DWXbAjC-.d.mts → correspondence-model-JSyDWwmn.d.mts} +19 -1
  44. package/dist/{correspondence-model-DWXbAjC-.d.ts → correspondence-model-JSyDWwmn.d.ts} +19 -1
  45. package/dist/data-CdjlIcAo.d.mts +33 -0
  46. package/dist/data-_b06lgY6.d.ts +33 -0
  47. package/dist/gematria/index.d.mts +1 -1
  48. package/dist/gematria/index.d.ts +1 -1
  49. package/dist/gematria/index.js +5 -5
  50. package/dist/gematria/index.mjs +2 -2
  51. package/dist/index.d.mts +6 -5
  52. package/dist/index.d.ts +6 -5
  53. package/dist/index.js +228 -204
  54. package/dist/index.mjs +8 -8
  55. package/dist/numerology/index.d.mts +21 -0
  56. package/dist/numerology/index.d.ts +21 -0
  57. package/dist/numerology/index.js +18 -18
  58. package/dist/numerology/index.mjs +3 -3
  59. package/dist/semantic/index.d.mts +2 -2
  60. package/dist/semantic/index.d.ts +2 -2
  61. package/dist/semantic/index.js +26 -26
  62. package/dist/semantic/index.mjs +7 -7
  63. package/dist/{swisseph.node-2PWBQLWG.mjs → swisseph.node-53QCJWTI.mjs} +4 -3
  64. package/dist/swisseph.node-53QCJWTI.mjs.map +1 -0
  65. package/dist/{swisseph.node-NWM75JF3.js → swisseph.node-CGBZTQ5N.js} +4 -3
  66. package/dist/swisseph.node-CGBZTQ5N.js.map +1 -0
  67. package/dist/swisseph.node-GPVFDOB6.wasm +0 -0
  68. package/dist/swisseph.node.js +1 -1
  69. package/dist/swisseph.node.wasm +0 -0
  70. package/dist/swisseph.web-GPVFDOB6.wasm +0 -0
  71. package/dist/{wasm/build/swisseph.web-CK57WSU3.mjs → swisseph.web-SRINFOJC.mjs} +4 -3
  72. package/dist/swisseph.web-SRINFOJC.mjs.map +1 -0
  73. package/dist/{wasm/build/swisseph.web-GPTWPXKT.js → swisseph.web-XCF4GL2M.js} +4 -3
  74. package/dist/swisseph.web-XCF4GL2M.js.map +1 -0
  75. package/dist/swisseph.web.js +1 -1
  76. package/dist/swisseph.web.wasm +0 -0
  77. package/dist/tarot/index.d.mts +102 -126
  78. package/dist/tarot/index.d.ts +102 -126
  79. package/dist/tarot/index.js +23 -23
  80. package/dist/tarot/index.mjs +3 -3
  81. package/dist/{topology-CSSfYL2c.d.mts → topology-CH3hsIqO.d.mts} +2 -1
  82. package/dist/{topology-Bbgniegh.d.ts → topology-DXYTpDvj.d.ts} +2 -1
  83. package/dist/visual/index.d.mts +9 -3
  84. package/dist/visual/index.d.ts +9 -3
  85. package/dist/visual/index.js +48 -44
  86. package/dist/visual/index.mjs +3 -3
  87. package/dist/wasm/build/{swisseph.node-2PWBQLWG.mjs → swisseph.node-53QCJWTI.mjs} +4 -3
  88. package/dist/wasm/build/swisseph.node-53QCJWTI.mjs.map +1 -0
  89. package/dist/wasm/build/{swisseph.node-NWM75JF3.js → swisseph.node-CGBZTQ5N.js} +4 -3
  90. package/dist/wasm/build/swisseph.node-CGBZTQ5N.js.map +1 -0
  91. package/dist/wasm/build/swisseph.node-GPVFDOB6.wasm +0 -0
  92. package/dist/wasm/build/swisseph.node.js +1 -1
  93. package/dist/wasm/build/swisseph.node.wasm +0 -0
  94. package/dist/wasm/build/swisseph.web-GPVFDOB6.wasm +0 -0
  95. package/dist/{swisseph.web-CK57WSU3.mjs → wasm/build/swisseph.web-SRINFOJC.mjs} +4 -3
  96. package/dist/wasm/build/swisseph.web-SRINFOJC.mjs.map +1 -0
  97. package/dist/{swisseph.web-GPTWPXKT.js → wasm/build/swisseph.web-XCF4GL2M.js} +4 -3
  98. package/dist/wasm/build/swisseph.web-XCF4GL2M.js.map +1 -0
  99. package/dist/wasm/build/swisseph.web.js +1 -1
  100. package/dist/wasm/build/swisseph.web.wasm +0 -0
  101. package/package.json +2 -1
  102. package/wasm/build/swisseph.node.js +1 -1
  103. package/wasm/build/swisseph.node.wasm +0 -0
  104. package/wasm/build/swisseph.web.js +1 -1
  105. package/wasm/build/swisseph.web.wasm +0 -0
  106. package/dist/chunk-36XZ5WR2.js.map +0 -1
  107. package/dist/chunk-3UJPBUY4.mjs.map +0 -1
  108. package/dist/chunk-5HXSHALQ.mjs.map +0 -1
  109. package/dist/chunk-5K4OQ4UB.mjs.map +0 -1
  110. package/dist/chunk-6N5YC2WD.mjs.map +0 -1
  111. package/dist/chunk-7YU7TRCG.mjs.map +0 -1
  112. package/dist/chunk-BEFGGHIJ.js.map +0 -1
  113. package/dist/chunk-ITESL6GR.mjs.map +0 -1
  114. package/dist/chunk-K33NFXSD.js.map +0 -1
  115. package/dist/chunk-LQX6PW35.js.map +0 -1
  116. package/dist/chunk-QS5XAAAG.mjs.map +0 -1
  117. package/dist/chunk-SHKAAZHT.mjs.map +0 -1
  118. package/dist/chunk-SYLFUBAB.js.map +0 -1
  119. package/dist/chunk-UZ42PN5T.js.map +0 -1
  120. package/dist/chunk-VJ6RW5H4.js.map +0 -1
  121. package/dist/chunk-WLML6SVX.js.map +0 -1
  122. package/dist/swisseph-YPVN5VCI.wasm +0 -0
  123. package/dist/swisseph.js +0 -30
  124. package/dist/swisseph.node-2K5IHMKE.wasm +0 -0
  125. package/dist/swisseph.node-2PWBQLWG.mjs.map +0 -1
  126. package/dist/swisseph.node-NWM75JF3.js.map +0 -1
  127. package/dist/swisseph.wasm +0 -0
  128. package/dist/swisseph.web-2K5IHMKE.wasm +0 -0
  129. package/dist/swisseph.web-CK57WSU3.mjs.map +0 -1
  130. package/dist/swisseph.web-GPTWPXKT.js.map +0 -1
  131. package/dist/wasm/build/swisseph-YPVN5VCI.wasm +0 -0
  132. package/dist/wasm/build/swisseph.js +0 -30
  133. package/dist/wasm/build/swisseph.node-2K5IHMKE.wasm +0 -0
  134. package/dist/wasm/build/swisseph.node-2PWBQLWG.mjs.map +0 -1
  135. package/dist/wasm/build/swisseph.node-NWM75JF3.js.map +0 -1
  136. package/dist/wasm/build/swisseph.wasm +0 -0
  137. package/dist/wasm/build/swisseph.web-2K5IHMKE.wasm +0 -0
  138. package/dist/wasm/build/swisseph.web-CK57WSU3.mjs.map +0 -1
  139. package/dist/wasm/build/swisseph.web-GPTWPXKT.js.map +0 -1
  140. package/dist/webassembly.md +0 -127
  141. package/wasm/build/swisseph-YPVN5VCI.wasm +0 -0
  142. package/wasm/build/swisseph.d.ts +0 -12
  143. package/wasm/build/swisseph.js +0 -30
  144. package/wasm/build/swisseph.wasm +0 -0
  145. package/wasm/build/webassembly.md +0 -127
@@ -1,53 +1,54 @@
1
1
  'use strict';
2
2
 
3
- var chunkVJ6RW5H4_js = require('./chunk-VJ6RW5H4.js');
3
+ var chunkQ7YAKPBH_js = require('./chunk-Q7YAKPBH.js');
4
4
 
5
5
  // src/core/topology.ts
6
6
  var TREE_TOPOLOGY_SPHERE_NAMES = [
7
- chunkVJ6RW5H4_js.SPHERES.KETHER,
8
- chunkVJ6RW5H4_js.SPHERES.CHOKHMAH,
9
- chunkVJ6RW5H4_js.SPHERES.BINAH,
10
- chunkVJ6RW5H4_js.SPHERES.DAATH,
11
- chunkVJ6RW5H4_js.SPHERES.CHESED,
12
- chunkVJ6RW5H4_js.SPHERES.GEBURAH,
13
- chunkVJ6RW5H4_js.SPHERES.TIPHARETH,
14
- chunkVJ6RW5H4_js.SPHERES.NETZACH,
15
- chunkVJ6RW5H4_js.SPHERES.HOD,
16
- chunkVJ6RW5H4_js.SPHERES.YESOD,
17
- chunkVJ6RW5H4_js.SPHERES.MALKUTH
7
+ chunkQ7YAKPBH_js.SPHERES.KETHER,
8
+ chunkQ7YAKPBH_js.SPHERES.CHOKHMAH,
9
+ chunkQ7YAKPBH_js.SPHERES.BINAH,
10
+ chunkQ7YAKPBH_js.SPHERES.DAATH,
11
+ chunkQ7YAKPBH_js.SPHERES.CHESED,
12
+ chunkQ7YAKPBH_js.SPHERES.GEBURAH,
13
+ chunkQ7YAKPBH_js.SPHERES.TIPHARETH,
14
+ chunkQ7YAKPBH_js.SPHERES.NETZACH,
15
+ chunkQ7YAKPBH_js.SPHERES.HOD,
16
+ chunkQ7YAKPBH_js.SPHERES.YESOD,
17
+ chunkQ7YAKPBH_js.SPHERES.MALKUTH
18
18
  ];
19
19
  var TREE_TOPOLOGY_SPHERE_IDS = TREE_TOPOLOGY_SPHERE_NAMES.map(
20
- (name) => chunkVJ6RW5H4_js.id("sphere" /* SPHERE */, name)
20
+ (name) => chunkQ7YAKPBH_js.id("sphere" /* SPHERE */, name)
21
21
  );
22
22
  var TREE_TOPOLOGY_PATH_IDS = Array.from(
23
23
  { length: 22 },
24
- (_, index) => chunkVJ6RW5H4_js.id("path" /* PATH */, index + 1)
24
+ (_, index) => chunkQ7YAKPBH_js.id("path" /* PATH */, index + 1)
25
25
  );
26
26
  var TREE_TOPOLOGY_SPHERE_NUMBERS = {
27
- [chunkVJ6RW5H4_js.SPHERES.KETHER]: 1,
28
- [chunkVJ6RW5H4_js.SPHERES.CHOKHMAH]: 2,
29
- [chunkVJ6RW5H4_js.SPHERES.BINAH]: 3,
30
- [chunkVJ6RW5H4_js.SPHERES.DAATH]: 11,
31
- [chunkVJ6RW5H4_js.SPHERES.CHESED]: 4,
32
- [chunkVJ6RW5H4_js.SPHERES.GEBURAH]: 5,
33
- [chunkVJ6RW5H4_js.SPHERES.TIPHARETH]: 6,
34
- [chunkVJ6RW5H4_js.SPHERES.NETZACH]: 7,
35
- [chunkVJ6RW5H4_js.SPHERES.HOD]: 8,
36
- [chunkVJ6RW5H4_js.SPHERES.YESOD]: 9,
37
- [chunkVJ6RW5H4_js.SPHERES.MALKUTH]: 10
27
+ [chunkQ7YAKPBH_js.SPHERES.KETHER]: 1,
28
+ [chunkQ7YAKPBH_js.SPHERES.CHOKHMAH]: 2,
29
+ [chunkQ7YAKPBH_js.SPHERES.BINAH]: 3,
30
+ [chunkQ7YAKPBH_js.SPHERES.DAATH]: 11,
31
+ [chunkQ7YAKPBH_js.SPHERES.CHESED]: 4,
32
+ [chunkQ7YAKPBH_js.SPHERES.GEBURAH]: 5,
33
+ [chunkQ7YAKPBH_js.SPHERES.TIPHARETH]: 6,
34
+ [chunkQ7YAKPBH_js.SPHERES.NETZACH]: 7,
35
+ [chunkQ7YAKPBH_js.SPHERES.HOD]: 8,
36
+ [chunkQ7YAKPBH_js.SPHERES.YESOD]: 9,
37
+ [chunkQ7YAKPBH_js.SPHERES.MALKUTH]: 10
38
38
  };
39
39
  var TREE_TOPOLOGY_LIGHTNING_SPHERE_NAMES = [
40
- chunkVJ6RW5H4_js.SPHERES.KETHER,
41
- chunkVJ6RW5H4_js.SPHERES.CHOKHMAH,
42
- chunkVJ6RW5H4_js.SPHERES.BINAH,
43
- chunkVJ6RW5H4_js.SPHERES.CHESED,
44
- chunkVJ6RW5H4_js.SPHERES.GEBURAH,
45
- chunkVJ6RW5H4_js.SPHERES.TIPHARETH,
46
- chunkVJ6RW5H4_js.SPHERES.NETZACH,
47
- chunkVJ6RW5H4_js.SPHERES.HOD,
48
- chunkVJ6RW5H4_js.SPHERES.YESOD,
49
- chunkVJ6RW5H4_js.SPHERES.MALKUTH
40
+ chunkQ7YAKPBH_js.SPHERES.KETHER,
41
+ chunkQ7YAKPBH_js.SPHERES.CHOKHMAH,
42
+ chunkQ7YAKPBH_js.SPHERES.BINAH,
43
+ chunkQ7YAKPBH_js.SPHERES.CHESED,
44
+ chunkQ7YAKPBH_js.SPHERES.GEBURAH,
45
+ chunkQ7YAKPBH_js.SPHERES.TIPHARETH,
46
+ chunkQ7YAKPBH_js.SPHERES.NETZACH,
47
+ chunkQ7YAKPBH_js.SPHERES.HOD,
48
+ chunkQ7YAKPBH_js.SPHERES.YESOD,
49
+ chunkQ7YAKPBH_js.SPHERES.MALKUTH
50
50
  ];
51
+ var topologyCache = /* @__PURE__ */ new Map();
51
52
  function isNodeType(node, type) {
52
53
  return node.type === type;
53
54
  }
@@ -58,7 +59,7 @@ function clonePathData(data) {
58
59
  return { ...data };
59
60
  }
60
61
  function parsePathNumber(pathId) {
61
- const parsed = Number.parseInt(chunkVJ6RW5H4_js.parseId(pathId), 10);
62
+ const parsed = Number.parseInt(chunkQ7YAKPBH_js.parseId(pathId), 10);
62
63
  if (!Number.isInteger(parsed)) {
63
64
  throw new Error(`Invalid tree path id: ${pathId}`);
64
65
  }
@@ -109,6 +110,7 @@ var TreeTopology = class {
109
110
  this.pathsById = /* @__PURE__ */ new Map();
110
111
  this.pathsByNumber = /* @__PURE__ */ new Map();
111
112
  this.pathsBySpherePair = /* @__PURE__ */ new Map();
113
+ this.pathsBySphereId = /* @__PURE__ */ new Map();
112
114
  this.routesByKey = /* @__PURE__ */ new Map();
113
115
  this.system = system;
114
116
  this.spheres = spheres.map(
@@ -141,6 +143,11 @@ var TreeTopology = class {
141
143
  this.pathsById.set(path.id, path);
142
144
  this.pathsByNumber.set(path.number, path);
143
145
  this.pathsBySpherePair.set(pairKey(path.from.id, path.to.id), path);
146
+ for (const sphereId of [path.from.id, path.to.id]) {
147
+ const spherePaths = this.pathsBySphereId.get(sphereId) ?? [];
148
+ spherePaths.push(path);
149
+ this.pathsBySphereId.set(sphereId, spherePaths);
150
+ }
144
151
  }
145
152
  for (const key of ["lightning", "serpent"]) {
146
153
  this.routesByKey.set(key, this.buildRoute(key));
@@ -148,7 +155,7 @@ var TreeTopology = class {
148
155
  }
149
156
  getSpheres(options = {}) {
150
157
  const includeDaath = options.includeDaath ?? true;
151
- return includeDaath ? [...this.spheres] : this.spheres.filter((sphere) => sphere.name !== chunkVJ6RW5H4_js.SPHERES.DAATH);
158
+ return includeDaath ? [...this.spheres] : this.spheres.filter((sphere) => sphere.name !== chunkQ7YAKPBH_js.SPHERES.DAATH);
152
159
  }
153
160
  getPrimarySpheres() {
154
161
  return this.getSpheres({ includeDaath: false });
@@ -205,7 +212,7 @@ var TreeTopology = class {
205
212
  if (!sphere) {
206
213
  return [];
207
214
  }
208
- return this.paths.filter((path) => path.from.id === sphere.id || path.to.id === sphere.id).map((path) => {
215
+ return (this.pathsBySphereId.get(sphere.id) ?? []).map((path) => {
209
216
  const isForward = path.from.id === sphere.id;
210
217
  return {
211
218
  sphere: isForward ? path.to : path.from,
@@ -285,19 +292,24 @@ var TreeTopology = class {
285
292
  };
286
293
  function getTreeTopology(options = {}) {
287
294
  const system = options.system ?? options.tree?.activeSystem ?? "kaabalah";
288
- const tree = options.tree ?? chunkVJ6RW5H4_js.createTree({ system });
295
+ if (!options.tree) {
296
+ const cached = topologyCache.get(system);
297
+ if (cached)
298
+ return cached;
299
+ }
300
+ const tree = options.tree ?? chunkQ7YAKPBH_js.createTree({ system });
289
301
  const spheres = [];
290
302
  for (const sphereId of TREE_TOPOLOGY_SPHERE_IDS) {
291
303
  const sphereNode = tree.getNode(sphereId);
292
304
  if (!sphereNode) {
293
305
  continue;
294
306
  }
295
- const name = chunkVJ6RW5H4_js.parseId(sphereId);
307
+ const name = chunkQ7YAKPBH_js.parseId(sphereId);
296
308
  spheres.push({
297
309
  id: sphereId,
298
310
  name,
299
311
  number: TREE_TOPOLOGY_SPHERE_NUMBERS[name],
300
- role: name === chunkVJ6RW5H4_js.SPHERES.DAATH ? "hidden" : "sephirah",
312
+ role: name === chunkQ7YAKPBH_js.SPHERES.DAATH ? "hidden" : "sephirah",
301
313
  data: cloneSphereData(sphereNode.data)
302
314
  });
303
315
  }
@@ -323,11 +335,15 @@ function getTreeTopology(options = {}) {
323
335
  data: clonePathData(pathNode.data)
324
336
  };
325
337
  }).sort((left, right) => left.number - right.number);
326
- return new TreeTopology({
338
+ const topology = new TreeTopology({
327
339
  system,
328
340
  spheres,
329
341
  paths
330
342
  });
343
+ if (!options.tree) {
344
+ topologyCache.set(system, topology);
345
+ }
346
+ return topology;
331
347
  }
332
348
 
333
349
  // src/core/workspace.ts
@@ -339,30 +355,11 @@ function cloneNode(node) {
339
355
  data: node.data && typeof node.data === "object" ? { ...node.data } : node.data
340
356
  });
341
357
  }
342
- function cloneMetadata(metadata) {
343
- if (!metadata) {
344
- return void 0;
345
- }
346
- return {
347
- ...metadata,
348
- tags: metadata.tags ? [...metadata.tags] : void 0,
349
- attributes: metadata.attributes ? { ...metadata.attributes } : void 0
350
- };
351
- }
352
- function cloneSource(source) {
353
- if (source.kind === "bridge") {
354
- return {
355
- ...source,
356
- parts: [...source.parts]
357
- };
358
- }
359
- return { ...source };
360
- }
361
358
  function cloneEdge(edge) {
362
359
  return Object.freeze({
363
360
  ...edge,
364
- metadata: cloneMetadata(edge.metadata),
365
- sources: edge.sources.map(cloneSource)
361
+ metadata: chunkQ7YAKPBH_js.cloneMetadata(edge.metadata),
362
+ sources: edge.sources.map(chunkQ7YAKPBH_js.cloneSource)
366
363
  });
367
364
  }
368
365
  function cloneNote(note) {
@@ -372,36 +369,6 @@ function cloneNote(note) {
372
369
  metadata: note.metadata ? { ...note.metadata } : void 0
373
370
  });
374
371
  }
375
- function mergeMetadata(current, next) {
376
- if (!current) {
377
- return cloneMetadata(next);
378
- }
379
- if (!next) {
380
- return cloneMetadata(current);
381
- }
382
- return {
383
- ...current,
384
- ...next,
385
- tags: [.../* @__PURE__ */ new Set([...current.tags ?? [], ...next.tags ?? []])],
386
- attributes: {
387
- ...current.attributes ?? {},
388
- ...next.attributes ?? {}
389
- }
390
- };
391
- }
392
- function mergeSources(current, next) {
393
- const seen = /* @__PURE__ */ new Set();
394
- const merged = [];
395
- for (const source of [...current, next]) {
396
- const key = JSON.stringify(source);
397
- if (seen.has(key)) {
398
- continue;
399
- }
400
- seen.add(key);
401
- merged.push(cloneSource(source));
402
- }
403
- return merged;
404
- }
405
372
  function normalizeTypes(type) {
406
373
  if (!type) {
407
374
  return void 0;
@@ -465,7 +432,7 @@ function createGraphData(descriptor, nodes, edges, notes) {
465
432
  noteIdsByNodeId.set(clonedNote.target.nodeId, nodeNoteIds);
466
433
  continue;
467
434
  }
468
- const edgeId = chunkVJ6RW5H4_js.makeCorrespondenceId(
435
+ const edgeId = chunkQ7YAKPBH_js.makeCorrespondenceId(
469
436
  clonedNote.target.left,
470
437
  clonedNote.target.right
471
438
  );
@@ -564,7 +531,7 @@ function applyOverlays(base, overlays) {
564
531
  `Overlay ${overlay.id} references unknown nodes in ${correspondence.left} <-> ${correspondence.right}`
565
532
  );
566
533
  }
567
- const edgeId = chunkVJ6RW5H4_js.makeCorrespondenceId(
534
+ const edgeId = chunkQ7YAKPBH_js.makeCorrespondenceId(
568
535
  correspondence.left,
569
536
  correspondence.right
570
537
  );
@@ -590,7 +557,7 @@ function applyOverlays(base, overlays) {
590
557
  id: edgeId,
591
558
  left: correspondence.left,
592
559
  right: correspondence.right,
593
- metadata: cloneMetadata(correspondence.metadata),
560
+ metadata: chunkQ7YAKPBH_js.cloneMetadata(correspondence.metadata),
594
561
  sources: [overlaySource]
595
562
  })
596
563
  );
@@ -600,8 +567,8 @@ function applyOverlays(base, overlays) {
600
567
  edgeId,
601
568
  cloneEdge({
602
569
  ...existingEdge,
603
- metadata: mergeMetadata(existingEdge.metadata, correspondence.metadata),
604
- sources: mergeSources(existingEdge.sources, overlaySource)
570
+ metadata: chunkQ7YAKPBH_js.mergeMetadata(existingEdge.metadata, correspondence.metadata),
571
+ sources: chunkQ7YAKPBH_js.mergeSources(existingEdge.sources, overlaySource)
605
572
  })
606
573
  );
607
574
  }
@@ -619,7 +586,7 @@ function applyOverlays(base, overlays) {
619
586
  return nodesById.has(note.target.nodeId);
620
587
  }
621
588
  return edgesById.has(
622
- chunkVJ6RW5H4_js.makeCorrespondenceId(note.target.left, note.target.right)
589
+ chunkQ7YAKPBH_js.makeCorrespondenceId(note.target.left, note.target.right)
623
590
  );
624
591
  });
625
592
  return {
@@ -703,7 +670,7 @@ var TreeWorkspace = class {
703
670
  );
704
671
  }
705
672
  getEdge(left, right) {
706
- return this.graph.edgesById.get(chunkVJ6RW5H4_js.makeCorrespondenceId(left, right));
673
+ return this.graph.edgesById.get(chunkQ7YAKPBH_js.makeCorrespondenceId(left, right));
707
674
  }
708
675
  getEdges(nodeId) {
709
676
  if (!nodeId) {
@@ -718,7 +685,7 @@ var TreeWorkspace = class {
718
685
  if (target.kind === "node") {
719
686
  return (this.graph.noteIdsByNodeId.get(target.nodeId) ?? []).map((noteId) => this.graph.notesById.get(noteId)).filter((note) => Boolean(note));
720
687
  }
721
- const edgeId = chunkVJ6RW5H4_js.makeCorrespondenceId(target.left, target.right);
688
+ const edgeId = chunkQ7YAKPBH_js.makeCorrespondenceId(target.left, target.right);
722
689
  return (this.graph.noteIdsByCorrespondenceId.get(edgeId) ?? []).map((noteId) => this.graph.notesById.get(noteId)).filter((note) => Boolean(note));
723
690
  }
724
691
  getCorrespondences(nodeId, options = {}) {
@@ -838,7 +805,7 @@ function getCanonicalTree(opts = {
838
805
  if (cachedTree) {
839
806
  return cachedTree;
840
807
  }
841
- const tree = chunkVJ6RW5H4_js.createTree({
808
+ const tree = chunkQ7YAKPBH_js.createTree({
842
809
  system: opts.system,
843
810
  parts
844
811
  });
@@ -860,4 +827,4 @@ exports.createTreeWorkspace = createTreeWorkspace;
860
827
  exports.getCanonicalTree = getCanonicalTree;
861
828
  exports.getTreeTopology = getTreeTopology;
862
829
  //# sourceMappingURL=out.js.map
863
- //# sour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W;AAAA,IACtB,QAAQ,KAAK;AAAA,IACb;AAAA,EACF,CAAC;AAED,QAAM,gBAAgB,oBAAoB;AAAA,IACxC,MAAM;AAAA,IACN,YAAY,yBAAyB,MAAM,QAAQ;AAAA,EACrD,CAAC;AAED,qBAAmB,IAAI,UAAU,aAAa;AAE9C,SAAO;AACT","sourcesContent":["import { SPHERES } from \"./constants\";\nimport { createTree } from \"./factory\";\nimport { SystemKey } from \"./systems/registry\";\nimport {\n id,\n KaabalahTypes,\n Node,\n NodeData,\n NodeId,\n NodeType,\n parseId,\n} from \"./types\";\nimport { TreeOfLife } from \"./tree-of-life\";\n\nexport type TreeTopologySphereName =\n (typeof TREE_TOPOLOGY_SPHERE_NAMES)[number];\nexport type TreeTopologySphereId = NodeId<KaabalahTypes.SPHERE>;\nexport type TreeTopologyPathId = NodeId<KaabalahTypes.PATH>;\nexport type TreeTopologySphereRole = \"sephirah\" | \"hidden\";\nexport type TreeTopologyRouteKey = \"lightning\" | \"serpent\";\nexport type TreeTopologyRouteDirection = \"descending\" | \"ascending\";\n\nexport const TREE_TOPOLOGY_SPHERE_NAMES = [\n SPHERES.KETHER,\n SPHERES.CHOKHMAH,\n SPHERES.BINAH,\n SPHERES.DAATH,\n SPHERES.CHESED,\n SPHERES.GEBURAH,\n SPHERES.TIPHARETH,\n SPHERES.NETZACH,\n SPHERES.HOD,\n SPHERES.YESOD,\n SPHERES.MALKUTH,\n] as const;\n\nexport const TREE_TOPOLOGY_SPHERE_IDS = TREE_TOPOLOGY_SPHERE_NAMES.map(\n (name) => id(KaabalahTypes.SPHERE, name)\n) as readonly TreeTopologySphereId[];\n\nexport const TREE_TOPOLOGY_PATH_IDS = Array.from(\n { length: 22 },\n (_, index) => id(KaabalahTypes.PATH, index + 1)\n) as readonly TreeTopologyPathId[];\n\nconst TREE_TOPOLOGY_SPHERE_NUMBERS = {\n [SPHERES.KETHER]: 1,\n [SPHERES.CHOKHMAH]: 2,\n [SPHERES.BINAH]: 3,\n [SPHERES.DAATH]: 11,\n [SPHERES.CHESED]: 4,\n [SPHERES.GEBURAH]: 5,\n [SPHERES.TIPHARETH]: 6,\n [SPHERES.NETZACH]: 7,\n [SPHERES.HOD]: 8,\n [SPHERES.YESOD]: 9,\n [SPHERES.MALKUTH]: 10,\n} as const satisfies Record<TreeTopologySphereName, number>;\n\nexport const TREE_TOPOLOGY_LIGHTNING_SPHERE_NAMES = [\n SPHERES.KETHER,\n SPHERES.CHOKHMAH,\n SPHERES.BINAH,\n SPHERES.CHESED,\n SPHERES.GEBURAH,\n SPHERES.TIPHARETH,\n SPHERES.NETZACH,\n SPHERES.HOD,\n SPHERES.YESOD,\n SPHERES.MALKUTH,\n] as const satisfies readonly TreeTopologySphereName[];\n\nexport interface TreeTopologySphere {\n id: TreeTopologySphereId;\n name: TreeTopologySphereName;\n number: number;\n role: TreeTopologySphereRole;\n data?: NodeData<KaabalahTypes.SPHERE>;\n}\n\nexport interface TreeTopologyPath {\n id: TreeTopologyPathId;\n number: number;\n from: TreeTopologySphere;\n to: TreeTopologySphere;\n data: NodeData<KaabalahTypes.PATH>;\n}\n\nexport interface TreeTopologyAdjacentSphere {\n sphere: TreeTopologySphere;\n path: TreeTopologyPath;\n direction: \"forward\" | \"reverse\";\n}\n\nexport interface TreeTopologyRouteSegment {\n index: number;\n from: TreeTopologySphere;\n to: TreeTopologySphere;\n path?: TreeTopologyPath;\n isConnected: boolean;\n}\n\nexport interface TreeTopologyRouteTarget {\n targetId: TreeTopologySphereId | TreeTopologyPathId;\n targetType: \"sphere\" | \"path\";\n}\n\nexport interface TreeTopologyRoute {\n key: TreeTopologyRouteKey;\n name: string;\n direction: TreeTopologyRouteDirection;\n spheres: readonly TreeTopologySphere[];\n segments: readonly TreeTopologyRouteSegment[];\n isFullyConnected: boolean;\n missingSegments: readonly TreeTopologyRouteSegment[];\n targets: readonly TreeTopologyRouteTarget[];\n targetIds: readonly (TreeTopologySphereId | TreeTopologyPathId)[];\n}\n\nexport type TreeTopologySphereLookup =\n | TreeTopologySphereName\n | TreeTopologySphereId\n | {\n id?: TreeTopologySphereId;\n name?: TreeTopologySphereName | string;\n number?: number;\n };\n\nexport type TreeTopologyPathLookup =\n | number\n | TreeTopologyPathId\n | {\n id?: TreeTopologyPathId;\n number?: number;\n between?: readonly [TreeTopologySphereLookup, TreeTopologySphereLookup];\n };\n\nexport interface TreeTopologyOptions {\n system?: SystemKey;\n tree?: TreeOfLife;\n}\n\nexport interface GetTreeTopologySpheresOptions {\n includeDaath?: boolean;\n}\n\nconst topologyCache = new Map<string, TreeTopology>();\n\nfunction isNodeType<T extends NodeType>(\n node: Node<NodeType>,\n type: T\n): node is Node<T> {\n return node.type === type;\n}\n\nfunction cloneSphereData(data?: NodeData<KaabalahTypes.SPHERE>) {\n return data ? { ...data } : undefined;\n}\n\nfunction clonePathData(data: NodeData<KaabalahTypes.PATH>) {\n return { ...data };\n}\n\nfunction parsePathNumber(pathId: TreeTopologyPathId) {\n const parsed = Number.parseInt(parseId(pathId), 10);\n\n if (!Number.isInteger(parsed)) {\n throw new Error(`Invalid tree path id: ${pathId}`);\n }\n\n return parsed;\n}\n\nfunction normalizeName(value: string) {\n return value.trim().toLowerCase();\n}\n\nfunction pairKey(left: TreeTopologySphereId, right: TreeTopologySphereId) {\n return [String(left), String(right)].sort().join(\"|\");\n}\n\nfunction routeNames() {\n return [...TREE_TOPOLOGY_LIGHTNING_SPHERE_NAMES];\n}\n\nfunction routeDescriptor(key: TreeTopologyRouteKey) {\n return key === \"lightning\"\n ? {\n name: \"Lightning Path\",\n direction: \"descending\" as const,\n }\n : {\n name: \"Serpent Path\",\n direction: \"ascending\" as const,\n };\n}\n\nfunction routeTargetList(segments: readonly TreeTopologyRouteSegment[]) {\n if (segments.length === 0) {\n return [] as TreeTopologyRouteTarget[];\n }\n\n const targets: TreeTopologyRouteTarget[] = [\n { targetId: segments[0].from.id, targetType: \"sphere\" },\n ];\n\n for (const segment of segments) {\n if (segment.path) {\n targets.push({ targetId: segment.path.id, targetType: \"path\" });\n }\n\n targets.push({ targetId: segment.to.id, targetType: \"sphere\" });\n }\n\n return targets;\n}\n\nexport class TreeTopology {\n public readonly system: SystemKey;\n\n private readonly spheres: readonly TreeTopologySphere[];\n private readonly paths: readonly TreeTopologyPath[];\n private readonly spheresById = new Map<\n TreeTopologySphereId,\n TreeTopologySphere\n >();\n private readonly spheresByName = new Map<string, TreeTopologySphere>();\n private readonly spheresByNumber = new Map<number, TreeTopologySphere>();\n private readonly pathsById = new Map<TreeTopologyPathId, TreeTopologyPath>();\n private readonly pathsByNumber = new Map<number, TreeTopologyPath>();\n private readonly pathsBySpherePair = new Map<string, TreeTopologyPath>();\n private readonly pathsBySphereId = new Map<TreeTopologySphereId, TreeTopologyPath[]>();\n private readonly routesByKey = new Map<\n TreeTopologyRouteKey,\n TreeTopologyRoute\n >();\n\n constructor({\n system,\n spheres,\n paths,\n }: {\n system: SystemKey;\n spheres: readonly TreeTopologySphere[];\n paths: readonly TreeTopologyPath[];\n }) {\n this.system = system;\n this.spheres = spheres.map((sphere) =>\n Object.freeze({\n ...sphere,\n data: cloneSphereData(sphere.data),\n })\n );\n\n for (const sphere of this.spheres) {\n this.spheresById.set(sphere.id, sphere);\n this.spheresByName.set(normalizeName(sphere.name), sphere);\n this.spheresByNumber.set(sphere.number, sphere);\n }\n\n this.paths = paths.map((path) => {\n const from = this.spheresById.get(path.from.id);\n const to = this.spheresById.get(path.to.id);\n\n if (!from || !to) {\n throw new Error(\n `Tree topology path ${path.id} references unknown spheres.`\n );\n }\n\n return Object.freeze({\n ...path,\n from,\n to,\n data: clonePathData(path.data),\n });\n });\n\n for (const path of this.paths) {\n this.pathsById.set(path.id, path);\n this.pathsByNumber.set(path.number, path);\n this.pathsBySpherePair.set(pairKey(path.from.id, path.to.id), path);\n\n for (const sphereId of [path.from.id, path.to.id]) {\n const spherePaths = this.pathsBySphereId.get(sphereId) ?? [];\n spherePaths.push(path);\n this.pathsBySphereId.set(sphereId, spherePaths);\n }\n }\n\n for (const key of [\"lightning\", \"serpent\"] as const) {\n this.routesByKey.set(key, this.buildRoute(key));\n }\n }\n\n getSpheres(options: GetTreeTopologySpheresOptions = {}) {\n const includeDaath = options.includeDaath ?? true;\n\n return includeDaath\n ? [...this.spheres]\n : this.spheres.filter((sphere) => sphere.name !== SPHERES.DAATH);\n }\n\n getPrimarySpheres() {\n return this.getSpheres({ includeDaath: false });\n }\n\n getSphere(lookup: TreeTopologySphereLookup) {\n if (typeof lookup === \"string\") {\n if (lookup.startsWith(`${KaabalahTypes.SPHERE}:`)) {\n return this.spheresById.get(lookup as TreeTopologySphereId);\n }\n\n return this.spheresByName.get(normalizeName(lookup));\n }\n\n if (lookup.id) {\n return this.spheresById.get(lookup.id);\n }\n\n if (lookup.number) {\n return this.spheresByNumber.get(lookup.number);\n }\n\n if (lookup.name) {\n return this.spheresByName.get(normalizeName(lookup.name));\n }\n\n return undefined;\n }\n\n getPaths() {\n return [...this.paths];\n }\n\n getPath(lookup: TreeTopologyPathLookup) {\n if (typeof lookup === \"number\") {\n return this.pathsByNumber.get(lookup);\n }\n\n if (typeof lookup === \"string\") {\n return this.pathsById.get(lookup as TreeTopologyPathId);\n }\n\n if (lookup.id) {\n return this.pathsById.get(lookup.id);\n }\n\n if (lookup.number) {\n return this.pathsByNumber.get(lookup.number);\n }\n\n if (lookup.between) {\n return this.getPathBetween(lookup.between[0], lookup.between[1]);\n }\n\n return undefined;\n }\n\n getPathBetween(\n first: TreeTopologySphereLookup,\n second: TreeTopologySphereLookup\n ) {\n const firstSphere = this.getSphere(first);\n const secondSphere = this.getSphere(second);\n\n if (!firstSphere || !secondSphere) {\n return undefined;\n }\n\n return this.pathsBySpherePair.get(pairKey(firstSphere.id, secondSphere.id));\n }\n\n getAdjacentSpheres(\n sphereLookup: TreeTopologySphereLookup\n ): TreeTopologyAdjacentSphere[] {\n const sphere = this.getSphere(sphereLookup);\n\n if (!sphere) {\n return [];\n }\n\n return (this.pathsBySphereId.get(sphere.id) ?? [])\n .map((path) => {\n const isForward = path.from.id === sphere.id;\n\n return {\n sphere: isForward ? path.to : path.from,\n path,\n direction: isForward ? \"forward\" : \"reverse\",\n };\n });\n }\n\n getRoutes() {\n return [...this.routesByKey.values()];\n }\n\n getRoute(key: TreeTopologyRouteKey) {\n return this.routesByKey.get(key);\n }\n\n nextInRoute(\n routeKey: TreeTopologyRouteKey,\n sphereLookup: TreeTopologySphereLookup\n ) {\n const route = this.getRoute(routeKey);\n const sphere = this.getSphere(sphereLookup);\n\n if (!route || !sphere) {\n return undefined;\n }\n\n const index = route.spheres.findIndex(\n (routeSphere) => routeSphere.id === sphere.id\n );\n\n return index >= 0 ? route.spheres[index + 1] : undefined;\n }\n\n previousInRoute(\n routeKey: TreeTopologyRouteKey,\n sphereLookup: TreeTopologySphereLookup\n ) {\n const route = this.getRoute(routeKey);\n const sphere = this.getSphere(sphereLookup);\n\n if (!route || !sphere) {\n return undefined;\n }\n\n const index = route.spheres.findIndex(\n (routeSphere) => routeSphere.id === sphere.id\n );\n\n return index > 0 ? route.spheres[index - 1] : undefined;\n }\n\n private buildRoute(key: TreeTopologyRouteKey): TreeTopologyRoute {\n const descriptor = routeDescriptor(key);\n const names = routeNames();\n const orderedNames = key === \"serpent\" ? names.reverse() : names;\n const spheres = orderedNames.map((name) => {\n const sphere = this.getSphere(name);\n\n if (!sphere) {\n throw new Error(\n `Tree topology route \"${key}\" references missing sphere \"${name}\" in ${this.system}.`\n );\n }\n\n return sphere;\n });\n const segments: TreeTopologyRouteSegment[] = [];\n\n for (let index = 0; index < spheres.length - 1; index++) {\n const from = spheres[index];\n const to = spheres[index + 1];\n const path = this.getPathBetween(from.name, to.name);\n\n segments.push({\n index,\n from,\n to,\n path,\n isConnected: Boolean(path),\n });\n }\n\n const targets = routeTargetList(segments);\n const missingSegments = segments.filter((segment) => !segment.isConnected);\n\n return Object.freeze({\n key,\n name: descriptor.name,\n direction: descriptor.direction,\n spheres: Object.freeze([...spheres]),\n segments: Object.freeze(segments),\n isFullyConnected: missingSegments.length === 0,\n missingSegments: Object.freeze(missingSegments),\n targets: Object.freeze(targets),\n targetIds: Object.freeze(targets.map((target) => target.targetId)),\n });\n }\n}\n\nexport function getTreeTopology(options: TreeTopologyOptions = {}) {\n const system = options.system ?? options.tree?.activeSystem ?? \"kaabalah\";\n if (!options.tree) {\n const cached = topologyCache.get(system);\n if (cached) return cached;\n }\n\n const tree = options.tree ?? createTree({ system });\n const spheres: TreeTopologySphere[] = [];\n\n for (const sphereId of TREE_TOPOLOGY_SPHERE_IDS) {\n const sphereNode = tree.getNode(sphereId);\n\n if (!sphereNode) {\n continue;\n }\n\n const name = parseId(sphereId) as TreeTopologySphereName;\n\n spheres.push({\n id: sphereId,\n name,\n number: TREE_TOPOLOGY_SPHERE_NUMBERS[name],\n role: name === SPHERES.DAATH ? \"hidden\" : \"sephirah\",\n data: cloneSphereData(sphereNode.data),\n });\n }\n\n const spheresById = new Map(spheres.map((sphere) => [sphere.id, sphere]));\n const paths = tree\n .getNodes()\n .filter((node): node is Node<KaabalahTypes.PATH> =>\n isNodeType(node, KaabalahTypes.PATH)\n )\n .map((pathNode) => {\n if (!pathNode.data?.from || !pathNode.data?.to) {\n throw new Error(`Tree topology path ${pathNode.id} is missing endpoints.`);\n }\n\n const from = spheresById.get(pathNode.data.from);\n const to = spheresById.get(pathNode.data.to);\n\n if (!from || !to) {\n throw new Error(\n `Tree topology path ${pathNode.id} references unknown spheres.`\n );\n }\n\n return {\n id: pathNode.id,\n number: parsePathNumber(pathNode.id),\n from,\n to,\n data: clonePathData(pathNode.data),\n } satisfies TreeTopologyPath;\n })\n .sort((left, right) => left.number - right.number);\n\n const topology = new TreeTopology({\n system,\n spheres,\n paths,\n });\n\n if (!options.tree) {\n topologyCache.set(system, topology);\n }\n\n return topology;\n}\n","import {\n CorrespondenceEdge,\n CorrespondenceMap,\n CorrespondenceMatch,\n CorrespondenceSource,\n CorrespondenceStep,\n TreeNote,\n TreeNoteTarget,\n TreeOverlay,\n TreeWorkspaceDescriptor,\n cloneMetadata,\n cloneSource,\n makeCorrespondenceId,\n mergeMetadata,\n mergeSources,\n} from \"./correspondence-model\";\nimport { createTree, TreeOptions } from \"./factory\";\nimport { TreeOfLife } from \"./tree-of-life\";\nimport { Node, NodeId, NodeType } from \"./types\";\n\nexport interface TreeCorrespondenceQueryOptions<T extends NodeType = NodeType> {\n type?: T | readonly T[];\n depth?: number;\n includeSelf?: boolean;\n limit?: number;\n}\n\nexport interface TreeFindNodesOptions<T extends NodeType = NodeType> {\n type?: T | readonly T[];\n ids?: readonly NodeId<T>[];\n search?: string;\n predicate?: (node: Node<T>) => boolean;\n}\n\nexport interface TreeVisualRequest {\n nodeId: NodeId<NodeType>;\n kind?: string;\n [key: string]: unknown;\n}\n\nexport interface TreeVisualResult {\n kind: string;\n nodeId: NodeId<NodeType>;\n [key: string]: unknown;\n}\n\nexport type TreeVisualResolver = (input: {\n request: TreeVisualRequest;\n workspace: TreeWorkspace;\n}) => TreeVisualResult | undefined;\n\nexport interface CreateTreeWorkspaceOptions {\n base?: TreeWorkspace | TreeOfLife;\n overlays?: TreeOverlay[];\n descriptor?: TreeWorkspaceDescriptor;\n visualResolvers?: TreeVisualResolver[];\n}\n\ntype TreeGraphData = {\n descriptor: TreeWorkspaceDescriptor;\n nodesById: Map<NodeId<NodeType>, Node<NodeType>>;\n nodeIdsByType: Map<NodeType, NodeId<NodeType>[]>;\n edgesById: Map<string, CorrespondenceEdge>;\n edgeIdsByNodeId: Map<NodeId<NodeType>, string[]>;\n notesById: Map<string, TreeNote>;\n noteIdsByNodeId: Map<NodeId<NodeType>, string[]>;\n noteIdsByCorrespondenceId: Map<string, string[]>;\n};\n\nfunction cloneNode<T extends NodeType>(node: Node<T>): Node<T> {\n return Object.freeze({\n id: node.id,\n type: node.type,\n name: node.name,\n data:\n node.data && typeof node.data === \"object\"\n ? ({ ...node.data } as Node<T>[\"data\"])\n : node.data,\n });\n}\n\nfunction cloneEdge(edge: CorrespondenceEdge): CorrespondenceEdge {\n return Object.freeze({\n ...edge,\n metadata: cloneMetadata(edge.metadata),\n sources: edge.sources.map(cloneSource),\n });\n}\n\nfunction cloneNote(note: TreeNote): TreeNote {\n return Object.freeze({\n ...note,\n target: { ...note.target },\n metadata: note.metadata ? { ...note.metadata } : undefined,\n });\n}\n\nfunction normalizeTypes<T extends NodeType>(\n type?: T | readonly T[]\n): Set<NodeType> | undefined {\n if (!type) {\n return undefined;\n }\n\n return new Set(Array.isArray(type) ? type : [type]);\n}\n\nfunction sortNodes<T extends NodeType>(nodes: Node<T>[]) {\n return [...nodes].sort((left, right) => {\n if (left.type !== right.type) {\n return left.type.localeCompare(right.type);\n }\n\n const leftLabel = String(left.name ?? left.id);\n const rightLabel = String(right.name ?? right.id);\n\n return leftLabel.localeCompare(rightLabel);\n });\n}\n\nfunction sortMatches<T extends NodeType>(matches: CorrespondenceMatch<T>[]) {\n return [...matches].sort((left, right) => {\n if (left.distance !== right.distance) {\n return left.distance - right.distance;\n }\n\n if (left.node.type !== right.node.type) {\n return left.node.type.localeCompare(right.node.type);\n }\n\n const leftLabel = String(left.node.name ?? left.node.id);\n const rightLabel = String(right.node.name ?? right.node.id);\n\n return leftLabel.localeCompare(rightLabel);\n });\n}\n\nfunction createGraphData(\n descriptor: TreeWorkspaceDescriptor,\n nodes: Iterable<Node<NodeType>>,\n edges: Iterable<CorrespondenceEdge>,\n notes: Iterable<TreeNote>\n): TreeGraphData {\n const nodesById = new Map<NodeId<NodeType>, Node<NodeType>>();\n const nodeIdsByType = new Map<NodeType, NodeId<NodeType>[]>();\n const edgesById = new Map<string, CorrespondenceEdge>();\n const edgeIdsByNodeId = new Map<NodeId<NodeType>, string[]>();\n const notesById = new Map<string, TreeNote>();\n const noteIdsByNodeId = new Map<NodeId<NodeType>, string[]>();\n const noteIdsByCorrespondenceId = new Map<string, string[]>();\n\n for (const node of nodes) {\n const clonedNode = cloneNode(node);\n\n nodesById.set(clonedNode.id, clonedNode);\n\n const typedIds = nodeIdsByType.get(clonedNode.type) ?? [];\n typedIds.push(clonedNode.id as NodeId<NodeType>);\n nodeIdsByType.set(clonedNode.type, typedIds);\n }\n\n for (const edge of edges) {\n const clonedEdge = cloneEdge(edge);\n\n edgesById.set(clonedEdge.id, clonedEdge);\n\n const leftEdges = edgeIdsByNodeId.get(clonedEdge.left) ?? [];\n leftEdges.push(clonedEdge.id);\n edgeIdsByNodeId.set(clonedEdge.left, leftEdges);\n\n const rightEdges = edgeIdsByNodeId.get(clonedEdge.right) ?? [];\n rightEdges.push(clonedEdge.id);\n edgeIdsByNodeId.set(clonedEdge.right, rightEdges);\n }\n\n for (const note of notes) {\n const clonedNote = cloneNote(note);\n notesById.set(clonedNote.id, clonedNote);\n\n if (clonedNote.target.kind === \"node\") {\n const nodeNoteIds = noteIdsByNodeId.get(clonedNote.target.nodeId) ?? [];\n nodeNoteIds.push(clonedNote.id);\n noteIdsByNodeId.set(clonedNote.target.nodeId, nodeNoteIds);\n continue;\n }\n\n const edgeId = makeCorrespondenceId(\n clonedNote.target.left,\n clonedNote.target.right\n );\n const correspondenceNoteIds =\n noteIdsByCorrespondenceId.get(edgeId) ?? [];\n correspondenceNoteIds.push(clonedNote.id);\n noteIdsByCorrespondenceId.set(edgeId, correspondenceNoteIds);\n }\n\n for (const ids of nodeIdsByType.values()) {\n ids.sort((left, right) => String(left).localeCompare(String(right)));\n }\n\n for (const ids of edgeIdsByNodeId.values()) {\n ids.sort((left, right) => left.localeCompare(right));\n }\n\n for (const ids of noteIdsByNodeId.values()) {\n ids.sort((left, right) => left.localeCompare(right));\n }\n\n for (const ids of noteIdsByCorrespondenceId.values()) {\n ids.sort((left, right) => left.localeCompare(right));\n }\n\n return {\n descriptor: Object.freeze({ ...descriptor }),\n nodesById,\n nodeIdsByType,\n edgesById,\n edgeIdsByNodeId,\n notesById,\n noteIdsByNodeId,\n noteIdsByCorrespondenceId,\n };\n}\n\nfunction normalizeBase(base?: TreeWorkspace | TreeOfLife) {\n if (!base) {\n return {\n descriptor: {},\n nodes: [] as Node<NodeType>[],\n edges: [] as CorrespondenceEdge[],\n notes: [] as TreeNote[],\n };\n }\n\n if (base instanceof TreeWorkspace) {\n return {\n descriptor: base.descriptor,\n nodes: base.getNodes(),\n edges: base.getEdges(),\n notes: base.getNotes(),\n };\n }\n\n return {\n descriptor: {\n system: base.activeSystem ?? undefined,\n parts: base.loadedParts.filter((part) => part !== \"base\"),\n },\n nodes: base.getNodes(),\n edges: base.getEdges(),\n notes: [] as TreeNote[],\n };\n}\n\nfunction applyOverlays(\n base: ReturnType<typeof normalizeBase>,\n overlays: TreeOverlay[]\n) {\n const nodesById = new Map<NodeId<NodeType>, Node<NodeType>>();\n const edgesById = new Map<string, CorrespondenceEdge>();\n const notes: TreeNote[] = [];\n\n for (const node of base.nodes) {\n nodesById.set(node.id as NodeId<NodeType>, cloneNode(node));\n }\n\n for (const edge of base.edges) {\n edgesById.set(edge.id, cloneEdge(edge));\n }\n\n for (const note of base.notes) {\n notes.push(cloneNote(note));\n }\n\n for (const overlay of overlays) {\n for (const node of overlay.nodes ?? []) {\n const existing = nodesById.get(node.id as NodeId<NodeType>);\n\n if (existing && existing.type !== node.type) {\n throw new Error(\n `Overlay ${overlay.id} tried to upsert ${node.id} with a different type`\n );\n }\n\n nodesById.set(\n node.id as NodeId<NodeType>,\n cloneNode(\n existing\n ? {\n ...existing,\n ...node,\n data: {\n ...(existing.data ?? {}),\n ...(node.data ?? {}),\n } as Node<NodeType>[\"data\"],\n }\n : node\n )\n );\n }\n\n for (const correspondence of overlay.correspondences ?? []) {\n if (\n !nodesById.has(correspondence.left) ||\n !nodesById.has(correspondence.right)\n ) {\n throw new Error(\n `Overlay ${overlay.id} references unknown nodes in ${correspondence.left} <-> ${correspondence.right}`\n );\n }\n\n const edgeId = makeCorrespondenceId(\n correspondence.left,\n correspondence.right\n );\n\n if (correspondence.op === \"remove\") {\n edgesById.delete(edgeId);\n continue;\n }\n\n const existingEdge = edgesById.get(edgeId);\n const overlaySource: CorrespondenceSource = {\n kind: \"overlay\",\n overlayId: overlay.id,\n label: overlay.name,\n };\n\n if (!existingEdge) {\n if (correspondence.op !== \"add\") {\n throw new Error(\n `Overlay ${overlay.id} cannot annotate missing correspondence ${edgeId}`\n );\n }\n\n edgesById.set(\n edgeId,\n cloneEdge({\n id: edgeId,\n left: correspondence.left,\n right: correspondence.right,\n metadata: cloneMetadata(correspondence.metadata),\n sources: [overlaySource],\n })\n );\n continue;\n }\n\n edgesById.set(\n edgeId,\n cloneEdge({\n ...existingEdge,\n metadata: mergeMetadata(existingEdge.metadata, correspondence.metadata),\n sources: mergeSources(existingEdge.sources, overlaySource),\n })\n );\n }\n\n for (const note of overlay.notes ?? []) {\n notes.push(\n cloneNote({\n ...note,\n metadata: note.metadata ? { ...note.metadata } : undefined,\n })\n );\n }\n }\n\n const filteredNotes = notes.filter((note) => {\n if (note.target.kind === \"node\") {\n return nodesById.has(note.target.nodeId);\n }\n\n return edgesById.has(\n makeCorrespondenceId(note.target.left, note.target.right)\n );\n });\n\n return {\n nodes: [...nodesById.values()],\n edges: [...edgesById.values()],\n notes: filteredNotes,\n };\n}\n\nfunction reconstructPath(\n startId: NodeId<NodeType>,\n targetId: NodeId<NodeType>,\n previous: Map<NodeId<NodeType>, { from: NodeId<NodeType>; edgeId: string }>,\n edgesById: Map<string, CorrespondenceEdge>\n) {\n const steps: CorrespondenceStep[] = [];\n let current = targetId;\n\n while (current !== startId) {\n const link = previous.get(current);\n\n if (!link) {\n break;\n }\n\n const edge = edgesById.get(link.edgeId);\n\n if (!edge) {\n break;\n }\n\n steps.push({\n from: link.from,\n to: current,\n edge,\n });\n current = link.from;\n }\n\n return steps.reverse();\n}\n\nfunction buildCanonicalDescriptor(opts: TreeOptions, cacheKey: string) {\n return {\n id: `canonical:${cacheKey}`,\n name: \"Canonical Tree\",\n system: opts.system,\n parts: [...(opts.parts ?? [])],\n cacheKey,\n } satisfies TreeWorkspaceDescriptor;\n}\n\nconst canonicalTreeCache = new Map<string, TreeWorkspace>();\n\nexport class TreeWorkspace {\n public readonly descriptor: TreeWorkspaceDescriptor;\n\n constructor(\n private readonly graph: TreeGraphData,\n private readonly visualResolvers: readonly TreeVisualResolver[] = []\n ) {\n this.descriptor = graph.descriptor;\n }\n\n getNode<T extends NodeType>(id: NodeId<T>) {\n return this.graph.nodesById.get(id as NodeId<NodeType>) as\n | Node<T>\n | undefined;\n }\n\n hasNode(id: NodeId<NodeType>) {\n return this.graph.nodesById.has(id);\n }\n\n getNodes<T extends NodeType>(type?: T): Node<T>[] {\n if (!type) {\n return sortNodes(\n [...this.graph.nodesById.values()] as Node<T>[]\n );\n }\n\n const ids = this.graph.nodeIdsByType.get(type) ?? [];\n\n return ids\n .map((id) => this.graph.nodesById.get(id) as Node<T> | undefined)\n .filter((node): node is Node<T> => Boolean(node));\n }\n\n findNodes<T extends NodeType = NodeType>(\n options: TreeFindNodesOptions<T> = {}\n ): Node<T>[] {\n const typeFilter = normalizeTypes(options.type);\n const search = options.search?.trim().toLowerCase();\n\n const candidates = options.ids\n ? options.ids\n .map((id) => this.graph.nodesById.get(id as NodeId<NodeType>))\n .filter((node): node is Node<NodeType> => Boolean(node))\n : typeFilter\n ? [...typeFilter].flatMap((type) => this.getNodes(type))\n : this.getNodes();\n\n return sortNodes(\n candidates.filter((node): node is Node<T> => {\n if (typeFilter && !typeFilter.has(node.type)) {\n return false;\n }\n\n if (search) {\n const haystacks = [\n String(node.id).toLowerCase(),\n String(node.name ?? \"\").toLowerCase(),\n ];\n\n if (!haystacks.some((value) => value.includes(search))) {\n return false;\n }\n }\n\n return options.predicate ? options.predicate(node as Node<T>) : true;\n })\n );\n }\n\n getEdge(left: NodeId<NodeType>, right: NodeId<NodeType>) {\n return this.graph.edgesById.get(makeCorrespondenceId(left, right));\n }\n\n getEdges(nodeId?: NodeId<NodeType>) {\n if (!nodeId) {\n return [...this.graph.edgesById.values()];\n }\n\n return (this.graph.edgeIdsByNodeId.get(nodeId) ?? [])\n .map((edgeId) => this.graph.edgesById.get(edgeId))\n .filter((edge): edge is CorrespondenceEdge => Boolean(edge));\n }\n\n getNotes(target?: TreeNoteTarget) {\n if (!target) {\n return [...this.graph.notesById.values()];\n }\n\n if (target.kind === \"node\") {\n return (this.graph.noteIdsByNodeId.get(target.nodeId) ?? [])\n .map((noteId) => this.graph.notesById.get(noteId))\n .filter((note): note is TreeNote => Boolean(note));\n }\n\n const edgeId = makeCorrespondenceId(target.left, target.right);\n\n return (this.graph.noteIdsByCorrespondenceId.get(edgeId) ?? [])\n .map((noteId) => this.graph.notesById.get(noteId))\n .filter((note): note is TreeNote => Boolean(note));\n }\n\n getCorrespondences<T extends NodeType, U extends NodeType = NodeType>(\n nodeId: NodeId<T>,\n options: TreeCorrespondenceQueryOptions<U> = {}\n ): CorrespondenceMatch<U>[] {\n if (!this.graph.nodesById.has(nodeId as NodeId<NodeType>)) {\n return [];\n }\n\n const typeFilter = normalizeTypes(options.type);\n const includeSelf = options.includeSelf ?? false;\n const depth = Math.max(1, options.depth ?? 1);\n const limit = options.limit ?? Infinity;\n\n const previous = new Map<\n NodeId<NodeType>,\n { from: NodeId<NodeType>; edgeId: string }\n >();\n const visited = new Set<NodeId<NodeType>>([nodeId as NodeId<NodeType>]);\n const queue: Array<{ nodeId: NodeId<NodeType>; distance: number }> = [\n {\n nodeId: nodeId as NodeId<NodeType>,\n distance: 0,\n },\n ];\n const matches: CorrespondenceMatch<NodeType>[] = [];\n\n while (queue.length > 0 && matches.length < limit) {\n const current = queue.shift()!;\n\n if (current.distance >= depth) {\n continue;\n }\n\n for (const edgeId of this.graph.edgeIdsByNodeId.get(current.nodeId) ?? []) {\n const edge = this.graph.edgesById.get(edgeId);\n\n if (!edge) {\n continue;\n }\n\n const nextNodeId =\n edge.left === current.nodeId ? edge.right : edge.left;\n\n if (visited.has(nextNodeId)) {\n continue;\n }\n\n visited.add(nextNodeId);\n previous.set(nextNodeId, {\n from: current.nodeId,\n edgeId,\n });\n\n const distance = current.distance + 1;\n const nextNode = this.graph.nodesById.get(nextNodeId);\n\n if (!nextNode) {\n continue;\n }\n\n if ((!typeFilter || typeFilter.has(nextNode.type)) && distance > 0) {\n matches.push({\n node: nextNode,\n distance,\n path: reconstructPath(\n nodeId as NodeId<NodeType>,\n nextNodeId,\n previous,\n this.graph.edgesById\n ),\n });\n }\n\n queue.push({\n nodeId: nextNodeId,\n distance,\n });\n }\n }\n\n if (includeSelf) {\n const sourceNode = this.graph.nodesById.get(nodeId as NodeId<NodeType>);\n\n if (\n sourceNode &&\n (!typeFilter || typeFilter.has(sourceNode.type)) &&\n matches.length < limit\n ) {\n matches.unshift({\n node: sourceNode as Node<U>,\n distance: 0,\n path: [],\n });\n }\n }\n\n return sortMatches(matches as CorrespondenceMatch<U>[]).slice(0, limit);\n }\n\n getCorrespondenceMap<T extends NodeType>(\n nodeId: NodeId<T>,\n options: Omit<TreeCorrespondenceQueryOptions, \"type\"> = {}\n ): CorrespondenceMap {\n const grouped: Record<string, CorrespondenceMatch[]> = {};\n\n for (const match of this.getCorrespondences(nodeId, options)) {\n const typeKey = match.node.type;\n const typeMatches = grouped[typeKey] ?? [];\n typeMatches.push(match as CorrespondenceMatch);\n grouped[typeKey] = typeMatches;\n }\n\n return grouped as CorrespondenceMap;\n }\n\n resolveVisual(request: TreeVisualRequest) {\n for (const resolver of this.visualResolvers) {\n const resolved = resolver({\n request,\n workspace: this,\n });\n\n if (resolved) {\n return resolved;\n }\n }\n\n return undefined;\n }\n}\n\nexport function createTreeWorkspace(\n options: CreateTreeWorkspaceOptions = {}\n) {\n const base = normalizeBase(options.base);\n const overlays = options.overlays ?? [];\n const applied = applyOverlays(base, overlays);\n const descriptor = {\n ...base.descriptor,\n ...options.descriptor,\n };\n\n return new TreeWorkspace(\n createGraphData(descriptor, applied.nodes, applied.edges, applied.notes),\n options.visualResolvers ?? []\n );\n}\n\nexport function getCanonicalTree(\n opts: TreeOptions = {\n system: \"kaabalah\",\n parts: [],\n }\n) {\n const parts = [...(opts.parts ?? [])];\n const cacheKey = `${opts.system}:${parts.join(\",\")}`;\n const cachedTree = canonicalTreeCache.get(cacheKey);\n\n if (cachedTree) {\n return cachedTree;\n }\n\n const tree = createTree({\n system: opts.system,\n parts,\n });\n\n const canonicalTree = createTreeWorkspace({\n base: tree,\n descriptor: buildCanonicalDescriptor(opts, cacheKey),\n });\n\n canonicalTreeCache.set(cacheKey, canonicalTree);\n\n return canonicalTree;\n}\n"]}