@johnmorrisdotca/wakusei-planets 0.32.0 → 0.34.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/NOTICE.md +15 -1
  3. package/README.md +11 -5
  4. package/dist/bodies/all.d.ts +1 -0
  5. package/dist/bodies/all.js +1 -0
  6. package/dist/bodies/minor.d.ts +1 -0
  7. package/dist/bodies/minor.js +16 -0
  8. package/dist/data/minor.d.ts +3 -0
  9. package/dist/data/minor.js +7 -0
  10. package/dist/data/tables.d.ts +4 -2
  11. package/dist/data/tables.js +1 -1
  12. package/dist/element.d.ts +10 -1
  13. package/dist/element.js +36 -6
  14. package/dist/embed.d.ts +1 -1
  15. package/dist/embed.js +3 -3
  16. package/dist/ephemeris.d.ts +7 -7
  17. package/dist/ephemeris.js +36 -13
  18. package/dist/facts.d.ts +28 -4
  19. package/dist/facts.js +24 -2
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +1 -1
  22. package/dist/nearest.js +6 -4
  23. package/dist/scene/body.d.ts +13 -2
  24. package/dist/scene/body.js +35 -0
  25. package/dist/scene/name-label.d.ts +116 -0
  26. package/dist/scene/name-label.js +232 -0
  27. package/dist/scene/painter.d.ts +29 -0
  28. package/dist/scene/painter.js +36 -0
  29. package/dist/scene/textures.d.ts +2 -2
  30. package/dist/space/arrows.d.ts +29 -3
  31. package/dist/space/arrows.js +38 -6
  32. package/dist/space/bodies.d.ts +6 -6
  33. package/dist/space/bodies.js +6 -6
  34. package/dist/space/element.d.ts +20 -0
  35. package/dist/space/element.js +44 -4
  36. package/dist/space/frame.d.ts +28 -3
  37. package/dist/space/frame.js +40 -4
  38. package/dist/space/index.d.ts +2 -2
  39. package/dist/space/index.js +2 -2
  40. package/dist/space/scale.d.ts +4 -4
  41. package/dist/space/scale.js +8 -2
  42. package/dist/space/scene.d.ts +17 -3
  43. package/dist/space/scene.js +36 -17
  44. package/dist/stops.d.ts +1 -1
  45. package/dist/stops.js +4 -1
  46. package/dist/tables/all.d.ts +1 -0
  47. package/dist/tables/all.js +1 -0
  48. package/dist/tables/lazy.d.ts +5 -0
  49. package/dist/tables/lazy.js +12 -0
  50. package/dist/tables/minor.d.ts +1 -0
  51. package/dist/tables/minor.js +317 -0
  52. package/dist/textures/vesta-1024.webp +0 -0
  53. package/dist/textures/vesta-512.webp +0 -0
  54. package/dist/version.d.ts +1 -1
  55. package/dist/version.js +1 -1
  56. package/package.json +12 -2
