magic-pill 9.3.0 → 9.4.0-next.2

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 (54) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +114 -3
  3. package/dist/MagicPill/MagicPill.d.mts +51 -1
  4. package/dist/MagicPill/MagicPill.d.ts +51 -1
  5. package/dist/MagicPill/MagicPill.js +53 -4
  6. package/dist/MagicPill/MagicPill.mjs +55 -6
  7. package/dist/MagicPill/flag.js +1 -59
  8. package/dist/MagicPill/flag.mjs +1 -58
  9. package/dist/Pill/PillProgress.d.mts +12 -0
  10. package/dist/Pill/PillProgress.d.ts +12 -0
  11. package/dist/Pill/PillProgress.js +42 -0
  12. package/dist/Pill/PillProgress.mjs +42 -0
  13. package/dist/Pill/goo.js +576 -0
  14. package/dist/Pill/goo.mjs +566 -0
  15. package/dist/Pill/morph.js +11 -4
  16. package/dist/Pill/morph.mjs +10 -5
  17. package/dist/PillNavbar/PillNavbar.d.mts +8 -0
  18. package/dist/PillNavbar/PillNavbar.d.ts +8 -0
  19. package/dist/PillNavbar/PillNavbar.js +3 -2
  20. package/dist/PillNavbar/PillNavbar.mjs +3 -2
  21. package/dist/PillNavbar/room.d.mts +3 -0
  22. package/dist/PillNavbar/room.d.ts +2 -0
  23. package/dist/PillNavbar/room.js +89 -17
  24. package/dist/PillNavbar/room.mjs +89 -18
  25. package/dist/index.d.mts +3 -2
  26. package/dist/index.d.ts +3 -2
  27. package/dist/index.js +2 -0
  28. package/dist/index.mjs +2 -1
  29. package/dist/satellites/Actions.d.mts +12 -0
  30. package/dist/satellites/Actions.d.ts +11 -0
  31. package/dist/satellites/Actions.js +181 -0
  32. package/dist/satellites/Actions.mjs +177 -0
  33. package/dist/satellites/Orbitals.js +585 -0
  34. package/dist/satellites/Orbitals.mjs +585 -0
  35. package/dist/satellites/Satellites.js +634 -0
  36. package/dist/satellites/Satellites.mjs +634 -0
  37. package/dist/satellites/layout.js +209 -0
  38. package/dist/satellites/layout.mjs +209 -0
  39. package/dist/satellites/measure.js +25 -0
  40. package/dist/satellites/measure.mjs +24 -0
  41. package/dist/satellites/orbits.js +139 -0
  42. package/dist/satellites/orbits.mjs +136 -0
  43. package/dist/satellites/types.d.mts +58 -0
  44. package/dist/satellites/types.d.ts +58 -0
  45. package/dist/satellites.d.mts +5 -0
  46. package/dist/satellites.d.ts +5 -0
  47. package/dist/satellites.js +14 -0
  48. package/dist/satellites.mjs +12 -0
  49. package/dist/store/store.d.mts +103 -0
  50. package/dist/store/store.d.ts +103 -0
  51. package/dist/store/store.js +52 -1
  52. package/dist/store/store.mjs +52 -2
  53. package/dist/styles.css +322 -8
  54. package/package.json +11 -1
