@johnmorrisdotca/wakusei-planets 0.58.0 → 0.60.0

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.
@@ -0,0 +1,133 @@
1
+ // The flat map's own words, in English and Japanese. The names of the bodies, the orbiters and the places come from the package's own tables (`BODIES`, `ORBITER_FACTS`, each place's `name`), not from here.
2
+ // The keys that chikyu-earth's flat map also has (`map`, `controls`, `myPlace`, `footprint`, `groundTrack`, `zoomIn`, `zoomOut`, `all`, `help`) say the same thing in the same words, so a page that swaps one map for the other keeps its wording.
3
+ /**
4
+ * The words the flat map writes, one table for each language: `{body}`, `{name}`, `{altitude}` and the like are filled in. The Japanese is standard, polite Japanese.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { FLAT_WORDS } from "@johnmorrisdotca/wakusei-planets/flat";
9
+ *
10
+ * console.log(FLAT_WORDS.en.footprint, FLAT_WORDS.ja.footprint);
11
+ * ```
12
+ */
13
+ export const FLAT_WORDS = {
14
+ en: {
15
+ map: "Flat map of {body}",
16
+ controls: "Map controls",
17
+ myPlace: "My place",
18
+ centreHome: "Centre the map on my place",
19
+ centreOn: "Centre the map on {where}",
20
+ nearSide: "Near side",
21
+ farSide: "Far side",
22
+ primeMeridian: "Prime meridian",
23
+ layersFilter: "What to show",
24
+ orbiters: "Orbiters",
25
+ landing: "Landing and rover sites",
26
+ crash: "Crash and impact sites",
27
+ planned: "Planned landings",
28
+ feature: "Named features",
29
+ footprint: "Footprint",
30
+ groundTrack: "Ground track",
31
+ zoomIn: "Zoom in",
32
+ zoomOut: "Zoom out",
33
+ all: "All",
34
+ kind_crewed: "crewed landing",
35
+ kind_landing: "landing",
36
+ kind_rover: "rover",
37
+ kind_crash: "crash",
38
+ kind_impact: "impact",
39
+ kind_entry: "entry",
40
+ kind_planned: "planned landing",
41
+ kind_feature: "named feature",
42
+ kind_orbiter: "orbiter",
43
+ status_tracked: "path fitted to tracking",
44
+ status_predicted: "path carried on from tracking",
45
+ status_modelled: "mean orbit only, position approximate",
46
+ status_none: "no public path",
47
+ announceOrbiter: "{name}, orbiting {body}, {altitude} km up{note}",
48
+ announcePlace: "{name}, {kind} on {body}, {lat}, {lon}",
49
+ approximate: ", position approximate",
50
+ mapMissing: "The map picture could not be loaded. The marks are still in place.",
51
+ nothing: "Nothing to show.",
52
+ help: "Arrow keys move from one orbiter or mark to the next, Enter chooses it, plus and minus zoom.",
53
+ shown: "{orbiters} orbiters and {places} places shown",
54
+ },
55
+ ja: {
56
+ map: "{body}の平面地図",
57
+ controls: "地図の操作",
58
+ myPlace: "自分の場所",
59
+ centreHome: "地図の中心を自分の場所にする",
60
+ centreOn: "地図の中心を{where}にする",
61
+ nearSide: "表側",
62
+ farSide: "裏側",
63
+ primeMeridian: "本初子午線",
64
+ layersFilter: "表示するもの",
65
+ orbiters: "周回機",
66
+ landing: "着陸地点と探査車の地点",
67
+ crash: "墜落・衝突地点",
68
+ planned: "着陸予定地点",
69
+ feature: "地形の名前",
70
+ footprint: "可視範囲",
71
+ groundTrack: "地上軌跡",
72
+ zoomIn: "拡大",
73
+ zoomOut: "縮小",
74
+ all: "すべて",
75
+ kind_crewed: "有人着陸",
76
+ kind_landing: "着陸",
77
+ kind_rover: "探査車",
78
+ kind_crash: "墜落",
79
+ kind_impact: "衝突",
80
+ kind_entry: "大気圏突入",
81
+ kind_planned: "着陸予定",
82
+ kind_feature: "地形",
83
+ kind_orbiter: "周回機",
84
+ status_tracked: "追跡データに合わせた軌道",
85
+ status_predicted: "追跡データから延長した軌道",
86
+ status_modelled: "平均軌道のみ、位置はおおよそ",
87
+ status_none: "公開された軌道データなし",
88
+ announceOrbiter: "{name}、{body}の周回機、高度 {altitude} km{note}",
89
+ announcePlace: "{name}、{body}の{kind}、{lat}、{lon}",
90
+ approximate: "、位置はおおよそ",
91
+ mapMissing: "地図の画像を読み込めませんでした。印はそのまま表示します。",
92
+ nothing: "表示するものがありません。",
93
+ help: "矢印キーで次の周回機や印へ移り、Enter キーで選びます。プラスとマイナスのキーで拡大・縮小します。",
94
+ shown: "周回機{orbiters}機と地点{places}か所を表示中",
95
+ },
96
+ };
97
+ /**
98
+ * The words with their `{name}` places filled in; a key a language does not have is said in English, and a key neither has comes back as it is.
99
+ *
100
+ * @param lang - `en` or `ja`.
101
+ * @param key - A key of `FLAT_WORDS`.
102
+ * @param values - What goes in the `{...}` places.
103
+ * @returns The sentence.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * import { say } from "@johnmorrisdotca/wakusei-planets/flat";
108
+ *
109
+ * console.log(say("en", "map", { body: "Mars" }), "|", say("ja", "map", { body: "火星" }));
110
+ * ```
111
+ */
112
+ export const say = (lang, key, values = {}) => (FLAT_WORDS[lang][key] ?? FLAT_WORDS.en[key] ?? key).replace(/\{(\w+)\}/g, (all, name) => String(values[name] ?? all));
113
+ /**
114
+ * A latitude or longitude with its hemisphere, in the language's way: `3.01° S` and `23.47° E`, or `南緯3.01°` and `東経23.47°`.
115
+ *
116
+ * @param lang - `en` or `ja`.
117
+ * @param axis - `lat` or `lon`.
118
+ * @param degrees - Degrees, north and east positive.
119
+ * @returns The text.
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * import { coordinateText } from "@johnmorrisdotca/wakusei-planets/flat";
124
+ *
125
+ * console.log(coordinateText("en", "lat", -3.01), "|", coordinateText("ja", "lon", 23.47));
126
+ * ```
127
+ */
128
+ export function coordinateText(lang, axis, degrees) {
129
+ const value = Math.abs(degrees).toFixed(2);
130
+ if (lang === "ja")
131
+ return `${axis === "lat" ? (degrees < 0 ? "南緯" : "北緯") : degrees < 0 ? "西経" : "東経"}${value}°`;
132
+ return `${value}° ${axis === "lat" ? (degrees < 0 ? "S" : "N") : degrees < 0 ? "W" : "E"}`;
133
+ }
@@ -48,6 +48,29 @@ export declare const COVER_MIN_PX = 6;
48
48
  * ```
49
49
  */
50
50
  export declare function coveredBy(entries: readonly CoverEntry[]): Map<string, string>;
51
+ /**
52
+ * Which body, if any, hides a point of a label: the nearest body whose drawn disc holds the point on the screen and which is nearer the camera than the point is. For a name, a ring or a pin whose place is a point
53
+ * (a belt's name at its anchor, the Oort cloud's note, a mark on a surface), not a body. A disc narrower than `COVER_MIN_PX` hides nothing, and `self` (the point's own body) never hides it. A disc test
54
+ * for each of the few discs big enough to matter; nothing is read back from the picture.
55
+ *
56
+ * @param point - The point's place on the screen in CSS pixels and its distance from the camera (any unit, the same as the discs').
57
+ * @param discs - The drawn discs: their places and radii on the screen (the radius `placeOf(id).r` gives, rounded at the edge of the picture) and their distances.
58
+ * @param self - The id of the body the point belongs to, if it belongs to one.
59
+ * @returns The id of the covering body, or `null` when the point is in the open.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * import { coverOf } from "@johnmorrisdotca/wakusei-planets/space";
64
+ *
65
+ * const discs = [{ id: "pholus", x: 300, y: 300, r: 200, distance: 4 }];
66
+ * console.log(coverOf({ x: 340, y: 280, distance: 5_000 }, discs), coverOf({ x: 640, y: 280, distance: 5_000 }, discs));
67
+ * ```
68
+ */
69
+ export declare function coverOf(point: {
70
+ x: number;
71
+ y: number;
72
+ distance: number;
73
+ }, discs: readonly CoverEntry[], self?: string): string | null;
51
74
  /**
52
75
  * One quiet arrow: outside the covering body's disc, on the side nearest the bodies behind it, pointing in behind it, with the surest of them named and the rest counted.
53
76
  *
@@ -31,20 +31,42 @@ export const COVER_MIN_PX = 6;
31
31
  export function coveredBy(entries) {
32
32
  const behind = new Map();
33
33
  for (const body of entries) {
34
- let cover;
35
- for (const other of entries) {
36
- if (other === body || other.r < COVER_MIN_PX || other.distance >= body.distance)
37
- continue;
38
- if (Math.hypot(body.x - other.x, body.y - other.y) >= other.r)
39
- continue;
40
- if (cover === undefined || other.distance < cover.distance)
41
- cover = other;
42
- }
43
- if (cover !== undefined)
44
- behind.set(body.id, cover.id);
34
+ const cover = coverOf(body, entries, body.id);
35
+ if (cover !== null)
36
+ behind.set(body.id, cover);
45
37
  }
46
38
  return behind;
47
39
  }
40
+ /**
41
+ * Which body, if any, hides a point of a label: the nearest body whose drawn disc holds the point on the screen and which is nearer the camera than the point is. For a name, a ring or a pin whose place is a point
42
+ * (a belt's name at its anchor, the Oort cloud's note, a mark on a surface), not a body. A disc narrower than `COVER_MIN_PX` hides nothing, and `self` (the point's own body) never hides it. A disc test
43
+ * for each of the few discs big enough to matter; nothing is read back from the picture.
44
+ *
45
+ * @param point - The point's place on the screen in CSS pixels and its distance from the camera (any unit, the same as the discs').
46
+ * @param discs - The drawn discs: their places and radii on the screen (the radius `placeOf(id).r` gives, rounded at the edge of the picture) and their distances.
47
+ * @param self - The id of the body the point belongs to, if it belongs to one.
48
+ * @returns The id of the covering body, or `null` when the point is in the open.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * import { coverOf } from "@johnmorrisdotca/wakusei-planets/space";
53
+ *
54
+ * const discs = [{ id: "pholus", x: 300, y: 300, r: 200, distance: 4 }];
55
+ * console.log(coverOf({ x: 340, y: 280, distance: 5_000 }, discs), coverOf({ x: 640, y: 280, distance: 5_000 }, discs));
56
+ * ```
57
+ */
58
+ export function coverOf(point, discs, self) {
59
+ let cover;
60
+ for (const other of discs) {
61
+ if (other.id === self || other.r < COVER_MIN_PX || other.distance >= point.distance)
62
+ continue;
63
+ if (Math.hypot(point.x - other.x, point.y - other.y) >= other.r)
64
+ continue;
65
+ if (cover === undefined || other.distance < cover.distance)
66
+ cover = other;
67
+ }
68
+ return cover === undefined ? null : cover.id;
69
+ }
48
70
  /**
49
71
  * How far outside the disc's edge the arrow's tip sits, in CSS pixels.
50
72
  *
@@ -26,6 +26,18 @@ export { EARTH_PLACE_LOOKS, EARTH_PLACE_MARKS, type EarthPlace, type EarthPlaceK
26
26
  export { setThreeLoader, SPACE_BODIES, type RidePoint, type RideTarget, type Sight, type SightEdge, type SpaceBody, type SpaceLight };
27
27
  /** Where a body is on the screen, in CSS pixels in the element: its centre and its radius. */
