magic-pill 9.4.0-next.3 → 9.4.0-next.4

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 (45) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +10 -7
  3. package/dist/MagicPill/MagicPill.d.mts +2 -1
  4. package/dist/MagicPill/MagicPill.d.ts +2 -1
  5. package/dist/MagicPill/MagicPill.js +10 -3
  6. package/dist/MagicPill/MagicPill.mjs +10 -3
  7. package/dist/Pill/Pill.js +1 -0
  8. package/dist/Pill/Pill.mjs +1 -0
  9. package/dist/Pill/goo.js +60 -28
  10. package/dist/Pill/goo.mjs +60 -28
  11. package/dist/Pill/modal.js +3 -1
  12. package/dist/Pill/modal.mjs +3 -1
  13. package/dist/Pill/morph.js +56 -2
  14. package/dist/Pill/morph.mjs +56 -3
  15. package/dist/PillForm/PillForm.js +6 -1
  16. package/dist/PillForm/PillForm.mjs +7 -2
  17. package/dist/PillForm/dates.js +14 -3
  18. package/dist/PillForm/dates.mjs +14 -3
  19. package/dist/PillForm/room.js +46 -0
  20. package/dist/PillForm/room.mjs +46 -0
  21. package/dist/PillNavbar/PillNavbar.js +3 -1
  22. package/dist/PillNavbar/PillNavbar.mjs +4 -2
  23. package/dist/PillNavbar/room.js +65 -11
  24. package/dist/PillNavbar/room.mjs +65 -12
  25. package/dist/PillNotification/PillNotification.js +2 -4
  26. package/dist/PillNotification/PillNotification.mjs +2 -4
  27. package/dist/PillNotification/RowsBody.js +77 -0
  28. package/dist/PillNotification/RowsBody.mjs +77 -0
  29. package/dist/forms.css +14 -0
  30. package/dist/satellites/Actions.js +181 -6
  31. package/dist/satellites/Actions.mjs +182 -7
  32. package/dist/satellites/Orbitals.js +67 -17
  33. package/dist/satellites/Orbitals.mjs +69 -19
  34. package/dist/satellites/Satellites.js +197 -84
  35. package/dist/satellites/Satellites.mjs +198 -86
  36. package/dist/satellites/handoff.js +36 -0
  37. package/dist/satellites/handoff.mjs +34 -0
  38. package/dist/satellites/measure.js +22 -0
  39. package/dist/satellites/measure.mjs +22 -1
  40. package/dist/satellites/orbits.js +12 -0
  41. package/dist/satellites/orbits.mjs +12 -1
  42. package/dist/satellites/types.d.mts +7 -1
  43. package/dist/satellites/types.d.ts +7 -1
  44. package/dist/styles.css +78 -15
  45. package/package.json +1 -1
@@ -12,6 +12,7 @@ const require_react = require("../utils/react.js");
12
12
  const require_timing = require("../utils/timing.js");
13
13
  const require_visuallyHidden = require("../utils/visuallyHidden.js");
14
14
  const require_layout = require("./layout.js");
15
+ const require_handoff = require("./handoff.js");
15
16
  const require_measure = require("./measure.js");
16
17
  const require_Orbitals = require("./Orbitals.js");
17
18
  const require_Actions = require("./Actions.js");
@@ -20,10 +21,12 @@ let react_jsx_runtime = require("react/jsx-runtime");
20
21
  // src/satellites/Satellites.tsx
21
22
  const ELECTRON_STYLE = {
22
23
  position: "fixed",
23
- zIndex: "var(--mp-z-index, 50)",
24
+ zIndex: "calc(var(--mp-z-index, 50) - 1)",
24
25
  margin: 0
25
26
  };
26
27
  const SHIFT = "mp-satellite-shift";
28
+ /** The room the satellites take beside a horizontal host, as planned (`--_mp-shift-x` applies it, maybe later) */
29
+ const PLANNED_ROOM = "--_mp-room-x";
27
30
  /** The page's actions' entry among the satellites' presences */
28
31
  const ACTIONS = "\0actions";
29
32
  const SIDE_PLACEMENTS = /* @__PURE__ */ new Set(["left", "right"]);
@@ -76,19 +79,46 @@ const bud = (anchor, element, kind, delay, duration, from, opaque = false) => re
76
79
  opaque
77
80
  }], kind === "split" ? "open" : "close", { duration });
