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.
- package/CHANGELOG.md +38 -2
- package/README.md +25 -17
- package/dist/MagicPill/MagicPill.d.mts +16 -2
- package/dist/MagicPill/MagicPill.d.ts +16 -2
- package/dist/MagicPill/MagicPill.js +12 -3
- package/dist/MagicPill/MagicPill.mjs +12 -3
- package/dist/Pill/Pill.js +1 -0
- package/dist/Pill/Pill.mjs +1 -0
- package/dist/Pill/goo.js +110 -35
- package/dist/Pill/goo.mjs +110 -36
- package/dist/Pill/modal.js +3 -1
- package/dist/Pill/modal.mjs +3 -1
- package/dist/Pill/morph.js +64 -10
- package/dist/Pill/morph.mjs +64 -11
- package/dist/Pill/zone.js +1 -2
- package/dist/Pill/zone.mjs +1 -2
- package/dist/PillForm/PillForm.js +6 -1
- package/dist/PillForm/PillForm.mjs +7 -2
- package/dist/PillForm/dates.js +14 -3
- package/dist/PillForm/dates.mjs +14 -3
- package/dist/PillForm/room.js +46 -0
- package/dist/PillForm/room.mjs +46 -0
- package/dist/PillNavbar/PillNavbar.js +3 -1
- package/dist/PillNavbar/PillNavbar.mjs +4 -2
- package/dist/PillNavbar/room.js +99 -24
- package/dist/PillNavbar/room.mjs +98 -25
- package/dist/PillNotification/PillNotification.js +2 -4
- package/dist/PillNotification/PillNotification.mjs +2 -4
- package/dist/PillNotification/RowsBody.js +77 -0
- package/dist/PillNotification/RowsBody.mjs +77 -0
- package/dist/forms.css +14 -0
- package/dist/satellites/Actions.js +181 -6
- package/dist/satellites/Actions.mjs +182 -7
- package/dist/satellites/Orbitals.js +218 -50
- package/dist/satellites/Orbitals.mjs +220 -52
- package/dist/satellites/Satellites.js +495 -107
- package/dist/satellites/Satellites.mjs +498 -111
- package/dist/satellites/handoff.js +36 -0
- package/dist/satellites/handoff.mjs +34 -0
- package/dist/satellites/layout.js +69 -3
- package/dist/satellites/layout.mjs +69 -4
- package/dist/satellites/measure.js +22 -0
- package/dist/satellites/measure.mjs +22 -1
- package/dist/satellites/orbits.js +49 -2
- package/dist/satellites/orbits.mjs +47 -3
- package/dist/satellites/types.d.mts +15 -1
- package/dist/satellites/types.d.ts +15 -1
- package/dist/satellites.d.mts +2 -2
- package/dist/satellites.d.ts +2 -2
- package/dist/styles.css +103 -15
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
let react = require("react");
|
|
4
|
+
|
|
5
|
+
// src/satellites/handoff.ts
|
|
6
|
+
const entries = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
const entryOf = (store) => {
|
|
8
|
+
let entry = entries.get(store);
|
|
9
|
+
if (!entry) {
|
|
10
|
+
entry = {
|
|
11
|
+
value: void 0,
|
|
12
|
+
listeners: /* @__PURE__ */ new Set()
|
|
13
|
+
};
|
|
14
|
+
entries.set(store, entry);
|
|
15
|
+
}
|
|
16
|
+
return entry;
|
|
17
|
+
};
|
|
18
|
+
function setHandoff(store, value) {
|
|
19
|
+
const entry = entryOf(store);
|
|
20
|
+
if (entry.value === value) return;
|
|
21
|
+
entry.value = value;
|
|
22
|
+
for (const listener of entry.listeners) listener();
|
|
23
|
+
}
|
|
24
|
+
const getHandoff = (store) => entryOf(store).value;
|
|
25
|
+
/** The host's handoff, as it changes. */
|
|
26
|
+
function useHandoff(store) {
|
|
27
|
+
const entry = entryOf(store);
|
|
28
|
+
return (0, react.useSyncExternalStore)((listener) => {
|
|
29
|
+
entry.listeners.add(listener);
|
|
30
|
+
return () => entry.listeners.delete(listener);
|
|
31
|
+
}, () => entry.value, () => void 0);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.getHandoff = getHandoff;
|
|
35
|
+
exports.setHandoff = setHandoff;
|
|
36
|
+
exports.useHandoff = useHandoff;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useSyncExternalStore } from "react";
|
|
4
|
+
|
|
5
|
+
// src/satellites/handoff.ts
|
|
6
|
+
const entries = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
const entryOf = (store) => {
|
|
8
|
+
let entry = entries.get(store);
|
|
9
|
+
if (!entry) {
|
|
10
|
+
entry = {
|
|
11
|
+
value: void 0,
|
|
12
|
+
listeners: /* @__PURE__ */ new Set()
|
|
13
|
+
};
|
|
14
|
+
entries.set(store, entry);
|
|
15
|
+
}
|
|
16
|
+
return entry;
|
|
17
|
+
};
|
|
18
|
+
function setHandoff(store, value) {
|
|
19
|
+
const entry = entryOf(store);
|
|
20
|
+
if (entry.value === value) return;
|
|
21
|
+
entry.value = value;
|
|
22
|
+
for (const listener of entry.listeners) listener();
|
|
23
|
+
}
|
|
24
|
+
const getHandoff = (store) => entryOf(store).value;
|
|
25
|
+
/** The host's handoff, as it changes. */
|
|
26
|
+
function useHandoff(store) {
|
|
27
|
+
const entry = entryOf(store);
|
|
28
|
+
return useSyncExternalStore((listener) => {
|
|
29
|
+
entry.listeners.add(listener);
|
|
30
|
+
return () => entry.listeners.delete(listener);
|
|
31
|
+
}, () => entry.value, () => void 0);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { getHandoff, setHandoff, useHandoff };
|
|
@@ -1,5 +1,69 @@
|
|
|
1
1
|
// src/satellites/layout.ts
|
|
2
|
+
/** How much of the obstacles the satellites cover, in px² (0: clear of them all) */
|
|
3
|
+
function coverage(boxes, obstacles) {
|
|
4
|
+
let covered = 0;
|
|
5
|
+
for (const box of Object.values(boxes)) for (const obstacle of obstacles) {
|
|
6
|
+
const width = Math.min(box.left + box.width, obstacle.left + obstacle.width) - Math.max(box.left, obstacle.left);
|
|
7
|
+
const height = Math.min(box.top + box.height, obstacle.top + obstacle.height) - Math.max(box.top, obstacle.top);
|
|
8
|
+
if (width > 0 && height > 0) covered += width * height;
|
|
9
|
+
}
|
|
10
|
+
return covered;
|
|
11
|
+
}
|
|
2
12
|
function planSatellites(input) {
|
|
13
|
+
const first = plan(input);
|
|
14
|
+
const { actions, obstacles } = input;
|
|
15
|
+
if (!actions || !obstacles?.length) return first;
|
|
16
|
+
let best = first;
|
|
17
|
+
let least = coverage(first.boxes, obstacles);
|
|
18
|
+
if (least === 0) return first;
|
|
19
|
+
const otherSide = {
|
|
20
|
+
start: "end",
|
|
21
|
+
end: "start",
|
|
22
|
+
beside: void 0
|
|
23
|
+
}[actions.side];
|
|
24
|
+
const tries = [];
|
|
25
|
+
if (otherSide) tries.push({
|
|
26
|
+
...actions,
|
|
27
|
+
side: otherSide
|
|
28
|
+
});
|
|
29
|
+
if (actions.turn === "auto") {
|
|
30
|
+
tries.push({
|
|
31
|
+
...actions,
|
|
32
|
+
turn: "across"
|
|
33
|
+
});
|
|
34
|
+
if (otherSide) tries.push({
|
|
35
|
+
...actions,
|
|
36
|
+
side: otherSide,
|
|
37
|
+
turn: "across"
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const { wheel } = actions;
|
|
41
|
+
if (wheel) for (let shown = wheel.count - 1; shown >= 1; shown--) {
|
|
42
|
+
tries.push({
|
|
43
|
+
...actions,
|
|
44
|
+
shown
|
|
45
|
+
});
|
|
46
|
+
if (otherSide) tries.push({
|
|
47
|
+
...actions,
|
|
48
|
+
side: otherSide,
|
|
49
|
+
shown
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
for (const tried of tries) {
|
|
53
|
+
const layout = plan({
|
|
54
|
+
...input,
|
|
55
|
+
actions: tried
|
|
56
|
+
});
|
|
57
|
+
const covered = coverage(layout.boxes, obstacles);
|
|
58
|
+
if (covered < least) {
|
|
59
|
+
best = layout;
|
|
60
|
+
least = covered;
|
|
61
|
+
if (covered === 0) break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return best;
|
|
65
|
+
}
|
|
66
|
+
function plan(input) {
|
|
3
67
|
const { viewport, host, placement, vertical, electrons, side, line, gap, offset, actions } = input;
|
|
4
68
|
const rtl = input.rtl && !vertical;
|
|
5
69
|
const sizes = new Map(electrons.map((electron) => [electron.id, electron]));
|
|
@@ -7,8 +71,9 @@ function planSatellites(input) {
|
|
|
7
71
|
const mainLength = vertical ? viewport.height : viewport.width;
|
|
8
72
|
const available = mainLength - offset * 2;
|
|
9
73
|
let actionsAcross = actions?.turn === "across";
|
|
10
|
-
let actionsShown;
|
|
11
74
|
const wheel = actions?.wheel && actions.wheel.count > 1 && !actionsAcross ? actions.wheel : void 0;
|
|
75
|
+
const cap = wheel && actions?.shown !== void 0 && actions.shown < wheel.count ? actions.shown : void 0;
|
|
76
|
+
let actionsShown = cap;
|
|
12
77
|
const setActionsBox = () => {
|
|
13
78
|
if (!actions) return;
|
|
14
79
|
const along = {
|
|
@@ -33,7 +98,7 @@ function planSatellites(input) {
|
|
|
33
98
|
if (!wheel || !actions) return false;
|
|
34
99
|
const fit = fitting(len(actions) - over);
|
|
35
100
|
if (fit < least || fit >= wheel.count) return false;
|
|
36
|
-
actionsShown = fit;
|
|
101
|
+
actionsShown = cap === void 0 ? fit : Math.min(fit, cap);
|
|
37
102
|
setActionsBox();
|
|
38
103
|
return true;
|
|
39
104
|
};
|
|
@@ -83,7 +148,7 @@ function planSatellites(input) {
|
|
|
83
148
|
const besideRow = () => [...sides.beside.includes("actions") ? ["actions"] : [], ...sides.beside.filter((id) => id !== "actions").reverse()];
|
|
84
149
|
const lengthOfRow = (ids) => Math.max(0, lengthOf(ids) - gap);
|
|
85
150
|
if (actions && sides.beside.includes("actions")) {
|
|
86
|
-
actionsShown =
|
|
151
|
+
actionsShown = cap;
|
|
87
152
|
actionsAcross = actions.turn === "across";
|
|
88
153
|
setActionsBox();
|
|
89
154
|
const over = lengthOfRow(besideRow()) - available;
|
|
@@ -206,4 +271,5 @@ function planSatellites(input) {
|
|
|
206
271
|
};
|
|
207
272
|
}
|
|
208
273
|
|
|
274
|
+
exports.coverage = coverage;
|
|
209
275
|
exports.planSatellites = planSatellites;
|
|
@@ -1,5 +1,69 @@
|
|
|
1
1
|
// src/satellites/layout.ts
|
|
2
|
+
/** How much of the obstacles the satellites cover, in px² (0: clear of them all) */
|
|
3
|
+
function coverage(boxes, obstacles) {
|
|
4
|
+
let covered = 0;
|
|
5
|
+
for (const box of Object.values(boxes)) for (const obstacle of obstacles) {
|
|
6
|
+
const width = Math.min(box.left + box.width, obstacle.left + obstacle.width) - Math.max(box.left, obstacle.left);
|
|
7
|
+
const height = Math.min(box.top + box.height, obstacle.top + obstacle.height) - Math.max(box.top, obstacle.top);
|
|
8
|
+
if (width > 0 && height > 0) covered += width * height;
|
|
9
|
+
}
|
|
10
|
+
return covered;
|
|
11
|
+
}
|
|
2
12
|
function planSatellites(input) {
|
|
13
|
+
const first = plan(input);
|
|
14
|
+
const { actions, obstacles } = input;
|
|
15
|
+
if (!actions || !obstacles?.length) return first;
|
|
16
|
+
let best = first;
|
|
17
|
+
let least = coverage(first.boxes, obstacles);
|
|
18
|
+
if (least === 0) return first;
|
|
19
|
+
const otherSide = {
|
|
20
|
+
start: "end",
|
|
21
|
+
end: "start",
|
|
22
|
+
beside: void 0
|
|
23
|
+
}[actions.side];
|
|
24
|
+
const tries = [];
|
|
25
|
+
if (otherSide) tries.push({
|
|
26
|
+
...actions,
|
|
27
|
+
side: otherSide
|
|
28
|
+
});
|
|
29
|
+
if (actions.turn === "auto") {
|
|
30
|
+
tries.push({
|
|
31
|
+
...actions,
|
|
32
|
+
turn: "across"
|
|
33
|
+
});
|
|
34
|
+
if (otherSide) tries.push({
|
|
35
|
+
...actions,
|
|
36
|
+
side: otherSide,
|
|
37
|
+
turn: "across"
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const { wheel } = actions;
|
|
41
|
+
if (wheel) for (let shown = wheel.count - 1; shown >= 1; shown--) {
|
|
42
|
+
tries.push({
|
|
43
|
+
...actions,
|
|
44
|
+
shown
|
|
45
|
+
});
|
|
46
|
+
if (otherSide) tries.push({
|
|
47
|
+
...actions,
|
|
48
|
+
side: otherSide,
|
|
49
|
+
shown
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
for (const tried of tries) {
|
|
53
|
+
const layout = plan({
|
|
54
|
+
...input,
|
|
55
|
+
actions: tried
|
|
56
|
+
});
|
|
57
|
+
const covered = coverage(layout.boxes, obstacles);
|
|
58
|
+
if (covered < least) {
|
|
59
|
+
best = layout;
|
|
60
|
+
least = covered;
|
|
61
|
+
if (covered === 0) break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return best;
|
|
65
|
+
}
|
|
66
|
+
function plan(input) {
|
|
3
67
|
const { viewport, host, placement, vertical, electrons, side, line, gap, offset, actions } = input;
|
|
4
68
|
const rtl = input.rtl && !vertical;
|
|
5
69
|
const sizes = new Map(electrons.map((electron) => [electron.id, electron]));
|
|
@@ -7,8 +71,9 @@ function planSatellites(input) {
|
|
|
7
71
|
const mainLength = vertical ? viewport.height : viewport.width;
|
|
8
72
|
const available = mainLength - offset * 2;
|
|
9
73
|
let actionsAcross = actions?.turn === "across";
|
|
10
|
-
let actionsShown;
|
|
11
74
|
const wheel = actions?.wheel && actions.wheel.count > 1 && !actionsAcross ? actions.wheel : void 0;
|
|
75
|
+
const cap = wheel && actions?.shown !== void 0 && actions.shown < wheel.count ? actions.shown : void 0;
|
|
76
|
+
let actionsShown = cap;
|
|
12
77
|
const setActionsBox = () => {
|
|
13
78
|
if (!actions) return;
|
|
14
79
|
const along = {
|
|
@@ -33,7 +98,7 @@ function planSatellites(input) {
|
|
|
33
98
|
if (!wheel || !actions) return false;
|
|
34
99
|
const fit = fitting(len(actions) - over);
|
|
35
100
|
if (fit < least || fit >= wheel.count) return false;
|
|
36
|
-
actionsShown = fit;
|
|
101
|
+
actionsShown = cap === void 0 ? fit : Math.min(fit, cap);
|
|
37
102
|
setActionsBox();
|
|
38
103
|
return true;
|
|
39
104
|
};
|
|
@@ -83,7 +148,7 @@ function planSatellites(input) {
|
|
|
83
148
|
const besideRow = () => [...sides.beside.includes("actions") ? ["actions"] : [], ...sides.beside.filter((id) => id !== "actions").reverse()];
|
|
84
149
|
const lengthOfRow = (ids) => Math.max(0, lengthOf(ids) - gap);
|
|
85
150
|
if (actions && sides.beside.includes("actions")) {
|
|
86
|
-
actionsShown =
|
|
151
|
+
actionsShown = cap;
|
|
87
152
|
actionsAcross = actions.turn === "across";
|
|
88
153
|
setActionsBox();
|
|
89
154
|
const over = lengthOfRow(besideRow()) - available;
|
|
@@ -206,4 +271,4 @@ function planSatellites(input) {
|
|
|
206
271
|
};
|
|
207
272
|
}
|
|
208
273
|
|
|
209
|
-
export { planSatellites };
|
|
274
|
+
export { coverage, planSatellites };
|
|
@@ -20,6 +20,28 @@ function durations(element) {
|
|
|
20
20
|
change: require_timing.parseDuration(style.getPropertyValue("--_mp-change"), 250)
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* The other pills on the screen (a sidebar, a help pill…), for the satellites to keep clear of:
|
|
25
|
+
* the fixed ones that show, not the host, nor what's in it, nor any satellite (inline pills).
|
|
26
|
+
* The electrons and the page's actions go elsewhere over one; an electron's orbitals turn away.
|
|
27
|
+
*/
|
|
28
|
+
function otherPills(root) {
|
|
29
|
+
const boxes = [];
|
|
30
|
+
for (const element of document.querySelectorAll("[data-mp=\"pill\"][data-placement]")) {
|
|
31
|
+
const { placement, presence } = element.dataset;
|
|
32
|
+
if (placement === "inline" || placement === "overlay" || presence === "hidden") continue;
|
|
33
|
+
if (element === root || root.contains(element) || element.contains(root)) continue;
|
|
34
|
+
const { left, top, width, height } = element.getBoundingClientRect();
|
|
35
|
+
if (width > 0 && height > 0) boxes.push({
|
|
36
|
+
left,
|
|
37
|
+
top,
|
|
38
|
+
width,
|
|
39
|
+
height
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return boxes;
|
|
43
|
+
}
|
|
23
44
|
|
|
24
45
|
exports.durations = durations;
|
|
46
|
+
exports.otherPills = otherPills;
|
|
25
47
|
exports.toPixels = toPixels;
|
|
@@ -20,5 +20,26 @@ function durations(element) {
|
|
|
20
20
|
change: parseDuration(style.getPropertyValue("--_mp-change"), 250)
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* The other pills on the screen (a sidebar, a help pill…), for the satellites to keep clear of:
|
|
25
|
+
* the fixed ones that show, not the host, nor what's in it, nor any satellite (inline pills).
|
|
26
|
+
* The electrons and the page's actions go elsewhere over one; an electron's orbitals turn away.
|
|
27
|
+
*/
|
|
28
|
+
function otherPills(root) {
|
|
29
|
+
const boxes = [];
|
|
30
|
+
for (const element of document.querySelectorAll("[data-mp=\"pill\"][data-placement]")) {
|
|
31
|
+
const { placement, presence } = element.dataset;
|
|
32
|
+
if (placement === "inline" || placement === "overlay" || presence === "hidden") continue;
|
|
33
|
+
if (element === root || root.contains(element) || element.contains(root)) continue;
|
|
34
|
+
const { left, top, width, height } = element.getBoundingClientRect();
|
|
35
|
+
if (width > 0 && height > 0) boxes.push({
|
|
36
|
+
left,
|
|
37
|
+
top,
|
|
38
|
+
width,
|
|
39
|
+
height
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return boxes;
|
|
43
|
+
}
|
|
23
44
|
|
|
24
|
-
export { durations, toPixels };
|
|
45
|
+
export { durations, otherPills, toPixels };
|
|
@@ -1,14 +1,58 @@
|
|
|
1
1
|
// src/satellites/orbits.ts
|
|
2
|
+
/** The same orbit moved by `dx`, `dy` with its electron (the arc and everything on it). */
|
|
3
|
+
const movedOrbit = (orbit, dx, dy) => ({
|
|
4
|
+
...orbit,
|
|
5
|
+
x: orbit.x + dx,
|
|
6
|
+
y: orbit.y + dy,
|
|
7
|
+
spots: orbit.spots.map((spot) => ({
|
|
8
|
+
...spot,
|
|
9
|
+
x: spot.x + dx,
|
|
10
|
+
y: spot.y + dy
|
|
11
|
+
}))
|
|
12
|
+
});
|
|
2
13
|
/** How far a wheel can turn: from 0 to this many orbitals. */
|
|
3
14
|
const wheelEnd = (orbit) => Math.max(0, orbit.count - orbit.visible);
|
|
15
|
+
/** Orbital `index`'s slot on the arc (0 to visible − 1 on it), mirrored in a right-to-left page. */
|
|
16
|
+
const slotOf = (orbit, index, turn) => orbit.rtl ? orbit.visible - 1 - index + turn : index - turn;
|
|
17
|
+
/**
|
|
18
|
+
* How many orbitals are past each end of a wheel's arc, turned by `turn`:
|
|
19
|
+
* `low` past its first slot, `high` past its last one.
|
|
20
|
+
*/
|
|
21
|
+
function hiddenPast(orbit, turn = 0) {
|
|
22
|
+
const past = {
|
|
23
|
+
low: 0,
|
|
24
|
+
high: 0
|
|
25
|
+
};
|
|
26
|
+
if (!orbit.wheel) return past;
|
|
27
|
+
for (let index = 0; index < orbit.count; index++) {
|
|
28
|
+
const slot = slotOf(orbit, index, turn);
|
|
29
|
+
if (slot < -.5) past.low++;
|
|
30
|
+
else if (slot > orbit.visible - .5) past.high++;
|
|
31
|
+
}
|
|
32
|
+
return past;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A point by an end of the arc (its first slot, low, or its last one, high):
|
|
36
|
+
* `along` px past it on the orbit, `outward` px further from the electron.
|
|
37
|
+
*/
|
|
38
|
+
function pastEnd(orbit, end, along, outward = 0) {
|
|
39
|
+
const degrees = along / orbit.radius * (180 / Math.PI);
|
|
40
|
+
const angle = end === "low" ? orbit.first - degrees : orbit.first + (orbit.visible - 1) * orbit.step + degrees;
|
|
41
|
+
const radius = orbit.radius + outward;
|
|
42
|
+
return {
|
|
43
|
+
x: orbit.x + Math.cos(radians(angle)) * radius,
|
|
44
|
+
y: orbit.y + Math.sin(radians(angle)) * radius,
|
|
45
|
+
angle
|
|
46
|
+
};
|
|
47
|
+
}
|
|
4
48
|
/**
|
|
5
49
|
* Where orbital `index` is with the wheel turned by `turn` orbitals: on the
|
|
6
50
|
* arc's slots, fading out past either end (the next one peeks out at a
|
|
7
51
|
* fifth), mirrored in a right-to-left page (the first one on the right).
|
|
8
52
|
*/
|
|
9
53
|
function spotOn(orbit, index, turn = 0) {
|
|
10
|
-
const {
|
|
11
|
-
const slot = orbit
|
|
54
|
+
const { visible } = orbit;
|
|
55
|
+
const slot = slotOf(orbit, index, turn);
|
|
12
56
|
const angle = orbit.first + slot * orbit.step;
|
|
13
57
|
const past = slot < 0 ? -slot : slot > visible - 1 ? slot - (visible - 1) : 0;
|
|
14
58
|
const peeks = slot < 0 ? orbit.peek.low : orbit.peek.high;
|
|
@@ -133,7 +177,10 @@ function orbitalAt(orbit, size, electronRadius, px, py, turn = 0) {
|
|
|
133
177
|
return bestGap <= Math.max(orbit.step / 2 + 8, 30) ? best : -1;
|
|
134
178
|
}
|
|
135
179
|
|
|
180
|
+
exports.hiddenPast = hiddenPast;
|
|
181
|
+
exports.movedOrbit = movedOrbit;
|
|
136
182
|
exports.orbitalAt = orbitalAt;
|
|
183
|
+
exports.pastEnd = pastEnd;
|
|
137
184
|
exports.planOrbit = planOrbit;
|
|
138
185
|
exports.spotOn = spotOn;
|
|
139
186
|
exports.wheelEnd = wheelEnd;
|
|
@@ -1,14 +1,58 @@
|
|
|
1
1
|
// src/satellites/orbits.ts
|
|
2
|
+
/** The same orbit moved by `dx`, `dy` with its electron (the arc and everything on it). */
|
|
3
|
+
const movedOrbit = (orbit, dx, dy) => ({
|
|
4
|
+
...orbit,
|
|
5
|
+
x: orbit.x + dx,
|
|
6
|
+
y: orbit.y + dy,
|
|
7
|
+
spots: orbit.spots.map((spot) => ({
|
|
8
|
+
...spot,
|
|
9
|
+
x: spot.x + dx,
|
|
10
|
+
y: spot.y + dy
|
|
11
|
+
}))
|
|
12
|
+
});
|
|
2
13
|
/** How far a wheel can turn: from 0 to this many orbitals. */
|
|
3
14
|
const wheelEnd = (orbit) => Math.max(0, orbit.count - orbit.visible);
|
|
15
|
+
/** Orbital `index`'s slot on the arc (0 to visible − 1 on it), mirrored in a right-to-left page. */
|
|
16
|
+
const slotOf = (orbit, index, turn) => orbit.rtl ? orbit.visible - 1 - index + turn : index - turn;
|
|
17
|
+
/**
|
|
18
|
+
* How many orbitals are past each end of a wheel's arc, turned by `turn`:
|
|
19
|
+
* `low` past its first slot, `high` past its last one.
|
|
20
|
+
*/
|
|
21
|
+
function hiddenPast(orbit, turn = 0) {
|
|
22
|
+
const past = {
|
|
23
|
+
low: 0,
|
|
24
|
+
high: 0
|
|
25
|
+
};
|
|
26
|
+
if (!orbit.wheel) return past;
|
|
27
|
+
for (let index = 0; index < orbit.count; index++) {
|
|
28
|
+
const slot = slotOf(orbit, index, turn);
|
|
29
|
+
if (slot < -.5) past.low++;
|
|
30
|
+
else if (slot > orbit.visible - .5) past.high++;
|
|
31
|
+
}
|
|
32
|
+
return past;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A point by an end of the arc (its first slot, low, or its last one, high):
|
|
36
|
+
* `along` px past it on the orbit, `outward` px further from the electron.
|
|
37
|
+
*/
|
|
38
|
+
function pastEnd(orbit, end, along, outward = 0) {
|
|
39
|
+
const degrees = along / orbit.radius * (180 / Math.PI);
|
|
40
|
+
const angle = end === "low" ? orbit.first - degrees : orbit.first + (orbit.visible - 1) * orbit.step + degrees;
|
|
41
|
+
const radius = orbit.radius + outward;
|
|
42
|
+
return {
|
|
43
|
+
x: orbit.x + Math.cos(radians(angle)) * radius,
|
|
44
|
+
y: orbit.y + Math.sin(radians(angle)) * radius,
|
|
45
|
+
angle
|
|
46
|
+
};
|
|
47
|
+
}
|
|
4
48
|
/**
|
|
5
49
|
* Where orbital `index` is with the wheel turned by `turn` orbitals: on the
|
|
6
50
|
* arc's slots, fading out past either end (the next one peeks out at a
|
|
7
51
|
* fifth), mirrored in a right-to-left page (the first one on the right).
|
|
8
52
|
*/
|
|
9
53
|
function spotOn(orbit, index, turn = 0) {
|
|
10
|
-
const {
|
|
11
|
-
const slot = orbit
|
|
54
|
+
const { visible } = orbit;
|
|
55
|
+
const slot = slotOf(orbit, index, turn);
|
|
12
56
|
const angle = orbit.first + slot * orbit.step;
|
|
13
57
|
const past = slot < 0 ? -slot : slot > visible - 1 ? slot - (visible - 1) : 0;
|
|
14
58
|
const peeks = slot < 0 ? orbit.peek.low : orbit.peek.high;
|
|
@@ -133,4 +177,4 @@ function orbitalAt(orbit, size, electronRadius, px, py, turn = 0) {
|
|
|
133
177
|
return bestGap <= Math.max(orbit.step / 2 + 8, 30) ? best : -1;
|
|
134
178
|
}
|
|
135
179
|
|
|
136
|
-
export { orbitalAt, planOrbit, spotOn, wheelEnd };
|
|
180
|
+
export { hiddenPast, movedOrbit, orbitalAt, pastEnd, planOrbit, spotOn, wheelEnd };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentType, RefObject } from "react";
|
|
1
|
+
import { CSSProperties, ComponentType, RefObject } from "react";
|
|
2
2
|
import { LinkComponent, PillPlacement, PillTheme, PillVariant } from "../Pill/types.mjs";
|
|
3
3
|
import { PillStore } from "../store/store.mjs";
|
|
4
4
|
/** Where electrons go: further along the edge, before the pill, or one row towards the page. */
|
|
@@ -18,6 +18,11 @@ export type ActionsOrientation = "auto" | "horizontal" | "vertical";
|
|
|
18
18
|
export type NearestToPill = "electrons" | "actions";
|
|
19
19
|
/** What opens an electron's orbitals: a long press or hovering it with a mouse, a long press only, or a tap. */
|
|
20
20
|
export type OrbitalsOpenOn = "press-hover" | "press" | "tap";
|
|
21
|
+
/**
|
|
22
|
+
* How a wheel of orbitals says there are more past its ends: the next one
|
|
23
|
+
* peeking out where there's room, small dots, or a count that turns the wheel.
|
|
24
|
+
*/
|
|
25
|
+
export type OrbitalsMore = "peek" | "dots" | "count";
|
|
21
26
|
/** The host, as its satellites see it. */
|
|
22
27
|
export interface SatelliteHost {
|
|
23
28
|
name: string;
|
|
@@ -31,6 +36,12 @@ export interface SatelliteHost {
|
|
|
31
36
|
linkComponent?: LinkComponent;
|
|
32
37
|
variant?: PillVariant;
|
|
33
38
|
theme?: PillTheme;
|
|
39
|
+
/**
|
|
40
|
+
* The tokens (`--mp-*`) set in the host's own `style`: its satellites take them too (they're pills of
|
|
41
|
+
* their own beside it, not inside it, so they don't inherit them). The adaptive glass, the light
|
|
42
|
+
* following the pointer, the readability veil… applied to the main pill only
|
|
43
|
+
*/
|
|
44
|
+
tokens?: CSSProperties;
|
|
34
45
|
electronSide: ElectronSide;
|
|
35
46
|
electronLine: ElectronLine;
|
|
36
47
|
keepElectronsOut: boolean;
|
|
@@ -38,12 +49,15 @@ export interface SatelliteHost {
|
|
|
38
49
|
arrange: SatelliteArrangement;
|
|
39
50
|
orbitalsOpenOn: OrbitalsOpenOn;
|
|
40
51
|
orbitalLabels: boolean;
|
|
52
|
+
orbitalsMore: OrbitalsMore;
|
|
41
53
|
orbitalsStayOpen: boolean;
|
|
42
54
|
actionsStyle: ActionsStyle;
|
|
43
55
|
actionsSide: ActionsSide;
|
|
44
56
|
actionsOrientation: ActionsOrientation;
|
|
45
57
|
actionsWheel: boolean;
|
|
46
58
|
nearestToPill: NearestToPill;
|
|
59
|
+
/** Keep clear of the other pills on the screen */
|
|
60
|
+
avoidPills: boolean;
|
|
47
61
|
actionsLabel: string;
|
|
48
62
|
}
|
|
49
63
|
/** `satellites` from `magic-pill/satellites`, passed to `<MagicPill satellites={satellites}>`. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentType, RefObject } from "react";
|
|
1
|
+
import { CSSProperties, ComponentType, RefObject } from "react";
|
|
2
2
|
import { LinkComponent, PillPlacement, PillTheme, PillVariant } from "../Pill/types.js";
|
|
3
3
|
import { PillStore } from "../store/store.js";
|
|
4
4
|
/** Where electrons go: further along the edge, before the pill, or one row towards the page. */
|
|
@@ -18,6 +18,11 @@ export type ActionsOrientation = "auto" | "horizontal" | "vertical";
|
|
|
18
18
|
export type NearestToPill = "electrons" | "actions";
|
|
19
19
|
/** What opens an electron's orbitals: a long press or hovering it with a mouse, a long press only, or a tap. */
|
|
20
20
|
export type OrbitalsOpenOn = "press-hover" | "press" | "tap";
|
|
21
|
+
/**
|
|
22
|
+
* How a wheel of orbitals says there are more past its ends: the next one
|
|
23
|
+
* peeking out where there's room, small dots, or a count that turns the wheel.
|
|
24
|
+
*/
|
|
25
|
+
export type OrbitalsMore = "peek" | "dots" | "count";
|
|
21
26
|
/** The host, as its satellites see it. */
|
|
22
27
|
export interface SatelliteHost {
|
|
23
28
|
name: string;
|
|
@@ -31,6 +36,12 @@ export interface SatelliteHost {
|
|
|
31
36
|
linkComponent?: LinkComponent;
|
|
32
37
|
variant?: PillVariant;
|
|
33
38
|
theme?: PillTheme;
|
|
39
|
+
/**
|
|
40
|
+
* The tokens (`--mp-*`) set in the host's own `style`: its satellites take them too (they're pills of
|
|
41
|
+
* their own beside it, not inside it, so they don't inherit them). The adaptive glass, the light
|
|
42
|
+
* following the pointer, the readability veil… applied to the main pill only
|
|
43
|
+
*/
|
|
44
|
+
tokens?: CSSProperties;
|
|
34
45
|
electronSide: ElectronSide;
|
|
35
46
|
electronLine: ElectronLine;
|
|
36
47
|
keepElectronsOut: boolean;
|
|
@@ -38,12 +49,15 @@ export interface SatelliteHost {
|
|
|
38
49
|
arrange: SatelliteArrangement;
|
|
39
50
|
orbitalsOpenOn: OrbitalsOpenOn;
|
|
40
51
|
orbitalLabels: boolean;
|
|
52
|
+
orbitalsMore: OrbitalsMore;
|
|
41
53
|
orbitalsStayOpen: boolean;
|
|
42
54
|
actionsStyle: ActionsStyle;
|
|
43
55
|
actionsSide: ActionsSide;
|
|
44
56
|
actionsOrientation: ActionsOrientation;
|
|
45
57
|
actionsWheel: boolean;
|
|
46
58
|
nearestToPill: NearestToPill;
|
|
59
|
+
/** Keep clear of the other pills on the screen */
|
|
60
|
+
avoidPills: boolean;
|
|
47
61
|
actionsLabel: string;
|
|
48
62
|
}
|
|
49
63
|
/** `satellites` from `magic-pill/satellites`, passed to `<MagicPill satellites={satellites}>`. */
|
package/dist/satellites.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ActionsOrientation, ActionsSide, ActionsStyle, ElectronEnding, ElectronLine, ElectronSide, NearestToPill, OrbitalsOpenOn, PillSatellites, SatelliteArrangement } from "./satellites/types.mjs";
|
|
1
|
+
import { ActionsOrientation, ActionsSide, ActionsStyle, ElectronEnding, ElectronLine, ElectronSide, NearestToPill, OrbitalsMore, OrbitalsOpenOn, PillSatellites, SatelliteArrangement } from "./satellites/types.mjs";
|
|
2
2
|
import { usePillActions } from "./satellites/Actions.mjs";
|
|
3
3
|
import { Electron, ElectronOptions, Orbital, PillActionItem } from "./store/store.mjs";
|
|
4
4
|
export declare const satellites: PillSatellites;
|
|
5
|
-
export { type ActionsOrientation, type ActionsSide, type ActionsStyle, type Electron, type ElectronEnding, type ElectronLine, type ElectronOptions, type ElectronSide, type NearestToPill, type Orbital, type OrbitalsOpenOn, type PillActionItem, type PillSatellites, type SatelliteArrangement, usePillActions };
|
|
5
|
+
export { type ActionsOrientation, type ActionsSide, type ActionsStyle, type Electron, type ElectronEnding, type ElectronLine, type ElectronOptions, type ElectronSide, type NearestToPill, type Orbital, type OrbitalsMore, type OrbitalsOpenOn, type PillActionItem, type PillSatellites, type SatelliteArrangement, usePillActions };
|
package/dist/satellites.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ActionsOrientation, ActionsSide, ActionsStyle, ElectronEnding, ElectronLine, ElectronSide, NearestToPill, OrbitalsOpenOn, PillSatellites, SatelliteArrangement } from "./satellites/types.js";
|
|
1
|
+
import { ActionsOrientation, ActionsSide, ActionsStyle, ElectronEnding, ElectronLine, ElectronSide, NearestToPill, OrbitalsMore, OrbitalsOpenOn, PillSatellites, SatelliteArrangement } from "./satellites/types.js";
|
|
2
2
|
import { usePillActions } from "./satellites/Actions.js";
|
|
3
3
|
import { Electron, ElectronOptions, Orbital, PillActionItem } from "./store/store.js";
|
|
4
4
|
export declare const satellites: PillSatellites;
|
|
5
|
-
export { type ActionsOrientation, type ActionsSide, type ActionsStyle, type Electron, type ElectronEnding, type ElectronLine, type ElectronOptions, type ElectronSide, type NearestToPill, type Orbital, type OrbitalsOpenOn, type PillActionItem, type PillSatellites, type SatelliteArrangement, usePillActions };
|
|
5
|
+
export { type ActionsOrientation, type ActionsSide, type ActionsStyle, type Electron, type ElectronEnding, type ElectronLine, type ElectronOptions, type ElectronSide, type NearestToPill, type Orbital, type OrbitalsMore, type OrbitalsOpenOn, type PillActionItem, type PillSatellites, type SatelliteArrangement, usePillActions };
|