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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 = void 0;
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 = void 0;
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 };
@@ -1,14 +1,47 @@
1
1
  // src/satellites/orbits.ts
2
2
  /** How far a wheel can turn: from 0 to this many orbitals. */
3
3
  const wheelEnd = (orbit) => Math.max(0, orbit.count - orbit.visible);
4
+ /** Orbital `index`'s slot on the arc (0 to visible − 1 on it), mirrored in a right-to-left page. */
5
+ const slotOf = (orbit, index, turn) => orbit.rtl ? orbit.visible - 1 - index + turn : index - turn;
6
+ /**
7
+ * How many orbitals are past each end of a wheel's arc, turned by `turn`:
8
+ * `low` past its first slot, `high` past its last one.
9
+ */
10
+ function hiddenPast(orbit, turn = 0) {
11
+ const past = {
12
+ low: 0,
13
+ high: 0
14
+ };
15
+ if (!orbit.wheel) return past;
16
+ for (let index = 0; index < orbit.count; index++) {
17
+ const slot = slotOf(orbit, index, turn);
18
+ if (slot < -.5) past.low++;
19
+ else if (slot > orbit.visible - .5) past.high++;
20
+ }
21
+ return past;
22
+ }
23
+ /**
24
+ * A point by an end of the arc (its first slot, low, or its last one, high):
25
+ * `along` px past it on the orbit, `outward` px further from the electron.
26
+ */
27
+ function pastEnd(orbit, end, along, outward = 0) {
28
+ const degrees = along / orbit.radius * (180 / Math.PI);
29
+ const angle = end === "low" ? orbit.first - degrees : orbit.first + (orbit.visible - 1) * orbit.step + degrees;
30
+ const radius = orbit.radius + outward;
31
+ return {
32
+ x: orbit.x + Math.cos(radians(angle)) * radius,
33
+ y: orbit.y + Math.sin(radians(angle)) * radius,
34
+ angle
35
+ };
36
+ }
4
37
  /**
5
38
  * Where orbital `index` is with the wheel turned by `turn` orbitals: on the
6
39
  * arc's slots, fading out past either end (the next one peeks out at a
7
40
  * fifth), mirrored in a right-to-left page (the first one on the right).
8
41
  */
