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

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.
@@ -2,11 +2,11 @@
2
2
 
3
3
  import { useEffect, useReducer, useRef, useState, useSyncExternalStore } from "react";
4
4
  import Pill from "../Pill/Pill.mjs";
5
- import { atEdgeOf, atPoint, playNecks, playOrbit } from "../Pill/goo.mjs";
5
+ import { DROPLET, SPLIT, atEdgeOf, atPoint, playNecks, playOrbit } from "../Pill/goo.mjs";
6
6
  import { EXIT, MORPH, MOVE, cancel } from "../Pill/morph.mjs";
7
7
  import { PillProgress } from "../Pill/PillProgress.mjs";
8
8
  import { findActiveIndex } from "../PillNavbar/matchPath.mjs";
9
- import { foldedWidth } from "../PillNavbar/room.mjs";
9
+ import { foldedWidth, openSize } from "../PillNavbar/room.mjs";
10
10
  import { NO_ELECTRONS } from "../store/store.mjs";
11
11
  import { useIsomorphicLayoutEffect } from "../utils/react.mjs";
12
12
  import { prefersReducedMotion } from "../utils/timing.mjs";
@@ -30,11 +30,12 @@ const SIDE_PLACEMENTS = /* @__PURE__ */ new Set(["left", "right"]);
30
30
  /**
31
31
  * The page's actions' box along the pill, whichever way their pill runs now
32
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).
33
+ * open, with all of them (not cut short by a wheel).
34
34
  */