@@ -0,0 +1,232 @@
1
+ // A body's name written on its own globe (kazoku-ui's shared body label), fitted to this package's bodies: the band is a child of the body's mesh, so it turns with the body, in the frame
2
+ // the bodies' shaders use (longitude 0 along the mesh's +z, east along +x, the pole +y); and it is lit by the same direction the body is, through its own small shader, because the
3
+ // bodies have no three.js lights (each is lit by the `uLight` of its own material). Nothing here draws: the host calls `update` before each draw and `set` when a setting changed.
4
+ import { BODY_LABEL_FONT, createBodyLabel, loadBodyLabelFont } from "@johnmorrisdotca/kazoku-ui/body-label";
5
+ /** The family's standard attribute names, as `readNameLabel` reads them. */
6
+ export const NAME_LABEL_ATTRIBUTES = ["body-label", "body-label-strength", "body-label-repeat", "body-label-latitude", "body-label-facing", "body-label-font", "body-label-fallback-font"];
7
+ const LOOKS = ["painted", "etched", "outline", "burned"];
8
+ const REPEATS = ["once", "both", "around"];
9
+ /**
10
+ * The label the family's attributes ask for (`body-label="painted"` and the six beside it), or `null` when `body-label` is absent or not a look.
11
+ *
12
+ * @param el - Anything with `getAttribute` and `hasAttribute`: the element.
13
+ * @returns The options, or `null` for no label.
14
+ *
15
+ * @example
16
+ * ```ts no-run
17
+ * import { readNameLabel } from "@johnmorrisdotca/wakusei-planets/painter";
18
+ *
19
+ * const el = document.querySelector("wakusei-body")!;
20
+ * el.setAttribute("body-label", "etched");
21
+ * console.log(readNameLabel(el)?.look);
22
+ * ```
23
+ */
24
+ export function readNameLabel(el) {
25
+ const look = el.getAttribute("body-label");
26
+ if (look === null || !LOOKS.includes(look))
27
+ return null;
28
+ const out = { look: look };
29
+ const strength = Number(el.getAttribute("body-label-strength"));
30
+ if (el.getAttribute("body-label-strength") !== null && Number.isFinite(strength))
31
+ out.strength = Math.max(0, Math.min(1, strength));
32
+ const repeat = el.getAttribute("body-label-repeat");
33
+ if (repeat !== null && REPEATS.includes(repeat))
34
+ out.repeat = repeat;
35
+ const latitude = Number(el.getAttribute("body-label-latitude"));
36
+ if (el.getAttribute("body-label-latitude") !== null && Number.isFinite(latitude))
37
+ out.latitude = latitude;
38
+ if (el.hasAttribute("body-label-facing") && el.getAttribute("body-label-facing") !== "off" && el.getAttribute("body-label-facing") !== "false")
39
+ out.facing = true;
40
+ const font = el.getAttribute("body-label-font");
41
+ if (font !== null && font.trim() !== "")
42
+ out.font = font.trim();
43
+ const fallback = el.getAttribute("body-label-fallback-font");
44
+ if (fallback !== null && fallback.trim() !== "")
45
+ out.fallbackFont = fallback.trim();
46
+ return out;
47
+ }
48
+ /**
49
+ * The text written for a body: its English name in capitals (the family's look), or its Japanese name as it is.
50
+ *
51
+ * @param name - The body's names, as `BODIES[id].name` holds them.
52
+ * @param lang - `en` (the default) or `ja`.
53
+ * @returns The text to write.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { BODIES } from "@johnmorrisdotca/wakusei-planets";
58
+ * import { nameLabelText } from "@johnmorrisdotca/wakusei-planets/painter";
59
+ *
60
+ * console.log(nameLabelText(BODIES.earth.name, "en"), nameLabelText(BODIES.earth.name, "ja"));
61
+ * ```
62
+ */
63
+ export function nameLabelText(name, lang = "en") {
64
+ return lang === "ja" ? name.ja : name.en.toUpperCase();
65
+ }
66
+ /** One string that changes whenever the label would be made differently (the text and every setting): for a host that keeps a still for each state. */
67
+ export function nameLabelKey(text, options) {
68
+ if (!options)
69
+ return "";
70
+ const o = { ...DEFAULTS, ...options };
71
+ return `${text}|${o.look}|${o.strength}|${o.repeat}|${o.latitude}|${o.facing}|${o.font}|${o.fallbackFont}|${o.size}|${o.minRadiusPx}`;
72
+ }
73
+ const DEFAULTS = { strength: 0.5, repeat: "once", latitude: 0, facing: false, font: BODY_LABEL_FONT, fallbackFont: "", size: "medium", minRadiusPx: 24 };
74
+ const hasLabelParts = (T) => {
75
+ const parts = T;
76
+ return typeof parts.CanvasTexture === "function" && typeof parts.SRGBColorSpace === "string" && typeof parts.NormalBlending === "number";
77
+ };
78
+ let warned = false;
79
+ /** The name is drawn to a canvas: without one (Node, a worker with no `OffscreenCanvas`) there is no label and nothing to draw. */
80
+ const canDraw = () => typeof document !== "undefined" || typeof OffscreenCanvas !== "undefined";
81
+ const LABEL_VERTEX = /* glsl */ `
82
+ varying vec2 vUv;
83
+ varying vec3 vN;
84
+ void main() {
85
+ vUv = uv;
86
+ vN = normalize(transpose(inverse(mat3(modelMatrix))) * normal);
87
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
88
+ }`;
89
+ // lit as the bodies are: the Sun's direction in the scene's axes, a little wrap past the terminator and a little ambient on the night side, so a name on the night side is dark too
90
+ const LABEL_FRAGMENT = /* glsl */ `
91
+ uniform sampler2D uMap;
92
+ uniform vec3 uLight;
93
+ uniform float uOpacity;
94
+ uniform float uAmbient;
95
+ uniform float uWrap;
96
+ varying vec2 vUv;
97
+ varying vec3 vN;
98
+ void main() {
99
+ vec4 c = texture2D(uMap, vUv);
100
+ float d = dot(normalize(vN), uLight);
101
+ float lit = uAmbient + (1.0 - uAmbient) * clamp((d + uWrap) / (1.0 + uWrap), 0.0, 1.0);
102
+ gl_FragColor = vec4(c.rgb * lit, c.a * uOpacity);
103
+ #include <colorspace_fragment>
104
+ }`;
105
+ /** The three.js the shared label is handed: its own, but with a material lit by the bodies' light instead of three's Lambert (the scenes here have no three.js lights). */
106
+ function litThree(T, emissive) {
107
+ const made = [];
108
+ class LitLabelMaterial extends T.ShaderMaterial {
109
+ constructor(parameters) {
110
+ const { map, ...rest } = parameters;
111
+ super({
112
+ ...rest,
113
+ vertexShader: LABEL_VERTEX,
114
+ fragmentShader: LABEL_FRAGMENT,
115
+ uniforms: { uMap: { value: map }, uLight: { value: new T.Vector3(0, 0, 1) }, uOpacity: { value: 1 }, uAmbient: { value: emissive ? 1 : 0.06 }, uWrap: { value: 0.08 } },
116
+ });
117
+ made.push(this);
118
+ }
119
+ }
120
+ return { ...T, MeshLambertMaterial: LitLabelMaterial, made };
121
+ }
122
+ const FAR_EYE = { getWorldPosition: (v) => v.set(0, 0, 1e6) };
123
+ let fontLoad;
124
+ let fontUrl;
125
+ /**
126
+ * Where Michroma is fetched from, for a page whose bundler does not carry kazoku-ui's font file along with its module (the label looks for it next to the module, `fonts/Michroma-Regular.ttf`). Call it before the
127
+ * first name is written. A page that sets `body-label-font` to a font of its own needs nothing here.
128
+ *
129
+ * @param url - The address of `Michroma-Regular.ttf`, with its `OFL.txt` beside it.
130
+ *
131
+ * @example
132
+ * ```ts no-run
133
+ * import { setBodyLabelFontUrl } from "@johnmorrisdotca/wakusei-planets/painter";
134
+ *
135
+ * setBodyLabelFontUrl("/fonts/Michroma-Regular.ttf");
136
+ * ```
137
+ */
138
+ export function setBodyLabelFontUrl(url) {
139
+ fontUrl = url;
140
+ fontLoad = undefined;
141
+ }
142
+ /** Michroma, fetched once from kazoku-ui's own copy (or `setBodyLabelFontUrl`'s), the first time a label in it is made. A fetch that fails leaves the page's sans, and is not tried again. */
143
+ const ensureFont = (font) => (font === BODY_LABEL_FONT && canDraw() ? (fontLoad ??= (fontUrl === undefined ? loadBodyLabelFont() : loadBodyLabelFont(fontUrl)).catch(() => BODY_LABEL_FONT)) : Promise.resolve());
144
+ /**
145
+ * Make a body's name label. The group is empty until the font is in (at once when it is already loaded); `onReady` is called when the name is drawn, so the host can draw its view again.
146
+ *
147
+ * @param T - The three.js module the bodies use. Without `CanvasTexture`, `SRGBColorSpace` and `NormalBlending` there is no label, and a warning once.
148
+ * @param text - The name as it is written.
149
+ * @param options - The look and the rest.
150
+ * @param emissive - The body glows (the Sun): the name is lit fully, from no direction.
151
+ * @param onReady - Called when the name is drawn, and again when a new font is in.
152
+ */
153
+ export function createNameLabel(T, text, options, emissive, onReady) {
154
+ const group = new T.Group();
155
+ group.name = "name-label";
156
+ // the shared label's frame has longitude 0 along +x and east towards -z; the bodies' has longitude 0 along +z and east along +x: a quarter turn about the pole maps one onto the other
157
+ group.rotation.y = -Math.PI / 2;
158
+ let label;
159
+ let materials = [];
160
+ let wanted = { text, options: { ...DEFAULTS, ...withoutUndefined(options) } };
161
+ let disposed = false;
162
+ let ready = false;
163
+ const light = new T.Vector3(0, 0, 1);
164
+ const able = hasLabelParts(T) && canDraw();
165
+ if (!able && !warned && canDraw()) {
166
+ warned = true;
167
+ console.warn("wakusei-planets: the three.js handed over lacks CanvasTexture, SRGBColorSpace or NormalBlending, so a name cannot be written on a body");
168
+ }
169
+ const make = () => {
170
+ if (disposed || label !== undefined || !able)
171
+ return;
172
+ const lit = litThree(T, emissive);
173
+ label = createBodyLabel(lit, { text: wanted.text, ...wanted.options, radius: 1 });
174
+ materials = lit.made;
175
+ group.add(label.object);
176
+ void label.ready.then(() => {
177
+ if (disposed)
178
+ return;
179
+ ready = true;
180
+ onReady();
181
+ });
182
+ };
183
+ void ensureFont(wanted.options.font).then(() => {
184
+ if (!disposed)
185
+ make();
186
+ });
187
+ return {
188
+ object: group,
189
+ get ready() {
190
+ return ready;
191
+ },
192
+ update(camera, radiusPx, toLight) {
193
+ if (label === undefined)
194
+ return false;
195
+ light.set(toLight[0], toLight[1], toLight[2]);
196
+ for (const m of materials) {
197
+ const u = m.uniforms;
198
+ u.uLight.value.copy(light);
199
+ u.uOpacity.value = m.opacity;
200
+ }
201
+ return label.update((camera ?? FAR_EYE), radiusPx);
202
+ },
203
+ set(nextText, next) {
204
+ wanted = { text: nextText, options: { ...DEFAULTS, ...withoutUndefined(next) } };
205
+ if (label === undefined)
206
+ return;
207
+ const fontChanged = wanted.options.font !== label.options.font;
208
+ label.set({ text: wanted.text, ...wanted.options });
209
+ if (fontChanged)
210
+ void ensureFont(wanted.options.font).then(() => {
211
+ // the shared label repaints only when a setting changed: the new font arriving after the set is told by setting the font again
212
+ if (!disposed && label !== undefined) {
213
+ label.set({ font: "" });
214
+ label.set({ font: wanted.options.font });
215
+ onReady();
216
+ }
217
+ });
218
+ },
219
+ dispose() {
220
+ disposed = true;
221
+ if (label !== undefined) {
222
+ group.remove(label.object);
223
+ label.dispose();
224
+ label = undefined;
225
+ }
226
+ materials = [];
227
+ },
228
+ };
229
+ }
230
+ function withoutUndefined(value) {
231
+ return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined));
232
+ }
@@ -5,7 +5,9 @@ import { type Vec3 } from "../vec.ts";
5
5
  import { type DetailStats } from "./detail.ts";
