@gearbox-protocol/ui-kit 3.13.0-next.1 → 3.13.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.
@@ -1,53 +1,143 @@
1
- import { jsx as s } from "react/jsx-runtime";
2
- import l from "react";
3
- import { getStatic as c } from "../../utils/static.js";
4
- import { RoundedImage as m } from "../rounded-image/rounded-image.js";
5
- const r = c("/tokens/default.svg");
6
- function d(e) {
7
- return e.replace("/", "").replace(" ", "").replace("-f", "").replace("-", "_").toLowerCase();
1
+ import { jsx as r, jsxs as S, Fragment as _ } from "react/jsx-runtime";
2
+ import w from "react";
3
+ import "@gearbox-protocol/sdk";
4
+ import { cn as I } from "../../utils/cn.js";
5
+ import "sonner";
6
+ import "@gearbox-protocol/sdk/common-utils";
7
+ import { getStatic as d } from "../../utils/static.js";
8
+ import "luxon";
9
+ import "../../utils/z-index.js";
10
+ import { RoundedImage as l } from "../rounded-image/rounded-image.js";
11
+ const s = d("/tokens/default.svg");
12
+ function T(t) {
13
+ return t.replace("/", "").replace(" ", "").replace("-f", "").replace("-", "_").toLowerCase();
8
14
  }
9
- function a(e) {
10
- if (!e) return r;
11
- if (typeof e == "object" && e !== null && "icon" in e)
12
- return e.icon;
13
- const n = d(e);
14
- return n ? c(`/tokens/${n}.svg`) : r;
15
+ function j(t) {
16
+ return typeof t == "object" && t !== null && "icon" in t && !("kind" in t);
15
17
  }
16
- const g = l.forwardRef(
17
- ({
18
- symbol: e,
19
- size: n = 48,
20
- fit: o = "contain",
21
- rounded: t = !1,
22
- className: f,
23
- ...i
24
- }, u) => {
25
- const p = a(e);
26
- return /* @__PURE__ */ s(
27
- m,
18
+ function k(t) {
19
+ return typeof t == "object" && t !== null && "kind" in t && t.kind === "composite";
20
+ }
21
+ function u(t) {
22
+ if (t.type === "url") return t.url;
23
+ const o = T(t.symbol);
24
+ return o ? d(`/tokens/${o}.svg`) : s;
25
+ }
26
+ function y(t) {
27
+ if (!t || k(t))
28
+ return s;
29
+ if (j(t))
30
+ return t.icon;
31
+ const o = T(t);
32
+ return o ? d(`/tokens/${o}.svg`) : s;
33
+ }
34
+ function F(t) {
35
+ return t ? k(t) ? t.layers.map(u) : [y(t)] : [s];
36
+ }
37
+ const b = 0.65, L = w.forwardRef(function({ symbol: o, size: e = 48, fit: n = "contain", rounded: c = !1, className: a, ...f }, i) {
38
+ if (k(o))
39
+ return /* @__PURE__ */ r(
40
+ N,
28
41
  {
29
- ref: u,
30
- className: f,
31
- src: p,
32
- alt: "",
33
- rounded: t,
34
- fit: o,
35
- width: n,
36
- height: n,
37
- size: n,
38
- ...i
42
+ ref: i,
43
+ composite: o,
44
+ size: e,
45
+ fit: n,
46
+ rounded: c,
47
+ className: a
39
48
  }
40
49
  );
50
+ const p = y(o);
51
+ return /* @__PURE__ */ r(
52
+ l,
53
+ {
54
+ ref: i,
55
+ className: a,
56
+ src: p,
57
+ alt: "",
58
+ rounded: c,
59
+ fit: n,
60
+ width: e,
61
+ height: e,
62
+ size: e,
63
+ ...f
64
+ }
65
+ );
66
+ }), N = w.forwardRef(function({ composite: o, size: e, fit: n, rounded: c, className: a }, f) {
67
+ const { preset: i, layers: p, scaleFactor: U = b } = o, [C, x] = p, g = u(C), R = u(x), m = Math.round(e * U);
68
+ let h;
69
+ switch (i) {
70
+ case "centered_foreground":
71
+ h = /* @__PURE__ */ S(_, { children: [
72
+ /* @__PURE__ */ r(
73
+ l,
74
+ {
75
+ className: "absolute inset-0",
76
+ style: { zIndex: 0 },
77
+ src: g,
78
+ alt: "background",
79
+ rounded: c,
80
+ fit: n,
81
+ size: e
82
+ }
83
+ ),
84
+ /* @__PURE__ */ r(
85
+ "div",
86
+ {
87
+ className: I(
88
+ "absolute left-1/2 top-1/2 z-[1] -translate-x-1/2 -translate-y-1/2",
89
+ "flex items-center justify-center"
90
+ ),
91
+ style: {
92
+ width: m,
93
+ height: m
94
+ },
95
+ children: /* @__PURE__ */ r(
96
+ l,
97
+ {
98
+ src: R,
99
+ alt: "foreground",
100
+ rounded: c,
101
+ fit: n,
102
+ size: m
103
+ }
104
+ )
105
+ }
106
+ )
107
+ ] });
108
+ break;
109
+ default:
110
+ return console.error("Unknown TokenIcon composite preset", i), /* @__PURE__ */ r(
111
+ l,
112
+ {
113
+ src: g,
114
+ alt: "error",
115
+ rounded: c,
116
+ fit: n,
117
+ size: e
118
+ }
119
+ );
41
120
  }
42
- );
43
- g.displayName = "TokenIcon";
44
- function h(e) {
45
- e.forEach((n) => {
46
- const o = a(n), t = new window.Image();
47
- t.src = o;
48
- });
121
+ return /* @__PURE__ */ r(
122
+ "div",
123
+ {
124
+ ref: f,
125
+ className: I("relative inline-block shrink-0", a),
126
+ style: { width: e, height: e },
127
+ children: h
128
+ }
129
+ );
130
+ });
131
+ N.displayName = "TokenIconComposite";
132
+ L.displayName = "TokenIcon";
133
+ function B(t) {
134
+ for (const o of t)
135
+ for (const e of F(o)) {
136
+ const n = new window.Image();
137
+ n.src = e;
138
+ }
49
139
  }
50
140
  export {
51
- g as TokenIcon,
52
- h as preloadTokenIcons
141
+ L as TokenIcon,
142
+ B as preloadTokenIcons
53
143
  };
@@ -1,19 +1,20 @@
1
- import { jsxs as t, jsx as e } from "react/jsx-runtime";
2
- import { cva as N } from "class-variance-authority";
3
- import x from "react";
4
- import { RoundedImage as y } from "../rounded-image/rounded-image.js";
1
+ import { jsxs as t, jsx as i } from "react/jsx-runtime";
2
+ import { cva as y } from "class-variance-authority";
3
+ import N from "react";
4
+ import { RoundedImage as x } from "../rounded-image/rounded-image.js";
5
5
  import { ShortString as S } from "../short-string/short-string.js";
6
- import { TokenIcon as c } from "../token-icon/token-icon.js";
7
- import { SimpleTooltip as b } from "../tooltip/simple-tooltip.js";
6
+ import { TokenIcon as l } from "../token-icon/token-icon.js";
7
+ import { SimpleTooltip as I } from "../tooltip/simple-tooltip.js";
8
8
  import "../tooltip/tooltip.js";
9
+ import { isIconComposite as b } from "../../types/common.js";
9
10
  import "@gearbox-protocol/sdk";
10
- import { cn as I } from "../../utils/cn.js";
11
+ import { cn as T } from "../../utils/cn.js";
11
12
  import "sonner";
12
13
  import "@gearbox-protocol/sdk/common-utils";
13
- import { getNetworkIcon as T } from "../../utils/network-icons.js";
14
+ import { getNetworkIcon as R } from "../../utils/network-icons.js";
14
15
  import "luxon";
15
16
  import "../../utils/z-index.js";
16
- const R = N("", {
17
+ const _ = y("", {
17
18
  variants: {
18
19
  marginSize: {
19
20
  sm: "gap-1",
@@ -25,52 +26,60 @@ const R = N("", {
25
26
  marginSize: "md"
26
27
  }
27
28
  });
28
- function _(r) {
29
- if (r)
30
- return typeof r == "string" ? r : r.icon ? { icon: r.icon } : r.symbol;
31
- }
32
29
  function j(r) {
30
+ if (r) {
31
+ if (typeof r == "string") return r;
32
+ if (r.icon !== void 0) {
33
+ if (typeof r.icon == "string")
34
+ return { icon: r.icon };
35
+ if (b(r.icon))
36
+ return r.icon;
37
+ }
38
+ return r.symbol;
39
+ }
40
+ }
41
+ function z(r) {
33
42
  if (r)
34
43
  return typeof r == "string" ? r : r.title;
35
44
  }
36
- const z = x.forwardRef(
45
+ const V = N.forwardRef(
37
46
  ({
38
47
  className: r,
39
48
  marginSize: d = "lg",
40
- token: m,
41
- title: n,
42
- size: a = 24,
49
+ token: n,
50
+ title: m,
51
+ size: s = 24,
43
52
  showSymbol: f = !1,
44
53
  showIcon: p = !0,
45
- maxLength: g,
46
- chainId: V,
47
- comment: l,
48
- network: i,
49
- ...u
54
+ maxLength: u,
55
+ chainId: C,
56
+ comment: c,
57
+ network: e,
58
+ ...g
50
59
  }, h) => {
51
- const o = _(m), v = n || j(m), s = () => i ? /* @__PURE__ */ t("div", { className: "relative", children: [
52
- /* @__PURE__ */ e(
53
- c,
60
+ const o = j(n), v = m || z(n), a = () => e ? /* @__PURE__ */ t("div", { className: "relative", children: [
61
+ /* @__PURE__ */ i(
62
+ l,
54
63
  {
55
64
  symbol: o,
56
- size: a,
65
+ size: s,
57
66
  className: "shrink-0 self-center"
58
67
  }
59
68
  ),
60
- /* @__PURE__ */ e("div", { className: "absolute -top-[10px] -right-[7px]", children: /* @__PURE__ */ e(
61
- y,
69
+ /* @__PURE__ */ i("div", { className: "absolute -top-[10px] -right-[7px]", children: /* @__PURE__ */ i(
70
+ x,
62
71
  {
63
- src: T(i),
64
- alt: i,
72
+ src: R(e),
73
+ alt: e,
65
74
  size: 14,
66
75
  rounded: !0
67
76
  }
68
77
  ) })
69
- ] }) : /* @__PURE__ */ e(
70
- c,
78
+ ] }) : /* @__PURE__ */ i(
79
+ l,
71
80
  {
72
81
  symbol: o,
73
- size: a,
82
+ size: s,
74
83
  className: "shrink-0 self-center"
75
84
  }
76
85
  );
@@ -78,22 +87,22 @@ const z = x.forwardRef(
78
87
  "div",
79
88
  {
80
89
  ref: h,
81
- className: I(
90
+ className: T(
82
91
  "flex items-center",
83
- R({ marginSize: d }),
92
+ _({ marginSize: d }),
84
93
  r
85
94
  ),
86
- ...u,
95
+ ...g,
87
96
  children: [
88
- p && o && (i !== void 0 ? /* @__PURE__ */ t(b, { title: s(), children: [
97
+ p && o && (e !== void 0 ? /* @__PURE__ */ t(I, { title: a(), children: [
89
98
  "Network: ",
90
- i
91
- ] }) : s()),
92
- (n || f) && /* @__PURE__ */ t("div", { className: "flex items-center gap-1 self-center", children: [
93
- /* @__PURE__ */ e("div", { children: /* @__PURE__ */ e(S, { maxLength: g, children: v }) }),
94
- l && /* @__PURE__ */ t("div", { className: "text-md text-muted-foreground leading-tight", children: [
99
+ e
100
+ ] }) : a()),
101
+ (m || f) && /* @__PURE__ */ t("div", { className: "flex items-center gap-1 self-center", children: [
102
+ /* @__PURE__ */ i("div", { children: /* @__PURE__ */ i(S, { maxLength: u, children: v }) }),
103
+ c && /* @__PURE__ */ t("div", { className: "text-md text-muted-foreground leading-tight", children: [
95
104
  "(",
96
- l,
105
+ c,
97
106
  ")"
98
107
  ] })
99
108
  ] })
@@ -102,8 +111,8 @@ const z = x.forwardRef(
102
111
  );
103
112
  }
104
113
  );
105
- z.displayName = "TokenSymbol";
114
+ V.displayName = "TokenSymbol";
106
115
  export {
107
- z as TokenSymbol,
108
- _ as getSymbolOrIcon
116
+ V as TokenSymbol,
117
+ j as getSymbolOrIcon
109
118
  };
@@ -1 +1,6 @@
1
-
1
+ function n(o) {
2
+ return typeof o == "object" && o !== null && "kind" in o && o.kind === "composite";
3
+ }
4
+ export {
5
+ n as isIconComposite
6
+ };