@johnmorrisdotca/chikyu-earth 0.32.0 → 0.33.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 +11 -0
- package/NOTICE.md +10 -1
- package/README.md +13 -2
- package/dist/catalogue/fleets.d.ts +70 -0
- package/dist/catalogue/fleets.js +66 -0
- package/dist/catalogue/index.d.ts +5 -0
- package/dist/catalogue/index.js +7 -0
- package/dist/catalogue/kinds.d.ts +143 -0
- package/dist/catalogue/kinds.js +121 -0
- package/dist/catalogue/omm.d.ts +44 -0
- package/dist/catalogue/omm.js +92 -0
- package/dist/catalogue/orbit.d.ts +95 -0
- package/dist/catalogue/orbit.js +91 -0
- package/dist/catalogue/pack.d.ts +193 -0
- package/dist/catalogue/pack.js +327 -0
- package/dist/data/meteor-iau.d.ts +79 -0
- package/dist/data/meteor-iau.js +77 -0
- package/dist/data/meteor-showers.js +24 -20
- package/dist/data-door.d.ts +2 -0
- package/dist/data-door.js +4 -2
- package/dist/door/index.d.ts +1 -0
- package/dist/door/index.js +1 -0
- package/dist/door/packed.d.ts +64 -0
- package/dist/door/packed.js +91 -0
- package/dist/meteors/index.d.ts +2 -0
- package/dist/meteors/index.js +2 -0
- package/dist/meteors/parents.d.ts +45 -0
- package/dist/meteors/parents.js +67 -0
- package/dist/realistic/body-label.d.ts +13 -0
- package/dist/realistic/body-label.js +16 -0
- package/dist/realistic/earth.d.ts +3 -0
- package/dist/realistic/earth.js +21 -0
- package/dist/realistic/element.d.ts +18 -0
- package/dist/realistic/element.js +35 -3
- package/dist/realistic/index.d.ts +1 -1
- package/dist/realistic/index.js +1 -1
- package/dist/satellites/source.d.ts +4 -0
- package/dist/satellites/source.js +2 -2
- package/dist/sky/host.d.ts +55 -0
- package/dist/sky/host.js +382 -0
- package/dist/space/element.d.ts +18 -0
- package/dist/space/element.js +35 -3
- package/dist/space/scene.d.ts +3 -0
- package/dist/space/scene.js +26 -0
- package/package.json +11 -1
package/dist/sky/host.js
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { canvasRatio } from "../markers/project.js";
|
|
2
|
+
/** The styles of the layer, for an element to add to its own (`#sk-canvas`, `#sk-names` and the labels in its shadow root). */
|
|
3
|
+
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}" +
|
|
4
|
+
".sk-name,.sk-figure,.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)}" +
|
|
5
|
+
".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}" +
|
|
6
|
+
".sk-figure{color:var(--hoshi-label-colour,#e9f1ff)}[hidden]{display:none}";
|
|
7
|
+
const NAME_POOL = 40;
|
|
8
|
+
/** The attributes this layer reads. */
|
|
9
|
+
export const SKY_ATTRIBUTES = ["star-names", "star-names-magnitude", "constellation-lines"];
|
|
10
|
+
/**
|
|
11
|
+
* Makes the layer of one element, inside its shadow root. Nothing of hoshi-stars is loaded, and nothing is added to the root, until one of the three attributes is there.
|
|
12
|
+
*
|
|
13
|
+
* @param options - The attribute reader, the language and the shadow root.
|
|
14
|
+
* @returns The host.
|
|
15
|
+
*/
|
|
16
|
+
export function createSkyHost(options) {
|
|
17
|
+
const { root } = options;
|
|
18
|
+
const doc = root.ownerDocument;
|
|
19
|
+
let module;
|
|
20
|
+
let loading = false;
|
|
21
|
+
let failed = false;
|
|
22
|
+
let names;
|
|
23
|
+
let lines;
|
|
24
|
+
let last = null;
|
|
25
|
+
let renders = 0;
|
|
26
|
+
let style = {};
|
|
27
|
+
let canvas;
|
|
28
|
+
let box;
|
|
29
|
+
const pool = [];
|
|
30
|
+
const designations = [];
|
|
31
|
+
let figureName;
|
|
32
|
+
let attached = false;
|
|
33
|
+
let covered;
|
|
34
|
+
/** The language the names were last laid out in: the page may change its language after the element was made, so it is read again at each draw. */
|
|
35
|
+
let usedLang;
|
|
36
|
+
/** The names drawn at the last frame that were left out because they ran over another as the browser draws them (by label), and how many names are shown. */
|
|
37
|
+
const culled = [];
|
|
38
|
+
let drawnNames = 0;
|
|
39
|
+
const wanted = () => options.attribute("star-names") !== null || options.attribute("constellation-lines") !== null;
|
|
40
|
+
const attach = () => {
|
|
41
|
+
if (attached)
|
|
42
|
+
return;
|
|
43
|
+
attached = true;
|
|
44
|
+
canvas = doc.createElement("canvas");
|
|
45
|
+
canvas.id = "sk-canvas";
|
|
46
|
+
canvas.setAttribute("aria-hidden", "true");
|
|
47
|
+
box = doc.createElement("div");
|
|
48
|
+
box.id = "sk-names";
|
|
49
|
+
box.setAttribute("aria-hidden", "true");
|
|
50
|
+
figureName = doc.createElement("span");
|
|
51
|
+
figureName.className = "sk-figure";
|
|
52
|
+
figureName.hidden = true;
|
|
53
|
+
box.append(figureName);
|
|
54
|
+
root.append(canvas, box);
|
|
55
|
+
const host = root.host;
|
|
56
|
+
const place = (event) => {
|
|
57
|
+
const rect = host.getBoundingClientRect();
|
|
58
|
+
return { x: event.clientX - rect.left, y: event.clientY - rect.top };
|
|
59
|
+
};
|
|
60
|
+
// a mouse lights the figure it rests on and lets go when it leaves; a finger lights what it touches and the pick stays until the next touch
|
|
61
|
+
host.addEventListener("pointermove", (event) => {
|
|
62
|
+
if (!lines || event.pointerType === "touch")
|
|
63
|
+
return;
|
|
64
|
+
const at = place(event);
|
|
65
|
+
if (lines.point(at.x, at.y))
|
|
66
|
+
drawLines();
|
|
67
|
+
});
|
|
68
|
+
host.addEventListener("pointerleave", (event) => {
|
|
69
|
+
if (!lines || event.pointerType === "touch")
|
|
70
|
+
return;
|
|
71
|
+
if (lines.point())
|
|
72
|
+
drawLines();
|
|
73
|
+
});
|
|
74
|
+
host.addEventListener("pointerdown", (event) => {
|
|
75
|
+
if (!lines || event.pointerType !== "touch")
|
|
76
|
+
return;
|
|
77
|
+
const at = place(event);
|
|
78
|
+
if (lines.point(at.x, at.y))
|
|
79
|
+
drawLines();
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
const sizeCanvas = (frame) => {
|
|
83
|
+
const ratio = canvasRatio(frame.width, frame.height, globalThis.devicePixelRatio || 1);
|
|
84
|
+
const w = Math.max(1, Math.round(frame.width * ratio));
|
|
85
|
+
const h = Math.max(1, Math.round(frame.height * ratio));
|
|
86
|
+
if (canvas.width !== w || canvas.height !== h) {
|
|
87
|
+
canvas.width = w;
|
|
88
|
+
canvas.height = h;
|
|
89
|
+
}
|
|
90
|
+
const context = canvas.getContext("2d");
|
|
91
|
+
context?.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
92
|
+
return context;
|
|
93
|
+
};
|
|
94
|
+
/** The lines and the rings, and the names: drawn again from what `update` laid out. */
|
|
95
|
+
function drawLines() {
|
|
96
|
+
const frame = last;
|
|
97
|
+
if (!frame || !canvas || !module)
|
|
98
|
+
return;
|
|
99
|
+
const context = sizeCanvas(frame);
|
|
100
|
+
if (!context)
|
|
101
|
+
return;
|
|
102
|
+
renders += 1;
|
|
103
|
+
context.clearRect(0, 0, frame.width, frame.height);
|
|
104
|
+
if (lines && lines.count > 0) {
|
|
105
|
+
context.lineWidth = 1;
|
|
106
|
+
context.lineCap = "round";
|
|
107
|
+
context.strokeStyle = "#cfe0ff";
|
|
108
|
+
for (const figure of lines.figures) {
|
|
109
|
+
const opacity = lines.opacityOf(figure);
|
|
110
|
+
if (opacity <= 0)
|
|
111
|
+
continue;
|
|
112
|
+
context.globalAlpha = opacity;
|
|
113
|
+
context.beginPath();
|
|
114
|
+
for (let i = figure.start; i < figure.end; i += 1) {
|
|
115
|
+
context.moveTo(lines.segments[i * 4], lines.segments[i * 4 + 1]);
|
|
116
|
+
context.lineTo(lines.segments[i * 4 + 2], lines.segments[i * 4 + 3]);
|
|
117
|
+
}
|
|
118
|
+
context.stroke();
|
|
119
|
+
}
|
|
120
|
+
context.globalAlpha = 1;
|
|
121
|
+
}
|
|
122
|
+
if (names) {
|
|
123
|
+
const s = names.style;
|
|
124
|
+
context.lineWidth = s.ringWidth;
|
|
125
|
+
context.strokeStyle = s.ringColour;
|
|
126
|
+
for (const [index, label] of names.labels.entries()) {
|
|
127
|
+
if (culled[index])
|
|
128
|
+
continue;
|
|
129
|
+
if (label.ring > 0) {
|
|
130
|
+
context.beginPath();
|
|
131
|
+
context.arc(label.x, label.y, label.ring, 0, Math.PI * 2);
|
|
132
|
+
context.stroke();
|
|
133
|
+
}
|
|
134
|
+
if (label.leader) {
|
|
135
|
+
context.strokeStyle = s.leaderColour;
|
|
136
|
+
context.beginPath();
|
|
137
|
+
context.moveTo(label.leaderX0, label.leaderY0);
|
|
138
|
+
context.lineTo(label.leaderX1, label.leaderY1);
|
|
139
|
+
context.stroke();
|
|
140
|
+
context.strokeStyle = s.ringColour;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// the picked figure's name
|
|
145
|
+
if (figureName) {
|
|
146
|
+
const name = lines?.name;
|
|
147
|
+
if (name) {
|
|
148
|
+
figureName.hidden = false;
|
|
149
|
+
if (figureName.textContent !== name.text)
|
|
150
|
+
figureName.textContent = name.text;
|
|
151
|
+
figureName.style.transform = `translate(${Math.round(name.x)}px,${Math.round(name.y)}px) translate(-50%,-100%)`;
|
|
152
|
+
}
|
|
153
|
+
else
|
|
154
|
+
figureName.hidden = true;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function placeNames() {
|
|
158
|
+
if (!box || !names) {
|
|
159
|
+
drawnNames = 0;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const shown = names.labels.length;
|
|
163
|
+
while (pool.length < Math.min(NAME_POOL, shown)) {
|
|
164
|
+
const name = doc.createElement("span");
|
|
165
|
+
name.className = "sk-name";
|
|
166
|
+
const designation = doc.createElement("span");
|
|
167
|
+
designation.className = "sk-designation";
|
|
168
|
+
box.append(name, designation);
|
|
169
|
+
pool.push(name);
|
|
170
|
+
designations.push(designation);
|
|
171
|
+
}
|
|
172
|
+
for (let i = 0; i < pool.length; i += 1) {
|
|
173
|
+
const name = pool[i];
|
|
174
|
+
const designation = designations[i];
|
|
175
|
+
const label = i < shown ? names.labels[i] : undefined;
|
|
176
|
+
if (!label) {
|
|
177
|
+
if (!name.hidden) {
|
|
178
|
+
name.hidden = true;
|
|
179
|
+
designation.hidden = true;
|
|
180
|
+
}
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
const text = module.labelText(label.text, names.style);
|
|
184
|
+
if (name.textContent !== text)
|
|
185
|
+
name.textContent = text;
|
|
186
|
+
name.hidden = false;
|
|
187
|
+
const shift = label.anchor === "end" ? "-100%" : label.anchor === "middle" ? "-50%" : "0";
|
|
188
|
+
name.style.transform = `translate(${Math.round(label.textX)}px,${Math.round(label.textY)}px) translate(${shift},-100%)`;
|
|
189
|
+
if (label.designation && names.style.designation === "below") {
|
|
190
|
+
if (designation.textContent !== label.designation)
|
|
191
|
+
designation.textContent = label.designation;
|
|
192
|
+
designation.hidden = false;
|
|
193
|
+
designation.style.transform = `translate(${Math.round(label.designationX)}px,${Math.round(label.designationY)}px) translate(${shift},-100%)`;
|
|
194
|
+
}
|
|
195
|
+
else
|
|
196
|
+
designation.hidden = true;
|
|
197
|
+
}
|
|
198
|
+
cullOverlaps(shown);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* hoshi-stars lays the names out by the width it works a name to have (a letter is about 0.6 of the size, a Japanese letter the whole size), and the browser draws them with the font it has: Michroma where it has loaded, another font where it has not, or where
|
|
202
|
+
* the page has none that has the letters (a Japanese name on a machine with no Japanese font). The two can differ, so the names are measured as they are drawn, and a name that runs over one placed before it (the brighter star's) is left out, with its ring.
|
|
203
|
+
*/
|
|
204
|
+
function cullOverlaps(shown) {
|
|
205
|
+
culled.length = 0;
|
|
206
|
+
let visible = 0;
|
|
207
|
+
const kept = [];
|
|
208
|
+
for (let i = 0; i < shown; i += 1) {
|
|
209
|
+
const name = pool[i];
|
|
210
|
+
if (!name || name.hidden) {
|
|
211
|
+
culled.push(true);
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (typeof name.getBoundingClientRect !== "function") {
|
|
215
|
+
culled.push(false);
|
|
216
|
+
visible += 1;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const rect = name.getBoundingClientRect();
|
|
220
|
+
const over = kept.some((one) => rect.left < one.r && rect.right > one.l && rect.top < one.b && rect.bottom > one.t);
|
|
221
|
+
if (over) {
|
|
222
|
+
name.hidden = true;
|
|
223
|
+
designations[i].hidden = true;
|
|
224
|
+
culled.push(true);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
kept.push({ l: rect.left, t: rect.top, r: rect.right, b: rect.bottom });
|
|
228
|
+
culled.push(false);
|
|
229
|
+
visible += 1;
|
|
230
|
+
}
|
|
231
|
+
drawnNames = visible;
|
|
232
|
+
}
|
|
233
|
+
const vars = () => {
|
|
234
|
+
if (!box || !module)
|
|
235
|
+
return;
|
|
236
|
+
const properties = module.labelStyleVars(style);
|
|
237
|
+
for (const [name, value] of Object.entries(properties))
|
|
238
|
+
box.style.setProperty(name, value);
|
|
239
|
+
// the case is drawn by the labels' own CSS (small capitals, or the text itself written in capitals or lower case by `labelText`)
|
|
240
|
+
box.style.setProperty("--hoshi-label-case-variant", (style.case ?? "small-caps") === "small-caps" ? "small-caps" : "normal");
|
|
241
|
+
};
|
|
242
|
+
const configure = () => {
|
|
243
|
+
if (!module)
|
|
244
|
+
return;
|
|
245
|
+
const count = options.attribute("star-names");
|
|
246
|
+
const magnitude = options.attribute("star-names-magnitude");
|
|
247
|
+
const settings = module.starNamesFromAttributes(count, magnitude);
|
|
248
|
+
const strength = module.lineStrengthFromAttribute(options.attribute("constellation-lines"));
|
|
249
|
+
const lang = options.language();
|
|
250
|
+
usedLang = lang;
|
|
251
|
+
if (settings) {
|
|
252
|
+
if (!names)
|
|
253
|
+
names = module.createStarNames({ ...settings, lang, style });
|
|
254
|
+
else
|
|
255
|
+
names.set({ ...settings, lang, style });
|
|
256
|
+
}
|
|
257
|
+
else
|
|
258
|
+
names = undefined;
|
|
259
|
+
if (strength !== undefined) {
|
|
260
|
+
if (!lines)
|
|
261
|
+
lines = module.createFigureLines({ strength, lang, style });
|
|
262
|
+
else
|
|
263
|
+
lines.set({ strength, lang, style });
|
|
264
|
+
}
|
|
265
|
+
else
|
|
266
|
+
lines = undefined;
|
|
267
|
+
vars();
|
|
268
|
+
};
|
|
269
|
+
const load = () => {
|
|
270
|
+
if (module || loading || failed || !wanted())
|
|
271
|
+
return;
|
|
272
|
+
loading = true;
|
|
273
|
+
attach();
|
|
274
|
+
void import("@johnmorrisdotca/hoshi-stars/sky-labels")
|
|
275
|
+
.then(async (loaded) => {
|
|
276
|
+
module = loaded;
|
|
277
|
+
if (!style.font)
|
|
278
|
+
await options.loadFont().catch(() => undefined);
|
|
279
|
+
configure();
|
|
280
|
+
loading = false;
|
|
281
|
+
compute();
|
|
282
|
+
})
|
|
283
|
+
.catch((error) => {
|
|
284
|
+
loading = false;
|
|
285
|
+
failed = true;
|
|
286
|
+
options.onError(error);
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
/** Lays the names and lines out for the last frame, and draws them. */
|
|
290
|
+
function compute() {
|
|
291
|
+
const frame = last;
|
|
292
|
+
if (!frame || !module)
|
|
293
|
+
return;
|
|
294
|
+
if (usedLang !== undefined && options.language() !== usedLang)
|
|
295
|
+
configure();
|
|
296
|
+
const discs = frame.discs;
|
|
297
|
+
covered = discs.length === 0 ? undefined : (x, y) => discs.some((d) => (x - d.x) * (x - d.x) + (y - d.y) * (y - d.y) <= d.radius * d.radius);
|
|
298
|
+
const view = { width: frame.width, height: frame.height };
|
|
299
|
+
if (names)
|
|
300
|
+
names.update(frame.project, view, covered);
|
|
301
|
+
if (lines)
|
|
302
|
+
lines.update(frame.project, view, names ? names.labels : undefined);
|
|
303
|
+
placeNames();
|
|
304
|
+
drawLines();
|
|
305
|
+
}
|
|
306
|
+
// the family's chooser tells the document when the page's language changes: the names are written again, though nothing else is drawn
|
|
307
|
+
const onLanguage = () => queueMicrotask(() => {
|
|
308
|
+
if (module && wanted() && usedLang !== options.language()) {
|
|
309
|
+
configure();
|
|
310
|
+
compute();
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
doc.addEventListener("kazoku-languagechange", onLanguage);
|
|
314
|
+
// a font arrives (Michroma, or the one a Japanese name falls back to): the names are measured as they are drawn, so they are laid out again
|
|
315
|
+
const onFonts = () => {
|
|
316
|
+
if (module && wanted() && last)
|
|
317
|
+
compute();
|
|
318
|
+
};
|
|
319
|
+
doc.fonts?.addEventListener?.("loadingdone", onFonts);
|
|
320
|
+
return {
|
|
321
|
+
frame(next) {
|
|
322
|
+
last = next;
|
|
323
|
+
if (!wanted()) {
|
|
324
|
+
if (attached && canvas)
|
|
325
|
+
canvas.getContext("2d")?.clearRect(0, 0, canvas.width, canvas.height);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
load();
|
|
329
|
+
if (!next) {
|
|
330
|
+
if (canvas)
|
|
331
|
+
canvas.getContext("2d")?.clearRect(0, 0, canvas.width, canvas.height);
|
|
332
|
+
for (const name of pool)
|
|
333
|
+
name.hidden = true;
|
|
334
|
+
for (const designation of designations)
|
|
335
|
+
designation.hidden = true;
|
|
336
|
+
if (figureName)
|
|
337
|
+
figureName.hidden = true;
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
compute();
|
|
341
|
+
},
|
|
342
|
+
refresh() {
|
|
343
|
+
if (!wanted()) {
|
|
344
|
+
names = undefined;
|
|
345
|
+
lines = undefined;
|
|
346
|
+
if (attached && canvas)
|
|
347
|
+
canvas.getContext("2d")?.clearRect(0, 0, canvas.width, canvas.height);
|
|
348
|
+
for (const name of pool)
|
|
349
|
+
name.hidden = true;
|
|
350
|
+
for (const designation of designations)
|
|
351
|
+
designation.hidden = true;
|
|
352
|
+
if (figureName)
|
|
353
|
+
figureName.hidden = true;
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (!module) {
|
|
357
|
+
load();
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
configure();
|
|
361
|
+
compute();
|
|
362
|
+
},
|
|
363
|
+
setStyle(next) {
|
|
364
|
+
style = next;
|
|
365
|
+
if (module) {
|
|
366
|
+
configure();
|
|
367
|
+
compute();
|
|
368
|
+
}
|
|
369
|
+
},
|
|
370
|
+
get stats() {
|
|
371
|
+
return { on: wanted(), loaded: module !== undefined, names: names ? drawnNames : 0, figures: lines?.count ?? 0, picked: lines?.picked?.abbreviation ?? null, renders, lang: usedLang ?? "" };
|
|
372
|
+
},
|
|
373
|
+
dispose() {
|
|
374
|
+
doc.removeEventListener("kazoku-languagechange", onLanguage);
|
|
375
|
+
doc.fonts?.removeEventListener?.("loadingdone", onFonts);
|
|
376
|
+
canvas?.remove();
|
|
377
|
+
box?.remove();
|
|
378
|
+
pool.length = 0;
|
|
379
|
+
designations.length = 0;
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
}
|
package/dist/space/element.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ViewController } from "@johnmorrisdotca/kazoku-ui/view-controls";
|
|
2
2
|
import type { GeoPoint } from "../types.ts";
|
|
3
3
|
import { type BodyLabelSettings } from "../realistic/body-label.ts";
|
|
4
|
+
import type { LabelStyle } from "@johnmorrisdotca/hoshi-stars/sky-labels";
|
|
4
5
|
import { setThreeLoader } from "../realistic/shared.ts";
|
|
5
6
|
import type { LightMode } from "../realistic/earth.ts";
|
|
6
7
|
import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/types.ts";
|
|
@@ -172,6 +173,13 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
172
173
|
*/
|
|
173
174
|
get bodyLabel(): BodyLabelSettings | null;
|
|
174
175
|
set bodyLabel(value: Partial<BodyLabelSettings> | null);
|
|
176
|
+
/**
|
|
177
|
+
* The names of the brightest stars and the constellations as faint lines, laid over the sky the page draws (hoshi-stars' `sky-labels`, an optional peer loaded only when one of these is set). The plain attributes are hoshi's: `star-names` (a count of the brightest stars in view and not covered by the
|
|
178
|
+
* Earth, the Moon or the Sun; bare is 10), `star-names-magnitude` (only stars at least that bright) and `constellation-lines` (the 88 figures as lines at this strength, 0 to 1; bare is 0.16): none of them, and nothing is loaded. The figure under the pointer or touched is at full strength and shows its name. Names are in the
|
|
179
|
+
* page's language and never overlap. Nothing is redrawn at rest. `chikyu-sky-unavailable` is sent when hoshi-stars is not there. The property is the look of the names, a partial hoshi-stars `LabelStyle` (font, size, case, ring, leader and the rest).
|
|
180
|
+
*/
|
|
181
|
+
get skyStyle(): Partial<LabelStyle>;
|
|
182
|
+
set skyStyle(value: Partial<LabelStyle>);
|
|
175
183
|
/**
|
|
176
184
|
* How many times its real thickness the air is drawn, from 1 (the true thickness) to 5 (the attribute `air-thickness`; 3 when the page says nothing): see `<chikyu-earth-realistic>`. While it is above 1 the element says so in a line
|
|
177
185
|
* under the picture (`air-label="off"` takes the line away, for a page that says it itself).
|
|
@@ -332,6 +340,16 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
332
340
|
made: boolean;
|
|
333
341
|
showing: boolean;
|
|
334
342
|
};
|
|
343
|
+
/** The names of the stars and the constellation lines: whether one is asked for, whether hoshi-stars is loaded, the names and figures laid out at the last draw, the figure picked, how many times the layer was drawn and the language its names were last laid out in. */
|
|
344
|
+
sky: {
|
|
345
|
+
on: boolean;
|
|
346
|
+
loaded: boolean;
|
|
347
|
+
names: number;
|
|
348
|
+
figures: number;
|
|
349
|
+
picked: string | null;
|
|
350
|
+
renders: number;
|
|
351
|
+
lang: string;
|
|
352
|
+
};
|
|
335
353
|
};
|
|
336
354
|
}
|
|
337
355
|
declare global {
|
package/dist/space/element.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
|
|
2
2
|
import { adoptStyles } from "../adopt.js";
|
|
3
3
|
import { airFor, readAirThickness } from "../realistic/air.js";
|
|
4
|
-
import { BODY_LABEL_ATTRIBUTES, bodyLabelText, readBodyLabel } from "../realistic/body-label.js";
|
|
4
|
+
import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "../realistic/body-label.js";
|
|
5
|
+
import { createSkyHost, SKY_ATTRIBUTES } from "../sky/host.js";
|
|
5
6
|
import { createGate, frameCap } from "../realistic/gate.js";
|
|
6
7
|
import { setThreeLoader, takeRenderer } from "../realistic/shared.js";
|
|
7
8
|
import { NOTES_STYLE, setAirNote } from "../realistic/air-note.js";
|
|
@@ -101,7 +102,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
|
|
|
101
102
|
* ```
|
|
102
103
|
*/
|
|
103
104
|
export class ChikyuSpace extends HTMLElement {
|
|
104
|
-
static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, "air-thickness", "air-label", "lang"];
|
|
105
|
+
static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, "air-thickness", "air-label", "lang"];
|
|
105
106
|
#model = newSpaceModel();
|
|
106
107
|
#mode = "now";
|
|
107
108
|
#speed = 1;
|
|
@@ -109,6 +110,9 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
109
110
|
/** The page has set a `speed` since the element came into the page: for a reader who prefers reduced motion, that is the Play that lets meteors start. */
|
|
110
111
|
#played = false;
|
|
111
112
|
#note;
|
|
113
|
+
/** The names of the stars and the constellation lines (`star-names`, `constellation-lines`), and the look of the names. */
|
|
114
|
+
#sky;
|
|
115
|
+
#skyStyle = {};
|
|
112
116
|
#airNote;
|
|
113
117
|
#gate;
|
|
114
118
|
#taken;
|
|
@@ -158,6 +162,14 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
158
162
|
this.#labelBox = root.getElementById("labels");
|
|
159
163
|
this.#note = root.getElementById("meteor-note");
|
|
160
164
|
this.#airNote = root.getElementById("air-note");
|
|
165
|
+
this.#sky = createSkyHost({
|
|
166
|
+
root,
|
|
167
|
+
attribute: (name) => this.getAttribute(name),
|
|
168
|
+
language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
|
|
169
|
+
onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-sky-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
170
|
+
loadFont: loadMichroma,
|
|
171
|
+
});
|
|
172
|
+
this.#sky.setStyle(this.#skyStyle);
|
|
161
173
|
this.#model.airThickness = readAirThickness(this.getAttribute("air-thickness"));
|
|
162
174
|
this.#applyBodyLabel();
|
|
163
175
|
setAirNote(this.#airNote, this, this.#model.airThickness);
|
|
@@ -188,6 +200,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
188
200
|
this.#tiers[layer] = width;
|
|
189
201
|
},
|
|
190
202
|
onLabels: (places) => this.#placeLabels(places),
|
|
203
|
+
onSky: (sky) => this.#sky?.frame(sky),
|
|
191
204
|
onLabelError: (error) => this.dispatchEvent(new CustomEvent("chikyu-body-label-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
192
205
|
onSelected: (place) => this.#placeChosen(place),
|
|
193
206
|
onMoving: () => this.#gate?.request(),
|
|
@@ -226,6 +239,8 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
226
239
|
this.#view = undefined;
|
|
227
240
|
this.#taken?.release();
|
|
228
241
|
this.#taken = undefined;
|
|
242
|
+
this.#sky?.dispose();
|
|
243
|
+
this.#sky = undefined;
|
|
229
244
|
}
|
|
230
245
|
attributeChangedCallback(name, _old, value) {
|
|
231
246
|
if (name === "center")
|
|
@@ -268,11 +283,15 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
268
283
|
}
|
|
269
284
|
else if (name === "meteors-label" || name === "lang") {
|
|
270
285
|
setMeteorNote(this.#note, this, this.#model.meteors.on);
|
|
271
|
-
if (name === "lang")
|
|
286
|
+
if (name === "lang") {
|
|
272
287
|
this.#applyBodyLabel();
|
|
288
|
+
this.#sky?.refresh();
|
|
289
|
+
}
|
|
273
290
|
}
|
|
274
291
|
else if (BODY_LABEL_ATTRIBUTES.includes(name))
|
|
275
292
|
this.#applyBodyLabel();
|
|
293
|
+
else if (SKY_ATTRIBUTES.includes(name))
|
|
294
|
+
this.#sky?.refresh();
|
|
276
295
|
if (name === "air-thickness" || name === "air-label" || name === "lang")
|
|
277
296
|
setAirNote(this.#airNote, this, this.#model.airThickness);
|
|
278
297
|
}
|
|
@@ -340,6 +359,18 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
340
359
|
if (value.fallbackFont)
|
|
341
360
|
this.setAttribute("body-label-fallback-font", value.fallbackFont);
|
|
342
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* The names of the brightest stars and the constellations as faint lines, laid over the sky the page draws (hoshi-stars' `sky-labels`, an optional peer loaded only when one of these is set). The plain attributes are hoshi's: `star-names` (a count of the brightest stars in view and not covered by the
|
|
364
|
+
* Earth, the Moon or the Sun; bare is 10), `star-names-magnitude` (only stars at least that bright) and `constellation-lines` (the 88 figures as lines at this strength, 0 to 1; bare is 0.16): none of them, and nothing is loaded. The figure under the pointer or touched is at full strength and shows its name. Names are in the
|
|
365
|
+
* page's language and never overlap. Nothing is redrawn at rest. `chikyu-sky-unavailable` is sent when hoshi-stars is not there. The property is the look of the names, a partial hoshi-stars `LabelStyle` (font, size, case, ring, leader and the rest).
|
|
366
|
+
*/
|
|
367
|
+
get skyStyle() {
|
|
368
|
+
return { ...this.#skyStyle };
|
|
369
|
+
}
|
|
370
|
+
set skyStyle(value) {
|
|
371
|
+
this.#skyStyle = { ...value };
|
|
372
|
+
this.#sky?.setStyle(this.#skyStyle);
|
|
373
|
+
}
|
|
343
374
|
/** Puts the name's settings and text right from the attributes (`body-label` and its family, `lang`). */
|
|
344
375
|
#applyBodyLabel() {
|
|
345
376
|
this.#model.bodyLabel.settings = readBodyLabel((name) => this.getAttribute(name));
|
|
@@ -705,6 +736,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
705
736
|
bodies: { look: this.#model.bodies || painter?.looks?.[0] || "plain", painted: this.#model.painted.bodies, moons: this.#model.painted.moons },
|
|
706
737
|
meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
|
|
707
738
|
bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
|
|
739
|
+
sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, renders: 0, lang: "" },
|
|
708
740
|
};
|
|
709
741
|
}
|
|
710
742
|
#satelliteStats() {
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
|
|
|
7
7
|
import { type ScaleMode } from "./scale.ts";
|
|
8
8
|
import type { SatelliteRef } from "../satellites/types.ts";
|
|
9
9
|
import { type RideLook } from "./ride.ts";
|
|
10
|
+
import type { SkyFrame } from "../sky/host.ts";
|
|
10
11
|
import { type SatelliteState } from "./satellite-layer.ts";
|
|
11
12
|
import { type BodyLabelState } from "../realistic/body-label.ts";
|
|
12
13
|
import { type MeteorState } from "../meteors/layer.ts";
|
|
@@ -283,6 +284,8 @@ export interface SpaceDeps {
|
|
|
283
284
|
air?: () => "full" | "light";
|
|
284
285
|
/** Where each body is on the screen, in CSS pixels in the box, or null when it is behind the camera. Called at each draw. */
|
|
285
286
|
onLabels?: (places: Record<BodyName, BodyPlace | null>) => void;
|
|
287
|
+
/** Where the sky falls on the screen at this draw, and the bodies that cover it (the names of the stars and the constellation lines are laid over it). Called at each draw. */
|
|
288
|
+
onSky?: (frame: SkyFrame) => void;
|
|
286
289
|
/** The name written on the Earth could not be made. */
|
|
287
290
|
onLabelError?: (error: unknown) => void;
|
|
288
291
|
/** Where the chosen satellite is on the screen, or null. Called at each draw while a satellite is chosen (and once when it is let go). */
|
package/dist/space/scene.js
CHANGED
|
@@ -594,6 +594,32 @@ export function createSpaceItem(model, deps) {
|
|
|
594
594
|
if (model.bodyLabel.settings && !nameOn)
|
|
595
595
|
nameOn = createBodyLabelLayer(three, earth, model.bodyLabel, { invalidate: () => deps.invalidate(), ...(deps.onLabelError ? { onError: deps.onLabelError } : {}) });
|
|
596
596
|
nameOn?.sync(camera, rideFrom ? 0 : Math.min(px.Earth, 1e5));
|
|
597
|
+
if (deps.onSky) {
|
|
598
|
+
const sky = new three.Vector3();
|
|
599
|
+
// stars are directions: a point far along the direction from the camera, in the scene's axes (x to the vernal equinox, y north, z completing the hand), seen through the camera
|
|
600
|
+
const reach = Math.max(10, Math.min(camera.far * 0.5, 1000));
|
|
601
|
+
const discs = [];
|
|
602
|
+
for (const name of ["Earth", "Moon", "Sun"]) {
|
|
603
|
+
const at = pos[name];
|
|
604
|
+
sky.set(at[0], at[1], at[2]).project(camera);
|
|
605
|
+
if (sky.z > 1 || sky.z < -1)
|
|
606
|
+
continue;
|
|
607
|
+
discs.push({ x: ((sky.x + 1) / 2) * size.width, y: ((1 - sky.y) / 2) * size.height, radius: Math.min(px[name], 1e5) });
|
|
608
|
+
}
|
|
609
|
+
deps.onSky({
|
|
610
|
+
width: size.width,
|
|
611
|
+
height: size.height,
|
|
612
|
+
discs,
|
|
613
|
+
project(rightAscension, declination, out) {
|
|
614
|
+
const r = rightAscension * RAD;
|
|
615
|
+
const d = declination * RAD;
|
|
616
|
+
sky.set(Math.cos(d) * Math.cos(r), Math.sin(d), -Math.cos(d) * Math.sin(r)).multiplyScalar(reach).add(camera.position).project(camera);
|
|
617
|
+
out.x = ((sky.x + 1) / 2) * size.width;
|
|
618
|
+
out.y = ((1 - sky.y) / 2) * size.height;
|
|
619
|
+
return sky.z > -1 && sky.z < 1;
|
|
620
|
+
},
|
|
621
|
+
});
|
|
622
|
+
}
|
|
597
623
|
if (layer && deps.onSelected) {
|
|
598
624
|
const at = model.satellites.selected ? layer.place(camera, size) : null;
|
|
599
625
|
if (at || selectedShown)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"description": "Chikyu Earth 地球 — A line-drawn globe for the web: country outlines that turn at the Earth's own rate, centred on where you are, with an optional realistic Earth from space (three.js), the Sun, Moon and planets, satellites on their orbits, and markers for any place. A web component and an SVG string.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"earth",
|
|
@@ -149,6 +149,11 @@
|
|
|
149
149
|
"import": "./dist/sheets/index.js",
|
|
150
150
|
"default": "./dist/sheets/index.js"
|
|
151
151
|
},
|
|
152
|
+
"./catalogue": {
|
|
153
|
+
"types": "./dist/catalogue/index.d.ts",
|
|
154
|
+
"import": "./dist/catalogue/index.js",
|
|
155
|
+
"default": "./dist/catalogue/index.js"
|
|
156
|
+
},
|
|
152
157
|
"./package.json": "./package.json"
|
|
153
158
|
},
|
|
154
159
|
"files": [
|
|
@@ -194,6 +199,7 @@
|
|
|
194
199
|
"d3-geo": "^3.1.1"
|
|
195
200
|
},
|
|
196
201
|
"peerDependencies": {
|
|
202
|
+
"@johnmorrisdotca/hoshi-stars": ">=0.30.0",
|
|
197
203
|
"@johnmorrisdotca/wakusei-planets": ">=0.5.0",
|
|
198
204
|
"astronomy-engine": ">=2.1.0",
|
|
199
205
|
"satellite.js": ">=6.0.0",
|
|
@@ -211,6 +217,9 @@
|
|
|
211
217
|
},
|
|
212
218
|
"@johnmorrisdotca/wakusei-planets": {
|
|
213
219
|
"optional": true
|
|
220
|
+
},
|
|
221
|
+
"@johnmorrisdotca/hoshi-stars": {
|
|
222
|
+
"optional": true
|
|
214
223
|
}
|
|
215
224
|
},
|
|
216
225
|
"devDependencies": {
|
|
@@ -220,6 +229,7 @@
|
|
|
220
229
|
"@angular/platform-browser": "^22.2.4",
|
|
221
230
|
"@eslint/js": "^9.0.0",
|
|
222
231
|
"@johnmorrisdotca/hata": "^1.8.0",
|
|
232
|
+
"@johnmorrisdotca/hoshi-stars": "^0.30.0",
|
|
223
233
|
"@johnmorrisdotca/kuni": "^1.5.0",
|
|
224
234
|
"@johnmorrisdotca/wakusei-planets": "^0.5.0",
|
|
225
235
|
"@playwright/test": "1.64.0",
|