@johnmorrisdotca/chikyu-earth 0.31.0 → 0.33.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 (46) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/NOTICE.md +10 -1
  3. package/README.md +32 -2
  4. package/dist/catalogue/fleets.d.ts +70 -0
  5. package/dist/catalogue/fleets.js +66 -0
  6. package/dist/catalogue/index.d.ts +5 -0
  7. package/dist/catalogue/index.js +7 -0
  8. package/dist/catalogue/kinds.d.ts +143 -0
  9. package/dist/catalogue/kinds.js +121 -0
  10. package/dist/catalogue/omm.d.ts +44 -0
  11. package/dist/catalogue/omm.js +92 -0
  12. package/dist/catalogue/orbit.d.ts +95 -0
  13. package/dist/catalogue/orbit.js +91 -0
  14. package/dist/catalogue/pack.d.ts +193 -0
  15. package/dist/catalogue/pack.js +327 -0
  16. package/dist/data/meteor-iau.d.ts +79 -0
  17. package/dist/data/meteor-iau.js +77 -0
  18. package/dist/data/meteor-showers.js +24 -20
  19. package/dist/data-door.d.ts +2 -0
  20. package/dist/data-door.js +4 -2
  21. package/dist/door/index.d.ts +1 -0
  22. package/dist/door/index.js +1 -0
  23. package/dist/door/packed.d.ts +64 -0
  24. package/dist/door/packed.js +91 -0
  25. package/dist/meteors/index.d.ts +2 -0
  26. package/dist/meteors/index.js +2 -0
  27. package/dist/meteors/parents.d.ts +45 -0
  28. package/dist/meteors/parents.js +67 -0
  29. package/dist/realistic/body-label.d.ts +126 -0
  30. package/dist/realistic/body-label.js +187 -0
  31. package/dist/realistic/earth.d.ts +8 -0
  32. package/dist/realistic/earth.js +29 -0
  33. package/dist/realistic/element.d.ts +35 -0
  34. package/dist/realistic/element.js +78 -2
  35. package/dist/realistic/index.d.ts +1 -0
  36. package/dist/realistic/index.js +1 -0
  37. package/dist/realistic/textures.d.ts +8 -0
  38. package/dist/satellites/source.d.ts +4 -0
  39. package/dist/satellites/source.js +2 -2
  40. package/dist/sky/host.d.ts +55 -0
  41. package/dist/sky/host.js +382 -0
  42. package/dist/space/element.d.ts +35 -0
  43. package/dist/space/element.js +78 -2
  44. package/dist/space/scene.d.ts +8 -0
  45. package/dist/space/scene.js +34 -0
  46. package/package.json +12 -2