6
6
  import { type TileLevel } from "./tiles.ts";
7
7
  import { moonOffset, orientation } from "./orient.ts";
8
+ import { type NameLabelOptions } from "./name-label.ts";
8
9
  export { moonOffset, orientation };
10
+ export { nameLabelText, readNameLabel, setBodyLabelFontUrl, type NameLabelOptions } from "./name-label.ts";
9
11
  /**
10
12
  * The looks the painter draws: `realistic` (shaded from the body's real colours and features) and `painted` (a public-domain surface map, with the shaded look until it arrives).
11
13
  *
@@ -54,6 +56,25 @@ export interface PaintContext {
54
56
  maxTexture?: number;
55
57
  /** Told when the finer map tiles' levels for this body are known (`undefined` when it has none), so a view can raise its zoom range. Only called for a painter that has a tile set and a view in `PaintInfo`. */
56
58
  onLevels?(levels: readonly TileLevel[] | undefined): void;
59
+ /** The body's name written on its globe (see `PaintLabel`), or none. `setLabel` on the painting changes it later. */
60
+ label?: PaintLabel | null;
61
+ }
62
+ /**
63
+ * The name on a body the painter makes: the family's `NameLabelOptions`, with the language the name is written in (`en`, in capitals, by default) or a `text` of your own instead of the body's name.
64
+ *
65
+ * @example
66
+ * ```ts no-run
67
+ * import type { PaintLabel } from "@johnmorrisdotca/wakusei-planets/painter";
68
+ *
69
+ * const label: PaintLabel = { look: "painted", lang: "ja" };
70
+ * console.log(label.lang);
71
+ * ```
72
+ */
73
+ export interface PaintLabel extends NameLabelOptions {
74
+ /** The language of the name: `en` (capitals) or `ja`. Default `en`. */
75
+ lang?: "en" | "ja";
76
+ /** Written instead of the body's name. */
77
+ text?: string;
57
78
  }
