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

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.
@@ -6,7 +6,7 @@ import { SPLIT, playOrbit } from "../Pill/goo.mjs";
6
6
  import { useIsomorphicLayoutEffect } from "../utils/react.mjs";
7
7
  import { parseDuration } from "../utils/timing.mjs";
8
8
  import { durations, toPixels } from "./measure.mjs";
9
- import { orbitalAt, planOrbit, spotOn, wheelEnd } from "./orbits.mjs";
9
+ import { hiddenPast, orbitalAt, pastEnd, planOrbit, spotOn, wheelEnd } from "./orbits.mjs";
10
10
  import { jsx, jsxs } from "react/jsx-runtime";
11
11
 
12
12
  // src/satellites/Orbitals.tsx
@@ -28,6 +28,28 @@ const LABEL_STYLE = {
28
28
  left: 0,
29
29
  top: 0
30
30
  };
31
+ const MARKER_STYLE = {
32
+ position: "fixed",
33
+ left: 0,
34
+ top: 0,
35
+ margin: 0,
36
+ opacity: 0,
37
+ pointerEvents: "none"
38
+ };
39
+ const DOTS_STYLE = {
40
+ ...MARKER_STYLE,
41
+ display: "flex",
42
+ gap: 4,
43
+ transition: "opacity 150ms ease-out"
44
+ };
45
+ const DOT_STYLE = {
46
+ display: "block",
47
+ inlineSize: 6,
48
+ blockSize: 6,
49
+ borderRadius: "50%",
50
+ background: "currentColor"
51
+ };
52
+ const ENDS = ["low", "high"];
31
53
  /** Another electron opened its orbitals: these close */
32
54
  const OPENED = "mp-orbitals-open";
33
55
  /** The direction away from the screen's edge, by the host's placement */
@@ -82,6 +104,16 @@ function Orbitals({ electron, getElement, host, out }) {
82
104
  const focusFirst = useRef(false);
83
105
  const turn = useRef(0);
84
106
  const snapping = useRef(0);
107
+ const markers = useRef({
108
+ low: null,
109
+ high: null
110
+ });
111
+ const [past, setPast] = useState({
112
+ low: 0,
113
+ high: 0
114
+ });
115
+ const lastPast = useRef(past);
116
+ const surface = useRef("");
85
117
  const clearTimers = () => {
86
118
  timers.current.forEach(clearTimeout);
87
119
  timers.current = [];
@@ -107,6 +139,14 @@ function Orbitals({ electron, getElement, host, out }) {
107
139
  },
108
140
  rtl: getComputedStyle(root).direction === "rtl"
109
141
  });
142
+ if (host.orbitalsMore !== "peek") orbit.current = {
143
+ ...orbit.current,
144
+ peek: {
145
+ low: false,
146
+ high: false
147
+ }
148
+ };
149
+ surface.current = getComputedStyle(element).backgroundColor;
110
150
  return read;
111
151
  };
112
152
  const applyTurn = () => {
@@ -128,8 +168,44 @@ function Orbitals({ electron, getElement, host, out }) {
128
168
  pill.style.pointerEvents = closing.current ? "none" : "auto";
129
169
  }
130
170
  });
171
+ placeMarkers(current);
131
172
  placeLabel();
132
173
  };
