@johnmorrisdotca/chikyu-earth 0.43.0 → 0.45.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 (39) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/NOTICE.md +15 -5
  3. package/README.md +4 -4
  4. package/dist/door/map.js +5 -1
  5. package/dist/element.d.ts +30 -0
  6. package/dist/element.js +82 -2
  7. package/dist/markers/here-city-host.d.ts +3 -1
  8. package/dist/markers/here-city-host.js +67 -5
  9. package/dist/markers/here-city.d.ts +94 -1
  10. package/dist/markers/here-city.js +69 -1
  11. package/dist/markers/index.d.ts +1 -1
  12. package/dist/markers/index.js +1 -1
  13. package/dist/realistic/element-base.d.ts +18 -0
  14. package/dist/realistic/element-base.js +59 -12
  15. package/dist/realistic/index.d.ts +1 -0
  16. package/dist/realistic/index.js +1 -0
  17. package/dist/realistic/zoom-reach.d.ts +29 -0
  18. package/dist/realistic/zoom-reach.js +30 -0
  19. package/dist/satellites/catalogue.d.ts +52 -1
  20. package/dist/satellites/catalogue.js +96 -5
  21. package/dist/satellites/index.d.ts +1 -1
  22. package/dist/satellites/index.js +1 -1
  23. package/dist/sea-names/features.d.ts +12 -0
  24. package/dist/sea-names/features.js +46 -0
  25. package/dist/sea-names/geometry.d.ts +121 -0
  26. package/dist/sea-names/geometry.js +135 -0
  27. package/dist/sea-names/host.d.ts +46 -0
  28. package/dist/sea-names/host.js +111 -0
  29. package/dist/space/element-base.d.ts +29 -1
  30. package/dist/space/element-base.js +82 -7
  31. package/dist/space/generic-satellite.d.ts +46 -0
  32. package/dist/space/generic-satellite.js +96 -0
  33. package/dist/space/index.d.ts +2 -1
  34. package/dist/space/index.js +2 -1
  35. package/dist/space/ride.d.ts +45 -0
  36. package/dist/space/ride.js +38 -0
  37. package/dist/space/scene.d.ts +3 -1
  38. package/dist/space/scene.js +54 -25
  39. package/package.json +3 -3
@@ -1,3 +1,5 @@
1
+ // The nearest city's name on a "you are here" marker. Pure: kuni does the lookup (`CitySet.nearest`); this only decides which places are named, in which language, and how far is too far.
2
+ import { greatCircleKm } from "../route.js";
1
3
  /**
2
4
  * How far, in kilometres, a `here` marker looks for a city when `here-city` is set with no number.
3
5
  *
@@ -21,7 +23,7 @@ export const HERE_CITY_KM = 100;
21
23
  */
22
24
  export const HERE_CITY_MAX_KM = 20_000;
23
25
  /**
24
- * The kuni tiers a `here` marker's city is chosen from. A city of fewer than 100,000 people is in none of them.
26
+ * The kuni tiers a `here` marker looks through first. A smaller town is read afterwards from that city's country, one country file at a time.
25
27
  *
26
28
  * @example
27
29
  * ```ts
@@ -105,3 +107,69 @@ export function hereCityLabels(places, source, options) {
105
107
  }
106
108
  return out;
107
109
  }
110
+ /**
111
+ * At most two countries to read for a place. The first is the country of the nearest city in the three tiers, however far.
112
+ * The second is added only when a city of another country is also inside the limit: a place near a border. `src/countries.ts` has no point-in-country test, so the country comes from those cities.
113
+ *
114
+ * @param point - The place.
115
+ * @param source - The three tiers.
116
+ * @param maxKm - The limit, in kilometres.
117
+ * @returns ISO codes, upper case, at most two.
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * import { hereCountries } from "@johnmorrisdotca/chikyu-earth/markers";
122
+ *
123
+ * const source = {
124
+ * nearest: () => ({ city: { id: "a", name: { en: "A" }, country: "fr" }, km: 30 }),
125
+ * within: () => [{ city: { country: "fr" }, km: 30 }, { city: { country: "de" }, km: 40 }],
126
+ * };
127
+ * console.log(hereCountries({ lat: 49, lon: 8 }, source, 100).join(" "));
128
+ * ```
129
+ */
130
+ export function hereCountries(point, source, maxKm) {
131
+ const nearest = source.nearest(point);
132
+ const first = nearest?.city.country?.trim().toUpperCase();
133
+ if (!first)
134
+ return [];
135
+ const out = [first];
136
+ for (const hit of source.within?.(point, maxKm) ?? []) {
137
+ const code = hit.city.country?.trim().toUpperCase();
138
+ if (code && code !== first) {
139
+ out.push(code);
140
+ break;
141
+ }
142
+ }
143
+ return out;
144
+ }
145
+ /**
146
+ * The city to draw: the nearest of the coarse hit and the towns, and only when it is within `maxKm`. A town closer than the big city wins.
147
+ *
148
+ * @param point - The place.
149
+ * @param coarse - The nearest city of the three tiers inside the limit, or null.
150
+ * @param towns - The cities of the one or two countries read for this place.
151
+ * @param maxKm - The limit, in kilometres.
152
+ * @returns The city and its distance, or null when none is close enough.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * import { chooseHereCity } from "@johnmorrisdotca/chikyu-earth/markers";
157
+ *
158
+ * const town = { id: "v", name: { en: "Village" }, lat: 0.05, lon: 0 };
159
+ * const chosen = chooseHereCity({ lat: 0, lon: 0 }, { city: { id: "c", name: { en: "City" } }, km: 40 }, [town], 100);
160
+ * console.log(chosen?.id);
161
+ * ```
162
+ */
163
+ export function chooseHereCity(point, coarse, towns, maxKm) {
164
+ if (!(maxKm > 0))
165
+ return null;
166
+ let best = coarse && coarse.km <= maxKm ? { id: coarse.city.id, name: coarse.city.name, km: coarse.km } : null;
167
+ for (const town of towns) {
168
+ const km = greatCircleKm({ lon: point.lon, lat: point.lat }, { lon: town.lon, lat: town.lat });
169
+ if (km === null || km > maxKm)
170
+ continue;
171
+ if (!best || km < best.km - 1e-6)
172
+ best = { id: town.id, name: town.name, km };
173
+ }
174
+ return best;
175
+ }
@@ -4,5 +4,5 @@ export { clusterPoints, type Cluster } from "./cluster.ts";
4
4
  export { placeLabels, type LabelItem, type Placement } from "./labels.ts";
