nish-ui 2.0.1 → 2.1.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 (63) hide show
  1. package/README.md +18 -8
  2. package/dist/chart.js +1 -1
  3. package/dist/elements-all.js +13 -13
  4. package/dist/elements-charts.js +1 -1
  5. package/dist/elements-data.js +1 -1
  6. package/dist/elements-forms.js +1 -1
  7. package/dist/elements.js +3 -3
  8. package/dist/esm/components/app-shell.js +145 -45
  9. package/dist/esm/components/breadcrumbs.js +1 -1
  10. package/dist/esm/components/calendar-classes.js +325 -0
  11. package/dist/esm/components/calendar.js +263 -0
  12. package/dist/esm/components/canvas/route.js +56 -20
  13. package/dist/esm/components/carousel-classes.js +27 -0
  14. package/dist/esm/components/carousel.js +317 -0
  15. package/dist/esm/components/command.js +2 -27
  16. package/dist/esm/components/context-menu.js +199 -0
  17. package/dist/esm/components/date-picker.js +208 -0
  18. package/dist/esm/components/display-classes.js +10 -13
  19. package/dist/esm/components/display.js +22 -19
  20. package/dist/esm/components/drawer.js +139 -0
  21. package/dist/esm/components/filters.js +1 -1
  22. package/dist/esm/components/flow.js +1 -1
  23. package/dist/esm/components/hooks.js +17 -6
  24. package/dist/esm/components/hover-card.js +221 -0
  25. package/dist/esm/components/icons.js +17 -0
  26. package/dist/esm/components/inbox.js +2 -1
  27. package/dist/esm/components/lazy-module.js +53 -0
  28. package/dist/esm/components/menu.js +344 -0
  29. package/dist/esm/components/modal.js +173 -0
  30. package/dist/esm/components/more-sheet.js +52 -0
  31. package/dist/esm/components/multi-select.js +420 -0
  32. package/dist/esm/components/nav-items.js +138 -0
  33. package/dist/esm/components/nav.js +13 -174
  34. package/dist/esm/components/navigate.js +33 -0
  35. package/dist/esm/components/overlay-core.js +221 -0
  36. package/dist/esm/components/overlay-dialog.js +255 -0
  37. package/dist/esm/components/overlay-position.js +163 -0
  38. package/dist/esm/components/overlay.js +7 -1441
  39. package/dist/esm/components/popover.js +92 -0
  40. package/dist/esm/components/segmented.js +2 -1
  41. package/dist/esm/components/split.js +1 -1
  42. package/dist/esm/components/strings.js +25 -0
  43. package/dist/esm/components/tooltip.js +177 -0
  44. package/dist/esm/components/tree-view-classes.js +57 -0
  45. package/dist/esm/components/tree-view.js +319 -0
  46. package/dist/esm/components/virtual-table.js +245 -0
  47. package/dist/esm/components/virtual.js +291 -0
  48. package/dist/esm/inbox.js +12 -0
  49. package/dist/esm/index.js +61 -2
  50. package/dist/esm/runtime.js +1 -1
  51. package/dist/esm/service-tokens.js +6 -0
  52. package/dist/esm/theme.js +2 -2
  53. package/dist/esm/virtual-range.js +73 -0
  54. package/dist/format.js +1 -1
  55. package/dist/inbox.d.ts +238 -0
  56. package/dist/index.d.ts +1032 -778
  57. package/dist/nish-components.css +2 -0
  58. package/dist/nish-components.min.css +1 -1
  59. package/dist/service-tokens.d.ts +60 -0
  60. package/dist/theme.d.ts +50 -0
  61. package/dist/theme.global.js +28 -3
  62. package/dist/theme.js +28 -3
  63. package/package.json +17 -1
