kaabalah 6.14.0 → 6.16.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 (117) hide show
  1. package/README.md +15 -0
  2. package/dist/astrology/index.d.mts +39 -1
  3. package/dist/astrology/index.d.ts +39 -1
  4. package/dist/astrology/index.js +75 -53
  5. package/dist/astrology/index.mjs +3 -1
  6. package/dist/chunk-2IC6H3FI.js +1600 -0
  7. package/dist/chunk-2IC6H3FI.js.map +1 -0
  8. package/dist/{chunk-RAQDVWNK.mjs → chunk-3JMY4U4S.mjs} +546 -3
  9. package/dist/chunk-3JMY4U4S.mjs.map +1 -0
  10. package/dist/chunk-3QN5V3DP.js +4737 -0
  11. package/dist/chunk-3QN5V3DP.js.map +1 -0
  12. package/dist/{chunk-UNXDDLZS.js → chunk-6LZOAU6E.js} +548 -3
  13. package/dist/chunk-6LZOAU6E.js.map +1 -0
  14. package/dist/{chunk-LXJ3THNW.mjs → chunk-7JWBIAUF.mjs} +12 -9
  15. package/dist/chunk-7JWBIAUF.mjs.map +1 -0
  16. package/dist/{chunk-Q7YAKPBH.js → chunk-7OWGGDRF.js} +80 -1015
  17. package/dist/chunk-7OWGGDRF.js.map +1 -0
  18. package/dist/{chunk-2WCC2KCJ.js → chunk-BALOSCWQ.mjs} +22 -3
  19. package/dist/chunk-BALOSCWQ.mjs.map +1 -0
  20. package/dist/{chunk-4PVIDUPI.js → chunk-BKFHIKFY.js} +647 -187
  21. package/dist/chunk-BKFHIKFY.js.map +1 -0
  22. package/dist/{chunk-7C7VO76O.js → chunk-CMXTZKWW.js} +574 -147
  23. package/dist/chunk-CMXTZKWW.js.map +1 -0
  24. package/dist/{chunk-6GDEXIDI.js → chunk-HEZCZXQC.js} +25 -22
  25. package/dist/chunk-HEZCZXQC.js.map +1 -0
  26. package/dist/chunk-ICUDGCYX.js +15 -0
  27. package/dist/chunk-ICUDGCYX.js.map +1 -0
  28. package/dist/chunk-IT7GZ337.mjs +4679 -0
  29. package/dist/chunk-IT7GZ337.mjs.map +1 -0
  30. package/dist/{chunk-NOZKIUGP.mjs → chunk-J5Y325TG.mjs} +80 -1015
  31. package/dist/chunk-J5Y325TG.mjs.map +1 -0
  32. package/dist/chunk-JY4QC6FR.js +2214 -0
  33. package/dist/chunk-JY4QC6FR.js.map +1 -0
  34. package/dist/{chunk-URDMOQRN.mjs → chunk-L5EYUE4B.js} +27 -2
  35. package/dist/chunk-L5EYUE4B.js.map +1 -0
  36. package/dist/{chunk-QQN54SLY.mjs → chunk-LQVHJ3VY.mjs} +454 -32
  37. package/dist/chunk-LQVHJ3VY.mjs.map +1 -0
  38. package/dist/{chunk-WA52P72D.mjs → chunk-MWLSSRHL.mjs} +628 -168
  39. package/dist/chunk-MWLSSRHL.mjs.map +1 -0
  40. package/dist/{chunk-CW6QDSMF.js → chunk-PBBF5DKC.js} +88 -21
  41. package/dist/chunk-PBBF5DKC.js.map +1 -0
  42. package/dist/chunk-RUE6NTVT.mjs +2211 -0
  43. package/dist/chunk-RUE6NTVT.mjs.map +1 -0
  44. package/dist/{chunk-X5HGLMEF.mjs → chunk-UO2RQQZO.mjs} +770 -3
  45. package/dist/chunk-UO2RQQZO.mjs.map +1 -0
  46. package/dist/chunk-W2N7STO3.mjs +13 -0
  47. package/dist/chunk-W2N7STO3.mjs.map +1 -0
  48. package/dist/chunk-WP5MRAYG.mjs +6289 -0
  49. package/dist/chunk-WP5MRAYG.mjs.map +1 -0
  50. package/dist/chunk-WRF3EORB.js +6333 -0
  51. package/dist/chunk-WRF3EORB.js.map +1 -0
  52. package/dist/{chunk-OSMB2MJR.mjs → chunk-Z3JZ5DZN.mjs} +68 -3
  53. package/dist/chunk-Z3JZ5DZN.mjs.map +1 -0
  54. package/dist/cli.js +39837 -28550
  55. package/dist/cli.js.map +1 -1
  56. package/dist/core/index.d.mts +24 -1
  57. package/dist/core/index.d.ts +24 -1
  58. package/dist/core/index.js +67 -53
  59. package/dist/core/index.mjs +4 -2
  60. package/dist/{data-BRi5-xg_.d.ts → data-Dle4z75J.d.ts} +1 -1
  61. package/dist/{data-BoQrkrWX.d.mts → data-DvKCOgjb.d.mts} +1 -1
  62. package/dist/gematria/index.d.mts +153 -1
  63. package/dist/gematria/index.d.ts +153 -1
  64. package/dist/gematria/index.js +15 -5
  65. package/dist/gematria/index.mjs +4 -2
  66. package/dist/iching/index.d.mts +802 -30
  67. package/dist/iching/index.d.ts +802 -30
  68. package/dist/iching/index.js +72 -38
  69. package/dist/iching/index.mjs +5 -3
  70. package/dist/ifa/index.d.mts +44 -1
  71. package/dist/ifa/index.d.ts +44 -1
  72. package/dist/ifa/index.js +11 -2
  73. package/dist/ifa/index.mjs +2 -1
  74. package/dist/index.d.mts +8 -8
  75. package/dist/index.d.ts +8 -8
  76. package/dist/index.js +375 -265
  77. package/dist/index.mjs +12 -10
  78. package/dist/numerology/index.d.mts +872 -1
  79. package/dist/numerology/index.d.ts +872 -1
  80. package/dist/numerology/index.js +28 -18
  81. package/dist/numerology/index.mjs +5 -3
  82. package/dist/semantic/index.d.mts +94 -17
  83. package/dist/semantic/index.d.ts +94 -17
  84. package/dist/semantic/index.js +57 -35
  85. package/dist/semantic/index.mjs +9 -7
  86. package/dist/tarot/index.d.mts +15 -10
  87. package/dist/tarot/index.d.ts +15 -10
  88. package/dist/tarot/index.js +32 -30
  89. package/dist/tarot/index.mjs +5 -3
  90. package/dist/visual/index.js +48 -46
  91. package/dist/visual/index.mjs +5 -3
  92. package/package.json +7 -3
  93. package/dist/chunk-2WCC2KCJ.js.map +0 -1
  94. package/dist/chunk-47BAJUYW.js +0 -830
  95. package/dist/chunk-47BAJUYW.js.map +0 -1
  96. package/dist/chunk-4PVIDUPI.js.map +0 -1
  97. package/dist/chunk-6GDEXIDI.js.map +0 -1
  98. package/dist/chunk-7C7VO76O.js.map +0 -1
  99. package/dist/chunk-CW6QDSMF.js.map +0 -1
  100. package/dist/chunk-LXJ3THNW.mjs.map +0 -1
  101. package/dist/chunk-NOZKIUGP.mjs.map +0 -1
  102. package/dist/chunk-OSMB2MJR.mjs.map +0 -1
  103. package/dist/chunk-OZUEDZ4U.mjs +0 -3699
  104. package/dist/chunk-OZUEDZ4U.mjs.map +0 -1
  105. package/dist/chunk-PEHDLSUH.mjs +0 -2227
  106. package/dist/chunk-PEHDLSUH.mjs.map +0 -1
  107. package/dist/chunk-Q7YAKPBH.js.map +0 -1
  108. package/dist/chunk-QQN54SLY.mjs.map +0 -1
  109. package/dist/chunk-RAQDVWNK.mjs.map +0 -1
  110. package/dist/chunk-SWWLTDR6.js +0 -2280
  111. package/dist/chunk-SWWLTDR6.js.map +0 -1
  112. package/dist/chunk-UNXDDLZS.js.map +0 -1
  113. package/dist/chunk-URDMOQRN.mjs.map +0 -1
  114. package/dist/chunk-WA52P72D.mjs.map +0 -1
  115. package/dist/chunk-X5HGLMEF.mjs.map +0 -1
  116. package/dist/chunk-XWVT3SI7.js +0 -3735
  117. package/dist/chunk-XWVT3SI7.js.map +0 -1