58
79
  /**
59
80
  * The camera that draws a body and the size of its view, so the painter can tell which part of the body's surface is in view and lay finer map tiles over it. The camera's world and projection matrices must be
@@ -119,6 +140,14 @@ export interface Painting {
119
140
  update(info: PaintInfo): void;
120
141
  /** What the window of finer map tiles on this body is doing, or `undefined` for a body with none (a glowing one, one with no painted map, or a painter with no tile set). */
121
142
  readonly tiles?: DetailStats;
143
+ /** Write the body's name on its globe, change how, or take it off (`null`). The name is drawn when the font is in, and `context.invalidate` is called then. */
144
+ setLabel(label: PaintLabel | null): void;
145
+ /** The name on the globe now: whether one is drawn (made and big enough on the screen at the last `update`), the text, and the group's turn about the pole in radians (for `facing`). */
146
+ readonly label: {
147
+ shown: boolean;
148
+ text: string;
149
+ turn: number;
150
+ } | null;
122
151
  dispose(): void;
123
152
  }
124
153
  /**
@@ -11,7 +11,9 @@ import { detailOf, lookOf } from "./look.js";
11
11
  import { seenRegion } from "./tiles.js";
12
12
  import { moonOffset, orientation } from "./orient.js";
13
13
  import { ringStrip } from "./rings.js";
14
+ import { createNameLabel, nameLabelText } from "./name-label.js";
14
15
  export { moonOffset, orientation };
16
+ export { nameLabelText, readNameLabel, setBodyLabelFontUrl } from "./name-label.js";
15
17
  /**
16
18
  * The looks the painter draws: `realistic` (shaded from the body's real colours and features) and `painted` (a public-domain surface map, with the shaded look until it arrives).
17
19
  *
@@ -336,9 +338,38 @@ function paint(T, id, context, bases) {
336
338
  const scaleZ = axes ? axes[0] / facts.radiusKm : 1;
337
339
  const light = new T.Vector3();
338
340
  const poleVec = new T.Vector3();
341
+ // the name on the globe: a child of the mesh, so it turns with the body; made when asked, drawn once its font is in
342
+ let label;
343
+ let labelText = "";
344
+ let labelShown = false;
345
+ const setLabel = (next) => {
346
+ if (next === null || next === undefined || gone) {
347
+ if (label !== undefined) {
348
+ mesh.remove(label.object);
349
+ label.dispose();
350
+ label = undefined;
351
+ labelShown = false;
352
+ }
353
+ return;
354
+ }
355
+ const { lang, text, ...options } = next;
356
+ labelText = text ?? nameLabelText(facts.name, lang ?? "en");
357
+ if (label === undefined) {
358
+ label = createNameLabel(T, labelText, options, look.emissive === true, redraw);
359
+ mesh.add(label.object);
360
+ }
361
+ else
362
+ label.set(labelText, options);
363
+ };
364
+ if (context.label)
365
+ setLabel(context.label);
339
366
  return {
340
367
  object: group,
341
368
  ...(look.emissive === true ? { billboard: true } : {}),
369
+ setLabel,
370
+ get label() {
371
+ return label === undefined ? null : { shown: labelShown, text: labelText, turn: label.object.children[0] !== undefined ? label.object.children[0].rotation.y : 0 };
372
+ },
342
373
  get tiles() {
343
374
  return detail?.stats;
344
375
  },
@@ -377,9 +408,14 @@ function paint(T, id, context, bases) {
377
408
  ringMaterial.uniforms.uScale.value = scale;
378
409
  }
379
410
  keepSized(info.radiusPx);
411
+ if (label !== undefined) {
412
+ label.update(info.view?.camera, info.radiusPx, info.toSun);
413
+ labelShown = label.object.children[0] !== undefined && label.object.children[0].visible;
414
+ }
380
415
  },
381
416
  dispose() {
382
417
  gone = true;
418
+ setLabel(null);
383
419
  if (windowUniforms !== undefined) {
384
420
  windowUniforms.uDetailOn.value = 0;
385
421
  windowUniforms.uDetail.value = null;
@@ -11,7 +11,7 @@ import { type BodyMapSource } from "../door/map.ts";
11
11
  * console.log(TEXTURE_BASE);
12
12
  * ```
13
13
  */
