@spear-ai/spectral 1.3.9 → 1.3.11
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/.js +91 -0
- package/dist/Accordion/AccordionBase.js +233 -0
- package/dist/App.js +8 -0
- package/dist/Badge/BadgeBase.js +35 -0
- package/dist/Badge.js +7 -0
- package/dist/Button.js +99 -0
- package/dist/Card.js +35 -0
- package/dist/Checkbox/CheckboxBase.js +141 -0
- package/dist/Drawer.js +1293 -0
- package/dist/Icons/AnnotationsIcon.js +28 -0
- package/dist/Icons/CalendarIcon.js +60 -0
- package/dist/Icons/ClockIcon.js +40 -0
- package/dist/Icons/DeleteIcon.js +32 -0
- package/dist/Icons/DurationIcon.js +80 -0
- package/dist/Icons/EraserIcon.js +37 -0
- package/dist/Icons/GoToFirstIcon.js +40 -0
- package/dist/Icons/GoToLastIcon.js +40 -0
- package/dist/Icons/IconBase.js +33 -0
- package/dist/Icons/LabelIcon.js +27 -0
- package/dist/Icons/LassoIcon.js +50 -0
- package/dist/Icons/LineToolIcon.js +96 -0
- package/dist/Icons/LiveViewIcon.js +70 -0
- package/dist/Icons/LocationIcon.js +40 -0
- package/dist/Icons/MetadataIcon.js +28 -0
- package/dist/Icons/OntologyIcon.js +31 -0
- package/dist/Icons/PlayIcon.js +28 -0
- package/dist/Icons/PlusIcon.js +27 -0
- package/dist/Icons/ResetIcon.js +25 -0
- package/dist/Icons/ScissorsIcon.js +36 -0
- package/dist/Icons/TrashIcon.js +25 -0
- package/dist/Icons/UndoIcon.js +28 -0
- package/dist/Icons/ZoomAllIcon.js +28 -0
- package/dist/Icons/ZoomXIcon.js +41 -0
- package/dist/Icons/ZoomYIcon.js +41 -0
- package/dist/Icons/iconTypes.js +2 -0
- package/dist/Icons.js +51 -0
- package/dist/Label.js +13 -0
- package/dist/Popover.js +250 -0
- package/dist/RadioGroup/RadioGroupBase.js +254 -0
- package/dist/Skeleton.js +10 -0
- package/dist/Slider/SliderBase.js +315 -0
- package/dist/Slider.js +74 -0
- package/dist/Switch/SwitchBase.js +131 -0
- package/dist/Switch.js +59 -0
- package/dist/Toggle/ToggleBase.js +51 -0
- package/dist/Toggle.js +51 -0
- package/dist/ToggleGroup/ToggleGroupBase.js +125 -0
- package/dist/ToggleGroup.js +53 -0
- package/dist/Toolbar.js +13 -0
- package/dist/Tooltip/TooltipBase.js +225 -0
- package/dist/Tooltip.js +371 -0
- package/dist/features/LabelingTools/LabelingTools.d.ts.map +1 -0
- package/dist/features/LabelingTools.js +107 -0
- package/dist/hooks/useAccordionAutoScroll.js +65 -0
- package/dist/hooks/useOutsideClick.js +16 -0
- package/dist/hooks/useTheme.js +19 -0
- package/dist/index-B7LSgz_k.js +446 -0
- package/dist/index-CRBC94ik.js +34 -0
- package/dist/index-gg2zpNk0.js +672 -0
- package/dist/index-sDEISz8i.js +1558 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/loader-circle-Btf6jOd5.js +101 -0
- package/dist/main.js +25212 -0
- package/dist/primitives/label.js +27 -0
- package/dist/primitives/slot.js +40 -0
- package/dist/twUtils-CRiPKpXj.js +2743 -0
- package/dist/utils/refs.js +10 -0
- package/dist/utils/shared.js +29 -0
- package/dist/utils/twUtils.js +5 -0
- package/package.json +19 -15
- package/dist/components/LabelingTools/LabelingTools.d.ts.map +0 -1
- package/dist/index.js +0 -8443
- package/dist/spectral.cjs.js +0 -83
- /package/dist/{components → features}/LabelingTools/LabelingTools.d.ts +0 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import './assets/main.css'
|
|
2
|
+
import { jsx as j, jsxs as M } from "react/jsx-runtime";
|
|
3
|
+
import { Slot as S } from "../primitives/slot.js";
|
|
4
|
+
import { createContext as T, forwardRef as L, useId as U, useState as P, useRef as E, useEffect as I, useCallback as C, useContext as $, useImperativeHandle as B } from "react";
|
|
5
|
+
function q(...s) {
|
|
6
|
+
return s.filter(Boolean).join(" ");
|
|
7
|
+
}
|
|
8
|
+
const H = T(null);
|
|
9
|
+
function z(s) {
|
|
10
|
+
const { value: i, defaultValue: t, onChange: r } = s, [d, n] = P(t), u = i !== void 0, R = u ? i : d, l = C(
|
|
11
|
+
(e) => {
|
|
12
|
+
u || n(e), r?.(e);
|
|
13
|
+
},
|
|
14
|
+
[u, r]
|
|
15
|
+
);
|
|
16
|
+
return [R, l];
|
|
17
|
+
}
|
|
18
|
+
function J(s, i, t, r) {
|
|
19
|
+
const d = s.length;
|
|
20
|
+
let n = i;
|
|
21
|
+
for (let u = 0; u < d; u += 1) {
|
|
22
|
+
if (n = t === "next" ? n + 1 : n - 1, r && (n < 0 && (n = d - 1), n >= d && (n = 0)), n < 0 || n >= d) return i;
|
|
23
|
+
if (!s[n].disabled) return n;
|
|
24
|
+
}
|
|
25
|
+
return i;
|
|
26
|
+
}
|
|
27
|
+
function Q(s, i, t) {
|
|
28
|
+
const { key: r } = s;
|
|
29
|
+
return r === "Home" ? "first" : r === "End" ? "last" : i === "vertical" ? r === "ArrowDown" ? "next" : r === "ArrowUp" ? "prev" : null : r === "ArrowRight" ? t === "rtl" ? "prev" : "next" : r === "ArrowLeft" ? t === "rtl" ? "next" : "prev" : null;
|
|
30
|
+
}
|
|
31
|
+
const W = L(
|
|
32
|
+
({
|
|
33
|
+
asChild: s,
|
|
34
|
+
className: i,
|
|
35
|
+
value: t,
|
|
36
|
+
defaultValue: r,
|
|
37
|
+
onValueChange: d,
|
|
38
|
+
name: n,
|
|
39
|
+
required: u = !1,
|
|
40
|
+
form: R,
|
|
41
|
+
disabled: l = !1,
|
|
42
|
+
orientation: e = "vertical",
|
|
43
|
+
dir: V = "ltr",
|
|
44
|
+
loop: b = !0,
|
|
45
|
+
id: v,
|
|
46
|
+
...f
|
|
47
|
+
}, p) => {
|
|
48
|
+
const m = U(), O = v ?? `rg-${m}`, [x, y] = z({
|
|
49
|
+
value: t,
|
|
50
|
+
defaultValue: r ?? void 0,
|
|
51
|
+
onChange: d
|
|
52
|
+
}), [A, g] = P(x), k = E([]), G = E(null);
|
|
53
|
+
I(() => {
|
|
54
|
+
x !== void 0 && g(x);
|
|
55
|
+
}, [x]), I(() => {
|
|
56
|
+
const c = G.current;
|
|
57
|
+
if (!c) return;
|
|
58
|
+
const a = () => {
|
|
59
|
+
y(r ?? void 0);
|
|
60
|
+
};
|
|
61
|
+
return c.addEventListener("reset", a), () => c.removeEventListener("reset", a);
|
|
62
|
+
}, [r, y]);
|
|
63
|
+
const o = C((c) => (k.current.push(c), () => {
|
|
64
|
+
k.current = k.current.filter((a) => a.value !== c.value);
|
|
65
|
+
}), []), h = C(
|
|
66
|
+
(c, a) => {
|
|
67
|
+
l || (y(c), a?.focus && (g(c), k.current.find((K) => K.value === c)?.ref.current?.focus()));
|
|
68
|
+
},
|
|
69
|
+
[l, y]
|
|
70
|
+
), w = {
|
|
71
|
+
value: x,
|
|
72
|
+
setValue: h,
|
|
73
|
+
name: n,
|
|
74
|
+
required: u,
|
|
75
|
+
form: R,
|
|
76
|
+
disabled: l,
|
|
77
|
+
orientation: e,
|
|
78
|
+
dir: V,
|
|
79
|
+
loop: b,
|
|
80
|
+
registerItem: o,
|
|
81
|
+
focusableValue: A,
|
|
82
|
+
setFocusableValue: g,
|
|
83
|
+
formElRef: G,
|
|
84
|
+
itemsRef: k
|
|
85
|
+
}, N = s ? S : "div", F = p;
|
|
86
|
+
return /* @__PURE__ */ j(H.Provider, { value: w, children: /* @__PURE__ */ j(
|
|
87
|
+
N,
|
|
88
|
+
{
|
|
89
|
+
id: O,
|
|
90
|
+
ref: F,
|
|
91
|
+
role: "radiogroup",
|
|
92
|
+
"aria-orientation": e,
|
|
93
|
+
"data-disabled": l ? "" : void 0,
|
|
94
|
+
className: q(i),
|
|
95
|
+
...f
|
|
96
|
+
}
|
|
97
|
+
) });
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
W.displayName = "RadioGroup";
|
|
101
|
+
const X = L(
|
|
102
|
+
({ asChild: s, className: i, value: t, disabled: r, id: d, onKeyDown: n, onClick: u, ...R }, l) => {
|
|
103
|
+
const e = $(H);
|
|
104
|
+
if (!e) throw new Error("RadioGroupItem must be used within RadioGroup");
|
|
105
|
+
const V = U(), b = d ?? `rgi-${V}`, v = E(null), f = E(null);
|
|
106
|
+
B(
|
|
107
|
+
l,
|
|
108
|
+
() => v.current,
|
|
109
|
+
[]
|
|
110
|
+
);
|
|
111
|
+
const p = e.value === t, m = !!r || e.disabled;
|
|
112
|
+
I(() => {
|
|
113
|
+
const o = { value: t, ref: v, disabled: !!m, id: b };
|
|
114
|
+
return e.registerItem(o);
|
|
115
|
+
}, [t, m, b]), I(() => {
|
|
116
|
+
!e.formElRef.current && f.current?.form && (e.formElRef.current = f.current.form);
|
|
117
|
+
}, [e.formElRef]), I(() => {
|
|
118
|
+
f.current && (f.current.checked = p);
|
|
119
|
+
}, [p]);
|
|
120
|
+
const x = (e.focusableValue ? e.focusableValue === t : p) && !m ? 0 : -1, y = s ? S : "button", A = (o) => {
|
|
121
|
+
v.current = o;
|
|
122
|
+
}, g = C(
|
|
123
|
+
(o) => {
|
|
124
|
+
if (!m && (e.setValue(t, { focus: !0, user: o }), f.current)) {
|
|
125
|
+
const h = new Event("change", { bubbles: !0 });
|
|
126
|
+
f.current.dispatchEvent(h);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
[e, m, t]
|
|
130
|
+
), k = C(
|
|
131
|
+
(o) => {
|
|
132
|
+
u?.(o), !o.defaultPrevented && g(!0);
|
|
133
|
+
},
|
|
134
|
+
[u, g]
|
|
135
|
+
), G = C(
|
|
136
|
+
(o) => {
|
|
137
|
+
if (n?.(o), o.defaultPrevented) return;
|
|
138
|
+
if (o.key === " " || o.key === "Enter") {
|
|
139
|
+
o.preventDefault(), g(!0);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const h = Q(o, e.orientation, e.dir);
|
|
143
|
+
if (h) {
|
|
144
|
+
o.preventDefault();
|
|
145
|
+
const w = [...e.itemsRef.current], N = w.findIndex((a) => a.value === t);
|
|
146
|
+
if (N === -1) return;
|
|
147
|
+
if (h === "first") {
|
|
148
|
+
const a = w.find((D) => !D.disabled);
|
|
149
|
+
a && e.setValue(a.value, { focus: !0, user: !0 });
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (h === "last") {
|
|
153
|
+
const a = [...w].reverse().find((D) => !D.disabled);
|
|
154
|
+
a && e.setValue(a.value, { focus: !0, user: !0 });
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const F = J(w, N, h, e.loop), c = w[F];
|
|
158
|
+
c && !c.disabled && e.setValue(c.value, { focus: !0, user: !0 });
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
[e, n, g, t]
|
|
162
|
+
);
|
|
163
|
+
return /* @__PURE__ */ M(
|
|
164
|
+
y,
|
|
165
|
+
{
|
|
166
|
+
id: b,
|
|
167
|
+
ref: A,
|
|
168
|
+
type: "button",
|
|
169
|
+
role: "radio",
|
|
170
|
+
"aria-checked": p,
|
|
171
|
+
"aria-disabled": m || void 0,
|
|
172
|
+
"data-state": p ? "checked" : "unchecked",
|
|
173
|
+
"data-disabled": m ? "" : void 0,
|
|
174
|
+
tabIndex: x,
|
|
175
|
+
onClick: k,
|
|
176
|
+
onKeyDown: G,
|
|
177
|
+
className: q(
|
|
178
|
+
"inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full",
|
|
179
|
+
"border-input bg-background border",
|
|
180
|
+
"focus-visible:ring-ring focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",
|
|
181
|
+
"data-[state=checked]:border-primary data-[state=checked]:bg-primary/10",
|
|
182
|
+
"disabled:cursor-not-allowed disabled:opacity-50",
|
|
183
|
+
i
|
|
184
|
+
),
|
|
185
|
+
...R,
|
|
186
|
+
children: [
|
|
187
|
+
/* @__PURE__ */ j(
|
|
188
|
+
"input",
|
|
189
|
+
{
|
|
190
|
+
ref: f,
|
|
191
|
+
type: "radio",
|
|
192
|
+
name: e.name,
|
|
193
|
+
value: t,
|
|
194
|
+
required: e.required,
|
|
195
|
+
disabled: m,
|
|
196
|
+
form: e.form,
|
|
197
|
+
checked: p,
|
|
198
|
+
readOnly: !0,
|
|
199
|
+
tabIndex: -1,
|
|
200
|
+
"aria-hidden": "true",
|
|
201
|
+
style: {
|
|
202
|
+
position: "absolute",
|
|
203
|
+
opacity: 0,
|
|
204
|
+
width: 0,
|
|
205
|
+
height: 0,
|
|
206
|
+
pointerEvents: "none"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
),
|
|
210
|
+
R.children
|
|
211
|
+
]
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
X.displayName = "RadioGroupItem";
|
|
217
|
+
const Y = L(
|
|
218
|
+
({ asChild: s, className: i, forceMount: t, ...r }, d) => {
|
|
219
|
+
if (!$(H)) return null;
|
|
220
|
+
const [u, R] = P(!1), l = E(null);
|
|
221
|
+
return B(
|
|
222
|
+
d,
|
|
223
|
+
() => l.current,
|
|
224
|
+
[]
|
|
225
|
+
), I(() => {
|
|
226
|
+
const b = l.current;
|
|
227
|
+
if (!b) return;
|
|
228
|
+
const v = b.closest('[role="radio"]');
|
|
229
|
+
if (!v) return;
|
|
230
|
+
const f = () => {
|
|
231
|
+
R(v.getAttribute("aria-checked") === "true");
|
|
232
|
+
};
|
|
233
|
+
f();
|
|
234
|
+
const p = new MutationObserver(f);
|
|
235
|
+
return p.observe(v, { attributes: !0, attributeFilter: ["aria-checked"] }), () => p.disconnect();
|
|
236
|
+
}, []), !u && !t ? null : /* @__PURE__ */ j(
|
|
237
|
+
s ? S : "span",
|
|
238
|
+
{
|
|
239
|
+
ref: (b) => {
|
|
240
|
+
l.current = b;
|
|
241
|
+
},
|
|
242
|
+
"data-state": u ? "checked" : "unchecked",
|
|
243
|
+
className: q("flex items-center justify-center text-current", i),
|
|
244
|
+
...r
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
);
|
|
249
|
+
Y.displayName = "RadioGroupIndicator";
|
|
250
|
+
export {
|
|
251
|
+
W as RadioGroup,
|
|
252
|
+
Y as RadioGroupIndicator,
|
|
253
|
+
X as RadioGroupItem
|
|
254
|
+
};
|
package/dist/Skeleton.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import './assets/main.css'
|
|
2
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
3
|
+
import { c as n } from "./twUtils-CRiPKpXj.js";
|
|
4
|
+
import "react";
|
|
5
|
+
function s({ className: t, ...e }) {
|
|
6
|
+
return /* @__PURE__ */ o("div", { "data-slot": "skeleton", className: n("bg-accent animate-pulse rounded-md", t), ...e });
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
s as Skeleton
|
|
10
|
+
};
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import './assets/main.css'
|
|
2
|
+
import { jsx as k, jsxs as Q } from "react/jsx-runtime";
|
|
3
|
+
import { Slot as P } from "../primitives/slot.js";
|
|
4
|
+
import { createContext as W, forwardRef as z, useEffect as Z, useRef as B, useState as F, useCallback as A, useContext as U, createRef as _ } from "react";
|
|
5
|
+
function E(...r) {
|
|
6
|
+
return r.filter(Boolean).join(" ");
|
|
7
|
+
}
|
|
8
|
+
function I(r, o, e) {
|
|
9
|
+
return Math.min(e, Math.max(o, r));
|
|
10
|
+
}
|
|
11
|
+
function j(r, o, e) {
|
|
12
|
+
const a = Math.round((r - e) / o), l = e + a * o;
|
|
13
|
+
return Number(l.toFixed(10));
|
|
14
|
+
}
|
|
15
|
+
function L(r, o, e) {
|
|
16
|
+
return (r - o) * 100 / (e - o);
|
|
17
|
+
}
|
|
18
|
+
function tt(r, o, e) {
|
|
19
|
+
return o + r / 100 * (e - o);
|
|
20
|
+
}
|
|
21
|
+
function et(r, o) {
|
|
22
|
+
let e = 0, a = 1 / 0;
|
|
23
|
+
for (let l = 0; l < r.length; l += 1) {
|
|
24
|
+
const n = Math.abs(r[l] - o);
|
|
25
|
+
n < a && (a = n, e = l);
|
|
26
|
+
}
|
|
27
|
+
return e;
|
|
28
|
+
}
|
|
29
|
+
function nt(r) {
|
|
30
|
+
const { value: o, defaultValue: e, onChange: a } = r, [l, n] = F(e), s = Array.isArray(o), t = s ? o : l, i = A(
|
|
31
|
+
(u) => {
|
|
32
|
+
const d = typeof u == "function" ? u(t) : u;
|
|
33
|
+
s || n(d), a?.(d);
|
|
34
|
+
},
|
|
35
|
+
[s, a, t]
|
|
36
|
+
);
|
|
37
|
+
return [t, i];
|
|
38
|
+
}
|
|
39
|
+
const x = W(null), rt = z(
|
|
40
|
+
({
|
|
41
|
+
asChild: r,
|
|
42
|
+
className: o,
|
|
43
|
+
value: e,
|
|
44
|
+
defaultValue: a,
|
|
45
|
+
onValueChange: l,
|
|
46
|
+
onValueCommit: n,
|
|
47
|
+
min: s = 0,
|
|
48
|
+
max: t = 100,
|
|
49
|
+
step: i = 1,
|
|
50
|
+
minStepsBetweenThumbs: u = 0,
|
|
51
|
+
orientation: d = "horizontal",
|
|
52
|
+
dir: S = "ltr",
|
|
53
|
+
disabled: b = !1,
|
|
54
|
+
name: p,
|
|
55
|
+
form: N,
|
|
56
|
+
required: T,
|
|
57
|
+
children: V,
|
|
58
|
+
...$
|
|
59
|
+
}, c) => {
|
|
60
|
+
const [m, f] = nt({
|
|
61
|
+
value: e,
|
|
62
|
+
defaultValue: a && a.length > 0 ? a : [s],
|
|
63
|
+
onChange: l
|
|
64
|
+
});
|
|
65
|
+
Z(() => {
|
|
66
|
+
f((g) => X(g, { min: s, max: t, step: i, minStepsBetweenThumbs: u }));
|
|
67
|
+
}, [s, t, i, u, f]);
|
|
68
|
+
const v = B(null), h = B([]), [y, C] = F(null), w = A(
|
|
69
|
+
(g, R) => {
|
|
70
|
+
const D = X(g, { min: s, max: t, step: i, minStepsBetweenThumbs: u });
|
|
71
|
+
f(D), R?.commit && n?.(D);
|
|
72
|
+
},
|
|
73
|
+
[t, s, u, n, f, i]
|
|
74
|
+
), K = A(
|
|
75
|
+
(g, R, D) => {
|
|
76
|
+
const G = [...m];
|
|
77
|
+
G[g] = R, w(G, D);
|
|
78
|
+
},
|
|
79
|
+
[w, m]
|
|
80
|
+
), M = {
|
|
81
|
+
values: m,
|
|
82
|
+
setValues: w,
|
|
83
|
+
min: s,
|
|
84
|
+
max: t,
|
|
85
|
+
step: i,
|
|
86
|
+
minStepsBetweenThumbs: u,
|
|
87
|
+
orientation: d,
|
|
88
|
+
dir: S,
|
|
89
|
+
disabled: b,
|
|
90
|
+
trackRef: v,
|
|
91
|
+
thumbsRef: h,
|
|
92
|
+
activeIndex: y,
|
|
93
|
+
setActiveIndex: C,
|
|
94
|
+
updateAtIndex: K
|
|
95
|
+
}, J = r ? P : "div", O = c;
|
|
96
|
+
return /* @__PURE__ */ k(x.Provider, { value: M, children: /* @__PURE__ */ Q(
|
|
97
|
+
J,
|
|
98
|
+
{
|
|
99
|
+
ref: O,
|
|
100
|
+
role: "presentation",
|
|
101
|
+
"data-orientation": d,
|
|
102
|
+
"data-disabled": b ? "" : void 0,
|
|
103
|
+
className: E(
|
|
104
|
+
"relative touch-none select-none",
|
|
105
|
+
d === "horizontal" ? "h-6 w-full" : "h-full w-6",
|
|
106
|
+
o
|
|
107
|
+
),
|
|
108
|
+
...$,
|
|
109
|
+
children: [
|
|
110
|
+
p && M.values.map((g, R) => /* @__PURE__ */ k(
|
|
111
|
+
"input",
|
|
112
|
+
{
|
|
113
|
+
type: "hidden",
|
|
114
|
+
name: M.values.length > 1 ? `${p}[]` : p,
|
|
115
|
+
value: String(g),
|
|
116
|
+
form: N,
|
|
117
|
+
required: T && R === 0,
|
|
118
|
+
"aria-hidden": "true"
|
|
119
|
+
},
|
|
120
|
+
R
|
|
121
|
+
)),
|
|
122
|
+
V
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
) });
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
rt.displayName = "Slider";
|
|
129
|
+
function X(r, o) {
|
|
130
|
+
const { min: e, max: a, step: l, minStepsBetweenThumbs: n } = o, s = r.map((i) => I(j(i, l, e), e, a));
|
|
131
|
+
if (s.sort((i, u) => i - u), s.length <= 1 || n <= 0) return s;
|
|
132
|
+
const t = l * n;
|
|
133
|
+
for (let i = 1; i < s.length; i += 1)
|
|
134
|
+
s[i] - s[i - 1] < t && (s[i] = I(s[i - 1] + t, e, a));
|
|
135
|
+
return s;
|
|
136
|
+
}
|
|
137
|
+
const ot = z(
|
|
138
|
+
({ asChild: r, className: o, onPointerDown: e, ...a }, l) => {
|
|
139
|
+
const n = U(x);
|
|
140
|
+
if (!n) throw new Error("SliderTrack must be used within Slider");
|
|
141
|
+
const s = r ? P : "div", t = (u) => {
|
|
142
|
+
n.trackRef.current = u, typeof l == "function" ? l(u) : l && "current" in l && (l.current = u);
|
|
143
|
+
}, i = A(
|
|
144
|
+
(u) => {
|
|
145
|
+
if (e?.(u), u.defaultPrevented || n.disabled) return;
|
|
146
|
+
const d = n.trackRef.current;
|
|
147
|
+
if (!d) return;
|
|
148
|
+
d.setPointerCapture?.(u.pointerId), u.preventDefault();
|
|
149
|
+
const S = d.getBoundingClientRect(), b = Y(u.clientX, u.clientY, S, n), p = et(n.values, b);
|
|
150
|
+
n.setActiveIndex(p), n.updateAtIndex(p, b), H(p, n);
|
|
151
|
+
},
|
|
152
|
+
[n, e]
|
|
153
|
+
);
|
|
154
|
+
return /* @__PURE__ */ k(
|
|
155
|
+
s,
|
|
156
|
+
{
|
|
157
|
+
ref: t,
|
|
158
|
+
"data-orientation": n.orientation,
|
|
159
|
+
className: E(
|
|
160
|
+
"bg-secondary relative grow rounded-full",
|
|
161
|
+
n.orientation === "horizontal" ? "h-2" : "w-2",
|
|
162
|
+
o
|
|
163
|
+
),
|
|
164
|
+
style: { touchAction: "none" },
|
|
165
|
+
onPointerDown: i,
|
|
166
|
+
...a
|
|
167
|
+
}
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
ot.displayName = "SliderTrack";
|
|
172
|
+
const it = z(
|
|
173
|
+
({ asChild: r, className: o, style: e, ...a }, l) => {
|
|
174
|
+
const n = U(x);
|
|
175
|
+
if (!n) throw new Error("SliderRange must be used within Slider");
|
|
176
|
+
const s = r ? P : "div", t = L(n.values[0], n.min, n.max), i = L(n.values[n.values.length - 1], n.min, n.max), u = n.orientation === "horizontal" ? { left: `${t}%`, width: `${i - t}%` } : { bottom: `${t}%`, height: `${i - t}%` };
|
|
177
|
+
return /* @__PURE__ */ k(
|
|
178
|
+
s,
|
|
179
|
+
{
|
|
180
|
+
ref: l,
|
|
181
|
+
"data-orientation": n.orientation,
|
|
182
|
+
className: E("bg-primary absolute rounded-full", n.orientation === "horizontal" ? "h-2" : "w-2", o),
|
|
183
|
+
style: { ...u, ...e },
|
|
184
|
+
...a
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
it.displayName = "SliderRange";
|
|
190
|
+
const at = z(
|
|
191
|
+
({ asChild: r, className: o, index: e, onKeyDown: a, onPointerDown: l, ...n }, s) => {
|
|
192
|
+
const t = U(x);
|
|
193
|
+
if (!t) throw new Error("SliderThumb must be used within Slider");
|
|
194
|
+
const [i] = F(() => {
|
|
195
|
+
const c = typeof e == "number" ? e : t.thumbsRef.current.length;
|
|
196
|
+
return t.thumbsRef.current[c] || (t.thumbsRef.current[c] = _()), c;
|
|
197
|
+
}), u = t.values[i] ?? t.values[t.values.length - 1], d = L(u, t.min, t.max), S = r ? P : "button", b = (c) => {
|
|
198
|
+
t.thumbsRef.current[i].current = c, typeof s == "function" ? s(c) : s && "current" in s && (s.current = c);
|
|
199
|
+
}, N = (t.activeIndex === null || t.activeIndex === i) && !t.disabled ? 0 : -1, T = A(
|
|
200
|
+
(c) => {
|
|
201
|
+
if (a?.(c), c.defaultPrevented || t.disabled) return;
|
|
202
|
+
const m = Math.max(t.step * 10, t.step), f = (w) => w === "inc" ? 1 : -1, v = (w) => st(i, w, t), h = c.key;
|
|
203
|
+
if (h === "Home") {
|
|
204
|
+
c.preventDefault(), t.updateAtIndex(i, t.min, { commit: !0 });
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (h === "End") {
|
|
208
|
+
c.preventDefault(), t.updateAtIndex(i, t.max, { commit: !0 });
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const y = t.orientation === "horizontal", C = t.dir === "rtl";
|
|
212
|
+
if (h === "ArrowRight" && y) {
|
|
213
|
+
c.preventDefault(), v(t.step * (C ? -1 : 1));
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (h === "ArrowLeft" && y) {
|
|
217
|
+
c.preventDefault(), v(t.step * (C ? 1 : -1));
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (h === "ArrowUp" && !y) {
|
|
221
|
+
c.preventDefault(), v(t.step);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (h === "ArrowDown" && !y) {
|
|
225
|
+
c.preventDefault(), v(-t.step);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (h === "PageUp") {
|
|
229
|
+
c.preventDefault(), v(f("inc") * m);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (h === "PageDown") {
|
|
233
|
+
c.preventDefault(), v(f("dec") * m);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
[t, i, a]
|
|
238
|
+
), V = A(
|
|
239
|
+
(c) => {
|
|
240
|
+
if (l?.(c), c.defaultPrevented || t.disabled) return;
|
|
241
|
+
const m = t.trackRef.current, f = t.thumbsRef.current[i].current;
|
|
242
|
+
!m || !f || (f.setPointerCapture?.(c.pointerId), c.preventDefault(), t.setActiveIndex(i), H(i, t));
|
|
243
|
+
},
|
|
244
|
+
[t, i, l]
|
|
245
|
+
), $ = t.orientation === "horizontal" ? { left: `${d}%`, transform: "translate(-50%, -50%)" } : { bottom: `${d}%`, transform: "translate(-50%, 50%)" };
|
|
246
|
+
return /* @__PURE__ */ k(
|
|
247
|
+
S,
|
|
248
|
+
{
|
|
249
|
+
ref: b,
|
|
250
|
+
role: "slider",
|
|
251
|
+
tabIndex: N,
|
|
252
|
+
"aria-valuemin": t.min,
|
|
253
|
+
"aria-valuemax": t.max,
|
|
254
|
+
"aria-valuenow": u,
|
|
255
|
+
"aria-orientation": t.orientation,
|
|
256
|
+
"aria-disabled": t.disabled || void 0,
|
|
257
|
+
"data-orientation": t.orientation,
|
|
258
|
+
"data-disabled": t.disabled ? "" : void 0,
|
|
259
|
+
className: E(
|
|
260
|
+
"bg-background absolute grid place-items-center rounded-full shadow",
|
|
261
|
+
"border-input border outline-none",
|
|
262
|
+
"focus-visible:ring-ring focus-visible:ring-2 focus-visible:ring-offset-2",
|
|
263
|
+
"h-5 w-5",
|
|
264
|
+
o
|
|
265
|
+
),
|
|
266
|
+
style: {
|
|
267
|
+
...$,
|
|
268
|
+
top: t.orientation === "horizontal" ? "50%" : "auto",
|
|
269
|
+
left: t.orientation === "horizontal" ? void 0 : "50%",
|
|
270
|
+
touchAction: "none"
|
|
271
|
+
},
|
|
272
|
+
onKeyDown: T,
|
|
273
|
+
onPointerDown: V,
|
|
274
|
+
...n
|
|
275
|
+
}
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
);
|
|
279
|
+
at.displayName = "SliderThumb";
|
|
280
|
+
function Y(r, o, e, a) {
|
|
281
|
+
let l;
|
|
282
|
+
if (a.orientation === "horizontal") {
|
|
283
|
+
const i = I(r - e.left, 0, e.width) / e.width * 100;
|
|
284
|
+
l = a.dir === "rtl" ? 100 - i : i;
|
|
285
|
+
} else
|
|
286
|
+
l = 100 - I(o - e.top, 0, e.height) / e.height * 100;
|
|
287
|
+
const n = tt(l, a.min, a.max), s = j(n, a.step, a.min);
|
|
288
|
+
return I(s, a.min, a.max);
|
|
289
|
+
}
|
|
290
|
+
function q(r, o, e) {
|
|
291
|
+
const a = e.step * e.minStepsBetweenThumbs, l = r > 0 ? e.values[r - 1] : e.min, n = r < e.values.length - 1 ? e.values[r + 1] : e.max, s = l + (r > 0 ? a : 0), t = n - (r < e.values.length - 1 ? a : 0);
|
|
292
|
+
return I(o, s, t);
|
|
293
|
+
}
|
|
294
|
+
function st(r, o, e) {
|
|
295
|
+
const a = e.values[r], l = q(r, j(a + o, e.step, e.min), e);
|
|
296
|
+
e.updateAtIndex(r, l, { commit: !0 });
|
|
297
|
+
}
|
|
298
|
+
function H(r, o) {
|
|
299
|
+
const e = o.trackRef.current;
|
|
300
|
+
if (!e) return;
|
|
301
|
+
const a = () => e.getBoundingClientRect(), l = (s) => {
|
|
302
|
+
if (o.disabled) return;
|
|
303
|
+
const t = Y(s.clientX, s.clientY, a(), o), i = q(r, t, o);
|
|
304
|
+
o.updateAtIndex(r, i);
|
|
305
|
+
}, n = () => {
|
|
306
|
+
o.setActiveIndex(null), o.setValues([...o.values], { commit: !0 }), window.removeEventListener("pointermove", l, !0), window.removeEventListener("pointerup", n, !0);
|
|
307
|
+
};
|
|
308
|
+
window.addEventListener("pointermove", l, !0), window.addEventListener("pointerup", n, !0);
|
|
309
|
+
}
|
|
310
|
+
export {
|
|
311
|
+
rt as Slider,
|
|
312
|
+
it as SliderRange,
|
|
313
|
+
at as SliderThumb,
|
|
314
|
+
ot as SliderTrack
|
|
315
|
+
};
|
package/dist/Slider.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import './assets/main.css'
|
|
2
|
+
import { jsxs as v, jsx as t } from "react/jsx-runtime";
|
|
3
|
+
import { Slider as w, SliderTrack as p, SliderRange as x, SliderThumb as S } from "./Slider/SliderBase.js";
|
|
4
|
+
import { c as a } from "./twUtils-CRiPKpXj.js";
|
|
5
|
+
const j = ({
|
|
6
|
+
className: o,
|
|
7
|
+
defaultValue: e,
|
|
8
|
+
value: r,
|
|
9
|
+
min: i = 0,
|
|
10
|
+
max: l = 100,
|
|
11
|
+
step: n = 1,
|
|
12
|
+
minStepsBetweenThumbs: d = 1,
|
|
13
|
+
onValueChange: s,
|
|
14
|
+
orientation: c = "horizontal",
|
|
15
|
+
onValueCommit: h,
|
|
16
|
+
disabled: b,
|
|
17
|
+
name: u,
|
|
18
|
+
...m
|
|
19
|
+
}) => {
|
|
20
|
+
const f = r || e || [i];
|
|
21
|
+
return /* @__PURE__ */ v(
|
|
22
|
+
w,
|
|
23
|
+
{
|
|
24
|
+
"data-slot": "slider",
|
|
25
|
+
defaultValue: e,
|
|
26
|
+
value: r,
|
|
27
|
+
min: i,
|
|
28
|
+
max: l,
|
|
29
|
+
step: n,
|
|
30
|
+
minStepsBetweenThumbs: d,
|
|
31
|
+
onValueChange: s,
|
|
32
|
+
orientation: c,
|
|
33
|
+
onValueCommit: h,
|
|
34
|
+
disabled: b,
|
|
35
|
+
name: u,
|
|
36
|
+
className: a(
|
|
37
|
+
"relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",
|
|
38
|
+
o
|
|
39
|
+
),
|
|
40
|
+
...m,
|
|
41
|
+
children: [
|
|
42
|
+
/* @__PURE__ */ t(
|
|
43
|
+
p,
|
|
44
|
+
{
|
|
45
|
+
"data-slot": "slider-track",
|
|
46
|
+
className: a(
|
|
47
|
+
"bg-slider-track relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5"
|
|
48
|
+
),
|
|
49
|
+
children: /* @__PURE__ */ t(
|
|
50
|
+
x,
|
|
51
|
+
{
|
|
52
|
+
"data-slot": "slider-range",
|
|
53
|
+
className: a(
|
|
54
|
+
"bg-slider-range absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full"
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
),
|
|
60
|
+
Array.from({ length: f.length }, (k, g) => /* @__PURE__ */ t(
|
|
61
|
+
S,
|
|
62
|
+
{
|
|
63
|
+
"data-slot": "slider-thumb",
|
|
64
|
+
className: "border-slider-thumb-border bg-slider-thumb-bg ring-slider-thumb-ring/50 block size-4 shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
|
|
65
|
+
},
|
|
66
|
+
g
|
|
67
|
+
))
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
export {
|
|
73
|
+
j as Slider
|
|
74
|
+
};
|