@masterpeach/plugin-react 0.0.0-experimental-20260625203238

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.
@@ -0,0 +1,1288 @@
1
+ import { jsx as I, jsxs as C, Fragment as ze } from "react/jsx-runtime";
2
+ import { c as je, ai as Re, aj as K, y as q, N as me, ak as Ve, al as te, r as He, am as Te, an as Ye, ao as Ge, k as J, ap as Xe, aq as Ae, n as ae, P as qe, ar as Ke, J as Je, t as pe, as as Qe, at as Ze, au as Ee, f as ye } from "./index-B67iXHsu.js";
3
+ import { useState as X, useRef as Q, useMemo as V, useEffect as Fe } from "react";
4
+ import { erc20Abi as xe } from "viem";
5
+ import { usePublicClient as et } from "wagmi";
6
+ /**
7
+ * @license lucide-react v0.577.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */
12
+ const tt = [
13
+ ["path", { d: "M18 8L22 12L18 16", key: "1r0oui" }],
14
+ ["path", { d: "M2 12H22", key: "1m8cig" }]
15
+ ], nt = je("move-right", tt);
16
+ function Z(e, r) {
17
+ const o = r.get(e) ?? r.get(e.toLowerCase());
18
+ if (o) return te(o) ?? o;
19
+ const a = K.get(e);
20
+ return a ? te(a) ?? a : void 0;
21
+ }
22
+ function ot(e, r) {
23
+ const o = /* @__PURE__ */ new Map();
24
+ for (const a of e) {
25
+ let c = r.get(a) ?? r.get(a.toLowerCase());
26
+ if (!(c != null && c.symbol)) {
27
+ const g = K.get(a);
28
+ g && (c = g);
29
+ }
30
+ c && (o.set(a, c), o.set(a.toLowerCase(), c));
31
+ }
32
+ return o;
33
+ }
34
+ function ve(e) {
35
+ return [...e].sort().join("|");
36
+ }
37
+ async function rt(e, r) {
38
+ const o = /* @__PURE__ */ new Map();
39
+ if (r.length === 0) return o;
40
+ const a = r.flatMap((c) => [
41
+ {
42
+ address: c,
43
+ abi: xe,
44
+ functionName: "symbol"
45
+ },
46
+ {
47
+ address: c,
48
+ abi: xe,
49
+ functionName: "decimals"
50
+ }
51
+ ]);
52
+ try {
53
+ const c = await e.multicall({
54
+ contracts: a,
55
+ allowFailure: !0
56
+ });
57
+ r.forEach((g, f) => {
58
+ const m = c[f * 2], d = c[f * 2 + 1];
59
+ if ((m == null ? void 0 : m.status) === "success" || (d == null ? void 0 : d.status) === "success") {
60
+ const b = (m == null ? void 0 : m.status) === "success" ? m.result : void 0, v = (d == null ? void 0 : d.status) === "success" ? d.result : 18, L = {
61
+ address: g,
62
+ symbol: b,
63
+ decimals: v,
64
+ logoURI: "",
65
+ name: b ?? ""
66
+ }, _ = te(L) ?? L;
67
+ o.set(g, _), o.set(g.toLowerCase(), _);
68
+ }
69
+ });
70
+ } catch (c) {
71
+ He(c, "sankey-token-metadata"), console.error(`[useSankeyData] Multicall failed for ${r.length} tokens:`, c);
72
+ }
73
+ return o;
74
+ }
75
+ const re = [
76
+ "#E32F2F",
77
+ "#842CFF",
78
+ "#FF562B",
79
+ "#FF923B",
80
+ "#FFD61F",
81
+ "#C8FF00",
82
+ "#31D829",
83
+ "#52FFD2",
84
+ "#0A05FF",
85
+ "#6868FF",
86
+ "#842CFF",
87
+ "#FF65F8",
88
+ "#FF4D00",
89
+ "#FFB800",
90
+ "#7DFF52",
91
+ "#00FFAE",
92
+ "#00BFFF",
93
+ "#0085FF",
94
+ "#6A5ACD",
95
+ "#FF1493",
96
+ "#A020F0",
97
+ "#E0B0FF"
98
+ ], st = 6, it = "__sankey_virtual__";
99
+ function we(e, r) {
100
+ return e.symbol || e.name || String(r);
101
+ }
102
+ function Ce(e, r) {
103
+ const o = Array(e).fill(0), a = Array.from({ length: e }, () => []), c = Array(e).fill(0);
104
+ r.forEach(({ source: d, target: b }) => {
105
+ var v;
106
+ o[b] = (o[b] ?? 0) + 1, (v = a[d]) == null || v.push(b);
107
+ });
108
+ const g = [];
109
+ o.forEach((d, b) => {
110
+ d === 0 && g.push(b);
111
+ });
112
+ let f = 0, m = 0;
113
+ for (; f < g.length; ) {
114
+ const d = g[f];
115
+ f += 1, m += 1, (a[d] ?? []).forEach((v) => {
116
+ c[v] = Math.max(c[v] ?? 0, (c[d] ?? 0) + 1), o[v] = (o[v] ?? 0) - 1, (o[v] ?? 0) === 0 && g.push(v);
117
+ });
118
+ }
119
+ return m !== e ? Array(e).fill(0) : c;
120
+ }
121
+ function ct(e, r) {
122
+ var T;
123
+ if (e.length < 3 || r.length < 2)
124
+ return { nodes: e, links: r };
125
+ const o = e.length, a = Ce(o, r), c = a.length ? Math.max(...a) : 0, g = Array.from(
126
+ { length: o },
127
+ () => []
128
+ ), f = Array.from(
129
+ { length: o },
130
+ () => []
131
+ ), m = Array(o).fill(0);
132
+ r.forEach((y) => {
133
+ var N, E;
134
+ const w = y.value || 0;
135
+ (N = g[y.target]) == null || N.push({ nodeIndex: y.source, weight: w }), (E = f[y.source]) == null || E.push({ nodeIndex: y.target, weight: w }), m[y.source] = (m[y.source] ?? 0) + w, m[y.target] = (m[y.target] ?? 0) + w;
136
+ });
137
+ const d = /* @__PURE__ */ new Map();
138
+ e.forEach((y, w) => {
139
+ const N = a[w] || 0, E = d.get(N);
140
+ if (E) {
141
+ E.push(w);
142
+ return;
143
+ }
144
+ d.set(N, [w]);
145
+ });
146
+ const b = (y, w) => {
147
+ const N = (m[w] || 0) - (m[y] || 0);
148
+ return Math.abs(N) > 1e-6 ? N : we(e[y], y).localeCompare(we(e[w], w));
149
+ };
150
+ for (let y = 0; y <= c; y += 1)
151
+ (T = d.get(y)) == null || T.sort(b);
152
+ const v = /* @__PURE__ */ new Map(), L = () => {
153
+ v.clear();
154
+ for (let y = 0; y <= c; y += 1) {
155
+ const w = d.get(y);
156
+ w && w.forEach((N, E) => {
157
+ v.set(N, E);
158
+ });
159
+ }
160
+ }, _ = (y) => {
161
+ let w = 0, N = 0;
162
+ return y.forEach(({ nodeIndex: E, weight: P }) => {
163
+ var h;
164
+ const U = a[E] || 0, $ = ((h = d.get(U)) == null ? void 0 : h.length) || 1, M = v.get(E) ?? 0, t = $ <= 1 ? 0.5 : M / ($ - 1);
165
+ w += t * P, N += P;
166
+ }), N > 0 ? w / N : null;
167
+ }, F = (y, w) => {
168
+ const N = d.get(y);
169
+ if (!N || N.length < 2)
170
+ return;
171
+ const E = /* @__PURE__ */ new Map();
172
+ N.forEach((P, U) => {
173
+ E.set(P, U);
174
+ }), N.sort((P, U) => {
175
+ const $ = _(w === "incoming" ? g[P] : f[P]), M = _(w === "incoming" ? g[U] : f[U]);
176
+ if ($ !== null && M !== null && Math.abs($ - M) > 1e-6)
177
+ return $ - M;
178
+ if ($ !== null && M === null)
179
+ return -1;
180
+ if ($ === null && M !== null)
181
+ return 1;
182
+ const t = b(P, U);
183
+ return t !== 0 ? t : (E.get(P) || 0) - (E.get(U) || 0);
184
+ }), N.forEach((P, U) => {
185
+ v.set(P, U);
186
+ });
187
+ };
188
+ L();
189
+ for (let y = 0; y < st; y += 1) {
190
+ for (let w = 1; w <= c; w += 1)
191
+ F(w, "incoming");
192
+ for (let w = c - 1; w >= 0; w -= 1)
193
+ F(w, "outgoing");
194
+ }
195
+ const S = [];
196
+ for (let y = 0; y <= c; y += 1) {
197
+ const w = d.get(y);
198
+ w && S.push(...w);
199
+ }
200
+ const R = /* @__PURE__ */ new Map();
201
+ S.forEach((y, w) => {
202
+ R.set(y, w);
203
+ });
204
+ const D = S.map((y, w) => ({
205
+ ...e[y],
206
+ sortOrder: w
207
+ })), B = r.map((y) => {
208
+ const w = R.get(y.source), N = R.get(y.target);
209
+ return w === void 0 || N === void 0 ? y : {
210
+ ...y,
211
+ source: w,
212
+ target: N,
213
+ sourceIndex: w,
214
+ targetIndex: N
215
+ };
216
+ });
217
+ return {
218
+ nodes: D,
219
+ links: B
220
+ };
221
+ }
222
+ function at(e, r) {
223
+ if (!e.length || !r.length)
224
+ return { nodes: e, links: r };
225
+ const o = Ce(e.length, r), a = [...e], c = [];
226
+ let g = 0;
227
+ return r.forEach((f) => {
228
+ const m = o[f.source] ?? 0, d = o[f.target] ?? m;
229
+ if (d - m <= 1) {
230
+ c.push(f);
231
+ return;
232
+ }
233
+ let v = f.source;
234
+ for (let L = m + 1; L < d; L += 1) {
235
+ const _ = a.length;
236
+ a.push({
237
+ name: "",
238
+ tokenAddress: `${it}_${g}`,
239
+ decimals: 18,
240
+ isMiddle: !0,
241
+ isVirtual: !0
242
+ }), c.push({
243
+ ...f,
244
+ source: v,
245
+ target: _,
246
+ sourceIndex: v,
247
+ targetIndex: _
248
+ }), v = _, g += 1;
249
+ }
250
+ c.push({
251
+ ...f,
252
+ source: v,
253
+ target: f.target,
254
+ sourceIndex: v,
255
+ targetIndex: f.target
256
+ });
257
+ }), {
258
+ nodes: a,
259
+ links: c
260
+ };
261
+ }
262
+ function ut(e) {
263
+ const r = Re(), [o, a] = X(/* @__PURE__ */ new Map()), c = Q(o);
264
+ c.current = o;
265
+ const g = V(() => e ? Array.isArray(e) ? e : e.paths : [], [e]), f = V(() => {
266
+ if (!g || g.length === 0) return [];
267
+ const L = /* @__PURE__ */ new Set();
268
+ return g.forEach((_) => {
269
+ L.add(_.tokenIn), L.add(_.tokenOut);
270
+ }), Array.from(L);
271
+ }, [g]), m = Q("");
272
+ m.current = ve(f);
273
+ const d = 56, b = et({ chainId: d });
274
+ return Fe(() => {
275
+ if (f.length === 0 || !b) return;
276
+ let L = !1;
277
+ const _ = ve(f);
278
+ return (async () => {
279
+ var E, P, U, $;
280
+ const S = c.current;
281
+ let R = ot(f, S);
282
+ a(R);
283
+ const D = f.filter(
284
+ (M) => {
285
+ var t, h;
286
+ return M.toLowerCase() !== me.toLowerCase() && !((t = R.get(M)) != null && t.symbol || (h = R.get(M.toLowerCase())) != null && h.symbol);
287
+ }
288
+ );
289
+ if (D.length === 0) return;
290
+ const B = Ve(D).catch((M) => (console.error("[useSankeyData] Error fetching from API", M), [])), T = rt(b, D), [y, w] = await Promise.all([B, T]);
291
+ if (L || m.current !== _) return;
292
+ const N = new Map(R);
293
+ for (const M of y)
294
+ M != null && M.symbol && (N.set(M.address.toLowerCase(), M), N.set(M.address, M));
295
+ for (const M of D) {
296
+ if ((E = N.get(M)) != null && E.symbol || (P = N.get(M.toLowerCase())) != null && P.symbol) continue;
297
+ const t = w.get(M) ?? w.get(M.toLowerCase());
298
+ if (!t) continue;
299
+ const h = ((U = N.get(M)) == null ? void 0 : U.logoURI) || (($ = N.get(M.toLowerCase())) == null ? void 0 : $.logoURI) || "", p = { ...t, logoURI: h || t.logoURI || "" };
300
+ N.set(M, p), N.set(M.toLowerCase(), p);
301
+ const k = t.symbol ?? "", n = t.decimals ?? 18, l = K.get(M);
302
+ if (!(l != null && l.logoURI)) {
303
+ const s = te({
304
+ address: M,
305
+ symbol: k,
306
+ name: k || M,
307
+ decimals: n,
308
+ logoURI: h
309
+ });
310
+ s && K.set(M, s);
311
+ }
312
+ }
313
+ a(N);
314
+ })(), () => {
315
+ L = !0;
316
+ };
317
+ }, [f, b, d, r]), V(() => {
318
+ var M;
319
+ if (!g || g.length === 0)
320
+ return { nodes: [], links: [] };
321
+ const L = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map();
322
+ f.forEach((t) => {
323
+ L.set(t, 0), _.set(t, 0);
324
+ }), g.forEach((t) => {
325
+ _.set(t.tokenIn, (_.get(t.tokenIn) || 0) + 1), L.set(t.tokenOut, (L.get(t.tokenOut) || 0) + 1);
326
+ });
327
+ const F = [], S = /* @__PURE__ */ new Map();
328
+ f.forEach((t, h) => {
329
+ var i, x;
330
+ const p = Z(t, o), k = L.get(t) === 0, n = _.get(t) === 0;
331
+ let l = p == null ? void 0 : p.symbol, u = l || t.slice(0, 6) + "..." + t.slice(-4), s = t;
332
+ (k || n) && l === "WBNB" && (l = "BNB", u = "BNB", s = me), F.push({
333
+ name: u,
334
+ tokenAddress: s,
335
+ symbol: l,
336
+ logoURI: (p == null ? void 0 : p.logoURI) || ((i = K.get(t)) == null ? void 0 : i.logoURI) || ((x = K.get(t.toLowerCase())) == null ? void 0 : x.logoURI),
337
+ decimals: (p == null ? void 0 : p.decimals) || 18,
338
+ isSource: k,
339
+ isSink: n,
340
+ isMiddle: (L.get(t) || 0) > 0 && (_.get(t) || 0) > 0
341
+ }), S.set(t, h);
342
+ });
343
+ const R = (t) => {
344
+ var h;
345
+ return ((h = Z(t, o)) == null ? void 0 : h.decimals) ?? 18;
346
+ }, D = (t, h) => {
347
+ try {
348
+ return Number(q(t).div(q(10).pow(h)).toString());
349
+ } catch {
350
+ return Number(t);
351
+ }
352
+ }, B = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ new Map();
353
+ f.forEach((t) => T.set(t, 0)), g.forEach((t) => T.set(t.tokenOut, (T.get(t.tokenOut) || 0) + 1));
354
+ let y = (M = g[0]) == null ? void 0 : M.tokenIn;
355
+ for (const t of f)
356
+ if (T.get(t) === 0) {
357
+ y = t;
358
+ break;
359
+ }
360
+ if (y) {
361
+ B.set(y, 1);
362
+ const t = Math.max(3, Math.min(10, g.length));
363
+ for (let h = 0; h < t; h++) {
364
+ const p = /* @__PURE__ */ new Map();
365
+ for (const n of g) {
366
+ const l = B.get(n.tokenIn);
367
+ if (l === void 0) continue;
368
+ const u = D(n.amountIn, R(n.tokenIn)), s = D(n.amountOut, R(n.tokenOut));
369
+ if (s <= 0) continue;
370
+ const i = u * l, x = p.get(n.tokenOut) || { valueSum: 0, amountSum: 0 };
371
+ x.valueSum += i, x.amountSum += s, p.set(n.tokenOut, x);
372
+ }
373
+ let k = !1;
374
+ for (const [n, { valueSum: l, amountSum: u }] of p) {
375
+ if (u <= 0) continue;
376
+ const s = l / u, i = B.get(n), x = i === void 0 ? 1 / 0 : Math.abs(i - s) / Math.max(s, 1e-12);
377
+ (i === void 0 || x > 1e-6) && (B.set(n, s), k = !0);
378
+ }
379
+ if (!k) break;
380
+ }
381
+ }
382
+ let w = 0;
383
+ y && B.get(y) && (e && !Array.isArray(e) && e.amountIn ? w = D(e.amountIn, R(y)) * (B.get(y) || 1) : g.forEach((t) => {
384
+ if (t.tokenIn === y) {
385
+ const h = D(t.amountIn, R(t.tokenIn));
386
+ w += h * (B.get(y) || 1);
387
+ }
388
+ }));
389
+ const N = /* @__PURE__ */ new Map();
390
+ let E = 0;
391
+ const P = /* @__PURE__ */ new Map();
392
+ g.forEach((t) => {
393
+ const h = S.get(t.tokenIn), p = S.get(t.tokenOut), k = Z(t.tokenIn, o), n = Z(t.tokenOut, o);
394
+ if (h === void 0 || p === void 0)
395
+ return;
396
+ const l = t.provider || "unknown";
397
+ N.has(l) || (N.set(l, re[E % re.length]), E++);
398
+ const u = h !== void 0 ? F[h] : null, s = p !== void 0 ? F[p] : null;
399
+ let i = (k == null ? void 0 : k.symbol) || t.tokenIn.slice(0, 6), x = (n == null ? void 0 : n.symbol) || t.tokenOut.slice(0, 6);
400
+ u != null && u.isSource && i === "WBNB" && (i = "BNB"), s != null && s.isSink && x === "WBNB" && (x = "BNB");
401
+ const O = B.get(t.tokenIn) || 0, W = D(t.amountIn, R(t.tokenIn));
402
+ D(t.amountOut, R(t.tokenOut));
403
+ const j = W * O, z = `${t.tokenIn}-${t.tokenOut}-${l}`, A = P.get(z), H = Number(t.feeRate);
404
+ A ? (A.value += j || 0, A.amountIn = q(A.amountIn).add(t.amountIn).toFixed(0), A.amountOut = q(A.amountOut).add(t.amountOut).toFixed(0), A.__feeWeightedSum += (W || 0) * (H || 0), A.__amountInWeight += W || 0) : P.set(z, {
405
+ source: h,
406
+ target: p,
407
+ value: j || 1,
408
+ provider: t.provider,
409
+ feeRate: q(t.feeRate).mul(100).toFixed(2),
410
+ amountIn: t.amountIn,
411
+ amountOut: t.amountOut,
412
+ poolAddress: t.pool,
413
+ tokenInSymbol: i,
414
+ tokenOutSymbol: x,
415
+ sourceIndex: h,
416
+ targetIndex: p,
417
+ percent: "0%",
418
+ color: N.get(l) || re[0],
419
+ groupId: z,
420
+ displaySourceLogoURI: u == null ? void 0 : u.logoURI,
421
+ displayTargetLogoURI: s == null ? void 0 : s.logoURI,
422
+ displaySourceDecimals: u == null ? void 0 : u.decimals,
423
+ displayTargetDecimals: s == null ? void 0 : s.decimals,
424
+ __feeWeightedSum: (W || 0) * (H || 0),
425
+ __amountInWeight: W || 0
426
+ });
427
+ });
428
+ const U = Array.from(P.values()).map((t) => {
429
+ const h = w > 0 ? t.value / w * 100 : 0, p = h > 0 && h < 0.01 ? "<0.01%" : `${h.toFixed(2)}%`, k = t.__amountInWeight > 0 ? q(t.__feeWeightedSum).div(t.__amountInWeight).mul(100).toFixed(2) : t.feeRate, { __feeWeightedSum: n, __amountInWeight: l, ...u } = t;
430
+ return {
431
+ ...u,
432
+ percent: p,
433
+ feeRate: k
434
+ };
435
+ }), $ = at(F, U);
436
+ return ct($.nodes, $.links);
437
+ }, [g, f, o, e]);
438
+ }
439
+ function ke(e, r) {
440
+ let o;
441
+ if (r === void 0)
442
+ for (const a of e)
443
+ a != null && (o < a || o === void 0 && a >= a) && (o = a);
444
+ else {
445
+ let a = -1;
446
+ for (let c of e)
447
+ (c = r(c, ++a, e)) != null && (o < c || o === void 0 && c >= c) && (o = c);
448
+ }
449
+ return o;
450
+ }
451
+ function lt(e, r) {
452
+ let o;
453
+ if (r === void 0)
454
+ for (const a of e)
455
+ a != null && (o > a || o === void 0 && a >= a) && (o = a);
456
+ else {
457
+ let a = -1;
458
+ for (let c of e)
459
+ (c = r(c, ++a, e)) != null && (o > c || o === void 0 && c >= c) && (o = c);
460
+ }
461
+ return o;
462
+ }
463
+ function se(e, r) {
464
+ let o = 0;
465
+ if (r === void 0)
466
+ for (let a of e)
467
+ (a = +a) && (o += a);
468
+ else {
469
+ let a = -1;
470
+ for (let c of e)
471
+ (c = +r(c, ++a, e)) && (o += c);
472
+ }
473
+ return o;
474
+ }
475
+ function De(e, r) {
476
+ return e.sourceLinks.length ? e.depth : r - 1;
477
+ }
478
+ function ee(e) {
479
+ return function() {
480
+ return e;
481
+ };
482
+ }
483
+ function Ie(e, r) {
484
+ return ne(e.source, r.source) || e.index - r.index;
485
+ }
486
+ function be(e, r) {
487
+ return ne(e.target, r.target) || e.index - r.index;
488
+ }
489
+ function ne(e, r) {
490
+ return e.y0 - r.y0;
491
+ }
492
+ function ie(e) {
493
+ return e.value;
494
+ }
495
+ function ft(e) {
496
+ return e.index;
497
+ }
498
+ function dt(e) {
499
+ return e.nodes;
500
+ }
501
+ function ht(e) {
502
+ return e.links;
503
+ }
504
+ function Ne(e, r) {
505
+ const o = e.get(r);
506
+ if (!o) throw new Error("missing: " + r);
507
+ return o;
508
+ }
509
+ function Le({ nodes: e }) {
510
+ for (const r of e) {
511
+ let o = r.y0, a = o;
512
+ for (const c of r.sourceLinks)
513
+ c.y0 = o + c.width / 2, o += c.width;
514
+ for (const c of r.targetLinks)
515
+ c.y1 = a + c.width / 2, a += c.width;
516
+ }
517
+ }
518
+ function gt() {
519
+ let e = 0, r = 0, o = 1, a = 1, c = 24, g = 8, f, m = ft, d = De, b, v, L = dt, _ = ht, F = 6;
520
+ function S() {
521
+ const n = { nodes: L.apply(null, arguments), links: _.apply(null, arguments) };
522
+ return R(n), D(n), B(n), T(n), N(n), Le(n), n;
523
+ }
524
+ S.update = function(n) {
525
+ return Le(n), n;
526
+ }, S.nodeId = function(n) {
527
+ return arguments.length ? (m = typeof n == "function" ? n : ee(n), S) : m;
528
+ }, S.nodeAlign = function(n) {
529
+ return arguments.length ? (d = typeof n == "function" ? n : ee(n), S) : d;
530
+ }, S.nodeSort = function(n) {
531
+ return arguments.length ? (b = n, S) : b;
532
+ }, S.nodeWidth = function(n) {
533
+ return arguments.length ? (c = +n, S) : c;
534
+ }, S.nodePadding = function(n) {
535
+ return arguments.length ? (g = f = +n, S) : g;
536
+ }, S.nodes = function(n) {
537
+ return arguments.length ? (L = typeof n == "function" ? n : ee(n), S) : L;
538
+ }, S.links = function(n) {
539
+ return arguments.length ? (_ = typeof n == "function" ? n : ee(n), S) : _;
540
+ }, S.linkSort = function(n) {
541
+ return arguments.length ? (v = n, S) : v;
542
+ }, S.size = function(n) {
543
+ return arguments.length ? (e = r = 0, o = +n[0], a = +n[1], S) : [o - e, a - r];
544
+ }, S.extent = function(n) {
545
+ return arguments.length ? (e = +n[0][0], o = +n[1][0], r = +n[0][1], a = +n[1][1], S) : [[e, r], [o, a]];
546
+ }, S.iterations = function(n) {
547
+ return arguments.length ? (F = +n, S) : F;
548
+ };
549
+ function R({ nodes: n, links: l }) {
550
+ for (const [s, i] of n.entries())
551
+ i.index = s, i.sourceLinks = [], i.targetLinks = [];
552
+ const u = new Map(n.map((s, i) => [m(s, i, n), s]));
553
+ for (const [s, i] of l.entries()) {
554
+ i.index = s;
555
+ let { source: x, target: O } = i;
556
+ typeof x != "object" && (x = i.source = Ne(u, x)), typeof O != "object" && (O = i.target = Ne(u, O)), x.sourceLinks.push(i), O.targetLinks.push(i);
557
+ }
558
+ if (v != null)
559
+ for (const { sourceLinks: s, targetLinks: i } of n)
560
+ s.sort(v), i.sort(v);
561
+ }
562
+ function D({ nodes: n }) {
563
+ for (const l of n)
564
+ l.value = l.fixedValue === void 0 ? Math.max(se(l.sourceLinks, ie), se(l.targetLinks, ie)) : l.fixedValue;
565
+ }
566
+ function B({ nodes: n }) {
567
+ const l = n.length;
568
+ let u = new Set(n), s = /* @__PURE__ */ new Set(), i = 0;
569
+ for (; u.size; ) {
570
+ for (const x of u) {
571
+ x.depth = i;
572
+ for (const { target: O } of x.sourceLinks)
573
+ s.add(O);
574
+ }
575
+ if (++i > l) throw new Error("circular link");
576
+ u = s, s = /* @__PURE__ */ new Set();
577
+ }
578
+ }
579
+ function T({ nodes: n }) {
580
+ const l = n.length;
581
+ let u = new Set(n), s = /* @__PURE__ */ new Set(), i = 0;
582
+ for (; u.size; ) {
583
+ for (const x of u) {
584
+ x.height = i;
585
+ for (const { source: O } of x.targetLinks)
586
+ s.add(O);
587
+ }
588
+ if (++i > l) throw new Error("circular link");
589
+ u = s, s = /* @__PURE__ */ new Set();
590
+ }
591
+ }
592
+ function y({ nodes: n }) {
593
+ const l = ke(n, (i) => i.depth) + 1, u = (o - e - c) / (l - 1), s = new Array(l);
594
+ for (const i of n) {
595
+ const x = Math.max(0, Math.min(l - 1, Math.floor(d.call(null, i, l))));
596
+ i.layer = x, i.x0 = e + x * u, i.x1 = i.x0 + c, s[x] ? s[x].push(i) : s[x] = [i];
597
+ }
598
+ if (b) for (const i of s)
599
+ i.sort(b);
600
+ return s;
601
+ }
602
+ function w(n) {
603
+ const l = lt(n, (u) => (a - r - (u.length - 1) * f) / se(u, ie));
604
+ for (const u of n) {
605
+ let s = r;
606
+ for (const i of u) {
607
+ i.y0 = s, i.y1 = s + i.value * l, s = i.y1 + f;
608
+ for (const x of i.sourceLinks)
609
+ x.width = x.value * l;
610
+ }
611
+ s = (a - s + f) / (u.length + 1);
612
+ for (let i = 0; i < u.length; ++i) {
613
+ const x = u[i];
614
+ x.y0 += s * (i + 1), x.y1 += s * (i + 1);
615
+ }
616
+ h(u);
617
+ }
618
+ }
619
+ function N(n) {
620
+ const l = y(n);
621
+ f = Math.min(g, (a - r) / (ke(l, (u) => u.length) - 1)), w(l);
622
+ for (let u = 0; u < F; ++u) {
623
+ const s = Math.pow(0.99, u), i = Math.max(1 - s, (u + 1) / F);
624
+ P(l, s, i), E(l, s, i);
625
+ }
626
+ }
627
+ function E(n, l, u) {
628
+ for (let s = 1, i = n.length; s < i; ++s) {
629
+ const x = n[s];
630
+ for (const O of x) {
631
+ let W = 0, j = 0;
632
+ for (const { source: A, value: H } of O.targetLinks) {
633
+ let Y = H * (O.layer - A.layer);
634
+ W += p(A, O) * Y, j += Y;
635
+ }
636
+ if (!(j > 0)) continue;
637
+ let z = (W / j - O.y0) * l;
638
+ O.y0 += z, O.y1 += z, t(O);
639
+ }
640
+ b === void 0 && x.sort(ne), U(x, u);
641
+ }
642
+ }
643
+ function P(n, l, u) {
644
+ for (let s = n.length, i = s - 2; i >= 0; --i) {
645
+ const x = n[i];
646
+ for (const O of x) {
647
+ let W = 0, j = 0;
648
+ for (const { target: A, value: H } of O.sourceLinks) {
649
+ let Y = H * (A.layer - O.layer);
650
+ W += k(O, A) * Y, j += Y;
651
+ }
652
+ if (!(j > 0)) continue;
653
+ let z = (W / j - O.y0) * l;
654
+ O.y0 += z, O.y1 += z, t(O);
655
+ }
656
+ b === void 0 && x.sort(ne), U(x, u);
657
+ }
658
+ }
659
+ function U(n, l) {
660
+ const u = n.length >> 1, s = n[u];
661
+ M(n, s.y0 - f, u - 1, l), $(n, s.y1 + f, u + 1, l), M(n, a, n.length - 1, l), $(n, r, 0, l);
662
+ }
663
+ function $(n, l, u, s) {
664
+ for (; u < n.length; ++u) {
665
+ const i = n[u], x = (l - i.y0) * s;
666
+ x > 1e-6 && (i.y0 += x, i.y1 += x), l = i.y1 + f;
667
+ }
668
+ }
669
+ function M(n, l, u, s) {
670
+ for (; u >= 0; --u) {
671
+ const i = n[u], x = (i.y1 - l) * s;
672
+ x > 1e-6 && (i.y0 -= x, i.y1 -= x), l = i.y0 - f;
673
+ }
674
+ }
675
+ function t({ sourceLinks: n, targetLinks: l }) {
676
+ if (v === void 0) {
677
+ for (const { source: { sourceLinks: u } } of l)
678
+ u.sort(be);
679
+ for (const { target: { targetLinks: u } } of n)
680
+ u.sort(Ie);
681
+ }
682
+ }
683
+ function h(n) {
684
+ if (v === void 0)
685
+ for (const { sourceLinks: l, targetLinks: u } of n)
686
+ l.sort(be), u.sort(Ie);
687
+ }
688
+ function p(n, l) {
689
+ let u = n.y0 - (n.sourceLinks.length - 1) * f / 2;
690
+ for (const { target: s, width: i } of n.sourceLinks) {
691
+ if (s === l) break;
692
+ u += i + f;
693
+ }
694
+ for (const { source: s, width: i } of l.targetLinks) {
695
+ if (s === n) break;
696
+ u -= i;
697
+ }
698
+ return u;
699
+ }
700
+ function k(n, l) {
701
+ let u = l.y0 - (l.targetLinks.length - 1) * f / 2;
702
+ for (const { source: s, width: i } of l.targetLinks) {
703
+ if (s === n) break;
704
+ u += i + f;
705
+ }
706
+ for (const { target: s, width: i } of n.sourceLinks) {
707
+ if (s === l) break;
708
+ u -= i;
709
+ }
710
+ return u;
711
+ }
712
+ return S;
713
+ }
714
+ var ue = Math.PI, le = 2 * ue, G = 1e-6, mt = le - G;
715
+ function fe() {
716
+ this._x0 = this._y0 = // start of current subpath
717
+ this._x1 = this._y1 = null, this._ = "";
718
+ }
719
+ function Be() {
720
+ return new fe();
721
+ }
722
+ fe.prototype = Be.prototype = {
723
+ constructor: fe,
724
+ moveTo: function(e, r) {
725
+ this._ += "M" + (this._x0 = this._x1 = +e) + "," + (this._y0 = this._y1 = +r);
726
+ },
727
+ closePath: function() {
728
+ this._x1 !== null && (this._x1 = this._x0, this._y1 = this._y0, this._ += "Z");
729
+ },
730
+ lineTo: function(e, r) {
731
+ this._ += "L" + (this._x1 = +e) + "," + (this._y1 = +r);
732
+ },
733
+ quadraticCurveTo: function(e, r, o, a) {
734
+ this._ += "Q" + +e + "," + +r + "," + (this._x1 = +o) + "," + (this._y1 = +a);
735
+ },
736
+ bezierCurveTo: function(e, r, o, a, c, g) {
737
+ this._ += "C" + +e + "," + +r + "," + +o + "," + +a + "," + (this._x1 = +c) + "," + (this._y1 = +g);
738
+ },
739
+ arcTo: function(e, r, o, a, c) {
740
+ e = +e, r = +r, o = +o, a = +a, c = +c;
741
+ var g = this._x1, f = this._y1, m = o - e, d = a - r, b = g - e, v = f - r, L = b * b + v * v;
742
+ if (c < 0) throw new Error("negative radius: " + c);
743
+ if (this._x1 === null)
744
+ this._ += "M" + (this._x1 = e) + "," + (this._y1 = r);
745
+ else if (L > G) if (!(Math.abs(v * m - d * b) > G) || !c)
746
+ this._ += "L" + (this._x1 = e) + "," + (this._y1 = r);
747
+ else {
748
+ var _ = o - g, F = a - f, S = m * m + d * d, R = _ * _ + F * F, D = Math.sqrt(S), B = Math.sqrt(L), T = c * Math.tan((ue - Math.acos((S + L - R) / (2 * D * B))) / 2), y = T / B, w = T / D;
749
+ Math.abs(y - 1) > G && (this._ += "L" + (e + y * b) + "," + (r + y * v)), this._ += "A" + c + "," + c + ",0,0," + +(v * _ > b * F) + "," + (this._x1 = e + w * m) + "," + (this._y1 = r + w * d);
750
+ }
751
+ },
752
+ arc: function(e, r, o, a, c, g) {
753
+ e = +e, r = +r, o = +o, g = !!g;
754
+ var f = o * Math.cos(a), m = o * Math.sin(a), d = e + f, b = r + m, v = 1 ^ g, L = g ? a - c : c - a;
755
+ if (o < 0) throw new Error("negative radius: " + o);
756
+ this._x1 === null ? this._ += "M" + d + "," + b : (Math.abs(this._x1 - d) > G || Math.abs(this._y1 - b) > G) && (this._ += "L" + d + "," + b), o && (L < 0 && (L = L % le + le), L > mt ? this._ += "A" + o + "," + o + ",0,1," + v + "," + (e - f) + "," + (r - m) + "A" + o + "," + o + ",0,1," + v + "," + (this._x1 = d) + "," + (this._y1 = b) : L > G && (this._ += "A" + o + "," + o + ",0," + +(L >= ue) + "," + v + "," + (this._x1 = e + o * Math.cos(c)) + "," + (this._y1 = r + o * Math.sin(c))));
757
+ },
758
+ rect: function(e, r, o, a) {
759
+ this._ += "M" + (this._x0 = this._x1 = +e) + "," + (this._y0 = this._y1 = +r) + "h" + +o + "v" + +a + "h" + -o + "Z";
760
+ },
761
+ toString: function() {
762
+ return this._;
763
+ }
764
+ };
765
+ function Me(e) {
766
+ return function() {
767
+ return e;
768
+ };
769
+ }
770
+ function pt(e) {
771
+ return e[0];
772
+ }
773
+ function yt(e) {
774
+ return e[1];
775
+ }
776
+ var xt = Array.prototype.slice;
777
+ function vt(e) {
778
+ return e.source;
779
+ }
780
+ function wt(e) {
781
+ return e.target;
782
+ }
783
+ function kt(e) {
784
+ var r = vt, o = wt, a = pt, c = yt, g = null;
785
+ function f() {
786
+ var m, d = xt.call(arguments), b = r.apply(this, d), v = o.apply(this, d);
787
+ if (g || (g = m = Be()), e(g, +a.apply(this, (d[0] = b, d)), +c.apply(this, d), +a.apply(this, (d[0] = v, d)), +c.apply(this, d)), m) return g = null, m + "" || null;
788
+ }
789
+ return f.source = function(m) {
790
+ return arguments.length ? (r = m, f) : r;
791
+ }, f.target = function(m) {
792
+ return arguments.length ? (o = m, f) : o;
793
+ }, f.x = function(m) {
794
+ return arguments.length ? (a = typeof m == "function" ? m : Me(+m), f) : a;
795
+ }, f.y = function(m) {
796
+ return arguments.length ? (c = typeof m == "function" ? m : Me(+m), f) : c;
797
+ }, f.context = function(m) {
798
+ return arguments.length ? (g = m ?? null, f) : g;
799
+ }, f;
800
+ }
801
+ function It(e, r, o, a, c) {
802
+ e.moveTo(r, o), e.bezierCurveTo(r = (r + a) / 2, o, r, c, a, c);
803
+ }
804
+ function bt() {
805
+ return kt(It);
806
+ }
807
+ function Nt(e) {
808
+ return [e.source.x1, e.y0];
809
+ }
810
+ function Lt(e) {
811
+ return [e.target.x0, e.y1];
812
+ }
813
+ function Mt() {
814
+ return bt().source(Nt).target(Lt);
815
+ }
816
+ const St = ({ data: e }) => {
817
+ var b, v, L, _, F;
818
+ const { resolveLogo: r } = Te(), o = {
819
+ ...e.source,
820
+ logoURI: e.displaySourceLogoURI || ((b = e.source) == null ? void 0 : b.logoURI),
821
+ decimals: e.displaySourceDecimals ?? ((v = e.source) == null ? void 0 : v.decimals)
822
+ }, a = {
823
+ ...e.target,
824
+ logoURI: e.displayTargetLogoURI || ((L = e.target) == null ? void 0 : L.logoURI),
825
+ decimals: e.displayTargetDecimals ?? ((_ = e.target) == null ? void 0 : _.decimals)
826
+ }, c = e.poolAddress, g = !!c && !Qe.includes((F = e.provider) == null ? void 0 : F.trim().toUpperCase());
827
+ if (!o || !a) return null;
828
+ const f = r ? r(o.address || o.tokenAddress, o.logoURI) : o.logoURI, m = r ? r(a.address || a.tokenAddress, a.logoURI) : a.logoURI, d = {
829
+ amountIn: e.amountIn,
830
+ amountOut: e.amountOut,
831
+ tokenInSymbol: e.tokenInSymbol,
832
+ tokenOutSymbol: e.tokenOutSymbol,
833
+ feeRate: e.feeRate,
834
+ provider: e.provider,
835
+ percent: e.percent,
836
+ color: e.color
837
+ };
838
+ return /* @__PURE__ */ I("div", { className: "pointer-events-auto min-w-[280px] rounded-2xl border border-border/80 bg-card/95 p-4 text-foreground shadow-2xl backdrop-blur-xl", children: /* @__PURE__ */ C("div", { className: "flex flex-col gap-2", children: [
839
+ /* @__PURE__ */ I("div", { className: "flex items-center justify-between", children: /* @__PURE__ */ C("div", { className: "flex items-center gap-2", children: [
840
+ /* @__PURE__ */ I("div", { className: "rounded-full w-5 h-5 flex items-center justify-center overflow-hidden", children: /* @__PURE__ */ I(
841
+ J,
842
+ {
843
+ fallbackText: d.provider,
844
+ src: Ze(d.provider),
845
+ className: "w-full h-full object-cover"
846
+ }
847
+ ) }),
848
+ /* @__PURE__ */ C("div", { className: "flex flex-col", children: [
849
+ /* @__PURE__ */ C("div", { className: "flex items-center gap-1.5", children: [
850
+ /* @__PURE__ */ I(
851
+ "div",
852
+ {
853
+ className: "w-2 h-2 rounded-full",
854
+ style: { backgroundColor: d.color }
855
+ }
856
+ ),
857
+ /* @__PURE__ */ I("span", { className: "text-sm leading-none text-foreground", children: Ee(d.provider) })
858
+ ] }),
859
+ /* @__PURE__ */ I("p", { className: "text-xs font-medium text-muted-foreground", children: /* @__PURE__ */ I("span", { children: d.percent }) })
860
+ ] })
861
+ ] }) }),
862
+ /* @__PURE__ */ C("div", { className: "bg-input text-foreground rounded-md p-2 flex items-center justify-between gap-1", children: [
863
+ /* @__PURE__ */ C("div", { className: "flex items-center gap-1", children: [
864
+ /* @__PURE__ */ I(
865
+ J,
866
+ {
867
+ fallbackText: d.tokenInSymbol,
868
+ src: f,
869
+ className: "w-4 h-4 rounded-full"
870
+ }
871
+ ),
872
+ /* @__PURE__ */ C("span", { className: "text-xs font-medium leading-none", children: [
873
+ d.amountIn ? ye(d.amountIn, o.decimals || 18, !1) : "0",
874
+ " ",
875
+ /* @__PURE__ */ I("span", { className: "text-muted-foreground", children: d.tokenInSymbol })
876
+ ] })
877
+ ] }),
878
+ /* @__PURE__ */ I(nt, { className: "size-3" }),
879
+ /* @__PURE__ */ C("div", { className: "flex items-center gap-1", children: [
880
+ /* @__PURE__ */ C("span", { className: "text-xs font-medium leading-none", children: [
881
+ d.amountOut ? ye(d.amountOut, a.decimals || 18, !1) : "0",
882
+ " ",
883
+ /* @__PURE__ */ I("span", { className: "text-muted-foreground", children: d.tokenOutSymbol })
884
+ ] }),
885
+ m && /* @__PURE__ */ I(
886
+ J,
887
+ {
888
+ fallbackText: d.tokenOutSymbol,
889
+ src: m,
890
+ className: "w-4 h-4 rounded-full"
891
+ }
892
+ )
893
+ ] })
894
+ ] }),
895
+ /* @__PURE__ */ I("p", { className: "text-xs font-medium text-muted-foreground leading-none mt-1", children: "Pool:" }),
896
+ /* @__PURE__ */ C("div", { className: "flex items-center gap-4 justify-between text-xs font-medium text-muted-foreground relative -top-1", children: [
897
+ /* @__PURE__ */ C("div", { className: "flex items-center gap-1", children: [
898
+ /* @__PURE__ */ C("p", { className: "flex items-center gap-1", children: [
899
+ d.tokenInSymbol,
900
+ " - ",
901
+ d.tokenOutSymbol
902
+ ] }),
903
+ /* @__PURE__ */ C("span", { children: [
904
+ d.feeRate,
905
+ "%"
906
+ ] })
907
+ ] }),
908
+ g ? /* @__PURE__ */ I(Ae, { address: c, showLinkIcon: !0, hoverLight: !0 }) : null
909
+ ] })
910
+ ] }) });
911
+ }, Se = 500, ce = 48, _t = 108, Ot = 40, _e = 2, oe = (e) => (e.x0 + e.x1) / 2, Oe = (e) => (e.y0 + e.y1) / 2;
912
+ function Rt(e) {
913
+ if (!e.length)
914
+ return "";
915
+ const r = e[0];
916
+ let o = r.source.isVirtual ? oe(r.source) : r.source.x1, a = r.source.isVirtual ? Oe(r.source) : r.y0, c = `M${o},${a}`;
917
+ return e.forEach((g) => {
918
+ const f = g.target.isVirtual ? oe(g.target) : g.target.x0, m = g.target.isVirtual ? Oe(g.target) : g.y1, d = (o + f) / 2;
919
+ c += `C${d},${a} ${d},${m} ${f},${m}`, o = f, a = m;
920
+ }), c;
921
+ }
922
+ function Bt({ data: e, height: r = Se }) {
923
+ const o = Q(null), a = Q(null), { resolveLogo: c } = Te();
924
+ Re();
925
+ const { nodes: g, links: f } = ut(e), [m, d] = X(null), [b, v] = X(null), [L, _] = X(!1), [F, S] = X(null), R = Q(null), D = V(() => {
926
+ if (!g.length || !f.length) return null;
927
+ const t = g.map((p, k) => ({ ...p, id: k })), h = f.map((p) => ({
928
+ ...p,
929
+ source: p.source,
930
+ target: p.target,
931
+ value: p.value
932
+ }));
933
+ return { nodes: t, links: h };
934
+ }, [g, f]), B = V(() => {
935
+ if (r !== Se || !f.length) return r;
936
+ const t = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
937
+ f.forEach((k) => {
938
+ h.set(k.source, (h.get(k.source) || 0) + 1), t.set(k.target, (t.get(k.target) || 0) + 1);
939
+ });
940
+ let p = !1;
941
+ for (const k of t.values())
942
+ if (k > 1) {
943
+ p = !0;
944
+ break;
945
+ }
946
+ if (!p) {
947
+ for (const k of h.values())
948
+ if (k > 1) {
949
+ p = !0;
950
+ break;
951
+ }
952
+ }
953
+ return p ? r : 320;
954
+ }, [f, r]), [T, y] = X({ width: 0, height: B });
955
+ Fe(() => {
956
+ if (!o.current) return;
957
+ const t = new ResizeObserver((h) => {
958
+ h[0] && y({
959
+ width: h[0].contentRect.width,
960
+ height: B
961
+ });
962
+ });
963
+ return t.observe(o.current), () => t.disconnect();
964
+ }, [B]);
965
+ const w = V(() => {
966
+ if (!D || T.width === 0) return null;
967
+ const t = gt().nodeWidth(ce).nodePadding(50).extent([
968
+ [0, 10],
969
+ [T.width, T.height - 20]
970
+ ]).nodeAlign(De).nodeSort((h, p) => {
971
+ const k = (h.sortOrder ?? 0) - (p.sortOrder ?? 0);
972
+ return k !== 0 ? k : (p.value ?? 0) - (h.value ?? 0);
973
+ }).linkSort((h, p) => {
974
+ const k = (h.source.sortOrder ?? 0) - (p.source.sortOrder ?? 0);
975
+ if (k !== 0)
976
+ return k;
977
+ const n = (h.target.sortOrder ?? 0) - (p.target.sortOrder ?? 0);
978
+ return n !== 0 ? n : (p.value ?? 0) - (h.value ?? 0);
979
+ }).iterations(128);
980
+ try {
981
+ return t(JSON.parse(JSON.stringify(D)));
982
+ } catch (h) {
983
+ return console.error("[D3Sankey] Layout failed:", h), null;
984
+ }
985
+ }, [D, T]), N = V(() => {
986
+ if (!w) return null;
987
+ const t = w.nodes.map((s) => {
988
+ if (!s.isVirtual)
989
+ return { ...s };
990
+ const i = (s.x0 + s.x1) / 2;
991
+ return {
992
+ ...s,
993
+ x0: i - _e / 2,
994
+ x1: i + _e / 2
995
+ };
996
+ }), h = Array.from(new Set(t.map((s) => s.x0))).sort((s, i) => s - i), p = h[0], k = h[h.length - 1], n = /* @__PURE__ */ new Map();
997
+ [p, k].forEach((s) => {
998
+ const i = t.filter((A) => A.x0 === s);
999
+ if (i.length === 0) return;
1000
+ const x = Math.min(...i.map((A) => A.y0)), W = Math.max(...i.map((A) => A.y1)) - x, z = T.height / 2 - W / 2 - x;
1001
+ i.forEach((A) => {
1002
+ A.y0 += z, A.y1 += z, n.set(A.id, z);
1003
+ });
1004
+ });
1005
+ const l = new Map(t.map((s) => [s.id, s])), u = w.links.map((s) => {
1006
+ const i = l.get(s.source.id), x = l.get(s.target.id);
1007
+ if (!i || !x)
1008
+ return s;
1009
+ const O = n.get(s.source.id) || 0, W = n.get(s.target.id) || 0, j = s.y0 + O, z = s.y1 + W, A = i.isVirtual ? 0 : 12, H = x.isVirtual ? 0 : 12, Y = i.y1 - i.y0, de = x.y1 - x.y0, he = Math.max(0.1, (Y - A * 2) / Y), ge = Math.max(0.1, (de - H * 2) / de), Pe = j - i.y0, Ue = i.y0 + A + Pe * he, $e = z - x.y0, We = x.y0 + H + $e * ge;
1010
+ return {
1011
+ ...s,
1012
+ source: i,
1013
+ target: x,
1014
+ y0: Ue,
1015
+ y1: We,
1016
+ width: s.width * Math.min(he, ge)
1017
+ };
1018
+ });
1019
+ return { nodes: t, links: u };
1020
+ }, [w, T.height]), E = V(() => {
1021
+ if (!N)
1022
+ return [];
1023
+ const t = /* @__PURE__ */ new Map();
1024
+ return N.links.forEach((h, p) => {
1025
+ const k = h.groupId || `link-${p}`, n = t.get(k), l = { ...h, __index: p };
1026
+ if (n) {
1027
+ n.push(l);
1028
+ return;
1029
+ }
1030
+ t.set(k, [l]);
1031
+ }), Array.from(t.entries()).map(([h, p]) => {
1032
+ const k = [...p].sort((u, s) => {
1033
+ const i = (u.source.isVirtual ? oe(u.source) : u.source.x0) - (s.source.isVirtual ? oe(s.source) : s.source.x0);
1034
+ return Math.abs(i) > 1e-6 ? i : u.__index - s.__index;
1035
+ }), n = k[0], l = k[k.length - 1];
1036
+ return {
1037
+ ...n,
1038
+ groupId: h,
1039
+ source: n.source,
1040
+ target: l.target,
1041
+ width: Math.max(Math.min(...k.map((u) => u.width || 0)), 2),
1042
+ path: Rt(k)
1043
+ };
1044
+ });
1045
+ }, [N]), P = (t, h) => {
1046
+ if (R.current && (clearTimeout(R.current), R.current = null), o.current) {
1047
+ const p = o.current.getBoundingClientRect();
1048
+ S({
1049
+ x: h.clientX - p.left,
1050
+ y: h.clientY - p.top
1051
+ });
1052
+ }
1053
+ v(t), _(!0);
1054
+ }, U = () => {
1055
+ R.current = setTimeout(() => {
1056
+ _(!1), v(null);
1057
+ }, 150);
1058
+ }, $ = (t) => `sankey-gradient-${(t || "unknown").replace(/[^a-z0-9_-]/gi, "_")}`, M = V(() => {
1059
+ const t = /* @__PURE__ */ new Map();
1060
+ return E.forEach((h) => {
1061
+ const p = h.provider || "unknown";
1062
+ t.has(p) || t.set(p, h.color);
1063
+ }), Array.from(t.entries());
1064
+ }, [E]);
1065
+ return !g.length || !f.length ? /* @__PURE__ */ I("div", { style: { height: B }, className: "flex items-center justify-center", children: /* @__PURE__ */ I("span", { className: "text-secondary", children: "No routing data | Rendering failed" }) }) : /* @__PURE__ */ C("div", { className: "w-full h-full flex flex-col gap-4 mt-4 relative select-none", ref: o, children: [
1066
+ /* @__PURE__ */ C("div", { style: { width: "100%", height: T.height }, className: "relative", children: [
1067
+ /* @__PURE__ */ C(
1068
+ "svg",
1069
+ {
1070
+ ref: a,
1071
+ width: "100%",
1072
+ height: T.height,
1073
+ viewBox: `0 0 ${T.width} ${T.height}`,
1074
+ className: "overflow-visible",
1075
+ children: [
1076
+ /* @__PURE__ */ I("defs", { children: M.map(([t, h]) => /* @__PURE__ */ C(
1077
+ "linearGradient",
1078
+ {
1079
+ id: $(t),
1080
+ gradientUnits: "userSpaceOnUse",
1081
+ spreadMethod: "repeat",
1082
+ x1: 0,
1083
+ x2: T.width,
1084
+ children: [
1085
+ /* @__PURE__ */ I("stop", { offset: "0%", stopColor: h, stopOpacity: 0.65 }),
1086
+ /* @__PURE__ */ I("stop", { offset: "50%", stopColor: h, stopOpacity: 0.9 }),
1087
+ /* @__PURE__ */ I("stop", { offset: "100%", stopColor: h, stopOpacity: 0.65 }),
1088
+ /* @__PURE__ */ I(
1089
+ "animateTransform",
1090
+ {
1091
+ attributeName: "gradientTransform",
1092
+ type: "translate",
1093
+ from: "0 0",
1094
+ to: `${T.width} 0`,
1095
+ dur: "3.6s",
1096
+ repeatCount: "indefinite"
1097
+ }
1098
+ )
1099
+ ]
1100
+ },
1101
+ t
1102
+ )) }),
1103
+ /* @__PURE__ */ I("g", { children: E.map((t, h) => {
1104
+ const p = b && b.groupId === t.groupId || m === t.provider, k = (b || m) && !p;
1105
+ return /* @__PURE__ */ I(
1106
+ "path",
1107
+ {
1108
+ d: t.path || Mt()(t) || "",
1109
+ fill: "none",
1110
+ stroke: `url(#${$(t.provider)})`,
1111
+ strokeWidth: t.width,
1112
+ opacity: k ? 0.1 : p ? 1 : 0.8,
1113
+ className: "cursor-pointer transition-opacity duration-300",
1114
+ onMouseEnter: (n) => P(t, n),
1115
+ onMouseLeave: U,
1116
+ style: {
1117
+ // Only transition opacity to avoid any path deformation during re-renders
1118
+ transition: "opacity 0.3s ease-in-out"
1119
+ },
1120
+ strokeLinecap: "butt"
1121
+ },
1122
+ `link-${h}`
1123
+ );
1124
+ }) }),
1125
+ /* @__PURE__ */ I("g", { children: N == null ? void 0 : N.nodes.map((t, h) => {
1126
+ if (t.isVirtual)
1127
+ return null;
1128
+ const p = t.isSource || t.isSink ? ce : _t, k = Math.max(t.y1 - t.y0, Ot), n = t.x0 - (p - ce) / 2, l = t.y0 - (k - (t.y1 - t.y0)) / 2, u = (s) => /* @__PURE__ */ C(ze, { children: [
1129
+ /* @__PURE__ */ I("div", { className: "w-5 h-5 rounded-full overflow-hidden shrink-0", children: /* @__PURE__ */ I(
1130
+ J,
1131
+ {
1132
+ fallbackText: t.symbol,
1133
+ src: c ? c(t.address || t.tokenAddress, t.logoURI) : t.logoURI,
1134
+ alt: t.symbol,
1135
+ className: "w-full h-full object-cover"
1136
+ }
1137
+ ) }),
1138
+ /* @__PURE__ */ I("span", { className: "text-foreground text-center leading-tight wrap-break-word text-[12px]", children: pe(t.symbol, 6) || pe(t.name, 6) })
1139
+ ] });
1140
+ return /* @__PURE__ */ I(
1141
+ "foreignObject",
1142
+ {
1143
+ x: n,
1144
+ y: l,
1145
+ width: p,
1146
+ height: k,
1147
+ className: "overflow-visible",
1148
+ children: /* @__PURE__ */ C("div", { className: "relative w-full h-full group cursor-pointer", children: [
1149
+ /* @__PURE__ */ I("div", { className: "absolute inset-0 bg-background/15 border border-border rounded-[12px] backdrop-blur-xl" }),
1150
+ /* @__PURE__ */ I("div", { className: "absolute inset-0 bg-background/10 border border-border rounded-[12px]" }),
1151
+ /* @__PURE__ */ I(
1152
+ "div",
1153
+ {
1154
+ className: ae(
1155
+ "w-full h-full flex items-center justify-center p-1 relative z-10",
1156
+ t.isSource || t.isSink ? "flex-col gap-2" : "flex-row gap-1"
1157
+ ),
1158
+ children: /* @__PURE__ */ C(Ye, { children: [
1159
+ /* @__PURE__ */ I(Ge, { asChild: !0, children: /* @__PURE__ */ I("div", { className: "flex gap-1 items-center justify-center w-full h-auto py-3", children: t.isSource || t.isSink ? /* @__PURE__ */ I("div", { className: "flex flex-col items-center gap-2", children: /* @__PURE__ */ I("div", { className: "w-6 h-6 rounded-full overflow-hidden shrink-0", children: /* @__PURE__ */ I(
1160
+ J,
1161
+ {
1162
+ fallbackText: t.symbol,
1163
+ src: c ? c(
1164
+ t.address || t.tokenAddress,
1165
+ t.logoURI
1166
+ ) : t.logoURI,
1167
+ alt: t.symbol,
1168
+ className: "w-full h-full object-cover"
1169
+ }
1170
+ ) }) }) : u() }) }),
1171
+ /* @__PURE__ */ I(Xe, { className: "max-w-[320px] text-xs z-9999", children: /* @__PURE__ */ C("div", { className: "flex items-center gap-4", children: [
1172
+ /* @__PURE__ */ I("div", { className: "flex gap-1 items-center", children: u() }),
1173
+ /* @__PURE__ */ I(Ae, { address: t.tokenAddress, showLinkIcon: !0, hoverLight: !0 })
1174
+ ] }) })
1175
+ ] })
1176
+ }
1177
+ )
1178
+ ] })
1179
+ },
1180
+ `node-${h}`
1181
+ );
1182
+ }) })
1183
+ ]
1184
+ }
1185
+ ),
1186
+ /* @__PURE__ */ C(qe, { open: L, onOpenChange: _, modal: !1, children: [
1187
+ /* @__PURE__ */ I(
1188
+ Ke,
1189
+ {
1190
+ className: "pointer-events-none absolute",
1191
+ style: {
1192
+ left: F ? F.x : 0,
1193
+ top: F ? F.y : 0,
1194
+ width: 1,
1195
+ height: 1
1196
+ }
1197
+ }
1198
+ ),
1199
+ /* @__PURE__ */ I(
1200
+ Je,
1201
+ {
1202
+ className: "w-fit z-9999 p-0 border-none bg-transparent shadow-none",
1203
+ side: "top",
1204
+ align: "center",
1205
+ sideOffset: 0,
1206
+ onMouseEnter: () => {
1207
+ R.current && (clearTimeout(R.current), R.current = null);
1208
+ },
1209
+ onMouseLeave: U,
1210
+ children: b && /* @__PURE__ */ I(St, { data: b })
1211
+ }
1212
+ )
1213
+ ] })
1214
+ ] }),
1215
+ /* @__PURE__ */ I(
1216
+ Tt,
1217
+ {
1218
+ links: f,
1219
+ hoveredProvider: m,
1220
+ setHoveredProvider: d
1221
+ }
1222
+ )
1223
+ ] });
1224
+ }
1225
+ const Tt = ({
1226
+ links: e,
1227
+ hoveredProvider: r,
1228
+ setHoveredProvider: o
1229
+ }) => {
1230
+ const [a, c] = X(!1), g = V(() => {
1231
+ const v = /* @__PURE__ */ new Set();
1232
+ return e.filter((L) => v.has(L.provider) ? !1 : (v.add(L.provider), !0));
1233
+ }, [e]), m = 7 * 2, d = g.length > m, b = a ? g : g.slice(0, m);
1234
+ return /* @__PURE__ */ C("div", { className: "px-0 pb-2 flex gap-6", children: [
1235
+ /* @__PURE__ */ C("div", { className: "flex flex-wrap gap-y-3 gap-x-10", children: [
1236
+ b.map((v) => /* @__PURE__ */ C(
1237
+ "div",
1238
+ {
1239
+ className: "flex items-center gap-2 cursor-pointer group",
1240
+ onMouseEnter: () => o(v.provider),
1241
+ onMouseLeave: () => o(null),
1242
+ children: [
1243
+ /* @__PURE__ */ I(
1244
+ "div",
1245
+ {
1246
+ className: ae(
1247
+ "w-2 h-2 rounded-full shrink-0 transition-transform"
1248
+ // (hoveredProvider === link.provider) ? "scale-125" : "group-hover:scale-125"
1249
+ ),
1250
+ style: { backgroundColor: v.color || "#fff" }
1251
+ }
1252
+ ),
1253
+ /* @__PURE__ */ I(
1254
+ "span",
1255
+ {
1256
+ className: ae(
1257
+ "text-[12px] whitespace-nowrap transition-colors cursor-pointer",
1258
+ r === v.provider ? "text-foreground" : "text-foreground/70 group-hover:text-foreground"
1259
+ ),
1260
+ children: Ee(v.provider)
1261
+ }
1262
+ )
1263
+ ]
1264
+ },
1265
+ v.provider
1266
+ )),
1267
+ d && !a && /* @__PURE__ */ I(
1268
+ "button",
1269
+ {
1270
+ onClick: () => c(!0),
1271
+ className: "text-[12px] text-[#FF9E44] hover:opacity-80 transition-opacity",
1272
+ children: "Show All"
1273
+ }
1274
+ )
1275
+ ] }),
1276
+ a && d && /* @__PURE__ */ I("div", { className: "flex justify-start", children: /* @__PURE__ */ I(
1277
+ "button",
1278
+ {
1279
+ onClick: () => c(!1),
1280
+ className: "text-[12px] text-[#FF9E44] hover:opacity-80 transition-opacity",
1281
+ children: "Show Less"
1282
+ }
1283
+ ) })
1284
+ ] });
1285
+ };
1286
+ export {
1287
+ Bt as default
1288
+ };