28
28
  export type { BodyPlace };
29
+ /**
30
+ * What a body behind another gets: `hide` (fade its name and ring out), `arrow` (a quiet arrow on the disc's edge) or `name` (draw it over the disc).
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import type { Covered } from "@johnmorrisdotca/wakusei-planets/space/element";
35
+ *
36
+ * const how: Covered = "hide";
37
+ * console.log(how);
38
+ * ```
39
+ */
40
+ export type Covered = "hide" | "arrow" | "name";
29
41
  /**
30
42
  * What a page can tell a reader about a body now.
31
43
  *
@@ -403,11 +415,13 @@ export declare class WakuseiSpace extends HTMLElement {
403
415
  get orbiterTrack(): boolean;
404
416
  set orbiterTrack(value: boolean);
405
417
  /**
406
- * What a body behind another gets (the attribute `covered`): `name` (the default) draws its floating name and ring over the nearer body's disc as always; `arrow` draws instead one small quiet arrow just outside the
407
- * disc's edge on the side nearest the hidden body, pointing in behind it, with the surest hidden body's name beside it and the others counted (`Uranus +4`); a press on it goes to that body. The arrow goes as the body comes out.
418
+ * What a body behind another gets (the attribute `covered`): `hide` (the default) fades its floating name and ring out while its place is inside a nearer body's drawn disc, and back when it comes out, as if the disc hid
419
+ * them; `arrow` draws instead one small quiet arrow just outside the disc's edge on the side nearest the hidden body, pointing in behind it, with the surest hidden body's name beside it and the others counted
420
+ * (`Uranus +4`); a press on it goes to that body. The arrow goes as the body comes out; `name` draws the name and ring over the nearer body's disc as 0.57 and earlier did. The same discs hide the Oort cloud's note, the
421
+ * marks of the places on a body that is behind another, and, through `coveredAt`, any label a page draws over the view.
408
422
  */
