@johnmorrisdotca/chikyu-earth 0.31.0 → 0.32.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,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.32.0 - 2026-11-11
6
+
7
+ - **The Earth's name written on the globe, as the family's body label** (MODULES-923). `<chikyu-earth-realistic>` and `<chikyu-space>` take the family's plain attributes `body-label` (`painted`, `etched`, `outline` or `burned`; absent, off), `body-label-strength`, `body-label-repeat`, `body-label-latitude`, `body-label-facing`, `body-label-font` and `body-label-fallback-font`, and the property `bodyLabel` (an object with the same options, or `null`). It writes `EARTH` (`地球` on a Japanese page) on the globe with kazoku-ui's shared `body-label`, so it turns with the Earth and the surface shows through the letters; the default is the family's, Michroma, painted, half strength, once. Off unless set: nothing of it is fetched or made until `body-label` is first set, then the family's label is loaded and Michroma (64 kB) only when the page names no font of its own. No name while the Earth is under 24 pixels in radius or a ride hides it; nothing is drawn at rest. `chikyu-body-label-unavailable` is sent when the three.js handed over lacks a part the label needs (`ThreeParts` gains the optional `CanvasTexture`, `SphereGeometry`, `MeshLambertMaterial`, `SRGBColorSpace`, `NormalBlending` and `AdditiveBlending`). `stats.bodyLabel` has `on`, `text`, `made` and `showing`. New in `@johnmorrisdotca/chikyu-earth/realistic`: `readBodyLabel`, `bodyLabelText`, `BODY_LABEL_ATTRIBUTES`. New guide: A name on the Earth (English and Japanese).
8
+
9
+ - **CI installs Playwright's browsers in bounded, cached steps** (KAZOKU-UI-100). A slow package mirror held `playwright install --with-deps` for the whole job limit on 2026-11-09 and 2026-11-10, so no test ran and the failure read as a test failure. `.github/actions/playwright` (the family's, kazoku-ui's copy is canonical) caches the browsers by Playwright's version, then installs the system libraries in a step of their own: two tries, each cut off after 7 minutes, and a failure that says it is the runner's package mirror and that nothing was run. Free: GitHub-hosted Linux runners and the cache.
10
+ - **`pnpm docs:check` reads a guide's front matter as strict YAML** (KAZOKU-UI-102). A title or description holding a colon and a space without quotes passed the old line reader while GitHub showed "Error in user YAML" above the page. `scripts/docs-site.mjs` (the family's, version `2026-11-10-strict-front-matter`) now fails with the file, the line and a plain sentence on an unquoted colon, an unquoted " #", a value that starts with a YAML character (`[ { & * ! | > % @` or a backtick), a tab, an indented continuation, a key twice and an unclosed quote. It found one more bad guide, `docs/guides/ja/data-door.md`, whose title is now in quotes.
11
+
5
12
  ## 0.31.0 - 2026-11-11
6
13
 
