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.
- package/CHANGELOG.md +12 -2
- package/README.md +19 -14
- package/dist/MagicPill/MagicPill.d.mts +14 -1
- package/dist/MagicPill/MagicPill.d.ts +14 -1
- package/dist/MagicPill/MagicPill.js +3 -1
- package/dist/MagicPill/MagicPill.mjs +3 -1
- package/dist/Pill/goo.js +58 -15
- package/dist/Pill/goo.mjs +58 -16
- package/dist/Pill/morph.js +8 -8
- package/dist/Pill/morph.mjs +8 -8
- package/dist/Pill/zone.js +1 -2
- package/dist/Pill/zone.mjs +1 -2
- package/dist/PillNavbar/room.js +36 -15
- package/dist/PillNavbar/room.mjs +36 -16
- package/dist/satellites/Orbitals.js +163 -45
- package/dist/satellites/Orbitals.mjs +164 -46
- package/dist/satellites/Satellites.js +338 -63
- package/dist/satellites/Satellites.mjs +340 -65
- package/dist/satellites/layout.js +69 -3
- package/dist/satellites/layout.mjs +69 -4
- package/dist/satellites/orbits.js +37 -2
- package/dist/satellites/orbits.mjs +36 -3
- package/dist/satellites/types.d.mts +8 -0
- package/dist/satellites/types.d.ts +8 -0
- package/dist/satellites.d.mts +2 -2
- package/dist/satellites.d.ts +2 -2
- package/dist/styles.css +25 -0
- package/package.json +1 -1
|
@@ -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
|
|
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: [
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
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
|
-
|
|
542
|
-
|
|
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:
|
|
550
|
-
"data-satellite": "orbital",
|
|
551
|
-
"data-
|
|
552
|
-
|
|
553
|
-
|
|
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
|
-
|
|
566
|
-
|
|
680
|
+
tabIndex: -1,
|
|
681
|
+
"aria-hidden": "true",
|
|
682
|
+
onClick: () => turnPage(end),
|
|
683
|
+
children: ["+", past[end]]
|
|
567
684
|
})
|
|
568
|
-
},
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
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
|
|