409
- get covered(): "name" | "arrow";
410
- set covered(value: "name" | "arrow");
423
+ get covered(): Covered;
424
+ set covered(value: Covered);
411
425
  /**
412
426
  * Keep a body's floating name and dot while its name is drawn on its globe (the attribute `labels-always`; off by default). Off, a body that carries its drawn name (`body-label` on, and the body at least 24 CSS pixels in
413
427
  * radius) fades its floating name and dot out, and they fade back when it shrinks below that; bodies with no drawn name keep their floating names.
@@ -790,6 +804,15 @@ export declare class WakuseiSpace extends HTMLElement {
790
804
  };
791
805
  /** Where a body is on the screen now: its centre and radius in CSS pixels in the element, or `null` when it is behind the camera or not drawn. */
792
806
  placeOf(id: BodyId): BodyPlace | null;
807
+ /**
808
+ * Which body's drawn disc hides a point of the scene at the last draw, or `null`: for a page that draws its own label over the view (a belt's name at its anchor, a pin) and wants it to go where a nearer body is in
809
+ * front of it, the way the view's own names do. The point is in the scene's places (`stats.camera` is in the same ones); the discs are the bodies and moons placed on the screen, at the radius `placeOf(id).r`
810
+ * gives. Always `null` while `labels` is off, since the discs are worked out with the names.
811
+ *
812
+ * @param point - A place in the scene.
813
+ * @returns The id of the covering body, or `null` when the point is in the open or off the view.
814
+ */
815
+ coveredAt(point: readonly [number, number, number]): string | null;
793
816
  /** True for the full-screen mode (the `immersive` attribute): the element fills its box in any shape, a plain wheel zooms instead of scrolling the page, and a touch drag turns the view instead of scrolling it. */