@@ -0,0 +1,382 @@
1
+ import { canvasRatio } from "../markers/project.js";
2
+ /** The styles of the layer, for an element to add to its own (`#sk-canvas`, `#sk-names` and the labels in its shadow root). */
3
+ 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}" +
4
+ ".sk-name,.sk-figure,.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)}" +
5
+ ".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}" +
6
+ ".sk-figure{color:var(--hoshi-label-colour,#e9f1ff)}[hidden]{display:none}";
7
+ const NAME_POOL = 40;
8
+ /** The attributes this layer reads. */
9
+ export const SKY_ATTRIBUTES = ["star-names", "star-names-magnitude", "constellation-lines"];
10
+ /**
11
+ * Makes the layer of one element, inside its shadow root. Nothing of hoshi-stars is loaded, and nothing is added to the root, until one of the three attributes is there.
12
+ *
13
+ * @param options - The attribute reader, the language and the shadow root.
14
+ * @returns The host.
15
+ */
16
+ export function createSkyHost(options) {
17
+ const { root } = options;
18
+ const doc = root.ownerDocument;
19
+ let module;
20
+ let loading = false;
21
+ let failed = false;
22
+ let names;
23
+ let lines;
24
+ let last = null;
25
+ let renders = 0;
26
+ let style = {};
27
+ let canvas;
28
+ let box;
29
+ const pool = [];
30
+ const designations = [];
31
+ let figureName;
32
+ let attached = false;
33
+ let covered;
34
+ /** The language the names were last laid out in: the page may change its language after the element was made, so it is read again at each draw. */
35
+ let usedLang;
36
+ /** The names drawn at the last frame that were left out because they ran over another as the browser draws them (by label), and how many names are shown. */
37
+ const culled = [];
38
+ let drawnNames = 0;
39
+ const wanted = () => options.attribute("star-names") !== null || options.attribute("constellation-lines") !== null;
40
+ const attach = () => {
41
+ if (attached)
42
+ return;
43
+ attached = true;
44
+ canvas = doc.createElement("canvas");
45
+ canvas.id = "sk-canvas";
46
+ canvas.setAttribute("aria-hidden", "true");
47
+ box = doc.createElement("div");
48
+ box.id = "sk-names";
49
+ box.setAttribute("aria-hidden", "true");
50
+ figureName = doc.createElement("span");
51
+ figureName.className = "sk-figure";
52
+ figureName.hidden = true;
53
+ box.append(figureName);
54
+ root.append(canvas, box);
55
+ const host = root.host;
56
+ const place = (event) => {
57
+ const rect = host.getBoundingClientRect();
58
+ return { x: event.clientX - rect.left, y: event.clientY - rect.top };
59
+ };
60
+ // a mouse lights the figure it rests on and lets go when it leaves; a finger lights what it touches and the pick stays until the next touch
61
+ host.addEventListener("pointermove", (event) => {
62
+ if (!lines || event.pointerType === "touch")
63
+ return;
64
+ const at = place(event);
65
+ if (lines.point(at.x, at.y))
66
+ drawLines();
67
+ });
68
+ host.addEventListener("pointerleave", (event) => {
69
+ if (!lines || event.pointerType === "touch")
70
+ return;
71
+ if (lines.point())
72
+ drawLines();
73
+ });
74
+ host.addEventListener("pointerdown", (event) => {
75
+ if (!lines || event.pointerType !== "touch")
76
+ return;
77
+ const at = place(event);
78
+ if (lines.point(at.x, at.y))
79
+ drawLines();
80
+ });
81
+ };
82
+ const sizeCanvas = (frame) => {
83
+ const ratio = canvasRatio(frame.width, frame.height, globalThis.devicePixelRatio || 1);
84
+ const w = Math.max(1, Math.round(frame.width * ratio));
85
+ const h = Math.max(1, Math.round(frame.height * ratio));
86
+ if (canvas.width !== w || canvas.height !== h) {
87
+ canvas.width = w;
88
+ canvas.height = h;
89
+ }
90
+ const context = canvas.getContext("2d");
91
+ context?.setTransform(ratio, 0, 0, ratio, 0, 0);
92
+ return context;
93
+ };
94
+ /** The lines and the rings, and the names: drawn again from what `update` laid out. */
95
+ function drawLines() {
96
+ const frame = last;
97
+ if (!frame || !canvas || !module)
98
+ return;
99
+ const context = sizeCanvas(frame);
100
+ if (!context)
101
+ return;
102
+ renders += 1;
103
+ context.clearRect(0, 0, frame.width, frame.height);
104
+ if (lines && lines.count > 0) {
105
+ context.lineWidth = 1;
106
+ context.lineCap = "round";
107
+ context.strokeStyle = "#cfe0ff";
108
+ for (const figure of lines.figures) {
109
+ const opacity = lines.opacityOf(figure);
110
+ if (opacity <= 0)
111
+ continue;
112
+ context.globalAlpha = opacity;
113
+ context.beginPath();
114
+ for (let i = figure.start; i < figure.end; i += 1) {
115
+ context.moveTo(lines.segments[i * 4], lines.segments[i * 4 + 1]);
116
+ context.lineTo(lines.segments[i * 4 + 2], lines.segments[i * 4 + 3]);
117
+ }
118
+ context.stroke();
119
+ }
120
+ context.globalAlpha = 1;
121
+ }
122
+ if (names) {
123
+ const s = names.style;
124
+ context.lineWidth = s.ringWidth;
125
+ context.strokeStyle = s.ringColour;
126
+ for (const [index, label] of names.labels.entries()) {
127
+ if (culled[index])
128
+ continue;
129
+ if (label.ring > 0) {
130
+ context.beginPath();
131
+ context.arc(label.x, label.y, label.ring, 0, Math.PI * 2);
132
+ context.stroke();
133
+ }
134
+ if (label.leader) {
135
+ context.strokeStyle = s.leaderColour;
136
+ context.beginPath();
137
+ context.moveTo(label.leaderX0, label.leaderY0);
138
+ context.lineTo(label.leaderX1, label.leaderY1);
139
+ context.stroke();
140
+ context.strokeStyle = s.ringColour;
141
+ }
142
+ }
143
+ }
144
+ // the picked figure's name
145
+ if (figureName) {
146
+ const name = lines?.name;
147
+ if (name) {
148
+ figureName.hidden = false;
149
+ if (figureName.textContent !== name.text)
150
+ figureName.textContent = name.text;
151
+ figureName.style.transform = `translate(${Math.round(name.x)}px,${Math.round(name.y)}px) translate(-50%,-100%)`;
152
+ }
153
+ else
154
+ figureName.hidden = true;
155
+ }
156
+ }
157
+ function placeNames() {
158
+ if (!box || !names) {
159
+ drawnNames = 0;
160
+ return;
161
+ }
162
+ const shown = names.labels.length;
163
+ while (pool.length < Math.min(NAME_POOL, shown)) {
164
+ const name = doc.createElement("span");
165
+ name.className = "sk-name";
166
+ const designation = doc.createElement("span");
167
+ designation.className = "sk-designation";
168
+ box.append(name, designation);
169
+ pool.push(name);
170
+ designations.push(designation);
171
+ }
172
+ for (let i = 0; i < pool.length; i += 1) {
173
+ const name = pool[i];
174
+ const designation = designations[i];
175
+ const label = i < shown ? names.labels[i] : undefined;
176
+ if (!label) {
177
+ if (!name.hidden) {
178
+ name.hidden = true;
179
+ designation.hidden = true;
180
+ }
181
+ continue;
182
+ }
183
+ const text = module.labelText(label.text, names.style);
184
+ if (name.textContent !== text)
185
+ name.textContent = text;
186
+ name.hidden = false;
187
+ const shift = label.anchor === "end" ? "-100%" : label.anchor === "middle" ? "-50%" : "0";
188
+ name.style.transform = `translate(${Math.round(label.textX)}px,${Math.round(label.textY)}px) translate(${shift},-100%)`;
189
+ if (label.designation && names.style.designation === "below") {
190
+ if (designation.textContent !== label.designation)
191
+ designation.textContent = label.designation;
192
+ designation.hidden = false;
193
+ designation.style.transform = `translate(${Math.round(label.designationX)}px,${Math.round(label.designationY)}px) translate(${shift},-100%)`;
194
+ }
195
+ else
196
+ designation.hidden = true;
197
+ }
198
+ cullOverlaps(shown);
199
+ }
200
+ /**
201
+ * hoshi-stars lays the names out by the width it works a name to have (a letter is about 0.6 of the size, a Japanese letter the whole size), and the browser draws them with the font it has: Michroma where it has loaded, another font where it has not, or where
202
+ * the page has none that has the letters (a Japanese name on a machine with no Japanese font). The two can differ, so the names are measured as they are drawn, and a name that runs over one placed before it (the brighter star's) is left out, with its ring.
203
+ */
204
+ function cullOverlaps(shown) {
205
+ culled.length = 0;
206
+ let visible = 0;
207
+ const kept = [];
208
+ for (let i = 0; i < shown; i += 1) {
209
+ const name = pool[i];
210
+ if (!name || name.hidden) {
211
+ culled.push(true);
212
+ continue;
213
+ }
214
+ if (typeof name.getBoundingClientRect !== "function") {
215
+ culled.push(false);
216
+ visible += 1;
217
+ continue;
218
+ }
219
+ const rect = name.getBoundingClientRect();
220
+ const over = kept.some((one) => rect.left < one.r && rect.right > one.l && rect.top < one.b && rect.bottom > one.t);
221
+ if (over) {
222
+ name.hidden = true;
223
+ designations[i].hidden = true;
224
+ culled.push(true);
225
+ continue;
226
+ }
227
+ kept.push({ l: rect.left, t: rect.top, r: rect.right, b: rect.bottom });
228
+ culled.push(false);
229
+ visible += 1;
230
+ }
231
+ drawnNames = visible;
232
+ }
233
+ const vars = () => {
234
+ if (!box || !module)
235
+ return;
236
+ const properties = module.labelStyleVars(style);
237
+ for (const [name, value] of Object.entries(properties))
238
+ box.style.setProperty(name, value);
239
+ // the case is drawn by the labels' own CSS (small capitals, or the text itself written in capitals or lower case by `labelText`)
240
+ box.style.setProperty("--hoshi-label-case-variant", (style.case ?? "small-caps") === "small-caps" ? "small-caps" : "normal");
241
+ };
242
+ const configure = () => {
243
+ if (!module)
244
+ return;
245
+ const count = options.attribute("star-names");
246
+ const magnitude = options.attribute("star-names-magnitude");
247
+ const settings = module.starNamesFromAttributes(count, magnitude);
248
+ const strength = module.lineStrengthFromAttribute(options.attribute("constellation-lines"));
249
+ const lang = options.language();
250
+ usedLang = lang;
251
+ if (settings) {
252
+ if (!names)
253
+ names = module.createStarNames({ ...settings, lang, style });
254
+ else
255
+ names.set({ ...settings, lang, style });
256
+ }
257
+ else
258
+ names = undefined;
259
+ if (strength !== undefined) {
260
+ if (!lines)
261
+ lines = module.createFigureLines({ strength, lang, style });
262
+ else
263
+ lines.set({ strength, lang, style });
264
+ }
265
+ else
266
+ lines = undefined;
267
+ vars();
268
+ };
269
+ const load = () => {
270
+ if (module || loading || failed || !wanted())
271
+ return;
272
+ loading = true;
273
+ attach();
274
+ void import("@johnmorrisdotca/hoshi-stars/sky-labels")
275
+ .then(async (loaded) => {
276
+ module = loaded;
277
+ if (!style.font)
278
+ await options.loadFont().catch(() => undefined);
279
+ configure();
280
+ loading = false;
281
+ compute();
282
+ })
283
+ .catch((error) => {
284
+ loading = false;
285
+ failed = true;
286
+ options.onError(error);
287
+ });
288
+ };
289
+ /** Lays the names and lines out for the last frame, and draws them. */
290
+ function compute() {
291
+ const frame = last;
292
+ if (!frame || !module)
293
+ return;
294
+ if (usedLang !== undefined && options.language() !== usedLang)
295
+ configure();
296
+ const discs = frame.discs;
297
+ covered = discs.length === 0 ? undefined : (x, y) => discs.some((d) => (x - d.x) * (x - d.x) + (y - d.y) * (y - d.y) <= d.radius * d.radius);
298
+ const view = { width: frame.width, height: frame.height };
299
+ if (names)
300
+ names.update(frame.project, view, covered);
301
+ if (lines)
302
+ lines.update(frame.project, view, names ? names.labels : undefined);
303
+ placeNames();
304
+ drawLines();
305
+ }
306
+ // the family's chooser tells the document when the page's language changes: the names are written again, though nothing else is drawn
307
+ const onLanguage = () => queueMicrotask(() => {
308
+ if (module && wanted() && usedLang !== options.language()) {
309
+ configure();
310
+ compute();
311
+ }
312
+ });
313
+ doc.addEventListener("kazoku-languagechange", onLanguage);
314
+ // a font arrives (Michroma, or the one a Japanese name falls back to): the names are measured as they are drawn, so they are laid out again
315
+ const onFonts = () => {
316
+ if (module && wanted() && last)
317
+ compute();
318
+ };
319
+ doc.fonts?.addEventListener?.("loadingdone", onFonts);
320
+ return {
321
+ frame(next) {
322
+ last = next;
323
+ if (!wanted()) {
324
+ if (attached && canvas)
325
+ canvas.getContext("2d")?.clearRect(0, 0, canvas.width, canvas.height);
326
+ return;
327
+ }
328
+ load();
329
+ if (!next) {
330
+ if (canvas)
331
+ canvas.getContext("2d")?.clearRect(0, 0, canvas.width, canvas.height);
332
+ for (const name of pool)
333
+ name.hidden = true;
334
+ for (const designation of designations)
335
+ designation.hidden = true;
336
+ if (figureName)
337
+ figureName.hidden = true;
338
+ return;
339
+ }
340
+ compute();
341
+ },
342
+ refresh() {
343
+ if (!wanted()) {
344
+ names = undefined;
345
+ lines = undefined;
346
+ if (attached && canvas)
347
+ canvas.getContext("2d")?.clearRect(0, 0, canvas.width, canvas.height);
348
+ for (const name of pool)
349
+ name.hidden = true;
350
+ for (const designation of designations)
351
+ designation.hidden = true;
352
+ if (figureName)
353
+ figureName.hidden = true;
354
+ return;
355
+ }
356
+ if (!module) {
357
+ load();
358
+ return;
359
+ }
360
+ configure();
361
+ compute();
362
+ },
363
+ setStyle(next) {
364
+ style = next;
365
+ if (module) {
366
+ configure();
367
+ compute();
368
+ }
369
+ },
370
+ get stats() {
371
+ return { on: wanted(), loaded: module !== undefined, names: names ? drawnNames : 0, figures: lines?.count ?? 0, picked: lines?.picked?.abbreviation ?? null, renders, lang: usedLang ?? "" };
372
+ },
373
+ dispose() {
374
+ doc.removeEventListener("kazoku-languagechange", onLanguage);
375
+ doc.fonts?.removeEventListener?.("loadingdone", onFonts);
376
+ canvas?.remove();
377
+ box?.remove();
378
+ pool.length = 0;
379
+ designations.length = 0;
380
+ },
381
+ };
382
+ }
@@ -1,5 +1,7 @@
1
1
  import { type ViewController } from "@johnmorrisdotca/kazoku-ui/view-controls";
