@johnmorrisdotca/chikyu-earth 0.35.0 → 0.36.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 (44) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/NOTICE.md +23 -1
  3. package/README.md +20 -2
  4. package/dist/borders/layer.d.ts +75 -0
  5. package/dist/borders/layer.js +136 -0
  6. package/dist/borders/lines.d.ts +138 -0
  7. package/dist/borders/lines.js +227 -0
  8. package/dist/cities/host.d.ts +9 -0
  9. package/dist/cities/host.js +14 -2
  10. package/dist/country-names/geometry.d.ts +264 -0
  11. package/dist/country-names/geometry.js +372 -0
  12. package/dist/country-names/host.d.ts +82 -0
  13. package/dist/country-names/host.js +212 -0
  14. package/dist/grid/layer.d.ts +45 -0
  15. package/dist/grid/layer.js +66 -0
  16. package/dist/grid/lines.d.ts +85 -0
  17. package/dist/grid/lines.js +113 -0
  18. package/dist/markers/go-to-place.d.ts +27 -0
  19. package/dist/markers/go-to-place.js +35 -0
  20. package/dist/markers/index.d.ts +2 -1
  21. package/dist/markers/index.js +2 -1
  22. package/dist/markers/layer.d.ts +7 -0
  23. package/dist/markers/layer.js +7 -0
  24. package/dist/markers/place-layer.d.ts +58 -7
  25. package/dist/markers/place-layer.js +326 -64
  26. package/dist/markers/place-sprites.d.ts +33 -0
  27. package/dist/markers/place-sprites.js +161 -0
  28. package/dist/markers/places.d.ts +91 -6
  29. package/dist/markers/places.js +135 -6
  30. package/dist/realistic/earth.d.ts +11 -0
  31. package/dist/realistic/earth.js +54 -0
  32. package/dist/realistic/element.d.ts +65 -4
  33. package/dist/realistic/element.js +198 -26
  34. package/dist/realistic/immersive.d.ts +7 -0
  35. package/dist/realistic/immersive.js +17 -0
  36. package/dist/realistic/index.d.ts +6 -0
  37. package/dist/realistic/index.js +3 -0
  38. package/dist/realistic/textures.d.ts +3 -0
  39. package/dist/space/element.d.ts +81 -7
  40. package/dist/space/element.js +246 -16
  41. package/dist/space/index.d.ts +1 -1
  42. package/dist/space/scene.d.ts +53 -5
  43. package/dist/space/scene.js +88 -8
  44. package/package.json +3 -3
@@ -9,6 +9,10 @@ import type { SkyKeepClear } from "../sky/keep-clear.ts";
9
9
  import type { SkyLabelStyle } from "../sky/style.ts";
10
10
  import { type Place, type PlaceLook } from "../markers/places.ts";
11
11
  import { type CityNamesStyle } from "../cities/host.ts";
12
+ import { type BorderSets } from "../borders/lines.ts";
13
+ import type { BorderData, BorderStats } from "../borders/layer.ts";
14
+ import type { GridStats } from "../grid/layer.ts";
15
+ import { type CountryNamesStats, type CountryNamesStyle } from "../country-names/host.ts";
12
16
  import { setSharedRenderer, setThreeLoader } from "./shared.ts";
13
17
  export { setSharedRenderer, setThreeLoader };
14
18
  export type { CameraMode };
@@ -87,6 +91,13 @@ export declare const readTime: (value: string | null) => number | "now";
87
91
  * is sent when the strongest active shower changes, with `detail: { shower, zhr }` (`shower` is `null` when none is active).
88
92
  * `meteors-strength` (0 to 1, the property `meteorsStrength`; 1 when the page says nothing) makes them subtler: fewer streaks and fainter ones, none at 0, and nothing that is real changes.
89
93
  *
94
+ * `borders` draws the borders on the land as thin lines that turn with the Earth: `countries` (chizu's, at any size), `regions` (provinces, states and the like, from the page's `borderData.regions`,
95
+ * once the Earth is large enough to tell them apart), or both with a bare attribute. The shapes are loaded only when a set is switched on; `chikyu-borders-unavailable` is sent when they cannot be.
96
+ *
97
+ * `grid` draws the meridians and parallels on the Earth (every 30 degrees while it is small on the screen, every 15 once it is large), with the equator, the tropics, the polar circles and the prime
98
+ * meridian picked out, light on the day side and dim on the night side. `country-names` names the countries at the middle of the part of each in view, in the page's language, never over another
99
+ * name, as many as fit (40 at most, or the number given); the outlines are loaded only when it is set, and `chikyu-country-names-unavailable` is sent when they cannot be.
100
+ *
90
101
  * @example
