@johnmorrisdotca/chikyu-earth 0.10.0 → 0.11.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
@@ -1,6 +1,23 @@
1
1
  # Changelog
2
2
 
3
- ## 0.10.0
3
+ ## 0.11.0 - 2026-11-03
4
+
5
+ The real Sun, planets, Pluto and moons in the space view.
6
+
7
+ - **`<chikyu-space>` draws the real bodies through its `BodyPainter` seam with [wakusei-planets](https://github.com/johnmorrisdotca/wakusei-planets) 0.5.0** (an optional peer): `setBodyPainter(painter)` with `painter` from `@johnmorrisdotca/wakusei-planets/painter`, and `bodies="realistic"` or `bodies="painted"` (`plain` for the old spheres) on the element, the Sun with its glow, banded Jupiter, Saturn with Cassini's rings, Mars, Venus, Mercury, Uranus, Neptune and Pluto, lit from the Sun in the scene's own axes. One WebGL context, nothing drawn at rest, bodies drawn at the view's rate cap; a picture arriving later asks for a redraw; sharper pictures are fetched only for a body that is big on the screen and let go when it is not. The demo draws them by default (Planets: Shaded, Painted, Plain), the ride along too; the embed takes `&bodies=painted`.
8
+ - **Pluto** joins the planets: `PLANETS`, `BODY_NAMES` (the names beside the bodies and `body = "Pluto"`), its orbit, its size in both scales.
9
+ - **The moons, at their planets, when the camera is near.** A painter's optional `moons(planet, ms)` says where they are (wakusei-planets: Mars's two, Jupiter's four, Saturn's seven, Uranus's five, Neptune's three, Pluto's three, from JPL's mean elements); the view shows them once the planet is 4 pixels across, at least 2 pixels each, in their order round it, and lets them go four seconds after they leave the view. `zoomFor("Jupiter-moons")` is the zoom that frames a planet with its nearer moons. `stats.bodies` counts what the painter made.
10
+ - **The seam grew, and kept its old shape**: `make(three, name, context)` may return a promise; a drawing may have `update({ toSun, ms, radiusPx })` and `dispose`; `BodyPainter` has optional `moons` and `looks`; new types `BodyMoon` and `PaintContext`. A painter written for 0.10 still works.
11
+ - **The embed page shows the space view** when asked for it: the globe it hides stayed in the page (an author `display: block` beat the `hidden` attribute), so `embed.html?look=space` and `look=realistic` showed the line globe and left the real view below it, out of sight.
12
+ - **kazoku-ui 0.11.0** for the demo: the Centre button and the zoom slider.
13
+ - **A drag turns the globe while it is going on** (MODULES-254). The line and thick globe redrew its projection only when the pointer was let go (a move made only a cheap transform), so it stayed still and jumped on release. `setView(view, final, live)`: with `live` (a hand is on the view, which is anything but the Auto-turn) the projection is also redrawn while it turns, at most 30 times a second. The demo, the embed page and the guides pass `event.detail.reason !== "auto"`. Test: `e2e/hold.gl.ts`, a real pointer that goes down, moves and is not let go, in the line, thick, realistic and space looks with the Auto-turn on and off.
14
+ - **kazoku-ui 0.12.0** for the demo (MODULES-234): the horizontal layout with the zoom slider, the **Centre** button (zoom in, drag the globe far off, press Centre and it is back in the middle at Fit and the default angle; the pan is held so the globe cannot be lost, and because the globe fills its square the controls' default hold, "the picture keeps covering the view", is the right one, so `object-size` is left out), and **exact grab**: `grab-radius="fit"` on the flat globe, the Earth from space with its disc's radius (the demo and the embed page set it; the guides and the README's examples carry `grab-radius="fit"`), so the touched point stays under the pointer (a drag of 31 px moves the ground at the middle by 31 px). The space view keeps the fixed angle, because its radius changes with the body and the scale. On a phone the horizontal layout's readout is Fit. Tests: `e2e/follows.gl.ts` runs kazoku-ui's shared `checkFollowsTheHand` (drag, arrow keys, Auto-turn west to east) and `checkExactGrab` in the line, thick, realistic and space looks (`e2e/ground.mjs` is kazoku-ui's `templates/e2e-ground.mjs`, unchanged); `e2e/centre.gl.ts` drags the globe far off, presses Centre and checks it is back, picture and all.
15
+ - **Always lit and Night boost** (MODULES-259): a ride on the night side is no longer a black frame. `light="sun"` (the true light, the default), `light="lit"` (the Earth lit as if by daylight from the camera's side, the day picture and no city lights) or `light="boost"` (the true terminator, with the night side raised so land and coasts read), on `<chikyu-space>` and `<chikyu-earth-realistic>`, as `element.light`, as three buttons in the demo (Light: Sun, Always lit, Night boost; English and Japanese) and in the address (`?light=lit`; the embed takes it too). The Sun, the Moon and the planets keep their true places. One uniform each and no extra pass. Tests: a night-side view is dark with the Sun and bright with Always lit and Night boost, and a ride on the ISS at a moment of its orbit in the Earth's shadow goes from nearly black (mean brightness 12 of 255) to 33 with Always lit and 18 with Night boost (`e2e/ride.gl.ts`).
16
+ - A guide, "The real Sun, planets, Pluto and moons", in English and Japanese.
17
+ - Documentation: an architecture guide with its Japanese twin, a code builder page (`builder.html`), a longer README whose examples run (`pnpm test:readme`), and every release of this changelog dated. No behaviour changed.
18
+ - The README opens with the package's thumbnail, and the demo carries it as its link preview (og:image) and publishes the card, a dark card and an icon on Pages at `thumbnail.png`, `thumbnail-dark.png` and `icon.png`.
19
+
20
+ ## 0.10.0 - 2026-11-03
4
21
 
5
22
  Three fixes for a page that puts the Earth behind something else.
6
23
 
@@ -9,7 +26,7 @@ Three fixes for a page that puts the Earth behind something else.
9
26
  - **A strict Content-Security-Policy no longer refuses the elements' styles** (MODULES-180). `<chikyu-earth>`, `<chikyu-earth-realistic>` and `<chikyu-space>` wrote a `<style>` into their shadow roots, which `style-src 'self'` blocks. They now adopt a constructable stylesheet (shared by every element with the same text), and where a browser has none, a `<style>` carrying the element's `nonce`. Test (`e2e/csp.gl.ts`): each element in a page served with `style-src 'self'` reports no violation, its styles apply, and no `<style>` is written.
10
27
  - **`setSharedRenderer(renderer)`** (`@johnmorrisdotca/chikyu-earth/realistic/element`; MODULES-171): the page hands the Earth and the space view a renderer made with kazoku-ui's `createSharedRenderer`, so a page that draws other things with it keeps one WebGL context. The page owns it: its `maxRatio` and `onContext` apply and the elements never dispose it. Call it before the first element connects (it throws while one is in the page). Unit-tested (`test/shared.test.ts`).
11
28
 
12
- ## 0.9.1
29
+ ## 0.9.1 - 2026-11-02
13
30
 
14
31
  The ground now follows the pointer, in every look and when riding.
15
32
 
@@ -19,7 +36,7 @@ The ground now follows the pointer, in every look and when riding.
19
36
  - **The demo keeps the address's yaw and tilt when it opens on a ride** (it set both to 0 as the ride began), and **an address with `ride` and no `look` opens the space look**, so the reported address rides the ISS.
20
37
  - **Tests**: `e2e/drag.gl.ts` drags with a real pointer, presses the arrow keys and runs Auto-turn in the line, thick, realistic and space looks, riding the ISS (down and at the horizon) and the Moon, and behind the ISS and the Moon, and checks which way the ground moved by sliding the first picture over the second; and that a ride opens with the address's turn, a drag writes it back and the address brings the same picture back; and the reported address. All fail on 0.9.0. Unit tests for `ridePose` and the view's signs.
21
38
 
22
- ## 0.9.0
39
+ ## 0.9.0 - 2026-11-02
23
40
 
24
41
  Ride along: the camera on the ISS, a Starlink satellite, the Moon or a planet, looking at the Earth.
25
42
 
@@ -40,7 +57,7 @@ Ride along: the camera on the ISS, a Starlink satellite, the Moon or a planet, l
40
57
  - **Docs**: a ride-along guide in English and Japanese, a page for it (docs/ride-along.md) and every new export with TSDoc and an example, usage examples run by `pnpm test:usage` (a Vite page that rides the ISS and is opened in a browser; `ridePose` in Node), README section, screenshots. The space view has no markers (those belong to the flat and the realistic globes), so the ticket's "markers stay on the ground" has nothing to do here.
41
58
  - The names beside the bodies are not drawn for the body being ridden (the camera is inside it) and the Earth's is not drawn when riding at a body.
42
59
 
43
- ## 0.8.0
60
+ ## 0.8.0 - 2026-11-02
44
61
 
45
62
  Satellites on the space view, the space view in the embed, and the demo's space controls in Japanese.
46
63
 
@@ -68,7 +85,7 @@ Satellites on the space view, the space view in the embed, and the demo's space
68
85
  - `ThreeParts` has an optional `Points`: a three.js subset handed over by `setThreeLoader` needs it only for satellites (the demo's `three-subset.ts` has it).
69
86
  - The CHANGELOG of 0.7.0, whose published tarball showed the family-parts notes under the 0.6.0 heading, is as fixed in 6f26012; this entry is under its own heading.
70
87
 
71
- ## 0.7.0
88
+ ## 0.7.0 - 2026-11-02
72
89
 
73
90
  The space view can look at any body, bodies can be chosen, and how the Sun and the planets are drawn is a seam another package can fill.
74
91
 
@@ -91,7 +108,7 @@ Chikyu Earth now has what every package of the family has, and it was missing fr
91
108
  - **The family's must-have list**, checked: `scripts/check-standard.mjs` (kazoku-ui's, unchanged) fails `pnpm check` when a package lacks its demo, embed page, docs site with Japanese twins, family files or tested usage.
92
109
  - **Family files**: `family-template.mjs` and `family-readme.mjs` of 2026-11-02 with Chikyu Earth added to the family's list (33 packages), `family.css`, and the README's "The family" block. Added to the list here only; the other packages take the new files when they are next touched.
93
110
 
94
- ## 0.6.0 (never published on its own: it ships in 0.7.0)
111
+ ## 0.6.0 - 2026-11-02 (never published on its own: it ships in 0.7.0)
95
112
 
96
113
  The Sun, the Moon and the planets: `<chikyu-space>`, an optional entry point, under the same performance budget as the Earth from space.
97
114
 
@@ -110,7 +127,7 @@ The Sun, the Moon and the planets: `<chikyu-space>`, an optional entry point, un
110
127
  - **Research, no code** ([docs/satellite-sources.md](docs/satellite-sources.md), MODULES-85): CelesTrak (grey), Space-Track (red for a package), the r/SpaceX API (archived, offline), Launch Library 2 (grey), Wikipedia and Wikidata
111
128
  (green) for launches; the recommendation is a satellite view that takes elements the page supplies. John chooses before MODULES-86 and MODULES-87 start.
112
129
 
113
- ## 0.5.0
130
+ ## 0.5.0 - 2026-11-02
114
131
 
115
132
  The Earth from space, and markers for any place on either globe, both under a hard performance budget.
116
133
 
@@ -146,7 +163,7 @@ An optional realistic look, drawn with three.js through kazoku-ui's shared rende
146
163
  - `pnpm test:soak` (`SOAK_MINUTES`, 10 by default; CI runs 1) turns, zooms, re-times and toggles for that long and compares the heap, the GPU objects and the draw rate with the start.
147
164
  - `pnpm screenshots` also makes the realistic pictures; `scripts/make-textures.py` makes the textures from NASA's sources.
148
165
 
149
- ## 0.4.0
166
+ ## 0.4.0 - 2026-11-02
150
167
 
151
168
  The outlines now come from chizu, the controls from kazoku-ui 0.9, and the release from the family's shared workflow.
152
169
 
@@ -166,7 +183,7 @@ The outlines now come from chizu, the controls from kazoku-ui 0.9, and the relea
166
183
  - **AGENTS.md** is kazoku-ui's template (Facts: board `modules`, area `chikyu-earth`, ports 8200 to 8299).
167
184
  - A still picture of the demo opens the README; `pnpm screenshots` makes the pictures in `docs/images/`.
168
185
 
169
- ## 0.3.0
186
+ ## 0.3.0 - 2026-11-01
170
187
 
171
188
  The shared-controls integration is documented and covered in every motion preference, and the future of the
172
189
  country data is written down.
@@ -179,7 +196,7 @@ country data is written down.
179
196
  data later.
180
197
  - The demo and test servers move to this work's port block, 8200–8299.
181
198
 
182
- ## 0.2.0
199
+ ## 0.2.0 - 2026-11-01
183
200
 
184
201
  The globe now uses the family's shared view controls.
185
202
 
@@ -192,7 +209,7 @@ The globe now uses the family's shared view controls.
192
209
  - Browser tests now cover Chromium and WebKit at desk and phone sizes, including drag, pinch, zoom, Fit and the
193
210
  continuing Earth-rate turn.
194
211
 
195
- ## 0.1.0
212
+ ## 0.1.0 - 2026-11-01
196
213
 
197
214
  The first scaffold, and the first working globe.
198
215
 
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ <p align="center"><a href="https://johnmorrisdotca.github.io/chikyu-earth/"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/johnmorrisdotca/chikyu-earth/main/docs/images/thumbnail-dark.png"><img src="https://raw.githubusercontent.com/johnmorrisdotca/chikyu-earth/main/docs/images/thumbnail.png" alt="Chikyu Earth: the globe as a line drawing over Europe and Africa, and as the realistic Earth over Asia with evening in the east." width="1200"></picture></a></p>
2
+
1
3
  <h1 align="center">Chikyu Earth <sub>地球</sub></h1>
2
4
 
3
5
  <p align="center"><strong>A line-drawn globe that turns at the Earth's own rate, and opens centred on where you are.</strong><br>
@@ -13,6 +15,24 @@ Country outlines in the same thin-line style as Hako Devices and Uchusen Rockets
13
15
 
14
16
  <p align="center"><img alt="The line-drawn globe, Europe and Africa in view, with the shared control bar" src="docs/images/line-desk.png" width="640"></p>
15
17
 
18
+ ## Who it is for
19
+
20
+ - **A developer who wants a globe on a page** with one tag, no build step, no canvas, and an SVG that prints sharply.
21
+ - **A site with a place on it**: a team, a venue, a flight, a satellite pass. Markers move with the globe and gather into clusters.
22
+ - **A teacher or writer** who wants the Earth turning at its own rate, and the Sun, Moon and planets where they are on a date.
23
+ - **A maker of tools** who wants countries as data: outlines, English and Japanese names and two-letter codes, with no network.
24
+
25
+ ## Features
26
+
27
+ - A line-drawn globe as one SVG: country outlines on an orthographic disc, in two looks (`line`, `thick`), with an optional graticule.
28
+ - It opens centred on where the reader is, or where you say. Auto-turn runs at the Earth's own rate: one sidereal day a turn.
29
+ - The Earth from space (`/realistic`): day and night by the real Sun, city lights, sun glint, clouds and the atmosphere, drawn with three.js through one shared WebGL context.
30
+ - The Sun, the Moon and the planets where they are on a date and time (`/space`), and satellites at the places SGP4 puts them (`/satellites`), with a camera that rides along.
31
+ - Markers with labels, groups, clusters and events (`/markers`), on either globe.
32
+ - Pure parts that run on a server: `globe()`, the rotation and view maths, `COUNTRIES` and `countryList()`.
33
+ - The shared kazoku-ui view controls: drag, tilt, zoom, pan, pinch, Front and Fit, with the view kept in the address.
34
+ - Names in English and Japanese, and a strict content security policy is enough.
35
+
16
36
  ## Install and use
17
37
 
18
38
  ```sh
@@ -59,7 +79,7 @@ The [kazoku-ui](https://github.com/johnmorrisdotca/kazoku-ui) view controls turn
59
79
 
60
80
  const earth = document.querySelector("chikyu-earth");
61
81
  document.querySelector("kazoku-view-controls").addEventListener("kazoku-viewchange", (event) => {
62
- earth.setView(event.detail, event.detail.final);
82
+ earth.setView(event.detail, event.detail.final, event.detail.reason !== "auto");
63
83
  });
64
84
  </script>
65
85
  </head>
@@ -67,7 +87,7 @@ The [kazoku-ui](https://github.com/johnmorrisdotca/kazoku-ui) view controls turn
67
87
  <div id="globe" tabindex="0">
68
88
  <chikyu-earth size="420" look="thick" center="139.7,35.7"></chikyu-earth>
69
89
  </div>
70
- <kazoku-view-controls for="globe" address controls="advanced" tilt-max="90" speed="0.004178"></kazoku-view-controls>
90
+ <kazoku-view-controls for="globe" address grab-radius="fit" controls="advanced" tilt-max="90" speed="0.004178"></kazoku-view-controls>
71
91
  </body>
72
92
  </html>
73
93
  ```
@@ -129,7 +149,7 @@ at most 30 times a second while it does, in one WebGL context, with textures tha
129
149
 
130
150
  ## The Sun, the Moon and the planets
131
151
 
132
- `<chikyu-space>` (`@johnmorrisdotca/chikyu-earth/space/element`) places the Earth, the Moon, the Sun and the planets where they are at a date and time, with the Moon's phase and the Earth's day side
152
+ `<chikyu-space>` (`@johnmorrisdotca/chikyu-earth/space/element`) places the Earth, the Moon, the Sun, the planets and Pluto (the real ones, with their moons, when [wakusei-planets](https://github.com/johnmorrisdotca/wakusei-planets) is installed: [guide](docs/guides/the-real-planets.md)) where they are at a date and time, with the Moon's phase and the Earth's day side
133
153
  from the light, a compressed scale you can read (and a true one that shows how empty it is), time that runs forwards or backwards, and a zoom from the Earth to the solar system. Positions are
134
154
  computed in the browser by astronomy-engine (MIT), nothing is fetched. [docs/space.md](docs/space.md).
135
155
 
@@ -178,7 +198,7 @@ rotate or drag controls.
178
198
 
179
199
  ```html
180
200
  <div id="globe" tabindex="0"><chikyu-earth size="420"></chikyu-earth></div>
181
- <kazoku-view-controls id="controls" for="globe" address controls="advanced" tilt-max="90" speed="0.004178" autoplay></kazoku-view-controls>
201
+ <kazoku-view-controls id="controls" for="globe" address grab-radius="fit" controls="advanced" tilt-max="90" speed="0.004178" autoplay></kazoku-view-controls>
182
202
  ```
183
203
 
184
204
  ```ts no-run
@@ -243,6 +263,188 @@ countryList().find((c) => c.alpha2 === "JP"); // { name: "Japan", ja: "日本",
243
263
 
244
264
  To take newer outlines, update `@johnmorrisdotca/chizu`; there is no data file in this repository.
245
265
 
266
+ ## Examples
267
+
268
+ Every `ts` block in this README that is not marked `no-run` is type-checked and run against the package as npm packs it (`pnpm test:readme`).
269
+
270
+ ```ts
271
+ import { COUNTRIES, countryList } from "@johnmorrisdotca/chikyu-earth";
272
+
273
+ COUNTRIES.features.length; // 177
274
+ countryList().find((country) => country.alpha2 === "CA")?.ja; // "カナダ"
275
+ ```
276
+
277
+ A globe with a graticule, centred on Tokyo, as a string:
278
+
279
+ ```ts
280
+ import { globe } from "@johnmorrisdotca/chikyu-earth";
281
+
282
+ const svg = globe({ size: 240, style: "thick", centre: { lon: 139.7, lat: 35.7 }, graticule: true });
283
+ if (!svg.startsWith("<svg")) throw new Error("not an SVG");
284
+ ```
285
+
286
+ The turn of the Earth, from the time:
287
+
288
+ ```ts
289
+ import { centreRotation, rotationAt, SIDEREAL_DAY_MS, spinAt } from "@johnmorrisdotca/chikyu-earth";
290
+
291
+ const tokyo = { lon: 139.7, lat: 35.7 };
292
+ console.log(centreRotation(tokyo), rotationAt(tokyo, SIDEREAL_DAY_MS / 2, 0), spinAt(SIDEREAL_DAY_MS / 4));
293
+ ```
294
+
295
+ What a shared controller's camera means for the projection:
296
+
297
+ ```ts
298
+ import { HOME_VIEW, projectionView } from "@johnmorrisdotca/chikyu-earth";
299
+
300
+ const view = projectionView({ lon: 0, lat: 0 }, 400, { ...HOME_VIEW, zoom: 2 });
301
+ console.log(view.scale, view.translate);
302
+ ```
303
+
304
+ A look that does not exist falls back to the default instead of failing:
305
+
306
+ ```ts
307
+ import { cleanStyle, STYLE_NAMES } from "@johnmorrisdotca/chikyu-earth";
308
+
309
+ console.log(STYLE_NAMES, cleanStyle("neon"));
310
+ ```
311
+
312
+ The globe with a graticule and the realistic Earth, side by side in HTML:
313
+
314
+ ```html
315
+ <chikyu-earth center="-79.38,43.65" look="line" graticule size="240"></chikyu-earth>
316
+ <chikyu-earth-realistic center="-79.38,43.65" time="2026-06-21T12:00Z" style="display: block; width: 240px"></chikyu-earth-realistic>
317
+ ```
318
+
319
+ A page that cannot run script uses an iframe of the embed page:
320
+
321
+ ```html
322
+ <iframe src="https://johnmorrisdotca.github.io/chikyu-earth/embed.html?look=thick&center=10,30&graticule=1" title="The Earth" width="320" height="320" style="border:0"></iframe>
323
+ ```
324
+
325
+ ## The code builder
326
+
327
+ [The code builder](https://johnmorrisdotca.github.io/chikyu-earth/builder.html) is one screen: choose the place to centre on, the look, the graticule and the size, then pick how your page is made (HTML from a CDN, a module, React or an iframe) and copy the code. It writes the same text the guides show.
328
+
329
+ <p align="center"><img alt="The code builder: rows of places, looks, graticule and size, tabs for each way a page is made, a preview and the code to copy" src="docs/images/builder-desk.png" width="640"></p>
330
+
331
+ ## API
332
+
333
+ The reference is a site, made from the source's own doc comments: every export has a summary, its parameters, what it returns and an example that runs when the site is built. [Open the reference](https://johnmorrisdotca.github.io/chikyu-earth/docs/).
334
+
335
+ | Entry point | What it gives |
336
+ | --- | --- |
337
+ | `@johnmorrisdotca/chikyu-earth` | The pure side: `globe`, `COUNTRIES`, `countryList`, the looks, the rotation and view maths. No browser. |
338
+ | `.../element` | `<chikyu-earth>`. |
339
+ | `.../realistic`, `.../realistic/element` | The Earth from space; `three` for the element. |
340
+ | `.../markers` | `attachMarkers` and the pure projection, clusters and labels. |
341
+ | `.../space`, `.../space/element` | The Sun, the Moon and the planets; `astronomy-engine` and `three`. |
342
+ | `.../satellites` | SGP4 for a group of satellites; `satellite.js`. |
343
+
344
+ ## Guides
345
+
346
+ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-started.md).
347
+
348
+ | Guide | What it is for |
349
+ | --- | --- |
350
+ | [Getting started](docs/guides/getting-started.md) | A globe on a page |
351
+ | [HTML and CDN](docs/guides/html-and-cdn.md) | A script tag from jsDelivr or unpkg |
352
+ | [Bundlers](docs/guides/bundlers.md) | Vite and webpack |
353
+ | [Frameworks](docs/guides/frameworks.md) | React, Vue, Svelte, Angular |
354
+ | [Embed in an iframe](docs/guides/embed-in-an-iframe.md) | No script of your own |
355
+ | [TypeScript and Node](docs/guides/typescript-and-node.md) | Types and the pure side |
356
+ | [The realistic Earth and markers](docs/guides/realistic-and-markers.md) | The Earth from space, markers |
357
+ | [Satellites](docs/guides/satellites.md) | SGP4 and the space view |
358
+ | [Ride along](docs/guides/ride-along.md) | A camera on a moving body |
359
+ | [How it stays light](docs/guides/how-it-works.md) | The budget |
360
+ | [Architecture](docs/guides/architecture.md) | How the layers fit |
361
+ | [Troubleshooting](docs/guides/troubleshooting.md) | Something does not appear |
362
+ | [Upgrading](docs/guides/upgrading.md) | What to act on between versions |
363
+
364
+ ## Limits
365
+
366
+ - The outlines are Natural Earth 1:110m: good for a globe, not for a street map. `COUNTRIES` has 177 features, Antarctica included.
367
+ - Three places have no two-letter code (`alpha2` is `null`), and Kosovo is `XK`.
368
+ - The Earth from space and the space view need WebGL; without it the line globe is drawn.
369
+ - Satellite elements are a day's snapshot you supply; the package fetches nothing. The positions are SGP4's, good for a picture, not for pointing an antenna.
370
+
371
+ ```ts
372
+ import { countryList } from "@johnmorrisdotca/chikyu-earth";
373
+
374
+ console.log(countryList().filter((country) => country.alpha2 === null).map((country) => country.name));
375
+ ```
376
+
377
+ ## Accessibility
378
+
379
+ - A reader who prefers reduced motion gets a still globe, and the riding-along camera draws at most one frame a second.
380
+ - The view takes the keyboard through the shared controls, and the markers' labels are real buttons.
381
+ - Names are available in English and Japanese.
382
+
383
+ ```html
384
+ <div id="globe" tabindex="0" role="group" aria-label="The Earth"><chikyu-earth size="420"></chikyu-earth></div>
385
+ ```
386
+
387
+ ## Browser and runtime support
388
+
389
+ - The package needs Node 24 or later. The pure side runs in Node and in any current browser; the elements need a current browser.
390
+ - The Earth from space and the space view need WebGL and `three` `>=0.160.0` (an optional peer); the space view also needs `astronomy-engine`, and satellites `satellite.js`:
391
+
392
+ ```sh
393
+ npm install three astronomy-engine satellite.js
394
+ ```
395
+
396
+ - The tests run the demo in Chromium and WebKit at a phone's width and a desk's, with WebGL drawn in software.
397
+
398
+ ## Languages
399
+
400
+ The countries have English and Japanese names (`countryList()` gives `name` and `ja`), the demo is in both, and every guide in [docs/guides](docs/guides) has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-started.md), one language to a page.
401
+
402
+ ```ts
403
+ import { countryList } from "@johnmorrisdotca/chikyu-earth";
404
+
405
+ console.log(countryList().find((country) => country.alpha2 === "JP"));
406
+ ```
407
+
408
+ ## Architecture
409
+
410
+ One small core and four optional layers, each its own entry point. The core is a pure function that returns an SVG string; the layers add the Earth from space, markers, the space view and satellites. [Architecture](docs/guides/architecture.md) has the layers.
411
+
412
+ ```ts
413
+ import { DEGREES_PER_MS } from "@johnmorrisdotca/chikyu-earth";
414
+
415
+ console.log((DEGREES_PER_MS * 1000).toFixed(6), "degrees a second");
416
+ ```
417
+
418
+ ## Development
419
+
420
+ ```sh
421
+ pnpm install
422
+ pnpm check # lint, types, unit tests, the build and the packed package
423
+ pnpm test:readme # the README's ts blocks, type-checked and run against the packed package
424
+ pnpm test:usage # every way of using it, built or run
425
+ pnpm docs:check # the reference site's checks
426
+ pnpm test:demo # the demo, the embed page and the docs site in a real browser
427
+ pnpm dev # the demo on http://127.0.0.1:8200/chikyu-earth/
428
+ ```
429
+
430
+ ## Contributing
431
+
432
+ See [CONTRIBUTING.md](CONTRIBUTING.md). Work in a git worktree from `origin/main`, one branch per change:
433
+
434
+ ```sh
435
+ git worktree add ../chikyu-work -b my-change origin/main
436
+ ```
437
+
438
+ The rules that matter most: draw from public facts and cite them, no data of our own, a look changes lines and fills and never the geometry, and a fact with no source is left out.
439
+
440
+ ## Changes
441
+
442
+ [CHANGELOG.md](CHANGELOG.md) lists every release with its date.
443
+
444
+ ## Licence
445
+
446
+ MIT: see [LICENSE](LICENSE). The outlines are Natural Earth's (public domain), and the realistic Earth's pictures are made from NASA Earth Observatory images: [NOTICE.md](NOTICE.md) says what each rests on.
447
+
246
448
  ## The name
247
449
 
248
450
  Chikyu (地球, ちきゅう) is Japanese for the Earth.
package/dist/element.d.ts CHANGED
@@ -20,13 +20,16 @@ export declare class ChikyuEarth extends HTMLElement {
20
20
  get centre(): GeoPoint;
21
21
  /** A box laid over the globe for markers (see `@johnmorrisdotca/chikyu-earth/markers`): where it is, the pose of the last drawing, and a way to hear the next. */
22
22
  get overlay(): OverlayHost;
23
+ disconnectedCallback(): void;
23
24
  connectedCallback(): void;
24
25
  attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
25
26
  /**
26
27
  * Apply a shared controller's camera. Every event updates the state; `final: false` makes only the cheap
27
- * relative transform, and `final: true` redraws the orthographic projection.
28
+ * relative transform, and `final: true` redraws the orthographic projection. `live: true` says a hand is on the view (a drag, a pinch, a key held):
29
+ * the projection is then also redrawn while it turns, at most 30 times a second, so the globe follows the pointer instead of jumping when it is let go.
30
+ * The automatic turn leaves `live` off and is drawn about once a second.
28
31
  */
29
- setView(view: GlobeView, final?: boolean): void;
32
+ setView(view: GlobeView, final?: boolean, live?: boolean): void;
30
33
  }
31
34
  declare global {
32
35
  interface HTMLElementTagNameMap {
package/dist/element.js CHANGED
@@ -14,6 +14,8 @@ const readCentre = (value) => {
14
14
  return null;
15
15
  return { lon, lat };
16
16
  };
17
+ /** The least time between two redraws of the projection while a hand is turning the globe: 30 a second at most. */
18
+ const LIVE_MS = 1000 / 30;
17
19
  const STYLE = ":host{display:block;position:relative}.holder svg{display:block;width:100%;height:auto}.overlay{position:absolute;inset:0;pointer-events:none;transform-origin:50% 50%}";
18
20
  /**
19
21
  * The `<chikyu-earth>` custom element: the line globe, drawn as SVG in its shadow root. Importing this entry point registers the tag once. It takes the attributes `size` (pixels, 320 by default), `center` (`"lon,lat"`; wins over the browser's location), `look` (`line` or `thick`; `style` is the older name for it, and a framework that reads `style` as CSS cannot use it) and `graticule`, and a shared view controller's camera through `setView`.
@@ -36,6 +38,8 @@ export class ChikyuEarth extends HTMLElement {
36
38
  #listeners = new Set();
37
39
  #overlay;
38
40
  #pose = null;
41
+ #liveTimer;
42
+ #liveAt = 0;
39
43
  /** Where the view is centred now: the `center` attribute, else the reader's place once the browser has answered. */
40
44
  get centre() {
41
45
  return { ...this.#centre };
@@ -52,6 +56,10 @@ export class ChikyuEarth extends HTMLElement {
52
56
  },
53
57
  };
54
58
  }
59
+ disconnectedCallback() {
60
+ clearTimeout(this.#liveTimer);
61
+ this.#liveTimer = undefined;
62
+ }
55
63
  connectedCallback() {
56
64
  this.#centre = readCentre(this.getAttribute("center")) ?? { lon: 0, lat: 0 };
57
65
  this.#render();
@@ -65,14 +73,27 @@ export class ChikyuEarth extends HTMLElement {
65
73
  }
66
74
  /**
67
75
  * Apply a shared controller's camera. Every event updates the state; `final: false` makes only the cheap
68
- * relative transform, and `final: true` redraws the orthographic projection.
76
+ * relative transform, and `final: true` redraws the orthographic projection. `live: true` says a hand is on the view (a drag, a pinch, a key held):
77
+ * the projection is then also redrawn while it turns, at most 30 times a second, so the globe follows the pointer instead of jumping when it is let go.
78
+ * The automatic turn leaves `live` off and is drawn about once a second.
69
79
  */
70
- setView(view, final = true) {
80
+ setView(view, final = true, live = false) {
71
81
  this.#view = { ...view };
72
- if (final)
82
+ if (final) {
83
+ clearTimeout(this.#liveTimer);
84
+ this.#liveTimer = undefined;
73
85
  this.#render();
74
- else
75
- this.#transform();
86
+ return;
87
+ }
88
+ this.#transform();
89
+ if (live && (view.yaw !== this.#drawn.yaw || view.tilt !== this.#drawn.tilt) && this.#liveTimer === undefined) {
90
+ const wait = Math.max(0, LIVE_MS - (performance.now() - this.#liveAt));
91
+ this.#liveTimer = setTimeout(() => {
92
+ this.#liveTimer = undefined;
93
+ this.#liveAt = performance.now();
94
+ this.#render();
95
+ }, wait);
96
+ }
76
97
  }
77
98
  #locate() {
78
99
  if (readCentre(this.getAttribute("center")))
@@ -18,6 +18,19 @@ type Three = ThreeParts;
18
18
  */
19
19
  export declare const ATMOSPHERE_OUTER = 1.08;
20
20
  /** What the scene reads at each draw; the element changes it and asks for a draw. */
21
+ /**
22
+ * How the Earth is lit: `sun` (the true light, with the night side dark and the city lights on it), `lit` (always lit, as if by daylight from the camera's side, the day picture and no city lights: the night side is never a black frame)
23
+ * or `boost` (the true terminator, with the night side raised so the land and coasts read).
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import type { LightMode } from "@johnmorrisdotca/chikyu-earth/realistic";
28
+ *
29
+ * const modes: LightMode[] = ["sun", "lit", "boost"];
30
+ * console.log(modes.join(", "));
31
+ * ```
32
+ */
33
+ export type LightMode = "sun" | "lit" | "boost";
21
34
  export interface EarthModel {
22
35
  /** The home centre; the shared controls' yaw and tilt are added to it as in the flat globe. */
23
36
  centre: GeoPoint;
@@ -26,6 +39,8 @@ export interface EarthModel {
26
39
  time: number;
27
40
  clouds: boolean;
28
41
  lights: boolean;
42
+ /** How the Earth is lit (see `LightMode`). */
43
+ light: LightMode;
29
44
  /** Where the camera looked at the last draw (the element decides from it whether a new draw is worth it). */
30
45
  drawn: {
31
46
  view: GlobeView;
@@ -22,6 +22,7 @@ export const newModel = () => ({
22
22
  time: Date.now(),
23
23
  clouds: true,
24
24
  lights: true,
25
+ light: "sun",
25
26
  drawn: null,
26
27
  ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
27
28
  });
@@ -92,7 +93,7 @@ export function createEarthItem(model, deps) {
92
93
  const surface = new three.ShaderMaterial({
93
94
  vertexShader: SURFACE_VERT,
94
95
  fragmentShader: SURFACE_FRAG,
95
- uniforms: { dayMap: uniform.day, nightMap: uniform.night, waterMap: uniform.water, sunDir, lights: { value: 1 }, ortho: { value: 1 } },
96
+ uniforms: { dayMap: uniform.day, nightMap: uniform.night, waterMap: uniform.water, sunDir, lights: { value: 1 }, boost: { value: 0 }, ortho: { value: 1 } },
96
97
  });
97
98
  const cloudShift = { value: 0 };
98
99
  const cloudMaterial = new three.ShaderMaterial({
@@ -133,9 +134,12 @@ export function createEarthItem(model, deps) {
133
134
  turned.rotation.set(look.lat * RAD, -look.lon * RAD, 0, "XYZ");
134
135
  const [sx, sy, sz] = unitVector(subsolarPoint(model.time));
135
136
  sunDir.value.set(sx, sy, sz).applyEuler(turned.rotation);
137
+ if (model.light === "lit")
138
+ sunDir.value.set(0, 0, 1);
136
139
  cloudShift.value = -(((model.time / 3_600_000) * deps.drift) % 360) / 360;
137
140
  clouds.visible = model.clouds;
138
- surface.uniforms["lights"].value = model.lights ? 1 : 0;
141
+ surface.uniforms["lights"].value = model.lights && model.light !== "lit" ? 1 : 0;
142
+ surface.uniforms["boost"].value = model.light === "boost" ? 1 : 0;
139
143
  const radius = discRadius(size.width, size.height, view.zoom);
140
144
  camera.left = (-size.width / 2 - view.panX) / radius;
141
145
  camera.right = (size.width / 2 - view.panX) / radius;
@@ -1,4 +1,5 @@
1
1
  import type { GeoPoint, GlobeView } from "../types.ts";
2
+ import { type LightMode } from "./earth.ts";
2
3
  import { setSharedRenderer, setThreeLoader } from "./shared.ts";
3
4
  export { setSharedRenderer, setThreeLoader };
4
5
  import type { OverlayHost } from "../markers/layer.ts";
@@ -60,6 +61,9 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
60
61
  set time(value: number | Date | "now");
61
62
  get clouds(): boolean;
62
63
  set clouds(value: boolean);
64
+ /** How the Earth is lit: `sun` (true, the default), `lit` (always lit: the night side is never a black frame) or `boost` (the true terminator with the night side raised). */
65
+ get light(): LightMode;
66
+ set light(value: LightMode);
63
67
  get lights(): boolean;
64
68
  set lights(value: boolean);
65
69
  /** What the element is doing, for a page or a test: its state, the texture widths held, the draws made. */
@@ -20,6 +20,8 @@ const readCentre = (value) => {
20
20
  return null;
21
21
  return { lon: lon, lat: lat };
22
22
  };
23
+ /** A `light` attribute: `lit` or `boost`, else the true sun. */
24
+ const readLight = (value) => (value === "lit" || value === "boost" ? value : "sun");
23
25
  const readRatio = (value) => {
24
26
  const ratio = Number(value);
25
27
  return value !== null && Number.isFinite(ratio) && ratio > 0 ? Math.min(ratio, 2) : undefined;
@@ -58,7 +60,7 @@ export const readTime = (value) => {
58
60
  * ```
59
61
  */
60
62
  export class ChikyuEarthRealistic extends HTMLElement {
61
- static observedAttributes = ["center", "time", "clouds", "lights", "live-seconds"];
63
+ static observedAttributes = ["center", "time", "clouds", "lights", "light", "live-seconds"];
62
64
  #model = newModel();
63
65
  #mode = "now";
64
66
  #view;
@@ -84,6 +86,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
84
86
  this.#model.time = this.#mode === "now" ? Date.now() : this.#mode;
85
87
  this.#model.clouds = this.getAttribute("clouds") !== "off";
86
88
  this.#model.lights = this.getAttribute("lights") !== "off";
89
+ this.#model.light = readLight(this.getAttribute("light"));
87
90
  if (!this.hasAttribute("role"))
88
91
  this.setAttribute("role", "img");
89
92
  if (!this.hasAttribute("aria-label"))
@@ -160,6 +163,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
160
163
  this.clouds = value !== "off";
161
164
  else if (name === "lights")
162
165
  this.lights = value !== "off";
166
+ else if (name === "light")
167
+ this.light = readLight(value);
163
168
  else if (name === "live-seconds")
164
169
  this.#startTick();
165
170
  }
@@ -204,6 +209,14 @@ export class ChikyuEarthRealistic extends HTMLElement {
204
209
  this.#model.clouds = value;
205
210
  this.#gate?.soon();
206
211
  }
212
+ /** How the Earth is lit: `sun` (true, the default), `lit` (always lit: the night side is never a black frame) or `boost` (the true terminator with the night side raised). */
213
+ get light() {
214
+ return this.#model.light;
215
+ }
216
+ set light(value) {
217
+ this.#model.light = value;
218
+ this.#gate?.soon();
219
+ }
207
220
  get lights() {
208
221
  return this.#model.lights;
209
222
  }
@@ -1,5 +1,5 @@
1
1
  export { subsolarPoint, unitVector, julianDay } from "./sun.ts";
2
2
  export { chooseTier, textureBytes, textureCap, MAX_TEXTURE, TIERS, TEXELS_PER_RADIUS_PIXEL, type Layer } from "./tiers.ts";
3
3
  export { createGate, frameCap, type Gate } from "./gate.ts";
4
- export { lookAt, discRadius, ATMOSPHERE_OUTER } from "./earth.ts";
4
+ export { lookAt, discRadius, ATMOSPHERE_OUTER, type LightMode } from "./earth.ts";
5
5
  export type { ThreeParts } from "./earth.ts";
@@ -1,5 +1,5 @@
1
1
  export declare const SURFACE_VERT = "\nvarying vec2 vUv;\nvarying vec3 vNormal;\nvarying vec3 vWorld;\nvoid main() {\n vUv = uv;\n vNormal = normalize(mat3(modelMatrix) * position);\n vWorld = (modelMatrix * vec4(position, 1.0)).xyz;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}";
2
- export declare const SURFACE_FRAG = "\nuniform sampler2D dayMap;\nuniform sampler2D nightMap;\nuniform sampler2D waterMap;\nuniform vec3 sunDir;\nuniform float lights;\nuniform float ortho;\nvarying vec2 vUv;\nvarying vec3 vNormal;\nvarying vec3 vWorld;\nvoid main() {\n vec3 n = normalize(vNormal);\n vec3 toEye = ortho > 0.5 ? vec3(0.0, 0.0, 1.0) : normalize(cameraPosition - vWorld);\n float ndl = dot(n, sunDir);\n float day = smoothstep(-0.10, 0.22, ndl);\n vec3 albedo = texture2D(dayMap, vUv).rgb;\n float water = texture2D(waterMap, vUv).r;\n\n vec3 lit = albedo * (0.07 + 1.0 * pow(max(ndl, 0.0), 0.5));\n float dusk = smoothstep(-0.14, 0.0, ndl) * (1.0 - smoothstep(0.0, 0.30, ndl));\n lit += vec3(0.55, 0.28, 0.14) * dusk * 0.30 * (0.35 + 0.65 * albedo.g);\n\n vec3 h = normalize(sunDir + toEye);\n float glint = pow(max(dot(n, h), 0.0), 220.0) * water * day;\n lit += vec3(1.0, 0.93, 0.80) * glint * 0.7;\n\n vec3 night = texture2D(nightMap, vUv).rgb;\n night = night * night * vec3(1.6, 1.5, 1.3) * lights + night * 0.25;\n vec3 col = mix(night, lit, day);\n\n float rim = pow(1.0 - clamp(dot(n, toEye), 0.0, 1.0), 3.0);\n float sunSide = 0.12 + 0.88 * smoothstep(-0.25, 0.5, ndl);\n col += vec3(0.20, 0.45, 1.0) * rim * sunSide * 0.55;\n gl_FragColor = vec4(col, 1.0);\n}";
2
+ export declare const SURFACE_FRAG = "\nuniform sampler2D dayMap;\nuniform sampler2D nightMap;\nuniform sampler2D waterMap;\nuniform vec3 sunDir;\nuniform float lights;\nuniform float boost;\nuniform float ortho;\nvarying vec2 vUv;\nvarying vec3 vNormal;\nvarying vec3 vWorld;\nvoid main() {\n vec3 n = normalize(vNormal);\n vec3 toEye = ortho > 0.5 ? vec3(0.0, 0.0, 1.0) : normalize(cameraPosition - vWorld);\n float ndl = dot(n, sunDir);\n float day = smoothstep(-0.10, 0.22, ndl);\n vec3 albedo = texture2D(dayMap, vUv).rgb;\n float water = texture2D(waterMap, vUv).r;\n\n vec3 lit = albedo * (0.07 + 1.0 * pow(max(ndl, 0.0), 0.5));\n float dusk = smoothstep(-0.14, 0.0, ndl) * (1.0 - smoothstep(0.0, 0.30, ndl));\n lit += vec3(0.55, 0.28, 0.14) * dusk * 0.30 * (0.35 + 0.65 * albedo.g);\n\n vec3 h = normalize(sunDir + toEye);\n float glint = pow(max(dot(n, h), 0.0), 220.0) * water * day;\n lit += vec3(1.0, 0.93, 0.80) * glint * 0.7;\n\n vec3 night = texture2D(nightMap, vUv).rgb;\n night = night * night * vec3(1.6, 1.5, 1.3) * lights + night * 0.25;\n vec3 col = mix(night, lit, day);\n col += pow(albedo, vec3(0.75)) * boost * 0.65 * (1.0 - day);\n\n float rim = pow(1.0 - clamp(dot(n, toEye), 0.0, 1.0), 3.0);\n float sunSide = 0.12 + 0.88 * smoothstep(-0.25, 0.5, ndl);\n col += vec3(0.20, 0.45, 1.0) * rim * sunSide * 0.55;\n gl_FragColor = vec4(col, 1.0);\n}";
3
3
  export declare const CLOUD_FRAG = "\nuniform sampler2D cloudMap;\nuniform vec3 sunDir;\nuniform float shift;\nuniform float opacity;\nvarying vec2 vUv;\nvarying vec3 vNormal;\nvoid main() {\n vec3 n = normalize(vNormal);\n float ndl = dot(n, sunDir);\n float c = texture2D(cloudMap, vec2(vUv.x + shift, vUv.y)).r;\n float a = smoothstep(0.28, 0.88, c) * opacity;\n float day = smoothstep(-0.10, 0.25, ndl);\n vec3 col = mix(vec3(0.015, 0.02, 0.04), vec3(1.0), day * (0.18 + 0.82 * pow(max(ndl, 0.0), 0.45)));\n col += vec3(0.55, 0.28, 0.14) * smoothstep(-0.14, 0.0, ndl) * (1.0 - smoothstep(0.0, 0.25, ndl)) * 0.35;\n gl_FragColor = vec4(col, a);\n}";
4
4
  export declare const ATMOSPHERE_VERT = "\nvarying vec3 vPosView;\nvarying vec3 vNormalView;\nvoid main() {\n vec4 view = modelViewMatrix * vec4(position, 1.0);\n vPosView = view.xyz;\n vNormalView = normalize(normalMatrix * position);\n gl_Position = projectionMatrix * view;\n}";
5
5
  export declare const ATMOSPHERE_FRAG = "\nuniform vec3 sunView;\nuniform float outer;\nuniform float ortho;\nvarying vec3 vPosView;\nvarying vec3 vNormalView;\nvoid main() {\n vec3 n = normalize(vNormalView);\n vec3 v = ortho > 0.5 ? vec3(0.0, 0.0, 1.0) : normalize(-vPosView);\n float nz = clamp(dot(n, v), -1.0, 1.0);\n float rho = outer * sqrt(max(0.0, 1.0 - nz * nz));\n float t = clamp((rho - 1.0) / (outer - 1.0), 0.0, 1.0);\n vec2 dir = normalize(n.xy + vec2(1e-5, 0.0));\n float side = smoothstep(-0.40, 0.55, dot(vec3(dir, 0.0), sunView));\n float glow = pow(1.0 - t, 3.0) * (0.10 + 0.90 * side);\n vec3 col = mix(vec3(0.10, 0.22, 0.60), vec3(0.42, 0.68, 1.0), side);\n gl_FragColor = vec4(col, glow * 0.9);\n}";
@@ -16,6 +16,7 @@ uniform sampler2D nightMap;
16
16
  uniform sampler2D waterMap;
17
17
  uniform vec3 sunDir;
18
18
  uniform float lights;
19
+ uniform float boost;
19
20
  uniform float ortho;
20
21
  varying vec2 vUv;
21
22
  varying vec3 vNormal;
@@ -39,6 +40,7 @@ void main() {
39
40
  vec3 night = texture2D(nightMap, vUv).rgb;
40
41
  night = night * night * vec3(1.6, 1.5, 1.3) * lights + night * 0.25;
41
42
  vec3 col = mix(night, lit, day);
43
+ col += pow(albedo, vec3(0.75)) * boost * 0.65 * (1.0 - day);
42
44
 
43
45
  float rim = pow(1.0 - clamp(dot(n, toEye), 0.0, 1.0), 3.0);
44
46
  float sunSide = 0.12 + 0.88 * smoothstep(-0.25, 0.5, ndl);