magic-pill 9.3.0 → 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/CHANGELOG.md +29 -0
- package/README.md +114 -3
- package/dist/MagicPill/MagicPill.d.mts +51 -1
- package/dist/MagicPill/MagicPill.d.ts +51 -1
- package/dist/MagicPill/MagicPill.js +53 -4
- package/dist/MagicPill/MagicPill.mjs +55 -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 +576 -0
- package/dist/Pill/goo.mjs +566 -0
- package/dist/Pill/morph.js +11 -4
- package/dist/Pill/morph.mjs +10 -5
- 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 +181 -0
- package/dist/satellites/Actions.mjs +177 -0
- package/dist/satellites/Orbitals.js +585 -0
- package/dist/satellites/Orbitals.mjs +585 -0
- package/dist/satellites/Satellites.js +634 -0
- package/dist/satellites/Satellites.mjs +634 -0
- package/dist/satellites/layout.js +209 -0
- package/dist/satellites/layout.mjs +209 -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 +58 -0
- package/dist/satellites/types.d.ts +58 -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 +322 -8
- package/package.json +11 -1
|
@@ -0,0 +1,209 @@
|
|
|
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
|
+
const len = (box) => vertical ? box.height : box.width;
|
|
7
|
+
const mainLength = vertical ? viewport.height : viewport.width;
|
|
8
|
+
const available = mainLength - offset * 2;
|
|
9
|
+
let actionsAcross = actions?.turn === "across";
|
|
10
|
+
let actionsShown;
|
|
11
|
+
const wheel = actions?.wheel && actions.wheel.count > 1 && !actionsAcross ? actions.wheel : void 0;
|
|
12
|
+
const setActionsBox = () => {
|
|
13
|
+
if (!actions) return;
|
|
14
|
+
const along = {
|
|
15
|
+
width: actions.width,
|
|
16
|
+
height: actions.height
|
|
17
|
+
};
|
|
18
|
+
if (actionsShown !== void 0 && wheel) {
|
|
19
|
+
const length = wheel.first + (actionsShown - 1) * wheel.step;
|
|
20
|
+
if (vertical) along.height = length;
|
|
21
|
+
else along.width = length;
|
|
22
|
+
}
|
|
23
|
+
sizes.set("actions", actionsAcross ? {
|
|
24
|
+
width: along.height,
|
|
25
|
+
height: along.width
|
|
26
|
+
} : along);
|
|
27
|
+
};
|
|
28
|
+
setActionsBox();
|
|
29
|
+
/** With a wheel, as many as a length holds (0: not even one) */
|
|
30
|
+
const fitting = (length) => !wheel || length < wheel.first ? 0 : Math.min(wheel.count, 1 + Math.floor((length - wheel.first) / wheel.step));
|
|
31
|
+
/** Cut the actions short by `over` px, keeping at least `least` of them: whether it did */
|
|
32
|
+
const cutShort = (over, least) => {
|
|
33
|
+
if (!wheel || !actions) return false;
|
|
34
|
+
const fit = fitting(len(actions) - over);
|
|
35
|
+
if (fit < least || fit >= wheel.count) return false;
|
|
36
|
+
actionsShown = fit;
|
|
37
|
+
setActionsBox();
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
const sides = {
|
|
41
|
+
before: [],
|
|
42
|
+
after: [],
|
|
43
|
+
beside: []
|
|
44
|
+
};
|
|
45
|
+
const stacked = [];
|
|
46
|
+
electrons.forEach((electron, index) => {
|
|
47
|
+
if (line === "across" && index > 0) stacked.push(electron.id);
|
|
48
|
+
else sides[side].push(electron.id);
|
|
49
|
+
});
|
|
50
|
+
const actionsSide = actions ? {
|
|
51
|
+
start: "before",
|
|
52
|
+
end: "after",
|
|
53
|
+
beside: "beside"
|
|
54
|
+
}[actions.side] : void 0;
|
|
55
|
+
const actionsNearer = input.nearest === "actions";
|
|
56
|
+
if (actionsSide) {
|
|
57
|
+
if (actionsNearer && actionsSide !== "beside") sides[actionsSide].unshift("actions");
|
|
58
|
+
else sides[actionsSide].push("actions");
|
|
59
|
+
}
|
|
60
|
+
const lengthOf = (ids) => ids.reduce((sum, id) => sum + len(sizes.get(id)) + gap, 0);
|
|
61
|
+
const rowLength = () => lengthOf(sides.before) + len(host) + lengthOf(sides.after);
|
|
62
|
+
const leastRowLength = () => lengthOf(sides.before) + Math.min(len(host), input.hostMin ?? 1e400) + lengthOf(sides.after);
|
|
63
|
+
if (leastRowLength() > available && actionsSide && actionsSide !== "beside") {
|
|
64
|
+
if (!cutShort(leastRowLength() - available, Math.min(2, wheel?.count ?? 0)) && actions?.turn === "auto" && !wheel) {
|
|
65
|
+
actionsAcross = true;
|
|
66
|
+
setActionsBox();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const movedBeside = [];
|
|
70
|
+
const [firstElectron, ...otherElectrons] = electrons.map((electron) => electron.id);
|
|
71
|
+
const order = [...otherElectrons.reverse()];
|
|
72
|
+
if (actionsNearer) order.push(...firstElectron ? [firstElectron] : [], ...actions ? ["actions"] : []);
|
|
73
|
+
else order.push(...actions ? ["actions"] : [], ...firstElectron ? [firstElectron] : []);
|
|
74
|
+
for (const id of order) {
|
|
75
|
+
if (leastRowLength() <= available) break;
|
|
76
|
+
for (const from of ["after", "before"]) {
|
|
77
|
+
if (!sides[from].includes(id)) continue;
|
|
78
|
+
sides[from] = sides[from].filter((other) => other !== id);
|
|
79
|
+
sides.beside.push(id);
|
|
80
|
+
movedBeside.push(id);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const besideRow = () => [...sides.beside.includes("actions") ? ["actions"] : [], ...sides.beside.filter((id) => id !== "actions").reverse()];
|
|
84
|
+
const lengthOfRow = (ids) => Math.max(0, lengthOf(ids) - gap);
|
|
85
|
+
if (actions && sides.beside.includes("actions")) {
|
|
86
|
+
actionsShown = void 0;
|
|
87
|
+
actionsAcross = actions.turn === "across";
|
|
88
|
+
setActionsBox();
|
|
89
|
+
const over = lengthOfRow(besideRow()) - available;
|
|
90
|
+
if (over > 0 && !cutShort(over, 1) && actions.turn === "auto" && !wheel) {
|
|
91
|
+
actionsAcross = true;
|
|
92
|
+
setActionsBox();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const align = vertical ? "center" : placement.endsWith("-start") ? "start" : placement.endsWith("-end") ? "end" : "center";
|
|
96
|
+
const hostStartOnItsOwn = vertical ? host.top : rtl ? viewport.width - host.left - host.width : host.left;
|
|
97
|
+
const at = {};
|
|
98
|
+
const gather = () => {
|
|
99
|
+
const total = rowLength();
|
|
100
|
+
let cursor = align === "start" ? offset : align === "end" ? mainLength - offset - total : mainLength / 2 - total / 2;
|
|
101
|
+
for (const id of [...sides.before].reverse()) {
|
|
102
|
+
at[id] = cursor;
|
|
103
|
+
cursor += len(sizes.get(id)) + gap;
|
|
104
|
+
}
|
|
105
|
+
at.host = cursor;
|
|
106
|
+
cursor += len(host) + gap;
|
|
107
|
+
for (const id of sides.after) {
|
|
108
|
+
at[id] = cursor;
|
|
109
|
+
cursor += len(sizes.get(id)) + gap;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const spread = () => {
|
|
113
|
+
const hostStart = align === "start" ? offset + lengthOf(sides.before) : align === "end" ? mainLength - offset - lengthOf(sides.after) - len(host) : mainLength / 2 - len(host) / 2;
|
|
114
|
+
const roomBefore = hostStart - offset - lengthOf(sides.before);
|
|
115
|
+
const roomAfter = mainLength - offset - (hostStart + len(host)) - lengthOf(sides.after);
|
|
116
|
+
if (roomBefore < 0 || roomAfter < 0) return false;
|
|
117
|
+
at.host = hostStart;
|
|
118
|
+
let cursor = offset;
|
|
119
|
+
for (const id of [...sides.before].reverse()) {
|
|
120
|
+
at[id] = cursor;
|
|
121
|
+
cursor += len(sizes.get(id)) + gap;
|
|
122
|
+
}
|
|
123
|
+
cursor = mainLength - offset;
|
|
124
|
+
for (const id of [...sides.after].reverse()) {
|
|
125
|
+
cursor -= len(sizes.get(id));
|
|
126
|
+
at[id] = cursor;
|
|
127
|
+
cursor -= gap;
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
};
|
|
131
|
+
if (input.arrange !== "spread" || !spread()) gather();
|
|
132
|
+
const hostStart = at.host;
|
|
133
|
+
const hostEnd = hostStart + len(host);
|
|
134
|
+
const besideRows = [];
|
|
135
|
+
for (const id of besideRow()) {
|
|
136
|
+
const current = besideRows[besideRows.length - 1];
|
|
137
|
+
if (current && lengthOfRow([...current, id]) <= available) current.push(id);
|
|
138
|
+
else besideRows.push([id]);
|
|
139
|
+
}
|
|
140
|
+
for (const row of besideRows) {
|
|
141
|
+
const total = lengthOfRow(row);
|
|
142
|
+
if (total <= len(host)) {
|
|
143
|
+
let fromEnd = hostEnd;
|
|
144
|
+
for (const id of [...row].reverse()) {
|
|
145
|
+
if (id === "actions") continue;
|
|
146
|
+
fromEnd -= len(sizes.get(id));
|
|
147
|
+
at[id] = fromEnd;
|
|
148
|
+
fromEnd -= gap;
|
|
149
|
+
}
|
|
150
|
+
if (row.includes("actions")) at.actions = hostStart;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
let cursor = Math.max(offset, Math.min(hostStart, mainLength - offset - total));
|
|
154
|
+
for (const id of row) {
|
|
155
|
+
at[id] = cursor;
|
|
156
|
+
cursor += len(sizes.get(id)) + gap;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const towardsPage = placement.startsWith("bottom") || placement === "right" ? -1 : 1;
|
|
160
|
+
const boxes = {};
|
|
161
|
+
const toBox = (id, mainStart, crossStart) => {
|
|
162
|
+
const { width, height } = sizes.get(id);
|
|
163
|
+
if (vertical) return {
|
|
164
|
+
left: crossStart,
|
|
165
|
+
top: mainStart,
|
|
166
|
+
width,
|
|
167
|
+
height
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
left: rtl ? viewport.width - mainStart - width : mainStart,
|
|
171
|
+
top: crossStart,
|
|
172
|
+
width,
|
|
173
|
+
height
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
const hostCross = vertical ? host.left : host.top;
|
|
177
|
+
const hostThick = vertical ? host.width : host.height;
|
|
178
|
+
const onEdge = (thick) => towardsPage < 0 ? hostCross + hostThick - thick : hostCross;
|
|
179
|
+
const rowIn = (thick, from, fromThick) => towardsPage < 0 ? from - gap - thick : from + fromThick + gap;
|
|
180
|
+
const thickOf = (id) => vertical ? sizes.get(id).width : sizes.get(id).height;
|
|
181
|
+
for (const id of [...sides.before, ...sides.after]) boxes[id] = toBox(id, at[id], onEdge(thickOf(id)));
|
|
182
|
+
let rowFrom = hostCross;
|
|
183
|
+
let rowThick = hostThick;
|
|
184
|
+
for (const row of besideRows) {
|
|
185
|
+
for (const id of row) boxes[id] = toBox(id, at[id], rowIn(thickOf(id), rowFrom, rowThick));
|
|
186
|
+
const thickest = Math.max(...row.map(thickOf));
|
|
187
|
+
rowFrom = towardsPage < 0 ? rowFrom - gap - thickest : rowFrom + rowThick + gap;
|
|
188
|
+
rowThick = thickest;
|
|
189
|
+
}
|
|
190
|
+
let previous = electrons[0]?.id;
|
|
191
|
+
for (const id of stacked) {
|
|
192
|
+
const base = boxes[previous];
|
|
193
|
+
const baseCross = vertical ? base.left : base.top;
|
|
194
|
+
const baseThick = vertical ? base.width : base.height;
|
|
195
|
+
boxes[id] = toBox(id, vertical ? base.top : rtl ? viewport.width - base.left - base.width : base.left, rowIn(thickOf(id), baseCross, baseThick));
|
|
196
|
+
previous = id;
|
|
197
|
+
}
|
|
198
|
+
const shiftAlong = hostStart - hostStartOnItsOwn;
|
|
199
|
+
return {
|
|
200
|
+
shift: rtl ? -shiftAlong : shiftAlong,
|
|
201
|
+
reserve: vertical ? 0 : lengthOf(sides.before) + lengthOf(sides.after),
|
|
202
|
+
boxes,
|
|
203
|
+
movedBeside,
|
|
204
|
+
actionsAcross,
|
|
205
|
+
...actionsShown !== void 0 ? { actionsShown } : {}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
exports.planSatellites = planSatellites;
|
|
@@ -0,0 +1,209 @@
|
|
|
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
|
+
const len = (box) => vertical ? box.height : box.width;
|
|
7
|
+
const mainLength = vertical ? viewport.height : viewport.width;
|
|
8
|
+
const available = mainLength - offset * 2;
|
|
9
|
+
let actionsAcross = actions?.turn === "across";
|
|
10
|
+
let actionsShown;
|
|
11
|
+
const wheel = actions?.wheel && actions.wheel.count > 1 && !actionsAcross ? actions.wheel : void 0;
|
|
12
|
+
const setActionsBox = () => {
|
|
13
|
+
if (!actions) return;
|
|
14
|
+
const along = {
|
|
15
|
+
width: actions.width,
|
|
16
|
+
height: actions.height
|
|
17
|
+
};
|
|
18
|
+
if (actionsShown !== void 0 && wheel) {
|
|
19
|
+
const length = wheel.first + (actionsShown - 1) * wheel.step;
|
|
20
|
+
if (vertical) along.height = length;
|
|
21
|
+
else along.width = length;
|
|
22
|
+
}
|
|
23
|
+
sizes.set("actions", actionsAcross ? {
|
|
24
|
+
width: along.height,
|
|
25
|
+
height: along.width
|
|
26
|
+
} : along);
|
|
27
|
+
};
|
|
28
|
+
setActionsBox();
|
|
29
|
+
/** With a wheel, as many as a length holds (0: not even one) */
|
|
30
|
+
const fitting = (length) => !wheel || length < wheel.first ? 0 : Math.min(wheel.count, 1 + Math.floor((length - wheel.first) / wheel.step));
|
|
31
|
+
/** Cut the actions short by `over` px, keeping at least `least` of them: whether it did */
|
|
32
|
+
const cutShort = (over, least) => {
|
|
33
|
+
if (!wheel || !actions) return false;
|
|
34
|
+
const fit = fitting(len(actions) - over);
|
|
35
|
+
if (fit < least || fit >= wheel.count) return false;
|
|
36
|
+
actionsShown = fit;
|
|
37
|
+
setActionsBox();
|
|
38
|
+
return true;
|
|
39
|
+
};
|
|
40
|
+
const sides = {
|
|
41
|
+
before: [],
|
|
42
|
+
after: [],
|
|
43
|
+
beside: []
|
|
44
|
+
};
|
|
45
|
+
const stacked = [];
|
|
46
|
+
electrons.forEach((electron, index) => {
|
|
47
|
+
if (line === "across" && index > 0) stacked.push(electron.id);
|
|
48
|
+
else sides[side].push(electron.id);
|
|
49
|
+
});
|
|
50
|
+
const actionsSide = actions ? {
|
|
51
|
+
start: "before",
|
|
52
|
+
end: "after",
|
|
53
|
+
beside: "beside"
|
|
54
|
+
}[actions.side] : void 0;
|
|
55
|
+
const actionsNearer = input.nearest === "actions";
|
|
56
|
+
if (actionsSide) {
|
|
57
|
+
if (actionsNearer && actionsSide !== "beside") sides[actionsSide].unshift("actions");
|
|
58
|
+
else sides[actionsSide].push("actions");
|
|
59
|
+
}
|
|
60
|
+
const lengthOf = (ids) => ids.reduce((sum, id) => sum + len(sizes.get(id)) + gap, 0);
|
|
61
|
+
const rowLength = () => lengthOf(sides.before) + len(host) + lengthOf(sides.after);
|
|
62
|
+
const leastRowLength = () => lengthOf(sides.before) + Math.min(len(host), input.hostMin ?? 1e400) + lengthOf(sides.after);
|
|
63
|
+
if (leastRowLength() > available && actionsSide && actionsSide !== "beside") {
|
|
64
|
+
if (!cutShort(leastRowLength() - available, Math.min(2, wheel?.count ?? 0)) && actions?.turn === "auto" && !wheel) {
|
|
65
|
+
actionsAcross = true;
|
|
66
|
+
setActionsBox();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const movedBeside = [];
|
|
70
|
+
const [firstElectron, ...otherElectrons] = electrons.map((electron) => electron.id);
|
|
71
|
+
const order = [...otherElectrons.reverse()];
|
|
72
|
+
if (actionsNearer) order.push(...firstElectron ? [firstElectron] : [], ...actions ? ["actions"] : []);
|
|
73
|
+
else order.push(...actions ? ["actions"] : [], ...firstElectron ? [firstElectron] : []);
|
|
74
|
+
for (const id of order) {
|
|
75
|
+
if (leastRowLength() <= available) break;
|
|
76
|
+
for (const from of ["after", "before"]) {
|
|
77
|
+
if (!sides[from].includes(id)) continue;
|
|
78
|
+
sides[from] = sides[from].filter((other) => other !== id);
|
|
79
|
+
sides.beside.push(id);
|
|
80
|
+
movedBeside.push(id);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const besideRow = () => [...sides.beside.includes("actions") ? ["actions"] : [], ...sides.beside.filter((id) => id !== "actions").reverse()];
|
|
84
|
+
const lengthOfRow = (ids) => Math.max(0, lengthOf(ids) - gap);
|
|
85
|
+
if (actions && sides.beside.includes("actions")) {
|
|
86
|
+
actionsShown = void 0;
|
|
87
|
+
actionsAcross = actions.turn === "across";
|
|
88
|
+
setActionsBox();
|
|
89
|
+
const over = lengthOfRow(besideRow()) - available;
|
|
90
|
+
if (over > 0 && !cutShort(over, 1) && actions.turn === "auto" && !wheel) {
|
|
91
|
+
actionsAcross = true;
|
|
92
|
+
setActionsBox();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const align = vertical ? "center" : placement.endsWith("-start") ? "start" : placement.endsWith("-end") ? "end" : "center";
|
|
96
|
+
const hostStartOnItsOwn = vertical ? host.top : rtl ? viewport.width - host.left - host.width : host.left;
|
|
97
|
+
const at = {};
|
|
98
|
+
const gather = () => {
|
|
99
|
+
const total = rowLength();
|
|
100
|
+
let cursor = align === "start" ? offset : align === "end" ? mainLength - offset - total : mainLength / 2 - total / 2;
|
|
101
|
+
for (const id of [...sides.before].reverse()) {
|
|
102
|
+
at[id] = cursor;
|
|
103
|
+
cursor += len(sizes.get(id)) + gap;
|
|
104
|
+
}
|
|
105
|
+
at.host = cursor;
|
|
106
|
+
cursor += len(host) + gap;
|
|
107
|
+
for (const id of sides.after) {
|
|
108
|
+
at[id] = cursor;
|
|
109
|
+
cursor += len(sizes.get(id)) + gap;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const spread = () => {
|
|
113
|
+
const hostStart = align === "start" ? offset + lengthOf(sides.before) : align === "end" ? mainLength - offset - lengthOf(sides.after) - len(host) : mainLength / 2 - len(host) / 2;
|
|
114
|
+
const roomBefore = hostStart - offset - lengthOf(sides.before);
|
|
115
|
+
const roomAfter = mainLength - offset - (hostStart + len(host)) - lengthOf(sides.after);
|
|
116
|
+
if (roomBefore < 0 || roomAfter < 0) return false;
|
|
117
|
+
at.host = hostStart;
|
|
118
|
+
let cursor = offset;
|
|
119
|
+
for (const id of [...sides.before].reverse()) {
|
|
120
|
+
at[id] = cursor;
|
|
121
|
+
cursor += len(sizes.get(id)) + gap;
|
|
122
|
+
}
|
|
123
|
+
cursor = mainLength - offset;
|
|
124
|
+
for (const id of [...sides.after].reverse()) {
|
|
125
|
+
cursor -= len(sizes.get(id));
|
|
126
|
+
at[id] = cursor;
|
|
127
|
+
cursor -= gap;
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
};
|
|
131
|
+
if (input.arrange !== "spread" || !spread()) gather();
|
|
132
|
+
const hostStart = at.host;
|
|
133
|
+
const hostEnd = hostStart + len(host);
|
|
134
|
+
const besideRows = [];
|
|
135
|
+
for (const id of besideRow()) {
|
|
136
|
+
const current = besideRows[besideRows.length - 1];
|
|
137
|
+
if (current && lengthOfRow([...current, id]) <= available) current.push(id);
|
|
138
|
+
else besideRows.push([id]);
|
|
139
|
+
}
|
|
140
|
+
for (const row of besideRows) {
|
|
141
|
+
const total = lengthOfRow(row);
|
|
142
|
+
if (total <= len(host)) {
|
|
143
|
+
let fromEnd = hostEnd;
|
|
144
|
+
for (const id of [...row].reverse()) {
|
|
145
|
+
if (id === "actions") continue;
|
|
146
|
+
fromEnd -= len(sizes.get(id));
|
|
147
|
+
at[id] = fromEnd;
|
|
148
|
+
fromEnd -= gap;
|
|
149
|
+
}
|
|
150
|
+
if (row.includes("actions")) at.actions = hostStart;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
let cursor = Math.max(offset, Math.min(hostStart, mainLength - offset - total));
|
|
154
|
+
for (const id of row) {
|
|
155
|
+
at[id] = cursor;
|
|
156
|
+
cursor += len(sizes.get(id)) + gap;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const towardsPage = placement.startsWith("bottom") || placement === "right" ? -1 : 1;
|
|
160
|
+
const boxes = {};
|
|
161
|
+
const toBox = (id, mainStart, crossStart) => {
|
|
162
|
+
const { width, height } = sizes.get(id);
|
|
163
|
+
if (vertical) return {
|
|
164
|
+
left: crossStart,
|
|
165
|
+
top: mainStart,
|
|
166
|
+
width,
|
|
167
|
+
height
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
left: rtl ? viewport.width - mainStart - width : mainStart,
|
|
171
|
+
top: crossStart,
|
|
172
|
+
width,
|
|
173
|
+
height
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
const hostCross = vertical ? host.left : host.top;
|
|
177
|
+
const hostThick = vertical ? host.width : host.height;
|
|
178
|
+
const onEdge = (thick) => towardsPage < 0 ? hostCross + hostThick - thick : hostCross;
|
|
179
|
+
const rowIn = (thick, from, fromThick) => towardsPage < 0 ? from - gap - thick : from + fromThick + gap;
|
|
180
|
+
const thickOf = (id) => vertical ? sizes.get(id).width : sizes.get(id).height;
|
|
181
|
+
for (const id of [...sides.before, ...sides.after]) boxes[id] = toBox(id, at[id], onEdge(thickOf(id)));
|
|
182
|
+
let rowFrom = hostCross;
|
|
183
|
+
let rowThick = hostThick;
|
|
184
|
+
for (const row of besideRows) {
|
|
185
|
+
for (const id of row) boxes[id] = toBox(id, at[id], rowIn(thickOf(id), rowFrom, rowThick));
|
|
186
|
+
const thickest = Math.max(...row.map(thickOf));
|
|
187
|
+
rowFrom = towardsPage < 0 ? rowFrom - gap - thickest : rowFrom + rowThick + gap;
|
|
188
|
+
rowThick = thickest;
|
|
189
|
+
}
|
|
190
|
+
let previous = electrons[0]?.id;
|
|
191
|
+
for (const id of stacked) {
|
|
192
|
+
const base = boxes[previous];
|
|
193
|
+
const baseCross = vertical ? base.left : base.top;
|
|
194
|
+
const baseThick = vertical ? base.width : base.height;
|
|
195
|
+
boxes[id] = toBox(id, vertical ? base.top : rtl ? viewport.width - base.left - base.width : base.left, rowIn(thickOf(id), baseCross, baseThick));
|
|
196
|
+
previous = id;
|
|
197
|
+
}
|
|
198
|
+
const shiftAlong = hostStart - hostStartOnItsOwn;
|
|
199
|
+
return {
|
|
200
|
+
shift: rtl ? -shiftAlong : shiftAlong,
|
|
201
|
+
reserve: vertical ? 0 : lengthOf(sides.before) + lengthOf(sides.after),
|
|
202
|
+
boxes,
|
|
203
|
+
movedBeside,
|
|
204
|
+
actionsAcross,
|
|
205
|
+
...actionsShown !== void 0 ? { actionsShown } : {}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
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;
|