magic-pill 9.4.0-next.1 → 9.4.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Pill/goo.mjs CHANGED
@@ -109,7 +109,7 @@ function createOverlay(zIndex, color, shadow) {
109
109
  const root = document.createElement("div");
110
110
  root.setAttribute("data-mp", "goo");
111
111
  root.setAttribute("aria-hidden", "true");
112
- root.style.cssText = `position:fixed;inset:0;pointer-events:none;z-index:${zIndex};`;
112
+ root.style.cssText = `position:fixed;left:0;top:0;width:0;height:0;pointer-events:none;z-index:${zIndex};`;
113
113
  const svg = document.createElementNS(SVG, "svg");
114
114
  svg.setAttribute("width", "0");
115
115
  svg.setAttribute("height", "0");
@@ -161,15 +161,29 @@ function createOverlay(zIndex, color, shadow) {
161
161
  moving
162
162
  };
163
163
  }
164
- /** Puts a shape where a pill is on screen, with its rounded corners at its current scale. */
165
- function place(shape, element) {
166
- const rect = element.getBoundingClientRect();
167
- const scale = element.offsetWidth > 0 ? rect.width / element.offsetWidth : 1;
168
- const radius = Number.parseFloat(getComputedStyle(element).borderTopLeftRadius) || 0;
169
- shape.style.width = `${rect.width}px`;
170
- shape.style.height = `${rect.height}px`;
171
- shape.style.transform = `translate(${rect.left}px, ${rect.top}px)`;
172
- shape.style.borderRadius = `${Math.min(radius * scale, rect.width / 2, rect.height / 2)}px`;
164
+ /**
165
+ * Puts the overlay around the two pills (with `margin` for the blur and the
166
+ * shadow), and each shape where its pill is, with its rounded corners at its
167
+ * current scale (`radius`: read once, at its full size).
168
+ */
169
+ function placeAll(overlay, pills, radii, margin) {
170
+ const a = pills.anchor.getBoundingClientRect();
171
+ const m = pills.moving.getBoundingClientRect();
172
+ const left = Math.min(a.left, m.left) - margin;
173
+ const top = Math.min(a.top, m.top) - margin;
174
+ const root = overlay.root.style;
175
+ root.transform = `translate(${left}px, ${top}px)`;
176
+ root.width = `${Math.max(a.right, m.right) + margin - left}px`;
177
+ root.height = `${Math.max(a.bottom, m.bottom) + margin - top}px`;
178
+ const put = (shape, rect, element, radius) => {
179
+ const scale = element.offsetWidth > 0 ? rect.width / element.offsetWidth : 1;
180
+ shape.style.width = `${rect.width}px`;
181
+ shape.style.height = `${rect.height}px`;
182
+ shape.style.transform = `translate(${rect.left - left}px, ${rect.top - top}px)`;
183
+ shape.style.borderRadius = `${Math.min(radius * scale, rect.width / 2, rect.height / 2)}px`;
184
+ };
185
+ put(overlay.anchor, a, pills.anchor, radii.anchor);
186
+ put(overlay.moving, m, pills.moving, radii.moving);
173
187
  }
174
188
  const OWN_LOOK = {
175
189
  transition: "none",
@@ -201,6 +215,17 @@ function playSplit(anchor, moving, kind, timing) {
201
215
  const fade = parseDuration(style.getPropertyValue("--_mp-fade"), 150);
202
216
  const easing = kind === "split" ? splitEasing(style.getPropertyValue("--mp-ease-split")) : SMOOTH;
203
217
  let overlay = null;
218
+ const radii = {
219
+ anchor: 0,
220
+ moving: 0
221
+ };
222
+ let margin = 0;
223
+ const placeShapes = () => {
224
+ if (overlay) placeAll(overlay, {
225
+ anchor,
226
+ moving
227
+ }, radii, margin);
228
+ };
204
229
  let glass = kind === "join";
205
230
  const saved = /* @__PURE__ */ new Map();
206
231
  let frame = 0;
@@ -302,9 +327,12 @@ function playSplit(anchor, moving, kind, timing) {
302
327
  saved.set("transition", [moving.style.getPropertyValue("transition"), moving.style.getPropertyPriority("transition")]);
303
328
  moving.style.setProperty("transition", "none", "important");
304
329
  const own = getComputedStyle(moving);
305
- overlay = createOverlay(zIndex, own.backgroundColor, dropShadow(own.boxShadow));
306
- place(overlay.anchor, anchor);
307
- place(overlay.moving, moving);
330
+ const shadow = dropShadow(own.boxShadow);
331
+ overlay = createOverlay(zIndex, own.backgroundColor, shadow);
332
+ radii.anchor = Number.parseFloat(getComputedStyle(anchor).borderTopLeftRadius) || 0;
333
+ radii.moving = Number.parseFloat(own.borderTopLeftRadius) || 0;
334
+ margin = goo * 3 + (shadow ? shadow.blur + Math.max(Math.abs(shadow.x), Math.abs(shadow.y)) : 0) + 8;
335
+ placeShapes();
308
336
  hideOwnLook();
309
337
  if (kind === "split") for (const name of BLUR) {
310
338
  saved.set(name, [moving.style.getPropertyValue(name), moving.style.getPropertyPriority(name)]);
@@ -328,8 +356,7 @@ function playSplit(anchor, moving, kind, timing) {
328
356
  if (begun && overlay) {
329
357
  const k = Math.min(1, Math.max(0, (elapsed - timing.delay) / timing.duration));
330
358
  overlay.blur.setAttribute("stdDeviation", (goo * gooAmount(k)).toFixed(2));
331
- place(overlay.anchor, anchor);
332
- place(overlay.moving, moving);
359
+ placeShapes();
333
360
  setGlass(!overlaps(moving.getBoundingClientRect(), anchor.getBoundingClientRect()));
334
361
  }
335
362
  if (elapsed >= timing.delay + timing.duration) {
@@ -343,5 +370,197 @@ function playSplit(anchor, moving, kind, timing) {
343
370
  running.set(moving, stop);
344
371
  return stop;
345
372
  }
373
+ /** Inside the anchor at its nearest edge, as a flag goes into its sidebar (`--mp-electron-start`). */
374
+ const atEdgeOf = (anchor) => (rect, element) => tuckedOffset(anchor.getBoundingClientRect(), rect, readNumber(getComputedStyle(element), "--mp-electron-start", 1));
375
+ /** Inside the anchor at a point of the screen (where a pill closing to a circle ends), small. */
376
+ const atPoint = (x, y, scale = .3) => (rect) => ({
377
+ x: x - (rect.left + rect.width / 2),
378
+ y: y - (rect.top + rect.height / 2),
379
+ scale
380
+ });
381
+ const budding = /* @__PURE__ */ new WeakMap();
382
+ /**
383
+ * Pills budding out of another (or going back into it), one after the other,
384
+ * as the concept drew an electron's orbitals: from inside it, small and
385
+ * see-through, to their spot. The pills draw themselves the whole time (their
386
+ * glass, rim and shadow stay, no colour switch at the end); one overlay under
387
+ * them draws only the necks between them and the anchor: the goo of the
388
+ * moment, every pill's inside cut out of it. An electron's orbitals, an
389
+ * electron out of its host or out of the one next to it, the page's actions.
390
+ */
391
+ function playOrbit(electron, items, kind, timing) {
392
+ for (const { element } of items) {
393
+ budding.get(element)?.();
394
+ for (const animation of element.getAnimations?.() ?? []) if (animation.id === "mp-split") animation.cancel();
395
+ }
396
+ if (timing.duration <= 0 || prefersReducedMotion() || typeof electron.animate !== "function" || items.length === 0) return () => {};
397
+ const style = getComputedStyle(electron);
398
+ const easing = kind === "open" ? splitEasing(style.getPropertyValue("--mp-ease-split")) : SMOOTH;
399
+ const centre = electron.getBoundingClientRect();
400
+ const cx = centre.left + centre.width / 2;
401
+ const cy = centre.top + centre.height / 2;
402
+ const longest = Math.max(...items.map(({ delay }) => delay)) + timing.duration;
403
+ for (const { element, delay, shown = 1, from = atPoint(cx, cy), opaque = false } of items) {
404
+ if (shown <= 0) continue;
405
+ const start = from(element.getBoundingClientRect(), element);
406
+ const end = getComputedStyle(element).scale;
407
+ const inside = {
408
+ translate: `${start.x}px ${start.y}px`,
409
+ scale: String(start.scale),
410
+ opacity: opaque ? shown : 0
411
+ };
412
+ const out = {
413
+ translate: "0px 0px",
414
+ scale: end === "none" ? "1" : end,
415
+ opacity: shown
416
+ };
417
+ const frames = kind === "open" ? [
418
+ inside,
419
+ {
420
+ ...out,
421
+ offset: .35
422
+ },
423
+ out
424
+ ] : [
425
+ out,
426
+ {
427
+ ...out,
428
+ offset: .65
429
+ },
430
+ inside
431
+ ];
432
+ const options = {
433
+ id: SPLIT,
434
+ duration: timing.duration,
435
+ delay,
436
+ fill: kind === "open" ? "backwards" : "forwards"
437
+ };
438
+ const ends = (kind === "open" ? [inside, out] : [out, inside]).map(({ translate, scale }) => ({
439
+ translate,
440
+ scale
441
+ }));
442
+ try {
443
+ element.animate(ends, {
444
+ ...options,
445
+ easing
446
+ });
447
+ } catch {
448
+ element.animate(ends, {
449
+ ...options,
450
+ easing: POP
451
+ });
452
+ }
453
+ if (!opaque) element.animate(frames.map(({ opacity, offset }) => offset === void 0 ? { opacity } : {
454
+ opacity,
455
+ offset
456
+ }), {
457
+ ...options,
458
+ easing: "linear"
459
+ });
460
+ else if (kind === "close") element.animate([
461
+ { opacity: shown },
462
+ {
463
+ opacity: shown,
464
+ offset: .85
465
+ },
466
+ { opacity: 0 }
467
+ ], {
468
+ ...options,
469
+ easing: "linear"
470
+ });
471
+ }
472
+ const stop = playNecks([electron, ...items.filter(({ shown = 1 }) => shown > 0).map(({ element }) => element)], longest);
473
+ const stopAll = () => {
474
+ stop();
475
+ for (const { element } of items) if (budding.get(element) === stopAll) budding.delete(element);
476
+ };
477
+ for (const { element } of items) budding.set(element, stopAll);
478
+ return stopAll;
479
+ }
480
+ /**
481
+ * The necks between pills, for `duration` ms: the goo of the moment under
482
+ * them, every pill's inside cut out of it, in the first one's colour. The
483
+ * pills draw themselves. Pills sliding past each other (or out of one
484
+ * another) seem to melt together as they meet and part.
485
+ */
486
+ function playNecks(pills, duration) {
487
+ if (pills.length < 2 || duration <= 0 || prefersReducedMotion() || typeof document === "undefined") return () => {};
488
+ const style = getComputedStyle(pills[0]);
489
+ const goo = readNumber(style, "--mp-goo", DEFAULT_GOO);
490
+ if (goo <= 0) return () => {};
491
+ const longest = duration;
492
+ const id = `mp-goo-${++overlays}`;
493
+ const root = document.createElement("div");
494
+ root.setAttribute("data-mp", "goo");
495
+ root.setAttribute("aria-hidden", "true");
496
+ root.style.cssText = `position:fixed;left:0;top:0;width:0;height:0;pointer-events:none;z-index:${(Number.parseInt(style.zIndex, 10) || 50) - 1};`;
497
+ const svg = document.createElementNS(SVG, "svg");
498
+ svg.setAttribute("width", "0");
499
+ svg.setAttribute("height", "0");
500
+ svg.style.position = "absolute";
501
+ const filter = document.createElementNS(SVG, "filter");
502
+ filter.id = id;
503
+ for (const [name, value] of Object.entries({
504
+ x: "-50%",
505
+ y: "-50%",
506
+ width: "200%",
507
+ height: "200%",
508
+ "color-interpolation-filters": "sRGB"
509
+ })) filter.setAttribute(name, value);
510
+ filter.innerHTML = `
511
+ <feGaussianBlur in="SourceAlpha" stdDeviation="0" result="blur"/>
512
+ <feComponentTransfer in="blur" result="goo"><feFuncA type="linear" slope="24" intercept="-12"/></feComponentTransfer>
513
+ <feMorphology in="SourceAlpha" operator="erode" radius="1" result="inside"/>
514
+ <feComposite in="goo" in2="inside" operator="out" result="necks"/>
515
+ <feFlood result="color"/>
516
+ <feComposite in="color" in2="necks" operator="in"/>`;
517
+ filter.querySelector("feFlood").style.setProperty("flood-color", style.backgroundColor);
518
+ svg.append(filter);
519
+ const layer = document.createElement("div");
520
+ layer.style.cssText = `position:absolute;inset:0;filter:url(#${id});`;
521
+ const radii = pills.map((pill) => Number.parseFloat(getComputedStyle(pill).borderTopLeftRadius) || 0);
522
+ const shapes = pills.map(() => {
523
+ const shape = document.createElement("div");
524
+ shape.style.cssText = "position:absolute;left:0;top:0;background:#000;";
525
+ layer.append(shape);
526
+ return shape;
527
+ });
528
+ root.append(svg, layer);
529
+ document.body.append(root);
530
+ const blur = filter.querySelector("feGaussianBlur");
531
+ const margin = goo * 3 + 8;
532
+ let frame = 0;
533
+ let stopped = false;
534
+ const stop = () => {
535
+ if (stopped) return;
536
+ stopped = true;
537
+ cancelAnimationFrame(frame);
538
+ root.remove();
539
+ };
540
+ const startedAt = performance.now();
541
+ const draw = (now) => {
542
+ if (stopped) return;
543
+ const elapsed = now - startedAt;
544
+ const rects = pills.map((pill) => pill.getBoundingClientRect());
545
+ const left = Math.min(...rects.map((rect) => rect.left)) - margin;
546
+ const top = Math.min(...rects.map((rect) => rect.top)) - margin;
547
+ root.style.transform = `translate(${left}px, ${top}px)`;
548
+ root.style.width = `${Math.max(...rects.map((rect) => rect.right)) + margin - left}px`;
549
+ root.style.height = `${Math.max(...rects.map((rect) => rect.bottom)) + margin - top}px`;
550
+ rects.forEach((rect, index) => {
551
+ const scale = pills[index].offsetWidth > 0 ? rect.width / pills[index].offsetWidth : 1;
552
+ const shape = shapes[index].style;
553
+ shape.width = `${rect.width}px`;
554
+ shape.height = `${rect.height}px`;
555
+ shape.transform = `translate(${rect.left - left}px, ${rect.top - top}px)`;
556
+ shape.borderRadius = `${Math.min(radii[index] * scale, rect.width / 2, rect.height / 2)}px`;
557
+ });
558
+ blur.setAttribute("stdDeviation", (goo * gooAmount(Math.min(1, elapsed / longest))).toFixed(2));
559
+ if (elapsed >= longest) return stop();
560
+ frame = requestAnimationFrame(draw);
561
+ };
562
+ frame = requestAnimationFrame(draw);
563
+ return stop;
564
+ }
346
565
 
347
- export { SPLIT, dropShadow, gooAmount, playSplit, splitEasing, springEasing, tuckedOffset };
566
+ export { SPLIT, atEdgeOf, atPoint, dropShadow, gooAmount, playNecks, playOrbit, playSplit, splitEasing, springEasing, tuckedOffset };
@@ -117,7 +117,7 @@ const EXIT = "mp-exit";
117
117
  * Played by script on top, the exit keeps its course. Pure, so it can be tested.
118
118
  */
119
119
  function planExit(start, timings, exit) {
120
- const wait = timings.fade + timings.change;
120
+ const wait = start.wait ?? timings.fade + timings.change;
121
121
  const total = wait + exit;
122
122
  if (exit <= 0 || total <= 0) return null;
123
123
  const plan = { pill: {
@@ -167,10 +167,13 @@ function playExit(element, timings) {
167
167
  const opacity = content.length > 0 ? getComputedStyle(content[0]).opacity : "0";
168
168
  const exit = require_timing.parseDuration(style.getPropertyValue("--_mp-exit"), 300);
169
169
  const to = style.getPropertyValue("--_mp-exit-scale").trim() || void 0;
170
+ const waitValue = style.getPropertyValue("--_mp-exit-wait").trim();
171
+ const wait = waitValue ? require_timing.parseDuration(waitValue, timings.fade + timings.change) : void 0;
170
172
  const plan = planExit({
171
173
  scale,
172
174
  content: Number(opacity) > 0 ? opacity : void 0,
173
- to
175
+ to,
176
+ wait
174
177
  }, timings, exit);
175
178
  if (!plan) return [];
176
179
  const animations = [element.animate(plan.pill.keyframes, plan.pill.options)];
@@ -493,7 +496,7 @@ var ExitWatch = class extends react.Component {
493
496
  getSnapshotBeforeUpdate(previous) {
494
497
  const element = this.props.target.current;
495
498
  if (!element || previous.presence !== "hidden" || this.props.presence === "hidden") return null;
496
- if ((element.getAnimations?.() ?? []).filter(({ id }) => id === EXIT).length === 0) return null;
499
+ if ((element.getAnimations?.() ?? []).filter(({ id }) => id === "mp-exit").length === 0) return null;
497
500
  const { scale } = getComputedStyle(element);
498
501
  cancel(element, EXIT, true);
499
502
  return scale && scale !== "none" ? scale : "1";
@@ -563,8 +566,10 @@ var PlacementWatch = class extends react.Component {
563
566
  };
564
567
 
565
568
  exports.EASING = EASING;
569
+ exports.EXIT = EXIT;
566
570
  exports.ExitWatch = ExitWatch;
567
571
  exports.MORPH = MORPH;
572
+ exports.MOVE = MOVE;
568
573
  exports.PlacementWatch = PlacementWatch;
569
574
  exports.animateMove = animateMove;
570
575
  exports.cancel = cancel;
@@ -117,7 +117,7 @@ const EXIT = "mp-exit";
117
117
  * Played by script on top, the exit keeps its course. Pure, so it can be tested.
118
118
  */
119
119
  function planExit(start, timings, exit) {
120
- const wait = timings.fade + timings.change;
120
+ const wait = start.wait ?? timings.fade + timings.change;
121
121
  const total = wait + exit;
122
122
  if (exit <= 0 || total <= 0) return null;
123
123
  const plan = { pill: {
@@ -167,10 +167,13 @@ function playExit(element, timings) {
167
167
  const opacity = content.length > 0 ? getComputedStyle(content[0]).opacity : "0";
168
168
  const exit = parseDuration(style.getPropertyValue("--_mp-exit"), 300);
169
169
  const to = style.getPropertyValue("--_mp-exit-scale").trim() || void 0;
170
+ const waitValue = style.getPropertyValue("--_mp-exit-wait").trim();
171
+ const wait = waitValue ? parseDuration(waitValue, timings.fade + timings.change) : void 0;
170
172
  const plan = planExit({
171
173
  scale,
172
174
  content: Number(opacity) > 0 ? opacity : void 0,
173
- to
175
+ to,
176
+ wait
174
177
  }, timings, exit);
175
178
  if (!plan) return [];
176
179
  const animations = [element.animate(plan.pill.keyframes, plan.pill.options)];
@@ -493,7 +496,7 @@ var ExitWatch = class extends Component {
493
496
  getSnapshotBeforeUpdate(previous) {
494
497
  const element = this.props.target.current;
495
498
  if (!element || previous.presence !== "hidden" || this.props.presence === "hidden") return null;
496
- if ((element.getAnimations?.() ?? []).filter(({ id }) => id === EXIT).length === 0) return null;
499
+ if ((element.getAnimations?.() ?? []).filter(({ id }) => id === "mp-exit").length === 0) return null;
497
500
  const { scale } = getComputedStyle(element);
498
501
  cancel(element, EXIT, true);
499
502
  return scale && scale !== "none" ? scale : "1";
@@ -562,4 +565,4 @@ var PlacementWatch = class extends Component {
562
565
  }
563
566
  };
564
567
 
565
- export { EASING, ExitWatch, MORPH, PlacementWatch, animateMove, cancel, captureSwap, planExit, planMorph, planSwap, playSwap, readMorphTimings, useSizeMorph };
568
+ export { EASING, EXIT, ExitWatch, MORPH, MOVE, PlacementWatch, animateMove, cancel, captureSwap, planExit, planMorph, planSwap, playSwap, readMorphTimings, useSizeMorph };
@@ -26,21 +26,141 @@ function usePillActions(items, options = {}) {
26
26
  function useHostActions(host) {
27
27
  return (0, react.useSyncExternalStore)(host.store.subscribe, host.store.getActions, () => null);
28
28
  }
29
- /** The actions themselves, as the pill's own: their label on hover and focus, a link or a button. */
30
- function ActionList({ items, host }) {
31
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillActions, { children: items.map((item) => item.href !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillAction, {
32
- icon: item.icon,
33
- label: item.label,
34
- expanded: item.expanded,
35
- href: item.href,
36
- linkComponent: host.linkComponent,
37
- onClick: item.onClick
38
- }, item.id ?? item.label) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillAction, {
39
- icon: item.icon,
40
- label: item.label,
41
- expanded: item.expanded,
42
- onClick: item.onClick
43
- }, item.id ?? item.label)) });
29
+ /**
30
+ * A row of actions cut short (`data-wheel`) turns like a wheel: a mouse
31
+ * wheel, a drag, a swipe or the arrow keys bring the others in, each one
32
+ * snapping into place, and the ends that hide some fade out.
33
+ */
34
+ function useActionsWheel(track) {
35
+ (0, react.useEffect)(() => {
36
+ const element = track.current;
37
+ if (!element) return;
38
+ const vertical = () => getComputedStyle(element).flexDirection.startsWith("column");
39
+ const cut = () => element.hasAttribute("data-wheel");
40
+ const ends = () => {
41
+ const along = vertical();
42
+ const position = Math.abs(along ? element.scrollTop : element.scrollLeft);
43
+ const room = along ? element.scrollHeight - element.clientHeight : element.scrollWidth - element.clientWidth;
44
+ element.toggleAttribute("data-more-start", cut() && position > 1);
45
+ element.toggleAttribute("data-more-end", cut() && position < room - 1);
46
+ };
47
+ const onWheel = (event) => {
48
+ if (!cut() || vertical()) return;
49
+ if (Math.abs(event.deltaY) <= Math.abs(event.deltaX)) return;
50
+ event.preventDefault();
51
+ element.scrollBy({ left: event.deltaY });
52
+ };
53
+ let drag = null;
54
+ let swallowClick = false;
55
+ const onPointerDown = (event) => {
56
+ if (!cut() || event.pointerType !== "mouse" || event.button !== 0) return;
57
+ drag = {
58
+ x: event.clientX,
59
+ y: event.clientY,
60
+ start: vertical() ? element.scrollTop : element.scrollLeft,
61
+ moved: false
62
+ };
63
+ };
64
+ const onPointerMove = (event) => {
65
+ if (!drag) return;
66
+ const along = vertical();
67
+ const delta = along ? event.clientY - drag.y : event.clientX - drag.x;
68
+ if (!drag.moved && Math.abs(delta) < 6) return;
69
+ if (!drag.moved) {
70
+ drag.moved = true;
71
+ element.style.scrollSnapType = "none";
72
+ }
73
+ if (along) element.scrollTop = drag.start - delta;
74
+ else element.scrollLeft = drag.start - delta;
75
+ };
76
+ const onPointerUp = () => {
77
+ if (!drag) return;
78
+ if (drag.moved) {
79
+ swallowClick = true;
80
+ element.style.removeProperty("scroll-snap-type");
81
+ setTimeout(() => swallowClick = false, 0);
82
+ }
83
+ drag = null;
84
+ };
85
+ const onClick = (event) => {
86
+ if (!swallowClick) return;
87
+ event.preventDefault();
88
+ event.stopPropagation();
89
+ swallowClick = false;
90
+ };
91
+ const onKeyDown = (event) => {
92
+ if (!cut()) return;
93
+ const along = vertical();
94
+ const rtl = getComputedStyle(element).direction === "rtl";
95
+ const next = along ? "ArrowDown" : rtl ? "ArrowLeft" : "ArrowRight";
96
+ const previous = along ? "ArrowUp" : rtl ? "ArrowRight" : "ArrowLeft";
97
+ if (event.key !== next && event.key !== previous) return;
98
+ const actions = [...element.children];
99
+ const index = actions.findIndex((action) => action.contains(document.activeElement));
100
+ if (index < 0) return;
101
+ const target = actions[index + (event.key === next ? 1 : -1)];
102
+ const focusable = target?.matches("a, button") ? target : target?.querySelector("a, button");
103
+ if (!focusable) return;
104
+ event.preventDefault();
105
+ focusable.focus({ preventScroll: true });
106
+ target.scrollIntoView({
107
+ block: "nearest",
108
+ inline: "nearest",
109
+ behavior: "smooth"
110
+ });
111
+ };
112
+ const observer = typeof MutationObserver === "undefined" ? void 0 : new MutationObserver(ends);
113
+ observer?.observe(element, {
114
+ attributes: true,
115
+ attributeFilter: ["data-wheel", "style"]
116
+ });
117
+ element.addEventListener("scroll", ends, { passive: true });
118
+ element.addEventListener("wheel", onWheel, { passive: false });
119
+ element.addEventListener("pointerdown", onPointerDown);
120
+ window.addEventListener("pointermove", onPointerMove);
121
+ window.addEventListener("pointerup", onPointerUp);
122
+ element.addEventListener("click", onClick, true);
123
+ element.addEventListener("keydown", onKeyDown);
124
+ ends();
125
+ return () => {
126
+ observer?.disconnect();
127
+ element.removeEventListener("scroll", ends);
128
+ element.removeEventListener("wheel", onWheel);
129
+ element.removeEventListener("pointerdown", onPointerDown);
130
+ window.removeEventListener("pointermove", onPointerMove);
131
+ window.removeEventListener("pointerup", onPointerUp);
132
+ element.removeEventListener("click", onClick, true);
133
+ element.removeEventListener("keydown", onKeyDown);
134
+ };
135
+ }, [track]);
136
+ }
137
+ /**
138
+ * The actions themselves, as the pill's own: their label on hover and focus,
139
+ * a link or a button. `wheel`: cut short to that length, in px, turning to
140
+ * show the others.
141
+ */
142
+ function ActionList({ items, host, wheel, inside }) {
143
+ const track = (0, react.useRef)(null);
144
+ useActionsWheel(track);
145
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_parts.PillActions, {
146
+ ref: track,
147
+ "data-inside": inside ? "" : void 0,
148
+ "data-wheel": wheel !== void 0 ? "" : void 0,
149
+ style: wheel !== void 0 ? { "--_mp-wheel-length": `${wheel}px` } : void 0,
150
+ children: items.map((item) => item.href !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillAction, {
151
+ icon: item.icon,
152
+ label: item.label,
153
+ expanded: item.expanded,
154
+ href: item.href,
155
+ linkComponent: host.linkComponent,
156
+ onClick: item.onClick
157
+ }, item.id ?? item.label) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PillAction, {
158
+ icon: item.icon,
159
+ label: item.label,
160
+ expanded: item.expanded,
161
+ onClick: item.onClick
162
+ }, item.id ?? item.label))
163
+ });
44
164
  }
45
165
  /** In the pill itself (`actionsStyle="inside"`): the actions, then a divider (the other way round on the end side). */
46
166
  function InsideActions({ host }) {
@@ -48,12 +168,14 @@ function InsideActions({ host }) {
48
168
  if (!items) return null;
49
169
  const list = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ActionList, {
50
170
  items,
51
- host
171
+ host,
172
+ inside: true
52
173
  });
53
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, {})] });
54
175
  }
55
176
 
56
177
  exports.ActionList = ActionList;
57
178
  exports.InsideActions = InsideActions;
179
+ exports.useActionsWheel = useActionsWheel;
58
180
  exports.useHostActions = useHostActions;
59
181
  exports.usePillActions = usePillActions;