5
5
  export type { GroupInfo, MarkerEventDetail, MarkerIcon, MarkerInput } from "./types.ts";
6
6
  export { cleanPlaces, groupCell, groupPlaces, layoutPlaces, MAX_PLACES, nearby, orthoView, PLACE_GROUP_PX, PLACE_LOOKS, readPlaceGroups, readPlaces, type Place, type PlaceGroup, type PlaceKind, type PlaceLabelSpot, type PlaceLayout, type PlaceLayoutOptions, type PlaceLook, type PlaceShape, type PlaceView, type SurfacePoint } from "./places.ts";
7
- export { HERE_CITY_KM, HERE_CITY_MAX_KM, HERE_CITY_TIERS, hereCityLabels, readHereCity, type HereCityHit, type HereCitySource } from "./here-city.ts";
7
+ export { HERE_CITY_KM, HERE_CITY_MAX_KM, HERE_CITY_TIERS, chooseHereCity, hereCityLabels, hereCountries, readHereCity, type HereCityHit, type HereCitySource, type HereTown } from "./here-city.ts";
8
8
  export { PLACE_DOTS, PLACE_MARKS } from "./place-layer.ts";
@@ -5,5 +5,5 @@ export { project, projectAll, canvasRatio } from "./project.js";
5
5
  export { clusterPoints } from "./cluster.js";
6
6
  export { placeLabels } from "./labels.js";
7
7
  export { cleanPlaces, groupCell, groupPlaces, layoutPlaces, MAX_PLACES, nearby, orthoView, PLACE_GROUP_PX, PLACE_LOOKS, readPlaceGroups, readPlaces } from "./places.js";
8
- export { HERE_CITY_KM, HERE_CITY_MAX_KM, HERE_CITY_TIERS, hereCityLabels, readHereCity } from "./here-city.js";
8
+ export { HERE_CITY_KM, HERE_CITY_MAX_KM, HERE_CITY_TIERS, chooseHereCity, hereCityLabels, hereCountries, readHereCity } from "./here-city.js";
9
9
  export { PLACE_DOTS, PLACE_MARKS } from "./place-layer.js";
@@ -16,6 +16,7 @@ import type { BorderData, BorderStats } from "../borders/layer.ts";
16
16
  import { type RouteLeg } from "../route.ts";
17
17
  import type { GridStats } from "../grid/layer.ts";
18
18
  import { type CountryNamesStats, type CountryNamesStyle } from "../country-names/host.ts";
19
+ import { type SeaNamesStats } from "../sea-names/host.ts";
19
20
  import { setSharedRenderer, setThreeLoader } from "./shared.ts";
20
21
  export { setSharedRenderer, setThreeLoader };
21
22
  export type { CameraMode };
@@ -271,6 +272,21 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
271
272
  */
272
273
  get countryNamesStyle(): CountryNamesStyle;
273
274
  set countryNamesStyle(value: CountryNamesStyle);
275
+ /**
276
+ * Names of oceans, seas and continents (the attribute `sea-names`). Off unless set: a bare attribute is on. Oceans and continents from far out, seas once the Earth is large on the screen. A city name keeps the space where both fit only one. Nothing is drawn again at rest.
277
+ *
278
+ * @example
279
+ * ```ts no-run
280
+ * import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
281
+ *
282
+ * const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
283
+ * earth.seaNames = true;
284
+ * console.log(earth.seaNames);
285
+ * earth.seaNames = false;
286
+ * ```
287
+ */
288
+ get seaNames(): boolean;
289
+ set seaNames(value: boolean);
274
290
  /**
275
291
  * 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.
276
292
  * Setting it writes the attribute: both sets as `borders="countries regions"`, one as its own word, none takes the attribute away.
@@ -431,6 +447,8 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
431
447
  };
432
448
  /** 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. */