14
- export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.32.0/dist/textures/";
14
+ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.34.0/dist/textures/";
15
15
  /**
16
16
  * Where the sharpest surface pictures are: the files of this exact version in the repository, on jsDelivr's GitHub address. The npm package holds only the two smaller widths, so a page that
17
17
  * never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
@@ -23,7 +23,7 @@ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdot
23
23
  * console.log(TEXTURE_FAR_BASE);
24
24
  * ```
25
25
  */
26
- export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.32.0/textures/";
26
+ export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.34.0/textures/";
27
27
  /**
28
28
  * Where the finer map tiles are by default: the demo site's `tiles/` folder (GitHub Pages sends `access-control-allow-origin: *`). The tiles are made by `scripts/make-body-tiles.py` and are in no package and no repository:
29
29
  * a page that serves its own gives the folder in the `tiles` attribute, and `tiles="off"` turns them off. A page that sets `texture-base` (it serves its own pictures) has none unless it says where they are.
@@ -1,6 +1,6 @@
1
1
  import { type Vec3 } from "../vec.ts";
2
2
  /**
3
- * How many arrowheads an orbit line carries.
3
+ * How many arrowheads an orbit line carries by default: two are enough to show which way a body goes round.
4
4
  *
5
5
  * @example
6
6
  * ```ts
@@ -9,7 +9,33 @@ import { type Vec3 } from "../vec.ts";
9
9
  * console.log(ARROWS_PER_ORBIT);
10
10
  * ```
11
11
  */