794
817
  get immersive(): boolean;
795
818
  set immersive(value: boolean);
@@ -7,7 +7,7 @@ import { createGameClock } from "./clock.js";
7
7
  import { bodyKindOf, findBody, hopFrom, hostOf, HOP_ORDER, systemOf } from "./bodies.js";
8
8
  import { sightChanged, sightOf, withinMargin } from "./sight.js";
9
9
  import { chooseLabels, nameSpot } from "./labels.js";
10
- import { coverArrows } from "./covered.js";
10
+ import { coverArrows, coverOf } from "./covered.js";
11
11
  import { createPainter, picturesPending } from "../scene/painter.js";
12
12
  import { NAME_LABEL_ATTRIBUTES, readNameLabel } from "../scene/name-label.js";
13
13
  import { createDoorHost } from "../door/host.js";
@@ -41,6 +41,7 @@ const SCALE_WORDS = {
41
41
  };
42
42
  /** A body whose disc is smaller than this many CSS pixels across its radius is marked with a ring as well as its name. */
43
43
  const RING_BELOW_PX = 4;
44
+ const readCovered = (value) => (value === "arrow" ? "arrow" : value === "name" ? "name" : "hide");
44
45
  /** The id of the package's own source of the belts: it is in every view, but is not one of `sources`. */
45
46
  const BELTS_SOURCE_ID = "wakusei-belts";
46
47
  /** The belts the attribute `belts` names: all of them where it is left out or says `all`, none for `off`, else a list of names separated by commas or spaces. */
