magic-pill 9.2.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 (96) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/MIGRATING.md +2 -0
  3. package/README.md +158 -17
  4. package/dist/MagicPill/MagicPill.d.mts +43 -1
  5. package/dist/MagicPill/MagicPill.d.ts +43 -1
  6. package/dist/MagicPill/MagicPill.js +53 -6
  7. package/dist/MagicPill/MagicPill.mjs +56 -9
  8. package/dist/MagicPill/flag.js +1 -59
  9. package/dist/MagicPill/flag.mjs +1 -58
  10. package/dist/MagicPill/useChoreography.js +2 -1
  11. package/dist/MagicPill/useChoreography.mjs +3 -2
  12. package/dist/Pill/PillProgress.d.mts +12 -0
  13. package/dist/Pill/PillProgress.d.ts +12 -0
  14. package/dist/Pill/PillProgress.js +42 -0
  15. package/dist/Pill/PillProgress.mjs +42 -0
  16. package/dist/Pill/goo.js +353 -0
  17. package/dist/Pill/goo.mjs +347 -0
  18. package/dist/Pill/modal.js +2 -1
  19. package/dist/Pill/modal.mjs +3 -2
  20. package/dist/Pill/morph.js +7 -4
  21. package/dist/Pill/morph.mjs +8 -5
  22. package/dist/Pill/travel.js +2 -1
  23. package/dist/Pill/travel.mjs +3 -2
  24. package/dist/Pill/zone.js +3 -2
  25. package/dist/Pill/zone.mjs +4 -3
  26. package/dist/PillForm/PillSubmit.js +1 -1
  27. package/dist/PillForm/PillSubmit.mjs +3 -3
  28. package/dist/PillForm/popover.js +2 -1
  29. package/dist/PillForm/popover.mjs +3 -2
  30. package/dist/PillNavbar/PillNavbar.d.mts +8 -0
  31. package/dist/PillNavbar/PillNavbar.d.ts +8 -0
  32. package/dist/PillNavbar/PillNavbar.js +3 -2
  33. package/dist/PillNavbar/PillNavbar.mjs +3 -2
  34. package/dist/PillNavbar/room.d.mts +3 -0
  35. package/dist/PillNavbar/room.d.ts +2 -0
  36. package/dist/PillNavbar/room.js +89 -17
  37. package/dist/PillNavbar/room.mjs +89 -18
  38. package/dist/PillOptics/PillOptics.js +2 -1
  39. package/dist/PillOptics/PillOptics.mjs +3 -2
  40. package/dist/forms.css +2 -1
  41. package/dist/index.d.mts +30 -15
  42. package/dist/index.d.ts +30 -15
  43. package/dist/index.js +40 -12
  44. package/dist/index.mjs +40 -13
  45. package/dist/satellites/Actions.d.mts +12 -0
  46. package/dist/satellites/Actions.d.ts +11 -0
  47. package/dist/satellites/Actions.js +59 -0
  48. package/dist/satellites/Actions.mjs +56 -0
  49. package/dist/satellites/Orbitals.js +554 -0
  50. package/dist/satellites/Orbitals.mjs +554 -0
  51. package/dist/satellites/Satellites.js +400 -0
  52. package/dist/satellites/Satellites.mjs +400 -0
  53. package/dist/satellites/layout.js +156 -0
  54. package/dist/satellites/layout.mjs +156 -0
  55. package/dist/satellites/measure.js +25 -0
  56. package/dist/satellites/measure.mjs +24 -0
  57. package/dist/satellites/orbits.js +139 -0
  58. package/dist/satellites/orbits.mjs +136 -0
  59. package/dist/satellites/types.d.mts +54 -0
  60. package/dist/satellites/types.d.ts +54 -0
  61. package/dist/satellites.d.mts +5 -0
  62. package/dist/satellites.d.ts +5 -0
  63. package/dist/satellites.js +14 -0
  64. package/dist/satellites.mjs +12 -0
  65. package/dist/store/store.d.mts +103 -0
  66. package/dist/store/store.d.ts +103 -0
  67. package/dist/store/store.js +52 -1
  68. package/dist/store/store.mjs +52 -2
  69. package/dist/styles.css +174 -10
  70. package/dist/utils/react.js +8 -1
  71. package/dist/utils/react.mjs +8 -2
  72. package/package.json +12 -2
  73. package/dist/icons/ArrowIcon.d.mts +0 -4
  74. package/dist/icons/ArrowIcon.d.ts +0 -4
  75. package/dist/icons/BoxIcon.d.mts +0 -4
  76. package/dist/icons/BoxIcon.d.ts +0 -4
  77. package/dist/icons/CheckIcon.d.mts +0 -4
  78. package/dist/icons/CheckIcon.d.ts +0 -4
  79. package/dist/icons/CloseIcon.d.mts +0 -4
  80. package/dist/icons/CloseIcon.d.ts +0 -4
  81. package/dist/icons/CouponIcon.d.mts +0 -4
  82. package/dist/icons/CouponIcon.d.ts +0 -4
  83. package/dist/icons/DocumentIcon.d.mts +0 -4
  84. package/dist/icons/DocumentIcon.d.ts +0 -4
  85. package/dist/icons/HelpIcon.d.mts +0 -4
  86. package/dist/icons/HelpIcon.d.ts +0 -4
  87. package/dist/icons/InfoIcon.d.mts +0 -4
  88. package/dist/icons/InfoIcon.d.ts +0 -4
  89. package/dist/icons/MailIcon.d.mts +0 -4
  90. package/dist/icons/MailIcon.d.ts +0 -4
  91. package/dist/icons/PhoneIcon.d.mts +0 -4
  92. package/dist/icons/PhoneIcon.d.ts +0 -4
  93. package/dist/icons/PlusIcon.d.mts +0 -4
  94. package/dist/icons/PlusIcon.d.ts +0 -4
  95. package/dist/icons/UndoIcon.d.mts +0 -4
  96. package/dist/icons/UndoIcon.d.ts +0 -4