35
35
  function alongBox(atom, vertical) {
36
36
  const copy = atom.cloneNode(true);
37
37
  copy.setAttribute("data-orientation", vertical ? "vertical" : "horizontal");
38
+ if (copy.dataset.presence === "rest") copy.dataset.presence = "compact";
38
39
  copy.removeAttribute("id");
39
40
  copy.inert = true;
40
41
  copy.style.visibility = "hidden";
@@ -54,6 +55,7 @@ function alongBox(atom, vertical) {
54
55
  return {
55
56
  width,
56
57
  height,
58
+ vertical,
57
59
  wheel: {
58
60
  count: actions.length,
59
61
  first: length - Math.max(0, actions.length - 1) * step,
@@ -66,12 +68,34 @@ function alongBox(atom, vertical) {
66
68
  * Out of the anchor (or back into it) with the goo, drawing itself the whole
67
69
  * way, as the orbitals do: from inside it at its nearest edge by default.
68
70
  */
71
+ /** Out of the anchor from a point inside it, or back into it there (seen the whole way: `opaque`). */
69
72
  const bud = (anchor, element, kind, delay, duration, from, opaque = false) => playOrbit(anchor, [{
70
73
  element,
71
74
  delay,
72
- from: from ?? atEdgeOf(anchor),
75
+ from,
73
76
  opaque
74
77
  }], kind === "split" ? "open" : "close", { duration });
78
+ /**
79
+ * Out of the anchor's edge as a droplet, growing to its size and then showing its content, or back
80
+ * into it the same way played backwards. `at`: where the anchor is going, if it's moving; `slide`:
81
+ * how it gets there, which a droplet coming out follows while it's still attached (from its edge
82
+ * where it is to its edge where it goes), or it would come out where the anchor no longer is.
83
+ */
84
+ function drop(anchor, element, kind, delay, duration, at, slide) {
85
+ const stop = playOrbit(anchor, [{
86
+ element,
87
+ delay,
88
+ from: atEdgeOf(anchor, at, DROPLET),
89
+ droplet: true
90
+ }], kind === "split" ? "open" : "close", { duration });
91
+ if (slide && kind === "split" && !prefersReducedMotion() && typeof element.animate === "function") element.animate([{ translate: `${slide.x}px ${slide.y}px` }, { translate: "0px 0px" }], {
92
+ id: SPLIT,
93
+ duration: slide.duration,
94
+ easing: "ease-in-out",
95
+ composite: "add"
96
+ });
97
+ return stop;
98
+ }
75
99
  /** The screen's length along the host's edge, less its offsets. */
76
100
  const mainRoom = (vertical, offset) => (vertical ? window.innerHeight : document.documentElement.clientWidth || window.innerWidth) - offset * 2;
77
101
  /**
@@ -98,6 +122,66 @@ const nextTo = (a, b, gap) => {
98
122
  return sideBySide || stacked;
99
123
  };
100
124
  /** What an electron shows: the ring and its value or icon, the value alone, or the app's own. */
125
+ /**
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
+ * The host's box at another size than it has now, from where it is by its placement's alignment
147
+ * (centred, or kept at its start or its end; against its side of the screen across it).
148
+ */
149
+ function alignedBox(root, placement, vertical, rtl, { width, height }) {
150
+ const box = {
151
+ left: root.offsetLeft,
152
+ top: root.offsetTop,
153
+ width: root.offsetWidth,
154
+ height: root.offsetHeight
155
+ };
156
+ const along = (start, size, open, align) => align === "start" ? start : align === "end" ? start + size - open : start + size / 2 - open / 2;
157
+ if (vertical) return {
158
+ left: placement === "right" ? box.left + box.width - width : box.left,
159
+ top: along(box.top, box.height, height, "centre"),
160
+ width,
161
+ height
162
+ };
163
+ const edge = placement.endsWith("-start") ? "start" : placement.endsWith("-end") ? "end" : "centre";
164
+ const aligned = edge === "centre" ? edge : edge === "end" !== rtl ? "end" : "start";
165
+ const top = placement.startsWith("bottom") ? box.top + box.height - height : box.top;
166
+ return {
167
+ left: along(box.left, box.width, width, aligned),
168
+ top,
169
+ width,
170
+ height
171
+ };
172
+ }
173
+ /**
174
+ * The host as it will be open, for the satellites' plan on its way to another placement: a circle
175
+ * then, or growing again (72 px wide, everything would seem to fit beside it): its size open, on a
176
+ * copy, where it opens.
177
+ */
178
+ function openHost(root, placement, vertical, rtl) {
179
+ const host = alignedBox(root, placement, vertical, rtl, openSize(root));
180
+ return vertical ? { host } : {
181
+ host,
182
+ hostMin: foldedWidth(root)
183
+ };
184
+ }
101
185
  function ElectronContent({ electron }) {
102
186
  const { input } = electron;
103
187
  if (input.render) return input.render();
@@ -154,11 +238,13 @@ function SatellitesLayer({ host }) {
154
238
  leaving: true
155
239
  });
156
240
  const [travelling, setTravelling] = useState(false);
241
+ const afterTrip = useRef(false);
157
242
  const spot = `${host.placement} ${host.vertical}`;
158
243
  const lastSpot = useRef(spot);
159
244
  useIsomorphicLayoutEffect(() => {
160
245
  if (lastSpot.current === spot) return;
161
246
  lastSpot.current = spot;
247
+ afterTrip.current = "trip";
162
248
  setTravelling(true);
163
249
  }, [spot]);
164
250
  useEffect(() => {
@@ -180,6 +266,20 @@ function SatellitesLayer({ host }) {
180
266
  clearTimeout(fallback);
181
267
  };
182
268
  }, [travelling, host.rootRef]);
269
+ const shownPlacement = (root) => root.dataset.placement ?? host.placement;
270
+ const [placement, setPlacement] = useState(host.placement);
271
+ useIsomorphicLayoutEffect(() => {
272
+ const root = host.rootRef.current;
273
+ if (!root) return;
274
+ const read = () => setPlacement(shownPlacement(root));
275
+ read();
276
+ const watch = new MutationObserver(read);
277
+ watch.observe(root, {
278
+ attributes: true,
279
+ attributeFilter: ["data-placement"]
280
+ });
281
+ return () => watch.disconnect();
282
+ }, [host.rootRef, host.placement]);
183
283
  const wanted = host.notifying && !host.keepElectronsOut || travelling;
184
284
  const wasTucked = useRef(wanted);
185
285
  const holding = useRef(false);
@@ -190,6 +290,7 @@ function SatellitesLayer({ host }) {
190
290
  if (wanted || !holding.current) return;
191
291
  const release = () => {
192
292
  holding.current = false;
293
+ if (afterTrip.current) afterTrip.current = "ending";
193
294
  refresh();
194
295
  };
195
296
  const morphs = (root?.getAnimations?.() ?? []).filter((animation) => animation.id === MORPH);
@@ -207,7 +308,9 @@ function SatellitesLayer({ host }) {
207
308
  const lastActions = useRef(null);
208
309
  if (actions) lastActions.current = actions;
209
310
  const detached = host.actionsStyle === "detached";
210
- const actionsPresence = detached && actions && !tucked ? "compact" : "hidden";
311
+ const turnPhase = useRef(null);
312
+ const turnFrom = useRef(null);
313
+ const actionsPresence = detached && actions && !tucked ? turnPhase.current ? "rest" : "compact" : "hidden";
211
314
  const goingIn = useRef(false);
212
315
  const wasDetached = useRef(detached);
213
316
  if (wasDetached.current && !detached && actions) goingIn.current = true;
@@ -220,8 +323,8 @@ function SatellitesLayer({ host }) {
220
323
  const actionsBox = useRef(null);
221
324
  const across = useRef(actionsAcross);
222
325
  across.current = actionsAcross;
223
- const presenceOf = ({ electron, leaving }) => {
224
- if (leaving || tucked) return "hidden";
326
+ const presenceOf = ({ electron, leaving }, tuck = tucked) => {
327
+ if (leaving || tuck) return "hidden";
225
328
  return electron.input.hideOnOrigin !== false && electron.origin !== void 0 && findActiveIndex(host.pathname, [{ href: electron.origin }]) === 0 ? "hidden" : "compact";
226
329
  };
227
330
  const entries = [...shown.current.values()].map((entry) => ({
@@ -232,7 +335,8 @@ function SatellitesLayer({ host }) {
232
335
  const presences = useRef(/* @__PURE__ */ new Map());
233
336
  const applied = useRef({
234
337
  shift: 0,
235
- reserve: 0
338
+ reserve: 0,
339
+ vertical: false
236
340
  });
237
341
  const hostMin = useRef(void 0);
238
342
  const rows = useRef(/* @__PURE__ */ new Map());
@@ -245,7 +349,8 @@ function SatellitesLayer({ host }) {
245
349
  arrange.current = (animate) => {
246
350
  const root = host.rootRef.current;
247
351
  if (!root) return;
248
- const vertical = SIDE_PLACEMENTS.has(host.placement);
352
+ const placement = shownPlacement(root);
353
+ const vertical = SIDE_PLACEMENTS.has(placement);
249
354
  const style = getComputedStyle(root);
250
355
  const gap = toPixels(style.getPropertyValue("--mp-electron-gap"), root, Number.parseFloat(style.columnGap) || 16);
251
356
  const offset = toPixels(style.getPropertyValue("--_mp-offset"), root, 24);
@@ -255,43 +360,59 @@ function SatellitesLayer({ host }) {
255
360
  const atomOut = actionsPresence !== "hidden" && atomElement;
256
361
  if (atomOut && (animate || !actionsBox.current)) actionsBox.current = alongBox(atomElement, vertical);
257
362
  const turn = host.actionsOrientation === "auto" ? "auto" : host.actionsOrientation === "vertical" === vertical ? "along" : "across";
258
- const layout = planSatellites({
363
+ const sized = (list) => list.map(({ electron }) => {
364
+ const element = elements.current.get(electron.id);
365
+ return {
366
+ id: electron.id,
367
+ width: element.offsetWidth || 72,
368
+ height: element.offsetHeight || 72
369
+ };
370
+ });
371
+ const otherAxis = !!actionsBox.current && actionsBox.current.vertical !== vertical;
372
+ const actionsInput = (shown) => shown && actionsBox.current ? {
373
+ width: otherAxis ? actionsBox.current.height : actionsBox.current.width,
374
+ height: otherAxis ? actionsBox.current.width : actionsBox.current.height,
375
+ side: host.actionsSide,
376
+ turn,
377
+ ...host.actionsWheel ? { wheel: actionsBox.current.wheel } : {}
378
+ } : void 0;
379
+ const squeezed = !vertical && hostMin.current !== void 0 && root.offsetWidth < hostMin.current - .5;
380
+ const input = {
259
381
  viewport: {
260
382
  width: document.documentElement.clientWidth || window.innerWidth,
261
383
  height: window.innerHeight
262
384
  },
263
- host: {
385
+ host: squeezed ? alignedBox(root, placement, vertical, style.direction === "rtl", {
386
+ width: hostMin.current,
387
+ height: root.offsetHeight
388
+ }) : {
264
389
  left: root.offsetLeft,
265
390
  top: root.offsetTop,
266
391
  width: root.offsetWidth,
267
392
  height: root.offsetHeight
268
393
  },
269
394
  hostMin: vertical ? void 0 : hostMin.current,
270
- placement: host.placement,
395
+ placement,
271
396
  vertical,
272
397
  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,
398
+ electrons: sized(out),
399
+ actions: actionsInput(!!atomOut),
288
400
  nearest: host.nearestToPill,
289
401
  side: host.electronSide,
290
402
  line: host.electronLine,
291
403
  arrange: host.arrange,
292
404
  gap,
293
- offset
294
- });
405
+ offset,
406
+ obstacles: host.avoidPills ? otherPills(root) : void 0
407
+ };
408
+ const layout = planSatellites(input);
409
+ if (!tucked && afterTrip.current === "ending") afterTrip.current = false;
410
+ const trip = afterTrip.current ? planSatellites({
411
+ ...input,
412
+ ...openHost(root, placement, vertical, style.direction === "rtl"),
413
+ electrons: sized(entries.filter((entry) => presenceOf(entry, false) !== "hidden" && elements.current.get(entry.electron.id))),
414
+ actions: actionsInput(detached && !!actions && !!atomElement)
415
+ }) : layout;
295
416
  if (animate && host.actionsStyle === "inside") {
296
417
  const track = root.querySelector("[data-mp=\"actions\"][data-inside]");
297
418
  if (track) {
@@ -312,34 +433,59 @@ function SatellitesLayer({ host }) {
312
433
  const hostAlong = (vertical ? root.offsetTop : root.offsetLeft) + layout.shift + (vertical ? root.offsetHeight : root.offsetWidth) / 2;
313
434
  const alongOf = (box) => vertical ? box.top + box.height / 2 : box.left + box.width / 2;
314
435
  const spotOf = (box) => `${alongOf(box) < hostAlong ? "before" : "after"} ${Math.round(vertical ? box.left : box.top)}`;
436
+ const hostAt = () => ({
437
+ left: root.offsetLeft + (vertical ? 0 : applied.current.shift),
438
+ top: root.offsetTop + (vertical ? applied.current.shift : 0),
439
+ width: root.offsetWidth,
440
+ height: root.offsetHeight
441
+ });
315
442
  const hostCentre = () => vertical ? atPoint(root.offsetLeft + root.offsetWidth / 2, hostAlong) : atPoint(hostAlong, root.offsetTop + root.offsetHeight / 2);
316
443
  const changing = (id, box) => !!box && presences.current.get(id) === "compact" && spots.current.has(id) && spots.current.get(id) !== spotOf(box);
317
444
  const turning = !!atomElement && !!atomOut && layout.actionsAcross !== across.current && presences.current.get(ACTIONS) === "compact";
318
445
  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
446
  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));
447
+ const settling = holding || !animate && previous.placement !== void 0 && previous.placement !== placement;
448
+ const vector = (shift, onSide) => onSide ? {
449
+ x: 0,
450
+ y: shift
451
+ } : {
452
+ x: shift,
453
+ y: 0
454
+ };
455
+ const was = vector(previous.shift, previous.vertical);
456
+ const now = vector(trip.shift, vertical);
457
+ let slide;
458
+ if (!settling && (Math.abs(was.x - now.x) > .5 || Math.abs(was.y - now.y) > .5)) {
459
+ if (trip.shift) root.style.setProperty("translate", `${now.x}px ${now.y}px`);
323
460
  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");
461
+ if (moving) {
462
+ slide = {
463
+ x: was.x - now.x,
464
+ y: was.y - now.y,
465
+ duration: timings.change
466
+ };
467
+ root.animate([{ translate: `${was.x - now.x}px ${was.y - now.y}px` }, { translate: "0px 0px" }], {
468
+ id: SHIFT,
469
+ duration: timings.change,
470
+ easing: "ease-in-out",
471
+ composite: "add"
472
+ });
473
+ }
334
474
  }
335
- if (!holding) applied.current = {
336
- shift: layout.shift,
337
- reserve: layout.reserve
475
+ const reserve = vertical ? 0 : trip.reserve;
476
+ 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
338
484
  };
339
485
  const rejoin = (id, element, then) => {
340
486
  rejoining.current.add(id);
341
487
  const { exit } = durations(element);
342
- bud(root, element, "join", 0, exit);
488
+ drop(root, element, "join", 0, exit);
343
489
  setTimeout(() => {
344
490
  rejoining.current.delete(id);
345
491
  then();
@@ -364,7 +510,28 @@ function SatellitesLayer({ host }) {
364
510
  const box = boxes.actions;
365
511
  const settled = layout.actionsAcross === across.current;
366
512
  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)) {
513
+ const sideChanged = moved && spots.current.get(ACTIONS).split(" ")[0] !== spotOf(box).split(" ")[0];
514
+ if (animate && atomOut && was === "compact" && !settled && !sideChanged && !reduced && !rejoining.current.has(ACTIONS)) {
515
+ const turnTo = layout.actionsAcross;
516
+ const { fade, change } = durations(atomElement);
517
+ turnFrom.current = {
518
+ left: Number.parseFloat(atomElement.style.left),
519
+ top: Number.parseFloat(atomElement.style.top),
520
+ width: atomElement.offsetWidth,
521
+ height: atomElement.offsetHeight
522
+ };
523
+ turnPhase.current = "closing";
524
+ rejoining.current.add(ACTIONS);
525
+ refresh();
526
+ setTimeout(() => {
527
+ rejoining.current.delete(ACTIONS);
528
+ spots.current.delete(ACTIONS);
529
+ turnFrom.current = null;
530
+ turnPhase.current = "turned";
531
+ setActionsAcross(turnTo);
532
+ refresh();
533
+ }, fade + change + 20);
534
+ } else if (animate && atomOut && was === "compact" && (!settled || moved) && !reduced && !rejoining.current.has(ACTIONS)) {
368
535
  const turnTo = layout.actionsAcross;
369
536
  rejoin(ACTIONS, atomElement, () => {
370
537
  presences.current.set(ACTIONS, "hidden");
@@ -373,12 +540,21 @@ function SatellitesLayer({ host }) {
373
540
  refresh();
374
541
  });
375
542
  } else if (animate && atomOut && !settled && !rejoining.current.has(ACTIONS)) setActionsAcross(layout.actionsAcross);
543
+ const from = turnFrom.current;
544
+ if (turnPhase.current === "closing" && from) {
545
+ const width = atomElement.offsetWidth;
546
+ const height = atomElement.offsetHeight;
547
+ const left = vertical ? placement === "right" ? from.left + from.width - width : from.left : from.left + from.width / 2 - width / 2;
548
+ const top = vertical ? from.top + from.height / 2 - height / 2 : placement.startsWith("bottom") ? from.top + from.height - height : from.top;
549
+ atomElement.style.left = `${left}px`;
550
+ atomElement.style.top = `${top}px`;
551
+ }
376
552
  if (animate && atomOut && actionsBox.current) {
377
553
  const { wheel } = actionsBox.current;
378
554
  const length = layout.actionsShown !== void 0 ? wheel.action + (layout.actionsShown - 1) * wheel.step : void 0;
379
555
  if (length !== wheelLength) setWheelLength(length);
380
556
  }
381
- if (box && atomOut && settled && !rejoining.current.has(ACTIONS) && !holding) {
557
+ if (box && atomOut && settled && !rejoining.current.has(ACTIONS) && !holding && (animate || !moved) && turnPhase.current !== "closing") {
382
558
  const before = alongOf(box) < hostAlong;
383
559
  const width = atomElement.offsetWidth || box.width;
384
560
  const height = atomElement.offsetHeight || box.height;
@@ -391,12 +567,45 @@ function SatellitesLayer({ host }) {
391
567
  atomElement.style.left = `${left}px`;
392
568
  atomElement.style.top = `${top}px`;
393
569
  spots.current.set(ACTIONS, spotOf(box));
394
- if (animate && was !== "compact") {
570
+ if (turnPhase.current === "sliding") {} else if (animate && turnPhase.current === "turned") {
571
+ turnPhase.current = null;
572
+ if (moving && Number.isFinite(from.left) && Number.isFinite(from.top) && (Math.abs(from.left - left) > .5 || Math.abs(from.top - top) > .5)) {
573
+ atomElement.animate([{ translate: `${from.left - left}px ${from.top - top}px` }, { translate: "0px 0px" }], {
574
+ id: SHIFT,
575
+ duration: timings.change,
576
+ easing: "ease-in-out",
577
+ composite: "add"
578
+ });
579
+ turnPhase.current = "sliding";
580
+ setTimeout(() => {
581
+ turnPhase.current = null;
582
+ refresh();
583
+ }, timings.change);
584
+ } else refresh();
585
+ } else if (animate && (was === void 0 || was === "hidden")) {
395
586
  const fromInside = styleChanged && insideSpot.current ? atPoint(insideSpot.current.x, insideSpot.current.y, 1) : void 0;
396
587
  cancel(atomElement, MORPH, true);
397
588
  cancel(atomElement, MOVE);
398
- bud(root, atomElement, "split", 0, durations(atomElement).enter, fromInside, !!fromInside);
399
- } else if (moving && was === "compact" && Number.isFinite(from.left) && Number.isFinite(from.top)) {
589
+ if (fromInside) bud(root, atomElement, "split", 0, durations(atomElement).enter, fromInside, true);
590
+ else drop(root, atomElement, "split", 0, 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) {
592
+ atomElement.style.left = `${from.left}px`;
593
+ atomElement.style.top = `${from.top}px`;
594
+ turnFrom.current = {
595
+ left: from.left,
596
+ top: from.top,
597
+ width,
598
+ height
599
+ };
600
+ turnPhase.current = "closing";
601
+ const { fade, change } = durations(atomElement);
602
+ setTimeout(() => {
603
+ turnFrom.current = null;
604
+ turnPhase.current = "turned";
605
+ refresh();
606
+ }, fade + change + 20);
607
+ refresh();
608
+ } else if (moving && (was === "compact" || was === "rest") && Number.isFinite(from.left) && Number.isFinite(from.top)) {
400
609
  if (Math.abs(from.left - left) > .5 || Math.abs(from.top - top) > .5) {
401
610
  slides.push({
402
611
  element: atomElement,
@@ -411,7 +620,7 @@ function SatellitesLayer({ host }) {
411
620
  });
412
621
  }
413
622
  }
414
- } else if (animate && !atomOut && was === "compact") {
623
+ } else if (animate && !atomOut && (was === "compact" || was === "rest")) {
415
624
  const { fade, exit } = durations(atomElement);
416
625
  if (styleChanged && host.actionsStyle === "inside" && insideSpot.current) {
417
626
  cancel(atomElement, EXIT, true);
@@ -423,12 +632,13 @@ function SatellitesLayer({ host }) {
423
632
  refresh();
424
633
  }, exit + 20);
425
634
  } else if (tucked) bud(root, atomElement, "join", 0, Math.max(exit, fade + durations(atomElement).change), hostCentre());
426
- else bud(root, atomElement, "join", fade, exit);
635
+ else drop(root, atomElement, "join", fade, exit, hostAt);
427
636
  spots.current.delete(ACTIONS);
428
637
  }
429
638
  if (animate && !rejoining.current.has(ACTIONS) && !holding && (settled || !atomOut)) presences.current.set(ACTIONS, actionsPresence);
430
639
  }
431
640
  const crossOf = (box) => Math.round(vertical ? box.left : box.top);
641
+ const hopping = /* @__PURE__ */ new Set();
432
642
  out.forEach(({ electron }, index) => {
433
643
  const element = elements.current.get(electron.id);
434
644
  const box = boxes[electron.id];
@@ -438,7 +648,7 @@ function SatellitesLayer({ host }) {
438
648
  element.style.left = `${box.left}px`;
439
649
  element.style.top = `${box.top}px`;
440
650
  rows.current.set(electron.id, String(crossOf(box)));
441
- bud(root, element, "split", 0, durations(element).enter);
651
+ drop(root, element, "split", 0, durations(element).enter, hostAt, slide);
442
652
  return;
443
653
  }
444
654
  const moved = was === "compact" && spots.current.has(electron.id) && spots.current.get(electron.id) !== spotOf(box);
@@ -450,7 +660,7 @@ function SatellitesLayer({ host }) {
450
660
  });
451
661
  return;
452
662
  }
453
- if (holding) return;
663
+ if (holding || moved && !animate) return;
454
664
  spots.current.set(electron.id, spotOf(box));
455
665
  const from = {
456
666
  left: Number.parseFloat(element.style.left),
@@ -474,8 +684,65 @@ function SatellitesLayer({ host }) {
474
684
  if (was === void 0 || was === "hidden") {
475
685
  const before = out[index - 1];
476
686
  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, durations(element).enter);
687
+ const anchor = neighbour && before && !hopping.has(before.electron.id) && nextTo(boxes[before.electron.id], box, gap) ? neighbour : root;
688
+ if (anchor === root) drop(root, element, "split", 0, durations(element).enter, hostAt, slide);
689
+ else drop(anchor, element, "split", 0, durations(element).enter);
690
+ } else if (moving && placed && Math.hypot(from.left - box.left, from.top - box.top) > gap && !reduced) {
691
+ hopping.add(electron.id);
692
+ const { fade, change } = durations(element);
693
+ const options = {
694
+ id: SHIFT,
695
+ duration: fade * 2 + change
696
+ };
697
+ const at = `${from.left - box.left}px ${from.top - box.top}px`;
698
+ element.animate([
699
+ {
700
+ translate: at,
701
+ easing: "ease-in-out"
702
+ },
703
+ {
704
+ translate: at,
705
+ offset: .3,
706
+ easing: "ease-in-out"
707
+ },
708
+ {
709
+ translate: "0px 0px",
710
+ offset: .7
711
+ },
712
+ { translate: "0px 0px" }
713
+ ], {
714
+ ...options,
715
+ composite: "add"
716
+ });
717
+ element.animate([
718
+ {
719
+ scale: 1,
720
+ easing: "ease-in"
721
+ },
722
+ {
723
+ scale: DROPLET * 2,
724
+ offset: .3
725
+ },
726
+ {
727
+ scale: DROPLET * 2,
728
+ offset: .7,
729
+ easing: "ease-out"
730
+ },
731
+ { scale: 1 }
732
+ ], options);
733
+ const content = [
734
+ { opacity: 1 },
735
+ {
736
+ opacity: 0,
737
+ offset: .2
738
+ },
739
+ {
740
+ opacity: 0,
741
+ offset: .8
742
+ },
743
+ { opacity: 1 }
744
+ ];
745
+ for (const child of element.children) child.animate(content, options);
479
746
  } else if (moving && placed && (Math.abs(from.left - box.left) > .5 || Math.abs(from.top - box.top) > .5)) {
480
747
  slides.push({
481
748
  element,
@@ -507,7 +774,7 @@ function SatellitesLayer({ host }) {
507
774
  if (ending === "pop") continue;
508
775
  const { fade, change, exit } = durations(element);
509
776
  if (tucked && !entry.leaving) bud(root, element, "join", 0, Math.max(exit, fade + change), hostCentre());
510
- else bud(root, element, "join", fade, exit);
777
+ else drop(root, element, "join", fade, exit, hostAt);
511
778
  }
512
779
  for (const entry of entries) presences.current.set(entry.electron.id, entry.presence);
513
780
  }
@@ -530,18 +797,26 @@ function SatellitesLayer({ host }) {
530
797
  clearTimeout(settle);
531
798
  observer?.disconnect();
532
799
  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
800
  };
540
801
  }, [
541
802
  host.rootRef,
542
- host.placement,
803
+ placement,
543
804
  !!shownActions
544
805
  ]);
806
+ useEffect(() => {
807
+ const root = host.rootRef.current;
808
+ return () => {
809
+ if (!root) return;
810
+ root.style.removeProperty("translate");
811
+ const { reserve } = applied.current;
812
+ if (reserve && root.style.getPropertyValue("--_mp-shift-x") === `${reserve}px`) root.style.removeProperty("--_mp-shift-x");
813
+ applied.current = {
814
+ shift: 0,
815
+ reserve: 0,
816
+ vertical: false
817
+ };
818
+ };
819
+ }, [host.rootRef]);
545
820
  const leavingIds = entries.filter((entry) => entry.leaving).map((entry) => entry.electron.id);
546
821
  useEffect(() => {
547
822
  if (leavingIds.length === 0) return;