12
- export declare const ARROWS_PER_ORBIT = 6;
12
+ export declare const ARROWS_PER_ORBIT = 2;
13
+ /**
14
+ * The most arrowheads an orbit line may carry, whatever a page asks for.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { MAX_ARROWS_PER_ORBIT } from "@johnmorrisdotca/wakusei-planets/space";
19
+ *
20
+ * console.log(MAX_ARROWS_PER_ORBIT);
21
+ * ```
22
+ */
23
+ export declare const MAX_ARROWS_PER_ORBIT = 4;
24
+ /**
25
+ * Reads the number of arrowheads a page asks for (the attribute `arrows` or the property): a whole number from 0 (none) to `MAX_ARROWS_PER_ORBIT`; more is four, less is none, and anything that is not a number is
26
+ * the default, `ARROWS_PER_ORBIT`.
27
+ *
28
+ * @param value - A number, the text of an attribute, or nothing.
29
+ * @returns How many arrowheads to draw on each orbit line.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import { arrowCount } from "@johnmorrisdotca/wakusei-planets/space";
34
+ *
35
+ * console.log(arrowCount(undefined), arrowCount("3"), arrowCount(9), arrowCount("-1"), arrowCount("many"));
36
+ * ```
37
+ */
38
+ export declare function arrowCount(value: unknown): number;
13
39
  /**
14
40
  * One arrowhead on an orbit line: where its tip is and the way it points, the way the body goes along the line.
15
41
  *
@@ -31,7 +57,7 @@ export interface OrbitArrow {
31
57
  * They show the real way the body travels, which is the same whichever way the clock runs.
32
58
  *
33
59
  * @param line - The orbit line, `count + 1` points whose last is near the first.
34
- * @param arrows - How many arrowheads (`ARROWS_PER_ORBIT` by default).
60
+ * @param arrows - How many arrowheads (`ARROWS_PER_ORBIT`, two, by default; at most `MAX_ARROWS_PER_ORBIT`).
35
61
  * @returns The arrows, each at a point of the line.
36
62
  *
37
63
  * @example
@@ -1,7 +1,7 @@
1
1
  // The little arrows on an orbit line that show which way the body goes, and the shapes the help mode draws round the body looked at. Pure: lines in, places and directions out; the scene turns them into lines on the screen.
2
2
  import { add, cross, dot, RAD, scale, unit } from "../vec.js";
3
3
  /**
4
- * How many arrowheads an orbit line carries.
4
+ * How many arrowheads an orbit line carries by default: two are enough to show which way a body goes round.
5
5
  *
6
6
  * @example
7
7
  * ```ts
@@ -10,14 +10,45 @@ import { add, cross, dot, RAD, scale, unit } from "../vec.js";
10
10
  * console.log(ARROWS_PER_ORBIT);
11
11
  * ```
12
12
  */
13
- export const ARROWS_PER_ORBIT = 6;
13
+ export const ARROWS_PER_ORBIT = 2;
14
+ /**
15
+ * The most arrowheads an orbit line may carry, whatever a page asks for.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { MAX_ARROWS_PER_ORBIT } from "@johnmorrisdotca/wakusei-planets/space";
20
+ *
21
+ * console.log(MAX_ARROWS_PER_ORBIT);
22
+ * ```
23
+ */
24
+ export const MAX_ARROWS_PER_ORBIT = 4;
25
+ /**
26
+ * Reads the number of arrowheads a page asks for (the attribute `arrows` or the property): a whole number from 0 (none) to `MAX_ARROWS_PER_ORBIT`; more is four, less is none, and anything that is not a number is
27
+ * the default, `ARROWS_PER_ORBIT`.
28
+ *
29
+ * @param value - A number, the text of an attribute, or nothing.
30
+ * @returns How many arrowheads to draw on each orbit line.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { arrowCount } from "@johnmorrisdotca/wakusei-planets/space";
35
+ *
36
+ * console.log(arrowCount(undefined), arrowCount("3"), arrowCount(9), arrowCount("-1"), arrowCount("many"));
37
+ * ```
38
+ */
39
+ export function arrowCount(value) {
40
+ const n = typeof value === "string" && value.trim() !== "" ? Number(value) : value;
41
+ if (typeof n !== "number" || !Number.isFinite(n))
42
+ return ARROWS_PER_ORBIT;
43
+ return Math.min(MAX_ARROWS_PER_ORBIT, Math.max(0, Math.round(n)));
44
+ }
14
45
  /**
15
46
  * Where the arrowheads go on an orbit line, and which way each points. The line is the points of `planetOrbit` as the view places them: they run from where the body is now once round in the order the body
16
47
  * goes, so the direction of each arrow is the line's own direction there, from the point before to the point after. The arrows are spread evenly round the line and stay clear of the body, which is at its first point.
17
48
  * They show the real way the body travels, which is the same whichever way the clock runs.
18
49
  *
19
50
  * @param line - The orbit line, `count + 1` points whose last is near the first.
20
- * @param arrows - How many arrowheads (`ARROWS_PER_ORBIT` by default).
51
+ * @param arrows - How many arrowheads (`ARROWS_PER_ORBIT`, two, by default; at most `MAX_ARROWS_PER_ORBIT`).
21
52
  * @returns The arrows, each at a point of the line.
22
53
  *
23
54
  * @example
@@ -31,11 +62,12 @@ export const ARROWS_PER_ORBIT = 6;
31
62
  export function arrowSites(line, arrows = ARROWS_PER_ORBIT) {
32
63
  const n = line.length - 1;
33
64
  const out = [];
34
- if (n < 4 || arrows < 1)
65
+ const count = arrowCount(arrows);
66
+ if (n < 4 || count < 1)
35
67
  return out;
36
- for (let k = 0; k < arrows; k += 1) {
68
+ for (let k = 0; k < count; k += 1) {
37
69
  // k + 1/2 of the way round in equal steps: never at the body (the first point) or at the join
38
- const i = Math.min(n - 1, Math.max(1, Math.round(((k + 0.5) / arrows) * n)));
70
+ const i = Math.min(n - 1, Math.max(1, Math.round(((k + 0.5) / count) * n)));
39
71
  const before = line[i - 1];
40
72
  const after = line[i + 1];
41
73
  const direction = unit([after[0] - before[0], after[1] - before[1], after[2] - before[2]]);
@@ -1,6 +1,6 @@
1
1
  import { type BodyId, type HostId } from "../facts.ts";
2
2
  /**
3
- * What a body is: the Sun, one of the eight planets, a dwarf planet (Pluto among them) or a moon.
3
+ * What a body is: the Sun, one of the eight planets, a dwarf planet (Pluto among them), a moon, or a minor body: an `asteroid` (Vesta, Pallas), a `centaur` (Chiron, Pholus) or a `comet` (Halley).
4
4
  *
5
5
  * @example
6
6
  * ```ts
@@ -10,10 +10,10 @@ import { type BodyId, type HostId } from "../facts.ts";
10
10
  * console.log(kind);
11
11
  * ```
12
12
  */
