@johnmorrisdotca/chikyu-earth 0.38.0 → 0.40.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +2 -1
  3. package/dist/cities/geometry.d.ts +7 -0
  4. package/dist/cities/geometry.js +1 -1
  5. package/dist/cities/host.d.ts +10 -2
  6. package/dist/cities/host.js +4 -2
  7. package/dist/markers/layer.d.ts +16 -1
  8. package/dist/markers/layer.js +3 -2
  9. package/dist/markers/place-layer.js +3 -0
  10. package/dist/paint/buffer.d.ts +6 -1
  11. package/dist/paint/buffer.js +151 -68
  12. package/dist/paint/texture.d.ts +16 -6
  13. package/dist/paint/texture.js +46 -27
  14. package/dist/realistic/earth.d.ts +1 -1
  15. package/dist/realistic/earth.js +5 -4
  16. package/dist/realistic/element-base.d.ts +437 -0
  17. package/dist/realistic/element-base.js +1249 -0
  18. package/dist/realistic/element.d.ts +2 -431
  19. package/dist/realistic/element.js +3 -1203
  20. package/dist/realistic/index.d.ts +1 -1
  21. package/dist/realistic/no-cultures.d.ts +1 -0
  22. package/dist/realistic/no-cultures.js +2 -0
  23. package/dist/realistic/tiles.d.ts +24 -0
  24. package/dist/realistic/tiles.js +30 -12
  25. package/dist/sky/culture-source.d.ts +15 -0
  26. package/dist/sky/culture-source.js +15 -0
  27. package/dist/sky/cultures.d.ts +1 -0
  28. package/dist/sky/cultures.js +8 -0
  29. package/dist/sky/host.d.ts +12 -0
  30. package/dist/sky/host.js +174 -22
  31. package/dist/space/element-base.d.ts +624 -0
  32. package/dist/space/element-base.js +1656 -0
  33. package/dist/space/element.d.ts +2 -612
  34. package/dist/space/element.js +3 -1597
  35. package/dist/space/no-cultures.d.ts +1 -0
  36. package/dist/space/no-cultures.js +2 -0
  37. package/dist/space/scene.d.ts +8 -1
  38. package/dist/space/scene.js +73 -34
  39. package/package.json +23 -3
@@ -3,7 +3,7 @@ export { chooseTier, textureBytes, textureCap, MAX_TEXTURE, TIERS, TEXELS_PER_RA
3
3
  export { createGate, frameCap, type Gate } from "./gate.ts";
4
4
  export { lookAt, discRadius, ATMOSPHERE_OUTER, cameraCentre, type CameraMode, type LightMode } from "./earth.ts";
5
5
  export type { ThreeParts } from "./earth.ts";
6
- export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView, type TileCamera, type TileId, type TileLayer, type VisibleTile } from "./tiles.ts";
6
+ export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView, type TileCamera, type TileId, type TileLayer, type TilePerspective, type VisibleTile } from "./tiles.ts";
7
7
  export { TILE_KEEP_MS, TILE_LIMIT } from "./tile-set.ts";
8
8
  export { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel, loadMichroma, setBodyLabelFontUrl, type BodyLabelSettings } from "./body-label.ts";
9
9
  export { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_THICKNESS_MAX, AIR_TOP, AIR_VERT, airFor, airFrag, airTop, readAirThickness, type AirSamples } from "./air.ts";
@@ -0,0 +1 @@
1
+ export * from "./element-base.ts";
@@ -0,0 +1,2 @@
1
+ // `<chikyu-earth-realistic>` with no sky culture but the IAU's: nothing under `hoshi-stars/cultures` is in the build, and `constellation-culture` is `iau` whatever a page sets (with one warning). Everything else is as `realistic/element`.
2
+ export * from "./element-base.js";
@@ -51,6 +51,30 @@ export interface TileCamera {
51
51
  panX: number;
52
52
  panY: number;
53
53
  radius: number;
54
+ /** A camera of the space view, which has a real place and a perspective, in place of the disc: when given, `lon`, `lat`, `panX`, `panY` are not read and `radius` is the disc's radius at the nearest ground. */
55
+ perspective?: TilePerspective;
56
+ }
57
+ /**
58
+ * A camera that sees the Earth in perspective, from a place that can be a few kilometres above the ground, in the Earth's own axes (x toward longitude 90, y north, z toward longitude 0; the Earth's radius is 1).
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import type { TilePerspective } from "@johnmorrisdotca/chikyu-earth/realistic";
63
+ *
64
+ * const look: TilePerspective = { eye: [0, 0, 1.0235], project: (p) => ({ x: 400 + p[0] * 5000, y: 300 - p[1] * 5000 }), ground: () => [0, 0, 1] };
65
+ * console.log(look.eye);
66
+ * ```
67
+ */
68
+ export interface TilePerspective {
69
+ /** Where the camera is. */
70
+ eye: readonly [number, number, number];
71
+ /** Where a point of the Earth's surface falls in the box (CSS pixels), or `null` where it is behind the camera. */
72
+ project(point: readonly [number, number, number]): {
73
+ x: number;
74
+ y: number;
75
+ } | null;
76
+ /** The point of the Earth's surface under a place in the box (a unit vector), or `null` where the box shows the sky. */
77
+ ground(x: number, y: number): readonly [number, number, number] | null;
54
78
  }
