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
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  import { useEffect } from "react";
4
+ import { useIsomorphicLayoutEffect } from "../utils/react.mjs";
4
5
 
5
6
  // src/PillNavbar/room.ts
6
7
  const ACTION = "[data-mp=\"action\"]";
@@ -9,12 +10,15 @@ const ACTION = "[data-mp=\"action\"]";
9
10
  * Removed by the caller. `free`: without the room its satellites take beside it (what they plan
10
11
  * with: measured within it, the pill would only seem to fit what they left it the time before).
11
12
  */
12
- function layOutCopy(pill, prepare = () => {}, free = false) {
13
+ function layOutCopy(pill, prepare = () => {}, free = false, presence) {
13
14
  const copy = pill.cloneNode(false);
14
15
  const side = copy.dataset.placement === "left" || copy.dataset.placement === "right";
15
16
  if (free && !side) copy.style.removeProperty("--_mp-shift-x");
17
+ const planned = copy.style.getPropertyValue("--_mp-room-x");
18
+ if (!free && !side && planned) copy.style.setProperty("--_mp-shift-x", planned);
16
19
  if (copy.dataset.presence === "rest" || copy.dataset.presence === "hidden") copy.dataset.presence = "compact";
17
- for (const child of pill.children) if (child.getAttribute("data-mp") !== "panel") copy.append(child.cloneNode(true));
20
+ if (presence !== void 0 && presence !== "rest" && presence !== "hidden") copy.dataset.presence = presence;
21
+ for (const child of pill.children) if (child.getAttribute("data-mp") !== "panel" && !child.hasAttribute("data-leaving")) copy.append(child.cloneNode(true));
18
22
  copy.querySelectorAll("[id], [name]").forEach((node) => {
19
23
  node.removeAttribute("id");
20
24
  node.removeAttribute("name");
@@ -41,14 +45,14 @@ function layOutCopy(pill, prepare = () => {}, free = false) {
41
45
  * even if it's folded). Laid out on a copy, removed before anything is
42
46
  * painted: the labels on screen may be moving, and the app's own styles count.
43
47
  */
44
- function fitsWith(navbar, item, { unfold = false } = {}) {
48
+ function fitsWith(navbar, item, { unfold = false, presence } = {}) {
45
49
  const pill = navbar.closest("[data-mp=\"pill\"]");
46
50
  if (!pill) return true;
47
51
  const index = item ? [...navbar.querySelectorAll(ACTION)].indexOf(item) : -1;
48
52
  const { copy, navbar: copied } = layOutCopy(pill, (laidOut) => {
49
53
  if (unfold) laidOut.removeAttribute("data-folded");
50
54
  if (index >= 0) laidOut.querySelectorAll(ACTION)[index]?.setAttribute("data-expanded", "");
51
- });
55
+ }, false, presence);
52
56
  const fits = !copied || isInside(copied, copy);
53
57
  copy.remove();
54
58
  return fits;
@@ -58,11 +62,26 @@ function fitsWith(navbar, item, { unfold = false } = {}) {
58
62
  * if it has no navbar that can fold them (`labels="current"`). The
59
63
  * satellites ask, to know whether an electron fits next to it.
60
64
  */
61
- function foldedWidth(pill) {
65
+ function foldedWidth(pill, { content = false } = {}) {
62
66
  const navbar = pill.querySelector("[data-mp=\"navbar\"]");
63
67
  if (!navbar || navbar.dataset.labels === "current") return pill.offsetWidth;
64
68
  const { copy } = layOutCopy(pill, (copied) => copied.setAttribute("data-folded", ""), true);
65
- const width = copy.offsetWidth;
69
+ const width = content ? Math.max(copy.offsetWidth, copy.scrollWidth + (Number.parseFloat(getComputedStyle(copy).paddingRight) || 0)) : copy.offsetWidth;
70
+ copy.remove();
71
+ return width;
72
+ }
73
+ /**
74
+ * How wide the pill is with its navbar's current page's label open, when that label folds by itself
75
+ * (`labels="auto"`); undefined otherwise. The satellites plan from it and from `foldedWidth`, never
76
+ * from the width the pill has at the moment: the label folds because of the room they take, and the
77
+ * room they take depended on whether it had folded (back and forth, every frame).
78
+ */
79
+ function unfoldedWidth(pill) {
80
+ const navbar = pill.querySelector("[data-mp=\"navbar\"]");
81
+ if (!navbar || navbar.dataset.labels !== "auto") return void 0;
82
+ const { copy } = layOutCopy(pill, (copied) => copied.removeAttribute("data-folded"), true);
83
+ const style = getComputedStyle(copy);
84
+ const width = Math.max(copy.offsetWidth, copy.scrollWidth + (Number.parseFloat(style.paddingRight) || 0));
66
85
  copy.remove();
67
86
  return width;
68
87
  }
@@ -80,12 +99,25 @@ function openSize(pill) {
80
99
  copy.remove();
81
100
  return size;
82
101
  }
83
- /** Whether the navbar ends before the pill's padding does. */
102
+ /**
103
+ * Whether the navbar ends before the pill's padding does, with what's beside it in the pill too (the
104
+ * page's actions after a divider): nothing of the pill's content runs past it. The navbar alone used
105
+ * to be measured against the whole pill, and squeezed by the actions next to it
106
+ */
84
107
  function isInside(navbar, pill) {
85
108
  const style = getComputedStyle(pill);
86
109
  const room = pill.clientWidth - (parseFloat(style.paddingLeft) || 0) - (parseFloat(style.paddingRight) || 0);
87
- return navbar.scrollWidth <= room + 1;
110
+ const beside = [...pill.children].filter((child) => child !== navbar && !child.contains(navbar) && child.getAttribute("data-mp") !== "panel");
111
+ const others = beside.reduce((sum, child) => sum + child.offsetWidth, 0);
112
+ const gaps = beside.length * (parseFloat(style.columnGap) || 0);
113
+ return navbar.scrollWidth + others + gaps <= room + 1;
88
114
  }
115
+ /**
116
+ * What a measurement on a copy of the pill depends on: the screen's size, the page's root (a theme, a
117
+ * font size set there) and the pill's markup, which the copy is made from. Not its animations: a
118
+ * copy has none, so a pill morphing or travelling gets the same answer at every frame
119
+ */
120
+ const inputsOf = (pill) => `${window.innerWidth}x${window.innerHeight} ${document.documentElement.className} ${document.documentElement.getAttribute("style") ?? ""} ${pill.outerHTML}`;
89
121
  const isHorizontal = (navbar) => {
90
122
  const pill = navbar.closest("[data-mp=\"pill\"]");
91
123
  return pill?.dataset.orientation === "horizontal" && pill.dataset.unstyled === void 0;
@@ -95,7 +127,16 @@ const isHorizontal = (navbar) => {
95
127
  * the keyboard) has no room for its label next to the open ones, and
96
128
  * `data-folded` while the current page's label folds at rest (`labels`).
97
129
  */
98
- function useRoom(ref, labels = "auto") {
130
+ function useRoom(ref, labels = "auto", presence) {
131
+ useIsomorphicLayoutEffect(() => {
132
+ const navbar = ref.current;
133
+ if (!navbar || labels !== "auto" || presence === void 0) return;
134
+ if (isHorizontal(navbar) && !fitsWith(navbar, null, {
135
+ unfold: true,
136
+ presence
137
+ })) navbar.setAttribute("data-folded", "");
138
+ else navbar.removeAttribute("data-folded");
139
+ }, [presence]);
99
140
  useEffect(() => {
100
141
  const navbar = ref.current;
101
142
  if (!navbar) return;
@@ -109,11 +150,21 @@ function useRoom(ref, labels = "auto") {
109
150
  }
110
151
  const pill = navbar.closest("[data-mp=\"pill\"]");
111
152
  let frame = 0;
153
+ let decided = "";
154
+ const check = () => {
155
+ if (pill && inputsOf(pill) === decided) return;
156
+ fold(isHorizontal(navbar) && !fitsWith(navbar, null, { unfold: true }));
157
+ decided = pill ? inputsOf(pill) : "";
158
+ };
112
159
  const update = () => {
113
160
  cancelAnimationFrame(frame);
114
- frame = requestAnimationFrame(() => fold(isHorizontal(navbar) && !fitsWith(navbar, null, { unfold: true })));
161
+ frame = requestAnimationFrame(check);
162
+ };
163
+ const fontsLoaded = () => {
164
+ decided = "";
165
+ update();
115
166
  };
116
- fold(isHorizontal(navbar) && !fitsWith(navbar, null, { unfold: true }));
167
+ check();
117
168
  const mutations = new MutationObserver(update);
118
169
  mutations.observe(navbar, {
119
170
  subtree: true,
@@ -131,11 +182,13 @@ function useRoom(ref, labels = "auto") {
131
182
  const sizes = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(update);
132
183
  if (pill) sizes?.observe(pill);
133
184
  window.addEventListener("resize", update);
185
+ document.fonts?.addEventListener?.("loadingdone", fontsLoaded);
134
186
  return () => {
135
187
  cancelAnimationFrame(frame);
136
188
  mutations.disconnect();
137
189
  sizes?.disconnect();
138
190
  window.removeEventListener("resize", update);
191
+ document.fonts?.removeEventListener?.("loadingdone", fontsLoaded);
139
192
  fold(false);
140
193
  };
141
194
  }, [ref, labels]);
@@ -171,4 +224,4 @@ function useRoom(ref, labels = "auto") {
171
224
  }, [ref]);
172
225
  }
173
226
 
174
- export { fitsWith, foldedWidth, openSize, useRoom };
227
+ export { fitsWith, foldedWidth, openSize, unfoldedWidth, useRoom };
@@ -2,6 +2,7 @@ const require_parts = require("../Pill/parts.js");
2
2
  const require_PillAction = require("../Pill/PillAction.js");
3
3
  const require_PillPanel = require("../Pill/PillPanel.js");
4
4
  const require_PlusIcon = require("../icons/PlusIcon.js");
5
+ const require_RowsBody = require("./RowsBody.js");
5
6
  let react_jsx_runtime = require("react/jsx-runtime");
6
7
 
7
8
  // src/PillNotification/PillNotification.tsx
@@ -63,10 +64,7 @@ function NotificationContent({ icon, message, action, panel, layout = "pill", li
63
64
  }), notificationPanel] });
64
65
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
65
66
  iconAndDivider,
66
- layout === "rows" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
67
- "data-mp": "body",
68
- children: messageAndActions
69
- }) : messageAndActions,
67
+ layout === "rows" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_RowsBody.RowsBody, { children: messageAndActions }) : messageAndActions,
70
68
  notificationPanel
71
69
  ] });
72
70
  }
@@ -2,6 +2,7 @@ import { PillActions, PillDivider, PillIcon, PillMessage } from "../Pill/parts.m
2
2
  import PillAction from "../Pill/PillAction.mjs";
3
3
  import { PillPanel, PillPanelTrigger } from "../Pill/PillPanel.mjs";
4
4
  import PlusIcon from "../icons/PlusIcon.mjs";
5
+ import { RowsBody } from "./RowsBody.mjs";
5
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
7
 
7
8
  // src/PillNotification/PillNotification.tsx
@@ -63,10 +64,7 @@ function NotificationContent({ icon, message, action, panel, layout = "pill", li
63
64
  }), notificationPanel] });