@@ -53,6 +53,81 @@ export interface PillQueueState {
53
53
  /** The ones waiting behind it, first in, first out. */
54
54
  readonly queued: readonly QueuedNotification[];
55
55
  }
56
+ /** One of the current page's actions, next to the pill (beta, `magic-pill/satellites`). */
57
+ export interface PillActionItem {
58
+ icon: ReactNode;
59
+ /** Its name: shown on hover and focus, or all the time with `expanded` */
60
+ label: string;
61
+ onClick?: (event: {
62
+ preventDefault(): void;
63
+ }) => void;
64
+ /** A link instead (with the host's `linkComponent`) */
65
+ href?: string;
66
+ expanded?: boolean;
67
+ id?: string;
68
+ }
69
+ /** One of an electron's quick actions (beta). */
70
+ export interface Orbital {
71
+ icon: ReactNode;
72
+ /** Its name: shown next to it while it's under the finger, the pointer or the focus */
73
+ label: string;
74
+ onClick?: (event: {
75
+ preventDefault(): void;
76
+ }) => void;
77
+ /** A link instead (with the host's `linkComponent`) */
78
+ href?: string;
79
+ id?: string;
80
+ }
81
+ /**
82
+ * An electron (beta): a small round pill that splits out of the host to keep
83
+ * a background activity (a timer, an upload…) in reach while the person goes
84
+ * elsewhere in the app. Shown by `magic-pill/satellites`, passed to the host.
85
+ */
86
+ export interface ElectronOptions {
87
+ /** Its accessible name, e.g. "Focus timer". */
88
+ label: string;
89
+ /** A short live text, e.g. "4:34" or "64%". */
90
+ value?: string;
91
+ /**
92
+ * What screen readers read for the value, e.g. "4 minutes left". Default:
93
+ * `value`. Round it, so that the name doesn't change every second.
94
+ */
95
+ valueText?: string;
96
+ /** An icon; with `progress` and no `value`, it sits inside the ring. */
97
+ icon?: ReactNode;
98
+ /** 0 to 1: draws a progress ring around its content. */
99
+ progress?: number;
100
+ variant?: PillVariant;
101
+ /** Where it came from: a tap goes back there. Default: the path it was started on. */
102
+ href?: string;
103
+ /** Instead of going back: what a tap does. */
104
+ onClick?: (event: {
105
+ preventDefault(): void;
106
+ }) => void;
107
+ /** Tucked into the pill while the current path is its `href` (needs the host's `pathname`). Default true. */
108
+ hideOnOrigin?: boolean;
109
+ /** How it leaves when it ends: back into the pill ("join") or scaling out ("pop"). Default: the host's. */
110
+ ending?: "join" | "pop";
111
+ /** Said once by screen readers whenever it changes, for a milestone ("Break time"). */
112
+ announce?: string;
113
+ /** Your own content instead of the ring, the value and the icon. */
114
+ render?: () => ReactNode;
115
+ /**
116
+ * Its quick actions: a long press (or hovering it with a mouse, or a tap,
117
+ * see the host's `orbitalsOpenOn`) fans them out around it.
118
+ */
119
+ orbitals?: readonly Orbital[];
120
+ /** The label of the orbital that goes back, when a tap opens them (`orbitalsOpenOn="tap"`). Default "Back". */
121
+ backLabel?: string;
122
+ /** Starting an electron with an id that's already there updates it in place. */
123
+ id?: string;
124
+ }
125
+ export interface Electron {
126
+ readonly id: string;
127
+ readonly input: ElectronOptions;
128
+ /** Where a tap takes the person back to: its `href`, or the path it was started on */
129
+ readonly origin: string | undefined;
130
+ }
56
131
  export interface PillController {
57
132
  readonly name: string;
58
133
  /**
@@ -65,6 +140,34 @@ export interface PillController {
65
140
  dismiss: (id?: string) => void;
66
141
  /** Empty the queue and dismiss the visible notification. */
67
142
  clear: () => void;
143
+ /** Start an electron (beta, `magic-pill/satellites`). Returns its id. */
144
+ electron: (input: ElectronOptions) => string;
145
+ /** Change an electron's options, e.g. its value every second. */
146
+ updateElectron: (id: string, patch: Partial<ElectronOptions>) => void;
147
+ /** End an electron: it joins back into the pill (or pops away). */
148
+ endElectron: (id: string) => void;
149
+ /**
150
+ * The current page's actions, next to the pill (beta, `magic-pill/satellites`);
151
+ * `null` or none: they go. `usePillActions()` does it for a page while it's mounted.
152
+ */
153
+ setActions: (items: readonly PillActionItem[] | null) => void;
154
+ }
155
+ /** One named pill's queue. Internal: the host uses more than the controller exposes. */
156
+ export interface PillStore {
157
+ getState: () => PillQueueState;
158
+ subscribe: (listener: () => void) => () => void;
159
+ notify: (input: NotifyInput) => string;
160
+ update: (id: string, patch: Partial<NotifyOptions>) => void;
161
+ dismiss: (id: string | undefined, reason: DismissReason) => void;
162
+ clear: () => void;
163
+ /** Counts mounted hosts, to warn about two hosts with the same name. Returns the cleanup. */
164
+ registerHost: () => () => void;
165
+ getElectrons: () => readonly Electron[];
166
+ electron: (input: ElectronOptions) => string;
167
+ updateElectron: (id: string, patch: Partial<ElectronOptions>) => void;
168
+ endElectron: (id: string) => void;
169
+ getActions: () => readonly PillActionItem[] | null;
170
+ setActions: (items: readonly PillActionItem[] | null) => void;
68
171
  }