2
2
  import type { GeoPoint } from "../types.ts";
3
+ import { type BodyLabelSettings } from "../realistic/body-label.ts";
4
+ import type { LabelStyle } from "@johnmorrisdotca/hoshi-stars/sky-labels";
3
5
  import { setThreeLoader } from "../realistic/shared.ts";
4
6
  import type { LightMode } from "../realistic/earth.ts";
5
7
  import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/types.ts";
@@ -162,6 +164,22 @@ export declare class ChikyuSpace extends HTMLElement {
162
164
  */
163
165
  get meteorsStrength(): number;
164
166
  set meteorsStrength(value: number);
167
+ /**
168
+ * The name written on the Earth, as the family's body label: `EARTH` (`地球` on a Japanese page) laid on the globe so it turns with it, the surface showing through the letters. Off (`null`) unless the page sets it. The plain attributes are the family's:
169
+ * `body-label` (`painted`, `etched`, `outline` or `burned`; absent, no label), `body-label-strength` (0 to 1, 0.5), `body-label-repeat` (`once`, `both` or `around`), `body-label-latitude` (degrees), `body-label-facing` (present: always facing the reader),
170
+ * `body-label-font` (a CSS font family the page has loaded; Michroma, fetched once, when left out) and `body-label-fallback-font` (for letters the font has none of, such as Japanese). The property is the same options as an object, or `null`; setting it writes the attributes.
171
+ * Nothing of it is fetched or made until it is first set, it is not drawn while the Earth is under 24 pixels in radius, and nothing is drawn at rest. A three.js handed over with `setThreeLoader` must include `CanvasTexture`, `SphereGeometry`, `MeshLambertMaterial`, `SRGBColorSpace`, `NormalBlending`
172
+ * and `AdditiveBlending`; without them `chikyu-body-label-unavailable` is sent and the name is not drawn.
173
+ */
174
+ get bodyLabel(): BodyLabelSettings | null;
175
+ set bodyLabel(value: Partial<BodyLabelSettings> | null);
176
+ /**
177
+ * The names of the brightest stars and the constellations as faint lines, laid over the sky the page draws (hoshi-stars' `sky-labels`, an optional peer loaded only when one of these is set). The plain attributes are hoshi's: `star-names` (a count of the brightest stars in view and not covered by the
178
+ * Earth, the Moon or the Sun; bare is 10), `star-names-magnitude` (only stars at least that bright) and `constellation-lines` (the 88 figures as lines at this strength, 0 to 1; bare is 0.16): none of them, and nothing is loaded. The figure under the pointer or touched is at full strength and shows its name. Names are in the
179
+ * page's language and never overlap. Nothing is redrawn at rest. `chikyu-sky-unavailable` is sent when hoshi-stars is not there. The property is the look of the names, a partial hoshi-stars `LabelStyle` (font, size, case, ring, leader and the rest).
180
+ */
181
+ get skyStyle(): Partial<LabelStyle>;
182
+ set skyStyle(value: Partial<LabelStyle>);
165
183
  /**
166
184
  * How many times its real thickness the air is drawn, from 1 (the true thickness) to 5 (the attribute `air-thickness`; 3 when the page says nothing): see `<chikyu-earth-realistic>`. While it is above 1 the element says so in a line
167
185
  * under the picture (`air-label="off"` takes the line away, for a page that says it itself).
@@ -315,6 +333,23 @@ export declare class ChikyuSpace extends HTMLElement {
315
333
  shower: string | null;
316
334
  zhr: number;
317
335
  };
336
+ /** The name written on the Earth: whether `body-label` is set, its text, the label is made, and it is showing (it is hidden while the Earth is small). */
337
+ bodyLabel: {
338
+ on: boolean;
339
+ text: string;
340
+ made: boolean;
341
+ showing: boolean;
342
+ };
343
+ /** The names of the stars and the constellation lines: whether one is asked for, whether hoshi-stars is loaded, the names and figures laid out at the last draw, the figure picked, how many times the layer was drawn and the language its names were last laid out in. */
344
+ sky: {
345
+ on: boolean;
346
+ loaded: boolean;
347
+ names: number;
348
+ figures: number;
349
+ picked: string | null;
350
+ renders: number;
351
+ lang: string;
352
+ };
318
353
  };
