@johnmorrisdotca/chikyu-earth 0.37.0 → 0.39.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 +15 -0
- package/NOTICE.md +2 -1
- package/README.md +2 -1
- package/dist/markers/place-layer.d.ts +12 -1
- package/dist/markers/place-layer.js +88 -18
- package/dist/markers/place-sprites.d.ts +5 -0
- package/dist/markers/place-sprites.js +8 -0
- package/dist/paint/buffer.d.ts +58 -0
- package/dist/paint/buffer.js +321 -0
- package/dist/paint/math.d.ts +24 -0
- package/dist/paint/math.js +94 -0
- package/dist/paint/texture.d.ts +34 -0
- package/dist/paint/texture.js +52 -0
- package/dist/realistic/earth.d.ts +9 -0
- package/dist/realistic/earth.js +19 -10
- package/dist/realistic/element-base.d.ts +437 -0
- package/dist/realistic/element-base.js +1209 -0
- package/dist/realistic/element.d.ts +2 -406
- package/dist/realistic/element.js +3 -1151
- package/dist/realistic/index.d.ts +1 -1
- package/dist/realistic/no-cultures.d.ts +1 -0
- package/dist/realistic/no-cultures.js +2 -0
- package/dist/realistic/shaders.js +13 -0
- package/dist/realistic/tiles.d.ts +24 -0
- package/dist/realistic/tiles.js +30 -12
- package/dist/satellites/track.js +26 -11
- package/dist/satellites/types.d.ts +5 -2
- package/dist/sky/culture-source.d.ts +15 -0
- package/dist/sky/culture-source.js +15 -0
- package/dist/sky/cultures.d.ts +1 -0
- package/dist/sky/cultures.js +8 -0
- package/dist/sky/host.js +144 -18
- package/dist/space/element-base.d.ts +624 -0
- package/dist/space/element-base.js +1627 -0
- package/dist/space/element.d.ts +2 -587
- package/dist/space/element.js +3 -1546
- package/dist/space/no-cultures.d.ts +1 -0
- package/dist/space/no-cultures.js +2 -0
- package/dist/space/satellite-layer.d.ts +24 -0
- package/dist/space/satellite-layer.js +45 -5
- package/dist/space/scene.d.ts +16 -0
- package/dist/space/scene.js +56 -9
- package/package.json +23 -3
|
@@ -3,7 +3,7 @@ export { chooseTier, textureBytes, textureCap, MAX_TEXTURE, TIERS, TEXELS_PER_RA
|
|
|
3
3
|
export { createGate, frameCap, type Gate } from "./gate.ts";
|
|
4
4
|
export { lookAt, discRadius, ATMOSPHERE_OUTER, cameraCentre, type CameraMode, type LightMode } from "./earth.ts";
|
|
5
5
|
export type { ThreeParts } from "./earth.ts";
|
|
6
|
-
export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView, type TileCamera, type TileId, type TileLayer, type VisibleTile } from "./tiles.ts";
|
|
6
|
+
export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView, type TileCamera, type TileId, type TileLayer, type TilePerspective, type VisibleTile } from "./tiles.ts";
|
|
7
7
|
export { TILE_KEEP_MS, TILE_LIMIT } from "./tile-set.ts";
|
|
8
8
|
export { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel, loadMichroma, setBodyLabelFontUrl, type BodyLabelSettings } from "./body-label.ts";
|
|
9
9
|
export { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_THICKNESS_MAX, AIR_TOP, AIR_VERT, airFor, airFrag, airTop, readAirThickness, type AirSamples } from "./air.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./element-base.ts";
|
|
@@ -31,6 +31,10 @@ uniform float cloudShift;
|
|
|
31
31
|
uniform float lights;
|
|
32
32
|
uniform float boost;
|
|
33
33
|
uniform float ortho;
|
|
34
|
+
uniform sampler2D paintMap;
|
|
35
|
+
uniform float paintNow;
|
|
36
|
+
uniform float paintSpan;
|
|
37
|
+
uniform float paintOn;
|
|
34
38
|
${tile ? "uniform vec4 nightRect;\nvarying vec2 vUvG;" : ""}
|
|
35
39
|
varying vec2 vUv;
|
|
36
40
|
varying vec3 vNormal;
|
|
@@ -82,6 +86,15 @@ void main() {
|
|
|
82
86
|
night += vec3(0.04, 0.08, 0.20) * smoothstep(-0.20, -0.06, ndl) * (1.0 - smoothstep(-0.06, 0.06, ndl)) * 0.28;
|
|
83
87
|
vec3 col = mix(night, lit, day);
|
|
84
88
|
col += pow(albedo, vec3(0.75)) * boost * 0.65 * (1.0 - day);
|
|
89
|
+
if (paintOn > 0.5) {
|
|
90
|
+
vec4 stamp = texture2D(paintMap, ${tile ? "vUvG" : "vUv"});
|
|
91
|
+
float then = floor(stamp.r * 255.0 + 0.5) * 256.0 + floor(stamp.g * 255.0 + 0.5);
|
|
92
|
+
float age = paintNow - then;
|
|
93
|
+
if (age < -32768.0) age += 65536.0;
|
|
94
|
+
if (age > 32768.0) age -= 65536.0;
|
|
95
|
+
float show = stamp.a * step(-1.0, age) * (1.0 - smoothstep(paintSpan * 0.82, paintSpan, age));
|
|
96
|
+
col = mix(col, vec3(1.0, 0.55, 0.12), clamp(show, 0.0, 0.92));
|
|
97
|
+
}
|
|
85
98
|
|
|
86
99
|
gl_FragColor = vec4(col, 1.0);
|
|
87
100
|
}`;
|
|
@@ -51,6 +51,30 @@ export interface TileCamera {
|
|
|
51
51
|
panX: number;
|
|
52
52
|
panY: number;
|
|
53
53
|
radius: number;
|
|
54
|
+
/** A camera of the space view, which has a real place and a perspective, in place of the disc: when given, `lon`, `lat`, `panX`, `panY` are not read and `radius` is the disc's radius at the nearest ground. */
|
|
55
|
+
perspective?: TilePerspective;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A camera that sees the Earth in perspective, from a place that can be a few kilometres above the ground, in the Earth's own axes (x toward longitude 90, y north, z toward longitude 0; the Earth's radius is 1).
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import type { TilePerspective } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
63
|
+
*
|
|
64
|
+
* const look: TilePerspective = { eye: [0, 0, 1.0235], project: (p) => ({ x: 400 + p[0] * 5000, y: 300 - p[1] * 5000 }), ground: () => [0, 0, 1] };
|
|
65
|
+
* console.log(look.eye);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export interface TilePerspective {
|
|
69
|
+
/** Where the camera is. */
|
|
70
|
+
eye: readonly [number, number, number];
|
|
71
|
+
/** Where a point of the Earth's surface falls in the box (CSS pixels), or `null` where it is behind the camera. */
|
|
72
|
+
project(point: readonly [number, number, number]): {
|
|
73
|
+
x: number;
|
|
74
|
+
y: number;
|
|
75
|
+
} | null;
|
|
76
|
+
/** The point of the Earth's surface under a place in the box (a unit vector), or `null` where the box shows the sky. */
|
|
77
|
+
ground(x: number, y: number): readonly [number, number, number] | null;
|
|
54
78
|
}
|
|
55
79
|
/**
|
|
56
80
|
* A tile that is in view: where, how far its middle is from the middle of the box (CSS pixels, for loading the middle first) and how dark its darkest sampled point is (`ndl`, the
|
package/dist/realistic/tiles.js
CHANGED
|
@@ -130,6 +130,10 @@ const turned = (lon, lat, lonRad, latRad) => {
|
|
|
130
130
|
* ```
|
|
131
131
|
*/
|
|
132
132
|
export function pointOnEarth(camera, x, y) {
|
|
133
|
+
if (camera.perspective) {
|
|
134
|
+
const g = camera.perspective.ground(x, y);
|
|
135
|
+
return g ? { lon: Math.atan2(g[0], g[2]) / RAD, lat: Math.asin(Math.max(-1, Math.min(1, g[1]))) / RAD } : undefined;
|
|
136
|
+
}
|
|
133
137
|
const px = (x - camera.width / 2 - camera.panX) / camera.radius;
|
|
134
138
|
const py = (camera.height / 2 + camera.panY - y) / camera.radius;
|
|
135
139
|
const rest = 1 - px * px - py * py;
|
|
@@ -174,33 +178,47 @@ export function tilesInView(level, camera, sun) {
|
|
|
174
178
|
const rows = tileRows(level);
|
|
175
179
|
const lonRad = camera.lon * RAD;
|
|
176
180
|
const latRad = camera.lat * RAD;
|
|
181
|
+
const look = camera.perspective;
|
|
177
182
|
const margin = Math.min(160, Math.min(camera.width, camera.height) / 4);
|
|
178
183
|
const cx = camera.width / 2 + camera.panX;
|
|
179
184
|
const cy = camera.height / 2 + camera.panY;
|
|
180
185
|
const found = new Map();
|
|
181
186
|
const ndlOf = (z) => (sun ? z[0] * sun[0] + z[1] * sun[1] + z[2] * sun[2] : 1);
|
|
187
|
+
const eyeLength = look ? Math.hypot(...look.eye) : 1;
|
|
188
|
+
/** A point of the map as the camera has it: the vector to light it by, and where it is in the box when it faces the camera. */
|
|
189
|
+
const sample = (lon, lat) => {
|
|
190
|
+
if (!look) {
|
|
191
|
+
const n = turned(lon, lat, lonRad, latRad);
|
|
192
|
+
const at = { x: cx + n[0] * camera.radius, y: cy - n[1] * camera.radius };
|
|
193
|
+
return { n, screen: n[2] < 0 ? null : at, flat: at, toward: n[2] };
|
|
194
|
+
}
|
|
195
|
+
const cl = Math.cos(lat);
|
|
196
|
+
const n = [cl * Math.sin(lon), Math.sin(lat), cl * Math.cos(lon)];
|
|
197
|
+
const along = n[0] * look.eye[0] + n[1] * look.eye[1] + n[2] * look.eye[2];
|
|
198
|
+
// a point is in sight when it is on the camera's side of the horizon (the plane through the points where its sight lines graze the Earth)
|
|
199
|
+
const screen = along < 1 ? null : look.project(n);
|
|
200
|
+
return { n, screen, flat: screen, toward: along / eyeLength };
|
|
201
|
+
};
|
|
182
202
|
for (let row = 0; row < rows; row += 1) {
|
|
183
203
|
for (let col = 0; col < columns; col += 1) {
|
|
184
204
|
const [west, north, east, south] = tileRect({ level, col, row });
|
|
185
|
-
const middle =
|
|
186
|
-
if (middle
|
|
205
|
+
const middle = sample((west + east) / 2, (north + south) / 2);
|
|
206
|
+
if (middle.toward < -0.4)
|
|
187
207
|
continue;
|
|
188
208
|
let inside = false;
|
|
189
209
|
let darkest = 1;
|
|
190
210
|
for (let j = 0; j <= 2; j += 1) {
|
|
191
211
|
for (let i = 0; i <= 2; i += 1) {
|
|
192
|
-
const p =
|
|
193
|
-
darkest = Math.min(darkest, ndlOf(p));
|
|
194
|
-
if (p
|
|
212
|
+
const p = sample(west + ((east - west) * i) / 2, north + ((south - north) * j) / 2);
|
|
213
|
+
darkest = Math.min(darkest, ndlOf(p.n));
|
|
214
|
+
if (!p.screen)
|
|
195
215
|
continue;
|
|
196
|
-
|
|
197
|
-
const sy = cy - p[1] * camera.radius;
|
|
198
|
-
if (sx >= -margin && sx <= camera.width + margin && sy >= -margin && sy <= camera.height + margin)
|
|
216
|
+
if (p.screen.x >= -margin && p.screen.x <= camera.width + margin && p.screen.y >= -margin && p.screen.y <= camera.height + margin)
|
|
199
217
|
inside = true;
|
|
200
218
|
}
|
|
201
219
|
}
|
|
202
220
|
if (inside) {
|
|
203
|
-
const d = Math.hypot(
|
|
221
|
+
const d = middle.flat ? Math.hypot(middle.flat.x - camera.width / 2, middle.flat.y - camera.height / 2) : Math.hypot(camera.width, camera.height);
|
|
204
222
|
found.set(row * columns + col, { d, ndl: darkest });
|
|
205
223
|
}
|
|
206
224
|
}
|
|
@@ -217,9 +235,9 @@ export function tilesInView(level, camera, sun) {
|
|
|
217
235
|
if (found.has(key))
|
|
218
236
|
continue;
|
|
219
237
|
const [west, north, east, south] = tileRect(tile);
|
|
220
|
-
const p =
|
|
221
|
-
const dark = [
|
|
222
|
-
found.set(key, { d: Math.hypot(
|
|
238
|
+
const p = sample((west + east) / 2, (north + south) / 2);
|
|
239
|
+
const dark = [sample(west, north), sample(east, north), sample(west, south), sample(east, south), p].reduce((least, q) => Math.min(least, ndlOf(q.n)), 1);
|
|
240
|
+
found.set(key, { d: p.flat ? Math.hypot(p.flat.x - camera.width / 2, p.flat.y - camera.height / 2) : Math.hypot(camera.width, camera.height), ndl: dark });
|
|
223
241
|
}
|
|
224
242
|
}
|
|
225
243
|
return [...found]
|
package/dist/satellites/track.js
CHANGED
|
@@ -123,7 +123,9 @@ export function createSatellites(sets, options = {}) {
|
|
|
123
123
|
const timing = { lastBatchMs: 0, maxBatchMs: 0 };
|
|
124
124
|
const pinned = new Float32Array(n * 3);
|
|
125
125
|
const pinOk = new Uint8Array(n);
|
|
126
|
-
|
|
126
|
+
// when each satellite was last pinned (NaN: never), so a group can be pinned a slice at a time and `arc` turns each from its own pin
|
|
127
|
+
const pinMsOf = new Float64Array(n).fill(Number.NaN);
|
|
128
|
+
let pinnedCount = 0;
|
|
127
129
|
/** Turn `x,y,z` about the unit axis `nx,ny,nz` by `ang` radians, into `out` at `at` (no allocation: it runs for every satellite on every frame). */
|
|
128
130
|
const turn = (x, y, z, nx, ny, nz, ang, out, at) => {
|
|
129
131
|
const c = Math.cos(ang);
|
|
@@ -138,10 +140,13 @@ export function createSatellites(sets, options = {}) {
|
|
|
138
140
|
const isEccentric = new Uint8Array(n);
|
|
139
141
|
for (const i of eccentric)
|
|
140
142
|
isEccentric[i] = 1;
|
|
141
|
-
/** SGP4 for
|
|
142
|
-
const sample = (buffer, ok, ms) => {
|
|
143
|
+
/** SGP4 for satellites `from` up to (not including) `to` at one moment (the whole group by default), into `buffer` in the space view's axes (TEME x, z, -y: x to the vernal equinox, y north). */
|
|
144
|
+
const sample = (buffer, ok, ms, from = 0, to = n, skipEccentric = false) => {
|
|
143
145
|
const started = performance.now();
|
|
144
|
-
for (let i =
|
|
146
|
+
for (let i = from; i < to; i += 1) {
|
|
147
|
+
// an eccentric orbit is placed by SGP4 at every frame by `arc` and never read from a pin
|
|
148
|
+
if (skipEccentric && isEccentric[i] === 1)
|
|
149
|
+
continue;
|
|
145
150
|
const epoch = epochs[i];
|
|
146
151
|
if (Math.abs(ms - epoch) > maxAgeMs) {
|
|
147
152
|
ok[i] = 0;
|
|
@@ -198,18 +203,28 @@ export function createSatellites(sets, options = {}) {
|
|
|
198
203
|
get placed() {
|
|
199
204
|
return placed;
|
|
200
205
|
},
|
|
201
|
-
pin(ms) {
|
|
206
|
+
pin(ms, first = 0, count = n) {
|
|
202
207
|
if (n === 0)
|
|
203
208
|
return;
|
|
204
|
-
|
|
205
|
-
|
|
209
|
+
const from = Math.max(0, Math.min(n, Math.floor(first)));
|
|
210
|
+
const to = Math.max(from, Math.min(n, from + Math.floor(count)));
|
|
211
|
+
if (to === from)
|
|
212
|
+
return;
|
|
213
|
+
sample(pinned, pinOk, ms, from, to, true);
|
|
214
|
+
for (let i = from; i < to; i += 1) {
|
|
215
|
+
if (Number.isNaN(pinMsOf[i]))
|
|
216
|
+
pinnedCount += 1;
|
|
217
|
+
pinMsOf[i] = ms;
|
|
218
|
+
}
|
|
206
219
|
},
|
|
207
220
|
arc(ms, spanMs, positions, segments) {
|
|
208
221
|
if (n === 0)
|
|
209
222
|
return 0;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
223
|
+
// a satellite never pinned is pinned now, all together
|
|
224
|
+
if (pinnedCount < n) {
|
|
225
|
+
sample(pinned, pinOk, ms, 0, n, true);
|
|
226
|
+
pinMsOf.fill(ms);
|
|
227
|
+
pinnedCount = n;
|
|
213
228
|
}
|
|
214
229
|
const span = spanMs;
|
|
215
230
|
let count = 0;
|
|
@@ -258,7 +273,7 @@ export function createSatellites(sets, options = {}) {
|
|
|
258
273
|
const ny = normal[k + 1];
|
|
259
274
|
const nz = normal[k + 2];
|
|
260
275
|
const sweep = Math.max(-Math.PI, Math.min(Math.PI, rate[i] * span));
|
|
261
|
-
const along = rate[i] * (ms -
|
|
276
|
+
const along = rate[i] * (ms - pinMsOf[i]);
|
|
262
277
|
turn(pinned[k], pinned[k + 1], pinned[k + 2], nx, ny, nz, along, positions, k);
|
|
263
278
|
turn(pinned[k], pinned[k + 1], pinned[k + 2], nx, ny, nz, along - sweep, segments, w);
|
|
264
279
|
segments[w + 3] = positions[k];
|
|
@@ -168,8 +168,11 @@ export interface Satellites {
|
|
|
168
168
|
readonly classColour: Float32Array;
|
|
169
169
|
/** The game time between the two moments SGP4 is run at (1000 to 60000 ms); the space view sets it from the clock's speed. */
|
|
170
170
|
setStep(ms: number): void;
|
|
171
|
-
/**
|
|
172
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Place satellites with SGP4 at `ms` and keep that place, and the time it was kept at: every satellite, or `count` of them from index `first`, so a big group can be pinned a slice a frame instead of all in one.
|
|
173
|
+
* `arc` turns each satellite along its orbit from its own last pin. No interpolation. A satellite never pinned is pinned by the first `arc`.
|
|
174
|
+
*/
|
|
175
|
+
pin(ms: number, first?: number, count?: number): void;
|
|
173
176
|
/**
|
|
174
177
|
* The place of each satellite at `ms` into `positions` (3 numbers each) and the stretch of orbit it travels over `spanMs` of game time into `segments` (6 numbers each: where it was `spanMs` earlier, then where it is).
|
|
175
178
|
* The place is the last `pin`, turned about the orbit's axis by the mean motion, so a fast clock does not run SGP4 for every satellite on every frame. A `spanMs` that would turn it more than half a revolution is cut there. An orbit with an eccentricity of 0.02 or more is placed by SGP4 itself instead (two calls a frame), because a turn at the mean motion would put it off its path.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Culture } from "@johnmorrisdotca/hoshi-stars/culture";
|
|
2
|
+
/** How to bring each culture in, by id: a dynamic import of its own, so that a bundler makes a file of each. */
|
|
3
|
+
export type CultureLoaders = Readonly<Record<string, () => Promise<Culture>>>;
|
|
4
|
+
/**
|
|
5
|
+
* Sets the cultures an element can load. The default entries (`@johnmorrisdotca/chikyu-earth/space/element` and `.../realistic/element`) set `western`, `japanese` and `chinese`; the entries without cultures set none.
|
|
6
|
+
*
|
|
7
|
+
* @param next - The loaders, by culture id.
|
|
8
|
+
*/
|
|
9
|
+
export declare function setCultureLoaders(next: CultureLoaders): void;
|
|
10
|
+
/**
|
|
11
|
+
* The cultures that can be loaded now.
|
|
12
|
+
*
|
|
13
|
+
* @returns The loaders, by culture id; empty when the build leaves the cultures out.
|
|
14
|
+
*/
|
|
15
|
+
export declare const cultureLoaders: () => CultureLoaders;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
let loaders = {};
|
|
2
|
+
/**
|
|
3
|
+
* Sets the cultures an element can load. The default entries (`@johnmorrisdotca/chikyu-earth/space/element` and `.../realistic/element`) set `western`, `japanese` and `chinese`; the entries without cultures set none.
|
|
4
|
+
*
|
|
5
|
+
* @param next - The loaders, by culture id.
|
|
6
|
+
*/
|
|
7
|
+
export function setCultureLoaders(next) {
|
|
8
|
+
loaders = next;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The cultures that can be loaded now.
|
|
12
|
+
*
|
|
13
|
+
* @returns The loaders, by culture id; empty when the build leaves the cultures out.
|
|
14
|
+
*/
|
|
15
|
+
export const cultureLoaders = () => loaders;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The sky cultures besides the IAU's, each loaded by a dynamic import of its own, only when a page asks for it: a page that never sets `chinese` never downloads it. (The imports are written out, one for each, so that a bundler makes a file of each.)
|
|
2
|
+
// Importing this file is what puts them in a build: the default entries do, the entries without cultures do not.
|
|
3
|
+
import { setCultureLoaders } from "./culture-source.js";
|
|
4
|
+
setCultureLoaders({
|
|
5
|
+
western: async () => (await import("@johnmorrisdotca/hoshi-stars/cultures/western")).western,
|
|
6
|
+
japanese: async () => (await import("@johnmorrisdotca/hoshi-stars/cultures/japanese")).japanese,
|
|
7
|
+
chinese: async () => (await import("@johnmorrisdotca/hoshi-stars/cultures/chinese")).chinese,
|
|
8
|
+
});
|
package/dist/sky/host.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { canvasRatio } from "../markers/project.js";
|
|
2
2
|
import { boxCovered, pathOutside, touches } from "./cover.js";
|
|
3
|
+
import { cultureLoaders } from "./culture-source.js";
|
|
3
4
|
import { createCultureLines } from "./culture-lines.js";
|
|
4
5
|
import { areaInHull, hullOf, nearestSegment, placeBox, visibleCentre } from "./figure-pick.js";
|
|
5
6
|
import { inKeep, keepBox, touchesKeep } from "./keep-clear.js";
|
|
@@ -7,15 +8,8 @@ import { inKeep, keepBox, touchesKeep } from "./keep-clear.js";
|
|
|
7
8
|
export const SKY_STYLE = "#sk-canvas{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}#sk-names{position:absolute;inset:0;overflow:hidden;pointer-events:none}" +
|
|
8
9
|
".sk-name,.sk-figure,.sk-constellation,.sk-designation{position:absolute;left:0;top:0;margin:0;white-space:nowrap;pointer-events:none;font-family:var(--hoshi-label-font,Michroma,system-ui,sans-serif);font-size:calc(var(--hoshi-label-size,11) * 1px);font-weight:var(--hoshi-label-weight,400);color:var(--hoshi-label-colour,#e9f1ff);letter-spacing:calc(var(--hoshi-label-letter-spacing,.14) * 1em);font-variant:var(--hoshi-label-case-variant,small-caps);text-transform:var(--hoshi-label-case-transform,none);text-shadow:0 0 calc(var(--hoshi-label-halo-width,3) * 1px) var(--hoshi-label-halo,#0a1230)}" +
|
|
9
10
|
".sk-designation{font-family:var(--hoshi-label-designation-font,ui-monospace,monospace);font-size:calc(var(--hoshi-label-designation-size,9) * 1px);color:var(--hoshi-label-designation-colour,#b8c6e0);letter-spacing:0;font-variant:normal;text-transform:none}" +
|
|
10
|
-
".sk-figure{color:var(--hoshi-label-colour,#e9f1ff);opacity:0;transition:opacity .15s ease-out}.sk-constellation{font-size:calc(var(--hoshi-label-size,11) * .9px);color:var(--hoshi-label-constellation-colour,#9db0d3);letter-spacing:.22em;opacity:.85}@media (prefers-reduced-motion:reduce){.sk-figure{transition:none}}.sk-ruler{visibility:hidden}.sk-live{position:absolute;left:0;top:0;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
|
|
11
|
-
|
|
12
|
-
* The sky cultures besides the IAU's, each loaded by a dynamic import of its own, only when a page asks for it: a page that never sets `chinese` never downloads it. (The imports are written out, one for each, so that a bundler makes a file of each.)
|
|
13
|
-
*/
|
|
14
|
-
const CULTURES = {
|
|
15
|
-
western: async () => (await import("@johnmorrisdotca/hoshi-stars/cultures/western")).western,
|
|
16
|
-
japanese: async () => (await import("@johnmorrisdotca/hoshi-stars/cultures/japanese")).japanese,
|
|
17
|
-
chinese: async () => (await import("@johnmorrisdotca/hoshi-stars/cultures/chinese")).chinese,
|
|
18
|
-
};
|
|
11
|
+
".sk-figure{color:var(--hoshi-label-colour,#e9f1ff);opacity:0;transition:opacity .15s ease-out}.sk-constellation{font-size:calc(var(--hoshi-label-size,11) * .9px);color:var(--hoshi-label-constellation-colour,#9db0d3);letter-spacing:.22em;opacity:.85}@media (prefers-reduced-motion:reduce){.sk-figure{transition:none}}.sk-ruler{visibility:hidden}.sk-live{position:absolute;left:0;top:0;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}" +
|
|
12
|
+
"button.sk-name,button.sk-hit{background:transparent;border:0;padding:0;cursor:pointer;pointer-events:auto}button.sk-hit{width:28px;height:28px}button.sk-name:focus-visible,button.sk-hit:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}[hidden]{display:none}";
|
|
19
13
|
const warnedCultures = new Set();
|
|
20
14
|
const NAME_POOL = 40;
|
|
21
15
|
/** What other layers of the element draw as labels over the sky (bodies, satellites, places, cities): a constellation's name keeps off them. */
|
|
@@ -46,6 +40,11 @@ export function createSkyHost(options) {
|
|
|
46
40
|
let figureName;
|
|
47
41
|
/** The figure the pointer rests on, and the one a click or tap picked (IAU abbreviations): the lines of either are lit and the name of one is shown. */
|
|
48
42
|
let hoverAbbr = null;
|
|
43
|
+
/** What a press on a named star tells the page, kept with the button that shows the name. */
|
|
44
|
+
const starOf = new Map();
|
|
45
|
+
/** A focusable point on each figure in view, and the abbreviation it picks. */
|
|
46
|
+
const hits = [];
|
|
47
|
+
const hitAbbr = new Map();
|
|
49
48
|
let pickAbbr = null;
|
|
50
49
|
/** The abbreviation the name now shown (the figure name's span) is of, and the timer that hides it after it has faded. */
|
|
51
50
|
let shownAbbr = null;
|
|
@@ -179,10 +178,10 @@ export function createSkyHost(options) {
|
|
|
179
178
|
canvas.setAttribute("aria-hidden", "true");
|
|
180
179
|
box = doc.createElement("div");
|
|
181
180
|
box.id = "sk-names";
|
|
182
|
-
box.setAttribute("aria-hidden", "true");
|
|
183
181
|
figureName = doc.createElement("span");
|
|
184
182
|
figureName.className = "sk-figure";
|
|
185
183
|
figureName.hidden = true;
|
|
184
|
+
figureName.setAttribute("aria-hidden", "true");
|
|
186
185
|
box.append(figureName);
|
|
187
186
|
ruler = doc.createElement("span");
|
|
188
187
|
ruler.className = "sk-ruler";
|
|
@@ -238,13 +237,23 @@ export function createSkyHost(options) {
|
|
|
238
237
|
host.addEventListener("pointerup", (event) => {
|
|
239
238
|
const start = down;
|
|
240
239
|
down = undefined;
|
|
241
|
-
if (!start || start.id !== event.pointerId
|
|
240
|
+
if (!start || start.id !== event.pointerId)
|
|
242
241
|
return;
|
|
243
242
|
const here = place(event);
|
|
244
243
|
// a press that did not move, and was not held: a click or a tap, not the start of a turn
|
|
245
244
|
if (Math.hypot(here.x - start.x, here.y - start.y) > 6 || event.timeStamp - start.at > 600)
|
|
246
245
|
return;
|
|
247
|
-
|
|
246
|
+
const star = starAt(here.x, here.y);
|
|
247
|
+
if (star) {
|
|
248
|
+
emitStar(star, event.pointerType || "mouse");
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (!lines || !drawStrokes)
|
|
252
|
+
return;
|
|
253
|
+
const figure = figureAt(here.x, here.y);
|
|
254
|
+
setPick(figure, true);
|
|
255
|
+
if (figure)
|
|
256
|
+
emitFigure(figure, event.pointerType || "mouse");
|
|
248
257
|
});
|
|
249
258
|
host.addEventListener("keydown", (event) => {
|
|
250
259
|
if (!lines || !drawStrokes || event.altKey || event.ctrlKey || event.metaKey)
|
|
@@ -333,11 +342,57 @@ export function createSkyHost(options) {
|
|
|
333
342
|
if (send) {
|
|
334
343
|
emit("chikyu-constellation-pick", abbreviation === null ? null : detailOf(abbreviation));
|
|
335
344
|
// a pick is read out, with the figure's name in the page's language; a hover is not (it would be too much to hear)
|
|
336
|
-
|
|
337
|
-
live.textContent = abbreviation === null ? "" : options.language() === "ja" ? `${figureText(abbreviation)}を選択` : `${figureText(abbreviation)} selected`;
|
|
345
|
+
sayPick(abbreviation === null ? "" : figureText(abbreviation));
|
|
338
346
|
}
|
|
339
347
|
drawLines();
|
|
340
348
|
}
|
|
349
|
+
/** Read a pick out, with its name in the page's language. An empty text clears it. */
|
|
350
|
+
function sayPick(text) {
|
|
351
|
+
if (live)
|
|
352
|
+
live.textContent = text === "" ? "" : options.language() === "ja" ? `${text}を選択` : `${text} selected`;
|
|
353
|
+
}
|
|
354
|
+
/** A named star that was pressed or tapped. `name` is the name as drawn. */
|
|
355
|
+
function emitStar(star, pointerType) {
|
|
356
|
+
emit("chikyu-sky-pick", { kind: "star", hr: star.hr, name: star.name, designation: star.designation, x: star.x, y: star.y, pointerType });
|
|
357
|
+
sayPick(star.name);
|
|
358
|
+
}
|
|
359
|
+
/** A constellation figure that was pressed or tapped. */
|
|
360
|
+
function emitFigure(abbreviation, pointerType) {
|
|
361
|
+
emit("chikyu-sky-pick", { kind: "constellation", abbreviation, pointerType });
|
|
362
|
+
}
|
|
363
|
+
/** The named star under a point: its name box first, else the nearest star point within reach. Culled names are not there. */
|
|
364
|
+
function starAt(x, y) {
|
|
365
|
+
const named = names;
|
|
366
|
+
const sky = module;
|
|
367
|
+
if (!named || !sky)
|
|
368
|
+
return null;
|
|
369
|
+
const drawn = (label) => ({
|
|
370
|
+
hr: label.hr,
|
|
371
|
+
name: sky.labelText(label.text, named.style),
|
|
372
|
+
designation: label.designation,
|
|
373
|
+
x: label.x,
|
|
374
|
+
y: label.y,
|
|
375
|
+
});
|
|
376
|
+
for (const [index, label] of named.labels.entries()) {
|
|
377
|
+
if (culled[index])
|
|
378
|
+
continue;
|
|
379
|
+
if (x >= label.x0 && x <= label.x1 && y >= label.y0 && y <= label.y1)
|
|
380
|
+
return drawn(label);
|
|
381
|
+
}
|
|
382
|
+
let best = null;
|
|
383
|
+
let bestD = Number.POSITIVE_INFINITY;
|
|
384
|
+
for (const [index, label] of named.labels.entries()) {
|
|
385
|
+
if (culled[index])
|
|
386
|
+
continue;
|
|
387
|
+
const reach = Math.max(label.ring, 14);
|
|
388
|
+
const d = (x - label.x) ** 2 + (y - label.y) ** 2;
|
|
389
|
+
if (d <= reach * reach && d < bestD) {
|
|
390
|
+
bestD = d;
|
|
391
|
+
best = drawn(label);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return best;
|
|
395
|
+
}
|
|
341
396
|
/** Picks the next (or the previous) figure in view, from the left: the keyboard's way to pick. */
|
|
342
397
|
function cycle(step) {
|
|
343
398
|
if (!lines)
|
|
@@ -348,6 +403,8 @@ export function createSkyHost(options) {
|
|
|
348
403
|
const at = inView.findIndex((f) => f.abbreviation === pickAbbr);
|
|
349
404
|
const next = inView[(at < 0 ? (step > 0 ? 0 : inView.length - 1) : (at + step + inView.length) % inView.length)];
|
|
350
405
|
setPick(next.abbreviation, true);
|
|
406
|
+
// the key picks as Enter on a figure's button does, so the page hears every pick of the reader's the same way
|
|
407
|
+
emitFigure(next.abbreviation, "keyboard");
|
|
351
408
|
}
|
|
352
409
|
const takenAbbr = [];
|
|
353
410
|
/** Whether a box may stand: clear of bodies and kept-clear areas, and clear of the names already placed (those of `ignore` aside). */
|
|
@@ -498,6 +555,7 @@ export function createSkyHost(options) {
|
|
|
498
555
|
while (figurePool.length <= shownFigures) {
|
|
499
556
|
const span = doc.createElement("span");
|
|
500
557
|
span.className = "sk-constellation";
|
|
558
|
+
span.setAttribute("aria-hidden", "true");
|
|
501
559
|
box.append(span);
|
|
502
560
|
figurePool.push(span);
|
|
503
561
|
}
|
|
@@ -578,10 +636,21 @@ export function createSkyHost(options) {
|
|
|
578
636
|
}
|
|
579
637
|
const shown = names.labels.length;
|
|
580
638
|
while (pool.length < Math.min(NAME_POOL, shown)) {
|
|
581
|
-
const name = doc.createElement("
|
|
639
|
+
const name = doc.createElement("button");
|
|
582
640
|
name.className = "sk-name";
|
|
641
|
+
name.setAttribute("type", "button");
|
|
642
|
+
name.addEventListener("click", (event) => {
|
|
643
|
+
// a pointer already sent the pick from the press; Enter and Space are a click with no pointer (detail 0)
|
|
644
|
+
if (event.detail !== 0)
|
|
645
|
+
return;
|
|
646
|
+
const star = starOf.get(name);
|
|
647
|
+
if (!star || name.hidden)
|
|
648
|
+
return;
|
|
649
|
+
emitStar(star, "keyboard");
|
|
650
|
+
});
|
|
583
651
|
const designation = doc.createElement("span");
|
|
584
652
|
designation.className = "sk-designation";
|
|
653
|
+
designation.setAttribute("aria-hidden", "true");
|
|
585
654
|
box.append(name, designation);
|
|
586
655
|
pool.push(name);
|
|
587
656
|
designations.push(designation);
|
|
@@ -595,11 +664,14 @@ export function createSkyHost(options) {
|
|
|
595
664
|
name.hidden = true;
|
|
596
665
|
designation.hidden = true;
|
|
597
666
|
}
|
|
667
|
+
starOf.delete(name);
|
|
598
668
|
continue;
|
|
599
669
|
}
|
|
600
670
|
const text = module.labelText(label.text, names.style);
|
|
601
671
|
if (name.textContent !== text)
|
|
602
672
|
name.textContent = text;
|
|
673
|
+
name.setAttribute("aria-label", text);
|
|
674
|
+
starOf.set(name, { hr: label.hr, name: text, designation: label.designation, x: label.x, y: label.y });
|
|
603
675
|
name.hidden = false;
|
|
604
676
|
const shift = label.anchor === "end" ? "-100%" : label.anchor === "middle" ? "-50%" : "0";
|
|
605
677
|
name.style.transform = `translate(${Math.round(label.textX)}px,${Math.round(label.textY)}px) translate(${shift},-100%)`;
|
|
@@ -678,6 +750,59 @@ export function createSkyHost(options) {
|
|
|
678
750
|
for (const el of figurePool)
|
|
679
751
|
el.hidden = true;
|
|
680
752
|
shownFigures = 0;
|
|
753
|
+
for (const hit of hits)
|
|
754
|
+
hit.hidden = true;
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* One focusable point on each figure that is in view, at the middle of the part of it on the picture. Enter picks it. Nothing is drawn: the buttons are the way a keyboard reaches a figure, and they are moved only when the picture is laid out.
|
|
758
|
+
*/
|
|
759
|
+
function placeFigureHits(frame) {
|
|
760
|
+
if (!box || !lines) {
|
|
761
|
+
for (const hit of hits)
|
|
762
|
+
hit.hidden = true;
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
const placed = [];
|
|
766
|
+
const at = { x: 0, y: 0 };
|
|
767
|
+
const blocked = keep.length > 0 ? blockedAt : covered;
|
|
768
|
+
for (const figure of lines.figures) {
|
|
769
|
+
if (figure.end <= figure.start)
|
|
770
|
+
continue;
|
|
771
|
+
if (!visibleCentre(lines.segments, figure.start, figure.end, frame.width, frame.height, blocked, at))
|
|
772
|
+
continue;
|
|
773
|
+
placed.push({ abbreviation: figure.abbreviation, x: at.x, y: at.y });
|
|
774
|
+
}
|
|
775
|
+
placed.sort((a, b) => a.x - b.x);
|
|
776
|
+
while (hits.length < placed.length) {
|
|
777
|
+
const hit = doc.createElement("button");
|
|
778
|
+
hit.className = "sk-hit";
|
|
779
|
+
hit.setAttribute("type", "button");
|
|
780
|
+
hit.addEventListener("click", (event) => {
|
|
781
|
+
if (event.detail !== 0)
|
|
782
|
+
return;
|
|
783
|
+
const abbreviation = hitAbbr.get(hit);
|
|
784
|
+
if (!abbreviation || hit.hidden)
|
|
785
|
+
return;
|
|
786
|
+
setPick(abbreviation, true);
|
|
787
|
+
emitFigure(abbreviation, "keyboard");
|
|
788
|
+
});
|
|
789
|
+
box.append(hit);
|
|
790
|
+
hits.push(hit);
|
|
791
|
+
}
|
|
792
|
+
for (let i = 0; i < hits.length; i += 1) {
|
|
793
|
+
const hit = hits[i];
|
|
794
|
+
const figure = placed[i];
|
|
795
|
+
if (!figure) {
|
|
796
|
+
hit.hidden = true;
|
|
797
|
+
hitAbbr.delete(hit);
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
800
|
+
const text = figureText(figure.abbreviation);
|
|
801
|
+
hit.setAttribute("aria-label", text);
|
|
802
|
+
hit.hidden = false;
|
|
803
|
+
hit.style.transform = `translate(${Math.round(figure.x)}px,${Math.round(figure.y)}px) translate(-50%,-50%)`;
|
|
804
|
+
hitAbbr.set(hit, figure.abbreviation);
|
|
805
|
+
}
|
|
681
806
|
}
|
|
682
807
|
/** The settings no longer ask for the lines: a figure that was picked is let go, and the page is told. */
|
|
683
808
|
function letGo() {
|
|
@@ -702,11 +827,11 @@ export function createSkyHost(options) {
|
|
|
702
827
|
const id = raw === null || raw.trim() === "" ? "iau" : raw.trim().toLowerCase();
|
|
703
828
|
if (id === "iau")
|
|
704
829
|
return id;
|
|
705
|
-
if (Object.hasOwn(
|
|
830
|
+
if (Object.hasOwn(cultureLoaders(), id) && !cultureFailed.has(id))
|
|
706
831
|
return id;
|
|
707
832
|
if (!warnedCultures.has(id)) {
|
|
708
833
|
warnedCultures.add(id);
|
|
709
|
-
console.warn(`chikyu-earth: constellation-culture="${id}" is not a sky culture here (iau,
|
|
834
|
+
console.warn(`chikyu-earth: constellation-culture="${id}" is not a sky culture here (${["iau", ...Object.keys(cultureLoaders())].join(", ")}): the IAU's constellations are used.`);
|
|
710
835
|
}
|
|
711
836
|
return "iau";
|
|
712
837
|
};
|
|
@@ -714,7 +839,7 @@ export function createSkyHost(options) {
|
|
|
714
839
|
if (cultureLoading.has(id))
|
|
715
840
|
return;
|
|
716
841
|
cultureLoading.add(id);
|
|
717
|
-
void Promise.all([(options.cultures ?? ((name) =>
|
|
842
|
+
void Promise.all([(options.cultures ?? ((name) => cultureLoaders()[name]()))(id), import("@johnmorrisdotca/hoshi-stars/lines")])
|
|
718
843
|
.then(([loaded, library]) => {
|
|
719
844
|
const info = new Map();
|
|
720
845
|
const figures = [];
|
|
@@ -864,6 +989,7 @@ export function createSkyHost(options) {
|
|
|
864
989
|
placeNames();
|
|
865
990
|
placeConstellationNames(frame);
|
|
866
991
|
drawLines();
|
|
992
|
+
placeFigureHits(frame);
|
|
867
993
|
}
|
|
868
994
|
/** The stars that are named at the last frame: each one's own point on the screen (the label's anchor) and its name, from the picture's top left, without the names the browser's measure left out. */
|
|
869
995
|
const starPoints = () => {
|