13
- export type SpaceKind = "star" | "planet" | "dwarf-planet" | "moon";
13
+ export type SpaceKind = "star" | "planet" | "dwarf-planet" | "moon" | "asteroid" | "centaur" | "comet";
14
14
  /**
15
- * Every body the package knows, in the order a hopper goes: the Sun, then each planet and dwarf planet from the Sun outwards, each followed by its moons nearest first (Mercury, Venus, the Earth and the
16
- * Moon, Mars, Phobos and Deimos, Ceres, Jupiter and its four large moons, and on to Sedna).
15
+ * Every body the package knows, in the order a hopper goes: the Sun, then each planet, dwarf planet and minor body from the Sun outwards, each followed by its moons nearest first (Mercury, Venus, the Earth and the
16
+ * Moon, Mars, Phobos and Deimos, Vesta, Ceres, Pallas, Jupiter and its four large moons, and on to Sedna).
17
17
  *
18
18
  * @example
19
19
  * ```ts
@@ -27,13 +27,13 @@ export declare const HOP_ORDER: readonly BodyId[];
27
27
  * What kind of body a name is.
28
28
  *
29
29
  * @param id - A body's name.
30
- * @returns `star` for the Sun, `planet` for the eight planets, `dwarf-planet` for Pluto and the others, or `moon`.
30
+ * @returns `star` for the Sun, `planet` for the eight planets, `dwarf-planet` for Pluto and the others, `moon`, or `asteroid`, `centaur` or `comet` for a minor body.
31
31
  *
32
32
  * @example
33
33
  * ```ts
34
34
  * import { bodyKindOf } from "@johnmorrisdotca/wakusei-planets/space";
35
35
  *
36
- * console.log(bodyKindOf("ceres"), bodyKindOf("moon"));
36
+ * console.log(bodyKindOf("ceres"), bodyKindOf("moon"), bodyKindOf("halley"));
37
37
  * ```
38
38
  */
39
39
  export declare function bodyKindOf(id: BodyId): SpaceKind;
@@ -1,10 +1,10 @@
1
1
  // Which bodies the space view can put at the middle of its view, and in what order a reader hops from one to the next. Pure: names in, names out.
2
2
  import { BODIES, MOONS_OF } from "../facts.js";
