@peerproblem/sw3-ui 0.0.0-stage → 0.3.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.
Files changed (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +109 -2
  3. package/agent/components/accordion.md +95 -0
  4. package/agent/components/action-square.md +106 -0
  5. package/agent/components/agent-bridge.md +87 -0
  6. package/agent/components/agent-console.md +123 -0
  7. package/agent/components/alert-dialog.md +82 -0
  8. package/agent/components/app-shell.md +105 -0
  9. package/agent/components/area-chart.md +56 -0
  10. package/agent/components/async-options.md +47 -0
  11. package/agent/components/autocomplete.md +69 -0
  12. package/agent/components/avatar.md +88 -0
  13. package/agent/components/badge.md +51 -0
  14. package/agent/components/bar-chart.md +56 -0
  15. package/agent/components/bar-list.md +49 -0
  16. package/agent/components/breadcrumbs.md +43 -0
  17. package/agent/components/button.md +109 -0
  18. package/agent/components/calendar.md +114 -0
  19. package/agent/components/canvas.md +105 -0
  20. package/agent/components/card.md +78 -0
  21. package/agent/components/carousel.md +113 -0
  22. package/agent/components/chart-card.md +41 -0
  23. package/agent/components/chart-surface.md +56 -0
  24. package/agent/components/checkbox.md +88 -0
  25. package/agent/components/citation-chip.md +61 -0
  26. package/agent/components/collapsible.md +69 -0
  27. package/agent/components/color-picker.md +82 -0
  28. package/agent/components/combobox.md +104 -0
  29. package/agent/components/command.md +92 -0
  30. package/agent/components/dashboard-grid.md +73 -0
  31. package/agent/components/date-input.md +87 -0
  32. package/agent/components/date-picker.md +122 -0
  33. package/agent/components/dialog.md +97 -0
  34. package/agent/components/donut-chart.md +50 -0
  35. package/agent/components/drawer.md +101 -0
  36. package/agent/components/empty-state.md +52 -0
  37. package/agent/components/field.md +80 -0
  38. package/agent/components/file-input.md +84 -0
  39. package/agent/components/hover-card.md +64 -0
  40. package/agent/components/image-cropper.md +77 -0
  41. package/agent/components/input.md +49 -0
  42. package/agent/components/label.md +53 -0
  43. package/agent/components/line-chart.md +60 -0
  44. package/agent/components/listbox.md +84 -0
  45. package/agent/components/map-view.md +104 -0
  46. package/agent/components/menu.md +117 -0
  47. package/agent/components/menubar.md +67 -0
  48. package/agent/components/meter.md +59 -0
  49. package/agent/components/navigation-menu.md +98 -0
  50. package/agent/components/number-input.md +81 -0
  51. package/agent/components/otp-input.md +67 -0
  52. package/agent/components/pagination.md +80 -0
  53. package/agent/components/password-input.md +67 -0
  54. package/agent/components/pill-button.md +116 -0
  55. package/agent/components/popover.md +85 -0
  56. package/agent/components/poster-card.md +61 -0
  57. package/agent/components/preferences.md +92 -0
  58. package/agent/components/progress.md +63 -0
  59. package/agent/components/provider.md +47 -0
  60. package/agent/components/radio.md +91 -0
  61. package/agent/components/rating.md +66 -0
  62. package/agent/components/reorder.md +61 -0
  63. package/agent/components/resizable.md +87 -0
  64. package/agent/components/scatter-chart.md +49 -0
  65. package/agent/components/scroll-area.md +81 -0
  66. package/agent/components/segmented-control.md +56 -0
  67. package/agent/components/select.md +130 -0
  68. package/agent/components/separator.md +60 -0
  69. package/agent/components/shortcuts.md +50 -0
  70. package/agent/components/sidebar-nav.md +68 -0
  71. package/agent/components/skeleton.md +58 -0
  72. package/agent/components/slider.md +79 -0
  73. package/agent/components/sparkline.md +39 -0
  74. package/agent/components/squircle.md +58 -0
  75. package/agent/components/stat.md +58 -0
  76. package/agent/components/switch.md +48 -0
  77. package/agent/components/table.md +58 -0
  78. package/agent/components/tabs.md +108 -0
  79. package/agent/components/textarea.md +68 -0
  80. package/agent/components/time-input.md +84 -0
  81. package/agent/components/timeline.md +91 -0
  82. package/agent/components/toast.md +85 -0
  83. package/agent/components/toggle.md +76 -0
  84. package/agent/components/token-input.md +66 -0
  85. package/agent/components/toolbar.md +76 -0
  86. package/agent/components/tooltip.md +83 -0
  87. package/agent/components/tracker.md +47 -0
  88. package/agent/components/tree.md +87 -0
  89. package/agent/components/treemap.md +72 -0
  90. package/agent/components/trend-chart.md +80 -0
  91. package/agent/components/trigger-menu.md +67 -0
  92. package/agent/components/typography.md +51 -0
  93. package/agent/components/waterfall.md +78 -0
  94. package/agent/components/week-schedule.md +113 -0
  95. package/agent/llms/actions-and-layout.txt +1749 -0
  96. package/agent/llms/agents.txt +505 -0
  97. package/agent/llms/charts.txt +778 -0
  98. package/agent/llms/dashboards.txt +457 -0
  99. package/agent/llms/extend.txt +132 -0
  100. package/agent/llms/extras.txt +527 -0
  101. package/agent/llms/forms.txt +2152 -0
  102. package/agent/llms/foundations.txt +674 -0
  103. package/agent/llms/hooks.txt +178 -0
  104. package/agent/llms/maps.txt +229 -0
  105. package/agent/llms/overlays-and-navigation.txt +1167 -0
  106. package/agent/llms-full.txt +8717 -0
  107. package/agent/llms.txt +145 -0
  108. package/agent/registry.json +11289 -0
  109. package/agent/tokens.md +66 -0
  110. package/dist/agent/index.d.ts +235 -0
  111. package/dist/agent/index.js +21 -0
  112. package/dist/card-Ipm-Cj5f.d.ts +490 -0
  113. package/dist/charts/index.d.ts +289 -0
  114. package/dist/charts/index.js +815 -0
  115. package/dist/check/cli.d.ts +1 -0
  116. package/dist/check/cli.js +48 -0
  117. package/dist/check/rendered.d.ts +11 -0
  118. package/dist/check/rendered.js +77 -0
  119. package/dist/check/source.d.ts +13 -0
  120. package/dist/check/source.js +182 -0
  121. package/dist/chunk-3DXBM65D.js +65 -0
  122. package/dist/chunk-3H5X4ZP6.js +55 -0
  123. package/dist/chunk-6XC4BC5C.js +92 -0
  124. package/dist/chunk-7H6TEAWD.js +507 -0
  125. package/dist/chunk-I63ZTJOI.js +1089 -0
  126. package/dist/chunk-JCIRUM4W.js +33 -0
  127. package/dist/chunk-LTBEHZ3P.js +25 -0
  128. package/dist/chunk-QDPPLO4U.js +60 -0
  129. package/dist/chunk-U2XFBPU4.js +56 -0
  130. package/dist/chunk-UY2WH5AY.js +681 -0
  131. package/dist/extras.d.ts +203 -0
  132. package/dist/extras.js +904 -0
  133. package/dist/icons-BJiGEAnU.d.ts +68 -0
  134. package/dist/index.d.ts +3737 -0
  135. package/dist/index.js +14477 -0
  136. package/dist/map/index.d.ts +115 -0
  137. package/dist/map/index.js +394 -0
  138. package/dist/meta/index.d.ts +3314 -0
  139. package/dist/meta/index.js +5106 -0
  140. package/dist/rules-1RIZ_JZr.d.ts +38 -0
  141. package/dist/styles.css +4037 -0
  142. package/dist/themes/calm.css +42 -0
  143. package/dist/themes/frost.css +40 -0
  144. package/package.json +142 -4
@@ -0,0 +1,1089 @@
1
+ 'use client';
2
+ import {
3
+ Icon,
4
+ InsetSquircleButton,
5
+ SquircleLayers,
6
+ cx,
7
+ moveFocus,
8
+ resolveSmoothing,
9
+ useControllableState,
10
+ useSquircle
11
+ } from "./chunk-UY2WH5AY.js";
12
+ import {
13
+ useAgentBinding
14
+ } from "./chunk-JCIRUM4W.js";
15
+
16
+ // src/components/segmented-control.tsx
17
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
18
+ import { jsx, jsxs } from "react/jsx-runtime";
19
+ var useIsoLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
20
+ function SegmentedControl({
21
+ options,
22
+ value,
23
+ onValueChange,
24
+ size = "md",
25
+ radius = "sm",
26
+ appearance = "default",
27
+ fullWidth,
28
+ className,
29
+ ...aria
30
+ }) {
31
+ const ref = useRef(null);
32
+ const iconCapsule = appearance === "icon-capsule";
33
+ const sq = useSquircle(iconCapsule ? { shape: "smooth-capsule", radius: "full" } : { radius });
34
+ const inner = Math.max(0, sq.radius - 3);
35
+ const [box, setBox] = useState(null);
36
+ const [gliding, setGliding] = useState(false);
37
+ const lastValue = useRef(value);
38
+ const measure = useCallback(() => {
39
+ const item = ref.current?.querySelector('.sw-segmented__item[data-state="checked"]');
40
+ if (!item) return setBox(null);
41
+ const next = { x: item.offsetLeft, y: item.offsetTop, w: item.offsetWidth, h: item.offsetHeight };
42
+ setBox((b) => b && b.x === next.x && b.y === next.y && b.w === next.w && b.h === next.h ? b : next);
43
+ }, []);
44
+ useIsoLayoutEffect(() => {
45
+ const changed = lastValue.current !== value;
46
+ lastValue.current = value;
47
+ setGliding(changed && box != null);
48
+ measure();
49
+ }, [value, measure]);
50
+ useEffect(() => {
51
+ const root = ref.current;
52
+ if (!root || typeof ResizeObserver === "undefined") return;
53
+ const ro = new ResizeObserver(() => {
54
+ setGliding(false);
55
+ measure();
56
+ });
57
+ ro.observe(root);
58
+ root.querySelectorAll(".sw-segmented__item").forEach((el) => ro.observe(el));
59
+ return () => ro.disconnect();
60
+ }, [measure, options.length]);
61
+ return /* @__PURE__ */ jsxs(
62
+ "div",
63
+ {
64
+ ref: (el) => {
65
+ ref.current = el;
66
+ sq.ref(el);
67
+ },
68
+ role: "radiogroup",
69
+ "data-sw": "segmented-control",
70
+ "data-size": size,
71
+ "data-appearance": iconCapsule ? appearance : void 0,
72
+ className: cx("sw-segmented sw-sq", fullWidth && "sw-segmented--full", className),
73
+ onKeyDown: (e) => moveFocus(ref.current, e, "horizontal"),
74
+ ...aria,
75
+ children: [
76
+ /* @__PURE__ */ jsx(SquircleLayers, { paths: sq.paths, radius: sq.radius, borderWidth: 0 }),
77
+ box && /* @__PURE__ */ jsx(Pill, { radius: iconCapsule ? "full" : inner, circular: iconCapsule, box, gliding }),
78
+ options.map((o) => {
79
+ const active = o.value === value;
80
+ return /* @__PURE__ */ jsx(
81
+ "button",
82
+ {
83
+ type: "button",
84
+ role: "radio",
85
+ "aria-checked": active,
86
+ tabIndex: active ? 0 : -1,
87
+ disabled: o.disabled,
88
+ "data-sw-item": true,
89
+ "data-value": o.value,
90
+ "data-state": active ? "checked" : "unchecked",
91
+ className: "sw-segmented__item",
92
+ onClick: () => onValueChange(o.value),
93
+ children: /* @__PURE__ */ jsx("span", { className: "sw-segmented__label", children: o.label })
94
+ },
95
+ o.value
96
+ );
97
+ })
98
+ ]
99
+ }
100
+ );
101
+ }
102
+ function Pill({ radius, circular, box, gliding }) {
103
+ const sq = useSquircle({ radius, smoothing: circular ? "none" : void 0, ringOffset: 2 });
104
+ return /* @__PURE__ */ jsx(
105
+ "span",
106
+ {
107
+ ref: sq.ref,
108
+ "aria-hidden": true,
109
+ className: "sw-segmented__pill sw-sq",
110
+ "data-gliding": gliding ? "" : void 0,
111
+ style: { transform: `translate(${box.x}px, ${box.y}px)`, width: box.w, height: box.h },
112
+ children: /* @__PURE__ */ jsx(SquircleLayers, { paths: sq.paths, radius: sq.radius, ringOffset: sq.ringOffset, borderWidth: 0 })
113
+ }
114
+ );
115
+ }
116
+
117
+ // src/primitives/field-context.tsx
118
+ import { createContext, useContext, useId } from "react";
119
+ var FieldContext = createContext(null);
120
+ var useFieldContext = () => useContext(FieldContext);
121
+ function useFieldControl(props = {}) {
122
+ const field = useFieldContext();
123
+ const auto = useId();
124
+ const describedBy2 = [props["aria-describedby"], field?.hasDescription && field.descriptionId, field?.hasError && field.errorId].filter(Boolean).join(" ") || void 0;
125
+ const invalid = props.invalid ?? field?.invalid ?? false;
126
+ return {
127
+ id: props.id ?? field?.controlId ?? auto,
128
+ disabled: props.disabled ?? field?.disabled ?? void 0,
129
+ required: props.required ?? field?.required ?? void 0,
130
+ "aria-invalid": invalid || void 0,
131
+ "aria-describedby": describedBy2,
132
+ "aria-labelledby": props["aria-labelledby"] ?? (field && field.hasLabel !== false ? field.labelId : void 0),
133
+ /** `true` when inside a Field (so the control should not render its own label). */
134
+ inField: !!field,
135
+ labelId: field && field.hasLabel !== false ? field.labelId : void 0
136
+ };
137
+ }
138
+
139
+ // src/components/toggle.tsx
140
+ import {
141
+ createContext as createContext2,
142
+ forwardRef,
143
+ useContext as useContext2,
144
+ useId as useId3,
145
+ useLayoutEffect as useLayoutEffect2,
146
+ useRef as useRef2,
147
+ useState as useState3
148
+ } from "react";
149
+
150
+ // src/components/_forms-shared.tsx
151
+ import { useCallback as useCallback2, useEffect as useEffect2, useId as useId2, useMemo, useState as useState2 } from "react";
152
+ import { getSvgPath } from "figma-squircle";
153
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
154
+ var clamp = (v, min, max) => Math.min(max, Math.max(min, v));
155
+ function decimalsOf(n) {
156
+ if (!Number.isFinite(n)) return 0;
157
+ const s = String(n);
158
+ if (s.includes("e-")) return parseInt(s.split("e-")[1], 10);
159
+ const i = s.indexOf(".");
160
+ return i < 0 ? 0 : s.length - i - 1;
161
+ }
162
+ function snap(value, step, base = 0) {
163
+ if (!(step > 0)) return value;
164
+ const d = Math.max(decimalsOf(step), decimalsOf(base));
165
+ return Number((Math.round((value - base) / step) * step + base).toFixed(d));
166
+ }
167
+ function useLocale(locale) {
168
+ const [detected, setDetected] = useState2("en-US");
169
+ useEffect2(() => {
170
+ if (locale) return;
171
+ const l = document.documentElement.lang || navigator.language;
172
+ if (l) setDetected(l);
173
+ }, [locale]);
174
+ return locale ?? detected;
175
+ }
176
+ function useNumberFormat(locale, options) {
177
+ const loc = useLocale(locale);
178
+ const key = JSON.stringify(options ?? {});
179
+ return useMemo(() => {
180
+ try {
181
+ return new Intl.NumberFormat(loc, options);
182
+ } catch {
183
+ return new Intl.NumberFormat("en-US", options);
184
+ }
185
+ }, [loc, key]);
186
+ }
187
+ function useGaugeFormat(min, max, locale, options) {
188
+ const fmt = useNumberFormat(locale, options ?? { style: "percent", maximumFractionDigits: 0 });
189
+ const percentStyle = options ? options.style === "percent" : true;
190
+ return useCallback2(
191
+ (v) => fmt.format(percentStyle ? max === min ? 0 : (clamp(v, min, max) - min) / (max - min) : v),
192
+ [fmt, percentStyle, min, max]
193
+ );
194
+ }
195
+ var LABELABLE = /* @__PURE__ */ new Set(["INPUT", "BUTTON", "SELECT", "TEXTAREA", "METER", "OUTPUT", "PROGRESS"]);
196
+ var isLabelable = (el) => LABELABLE.has(el.tagName) && !(el.tagName === "INPUT" && el.type === "hidden");
197
+ function focusLabelTarget(el) {
198
+ if (el.matches('[aria-disabled="true"], [data-disabled]')) return;
199
+ const pick = (el.tabIndex >= 0 && el.matches("[tabindex]") ? el : null) ?? el.querySelector('[aria-checked="true"]:not([disabled]), [tabindex="0"]:not([disabled])') ?? el.querySelector('input:not([type="hidden"]):not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"])');
200
+ pick?.focus();
201
+ }
202
+ function labelClick(targetId) {
203
+ return (e) => {
204
+ if (!targetId) return;
205
+ const el = document.getElementById(targetId);
206
+ if (!el || isLabelable(el)) return;
207
+ e.preventDefault();
208
+ focusLabelTarget(el);
209
+ };
210
+ }
211
+ function useComposedRef(...refs) {
212
+ return useCallback2((value) => {
213
+ for (const ref of refs) {
214
+ if (!ref) continue;
215
+ if (typeof ref === "function") ref(value);
216
+ else ref.current = value;
217
+ }
218
+ }, refs);
219
+ }
220
+ function setNativeValue(el, value) {
221
+ const proto = el instanceof HTMLTextAreaElement ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
222
+ Object.getOwnPropertyDescriptor(proto, "value")?.set?.call(el, value);
223
+ el.dispatchEvent(new Event("input", { bubbles: true }));
224
+ }
225
+ function FieldShell({
226
+ slug,
227
+ size,
228
+ radius,
229
+ controlId,
230
+ label,
231
+ hint,
232
+ error,
233
+ invalid,
234
+ disabled,
235
+ className,
236
+ style,
237
+ fieldClassName,
238
+ footer,
239
+ rootRef,
240
+ data,
241
+ children
242
+ }) {
243
+ const sq = useSquircle({ radius });
244
+ const message = error ? /* @__PURE__ */ jsx2("p", { id: `${controlId}-e`, className: "sw-input__error", children: error }) : hint ? /* @__PURE__ */ jsx2("p", { id: `${controlId}-h`, className: "sw-input__hint", children: hint }) : null;
245
+ return /* @__PURE__ */ jsxs2(
246
+ "div",
247
+ {
248
+ ref: rootRef,
249
+ "data-sw": slug,
250
+ "data-size": size,
251
+ "data-invalid": invalid ? "" : void 0,
252
+ "data-disabled": disabled ? "" : void 0,
253
+ className: cx("sw-input", slug !== "input" && `sw-${slug}`, className),
254
+ style,
255
+ ...data,
256
+ children: [
257
+ label && /* @__PURE__ */ jsx2("label", { htmlFor: controlId, className: "sw-input__label", children: label }),
258
+ /* @__PURE__ */ jsxs2(
259
+ "div",
260
+ {
261
+ ref: sq.ref,
262
+ className: cx("sw-input__field sw-sq", fieldClassName),
263
+ onMouseDown: (e) => {
264
+ if (e.target !== e.currentTarget) return;
265
+ const control = e.currentTarget.querySelector('input:not([type="hidden"]), textarea');
266
+ if (control) {
267
+ e.preventDefault();
268
+ control.focus();
269
+ }
270
+ },
271
+ children: [
272
+ /* @__PURE__ */ jsx2(SquircleLayers, { paths: sq.paths, radius: sq.radius, ringOffset: sq.ringOffset, borderWidth: 1 }),
273
+ children
274
+ ]
275
+ }
276
+ ),
277
+ footer ? /* @__PURE__ */ jsxs2("div", { className: "sw-input__foot", children: [
278
+ message ?? /* @__PURE__ */ jsx2("span", {}),
279
+ footer
280
+ ] }) : message
281
+ ]
282
+ }
283
+ );
284
+ }
285
+ function describedBy(fromField, controlId, hint, error) {
286
+ return [fromField, error ? `${controlId}-e` : hint ? `${controlId}-h` : void 0].filter(Boolean).join(" ") || void 0;
287
+ }
288
+ var GRIP_INSET = 4;
289
+ function ResizeGrip({ target, radius, disabled }) {
290
+ const [dragging, setDragging] = useState2(false);
291
+ const id = `sw-grip-${useId2().replace(/[^a-zA-Z0-9_-]/g, "")}`;
292
+ const r = Math.max(2, radius - GRIP_INSET);
293
+ const g = Math.ceil(r * 1.7) + 1;
294
+ const d = useMemo(() => getSvgPath({ width: g * 2, height: g * 2, cornerRadius: r, cornerSmoothing: resolveSmoothing(void 0), preserveSmoothing: true }), [g, r]);
295
+ if (disabled) return null;
296
+ return /* @__PURE__ */ jsx2(
297
+ "span",
298
+ {
299
+ "aria-hidden": true,
300
+ className: "sw-resize-grip",
301
+ "data-dragging": dragging ? "" : void 0,
302
+ style: { "--_g": `${g}px` },
303
+ onPointerDown: (e) => {
304
+ const el = target.current;
305
+ if (!el || e.button !== 0) return;
306
+ e.preventDefault();
307
+ const cs = getComputedStyle(el);
308
+ const line = parseFloat(cs.lineHeight) || parseFloat(cs.fontSize) * 1.45;
309
+ const min = (el.rows || 1) * line + parseFloat(cs.paddingTop) + parseFloat(cs.paddingBottom);
310
+ const startY = e.clientY;
311
+ const startH = el.getBoundingClientRect().height;
312
+ const grip = e.currentTarget;
313
+ grip.setPointerCapture(e.pointerId);
314
+ setDragging(true);
315
+ const move = (ev) => {
316
+ el.style.height = `${Math.max(min, startH + ev.clientY - startY)}px`;
317
+ };
318
+ const up = () => {
319
+ grip.removeEventListener("pointermove", move);
320
+ grip.removeEventListener("pointerup", up);
321
+ grip.removeEventListener("pointercancel", up);
322
+ setDragging(false);
323
+ };
324
+ grip.addEventListener("pointermove", move);
325
+ grip.addEventListener("pointerup", up);
326
+ grip.addEventListener("pointercancel", up);
327
+ },
328
+ onDoubleClick: () => {
329
+ if (target.current) target.current.style.height = "";
330
+ },
331
+ children: /* @__PURE__ */ jsxs2("svg", { className: "sw-resize-grip__arc", width: g, height: g, viewBox: `0 0 ${g} ${g}`, overflow: "visible", children: [
332
+ /* @__PURE__ */ jsxs2("defs", { children: [
333
+ /* @__PURE__ */ jsxs2("radialGradient", { id: `${id}-f`, cx: g, cy: g, r: g, gradientUnits: "userSpaceOnUse", children: [
334
+ /* @__PURE__ */ jsx2("stop", { offset: "0.35", stopColor: "#fff" }),
335
+ /* @__PURE__ */ jsx2("stop", { offset: "1", stopColor: "#fff", stopOpacity: "0" })
336
+ ] }),
337
+ /* @__PURE__ */ jsx2("mask", { id: `${id}-m`, maskUnits: "userSpaceOnUse", x: -2, y: -2, width: g + 4, height: g + 4, children: /* @__PURE__ */ jsx2("rect", { x: -2, y: -2, width: g + 4, height: g + 4, fill: `url(#${id}-f)` }) })
338
+ ] }),
339
+ /* @__PURE__ */ jsx2("g", { mask: `url(#${id}-m)`, children: /* @__PURE__ */ jsx2("path", { d, transform: `translate(${-g} ${-g})`, fill: "none" }) })
340
+ ] })
341
+ }
342
+ );
343
+ }
344
+
345
+ // src/components/toggle.tsx
346
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
347
+ var ToggleGroupContext = createContext2(null);
348
+ var Toggle = forwardRef(function Toggle2({
349
+ pressed: pressedProp,
350
+ defaultPressed = false,
351
+ onPressedChange,
352
+ value,
353
+ size: sizeProp,
354
+ variant: variantProp,
355
+ radius,
356
+ icon,
357
+ disabled,
358
+ className,
359
+ children,
360
+ onClick,
361
+ onFocus,
362
+ ...rest
363
+ }, ref) {
364
+ const group = useContext2(ToggleGroupContext);
365
+ const auto = useId3();
366
+ const v = value ?? auto;
367
+ const [own, setOwn] = useControllableState({ value: pressedProp, defaultValue: defaultPressed, onChange: onPressedChange });
368
+ const pressed = group ? group.value.includes(v) : own;
369
+ const isDisabled = !!disabled || !!group?.disabled;
370
+ const size = sizeProp ?? group?.size ?? "md";
371
+ const variant = variantProp ?? group?.variant ?? "ghost";
372
+ const sq = useSquircle({ radius: radius ?? group?.itemRadius ?? (size === "sm" ? "xs" : "sm"), ringOffset: 2 });
373
+ const btn = useRef2(null);
374
+ const setRef = useComposedRef(sq.ref, btn, ref);
375
+ const iconOnly = !!icon && children == null;
376
+ const press = () => {
377
+ if (isDisabled) return;
378
+ if (group) {
379
+ onPressedChange?.(!pressed);
380
+ group.press(v);
381
+ } else setOwn(!own);
382
+ };
383
+ useAgentBinding(btn, {
384
+ kind: "toggle",
385
+ state: () => ({ pressed, value: v, disabled: isDisabled }),
386
+ actions: { toggle: press, setChecked: (b) => {
387
+ if (!!b !== pressed) press();
388
+ } }
389
+ });
390
+ const tabIndex = group ? group.tabStop === void 0 || group.tabStop === v ? 0 : -1 : void 0;
391
+ return /* @__PURE__ */ jsxs3(
392
+ "button",
393
+ {
394
+ ref: setRef,
395
+ type: "button",
396
+ "aria-pressed": pressed,
397
+ disabled: group ? void 0 : isDisabled,
398
+ "aria-disabled": group && isDisabled ? true : void 0,
399
+ tabIndex,
400
+ "data-sw": "toggle",
401
+ "data-value": v,
402
+ "data-state": pressed ? "on" : "off",
403
+ "data-size": size,
404
+ "data-variant": variant,
405
+ "data-icon-only": iconOnly ? "" : void 0,
406
+ "data-disabled": isDisabled ? "" : void 0,
407
+ className: cx("sw-toggle sw-sq", className),
408
+ onFocus: (e) => {
409
+ onFocus?.(e);
410
+ group?.setTabStop(v);
411
+ },
412
+ onClick: (e) => {
413
+ onClick?.(e);
414
+ if (!e.defaultPrevented) press();
415
+ },
416
+ ...rest,
417
+ children: [
418
+ /* @__PURE__ */ jsx3(SquircleLayers, { paths: sq.paths, radius: sq.radius, ringOffset: sq.ringOffset, borderWidth: !group && variant === "outline" ? 1 : 0 }),
419
+ icon && /* @__PURE__ */ jsx3("span", { className: "sw-toggle__icon", "aria-hidden": "true", children: icon }),
420
+ children != null && /* @__PURE__ */ jsx3("span", { className: "sw-toggle__label", children })
421
+ ]
422
+ }
423
+ );
424
+ });
425
+ function ToggleGroup({
426
+ value,
427
+ defaultValue = [],
428
+ onValueChange,
429
+ multiple = false,
430
+ deselectable = true,
431
+ items,
432
+ disabled = false,
433
+ orientation = "horizontal",
434
+ loop = true,
435
+ size = "md",
436
+ variant = "ghost",
437
+ radius = "sm",
438
+ name,
439
+ className,
440
+ children,
441
+ onKeyDown,
442
+ ...rest
443
+ }) {
444
+ const [current, setCurrent] = useControllableState({ value, defaultValue, onChange: onValueChange });
445
+ const [tabStop, setTabStop] = useState3(void 0);
446
+ const rootRef = useRef2(null);
447
+ const sq = useSquircle({ radius });
448
+ const setRootRef = useComposedRef(sq.ref, rootRef);
449
+ const itemRadius = Math.max(0, sq.radius - 3);
450
+ const list = () => Array.from(rootRef.current?.querySelectorAll('[data-sw="toggle"]') ?? []);
451
+ useLayoutEffect2(() => {
452
+ const all = list();
453
+ if (tabStop && all.some((b) => b.dataset.value === tabStop)) return;
454
+ const ok = all.filter((b) => b.getAttribute("aria-disabled") !== "true");
455
+ const pick = ok.find((b) => b.getAttribute("aria-pressed") === "true") ?? ok[0] ?? all[0];
456
+ setTabStop(pick?.dataset.value ?? null);
457
+ });
458
+ const press = (v) => {
459
+ if (disabled) return;
460
+ setCurrent((prev) => {
461
+ const on = prev.includes(v);
462
+ if (multiple) return on ? prev.filter((x) => x !== v) : [...prev, v];
463
+ if (on) return deselectable ? [] : prev;
464
+ return [v];
465
+ });
466
+ };
467
+ const onKey = (e) => {
468
+ onKeyDown?.(e);
469
+ const fwd = orientation === "horizontal" ? "ArrowRight" : "ArrowDown";
470
+ const back = orientation === "horizontal" ? "ArrowLeft" : "ArrowUp";
471
+ if (e.defaultPrevented || ![fwd, back, "Home", "End"].includes(e.key)) return;
472
+ const all = list();
473
+ const i = all.indexOf(e.target);
474
+ if (i < 0) return;
475
+ e.preventDefault();
476
+ let t = e.key === "Home" ? 0 : e.key === "End" ? all.length - 1 : i + (e.key === fwd ? 1 : -1);
477
+ if (loop) t = (t + all.length) % all.length;
478
+ else t = Math.max(0, Math.min(all.length - 1, t));
479
+ all[t]?.focus();
480
+ };
481
+ useAgentBinding(rootRef, {
482
+ kind: "toggle-group",
483
+ state: () => ({ value: current, multiple, disabled }),
484
+ actions: {
485
+ setValue: (v) => setCurrent(Array.isArray(v) ? v.map(String) : [String(v)]),
486
+ toggle: (v) => press(String(v)),
487
+ select: (v) => setCurrent((p) => multiple ? p.includes(v) ? p : [...p, v] : [v]),
488
+ clear: () => setCurrent([])
489
+ },
490
+ items: () => list().map((b) => ({
491
+ value: b.dataset.value ?? "",
492
+ label: b.getAttribute("aria-label") ?? b.textContent ?? "",
493
+ disabled: b.getAttribute("aria-disabled") === "true"
494
+ }))
495
+ });
496
+ return /* @__PURE__ */ jsx3(ToggleGroupContext.Provider, { value: { value: current, press, disabled, size, variant, itemRadius, tabStop, setTabStop }, children: /* @__PURE__ */ jsxs3(
497
+ "div",
498
+ {
499
+ ref: setRootRef,
500
+ role: "group",
501
+ "aria-orientation": orientation,
502
+ "aria-disabled": disabled || void 0,
503
+ "data-sw": "toggle-group",
504
+ "data-orientation": orientation,
505
+ "data-variant": variant,
506
+ "data-multiple": multiple ? "" : void 0,
507
+ "data-deselectable": !multiple && deselectable ? "" : void 0,
508
+ className: cx("sw-toggle-group sw-sq", className),
509
+ onKeyDown: onKey,
510
+ ...rest,
511
+ children: [
512
+ /* @__PURE__ */ jsx3(SquircleLayers, { paths: sq.paths, radius: sq.radius, borderWidth: variant === "outline" ? 1 : 0 }),
513
+ items?.map((i) => /* @__PURE__ */ jsx3(Toggle, { value: i.value, icon: i.icon, disabled: i.disabled, "aria-label": i["aria-label"], children: i.label }, i.value)),
514
+ children,
515
+ name && current.map((v) => /* @__PURE__ */ jsx3("input", { type: "hidden", name, value: v }, v))
516
+ ]
517
+ }
518
+ ) });
519
+ }
520
+
521
+ // src/components/slider.tsx
522
+ import { useId as useId4, useRef as useRef3, useState as useState4 } from "react";
523
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
524
+ var DEFAULT_FORMAT = { maximumFractionDigits: 2 };
525
+ function Slider({
526
+ value,
527
+ defaultValue,
528
+ onValueChange,
529
+ onValueCommit,
530
+ min = 0,
531
+ max = 100,
532
+ step = 1,
533
+ largeStep,
534
+ minStepsBetweenThumbs = 0,
535
+ orientation = "horizontal",
536
+ disabled,
537
+ readOnly = false,
538
+ name,
539
+ label,
540
+ showValue,
541
+ marks,
542
+ formatOptions,
543
+ locale,
544
+ thumbLabels,
545
+ size = "md",
546
+ id,
547
+ className,
548
+ style,
549
+ "aria-label": ariaLabel,
550
+ "aria-labelledby": ariaLabelledBy
551
+ }) {
552
+ const fc = useFieldControl({ id, disabled });
553
+ const [current, setCurrent] = useControllableState({ value, defaultValue: defaultValue ?? min, onChange: onValueChange });
554
+ const isRange = Array.isArray(current);
555
+ const values = isRange ? [...current] : [current];
556
+ const latest = useRef3(current);
557
+ latest.current = current;
558
+ const isDisabled = !!fc.disabled;
559
+ const locked = isDisabled || readOnly;
560
+ const big = largeStep ?? step * 10;
561
+ const gap = minStepsBetweenThumbs * step;
562
+ const top = snap(min + Math.floor((max - min) / step + 1e-9) * step, step, min);
563
+ const fmt = useGaugeFormat(min, max, locale, formatOptions ?? DEFAULT_FORMAT);
564
+ const pct = (v) => max === min ? 0 : (clamp(v, min, max) - min) / (max - min) * 100;
565
+ const fit = (raw) => clamp(snap(raw, step, min), min, top);
566
+ const update = (index, raw) => {
567
+ setCurrent((prev) => {
568
+ let v = fit(raw);
569
+ let out;
570
+ if (Array.isArray(prev)) {
571
+ const [a, b] = prev;
572
+ v = index === 0 ? Math.min(v, b - gap) : Math.max(v, a + gap);
573
+ const next = index === 0 ? [v, b] : [a, v];
574
+ out = next[0] === a && next[1] === b ? prev : next;
575
+ } else out = v;
576
+ latest.current = out;
577
+ return out;
578
+ });
579
+ };
580
+ const trackRef = useRef3(null);
581
+ const rootRef = useRef3(null);
582
+ const thumbs = useRef3([]);
583
+ const active = useRef3(null);
584
+ const keyMoved = useRef3(false);
585
+ const [dragging, setDragging] = useState4(false);
586
+ const fromPointer = (e) => {
587
+ const r = trackRef.current?.getBoundingClientRect();
588
+ if (!r) return min;
589
+ const ratio = orientation === "horizontal" ? (e.clientX - r.left) / (r.width || 1) : (r.bottom - e.clientY) / (r.height || 1);
590
+ return min + clamp(ratio, 0, 1) * (max - min);
591
+ };
592
+ const onPointerDown = (e) => {
593
+ if (locked || e.button !== 0) return;
594
+ e.preventDefault();
595
+ const v = fromPointer(e);
596
+ let idx = 0;
597
+ if (values.length === 2) {
598
+ const [a, b] = values;
599
+ idx = Math.abs(v - a) < Math.abs(v - b) ? 0 : Math.abs(v - a) > Math.abs(v - b) ? 1 : v > b ? 1 : 0;
600
+ }
601
+ active.current = idx;
602
+ e.currentTarget.setPointerCapture?.(e.pointerId);
603
+ setDragging(true);
604
+ update(idx, v);
605
+ thumbs.current[idx]?.focus();
606
+ };
607
+ const onPointerMove = (e) => {
608
+ if (active.current == null) return;
609
+ update(active.current, fromPointer(e));
610
+ };
611
+ const endDrag = () => {
612
+ if (active.current == null) return;
613
+ active.current = null;
614
+ setDragging(false);
615
+ onValueCommit?.(latest.current);
616
+ };
617
+ const onKeyDown = (e, i) => {
618
+ if (locked) return;
619
+ let v = values[i];
620
+ switch (e.key) {
621
+ case "ArrowRight":
622
+ case "ArrowUp":
623
+ v += e.shiftKey ? big : step;
624
+ break;
625
+ case "ArrowLeft":
626
+ case "ArrowDown":
627
+ v -= e.shiftKey ? big : step;
628
+ break;
629
+ case "PageUp":
630
+ v += big;
631
+ break;
632
+ case "PageDown":
633
+ v -= big;
634
+ break;
635
+ case "Home":
636
+ v = min;
637
+ break;
638
+ case "End":
639
+ v = max;
640
+ break;
641
+ default:
642
+ return;
643
+ }
644
+ e.preventDefault();
645
+ keyMoved.current = true;
646
+ update(i, v);
647
+ };
648
+ const onKeyUp = () => {
649
+ if (!keyMoved.current) return;
650
+ keyMoved.current = false;
651
+ onValueCommit?.(latest.current);
652
+ };
653
+ const setValue = (v) => {
654
+ if (locked) return;
655
+ if (Array.isArray(v) && isRange) {
656
+ const a = fit(Math.min(v[0], v[1]));
657
+ const b = Math.max(fit(Math.max(v[0], v[1])), Math.min(top, a + gap));
658
+ latest.current = [a, b];
659
+ setCurrent([a, b]);
660
+ } else update(0, Array.isArray(v) ? v[0] : Number(v));
661
+ onValueCommit?.(latest.current);
662
+ };
663
+ useAgentBinding(rootRef, {
664
+ kind: "slider",
665
+ state: () => ({ value: latest.current, min, max, step, disabled: isDisabled, readOnly }),
666
+ actions: {
667
+ setValue: (v) => setValue(v),
668
+ increment: () => {
669
+ update(isRange ? 1 : 0, values[isRange ? 1 : 0] + step);
670
+ onValueCommit?.(latest.current);
671
+ },
672
+ decrement: () => {
673
+ update(0, values[0] - step);
674
+ onValueCommit?.(latest.current);
675
+ }
676
+ }
677
+ });
678
+ const ownLabelId = useId4();
679
+ const groupLabelId = ariaLabelledBy ?? (label ? ownLabelId : fc.inField ? fc.labelId : void 0);
680
+ const valueText = values.map(fmt).join(" \u2013 ");
681
+ const shouldShowValue = showValue ?? !!label;
682
+ const [startPct, endPct] = values.length === 2 ? [pct(values[0]), pct(values[1])] : [0, pct(values[0])];
683
+ const horizontal = orientation === "horizontal";
684
+ const along = (p) => horizontal ? { left: `${p}%` } : { bottom: `${p}%` };
685
+ const markList = (marks ?? []).map((m) => typeof m === "number" ? { value: m } : m);
686
+ return /* @__PURE__ */ jsxs4(
687
+ "div",
688
+ {
689
+ ref: rootRef,
690
+ role: "group",
691
+ id: fc.id,
692
+ "aria-label": ariaLabel,
693
+ "aria-labelledby": groupLabelId,
694
+ "aria-describedby": fc["aria-describedby"],
695
+ "data-sw": "slider",
696
+ "data-orientation": orientation,
697
+ "data-size": size,
698
+ "data-range": isRange ? "" : void 0,
699
+ "data-disabled": isDisabled ? "" : void 0,
700
+ "data-readonly": readOnly ? "" : void 0,
701
+ "data-dragging": dragging ? "" : void 0,
702
+ className: cx("sw-slider", className),
703
+ style,
704
+ children: [
705
+ (label || shouldShowValue) && /* @__PURE__ */ jsxs4("div", { className: "sw-slider__header", children: [
706
+ label && /* @__PURE__ */ jsx4("span", { id: ownLabelId, className: "sw-slider__label", children: label }),
707
+ shouldShowValue && /* @__PURE__ */ jsx4("output", { className: "sw-slider__value", "data-sw": "slider-value", "aria-hidden": "true", children: valueText })
708
+ ] }),
709
+ /* @__PURE__ */ jsxs4(
710
+ "div",
711
+ {
712
+ className: "sw-slider__control",
713
+ "data-sw": "slider-control",
714
+ onPointerDown,
715
+ onPointerMove,
716
+ onPointerUp: endDrag,
717
+ onPointerCancel: endDrag,
718
+ onLostPointerCapture: endDrag,
719
+ children: [
720
+ /* @__PURE__ */ jsxs4("div", { ref: trackRef, className: "sw-slider__track", "data-sw": "slider-track", children: [
721
+ /* @__PURE__ */ jsx4(
722
+ "div",
723
+ {
724
+ className: "sw-slider__indicator",
725
+ "data-sw": "slider-indicator",
726
+ style: horizontal ? { left: `${startPct}%`, width: `${endPct - startPct}%` } : { bottom: `${startPct}%`, height: `${endPct - startPct}%` }
727
+ }
728
+ ),
729
+ markList.map((m) => {
730
+ const p = pct(m.value);
731
+ return /* @__PURE__ */ jsx4("span", { className: "sw-slider__mark", "data-active": p >= startPct && p <= endPct ? "" : void 0, style: along(p) }, m.value);
732
+ })
733
+ ] }),
734
+ values.map((v, i) => {
735
+ const thumbId = `${ownLabelId}-t${i}`;
736
+ const thumbLabel = isRange ? thumbLabels?.[i] ?? (i === 0 ? "Minimum" : "Maximum") : void 0;
737
+ return /* @__PURE__ */ jsx4(
738
+ "div",
739
+ {
740
+ ref: (el) => {
741
+ thumbs.current[i] = el;
742
+ },
743
+ id: thumbId,
744
+ role: "slider",
745
+ tabIndex: isDisabled ? void 0 : 0,
746
+ "aria-valuenow": v,
747
+ "aria-valuemin": isRange && i === 1 ? values[0] + gap : min,
748
+ "aria-valuemax": isRange && i === 0 ? values[1] - gap : max,
749
+ "aria-valuetext": fmt(v),
750
+ "aria-orientation": orientation,
751
+ "aria-disabled": isDisabled || void 0,
752
+ "aria-readonly": readOnly || void 0,
753
+ "aria-label": thumbLabel ?? (groupLabelId ? void 0 : ariaLabel),
754
+ "aria-labelledby": groupLabelId ? thumbLabel ? `${groupLabelId} ${thumbId}` : groupLabelId : void 0,
755
+ "data-sw": "slider-thumb",
756
+ "data-index": i,
757
+ className: "sw-slider__thumb",
758
+ style: along(pct(v)),
759
+ onKeyDown: (e) => onKeyDown(e, i),
760
+ onKeyUp
761
+ },
762
+ i
763
+ );
764
+ })
765
+ ]
766
+ }
767
+ ),
768
+ markList.some((m) => m.label != null) && /* @__PURE__ */ jsx4("div", { className: "sw-slider__marks", "aria-hidden": "true", children: markList.map((m) => m.label != null && /* @__PURE__ */ jsx4("span", { className: "sw-slider__mark-label", style: along(pct(m.value)), children: m.label }, m.value)) }),
769
+ name && !isDisabled && /* @__PURE__ */ jsx4("input", { type: "hidden", name, value: values.join("/") })
770
+ ]
771
+ }
772
+ );
773
+ }
774
+
775
+ // src/components/number-input.tsx
776
+ import { forwardRef as forwardRef2, useEffect as useEffect3, useMemo as useMemo2, useRef as useRef4, useState as useState5 } from "react";
777
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
778
+ var NumberInput = forwardRef2(function NumberInput2({
779
+ value,
780
+ defaultValue = null,
781
+ onValueChange,
782
+ onValueCommit,
783
+ min,
784
+ max,
785
+ step = 1,
786
+ largeStep,
787
+ smallStep,
788
+ formatOptions,
789
+ locale,
790
+ wheel = false,
791
+ stepper = true,
792
+ label,
793
+ hint,
794
+ error,
795
+ invalid,
796
+ size = "md",
797
+ radius = "sm",
798
+ incrementLabel = "Increase",
799
+ decrementLabel = "Decrease",
800
+ className,
801
+ style,
802
+ id,
803
+ disabled,
804
+ required,
805
+ readOnly,
806
+ name,
807
+ onBlur,
808
+ onFocus,
809
+ onKeyDown,
810
+ onKeyUp,
811
+ "aria-describedby": ariaDescribedBy,
812
+ ...rest
813
+ }, ref) {
814
+ const fc = useFieldControl({ id, disabled, required, invalid: invalid ?? (error ? true : void 0), "aria-describedby": ariaDescribedBy });
815
+ const [num, setNum] = useControllableState({ value, defaultValue, onChange: onValueChange });
816
+ const latest = useRef4(num);
817
+ latest.current = num;
818
+ const lo = min ?? -Infinity;
819
+ const hi = max ?? Infinity;
820
+ const big = largeStep ?? step * 10;
821
+ const small = smallStep ?? step / 10;
822
+ const options = useMemo2(
823
+ () => ({ maximumFractionDigits: Math.max(formatOptions?.style === "percent" ? 0 : 3, decimalsOf(step), decimalsOf(small)), ...formatOptions }),
824
+ [formatOptions, step, small]
825
+ );
826
+ const fmt = useNumberFormat(locale, options);
827
+ const isPercent = options.style === "percent";
828
+ const format = (v) => v == null ? "" : fmt.format(v);
829
+ const parse = (text) => {
830
+ let s = text.trim().replace(/−/g, "-");
831
+ if (!s) return null;
832
+ const parts = fmt.formatToParts(-11111.1);
833
+ const group = parts.find((p) => p.type === "group")?.value;
834
+ const decimal = parts.find((p) => p.type === "decimal")?.value ?? ".";
835
+ if (group) s = s.split(group).join("");
836
+ s = s.replace(/[\s  ]/g, "");
837
+ if (decimal !== ".") s = s.split(decimal).join(".");
838
+ s = s.replace(/[^0-9.\-+eE]/g, "");
839
+ const n = Number(s);
840
+ if (s === "" || s === "-" || !Number.isFinite(n)) return NaN;
841
+ return isPercent ? n / 100 : n;
842
+ };
843
+ const inner = useRef4(null);
844
+ const rootRef = useRef4(null);
845
+ const setRef = useComposedRef(inner, ref);
846
+ const editing = useRef4(false);
847
+ const [draft, setDraft] = useState5(() => format(num));
848
+ useEffect3(() => {
849
+ if (!editing.current) setDraft(format(num));
850
+ }, [num, fmt]);
851
+ const isDisabled = !!fc.disabled;
852
+ const locked = isDisabled || !!readOnly;
853
+ const set = (v) => {
854
+ latest.current = v;
855
+ setNum(v);
856
+ setDraft(format(v));
857
+ };
858
+ const commit = () => {
859
+ const parsed = parse(draft);
860
+ const v = Number.isNaN(parsed) ? latest.current : parsed == null ? null : clamp(snap(parsed, step, min ?? 0), lo, hi);
861
+ set(v);
862
+ onValueCommit?.(v);
863
+ };
864
+ const stepBy = (amount, grid = step) => {
865
+ if (locked) return;
866
+ const parsed = parse(draft);
867
+ const base = Number.isNaN(parsed) || parsed == null ? latest.current : parsed;
868
+ if (base == null) {
869
+ set(amount > 0 ? Number.isFinite(lo) ? lo : 0 : Number.isFinite(hi) ? hi : 0);
870
+ return;
871
+ }
872
+ set(clamp(snap(base + amount, grid, min ?? 0), lo, hi));
873
+ };
874
+ const jump = (to) => !locked && Number.isFinite(to) && set(to);
875
+ const stepRef = useRef4(stepBy);
876
+ stepRef.current = stepBy;
877
+ useEffect3(() => {
878
+ const el = inner.current;
879
+ if (!el || !wheel) return;
880
+ const onWheel = (e) => {
881
+ if (document.activeElement !== el || e.deltaY === 0) return;
882
+ e.preventDefault();
883
+ stepRef.current((e.deltaY < 0 ? 1 : -1) * (e.shiftKey ? big : e.altKey ? small : step), e.altKey ? small : step);
884
+ onValueCommit?.(latest.current);
885
+ };
886
+ el.addEventListener("wheel", onWheel, { passive: false });
887
+ return () => el.removeEventListener("wheel", onWheel);
888
+ }, [wheel, big, small, step, onValueCommit]);
889
+ const timer = useRef4(null);
890
+ const stopRepeat = () => {
891
+ if (timer.current == null) return;
892
+ clearTimeout(timer.current);
893
+ timer.current = null;
894
+ onValueCommit?.(latest.current);
895
+ };
896
+ useEffect3(() => () => {
897
+ if (timer.current) clearTimeout(timer.current);
898
+ }, []);
899
+ const startRepeat = (dir, shift) => {
900
+ const amount = dir * (shift ? big : step);
901
+ stepRef.current(amount);
902
+ const loop = (delay) => {
903
+ timer.current = setTimeout(() => {
904
+ stepRef.current(amount);
905
+ loop(60);
906
+ }, delay);
907
+ };
908
+ loop(400);
909
+ };
910
+ useAgentBinding(rootRef, {
911
+ kind: "number-input",
912
+ state: () => ({ value: latest.current, min, max, step, disabled: isDisabled, readOnly: !!readOnly }),
913
+ actions: {
914
+ setValue: (v) => {
915
+ if (locked) return;
916
+ const n = v == null ? null : clamp(Number(v), lo, hi);
917
+ set(n);
918
+ onValueCommit?.(n);
919
+ },
920
+ increment: () => {
921
+ stepBy(step);
922
+ onValueCommit?.(latest.current);
923
+ },
924
+ decrement: () => {
925
+ stepBy(-step);
926
+ onValueCommit?.(latest.current);
927
+ },
928
+ clear: () => {
929
+ if (!locked) {
930
+ set(null);
931
+ onValueCommit?.(null);
932
+ }
933
+ }
934
+ }
935
+ });
936
+ const atMin = num != null && num <= lo;
937
+ const atMax = num != null && num >= hi;
938
+ const stepButton = (dir) => /* @__PURE__ */ jsx5(
939
+ InsetSquircleButton,
940
+ {
941
+ tabIndex: -1,
942
+ "aria-label": dir > 0 ? incrementLabel : decrementLabel,
943
+ "aria-controls": fc.id,
944
+ disabled: locked || (dir > 0 ? atMax : atMin),
945
+ "data-sw": dir > 0 ? "number-input-increment" : "number-input-decrement",
946
+ className: "sw-number-input__step",
947
+ onPointerDown: (e) => {
948
+ if (e.button !== 0) return;
949
+ e.preventDefault();
950
+ startRepeat(dir, e.shiftKey);
951
+ },
952
+ onPointerUp: stopRepeat,
953
+ onPointerLeave: stopRepeat,
954
+ onPointerCancel: stopRepeat,
955
+ onClick: (e) => {
956
+ if (e.detail === 0) {
957
+ stepBy(dir * step);
958
+ onValueCommit?.(latest.current);
959
+ }
960
+ },
961
+ children: /* @__PURE__ */ jsx5(Icon, { name: dir > 0 ? "plus" : "minus", width: 16, height: 16, weight: 1.75 })
962
+ }
963
+ );
964
+ return /* @__PURE__ */ jsxs5(
965
+ FieldShell,
966
+ {
967
+ slug: "number-input",
968
+ rootRef,
969
+ size,
970
+ radius,
971
+ controlId: fc.id,
972
+ label,
973
+ hint,
974
+ error,
975
+ invalid: !!fc["aria-invalid"],
976
+ disabled: isDisabled,
977
+ className,
978
+ style,
979
+ fieldClassName: stepper ? "sw-number-input__field" : void 0,
980
+ data: { "data-stepper": stepper ? "" : void 0 },
981
+ children: [
982
+ stepper && stepButton(-1),
983
+ /* @__PURE__ */ jsx5(
984
+ "input",
985
+ {
986
+ ref: setRef,
987
+ id: fc.id,
988
+ type: "text",
989
+ role: "spinbutton",
990
+ inputMode: "decimal",
991
+ autoComplete: "off",
992
+ autoCorrect: "off",
993
+ spellCheck: false,
994
+ disabled: fc.disabled,
995
+ required: fc.required,
996
+ readOnly,
997
+ "aria-valuenow": num ?? void 0,
998
+ "aria-valuemin": min,
999
+ "aria-valuemax": max,
1000
+ "aria-valuetext": draft || void 0,
1001
+ "aria-invalid": fc["aria-invalid"],
1002
+ "aria-describedby": describedBy(fc["aria-describedby"], fc.id, hint, error),
1003
+ "aria-labelledby": fc["aria-labelledby"],
1004
+ className: "sw-input__control sw-number-input__control",
1005
+ value: draft,
1006
+ onFocus: (e) => {
1007
+ editing.current = true;
1008
+ onFocus?.(e);
1009
+ },
1010
+ onBlur: (e) => {
1011
+ editing.current = false;
1012
+ commit();
1013
+ onBlur?.(e);
1014
+ },
1015
+ onChange: (e) => {
1016
+ const text = e.target.value;
1017
+ setDraft(text);
1018
+ const parsed = parse(text);
1019
+ if (!Number.isNaN(parsed)) {
1020
+ latest.current = parsed;
1021
+ setNum(parsed);
1022
+ }
1023
+ },
1024
+ onKeyDown: (e) => {
1025
+ onKeyDown?.(e);
1026
+ if (e.defaultPrevented) return;
1027
+ const amount = e.shiftKey ? big : e.altKey ? small : step;
1028
+ switch (e.key) {
1029
+ case "ArrowUp":
1030
+ stepBy(amount, e.altKey ? small : step);
1031
+ break;
1032
+ case "ArrowDown":
1033
+ stepBy(-amount, e.altKey ? small : step);
1034
+ break;
1035
+ case "PageUp":
1036
+ stepBy(big);
1037
+ break;
1038
+ case "PageDown":
1039
+ stepBy(-big);
1040
+ break;
1041
+ case "Home":
1042
+ if (min == null) return;
1043
+ jump(min);
1044
+ break;
1045
+ case "End":
1046
+ if (max == null) return;
1047
+ jump(max);
1048
+ break;
1049
+ case "Enter":
1050
+ commit();
1051
+ return;
1052
+ default:
1053
+ return;
1054
+ }
1055
+ e.preventDefault();
1056
+ },
1057
+ onKeyUp: (e) => {
1058
+ onKeyUp?.(e);
1059
+ if (["ArrowUp", "ArrowDown", "PageUp", "PageDown", "Home", "End"].includes(e.key)) onValueCommit?.(latest.current);
1060
+ },
1061
+ ...rest
1062
+ }
1063
+ ),
1064
+ stepper && stepButton(1),
1065
+ name && !isDisabled && /* @__PURE__ */ jsx5("input", { type: "hidden", name, value: num ?? "" })
1066
+ ]
1067
+ }
1068
+ );
1069
+ });
1070
+
1071
+ export {
1072
+ SegmentedControl,
1073
+ FieldContext,
1074
+ useFieldContext,
1075
+ useFieldControl,
1076
+ clamp,
1077
+ useGaugeFormat,
1078
+ isLabelable,
1079
+ labelClick,
1080
+ useComposedRef,
1081
+ setNativeValue,
1082
+ FieldShell,
1083
+ describedBy,
1084
+ ResizeGrip,
1085
+ Toggle,
1086
+ ToggleGroup,
1087
+ Slider,
1088
+ NumberInput
1089
+ };