174
+ const placeMarkers = (current) => {
175
+ if (host.orbitalsMore === "peek") return;
176
+ const counts = hiddenPast(current, turn.current);
177
+ if (counts.low !== lastPast.current.low || counts.high !== lastPast.current.high) {
178
+ lastPast.current = counts;
179
+ setPast(counts);
180
+ }
181
+ const size = settings.current?.size ?? 44;
182
+ for (const end of ENDS) {
183
+ const marker = markers.current[end];
184
+ if (!marker) continue;
185
+ const on = current.wheel && counts[end] > 0 && !closing.current;
186
+ const length = marker.offsetWidth;
187
+ const height = marker.offsetHeight;
188
+ const outward = host.orbitalsMore === "count" ? size / 2 + Math.min(length, height) / 2 - 2 : size / 2 + 7;
189
+ const spot = pastEnd(current, end, size * .45, outward);
190
+ const reach = Math.max(length, height) / 2 + 6;
191
+ const x = Math.min(Math.max(spot.x, reach), (document.documentElement.clientWidth || window.innerWidth) - reach);
192
+ const y = Math.min(Math.max(spot.y, reach), window.innerHeight - reach);
193
+ marker.style.translate = `${x - length / 2}px ${y - height / 2}px`;
194
+ if (host.orbitalsMore === "dots") {
195
+ marker.style.rotate = `${spot.angle + 90}deg`;
196
+ marker.style.color = surface.current;
197
+ }
198
+ marker.style.opacity = on ? "1" : "0";
199
+ marker.style.pointerEvents = on && host.orbitalsMore === "count" ? "auto" : "none";
200
+ }
201
+ };
202
+ const turnPage = (end) => {
203
+ const current = orbit.current;
204
+ if (!current?.wheel) return;
205
+ const page = Math.max(1, current.visible - 1);
206
+ const towards = (end === "low" ? -1 : 1) * (current.rtl ? -1 : 1);
207
+ turnTo(Math.round(turn.current) + towards * page, true);
208
+ };
133
209
  const placeLabel = () => {
134
210
  const label = labelRef.current;
135
211
  const index = api.current.hot;
@@ -376,6 +452,14 @@ function Orbitals({ electron, getElement, host, out }) {
376
452
  host.placement,
377
453
  electron.id
378
454
  ]);
