magic-pill 9.4.0-next.1 → 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.
- package/CHANGELOG.md +17 -0
- package/dist/MagicPill/MagicPill.d.mts +9 -1
- package/dist/MagicPill/MagicPill.d.ts +9 -1
- package/dist/MagicPill/MagicPill.js +3 -1
- package/dist/MagicPill/MagicPill.mjs +3 -1
- package/dist/Pill/goo.js +238 -15
- package/dist/Pill/goo.mjs +235 -16
- package/dist/Pill/morph.js +8 -3
- package/dist/Pill/morph.mjs +7 -4
- package/dist/satellites/Actions.js +138 -16
- package/dist/satellites/Actions.mjs +139 -18
- package/dist/satellites/Orbitals.js +76 -45
- package/dist/satellites/Orbitals.mjs +77 -46
- package/dist/satellites/Satellites.js +284 -50
- package/dist/satellites/Satellites.mjs +285 -51
- package/dist/satellites/layout.js +83 -30
- package/dist/satellites/layout.mjs +83 -30
- package/dist/satellites/types.d.mts +4 -0
- package/dist/satellites/types.d.ts +4 -0
- package/dist/satellites.d.mts +2 -2
- package/dist/satellites.d.ts +2 -2
- package/dist/store/store.js +1 -1
- package/dist/store/store.mjs +1 -1
- package/dist/styles.css +170 -17
- package/package.json +1 -1
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
|
4
4
|
import Pill from "../Pill/Pill.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { atEdgeOf, atPoint, playNecks, playOrbit } from "../Pill/goo.mjs";
|
|
6
|
+
import { EXIT, MORPH, MOVE, cancel } from "../Pill/morph.mjs";
|
|
6
7
|
import { PillProgress } from "../Pill/PillProgress.mjs";
|
|
7
8
|
import { findActiveIndex } from "../PillNavbar/matchPath.mjs";
|
|
8
9
|
import { foldedWidth } from "../PillNavbar/room.mjs";
|
|
@@ -28,7 +29,8 @@ const ACTIONS = "\0actions";
|
|
|
28
29
|
const SIDE_PLACEMENTS = /* @__PURE__ */ new Set(["left", "right"]);
|
|
29
30
|
/**
|
|
30
31
|
* The page's actions' box along the pill, whichever way their pill runs now
|
|
31
|
-
* and even while its size animates: laid out on a hidden copy, turned along
|
|
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).
|
|
32
34
|
*/
|
|
33
35
|
function alongBox(atom, vertical) {
|
|
34
36
|
const copy = atom.cloneNode(true);
|
|
@@ -39,13 +41,55 @@ function alongBox(atom, vertical) {
|
|
|
39
41
|
copy.style.pointerEvents = "none";
|
|
40
42
|
copy.style.translate = "none";
|
|
41
43
|
copy.style.scale = "none";
|
|
44
|
+
copy.querySelector("[data-mp=\"actions\"]")?.removeAttribute("data-wheel");
|
|
42
45
|
atom.after(copy);
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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;
|
|
47
53
|
copy.remove();
|
|
48
|
-
return
|
|
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) => playOrbit(anchor, [{
|
|
70
|
+
element,
|
|
71
|
+
delay,
|
|
72
|
+
from: from ?? 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;
|
|
49
93
|
}
|
|
50
94
|
/** Two boxes side by side, a gap apart: the second can come out of the first. */
|
|
51
95
|
const nextTo = (a, b, gap) => {
|
|
@@ -109,15 +153,70 @@ function SatellitesLayer({ host }) {
|
|
|
109
153
|
...entry,
|
|
110
154
|
leaving: true
|
|
111
155
|
});
|
|
112
|
-
const
|
|
156
|
+
const [travelling, setTravelling] = useState(false);
|
|
157
|
+
const spot = `${host.placement} ${host.vertical}`;
|
|
158
|
+
const lastSpot = useRef(spot);
|
|
159
|
+
useIsomorphicLayoutEffect(() => {
|
|
160
|
+
if (lastSpot.current === spot) return;
|
|
161
|
+
lastSpot.current = spot;
|
|
162
|
+
setTravelling(true);
|
|
163
|
+
}, [spot]);
|
|
164
|
+
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 = useRef(wanted);
|
|
185
|
+
const holding = useRef(false);
|
|
186
|
+
if (wasTucked.current && !wanted) holding.current = true;
|
|
187
|
+
wasTucked.current = wanted;
|
|
188
|
+
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 === 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;
|
|
113
206
|
const actions = useHostActions(host);
|
|
114
207
|
const lastActions = useRef(null);
|
|
115
208
|
if (actions) lastActions.current = actions;
|
|
116
209
|
const detached = host.actionsStyle === "detached";
|
|
117
210
|
const actionsPresence = detached && actions && !tucked ? "compact" : "hidden";
|
|
118
|
-
const
|
|
211
|
+
const goingIn = useRef(false);
|
|
212
|
+
const wasDetached = 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;
|
|
119
217
|
const atom = useRef(null);
|
|
120
218
|
const [actionsAcross, setActionsAcross] = useState(false);
|
|
219
|
+
const [wheelLength, setWheelLength] = useState(void 0);
|
|
121
220
|
const actionsBox = useRef(null);
|
|
122
221
|
const across = useRef(actionsAcross);
|
|
123
222
|
across.current = actionsAcross;
|
|
@@ -137,6 +236,11 @@ function SatellitesLayer({ host }) {
|
|
|
137
236
|
});
|
|
138
237
|
const hostMin = useRef(void 0);
|
|
139
238
|
const rows = useRef(/* @__PURE__ */ new Map());
|
|
239
|
+
const spots = useRef(/* @__PURE__ */ new Map());
|
|
240
|
+
const rejoining = useRef(/* @__PURE__ */ new Set());
|
|
241
|
+
const splitNext = useRef(/* @__PURE__ */ new Set());
|
|
242
|
+
const insideSpot = useRef(null);
|
|
243
|
+
const lastStyle = useRef(host.actionsStyle);
|
|
140
244
|
const arrange = useRef(() => {});
|
|
141
245
|
arrange.current = (animate) => {
|
|
142
246
|
const root = host.rootRef.current;
|
|
@@ -178,19 +282,42 @@ function SatellitesLayer({ host }) {
|
|
|
178
282
|
width: actionsBox.current.width,
|
|
179
283
|
height: actionsBox.current.height,
|
|
180
284
|
side: host.actionsSide,
|
|
181
|
-
turn
|
|
285
|
+
turn,
|
|
286
|
+
...host.actionsWheel ? { wheel: actionsBox.current.wheel } : {}
|
|
182
287
|
} : void 0,
|
|
288
|
+
nearest: host.nearestToPill,
|
|
183
289
|
side: host.electronSide,
|
|
184
290
|
line: host.electronLine,
|
|
185
291
|
arrange: host.arrange,
|
|
186
292
|
gap,
|
|
187
293
|
offset
|
|
188
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
|
+
}
|
|
189
308
|
const reduced = prefersReducedMotion();
|
|
190
309
|
const moving = animate && !reduced && typeof root.animate === "function";
|
|
191
310
|
const timings = 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 ? atPoint(root.offsetLeft + root.offsetWidth / 2, hostAlong) : 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;
|
|
192
319
|
const previous = applied.current;
|
|
193
|
-
if (Math.abs(layout.shift - previous.shift) > .5) {
|
|
320
|
+
if (!holding && Math.abs(layout.shift - previous.shift) > .5) {
|
|
194
321
|
const along = (value) => vertical ? `0px ${value}px` : `${value}px 0px`;
|
|
195
322
|
if (layout.shift) root.style.setProperty("translate", along(layout.shift));
|
|
196
323
|
else root.style.removeProperty("translate");
|
|
@@ -201,70 +328,161 @@ function SatellitesLayer({ host }) {
|
|
|
201
328
|
composite: "add"
|
|
202
329
|
});
|
|
203
330
|
}
|
|
204
|
-
if (!vertical && layout.reserve !== previous.reserve) {
|
|
331
|
+
if (!holding && !vertical && layout.reserve !== previous.reserve) {
|
|
205
332
|
if (layout.reserve) root.style.setProperty("--_mp-shift-x", `${layout.reserve}px`);
|
|
206
333
|
else root.style.removeProperty("--_mp-shift-x");
|
|
207
334
|
}
|
|
208
|
-
applied.current = {
|
|
335
|
+
if (!holding) applied.current = {
|
|
209
336
|
shift: layout.shift,
|
|
210
337
|
reserve: layout.reserve
|
|
211
338
|
};
|
|
212
|
-
|
|
213
|
-
|
|
339
|
+
const rejoin = (id, element, then) => {
|
|
340
|
+
rejoining.current.add(id);
|
|
341
|
+
const { exit } = 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 = [];
|
|
214
362
|
if (atomElement) {
|
|
215
363
|
const was = presences.current.get(ACTIONS);
|
|
216
364
|
const box = boxes.actions;
|
|
217
365
|
const settled = layout.actionsAcross === across.current;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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();
|
|
224
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 ? atPoint(insideSpot.current.x, insideSpot.current.y, 1) : void 0;
|
|
396
|
+
cancel(atomElement, MORPH, true);
|
|
397
|
+
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)) {
|
|
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
|
+
}
|
|
225
414
|
} else if (animate && !atomOut && was === "compact") {
|
|
226
|
-
const { fade,
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
415
|
+
const { fade, exit } = durations(atomElement);
|
|
416
|
+
if (styleChanged && host.actionsStyle === "inside" && insideSpot.current) {
|
|
417
|
+
cancel(atomElement, EXIT, true);
|
|
418
|
+
for (const child of atomElement.children) child.style.opacity = "1";
|
|
419
|
+
bud(root, atomElement, "join", 0, exit, 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 + durations(atomElement).change), hostCentre());
|
|
426
|
+
else bud(root, atomElement, "join", fade, exit);
|
|
427
|
+
spots.current.delete(ACTIONS);
|
|
231
428
|
}
|
|
232
|
-
if (animate && (settled || !atomOut)) presences.current.set(ACTIONS, actionsPresence);
|
|
429
|
+
if (animate && !rejoining.current.has(ACTIONS) && !holding && (settled || !atomOut)) presences.current.set(ACTIONS, actionsPresence);
|
|
233
430
|
}
|
|
234
431
|
const crossOf = (box) => Math.round(vertical ? box.left : box.top);
|
|
235
432
|
out.forEach(({ electron }, index) => {
|
|
236
433
|
const element = elements.current.get(electron.id);
|
|
237
434
|
const box = boxes[electron.id];
|
|
238
435
|
const was = presences.current.get(electron.id);
|
|
239
|
-
|
|
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, 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
|
+
};
|
|
240
459
|
element.style.left = `${box.left}px`;
|
|
241
460
|
element.style.top = `${box.top}px`;
|
|
242
461
|
const row = String(crossOf(box));
|
|
243
462
|
const changedRow = rows.current.has(electron.id) && rows.current.get(electron.id) !== row;
|
|
244
463
|
rows.current.set(electron.id, row);
|
|
464
|
+
const placed = Number.isFinite(from.left) && Number.isFinite(from.top);
|
|
245
465
|
if (!animate) {
|
|
246
|
-
if (changedRow && !reduced && typeof element.animate === "function") {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
composite: "add"
|
|
253
|
-
});
|
|
254
|
-
}
|
|
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
|
+
});
|
|
255
472
|
return;
|
|
256
473
|
}
|
|
257
474
|
if (was === void 0 || was === "hidden") {
|
|
258
475
|
const before = out[index - 1];
|
|
259
476
|
const neighbour = before ? elements.current.get(before.electron.id) : void 0;
|
|
260
477
|
const anchor = neighbour && before && nextTo(boxes[before.electron.id], box, gap) ? neighbour : root;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
478
|
+
bud(anchor, element, "split", 0, 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
|
|
264
484
|
});
|
|
265
|
-
|
|
266
|
-
const to = element.getBoundingClientRect();
|
|
267
|
-
element.animate([{ translate: `${from.left - to.left}px ${from.top - to.top}px` }, { translate: "0px 0px" }], {
|
|
485
|
+
element.animate([{ translate: `${from.left - box.left}px ${from.top - box.top}px` }, { translate: "0px 0px" }], {
|
|
268
486
|
id: SHIFT,
|
|
269
487
|
duration: timings.change,
|
|
270
488
|
easing: "ease-in-out",
|
|
@@ -272,16 +490,24 @@ function SatellitesLayer({ host }) {
|
|
|
272
490
|
});
|
|
273
491
|
}
|
|
274
492
|
});
|
|
275
|
-
|
|
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) playNecks([...passing], timings.change);
|
|
501
|
+
if (animate && !holding) {
|
|
276
502
|
for (const entry of entries) {
|
|
277
503
|
const element = elements.current.get(entry.electron.id);
|
|
278
504
|
if (!element || entry.presence !== "hidden" || presences.current.get(entry.electron.id) !== "compact") continue;
|
|
279
|
-
|
|
505
|
+
const ending = entry.leaving ? entry.electron.input.ending ?? host.electronEnding : "join";
|
|
506
|
+
spots.current.delete(entry.electron.id);
|
|
507
|
+
if (ending === "pop") continue;
|
|
280
508
|
const { fade, change, exit } = durations(element);
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
duration: exit
|
|
284
|
-
});
|
|
509
|
+
if (tucked && !entry.leaving) bud(root, element, "join", 0, Math.max(exit, fade + change), hostCentre());
|
|
510
|
+
else bud(root, element, "join", fade, exit);
|
|
285
511
|
}
|
|
286
512
|
for (const entry of entries) presences.current.set(entry.electron.id, entry.presence);
|
|
287
513
|
}
|
|
@@ -290,12 +516,18 @@ function SatellitesLayer({ host }) {
|
|
|
290
516
|
useEffect(() => {
|
|
291
517
|
const root = host.rootRef.current;
|
|
292
518
|
if (!root) return;
|
|
293
|
-
|
|
519
|
+
let settle;
|
|
520
|
+
const follow = () => {
|
|
521
|
+
arrange.current(false);
|
|
522
|
+
clearTimeout(settle);
|
|
523
|
+
settle = setTimeout(() => arrange.current(true), 200);
|
|
524
|
+
};
|
|
294
525
|
const observer = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(follow);
|
|
295
526
|
observer?.observe(root);
|
|
296
527
|
if (atom.current) observer?.observe(atom.current);
|
|
297
528
|
window.addEventListener("resize", follow);
|
|
298
529
|
return () => {
|
|
530
|
+
clearTimeout(settle);
|
|
299
531
|
observer?.disconnect();
|
|
300
532
|
window.removeEventListener("resize", follow);
|
|
301
533
|
root.style.removeProperty("translate");
|
|
@@ -324,6 +556,7 @@ function SatellitesLayer({ host }) {
|
|
|
324
556
|
shown.current.delete(id);
|
|
325
557
|
presences.current.delete(id);
|
|
326
558
|
rows.current.delete(id);
|
|
559
|
+
spots.current.delete(id);
|
|
327
560
|
refresh();
|
|
328
561
|
}, fade + change + exit + 100);
|
|
329
562
|
});
|
|
@@ -377,7 +610,8 @@ function SatellitesLayer({ host }) {
|
|
|
377
610
|
style: ELECTRON_STYLE,
|
|
378
611
|
children: /* @__PURE__ */ jsx(ActionList, {
|
|
379
612
|
items: shownActions,
|
|
380
|
-
host
|
|
613
|
+
host,
|
|
614
|
+
wheel: wheelLength
|
|
381
615
|
})
|
|
382
616
|
}),
|
|
383
617
|
entries.map(({ electron, presence }) => electron.input.orbitals?.length ? /* @__PURE__ */ jsx(Orbitals, {
|
|
@@ -3,21 +3,40 @@ function planSatellites(input) {
|
|
|
3
3
|
const { viewport, host, placement, vertical, electrons, side, line, gap, offset, actions } = input;
|
|
4
4
|
const rtl = input.rtl && !vertical;
|
|
5
5
|
const sizes = new Map(electrons.map((electron) => [electron.id, electron]));
|
|
6
|
+
const len = (box) => vertical ? box.height : box.width;
|
|
7
|
+
const mainLength = vertical ? viewport.height : viewport.width;
|
|
8
|
+
const available = mainLength - offset * 2;
|
|
6
9
|
let actionsAcross = actions?.turn === "across";
|
|
10
|
+
let actionsShown;
|
|
11
|
+
const wheel = actions?.wheel && actions.wheel.count > 1 && !actionsAcross ? actions.wheel : void 0;
|
|
7
12
|
const setActionsBox = () => {
|
|
8
13
|
if (!actions) return;
|
|
9
|
-
|
|
10
|
-
width: actions.height,
|
|
11
|
-
height: actions.width
|
|
12
|
-
} : {
|
|
14
|
+
const along = {
|
|
13
15
|
width: actions.width,
|
|
14
16
|
height: actions.height
|
|
15
|
-
}
|
|
17
|
+
};
|
|
18
|
+
if (actionsShown !== void 0 && wheel) {
|
|
19
|
+
const length = wheel.first + (actionsShown - 1) * wheel.step;
|
|
20
|
+
if (vertical) along.height = length;
|
|
21
|
+
else along.width = length;
|
|
22
|
+
}
|
|
23
|
+
sizes.set("actions", actionsAcross ? {
|
|
24
|
+
width: along.height,
|
|
25
|
+
height: along.width
|
|
26
|
+
} : along);
|
|
16
27
|
};
|
|
17
28
|
setActionsBox();
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
29
|
+
/** With a wheel, as many as a length holds (0: not even one) */
|
|
30
|
+
const fitting = (length) => !wheel || length < wheel.first ? 0 : Math.min(wheel.count, 1 + Math.floor((length - wheel.first) / wheel.step));
|
|
31
|
+
/** Cut the actions short by `over` px, keeping at least `least` of them: whether it did */
|
|
32
|
+
const cutShort = (over, least) => {
|
|
33
|
+
if (!wheel || !actions) return false;
|
|
34
|
+
const fit = fitting(len(actions) - over);
|
|
35
|
+
if (fit < least || fit >= wheel.count) return false;
|
|
36
|
+
actionsShown = fit;
|
|
37
|
+
setActionsBox();
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
21
40
|
const sides = {
|
|
22
41
|
before: [],
|
|
23
42
|
after: [],
|
|
@@ -33,21 +52,25 @@ function planSatellites(input) {
|
|
|
33
52
|
end: "after",
|
|
34
53
|
beside: "beside"
|
|
35
54
|
}[actions.side] : void 0;
|
|
36
|
-
|
|
55
|
+
const actionsNearer = input.nearest === "actions";
|
|
56
|
+
if (actionsSide) {
|
|
57
|
+
if (actionsNearer && actionsSide !== "beside") sides[actionsSide].unshift("actions");
|
|
58
|
+
else sides[actionsSide].push("actions");
|
|
59
|
+
}
|
|
37
60
|
const lengthOf = (ids) => ids.reduce((sum, id) => sum + len(sizes.get(id)) + gap, 0);
|
|
38
61
|
const rowLength = () => lengthOf(sides.before) + len(host) + lengthOf(sides.after);
|
|
39
62
|
const leastRowLength = () => lengthOf(sides.before) + Math.min(len(host), input.hostMin ?? 1e400) + lengthOf(sides.after);
|
|
40
|
-
if (leastRowLength() > available &&
|
|
41
|
-
|
|
42
|
-
|
|
63
|
+
if (leastRowLength() > available && actionsSide && actionsSide !== "beside") {
|
|
64
|
+
if (!cutShort(leastRowLength() - available, Math.min(2, wheel?.count ?? 0)) && actions?.turn === "auto" && !wheel) {
|
|
65
|
+
actionsAcross = true;
|
|
66
|
+
setActionsBox();
|
|
67
|
+
}
|
|
43
68
|
}
|
|
44
69
|
const movedBeside = [];
|
|
45
70
|
const [firstElectron, ...otherElectrons] = electrons.map((electron) => electron.id);
|
|
46
|
-
const order = [
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
...firstElectron ? [firstElectron] : []
|
|
50
|
-
];
|
|
71
|
+
const order = [...otherElectrons.reverse()];
|
|
72
|
+
if (actionsNearer) order.push(...firstElectron ? [firstElectron] : [], ...actions ? ["actions"] : []);
|
|
73
|
+
else order.push(...actions ? ["actions"] : [], ...firstElectron ? [firstElectron] : []);
|
|
51
74
|
for (const id of order) {
|
|
52
75
|
if (leastRowLength() <= available) break;
|
|
53
76
|
for (const from of ["after", "before"]) {
|
|
@@ -57,9 +80,17 @@ function planSatellites(input) {
|
|
|
57
80
|
movedBeside.push(id);
|
|
58
81
|
}
|
|
59
82
|
}
|
|
60
|
-
|
|
61
|
-
|
|
83
|
+
const besideRow = () => [...sides.beside.includes("actions") ? ["actions"] : [], ...sides.beside.filter((id) => id !== "actions").reverse()];
|
|
84
|
+
const lengthOfRow = (ids) => Math.max(0, lengthOf(ids) - gap);
|
|
85
|
+
if (actions && sides.beside.includes("actions")) {
|
|
86
|
+
actionsShown = void 0;
|
|
87
|
+
actionsAcross = actions.turn === "across";
|
|
62
88
|
setActionsBox();
|
|
89
|
+
const over = lengthOfRow(besideRow()) - available;
|
|
90
|
+
if (over > 0 && !cutShort(over, 1) && actions.turn === "auto" && !wheel) {
|
|
91
|
+
actionsAcross = true;
|
|
92
|
+
setActionsBox();
|
|
93
|
+
}
|
|
63
94
|
}
|
|
64
95
|
const align = vertical ? "center" : placement.endsWith("-start") ? "start" : placement.endsWith("-end") ? "end" : "center";
|
|
65
96
|
const hostStartOnItsOwn = vertical ? host.top : rtl ? viewport.width - host.left - host.width : host.left;
|
|
@@ -99,17 +130,31 @@ function planSatellites(input) {
|
|
|
99
130
|
};
|
|
100
131
|
if (input.arrange !== "spread" || !spread()) gather();
|
|
101
132
|
const hostStart = at.host;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
for (const id of
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
133
|
+
const hostEnd = hostStart + len(host);
|
|
134
|
+
const besideRows = [];
|
|
135
|
+
for (const id of besideRow()) {
|
|
136
|
+
const current = besideRows[besideRows.length - 1];
|
|
137
|
+
if (current && lengthOfRow([...current, id]) <= available) current.push(id);
|
|
138
|
+
else besideRows.push([id]);
|
|
139
|
+
}
|
|
140
|
+
for (const row of besideRows) {
|
|
141
|
+
const total = lengthOfRow(row);
|
|
142
|
+
if (total <= len(host)) {
|
|
143
|
+
let fromEnd = hostEnd;
|
|
144
|
+
for (const id of [...row].reverse()) {
|
|
145
|
+
if (id === "actions") continue;
|
|
146
|
+
fromEnd -= len(sizes.get(id));
|
|
147
|
+
at[id] = fromEnd;
|
|
148
|
+
fromEnd -= gap;
|
|
149
|
+
}
|
|
150
|
+
if (row.includes("actions")) at.actions = hostStart;
|
|
108
151
|
continue;
|
|
109
152
|
}
|
|
110
|
-
cursor
|
|
111
|
-
|
|
112
|
-
|
|
153
|
+
let cursor = Math.max(offset, Math.min(hostStart, mainLength - offset - total));
|
|
154
|
+
for (const id of row) {
|
|
155
|
+
at[id] = cursor;
|
|
156
|
+
cursor += len(sizes.get(id)) + gap;
|
|
157
|
+
}
|
|
113
158
|
}
|
|
114
159
|
const towardsPage = placement.startsWith("bottom") || placement === "right" ? -1 : 1;
|
|
115
160
|
const boxes = {};
|
|
@@ -134,7 +179,14 @@ function planSatellites(input) {
|
|
|
134
179
|
const rowIn = (thick, from, fromThick) => towardsPage < 0 ? from - gap - thick : from + fromThick + gap;
|
|
135
180
|
const thickOf = (id) => vertical ? sizes.get(id).width : sizes.get(id).height;
|
|
136
181
|
for (const id of [...sides.before, ...sides.after]) boxes[id] = toBox(id, at[id], onEdge(thickOf(id)));
|
|
137
|
-
|
|
182
|
+
let rowFrom = hostCross;
|
|
183
|
+
let rowThick = hostThick;
|
|
184
|
+
for (const row of besideRows) {
|
|
185
|
+
for (const id of row) boxes[id] = toBox(id, at[id], rowIn(thickOf(id), rowFrom, rowThick));
|
|
186
|
+
const thickest = Math.max(...row.map(thickOf));
|
|
187
|
+
rowFrom = towardsPage < 0 ? rowFrom - gap - thickest : rowFrom + rowThick + gap;
|
|
188
|
+
rowThick = thickest;
|
|
189
|
+
}
|
|
138
190
|
let previous = electrons[0]?.id;
|
|
139
191
|
for (const id of stacked) {
|
|
140
192
|
const base = boxes[previous];
|
|
@@ -149,7 +201,8 @@ function planSatellites(input) {
|
|
|
149
201
|
reserve: vertical ? 0 : lengthOf(sides.before) + lengthOf(sides.after),
|
|
150
202
|
boxes,
|
|
151
203
|
movedBeside,
|
|
152
|
-
actionsAcross
|
|
204
|
+
actionsAcross,
|
|
205
|
+
...actionsShown !== void 0 ? { actionsShown } : {}
|
|
153
206
|
};
|
|
154
207
|
}
|
|
155
208
|
|