@gearbox-protocol/ui-kit 4.0.0-next.29 → 4.0.0-next.30

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,6 @@
1
+ class t {
2
+ static interval = "slider-interval";
3
+ }
4
+ export {
5
+ t as SliderTest
6
+ };
@@ -1,28 +1,31 @@
1
- import { Slider as o } from "./slider.js";
2
- import { SliderProvider as i, useSliderContext as a } from "./slider-context.js";
3
- import { SliderMark as m } from "./slider-mark.js";
4
- import { SliderTrack as d } from "./slider-track.js";
5
- import { makeMarkerPoints as n, validateMarkerPoints as p } from "./slider-utils.js";
6
- import { THEME_COLOR_MAP as M, THUMB_HALF as S, THUMB_SIZE as v, getIntervalBounds as T, getThumbInBoundsOffset as k, resolveColor as u } from "./types.js";
7
- import { decimalsToStep as c, findClosestPoint as B, formatWithDecimals as C, formatWithoutDecimals as H, splitInterval as I, validateMinMax as _ } from "../../utils/math.js";
1
+ import { SliderTest as o } from "./constants.js";
2
+ import { Slider as i } from "./slider.js";
3
+ import { SliderProvider as l, useSliderContext as m } from "./slider-context.js";
4
+ import { SliderMark as d } from "./slider-mark.js";
5
+ import { SliderTrack as n } from "./slider-track.js";
6
+ import { makeMarkerPoints as x, resolveSnap as M, validateMarkerPoints as S } from "./slider-utils.js";
7
+ import { THEME_COLOR_MAP as T, THUMB_HALF as k, THUMB_SIZE as u, getIntervalBounds as P, getThumbInBoundsOffset as c, resolveColor as B } from "./types.js";
8
+ import { decimalsToStep as H, findClosestPoint as I, formatWithDecimals as _, formatWithoutDecimals as h, splitInterval as E, validateMinMax as O } from "../../utils/math.js";
8
9
  export {
9
- o as Slider,
10
- m as SliderMark,
11
- i as SliderProvider,
12
- d as SliderTrack,
13
- M as THEME_COLOR_MAP,
14
- S as THUMB_HALF,
15
- v as THUMB_SIZE,
16
- c as decimalsToStep,
17
- B as findClosestPoint,
18
- C as formatWithDecimals,
19
- H as formatWithoutDecimals,
20
- T as getIntervalBounds,
21
- k as getThumbInBoundsOffset,
22
- n as makeMarkerPoints,
23
- u as resolveColor,
24
- I as splitInterval,
25
- a as useSliderContext,
26
- p as validateMarkerPoints,
27
- _ as validateMinMax
10
+ i as Slider,
11
+ d as SliderMark,
12
+ l as SliderProvider,
13
+ o as SliderTest,
14
+ n as SliderTrack,
15
+ T as THEME_COLOR_MAP,
16
+ k as THUMB_HALF,
17
+ u as THUMB_SIZE,
18
+ H as decimalsToStep,
19
+ I as findClosestPoint,
20
+ _ as formatWithDecimals,
21
+ h as formatWithoutDecimals,
22
+ P as getIntervalBounds,
23
+ c as getThumbInBoundsOffset,
24
+ x as makeMarkerPoints,
25
+ B as resolveColor,
26
+ M as resolveSnap,
27
+ E as splitInterval,
28
+ m as useSliderContext,
29
+ S as validateMarkerPoints,
30
+ O as validateMinMax
28
31
  };
@@ -1,40 +1,42 @@
1
1
  import { jsx as s, Fragment as m } from "react/jsx-runtime";
