magic-pill 9.4.0-next.2 → 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 (51) hide show
  1. package/CHANGELOG.md +38 -2
  2. package/README.md +25 -17
  3. package/dist/MagicPill/MagicPill.d.mts +16 -2
  4. package/dist/MagicPill/MagicPill.d.ts +16 -2
  5. package/dist/MagicPill/MagicPill.js +12 -3
  6. package/dist/MagicPill/MagicPill.mjs +12 -3
  7. package/dist/Pill/Pill.js +1 -0
  8. package/dist/Pill/Pill.mjs +1 -0
  9. package/dist/Pill/goo.js +110 -35
  10. package/dist/Pill/goo.mjs +110 -36
  11. package/dist/Pill/modal.js +3 -1
  12. package/dist/Pill/modal.mjs +3 -1
  13. package/dist/Pill/morph.js +64 -10
  14. package/dist/Pill/morph.mjs +64 -11
  15. package/dist/Pill/zone.js +1 -2
  16. package/dist/Pill/zone.mjs +1 -2
  17. package/dist/PillForm/PillForm.js +6 -1
  18. package/dist/PillForm/PillForm.mjs +7 -2
  19. package/dist/PillForm/dates.js +14 -3
  20. package/dist/PillForm/dates.mjs +14 -3
  21. package/dist/PillForm/room.js +46 -0
  22. package/dist/PillForm/room.mjs +46 -0
  23. package/dist/PillNavbar/PillNavbar.js +3 -1
  24. package/dist/PillNavbar/PillNavbar.mjs +4 -2
  25. package/dist/PillNavbar/room.js +99 -24
  26. package/dist/PillNavbar/room.mjs +98 -25
  27. package/dist/PillNotification/PillNotification.js +2 -4
  28. package/dist/PillNotification/PillNotification.mjs +2 -4
  29. package/dist/PillNotification/RowsBody.js +77 -0
  30. package/dist/PillNotification/RowsBody.mjs +77 -0
  31. package/dist/forms.css +14 -0
  32. package/dist/satellites/Actions.js +181 -6
  33. package/dist/satellites/Actions.mjs +182 -7
  34. package/dist/satellites/Orbitals.js +218 -50
  35. package/dist/satellites/Orbitals.mjs +220 -52
  36. package/dist/satellites/Satellites.js +495 -107
  37. package/dist/satellites/Satellites.mjs +498 -111
  38. package/dist/satellites/handoff.js +36 -0
  39. package/dist/satellites/handoff.mjs +34 -0
  40. package/dist/satellites/layout.js +69 -3
  41. package/dist/satellites/layout.mjs +69 -4
  42. package/dist/satellites/measure.js +22 -0
  43. package/dist/satellites/measure.mjs +22 -1
  44. package/dist/satellites/orbits.js +49 -2
  45. package/dist/satellites/orbits.mjs +47 -3
  46. package/dist/satellites/types.d.mts +15 -1
  47. package/dist/satellites/types.d.ts +15 -1
  48. package/dist/satellites.d.mts +2 -2
  49. package/dist/satellites.d.ts +2 -2
  50. package/dist/styles.css +103 -15
  51. package/package.json +1 -1
@@ -1,21 +1,33 @@
1
1
  "use client";
2
2
 
3
3
  let react = require("react");
4
+ const require_react = require("../utils/react.js");
4
5
 
5
6
  // src/PillNavbar/room.ts
6
7
  const ACTION = "[data-mp=\"action\"]";
7
- /** A copy of the pill with its navbar, laid out next to it, hidden, to measure. Removed by the caller. */
8
- function layOutCopy(pill, prepare) {
8
+ /**
9
+ * A copy of the pill (and its navbar, if it has one), laid out next to it, hidden, to measure.
10
+ * Removed by the caller. `free`: without the room its satellites take beside it (what they plan
11
+ * with: measured within it, the pill would only seem to fit what they left it the time before).
12
+ */
13
+ function layOutCopy(pill, prepare = () => {}, free = false, presence) {
9
14
  const copy = pill.cloneNode(false);
10
- for (const child of pill.children) if (child.getAttribute("data-mp") !== "panel") copy.append(child.cloneNode(true));
15
+ const side = copy.dataset.placement === "left" || copy.dataset.placement === "right";
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);
19
+ if (copy.dataset.presence === "rest" || copy.dataset.presence === "hidden") copy.dataset.presence = "compact";
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));
11
22
  copy.querySelectorAll("[id], [name]").forEach((node) => {
12
23
  node.removeAttribute("id");
13
24
  node.removeAttribute("name");
14
25
  });
15
26
  const navbar = copy.querySelector("[data-mp=\"navbar\"]");