319
354
  }
320
355
  declare global {
@@ -1,6 +1,8 @@
1
1
  import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
2
2
  import { adoptStyles } from "../adopt.js";
3
3
  import { airFor, readAirThickness } from "../realistic/air.js";
4
+ import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "../realistic/body-label.js";
5
+ import { createSkyHost, SKY_ATTRIBUTES } from "../sky/host.js";
4
6
  import { createGate, frameCap } from "../realistic/gate.js";
5
7
  import { setThreeLoader, takeRenderer } from "../realistic/shared.js";
6
8
  import { NOTES_STYLE, setAirNote } from "../realistic/air-note.js";
@@ -100,7 +102,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
100
102
  * ```
101
103
  */
102
104
  export class ChikyuSpace extends HTMLElement {
103
- static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", "air-thickness", "air-label", "lang"];
105
+ static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, "air-thickness", "air-label", "lang"];
104
106
  #model = newSpaceModel();
105
107
  #mode = "now";
106
108
  #speed = 1;
@@ -108,6 +110,9 @@ export class ChikyuSpace extends HTMLElement {
108
110
  /** The page has set a `speed` since the element came into the page: for a reader who prefers reduced motion, that is the Play that lets meteors start. */
109
111
  #played = false;
110
112
  #note;
113
+ /** The names of the stars and the constellation lines (`star-names`, `constellation-lines`), and the look of the names. */
114
+ #sky;
115
+ #skyStyle = {};
111
116
  #airNote;
112
117
  #gate;
113
118
  #taken;
@@ -157,7 +162,16 @@ export class ChikyuSpace extends HTMLElement {
157
162
  this.#labelBox = root.getElementById("labels");
158
163
  this.#note = root.getElementById("meteor-note");
159
164
  this.#airNote = root.getElementById("air-note");
165
+ this.#sky = createSkyHost({
166
+ root,
167
+ attribute: (name) => this.getAttribute(name),
168
+ language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
169
+ onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-sky-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
170
+ loadFont: loadMichroma,
171
+ });
172
+ this.#sky.setStyle(this.#skyStyle);
160
173
  this.#model.airThickness = readAirThickness(this.getAttribute("air-thickness"));
174
+ this.#applyBodyLabel();
161
175
  setAirNote(this.#airNote, this, this.#model.airThickness);
162
176
  this.#played = false;
163
177
  this.#model.meteors.on = this.#meteorsAsked();
@@ -186,6 +200,8 @@ export class ChikyuSpace extends HTMLElement {
186
200
  this.#tiers[layer] = width;
187
201
  },
188
202
  onLabels: (places) => this.#placeLabels(places),
203
+ onSky: (sky) => this.#sky?.frame(sky),
204
+ onLabelError: (error) => this.dispatchEvent(new CustomEvent("chikyu-body-label-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
189
205
  onSelected: (place) => this.#placeChosen(place),
190
206
  onMoving: () => this.#gate?.request(),
191
207
  onRideLost: () => this.#rideLost(),
@@ -223,6 +239,8 @@ export class ChikyuSpace extends HTMLElement {
223
239
  this.#view = undefined;
224
240
  this.#taken?.release();
225
241
  this.#taken = undefined;
242
+ this.#sky?.dispose();
243
+ this.#sky = undefined;
226
244
  }
227
245
  attributeChangedCallback(name, _old, value) {
228
246
  if (name === "center")
@@ -263,8 +281,17 @@ export class ChikyuSpace extends HTMLElement {
263
281
  this.#model.airThickness = readAirThickness(value);
264
282
  this.#gate?.request();
265
283
  }
266
- else if (name === "meteors-label" || name === "lang")
284
+ else if (name === "meteors-label" || name === "lang") {
267
285
  setMeteorNote(this.#note, this, this.#model.meteors.on);
286
+ if (name === "lang") {
287
+ this.#applyBodyLabel();
288
+ this.#sky?.refresh();
289
+ }
290
+ }
291
+ else if (BODY_LABEL_ATTRIBUTES.includes(name))
292
+ this.#applyBodyLabel();
293
+ else if (SKY_ATTRIBUTES.includes(name))
294
+ this.#sky?.refresh();
268
295
  if (name === "air-thickness" || name === "air-label" || name === "lang")
269
296
  setAirNote(this.#airNote, this, this.#model.airThickness);
270
297
  }
@@ -303,6 +330,53 @@ export class ChikyuSpace extends HTMLElement {
303
330
  set meteorsStrength(value) {
304
331
  this.setAttribute("meteors-strength", String(value));
305
332
  }
333
+ /**
334
+ * The name written on the Earth, as the family's body label: `EARTH` (`地球` on a Japanese page) laid on the globe so it turns with it, the surface showing through the letters. Off (`null`) unless the page sets it. The plain attributes are the family's:
335
+ * `body-label` (`painted`, `etched`, `outline` or `burned`; absent, no label), `body-label-strength` (0 to 1, 0.5), `body-label-repeat` (`once`, `both` or `around`), `body-label-latitude` (degrees), `body-label-facing` (present: always facing the reader),
336
+ * `body-label-font` (a CSS font family the page has loaded; Michroma, fetched once, when left out) and `body-label-fallback-font` (for letters the font has none of, such as Japanese). The property is the same options as an object, or `null`; setting it writes the attributes.
337
+ * Nothing of it is fetched or made until it is first set, it is not drawn while the Earth is under 24 pixels in radius, and nothing is drawn at rest. A three.js handed over with `setThreeLoader` must include `CanvasTexture`, `SphereGeometry`, `MeshLambertMaterial`, `SRGBColorSpace`, `NormalBlending`
338
+ * and `AdditiveBlending`; without them `chikyu-body-label-unavailable` is sent and the name is not drawn.
339
+ */
340
+ get bodyLabel() {
341
+ return readBodyLabel((name) => this.getAttribute(name));
342
+ }
343
+ set bodyLabel(value) {
344
+ for (const name of BODY_LABEL_ATTRIBUTES)
345
+ this.removeAttribute(name);
346
+ if (value === null)
347
+ return;
348
+ this.setAttribute("body-label", value.look ?? "painted");
349
+ if (value.strength !== undefined)
350
+ this.setAttribute("body-label-strength", String(value.strength));
351
+ if (value.repeat !== undefined)
352
+ this.setAttribute("body-label-repeat", value.repeat);
353
+ if (value.latitude !== undefined)
354
+ this.setAttribute("body-label-latitude", String(value.latitude));
355
+ if (value.facing)
356
+ this.setAttribute("body-label-facing", "");
357
+ if (value.font)
358
+ this.setAttribute("body-label-font", value.font);
359
+ if (value.fallbackFont)
360
+ this.setAttribute("body-label-fallback-font", value.fallbackFont);
361
+ }
362
+ /**
363
+ * The names of the brightest stars and the constellations as faint lines, laid over the sky the page draws (hoshi-stars' `sky-labels`, an optional peer loaded only when one of these is set). The plain attributes are hoshi's: `star-names` (a count of the brightest stars in view and not covered by the
364
+ * Earth, the Moon or the Sun; bare is 10), `star-names-magnitude` (only stars at least that bright) and `constellation-lines` (the 88 figures as lines at this strength, 0 to 1; bare is 0.16): none of them, and nothing is loaded. The figure under the pointer or touched is at full strength and shows its name. Names are in the
365
+ * page's language and never overlap. Nothing is redrawn at rest. `chikyu-sky-unavailable` is sent when hoshi-stars is not there. The property is the look of the names, a partial hoshi-stars `LabelStyle` (font, size, case, ring, leader and the rest).
366
+ */
367
+ get skyStyle() {
368
+ return { ...this.#skyStyle };
369
+ }
370
+ set skyStyle(value) {
371
+ this.#skyStyle = { ...value };
372
+ this.#sky?.setStyle(this.#skyStyle);
373
+ }
374
+ /** Puts the name's settings and text right from the attributes (`body-label` and its family, `lang`). */
375
+ #applyBodyLabel() {
376
+ this.#model.bodyLabel.settings = readBodyLabel((name) => this.getAttribute(name));
377
+ this.#model.bodyLabel.text = bodyLabelText((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en");
378
+ this.#gate?.request();
379
+ }
306
380
  /**
307
381
  * How many times its real thickness the air is drawn, from 1 (the true thickness) to 5 (the attribute `air-thickness`; 3 when the page says nothing): see `<chikyu-earth-realistic>`. While it is above 1 the element says so in a line
308
382
  * under the picture (`air-label="off"` takes the line away, for a page that says it itself).
@@ -661,6 +735,8 @@ export class ChikyuSpace extends HTMLElement {
661
735
  camera: { position: [this.#model.pose.p[0], this.#model.pose.p[1], this.#model.pose.p[2]], fov: this.#model.pose.fov },
662
736
  bodies: { look: this.#model.bodies || painter?.looks?.[0] || "plain", painted: this.#model.painted.bodies, moons: this.#model.painted.moons },
663
737
  meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
738
+ bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
739
+ sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, renders: 0, lang: "" },
664
740
  };
665
741
  }
666
742
  #satelliteStats() {
@@ -7,7 +7,9 @@ import { type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
7
7
  import { type ScaleMode } from "./scale.ts";
8
8
  import type { SatelliteRef } from "../satellites/types.ts";
9
9
  import { type RideLook } from "./ride.ts";
10
+ import type { SkyFrame } from "../sky/host.ts";
10
11
  import { type SatelliteState } from "./satellite-layer.ts";
12
+ import { type BodyLabelState } from "../realistic/body-label.ts";
11
13
  import { type MeteorState } from "../meteors/layer.ts";
12
14
  type Three = ThreeParts;
13
15
  /** How much of the view's shorter side the Earth's disc fills at zoom 1 when the page does not say: 0.9, so the atmosphere's glow (8% beyond the disc) is inside the view and never cut. */
@@ -152,6 +154,8 @@ export interface SpaceModel {
152
154
  satellites: SatelliteState;
153
155
  /** Meteors seen from space, on the Earth (src/meteors/layer.ts): off unless the element switches them on. */
154
156
  meteors: MeteorState;
157
+ /** The name written on the Earth (src/realistic/body-label.ts): off unless the element sets it. */
158
+ bodyLabel: BodyLabelState;
155
159
  /** The body or satellite the camera rides along with, or null. */
156
160
  ride: RideState | null;
157
161
  /** Set at each draw: the target of the ride could not be placed (a satellite whose elements are too old, or that is gone), so the ordinary camera was used. */
@@ -280,6 +284,10 @@ export interface SpaceDeps {
280
284
  air?: () => "full" | "light";
281
285
  /** Where each body is on the screen, in CSS pixels in the box, or null when it is behind the camera. Called at each draw. */
282
286
  onLabels?: (places: Record<BodyName, BodyPlace | null>) => void;
287
+ /** Where the sky falls on the screen at this draw, and the bodies that cover it (the names of the stars and the constellation lines are laid over it). Called at each draw. */
288
+ onSky?: (frame: SkyFrame) => void;
289
+ /** The name written on the Earth could not be made. */
290
+ onLabelError?: (error: unknown) => void;
283
291
  /** Where the chosen satellite is on the screen, or null. Called at each draw while a satellite is chosen (and once when it is let go). */
284
292
  onSelected?: (place: {
285
293
  x: number;