433
449
  countryNames: CountryNamesStats;
450
+ /** The names of oceans, seas and continents: whether `sea-names` is on, the Earth's radius on the screen, the names shown at the last draw, and how many times the layer was laid out. */
451
+ seaNames: SeaNamesStats;
434
452
  };
435
453
  /**
436
454
  * 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,
@@ -31,11 +31,14 @@ import { readRoute, routeLeg, routeText } from "../route.js";
31
31
  import { applyRoute } from "../route/layer.js";
32
32
  import { COUNTRY_NAMES_ATTRIBUTES } from "../country-names/geometry.js";
33
33
  import { COUNTRY_NAMES_STYLE, createCountryHost } from "../country-names/host.js";
34
+ import { SEA_NAMES_ATTRIBUTES, readSeaNames } from "../sea-names/geometry.js";
35
+ import { SEA_NAMES_STYLE, createSeaHost } from "../sea-names/host.js";
34
36
  import { createGate, frameCap } from "./gate.js";
35
37
  import { setSharedRenderer, setThreeLoader, takeRenderer } from "./shared.js";
36
38
  export { setSharedRenderer, setThreeLoader };
37
39
  import { MAX_TEXTURE, TIERS } from "./tiers.js";
38
- 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;
40
+ import { mayWriteZoomMax, raisedZoomMax } from "./zoom-reach.js";
41
+ 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 + SEA_NAMES_STYLE + CITY_NAMES_STYLE + METEOR_NOTE_STYLE + NOTES_STYLE;
39
42
  const RAD = Math.PI / 180;
40
43
  /** The Sun and the clouds are re-placed this often at real time: 15 degrees an hour is 0.25 degree a minute. */
41
44
  const LIVE_TICK_MS = 60_000;
@@ -46,8 +49,6 @@ const TIME_EVENT_MS = 250;
46
49
  const SUN_RATE = 360 / 86_400;
47
50
  /** Tilt to the poles; zoom from a tenth of Fit, which leaves the whole Earth small in the view, to 5 times: the package's own pictures are sharp to about 5 times. */
48
51
  const LIMITS = { tiltMax: 90, zoomMin: 0.1, zoomMax: 5 };
