@johnmorrisdotca/wakusei-planets 0.74.2 → 0.75.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.
Files changed (59) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/NOTICE.md +4 -3
  3. package/README.md +7 -7
  4. package/dist/bodies/dwarfs.js +1 -1
  5. package/dist/bodies/earth-look.js +1 -1
  6. package/dist/bodies/jupiter.js +1 -1
  7. package/dist/bodies/mars.js +1 -1
  8. package/dist/bodies/moons-neptune.js +1 -1
  9. package/dist/bodies/moons-pluto.js +2 -0
  10. package/dist/bodies/moons-saturn.js +1 -1
  11. package/dist/bodies/neptune.js +1 -1
  12. package/dist/bodies/pluto.js +1 -0
  13. package/dist/bodies/saturn.js +1 -1
  14. package/dist/bodies/uranus.js +1 -1
  15. package/dist/bodies/venus.js +1 -1
  16. package/dist/data/discovery.js +30 -0
  17. package/dist/data/estimated-moons.js +354 -354
  18. package/dist/data/moon-catalogue.d.ts +1 -1
  19. package/dist/data/moon-catalogue.js +368 -368
  20. package/dist/data/orbits.js +3 -0
  21. package/dist/element.d.ts +1 -1
  22. package/dist/element.js +19 -2
  23. package/dist/facts.d.ts +1 -1
  24. package/dist/facts.js +4 -1
  25. package/dist/flat/bodies.d.ts +11 -10
  26. package/dist/flat/bodies.js +62 -28
  27. package/dist/flat/element.d.ts +55 -16
  28. package/dist/flat/element.js +746 -86
  29. package/dist/flat/index.d.ts +4 -2
  30. package/dist/flat/index.js +5 -3
  31. package/dist/flat/look.d.ts +206 -0
  32. package/dist/flat/look.js +305 -0
  33. package/dist/flat/marks.d.ts +122 -0
  34. package/dist/flat/marks.js +60 -0
  35. package/dist/flat/scene.d.ts +119 -2
  36. package/dist/flat/scene.js +130 -2
  37. package/dist/flat/words.d.ts +16 -0
  38. package/dist/flat/words.js +74 -1
  39. package/dist/moon-catalogue.d.ts +9 -9
  40. package/dist/moon-catalogue.js +11 -10
  41. package/dist/moon-pages/element.js +0 -2
  42. package/dist/moon-pages/hero.d.ts +1 -4
  43. package/dist/moon-pages/hero.js +5 -10
  44. package/dist/portrait/model.js +3 -3
  45. package/dist/scene/body.d.ts +1 -0
  46. package/dist/scene/body.js +8 -4
  47. package/dist/scene/glsl.js +3 -1
  48. package/dist/scene/look.d.ts +15 -0
  49. package/dist/scene/look.js +19 -0
  50. package/dist/scene/name-label.d.ts +10 -0
  51. package/dist/scene/name-label.js +93 -1
  52. package/dist/scene/painter.d.ts +2 -1
  53. package/dist/scene/painter.js +8 -4
  54. package/dist/scene/textures.d.ts +2 -2
  55. package/dist/space/element.d.ts +15 -1
  56. package/dist/space/element.js +23 -1
  57. package/dist/version.d.ts +1 -1
  58. package/dist/version.js +1 -1
  59. package/package.json +1 -1
@@ -1,19 +1,22 @@
1
1
  var _a;
2
- // <wakusei-flat>: the Moon or Mars on a flat map. A canvas for the map (the body's own picture, day and night, the Sun) with the landing, rover and crash sites on it, and a canvas for the orbiters, which move over it with their coverage circles and ground tracks.
3
- // The same attributes, events and look as chikyu-earth's <chikyu-flat>, so a page can swap one for the other behind one control. Nothing runs on a timer when the clock is held, and nothing is drawn at rest, out of sight or in a hidden tab.
2
+ // <wakusei-flat>: any body the package has a picture of, on a flat map. A canvas for the map (the body's picture as a photo or as a line map, the night, the sunrise line, the Sun) with the landing, rover and crash sites and the named features on it, and a canvas for the orbiters and the page's own marks, which move over it with their coverage circles and ground tracks.
3
+ // The same attributes, events, key, look switch and credit line as chikyu-earth's <chikyu-flat>, so a page can swap one for the other behind one control. Nothing runs on a timer when the clock is held, and nothing is drawn at rest, out of sight or in a hidden tab.
4
4
  // This file registers nothing: `@johnmorrisdotca/wakusei-planets/flat/define` does.
5
5
  import { coverageAngleRad } from "../ground-track.js";
6
6
  import { orbiterElements } from "../orbiters.js";
7
7
  import { flagCodeOf, LANDING_SITES } from "../landing-sites.js";
8
8
  import { layerOf, placeRank, readPlaceLayers, readSurfaceNames } from "../place-marks.js";
9
- import { loadPlaces } from "../places.js";
9
+ import { loadPlaces, PLACE_BODIES } from "../places.js";
10
+ import { picturesCredit } from "../picture-credits.js";
10
11
  import { texturePaths } from "../scene/textures.js";
11
12
  import { BODIES } from "../facts.js";
12
13
  import { createGameClock } from "../space/clock.js";
13
14
  import { flatBody, isFlatBody, orbiterColour, orbiterName } from "./bodies.js";
14
15
  import { MAX_ZOOM, clampView, pixelsPerDegree, projectFlat, wrapLongitude, zoomAbout } from "./geometry.js";
15
- import { circleOutline, flatOrbiter, flatSun, flatTrack, shadeNight, trackPieces } from "./scene.js";
16
- import { coordinateText, say } from "./words.js";
16
+ import { MAP_LAND, MAP_LINE, MAP_SEA, creditLicence, creditWho, pictureWidth, readLook, toneMap, toneRamp } from "./look.js";
17
+ import { markName, readMarks } from "./marks.js";
18
+ import { circleOutline, flatMoonTrackHalf, flatMoonTracks, flatMoons, flatOrbiter, flatSun, flatSunRate, flatTrack, moonsOfBody, shadeNight, sunriseLine, trackPieces } from "./scene.js";
19
+ import { coordinateText, gridText, say } from "./words.js";
17
20
  const RAD = Math.PI / 180;
18
21
  const TIME_EVENT_MS = 250;
19
22
  /** How long, in real seconds, a fast clock's streak covers, and the longest it is drawn, in pixels. */
@@ -23,8 +26,6 @@ const STREAK_PX = 28;
23
26
  const TAP_SLOP = 5;
24
27
  /** The clock speed from which the map is shaded in coarser cells and the tracks are worked out less often. */
25
28
  const FAST_SPEED = 300;
26
- /** The widths of the body's pictures: the package's own two, and the sharpest, which the repository holds. */
27
- const WIDTHS = [1024, 2048];
28
29
  const escape = (text) => text.replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
29
30
  const flag = (value) => value !== null && !/^(off|false|no|0)$/i.test(value.trim());
30
31
  const finite = (value, fallback) => (value === null || value.trim() === "" || !Number.isFinite(Number(value)) ? fallback : Number(value));
@@ -87,6 +88,39 @@ canvas{position:absolute;inset:0;width:100%;height:100%;display:block}
87
88
  .flag{position:absolute;left:0;top:0;height:11px;width:16px;pointer-events:none}
88
89
  .flag:not(:defined){display:none}
89
90
  .tip .flag{position:static;display:inline-block;vertical-align:-1px;margin-right:6px}
