magic-pill 9.3.0 → 9.4.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +114 -3
  3. package/dist/MagicPill/MagicPill.d.mts +43 -1
  4. package/dist/MagicPill/MagicPill.d.ts +43 -1
  5. package/dist/MagicPill/MagicPill.js +51 -4
  6. package/dist/MagicPill/MagicPill.mjs +53 -6
  7. package/dist/MagicPill/flag.js +1 -59
  8. package/dist/MagicPill/flag.mjs +1 -58
  9. package/dist/Pill/PillProgress.d.mts +12 -0
  10. package/dist/Pill/PillProgress.d.ts +12 -0
  11. package/dist/Pill/PillProgress.js +42 -0
  12. package/dist/Pill/PillProgress.mjs +42 -0
  13. package/dist/Pill/goo.js +353 -0
  14. package/dist/Pill/goo.mjs +347 -0
  15. package/dist/Pill/morph.js +4 -2
  16. package/dist/Pill/morph.mjs +4 -2
  17. package/dist/PillNavbar/PillNavbar.d.mts +8 -0
  18. package/dist/PillNavbar/PillNavbar.d.ts +8 -0
  19. package/dist/PillNavbar/PillNavbar.js +3 -2
  20. package/dist/PillNavbar/PillNavbar.mjs +3 -2
  21. package/dist/PillNavbar/room.d.mts +3 -0
  22. package/dist/PillNavbar/room.d.ts +2 -0
  23. package/dist/PillNavbar/room.js +89 -17
  24. package/dist/PillNavbar/room.mjs +89 -18
  25. package/dist/index.d.mts +3 -2
  26. package/dist/index.d.ts +3 -2
  27. package/dist/index.js +2 -0
  28. package/dist/index.mjs +2 -1
  29. package/dist/satellites/Actions.d.mts +12 -0
  30. package/dist/satellites/Actions.d.ts +11 -0
  31. package/dist/satellites/Actions.js +59 -0
  32. package/dist/satellites/Actions.mjs +56 -0
  33. package/dist/satellites/Orbitals.js +554 -0
  34. package/dist/satellites/Orbitals.mjs +554 -0
  35. package/dist/satellites/Satellites.js +400 -0
  36. package/dist/satellites/Satellites.mjs +400 -0
  37. package/dist/satellites/layout.js +156 -0
  38. package/dist/satellites/layout.mjs +156 -0
  39. package/dist/satellites/measure.js +25 -0
  40. package/dist/satellites/measure.mjs +24 -0
  41. package/dist/satellites/orbits.js +139 -0
  42. package/dist/satellites/orbits.mjs +136 -0
  43. package/dist/satellites/types.d.mts +54 -0
  44. package/dist/satellites/types.d.ts +54 -0
  45. package/dist/satellites.d.mts +5 -0
  46. package/dist/satellites.d.ts +5 -0
  47. package/dist/satellites.js +14 -0
  48. package/dist/satellites.mjs +12 -0
  49. package/dist/store/store.d.mts +103 -0
  50. package/dist/store/store.d.ts +103 -0
  51. package/dist/store/store.js +52 -1
  52. package/dist/store/store.mjs +52 -2
  53. package/dist/styles.css +168 -7
  54. package/package.json +11 -1
