@pawkit/ui 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 (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +28 -2
  3. package/dist/index.d.ts +26 -0
  4. package/dist/index.js +26 -0
  5. package/dist/lib/sounds.d.ts +5 -0
  6. package/dist/lib/sounds.js +94 -0
  7. package/dist/lib/utils.d.ts +2 -0
  8. package/dist/lib/utils.js +5 -0
  9. package/dist/ui/avatar.d.ts +17 -0
  10. package/dist/ui/avatar.js +30 -0
  11. package/dist/ui/button.d.ts +15 -0
  12. package/dist/ui/button.js +38 -0
  13. package/dist/ui/card.d.ts +6 -0
  14. package/dist/ui/card.js +14 -0
  15. package/dist/ui/command.d.ts +17 -0
  16. package/dist/ui/command.js +42 -0
  17. package/dist/ui/dialog.d.ts +14 -0
  18. package/dist/ui/dialog.js +25 -0
  19. package/dist/ui/dropzone.d.ts +14 -0
  20. package/dist/ui/dropzone.js +70 -0
  21. package/dist/ui/empty-state.d.ts +10 -0
  22. package/dist/ui/empty-state.js +12 -0
  23. package/dist/ui/fluid-hover.d.ts +15 -0
  24. package/dist/ui/fluid-hover.js +69 -0
  25. package/dist/ui/input.d.ts +8 -0
  26. package/dist/ui/input.js +15 -0
  27. package/dist/ui/juicy-button.d.ts +21 -0
  28. package/dist/ui/juicy-button.js +32 -0
  29. package/dist/ui/kbd.d.ts +3 -0
  30. package/dist/ui/kbd.js +7 -0
  31. package/dist/ui/list.d.ts +24 -0
  32. package/dist/ui/list.js +20 -0
  33. package/dist/ui/menu.d.ts +20 -0
  34. package/dist/ui/menu.js +42 -0
  35. package/dist/ui/pixel-pup.d.ts +88 -0
  36. package/dist/ui/pixel-pup.js +424 -0
  37. package/dist/ui/popover.d.ts +8 -0
  38. package/dist/ui/popover.js +12 -0
  39. package/dist/ui/segmented-control.d.ts +15 -0
  40. package/dist/ui/segmented-control.js +45 -0
  41. package/dist/ui/sheet.d.ts +12 -0
  42. package/dist/ui/sheet.js +16 -0
  43. package/dist/ui/slider.d.ts +5 -0
  44. package/dist/ui/slider.js +12 -0
  45. package/dist/ui/stepper.d.ts +14 -0
  46. package/dist/ui/stepper.js +55 -0
  47. package/dist/ui/switch.d.ts +5 -0
  48. package/dist/ui/switch.js +9 -0
  49. package/dist/ui/tabs.d.ts +10 -0
  50. package/dist/ui/tabs.js +43 -0
  51. package/dist/ui/toast.d.ts +22 -0
  52. package/dist/ui/toast.js +49 -0
  53. package/dist/ui/tooltip.d.ts +17 -0
  54. package/dist/ui/tooltip.js +16 -0
  55. package/dist/ui/tuner.d.ts +39 -0
  56. package/dist/ui/tuner.js +52 -0
  57. package/package.json +63 -5
  58. package/styles.css +279 -0
@@ -0,0 +1,424 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ /* 16×11 sprites, facing right. b body · t tail · w belly · e ear · k eye · n nose · c closed eye */
5
+ const DOG = {
6
+ sit: [
7
+ "..........e..e..",
8
+ "..........ee.ee.",
9
+ ".........bbbbbb.",
10
+ ".........bbbkbbb",
11
+ ".........bbbbbbn",
12
+ "........wwwwbbb.",
13
+ ".......bbwwww...",
14
+ "t.....bbbbbww...",
15
+ "tt...bbbbbbww...",
16
+ ".tbbbbbbbbbwb...",
17
+ "..wwwbbbb.ww.w..",
18
+ ],
19
+ sitWag: [
20
+ "..........e..e..",
21
+ "..........ee.ee.",
22
+ ".........bbbbbb.",
23
+ ".........bbbkbbb",
24
+ ".........bbbbbbn",
25
+ "t.......wwwwbbb.",
26
+ "t......bbwwww...",
27
+ ".t....bbbbbww...",
28
+ "..b..bbbbbbww...",
29
+ "..bbbbbbbbbwb...",
30
+ "..wwwbbbb.ww.w..",
31
+ ],
32
+ stand: [
33
+ "..........e..e..",
34
+ "..........ee.ee.",
35
+ ".........bbbbbb.",
36
+ ".........bbbkbbb",
37
+ "t........bbbbbbn",
38
+ "tt.......wwwbbb.",
39
+ ".tbbbbbbbbwww...",
40
+ "..bbbbbbbbbbb...",
41
+ "..bbbbbbbbbbb...",
42
+ "..wb.wb..wb.wb..",
43
+ "..ww.ww..ww.ww..",
44
+ ],
45
+ standWag: [
46
+ "..........e..e..",
47
+ "..........ee.ee.",
48
+ "t........bbbbbb.",
49
+ "t........bbbkbbb",
50
+ ".t.......bbbbbbn",
51
+ "..b......wwwbbb.",
52
+ "..bbbbbbbbwww...",
53
+ "..bbbbbbbbbbb...",
54
+ "..bbbbbbbbbbb...",
55
+ "..wb.wb..wb.wb..",
56
+ "..ww.ww..ww.ww..",
57
+ ],
58
+ run: [
59
+ "..........e..e..",
60
+ "t.........ee.ee.",
61
+ "tt.......bbbbbb.",
62
+ ".t.......bbbkbbb",
63
+ "..b......bbbbbbn",
64
+ "..bbbbbbbwwwbbb.",
65
+ "..bbbbbbbbwww...",
66
+ "..bbbbbbbbbbb...",
67
+ ".wb..bb..bb.wb..",
68
+ "ww...ww..ww..ww.",
69
+ "................",
70
+ ],
71
+ sleep: [
72
+ "................",
73
+ "................",
74
+ "................",
75
+ "................",
76
+ "................",
77
+ ".........ee.ee..",
78
+ "t.......bbbbbb..",
79
+ "tbbbbbbbbbccbbbn",
80
+ ".bbbbbbbbbbbbbb.",
81
+ ".wwbbbbbbbbwwww.",
82
+ "................",
83
+ ],
84
+ };
85
+ const CAT = {
86
+ sit: [
87
+ "...........e..e.",
88
+ "..........ee.ee.",
89
+ "..........bbbbb.",
90
+ "..........bbkbbb",
91
+ "..........bbbbbn",
92
+ "...........wbbb.",
93
+ "t.........bwww..",
94
+ "t........bbwww..",
95
+ "t.......bbbbww..",
96
+ ".t......bbbbww..",
97
+ ".tbbbbbbbbbwbw..",
98
+ ],
99
+ sitWag: [
100
+ "...........e..e.",
101
+ "..........ee.ee.",
102
+ "..........bbbbb.",
103
+ "..........bbkbbb",
104
+ "..........bbbbbn",
105
+ "t..........wbbb.",
106
+ ".t........bwww..",
107
+ ".t.......bbwww..",
108
+ "..t.....bbbbww..",
109
+ "..t.....bbbbww..",
110
+ "...bbbbbbbbwbw..",
111
+ ],
112
+ stand: [
113
+ "...........e..e.",
114
+ "t.........ee.ee.",
115
+ "t.........bbbbb.",
116
+ ".t........bbkbbb",
117
+ ".t........bbbbbn",
118
+ "..t......bbwbb..",
119
+ "..bbbbbbbbbww...",
120
+ "..bbbbbbbbbbw...",
121
+ "..bbbbbbbbbbb...",
122
+ "..b.b....b.b....",
123
+ "..w.w....w.w....",
124
+ ],
125
+ standWag: [
126
+ "...........e..e.",
127
+ "..........ee.ee.",
128
+ "t.........bbbbb.",
129
+ "t.........bbkbbb",
130
+ ".t........bbbbbn",
131
+ "..t......bbwbb..",
132
+ "..bbbbbbbbbww...",
133
+ "..bbbbbbbbbbw...",
134
+ "..bbbbbbbbbbb...",
135
+ "..b.b....b.b....",
136
+ "..w.w....w.w....",
137
+ ],
138
+ run: [
139
+ "...........e..e.",
140
+ "..........ee.ee.",
141
+ "tt........bbbbb.",
142
+ "..t.......bbkbbb",
143
+ "...t......bbbbbn",
144
+ "...bbbbbbbbwbb..",
145
+ "..bbbbbbbbbbw...",
146
+ "..bbbbbbbbbbb...",
147
+ ".bb.........bb..",
148
+ "bw...........wb.",
149
+ "................",
150
+ ],
151
+ sleep: [
152
+ "................",
153
+ "................",
154
+ "................",
155
+ "................",
156
+ "................",
157
+ "...........e.e..",
158
+ "......bbbbbbbbb.",
159
+ ".....bbbbbbbccbn",
160
+ "....bbbbbbbbbbb.",
161
+ ".ttbbbbbbbbbbww.",
162
+ ".twwbbbbbbbbbw..",
163
+ ],
164
+ };
165
+ /** Built-in coats. Pass a name, or your own PupPalette. */
166
+ export const PUP_PALETTES = {
167
+ shiba: { body: "#e9a867", belly: "#fff4e6", ear: "#c9783c", eye: "#2b2420" },
168
+ cream: { body: "#f1d7ae", belly: "#fffaf0", ear: "#dcb27c", eye: "#3a2e26" },
169
+ cocoa: { body: "#8b5e3c", belly: "#f1d9bd", ear: "#6b4429", eye: "#1d1410" },
170
+ husky: { body: "#8c95a1", belly: "#f4f6f8", ear: "#5e6670", eye: "#1f2937", nose: "#1f2937" },
171
+ midnight: { body: "#3d3a40", belly: "#e9e4dc", ear: "#29262b", eye: "#f5c542", nose: "#f19ab0" },
172
+ ginger: { body: "#f39c4a", belly: "#fff1df", ear: "#d9762a", eye: "#3b2a1a", nose: "#f19ab0" },
173
+ };
174
+ function resolve(p) {
175
+ return { b: p.body, t: p.body, w: p.belly, e: p.ear, k: p.eye, n: p.nose ?? p.eye, c: p.ear };
176
+ }
177
+ function Sprite({ sprites, pose, blink, px, colors, }) {
178
+ // One path per color: no seams between pixels when the pup is rotated or scaled.
179
+ const paths = {};
180
+ sprites[pose].forEach((row, y) => {
181
+ [...row].forEach((ch, x) => {
182
+ if (ch === ".")
183
+ return;
184
+ const fill = colors[blink && ch === "k" ? "c" : ch];
185
+ paths[fill] = `${paths[fill] ?? ""}M${x} ${y}h1v1h-1z`;
186
+ });
187
+ });
188
+ return (_jsx("svg", { width: 16 * px, height: 11 * px, viewBox: "0 0 16 11", shapeRendering: "crispEdges", "aria-hidden": true, style: { display: "block" }, children: Object.entries(paths).map(([fill, d]) => (_jsx("path", { d: d, fill: fill }, fill))) }));
189
+ }
190
+ /** A static sprite, e.g. for previews or avatars. */
191
+ function PupSprite({ species = "dog", palette = species === "cat" ? "ginger" : "shiba", pose = "sit", size = 4, }) {
192
+ const colors = resolve(typeof palette === "string" ? PUP_PALETTES[palette] : palette);
193
+ return (_jsx(Sprite, { sprites: species === "cat" ? CAT : DOG, pose: pose, blink: false, px: size, colors: colors }));
194
+ }
195
+ const STORE = "pk-pup";
196
+ const NEAR = 160;
197
+ /**
198
+ * A quiet pixel dog. It rests in a corner, blinks, looks toward your cursor,
199
+ * stands up and wags when you come near, and dozes off when you leave.
200
+ * Click to pet. Drag to carry it anywhere — it remembers the spot.
201
+ */
202
+ function PixelPup({ size = 3, follow = false, species = "dog", palette = species === "cat" ? "ginger" : "shiba", bark, sleepAfter = 20_000, }) {
203
+ const sprites = species === "cat" ? CAT : DOG;
204
+ const colors = React.useMemo(() => resolve(typeof palette === "string" ? PUP_PALETTES[palette] : palette), [palette]);
205
+ const w = 16 * size;
206
+ const h = 11 * size;
207
+ const [pos, setPos] = React.useState(null);
208
+ const [mood, setMood] = React.useState("sit");
209
+ const [flip, setFlip] = React.useState(false);
210
+ const [blink, setBlink] = React.useState(false);
211
+ const [wag, setWag] = React.useState(false);
212
+ const [running, setRunning] = React.useState(false);
213
+ const [dragging, setDragging] = React.useState(false);
214
+ const [fx, setFx] = React.useState(null);
215
+ const [bubble, setBubble] = React.useState(null);
216
+ const posRef = React.useRef({ x: 0, y: 0 });
217
+ const moodRef = React.useRef("sit");
218
+ moodRef.current = mood;
219
+ const cursor = React.useRef(null);
220
+ const sleepTimer = React.useRef(undefined);
221
+ const drag = React.useRef(null);
222
+ const clamp = React.useCallback((p) => ({
223
+ x: Math.min(window.innerWidth - w - 8, Math.max(8, p.x)),
224
+ y: Math.min(window.innerHeight - h - 8, Math.max(8, p.y)),
225
+ }), [w, h]);
226
+ const place = React.useCallback((p) => {
227
+ posRef.current = p;
228
+ setPos(p);
229
+ }, []);
230
+ const scheduleSleep = React.useCallback(() => {
231
+ window.clearTimeout(sleepTimer.current);
232
+ sleepTimer.current = window.setTimeout(() => setMood("sleep"), sleepAfter);
233
+ }, [sleepAfter]);
234
+ // Mount: restore spot, listen to the cursor (rAF-throttled, no polling).
235
+ React.useEffect(() => {
236
+ let saved = null;
237
+ try {
238
+ saved = JSON.parse(localStorage.getItem(STORE) ?? "null");
239
+ }
240
+ catch { }
241
+ place(clamp(saved ?? { x: window.innerWidth - w - 28, y: window.innerHeight - h - 24 }));
242
+ scheduleSleep();
243
+ let raf = 0;
244
+ const onMove = (e) => {
245
+ if (e.pointerType !== "mouse")
246
+ return;
247
+ cursor.current = { x: e.clientX, y: e.clientY };
248
+ if (raf)
249
+ return;
250
+ raf = requestAnimationFrame(() => {
251
+ raf = 0;
252
+ const c = cursor.current;
253
+ if (!c || drag.current)
254
+ return;
255
+ const p = posRef.current;
256
+ const cx = p.x + w / 2;
257
+ const near = Math.hypot(c.x - cx, c.y - (p.y + h / 2)) < NEAR;
258
+ if (moodRef.current === "sleep") {
259
+ if (!near)
260
+ return; // far-away movement doesn't wake it
261
+ }
262
+ else
263
+ scheduleSleep();
264
+ if (near) {
265
+ setMood("alert");
266
+ scheduleSleep();
267
+ }
268
+ else if (moodRef.current === "alert")
269
+ setMood("sit");
270
+ if (Math.abs(c.x - cx) > 6)
271
+ setFlip(c.x < cx);
272
+ });
273
+ };
274
+ const onResize = () => place(clamp(posRef.current));
275
+ window.addEventListener("pointermove", onMove, { passive: true });
276
+ window.addEventListener("resize", onResize);
277
+ return () => {
278
+ window.removeEventListener("pointermove", onMove);
279
+ window.removeEventListener("resize", onResize);
280
+ window.clearTimeout(sleepTimer.current);
281
+ cancelAnimationFrame(raf);
282
+ };
283
+ }, [clamp, place, scheduleSleep, w, h]);
284
+ // Blink now and then while awake.
285
+ React.useEffect(() => {
286
+ if (mood === "sleep")
287
+ return;
288
+ let t;
289
+ const loop = () => {
290
+ t = window.setTimeout(() => {
291
+ setBlink(true);
292
+ t = window.setTimeout(() => {
293
+ setBlink(false);
294
+ loop();
295
+ }, 140);
296
+ }, 2500 + Math.random() * 3500);
297
+ };
298
+ loop();
299
+ return () => window.clearTimeout(t);
300
+ }, [mood]);
301
+ // Wag only when you're close.
302
+ React.useEffect(() => {
303
+ if (mood !== "alert" || dragging)
304
+ return setWag(false);
305
+ const id = window.setInterval(() => setWag((v) => !v), 170);
306
+ return () => window.clearInterval(id);
307
+ }, [mood, dragging]);
308
+ // Optional: chase the cursor.
309
+ React.useEffect(() => {
310
+ if (!follow || matchMedia("(prefers-reduced-motion: reduce)").matches)
311
+ return;
312
+ let frame = 0;
313
+ const id = window.setInterval(() => {
314
+ const c = cursor.current;
315
+ if (!c || drag.current)
316
+ return;
317
+ const p = posRef.current;
318
+ const dx = c.x - w / 2 - p.x;
319
+ const dy = c.y + 18 - p.y;
320
+ const d = Math.hypot(dx, dy);
321
+ if (d > 28) {
322
+ const k = Math.min(9, d) / d;
323
+ place({ x: p.x + dx * k, y: p.y + dy * k });
324
+ setFlip(dx < 0);
325
+ setRunning(++frame % 2 === 1);
326
+ setMood("alert");
327
+ scheduleSleep();
328
+ }
329
+ else
330
+ setRunning(false);
331
+ }, 90);
332
+ return () => {
333
+ window.clearInterval(id);
334
+ setRunning(false);
335
+ };
336
+ }, [follow, place, scheduleSleep, w]);
337
+ // Paddle legs while carried.
338
+ const [paddle, setPaddle] = React.useState(false);
339
+ React.useEffect(() => {
340
+ if (!dragging)
341
+ return;
342
+ const id = window.setInterval(() => setPaddle((v) => !v), 140);
343
+ return () => window.clearInterval(id);
344
+ }, [dragging]);
345
+ const pet = () => {
346
+ setMood("alert");
347
+ scheduleSleep();
348
+ setFx({ id: Date.now(), name: "hop" });
349
+ setBubble({ id: Date.now(), text: bark ?? (species === "cat" ? "喵~" : "汪!") });
350
+ };
351
+ if (!pos)
352
+ return null;
353
+ const pose = dragging
354
+ ? paddle
355
+ ? "run"
356
+ : "stand"
357
+ : running
358
+ ? "run"
359
+ : mood === "sleep"
360
+ ? "sleep"
361
+ : mood === "alert"
362
+ ? wag
363
+ ? "standWag"
364
+ : "stand"
365
+ : "sit";
366
+ return (_jsxs("button", { type: "button", "aria-label": species === "cat" ? "Pixel cat" : "Pixel pup", onPointerDown: (e) => {
367
+ if (e.button !== 0)
368
+ return;
369
+ e.currentTarget.setPointerCapture(e.pointerId);
370
+ drag.current = {
371
+ dx: e.clientX - pos.x,
372
+ dy: e.clientY - pos.y,
373
+ sx: e.clientX,
374
+ sy: e.clientY,
375
+ moved: false,
376
+ };
377
+ }, onPointerMove: (e) => {
378
+ const d = drag.current;
379
+ if (!d)
380
+ return;
381
+ if (!d.moved && Math.hypot(e.clientX - d.sx, e.clientY - d.sy) < 4)
382
+ return;
383
+ if (!d.moved) {
384
+ d.moved = true;
385
+ setDragging(true);
386
+ setMood("alert");
387
+ }
388
+ if (e.movementX)
389
+ setFlip(e.movementX < 0);
390
+ place(clamp({ x: e.clientX - d.dx, y: e.clientY - d.dy }));
391
+ }, onPointerUp: () => {
392
+ const d = drag.current;
393
+ drag.current = null;
394
+ if (!d)
395
+ return;
396
+ if (!d.moved)
397
+ return pet();
398
+ setDragging(false);
399
+ setFx({ id: Date.now(), name: "land" });
400
+ scheduleSleep();
401
+ try {
402
+ localStorage.setItem(STORE, JSON.stringify(posRef.current));
403
+ }
404
+ catch { }
405
+ }, onPointerCancel: () => {
406
+ drag.current = null;
407
+ setDragging(false);
408
+ }, onClick: (e) => {
409
+ if (e.detail === 0)
410
+ pet(); // keyboard
411
+ }, className: "fixed top-0 left-0 z-[90] touch-none select-none rounded-md outline-offset-4", style: {
412
+ translate: `${pos.x}px ${pos.y}px`,
413
+ cursor: dragging ? "grabbing" : "grab",
414
+ }, children: [_jsx("span", { className: "pointer-events-none absolute right-[14%] bottom-[-2px] left-[14%] h-1.5 rounded-[50%] bg-black/12 transition-[scale,opacity] duration-200 dark:bg-black/40", style: { scale: dragging ? "0.65" : "1", opacity: dragging ? 0.5 : 1 } }), _jsx("span", { className: "block transition-[translate,rotate,scale] duration-300 ease-spring", style: {
415
+ translate: dragging ? "0 -8px" : "0 0",
416
+ rotate: dragging ? (flip ? "8deg" : "-8deg") : "0deg",
417
+ scale: dragging ? "1.08" : "1",
418
+ }, children: _jsx("span", { className: "block origin-bottom", style: {
419
+ animation: fx
420
+ ? `${fx.name === "hop" ? "pk-hop 420ms" : "pk-land 360ms"} var(--pk-spring)`
421
+ : undefined,
422
+ }, children: _jsx("span", { className: "block", style: { transform: flip ? "scaleX(-1)" : undefined }, children: _jsx(Sprite, { sprites: sprites, pose: pose, blink: blink, px: size, colors: colors }) }) }, fx?.id) }), mood === "sleep" && !dragging && (_jsx("span", { className: "pointer-events-none absolute -top-3 right-0 animate-[pk-zz_2.4s_ease-in-out_infinite] font-mono font-semibold text-[11px] text-fg-3", children: "z" })), bubble && (_jsx("span", { className: "pointer-events-none absolute -top-6 left-1/2 -translate-x-1/2 animate-[pk-bark_900ms_var(--pk-ease)_forwards] whitespace-nowrap rounded-full bg-raised px-1.5 py-0.5 font-semibold text-[11px] text-fg opacity-0 shadow-float", children: bubble.text }, bubble.id))] }));
423
+ }
424
+ export { PixelPup, PupSprite };
@@ -0,0 +1,8 @@
1
+ import { Popover as PopoverPrimitive } from "radix-ui";
2
+ import type * as React from "react";
3
+ declare const Popover: React.FC<PopoverPrimitive.PopoverProps>;
4
+ declare const PopoverTrigger: React.ForwardRefExoticComponent<PopoverPrimitive.PopoverTriggerProps & React.RefAttributes<HTMLButtonElement>>;
5
+ declare const PopoverClose: React.ForwardRefExoticComponent<PopoverPrimitive.PopoverCloseProps & React.RefAttributes<HTMLButtonElement>>;
6
+ /** Grows out of its trigger. */
7
+ declare function PopoverContent({ className, sideOffset, align, ...props }: React.ComponentProps<typeof PopoverPrimitive.Content>): React.JSX.Element;
8
+ export { Popover, PopoverClose, PopoverContent, PopoverTrigger };
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { Popover as PopoverPrimitive } from "radix-ui";
4
+ import { cn } from "../lib/utils.js";
5
+ const Popover = PopoverPrimitive.Root;
6
+ const PopoverTrigger = PopoverPrimitive.Trigger;
7
+ const PopoverClose = PopoverPrimitive.Close;
8
+ /** Grows out of its trigger. */
9
+ function PopoverContent({ className, sideOffset = 8, align = "center", ...props }) {
10
+ return (_jsx(PopoverPrimitive.Portal, { children: _jsx(PopoverPrimitive.Content, { "data-slot": "popover", sideOffset: sideOffset, align: align, className: cn("z-50 w-64 rounded-xl bg-raised p-3 text-[14px] text-fg shadow-float outline-none", "origin-(--radix-popover-content-transform-origin)", "data-[state=open]:animate-[pk-pop-in_260ms_var(--pk-spring)] data-[state=closed]:animate-pk-out", className), ...props }) }));
11
+ }
12
+ export { Popover, PopoverClose, PopoverContent, PopoverTrigger };
@@ -0,0 +1,15 @@
1
+ import * as React from "react";
2
+ interface SegmentedControlProps<T extends string> {
3
+ value: T;
4
+ onValueChange: (value: T) => void;
5
+ options: readonly (T | {
6
+ value: T;
7
+ label: React.ReactNode;
8
+ })[];
9
+ size?: "sm" | "md";
10
+ className?: string;
11
+ "aria-label"?: string;
12
+ }
13
+ /** Day / Week / Month. One white pill glides to the selection. */
14
+ declare function SegmentedControl<T extends string>({ value, onValueChange, options, size, className, ...props }: SegmentedControlProps<T>): React.JSX.Element;
15
+ export { SegmentedControl };
@@ -0,0 +1,45 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { cn } from "../lib/utils.js";
5
+ /** Day / Week / Month. One white pill glides to the selection. */
6
+ function SegmentedControl({ value, onValueChange, options, size = "md", className, ...props }) {
7
+ const items = options.map((o) => (typeof o === "string" ? { value: o, label: o } : o));
8
+ const refs = React.useRef(new Map());
9
+ const [pill, setPill] = React.useState(null);
10
+ const [ready, setReady] = React.useState(false);
11
+ React.useLayoutEffect(() => {
12
+ const el = refs.current.get(value);
13
+ if (!el)
14
+ return;
15
+ const measure = () => setPill({ x: el.offsetLeft, w: el.offsetWidth });
16
+ measure();
17
+ const ro = new ResizeObserver(measure);
18
+ ro.observe(el);
19
+ return () => ro.disconnect();
20
+ }, [value]);
21
+ React.useEffect(() => {
22
+ const id = requestAnimationFrame(() => setReady(true));
23
+ return () => cancelAnimationFrame(id);
24
+ }, []);
25
+ const onKeyDown = (e) => {
26
+ const i = items.findIndex((o) => o.value === value);
27
+ const d = e.key === "ArrowRight" ? 1 : e.key === "ArrowLeft" ? -1 : 0;
28
+ if (!d)
29
+ return;
30
+ e.preventDefault();
31
+ const next = items[(i + d + items.length) % items.length].value;
32
+ onValueChange(next);
33
+ refs.current.get(next)?.focus();
34
+ };
35
+ return (_jsxs("div", { role: "radiogroup", "data-slot": "segmented-control", onKeyDown: onKeyDown, className: cn("relative inline-flex select-none items-center rounded-[10px] bg-fill p-[3px]", className), ...props, children: [pill && (_jsx("span", { "aria-hidden": true, className: cn("absolute top-[3px] bottom-[3px] left-0 rounded-[7px] bg-raised shadow-card", ready && "transition-[translate,width] duration-400 ease-spring"), style: { translate: `${pill.x}px 0`, width: pill.w } })), items.map((o) => {
36
+ const active = o.value === value;
37
+ return (_jsx("button", { ref: (el) => {
38
+ if (el)
39
+ refs.current.set(o.value, el);
40
+ else
41
+ refs.current.delete(o.value);
42
+ }, type: "button", role: "radio", "aria-checked": active, tabIndex: active ? 0 : -1, onClick: () => onValueChange(o.value), className: cn("relative z-10 rounded-[7px] font-medium transition-colors duration-200 ease-pk", size === "sm" ? "h-6 px-2.5 text-xs" : "h-7 px-3.5 text-[13px]", active ? "text-fg" : "text-fg-2 hover:text-fg"), children: o.label }, o.value));
43
+ })] }));
44
+ }
45
+ export { SegmentedControl };
@@ -0,0 +1,12 @@
1
+ import { Dialog as SheetPrimitive } from "radix-ui";
2
+ import type * as React from "react";
3
+ declare const Sheet: React.FC<SheetPrimitive.DialogProps>;
4
+ declare const SheetTrigger: React.ForwardRefExoticComponent<SheetPrimitive.DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>;
5
+ declare const SheetClose: React.ForwardRefExoticComponent<SheetPrimitive.DialogCloseProps & React.RefAttributes<HTMLButtonElement>>;
6
+ declare const SheetTitle: React.ForwardRefExoticComponent<SheetPrimitive.DialogTitleProps & React.RefAttributes<HTMLHeadingElement>>;
7
+ declare const SheetDescription: React.ForwardRefExoticComponent<SheetPrimitive.DialogDescriptionProps & React.RefAttributes<HTMLParagraphElement>>;
8
+ /** A panel that slides in from the right, or rises from the bottom like an iOS sheet. */
9
+ declare function SheetContent({ side, className, children, ...props }: React.ComponentProps<typeof SheetPrimitive.Content> & {
10
+ side?: "right" | "bottom";
11
+ }): React.JSX.Element;
12
+ export { Sheet, SheetClose, SheetContent, SheetDescription, SheetTitle, SheetTrigger };
@@ -0,0 +1,16 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Dialog as SheetPrimitive } from "radix-ui";
4
+ import { cn } from "../lib/utils.js";
5
+ const Sheet = SheetPrimitive.Root;
6
+ const SheetTrigger = SheetPrimitive.Trigger;
7
+ const SheetClose = SheetPrimitive.Close;
8
+ const SheetTitle = SheetPrimitive.Title;
9
+ const SheetDescription = SheetPrimitive.Description;
10
+ /** A panel that slides in from the right, or rises from the bottom like an iOS sheet. */
11
+ function SheetContent({ side = "right", className, children, ...props }) {
12
+ return (_jsxs(SheetPrimitive.Portal, { children: [_jsx(SheetPrimitive.Overlay, { className: "fixed inset-0 z-50 bg-black/20 data-[state=closed]:animate-[pk-fade-out_200ms_ease-in_forwards] data-[state=open]:animate-[pk-fade-in_240ms_var(--pk-ease)] dark:bg-black/50" }), _jsxs(SheetPrimitive.Content, { "data-slot": "sheet", "data-side": side, className: cn("fixed z-50 bg-surface shadow-float outline-none", side === "right" &&
13
+ "top-2 right-2 bottom-2 w-[min(380px,calc(100vw-16px))] rounded-2xl p-5 data-[state=closed]:animate-[pk-sheet-right-out_200ms_ease-in_forwards] data-[state=open]:animate-[pk-sheet-right-in_380ms_var(--pk-ease)]", side === "bottom" &&
14
+ "right-0 bottom-0 left-0 mx-auto max-h-[85dvh] w-full max-w-[560px] rounded-t-3xl px-5 pt-2.5 pb-[max(20px,env(safe-area-inset-bottom))] data-[state=closed]:animate-[pk-sheet-up-out_200ms_ease-in_forwards] data-[state=open]:animate-[pk-sheet-up-in_400ms_var(--pk-ease)]", className), ...props, children: [side === "bottom" && (_jsx("div", { "aria-hidden": true, className: "mx-auto mb-4 h-1 w-9 rounded-full bg-fg/15" })), children] })] }));
15
+ }
16
+ export { Sheet, SheetClose, SheetContent, SheetDescription, SheetTitle, SheetTrigger };
@@ -0,0 +1,5 @@
1
+ import { Slider as SliderPrimitive } from "radix-ui";
2
+ import type * as React from "react";
3
+ /** A thick, calm track with a white thumb that grows a little while dragged. */
4
+ declare function Slider({ className, defaultValue, value, min, max, ...props }: React.ComponentProps<typeof SliderPrimitive.Root>): React.JSX.Element;
5
+ export { Slider };
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Slider as SliderPrimitive } from "radix-ui";
4
+ import { cn } from "../lib/utils.js";
5
+ /** A thick, calm track with a white thumb that grows a little while dragged. */
6
+ function Slider({ className, defaultValue, value, min = 0, max = 100, ...props }) {
7
+ const values = value ?? defaultValue ?? [min];
8
+ return (_jsxs(SliderPrimitive.Root, { "data-slot": "slider", defaultValue: defaultValue, value: value, min: min, max: max, className: cn("relative flex h-5 w-full touch-none select-none items-center data-[disabled]:opacity-40", className), ...props, children: [_jsx(SliderPrimitive.Track, { className: "relative h-1.5 grow overflow-hidden rounded-full bg-fg/10", children: _jsx(SliderPrimitive.Range, { className: "absolute h-full rounded-full bg-accent" }) }), values.map((_, i) => (_jsx(SliderPrimitive.Thumb
9
+ // biome-ignore lint/suspicious/noArrayIndexKey: thumbs are positional
10
+ , { className: cn("block size-5 cursor-grab rounded-full bg-white shadow-thumb outline-none", "transition-[scale,box-shadow] duration-200 ease-spring active:scale-110 active:cursor-grabbing", "focus-visible:shadow-[var(--pk-shadow-thumb),0_0_0_4px_var(--pk-accent-soft)]") }, i)))] }));
11
+ }
12
+ export { Slider };
@@ -0,0 +1,14 @@
1
+ import * as React from "react";
2
+ interface StepperProps {
3
+ value: number;
4
+ onValueChange: (value: number) => void;
5
+ min?: number;
6
+ max?: number;
7
+ step?: number;
8
+ /** Shown before the number, e.g. "Gap". */
9
+ label?: React.ReactNode;
10
+ className?: string;
11
+ }
12
+ /** − 24 + — the number rolls in the direction you pressed. Hold to repeat. */
13
+ declare function Stepper({ value, onValueChange, min, max, step, label, className, }: StepperProps): React.JSX.Element;
14
+ export { Stepper };
@@ -0,0 +1,55 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Minus, Plus } from "lucide-react";
4
+ import * as React from "react";
5
+ import { cn } from "../lib/utils.js";
6
+ /** − 24 + — the number rolls in the direction you pressed. Hold to repeat. */
7
+ function Stepper({ value, onValueChange, min = -Infinity, max = Infinity, step = 1, label, className, }) {
8
+ const latest = React.useRef(value);
9
+ latest.current = value;
10
+ const [dir, setDir] = React.useState(0);
11
+ const timer = React.useRef(undefined);
12
+ const bump = React.useCallback((d) => {
13
+ const next = Math.min(max, Math.max(min, +(latest.current + d * step).toFixed(6)));
14
+ if (next === latest.current)
15
+ return false;
16
+ setDir(d);
17
+ latest.current = next;
18
+ onValueChange(next);
19
+ return true;
20
+ }, [max, min, step, onValueChange]);
21
+ const stop = React.useCallback(() => window.clearTimeout(timer.current), []);
22
+ const start = (d) => {
23
+ if (!bump(d))
24
+ return;
25
+ let delay = 380;
26
+ const tick = () => {
27
+ if (!bump(d))
28
+ return;
29
+ delay = Math.max(40, delay * 0.8);
30
+ timer.current = window.setTimeout(tick, delay);
31
+ };
32
+ timer.current = window.setTimeout(tick, delay);
33
+ };
34
+ React.useEffect(() => stop, [stop]);
35
+ const btn = "grid size-7 place-items-center rounded-md text-fg-2 transition-[background-color,transform] duration-150 " +
36
+ "hover:bg-fill-hover hover:text-fg active:scale-90 disabled:pointer-events-none disabled:opacity-30";
37
+ return (_jsxs("div", { "data-slot": "stepper", className: cn("inline-flex h-9 select-none items-center gap-1 rounded-lg bg-fill px-1", className), children: [label && _jsx("span", { className: "pr-1 pl-2 text-[13px] text-fg-2", children: label }), _jsx("button", { type: "button", "aria-label": "Decrease", className: btn, disabled: value <= min, onPointerDown: (e) => {
38
+ if (e.button === 0)
39
+ start(-1);
40
+ }, onPointerUp: stop, onPointerLeave: stop, onKeyDown: (e) => {
41
+ if (e.key === "Enter" || e.key === " ") {
42
+ e.preventDefault();
43
+ bump(-1);
44
+ }
45
+ }, children: _jsx(Minus, { className: "size-3.5" }) }), _jsx("span", { "aria-live": "polite", className: "relative h-5 min-w-7 overflow-hidden text-center font-medium text-sm tabular-nums", children: _jsx("span", { className: cn("block", dir !== 0 && "animate-[pk-roll_260ms_var(--pk-spring)]"), style: { "--pk-roll-from": dir === 1 ? "60%" : "-60%" }, children: value }, value) }), _jsx("button", { type: "button", "aria-label": "Increase", className: btn, disabled: value >= max, onPointerDown: (e) => {
46
+ if (e.button === 0)
47
+ start(1);
48
+ }, onPointerUp: stop, onPointerLeave: stop, onKeyDown: (e) => {
49
+ if (e.key === "Enter" || e.key === " ") {
50
+ e.preventDefault();
51
+ bump(1);
52
+ }
53
+ }, children: _jsx(Plus, { className: "size-3.5" }) })] }));
54
+ }
55
+ export { Stepper };
@@ -0,0 +1,5 @@
1
+ import { Switch as SwitchPrimitive } from "radix-ui";
2
+ import type * as React from "react";
3
+ /** iOS-style switch. The thumb stretches while pressed, then springs into place. */
4
+ declare function Switch({ className, ...props }: React.ComponentProps<typeof SwitchPrimitive.Root>): React.JSX.Element;
5
+ export { Switch };
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { Switch as SwitchPrimitive } from "radix-ui";
4
+ import { cn } from "../lib/utils.js";
5
+ /** iOS-style switch. The thumb stretches while pressed, then springs into place. */
6
+ function Switch({ className, ...props }) {
7
+ return (_jsx(SwitchPrimitive.Root, { "data-slot": "switch", className: cn("group relative inline-flex h-[26px] w-[44px] shrink-0 cursor-pointer items-center rounded-full p-[2px]", "bg-fg/12 transition-colors duration-200 ease-pk data-[state=checked]:bg-success", "disabled:cursor-not-allowed disabled:opacity-40", className), ...props, children: _jsx(SwitchPrimitive.Thumb, { className: cn("pointer-events-none block h-[22px] w-[22px] rounded-full bg-white shadow-thumb", "transition-[width,translate] duration-300 ease-spring", "group-active:w-[27px] data-[state=checked]:translate-x-[18px] group-active:data-[state=checked]:translate-x-[13px]") }) }));
8
+ }
9
+ export { Switch };
@@ -0,0 +1,10 @@
1
+ import { Tabs as TabsPrimitive } from "radix-ui";
2
+ import * as React from "react";
3
+ declare const Tabs: React.ForwardRefExoticComponent<TabsPrimitive.TabsProps & React.RefAttributes<HTMLDivElement>>;
4
+ declare const TabsContent: (props: React.ComponentProps<typeof TabsPrimitive.Content>) => React.JSX.Element;
5
+ /** The indicator glides to the active tab. `pill` like a segmented control, `line` like an underline. */
6
+ declare function TabsList({ variant, className, children, ...props }: React.ComponentProps<typeof TabsPrimitive.List> & {
7
+ variant?: "line" | "pill";
8
+ }): React.JSX.Element;
9
+ declare function TabsTrigger({ className, ...props }: React.ComponentProps<typeof TabsPrimitive.Trigger>): React.JSX.Element;
10
+ export { Tabs, TabsContent, TabsList, TabsTrigger };