3
- /** Planets, then dwarf planets, ordered by the distance of their orbits from the Sun, each followed by its moons nearest first. */
4
- const SUN_ORDER = ["mercury", "venus", "earth", "mars", "ceres", "jupiter", "saturn", "uranus", "neptune", "pluto", "orcus", "haumea", "quaoar", "makemake", "gonggong", "eris", "sedna"];
3
+ /** Planets, dwarf planets and minor bodies, ordered by the size of their orbits (the semi-major axis), each followed by its moons nearest first. */
4
+ const SUN_ORDER = ["mercury", "venus", "earth", "mars", "vesta", "ceres", "pallas", "jupiter", "saturn", "chiron", "halley", "uranus", "pholus", "neptune", "pluto", "orcus", "haumea", "quaoar", "makemake", "gonggong", "eris", "sedna"];
5
5
  /**
6
- * Every body the package knows, in the order a hopper goes: the Sun, then each planet and dwarf planet from the Sun outwards, each followed by its moons nearest first (Mercury, Venus, the Earth and the
7
- * Moon, Mars, Phobos and Deimos, Ceres, Jupiter and its four large moons, and on to Sedna).
6
+ * Every body the package knows, in the order a hopper goes: the Sun, then each planet, dwarf planet and minor body from the Sun outwards, each followed by its moons nearest first (Mercury, Venus, the Earth and the
7
+ * Moon, Mars, Phobos and Deimos, Vesta, Ceres, Pallas, Jupiter and its four large moons, and on to Sedna).
8
8
  *
9
9
  * @example
10
10
  * ```ts
@@ -18,13 +18,13 @@ export const HOP_ORDER = ["sun", ...SUN_ORDER.flatMap((id) => [id, ...(MOONS_OF[
18
18
  * What kind of body a name is.
19
19
  *
20
20
  * @param id - A body's name.
21
- * @returns `star` for the Sun, `planet` for the eight planets, `dwarf-planet` for Pluto and the others, or `moon`.
21
+ * @returns `star` for the Sun, `planet` for the eight planets, `dwarf-planet` for Pluto and the others, `moon`, or `asteroid`, `centaur` or `comet` for a minor body.
22
22
  *
23
23
  * @example
24
24
  * ```ts
25
25
  * import { bodyKindOf } from "@johnmorrisdotca/wakusei-planets/space";
26
26
  *
27
- * console.log(bodyKindOf("ceres"), bodyKindOf("moon"));
27
+ * console.log(bodyKindOf("ceres"), bodyKindOf("moon"), bodyKindOf("halley"));
28
28
  * ```
29
29
  */
30
30
  export function bodyKindOf(id) {
@@ -1,6 +1,8 @@
1
1
  import { type ViewController } from "@johnmorrisdotca/kazoku-ui/view-controls";
2
+ import "../tables/minor.ts";
2
3
  import { type BodyId } from "../facts.ts";
3
4
  import { type SpaceKind } from "./bodies.ts";
5
+ import { type NameLabelOptions } from "../scene/name-label.ts";
4
6
  import type { Credit, DataSource } from "../data-door.ts";
5
7
  import { type DoorHost } from "../door/host.ts";
6
8
  import { setThreeLoader } from "../scene/shared.ts";
@@ -127,6 +129,12 @@ export declare class WakuseiSpace extends HTMLElement {
127
129
  connectedCallback(): void;
128
130
  disconnectedCallback(): void;
129
131
  attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
132
+ /**
133
+ * The name written on each body's globe (`{ look: "painted", strength: 0.5, repeat: "once", latitude: 0, facing: false, font: "Michroma", fallbackFont: "" }`), or `null` for none. Set, it takes the place of the
134
+ * `body-label` attributes; set to `undefined` the attributes are read again. The text is each body's own name in the element's `lang` (capitals in English). A body too small on the screen (24 CSS pixels of radius by default) carries none.
135
+ */
136
+ get bodyLabel(): NameLabelOptions | null;
137
+ set bodyLabel(value: NameLabelOptions | null | undefined);
130
138
  /** The home place the camera starts above, as longitude and latitude in degrees. */
131
139
  get centre(): {
132
140
  lon: number;
@@ -152,6 +160,9 @@ export declare class WakuseiSpace extends HTMLElement {
152
160
  set labels(value: boolean);
153
161
  get orbits(): boolean;
154
162
  set orbits(value: boolean);
163
+ /** How many small arrowheads each orbit line carries to show which way the body goes: 2 by default, at most 4, 0 for none (the attribute `arrows` says the same). Anything else is made a whole number in that range. */
164
+ get arrows(): number;
165
+ set arrows(value: number);
155
166
  /**
156
167
  * Help mode (the `help` attribute; off by default): on the body looked at, a line along its axis and a curved arrow round it showing which way it spins, by the right-hand rule about the axis it really turns about, so it is
157
168
  * right for Venus and Uranus, which turn backwards, and for Uranus on its side. It is about learning, so the arrow is drawn over the body.
@@ -321,6 +332,15 @@ export declare class WakuseiSpace extends HTMLElement {
321
332
  retrograde: boolean;
322
333
  arcTurn: [number, number, number];
323
334
  } | null;
335
+ /** The names on the globes at the last draw: how many are drawn (made, their font in, and the body big enough on the screen), and the one on the body looked at (its text and its turn about the pole in radians), or null. */
336
+ bodyLabels: {
337
+ count: number;
338
+ focus: {
339
+ shown: boolean;
340
+ text: string;
341
+ turn: number;
342
+ } | null;
343
+ };
324
344
  };
325
345
  /** Where a body is on the screen now: its centre and radius in CSS pixels in the element, or `null` when it is behind the camera or not drawn. */
326
346
  placeOf(id: BodyId): BodyPlace | null;