78
81
  /**
82
+ * How long the screen (or the host) stays the same size before the satellites decide again: a drag
83
+ * of the window's edge sends one event per frame. Was 200 ms: a pause you could feel once you let go
84
+ */
85
+ const SETTLED = 120;
86
+ /** A host's slide longer than this (px) can run against a droplet's way out (see drop) */
87
+ const AGAINST = 24;
88
+ /**
79
89
  * Out of the anchor's edge as a droplet, growing to its size and then showing its content, or back
80
90
  * into it the same way played backwards. `at`: where the anchor is going, if it's moving; `slide`:
81
91
  * how it gets there, which a droplet coming out follows while it's still attached (from its edge
82
92
  * where it is to its edge where it goes), or it would come out where the anchor no longer is.
83
93
  */
84
94
  function drop(anchor, element, kind, delay, duration, at, slide) {
95
+ const from = require_goo.atEdgeOf(anchor, at, require_goo.DROPLET);
96
+ const moves = !!slide && kind === "split" && !require_timing.prefersReducedMotion() && typeof element.animate === "function";
97
+ if (moves && slide && Math.hypot(slide.x, slide.y) > AGAINST) {
98
+ for (const animation of element.getAnimations?.() ?? []) if (animation.id === "mp-split") animation.cancel();
99
+ const out = from(element.getBoundingClientRect(), element);
100
+ if (out.x * slide.x + out.y * slide.y < 0) {
101
+ const wait = delay + slide.duration;
102
+ const stop = require_goo.playOrbit(anchor, [{
103
+ element,
104
+ delay: wait,
105
+ from,
106
+ droplet: true
107
+ }], "open", { duration });
108
+ element.animate([{ opacity: 0 }, { opacity: 0 }], {
109
+ id: require_goo.SPLIT,
110
+ duration: wait
111
+ });
112
+ return stop;
113
+ }
114
+ }
85
115
  const stop = require_goo.playOrbit(anchor, [{
86
116
  element,
87
117
  delay,
88
- from: require_goo.atEdgeOf(anchor, at, require_goo.DROPLET),
118
+ from,
89
119
  droplet: true
90
120
  }], kind === "split" ? "open" : "close", { duration });
91
- if (slide && kind === "split" && !require_timing.prefersReducedMotion() && typeof element.animate === "function") element.animate([{ translate: `${slide.x}px ${slide.y}px` }, { translate: "0px 0px" }], {
121
+ if (moves && slide) element.animate([{ translate: `${slide.x}px ${slide.y}px` }, { translate: "0px 0px" }], {
92
122
  id: require_goo.SPLIT,
93
123
  duration: slide.duration,
94
124
  easing: "ease-in-out",
@@ -100,18 +130,22 @@ function drop(anchor, element, kind, delay, duration, at, slide) {
100
130
  const mainRoom = (vertical, offset) => (vertical ? window.innerHeight : document.documentElement.clientWidth || window.innerWidth) - offset * 2;
101
131
  /**
102
132
  * The length of the page's actions inside the pill when they must be cut
103
- * short to leave it `room` (undefined: all of them fit). `least`: how short
104
- * the host gets with its navbar's labels folded.
133
+ * short to leave it `room` (undefined: all of them fit). `length`: how long
134
+ * the host is, its actions as they are now, with its navbar's current page's
135
+ * label open when it folds by itself: the navbar keeps its room first, and
136
+ * the actions show what fits, the rest in their wheel.
105
137
  */
106
- function insideWheelLength(track, root, vertical, room, least) {
138
+ function insideWheelLength(track, root, vertical, room, length, folded) {
107
139
  const actions = [...track.children];
108
140
  if (actions.length < 2) return void 0;
109
141
  const along = (element) => vertical ? element.offsetTop : element.offsetLeft;
110
142
  const action = vertical ? actions[0].offsetHeight : actions[0].offsetWidth;
111
143
  const step = Math.abs(along(actions[1]) - along(actions[0]));
112
144
  const all = action + (actions.length - 1) * step;
113
- const now = vertical ? track.clientHeight : track.clientWidth;
114
- const left = room - ((vertical ? root.offsetHeight : Math.min(root.offsetWidth, least ?? 1e400)) - now);
145
+ const now = track.hasAttribute("data-wheel") ? Number.parseFloat(track.style.getPropertyValue("--_mp-wheel-length")) || all : all;
146
+ const leftWith = (host) => room - (host - now);
147
+ const open = vertical ? root.offsetHeight : length ?? root.offsetWidth;
148
+ const left = !vertical && folded !== void 0 && leftWith(open) < action ? leftWith(Math.min(open, folded)) : leftWith(open);
115
149
  if (left >= all - .5 || step <= 0) return void 0;
116
150
  return action + (Math.max(1, Math.min(actions.length, 1 + Math.floor((left - action) / step))) - 1) * step;
117
151
  }
@@ -123,26 +157,6 @@ const nextTo = (a, b, gap) => {
123
157
  };
124
158
  /** What an electron shows: the ring and its value or icon, the value alone, or the app's own. */
125
159
  /**
126
- * The other pills on the screen (a sidebar, a help pill…), for the satellites to keep clear of:
127
- * the fixed ones that show, not the host, nor what's in it, nor any satellite (inline pills).
128
- */
129
- function otherPills(root) {
130
- const boxes = [];
131
- for (const element of document.querySelectorAll("[data-mp=\"pill\"][data-placement]")) {
132
- const { placement, presence } = element.dataset;
133
- if (placement === "inline" || placement === "overlay" || presence === "hidden") continue;
134
- if (element === root || root.contains(element) || element.contains(root)) continue;
135
- const { left, top, width, height } = element.getBoundingClientRect();
136
- if (width > 0 && height > 0) boxes.push({
137
- left,
138
- top,
139
- width,
140
- height
141
- });
142
- }
143
- return boxes;
144
- }
145
- /**
146
160
  * The host's box at another size than it has now, from where it is by its placement's alignment
147
161
  * (centred, or kept at its start or its end; against its side of the screen across it).
148
162
  */
@@ -175,11 +189,11 @@ function alignedBox(root, placement, vertical, rtl, { width, height }) {
175
189
  * then, or growing again (72 px wide, everything would seem to fit beside it): its size open, on a
176
190
  * copy, where it opens.
177
191
  */
178
- function openHost(root, placement, vertical, rtl) {
192
+ function openHost(root, placement, vertical, rtl, folded) {
179
193
  const host = alignedBox(root, placement, vertical, rtl, require_room.openSize(root));
180
194
  return vertical ? { host } : {
181
195
  host,
182
- hostMin: require_room.foldedWidth(root)
196
+ hostMin: folded ?? require_room.foldedWidth(root)
183
197
  };
184
198
  }
185
199
  function ElectronContent({ electron }) {
@@ -310,13 +324,25 @@ function SatellitesLayer({ host }) {
310
324
  const detached = host.actionsStyle === "detached";
311
325
  const turnPhase = (0, react.useRef)(null);
312
326
  const turnFrom = (0, react.useRef)(null);
313
- const actionsPresence = detached && actions && !tucked ? turnPhase.current ? "rest" : "compact" : "hidden";
327
+ const presences = (0, react.useRef)(/* @__PURE__ */ new Map());
328
+ const handoff = require_handoff.useHandoff(host.store);
329
+ const [style, setStyle] = (0, react.useState)(host.actionsStyle);
330
+ const [leavingPill, setLeavingPill] = (0, react.useState)(false);
331
+ const waits = style !== host.actionsStyle ? detached && style === "inside" && !!actions : leavingPill;
332
+ if (style !== host.actionsStyle) {
333
+ setStyle(host.actionsStyle);
334
+ setLeavingPill(waits);
335
+ }
336
+ (0, react.useEffect)(() => {
337
+ if (leavingPill) setLeavingPill(false);
338
+ }, [leavingPill]);
339
+ const actionsPresence = detached && actions && !tucked && !waits && handoff !== "out" ? turnPhase.current ? "rest" : "compact" : "hidden";
314
340
  const goingIn = (0, react.useRef)(false);
315
341
  const wasDetached = (0, react.useRef)(detached);
316
- if (wasDetached.current && !detached && actions) goingIn.current = true;
342
+ if (wasDetached.current && !detached && actions) goingIn.current = presences.current.get(ACTIONS) === "compact";
317
343
  if (detached) goingIn.current = false;
318
344
  wasDetached.current = detached;
319
- const shownActions = detached || goingIn.current ? actions ?? lastActions.current : null;
345
+ const shownActions = detached && !waits && handoff !== "out" || goingIn.current ? actions ?? lastActions.current : null;
320
346
  const atom = (0, react.useRef)(null);
321
347
  const [actionsAcross, setActionsAcross] = (0, react.useState)(false);
322
348
  const [wheelLength, setWheelLength] = (0, react.useState)(void 0);
@@ -332,19 +358,21 @@ function SatellitesLayer({ host }) {
332
358
  presence: presenceOf(entry)
333
359
  }));
334
360
  const elements = (0, react.useRef)(/* @__PURE__ */ new Map());
335
- const presences = (0, react.useRef)(/* @__PURE__ */ new Map());
336
361
  const applied = (0, react.useRef)({
337
362
  shift: 0,
338
363
  reserve: 0,
339
364
  vertical: false
340
365
  });
341
366
  const hostMin = (0, react.useRef)(void 0);
367
+ const hostOpen = (0, react.useRef)(void 0);
342
368
  const rows = (0, react.useRef)(/* @__PURE__ */ new Map());
343
369
  const spots = (0, react.useRef)(/* @__PURE__ */ new Map());
344
370
  const rejoining = (0, react.useRef)(/* @__PURE__ */ new Set());
345
371
  const splitNext = (0, react.useRef)(/* @__PURE__ */ new Set());
346
- const insideSpot = (0, react.useRef)(null);
372
+ const atomPlaced = (0, react.useRef)(null);
347
373
  const lastStyle = (0, react.useRef)(host.actionsStyle);
374
+ const foldingSince = (0, react.useRef)(void 0);
375
+ const tripHost = (0, react.useRef)(null);
348
376
  const arrange = (0, react.useRef)(() => {});
349
377
  arrange.current = (animate) => {
350
378
  const root = host.rootRef.current;
@@ -355,7 +383,10 @@ function SatellitesLayer({ host }) {
355
383
  const gap = require_measure.toPixels(style.getPropertyValue("--mp-electron-gap"), root, Number.parseFloat(style.columnGap) || 16);
356
384
  const offset = require_measure.toPixels(style.getPropertyValue("--_mp-offset"), root, 24);
357
385
  const out = entries.filter((entry) => entry.presence !== "hidden" && elements.current.get(entry.electron.id));
358
- if (animate && !vertical) hostMin.current = require_room.foldedWidth(root);
386
+ if (animate && !vertical) {
387
+ hostMin.current = require_room.foldedWidth(root);
388
+ hostOpen.current = require_room.unfoldedWidth(root);
389
+ }
359
390
  const atomElement = atom.current;
360
391
  const atomOut = actionsPresence !== "hidden" && atomElement;
361
392
  if (atomOut && (animate || !actionsBox.current)) actionsBox.current = alongBox(atomElement, vertical);
@@ -403,20 +434,46 @@ function SatellitesLayer({ host }) {
403
434
  arrange: host.arrange,
404
435
  gap,
405
436
  offset,
406
- obstacles: host.avoidPills ? otherPills(root) : void 0
437
+ obstacles: host.avoidPills ? require_measure.otherPills(root) : void 0
407
438
  };
408
- const layout = require_layout.planSatellites(input);
439
+ const rtl = style.direction === "rtl";
440
+ const open = hostOpen.current;
441
+ const least = hostMin.current;
442
+ const canFold = !vertical && open !== void 0 && least !== void 0 && least < open - .5;
443
+ const asOpen = canFold ? require_layout.planSatellites({
444
+ ...input,
445
+ host: alignedBox(root, placement, vertical, rtl, {
446
+ width: open,
447
+ height: root.offsetHeight
448
+ }),
449
+ hostMin: void 0
450
+ }) : void 0;
451
+ const asFolded = canFold ? require_layout.planSatellites({
452
+ ...input,
453
+ host: alignedBox(root, placement, vertical, rtl, {
454
+ width: least,
455
+ height: root.offsetHeight
456
+ })
457
+ }) : void 0;
458
+ const fitsOpen = !!asOpen && open + asOpen.reserve <= input.viewport.width - offset * 2 + .5 && asOpen.movedBeside.length <= asFolded.movedBeside.length && (!asOpen.actionsAcross || asFolded.actionsAcross) && (asOpen.actionsShown ?? 1e400) >= (asFolded.actionsShown ?? 1e400);
459
+ const layout = !canFold ? require_layout.planSatellites(input) : fitsOpen ? asOpen : asFolded;
409
460
  if (!tucked && afterTrip.current === "ending") afterTrip.current = false;
461
+ const tripInputs = `${placement} ${input.viewport.width}x${input.viewport.height}`;
462
+ if (afterTrip.current && (animate || tripHost.current?.inputs !== tripInputs)) tripHost.current = {
463
+ inputs: tripInputs,
464
+ value: openHost(root, placement, vertical, style.direction === "rtl", animate ? hostMin.current : void 0)
465
+ };
410
466
  const trip = afterTrip.current ? require_layout.planSatellites({
411
467
  ...input,
412
- ...openHost(root, placement, vertical, style.direction === "rtl"),
468
+ ...tripHost.current.value,
413
469
  electrons: sized(entries.filter((entry) => presenceOf(entry, false) !== "hidden" && elements.current.get(entry.electron.id))),
414
470
  actions: actionsInput(detached && !!actions && !!atomElement)
415
471
  }) : layout;
416
472
  if (animate && host.actionsStyle === "inside") {
417
473
  const track = root.querySelector("[data-mp=\"actions\"][data-inside]");
418
474
  if (track) {
419
- const length = host.actionsWheel ? insideWheelLength(track, root, vertical, mainRoom(vertical, offset) - layout.reserve, hostMin.current) : void 0;
475
+ const hostLength = hostOpen.current ?? (hostMin.current !== void 0 ? Math.min(root.offsetWidth, hostMin.current) : void 0);
476
+ const length = host.actionsWheel ? insideWheelLength(track, root, vertical, mainRoom(vertical, offset) - layout.reserve, hostLength, vertical ? void 0 : require_room.foldedWidth(root, { content: true })) : void 0;
420
477
  if (length === void 0) {
421
478
  track.removeAttribute("data-wheel");
422
479
  track.style.removeProperty("--_mp-wheel-length");
@@ -432,7 +489,15 @@ function SatellitesLayer({ host }) {
432
489
  const boxes = layout.boxes;
433
490
  const hostAlong = (vertical ? root.offsetTop : root.offsetLeft) + layout.shift + (vertical ? root.offsetHeight : root.offsetWidth) / 2;
434
491
  const alongOf = (box) => vertical ? box.top + box.height / 2 : box.left + box.width / 2;
435
- const spotOf = (box) => `${alongOf(box) < hostAlong ? "before" : "after"} ${Math.round(vertical ? box.left : box.top)}`;
492
+ const outer = placement.startsWith("bottom") || placement === "right";
493
+ const hostCross = vertical ? root.offsetLeft : root.offsetTop;
494
+ const hostThick = vertical ? root.offsetWidth : root.offsetHeight;
495
+ const rowOf = (box) => {
496
+ const start = vertical ? box.left : box.top;
497
+ const thick = vertical ? box.width : box.height;
498
+ return Math.round(outer ? hostCross + hostThick - (start + thick) : start - hostCross);
499
+ };
500
+ const spotOf = (box) => `${alongOf(box) < hostAlong ? "before" : "after"} ${rowOf(box)}`;
436
501
  const hostAt = () => ({
437
502
  left: root.offsetLeft + (vertical ? 0 : applied.current.shift),
438
503
  top: root.offsetTop + (vertical ? applied.current.shift : 0),
@@ -454,6 +519,7 @@ function SatellitesLayer({ host }) {
454
519
  };
455
520
  const was = vector(previous.shift, previous.vertical);
456
521
  const now = vector(trip.shift, vertical);
522
+ const hostSlide = vertical ? now.y - was.y : now.x - was.x;
457
523
  let slide;
458
524
  if (!settling && (Math.abs(was.x - now.x) > .5 || Math.abs(was.y - now.y) > .5)) {
459
525
  if (trip.shift) root.style.setProperty("translate", `${now.x}px ${now.y}px`);
@@ -474,14 +540,26 @@ function SatellitesLayer({ host }) {
474
540
  }
475
541
  const reserve = vertical ? 0 : trip.reserve;
476
542
  const room = root.style.getPropertyValue("--_mp-shift-x");
477
- if (!settling && reserve && room !== `${reserve}px`) root.style.setProperty("--_mp-shift-x", `${reserve}px`);
478
- else if (!settling && !reserve && previous.reserve && room === `${previous.reserve}px`) root.style.removeProperty("--_mp-shift-x");
479
- if (!settling) applied.current = {
480
- shift: trip.shift,
481
- reserve,
482
- vertical,
483
- placement
484
- };
543
+ if (!settling) {
544
+ if (reserve) root.style.setProperty(PLANNED_ROOM, `${reserve}px`);
545
+ else root.style.removeProperty(PLANNED_ROOM);
546
+ const folding = reserve > (Number.parseFloat(room) || 0) && layout === asFolded && (placement === "top" || placement === "bottom") && root.offsetWidth > input.viewport.width - offset * 2 - reserve + .5;
547
+ if (!folding) foldingSince.current = void 0;
548
+ else if (foldingSince.current === void 0) {
549
+ foldingSince.current = performance.now();
550
+ const wait = timings.change * 2;
551
+ setTimeout(() => arrange.current(false), wait + 20);
552
+ }
553
+ const waits = folding && performance.now() - foldingSince.current < timings.change * 2;
554
+ if (reserve && !waits && room !== `${reserve}px`) root.style.setProperty("--_mp-shift-x", `${reserve}px`);
555
+ else if (!reserve && previous.reserve && room === `${previous.reserve}px`) root.style.removeProperty("--_mp-shift-x");
556
+ applied.current = {
557
+ shift: trip.shift,
558
+ reserve,
559
+ vertical,
560
+ placement
561
+ };
562
+ }
485
563
  const rejoin = (id, element, then) => {
486
564
  rejoining.current.add(id);
487
565
  const { exit } = require_measure.durations(element);
@@ -492,18 +570,7 @@ function SatellitesLayer({ host }) {
492
570
  }, exit + 20);
493
571
  };
494
572
  const styleChanged = lastStyle.current !== host.actionsStyle;
495
- if (animate) {
496
- const track = host.actionsStyle === "inside" ? root.querySelector("[data-mp=\"actions\"][data-inside]") : null;
497
- if (track) {
498
- const hostLeft = root.offsetLeft + (vertical ? 0 : layout.shift);
499
- const hostTop = root.offsetTop + (vertical ? layout.shift : 0);
500
- insideSpot.current = {
501
- x: hostLeft + track.offsetLeft + track.offsetWidth / 2,
502
- y: hostTop + track.offsetTop + track.offsetHeight / 2
503
- };
504
- }
505
- lastStyle.current = host.actionsStyle;
506
- }
573
+ if (animate) lastStyle.current = host.actionsStyle;
507
574
  const slides = [];
508
575
  if (atomElement) {
509
576
  const was = presences.current.get(ACTIONS);
@@ -514,7 +581,7 @@ function SatellitesLayer({ host }) {
514
581
  if (animate && atomOut && was === "compact" && !settled && !sideChanged && !reduced && !rejoining.current.has(ACTIONS)) {
515
582
  const turnTo = layout.actionsAcross;
516
583
  const { fade, change } = require_measure.durations(atomElement);
517
- turnFrom.current = {
584
+ turnFrom.current = atomPlaced.current ?? {
518
585
  left: Number.parseFloat(atomElement.style.left),
519
586
  top: Number.parseFloat(atomElement.style.top),
520
587
  width: atomElement.offsetWidth,
@@ -562,11 +629,25 @@ function SatellitesLayer({ host }) {
562
629
  left: Number.parseFloat(atomElement.style.left),
563
630
  top: Number.parseFloat(atomElement.style.top)
564
631
  };
565
- const left = !vertical && before ? box.left + box.width - width : box.left;
566
- const top = vertical && before ? box.top + box.height - height : box.top;
632
+ const left = vertical ? placement === "right" ? box.left + box.width - width : box.left : before ? box.left + box.width - width : box.left;
633
+ const top = vertical ? before ? box.top + box.height - height : box.top : placement.startsWith("bottom") ? box.top + box.height - height : box.top;
567
634
  atomElement.style.left = `${left}px`;
568
635
  atomElement.style.top = `${top}px`;
569
636
  spots.current.set(ACTIONS, spotOf(box));
637
+ const placedLast = atomPlaced.current;
638
+ const facing = (at) => vertical ? before ? at.top + at.height : at.top : before ? at.left + at.width : at.left;
639
+ const withHost = !!placedLast && (Math.abs(placedLast.width - width) > .5 || Math.abs(placedLast.height - height) > .5) && Math.abs(facing({
640
+ left,
641
+ top,
642
+ width,
643
+ height
644
+ }) - facing(placedLast) - hostSlide) <= 1;
645
+ atomPlaced.current = {
646
+ left,
647
+ top,
648
+ width,
649
+ height
650
+ };
570
651
  if (turnPhase.current === "sliding") {} else if (animate && turnPhase.current === "turned") {
571
652
  turnPhase.current = null;
572
653
  if (moving && Number.isFinite(from.left) && Number.isFinite(from.top) && (Math.abs(from.left - left) > .5 || Math.abs(from.top - top) > .5)) {
@@ -583,12 +664,10 @@ function SatellitesLayer({ host }) {
583
664
  }, timings.change);
584
665
  } else refresh();
585
666
  } else if (animate && (was === void 0 || was === "hidden")) {
586
- const fromInside = styleChanged && insideSpot.current ? require_goo.atPoint(insideSpot.current.x, insideSpot.current.y, 1) : void 0;
587
667
  require_morph.cancel(atomElement, require_morph.MORPH, true);
588
668
  require_morph.cancel(atomElement, require_morph.MOVE);
589
- if (fromInside) bud(root, atomElement, "split", 0, require_measure.durations(atomElement).enter, fromInside, true);
590
- else drop(root, atomElement, "split", 0, require_measure.durations(atomElement).enter, hostAt, slide);
591
- } else if (moving && was === "compact" && Number.isFinite(from.left) && Number.isFinite(from.top) && Math.hypot(from.left - left, from.top - top) > gap) {
669
+ drop(root, atomElement, "split", 0, require_measure.durations(atomElement).enter, hostAt, slide);
670
+ } else if (moving && was === "compact" && !withHost && Number.isFinite(from.left) && Number.isFinite(from.top) && Math.hypot(from.left - left, from.top - top) > gap) {
592
671
  atomElement.style.left = `${from.left}px`;
593
672
  atomElement.style.top = `${from.top}px`;
594
673
  turnFrom.current = {
@@ -606,13 +685,40 @@ function SatellitesLayer({ host }) {
606
685
  }, fade + change + 20);
607
686
  refresh();
608
687
  } else if (moving && (was === "compact" || was === "rest") && Number.isFinite(from.left) && Number.isFinite(from.top)) {
609
- if (Math.abs(from.left - left) > .5 || Math.abs(from.top - top) > .5) {
688
+ if (withHost && placedLast) atomElement.animate([{
689
+ width: `${placedLast.width}px`,
690
+ height: `${placedLast.height}px`
691
+ }, {
692
+ width: `${width}px`,
693
+ height: `${height}px`
694
+ }], {
695
+ id: SHIFT,
696
+ duration: timings.change,
697
+ easing: "ease-in-out"
698
+ });
699
+ const along = withHost ? facing(placedLast) - facing({
700
+ left,
701
+ top,
702
+ width,
703
+ height
704
+ }) : 0;
705
+ const shift = withHost ? vertical ? {
706
+ x: 0,
707
+ y: along
708
+ } : {
709
+ x: along,
710
+ y: 0
711
+ } : {
712
+ x: from.left - left,
713
+ y: from.top - top
714
+ };
715
+ if (Math.abs(shift.x) > .5 || Math.abs(shift.y) > .5) {
610
716
  slides.push({
611
717
  element: atomElement,
612
- from: vertical ? from.top : from.left,
718
+ from: vertical ? top + shift.y : left + shift.x,
613
719
  to: vertical ? top : left
614
720
  });
615
- atomElement.animate([{ translate: `${from.left - left}px ${from.top - top}px` }, { translate: "0px 0px" }], {
721
+ atomElement.animate([{ translate: `${shift.x}px ${shift.y}px` }, { translate: "0px 0px" }], {
616
722
  id: SHIFT,
617
723
  duration: timings.change,
618
724
  easing: "ease-in-out",
@@ -622,22 +728,21 @@ function SatellitesLayer({ host }) {
622
728
  }
623
729
  } else if (animate && !atomOut && (was === "compact" || was === "rest")) {
624
730
  const { fade, exit } = require_measure.durations(atomElement);
625
- if (styleChanged && host.actionsStyle === "inside" && insideSpot.current) {
626
- require_morph.cancel(atomElement, require_morph.EXIT, true);
627
- for (const child of atomElement.children) child.style.opacity = "1";
628
- bud(root, atomElement, "join", 0, exit, require_goo.atPoint(insideSpot.current.x, insideSpot.current.y, 1), true);
731
+ if (styleChanged && host.actionsStyle === "inside" && goingIn.current) {
732
+ require_handoff.setHandoff(host.store, "in");
733
+ drop(root, atomElement, "join", fade, exit, hostAt);
629
734
  setTimeout(() => {
630
- for (const child of atomElement.children) child.style.removeProperty("opacity");
631
735
  goingIn.current = false;
736
+ require_handoff.setHandoff(host.store, void 0);
632
737
  refresh();
633
- }, exit + 20);
738
+ }, fade + exit + 20);
634
739
  } else if (tucked) bud(root, atomElement, "join", 0, Math.max(exit, fade + require_measure.durations(atomElement).change), hostCentre());
635
740
  else drop(root, atomElement, "join", fade, exit, hostAt);
636
741
  spots.current.delete(ACTIONS);
637
742
  }
638
743
  if (animate && !rejoining.current.has(ACTIONS) && !holding && (settled || !atomOut)) presences.current.set(ACTIONS, actionsPresence);
639
744
  }
640
- const crossOf = (box) => Math.round(vertical ? box.left : box.top);
745
+ const crossOf = rowOf;
641
746
  const hopping = /* @__PURE__ */ new Set();
642
747
  out.forEach(({ electron }, index) => {
643
748
  const element = elements.current.get(electron.id);
@@ -773,7 +878,7 @@ function SatellitesLayer({ host }) {
773
878
  spots.current.delete(entry.electron.id);
774
879
  if (ending === "pop") continue;
775
880
  const { fade, change, exit } = require_measure.durations(element);
776
- if (tucked && !entry.leaving) bud(root, element, "join", 0, Math.max(exit, fade + change), hostCentre());
881
+ if (tucked) bud(root, element, "join", 0, Math.max(exit, fade + change), hostCentre());
777
882
  else drop(root, element, "join", fade, exit, hostAt);
778
883
  }
779
884
  for (const entry of entries) presences.current.set(entry.electron.id, entry.presence);
@@ -787,7 +892,7 @@ function SatellitesLayer({ host }) {
787
892
  const follow = () => {
788
893
  arrange.current(false);
789
894
  clearTimeout(settle);
790
- settle = setTimeout(() => arrange.current(true), 200);
895
+ settle = setTimeout(() => arrange.current(true), SETTLED);
791
896
  };
792
897
  const observer = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(follow);
793
898
  observer?.observe(root);
@@ -810,6 +915,8 @@ function SatellitesLayer({ host }) {
810
915
  root.style.removeProperty("translate");
811
916
  const { reserve } = applied.current;
812
917
  if (reserve && root.style.getPropertyValue("--_mp-shift-x") === `${reserve}px`) root.style.removeProperty("--_mp-shift-x");
918
+ root.style.removeProperty(PLANNED_ROOM);
919
+ require_handoff.setHandoff(host.store, void 0);
813
920
  applied.current = {
814
921
  shift: 0,
815
922
  reserve: 0,
@@ -862,7 +969,10 @@ function SatellitesLayer({ host }) {
862
969
  presence,
863
970
  "data-satellite": "electron",
864
971
  "data-ending": leaving && ending === "pop" ? "pop" : void 0,
865
- style: ELECTRON_STYLE,
972
+ style: host.tokens ? {
973
+ ...host.tokens,
974
+ ...ELECTRON_STYLE
975
+ } : ELECTRON_STYLE,
866
976
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ElectronBody, {
867
977
  electron,
868
978
  host
@@ -878,11 +988,13 @@ function SatellitesLayer({ host }) {
878
988
  variant: host.variant,
879
989
  orientation: host.vertical !== actionsAcross ? "vertical" : "horizontal",
880
990
  presence: actionsPresence,
881
- scene: shownActions.map((item) => item.id ?? item.label).join("\n"),
882
991
  role: "group",
883
992
  "aria-label": host.actionsLabel,
884
993
  "data-satellite": "actions",
885
- style: ELECTRON_STYLE,
994
+ style: host.tokens ? {
995
+ ...host.tokens,
996
+ ...ELECTRON_STYLE
997
+ } : ELECTRON_STYLE,
886
998
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Actions.ActionList, {
887
999
  items: shownActions,
888
1000
  host,
@@ -906,4 +1018,5 @@ function SatellitesLayer({ host }) {
906
1018
  ] });
907
1019
  }
908
1020
 
909
- exports.SatellitesLayer = SatellitesLayer;
1021
+ exports.SatellitesLayer = SatellitesLayer;
1022
+ exports.drop = drop;