@@ -0,0 +1,263 @@
1
+ "use client";
2
+
3
+ // src/components/calendar.tsx
4
+ import { useId, useRef, useState, useSyncExternalStore } from "react";
5
+ import { cn } from "../cn.js";
6
+ import { getDefaultLocale } from "../format.js";
7
+ import {
8
+ addDays,
9
+ calendarKeyTarget,
10
+ clampIso,
11
+ dayNumber,
12
+ firstOfMonth,
13
+ fullDate,
14
+ inRange,
15
+ isoToday,
16
+ monthGrid,
17
+ monthNames,
18
+ monthOf,
19
+ monthTitle,
20
+ parseIso,
21
+ parseMonth,
22
+ resolveLocale,
23
+ shiftMonth,
24
+ weekStartFor,
25
+ weekdayNames
26
+ } from "./calendar-classes.js";
27
+ import { isRtl, useIsoLayoutEffect } from "./client.js";
28
+ import { ChevronLeftIcon, ChevronRightIcon } from "./icons.js";
29
+ import { IconButton, Select } from "./primitives.js";
30
+ import { useNishConfig, useNishStrings } from "./provider.js";
31
+ import { jsx, jsxs } from "react/jsx-runtime";
32
+ var warned = /* @__PURE__ */ new Set();
33
+ var noopSubscribe = () => () => {
34
+ };
35
+ var EMPTY_GRID = Array.from({ length: 6 }, () => Array.from({ length: 7 }, () => null));
36
+ var pad2 = (n) => String(n).padStart(2, "0");
37
+ var pad4 = (n) => String(n).padStart(4, "0");
38
+ function Calendar({
39
+ value,
40
+ defaultValue,
41
+ onValueChange,
42
+ month: monthProp,
43
+ defaultMonth,
44
+ onMonthChange,
45
+ min: minProp,
46
+ max: maxProp,
47
+ isDateDisabled,
48
+ locale,
49
+ weekStartsOn,
50
+ captionLayout = "label",
51
+ fromYear,
52
+ toYear,
53
+ autoFocus = false,
54
+ previousMonthLabel,
55
+ nextMonthLabel,
56
+ className,
57
+ ref,
58
+ ...rest
59
+ }) {
60
+ const strings = useNishStrings();
61
+ const config = useNishConfig();
62
+ const loc = resolveLocale(locale ?? config.locale ?? getDefaultLocale());
63
+ const ws = weekStartsOn ?? weekStartFor(loc);
64
+ const titleId = useId();
65
+ const rootRef = useRef(null);
66
+ const focusPending = useRef(false);
67
+ const check = (prop, v, isMonth = false) => {
68
+ if (v == null) return null;
69
+ const ok = isMonth ? parseMonth(v) !== null : parseIso(v) !== null;
70
+ if (ok) return v;
71
+ if (process.env.NODE_ENV !== "production" && !warned.has(prop)) {
72
+ warned.add(prop);
73
+ console.warn(`Calendar: "${prop}" must be ${isMonth ? "YYYY-MM" : "YYYY-MM-DD"}`);
74
+ }
75
+ return null;
76
+ };
77
+ const valueIso = check("value", value);
78
+ const defaultIso = check("defaultValue", defaultValue);
79
+ const min = check("min", minProp);
80
+ const max = check("max", maxProp);
81
+ const monthControlled = check("month", monthProp, true);
82
+ const defaultMonthIso = check("defaultMonth", defaultMonth, true);
83
+ const controlled = value !== void 0;
84
+ const [ownValue, setOwnValue] = useState(defaultIso);
85
+ const selected = controlled ? valueIso : ownValue;
86
+ const [ownMonth, setOwnMonth] = useState(() => defaultMonthIso ?? (selected ? monthOf(selected) : null));
87
+ const [focusedDate, setFocusedDate] = useState(null);
88
+ const today = useSyncExternalStore(
89
+ noopSubscribe,
90
+ () => isoToday(),
91
+ () => null
92
+ );
93
+ const shown = monthControlled ?? ownMonth ?? (today ? monthOf(today) : null);
94
+ const setMonth = (raw) => {
95
+ const next = clampIso(raw, "0001-01", "9999-12");
96
+ if (next === shown) return;
97
+ if (monthProp === void 0) setOwnMonth(next);
98
+ onMonthChange?.(next);
99
+ };
100
+ const disabled = (iso) => !inRange(iso, min, max) || isDateDisabled?.(iso) === true;
101
+ const inShown = (iso) => iso !== null && shown !== null && monthOf(iso) === shown;
102
+ let tabStop = null;
103
+ if (shown) {
104
+ if (inShown(focusedDate)) tabStop = focusedDate;
105
+ else if (inShown(selected)) tabStop = selected;
106
+ else if (inShown(today)) tabStop = today;
107
+ else {
108
+ const days = monthGrid(shown, ws).flat().filter((d) => d !== null);
109
+ tabStop = days.find((d) => !disabled(d)) ?? days[0] ?? null;
110
+ }
111
+ }
112
+ useIsoLayoutEffect(() => {
113
+ if (!focusPending.current) return;
114
+ focusPending.current = false;
115
+ if (!focusedDate) return;
116
+ rootRef.current?.querySelector(`[data-date="${focusedDate}"]`)?.focus();
117
+ });
118
+ const setRoot = (node) => {
119
+ rootRef.current = node;
120
+ if (typeof ref === "function") ref(node);
121
+ else if (ref) ref.current = node;
122
+ };
123
+ const pick = (iso) => {
124
+ if (disabled(iso)) return;
125
+ setFocusedDate(iso);
126
+ if (!controlled) setOwnValue(iso);
127
+ onValueChange?.(iso);
128
+ };
129
+ const onGridKey = (e) => {
130
+ const from = e.target.closest?.("[data-date]")?.getAttribute("data-date") ?? tabStop;
131
+ if (!from) return;
132
+ const raw = calendarKeyTarget(e.key, e.shiftKey, from, ws, isRtl(e.currentTarget));
133
+ if (!raw) return;
134
+ e.preventDefault();
135
+ const target = clampIso(raw, min ?? "0001-01-01", max ?? "9999-12-31");
136
+ const moved = target !== focusedDate || monthOf(target) !== shown;
137
+ setFocusedDate(target);
138
+ setMonth(monthOf(target));
139
+ if (moved) {
140
+ focusPending.current = true;
141
+ } else {
142
+ e.currentTarget.querySelector(`[data-date="${target}"]`)?.focus();
143
+ }
144
+ };
145
+ const grid = shown ? monthGrid(shown, ws) : EMPTY_GRID;
146
+ const names = weekdayNames(loc, ws);
147
+ const dropdowns = captionLayout === "dropdowns";
148
+ const shownYear = shown ? Number(shown.slice(0, 4)) : null;
149
+ const shownMonthNo = shown ? Number(shown.slice(5, 7)) : null;
150
+ const prevDisabled = !shown || shown <= "0001-01" || min !== null && addDays(firstOfMonth(shown), -1) < min;
151
+ const nextDisabled = !shown || shown >= "9999-12" || max !== null && firstOfMonth(shiftMonth(shown, 1)) > max;
152
+ let years = [];
153
+ if (dropdowns) {
154
+ const baseYear = today ? Number(today.slice(0, 4)) : shownYear ?? 2026;
155
+ const from = fromYear ?? (min ? Number(min.slice(0, 4)) : baseYear - 100);
156
+ const to = toYear ?? (max ? Number(max.slice(0, 4)) : baseYear + 10);
157
+ for (let y = from; y <= to; y++) years.push(y);
158
+ if (shownYear !== null && !years.includes(shownYear)) years = [...years, shownYear].sort((a, b) => a - b);
159
+ }
160
+ return /* @__PURE__ */ jsxs("div", { ...rest, ref: setRoot, className: cn("inline-flex select-none flex-col gap-2", className), children: [
161
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-1", children: [
162
+ /* @__PURE__ */ jsx(
163
+ IconButton,
164
+ {
165
+ size: "sm",
166
+ label: previousMonthLabel ?? strings.previousMonth,
167
+ "aria-disabled": prevDisabled || void 0,
168
+ className: "aria-disabled:cursor-not-allowed aria-disabled:opacity-40",
169
+ onClick: () => !prevDisabled && shown && setMonth(shiftMonth(shown, -1)),
170
+ children: /* @__PURE__ */ jsx(ChevronLeftIcon, { className: "rtl:-scale-x-100" })
171
+ }
172
+ ),
173
+ /* @__PURE__ */ jsx("div", { id: titleId, "aria-live": "polite", className: cn("text-sm font-semibold text-th-hi", dropdowns && "sr-only"), children: shown ? monthTitle(shown, loc) : "" }),
174
+ dropdowns && /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-1", children: [
175
+ /* @__PURE__ */ jsx(
176
+ Select,
177
+ {
178
+ size: "sm",
179
+ "aria-label": strings.month,
180
+ value: shownMonthNo ?? "",
181
+ disabled: !shown,
182
+ onChange: (e) => shownYear !== null && setMonth(`${pad4(shownYear)}-${pad2(Number(e.target.value))}`),
183
+ children: monthNames(loc).map((name, i) => /* @__PURE__ */ jsx("option", { value: i + 1, children: name }, i))
184
+ }
185
+ ),
186
+ /* @__PURE__ */ jsx(
187
+ Select,
188
+ {
189
+ size: "sm",
190
+ "aria-label": strings.year,
191
+ value: shownYear ?? "",
192
+ disabled: !shown,
193
+ onChange: (e) => shownMonthNo !== null && setMonth(`${pad4(Number(e.target.value))}-${pad2(shownMonthNo)}`),
194
+ children: years.map((y) => /* @__PURE__ */ jsx("option", { value: y, children: y }, y))
195
+ }
196
+ )
197
+ ] }),
198
+ /* @__PURE__ */ jsx(
199
+ IconButton,
200
+ {
201
+ size: "sm",
202
+ label: nextMonthLabel ?? strings.nextMonth,
203
+ "aria-disabled": nextDisabled || void 0,
204
+ className: "aria-disabled:cursor-not-allowed aria-disabled:opacity-40",
205
+ onClick: () => !nextDisabled && shown && setMonth(shiftMonth(shown, 1)),
206
+ children: /* @__PURE__ */ jsx(ChevronRightIcon, { className: "rtl:-scale-x-100" })
207
+ }
208
+ )
209
+ ] }),
210
+ /* @__PURE__ */ jsxs("table", { role: "grid", "aria-labelledby": titleId, className: "border-collapse", onKeyDown: onGridKey, children: [
211
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: names.map((n) => /* @__PURE__ */ jsx(
212
+ "th",
213
+ {
214
+ scope: "col",
215
+ abbr: n.long,
216
+ className: "size-10 overflow-hidden px-0.5 py-0 text-center text-xs font-medium text-th-hi3 pointer-coarse:h-11 pointer-coarse:w-[min(2.75rem,calc((100vw_-_2.6rem)/7))]",
217
+ children: n.short
218
+ },
219
+ n.long
220
+ )) }) }),
221
+ /* @__PURE__ */ jsx("tbody", { children: grid.map((row, r) => /* @__PURE__ */ jsx("tr", { children: row.map((iso, c) => {
222
+ if (!iso) {
223
+ return /* @__PURE__ */ jsx("td", { className: "p-0", children: /* @__PURE__ */ jsx(
224
+ "div",
225
+ {
226
+ "aria-hidden": "true",
227
+ className: "size-10 pointer-coarse:h-11 pointer-coarse:w-[min(2.75rem,calc((100vw_-_2.6rem)/7))]"
228
+ }
229
+ ) }, c);
230
+ }
231
+ const isSelected = iso === selected;
232
+ const isDisabled = disabled(iso);
233
+ const isTabStop = iso === tabStop;
234
+ return /* @__PURE__ */ jsx("td", { role: "gridcell", "aria-selected": isSelected, className: "p-0", children: /* @__PURE__ */ jsx(
235
+ "button",
236
+ {
237
+ type: "button",
238
+ tabIndex: isTabStop ? 0 : -1,
239
+ "data-date": iso,
240
+ "data-autofocus": autoFocus && isTabStop ? "" : void 0,
241
+ "aria-label": fullDate(iso, loc),
242
+ "aria-current": iso === today ? "date" : void 0,
243
+ "aria-disabled": isDisabled || void 0,
244
+ "data-state": isSelected ? "active" : "inactive",
245
+ "data-disabled": isDisabled ? "" : void 0,
246
+ onClick: () => pick(iso),
247
+ className: cn(
248
+ "flex size-10 items-center justify-center rounded-lg text-sm tabular-nums text-th-hi2 transition-colors pointer-coarse:h-11 pointer-coarse:w-[min(2.75rem,calc((100vw_-_2.6rem)/7))]",
249
+ !isSelected && !isDisabled && "hover:bg-th-elevated hover:text-th-hi",
250
+ iso === today && !isSelected && "font-semibold text-th-accent ring-1 ring-inset ring-th-accent/50",
251
+ isSelected && "bg-th-accent font-semibold text-th-on-accent forced-colors:bg-[Highlight] forced-colors:text-[HighlightText] forced-colors:forced-color-adjust-none",
252
+ isDisabled && "cursor-not-allowed text-th-ghost line-through forced-colors:text-[GrayText]"
253
+ ),
254
+ children: dayNumber(iso, loc)
255
+ }
256
+ ) }, c);
257
+ }) }, r)) })
258
+ ] })
259
+ ] });
260
+ }
261
+ export {
262
+ Calendar
263
+ };
@@ -175,20 +175,34 @@ function routeColumns(layout, groups, edges) {
175
175
  ln.x = list.length === 1 || hi <= lo ? (l + r) / 2 : lo + (hi - lo) * i / (list.length - 1);
176
176
  });
