@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
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The oceans, seas, gulfs, bays and continents that can be named, each with the point its name is set at.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { SEA_FEATURES } from "@johnmorrisdotca/chikyu-earth/realistic";
7
+ *
8
+ * console.log(SEA_FEATURES.find((one) => one.id === "africa")?.name.en);
9
+ * ```
10
+ */
11
+ export const SEA_FEATURES = [
12
+ { id: "arctic-ocean", kind: "ocean", lon: -178.50, lat: 87.71, name: { en: "Arctic Ocean", ja: "北極海" } },
13
+ { id: "southern-ocean", kind: "ocean", lon: -88.50, lat: -70.76, name: { en: "Southern Ocean", ja: "南極海" } },
14
+ { id: "atlantic-ocean", kind: "ocean", lon: -28.59, lat: -5.03, name: { en: "Atlantic Ocean", ja: "大西洋" } },
15
+ { id: "pacific-ocean", kind: "ocean", lon: -145.50, lat: -8.03, name: { en: "Pacific Ocean", ja: "太平洋" } },
16
+ { id: "indian-ocean", kind: "ocean", lon: 81.12, lat: -38.03, name: { en: "Indian Ocean", ja: "インド洋" } },
17
+ { id: "south-america", kind: "continent", lon: -59.34, lat: -19.88, name: { en: "South America", ja: "南アメリカ" } },
18
+ { id: "australia", kind: "continent", lon: 139.18, lat: -25.15, name: { en: "Australia", ja: "オーストラリア大陸" } },
19
+ { id: "africa", kind: "continent", lon: 16.50, lat: 7.21, name: { en: "Africa", ja: "アフリカ" } },
20
+ { id: "antarctica", kind: "continent", lon: 34.00, lat: -88.00, name: { en: "Antarctica", ja: "南極大陸" } },
21
+ { id: "asia", kind: "continent", lon: 96.10, lat: 47.33, name: { en: "Asia", ja: "アジア" } },
22
+ { id: "europe", kind: "continent", lon: 20.52, lat: 54.03, name: { en: "Europe", ja: "ヨーロッパ" } },
23
+ { id: "north-america", kind: "continent", lon: -102.09, lat: 61.65, name: { en: "North America", ja: "北アメリカ" } },
24
+ { id: "black-sea", kind: "sea", lon: 34.98, lat: 42.42, name: { en: "Black Sea", ja: "黒海" } },
25
+ { id: "philippine-sea", kind: "sea", lon: 134.32, lat: 19.12, name: { en: "Philippine Sea", ja: "フィリピン海" } },
26
+ { id: "tasman-sea", kind: "sea", lon: 159.86, lat: -40.29, name: { en: "Tasman Sea", ja: "タスマン海" } },
27
+ { id: "bay-of-bengal", kind: "bay", lon: 87.19, lat: 13.02, name: { en: "Bay of Bengal", ja: "ベンガル湾" } },
28
+ { id: "south-china-sea", kind: "sea", lon: 112.85, lat: 10.28, name: { en: "South China Sea", ja: "南シナ海" } },
29
+ { id: "arabian-sea", kind: "sea", lon: 64.53, lat: 12.82, name: { en: "Arabian Sea", ja: "アラビア海" } },
30
+ { id: "beaufort-sea", kind: "sea", lon: -137.07, lat: 70.71, name: { en: "Beaufort Sea", ja: "ボーフォート海" } },
31
+ { id: "caribbean-sea", kind: "sea", lon: -74.85, lat: 15.99, name: { en: "Caribbean Sea", ja: "カリブ海" } },
32
+ { id: "gulf-of-mexico", kind: "gulf", lon: -90.36, lat: 25.30, name: { en: "Gulf of Mexico", ja: "メキシコ湾" } },
33
+ { id: "labrador-sea", kind: "sea", lon: -54.27, lat: 54.96, name: { en: "Labrador Sea", ja: "ラブラドル海" } },
34
+ { id: "hudson-bay", kind: "bay", lon: -84.46, lat: 59.20, name: { en: "Hudson Bay", ja: "ハドソン湾" } },
35
+ { id: "caspian-sea", kind: "sea", lon: 51.21, lat: 41.11, name: { en: "Caspian Sea", ja: "カスピ海" } },
36
+ { id: "baffin-bay", kind: "bay", lon: -65.57, lat: 74.42, name: { en: "Baffin Bay", ja: "バフィン湾" } },
37
+ { id: "gulf-of-alaska", kind: "gulf", lon: -149.88, lat: 58.55, name: { en: "Gulf of Alaska", ja: "アラスカ湾" } },
38
+ { id: "red-sea", kind: "sea", lon: 38.33, lat: 22.96, name: { en: "Red Sea", ja: "紅海" } },
39
+ { id: "sea-of-okhotsk", kind: "sea", lon: 147.72, lat: 50.78, name: { en: "Sea of Okhotsk", ja: "オホーツク海" } },
40
+ { id: "weddell-sea", kind: "sea", lon: -46.28, lat: -75.96, name: { en: "Weddell Sea", ja: "ウェッデル海" } },
41
+ { id: "persian-gulf", kind: "gulf", lon: 52.22, lat: 25.47, name: { en: "Persian Gulf", ja: "ペルシア湾" } },
42
+ { id: "mediterranean-sea", kind: "sea", lon: 20.41, lat: 35.33, name: { en: "Mediterranean Sea", ja: "地中海" } },
43
+ { id: "ross-sea", kind: "sea", lon: -169.50, lat: -77.69, name: { en: "Ross Sea", ja: "ロス海" } },
44
+ { id: "coral-sea", kind: "sea", lon: 156.28, lat: -19.38, name: { en: "Coral Sea", ja: "珊瑚海" } },
45
+ { id: "sea-of-japan", kind: "sea", lon: 135.81, lat: 41.78, name: { en: "Sea of Japan", ja: "日本海" } },
46
+ ];
@@ -0,0 +1,121 @@
1
+ import type { CityFrame } from "../cities/geometry.ts";
2
+ import { SEA_FEATURES } from "./features.ts";
3
+ export { SEA_FEATURES };
4
+ /**
5
+ * One named place: an ocean, a sea, a gulf, a bay or a continent, with the point its name is set at.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import type { SeaFeature } from "@johnmorrisdotca/chikyu-earth/realistic";
10
+ *
11
+ * const pacific: SeaFeature = { id: "pacific-ocean", kind: "ocean", lon: -145.5, lat: -8, name: { en: "Pacific Ocean", ja: "太平洋" } };
12
+ * console.log(pacific.name.en);
13
+ * ```
14
+ */
15
+ export interface SeaFeature {
16
+ id: string;
17
+ kind: "ocean" | "continent" | "sea" | "gulf" | "bay";
18
+ lon: number;
19
+ lat: number;
20
+ name: {
21
+ en: string;
22
+ ja: string;
23
+ };
24
+ }
25
+ /**
26
+ * A name placed for one draw: its id, the text, and the box it takes.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import type { SeaName } from "@johnmorrisdotca/chikyu-earth/realistic";
31
+ *
32
+ * const say = (one: SeaName): string => one.text;
33
+ * console.log(typeof say);
34
+ * ```
35
+ */
36
+ export interface SeaName {
37
+ id: string;
38
+ kind: SeaFeature["kind"];
39
+ text: string;
40
+ left: number;
41
+ top: number;
42
+ width: number;
43
+ height: number;
44
+ size: number;
45
+ }
46
+ /**
47
+ * The Earth's radius, in CSS pixels, at which seas, gulfs and bays join the oceans and continents.
48
+ * Below this the view is the wide Earth: only oceans and continents are named.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * import { SEA_RADIUS } from "@johnmorrisdotca/chikyu-earth/realistic";
53
+ *
54
+ * console.log(SEA_RADIUS > 200);
55
+ * ```
56
+ */
57
+ export declare const SEA_RADIUS = 280;
58
+ /** Space between the letters of a water name, as a share of the text size. Continents use a little less. */
59
+ export declare const SEA_LETTER_SPACING = 0.22;
60
+ export declare const LAND_LETTER_SPACING = 0.06;
61
+ /**
62
+ * The names a view of this size may show: oceans and continents while the Earth is small, and seas, gulfs and bays once it is at least {@link SEA_RADIUS} pixels in radius.
63
+ *
64
+ * @param radius - The Earth's radius on the screen, in CSS pixels.
65
+ * @returns The features, oceans and continents first.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * import { seaNamesFor } from "@johnmorrisdotca/chikyu-earth/realistic";
70
+ *
71
+ * console.log(seaNamesFor(120).some((one) => one.id === "pacific-ocean"));
72
+ * console.log(seaNamesFor(120).some((one) => one.id === "sea-of-japan"));
73
+ * console.log(seaNamesFor(400).some((one) => one.id === "mediterranean-sea"));
74
+ * ```
75
+ */
76
+ export declare function seaNamesFor(radius: number): readonly SeaFeature[];
77
+ /**
78
+ * Reads the `sea-names` attribute. Absent or `off` is off. A bare attribute, or any other value, is on.
79
+ *
80
+ * @param value - The attribute's value, or null when it is absent.
81
+ * @returns Whether the names are on.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * import { readSeaNames } from "@johnmorrisdotca/chikyu-earth/realistic";
86
+ *
87
+ * console.log(readSeaNames(null), readSeaNames(""), readSeaNames("off"));
88
+ * ```
89
+ */
90
+ export declare function readSeaNames(value: string | null): boolean;
91
+ /** The attributes the elements watch for these names. */
92
+ export declare const SEA_NAMES_ATTRIBUTES: readonly ["sea-names"];
93
+ /**
94
+ * Lays the names out for one draw. A name on the far side, or off the Earth's disc, is left out. A box in `taken` (a city name, a place, a country) keeps its space: the name moves aside, and if the only room is taken it is left out, so a city that was placed first wins.
95
+ *
96
+ * @param radius - The Earth's radius on the screen. It chooses oceans and continents, or those plus the seas.
97
+ * @param frame - Where the Earth is, and how to project a place. `project` returns how squarely the place faces the viewer.
98
+ * @param lang - `en` or `ja`.
99
+ * @param taken - Boxes already used. A name is not put over one.
100
+ * @returns The names to show.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * import { layoutSeaNames } from "@johnmorrisdotca/chikyu-earth/realistic";
105
+ *
106
+ * const frame = { width: 400, height: 400, radius: 160, project: (lon: number, lat: number, out: { x: number; y: number }) => { out.x = 200 + lon; out.y = 200 - lat; return 1; } };
107
+ * console.log(layoutSeaNames(160, frame, "en", []).some((one) => one.id === "africa"));
108
+ * ```
109
+ */
110
+ export declare function layoutSeaNames(radius: number, frame: CityFrame & {
111
+ disc?: {
112
+ x: number;
113
+ y: number;
114
+ radius: number;
115
+ };
116
+ }, lang: "en" | "ja", taken: readonly {
117
+ left: number;
118
+ top: number;
119
+ width: number;
120
+ height: number;
121
+ }[]): SeaName[];
@@ -0,0 +1,135 @@
1
+ import { nameWidth } from "../cities/geometry.js";
2
+ import { SEA_FEATURES } from "./features.js";
3
+ export { SEA_FEATURES };
4
+ /**
5
+ * The Earth's radius, in CSS pixels, at which seas, gulfs and bays join the oceans and continents.
6
+ * Below this the view is the wide Earth: only oceans and continents are named.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { SEA_RADIUS } from "@johnmorrisdotca/chikyu-earth/realistic";
11
+ *
12
+ * console.log(SEA_RADIUS > 200);
13
+ * ```
14
+ */
15
+ export const SEA_RADIUS = 280;
16
+ /** Space between the letters of a water name, as a share of the text size. Continents use a little less. */
17
+ export const SEA_LETTER_SPACING = 0.22;
18
+ export const LAND_LETTER_SPACING = 0.06;
19
+ const WATER = new Set(["ocean", "sea", "gulf", "bay"]);
20
+ const FACING = 0.25;
21
+ const MAX = 18;
22
+ /**
23
+ * The names a view of this size may show: oceans and continents while the Earth is small, and seas, gulfs and bays once it is at least {@link SEA_RADIUS} pixels in radius.
24
+ *
25
+ * @param radius - The Earth's radius on the screen, in CSS pixels.
26
+ * @returns The features, oceans and continents first.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { seaNamesFor } from "@johnmorrisdotca/chikyu-earth/realistic";
31
+ *
32
+ * console.log(seaNamesFor(120).some((one) => one.id === "pacific-ocean"));
33
+ * console.log(seaNamesFor(120).some((one) => one.id === "sea-of-japan"));
34
+ * console.log(seaNamesFor(400).some((one) => one.id === "mediterranean-sea"));
35
+ * ```
36
+ */
37
+ export function seaNamesFor(radius) {
38
+ const wide = SEA_FEATURES.filter((one) => one.kind === "ocean" || one.kind === "continent");
39
+ if (radius < SEA_RADIUS)
40
+ return wide;
41
+ return SEA_FEATURES;
42
+ }
43
+ /**
44
+ * Reads the `sea-names` attribute. Absent or `off` is off. A bare attribute, or any other value, is on.
45
+ *
46
+ * @param value - The attribute's value, or null when it is absent.
47
+ * @returns Whether the names are on.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import { readSeaNames } from "@johnmorrisdotca/chikyu-earth/realistic";
52
+ *
53
+ * console.log(readSeaNames(null), readSeaNames(""), readSeaNames("off"));
54
+ * ```
55
+ */
56
+ export function readSeaNames(value) {
57
+ return value !== null && value !== "off";
58
+ }
59
+ /** The attributes the elements watch for these names. */
60
+ export const SEA_NAMES_ATTRIBUTES = ["sea-names"];
61
+ const spacingOf = (kind) => (WATER.has(kind) ? SEA_LETTER_SPACING : LAND_LETTER_SPACING);
62
+ const boxOf = (text, size, spacing) => {
63
+ let width = 0;
64
+ for (const char of text)
65
+ width += ((char.codePointAt(0) ?? 0) >= 0x2e80 ? size : size * 0.58) + size * spacing;
66
+ return { width: Math.ceil(Math.max(width, nameWidth(text, size))) + 4, height: Math.ceil(size * 1.35) };
67
+ };
68
+ /**
69
+ * Lays the names out for one draw. A name on the far side, or off the Earth's disc, is left out. A box in `taken` (a city name, a place, a country) keeps its space: the name moves aside, and if the only room is taken it is left out, so a city that was placed first wins.
70
+ *
71
+ * @param radius - The Earth's radius on the screen. It chooses oceans and continents, or those plus the seas.
72
+ * @param frame - Where the Earth is, and how to project a place. `project` returns how squarely the place faces the viewer.
73
+ * @param lang - `en` or `ja`.
74
+ * @param taken - Boxes already used. A name is not put over one.
75
+ * @returns The names to show.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * import { layoutSeaNames } from "@johnmorrisdotca/chikyu-earth/realistic";
80
+ *
81
+ * const frame = { width: 400, height: 400, radius: 160, project: (lon: number, lat: number, out: { x: number; y: number }) => { out.x = 200 + lon; out.y = 200 - lat; return 1; } };
82
+ * console.log(layoutSeaNames(160, frame, "en", []).some((one) => one.id === "africa"));
83
+ * ```
84
+ */
85
+ export function layoutSeaNames(radius, frame, lang, taken) {
86
+ const out = { x: 0, y: 0 };
87
+ const disc = frame.disc;
88
+ const blocked = taken.map((box) => ({ l: box.left, t: box.top, r: box.left + box.width, b: box.top + box.height }));
89
+ const placed = [];
90
+ const hits = (box, others) => {
91
+ for (const other of others)
92
+ if (box.l < other.r && box.r > other.l && box.t < other.b && box.b > other.t)
93
+ return true;
94
+ return false;
95
+ };
96
+ const inDisc = (box) => {
97
+ if (!disc)
98
+ return true;
99
+ const reach = disc.radius - 2;
100
+ return Math.hypot(box.l - disc.x, box.t - disc.y) <= reach && Math.hypot(box.r - disc.x, box.t - disc.y) <= reach && Math.hypot(box.l - disc.x, box.b - disc.y) <= reach && Math.hypot(box.r - disc.x, box.b - disc.y) <= reach;
101
+ };
102
+ const names = [];
103
+ const features = [...seaNamesFor(radius)].sort((a, b) => rank(b) - rank(a));
104
+ for (const feature of features) {
105
+ if (names.length >= MAX)
106
+ break;
107
+ const facing = frame.project(feature.lon, feature.lat, out);
108
+ if (facing < FACING)
109
+ continue;
110
+ const text = lang === "ja" ? feature.name.ja : feature.name.en;
111
+ const size = feature.kind === "ocean" || feature.kind === "continent" ? 14 : 12;
112
+ const { width, height } = boxOf(text, size, spacingOf(feature.kind));
113
+ const shifts = [
114
+ [-width / 2, -height / 2],
115
+ [8, -height / 2],
116
+ [-width - 8, -height / 2],
117
+ [-width / 2, -height - 6],
118
+ [-width / 2, 8],
119
+ ];
120
+ for (const [dx, dy] of shifts) {
121
+ const left = out.x + dx;
122
+ const top = out.y + dy;
123
+ const box = { l: left, t: top, r: left + width, b: top + height };
124
+ if (box.l < 0 || box.t < 0 || box.r > frame.width || box.b > frame.height)
125
+ continue;
126
+ if (!inDisc(box) || hits(box, blocked) || hits(box, placed))
127
+ continue;
128
+ placed.push(box);
129
+ names.push({ id: feature.id, kind: feature.kind, text, left, top, width, height, size });
130
+ break;
131
+ }
132
+ }
133
+ return names;
134
+ }
135
+ const rank = (feature) => (feature.kind === "sea" || feature.kind === "gulf" || feature.kind === "bay" ? 3 : feature.kind === "continent" ? 2 : 1);
@@ -0,0 +1,46 @@
1
+ import { type SeaName } from "./geometry.ts";
2
+ import type { CityFrame } from "../cities/geometry.ts";
3
+ /** The styles of the layer (`#sea-names` in the element's shadow root). Water is spaced out; continents a little less. */
4
+ export declare const SEA_NAMES_STYLE: string;
5
+ export interface SeaNamesStats {
6
+ on: boolean;
7
+ radius: number;
8
+ names: number;
9
+ renders: number;
10
+ }
11
+ export interface SeaHost {
12
+ frame(frame: (CityFrame & {
13
+ disc?: {
14
+ x: number;
15
+ y: number;
16
+ radius: number;
17
+ };
18
+ }) | null, taken?: readonly {
19
+ left: number;
20
+ top: number;
21
+ width: number;
22
+ height: number;
23
+ }[]): void;
24
+ refresh(): void;
25
+ readonly shown: readonly SeaName[];
26
+ readonly boxes: readonly {
27
+ left: number;
28
+ top: number;
29
+ width: number;
30
+ height: number;
31
+ }[];
32
+ readonly stats: SeaNamesStats;
33
+ dispose(): void;
34
+ }
35
+ export interface SeaHostOptions {
36
+ attribute(name: string): string | null;
37
+ language(): "en" | "ja";
38
+ root: ShadowRoot;
39
+ }
40
+ /**
41
+ * Makes the layer of one element. Nothing is added to the root until `sea-names` is on.
42
+ *
43
+ * @param options - The attribute reader, the language and the shadow root.
44
+ * @returns The host.
45
+ */
46
+ export declare function createSeaHost(options: SeaHostOptions): SeaHost;
@@ -0,0 +1,111 @@
1
+ // Names of oceans, seas and continents over an element's picture. The element tells this where the Earth is at each draw. Nothing is added until `sea-names` is on, and nothing is drawn at rest.
2
+ import { LAND_LETTER_SPACING, SEA_LETTER_SPACING, layoutSeaNames, readSeaNames } from "./geometry.js";
3
+ /** The styles of the layer (`#sea-names` in the element's shadow root). Water is spaced out; continents a little less. */
4
+ export const SEA_NAMES_STYLE = "#sea-names{position:absolute;inset:0;overflow:hidden;pointer-events:none}" +
5
+ ".sea-name{position:absolute;left:0;top:0;margin:0;white-space:nowrap;text-align:center;pointer-events:none;will-change:transform;" +
6
+ "font-family:var(--chikyu-sea-font,system-ui,-apple-system,'Segoe UI',sans-serif);font-weight:500;color:var(--chikyu-sea-colour,rgba(186,214,228,.9));" +
7
+ `letter-spacing:${SEA_LETTER_SPACING}em;` +
8
+ "text-shadow:0 0 3px #061018,0 0 3px #061018}" +
9
+ `.sea-name[data-kind=continent]{letter-spacing:${LAND_LETTER_SPACING}em;color:var(--chikyu-land-colour,rgba(232,224,200,.92))}` +
10
+ ".sea-name[hidden]{display:none}";
11
+ /**
12
+ * Makes the layer of one element. Nothing is added to the root until `sea-names` is on.
13
+ *
14
+ * @param options - The attribute reader, the language and the shadow root.
15
+ * @returns The host.
16
+ */
17
+ export function createSeaHost(options) {
18
+ const { root } = options;
19
+ const doc = root.ownerDocument;
20
+ let on = readSeaNames(options.attribute("sea-names"));
21
+ let last = null;
22
+ let taken = [];
23
+ let shown = [];
24
+ let renders = 0;
25
+ let box;
26
+ const pool = [];
27
+ const attach = () => {
28
+ if (box)
29
+ return;
30
+ box = doc.createElement("div");
31
+ box.id = "sea-names";
32
+ box.setAttribute("aria-hidden", "true");
33
+ const cities = root.getElementById("cn-canvas");
34
+ if (cities)
35
+ root.insertBefore(box, cities);
36
+ else
37
+ root.append(box);
38
+ };
39
+ const clear = () => {
40
+ for (const name of pool)
41
+ name.hidden = true;
42
+ shown = [];
43
+ };
44
+ const place = () => {
45
+ if (!box)
46
+ return;
47
+ renders += 1;
48
+ while (pool.length < shown.length) {
49
+ const name = doc.createElement("span");
50
+ name.className = "sea-name";
51
+ box.append(name);
52
+ pool.push(name);
53
+ }
54
+ pool.forEach((name, index) => {
55
+ const one = shown[index];
56
+ if (!one) {
57
+ name.hidden = true;
58
+ return;
59
+ }
60
+ name.hidden = false;
61
+ name.dataset["kind"] = one.kind;
62
+ name.textContent = one.text;
63
+ name.style.fontSize = `${one.size}px`;
64
+ name.style.transform = `translate(${one.left}px, ${one.top}px)`;
65
+ });
66
+ };
67
+ const compute = () => {
68
+ if (!on || !last) {
69
+ clear();
70
+ if (box)
71
+ place();
72
+ return;
73
+ }
74
+ attach();
75
+ shown = layoutSeaNames(last.radius, last, options.language(), taken);
76
+ place();
77
+ };
78
+ return {
79
+ frame(frame, next = []) {
80
+ last = frame;
81
+ taken = next;
82
+ compute();
83
+ },
84
+ refresh() {
85
+ on = readSeaNames(options.attribute("sea-names"));
86
+ if (!on) {
87
+ clear();
88
+ box?.remove();
89
+ box = undefined;
90
+ pool.length = 0;
91
+ return;
92
+ }
93
+ compute();
94
+ },
95
+ get shown() {
96
+ return shown;
97
+ },
98
+ get boxes() {
99
+ return shown.map((one) => ({ left: one.left, top: one.top, width: one.width, height: one.height }));
100
+ },
101
+ get stats() {
102
+ return { on, radius: last?.radius ?? 0, names: on ? shown.length : 0, renders };
103
+ },
104
+ dispose() {
105
+ clear();
106
+ box?.remove();
107
+ box = undefined;
108
+ on = false;
109
+ },
110
+ };
111
+ }
@@ -10,6 +10,7 @@ import type { BorderData, BorderStats } from "../borders/layer.ts";
10
10
  import { type RouteLeg } from "../route.ts";