69
172
  /** Control the <MagicPill> with this name (default "main") from anywhere. */
70
173
  export declare function pill(name?: string): PillController;
@@ -53,6 +53,81 @@ export interface PillQueueState {
53
53
  /** The ones waiting behind it, first in, first out. */
54
54
  readonly queued: readonly QueuedNotification[];
55
55
  }
56
+ /** One of the current page's actions, next to the pill (beta, `magic-pill/satellites`). */
57
+ export interface PillActionItem {
58
+ icon: ReactNode;
59
+ /** Its name: shown on hover and focus, or all the time with `expanded` */
60
+ label: string;
61
+ onClick?: (event: {
62
+ preventDefault(): void;
63
+ }) => void;
64
+ /** A link instead (with the host's `linkComponent`) */
65
+ href?: string;
66
+ expanded?: boolean;
67
+ id?: string;
68
+ }
69
+ /** One of an electron's quick actions (beta). */
70
+ export interface Orbital {
71
+ icon: ReactNode;
72
+ /** Its name: shown next to it while it's under the finger, the pointer or the focus */
73
+ label: string;
74
+ onClick?: (event: {
75
+ preventDefault(): void;
76
+ }) => void;
77
+ /** A link instead (with the host's `linkComponent`) */
78
+ href?: string;
79
+ id?: string;
80
+ }
81
+ /**
82
+ * An electron (beta): a small round pill that splits out of the host to keep
83
+ * a background activity (a timer, an upload…) in reach while the person goes
84
+ * elsewhere in the app. Shown by `magic-pill/satellites`, passed to the host.
85
+ */
86
+ export interface ElectronOptions {
87
+ /** Its accessible name, e.g. "Focus timer". */
88
+ label: string;
89
+ /** A short live text, e.g. "4:34" or "64%". */
90
+ value?: string;
91
+ /**
92
+ * What screen readers read for the value, e.g. "4 minutes left". Default:
93
+ * `value`. Round it, so that the name doesn't change every second.
94
+ */
95
+ valueText?: string;
96
+ /** An icon; with `progress` and no `value`, it sits inside the ring. */
97
+ icon?: ReactNode;
98
+ /** 0 to 1: draws a progress ring around its content. */
99
+ progress?: number;
100
+ variant?: PillVariant;
101
+ /** Where it came from: a tap goes back there. Default: the path it was started on. */
102
+ href?: string;
103
+ /** Instead of going back: what a tap does. */
104
+ onClick?: (event: {
105
+ preventDefault(): void;
106
+ }) => void;
107
+ /** Tucked into the pill while the current path is its `href` (needs the host's `pathname`). Default true. */
108
+ hideOnOrigin?: boolean;
109
+ /** How it leaves when it ends: back into the pill ("join") or scaling out ("pop"). Default: the host's. */
110
+ ending?: "join" | "pop";
111
+ /** Said once by screen readers whenever it changes, for a milestone ("Break time"). */
112
+ announce?: string;
113
+ /** Your own content instead of the ring, the value and the icon. */
114
+ render?: () => ReactNode;
115
+ /**
116
+ * Its quick actions: a long press (or hovering it with a mouse, or a tap,
117
+ * see the host's `orbitalsOpenOn`) fans them out around it.
118
+ */
119
+ orbitals?: readonly Orbital[];
120
+ /** The label of the orbital that goes back, when a tap opens them (`orbitalsOpenOn="tap"`). Default "Back". */
121
+ backLabel?: string;
122
+ /** Starting an electron with an id that's already there updates it in place. */
123
+ id?: string;
124
+ }
125
+ export interface Electron {
126
+ readonly id: string;
127
+ readonly input: ElectronOptions;
128
+ /** Where a tap takes the person back to: its `href`, or the path it was started on */
129
+ readonly origin: string | undefined;
130
+ }
56
131
  export interface PillController {
57
132
  readonly name: string;
58
133
  /**
@@ -65,6 +140,34 @@ export interface PillController {
65
140
  dismiss: (id?: string) => void;
66
141
  /** Empty the queue and dismiss the visible notification. */
67
142
  clear: () => void;
143
+ /** Start an electron (beta, `magic-pill/satellites`). Returns its id. */
144
+ electron: (input: ElectronOptions) => string;
145
+ /** Change an electron's options, e.g. its value every second. */
146
+ updateElectron: (id: string, patch: Partial<ElectronOptions>) => void;
147
+ /** End an electron: it joins back into the pill (or pops away). */
148
+ endElectron: (id: string) => void;
149
+ /**
150
+ * The current page's actions, next to the pill (beta, `magic-pill/satellites`);
151
+ * `null` or none: they go. `usePillActions()` does it for a page while it's mounted.
152
+ */
153
+ setActions: (items: readonly PillActionItem[] | null) => void;
154
+ }
155
+ /** One named pill's queue. Internal: the host uses more than the controller exposes. */
156
+ export interface PillStore {
157
+ getState: () => PillQueueState;
158
+ subscribe: (listener: () => void) => () => void;
159
+ notify: (input: NotifyInput) => string;
160
+ update: (id: string, patch: Partial<NotifyOptions>) => void;
161
+ dismiss: (id: string | undefined, reason: DismissReason) => void;
162
+ clear: () => void;
163
+ /** Counts mounted hosts, to warn about two hosts with the same name. Returns the cleanup. */
164
+ registerHost: () => () => void;
165
+ getElectrons: () => readonly Electron[];
166
+ electron: (input: ElectronOptions) => string;
167
+ updateElectron: (id: string, patch: Partial<ElectronOptions>) => void;
168
+ endElectron: (id: string) => void;
169
+ getActions: () => readonly PillActionItem[] | null;
170
+ setActions: (items: readonly PillActionItem[] | null) => void;
68
171
  }