91
102
  * ```ts no-run
92
103
  * import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
@@ -159,13 +170,32 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
159
170
  get keepClear(): SkyKeepClear[];
160
171
  set keepClear(value: readonly SkyKeepClear[] | null);
161
172
  /**
162
- * Places marked on the Earth (the attribute `places`, a JSON array): each `{ id, lon, lat, label, kind }`, `kind` being `here` (where the reader is: drawn bright and taller, with a quiet pulse) or `favourite`
163
- * (the default: quieter). Each stands up out of the ground, turns with the Earth, is hidden on its far side and keeps its size in pixels at any zoom. Names go at the top, `here` first, and never overlap
164
- * one another; one with no room is left out. The element stores nothing and sends nothing: the page hands the places over and keeps them where it likes. Setting the property writes the attribute; at most
165
- * `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight and for a reader who asked for less motion.
173
+ * Places marked on the Earth (the attribute `places`, a JSON array): each `{ id, lon, lat, label, kind, color }`, `kind` being `here` (where the reader is: drawn bright and taller, with a quiet pulse) or `favourite`
174
+ * (the default: quieter), and `color` an optional CSS colour of its own. The first `PLACE_MARKS` in sight (`here` first, then in the order given) stand up out of the ground with their names; every other place
175
+ * is a ring on the ground, all of them one draw call, and places that crowd are gathered into one ring with their count. They turn with the Earth, are hidden on its far side, are dimmer on its night side
176
+ * and keep their size in pixels at any zoom. Names never overlap one another; one with no room is left out. The element stores nothing and sends nothing: the page hands the places over and keeps them where
177
+ * it likes. Setting the property writes the attribute; at most `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight and for a reader who asked
178
+ * for less motion.
166
179
  */
167
180
  get places(): Place[];
168
181
  set places(value: readonly Place[]);
182
+ /**
183
+ * Turn the Earth so a place of `places` is in the middle, at a pace a reader can follow (at once with `smooth: false`, for a reader who asked for less motion, or before the picture is live); the zoom
184
+ * and pan stay. The place is named by its `id`, or by its label in any case. The tilt is held to 90 degrees either way, so a place more than 90 degrees of latitude from `center` comes as near the middle
185
+ * as that allows.
186
+ *
187
+ * @param text - The place's id or label.
188
+ * @param options - `smooth` (true by default).
189
+ * @returns The place, once the turn has started; `undefined` when there is no such place.
190
+ */
191
+ goToPlace(text: string, options?: {
192
+ smooth?: boolean;
193
+ }): Promise<Place | undefined>;
194
+ /**
195
+ * Whether places that crowd are gathered into one ring with their count (the attribute `place-groups`): on by default, `off` leaves every place its own ring. Setting the property writes the attribute.
196
+ */
197
+ get placeGroups(): boolean;
198
+ set placeGroups(value: boolean);
169
199
  /** How the places are drawn (the attribute `places-look`): `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 on the ground). */
170
200
  get placesLook(): PlaceLook;
171
201
  set placesLook(value: PlaceLook);
@@ -174,6 +204,27 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
174
204
  */
175
205
  get cityNamesStyle(): CityNamesStyle;
176
206
  set cityNamesStyle(value: CityNamesStyle);
207
+ /** Whether the meridians and parallels are drawn (the attribute `grid`). Setting it writes the attribute, or takes it away. */
208
+ get grid(): boolean;
209
+ set grid(value: boolean);
210
+ /**
211
+ * The look of the names of countries (`country-names`): font, weight, colour, the outline round the text, and the smallest and largest text size. Any of them may be left out; the Earth's size, the
212
+ * language and the data are not set here.
213
+ */
214
+ get countryNamesStyle(): CountryNamesStyle;
215
+ set countryNamesStyle(value: CountryNamesStyle);
216
+ /**
217
+ * Which borders are drawn (the attribute `borders`): the countries' at any size, and the regions' (provinces, states, prefectures) once the Earth is large enough on the screen to tell them apart.
218
+ * Setting it writes the attribute: both sets as `borders="countries regions"`, one as its own word, none takes the attribute away.
219
+ */
220
+ get borders(): BorderSets;
221
+ set borders(value: BorderSets);
222
+ /**
223
+ * Where the borders' shapes come from (see `BorderData`): `countries` in place of chizu's `world-geo`, and `regions`, a country's regions by its code, which draws the regions; without it none are drawn.
224
+ * Set it before `borders` is switched on: shapes already loaded are kept.
225
+ */
226
+ get borderData(): BorderData;
227
+ set borderData(value: BorderData);
177
228
  /** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
178
229
  get controller(): ViewController | undefined;
179
230
  /**
@@ -286,6 +337,10 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
286
337
  shown: number;
287
338
  labels: number;
288
339
  renders: number;
340
+ marks: number;
341
+ groups: number;
342
+ sprites: number;
343
+ omitted: number;
289
344
  };
290
345
  /** The names of cities: whether `city-names` is set and the most it asks for, the Earth's radius on the screen, the tiers of kuni's cities that have arrived and how many cities, the names shown at the last draw and how many times the layer was drawn. */
291
346
  cityNames: {
@@ -297,6 +352,12 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
297
352
  names: number;
298
353
  renders: number;
299
354
  };
355
+ /** The borders: the segments of each set, whether each was drawn at the last draw, the countries whose regions have arrived, how many times a set's lines were made, and whether a set could not be loaded. */
356
+ borders: BorderStats;
357
+ /** The grid: whether it was drawn at the last draw, whether every 15 degrees (else 30), its segments then, how many times its lines were made, and whether it could not be made. */
358
+ grid: GridStats;
359
+ /** The names of countries: whether `country-names` is set and the most it asks for, the countries loaded, the names shown at the last draw, how many times they were laid out, and whether the outlines could not be loaded. */
360
+ countryNames: CountryNamesStats;
300
361
  };
