@gearbox-protocol/permissionless-ui 1.22.0-next.67 → 1.22.0-next.69

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,28 +1,31 @@
1
1
  import { jsx as f } from "react/jsx-runtime";
2
- import { useSliderContext as u } from "./slider-context.js";
3
- import { getThumbInBoundsOffset as i, getIntervalBounds as d, resolveColor as m } from "./types.js";
4
- function C({ value: r, min: o, max: t }) {
5
- const e = u()?.colorIntervals, s = t - o;
2
+ import { useSliderContext as i } from "./slider-context.js";
3
+ import { getThumbInBoundsOffset as p, getIntervalBounds as d, resolveColor as b } from "./types.js";
4
+ function C({ value: r, min: t, max: o, onClick: n }) {
5
+ const a = i()?.colorIntervals, s = o - t;
6
6
  if (s <= 0) return null;
7
- const l = (r - o) / s * 100, c = i(l), a = p(r, e);
7
+ const c = (r - t) / s * 100, l = p(c), u = m(r, a);
8
8
  return /* @__PURE__ */ f(
9
- "div",
9
+ "button",
10
10
  {
11
- className: "absolute h-2.5 w-2.5 rounded-full -translate-x-1/2 -translate-y-1/2",
11
+ type: "button",
12
+ tabIndex: -1,
13
+ className: "absolute h-2.5 w-2.5 rounded-full -translate-x-1/2 -translate-y-1/2 pointer-events-auto cursor-pointer border-0 p-0 appearance-none bg-transparent",
12
14
  style: {
13
- left: `calc(${l}% + ${c}px)`,
15
+ left: `calc(${c}% + ${l}px)`,
14
16
  top: "50%",
15
- backgroundColor: a ?? "hsl(var(--gray-40))"
16
- }
17
+ backgroundColor: u ?? "hsl(var(--gray-40))"
18
+ },
19
+ onClick: () => n?.(r)
17
20
  }
18
21
  );
19
22
  }
