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,634 @@
1
+ "use client";
2
+
3
+ let react = require("react");
4
+ const require_Pill = require("../Pill/Pill.js");
5
+ const require_goo = require("../Pill/goo.js");
6
+ const require_morph = require("../Pill/morph.js");
7
+ const require_PillProgress = require("../Pill/PillProgress.js");
8
+ const require_matchPath = require("../PillNavbar/matchPath.js");
9
+ const require_room = require("../PillNavbar/room.js");
10
+ const require_store = require("../store/store.js");
11
+ const require_react = require("../utils/react.js");
12
+ const require_timing = require("../utils/timing.js");
13
+ const require_visuallyHidden = require("../utils/visuallyHidden.js");
14
+ const require_layout = require("./layout.js");
15
+ const require_measure = require("./measure.js");
16
+ const require_Orbitals = require("./Orbitals.js");
17
+ const require_Actions = require("./Actions.js");
18
+ let react_jsx_runtime = require("react/jsx-runtime");
19
+
20
+ // src/satellites/Satellites.tsx
21
+ const ELECTRON_STYLE = {
22
+ position: "fixed",
23
+ zIndex: "var(--mp-z-index, 50)",
24
+ margin: 0
25
+ };
26
+ const SHIFT = "mp-satellite-shift";
27
+ /** The page's actions' entry among the satellites' presences */
28
+ const ACTIONS = "\0actions";
29
+ const SIDE_PLACEMENTS = /* @__PURE__ */ new Set(["left", "right"]);
30
+ /**
31
+ * The page's actions' box along the pill, whichever way their pill runs now
32
+ * and even while its size animates: laid out on a hidden copy, turned along,
33
+ * with all of them (not cut short by a wheel).
34
+ */
35
+ function alongBox(atom, vertical) {
36
+ const copy = atom.cloneNode(true);
37
+ copy.setAttribute("data-orientation", vertical ? "vertical" : "horizontal");
38
+ copy.removeAttribute("id");
39
+ copy.inert = true;
40
+ copy.style.visibility = "hidden";
41
+ copy.style.pointerEvents = "none";
42
+ copy.style.translate = "none";
43
+ copy.style.scale = "none";
44
+ copy.querySelector("[data-mp=\"actions\"]")?.removeAttribute("data-wheel");
45
+ atom.after(copy);
46
+ const width = copy.offsetWidth;
47
+ const height = copy.offsetHeight;
48
+ const actions = [...copy.querySelectorAll("[data-mp=\"actions\"] > *")];
49
+ const along = (element) => vertical ? element.offsetTop : element.offsetLeft;
50
+ const action = actions[0] ? vertical ? actions[0].offsetHeight : actions[0].offsetWidth : 0;
51
+ const step = actions.length > 1 ? Math.abs(along(actions[1]) - along(actions[0])) : action;
52
+ const length = vertical ? height : width;
53
+ copy.remove();
54
+ return {
55
+ width,
56
+ height,
57
+ wheel: {
58
+ count: actions.length,
59
+ first: length - Math.max(0, actions.length - 1) * step,
60
+ step,
61
+ action
62
+ }
63
+ };
64
+ }
65
+ /**
66
+ * Out of the anchor (or back into it) with the goo, drawing itself the whole
67
+ * way, as the orbitals do: from inside it at its nearest edge by default.
68
+ */
69
+ const bud = (anchor, element, kind, delay, duration, from, opaque = false) => require_goo.playOrbit(anchor, [{
70
+ element,
71
+ delay,
72
+ from: from ?? require_goo.atEdgeOf(anchor),
73
+ opaque
74
+ }], kind === "split" ? "open" : "close", { duration });
75
+ /** The screen's length along the host's edge, less its offsets. */
76
+ const mainRoom = (vertical, offset) => (vertical ? window.innerHeight : document.documentElement.clientWidth || window.innerWidth) - offset * 2;
77
+ /**
78
+ * The length of the page's actions inside the pill when they must be cut
79
+ * short to leave it `room` (undefined: all of them fit). `least`: how short
80
+ * the host gets with its navbar's labels folded.
81
+ */
82
+ function insideWheelLength(track, root, vertical, room, least) {
83
+ const actions = [...track.children];
84
+ if (actions.length < 2) return void 0;
85
+ const along = (element) => vertical ? element.offsetTop : element.offsetLeft;
86
+ const action = vertical ? actions[0].offsetHeight : actions[0].offsetWidth;
87
+ const step = Math.abs(along(actions[1]) - along(actions[0]));
88
+ const all = action + (actions.length - 1) * step;
89
+ const now = vertical ? track.clientHeight : track.clientWidth;
90
+ const left = room - ((vertical ? root.offsetHeight : Math.min(root.offsetWidth, least ?? 1e400)) - now);
91
+ if (left >= all - .5 || step <= 0) return void 0;
92
+ return action + (Math.max(1, Math.min(actions.length, 1 + Math.floor((left - action) / step))) - 1) * step;
93
+ }
94
+ /** Two boxes side by side, a gap apart: the second can come out of the first. */
95
+ const nextTo = (a, b, gap) => {
96
+ const sideBySide = Math.abs(a.top - b.top) < 2 && Math.abs(Math.abs(a.left - b.left) - (a.width + gap)) < 2;
97
+ const stacked = Math.abs(a.left - b.left) < 2 && Math.abs(Math.abs(a.top - b.top) - (a.height + gap)) < 2;
98
+ return sideBySide || stacked;
99
+ };
100
+ /** What an electron shows: the ring and its value or icon, the value alone, or the app's own. */
101
+ function ElectronContent({ electron }) {
102
+ const { input } = electron;
103
+ if (input.render) return input.render();
104
+ const inner = input.value !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
105
+ "data-mp": "electron-value",
106
+ children: input.value
107
+ }) : input.icon !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
108
+ "data-mp": "electron-icon",
109
+ "aria-hidden": "true",
110
+ children: input.icon
111
+ }) : null;
112
+ return input.progress !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillProgress.PillProgress, {
113
+ value: input.progress,
114
+ children: inner
115
+ }) : inner;
116
+ }
117
+ /** All of the circle is a link back to where it came from, or a button for its `onClick`. */
118
+ function ElectronBody({ electron, host }) {
119
+ const { input, origin } = electron;
120
+ const valueText = input.valueText ?? input.value;
121
+ const name = valueText ? `${input.label}, ${valueText}` : input.label;
122
+ const content = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ElectronContent, { electron });
123
+ if (input.onClick) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
124
+ type: "button",
125
+ "data-mp": "electron",
126
+ "aria-label": name,
127
+ onClick: (event) => input.onClick?.(event),
128
+ children: content
129
+ });
130
+ if (origin !== void 0) {
131
+ const Link = host.linkComponent ?? "a";
132
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Link, {
133
+ href: origin,
134
+ "data-mp": "electron",
135
+ "aria-label": name,
136
+ draggable: false,
137
+ children: content
138
+ });
139
+ }
140
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
141
+ "data-mp": "electron",
142
+ role: "img",
143
+ "aria-label": name,
144
+ children: content
145
+ });
146
+ }
147
+ function SatellitesLayer({ host }) {
148
+ const electrons = (0, react.useSyncExternalStore)(host.store.subscribe, host.store.getElectrons, () => require_store.NO_ELECTRONS);
149
+ const [, refresh] = (0, react.useReducer)((count) => count + 1, 0);
150
+ const shown = (0, react.useRef)(/* @__PURE__ */ new Map());
151
+ for (const electron of electrons) shown.current.set(electron.id, { electron });
152
+ for (const [id, entry] of shown.current) if (!entry.leaving && !electrons.some((electron) => electron.id === id)) shown.current.set(id, {
153
+ ...entry,
154
+ leaving: true
155
+ });
156
+ const [travelling, setTravelling] = (0, react.useState)(false);
157
+ const spot = `${host.placement} ${host.vertical}`;
158
+ const lastSpot = (0, react.useRef)(spot);
159
+ require_react.useIsomorphicLayoutEffect(() => {
160
+ if (lastSpot.current === spot) return;
161
+ lastSpot.current = spot;
162
+ setTravelling(true);
163
+ }, [spot]);
164
+ (0, react.useEffect)(() => {
165
+ const root = host.rootRef.current;
166
+ if (!travelling || !root) return;
167
+ let closed = false;
168
+ const watch = new MutationObserver(() => {
169
+ const presence = root.dataset.presence;
170
+ if (presence === "rest" || presence === "hidden") closed = true;
171
+ else if (closed) setTravelling(false);
172
+ });
173
+ watch.observe(root, {
174
+ attributes: true,
175
+ attributeFilter: ["data-presence"]
176
+ });
177
+ const fallback = setTimeout(() => setTravelling(false), 1500);
178
+ return () => {
179
+ watch.disconnect();
180
+ clearTimeout(fallback);
181
+ };
182
+ }, [travelling, host.rootRef]);
183
+ const wanted = host.notifying && !host.keepElectronsOut || travelling;
184
+ const wasTucked = (0, react.useRef)(wanted);
185
+ const holding = (0, react.useRef)(false);
186
+ if (wasTucked.current && !wanted) holding.current = true;
187
+ wasTucked.current = wanted;
188
+ require_react.useIsomorphicLayoutEffect(() => {
189
+ const root = host.rootRef.current;
190
+ if (wanted || !holding.current) return;
191
+ const release = () => {
192
+ holding.current = false;
193
+ refresh();
194
+ };
195
+ const morphs = (root?.getAnimations?.() ?? []).filter((animation) => animation.id === require_morph.MORPH);
196
+ if (morphs.length === 0) return release();
197
+ let cancelled = false;
198
+ Promise.allSettled(morphs.map((animation) => animation.finished)).then(() => {
199
+ if (!cancelled) release();
200
+ });
201
+ return () => {
202
+ cancelled = true;
203
+ };
204
+ }, [wanted]);
205
+ const tucked = wanted || holding.current;
206
+ const actions = require_Actions.useHostActions(host);
207
+ const lastActions = (0, react.useRef)(null);
208
+ if (actions) lastActions.current = actions;
209
+ const detached = host.actionsStyle === "detached";
210
+ const actionsPresence = detached && actions && !tucked ? "compact" : "hidden";
211
+ const goingIn = (0, react.useRef)(false);
212
+ const wasDetached = (0, react.useRef)(detached);
213
+ if (wasDetached.current && !detached && actions) goingIn.current = true;
214
+ if (detached) goingIn.current = false;
215
+ wasDetached.current = detached;
216
+ const shownActions = detached || goingIn.current ? actions ?? lastActions.current : null;
217
+ const atom = (0, react.useRef)(null);
218
+ const [actionsAcross, setActionsAcross] = (0, react.useState)(false);
219
+ const [wheelLength, setWheelLength] = (0, react.useState)(void 0);
220
+ const actionsBox = (0, react.useRef)(null);
221
+ const across = (0, react.useRef)(actionsAcross);
222
+ across.current = actionsAcross;
223
+ const presenceOf = ({ electron, leaving }) => {
224
+ if (leaving || tucked) return "hidden";
225
+ return electron.input.hideOnOrigin !== false && electron.origin !== void 0 && require_matchPath.findActiveIndex(host.pathname, [{ href: electron.origin }]) === 0 ? "hidden" : "compact";
226
+ };
227
+ const entries = [...shown.current.values()].map((entry) => ({
228
+ ...entry,
229
+ presence: presenceOf(entry)
230
+ }));
231
+ const elements = (0, react.useRef)(/* @__PURE__ */ new Map());
232
+ const presences = (0, react.useRef)(/* @__PURE__ */ new Map());
233
+ const applied = (0, react.useRef)({
234
+ shift: 0,
235
+ reserve: 0
236
+ });
237
+ const hostMin = (0, react.useRef)(void 0);
238
+ const rows = (0, react.useRef)(/* @__PURE__ */ new Map());
239
+ const spots = (0, react.useRef)(/* @__PURE__ */ new Map());
240
+ const rejoining = (0, react.useRef)(/* @__PURE__ */ new Set());
241
+ const splitNext = (0, react.useRef)(/* @__PURE__ */ new Set());
242
+ const insideSpot = (0, react.useRef)(null);
243
+ const lastStyle = (0, react.useRef)(host.actionsStyle);
244
+ const arrange = (0, react.useRef)(() => {});
245
+ arrange.current = (animate) => {
246
+ const root = host.rootRef.current;
247
+ if (!root) return;
248
+ const vertical = SIDE_PLACEMENTS.has(host.placement);
249
+ const style = getComputedStyle(root);
250
+ const gap = require_measure.toPixels(style.getPropertyValue("--mp-electron-gap"), root, Number.parseFloat(style.columnGap) || 16);
251
+ const offset = require_measure.toPixels(style.getPropertyValue("--_mp-offset"), root, 24);
252
+ const out = entries.filter((entry) => entry.presence !== "hidden" && elements.current.get(entry.electron.id));
253
+ if (animate && !vertical) hostMin.current = require_room.foldedWidth(root);
254
+ const atomElement = atom.current;
255
+ const atomOut = actionsPresence !== "hidden" && atomElement;
256
+ if (atomOut && (animate || !actionsBox.current)) actionsBox.current = alongBox(atomElement, vertical);
257
+ const turn = host.actionsOrientation === "auto" ? "auto" : host.actionsOrientation === "vertical" === vertical ? "along" : "across";
258
+ const layout = require_layout.planSatellites({
259
+ viewport: {
260
+ width: document.documentElement.clientWidth || window.innerWidth,
261
+ height: window.innerHeight
262
+ },
263
+ host: {
264
+ left: root.offsetLeft,
265
+ top: root.offsetTop,
266
+ width: root.offsetWidth,
267
+ height: root.offsetHeight
268
+ },
269
+ hostMin: vertical ? void 0 : hostMin.current,
270
+ placement: host.placement,
271
+ vertical,
272
+ rtl: style.direction === "rtl",
273
+ electrons: out.map(({ electron }) => {
274
+ const element = elements.current.get(electron.id);
275
+ return {
276
+ id: electron.id,
277
+ width: element.offsetWidth || 72,
278
+ height: element.offsetHeight || 72
279
+ };
280
+ }),
281
+ actions: atomOut && actionsBox.current ? {
282
+ width: actionsBox.current.width,
283
+ height: actionsBox.current.height,
284
+ side: host.actionsSide,
285
+ turn,
286
+ ...host.actionsWheel ? { wheel: actionsBox.current.wheel } : {}
287
+ } : void 0,
288
+ nearest: host.nearestToPill,
289
+ side: host.electronSide,
290
+ line: host.electronLine,
291
+ arrange: host.arrange,
292
+ gap,
293
+ offset
294
+ });
295
+ if (animate && host.actionsStyle === "inside") {
296
+ const track = root.querySelector("[data-mp=\"actions\"][data-inside]");
297
+ if (track) {
298
+ const length = host.actionsWheel ? insideWheelLength(track, root, vertical, mainRoom(vertical, offset) - layout.reserve, hostMin.current) : void 0;
299
+ if (length === void 0) {
300
+ track.removeAttribute("data-wheel");
301
+ track.style.removeProperty("--_mp-wheel-length");
302
+ } else {
303
+ track.setAttribute("data-wheel", "");
304
+ track.style.setProperty("--_mp-wheel-length", `${length}px`);
305
+ }
306
+ }
307
+ }
308
+ const reduced = require_timing.prefersReducedMotion();
309
+ const moving = animate && !reduced && typeof root.animate === "function";
310
+ const timings = require_measure.durations(out[0] ? elements.current.get(out[0].electron.id) : root);
311
+ const boxes = layout.boxes;
312
+ const hostAlong = (vertical ? root.offsetTop : root.offsetLeft) + layout.shift + (vertical ? root.offsetHeight : root.offsetWidth) / 2;
313
+ const alongOf = (box) => vertical ? box.top + box.height / 2 : box.left + box.width / 2;
314
+ const spotOf = (box) => `${alongOf(box) < hostAlong ? "before" : "after"} ${Math.round(vertical ? box.left : box.top)}`;
315
+ const hostCentre = () => vertical ? require_goo.atPoint(root.offsetLeft + root.offsetWidth / 2, hostAlong) : require_goo.atPoint(hostAlong, root.offsetTop + root.offsetHeight / 2);
316
+ const changing = (id, box) => !!box && presences.current.get(id) === "compact" && spots.current.has(id) && spots.current.get(id) !== spotOf(box);
317
+ const turning = !!atomElement && !!atomOut && layout.actionsAcross !== across.current && presences.current.get(ACTIONS) === "compact";
318
+ const holding = animate && !reduced && (out.some(({ electron }) => !rejoining.current.has(electron.id) && changing(electron.id, boxes[electron.id])) || !!atomOut && !rejoining.current.has(ACTIONS) && (turning || changing(ACTIONS, boxes.actions))) || rejoining.current.size > 0;
319
+ const previous = applied.current;
320
+ if (!holding && Math.abs(layout.shift - previous.shift) > .5) {
321
+ const along = (value) => vertical ? `0px ${value}px` : `${value}px 0px`;
322
+ if (layout.shift) root.style.setProperty("translate", along(layout.shift));
323
+ else root.style.removeProperty("translate");
324
+ if (moving) root.animate([{ translate: along(previous.shift - layout.shift) }, { translate: "0px 0px" }], {
325
+ id: SHIFT,
326
+ duration: timings.change,
327
+ easing: "ease-in-out",
328
+ composite: "add"
329
+ });
330
+ }
331
+ if (!holding && !vertical && layout.reserve !== previous.reserve) {
332
+ if (layout.reserve) root.style.setProperty("--_mp-shift-x", `${layout.reserve}px`);
333
+ else root.style.removeProperty("--_mp-shift-x");
334
+ }
335
+ if (!holding) applied.current = {
336
+ shift: layout.shift,
337
+ reserve: layout.reserve
338
+ };
339
+ const rejoin = (id, element, then) => {
340
+ rejoining.current.add(id);
341
+ const { exit } = require_measure.durations(element);
342
+ bud(root, element, "join", 0, exit);
343
+ setTimeout(() => {
344
+ rejoining.current.delete(id);
345
+ then();
346
+ }, exit + 20);
347
+ };
348
+ const styleChanged = lastStyle.current !== host.actionsStyle;
349
+ if (animate) {
350
+ const track = host.actionsStyle === "inside" ? root.querySelector("[data-mp=\"actions\"][data-inside]") : null;
351
+ if (track) {
352
+ const hostLeft = root.offsetLeft + (vertical ? 0 : layout.shift);
353
+ const hostTop = root.offsetTop + (vertical ? layout.shift : 0);
354
+ insideSpot.current = {
355
+ x: hostLeft + track.offsetLeft + track.offsetWidth / 2,
356
+ y: hostTop + track.offsetTop + track.offsetHeight / 2
357
+ };
358
+ }
359
+ lastStyle.current = host.actionsStyle;
360
+ }
361
+ const slides = [];
362
+ if (atomElement) {
363
+ const was = presences.current.get(ACTIONS);
364
+ const box = boxes.actions;
365
+ const settled = layout.actionsAcross === across.current;
366
+ const moved = !!box && spots.current.has(ACTIONS) && spots.current.get(ACTIONS) !== spotOf(box);
367
+ if (animate && atomOut && was === "compact" && (!settled || moved) && !reduced && !rejoining.current.has(ACTIONS)) {
368
+ const turnTo = layout.actionsAcross;
369
+ rejoin(ACTIONS, atomElement, () => {
370
+ presences.current.set(ACTIONS, "hidden");
371
+ spots.current.delete(ACTIONS);
372
+ setActionsAcross(turnTo);
373
+ refresh();
374
+ });
375
+ } else if (animate && atomOut && !settled && !rejoining.current.has(ACTIONS)) setActionsAcross(layout.actionsAcross);
376
+ if (animate && atomOut && actionsBox.current) {
377
+ const { wheel } = actionsBox.current;
378
+ const length = layout.actionsShown !== void 0 ? wheel.action + (layout.actionsShown - 1) * wheel.step : void 0;
379
+ if (length !== wheelLength) setWheelLength(length);
380
+ }
381
+ if (box && atomOut && settled && !rejoining.current.has(ACTIONS) && !holding) {
382
+ const before = alongOf(box) < hostAlong;
383
+ const width = atomElement.offsetWidth || box.width;
384
+ const height = atomElement.offsetHeight || box.height;
385
+ const from = {
386
+ left: Number.parseFloat(atomElement.style.left),
387
+ top: Number.parseFloat(atomElement.style.top)
388
+ };
389
+ const left = !vertical && before ? box.left + box.width - width : box.left;
390
+ const top = vertical && before ? box.top + box.height - height : box.top;
391
+ atomElement.style.left = `${left}px`;
392
+ atomElement.style.top = `${top}px`;
393
+ spots.current.set(ACTIONS, spotOf(box));
394
+ if (animate && was !== "compact") {
395
+ const fromInside = styleChanged && insideSpot.current ? require_goo.atPoint(insideSpot.current.x, insideSpot.current.y, 1) : void 0;
396
+ require_morph.cancel(atomElement, require_morph.MORPH, true);
397
+ require_morph.cancel(atomElement, require_morph.MOVE);
398
+ bud(root, atomElement, "split", 0, require_measure.durations(atomElement).enter, fromInside, !!fromInside);
399
+ } else if (moving && was === "compact" && Number.isFinite(from.left) && Number.isFinite(from.top)) {
400
+ if (Math.abs(from.left - left) > .5 || Math.abs(from.top - top) > .5) {
401
+ slides.push({
402
+ element: atomElement,
403
+ from: vertical ? from.top : from.left,
404
+ to: vertical ? top : left
405
+ });
406
+ atomElement.animate([{ translate: `${from.left - left}px ${from.top - top}px` }, { translate: "0px 0px" }], {
407
+ id: SHIFT,
408
+ duration: timings.change,
409
+ easing: "ease-in-out",
410
+ composite: "add"
411
+ });
412
+ }
413
+ }
414
+ } else if (animate && !atomOut && was === "compact") {
415
+ const { fade, exit } = require_measure.durations(atomElement);
416
+ if (styleChanged && host.actionsStyle === "inside" && insideSpot.current) {
417
+ require_morph.cancel(atomElement, require_morph.EXIT, true);
418
+ for (const child of atomElement.children) child.style.opacity = "1";
419
+ bud(root, atomElement, "join", 0, exit, require_goo.atPoint(insideSpot.current.x, insideSpot.current.y, 1), true);
420
+ setTimeout(() => {
421
+ for (const child of atomElement.children) child.style.removeProperty("opacity");
422
+ goingIn.current = false;
423
+ refresh();
424
+ }, exit + 20);
425
+ } else if (tucked) bud(root, atomElement, "join", 0, Math.max(exit, fade + require_measure.durations(atomElement).change), hostCentre());
426
+ else bud(root, atomElement, "join", fade, exit);
427
+ spots.current.delete(ACTIONS);
428
+ }
429
+ if (animate && !rejoining.current.has(ACTIONS) && !holding && (settled || !atomOut)) presences.current.set(ACTIONS, actionsPresence);
430
+ }
431
+ const crossOf = (box) => Math.round(vertical ? box.left : box.top);
432
+ out.forEach(({ electron }, index) => {
433
+ const element = elements.current.get(electron.id);
434
+ const box = boxes[electron.id];
435
+ const was = presences.current.get(electron.id);
436
+ if (rejoining.current.has(electron.id)) return;
437
+ if (splitNext.current.delete(electron.id)) {
438
+ element.style.left = `${box.left}px`;
439
+ element.style.top = `${box.top}px`;
440
+ rows.current.set(electron.id, String(crossOf(box)));
441
+ bud(root, element, "split", 0, require_measure.durations(element).enter);
442
+ return;
443
+ }
444
+ const moved = was === "compact" && spots.current.has(electron.id) && spots.current.get(electron.id) !== spotOf(box);
445
+ if (animate && moved && !reduced) {
446
+ spots.current.set(electron.id, spotOf(box));
447
+ rejoin(electron.id, element, () => {
448
+ splitNext.current.add(electron.id);
449
+ arrange.current(true);
450
+ });
451
+ return;
452
+ }
453
+ if (holding) return;
454
+ spots.current.set(electron.id, spotOf(box));
455
+ const from = {
456
+ left: Number.parseFloat(element.style.left),
457
+ top: Number.parseFloat(element.style.top)
458
+ };
459
+ element.style.left = `${box.left}px`;
460
+ element.style.top = `${box.top}px`;
461
+ const row = String(crossOf(box));
462
+ const changedRow = rows.current.has(electron.id) && rows.current.get(electron.id) !== row;
463
+ rows.current.set(electron.id, row);
464
+ const placed = Number.isFinite(from.left) && Number.isFinite(from.top);
465
+ if (!animate) {
466
+ if (changedRow && placed && !reduced && typeof element.animate === "function") element.animate([{ translate: `${from.left - box.left}px ${from.top - box.top}px` }, { translate: "0px 0px" }], {
467
+ id: SHIFT,
468
+ duration: timings.change,
469
+ easing: "ease-in-out",
470
+ composite: "add"
471
+ });
472
+ return;
473
+ }
474
+ if (was === void 0 || was === "hidden") {
475
+ const before = out[index - 1];
476
+ const neighbour = before ? elements.current.get(before.electron.id) : void 0;
477
+ const anchor = neighbour && before && nextTo(boxes[before.electron.id], box, gap) ? neighbour : root;
478
+ bud(anchor, element, "split", 0, require_measure.durations(element).enter);
479
+ } else if (moving && placed && (Math.abs(from.left - box.left) > .5 || Math.abs(from.top - box.top) > .5)) {
480
+ slides.push({
481
+ element,
482
+ from: vertical ? from.top : from.left,
483
+ to: vertical ? box.top : box.left
484
+ });
485
+ element.animate([{ translate: `${from.left - box.left}px ${from.top - box.top}px` }, { translate: "0px 0px" }], {
486
+ id: SHIFT,
487
+ duration: timings.change,
488
+ easing: "ease-in-out",
489
+ composite: "add"
490
+ });
491
+ }
492
+ });
493
+ const passing = /* @__PURE__ */ new Set();
494
+ slides.forEach((a, i) => slides.slice(i + 1).forEach((b) => {
495
+ if (Math.sign(a.from - b.from) !== Math.sign(a.to - b.to)) {
496
+ passing.add(a.element);
497
+ passing.add(b.element);
498
+ }
499
+ }));
500
+ if (passing.size > 1) require_goo.playNecks([...passing], timings.change);
501
+ if (animate && !holding) {
502
+ for (const entry of entries) {
503
+ const element = elements.current.get(entry.electron.id);
504
+ if (!element || entry.presence !== "hidden" || presences.current.get(entry.electron.id) !== "compact") continue;
505
+ const ending = entry.leaving ? entry.electron.input.ending ?? host.electronEnding : "join";
506
+ spots.current.delete(entry.electron.id);
507
+ if (ending === "pop") continue;
508
+ const { fade, change, exit } = require_measure.durations(element);
509
+ if (tucked && !entry.leaving) bud(root, element, "join", 0, Math.max(exit, fade + change), hostCentre());
510
+ else bud(root, element, "join", fade, exit);
511
+ }
512
+ for (const entry of entries) presences.current.set(entry.electron.id, entry.presence);
513
+ }
514
+ };
515
+ require_react.useIsomorphicLayoutEffect(() => arrange.current(true));
516
+ (0, react.useEffect)(() => {
517
+ const root = host.rootRef.current;
518
+ if (!root) return;
519
+ let settle;
520
+ const follow = () => {
521
+ arrange.current(false);
522
+ clearTimeout(settle);
523
+ settle = setTimeout(() => arrange.current(true), 200);
524
+ };
525
+ const observer = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(follow);
526
+ observer?.observe(root);
527
+ if (atom.current) observer?.observe(atom.current);
528
+ window.addEventListener("resize", follow);
529
+ return () => {
530
+ clearTimeout(settle);
531
+ observer?.disconnect();
532
+ window.removeEventListener("resize", follow);
533
+ root.style.removeProperty("translate");
534
+ if (!SIDE_PLACEMENTS.has(host.placement)) root.style.removeProperty("--_mp-shift-x");
535
+ applied.current = {
536
+ shift: 0,
537
+ reserve: 0
538
+ };
539
+ };
540
+ }, [
541
+ host.rootRef,
542
+ host.placement,
543
+ !!shownActions
544
+ ]);
545
+ const leavingIds = entries.filter((entry) => entry.leaving).map((entry) => entry.electron.id);
546
+ (0, react.useEffect)(() => {
547
+ if (leavingIds.length === 0) return;
548
+ const timers = leavingIds.map((id) => {
549
+ const element = elements.current.get(id);
550
+ const { fade, change, exit } = element ? require_measure.durations(element) : {
551
+ fade: 150,
552
+ change: 250,
553
+ exit: 300
554
+ };
555
+ return setTimeout(() => {
556
+ shown.current.delete(id);
557
+ presences.current.delete(id);
558
+ rows.current.delete(id);
559
+ spots.current.delete(id);
560
+ refresh();
561
+ }, fade + change + exit + 100);
562
+ });
563
+ return () => timers.forEach(clearTimeout);
564
+ }, [leavingIds.join(" ")]);
565
+ const [announcement, setAnnouncement] = (0, react.useState)("");
566
+ const announced = (0, react.useRef)(/* @__PURE__ */ new Map());
567
+ (0, react.useEffect)(() => {
568
+ for (const electron of electrons) {
569
+ const text = electron.input.announce;
570
+ if (text && announced.current.get(electron.id) !== text) setAnnouncement(text);
571
+ announced.current.set(electron.id, text);
572
+ }
573
+ }, [electrons]);
574
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
575
+ entries.map(({ electron, presence, leaving }) => {
576
+ const ending = electron.input.ending ?? host.electronEnding;
577
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Pill, {
578
+ ref: (element) => {
579
+ if (element) elements.current.set(electron.id, element);
580
+ else elements.current.delete(electron.id);
581
+ },
582
+ placement: "inline",
583
+ ladder: false,
584
+ moveThroughCircle: false,
585
+ theme: host.theme,
586
+ variant: electron.input.variant ?? host.variant,
587
+ presence,
588
+ "data-satellite": "electron",
589
+ "data-ending": leaving && ending === "pop" ? "pop" : void 0,
590
+ style: ELECTRON_STYLE,
591
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ElectronBody, {
592
+ electron,
593
+ host
594
+ })
595
+ }, electron.id);
596
+ }),
597
+ shownActions && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Pill, {
598
+ ref: atom,
599
+ placement: "inline",
600
+ ladder: false,
601
+ moveThroughCircle: false,
602
+ theme: host.theme,
603
+ variant: host.variant,
604
+ orientation: host.vertical !== actionsAcross ? "vertical" : "horizontal",
605
+ presence: actionsPresence,
606
+ scene: shownActions.map((item) => item.id ?? item.label).join("\n"),
607
+ role: "group",
608
+ "aria-label": host.actionsLabel,
609
+ "data-satellite": "actions",
610
+ style: ELECTRON_STYLE,
611
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Actions.ActionList, {
612
+ items: shownActions,
613
+ host,
614
+ wheel: wheelLength
615
+ })
616
+ }),
617
+ entries.map(({ electron, presence }) => electron.input.orbitals?.length ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Orbitals.Orbitals, {
618
+ electron,
619
+ getElement: () => elements.current.get(electron.id),
620
+ host,
621
+ out: presence !== "hidden"
622
+ }, `orbitals ${electron.id}`) : null),
623
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
624
+ role: "status",
625
+ "aria-live": "polite",
626
+ "aria-atomic": "true",
627
+ "data-mp": "announcer",
628
+ style: require_visuallyHidden.VISUALLY_HIDDEN,
629
+ children: announcement
630
+ })
631
+ ] });
632
+ }
633
+
634
+ exports.SatellitesLayer = SatellitesLayer;