91
+ .pair{display:inline-flex;gap:0}
92
+ .pair button:first-child{border-radius:999px 0 0 999px}
93
+ .pair button:last-child{border-radius:0 999px 999px 0;margin-left:-1px}
94
+ .legend{font-size:.85em;line-height:1.3;padding-left:var(--wakusei-flat-key-inset,0)}
95
+ .legend[hidden],.legend ul[hidden]{display:none}
96
+ .legend button{min-height:28px;padding:1px 10px;font-size:inherit}
97
+ @media (pointer:coarse){.legend button{min-height:40px}}
98
+ .legend ul{list-style:none;margin:6px 0 0;padding:0;display:flex;flex-wrap:wrap;gap:6px 16px}
99
+ .legend li{display:inline-flex;align-items:center;gap:6px}
100
+ .g{display:inline-flex;align-items:center;justify-content:center;gap:2px;flex:none;width:30px;height:20px;border-radius:4px;background:var(--wakusei-flat-sea,#0b1830)}
101
+ .g::before{content:"";display:block}
102
+ .g.sun::before{width:10px;height:10px;border-radius:50%;background:#ffd54f;box-shadow:0 0 0 1px rgba(0,0,0,.55),0 0 0 3px rgba(255,255,255,.4)}
103
+ .g.home::before{width:8px;height:8px;background:#fff;box-shadow:0 0 0 2px #0b1830;transform:rotate(45deg)}
104
+ .g.orbiter::before{width:8px;height:8px;border-radius:50%;background:#ffd23f;box-shadow:0 0 0 1px rgba(0,0,0,.8)}
105
+ .g.faint::before{width:8px;height:8px;border-radius:50%;box-sizing:border-box;border:1.6px solid #ffd23f;background:rgba(255,210,63,.35)}
106
+ .g.chosen::before{width:12px;height:12px;box-sizing:border-box;border:2px solid #fff;border-radius:50%;box-shadow:0 0 0 1px #000}
107
+ .g.footprint::before{width:16px;height:16px;box-sizing:border-box;border:1px solid rgba(255,255,255,.8);border-radius:50%;background:rgba(255,255,255,.12)}
108
+ .g.track::before{width:20px;height:0;border-top:3px solid #fff;border-radius:2px;box-shadow:0 0 0 1px rgba(0,0,0,.55)}
109
+ .g.sunrise::before{width:20px;height:0;border-top:2px solid #ffd98a;box-shadow:0 0 0 1px rgba(0,0,0,.6)}
110
+ .g.night{background:linear-gradient(90deg,#4a6a96,#05080f)}
111
+ .g.landing::before{width:7px;height:7px;background:#fff;box-shadow:0 0 0 1px #000;transform:rotate(45deg)}
112
+ .g.crash::before{content:"×";font-size:16px;line-height:1;font-weight:700;color:#ff8a65;text-shadow:0 0 2px #000,0 0 2px #000}
113
+ .g.planned::before{width:9px;height:9px;box-sizing:border-box;border:2px dashed #b9a7ff;border-radius:50%}
114
+ .g.feature::before{width:5px;height:5px;border-radius:50%;background:#fff;box-shadow:0 0 0 1px #000}
115
+ .g.picture::before{content:"©";font-size:12px;color:#fff}
116
+ .g.custom::before{width:8px;height:8px;border-radius:50%;background:var(--c,#fff);box-shadow:0 0 0 1px #000}
117
+ button.credit{position:absolute;right:8px;bottom:8px;display:block;margin:0;padding:2px 8px;min-height:0;border:0;border-radius:6px;background:rgba(8,14,28,.72);color:#fff;font-size:.7em;line-height:1.3;max-width:calc(100% - 16px);text-align:right;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
118
+ button.credit .wide,button.credit .full,button.credit[data-open] .short,button.credit[data-open] .wide{display:none}
119
+ button.credit[data-open]{white-space:normal;overflow:visible}
120
+ button.credit[data-open] .full{display:inline}
121
+ @container (min-width:600px){button.credit .short{display:none}button.credit .wide{display:inline}button.credit[data-open] .wide{display:none}}
122
+ @media (pointer:coarse){button.credit{min-height:28px;padding:4px 10px}}
123
+ .credit[hidden]{display:none}
90
124
  .sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
91
125
  `;
92
126
  /** Puts the styles in the shadow root so a strict Content-Security-Policy allows them: a constructable stylesheet is not inline markup. A browser without that gets a <style> carrying the element's `nonce`. */
@@ -134,20 +168,24 @@ function picture(url) {
134
168
  return held;
135
169
  }
136
170
  /**
137
- * The `<wakusei-flat>` custom element: the Moon or Mars on a flat map, with day and night from the Sun's direction for the time shown, the landing, rover and crash sites marked, and the spacecraft in orbit as dots that move over it. Import
171
+ * The `<wakusei-flat>` custom element: any body the package has a picture of (every planet and dwarf planet, the Moon and the other moons, Vesta) on a flat map, with day and night from the Sun's direction for the time shown, the sunrise and sunset line, the Sun's mark,
172
+ * the landing, rover and crash sites and the named features where the package has them, the spacecraft in orbit round the Moon and Mars as dots that move over it, and any marks the page adds (`setMarks`). Import
138
173
  * `@johnmorrisdotca/wakusei-planets/flat/define` to register the tag. It needs no WebGL and no peer: the map is the package's own picture of the body (the same one the 3D views are painted from), fetched from the package's CDN folder unless `texture-base` says where yours are.
174
+ * It has two looks: `photo` (the default: the picture itself) and `map` (a line map drawn from the same picture: dark tones, a line where one tone meets the next, a grid with its degrees, the names). The picture's credit is one small line at the map's bottom edge in both.
139
175
  *
140
- * Attributes (the ones marked "same" are the names and meanings `<chikyu-flat>` has): `body` (`moon`, the default, or `mars`), `center` (same: the longitude in the middle, degrees; 0, the near side or the prime meridian, by default; the map wraps round the body),
176
+ * Attributes (the ones marked "same" are the names and meanings `<chikyu-flat>` has): `body` (`moon`, the default, or any of `FLAT_BODIES`: `mars`, `jupiter`, `titan`, ...), `look` (same: `photo`, the default here, or `map`), `center` (same: the longitude in the middle, degrees; 0, the near side or the prime meridian, by default; the map wraps round the body),
141
177
  * `home-lon` and `home-lat` (same: the reader's place, a chosen site: a marker, and the "My place" button, which appear only when given),
142
- * `footprint` and `track` (same: the circle on the ground the orbiter can see, and its ground track for one trip round; the footprint and track of the chosen orbiter, or of every orbiter shown when none is chosen), `footprint-elevation` (same: degrees above the horizon the circle is drawn for; 10 by default),
178
+ * `moons` (the moons of the body, each marked over the place on the ground it is straight above, named and pressable; `all` or empty for every moon, some ids with commas, `off` or absent for none; Earth has one, Mars two, Jupiter six, Saturn nineteen, Uranus five, Neptune four, Pluto three),
179
+ * `footprint` and `track` (same, for the Moon and Mars, the bodies with orbiters: the circle on the ground the orbiter can see, and its ground track for one trip round; the footprint and track of the chosen orbiter, or of every orbiter shown when none is chosen; `track` also draws each moon's path over the ground, half a turn of the body either way), `footprint-elevation` (same: degrees above the horizon the circle is drawn for; 10 by default),
143
180
  * `paused` (same: hold the clock and keep the speed; nothing is drawn while it is held), `time` (same: `now`, an ISO date or milliseconds since 1970; live when absent), `speed` (same: 1 is real time, 0 holds, 86400 is a day a second, negative runs backwards),
144
- * `selected` (same: the chosen orbiter's id such as `lro`, or a place's id such as `moon/apollo-11-lunar-module`), `shade` (same: `off` for no night), `dot-size` (same: pixels), `controls` (same: `none`, or any of `centre zoom footprint track chips`; all by default), `lang` (same: `en` or `ja`; the page's language by default),
145
- * `orbiters` (`all`, the default, `off`, or some ids with commas: the orbiters drawn), `places` (the kinds of place marked, from `landing` (crewed, landing and rover sites), `crash` (crashes and impacts), `planned` and `feature` (named craters, seas and mountains); `landing` by default, `all` for every kind, `off` for none),
181
+ * `selected` (same: the chosen orbiter's id such as `lro`, or a place's id such as `moon/apollo-11-lunar-module`), `shade` (same: `off` for no night), `dot-size` (same: pixels), `controls` (same: `none`, or any of `centre zoom footprint track chips key look`: the buttons, filter chips, key and Map / Photo pair shown; all but `look` by default), `lang` (same: `en` or `ja`; the page's language by default),
182
+ * `orbiters` (`all`, the default, `off`, or some ids with commas: the orbiters drawn), `places` (the kinds of place marked, from `landing` (crewed, landing and rover sites), `crash` (crashes and impacts), `planned` and `feature` (named craters, seas and mountains); `landing` by default and in the photo look, `landing` and `feature` in the map look, `all` for every kind, `off` for none),
146
183
  * `names` (`off` for no names beside the marks, or the most names to show), `site-flags` (the landing sites carry their country's flag: `<hata-flag>` beside the name on the map and in the tip; the page imports `@johnmorrisdotca/hata`, and without it the name stands alone), `texture-base` and `texture-far-base` (where the body's pictures are: the package's folder on jsDelivr by default).
147
184
  *
148
- * Events (the same names as chikyu's with `wakusei-` for `chikyu-`): `wakusei-flat-pick` (an orbiter, a place of the tables (a landing, a rover, a crash, a crater, a mountain) or a landing site under the pointer, tapped, or reached by the keyboard: a `FlatPick` with `kind`, `id`, `name`, `via` and, for a place, `place` (its record) and `site` (the landing site, where it is one); `detail.id` is null when a tap lands on nothing and clears the choice), `wakusei-flat-filter` (a chip changed what is shown: `{ orbiters, layers }`),
149
- * `wakusei-flat-view` (the reader panned or zoomed: `{ center, zoom }`) and `wakusei-timechange` (`{ time, running, paused }`, at most four a second while time runs; the name the space view uses).
150
- * Style it with the custom properties `--wakusei-flat-sea`, `--wakusei-flat-aspect`, `--wakusei-flat-aspect-narrow` and `--wakusei-flat-radius`.
185
+ * Events (the same names as chikyu's with `wakusei-` for `chikyu-`): `wakusei-flat-pick` (an orbiter, a place of the tables (a landing, a rover, a crash, a crater, a mountain), a landing site or a mark the page added, under the pointer, tapped, or reached by the keyboard: a `FlatPick` with `kind`, `id`, `name`, `via` and, for a place, `place` (its record) and `site` (the landing site, where it is one), for a mark `mark` (its record, with the page's `data`); `detail.id` is null when a tap lands on nothing and clears the choice), `wakusei-flat-filter` (a chip changed what is shown: `{ orbiters, layers }`),
186
+ * `wakusei-flat-look` (the look or how it stands changed: `{ look, state }`), `wakusei-flat-view` (the reader panned or zoomed: `{ center, zoom }`) and `wakusei-timechange` (`{ time, running, paused }`, at most four a second while time runs; the name the space view uses).
187
+ * For the page's own marks: `setMarks(group, marks, label)`, `clearMarks(group?)`, the `marks` property and `groups` (the groups the key names).
188
+ * Style it with the custom properties `--wakusei-flat-sea` and `--wakusei-flat-land` (the darkest and lightest tone of the map look), `--wakusei-flat-line` (the line between tones), `--wakusei-flat-key-inset` (room kept at the left of the key, for a card lying over the map's left side), `--wakusei-flat-aspect`, `--wakusei-flat-aspect-narrow` and `--wakusei-flat-radius`.
151
189
  *
152
190
  * @example
153
191
  * ```ts no-run
@@ -162,7 +200,7 @@ function picture(url) {
162
200
  * ```
163
201
  */
164
202
  export class WakuseiFlat extends HTMLElement {
165
- static observedAttributes = ["body", "center", "home-lon", "home-lat", "time", "speed", "paused", "footprint", "track", "footprint-elevation", "selected", "shade", "dot-size", "controls", "lang", "orbiters", "places", "names", "site-flags", "texture-base", "texture-far-base"];
203
+ static observedAttributes = ["body", "look", "moons", "center", "home-lon", "home-lat", "time", "speed", "paused", "footprint", "track", "footprint-elevation", "selected", "shade", "dot-size", "controls", "lang", "orbiters", "places", "names", "site-flags", "texture-base", "texture-far-base"];
166
204
  #body = "moon";
167
205
  #info = flatBody("moon");
168
206
  #clock = createGameClock("now", 1);
@@ -175,6 +213,10 @@ export class WakuseiFlat extends HTMLElement {
175
213
  #placesFor = "";
176
214
  #layers = new Set(["landing"]);
177
215
  #showOrbiters = true;
216
+ #showMoons = false;
217
+ #moonIds = [];
218
+ #moonMarks = [];
219
+ #moonTracks;
178
220
  #orbiterIds = [];
179
221
  #footprint = false;
180
222
  #track = false;
@@ -194,6 +236,20 @@ export class WakuseiFlat extends HTMLElement {
194
236
  #viewSent = "";
195
237
  #announced = -Infinity;
196
238
  #mapKey = "";
239
+ #look = "photo";
240
+ #lookSent = "";
241
+ #tone;
242
+ #toneKey = "";
243
+ #toneFailed = false;
244
+ #sunRate = 0.004;
245
+ #placesLoaded = false;
246
+ #layersOwn = false;
247
+ #groups = new Map();
248
+ #customs = [];
249
+ #legend;
250
+ #legendKey = "";
251
+ #legendOpen = null;
252
+ #credit;
197
253
  #image;
198
254
  #imageWidth = 0;
199
255
  #imageAsked = "";
@@ -219,13 +275,92 @@ export class WakuseiFlat extends HTMLElement {
219
275
  #counts = { draws: 0, mapDraws: 0, dots: 0, lastMs: 0, maxMs: 0 };
220
276
  #measureCtx;
221
277
  // --- the page's controls ---------------------------------------------------------------------------------------------------------------------
222
- /** The body on the map: `moon` or `mars`. */
278
+ /** The body on the map: any of `FLAT_BODIES` (`moon` by default). */
223
279
  get body() {
224
280
  return this.#body;
225
281
  }
226
282
  set body(value) {
227
283
  this.setAttribute("body", value);
228
284
  }
285
+ /** The look of the map: `photo`, the body's own picture (the default), or `map`, a line map drawn from the same picture. The `look` attribute. */
286
+ get look() {
287
+ return this.#look;
288
+ }
289
+ set look(value) {
290
+ this.setAttribute("look", readLook(value));
291
+ }
292
+ /** How the look stands: `loading` (the picture is on its way; the plain ground, the grid and the marks show meanwhile), `map` or `photo` (that look is drawn) or `failed` (the picture could not be had; the plain ground, the grid and the marks stay). */
293
+ get lookState() {
294
+ if (this.#imageFailed || this.#toneFailed)
295
+ return "failed";
296
+ if (this.#look === "map")
297
+ return this.#tone !== undefined ? "map" : "loading";
298
+ return this.#image !== undefined ? "photo" : "loading";
299
+ }
300
+ /** Whether the key's list is open: what the reader chose, else open on a map 600 pixels wide or more and shut on a narrower one. Set it to fold the key from code. */
301
+ get keyOpen() {
302
+ return this.#legendIsOpen();
303
+ }
304
+ set keyOpen(value) {
305
+ this.#legendOpen = Boolean(value);
306
+ this.#syncLegend();
307
+ }
308
+ /** The page's marks, all groups together, in the order they were given. Set it to replace every group at once (a mark's own `group` names its group, `marks` the rest). */
309
+ get marks() {
310
+ return [...this.#groups.values()].flatMap((group) => group.marks);
311
+ }
312
+ set marks(list) {
313
+ this.#groups.clear();
314
+ const names = new Set(list.map((mark) => mark.group ?? "marks"));
315
+ for (const name of names)
316
+ this.#groups.set(name, { label: null, marks: readMarks(name, list.filter((mark) => (mark.group ?? "marks") === name)) });
317
+ this.#marksChanged();
318
+ }
319
+ /** The groups of the page's marks and what the key calls each: `[{ group, label, count }]`. */
320
+ get groups() {
321
+ return [...this.#groups].map(([group, held]) => ({ group, label: held.label, count: held.marks.length }));
322
+ }
323
+ /**
324
+ * Replace one group of the page's marks: points on the ground that the map draws over the picture, names when they are pointed at, pressed or reached by the keyboard, lists in the key under `label`, and sends `wakusei-flat-pick` (`kind: "mark"`) for.
325
+ * A page that moves a mark (a moon's sub-point, an orbiter) calls this again with the new places; the map draws at the next frame. An empty list or `null` takes the group away.
326
+ *
327
+ * @param group - The group's name; a mark's own `group` wins when it has one.
328
+ * @param marks - The marks of the group.
329
+ * @param label - What the key calls the group (one text, or `{ en, ja }`); the group's name when left out.
330
+ */
331
+ setMarks(group, marks, label) {
332
+ const held = marks === null ? [] : readMarks(group, marks);
333
+ if (held.length === 0)
334
+ this.#groups.delete(group);
335
+ else
336
+ this.#groups.set(group, { label: label ?? this.#groups.get(group)?.label ?? null, marks: held });
337
+ this.#marksChanged();
338
+ }
339
+ /** Take away one group of the page's marks, or all of them. */
340
+ clearMarks(group) {
341
+ if (group === undefined)
342
+ this.#groups.clear();
343
+ else
344
+ this.#groups.delete(group);
345
+ this.#marksChanged();
346
+ }
347
+ /** The page's marks and the moons the element places itself (`moons`), in one list: what is drawn, hit, reached by the keyboard and read aloud. */
348
+ #allMarks() {
349
+ return this.#moonMarks.length === 0 ? this.marks : [...this.marks, ...this.#moonMarks];
350
+ }
351
+ #marksChanged() {
352
+ const chosen = this.#selected?.kind === "mark" ? this.#selected.id : null;
353
+ if (chosen !== null && !this.#allMarks().some((mark) => mark.id === chosen))
354
+ this.#selected = null;
355
+ if (this.#hover?.kind === "mark" && !this.#allMarks().some((mark) => mark.id === this.#hover.id))
356
+ this.#hover = null;
357
+ if (this.#cursor?.kind === "mark" && !this.#allMarks().some((mark) => mark.id === this.#cursor.id))
358
+ this.#cursor = null;
359
+ this.#legendKey = "";
360
+ this.#sync();
361
+ this.#syncLegend();
362
+ this.#request();
363
+ }
229
364
  /** Whether the landing sites carry their country's flag (the attribute `site-flags`): beside the name on the map, and in the tip. The flag is `<hata-flag>` from `@johnmorrisdotca/hata`, which the page imports; where it is not defined the name stands alone. */
230
365
  get siteFlags() {
231
366
  return this.hasAttribute("site-flags");
@@ -309,20 +444,23 @@ export class WakuseiFlat extends HTMLElement {
309
444
  get layers() {
310
445
  return [...this.#layers];
311
446
  }
312
- /** Counters for a test or a page: draws of the dots, draws of the map, the orbiters drawn at the last draw, the milliseconds the last draw and the slowest took, the marks drawn, and the canvases' size in pixels. */
447
+ /** Counters for a test or a page: draws of the dots, draws of the map, the orbiters drawn at the last draw, the marks drawn (the places of the tables, and `custom` for the page's own), the milliseconds the last draw and the slowest took, whether the picture is in and which look is drawn, and the canvases' size in pixels. */
313
448
  get stats() {
314
449
  const canvases = [this.#mapCanvas, this.#dotCanvas].filter((c) => c !== undefined).map((c) => ({ width: c.width, height: c.height }));
315
- return { draws: this.#counts.draws, mapDraws: this.#counts.mapDraws, dots: this.#counts.dots, marks: this.#marks.length, lastDrawMs: this.#counts.lastMs, maxDrawMs: this.#counts.maxMs, averageDrawMs: this.#counts.draws > 0 ? this.#totalMs / this.#counts.draws : 0, running: this.#running(), paused: this.#paused, fast: this.#fast(), mapLoaded: this.#image !== undefined, canvases };
450
+ return { draws: this.#counts.draws, mapDraws: this.#counts.mapDraws, dots: this.#counts.dots, marks: this.#marks.length, custom: this.#customs.filter((one) => one.on).length, lastDrawMs: this.#counts.lastMs, maxDrawMs: this.#counts.maxMs, averageDrawMs: this.#counts.draws > 0 ? this.#totalMs / this.#counts.draws : 0, running: this.#running(), paused: this.#paused, fast: this.#fast(), mapLoaded: this.#image !== undefined, look: this.#look, lookState: this.lookState, canvases };
316
451
  }
317
- /** Where an orbiter or a place is on the screen as of the last draw, in CSS pixels from the map's top left, or null when it is not drawn (not shown, off the map, or an orbiter with no path). */
452
+ /** Where an orbiter, a place or one of the page's marks is on the screen as of the last draw, in CSS pixels from the map's top left, or null when it is not drawn (not shown, off the map, or an orbiter with no path). */
318
453
  placeOf(id) {
319
454
  const orb = this.#orbs.find((one) => one.id === id && one.on);
320
455
  if (orb)
321
456
  return { x: orb.x, y: orb.y, lon: orb.lon, lat: orb.lat, altitudeKm: orb.altitudeKm };
322
457
  const mark = this.#marks.find((one) => one.place.id === id);
323
- return mark ? { x: mark.x, y: mark.y, lon: mark.place.lon, lat: mark.place.lat, altitudeKm: null } : null;
458
+ if (mark)
459
+ return { x: mark.x, y: mark.y, lon: mark.place.lon, lat: mark.place.lat, altitudeKm: null };
460
+ const custom = this.#customs.find((one) => one.mark.id === id && one.on);
461
+ return custom ? { x: custom.x, y: custom.y, lon: custom.mark.lon, lat: custom.mark.lat, altitudeKm: null } : null;
324
462
  }
325
- /** Choose an orbiter or a place from code, as a reader's tap would, without sending `wakusei-flat-pick`. An id the map does not hold, or `null`, clears the choice. */
463
+ /** Choose an orbiter, a place or a mark from code, as a reader's tap would, without sending `wakusei-flat-pick`. An id the map does not hold, or `null`, clears the choice. */
326
464
  pick(id) {
327
465
  this.selected = id;
328
466
  }
@@ -373,13 +511,16 @@ export class WakuseiFlat extends HTMLElement {
373
511
  this.#langWatch?.disconnect();
374
512
  this.#sizer = this.#watcher = this.#langWatch = undefined;
375
513
  document.removeEventListener("visibilitychange", this.#onVisibility);
514
+ // the line map's tones are made again when the element comes back
515
+ this.#dropTone();
376
516
  }
377
517
  attributeChangedCallback(name, old, value) {
378
518
  if (!this.#connected || old === value)
379
519
  return;
380
520
  this.#read(name);
381
- if (name === "lang" || name === "controls" || name === "home-lon" || name === "home-lat" || name === "body" || name === "orbiters" || name === "places")
521
+ if (name === "lang" || name === "controls" || name === "home-lon" || name === "home-lat" || name === "body" || name === "orbiters" || name === "places" || name === "look")
382
522
  this.#words();
523
+ this.#syncLegend();
383
524
  this.#sync();
384
525
  this.#request();
385
526
  this.#schedule();
@@ -417,6 +558,9 @@ export class WakuseiFlat extends HTMLElement {
417
558
  if (next !== this.#body || this.#placesFor === "") {
418
559
  this.#body = next;
419
560
  this.#info = flatBody(next);
561
+ this.#sunRate = Math.max(1e-6, flatSunRate(next, this.#clock.advance(performance.now())));
562
+ this.#placesLoaded = false;
563
+ this.#dropTone();
420
564
  this.#selected = this.#cursor = this.#hover = null;
421
565
  this.#tracks.clear();
422
566
  this.#orbs = [];
@@ -428,12 +572,17 @@ export class WakuseiFlat extends HTMLElement {
428
572
  this.#imageWidth = 0;
429
573
  this.#imageAsked = "";
430
574
  this.#imageFailed = false;
575
+ this.#toneFailed = false;
576
+ this.#legendKey = "";
431
577
  this.#mapKey = "";
432
578
  this.#view = clampView({ ...this.#view, centerLon: finite(this.getAttribute("center"), 0), centerLat: 0, zoom: 1 });
433
579
  this.#readOrbiters();
580
+ this.#readMoons();
434
581
  this.#loadPlaces();
435
582
  }
436
583
  }
584
+ else if (name === "look")
585
+ this.#setLook(readLook(value));
437
586
  else if (name === "center") {
438
587
  const lon = finite(value, Number.NaN);
439
588
  if (Number.isFinite(lon))
@@ -442,8 +591,11 @@ export class WakuseiFlat extends HTMLElement {
442
591
  }
443
592
  else if (name === "orbiters")
444
593
  this.#readOrbiters();
594
+ else if (name === "moons")
595
+ this.#readMoons();
445
596
  else if (name === "places") {
446
- this.#layers = new Set(value === null ? ["landing"] : /^(off|none|false|0)$/i.test(value.trim()) ? [] : readPlaceLayers(value));
597
+ this.#layersOwn = value !== null;
598
+ this.#layers = this.#layersFor(value);
447
599
  this.#mapKey = "";
448
600
  }
449
601
  else if (name === "footprint")
@@ -485,6 +637,27 @@ export class WakuseiFlat extends HTMLElement {
485
637
  }
486
638
  this.#tracks.clear();
487
639
  }
640
+ /** `moons`: absent or `off` shows none (the chip turns them on), empty or `all` shows every moon of the body, or some ids with commas. A body with no moons has none whatever is asked. */
641
+ #readMoons() {
642
+ const value = this.getAttribute("moons");
643
+ const all = [...moonsOfBody(this.#body)];
644
+ if (value === null || /^(off|none|false|0)$/i.test(value.trim())) {
645
+ this.#showMoons = false;
646
+ this.#moonIds = all;
647
+ }
648
+ else if (value.trim() === "" || /^(all|on|true|1)$/i.test(value.trim())) {
649
+ this.#showMoons = all.length > 0;
650
+ this.#moonIds = all;
651
+ }
652
+ else {
653
+ const wanted = value.toLowerCase().split(/[\s,]+/).filter((one) => one !== "");
654
+ this.#moonIds = all.filter((id) => wanted.includes(id));
655
+ this.#showMoons = this.#moonIds.length > 0;
656
+ }
657
+ this.#moonMarks = [];
658
+ this.#moonTracks = undefined;
659
+ this.#legendKey = "";
660
+ }
488
661
  #readClock() {
489
662
  const now = performance.now();
490
663
  this.#clock.advance(now);
@@ -501,26 +674,43 @@ export class WakuseiFlat extends HTMLElement {
501
674
  return null;
502
675
  if (this.#info.orbiters.includes(id))
503
676
  return { kind: "orbiter", id: id };
677
+ if (this.#allMarks().some((mark) => mark.id === id))
678
+ return { kind: "mark", id };
504
679
  // a landing site's own id (`moon/apollo-11`) is its lander's place
505
680
  const place = LANDING_SITES.find((site) => site.id === id)?.place ?? id;
506
- return this.#placeIds.has(place) || /^(moon|mars)\//.test(place) ? { kind: "place", id: place } : null;
681
+ return this.#placeIds.has(place) || place.startsWith(`${this.#body}/`) ? { kind: "place", id: place } : null;
682
+ }
683
+ /** The kinds of place marked when the page names none: the sites, and in the map look the named features as well. */
684
+ #layersFor(value) {
685
+ if (value === null)
686
+ return new Set(this.#look === "map" ? ["landing", "feature"] : ["landing"]);
687
+ return new Set(/^(off|none|false|0)$/i.test(value.trim()) ? [] : readPlaceLayers(value));
507
688
  }
508
689
  #loadPlaces() {
509
690
  const body = this.#body;
510
691
  this.#placesFor = body;
511
692
  const turn = (this.#placesTurn += 1);
512
- void loadPlaces(body).then((list) => {
693
+ // a body the package holds no places for (the Earth, Uranus, Neptune, Phobos, Deimos, Phoebe) has the picture, the night and the page's own marks
694
+ const held = PLACE_BODIES.includes(body);
695
+ void (held ? loadPlaces(body) : Promise.resolve([])).then((list) => {
513
696
  if (turn !== this.#placesTurn || !this.#connected)
514
697
  return;
698
+ this.#placesLoaded = true;
515
699
  this.#places = list;
516
700
  this.#placeIds = new Map(list.map((place) => [place.id, place]));
517
701
  const wanted = this.getAttribute("selected");
518
702
  if (this.#selected === null && wanted !== null && wanted.trim() !== "")
519
703
  this.#selected = this.#find(wanted.trim());
520
704
  this.#mapKey = "";
705
+ this.#legendKey = "";
521
706
  this.#words();
522
707
  this.#request();
523
- }, () => undefined);
708
+ }, () => {
709
+ if (turn !== this.#placesTurn)
710
+ return;
711
+ this.#placesLoaded = true;
712
+ this.#words();
713
+ });
524
714
  }
525
715
  // --- the clock -------------------------------------------------------------------------------------------------------------------------------
526
716
  /** The clock is running and the element is in sight: it asks for frames. A held clock, a hidden tab and a view out of sight ask for none. */
@@ -533,13 +723,15 @@ export class WakuseiFlat extends HTMLElement {
533
723
  }
534
724
  /**
535
725
  * How often a running clock draws: as often as an orbiter (about 0.08 degree of the map a second) moves half a pixel, up to every frame, and at least once a second; once a second at most for a reader who asked for reduced motion.
536
- * With no orbiter to show, the pace of the night's edge (Mars turns 0.004 degree a second, the Moon's sunrise creeps along at 0.0001).
726
+ * With no orbiter to show, the pace of the night's edge (the Sun crosses Mars's ground at 0.004 degree a second and the Moon's at 0.0001; `flatSunRate` says for any body).
537
727
  */
538
728
  #rate() {
539
729
  const k = pixelsPerDegree(this.#view.width > 0 ? this.#view : { ...this.#view, width: 600, height: 300 });
540
730
  const dots = this.#showOrbiters && this.#orbiterIds.length > 0;
541
- let perSecond = ((dots ? 0.08 : this.#body === "mars" ? 0.0042 : 0.00015) * Math.abs(this.#speed) * k) / 0.5;
542
- perSecond = Math.min(60, Math.max(dots ? 1 : 1 / 30, perSecond));
731
+ // a moon crosses the ground more slowly than a craft and faster than the Sun
732
+ const moons = this.#showMoons && this.#moonIds.length > 0;
733
+ let perSecond = ((dots ? 0.08 : moons ? Math.max(this.#sunRate, 0.01) : this.#sunRate) * Math.abs(this.#speed) * k) / 0.5;
734
+ perSecond = Math.min(60, Math.max(dots || moons ? 1 : 1 / 30, perSecond));
543
735
  if (prefersLessMotion())
544
736
  perSecond = Math.min(perSecond, 1);
545
737
  return perSecond;
@@ -573,8 +765,7 @@ export class WakuseiFlat extends HTMLElement {
573
765
  #wantPicture() {
574
766
  if (this.#imageFailed || this.#view.width === 0)
575
767
  return;
576
- const need = 360 * pixelsPerDegree(this.#view) * this.#dpr;
577
- const width = WIDTHS.find((one) => one >= need) ?? WIDTHS[WIDTHS.length - 1];
768
+ const width = pictureWidth(this.#body, 360 * pixelsPerDegree(this.#view) * this.#dpr);
578
769
  const paths = texturePaths(this);
579
770
  const url = `${width <= 1024 ? paths.textureBase() : paths.farBase()}${this.#body}-${width}.webp`;
580
771
  // a sharper picture already held is kept; the first is asked for at once, a sharper one when the view needs it
@@ -588,7 +779,11 @@ export class WakuseiFlat extends HTMLElement {
588
779
  this.#image = image;
589
780
  this.#imageWidth = width;
590
781
  this.#mapKey = "";
591
- this.setAttribute("data-state", "ready");
782
+ this.#toneFailed = false;
783
+ if (this.#look === "map")
784
+ this.#makeTone();
785
+ this.setAttribute("data-state", this.#look === "map" && this.#tone === undefined && !this.#toneFailed ? "loading" : "ready");
786
+ this.#announceLook();
592
787
  this.#request();
593
788
  }, () => {
594
789
  if (turn !== this.#imageTurn)
@@ -599,10 +794,107 @@ export class WakuseiFlat extends HTMLElement {
599
794
  this.setAttribute("data-state", "ready");
600
795
  this.#mapKey = "";
601
796
  this.#showMessage();
797
+ this.#announceLook();
602
798
  this.#request();
603
799
  }
604
800
  });
605
801
  }
802
+ // --- the looks -------------------------------------------------------------------------------------------------------------------------------
803
+ /** Choose the look. The map look turns the picture the element already holds (or is fetching) into tones; the photo look frees them again. */
804
+ #setLook(look) {
805
+ if (look === this.#look && this.#lookSent !== "")
806
+ return;
807
+ this.#look = look;
808
+ if (!this.#layersOwn)
809
+ this.#layers = this.#layersFor(null);
810
+ if (look === "map")
811
+ this.#makeTone();
812
+ else
813
+ this.#dropTone();
814
+ this.#mapKey = "";
815
+ this.#legendKey = "";
816
+ this.#announceLook();
817
+ this.#syncLegend();
818
+ this.#request();
819
+ }
820
+ #dropTone() {
821
+ this.#tone = undefined;
822
+ this.#toneKey = "";
823
+ }
824
+ /** The line map's picture: the held picture's pixels cut into tones of equal area, with a line where one meets the next, on a canvas of its own the size of the picture. Made once for each picture and kept until the look goes back or the element leaves. */
825
+ #makeTone() {
826
+ const image = this.#image;
827
+ if (image === undefined || this.#toneKey === `${this.#body}|${this.#imageWidth}`)
828
+ return;
829
+ try {
830
+ const scratch = this.ownerDocument.createElement("canvas");
831
+ scratch.width = image.naturalWidth;
832
+ scratch.height = image.naturalHeight;
833
+ const context = scratch.getContext("2d", { willReadFrequently: true });
834
+ if (context === null)
835
+ throw new Error("no 2d canvas");
836
+ context.drawImage(image, 0, 0);
837
+ const picture = context.getImageData(0, 0, scratch.width, scratch.height);
838
+ const style = getComputedStyle(this);
839
+ const tone = (name, fallback) => {
840
+ const m = /^#([0-9a-f]{6})$/i.exec(style.getPropertyValue(name).trim());
841
+ return m ? [parseInt(m[1].slice(0, 2), 16), parseInt(m[1].slice(2, 4), 16), parseInt(m[1].slice(4, 6), 16)] : fallback;
842
+ };
843
+ const line = tone("--wakusei-flat-line", [MAP_LINE[0], MAP_LINE[1], MAP_LINE[2]]);
844
+ const pixels = toneMap(picture.data, scratch.width, scratch.height, toneRamp(tone("--wakusei-flat-sea", MAP_SEA), tone("--wakusei-flat-land", MAP_LAND)), [line[0], line[1], line[2], MAP_LINE[3]]);
845
+ const out = this.ownerDocument.createElement("canvas");
846
+ out.width = scratch.width;
847
+ out.height = scratch.height;
848
+ out.getContext("2d").putImageData(new ImageData(pixels, scratch.width, scratch.height), 0, 0);
849
+ this.#tone = out;
850
+ this.#toneKey = `${this.#body}|${this.#imageWidth}`;
851
+ this.#toneFailed = false;
852
+ }
853
+ catch {
854
+ // a picture whose pixels cannot be read (a server that sends no cross-origin header): the plain ground, the grid and the marks stay
855
+ this.#tone = undefined;
856
+ this.#toneFailed = true;
857
+ }
858
+ }
859
+ /** `wakusei-flat-look`, when the look or how it stands changes. */
860
+ #announceLook() {
861
+ const state = this.lookState;
862
+ const key = `${this.#look}/${state}`;
863
+ this.#showCredit();
864
+ this.#syncLegend();
865
+ if (key === this.#lookSent)
866
+ return;
867
+ const first = this.#lookSent === "";
868
+ this.#lookSent = key;
869
+ this.#sync();
870
+ this.#showMessage();
871
+ if (!first)
872
+ this.dispatchEvent(new CustomEvent("wakusei-flat-look", { detail: { look: this.#look, state }, bubbles: true, composed: true }));
873
+ }
874
+ /** The picture's credit, at the map's bottom edge: one small line (`Mars: NASA / USGS (public domain)`, `Mars: NASA / USGS` on a narrow map) whose whole credit is a tap away, and in the key. Both looks carry it: the line map is drawn from the picture. */
875
+ #showCredit() {
876
+ const credit = this.#credit;
877
+ if (!credit)
878
+ return;
879
+ const lang = this.language;
880
+ const words = { body: this.#nameOfBody(lang), who: creditWho(this.#body), licence: creditLicence(this.#body, lang) };
881
+ const line = this.#creditText();
882
+ credit.hidden = line === "" || this.lookState === "failed";
883
+ if (credit.hidden)
884
+ return;
885
+ const [short, wide, full] = credit.children;
886
+ short.textContent = say(lang, "creditShort", words);
887
+ wide.textContent = say(lang, "creditWide", words);
888
+ if (full.textContent !== line)
889
+ full.textContent = line;
890
+ credit.setAttribute("aria-label", line);
891
+ credit.title = line;
892
+ credit.lang = lang;
893
+ }
894
+ /** The whole credit of the body's picture, in the page's language. */
895
+ #creditText() {
896
+ return picturesCredit([this.#body], this.language);
897
+ }
606
898
  #measure() {
607
899
  const stage = this.#stage;
608
900
  if (!stage)
@@ -664,7 +956,7 @@ export class WakuseiFlat extends HTMLElement {
664
956
  const lang = this.language;
665
957
  const names = readSurfaceNames(this.getAttribute("names"));
666
958
  // the map is drawn again only when the view, the home, the marks, the picture or the Sun's place (about a quarter of a degree) changed
667
- const key = [v.width, v.height, this.#dpr, v.centerLon.toFixed(3), v.centerLat.toFixed(3), v.zoom.toFixed(3), shade ? Math.round(sun.lon * 4) : "x", shade ? Math.round(sun.lat * 4) : "x", this.#fast() ? "f" : "s", home ? `${home.lon},${home.lat}` : "", [...this.#layers].join("+"), this.#places.length, this.hasAttribute("site-flags"), names.on ? (names.limit ?? "on") : "off", lang, this.#imageWidth, this.#imageFailed].join("|");
959
+ const key = [v.width, v.height, this.#dpr, v.centerLon.toFixed(3), v.centerLat.toFixed(3), v.zoom.toFixed(3), shade ? Math.round(sun.lon * 4) : "x", shade ? Math.round(sun.lat * 4) : "x", this.#fast() ? "f" : "s", home ? `${home.lon},${home.lat}` : "", [...this.#layers].join("+"), this.#places.length, this.hasAttribute("site-flags"), names.on ? (names.limit ?? "on") : "off", lang, this.#imageWidth, this.#imageFailed, this.#look, this.#toneKey].join("|");
668
960
  if (key === this.#mapKey)
669
961
  return;
670
962
  this.#mapKey = key;
@@ -675,24 +967,28 @@ export class WakuseiFlat extends HTMLElement {
675
967
  const k = pixelsPerDegree(v);
676
968
  const wrap = 360 * k;
677
969
  ctx.setTransform(this.#dpr, 0, 0, this.#dpr, 0, 0);
678
- ctx.fillStyle = this.#info.ground;
970
+ const lines = this.#look === "map";
971
+ ctx.fillStyle = lines ? `rgb(${MAP_SEA[0]},${MAP_SEA[1]},${MAP_SEA[2]})` : this.#info.ground;
679
972
  ctx.fillRect(0, 0, v.width, v.height);
680
- // the body's picture: 360 degrees wide, drawn again a world to the left and right wherever the box is wider than the world
681
- if (this.#image) {
973
+ // the body's picture, or the line map made from it: 360 degrees wide, drawn again a world to the left and right wherever the box is wider than the world
974
+ const source = lines ? this.#tone : this.#image;
975
+ if (source) {
682
976
  ctx.imageSmoothingEnabled = true;
683
977
  ctx.imageSmoothingQuality = "high";
684
978
  const left = v.width / 2 + (-180 - v.centerLon) * k;
685
979
  const top = v.height / 2 - (90 - v.centerLat) * k;
686
980
  for (let x = left - Math.ceil(left / wrap) * wrap; x < v.width; x += wrap)
687
- ctx.drawImage(this.#image, x, top, wrap, 180 * k);
981
+ ctx.drawImage(source, x, top, wrap, 180 * k);
688
982
  }
689
983
  if (shade)
690
984
  this.#drawNight(ctx, sun);
691
- this.#drawGraticule(ctx);
692
- // the Sun overhead
985
+ this.#drawGraticule(ctx, lang);
986
+ if (shade)
987
+ this.#drawSunrise(ctx, sun);
988
+ // the Sun overhead: a yellow dot with a dark edge and a pale ring, so it reads on a pale picture and a dark one
693
989
  const at = projectFlat(v, sun.lon, sun.lat);
694
990
  for (const x of [at.x, at.x - wrap, at.x + wrap]) {
695
- if (x < -8 || x > v.width + 8)
991
+ if (x < -10 || x > v.width + 10)
696
992
  continue;
697
993
  ctx.beginPath();
698
994
  ctx.arc(x, at.y, 5, 0, Math.PI * 2);
@@ -701,6 +997,11 @@ export class WakuseiFlat extends HTMLElement {
701
997
  ctx.lineWidth = 1;
702
998
  ctx.strokeStyle = "rgba(0,0,0,.6)";
703
999
  ctx.stroke();
1000
+ ctx.beginPath();
1001
+ ctx.arc(x, at.y, 7.5, 0, Math.PI * 2);
1002
+ ctx.lineWidth = 1.5;
1003
+ ctx.strokeStyle = "rgba(255,255,255,.65)";
1004
+ ctx.stroke();
704
1005
  }
705
1006
  this.#drawMarks(ctx, names, lang);
706
1007
  if (home) {
@@ -719,7 +1020,7 @@ export class WakuseiFlat extends HTMLElement {
719
1020
  ctx.restore();
720
1021
  }
721
1022
  }
722
- this.setAttribute("data-state", this.#image || this.#imageFailed ? "ready" : "loading");
1023
+ this.setAttribute("data-state", this.lookState === "loading" ? "loading" : "ready");
723
1024
  }
724
1025
  /** The night side: the Sun's height at each cell of a grid laid over the view, turned into the night's colour and drawn over the picture, smoothed. Coarser cells at a fast clock. */
725
1026
  #drawNight(ctx, sun) {
@@ -745,30 +1046,92 @@ export class WakuseiFlat extends HTMLElement {
745
1046
  ctx.imageSmoothingEnabled = true;
746
1047
  ctx.drawImage(shade.canvas, 0, 0, columns * cell, rows * cell);
747
1048
  }
748
- #drawGraticule(ctx) {
1049
+ /** The grid of longitude and latitude: every 30 degrees on the photo, every 30, 15 or 10 on the line map (as far in as the zoom is) with its degrees written along the left and top edges. */
1050
+ #drawGraticule(ctx, lang) {
749
1051
  const v = this.#view;
750
1052
  const k = pixelsPerDegree(v);
751
1053
  const wrap = 360 * k;
1054
+ const lines = this.#look === "map";
1055
+ const step = lines ? (v.zoom >= 4 ? 10 : v.zoom >= 2 ? 15 : 30) : 30;
1056
+ const reach = lines ? 90 - step : 60;
752
1057
  ctx.lineWidth = 1;
753
1058
  ctx.beginPath();
754
- for (let lon = -180; lon < 180; lon += 30) {
1059
+ const meridians = [];
1060
+ for (let lon = -180; lon < 180; lon += step) {
755
1061
  const x0 = v.width / 2 + wrapLongitude(lon - v.centerLon) * k;
756
1062
  for (let x = x0 - Math.ceil((x0 + 1) / wrap) * wrap; x <= v.width; x += wrap) {
757
1063
  if (x < -1)
758
1064
  continue;
759
1065
  ctx.moveTo(Math.round(x) + 0.5, 0);
760
1066
  ctx.lineTo(Math.round(x) + 0.5, v.height);
1067
+ meridians.push({ x, lon });
761
1068
  }
762
1069
  }
763
- for (let lat = -60; lat <= 60; lat += 30) {
1070
+ const parallels = [];
1071
+ for (let lat = -reach; lat <= reach; lat += step) {
764
1072
  const y = Math.round(v.height / 2 - (lat - v.centerLat) * k) + 0.5;
765
1073
  if (y < 0 || y > v.height)
766
1074
  continue;
767
1075
  ctx.moveTo(0, y);
768
1076
  ctx.lineTo(v.width, y);
1077
+ parallels.push({ y, lat });
769
1078
  }
770
- ctx.strokeStyle = "rgba(170,195,230,.32)";
1079
+ ctx.strokeStyle = lines ? "rgba(190,215,245,.30)" : "rgba(170,195,230,.32)";
771
1080
  ctx.stroke();
1081
+ if (!lines)
1082
+ return;
1083
+ // the degrees, where the lines meet the map's edge, with room for each (a label that would sit on the one before is left out)
1084
+ ctx.font = "600 10px system-ui, sans-serif";
1085
+ ctx.lineJoin = "round";
1086
+ ctx.lineWidth = 3;
1087
+ ctx.strokeStyle = "rgba(4,10,22,.85)";
1088
+ ctx.fillStyle = "rgba(226,238,252,.95)";
1089
+ ctx.textBaseline = "alphabetic";
1090
+ ctx.textAlign = "left";
1091
+ for (const { y, lat } of parallels) {
1092
+ const text = gridText(lang, "lat", lat);
1093
+ ctx.strokeText(text, 4, y - 3);
1094
+ ctx.fillText(text, 4, y - 3);
1095
+ }
1096
+ ctx.textBaseline = "top";
1097
+ ctx.textAlign = "center";
1098
+ let last = -Infinity;
1099
+ for (const { x, lon } of meridians.sort((a, b) => a.x - b.x)) {
1100
+ const text = gridText(lang, "lon", lon);
1101
+ const half = ctx.measureText(text).width / 2;
1102
+ if (x - half < 2 || x + half > v.width - 2 || x - half < last + 6)
1103
+ continue;
1104
+ ctx.strokeText(text, x, 3);
1105
+ ctx.fillText(text, x, 3);
1106
+ last = x + half;
1107
+ }
1108
+ ctx.textAlign = "left";
1109
+ }
1110
+ /** The sunrise and sunset line: the circle where the Sun is on the horizon, over the night's edge, pale with a dark edge so it reads on the photo and on the line map. */
1111
+ #drawSunrise(ctx, sun) {
1112
+ const v = this.#view;
1113
+ const k = pixelsPerDegree(v);
1114
+ const wrap = 360 * k;
1115
+ const ring = sunriseLine(sun, 180);
1116
+ const base = wrapLongitude(sun.lon - v.centerLon);
1117
+ const xs = ring.map(([lon]) => v.width / 2 + (base + (lon - sun.lon)) * k);
1118
+ const ys = ring.map(([, lat]) => v.height / 2 - (lat - v.centerLat) * k);
1119
+ const lo = Math.min(...xs);
1120
+ const hi = Math.max(...xs);
1121
+ for (const pass of [0, 1]) {
1122
+ ctx.beginPath();
1123
+ for (const shift of [-wrap, 0, wrap]) {
1124
+ if (hi + shift < 0 || lo + shift > v.width)
1125
+ continue;
1126
+ xs.forEach((x, i) => (i === 0 ? ctx.moveTo(x + shift, ys[i]) : ctx.lineTo(x + shift, ys[i])));
1127
+ }
1128
+ ctx.lineJoin = "round";
1129
+ ctx.setLineDash(pass === 0 ? [] : [6, 3]);
1130
+ ctx.lineWidth = pass === 0 ? 3.4 : 1.6;
1131
+ ctx.strokeStyle = pass === 0 ? "rgba(0,0,0,.55)" : "rgba(255,226,150,.95)";
1132
+ ctx.stroke();
1133
+ }
1134
+ ctx.setLineDash([]);
772
1135
  }
773
1136
  /** The marks of the kinds on show: sites as shapes by kind, the named features as a small dot, and a name beside as many as there is room for. */
774
1137
  #drawMarks(ctx, names, lang) {
@@ -1006,9 +1369,12 @@ export class WakuseiFlat extends HTMLElement {
1006
1369
  ctx.stroke();
1007
1370
  }
1008
1371
  }
1372
+ this.#placeMoons(ms);
1373
+ this.#drawCustoms(ctx);
1009
1374
  this.#counts.draws += 1;
1010
1375
  this.#counts.dots = dots;
1011
1376
  this.#placeMarks();
1377
+ this.#syncLegend();
1012
1378
  this.#showMessage();
1013
1379
  const took = performance.now() - started;
1014
1380
  this.#lastDraw = started;
@@ -1020,6 +1386,140 @@ export class WakuseiFlat extends HTMLElement {
1020
1386
  this.#announceTime(ms);
1021
1387
  this.#schedule();
1022
1388
  }
1389
+ /** The moons of the body, as marks over the place on the ground each is straight above, worked out for the moment drawn: named, pressable, in the key as a group of their own. None unless `moons` (or the chip) asks. */
1390
+ #placeMoons(ms) {
1391
+ if (!this.#showMoons || this.#moonIds.length === 0) {
1392
+ if (this.#moonMarks.length > 0) {
1393
+ this.#moonMarks = [];
1394
+ this.#legendKey = "";
1395
+ }
1396
+ return;
1397
+ }
1398
+ const before = this.#moonMarks.length;
1399
+ this.#moonMarks = flatMoons(this.#body, ms)
1400
+ .filter((moon) => this.#moonIds.includes(moon.id))
1401
+ .map((moon) => ({ id: moon.id, lat: moon.lat, lon: moon.lon, name: BODIES[moon.id].name, group: "moons", shape: "dot", colour: BODIES[moon.id].colour, size: 4.5, labelled: true, data: { moon: moon.id, distanceKm: moon.distanceKm } }));
1402
+ if (before !== this.#moonMarks.length)
1403
+ this.#legendKey = "";
1404
+ }
1405
+ /** The tracks of the moons over the ground (half a turn of the body either way), worked out again when the clock has moved a fortieth of that. */
1406
+ #moonTrackOf(ms) {
1407
+ const half = flatMoonTrackHalf(this.#body);
1408
+ const every = Math.max((half * 2) / 40, this.#fast() ? Math.abs(this.#speed) * 1000 : 0);
1409
+ const key = `${this.#body}|${Math.round(ms / every)}|${this.#moonIds.join()}`;
1410
+ if (this.#moonTracks && this.#moonTracks.key === key)
1411
+ return this.#moonTracks;
1412
+ const past = new Map();
1413
+ const future = new Map();
1414
+ for (const [id, points] of flatMoonTracks(this.#body, ms, 48)) {
1415
+ if (!this.#moonIds.includes(id))
1416
+ continue;
1417
+ past.set(id, trackPieces(points.filter((p) => p.ms <= ms)));
1418
+ future.set(id, trackPieces(points.filter((p) => p.ms >= ms)));
1419
+ }
1420
+ return (this.#moonTracks = { key, past, future });
1421
+ }
1422
+ /** The page's own marks (`setMarks`): each in its shape and colour with a dark rim, and its name beside it when the page asked for that and there is room. They are drawn with the dots so a page that moves them sees them at the next frame. */
1423
+ #drawCustoms(ctx) {
1424
+ const lang = this.language;
1425
+ const v = this.#view;
1426
+ const customs = [];
1427
+ for (const mark of this.#allMarks()) {
1428
+ const at = this.#screen(mark.lon, mark.lat, mark.size + 2);
1429
+ customs.push({ mark, x: at?.x ?? 0, y: at?.y ?? 0, on: at !== null });
1430
+ }
1431
+ this.#customs = customs;
1432
+ if (customs.length === 0)
1433
+ return;
1434
+ const boxes = [];
1435
+ const labels = [];
1436
+ ctx.font = "600 11px system-ui, sans-serif";
1437
+ ctx.textBaseline = "middle";
1438
+ for (const { mark, x, y, on } of customs) {
1439
+ if (!on)
1440
+ continue;
1441
+ const colour = mark.colour ?? "#ffffff";
1442
+ const r = mark.size;
1443
+ ctx.save();
1444
+ ctx.translate(x, y);
1445
+ ctx.lineJoin = "round";
1446
+ ctx.lineWidth = 1.6;
1447
+ ctx.strokeStyle = "rgba(0,0,0,.85)";
1448
+ ctx.fillStyle = colour;
1449
+ if (mark.shape === "dot") {
1450
+ ctx.beginPath();
1451
+ ctx.arc(0, 0, r, 0, Math.PI * 2);
1452
+ ctx.fill();
1453
+ ctx.stroke();
1454
+ }
1455
+ else if (mark.shape === "ring") {
1456
+ ctx.beginPath();
1457
+ ctx.arc(0, 0, r, 0, Math.PI * 2);
1458
+ ctx.lineWidth = 4;
1459
+ ctx.stroke();
1460
+ ctx.lineWidth = 2;
1461
+ ctx.strokeStyle = colour;
1462
+ ctx.stroke();
1463
+ }
1464
+ else if (mark.shape === "diamond" || mark.shape === "square") {
1465
+ if (mark.shape === "diamond")
1466
+ ctx.rotate(Math.PI / 4);
1467
+ const side = mark.shape === "diamond" ? r * 0.85 : r;
1468
+ ctx.strokeRect(-side, -side, side * 2, side * 2);
1469
+ ctx.fillRect(-side, -side, side * 2, side * 2);
1470
+ }
1471
+ else if (mark.shape === "cross") {
1472
+ ctx.beginPath();
1473
+ ctx.moveTo(-r, -r);
1474
+ ctx.lineTo(r, r);
1475
+ ctx.moveTo(r, -r);
1476
+ ctx.lineTo(-r, r);
1477
+ ctx.lineWidth = 4.4;
1478
+ ctx.stroke();
1479
+ ctx.lineWidth = 2.2;
1480
+ ctx.strokeStyle = colour;
1481
+ ctx.stroke();
1482
+ }
1483
+ else {
1484
+ ctx.beginPath();
1485
+ for (let i = 0; i < 10; i += 1) {
1486
+ const radius = i % 2 === 0 ? r * 1.35 : r * 0.55;
1487
+ const angle = -Math.PI / 2 + (i * Math.PI) / 5;
1488
+ if (i === 0)
1489
+ ctx.moveTo(Math.cos(angle) * radius, Math.sin(angle) * radius);
1490
+ else
1491
+ ctx.lineTo(Math.cos(angle) * radius, Math.sin(angle) * radius);
1492
+ }
1493
+ ctx.closePath();
1494
+ ctx.fill();
1495
+ ctx.stroke();
1496
+ }
1497
+ ctx.restore();
1498
+ boxes.push({ x0: x - r - 1, y0: y - r - 1, x1: x + r + 1, y1: y + r + 1 });
1499
+ if (mark.labelled === true) {
1500
+ const text = markName(mark.name, lang);
1501
+ const width = this.#measureText(text);
1502
+ const right = { x0: x + r + 4, y0: y - 7, x1: x + r + 4 + width, y1: y + 7 };
1503
+ const left = { x0: x - r - 4 - width, y0: y - 7, x1: x - r - 4, y1: y + 7 };
1504
+ const fits = (b) => b.x0 >= 0 && b.x1 <= v.width && !boxes.some((o) => b.x0 < o.x1 && b.x1 > o.x0 && b.y0 < o.y1 && b.y1 > o.y0);
1505
+ const where = fits(right) ? right : fits(left) ? left : null;
1506
+ if (where !== null) {
1507
+ boxes.push(where);
1508
+ labels.push({ text, x: where === right ? where.x0 : where.x1, y, align: where === right ? "left" : "right" });
1509
+ }
1510
+ }
1511
+ }
1512
+ ctx.lineWidth = 3;
1513
+ ctx.lineJoin = "round";
1514
+ ctx.strokeStyle = "rgba(0,0,0,.72)";
1515
+ ctx.fillStyle = "#fff";
1516
+ for (const label of labels) {
1517
+ ctx.textAlign = label.align;
1518
+ ctx.strokeText(label.text, label.x, label.y);
1519
+ ctx.fillText(label.text, label.x, label.y);
1520
+ }
1521
+ ctx.textAlign = "left";
1522
+ }
1023
1523
  /** The coverage circles and the ground tracks, drawn before the dots so the dots lie on them. */
1024
1524
  #drawOver(ctx, orbs, chosen, ms) {
1025
1525
  const v = this.#view;
@@ -1066,40 +1566,56 @@ export class WakuseiFlat extends HTMLElement {
1066
1566
  }
1067
1567
  }
1068
1568
  }
1569
+ const chosenMoon = this.#selected?.kind === "mark" ? this.#moonMarks.find((one) => one.id === this.#selected.id) : undefined;
1069
1570
  if (this.#track || chosen) {
1070
1571
  for (const o of this.#track ? orbs : chosen ? [chosen] : []) {
1071
1572
  const lines = this.#trackOf(o.id, ms);
1072
1573
  const strong = chosen !== undefined && o.id === chosen.id;
1073
- const draw = (pieces, dash) => {
1074
- if (pieces.length === 0)
1075
- return;
1076
- for (const pass of strong ? [0, 1] : [1]) {
1077
- ctx.beginPath();
1078
- for (const [a, b] of pieces) {
1079
- const xa = v.width / 2 + wrapLongitude(a.lon - v.centerLon) * k;
1080
- const xb = xa + (b.lon - a.lon) * k;
1081
- const ya = v.height / 2 - (a.lat - v.centerLat) * k;
1082
- const yb = v.height / 2 - (b.lat - v.centerLat) * k;
1083
- for (const shift of [-wrap, 0, wrap]) {
1084
- if (Math.max(xa, xb) + shift < -2 || Math.min(xa, xb) + shift > v.width + 2)
1085
- continue;
1086
- ctx.moveTo(xa + shift, ya);
1087
- ctx.lineTo(xb + shift, yb);
1088
- }
1089
- }
1090
- ctx.setLineDash(dash ? [4, 4] : []);
1091
- ctx.lineWidth = pass === 0 ? 4 : strong ? 1.8 : 1.2;
1092
- ctx.strokeStyle = pass === 0 ? "rgba(0,0,0,.55)" : strong ? "#ffffff" : o.colour;
1093
- ctx.globalAlpha = strong || pass === 0 ? 1 : dash ? 0.5 : 0.85;
1094
- ctx.stroke();
1095
- }
1096
- };
1097
- draw(lines.past, true);
1098
- draw(lines.future, false);
1099
- ctx.setLineDash([]);
1100
- ctx.globalAlpha = 1;
1574
+ this.#strokePieces(ctx, lines.past, o.colour, strong, true);
1575
+ this.#strokePieces(ctx, lines.future, o.colour, strong, false);
1576
+ }
1577
+ }
1578
+ // the moons' tracks: every moon shown with `track` on, or the chosen moon's alone
1579
+ if (this.#moonMarks.length > 0 && (this.#track || chosenMoon !== undefined)) {
1580
+ const tracks = this.#moonTrackOf(ms);
1581
+ for (const moon of this.#moonMarks) {
1582
+ if (!this.#track && moon.id !== chosenMoon?.id)
1583
+ continue;
1584
+ const strong = moon.id === chosenMoon?.id;
1585
+ this.#strokePieces(ctx, tracks.past.get(moon.id) ?? [], moon.colour ?? "#ffffff", strong, true);
1586
+ this.#strokePieces(ctx, tracks.future.get(moon.id) ?? [], moon.colour ?? "#ffffff", strong, false);
1587
+ }
1588
+ }
1589
+ }
1590
+ /** A track's pieces in a colour, over a dark edge: dashed behind the thing, solid ahead; the chosen one white and thick. Each piece is drawn a world to the left and right as well. */
1591
+ #strokePieces(ctx, pieces, colour, strong, dash) {
1592
+ if (pieces.length === 0)
1593
+ return;
1594
+ const v = this.#view;
1595
+ const k = pixelsPerDegree(v);
1596
+ const wrap = 360 * k;
1597
+ for (const pass of strong ? [0, 1] : [1]) {
1598
+ ctx.beginPath();
1599
+ for (const [a, b] of pieces) {
1600
+ const xa = v.width / 2 + wrapLongitude(a.lon - v.centerLon) * k;
1601
+ const xb = xa + (b.lon - a.lon) * k;
1602
+ const ya = v.height / 2 - (a.lat - v.centerLat) * k;
1603
+ const yb = v.height / 2 - (b.lat - v.centerLat) * k;
1604
+ for (const shift of [-wrap, 0, wrap]) {
1605
+ if (Math.max(xa, xb) + shift < -2 || Math.min(xa, xb) + shift > v.width + 2)
1606
+ continue;
1607
+ ctx.moveTo(xa + shift, ya);
1608
+ ctx.lineTo(xb + shift, yb);
1609
+ }
1101
1610
  }
1611
+ ctx.setLineDash(dash ? [4, 4] : []);
1612
+ ctx.lineWidth = pass === 0 ? 4 : strong ? 1.8 : 1.2;
1613
+ ctx.strokeStyle = pass === 0 ? "rgba(0,0,0,.55)" : strong ? "#ffffff" : colour;
1614
+ ctx.globalAlpha = strong || pass === 0 ? 1 : dash ? 0.5 : 0.85;
1615
+ ctx.stroke();
1102
1616
  }
1617
+ ctx.setLineDash([]);
1618
+ ctx.globalAlpha = 1;
1103
1619
  }
1104
1620
  /** An orbiter's ground track for one trip round, half behind it and half ahead, worked out again when the clock has moved a fortieth of a trip (and, at a fast clock, a real second). */
1105
1621
  #trackOf(id, ms) {
@@ -1132,6 +1648,10 @@ export class WakuseiFlat extends HTMLElement {
1132
1648
  const o = this.#orbs.find((one) => one.id === item.id);
1133
1649
  return o?.on ? { x: o.x, y: o.y } : null;
1134
1650
  }
1651
+ if (item.kind === "mark") {
1652
+ const custom = this.#customs.find((one) => one.mark.id === item.id);
1653
+ return custom?.on ? { x: custom.x, y: custom.y } : null;
1654
+ }
1135
1655
  const mark = this.#marks.find((one) => one.place.id === item.id);
1136
1656
  return mark ? { x: mark.x, y: mark.y } : null;
1137
1657
  }
@@ -1194,6 +1714,12 @@ export class WakuseiFlat extends HTMLElement {
1194
1714
  const o = this.#orbs.find((one) => one.id === item.id);
1195
1715
  return say(lang, "announceOrbiter", { name: orbiterName(item.id, lang), body: this.#nameOfBody(lang), altitude: o ? Math.round(o.altitudeKm).toLocaleString(lang) : "", note: o?.dim ? say(lang, "approximate") : "" });
1196
1716
  }
1717
+ if (item.kind === "mark") {
1718
+ const mark = this.#allMarks().find((one) => one.id === item.id);
1719
+ if (mark?.group === "moons" && mark.data !== undefined)
1720
+ return say(lang, "announceMoon", { name: markName(mark.name, lang), body: this.#nameOfBody(lang), lat: coordinateText(lang, "lat", mark.lat), lon: coordinateText(lang, "lon", mark.lon), km: Math.round(mark.data.distanceKm).toLocaleString(lang) });
1721
+ return mark ? say(lang, "announceMark", { name: markName(mark.name, lang), lat: coordinateText(lang, "lat", mark.lat), lon: coordinateText(lang, "lon", mark.lon) }) : item.id;
1722
+ }
1197
1723
  const place = this.#placeIds.get(item.id);
1198
1724
  if (!place)
1199
1725
  return item.id;
@@ -1203,7 +1729,7 @@ export class WakuseiFlat extends HTMLElement {
1203
1729
  const msg = this.#msg;
1204
1730
  if (!msg)
1205
1731
  return;
1206
- msg.textContent = this.#imageFailed ? say(this.language, "mapMissing") : "";
1732
+ msg.textContent = this.#imageFailed || this.#toneFailed ? say(this.language, "mapMissing") : "";
1207
1733
  }
1208
1734
  #build(root) {
1209
1735
  const d = root.ownerDocument;
@@ -1226,9 +1752,19 @@ export class WakuseiFlat extends HTMLElement {
1226
1752
  const help = Object.assign(d.createElement("p"), { className: "sr", id: "help" });
1227
1753
  dots.setAttribute("aria-describedby", "help live");
1228
1754
  const flagLayer = Object.assign(d.createElement("div"), { className: "flags", hidden: true });
1229
- stage.append(map, flagLayer, dots, selRing, hovRing, tip, msg);
1755
+ const credit = Object.assign(d.createElement("button"), { className: "credit", type: "button", hidden: true });
1756
+ for (const name of ["short", "wide", "full"])
1757
+ credit.append(Object.assign(d.createElement("span"), { className: name }));
1758
+ credit.setAttribute("aria-expanded", "false");
1759
+ credit.addEventListener("click", () => credit.setAttribute("aria-expanded", String(credit.toggleAttribute("data-open"))));
1760
+ const legend = Object.assign(d.createElement("div"), { className: "legend", hidden: true });
1761
+ legend.setAttribute("role", "group");
1762
+ legend.addEventListener("click", this.#onLegend);
1763
+ stage.append(map, flagLayer, dots, selRing, hovRing, tip, credit, msg);
1230
1764
  this.#flagLayer = flagLayer;
1231
- root.append(bar, stage, live, help);
1765
+ this.#credit = credit;
1766
+ this.#legend = legend;
1767
+ root.append(bar, stage, legend, live, help);
1232
1768
  this.#bar = bar;
1233
1769
  this.#stage = stage;
1234
1770
  this.#mapCanvas = map;
@@ -1257,7 +1793,7 @@ export class WakuseiFlat extends HTMLElement {
1257
1793
  const raw = (this.getAttribute("controls") ?? "").trim().toLowerCase();
1258
1794
  if (raw === "none" || raw === "off")
1259
1795
  return new Set();
1260
- const all = ["centre", "zoom", "footprint", "track", "chips"];
1796
+ const all = ["centre", "zoom", "footprint", "track", "chips", "key"];
1261
1797
  if (raw === "" || raw === "all")
1262
1798
  return new Set(all);
1263
1799
  return new Set(raw.split(/[\s,]+/).map((one) => (one === "center" ? "centre" : one)));
@@ -1282,12 +1818,18 @@ export class WakuseiFlat extends HTMLElement {
1282
1818
  if (Number.isFinite(finite(this.getAttribute("home-lon"), Number.NaN)))
1283
1819
  first.push(button("home", say(lang, "myPlace"), ` aria-label="${escape(say(lang, "centreHome"))}" aria-pressed="false"`));
1284
1820
  }
1821
+ // the look's own pair of buttons, beside the centre buttons: not among the defaults, so a page that has not asked for it sees no new button
1822
+ if (wants.has("look"))
1823
+ first.push(`<span class="pair" role="group" aria-label="${escape(say(lang, "lookGroup"))}">${button("look-map", say(lang, "lookMap"), ` aria-pressed="false"`)}${button("look-photo", say(lang, "lookPhoto"), ` aria-pressed="false"`)}</span>`);
1285
1824
  first.push(`<span class="gap"></span>`);
1286
1825
  if (wants.has("zoom"))
1287
1826
  first.push(button("zoomout", "−", ` aria-label="${escape(say(lang, "zoomOut"))}"`), button("zoomin", "+", ` aria-label="${escape(say(lang, "zoomIn"))}"`));
1288
- if (wants.has("footprint"))
1827
+ // a footprint and a ground track belong to an orbiter: a body with none has neither button
1828
+ const craft = this.#info.orbiters.some((id) => orbiterElements(id) !== undefined);
1829
+ const moons = moonsOfBody(this.#body).length;
1830
+ if (wants.has("footprint") && craft)
1289
1831
  first.push(button("footprint", say(lang, "footprint"), ` aria-pressed="false"`));
1290
- if (wants.has("track"))
1832
+ if (wants.has("track") && (craft || moons > 0))
1291
1833
  first.push(button("track", say(lang, "groundTrack"), ` aria-pressed="false"`));
1292
1834
  if (first.length > 1)
1293
1835
  rows.push(`<div class="row">${first.join("")}</div>`);
@@ -1296,17 +1838,24 @@ export class WakuseiFlat extends HTMLElement {
1296
1838
  for (const place of this.#places)
1297
1839
  counts.set(layerOf(place.kind), (counts.get(layerOf(place.kind)) ?? 0) + 1);
1298
1840
  const chip = (act, key, label, n) => `<button type="button" class="chip" data-act="layer" data-layer="${act}" aria-pressed="false"><span class="swatch" data-key="${key}"></span>${escape(label)} <span class="n">${n.toLocaleString(lang)}</span></button>`;
1299
- const chips = [chip("orbiters", "orbiters", say(lang, "orbiters"), this.#info.orbiters.filter((id) => orbiterElements(id) !== undefined).length)];
1841
+ const chips = craft ? [chip("orbiters", "orbiters", say(lang, "orbiters"), this.#info.orbiters.filter((id) => orbiterElements(id) !== undefined).length)] : [];
1842
+ if (moons > 0)
1843
+ chips.push(chip("moons", "moons", say(lang, "moons"), moons));
1844
+ // while a body's places are on their way every chip is there (so the row does not jump); once they are in, only the kinds the body has
1845
+ const waiting = !this.#placesLoaded && PLACE_BODIES.includes(this.#body);
1300
1846
  for (const layer of ["landing", "crash", "planned", "feature"])
1301
- if ((counts.get(layer) ?? 0) > 0 || this.#places.length === 0)
1847
+ if ((counts.get(layer) ?? 0) > 0 || waiting)
1302
1848
  chips.push(chip(layer, LAYER_WORD[layer], say(lang, layer), counts.get(layer) ?? 0));
1303
- rows.push(`<div class="row chips" role="group" aria-label="${escape(say(lang, "layersFilter"))}">${chips.join("")}</div>`);
1849
+ if (chips.length > 0)
1850
+ rows.push(`<div class="row chips" role="group" aria-label="${escape(say(lang, "layersFilter"))}">${chips.join("")}</div>`);
1304
1851
  }
1305
1852
  bar.innerHTML = rows.join("");
1853
+ this.#showCredit();
1306
1854
  // colours go on through the CSS object model: an inline style attribute in the markup would be refused by a strict Content-Security-Policy
1307
- const swatches = { orbiters: "#ffd23f", landing: "#ffffff", crash: "#ff8a65", planned: "#b9a7ff", feature: "#9aa5b1" };
1855
+ const swatches = { orbiters: "#ffd23f", moons: "#b8e986", landing: "#ffffff", crash: "#ff8a65", planned: "#b9a7ff", feature: "#9aa5b1" };
1308
1856
  bar.querySelectorAll(".swatch").forEach((swatch) => swatch.style.setProperty("--c", swatches[swatch.dataset["key"] ?? ""] ?? "#9aa5b1"));
1309
1857
  this.#sync();
1858
+ this.#syncLegend();
1310
1859
  }
1311
1860
  /** Bring the pressed states of the buttons and chips up to date without making them again (a reader may be using one). */
1312
1861
  #sync() {
@@ -1316,11 +1865,13 @@ export class WakuseiFlat extends HTMLElement {
1316
1865
  const home = finite(this.getAttribute("home-lon"), Number.NaN);
1317
1866
  bar.querySelectorAll('[data-act="centre"]').forEach((b) => b.setAttribute("aria-pressed", String(Math.abs(wrapLongitude(this.#view.centerLon - Number(b.dataset["lon"]))) < 0.5)));
1318
1867
  bar.querySelectorAll('[data-act="home"]').forEach((b) => b.setAttribute("aria-pressed", String(Number.isFinite(home) && Math.abs(wrapLongitude(this.#view.centerLon - home)) < 0.5)));
1868
+ bar.querySelectorAll('[data-act="look-map"]').forEach((b) => b.setAttribute("aria-pressed", String(this.#look === "map")));
1869
+ bar.querySelectorAll('[data-act="look-photo"]').forEach((b) => b.setAttribute("aria-pressed", String(this.#look === "photo")));
1319
1870
  bar.querySelectorAll('[data-act="footprint"]').forEach((b) => b.setAttribute("aria-pressed", String(this.#footprint)));
1320
1871
  bar.querySelectorAll('[data-act="track"]').forEach((b) => b.setAttribute("aria-pressed", String(this.#track)));
1321
1872
  bar.querySelectorAll('[data-act="layer"]').forEach((b) => {
1322
1873
  const layer = b.dataset["layer"];
1323
- b.setAttribute("aria-pressed", String(layer === "orbiters" ? this.#showOrbiters : this.#layers.has(layer)));
1874
+ b.setAttribute("aria-pressed", String(layer === "orbiters" ? this.#showOrbiters : layer === "moons" ? this.#showMoons : this.#layers.has(layer)));
1324
1875
  });
1325
1876
  bar.querySelector('[data-act="zoomin"]')?.toggleAttribute("disabled", this.#view.zoom >= MAX_ZOOM);
1326
1877
  bar.querySelector('[data-act="zoomout"]')?.toggleAttribute("disabled", this.#view.zoom <= 1);
@@ -1343,6 +1894,10 @@ export class WakuseiFlat extends HTMLElement {
1343
1894
  this.#setView(zoomAbout(v, 1.6));
1344
1895
  else if (act === "zoomout")
1345
1896
  this.#setView(zoomAbout(v, 1 / 1.6));
1897
+ else if (act === "look-map" || act === "look-photo") {
1898
+ // the attribute is the look: the page that set the controls sees the change as it sees any other
1899
+ this.setAttribute("look", act === "look-photo" ? "photo" : "map");
1900
+ }
1346
1901
  else if (act === "footprint") {
1347
1902
  this.#footprint = !this.#footprint;
1348
1903
  this.#sync();
@@ -1358,6 +1913,13 @@ export class WakuseiFlat extends HTMLElement {
1358
1913
  const layer = target.dataset["layer"];
1359
1914
  if (layer === "orbiters")
1360
1915
  this.#showOrbiters = !this.#showOrbiters;
1916
+ else if (layer === "moons") {
1917
+ this.#showMoons = !this.#showMoons;
1918
+ if (!this.#showMoons && this.#selected?.kind === "mark" && this.#moonMarks.some((one) => one.id === this.#selected.id))
1919
+ this.#selected = null;
1920
+ if (!this.#showMoons)
1921
+ this.#moonMarks = [];
1922
+ }
1361
1923
  else if (this.#layers.has(layer))
1362
1924
  this.#layers.delete(layer);
1363
1925
  else
@@ -1367,13 +1929,92 @@ export class WakuseiFlat extends HTMLElement {
1367
1929
  this.#selected = null;
1368
1930
  if (this.#selected?.kind === "orbiter" && !this.#showOrbiters)
1369
1931
  this.#selected = null;
1932
+ this.#layersOwn = true;
1370
1933
  this.#mapKey = "";
1371
1934
  this.#sync();
1372
1935
  this.#request();
1373
1936
  this.#schedule();
1374
- this.dispatchEvent(new CustomEvent("wakusei-flat-filter", { detail: { orbiters: this.#showOrbiters, layers: [...this.#layers] }, bubbles: true, composed: true }));
1937
+ this.dispatchEvent(new CustomEvent("wakusei-flat-filter", { detail: { orbiters: this.#showOrbiters, moons: this.#showMoons, layers: [...this.#layers] }, bubbles: true, composed: true }));
1375
1938
  }
1376
1939
  };
1940
+ /** The key under the map: every mark the map draws now, each with the picture of it and its name. Made again only when what is drawn, the words or the fold change. What is not drawn is not in it. */
1941
+ #syncLegend() {
1942
+ const box = this.#legend;
1943
+ if (!box)
1944
+ return;
1945
+ const lang = this.language;
1946
+ const wants = this.#wants().has("key");
1947
+ box.hidden = !wants;
1948
+ if (!wants)
1949
+ return;
1950
+ const open = this.#legendIsOpen();
1951
+ const shade = this.getAttribute("shade") !== "off";
1952
+ const entries = [];
1953
+ if (shade)
1954
+ entries.push({ glyph: "sun", text: say(lang, "keySun") }, { glyph: "sunrise", text: say(lang, "keySunrise") }, { glyph: "night", text: say(lang, "keyNight") });
1955
+ if (this.#home())
1956
+ entries.push({ glyph: "home", text: say(lang, "keyHome") });
1957
+ if (this.#showOrbiters && this.#orbs.some((o) => o.on))
1958
+ entries.push({ glyph: "orbiter", text: say(lang, "keyOrbiter") });
1959
+ if (this.#showOrbiters && this.#orbs.some((o) => o.on && o.dim))
1960
+ entries.push({ glyph: "faint", text: say(lang, "keyOrbiterApprox") });
1961
+ if (this.#selected !== null)
1962
+ entries.push({ glyph: "chosen", text: say(lang, "keyRing") });
1963
+ if (this.#footprint && this.#orbs.some((o) => o.on))
1964
+ entries.push({ glyph: "footprint", text: say(lang, "keyFootprint") });
1965
+ if (this.#track && this.#orbs.some((o) => o.on))
1966
+ entries.push({ glyph: "track", text: say(lang, "keyTrack") });
1967
+ if (this.#moonMarks.length > 0)
1968
+ entries.push({ glyph: "custom", text: say(lang, "keyMoon"), colour: this.#moonMarks[0].colour ?? "#ffffff" });
1969
+ if (this.#track && this.#moonMarks.length > 0)
1970
+ entries.push({ glyph: "track", text: say(lang, "keyMoonTrack") });
1971
+ for (const layer of this.#layers)
1972
+ if (this.#marks.some((m) => m.layer === layer))
1973
+ entries.push({ glyph: layer, text: say(lang, layer) });
1974
+ for (const [group, held] of this.#groups)
1975
+ entries.push({ glyph: "custom", text: markName(held.label ?? group, lang), colour: held.marks[0]?.colour ?? "#ffffff" });
1976
+ const credit = this.#creditText();
1977
+ if (credit !== "")
1978
+ entries.push({ glyph: "picture", text: credit });
1979
+ const key = JSON.stringify([lang, open, entries]);
1980
+ if (key === this.#legendKey)
1981
+ return;
1982
+ this.#legendKey = key;
1983
+ const d = box.ownerDocument;
1984
+ const toggle = d.createElement("button");
1985
+ toggle.type = "button";
1986
+ toggle.dataset["act"] = "key";
1987
+ toggle.setAttribute("aria-expanded", String(open));
1988
+ toggle.setAttribute("aria-controls", "legend-list");
1989
+ toggle.setAttribute("aria-label", say(lang, open ? "keyHide" : "keyShow"));
1990
+ toggle.textContent = `${say(lang, "key")} ${open ? "▾" : "▸"}`;
1991
+ const list = d.createElement("ul");
1992
+ list.id = "legend-list";
1993
+ list.setAttribute("aria-label", say(lang, "keyMarks"));
1994
+ list.hidden = !open;
1995
+ for (const entry of entries) {
1996
+ const item = d.createElement("li");
1997
+ const glyph = d.createElement("span");
1998
+ glyph.className = `g ${entry.glyph}`;
1999
+ glyph.setAttribute("aria-hidden", "true");
2000
+ if (entry.colour !== undefined)
2001
+ glyph.style.setProperty("--c", entry.colour);
2002
+ item.append(glyph, entry.text);
2003
+ list.append(item);
2004
+ }
2005
+ box.replaceChildren(toggle, list);
2006
+ box.lang = lang;
2007
+ }
2008
+ /** Whether the key's list is open: what the reader chose, else open on a wide map and shut on a narrow one. */
2009
+ #legendIsOpen() {
2010
+ return this.#legendOpen ?? this.#view.width >= 600;
2011
+ }
2012
+ #onLegend = (event) => {
2013
+ if (!event.target?.closest("button[data-act=key]"))
2014
+ return;
2015
+ this.keyOpen = !this.#legendIsOpen();
2016
+ this.#legend?.querySelector("button[data-act=key]")?.focus();
2017
+ };
1377
2018
  #setView(view) {
1378
2019
  this.#view = clampView(view);
1379
2020
  this.#mapKey = "";
@@ -1412,6 +2053,15 @@ export class WakuseiFlat extends HTMLElement {
1412
2053
  best = { kind: "orbiter", id: o.id };
1413
2054
  }
1414
2055
  }
2056
+ for (const c of this.#customs) {
2057
+ if (!c.on)
2058
+ continue;
2059
+ const d = (c.x - x) ** 2 + (c.y - y) ** 2 - 12;
2060
+ if (d <= gap) {
2061
+ gap = d;
2062
+ best = { kind: "mark", id: c.mark.id };
2063
+ }
2064
+ }
1415
2065
  for (const mark of this.#marks) {
1416
2066
  const d = (mark.x - x) ** 2 + (mark.y - y) ** 2;
1417
2067
  if (d <= gap) {
@@ -1429,6 +2079,10 @@ export class WakuseiFlat extends HTMLElement {
1429
2079
  const o = this.#orbs.find((one) => one.id === item.id);
1430
2080
  detail = { kind: "orbiter", id: item.id, name: orbiterName(item.id, this.language), body: this.#body, lat: o?.lat ?? null, lon: o?.lon ?? null, altitudeKm: o?.altitudeKm ?? null, status: o?.status ?? null, placeKind: null, via };
1431
2081
  }
2082
+ else if (item.kind === "mark") {
2083
+ const mark = this.#allMarks().find((one) => one.id === item.id);
2084
+ detail = { kind: "mark", id: item.id, name: mark ? markName(mark.name, this.language) : item.id, body: this.#body, lat: mark?.lat ?? null, lon: mark?.lon ?? null, altitudeKm: null, status: null, placeKind: null, via, ...(mark ? { mark } : {}) };
2085
+ }
1432
2086
  else {
1433
2087
  const place = this.#placeIds.get(item.id);
1434
2088
  const site = siteOf(item.id);
@@ -1444,6 +2098,9 @@ export class WakuseiFlat extends HTMLElement {
1444
2098
  this.#selected = item;
1445
2099
  this.#request();
1446
2100
  }
2101
+ // a tap chooses what it touched: the keyboard's place is let go, so the ring and the tip are where the finger was
2102
+ if (via === "tap")
2103
+ this.#cursor = null;
1447
2104
  this.#sync();
1448
2105
  this.#placeMarks();
1449
2106
  if (item) {
@@ -1596,6 +2253,9 @@ export class WakuseiFlat extends HTMLElement {
1596
2253
  for (const o of this.#orbs)
1597
2254
  if (o.on)
1598
2255
  list.push({ item: { kind: "orbiter", id: o.id }, x: o.x, y: o.y });
2256
+ for (const c of this.#customs)
2257
+ if (c.on)
2258
+ list.push({ item: { kind: "mark", id: c.mark.id }, x: c.x, y: c.y });
1599
2259
  for (const m of this.#marks)
1600
2260
  list.push({ item: { kind: "place", id: m.place.id }, x: m.x, y: m.y });
1601
2261
  if (list.length === 0)