20
- function p(r, o) {
21
- if (o)
22
- for (const t of o) {
23
- const { start: n, end: e } = d(t);
23
+ function m(r, t) {
24
+ if (t)
25
+ for (const o of t) {
26
+ const { start: n, end: e } = d(o);
24
27
  if (r >= n && r <= e)
25
- return m(t.color) ?? "hsl(var(--success))";
28
+ return b(o.color) ?? "hsl(var(--success))";
26
29
  }
27
30
  }
28
31
  export {
@@ -1,9 +1,9 @@
1
- import { jsx as f, jsxs as W } from "react/jsx-runtime";
1
+ import { jsx as u, jsxs as j } from "react/jsx-runtime";
2
2
  import { LEVERAGE_DECIMALS as I } from "@gearbox-protocol/sdk";
3
3
  import * as C from "@radix-ui/react-slider";
4
4
  import * as X from "react";
5
- import { useMemo as y, useRef as j, useState as q, useLayoutEffect as H } from "react";
6
- import { cn as B } from "../../utils/cn.js";
5
+ import { useMemo as y, useRef as B, useState as q, useLayoutEffect as H } from "react";
6
+ import { cn as V } from "../../utils/cn.js";
7
7
  import "sonner";
8
8
  import "luxon";
9
9
  import { SliderProvider as J } from "./slider-context.js";
@@ -17,23 +17,23 @@ function R(t, n, o) {
17
17
  }
18
18
  function Y(t, n, o, a) {
19
19
  const r = /* @__PURE__ */ new Set([t]);
20
- for (let i = 1; n >= t + o * i; i += 1)
21
- r.add(t + o * i);
22
- return r.add(n), [...r].sort((i, s) => i - s);
20
+ for (let s = 1; n >= t + o * s; s += 1)
21
+ r.add(t + o * s);
22
+ return r.add(n), [...r].sort((s, i) => s - i);
23
23
  }
24
24
  function Z(t, n, o) {
25
25
  if (t.length === 0) return t;
26
26
  const a = t.length - 1, r = {
27
27
  point: Math.max(t[0].point, n),
28
28
  type: t[0].type
29
- }, i = {
29
+ }, s = {
30
30
  point: Math.min(t[a].point, o),
31
31
  type: t[a].type
32
- }, s = t.slice(1, a).reduce((l, c) => (c.point !== r.point && c.point !== i.point && (l[c.point] = c), l), {});
33
- return [r, ...Object.values(s), i];
32
+ }, i = t.slice(1, a).reduce((l, c) => (c.point !== r.point && c.point !== s.point && (l[c.point] = c), l), {});
33
+ return [r, ...Object.values(i), s];
34
34
  }
35
35
  function tt(t, n, o, a, r) {
36
- const i = R(t, o, 1), l = Y(i, n, r).map(
36
+ const s = R(t, o, 1), l = Y(s, n, r).map(
37
37
  (c) => ({
38
38
  point: R(c, o, a),
39
39
  type: "base"
@@ -42,15 +42,15 @@ function tt(t, n, o, a, r) {
42
42
  return Z(l, t, n);
43
43
  }
44
44
  function et(t, n, o) {
45
- const a = t, r = R(a, o, 1), i = Math.abs(r - a), s = n.reduce(
45
+ const a = t, r = R(a, o, 1), s = Math.abs(r - a), i = n.reduce(
46
46
  (p, x) => {
47
47
  const N = x !== void 0 ? Math.abs(x - a) : Number.MAX_SAFE_INTEGER;
48
48
  return p[N] = x || 0, p;
49
49
  },
50
50
  []
51
51
  ), l = {
52
- [i]: r,
53
- ...s
52
+ [s]: r,
53
+ ...i
54
54
  }, c = Math.min(
55
55
  ...Object.keys(l).map((p) => Number(p))
56
56
  );
@@ -66,88 +66,91 @@ const ot = X.forwardRef(
66
66
  to: o,
67
67
  value: a,
68
68
  onChangeValue: r,
69
- onSubmitValue: i,
70
- colorIntervals: s,
69
+ onSubmitValue: s,
70
+ colorIntervals: i,
71
71
  precision: l = 10,
72
72
  markerStep: c = 100,
73
- epsilon: S = 8,
73
+ epsilon: A = 8,
74
74
  colorIntervalLabel: p,
75
75
  ...x
76
76
  }, N) => {
77
- const [d, u] = n > o ? [o, n] : [n, o], M = Array.isArray(l) ? l[0] : l, F = y(() => E / M, [M]), G = y(
78
- () => s?.flatMap((e) => [e.start, e.end]) || [],
79
- [s]
80
- ), A = (e) => {
81
- const { minDistance: m, minPoint: h } = et(
77
+ const [f, m] = n > o ? [o, n] : [n, o], v = Array.isArray(l) ? l[0] : l, F = y(() => E / v, [v]), G = y(
78
+ () => i?.flatMap((e) => [e.start, e.end]) || [],
79
+ [i]
80
+ ), D = (e) => {
81
+ const { minDistance: d, minPoint: h } = et(
82
82
  e,
83
83
  G,
84
84
  E
85
85
  );
86
- return m < S ? nt(h, d, u) : e;
86
+ return d < A ? nt(h, f, m) : e;
87
87
  }, $ = (e) => {
88
- e.length > 0 && r(A(e[0]));
88
+ e.length > 0 && r(D(e[0]));
89
89
  }, z = (e) => {
90
- i && e.length > 0 && i(A(e[0]));
90
+ s && e.length > 0 && s(D(e[0]));
91
91
  }, k = y(() => c ? tt(
92
- d,
93
- u,
92
+ f,
93
+ m,
94
94
  E,
95
- M,
95
+ v,
96
96
  c
97
- ).map((m) => m.point) : void 0, [d, u, M, c]), D = j(null), L = j(null), [T, O] = q(void 0), P = y(() => {
98
- if (!s?.length) return;
99
- const e = s[s.length - 1], { start: m, end: h } = U(e), b = u - d;
97
+ ).map((d) => d.point) : void 0, [f, m, v, c]), L = B(null), S = B(null), [T, O] = q(void 0), P = y(() => {
98
+ if (!i?.length) return;
99
+ const e = i[i.length - 1], { start: d, end: h } = U(e), b = m - f;
100
100
  if (b <= 0) return;
101
- const g = (m - d) / b * 100, v = (h - d) / b * 100, V = _(g), w = _(v);
101
+ const g = (d - f) / b * 100, M = (h - f) / b * 100, W = _(g), w = _(M);
102
102
  return {
103
- pct: (g + v) / 2,
104
- offsetPx: (V + w) / 2
103
+ pct: (g + M) / 2,
104
+ offsetPx: (W + w) / 2
105
105
  };
106
- }, [s, d, u]);
106
+ }, [i, f, m]);
107
107
  return H(() => {
108
- const e = D.current, m = L.current;
109
- if (!P || !e || !m) {
108
+ const e = L.current, d = S.current;
109
+ if (!P || !e || !d) {
110
110
  O(void 0);
111
111
  return;
112
112
  }
113
113
  const h = () => {
114
- const g = e.offsetWidth, v = m.offsetWidth, w = P.pct / 100 * g + P.offsetPx - v / 2;
115
- O(Math.max(0, Math.min(w, g - v)));
114
+ const g = e.offsetWidth, M = d.offsetWidth, w = P.pct / 100 * g + P.offsetPx - M / 2;
115
+ O(Math.max(0, Math.min(w, g - M)));
116
116
  };
117
117
  h();
118
118
  const b = new ResizeObserver(h);
119
119
  return b.observe(e), () => b.disconnect();
120
- }, [P]), /* @__PURE__ */ f(J, { colorIntervals: s, min: d, max: u, children: /* @__PURE__ */ W("div", { className: "relative w-full px-[9px] pb-3", children: [
121
- /* @__PURE__ */ f("div", { className: "relative", children: /* @__PURE__ */ W(
120
+ }, [P]), /* @__PURE__ */ u(J, { colorIntervals: i, min: f, max: m, children: /* @__PURE__ */ j("div", { className: "relative w-full px-[9px] pb-3", children: [
121
+ /* @__PURE__ */ u("div", { className: "relative", children: /* @__PURE__ */ j(
122
122
  C.Root,
123
123
  {
124
124
  ref: N,
125
- className: B(
125
+ className: V(
126
126
  "relative flex w-full touch-none select-none items-center",
127
127
  t
128
128
  ),
129
- min: d,
130
- max: u,
129
+ min: f,
130
+ max: m,
131
131
  step: F,
132
132
  value: [a],
133
133
  onValueChange: $,
134
134
  onValueCommit: z,
135
135
  ...x,
136
136
  children: [
137
- /* @__PURE__ */ f(C.Track, { className: "relative h-1 grow overflow-hidden bg-gray-40 mx-[9px]", children: /* @__PURE__ */ f(Q, {}) }),
138
- k && k.length > 0 && /* @__PURE__ */ f("div", { className: "absolute inset-0 pointer-events-none flex items-center", children: /* @__PURE__ */ f("div", { className: "relative w-full", children: k.map((e) => /* @__PURE__ */ f(
137
+ /* @__PURE__ */ u(C.Track, { className: "relative h-1 grow overflow-hidden bg-gray-40 mx-[9px] cursor-pointer", children: /* @__PURE__ */ u(Q, {}) }),
138
+ k && k.length > 0 && /* @__PURE__ */ u("div", { className: "absolute inset-0 pointer-events-none flex items-center", children: /* @__PURE__ */ u("div", { className: "relative w-full", children: k.map((e) => /* @__PURE__ */ u(
139
139
  K,
140
140
  {
141
141
  value: e,
142
- min: d,
143
- max: u
142
+ min: f,
143
+ max: m,
144
+ onClick: (d) => {
145
+ r(d), s?.(d);
146
+ }
144
147
  },
145
148
  `mark-${e}`
146
149
  )) }) }),
147
- /* @__PURE__ */ f(
150
+ /* @__PURE__ */ u(
148
151
  C.Thumb,
149
152
  {
150
- className: B(
153
+ className: V(
151
154
  "relative block h-[18px] w-[18px] rounded-full bg-foreground",
152
155
  "cursor-grab active:cursor-grabbing",
153
156
  "focus-visible:outline-none",
@@ -160,10 +163,10 @@ const ot = X.forwardRef(
160
163
  ]
161
164
  }
162
165
  ) }),
163
- p && s && s.length > 0 && /* @__PURE__ */ f("div", { ref: D, className: "relative h-[14px] mt-2.5", children: /* @__PURE__ */ f(
166
+ p && i && i.length > 0 && /* @__PURE__ */ u("div", { ref: L, className: "relative h-[14px] mt-2.5", children: /* @__PURE__ */ u(
164
167
  "div",
165
168
  {
166
- ref: L,
169
+ ref: S,
167
170
  className: "absolute text-[11px] font-medium leading-[126%] text-success whitespace-nowrap",
168
171
  style: T !== void 0 ? { left: `${T}px` } : void 0,
169
172
  children: p