301
362
  /**
302
363
  * Apply a shared view controller's camera (yaw, tilt, zoom, pan). A change under half a pixel is not drawn, a settled change always is,
@@ -4,6 +4,7 @@
4
4
  import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
5
5
  import { adoptStyles } from "../adopt.js";
6
6
  import { airFor, readAirThickness } from "./air.js";
7
+ import { IMMERSIVE_STYLE, immersiveWheel } from "./immersive.js";
7
8
  import { NOTES_STYLE, setAirNote } from "./air-note.js";
8
9
  import { cameraCentre, createEarthItem, discRadius, lookAt, newModel } from "./earth.js";
9
10
  import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
@@ -15,15 +16,21 @@ import { folderSource } from "../door/map.js";
15
16
  import { ownCredit } from "../door/own.js";
16
17
  import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "./body-label.js";
17
18
  import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
18
- import { cleanPlaces, orthoView, readPlaces } from "../markers/places.js";
19
+ import { cleanPlaces, orthoView, readPlaceGroups, readPlaces } from "../markers/places.js";
19
20
  import { createPlaceLayer, PLACE_STYLE, readPlaceLook } from "../markers/place-layer.js";
21
+ import { aimAt, findPlace, glideView } from "../markers/go-to-place.js";
22
+ import { subsolarPoint } from "./sun.js";
20
23
  import { CITY_NAMES_ATTRIBUTES, CITY_NAMES_STYLE, createCityHost } from "../cities/host.js";
21
24
  import { project } from "../markers/project.js";
25
+ import { BORDER_ATTRIBUTES, readBorders } from "../borders/lines.js";
26
+ import { GRID_ATTRIBUTES, readGrid } from "../grid/lines.js";
27
+ import { COUNTRY_NAMES_ATTRIBUTES } from "../country-names/geometry.js";
28
+ import { COUNTRY_NAMES_STYLE, createCountryHost } from "../country-names/host.js";
22
29
  import { createGate, frameCap } from "./gate.js";
23
30
  import { setSharedRenderer, setThreeLoader, takeRenderer } from "./shared.js";
24
31
  export { setSharedRenderer, setThreeLoader };
25
32
  import { MAX_TEXTURE, TIERS } from "./tiers.js";
26
- const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative;isolation:isolate}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#overlay{position:absolute;inset:0}#overlay{pointer-events:none}" + PLACE_STYLE + SKY_STYLE + CITY_NAMES_STYLE + METEOR_NOTE_STYLE + NOTES_STYLE;
33
+ const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative;isolation:isolate}" + IMMERSIVE_STYLE + "#stage,#overlay{position:absolute;inset:0}#overlay{pointer-events:none}" + PLACE_STYLE + SKY_STYLE + COUNTRY_NAMES_STYLE + CITY_NAMES_STYLE + METEOR_NOTE_STYLE + NOTES_STYLE;
27
34
  const RAD = Math.PI / 180;
28
35
  /** The Sun and the clouds are re-placed this often at real time: 15 degrees an hour is 0.25 degree a minute. */
29
36
  const LIVE_TICK_MS = 60_000;