@@ -0,0 +1,400 @@
1
+ "use client";
2
+
3
+ import { useEffect, useReducer, useRef, useState, useSyncExternalStore } from "react";
4
+ import Pill from "../Pill/Pill.mjs";
5
+ import { playSplit } from "../Pill/goo.mjs";
6
+ import { PillProgress } from "../Pill/PillProgress.mjs";
7
+ import { findActiveIndex } from "../PillNavbar/matchPath.mjs";
8
+ import { foldedWidth } from "../PillNavbar/room.mjs";
9
+ import { NO_ELECTRONS } from "../store/store.mjs";
10
+ import { useIsomorphicLayoutEffect } from "../utils/react.mjs";
11
+ import { prefersReducedMotion } from "../utils/timing.mjs";
12
+ import { VISUALLY_HIDDEN } from "../utils/visuallyHidden.mjs";
13
+ import { planSatellites } from "./layout.mjs";
14
+ import { durations, toPixels } from "./measure.mjs";
15
+ import { Orbitals } from "./Orbitals.mjs";
16
+ import { ActionList, useHostActions } from "./Actions.mjs";
17
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
18
+
19
+ // src/satellites/Satellites.tsx
20
+ const ELECTRON_STYLE = {
21
+ position: "fixed",
22
+ zIndex: "var(--mp-z-index, 50)",
23
+ margin: 0
24
+ };
25
+ const SHIFT = "mp-satellite-shift";
26
+ /** The page's actions' entry among the satellites' presences */
27
+ const ACTIONS = "\0actions";
28
+ const SIDE_PLACEMENTS = /* @__PURE__ */ new Set(["left", "right"]);
29
+ /**
30
+ * 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
+ */
33
+ function alongBox(atom, vertical) {
34
+ const copy = atom.cloneNode(true);
35
+ copy.setAttribute("data-orientation", vertical ? "vertical" : "horizontal");
36
+ copy.removeAttribute("id");
37
+ copy.inert = true;
38
+ copy.style.visibility = "hidden";
39
+ copy.style.pointerEvents = "none";
40
+ copy.style.translate = "none";
41
+ copy.style.scale = "none";
42
+ atom.after(copy);
43
+ const box = {
44
+ width: copy.offsetWidth,
45
+ height: copy.offsetHeight
46
+ };
47
+ copy.remove();
48
+ return box;
49
+ }
50
+ /** Two boxes side by side, a gap apart: the second can come out of the first. */
51
+ const nextTo = (a, b, gap) => {
52
+ const sideBySide = Math.abs(a.top - b.top) < 2 && Math.abs(Math.abs(a.left - b.left) - (a.width + gap)) < 2;
53
+ const stacked = Math.abs(a.left - b.left) < 2 && Math.abs(Math.abs(a.top - b.top) - (a.height + gap)) < 2;
54
+ return sideBySide || stacked;
55
+ };
56
+ /** What an electron shows: the ring and its value or icon, the value alone, or the app's own. */
57
+ function ElectronContent({ electron }) {
58
+ const { input } = electron;
59
+ if (input.render) return input.render();
60
+ const inner = input.value !== void 0 ? /* @__PURE__ */ jsx("span", {
61
+ "data-mp": "electron-value",
62
+ children: input.value
63
+ }) : input.icon !== void 0 ? /* @__PURE__ */ jsx("span", {
64
+ "data-mp": "electron-icon",
65
+ "aria-hidden": "true",
66
+ children: input.icon
67
+ }) : null;
68
+ return input.progress !== void 0 ? /* @__PURE__ */ jsx(PillProgress, {
69
+ value: input.progress,
70
+ children: inner
71
+ }) : inner;
72
+ }
73
+ /** All of the circle is a link back to where it came from, or a button for its `onClick`. */
74
+ function ElectronBody({ electron, host }) {
75
+ const { input, origin } = electron;
76
+ const valueText = input.valueText ?? input.value;
77
+ const name = valueText ? `${input.label}, ${valueText}` : input.label;
78
+ const content = /* @__PURE__ */ jsx(ElectronContent, { electron });
79
+ if (input.onClick) return /* @__PURE__ */ jsx("button", {
80
+ type: "button",
81
+ "data-mp": "electron",
82
+ "aria-label": name,
83
+ onClick: (event) => input.onClick?.(event),
84
+ children: content
85
+ });
86
+ if (origin !== void 0) {
87
+ const Link = host.linkComponent ?? "a";
88
+ return /* @__PURE__ */ jsx(Link, {
89
+ href: origin,
90
+ "data-mp": "electron",
91
+ "aria-label": name,
92
+ draggable: false,
93
+ children: content
94
+ });
95
+ }
96
+ return /* @__PURE__ */ jsx("span", {
97
+ "data-mp": "electron",
98
+ role: "img",
99
+ "aria-label": name,
100
+ children: content
101
+ });
102
+ }
103
+ function SatellitesLayer({ host }) {
104
+ const electrons = useSyncExternalStore(host.store.subscribe, host.store.getElectrons, () => NO_ELECTRONS);
105
+ const [, refresh] = useReducer((count) => count + 1, 0);
106
+ const shown = useRef(/* @__PURE__ */ new Map());
107
+ for (const electron of electrons) shown.current.set(electron.id, { electron });
108
+ for (const [id, entry] of shown.current) if (!entry.leaving && !electrons.some((electron) => electron.id === id)) shown.current.set(id, {
109
+ ...entry,
110
+ leaving: true
111
+ });
112
+ const tucked = host.notifying && !host.keepElectronsOut;
113
+ const actions = useHostActions(host);
114
+ const lastActions = useRef(null);
115
+ if (actions) lastActions.current = actions;
116
+ const detached = host.actionsStyle === "detached";
117
+ const actionsPresence = detached && actions && !tucked ? "compact" : "hidden";
118
+ const shownActions = detached ? actions ?? lastActions.current : null;
119
+ const atom = useRef(null);
120
+ const [actionsAcross, setActionsAcross] = useState(false);
121
+ const actionsBox = useRef(null);
122
+ const across = useRef(actionsAcross);
123
+ across.current = actionsAcross;
124
+ const presenceOf = ({ electron, leaving }) => {
125
+ if (leaving || tucked) return "hidden";
126
+ return electron.input.hideOnOrigin !== false && electron.origin !== void 0 && findActiveIndex(host.pathname, [{ href: electron.origin }]) === 0 ? "hidden" : "compact";
127
+ };
128
+ const entries = [...shown.current.values()].map((entry) => ({
129
+ ...entry,
130
+ presence: presenceOf(entry)
131
+ }));
132
+ const elements = useRef(/* @__PURE__ */ new Map());
133
+ const presences = useRef(/* @__PURE__ */ new Map());
134
+ const applied = useRef({
135
+ shift: 0,
136
+ reserve: 0
137
+ });
138
+ const hostMin = useRef(void 0);
139
+ const rows = useRef(/* @__PURE__ */ new Map());
140
+ const arrange = useRef(() => {});
141
+ arrange.current = (animate) => {
142
+ const root = host.rootRef.current;
143
+ if (!root) return;
144
+ const vertical = SIDE_PLACEMENTS.has(host.placement);
145
+ const style = getComputedStyle(root);
146
+ const gap = toPixels(style.getPropertyValue("--mp-electron-gap"), root, Number.parseFloat(style.columnGap) || 16);
147
+ const offset = toPixels(style.getPropertyValue("--_mp-offset"), root, 24);
148
+ const out = entries.filter((entry) => entry.presence !== "hidden" && elements.current.get(entry.electron.id));
149
+ if (animate && !vertical) hostMin.current = foldedWidth(root);
150
+ const atomElement = atom.current;
151
+ const atomOut = actionsPresence !== "hidden" && atomElement;
152
+ if (atomOut && (animate || !actionsBox.current)) actionsBox.current = alongBox(atomElement, vertical);
153
+ const turn = host.actionsOrientation === "auto" ? "auto" : host.actionsOrientation === "vertical" === vertical ? "along" : "across";
154
+ const layout = planSatellites({
155
+ viewport: {
156
+ width: document.documentElement.clientWidth || window.innerWidth,
157
+ height: window.innerHeight
158
+ },
159
+ host: {
160
+ left: root.offsetLeft,
161
+ top: root.offsetTop,
162
+ width: root.offsetWidth,
163
+ height: root.offsetHeight
164
+ },
165
+ hostMin: vertical ? void 0 : hostMin.current,
166
+ placement: host.placement,
167
+ vertical,
168
+ rtl: style.direction === "rtl",
169
+ electrons: out.map(({ electron }) => {
170
+ const element = elements.current.get(electron.id);
171
+ return {
172
+ id: electron.id,
173
+ width: element.offsetWidth || 72,
174
+ height: element.offsetHeight || 72
175
+ };
176
+ }),
177
+ actions: atomOut && actionsBox.current ? {
178
+ width: actionsBox.current.width,
179
+ height: actionsBox.current.height,
180
+ side: host.actionsSide,
181
+ turn
182
+ } : void 0,
183
+ side: host.electronSide,
184
+ line: host.electronLine,
185
+ arrange: host.arrange,
186
+ gap,
187
+ offset
188
+ });
189
+ const reduced = prefersReducedMotion();
190
+ const moving = animate && !reduced && typeof root.animate === "function";
191
+ const timings = durations(out[0] ? elements.current.get(out[0].electron.id) : root);
192
+ const previous = applied.current;
193
+ if (Math.abs(layout.shift - previous.shift) > .5) {
194
+ const along = (value) => vertical ? `0px ${value}px` : `${value}px 0px`;
195
+ if (layout.shift) root.style.setProperty("translate", along(layout.shift));
196
+ else root.style.removeProperty("translate");
197
+ if (moving) root.animate([{ translate: along(previous.shift - layout.shift) }, { translate: "0px 0px" }], {
198
+ id: SHIFT,
199
+ duration: timings.change,
200
+ easing: "ease-in-out",
201
+ composite: "add"
202
+ });
203
+ }
204
+ if (!vertical && layout.reserve !== previous.reserve) {
205
+ if (layout.reserve) root.style.setProperty("--_mp-shift-x", `${layout.reserve}px`);
206
+ else root.style.removeProperty("--_mp-shift-x");
207
+ }
208
+ applied.current = {
209
+ shift: layout.shift,
210
+ reserve: layout.reserve
211
+ };
212
+ if (animate && atomOut && layout.actionsAcross !== across.current) setActionsAcross(layout.actionsAcross);
213
+ const boxes = layout.boxes;
214
+ if (atomElement) {
215
+ const was = presences.current.get(ACTIONS);
216
+ const box = boxes.actions;
217
+ const settled = layout.actionsAcross === across.current;
218
+ if (box && atomOut && settled) {
219
+ atomElement.style.left = `${box.left}px`;
220
+ atomElement.style.top = `${box.top}px`;
221
+ if (animate && was !== "compact") playSplit(root, atomElement, "split", {
222
+ delay: 0,
223
+ duration: durations(atomElement).enter
224
+ });
225
+ } else if (animate && !atomOut && was === "compact") {
226
+ const { fade, change, exit } = durations(atomElement);
227
+ playSplit(root, atomElement, "join", {
228
+ delay: fade + change,
229
+ duration: exit
230
+ });
231
+ }
232
+ if (animate && (settled || !atomOut)) presences.current.set(ACTIONS, actionsPresence);
233
+ }
234
+ const crossOf = (box) => Math.round(vertical ? box.left : box.top);
235
+ out.forEach(({ electron }, index) => {
236
+ const element = elements.current.get(electron.id);
237
+ const box = boxes[electron.id];
238
+ const was = presences.current.get(electron.id);
239
+ const from = element.getBoundingClientRect();
240
+ element.style.left = `${box.left}px`;
241
+ element.style.top = `${box.top}px`;
242
+ const row = String(crossOf(box));
243
+ const changedRow = rows.current.has(electron.id) && rows.current.get(electron.id) !== row;
244
+ rows.current.set(electron.id, row);
245
+ if (!animate) {
246
+ if (changedRow && !reduced && typeof element.animate === "function") {
247
+ const to = element.getBoundingClientRect();
248
+ element.animate([{ translate: `${from.left - to.left}px ${from.top - to.top}px` }, { translate: "0px 0px" }], {
249
+ id: SHIFT,
250
+ duration: timings.change,
251
+ easing: "ease-in-out",
252
+ composite: "add"
253
+ });
254
+ }
255
+ return;
256
+ }
257
+ if (was === void 0 || was === "hidden") {
258
+ const before = out[index - 1];
259
+ const neighbour = before ? elements.current.get(before.electron.id) : void 0;
260
+ const anchor = neighbour && before && nextTo(boxes[before.electron.id], box, gap) ? neighbour : root;
261
+ playSplit(anchor, element, "split", {
262
+ delay: 0,
263
+ duration: durations(element).enter
264
+ });
265
+ } else if (moving && (Math.abs(from.left - box.left) > .5 || Math.abs(from.top - box.top) > .5)) {
266
+ const to = element.getBoundingClientRect();
267
+ element.animate([{ translate: `${from.left - to.left}px ${from.top - to.top}px` }, { translate: "0px 0px" }], {
268
+ id: SHIFT,
269
+ duration: timings.change,
270
+ easing: "ease-in-out",
271
+ composite: "add"
272
+ });
273
+ }
274
+ });
275
+ if (animate) {
276
+ for (const entry of entries) {
277
+ const element = elements.current.get(entry.electron.id);
278
+ if (!element || entry.presence !== "hidden" || presences.current.get(entry.electron.id) !== "compact") continue;
279
+ if ((entry.leaving ? entry.electron.input.ending ?? host.electronEnding : "join") === "pop") continue;
280
+ const { fade, change, exit } = durations(element);
281
+ playSplit(root, element, "join", {
282
+ delay: fade + change,
283
+ duration: exit
284
+ });
285
+ }
286
+ for (const entry of entries) presences.current.set(entry.electron.id, entry.presence);
287
+ }
288
+ };
289
+ useIsomorphicLayoutEffect(() => arrange.current(true));
290
+ useEffect(() => {
291
+ const root = host.rootRef.current;
292
+ if (!root) return;
293
+ const follow = () => arrange.current(false);
294
+ const observer = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(follow);
295
+ observer?.observe(root);
296
+ if (atom.current) observer?.observe(atom.current);
297
+ window.addEventListener("resize", follow);
298
+ return () => {
299
+ observer?.disconnect();
300
+ window.removeEventListener("resize", follow);
301
+ root.style.removeProperty("translate");
302
+ if (!SIDE_PLACEMENTS.has(host.placement)) root.style.removeProperty("--_mp-shift-x");
303
+ applied.current = {
304
+ shift: 0,
305
+ reserve: 0
306
+ };
307
+ };
308
+ }, [
309
+ host.rootRef,
310
+ host.placement,
311
+ !!shownActions
312
+ ]);
313
+ const leavingIds = entries.filter((entry) => entry.leaving).map((entry) => entry.electron.id);
314
+ useEffect(() => {
315
+ if (leavingIds.length === 0) return;
316
+ const timers = leavingIds.map((id) => {
317
+ const element = elements.current.get(id);
318
+ const { fade, change, exit } = element ? durations(element) : {
319
+ fade: 150,
320
+ change: 250,
321
+ exit: 300
322
+ };
323
+ return setTimeout(() => {
324
+ shown.current.delete(id);
325
+ presences.current.delete(id);
326
+ rows.current.delete(id);
327
+ refresh();
328
+ }, fade + change + exit + 100);
329
+ });
330
+ return () => timers.forEach(clearTimeout);
331
+ }, [leavingIds.join(" ")]);
332
+ const [announcement, setAnnouncement] = useState("");
333
+ const announced = useRef(/* @__PURE__ */ new Map());
334
+ useEffect(() => {
335
+ for (const electron of electrons) {
336
+ const text = electron.input.announce;
337
+ if (text && announced.current.get(electron.id) !== text) setAnnouncement(text);
338
+ announced.current.set(electron.id, text);
339
+ }
340
+ }, [electrons]);
341
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
342
+ entries.map(({ electron, presence, leaving }) => {
343
+ const ending = electron.input.ending ?? host.electronEnding;
344
+ return /* @__PURE__ */ jsx(Pill, {
345
+ ref: (element) => {
346
+ if (element) elements.current.set(electron.id, element);
347
+ else elements.current.delete(electron.id);
348
+ },
349
+ placement: "inline",
350
+ ladder: false,
351
+ moveThroughCircle: false,
352
+ theme: host.theme,
353
+ variant: electron.input.variant ?? host.variant,
354
+ presence,
355
+ "data-satellite": "electron",
356
+ "data-ending": leaving && ending === "pop" ? "pop" : void 0,
357
+ style: ELECTRON_STYLE,
358
+ children: /* @__PURE__ */ jsx(ElectronBody, {
359
+ electron,
360
+ host
361
+ })
362
+ }, electron.id);
363
+ }),
364
+ shownActions && /* @__PURE__ */ jsx(Pill, {
365
+ ref: atom,
366
+ placement: "inline",
367
+ ladder: false,
368
+ moveThroughCircle: false,
369
+ theme: host.theme,
370
+ variant: host.variant,
371
+ orientation: host.vertical !== actionsAcross ? "vertical" : "horizontal",
372
+ presence: actionsPresence,
373
+ scene: shownActions.map((item) => item.id ?? item.label).join("\n"),
374
+ role: "group",
375
+ "aria-label": host.actionsLabel,
376
+ "data-satellite": "actions",
377
+ style: ELECTRON_STYLE,
378
+ children: /* @__PURE__ */ jsx(ActionList, {
379
+ items: shownActions,
380
+ host
381
+ })
382
+ }),
383
+ entries.map(({ electron, presence }) => electron.input.orbitals?.length ? /* @__PURE__ */ jsx(Orbitals, {
384
+ electron,
385
+ getElement: () => elements.current.get(electron.id),
386
+ host,
387
+ out: presence !== "hidden"
388
+ }, `orbitals ${electron.id}`) : null),
389
+ /* @__PURE__ */ jsx("div", {
390
+ role: "status",
391
+ "aria-live": "polite",
392
+ "aria-atomic": "true",
393
+ "data-mp": "announcer",
394
+ style: VISUALLY_HIDDEN,
395
+ children: announcement
396
+ })
397
+ ] });
398
+ }
399
+
400
+ export { SatellitesLayer };
@@ -0,0 +1,156 @@
1
+ // src/satellites/layout.ts
2
+ function planSatellites(input) {
3
+ const { viewport, host, placement, vertical, electrons, side, line, gap, offset, actions } = input;
4
+ const rtl = input.rtl && !vertical;
5
+ const sizes = new Map(electrons.map((electron) => [electron.id, electron]));
6
+ let actionsAcross = actions?.turn === "across";
7
+ const setActionsBox = () => {
8
+ if (!actions) return;
9
+ sizes.set("actions", actionsAcross ? {
10
+ width: actions.height,
11
+ height: actions.width
12
+ } : {
13
+ width: actions.width,
14
+ height: actions.height
15
+ });
16
+ };
17
+ setActionsBox();
18
+ const len = (box) => vertical ? box.height : box.width;
19
+ const mainLength = vertical ? viewport.height : viewport.width;
20
+ const available = mainLength - offset * 2;
21
+ const sides = {
22
+ before: [],
23
+ after: [],
24
+ beside: []
25
+ };
26
+ const stacked = [];
27
+ electrons.forEach((electron, index) => {
28
+ if (line === "across" && index > 0) stacked.push(electron.id);
29
+ else sides[side].push(electron.id);
30
+ });
31
+ const actionsSide = actions ? {
32
+ start: "before",
33
+ end: "after",
34
+ beside: "beside"
35
+ }[actions.side] : void 0;
36
+ if (actionsSide) sides[actionsSide].push("actions");
37
+ const lengthOf = (ids) => ids.reduce((sum, id) => sum + len(sizes.get(id)) + gap, 0);
38
+ const rowLength = () => lengthOf(sides.before) + len(host) + lengthOf(sides.after);
39
+ const leastRowLength = () => lengthOf(sides.before) + Math.min(len(host), input.hostMin ?? 1e400) + lengthOf(sides.after);
40
+ if (leastRowLength() > available && actions?.turn === "auto" && actionsSide !== "beside") {
41
+ actionsAcross = true;
42
+ setActionsBox();
43
+ }
44
+ const movedBeside = [];
45
+ const [firstElectron, ...otherElectrons] = electrons.map((electron) => electron.id);
46
+ const order = [
47
+ ...otherElectrons.reverse(),
48
+ ...actions ? ["actions"] : [],
49
+ ...firstElectron ? [firstElectron] : []
50
+ ];
51
+ for (const id of order) {
52
+ if (leastRowLength() <= available) break;
53
+ for (const from of ["after", "before"]) {
54
+ if (!sides[from].includes(id)) continue;
55
+ sides[from] = sides[from].filter((other) => other !== id);
56
+ sides.beside.push(id);
57
+ movedBeside.push(id);
58
+ }
59
+ }
60
+ if (actions?.turn === "auto" && sides.beside.includes("actions") && actionsAcross) {
61
+ actionsAcross = false;
62
+ setActionsBox();
63
+ }
64
+ const align = vertical ? "center" : placement.endsWith("-start") ? "start" : placement.endsWith("-end") ? "end" : "center";
65
+ const hostStartOnItsOwn = vertical ? host.top : rtl ? viewport.width - host.left - host.width : host.left;
66
+ const at = {};
67
+ const gather = () => {
68
+ const total = rowLength();
69
+ let cursor = align === "start" ? offset : align === "end" ? mainLength - offset - total : mainLength / 2 - total / 2;
70
+ for (const id of [...sides.before].reverse()) {
71
+ at[id] = cursor;
72
+ cursor += len(sizes.get(id)) + gap;
73
+ }
74
+ at.host = cursor;
75
+ cursor += len(host) + gap;
76
+ for (const id of sides.after) {
77
+ at[id] = cursor;
78
+ cursor += len(sizes.get(id)) + gap;
79
+ }
80
+ };
81
+ const spread = () => {
82
+ const hostStart = align === "start" ? offset + lengthOf(sides.before) : align === "end" ? mainLength - offset - lengthOf(sides.after) - len(host) : mainLength / 2 - len(host) / 2;
83
+ const roomBefore = hostStart - offset - lengthOf(sides.before);
84
+ const roomAfter = mainLength - offset - (hostStart + len(host)) - lengthOf(sides.after);
85
+ if (roomBefore < 0 || roomAfter < 0) return false;
86
+ at.host = hostStart;
87
+ let cursor = offset;
88
+ for (const id of [...sides.before].reverse()) {
89
+ at[id] = cursor;
90
+ cursor += len(sizes.get(id)) + gap;
91
+ }
92
+ cursor = mainLength - offset;
93
+ for (const id of [...sides.after].reverse()) {
94
+ cursor -= len(sizes.get(id));
95
+ at[id] = cursor;
96
+ cursor -= gap;
97
+ }
98
+ return true;
99
+ };
100
+ if (input.arrange !== "spread" || !spread()) gather();
101
+ const hostStart = at.host;
102
+ let cursor = hostStart + len(host);
103
+ let fromStart = hostStart;
104
+ for (const id of sides.beside) {
105
+ if (id === "actions") {
106
+ at[id] = fromStart;
107
+ fromStart += len(sizes.get(id)) + gap;
108
+ continue;
109
+ }
110
+ cursor -= len(sizes.get(id));
111
+ at[id] = cursor;
112
+ cursor -= gap;
113
+ }
114
+ const towardsPage = placement.startsWith("bottom") || placement === "right" ? -1 : 1;
115
+ const boxes = {};
116
+ const toBox = (id, mainStart, crossStart) => {
117
+ const { width, height } = sizes.get(id);
118
+ if (vertical) return {
119
+ left: crossStart,
120
+ top: mainStart,
121
+ width,
122
+ height
123
+ };
124
+ return {
125
+ left: rtl ? viewport.width - mainStart - width : mainStart,
126
+ top: crossStart,
127
+ width,
128
+ height
129
+ };
130
+ };
131
+ const hostCross = vertical ? host.left : host.top;
132
+ const hostThick = vertical ? host.width : host.height;
133
+ const onEdge = (thick) => towardsPage < 0 ? hostCross + hostThick - thick : hostCross;
134
+ const rowIn = (thick, from, fromThick) => towardsPage < 0 ? from - gap - thick : from + fromThick + gap;
135
+ const thickOf = (id) => vertical ? sizes.get(id).width : sizes.get(id).height;
136
+ for (const id of [...sides.before, ...sides.after]) boxes[id] = toBox(id, at[id], onEdge(thickOf(id)));
137
+ for (const id of sides.beside) boxes[id] = toBox(id, at[id], rowIn(thickOf(id), hostCross, hostThick));
138
+ let previous = electrons[0]?.id;
139
+ for (const id of stacked) {
140
+ const base = boxes[previous];
141
+ const baseCross = vertical ? base.left : base.top;
142
+ const baseThick = vertical ? base.width : base.height;
143
+ boxes[id] = toBox(id, vertical ? base.top : rtl ? viewport.width - base.left - base.width : base.left, rowIn(thickOf(id), baseCross, baseThick));
144
+ previous = id;
145
+ }
146
+ const shiftAlong = hostStart - hostStartOnItsOwn;
147
+ return {
148
+ shift: rtl ? -shiftAlong : shiftAlong,
149
+ reserve: vertical ? 0 : lengthOf(sides.before) + lengthOf(sides.after),
150
+ boxes,
151
+ movedBeside,
152
+ actionsAcross
153
+ };
154
+ }
155
+
156
+ exports.planSatellites = planSatellites;