@johnmorrisdotca/chikyu-earth 0.46.6 → 0.48.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 -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 +12 -1
- package/dist/realistic/earth.js +17 -1
- package/dist/realistic/element-base.d.ts +92 -0
- package/dist/realistic/element-base.js +179 -4
- package/dist/sky/claim.d.ts +4 -0
- package/dist/sky/claim.js +8 -0
- package/dist/sky/host.js +5 -0
- package/dist/space/element-base.d.ts +168 -2
- package/dist/space/element-base.js +402 -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/path-controls.d.ts +56 -0
- package/dist/space/path-controls.js +121 -0
- package/dist/space/path-ribbons.d.ts +25 -0
- package/dist/space/path-ribbons.js +165 -0
- package/dist/space/paths.d.ts +119 -0
- package/dist/space/paths.js +163 -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 +83 -2
- package/dist/space/satellite-layer.js +231 -52
- package/dist/space/satellite-model.d.ts +2 -1
- package/dist/space/satellite-model.js +4 -3
- package/dist/space/scene.d.ts +41 -0
- package/dist/space/scene.js +82 -13
- package/package.json +6 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/** The most extra paths drawn at once. A longer list keeps the last of it (the most recent). */
|
|
2
|
+
export const MAX_PATHS = 16;
|
|
3
|
+
/** The path hit radius in CSS pixels when the page does not say (`path-hit`), and its range. A touch is given twice as much, and at least {@link TOUCH_HIT_MIN}. */
|
|
4
|
+
export const DEFAULT_PATH_HIT = 8;
|
|
5
|
+
export const MAX_PATH_HIT = 40;
|
|
6
|
+
export const TOUCH_HIT_MIN = 16;
|
|
7
|
+
export const MIN_PATH_WIDTH = 0.5;
|
|
8
|
+
export const MAX_PATH_WIDTH = 8;
|
|
9
|
+
/** The look of each name before a page overrides any. They differ in width and dash, not only in colour. */
|
|
10
|
+
export const BUILT_IN_PATH_STYLES = {
|
|
11
|
+
selected: { color: "#ffffff", width: 2, opacity: 0.85, dash: null },
|
|
12
|
+
hovered: { color: "#ffffff", width: 1.5, opacity: 0.6, dash: [6, 4] },
|
|
13
|
+
favourite: { color: "#ffd166", width: 1.75, opacity: 0.85, dash: [3, 4] },
|
|
14
|
+
path: { color: "#ffffff", width: 1.5, opacity: 0.8, dash: null },
|
|
15
|
+
};
|
|
16
|
+
const clamp = (value, low, high) => Math.min(high, Math.max(low, value));
|
|
17
|
+
/**
|
|
18
|
+
* Take a look a page gave and make a whole one: what is missing or out of range is taken from `base` (a number is held to its range, a dash that is not two numbers of 1 to 64 is `base`'s dash, `null` is a solid line).
|
|
19
|
+
*
|
|
20
|
+
* @param given - The page's look, any part of it.
|
|
21
|
+
* @param base - The look to fall back on.
|
|
22
|
+
* @returns A look with every part set.
|
|
23
|
+
*/
|
|
24
|
+
export function completeStyle(given, base) {
|
|
25
|
+
const out = { ...base, dash: base.dash ? [...base.dash] : null };
|
|
26
|
+
if (!given || typeof given !== "object")
|
|
27
|
+
return out;
|
|
28
|
+
if (typeof given.color === "string" && given.color.trim() !== "")
|
|
29
|
+
out.color = given.color.trim();
|
|
30
|
+
if (typeof given.width === "number" && Number.isFinite(given.width))
|
|
31
|
+
out.width = clamp(given.width, MIN_PATH_WIDTH, MAX_PATH_WIDTH);
|
|
32
|
+
if (typeof given.opacity === "number" && Number.isFinite(given.opacity))
|
|
33
|
+
out.opacity = clamp(given.opacity, 0, 1);
|
|
34
|
+
if (given.dash === null)
|
|
35
|
+
out.dash = null;
|
|
36
|
+
else if (Array.isArray(given.dash) && given.dash.length === 2 && given.dash.every((n) => typeof n === "number" && Number.isFinite(n)))
|
|
37
|
+
out.dash = [clamp(given.dash[0], 1, 64), clamp(given.dash[1], 1, 64)];
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The table of looks in use: the built-in ones with the page's own laid over them, name by name. An override is a partial look over the built-in of that name (or over `path` for a new name);
|
|
42
|
+
* `null` takes a page's override away.
|
|
43
|
+
*
|
|
44
|
+
* @param overrides - The page's entries.
|
|
45
|
+
* @returns The whole table, a new object.
|
|
46
|
+
*/
|
|
47
|
+
export function styleTable(overrides) {
|
|
48
|
+
const table = {};
|
|
49
|
+
for (const [name, style] of Object.entries(BUILT_IN_PATH_STYLES))
|
|
50
|
+
table[name] = completeStyle(null, style);
|
|
51
|
+
for (const [name, given] of Object.entries(overrides)) {
|
|
52
|
+
if (given === null || name === "")
|
|
53
|
+
continue;
|
|
54
|
+
table[name] = completeStyle(given, table[name] ?? BUILT_IN_PATH_STYLES["path"]);
|
|
55
|
+
}
|
|
56
|
+
return table;
|
|
57
|
+
}
|
|
58
|
+
/** The part of a list that is drawn and how much was left out: the last {@link MAX_PATHS}, in their order. */
|
|
59
|
+
export function capPaths(list) {
|
|
60
|
+
const dropped = Math.max(0, list.length - MAX_PATHS);
|
|
61
|
+
return { kept: list.slice(dropped), dropped };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Find the satellite an id names among the groups shown: a NORAD number, or `group:index` (`group/index` is read the same). `null` when nothing matches.
|
|
65
|
+
*
|
|
66
|
+
* @param id - The id from a path request.
|
|
67
|
+
* @param groups - The groups, by name.
|
|
68
|
+
* @returns The satellite, or `null`.
|
|
69
|
+
*/
|
|
70
|
+
export function resolvePathId(id, groups) {
|
|
71
|
+
if (typeof id === "string") {
|
|
72
|
+
const at = Math.max(id.lastIndexOf(":"), id.lastIndexOf("/"));
|
|
73
|
+
if (at > 0) {
|
|
74
|
+
const group = id.slice(0, at);
|
|
75
|
+
const index = Number(id.slice(at + 1));
|
|
76
|
+
const found = groups.get(group);
|
|
77
|
+
return found && Number.isInteger(index) && index >= 0 && index < found.satellites.count ? { group, index } : null;
|
|
78
|
+
}
|
|
79
|
+
const number = Number(id);
|
|
80
|
+
if (id.trim() === "" || !Number.isInteger(number))
|
|
81
|
+
return null;
|
|
82
|
+
return resolvePathId(number, groups);
|
|
83
|
+
}
|
|
84
|
+
if (!Number.isInteger(id))
|
|
85
|
+
return null;
|
|
86
|
+
for (const [group, found] of groups) {
|
|
87
|
+
const sets = found.satellites.sets;
|
|
88
|
+
for (let index = 0; index < found.satellites.count; index += 1)
|
|
89
|
+
if (sets[index]?.NORAD_CAT_ID === id)
|
|
90
|
+
return { group, index };
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
/** The radius a pointer finds a path within: the page's `path-hit` for a mouse or a pen, twice it (at least {@link TOUCH_HIT_MIN}) for a touch, and 0 (no test) when `path-hit` is 0. */
|
|
95
|
+
export function hitRadius(base, pointer) {
|
|
96
|
+
if (!(base > 0))
|
|
97
|
+
return 0;
|
|
98
|
+
return pointer === "touch" ? Math.max(TOUCH_HIT_MIN, base * 2) : base;
|
|
99
|
+
}
|
|
100
|
+
/** Read `path-hit`: a number of CSS pixels from 0 to {@link MAX_PATH_HIT}, `off` for 0, and the default for nothing or anything else. */
|
|
101
|
+
export function readPathHit(value) {
|
|
102
|
+
if (value === null || value.trim() === "")
|
|
103
|
+
return DEFAULT_PATH_HIT;
|
|
104
|
+
const text = value.trim().toLowerCase();
|
|
105
|
+
if (text === "off")
|
|
106
|
+
return 0;
|
|
107
|
+
const number = Number(text);
|
|
108
|
+
return Number.isFinite(number) && number >= 0 ? Math.min(MAX_PATH_HIT, number) : DEFAULT_PATH_HIT;
|
|
109
|
+
}
|
|
110
|
+
/** The look of the path of a request: a name in the table, a partial look over `path`, or `path` itself. A name the table does not have is `path`. */
|
|
111
|
+
export function styleOf(request, table) {
|
|
112
|
+
const given = request.style;
|
|
113
|
+
const base = table["path"] ?? BUILT_IN_PATH_STYLES["path"];
|
|
114
|
+
if (given === undefined)
|
|
115
|
+
return { name: "path", style: base };
|
|
116
|
+
if (typeof given === "string")
|
|
117
|
+
return table[given] ? { name: given, style: table[given] } : { name: "path", style: base };
|
|
118
|
+
return { name: "custom", style: completeStyle(given, base) };
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* How far a point is from a line segment, and the point on it nearest. All in the same units (CSS pixels on the picture).
|
|
122
|
+
*
|
|
123
|
+
* @param px - The point's x.
|
|
124
|
+
* @param py - The point's y.
|
|
125
|
+
* @param ax - The segment's start x.
|
|
126
|
+
* @param ay - The segment's start y.
|
|
127
|
+
* @param bx - The segment's end x.
|
|
128
|
+
* @param by - The segment's end y.
|
|
129
|
+
* @returns The distance and the nearest point.
|
|
130
|
+
*/
|
|
131
|
+
export function nearestOnSegment(px, py, ax, ay, bx, by) {
|
|
132
|
+
const dx = bx - ax;
|
|
133
|
+
const dy = by - ay;
|
|
134
|
+
const len2 = dx * dx + dy * dy;
|
|
135
|
+
const t = len2 > 0 ? clamp(((px - ax) * dx + (py - ay) * dy) / len2, 0, 1) : 0;
|
|
136
|
+
const x = ax + dx * t;
|
|
137
|
+
const y = ay + dy * t;
|
|
138
|
+
return { distance: Math.hypot(px - x, py - y), x, y };
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The nearest of several closed loops of screen points to a point, within `radius`. A segment is left out when either end is flagged hidden (behind the Earth, behind the camera or off the picture's depth).
|
|
142
|
+
*
|
|
143
|
+
* @param px - The point's x.
|
|
144
|
+
* @param py - The point's y.
|
|
145
|
+
* @param loops - Each loop's screen points (`xy`, two numbers each) and a flag for each point (`ok`: 1 when the point can be seen, else 0).
|
|
146
|
+
* @param radius - The most the point may be from a loop.
|
|
147
|
+
* @returns The loop's index, the distance and the nearest point, or `null` when no loop is within the radius.
|
|
148
|
+
*/
|
|
149
|
+
export function nearestLoop(px, py, loops, radius) {
|
|
150
|
+
let best = null;
|
|
151
|
+
for (let l = 0; l < loops.length; l += 1) {
|
|
152
|
+
const { xy, ok, count } = loops[l];
|
|
153
|
+
for (let i = 0; i < count; i += 1) {
|
|
154
|
+
const j = (i + 1) % count;
|
|
155
|
+
if (!ok[i] || !ok[j])
|
|
156
|
+
continue;
|
|
157
|
+
const near = nearestOnSegment(px, py, xy[i * 2], xy[i * 2 + 1], xy[j * 2], xy[j * 2 + 1]);
|
|
158
|
+
if (near.distance <= radius && (best === null || near.distance < best.distance))
|
|
159
|
+
best = { index: l, distance: near.distance, x: near.x, y: near.y };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return best;
|
|
163
|
+
}
|
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
|
+
}
|
|
@@ -2,6 +2,7 @@ import type * as THREE from "three";
|
|
|
2
2
|
import type { SatelliteRef, Satellites } from "../satellites/types.ts";
|
|
3
3
|
import type { ThreeParts } from "../realistic/textures.ts";
|
|
4
4
|
import { type SatelliteFocus } from "./satellite-focus.ts";
|
|
5
|
+
import { type PathHit, type PathInfo, type PathRequest, type PathStyle } from "./paths.ts";
|
|
5
6
|
type Three = ThreeParts;
|
|
6
7
|
/** How a group looks: the colour of its dots and their size in CSS pixels, and whether every orbit is drawn (only for a small group). */
|
|
7
8
|
export interface SatelliteStyle {
|
|
@@ -28,6 +29,32 @@ export interface SatelliteState {
|
|
|
28
29
|
orbitTint: boolean;
|
|
29
30
|
/** One group shown on its own. `null` leaves every group as the page set it. */
|
|
30
31
|
focus: SatelliteFocus | null;
|
|
32
|
+
/**
|
|
33
|
+
* 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.
|
|
34
|
+
* `enabled` is off when the page turns the faint orbit off. The path is computed once per satellite, from the elements already loaded.
|
|
35
|
+
*/
|
|
36
|
+
hover: {
|
|
37
|
+
ref: SatelliteRef | null;
|
|
38
|
+
fade: number;
|
|
39
|
+
enabled: boolean;
|
|
40
|
+
color: string;
|
|
41
|
+
opacity: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The extra paths a page asked for (`setPaths`), the look table (`setPathStyles`: the page's entries over the built-in ones), whether the chosen satellite's own orbit is drawn (`selected-path`), and a number that goes up at each change so the layer
|
|
45
|
+
* rewrites its buffers only when something changed. `info` is what the last draw resolved and kept: the paths drawn, in order; `dropped` how many the cap left out and `unresolved` how many matched no satellite.
|
|
46
|
+
*/
|
|
47
|
+
paths: {
|
|
48
|
+
requests: PathRequest[];
|
|
49
|
+
overrides: Record<string, Partial<PathStyle> | null>;
|
|
50
|
+
selectedOn: boolean;
|
|
51
|
+
version: number;
|
|
52
|
+
info: PathInfo[];
|
|
53
|
+
dropped: number;
|
|
54
|
+
unresolved: number;
|
|
55
|
+
};
|
|
56
|
+
/** Set at each draw by the view: the satellite a ride is on, whose own orbit is drawn in the `selected` look while `selected-path` is on. `null` when none rides a satellite. */
|
|
57
|
+
ridden: SatelliteRef | null;
|
|
31
58
|
/**
|
|
32
59
|
* 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
60
|
* 0 draws the whole stretch one frame spans, however long that is.
|
|
@@ -50,6 +77,11 @@ export interface SatelliteState {
|
|
|
50
77
|
updates: number;
|
|
51
78
|
totalMs: number;
|
|
52
79
|
selectedRing: boolean;
|
|
80
|
+
hoverPath: boolean;
|
|
81
|
+
hoverOpacity: number;
|
|
82
|
+
selectedOpacity: number;
|
|
83
|
+
pathsDrawn: number;
|
|
84
|
+
pathDraws: number;
|
|
53
85
|
};
|
|
54
86
|
}
|
|
55
87
|
/**
|
|
@@ -82,6 +114,20 @@ export declare function longestStreak(segments: Float32Array, count: number, ear
|
|
|
82
114
|
export declare const newSatelliteState: () => SatelliteState;
|
|
83
115
|
/** The most orbits a group may draw all at once, one line each. */
|
|
84
116
|
export declare const MAX_ORBIT_GROUP = 40;
|
|
117
|
+
/** 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. */
|
|
118
|
+
export declare const SELECTED_PATH_OPACITY: number;
|
|
119
|
+
/** The orbit under the pointer, before it fades. A page may set another with `--chikyu-hover-path-opacity`. */
|
|
120
|
+
export declare const HOVER_PATH_OPACITY: number;
|
|
121
|
+
/** How long the faint orbit takes to go after the pointer leaves, in milliseconds. Reduced motion takes it away at once. */
|
|
122
|
+
export declare const HOVER_FADE_MS = 180;
|
|
123
|
+
/**
|
|
124
|
+
* How much of the faint orbit is left `elapsedMs` into its fade, from `from` (1 while the pointer rests) down to 0.
|
|
125
|
+
*
|
|
126
|
+
* @param elapsedMs - Milliseconds since the pointer left.
|
|
127
|
+
* @param from - The opacity share when the fade began, 0 to 1.
|
|
128
|
+
* @returns The share still drawn, 0 when the fade is over.
|
|
129
|
+
*/
|
|
130
|
+
export declare const fadeLeft: (elapsedMs: number, from: number) => number;
|
|
85
131
|
/** 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
132
|
export declare const PIN_PERIOD_MS = 1000;
|
|
87
133
|
/**
|
|
@@ -127,7 +173,32 @@ export declare function screenEdge(x: number, y: number, width: number, height:
|
|
|
127
173
|
*/
|
|
128
174
|
export declare function edgeBeyondCamera(x: number, y: number): ScreenEdge;
|
|
129
175
|
/**
|
|
130
|
-
*
|
|
176
|
+
* 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.
|
|
177
|
+
*
|
|
178
|
+
* @param camera - The camera, in the same units as the sphere (Earth radii).
|
|
179
|
+
* @param satellite - The satellite, in those units.
|
|
180
|
+
* @returns True when the globe is in the way.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* import { earthHides } from "@johnmorrisdotca/chikyu-earth/space";
|
|
185
|
+
*
|
|
186
|
+
* const camera = { x: 0, y: 0, z: 4 };
|
|
187
|
+
* console.log(earthHides(camera, { x: 0, y: 0, z: 1.2 }));
|
|
188
|
+
* console.log(earthHides(camera, { x: 0, y: 0, z: -1.2 }));
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
export declare function earthHides(camera: {
|
|
192
|
+
x: number;
|
|
193
|
+
y: number;
|
|
194
|
+
z: number;
|
|
195
|
+
}, satellite: {
|
|
196
|
+
x: number;
|
|
197
|
+
y: number;
|
|
198
|
+
z: number;
|
|
199
|
+
}): boolean;
|
|
200
|
+
/**
|
|
201
|
+
* 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
202
|
*
|
|
132
203
|
* @example
|
|
133
204
|
* ```ts
|
|
@@ -148,6 +219,8 @@ export interface SatelliteScreen {
|
|
|
148
219
|
edge: ScreenEdge | null;
|
|
149
220
|
/** 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
221
|
behind: boolean;
|
|
222
|
+
/** 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. */
|
|
223
|
+
occluded: boolean;
|
|
151
224
|
}
|
|
152
225
|
export interface SatelliteLayer {
|
|
153
226
|
/** 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. */
|
|
@@ -156,7 +229,10 @@ export interface SatelliteLayer {
|
|
|
156
229
|
height: number;
|
|
157
230
|
}): SatelliteScreen | null;
|
|
158
231
|
/** Place every shown group for `model.time` and the chosen satellite exactly. `earthPx` is the Earth's radius on the screen, so a dot grows as the view zooms in. */
|
|
159
|
-
update(time: number, speed: number, earthPx?: number
|
|
232
|
+
update(time: number, speed: number, earthPx?: number, size?: {
|
|
233
|
+
width: number;
|
|
234
|
+
height: number;
|
|
235
|
+
}): void;
|
|
160
236
|
/** Set the dot size from the Earth's radius on the screen for this frame, after the camera is known. */
|
|
161
237
|
resize(earthPx: number): void;
|
|
162
238
|
/** The satellite nearest to a point of the view (CSS pixels) within `radius`, if one is in front of the Earth. */
|
|
@@ -164,6 +240,11 @@ export interface SatelliteLayer {
|
|
|
164
240
|
width: number;
|
|
165
241
|
height: number;
|
|
166
242
|
}, radius: number): SatelliteRef | null;
|
|
243
|
+
/** The path nearest to a point of the view (CSS pixels) within `radius`, if one is drawn there and not hidden by the Earth: the extra paths and the chosen satellite's own. */
|
|
244
|
+
pathAt(x: number, y: number, camera: THREE.Camera, size: {
|
|
245
|
+
width: number;
|
|
246
|
+
height: number;
|
|
247
|
+
}, radius: number): Omit<PathHit, "pointer"> | null;
|
|
167
248
|
/** Where the chosen satellite is in the view, if it is. */
|
|
168
249
|
place(camera: THREE.Camera, size: {
|
|
169
250
|
width: number;
|