11
11
  import type { GridStats } from "../grid/layer.ts";
12
12
  import { type CountryNamesStats, type CountryNamesStyle } from "../country-names/host.ts";
13
+ import { type SeaNamesStats } from "../sea-names/host.ts";
13
14
  import type { TileStats } from "../realistic/tile-set.ts";
14
15
  import { setThreeLoader } from "../realistic/shared.ts";
15
16
  import type { LightMode } from "../realistic/earth.ts";
@@ -17,7 +18,7 @@ import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/type
17
18
  import { type PlanetName } from "./ephemeris.ts";
18
19
  import { type SatelliteScreen, type SatelliteStyle } from "./satellite-layer.ts";
19
20
  import { type SatelliteOthers } from "./satellite-focus.ts";
20
- import { type RideFace, type RideLook } from "./ride.ts";
21
+ import { type RideFace, type RideLook, type RideViewpoint } from "./ride.ts";
21
22
  import { type ScaleMode } from "./scale.ts";
22
23
  import { BODY_NAMES, type CameraMode, type BodyName, type BodyPainter, type RideTarget, type SatellitePainter } from "./scene.ts";
23
24
  import { type PaintSpec } from "../paint/buffer.ts";
@@ -113,6 +114,8 @@ export interface RideOptions {
113
114
  look?: RideLook;
114
115
  /** Face this way as the ride opens (`face`). */
115
116
  face?: RideFace;
117
+ /** `outside` (the default, or the element's `ride-viewpoint`) shows the satellite: with `view: "from"` the camera is a little behind and above it (straight above it with `look: "down"`), and a satellite the page has no model for is drawn small from the package's own sketch of its kind. `inside` is the camera at the satellite, as before, and no sketch. A body is always ridden from inside. */
118
+ viewpoint?: RideViewpoint;
116
119
  distanceKm?: number;
117
120
  smooth?: boolean;
118
121
  }