9
42
  function spotOn(orbit, index, turn = 0) {
10
- const { count, visible } = orbit;
11
- const slot = orbit.rtl ? count - 1 - index + turn - (count - visible) : index - turn;
43
+ const { visible } = orbit;
44
+ const slot = slotOf(orbit, index, turn);
12
45
  const angle = orbit.first + slot * orbit.step;
13
46
  const past = slot < 0 ? -slot : slot > visible - 1 ? slot - (visible - 1) : 0;
14
47
  const peeks = slot < 0 ? orbit.peek.low : orbit.peek.high;
@@ -133,7 +166,9 @@ function orbitalAt(orbit, size, electronRadius, px, py, turn = 0) {
133
166
  return bestGap <= Math.max(orbit.step / 2 + 8, 30) ? best : -1;
134
167
  }
135
168
 
169
+ exports.hiddenPast = hiddenPast;
136
170
  exports.orbitalAt = orbitalAt;
171
+ exports.pastEnd = pastEnd;
137
172
  exports.planOrbit = planOrbit;
138
173
  exports.spotOn = spotOn;
139
174
  exports.wheelEnd = wheelEnd;
@@ -1,14 +1,47 @@
1
1
  // src/satellites/orbits.ts
2
2
  /** How far a wheel can turn: from 0 to this many orbitals. */
3
3
  const wheelEnd = (orbit) => Math.max(0, orbit.count - orbit.visible);
4
+ /** Orbital `index`'s slot on the arc (0 to visible − 1 on it), mirrored in a right-to-left page. */
5
+ const slotOf = (orbit, index, turn) => orbit.rtl ? orbit.visible - 1 - index + turn : index - turn;
6
+ /**
7
+ * How many orbitals are past each end of a wheel's arc, turned by `turn`:
8
+ * `low` past its first slot, `high` past its last one.
9
+ */
10
+ function hiddenPast(orbit, turn = 0) {
11
+ const past = {
12
+ low: 0,
13
+ high: 0
14
+ };
15
+ if (!orbit.wheel) return past;
16
+ for (let index = 0; index < orbit.count; index++) {
17
+ const slot = slotOf(orbit, index, turn);
18
+ if (slot < -.5) past.low++;
19
+ else if (slot > orbit.visible - .5) past.high++;
20
+ }
21
+ return past;
22
+ }
23
+ /**
24
+ * A point by an end of the arc (its first slot, low, or its last one, high):
25
+ * `along` px past it on the orbit, `outward` px further from the electron.
26
+ */
27
+ function pastEnd(orbit, end, along, outward = 0) {
28
+ const degrees = along / orbit.radius * (180 / Math.PI);
29
+ const angle = end === "low" ? orbit.first - degrees : orbit.first + (orbit.visible - 1) * orbit.step + degrees;
30
+ const radius = orbit.radius + outward;
31
+ return {
32
+ x: orbit.x + Math.cos(radians(angle)) * radius,
33
+ y: orbit.y + Math.sin(radians(angle)) * radius,
34
+ angle
35
+ };
36
+ }
4
37
  /**
5
38
  * Where orbital `index` is with the wheel turned by `turn` orbitals: on the
6
39
  * arc's slots, fading out past either end (the next one peeks out at a
7
40
  * fifth), mirrored in a right-to-left page (the first one on the right).
8
41
  */
9
42
  function spotOn(orbit, index, turn = 0) {
10
- const { count, visible } = orbit;
11
- const slot = orbit.rtl ? count - 1 - index + turn - (count - visible) : index - turn;
43
+ const { visible } = orbit;
44
+ const slot = slotOf(orbit, index, turn);
12
45
  const angle = orbit.first + slot * orbit.step;
13
46
  const past = slot < 0 ? -slot : slot > visible - 1 ? slot - (visible - 1) : 0;
14
47
  const peeks = slot < 0 ? orbit.peek.low : orbit.peek.high;
@@ -133,4 +166,4 @@ function orbitalAt(orbit, size, electronRadius, px, py, turn = 0) {
133
166
  return bestGap <= Math.max(orbit.step / 2 + 8, 30) ? best : -1;
134
167
  }
135
168
 
136
- export { orbitalAt, planOrbit, spotOn, wheelEnd };
169
+ export { hiddenPast, orbitalAt, pastEnd, planOrbit, spotOn, wheelEnd };
@@ -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;
@@ -38,12 +43,15 @@ export interface SatelliteHost {
38
43
  arrange: SatelliteArrangement;
39
44
  orbitalsOpenOn: OrbitalsOpenOn;
40
45
  orbitalLabels: boolean;
46
+ orbitalsMore: OrbitalsMore;
41
47
  orbitalsStayOpen: boolean;
42
48
  actionsStyle: ActionsStyle;
43
49
  actionsSide: ActionsSide;
44
50
  actionsOrientation: ActionsOrientation;
45
51
  actionsWheel: boolean;
46
52
  nearestToPill: NearestToPill;
53
+ /** Keep clear of the other pills on the screen */
54
+ avoidPills: boolean;
47
55
  actionsLabel: string;
48
56
  }
49
57
  /** `satellites` from `magic-pill/satellites`, passed to `<MagicPill satellites={satellites}>`. */
@@ -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;
@@ -38,12 +43,15 @@ export interface SatelliteHost {
38
43
  arrange: SatelliteArrangement;
39
44
  orbitalsOpenOn: OrbitalsOpenOn;
40
45
  orbitalLabels: boolean;
46
+ orbitalsMore: OrbitalsMore;
41
47
  orbitalsStayOpen: boolean;
42
48
  actionsStyle: ActionsStyle;
43
49
  actionsSide: ActionsSide;
44
50
  actionsOrientation: ActionsOrientation;
45
51
  actionsWheel: boolean;
46
52
  nearestToPill: NearestToPill;
53
+ /** Keep clear of the other pills on the screen */
54
+ avoidPills: boolean;
47
55
  actionsLabel: string;
48
56
  }
49
57
  /** `satellites` from `magic-pill/satellites`, passed to `<MagicPill satellites={satellites}>`. */
@@ -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 };
@@ -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 };
package/dist/styles.css CHANGED
@@ -348,6 +348,31 @@
348
348
  transition: none;
349
349
  }
350
350
 
351
+ /* A wheel's count of the orbitals past one of its ends (orbitalsMore:
352
+ "count"): a small pill of the same look; a press turns the wheel */
353
+ &[data-satellite="orbital-more"] {
354
+ --_mp-padding: 0px;
355
+ --_mp-rest-size: calc(1lh + 0.5rem);
356
+ --_mp-change: 0ms;
357
+ --_mp-fade: 0ms;
358
+ z-index: calc(var(--mp-z-index, 50) + 1);
359
+ min-block-size: 0;
360
+ padding: 0;
361
+ font: 700 0.75rem / 1.2 var(--mp-font-accent, inherit);
362
+ white-space: nowrap;
363
+ transition: opacity 150ms ease-out;
364
+
365
+ & > button {
366
+ padding: 0.25rem 0.55rem;
367
+ border: 0;
368
+ border-radius: inherit;
369
+ background: none;
370
+ color: inherit;
371
+ font: inherit;
372
+ cursor: pointer;
373
+ }
374
+ }
375
+
351
376
  /* An electron whose activity ends can pop away instead, like any pill leaving */
352
377
  /* An electron and the page's actions never change size: they go back
353
378
  into the pill once their content has faded, not after a size change */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magic-pill",
3
- "version": "9.4.0-next.2",
3
+ "version": "9.4.0-next.3",
4
4
  "type": "commonjs",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",