177
177
  }
178
- const taken = [];
178
+ const buckets = /* @__PURE__ */ new Map();
179
+ const addTaken = (h) => {
180
+ const k = Math.floor(h.y / TRACK_GAP);
181
+ const list = buckets.get(k);
182
+ if (list) list.push(h);
183
+ else buckets.set(k, [h]);
184
+ };
179
185
  for (const w of wires) {
180
- taken.push({ y: w.src.y, xa: w.src.x, xb: lanes.get(w.exit).x, src: w.src.key, dst: w.dst.key, track: false });
181
- taken.push({ y: w.dst.y, xa: lanes.get(w.entry).x, xb: w.dst.x, src: w.src.key, dst: w.dst.key, track: false });
186
+ addTaken({ y: w.src.y, xa: w.src.x, xb: lanes.get(w.exit).x, src: w.src.key, dst: w.dst.key, track: false });
187
+ addTaken({ y: w.dst.y, xa: lanes.get(w.entry).x, xb: w.dst.x, src: w.src.key, dst: w.dst.key, track: false });
182
188
  }
183
189
  const sameLine = (h, w) => h.src === w.src.key || h.dst === w.dst.key;
184
190
  const trackFree = (y, xa, xb, w) => {
185
- for (const h of taken) {
186
- if (Math.min(xb, h.xb) - Math.max(xa, h.xa) <= 0.5) continue;
187
- const dy = Math.abs(h.y - y);
188
- if (dy < 0.5 ? !sameLine(h, w) : h.track && dy < TRACK_GAP - 0.5) return false;
191
+ const lastBucket = Math.floor((y + TRACK_GAP) / TRACK_GAP);
192
+ for (let k = Math.floor((y - TRACK_GAP) / TRACK_GAP); k <= lastBucket; k++) {
193
+ const list = buckets.get(k);
194
+ if (!list) continue;
195
+ for (const h of list) {
196
+ if (Math.min(xb, h.xb) - Math.max(xa, h.xa) <= 0.5) continue;
197
+ const dy = Math.abs(h.y - y);
198
+ if (dy < 0.5 ? !sameLine(h, w) : h.track && dy < TRACK_GAP - 0.5) return false;
199
+ }
189
200
  }
190
201
  return true;
191
202
  };
203
+ let trackSeq = 0;
204
+ const tracksByPort = /* @__PURE__ */ new Map();
205
+ const noTracks = [];
192
206
  const spanOf = (w) => w.mode === "far" ? [w.src.col + 1, w.dst.col - 1] : [w.dst.col, w.src.col];
193
207
  const cardFree = (y, c0, c1) => {
194
208
  for (let c = c0; c <= c1; c++) for (const b of cols[c].boxes) if (y > b.y - CLEARANCE + 1e-6 && y < b.y + b.h + CLEARANCE - 1e-6) return false;
@@ -226,24 +240,46 @@ function routeColumns(layout, groups, edges) {
226
240
  const [c0, c1] = spanOf(w);
227
241
  const avg = (w.src.y + w.dst.y) / 2;
228
242
  const near = (a, b) => Math.abs(a - avg) - Math.abs(b - avg) || a - b;
229
- const candidates = [];
230
- for (const h of taken) if (h.track && sameLine(h, w) && !candidates.includes(h.y)) candidates.push(h.y);
231
- for (const b of [...bandsOf(c0, c1)].sort((p, q) => gap(avg, p) - gap(avg, q) || p[0] - q[0])) {
232
- const n = Math.min(Math.floor((b[1] - b[0]) / TRACK_GAP) + 1, wanted.get(`${b[0]}|${b[1]}`) ?? 1);
233
- const slots = [];
234
- for (let i = 0; i < n; i++) slots.push((b[0] + b[1]) / 2 + TRACK_GAP * (i - (n - 1) / 2));
235
- candidates.push(...slots.sort(near));
236
- }
237
- const outer = [];
238
- for (let k = 0; k <= wires.length; k++) outer.push(minY - OUTSIDE_GAP - TRACK_GAP * k, maxY + OUTSIDE_GAP + TRACK_GAP * k);
239
- candidates.push(...outer.sort(near));
240
243
  const xo = lanes.get(w.exit).x;
241
244
  const xe = lanes.get(w.entry).x;
242
245
  const xa = Math.min(xo, xe);
243
246
  const xb = Math.max(xo, xe);
244
- const y = candidates.find((c) => cardFree(c, c0, c1) && trackFree(c, xa, xb, w)) ?? candidates[candidates.length - 1];
247
+ const ok = (c) => cardFree(c, c0, c1) && trackFree(c, xa, xb, w);
248
+ const find = () => {
249
+ const bySrc = tracksByPort.get("s" + w.src.key) ?? noTracks;
250
+ const byDst = tracksByPort.get("d" + w.dst.key) ?? noTracks;
251
+ const seen = /* @__PURE__ */ new Set();
252
+ for (let i = 0, j = 0; i < bySrc.length || j < byDst.length; ) {
253
+ const t = j >= byDst.length || i < bySrc.length && bySrc[i][1] <= byDst[j][1] ? bySrc[i++] : byDst[j++];
254
+ if (seen.has(t[0])) continue;
255
+ seen.add(t[0]);
256
+ if (ok(t[0])) return t[0];
257
+ }
258
+ for (const b of [...bandsOf(c0, c1)].sort((p, q) => gap(avg, p) - gap(avg, q) || p[0] - q[0])) {
259
+ const n = Math.min(Math.floor((b[1] - b[0]) / TRACK_GAP) + 1, wanted.get(`${b[0]}|${b[1]}`) ?? 1);
260
+ const slots = [];
261
+ for (let i = 0; i < n; i++) slots.push((b[0] + b[1]) / 2 + TRACK_GAP * (i - (n - 1) / 2));
262
+ for (const c of slots.sort(near)) if (ok(c)) return c;
263
+ }
264
+ let last = 0;
265
+ for (let i = 0, j = 0; i <= wires.length || j <= wires.length; ) {
266
+ const up = minY - OUTSIDE_GAP - TRACK_GAP * i;
267
+ const down = maxY + OUTSIDE_GAP + TRACK_GAP * j;
268
+ const c = j > wires.length || i <= wires.length && near(up, down) <= 0 ? (i++, up) : (j++, down);
269
+ if (ok(c)) return c;
270
+ last = c;
271
+ }
272
+ return last;
273
+ };
274
+ const y = find();
245
275
  trackYs.set(w.edge.id, y);
246
- taken.push({ y, xa, xb, src: w.src.key, dst: w.dst.key, track: true });
276
+ addTaken({ y, xa, xb, src: w.src.key, dst: w.dst.key, track: true });
277
+ for (const key of ["s" + w.src.key, "d" + w.dst.key]) {
278
+ const list = tracksByPort.get(key);
279
+ if (list) list.push([y, trackSeq]);
280
+ else tracksByPort.set(key, [[y, trackSeq]]);
281
+ }
282
+ trackSeq++;
247
283
  }
248
284
  for (const w of wires) {
249
285
  const { src, dst } = w;
@@ -0,0 +1,27 @@
1
+ // src/components/carousel-classes.ts
2
+ var CAROUSEL_MIN_INTERVAL = 2e3;
3
+ var CAROUSEL_MAX_DOTS = 7;
4
+ function nearestSlide(starts, origin) {
5
+ let best = -1;
6
+ let bestDistance = Infinity;
7
+ for (let i = 0; i < starts.length; i++) {
8
+ const distance = Math.abs(starts[i] - origin);
9
+ if (distance < bestDistance) {
10
+ best = i;
11
+ bestDistance = distance;
12
+ }
13
+ }
14
+ return best;
15
+ }
16
+ function stepIndex(index, dir, count, loop) {
17
+ if (count <= 0) return 0;
18
+ const next = index + dir;
19
+ if (loop) return (next + count) % count;
20
+ return Math.min(Math.max(next, 0), count - 1);
21
+ }
22
+ export {
23
+ CAROUSEL_MAX_DOTS,
24
+ CAROUSEL_MIN_INTERVAL,
25
+ nearestSlide,
26
+ stepIndex
27
+ };