69
172
  /** Control the <MagicPill> with this name (default "main") from anywhere. */
70
173
  export declare function pill(name?: string): PillController;
@@ -1,6 +1,7 @@
1
1
  const require_react = require("../utils/react.js");
2
2
 
3
3
  // src/store/store.ts
4
+ const NO_ELECTRONS = Object.freeze([]);
4
5
  const EMPTY_STATE = Object.freeze({
5
6
  current: null,
6
7
  queued: Object.freeze([])
@@ -11,7 +12,13 @@ function createStore(name) {
11
12
  let items = [];
12
13
  let state = EMPTY_STATE;
13
14
  let hosts = 0;
15
+ let electrons = NO_ELECTRONS;
16
+ let actions = null;
14
17
  const listeners = /* @__PURE__ */ new Set();
18
+ const setElectrons = (next) => {
19
+ electrons = next.length === 0 ? NO_ELECTRONS : next;
20
+ listeners.forEach((listener) => listener());
21
+ };
15
22
  const commit = (next) => {
16
23
  items = next;
17
24
  state = next.length === 0 ? EMPTY_STATE : {
@@ -62,6 +69,45 @@ function createStore(name) {
62
69
  commit([]);
63
70
  dismissed.forEach((item) => item.input.onDismiss?.(item.id, "cleared"));
64
71
  },
72
+ getElectrons: () => electrons,
73
+ electron(input) {
74
+ const id = input.id ?? `mp-${++lastId}`;
75
+ if (isServer()) {
76
+ require_react.devWarn(`pill("${name}").electron() was called on the server and does nothing: call it from client code.`);
77
+ return id;
78
+ }
79
+ const existing = electrons.find((electron) => electron.id === id);
80
+ if (existing) setElectrons(electrons.map((electron) => electron === existing ? {
81
+ ...existing,
82
+ input
83
+ } : electron));
84
+ else setElectrons([...electrons, {
85
+ id,
86
+ input,
87
+ origin: input.href ?? window.location.pathname
88
+ }]);
89
+ return id;
90
+ },
91
+ updateElectron(id, patch) {
92
+ const existing = electrons.find((electron) => electron.id === id);
93
+ if (existing) setElectrons(electrons.map((electron) => electron === existing ? {
94
+ ...existing,
95
+ input: {
96
+ ...existing.input,
97
+ ...patch
98
+ }
99
+ } : electron));
100
+ },
101
+ endElectron(id) {
102
+ if (electrons.some((electron) => electron.id === id)) setElectrons(electrons.filter((electron) => electron.id !== id));
103
+ },
104
+ getActions: () => actions,
105
+ setActions(items) {
106
+ const next = items && items.length > 0 ? items : null;
107
+ if (next === actions) return;
108
+ actions = next;
109
+ listeners.forEach((listener) => listener());
110
+ },
65
111
  registerHost() {
66
112
  hosts += 1;
67
113
  if (hosts > 1) require_react.devWarn(`Several <MagicPill name="${name}"> are mounted. Give each one its own name.`);
@@ -92,7 +138,11 @@ function pill(name = "main") {
92
138
  notify: (input) => store.notify(input),
93
139
  update: (id, patch) => store.update(id, patch),
94
140
  dismiss: (id) => store.dismiss(id, "dismissed"),
95
- clear: () => store.clear()
141
+ clear: () => store.clear(),
142
+ electron: (input) => store.electron(input),
143
+ updateElectron: (id, patch) => store.updateElectron(id, patch),
144
+ endElectron: (id) => store.endElectron(id),
145
+ setActions: (items) => store.setActions(items)
96
146
  });
97
147
  controllers.set(name, controller);
98
148
  }
@@ -100,5 +150,6 @@ function pill(name = "main") {
100
150
  }
101
151
 
102
152
  exports.EMPTY_STATE = EMPTY_STATE;
153
+ exports.NO_ELECTRONS = NO_ELECTRONS;
103
154
  exports.getStore = getStore;
104
155
  exports.pill = pill;
@@ -1,6 +1,7 @@
1
1
  import { devWarn } from "../utils/react.mjs";
2
2
 
3
3
  // src/store/store.ts
4
+ const NO_ELECTRONS = Object.freeze([]);
4
5
  const EMPTY_STATE = Object.freeze({
5
6
  current: null,
6
7
  queued: Object.freeze([])
@@ -11,7 +12,13 @@ function createStore(name) {
11
12
  let items = [];
12
13
  let state = EMPTY_STATE;
13
14
  let hosts = 0;
15
+ let electrons = NO_ELECTRONS;
16
+ let actions = null;
14
17
  const listeners = /* @__PURE__ */ new Set();
18
+ const setElectrons = (next) => {
19
+ electrons = next.length === 0 ? NO_ELECTRONS : next;
20
+ listeners.forEach((listener) => listener());
21
+ };
15
22
  const commit = (next) => {
16
23
  items = next;
17
24
  state = next.length === 0 ? EMPTY_STATE : {
@@ -62,6 +69,45 @@ function createStore(name) {
62
69
  commit([]);
63
70
  dismissed.forEach((item) => item.input.onDismiss?.(item.id, "cleared"));
64
71
  },
72
+ getElectrons: () => electrons,
73
+ electron(input) {
74
+ const id = input.id ?? `mp-${++lastId}`;
75
+ if (isServer()) {
76
+ devWarn(`pill("${name}").electron() was called on the server and does nothing: call it from client code.`);
77
+ return id;
78
+ }
79
+ const existing = electrons.find((electron) => electron.id === id);
80
+ if (existing) setElectrons(electrons.map((electron) => electron === existing ? {
81
+ ...existing,
82
+ input
83
+ } : electron));
84
+ else setElectrons([...electrons, {
85
+ id,
86
+ input,
87
+ origin: input.href ?? window.location.pathname
88
+ }]);
89
+ return id;
90
+ },
91
+ updateElectron(id, patch) {
92
+ const existing = electrons.find((electron) => electron.id === id);
93
+ if (existing) setElectrons(electrons.map((electron) => electron === existing ? {
94
+ ...existing,
95
+ input: {
96
+ ...existing.input,
97
+ ...patch
98
+ }
99
+ } : electron));
100
+ },
101
+ endElectron(id) {
102
+ if (electrons.some((electron) => electron.id === id)) setElectrons(electrons.filter((electron) => electron.id !== id));
103
+ },
104
+ getActions: () => actions,
105
+ setActions(items) {
106
+ const next = items && items.length > 0 ? items : null;
107
+ if (next === actions) return;
108
+ actions = next;
109
+ listeners.forEach((listener) => listener());
110
+ },
65
111
  registerHost() {
66
112
  hosts += 1;
67
113
  if (hosts > 1) devWarn(`Several <MagicPill name="${name}"> are mounted. Give each one its own name.`);
@@ -92,11 +138,15 @@ function pill(name = "main") {
92
138
  notify: (input) => store.notify(input),
93
139
  update: (id, patch) => store.update(id, patch),
94
140
  dismiss: (id) => store.dismiss(id, "dismissed"),
95
- clear: () => store.clear()
141
+ clear: () => store.clear(),
142
+ electron: (input) => store.electron(input),
143
+ updateElectron: (id, patch) => store.updateElectron(id, patch),
144
+ endElectron: (id) => store.endElectron(id),
145
+ setActions: (items) => store.setActions(items)
96
146
  });
97
147
  controllers.set(name, controller);
98
148
  }
99
149
  return controller;
100
150
  }
101
151
 
102
- export { EMPTY_STATE, getStore, pill };
152
+ export { EMPTY_STATE, NO_ELECTRONS, getStore, pill };
package/dist/styles.css CHANGED
@@ -20,6 +20,22 @@
20
20
  sets a display. Your own unlayered CSS still beats both. */
21
21
  @layer look, theme, forms, behaviour;
22
22
 
23
+ @layer look {
24
+ /* The label of the orbital under the finger (magic-pill/satellites):
25
+ outside any pill, so it takes the public tokens */
26
+ [data-mp="orbital-label"] {
27
+ z-index: calc(var(--mp-z-index, 50) + 1);
28
+ padding: 0.3rem 0.7rem;
29
+ border-radius: 999px;
30
+ background: var(--mp-action, #f9f9f9);
31
+ color: var(--mp-on-action, #141414);
32
+ box-shadow: 0 4px 10px rgb(20 20 20 / 0.25);
33
+ font: 700 0.8125rem / 1.2 var(--mp-font-accent, inherit);
34
+ white-space: nowrap;
35
+ pointer-events: none;
36
+ }
37
+ }
38
+
23
39
  @layer behaviour {
24
40
  /* ─── Behaviour: kept by `unstyled` pills ──────────────────────────────── */
25
41
 
@@ -76,7 +92,7 @@
76
92
  --_mp-exit: var(--mp-duration-exit, 300ms);
77
93
  --_mp-change: var(--mp-duration-change, 250ms);
78
94
  /* The content fades out before the pill shrinks, and in once it has grown */
79
- --_mp-fade: 150ms;
95
+ --_mp-fade: var(--mp-duration-fade, 150ms);
80
96
  /* A panel stays above the other pills until it has closed back */
81
97
  --_mp-lower: calc(var(--_mp-fade) + var(--_mp-change));
82
98
  /* The entry overshoot from the mockups' "pop" */
@@ -262,13 +278,51 @@
262
278
  right: calc(var(--_mp-offset) + env(safe-area-inset-right, 0px) + var(--_mp-shift-x, 0px));
263
279
  }
264
280
 
265
- /* A sidebar's flag pops out of the sidebar's side, and scales back into it */
266
- &[data-layout="flag"][data-placement="left"] {
267
- transform-origin: var(--mp-scale-origin, left center);
281
+ /* A sidebar's flag and an electron (magic-pill/satellites) come out of
282
+ the pill's edge as a droplet and go back into it (goo.ts moves them),
283
+ so they don't scale in or out. Their entry and exit take the split's
284
+ and the join's durations */
285
+ &:is([data-layout="flag"], [data-satellite]) {
286
+ --_mp-enter: var(--mp-duration-split, var(--mp-duration-enter, 500ms));
287
+ --_mp-exit: var(--mp-duration-join, var(--mp-duration-exit, 300ms));
288
+ --_mp-exit-scale: 1;
289
+
290
+ &[data-presence="hidden"] {
291
+ scale: 1;
292
+ }
293
+ }
294
+
295
+ /* An electron's orbitals: small round pills, the size of an action. The
296
+ one under the finger, the pointer or the focus takes the actions'
297
+ colours and grows a little */
298
+ &[data-satellite="orbital"] {
299
+ --_mp-padding: 0px;
300
+ --_mp-change: 0ms;
301
+ --_mp-action-size: var(--mp-orbital-size, var(--mp-action-size, 2.75rem));
302
+
303
+ &:not([data-presence="hidden"]) {
304
+ transition:
305
+ scale 120ms ease-out,
306
+ background-color 120ms ease-out,
307
+ color 120ms ease-out,
308
+ var(--_mp-also, visibility 0s),
309
+ visibility 0s;
310
+ }
311
+
312
+ &[data-hot] {
313
+ scale: 1.12;
314
+ background-color: var(--_mp-action);
315
+ color: var(--_mp-on-action);
316
+ }
268
317
  }
269
318
 
270
- &[data-layout="flag"][data-placement="right"] {
271
- transform-origin: var(--mp-scale-origin, right center);
319
+ /* An electron whose activity ends can pop away instead, like any pill leaving */
320
+ &[data-satellite][data-ending="pop"] {
321
+ --_mp-exit-scale: 0;
322
+
323
+ &[data-presence="hidden"] {
324
+ scale: 0;
325
+ }
272
326
  }
273
327
 
274
328
  &[data-placement="overlay"] {
@@ -490,6 +544,112 @@
490
544
  outline-offset: 2px;
491
545
  }
492
546
 
547
+ /* An electron: all of the circle is a link back to where it came from.
548
+ The circle's size, padding included, the same whatever box-sizing an
549
+ app's reset gives everything (its CSS beats these layers) */
550
+ & [data-mp="electron"] {
551
+ display: grid;
552
+ place-items: center;
553
+ box-sizing: border-box;
554
+ inline-size: var(--_mp-rest-size);
555
+ block-size: var(--_mp-rest-size);
556
+ margin: calc(var(--_mp-padding) * -1);
557
+ padding: var(--_mp-padding);
558
+ border: 0;
559
+ border-radius: 50%;
560
+ background: none;
561
+ color: inherit;
562
+ font: inherit;
563
+ text-decoration: none;
564
+ cursor: pointer;
565
+ -webkit-tap-highlight-color: transparent;
566
+ }
567
+
568
+ /* With orbitals: a long press opens them, with no scrolling or callout */
569
+ & [data-mp="electron"][aria-haspopup] {
570
+ touch-action: none;
571
+ -webkit-touch-callout: none;
572
+ user-select: none;
573
+ }
574
+
575
+ & [data-mp="orbital"] {
576
+ display: grid;
577
+ place-items: center;
578
+ inline-size: var(--_mp-action-size);
579
+ block-size: var(--_mp-action-size);
580
+ padding: 0;
581
+ border: 0;
582
+ border-radius: 50%;
583
+ background: none;
584
+ color: inherit;
585
+ font-size: 1.25rem;
586
+ cursor: pointer;
587
+ -webkit-tap-highlight-color: transparent;
588
+
589
+ & > :is(svg, img) {
590
+ inline-size: 1em;
591
+ block-size: 1em;
592
+ }
593
+ }
594
+
595
+ & [data-mp="orbital"]:focus-visible {
596
+ outline: 2px solid currentColor;
597
+ outline-offset: -4px;
598
+ }
599
+
600
+ & [data-mp="electron"]:focus-visible {
601
+ outline: 2px solid var(--_mp-on-surface);
602
+ outline-offset: -5px;
603
+ }
604
+
605
+ & [data-mp="electron-value"] {
606
+ font: 700 0.8125rem / 1 var(--mp-font-accent, inherit);
607
+ font-variant-numeric: tabular-nums;
608
+ }
609
+
610
+ /* The value alone, without a ring: larger */
611
+ & [data-mp="electron"] > [data-mp="electron-value"] {
612
+ font-size: 1rem;
613
+ }
614
+
615
+ & [data-mp="electron-icon"] {
616
+ display: grid;
617
+ font-size: 1.375rem;
618
+
619
+ & > :is(svg, img) {
620
+ inline-size: 1em;
621
+ block-size: 1em;
622
+ }
623
+ }
624
+
625
+ /* A progress ring around its content, in the text colour */
626
+ & [data-mp="progress"] {
627
+ position: relative;
628
+ display: grid;
629
+ place-items: center;
630
+ inline-size: var(--_mp-action-size);
631
+ block-size: var(--_mp-action-size);
632
+
633
+ & > svg {
634
+ position: absolute;
635
+ top: 50%;
636
+ left: 50%;
637
+ inline-size: var(--mp-progress-size, 3.375rem);
638
+ block-size: var(--mp-progress-size, 3.375rem);
639
+ translate: -50% -50%;
640
+ rotate: -90deg;
641
+ overflow: visible;
642
+ fill: none;
643
+ stroke: currentColor;
644
+ stroke-width: var(--mp-progress-width, 3.5);
645
+ stroke-linecap: round;
646
+ }
647
+ }
648
+
649
+ & [data-mp="progress-track"] {
650
+ opacity: 0.25;
651
+ }
652
+
493
653
  & [data-mp="action"][aria-disabled="true"] {
494
654
  cursor: not-allowed;
495
655
  opacity: 0.6;
@@ -509,10 +669,13 @@
509
669
  font-size: 1.25rem;
510
670
  }
511
671
 
512
- & [data-mp="icon"] > svg,
513
- & [data-mp="action-icon"] > svg {
672
+ /* Any icon fits the slot: an svg or an image is 1em square, a font
673
+ icon (Font Awesome's <i>, an emoji) takes the font size */
674
+ & [data-mp="icon"] > :is(svg, img),
675
+ & [data-mp="action-icon"] > :is(svg, img) {
514
676
  inline-size: 1em;
515
677
  block-size: 1em;
678
+ object-fit: contain;
516
679
  }
517
680
 
518
681
  /* Labels: folded away (but still the accessible name) until expanded.
@@ -636,8 +799,9 @@
636
799
  }
637
800
 
638
801
  /* No room for two labels (PillNavbar/room.ts): the one that was open
639
- folds while another is pointed at or focused */
640
- & [data-mp="navbar"][data-tight] [data-mp="action"]:not(:hover, :focus-visible) {
802
+ folds while another is pointed at or focused. Folded at rest too with
803
+ labels="closed", or "auto" while the current one has no room */
804
+ & [data-mp="navbar"]:is([data-tight], [data-folded]) [data-mp="action"]:not(:hover, :focus-visible) {
641
805
  & [data-mp="action-body"] {
642
806
  padding-inline-end: calc((var(--_mp-action-size) - 1.25rem) / 2);
643
807
  }
@@ -10,6 +10,12 @@ const INERT_VALUE = Number.parseInt(react.version, 10) >= 19 ? true : "";
10
10
  function inertProps(inert) {
11
11
  return inert ? { inert: INERT_VALUE } : {};
12
12
  }
13
+ /**
14
+ * `useLayoutEffect` in the browser, `useEffect` on the server (L31). Layout
15
+ * effects never run on the server anyway, but React 18 warns about each one
16
+ * it meets while rendering there. Every hook of the library uses this one.
17
+ */
18
+ const useIsomorphicLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
13
19
  /** Combine refs (React 18 compatible: no ref cleanup functions). */
14
20
  function mergeRefs(...refs) {
15
21
  return (node) => {
@@ -20,4 +26,5 @@ function mergeRefs(...refs) {
20
26
 
21
27
  exports.devWarn = devWarn;
22
28
  exports.inertProps = inertProps;
23
- exports.mergeRefs = mergeRefs;
29
+ exports.mergeRefs = mergeRefs;
30
+ exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
@@ -1,4 +1,4 @@
1
- import { version } from "react";
1
+ import { useEffect, useLayoutEffect, version } from "react";
2
2
 
3
3
  // src/utils/react.ts
4
4
  /** Warn in development builds only. */
@@ -10,6 +10,12 @@ const INERT_VALUE = Number.parseInt(version, 10) >= 19 ? true : "";
10
10
  function inertProps(inert) {
11
11
  return inert ? { inert: INERT_VALUE } : {};
12
12
  }
13
+ /**
14
+ * `useLayoutEffect` in the browser, `useEffect` on the server (L31). Layout
15
+ * effects never run on the server anyway, but React 18 warns about each one
16
+ * it meets while rendering there. Every hook of the library uses this one.
17
+ */
18
+ const useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
13
19
  /** Combine refs (React 18 compatible: no ref cleanup functions). */
14
20
  function mergeRefs(...refs) {
15
21
  return (node) => {
@@ -18,4 +24,4 @@ function mergeRefs(...refs) {
18
24
  };
19
25
  }
20
26
 
21
- export { devWarn, inertProps, mergeRefs };
27
+ export { devWarn, inertProps, mergeRefs, useIsomorphicLayoutEffect };