@johnmorrisdotca/chikyu-earth 0.22.1 → 0.24.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 +14 -0
- package/README.md +3 -2
- package/dist/realistic/earth.d.ts +2 -0
- package/dist/realistic/earth.js +1 -0
- package/dist/realistic/element.d.ts +34 -1
- package/dist/realistic/element.js +128 -12
- package/dist/realistic/gate.d.ts +7 -0
- package/dist/realistic/gate.js +11 -1
- 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,20 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.24.0 - 2026-11-10
|
|
6
|
+
|
|
7
|
+
- **The demo's views open moving** (MODULES-815). A link that says nothing about the clock (no `play`, no `speed`, no `time`) opens the space view and the realistic Earth running from now at an hour a second (`speed` 3600, the first step of the Time row where motion shows; real time looks frozen), with the date box running with it. They opened held (the space view) or following the real clock (the realistic Earth) before. Links that say something work as they say: `speed=0` and `play=off` hold, a date (`time`) is shown as it says and held until Play, a speed other than 0 with no `play` runs at it, and a reader's Pause, written to the address as `time`, stays held. A hold with no date to write (Back to a date that was "now" on the realistic Earth, Now pressed while held) is written as `play=off`. Changing look keeps the clock as the reader left it: a view that was running goes on running from the date reached, one that was paused stays paused. The line and thick globes already turn on their own when the page opens (the view controls' Auto-turn, at the Earth's own rate). **A reader who prefers reduced motion still gets a still view with Play off**: John has not decided whether that changes, and the one place to change is `OPEN_MOVING_WITH_REDUCED_MOTION` in `demo/demo.ts` (kazoku-ui's replay bar also turns Play off under reduced motion, so the change needs an option there first). Nothing is drawn while held, out of sight or in a hidden tab, and never more than 30 frames a second, as before. The package's elements are unchanged (`<chikyu-space>` still defaults to real time and `<chikyu-earth-realistic>` to following the real clock), and so is the embed page. Guide in English and Japanese: `docs/guides/time-and-play.md`. Tests: `e2e/date-play.demo.ts` (the space view and the globes) and `e2e/realistic-play.demo.ts`; "nothing at all opens held" became "opens moving".
|
|
8
|
+
|
|
9
|
+
## 0.23.0 - 2026-11-10
|
|
10
|
+
|
|
11
|
+
- **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.
|
|
12
|
+
- **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`.
|
|
13
|
+
|
|
14
|
+
- **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`.
|
|
15
|
+
- **A flaky test mended, and one empty draw removed** (MODULES-808). `e2e/tiles.gl.ts` "tiles that arrive one after another are a few draws" failed in CI with 7 draws against a limit under 7 (4 tiles, and the limit was the tiles requested plus 3). Measured frame by frame, with the tiles answered after different waits (the slow route that reproduces it: 7 or 8 draws in 4 runs of 10): the element draws at most once in a frame, never faster than 30 a second, and a tile that arrives in its own frame is one draw. The test was wrong in two ways. It counted from before the zoom, and the same zoom also swaps the package's own pictures for sharper ones (day, night, clouds and water, a draw each, up to four, within the first 100 ms and before any tile has arrived), which are draws the tiles did not ask for; and "requested plus 3" is a fixed number for a count that depends on how the arrivals fall across frames. It now checks the rule itself, for tiles answered at once, one after another and in clumps, watching the page's frames: at most one draw in any frame, no more draws than the frames that had something new to show (a tile arrived, or a sharper picture was swapped in) plus the zoom's own draw, and at most 30 a second. A second CI run of the new test showed the rule was not yet exact: 6 draws against 4 frames with news plus 1. The extra was a draw with nothing new in it. When a second tile arrived a few milliseconds after the first and before the draw the first had asked for, the draw gate set a timer and drew again 33 ms later, after the first draw had already shown both tiles. `Gate` has a new `drawn()`, which `<chikyu-earth-realistic>` calls at the start of every draw; from then on an ask made after a run and before its draw begins is dropped, since that draw reads the state as it is when it runs, so what arrives in one frame is one draw. A draw that never begins no longer holds asks back for more than the gap. The space view's gate is unchanged. Tests: `test/realistic.test.ts` and, with the frames listed in its failure message, `e2e/tiles.gl.ts`. The other tests that count draws (`e2e/realistic.gl.ts`, `e2e/freeze.demo.ts`, `e2e/markers.gl.ts`) count rest, bursts of asks in one task or a rate over a fixed time, none of them by how arrivals fall.
|
|
16
|
+
- **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.
|
|
17
|
+
- **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.
|
|
18
|
+
|
|
5
19
|
## 0.22.1 - 2026-11-09
|
|
6
20
|
|
|
7
21
|
- 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 |
|
|
@@ -69,6 +69,8 @@ export interface EarthDeps {
|
|
|
69
69
|
invalidate: () => void;
|
|
70
70
|
onError?: (error: unknown) => void;
|
|
71
71
|
onTier?: (layer: Layer, width: number) => void;
|
|
72
|
+
/** Told at the start of every draw, before anything is read for it. */
|
|
73
|
+
onDraw?: () => void;
|
|
72
74
|
/** Told at every draw where the disc is, for what is laid over it (markers). */
|
|
73
75
|
onPose?: (pose: {
|
|
74
76
|
lon: number;
|
package/dist/realistic/earth.js
CHANGED
|
@@ -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"));
|
|
@@ -132,6 +177,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
132
177
|
},
|
|
133
178
|
drift: 1.5,
|
|
134
179
|
invalidate: () => this.#gate?.soon(),
|
|
180
|
+
onDraw: () => this.#gate?.drawn(),
|
|
135
181
|
onPose: (pose) => {
|
|
136
182
|
if (this.#hands)
|
|
137
183
|
this.#hands.controller.grabRadius = discRadius(pose.width, pose.height, 1);
|
|
@@ -160,6 +206,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
160
206
|
this.addEventListener("focusin", this.#take);
|
|
161
207
|
this.#hands = carryControls(this, { initial: this.#model.view, limits: LIMITS, onChange: (state, info) => this.setView(state, info.final) });
|
|
162
208
|
this.#startTick();
|
|
209
|
+
document.addEventListener("visibilitychange", this.#onVisible);
|
|
163
210
|
this.#locate();
|
|
164
211
|
}
|
|
165
212
|
disconnectedCallback() {
|
|
@@ -170,8 +217,10 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
170
217
|
if (this.#reach !== null && this.getAttribute("zoom-max") === this.#reach)
|
|
171
218
|
this.removeAttribute("zoom-max");
|
|
172
219
|
this.#reach = null;
|
|
173
|
-
|
|
220
|
+
clearTimeout(this.#tick);
|
|
174
221
|
this.#tick = undefined;
|
|
222
|
+
this.#running = false;
|
|
223
|
+
document.removeEventListener("visibilitychange", this.#onVisible);
|
|
175
224
|
this.#gate?.cancel();
|
|
176
225
|
this.#view?.dispose();
|
|
177
226
|
this.#view = undefined;
|
|
@@ -183,6 +232,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
183
232
|
this.centre = readCentre(value) ?? { lon: 0, lat: 0 };
|
|
184
233
|
else if (name === "time")
|
|
185
234
|
this.time = readTime(value);
|
|
235
|
+
else if (name === "speed")
|
|
236
|
+
this.#setSpeed(readSpeed(value));
|
|
186
237
|
else if (name === "clouds")
|
|
187
238
|
this.clouds = value !== "off";
|
|
188
239
|
else if (name === "lights")
|
|
@@ -232,9 +283,9 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
232
283
|
this.#model.centre = { ...value };
|
|
233
284
|
this.#gate?.soon();
|
|
234
285
|
}
|
|
235
|
-
/** The moment shown: milliseconds since the epoch, or "now"
|
|
286
|
+
/** 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
287
|
get time() {
|
|
237
|
-
return this.#mode;
|
|
288
|
+
return this.#mode === "now" && this.speed === 1 ? "now" : this.#model.time;
|
|
238
289
|
}
|
|
239
290
|
set time(value) {
|
|
240
291
|
this.#mode = value instanceof Date ? value.getTime() : value;
|
|
@@ -242,6 +293,28 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
242
293
|
this.#model.time = Date.now();
|
|
243
294
|
else
|
|
244
295
|
this.#model.time = this.#mode;
|
|
296
|
+
this.#last = performance.now();
|
|
297
|
+
this.#startTick();
|
|
298
|
+
this.#gate?.soon();
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* 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
|
|
302
|
+
* 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.
|
|
303
|
+
*/
|
|
304
|
+
get speed() {
|
|
305
|
+
return this.#speed ?? (this.#mode === "now" ? 1 : 0);
|
|
306
|
+
}
|
|
307
|
+
set speed(value) {
|
|
308
|
+
if (Number.isFinite(value))
|
|
309
|
+
this.setAttribute("speed", String(value));
|
|
310
|
+
else
|
|
311
|
+
this.removeAttribute("speed");
|
|
312
|
+
}
|
|
313
|
+
#setSpeed(next) {
|
|
314
|
+
if (this.isConnected && this.speed !== 0)
|
|
315
|
+
this.#advance(performance.now());
|
|
316
|
+
this.#speed = next;
|
|
317
|
+
this.#last = performance.now();
|
|
245
318
|
this.#startTick();
|
|
246
319
|
this.#gate?.soon();
|
|
247
320
|
}
|
|
@@ -302,19 +375,62 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
302
375
|
get view() {
|
|
303
376
|
return { ...this.#model.view };
|
|
304
377
|
}
|
|
305
|
-
/**
|
|
378
|
+
/** Bring the moment shown up to `now` (the page's own clock, in milliseconds) at the speed it has run at. */
|
|
379
|
+
#advance(now) {
|
|
380
|
+
if (this.speed === 1 && this.#mode === "now")
|
|
381
|
+
this.#model.time = Date.now();
|
|
382
|
+
else
|
|
383
|
+
this.#model.time += (now - this.#last) * this.speed;
|
|
384
|
+
this.#last = now;
|
|
385
|
+
}
|
|
386
|
+
/** 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). */
|
|
387
|
+
#wait() {
|
|
388
|
+
const seconds = Number(this.getAttribute("live-seconds"));
|
|
389
|
+
const live = Number.isFinite(seconds) && seconds > 0 ? Math.max(MIN_TICK_MS, seconds * 1000) : LIVE_TICK_MS;
|
|
390
|
+
const speed = Math.abs(this.speed);
|
|
391
|
+
if (speed <= 1)
|
|
392
|
+
return live;
|
|
393
|
+
if (typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches)
|
|
394
|
+
return Math.min(live, 1000);
|
|
395
|
+
const radius = this.#model.drawn?.radius ?? 200;
|
|
396
|
+
return Math.min(live, 1000 / Math.min(30, Math.max(1, SUN_RATE * RAD * speed * radius)));
|
|
397
|
+
}
|
|
398
|
+
/** 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. */
|
|
399
|
+
#announce(running) {
|
|
400
|
+
const now = performance.now();
|
|
401
|
+
if (running && (now - this.#announced < TIME_EVENT_MS || document.visibilityState === "hidden"))
|
|
402
|
+
return;
|
|
403
|
+
this.#announced = running ? now : -Infinity;
|
|
404
|
+
this.dispatchEvent(new CustomEvent("chikyu-timechange", { detail: { time: this.#model.time, running } }));
|
|
405
|
+
}
|
|
406
|
+
/** 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
407
|
#startTick() {
|
|
307
|
-
|
|
408
|
+
clearTimeout(this.#tick);
|
|
308
409
|
this.#tick = undefined;
|
|
309
|
-
|
|
410
|
+
const go = this.isConnected && this.speed !== 0;
|
|
411
|
+
// the clock was running and now holds: told once, so a page's date box stops following it
|
|
412
|
+
if (this.#running && !go) {
|
|
413
|
+
this.#running = false;
|
|
414
|
+
this.#announce(false);
|
|
415
|
+
}
|
|
416
|
+
if (!go)
|
|
310
417
|
return;
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
this.#tick = setInterval(this.#onTick, ms);
|
|
418
|
+
this.#running = true;
|
|
419
|
+
this.#tick = setTimeout(this.#onTick, this.#wait());
|
|
314
420
|
}
|
|
315
421
|
#onTick = () => {
|
|
316
|
-
this.#
|
|
422
|
+
this.#advance(performance.now());
|
|
423
|
+
this.#tick = setTimeout(this.#onTick, this.#wait());
|
|
424
|
+
this.#gate?.soon();
|
|
425
|
+
this.#announce(true);
|
|
426
|
+
};
|
|
427
|
+
/** Back in a shown tab: the moment is brought up to date, and drawn. */
|
|
428
|
+
#onVisible = () => {
|
|
429
|
+
if (document.visibilityState === "hidden" || !this.#running)
|
|
430
|
+
return;
|
|
431
|
+
this.#advance(performance.now());
|
|
317
432
|
this.#gate?.soon();
|
|
433
|
+
this.#announce(true);
|
|
318
434
|
};
|
|
319
435
|
#take = () => {
|
|
320
436
|
if (this.#view && !this.#view.live)
|
package/dist/realistic/gate.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare const browserTimers: Timers;
|
|
|
13
13
|
*
|
|
14
14
|
* const gate: Gate = createGate(33, () => console.log("draw"));
|
|
15
15
|
* gate.request();
|
|
16
|
+
* gate.drawn();
|
|
16
17
|
* gate.cancel();
|
|
17
18
|
* ```
|
|
18
19
|
*/
|
|
@@ -25,6 +26,12 @@ export interface Gate {
|
|
|
25
26
|
cancel(): void;
|
|
26
27
|
/** Change the least time between runs (a lower frame rate on a battery). */
|
|
27
28
|
setMinMs(minMs: number): void;
|
|
29
|
+
/**
|
|
30
|
+
* Tell the gate a draw has begun (call it first thing in the draw). From the first call, an ask made after a run and before the draw it asked for is dropped, since that draw reads the state as it is
|
|
31
|
+
* when it runs and so shows the change too: two tiles that arrive a few milliseconds apart are one draw, not a draw and a second, empty one 33 ms later. A draw that does not come within `minMs`
|
|
32
|
+
* (a hidden tab, a busy machine) no longer holds asks back.
|
|
33
|
+
*/
|
|
34
|
+
drawn(): void;
|
|
28
35
|
}
|
|
29
36
|
/**
|
|
30
37
|
* A rate gate for the draw: asks that come faster than `minMs` apart become one, and the last ask is never lost, so a burst of changes costs one draw.
|
package/dist/realistic/gate.js
CHANGED
|
@@ -28,15 +28,21 @@ export function createGate(minMs, fire, timers = browserTimers) {
|
|
|
28
28
|
let last = -Infinity;
|
|
29
29
|
let waiting;
|
|
30
30
|
let soon = false;
|
|
31
|
+
let tracking = false;
|
|
32
|
+
let undrawn = false;
|
|
31
33
|
const run = () => {
|
|
32
34
|
waiting = undefined;
|
|
33
35
|
last = timers.now();
|
|
36
|
+
undrawn = true;
|
|
34
37
|
fire();
|
|
35
38
|
};
|
|
36
39
|
const request = () => {
|
|
37
40
|
if (waiting !== undefined)
|
|
38
41
|
return;
|
|
39
|
-
const
|
|
42
|
+
const now = timers.now();
|
|
43
|
+
if (tracking && undrawn && now - last < least)
|
|
44
|
+
return;
|
|
45
|
+
const wait = last + least - now;
|
|
40
46
|
if (wait <= 0)
|
|
41
47
|
run();
|
|
42
48
|
else
|
|
@@ -61,6 +67,10 @@ export function createGate(minMs, fire, timers = browserTimers) {
|
|
|
61
67
|
setMinMs(value) {
|
|
62
68
|
least = value;
|
|
63
69
|
},
|
|
70
|
+
drawn() {
|
|
71
|
+
tracking = true;
|
|
72
|
+
undrawn = false;
|
|
73
|
+
},
|
|
64
74
|
};
|
|
65
75
|
}
|
|
66
76
|
/**
|
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.24.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",
|