@johnmorrisdotca/chikyu-earth 0.64.0 → 0.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +2 -2
- package/dist/space/compass.d.ts +82 -3
- package/dist/space/compass.js +72 -3
- package/dist/space/element-base.d.ts +31 -0
- package/dist/space/element-base.js +46 -2
- package/dist/space/index.d.ts +1 -0
- package/dist/space/index.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- **The page chooses where a ride's compass goes** (MODULES-1732). The compass was fixed in the top-left corner, 8 pixels in, so a page with a card at the top left had to start it about 85 pixels lower to clear the compass. Two attributes, each with a property, now place it. With neither set the compass is where it always was.
|
|
6
|
+
- **`compass-place`** (property `compassPlace`): `top-left` (the default), `top-right`, `bottom-left` or `bottom-right`. A value that is not one of the four reads as `top-left`.
|
|
7
|
+
- **`compass-offset`** (property `compassOffset`, `{ x, y }`): pixels in from that corner, written `x,y` (`x` from the side, `y` from the top or the bottom, such as `16,96`) or as one number for both; 8,8 by default. A value that is not one or two numbers of 0 or more reads as `8,8`. Each attribute is read by itself.
|
|
8
|
+
- **Live and inside.** Setting either while riding moves the compass at once. It is held inside the picture on every side: an offset larger than the room the picture has leaves it against the far edge, so on a narrow phone it still fits. The compass is now in a grid over the picture (`#compass-place`) whose gaps give way, which keeps `#compass`'s own box the same size as before.
|
|
9
|
+
- **Pure parts** in `/space`: `readCompassPlace`, `readCompassOffset`, `COMPASS_PLACE`, `COMPASS_OFFSET` and the types `CompassPlace` and `CompassOffset`, with unit tests (`test/compass.test.ts`: the four corners in any case, `x,y` in its spellings, bad values reading as the default).
|
|
10
|
+
- **Tests.** `e2e/compass-place.gl.ts` reads the compass's box against the element's at a desktop and a phone size: each corner with the offset, the default unchanged (the same box as on 0.64.0), an offset with no room, a change while riding in the same turn, and the properties. It fails on 0.64.0 everywhere but the default. The ride guide in English and Japanese, `docs/ride-along.md`, `docs/space.md` and the README.
|
|
11
|
+
|
|
5
12
|
## 0.64.0 - 2026-11-20
|
|
6
13
|
|
|
7
14
|
- **From one satellite to another a ride glides round the Earth** (MODULES-1735). A `ride` call that goes from one satellite to another moved the camera in a straight line, which for a satellite behind the Earth ran through the Earth (held 1 km over the ground since 0.63.0), so a page had to climb, cross and come down in steps of its own. The camera now glides along the great circle round the Earth's centre, its height going evenly from the one ride's to the other's and never under 100 km above the ground (`GLIDE_FLOOR_KM`). The look is carried along the circle and goes over from the first look to the second, so a facing (ahead, down and the rest) stays level, nothing rolls over against the local vertical, and the view turns once towards its end. The glide back is the same flight the other way.
|
package/README.md
CHANGED
|
@@ -359,7 +359,7 @@ Passes are only as good as the orbit data are new: each pass says how old its el
|
|
|
359
359
|
<p align="center"><img alt="Riding along with the ISS, tipped towards the horizon: the Earth's curve and atmosphere, and the orbits of the other stations in the sky" src="docs/images/space-ride-horizon.png" width="420"></p>
|
|
360
360
|
|
|
361
361
|
`space.ride({ group: "stations", index: 0 }, { look: "horizon" })` puts the camera on the ISS (or a Starlink satellite, the Moon, a planet) at its real place for the moment shown and looks at the Earth, which goes by beneath
|
|
362
|
-
as the body moves along its orbit; switch to another body and the camera glides there; from one satellite to another it glides round the Earth along the great circle, never through it and at least 100 km above the ground, with the facing kept level, so a satellite on the far side is reached in one smooth flight and Back is the same flight the other way. Straight down or toward the horizon, from the body or following it at a distance, time faster or slower. A ridden satellite is in the picture by default (the camera a little behind and above it, a small drawing of it where the page has no model, not to scale); `ride-viewpoint="inside"` (property `rideViewpoint`, option `viewpoint`) puts the camera at the satellite instead. A drag turns the view where the camera is, like turning your head (the satellite leaves the picture as you look away); `ride-drag="orbit"` (property `rideDrag`, option `drag`) takes the camera round the satellite as before. Seen from above, the model shrinks as the ride rises and hands over to the ordinary mark by 2,000 km; `ride-model-size="fixed"` (property `rideModelSize`, option `modelSize`) keeps one size at every height. `ride-up="north"` (property `rideUp`, option `up`) puts north at the top of the view above a satellite, so it is seen to go the way it really goes; a small compass on a ride shows north and the heading (`compass="off"` hides it), `rideTrack` and `chikyu-ride-track` give the heading, ground point and whether the Sun lights it, and the chosen orbit is amber in sunlight and blue in the Earth's shadow (`path-light="off"` for one colour). `ride-model-share`, `ride-model-seat` and `ride-zoom` frame and zoom the ridden satellite (properties `rideModelShare`, `rideModelSeat`, `rideZoom`). `face("ahead")` (behind, left, right, down, up; the keys W, S, A, D, F, R) turns a ride from the satellite or following it that way; the view above a satellite looks down on it and has no facings, so there `face()` returns `false` and the camera stays as it was. In every view the camera is never under the ground: it is held at least 1 km above it. It animates continuously, so it keeps to the
|
|
362
|
+
as the body moves along its orbit; switch to another body and the camera glides there; from one satellite to another it glides round the Earth along the great circle, never through it and at least 100 km above the ground, with the facing kept level, so a satellite on the far side is reached in one smooth flight and Back is the same flight the other way. Straight down or toward the horizon, from the body or following it at a distance, time faster or slower. A ridden satellite is in the picture by default (the camera a little behind and above it, a small drawing of it where the page has no model, not to scale); `ride-viewpoint="inside"` (property `rideViewpoint`, option `viewpoint`) puts the camera at the satellite instead. A drag turns the view where the camera is, like turning your head (the satellite leaves the picture as you look away); `ride-drag="orbit"` (property `rideDrag`, option `drag`) takes the camera round the satellite as before. Seen from above, the model shrinks as the ride rises and hands over to the ordinary mark by 2,000 km; `ride-model-size="fixed"` (property `rideModelSize`, option `modelSize`) keeps one size at every height. `ride-up="north"` (property `rideUp`, option `up`) puts north at the top of the view above a satellite, so it is seen to go the way it really goes; a small compass on a ride shows north and the heading (`compass="off"` hides it; `compass-place` puts it in another corner, `top-left` by default, and `compass-offset="x,y"` sets the pixels in from that corner, 8,8 by default; properties `compassPlace` and `compassOffset`), `rideTrack` and `chikyu-ride-track` give the heading, ground point and whether the Sun lights it, and the chosen orbit is amber in sunlight and blue in the Earth's shadow (`path-light="off"` for one colour). `ride-model-share`, `ride-model-seat` and `ride-zoom` frame and zoom the ridden satellite (properties `rideModelShare`, `rideModelSeat`, `rideZoom`). `face("ahead")` (behind, left, right, down, up; the keys W, S, A, D, F, R) turns a ride from the satellite or following it that way; the view above a satellite looks down on it and has no facings, so there `face()` returns `false` and the camera stays as it was. In every view the camera is never under the ground: it is held at least 1 km above it. It animates continuously, so it keeps to the
|
|
363
363
|
same budget: at most 30 frames a second (one a second for reduced motion), nothing drawn while paused, out of sight or hidden. [Ride along guide](docs/guides/ride-along.md), [docs/ride-along.md](docs/ride-along.md).
|
|
364
364
|
|
|
365
365
|
## Printable sheets
|
|
@@ -615,7 +615,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
|
|
|
615
615
|
|
|
616
616
|
## How to cite
|
|
617
617
|
|
|
618
|
-
> Morris, J. (2026). *Chikyu Earth* (version 0.
|
|
618
|
+
> Morris, J. (2026). *Chikyu Earth* (version 0.65.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
|
|
619
619
|
|
|
620
620
|
GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA. Cite the version you used (`npm ls @johnmorrisdotca/chikyu-earth`), and credit the sources behind the numbers and pictures: [NOTICE.md](NOTICE.md) says who made each one and under what terms.
|
|
621
621
|
|
package/dist/space/compass.d.ts
CHANGED
|
@@ -15,14 +15,93 @@ export declare const COMPASS_WORDS: {
|
|
|
15
15
|
readonly points: Record<CompassPoint, string>;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
/** The styles of the compass (`#compass`) in an element's shadow root. The dial is white lines on a dark disc, the way-it-goes dot yellow, so it reads on the sea, the land, the night and the day alike; `--chikyu-compass-colour` and `--chikyu-compass-travel` change them. */
|
|
19
|
-
export declare const COMPASS_STYLE = "#compass{position:absolute;
|
|
18
|
+
/** The styles of the compass (`#compass`, in `#compass-place`) in an element's shadow root. `#compass-place` is a grid over the whole picture: a gap of the offset's size on the corner's two sides (it gives way when the picture is too small, so the compass never leaves it), and the compass in the cell beside them. The dial is white lines on a dark disc, the way-it-goes dot yellow, so it reads on the sea, the land, the night and the day alike; `--chikyu-compass-colour` and `--chikyu-compass-travel` change them. */
|
|
19
|
+
export declare const COMPASS_STYLE = "#compass-place{position:absolute;inset:0;display:grid;grid-template-columns:minmax(0,var(--compass-x,8px)) max-content;grid-template-rows:minmax(0,var(--compass-y,8px)) max-content;justify-content:start;align-content:start;pointer-events:none}#compass-place[data-right]{grid-template-columns:max-content minmax(0,var(--compass-x,8px));justify-content:end}#compass-place[data-bottom]{grid-template-rows:max-content minmax(0,var(--compass-y,8px));align-content:end}#compass{grid-column:2;grid-row:2;justify-self:start;align-self:start;display:flex;flex-direction:column;align-items:center;gap:2px;pointer-events:none;color:var(--chikyu-compass-colour,#fff);font:11px/1.2 system-ui,-apple-system,sans-serif}#compass-place[data-right] #compass{grid-column:1}#compass-place[data-bottom] #compass{grid-row:1}#compass[hidden]{display:none}#compass svg{width:64px;height:64px;display:block;overflow:visible}#compass .disc{fill:#0b0e14b3;stroke:currentColor;stroke-opacity:.55;stroke-width:1}#compass .north{fill:currentColor}#compass .south{fill:currentColor;fill-opacity:.35}#compass .travel{fill:var(--chikyu-compass-travel,#ffd166);stroke:#0b0e14;stroke-width:1}#compass text{fill:currentColor;font:600 11px system-ui,-apple-system,sans-serif;text-anchor:middle;dominant-baseline:central;paint-order:stroke;stroke:#0b0e14;stroke-width:2.5px}#compass .words{background:#0b0e14b3;padding:1px 6px;border-radius:4px;white-space:nowrap}#compass .words[hidden]{display:none}";
|
|
20
20
|
/** The compass's markup: put it in the shadow root and hand it to `createCompass`. */
|
|
21
|
-
export declare const COMPASS_HTML = "<div id=\"compass\" role=\"img\" hidden><svg viewBox=\"-36 -36 72 72\" aria-hidden=\"true\"><circle class=\"disc\" r=\"25\"></circle><g class=\"arrow\"><path class=\"north\" d=\"M0 -21 L5 -3 L0 -7 L-5 -3 Z\"></path><path class=\"south\" d=\"M0 21 L4 4 L0 7 L-4 4 Z\"></path></g><text class=\"n\" x=\"0\" y=\"-31\">N</text><circle class=\"travel\" r=\"3.4\" cx=\"0\" cy=\"-25\"></circle></svg><span class=\"words\"></span></div>";
|
|
21
|
+
export declare const COMPASS_HTML = "<div id=\"compass-place\"><div id=\"compass\" role=\"img\" hidden><svg viewBox=\"-36 -36 72 72\" aria-hidden=\"true\"><circle class=\"disc\" r=\"25\"></circle><g class=\"arrow\"><path class=\"north\" d=\"M0 -21 L5 -3 L0 -7 L-5 -3 Z\"></path><path class=\"south\" d=\"M0 21 L4 4 L0 7 L-4 4 Z\"></path></g><text class=\"n\" x=\"0\" y=\"-31\">N</text><circle class=\"travel\" r=\"3.4\" cx=\"0\" cy=\"-25\"></circle></svg><span class=\"words\"></span></div></div>";
|
|
22
22
|
export type CompassMode = "full" | "north" | "off";
|
|
23
23
|
/** Read the attribute `compass`: `off` takes the compass away, `north` shows the arrow without the words, anything else (or nothing) shows both. */
|
|
24
24
|
export declare function readCompass(value: string | null): CompassMode;
|
|
25
|
+
/**
|
|
26
|
+
* The corners of the picture the compass of a ride can be put in (the attribute `compass-place`, the property `compassPlace`).
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import type { CompassPlace } from "@johnmorrisdotca/chikyu-earth/space";
|
|
31
|
+
*
|
|
32
|
+
* const corner: CompassPlace = "top-right";
|
|
33
|
+
* console.log(corner);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export type CompassPlace = "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
37
|
+
/**
|
|
38
|
+
* How far the compass is from its corner, in pixels: `x` from the side and `y` from the top or the bottom (the attribute `compass-offset`, the property `compassOffset`).
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import type { CompassOffset } from "@johnmorrisdotca/chikyu-earth/space";
|
|
43
|
+
*
|
|
44
|
+
* const offset: CompassOffset = { x: 16, y: 96 };
|
|
45
|
+
* console.log(`${offset.x},${offset.y}`);
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export interface CompassOffset {
|
|
49
|
+
x: number;
|
|
50
|
+
y: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The compass's corner when nothing is set: the top-left, where it always was.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { COMPASS_PLACE } from "@johnmorrisdotca/chikyu-earth/space";
|
|
58
|
+
*
|
|
59
|
+
* console.log(COMPASS_PLACE);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare const COMPASS_PLACE: CompassPlace;
|
|
63
|
+
/**
|
|
64
|
+
* The compass's offset when nothing is set: 8 pixels in from both sides of its corner, where it always was.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { COMPASS_OFFSET } from "@johnmorrisdotca/chikyu-earth/space";
|
|
69
|
+
*
|
|
70
|
+
* console.log(COMPASS_OFFSET.x, COMPASS_OFFSET.y);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare const COMPASS_OFFSET: Readonly<CompassOffset>;
|
|
74
|
+
/**
|
|
75
|
+
* Read the attribute `compass-place`: one of the four corners, in any case, or the top-left corner for anything else (or nothing).
|
|
76
|
+
*
|
|
77
|
+
* @param value - The attribute's text, or `null` when it is not set.
|
|
78
|
+
* @returns The corner.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* import { readCompassPlace } from "@johnmorrisdotca/chikyu-earth/space";
|
|
83
|
+
*
|
|
84
|
+
* console.log(readCompassPlace("Bottom-Right"), readCompassPlace("middle"));
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export declare function readCompassPlace(value: string | null): CompassPlace;
|
|
88
|
+
/**
|
|
89
|
+
* Read the attribute `compass-offset`: `x,y` in pixels from the corner (a space may stand for the comma and `px` may follow a number), or one number for both. Each is 0 or more; anything else (or nothing) is 8,8.
|
|
90
|
+
*
|
|
91
|
+
* @param value - The attribute's text, or `null` when it is not set.
|
|
92
|
+
* @returns The offset in pixels.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { readCompassOffset } from "@johnmorrisdotca/chikyu-earth/space";
|
|
97
|
+
*
|
|
98
|
+
* console.log(readCompassOffset("16,96"), readCompassOffset("-3,x"));
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function readCompassOffset(value: string | null): CompassOffset;
|
|
25
102
|
export interface Compass {
|
|
103
|
+
/** Put the compass in a corner, `offset` pixels in from it; the offset is held to what the picture has room for, so the compass is always inside it. */
|
|
104
|
+
place(place: CompassPlace, offset: CompassOffset): void;
|
|
26
105
|
/** Show what the last draw found (or hide the compass for `null`). Changes the page only when something it shows moved by half a degree (the words: a whole degree), the language or the mode changed, so a view at rest does nothing. */
|
|
27
106
|
update(track: RideTrack | null, lang: "en" | "ja", mode: CompassMode): void;
|
|
28
107
|
/** What the compass shows now, for a test: the angle of the arrow, the angle of the dot and the words; `null` when it is hidden. */
|
package/dist/space/compass.js
CHANGED
|
@@ -6,18 +6,81 @@ export const COMPASS_WORDS = {
|
|
|
6
6
|
en: { north: "N", heading: "Heading {point} {deg}°", label: "Compass: north is shown by the arrow. Heading {point}, {deg} degrees.", points: { N: "N", NE: "NE", E: "E", SE: "SE", S: "S", SW: "SW", W: "W", NW: "NW" } },
|
|
7
7
|
ja: { north: "北", heading: "進行方向 {point} {deg}°", label: "方位磁針:矢印が北を指します。進行方向は{point}、{deg}度。", points: { N: "北", NE: "北東", E: "東", SE: "南東", S: "南", SW: "南西", W: "西", NW: "北西" } },
|
|
8
8
|
};
|
|
9
|
-
/** The styles of the compass (`#compass`) in an element's shadow root. The dial is white lines on a dark disc, the way-it-goes dot yellow, so it reads on the sea, the land, the night and the day alike; `--chikyu-compass-colour` and `--chikyu-compass-travel` change them. */
|
|
10
|
-
export const COMPASS_STYLE = "#compass{position:absolute;
|
|
9
|
+
/** The styles of the compass (`#compass`, in `#compass-place`) in an element's shadow root. `#compass-place` is a grid over the whole picture: a gap of the offset's size on the corner's two sides (it gives way when the picture is too small, so the compass never leaves it), and the compass in the cell beside them. The dial is white lines on a dark disc, the way-it-goes dot yellow, so it reads on the sea, the land, the night and the day alike; `--chikyu-compass-colour` and `--chikyu-compass-travel` change them. */
|
|
10
|
+
export const COMPASS_STYLE = "#compass-place{position:absolute;inset:0;display:grid;grid-template-columns:minmax(0,var(--compass-x,8px)) max-content;grid-template-rows:minmax(0,var(--compass-y,8px)) max-content;justify-content:start;align-content:start;pointer-events:none}#compass-place[data-right]{grid-template-columns:max-content minmax(0,var(--compass-x,8px));justify-content:end}#compass-place[data-bottom]{grid-template-rows:max-content minmax(0,var(--compass-y,8px));align-content:end}#compass{grid-column:2;grid-row:2;justify-self:start;align-self:start;display:flex;flex-direction:column;align-items:center;gap:2px;pointer-events:none;color:var(--chikyu-compass-colour,#fff);font:11px/1.2 system-ui,-apple-system,sans-serif}#compass-place[data-right] #compass{grid-column:1}#compass-place[data-bottom] #compass{grid-row:1}#compass[hidden]{display:none}#compass svg{width:64px;height:64px;display:block;overflow:visible}#compass .disc{fill:#0b0e14b3;stroke:currentColor;stroke-opacity:.55;stroke-width:1}#compass .north{fill:currentColor}#compass .south{fill:currentColor;fill-opacity:.35}#compass .travel{fill:var(--chikyu-compass-travel,#ffd166);stroke:#0b0e14;stroke-width:1}#compass text{fill:currentColor;font:600 11px system-ui,-apple-system,sans-serif;text-anchor:middle;dominant-baseline:central;paint-order:stroke;stroke:#0b0e14;stroke-width:2.5px}#compass .words{background:#0b0e14b3;padding:1px 6px;border-radius:4px;white-space:nowrap}#compass .words[hidden]{display:none}";
|
|
11
11
|
/** The compass's markup: put it in the shadow root and hand it to `createCompass`. */
|
|
12
|
-
export const COMPASS_HTML = '<div id="compass" role="img" hidden><svg viewBox="-36 -36 72 72" aria-hidden="true"><circle class="disc" r="25"></circle><g class="arrow"><path class="north" d="M0 -21 L5 -3 L0 -7 L-5 -3 Z"></path><path class="south" d="M0 21 L4 4 L0 7 L-4 4 Z"></path></g><text class="n" x="0" y="-31">N</text><circle class="travel" r="3.4" cx="0" cy="-25"></circle></svg><span class="words"></span></div>';
|
|
12
|
+
export const COMPASS_HTML = '<div id="compass-place"><div id="compass" role="img" hidden><svg viewBox="-36 -36 72 72" aria-hidden="true"><circle class="disc" r="25"></circle><g class="arrow"><path class="north" d="M0 -21 L5 -3 L0 -7 L-5 -3 Z"></path><path class="south" d="M0 21 L4 4 L0 7 L-4 4 Z"></path></g><text class="n" x="0" y="-31">N</text><circle class="travel" r="3.4" cx="0" cy="-25"></circle></svg><span class="words"></span></div></div>';
|
|
13
13
|
/** Read the attribute `compass`: `off` takes the compass away, `north` shows the arrow without the words, anything else (or nothing) shows both. */
|
|
14
14
|
export function readCompass(value) {
|
|
15
15
|
const text = (value ?? "").trim().toLowerCase();
|
|
16
16
|
return text === "off" || text === "false" || text === "no" || text === "none" ? "off" : text === "north" ? "north" : "full";
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* The compass's corner when nothing is set: the top-left, where it always was.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { COMPASS_PLACE } from "@johnmorrisdotca/chikyu-earth/space";
|
|
24
|
+
*
|
|
25
|
+
* console.log(COMPASS_PLACE);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export const COMPASS_PLACE = "top-left";
|
|
29
|
+
/**
|
|
30
|
+
* The compass's offset when nothing is set: 8 pixels in from both sides of its corner, where it always was.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { COMPASS_OFFSET } from "@johnmorrisdotca/chikyu-earth/space";
|
|
35
|
+
*
|
|
36
|
+
* console.log(COMPASS_OFFSET.x, COMPASS_OFFSET.y);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export const COMPASS_OFFSET = { x: 8, y: 8 };
|
|
40
|
+
const COMPASS_PLACES = ["top-left", "top-right", "bottom-left", "bottom-right"];
|
|
41
|
+
/**
|
|
42
|
+
* Read the attribute `compass-place`: one of the four corners, in any case, or the top-left corner for anything else (or nothing).
|
|
43
|
+
*
|
|
44
|
+
* @param value - The attribute's text, or `null` when it is not set.
|
|
45
|
+
* @returns The corner.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { readCompassPlace } from "@johnmorrisdotca/chikyu-earth/space";
|
|
50
|
+
*
|
|
51
|
+
* console.log(readCompassPlace("Bottom-Right"), readCompassPlace("middle"));
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function readCompassPlace(value) {
|
|
55
|
+
const text = (value ?? "").trim().toLowerCase();
|
|
56
|
+
return COMPASS_PLACES.find((place) => place === text) ?? COMPASS_PLACE;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Read the attribute `compass-offset`: `x,y` in pixels from the corner (a space may stand for the comma and `px` may follow a number), or one number for both. Each is 0 or more; anything else (or nothing) is 8,8.
|
|
60
|
+
*
|
|
61
|
+
* @param value - The attribute's text, or `null` when it is not set.
|
|
62
|
+
* @returns The offset in pixels.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { readCompassOffset } from "@johnmorrisdotca/chikyu-earth/space";
|
|
67
|
+
*
|
|
68
|
+
* console.log(readCompassOffset("16,96"), readCompassOffset("-3,x"));
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export function readCompassOffset(value) {
|
|
72
|
+
const parts = (value ?? "").trim().toLowerCase().split(/\s*,\s*|\s+/);
|
|
73
|
+
if (parts.length > 2)
|
|
74
|
+
return { ...COMPASS_OFFSET };
|
|
75
|
+
const numbers = parts.map((part) => (/^\d+(\.\d+)?(px)?$/.test(part) ? parseFloat(part) : NaN));
|
|
76
|
+
if (numbers.some((n) => !Number.isFinite(n)))
|
|
77
|
+
return { ...COMPASS_OFFSET };
|
|
78
|
+
return { x: numbers[0], y: numbers[1] ?? numbers[0] };
|
|
79
|
+
}
|
|
18
80
|
/** Take the markup the element put in its shadow root and make the compass of it. */
|
|
19
81
|
export function createCompass(root) {
|
|
20
82
|
const box = root.getElementById("compass");
|
|
83
|
+
const slot = root.getElementById("compass-place");
|
|
21
84
|
const arrow = box.querySelector(".arrow");
|
|
22
85
|
const letter = box.querySelector("text.n");
|
|
23
86
|
const dot = box.querySelector(".travel");
|
|
@@ -25,6 +88,12 @@ export function createCompass(root) {
|
|
|
25
88
|
let key = "";
|
|
26
89
|
let shown = null;
|
|
27
90
|
return {
|
|
91
|
+
place(place, offset) {
|
|
92
|
+
slot.toggleAttribute("data-right", place.endsWith("right"));
|
|
93
|
+
slot.toggleAttribute("data-bottom", place.startsWith("bottom"));
|
|
94
|
+
slot.style.setProperty("--compass-x", `${offset.x}px`);
|
|
95
|
+
slot.style.setProperty("--compass-y", `${offset.y}px`);
|
|
96
|
+
},
|
|
28
97
|
update(track, lang, mode) {
|
|
29
98
|
if (!track || mode === "off" || track.northDeg === null) {
|
|
30
99
|
if (!box.hidden)
|
|
@@ -23,6 +23,7 @@ import { type SatelliteScreen, type SatelliteStyle } from "./satellite-layer.ts"
|
|
|
23
23
|
import { type SatelliteOthers } from "./satellite-focus.ts";
|
|
24
24
|
import { type PathStats } from "./path-controls.ts";
|
|
25
25
|
import { type PathHit, type PathRequest, type PathStyle } from "./paths.ts";
|
|
26
|
+
import { type CompassOffset, type CompassPlace } from "./compass.ts";
|
|
26
27
|
import type { RideUp } from "./north-up.ts";
|
|
27
28
|
import { type RideDrag, type RideFace, type RideLook, type RideModelSize, type RideViewpoint } from "./ride.ts";
|
|
28
29
|
import { type ScaleMode } from "./scale.ts";
|
|
@@ -797,6 +798,36 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
797
798
|
* ```
|
|
798
799
|
*/
|
|
799
800
|
get rideTrack(): RideTrack | null;
|
|
801
|
+
/**
|
|
802
|
+
* The corner of the picture the compass of a ride is in (the attribute `compass-place`): `top-left` (the default, and where it always was), `top-right`, `bottom-left` or `bottom-right`. Anything else reads as `top-left`.
|
|
803
|
+
* Set while riding, it moves the compass at once. The compass is held inside the picture on every side, so on a narrow picture it is still all there. See `compassOffset`.
|
|
804
|
+
*
|
|
805
|
+
* @example
|
|
806
|
+
* ```ts
|
|
807
|
+
* import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
808
|
+
*
|
|
809
|
+
* const space = document.createElement("chikyu-space") as ChikyuSpace;
|
|
810
|
+
* space.compassPlace = "top-right";
|
|
811
|
+
* console.log(space.compassPlace);
|
|
812
|
+
* ```
|
|
813
|
+
*/
|
|
814
|
+
get compassPlace(): CompassPlace;
|
|
815
|
+
set compassPlace(value: CompassPlace);
|
|
816
|
+
/**
|
|
817
|
+
* How far in from its corner the compass of a ride is, in pixels (the attribute `compass-offset`, written `x,y`, such as `16,96`, or one number for both): `x` from the side, `y` from the top or the bottom. It is `{ x: 8, y: 8 }` by default, where the compass always was.
|
|
818
|
+
* A value that is not two numbers of 0 or more reads as the default. The offset is held to the room the picture has, so a large one leaves the compass against the far edge, not outside it. Set while riding, it moves the compass at once. See `compassPlace`.
|
|
819
|
+
*
|
|
820
|
+
* @example
|
|
821
|
+
* ```ts
|
|
822
|
+
* import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
823
|
+
*
|
|
824
|
+
* const space = document.createElement("chikyu-space") as ChikyuSpace;
|
|
825
|
+
* space.compassOffset = { x: 16, y: 96 };
|
|
826
|
+
* console.log(space.compassOffset);
|
|
827
|
+
* ```
|
|
828
|
+
*/
|
|
829
|
+
get compassOffset(): CompassOffset;
|
|
830
|
+
set compassOffset(value: CompassOffset);
|
|
800
831
|
/**
|
|
801
832
|
* The radius of the ridden satellite's model as a share of the picture's height, 0.02 to 1.2 (the attribute `ride-model-share`), or `null` for the ride's own: 0.22 along the way it goes, 0.17 above the satellite (its size at the lowest height; `ride-model-size="distance"` still shrinks it as the ride rises).
|
|
802
833
|
* Set while riding it glides in 0.4 s (at once for a reader who asked for less motion). `stats.followModel.share` is the share in use.
|
|
@@ -41,7 +41,7 @@ import { bindPaths, emptyPathStats, pointerOf, readPathPriority } from "./path-c
|
|
|
41
41
|
import { styleTable } from "./paths.js";
|
|
42
42
|
import { bindSatelliteHover, hoverPathOn, hoverStyleOf, namesOnHover as namesHoverOn } from "./satellite-hover.js";
|
|
43
43
|
import { clampFollow, retargetFollow } from "./follow.js";
|
|
44
|
-
import { COMPASS_HTML, COMPASS_STYLE, createCompass, readCompass } from "./compass.js";
|
|
44
|
+
import { COMPASS_HTML, COMPASS_STYLE, createCompass, readCompass, readCompassOffset, readCompassPlace } from "./compass.js";
|
|
45
45
|
import { OUTSIDE_KM, RIDE_FACES, rideTiltLimits, rideTurnDegrees } from "./ride.js";
|
|
46
46
|
import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
|
|
47
47
|
import { BODY_NAMES, createSpaceItem, DEFAULT_EARTH_SIZE, newSpaceModel } from "./scene.js";
|
|
@@ -200,7 +200,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
|
|
|
200
200
|
* ```
|
|
201
201
|
*/
|
|
202
202
|
export class ChikyuSpace extends HTMLElement {
|
|
203
|
-
static observedAttributes = ["cloud-drift", "cloud-fade", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...BEAM_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "place-layers", "here-city", "route", "bodies-credit", "satellite-tint", "satellite-streak-max", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "ride-viewpoint", "ride-outside-km", "ride-model-size", "ride-drag", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far", "follow", "follow-ease", "dim-occluded", "ride-model-share", "ride-model-seat", "ride-zoom", "ride-up", "compass", "smooth-fps"];
|
|
203
|
+
static observedAttributes = ["cloud-drift", "cloud-fade", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...BEAM_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "place-layers", "here-city", "route", "bodies-credit", "satellite-tint", "satellite-streak-max", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "ride-viewpoint", "ride-outside-km", "ride-model-size", "ride-drag", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far", "follow", "follow-ease", "dim-occluded", "ride-model-share", "ride-model-seat", "ride-zoom", "ride-up", "compass", "compass-place", "compass-offset", "smooth-fps"];
|
|
204
204
|
#model = newSpaceModel();
|
|
205
205
|
/** The finer imagery (NASA's tile service), one source while the attributes stay the same. Off unless `tiles-finer="gibs"`. */
|
|
206
206
|
#finerHold = createFinerHolder(() => new Date(this.#model.time), () => this.#gate?.request());
|
|
@@ -317,6 +317,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
317
317
|
root.innerHTML = `<div id="stage"></div><div id="places"></div><div id="labels" aria-hidden="true"></div>${COMPASS_HTML}<div id="notes"><p id="air-note" hidden></p><p id="meteor-note" hidden></p><p id="bodies-note" hidden></p><p id="finer-credit" hidden></p></div>`;
|
|
318
318
|
adoptStyles(root, STYLE, this.nonce);
|
|
319
319
|
this.#compass = createCompass(root);
|
|
320
|
+
this.#placeCompass();
|
|
320
321
|
this.#stage = root.getElementById("stage");
|
|
321
322
|
this.#labelBox = root.getElementById("labels");
|
|
322
323
|
this.#note = root.getElementById("meteor-note");
|
|
@@ -537,6 +538,8 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
537
538
|
this.#applyUp();
|
|
538
539
|
else if (name === "compass")
|
|
539
540
|
this.#showCompass();
|
|
541
|
+
else if (name === "compass-place" || name === "compass-offset")
|
|
542
|
+
this.#placeCompass();
|
|
540
543
|
else if (name === "ride-model-share" || name === "ride-model-seat")
|
|
541
544
|
this.#applyFrame();
|
|
542
545
|
else if (name === "ride-zoom")
|
|
@@ -2094,6 +2097,47 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
2094
2097
|
get rideTrack() {
|
|
2095
2098
|
return this.#model.rideTrack ? { ...this.#model.rideTrack } : null;
|
|
2096
2099
|
}
|
|
2100
|
+
/**
|
|
2101
|
+
* The corner of the picture the compass of a ride is in (the attribute `compass-place`): `top-left` (the default, and where it always was), `top-right`, `bottom-left` or `bottom-right`. Anything else reads as `top-left`.
|
|
2102
|
+
* Set while riding, it moves the compass at once. The compass is held inside the picture on every side, so on a narrow picture it is still all there. See `compassOffset`.
|
|
2103
|
+
*
|
|
2104
|
+
* @example
|
|
2105
|
+
* ```ts
|
|
2106
|
+
* import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
2107
|
+
*
|
|
2108
|
+
* const space = document.createElement("chikyu-space") as ChikyuSpace;
|
|
2109
|
+
* space.compassPlace = "top-right";
|
|
2110
|
+
* console.log(space.compassPlace);
|
|
2111
|
+
* ```
|
|
2112
|
+
*/
|
|
2113
|
+
get compassPlace() {
|
|
2114
|
+
return readCompassPlace(this.getAttribute("compass-place"));
|
|
2115
|
+
}
|
|
2116
|
+
set compassPlace(value) {
|
|
2117
|
+
this.setAttribute("compass-place", value);
|
|
2118
|
+
}
|
|
2119
|
+
/**
|
|
2120
|
+
* How far in from its corner the compass of a ride is, in pixels (the attribute `compass-offset`, written `x,y`, such as `16,96`, or one number for both): `x` from the side, `y` from the top or the bottom. It is `{ x: 8, y: 8 }` by default, where the compass always was.
|
|
2121
|
+
* A value that is not two numbers of 0 or more reads as the default. The offset is held to the room the picture has, so a large one leaves the compass against the far edge, not outside it. Set while riding, it moves the compass at once. See `compassPlace`.
|
|
2122
|
+
*
|
|
2123
|
+
* @example
|
|
2124
|
+
* ```ts
|
|
2125
|
+
* import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
2126
|
+
*
|
|
2127
|
+
* const space = document.createElement("chikyu-space") as ChikyuSpace;
|
|
2128
|
+
* space.compassOffset = { x: 16, y: 96 };
|
|
2129
|
+
* console.log(space.compassOffset);
|
|
2130
|
+
* ```
|
|
2131
|
+
*/
|
|
2132
|
+
get compassOffset() {
|
|
2133
|
+
return readCompassOffset(this.getAttribute("compass-offset"));
|
|
2134
|
+
}
|
|
2135
|
+
set compassOffset(value) {
|
|
2136
|
+
this.setAttribute("compass-offset", `${value.x},${value.y}`);
|
|
2137
|
+
}
|
|
2138
|
+
#placeCompass() {
|
|
2139
|
+
this.#compass?.place(this.compassPlace, this.compassOffset);
|
|
2140
|
+
}
|
|
2097
2141
|
/** Shows the compass for the last draw (the language, the mode of the attribute `compass`), and tells the page when the heading changed by a whole degree, or the satellite went into or out of the Earth's shadow. Called with the draw. */
|
|
2098
2142
|
#showCompass() {
|
|
2099
2143
|
const track = this.#model.rideTrack;
|
package/dist/space/index.d.ts
CHANGED
|
@@ -12,3 +12,4 @@ export type { BeamStats } from "../beam/layer.ts";
|
|
|
12
12
|
export { RIDE_PATH_FADE_KM } from "./path-ribbons.ts";
|
|
13
13
|
export { createTrailBuilder, TRAIL_DEFAULT_ORBITS, TRAIL_MAX_ORBITS, TRAIL_MAX_POINTS, TRAIL_POINTS_PER_ORBIT, trailOrbits, type PlaceAt, type TrailBuilder } from "./trail.ts";
|
|
14
14
|
export { descentFloorKm, FLY_FLOOR_KM, FLY_HEIGHT_KM, FLY_MIN_KM, flyAcrossMs, flyAim, flyAt, flyDistance, flyDownMs, flyLonLat, flyStateAt, flyStill, planFly, type FlyPhase, type FlyPlan, type FlyPoint, type FlyState } from "./fly.ts";
|
|
15
|
+
export { COMPASS_OFFSET, COMPASS_PLACE, readCompassOffset, readCompassPlace, type CompassOffset, type CompassPlace } from "./compass.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -13,3 +13,4 @@ export { BEAM_ATTRIBUTES, BEAM_COLOUR, BEAM_ELEVATION, beamCells, footprintAngle
|
|
|
13
13
|
export { RIDE_PATH_FADE_KM } from "./path-ribbons.js";
|
|
14
14
|
export { createTrailBuilder, TRAIL_DEFAULT_ORBITS, TRAIL_MAX_ORBITS, TRAIL_MAX_POINTS, TRAIL_POINTS_PER_ORBIT, trailOrbits } from "./trail.js";
|
|
15
15
|
export { descentFloorKm, FLY_FLOOR_KM, FLY_HEIGHT_KM, FLY_MIN_KM, flyAcrossMs, flyAim, flyAt, flyDistance, flyDownMs, flyLonLat, flyStateAt, flyStill, planFly } from "./fly.js";
|
|
16
|
+
export { COMPASS_OFFSET, COMPASS_PLACE, readCompassOffset, readCompassPlace } from "./compass.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.65.0",
|
|
4
4
|
"description": "Chikyu Earth 地球 — A line-drawn globe for the web: country outlines that turn at the Earth's own rate, centred on the place you give it, with an optional realistic Earth from space (three.js), the Sun, Moon and planets, satellites on their orbits, and markers for any place. A web component and an SVG string.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"earth",
|