@johnmorrisdotca/wakusei-planets 0.37.1 → 0.38.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 +19 -0
- package/NOTICE.md +12 -1
- package/README.md +5 -3
- package/dist/belts/data.d.ts +2 -0
- package/dist/belts/data.js +12 -0
- package/dist/belts/index.d.ts +270 -0
- package/dist/belts/index.js +308 -0
- package/dist/belts/totals.d.ts +43 -0
- package/dist/belts/totals.js +25 -0
- package/dist/data/orbiters.d.ts +221 -199
- package/dist/data/orbiters.js +288 -200
- package/dist/data-door.d.ts +2 -0
- package/dist/data-door.js +4 -2
- package/dist/door/points.d.ts +14 -5
- package/dist/door/points.js +78 -27
- package/dist/earth-places.d.ts +40 -0
- package/dist/earth-places.js +47 -0
- package/dist/orbiter-facts.d.ts +61 -4
- package/dist/orbiter-facts.js +17 -3
- package/dist/orbiters.d.ts +122 -2
- package/dist/orbiters.js +205 -3
- package/dist/place-marks.d.ts +76 -0
- package/dist/place-marks.js +66 -0
- package/dist/places.d.ts +1 -1
- package/dist/places.js +1 -1
- package/dist/scene/earth-places.d.ts +190 -0
- package/dist/scene/earth-places.js +190 -0
- package/dist/scene/painter.d.ts +2 -1
- package/dist/scene/painter.js +6 -3
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +74 -3
- package/dist/space/element.js +293 -8
- package/dist/space/ride.d.ts +4 -4
- package/dist/space/ride.js +10 -3
- package/dist/space/scene.d.ts +44 -2
- package/dist/space/scene.js +139 -11
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +15 -2
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type { SpotView } from "../place-marks.ts";
|
|
2
|
+
/**
|
|
3
|
+
* What a place is to the reader: `here` (where they are, drawn tall and bright) or `favourite` (a place they keep, drawn shorter and quieter).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import type { EarthPlaceKind } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
8
|
+
*
|
|
9
|
+
* const kind: EarthPlaceKind = "here";
|
|
10
|
+
* console.log(kind);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export type EarthPlaceKind = "here" | "favourite";
|
|
14
|
+
/**
|
|
15
|
+
* One place for the `earth-places` attribute or the `earthPlaces` property of `<wakusei-space>`: the same record chikyu-earth's `places` takes.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import type { EarthPlace } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
20
|
+
*
|
|
21
|
+
* const places: EarthPlace[] = [
|
|
22
|
+
* { id: "me", lon: -79.4, lat: 43.7, label: "You are here", kind: "here" },
|
|
23
|
+
* { id: "tokyo", lon: 139.69, lat: 35.69, label: "Tokyo" },
|
|
24
|
+
* ];
|
|
25
|
+
* console.log(places.length);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export interface EarthPlace {
|
|
29
|
+
/** Your own unique name for it. */
|
|
30
|
+
id: string;
|
|
31
|
+
/** Degrees east, -180 to 180. */
|
|
32
|
+
lon: number;
|
|
33
|
+
/** Degrees north, -90 to 90. */
|
|
34
|
+
lat: number;
|
|
35
|
+
/** Shown beside the marker when there is room. */
|
|
36
|
+
label?: string;
|
|
37
|
+
/** `here` or `favourite` (the default). */
|
|
38
|
+
kind?: EarthPlaceKind;
|
|
39
|
+
/** A CSS colour for this place alone: a hex colour, `rgb()` or `hsl()` with numbers, or a colour's name. */
|
|
40
|
+
color?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* How a place is drawn: `beam` (a light rising out of the ground with a ring at its foot, the default), `pin` (a thin stick with a round head) or `ring` (only the ring lying on the ground).
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { EARTH_PLACE_LOOKS, type EarthPlaceLook } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
48
|
+
*
|
|
49
|
+
* const look: EarthPlaceLook = "pin";
|
|
50
|
+
* console.log(EARTH_PLACE_LOOKS.includes(look));
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export type EarthPlaceLook = "beam" | "pin" | "ring";
|
|
54
|
+
/**
|
|
55
|
+
* Every look a place can have, the default first.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { EARTH_PLACE_LOOKS } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
60
|
+
*
|
|
61
|
+
* console.log(EARTH_PLACE_LOOKS.join(", "));
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare const EARTH_PLACE_LOOKS: readonly EarthPlaceLook[];
|
|
65
|
+
/**
|
|
66
|
+
* The most markers the Earth carries at once: the first this many places in sight, `here` first and then in the order given. The rest are counted in `earthPlacesShown().omitted`.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { EARTH_PLACE_MARKS } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
71
|
+
*
|
|
72
|
+
* console.log(EARTH_PLACE_MARKS); // 32
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare const EARTH_PLACE_MARKS = 32;
|
|
76
|
+
/** Nothing is laid on an Earth under this many CSS pixels of radius: a marker the size of the planet is not a marker. */
|
|
77
|
+
export declare const EARTH_PLACES_FROM_PX = 40;
|
|
78
|
+
/** Where one place's marker goes: the foot on the ground, the top of the stick, the ring's turn, how flat it is and its radius, and how strongly it shows. The shape of chikyu-earth's `PlaceShape`. */
|
|
79
|
+
export interface EarthPlaceShape {
|
|
80
|
+
/** Index into the places given. */
|
|
81
|
+
index: number;
|
|
82
|
+
x: number;
|
|
83
|
+
y: number;
|
|
84
|
+
tipX: number;
|
|
85
|
+
tipY: number;
|
|
86
|
+
angle: number;
|
|
87
|
+
length: number;
|
|
88
|
+
ringAngle: number;
|
|
89
|
+
squash: number;
|
|
90
|
+
ring: number;
|
|
91
|
+
opacity: number;
|
|
92
|
+
/** 0 by day, 1 in full night. */
|
|
93
|
+
night: number;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The markers and names of a set of places in one picture. The shape of chikyu-earth's `PlaceLayout`.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import type { EarthPlaceLayout } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
101
|
+
*
|
|
102
|
+
* const none: EarthPlaceLayout = { shapes: [], labels: [] };
|
|
103
|
+
* console.log(none.shapes.length);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export interface EarthPlaceLayout {
|
|
107
|
+
shapes: EarthPlaceShape[];
|
|
108
|
+
labels: {
|
|
109
|
+
index: number;
|
|
110
|
+
left: number;
|
|
111
|
+
top: number;
|
|
112
|
+
}[];
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* What a layout may be told: the size of each name as it is drawn, boxes in use by other names, the most names, and where the Sun is overhead.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* import type { EarthPlaceLayoutOptions } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
120
|
+
*
|
|
121
|
+
* const options: EarthPlaceLayoutOptions = { size: () => ({ width: 60, height: 18 }), maxLabels: 8, sun: { lon: 0, lat: 0 } };
|
|
122
|
+
* console.log(options.maxLabels);
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export interface EarthPlaceLayoutOptions {
|
|
126
|
+
size?: (place: EarthPlace, index: number) => {
|
|
127
|
+
width: number;
|
|
128
|
+
height: number;
|
|
129
|
+
} | null;
|
|
130
|
+
taken?: readonly {
|
|
131
|
+
left: number;
|
|
132
|
+
top: number;
|
|
133
|
+
width: number;
|
|
134
|
+
height: number;
|
|
135
|
+
}[];
|
|
136
|
+
maxLabels?: number;
|
|
137
|
+
sun?: {
|
|
138
|
+
lon: number;
|
|
139
|
+
lat: number;
|
|
140
|
+
} | null;
|
|
141
|
+
}
|
|
142
|
+
/** The two things `@johnmorrisdotca/wakusei-planets/earth-places` hands the views: reading the attribute, and laying places on a picture. Both are chikyu-earth's. */
|
|
143
|
+
export interface EarthPlacesLayout {
|
|
144
|
+
read(value: string | null | undefined): EarthPlace[];
|
|
145
|
+
layout(places: readonly EarthPlace[], view: SpotView, look: EarthPlaceLook, options?: EarthPlaceLayoutOptions): EarthPlaceLayout;
|
|
146
|
+
}
|
|
147
|
+
/** Give the views the layout of places (what importing `@johnmorrisdotca/wakusei-planets/earth-places` does). Views already on the page lay their places at once. */
|
|
148
|
+
export declare function setEarthPlacesLayout(using: EarthPlacesLayout): void;
|
|
149
|
+
/** The layout `setEarthPlacesLayout` was given, if any. */
|
|
150
|
+
export declare const earthPlacesLayout: () => EarthPlacesLayout | undefined;
|
|
151
|
+
/** Hear `setEarthPlacesLayout`; returns the call that stops it. */
|
|
152
|
+
export declare function onEarthPlacesLayout(heard: () => void): () => void;
|
|
153
|
+
/** The look an attribute asks for: `beam`, `pin` or `ring`; anything else is `beam`. */
|
|
154
|
+
export declare const readEarthPlaceLook: (value: string | null) => EarthPlaceLook;
|
|
155
|
+
/**
|
|
156
|
+
* What the layer drew at the last layout, for one place: its id, its kind, where its foot is (CSS pixels from the view's top left) and whether its name was drawn.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* import type { EarthPlaceMark } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
161
|
+
*
|
|
162
|
+
* const mark: EarthPlaceMark = { id: "me", kind: "here", x: 210, y: 210, named: true };
|
|
163
|
+
* console.log(mark.named);
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export interface EarthPlaceMark {
|
|
167
|
+
id: string;
|
|
168
|
+
kind: EarthPlaceKind;
|
|
169
|
+
x: number;
|
|
170
|
+
y: number;
|
|
171
|
+
named: boolean;
|
|
172
|
+
}
|
|
173
|
+
/** The markers over one view. */
|
|
174
|
+
export interface EarthPlaceLayerView {
|
|
175
|
+
/** Draw the markers of a layout, moving the ones already there and hiding the rest. */
|
|
176
|
+
set(places: readonly EarthPlace[], layout: EarthPlaceLayout, look: EarthPlaceLook): void;
|
|
177
|
+
/** Hide every marker. */
|
|
178
|
+
clear(): void;
|
|
179
|
+
/** How wide a name is when drawn, in CSS pixels, in the font the layer's CSS gives it (padding included). */
|
|
180
|
+
width(text: string): number;
|
|
181
|
+
readonly shown: readonly EarthPlaceMark[];
|
|
182
|
+
dispose(): void;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Make the layer of markers inside a view's shadow root, above its picture. It holds a handful of elements made once and kept; a draw only writes the numbers that changed.
|
|
186
|
+
*
|
|
187
|
+
* @param root - The view's shadow root.
|
|
188
|
+
* @returns The layer.
|
|
189
|
+
*/
|
|
190
|
+
export declare function createEarthPlaceLayer(root: ShadowRoot): EarthPlaceLayerView;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every look a place can have, the default first.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { EARTH_PLACE_LOOKS } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
7
|
+
*
|
|
8
|
+
* console.log(EARTH_PLACE_LOOKS.join(", "));
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export const EARTH_PLACE_LOOKS = ["beam", "pin", "ring"];
|
|
12
|
+
/**
|
|
13
|
+
* The most markers the Earth carries at once: the first this many places in sight, `here` first and then in the order given. The rest are counted in `earthPlacesShown().omitted`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { EARTH_PLACE_MARKS } from "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
18
|
+
*
|
|
19
|
+
* console.log(EARTH_PLACE_MARKS); // 32
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const EARTH_PLACE_MARKS = 32;
|
|
23
|
+
/** Nothing is laid on an Earth under this many CSS pixels of radius: a marker the size of the planet is not a marker. */
|
|
24
|
+
export const EARTH_PLACES_FROM_PX = 40;
|
|
25
|
+
// on globalThis, so the separate copies a CDN can load share the one layout
|
|
26
|
+
const SLOT = Symbol.for("@johnmorrisdotca/wakusei-planets/earth-places");
|
|
27
|
+
const slot = (globalThis[SLOT] ??= { heard: new Set() });
|
|
28
|
+
/** Give the views the layout of places (what importing `@johnmorrisdotca/wakusei-planets/earth-places` does). Views already on the page lay their places at once. */
|
|
29
|
+
export function setEarthPlacesLayout(using) {
|
|
30
|
+
slot.using = using;
|
|
31
|
+
for (const heard of slot.heard)
|
|
32
|
+
heard();
|
|
33
|
+
}
|
|
34
|
+
/** The layout `setEarthPlacesLayout` was given, if any. */
|
|
35
|
+
export const earthPlacesLayout = () => slot.using;
|
|
36
|
+
/** Hear `setEarthPlacesLayout`; returns the call that stops it. */
|
|
37
|
+
export function onEarthPlacesLayout(heard) {
|
|
38
|
+
slot.heard.add(heard);
|
|
39
|
+
return () => slot.heard.delete(heard);
|
|
40
|
+
}
|
|
41
|
+
/** The look an attribute asks for: `beam`, `pin` or `ring`; anything else is `beam`. */
|
|
42
|
+
export const readEarthPlaceLook = (value) => EARTH_PLACE_LOOKS.includes(value ?? "") ? value : "beam";
|
|
43
|
+
const SVG = "http://www.w3.org/2000/svg";
|
|
44
|
+
const STYLE = `.wk-eplaces{position:absolute;inset:0;pointer-events:none;overflow:hidden;--wk-here:var(--wakusei-place-here,#ffd34d);--wk-fav:var(--wakusei-place-favourite,#7fd6ff)}
|
|
45
|
+
.wk-eplaces svg{position:absolute;inset:0;width:100%;height:100%;overflow:visible}
|
|
46
|
+
.wk-eplace{color:var(--wk-fav)}
|
|
47
|
+
.wk-eplace[data-kind=here]{color:var(--wk-here)}
|
|
48
|
+
.wk-eplace line,.wk-eplace ellipse,.wk-eplace circle{vector-effect:non-scaling-stroke}
|
|
49
|
+
.wk-eplace-name{position:absolute;left:0;top:0;padding:0 5px;box-sizing:border-box;border-radius:4px;background:rgba(10,14,22,.78);color:#fff;font:12px/18px var(--wakusei-place-font,system-ui,-apple-system,sans-serif);white-space:nowrap;height:18px}
|
|
50
|
+
.wk-eplace-name[data-kind=here]{font-weight:600}`;
|
|
51
|
+
/**
|
|
52
|
+
* Make the layer of markers inside a view's shadow root, above its picture. It holds a handful of elements made once and kept; a draw only writes the numbers that changed.
|
|
53
|
+
*
|
|
54
|
+
* @param root - The view's shadow root.
|
|
55
|
+
* @returns The layer.
|
|
56
|
+
*/
|
|
57
|
+
export function createEarthPlaceLayer(root) {
|
|
58
|
+
const style = document.createElement("style");
|
|
59
|
+
style.textContent = STYLE;
|
|
60
|
+
const box = document.createElement("div");
|
|
61
|
+
box.className = "wk-eplaces";
|
|
62
|
+
box.setAttribute("part", "earth-places");
|
|
63
|
+
box.setAttribute("aria-hidden", "true");
|
|
64
|
+
const svg = document.createElementNS(SVG, "svg");
|
|
65
|
+
box.append(svg);
|
|
66
|
+
root.append(style, box);
|
|
67
|
+
// a name that is never shown, only to read the font the CSS gives a name; names are measured with it once and kept
|
|
68
|
+
const probe = document.createElement("span");
|
|
69
|
+
probe.className = "wk-eplace-name";
|
|
70
|
+
probe.hidden = true;
|
|
71
|
+
box.append(probe);
|
|
72
|
+
const widths = new Map();
|
|
73
|
+
let context;
|
|
74
|
+
const pool = [];
|
|
75
|
+
let shown = [];
|
|
76
|
+
const item = (i) => {
|
|
77
|
+
let it = pool[i];
|
|
78
|
+
if (it === undefined) {
|
|
79
|
+
const g = document.createElementNS(SVG, "g");
|
|
80
|
+
g.setAttribute("class", "wk-eplace");
|
|
81
|
+
const stick = document.createElementNS(SVG, "line");
|
|
82
|
+
stick.setAttribute("stroke", "currentColor");
|
|
83
|
+
stick.setAttribute("stroke-linecap", "round");
|
|
84
|
+
const ring = document.createElementNS(SVG, "ellipse");
|
|
85
|
+
ring.setAttribute("fill", "none");
|
|
86
|
+
ring.setAttribute("stroke", "currentColor");
|
|
87
|
+
const head = document.createElementNS(SVG, "circle");
|
|
88
|
+
head.setAttribute("fill", "currentColor");
|
|
89
|
+
g.append(stick, ring, head);
|
|
90
|
+
svg.append(g);
|
|
91
|
+
const name = document.createElement("span");
|
|
92
|
+
name.className = "wk-eplace-name";
|
|
93
|
+
box.append(name);
|
|
94
|
+
it = { g, stick, ring, head, name };
|
|
95
|
+
pool[i] = it;
|
|
96
|
+
}
|
|
97
|
+
return it;
|
|
98
|
+
};
|
|
99
|
+
const set = (el, name, value) => {
|
|
100
|
+
if (el.getAttribute(name) !== value)
|
|
101
|
+
el.setAttribute(name, value);
|
|
102
|
+
};
|
|
103
|
+
const n = (value) => String(Math.round(value * 10) / 10);
|
|
104
|
+
return {
|
|
105
|
+
set(places, layout, look) {
|
|
106
|
+
const named = new Map(layout.labels.map((spot) => [spot.index, spot]));
|
|
107
|
+
shown = [];
|
|
108
|
+
for (const [i, shape] of layout.shapes.entries()) {
|
|
109
|
+
const place = places[shape.index];
|
|
110
|
+
const it = item(i);
|
|
111
|
+
const here = place.kind === "here";
|
|
112
|
+
const dim = 1 - 0.5 * shape.night;
|
|
113
|
+
set(it.g, "data-kind", here ? "here" : "favourite");
|
|
114
|
+
if (place.color !== undefined)
|
|
115
|
+
it.g.style.color = place.color;
|
|
116
|
+
else if (it.g.style.color !== "")
|
|
117
|
+
it.g.style.color = "";
|
|
118
|
+
it.g.style.display = "";
|
|
119
|
+
it.g.setAttribute("opacity", n(shape.opacity * dim));
|
|
120
|
+
it.g.setAttribute("transform", `translate(${n(shape.x)} ${n(shape.y)})`);
|
|
121
|
+
set(it.ring, "rx", n(shape.ring));
|
|
122
|
+
set(it.ring, "ry", n(shape.ring * shape.squash));
|
|
123
|
+
set(it.ring, "transform", `rotate(${n(shape.ringAngle)})`);
|
|
124
|
+
set(it.ring, "stroke-width", here ? "2" : "1.5");
|
|
125
|
+
const stick = look !== "ring";
|
|
126
|
+
it.stick.style.display = stick ? "" : "none";
|
|
127
|
+
it.head.style.display = look === "pin" ? "" : "none";
|
|
128
|
+
if (stick) {
|
|
129
|
+
set(it.stick, "x2", n(shape.tipX - shape.x));
|
|
130
|
+
set(it.stick, "y2", n(shape.tipY - shape.y));
|
|
131
|
+
set(it.stick, "stroke-width", look === "beam" ? (here ? "3" : "2") : here ? "2" : "1.5");
|
|
132
|
+
set(it.stick, "stroke-opacity", look === "beam" ? "0.85" : "1");
|
|
133
|
+
}
|
|
134
|
+
if (look === "pin") {
|
|
135
|
+
set(it.head, "cx", n(shape.tipX - shape.x));
|
|
136
|
+
set(it.head, "cy", n(shape.tipY - shape.y));
|
|
137
|
+
set(it.head, "r", here ? "5" : "3.5");
|
|
138
|
+
}
|
|
139
|
+
const spot = named.get(shape.index);
|
|
140
|
+
if (spot !== undefined) {
|
|
141
|
+
it.name.hidden = false;
|
|
142
|
+
if (it.name.textContent !== place.label)
|
|
143
|
+
it.name.textContent = place.label ?? "";
|
|
144
|
+
set(it.name, "data-kind", here ? "here" : "favourite");
|
|
145
|
+
it.name.style.opacity = n(shape.opacity * (1 - 0.3 * shape.night));
|
|
146
|
+
it.name.style.transform = `translate(${n(spot.left)}px,${n(spot.top)}px)`;
|
|
147
|
+
}
|
|
148
|
+
else
|
|
149
|
+
it.name.hidden = true;
|
|
150
|
+
shown.push({ id: place.id, kind: here ? "here" : "favourite", x: shape.x, y: shape.y, named: spot !== undefined });
|
|
151
|
+
}
|
|
152
|
+
for (let i = layout.shapes.length; i < pool.length; i += 1) {
|
|
153
|
+
const it = pool[i];
|
|
154
|
+
it.g.style.display = "none";
|
|
155
|
+
it.name.hidden = true;
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
clear() {
|
|
159
|
+
for (const it of pool) {
|
|
160
|
+
it.g.style.display = "none";
|
|
161
|
+
it.name.hidden = true;
|
|
162
|
+
}
|
|
163
|
+
shown = [];
|
|
164
|
+
},
|
|
165
|
+
width(text) {
|
|
166
|
+
const known = widths.get(text);
|
|
167
|
+
if (known !== undefined)
|
|
168
|
+
return known;
|
|
169
|
+
if (context === undefined) {
|
|
170
|
+
context = document.createElement("canvas").getContext("2d");
|
|
171
|
+
if (context !== null)
|
|
172
|
+
context.font = getComputedStyle(probe).font;
|
|
173
|
+
}
|
|
174
|
+
if (widths.size > 2000)
|
|
175
|
+
widths.clear();
|
|
176
|
+
const width = Math.ceil((context?.measureText(text).width ?? text.length * 7) + 10);
|
|
177
|
+
widths.set(text, width);
|
|
178
|
+
return width;
|
|
179
|
+
},
|
|
180
|
+
get shown() {
|
|
181
|
+
return shown;
|
|
182
|
+
},
|
|
183
|
+
dispose() {
|
|
184
|
+
box.remove();
|
|
185
|
+
style.remove();
|
|
186
|
+
pool.length = 0;
|
|
187
|
+
shown = [];
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
}
|
package/dist/scene/painter.d.ts
CHANGED
|
@@ -168,7 +168,8 @@ export interface MoonSite {
|
|
|
168
168
|
radius: number;
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
171
|
-
* Where the pictures are, if not on jsDelivr: a folder address that ends in a slash. `farBase` holds the widest pictures (2048), which the npm package leaves out.
|
|
171
|
+
* Where the pictures are, if not on jsDelivr: a folder address that ends in a slash. `farBase` holds the widest pictures (2048), which the npm package leaves out. A page that gives its own
|
|
172
|
+
* `textureBase` (the package's `dist/textures/`, say) and no `farBase` is never asked for those: the painter stops at the widest the package ships (1024). Give `farBase` too when the 2048s are served.
|
|
172
173
|
*
|
|
173
174
|
* @example
|
|
174
175
|
* ```ts no-run
|
package/dist/scene/painter.js
CHANGED
|
@@ -232,7 +232,9 @@ function paint(T, id, context, bases) {
|
|
|
232
232
|
glowMesh = glow;
|
|
233
233
|
}
|
|
234
234
|
// the painted map: the smallest width at once, a sharper one when the body is big on the screen, back to the small one when it is not
|
|
235
|
-
|
|
235
|
+
// a width the far base holds (the sharpest, which the npm package leaves out) only when there is a far base: a page that gave its own textureBase and no farBase has only the package's widths
|
|
236
|
+
const farFrom = look.painted?.far;
|
|
237
|
+
const widths = (look.painted?.widths ?? []).filter((w, i) => i === 0 || (w <= maxWidth && (bases.far !== undefined || farFrom === undefined || w < farFrom)));
|
|
236
238
|
let small;
|
|
237
239
|
let sharp;
|
|
238
240
|
let sharpWidth = 0;
|
|
@@ -240,7 +242,7 @@ function paint(T, id, context, bases) {
|
|
|
240
242
|
let failed = false;
|
|
241
243
|
let tooBigSince = 0;
|
|
242
244
|
const tried = new Set();
|
|
243
|
-
const urlOf = (w) => `${look.painted.far !== undefined && w >= look.painted.far ? bases.far : bases.near}${look.painted.map}-${w}.webp`;
|
|
245
|
+
const urlOf = (w) => `${look.painted.far !== undefined && w >= look.painted.far && bases.far !== undefined ? bases.far : bases.near}${look.painted.map}-${w}.webp`;
|
|
244
246
|
const prepare = (t) => {
|
|
245
247
|
t.anisotropy = 4;
|
|
246
248
|
t.wrapS = T.RepeatWrapping;
|
|
@@ -464,7 +466,8 @@ function paint(T, id, context, bases) {
|
|
|
464
466
|
*/
|
|
465
467
|
export function createPainter(options = {}) {
|
|
466
468
|
const near = slash(options.textureBase ?? TEXTURE_BASE);
|
|
467
|
-
|
|
469
|
+
// the widest pictures are not in the npm package: a page with its own textureBase has them only where it says so with farBase (no far base, and the painter stops at the package's widths)
|
|
470
|
+
const far = options.farBase !== undefined ? slash(options.farBase) : options.textureBase !== undefined ? undefined : TEXTURE_FAR_BASE;
|
|
468
471
|
const own = options.tiles;
|
|
469
472
|
const tiles = own === "off" || own === "none" || own === "" ? undefined : own !== undefined ? slash(own) : options.textureBase !== undefined ? undefined : TILES_BASE;
|
|
470
473
|
const book = options.book ?? createSourceBook({ kinds: ["tiles"] });
|
package/dist/scene/textures.d.ts
CHANGED
|
@@ -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.
|
|
14
|
+
export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.38.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.
|
|
26
|
+
export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.38.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.
|
package/dist/space/element.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { type Sight, type SightEdge } from "./sight.ts";
|
|
|
6
6
|
import { type NameLabelOptions } from "../scene/name-label.ts";
|
|
7
7
|
import type { Credit, DataSource } from "../data-door.ts";
|
|
8
8
|
import { type DoorHost } from "../door/host.ts";
|
|
9
|
+
import { type BeltId } from "../belts/index.ts";
|
|
9
10
|
import { setThreeLoader } from "../scene/shared.ts";
|
|
10
11
|
import { type SpacePlanet } from "./frame.ts";
|
|
11
12
|
import { type ScaleMode } from "./scale.ts";
|
|
@@ -14,8 +15,10 @@ import { type SunRegion } from "./regions.ts";
|
|
|
14
15
|
import { type TravelKind } from "./travel.ts";
|
|
15
16
|
import { type Place } from "../places.ts";
|
|
16
17
|
import { type PlaceLayer } from "../place-marks.ts";
|
|
18
|
+
import { type EarthPlace, type EarthPlaceLook, type EarthPlaceMark } from "../scene/earth-places.ts";
|
|
17
19
|
import { SPACE_BODIES, type BodyPlace, type RidePoint, type RideState, type RideTarget, type SpaceBody, type SpaceLight } from "./scene.ts";
|
|
18
20
|
export { setPlacesLoader } from "../scene/place-layer.ts";
|
|
21
|
+
export { EARTH_PLACE_LOOKS, EARTH_PLACE_MARKS, type EarthPlace, type EarthPlaceKind, type EarthPlaceLook, type EarthPlaceMark } from "../scene/earth-places.ts";
|
|
19
22
|
export { setThreeLoader, SPACE_BODIES, type RidePoint, type RideTarget, type Sight, type SightEdge, type SpaceBody, type SpaceLight };
|
|
20
23
|
/** Where a body is on the screen, in CSS pixels in the element: its centre and its radius. */
|
|
21
24
|
export type { BodyPlace };
|
|
@@ -190,6 +193,31 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
190
193
|
x: number;
|
|
191
194
|
y: number;
|
|
192
195
|
}[];
|
|
196
|
+
/**
|
|
197
|
+
* The reader's own place and the places they keep, drawn on the Earth wherever the camera looks: a list of `{ id, lon, lat, label, kind, color }` (`kind` is `here` or `favourite`), as JSON in the attribute `earth-places`.
|
|
198
|
+
* Each is a marker standing out of the ground that turns with the Earth, is hidden on the far side, fades at the edge and keeps its size in pixels; a name shows beside it when there is room, never over another name. Setting the property
|
|
199
|
+
* writes the attribute, and an empty list takes it away. It reads as the list chikyu-earth cleaned (a place with a longitude or latitude out of range is left out, at most 5,000). It draws nothing, and reads as empty, until the page has
|
|
200
|
+
* imported `@johnmorrisdotca/wakusei-planets/earth-places`, which brings chikyu-earth's layout (an optional peer).
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts no-run
|
|
204
|
+
* import "@johnmorrisdotca/wakusei-planets/earth-places";
|
|
205
|
+
* import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
206
|
+
*
|
|
207
|
+
* const space = document.querySelector<WakuseiSpace>("wakusei-space")!;
|
|
208
|
+
* space.earthPlaces = [{ id: "me", lon: -79.4, lat: 43.7, label: "You are here", kind: "here" }];
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
get earthPlaces(): EarthPlace[];
|
|
212
|
+
set earthPlaces(list: readonly EarthPlace[] | null);
|
|
213
|
+
/** How the places on the Earth are drawn (the attribute `earth-places-look`): `beam` (the default), `pin` or `ring`. Setting it writes the attribute. */
|
|
214
|
+
get earthPlacesLook(): EarthPlaceLook;
|
|
215
|
+
set earthPlacesLook(look: EarthPlaceLook | null);
|
|
216
|
+
/** The markers laid on the Earth now, as the last draw left them: each place's id and kind, where its foot is in CSS pixels from the view's top left and whether its name is drawn; `omitted` counts the places in sight beyond the first `EARTH_PLACE_MARKS`. */
|
|
217
|
+
get earthPlacesShown(): {
|
|
218
|
+
marks: readonly EarthPlaceMark[];
|
|
219
|
+
omitted: number;
|
|
220
|
+
};
|
|
193
221
|
/**
|
|
194
222
|
* Go to a place on a body: the view glides to the body (as `goTo` does), or on the body looked at turns round it, and the camera comes to rest straight above the place. The place is an id (`mars/perseverance`) or an English or Japanese name, on the body looked at
|
|
195
223
|
* unless `body` names another. The zoom stays on the same body and is 1 (the whole body) on another, unless `zoom` is given. Resolves the place, or `undefined` when the body has no place by that name or cannot be looked at.
|
|
@@ -246,7 +274,7 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
246
274
|
get region(): SunRegion | null;
|
|
247
275
|
/**
|
|
248
276
|
* Show the spacecraft in orbit round the Moon and Mars (the attribute `orbiters`; off by default): each a small dot where `/orbiters` puts it on the date shown, scaled with its body, on its orbit line, with its
|
|
249
|
-
* name beside it in the page's language, once the body is at least 24 CSS pixels in radius on the screen. A modelled
|
|
277
|
+
* name beside it in the page's language, once the body is at least 24 CSS pixels in radius on the screen. A modelled path is drawn dim, and a predicted one whose measured error is more than 2 per cent of its body's radius (`orbiterDim`); a craft with no path is not drawn. The paths (a 9 kB module)
|
|
250
278
|
* are loaded the first time they are shown. `stats.orbiters` says what was drawn and each one's status.
|
|
251
279
|
*/
|
|
252
280
|
get orbiters(): boolean;
|
|
@@ -257,6 +285,21 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
257
285
|
*/
|
|
258
286
|
get roadster(): boolean;
|
|
259
287
|
set roadster(value: boolean);
|
|
288
|
+
/**
|
|
289
|
+
* The orbiter picked out (the attribute `orbiter`, an id from `/orbiters` such as `lro`; none by default): its orbit line is drawn brighter, it alone keeps its line when `orbiterLines` is
|
|
290
|
+
* `chosen`, and its ground track is drawn when `orbiterTrack` is on.
|
|
291
|
+
*/
|
|
292
|
+
get orbiter(): string | null;
|
|
293
|
+
set orbiter(value: string | null);
|
|
294
|
+
/** Which orbiters' orbit lines are drawn (the attribute `orbiter-lines`): `all` (the default), `chosen` (the one `orbiter` names) or `none`. Apart from the planets' and moons' lines (`orbits`). */
|
|
295
|
+
get orbiterLines(): "all" | "chosen" | "none";
|
|
296
|
+
set orbiterLines(value: "all" | "chosen" | "none");
|
|
297
|
+
/**
|
|
298
|
+
* Draw the chosen orbiter's ground track (the attribute `orbiter-track`; off by default): the line on its body under the craft from one trip before the moment shown to one trip after, the body
|
|
299
|
+
* turning beneath it, so each trip crosses the equator further west.
|
|
300
|
+
*/
|
|
301
|
+
get orbiterTrack(): boolean;
|
|
302
|
+
set orbiterTrack(value: boolean);
|
|
260
303
|
/**
|
|
261
304
|
* What a body behind another gets (the attribute `covered`): `name` (the default) draws its floating name and ring over the nearer body's disc as always; `arrow` draws instead one small quiet arrow just outside the
|
|
262
305
|
* disc's edge on the side nearest the hidden body, pointing in behind it, with the surest hidden body's name beside it and the others counted (`Uranus +4`); a press on it goes to that body. The arrow goes as the body comes out.
|
|
@@ -402,6 +445,29 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
402
445
|
* @param options - `view`, `look`, `distanceKm`, `around`, `smooth` (see `RideOptions`).
|
|
403
446
|
*/
|
|
404
447
|
ride(target: RideTarget | null, options?: RideOptions): void;
|
|
448
|
+
/**
|
|
449
|
+
* The belts drawn, by name (`main`, `hilda`, `trojan`, `centaur`, `classical`, `resonant`, `scattered`): all seven by default, `[]` for none. The attribute `belts` says the same (`belts="off"`, `belts="main trojan"`). Each belt is one instanced draw of its own
|
|
450
|
+
* colour, from the package's own source of NASA/JPL's Small-Body Database (`@johnmorrisdotca/wakusei-planets/belts`), fetched when the view first draws it.
|
|
451
|
+
*/
|
|
452
|
+
get belts(): readonly BeltId[];
|
|
453
|
+
set belts(list: readonly BeltId[]);
|
|
454
|
+
/**
|
|
455
|
+
* Fly into a belt: the camera goes to a point on a circular orbit in the middle of the belt, tilted a few degrees to the ecliptic so that it passes through the belt's thickness, looking the way it goes with the ecliptic's north at the top, at true
|
|
456
|
+
* distances (the squeezed scale is left), and a drag looks about. The dots round it are the belt's bodies; a line on the view says how many bodies there really are, and that neighbours are millions of kilometres apart, which is why the picture is
|
|
457
|
+
* mostly empty. Time runs as the clock says (`speed`). `leaveBelt()` goes back.
|
|
458
|
+
*
|
|
459
|
+
* @param belt - The belt, `main` by default.
|
|
460
|
+
* @param options - `smooth` (a glide, true by default).
|
|
461
|
+
*/
|
|
462
|
+
enterBelt(belt?: BeltId, options?: {
|
|
463
|
+
smooth?: boolean;
|
|
464
|
+
}): void;
|
|
465
|
+
/** Come out of a belt: the camera goes back to the body it looked at before. */
|
|
466
|
+
leaveBelt(options?: {
|
|
467
|
+
smooth?: boolean;
|
|
468
|
+
}): void;
|
|
469
|
+
/** The belt the camera is flying through, or null. */
|
|
470
|
+
get flyingThrough(): BeltId | null;
|
|
405
471
|
/** What the camera is riding along with now, or null. */
|
|
406
472
|
get riding(): Riding | null;
|
|
407
473
|
/** The zoom that shows a part of the sky: the Earth alone, the Moon's orbit, the Sun, the planets out to Mars, all of them, or a planet's nearer moons, at this scale and moment. */
|
|
@@ -485,9 +551,11 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
485
551
|
reach: number;
|
|
486
552
|
distance: number;
|
|
487
553
|
} | null;
|
|
488
|
-
/** The data door: the small bodies in the one instanced draw, and what the sources have done (tile loads started, failed and refused, bytes held, records read). */
|
|
554
|
+
/** The data door: the small bodies of a page's own sources in the one instanced draw (`points`), the package's own belts (`belts` bodies in `draws` instanced draws, one for each belt), and what the sources have done (tile loads started, failed and refused, bytes held, records read). */
|
|
489
555
|
door: {
|
|
490
556
|
points: number;
|
|
557
|
+
belts: number;
|
|
558
|
+
draws: number;
|
|
491
559
|
sources: ReturnType<DoorHost["book"]["stats"]>;
|
|
492
560
|
};
|
|
493
561
|
/** The catalogue's other moons (`all-moons`): whether they are asked for, whether the catalogue has loaded, and how many dots the last draw drew. */
|
|
@@ -532,10 +600,13 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
532
600
|
position: [number, number, number] | null;
|
|
533
601
|
radiusPx: number;
|
|
534
602
|
};
|
|
535
|
-
/** The orbiters at the last draw: how many dots were drawn (their body big enough on the screen),
|
|
603
|
+
/** The orbiters at the last draw: how many dots were drawn (their body big enough on the screen), each drawn craft's status (`tracked`, `predicted`, `modelled`); `dim` lists the craft drawn dim (`orbiterDim` from `/orbiters`); `lines` how many orbit lines and `track` how many points of ground track were drawn. */
|
|
536
604
|
orbiters: {
|
|
537
605
|
count: number;
|
|
538
606
|
status: Record<string, "tracked" | "predicted" | "modelled" | "none">;
|
|
607
|
+
dim: string[];
|
|
608
|
+
lines: number;
|
|
609
|
+
track: number;
|
|
539
610
|
};
|
|
540
611
|
};
|
|
541
612
|
/** 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. */
|