@@ -107,7 +108,7 @@ const readBody = (value) => {
107
108
  * 1.05 radii from the surface (`FIT_DISTANCE` over the zoom), so past a zoom of about 3.9 nothing moves; 3.6 is where the finest map tiles of the Earth, Mars and the Moon (16384 pixels round) run out of detail too, so it is the same ceiling for both.
108
109
  */
109
110
  const CARRIED_LIMITS = { zoomMin: 1e-6, zoomMax: 3.6, tiltMax: 90 };
110
- const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[data-flip]{display:flex;flex-direction:row-reverse}.sp-label[data-flip]::before{margin:0 -2px 1px 5px}.sp-label[hidden]{display:none}.sp-arrow{position:absolute;left:0;top:0;margin:0;padding:0 4px 0 0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.8;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:auto;cursor:pointer}.sp-arrow::before{content:"";display:inline-block;width:0;height:0;margin:0 5px 1px 0;border:5px solid transparent;border-left:7px solid #fff;transform:rotate(var(--turn,0deg));transform-origin:30% 50%}.sp-arrow[hidden]{display:none}.sp-arrow:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label[data-far]:not([data-carried]),.sp-ring[data-far]:not([data-carried]){opacity:var(--wakusei-far-opacity,.5)}.sp-arrow[data-far]{opacity:calc(.8*var(--wakusei-far-opacity,.5))}.sp-label,.sp-ring,.sp-arrow{transition:opacity .35s ease}.sp-label[data-carried],.sp-ring[data-carried]{opacity:0;pointer-events:none}@media (prefers-reduced-motion:reduce){.sp-label,.sp-ring,.sp-arrow{transition:none}}.sp-ring{position:absolute;left:0;top:0;width:16px;height:16px;margin:-8px 0 0 -8px;box-sizing:border-box;border:1.5px solid rgba(255,255,255,.85);border-radius:50%;box-shadow:0 0 3px #000;pointer-events:none;will-change:transform}.sp-ring[hidden]{display:none}.sp-scale{position:absolute;left:10px;top:8px;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.9;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-region{position:absolute;left:10px;bottom:8px;margin:0;padding:0;font:600 15px/20px system-ui,-apple-system,sans-serif;color:#fff;opacity:.95;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:none;transition:opacity .35s}.sp-region[hidden]{display:block;opacity:0}@media (prefers-reduced-motion:reduce){.sp-region{transition:none}}.sp-note{position:absolute;left:10px;right:10px;top:28px;max-width:44em;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.92;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-note[hidden],.sp-oort[hidden]{display:none}.sp-oort{position:absolute;left:0;top:0;margin:0;padding:0;font:italic 12px/16px system-ui,-apple-system,sans-serif;color:#aeb8e6;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}</style><div id="stage"></div><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p><p class="sp-region" id="region" part="region" role="status" hidden></p><p class="sp-note" part="note" role="status" hidden></p><p class="sp-oort" part="oort" hidden></p>`;
111
+ const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[data-flip]{display:flex;flex-direction:row-reverse}.sp-label[data-flip]::before{margin:0 -2px 1px 5px}.sp-label[hidden]{display:none}.sp-arrow{position:absolute;left:0;top:0;margin:0;padding:0 4px 0 0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.8;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:auto;cursor:pointer}.sp-arrow::before{content:"";display:inline-block;width:0;height:0;margin:0 5px 1px 0;border:5px solid transparent;border-left:7px solid #fff;transform:rotate(var(--turn,0deg));transform-origin:30% 50%}.sp-arrow[hidden]{display:none}.sp-arrow:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label[data-far]:not([data-carried]),.sp-ring[data-far]:not([data-carried]){opacity:var(--wakusei-far-opacity,.5)}.sp-arrow[data-far]{opacity:calc(.8*var(--wakusei-far-opacity,.5))}.sp-label,.sp-ring,.sp-arrow{transition:opacity .35s ease}.sp-label[data-carried],.sp-ring[data-carried]{opacity:0;pointer-events:none}@media (prefers-reduced-motion:reduce){.sp-label,.sp-ring,.sp-arrow{transition:none}}.sp-ring{position:absolute;left:0;top:0;width:16px;height:16px;margin:-8px 0 0 -8px;box-sizing:border-box;border:1.5px solid rgba(255,255,255,.85);border-radius:50%;box-shadow:0 0 3px #000;pointer-events:none;will-change:transform}.sp-ring[hidden]{display:none}.sp-scale{position:absolute;left:10px;top:8px;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.9;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-region{position:absolute;left:10px;bottom:8px;margin:0;padding:0;font:600 15px/20px system-ui,-apple-system,sans-serif;color:#fff;opacity:.95;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:none;transition:opacity .35s}.sp-region[hidden]{display:block;opacity:0}@media (prefers-reduced-motion:reduce){.sp-region{transition:none}}.sp-note{position:absolute;left:10px;right:10px;top:28px;max-width:44em;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.92;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-note[hidden],.sp-oort[hidden]{display:none}.sp-oort{position:absolute;left:0;top:0;margin:0;padding:0;font:italic 12px/16px system-ui,-apple-system,sans-serif;color:#aeb8e6;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none;transition:opacity .35s ease}.sp-oort[data-covered]{opacity:0}@media (prefers-reduced-motion:reduce){.sp-oort{transition:none}}</style><div id="stage"></div><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p><p class="sp-region" id="region" part="region" role="status" hidden></p><p class="sp-note" part="note" role="status" hidden></p><p class="sp-oort" part="oort" hidden></p>`;
111
112
  const orbiterLines = (value) => (value === "chosen" || value === "none" ? value : "all");
112
113
  /**
113
114
  * The `<wakusei-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`
@@ -209,7 +210,7 @@ export class WakuseiSpace extends HTMLElement {
209
210
  this.#model.moonSize = readMoonSize(this.getAttribute("moon-size") ?? 2);
210
211
  this.#model.labels = this.getAttribute("labels") !== "off";
211
212
  this.#labelsAlways = this.hasAttribute("labels-always") && this.getAttribute("labels-always") !== "off";
212
- this.#covered = this.getAttribute("covered") === "arrow" ? "arrow" : "name";
213
+ this.#covered = readCovered(this.getAttribute("covered"));
213
214
  this.roadster = this.hasAttribute("roadster") && this.getAttribute("roadster") !== "off";
214
215
  const craft = this.getAttribute("spacecraft");
215
216
  if (craft !== null && craft !== "off")
@@ -368,7 +369,7 @@ export class WakuseiSpace extends HTMLElement {
368
369
  else if (name === "labels-always")
369
370
  this.labelsAlways = value !== null && value !== "off";
370
371
  else if (name === "covered")
371
- this.covered = value === "arrow" ? "arrow" : "name";
372
+ this.covered = readCovered(value);
372
373
  else if (name === "roadster")
373
374
  this.roadster = value !== null && value !== "off";
374
375
  else if (name === "spacecraft")
@@ -712,6 +713,8 @@ export class WakuseiSpace extends HTMLElement {
712
713
  this.#earthLayer?.clear();
713
714
  this.#earthOmitted = 0;
714
715
  };
716
+ if (surface !== null && this.#covered !== "name" && this.#places?.["earth"]?.behind !== undefined)
717
+ return clear();
715
718
  if (surface === null || root === null || using === undefined || !this.hasAttribute("earth-places") || !(surface.radiusPx >= EARTH_PLACES_FROM_PX))
716
719
  return clear();
717
720
  const places = this.#readEarthPlaces();
@@ -751,6 +754,11 @@ export class WakuseiSpace extends HTMLElement {
751
754
  const names = readSurfaceNames(this.getAttribute("surface-names"));
752
755
  const surface = this.#surface;
753
756
  const root = this.shadowRoot;
757
+ // the marks lie on the body looked at: not drawn while a nearer body's disc is over it
758
+ if (surface !== null && this.#covered !== "name" && this.#places?.[surface.id]?.behind !== undefined) {
759
+ this.#markLayer?.clear();
760
+ return;
761
+ }
754
762
  if ((!names.on && layers.length === 0) || surface === null || root === null || !PLACE_BODIES.includes(surface.id)) {
755
763
  if (!names.on && layers.length === 0 && this.#markLayer !== undefined) {
756
764
  this.#markLayer.dispose();
@@ -1085,11 +1093,13 @@ export class WakuseiSpace extends HTMLElement {
1085
1093
  this.#model.orbiterTrack = value;
1086
1094
  this.#gate?.request();
1087
1095
  }
1088
- #covered = "name";
1096
+ #covered = "hide";
1089
1097
  #arrows = new Map();
1090
1098
  /**
1091
- * What a body behind another gets (the attribute `covered`): `name` (the default) draws its floating name and ring over the nearer body's disc as always; `arrow` draws instead one small quiet arrow just outside the
1092
- * disc's edge on the side nearest the hidden body, pointing in behind it, with the surest hidden body's name beside it and the others counted (`Uranus +4`); a press on it goes to that body. The arrow goes as the body comes out.
1099
+ * What a body behind another gets (the attribute `covered`): `hide` (the default) fades its floating name and ring out while its place is inside a nearer body's drawn disc, and back when it comes out, as if the disc hid
1100
+ * them; `arrow` draws instead one small quiet arrow just outside the disc's edge on the side nearest the hidden body, pointing in behind it, with the surest hidden body's name beside it and the others counted
1101
+ * (`Uranus +4`); a press on it goes to that body. The arrow goes as the body comes out; `name` draws the name and ring over the nearer body's disc as 0.57 and earlier did. The same discs hide the Oort cloud's note, the
1102
+ * marks of the places on a body that is behind another, and, through `coveredAt`, any label a page draws over the view.
1093
1103
  */
1094
1104
  get covered() {
1095
1105
  return this.#covered;
@@ -1098,6 +1108,7 @@ export class WakuseiSpace extends HTMLElement {
1098
1108
  this.#covered = value;
1099
1109
  if (this.#places)
1100
1110
  this.#placeLabels(this.#places);
1111
+ this.#placeOort();
1101
1112
  }
1102
1113
  #labelsAlways = false;
1103
1114
  /**
@@ -1641,12 +1652,14 @@ export class WakuseiSpace extends HTMLElement {
1641
1652
  return out;
1642
1653
  }
1643
1654
  /**
1644
- * The controls' yaw and tilt that look at a body from the side the camera comes from, swung so a companion is in the picture and the body stays at least half lit; null when the camera has not drawn yet.
1655
+ * The controls' yaw and tilt that look at a body from the side the camera comes from, swung so a companion is in the picture and the body stays at least half lit; null for the Earth before the camera has drawn.
1645
1656
  * The reader's own later turn is not touched: this runs for an arrival and for a double click, not for a drag.
1646
1657
  */
1647
1658
  #faceApproach(id, swing = true) {
1648
1659
  const model = this.#model;
1649
- if (!model.pose.valid)
1660
+ // a move asked for before the first draw (an address that opens at a body, `goTo` on a page that has just loaded) comes from where the view opens, the Earth: its camera is not drawn yet, and with no side
1661
+ // chosen the body is looked at from whichever side the default aim falls on, which for a body beyond the Earth is the night side half the day
1662
+ if (!model.pose.valid && id === "earth")
1650
1663
  return null;
1651
1664
  const body = this.#site(id);
1652
1665
  const sun = id === "sun" ? undefined : this.#site("sun").at;
@@ -1991,6 +2004,10 @@ export class WakuseiSpace extends HTMLElement {
1991
2004
  this.#showNote();
1992
2005
  if (this.#oortLabel.hidden)
1993
2006
  this.#oortLabel.hidden = false;
2007
+ // the note fades out while a nearer body's disc is over its place
2008
+ const behind = this.#covered !== "name" && coverOf(at, this.#model.discs) !== null;
2009
+ if (this.#oortLabel.hasAttribute("data-covered") !== behind)
2010
+ this.#oortLabel.toggleAttribute("data-covered", behind);
1994
2011
  this.#oortLabel.style.transform = `translate(${Math.round(at.x) + 6}px,${Math.round(at.y) - 8}px)`;
1995
2012
  }
1996
2013
  /** What the camera is riding along with now, or null. */
@@ -2190,7 +2207,8 @@ export class WakuseiSpace extends HTMLElement {
2190
2207
  // beside the dot, on the side that stays inside the view
2191
2208
  const { x, y, flipped } = nameSpot(at, { width, height: 16 }, frame);
2192
2209
  // a body that carries its drawn name gives its floating name up (it fades, and leaves its place to the others) unless the page keeps both; a body behind another gives it up for the arrow
2193
- const carried = at.named === true && !this.#labelsAlways;
2210
+ const hidden = at.behind !== undefined && this.#covered === "hide";
2211
+ const carried = hidden || (at.named === true && !this.#labelsAlways);
2194
2212
  const covered = at.behind !== undefined && this.#covered === "arrow";
2195
2213
  if (covered)
2196
2214
  continue;
@@ -2451,6 +2469,17 @@ export class WakuseiSpace extends HTMLElement {
2451
2469
  const at = this.#places?.[id];
2452
2470
  return at ? { ...at } : null;
2453
2471
  }
2472
+ /**
2473
+ * Which body's drawn disc hides a point of the scene at the last draw, or `null`: for a page that draws its own label over the view (a belt's name at its anchor, a pin) and wants it to go where a nearer body is in
2474
+ * front of it, the way the view's own names do. The point is in the scene's places (`stats.camera` is in the same ones); the discs are the bodies and moons placed on the screen, at the radius `placeOf(id).r`
2475
+ * gives. Always `null` while `labels` is off, since the discs are worked out with the names.
2476
+ *
2477
+ * @param point - A place in the scene.
2478
+ * @returns The id of the covering body, or `null` when the point is in the open or off the view.
2479
+ */
2480
+ coveredAt(point) {
2481
+ return this.#model.coverAt([point[0], point[1], point[2]]);
2482
+ }
2454
2483
  #nameLabel(button, id) {
2455
2484
  const text = this.#nameOf(id);
2456
2485
  button.textContent = text;
@@ -7,7 +7,7 @@ export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, systemOf, type SpaceK
7
7
  export { besideMoon, BESIDE_RADII, type BesideCamera, type BesideInput } from "./beside.ts";
8
8
  export { ARROWS_PER_ORBIT, arrowCount, arrowSites, MAX_ARROWS_PER_ORBIT, chevron, helpSpin, readHelpPlace, spinArrow, type HelpPlace, type OrbitArrow } from "./arrows.ts";
9
9
  export { spinAxis, type SpinAxis } from "./spin.ts";
10
- export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy, type CoverArrow, type CoverEntry } from "./covered.ts";
10
+ export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy, coverOf, type CoverArrow, type CoverEntry } from "./covered.ts";
11
11
  export { TRAVEL_BUDGET_MS, TRAVEL_CLEARANCE, arrivalSide, travelArrival, travelPlan, travelPose, type ArrivalCompanion, type TravelBody, type TravelInput, type TravelKind, type TravelPlan, type TravelSample, type TravelSight, type TravelView } from "./travel.ts";
12
12
  export { bodyBasis, carry, controlsFor, directionBetween, FRAMES, hasRotation, holdSite, keepClear, pairAxis, pairBasis, readFrame, type FrameKind, type HoldBasis } from "./hold.ts";
13
13
  export { regionOrbits, regionView, SUN_REGIONS, type SunRegion } from "./regions.ts";
@@ -8,7 +8,7 @@ export { bodyKindOf, findBody, HOP_ORDER, hopFrom, hostOf, systemOf } from "./bo
8
8
  export { besideMoon, BESIDE_RADII } from "./beside.js";
9
9
  export { ARROWS_PER_ORBIT, arrowCount, arrowSites, MAX_ARROWS_PER_ORBIT, chevron, helpSpin, readHelpPlace, spinArrow } from "./arrows.js";
10
10
  export { spinAxis } from "./spin.js";
11
- export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy } from "./covered.js";
11
+ export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy, coverOf } from "./covered.js";
12
12
  export { TRAVEL_BUDGET_MS, TRAVEL_CLEARANCE, arrivalSide, travelArrival, travelPlan, travelPose } from "./travel.js";
13
13
  export { bodyBasis, carry, controlsFor, directionBetween, FRAMES, hasRotation, holdSite, keepClear, pairAxis, pairBasis, readFrame } from "./hold.js";
14
14
  export { regionOrbits, regionView, SUN_REGIONS } from "./regions.js";
@@ -9,6 +9,7 @@ import { type PaintLabel, type WakuseiPainter } from "../scene/painter.ts";
9
9
  import "../bodies/all.ts";
10
10
  import { type Vec3 } from "../vec.ts";
11
11
  import { type HelpPlace, type OrbitArrow } from "./arrows.ts";
12
+ import { type CoverEntry } from "./covered.ts";
12
13
  import type { SightInput } from "./sight.ts";
13
14
  import { type SpaceDwarf, type SpaceFrame, type SpacePlanet, type SpaceVec3 } from "./frame.ts";
14
15
  import { type PaintSpec, type PaintTrail } from "../paint/trail.ts";
@@ -319,7 +320,11 @@ export interface SpaceModel {
319
320
  oort: {
320
321
  x: number;
321
322
  y: number;
323
+ distance: number;
322
324
  } | null;
325
+ /** The drawn discs at the last draw (the bodies and moons placed on the screen, with their distances from the camera), and which of them hides a point of the scene (in the scene's absolute places), or null when none does. */
326
+ discs: readonly CoverEntry[];
327
+ coverAt: (point: Vec3) => string | null;
323
328
  /** How many frames the ephemeris has worked out. */
324
329
  lookups: number;
325
330
  /** Pixels a game-second moves things on the screen (the fastest turning body in sight): the draw rate follows it. */
@@ -12,7 +12,7 @@ import { groundDirection } from "./aim.js";
12
12
  import { hostOf } from "./bodies.js";
13
13
  import { arrowSites, ARROWS_PER_ORBIT, chevron, helpSpin, MAX_ARROWS_PER_ORBIT } from "./arrows.js";
14
14
  import { besideMoon } from "./beside.js";
15
- import { coveredBy } from "./covered.js";
15
+ import { coveredBy, coverOf } from "./covered.js";
16
16
  import { spinAxis } from "./spin.js";
17
17
  import { createTrack, EARTH_RADIUS_KM, eclipticToScene, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
18
18
  import { createPaintOverlay } from "./paint-overlay.js";
@@ -170,6 +170,8 @@ export const newSpaceModel = () => ({
170
170
  door: { points: 0, belts: 0, draws: 0, used: {} },
171
171
  belts: BELT_IDS,
172
172
  oort: null,
173
+ discs: [],
174
+ coverAt: () => null,
173
175
  lookups: 0,
174
176
  motion: 0,
175
177
  drawnView: null,
@@ -852,7 +854,7 @@ export function createSpaceItem(model, deps) {
852
854
  const off = projected.x * projected.x + projected.y * projected.y;
853
855
  if (off < best) {
854
856
  best = off;
855
- model.oort = { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height };
857
+ model.oort = { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height, distance: Math.hypot(oortPositions[i * 3] - camera.position.x, oortPositions[i * 3 + 1] - camera.position.y, oortPositions[i * 3 + 2] - camera.position.z) };
856
858
  }
857
859
  }
858
860
  }
@@ -1314,8 +1316,23 @@ export function createSpaceItem(model, deps) {
1314
1316
  }
1315
1317
  for (const [id, cover] of coveredBy(entries))
1316
1318
  places[id].behind = cover;
1319
+ // a point of the scene that a page labels (a belt's name at its anchor) is hidden by the same discs
1320
+ model.discs = entries;
1321
+ model.coverAt = (point) => {
1322
+ // in front of the camera, whatever the far plane cuts: a belt's name is labelled far beyond what is drawn
1323
+ projected.set(point[0] - origin[0], point[1] - origin[1], point[2] - origin[2]).applyMatrix4(camera.matrixWorldInverse);
1324
+ if (!(projected.z < 0))
1325
+ return null;
1326
+ const distance = Math.hypot(projected.x, projected.y, projected.z);
1327
+ projected.applyMatrix4(camera.projectionMatrix);
1328
+ return coverOf({ x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height, distance }, entries);
1329
+ };
1317
1330
  deps.onLabels(places);
1318
1331
  }
1332
+ else {
1333
+ model.discs = [];
1334
+ model.coverAt = () => null;
1335
+ }
1319
1336
  // after the names: the places on the Earth keep clear of them
1320
1337
  if (deps.onEarth && (deps.wantEarth?.() ?? false)) {
1321
1338
  const earth = rideFrom ? undefined : slots.get("earth")?.drawing;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/wakusei-planets",
3
- "version": "0.58.0",
3
+ "version": "0.60.0",
4
4
  "description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
5
5
  "keywords": [
6
6
  "planets",
@@ -92,6 +92,7 @@
92
92
  "./dist/lineup/element.js",
93
93
  "./dist/space/element.js",
94
94
  "./dist/plan/element.js",
95
+ "./dist/flat/define.js",
95
96
  "./dist/surface/element.js",
96
97
  "./dist/surface/land.js",
97
98
  "./dist/earth-places.js",
@@ -103,6 +104,7 @@
103
104
  "./src/lineup/element.ts",
104
105
  "./src/space/element.ts",
105
106
  "./src/plan/element.ts",
107
+ "./src/flat/define.ts",
106
108
  "./src/surface/element.ts",
107
109
  "./src/surface/land.ts",
108
110
  "./src/earth-places.ts",
@@ -154,6 +156,16 @@
154
156
  "import": "./dist/plan/element.js",
155
157
  "default": "./dist/plan/element.js"
156
158
  },
159
+ "./flat": {
160
+ "types": "./dist/flat/index.d.ts",
161
+ "import": "./dist/flat/index.js",
162
+ "default": "./dist/flat/index.js"
163
+ },
164
+ "./flat/define": {
165
+ "types": "./dist/flat/define.d.ts",
166
+ "import": "./dist/flat/define.js",
167
+ "default": "./dist/flat/define.js"
168
+ },
157
169
  "./surface": {
158
170
  "types": "./dist/surface/index.d.ts",
159
171
  "import": "./dist/surface/index.js",