@@ -1,830 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkQ7YAKPBH_js = require('./chunk-Q7YAKPBH.js');
4
-
5
- // src/core/topology.ts
6
- var TREE_TOPOLOGY_SPHERE_NAMES = [
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
- ];
19
- var TREE_TOPOLOGY_SPHERE_IDS = TREE_TOPOLOGY_SPHERE_NAMES.map(
20
- (name) => chunkQ7YAKPBH_js.id("sphere" /* SPHERE */, name)
21
- );
22
- var TREE_TOPOLOGY_PATH_IDS = Array.from(
23
- { length: 22 },
24
- (_, index) => chunkQ7YAKPBH_js.id("path" /* PATH */, index + 1)
25
- );
26
- var TREE_TOPOLOGY_SPHERE_NUMBERS = {
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
- };
39
- var TREE_TOPOLOGY_LIGHTNING_SPHERE_NAMES = [
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
- ];
51
- var topologyCache = /* @__PURE__ */ new Map();
52
- function isNodeType(node, type) {
53
- return node.type === type;
54
- }
55
- function cloneSphereData(data) {
56
- return data ? { ...data } : void 0;
57
- }
58
- function clonePathData(data) {
59
- return { ...data };
60
- }
61
- function parsePathNumber(pathId) {
62
- const parsed = Number.parseInt(chunkQ7YAKPBH_js.parseId(pathId), 10);
63
- if (!Number.isInteger(parsed)) {
64
- throw new Error(`Invalid tree path id: ${pathId}`);
65
- }
66
- return parsed;
67
- }
68
- function normalizeName(value) {
69
- return value.trim().toLowerCase();
70
- }
71
- function pairKey(left, right) {
72
- return [String(left), String(right)].sort().join("|");
73
- }
74
- function routeNames() {
75
- return [...TREE_TOPOLOGY_LIGHTNING_SPHERE_NAMES];
76
- }
77
- function routeDescriptor(key) {
78
- return key === "lightning" ? {
79
- name: "Lightning Path",
80
- direction: "descending"
81
- } : {
82
- name: "Serpent Path",
83
- direction: "ascending"
84
- };
85
- }
86
- function routeTargetList(segments) {
87
- if (segments.length === 0) {
88
- return [];
89
- }
90
- const targets = [
91
- { targetId: segments[0].from.id, targetType: "sphere" }
92
- ];
93
- for (const segment of segments) {
94
- if (segment.path) {
95
- targets.push({ targetId: segment.path.id, targetType: "path" });
96
- }
97
- targets.push({ targetId: segment.to.id, targetType: "sphere" });
98
- }
99
- return targets;
100
- }
101
- var TreeTopology = class {
102
- constructor({
103
- system,
104
- spheres,
105
- paths
106
- }) {
107
- this.spheresById = /* @__PURE__ */ new Map();
108
- this.spheresByName = /* @__PURE__ */ new Map();
109
- this.spheresByNumber = /* @__PURE__ */ new Map();
110
- this.pathsById = /* @__PURE__ */ new Map();
111
- this.pathsByNumber = /* @__PURE__ */ new Map();
112
- this.pathsBySpherePair = /* @__PURE__ */ new Map();
113
- this.pathsBySphereId = /* @__PURE__ */ new Map();
114
- this.routesByKey = /* @__PURE__ */ new Map();
115
- this.system = system;
116
- this.spheres = spheres.map(
117
- (sphere) => Object.freeze({
118
- ...sphere,
119
- data: cloneSphereData(sphere.data)
120
- })
121
- );
122
- for (const sphere of this.spheres) {
123
- this.spheresById.set(sphere.id, sphere);
124
- this.spheresByName.set(normalizeName(sphere.name), sphere);
125
- this.spheresByNumber.set(sphere.number, sphere);
126
- }
127
- this.paths = paths.map((path) => {
128
- const from = this.spheresById.get(path.from.id);
129
- const to = this.spheresById.get(path.to.id);
130
- if (!from || !to) {
131
- throw new Error(
132
- `Tree topology path ${path.id} references unknown spheres.`
133
- );
134
- }
135
- return Object.freeze({
136
- ...path,
137
- from,
138
- to,
139
- data: clonePathData(path.data)
140
- });
141
- });
142
- for (const path of this.paths) {
143
- this.pathsById.set(path.id, path);
144
- this.pathsByNumber.set(path.number, path);
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
- }
151
- }
152
- for (const key of ["lightning", "serpent"]) {
153
- this.routesByKey.set(key, this.buildRoute(key));
154
- }
155
- }
156
- getSpheres(options = {}) {
157
- const includeDaath = options.includeDaath ?? true;
158
- return includeDaath ? [...this.spheres] : this.spheres.filter((sphere) => sphere.name !== chunkQ7YAKPBH_js.SPHERES.DAATH);
159
- }
160
- getPrimarySpheres() {
161
- return this.getSpheres({ includeDaath: false });
162
- }
163
- getSphere(lookup) {
164
- if (typeof lookup === "string") {
165
- if (lookup.startsWith(`${"sphere" /* SPHERE */}:`)) {
166
- return this.spheresById.get(lookup);
167
- }
168
- return this.spheresByName.get(normalizeName(lookup));
169
- }
170
- if (lookup.id) {
171
- return this.spheresById.get(lookup.id);
172
- }
173
- if (lookup.number) {
174
- return this.spheresByNumber.get(lookup.number);
175
- }
176
- if (lookup.name) {
177
- return this.spheresByName.get(normalizeName(lookup.name));
178
- }
179
- return void 0;
180
- }
181
- getPaths() {
182
- return [...this.paths];
183
- }
184
- getPath(lookup) {
185
- if (typeof lookup === "number") {
186
- return this.pathsByNumber.get(lookup);
187
- }
188
- if (typeof lookup === "string") {
189
- return this.pathsById.get(lookup);
190
- }
191
- if (lookup.id) {
192
- return this.pathsById.get(lookup.id);
193
- }
194
- if (lookup.number) {
195
- return this.pathsByNumber.get(lookup.number);
196
- }
197
- if (lookup.between) {
198
- return this.getPathBetween(lookup.between[0], lookup.between[1]);
199
- }
200
- return void 0;
201
- }
202
- getPathBetween(first, second) {
203
- const firstSphere = this.getSphere(first);
204
- const secondSphere = this.getSphere(second);
205
- if (!firstSphere || !secondSphere) {
206
- return void 0;
207
- }
208
- return this.pathsBySpherePair.get(pairKey(firstSphere.id, secondSphere.id));
209
- }
210
- getAdjacentSpheres(sphereLookup) {
211
- const sphere = this.getSphere(sphereLookup);
212
- if (!sphere) {
213
- return [];
214
- }
215
- return (this.pathsBySphereId.get(sphere.id) ?? []).map((path) => {
216
- const isForward = path.from.id === sphere.id;
217
- return {
218
- sphere: isForward ? path.to : path.from,
219
- path,
220
- direction: isForward ? "forward" : "reverse"
221
- };
222
- });
223
- }
224
- getRoutes() {
225
- return [...this.routesByKey.values()];
226
- }
227
- getRoute(key) {
228
- return this.routesByKey.get(key);
229
- }
230
- nextInRoute(routeKey, sphereLookup) {
231
- const route = this.getRoute(routeKey);
232
- const sphere = this.getSphere(sphereLookup);
233
- if (!route || !sphere) {
234
- return void 0;
235
- }
236
- const index = route.spheres.findIndex(
237
- (routeSphere) => routeSphere.id === sphere.id
238
- );
239
- return index >= 0 ? route.spheres[index + 1] : void 0;
240
- }
241
- previousInRoute(routeKey, sphereLookup) {
242
- const route = this.getRoute(routeKey);
243
- const sphere = this.getSphere(sphereLookup);
244
- if (!route || !sphere) {
245
- return void 0;
246
- }
247
- const index = route.spheres.findIndex(
248
- (routeSphere) => routeSphere.id === sphere.id
249
- );
250
- return index > 0 ? route.spheres[index - 1] : void 0;
251
- }
252
- buildRoute(key) {
253
- const descriptor = routeDescriptor(key);
254
- const names = routeNames();
255
- const orderedNames = key === "serpent" ? names.reverse() : names;
256
- const spheres = orderedNames.map((name) => {
257
- const sphere = this.getSphere(name);
258
- if (!sphere) {
259
- throw new Error(
260
- `Tree topology route "${key}" references missing sphere "${name}" in ${this.system}.`
261
- );
262
- }
263
- return sphere;
264
- });
265
- const segments = [];
266
- for (let index = 0; index < spheres.length - 1; index++) {
267
- const from = spheres[index];
268
- const to = spheres[index + 1];
269
- const path = this.getPathBetween(from.name, to.name);
270
- segments.push({
271
- index,
272
- from,
273
- to,
274
- path,
275
- isConnected: Boolean(path)
276
- });
277
- }
278
- const targets = routeTargetList(segments);
279
- const missingSegments = segments.filter((segment) => !segment.isConnected);
280
- return Object.freeze({
281
- key,
282
- name: descriptor.name,
283
- direction: descriptor.direction,
284
- spheres: Object.freeze([...spheres]),
285
- segments: Object.freeze(segments),
286
- isFullyConnected: missingSegments.length === 0,
287
- missingSegments: Object.freeze(missingSegments),
288
- targets: Object.freeze(targets),
289
- targetIds: Object.freeze(targets.map((target) => target.targetId))
290
- });
291
- }
292
- };
293
- function getTreeTopology(options = {}) {
294
- const system = options.system ?? options.tree?.activeSystem ?? "kaabalah";
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 });
301
- const spheres = [];
302
- for (const sphereId of TREE_TOPOLOGY_SPHERE_IDS) {
303
- const sphereNode = tree.getNode(sphereId);
304
- if (!sphereNode) {
305
- continue;
306
- }
307
- const name = chunkQ7YAKPBH_js.parseId(sphereId);
308
- spheres.push({
309
- id: sphereId,
310
- name,
311
- number: TREE_TOPOLOGY_SPHERE_NUMBERS[name],
312
- role: name === chunkQ7YAKPBH_js.SPHERES.DAATH ? "hidden" : "sephirah",
313
- data: cloneSphereData(sphereNode.data)
314
- });
315
- }
316
- const spheresById = new Map(spheres.map((sphere) => [sphere.id, sphere]));
317
- const paths = tree.getNodes().filter(
318
- (node) => isNodeType(node, "path" /* PATH */)
319
- ).map((pathNode) => {
320
- if (!pathNode.data?.from || !pathNode.data?.to) {
321
- throw new Error(`Tree topology path ${pathNode.id} is missing endpoints.`);
322
- }
323
- const from = spheresById.get(pathNode.data.from);
324
- const to = spheresById.get(pathNode.data.to);
325
- if (!from || !to) {
326
- throw new Error(
327
- `Tree topology path ${pathNode.id} references unknown spheres.`
328
- );
329
- }
330
- return {
331
- id: pathNode.id,
332
- number: parsePathNumber(pathNode.id),
333
- from,
334
- to,
335
- data: clonePathData(pathNode.data)
336
- };
337
- }).sort((left, right) => left.number - right.number);
338
- const topology = new TreeTopology({
339
- system,
340
- spheres,
341
- paths
342
- });
343
- if (!options.tree) {
344
- topologyCache.set(system, topology);
345
- }
346
- return topology;
347
- }
348
-
349
- // src/core/workspace.ts
350
- function cloneNode(node) {
351
- return Object.freeze({
352
- id: node.id,
353
- type: node.type,
354
- name: node.name,
355
- data: node.data && typeof node.data === "object" ? { ...node.data } : node.data
356
- });
357
- }
358
- function cloneEdge(edge) {
359
- return Object.freeze({
360
- ...edge,
361
- metadata: chunkQ7YAKPBH_js.cloneMetadata(edge.metadata),
362
- sources: edge.sources.map(chunkQ7YAKPBH_js.cloneSource)
363
- });
364
- }
365
- function cloneNote(note) {
366
- return Object.freeze({
367
- ...note,
368
- target: { ...note.target },
369
- metadata: note.metadata ? { ...note.metadata } : void 0
370
- });
371
- }
372
- function normalizeTypes(type) {
373
- if (!type) {
374
- return void 0;
375
- }
376
- return new Set(Array.isArray(type) ? type : [type]);
377
- }
378
- function sortNodes(nodes) {
379
- return [...nodes].sort((left, right) => {
380
- if (left.type !== right.type) {
381
- return left.type.localeCompare(right.type);
382
- }
383
- const leftLabel = String(left.name ?? left.id);
384
- const rightLabel = String(right.name ?? right.id);
385
- return leftLabel.localeCompare(rightLabel);
386
- });
387
- }
388
- function sortMatches(matches) {
389
- return [...matches].sort((left, right) => {
390
- if (left.distance !== right.distance) {
391
- return left.distance - right.distance;
392
- }
393
- if (left.node.type !== right.node.type) {
394
- return left.node.type.localeCompare(right.node.type);
395
- }
396
- const leftLabel = String(left.node.name ?? left.node.id);
397
- const rightLabel = String(right.node.name ?? right.node.id);
398
- return leftLabel.localeCompare(rightLabel);
399
- });
400
- }
401
- function createGraphData(descriptor, nodes, edges, notes) {
402
- const nodesById = /* @__PURE__ */ new Map();
403
- const nodeIdsByType = /* @__PURE__ */ new Map();
404
- const edgesById = /* @__PURE__ */ new Map();
405
- const edgeIdsByNodeId = /* @__PURE__ */ new Map();
406
- const notesById = /* @__PURE__ */ new Map();
407
- const noteIdsByNodeId = /* @__PURE__ */ new Map();
408
- const noteIdsByCorrespondenceId = /* @__PURE__ */ new Map();
409
- for (const node of nodes) {
410
- const clonedNode = cloneNode(node);
411
- nodesById.set(clonedNode.id, clonedNode);
412
- const typedIds = nodeIdsByType.get(clonedNode.type) ?? [];
413
- typedIds.push(clonedNode.id);
414
- nodeIdsByType.set(clonedNode.type, typedIds);
415
- }
416
- for (const edge of edges) {
417
- const clonedEdge = cloneEdge(edge);
418
- edgesById.set(clonedEdge.id, clonedEdge);
419
- const leftEdges = edgeIdsByNodeId.get(clonedEdge.left) ?? [];
420
- leftEdges.push(clonedEdge.id);
421
- edgeIdsByNodeId.set(clonedEdge.left, leftEdges);
422
- const rightEdges = edgeIdsByNodeId.get(clonedEdge.right) ?? [];
423
- rightEdges.push(clonedEdge.id);
424
- edgeIdsByNodeId.set(clonedEdge.right, rightEdges);
425
- }
426
- for (const note of notes) {
427
- const clonedNote = cloneNote(note);
428
- notesById.set(clonedNote.id, clonedNote);
429
- if (clonedNote.target.kind === "node") {
430
- const nodeNoteIds = noteIdsByNodeId.get(clonedNote.target.nodeId) ?? [];
431
- nodeNoteIds.push(clonedNote.id);
432
- noteIdsByNodeId.set(clonedNote.target.nodeId, nodeNoteIds);
433
- continue;
434
- }
435
- const edgeId = chunkQ7YAKPBH_js.makeCorrespondenceId(
436
- clonedNote.target.left,
437
- clonedNote.target.right
438
- );
439
- const correspondenceNoteIds = noteIdsByCorrespondenceId.get(edgeId) ?? [];
440
- correspondenceNoteIds.push(clonedNote.id);
441
- noteIdsByCorrespondenceId.set(edgeId, correspondenceNoteIds);
442
- }
443
- for (const ids of nodeIdsByType.values()) {
444
- ids.sort((left, right) => String(left).localeCompare(String(right)));
445
- }
446
- for (const ids of edgeIdsByNodeId.values()) {
447
- ids.sort((left, right) => left.localeCompare(right));
448
- }
449
- for (const ids of noteIdsByNodeId.values()) {
450
- ids.sort((left, right) => left.localeCompare(right));
451
- }
452
- for (const ids of noteIdsByCorrespondenceId.values()) {
453
- ids.sort((left, right) => left.localeCompare(right));
454
- }
455
- return {
456
- descriptor: Object.freeze({ ...descriptor }),
457
- nodesById,
458
- nodeIdsByType,
459
- edgesById,
460
- edgeIdsByNodeId,
461
- notesById,
462
- noteIdsByNodeId,
463
- noteIdsByCorrespondenceId
464
- };
465
- }
466
- function normalizeBase(base) {
467
- if (!base) {
468
- return {
469
- descriptor: {},
470
- nodes: [],
471
- edges: [],
472
- notes: []
473
- };
474
- }
475
- if (base instanceof TreeWorkspace) {
476
- return {
477
- descriptor: base.descriptor,
478
- nodes: base.getNodes(),
479
- edges: base.getEdges(),
480
- notes: base.getNotes()
481
- };
482
- }
483
- return {
484
- descriptor: {
485
- system: base.activeSystem ?? void 0,
486
- parts: base.loadedParts.filter((part) => part !== "base")
487
- },
488
- nodes: base.getNodes(),
489
- edges: base.getEdges(),
490
- notes: []
491
- };
492
- }
493
- function applyOverlays(base, overlays) {
494
- const nodesById = /* @__PURE__ */ new Map();
495
- const edgesById = /* @__PURE__ */ new Map();
496
- const notes = [];
497
- for (const node of base.nodes) {
498
- nodesById.set(node.id, cloneNode(node));
499
- }
500
- for (const edge of base.edges) {
501
- edgesById.set(edge.id, cloneEdge(edge));
502
- }
503
- for (const note of base.notes) {
504
- notes.push(cloneNote(note));
505
- }
506
- for (const overlay of overlays) {
507
- for (const node of overlay.nodes ?? []) {
508
- const existing = nodesById.get(node.id);
509
- if (existing && existing.type !== node.type) {
510
- throw new Error(
511
- `Overlay ${overlay.id} tried to upsert ${node.id} with a different type`
512
- );
513
- }
514
- nodesById.set(
515
- node.id,
516
- cloneNode(
517
- existing ? {
518
- ...existing,
519
- ...node,
520
- data: {
521
- ...existing.data ?? {},
522
- ...node.data ?? {}
523
- }
524
- } : node
525
- )
526
- );
527
- }
528
- for (const correspondence of overlay.correspondences ?? []) {
529
- if (!nodesById.has(correspondence.left) || !nodesById.has(correspondence.right)) {
530
- throw new Error(
531
- `Overlay ${overlay.id} references unknown nodes in ${correspondence.left} <-> ${correspondence.right}`
532
- );
533
- }
534
- const edgeId = chunkQ7YAKPBH_js.makeCorrespondenceId(
535
- correspondence.left,
536
- correspondence.right
537
- );
538
- if (correspondence.op === "remove") {
539
- edgesById.delete(edgeId);
540
- continue;
541
- }
542
- const existingEdge = edgesById.get(edgeId);
543
- const overlaySource = {
544
- kind: "overlay",
545
- overlayId: overlay.id,
546
- label: overlay.name
547
- };
548
- if (!existingEdge) {
549
- if (correspondence.op !== "add") {
550
- throw new Error(
551
- `Overlay ${overlay.id} cannot annotate missing correspondence ${edgeId}`
552
- );
553
- }
554
- edgesById.set(
555
- edgeId,
556
- cloneEdge({
557
- id: edgeId,
558
- left: correspondence.left,
559
- right: correspondence.right,
560
- metadata: chunkQ7YAKPBH_js.cloneMetadata(correspondence.metadata),
561
- sources: [overlaySource]
562
- })
563
- );
564
- continue;
565
- }
566
- edgesById.set(
567
- edgeId,
568
- cloneEdge({
569
- ...existingEdge,
570
- metadata: chunkQ7YAKPBH_js.mergeMetadata(existingEdge.metadata, correspondence.metadata),
571
- sources: chunkQ7YAKPBH_js.mergeSources(existingEdge.sources, overlaySource)
572
- })
573
- );
574
- }
575
- for (const note of overlay.notes ?? []) {
576
- notes.push(
577
- cloneNote({
578
- ...note,
579
- metadata: note.metadata ? { ...note.metadata } : void 0
580
- })
581
- );
582
- }
583
- }
584
- const filteredNotes = notes.filter((note) => {
585
- if (note.target.kind === "node") {
586
- return nodesById.has(note.target.nodeId);
587
- }
588
- return edgesById.has(
589
- chunkQ7YAKPBH_js.makeCorrespondenceId(note.target.left, note.target.right)
590
- );
591
- });
592
- return {
593
- nodes: [...nodesById.values()],
594
- edges: [...edgesById.values()],
595
- notes: filteredNotes
596
- };
597
- }
598
- function reconstructPath(startId, targetId, previous, edgesById) {
599
- const steps = [];
600
- let current = targetId;
601
- while (current !== startId) {
602
- const link = previous.get(current);
603
- if (!link) {
604
- break;
605
- }
606
- const edge = edgesById.get(link.edgeId);
607
- if (!edge) {
608
- break;
609
- }
610
- steps.push({
611
- from: link.from,
612
- to: current,
613
- edge
614
- });
615
- current = link.from;
616
- }
617
- return steps.reverse();
618
- }
619
- function buildCanonicalDescriptor(opts, cacheKey) {
620
- return {
621
- id: `canonical:${cacheKey}`,
622
- name: "Canonical Tree",
623
- system: opts.system,
624
- parts: [...opts.parts ?? []],
625
- cacheKey
626
- };
627
- }
628
- var canonicalTreeCache = /* @__PURE__ */ new Map();
629
- var TreeWorkspace = class {
630
- constructor(graph, visualResolvers = []) {
631
- this.graph = graph;
632
- this.visualResolvers = visualResolvers;
633
- this.descriptor = graph.descriptor;
634
- }
635
- getNode(id2) {
636
- return this.graph.nodesById.get(id2);
637
- }
638
- hasNode(id2) {
639
- return this.graph.nodesById.has(id2);
640
- }
641
- getNodes(type) {
642
- if (!type) {
643
- return sortNodes(
644
- [...this.graph.nodesById.values()]
645
- );
646
- }
647
- const ids = this.graph.nodeIdsByType.get(type) ?? [];
648
- return ids.map((id2) => this.graph.nodesById.get(id2)).filter((node) => Boolean(node));
649
- }
650
- findNodes(options = {}) {
651
- const typeFilter = normalizeTypes(options.type);
652
- const search = options.search?.trim().toLowerCase();
653
- const candidates = options.ids ? options.ids.map((id2) => this.graph.nodesById.get(id2)).filter((node) => Boolean(node)) : typeFilter ? [...typeFilter].flatMap((type) => this.getNodes(type)) : this.getNodes();
654
- return sortNodes(
655
- candidates.filter((node) => {
656
- if (typeFilter && !typeFilter.has(node.type)) {
657
- return false;
658
- }
659
- if (search) {
660
- const haystacks = [
661
- String(node.id).toLowerCase(),
662
- String(node.name ?? "").toLowerCase()
663
- ];
664
- if (!haystacks.some((value) => value.includes(search))) {
665
- return false;
666
- }
667
- }
668
- return options.predicate ? options.predicate(node) : true;
669
- })
670
- );
671
- }
672
- getEdge(left, right) {
673
- return this.graph.edgesById.get(chunkQ7YAKPBH_js.makeCorrespondenceId(left, right));
674
- }
675
- getEdges(nodeId) {
676
- if (!nodeId) {
677
- return [...this.graph.edgesById.values()];
678
- }
679
- return (this.graph.edgeIdsByNodeId.get(nodeId) ?? []).map((edgeId) => this.graph.edgesById.get(edgeId)).filter((edge) => Boolean(edge));
680
- }
681
- getNotes(target) {
682
- if (!target) {
683
- return [...this.graph.notesById.values()];
684
- }
685
- if (target.kind === "node") {
686
- return (this.graph.noteIdsByNodeId.get(target.nodeId) ?? []).map((noteId) => this.graph.notesById.get(noteId)).filter((note) => Boolean(note));
687
- }
688
- const edgeId = chunkQ7YAKPBH_js.makeCorrespondenceId(target.left, target.right);
689
- return (this.graph.noteIdsByCorrespondenceId.get(edgeId) ?? []).map((noteId) => this.graph.notesById.get(noteId)).filter((note) => Boolean(note));
690
- }
691
- getCorrespondences(nodeId, options = {}) {
692
- if (!this.graph.nodesById.has(nodeId)) {
693
- return [];
694
- }
695
- const typeFilter = normalizeTypes(options.type);
696
- const includeSelf = options.includeSelf ?? false;
697
- const depth = Math.max(1, options.depth ?? 1);
698
- const limit = options.limit ?? Infinity;
699
- const previous = /* @__PURE__ */ new Map();
700
- const visited = /* @__PURE__ */ new Set([nodeId]);
701
- const queue = [
702
- {
703
- nodeId,
704
- distance: 0
705
- }
706
- ];
707
- const matches = [];
708
- while (queue.length > 0 && matches.length < limit) {
709
- const current = queue.shift();
710
- if (current.distance >= depth) {
711
- continue;
712
- }
713
- for (const edgeId of this.graph.edgeIdsByNodeId.get(current.nodeId) ?? []) {
714
- const edge = this.graph.edgesById.get(edgeId);
715
- if (!edge) {
716
- continue;
717
- }
718
- const nextNodeId = edge.left === current.nodeId ? edge.right : edge.left;
719
- if (visited.has(nextNodeId)) {
720
- continue;
721
- }
722
- visited.add(nextNodeId);
723
- previous.set(nextNodeId, {
724
- from: current.nodeId,
725
- edgeId
726
- });
727
- const distance = current.distance + 1;
728
- const nextNode = this.graph.nodesById.get(nextNodeId);
729
- if (!nextNode) {
730
- continue;
731
- }
732
- if ((!typeFilter || typeFilter.has(nextNode.type)) && distance > 0) {
733
- matches.push({
734
- node: nextNode,
735
- distance,
736
- path: reconstructPath(
737
- nodeId,
738
- nextNodeId,
739
- previous,
740
- this.graph.edgesById
741
- )
742
- });
743
- }
744
- queue.push({
745
- nodeId: nextNodeId,
746
- distance
747
- });
748
- }
749
- }
750
- if (includeSelf) {
751
- const sourceNode = this.graph.nodesById.get(nodeId);
752
- if (sourceNode && (!typeFilter || typeFilter.has(sourceNode.type)) && matches.length < limit) {
753
- matches.unshift({
754
- node: sourceNode,
755
- distance: 0,
756
- path: []
757
- });
758
- }
759
- }
760
- return sortMatches(matches).slice(0, limit);
761
- }
762
- getCorrespondenceMap(nodeId, options = {}) {
763
- const grouped = {};
764
- for (const match of this.getCorrespondences(nodeId, options)) {
765
- const typeKey = match.node.type;
766
- const typeMatches = grouped[typeKey] ?? [];
767
- typeMatches.push(match);
768
- grouped[typeKey] = typeMatches;
769
- }
770
- return grouped;
771
- }
772
- resolveVisual(request) {
773
- for (const resolver of this.visualResolvers) {
774
- const resolved = resolver({
775
- request,
776
- workspace: this
777
- });
778
- if (resolved) {
779
- return resolved;
780
- }
781
- }
782
- return void 0;
783
- }
784
- };
785
- function createTreeWorkspace(options = {}) {
786
- const base = normalizeBase(options.base);
787
- const overlays = options.overlays ?? [];
788
- const applied = applyOverlays(base, overlays);
789
- const descriptor = {
790
- ...base.descriptor,
791
- ...options.descriptor
792
- };
793
- return new TreeWorkspace(
794
- createGraphData(descriptor, applied.nodes, applied.edges, applied.notes),
795
- options.visualResolvers ?? []
796
- );
797
- }
798
- function getCanonicalTree(opts = {
799
- system: "kaabalah",
800
- parts: []
801
- }) {
802
- const parts = [...opts.parts ?? []];
803
- const cacheKey = `${opts.system}:${parts.join(",")}`;
804
- const cachedTree = canonicalTreeCache.get(cacheKey);
805
- if (cachedTree) {
806
- return cachedTree;
807
- }
808
- const tree = chunkQ7YAKPBH_js.createTree({
809
- system: opts.system,
810
- parts
811
- });
812
- const canonicalTree = createTreeWorkspace({
813
- base: tree,
814
- descriptor: buildCanonicalDescriptor(opts, cacheKey)
815
- });
816
- canonicalTreeCache.set(cacheKey, canonicalTree);
817
- return canonicalTree;
818
- }
819
-
820
- exports.TREE_TOPOLOGY_LIGHTNING_SPHERE_NAMES = TREE_TOPOLOGY_LIGHTNING_SPHERE_NAMES;
821
- exports.TREE_TOPOLOGY_PATH_IDS = TREE_TOPOLOGY_PATH_IDS;
822
- exports.TREE_TOPOLOGY_SPHERE_IDS = TREE_TOPOLOGY_SPHERE_IDS;
823
- exports.TREE_TOPOLOGY_SPHERE_NAMES = TREE_TOPOLOGY_SPHERE_NAMES;
824
- exports.TreeTopology = TreeTopology;
825
- exports.TreeWorkspace = TreeWorkspace;
826
- exports.createTreeWorkspace = createTreeWorkspace;
827
- exports.getCanonicalTree = getCanonicalTree;
828
- exports.getTreeTopology = getTreeTopology;
829
- //# sourceMappingURL=out.js.map
830
- //# sourceMappingURL=chunk-47BAJUYW.js.map