64
65
  return /* @__PURE__ */ jsxs(Fragment, { children: [
65
66
  iconAndDivider,
66
- layout === "rows" ? /* @__PURE__ */ jsx("div", {
67
- "data-mp": "body",
68
- children: messageAndActions
69
- }) : messageAndActions,
67
+ layout === "rows" ? /* @__PURE__ */ jsx(RowsBody, { children: messageAndActions }) : messageAndActions,
70
68
  notificationPanel
71
69
  ] });
72
70
  }
@@ -0,0 +1,77 @@
1
+ "use client";
2
+
3
+ let react = require("react");
4
+ const require_morph = require("../Pill/morph.js");
5
+ const require_react = require("../utils/react.js");
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+
8
+ // src/PillNotification/RowsBody.tsx
9
+ /** Measured on a copy of the pill, open and as it ends up: the pill itself may be on its way there (a
10
+ * circle growing into the notification, its size animating), the message wrapping at no width */
11
+ function measure(body) {
12
+ const pill = body.closest("[data-mp=\"pill\"]");
13
+ const index = pill ? [...pill.children].indexOf(body) : -1;
14
+ if (!pill || index < 0 || typeof document.createRange !== "function") return { under: false };
15
+ const open = (copy) => {
16
+ if (copy.dataset.presence === "rest" || copy.dataset.presence === "hidden") copy.dataset.presence = "compact";
17
+ };
18
+ return require_morph.onCopy(pill, (copy) => {
19
+ const copied = copy.children[index];
20
+ const message = copied.querySelector(":scope > [data-mp=\"message\"]");
21
+ const result = { under: false };
22
+ if (!message) return result;
23
+ const range = document.createRange();
24
+ range.selectNodeContents(message);
25
+ const lines = [...range.getClientRects?.() ?? []].filter((line) => line.width > 0);
26
+ if (new Set(lines.map((line) => Math.round(line.top))).size > 1) {
27
+ const longest = Math.max(...lines.map((line) => line.right)) - Math.min(...lines.map((line) => line.left));
28
+ const style = getComputedStyle(message);
29
+ const padding = (Number.parseFloat(style.paddingInlineStart) || 0) + (Number.parseFloat(style.paddingInlineEnd) || 0);
30
+ result.message = Math.ceil(longest + padding);
31
+ message.style.inlineSize = `${result.message}px`;
32
+ }
33
+ const actions = copied.querySelector(":scope > [data-mp=\"actions\"]");
34
+ if (!actions || actions.offsetTop <= message.offsetTop + 1) return result;
35
+ result.under = true;
36
+ copied.setAttribute("data-under", "");
37
+ const rtl = getComputedStyle(copied).direction === "rtl";
38
+ const box = copied.getBoundingClientRect();
39
+ const row = actions.getBoundingClientRect();
40
+ const under = rtl ? row.right - box.right : box.left - row.left;
41
+ const parts = [...actions.children].map((child) => child.getBoundingClientRect());
42
+ if (parts.length > 0) {
43
+ const content = Math.max(...parts.map((part) => part.right)) - Math.min(...parts.map((part) => part.left));
44
+ result.body = Math.ceil(Math.max(message.offsetWidth, content - under));
45
+ }
46
+ return result;
47
+ }, open);
48
+ }
49
+ function fit(body) {
50
+ const message = body.querySelector(":scope > [data-mp=\"message\"]");
51
+ if (!message) return;
52
+ message.style.removeProperty("inline-size");
53
+ body.style.removeProperty("inline-size");
54
+ body.removeAttribute("data-under");
55
+ const fitted = measure(body);
56
+ if (fitted.message !== void 0) message.style.inlineSize = `${fitted.message}px`;
57
+ if (fitted.body !== void 0) body.style.inlineSize = `${fitted.body}px`;
58
+ if (fitted.under) body.setAttribute("data-under", "");
59
+ }
60
+ function RowsBody({ children }) {
61
+ const ref = (0, react.useRef)(null);
62
+ require_react.useIsomorphicLayoutEffect(() => {
63
+ if (ref.current) fit(ref.current);
64
+ });
65
+ (0, react.useEffect)(() => {
66
+ const refit = () => ref.current && fit(ref.current);
67
+ window.addEventListener("resize", refit);
68
+ return () => window.removeEventListener("resize", refit);
69
+ }, []);
70
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
71
+ ref,
72
+ "data-mp": "body",
73
+ children
74
+ });
75
+ }
76
+
77
+ exports.RowsBody = RowsBody;
@@ -0,0 +1,77 @@
1
+ "use client";
2
+
3
+ import { useEffect, useRef } from "react";
4
+ import { onCopy } from "../Pill/morph.mjs";
5
+ import { useIsomorphicLayoutEffect } from "../utils/react.mjs";
6
+ import { jsx } from "react/jsx-runtime";
7
+
8
+ // src/PillNotification/RowsBody.tsx
9
+ /** Measured on a copy of the pill, open and as it ends up: the pill itself may be on its way there (a
10
+ * circle growing into the notification, its size animating), the message wrapping at no width */
11
+ function measure(body) {
12
+ const pill = body.closest("[data-mp=\"pill\"]");
13
+ const index = pill ? [...pill.children].indexOf(body) : -1;
14
+ if (!pill || index < 0 || typeof document.createRange !== "function") return { under: false };
15
+ const open = (copy) => {
16
+ if (copy.dataset.presence === "rest" || copy.dataset.presence === "hidden") copy.dataset.presence = "compact";
17
+ };
18
+ return onCopy(pill, (copy) => {
19
+ const copied = copy.children[index];
20
+ const message = copied.querySelector(":scope > [data-mp=\"message\"]");
21
+ const result = { under: false };
22
+ if (!message) return result;
23
+ const range = document.createRange();
24
+ range.selectNodeContents(message);
25
+ const lines = [...range.getClientRects?.() ?? []].filter((line) => line.width > 0);
26
+ if (new Set(lines.map((line) => Math.round(line.top))).size > 1) {
27
+ const longest = Math.max(...lines.map((line) => line.right)) - Math.min(...lines.map((line) => line.left));
28
+ const style = getComputedStyle(message);
29
+ const padding = (Number.parseFloat(style.paddingInlineStart) || 0) + (Number.parseFloat(style.paddingInlineEnd) || 0);
30
+ result.message = Math.ceil(longest + padding);
31
+ message.style.inlineSize = `${result.message}px`;
32
+ }
33
+ const actions = copied.querySelector(":scope > [data-mp=\"actions\"]");
34
+ if (!actions || actions.offsetTop <= message.offsetTop + 1) return result;
35
+ result.under = true;
36
+ copied.setAttribute("data-under", "");
37
+ const rtl = getComputedStyle(copied).direction === "rtl";
38
+ const box = copied.getBoundingClientRect();
39
+ const row = actions.getBoundingClientRect();
40
+ const under = rtl ? row.right - box.right : box.left - row.left;
41
+ const parts = [...actions.children].map((child) => child.getBoundingClientRect());
42
+ if (parts.length > 0) {
43
+ const content = Math.max(...parts.map((part) => part.right)) - Math.min(...parts.map((part) => part.left));
44
+ result.body = Math.ceil(Math.max(message.offsetWidth, content - under));
45
+ }
46
+ return result;
47
+ }, open);
48
+ }
49
+ function fit(body) {
50
+ const message = body.querySelector(":scope > [data-mp=\"message\"]");
51
+ if (!message) return;
52
+ message.style.removeProperty("inline-size");
53
+ body.style.removeProperty("inline-size");
54
+ body.removeAttribute("data-under");
55
+ const fitted = measure(body);
56
+ if (fitted.message !== void 0) message.style.inlineSize = `${fitted.message}px`;
57
+ if (fitted.body !== void 0) body.style.inlineSize = `${fitted.body}px`;
58
+ if (fitted.under) body.setAttribute("data-under", "");
59
+ }
60
+ function RowsBody({ children }) {
61
+ const ref = useRef(null);
62
+ useIsomorphicLayoutEffect(() => {
63
+ if (ref.current) fit(ref.current);
64
+ });
65
+ useEffect(() => {
66
+ const refit = () => ref.current && fit(ref.current);
67
+ window.addEventListener("resize", refit);
68
+ return () => window.removeEventListener("resize", refit);
69
+ }, []);
70
+ return /* @__PURE__ */ jsx("div", {
71
+ ref,
72
+ "data-mp": "body",
73
+ children
74
+ });
75
+ }
76
+
77
+ export { RowsBody };
package/dist/forms.css CHANGED
@@ -246,6 +246,20 @@
246
246
  inline-size: 15rem;
