@johnmorrisdotca/wakusei-planets 0.70.0 → 0.72.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +16 -4
- package/dist/moon-pages/data.d.ts +157 -0
- package/dist/moon-pages/data.js +138 -0
- package/dist/moon-pages/element.d.ts +82 -0
- package/dist/moon-pages/element.js +670 -0
- package/dist/moon-pages/index.d.ts +1 -0
- package/dist/moon-pages/index.js +2 -0
- package/dist/moon-pages/words.d.ts +115 -0
- package/dist/moon-pages/words.js +116 -0
- package/dist/place-radii.d.ts +57 -0
- package/dist/place-radii.js +24 -0
- package/dist/places.d.ts +32 -2
- package/dist/places.js +37 -8
- package/dist/scene/textures.d.ts +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +2 -1
- package/package.json +13 -1
|
@@ -0,0 +1,670 @@
|
|
|
1
|
+
// <wakusei-moon-pages>: one giant planet's moons in four tabs, each one screen. Orbits: every orbit of /moon-catalogue in SVG, from above, at an angle or from the side, coloured by direction or by family.
|
|
2
|
+
// Map and portrait: <wakusei-plan> and <wakusei-portrait>. Main moons: a card with a picture for each moon drawn in full. Every moon: the whole list in a table that sorts. Every number is worked out from the
|
|
3
|
+
// package's data (moonPage). The WebGL parts and the bodies' looks are fetched only when their tab is first opened. Nothing runs on a timer; it never writes the page's address: a choice is reflected on its
|
|
4
|
+
// own attributes and sent as `wakusei-moon-pages-change`, for the page to keep where it likes.
|
|
5
|
+
import { MOONS_OF } from "../facts.js";
|
|
6
|
+
import { addBody, addMoons, defaultPortrait, encodeScene } from "../portrait/model.js";
|
|
7
|
+
import { moonPage, MOON_PAGE_HOSTS } from "./data.js";
|
|
8
|
+
import { MOON_PAGE_WORDS } from "./words.js";
|
|
9
|
+
/**
|
|
10
|
+
* The four tabs of `<wakusei-moon-pages>`, in their order: `orbits`, `views` (the map and the portrait), `cards` (the moons drawn in full) and `table` (every moon).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts no-run
|
|
14
|
+
* import { MOON_PAGE_TABS } from "@johnmorrisdotca/wakusei-planets/moon-pages/element";
|
|
15
|
+
*
|
|
16
|
+
* console.log(MOON_PAGE_TABS.join(", "));
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const MOON_PAGE_TABS = ["orbits", "views", "cards", "table"];
|
|
20
|
+
const VIEWS = ["above", "tilted", "side"];
|
|
21
|
+
const REACHES = ["all", "inner"];
|
|
22
|
+
const COLOURS = ["direction", "group"];
|
|
23
|
+
const COLUMNS = ["name", "family", "size", "distance", "period", "year", "where", "by", "direction"];
|
|
24
|
+
const TEXT_COLUMNS = ["name", "where", "by"];
|
|
25
|
+
const ELEVATION = { above: 90, tilted: 30, side: 0 };
|
|
26
|
+
const NONE = "—";
|
|
27
|
+
const DEFAULTS = { planet: "jupiter", tab: "orbits", view: "tilted", reach: "all", colour: "direction", sort: "distance", order: "up" };
|
|
28
|
+
const ALLOWED = { planet: MOON_PAGE_HOSTS, tab: MOON_PAGE_TABS, view: VIEWS, reach: REACHES, colour: COLOURS, sort: COLUMNS, order: ["up", "down"] };
|
|
29
|
+
const STATE_KEYS = Object.keys(DEFAULTS);
|
|
30
|
+
/** Each planet's own look and its moons' looks, fetched for the portrait and the cards. */
|
|
31
|
+
const LOOKS = {
|
|
32
|
+
jupiter: () => Promise.all([import("../bodies/jupiter.js"), import("../bodies/moons-jupiter.js")]),
|
|
33
|
+
saturn: () => Promise.all([import("../bodies/saturn.js"), import("../bodies/moons-saturn.js")]),
|
|
34
|
+
uranus: () => Promise.all([import("../bodies/uranus.js"), import("../bodies/moons-uranus.js")]),
|
|
35
|
+
neptune: () => Promise.all([import("../bodies/neptune.js"), import("../bodies/moons-neptune.js")]),
|
|
36
|
+
};
|
|
37
|
+
const escape = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
38
|
+
const ink = (name, light, dark) => `var(--${name}, light-dark(${light}, ${dark}))`;
|
|
39
|
+
const TEMPLATE = `<style>
|
|
40
|
+
:host { display: block; color: ${ink("ink", "#1f2320", "#ece8dc")}; font-family: var(--font, system-ui, -apple-system, "Segoe UI", sans-serif); }
|
|
41
|
+
:host([hidden]), [hidden] { display: none !important; }
|
|
42
|
+
* { box-sizing: border-box; }
|
|
43
|
+
button { font: inherit; color: inherit; cursor: pointer; }
|
|
44
|
+
.top { display: grid; gap: 8px; margin-bottom: 12px; }
|
|
45
|
+
h2 { margin: 0; font-size: 1.5rem; }
|
|
46
|
+
.fine { font-size: .75rem; color: ${ink("muted", "#6b6f68", "#a09d93")}; margin: 0; }
|
|
47
|
+
.lede { font-size: .9rem; max-width: 80ch; }
|
|
48
|
+
.short { display: none; }
|
|
49
|
+
.panels { border: 1px solid ${ink("rule", "#ddd6c6", "#3a3d38")}; border-radius: var(--radius, 16px); background: ${ink("surface", "#fbf8f1", "#1d201e")}; overflow: hidden; }
|
|
50
|
+
.tabs { display: flex; border-bottom: 1px solid ${ink("rule", "#ddd6c6", "#3a3d38")}; }
|
|
51
|
+
.tabs button { flex: 1; border: 0; background: transparent; min-height: 48px; padding: 0 6px; font-size: .9rem; font-weight: 600; color: ${ink("muted", "#6b6f68", "#a09d93")}; border-bottom: 3px solid transparent; }
|
|
52
|
+
.tabs button[aria-selected="true"] { color: inherit; border-bottom-color: ${ink("accent", "#b5452c", "#b5452c")}; }
|
|
53
|
+
.panel { padding: 14px; display: grid; gap: 14px; }
|
|
54
|
+
.panel > * { min-width: 0; max-width: 100%; }
|
|
55
|
+
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
|
56
|
+
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; background: ${ink("surface", "#fbf8f1", "#1d201e")}; border: 1px solid ${ink("rule", "#ddd6c6", "#3a3d38")}; border-radius: 26px; padding: 3px; }
|
|
57
|
+
.seg button { border: 0; background: transparent; border-radius: 999px; min-width: 48px; min-height: 48px; padding: 0 10px; font-weight: 600; }
|
|
58
|
+
.seg button[aria-pressed="true"] { background: ${ink("ink", "#1f2320", "#ece8dc")}; color: ${ink("surface", "#fbf8f1", "#1d201e")}; }
|
|
59
|
+
button:focus-visible, [tabindex]:focus-visible { outline: 3px solid ${ink("accent", "#b5452c", "#b5452c")}; outline-offset: 2px; }
|
|
60
|
+
.stage { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; }
|
|
61
|
+
svg.orbits { flex: 0 1 auto; width: min(100%, 640px, calc(60vh * var(--ratio, 1))); aspect-ratio: var(--ratio, 1); display: block; border-radius: 12px; background: #06080d; color: #c9d4e3; touch-action: manipulation; }
|
|
62
|
+
svg.orbits path { vector-effect: non-scaling-stroke; stroke-opacity: var(--line, .6); }
|
|
63
|
+
svg.orbits path[data-full] { stroke-opacity: .9; }
|
|
64
|
+
svg.orbits .lit path { stroke-opacity: 1; }
|
|
65
|
+
svg.orbits .planet { stroke: rgba(255,255,255,.5); stroke-width: 1; vector-effect: non-scaling-stroke; }
|
|
66
|
+
.side { flex: 1 1 220px; display: grid; gap: 10px; align-content: start; min-width: 0; }
|
|
67
|
+
.key { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: .85rem; }
|
|
68
|
+
.key li { display: flex; align-items: center; gap: 8px; }
|
|
69
|
+
.key b { font-variant-numeric: tabular-nums; }
|
|
70
|
+
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; flex: none; }
|
|
71
|
+
.pick { min-height: 2.6em; color: inherit; font-size: .85rem; }
|
|
72
|
+
.views { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; }
|
|
73
|
+
figure { margin: 0; display: grid; gap: 6px; min-width: 0; }
|
|
74
|
+
.plan { flex: 0 1 300px; }
|
|
75
|
+
.plan .box { min-height: 300px; display: grid; place-items: center; }
|
|
76
|
+
.portrait { flex: 1 1 420px; }
|
|
77
|
+
.portrait .box { border-radius: 12px; background: #06080d; overflow: hidden; }
|
|
78
|
+
.portrait wakusei-portrait { --wakusei-size: 100%; width: 100%; max-width: none; }
|
|
79
|
+
.cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: 10px; max-height: 70vh; overflow-y: auto; }
|
|
80
|
+
.moons-card { display: grid; grid-template-columns: 88px 1fr; gap: 10px; align-items: start; border: 1px solid ${ink("rule", "#ddd6c6", "#3a3d38")}; border-radius: 12px; padding: 10px; }
|
|
81
|
+
.picture { width: 88px; height: 88px; border-radius: 10px; background: #06080d; position: relative; overflow: hidden; }
|
|
82
|
+
.picture wakusei-body { --wakusei-size: 88px; width: 88px; pointer-events: none; }
|
|
83
|
+
.moons-card h3 { margin: 0 0 4px; font-size: 1rem; }
|
|
84
|
+
.moons-card dl { display: grid; grid-template-columns: max-content 1fr; gap: 1px 10px; margin: 0 0 4px; font-size: .8rem; }
|
|
85
|
+
.moons-card dt { color: ${ink("muted", "#6b6f68", "#a09d93")}; }
|
|
86
|
+
.moons-card dd { margin: 0; overflow-wrap: anywhere; }
|
|
87
|
+
.table-box { position: relative; max-width: 100%; max-height: 62vh; overflow: auto; border: 1px solid ${ink("rule", "#ddd6c6", "#3a3d38")}; border-radius: 12px; }
|
|
88
|
+
table { border-collapse: collapse; width: 100%; font-size: .85rem; font-variant-numeric: tabular-nums; }
|
|
89
|
+
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid ${ink("rule", "#ddd6c6", "#3a3d38")}; vertical-align: top; white-space: nowrap; }
|
|
90
|
+
td[data-number="true"], th[data-number="true"] { text-align: right; }
|
|
91
|
+
thead th { position: sticky; top: 0; z-index: 1; background: ${ink("surface", "#fbf8f1", "#1d201e")}; padding: 0; font-size: .75rem; letter-spacing: .06em; color: ${ink("muted", "#6b6f68", "#a09d93")}; font-weight: 600; }
|
|
92
|
+
thead button { width: 100%; min-height: 44px; padding: 6px 10px; border: 0; background: transparent; text-align: inherit; white-space: nowrap; }
|
|
93
|
+
th[aria-sort] button { color: ${ink("ink", "#1f2320", "#ece8dc")}; }
|
|
94
|
+
th[aria-sort="ascending"] button::after { content: " ▲"; }
|
|
95
|
+
th[aria-sort="descending"] button::after { content: " ▼"; }
|
|
96
|
+
tbody th { font-weight: 400; }
|
|
97
|
+
td:nth-child(7), td:nth-child(8) { white-space: normal; min-width: 9rem; max-width: 16rem; }
|
|
98
|
+
tr:last-child > * { border-bottom: 0; }
|
|
99
|
+
.credits { margin-top: 20px; }
|
|
100
|
+
@media (max-width: 600px) {
|
|
101
|
+
.top { gap: 6px; margin-bottom: 8px; }
|
|
102
|
+
h2 { font-size: 1.2rem; }
|
|
103
|
+
.lede { display: none; }
|
|
104
|
+
.short { display: block; }
|
|
105
|
+
}
|
|
106
|
+
</style>
|
|
107
|
+
<section class="top" part="top">
|
|
108
|
+
<h2 id="moons-h" part="title"></h2>
|
|
109
|
+
<slot name="planets"></slot>
|
|
110
|
+
<p class="fine lede" id="lede"></p>
|
|
111
|
+
<p class="fine short" id="short"></p>
|
|
112
|
+
</section>
|
|
113
|
+
<div class="panels" part="panels">
|
|
114
|
+
<div class="tabs" role="tablist" id="tabs" data-w-label="tabs">
|
|
115
|
+
<button type="button" role="tab" id="tab-orbits" aria-controls="panel-orbits" data-tab="orbits" data-w="tab_orbits"></button>
|
|
116
|
+
<button type="button" role="tab" id="tab-views" aria-controls="panel-views" data-tab="views" data-w="tab_views"></button>
|
|
117
|
+
<button type="button" role="tab" id="tab-cards" aria-controls="panel-cards" data-tab="cards" data-w="tab_cards"></button>
|
|
118
|
+
<button type="button" role="tab" id="tab-table" aria-controls="panel-table" data-tab="table" data-w="tab_table"></button>
|
|
119
|
+
</div>
|
|
120
|
+
<div class="panel" role="tabpanel" id="panel-orbits" aria-labelledby="tab-orbits">
|
|
121
|
+
<div class="row">
|
|
122
|
+
<div class="seg" id="view" role="group" data-w-label="view"><button type="button" data-view="above" data-w="above"></button><button type="button" data-view="tilted" data-w="tilted"></button><button type="button" data-view="side" data-w="side"></button></div>
|
|
123
|
+
<div class="seg" id="reach" role="group" data-w-label="reach"><button type="button" data-reach="all" data-w="all"></button><button type="button" data-reach="inner" data-w="inner"></button></div>
|
|
124
|
+
<div class="seg" id="colour" role="group" data-w-label="colour"><button type="button" data-colour="direction" data-w="direction"></button><button type="button" data-colour="group" data-w="family"></button></div>
|
|
125
|
+
</div>
|
|
126
|
+
<div class="stage">
|
|
127
|
+
<svg id="orbits" class="orbits" role="img" aria-labelledby="orbit-caption"></svg>
|
|
128
|
+
<div class="side">
|
|
129
|
+
<ul class="key" id="key"></ul>
|
|
130
|
+
<p class="fine pick" id="pick" role="status"></p>
|
|
131
|
+
<p class="fine" id="orbit-caption"></p>
|
|
132
|
+
<p class="fine" data-w="orbits_hint"></p>
|
|
133
|
+
</div>
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
<div class="panel" role="tabpanel" id="panel-views" aria-labelledby="tab-views" hidden>
|
|
137
|
+
<div class="views">
|
|
138
|
+
<figure class="plan"><div class="box" id="plan-box"></div><figcaption class="fine" id="plan-caption"></figcaption></figure>
|
|
139
|
+
<figure class="portrait"><div class="box" id="portrait-box"></div><figcaption class="fine" id="portrait-caption"></figcaption></figure>
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
<div class="panel" role="tabpanel" id="panel-cards" aria-labelledby="tab-cards" hidden>
|
|
143
|
+
<p class="fine" id="cards-intro"></p>
|
|
144
|
+
<ul class="cards" id="cards"></ul>
|
|
145
|
+
</div>
|
|
146
|
+
<div class="panel" role="tabpanel" id="panel-table" aria-labelledby="tab-table" hidden>
|
|
147
|
+
<p class="fine" id="table-intro" role="status"></p>
|
|
148
|
+
<div class="table-box" tabindex="0" role="region" aria-labelledby="tab-table">
|
|
149
|
+
<table id="table"><thead><tr>
|
|
150
|
+
<th scope="col" data-col="name"><button type="button" data-sort="name" data-w="col_name"></button></th>
|
|
151
|
+
<th scope="col" data-col="family"><button type="button" data-sort="family" data-w="col_family"></button></th>
|
|
152
|
+
<th scope="col" data-col="size" data-number="true"><button type="button" data-sort="size" data-w="col_size"></button></th>
|
|
153
|
+
<th scope="col" data-col="distance" data-number="true"><button type="button" data-sort="distance" data-w="col_distance"></button></th>
|
|
154
|
+
<th scope="col" data-col="period" data-number="true"><button type="button" data-sort="period" data-w="col_period"></button></th>
|
|
155
|
+
<th scope="col" data-col="year" data-number="true"><button type="button" data-sort="year" data-w="col_year"></button></th>
|
|
156
|
+
<th scope="col" data-col="where"><button type="button" data-sort="where" data-w="col_where"></button></th>
|
|
157
|
+
<th scope="col" data-col="by"><button type="button" data-sort="by" data-w="col_by"></button></th>
|
|
158
|
+
<th scope="col" data-col="direction"><button type="button" data-sort="direction" data-w="col_direction"></button></th>
|
|
159
|
+
</tr></thead><tbody id="rows"></tbody></table>
|
|
160
|
+
</div>
|
|
161
|
+
<p class="fine" data-w="table_note"></p>
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
<p class="fine credits" id="credits" part="credits"></p>`;
|
|
165
|
+
/**
|
|
166
|
+
* The `<wakusei-moon-pages>` custom element: one giant planet's moons in four tabs, each one screen.
|
|
167
|
+
*
|
|
168
|
+
* - **Orbits**: every orbit of `/moon-catalogue` in SVG, seen from above the planet's pole, at an angle or from the side, every moon or the inner ones, coloured prograde and retrograde or by family, with the key and a dot
|
|
169
|
+
* where each moon is on `MOON_PAGE_TIME`; pointing at an orbit, or a press on it, says whose it is.
|
|
170
|
+
* - **Map and portrait**: `<wakusei-plan>` from above the pole and a `<wakusei-portrait>` of the planet with the moons drawn in full.
|
|
171
|
+
* - **Main moons**: a card with a painted picture for each moon drawn in full, its size (three axes for a shaped one), distance, period, discovery and how its shape is known.
|
|
172
|
+
* - **Every moon**: the whole list in a table that sorts by any column, both ways; a size worked out from brightness is marked ≈, and — is a value no source gives.
|
|
173
|
+
*
|
|
174
|
+
* Attributes: `planet` (`jupiter`, the default, `saturn`, `uranus` or `neptune`; a change draws the other planet), `lang` (`en` or `ja`; the nearest `lang` up the page when left out, and it follows that one),
|
|
175
|
+
* `tab`, `view` (`above`, `tilted` or `side`), `reach` (`all` or `inner`), `colour` (`direction` or `group`), `sort` (`name`, `family`, `size`, `distance`, `period`, `year`, `where`, `by` or `direction`) and `order`
|
|
176
|
+
* (`up` or `down`), and `texture-base` and `texture-far-base`, handed to the bodies it draws. A slot named `planets` sits under the title, for a page's own row of links to the other planets.
|
|
177
|
+
*
|
|
178
|
+
* It never writes the page's address. A choice made in it is reflected on its attribute and sent as `wakusei-moon-pages-change` (bubbling, composed) with `detail` the whole `MoonPagesState`; a page that keeps its
|
|
179
|
+
* address writes the detail there and sets the attributes back from it when it loads. Setting an attribute sends no event. The numbers are `moonPage(planet)`'s, worked out in a few milliseconds. The plan, the
|
|
180
|
+
* portrait, the cards' bodies and the planet's looks are fetched only when their tab is first opened, so a page that shows only the orbits and the table loads no WebGL. Nothing runs on a timer; the orbits are drawn
|
|
181
|
+
* again only when a choice, the language or the element's width changes. `data-state` is `ready` once it has drawn.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts no-run
|
|
185
|
+
* import "@johnmorrisdotca/wakusei-planets/moon-pages/element";
|
|
186
|
+
* import type { MoonPagesState, WakuseiMoonPages } from "@johnmorrisdotca/wakusei-planets/moon-pages/element";
|
|
187
|
+
*
|
|
188
|
+
* const pages = document.createElement("wakusei-moon-pages") as WakuseiMoonPages;
|
|
189
|
+
* pages.setAttribute("planet", "saturn");
|
|
190
|
+
* pages.setAttribute("tab", "table");
|
|
191
|
+
* pages.addEventListener("wakusei-moon-pages-change", (event) => console.log((event as CustomEvent<MoonPagesState>).detail));
|
|
192
|
+
* document.body.append(pages);
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
export class WakuseiMoonPages extends HTMLElement {
|
|
196
|
+
static observedAttributes = [...STATE_KEYS, "lang", "texture-base", "texture-far-base"];
|
|
197
|
+
#root;
|
|
198
|
+
#state = { ...DEFAULTS };
|
|
199
|
+
#data;
|
|
200
|
+
#picked = null;
|
|
201
|
+
#drawn = [];
|
|
202
|
+
#extent = 1;
|
|
203
|
+
#tall = 1;
|
|
204
|
+
#width = 0;
|
|
205
|
+
#plan;
|
|
206
|
+
#portrait;
|
|
207
|
+
#cardsFor;
|
|
208
|
+
#watch;
|
|
209
|
+
#resize;
|
|
210
|
+
#reflecting = false;
|
|
211
|
+
/** What it shows now. */
|
|
212
|
+
get state() {
|
|
213
|
+
return { ...this.#state };
|
|
214
|
+
}
|
|
215
|
+
/** The numbers it draws: `moonPage(planet)`. */
|
|
216
|
+
get page() {
|
|
217
|
+
return this.#page();
|
|
218
|
+
}
|
|
219
|
+
connectedCallback() {
|
|
220
|
+
if (this.#root === undefined) {
|
|
221
|
+
this.#root = this.attachShadow({ mode: "open" });
|
|
222
|
+
this.#root.innerHTML = TEMPLATE;
|
|
223
|
+
this.#bind();
|
|
224
|
+
}
|
|
225
|
+
this.#read();
|
|
226
|
+
this.#watch = new MutationObserver(() => {
|
|
227
|
+
if (!this.hasAttribute("lang"))
|
|
228
|
+
this.#render();
|
|
229
|
+
});
|
|
230
|
+
this.#watch.observe(document.documentElement, { attributes: true, attributeFilter: ["lang"] });
|
|
231
|
+
const near = this.parentElement?.closest("[lang]");
|
|
232
|
+
if (near !== null && near !== undefined && near !== document.documentElement)
|
|
233
|
+
this.#watch.observe(near, { attributes: true, attributeFilter: ["lang"] });
|
|
234
|
+
if (typeof ResizeObserver === "function") {
|
|
235
|
+
this.#resize = new ResizeObserver(() => {
|
|
236
|
+
const width = this.#$("#orbits").getBoundingClientRect().width;
|
|
237
|
+
if (Math.abs(width - this.#width) > 1 && this.#state.tab === "orbits")
|
|
238
|
+
this.#drawOrbits();
|
|
239
|
+
});
|
|
240
|
+
this.#resize.observe(this);
|
|
241
|
+
}
|
|
242
|
+
this.#render();
|
|
243
|
+
}
|
|
244
|
+
disconnectedCallback() {
|
|
245
|
+
this.#watch?.disconnect();
|
|
246
|
+
this.#resize?.disconnect();
|
|
247
|
+
}
|
|
248
|
+
attributeChangedCallback(name, before, after) {
|
|
249
|
+
if (this.#reflecting || before === after || this.#root === undefined)
|
|
250
|
+
return;
|
|
251
|
+
if (STATE_KEYS.includes(name))
|
|
252
|
+
this.#read();
|
|
253
|
+
this.#render();
|
|
254
|
+
}
|
|
255
|
+
// --- reading and writing the state --------------------------------------------------------------------------------------------------------------------
|
|
256
|
+
#read() {
|
|
257
|
+
const next = { ...DEFAULTS };
|
|
258
|
+
for (const key of STATE_KEYS) {
|
|
259
|
+
const value = this.getAttribute(key);
|
|
260
|
+
if (value !== null && ALLOWED[key].includes(value))
|
|
261
|
+
next[key] = value;
|
|
262
|
+
}
|
|
263
|
+
if (next.planet !== this.#state.planet)
|
|
264
|
+
this.#picked = null;
|
|
265
|
+
this.#state = next;
|
|
266
|
+
}
|
|
267
|
+
/** A choice made here: kept, reflected on the attributes, sent. */
|
|
268
|
+
#choose(change) {
|
|
269
|
+
this.#state = { ...this.#state, ...change };
|
|
270
|
+
this.#reflecting = true;
|
|
271
|
+
for (const key of STATE_KEYS) {
|
|
272
|
+
const value = this.#state[key];
|
|
273
|
+
if (value === DEFAULTS[key] && key !== "planet")
|
|
274
|
+
this.removeAttribute(key);
|
|
275
|
+
else if (this.getAttribute(key) !== value)
|
|
276
|
+
this.setAttribute(key, value);
|
|
277
|
+
}
|
|
278
|
+
this.#reflecting = false;
|
|
279
|
+
this.#render();
|
|
280
|
+
this.dispatchEvent(new CustomEvent("wakusei-moon-pages-change", { detail: this.state, bubbles: true, composed: true }));
|
|
281
|
+
}
|
|
282
|
+
#page() {
|
|
283
|
+
if (this.#data?.host !== this.#state.planet)
|
|
284
|
+
this.#data = moonPage(this.#state.planet);
|
|
285
|
+
return this.#data;
|
|
286
|
+
}
|
|
287
|
+
// --- words ---------------------------------------------------------------------------------------------------------------------------------------------
|
|
288
|
+
#lang() {
|
|
289
|
+
const own = this.getAttribute("lang") ?? this.closest("[lang]")?.getAttribute("lang") ?? "en";
|
|
290
|
+
return own.toLowerCase().startsWith("ja") ? "ja" : "en";
|
|
291
|
+
}
|
|
292
|
+
#say(key, values = {}) {
|
|
293
|
+
return MOON_PAGE_WORDS[this.#lang()][key].replace(/\{(\w+)\}/g, (all, name) => String(values[name] ?? all));
|
|
294
|
+
}
|
|
295
|
+
#number(n, digits = 0) {
|
|
296
|
+
return n.toLocaleString(this.#lang() === "ja" ? "ja-JP" : "en-CA", { maximumFractionDigits: digits, minimumFractionDigits: digits });
|
|
297
|
+
}
|
|
298
|
+
#day(ms) {
|
|
299
|
+
return new Date(ms).toLocaleDateString(this.#lang() === "ja" ? "ja-JP" : "en-CA", { dateStyle: "long", timeZone: "UTC" });
|
|
300
|
+
}
|
|
301
|
+
#diameter(radius) {
|
|
302
|
+
const d = 2 * radius;
|
|
303
|
+
return this.#number(d, d < 10 ? 1 : 0);
|
|
304
|
+
}
|
|
305
|
+
#period(days) {
|
|
306
|
+
return this.#number(days, days < 10 ? 2 : 1);
|
|
307
|
+
}
|
|
308
|
+
#moonName(m) {
|
|
309
|
+
return this.#lang() === "ja" && m.ja !== null ? m.ja : m.en;
|
|
310
|
+
}
|
|
311
|
+
#planetName() {
|
|
312
|
+
return this.#page().name[this.#lang()];
|
|
313
|
+
}
|
|
314
|
+
#$(selector) {
|
|
315
|
+
return this.#root.querySelector(selector);
|
|
316
|
+
}
|
|
317
|
+
#$$(selector) {
|
|
318
|
+
return [...this.#root.querySelectorAll(selector)];
|
|
319
|
+
}
|
|
320
|
+
// --- the events --------------------------------------------------------------------------------------------------------------------------------------------
|
|
321
|
+
#bind() {
|
|
322
|
+
const tabs = this.#$$("[role=tab]");
|
|
323
|
+
for (const button of tabs) {
|
|
324
|
+
button.addEventListener("click", () => this.#choose({ tab: button.dataset["tab"] }));
|
|
325
|
+
button.addEventListener("keydown", (event) => {
|
|
326
|
+
const at = MOON_PAGE_TABS.indexOf(this.#state.tab);
|
|
327
|
+
const step = event.key === "ArrowRight" ? 1 : event.key === "ArrowLeft" ? -1 : 0;
|
|
328
|
+
let next;
|
|
329
|
+
if (event.key === "Home")
|
|
330
|
+
next = MOON_PAGE_TABS[0];
|
|
331
|
+
else if (event.key === "End")
|
|
332
|
+
next = MOON_PAGE_TABS[MOON_PAGE_TABS.length - 1];
|
|
333
|
+
else if (step !== 0)
|
|
334
|
+
next = MOON_PAGE_TABS[(at + step + MOON_PAGE_TABS.length) % MOON_PAGE_TABS.length];
|
|
335
|
+
if (next === undefined)
|
|
336
|
+
return;
|
|
337
|
+
event.preventDefault();
|
|
338
|
+
this.#choose({ tab: next });
|
|
339
|
+
this.#$(`#tab-${next}`).focus();
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
for (const b of this.#$$("#view [data-view]"))
|
|
343
|
+
b.addEventListener("click", () => this.#choose({ view: b.dataset["view"] }));
|
|
344
|
+
for (const b of this.#$$("#reach [data-reach]"))
|
|
345
|
+
b.addEventListener("click", () => this.#choose({ reach: b.dataset["reach"] }));
|
|
346
|
+
for (const b of this.#$$("#colour [data-colour]"))
|
|
347
|
+
b.addEventListener("click", () => this.#choose({ colour: b.dataset["colour"] }));
|
|
348
|
+
for (const b of this.#$$("thead button[data-sort]")) {
|
|
349
|
+
b.addEventListener("click", () => {
|
|
350
|
+
const column = b.dataset["sort"];
|
|
351
|
+
this.#choose(column === this.#state.sort ? { order: this.#state.order === "down" ? "up" : "down" } : { sort: column, order: "up" });
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
const svg = this.#$("#orbits");
|
|
355
|
+
svg.addEventListener("pointermove", (event) => {
|
|
356
|
+
if (event.pointerType === "mouse")
|
|
357
|
+
this.#light(this.#nearest(event.clientX, event.clientY));
|
|
358
|
+
});
|
|
359
|
+
svg.addEventListener("pointerdown", (event) => this.#light(this.#nearest(event.clientX, event.clientY)));
|
|
360
|
+
}
|
|
361
|
+
// --- drawing -------------------------------------------------------------------------------------------------------------------------------------------
|
|
362
|
+
#render() {
|
|
363
|
+
if (this.#root === undefined || !this.isConnected)
|
|
364
|
+
return;
|
|
365
|
+
const data = this.#page();
|
|
366
|
+
const planet = this.#planetName();
|
|
367
|
+
const c = data.counts;
|
|
368
|
+
for (const el of this.#$$("[data-w]"))
|
|
369
|
+
el.textContent = this.#say(el.dataset["w"]);
|
|
370
|
+
for (const el of this.#$$("[data-w-label]"))
|
|
371
|
+
el.setAttribute("aria-label", this.#say(el.dataset["wLabel"]));
|
|
372
|
+
this.#$("#moons-h").textContent = this.#say("title", { planet });
|
|
373
|
+
this.#$("#lede").textContent = this.#say("lede", { total: this.#number(c.total), named: this.#number(c.named), prograde: this.#number(c.prograde), retrograde: this.#number(c.retrograde), planet, featured: this.#number(c.featured) });
|
|
374
|
+
this.#$("#short").textContent = this.#say("short", { total: this.#number(c.total), named: this.#number(c.named), retrograde: this.#number(c.retrograde) });
|
|
375
|
+
this.#$("#credits").textContent = this.#say("credits", { fetched: this.#day(Date.parse(`${data.fetched}T00:00:00Z`)) });
|
|
376
|
+
for (const button of this.#$$("[role=tab]")) {
|
|
377
|
+
const on = button.dataset["tab"] === this.#state.tab;
|
|
378
|
+
button.setAttribute("aria-selected", String(on));
|
|
379
|
+
button.tabIndex = on ? 0 : -1;
|
|
380
|
+
this.#$(`#${button.getAttribute("aria-controls")}`).hidden = !on;
|
|
381
|
+
}
|
|
382
|
+
for (const b of this.#$$("#view [data-view]"))
|
|
383
|
+
b.setAttribute("aria-pressed", String(b.dataset["view"] === this.#state.view));
|
|
384
|
+
for (const b of this.#$$("#reach [data-reach]"))
|
|
385
|
+
b.setAttribute("aria-pressed", String(b.dataset["reach"] === this.#state.reach));
|
|
386
|
+
for (const b of this.#$$("#colour [data-colour]"))
|
|
387
|
+
b.setAttribute("aria-pressed", String(b.dataset["colour"] === this.#state.colour));
|
|
388
|
+
if (this.#state.tab === "orbits") {
|
|
389
|
+
this.#drawOrbits();
|
|
390
|
+
this.#drawKey();
|
|
391
|
+
this.#$("#orbit-caption").textContent = this.#say("orbit_caption", { date: this.#day(data.time) });
|
|
392
|
+
}
|
|
393
|
+
if (this.#state.tab === "views")
|
|
394
|
+
this.#mountViews();
|
|
395
|
+
if (this.#state.tab === "cards")
|
|
396
|
+
this.#drawCards();
|
|
397
|
+
if (this.#state.tab === "table")
|
|
398
|
+
this.#drawTable();
|
|
399
|
+
this.setAttribute("data-state", "ready");
|
|
400
|
+
}
|
|
401
|
+
#drawOrbits() {
|
|
402
|
+
const data = this.#page();
|
|
403
|
+
const svg = this.#$("#orbits");
|
|
404
|
+
const placed = data.moons.filter((m) => m.orbit !== null);
|
|
405
|
+
const elevation = ELEVATION[this.#state.view];
|
|
406
|
+
const rad = (elevation * Math.PI) / 180;
|
|
407
|
+
const project = (x, y, z) => [x, y * Math.sin(rad) + z * Math.cos(rad)];
|
|
408
|
+
const reach = this.#state.reach === "all" ? Math.max(...placed.map((m) => Math.max(...m.orbit.map(Math.abs)))) : data.inner;
|
|
409
|
+
// the picture is as tall as the orbits that fit across it reach up and down from this angle, so a tilted view is not mostly empty
|
|
410
|
+
let up = 0;
|
|
411
|
+
for (const moon of placed) {
|
|
412
|
+
const o = moon.orbit;
|
|
413
|
+
let fits = true;
|
|
414
|
+
let high = 0;
|
|
415
|
+
for (let k = 0; k < o.length; k += 3) {
|
|
416
|
+
if (Math.abs(o[k]) > reach * 1.001)
|
|
417
|
+
fits = false;
|
|
418
|
+
high = Math.max(high, Math.abs(project(o[k], o[k + 1], o[k + 2])[1]));
|
|
419
|
+
}
|
|
420
|
+
if (fits)
|
|
421
|
+
up = Math.max(up, high);
|
|
422
|
+
}
|
|
423
|
+
const extent = reach * 1.06;
|
|
424
|
+
const tall = Math.min(extent, Math.max(up * 1.06, extent * 0.4));
|
|
425
|
+
this.#extent = extent;
|
|
426
|
+
this.#tall = tall;
|
|
427
|
+
svg.style.setProperty("--ratio", String(extent / tall));
|
|
428
|
+
// the more lines, the fainter each: Saturn's 292 would otherwise be a solid block
|
|
429
|
+
svg.style.setProperty("--line", String(Math.min(0.6, 6 / Math.sqrt(placed.length))));
|
|
430
|
+
svg.setAttribute("viewBox", `${-extent} ${-tall} ${2 * extent} ${2 * tall}`);
|
|
431
|
+
this.#width = svg.getBoundingClientRect().width;
|
|
432
|
+
const px = (2 * extent) / (this.#width || 600);
|
|
433
|
+
const colourOf = (m) => m.colour[this.#state.colour];
|
|
434
|
+
const back = [];
|
|
435
|
+
const front = [];
|
|
436
|
+
this.#drawn = [];
|
|
437
|
+
// the irregular moons first and the moons drawn in full last, so the big moons' lines lie on top
|
|
438
|
+
const order = [...placed].sort((a, b) => Number(a.full) - Number(b.full) || (b.a ?? 0) - (a.a ?? 0));
|
|
439
|
+
for (const moon of order) {
|
|
440
|
+
const o = moon.orbit;
|
|
441
|
+
const points = [];
|
|
442
|
+
const depth = [];
|
|
443
|
+
for (let k = 0; k < o.length; k += 3) {
|
|
444
|
+
const [sx, sy] = project(o[k], o[k + 1], o[k + 2]);
|
|
445
|
+
points.push([sx, -sy]);
|
|
446
|
+
depth.push(-o[k + 1] * Math.cos(rad) + o[k + 2] * Math.sin(rad));
|
|
447
|
+
}
|
|
448
|
+
this.#drawn.push({ id: moon.id, points });
|
|
449
|
+
// seen from above everything is one path; otherwise each step of the line goes to the side of the planet its middle is on (the far side drawn before the planet, the near side after it), with no gap
|
|
450
|
+
const path = (side) => {
|
|
451
|
+
const n = points.length;
|
|
452
|
+
const inside = (k) => side === "all" || (depth[k % n] + depth[(k + 1) % n] > 0) === (side === "near");
|
|
453
|
+
let d = "";
|
|
454
|
+
for (let k = 0; k < n; k += 1) {
|
|
455
|
+
if (!inside(k))
|
|
456
|
+
continue;
|
|
457
|
+
if (k === 0 || !inside(k - 1))
|
|
458
|
+
d += `M${points[k][0]} ${points[k][1]}`;
|
|
459
|
+
const [x, y] = points[(k + 1) % n];
|
|
460
|
+
d += `L${x} ${y}`;
|
|
461
|
+
}
|
|
462
|
+
return d === "" ? "" : `<path d="${d}" stroke="${colourOf(moon)}" stroke-width="${moon.full ? 1.8 : 1}" data-id="${moon.id}" data-dir="${moon.retro === 1 ? "retrograde" : "prograde"}"${moon.full ? ' data-full=""' : ""}/>`;
|
|
463
|
+
};
|
|
464
|
+
if (elevation === 90)
|
|
465
|
+
back.push(path("all"));
|
|
466
|
+
else {
|
|
467
|
+
back.push(path("far"));
|
|
468
|
+
front.push(path("near"));
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
const dots = [];
|
|
472
|
+
const names = [];
|
|
473
|
+
for (const moon of placed) {
|
|
474
|
+
if (moon.at === null)
|
|
475
|
+
continue;
|
|
476
|
+
const [sx, sy] = project(moon.at[0], moon.at[1], moon.at[2]);
|
|
477
|
+
if (Math.abs(sx) > extent || Math.abs(sy) > tall)
|
|
478
|
+
continue;
|
|
479
|
+
dots.push(`<circle cx="${sx}" cy="${-sy}" r="${(moon.full ? 1.4 : 1) * 2.6 * px}" fill="${colourOf(moon)}" data-id="${moon.id}"/>`);
|
|
480
|
+
if (moon.full && (this.#state.reach === "inner" || (moon.a ?? 0) / data.unit > extent / 8))
|
|
481
|
+
names.push(`<text x="${sx + 5 * px}" y="${-sy - 5 * px}" font-size="${12 * px}">${escape(this.#moonName(moon))}</text>`);
|
|
482
|
+
}
|
|
483
|
+
const planetR = Math.max(data.radiusKm / data.unit, 4 * px);
|
|
484
|
+
const title = this.#say(`view_${this.#state.view}`, { planet: this.#planetName() });
|
|
485
|
+
svg.innerHTML = `<title>${escape(title)}</title><g class="lines" fill="none" stroke-linejoin="round">${back.join("")}</g><circle class="planet" cx="0" cy="0" r="${planetR}" fill="${data.colour}"/><g class="lines" fill="none" stroke-linejoin="round">${front.join("")}</g><g class="dots">${dots.join("")}</g><g class="names" fill="currentColor">${names.join("")}</g><g class="lit" fill="none"></g>`;
|
|
486
|
+
svg.dataset["view"] = this.#state.view;
|
|
487
|
+
svg.dataset["reach"] = this.#state.reach;
|
|
488
|
+
svg.dataset["colour"] = this.#state.colour;
|
|
489
|
+
svg.dataset["orbits"] = String(placed.length);
|
|
490
|
+
this.#light(this.#picked);
|
|
491
|
+
}
|
|
492
|
+
/** The orbit under a point of the picture (within 10 CSS pixels), or null. */
|
|
493
|
+
#nearest(clientX, clientY) {
|
|
494
|
+
const box = this.#$("#orbits").getBoundingClientRect();
|
|
495
|
+
if (box.width === 0)
|
|
496
|
+
return null;
|
|
497
|
+
const k = (2 * this.#extent) / box.width;
|
|
498
|
+
const x = (clientX - box.left) * k - this.#extent;
|
|
499
|
+
const y = (clientY - box.top) * k - this.#tall;
|
|
500
|
+
let best = null;
|
|
501
|
+
let bestD = 10 * k;
|
|
502
|
+
for (const orbit of this.#drawn) {
|
|
503
|
+
const p = orbit.points;
|
|
504
|
+
for (let i = 0; i < p.length; i += 1) {
|
|
505
|
+
const [ax, ay] = p[i];
|
|
506
|
+
const [bx, by] = p[(i + 1) % p.length];
|
|
507
|
+
const dx = bx - ax;
|
|
508
|
+
const dy = by - ay;
|
|
509
|
+
const t = Math.max(0, Math.min(1, ((x - ax) * dx + (y - ay) * dy) / (dx * dx + dy * dy || 1)));
|
|
510
|
+
const d = Math.hypot(x - ax - t * dx, y - ay - t * dy);
|
|
511
|
+
if (d < bestD) {
|
|
512
|
+
bestD = d;
|
|
513
|
+
best = orbit.id;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return best;
|
|
518
|
+
}
|
|
519
|
+
/** Light one orbit and say whose it is. */
|
|
520
|
+
#light(id) {
|
|
521
|
+
this.#picked = id;
|
|
522
|
+
const svg = this.#$("#orbits");
|
|
523
|
+
const lit = svg.querySelector(".lit");
|
|
524
|
+
const moon = id === null ? undefined : this.#page().moons.find((m) => m.id === id);
|
|
525
|
+
const orbit = id === null ? undefined : this.#drawn.find((o) => o.id === id);
|
|
526
|
+
if (lit !== null)
|
|
527
|
+
lit.innerHTML = moon === undefined || orbit === undefined ? "" : `<path d="M${orbit.points.map(([x, y]) => `${x} ${y}`).join("L")}Z" stroke="${moon.colour[this.#state.colour]}" stroke-width="3.2"/>`;
|
|
528
|
+
svg.dataset["picked"] = id ?? "";
|
|
529
|
+
this.#$("#pick").textContent =
|
|
530
|
+
moon === undefined || moon.a === null || moon.p === null
|
|
531
|
+
? ""
|
|
532
|
+
: this.#say("pick", { name: this.#moonName(moon), direction: this.#say(moon.retro === 1 ? "retrograde" : "prograde"), distance: this.#number(moon.a), planet: this.#planetName(), period: this.#period(moon.p) });
|
|
533
|
+
}
|
|
534
|
+
#drawKey() {
|
|
535
|
+
this.#$("#key").innerHTML = this.#page()
|
|
536
|
+
.key[this.#state.colour].filter((entry) => entry.count > 0)
|
|
537
|
+
.map((entry) => `<li data-key="${entry.id}"><span class="swatch" style="background:${entry.color}"></span><span>${escape(entry.names[this.#lang()])}</span> <b>${this.#number(entry.count)}</b></li>`)
|
|
538
|
+
.join("");
|
|
539
|
+
}
|
|
540
|
+
#textures(el) {
|
|
541
|
+
for (const name of ["texture-base", "texture-far-base"]) {
|
|
542
|
+
const value = this.getAttribute(name);
|
|
543
|
+
if (value === null)
|
|
544
|
+
el.removeAttribute(name);
|
|
545
|
+
else
|
|
546
|
+
el.setAttribute(name, value);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
#mountViews() {
|
|
550
|
+
const data = this.#page();
|
|
551
|
+
const host = data.host;
|
|
552
|
+
if (this.#plan?.getAttribute("system") !== host) {
|
|
553
|
+
void import("../plan/element.js");
|
|
554
|
+
void LOOKS[host]().then(() => import("../portrait/element.js"));
|
|
555
|
+
const plan = document.createElement("wakusei-plan");
|
|
556
|
+
plan.setAttribute("system", host);
|
|
557
|
+
plan.setAttribute("size", "300");
|
|
558
|
+
plan.setAttribute("time", String(data.time));
|
|
559
|
+
plan.setAttribute("mark", MOONS_OF[host][0]);
|
|
560
|
+
plan.addEventListener("wakusei-plan-pick", (event) => plan.setAttribute("mark", event.detail.id));
|
|
561
|
+
this.#$("#plan-box").replaceChildren(plan);
|
|
562
|
+
this.#plan = plan;
|
|
563
|
+
const portrait = document.createElement("wakusei-portrait");
|
|
564
|
+
const scene = { ...addMoons(addBody(defaultPortrait(), host), host), arrange: "row", scale: "readable", orbits: false };
|
|
565
|
+
portrait.setAttribute("scene", encodeScene(scene));
|
|
566
|
+
this.#$("#portrait-box").replaceChildren(portrait);
|
|
567
|
+
this.#portrait = portrait;
|
|
568
|
+
}
|
|
569
|
+
for (const el of [this.#plan, this.#portrait])
|
|
570
|
+
el.setAttribute("lang", this.#lang());
|
|
571
|
+
this.#textures(this.#portrait);
|
|
572
|
+
this.#$("#plan-caption").textContent = this.#say("plan_caption", { planet: this.#planetName(), date: this.#day(data.time) });
|
|
573
|
+
this.#$("#portrait-caption").textContent = this.#say("portrait_caption", { planet: this.#planetName() });
|
|
574
|
+
}
|
|
575
|
+
#drawCards() {
|
|
576
|
+
const data = this.#page();
|
|
577
|
+
const list = this.#$("#cards");
|
|
578
|
+
if (this.#cardsFor !== data.host) {
|
|
579
|
+
this.#cardsFor = data.host;
|
|
580
|
+
void LOOKS[data.host]().then(() => import("../element.js"));
|
|
581
|
+
list.replaceChildren(...data.cards.map((card) => {
|
|
582
|
+
const item = document.createElement("li");
|
|
583
|
+
item.className = "moons-card";
|
|
584
|
+
item.dataset["id"] = card.id;
|
|
585
|
+
const frame = document.createElement("div");
|
|
586
|
+
frame.className = "picture";
|
|
587
|
+
const body = document.createElement("wakusei-body");
|
|
588
|
+
body.setAttribute("body", card.id);
|
|
589
|
+
body.setAttribute("look", "painted");
|
|
590
|
+
body.setAttribute("live", "off");
|
|
591
|
+
body.setAttribute("fit", "tight");
|
|
592
|
+
frame.append(body);
|
|
593
|
+
const words = document.createElement("div");
|
|
594
|
+
words.className = "words";
|
|
595
|
+
item.append(frame, words);
|
|
596
|
+
return item;
|
|
597
|
+
}));
|
|
598
|
+
}
|
|
599
|
+
const shaped = data.counts.shaped;
|
|
600
|
+
this.#$("#cards-intro").textContent = `${this.#say("cards_intro", { n: data.cards.length, planet: this.#planetName() })}${shaped > 0 ? ` ${this.#say("cards_shaped", { shaped })}` : ""}`;
|
|
601
|
+
for (const item of this.#$$("#cards .moons-card")) {
|
|
602
|
+
const card = data.cards.find((c) => c.id === item.dataset["id"]);
|
|
603
|
+
const body = item.querySelector("wakusei-body");
|
|
604
|
+
body.setAttribute("lang", this.#lang());
|
|
605
|
+
this.#textures(body);
|
|
606
|
+
const size = card.axesKm === null ? [this.#say("card_size"), `${this.#diameter(card.radiusKm)} km`] : [this.#say("card_axes"), `${card.axesKm.map((a) => this.#number(2 * a, 2 * a < 10 ? 1 : 0)).join(" × ")} km`];
|
|
607
|
+
const rows = [
|
|
608
|
+
[size[0], size[1]],
|
|
609
|
+
[this.#say("card_distance"), card.a === null ? NONE : `${this.#number(card.a)} km`],
|
|
610
|
+
[this.#say("card_period"), card.p === null ? NONE : `${this.#say("days", { n: this.#period(card.p) })}${card.retro ? ` (${this.#say("retrograde")})` : ""}`],
|
|
611
|
+
[this.#say("card_found"), card.date ?? NONE],
|
|
612
|
+
[this.#say("card_where"), card.where ?? NONE],
|
|
613
|
+
[this.#say("card_by"), card.by ?? NONE],
|
|
614
|
+
];
|
|
615
|
+
const other = this.#lang() === "ja" ? card.name.en : card.name.ja;
|
|
616
|
+
item.querySelector(".words").innerHTML =
|
|
617
|
+
`<h3>${escape(card.name[this.#lang()])} <span class="fine">${escape(other)}</span></h3><dl>${rows.map(([k, v]) => `<dt>${escape(k)}</dt><dd>${escape(v)}</dd>`).join("")}</dl>` +
|
|
618
|
+
(card.shape === null ? "" : `<p class="fine">${escape(card.shape[this.#lang()])}</p>`);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
#drawTable() {
|
|
622
|
+
const data = this.#page();
|
|
623
|
+
const { sort } = this.#state;
|
|
624
|
+
const down = this.#state.order === "down";
|
|
625
|
+
const familyName = (id) => data.families.find((f) => f.id === id)?.names[this.#lang()] ?? id;
|
|
626
|
+
const valueOf = (m) => {
|
|
627
|
+
switch (sort) {
|
|
628
|
+
case "name": return this.#moonName(m);
|
|
629
|
+
case "family": return data.families.findIndex((f) => f.id === m.family);
|
|
630
|
+
case "size": return m.r;
|
|
631
|
+
case "distance": return m.a;
|
|
632
|
+
case "period": return m.p;
|
|
633
|
+
case "year": return m.year;
|
|
634
|
+
case "where": return m.where;
|
|
635
|
+
case "by": return m.by;
|
|
636
|
+
case "direction": return m.retro;
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
const collator = new Intl.Collator(this.#lang() === "ja" ? "ja" : "en", { numeric: true, sensitivity: "base" });
|
|
640
|
+
const rows = [...data.moons].sort((p, q) => {
|
|
641
|
+
const a = valueOf(p);
|
|
642
|
+
const b = valueOf(q);
|
|
643
|
+
if (a === null || b === null)
|
|
644
|
+
return a === b ? 0 : a === null ? 1 : -1;
|
|
645
|
+
const c = typeof a === "number" && typeof b === "number" ? a - b : collator.compare(String(a), String(b));
|
|
646
|
+
return (down ? -c : c) || (p.a ?? Infinity) - (q.a ?? Infinity);
|
|
647
|
+
});
|
|
648
|
+
this.#$("#rows").innerHTML = rows
|
|
649
|
+
.map((m) => {
|
|
650
|
+
const size = m.r === null ? NONE : `${m.est ? "≈ " : ""}${this.#diameter(m.r)}`;
|
|
651
|
+
const direction = m.retro === null ? NONE : `<span class="swatch" style="background:${m.colour.direction}"></span>${escape(this.#say(m.retro === 1 ? "retrograde" : "prograde"))}`;
|
|
652
|
+
const name = escape(this.#moonName(m));
|
|
653
|
+
return (`<tr data-id="${m.id}"${m.full ? ' data-full=""' : ""}><th scope="row">${m.full ? `<b>${name}</b>` : name}</th><td>${escape(familyName(m.family))}</td>` +
|
|
654
|
+
`<td data-number="true"${m.est ? ' data-estimate=""' : ""}>${size}</td><td data-number="true">${m.a === null ? NONE : this.#number(m.a)}</td><td data-number="true">${m.p === null ? NONE : this.#period(m.p)}</td>` +
|
|
655
|
+
`<td data-number="true">${m.year ?? NONE}</td><td>${escape(m.where ?? NONE)}</td><td>${escape(m.by ?? NONE)}</td><td>${direction}</td></tr>`);
|
|
656
|
+
})
|
|
657
|
+
.join("");
|
|
658
|
+
for (const th of this.#$$("thead th")) {
|
|
659
|
+
if (th.dataset["col"] === sort)
|
|
660
|
+
th.setAttribute("aria-sort", down ? "descending" : "ascending");
|
|
661
|
+
else
|
|
662
|
+
th.removeAttribute("aria-sort");
|
|
663
|
+
}
|
|
664
|
+
const header = this.#$(`thead button[data-sort="${sort}"]`).textContent ?? sort;
|
|
665
|
+
const text = TEXT_COLUMNS.includes(sort);
|
|
666
|
+
this.#$("#table-intro").textContent = this.#say("table_intro", { n: data.moons.length, col: header, order: this.#say(text ? (down ? "za" : "az") : down ? "down" : "up") });
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
if (typeof customElements !== "undefined" && !customElements.get("wakusei-moon-pages"))
|
|
670
|
+
customElements.define("wakusei-moon-pages", WakuseiMoonPages);
|