@johnmorrisdotca/chikyu-earth 0.65.1 → 0.66.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.66.0 - 2026-11-22
6
+
7
+ - **A lost context that the browser never gives back no longer leaves the labels over a black view** (MODULES-1499). On a phone that lost the WebGL context (iOS Safari under memory pressure) the Earth and the stars stopped being drawn while the city, star and place names stayed where the last frame put them, for good. Two changes, in `chikyu-space` and `chikyu-earth-realistic`. While `data-state` is `lost` the names, places, compass and notes are hidden, so nothing is left over a view that is not drawn. And the element now follows the shared renderer's own state: when kazoku-ui's renderer makes a new context after `restoreMs` (its next release; this is the half that needs it) the element goes back to `live`, and when none can be made it sends `chikyu-unavailable`, as for a browser with no WebGL. Tests: `e2e/space.gl.ts` (a context never restored is made again on a new canvas with the names hidden meanwhile and the Earth drawn; one that cannot be made ends as `chikyu-unavailable`) and `e2e/tiles.gl.ts` (the same for the realistic Earth). With a kazoku-ui from before the fix the first of them stays on `lost` and fails.
8
+ - **The places can be reached from the keyboard** (MODULES-1348). The place marks are hidden from a screen reader and take no pointer, so a reader with no mouse could not reach a place, though a press sends `chikyu-place-click`. On `<chikyu-space>` and `<chikyu-earth-realistic>`, the two elements that draw places, a focused element now has a way in.
9
+ - **The keys.** `P` goes to the next place in the picture from the left and `Shift`+`P` to the one before (round at the ends); `Enter` sends the same `chikyu-place-click` a press does (`id`, `kind`, `layer`, `label`, `lon`, `lat`, and `x`, `y` at the place's foot); `Escape` lets go. The view's keys (arrows, `+`, `-`, `0`, `Home`, `Space`), the ride's `W` `A` `S` `D` `R` `F` and the constellations' `C` are not taken, and a key with `Ctrl`, `Cmd` or `Alt` is left to the browser. `Enter` with no place chosen is the page's.
10
+ - **Which place.** A white ring with a dark edge is on the chosen place, turns with the Earth and goes when focus leaves, on `Escape`, when the place is taken from the list or its layer is switched off, and when the place is off the picture. No extra draw: the ring is the page layer's own.
11
+ - **Said aloud.** A live region in the element's shadow root says "Osaka, 2 of 5" (`label`, else `id`), or the same in Japanese on a Japanese page (`lang` of the nearest ancestor that has one); "No places in view" and "{name} is not in view" (when `Enter` is pressed on a place turned out of sight, which sends nothing) in both languages. An element with places is `role="group"` (it was `img`, whose inside a screen reader skips), and back to `img` with none; a `role` the page set is left alone.
12
+ - **What it reaches.** The places a press can reach (a marker or a ring in sight, not the far side, not a hidden layer); a place gathered into a crowd's counted ring is reached once the zoom opens it.
13
+ - **API.** `PlaceLayer` gains `reachable()`, `current`, `step(delta)` and `where(place)`; `bindPlaceKeys` and `placeKeyWords` are in `markers/place-keys.ts` (internal).
14
+ - **Tests.** `test/place-keys.test.ts` (stepping and wrapping, the ring following the picture and letting go, the words in both languages, the keys, `Enter`'s event, the keys left alone, the role) and `e2e/place-keys.gl.ts` on both elements: the ring is on the place, the live region and the accessibility tree carry the name, `Enter` sends the event, the arrow keys still turn the view with a place chosen, and a Japanese page hears Japanese. The places guide and the README, in English and Japanese.
15
+ - **The chosen satellite's name goes when the Earth hides the satellite** (MODULES-1766). The name beside the chosen satellite (`.sp-sat`) was put where the satellite projects on the screen whether the Earth was in front of it or not, so with the satellite on the far side its name was drawn on the Earth's face. the satellite layer's `place()`, which the name follows, now says there is no place while the Earth is in the way, by the same test the rings and `placeSatellite` use (a graze at the limb still counts as in view, so the name does not flicker there). A name that the pointer rests on, the ring names (`dim-occluded`, which dims a hidden name on purpose) and `pick` already left out a satellite the Earth hides. Tests: `test/satellite-layer.test.ts` and `e2e/chosen-name.gl.ts`.
16
+
5
17
  ## 0.65.1 - 2026-11-20
6
18
 
7
19
  - **Looking at Jupiter waits until the camera has arrived** (MODULES-1233). The space test no longer reads the distance a few seconds after the click. It waits until the element says the body is Jupiter and the distance has held still, then requires that distance, and a camera kept off Jupiter still fails. Test only.
package/README.md CHANGED
@@ -252,7 +252,7 @@ console.log(bodyLabelText("en"), bodyLabelText("ja"), BODY_LABEL_ATTRIBUTES.leng
252
252
 
253
253
  `route` on `<chikyu-earth>`, `<chikyu-earth-realistic>` and `<chikyu-space>` draws the line between two places (`lon,lat,lon,lat`). `routeInfo` gives the accurate distance on the Earth's real shape, the great-circle distance, the bearings and a flight time at 900 km/h. The line is off until it is set, and nothing is drawn at rest: [guide](docs/guides/routes.md).
254
254
 
255
- `places` on `<chikyu-space>` and `<chikyu-earth-realistic>` marks places on the Earth, each a beam, a pin or a ring (`places-look`) standing out of the ground, turning with the Earth, hidden on its far side and dimmer at night: `kind: "here"` for the reader's own place (brighter, with a quiet pulse) and favourites, quieter, each with an optional `color`. Up to 5,000: the first 32 in sight stand up with their names, the rest are rings in one draw call, crowds are gathered with their count, and `goToPlace(id)` turns the view to one. In the space view `flyTo(lat, lon, { height, phase })` goes across at the height the camera has, then down to hover over the place (30 km over land with `tiles-finer`, else 400 km); a new `flyTo` or `goToPlace` bends the running move without stopping it, a hand ends it where it is, and reduced motion jumps there. Names never overlap; nothing is drawn at rest. Each place can have a `layer` (switched with `place-layers`), a `size` or `look` of its own and a `namePriority`, so a harbour is a short mark and its name gives way to a city's; a press on a place sends `chikyu-place-click` with its `id` and `kind`. `here-city` (off by default) names a `here` place with the nearest city within 100 km, in the page's language; kuni is loaded only then. The package never asks for the reader's place and stores or sends nothing: the page asks on a press and rounds the place with `nearby` first: [guide](docs/guides/places.md).
255
+ `places` on `<chikyu-space>` and `<chikyu-earth-realistic>` marks places on the Earth, each a beam, a pin or a ring (`places-look`) standing out of the ground, turning with the Earth, hidden on its far side and dimmer at night: `kind: "here"` for the reader's own place (brighter, with a quiet pulse) and favourites, quieter, each with an optional `color`. Up to 5,000: the first 32 in sight stand up with their names, the rest are rings in one draw call, crowds are gathered with their count, and `goToPlace(id)` turns the view to one. In the space view `flyTo(lat, lon, { height, phase })` goes across at the height the camera has, then down to hover over the place (30 km over land with `tiles-finer`, else 400 km); a new `flyTo` or `goToPlace` bends the running move without stopping it, a hand ends it where it is, and reduced motion jumps there. Names never overlap; nothing is drawn at rest. Each place can have a `layer` (switched with `place-layers`), a `size` or `look` of its own and a `namePriority`, so a harbour is a short mark and its name gives way to a city's; a press on a place sends `chikyu-place-click` with its `id` and `kind`, and so does `Enter` after `P` and `Shift`+`P` have moved between the places from the keyboard (a ring shows which, a screen reader hears its name). `here-city` (off by default) names a `here` place with the nearest city within 100 km, in the page's language; kuni is loaded only then. The package never asks for the reader's place and stores or sends nothing: the page asks on a press and rounds the place with `nearby` first: [guide](docs/guides/places.md).
256
256
 
257
257
  ```html
258
258
  <chikyu-space places='[{"id":"me","lon":-79.4,"lat":43.7,"label":"You are here","kind":"here"}]'></chikyu-space>
@@ -615,7 +615,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
615
615
 
616
616
  ## How to cite
617
617
 
618
- > Morris, J. (2026). *Chikyu Earth* (version 0.65.1) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
618
+ > Morris, J. (2026). *Chikyu Earth* (version 0.66.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
619
619
 
620
620
  GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA. Cite the version you used (`npm ls @johnmorrisdotca/chikyu-earth`), and credit the sources behind the numbers and pictures: [NOTICE.md](NOTICE.md) says who made each one and under what terms.
621
621
 
@@ -623,6 +623,7 @@ GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gi
623
623
 
624
624
  - A reader who prefers reduced motion gets a still globe, and the riding-along camera draws at most one frame a second.
625
625
  - The view takes the keyboard through the shared controls, and the markers' labels are real buttons.
626
+ - With `<chikyu-space>` or `<chikyu-earth-realistic>` focused, `P` and `Shift`+`P` move between the places in the picture, a ring shows which one, a screen reader hears its name (in English or Japanese), and `Enter` sends `chikyu-place-click`: [guide](docs/guides/places.md).
626
627
  - Names are available in English and Japanese.
627
628
 
628
629
  ```html
@@ -0,0 +1,40 @@
1
+ import { type PlaceLayer } from "./place-layer.ts";
2
+ /** The words the keys say, in English and Japanese. `{name}`, `{n}` and `{total}` are filled in. */
3
+ declare const WORDS: {
4
+ readonly en: {
5
+ readonly at: "{name}, {n} of {total}";
6
+ readonly unnamed: "Place";
7
+ readonly hidden: "{name} is not in view";
8
+ readonly none: "No places in view";
9
+ };
10
+ readonly ja: {
11
+ readonly at: "{name}、{total}か所のうち{n}番目";
12
+ readonly unnamed: "場所";
13
+ readonly hidden: "{name}は見えていません";
14
+ readonly none: "見えている場所はありません";
15
+ };
16
+ };
17
+ /** What a reader hears for each thing the keys do, in a language. */
18
+ export declare const placeKeyWords: (lang: "en" | "ja", key: keyof (typeof WORDS)["en"], values?: {
19
+ name?: string;
20
+ n?: number;
21
+ total?: number;
22
+ }) => string;
23
+ /** What `bindPlaceKeys` gives back. */
24
+ export interface PlaceKeys {
25
+ /** Call when the places change: an element with places is a `group` (a screen reader skips what is inside an `img`), one without is the `img` it was. */
26
+ sync(count: number): void;
27
+ stop(): void;
28
+ }
29
+ /**
30
+ * Bind the place keys to an element.
31
+ *
32
+ * @param host - The focused element.
33
+ * @param layer - Its place layer, read at each key.
34
+ * @param live - A live region of its shadow root (`#place-live`), written with each place's name.
35
+ * @param language - The language of the words, read at each key.
36
+ * @param ownsRole - Whether the element set its own `role="img"` (the page's own `role` is left alone).
37
+ * @returns The binding.
38
+ */
39
+ export declare function bindPlaceKeys(host: HTMLElement, layer: () => PlaceLayer | undefined, live: () => HTMLElement | null, language: () => "en" | "ja", ownsRole: boolean): PlaceKeys;
40
+ export {};
@@ -0,0 +1,91 @@
1
+ // The keyboard's way to the places in the picture: with the element focused, `P` goes to the next place from the left and `Shift`+`P` to the one before, `Enter` presses the one the ring is on (the same
2
+ // `chikyu-place-click` as a press) and `Escape` lets go of it. The ring is drawn by the place layer; the name is said in a live region of the element's own shadow root. Keys the view controls and the ride use are left alone.
3
+ import { placeClick } from "./place-layer.js";
4
+ /** The words the keys say, in English and Japanese. `{name}`, `{n}` and `{total}` are filled in. */
5
+ const WORDS = {
6
+ en: { at: "{name}, {n} of {total}", unnamed: "Place", hidden: "{name} is not in view", none: "No places in view" },
7
+ ja: { at: "{name}、{total}か所のうち{n}番目", unnamed: "場所", hidden: "{name}は見えていません", none: "見えている場所はありません" },
8
+ };
9
+ /** What a reader hears for each thing the keys do, in a language. */
10
+ export const placeKeyWords = (lang, key, values = {}) => WORDS[lang][key].replace("{name}", values.name ?? "").replace("{n}", String(values.n ?? "")).replace("{total}", String(values.total ?? ""));
11
+ const nameOf = (place, lang) => place.label || place.id || placeKeyWords(lang, "unnamed");
12
+ /**
13
+ * Bind the place keys to an element.
14
+ *
15
+ * @param host - The focused element.
16
+ * @param layer - Its place layer, read at each key.
17
+ * @param live - A live region of its shadow root (`#place-live`), written with each place's name.
18
+ * @param language - The language of the words, read at each key.
19
+ * @param ownsRole - Whether the element set its own `role="img"` (the page's own `role` is left alone).
20
+ * @returns The binding.
21
+ */
22
+ export function bindPlaceKeys(host, layer, live, language, ownsRole) {
23
+ const say = (text) => {
24
+ const region = live();
25
+ if (!region)
26
+ return;
27
+ region.lang = language();
28
+ region.textContent = text === region.textContent ? `${text}${String.fromCharCode(0x200b)}` : text;
29
+ };
30
+ const key = (event) => {
31
+ if (event.ctrlKey || event.metaKey || event.altKey || event.defaultPrevented)
32
+ return;
33
+ const places = layer();
34
+ // while the context is lost nothing is drawn and the names are hidden: the keys wait for the view
35
+ if (!places || host.dataset["state"] === "lost")
36
+ return;
37
+ // typing in a field anywhere on the way to this element, or in editable text, is typing
38
+ if (event.composedPath().some((node) => node instanceof HTMLElement && (node.matches("input, textarea, select") || node.isContentEditable)))
39
+ return;
40
+ const lang = language();
41
+ if (event.key === "p" || event.key === "P") {
42
+ const moved = places.step(event.shiftKey ? -1 : 1);
43
+ say(moved ? placeKeyWords(lang, "at", { name: nameOf(moved.place, lang), n: moved.position, total: moved.total }) : placeKeyWords(lang, "none"));
44
+ event.preventDefault();
45
+ }
46
+ else if (event.key === "Enter" && places.current && !event.repeat) {
47
+ const at = places.where(places.current);
48
+ if (at)
49
+ host.dispatchEvent(new CustomEvent("chikyu-place-click", { detail: placeClick(places.current, at.x, at.y), bubbles: true, composed: true }));
50
+ else
51
+ say(placeKeyWords(lang, "hidden", { name: nameOf(places.current, lang) }));
52
+ event.preventDefault();
53
+ }
54
+ else if (event.key === "Escape" && places.current) {
55
+ places.current = null;
56
+ say("");
57
+ event.preventDefault();
58
+ }
59
+ };
60
+ const leave = (event) => {
61
+ if (event.relatedTarget instanceof Node && host.contains(event.relatedTarget))
62
+ return;
63
+ const places = layer();
64
+ if (places?.current)
65
+ places.current = null;
66
+ };
67
+ host.addEventListener("keydown", key);
68
+ host.addEventListener("focusout", leave);
69
+ let grouped = false;
70
+ return {
71
+ sync(count) {
72
+ if (!ownsRole)
73
+ return;
74
+ if (count > 0 && !grouped && host.getAttribute("role") === "img") {
75
+ grouped = true;
76
+ host.setAttribute("role", "group");
77
+ }
78
+ else if (count === 0 && grouped && host.getAttribute("role") === "group") {
79
+ grouped = false;
80
+ host.setAttribute("role", "img");
81
+ }
82
+ },
83
+ stop() {
84
+ host.removeEventListener("keydown", key);
85
+ host.removeEventListener("focusout", leave);
86
+ if (grouped && host.getAttribute("role") === "group")
87
+ host.setAttribute("role", "img");
88
+ grouped = false;
89
+ },
90
+ };
91
+ }
@@ -102,6 +102,25 @@ export interface PlaceLayer {
102
102
  late(taken?: () => readonly Box[]): void;
103
103
  /** The place under a point of the element (CSS pixels from its top left) in the last picture: a marker's stick or foot, or a ring, within a few pixels; null when there is none. A group of several is not a place. */
104
104
  pick(x: number, y: number): Place | null;
105
+ /** The places a press can reach in the last picture, as {@link PlaceLayer.pick} does, from the left of the picture to the right (top first where they share a column); empty while there are none. */
106
+ reachable(): readonly {
107
+ place: Place;
108
+ x: number;
109
+ y: number;
110
+ }[];
111
+ /** The place the keys are on, ringed in the picture, or null. Setting a place that is not in the list clears it. */
112
+ current: Place | null;
113
+ /** Move the keys' place to the next (or, with a negative step, the previous) reachable one; starts at the first (or the last) when none is current or the current one is out of reach. Null when nothing is reachable. */
114
+ step(delta: number): {
115
+ place: Place;
116
+ position: number;
117
+ total: number;
118
+ } | null;
119
+ /** Where a place is in the last picture, in CSS pixels, or null when the picture does not show it (off the box or on the far side). */
120
+ where(place: Place): {
121
+ x: number;
122
+ y: number;
123
+ } | null;
105
124
  /** The rings the picture draws for the places that are not markers of their own, as of the last `frame`; null while there are none. */
106
125
  readonly sprites: PlaceSpriteData | null;
107
126
  /**
@@ -33,7 +33,10 @@ export const PLACE_STYLE = "#places{position:absolute;inset:0;overflow:hidden;po
33
33
  ".pl-sat[hidden]{display:none}" +
34
34
  ".pl-dot{position:absolute;left:0;top:0;box-sizing:border-box;border:1.5px solid var(--c);border-radius:50%;opacity:.9}" +
35
35
  ".pl-dot[hidden]{display:none}" +
36
- ".pl-name.pl-measure{visibility:hidden}";
36
+ ".pl-name.pl-measure{visibility:hidden}" +
37
+ ".pl-current{position:absolute;left:-14px;top:-14px;width:28px;height:28px;box-sizing:border-box;border:2px solid #fff;border-radius:50%;box-shadow:0 0 0 2px rgba(4,10,20,.85),0 0 0 4px #fff;will-change:transform}" +
38
+ ".pl-current[hidden]{display:none}" +
39
+ "#place-live{position:absolute;width:1px;height:1px;margin:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}";
37
40
  /** The ring round a named satellite, in CSS pixels. */
38
41
  const SATELLITE_RING = 8;
39
42
  /**
@@ -325,7 +328,68 @@ export function createPlaceLayer(box) {
325
328
  // the pulse stops while the element is out of sight
326
329
  const watcher = typeof IntersectionObserver === "function" ? new IntersectionObserver((entries) => box.classList.toggle("pl-still", !entries.some((entry) => entry.isIntersecting))) : null;
327
330
  watcher?.observe(box);
331
+ const same = (a, b) => a.id === b.id && a.kind === b.kind;
332
+ let current = null;
333
+ let currentRing;
334
+ const whereIs = (place) => {
335
+ if (!lastView)
336
+ return null;
337
+ for (const shape of lastShapes)
338
+ if (same(lastOwn[shape.index], place))
339
+ return { x: shape.x, y: shape.y };
340
+ if (!lastView.at(place.lon, place.lat, point) || point.facing <= EDGE)
341
+ return null;
342
+ if (point.x < 0 || point.y < 0 || point.x > lastView.width || point.y > lastView.height)
343
+ return null;
344
+ return { x: point.x, y: point.y };
345
+ };
346
+ const showCurrent = () => {
347
+ const at = current ? whereIs(current) : null;
348
+ if (!at) {
349
+ if (currentRing && !currentRing.hidden)
350
+ currentRing.hidden = true;
351
+ return;
352
+ }
353
+ if (!currentRing) {
354
+ currentRing = doc.createElement("i");
355
+ currentRing.className = "pl-current";
356
+ box.append(currentRing);
357
+ }
358
+ if (currentRing.hidden)
359
+ currentRing.hidden = false;
360
+ currentRing.style.transform = `translate(${at.x.toFixed(1)}px,${at.y.toFixed(1)}px)`;
361
+ };
362
+ const keep = () => {
363
+ if (!current)
364
+ return;
365
+ current = places.find((place) => same(place, current)) ?? null;
366
+ showCurrent();
367
+ };
368
+ const reach = () => {
369
+ const found = [];
370
+ if (!lastView || !groupedFor)
371
+ return found;
372
+ const marked = new Set();
373
+ for (const shape of lastShapes) {
374
+ const place = lastOwn[shape.index];
375
+ marked.add(place);
376
+ found.push({ place, x: shape.x, y: shape.y });
377
+ }
378
+ for (const group of groups) {
379
+ if (group.members.length !== 1)
380
+ continue;
381
+ const place = groupedFor[group.members[0]];
382
+ if (marked.has(place) || !lastView.at(group.lon, group.lat, point) || point.facing <= EDGE)
383
+ continue;
384
+ if (point.x < 0 || point.y < 0 || point.x > lastView.width || point.y > lastView.height)
385
+ continue;
386
+ found.push({ place, x: point.x, y: point.y });
387
+ }
388
+ return found.sort((a, b) => a.x - b.x || a.y - b.y);
389
+ };
328
390
  const clear = () => {
391
+ if (currentRing && !currentRing.hidden)
392
+ currentRing.hidden = true;
329
393
  hideFrom(marks.map((m) => m.root), 0);
330
394
  hideFrom(names, 0);
331
395
  hideFrom(rings, 0);
@@ -357,6 +421,7 @@ export function createPlaceLayer(box) {
357
421
  places = shownPlaces(next, switches);
358
422
  stats.places = next.length;
359
423
  stats.hidden = next.length - places.length;
424
+ keep();
360
425
  if (places.length === 0) {
361
426
  groups = [];
362
427
  groupedFor = places;
@@ -376,6 +441,7 @@ export function createPlaceLayer(box) {
376
441
  groupedFor = places;
377
442
  sprites = null;
378
443
  }
444
+ keep();
379
445
  },
380
446
  get look() {
381
447
  return look;
@@ -636,6 +702,7 @@ export function createPlaceLayer(box) {
636
702
  stats.dots = drawnDots;
637
703
  stats.rings = seen.length;
638
704
  stats.satelliteNames = placed.length;
705
+ showCurrent();
639
706
  },
640
707
  stats,
641
708
  get boxes() {
@@ -693,10 +760,31 @@ export function createPlaceLayer(box) {
693
760
  }
694
761
  return best;
695
762
  },
763
+ reachable: reach,
764
+ get current() {
765
+ return current;
766
+ },
767
+ set current(value) {
768
+ current = value ? (places.find((place) => same(place, value)) ?? null) : null;
769
+ showCurrent();
770
+ },
771
+ step(delta) {
772
+ const list = reach();
773
+ if (list.length === 0)
774
+ return null;
775
+ const at = current ? list.findIndex((item) => same(item.place, current)) : -1;
776
+ const to = at < 0 ? (delta > 0 ? 0 : list.length - 1) : (((at + delta) % list.length) + list.length) % list.length;
777
+ current = list[to].place;
778
+ showCurrent();
779
+ return { place: current, position: to + 1, total: list.length };
780
+ },
781
+ where: whereIs,
696
782
  dispose() {
697
783
  watcher?.disconnect();
698
784
  fonts?.removeEventListener?.("loadingdone", refit);
699
785
  box.replaceChildren();
786
+ currentRing = undefined;
787
+ current = null;
700
788
  marks.length = 0;
701
789
  names.length = 0;
702
790
  measures.length = 0;
@@ -205,7 +205,7 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
205
205
  * and keep their size in pixels at any zoom. Names never overlap one another; one with no room is left out. The element stores nothing and sends nothing: the page hands the places over and keeps them where
206
206
  * it likes. Setting the property writes the attribute; at most `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight and for a reader who asked
207
207
  * for less motion. A place may also have a `layer` (shown or hidden with `place-layers`), a `size` (`small`), a `look` of its own (over `places-look`) and a `namePriority` (`low` lays its name after the cities'
208
- * names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`.
208
+ * names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`. With the element focused, `P` and `Shift`+`P` move between the places in the picture from the left (a ring shows which, and its name is said in a live region, in English or Japanese), `Enter` sends the same event and `Escape` lets go.
209
209
  */
210
210
  get places(): Place[];
211
211
  set places(value: readonly Place[]);
@@ -25,6 +25,7 @@ import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
25
25
  import { cleanPlaces, orthoView, readPlaceGroups, readPlaceLayers, readPlaces } from "../markers/places.js";
26
26
  import { readHereCity } from "../markers/here-city.js";
27
27
  import { createHereCity } from "../markers/here-city-host.js";
28
+ import { bindPlaceKeys } from "../markers/place-keys.js";
28
29
  import { createPlaceLayer, PLACE_STYLE, placeClick, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
29
30
  import { aimAt, findPlace, glideView } from "../markers/go-to-place.js";
30
31
  import { subsolarPoint } from "./sun.js";
@@ -45,7 +46,7 @@ export { setSharedRenderer, setThreeLoader };
45
46
  import { MAX_TEXTURE, TIERS } from "./tiers.js";
46
47
  import { readCloudFade } from "./cloud-fade.js";
47
48
  import { mayWriteZoomMax, raisedZoomMax } from "./zoom-reach.js";
48
- const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative;isolation:isolate}" + IMMERSIVE_STYLE + "#stage,#overlay{position:absolute;inset:0}#overlay{pointer-events:none}.sp-sat{position:absolute;left:0;top:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-sat[hidden]{display:none}.sp-sat[data-hover]{transition:opacity 180ms linear}@media (prefers-reduced-motion: reduce){.sp-sat[data-hover]{transition:none}}" + PLACE_STYLE + SKY_STYLE + COUNTRY_NAMES_STYLE + SEA_NAMES_STYLE + CITY_NAMES_STYLE + METEOR_NOTE_STYLE + NOTES_STYLE;
49
+ const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative;isolation:isolate}" + IMMERSIVE_STYLE + "#stage,#overlay{position:absolute;inset:0}#overlay{pointer-events:none}:host([data-state=\"lost\"]) #stage~*{visibility:hidden}.sp-sat{position:absolute;left:0;top:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-sat[hidden]{display:none}.sp-sat[data-hover]{transition:opacity 180ms linear}@media (prefers-reduced-motion: reduce){.sp-sat[data-hover]{transition:none}}" + PLACE_STYLE + SKY_STYLE + COUNTRY_NAMES_STYLE + SEA_NAMES_STYLE + CITY_NAMES_STYLE + METEOR_NOTE_STYLE + NOTES_STYLE;
49
50
  const RAD = Math.PI / 180;
50
51
  /** The Sun and the clouds are re-placed this often at real time: 15 degrees an hour is 0.25 degree a minute. */
51
52
  const LIVE_TICK_MS = 60_000;
@@ -208,6 +209,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
208
209
  #countriesStyle = {};
209
210
  #listeners = new Set();
210
211
  #placeLayer;
212
+ #placeKeys;
213
+ #ownRole = false;
211
214
  /** The nearest city's name on a `here` marker (`here-city`), loaded only when that is on. */
212
215
  #here;
213
216
  /** Whether the page has been told that places in sight were left undrawn. */
@@ -233,6 +236,9 @@ export class ChikyuEarthRealistic extends HTMLElement {
233
236
  #onContext = (state) => {
234
237
  if (state === "unavailable")
235
238
  this.#fail("WebGL is not available");
239
+ // A context the browser never gave back is made again by the shared renderer, which then says so here (the canvas it makes sends no event of its own).
240
+ else if (state === "restored")
241
+ this.#set("live");
236
242
  };
237
243
  // The canvas's own events reach the stage in the capture phase (they do not bubble); the shared renderer handles them and this follows.
238
244
  #lost = () => this.#set("lost");
@@ -253,12 +259,14 @@ export class ChikyuEarthRealistic extends HTMLElement {
253
259
  this.#applyBodyLabel();
254
260
  this.#door.book.ownOnly(this.getAttribute("data") === "own");
255
261
  this.#model.speed = this.speed;
256
- if (!this.hasAttribute("role"))
262
+ if (!this.hasAttribute("role")) {
257
263
  this.setAttribute("role", "img");
264
+ this.#ownRole = true;
265
+ }
258
266
  if (!this.hasAttribute("aria-label"))
259
267
  this.setAttribute("aria-label", "The Earth from space, with its sunlit and dark sides");
260
268
  const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
261
- root.innerHTML = `<div id="stage"></div><div id="places"></div><div id="overlay"></div><div id="notes"><p id="air-note" hidden></p><p id="meteor-note" hidden></p><p id="finer-credit" hidden></p></div>`;
269
+ root.innerHTML = `<div id="stage"></div><div id="places"></div><p id="place-live" role="status"></p><div id="overlay"></div><div id="notes"><p id="air-note" hidden></p><p id="meteor-note" hidden></p><p id="finer-credit" hidden></p></div>`;
262
270
  adoptStyles(root, STYLE, this.nonce);
263
271
  this.#stage = root.getElementById("stage");
264
272
  this.#overlay = root.getElementById("overlay");
@@ -282,6 +290,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
282
290
  this.#placeLayer.look = readPlaceLook(this.getAttribute("places-look"));
283
291
  this.#placeLayer.grouping = readPlaceGroups(this.getAttribute("place-groups"));
284
292
  this.#placeLayer.layers = readPlaceLayers(this.getAttribute("place-layers"));
293
+ this.#placeKeys = bindPlaceKeys(this, () => this.#placeLayer, () => root.getElementById("place-live"), () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"), this.#ownRole);
294
+ this.#placeKeys.sync(this.#placeList.length);
285
295
  this.#cities = createCityHost({
286
296
  root,
287
297
  attribute: (name) => this.getAttribute(name),
@@ -461,6 +471,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
461
471
  this.#sky = undefined;
462
472
  this.#here?.dispose();
463
473
  this.#here = undefined;
474
+ this.#placeKeys?.stop();
475
+ this.#placeKeys = undefined;
464
476
  this.#placeLayer?.dispose();
465
477
  this.#placeLayer = undefined;
466
478
  this.#cities?.dispose();
@@ -704,7 +716,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
704
716
  * and keep their size in pixels at any zoom. Names never overlap one another; one with no room is left out. The element stores nothing and sends nothing: the page hands the places over and keeps them where
705
717
  * it likes. Setting the property writes the attribute; at most `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight and for a reader who asked
706
718
  * for less motion. A place may also have a `layer` (shown or hidden with `place-layers`), a `size` (`small`), a `look` of its own (over `places-look`) and a `namePriority` (`low` lays its name after the cities'
707
- * names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`.
719
+ * names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`. With the element focused, `P` and `Shift`+`P` move between the places in the picture from the left (a ring shows which, and its name is said in a live region, in English or Japanese), `Enter` sends the same event and `Escape` lets go.
708
720
  */
709
721
  get places() {
710
722
  return this.#placeList.map((place) => ({ ...place }));
@@ -767,6 +779,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
767
779
  if (!layer)
768
780
  return;
769
781
  layer.set(this.#here?.named(this.#placeList) ?? this.#placeList);
782
+ this.#placeKeys?.sync(this.#placeList.length);
770
783
  this.#gate?.soon();
771
784
  }
772
785
  /**
@@ -392,7 +392,7 @@ export declare class ChikyuSpace extends HTMLElement {
392
392
  * and keep their size in pixels at any zoom. Names never overlap one another or the bodies' names; one with no room is left out. The element stores nothing and sends nothing: the page hands the places
393
393
  * over and keeps them where it likes. Setting the property writes the attribute; at most `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight
394
394
  * and for a reader who asked for less motion. A place may also have a `layer` (shown or hidden with `place-layers`), a `size` (`small`), a `look` of its own (over `places-look`) and a `namePriority` (`low` lays
395
- * its name after the cities' names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`.
395
+ * its name after the cities' names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`. With the element focused, `P` and `Shift`+`P` move between the places in the picture from the left (a ring shows which, and its name is said in a live region, in English or Japanese), `Enter` sends the same event and `Escape` lets go.
396
396
  */
397
397
  get places(): Place[];
398
398
  set places(value: readonly Place[]);
@@ -7,6 +7,7 @@ import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
7
7
  import { cleanPlaces, readPlaceGroups, readPlaceLayers, readPlaces } from "../markers/places.js";
8
8
  import { readHereCity } from "../markers/here-city.js";
9
9
  import { createHereCity } from "../markers/here-city-host.js";
10
+ import { bindPlaceKeys } from "../markers/place-keys.js";
10
11
  import { createPlaceLayer, PLACE_STYLE, placeClick, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
11
12
  import { aimAt, findPlace, PLACE_GLIDE_MS } from "../markers/go-to-place.js";
12
13
  import { subsolarPoint } from "../realistic/sun.js";
@@ -155,7 +156,7 @@ const readTime = (value) => {
155
156
  const ms = Date.parse(value);
156
157
  return Number.isFinite(ms) ? ms : "now";
157
158
  };
158
- const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden;isolation:isolate}${IMMERSIVE_STYLE}#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[hidden]{display:none}.sp-sat{position:absolute;left:0;top:0;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-sat[hidden]{display:none}.sp-sat[data-hover]{transition:opacity 180ms linear}@media (prefers-reduced-motion: reduce){.sp-sat[data-hover]{transition:none}}${PLACE_STYLE}${SKY_STYLE}${COUNTRY_NAMES_STYLE}${SEA_NAMES_STYLE}${CITY_NAMES_STYLE}${METEOR_NOTE_STYLE}${NOTES_STYLE}${COMPASS_STYLE}`;
159
+ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden;isolation:isolate}${IMMERSIVE_STYLE}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}:host([data-state="lost"]) #stage~*{visibility: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[hidden]{display:none}.sp-sat{position:absolute;left:0;top:0;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-sat[hidden]{display:none}.sp-sat[data-hover]{transition:opacity 180ms linear}@media (prefers-reduced-motion: reduce){.sp-sat[data-hover]{transition:none}}${PLACE_STYLE}${SKY_STYLE}${COUNTRY_NAMES_STYLE}${SEA_NAMES_STYLE}${CITY_NAMES_STYLE}${METEOR_NOTE_STYLE}${NOTES_STYLE}${COMPASS_STYLE}`;
159
160
  /**
160
161
  * The `<chikyu-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`, `time` (`now` or an ISO date), `speed` (1 is real time, 0 holds, 86400 is a day a second, negative runs backwards), `scale` (`compressed` or `true`), `labels` and `orbits` (`off` hides them); positions are computed in the browser by astronomy-engine, an optional peer dependency. It draws only when something changes, and nothing while it is out of sight.
161
162
  *
@@ -269,6 +270,8 @@ export class ChikyuSpace extends HTMLElement {
269
270
  #ridden = {};
270
271
  #toldFacing = null;
271
272
  #placeLayer;
273
+ #placeKeys;
274
+ #ownRole = false;
272
275
  /** The nearest city's name on a `here` marker (`here-city`), loaded only when that is on. */
273
276
  #here;
274
277
  /** Whether the page has been told that places in sight were left undrawn. */
@@ -309,12 +312,14 @@ export class ChikyuSpace extends HTMLElement {
309
312
  this.#model.earth = { size: readNumber(this.getAttribute("earth-size"), DEFAULT_EARTH_SIZE, 0.02, 50), x: readNumber(this.getAttribute("earth-x"), 0.5, -2, 3), y: readNumber(this.getAttribute("earth-y"), 0.5, -2, 3) };
310
313
  this.#model.stepMs = Math.max(1000, Math.abs(this.#speed) * 1000);
311
314
  this.#model.speed = this.#speed;
312
- if (!this.hasAttribute("role"))
315
+ if (!this.hasAttribute("role")) {
313
316
  this.setAttribute("role", "img");
317
+ this.#ownRole = true;
318
+ }
314
319
  if (!this.hasAttribute("aria-label"))
315
320
  this.setAttribute("aria-label", "The Earth, the Moon, the Sun and the planets in their places for the date shown");
316
321
  const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
317
- root.innerHTML = `<div id="stage"></div><div id="places"></div><div id="labels" aria-hidden="true"></div>${COMPASS_HTML}<div id="notes"><p id="air-note" hidden></p><p id="meteor-note" hidden></p><p id="bodies-note" hidden></p><p id="finer-credit" hidden></p></div>`;
322
+ root.innerHTML = `<div id="stage"></div><div id="places"></div><p id="place-live" role="status"></p><div id="labels" aria-hidden="true"></div>${COMPASS_HTML}<div id="notes"><p id="air-note" hidden></p><p id="meteor-note" hidden></p><p id="bodies-note" hidden></p><p id="finer-credit" hidden></p></div>`;
318
323
  adoptStyles(root, STYLE, this.nonce);
319
324
  this.#compass = createCompass(root);
320
325
  this.#placeCompass();
@@ -341,6 +346,8 @@ export class ChikyuSpace extends HTMLElement {
341
346
  this.#placeLayer.look = readPlaceLook(this.getAttribute("places-look"));
342
347
  this.#placeLayer.grouping = readPlaceGroups(this.getAttribute("place-groups"));
343
348
  this.#placeLayer.layers = readPlaceLayers(this.getAttribute("place-layers"));
349
+ this.#placeKeys = bindPlaceKeys(this, () => this.#placeLayer, () => root.getElementById("place-live"), () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"), this.#ownRole);
350
+ this.#placeKeys.sync(this.#placeList.length);
344
351
  this.#dimOccluded = this.getAttribute("dim-occluded") !== "off";
345
352
  this.#placeLayer.dimOccluded = this.#dimOccluded;
346
353
  this.#cities = createCityHost({
@@ -392,6 +399,9 @@ export class ChikyuSpace extends HTMLElement {
392
399
  const taken = takeRenderer((state) => {
393
400
  if (state === "unavailable")
394
401
  this.#fail("WebGL is not available");
402
+ // A context the browser never gave back is made again by the shared renderer, which then says so here (the canvas it makes sends no event of its own).
403
+ else if (state === "restored")
404
+ this.#set("live");
395
405
  });
396
406
  this.#taken = taken;
397
407
  const item = createSpaceItem(this.#model, {
@@ -516,6 +526,8 @@ export class ChikyuSpace extends HTMLElement {
516
526
  this.#sky = undefined;
517
527
  this.#here?.dispose();
518
528
  this.#here = undefined;
529
+ this.#placeKeys?.stop();
530
+ this.#placeKeys = undefined;
519
531
  this.#placeLayer?.dispose();
520
532
  this.#placeLayer = undefined;
521
533
  this.#cities?.dispose();
@@ -868,7 +880,7 @@ export class ChikyuSpace extends HTMLElement {
868
880
  * and keep their size in pixels at any zoom. Names never overlap one another or the bodies' names; one with no room is left out. The element stores nothing and sends nothing: the page hands the places
869
881
  * over and keeps them where it likes. Setting the property writes the attribute; at most `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight
870
882
  * and for a reader who asked for less motion. A place may also have a `layer` (shown or hidden with `place-layers`), a `size` (`small`), a `look` of its own (over `places-look`) and a `namePriority` (`low` lays
871
- * its name after the cities' names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`.
883
+ * its name after the cities' names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`. With the element focused, `P` and `Shift`+`P` move between the places in the picture from the left (a ring shows which, and its name is said in a live region, in English or Japanese), `Enter` sends the same event and `Escape` lets go.
872
884
  */
873
885
  get places() {
874
886
  return this.#placeList.map((place) => ({ ...place }));
@@ -931,6 +943,7 @@ export class ChikyuSpace extends HTMLElement {
931
943
  if (!layer)
932
944
  return;
933
945
  layer.set(this.#here?.named(this.#placeList) ?? this.#placeList);
946
+ this.#placeKeys?.sync(this.#placeList.length);
934
947
  this.#gate?.request();
935
948
  }
936
949
  /**
@@ -263,7 +263,7 @@ export interface SatelliteLayer {
263
263
  width: number;
264
264
  height: number;
265
265
  }, radius: number): Omit<PathHit, "pointer"> | null;
266
- /** Where the chosen satellite is in the view, if it is. */
266
+ /** Where the chosen satellite is in the view, if it is and the Earth is not in the way. */
267
267
  place(camera: THREE.Camera, size: {
268
268
  width: number;
269
269
  height: number;
@@ -899,7 +899,17 @@ export function createSatelliteLayer(three, scene, state, ratio) {
899
899
  place(camera, size) {
900
900
  if (!selectedPoints.visible)
901
901
  return null;
902
- projected.set(selectedPosition[0], selectedPosition[1], selectedPosition[2]).applyMatrix4(scene.matrixWorld).project(camera);
902
+ const ortho = camera.isOrthographicCamera === true;
903
+ const centreDepth = ortho ? view.set(0, 0, 0).applyMatrix4(camera.matrixWorldInverse).z : 0;
904
+ world.set(selectedPosition[0], selectedPosition[1], selectedPosition[2]).applyMatrix4(scene.matrixWorld);
905
+ if (ortho) {
906
+ view.copy(world).applyMatrix4(camera.matrixWorldInverse);
907
+ if (earthHidesDisc(view.x, view.y, view.z, centreDepth))
908
+ return null;
909
+ }
910
+ else if (earthHides(camera.position, world))
911
+ return null;
912
+ projected.copy(world).project(camera);
903
913
  if (projected.z > 1 || projected.z < -1)
904
914
  return null;
905
915
  return { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/chikyu-earth",
3
- "version": "0.65.1",
3
+ "version": "0.66.0",
4
4
  "description": "Chikyu Earth 地球 — A line-drawn globe for the web: country outlines that turn at the Earth's own rate, centred on the place you give it, with an optional realistic Earth from space (three.js), the Sun, Moon and planets, satellites on their orbits, and markers for any place. A web component and an SVG string.",
5
5
  "keywords": [
6
6
  "earth",
@@ -238,7 +238,7 @@
238
238
  },
239
239
  "dependencies": {
240
240
  "@johnmorrisdotca/chizu": "^1.6.0",
241
- "@johnmorrisdotca/kazoku-ui": "^0.41.0",
241
+ "@johnmorrisdotca/kazoku-ui": "^0.54.1",
242
242
  "d3-geo": "^3.1.1"
243
243
  },
244
244
  "peerDependencies": {