@@ -48,8 +55,6 @@ const readCentre = (value) => {
48
55
  const readCamera = (value) => (value === "ground" || value === "sun" ? value : "space");
49
56
  /** A `cloud-drift` attribute: degrees an hour the clouds are made to move eastward against the ground (0, the default: where the picture has them). */
50
57
  const readDrift = (value) => (value !== null && Number.isFinite(Number(value)) ? Number(value) : 0);
51
- /** The plain wheel in an immersive view is a pinch of this share: a notch (100) zooms about 1.2 times, as the family's mouse wheel does with Alt. */
52
- const WHEEL_AS_PINCH = 0.2;
53
58
  /** The quickest a satellite goes round, degrees a second (a low orbit: 88 minutes). */
54
59
  const SATELLITE_RATE = 360 / (88 * 60);
55
60
  const SATELLITE_COLORS = ["#ffd54f", "#7fd4ff", "#ff8fa3", "#9ef0a8"];
@@ -116,6 +121,13 @@ export const readTime = (value) => {
116
121
  * is sent when the strongest active shower changes, with `detail: { shower, zhr }` (`shower` is `null` when none is active).
117
122
  * `meteors-strength` (0 to 1, the property `meteorsStrength`; 1 when the page says nothing) makes them subtler: fewer streaks and fainter ones, none at 0, and nothing that is real changes.
118
123
  *
124
+ * `borders` draws the borders on the land as thin lines that turn with the Earth: `countries` (chizu's, at any size), `regions` (provinces, states and the like, from the page's `borderData.regions`,
125
+ * once the Earth is large enough to tell them apart), or both with a bare attribute. The shapes are loaded only when a set is switched on; `chikyu-borders-unavailable` is sent when they cannot be.
126
+ *
127
+ * `grid` draws the meridians and parallels on the Earth (every 30 degrees while it is small on the screen, every 15 once it is large), with the equator, the tropics, the polar circles and the prime
128
+ * meridian picked out, light on the day side and dim on the night side. `country-names` names the countries at the middle of the part of each in view, in the page's language, never over another
129
+ * name, as many as fit (40 at most, or the number given); the outlines are loaded only when it is set, and `chikyu-country-names-unavailable` is sent when they cannot be.
130
+ *
119
131
  * @example
120
132
  * ```ts no-run
121
133
  * import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
@@ -134,7 +146,7 @@ export const readTime = (value) => {
134
146
  * ```
135
147
  */
136
148
  export class ChikyuEarthRealistic extends HTMLElement {
137
- static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look"];
149
+ static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups"];
138
150
  #model = newModel();
139
151
  #mode = "now";
140
152
  #view;
@@ -161,9 +173,14 @@ export class ChikyuEarthRealistic extends HTMLElement {
161
173
  /** The names of cities on the Earth (`city-names`), and the look of the names. */
162
174
  #cities;
163
175
  #citiesStyle = {};
176
+ /** The names of the countries on the Earth (`country-names`), and the look of the names. */
177
+ #countries;
178
+ #countriesStyle = {};
164
179
  #listeners = new Set();
165
180
  #placeLayer;
166
181
  #placeList = [];
182
+ /** Counts the turns to a place, so a new one stops the one before. */
183
+ #placeGlide = 0;
167
184
  #hands;
168
185
  #reach = null;
169
186
  /** The page has set a `speed` since the element came into the page: for a reader who prefers reduced motion, that is the Play that lets meteors start. */
@@ -220,13 +237,26 @@ export class ChikyuEarthRealistic extends HTMLElement {
220
237
  this.#placeList = readPlaces(this.getAttribute("places"));
221
238
  this.#placeLayer.set(this.#placeList);
222
239
  this.#placeLayer.look = readPlaceLook(this.getAttribute("places-look"));
240
+ this.#placeLayer.grouping = readPlaceGroups(this.getAttribute("place-groups"));
223
241
  this.#cities = createCityHost({
224
242
  root,
225
243
  attribute: (name) => this.getAttribute(name),
226
244
  language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
227
245
  onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-city-names-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
246
+ onLayout: () => this.#countryFrame(),
228
247
  });
229
248
  this.#cities.setStyle(this.#citiesStyle);
249
+ Object.assign(this.#model.borders, readBorders(this.getAttribute("borders")));
250
+ this.#model.borders.onError = (error) => this.dispatchEvent(new CustomEvent("chikyu-borders-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } }));
251
+ this.#model.grid.on = readGrid(this.getAttribute("grid"));
252
+ this.#model.grid.onError = (error) => this.dispatchEvent(new CustomEvent("chikyu-grid-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } }));
253
+ this.#countries = createCountryHost({
254
+ root,
255
+ attribute: (name) => this.getAttribute(name),
256
+ language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
257
+ onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-country-names-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
258
+ });
259
+ this.#countries.setStyle(this.#countriesStyle);
230
260
  this.#played = false;
231
261
  this.#model.meteors.on = this.#meteorsAsked();
232
262
  this.#model.meteors.strength = readMeteorStrength(this.getAttribute("meteors-strength"));
@@ -268,16 +298,24 @@ export class ChikyuEarthRealistic extends HTMLElement {
268
298
  onTiled: () => this.#door.announce(),
269
299
  onSky: (sky) => this.#sky?.frame(sky),
270
300
  onLabelError: (error) => this.dispatchEvent(new CustomEvent("chikyu-body-label-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
301
+ placeSprites: () => this.#placeLayer?.sprites ?? null,
271
302
  onPose: (pose) => {
272
303
  if (this.#hands)
273
304
  this.#hands.controller.grabRadius = discRadius(pose.width, pose.height, 1);
274
305
  this.#pose = { ...pose, transform: "" };
275
- for (const listener of this.#listeners)
276
- listener(this.#pose);
306
+ this.#posing = true;
307
+ try {
308
+ for (const listener of this.#listeners)
309
+ listener(this.#pose);
310
+ }
311
+ finally {
312
+ this.#posing = false;
313
+ }
277
314
  if (this.#placeLayer && (this.#placeList.length > 0 || this.#placeLayer.stats.shown > 0))
278
- this.#placeLayer.frame(orthoView(pose));
315
+ this.#placeLayer.frame(orthoView(pose), [], [], this.#model.light === "lit" ? null : subsolarPoint(this.#model.time));
279
316
  this.#cityFrame();
280
317
  },
318
+ onPlaceRings: (drawn) => this.#ringsDrawn(drawn),
281
319
  onSatellitesError: (error) => this.dispatchEvent(new CustomEvent("chikyu-satellites-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
282
320
  onError: (error) => this.#fail(error instanceof Error ? error.message : String(error)),
283
321
  onTier: (layer, width) => {
@@ -331,6 +369,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
331
369
  this.#placeLayer = undefined;
332
370
  this.#cities?.dispose();
333
371
  this.#cities = undefined;
372
+ this.#countries?.dispose();
373
+ this.#countries = undefined;
334
374
  }
335
375
  attributeChangedCallback(name, _old, value) {
336
376
  if (name === "center")
@@ -373,6 +413,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
373
413
  this.#applyBodyLabel();
374
414
  this.#sky?.refresh();
375
415
  this.#cities?.refresh();
416
+ this.#countries?.refresh();
376
417
  }
377
418
  }
378
419
  else if (BODY_LABEL_ATTRIBUTES.includes(name))
@@ -388,8 +429,22 @@ export class ChikyuEarthRealistic extends HTMLElement {
388
429
  this.#placeLayer.look = readPlaceLook(value);
389
430
  this.#gate?.soon();
390
431
  }
432
+ else if (name === "place-groups" && this.#placeLayer) {
433
+ this.#placeLayer.grouping = readPlaceGroups(value);
434
+ this.#gate?.soon();
435
+ }
391
436
  else if (CITY_NAMES_ATTRIBUTES.includes(name))
392
437
  this.#cities?.refresh();
438
+ else if (name === "borders") {
439
+ Object.assign(this.#model.borders, readBorders(value));
440
+ this.#gate?.soon();
441
+ }
442
+ else if (name === "grid") {
443
+ this.#model.grid.on = readGrid(value);
444
+ this.#gate?.soon();
445
+ }
446
+ else if (COUNTRY_NAMES_ATTRIBUTES.includes(name))
447
+ this.#countries?.refresh();
393
448
  if (name === "air-thickness" || name === "air-label" || name === "lang")
394
449
  setAirNote(this.#airNote, this, this.#model.airThickness);
395
450
  }
@@ -504,10 +559,12 @@ export class ChikyuEarthRealistic extends HTMLElement {
504
559
  this.#sky?.setKeepClear(this.#keepClear);
505
560
  }
506
561
  /**
507
- * Places marked on the Earth (the attribute `places`, a JSON array): each `{ id, lon, lat, label, kind }`, `kind` being `here` (where the reader is: drawn bright and taller, with a quiet pulse) or `favourite`
508
- * (the default: quieter). Each stands up out of the ground, turns with the Earth, is hidden on its far side and keeps its size in pixels at any zoom. Names go at the top, `here` first, and never overlap
509
- * one another; one with no room is left out. The element stores nothing and sends nothing: the page hands the places over and keeps them where it likes. Setting the property writes the attribute; at most
510
- * `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight and for a reader who asked for less motion.
562
+ * Places marked on the Earth (the attribute `places`, a JSON array): each `{ id, lon, lat, label, kind, color }`, `kind` being `here` (where the reader is: drawn bright and taller, with a quiet pulse) or `favourite`
563
+ * (the default: quieter), and `color` an optional CSS colour of its own. The first `PLACE_MARKS` in sight (`here` first, then in the order given) stand up out of the ground with their names; every other place
564
+ * is a ring on the ground, all of them one draw call, and places that crowd are gathered into one ring with their count. They turn with the Earth, are hidden on its far side, are dimmer on its night side
565
+ * and keep their size in pixels at any zoom. Names never overlap one another; one with no room is left out. The element stores nothing and sends nothing: the page hands the places over and keeps them where
566
+ * it likes. Setting the property writes the attribute; at most `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight and for a reader who asked
567
+ * for less motion.
511
568
  */
512
569
  get places() {
513
570
  return this.#placeList.map((place) => ({ ...place }));
@@ -519,6 +576,55 @@ export class ChikyuEarthRealistic extends HTMLElement {
519
576
  else
520
577
  this.setAttribute("places", JSON.stringify(clean));
521
578
  }
579
+ /**
580
+ * Turn the Earth so a place of `places` is in the middle, at a pace a reader can follow (at once with `smooth: false`, for a reader who asked for less motion, or before the picture is live); the zoom
581
+ * and pan stay. The place is named by its `id`, or by its label in any case. The tilt is held to 90 degrees either way, so a place more than 90 degrees of latitude from `center` comes as near the middle
582
+ * as that allows.
583
+ *
584
+ * @param text - The place's id or label.
585
+ * @param options - `smooth` (true by default).
586
+ * @returns The place, once the turn has started; `undefined` when there is no such place.
587
+ */
588
+ async goToPlace(text, options = {}) {
589
+ const place = findPlace(this.#placeList, text);
590
+ if (!place)
591
+ return undefined;
592
+ const view = this.#model.view;
593
+ const from = { yaw: view.yaw, tilt: view.tilt };
594
+ const to = aimAt(cameraCentre(this.#model), place, from);
595
+ const bar = this.hasAttribute("data-kazoku-bar") && this.id ? this.getRootNode().querySelector?.(`kazoku-view-controls[for="${CSS.escape(this.id)}"]`) : null;
596
+ const controls = (bar ? Reflect.get(bar, "controller") : undefined) ?? this.#hands?.controller;
597
+ const glide = (this.#placeGlide += 1);
598
+ const set = (yaw, tilt, final) => {
599
+ if (controls)
600
+ controls.set({ yaw, tilt }, final, "place");
601
+ else
602
+ this.setView({ ...this.#model.view, yaw, tilt }, final);
603
+ };
604
+ glideView(set, from, to, options.smooth !== false && !prefersLessMotion() && this.#view?.live === true, () => glide === this.#placeGlide && this.isConnected);
605
+ return { ...place };
606
+ }
607
+ /**
608
+ * Whether places that crowd are gathered into one ring with their count (the attribute `place-groups`): on by default, `off` leaves every place its own ring. Setting the property writes the attribute.
609
+ */
610
+ get placeGroups() {
611
+ return this.#placeLayer?.grouping ?? readPlaceGroups(this.getAttribute("place-groups"));
612
+ }
613
+ set placeGroups(value) {
614
+ if (value)
615
+ this.removeAttribute("place-groups");
616
+ else
617
+ this.setAttribute("place-groups", "off");
618
+ }
619
+ /** The picture said whether it can draw the rings of the places that are not markers of their own. Without `Points` the places' layer draws them itself and the page is told once, so no place is lost without a word. */
620
+ #ringsDrawn(drawn) {
621
+ if (!this.#placeLayer || this.#placeLayer.ringsInPicture === drawn)
622
+ return;
623
+ this.#placeLayer.ringsInPicture = drawn;
624
+ if (!drawn)
625
+ this.dispatchEvent(new CustomEvent("chikyu-places-unavailable", { detail: { reason: "the three.js parts handed over lack Points: the places' rings are drawn as small circles in the page, at most 600, and stats.places.omitted counts the rest" } }));
626
+ this.#gate?.soon();
627
+ }
522
628
  /** How the places are drawn (the attribute `places-look`): `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 on the ground). */
523
629
  get placesLook() {
524
630
  return this.#placeLayer?.look ?? readPlaceLook(this.getAttribute("places-look"));
@@ -536,22 +642,81 @@ export class ChikyuEarthRealistic extends HTMLElement {
536
642
  this.#citiesStyle = { ...value };
537
643
  this.#cities?.setStyle(this.#citiesStyle);
538
644
  }
539
- /** Tells the names of cities where the Earth is in the picture just drawn: the orthographic view the markers share. */
645
+ /** Whether the meridians and parallels are drawn (the attribute `grid`). Setting it writes the attribute, or takes it away. */
646
+ get grid() {
647
+ return readGrid(this.getAttribute("grid"));
648
+ }
649
+ set grid(value) {
650
+ if (value)
651
+ this.setAttribute("grid", "");
652
+ else
653
+ this.removeAttribute("grid");
654
+ }
655
+ /**
656
+ * The look of the names of countries (`country-names`): font, weight, colour, the outline round the text, and the smallest and largest text size. Any of them may be left out; the Earth's size, the
657
+ * language and the data are not set here.
658
+ */
659
+ get countryNamesStyle() {
660
+ return { ...this.#countriesStyle };
661
+ }
662
+ set countryNamesStyle(value) {
663
+ this.#countriesStyle = { ...value };
664
+ this.#countries?.setStyle(this.#countriesStyle);
665
+ }
666
+ /**
667
+ * Which borders are drawn (the attribute `borders`): the countries' at any size, and the regions' (provinces, states, prefectures) once the Earth is large enough on the screen to tell them apart.
668
+ * Setting it writes the attribute: both sets as `borders="countries regions"`, one as its own word, none takes the attribute away.
669
+ */
670
+ get borders() {
671
+ return readBorders(this.getAttribute("borders"));
672
+ }
673
+ set borders(value) {
674
+ const words = [value.countries ? "countries" : "", value.regions ? "regions" : ""].filter(Boolean);
675
+ if (words.length === 0)
676
+ this.removeAttribute("borders");
677
+ else
678
+ this.setAttribute("borders", words.join(" "));
679
+ }
680
+ /**
681
+ * Where the borders' shapes come from (see `BorderData`): `countries` in place of chizu's `world-geo`, and `regions`, a country's regions by its code, which draws the regions; without it none are drawn.
682
+ * Set it before `borders` is switched on: shapes already loaded are kept.
683
+ */
684
+ get borderData() {
685
+ return { ...this.#model.borders.data };
686
+ }
687
+ set borderData(value) {
688
+ this.#model.borders.data = { ...value };
689
+ this.#gate?.soon();
690
+ }
691
+ /** Tells the names of cities, then of countries, where the Earth is in the picture just drawn (the orthographic view the markers share); the countries' names keep clear of the places' and the cities'. */
540
692
  #cityFrame() {
541
693
  const pose = this.#pose;
542
694
  if (!this.#cities || !pose)
543
695
  return;
544
- this.#cities.frame({
696
+ const frame = {
545
697
  width: pose.width,
546
698
  height: pose.height,
547
699
  radius: pose.radius,
700
+ disc: { x: pose.cx, y: pose.cy, radius: pose.radius },
548
701
  project: (lon, lat, out) => {
549
702
  const at = project(lon, lat, pose);
550
703
  out.x = at.x;
551
704
  out.y = at.y;
552
705
  return at.z;
553
706
  },
554
- });
707
+ };
708
+ this.#cities.frame(frame);
709
+ this.#nameFrame = frame;
710
+ this.#countryFrame();
711
+ }
712
+ /** The frame the names were last laid out on. */
713
+ #nameFrame = null;
714
+ /** Lays the countries' names out on the last frame, clear of the places' and the cities' names as they are now. */
715
+ #countryFrame() {
716
+ const countries = this.#countries;
717
+ if (!countries || !this.#nameFrame)
718
+ return;
719
+ countries.frame(this.#nameFrame, countries.stats.on ? [...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? []), ...[...this.#claims.values()].flat()] : []);
555
720
  }
556
721
  /** Puts the name's settings and text right from the attributes (`body-label` and its family, `lang`). */
557
722
  #applyBodyLabel() {
@@ -631,8 +796,21 @@ export class ChikyuEarthRealistic extends HTMLElement {
631
796
  this.#listeners.add(listener);
632
797
  return () => this.#listeners.delete(listener);
633
798
  },
799
+ claim: (owner, boxes) => {
800
+ if (boxes.length === 0)
801
+ this.#claims.delete(owner);
802
+ else
803
+ this.#claims.set(owner, boxes);
804
+ // laid out again only when the overlay changed between draws: at a draw the names are laid out after it anyway
805
+ if (!this.#posing)
806
+ this.#countryFrame();
807
+ },
634
808
  };
635
809
  }
810
+ /** The boxes overlays on the element (markers) take, by overlay. */
811
+ #claims = new Map();
812
+ /** True while the overlays are told of a draw. */
813
+ #posing = false;
636
814
  /** Where the view starts: longitude and latitude; the shared controls' yaw and tilt turn it from there. */
637
815
  get centre() {
638
816
  return { ...this.#model.centre };
@@ -739,8 +917,11 @@ export class ChikyuEarthRealistic extends HTMLElement {
739
917
  meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
740
918
  bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
741
919
  sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, pick: null, hover: null, constellations: 0, culture: "iau", renders: 0, lang: "", stars: [] },
742
- places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0 }) },
920
+ places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, marks: 0, groups: 0, sprites: 0, omitted: 0 }) },
743
921
  cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
922
+ borders: { ...this.#model.borders.stats, shown: { ...this.#model.borders.stats.shown }, loaded: [...this.#model.borders.stats.loaded] },
923
+ grid: { ...this.#model.grid.stats },
924
+ countryNames: this.#countries?.stats ?? { on: false, max: 0, countries: 0, names: 0, renders: 0, failed: false },
744
925
  };
745
926
  }
746
927
  /**
@@ -850,16 +1031,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
850
1031
  if (satellite)
851
1032
  this.dispatchEvent(new CustomEvent("chikyu-satellite-click", { detail: { ...satellite, info: this.satelliteInfo(satellite) }, bubbles: true, composed: true }));
852
1033
  };
853
- // In an immersive view a plain wheel zooms. It is passed on to the shared hands as the wheel's own pinch (Ctrl and a small step), so whichever hands hold the view (the element's, or a bar bound to it) apply it with their limits;
854
- // Ctrl, Command, Alt and Shift with the wheel are the family's own and are left alone.
855
- #wheel = (event) => {
856
- if (!this.hasAttribute("immersive") || event.ctrlKey || event.metaKey || event.altKey || event.shiftKey)
857
- return;
858
- event.preventDefault();
859
- event.stopImmediatePropagation();
860
- const pixels = event.deltaMode === 1 ? event.deltaY * 33 : event.deltaMode === 2 ? event.deltaY * 800 : event.deltaY;
861
- this.dispatchEvent(new WheelEvent("wheel", { deltaY: Math.max(-250, Math.min(250, pixels)) * WHEEL_AS_PINCH, deltaMode: 0, clientX: event.clientX, clientY: event.clientY, ctrlKey: true, bubbles: true, cancelable: true, composed: true }));
862
- };
1034
+ #wheel = (event) => immersiveWheel(this, event);
863
1035
  /** The view as it is (for a page that wants to read it back). */
864
1036
  get view() {
865
1037
  return { ...this.#model.view };
@@ -0,0 +1,7 @@
1
+ /** The host's styles in the immersive mode: any shape of box, and a touch drag that turns the view instead of scrolling the page. */
2
+ export declare const IMMERSIVE_STYLE = ":host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}";
3
+ /**
4
+ * In an immersive view a plain wheel zooms. It is passed on to the shared hands as the wheel's own pinch (Ctrl and a small step), so whichever hands hold the view (the element's, or a bar bound to it) apply it with their
5
+ * limits; Ctrl, Command, Alt and Shift with the wheel are the family's own and are left alone. Listen with `{ capture: true, passive: false }`, before the shared hands.
6
+ */
7
+ export declare function immersiveWheel(host: HTMLElement, event: WheelEvent): void;
@@ -0,0 +1,17 @@
1
+ // The full-screen mode of the 3D elements (the `immersive` attribute): the element fills its box in any shape, a plain wheel zooms instead of scrolling the page, and a touch drag turns the view.
2
+ /** The plain wheel in an immersive view is a pinch of this share: a notch (100) zooms about 1.2 times, as the family's mouse wheel does with Alt. */
3
+ const WHEEL_AS_PINCH = 0.2;
4
+ /** The host's styles in the immersive mode: any shape of box, and a touch drag that turns the view instead of scrolling the page. */
5
+ export const IMMERSIVE_STYLE = ":host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}";
6
+ /**
7
+ * In an immersive view a plain wheel zooms. It is passed on to the shared hands as the wheel's own pinch (Ctrl and a small step), so whichever hands hold the view (the element's, or a bar bound to it) apply it with their
8
+ * limits; Ctrl, Command, Alt and Shift with the wheel are the family's own and are left alone. Listen with `{ capture: true, passive: false }`, before the shared hands.
9
+ */
10
+ export function immersiveWheel(host, event) {
11
+ if (!host.hasAttribute("immersive") || event.ctrlKey || event.metaKey || event.altKey || event.shiftKey)
12
+ return;
13
+ event.preventDefault();
14
+ event.stopImmediatePropagation();
15
+ const pixels = event.deltaMode === 1 ? event.deltaY * 33 : event.deltaMode === 2 ? event.deltaY * 800 : event.deltaY;
16
+ host.dispatchEvent(new WheelEvent("wheel", { deltaY: Math.max(-250, Math.min(250, pixels)) * WHEEL_AS_PINCH, deltaMode: 0, clientX: event.clientX, clientY: event.clientY, ctrlKey: true, bubbles: true, cancelable: true, composed: true }));
17
+ }
@@ -12,3 +12,9 @@ export type { SkyLabelStyle } from "../sky/style.ts";
12
12
  export type { SkyKeepClear } from "../sky/keep-clear.ts";
13
13
  export { CITY_NAMES_DEFAULT, CITY_NAMES_MAX, TIER_RADIUS, cityNameText, cityRank, cityTiersFor, layoutCities, nameWidth, readCityNames, type CityFrame, type CityLayoutOptions, type CityName, type CityNameTier, type NamedCity } from "../cities/geometry.ts";
14
14
  export { CITY_NAMES_ATTRIBUTES, type CityNamesStyle } from "../cities/host.ts";
15
+ export { BORDER_ATTRIBUTES, BORDER_REGIONS_RADIUS, codesNear, readBorders, shapeBoxes, sharedEdges, type BorderFeature, type BorderSets, type BorderShapes } from "../borders/lines.ts";
16
+ export type { BorderData, BorderStats } from "../borders/layer.ts";
17
+ export { EARTH_TILT, GRID_ATTRIBUTES, GRID_FINE_RADIUS, gridLines, readGrid, type GridLines } from "../grid/lines.ts";
18
+ export type { GridStats } from "../grid/layer.ts";
19
+ export { COUNTRY_LETTER_SPACING, COUNTRY_NAMES_ATTRIBUTES, COUNTRY_NAMES_DEFAULT, COUNTRY_NAMES_MAX, countryNameBox, countryNameText, countrySpots, layoutCountryNames, readCountryNames, type CountryFrame, type CountryLayoutOptions, type CountryName, type CountrySpots, type NamedShape } from "../country-names/geometry.ts";
20
+ export type { CountryNamesStats, CountryNamesStyle } from "../country-names/host.ts";
@@ -11,3 +11,6 @@ export { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_THICKNESS_MAX, AIR_TOP, AIR_VER
11
11
  export { AIR_NOTE } from "./air-note.js";
12
12
  export { CITY_NAMES_DEFAULT, CITY_NAMES_MAX, TIER_RADIUS, cityNameText, cityRank, cityTiersFor, layoutCities, nameWidth, readCityNames } from "../cities/geometry.js";
13
13
  export { CITY_NAMES_ATTRIBUTES } from "../cities/host.js";
14
+ export { BORDER_ATTRIBUTES, BORDER_REGIONS_RADIUS, codesNear, readBorders, shapeBoxes, sharedEdges } from "../borders/lines.js";
15
+ export { EARTH_TILT, GRID_ATTRIBUTES, GRID_FINE_RADIUS, gridLines, readGrid } from "../grid/lines.js";
16
+ export { COUNTRY_LETTER_SPACING, COUNTRY_NAMES_ATTRIBUTES, COUNTRY_NAMES_DEFAULT, COUNTRY_NAMES_MAX, countryNameBox, countryNameText, countrySpots, layoutCountryNames, readCountryNames } from "../country-names/geometry.js";
@@ -25,6 +25,9 @@ export type ThreeParts = {
25
25
  SRGBColorSpace?: typeof THREE.SRGBColorSpace;
26
26
  NormalBlending?: typeof THREE.NormalBlending;
27
27
  AdditiveBlending?: typeof THREE.AdditiveBlending;
28
+ } & {
29
+ /** Only the borders (`borders`) use it, so a subset of three.js without it still draws everything else. */
30
+ LineSegments?: typeof THREE.LineSegments;
28
31
  };
29
32
  /** Milliseconds a lower texture size must be enough before the larger one is let go. */
30
33
  export declare const DOWNGRADE_AFTER_MS = 4000;