455
+ useIsomorphicLayoutEffect(() => {
456
+ const element = getElement();
457
+ if (!ring || !element) return;
458
+ element.style.zIndex = "calc(var(--mp-z-index, 50) + 1)";
459
+ return () => {
460
+ element.style.zIndex = "var(--mp-z-index, 50)";
461
+ };
462
+ }, [ring !== null]);
379
463
  useEffect(() => {
380
464
  const link = getElement()?.querySelector("[data-mp=\"electron\"]");
381
465
  if (!ring) {
@@ -383,7 +467,7 @@ function Orbitals({ electron, getElement, host, out }) {
383
467
  return;
384
468
  }
385
469
  link?.setAttribute("aria-expanded", "true");
386
- const inside = (target) => target instanceof Node && ([...pills.current.values()].some((pill) => pill.contains(target)) || !!link?.contains(target));
470
+ const inside = (target) => target instanceof Node && ([...pills.current.values(), ...Object.values(markers.current)].some((pill) => !!pill?.contains(target)) || !!link?.contains(target));
387
471
  const onPointerDown = (event) => {
388
472
  if (!inside(event.target)) api.current.close();
389
473
  };
@@ -526,59 +610,93 @@ function Orbitals({ electron, getElement, host, out }) {
526
610
  "data-mp": "orbitals",
527
611
  "data-orbitals": electron.id,
528
612
  style: MENU_STYLE,
529
- children: [items.map((item, index) => {
530
- const common = {
531
- role: "menuitem",
532
- tabIndex: -1,
533
- "data-mp": "orbital",
534
- "aria-label": item.label,
535
- onClick: run(item),
536
- onKeyDown: onKeyDown(index),
537
- onFocus: () => setHot(index)
538
- };
539
- return /* @__PURE__ */ jsx(Pill, {
613
+ children: [
614
+ items.map((item, index) => {
615
+ const common = {
616
+ role: "menuitem",
617
+ tabIndex: -1,
618
+ "data-mp": "orbital",
619
+ "aria-label": item.label,
620
+ onClick: run(item),
621
+ onKeyDown: onKeyDown(index),
622
+ onFocus: () => setHot(index)
623
+ };
624
+ return /* @__PURE__ */ jsx(Pill, {
625
+ ref: (element) => {
626
+ if (element) pills.current.set(index, element);
627
+ else pills.current.delete(index);
628
+ },
629
+ placement: "inline",
630
+ ladder: false,
631
+ moveThroughCircle: false,
632
+ theme: host.theme,
633
+ variant: electron.input.variant ?? host.variant,
634
+ presence: shown[index] ? "compact" : "hidden",
635
+ "data-satellite": "orbital",
636
+ "data-index": index,
637
+ "data-hot": hot === index ? "" : void 0,
638
+ style: ORBITAL_STYLE,
639
+ onPointerEnter: (event) => {
640
+ const moving = event.currentTarget.getAnimations?.().some((animation) => animation.id === "mp-split" && animation.playState === "running");
641
+ if (!closing.current && !moving) setHot(index);
642
+ },
643
+ onPointerLeave: () => setHot(-1),
644
+ children: item.href !== void 0 ? /* @__PURE__ */ jsx(Link, {
645
+ href: item.href,
646
+ ...common,
647
+ children: item.icon
648
+ }) : /* @__PURE__ */ jsx("button", {
649
+ type: "button",
650
+ ...common,
651
+ children: item.icon
652
+ })
653
+ }, item.id ?? index);
654
+ }),
655
+ host.orbitalsMore === "dots" && ENDS.map((end) => /* @__PURE__ */ jsx("span", {
540
656
  ref: (element) => {
541
- if (element) pills.current.set(index, element);
542
- else pills.current.delete(index);
657
+ markers.current[end] = element;
658
+ },
659
+ "aria-hidden": "true",
660
+ "data-mp": "orbital-dots",
661
+ "data-end": end,
662
+ style: DOTS_STYLE,
663
+ children: Array.from({ length: Math.min(3, past[end]) }, (_, index) => /* @__PURE__ */ jsx("i", { style: DOT_STYLE }, index))
664
+ }, end)),
665
+ host.orbitalsMore === "count" && ENDS.map((end) => /* @__PURE__ */ jsx(Pill, {
666
+ ref: (element) => {
667
+ markers.current[end] = element;
543
668
  },
544
669
  placement: "inline",
545
670
  ladder: false,
546
671
  moveThroughCircle: false,
547
672
  theme: host.theme,
548
673
  variant: electron.input.variant ?? host.variant,
549
- presence: shown[index] ? "compact" : "hidden",
550
- "data-satellite": "orbital",
551
- "data-index": index,
552
- "data-hot": hot === index ? "" : void 0,
553
- style: ORBITAL_STYLE,
554
- onPointerEnter: (event) => {
555
- const moving = event.currentTarget.getAnimations?.().some((animation) => animation.id === "mp-split" && animation.playState === "running");
556
- if (!closing.current && !moving) setHot(index);
557
- },
558
- onPointerLeave: () => setHot(-1),
559
- children: item.href !== void 0 ? /* @__PURE__ */ jsx(Link, {
560
- href: item.href,
561
- ...common,
562
- children: item.icon
563
- }) : /* @__PURE__ */ jsx("button", {
674
+ presence: "compact",
675
+ "data-satellite": "orbital-more",
676
+ "data-end": end,
677
+ style: MARKER_STYLE,
678
+ children: /* @__PURE__ */ jsxs("button", {
564
679
  type: "button",
565
- ...common,
566
- children: item.icon
680
+ tabIndex: -1,
681
+ "aria-hidden": "true",
682
+ onClick: () => turnPage(end),
683
+ children: ["+", past[end]]
567
684
  })
568
- }, item.id ?? index);
569
- }), host.orbitalLabels && hot >= 0 && items[hot] && /* @__PURE__ */ jsx(Pill, {
570
- ref: labelRef,
571
- placement: "inline",
572
- ladder: false,
573
- moveThroughCircle: false,
574
- theme: host.theme,
575
- variant: electron.input.variant ?? host.variant,
576
- presence: "compact",
577
- "aria-hidden": "true",
578
- "data-satellite": "orbital-label",
579
- style: LABEL_STYLE,
580
- children: items[hot].label
581
- })]
685
+ }, end)),
686
+ host.orbitalLabels && hot >= 0 && items[hot] && /* @__PURE__ */ jsx(Pill, {
687
+ ref: labelRef,
688
+ placement: "inline",
689
+ ladder: false,
690
+ moveThroughCircle: false,
691
+ theme: host.theme,
692
+ variant: electron.input.variant ?? host.variant,
693
+ presence: "compact",
694
+ "aria-hidden": "true",
695
+ "data-satellite": "orbital-label",
696
+ style: LABEL_STYLE,
697
+ children: items[hot].label
698
+ })
699
+ ]
582
700
  });
583
701
  }
584
702