@@ -133,6 +136,8 @@ export interface Riding {
133
136
  look: RideLook;
134
137
  face: RideFace | null;
135
138
  distanceKm: number;
139
+ /** `outside` or `inside` (see `RideOptions`). */
140
+ viewpoint: RideViewpoint;
136
141
  }
137
142
  type SatelliteStats = {
138
143
  groups: number;
@@ -339,6 +344,21 @@ export declare class ChikyuSpace extends HTMLElement {
339
344
  */
340
345
  get countryNamesStyle(): CountryNamesStyle;
341
346
  set countryNamesStyle(value: CountryNamesStyle);
347
+ /**
348
+ * 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.
349
+ *
350
+ * @example
351
+ * ```ts no-run
352
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
353
+ *
354
+ * const space = document.querySelector("chikyu-space") as ChikyuSpace;
355
+ * space.seaNames = true;
356
+ * console.log(space.seaNames);
357
+ * space.seaNames = false;
358
+ * ```
359
+ */
360
+ get seaNames(): boolean;
361
+ set seaNames(value: boolean);
342
362
  /**
343
363
  * Which borders are drawn on the Earth (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.
344
364
  * Setting it writes the attribute: both sets as `borders="countries regions"`, one as its own word, none takes the attribute away.
@@ -455,6 +475,12 @@ export declare class ChikyuSpace extends HTMLElement {
455
475
  noradId: number;
456
476
  name: string;
457
477
  } | null;
478
+ /**
479
+ * Where a ride puts the camera: `outside` (the default; the attribute `ride-viewpoint`) shows the satellite, `inside` puts the camera at it. It is the default for the next `ride` and, set while riding, moves the ride there in one eased glide (a jump for a reader who asked for reduced motion), keeping the ride and the clock.
480
+ * See `RideOptions.viewpoint`.
481
+ */
482
+ get rideViewpoint(): RideViewpoint;
483
+ set rideViewpoint(value: RideViewpoint);
458
484
  /** What the camera is riding along with now, or null. */
459
485
  get riding(): Riding | null;
460
486
  /**
@@ -689,6 +715,8 @@ export declare class ChikyuSpace extends HTMLElement {
689
715
  };
690
716
  /** 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. */
691
717
  countryNames: CountryNamesStats;
718
+ /** 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. */
719
+ seaNames: SeaNamesStats;
692
720
  };
693
721
  }
694
722
  declare global {