247
247
  }
248
248
 
249
+ /* Short of room (PillForm/room.ts): the button folds its label, still
250
+ its name; the field keeps room to type in */
251
+ &[data-tight] [data-mp="action"][type="submit"][data-expanded]:not(:focus-visible) {
252
+ & [data-mp="action-body"] {
253
+ padding-inline-end: calc((var(--_mp-action-size) - 1.25rem) / 2);
254
+ }
255
+
256
+ & [data-mp="action-icon"] + [data-mp="label"] {
257
+ grid-template-columns: 0fr;
258
+ margin-inline-start: 0;
259
+ opacity: 0;
260
+ }
261
+ }
262
+
249
263
  /* No room for it: the outline tells, and it's still read out */
250
264
  & :is([data-mp="field-error"], [data-mp="form-error"]) {
251
265
  position: absolute;
@@ -1,9 +1,13 @@
1
1
  "use client";
2
2
 
3
3
  let react = require("react");
4
+ const require_morph = require("../Pill/morph.js");
4
5
  const require_PillAction = require("../Pill/PillAction.js");
5
6
  const require_parts = require("../Pill/parts.js");
6
7
  const require_store = require("../store/store.js");
8
+ const require_react = require("../utils/react.js");
9
+ const require_timing = require("../utils/timing.js");
10
+ const require_handoff = require("./handoff.js");
7
11
  let react_jsx_runtime = require("react/jsx-runtime");
8
12
 
9
13
  // src/satellites/Actions.tsx
@@ -139,12 +143,13 @@ function useActionsWheel(track) {
139
143
  * a link or a button. `wheel`: cut short to that length, in px, turning to
140
144
  * show the others.
141
145
  */
142
- function ActionList({ items, host, wheel, inside }) {
146
+ function ActionList({ items, host, wheel, inside, leaving }) {
143
147
  const track = (0, react.useRef)(null);
144
148
  useActionsWheel(track);
145
149
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillActions, {
146
150
  ref: track,
147
151
  "data-inside": inside ? "" : void 0,
152
+ "data-leaving": leaving ? "" : void 0,
148
153
  "data-wheel": wheel !== void 0 ? "" : void 0,
149
154
  style: wheel !== void 0 ? { "--_mp-wheel-length": `${wheel}px` } : void 0,
150
155
  children: items.map((item) => item.href !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillAction, {
@@ -162,16 +167,186 @@ function ActionList({ items, host, wheel, inside }) {
162
167
  }, item.id ?? item.label))
163
168
  });
164
169
  }
165
- /** In the pill itself (`actionsStyle="inside"`): the actions, then a divider (the other way round on the end side). */
170
+ /** The actions in the pill opening or folding away (playInside), or held closed until they open */
171
+ const INSIDE = "mp-inside-actions";
172
+ /** Their row and its divider with nothing of them left: no length, no gap on either side of the divider */
173
+ function closedFrames(pill) {
174
+ const vertical = pill.dataset.orientation === "vertical";
175
+ const size = vertical ? "height" : "width";
176
+ const [start, end] = vertical ? ["marginBlockStart", "marginBlockEnd"] : ["marginInlineStart", "marginInlineEnd"];
177
+ const style = getComputedStyle(pill);
178
+ const gap = Number.parseFloat(vertical ? style.rowGap : style.columnGap) || 0;
179
+ return {
180
+ size,
181
+ start,
182
+ end,
183
+ list: {
184
+ opacity: 0,
185
+ [size]: "0px"
186
+ },
187
+ divider: {
188
+ opacity: 0,
189
+ [size]: "0px",
190
+ [start]: `${-gap}px`,
191
+ [end]: `${-gap}px`
192
+ }
193
+ };
194
+ }
195
+ /**
196
+ * The actions in the pill opening out of nothing as they come (their row growing, then showing), or
197
+ * folding back into nothing before they go: the pill follows its content at each frame, and the
198
+ * satellites follow the pill. Their divider and its gaps go with them. Undefined: no motion.
199
+ */
200
+ function playInside(list, divider, kind) {
201
+ const pill = list.closest("[data-mp=\"pill\"]");
202
+ if (!pill || typeof list.animate !== "function" || require_timing.prefersReducedMotion()) return void 0;
203
+ const { fade, change } = require_morph.readMorphTimings(pill);
204
+ if (fade + change <= 0) return void 0;
205
+ const closed = closedFrames(pill);
206
+ const { size, start, end } = closed;
207
+ const vertical = size === "height";
208
+ const length = vertical ? list.offsetHeight : list.offsetWidth;
209
+ const thickness = vertical ? divider.offsetHeight : divider.offsetWidth;
210
+ const grown = {
211
+ list: { [size]: `${length}px` },
212
+ divider: {
213
+ [size]: `${thickness}px`,
214
+ [start]: "0px",
215
+ [end]: "0px"
216
+ }
217
+ };
218
+ const frames = (part) => kind === "in" ? [
219
+ closed[part],
220
+ {
221
+ ...grown[part],
222
+ opacity: 0,
223
+ offset: change / (fade + change)
224
+ },
225
+ {
226
+ ...grown[part],
227
+ opacity: 1
228
+ }
229
+ ] : [
230
+ {
231
+ ...grown[part],
232
+ opacity: 1
233
+ },
234
+ {
235
+ ...grown[part],
236
+ opacity: 0,
237
+ offset: fade / (fade + change)
238
+ },
239
+ closed[part]
240
+ ];
241
+ const options = {
242
+ id: INSIDE,
243
+ duration: fade + change,
244
+ easing: "ease-in-out",
245
+ fill: kind === "out" ? "forwards" : "none"
246
+ };
247
+ list.style.overflow = "clip";
248
+ const animation = list.animate(frames("list"), options);
249
+ divider.animate(frames("divider"), options);
250
+ const done = () => list.style.removeProperty("overflow");
251
+ animation.finished.then(done, done);
252
+ return animation;
253
+ }
254
+ /** Stops their motion (an opening, a fold, the hold before they open) */
255
+ const stopInside = (...elements) => {
256
+ for (const element of elements) for (const animation of element?.getAnimations?.() ?? []) if (animation.id === INSIDE) animation.cancel();
257
+ };
258
+ /**
259
+ * In the pill itself (`actionsStyle="inside"`): the actions, then a divider (the other way round on
260
+ * the end side). They open out of nothing as they come, and fold away before they go. Switching to
261
+ * the pill, they wait for their own pill to go back into it; switching away, their own pill waits
262
+ * for them to have gone (handoff.ts).
263
+ */
166
264
  function InsideActions({ host }) {
167
265
  const items = useHostActions(host);
168
- if (!items) return null;
266
+ const handoff = require_handoff.useHandoff(host.store);
267
+ const inside = host.actionsStyle === "inside";
268
+ const [style, setStyle] = (0, react.useState)(host.actionsStyle);
269
+ const [waiting, setWaiting] = (0, react.useState)(false);
270
+ const waits = style !== host.actionsStyle ? inside && style === "detached" && !!items : waiting;
271
+ if (style !== host.actionsStyle) {
272
+ setStyle(host.actionsStyle);
273
+ setWaiting(waits);
274
+ }
275
+ (0, react.useEffect)(() => {
276
+ if (waiting) setWaiting(false);
277
+ }, [waiting]);
278
+ const wanted = inside && handoff !== "in" && !waits ? items : null;
279
+ const [shown, setShown] = (0, react.useState)(wanted);
280
+ if (wanted && wanted !== shown) setShown(wanted);
281
+ const listed = wanted ?? shown;
282
+ const leaving = !wanted && !!shown;
283
+ const divider = (0, react.useRef)(null);
284
+ const store = host.store;
285
+ const handingOut = leaving && !inside && !!items;
286
+ const open = !!listed && !leaving;
287
+ const sideOf = () => {
288
+ const line = divider.current;
289
+ return {
290
+ line,
291
+ list: (host.actionsSide === "end" ? line?.nextElementSibling : line?.previousElementSibling) ?? null
292
+ };
293
+ };
294
+ require_react.useIsomorphicLayoutEffect(() => {
295
+ const { line, list } = sideOf();
296
+ const pill = list?.closest("[data-mp=\"pill\"]");
297
+ if (!open || !line || !list || !pill || typeof list.animate !== "function" || require_timing.prefersReducedMotion()) return;
298
+ const closed = closedFrames(pill);
299
+ const hold = {
300
+ id: INSIDE,
301
+ duration: 6e4,
302
+ fill: "forwards"
303
+ };
304
+ list.style.overflow = "clip";
305
+ list.animate([closed.list, closed.list], hold);
306
+ line.animate([closed.divider, closed.divider], hold);
307
+ const frame = requestAnimationFrame(() => {
308
+ stopInside(list, line);
309
+ playInside(list, line, "in");
310
+ });
311
+ return () => {
312
+ cancelAnimationFrame(frame);
313
+ stopInside(list, line);
314
+ list.style.removeProperty("overflow");
315
+ };
316
+ }, [open]);
317
+ require_react.useIsomorphicLayoutEffect(() => {
318
+ if (!leaving) return;
319
+ if (handingOut) require_handoff.setHandoff(store, "out");
320
+ const { line, list } = sideOf();
321
+ let cancelled = false;
322
+ const gone = () => {
323
+ if (cancelled) return;
324
+ setShown(null);
325
+ if (require_handoff.getHandoff(store) === "out") require_handoff.setHandoff(store, void 0);
326
+ };
327
+ stopInside(list, line);
328
+ const animation = list && line ? playInside(list, line, "out") : void 0;
329
+ if (animation) animation.finished.then(gone, () => {});
330
+ else gone();
331
+ return () => {
332
+ cancelled = true;
333
+ stopInside(list, line);
334
+ list?.style.removeProperty("overflow");
335
+ if (require_handoff.getHandoff(store) === "out") require_handoff.setHandoff(store, void 0);
336
+ };
337
+ }, [leaving]);
338
+ if (!listed) return null;
169
339
  const list = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ActionList, {
170
- items,
340
+ items: listed,
171
341
  host,
172
- inside: true
342
+ inside: true,
343
+ leaving
344
+ });
345
+ const line = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillDivider, {
346
+ ref: divider,
347
+ "data-leaving": leaving ? "" : void 0
173
348
  });
174
- return host.actionsSide === "end" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillDivider, {}), list] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [list, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillDivider, {})] });
349
+ return host.actionsSide === "end" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [line, list] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [list, line] });
175
350
  }
176
351
 
177
352
  exports.ActionList = ActionList;