7
14
  - **The data door: sources of your own map and orbit data, with their licence and credit** (MODULES-902, step 3 of MODULES-831). New entry point `@johnmorrisdotca/chikyu-earth/door`: `EarthMapSource` (the Earth's map in tiles for the `day` or `night` layer; the family's `TileSource` of `MapPlace`, `ImageTile`), `earthTiles(base)` (the package's own folder of tiles as a source: what the `tiles` attribute now means), `mapKeys`, `tilePlace`, `tileKeyParts`, `ElementRecordSource` and `elementsFrom(url, info)` (orbit data through `fetchElements`), `createSourceBook`, `OWN_SOURCES` (`chikyu-pictures` and `chikyu-tiles`, written from `NOTICE.md`), `ownCredit`, and the family's `creditLine`, `validateSource`, `loadRecords`, `createTileStore` from `src/data-door.ts`, kazoku-ui's template copied unchanged (a test holds its hash). `<chikyu-earth-realistic>` takes `sources`, `addSource`, `removeSource`, `enableSource`, `data="own"` and `credits()`; `<chikyu-passes>` takes the same for orbit data (the newest epoch of a satellite wins), and its `credit` attribute stays and is followed by the line `credits()` writes, with the licences. `chikyu-creditschange` tells a page when the set of credited sources changes (not at each frame). Off (`remove()`, `enableSource(id, false)`, `data="own"`) aborts a source's loads, frees its tiles and drops its credit. A source is refused at once for an empty credit, no licence, a clashing id (or an id of the package's own) or a layer the Earth does not know; a tile that throws, is not a picture or has a size that is not a number is counted in `stats.tiles.failed` and never drawn. The tiles of a view share one budget, `TILE_BUDGET` (72 MB, the 48 tiles it has always held), and a tile that does not fit is refused and counted (`stats.tiles.refused`). With no source every picture is the same one. Every old attribute and function stays. One change: a tile that could not be fetched is no longer asked for again after 30 seconds; it is asked for again after the view has moved away from it and back, so a view at rest sends nothing. `stats.tiles` gains `heldBytes`, `refused` and `used`. New guide: Outside data, the data door (English and Japanese). The demo's Earth page shows the credit line under the view and reads `?data=own`.
package/README.md CHANGED
@@ -198,6 +198,24 @@ import { activeShowers } from "@johnmorrisdotca/chikyu-earth/meteors";
198
198
  for (const { shower, zhr } of activeShowers(Date.UTC(2026, 11, 14, 8))) console.log(`${shower.name}: ${zhr.toFixed(1)} an hour`);
199
199
  ```
200
200
 
201
+ ## A name on the Earth
202
+
203
+ `body-label` on `<chikyu-earth-realistic>` and `<chikyu-space>` writes the Earth's name (`EARTH`, `地球` on a Japanese page) on the globe so it turns with it and the surface shows through the letters: the family's shared label (kazoku-ui's `body-label`), in the family's plain attributes (`body-label` = `painted`, `etched`, `outline` or `burned`, then `body-label-strength`, `-repeat`, `-latitude`, `-facing`, `-font`, `-fallback-font`) and the property `bodyLabel`. The default is Michroma, painted, half strength, once, turning with the Earth. Off unless set; nothing is fetched until it is; nothing is drawn at rest: [guide](docs/guides/body-label.md).
204
+
205
+ ```js
206
+ import { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel } from "@johnmorrisdotca/chikyu-earth/realistic";
207
+
208
+ // The family's plain attributes: absent, no name; present, the family's own default (painted, half strength, once, on the equator).
209
+ const none = readBodyLabel(() => null);
210
+ const plain = readBodyLabel((name) => (name === "body-label" ? "" : null));
211
+ console.log(none, JSON.stringify(plain));
212
+
213
+ // A page's own choices, and the name in its language.
214
+ const mine = { "body-label": "etched", "body-label-strength": "0.8", "body-label-repeat": "both", "body-label-latitude": "55" };
215
+ console.log(JSON.stringify(readBodyLabel((name) => mine[name] ?? null)));
216
+ console.log(bodyLabelText("en"), bodyLabelText("ja"), BODY_LABEL_ATTRIBUTES.length);
217
+ ```
218
+
201
219
  ## Outside data: the data door
202
220
 
203
221
  The package draws; you bring the data. `@johnmorrisdotca/chikyu-earth/door` takes a finer map of the Earth, or a list of satellites' orbit data, as a **source**: a small object that carries its own licence and credit, so the screen can always say whose data it shows. With no source nothing changes: the Earth is drawn from the package's own pictures and tiles (`OWN_SOURCES`, written from `NOTICE.md`, never non-commercial or share-alike). A source of yours may be either, and the credit line prints that beside the licence.
@@ -512,6 +530,7 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
512
530
  | [When can I see the ISS?](docs/guides/passes.md) | Passes over a place, the sky dome, how it was checked |
513
531
  | [Ride along](docs/guides/ride-along.md) | A camera on a moving body |
514
532
  | [The date follows the clock, and Play](docs/guides/time-and-play.md) | The `chikyu-timechange` event, a `speed` for the space view and the realistic Earth, Play, Pause and Back |
533
+ | [A name on the Earth](docs/guides/body-label.md) | The Earth's name written on the globe, in the family's plain attribute names |
515
534
  | [Meteors seen from space](docs/guides/meteors.md) | Streaks over the night side, the shower table, what is real and what is illustration |
516
535
  | [Outside data, the data door](docs/guides/data-door.md) | Hand the package your own maps of the Earth or orbit data with their licence and credit, switch them off, and show whose data is on the screen |
517
536
  | [Zoom, pan and turn](docs/guides/zoom-and-pan.md) | The hands every view carries, each zoom range and why |
@@ -542,7 +561,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
542
561
 
543
562
  ## How to cite
544
563
 
545
- > Morris, J. (2026). *Chikyu Earth* (version 0.31.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
564
+ > Morris, J. (2026). *Chikyu Earth* (version 0.32.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
546
565
 
547
566
  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.
548
567
 
@@ -0,0 +1,113 @@
1
+ import type * as THREE from "three";
2
+ import type { BodyLabelLook } from "@johnmorrisdotca/kazoku-ui/body-label";
3
+ import type { ThreeParts } from "./textures.ts";
4
+ /**
5
+ * The attributes of the family's body label, in the order a settings panel lists them.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { BODY_LABEL_ATTRIBUTES } from "@johnmorrisdotca/chikyu-earth/realistic";
10
+ *
11
+ * console.log(BODY_LABEL_ATTRIBUTES.join(", "));
12
+ * ```
13
+ */
14
+ export declare const BODY_LABEL_ATTRIBUTES: readonly ["body-label", "body-label-strength", "body-label-repeat", "body-label-latitude", "body-label-facing", "body-label-font", "body-label-fallback-font"];
15
+ /**
16
+ * The settings of the name on the Earth: the same options the family's label takes, with the text left out (it is the Earth's own name, in the page's language).
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import type { BodyLabelSettings } from "@johnmorrisdotca/chikyu-earth/realistic";
21
+ *
22
+ * const settings: BodyLabelSettings = { look: "painted", strength: 0.5, repeat: "once", latitude: 0, facing: false };
23
+ * console.log(settings.look);
24
+ * ```
25
+ */
26
+ export interface BodyLabelSettings {
27
+ look: BodyLabelLook;
28
+ /** 0 to 1. */
29
+ strength: number;
30
+ repeat: "once" | "both" | "around";
31
+ /** Degrees, kept within 70 of the equator by the label. */
32
+ latitude: number;
33
+ /** The name keeps facing the reader while the Earth turns under it. */
34
+ facing: boolean;
35
+ /** A CSS font family the page has loaded; Michroma, fetched once, when left out. */
36
+ font?: string;
37
+ /** The family for letters the font has none of (Japanese); the page's sans when left out. */
38
+ fallbackFont?: string;
39
+ }
40
+ /** What an Earth tells its scene about its name: the settings now, or `null` for none, and the text. */
41
+ export interface BodyLabelState {
42
+ settings: BodyLabelSettings | null;
43
+ text: string;
44
+ /** What the layer has done: the label is made and in the globe, and it is showing (not hidden for being small), as of the last draw. */
45
+ drawn: {
46
+ made: boolean;
47
+ showing: boolean;
48
+ };
49
+ }
50
+ export declare const newBodyLabelState: () => BodyLabelState;
51
+ /**
52
+ * What the family's attributes mean: `body-label` (`painted`, `etched`, `outline` or `burned`; present with another value, or none, it is `painted`; absent, no label), `body-label-strength` (0 to 1, 0.5), `body-label-repeat` (`once`, `both` or
53
+ * `around`; `once`), `body-label-latitude` (degrees; 0), `body-label-facing` (present: always facing the reader), `body-label-font` and `body-label-fallback-font`.
54
+ *
55
+ * @param get - Reads an attribute by name, `null` for one that is not there.
56
+ * @returns The settings, or `null` for no label.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * import { readBodyLabel } from "@johnmorrisdotca/chikyu-earth/realistic";
61
+ *
62
+ * const attributes: Record<string, string> = { "body-label": "etched", "body-label-strength": "0.8", "body-label-repeat": "both" };
63
+ * console.log(readBodyLabel((name) => attributes[name] ?? null));
64
+ * ```
65
+ */
66
+ export declare function readBodyLabel(get: (name: string) => string | null): BodyLabelSettings | null;
67
+ /**
68
+ * The name written on the Earth: `EARTH`, or `地球` for a Japanese page.
69
+ *
70
+ * @param language - `en` or `ja`.
71
+ * @returns The text.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * import { bodyLabelText } from "@johnmorrisdotca/chikyu-earth/realistic";
76
+ *
77
+ * console.log(bodyLabelText("en"), bodyLabelText("ja"));
78
+ * ```
79
+ */
80
+ export declare const bodyLabelText: (language: "en" | "ja") => string;
81
+ export interface BodyLabelLayer {
82
+ /** Puts the label right for this draw (made, changed or taken away as the settings say) and returns nothing: it asks for a draw of its own when something changed. */
83
+ sync(camera: THREE.Camera, radiusPx: number): void;
84
+ dispose(): void;
85
+ }
86
+ /**
87
+ * Where Michroma, the family's font for the name, is fetched from. Left alone it is the file beside the label's own module (`fonts/Michroma-Regular.ttf` in kazoku-ui's `body-label`), which is right where the package is used as it is shipped, or through a
88
+ * bundler that keeps assets beside the code (Vite does); a bundler or a site that moves the module copies the file and says where with this. A page that names its own font (`body-label-font`) never fetches it.
89
+ *
90
+ * @param url - The font file's address, or `undefined` for the default.
91
+ *
92
+ * @example
93
+ * ```ts no-run
94
+ * import { setBodyLabelFontUrl } from "@johnmorrisdotca/chikyu-earth/realistic";
95
+ *
96
+ * setBodyLabelFontUrl("/fonts/Michroma-Regular.ttf");
97
+ * ```
98
+ */
99
+ export declare function setBodyLabelFontUrl(url: string | undefined): void;
100
+ /**
101
+ * Makes the layer that keeps the Earth's name on its globe, inside `parent` (the group or mesh that turns with the Earth, a radius of 1). The family's body label is loaded only when the settings first ask for it, and its font (Michroma, 64 kB) only
102
+ * when the page has named no font of its own. All three.js parts the label needs must be in `three` (the full three.js has them); without them `onError` is told once and nothing is drawn.
103
+ *
104
+ * @param three - The page's three.js.
105
+ * @param parent - What turns with the Earth.
106
+ * @param state - The settings and the text, which the element changes.
107
+ * @param deps - `invalidate` asks for a draw; `onError` hears of a label that could not be made.
108
+ * @returns The layer.
109
+ */
110
+ export declare function createBodyLabelLayer(three: ThreeParts, parent: THREE.Object3D, state: BodyLabelState, deps: {
111
+ invalidate: () => void;
112
+ onError?: (error: unknown) => void;
113
+ }): BodyLabelLayer;
@@ -0,0 +1,171 @@
1
+ /**
2
+ * The attributes of the family's body label, in the order a settings panel lists them.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { BODY_LABEL_ATTRIBUTES } from "@johnmorrisdotca/chikyu-earth/realistic";
7
+ *
8
+ * console.log(BODY_LABEL_ATTRIBUTES.join(", "));
9
+ * ```
10
+ */
11
+ export const BODY_LABEL_ATTRIBUTES = ["body-label", "body-label-strength", "body-label-repeat", "body-label-latitude", "body-label-facing", "body-label-font", "body-label-fallback-font"];
12
+ export const newBodyLabelState = () => ({ settings: null, text: "EARTH", drawn: { made: false, showing: false } });
13
+ const LOOKS = ["painted", "etched", "outline", "burned"];
14
+ const REPEATS = ["once", "both", "around"];
15
+ /**
16
+ * What the family's attributes mean: `body-label` (`painted`, `etched`, `outline` or `burned`; present with another value, or none, it is `painted`; absent, no label), `body-label-strength` (0 to 1, 0.5), `body-label-repeat` (`once`, `both` or
17
+ * `around`; `once`), `body-label-latitude` (degrees; 0), `body-label-facing` (present: always facing the reader), `body-label-font` and `body-label-fallback-font`.
18
+ *
19
+ * @param get - Reads an attribute by name, `null` for one that is not there.
20
+ * @returns The settings, or `null` for no label.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { readBodyLabel } from "@johnmorrisdotca/chikyu-earth/realistic";
25
+ *
26
+ * const attributes: Record<string, string> = { "body-label": "etched", "body-label-strength": "0.8", "body-label-repeat": "both" };
27
+ * console.log(readBodyLabel((name) => attributes[name] ?? null));
28
+ * ```
29
+ */
30
+ export function readBodyLabel(get) {
31
+ const look = get("body-label");
32
+ if (look === null)
33
+ return null;
34
+ const strength = get("body-label-strength");
35
+ const latitude = get("body-label-latitude");
36
+ const repeat = get("body-label-repeat") ?? "once";
37
+ const font = get("body-label-font")?.trim();
38
+ const fallback = get("body-label-fallback-font")?.trim();
39
+ const number = (text, fallbackValue) => (text === null || text.trim() === "" || !Number.isFinite(Number(text)) ? fallbackValue : Number(text));
40
+ return {
41
+ look: (LOOKS.includes(look.trim()) ? look.trim() : "painted"),
42
+ strength: Math.min(1, Math.max(0, number(strength, 0.5))),
43
+ repeat: (REPEATS.includes(repeat) ? repeat : "once"),
44
+ latitude: number(latitude, 0),
45
+ facing: get("body-label-facing") !== null && get("body-label-facing") !== "off",
46
+ ...(font ? { font } : {}),
47
+ ...(fallback ? { fallbackFont: fallback } : {}),
48
+ };
49
+ }
50
+ /**
51
+ * The name written on the Earth: `EARTH`, or `地球` for a Japanese page.
52
+ *
53
+ * @param language - `en` or `ja`.
54
+ * @returns The text.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { bodyLabelText } from "@johnmorrisdotca/chikyu-earth/realistic";
59
+ *
60
+ * console.log(bodyLabelText("en"), bodyLabelText("ja"));
61
+ * ```
62
+ */
63
+ export const bodyLabelText = (language) => (language === "ja" ? "地球" : "EARTH");
64
+ let fontUrl;
65
+ /**
66
+ * Where Michroma, the family's font for the name, is fetched from. Left alone it is the file beside the label's own module (`fonts/Michroma-Regular.ttf` in kazoku-ui's `body-label`), which is right where the package is used as it is shipped, or through a
67
+ * bundler that keeps assets beside the code (Vite does); a bundler or a site that moves the module copies the file and says where with this. A page that names its own font (`body-label-font`) never fetches it.
68
+ *
69
+ * @param url - The font file's address, or `undefined` for the default.
70
+ *
71
+ * @example
72
+ * ```ts no-run
73
+ * import { setBodyLabelFontUrl } from "@johnmorrisdotca/chikyu-earth/realistic";
74
+ *
75
+ * setBodyLabelFontUrl("/fonts/Michroma-Regular.ttf");
76
+ * ```
77
+ */
78
+ export function setBodyLabelFontUrl(url) {
79
+ fontUrl = url;
80
+ }
81
+ const signatureOf = (state) => (state.settings ? JSON.stringify([state.text, state.settings]) : "");
82
+ /**
83
+ * Makes the layer that keeps the Earth's name on its globe, inside `parent` (the group or mesh that turns with the Earth, a radius of 1). The family's body label is loaded only when the settings first ask for it, and its font (Michroma, 64 kB) only
84
+ * when the page has named no font of its own. All three.js parts the label needs must be in `three` (the full three.js has them); without them `onError` is told once and nothing is drawn.
85
+ *
86
+ * @param three - The page's three.js.
87
+ * @param parent - What turns with the Earth.
88
+ * @param state - The settings and the text, which the element changes.
89
+ * @param deps - `invalidate` asks for a draw; `onError` hears of a label that could not be made.
90
+ * @returns The layer.
91
+ */
92
+ export function createBodyLabelLayer(three, parent, state, deps) {
93
+ let label = null;
94
+ let loading = false;
95
+ let failed = false;
96
+ let signature = "";
97
+ let gone = false;
98
+ const options = () => {
99
+ const s = state.settings;
100
+ return { text: state.text, look: s.look, strength: s.strength, repeat: s.repeat, latitude: s.latitude, facing: s.facing, ...(s.font ? { font: s.font } : {}), ...(s.fallbackFont ? { fallbackFont: s.fallbackFont } : {}) };
101
+ };
102
+ const remove = () => {
103
+ if (!label)
104
+ return;
105
+ parent.remove(label.object);
106
+ label.dispose();
107
+ label = null;
108
+ signature = "";
109
+ state.drawn = { made: false, showing: false };
110
+ };
111
+ const make = () => {
112
+ loading = true;
113
+ void import("@johnmorrisdotca/kazoku-ui/body-label")
114
+ .then(async (module) => {
115
+ const parts = three;
116
+ for (const name of ["CanvasTexture", "SphereGeometry", "MeshLambertMaterial", "SRGBColorSpace", "NormalBlending", "AdditiveBlending"])
117
+ if (parts[name] === undefined)
118
+ throw new Error(`the three.js handed over has no ${name}, which the name on the Earth needs`);
119
+ if (!state.settings?.font)
120
+ await module.loadBodyLabelFont(fontUrl);
121
+ if (gone || !state.settings) {
122
+ loading = false;
123
+ return;
124
+ }
125
+ const made = module.createBodyLabel(three, options());
126
+ parent.add(made.object);
127
+ label = made;
128
+ state.drawn.made = true;
129
+ signature = signatureOf(state);
130
+ loading = false;
131
+ void made.ready.then(() => {
132
+ if (!gone)
133
+ deps.invalidate();
134
+ });
135
+ deps.invalidate();
136
+ })
137
+ .catch((error) => {
138
+ loading = false;
139
+ failed = true;
140
+ deps.onError?.(error);
141
+ });
142
+ };
143
+ return {
144
+ sync(camera, radiusPx) {
145
+ if (gone)
146
+ return;
147
+ if (!state.settings) {
148
+ remove();
149
+ return;
150
+ }
151
+ if (!label) {
152
+ if (!loading && !failed)
153
+ make();
154
+ return;
155
+ }
156
+ const now = signatureOf(state);
157
+ if (now !== signature) {
158
+ signature = now;
159
+ label.set(options());
160
+ deps.invalidate();
161
+ }
162
+ if (label.update(camera, radiusPx))
163
+ deps.invalidate();
164
+ state.drawn.showing = label.object.visible;
165
+ },
166
+ dispose() {
167
+ gone = true;
168
+ remove();
169
+ },
170
+ };
171
+ }
@@ -7,6 +7,7 @@ import { type SatelliteState } from "../space/satellite-layer.ts";
7
7
  import type { Layer } from "./tiers.ts";
8
8
  import { type ThreeParts } from "./textures.ts";
9
9
  import { type TileSet, type TileSources } from "./tile-set.ts";
10
+ import { type BodyLabelState } from "./body-label.ts";
10
11
  import { type MeteorState } from "../meteors/layer.ts";
11
12
  export type { ThreeParts };
12
13
  type Three = ThreeParts;
@@ -85,6 +86,8 @@ export interface EarthModel {
85
86
  ratio(): number;
86
87
  /** Meteors seen from space (src/meteors/layer.ts): off unless the element switches them on. */
87
88
  meteors: MeteorState;
89
+ /** The name written on the Earth (src/realistic/body-label.ts): off unless the element sets it. */
90
+ bodyLabel: BodyLabelState;
88
91
  }
89
92
  export interface EarthDeps {
90
93
  assets: AssetCache;
@@ -103,6 +106,8 @@ export interface EarthDeps {
103
106
  air?: () => "full" | "light";
104
107
  /** The satellites could not be drawn (the three.js parts handed over lack `Points`). */
105
108
  onSatellitesError?: (error: unknown) => void;
109
+ /** The name written on the Earth could not be made (the three.js handed over lacks a part, or the label could not be loaded). */
110
+ onLabelError?: (error: unknown) => void;
106
111
  /** Told after the tiles were put right for a draw: what the draw shows from each source is known now. */
107
112
  onTiled?: () => void;
108
113
  /** Told at the start of every draw, before anything is read for it. */
@@ -5,6 +5,7 @@ import { greenwichSidereal, subsolarPoint, unitVector } from "./sun.js";
5
5
  import { createSatelliteLayer, newSatelliteState } from "../space/satellite-layer.js";
6
6
  import { createTextureSet } from "./textures.js";
7
7
  import { createTileSet } from "./tile-set.js";
8
+ import { createBodyLabelLayer, newBodyLabelState } from "./body-label.js";
8
9
  import { createMeteorLayer, newMeteorState } from "../meteors/layer.js";
9
10
  const RAD = Math.PI / 180;
10
11
  /**
@@ -38,6 +39,7 @@ export const newModel = () => ({
38
39
  pick: null,
39
40
  ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
40
41
  meteors: newMeteorState(),
42
+ bodyLabel: newBodyLabelState(),
41
43
  });
42
44
  /**
43
45
  * The disc's radius in CSS pixels in a box of `width` x `height` at `zoom`: it fits the glow in the box at 1x.
@@ -183,6 +185,7 @@ export function createEarthItem(model, deps) {
183
185
  // the meteors: made the first time they are switched on, and asking for their own next draw while a streak is alive or one is due
184
186
  let meteors = null;
185
187
  let meteorTimer;
188
+ let nameOn = null;
186
189
  return {
187
190
  scene,
188
191
  camera,
@@ -227,6 +230,10 @@ export function createEarthItem(model, deps) {
227
230
  textures.sync(radius * model.ratio());
228
231
  tiles.sync({ lon: look.lon, lat: look.lat, width: size.width, height: size.height, panX: view.panX, panY: view.panY, radius }, [sunDir.value.x, sunDir.value.y, sunDir.value.z], true, model.ratio());
229
232
  deps.onTiled?.();
233
+ // the name written on the Earth: the layer is made the first time the settings ask for it, and keeps itself right
234
+ if (model.bodyLabel.settings && !nameOn)
235
+ nameOn = createBodyLabelLayer(three, turned, model.bodyLabel, { invalidate: deps.invalidate, ...(deps.onLabelError ? { onError: deps.onLabelError } : {}) });
236
+ nameOn?.sync(camera, radius);
230
237
  deps.onPose?.({ lon: look.lon, lat: look.lat, radius, cx: size.width / 2 + view.panX, cy: size.height / 2 + view.panY, width: size.width, height: size.height });
231
238
  if (model.meteors.on && !meteors)
232
239
  meteors = createMeteorLayer(three, turned, model.meteors);
@@ -245,6 +252,7 @@ export function createEarthItem(model, deps) {
245
252
  model.pick = null;
246
253
  clearTimeout(meteorTimer);
247
254
  meteors?.dispose();
255
+ nameOn?.dispose();
248
256
  model.tiles = null;
249
257
  tiles.dispose();
250
258
  textures.dispose();
@@ -4,6 +4,7 @@ import { type CameraMode, type LightMode } from "./earth.ts";
4
4
  import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/types.ts";
5
5
  import { type SatelliteStyle } from "../space/satellite-layer.ts";
6
6
  import type { Credit, DataSource } from "../data-door.ts";
7
+ import { type BodyLabelSettings } from "./body-label.ts";
7
8
  import { setSharedRenderer, setThreeLoader } from "./shared.ts";
8
9
  export { setSharedRenderer, setThreeLoader };
9
10
  export type { CameraMode };
@@ -123,6 +124,15 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
123
124
  */
124
125
  get meteorsStrength(): number;
125
126
  set meteorsStrength(value: number);
127
+ /**
128
+ * 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:
129
+ * `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),
130
+ * `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.
131
+ * 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`
132
+ * and `AdditiveBlending`; without them `chikyu-body-label-unavailable` is sent and the name is not drawn.
133
+ */
134
+ get bodyLabel(): BodyLabelSettings | null;
135
+ set bodyLabel(value: Partial<BodyLabelSettings> | null);
126
136
  /** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
127
137
  get controller(): ViewController | undefined;
128
138
  /**
@@ -203,6 +213,13 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
203
213
  shower: string | null;
204
214
  zhr: number;
205
215
  };
216
+ /** 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). */
217
+ bodyLabel: {
218
+ on: boolean;
219
+ text: string;
220
+ made: boolean;
221
+ showing: boolean;
222
+ };
206
223
  };
207
224
  /**
208
225
  * Apply a shared view controller's camera (yaw, tilt, zoom, pan). A change under half a pixel is not drawn, a settled change always is,
@@ -13,6 +13,7 @@ import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/
13
13
  import { createDoorHost } from "../door/host.js";
14
14
  import { folderSource } from "../door/map.js";
15
15
  import { ownCredit } from "../door/own.js";
16
+ import { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel } from "./body-label.js";
16
17
  import { createGate, frameCap } from "./gate.js";
17
18
  import { setSharedRenderer, setThreeLoader, takeRenderer } from "./shared.js";
18
19
  export { setSharedRenderer, setThreeLoader };
@@ -128,7 +129,7 @@ export const readTime = (value) => {
128
129
  * ```
129
130
  */
130
131
  export class ChikyuEarthRealistic extends HTMLElement {
131
- static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", "air-thickness", "air-label", "lang"];
132
+ static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, "air-thickness", "air-label", "lang"];
132
133
  #model = newModel();
133
134
  #mode = "now";
134
135
  #view;
@@ -178,6 +179,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
178
179
  this.#model.camera = readCamera(this.getAttribute("camera"));
179
180
  this.#model.cloudDrift = readDrift(this.getAttribute("cloud-drift"));
180
181
  this.#model.airThickness = readAirThickness(this.getAttribute("air-thickness"));
182
+ this.#applyBodyLabel();
181
183
  this.#door.book.ownOnly(this.getAttribute("data") === "own");
182
184
  this.#model.speed = this.speed;
183
185
  if (!this.hasAttribute("role"))
@@ -230,6 +232,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
230
232
  invalidate: () => this.#gate?.soon(),
231
233
  onDraw: () => this.#gate?.drawn(),
232
234
  onTiled: () => this.#door.announce(),
235
+ onLabelError: (error) => this.dispatchEvent(new CustomEvent("chikyu-body-label-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
233
236
  onPose: (pose) => {
234
237
  if (this.#hands)
235
238
  this.#hands.controller.grabRadius = discRadius(pose.width, pose.height, 1);
@@ -321,8 +324,13 @@ export class ChikyuEarthRealistic extends HTMLElement {
321
324
  this.#model.airThickness = readAirThickness(value);
322
325
  this.#gate?.soon();
323
326
  }
324
- else if (name === "meteors-label" || name === "lang")
327
+ else if (name === "meteors-label" || name === "lang") {
325
328
  this.#meteorNote();
329
+ if (name === "lang")
330
+ this.#applyBodyLabel();
331
+ }
332
+ else if (BODY_LABEL_ATTRIBUTES.includes(name))
333
+ this.#applyBodyLabel();
326
334
  if (name === "air-thickness" || name === "air-label" || name === "lang")
327
335
  setAirNote(this.#airNote, this, this.#model.airThickness);
328
336
  }
@@ -372,6 +380,41 @@ export class ChikyuEarthRealistic extends HTMLElement {
372
380
  set meteorsStrength(value) {
373
381
  this.setAttribute("meteors-strength", String(value));
374
382
  }
383
+ /**
384
+ * 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:
385
+ * `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),
386
+ * `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.
387
+ * 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`
388
+ * and `AdditiveBlending`; without them `chikyu-body-label-unavailable` is sent and the name is not drawn.
389
+ */
390
+ get bodyLabel() {
391
+ return readBodyLabel((name) => this.getAttribute(name));
392
+ }
393
+ set bodyLabel(value) {
394
+ for (const name of BODY_LABEL_ATTRIBUTES)
395
+ this.removeAttribute(name);
396
+ if (value === null)
397
+ return;
398
+ this.setAttribute("body-label", value.look ?? "painted");
399
+ if (value.strength !== undefined)
400
+ this.setAttribute("body-label-strength", String(value.strength));
401
+ if (value.repeat !== undefined)
402
+ this.setAttribute("body-label-repeat", value.repeat);
403
+ if (value.latitude !== undefined)
404
+ this.setAttribute("body-label-latitude", String(value.latitude));
405
+ if (value.facing)
406
+ this.setAttribute("body-label-facing", "");
407
+ if (value.font)
408
+ this.setAttribute("body-label-font", value.font);
409
+ if (value.fallbackFont)
410
+ this.setAttribute("body-label-fallback-font", value.fallbackFont);
411
+ }
412
+ /** Puts the name's settings and text right from the attributes (`body-label` and its family, `lang`). */
413
+ #applyBodyLabel() {
414
+ this.#model.bodyLabel.settings = readBodyLabel((name) => this.getAttribute(name));
415
+ this.#model.bodyLabel.text = bodyLabelText((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en");
416
+ this.#gate?.soon();
417
+ }
375
418
  /** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
376
419
  get controller() {
377
420
  return this.#hands?.controller;
@@ -550,6 +593,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
550
593
  canvas: stats?.canvas ?? { width: 0, height: 0, pixels: 0 },
551
594
  assets: { entries: stats?.assets.entries ?? 0, refs: stats?.assets.refs ?? 0 },
552
595
  meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
596
+ bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
553
597
  };
554
598
  }
555
599
  /**
@@ -5,5 +5,6 @@ export { lookAt, discRadius, ATMOSPHERE_OUTER, cameraCentre, type CameraMode, ty
5
5
  export type { ThreeParts } from "./earth.ts";
6
6
  export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView, type TileCamera, type TileId, type TileLayer, type VisibleTile } from "./tiles.ts";
7
7
  export { TILE_KEEP_MS, TILE_LIMIT } from "./tile-set.ts";
8
+ export { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel, setBodyLabelFontUrl, type BodyLabelSettings } from "./body-label.ts";
8
9
  export { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_THICKNESS_MAX, AIR_TOP, AIR_VERT, airFor, airFrag, airTop, readAirThickness, type AirSamples } from "./air.ts";
9
10
  export { AIR_NOTE } from "./air-note.ts";
@@ -6,5 +6,6 @@ export { createGate, frameCap } from "./gate.js";
6
6
  export { lookAt, discRadius, ATMOSPHERE_OUTER, cameraCentre } from "./earth.js";
7
7
  export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView } from "./tiles.js";
8
8
  export { TILE_KEEP_MS, TILE_LIMIT } from "./tile-set.js";
9
+ export { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel, setBodyLabelFontUrl } from "./body-label.js";
9
10
  export { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_THICKNESS_MAX, AIR_TOP, AIR_VERT, airFor, airFrag, airTop, readAirThickness } from "./air.js";
10
11
  export { AIR_NOTE } from "./air-note.js";
@@ -17,6 +17,14 @@ export type ThreeParts = {
17
17
  } & {
18
18
  /** Only the satellites use it, so a loader that hands over a subset of three.js without it still draws everything else. */
19
19
  Points?: typeof THREE.Points;
20
+ } & {
21
+ /** Only the name written on the Earth (`body-label`) uses these, so a subset of three.js without them still draws everything else. */
22
+ CanvasTexture?: typeof THREE.CanvasTexture;
23
+ SphereGeometry?: typeof THREE.SphereGeometry;
24
+ MeshLambertMaterial?: typeof THREE.MeshLambertMaterial;
25
+ SRGBColorSpace?: typeof THREE.SRGBColorSpace;
26
+ NormalBlending?: typeof THREE.NormalBlending;
27
+ AdditiveBlending?: typeof THREE.AdditiveBlending;
20
28
  };
21
29
  /** Milliseconds a lower texture size must be enough before the larger one is let go. */
22
30
  export declare const DOWNGRADE_AFTER_MS = 4000;
@@ -1,5 +1,6 @@
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";
3
4
  import { setThreeLoader } from "../realistic/shared.ts";
4
5
  import type { LightMode } from "../realistic/earth.ts";
5
6
  import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/types.ts";
@@ -162,6 +163,15 @@ export declare class ChikyuSpace extends HTMLElement {
162
163
  */
163
164
  get meteorsStrength(): number;
164
165
  set meteorsStrength(value: number);
166
+ /**
167
+ * 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:
168
+ * `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),
169
+ * `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.
170
+ * 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`
171
+ * and `AdditiveBlending`; without them `chikyu-body-label-unavailable` is sent and the name is not drawn.
172
+ */
173
+ get bodyLabel(): BodyLabelSettings | null;
174
+ set bodyLabel(value: Partial<BodyLabelSettings> | null);
165
175
  /**
166
176
  * 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
177
  * under the picture (`air-label="off"` takes the line away, for a page that says it itself).
@@ -315,6 +325,13 @@ export declare class ChikyuSpace extends HTMLElement {
315
325
  shower: string | null;
316
326
  zhr: number;
317
327
  };
328
+ /** 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). */
329
+ bodyLabel: {
330
+ on: boolean;
331
+ text: string;
332
+ made: boolean;
333
+ showing: boolean;
334
+ };
318
335
  };
319
336
  }
320
337
  declare global {
@@ -1,6 +1,7 @@
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, readBodyLabel } from "../realistic/body-label.js";
4
5
  import { createGate, frameCap } from "../realistic/gate.js";
5
6
  import { setThreeLoader, takeRenderer } from "../realistic/shared.js";
6
7
  import { NOTES_STYLE, setAirNote } from "../realistic/air-note.js";
@@ -100,7 +101,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
100
101
  * ```
101
102
  */
102
103
  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"];
104
+ 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, "air-thickness", "air-label", "lang"];
104
105
  #model = newSpaceModel();
105
106
  #mode = "now";
106
107
  #speed = 1;
@@ -158,6 +159,7 @@ export class ChikyuSpace extends HTMLElement {
158
159
  this.#note = root.getElementById("meteor-note");
159
160
  this.#airNote = root.getElementById("air-note");
160
161
  this.#model.airThickness = readAirThickness(this.getAttribute("air-thickness"));
162
+ this.#applyBodyLabel();
161
163
  setAirNote(this.#airNote, this, this.#model.airThickness);
162
164
  this.#played = false;
163
165
  this.#model.meteors.on = this.#meteorsAsked();
@@ -186,6 +188,7 @@ export class ChikyuSpace extends HTMLElement {
186
188
  this.#tiers[layer] = width;
187
189
  },
188
190
  onLabels: (places) => this.#placeLabels(places),
191
+ onLabelError: (error) => this.dispatchEvent(new CustomEvent("chikyu-body-label-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
189
192
  onSelected: (place) => this.#placeChosen(place),
190
193
  onMoving: () => this.#gate?.request(),
191
194
  onRideLost: () => this.#rideLost(),
@@ -263,8 +266,13 @@ export class ChikyuSpace extends HTMLElement {
263
266
  this.#model.airThickness = readAirThickness(value);
264
267
  this.#gate?.request();
265
268
  }
266
- else if (name === "meteors-label" || name === "lang")
269
+ else if (name === "meteors-label" || name === "lang") {
267
270
  setMeteorNote(this.#note, this, this.#model.meteors.on);
271
+ if (name === "lang")
272
+ this.#applyBodyLabel();
273
+ }
274
+ else if (BODY_LABEL_ATTRIBUTES.includes(name))
275
+ this.#applyBodyLabel();
268
276
  if (name === "air-thickness" || name === "air-label" || name === "lang")
269
277
  setAirNote(this.#airNote, this, this.#model.airThickness);
270
278
  }
@@ -303,6 +311,41 @@ export class ChikyuSpace extends HTMLElement {
303
311
  set meteorsStrength(value) {
304
312
  this.setAttribute("meteors-strength", String(value));
305
313
  }
314
+ /**
315
+ * 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:
316
+ * `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),
317
+ * `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.
318
+ * 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`
319
+ * and `AdditiveBlending`; without them `chikyu-body-label-unavailable` is sent and the name is not drawn.
320
+ */
321
+ get bodyLabel() {
322
+ return readBodyLabel((name) => this.getAttribute(name));
323
+ }
324
+ set bodyLabel(value) {
325
+ for (const name of BODY_LABEL_ATTRIBUTES)
326
+ this.removeAttribute(name);
327
+ if (value === null)
328
+ return;
329
+ this.setAttribute("body-label", value.look ?? "painted");
330
+ if (value.strength !== undefined)
331
+ this.setAttribute("body-label-strength", String(value.strength));
332
+ if (value.repeat !== undefined)
333
+ this.setAttribute("body-label-repeat", value.repeat);
334
+ if (value.latitude !== undefined)
335
+ this.setAttribute("body-label-latitude", String(value.latitude));
336
+ if (value.facing)
337
+ this.setAttribute("body-label-facing", "");
338
+ if (value.font)
339
+ this.setAttribute("body-label-font", value.font);
340
+ if (value.fallbackFont)
341
+ this.setAttribute("body-label-fallback-font", value.fallbackFont);
342
+ }
343
+ /** Puts the name's settings and text right from the attributes (`body-label` and its family, `lang`). */
344
+ #applyBodyLabel() {
345
+ this.#model.bodyLabel.settings = readBodyLabel((name) => this.getAttribute(name));
346
+ this.#model.bodyLabel.text = bodyLabelText((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en");
347
+ this.#gate?.request();
348
+ }
306
349
  /**
307
350
  * 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
351
  * under the picture (`air-label="off"` takes the line away, for a page that says it itself).
@@ -661,6 +704,7 @@ export class ChikyuSpace extends HTMLElement {
661
704
  camera: { position: [this.#model.pose.p[0], this.#model.pose.p[1], this.#model.pose.p[2]], fov: this.#model.pose.fov },
662
705
  bodies: { look: this.#model.bodies || painter?.looks?.[0] || "plain", painted: this.#model.painted.bodies, moons: this.#model.painted.moons },
663
706
  meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
707
+ bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
664
708
  };
665
709
  }
666
710
  #satelliteStats() {
@@ -8,6 +8,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
10
  import { type SatelliteState } from "./satellite-layer.ts";
11
+ import { type BodyLabelState } from "../realistic/body-label.ts";
11
12
  import { type MeteorState } from "../meteors/layer.ts";
12
13
  type Three = ThreeParts;
13
14
  /** 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 +153,8 @@ export interface SpaceModel {
152
153
  satellites: SatelliteState;
153
154
  /** Meteors seen from space, on the Earth (src/meteors/layer.ts): off unless the element switches them on. */
154
155
  meteors: MeteorState;
156
+ /** The name written on the Earth (src/realistic/body-label.ts): off unless the element sets it. */
157
+ bodyLabel: BodyLabelState;
155
158
  /** The body or satellite the camera rides along with, or null. */
156
159
  ride: RideState | null;
157
160
  /** 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 +283,8 @@ export interface SpaceDeps {
280
283
  air?: () => "full" | "light";
281
284
  /** 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
285
  onLabels?: (places: Record<BodyName, BodyPlace | null>) => void;
286
+ /** The name written on the Earth could not be made. */
287
+ onLabelError?: (error: unknown) => void;
283
288
  /** 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
289
  onSelected?: (place: {
285
290
  x: number;
@@ -6,6 +6,7 @@ import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
6
6
  import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
7
7
  import { ridePose } from "./ride.js";
8
8
  import { createSatelliteLayer, newSatelliteState } from "./satellite-layer.js";
9
+ import { createBodyLabelLayer, newBodyLabelState } from "../realistic/body-label.js";
9
10
  import { createMeteorLayer, newMeteorState } from "../meteors/layer.js";
10
11
  import { subsolarPoint, unitVector } from "../realistic/sun.js";
11
12
  const RAD = Math.PI / 180;
@@ -81,6 +82,7 @@ export const newSpaceModel = () => ({
81
82
  rideMotion: 0,
82
83
  satellites: newSatelliteState(),
83
84
  meteors: newMeteorState(),
85
+ bodyLabel: newBodyLabelState(),
84
86
  pick: null,
85
87
  ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
86
88
  });
@@ -263,6 +265,7 @@ export function createSpaceItem(model, deps) {
263
265
  let releaseTimer;
264
266
  let meteors = null;
265
267
  let meteorTimer;
268
+ let nameOn = null;
266
269
  let layer;
267
270
  const rideState = new Float64Array(6);
268
271
  let selectedShown = false;
@@ -587,6 +590,10 @@ export function createSpaceItem(model, deps) {
587
590
  }
588
591
  deps.onLabels(places);
589
592
  }
593
+ // the name written on the Earth: made the first time the settings ask for it; none while a ride along a body hides the Earth
594
+ if (model.bodyLabel.settings && !nameOn)
595
+ nameOn = createBodyLabelLayer(three, earth, model.bodyLabel, { invalidate: () => deps.invalidate(), ...(deps.onLabelError ? { onError: deps.onLabelError } : {}) });
596
+ nameOn?.sync(camera, rideFrom ? 0 : Math.min(px.Earth, 1e5));
590
597
  if (layer && deps.onSelected) {
591
598
  const at = model.satellites.selected ? layer.place(camera, size) : null;
592
599
  if (at || selectedShown)
@@ -622,6 +629,7 @@ export function createSpaceItem(model, deps) {
622
629
  if (meteorTimer !== undefined)
623
630
  clearTimeout(meteorTimer);
624
631
  meteors?.dispose();
632
+ nameOn?.dispose();
625
633
  layer?.dispose();
626
634
  model.pick = null;
627
635
  textures.dispose();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/chikyu-earth",
3
- "version": "0.31.0",
3
+ "version": "0.32.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 where you are, 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",
@@ -190,7 +190,7 @@
190
190
  },
191
191
  "dependencies": {
192
192
  "@johnmorrisdotca/chizu": "^1.6.0",
193
- "@johnmorrisdotca/kazoku-ui": "^0.27.0",
193
+ "@johnmorrisdotca/kazoku-ui": "^0.36.0",
194
194
  "d3-geo": "^3.1.1"
195
195
  },
196
196
  "peerDependencies": {