@justanarthur/modo-ui-notch 0.0.0-stage → 0.2.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 (136) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -2
  3. package/blocks/activities/agenda/examples.mdx +58 -0
  4. package/blocks/activities/agenda/index.tsx +332 -0
  5. package/blocks/activities/now-playing/examples.mdx +49 -0
  6. package/blocks/activities/now-playing/index.tsx +218 -0
  7. package/blocks/activities/shelf/examples.mdx +33 -0
  8. package/blocks/activities/shelf/index.tsx +289 -0
  9. package/blocks/activities/timer/examples.mdx +52 -0
  10. package/blocks/activities/timer/index.tsx +292 -0
  11. package/blocks/app/expanded-island/examples.mdx +45 -0
  12. package/blocks/app/expanded-island/index.tsx +127 -0
  13. package/blocks/app/settings-window/examples.mdx +30 -0
  14. package/blocks/app/settings-window/index.tsx +357 -0
  15. package/blocks/system/controls/examples.mdx +34 -0
  16. package/blocks/system/controls/index.tsx +167 -0
  17. package/blocks/system/devices/examples.mdx +25 -0
  18. package/blocks/system/devices/index.tsx +172 -0
  19. package/blocks/system/power-alert/examples.mdx +32 -0
  20. package/blocks/system/power-alert/index.tsx +89 -0
  21. package/blocks/system/system-stats/examples.mdx +23 -0
  22. package/blocks/system/system-stats/index.tsx +178 -0
  23. package/components/indicators/battery-glyph/examples.mdx +22 -0
  24. package/components/indicators/battery-glyph/index.tsx +91 -0
  25. package/components/indicators/countdown/examples.mdx +25 -0
  26. package/components/indicators/countdown/index.tsx +83 -0
  27. package/components/indicators/equalizer/examples.mdx +20 -0
  28. package/components/indicators/equalizer/index.tsx +116 -0
  29. package/components/indicators/media-scrubber/examples.mdx +21 -0
  30. package/components/indicators/media-scrubber/index.tsx +98 -0
  31. package/components/island/island/examples.mdx +57 -0
  32. package/components/island/island/index.tsx +415 -0
  33. package/components/island/island-flash/examples.mdx +55 -0
  34. package/components/island/island-flash/index.tsx +79 -0
  35. package/components/island/island-tabs/examples.mdx +53 -0
  36. package/components/island/island-tabs/index.tsx +285 -0
  37. package/dist/blocks/activities/agenda/index.d.ts +2 -0
  38. package/dist/blocks/activities/agenda/index.js +21 -0
  39. package/dist/blocks/activities/now-playing/index.d.ts +2 -0
  40. package/dist/blocks/activities/now-playing/index.js +22 -0
  41. package/dist/blocks/activities/shelf/index.d.ts +2 -0
  42. package/dist/blocks/activities/shelf/index.js +14 -0
  43. package/dist/blocks/activities/timer/index.d.ts +2 -0
  44. package/dist/blocks/activities/timer/index.js +19 -0
  45. package/dist/blocks/app/expanded-island/index.d.ts +3 -0
  46. package/dist/blocks/app/expanded-island/index.js +10 -0
  47. package/dist/blocks/app/settings-window/index.d.ts +2 -0
  48. package/dist/blocks/app/settings-window/index.js +7 -0
  49. package/dist/blocks/system/controls/index.d.ts +2 -0
  50. package/dist/blocks/system/controls/index.js +10 -0
  51. package/dist/blocks/system/devices/index.d.ts +2 -0
  52. package/dist/blocks/system/devices/index.js +12 -0
  53. package/dist/blocks/system/power-alert/index.d.ts +2 -0
  54. package/dist/blocks/system/power-alert/index.js +9 -0
  55. package/dist/blocks/system/system-stats/index.d.ts +2 -0
  56. package/dist/blocks/system/system-stats/index.js +12 -0
  57. package/dist/components/indicators/battery-glyph/index.d.ts +2 -0
  58. package/dist/components/indicators/battery-glyph/index.js +9 -0
  59. package/dist/components/indicators/countdown/index.d.ts +2 -0
  60. package/dist/components/indicators/countdown/index.js +8 -0
  61. package/dist/components/indicators/equalizer/index.d.ts +2 -0
  62. package/dist/components/indicators/equalizer/index.js +7 -0
  63. package/dist/components/indicators/media-scrubber/index.d.ts +2 -0
  64. package/dist/components/indicators/media-scrubber/index.js +8 -0
  65. package/dist/components/island/island/index.d.ts +3 -0
  66. package/dist/components/island/island/index.js +10 -0
  67. package/dist/components/island/island-flash/index.d.ts +2 -0
  68. package/dist/components/island/island-flash/index.js +7 -0
  69. package/dist/components/island/island-tabs/index.d.ts +2 -0
  70. package/dist/components/island/island-tabs/index.js +9 -0
  71. package/dist/index.d.ts +21 -0
  72. package/dist/index.js +151 -0
  73. package/dist/lib/clock.d.ts +2 -0
  74. package/dist/lib/clock.js +14 -0
  75. package/dist/lib/geometry.d.ts +2 -0
  76. package/dist/lib/geometry.js +24 -0
  77. package/dist/lib/island-context.d.ts +3 -0
  78. package/dist/lib/island-context.js +8 -0
  79. package/dist/lib/motion.d.ts +21 -0
  80. package/dist/lib/motion.js +16 -0
  81. package/dist/shared/chunk-152gpyq3.d.ts +13 -0
  82. package/dist/shared/chunk-2f7zxrbk.js +65 -0
  83. package/dist/shared/chunk-2qpcsv5h.d.ts +45 -0
  84. package/dist/shared/chunk-2s4q6mt0.js +27 -0
  85. package/dist/shared/chunk-45gytfr1.d.ts +84 -0
  86. package/dist/shared/chunk-502rmtap.js +54 -0
  87. package/dist/shared/chunk-50ffk4r7.d.ts +69 -0
  88. package/dist/shared/chunk-52gb3g6r.d.ts +12 -0
  89. package/dist/shared/chunk-5en5aaj1.d.ts +33 -0
  90. package/dist/shared/chunk-5w0yck07.d.ts +32 -0
  91. package/dist/shared/chunk-6c1jbefs.d.ts +36 -0
  92. package/dist/shared/chunk-78w7qwp0.js +58 -0
  93. package/dist/shared/chunk-7hr53mby.js +116 -0
  94. package/dist/shared/chunk-9nhpg9t8.d.ts +47 -0
  95. package/dist/shared/chunk-b8jb1w72.js +145 -0
  96. package/dist/shared/chunk-cfzmfnyh.d.ts +63 -0
  97. package/dist/shared/chunk-cpewy6yg.js +178 -0
  98. package/dist/shared/chunk-d5qm9cps.js +10 -0
  99. package/dist/shared/chunk-e3e4s4ds.d.ts +77 -0
  100. package/dist/shared/chunk-enm6td0p.js +280 -0
  101. package/dist/shared/chunk-fvedaas2.d.ts +33 -0
  102. package/dist/shared/chunk-gb56m10p.js +39 -0
  103. package/dist/shared/chunk-gex38j8x.d.ts +82 -0
  104. package/dist/shared/chunk-hpsabfsd.d.ts +75 -0
  105. package/dist/shared/chunk-hrpxbqmx.d.ts +28 -0
  106. package/dist/shared/chunk-hwtxpzg0.js +69 -0
  107. package/dist/shared/chunk-mp1nx0ez.js +101 -0
  108. package/dist/shared/chunk-phb53x1f.js +252 -0
  109. package/dist/shared/chunk-r8esmjfs.d.ts +42 -0
  110. package/dist/shared/chunk-rcp1g9ca.js +70 -0
  111. package/dist/shared/chunk-rpfwv3pz.js +209 -0
  112. package/dist/shared/chunk-rr5e0g15.d.ts +35 -0
  113. package/dist/shared/chunk-rx9sphz2.js +266 -0
  114. package/dist/shared/chunk-s33y1pcq.js +305 -0
  115. package/dist/shared/chunk-sbnrhy5m.js +331 -0
  116. package/dist/shared/chunk-w48eyvfr.d.ts +56 -0
  117. package/dist/shared/chunk-wwjxs75m.js +74 -0
  118. package/dist/shared/chunk-xdeek16r.d.ts +58 -0
  119. package/dist/shared/chunk-xkzjk1tq.js +206 -0
  120. package/dist/shared/chunk-yngkkxz2.d.ts +88 -0
  121. package/dist/shared/chunk-zvh0d3qb.js +63 -0
  122. package/dist/styles.css +222 -0
  123. package/index.ts +21 -0
  124. package/lib/clock.ts +53 -0
  125. package/lib/geometry.ts +130 -0
  126. package/lib/island-context.tsx +24 -0
  127. package/lib/motion.ts +42 -0
  128. package/mock/activities.tsx +100 -0
  129. package/mock/artwork.tsx +25 -0
  130. package/mock/data.ts +153 -0
  131. package/mock/desktop.tsx +83 -0
  132. package/mock/fit.ts +26 -0
  133. package/mock/island-content.tsx +217 -0
  134. package/mock/scene.tsx +52 -0
  135. package/mock/settings.tsx +210 -0
  136. package/package.json +117 -4