55
79
  /**
56
80
  * A tile that is in view: where, how far its middle is from the middle of the box (CSS pixels, for loading the middle first) and how dark its darkest sampled point is (`ndl`, the
@@ -130,6 +130,10 @@ const turned = (lon, lat, lonRad, latRad) => {
130
130
  * ```
131
131
  */
132
132
  export function pointOnEarth(camera, x, y) {
133
+ if (camera.perspective) {
134
+ const g = camera.perspective.ground(x, y);
135
+ return g ? { lon: Math.atan2(g[0], g[2]) / RAD, lat: Math.asin(Math.max(-1, Math.min(1, g[1]))) / RAD } : undefined;
136
+ }
133
137
  const px = (x - camera.width / 2 - camera.panX) / camera.radius;
134
138
  const py = (camera.height / 2 + camera.panY - y) / camera.radius;
135
139
  const rest = 1 - px * px - py * py;
@@ -174,33 +178,47 @@ export function tilesInView(level, camera, sun) {
174
178
  const rows = tileRows(level);
175
179
  const lonRad = camera.lon * RAD;
176
180
  const latRad = camera.lat * RAD;
181
+ const look = camera.perspective;
177
182
  const margin = Math.min(160, Math.min(camera.width, camera.height) / 4);
178
183
  const cx = camera.width / 2 + camera.panX;
179
184
  const cy = camera.height / 2 + camera.panY;
180
185
  const found = new Map();
181
186
  const ndlOf = (z) => (sun ? z[0] * sun[0] + z[1] * sun[1] + z[2] * sun[2] : 1);
187
+ const eyeLength = look ? Math.hypot(...look.eye) : 1;
188
+ /** A point of the map as the camera has it: the vector to light it by, and where it is in the box when it faces the camera. */
189
+ const sample = (lon, lat) => {
190
+ if (!look) {
191
+ const n = turned(lon, lat, lonRad, latRad);
192
+ const at = { x: cx + n[0] * camera.radius, y: cy - n[1] * camera.radius };
193
+ return { n, screen: n[2] < 0 ? null : at, flat: at, toward: n[2] };
194
+ }
195
+ const cl = Math.cos(lat);
196
+ const n = [cl * Math.sin(lon), Math.sin(lat), cl * Math.cos(lon)];
197
+ const along = n[0] * look.eye[0] + n[1] * look.eye[1] + n[2] * look.eye[2];
198
+ // a point is in sight when it is on the camera's side of the horizon (the plane through the points where its sight lines graze the Earth)
199
+ const screen = along < 1 ? null : look.project(n);
200
+ return { n, screen, flat: screen, toward: along / eyeLength };
201
+ };
182
202
  for (let row = 0; row < rows; row += 1) {
183
203
  for (let col = 0; col < columns; col += 1) {
184
204
  const [west, north, east, south] = tileRect({ level, col, row });
185
- const middle = turned((west + east) / 2, (north + south) / 2, lonRad, latRad);
186
- if (middle[2] < -0.4)
205
+ const middle = sample((west + east) / 2, (north + south) / 2);
206
+ if (middle.toward < -0.4)
187
207
  continue;
188
208
  let inside = false;
189
209
  let darkest = 1;
190
210
  for (let j = 0; j <= 2; j += 1) {
191
211
  for (let i = 0; i <= 2; i += 1) {
192
- const p = turned(west + ((east - west) * i) / 2, north + ((south - north) * j) / 2, lonRad, latRad);
193
- darkest = Math.min(darkest, ndlOf(p));
194
- if (p[2] < 0)
212
+ const p = sample(west + ((east - west) * i) / 2, north + ((south - north) * j) / 2);
213
+ darkest = Math.min(darkest, ndlOf(p.n));
214
+ if (!p.screen)
195
215
  continue;
196
- const sx = cx + p[0] * camera.radius;
197
- const sy = cy - p[1] * camera.radius;
198
- if (sx >= -margin && sx <= camera.width + margin && sy >= -margin && sy <= camera.height + margin)
216
+ if (p.screen.x >= -margin && p.screen.x <= camera.width + margin && p.screen.y >= -margin && p.screen.y <= camera.height + margin)
199
217
  inside = true;
200
218
  }
201
219
  }
202
220
  if (inside) {
203
- const d = Math.hypot(cx + middle[0] * camera.radius - camera.width / 2, cy - middle[1] * camera.radius - camera.height / 2);
221
+ const d = middle.flat ? Math.hypot(middle.flat.x - camera.width / 2, middle.flat.y - camera.height / 2) : Math.hypot(camera.width, camera.height);
204
222
  found.set(row * columns + col, { d, ndl: darkest });
205
223
  }
206
224
  }
@@ -217,9 +235,9 @@ export function tilesInView(level, camera, sun) {
217
235
  if (found.has(key))
218
236
  continue;
219
237
  const [west, north, east, south] = tileRect(tile);
220
- const p = turned((west + east) / 2, (north + south) / 2, lonRad, latRad);
221
- const dark = [turned(west, north, lonRad, latRad), turned(east, north, lonRad, latRad), turned(west, south, lonRad, latRad), turned(east, south, lonRad, latRad), p].reduce((least, q) => Math.min(least, ndlOf(q)), 1);
222
- found.set(key, { d: Math.hypot(cx + p[0] * camera.radius - camera.width / 2, cy - p[1] * camera.radius - camera.height / 2), ndl: dark });
238
+ const p = sample((west + east) / 2, (north + south) / 2);
239
+ const dark = [sample(west, north), sample(east, north), sample(west, south), sample(east, south), p].reduce((least, q) => Math.min(least, ndlOf(q.n)), 1);
240
+ found.set(key, { d: p.flat ? Math.hypot(p.flat.x - camera.width / 2, p.flat.y - camera.height / 2) : Math.hypot(camera.width, camera.height), ndl: dark });
223
241
  }
224
242
  }
225
243
  return [...found]
@@ -0,0 +1,15 @@
1
+ import type { Culture } from "@johnmorrisdotca/hoshi-stars/culture";
2
+ /** How to bring each culture in, by id: a dynamic import of its own, so that a bundler makes a file of each. */
3
+ export type CultureLoaders = Readonly<Record<string, () => Promise<Culture>>>;
4
+ /**
5
+ * Sets the cultures an element can load. The default entries (`@johnmorrisdotca/chikyu-earth/space/element` and `.../realistic/element`) set `western`, `japanese` and `chinese`; the entries without cultures set none.
6
+ *
7
+ * @param next - The loaders, by culture id.
8
+ */
9
+ export declare function setCultureLoaders(next: CultureLoaders): void;
10
+ /**
11
+ * The cultures that can be loaded now.
12
+ *
13
+ * @returns The loaders, by culture id; empty when the build leaves the cultures out.
14
+ */
15
+ export declare const cultureLoaders: () => CultureLoaders;
@@ -0,0 +1,15 @@
1
+ let loaders = {};
2
+ /**
3
+ * Sets the cultures an element can load. The default entries (`@johnmorrisdotca/chikyu-earth/space/element` and `.../realistic/element`) set `western`, `japanese` and `chinese`; the entries without cultures set none.
4
+ *
5
+ * @param next - The loaders, by culture id.
6
+ */
7
+ export function setCultureLoaders(next) {
8
+ loaders = next;
9
+ }
10
+ /**
11
+ * The cultures that can be loaded now.
12
+ *
13
+ * @returns The loaders, by culture id; empty when the build leaves the cultures out.
14
+ */
15
+ export const cultureLoaders = () => loaders;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ // The sky cultures besides the IAU's, each loaded by a dynamic import of its own, only when a page asks for it: a page that never sets `chinese` never downloads it. (The imports are written out, one for each, so that a bundler makes a file of each.)
2
+ // Importing this file is what puts them in a build: the default entries do, the entries without cultures do not.
3
+ import { setCultureLoaders } from "./culture-source.js";
4
+ setCultureLoaders({
5
+ western: async () => (await import("@johnmorrisdotca/hoshi-stars/cultures/western")).western,
6
+ japanese: async () => (await import("@johnmorrisdotca/hoshi-stars/cultures/japanese")).japanese,
7
+ chinese: async () => (await import("@johnmorrisdotca/hoshi-stars/cultures/chinese")).chinese,
8
+ });
@@ -11,6 +11,8 @@ export interface SkyHost {
11
11
  refresh(): void;
12
12
  /** The places where the sky's names must not go (the property `keepClear`): rectangles in the element's pixels, or elements of the page. `null` for none. */
13
13
  setKeepClear(areas: readonly SkyKeepClear[] | null): void;
14
+ /** Lays the names out once more on the last frame, where a layer placed before this one has moved between draws (a marker list changed, city names arrived). Nothing happens when there is no frame or no name is asked for. */
15
+ relayout(): void;
14
16
  /** The look of the names, as a partial hoshi-stars `LabelStyle` (the property `skyStyle`). */
15
17
  setStyle(style: Partial<SkyLabelStyle>): void;
16
18
  /** Picks a constellation by its IAU abbreviation (`Ori`), or lets it go (`null`): the property `constellation`. Sends no event. */
@@ -52,6 +54,16 @@ export interface SkyHostOptions {
52
54
  importer?: () => Promise<typeof import("@johnmorrisdotca/hoshi-stars/sky-labels")>;
53
55
  /** Brings hoshi-stars' `constellations` in, for the names of the figures: a dynamic import by default. */
54
56
  constellations?: () => Promise<typeof import("@johnmorrisdotca/hoshi-stars/constellations")>;
57
+ /**
58
+ * The boxes the layers placed before the sky take in the picture just drawn (the places' names and marks, the markers' labels, the bodies' and the cities' names), as left, top, width and height from the picture's top left. No star name, ring or figure name goes over one.
59
+ * Read when the names are laid out; the element refills the same list, so nothing is made at a draw.
60
+ */
61
+ taken?: () => readonly {
62
+ left: number;
63
+ top: number;
64
+ width: number;
65
+ height: number;
66
+ }[];
55
67
  /** Brings a sky culture of hoshi-stars in (`western`, `japanese` or `chinese`): a dynamic import of the culture by default, a page's own (or a test's) where it has one. */
56
68
  cultures?: (id: string) => Promise<Culture>;
57
69
  }
package/dist/sky/host.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { canvasRatio } from "../markers/project.js";
2
2
  import { boxCovered, pathOutside, touches } from "./cover.js";
3
+ import { cultureLoaders } from "./culture-source.js";
3
4
  import { createCultureLines } from "./culture-lines.js";
4
5
  import { areaInHull, hullOf, nearestSegment, placeBox, visibleCentre } from "./figure-pick.js";
5
6
  import { inKeep, keepBox, touchesKeep } from "./keep-clear.js";
@@ -7,15 +8,8 @@ import { inKeep, keepBox, touchesKeep } from "./keep-clear.js";
7
8
  export const SKY_STYLE = "#sk-canvas{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}#sk-names{position:absolute;inset:0;overflow:hidden;pointer-events:none}" +
8
9
  ".sk-name,.sk-figure,.sk-constellation,.sk-designation{position:absolute;left:0;top:0;margin:0;white-space:nowrap;pointer-events:none;font-family:var(--hoshi-label-font,Michroma,system-ui,sans-serif);font-size:calc(var(--hoshi-label-size,11) * 1px);font-weight:var(--hoshi-label-weight,400);color:var(--hoshi-label-colour,#e9f1ff);letter-spacing:calc(var(--hoshi-label-letter-spacing,.14) * 1em);font-variant:var(--hoshi-label-case-variant,small-caps);text-transform:var(--hoshi-label-case-transform,none);text-shadow:0 0 calc(var(--hoshi-label-halo-width,3) * 1px) var(--hoshi-label-halo,#0a1230)}" +
9
10
  ".sk-designation{font-family:var(--hoshi-label-designation-font,ui-monospace,monospace);font-size:calc(var(--hoshi-label-designation-size,9) * 1px);color:var(--hoshi-label-designation-colour,#b8c6e0);letter-spacing:0;font-variant:normal;text-transform:none}" +
10
- ".sk-figure{color:var(--hoshi-label-colour,#e9f1ff);opacity:0;transition:opacity .15s ease-out}.sk-constellation{font-size:calc(var(--hoshi-label-size,11) * .9px);color:var(--hoshi-label-constellation-colour,#9db0d3);letter-spacing:.22em;opacity:.85}@media (prefers-reduced-motion:reduce){.sk-figure{transition:none}}.sk-ruler{visibility:hidden}.sk-live{position:absolute;left:0;top:0;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}[hidden]{display:none}";
11
- /**
12
- * The sky cultures besides the IAU's, each loaded by a dynamic import of its own, only when a page asks for it: a page that never sets `chinese` never downloads it. (The imports are written out, one for each, so that a bundler makes a file of each.)
13
- */
14
- const CULTURES = {
15
- western: async () => (await import("@johnmorrisdotca/hoshi-stars/cultures/western")).western,
16
- japanese: async () => (await import("@johnmorrisdotca/hoshi-stars/cultures/japanese")).japanese,
17
- chinese: async () => (await import("@johnmorrisdotca/hoshi-stars/cultures/chinese")).chinese,
18
- };
11
+ ".sk-figure{color:var(--hoshi-label-colour,#e9f1ff);opacity:0;transition:opacity .15s ease-out}.sk-constellation{font-size:calc(var(--hoshi-label-size,11) * .9px);color:var(--hoshi-label-constellation-colour,#9db0d3);letter-spacing:.22em;opacity:.85}@media (prefers-reduced-motion:reduce){.sk-figure{transition:none}}.sk-ruler{visibility:hidden}.sk-live{position:absolute;left:0;top:0;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}" +
12
+ "button.sk-name,button.sk-hit{background:transparent;border:0;padding:0;cursor:pointer;pointer-events:auto}button.sk-hit{width:28px;height:28px}button.sk-name:focus-visible,button.sk-hit:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}[hidden]{display:none}";
19
13
  const warnedCultures = new Set();
20
14
  const NAME_POOL = 40;
21
15
  /** What other layers of the element draw as labels over the sky (bodies, satellites, places, cities): a constellation's name keeps off them. */
@@ -46,6 +40,11 @@ export function createSkyHost(options) {
46
40
  let figureName;
47
41
  /** The figure the pointer rests on, and the one a click or tap picked (IAU abbreviations): the lines of either are lit and the name of one is shown. */
48
42
  let hoverAbbr = null;
43
+ /** What a press on a named star tells the page, kept with the button that shows the name. */
44
+ const starOf = new Map();
45
+ /** A focusable point on each figure in view, and the abbreviation it picks. */
46
+ const hits = [];
47
+ const hitAbbr = new Map();
49
48
  let pickAbbr = null;
50
49
  /** The abbreviation the name now shown (the figure name's span) is of, and the timer that hides it after it has faded. */
51
50
  let shownAbbr = null;
@@ -87,7 +86,10 @@ export function createSkyHost(options) {
87
86
  let covered;
88
87
  /** The places the page asked to keep clear, and as boxes from the picture's top left: measured when something has changed (a resize, a new list), never at each frame. */
89
88
  let keepList = [];
89
+ const pageKeep = [];
90
+ /** What the names keep off: the page's places (`pageKeep`) and the boxes the layers placed before the sky take (the pool `ext`, refilled at each layout). */
90
91
  const keep = [];
92
+ const ext = [];
91
93
  let keepStale = true;
92
94
  let keepWatch;
93
95
  let keepEvents = false;
@@ -105,7 +107,7 @@ export function createSkyHost(options) {
105
107
  queuedFrame = true;
106
108
  const run = () => {
107
109
  queuedFrame = false;
108
- if (module && last && (keep.length > 0 || options.attribute("constellation-names") !== null || shownAbbr !== null))
110
+ if (module && last && (pageKeep.length > 0 || options.attribute("constellation-names") !== null || shownAbbr !== null))
109
111
  compute();
110
112
  };
111
113
  if (typeof globalThis.requestAnimationFrame === "function")
@@ -132,7 +134,7 @@ export function createSkyHost(options) {
132
134
  const measureKeep = (rewatch) => {
133
135
  keepStale = false;
134
136
  const items = keepItems();
135
- keep.length = 0;
137
+ pageKeep.length = 0;
136
138
  if (items.length === 0) {
137
139
  keepWatch?.disconnect();
138
140
  return;
@@ -140,7 +142,7 @@ export function createSkyHost(options) {
140
142
  const host = root.host;
141
143
  const own = host.getBoundingClientRect();
142
144
  for (const item of items)
143
- keep.push(keepBox(item, own));
145
+ pageKeep.push(keepBox(item, own));
144
146
  if (!rewatch)
145
147
  return;
146
148
  // a box that grows or shrinks is read again and the layer laid out again; the observer is set again only when the list has changed
@@ -166,9 +168,27 @@ export function createSkyHost(options) {
166
168
  function markStale() {
167
169
  keepStale = true;
168
170
  // scrolled or resized while something is kept clear: the names are laid out again at the next frame, once however many events
169
- if (keep.length > 0)
171
+ if (pageKeep.length > 0)
170
172
  later();
171
173
  }
174
+ /** Joins the page's places and the boxes of the layers placed before: the objects are reused, nothing is made at a layout. */
175
+ function mergeKeep() {
176
+ keep.length = 0;
177
+ for (const one of pageKeep)
178
+ keep.push(one);
179
+ const others = options.taken?.();
180
+ if (!others)
181
+ return;
182
+ for (let i = 0; i < others.length; i += 1) {
183
+ const o = others[i];
184
+ const one = (ext[i] ??= { l: 0, t: 0, r: 0, b: 0 });
185
+ one.l = o.left;
186
+ one.t = o.top;
187
+ one.r = o.left + o.width;
188
+ one.b = o.top + o.height;
189
+ keep.push(one);
190
+ }
191
+ }
172
192
  let keepRewatch = true;
173
193
  const attach = () => {
174
194
  if (attached)
@@ -179,10 +199,10 @@ export function createSkyHost(options) {
179
199
  canvas.setAttribute("aria-hidden", "true");
180
200
  box = doc.createElement("div");
181
201
  box.id = "sk-names";
182
- box.setAttribute("aria-hidden", "true");
183
202
  figureName = doc.createElement("span");
184
203
  figureName.className = "sk-figure";
185
204
  figureName.hidden = true;
205
+ figureName.setAttribute("aria-hidden", "true");
186
206
  box.append(figureName);
187
207
  ruler = doc.createElement("span");
188
208
  ruler.className = "sk-ruler";
@@ -238,13 +258,23 @@ export function createSkyHost(options) {
238
258
  host.addEventListener("pointerup", (event) => {
239
259
  const start = down;
240
260
  down = undefined;
241
- if (!start || start.id !== event.pointerId || !lines || !drawStrokes)
261
+ if (!start || start.id !== event.pointerId)
242
262
  return;
243
263
  const here = place(event);
244
264
  // a press that did not move, and was not held: a click or a tap, not the start of a turn
245
265
  if (Math.hypot(here.x - start.x, here.y - start.y) > 6 || event.timeStamp - start.at > 600)
246
266
  return;
247
- setPick(figureAt(here.x, here.y), true);
267
+ const star = starAt(here.x, here.y);
268
+ if (star) {
269
+ emitStar(star, event.pointerType || "mouse");
270
+ return;
271
+ }
272
+ if (!lines || !drawStrokes)
273
+ return;
274
+ const figure = figureAt(here.x, here.y);
275
+ setPick(figure, true);
276
+ if (figure)
277
+ emitFigure(figure, event.pointerType || "mouse");
248
278
  });
249
279
  host.addEventListener("keydown", (event) => {
250
280
  if (!lines || !drawStrokes || event.altKey || event.ctrlKey || event.metaKey)
@@ -333,11 +363,57 @@ export function createSkyHost(options) {
333
363
  if (send) {
334
364
  emit("chikyu-constellation-pick", abbreviation === null ? null : detailOf(abbreviation));
335
365
  // a pick is read out, with the figure's name in the page's language; a hover is not (it would be too much to hear)
336
- if (live)
337
- live.textContent = abbreviation === null ? "" : options.language() === "ja" ? `${figureText(abbreviation)}を選択` : `${figureText(abbreviation)} selected`;
366
+ sayPick(abbreviation === null ? "" : figureText(abbreviation));
338
367
  }
339
368
  drawLines();
340
369
  }
370
+ /** Read a pick out, with its name in the page's language. An empty text clears it. */
371
+ function sayPick(text) {
372
+ if (live)
373
+ live.textContent = text === "" ? "" : options.language() === "ja" ? `${text}を選択` : `${text} selected`;
374
+ }
375
+ /** A named star that was pressed or tapped. `name` is the name as drawn. */
376
+ function emitStar(star, pointerType) {
377
+ emit("chikyu-sky-pick", { kind: "star", hr: star.hr, name: star.name, designation: star.designation, x: star.x, y: star.y, pointerType });
378
+ sayPick(star.name);
379
+ }
380
+ /** A constellation figure that was pressed or tapped. */
381
+ function emitFigure(abbreviation, pointerType) {
382
+ emit("chikyu-sky-pick", { kind: "constellation", abbreviation, pointerType });
383
+ }
384
+ /** The named star under a point: its name box first, else the nearest star point within reach. Culled names are not there. */
385
+ function starAt(x, y) {
386
+ const named = names;
387
+ const sky = module;
388
+ if (!named || !sky)
389
+ return null;
390
+ const drawn = (label) => ({
391
+ hr: label.hr,
392
+ name: sky.labelText(label.text, named.style),
393
+ designation: label.designation,
394
+ x: label.x,
395
+ y: label.y,
396
+ });
397
+ for (const [index, label] of named.labels.entries()) {
398
+ if (culled[index])
399
+ continue;
400
+ if (x >= label.x0 && x <= label.x1 && y >= label.y0 && y <= label.y1)
401
+ return drawn(label);
402
+ }
403
+ let best = null;
404
+ let bestD = Number.POSITIVE_INFINITY;
405
+ for (const [index, label] of named.labels.entries()) {
406
+ if (culled[index])
407
+ continue;
408
+ const reach = Math.max(label.ring, 14);
409
+ const d = (x - label.x) ** 2 + (y - label.y) ** 2;
410
+ if (d <= reach * reach && d < bestD) {
411
+ bestD = d;
412
+ best = drawn(label);
413
+ }
414
+ }
415
+ return best;
416
+ }
341
417
  /** Picks the next (or the previous) figure in view, from the left: the keyboard's way to pick. */
342
418
  function cycle(step) {
343
419
  if (!lines)
@@ -348,6 +424,8 @@ export function createSkyHost(options) {
348
424
  const at = inView.findIndex((f) => f.abbreviation === pickAbbr);
349
425
  const next = inView[(at < 0 ? (step > 0 ? 0 : inView.length - 1) : (at + step + inView.length) % inView.length)];
350
426
  setPick(next.abbreviation, true);
427
+ // the key picks as Enter on a figure's button does, so the page hears every pick of the reader's the same way
428
+ emitFigure(next.abbreviation, "keyboard");
351
429
  }
352
430
  const takenAbbr = [];
353
431
  /** Whether a box may stand: clear of bodies and kept-clear areas, and clear of the names already placed (those of `ignore` aside). */
@@ -498,6 +576,7 @@ export function createSkyHost(options) {
498
576
  while (figurePool.length <= shownFigures) {
499
577
  const span = doc.createElement("span");
500
578
  span.className = "sk-constellation";
579
+ span.setAttribute("aria-hidden", "true");
501
580
  box.append(span);
502
581
  figurePool.push(span);
503
582
  }
@@ -578,10 +657,21 @@ export function createSkyHost(options) {
578
657
  }
579
658
  const shown = names.labels.length;
580
659
  while (pool.length < Math.min(NAME_POOL, shown)) {
581
- const name = doc.createElement("span");
660
+ const name = doc.createElement("button");
582
661
  name.className = "sk-name";
662
+ name.setAttribute("type", "button");
663
+ name.addEventListener("click", (event) => {
664
+ // a pointer already sent the pick from the press; Enter and Space are a click with no pointer (detail 0)
665
+ if (event.detail !== 0)
666
+ return;
667
+ const star = starOf.get(name);
668
+ if (!star || name.hidden)
669
+ return;
670
+ emitStar(star, "keyboard");
671
+ });
583
672
  const designation = doc.createElement("span");
584
673
  designation.className = "sk-designation";
674
+ designation.setAttribute("aria-hidden", "true");
585
675
  box.append(name, designation);
586
676
  pool.push(name);
587
677
  designations.push(designation);
@@ -595,11 +685,14 @@ export function createSkyHost(options) {
595
685
  name.hidden = true;
596
686
  designation.hidden = true;
597
687
  }
688
+ starOf.delete(name);
598
689
  continue;
599
690
  }
600
691
  const text = module.labelText(label.text, names.style);
601
692
  if (name.textContent !== text)
602
693
  name.textContent = text;
694
+ name.setAttribute("aria-label", text);
695
+ starOf.set(name, { hr: label.hr, name: text, designation: label.designation, x: label.x, y: label.y });
603
696
  name.hidden = false;
604
697
  const shift = label.anchor === "end" ? "-100%" : label.anchor === "middle" ? "-50%" : "0";
605
698
  name.style.transform = `translate(${Math.round(label.textX)}px,${Math.round(label.textY)}px) translate(${shift},-100%)`;
@@ -678,6 +771,59 @@ export function createSkyHost(options) {
678
771
  for (const el of figurePool)
679
772
  el.hidden = true;
680
773
  shownFigures = 0;
774
+ for (const hit of hits)
775
+ hit.hidden = true;
776
+ }
777
+ /**
778
+ * One focusable point on each figure that is in view, at the middle of the part of it on the picture. Enter picks it. Nothing is drawn: the buttons are the way a keyboard reaches a figure, and they are moved only when the picture is laid out.
779
+ */
780
+ function placeFigureHits(frame) {
781
+ if (!box || !lines) {
782
+ for (const hit of hits)
783
+ hit.hidden = true;
784
+ return;
785
+ }
786
+ const placed = [];
787
+ const at = { x: 0, y: 0 };
788
+ const blocked = keep.length > 0 ? blockedAt : covered;
789
+ for (const figure of lines.figures) {
790
+ if (figure.end <= figure.start)
791
+ continue;
792
+ if (!visibleCentre(lines.segments, figure.start, figure.end, frame.width, frame.height, blocked, at))
793
+ continue;
794
+ placed.push({ abbreviation: figure.abbreviation, x: at.x, y: at.y });
795
+ }
796
+ placed.sort((a, b) => a.x - b.x);
797
+ while (hits.length < placed.length) {
798
+ const hit = doc.createElement("button");
799
+ hit.className = "sk-hit";
800
+ hit.setAttribute("type", "button");
801
+ hit.addEventListener("click", (event) => {
802
+ if (event.detail !== 0)
803
+ return;
804
+ const abbreviation = hitAbbr.get(hit);
805
+ if (!abbreviation || hit.hidden)
806
+ return;
807
+ setPick(abbreviation, true);
808
+ emitFigure(abbreviation, "keyboard");
809
+ });
810
+ box.append(hit);
811
+ hits.push(hit);
812
+ }
813
+ for (let i = 0; i < hits.length; i += 1) {
814
+ const hit = hits[i];
815
+ const figure = placed[i];
816
+ if (!figure) {
817
+ hit.hidden = true;
818
+ hitAbbr.delete(hit);
819
+ continue;
820
+ }
821
+ const text = figureText(figure.abbreviation);
822
+ hit.setAttribute("aria-label", text);
823
+ hit.hidden = false;
824
+ hit.style.transform = `translate(${Math.round(figure.x)}px,${Math.round(figure.y)}px) translate(-50%,-50%)`;
825
+ hitAbbr.set(hit, figure.abbreviation);
826
+ }
681
827
  }
682
828
  /** The settings no longer ask for the lines: a figure that was picked is let go, and the page is told. */
683
829
  function letGo() {
@@ -702,11 +848,11 @@ export function createSkyHost(options) {
702
848
  const id = raw === null || raw.trim() === "" ? "iau" : raw.trim().toLowerCase();
703
849
  if (id === "iau")
704
850
  return id;
705
- if (Object.hasOwn(CULTURES, id) && !cultureFailed.has(id))
851
+ if (Object.hasOwn(cultureLoaders(), id) && !cultureFailed.has(id))
706
852
  return id;
707
853
  if (!warnedCultures.has(id)) {
708
854
  warnedCultures.add(id);
709
- console.warn(`chikyu-earth: constellation-culture="${id}" is not a sky culture here (iau, ${Object.keys(CULTURES).join(", ")}): the IAU's constellations are used.`);
855
+ console.warn(`chikyu-earth: constellation-culture="${id}" is not a sky culture here (${["iau", ...Object.keys(cultureLoaders())].join(", ")}): the IAU's constellations are used.`);
710
856
  }
711
857
  return "iau";
712
858
  };
@@ -714,7 +860,7 @@ export function createSkyHost(options) {
714
860
  if (cultureLoading.has(id))
715
861
  return;
716
862
  cultureLoading.add(id);
717
- void Promise.all([(options.cultures ?? ((name) => CULTURES[name]()))(id), import("@johnmorrisdotca/hoshi-stars/lines")])
863
+ void Promise.all([(options.cultures ?? ((name) => cultureLoaders()[name]()))(id), import("@johnmorrisdotca/hoshi-stars/lines")])
718
864
  .then(([loaded, library]) => {
719
865
  const info = new Map();
720
866
  const figures = [];
@@ -855,6 +1001,7 @@ export function createSkyHost(options) {
855
1001
  measureKeep(keepRewatch);
856
1002
  keepRewatch = false;
857
1003
  }
1004
+ mergeKeep();
858
1005
  takenStale = true;
859
1006
  hulls.length = 0;
860
1007
  if (names)
@@ -864,6 +1011,7 @@ export function createSkyHost(options) {
864
1011
  placeNames();
865
1012
  placeConstellationNames(frame);
866
1013
  drawLines();
1014
+ placeFigureHits(frame);
867
1015
  }
868
1016
  /** The stars that are named at the last frame: each one's own point on the screen (the label's anchor) and its name, from the picture's top left, without the names the browser's measure left out. */
869
1017
  const starPoints = () => {
@@ -933,6 +1081,10 @@ export function createSkyHost(options) {
933
1081
  configure();
934
1082
  compute();
935
1083
  },
1084
+ relayout() {
1085
+ if (module && wanted() && last)
1086
+ compute();
1087
+ },
936
1088
  setKeepClear(areas) {
937
1089
  keepList = areas ? [...areas] : [];
938
1090
  keepRewatch = true;