49
- /** With the finer tiles the detail runs 4 times further: the finest level is 4 times wider than the widest picture. */
50
- const TILES_ZOOM_MAX = "20";
51
52
  const readCentre = (value) => {
52
53
  if (!value)
53
54
  return null;
@@ -159,7 +160,7 @@ export const readTime = (value) => {
159
160
  * ```
160
161
  */
161
162
  export class ChikyuEarthRealistic extends HTMLElement {
162
- 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", "here-city", "route", "satellite-tint"];
163
+ 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, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "satellite-tint"];
163
164
  #model = newModel();
164
165
  #paint = createPaintState();
165
166
  #mode = "now";
@@ -189,6 +190,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
189
190
  #citiesStyle = {};
190
191
  /** The names of the countries on the Earth (`country-names`), and the look of the names. */
191
192
  #countries;
193
+ #seas;
192
194
  #countriesStyle = {};
193
195
  #listeners = new Set();
194
196
  #placeLayer;
@@ -279,6 +281,11 @@ export class ChikyuEarthRealistic extends HTMLElement {
279
281
  onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-country-names-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
280
282
  });
281
283
  this.#countries.setStyle(this.#countriesStyle);
284
+ this.#seas = createSeaHost({
285
+ root,
286
+ attribute: (name) => this.getAttribute(name),
287
+ language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
288
+ });
282
289
  this.#played = false;
283
290
  this.#model.meteors.on = this.#meteorsAsked();
284
291
  this.#model.meteors.strength = readMeteorStrength(this.getAttribute("meteors-strength"));
@@ -306,11 +313,12 @@ export class ChikyuEarthRealistic extends HTMLElement {
306
313
  cap: () => this.#textureCap(),
307
314
  sources: () => this.#tileSources(),
308
315
  onTiles: (layers) => {
309
- if (!this.hasAttribute("zoom-max") || this.getAttribute("zoom-max") === this.#reach) {
310
- this.#reach = TILES_ZOOM_MAX;
311
- // not written again when it is already there: the view controls take a written attribute as a new limit and bring the view back to fit, which a change of source must not do to a reader's zoom
312
- if (this.getAttribute("zoom-max") !== TILES_ZOOM_MAX)
313
- this.setAttribute("zoom-max", TILES_ZOOM_MAX);
316
+ if (mayWriteZoomMax(this.getAttribute("zoom-max"), this.#reach)) {
317
+ // only ever raised, and lowered when the tiles are taken away (below), not before
318
+ const reach = raisedZoomMax(this.#reach, layers);
319
+ this.#reach = reach;
320
+ if (this.getAttribute("zoom-max") !== reach)
321
+ this.setAttribute("zoom-max", reach);
314
322
  }
315
323
  this.dispatchEvent(new CustomEvent("chikyu-tiles", { detail: { layers } }));
316
324
  },
@@ -406,6 +414,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
406
414
  this.#cities = undefined;
407
415
  this.#countries?.dispose();
408
416
  this.#countries = undefined;
417
+ this.#seas?.dispose();
418
+ this.#seas = undefined;
409
419
  }
410
420
  attributeChangedCallback(name, _old, value) {
411
421
  if (name === "center")
@@ -448,6 +458,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
448
458
  this.#applyBodyLabel();
449
459
  this.#sky?.refresh();
450
460
  this.#cities?.refresh();
461
+ this.#seas?.refresh();
451
462
  this.#countries?.refresh();
452
463
  this.#here?.refresh();
453
464
  }
@@ -478,6 +489,11 @@ export class ChikyuEarthRealistic extends HTMLElement {
478
489
  }
479
490
  else if (CITY_NAMES_ATTRIBUTES.includes(name))
480
491
  this.#cities?.refresh();
492
+ else if (SEA_NAMES_ATTRIBUTES.includes(name)) {
493
+ this.#seas?.refresh();
494
+ this.#seaFrame();
495
+ this.#countryFrame();
496
+ }
481
497
  else if (name === "borders") {
482
498
  Object.assign(this.#model.borders, readBorders(value));
483
499
  this.#gate?.soon();
@@ -798,6 +814,28 @@ export class ChikyuEarthRealistic extends HTMLElement {
798
814
  this.#countriesStyle = { ...value };
799
815
  this.#countries?.setStyle(this.#countriesStyle);
800
816
  }
817
+ /**
818
+ * Names of oceans, seas and continents (the attribute `sea-names`). Off unless set: a bare attribute is on. Oceans and continents from far out, seas once the Earth is large on the screen. A city name keeps the space where both fit only one. Nothing is drawn again at rest.
819
+ *
820
+ * @example
821
+ * ```ts no-run
822
+ * import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
823
+ *
824
+ * const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
825
+ * earth.seaNames = true;
826
+ * console.log(earth.seaNames);
827
+ * earth.seaNames = false;
828
+ * ```
829
+ */
830
+ get seaNames() {
831
+ return readSeaNames(this.getAttribute("sea-names"));
832
+ }
833
+ set seaNames(value) {
834
+ if (value)
835
+ this.setAttribute("sea-names", "");
836
+ else
837
+ this.removeAttribute("sea-names");
838
+ }
801
839
  /**
802
840
  * 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.
803
841
  * Setting it writes the attribute: both sets as `borders="countries regions"`, one as its own word, none takes the attribute away.
@@ -850,6 +888,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
850
888
  #relayNames(cities, sky) {
851
889
  if (cities && this.#nameFrame)
852
890
  this.#cities?.frame(this.#nameFrame, this.#boxesBeforeCities());
891
+ this.#seaFrame();
853
892
  this.#countryFrame();
854
893
  if (sky)
855
894
  this.#sky?.relayout();
@@ -872,17 +911,24 @@ export class ChikyuEarthRealistic extends HTMLElement {
872
911
  out.push(...(this.#placeLayer?.boxes ?? []));
873
912
  for (const boxes of this.#claims.values())
874
913
  out.push(...boxes);
875
- out.push(...(this.#cities?.boxes ?? []));
914
+ out.push(...(this.#cities?.boxes ?? []), ...(this.#seas?.boxes ?? []));
876
915
  return out;
877
916
  }
878
917
  /** The frame the names were last laid out on. */
879
918
  #nameFrame = null;
880
- /** Lays the countries' names out on the last frame, clear of the places' and the cities' names as they are now. */
919
+ /** Lays the ocean, sea and continent names out on the last frame, clear of the places' and the cities' names. A city that was placed first keeps the space. */
920
+ #seaFrame() {
921
+ const seas = this.#seas;
922
+ if (!seas || !this.#nameFrame)
923
+ return;
924
+ seas.frame(this.#nameFrame, seas.stats.on ? [...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? []), ...[...this.#claims.values()].flat()] : []);
925
+ }
926
+ /** Lays the countries' names out on the last frame, clear of the places', the cities' and the sea names as they are now. */
881
927
  #countryFrame() {
882
928
  const countries = this.#countries;
883
929
  if (!countries || !this.#nameFrame)
884
930
  return;
885
- countries.frame(this.#nameFrame, countries.stats.on ? [...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? []), ...[...this.#claims.values()].flat()] : []);
931
+ countries.frame(this.#nameFrame, countries.stats.on ? [...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? []), ...(this.#seas?.boxes ?? []), ...[...this.#claims.values()].flat()] : []);
886
932
  }
887
933
  /** Puts the name's settings and text right from the attributes (`body-label` and its family, `lang`). */
888
934
  #applyBodyLabel() {
@@ -1097,6 +1143,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
1097
1143
  grid: { ...this.#model.grid.stats },
1098
1144
  route: { ...this.#model.route.stats },
1099
1145
  countryNames: this.#countries?.stats ?? { on: false, max: 0, countries: 0, names: 0, renders: 0, failed: false },
1146
+ seaNames: this.#seas?.stats ?? { on: false, radius: 0, names: 0, renders: 0 },
1100
1147
  };
1101
1148
  }
1102
1149
  /**
@@ -17,4 +17,5 @@ export type { BorderData, BorderStats } from "../borders/layer.ts";
17
17
  export { EARTH_TILT, GRID_ATTRIBUTES, GRID_FINE_RADIUS, gridLines, readGrid, type GridLines } from "../grid/lines.ts";
18
18
  export type { GridStats } from "../grid/layer.ts";
19
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 { SEA_FEATURES, SEA_RADIUS, layoutSeaNames, readSeaNames, seaNamesFor, type SeaFeature, type SeaName } from "../sea-names/geometry.ts";
20
21
  export type { CountryNamesStats, CountryNamesStyle } from "../country-names/host.ts";
@@ -14,3 +14,4 @@ export { CITY_NAMES_ATTRIBUTES } from "../cities/host.js";
14
14
  export { BORDER_ATTRIBUTES, BORDER_REGIONS_RADIUS, codesNear, readBorders, shapeBoxes, sharedEdges } from "../borders/lines.js";
15
15
  export { EARTH_TILT, GRID_ATTRIBUTES, GRID_FINE_RADIUS, gridLines, readGrid } from "../grid/lines.js";
16
16
  export { COUNTRY_LETTER_SPACING, COUNTRY_NAMES_ATTRIBUTES, COUNTRY_NAMES_DEFAULT, COUNTRY_NAMES_MAX, countryNameBox, countryNameText, countrySpots, layoutCountryNames, readCountryNames } from "../country-names/geometry.js";
17
+ export { SEA_FEATURES, SEA_RADIUS, layoutSeaNames, readSeaNames, seaNamesFor } from "../sea-names/geometry.js";
@@ -0,0 +1,29 @@
1
+ /** The zoom limit of the package's own pictures (the element's `LIMITS.zoomMax`), sharp to about this many times. */
2
+ export declare const PICTURE_ZOOM = 5;
3
+ /** The width of the widest picture the tiles are laid over, which that limit is sharp to. */
4
+ export declare const PICTURE_WIDTH = 4096;
5
+ /**
6
+ * The zoom limit a tile set gives: as many times `PICTURE_ZOOM` as the finest day level is wider than the widest picture (16384 across, 4 times: 20; 32768, 8 times: 40), never below the pictures' own
7
+ * limit, and the pictures' own limit when the set has no day layer.
8
+ *
9
+ * @param layers - The width in pixels of the finest level of each layer of the set.
10
+ * @returns The limit, as the attribute's text.
11
+ */
12
+ export declare const tilesZoomMax: (layers: Record<string, number>) => string;
13
+ /**
14
+ * The limit to write when a set has been read: the larger of the one written before and the set's own, so a source with fewer levels added later does not lower it (the view controls take a written
15
+ * attribute as a new limit and bring the view back to fit).
16
+ *
17
+ * @param written - What this element wrote before, or null.
18
+ * @param layers - The width of the finest level of each layer of the set read now.
19
+ * @returns The limit, as the attribute's text.
20
+ */
21
+ export declare const raisedZoomMax: (written: string | null, layers: Record<string, number>) => string;
22
+ /**
23
+ * Whether the element may write the limit: when the page has set none, or the one there is the one the element wrote. A `zoom-max` a page sets itself is never overwritten.
24
+ *
25
+ * @param attribute - The `zoom-max` attribute now, or null.
26
+ * @param written - What this element wrote before, or null.
27
+ * @returns True when the element may write.
28
+ */
29
+ export declare const mayWriteZoomMax: (attribute: string | null, written: string | null) => boolean;
@@ -0,0 +1,30 @@
1
+ // How far the realistic Earth may be zoomed once its tiles are found. Pure: the element reads and writes the `zoom-max` attribute, this says what to write.
2
+ /** The zoom limit of the package's own pictures (the element's `LIMITS.zoomMax`), sharp to about this many times. */
3
+ export const PICTURE_ZOOM = 5;
4
+ /** The width of the widest picture the tiles are laid over, which that limit is sharp to. */
5
+ export const PICTURE_WIDTH = 4096;
6
+ /**
7
+ * The zoom limit a tile set gives: as many times `PICTURE_ZOOM` as the finest day level is wider than the widest picture (16384 across, 4 times: 20; 32768, 8 times: 40), never below the pictures' own
8
+ * limit, and the pictures' own limit when the set has no day layer.
9
+ *
10
+ * @param layers - The width in pixels of the finest level of each layer of the set.
11
+ * @returns The limit, as the attribute's text.
12
+ */
13
+ export const tilesZoomMax = (layers) => String(Math.max(PICTURE_ZOOM, Math.round((PICTURE_ZOOM * (layers["day"] ?? 0)) / PICTURE_WIDTH)));
14
+ /**
15
+ * The limit to write when a set has been read: the larger of the one written before and the set's own, so a source with fewer levels added later does not lower it (the view controls take a written
16
+ * attribute as a new limit and bring the view back to fit).
17
+ *
18
+ * @param written - What this element wrote before, or null.
19
+ * @param layers - The width of the finest level of each layer of the set read now.
20
+ * @returns The limit, as the attribute's text.
21
+ */
22
+ export const raisedZoomMax = (written, layers) => String(Math.max(Number(written ?? 0), Number(tilesZoomMax(layers))));
23
+ /**
24
+ * Whether the element may write the limit: when the page has set none, or the one there is the one the element wrote. A `zoom-max` a page sets itself is never overwritten.
25
+ *
26
+ * @param attribute - The `zoom-max` attribute now, or null.
27
+ * @param written - What this element wrote before, or null.
28
+ * @returns True when the element may write.
29
+ */
30
+ export const mayWriteZoomMax = (attribute, written) => attribute === null || attribute === written;
@@ -81,7 +81,57 @@ export declare const SATELLITE_GROUPS: readonly SatelliteGroupInfo[];
81
81
  */
82
82
  export declare const CATALOGUE: readonly CatalogueEntry[];
83
83
  /**
84
- * Find catalogue entries by name, group name or NORAD number: "hubble", "hst", "25544" or "weather". Matching ignores case, spaces and punctuation, and a name that starts with the text comes before one that only has it inside.
84
+ * One plain row a page can index, for its own search box. No DOM: a group or a satellite, with both languages on every row.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * import type { CatalogueRow } from "@johnmorrisdotca/chikyu-earth/satellites";
89
+ *
90
+ * const row: CatalogueRow = { kind: "group", id: "weather", names: { en: "Weather", ja: "気象衛星" }, orbit: "mixed" };
91
+ * console.log(row.names.ja);
92
+ * ```
93
+ */
94
+ export interface CatalogueRow {
95
+ /** `group` for a button's group, `satellite` for one named satellite. */
96
+ kind: "satellite" | "group";
97
+ /** The group's id, or the satellite's NORAD number as a string. */
98
+ id: string;
99
+ /** The NORAD catalogue number. Only a satellite has one. */
100
+ noradId?: number;
101
+ /**
102
+ * Names in both languages. `ja` is the short Japanese name where {@link SHORT_NAMES} has one, and otherwise the English name:
103
+ * a name such as Sentinel-2A is written the same way in Japanese. `reading` is hiragana for a Japanese name that is not already kana.
104
+ */
105
+ names: {
106
+ en: string;
107
+ ja: string;
108
+ reading?: string;
109
+ };
110
+ /** The group's id. Only a satellite has one. */
111
+ group?: string;
112
+ orbit: OrbitKind;
113
+ /** Other names already written in the catalogue, such as HST for Hubble. Absent when there are none. */
114
+ aka?: readonly string[];
115
+ }
116
+ /**
117
+ * Plain rows for every group and every catalogue satellite, for a page to index. Both languages are on every row: `lang` says which language the page is showing and does not drop the other, so one index serves either.
118
+ * A satellite's Japanese name comes from {@link SHORT_NAMES} where that has one, and is otherwise the English name.
119
+ *
120
+ * @param lang - `en` or `ja`, the language the page is showing. Omit it for the same rows.
121
+ * @returns The groups in their own order, then the satellites in catalogue order.
122
+ * @example
123
+ * ```ts
124
+ * import { catalogueRows } from "@johnmorrisdotca/chikyu-earth/satellites";
125
+ *
126
+ * const hubble = catalogueRows("ja").find((row) => row.noradId === 20580);
127
+ * console.log(hubble?.names.ja, hubble?.aka?.join(", "));
128
+ * ```
129
+ */
130
+ export declare function catalogueRows(lang?: "en" | "ja"): CatalogueRow[];
131
+ /**
132
+ * Find catalogue entries by name, group name, NORAD number, Japanese name or a group's Japanese label: "hubble", "hst", "25544", "weather" or "ハッブル".
133
+ * An English or numeric query ignores case, spaces and punctuation, as before. Kana and kanji are matched as typed: only letter case and character width are folded (NFKC), and that same width fold is applied before the English comparison.
134
+ * A name that starts with the text comes before one that only has it inside.
85
135
  *
86
136
  * @param text - What the reader typed.
87
137
  * @param limit - The most entries to give back (8 by default).
@@ -91,6 +141,7 @@ export declare const CATALOGUE: readonly CatalogueEntry[];
91
141
  * import { findInCatalogue } from "@johnmorrisdotca/chikyu-earth/satellites";
92
142
  *
93
143
  * console.log(findInCatalogue("sentinel 2").map((entry) => entry.name));
144
+ * console.log(findInCatalogue("ハッブル").map((entry) => entry.name));
94
145
  * ```
95
146
  */
96
147
  export declare function findInCatalogue(text: string, limit?: number): CatalogueEntry[];
@@ -1,5 +1,6 @@
1
1
  // A small curated catalogue of satellites worth following: the groups the demo offers as buttons and the famous ones by name. Facts (names, NORAD numbers, orbit types) and our own words;
2
2
  // no orbital elements are here, and nothing is fetched. The elements come from the page (see docs/satellite-sources.md for the sources and their terms).
3
+ import { SHORT_NAMES } from "./names.js";
3
4
  /**
4
5
  * The groups, in the order the demo shows them. Each one is a CelesTrak list or a few single numbers; the elements are fetched by the page (or the demo's scheduled build), never by the package.
5
6
  *
@@ -205,7 +206,87 @@ export const CATALOGUE = [
205
206
  /** A name made easy to compare: upper case, letters and digits only. */
206
207
  const squash = (text) => text.toUpperCase().replace(/[^A-Z0-9]+/g, "");
207
208
  /**
208
- * Find catalogue entries by name, group name or NORAD number: "hubble", "hst", "25544" or "weather". Matching ignores case, spaces and punctuation, and a name that starts with the text comes before one that only has it inside.
209
+ * Hiragana readings of the Japanese names already in this catalogue, for a page that indexes by sound.
210
+ * A name that is already kana or Latin has none. These are this package's own readings (NOTICE.md).
211
+ */
212
+ const READINGS = {
213
+ 宇宙ステーション: "うちゅうステーション",
214
+ 有名な衛星: "ゆうめいなえいせい",
215
+ 科学衛星: "かがくえいせい",
216
+ 地球観測: "ちきゅうかんそく",
217
+ 気象衛星: "きしょうえいせい",
218
+ 静止衛星: "せいしえいせい",
219
+ 北斗: "ほくと",
220
+ アマチュア無線: "あまちゅあむせん",
221
+ 天宮: "てんぐう",
222
+ };
223
+ const GROUPS_BY_ID = new Map(SATELLITE_GROUPS.map((group) => [group.id, group]));
224
+ /** English and Japanese names. The reading is present only when it adds kana for a name that is not already kana. */
225
+ function rowNames(en, ja) {
226
+ const reading = READINGS[ja];
227
+ return reading !== undefined && reading !== ja ? { en, ja, reading } : { en, ja };
228
+ }
229
+ /**
230
+ * Other names already written on the catalogue entry: the catalogue's own name when a short name is shown instead, and a designation written in parentheses.
231
+ * Nothing is added that is not in that name. See NOTICE.md.
232
+ */
233
+ function akaOf(entry) {
234
+ const short = SHORT_NAMES[entry.noradId];
235
+ const en = short?.en ?? entry.name;
236
+ const ja = short?.ja ?? en;
237
+ const extras = [];
238
+ const add = (name) => {
239
+ const trimmed = name.trim();
240
+ if (trimmed === "" || trimmed === en || trimmed === ja || extras.includes(trimmed))
241
+ return;
242
+ extras.push(trimmed);
243
+ };
244
+ if (short)
245
+ add(entry.name);
246
+ const paren = /\(([^)]+)\)/.exec(entry.name);
247
+ if (paren?.[1])
248
+ add(paren[1]);
249
+ return extras.length > 0 ? extras : undefined;
250
+ }
251
+ /**
252
+ * Plain rows for every group and every catalogue satellite, for a page to index. Both languages are on every row: `lang` says which language the page is showing and does not drop the other, so one index serves either.
253
+ * A satellite's Japanese name comes from {@link SHORT_NAMES} where that has one, and is otherwise the English name.
254
+ *
255
+ * @param lang - `en` or `ja`, the language the page is showing. Omit it for the same rows.
256
+ * @returns The groups in their own order, then the satellites in catalogue order.
257
+ * @example
258
+ * ```ts
259
+ * import { catalogueRows } from "@johnmorrisdotca/chikyu-earth/satellites";
260
+ *
261
+ * const hubble = catalogueRows("ja").find((row) => row.noradId === 20580);
262
+ * console.log(hubble?.names.ja, hubble?.aka?.join(", "));
263
+ * ```
264
+ */
265
+ export function catalogueRows(lang) {
266
+ if (lang !== undefined && lang !== "en" && lang !== "ja")
267
+ throw new TypeError("catalogueRows lang is en or ja");
268
+ const groups = SATELLITE_GROUPS.map((group) => ({
269
+ kind: "group",
270
+ id: group.id,
271
+ names: rowNames(group.label, group.labelJa),
272
+ orbit: group.orbit,
273
+ }));
274
+ const satellites = CATALOGUE.map((entry) => {
275
+ const short = SHORT_NAMES[entry.noradId];
276
+ const en = short?.en ?? entry.name;
277
+ const ja = short?.ja ?? en;
278
+ const aka = akaOf(entry);
279
+ const row = { kind: "satellite", id: String(entry.noradId), noradId: entry.noradId, names: rowNames(en, ja), group: entry.group, orbit: entry.orbit };
280
+ if (aka)
281
+ row.aka = aka;
282
+ return row;
283
+ });
284
+ return [...groups, ...satellites];
285
+ }
286
+ /**
287
+ * Find catalogue entries by name, group name, NORAD number, Japanese name or a group's Japanese label: "hubble", "hst", "25544", "weather" or "ハッブル".
288
+ * An English or numeric query ignores case, spaces and punctuation, as before. Kana and kanji are matched as typed: only letter case and character width are folded (NFKC), and that same width fold is applied before the English comparison.
289
+ * A name that starts with the text comes before one that only has it inside.
209
290
  *
210
291
  * @param text - What the reader typed.
211
292
  * @param limit - The most entries to give back (8 by default).
@@ -215,19 +296,29 @@ const squash = (text) => text.toUpperCase().replace(/[^A-Z0-9]+/g, "");
215
296
  * import { findInCatalogue } from "@johnmorrisdotca/chikyu-earth/satellites";
216
297
  *
217
298
  * console.log(findInCatalogue("sentinel 2").map((entry) => entry.name));
299
+ * console.log(findInCatalogue("ハッブル").map((entry) => entry.name));
218
300
  * ```
219
301
  */
220
302
  export function findInCatalogue(text, limit = 8) {
221
- const wanted = squash(text);
222
- if (!wanted)
303
+ const source = text.normalize("NFKC");
304
+ const wanted = squash(source);
305
+ const folded = source.toLowerCase().trim();
306
+ const japanese = /[぀-ヿ一-鿿]/.test(source);
307
+ if (!wanted && !japanese)
223
308
  return [];
224
309
  const starts = [];
225
310
  const inside = [];
226
311
  for (const entry of CATALOGUE) {
227
312
  const name = squash(entry.name);
228
- if (String(entry.noradId) === wanted || name.startsWith(wanted))
313
+ const englishStart = wanted !== "" && (String(entry.noradId) === wanted || name.startsWith(wanted));
314
+ const englishInside = wanted !== "" && (name.includes(wanted) || squash(entry.group).includes(wanted) || squash(entry.about).includes(wanted));
315
+ const jaName = japanese ? (SHORT_NAMES[entry.noradId]?.ja ?? entry.name).normalize("NFKC").toLowerCase() : "";
316
+ const labelJa = japanese ? (GROUPS_BY_ID.get(entry.group)?.labelJa ?? "").normalize("NFKC").toLowerCase() : "";
317
+ const jaStart = japanese && folded !== "" && jaName.startsWith(folded);
318
+ const jaInside = japanese && folded !== "" && (jaName.includes(folded) || labelJa.includes(folded));
319
+ if (englishStart || jaStart)
229
320
  starts.push(entry);
230
- else if (name.includes(wanted) || squash(entry.group).includes(wanted) || squash(entry.about).includes(wanted))
321
+ else if (englishInside || jaInside)
231
322
  inside.push(entry);
232
323
  }
233
324
  return [...starts, ...inside].slice(0, limit);
@@ -4,6 +4,6 @@ export { DEFAULT_DIM_AFTER_DAYS, DEFAULT_MAX_AGE_DAYS, MAX_SATELLITE_SPEED } fro
4
4
  export type { ElementSet, RefusedElementSet, SatelliteInfo, SatelliteRef, Satellites } from "./types.ts";
5
5
  export { SHORT_NAMES } from "./names.ts";
6
6
  export { OWNER_COUNTRIES, ownerCountry } from "./owners.ts";
7
- export { CATALOGUE, SATELLITE_GROUPS, catalogueEntry, findInCatalogue, type CatalogueEntry, type OrbitKind, type SatelliteGroupInfo } from "./catalogue.ts";
7
+ export { CATALOGUE, SATELLITE_GROUPS, catalogueEntry, catalogueRows, findInCatalogue, type CatalogueEntry, type CatalogueRow, type OrbitKind, type SatelliteGroupInfo } from "./catalogue.ts";
8
8
  export { ElementSourceError, fetchElements, forgetElements, parseElements, type ElementFormat, type ElementSource, type FetchElementsOptions, type ParsedElements } from "./source.ts";
9
9
  export { missionElements, missionOf, missionPosition, missions, type HubbleVisit, type Mission, type MissionFile, type MissionPosition, type Orbiter } from "./missions.ts";
@@ -4,6 +4,6 @@ export { NEAREST_COUNT, closeApproach, nearest, overheadKm, within } from "./nea
4
4
  export { DEFAULT_DIM_AFTER_DAYS, DEFAULT_MAX_AGE_DAYS, MAX_SATELLITE_SPEED } from "./limits.js";
5
5
  export { SHORT_NAMES } from "./names.js";
6
6
  export { OWNER_COUNTRIES, ownerCountry } from "./owners.js";
7
- export { CATALOGUE, SATELLITE_GROUPS, catalogueEntry, findInCatalogue } from "./catalogue.js";
7
+ export { CATALOGUE, SATELLITE_GROUPS, catalogueEntry, catalogueRows, findInCatalogue } from "./catalogue.js";
8
8
  export { ElementSourceError, fetchElements, forgetElements, parseElements } from "./source.js";
9
9
  export { missionElements, missionOf, missionPosition, missions } from "./missions.js";
@@ -0,0 +1,12 @@
1
+ import type { SeaFeature } from "./geometry.ts";
2
+ /**
3
+ * The oceans, seas, gulfs, bays and continents that can be named, each with the point its name is set at.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { SEA_FEATURES } from "@johnmorrisdotca/chikyu-earth/realistic";
8
+ *
9
+ * console.log(SEA_FEATURES.find((one) => one.id === "africa")?.name.en);
10
+ * ```
11
+ */
12
+ export declare const SEA_FEATURES: readonly SeaFeature[];