@@ -0,0 +1,585 @@
1
+ "use client";
2
+
3
+ import { useEffect, useRef, useState } from "react";
4
+ import Pill from "../Pill/Pill.mjs";
5
+ import { SPLIT, playOrbit } from "../Pill/goo.mjs";
6
+ import { useIsomorphicLayoutEffect } from "../utils/react.mjs";
7
+ import { parseDuration } from "../utils/timing.mjs";
8
+ import { durations, toPixels } from "./measure.mjs";
9
+ import { orbitalAt, planOrbit, spotOn, wheelEnd } from "./orbits.mjs";
10
+ import { jsx, jsxs } from "react/jsx-runtime";
11
+
12
+ // src/satellites/Orbitals.tsx
13
+ const MENU_STYLE = {
14
+ position: "fixed",
15
+ inset: 0,
16
+ pointerEvents: "none",
17
+ zIndex: "var(--mp-z-index, 50)"
18
+ };
19
+ const ORBITAL_STYLE = {
20
+ position: "fixed",
21
+ left: 0,
22
+ top: 0,
23
+ margin: 0,
24
+ pointerEvents: "auto"
25
+ };
26
+ const LABEL_STYLE = {
27
+ position: "fixed",
28
+ left: 0,
29
+ top: 0
30
+ };
31
+ /** Another electron opened its orbitals: these close */
32
+ const OPENED = "mp-orbitals-open";
33
+ /** The direction away from the screen's edge, by the host's placement */
34
+ const AWAY = {
35
+ bottom: -90,
36
+ top: 90,
37
+ left: 0,
38
+ right: 180
39
+ };
40
+ const BACK_ICON = /* @__PURE__ */ jsx("svg", {
41
+ viewBox: "0 0 24 24",
42
+ fill: "none",
43
+ stroke: "currentColor",
44
+ strokeWidth: "2.4",
45
+ strokeLinecap: "round",
46
+ strokeLinejoin: "round",
47
+ "aria-hidden": "true",
48
+ children: /* @__PURE__ */ jsx("path", { d: "M10 6.5 4.5 12l5.5 5.5M5 12h14.5" })
49
+ });
50
+ /** The orbitals' tokens, read on the electron. */
51
+ function readSettings(element) {
52
+ const style = getComputedStyle(element);
53
+ const action = toPixels(style.getPropertyValue("--_mp-action-size"), element, 44);
54
+ const spread = Number.parseFloat(style.getPropertyValue("--mp-orbital-spread"));
55
+ return {
56
+ size: toPixels(style.getPropertyValue("--mp-orbital-size"), element, action),
57
+ distance: toPixels(style.getPropertyValue("--mp-orbital-distance"), element, 14),
58
+ spread: Number.isFinite(spread) ? spread : 0,
59
+ stagger: parseDuration(style.getPropertyValue("--mp-orbital-stagger"), 30),
60
+ hoverDelay: parseDuration(style.getPropertyValue("--mp-hover-delay"), 300),
61
+ longPress: parseDuration(style.getPropertyValue("--mp-long-press"), 450)
62
+ };
63
+ }
64
+ function Orbitals({ electron, getElement, host, out }) {
65
+ const tap = host.orbitalsOpenOn === "tap";
66
+ const own = electron.input.orbitals ?? [];
67
+ const items = own.length === 0 ? [] : [...tap ? [{
68
+ id: "back",
69
+ icon: BACK_ICON,
70
+ label: electron.input.backLabel ?? "Back",
71
+ href: electron.input.onClick ? void 0 : electron.origin,
72
+ onClick: electron.input.onClick
73
+ }] : [], ...own];
74
+ const [ring, setRing] = useState(null);
75
+ const [shown, setShown] = useState([]);
76
+ const [hot, setHot] = useState(-1);
77
+ const orbit = useRef(null);
78
+ const settings = useRef(null);
79
+ const pills = useRef(/* @__PURE__ */ new Map());
80
+ const timers = useRef([]);
81
+ const labelRef = useRef(null);
82
+ const focusFirst = useRef(false);
83
+ const turn = useRef(0);
84
+ const snapping = useRef(0);
85
+ const clearTimers = () => {
86
+ timers.current.forEach(clearTimeout);
87
+ timers.current = [];
88
+ };
89
+ const plan = () => {
90
+ const element = getElement();
91
+ const root = host.rootRef.current;
92
+ if (!element || !root) return null;
93
+ const read = readSettings(element);
94
+ settings.current = read;
95
+ const obstacles = [root, ...document.querySelectorAll("[data-mp=\"pill\"]:is([data-satellite=\"electron\"], [data-satellite=\"actions\"])")].filter((other) => other !== element && other.dataset.presence !== "hidden").map((other) => other.getBoundingClientRect());
96
+ orbit.current = planOrbit({
97
+ electron: element.getBoundingClientRect(),
98
+ count: items.length,
99
+ size: read.size,
100
+ distance: read.distance,
101
+ spread: read.spread,
102
+ away: AWAY[host.placement.split("-")[0]] ?? -90,
103
+ obstacles,
104
+ viewport: {
105
+ width: document.documentElement.clientWidth || window.innerWidth,
106
+ height: window.innerHeight
107
+ },
108
+ rtl: getComputedStyle(root).direction === "rtl"
109
+ });
110
+ return read;
111
+ };
112
+ const applyTurn = () => {
113
+ const current = orbit.current;
114
+ if (!current) return;
115
+ items.forEach((_, index) => {
116
+ const pill = pills.current.get(index);
117
+ if (!pill) return;
118
+ const spot = spotOn(current, index, turn.current);
119
+ pill.style.left = `${spot.x - pill.offsetWidth / 2}px`;
120
+ pill.style.top = `${spot.y - pill.offsetHeight / 2}px`;
121
+ if (current.wheel) {
122
+ pill.style.opacity = String(spot.shown);
123
+ pill.style.scale = String((.6 + .4 * spot.shown) * (api.current.hot === index ? 1.12 : 1));
124
+ pill.style.pointerEvents = spot.shown < .5 || closing.current ? "none" : "auto";
125
+ } else {
126
+ pill.style.removeProperty("opacity");
127
+ pill.style.removeProperty("scale");
128
+ pill.style.pointerEvents = closing.current ? "none" : "auto";
129
+ }
130
+ });
131
+ placeLabel();
132
+ };
133
+ const placeLabel = () => {
134
+ const label = labelRef.current;
135
+ const index = api.current.hot;
136
+ if (!label || index < 0 || !orbit.current || !settings.current) return;
137
+ const spot = spotOn(orbit.current, index, turn.current);
138
+ const distance = settings.current.size / 2 + 22;
139
+ const angle = spot.angle * Math.PI / 180;
140
+ const width = label.offsetWidth;
141
+ const height = label.offsetHeight;
142
+ const x = Math.min(Math.max(spot.x + Math.cos(angle) * distance, width / 2 + 6), window.innerWidth - width / 2 - 6);
143
+ const y = Math.min(Math.max(spot.y + Math.sin(angle) * distance, height / 2 + 6), window.innerHeight - height / 2 - 6);
144
+ label.style.translate = `${x - width / 2}px ${y - height / 2}px`;
145
+ };
146
+ const turnTo = (to, ease = false) => {
147
+ const current = orbit.current;
148
+ if (!current?.wheel) return;
149
+ const target = Math.min(Math.max(to, ease ? 0 : -.35), wheelEnd(current) + (ease ? 0 : .35));
150
+ cancelAnimationFrame(snapping.current);
151
+ if (!ease) {
152
+ turn.current = target;
153
+ applyTurn();
154
+ return;
155
+ }
156
+ const from = turn.current;
157
+ const startedAt = performance.now();
158
+ const step = (now) => {
159
+ const t = Math.min(1, (now - startedAt) / 180);
160
+ turn.current = from + (target - from) * (1 - (1 - t) ** 3);
161
+ applyTurn();
162
+ if (t < 1) snapping.current = requestAnimationFrame(step);
163
+ };
164
+ snapping.current = requestAnimationFrame(step);
165
+ };
166
+ const snap = () => turnTo(Math.round(turn.current), true);
167
+ const motion = useRef(() => {});
168
+ const opening = useRef(false);
169
+ const closing = useRef(false);
170
+ /** The orbitals that show, each with its delay: one after the other along the arc (or the other way round). */
171
+ const sequence = (reverse, stagger) => {
172
+ const current = orbit.current;
173
+ const shownOnes = items.map((_, index) => ({
174
+ index,
175
+ shown: current ? spotOn(current, index, turn.current).shown : 1
176
+ })).filter(({ shown }) => shown > 0);
177
+ return shownOnes.map(({ index, shown }, rank) => ({
178
+ element: pills.current.get(index),
179
+ shown,
180
+ delay: (reverse ? shownOnes.length - 1 - rank : rank) * stagger
181
+ })).filter(({ element }) => element);
182
+ };
183
+ const open = (how) => {
184
+ if (items.length === 0 || !out) return;
185
+ window.dispatchEvent(new CustomEvent(OPENED, { detail: electron.id }));
186
+ clearTimers();
187
+ motion.current();
188
+ if (!plan()) return;
189
+ focusFirst.current = how === "key";
190
+ turn.current = 0;
191
+ opening.current = true;
192
+ closing.current = false;
193
+ setHot(-1);
194
+ setRing({ how });
195
+ setShown(items.map(() => true));
196
+ };
197
+ const close = (quick = false) => {
198
+ if (!ring) return;
199
+ clearTimers();
200
+ setHot(-1);
201
+ closing.current = true;
202
+ for (const pill of pills.current.values()) pill.style.pointerEvents = "none";
203
+ const element = getElement();
204
+ const first = pills.current.get(0);
205
+ const { fade, exit } = first ? durations(first) : {
206
+ fade: 150,
207
+ exit: 300
208
+ };
209
+ const duration = quick ? fade + 100 : exit * .8;
210
+ const stagger = quick ? 0 : (settings.current?.stagger ?? 30) * .6;
211
+ const steps = sequence(true, stagger);
212
+ motion.current();
213
+ if (element) motion.current = playOrbit(element, steps, "close", { duration });
214
+ const longest = Math.max(0, ...steps.map(({ delay }) => delay)) + duration;
215
+ timers.current.push(setTimeout(() => {
216
+ setRing(null);
217
+ setShown([]);
218
+ closing.current = false;
219
+ }, longest + 30));
220
+ };
221
+ const api = useRef({
222
+ open,
223
+ close,
224
+ ring,
225
+ items,
226
+ hot,
227
+ setHot,
228
+ turnTo,
229
+ snap
230
+ });
231
+ api.current = {
232
+ open,
233
+ close,
234
+ ring,
235
+ items,
236
+ hot,
237
+ setHot,
238
+ turnTo,
239
+ snap
240
+ };
241
+ const hasItems = items.length > 0;
242
+ useEffect(() => {
243
+ const link = getElement()?.querySelector("[data-mp=\"electron\"]");
244
+ if (!link || !hasItems) return;
245
+ link.setAttribute("aria-haspopup", "menu");
246
+ let press = null;
247
+ let hoverTimer;
248
+ let swallowClick = false;
249
+ const hotAt = (event) => {
250
+ const element = getElement();
251
+ if (!orbit.current || !settings.current || !element) return;
252
+ api.current.setHot(orbitalAt(orbit.current, settings.current.size, element.offsetWidth / 2, event.clientX, event.clientY, turn.current));
253
+ };
254
+ const onPointerDown = (event) => {
255
+ if (event.button !== 0) return;
256
+ clearTimeout(hoverTimer);
257
+ if (api.current.ring) {
258
+ press = {
259
+ x: event.clientX,
260
+ y: event.clientY,
261
+ opened: true,
262
+ moved: false,
263
+ already: true,
264
+ timer: setTimeout(() => {}, 0)
265
+ };
266
+ try {
267
+ link.setPointerCapture(event.pointerId);
268
+ } catch {}
269
+ return;
270
+ }
271
+ const longPress = settings.current?.longPress ?? readSettings(getElement()).longPress;
272
+ press = {
273
+ x: event.clientX,
274
+ y: event.clientY,
275
+ opened: false,
276
+ moved: false,
277
+ timer: setTimeout(() => {
278
+ if (!press || press.moved) return;
279
+ press.opened = true;
280
+ if (!api.current.ring) api.current.open("press");
281
+ try {
282
+ link.setPointerCapture(event.pointerId);
283
+ } catch {}
284
+ }, longPress)
285
+ };
286
+ };
287
+ const onPointerMove = (event) => {
288
+ if (!press) return;
289
+ if (Math.hypot(event.clientX - press.x, event.clientY - press.y) > 12) {
290
+ if (!press.opened) clearTimeout(press.timer);
291
+ press.moved = true;
292
+ }
293
+ if (press.opened) hotAt(event);
294
+ };
295
+ const onPointerUp = () => {
296
+ if (!press) return;
297
+ clearTimeout(press.timer);
298
+ const { opened, already, moved } = press;
299
+ press = null;
300
+ if (!opened) return;
301
+ if (already && !moved && api.current.hot < 0) return;
302
+ swallowClick = true;
303
+ const { hot: index } = api.current;
304
+ if (index >= 0) pills.current.get(index)?.querySelector("[data-mp=\"orbital\"]")?.click();
305
+ api.current.setHot(-1);
306
+ };
307
+ const onPointerCancel = () => {
308
+ if (press) clearTimeout(press.timer);
309
+ press = null;
310
+ };
311
+ const onClick = (event) => {
312
+ if (swallowClick) {
313
+ swallowClick = false;
314
+ event.preventDefault();
315
+ event.stopPropagation();
316
+ return;
317
+ }
318
+ if (tap) {
319
+ event.preventDefault();
320
+ event.stopPropagation();
321
+ if (api.current.ring) api.current.close();
322
+ else api.current.open(event.detail === 0 ? "key" : "tap");
323
+ } else if (api.current.ring) api.current.close(true);
324
+ };
325
+ const onPointerEnter = (event) => {
326
+ if (event.pointerType !== "mouse" || host.orbitalsOpenOn !== "press-hover" || press) return;
327
+ const { hoverDelay } = settings.current ?? readSettings(getElement());
328
+ hoverTimer = setTimeout(() => {
329
+ if (!press && !api.current.ring) api.current.open("hover");
330
+ }, hoverDelay);
331
+ };
332
+ const onPointerLeave = () => clearTimeout(hoverTimer);
333
+ const onKeyDown = (event) => {
334
+ const away = {
335
+ bottom: "ArrowUp",
336
+ top: "ArrowDown",
337
+ left: "ArrowRight",
338
+ right: "ArrowLeft"
339
+ }[host.placement.split("-")[0]];
340
+ if (event.key === away || event.key === "ContextMenu" || event.key === "F10" && event.shiftKey) {
341
+ event.preventDefault();
342
+ api.current.open("key");
343
+ } else if (event.key === "Escape" && api.current.ring) {
344
+ event.preventDefault();
345
+ api.current.close();
346
+ }
347
+ };
348
+ const onContextMenu = (event) => event.preventDefault();
349
+ link.addEventListener("pointerdown", onPointerDown);
350
+ link.addEventListener("pointermove", onPointerMove);
351
+ link.addEventListener("pointerup", onPointerUp);
352
+ link.addEventListener("pointercancel", onPointerCancel);
353
+ link.addEventListener("click", onClick);
354
+ link.addEventListener("pointerenter", onPointerEnter);
355
+ link.addEventListener("pointerleave", onPointerLeave);
356
+ link.addEventListener("keydown", onKeyDown);
357
+ link.addEventListener("contextmenu", onContextMenu);
358
+ return () => {
359
+ clearTimeout(hoverTimer);
360
+ if (press) clearTimeout(press.timer);
361
+ link.removeAttribute("aria-haspopup");
362
+ link.removeEventListener("pointerdown", onPointerDown);
363
+ link.removeEventListener("pointermove", onPointerMove);
364
+ link.removeEventListener("pointerup", onPointerUp);
365
+ link.removeEventListener("pointercancel", onPointerCancel);
366
+ link.removeEventListener("click", onClick);
367
+ link.removeEventListener("pointerenter", onPointerEnter);
368
+ link.removeEventListener("pointerleave", onPointerLeave);
369
+ link.removeEventListener("keydown", onKeyDown);
370
+ link.removeEventListener("contextmenu", onContextMenu);
371
+ };
372
+ }, [
373
+ hasItems,
374
+ tap,
375
+ host.orbitalsOpenOn,
376
+ host.placement,
377
+ electron.id
378
+ ]);
379
+ useEffect(() => {
380
+ const link = getElement()?.querySelector("[data-mp=\"electron\"]");
381
+ if (!ring) {
382
+ link?.setAttribute("aria-expanded", "false");
383
+ return;
384
+ }
385
+ link?.setAttribute("aria-expanded", "true");
386
+ const inside = (target) => target instanceof Node && ([...pills.current.values()].some((pill) => pill.contains(target)) || !!link?.contains(target));
387
+ const onPointerDown = (event) => {
388
+ if (!inside(event.target)) api.current.close();
389
+ };
390
+ let leaving;
391
+ const onPointerMove = (event) => {
392
+ if (ring.how !== "hover" || !orbit.current || !settings.current || orbit.current.wheel) return;
393
+ const far = Math.hypot(event.clientX - orbit.current.x, event.clientY - orbit.current.y) > orbit.current.radius + settings.current.size / 2 + 26;
394
+ if (far && leaving === void 0) leaving = setTimeout(() => api.current.close(), 220);
395
+ if (!far) {
396
+ clearTimeout(leaving);
397
+ leaving = void 0;
398
+ }
399
+ };
400
+ const onOtherOpened = (event) => {
401
+ if (event.detail !== electron.id) api.current.close(true);
402
+ };
403
+ const near = (x, y) => !!orbit.current && !!settings.current && Math.hypot(x - orbit.current.x, y - orbit.current.y) <= orbit.current.radius + settings.current.size;
404
+ let settle;
405
+ const onWheel = (event) => {
406
+ if (!orbit.current?.wheel || !(inside(event.target) || near(event.clientX, event.clientY))) return;
407
+ event.preventDefault();
408
+ api.current.turnTo(turn.current + (event.deltaY + event.deltaX) / 90);
409
+ clearTimeout(settle);
410
+ settle = setTimeout(() => api.current.snap(), 160);
411
+ };
412
+ const angleOf = (event) => orbit.current ? Math.atan2(event.clientY - orbit.current.y, event.clientX - orbit.current.x) * 180 / Math.PI : 0;
413
+ let drag = null;
414
+ const onDragStart = (event) => {
415
+ if (!orbit.current?.wheel || event.button !== 0 || !(event.target instanceof Node)) return;
416
+ if (![...pills.current.values()].some((pill) => pill.contains(event.target))) return;
417
+ drag = {
418
+ angle: angleOf(event),
419
+ turn: turn.current,
420
+ x: event.clientX,
421
+ y: event.clientY,
422
+ moved: false
423
+ };
424
+ };
425
+ const onDragMove = (event) => {
426
+ if (!drag || !orbit.current) return;
427
+ if (!drag.moved && Math.hypot(event.clientX - drag.x, event.clientY - drag.y) <= 6) return;
428
+ drag.moved = true;
429
+ const turned = (angleOf(event) - drag.angle + 540) % 360 - 180;
430
+ api.current.turnTo(drag.turn + (orbit.current.rtl ? turned : -turned) / orbit.current.step);
431
+ };
432
+ const onDragEnd = () => {
433
+ if (!drag) return;
434
+ const { moved } = drag;
435
+ drag = null;
436
+ if (!moved) return;
437
+ api.current.snap();
438
+ const swallow = (event) => {
439
+ event.preventDefault();
440
+ event.stopPropagation();
441
+ };
442
+ document.addEventListener("click", swallow, {
443
+ capture: true,
444
+ once: true
445
+ });
446
+ setTimeout(() => document.removeEventListener("click", swallow, { capture: true }), 0);
447
+ };
448
+ document.addEventListener("pointerdown", onPointerDown, true);
449
+ document.addEventListener("pointermove", onPointerMove);
450
+ document.addEventListener("wheel", onWheel, { passive: false });
451
+ document.addEventListener("pointerdown", onDragStart);
452
+ document.addEventListener("pointermove", onDragMove);
453
+ document.addEventListener("pointerup", onDragEnd);
454
+ window.addEventListener(OPENED, onOtherOpened);
455
+ return () => {
456
+ clearTimeout(leaving);
457
+ clearTimeout(settle);
458
+ document.removeEventListener("pointerdown", onPointerDown, true);
459
+ document.removeEventListener("pointermove", onPointerMove);
460
+ document.removeEventListener("wheel", onWheel);
461
+ document.removeEventListener("pointerdown", onDragStart);
462
+ document.removeEventListener("pointermove", onDragMove);
463
+ document.removeEventListener("pointerup", onDragEnd);
464
+ window.removeEventListener(OPENED, onOtherOpened);
465
+ };
466
+ }, [ring, electron.id]);
467
+ useEffect(() => {
468
+ if (ring && !out) api.current.close(true);
469
+ }, [out]);
470
+ useEffect(() => {
471
+ if (ring) api.current.close(true);
472
+ }, [host.pathname]);
473
+ useEffect(() => () => {
474
+ clearTimers();
475
+ cancelAnimationFrame(snapping.current);
476
+ }, []);
477
+ useIsomorphicLayoutEffect(() => {
478
+ const element = getElement();
479
+ if (!ring || !element || !orbit.current) return;
480
+ applyTurn();
481
+ if (opening.current && pills.current.size >= items.length) {
482
+ opening.current = false;
483
+ const first = pills.current.get(0);
484
+ const duration = (first ? durations(first).enter : 500) * .8;
485
+ motion.current = playOrbit(element, sequence(false, settings.current?.stagger ?? 30), "open", { duration });
486
+ }
487
+ if (focusFirst.current && shown[0]) {
488
+ focusFirst.current = false;
489
+ pills.current.get(0)?.querySelector("[data-mp=\"orbital\"]")?.focus();
490
+ }
491
+ });
492
+ useEffect(() => {
493
+ if (!ring) turn.current = 0;
494
+ }, [ring]);
495
+ if (!ring || items.length === 0) return null;
496
+ const run = (item) => (event) => {
497
+ item.onClick?.(event);
498
+ if (!host.orbitalsStayOpen) close();
499
+ };
500
+ const onKeyDown = (index) => (event) => {
501
+ const count = items.length;
502
+ const focus = (next) => {
503
+ event.preventDefault();
504
+ const current = orbit.current;
505
+ if (current?.wheel) {
506
+ const wanted = Math.min(Math.max(turn.current, next - current.visible + 1), next);
507
+ if (wanted !== turn.current) turnTo(wanted, true);
508
+ }
509
+ setHot(next);
510
+ pills.current.get(next)?.querySelector("[data-mp=\"orbital\"]")?.focus();
511
+ };
512
+ if (["ArrowRight", "ArrowDown"].includes(event.key)) focus((index + 1) % count);
513
+ else if (["ArrowLeft", "ArrowUp"].includes(event.key)) focus((index - 1 + count) % count);
514
+ else if (event.key === "Home") focus(0);
515
+ else if (event.key === "End") focus(count - 1);
516
+ else if (event.key === "Escape") {
517
+ event.preventDefault();
518
+ close();
519
+ getElement()?.querySelector("[data-mp=\"electron\"]")?.focus();
520
+ } else if (event.key === "Tab") close();
521
+ };
522
+ const Link = host.linkComponent ?? "a";
523
+ return /* @__PURE__ */ jsxs("div", {
524
+ role: "menu",
525
+ "aria-label": electron.input.label,
526
+ "data-mp": "orbitals",
527
+ "data-orbitals": electron.id,
528
+ style: MENU_STYLE,
529
+ children: [items.map((item, index) => {
530
+ const common = {
531
+ role: "menuitem",
532
+ tabIndex: -1,
533
+ "data-mp": "orbital",
534
+ "aria-label": item.label,
535
+ onClick: run(item),
536
+ onKeyDown: onKeyDown(index),
537
+ onFocus: () => setHot(index)
538
+ };
539
+ return /* @__PURE__ */ jsx(Pill, {
540
+ ref: (element) => {
541
+ if (element) pills.current.set(index, element);
542
+ else pills.current.delete(index);
543
+ },
544
+ placement: "inline",
545
+ ladder: false,
546
+ moveThroughCircle: false,
547
+ theme: host.theme,
548
+ variant: electron.input.variant ?? host.variant,
549
+ presence: shown[index] ? "compact" : "hidden",
550
+ "data-satellite": "orbital",
551
+ "data-index": index,
552
+ "data-hot": hot === index ? "" : void 0,
553
+ style: ORBITAL_STYLE,
554
+ onPointerEnter: (event) => {
555
+ const moving = event.currentTarget.getAnimations?.().some((animation) => animation.id === "mp-split" && animation.playState === "running");
556
+ if (!closing.current && !moving) setHot(index);
557
+ },
558
+ onPointerLeave: () => setHot(-1),
559
+ children: item.href !== void 0 ? /* @__PURE__ */ jsx(Link, {
560
+ href: item.href,
561
+ ...common,
562
+ children: item.icon
563
+ }) : /* @__PURE__ */ jsx("button", {
564
+ type: "button",
565
+ ...common,
566
+ children: item.icon
567
+ })
568
+ }, item.id ?? index);
569
+ }), host.orbitalLabels && hot >= 0 && items[hot] && /* @__PURE__ */ jsx(Pill, {
570
+ ref: labelRef,
571
+ placement: "inline",
572
+ ladder: false,
573
+ moveThroughCircle: false,
574
+ theme: host.theme,
575
+ variant: electron.input.variant ?? host.variant,
576
+ presence: "compact",
577
+ "aria-hidden": "true",
578
+ "data-satellite": "orbital-label",
579
+ style: LABEL_STYLE,
580
+ children: items[hot].label
581
+ })]
582
+ });
583
+ }
584
+
585
+ export { Orbitals };