magic-pill 9.2.0 → 9.4.0-next.1

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