@expertrees/core 0.1.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.
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +428 -0
- package/dist/index.js +882 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,882 @@
|
|
|
1
|
+
import E from "graphology";
|
|
2
|
+
import { forceSimulation as A, forceLink as z, forceManyBody as T, forceCenter as Z, forceCollide as D } from "d3-force";
|
|
3
|
+
class S {
|
|
4
|
+
constructor(t) {
|
|
5
|
+
this._listeners = /* @__PURE__ */ new Map(), this._id = t.id, this._label = t.label, this._meta = t.meta, this._graph = new E({ multi: !1, allowSelfLoops: !1 });
|
|
6
|
+
for (const e of t.nodes)
|
|
7
|
+
this._graph.addNode(e.id, { ...e });
|
|
8
|
+
for (const e of t.edges)
|
|
9
|
+
e.directed ? this._graph.addDirectedEdge(e.source, e.target, { ...e }) : this._graph.addUndirectedEdge(e.source, e.target, { ...e });
|
|
10
|
+
}
|
|
11
|
+
// ─── Accessors ──────────────────────────────────────────────────────────────
|
|
12
|
+
get id() {
|
|
13
|
+
return this._id;
|
|
14
|
+
}
|
|
15
|
+
get label() {
|
|
16
|
+
return this._label;
|
|
17
|
+
}
|
|
18
|
+
get meta() {
|
|
19
|
+
return this._meta;
|
|
20
|
+
}
|
|
21
|
+
getNode(t) {
|
|
22
|
+
if (this._graph.hasNode(t))
|
|
23
|
+
return this._graph.getNodeAttributes(t);
|
|
24
|
+
}
|
|
25
|
+
getEdge(t) {
|
|
26
|
+
if (this._graph.hasEdge(t))
|
|
27
|
+
return this._graph.getEdgeAttributes(t);
|
|
28
|
+
}
|
|
29
|
+
getNodes() {
|
|
30
|
+
return this._graph.nodes().map((t) => this._graph.getNodeAttributes(t));
|
|
31
|
+
}
|
|
32
|
+
getEdges() {
|
|
33
|
+
return this._graph.edges().map((t) => this._graph.getEdgeAttributes(t));
|
|
34
|
+
}
|
|
35
|
+
getChildren(t) {
|
|
36
|
+
const e = this.getNode(t);
|
|
37
|
+
return e != null && e.childIds ? e.childIds.flatMap((s) => {
|
|
38
|
+
const i = this.getNode(s);
|
|
39
|
+
return i ? [i] : [];
|
|
40
|
+
}) : [];
|
|
41
|
+
}
|
|
42
|
+
getNodesAtDepth(t) {
|
|
43
|
+
return this.getNodes().filter((e) => e.depth === t);
|
|
44
|
+
}
|
|
45
|
+
getNodesUpToDepth(t) {
|
|
46
|
+
return this.getNodes().filter((e) => e.depth <= t);
|
|
47
|
+
}
|
|
48
|
+
// ─── Mutations ──────────────────────────────────────────────────────────────
|
|
49
|
+
setNodeState(t, e) {
|
|
50
|
+
this._graph.hasNode(t) && (this._graph.mergeNodeAttributes(t, { state: e }), this._emit("nodeStateChanged", { nodeId: t, state: e }), this._emit("changed", void 0));
|
|
51
|
+
}
|
|
52
|
+
addNode(t) {
|
|
53
|
+
this._graph.addNode(t.id, { ...t }), this._emit("nodeAdded", { node: t }), this._emit("changed", void 0);
|
|
54
|
+
}
|
|
55
|
+
removeNode(t) {
|
|
56
|
+
this._graph.hasNode(t) && (this._graph.dropNode(t), this._emit("nodeRemoved", { nodeId: t }), this._emit("changed", void 0));
|
|
57
|
+
}
|
|
58
|
+
addEdge(t) {
|
|
59
|
+
t.directed ? this._graph.addDirectedEdge(t.source, t.target, { ...t }) : this._graph.addUndirectedEdge(t.source, t.target, { ...t }), this._emit("edgeAdded", { edge: t }), this._emit("changed", void 0);
|
|
60
|
+
}
|
|
61
|
+
removeEdge(t) {
|
|
62
|
+
this._graph.hasEdge(t) && (this._graph.dropEdge(t), this._emit("edgeRemoved", { edgeId: t }), this._emit("changed", void 0));
|
|
63
|
+
}
|
|
64
|
+
addEvidence(t, e) {
|
|
65
|
+
if (!this._graph.hasNode(t)) return;
|
|
66
|
+
const i = this.getNode(t).evidence ?? [];
|
|
67
|
+
this._graph.mergeNodeAttributes(t, { evidence: [...i, e] }), this._emit("evidenceAdded", { nodeId: t, evidence: e }), this._emit("changed", void 0);
|
|
68
|
+
}
|
|
69
|
+
removeEvidence(t, e) {
|
|
70
|
+
if (!this._graph.hasNode(t)) return;
|
|
71
|
+
const i = (this.getNode(t).evidence ?? []).filter((o) => o.id !== e);
|
|
72
|
+
this._graph.mergeNodeAttributes(t, { evidence: i }), this._emit("evidenceRemoved", { nodeId: t, evidenceId: e }), this._emit("changed", void 0);
|
|
73
|
+
}
|
|
74
|
+
// ─── Serialization ──────────────────────────────────────────────────────────
|
|
75
|
+
toJSON() {
|
|
76
|
+
const t = {
|
|
77
|
+
id: this._id,
|
|
78
|
+
label: this._label,
|
|
79
|
+
nodes: this.getNodes(),
|
|
80
|
+
edges: this.getEdges()
|
|
81
|
+
};
|
|
82
|
+
return this._meta !== void 0 && (t.meta = this._meta), t;
|
|
83
|
+
}
|
|
84
|
+
static fromJSON(t) {
|
|
85
|
+
return new S(t);
|
|
86
|
+
}
|
|
87
|
+
// ─── Events ─────────────────────────────────────────────────────────────────
|
|
88
|
+
on(t, e) {
|
|
89
|
+
this._listeners.has(t) || this._listeners.set(t, /* @__PURE__ */ new Set());
|
|
90
|
+
const s = this._listeners.get(t);
|
|
91
|
+
return s.add(e), () => s.delete(e);
|
|
92
|
+
}
|
|
93
|
+
_emit(t, e) {
|
|
94
|
+
const s = this._listeners.get(t);
|
|
95
|
+
if (s)
|
|
96
|
+
for (const i of s)
|
|
97
|
+
e === void 0 ? i() : i(e);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
class B {
|
|
101
|
+
constructor(t = { nodeId: null, label: "Root" }) {
|
|
102
|
+
this._listeners = /* @__PURE__ */ new Set(), this._stack = [t];
|
|
103
|
+
}
|
|
104
|
+
get current() {
|
|
105
|
+
return this._stack[this._stack.length - 1];
|
|
106
|
+
}
|
|
107
|
+
get stack() {
|
|
108
|
+
return this._stack;
|
|
109
|
+
}
|
|
110
|
+
get canGoBack() {
|
|
111
|
+
return this._stack.length > 1;
|
|
112
|
+
}
|
|
113
|
+
push(t) {
|
|
114
|
+
this._stack.push(t), this._notify();
|
|
115
|
+
}
|
|
116
|
+
pop() {
|
|
117
|
+
if (!this.canGoBack) return;
|
|
118
|
+
const t = this._stack.pop();
|
|
119
|
+
return this._notify(), t;
|
|
120
|
+
}
|
|
121
|
+
reset() {
|
|
122
|
+
this._stack = [this._stack[0]], this._notify();
|
|
123
|
+
}
|
|
124
|
+
onChange(t) {
|
|
125
|
+
return this._listeners.add(t), () => this._listeners.delete(t);
|
|
126
|
+
}
|
|
127
|
+
_notify() {
|
|
128
|
+
for (const t of this._listeners) t(this._stack);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const R = [
|
|
132
|
+
{ depth: 0, minZoom: 0, maxZoom: 0.3 },
|
|
133
|
+
{ depth: 1, minZoom: 0.3, maxZoom: 0.6 },
|
|
134
|
+
{ depth: 2, minZoom: 0.6, maxZoom: 1.2 },
|
|
135
|
+
{ depth: 3, minZoom: 1.2, maxZoom: 2.5 },
|
|
136
|
+
{ depth: 4, minZoom: 2.5, maxZoom: 1 / 0 }
|
|
137
|
+
];
|
|
138
|
+
class L {
|
|
139
|
+
constructor(t) {
|
|
140
|
+
this._zoom = 1, this._listeners = /* @__PURE__ */ new Set(), this._thresholds = t ?? R;
|
|
141
|
+
}
|
|
142
|
+
get zoom() {
|
|
143
|
+
return this._zoom;
|
|
144
|
+
}
|
|
145
|
+
get thresholds() {
|
|
146
|
+
return this._thresholds;
|
|
147
|
+
}
|
|
148
|
+
setZoom(t) {
|
|
149
|
+
this._zoom = Math.max(0.01, t), this._notify();
|
|
150
|
+
}
|
|
151
|
+
onChange(t) {
|
|
152
|
+
return this._listeners.add(t), () => this._listeners.delete(t);
|
|
153
|
+
}
|
|
154
|
+
_notify() {
|
|
155
|
+
for (const t of this._listeners) t(this._zoom);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
class F {
|
|
159
|
+
constructor() {
|
|
160
|
+
this._simulation = null;
|
|
161
|
+
}
|
|
162
|
+
run(t, e, s) {
|
|
163
|
+
this.stop();
|
|
164
|
+
const { width: i, height: o, chargeStrength: a = -200, collisionPadding: r = 16, alphaDecay: n = 0.02 } = s, l = t.map((h) => {
|
|
165
|
+
var c, g;
|
|
166
|
+
return {
|
|
167
|
+
id: h.id,
|
|
168
|
+
depth: h.depth,
|
|
169
|
+
// Seed from manual position if provided, else random near world origin.
|
|
170
|
+
// World (0,0) maps to canvas center given the initial pan of (width/2, height/2).
|
|
171
|
+
x: ((c = h.position) == null ? void 0 : c.x) ?? (Math.random() - 0.5) * 100,
|
|
172
|
+
y: ((g = h.position) == null ? void 0 : g.y) ?? (Math.random() - 0.5) * 100
|
|
173
|
+
};
|
|
174
|
+
}), d = new Map(l.map((h) => [h.id, h])), v = [];
|
|
175
|
+
for (const h of t)
|
|
176
|
+
if (h.parentId) {
|
|
177
|
+
const c = d.get(h.parentId), g = d.get(h.id);
|
|
178
|
+
c && g && v.push({ id: `${h.parentId}->${h.id}`, source: c, target: g });
|
|
179
|
+
}
|
|
180
|
+
for (const h of e) {
|
|
181
|
+
const c = d.get(h.source), g = d.get(h.target);
|
|
182
|
+
c && g && v.push({ id: h.id, source: c, target: g });
|
|
183
|
+
}
|
|
184
|
+
const p = (h) => {
|
|
185
|
+
var c;
|
|
186
|
+
(c = s.onTick) == null || c.call(s, h);
|
|
187
|
+
};
|
|
188
|
+
this._simulation = A(l).alphaDecay(n).force(
|
|
189
|
+
"link",
|
|
190
|
+
z(v).id((h) => h.id).distance((h) => {
|
|
191
|
+
const c = h.source, g = h.target;
|
|
192
|
+
return 80 + Math.abs(c.depth - g.depth) * 20;
|
|
193
|
+
}).strength(0.4)
|
|
194
|
+
).force("charge", T().strength(a)).force("center", Z(0, 0)).force("collide", D().radius(r)).on("tick", () => {
|
|
195
|
+
const h = this._collectPositions(l);
|
|
196
|
+
p(h);
|
|
197
|
+
}).on("end", () => {
|
|
198
|
+
var c;
|
|
199
|
+
const h = this._collectPositions(l);
|
|
200
|
+
(c = s.onEnd) == null || c.call(s, h);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
stop() {
|
|
204
|
+
var t;
|
|
205
|
+
(t = this._simulation) == null || t.stop(), this._simulation = null;
|
|
206
|
+
}
|
|
207
|
+
reheat() {
|
|
208
|
+
var t;
|
|
209
|
+
(t = this._simulation) == null || t.alpha(0.3).restart();
|
|
210
|
+
}
|
|
211
|
+
_collectPositions(t) {
|
|
212
|
+
const e = /* @__PURE__ */ new Map();
|
|
213
|
+
for (const s of t)
|
|
214
|
+
e.set(s.id, { x: s.x, y: s.y });
|
|
215
|
+
return e;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const b = {
|
|
219
|
+
background: "#050a1a",
|
|
220
|
+
node: {
|
|
221
|
+
color: "#4a9eff",
|
|
222
|
+
glowColor: "#4a9eff",
|
|
223
|
+
glowRadius: 12,
|
|
224
|
+
size: 8,
|
|
225
|
+
shape: "circle",
|
|
226
|
+
opacity: 1,
|
|
227
|
+
labelColor: "#c8d8f0",
|
|
228
|
+
labelSize: 12,
|
|
229
|
+
labelFont: "system-ui, sans-serif"
|
|
230
|
+
},
|
|
231
|
+
edge: {
|
|
232
|
+
color: "#1e3a5f",
|
|
233
|
+
width: 1.5,
|
|
234
|
+
opacity: 0.6,
|
|
235
|
+
animated: !1
|
|
236
|
+
},
|
|
237
|
+
states: {
|
|
238
|
+
default: {},
|
|
239
|
+
active: {
|
|
240
|
+
color: "#7fcdff",
|
|
241
|
+
glowColor: "#7fcdff",
|
|
242
|
+
glowRadius: 20
|
|
243
|
+
},
|
|
244
|
+
locked: {
|
|
245
|
+
color: "#2a3a4a",
|
|
246
|
+
glowColor: "#2a3a4a",
|
|
247
|
+
glowRadius: 4,
|
|
248
|
+
opacity: 0.5,
|
|
249
|
+
labelColor: "#4a5a6a"
|
|
250
|
+
},
|
|
251
|
+
unlocked: {
|
|
252
|
+
color: "#50fa7b",
|
|
253
|
+
glowColor: "#50fa7b",
|
|
254
|
+
glowRadius: 16
|
|
255
|
+
},
|
|
256
|
+
highlighted: {
|
|
257
|
+
color: "#ffb86c",
|
|
258
|
+
glowColor: "#ffb86c",
|
|
259
|
+
glowRadius: 24
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
function I(m) {
|
|
264
|
+
var t, e, s, i, o;
|
|
265
|
+
return m ? {
|
|
266
|
+
background: m.background ?? b.background,
|
|
267
|
+
node: { ...b.node, ...m.node },
|
|
268
|
+
edge: { ...b.edge, ...m.edge },
|
|
269
|
+
states: {
|
|
270
|
+
default: { ...b.states.default, ...(t = m.states) == null ? void 0 : t.default },
|
|
271
|
+
active: { ...b.states.active, ...(e = m.states) == null ? void 0 : e.active },
|
|
272
|
+
locked: { ...b.states.locked, ...(s = m.states) == null ? void 0 : s.locked },
|
|
273
|
+
unlocked: { ...b.states.unlocked, ...(i = m.states) == null ? void 0 : i.unlocked },
|
|
274
|
+
highlighted: { ...b.states.highlighted, ...(o = m.states) == null ? void 0 : o.highlighted }
|
|
275
|
+
}
|
|
276
|
+
} : b;
|
|
277
|
+
}
|
|
278
|
+
const M = 40;
|
|
279
|
+
function O(m) {
|
|
280
|
+
return Array.from({ length: m }, () => ({
|
|
281
|
+
x: Math.random(),
|
|
282
|
+
y: Math.random(),
|
|
283
|
+
r: 0.4 + Math.random() * 1.2,
|
|
284
|
+
phase: Math.random() * Math.PI * 2,
|
|
285
|
+
speed: 0.4 + Math.random() * 1.2
|
|
286
|
+
}));
|
|
287
|
+
}
|
|
288
|
+
function x(m) {
|
|
289
|
+
let t = 0;
|
|
290
|
+
for (let e = 0; e < m.length; e++) t = t * 31 + m.charCodeAt(e) >>> 0;
|
|
291
|
+
return t % 1e3 / 1e3 * Math.PI * 2;
|
|
292
|
+
}
|
|
293
|
+
class W {
|
|
294
|
+
constructor(t, e) {
|
|
295
|
+
this._burst = null, this._burstDuration = 450, this._implode = null, this._implodeDuration = 420, this._canvas = t;
|
|
296
|
+
const s = t.getContext("2d");
|
|
297
|
+
if (!s) throw new Error("Could not get 2D context from canvas");
|
|
298
|
+
this._ctx = s, this._theme = I(e), this._dpr = window.devicePixelRatio ?? 1, this._bgStars = O(150), this._resize();
|
|
299
|
+
}
|
|
300
|
+
get canvas() {
|
|
301
|
+
return this._canvas;
|
|
302
|
+
}
|
|
303
|
+
get isBurstActive() {
|
|
304
|
+
return this._burst !== null;
|
|
305
|
+
}
|
|
306
|
+
/** Sync canvas physical pixel size to its CSS size. Call when the container resizes. */
|
|
307
|
+
resize() {
|
|
308
|
+
this._resize();
|
|
309
|
+
}
|
|
310
|
+
/** Returns the resolved fill color for a node (used for burst color matching). */
|
|
311
|
+
resolveNodeColor(t) {
|
|
312
|
+
return this._resolveStyle(t).color;
|
|
313
|
+
}
|
|
314
|
+
updateTheme(t) {
|
|
315
|
+
this._theme = I(t);
|
|
316
|
+
}
|
|
317
|
+
triggerBurst(t, e) {
|
|
318
|
+
this._burst = { startTime: performance.now(), center: t, color: e };
|
|
319
|
+
}
|
|
320
|
+
triggerImplode(t) {
|
|
321
|
+
this._implode = { startTime: performance.now(), center: t };
|
|
322
|
+
}
|
|
323
|
+
render(t, e, s) {
|
|
324
|
+
var g;
|
|
325
|
+
const i = this._ctx, o = performance.now() / 1e3, { pan: a, zoom: r, contextFadeAlpha: n, positions: l, internalStates: d } = s, v = this._canvas.width / this._dpr, p = this._canvas.height / this._dpr;
|
|
326
|
+
i.clearRect(0, 0, this._canvas.width, this._canvas.height), i.fillStyle = this._theme.background, i.fillRect(0, 0, this._canvas.width, this._canvas.height), i.save(), i.scale(this._dpr, this._dpr), this._renderBgStars(i, v, p, o), i.save(), i.translate(a.x, a.y), i.scale(r, r);
|
|
327
|
+
for (const _ of e) {
|
|
328
|
+
const f = l.get(_.source), u = l.get(_.target);
|
|
329
|
+
!f || !u || (this._drawEdge(i, f, u, _.style), (((g = _.style) == null ? void 0 : g.animated) ?? this._theme.edge.animated) && this._renderEdgeParticles(i, f, u, _, o, r));
|
|
330
|
+
}
|
|
331
|
+
for (const _ of t) {
|
|
332
|
+
if (!_.parentId) continue;
|
|
333
|
+
const f = l.get(_.parentId), u = l.get(_.id);
|
|
334
|
+
!f || !u || (i.save(), i.globalAlpha = n * 0.35, i.strokeStyle = this._theme.edge.color, i.lineWidth = this._theme.edge.width / r, i.setLineDash([4, 8]), i.beginPath(), i.moveTo(f.x, f.y), i.lineTo(u.x, u.y), i.stroke(), i.restore());
|
|
335
|
+
}
|
|
336
|
+
const h = t.filter((_) => _.childIds && _.childIds.length > 0), c = t.filter((_) => !_.childIds || _.childIds.length === 0);
|
|
337
|
+
for (const _ of [...h, ...c]) {
|
|
338
|
+
const f = l.get(_.id);
|
|
339
|
+
if (!f) continue;
|
|
340
|
+
const u = d.get(_.id) ?? "idle", y = !!(_.childIds && _.childIds.length > 0);
|
|
341
|
+
this._drawNode(i, _, f, u, n, r, y, o);
|
|
342
|
+
}
|
|
343
|
+
i.restore(), i.restore(), this._renderBurst(), this._renderImplode();
|
|
344
|
+
}
|
|
345
|
+
// ─── Background stars ─────────────────────────────────────────────────────
|
|
346
|
+
_renderBgStars(t, e, s, i) {
|
|
347
|
+
for (const o of this._bgStars) {
|
|
348
|
+
const a = 0.5 + 0.5 * Math.sin(i * o.speed + o.phase), r = 0.08 + 0.25 * a, n = o.r * (0.7 + 0.3 * a);
|
|
349
|
+
t.beginPath(), t.arc(o.x * e, o.y * s, n, 0, Math.PI * 2), t.fillStyle = `rgba(255,255,255,${r.toFixed(3)})`, t.fill();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
// ─── Node rendering ───────────────────────────────────────────────────────
|
|
353
|
+
_drawNode(t, e, s, i, o, a, r, n) {
|
|
354
|
+
r ? this._drawBubble(t, e, s, i, o, a, n) : this._drawStar(t, e, s, i, o, a, n);
|
|
355
|
+
}
|
|
356
|
+
_drawBubble(t, e, s, i, o, a, r) {
|
|
357
|
+
const n = this._resolveStyle(e), l = x(e.id), v = 1 + (i === "selected" ? 0.08 : 0.04) * Math.sin(r * 0.6 + l), p = M * v * (i === "hovered" ? 1.1 : 1), h = i === "selected";
|
|
358
|
+
t.save(), t.globalAlpha = n.opacity * o;
|
|
359
|
+
const c = h ? p * 2.8 : p * 2.2, g = h ? n.glowColor + "55" : n.glowColor + "30", _ = t.createRadialGradient(s.x, s.y, p * 0.5, s.x, s.y, c);
|
|
360
|
+
_.addColorStop(0, g), _.addColorStop(1, n.glowColor + "00"), t.fillStyle = _, t.beginPath(), t.arc(s.x, s.y, c, 0, Math.PI * 2), t.fill();
|
|
361
|
+
const f = t.createRadialGradient(s.x, s.y - p * 0.3, p * 0.1, s.x, s.y, p);
|
|
362
|
+
if (f.addColorStop(0, n.color + (h ? "70" : "50")), f.addColorStop(1, n.color + (h ? "28" : "18")), t.fillStyle = f, t.beginPath(), t.arc(s.x, s.y, p, 0, Math.PI * 2), t.fill(), t.strokeStyle = h ? n.glowColor : n.color, t.lineWidth = (h ? 2.5 : 1.5) / a, t.globalAlpha = n.opacity * o * (h ? 1 : 0.7), t.beginPath(), t.arc(s.x, s.y, p, 0, Math.PI * 2), t.stroke(), h) {
|
|
363
|
+
const u = r * 0.7 + l;
|
|
364
|
+
t.strokeStyle = n.glowColor, t.lineWidth = 1.5 / a, t.globalAlpha = n.opacity * o * 0.85, t.setLineDash([10 / a, 7 / a]), t.lineDashOffset = -u * 18, t.beginPath(), t.arc(s.x, s.y, p * 1.3, 0, Math.PI * 2), t.stroke(), t.setLineDash([]);
|
|
365
|
+
}
|
|
366
|
+
if (e.childIds && e.childIds.length > 0) {
|
|
367
|
+
const u = Math.min(e.childIds.length, 8), y = p * 0.55, w = Math.max(1.5, p * 0.06), N = r * 0.15 + l;
|
|
368
|
+
t.globalAlpha = n.opacity * o * 0.6, t.fillStyle = n.color + "90";
|
|
369
|
+
for (let P = 0; P < u; P++) {
|
|
370
|
+
const k = N + P / u * Math.PI * 2;
|
|
371
|
+
t.beginPath(), t.arc(
|
|
372
|
+
s.x + y * Math.cos(k),
|
|
373
|
+
s.y + y * Math.sin(k),
|
|
374
|
+
w,
|
|
375
|
+
0,
|
|
376
|
+
Math.PI * 2
|
|
377
|
+
), t.fill();
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
t.globalAlpha = n.opacity * o, t.fillStyle = n.labelColor, t.font = `bold ${n.labelSize * 1.2 / a}px ${n.labelFont}`, t.textAlign = "center", t.textBaseline = "middle", t.fillText(e.label, s.x, s.y), t.restore();
|
|
381
|
+
}
|
|
382
|
+
_drawStar(t, e, s, i, o, a, r) {
|
|
383
|
+
const n = this._resolveStyle(e), l = x(e.id), d = i === "selected", p = 1 + (d ? 0.4 : 0.22) * Math.sin(r * 1.7 + l) + 0.08 * Math.sin(r * 3.1 + l * 1.3), h = n.glowRadius * p, c = n.size * (i === "hovered" ? 1.4 : 1);
|
|
384
|
+
if (t.save(), t.globalAlpha = n.opacity * o, d) {
|
|
385
|
+
for (let _ = 0; _ < 2; _++) {
|
|
386
|
+
const f = _ * 0.9, u = (r + f) % 1.8 / 1.8, y = (c + h * 0.6) * (1 + u * 2.2), w = (1 - u) * 0.6;
|
|
387
|
+
t.strokeStyle = n.glowColor, t.lineWidth = 1.5 / a * (1 - u * 0.5), t.globalAlpha = w * n.opacity * o, t.beginPath(), t.arc(s.x, s.y, y, 0, Math.PI * 2), t.stroke();
|
|
388
|
+
}
|
|
389
|
+
t.globalAlpha = n.opacity * o;
|
|
390
|
+
}
|
|
391
|
+
if (h > 0) {
|
|
392
|
+
const g = t.createRadialGradient(s.x, s.y, 0, s.x, s.y, h + c);
|
|
393
|
+
g.addColorStop(0, n.glowColor + (d ? "ff" : "cc")), g.addColorStop(0.4, n.glowColor + (d ? "88" : "55")), g.addColorStop(1, n.glowColor + "00"), t.fillStyle = g, t.beginPath(), t.arc(s.x, s.y, h + c, 0, Math.PI * 2), t.fill();
|
|
394
|
+
}
|
|
395
|
+
t.fillStyle = d ? n.glowColor : n.color, t.beginPath(), this._drawShape(t, s, c, n.shape), t.fill(), c * a > 4 && (t.fillStyle = n.labelColor, t.font = `${n.labelSize / a}px ${n.labelFont}`, t.textAlign = "center", t.textBaseline = "top", t.fillText(e.label, s.x, s.y + c + 4 / a)), t.restore();
|
|
396
|
+
}
|
|
397
|
+
// ─── Edge particles ───────────────────────────────────────────────────────
|
|
398
|
+
_renderEdgeParticles(t, e, s, i, o, a) {
|
|
399
|
+
var c;
|
|
400
|
+
const r = s.x - e.x, n = s.y - e.y;
|
|
401
|
+
if (Math.sqrt(r * r + n * n) < 1) return;
|
|
402
|
+
const d = 3, v = 0.2, p = 2.5 / a, h = ((c = i.style) == null ? void 0 : c.color) ?? this._theme.edge.color;
|
|
403
|
+
for (let g = 0; g < d; g++) {
|
|
404
|
+
const _ = (o * v + g / d) % 1, f = e.x + r * _, u = e.y + n * _, y = Math.sin(_ * Math.PI);
|
|
405
|
+
t.save(), t.globalAlpha = y * 0.85;
|
|
406
|
+
const w = t.createRadialGradient(f, u, 0, f, u, p * 2.5);
|
|
407
|
+
w.addColorStop(0, h + "ff"), w.addColorStop(0.4, h + "99"), w.addColorStop(1, h + "00"), t.fillStyle = w, t.beginPath(), t.arc(f, u, p * 2.5, 0, Math.PI * 2), t.fill(), t.restore();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
// ─── Burst animation ──────────────────────────────────────────────────────
|
|
411
|
+
_renderBurst() {
|
|
412
|
+
if (!this._burst) return;
|
|
413
|
+
const t = this._ctx, s = (performance.now() - this._burst.startTime) / this._burstDuration;
|
|
414
|
+
if (s >= 1) {
|
|
415
|
+
this._burst = null;
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const i = 1 - Math.pow(1 - s, 3), o = Math.hypot(this._canvas.width, this._canvas.height), a = i * o, r = (1 - i) * 0.35;
|
|
419
|
+
t.save(), t.globalAlpha = r, t.fillStyle = this._burst.color, t.beginPath(), t.arc(
|
|
420
|
+
this._burst.center.x * this._dpr,
|
|
421
|
+
this._burst.center.y * this._dpr,
|
|
422
|
+
a,
|
|
423
|
+
0,
|
|
424
|
+
Math.PI * 2
|
|
425
|
+
), t.fill(), t.restore();
|
|
426
|
+
}
|
|
427
|
+
// ─── Implode animation ────────────────────────────────────────────────────
|
|
428
|
+
_renderImplode() {
|
|
429
|
+
if (!this._implode) return;
|
|
430
|
+
const t = this._ctx, s = (performance.now() - this._implode.startTime) / this._implodeDuration;
|
|
431
|
+
if (s >= 1) {
|
|
432
|
+
this._implode = null;
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
const i = s * s * s, o = Math.hypot(this._canvas.width, this._canvas.height), a = (1 - i) * o, r = (1 - s) * 0.55, n = (1 - i) * 40 * this._dpr, l = this._implode.center.x * this._dpr, d = this._implode.center.y * this._dpr;
|
|
436
|
+
t.save(), t.globalAlpha = r, t.strokeStyle = "#9b5de5", t.lineWidth = n, t.shadowColor = "#9b5de5", t.shadowBlur = 30 * this._dpr, t.beginPath(), t.arc(l, d, Math.max(0, a), 0, Math.PI * 2), t.stroke(), t.restore();
|
|
437
|
+
}
|
|
438
|
+
// ─── Shapes ───────────────────────────────────────────────────────────────
|
|
439
|
+
_resolveStyle(t) {
|
|
440
|
+
const e = this._theme.node, s = t.state ? this._theme.states[t.state] : {}, i = t.style ?? {};
|
|
441
|
+
return { ...e, ...s, ...i };
|
|
442
|
+
}
|
|
443
|
+
_drawShape(t, e, s, i) {
|
|
444
|
+
switch (i) {
|
|
445
|
+
case "circle":
|
|
446
|
+
t.arc(e.x, e.y, s, 0, Math.PI * 2);
|
|
447
|
+
break;
|
|
448
|
+
case "hexagon":
|
|
449
|
+
this._polygon(t, e, s, 6, Math.PI / 6);
|
|
450
|
+
break;
|
|
451
|
+
case "diamond":
|
|
452
|
+
this._polygon(t, e, s, 4, 0);
|
|
453
|
+
break;
|
|
454
|
+
case "star":
|
|
455
|
+
this._star(t, e, s);
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
_polygon(t, e, s, i, o) {
|
|
460
|
+
t.moveTo(e.x + s * Math.cos(o), e.y + s * Math.sin(o));
|
|
461
|
+
for (let a = 1; a < i; a++) {
|
|
462
|
+
const r = o + a * 2 * Math.PI / i;
|
|
463
|
+
t.lineTo(e.x + s * Math.cos(r), e.y + s * Math.sin(r));
|
|
464
|
+
}
|
|
465
|
+
t.closePath();
|
|
466
|
+
}
|
|
467
|
+
_star(t, e, s) {
|
|
468
|
+
const i = s * 0.4, o = 5;
|
|
469
|
+
for (let a = 0; a < o * 2; a++) {
|
|
470
|
+
const r = a * Math.PI / o - Math.PI / 2, n = a % 2 === 0 ? s : i, l = e.x + n * Math.cos(r), d = e.y + n * Math.sin(r);
|
|
471
|
+
a === 0 ? t.moveTo(l, d) : t.lineTo(l, d);
|
|
472
|
+
}
|
|
473
|
+
t.closePath();
|
|
474
|
+
}
|
|
475
|
+
_drawEdge(t, e, s, i) {
|
|
476
|
+
const o = { ...this._theme.edge, ...i };
|
|
477
|
+
t.save(), t.strokeStyle = o.color, t.lineWidth = o.width, t.globalAlpha = o.opacity, o.dashPattern && t.setLineDash(o.dashPattern), t.beginPath(), t.moveTo(e.x, e.y), t.lineTo(s.x, s.y), t.stroke(), t.restore();
|
|
478
|
+
}
|
|
479
|
+
_resize() {
|
|
480
|
+
const t = this._canvas.getBoundingClientRect(), e = Math.floor(t.width * this._dpr), s = Math.floor(t.height * this._dpr);
|
|
481
|
+
(this._canvas.width !== e || this._canvas.height !== s) && (this._canvas.width = e, this._canvas.height = s);
|
|
482
|
+
}
|
|
483
|
+
dispose() {
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
class H {
|
|
487
|
+
constructor(t) {
|
|
488
|
+
this._isPanning = !1, this._lastPan = { x: 0, y: 0 }, this._listeners = /* @__PURE__ */ new Set(), this._nodes = [], this._positions = /* @__PURE__ */ new Map(), this._nodeSize = 8, this._targetZoom = 1, this._zoomAnchor = null, this._zoomLerpAlpha = 0.14, this._timedZoom = null, this._activePointers = /* @__PURE__ */ new Map(), this._lastPinchDist = null, this._pointerDownPos = { x: 0, y: 0 }, this._canvas = t, this._dpr = window.devicePixelRatio ?? 1, this._state = {
|
|
489
|
+
pan: { x: t.width / (2 * this._dpr), y: t.height / (2 * this._dpr) },
|
|
490
|
+
zoom: 1,
|
|
491
|
+
hoveredNodeId: null,
|
|
492
|
+
selectedNodeId: null
|
|
493
|
+
}, this._onPointerDown = this._handlePointerDown.bind(this), this._onPointerMove = this._handlePointerMove.bind(this), this._onPointerUp = this._handlePointerUp.bind(this), this._onPointerCancel = this._handlePointerCancel.bind(this), this._onWheel = this._handleWheel.bind(this), t.addEventListener("pointerdown", this._onPointerDown), t.addEventListener("pointermove", this._onPointerMove), t.addEventListener("pointerup", this._onPointerUp), t.addEventListener("pointercancel", this._onPointerCancel), t.addEventListener("wheel", this._onWheel, { passive: !1 });
|
|
494
|
+
}
|
|
495
|
+
get state() {
|
|
496
|
+
return this._state;
|
|
497
|
+
}
|
|
498
|
+
get targetZoom() {
|
|
499
|
+
return this._targetZoom;
|
|
500
|
+
}
|
|
501
|
+
get zoomAnchor() {
|
|
502
|
+
return this._zoomAnchor;
|
|
503
|
+
}
|
|
504
|
+
setTargetZoom(t, e) {
|
|
505
|
+
this._timedZoom = null, this._targetZoom = t, e !== void 0 && (this._zoomAnchor = e);
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Animate zoom to `target` over `duration` ms.
|
|
509
|
+
* `easing: 'in'` — cubic ease-in (slow start, accelerates toward target).
|
|
510
|
+
* `easing: 'out'` — cubic ease-out (fast start, decelerates toward target).
|
|
511
|
+
*/
|
|
512
|
+
startTimedZoom(t, e, s, i = "in") {
|
|
513
|
+
this._timedZoom = {
|
|
514
|
+
startZoom: this._state.zoom,
|
|
515
|
+
target: t,
|
|
516
|
+
anchor: s ?? null,
|
|
517
|
+
startTime: performance.now(),
|
|
518
|
+
duration: e,
|
|
519
|
+
easing: i
|
|
520
|
+
}, this._targetZoom = t, this._zoomAnchor = s ?? null;
|
|
521
|
+
}
|
|
522
|
+
/** Instantly snap zoom and pan to a new center — used on navigation transitions. */
|
|
523
|
+
resetToCenter(t, e, s) {
|
|
524
|
+
this._timedZoom = null, this._targetZoom = t, this._state.zoom = t, this._state.pan = { x: e, y: s }, this._zoomAnchor = null;
|
|
525
|
+
}
|
|
526
|
+
updateNodes(t, e, s) {
|
|
527
|
+
this._nodes = t, this._positions = e, this._nodeSize = s;
|
|
528
|
+
}
|
|
529
|
+
onChange(t) {
|
|
530
|
+
return this._listeners.add(t), () => this._listeners.delete(t);
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Advance zoom animation one frame. Called every RAF frame by the engine.
|
|
534
|
+
* Returns true while the animation is still in progress.
|
|
535
|
+
*/
|
|
536
|
+
tick() {
|
|
537
|
+
const t = this._state.zoom;
|
|
538
|
+
if (this._timedZoom) {
|
|
539
|
+
const { startZoom: e, target: s, anchor: i, startTime: o, duration: a, easing: r } = this._timedZoom, n = Math.min(1, (performance.now() - o) / a), l = r === "out" ? 1 - Math.pow(1 - n, 3) : n * n * n;
|
|
540
|
+
this._state.zoom = e + (s - e) * l, n >= 1 ? (this._timedZoom = null, this._zoomAnchor = null) : this._zoomAnchor = i;
|
|
541
|
+
} else {
|
|
542
|
+
const e = this._targetZoom - this._state.zoom;
|
|
543
|
+
if (Math.abs(e) < 1e-4)
|
|
544
|
+
return this._zoomAnchor = null, !1;
|
|
545
|
+
this._state.zoom += e * this._zoomLerpAlpha;
|
|
546
|
+
}
|
|
547
|
+
if (this._zoomAnchor) {
|
|
548
|
+
const { x: e, y: s } = this._zoomAnchor;
|
|
549
|
+
this._state.pan = {
|
|
550
|
+
x: e - (e - this._state.pan.x) * (this._state.zoom / t),
|
|
551
|
+
y: s - (s - this._state.pan.y) * (this._state.zoom / t)
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
return !0;
|
|
555
|
+
}
|
|
556
|
+
dispose() {
|
|
557
|
+
this._canvas.removeEventListener("pointerdown", this._onPointerDown), this._canvas.removeEventListener("pointermove", this._onPointerMove), this._canvas.removeEventListener("pointerup", this._onPointerUp), this._canvas.removeEventListener("pointercancel", this._onPointerCancel), this._canvas.removeEventListener("wheel", this._onWheel);
|
|
558
|
+
}
|
|
559
|
+
// ─── Canvas → world coordinate transform ────────────────────────────────────
|
|
560
|
+
canvasToWorld(t, e) {
|
|
561
|
+
return {
|
|
562
|
+
x: (t - this._state.pan.x) / this._state.zoom,
|
|
563
|
+
y: (e - this._state.pan.y) / this._state.zoom
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
_getCanvasPos(t) {
|
|
567
|
+
const e = this._canvas.getBoundingClientRect();
|
|
568
|
+
return { x: t.clientX - e.left, y: t.clientY - e.top };
|
|
569
|
+
}
|
|
570
|
+
_hitTest(t) {
|
|
571
|
+
let e = null, s = 1 / 0;
|
|
572
|
+
for (const i of this._nodes) {
|
|
573
|
+
const o = this._positions.get(i.id);
|
|
574
|
+
if (!o) continue;
|
|
575
|
+
const r = !!(i.childIds && i.childIds.length > 0) ? M * 1.3 : this._nodeSize * 4, n = t.x - o.x, l = t.y - o.y, d = Math.sqrt(n * n + l * l);
|
|
576
|
+
d < r && d < s && (s = d, e = i.id);
|
|
577
|
+
}
|
|
578
|
+
return e;
|
|
579
|
+
}
|
|
580
|
+
_emit(t) {
|
|
581
|
+
for (const e of this._listeners) e(t);
|
|
582
|
+
}
|
|
583
|
+
// ─── Pointer handlers ────────────────────────────────────────────────────────
|
|
584
|
+
_handlePointerDown(t) {
|
|
585
|
+
this._canvas.setPointerCapture(t.pointerId);
|
|
586
|
+
const e = this._getCanvasPos(t);
|
|
587
|
+
this._activePointers.set(t.pointerId, e), this._activePointers.size === 1 ? (this._isPanning = !0, this._lastPan = e, this._pointerDownPos = e) : (this._isPanning = !1, this._lastPinchDist = null);
|
|
588
|
+
}
|
|
589
|
+
_handlePointerMove(t) {
|
|
590
|
+
const e = this._getCanvasPos(t);
|
|
591
|
+
if (this._activePointers.set(t.pointerId, e), this._activePointers.size >= 2) {
|
|
592
|
+
const s = [...this._activePointers.values()], i = Math.hypot(s[1].x - s[0].x, s[1].y - s[0].y);
|
|
593
|
+
if (this._lastPinchDist !== null && i > 0) {
|
|
594
|
+
const o = i / this._lastPinchDist, a = (s[0].x + s[1].x) / 2, r = (s[0].y + s[1].y) / 2;
|
|
595
|
+
this._targetZoom = Math.max(0.05, Math.min(20, this._targetZoom * o)), this._zoomAnchor = { x: a, y: r }, this._emit({ type: "zoom:change", zoom: this._targetZoom });
|
|
596
|
+
}
|
|
597
|
+
this._lastPinchDist = i;
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
if (this._isPanning) {
|
|
601
|
+
const s = e.x - this._lastPan.x, i = e.y - this._lastPan.y;
|
|
602
|
+
this._lastPan = e, this._state.pan = { x: this._state.pan.x + s, y: this._state.pan.y + i }, this._emit({ type: "pan:change", pan: this._state.pan });
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
if (t.pointerType !== "touch") {
|
|
606
|
+
const s = this.canvasToWorld(e.x, e.y), i = this._hitTest(s);
|
|
607
|
+
i !== this._state.hoveredNodeId && (this._state.hoveredNodeId && this._emit({ type: "node:blur", nodeId: this._state.hoveredNodeId }), this._state.hoveredNodeId = i, i && this._emit({ type: "node:hover", nodeId: i }));
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
_handlePointerUp(t) {
|
|
611
|
+
const e = this._getCanvasPos(t), s = this._activePointers.size >= 2, i = this._pointerDownPos;
|
|
612
|
+
if (this._activePointers.delete(t.pointerId), this._lastPinchDist = null, s) {
|
|
613
|
+
this._activePointers.size === 1 && (this._isPanning = !0, this._lastPan = [...this._activePointers.values()][0]);
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
this._isPanning = !1;
|
|
617
|
+
const o = Math.abs(e.x - i.x), a = Math.abs(e.y - i.y);
|
|
618
|
+
if (o < 4 && a < 4) {
|
|
619
|
+
const r = this.canvasToWorld(e.x, e.y), n = this._hitTest(r);
|
|
620
|
+
n ? (this._state.selectedNodeId = n === this._state.selectedNodeId ? null : n, this._emit({ type: "node:click", nodeId: n })) : (this._state.selectedNodeId = null, this._emit({ type: "canvas:click" }));
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
_handlePointerCancel(t) {
|
|
624
|
+
this._activePointers.delete(t.pointerId), this._lastPinchDist = null, this._activePointers.size === 0 && (this._isPanning = !1);
|
|
625
|
+
}
|
|
626
|
+
// ── Wheel (mouse / trackpad) ─────────────────────────────────────────────────
|
|
627
|
+
_handleWheel(t) {
|
|
628
|
+
t.preventDefault();
|
|
629
|
+
const e = this._getCanvasPos(t), s = t.deltaY < 0 ? 1.1 : 1 / 1.1;
|
|
630
|
+
this._targetZoom = Math.max(0.05, Math.min(20, this._targetZoom * s)), this._zoomAnchor = e, this._emit({ type: "zoom:change", zoom: this._targetZoom });
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
const U = 2.5, G = 0.35, C = 700;
|
|
634
|
+
class q {
|
|
635
|
+
constructor(t) {
|
|
636
|
+
var r, n;
|
|
637
|
+
this._positions = /* @__PURE__ */ new Map(), this._internalStates = /* @__PURE__ */ new Map(), this._rafId = null, this._pendingEnter = null, this._pendingExit = null, this._unsubscribers = [], this._visibleNodes = [], this._visibleEdges = [], this._contextFadeAlpha = 1, this._contextFadeStart = 0, this._contextFadeDuration = 400, this._navCooldownUntil = 0;
|
|
638
|
+
const { canvas: e, data: s, theme: i, lod: o, on: a = {} } = t;
|
|
639
|
+
if (this._eventHandlers = a, this._model = new S(s), this._nav = new B({ nodeId: null, label: s.label }), this._lod = new L(o), this._layout = new F(), this._renderer = new W(e, i ?? s.theme), this._interaction = new H(e), t.initialContextNodeId) {
|
|
640
|
+
const l = this._model.getNode(t.initialContextNodeId);
|
|
641
|
+
l && this._isBubble(l) && this._nav.push({ nodeId: l.id, label: l.label });
|
|
642
|
+
}
|
|
643
|
+
this._rebuildVisibleCache(), this._wireEvents(), this._runLayout(), this._startRenderLoop(), this._resizeObserver = new ResizeObserver(() => {
|
|
644
|
+
this._renderer.resize(), this._runLayout();
|
|
645
|
+
}), this._resizeObserver.observe(e), (n = (r = this._eventHandlers)["graph:ready"]) == null || n.call(r, s);
|
|
646
|
+
}
|
|
647
|
+
// ─── Public API ─────────────────────────────────────────────────────────────
|
|
648
|
+
setNodeState(t, e) {
|
|
649
|
+
this._model.setNodeState(t, e);
|
|
650
|
+
}
|
|
651
|
+
addEvidence(t, e) {
|
|
652
|
+
this._model.addEvidence(t, e);
|
|
653
|
+
}
|
|
654
|
+
removeEvidence(t, e) {
|
|
655
|
+
this._model.removeEvidence(t, e);
|
|
656
|
+
}
|
|
657
|
+
updateTheme(t) {
|
|
658
|
+
this._renderer.updateTheme(t);
|
|
659
|
+
}
|
|
660
|
+
zoomIn() {
|
|
661
|
+
this._interaction.setTargetZoom(Math.min(20, this._interaction.targetZoom * 1.3));
|
|
662
|
+
}
|
|
663
|
+
zoomOut() {
|
|
664
|
+
this._interaction.setTargetZoom(Math.max(0.05, this._interaction.targetZoom / 1.3));
|
|
665
|
+
}
|
|
666
|
+
goBack() {
|
|
667
|
+
this._nav.canGoBack && this._exitWithAnimation();
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Atomically jump to a specific nav stack depth, firing a single animation.
|
|
671
|
+
* `targetLength` is the desired `stack.length` after the jump.
|
|
672
|
+
* Silently pops intermediate frames; plays one implode + fade transition.
|
|
673
|
+
*/
|
|
674
|
+
jumpToNavDepth(t) {
|
|
675
|
+
var a, r;
|
|
676
|
+
if (this._nav.stack.length <= t) return;
|
|
677
|
+
this._pendingEnter !== null && (clearTimeout(this._pendingEnter), this._pendingEnter = null), this._pendingExit !== null && (clearTimeout(this._pendingExit), this._pendingExit = null);
|
|
678
|
+
let e;
|
|
679
|
+
for (; this._nav.stack.length > t && this._nav.canGoBack; )
|
|
680
|
+
e = this._nav.pop();
|
|
681
|
+
if (!e) return;
|
|
682
|
+
const i = this._renderer.canvas.getBoundingClientRect(), o = { x: i.width / 2, y: i.height / 2 };
|
|
683
|
+
this._navCooldownUntil = Date.now() + C, this._rebuildVisibleCache(), this._renderer.triggerImplode(o), this._interaction.resetToCenter(1, o.x, o.y), this._lod.setZoom(1);
|
|
684
|
+
for (const n of this._visibleNodes)
|
|
685
|
+
this._positions.set(n.id, { x: (Math.random() - 0.5) * 80, y: (Math.random() - 0.5) * 80 });
|
|
686
|
+
this._contextFadeAlpha = 0, this._contextFadeStart = performance.now(), this._runLayout(), (r = (a = this._eventHandlers)["context:exit"]) == null || r.call(a, e, this._nav.stack);
|
|
687
|
+
}
|
|
688
|
+
_exitWithAnimation() {
|
|
689
|
+
if (!this._nav.canGoBack) return;
|
|
690
|
+
this._pendingEnter !== null && (clearTimeout(this._pendingEnter), this._pendingEnter = null);
|
|
691
|
+
const e = this._renderer.canvas.getBoundingClientRect(), s = { x: e.width / 2, y: e.height / 2 }, i = 480;
|
|
692
|
+
this._interaction.startTimedZoom(0.45, i, void 0, "out"), this._pendingExit = setTimeout(() => {
|
|
693
|
+
this._pendingExit = null, this._renderer.triggerImplode(s), this._exitContext();
|
|
694
|
+
}, i);
|
|
695
|
+
}
|
|
696
|
+
enterContext(t) {
|
|
697
|
+
const e = this._model.getNode(t);
|
|
698
|
+
if (!e || !this._isBubble(e)) return;
|
|
699
|
+
this._pendingEnter !== null && (clearTimeout(this._pendingEnter), this._pendingEnter = null);
|
|
700
|
+
const i = this._renderer.canvas.getBoundingClientRect(), o = { x: i.width / 2, y: i.height / 2 }, a = this._positions.get(t), r = a ? (() => {
|
|
701
|
+
const { zoom: l, pan: d } = this._interaction.state;
|
|
702
|
+
return { x: a.x * l + d.x, y: a.y * l + d.y };
|
|
703
|
+
})() : void 0, n = 480;
|
|
704
|
+
this._interaction.startTimedZoom(2.5, n, r), this._pendingEnter = setTimeout(() => {
|
|
705
|
+
this._pendingEnter = null, this._enterContext(e, o);
|
|
706
|
+
}, n);
|
|
707
|
+
}
|
|
708
|
+
getGraph() {
|
|
709
|
+
return this._model.toJSON();
|
|
710
|
+
}
|
|
711
|
+
getNavigationStack() {
|
|
712
|
+
return this._nav.stack;
|
|
713
|
+
}
|
|
714
|
+
dispose() {
|
|
715
|
+
this._rafId !== null && cancelAnimationFrame(this._rafId), this._pendingEnter !== null && clearTimeout(this._pendingEnter), this._pendingExit !== null && clearTimeout(this._pendingExit), this._resizeObserver.disconnect(), this._layout.stop(), this._renderer.dispose(), this._interaction.dispose();
|
|
716
|
+
for (const t of this._unsubscribers) t();
|
|
717
|
+
}
|
|
718
|
+
// ─── Visible node cache ──────────────────────────────────────────────────────
|
|
719
|
+
_rebuildVisibleCache() {
|
|
720
|
+
const t = this._nav.current.nodeId;
|
|
721
|
+
this._visibleNodes = this._model.getNodes().filter(
|
|
722
|
+
(s) => t === null ? !s.parentId : s.parentId === t
|
|
723
|
+
);
|
|
724
|
+
const e = new Set(this._visibleNodes.map((s) => s.id));
|
|
725
|
+
this._visibleEdges = this._model.getEdges().filter(
|
|
726
|
+
(s) => e.has(s.source) && e.has(s.target)
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
// ─── Navigation ─────────────────────────────────────────────────────────────
|
|
730
|
+
_isBubble(t) {
|
|
731
|
+
return !!(t.childIds && t.childIds.length > 0);
|
|
732
|
+
}
|
|
733
|
+
_enterContext(t, e) {
|
|
734
|
+
var o, a;
|
|
735
|
+
this._nav.push({ nodeId: t.id, label: t.label }), this._navCooldownUntil = Date.now() + C, this._rebuildVisibleCache(), this._renderer.triggerBurst(e, this._renderer.resolveNodeColor(t));
|
|
736
|
+
const i = this._renderer.canvas.getBoundingClientRect();
|
|
737
|
+
this._interaction.resetToCenter(1, i.width / 2, i.height / 2), this._lod.setZoom(1);
|
|
738
|
+
for (const r of this._visibleNodes)
|
|
739
|
+
this._positions.set(r.id, {
|
|
740
|
+
x: (Math.random() - 0.5) * 80,
|
|
741
|
+
y: (Math.random() - 0.5) * 80
|
|
742
|
+
});
|
|
743
|
+
this._contextFadeAlpha = 0, this._contextFadeStart = performance.now(), this._runLayout(), (a = (o = this._eventHandlers)["context:enter"]) == null || a.call(o, t, this._nav.stack);
|
|
744
|
+
}
|
|
745
|
+
_exitContext() {
|
|
746
|
+
var i, o;
|
|
747
|
+
const t = this._nav.pop();
|
|
748
|
+
if (!t) return;
|
|
749
|
+
this._navCooldownUntil = Date.now() + C, this._rebuildVisibleCache();
|
|
750
|
+
const s = this._renderer.canvas.getBoundingClientRect();
|
|
751
|
+
this._interaction.resetToCenter(1, s.width / 2, s.height / 2), this._lod.setZoom(1);
|
|
752
|
+
for (const a of this._visibleNodes)
|
|
753
|
+
this._positions.set(a.id, {
|
|
754
|
+
x: (Math.random() - 0.5) * 80,
|
|
755
|
+
y: (Math.random() - 0.5) * 80
|
|
756
|
+
});
|
|
757
|
+
this._contextFadeAlpha = 0, this._contextFadeStart = performance.now(), this._runLayout(), (o = (i = this._eventHandlers)["context:exit"]) == null || o.call(i, t, this._nav.stack);
|
|
758
|
+
}
|
|
759
|
+
_checkNavigation() {
|
|
760
|
+
if (Date.now() < this._navCooldownUntil) return;
|
|
761
|
+
const t = this._interaction.targetZoom, e = this._interaction.zoomAnchor;
|
|
762
|
+
if (t > U && e) {
|
|
763
|
+
const { zoom: s, pan: i } = this._interaction.state, o = this._findBubbleAtCanvas(e, i, s);
|
|
764
|
+
if (o) {
|
|
765
|
+
this._enterContext(o, e);
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
t < G && this._nav.canGoBack && this._exitContext();
|
|
770
|
+
}
|
|
771
|
+
_findBubbleAtCanvas(t, e, s) {
|
|
772
|
+
const i = (t.x - e.x) / s, o = (t.y - e.y) / s;
|
|
773
|
+
for (const a of this._visibleNodes) {
|
|
774
|
+
if (!this._isBubble(a)) continue;
|
|
775
|
+
const r = this._positions.get(a.id);
|
|
776
|
+
if (!r) continue;
|
|
777
|
+
const n = i - r.x, l = o - r.y;
|
|
778
|
+
if (Math.sqrt(n * n + l * l) <= M * 1.3)
|
|
779
|
+
return a;
|
|
780
|
+
}
|
|
781
|
+
return null;
|
|
782
|
+
}
|
|
783
|
+
// ─── Events ─────────────────────────────────────────────────────────────────
|
|
784
|
+
_wireEvents() {
|
|
785
|
+
this._unsubscribers.push(
|
|
786
|
+
this._model.on("changed", () => {
|
|
787
|
+
this._rebuildVisibleCache();
|
|
788
|
+
})
|
|
789
|
+
), this._unsubscribers.push(
|
|
790
|
+
this._interaction.onChange((t) => {
|
|
791
|
+
var e, s, i, o, a, r, n, l;
|
|
792
|
+
switch (t.type) {
|
|
793
|
+
case "zoom:change":
|
|
794
|
+
case "pan:change":
|
|
795
|
+
break;
|
|
796
|
+
case "node:hover": {
|
|
797
|
+
this._internalStates.set(t.nodeId, "hovered");
|
|
798
|
+
const d = this._model.getNode(t.nodeId);
|
|
799
|
+
d && ((s = (e = this._eventHandlers)["node:hover"]) == null || s.call(e, d));
|
|
800
|
+
break;
|
|
801
|
+
}
|
|
802
|
+
case "node:blur": {
|
|
803
|
+
this._internalStates.get(t.nodeId) === "hovered" && this._internalStates.set(t.nodeId, "idle");
|
|
804
|
+
const v = this._model.getNode(t.nodeId);
|
|
805
|
+
v && ((o = (i = this._eventHandlers)["node:blur"]) == null || o.call(i, v));
|
|
806
|
+
break;
|
|
807
|
+
}
|
|
808
|
+
case "canvas:click": {
|
|
809
|
+
for (const [d, v] of this._internalStates)
|
|
810
|
+
v === "selected" && this._internalStates.set(d, "idle");
|
|
811
|
+
(r = (a = this._eventHandlers)["canvas:click"]) == null || r.call(a);
|
|
812
|
+
break;
|
|
813
|
+
}
|
|
814
|
+
case "node:click": {
|
|
815
|
+
const d = this._model.getNode(t.nodeId);
|
|
816
|
+
if (!d) break;
|
|
817
|
+
if (this._internalStates.get(t.nodeId) === "selected")
|
|
818
|
+
this._internalStates.set(t.nodeId, "idle");
|
|
819
|
+
else {
|
|
820
|
+
for (const [h, c] of this._internalStates)
|
|
821
|
+
c === "selected" && this._internalStates.set(h, "idle");
|
|
822
|
+
this._internalStates.set(t.nodeId, "selected");
|
|
823
|
+
}
|
|
824
|
+
(l = (n = this._eventHandlers)["node:click"]) == null || l.call(n, d);
|
|
825
|
+
break;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
})
|
|
829
|
+
);
|
|
830
|
+
}
|
|
831
|
+
// ─── Layout ─────────────────────────────────────────────────────────────────
|
|
832
|
+
_runLayout() {
|
|
833
|
+
const t = this._renderer.canvas.getBoundingClientRect();
|
|
834
|
+
this._layout.run(this._visibleNodes, this._visibleEdges, {
|
|
835
|
+
width: t.width || 800,
|
|
836
|
+
height: t.height || 600,
|
|
837
|
+
onTick: (e) => {
|
|
838
|
+
for (const [s, i] of e) this._positions.set(s, i);
|
|
839
|
+
this._interaction.updateNodes(this._visibleNodes, this._positions, 8);
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
// ─── Render loop ────────────────────────────────────────────────────────────
|
|
844
|
+
_startRenderLoop() {
|
|
845
|
+
const t = () => {
|
|
846
|
+
var s, i;
|
|
847
|
+
if (this._interaction.tick()) {
|
|
848
|
+
const o = this._interaction.state.zoom;
|
|
849
|
+
this._lod.setZoom(o), (i = (s = this._eventHandlers)["zoom:change"]) == null || i.call(s, o);
|
|
850
|
+
}
|
|
851
|
+
if (this._contextFadeAlpha < 1) {
|
|
852
|
+
const o = performance.now() - this._contextFadeStart;
|
|
853
|
+
this._contextFadeAlpha = Math.min(1, o / this._contextFadeDuration);
|
|
854
|
+
}
|
|
855
|
+
this._checkNavigation(), this._draw(), this._rafId = requestAnimationFrame(t);
|
|
856
|
+
};
|
|
857
|
+
this._rafId = requestAnimationFrame(t);
|
|
858
|
+
}
|
|
859
|
+
_draw() {
|
|
860
|
+
const { pan: t, zoom: e } = this._interaction.state;
|
|
861
|
+
this._renderer.render(this._visibleNodes, this._visibleEdges, {
|
|
862
|
+
positions: this._positions,
|
|
863
|
+
internalStates: this._internalStates,
|
|
864
|
+
contextFadeAlpha: this._contextFadeAlpha,
|
|
865
|
+
pan: t,
|
|
866
|
+
zoom: e
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
export {
|
|
871
|
+
M as BUBBLE_WORLD_RADIUS,
|
|
872
|
+
W as CanvasRenderer,
|
|
873
|
+
F as ForceLayout,
|
|
874
|
+
H as InteractionController,
|
|
875
|
+
L as LodController,
|
|
876
|
+
B as NavigationController,
|
|
877
|
+
S as SkillGraphModel,
|
|
878
|
+
q as SkillTreeEngine,
|
|
879
|
+
b as defaultTheme,
|
|
880
|
+
I as mergeTheme
|
|
881
|
+
};
|
|
882
|
+
//# sourceMappingURL=index.js.map
|