16
- if (!navbar) return null;
17
- navbar.removeAttribute("data-tight");
18
- prepare(navbar);
27
+ if (navbar) {
28
+ navbar.removeAttribute("data-tight");
29
+ prepare(navbar);
30
+ }
19
31
  copy.querySelectorAll("[data-mp=\"navbar\"], [data-mp=\"actions\"], [data-mp=\"action\"]").forEach((node) => {
20
32
  node.style.flexShrink = "0";
21
33
  });
@@ -33,17 +45,16 @@ function layOutCopy(pill, prepare) {
33
45
  * even if it's folded). Laid out on a copy, removed before anything is
34
46
  * painted: the labels on screen may be moving, and the app's own styles count.
35
47
  */
36
- function fitsWith(navbar, item, { unfold = false } = {}) {
48
+ function fitsWith(navbar, item, { unfold = false, presence } = {}) {
37
49
  const pill = navbar.closest("[data-mp=\"pill\"]");
38
50
  if (!pill) return true;
39
51
  const index = item ? [...navbar.querySelectorAll(ACTION)].indexOf(item) : -1;
40
- const laidOut = layOutCopy(pill, (copied) => {
41
- if (unfold) copied.removeAttribute("data-folded");
42
- if (index >= 0) copied.querySelectorAll(ACTION)[index]?.setAttribute("data-expanded", "");
43
- });
44
- if (!laidOut) return true;
45
- const fits = isInside(laidOut.navbar, laidOut.copy);
46
- laidOut.copy.remove();
52
+ const { copy, navbar: copied } = layOutCopy(pill, (laidOut) => {
53
+ if (unfold) laidOut.removeAttribute("data-folded");
54
+ if (index >= 0) laidOut.querySelectorAll(ACTION)[index]?.setAttribute("data-expanded", "");
55
+ }, false, presence);
56
+ const fits = !copied || isInside(copied, copy);
57
+ copy.remove();
47
58
  return fits;
48
59
  }
49
60
  /**
@@ -51,21 +62,62 @@ function fitsWith(navbar, item, { unfold = false } = {}) {
51
62
  * if it has no navbar that can fold them (`labels="current"`). The
52
63
  * satellites ask, to know whether an electron fits next to it.
53
64
  */
54
- function foldedWidth(pill) {
65
+ function foldedWidth(pill, { content = false } = {}) {
55
66
  const navbar = pill.querySelector("[data-mp=\"navbar\"]");
56
67
  if (!navbar || navbar.dataset.labels === "current") return pill.offsetWidth;
57
- const laidOut = layOutCopy(pill, (copied) => copied.setAttribute("data-folded", ""));
58
- if (!laidOut) return pill.offsetWidth;
59
- const width = laidOut.copy.offsetWidth;
60
- laidOut.copy.remove();
68
+ const { copy } = layOutCopy(pill, (copied) => copied.setAttribute("data-folded", ""), true);
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));
85
+ copy.remove();
61
86
  return width;
62
87
  }
63
- /** Whether the navbar ends before the pill's padding does. */
88
+ /**
89
+ * How big the pill is open, laid out on a copy: what a pill closed to a
90
+ * circle (on its way to another placement) opens to. The satellites ask,
91
+ * to give it its room and its spot before it opens.
92
+ */
93
+ function openSize(pill) {
94
+ const { copy } = layOutCopy(pill, void 0, true);
95
+ const size = {
96
+ width: copy.offsetWidth,
97
+ height: copy.offsetHeight
98
+ };
99
+ copy.remove();
100
+ return size;
101
+ }
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
+ */
64
107
  function isInside(navbar, pill) {
65
108
  const style = getComputedStyle(pill);
66
109
  const room = pill.clientWidth - (parseFloat(style.paddingLeft) || 0) - (parseFloat(style.paddingRight) || 0);
67
- 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;
68
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}`;
69
121
  const isHorizontal = (navbar) => {
70
122
  const pill = navbar.closest("[data-mp=\"pill\"]");
71
123
  return pill?.dataset.orientation === "horizontal" && pill.dataset.unstyled === void 0;
@@ -75,7 +127,16 @@ const isHorizontal = (navbar) => {
75
127
  * the keyboard) has no room for its label next to the open ones, and
76
128
  * `data-folded` while the current page's label folds at rest (`labels`).
77
129
  */
78
- function useRoom(ref, labels = "auto") {
130
+ function useRoom(ref, labels = "auto", presence) {
131
+ require_react.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]);
79
140
  (0, react.useEffect)(() => {
80
141
  const navbar = ref.current;
81
142
  if (!navbar) return;
@@ -89,11 +150,21 @@ function useRoom(ref, labels = "auto") {
89
150
  }
90
151
  const pill = navbar.closest("[data-mp=\"pill\"]");
91
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
+ };
92
159
  const update = () => {
93
160
  cancelAnimationFrame(frame);
94
- frame = requestAnimationFrame(() => fold(isHorizontal(navbar) && !fitsWith(navbar, null, { unfold: true })));
161
+ frame = requestAnimationFrame(check);
162
+ };
163
+ const fontsLoaded = () => {
164
+ decided = "";
165
+ update();
95
166
  };
96
- fold(isHorizontal(navbar) && !fitsWith(navbar, null, { unfold: true }));
167
+ check();
97
168
  const mutations = new MutationObserver(update);
98
169
  mutations.observe(navbar, {
99
170
  subtree: true,
@@ -111,11 +182,13 @@ function useRoom(ref, labels = "auto") {
111
182
  const sizes = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(update);
112
183
  if (pill) sizes?.observe(pill);
113
184
  window.addEventListener("resize", update);
185
+ document.fonts?.addEventListener?.("loadingdone", fontsLoaded);
114
186
  return () => {
115
187
  cancelAnimationFrame(frame);
116
188
  mutations.disconnect();
117
189
  sizes?.disconnect();
118
190
  window.removeEventListener("resize", update);
191
+ document.fonts?.removeEventListener?.("loadingdone", fontsLoaded);
119
192
  fold(false);
120
193
  };
121
194
  }, [ref, labels]);
@@ -153,4 +226,6 @@ function useRoom(ref, labels = "auto") {
153
226
 
154
227
  exports.fitsWith = fitsWith;
155
228
  exports.foldedWidth = foldedWidth;
229
+ exports.openSize = openSize;
230
+ exports.unfoldedWidth = unfoldedWidth;
156
231
  exports.useRoom = useRoom;
@@ -1,21 +1,33 @@
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\"]";
7
- /** A copy of the pill with its navbar, laid out next to it, hidden, to measure. Removed by the caller. */
8
- function layOutCopy(pill, prepare) {
8
+ /**
9
+ * A copy of the pill (and its navbar, if it has one), laid out next to it, hidden, to measure.
10
+ * Removed by the caller. `free`: without the room its satellites take beside it (what they plan
11
+ * with: measured within it, the pill would only seem to fit what they left it the time before).
12
+ */
13
+ function layOutCopy(pill, prepare = () => {}, free = false, presence) {
9
14
  const copy = pill.cloneNode(false);
10
- for (const child of pill.children) if (child.getAttribute("data-mp") !== "panel") copy.append(child.cloneNode(true));
15
+ const side = copy.dataset.placement === "left" || copy.dataset.placement === "right";
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);
19
+ if (copy.dataset.presence === "rest" || copy.dataset.presence === "hidden") copy.dataset.presence = "compact";
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));
11
22
  copy.querySelectorAll("[id], [name]").forEach((node) => {
12
23
  node.removeAttribute("id");
13
24
  node.removeAttribute("name");
14
25
  });
15
26
  const navbar = copy.querySelector("[data-mp=\"navbar\"]");
16
- if (!navbar) return null;
17
- navbar.removeAttribute("data-tight");
18
- prepare(navbar);
27
+ if (navbar) {
28
+ navbar.removeAttribute("data-tight");
29
+ prepare(navbar);
30
+ }
19
31
  copy.querySelectorAll("[data-mp=\"navbar\"], [data-mp=\"actions\"], [data-mp=\"action\"]").forEach((node) => {
20
32
  node.style.flexShrink = "0";
21
33
  });
@@ -33,17 +45,16 @@ function layOutCopy(pill, prepare) {
33
45
  * even if it's folded). Laid out on a copy, removed before anything is
34
46
  * painted: the labels on screen may be moving, and the app's own styles count.
35
47
  */
36
- function fitsWith(navbar, item, { unfold = false } = {}) {
48
+ function fitsWith(navbar, item, { unfold = false, presence } = {}) {
37
49
  const pill = navbar.closest("[data-mp=\"pill\"]");
38
50
  if (!pill) return true;
39
51
  const index = item ? [...navbar.querySelectorAll(ACTION)].indexOf(item) : -1;
40
- const laidOut = layOutCopy(pill, (copied) => {
41
- if (unfold) copied.removeAttribute("data-folded");
42
- if (index >= 0) copied.querySelectorAll(ACTION)[index]?.setAttribute("data-expanded", "");
43
- });
44
- if (!laidOut) return true;
45
- const fits = isInside(laidOut.navbar, laidOut.copy);
46
- laidOut.copy.remove();
52
+ const { copy, navbar: copied } = layOutCopy(pill, (laidOut) => {
53
+ if (unfold) laidOut.removeAttribute("data-folded");
54
+ if (index >= 0) laidOut.querySelectorAll(ACTION)[index]?.setAttribute("data-expanded", "");
55
+ }, false, presence);
56
+ const fits = !copied || isInside(copied, copy);
57
+ copy.remove();
47
58
  return fits;
48
59
  }
49
60
  /**
@@ -51,21 +62,62 @@ function fitsWith(navbar, item, { unfold = false } = {}) {
51
62
  * if it has no navbar that can fold them (`labels="current"`). The
52
63
  * satellites ask, to know whether an electron fits next to it.
53
64
  */
54
- function foldedWidth(pill) {
65
+ function foldedWidth(pill, { content = false } = {}) {
55
66
  const navbar = pill.querySelector("[data-mp=\"navbar\"]");
56
67
  if (!navbar || navbar.dataset.labels === "current") return pill.offsetWidth;
57
- const laidOut = layOutCopy(pill, (copied) => copied.setAttribute("data-folded", ""));
58
- if (!laidOut) return pill.offsetWidth;
59
- const width = laidOut.copy.offsetWidth;
60
- laidOut.copy.remove();
68
+ const { copy } = layOutCopy(pill, (copied) => copied.setAttribute("data-folded", ""), true);
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));
85
+ copy.remove();
61
86
  return width;
62
87
  }
63
- /** Whether the navbar ends before the pill's padding does. */
88
+ /**
89
+ * How big the pill is open, laid out on a copy: what a pill closed to a
90
+ * circle (on its way to another placement) opens to. The satellites ask,
91
+ * to give it its room and its spot before it opens.
92
+ */
93
+ function openSize(pill) {
94
+ const { copy } = layOutCopy(pill, void 0, true);
95
+ const size = {
96
+ width: copy.offsetWidth,
97
+ height: copy.offsetHeight
98
+ };
99
+ copy.remove();
100
+ return size;
101
+ }
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
+ */
64
107
  function isInside(navbar, pill) {
65
108
  const style = getComputedStyle(pill);
66
109
  const room = pill.clientWidth - (parseFloat(style.paddingLeft) || 0) - (parseFloat(style.paddingRight) || 0);
67
- 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;
68
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}`;
69
121
  const isHorizontal = (navbar) => {
70
122
  const pill = navbar.closest("[data-mp=\"pill\"]");
71
123
  return pill?.dataset.orientation === "horizontal" && pill.dataset.unstyled === void 0;
@@ -75,7 +127,16 @@ const isHorizontal = (navbar) => {
75
127
  * the keyboard) has no room for its label next to the open ones, and
76
128
  * `data-folded` while the current page's label folds at rest (`labels`).
77
129
  */
78
- 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]);
79
140
  useEffect(() => {
80
141
  const navbar = ref.current;
81
142
  if (!navbar) return;
@@ -89,11 +150,21 @@ function useRoom(ref, labels = "auto") {
89
150
  }
90
151
  const pill = navbar.closest("[data-mp=\"pill\"]");
91
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
+ };
92
159
  const update = () => {
93
160
  cancelAnimationFrame(frame);
94
- frame = requestAnimationFrame(() => fold(isHorizontal(navbar) && !fitsWith(navbar, null, { unfold: true })));
161
+ frame = requestAnimationFrame(check);
162
+ };
163
+ const fontsLoaded = () => {
164
+ decided = "";
165
+ update();
95
166
  };
96
- fold(isHorizontal(navbar) && !fitsWith(navbar, null, { unfold: true }));
167
+ check();
97
168
  const mutations = new MutationObserver(update);
98
169
  mutations.observe(navbar, {
99
170
  subtree: true,
@@ -111,11 +182,13 @@ function useRoom(ref, labels = "auto") {
111
182
  const sizes = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(update);
112
183
  if (pill) sizes?.observe(pill);
113
184
  window.addEventListener("resize", update);
185
+ document.fonts?.addEventListener?.("loadingdone", fontsLoaded);
114
186
  return () => {
115
187
  cancelAnimationFrame(frame);
116
188
  mutations.disconnect();
117
189
  sizes?.disconnect();
118
190
  window.removeEventListener("resize", update);
191
+ document.fonts?.removeEventListener?.("loadingdone", fontsLoaded);
119
192
  fold(false);
120
193
  };
121
194
  }, [ref, labels]);
@@ -151,4 +224,4 @@ function useRoom(ref, labels = "auto") {
151
224
  }, [ref]);
152
225
  }
153
226
 
154
- export { fitsWith, foldedWidth, 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;