2
- import { useMemo as f } from "react";
3
- import { useSliderContext as d } from "./slider-context.js";
4
- import { getIntervalBounds as v, resolveColor as h } from "./types.js";
5
- function k() {
6
- const r = d();
2
+ import { useMemo as d } from "react";
3
+ import { SliderTest as f } from "./constants.js";
4
+ import { useSliderContext as v } from "./slider-context.js";
5
+ import { getIntervalBounds as p, resolveColor as h } from "./types.js";
6
+ function C() {
7
+ const r = v();
7
8
  if (!r) return null;
8
- const { colorIntervals: t, min: n, max: o } = r;
9
+ const { colorIntervals: t, min: o, max: n } = r;
9
10
  if (!t?.length) return null;
10
- const e = o - n;
11
- return e <= 0 ? null : /* @__PURE__ */ s(p, { intervals: t, range: e, min: n });
11
+ const e = n - o;
12
+ return e <= 0 ? null : /* @__PURE__ */ s(x, { intervals: t, range: e, min: o });
12
13
  }
13
- function p({
14
+ function x({
14
15
  intervals: r,
15
16
  range: t,
16
- min: n
17
+ min: o
17
18
  }) {
18
- const o = f(
19
+ const n = d(
19
20
  () => [...r || []].reverse(),
20
21
  [r]
21
22
  );
22
- return /* @__PURE__ */ s(m, { children: o.map((e, u) => {
23
- const { start: l, end: c } = v(e), i = (l - n) / t * 100, a = (c - l) / t * 100;
23
+ return /* @__PURE__ */ s(m, { children: n.map((e, c) => {
24
+ const { start: l, end: i } = p(e), a = (l - o) / t * 100, u = (i - l) / t * 100;
24
25
  return /* @__PURE__ */ s(
25
26
  "div",
26
27
  {
28
+ "data-testid": f.interval,
27
29
  className: "absolute h-full",
28
30
  style: {
29
- left: `${i}%`,
30
- width: `${a}%`,
31
+ left: `${a}%`,
32
+ width: `${u}%`,
31
33
  backgroundColor: h(e.color) ?? "hsl(var(--success))"
32
34
  }
33
35
  },
34
- `interval-${u}-${l}-${c}`
36
+ `interval-${c}-${l}-${i}`
35
37
  );
36
38
  }) });
37
39
  }
38
40
  export {
39
- k as SliderTrack
41
+ C as SliderTrack
40
42
  };
@@ -1,32 +1,49 @@
1
- import { splitInterval as m, formatWithoutDecimals as a } from "../../utils/math.js";
2
- import { decimalsToStep as l, findClosestPoint as y, formatWithDecimals as u, validateMinMax as x } from "../../utils/math.js";
3
- function f(t, i, e) {
1
+ import { splitInterval as h, findClosestPoint as M, formatWithoutDecimals as m } from "../../utils/math.js";
2
+ import { decimalsToStep as g, formatWithDecimals as D, validateMinMax as P } from "../../utils/math.js";
3
+ function k(t, e, s) {
4
4
  if (t.length === 0) return t;
5
5
  const o = t.length - 1, r = {
6
- point: Math.max(t[0].point, i),
6
+ point: Math.max(t[0].point, e),
7
7
  type: t[0].type
8
- }, s = {
9
- point: Math.min(t[o].point, e),
8
+ }, c = {
9
+ point: Math.min(t[o].point, s),
10
10
  type: t[o].type
11
- }, c = t.slice(1, o).reduce((p, n) => (n.point !== r.point && n.point !== s.point && (p[n.point] = n), p), {});
12
- return [r, ...Object.values(c), s];
11
+ }, p = t.slice(1, o).reduce((i, n) => (n.point !== r.point && n.point !== c.point && (i[n.point] = n), i), {});
12
+ return [r, ...Object.values(p), c];
13
13
  }
14
- function d(t, i, e, o, r) {
15
- const s = a(t, e, 1), p = m(s, i, r).map(
14
+ function u(t, e, s, o, r) {
15
+ const c = m(t, s, 1), i = h(c, e, r).map(
16
16
  (n) => ({
17
- point: a(n, e, o),
17
+ point: m(n, s, o),
18
18
  type: "base"
19
19
  })
20
20
  );
21
- return f(p, t, i);
21
+ return k(i, t, e);
22
+ }
23
+ function y(t, { snapPoints: e, intervals: s, epsilon: o, decimals: r }) {
24
+ const { minDistance: c, minPoint: p } = M(
25
+ t,
26
+ [...e],
27
+ r
28
+ );
29
+ if (c >= o)
30
+ return t;
31
+ let i, n = o;
32
+ for (const a of e) {
33
+ const f = Math.abs(a - t);
34
+ f < n && (i = a, n = f);
35
+ }
36
+ const d = s?.some((a) => p >= a.start && p <= a.end);
37
+ return i !== void 0 && !d ? i : p;
22
38
  }
23
39
  export {
24
- l as decimalsToStep,
25
- y as findClosestPoint,
26
- u as formatWithDecimals,
27
- a as formatWithoutDecimals,
28
- d as makeMarkerPoints,
29
- m as splitInterval,
30
- f as validateMarkerPoints,
31
- x as validateMinMax
40
+ g as decimalsToStep,
41
+ M as findClosestPoint,
42
+ D as formatWithDecimals,
43
+ m as formatWithoutDecimals,
44
+ u as makeMarkerPoints,
45
+ y as resolveSnap,
46
+ h as splitInterval,
47
+ k as validateMarkerPoints,
48
+ P as validateMinMax
32
49
  };
@@ -1,4 +1,4 @@
1
- import { jsx as r, jsxs as T } from "react/jsx-runtime";
1
+ import { jsx as o, jsxs as W } from "react/jsx-runtime";
2
2
  import { LEVERAGE_DECIMALS as F } from "@gearbox-protocol/sdk/onchain";
3
3
  import * as P from "@radix-ui/react-slider";
4
4
  import * as H from "react";
@@ -6,14 +6,14 @@ import { useMemo as m, useRef as w, useCallback as J, useState as K, useLayoutEf
6
6
  import { cn as y } from "../../utils/cn.js";
7
7
  import "sonner";
8
8
  import "@gearbox-protocol/sdk/common-utils";
9
- import { findClosestPoint as X, validateMinMax as Y } from "../../utils/math.js";
9
+ import { validateMinMax as X } from "../../utils/math.js";
10
10
  import "luxon";
11
11
  import "../../utils/z-index.js";
12
- import { SliderProvider as Z } from "./slider-context.js";
13
- import { SliderMark as I } from "./slider-mark.js";
14
- import { SliderTrack as ee } from "./slider-track.js";
15
- import { makeMarkerPoints as te } from "./slider-utils.js";
16
- import { getIntervalBounds as ne, getThumbInBoundsOffset as W } from "./types.js";
12
+ import { SliderProvider as Y } from "./slider-context.js";
13
+ import { SliderMark as Z } from "./slider-mark.js";
14
+ import { SliderTrack as I } from "./slider-track.js";
15
+ import { makeMarkerPoints as ee, resolveSnap as te } from "./slider-utils.js";
16
+ import { getIntervalBounds as ne, getThumbInBoundsOffset as D } from "./types.js";
17
17
  const M = Number(F), re = H.forwardRef(
18
18
  ({
19
19
  className: O,
@@ -22,67 +22,69 @@ const M = Number(F), re = H.forwardRef(
22
22
  value: _,
23
23
  onChangeValue: N,
24
24
  onSubmitValue: g,
25
- colorIntervals: o,
25
+ colorIntervals: n,
26
26
  precision: h = 10,
27
27
  markerStep: v = 100,
28
28
  epsilon: j = 8,
29
- colorIntervalLabel: C,
29
+ colorIntervalLabel: L,
30
30
  ...z
31
31
  }, B) => {
32
- const [n, i] = u > p ? [p, u] : [u, p], d = Array.isArray(h) ? h[0] : h, $ = m(() => M / d, [d]), G = m(
33
- () => o?.flatMap((e) => [e.start, e.end]) || [],
34
- [o]
35
- ), L = (e) => {
36
- const { minDistance: t, minPoint: s } = X(
37
- e,
38
- G,
39
- M
40
- );
41
- return t < j ? Y(s, n, i) : e;
42
- }, U = (e) => {
43
- e.length > 0 && N(L(e[0]));
32
+ const [r, s] = u > p ? [p, u] : [u, p], d = Array.isArray(h) ? h[0] : h, $ = m(() => M / d, [d]), G = m(
33
+ () => n?.flatMap((e) => [e.start, e.end]) || [],
34
+ [n]
35
+ ), C = (e) => X(
36
+ te(e, {
37
+ snapPoints: G,
38
+ intervals: n,
39
+ epsilon: j,
40
+ decimals: M
41
+ }),
42
+ r,
43
+ s
44
+ ), U = (e) => {
45
+ e.length > 0 && N(C(e[0]));
44
46
  }, V = (e) => {
45
- g && e.length > 0 && g(L(e[0]));
46
- }, b = m(() => v ? te(
47
- n,
48
- i,
47
+ g && e.length > 0 && g(C(e[0]));
48
+ }, b = m(() => v ? ee(
49
+ r,
50
+ s,
49
51
  M,
50
52
  d,
51
53
  v
52
- ).map((t) => t.point) : void 0, [n, i, d, v]), E = w(null), q = J(() => {
54
+ ).map((t) => t.point) : void 0, [r, s, d, v]), E = w(null), q = J(() => {
53
55
  const e = E.current;
54
56
  if (!e) return;
55
57
  const t = () => {
56
58
  e.dataset.dragging = "";
57
- }, s = () => {
59
+ }, a = () => {
58
60
  document.removeEventListener("pointermove", t), delete e.dataset.dragging;
59
61
  };
60
- document.addEventListener("pointermove", t, { once: !0 }), document.addEventListener("pointerup", s, { once: !0 });
62
+ document.addEventListener("pointermove", t, { once: !0 }), document.addEventListener("pointerup", a, { once: !0 });
61
63
  }, []), R = w(null), k = w(null), [S, A] = K(void 0), f = m(() => {
62
- if (!o?.length) return;
63
- const e = o[o.length - 1], { start: t, end: s } = ne(e), a = i - n;
64
- if (a <= 0) return;
65
- const c = (t - n) / a * 100, l = (s - n) / a * 100, D = W(c), x = W(l);
64
+ if (!n?.length) return;
65
+ const e = n[n.length - 1], { start: t, end: a } = ne(e), i = s - r;
66
+ if (i <= 0) return;
67
+ const c = (t - r) / i * 100, l = (a - r) / i * 100, T = D(c), x = D(l);
66
68
  return {
67
69
  pct: (c + l) / 2,
68
- offsetPx: (D + x) / 2
70
+ offsetPx: (T + x) / 2
69
71
  };
70
- }, [o, n, i]);
72
+ }, [n, r, s]);
71
73
  return Q(() => {
72
74
  const e = R.current, t = k.current;
73
75
  if (!f || !e || !t) {
74
76
  A(void 0);
75
77
  return;
76
78
  }
77
- const s = () => {
79
+ const a = () => {
78
80
  const c = e.offsetWidth, l = t.offsetWidth, x = f.pct / 100 * c + f.offsetPx - l / 2;
79
81
  A(Math.max(0, Math.min(x, c - l)));
80
82
  };
81
- s();
82
- const a = new ResizeObserver(s);
83
- return a.observe(e), () => a.disconnect();
84
- }, [f]), /* @__PURE__ */ r(Z, { colorIntervals: o, min: n, max: i, children: /* @__PURE__ */ T("div", { className: "relative w-full px-[9px] pb-3", children: [
85
- /* @__PURE__ */ r(
83
+ a();
84
+ const i = new ResizeObserver(a);
85
+ return i.observe(e), () => i.disconnect();
86
+ }, [f]), /* @__PURE__ */ o(Y, { colorIntervals: n, min: r, max: s, children: /* @__PURE__ */ W("div", { className: "relative w-full px-[9px] pb-3", children: [
87
+ /* @__PURE__ */ o(
86
88
  "div",
87
89
  {
88
90
  ref: E,
@@ -93,7 +95,7 @@ const M = Number(F), re = H.forwardRef(
93
95
  "[&:not([data-dragging])_span[style]]:[transition-timing-function:cubic-bezier(0.25,0.1,0.25,1)]"
94
96
  ),
95
97
  onPointerDown: q,
96
- children: /* @__PURE__ */ T(
98
+ children: /* @__PURE__ */ W(
97
99
  P.Root,
98
100
  {
99
101
  ref: B,
@@ -101,28 +103,28 @@ const M = Number(F), re = H.forwardRef(
101
103
  "relative flex w-full touch-none select-none items-center",
102
104
  O
103
105
  ),
104
- min: n,
105
- max: i,
106
+ min: r,
107
+ max: s,
106
108
  step: $,
107
109
  value: [_],
108
110
  onValueChange: U,
109
111
  onValueCommit: V,
110
112
  ...z,
111
113
  children: [
112
- /* @__PURE__ */ r(P.Track, { className: "relative h-1 grow overflow-hidden bg-gray-40 mx-[9px] cursor-pointer", children: /* @__PURE__ */ r(ee, {}) }),
113
- b && b.length > 0 && /* @__PURE__ */ r("div", { className: "absolute inset-0 pointer-events-none flex items-center", children: /* @__PURE__ */ r("div", { className: "relative w-full", children: b.map((e) => /* @__PURE__ */ r(
114
- I,
114
+ /* @__PURE__ */ o(P.Track, { className: "relative h-1 grow overflow-hidden bg-gray-40 mx-[9px] cursor-pointer", children: /* @__PURE__ */ o(I, {}) }),
115
+ b && b.length > 0 && /* @__PURE__ */ o("div", { className: "absolute inset-0 pointer-events-none flex items-center", children: /* @__PURE__ */ o("div", { className: "relative w-full", children: b.map((e) => /* @__PURE__ */ o(
116
+ Z,
115
117
  {
116
118
  value: e,
117
- min: n,
118
- max: i,
119
+ min: r,
120
+ max: s,
119
121
  onSelect: (t) => {
120
122
  N(t), g?.(t);
121
123
  }
122
124
  },
123
125
  `mark-${e}`
124
126
  )) }) }),
125
- /* @__PURE__ */ r(
127
+ /* @__PURE__ */ o(
126
128
  P.Thumb,
127
129
  {
128
130
  className: y(
@@ -140,13 +142,13 @@ const M = Number(F), re = H.forwardRef(
140
142
  )
141
143
  }
142
144
  ),
143
- C && o && o.length > 0 && /* @__PURE__ */ r("div", { ref: R, className: "relative h-[14px] mt-2.5", children: /* @__PURE__ */ r(
145
+ L && n && n.length > 0 && /* @__PURE__ */ o("div", { ref: R, className: "relative h-[14px] mt-2.5", children: /* @__PURE__ */ o(
144
146
  "div",
145
147
  {
146
148
  ref: k,
147
149
  className: "absolute text-[11px] font-medium leading-[126%] text-success whitespace-nowrap",
148
150
  style: S !== void 0 ? { left: `${S}px` } : void 0,
149
- children: C
151
+ children: L
150
152
  }
151
153
  ) })
152
154
  ] }) });