@@ -0,0 +1,209 @@
1
+ "use client";
2
+
3
+ import {
4
+ DEFAULT_NOTCH2,
5
+ stripLayout2
6
+ } from "./chunk-zvh0d3qb.js";
7
+ import {
8
+ useIsland2
9
+ } from "./chunk-d5qm9cps.js";
10
+
11
+ // components/island/island-tabs/index.tsx
12
+ import { FocusRing } from "@justanarthur/modo-ui/lib/focus-ring";
13
+ import { GooIndicator } from "@justanarthur/modo-ui/lib/goo-indicator";
14
+ import { useRowFocus } from "@justanarthur/modo-ui/lib/row-group";
15
+ import { useShape } from "@justanarthur/modo-ui/lib/shape-context";
16
+ import { useSize } from "@justanarthur/modo-ui/lib/size-context";
17
+ import { useControllableState } from "@justanarthur/modo-ui/lib/use-controllable-state";
18
+ import { useFluidHover, useRegisterFluidHoverItem } from "@justanarthur/modo-ui/lib/use-fluid-hover";
19
+ import { cn } from "@justanarthur/modo-ui/lib/utils";
20
+ import { FluidHoverHighlight } from "@justanarthur/modo-ui/primitives/systems/fluid-hover";
21
+ import {
22
+ useEffect,
23
+ useLayoutEffect,
24
+ useRef,
25
+ useState
26
+ } from "react";
27
+ import { jsx, jsxs } from "react/jsx-runtime";
28
+ /*!
29
+ * Local addition: the open island's icon tabs, split across the two wings
30
+ * around the notch. Rebuilt from Just Notch's runtime (`island/tabs.tsx`) on
31
+ * modo-ui's fluid hover, liquid indicator and focus ring.
32
+ */
33
+ var TAB_WIDTH = { default: 40, compact: 30 };
34
+ var TAB_CLASS = { default: "w-10", compact: "w-7.5" };
35
+ var FADE = 16;
36
+ var NOTCH_FADE = 8;
37
+ function TabButton({ tab, index, selected, lit, size: sizeProp, register, onSelect }) {
38
+ const ref = useRef(null);
39
+ const size = useSize(sizeProp);
40
+ const shape = useShape();
41
+ useRegisterFluidHoverItem(register, index, ref);
42
+ const Icon = tab.icon;
43
+ return /* @__PURE__ */ jsx("button", {
44
+ ref,
45
+ type: "button",
46
+ role: "tab",
47
+ "aria-selected": selected,
48
+ "aria-label": tab.label,
49
+ tabIndex: selected ? 0 : -1,
50
+ "data-fluid-hover-index": index,
51
+ className: cn("relative z-10 flex shrink-0 cursor-pointer items-center justify-center bg-transparent outline-none transition-[color] duration-fast", size.control, TAB_CLASS[size.variant], shape.bg, lit ? "text-foreground" : "text-muted-foreground"),
52
+ onClick: () => onSelect(index),
53
+ children: /* @__PURE__ */ jsx(Icon, {
54
+ size: size.icon,
55
+ strokeWidth: lit ? 2 : 1.5,
56
+ className: "transition-[stroke-width] duration-fast"
57
+ })
58
+ });
59
+ }
60
+ function useWidth(ref) {
61
+ const [width, setWidth] = useState(0);
62
+ useLayoutEffect(() => {
63
+ const el = ref.current;
64
+ if (!el)
65
+ return;
66
+ setWidth(el.offsetWidth);
67
+ const observer = new ResizeObserver(() => setWidth(el.offsetWidth));
68
+ observer.observe(el);
69
+ return () => observer.disconnect();
70
+ }, [ref]);
71
+ return width;
72
+ }
73
+ function IslandTabs2({
74
+ tabs,
75
+ value: valueProp,
76
+ defaultValue,
77
+ onValueChange,
78
+ onHoverChange,
79
+ size: sizeProp,
80
+ notchWidth,
81
+ trailing,
82
+ label = "Widgets",
83
+ className
84
+ }) {
85
+ const [value, setValue] = useControllableState(valueProp, defaultValue ?? tabs[0]?.value, onValueChange);
86
+ const size = useSize(sizeProp);
87
+ const shape = useShape();
88
+ const island = useIsland2();
89
+ const notch = notchWidth ?? island?.geometry.notch.width ?? DEFAULT_NOTCH2.width;
90
+ const root = useRef(null);
91
+ const viewport = useRef(null);
92
+ const strip = useRef(null);
93
+ const end = useRef(null);
94
+ const width = useWidth(root);
95
+ const reserve = useWidth(end);
96
+ const hover = useFluidHover(strip, { axis: "x" });
97
+ const focus = useRowFocus(hover);
98
+ const selected = Math.max(0, tabs.findIndex((tab) => tab.value === value));
99
+ const layout = stripLayout2(tabs.length, width, notch, TAB_WIDTH[size.variant], reserve);
100
+ const hovered = hover.activeIndex === null ? null : tabs[hover.activeIndex]?.value ?? null;
101
+ const report = useRef(onHoverChange);
102
+ report.current = onHoverChange;
103
+ useEffect(() => report.current?.(hovered), [hovered]);
104
+ useEffect(() => {
105
+ const el = viewport.current;
106
+ const active = el?.querySelector("[role=tab][aria-selected=true]");
107
+ if (!el || !active)
108
+ return;
109
+ if (el.contains(document.activeElement) && document.activeElement !== active)
110
+ active.focus({ preventScroll: true });
111
+ const left = active.offsetLeft - el.scrollLeft;
112
+ const right = left + active.offsetWidth - el.clientWidth;
113
+ if (left < 0)
114
+ el.scrollBy({ left: left - FADE });
115
+ else if (right > 0)
116
+ el.scrollBy({ left: right + FADE });
117
+ }, [selected]);
118
+ useEffect(() => {
119
+ const el = viewport.current;
120
+ if (!el || !layout.overflow)
121
+ return;
122
+ const onWheel = (event) => {
123
+ if (Math.abs(event.deltaY) <= Math.abs(event.deltaX))
124
+ return;
125
+ event.preventDefault();
126
+ el.scrollLeft += event.deltaY;
127
+ };
128
+ el.addEventListener("wheel", onWheel, { passive: false });
129
+ return () => el.removeEventListener("wheel", onWheel);
130
+ }, [layout.overflow]);
131
+ const select = (index) => {
132
+ const tab = tabs[index];
133
+ if (tab)
134
+ setValue(tab.value);
135
+ };
136
+ const onKeyDown = (event) => {
137
+ const next = event.key === "ArrowRight" ? selected + 1 : event.key === "ArrowLeft" ? selected - 1 : event.key === "Home" ? 0 : event.key === "End" ? tabs.length - 1 : null;
138
+ if (next === null || !tabs[next])
139
+ return;
140
+ event.preventDefault();
141
+ select(next);
142
+ };
143
+ const hole = layout.overflow ? {
144
+ maskImage: `linear-gradient(to right, black ${layout.hole.start - NOTCH_FADE}px, transparent ${layout.hole.start}px, transparent ${layout.hole.end}px, black ${layout.hole.end + NOTCH_FADE}px)`
145
+ } : undefined;
146
+ const rect = hover.isMeasured ? hover.itemRects[selected] : undefined;
147
+ const button = (tab, index) => /* @__PURE__ */ jsx(TabButton, {
148
+ tab,
149
+ index,
150
+ selected: index === selected,
151
+ lit: index === selected || index === hover.activeIndex,
152
+ size: size.variant,
153
+ register: hover.registerItem,
154
+ onSelect: select
155
+ }, tab.value);
156
+ return /* @__PURE__ */ jsxs("div", {
157
+ ref: root,
158
+ className: cn("relative flex w-full min-w-0 items-center", size.control, className),
159
+ children: [
160
+ /* @__PURE__ */ jsx("div", {
161
+ className: "relative h-full min-w-0 flex-1",
162
+ style: hole,
163
+ children: /* @__PURE__ */ jsx("div", {
164
+ ref: viewport,
165
+ className: cn("h-full overflow-x-auto overflow-y-hidden scrollbar-hide", layout.overflow && "scroll-fade-x [--scroll-fade-size:16px]"),
166
+ children: /* @__PURE__ */ jsxs("div", {
167
+ ref: strip,
168
+ role: "tablist",
169
+ "aria-label": label,
170
+ className: "relative flex h-full w-max min-w-full items-center",
171
+ onKeyDown,
172
+ onMouseMove: hover.handlers.onMouseMove,
173
+ onMouseEnter: hover.handlers.onMouseEnter,
174
+ onMouseLeave: hover.handlers.onMouseLeave,
175
+ onFocus: focus.handlers.onFocus,
176
+ onBlur: focus.handlers.onBlur,
177
+ children: [
178
+ rect && /* @__PURE__ */ jsx(GooIndicator, {
179
+ rect,
180
+ className: cn("bg-active", shape.bg)
181
+ }),
182
+ /* @__PURE__ */ jsx(FluidHoverHighlight, {
183
+ hover,
184
+ hidden: hover.activeIndex === selected,
185
+ className: shape.bg
186
+ }),
187
+ /* @__PURE__ */ jsx(FocusRing, {
188
+ rect: focus.focusRect
189
+ }),
190
+ tabs.slice(0, layout.before).map(button),
191
+ /* @__PURE__ */ jsx("div", {
192
+ "aria-hidden": true,
193
+ className: "h-full shrink-0 grow",
194
+ style: { minWidth: layout.spacer }
195
+ }),
196
+ tabs.slice(layout.before).map((tab, i) => button(tab, layout.before + i))
197
+ ]
198
+ })
199
+ })
200
+ }),
201
+ trailing && /* @__PURE__ */ jsx("div", {
202
+ ref: end,
203
+ className: "flex shrink-0 items-center",
204
+ children: trailing
205
+ })
206
+ ]
207
+ });
208
+ }
209
+ export { IslandTabs2 };
@@ -0,0 +1,35 @@
1
+ import { SizeVariant } from "@justanarthur/modo-ui/lib/size-context";
2
+ import { JSX as JSX_1kxb } from "react";
3
+ interface MediaScrubberProps2 {
4
+ /** Where playback is, in seconds. */
5
+ position: number;
6
+ /** The track's length, in seconds. */
7
+ duration: number;
8
+ /** It plays: the position runs on from `position`, a second at a time. Defaults to `false`. */
9
+ playing?: boolean;
10
+ /** Called with the position to seek to, once, when a drag or a key press ends. */
11
+ onSeek?: (seconds: number) => void;
12
+ /** Step on the size ladder. Defaults to `'compact'`. */
13
+ size?: SizeVariant;
14
+ /** The slider's accessible name. Defaults to `'Position'`. */
15
+ label?: string;
16
+ /** No seeking. Defaults to `false`. */
17
+ disabled?: boolean;
18
+ /** Classes for the row. */
19
+ className?: string;
20
+ }
21
+ type Element_12xgc = JSX_1kxb["Element"];
22
+ /**
23
+ * Where a track is: elapsed time, a scrubber, and the time remaining.
24
+ *
25
+ * The scrubber is modo-ui's Slider at the compact step. While playing, the
26
+ * position runs on by itself a second at a time, on the second's edge, from
27
+ * the last `position` it got. Dragging shows the dragged value, and the
28
+ * remaining time follows it; `onSeek` fires once, when the drag or the key
29
+ * press ends, and playback runs on from the seek until the player reports
30
+ * its next `position`, so the thumb never jumps back to the stale one.
31
+ *
32
+ * @example {@include ./examples.mdx}
33
+ */
34
+ declare function MediaScrubber2({ position, duration, playing, onSeek, size, label, disabled, className }: MediaScrubberProps2): Element_12xgc;
35
+ export { MediaScrubberProps2, MediaScrubber2 };
@@ -0,0 +1,266 @@
1
+ "use client";
2
+
3
+ import {
4
+ SECOND2,
5
+ MINUTE2,
6
+ formatClock2,
7
+ useEdgeClock2
8
+ } from "./chunk-gb56m10p.js";
9
+ import {
10
+ Countdown2
11
+ } from "./chunk-502rmtap.js";
12
+ import {
13
+ IslandFlash2
14
+ } from "./chunk-78w7qwp0.js";
15
+
16
+ // blocks/activities/timer/index.tsx
17
+ import Button from "@justanarthur/modo-ui/components/actions/button";
18
+ import Meter from "@justanarthur/modo-ui/components/feedback/meter";
19
+ import NumberInput from "@justanarthur/modo-ui/components/inputs/number-input";
20
+ import { useControllableState } from "@justanarthur/modo-ui/lib/use-controllable-state";
21
+ import { cn } from "@justanarthur/modo-ui/lib/utils";
22
+ import { Pause, Play, Plus, Timer as TimerIcon, X } from "lucide-react";
23
+ import { useState } from "react";
24
+ import { jsx, jsxs } from "react/jsx-runtime";
25
+ /*!
26
+ * Local addition: a notch app's timer, from picking a length to "Time's up".
27
+ * Rebuilt from Just Notch's timer plugin (`Picker`, `Running`, `Ring`,
28
+ * `TimeUp`) as presentational parts: the run is a value the host may own.
29
+ */
30
+ var LABEL = { focus: "Focus", break: "Break", custom: "Timer" };
31
+ var start = (minutes, kind) => ({
32
+ kind,
33
+ total: minutes * MINUTE2,
34
+ endsAt: Date.now() + minutes * MINUTE2
35
+ });
36
+ var pause = (run) => ({ kind: run.kind, total: run.total, remaining: timeLeft(run, Date.now()) });
37
+ var resume = (run) => ({
38
+ kind: run.kind,
39
+ total: run.total,
40
+ endsAt: Date.now() + (run.remaining ?? 0)
41
+ });
42
+ var addMinute = (run) => run.endsAt === undefined ? { ...run, total: run.total + MINUTE2, remaining: (run.remaining ?? 0) + MINUTE2 } : { ...run, total: run.total + MINUTE2, endsAt: run.endsAt + MINUTE2 };
43
+ function timeLeft(run, now) {
44
+ return run.endsAt === undefined ? run.remaining ?? 0 : Math.max(0, run.endsAt - now);
45
+ }
46
+ function useTimeLeft(run) {
47
+ const end = run.endsAt ?? 0;
48
+ const now = useEdgeClock2(end, run.endsAt !== undefined && Date.now() < end + SECOND2);
49
+ return timeLeft(run, now);
50
+ }
51
+ function Ring({ run, className }) {
52
+ const left = useTimeLeft(run);
53
+ return /* @__PURE__ */ jsx(Meter, {
54
+ variant: "ring",
55
+ label: `${LABEL[run.kind]}, ${formatClock2(Math.ceil(left / SECOND2))} left`,
56
+ value: run.total ? left / run.total : 0,
57
+ tone: "default",
58
+ animate: false,
59
+ className
60
+ });
61
+ }
62
+ function Clock({ run, className, onEnd }) {
63
+ const paused = run.endsAt === undefined;
64
+ return /* @__PURE__ */ jsx(Countdown2, {
65
+ endsAt: run.endsAt,
66
+ paused,
67
+ remaining: run.remaining,
68
+ onEnd,
69
+ className: cn(className, paused ? "text-muted-foreground" : "text-status-warning")
70
+ });
71
+ }
72
+ function TimerLeading2() {
73
+ return /* @__PURE__ */ jsx(TimerIcon, {
74
+ size: 16,
75
+ strokeWidth: 1.5,
76
+ className: "text-status-warning"
77
+ });
78
+ }
79
+ function TimerTrailing2({ run }) {
80
+ return /* @__PURE__ */ jsx(Clock, {
81
+ run,
82
+ className: "text-caption weight-medium"
83
+ });
84
+ }
85
+ function TimerMinimal2({ run }) {
86
+ return /* @__PURE__ */ jsx(Ring, {
87
+ run,
88
+ className: "size-5.5"
89
+ });
90
+ }
91
+ function TimerDone2({ kind = "custom", next, minutes }) {
92
+ const detail = next ? `${LABEL[next]} starts now${minutes ? ` · ${minutes} min` : ""}` : `${LABEL[kind]} finished`;
93
+ return /* @__PURE__ */ jsx(IslandFlash2, {
94
+ icon: /* @__PURE__ */ jsx(TimerIcon, {
95
+ size: 20,
96
+ strokeWidth: 1.5
97
+ }),
98
+ tone: "warning",
99
+ title: "Time's up",
100
+ caption: detail
101
+ });
102
+ }
103
+ function Picker({ presets, focusMinutes, onStart }) {
104
+ const [minutes, setMinutes] = useState(null);
105
+ const valid = minutes !== null && Number.isInteger(minutes) && minutes >= 1 && minutes <= 99;
106
+ const submit = (event) => {
107
+ event.preventDefault();
108
+ if (valid)
109
+ onStart(start(minutes, "custom"));
110
+ };
111
+ return /* @__PURE__ */ jsxs("div", {
112
+ className: "flex size-full flex-col justify-center gap-3",
113
+ children: [
114
+ /* @__PURE__ */ jsxs("div", {
115
+ className: "grid grid-cols-4 gap-2",
116
+ children: [
117
+ presets.map((m) => /* @__PURE__ */ jsxs(Button, {
118
+ variant: "tertiary",
119
+ onClick: () => onStart(start(m, "custom")),
120
+ children: [
121
+ m,
122
+ " min"
123
+ ]
124
+ }, m)),
125
+ /* @__PURE__ */ jsx(Button, {
126
+ variant: "tertiary",
127
+ onClick: () => onStart(start(focusMinutes, "focus")),
128
+ children: "Pomodoro"
129
+ })
130
+ ]
131
+ }),
132
+ /* @__PURE__ */ jsxs("form", {
133
+ className: "flex items-center gap-2",
134
+ onSubmit: submit,
135
+ children: [
136
+ /* @__PURE__ */ jsx("div", {
137
+ className: "min-w-0 flex-1",
138
+ children: /* @__PURE__ */ jsx(NumberInput, {
139
+ className: "w-full",
140
+ variant: "bordered",
141
+ min: 1,
142
+ max: 99,
143
+ placeholder: "Custom minutes",
144
+ "aria-label": "Custom minutes",
145
+ endAdornment: "min",
146
+ value: minutes,
147
+ onValueChange: setMinutes
148
+ })
149
+ }),
150
+ /* @__PURE__ */ jsx(Button, {
151
+ type: "submit",
152
+ variant: "primary",
153
+ leadingIcon: Play,
154
+ disabled: !valid,
155
+ children: "Start"
156
+ })
157
+ ]
158
+ })
159
+ ]
160
+ });
161
+ }
162
+ function Running({ run, onChange, onEnd }) {
163
+ const paused = run.endsAt === undefined;
164
+ return /* @__PURE__ */ jsxs("div", {
165
+ className: "flex size-full items-center gap-5",
166
+ children: [
167
+ /* @__PURE__ */ jsx(Ring, {
168
+ run,
169
+ className: "size-16"
170
+ }),
171
+ /* @__PURE__ */ jsxs("div", {
172
+ className: "flex min-w-0 flex-1 flex-col",
173
+ children: [
174
+ /* @__PURE__ */ jsxs("span", {
175
+ className: "truncate text-caption text-muted-foreground",
176
+ children: [
177
+ LABEL[run.kind],
178
+ " · ",
179
+ Math.round(run.total / MINUTE2),
180
+ " min",
181
+ paused ? " · Paused" : ""
182
+ ]
183
+ }),
184
+ /* @__PURE__ */ jsx(Clock, {
185
+ run,
186
+ className: "text-display",
187
+ onEnd
188
+ })
189
+ ]
190
+ }),
191
+ /* @__PURE__ */ jsxs("div", {
192
+ className: "flex shrink-0 items-center gap-2",
193
+ children: [
194
+ /* @__PURE__ */ jsx(Button, {
195
+ variant: "tertiary",
196
+ leadingIcon: Plus,
197
+ onClick: () => onChange(addMinute(run)),
198
+ children: "1 min"
199
+ }),
200
+ /* @__PURE__ */ jsx(Button, {
201
+ variant: "tertiary",
202
+ size: "icon",
203
+ className: "text-status-warning",
204
+ "aria-label": paused ? "Resume" : "Pause",
205
+ onClick: () => onChange(paused ? resume(run) : pause(run)),
206
+ children: paused ? /* @__PURE__ */ jsx(Play, {
207
+ size: 16,
208
+ strokeWidth: 1.5,
209
+ fill: "currentColor"
210
+ }) : /* @__PURE__ */ jsx(Pause, {
211
+ size: 16,
212
+ strokeWidth: 1.5,
213
+ fill: "currentColor"
214
+ })
215
+ }),
216
+ /* @__PURE__ */ jsx(Button, {
217
+ variant: "tertiary",
218
+ size: "icon",
219
+ "aria-label": "Cancel",
220
+ onClick: () => onChange(null),
221
+ children: /* @__PURE__ */ jsx(X, {
222
+ size: 16,
223
+ strokeWidth: 1.5
224
+ })
225
+ })
226
+ ]
227
+ })
228
+ ]
229
+ });
230
+ }
231
+ function Timer2({
232
+ value,
233
+ defaultValue = null,
234
+ onValueChange,
235
+ onEnd,
236
+ presets = [1, 5, 10],
237
+ pomodoro = false,
238
+ focusMinutes = 25,
239
+ breakMinutes = 5,
240
+ className
241
+ }) {
242
+ const [run, setRun] = useControllableState(value, defaultValue, onValueChange);
243
+ const complete = (ended) => {
244
+ const next = pomodoro && ended.kind !== "custom" ? ended.kind === "focus" ? "break" : "focus" : undefined;
245
+ onEnd?.(ended, next);
246
+ setRun(next ? start(next === "break" ? breakMinutes : focusMinutes, next) : null);
247
+ };
248
+ return /* @__PURE__ */ jsx("div", {
249
+ className: cn("size-full", className),
250
+ children: run ? /* @__PURE__ */ jsx(Running, {
251
+ run,
252
+ onChange: setRun,
253
+ onEnd: () => complete(run)
254
+ }) : /* @__PURE__ */ jsx(Picker, {
255
+ presets,
256
+ focusMinutes,
257
+ onStart: setRun
258
+ })
259
+ });
260
+ }
261
+ Timer2.Leading = TimerLeading2;
262
+ Timer2.Trailing = TimerTrailing2;
263
+ Timer2.Minimal = TimerMinimal2;
264
+ Timer2.Done = TimerDone2;
265
+ var timer_default = Timer2;
266
+ export { TimerLeading2, TimerTrailing2, TimerMinimal2, TimerDone2, Timer2, timer_default };