@johnmorrisdotca/chikyu-earth 0.22.1 → 0.23.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 +9 -0
- package/README.md +3 -2
- package/dist/realistic/element.d.ts +34 -1
- package/dist/realistic/element.js +127 -12
- package/dist/space/element.d.ts +10 -1
- package/dist/space/element.js +33 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.23.0 - 2026-11-10
|
|
6
|
+
|
|
7
|
+
- **The date follows the clock, and the demo has Play, Pause and Back** (MODULES-784, MODULES-755). `<chikyu-space>` sends `chikyu-timechange` with `detail: { time, running }`: while the clock runs (`speed` not 0) four times a second at most however fast the picture is drawn (as often as the clock steps at real time), only while the tab is shown, and once with `running: false` when the clock holds, so a page can write the date it stopped on. `<chikyu-earth-realistic>` sends it too while its `time="now"` clock steps (every `live-seconds`) and once when it is given a date. `chikyu-time` stays as the every-step event and is documented so. Setting `speed` to 0 now keeps the moment the reader last saw, and the clock goes on from there.
|
|
8
|
+
- **The demo's Time row is kazoku-ui's `<kazoku-replay-bar>`** next to the date field, in place of the Time speed buttons: Play runs from the date shown and the box follows it (never while the reader is typing in it), Pause holds it and writes the date reached into `time`, Back to the date returns to the date chosen, and riding along starts the clock. `play=on` and `speed` stay in the address, and the date when the clock stops or the reader leaves. The space view opens held; `speed=0` links stay held, links that name a speed and no `play` keep running, and a reader who prefers reduced motion gets Play left off. Guide in English and Japanese: `docs/guides/time-and-play.md`. Test: `e2e/date-play.demo.ts`.
|
|
9
|
+
|
|
10
|
+
- **Play for the realistic Earth: `<chikyu-earth-realistic>` has a `speed`** (MODULES-799), with `<chikyu-space>`'s name and rules. `speed` is how many seconds pass for each real second (`0` holds, `3600` an hour a second, `86400` a day a second, negative runs backwards); the clock runs on from the date shown, and the Sun's light, the night side and the clouds follow it. Draws are at most 30 a second (as often as the Sun's turn moves a pixel, once a second at least, one step a second for a reader who prefers reduced motion), and nothing is drawn while it holds, is out of sight or is in a hidden tab. `chikyu-timechange` follows the same rules as the space view's: four a second at most while it runs, and once with `running: false` when it holds (a date set, or `speed` set to 0). Old links keep working: with no `speed`, `time="now"` still follows the real clock (the Sun and clouds put right every `live-seconds`) and a date still holds. `time` now reads the moment reached while the clock runs. New export `readSpeed`. The demo's Play bar runs the realistic look too: Play from `now` starts from the moment shown and writes it into `time`, Back returns to following the real clock when the date was `now`, and `play` and `speed` stay in the address. Guide section in English and Japanese: `docs/guides/time-and-play.md`. Tests: `e2e/realistic-play.demo.ts`, and the clock added to `e2e/freeze.demo.ts`.
|
|
11
|
+
- **A flaky test mended** (MODULES-800). `e2e/ride.gl.ts` "a reader who asked for reduced motion gets a jump and one step a second" failed about 3 runs in 4 on a loaded Mac: `freezeClock` paused the page's clock 50 ms past the time it had just read, and by then the clock had moved on, so `pauseAt` threw "Cannot fast-forward to the past". The pause is now 3 s ahead of the page's own time, and the glide test uses the same helper. The same sweep: a hold (Pause, a speed of 0) leaves one last frame already queued, and drawing it is right, but on a loaded Mac it landed after the 800 ms the "nothing is drawn while paused" tests allowed (`e2e/date-play.demo.ts` failed 2 runs in 3; the freeze test of the space clock had the same wait). `untilStill` in `e2e/gl.ts` waits until the draw and frame-request counts are the same a second apart (and fails after 20 s if frames keep coming) before the test measures rest; the element was not at fault.
|
|
12
|
+
- **Two more flaky tests mended** (MODULES-804, MODULES-805); the element and its pages are unchanged. `e2e/passes.demo.ts` "the satellite, the days, all passes and the darker sky change the list" ran out of its 5 s waits in CI. The list was never slow (worked out in 30 to 150 ms): in the desk and phone Chromium projects, which draw WebGL in software, the page's own pictures were drawn by the same emulated GPU too, and the passes page's world map alone kept that GPU busy for 5 to 10 s, from about a second after the page opened, in which the page drew no frame and answered no click (a click took 6 s; the whole test, 9 to 12 s, now takes under 1 s). Those two projects now rasterize the page on the CPU (`--disable-gpu-rasterization`; WebGL is still drawn in software), and the test waits for the count the page sets when it has made the list (`#data-note[data-passes]`), for up to 20 s, not for the `days` attribute that changes the moment the button is pressed. `e2e/ride.gl.ts` "paused it rests, and out of sight or in a hidden tab it draws nothing while the clock runs" took 20 to 60 s of its 60: 15 s of its own waits, and up to 44 s of waiting for the software GPU to finish the 33 s of frames the test before it (the frame-rate test) had asked for, which the browser made this test wait for with its clock running. That test now ends with `drainGpu` (a one-pixel read, in `e2e/gl.ts`), draws 2.5 s windows instead of 4 s, and the paused, out-of-sight and hidden-tab checks are three tests on the test's own clock (about 6 s each); the out-of-sight and hidden-tab tests now prove the ride is drawing in sight at 60x first, and the hidden-tab test no longer leaves the globe scrolled out of sight (it was checking the same thing twice). "riding, stopping and riding again" spent 45 s of its 60 on fixed waits and now runs the glides and the four seconds on the test's own clock.
|
|
13
|
+
|
|
5
14
|
## 0.22.1 - 2026-11-09
|
|
6
15
|
|
|
7
16
|
- kazoku-ui 0.27: the globe and the space looks draw at most 30 frames a second while they move (KAZOKU-UI-91), as the family's freeze rule asks; nothing else changes.
|
package/README.md
CHANGED
|
@@ -162,13 +162,13 @@ atmosphere at the rim, drawn with three.js through kazoku-ui's shared renderer.
|
|
|
162
162
|
|
|
163
163
|
Needs `three` and `@johnmorrisdotca/kazoku-ui` (both optional peers) and the pictures (1.6 MB, from NASA, in `dist/textures/`). It draws nothing while nothing changes,
|
|
164
164
|
at most 30 times a second while it does, in one WebGL context, with textures that grow as you zoom and are freed after. With `tiles="/tiles/"` (a folder of NASA map
|
|
165
|
-
tiles, [how](docs/guides/earth-tiles.md)) it loads only the finer tiles in view, so you can zoom in to 20 times and stay sharp. All of it, the budget and the tests:
|
|
165
|
+
tiles, [how](docs/guides/earth-tiles.md)) it loads only the finer tiles in view, so you can zoom in to 20 times and stay sharp. With `speed="86400"` (a day a second; the name `<chikyu-space>` uses) its clock runs on from the date shown and the Sun, the night side and the clouds follow it ([guide](docs/guides/time-and-play.md)). All of it, the budget and the tests:
|
|
166
166
|
[docs/realistic.md](docs/realistic.md).
|
|
167
167
|
|
|
168
168
|
## The Sun, the Moon and the planets
|
|
169
169
|
|
|
170
170
|
`<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
|
|
171
|
-
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
|
|
171
|
+
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 (Play, Pause and Back in the demo, and a `chikyu-timechange` event for a date box to follow: [guide](docs/guides/time-and-play.md)), and a zoom from the Earth to the solar system. Positions are
|
|
172
172
|
computed in the browser by astronomy-engine (MIT), nothing is fetched. [docs/space.md](docs/space.md). The solar system is wakusei-planets' to own, so this view is moving there; this package keeps the Earth and its satellites ([why two packages](docs/guides/two-packages.md)).
|
|
173
173
|
|
|
174
174
|
<p align="center"><img alt="The solar system on 2 November 2026 in the compressed scale: orbits round the Sun, the planets named" src="docs/images/space-solar.png" width="420"></p>
|
|
@@ -430,6 +430,7 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
|
|
|
430
430
|
| [Satellites](docs/guides/satellites.md) | SGP4 and the space view |
|
|
431
431
|
| [When can I see the ISS?](docs/guides/passes.md) | Passes over a place, the sky dome, how it was checked |
|
|
432
432
|
| [Ride along](docs/guides/ride-along.md) | A camera on a moving body |
|
|
433
|
+
| [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 |
|
|
433
434
|
| [Zoom, pan and turn](docs/guides/zoom-and-pan.md) | The hands every view carries, each zoom range and why |
|
|
434
435
|
| [Printable sheets](docs/guides/printable-sheets.md) | The globe, a world map, my country, day and night and the seasons to print and colour |
|
|
435
436
|
| [Why two packages](docs/guides/two-packages.md) | This package and wakusei-planets: which to install, alone and together |
|
|
@@ -19,6 +19,20 @@ type EarthLayer = Extract<Layer, "day" | "night" | "clouds" | "water">;
|
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
21
|
export type EarthState = "loading" | "live" | "unavailable" | "lost" | "idle";
|
|
22
|
+
/**
|
|
23
|
+
* A `speed` attribute: how many seconds pass for each real second.
|
|
24
|
+
*
|
|
25
|
+
* @param value - The attribute's text, or `null` when it is not there.
|
|
26
|
+
* @returns The speed, or `null` when the value is empty or not a number (the clock then follows `time`: real time for "now", held for a date).
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts no-run
|
|
30
|
+
* import { readSpeed } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
31
|
+
*
|
|
32
|
+
* console.log(readSpeed("86400"), readSpeed("-3600"), readSpeed(null));
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const readSpeed: (value: string | null) => number | null;
|
|
22
36
|
/**
|
|
23
37
|
* A `time` attribute: "now" (or none) follows the clock, else an ISO date such as 2026-06-21T12:00:00Z.
|
|
24
38
|
*
|
|
@@ -36,6 +50,14 @@ export declare const readTime: (value: string | null) => number | "now";
|
|
|
36
50
|
/**
|
|
37
51
|
* The `<chikyu-earth-realistic>` custom element: the Earth from space, drawn with three.js through kazoku-ui's shared renderer (one WebGL context for the page). It takes `center` (`"lon,lat"`), `time` (`now` or an ISO date; the real Sun at that moment), `clouds="off"`, `lights="off"`, `live-seconds`, `texture-base` (where the pictures are served from), `tiles` (where a set of finer map tiles is served from, see the Earth tiles guide: only the tiles in view are loaded, over the package's own pictures, which stay as the far view and the fallback; without it, or when a tile cannot be fetched, the Earth is drawn as before) and `max-ratio` (the most device pixels to a CSS pixel the canvas is drawn at, 2 at most, and `0.5` draws at half the size and scales it up: for a background; read when the element connects, and it is the shared renderer's cap for the whole page), and a shared view controller's camera through `setView`. It draws only when something changes, at most 30 times a second, and nothing while it is out of sight or the tab is hidden.
|
|
38
52
|
*
|
|
53
|
+
* It has a clock, like `<chikyu-space>`'s: `speed` is how many seconds pass for each real second (`1` is real time, `0` holds, `3600` is an hour a second, `86400` a day a second, a negative number runs backwards), and the clock runs from `time`, the moment shown.
|
|
54
|
+
* The Sun's light, the night side and the clouds follow it. Without a `speed`, nothing about a page from before changes: `time="now"` (or no `time`) follows the real clock, the Sun and the clouds put right every `live-seconds` (a minute by default, a second at the least),
|
|
55
|
+
* and a date holds still. A `speed` runs the clock from the moment shown at that rate (from now, when `time` is "now"); `speed="0"` holds it. At real time it steps every `live-seconds`; faster, it draws as often as the Sun's turn moves a pixel, once a second at least and 30 a second at most
|
|
56
|
+
* (a reader who prefers reduced motion gets one step a second), and nothing at all while it is held, out of sight or in a hidden tab.
|
|
57
|
+
*
|
|
58
|
+
* While time runs it sends `chikyu-timechange` with `detail: { time, running: true }` (the moment shown in milliseconds since 1970), at most four times a second however fast the picture is drawn and not from a hidden tab, and once with `running: false` when the clock holds
|
|
59
|
+
* (a date is set, or `speed` is set to 0): a page writes the date into its date box from it. It is not sent for a `time` the page sets itself.
|
|
60
|
+
*
|
|
39
61
|
* @example
|
|
40
62
|
* ```ts no-run
|
|
41
63
|
* import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
@@ -45,6 +67,11 @@ export declare const readTime: (value: string | null) => number | "now";
|
|
|
45
67
|
* earth.setAttribute("time", "2026-06-21T03:00Z");
|
|
46
68
|
* earth.setAttribute("texture-base", "/textures/");
|
|
47
69
|
* earth.setAttribute("tiles", "/tiles/");
|
|
70
|
+
* earth.setAttribute("speed", "86400");
|
|
71
|
+
* earth.addEventListener("chikyu-timechange", (event) => {
|
|
72
|
+
* const { time, running } = (event as CustomEvent<{ time: number; running: boolean }>).detail;
|
|
73
|
+
* console.log(new Date(time).toISOString(), running ? "running" : "held");
|
|
74
|
+
* });
|
|
48
75
|
* document.body.append(earth);
|
|
49
76
|
* ```
|
|
50
77
|
*/
|
|
@@ -64,9 +91,15 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
64
91
|
/** Where the view starts: longitude and latitude; the shared controls' yaw and tilt turn it from there. */
|
|
65
92
|
get centre(): GeoPoint;
|
|
66
93
|
set centre(value: GeoPoint);
|
|
67
|
-
/** The moment shown: milliseconds since the epoch, or "now"
|
|
94
|
+
/** The moment shown: milliseconds since the epoch, or "now" while it follows the real clock. The clock runs from it at `speed`, so a number read while time runs is the moment it has reached. */
|
|
68
95
|
get time(): number | "now";
|
|
69
96
|
set time(value: number | Date | "now");
|
|
97
|
+
/**
|
|
98
|
+
* Seconds of time for each real second: `1` is real time, `0` holds, `3600` is an hour a second, `86400` a day a second, a negative number runs backwards. Without one (the attribute `speed` left out) the clock
|
|
99
|
+
* follows `time`: real time for "now", held for a date. Reading it gives the speed in force. Setting it is setting the attribute (and `null`-like, a value that is not a number, takes it off); it works out the moment shown up to now at the old speed first, so a hold keeps the moment the reader saw last.
|
|
100
|
+
*/
|
|
101
|
+
get speed(): number;
|
|
102
|
+
set speed(value: number);
|
|
70
103
|
get clouds(): boolean;
|
|
71
104
|
set clouds(value: boolean);
|
|
72
105
|
/** 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). */
|
|
@@ -10,9 +10,13 @@ export { setSharedRenderer, setThreeLoader };
|
|
|
10
10
|
import { MAX_TEXTURE, TIERS } from "./tiers.js";
|
|
11
11
|
const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative}#stage,#overlay{position:absolute;inset:0}#overlay{pointer-events:none}";
|
|
12
12
|
const RAD = Math.PI / 180;
|
|
13
|
-
/** The Sun and the clouds are re-placed this often
|
|
13
|
+
/** The Sun and the clouds are re-placed this often at real time: 15 degrees an hour is 0.25 degree a minute. */
|
|
14
14
|
const LIVE_TICK_MS = 60_000;
|
|
15
15
|
const MIN_TICK_MS = 1000;
|
|
16
|
+
/** The least time between two `chikyu-timechange` events while time runs: a few a second at most, however fast the picture is drawn. */
|
|
17
|
+
const TIME_EVENT_MS = 250;
|
|
18
|
+
/** How fast the Sun goes round the Earth, degrees a second of real time (the light, the night side and the clouds' drift all follow it). */
|
|
19
|
+
const SUN_RATE = 360 / 86_400;
|
|
16
20
|
/** Tilt to the poles; zoom from a tenth of Fit, which leaves the whole Earth small in the view, to 5 times: the package's own pictures are sharp to about 5 times. */
|
|
17
21
|
const LIMITS = { tiltMax: 90, zoomMin: 0.1, zoomMax: 5 };
|
|
18
22
|
/** With the finer tiles the detail runs 4 times further: the finest level is 4 times wider than the widest picture. */
|
|
@@ -31,6 +35,25 @@ const readRatio = (value) => {
|
|
|
31
35
|
const ratio = Number(value);
|
|
32
36
|
return value !== null && Number.isFinite(ratio) && ratio > 0 ? Math.min(ratio, 2) : undefined;
|
|
33
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* A `speed` attribute: how many seconds pass for each real second.
|
|
40
|
+
*
|
|
41
|
+
* @param value - The attribute's text, or `null` when it is not there.
|
|
42
|
+
* @returns The speed, or `null` when the value is empty or not a number (the clock then follows `time`: real time for "now", held for a date).
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts no-run
|
|
46
|
+
* import { readSpeed } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
47
|
+
*
|
|
48
|
+
* console.log(readSpeed("86400"), readSpeed("-3600"), readSpeed(null));
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export const readSpeed = (value) => {
|
|
52
|
+
if (value === null || value.trim() === "")
|
|
53
|
+
return null;
|
|
54
|
+
const speed = Number(value);
|
|
55
|
+
return Number.isFinite(speed) ? speed : null;
|
|
56
|
+
};
|
|
34
57
|
/**
|
|
35
58
|
* A `time` attribute: "now" (or none) follows the clock, else an ISO date such as 2026-06-21T12:00:00Z.
|
|
36
59
|
*
|
|
@@ -53,6 +76,14 @@ export const readTime = (value) => {
|
|
|
53
76
|
/**
|
|
54
77
|
* The `<chikyu-earth-realistic>` custom element: the Earth from space, drawn with three.js through kazoku-ui's shared renderer (one WebGL context for the page). It takes `center` (`"lon,lat"`), `time` (`now` or an ISO date; the real Sun at that moment), `clouds="off"`, `lights="off"`, `live-seconds`, `texture-base` (where the pictures are served from), `tiles` (where a set of finer map tiles is served from, see the Earth tiles guide: only the tiles in view are loaded, over the package's own pictures, which stay as the far view and the fallback; without it, or when a tile cannot be fetched, the Earth is drawn as before) and `max-ratio` (the most device pixels to a CSS pixel the canvas is drawn at, 2 at most, and `0.5` draws at half the size and scales it up: for a background; read when the element connects, and it is the shared renderer's cap for the whole page), and a shared view controller's camera through `setView`. It draws only when something changes, at most 30 times a second, and nothing while it is out of sight or the tab is hidden.
|
|
55
78
|
*
|
|
79
|
+
* It has a clock, like `<chikyu-space>`'s: `speed` is how many seconds pass for each real second (`1` is real time, `0` holds, `3600` is an hour a second, `86400` a day a second, a negative number runs backwards), and the clock runs from `time`, the moment shown.
|
|
80
|
+
* The Sun's light, the night side and the clouds follow it. Without a `speed`, nothing about a page from before changes: `time="now"` (or no `time`) follows the real clock, the Sun and the clouds put right every `live-seconds` (a minute by default, a second at the least),
|
|
81
|
+
* and a date holds still. A `speed` runs the clock from the moment shown at that rate (from now, when `time` is "now"); `speed="0"` holds it. At real time it steps every `live-seconds`; faster, it draws as often as the Sun's turn moves a pixel, once a second at least and 30 a second at most
|
|
82
|
+
* (a reader who prefers reduced motion gets one step a second), and nothing at all while it is held, out of sight or in a hidden tab.
|
|
83
|
+
*
|
|
84
|
+
* While time runs it sends `chikyu-timechange` with `detail: { time, running: true }` (the moment shown in milliseconds since 1970), at most four times a second however fast the picture is drawn and not from a hidden tab, and once with `running: false` when the clock holds
|
|
85
|
+
* (a date is set, or `speed` is set to 0): a page writes the date into its date box from it. It is not sent for a `time` the page sets itself.
|
|
86
|
+
*
|
|
56
87
|
* @example
|
|
57
88
|
* ```ts no-run
|
|
58
89
|
* import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
@@ -62,16 +93,28 @@ export const readTime = (value) => {
|
|
|
62
93
|
* earth.setAttribute("time", "2026-06-21T03:00Z");
|
|
63
94
|
* earth.setAttribute("texture-base", "/textures/");
|
|
64
95
|
* earth.setAttribute("tiles", "/tiles/");
|
|
96
|
+
* earth.setAttribute("speed", "86400");
|
|
97
|
+
* earth.addEventListener("chikyu-timechange", (event) => {
|
|
98
|
+
* const { time, running } = (event as CustomEvent<{ time: number; running: boolean }>).detail;
|
|
99
|
+
* console.log(new Date(time).toISOString(), running ? "running" : "held");
|
|
100
|
+
* });
|
|
65
101
|
* document.body.append(earth);
|
|
66
102
|
* ```
|
|
67
103
|
*/
|
|
68
104
|
export class ChikyuEarthRealistic extends HTMLElement {
|
|
69
|
-
static observedAttributes = ["center", "time", "clouds", "lights", "light", "live-seconds", "tiles"];
|
|
105
|
+
static observedAttributes = ["center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles"];
|
|
70
106
|
#model = newModel();
|
|
71
107
|
#mode = "now";
|
|
72
108
|
#view;
|
|
73
109
|
#gate;
|
|
74
110
|
#tick;
|
|
111
|
+
/** The clock's speed when `speed` is given (attribute or property); `null` follows `time`: real time for "now", held for a date. */
|
|
112
|
+
#speed = null;
|
|
113
|
+
/** The page's own clock, in milliseconds, at the last step. */
|
|
114
|
+
#last = 0;
|
|
115
|
+
#announced = -Infinity;
|
|
116
|
+
/** The clock is running (a `running: false` is owed when it holds). */
|
|
117
|
+
#running = false;
|
|
75
118
|
#state = "loading";
|
|
76
119
|
#tiers = { day: TIERS.day[0], night: TIERS.night[0], clouds: TIERS.clouds[0], water: TIERS.water[0] };
|
|
77
120
|
#taken;
|
|
@@ -92,6 +135,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
92
135
|
this.#model.centre = readCentre(this.getAttribute("center")) ?? this.#model.centre;
|
|
93
136
|
this.#mode = readTime(this.getAttribute("time"));
|
|
94
137
|
this.#model.time = this.#mode === "now" ? Date.now() : this.#mode;
|
|
138
|
+
this.#speed = readSpeed(this.getAttribute("speed"));
|
|
139
|
+
this.#last = performance.now();
|
|
95
140
|
this.#model.clouds = this.getAttribute("clouds") !== "off";
|
|
96
141
|
this.#model.lights = this.getAttribute("lights") !== "off";
|
|
97
142
|
this.#model.light = readLight(this.getAttribute("light"));
|
|
@@ -160,6 +205,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
160
205
|
this.addEventListener("focusin", this.#take);
|
|
161
206
|
this.#hands = carryControls(this, { initial: this.#model.view, limits: LIMITS, onChange: (state, info) => this.setView(state, info.final) });
|
|
162
207
|
this.#startTick();
|
|
208
|
+
document.addEventListener("visibilitychange", this.#onVisible);
|
|
163
209
|
this.#locate();
|
|
164
210
|
}
|
|
165
211
|
disconnectedCallback() {
|
|
@@ -170,8 +216,10 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
170
216
|
if (this.#reach !== null && this.getAttribute("zoom-max") === this.#reach)
|
|
171
217
|
this.removeAttribute("zoom-max");
|
|
172
218
|
this.#reach = null;
|
|
173
|
-
|
|
219
|
+
clearTimeout(this.#tick);
|
|
174
220
|
this.#tick = undefined;
|
|
221
|
+
this.#running = false;
|
|
222
|
+
document.removeEventListener("visibilitychange", this.#onVisible);
|
|
175
223
|
this.#gate?.cancel();
|
|
176
224
|
this.#view?.dispose();
|
|
177
225
|
this.#view = undefined;
|
|
@@ -183,6 +231,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
183
231
|
this.centre = readCentre(value) ?? { lon: 0, lat: 0 };
|
|
184
232
|
else if (name === "time")
|
|
185
233
|
this.time = readTime(value);
|
|
234
|
+
else if (name === "speed")
|
|
235
|
+
this.#setSpeed(readSpeed(value));
|
|
186
236
|
else if (name === "clouds")
|
|
187
237
|
this.clouds = value !== "off";
|
|
188
238
|
else if (name === "lights")
|
|
@@ -232,9 +282,9 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
232
282
|
this.#model.centre = { ...value };
|
|
233
283
|
this.#gate?.soon();
|
|
234
284
|
}
|
|
235
|
-
/** The moment shown: milliseconds since the epoch, or "now"
|
|
285
|
+
/** The moment shown: milliseconds since the epoch, or "now" while it follows the real clock. The clock runs from it at `speed`, so a number read while time runs is the moment it has reached. */
|
|
236
286
|
get time() {
|
|
237
|
-
return this.#mode;
|
|
287
|
+
return this.#mode === "now" && this.speed === 1 ? "now" : this.#model.time;
|
|
238
288
|
}
|
|
239
289
|
set time(value) {
|
|
240
290
|
this.#mode = value instanceof Date ? value.getTime() : value;
|
|
@@ -242,6 +292,28 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
242
292
|
this.#model.time = Date.now();
|
|
243
293
|
else
|
|
244
294
|
this.#model.time = this.#mode;
|
|
295
|
+
this.#last = performance.now();
|
|
296
|
+
this.#startTick();
|
|
297
|
+
this.#gate?.soon();
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Seconds of time for each real second: `1` is real time, `0` holds, `3600` is an hour a second, `86400` a day a second, a negative number runs backwards. Without one (the attribute `speed` left out) the clock
|
|
301
|
+
* follows `time`: real time for "now", held for a date. Reading it gives the speed in force. Setting it is setting the attribute (and `null`-like, a value that is not a number, takes it off); it works out the moment shown up to now at the old speed first, so a hold keeps the moment the reader saw last.
|
|
302
|
+
*/
|
|
303
|
+
get speed() {
|
|
304
|
+
return this.#speed ?? (this.#mode === "now" ? 1 : 0);
|
|
305
|
+
}
|
|
306
|
+
set speed(value) {
|
|
307
|
+
if (Number.isFinite(value))
|
|
308
|
+
this.setAttribute("speed", String(value));
|
|
309
|
+
else
|
|
310
|
+
this.removeAttribute("speed");
|
|
311
|
+
}
|
|
312
|
+
#setSpeed(next) {
|
|
313
|
+
if (this.isConnected && this.speed !== 0)
|
|
314
|
+
this.#advance(performance.now());
|
|
315
|
+
this.#speed = next;
|
|
316
|
+
this.#last = performance.now();
|
|
245
317
|
this.#startTick();
|
|
246
318
|
this.#gate?.soon();
|
|
247
319
|
}
|
|
@@ -302,19 +374,62 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
302
374
|
get view() {
|
|
303
375
|
return { ...this.#model.view };
|
|
304
376
|
}
|
|
305
|
-
/**
|
|
377
|
+
/** Bring the moment shown up to `now` (the page's own clock, in milliseconds) at the speed it has run at. */
|
|
378
|
+
#advance(now) {
|
|
379
|
+
if (this.speed === 1 && this.#mode === "now")
|
|
380
|
+
this.#model.time = Date.now();
|
|
381
|
+
else
|
|
382
|
+
this.#model.time += (now - this.#last) * this.speed;
|
|
383
|
+
this.#last = now;
|
|
384
|
+
}
|
|
385
|
+
/** The wait before the next step: real time every `live-seconds` (a minute by default); faster time as often as the Sun's turn moves a pixel, 1 to 30 times a second (once a second for a reader who prefers reduced motion). */
|
|
386
|
+
#wait() {
|
|
387
|
+
const seconds = Number(this.getAttribute("live-seconds"));
|
|
388
|
+
const live = Number.isFinite(seconds) && seconds > 0 ? Math.max(MIN_TICK_MS, seconds * 1000) : LIVE_TICK_MS;
|
|
389
|
+
const speed = Math.abs(this.speed);
|
|
390
|
+
if (speed <= 1)
|
|
391
|
+
return live;
|
|
392
|
+
if (typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches)
|
|
393
|
+
return Math.min(live, 1000);
|
|
394
|
+
const radius = this.#model.drawn?.radius ?? 200;
|
|
395
|
+
return Math.min(live, 1000 / Math.min(30, Math.max(1, SUN_RATE * RAD * speed * radius)));
|
|
396
|
+
}
|
|
397
|
+
/** Tell the page the moment shown: at most four times a second while time runs (`running`, and not from a hidden tab), and once, at once, when it holds. */
|
|
398
|
+
#announce(running) {
|
|
399
|
+
const now = performance.now();
|
|
400
|
+
if (running && (now - this.#announced < TIME_EVENT_MS || document.visibilityState === "hidden"))
|
|
401
|
+
return;
|
|
402
|
+
this.#announced = running ? now : -Infinity;
|
|
403
|
+
this.dispatchEvent(new CustomEvent("chikyu-timechange", { detail: { time: this.#model.time, running } }));
|
|
404
|
+
}
|
|
405
|
+
/** While the clock runs the Sun and the clouds are put right at the pace `#wait` gives, and nothing runs at all while it holds. */
|
|
306
406
|
#startTick() {
|
|
307
|
-
|
|
407
|
+
clearTimeout(this.#tick);
|
|
308
408
|
this.#tick = undefined;
|
|
309
|
-
|
|
409
|
+
const go = this.isConnected && this.speed !== 0;
|
|
410
|
+
// the clock was running and now holds: told once, so a page's date box stops following it
|
|
411
|
+
if (this.#running && !go) {
|
|
412
|
+
this.#running = false;
|
|
413
|
+
this.#announce(false);
|
|
414
|
+
}
|
|
415
|
+
if (!go)
|
|
310
416
|
return;
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
this.#tick = setInterval(this.#onTick, ms);
|
|
417
|
+
this.#running = true;
|
|
418
|
+
this.#tick = setTimeout(this.#onTick, this.#wait());
|
|
314
419
|
}
|
|
315
420
|
#onTick = () => {
|
|
316
|
-
this.#
|
|
421
|
+
this.#advance(performance.now());
|
|
422
|
+
this.#tick = setTimeout(this.#onTick, this.#wait());
|
|
423
|
+
this.#gate?.soon();
|
|
424
|
+
this.#announce(true);
|
|
425
|
+
};
|
|
426
|
+
/** Back in a shown tab: the moment is brought up to date, and drawn. */
|
|
427
|
+
#onVisible = () => {
|
|
428
|
+
if (document.visibilityState === "hidden" || !this.#running)
|
|
429
|
+
return;
|
|
430
|
+
this.#advance(performance.now());
|
|
317
431
|
this.#gate?.soon();
|
|
432
|
+
this.#announce(true);
|
|
318
433
|
};
|
|
319
434
|
#take = () => {
|
|
320
435
|
if (this.#view && !this.#view.live)
|
package/dist/space/element.d.ts
CHANGED
|
@@ -120,13 +120,22 @@ type SatelliteStats = {
|
|
|
120
120
|
*
|
|
121
121
|
* It carries kazoku-ui's controls itself: a drag turns the view, two fingers pinch, Ctrl and the wheel zoom (a plain wheel at Fit scrolls the page) and the arrow keys, + and - work once it is focused. The zoom runs from a millionth of Fit (the whole solar system) to 2.5 times, and from 0.5 to 6 times while riding from a body. `controls="none"` turns the hands off; `zoom-min` and `zoom-max` change the range. A `<kazoku-view-controls for="...">` on the element takes the hands over, and the page applies its events with `setView`.
|
|
122
122
|
*
|
|
123
|
+
* While time runs (`speed` is not 0) it sends `chikyu-timechange` with `detail: { time, running: true }`, `time` being the moment shown in milliseconds since 1970, at most four times a second however fast the picture is
|
|
124
|
+
* drawn (and, with the clock at real time, as often as it steps: once a minute, or once a second with satellites or a ride on show), only while the tab is shown, and once with `running: false` when the clock holds
|
|
125
|
+
* (`speed` set to 0): a page writes the date into its date box from it. It is not sent for a `time` the page sets itself. `chikyu-time` is the older event of every step the clock takes (up to thirty a second):
|
|
126
|
+
* it is kept for pages that use it, but a page that shows the date wants `chikyu-timechange`.
|
|
127
|
+
*
|
|
123
128
|
* @example
|
|
124
129
|
* ```ts no-run
|
|
125
130
|
* import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
126
131
|
*
|
|
127
132
|
* const space = document.createElement("chikyu-space") as ChikyuSpace;
|
|
128
133
|
* space.setAttribute("time", "2026-11-02T12:00Z");
|
|
129
|
-
* space.setAttribute("speed", "
|
|
134
|
+
* space.setAttribute("speed", "86400");
|
|
135
|
+
* space.addEventListener("chikyu-timechange", (event) => {
|
|
136
|
+
* const { time, running } = (event as CustomEvent<{ time: number; running: boolean }>).detail;
|
|
137
|
+
* console.log(new Date(time).toISOString(), running ? "running" : "held");
|
|
138
|
+
* });
|
|
130
139
|
* document.body.append(space);
|
|
131
140
|
* ```
|
|
132
141
|
*/
|
package/dist/space/element.js
CHANGED
|
@@ -39,6 +39,8 @@ const EARTH_RATE = 360 / 86_164.0905;
|
|
|
39
39
|
const SATELLITE_RATE = 360 / (88 * 60);
|
|
40
40
|
const SATELLITE_COLORS = ["#ffd54f", "#7fd4ff", "#ff8fa3", "#9ef0a8"];
|
|
41
41
|
const REAL_TIME_TICK_MS = 60_000;
|
|
42
|
+
/** The least time between two `chikyu-timechange` events while time runs: a few a second at most, however fast the picture is drawn. */
|
|
43
|
+
const TIME_EVENT_MS = 250;
|
|
42
44
|
/**
|
|
43
45
|
* Tilt to the poles. The zoom is the camera's distance: a millionth of Fit takes in the whole solar system (the views of the planets and their distances need that much), and 2.5 times is as close as the Earth's 4096 pixel picture and the body textures stay sharp.
|
|
44
46
|
* Riding at a body looking at the Earth, the zoom only narrows the camera's field a little either way: 0.5 to 6.
|
|
@@ -65,13 +67,22 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
|
|
|
65
67
|
*
|
|
66
68
|
* It carries kazoku-ui's controls itself: a drag turns the view, two fingers pinch, Ctrl and the wheel zoom (a plain wheel at Fit scrolls the page) and the arrow keys, + and - work once it is focused. The zoom runs from a millionth of Fit (the whole solar system) to 2.5 times, and from 0.5 to 6 times while riding from a body. `controls="none"` turns the hands off; `zoom-min` and `zoom-max` change the range. A `<kazoku-view-controls for="...">` on the element takes the hands over, and the page applies its events with `setView`.
|
|
67
69
|
*
|
|
70
|
+
* While time runs (`speed` is not 0) it sends `chikyu-timechange` with `detail: { time, running: true }`, `time` being the moment shown in milliseconds since 1970, at most four times a second however fast the picture is
|
|
71
|
+
* drawn (and, with the clock at real time, as often as it steps: once a minute, or once a second with satellites or a ride on show), only while the tab is shown, and once with `running: false` when the clock holds
|
|
72
|
+
* (`speed` set to 0): a page writes the date into its date box from it. It is not sent for a `time` the page sets itself. `chikyu-time` is the older event of every step the clock takes (up to thirty a second):
|
|
73
|
+
* it is kept for pages that use it, but a page that shows the date wants `chikyu-timechange`.
|
|
74
|
+
*
|
|
68
75
|
* @example
|
|
69
76
|
* ```ts no-run
|
|
70
77
|
* import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
71
78
|
*
|
|
72
79
|
* const space = document.createElement("chikyu-space") as ChikyuSpace;
|
|
73
80
|
* space.setAttribute("time", "2026-11-02T12:00Z");
|
|
74
|
-
* space.setAttribute("speed", "
|
|
81
|
+
* space.setAttribute("speed", "86400");
|
|
82
|
+
* space.addEventListener("chikyu-timechange", (event) => {
|
|
83
|
+
* const { time, running } = (event as CustomEvent<{ time: number; running: boolean }>).detail;
|
|
84
|
+
* console.log(new Date(time).toISOString(), running ? "running" : "held");
|
|
85
|
+
* });
|
|
75
86
|
* document.body.append(space);
|
|
76
87
|
* ```
|
|
77
88
|
*/
|
|
@@ -88,6 +99,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
88
99
|
#state = "loading";
|
|
89
100
|
#timer;
|
|
90
101
|
#last = 0;
|
|
102
|
+
#announced = -Infinity;
|
|
91
103
|
#pool = new Map();
|
|
92
104
|
#places;
|
|
93
105
|
#chosenLabel;
|
|
@@ -223,12 +235,18 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
223
235
|
return this.#speed;
|
|
224
236
|
}
|
|
225
237
|
set speed(value) {
|
|
238
|
+
// time up to this moment is worked out at the old speed, so a hold keeps the moment the reader saw last
|
|
239
|
+
if (this.#speed !== 0 && this.isConnected)
|
|
240
|
+
this.#advance(performance.now());
|
|
241
|
+
const was = this.#speed;
|
|
226
242
|
this.#speed = Number.isFinite(value) ? value : 1;
|
|
227
243
|
this.#model.speed = this.#speed;
|
|
228
244
|
this.#model.stepMs = Math.max(1000, Math.abs(this.#speed) * 1000);
|
|
229
245
|
this.#last = performance.now();
|
|
230
246
|
this.#schedule();
|
|
231
247
|
this.#gate?.request();
|
|
248
|
+
if (this.#speed === 0 && was !== 0)
|
|
249
|
+
this.#announce(false);
|
|
232
250
|
}
|
|
233
251
|
get scale() {
|
|
234
252
|
return this.#model.mode;
|
|
@@ -545,16 +563,28 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
545
563
|
const wait = !satellites && !riding && this.#speed === 1 ? REAL_TIME_TICK_MS : 1000 / perSecond;
|
|
546
564
|
this.#timer = setTimeout(this.#tick, wait);
|
|
547
565
|
}
|
|
548
|
-
|
|
549
|
-
|
|
566
|
+
/** Bring the moment shown up to `now` (the page's own clock, in milliseconds) at the speed it has run at. */
|
|
567
|
+
#advance(now) {
|
|
550
568
|
if (this.#speed === 1 && this.#mode === "now")
|
|
551
569
|
this.#model.time = Date.now();
|
|
552
570
|
else
|
|
553
571
|
this.#model.time += (now - this.#last) * this.#speed;
|
|
554
572
|
this.#last = now;
|
|
573
|
+
}
|
|
574
|
+
/** Tell the page the moment shown: at most four times a second while time runs (`running`, and not from a hidden tab), and once, at once, when it holds. */
|
|
575
|
+
#announce(running) {
|
|
576
|
+
const now = performance.now();
|
|
577
|
+
if (running && (now - this.#announced < TIME_EVENT_MS || document.visibilityState === "hidden"))
|
|
578
|
+
return;
|
|
579
|
+
this.#announced = running ? now : -Infinity;
|
|
580
|
+
this.dispatchEvent(new CustomEvent("chikyu-timechange", { detail: { time: this.#model.time, running } }));
|
|
581
|
+
}
|
|
582
|
+
#tick = () => {
|
|
583
|
+
this.#advance(performance.now());
|
|
555
584
|
this.#gate?.request();
|
|
556
585
|
this.#schedule();
|
|
557
586
|
this.dispatchEvent(new CustomEvent("chikyu-time", { detail: { time: this.#model.time } }));
|
|
587
|
+
this.#announce(this.#speed !== 0);
|
|
558
588
|
};
|
|
559
589
|
// --- labels --------------------------------------------------------------------------------------------------------------------------------------
|
|
560
590
|
#placeLabels(places) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.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",
|