magic-pill 9.3.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.
- package/CHANGELOG.md +12 -0
- package/README.md +114 -3
- package/dist/MagicPill/MagicPill.d.mts +43 -1
- package/dist/MagicPill/MagicPill.d.ts +43 -1
- package/dist/MagicPill/MagicPill.js +51 -4
- package/dist/MagicPill/MagicPill.mjs +53 -6
- package/dist/MagicPill/flag.js +1 -59
- package/dist/MagicPill/flag.mjs +1 -58
- package/dist/Pill/PillProgress.d.mts +12 -0
- package/dist/Pill/PillProgress.d.ts +12 -0
- package/dist/Pill/PillProgress.js +42 -0
- package/dist/Pill/PillProgress.mjs +42 -0
- package/dist/Pill/goo.js +353 -0
- package/dist/Pill/goo.mjs +347 -0
- package/dist/Pill/morph.js +4 -2
- package/dist/Pill/morph.mjs +4 -2
- package/dist/PillNavbar/PillNavbar.d.mts +8 -0
- package/dist/PillNavbar/PillNavbar.d.ts +8 -0
- package/dist/PillNavbar/PillNavbar.js +3 -2
- package/dist/PillNavbar/PillNavbar.mjs +3 -2
- package/dist/PillNavbar/room.d.mts +3 -0
- package/dist/PillNavbar/room.d.ts +2 -0
- package/dist/PillNavbar/room.js +89 -17
- package/dist/PillNavbar/room.mjs +89 -18
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -0
- package/dist/index.mjs +2 -1
- package/dist/satellites/Actions.d.mts +12 -0
- package/dist/satellites/Actions.d.ts +11 -0
- package/dist/satellites/Actions.js +59 -0
- package/dist/satellites/Actions.mjs +56 -0
- package/dist/satellites/Orbitals.js +554 -0
- package/dist/satellites/Orbitals.mjs +554 -0
- package/dist/satellites/Satellites.js +400 -0
- package/dist/satellites/Satellites.mjs +400 -0
- package/dist/satellites/layout.js +156 -0
- package/dist/satellites/layout.mjs +156 -0
- package/dist/satellites/measure.js +25 -0
- package/dist/satellites/measure.mjs +24 -0
- package/dist/satellites/orbits.js +139 -0
- package/dist/satellites/orbits.mjs +136 -0
- package/dist/satellites/types.d.mts +54 -0
- package/dist/satellites/types.d.ts +54 -0
- package/dist/satellites.d.mts +5 -0
- package/dist/satellites.d.ts +5 -0
- package/dist/satellites.js +14 -0
- package/dist/satellites.mjs +12 -0
- package/dist/store/store.d.mts +103 -0
- package/dist/store/store.d.ts +103 -0
- package/dist/store/store.js +52 -1
- package/dist/store/store.mjs +52 -2
- package/dist/styles.css +168 -7
- package/package.json +11 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// src/satellites/layout.ts
|
|
2
|
+
function planSatellites(input) {
|
|
3
|
+
const { viewport, host, placement, vertical, electrons, side, line, gap, offset, actions } = input;
|
|
4
|
+
const rtl = input.rtl && !vertical;
|
|
5
|
+
const sizes = new Map(electrons.map((electron) => [electron.id, electron]));
|
|
6
|
+
let actionsAcross = actions?.turn === "across";
|
|
7
|
+
const setActionsBox = () => {
|
|
8
|
+
if (!actions) return;
|
|
9
|
+
sizes.set("actions", actionsAcross ? {
|
|
10
|
+
width: actions.height,
|
|
11
|
+
height: actions.width
|
|
12
|
+
} : {
|
|
13
|
+
width: actions.width,
|
|
14
|
+
height: actions.height
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
setActionsBox();
|
|
18
|
+
const len = (box) => vertical ? box.height : box.width;
|
|
19
|
+
const mainLength = vertical ? viewport.height : viewport.width;
|
|
20
|
+
const available = mainLength - offset * 2;
|
|
21
|
+
const sides = {
|
|
22
|
+
before: [],
|
|
23
|
+
after: [],
|
|
24
|
+
beside: []
|
|
25
|
+
};
|
|
26
|
+
const stacked = [];
|
|
27
|
+
electrons.forEach((electron, index) => {
|
|
28
|
+
if (line === "across" && index > 0) stacked.push(electron.id);
|
|
29
|
+
else sides[side].push(electron.id);
|
|
30
|
+
});
|
|
31
|
+
const actionsSide = actions ? {
|
|
32
|
+
start: "before",
|
|
33
|
+
end: "after",
|
|
34
|
+
beside: "beside"
|
|
35
|
+
}[actions.side] : void 0;
|
|
36
|
+
if (actionsSide) sides[actionsSide].push("actions");
|
|
37
|
+
const lengthOf = (ids) => ids.reduce((sum, id) => sum + len(sizes.get(id)) + gap, 0);
|
|
38
|
+
const rowLength = () => lengthOf(sides.before) + len(host) + lengthOf(sides.after);
|
|
39
|
+
const leastRowLength = () => lengthOf(sides.before) + Math.min(len(host), input.hostMin ?? 1e400) + lengthOf(sides.after);
|
|
40
|
+
if (leastRowLength() > available && actions?.turn === "auto" && actionsSide !== "beside") {
|
|
41
|
+
actionsAcross = true;
|
|
42
|
+
setActionsBox();
|
|
43
|
+
}
|
|
44
|
+
const movedBeside = [];
|
|
45
|
+
const [firstElectron, ...otherElectrons] = electrons.map((electron) => electron.id);
|
|
46
|
+
const order = [
|
|
47
|
+
...otherElectrons.reverse(),
|
|
48
|
+
...actions ? ["actions"] : [],
|
|
49
|
+
...firstElectron ? [firstElectron] : []
|
|
50
|
+
];
|
|
51
|
+
for (const id of order) {
|
|
52
|
+
if (leastRowLength() <= available) break;
|
|
53
|
+
for (const from of ["after", "before"]) {
|
|
54
|
+
if (!sides[from].includes(id)) continue;
|
|
55
|
+
sides[from] = sides[from].filter((other) => other !== id);
|
|
56
|
+
sides.beside.push(id);
|
|
57
|
+
movedBeside.push(id);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (actions?.turn === "auto" && sides.beside.includes("actions") && actionsAcross) {
|
|
61
|
+
actionsAcross = false;
|
|
62
|
+
setActionsBox();
|
|
63
|
+
}
|
|
64
|
+
const align = vertical ? "center" : placement.endsWith("-start") ? "start" : placement.endsWith("-end") ? "end" : "center";
|
|
65
|
+
const hostStartOnItsOwn = vertical ? host.top : rtl ? viewport.width - host.left - host.width : host.left;
|
|
66
|
+
const at = {};
|
|
67
|
+
const gather = () => {
|
|
68
|
+
const total = rowLength();
|
|
69
|
+
let cursor = align === "start" ? offset : align === "end" ? mainLength - offset - total : mainLength / 2 - total / 2;
|
|
70
|
+
for (const id of [...sides.before].reverse()) {
|
|
71
|
+
at[id] = cursor;
|
|
72
|
+
cursor += len(sizes.get(id)) + gap;
|
|
73
|
+
}
|
|
74
|
+
at.host = cursor;
|
|
75
|
+
cursor += len(host) + gap;
|
|
76
|
+
for (const id of sides.after) {
|
|
77
|
+
at[id] = cursor;
|
|
78
|
+
cursor += len(sizes.get(id)) + gap;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const spread = () => {
|
|
82
|
+
const hostStart = align === "start" ? offset + lengthOf(sides.before) : align === "end" ? mainLength - offset - lengthOf(sides.after) - len(host) : mainLength / 2 - len(host) / 2;
|
|
83
|
+
const roomBefore = hostStart - offset - lengthOf(sides.before);
|
|
84
|
+
const roomAfter = mainLength - offset - (hostStart + len(host)) - lengthOf(sides.after);
|
|
85
|
+
if (roomBefore < 0 || roomAfter < 0) return false;
|
|
86
|
+
at.host = hostStart;
|
|
87
|
+
let cursor = offset;
|
|
88
|
+
for (const id of [...sides.before].reverse()) {
|
|
89
|
+
at[id] = cursor;
|
|
90
|
+
cursor += len(sizes.get(id)) + gap;
|
|
91
|
+
}
|
|
92
|
+
cursor = mainLength - offset;
|
|
93
|
+
for (const id of [...sides.after].reverse()) {
|
|
94
|
+
cursor -= len(sizes.get(id));
|
|
95
|
+
at[id] = cursor;
|
|
96
|
+
cursor -= gap;
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
};
|
|
100
|
+
if (input.arrange !== "spread" || !spread()) gather();
|
|
101
|
+
const hostStart = at.host;
|
|
102
|
+
let cursor = hostStart + len(host);
|
|
103
|
+
let fromStart = hostStart;
|
|
104
|
+
for (const id of sides.beside) {
|
|
105
|
+
if (id === "actions") {
|
|
106
|
+
at[id] = fromStart;
|
|
107
|
+
fromStart += len(sizes.get(id)) + gap;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
cursor -= len(sizes.get(id));
|
|
111
|
+
at[id] = cursor;
|
|
112
|
+
cursor -= gap;
|
|
113
|
+
}
|
|
114
|
+
const towardsPage = placement.startsWith("bottom") || placement === "right" ? -1 : 1;
|
|
115
|
+
const boxes = {};
|
|
116
|
+
const toBox = (id, mainStart, crossStart) => {
|
|
117
|
+
const { width, height } = sizes.get(id);
|
|
118
|
+
if (vertical) return {
|
|
119
|
+
left: crossStart,
|
|
120
|
+
top: mainStart,
|
|
121
|
+
width,
|
|
122
|
+
height
|
|
123
|
+
};
|
|
124
|
+
return {
|
|
125
|
+
left: rtl ? viewport.width - mainStart - width : mainStart,
|
|
126
|
+
top: crossStart,
|
|
127
|
+
width,
|
|
128
|
+
height
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
const hostCross = vertical ? host.left : host.top;
|
|
132
|
+
const hostThick = vertical ? host.width : host.height;
|
|
133
|
+
const onEdge = (thick) => towardsPage < 0 ? hostCross + hostThick - thick : hostCross;
|
|
134
|
+
const rowIn = (thick, from, fromThick) => towardsPage < 0 ? from - gap - thick : from + fromThick + gap;
|
|
135
|
+
const thickOf = (id) => vertical ? sizes.get(id).width : sizes.get(id).height;
|
|
136
|
+
for (const id of [...sides.before, ...sides.after]) boxes[id] = toBox(id, at[id], onEdge(thickOf(id)));
|
|
137
|
+
for (const id of sides.beside) boxes[id] = toBox(id, at[id], rowIn(thickOf(id), hostCross, hostThick));
|
|
138
|
+
let previous = electrons[0]?.id;
|
|
139
|
+
for (const id of stacked) {
|
|
140
|
+
const base = boxes[previous];
|
|
141
|
+
const baseCross = vertical ? base.left : base.top;
|
|
142
|
+
const baseThick = vertical ? base.width : base.height;
|
|
143
|
+
boxes[id] = toBox(id, vertical ? base.top : rtl ? viewport.width - base.left - base.width : base.left, rowIn(thickOf(id), baseCross, baseThick));
|
|
144
|
+
previous = id;
|
|
145
|
+
}
|
|
146
|
+
const shiftAlong = hostStart - hostStartOnItsOwn;
|
|
147
|
+
return {
|
|
148
|
+
shift: rtl ? -shiftAlong : shiftAlong,
|
|
149
|
+
reserve: vertical ? 0 : lengthOf(sides.before) + lengthOf(sides.after),
|
|
150
|
+
boxes,
|
|
151
|
+
movedBeside,
|
|
152
|
+
actionsAcross
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { planSatellites };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const require_timing = require("../utils/timing.js");
|
|
2
|
+
|
|
3
|
+
// src/satellites/measure.ts
|
|
4
|
+
/** "1.5rem", "24px", "0.875em" → px; anything else → the fallback. */
|
|
5
|
+
function toPixels(value, element, fallback) {
|
|
6
|
+
const match = /^\s*(-?[\d.]+)(px|rem|em)?\s*$/.exec(value);
|
|
7
|
+
if (!match) return fallback;
|
|
8
|
+
const amount = Number.parseFloat(match[1]);
|
|
9
|
+
if (match[2] === "rem") return amount * (Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16);
|
|
10
|
+
if (match[2] === "em") return amount * (Number.parseFloat(getComputedStyle(element).fontSize) || 16);
|
|
11
|
+
return amount;
|
|
12
|
+
}
|
|
13
|
+
/** A pill's timings, as the stylesheet sets them for it. */
|
|
14
|
+
function durations(element) {
|
|
15
|
+
const style = getComputedStyle(element);
|
|
16
|
+
return {
|
|
17
|
+
enter: require_timing.parseDuration(style.getPropertyValue("--_mp-enter"), 500),
|
|
18
|
+
exit: require_timing.parseDuration(style.getPropertyValue("--_mp-exit"), 300),
|
|
19
|
+
fade: require_timing.parseDuration(style.getPropertyValue("--_mp-fade"), 150),
|
|
20
|
+
change: require_timing.parseDuration(style.getPropertyValue("--_mp-change"), 250)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.durations = durations;
|
|
25
|
+
exports.toPixels = toPixels;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { parseDuration } from "../utils/timing.mjs";
|
|
2
|
+
|
|
3
|
+
// src/satellites/measure.ts
|
|
4
|
+
/** "1.5rem", "24px", "0.875em" → px; anything else → the fallback. */
|
|
5
|
+
function toPixels(value, element, fallback) {
|
|
6
|
+
const match = /^\s*(-?[\d.]+)(px|rem|em)?\s*$/.exec(value);
|
|
7
|
+
if (!match) return fallback;
|
|
8
|
+
const amount = Number.parseFloat(match[1]);
|
|
9
|
+
if (match[2] === "rem") return amount * (Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16);
|
|
10
|
+
if (match[2] === "em") return amount * (Number.parseFloat(getComputedStyle(element).fontSize) || 16);
|
|
11
|
+
return amount;
|
|
12
|
+
}
|
|
13
|
+
/** A pill's timings, as the stylesheet sets them for it. */
|
|
14
|
+
function durations(element) {
|
|
15
|
+
const style = getComputedStyle(element);
|
|
16
|
+
return {
|
|
17
|
+
enter: parseDuration(style.getPropertyValue("--_mp-enter"), 500),
|
|
18
|
+
exit: parseDuration(style.getPropertyValue("--_mp-exit"), 300),
|
|
19
|
+
fade: parseDuration(style.getPropertyValue("--_mp-fade"), 150),
|
|
20
|
+
change: parseDuration(style.getPropertyValue("--_mp-change"), 250)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { durations, toPixels };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// src/satellites/orbits.ts
|
|
2
|
+
/** How far a wheel can turn: from 0 to this many orbitals. */
|
|
3
|
+
const wheelEnd = (orbit) => Math.max(0, orbit.count - orbit.visible);
|
|
4
|
+
/**
|
|
5
|
+
* Where orbital `index` is with the wheel turned by `turn` orbitals: on the
|
|
6
|
+
* arc's slots, fading out past either end (the next one peeks out at a
|
|
7
|
+
* fifth), mirrored in a right-to-left page (the first one on the right).
|
|
8
|
+
*/
|
|
9
|
+
function spotOn(orbit, index, turn = 0) {
|
|
10
|
+
const { count, visible } = orbit;
|
|
11
|
+
const slot = orbit.rtl ? count - 1 - index + turn - (count - visible) : index - turn;
|
|
12
|
+
const angle = orbit.first + slot * orbit.step;
|
|
13
|
+
const past = slot < 0 ? -slot : slot > visible - 1 ? slot - (visible - 1) : 0;
|
|
14
|
+
const peeks = slot < 0 ? orbit.peek.low : orbit.peek.high;
|
|
15
|
+
const shown = orbit.wheel ? Math.min(1, Math.max(0, 1 - past / (peeks ? 1.25 : 1))) : 1;
|
|
16
|
+
return {
|
|
17
|
+
x: orbit.x + Math.cos(radians(angle)) * orbit.radius,
|
|
18
|
+
y: orbit.y + Math.sin(radians(angle)) * orbit.radius,
|
|
19
|
+
angle,
|
|
20
|
+
shown
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const radians = (degrees) => degrees * Math.PI / 180;
|
|
24
|
+
function planOrbit(input) {
|
|
25
|
+
const { electron, count, size, distance, away, obstacles, viewport } = input;
|
|
26
|
+
const x = electron.left + electron.width / 2;
|
|
27
|
+
const y = electron.top + electron.height / 2;
|
|
28
|
+
const margin = 8;
|
|
29
|
+
const pad = size / 2 + 6;
|
|
30
|
+
const free = (px, py) => px >= size / 2 + margin && px <= viewport.width - size / 2 - margin && py >= size / 2 + margin && py <= viewport.height - size / 2 - margin && !obstacles.some((box) => Math.abs(px - (box.left + box.width / 2)) < box.width / 2 + pad && Math.abs(py - (box.top + box.height / 2)) < box.height / 2 + pad);
|
|
31
|
+
const at = (radius, angle) => ({
|
|
32
|
+
x: x + Math.cos(radians(angle)) * radius,
|
|
33
|
+
y: y + Math.sin(radians(angle)) * radius
|
|
34
|
+
});
|
|
35
|
+
const tightest = (radius) => 2 * Math.asin(Math.min(1, (size + 8) / (2 * radius))) * 180 / Math.PI;
|
|
36
|
+
const arcAt = (radius) => {
|
|
37
|
+
const ok = (offset) => {
|
|
38
|
+
const spot = at(radius, away + offset);
|
|
39
|
+
return free(spot.x, spot.y);
|
|
40
|
+
};
|
|
41
|
+
let seed = null;
|
|
42
|
+
for (let offset = 0; offset <= 180 && seed === null; offset++) if (ok(offset)) seed = offset;
|
|
43
|
+
else if (ok(-offset)) seed = -offset;
|
|
44
|
+
if (seed === null) return null;
|
|
45
|
+
let low = seed;
|
|
46
|
+
let high = seed;
|
|
47
|
+
while (low > -180 && ok(low - 1)) low--;
|
|
48
|
+
while (high < 180 && ok(high + 1)) high++;
|
|
49
|
+
return {
|
|
50
|
+
low,
|
|
51
|
+
high
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const place = (radius, step, first, visible, clear) => {
|
|
55
|
+
const wheel = count > visible;
|
|
56
|
+
const clearAt = (angle) => {
|
|
57
|
+
const spot = at(radius, angle);
|
|
58
|
+
return free(spot.x, spot.y);
|
|
59
|
+
};
|
|
60
|
+
const room = wheel && (visible + 1) * step < 360;
|
|
61
|
+
const peek = {
|
|
62
|
+
low: room && clearAt(first - step),
|
|
63
|
+
high: room && clearAt(first + visible * step)
|
|
64
|
+
};
|
|
65
|
+
const orbit = {
|
|
66
|
+
x,
|
|
67
|
+
y,
|
|
68
|
+
radius,
|
|
69
|
+
step,
|
|
70
|
+
first,
|
|
71
|
+
count,
|
|
72
|
+
visible,
|
|
73
|
+
wheel,
|
|
74
|
+
peek,
|
|
75
|
+
rtl: input.rtl,
|
|
76
|
+
spots: [],
|
|
77
|
+
clear
|
|
78
|
+
};
|
|
79
|
+
orbit.spots = Array.from({ length: count }, (_, index) => spotOn(orbit, index));
|
|
80
|
+
return orbit;
|
|
81
|
+
};
|
|
82
|
+
const base = electron.width / 2 + distance + size / 2;
|
|
83
|
+
const radii = [];
|
|
84
|
+
for (let radius = base; radius <= base + size * 1.25; radius += 4) radii.push(radius);
|
|
85
|
+
for (const wanted of input.spread > 0 ? [input.spread, 0] : [0]) for (const radius of radii) {
|
|
86
|
+
const arc = arcAt(radius);
|
|
87
|
+
if (!arc) continue;
|
|
88
|
+
const step = count > 1 ? Math.max(tightest(radius), wanted > 0 ? wanted / (count - 1) : tightest(radius) + 2) : 0;
|
|
89
|
+
const needed = step * (count - 1);
|
|
90
|
+
if (needed <= arc.high - arc.low) return place(radius, step, away + Math.min(Math.max(0, arc.low + needed / 2), arc.high - needed / 2) - needed / 2, count, true);
|
|
91
|
+
}
|
|
92
|
+
let best = null;
|
|
93
|
+
for (const radius of radii) {
|
|
94
|
+
const arc = arcAt(radius);
|
|
95
|
+
if (!arc) continue;
|
|
96
|
+
const step = tightest(radius) + 2;
|
|
97
|
+
const visible = Math.max(1, Math.min(count, Math.floor((arc.high - arc.low) / step) + 1));
|
|
98
|
+
if (!best || visible > best.visible) best = {
|
|
99
|
+
radius,
|
|
100
|
+
arc,
|
|
101
|
+
step,
|
|
102
|
+
visible
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (!best) {
|
|
106
|
+
const step = count > 1 ? tightest(base) + 2 : 0;
|
|
107
|
+
return place(base, step, away - step * (count - 1) / 2, count, false);
|
|
108
|
+
}
|
|
109
|
+
const width = best.step * (best.visible - 1);
|
|
110
|
+
const centre = Math.min(Math.max(0, best.arc.low + width / 2), best.arc.high - width / 2);
|
|
111
|
+
return place(best.radius, best.step, away + centre - width / 2, best.visible, true);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Which orbital a point is over, by its angle from the electron's centre: -1
|
|
115
|
+
* for none (or the middle). On a wheel turned by `turn`, only the ones that show.
|
|
116
|
+
*/
|
|
117
|
+
function orbitalAt(orbit, size, electronRadius, px, py, turn = 0) {
|
|
118
|
+
const dx = px - orbit.x;
|
|
119
|
+
const dy = py - orbit.y;
|
|
120
|
+
const distance = Math.hypot(dx, dy);
|
|
121
|
+
if (distance < electronRadius * .85 || distance > orbit.radius + size) return -1;
|
|
122
|
+
const angle = Math.atan2(dy, dx) * 180 / Math.PI;
|
|
123
|
+
let best = -1;
|
|
124
|
+
let bestGap = 1e400;
|
|
125
|
+
Array.from({ length: orbit.count }, (_, index) => spotOn(orbit, index, turn)).forEach((spot, index) => {
|
|
126
|
+
if (spot.shown < .5) return;
|
|
127
|
+
const gap = Math.abs((angle - spot.angle + 540) % 360 - 180);
|
|
128
|
+
if (gap < bestGap) {
|
|
129
|
+
bestGap = gap;
|
|
130
|
+
best = index;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
return bestGap <= Math.max(orbit.step / 2 + 8, 30) ? best : -1;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
exports.orbitalAt = orbitalAt;
|
|
137
|
+
exports.planOrbit = planOrbit;
|
|
138
|
+
exports.spotOn = spotOn;
|
|
139
|
+
exports.wheelEnd = wheelEnd;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// src/satellites/orbits.ts
|
|
2
|
+
/** How far a wheel can turn: from 0 to this many orbitals. */
|
|
3
|
+
const wheelEnd = (orbit) => Math.max(0, orbit.count - orbit.visible);
|
|
4
|
+
/**
|
|
5
|
+
* Where orbital `index` is with the wheel turned by `turn` orbitals: on the
|
|
6
|
+
* arc's slots, fading out past either end (the next one peeks out at a
|
|
7
|
+
* fifth), mirrored in a right-to-left page (the first one on the right).
|
|
8
|
+
*/
|
|
9
|
+
function spotOn(orbit, index, turn = 0) {
|
|
10
|
+
const { count, visible } = orbit;
|
|
11
|
+
const slot = orbit.rtl ? count - 1 - index + turn - (count - visible) : index - turn;
|
|
12
|
+
const angle = orbit.first + slot * orbit.step;
|
|
13
|
+
const past = slot < 0 ? -slot : slot > visible - 1 ? slot - (visible - 1) : 0;
|
|
14
|
+
const peeks = slot < 0 ? orbit.peek.low : orbit.peek.high;
|
|
15
|
+
const shown = orbit.wheel ? Math.min(1, Math.max(0, 1 - past / (peeks ? 1.25 : 1))) : 1;
|
|
16
|
+
return {
|
|
17
|
+
x: orbit.x + Math.cos(radians(angle)) * orbit.radius,
|
|
18
|
+
y: orbit.y + Math.sin(radians(angle)) * orbit.radius,
|
|
19
|
+
angle,
|
|
20
|
+
shown
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const radians = (degrees) => degrees * Math.PI / 180;
|
|
24
|
+
function planOrbit(input) {
|
|
25
|
+
const { electron, count, size, distance, away, obstacles, viewport } = input;
|
|
26
|
+
const x = electron.left + electron.width / 2;
|
|
27
|
+
const y = electron.top + electron.height / 2;
|
|
28
|
+
const margin = 8;
|
|
29
|
+
const pad = size / 2 + 6;
|
|
30
|
+
const free = (px, py) => px >= size / 2 + margin && px <= viewport.width - size / 2 - margin && py >= size / 2 + margin && py <= viewport.height - size / 2 - margin && !obstacles.some((box) => Math.abs(px - (box.left + box.width / 2)) < box.width / 2 + pad && Math.abs(py - (box.top + box.height / 2)) < box.height / 2 + pad);
|
|
31
|
+
const at = (radius, angle) => ({
|
|
32
|
+
x: x + Math.cos(radians(angle)) * radius,
|
|
33
|
+
y: y + Math.sin(radians(angle)) * radius
|
|
34
|
+
});
|
|
35
|
+
const tightest = (radius) => 2 * Math.asin(Math.min(1, (size + 8) / (2 * radius))) * 180 / Math.PI;
|
|
36
|
+
const arcAt = (radius) => {
|
|
37
|
+
const ok = (offset) => {
|
|
38
|
+
const spot = at(radius, away + offset);
|
|
39
|
+
return free(spot.x, spot.y);
|
|
40
|
+
};
|
|
41
|
+
let seed = null;
|
|
42
|
+
for (let offset = 0; offset <= 180 && seed === null; offset++) if (ok(offset)) seed = offset;
|
|
43
|
+
else if (ok(-offset)) seed = -offset;
|
|
44
|
+
if (seed === null) return null;
|
|
45
|
+
let low = seed;
|
|
46
|
+
let high = seed;
|
|
47
|
+
while (low > -180 && ok(low - 1)) low--;
|
|
48
|
+
while (high < 180 && ok(high + 1)) high++;
|
|
49
|
+
return {
|
|
50
|
+
low,
|
|
51
|
+
high
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const place = (radius, step, first, visible, clear) => {
|
|
55
|
+
const wheel = count > visible;
|
|
56
|
+
const clearAt = (angle) => {
|
|
57
|
+
const spot = at(radius, angle);
|
|
58
|
+
return free(spot.x, spot.y);
|
|
59
|
+
};
|
|
60
|
+
const room = wheel && (visible + 1) * step < 360;
|
|
61
|
+
const peek = {
|
|
62
|
+
low: room && clearAt(first - step),
|
|
63
|
+
high: room && clearAt(first + visible * step)
|
|
64
|
+
};
|
|
65
|
+
const orbit = {
|
|
66
|
+
x,
|
|
67
|
+
y,
|
|
68
|
+
radius,
|
|
69
|
+
step,
|
|
70
|
+
first,
|
|
71
|
+
count,
|
|
72
|
+
visible,
|
|
73
|
+
wheel,
|
|
74
|
+
peek,
|
|
75
|
+
rtl: input.rtl,
|
|
76
|
+
spots: [],
|
|
77
|
+
clear
|
|
78
|
+
};
|
|
79
|
+
orbit.spots = Array.from({ length: count }, (_, index) => spotOn(orbit, index));
|
|
80
|
+
return orbit;
|
|
81
|
+
};
|
|
82
|
+
const base = electron.width / 2 + distance + size / 2;
|
|
83
|
+
const radii = [];
|
|
84
|
+
for (let radius = base; radius <= base + size * 1.25; radius += 4) radii.push(radius);
|
|
85
|
+
for (const wanted of input.spread > 0 ? [input.spread, 0] : [0]) for (const radius of radii) {
|
|
86
|
+
const arc = arcAt(radius);
|
|
87
|
+
if (!arc) continue;
|
|
88
|
+
const step = count > 1 ? Math.max(tightest(radius), wanted > 0 ? wanted / (count - 1) : tightest(radius) + 2) : 0;
|
|
89
|
+
const needed = step * (count - 1);
|
|
90
|
+
if (needed <= arc.high - arc.low) return place(radius, step, away + Math.min(Math.max(0, arc.low + needed / 2), arc.high - needed / 2) - needed / 2, count, true);
|
|
91
|
+
}
|
|
92
|
+
let best = null;
|
|
93
|
+
for (const radius of radii) {
|
|
94
|
+
const arc = arcAt(radius);
|
|
95
|
+
if (!arc) continue;
|
|
96
|
+
const step = tightest(radius) + 2;
|
|
97
|
+
const visible = Math.max(1, Math.min(count, Math.floor((arc.high - arc.low) / step) + 1));
|
|
98
|
+
if (!best || visible > best.visible) best = {
|
|
99
|
+
radius,
|
|
100
|
+
arc,
|
|
101
|
+
step,
|
|
102
|
+
visible
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (!best) {
|
|
106
|
+
const step = count > 1 ? tightest(base) + 2 : 0;
|
|
107
|
+
return place(base, step, away - step * (count - 1) / 2, count, false);
|
|
108
|
+
}
|
|
109
|
+
const width = best.step * (best.visible - 1);
|
|
110
|
+
const centre = Math.min(Math.max(0, best.arc.low + width / 2), best.arc.high - width / 2);
|
|
111
|
+
return place(best.radius, best.step, away + centre - width / 2, best.visible, true);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Which orbital a point is over, by its angle from the electron's centre: -1
|
|
115
|
+
* for none (or the middle). On a wheel turned by `turn`, only the ones that show.
|
|
116
|
+
*/
|
|
117
|
+
function orbitalAt(orbit, size, electronRadius, px, py, turn = 0) {
|
|
118
|
+
const dx = px - orbit.x;
|
|
119
|
+
const dy = py - orbit.y;
|
|
120
|
+
const distance = Math.hypot(dx, dy);
|
|
121
|
+
if (distance < electronRadius * .85 || distance > orbit.radius + size) return -1;
|
|
122
|
+
const angle = Math.atan2(dy, dx) * 180 / Math.PI;
|
|
123
|
+
let best = -1;
|
|
124
|
+
let bestGap = 1e400;
|
|
125
|
+
Array.from({ length: orbit.count }, (_, index) => spotOn(orbit, index, turn)).forEach((spot, index) => {
|
|
126
|
+
if (spot.shown < .5) return;
|
|
127
|
+
const gap = Math.abs((angle - spot.angle + 540) % 360 - 180);
|
|
128
|
+
if (gap < bestGap) {
|
|
129
|
+
bestGap = gap;
|
|
130
|
+
best = index;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
return bestGap <= Math.max(orbit.step / 2 + 8, 30) ? best : -1;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export { orbitalAt, planOrbit, spotOn, wheelEnd };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ComponentType, RefObject } from "react";
|
|
2
|
+
import { LinkComponent, PillPlacement, PillTheme, PillVariant } from "../Pill/types.mjs";
|
|
3
|
+
import { PillStore } from "../store/store.mjs";
|
|
4
|
+
/** Where electrons go: further along the edge, before the pill, or one row towards the page. */
|
|
5
|
+
export type ElectronSide = "after" | "before" | "beside";
|
|
6
|
+
/** Several electrons line up along the pill, or stack across it. */
|
|
7
|
+
export type ElectronLine = "along" | "across";
|
|
8
|
+
/** The satellites gathered around the pill, or spread to the screen's edges. */
|
|
9
|
+
export type SatelliteArrangement = "gather" | "spread";
|
|
10
|
+
export type ElectronEnding = "join" | "pop";
|
|
11
|
+
/** Where the page's actions go: on the pill's start side, its end side, or beside it. */
|
|
12
|
+
export type ActionsSide = "start" | "end" | "beside";
|
|
13
|
+
/** The page's actions: a pill of their own, or in the pill after a divider. */
|
|
14
|
+
export type ActionsStyle = "detached" | "inside";
|
|
15
|
+
/** The page's actions run like the pill (turning across when room runs out: "auto"), or horizontal, or vertical. */
|
|
16
|
+
export type ActionsOrientation = "auto" | "horizontal" | "vertical";
|
|
17
|
+
/** What opens an electron's orbitals: a long press or hovering it with a mouse, a long press only, or a tap. */
|
|
18
|
+
export type OrbitalsOpenOn = "press-hover" | "press" | "tap";
|
|
19
|
+
/** The host, as its satellites see it. */
|
|
20
|
+
export interface SatelliteHost {
|
|
21
|
+
name: string;
|
|
22
|
+
store: PillStore;
|
|
23
|
+
rootRef: RefObject<HTMLElement | null>;
|
|
24
|
+
placement: PillPlacement;
|
|
25
|
+
vertical: boolean;
|
|
26
|
+
pathname?: string;
|
|
27
|
+
/** A notification has the pill, or it's on its way to or from one (the electrons tuck in, unless kept out) */
|
|
28
|
+
notifying: boolean;
|
|
29
|
+
linkComponent?: LinkComponent;
|
|
30
|
+
variant?: PillVariant;
|
|
31
|
+
theme?: PillTheme;
|
|
32
|
+
electronSide: ElectronSide;
|
|
33
|
+
electronLine: ElectronLine;
|
|
34
|
+
keepElectronsOut: boolean;
|
|
35
|
+
electronEnding: ElectronEnding;
|
|
36
|
+
arrange: SatelliteArrangement;
|
|
37
|
+
orbitalsOpenOn: OrbitalsOpenOn;
|
|
38
|
+
orbitalLabels: boolean;
|
|
39
|
+
orbitalsStayOpen: boolean;
|
|
40
|
+
actionsStyle: ActionsStyle;
|
|
41
|
+
actionsSide: ActionsSide;
|
|
42
|
+
actionsOrientation: ActionsOrientation;
|
|
43
|
+
actionsLabel: string;
|
|
44
|
+
}
|
|
45
|
+
/** `satellites` from `magic-pill/satellites`, passed to `<MagicPill satellites={satellites}>`. */
|
|
46
|
+
export interface PillSatellites {
|
|
47
|
+
Layer: ComponentType<{
|
|
48
|
+
host: SatelliteHost;
|
|
49
|
+
}>;
|
|
50
|
+
/** The page's actions in the pill itself, after a divider (`actionsStyle="inside"`) */
|
|
51
|
+
Inside: ComponentType<{
|
|
52
|
+
host: SatelliteHost;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ComponentType, RefObject } from "react";
|
|
2
|
+
import { LinkComponent, PillPlacement, PillTheme, PillVariant } from "../Pill/types.js";
|
|
3
|
+
import { PillStore } from "../store/store.js";
|
|
4
|
+
/** Where electrons go: further along the edge, before the pill, or one row towards the page. */
|
|
5
|
+
export type ElectronSide = "after" | "before" | "beside";
|
|
6
|
+
/** Several electrons line up along the pill, or stack across it. */
|
|
7
|
+
export type ElectronLine = "along" | "across";
|
|
8
|
+
/** The satellites gathered around the pill, or spread to the screen's edges. */
|
|
9
|
+
export type SatelliteArrangement = "gather" | "spread";
|
|
10
|
+
export type ElectronEnding = "join" | "pop";
|
|
11
|
+
/** Where the page's actions go: on the pill's start side, its end side, or beside it. */
|
|
12
|
+
export type ActionsSide = "start" | "end" | "beside";
|
|
13
|
+
/** The page's actions: a pill of their own, or in the pill after a divider. */
|
|
14
|
+
export type ActionsStyle = "detached" | "inside";
|
|
15
|
+
/** The page's actions run like the pill (turning across when room runs out: "auto"), or horizontal, or vertical. */
|
|
16
|
+
export type ActionsOrientation = "auto" | "horizontal" | "vertical";
|
|
17
|
+
/** What opens an electron's orbitals: a long press or hovering it with a mouse, a long press only, or a tap. */
|
|
18
|
+
export type OrbitalsOpenOn = "press-hover" | "press" | "tap";
|
|
19
|
+
/** The host, as its satellites see it. */
|
|
20
|
+
export interface SatelliteHost {
|
|
21
|
+
name: string;
|
|
22
|
+
store: PillStore;
|
|
23
|
+
rootRef: RefObject<HTMLElement | null>;
|
|
24
|
+
placement: PillPlacement;
|
|
25
|
+
vertical: boolean;
|
|
26
|
+
pathname?: string;
|
|
27
|
+
/** A notification has the pill, or it's on its way to or from one (the electrons tuck in, unless kept out) */
|
|
28
|
+
notifying: boolean;
|
|
29
|
+
linkComponent?: LinkComponent;
|
|
30
|
+
variant?: PillVariant;
|
|
31
|
+
theme?: PillTheme;
|
|
32
|
+
electronSide: ElectronSide;
|
|
33
|
+
electronLine: ElectronLine;
|
|
34
|
+
keepElectronsOut: boolean;
|
|
35
|
+
electronEnding: ElectronEnding;
|
|
36
|
+
arrange: SatelliteArrangement;
|
|
37
|
+
orbitalsOpenOn: OrbitalsOpenOn;
|
|
38
|
+
orbitalLabels: boolean;
|
|
39
|
+
orbitalsStayOpen: boolean;
|
|
40
|
+
actionsStyle: ActionsStyle;
|
|
41
|
+
actionsSide: ActionsSide;
|
|
42
|
+
actionsOrientation: ActionsOrientation;
|
|
43
|
+
actionsLabel: string;
|
|
44
|
+
}
|
|
45
|
+
/** `satellites` from `magic-pill/satellites`, passed to `<MagicPill satellites={satellites}>`. */
|
|
46
|
+
export interface PillSatellites {
|
|
47
|
+
Layer: ComponentType<{
|
|
48
|
+
host: SatelliteHost;
|
|
49
|
+
}>;
|
|
50
|
+
/** The page's actions in the pill itself, after a divider (`actionsStyle="inside"`) */
|
|
51
|
+
Inside: ComponentType<{
|
|
52
|
+
host: SatelliteHost;
|
|
53
|
+
}>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ActionsOrientation, ActionsSide, ActionsStyle, ElectronEnding, ElectronLine, ElectronSide, OrbitalsOpenOn, PillSatellites, SatelliteArrangement } from "./satellites/types.mjs";
|
|
2
|
+
import { usePillActions } from "./satellites/Actions.mjs";
|
|
3
|
+
import { Electron, ElectronOptions, Orbital, PillActionItem } from "./store/store.mjs";
|
|
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 Orbital, type OrbitalsOpenOn, type PillActionItem, type PillSatellites, type SatelliteArrangement, usePillActions };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ActionsOrientation, ActionsSide, ActionsStyle, ElectronEnding, ElectronLine, ElectronSide, OrbitalsOpenOn, PillSatellites, SatelliteArrangement } from "./satellites/types.js";
|
|
2
|
+
import { usePillActions } from "./satellites/Actions.js";
|
|
3
|
+
import { Electron, ElectronOptions, Orbital, PillActionItem } from "./store/store.js";
|
|
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 Orbital, type OrbitalsOpenOn, type PillActionItem, type PillSatellites, type SatelliteArrangement, usePillActions };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_Actions = require("./satellites/Actions.js");
|
|
5
|
+
const require_Satellites = require("./satellites/Satellites.js");
|
|
6
|
+
|
|
7
|
+
// src/satellites/index.ts
|
|
8
|
+
const satellites = {
|
|
9
|
+
Layer: require_Satellites.SatellitesLayer,
|
|
10
|
+
Inside: require_Actions.InsideActions
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
exports.satellites = satellites;
|
|
14
|
+
exports.usePillActions = require_Actions.usePillActions;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { InsideActions, usePillActions } from "./satellites/Actions.mjs";
|
|
4
|
+
import { SatellitesLayer } from "./satellites/Satellites.mjs";
|
|
5
|
+
|
|
6
|
+
// src/satellites/index.ts
|
|
7
|
+
const satellites = {
|
|
8
|
+
Layer: SatellitesLayer,
|
|
9
|
+
Inside: InsideActions
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { satellites, usePillActions };
|