@johnmorrisdotca/chikyu-earth 0.46.6 → 0.47.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 -3
- package/dist/beam/layer.d.ts +1 -1
- package/dist/markers/place-layer.d.ts +4 -0
- package/dist/markers/place-layer.js +20 -6
- package/dist/place/index.d.ts +230 -0
- package/dist/place/index.js +183 -0
- package/dist/place/land.d.ts +30 -0
- package/dist/place/land.js +177 -0
- package/dist/place/water.d.ts +15 -0
- package/dist/place/water.js +63 -0
- package/dist/realistic/earth.d.ts +9 -1
- package/dist/realistic/earth.js +13 -0
- package/dist/realistic/element-base.d.ts +21 -0
- package/dist/realistic/element-base.js +58 -3
- package/dist/space/element-base.d.ts +97 -2
- package/dist/space/element-base.js +280 -8
- package/dist/space/ephemeris.d.ts +1 -1
- package/dist/space/ephemeris.js +4 -2
- package/dist/space/follow.d.ts +36 -0
- package/dist/space/follow.js +46 -0
- package/dist/space/index.d.ts +1 -1
- package/dist/space/index.js +1 -0
- package/dist/space/ride.d.ts +3 -2
- package/dist/space/ride.js +6 -4
- package/dist/space/satellite-hover.d.ts +47 -0
- package/dist/space/satellite-hover.js +183 -0
- package/dist/space/satellite-layer.d.ts +56 -1
- package/dist/space/satellite-layer.js +93 -31
- package/dist/space/satellite-model.d.ts +2 -1
- package/dist/space/satellite-model.js +4 -3
- package/dist/space/scene.d.ts +38 -0
- package/dist/space/scene.js +77 -12
- package/package.json +6 -1
package/dist/space/ephemeris.js
CHANGED
|
@@ -66,7 +66,7 @@ export function frameAt(ms) {
|
|
|
66
66
|
}
|
|
67
67
|
const lerp3 = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
|
|
68
68
|
/**
|
|
69
|
-
* A frame between two others, `t` from 0 to 1. The spin
|
|
69
|
+
* A frame between two others, `t` from 0 to 1. The spin advances by how far the Earth turns in that time, so a step of a second takes the short way and a step of a day is a full turn.
|
|
70
70
|
*
|
|
71
71
|
* @param a - The earlier frame.
|
|
72
72
|
* @param b - The later frame.
|
|
@@ -87,7 +87,9 @@ export function blend(a, b, t) {
|
|
|
87
87
|
for (const name of PLANETS)
|
|
88
88
|
planets[name] = lerp3(a.planets[name], b.planets[name], t);
|
|
89
89
|
let turn = b.spin - a.spin;
|
|
90
|
-
|
|
90
|
+
// The samples are wrapped to a circle. Pick the turn that matches how far the Earth really turns in the time between them, so a step of a day is a full turn and a step of a second is the short way.
|
|
91
|
+
const expected = ((b.ms - a.ms) / 86_164_090.5) * 360;
|
|
92
|
+
turn += 360 * Math.round((expected - turn) / 360);
|
|
91
93
|
return { ms: a.ms + (b.ms - a.ms) * t, sun: lerp3(a.sun, b.sun, t), moon: lerp3(a.moon, b.moon, t), planets, spin: a.spin + turn * t };
|
|
92
94
|
}
|
|
93
95
|
/**
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Keep a share between 0 and 1. Anything that is not a number is 0. */
|
|
2
|
+
export declare const clampFollow: (value: number) => number;
|
|
3
|
+
/**
|
|
4
|
+
* The sidereal angle the camera uses, in degrees. `anchor` is the Earth's turn when the camera was set, `spin` is the turn now.
|
|
5
|
+
*
|
|
6
|
+
* @param anchor - The Earth's turn, in degrees, remembered for the space camera.
|
|
7
|
+
* @param spin - The Earth's turn now, in degrees.
|
|
8
|
+
* @param follow - 0 holds the stars, 1 turns with the Earth.
|
|
9
|
+
* @returns The angle added to the place the camera looks at.
|
|
10
|
+
*/
|
|
11
|
+
export declare const followSpin: (anchor: number, spin: number, follow: number) => number;
|
|
12
|
+
/**
|
|
13
|
+
* The longitude, in degrees, under the middle of the view. The same place before and after a change of `follow`.
|
|
14
|
+
*
|
|
15
|
+
* @param anchor - The Earth's turn remembered for the camera.
|
|
16
|
+
* @param spin - The Earth's turn now.
|
|
17
|
+
* @param follow - The share of that turn the camera takes.
|
|
18
|
+
* @param centreLon - The home longitude.
|
|
19
|
+
* @param yaw - The view's yaw, in degrees.
|
|
20
|
+
* @returns Longitude under the middle, in degrees.
|
|
21
|
+
*/
|
|
22
|
+
export declare const groundLongitude: (anchor: number, spin: number, follow: number, centreLon: number, yaw: number) => number;
|
|
23
|
+
/**
|
|
24
|
+
* Move the camera's anchor, and the yaw when the share becomes 1, so the longitude under the middle stays put.
|
|
25
|
+
*
|
|
26
|
+
* @param anchor - The anchor before the change.
|
|
27
|
+
* @param spin - The Earth's turn now.
|
|
28
|
+
* @param from - The share before the change.
|
|
29
|
+
* @param to - The share after the change.
|
|
30
|
+
* @param yaw - The view's yaw before the change.
|
|
31
|
+
* @returns The anchor and yaw to use with `to`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function retargetFollow(anchor: number, spin: number, from: number, to: number, yaw: number): {
|
|
34
|
+
anchor: number;
|
|
35
|
+
yaw: number;
|
|
36
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// How much of the Earth's turn the space camera takes. 0 holds the stars (the camera stays where it was set). 1 turns with the Earth.
|
|
2
|
+
// A change keeps the longitude under the middle of the view: the anchor (or, at 1, the yaw) is moved so the aim does not jump.
|
|
3
|
+
/** Keep a share between 0 and 1. Anything that is not a number is 0. */
|
|
4
|
+
export const clampFollow = (value) => (Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : 0);
|
|
5
|
+
/**
|
|
6
|
+
* The sidereal angle the camera uses, in degrees. `anchor` is the Earth's turn when the camera was set, `spin` is the turn now.
|
|
7
|
+
*
|
|
8
|
+
* @param anchor - The Earth's turn, in degrees, remembered for the space camera.
|
|
9
|
+
* @param spin - The Earth's turn now, in degrees.
|
|
10
|
+
* @param follow - 0 holds the stars, 1 turns with the Earth.
|
|
11
|
+
* @returns The angle added to the place the camera looks at.
|
|
12
|
+
*/
|
|
13
|
+
export const followSpin = (anchor, spin, follow) => {
|
|
14
|
+
const share = clampFollow(follow);
|
|
15
|
+
return anchor + share * (spin - anchor);
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The longitude, in degrees, under the middle of the view. The same place before and after a change of `follow`.
|
|
19
|
+
*
|
|
20
|
+
* @param anchor - The Earth's turn remembered for the camera.
|
|
21
|
+
* @param spin - The Earth's turn now.
|
|
22
|
+
* @param follow - The share of that turn the camera takes.
|
|
23
|
+
* @param centreLon - The home longitude.
|
|
24
|
+
* @param yaw - The view's yaw, in degrees.
|
|
25
|
+
* @returns Longitude under the middle, in degrees.
|
|
26
|
+
*/
|
|
27
|
+
export const groundLongitude = (anchor, spin, follow, centreLon, yaw) => followSpin(anchor, spin, follow) + centreLon - yaw - spin;
|
|
28
|
+
const wrap = (deg) => ((((deg + 180) % 360) + 360) % 360) - 180;
|
|
29
|
+
/**
|
|
30
|
+
* Move the camera's anchor, and the yaw when the share becomes 1, so the longitude under the middle stays put.
|
|
31
|
+
*
|
|
32
|
+
* @param anchor - The anchor before the change.
|
|
33
|
+
* @param spin - The Earth's turn now.
|
|
34
|
+
* @param from - The share before the change.
|
|
35
|
+
* @param to - The share after the change.
|
|
36
|
+
* @param yaw - The view's yaw before the change.
|
|
37
|
+
* @returns The anchor and yaw to use with `to`.
|
|
38
|
+
*/
|
|
39
|
+
export function retargetFollow(anchor, spin, from, to, yaw) {
|
|
40
|
+
const next = clampFollow(to);
|
|
41
|
+
const oldSpin = followSpin(anchor, spin, from);
|
|
42
|
+
if (next >= 1)
|
|
43
|
+
return { anchor: spin, yaw: wrap(yaw + (spin - oldSpin)) };
|
|
44
|
+
const nextAnchor = (oldSpin - next * spin) / (1 - next);
|
|
45
|
+
return { anchor: nextAnchor, yaw };
|
|
46
|
+
}
|
package/dist/space/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitP
|
|
|
2
2
|
export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
|
|
3
3
|
export { fitDistance, plainPainter, type BodyDrawing, type BodyMoon, type BodyPainter, type BodyView, type PaintContext, type SatellitePainter } from "./scene.ts";
|
|
4
4
|
export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideFace, type RideInput, type RideLook, type RidePose, type RideModelSize, type RideViewpoint } from "./ride.ts";
|
|
5
|
-
export type
|
|
5
|
+
export { earthHides, type SatelliteScreen } from "./satellite-layer.ts";
|
|
6
6
|
export { ABOVE_MODEL_KM, ABOVE_MODEL_SHARE, aboveAxes, aboveModelShare, MODEL_FADE_FROM_KM, MODEL_FADE_TO_KM, MODEL_HANDOVER_PX, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
|
|
7
7
|
export { genericSatellite, satelliteKind, type SatelliteKind } from "./generic-satellite.ts";
|
|
8
8
|
export { BEAM_ATTRIBUTES, BEAM_COLOUR, BEAM_ELEVATION, beamCells, footprintAngle, footprintKm, readBeam, type BeamCells, type BeamOptions } from "../beam/geometry.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitP
|
|
|
4
4
|
export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition } from "./scale.js";
|
|
5
5
|
export { fitDistance, plainPainter } from "./scene.js";
|
|
6
6
|
export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
|
|
7
|
+
export { earthHides } from "./satellite-layer.js";
|
|
7
8
|
export { ABOVE_MODEL_KM, ABOVE_MODEL_SHARE, aboveAxes, aboveModelShare, MODEL_FADE_FROM_KM, MODEL_FADE_TO_KM, MODEL_HANDOVER_PX, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
|
|
8
9
|
export { genericSatellite, satelliteKind } from "./generic-satellite.js";
|
|
9
10
|
export { BEAM_ATTRIBUTES, BEAM_COLOUR, BEAM_ELEVATION, beamCells, footprintAngle, footprintKm, readBeam } from "../beam/geometry.js";
|
package/dist/space/ride.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ export declare function faceOffset(face: RideFace): {
|
|
|
64
64
|
tilt: number;
|
|
65
65
|
};
|
|
66
66
|
/**
|
|
67
|
-
* The field of view, in degrees, of a riding camera at a zoom: the natural 60 divided by the zoom, held between 5 and 100.
|
|
67
|
+
* The field of view, in degrees, of a riding camera at a zoom: the natural 60 divided by the zoom, held between 1.5 and 100 (a zoom of 40, the most a ride takes, is 1.5 degrees).
|
|
68
68
|
*
|
|
69
69
|
* @param zoom - The shared controls' zoom.
|
|
70
70
|
* @returns The field of view in degrees.
|
|
@@ -203,6 +203,7 @@ export declare const OUTSIDE_KM = 25;
|
|
|
203
203
|
*
|
|
204
204
|
* @param pose - The pose from `ridePose` for the camera at the satellite.
|
|
205
205
|
* @param look - The look the pose was made with.
|
|
206
|
+
* @param low - How far below the middle of the picture the satellite is, as a share of half its height (0 the middle, 1 the bottom edge); by default 0.8 looking along and 0 looking down.
|
|
206
207
|
* @returns The pose moved back from the satellite, with how far the camera is from it in Earth radii and how many degrees below the middle of the picture the satellite is.
|
|
207
208
|
*
|
|
208
209
|
* @example
|
|
@@ -214,7 +215,7 @@ export declare const OUTSIDE_KM = 25;
|
|
|
214
215
|
* console.log(out.distance.toFixed(4), out.below.toFixed(1), out.pose.position.map((n) => n.toFixed(4)).join(","));
|
|
215
216
|
* ```
|
|
216
217
|
*/
|
|
217
|
-
export declare function outsidePose(pose: RidePose, look: RideLook): {
|
|
218
|
+
export declare function outsidePose(pose: RidePose, look: RideLook, low?: number): {
|
|
218
219
|
pose: RidePose;
|
|
219
220
|
distance: number;
|
|
220
221
|
below: number;
|
package/dist/space/ride.js
CHANGED
|
@@ -54,7 +54,7 @@ export function faceOffset(face) {
|
|
|
54
54
|
return { yaw: 0, tilt: 0 };
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
|
-
* The field of view, in degrees, of a riding camera at a zoom: the natural 60 divided by the zoom, held between 5 and 100.
|
|
57
|
+
* The field of view, in degrees, of a riding camera at a zoom: the natural 60 divided by the zoom, held between 1.5 and 100 (a zoom of 40, the most a ride takes, is 1.5 degrees).
|
|
58
58
|
*
|
|
59
59
|
* @param zoom - The shared controls' zoom.
|
|
60
60
|
* @returns The field of view in degrees.
|
|
@@ -67,7 +67,7 @@ export function faceOffset(face) {
|
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
69
|
export function rideFov(zoom) {
|
|
70
|
-
return Math.min(100, Math.max(5, RIDE_FOV / Math.max(0.05, zoom)));
|
|
70
|
+
return Math.min(100, Math.max(1.5, RIDE_FOV / Math.max(0.05, zoom)));
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* How many degrees the camera turns for a change of the controls' yaw at a zoom. The controls wrap their yaw into -180 to 180, so a page adds up the turns itself, change by change (`wrapYaw` of the change, scaled by this at the zoom of the moment), and hands
|
|
@@ -140,6 +140,7 @@ const OUTSIDE_LOW = 0.8;
|
|
|
140
140
|
*
|
|
141
141
|
* @param pose - The pose from `ridePose` for the camera at the satellite.
|
|
142
142
|
* @param look - The look the pose was made with.
|
|
143
|
+
* @param low - How far below the middle of the picture the satellite is, as a share of half its height (0 the middle, 1 the bottom edge); by default 0.8 looking along and 0 looking down.
|
|
143
144
|
* @returns The pose moved back from the satellite, with how far the camera is from it in Earth radii and how many degrees below the middle of the picture the satellite is.
|
|
144
145
|
*
|
|
145
146
|
* @example
|
|
@@ -151,10 +152,11 @@ const OUTSIDE_LOW = 0.8;
|
|
|
151
152
|
* console.log(out.distance.toFixed(4), out.below.toFixed(1), out.pose.position.map((n) => n.toFixed(4)).join(","));
|
|
152
153
|
* ```
|
|
153
154
|
*/
|
|
154
|
-
export function outsidePose(pose, look) {
|
|
155
|
+
export function outsidePose(pose, look, low) {
|
|
155
156
|
const height = Math.max(0, norm(pose.position) - 1);
|
|
156
157
|
const distance = Math.max(1e-5, Math.min(OUTSIDE_KM / 6371, height * 0.5));
|
|
157
|
-
const
|
|
158
|
+
const lowNow = low ?? (look === "horizon" ? OUTSIDE_LOW : 0);
|
|
159
|
+
const below = Math.atan(Math.max(0, lowNow) * Math.tan((pose.fov / 2) * RAD));
|
|
158
160
|
// the satellite is along the line of sight turned `below` down (towards the bottom of the picture): the camera is back along that line
|
|
159
161
|
const line = add(scale(pose.forward, Math.cos(below)), scale(pose.up, -Math.sin(below)));
|
|
160
162
|
return { pose: { ...pose, position: add(pose.position, scale(line, -distance)) }, distance, below: below / RAD };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { SatelliteRef } from "../satellites/types.ts";
|
|
2
|
+
import { type SatelliteState } from "./satellite-layer.ts";
|
|
3
|
+
/** The faint orbit is on unless `hover-path` is `off`. Left unset, it follows `names-on-hover` (itself on unless `off`). */
|
|
4
|
+
export declare const hoverPathOn: (path: string | null, names: string | null) => boolean;
|
|
5
|
+
/** A name is shown when the pointer rests on a satellite, unless `names-on-hover` is `off`. */
|
|
6
|
+
export declare const namesOnHover: (value: string | null) => boolean;
|
|
7
|
+
export interface HoverPlace {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
visible: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** What the element hands the hover: the satellite state, how to find a satellite, and where to put its name. */
|
|
13
|
+
export interface SatelliteHoverHost {
|
|
14
|
+
element: HTMLElement;
|
|
15
|
+
state: SatelliteState;
|
|
16
|
+
pick(x: number, y: number): SatelliteRef | null;
|
|
17
|
+
place(ref: SatelliteRef): HoverPlace | null;
|
|
18
|
+
name(ref: SatelliteRef): string | undefined;
|
|
19
|
+
selected(): SatelliteRef | null;
|
|
20
|
+
request(): void;
|
|
21
|
+
labelParent(): HTMLElement | null;
|
|
22
|
+
pathOn(): boolean;
|
|
23
|
+
namesOn(): boolean;
|
|
24
|
+
style(): {
|
|
25
|
+
color: string;
|
|
26
|
+
opacity: number;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface SatelliteHover {
|
|
30
|
+
/** Read the attributes again (they changed, or the element just connected). */
|
|
31
|
+
sync(): void;
|
|
32
|
+
/** Move the name to where the last draw put the satellite. Does not ask for a draw. */
|
|
33
|
+
follow(place: HoverPlace | null): void;
|
|
34
|
+
stop(): void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Show a satellite's name, and ask for its faint orbit, while a mouse rests on it. One at a time. Leaving fades both; reduced motion takes them away at once.
|
|
38
|
+
* Nothing is asked of the picture while the pointer is still.
|
|
39
|
+
*/
|
|
40
|
+
export declare function bindSatelliteHover(host: SatelliteHoverHost): SatelliteHover;
|
|
41
|
+
/** A blank custom property is the default. `Number("")` is 0, which would hide the orbit. */
|
|
42
|
+
export declare const hoverOpacityOf: (text: string) => number;
|
|
43
|
+
/** Colour and opacity from the element's own custom properties, or the faint orbit's own. */
|
|
44
|
+
export declare function hoverStyleOf(element: HTMLElement): {
|
|
45
|
+
color: string;
|
|
46
|
+
opacity: number;
|
|
47
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { prefersLessMotion } from "../meteors/note.js";
|
|
2
|
+
import { fadeLeft, HOVER_PATH_OPACITY } from "./satellite-layer.js";
|
|
3
|
+
/** The faint orbit is on unless `hover-path` is `off`. Left unset, it follows `names-on-hover` (itself on unless `off`). */
|
|
4
|
+
export const hoverPathOn = (path, names) => (path === "off" ? false : path !== null ? true : names !== "off");
|
|
5
|
+
/** A name is shown when the pointer rests on a satellite, unless `names-on-hover` is `off`. */
|
|
6
|
+
export const namesOnHover = (value) => value !== "off";
|
|
7
|
+
const same = (a, b) => a !== null && b !== null && a.group === b.group && a.index === b.index;
|
|
8
|
+
/**
|
|
9
|
+
* Show a satellite's name, and ask for its faint orbit, while a mouse rests on it. One at a time. Leaving fades both; reduced motion takes them away at once.
|
|
10
|
+
* Nothing is asked of the picture while the pointer is still.
|
|
11
|
+
*/
|
|
12
|
+
export function bindSatelliteHover(host) {
|
|
13
|
+
let label;
|
|
14
|
+
let leaving = false;
|
|
15
|
+
let timer;
|
|
16
|
+
let queued = false;
|
|
17
|
+
let point = null;
|
|
18
|
+
const clearTimer = () => {
|
|
19
|
+
if (timer !== undefined)
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
timer = undefined;
|
|
22
|
+
};
|
|
23
|
+
const hideName = (now) => {
|
|
24
|
+
if (!label)
|
|
25
|
+
return;
|
|
26
|
+
label.style.opacity = "0";
|
|
27
|
+
if (now || prefersLessMotion())
|
|
28
|
+
label.hidden = true;
|
|
29
|
+
};
|
|
30
|
+
const showName = (ref, place) => {
|
|
31
|
+
const box = host.labelParent();
|
|
32
|
+
const naming = host.namesOn() && ref && place && place.visible && !same(ref, host.selected()) ? ref : null;
|
|
33
|
+
if (!box || !naming || !place) {
|
|
34
|
+
hideName(true);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (!label) {
|
|
38
|
+
label = box.ownerDocument.createElement("div");
|
|
39
|
+
label.className = "sp-sat";
|
|
40
|
+
label.dataset["hover"] = "true";
|
|
41
|
+
box.append(label);
|
|
42
|
+
}
|
|
43
|
+
const text = host.name(naming) ?? "";
|
|
44
|
+
if (label.textContent !== text)
|
|
45
|
+
label.textContent = text;
|
|
46
|
+
label.hidden = text === "";
|
|
47
|
+
label.style.opacity = "1";
|
|
48
|
+
label.style.transform = `translate(${Math.round(place.x + 10)}px,${Math.round(place.y - 8)}px)`;
|
|
49
|
+
};
|
|
50
|
+
const apply = () => {
|
|
51
|
+
queued = false;
|
|
52
|
+
if (!point)
|
|
53
|
+
return;
|
|
54
|
+
if (point.x < 0)
|
|
55
|
+
return;
|
|
56
|
+
const ref = host.pathOn() || host.namesOn() ? host.pick(point.x, point.y) : null;
|
|
57
|
+
const hover = host.state.hover;
|
|
58
|
+
const path = host.pathOn() ? ref : null;
|
|
59
|
+
if (!path && (hover.ref || hover.fade > 0)) {
|
|
60
|
+
leave();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (same(path, hover.ref) && hover.fade === 1 && hover.enabled === host.pathOn()) {
|
|
64
|
+
showName(ref, ref ? host.place(ref) : null);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
clearTimer();
|
|
68
|
+
leaving = false;
|
|
69
|
+
const look = host.style();
|
|
70
|
+
hover.color = look.color;
|
|
71
|
+
hover.opacity = look.opacity;
|
|
72
|
+
hover.enabled = host.pathOn();
|
|
73
|
+
hover.ref = path;
|
|
74
|
+
hover.fade = path ? 1 : 0;
|
|
75
|
+
showName(ref, ref ? host.place(ref) : null);
|
|
76
|
+
host.request();
|
|
77
|
+
};
|
|
78
|
+
const queue = (x, y) => {
|
|
79
|
+
point = { x, y };
|
|
80
|
+
if (queued)
|
|
81
|
+
return;
|
|
82
|
+
queued = true;
|
|
83
|
+
host.element.ownerDocument.defaultView?.requestAnimationFrame(apply);
|
|
84
|
+
};
|
|
85
|
+
const leave = () => {
|
|
86
|
+
point = null;
|
|
87
|
+
const hover = host.state.hover;
|
|
88
|
+
if (!hover.ref && hover.fade === 0) {
|
|
89
|
+
hideName(true);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
clearTimer();
|
|
93
|
+
if (prefersLessMotion()) {
|
|
94
|
+
leaving = false;
|
|
95
|
+
hover.ref = null;
|
|
96
|
+
hover.fade = 0;
|
|
97
|
+
hideName(true);
|
|
98
|
+
host.request();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
leaving = true;
|
|
102
|
+
const from = hover.fade;
|
|
103
|
+
const started = performance.now();
|
|
104
|
+
hideName(false);
|
|
105
|
+
const step = () => {
|
|
106
|
+
const left = fadeLeft(performance.now() - started, from);
|
|
107
|
+
hover.fade = left;
|
|
108
|
+
host.request();
|
|
109
|
+
if (left > 0)
|
|
110
|
+
timer = setTimeout(step, 32);
|
|
111
|
+
else {
|
|
112
|
+
hover.ref = null;
|
|
113
|
+
hover.fade = 0;
|
|
114
|
+
leaving = false;
|
|
115
|
+
hideName(true);
|
|
116
|
+
host.request();
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
step();
|
|
120
|
+
};
|
|
121
|
+
const move = (event) => {
|
|
122
|
+
if (event.pointerType === "touch" || event.buttons !== 0)
|
|
123
|
+
return;
|
|
124
|
+
const rect = host.element.getBoundingClientRect();
|
|
125
|
+
queue(event.clientX - rect.left, event.clientY - rect.top);
|
|
126
|
+
};
|
|
127
|
+
const down = (event) => {
|
|
128
|
+
if (event.pointerType === "touch")
|
|
129
|
+
return;
|
|
130
|
+
leave();
|
|
131
|
+
};
|
|
132
|
+
host.element.addEventListener("pointermove", move);
|
|
133
|
+
host.element.addEventListener("pointerdown", down);
|
|
134
|
+
host.element.addEventListener("pointerleave", leave);
|
|
135
|
+
host.element.addEventListener("pointercancel", leave);
|
|
136
|
+
return {
|
|
137
|
+
sync() {
|
|
138
|
+
const on = host.pathOn();
|
|
139
|
+
const hover = host.state.hover;
|
|
140
|
+
const look = host.style();
|
|
141
|
+
hover.color = look.color;
|
|
142
|
+
hover.opacity = look.opacity;
|
|
143
|
+
if (hover.enabled === on)
|
|
144
|
+
return;
|
|
145
|
+
hover.enabled = on;
|
|
146
|
+
if (!on) {
|
|
147
|
+
clearTimer();
|
|
148
|
+
leaving = false;
|
|
149
|
+
hover.ref = null;
|
|
150
|
+
hover.fade = 0;
|
|
151
|
+
hideName(!host.namesOn());
|
|
152
|
+
}
|
|
153
|
+
host.request();
|
|
154
|
+
},
|
|
155
|
+
follow(place) {
|
|
156
|
+
if (leaving || !host.state.hover.ref)
|
|
157
|
+
return;
|
|
158
|
+
showName(host.state.hover.ref, place);
|
|
159
|
+
},
|
|
160
|
+
stop() {
|
|
161
|
+
clearTimer();
|
|
162
|
+
host.element.removeEventListener("pointermove", move);
|
|
163
|
+
host.element.removeEventListener("pointerdown", down);
|
|
164
|
+
host.element.removeEventListener("pointerleave", leave);
|
|
165
|
+
host.element.removeEventListener("pointercancel", leave);
|
|
166
|
+
label?.remove();
|
|
167
|
+
label = undefined;
|
|
168
|
+
host.state.hover.ref = null;
|
|
169
|
+
host.state.hover.fade = 0;
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/** A blank custom property is the default. `Number("")` is 0, which would hide the orbit. */
|
|
174
|
+
export const hoverOpacityOf = (text) => {
|
|
175
|
+
const raw = text.trim() === "" ? Number.NaN : Number(text);
|
|
176
|
+
return Number.isFinite(raw) && raw >= 0 && raw <= 1 ? raw : HOVER_PATH_OPACITY;
|
|
177
|
+
};
|
|
178
|
+
/** Colour and opacity from the element's own custom properties, or the faint orbit's own. */
|
|
179
|
+
export function hoverStyleOf(element) {
|
|
180
|
+
const css = element.ownerDocument.defaultView?.getComputedStyle(element);
|
|
181
|
+
const color = css?.getPropertyValue("--chikyu-hover-path").trim() || "#ffffff";
|
|
182
|
+
return { color, opacity: hoverOpacityOf(css?.getPropertyValue("--chikyu-hover-path-opacity") ?? "") };
|
|
183
|
+
}
|
|
@@ -28,6 +28,17 @@ export interface SatelliteState {
|
|
|
28
28
|
orbitTint: boolean;
|
|
29
29
|
/** One group shown on its own. `null` leaves every group as the page set it. */
|
|
30
30
|
focus: SatelliteFocus | null;
|
|
31
|
+
/**
|
|
32
|
+
* The satellite the pointer rests on, and the faint orbit drawn for it. `fade` is 1 while the pointer rests and falls to 0 after it leaves.
|
|
33
|
+
* `enabled` is off when the page turns the faint orbit off. The path is computed once per satellite, from the elements already loaded.
|
|
34
|
+
*/
|
|
35
|
+
hover: {
|
|
36
|
+
ref: SatelliteRef | null;
|
|
37
|
+
fade: number;
|
|
38
|
+
enabled: boolean;
|
|
39
|
+
color: string;
|
|
40
|
+
opacity: number;
|
|
41
|
+
};
|
|
31
42
|
/**
|
|
32
43
|
* The pixel ceiling of a streak's length on the screen above the interpolation limit, in CSS pixels at the Earth's own distance (`satellite-streak-max`). A streak is also never longer than {@link STREAK_REACH} Earth radii, so it shrinks with the Earth.
|
|
33
44
|
* 0 draws the whole stretch one frame spans, however long that is.
|
|
@@ -50,6 +61,9 @@ export interface SatelliteState {
|
|
|
50
61
|
updates: number;
|
|
51
62
|
totalMs: number;
|
|
52
63
|
selectedRing: boolean;
|
|
64
|
+
hoverPath: boolean;
|
|
65
|
+
hoverOpacity: number;
|
|
66
|
+
selectedOpacity: number;
|
|
53
67
|
};
|
|
54
68
|
}
|
|
55
69
|
/**
|
|
@@ -82,6 +96,20 @@ export declare function longestStreak(segments: Float32Array, count: number, ear
|
|
|
82
96
|
export declare const newSatelliteState: () => SatelliteState;
|
|
83
97
|
/** The most orbits a group may draw all at once, one line each. */
|
|
84
98
|
export declare const MAX_ORBIT_GROUP = 40;
|
|
99
|
+
/** How bright the chosen satellite's orbit is. The orbit under the pointer is about a third of this, so the two are told apart at a glance. */
|
|
100
|
+
export declare const SELECTED_PATH_OPACITY = 0.85;
|
|
101
|
+
/** The orbit under the pointer, before it fades. A page may set another with `--chikyu-hover-path-opacity`. */
|
|
102
|
+
export declare const HOVER_PATH_OPACITY: number;
|
|
103
|
+
/** How long the faint orbit takes to go after the pointer leaves, in milliseconds. Reduced motion takes it away at once. */
|
|
104
|
+
export declare const HOVER_FADE_MS = 180;
|
|
105
|
+
/**
|
|
106
|
+
* How much of the faint orbit is left `elapsedMs` into its fade, from `from` (1 while the pointer rests) down to 0.
|
|
107
|
+
*
|
|
108
|
+
* @param elapsedMs - Milliseconds since the pointer left.
|
|
109
|
+
* @param from - The opacity share when the fade began, 0 to 1.
|
|
110
|
+
* @returns The share still drawn, 0 when the fade is over.
|
|
111
|
+
*/
|
|
112
|
+
export declare const fadeLeft: (elapsedMs: number, from: number) => number;
|
|
85
113
|
/** How long, in milliseconds of wall time, a satellite's place is kept before SGP4 places it again when the clock is too fast to interpolate: about once a second. */
|
|
86
114
|
export declare const PIN_PERIOD_MS = 1000;
|
|
87
115
|
/**
|
|
@@ -127,7 +155,32 @@ export declare function screenEdge(x: number, y: number, width: number, height:
|
|
|
127
155
|
*/
|
|
128
156
|
export declare function edgeBeyondCamera(x: number, y: number): ScreenEdge;
|
|
129
157
|
/**
|
|
130
|
-
*
|
|
158
|
+
* Whether the Earth hides a satellite. The Earth is the unit sphere at the origin. True when the line from the camera to the satellite meets that sphere before it arrives. A graze at the limb is not hidden (the line only touches the sphere), and neither is a satellite in front of the Earth. This is not the test for a satellite behind the camera.
|
|
159
|
+
*
|
|
160
|
+
* @param camera - The camera, in the same units as the sphere (Earth radii).
|
|
161
|
+
* @param satellite - The satellite, in those units.
|
|
162
|
+
* @returns True when the globe is in the way.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* import { earthHides } from "@johnmorrisdotca/chikyu-earth/space";
|
|
167
|
+
*
|
|
168
|
+
* const camera = { x: 0, y: 0, z: 4 };
|
|
169
|
+
* console.log(earthHides(camera, { x: 0, y: 0, z: 1.2 }));
|
|
170
|
+
* console.log(earthHides(camera, { x: 0, y: 0, z: -1.2 }));
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
export declare function earthHides(camera: {
|
|
174
|
+
x: number;
|
|
175
|
+
y: number;
|
|
176
|
+
z: number;
|
|
177
|
+
}, satellite: {
|
|
178
|
+
x: number;
|
|
179
|
+
y: number;
|
|
180
|
+
z: number;
|
|
181
|
+
}): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Where a satellite is on the screen now: in CSS pixels from the view's top left (which may lie outside the box), whether it can be seen, which edge it lies beyond, whether it is behind the camera, whether the Earth hides it, and how high it is.
|
|
131
184
|
*
|
|
132
185
|
* @example
|
|
133
186
|
* ```ts
|
|
@@ -148,6 +201,8 @@ export interface SatelliteScreen {
|
|
|
148
201
|
edge: ScreenEdge | null;
|
|
149
202
|
/** The satellite is behind the camera. The picture would put it on the opposite side, so `edge` is taken from the camera's own axes. */
|
|
150
203
|
behind: boolean;
|
|
204
|
+
/** The Earth hides the satellite: the line from the camera meets the globe before the satellite. False at the limb, in front, and when the satellite is only behind the camera. */
|
|
205
|
+
occluded: boolean;
|
|
151
206
|
}
|
|
152
207
|
export interface SatelliteLayer {
|
|
153
208
|
/** Where one satellite of a shown group is on the screen as of the last update, or `null` when its group is not shown or it is not placed (its elements are too old). A satellite outside the picture or behind the camera is still returned, with `visible` false. */
|