astraeus 0.8.1 → 0.9.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 +67 -0
- package/README.md +28 -15
- package/package.json +1 -1
- package/src/api/AstraeusScene.d.ts +1 -1
- package/src/api/AstraeusScene.js +4 -1
- package/src/api/AstraeusScene.node.js +4 -1
- package/src/api/assembleScene.d.ts +2 -0
- package/src/api/assembleScene.js +27 -5
- package/src/api/cameraRequest.d.ts +15 -0
- package/src/api/cameraRequest.js +89 -0
- package/src/api/errors.d.ts +9 -1
- package/src/api/index.d.ts +6 -3
- package/src/api/look.d.ts +49 -0
- package/src/api/lookInput.d.ts +1 -1
- package/src/api/lookInput.js +6 -1
- package/src/api/planCamera.d.ts +35 -7
- package/src/api/planCamera.js +94 -11
- package/src/api/planSkyFigures.d.ts +22 -0
- package/src/api/planSkyFigures.js +145 -0
- package/src/api/planStory.d.ts +2 -2
- package/src/api/planStory.js +14 -9
- package/src/api/planViews.js +1 -1
- package/src/api/scene.d.ts +17 -4
- package/src/api/scene.js +23 -5
- package/src/api/sceneReads.d.ts +21 -2
- package/src/api/skyFigureInput.d.ts +45 -0
- package/src/api/skyFigureInput.js +1 -0
- package/src/api/skyTraceInput.d.ts +33 -0
- package/src/api/skyTraceInput.js +45 -0
- package/src/api/story.d.ts +12 -3
- package/src/api/story.js +44 -1
- package/src/api/viewerCamera.d.ts +4 -3
- package/src/api/viewerCamera.js +10 -32
- package/src/api/viewerHandle.d.ts +27 -4
- package/src/api/viewerHandle.js +6 -0
- package/src/api/viewerLink.d.ts +49 -4
- package/src/api/viewerLink.js +25 -0
- package/src/api/viewerPanels.d.ts +26 -0
- package/src/api/viewerPanels.js +42 -0
- package/src/api/viewerSelection.d.ts +1 -1
- package/src/api/viewerSelection.js +3 -3
- package/src/app/App.js +100 -18
- package/src/app/App.node.js +100 -18
- package/src/app/AstraeusScene.d.ts +20 -5
- package/src/app/AstraeusScene.js +3 -3
- package/src/app/CameraController.d.ts +17 -0
- package/src/app/CameraController.js +34 -9
- package/src/app/DeveloperSettings.d.ts +11 -3
- package/src/app/DeveloperSettings.js +13 -3
- package/src/app/SceneLabels.d.ts +20 -2
- package/src/app/SceneLabels.js +46 -6
- package/src/app/SkyFiguresView.d.ts +56 -0
- package/src/app/SkyFiguresView.js +242 -0
- package/src/app/StoryMarkers.d.ts +2 -2
- package/src/app/StoryMarkers.js +2 -2
- package/src/app/displaySwitches.d.ts +13 -3
- package/src/app/displaySwitches.js +17 -3
- package/src/app/experienceDefinition.d.ts +9 -3
- package/src/app/experienceDefinition.js +4 -2
- package/src/app/labelStyle.d.ts +17 -0
- package/src/app/labelStyle.js +13 -0
- package/src/app/liveLook.js +8 -0
- package/src/app/look.d.ts +9 -5
- package/src/app/look.js +11 -0
- package/src/app/lookOut.d.ts +32 -0
- package/src/app/lookOut.js +50 -0
- package/src/app/sceneCamera.d.ts +5 -3
- package/src/app/sceneCamera.js +66 -3
- package/src/app/sceneContentsHooks.d.ts +2 -1
- package/src/app/sceneContentsHooks.js +3 -2
- package/src/app/sceneFrame.d.ts +10 -1
- package/src/app/sceneFrame.js +45 -10
- package/src/app/sceneFraming.d.ts +7 -0
- package/src/app/sceneFraming.js +12 -0
- package/src/app/sceneHooks.d.ts +2 -0
- package/src/app/sceneHooks.js +4 -1
- package/src/app/scenePicking.d.ts +20 -0
- package/src/app/scenePicking.js +49 -0
- package/src/app/scenePointer.d.ts +3 -1
- package/src/app/scenePointer.js +3 -2
- package/src/app/skyFigures.d.ts +73 -0
- package/src/app/skyFigures.js +50 -0
- package/src/app/style.css +2 -1
- package/src/app/viewHiding.d.ts +2 -0
- package/src/app/viewHiding.js +7 -1
- package/src/app/viewLink.d.ts +8 -8
- package/src/app/viewLink.js +24 -4
- package/src/app/viewerPort.d.ts +30 -3
- package/src/assets/sky.d.ts +13 -4
- package/src/assets/sky.js +33 -8
- package/src/assets/stars/hyg-v42-naked-eye.json +1 -1
- package/src/core/bodies/moonSystem.js +1 -15
- package/src/core/lookValues.d.ts +9 -0
- package/src/core/lookValues.js +24 -0
- package/src/core/readBytes.d.ts +1 -0
- package/src/core/readBytes.js +15 -0
- package/src/core/skyTrace.d.ts +49 -0
- package/src/core/skyTrace.js +39 -0
- package/src/core/startView.d.ts +39 -0
- package/src/core/startView.js +56 -0
- package/src/core/storyPanels.d.ts +51 -3
- package/src/core/storyPanels.js +52 -12
- package/src/shell/AstraeusShell.d.ts +15 -6
- package/src/shell/AstraeusShell.js +76 -20
- package/src/shell/AstraeusShell.node.js +76 -20
- package/src/shell/ObjectControls.js +11 -8
- package/src/shell/StoryPanelView.d.ts +12 -3
- package/src/shell/StoryPanelView.js +2 -2
- package/src/shell/experience.d.ts +24 -0
- package/src/shell/experience.js +4 -1
- package/src/shell/infoModel.js +9 -1
- package/src/shell/objectModel.d.ts +6 -2
- package/src/shell/objectModel.js +10 -1
- package/src/shell/phone.css +1 -1
- package/src/shell/storyPanels.d.ts +1 -1
- package/src/shell/storyPanels.js +1 -1
- package/src/shell/style.css +9 -1
- package/src/shell/topBarIcons.d.ts +1 -0
- package/src/shell/topBarIcons.js +1 -0
- package/src/shell/useStoryPanels.d.ts +9 -6
- package/src/shell/useStoryPanels.js +10 -6
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { LookInput, LookRead } from "./look.js";
|
|
2
2
|
import type { PickChange } from "./pickerInput.js";
|
|
3
3
|
import type { TimeInput } from "./time.js";
|
|
4
|
+
import type { SceneSkyFigureRead } from "./sceneReads.js";
|
|
5
|
+
import type { SkyClearOptions, SkyTraceOptions } from "./skyTraceInput.js";
|
|
4
6
|
import type { SelectionChange } from "./viewerSelection.js";
|
|
7
|
+
import type { PanelChange } from "./viewerPanels.js";
|
|
5
8
|
import type { CameraPose, CameraTarget, EventZoneChange, ViewerChange, ViewerLink } from "./viewerLink.js";
|
|
6
9
|
/** Everything a host reads, sets and listens to on a drawn viewer: the handle `mount` returns (as `MountedScene`). Every call before the viewer is drawn or after it is gone throws `not-mounted`; reads are then undefined. */
|
|
7
10
|
export interface ViewerHandle {
|
|
@@ -21,9 +24,9 @@ export interface ViewerHandle {
|
|
|
21
24
|
setRate(rate: number | "auto"): void;
|
|
22
25
|
/** Switches to the view with this id (`setViews`). An unknown id, or a scene without views, throws `bad-view`; before `ready` or after `unmount` throws `not-mounted`. `onChange` hears it with `cause: "host"`. */
|
|
23
26
|
setView(id: string): void;
|
|
24
|
-
/** The camera as a plain value ({ focus, azimuthDeg, elevationDeg, distance }, the pose a copied view link carries); undefined until `ready` and after `unmount`; before the first frame is drawn it is the opening camera. Keep it and hand it to `setCamera` to put the camera back. */
|
|
27
|
+
/** The camera as a plain value (an orbit pose `{ focus, azimuthDeg, elevationDeg, distance }`, or a sky pose `{ lookOut, raDeg, decDeg, fovDeg }` while looking out; the pose a copied view link carries); undefined until `ready` and after `unmount`; before the first frame is drawn it is the opening camera (undefined for a look-out toward an id). Keep it and hand it to `setCamera` to put the camera back. */
|
|
25
28
|
readonly camera: CameraPose | undefined;
|
|
26
|
-
/** Points the camera: `{ follow: id }` keeps the distance, `{ focus: id }` frames the object, or a pose from `camera` puts it back where it was read (relative to its object, which a moving object carries along). The object must be one the showing view shows; an unknown or hidden id, or a malformed argument, throws `bad-camera`; before `ready` or after `unmount`, `not-mounted`. The camera eases there. */
|
|
29
|
+
/** Points the camera: `{ follow: id }` keeps the distance, `{ focus: id }` frames the object, `{ lookOut: id, direction?, fovDeg? }` stands inside a body looking out (direction: `{ raDeg, decDeg }` or an object id), or a pose from `camera` (either kind) puts it back where it was read (an orbit pose relative to its object, which a moving object carries along). The object must be one the showing view shows; an unknown or hidden id (the body or the object to turn toward), a direction or field of view out of range, or a malformed argument, throws `bad-camera`; before `ready` or after `unmount`, `not-mounted`. The camera eases there. */
|
|
27
30
|
setCamera(target: CameraTarget): void;
|
|
28
31
|
/** The ids of the events whose zone (`withinSeconds` of an event, or a pacing rule) holds the viewer's time now, among the zones the showing view has (an empty list in a scene without event zones); undefined until `ready` and after `unmount`. */
|
|
29
32
|
readonly eventZones: readonly string[] | undefined;
|
|
@@ -35,7 +38,7 @@ export interface ViewerHandle {
|
|
|
35
38
|
/** The id of the object whose information the viewer has open (the one the object menu, a click or a view switch chose); undefined until `ready` has resolved, after `unmount`, and when nothing is selected. Set it with `setSelected`. */
|
|
36
39
|
readonly selected: string | undefined;
|
|
37
40
|
/**
|
|
38
|
-
* Selects the object with this id, or clears the selection with `undefined`; `selected` reads it at once and `onSelect` hears it with `cause: "host"` (nothing is reported when the selection is already that).
|
|
41
|
+
* Selects the object (or sky figure, see `skyFigures`) with this id, or clears the selection with `undefined`; `selected` reads it at once and `onSelect` hears it with `cause: "host"` (nothing is reported when the selection is already that).
|
|
39
42
|
* The object must be one the showing view shows: an unknown or hidden id, an empty or non-string id throws `bad-selection`; before `ready` or after `unmount`, `not-mounted`. Like the object menu it opens the object's card, but the camera stays where it is (`setCamera` points the camera); a clear closes the card.
|
|
40
43
|
* Like every host call it is the last word: made straight after `await ready`, before the first frame, or inside an `onChange` report of a view switch, it holds; a later view switch that no longer shows the object drops it as it drops a visitor's choice.
|
|
41
44
|
*/
|
|
@@ -46,8 +49,14 @@ export interface ViewerHandle {
|
|
|
46
49
|
* No callbacks arrive after `unmount`. A listener that throws is reported to the page (`reportError`) and does not stop the listeners after it. Returns the function that stops it.
|
|
47
50
|
*/
|
|
48
51
|
onSelect(listener: (change: SelectionChange) => void): () => void;
|
|
52
|
+
/** The id of the open story panel or step; undefined until `ready`, after `unmount`, and when none is open. Set it with `setPanel`. */
|
|
53
|
+
readonly panel: string | undefined;
|
|
54
|
+
/** Opens the story panel or step with this id, or closes the open one with `undefined`; `onPanel` hears it with `cause: "host"`. Moves nothing else. An id the showing view does not show throws `bad-panels`; before `ready` or after `unmount`, `not-mounted`. */
|
|
55
|
+
setPanel(id: string | undefined): void;
|
|
56
|
+
/** Calls `listener({ panel?, timeUtcMs, cause })` when the open panel changes: `cause` is `visitor`, `host` (`setPanel`, or a drop by `setView`) or `playback` (a moment panel opened by itself). The opening panel is read, not reported. Returns the function that stops it. */
|
|
57
|
+
onPanel(listener: (change: PanelChange) => void): () => void;
|
|
49
58
|
/**
|
|
50
|
-
* Calls `listener(pose)` with the camera as a plain value (
|
|
59
|
+
* Calls `listener(pose)` with the camera as a plain value (an orbit pose or a sky pose, what `camera` reads) when it changes: a visitor's drag, zoom or pick, a view's camera rule, or your own `setCamera`
|
|
51
60
|
* (it reports as the camera eases, then stops when the pose settles). At most about ten times a second; an unchanged pose reports nothing, and neither does a camera following a moving object at a fixed pose.
|
|
52
61
|
* The pose the viewer opens with is read from `camera`, not reported. The engine moves nothing in response. No callbacks arrive after `unmount`. A listener that throws is reported to the page (`reportError`) and does not stop the listeners after it. Returns the function that stops it.
|
|
53
62
|
*/
|
|
@@ -60,6 +69,20 @@ export interface ViewerHandle {
|
|
|
60
69
|
readonly scale: string | undefined;
|
|
61
70
|
/** Switches to one of the scales the viewer offers (`Scene.scales`); any other id throws `bad-scale`; before `ready` or after `unmount`, `not-mounted`. `onChange` hears it with `cause: "host"`. */
|
|
62
71
|
setScale(id: string): void;
|
|
72
|
+
/** The sky figures the viewer draws (`Scene.addSkyFigures`), in the order added: id, label and kind; empty when the scene added none; undefined until `ready` has resolved and after `unmount`. */
|
|
73
|
+
readonly skyFigures: readonly SceneSkyFigureRead[] | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Traces the sky figure `id` (one of `skyFigures`) line by line: its segments are drawn in the order added, each growing from its first end, over `durationSeconds` (0.1 to 60, default 2) in the look's `skyLines.traced` colour; then `after` decides: `"stay"` (default) keeps them, `"fade"` eases them to `skyLines.faded` and removes them.
|
|
76
|
+
* The trace is drawn over the figure and follows the figure's switch (`skyFigures` or `skyBoundaries`): with the switch off it runs unseen. It runs on real time, so pausing or changing the scene clock does not change it; calling again restarts it. With `prefers-reduced-motion: reduce` the whole figure shows at once, stays for `seconds`, and then `after` applies (a `fade` removes it at once).
|
|
77
|
+
* An id that is not a figure the viewer draws throws `unknown-sky-figure`; options other than `{ durationSeconds?, after? }`, a `durationSeconds` outside its range or an `after` other than `stay` or `fade` throws `bad-sky-trace`; before `ready` or after `unmount`, `not-mounted`. It takes its place in call order with the other host calls.
|
|
78
|
+
*/
|
|
79
|
+
traceSkyFigure(id: string, options?: SkyTraceOptions): void;
|
|
80
|
+
/**
|
|
81
|
+
* Removes the trace of the sky figure `id` at any time (while it runs, after `stay`, or during a `fade`): the traced lines ease out over `durationSeconds` (0 to 60, default 1; 0 removes them at once), keeping the part drawn so far.
|
|
82
|
+
* A figure shown only when traced (`shown: "whenTraced"`) is then hidden, lines and label; an always-shown figure only loses the trace highlight and keeps its ordinary look. A figure with no trace is left alone (no error), and a later trace starts from nothing. With `prefers-reduced-motion: reduce` it removes the trace at once.
|
|
83
|
+
* An id that is not a figure the viewer draws throws `unknown-sky-figure`; options other than `{ durationSeconds? }` or a `durationSeconds` outside its range throws `bad-sky-trace`; before `ready` or after `unmount`, `not-mounted`. It takes its place in call order with the other host calls.
|
|
84
|
+
*/
|
|
85
|
+
clearSkyTrace(id: string, options?: SkyClearOptions): void;
|
|
63
86
|
/** The display switches the scene placed (`setSwitches`, wherever it placed them) that have something to act on, each on or off, by id (`orbitLines`, `labels`, `milkyWay`); empty when it placed none; undefined until `ready` has resolved and after `unmount`. */
|
|
64
87
|
readonly switches: Readonly<Record<string, boolean>> | undefined;
|
|
65
88
|
/** Turns a display switch the scene placed on or off, as the visitor's switch does; an id it did not place, or a non-boolean, throws `bad-switch`; before `ready` or after `unmount`, `not-mounted`. `onChange` hears it with `cause: "host"`. */
|
package/src/api/viewerHandle.js
CHANGED
|
@@ -8,18 +8,24 @@ export function viewerHandleOf(link) {
|
|
|
8
8
|
get camera() { return link.camera; },
|
|
9
9
|
get eventZones() { return link.eventZones; },
|
|
10
10
|
get selected() { return link.selected; },
|
|
11
|
+
get panel() { return link.panel; },
|
|
11
12
|
get look() { return link.look; },
|
|
12
13
|
get scale() { return link.scale; },
|
|
13
14
|
get switches() { return link.switches; },
|
|
15
|
+
get skyFigures() { return link.skyFigures; },
|
|
14
16
|
get pick() { return link.pick; },
|
|
15
17
|
setPick: (value) => link.setPick(value),
|
|
16
18
|
onPick: (listener) => link.onPick(listener),
|
|
17
19
|
setLook: (look) => link.setLook(look),
|
|
18
20
|
setScale: (id) => link.setScale(id),
|
|
19
21
|
setSwitch: (id, on) => link.setSwitch(id, on),
|
|
22
|
+
traceSkyFigure: (id, options) => link.traceSkyFigure(id, options),
|
|
23
|
+
clearSkyTrace: (id, options) => link.clearSkyTrace(id, options),
|
|
20
24
|
setView: (id) => link.setView(id),
|
|
21
25
|
setCamera: (target) => link.setCamera(target),
|
|
22
26
|
setSelected: (id) => link.setSelected(id),
|
|
27
|
+
setPanel: (id) => link.setPanel(id),
|
|
28
|
+
onPanel: (listener) => link.onPanel(listener),
|
|
23
29
|
setTime: (time) => link.setTime(time),
|
|
24
30
|
setRate: (rate) => link.setRate(rate),
|
|
25
31
|
setPlaying: (playing) => link.setPlaying(playing),
|
package/src/api/viewerLink.d.ts
CHANGED
|
@@ -2,8 +2,11 @@ import type { ViewerChangeCause, ViewerPort, ViewerState } from "../app/viewerPo
|
|
|
2
2
|
import type { ViewerControl } from "../app/viewerPort.js";
|
|
3
3
|
import type { LookInput, LookRead } from "./look.js";
|
|
4
4
|
import { type SelectionChange } from "./viewerSelection.js";
|
|
5
|
+
import { type PanelChange } from "./viewerPanels.js";
|
|
5
6
|
import type { PickChange } from "./pickerInput.js";
|
|
6
7
|
import type { TimeInput } from "./time.js";
|
|
8
|
+
import type { SceneSkyFigureRead } from "./sceneReads.js";
|
|
9
|
+
import { type SkyClearOptions, type SkyTraceOptions } from "./skyTraceInput.js";
|
|
7
10
|
/** What a host is told when the viewer's time, speed or playing state changes. */
|
|
8
11
|
export interface ViewerChange {
|
|
9
12
|
/** The viewer's time, Unix milliseconds UTC. */
|
|
@@ -38,8 +41,8 @@ export interface EventZoneChange {
|
|
|
38
41
|
/** What the report is about: `time` (playback crossed the zone, or a seek moved the clock across it) or `view` (a view switch showed or hid the zone). After a `view` leave the view's own camera rule owns the camera, so a host that restores a camera should do it only for `time`. */
|
|
39
42
|
readonly via: "time" | "view";
|
|
40
43
|
}
|
|
41
|
-
/** The camera as a plain value: the object it is centred on and where it stands from it.
|
|
42
|
-
export interface
|
|
44
|
+
/** The camera orbiting an object, as a plain value: the object it is centred on and where it stands from it. One of the two kinds of `CameraPose`. */
|
|
45
|
+
export interface OrbitPose {
|
|
43
46
|
/** The id of the object the camera is centred on (and follows as it moves). */
|
|
44
47
|
readonly focus: string;
|
|
45
48
|
/** Degrees about the up direction, 0 up to 360 (rounded to 0.01). */
|
|
@@ -49,12 +52,44 @@ export interface CameraPose {
|
|
|
49
52
|
/** Camera-to-object distance in the scene's scaled units (Earth radii), to five significant figures. */
|
|
50
53
|
readonly distance: number;
|
|
51
54
|
}
|
|
52
|
-
/**
|
|
55
|
+
/** A star-map position: J2000 equatorial degrees (the engine's EQJ frame). */
|
|
56
|
+
export interface SkyDirection {
|
|
57
|
+
/** Right ascension in degrees, 0 up to 360 (a value outside wraps). */
|
|
58
|
+
readonly raDeg: number;
|
|
59
|
+
/** Declination in degrees, within ±90. */
|
|
60
|
+
readonly decDeg: number;
|
|
61
|
+
}
|
|
62
|
+
/** The camera standing inside a body and looking out, as a plain value: the body, where it points and its field of view. One of the two kinds of `CameraPose`. */
|
|
63
|
+
export interface SkyPose {
|
|
64
|
+
/** The id of the body the camera stands in (at its centre). */
|
|
65
|
+
readonly lookOut: string;
|
|
66
|
+
/** Right ascension of the look direction, degrees 0 up to 360, J2000 equatorial (rounded to 0.01). */
|
|
67
|
+
readonly raDeg: number;
|
|
68
|
+
/** Declination of the look direction, degrees within ±90, J2000 equatorial (rounded to 0.01). */
|
|
69
|
+
readonly decDeg: number;
|
|
70
|
+
/** Vertical field of view in degrees, 5 to 100: the zoom (rounded to 0.01). */
|
|
71
|
+
readonly fovDeg: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* What `MountedScene.camera` reads and `onCameraChange` reports: an orbit pose (has `distance`) while the camera orbits an object, or a sky pose
|
|
75
|
+
* (has `lookOut`) while it stands inside a body looking out. Tell them apart with `"lookOut" in pose`; put either back with `setCamera`.
|
|
76
|
+
*/
|
|
77
|
+
export type CameraPose = OrbitPose | SkyPose;
|
|
78
|
+
/** Stand inside a body (at its centre) and look out: turned to a star-map position or toward an object, with an optional field of view. */
|
|
79
|
+
export interface LookOutTarget {
|
|
80
|
+
/** The id of the body to stand in; a body the showing view shows. */
|
|
81
|
+
readonly lookOut: string;
|
|
82
|
+
/** Where to point: a star-map position, or the id of an object or sky figure to turn toward. Omitted: the direction it already looks while looking out, else right ascension 0, declination 0. */
|
|
83
|
+
readonly direction?: SkyDirection | string;
|
|
84
|
+
/** Vertical field of view in degrees, 5 to 100. Omitted: the current one while looking out, else 60. */
|
|
85
|
+
readonly fovDeg?: number;
|
|
86
|
+
}
|
|
87
|
+
/** What `setCamera` takes: follow an object (keep the distance), focus it (frame it), look out from a body, or put the camera back on a pose from `camera`. */
|
|
53
88
|
export type CameraTarget = {
|
|
54
89
|
readonly follow: string;
|
|
55
90
|
} | {
|
|
56
91
|
readonly focus: string;
|
|
57
|
-
} | CameraPose;
|
|
92
|
+
} | LookOutTarget | CameraPose;
|
|
58
93
|
/** Where the playback rate comes from. `scene` is the rate the scene opened at; `chosen` is one a visitor or the host picked, which stays until it is released. */
|
|
59
94
|
export type RateSource = "scene" | "chosen";
|
|
60
95
|
/** What the host-link parts share: the one attached control, read through here so no part keeps a copy of it. */
|
|
@@ -88,8 +123,10 @@ export declare class ViewerLink implements ViewerPort {
|
|
|
88
123
|
get eventZones(): readonly string[] | undefined;
|
|
89
124
|
get view(): string | undefined;
|
|
90
125
|
get selected(): string | undefined;
|
|
126
|
+
get panel(): string | undefined;
|
|
91
127
|
get camera(): CameraPose | undefined;
|
|
92
128
|
get pick(): string | undefined;
|
|
129
|
+
get skyFigures(): readonly SceneSkyFigureRead[] | undefined;
|
|
93
130
|
get look(): LookRead | undefined;
|
|
94
131
|
get scale(): string | undefined;
|
|
95
132
|
get switches(): Readonly<Record<string, boolean>> | undefined;
|
|
@@ -102,8 +139,14 @@ export declare class ViewerLink implements ViewerPort {
|
|
|
102
139
|
setScale(id: string): void;
|
|
103
140
|
setSwitch(id: string, on: boolean): void;
|
|
104
141
|
setSelected(id: string | undefined): void;
|
|
142
|
+
setPanel(id: string | undefined): void;
|
|
143
|
+
onPanel(listener: (change: PanelChange) => void): () => void;
|
|
105
144
|
onChange(listener: (change: ViewerChange) => void): () => void;
|
|
106
145
|
onEventZone(listener: (change: EventZoneChange) => void): () => void;
|
|
146
|
+
/** Traces a sky figure line by line (checked here, `unknown-sky-figure` or `bad-sky-trace`); the viewer starts it at its next frame, after any host call made before it. */
|
|
147
|
+
traceSkyFigure(id: string, options?: SkyTraceOptions): void;
|
|
148
|
+
/** Removes a figure's trace (checked here, `unknown-sky-figure` or `bad-sky-trace`); a figure with no trace is left alone. Takes its place in call order like `traceSkyFigure`. */
|
|
149
|
+
clearSkyTrace(id: string, options?: SkyClearOptions): void;
|
|
107
150
|
setPick(value: string): void;
|
|
108
151
|
onPick(listener: (change: PickChange) => void): () => void;
|
|
109
152
|
pickNow(): string | undefined;
|
|
@@ -116,4 +159,6 @@ export declare class ViewerLink implements ViewerPort {
|
|
|
116
159
|
publish(state: ViewerState, cause: ViewerChangeCause): void;
|
|
117
160
|
/** The selection changed. A drop by time or the view names whatever last moved them (`onChange` names the same), so the cause is never a second opinion. */
|
|
118
161
|
publishSelection(state: ViewerState, byMove: boolean): void;
|
|
162
|
+
/** The open story panel changed. A drop by a view switch names whatever last moved the view (`onChange` names the same). */
|
|
163
|
+
publishPanel(state: ViewerState, cause: ViewerChangeCause | "move"): void;
|
|
119
164
|
}
|
package/src/api/viewerLink.js
CHANGED
|
@@ -3,10 +3,12 @@ import { ViewerLooks } from "./viewerLooks.js";
|
|
|
3
3
|
import { ViewerCamera } from "./viewerCamera.js";
|
|
4
4
|
import { ViewerClock } from "./viewerClock.js";
|
|
5
5
|
import { ViewerSelection } from "./viewerSelection.js";
|
|
6
|
+
import { ViewerPanels } from "./viewerPanels.js";
|
|
6
7
|
import { ViewerFirstDraw } from "./viewerFirstDraw.js";
|
|
7
8
|
import { ViewerPicker } from "./viewerPicker.js";
|
|
8
9
|
import { ViewerViews } from "./viewerViews.js";
|
|
9
10
|
import { ViewerZones } from "./viewerZones.js";
|
|
11
|
+
import { checkedClear, checkedTrace } from "./skyTraceInput.js";
|
|
10
12
|
const NOT_OPEN = "the viewer is not drawn yet (or is gone); wait for `ready` first";
|
|
11
13
|
function newWait() {
|
|
12
14
|
const wait = { done: false };
|
|
@@ -33,6 +35,7 @@ export class ViewerLink {
|
|
|
33
35
|
#camera = new ViewerCamera(this.#access);
|
|
34
36
|
#zones = new ViewerZones(this.#access);
|
|
35
37
|
#selection = new ViewerSelection(this.#access);
|
|
38
|
+
#panels = new ViewerPanels(this.#access);
|
|
36
39
|
#looks = new ViewerLooks(this.#access);
|
|
37
40
|
#frame = new ViewerFirstDraw();
|
|
38
41
|
#picker = new ViewerPicker(this.#access);
|
|
@@ -46,6 +49,7 @@ export class ViewerLink {
|
|
|
46
49
|
this.#control = control;
|
|
47
50
|
this.#clock.reset(control.read());
|
|
48
51
|
this.#selection.reset(control.read());
|
|
52
|
+
this.#panels.reset(control.read());
|
|
49
53
|
this.#mover = "playback";
|
|
50
54
|
this.#camera.reset();
|
|
51
55
|
this.#picker.reset(control);
|
|
@@ -57,6 +61,7 @@ export class ViewerLink {
|
|
|
57
61
|
this.#control = undefined;
|
|
58
62
|
this.#clock.reset(undefined);
|
|
59
63
|
this.#selection.reset(undefined);
|
|
64
|
+
this.#panels.reset(undefined);
|
|
60
65
|
this.#mover = "playback";
|
|
61
66
|
this.#camera.reset();
|
|
62
67
|
this.#picker.reset(undefined);
|
|
@@ -80,6 +85,7 @@ export class ViewerLink {
|
|
|
80
85
|
this.#clock.clearListeners();
|
|
81
86
|
this.#zones.clearListeners();
|
|
82
87
|
this.#selection.clearListeners();
|
|
88
|
+
this.#panels.clearListeners();
|
|
83
89
|
this.#camera.clearListeners();
|
|
84
90
|
this.#frame.clearListeners();
|
|
85
91
|
this.#picker.clearListeners();
|
|
@@ -96,8 +102,10 @@ export class ViewerLink {
|
|
|
96
102
|
get eventZones() { return this.#zones.eventZones; }
|
|
97
103
|
get view() { return this.#views.view; }
|
|
98
104
|
get selected() { return this.#selection.selected; }
|
|
105
|
+
get panel() { return this.#panels.panel; }
|
|
99
106
|
get camera() { return this.#camera.camera; }
|
|
100
107
|
get pick() { return this.#picker.pick; }
|
|
108
|
+
get skyFigures() { const control = this.#access.control(); return control === undefined ? undefined : control.skyFigures ?? []; }
|
|
101
109
|
get look() { return this.#looks.look; }
|
|
102
110
|
get scale() { return this.#looks.scale; }
|
|
103
111
|
get switches() { return this.#looks.switches; }
|
|
@@ -111,8 +119,22 @@ export class ViewerLink {
|
|
|
111
119
|
setScale(id) { this.#looks.setScale(id); this.#afterHost(); }
|
|
112
120
|
setSwitch(id, on) { this.#looks.setSwitch(id, on); this.#afterHost(); }
|
|
113
121
|
setSelected(id) { this.#selection.setSelected(id); this.#afterHost(); }
|
|
122
|
+
setPanel(id) { this.#panels.setPanel(id); this.#afterHost(); }
|
|
123
|
+
onPanel(listener) { return this.#panels.onPanel(listener); }
|
|
114
124
|
onChange(listener) { return this.#clock.onChange(listener); }
|
|
115
125
|
onEventZone(listener) { return this.#zones.onEventZone(listener); }
|
|
126
|
+
/** Traces a sky figure line by line (checked here, `unknown-sky-figure` or `bad-sky-trace`); the viewer starts it at its next frame, after any host call made before it. */
|
|
127
|
+
traceSkyFigure(id, options) {
|
|
128
|
+
const control = this.#access.open("traceSkyFigure");
|
|
129
|
+
const { seconds, after } = checkedTrace(id, options, (control.skyFigures ?? []).map((figure) => figure.id));
|
|
130
|
+
control.traceSkyFigure(id, seconds, after);
|
|
131
|
+
}
|
|
132
|
+
/** Removes a figure's trace (checked here, `unknown-sky-figure` or `bad-sky-trace`); a figure with no trace is left alone. Takes its place in call order like `traceSkyFigure`. */
|
|
133
|
+
clearSkyTrace(id, options) {
|
|
134
|
+
const control = this.#access.open("clearSkyTrace");
|
|
135
|
+
const { seconds } = checkedClear(id, options, (control.skyFigures ?? []).map((figure) => figure.id));
|
|
136
|
+
control.clearSkyTrace(id, seconds);
|
|
137
|
+
}
|
|
116
138
|
setPick(value) { this.#picker.setPick(value); }
|
|
117
139
|
onPick(listener) { return this.#picker.onPick(listener); }
|
|
118
140
|
pickNow() { return this.#picker.pick; }
|
|
@@ -130,10 +152,13 @@ export class ViewerLink {
|
|
|
130
152
|
const now = this.#publishes === serial ? state : this.#control?.read() ?? state;
|
|
131
153
|
this.#zones.publish(now, cause);
|
|
132
154
|
this.#selection.publish(now, cause);
|
|
155
|
+
this.#panels.publish(now, cause);
|
|
133
156
|
this.#camera.publish();
|
|
134
157
|
}
|
|
135
158
|
/** The selection changed. A drop by time or the view names whatever last moved them (`onChange` names the same), so the cause is never a second opinion. */
|
|
136
159
|
publishSelection(state, byMove) { this.#selection.publish(state, byMove ? this.#mover : "visitor"); }
|
|
160
|
+
/** The open story panel changed. A drop by a view switch names whatever last moved the view (`onChange` names the same). */
|
|
161
|
+
publishPanel(state, cause) { this.#panels.publish(state, cause === "move" ? this.#mover : cause); }
|
|
137
162
|
/** A host call moved the clock or the view: report the control's reading, change then zones. */
|
|
138
163
|
#afterHost() { this.publish(this.#access.open("publish").read(), "host"); }
|
|
139
164
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ViewerChangeCause, ViewerState } from "../app/viewerPort.js";
|
|
2
|
+
import type { LinkAccess } from "./viewerLink.js";
|
|
3
|
+
/** What a host is told when the open story panel changes. */
|
|
4
|
+
export interface PanelChange {
|
|
5
|
+
/** The panel now open; absent when it closed. */
|
|
6
|
+
readonly panel?: string;
|
|
7
|
+
/** The viewer's time, Unix milliseconds UTC. */
|
|
8
|
+
readonly timeUtcMs: number;
|
|
9
|
+
/** `visitor`, `host` (`setPanel`, or a drop by the host's `setView`) or `playback` (a moment panel opened by itself). */
|
|
10
|
+
readonly cause: ViewerChangeCause;
|
|
11
|
+
}
|
|
12
|
+
/** The host link's story panel: the open panel read, `setPanel` checked and the `onPanel` callbacks. */
|
|
13
|
+
export declare class ViewerPanels {
|
|
14
|
+
#private;
|
|
15
|
+
private readonly access;
|
|
16
|
+
constructor(access: LinkAccess);
|
|
17
|
+
/** The viewer attached (its first reading: the opening panel is read, not reported) or detached (undefined). */
|
|
18
|
+
reset(first: ViewerState | undefined): void;
|
|
19
|
+
clearListeners(): void;
|
|
20
|
+
/** The id of the open story panel; undefined before the viewer is drawn, after it is gone and when none is open. */
|
|
21
|
+
get panel(): string | undefined;
|
|
22
|
+
/** Opens a story panel the showing view shows, or closes the open one with `undefined`; the caller then publishes it as a host change. Any other id throws `bad-panels`; before the viewer is drawn or after it is gone, `not-mounted`. */
|
|
23
|
+
setPanel(id: unknown): void;
|
|
24
|
+
onPanel(listener: (change: PanelChange) => void): () => void;
|
|
25
|
+
publish(state: ViewerState, cause: ViewerChangeCause): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { SceneError } from "./errors.js";
|
|
2
|
+
import { callListeners } from "./listeners.js";
|
|
3
|
+
/** The host link's story panel: the open panel read, `setPanel` checked and the `onPanel` callbacks. */
|
|
4
|
+
export class ViewerPanels {
|
|
5
|
+
access;
|
|
6
|
+
#listeners = new Set();
|
|
7
|
+
/** The panel last read or reported; meaningful only while `#known` (the viewer is attached). */
|
|
8
|
+
#last;
|
|
9
|
+
#known = false;
|
|
10
|
+
constructor(access) {
|
|
11
|
+
this.access = access;
|
|
12
|
+
}
|
|
13
|
+
/** The viewer attached (its first reading: the opening panel is read, not reported) or detached (undefined). */
|
|
14
|
+
reset(first) {
|
|
15
|
+
this.#known = first !== undefined;
|
|
16
|
+
this.#last = first?.panel;
|
|
17
|
+
}
|
|
18
|
+
clearListeners() { this.#listeners.clear(); }
|
|
19
|
+
/** The id of the open story panel; undefined before the viewer is drawn, after it is gone and when none is open. */
|
|
20
|
+
get panel() { return this.access.control()?.read().panel; }
|
|
21
|
+
/** Opens a story panel the showing view shows, or closes the open one with `undefined`; the caller then publishes it as a host change. Any other id throws `bad-panels`; before the viewer is drawn or after it is gone, `not-mounted`. */
|
|
22
|
+
setPanel(id) {
|
|
23
|
+
const control = this.access.open("setPanel");
|
|
24
|
+
if (id !== undefined) {
|
|
25
|
+
const shown = control.panels();
|
|
26
|
+
if (typeof id !== "string" || !shown.includes(id)) {
|
|
27
|
+
throw new SceneError("bad-panels", `setPanel: ${typeof id === "string" ? `"${id}"` : String(id)} is not a story panel the showing view shows (${shown.join(", ")}); give one of them, or undefined to close the open one`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
control.setPanel(id);
|
|
31
|
+
}
|
|
32
|
+
onPanel(listener) {
|
|
33
|
+
this.#listeners.add(listener);
|
|
34
|
+
return () => { this.#listeners.delete(listener); };
|
|
35
|
+
}
|
|
36
|
+
publish(state, cause) {
|
|
37
|
+
if (!this.#known || state.panel === this.#last)
|
|
38
|
+
return;
|
|
39
|
+
this.#last = state.panel;
|
|
40
|
+
callListeners(this.#listeners, { ...(state.panel === undefined ? {} : { panel: state.panel }), timeUtcMs: state.timeUtcMs, cause });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -20,7 +20,7 @@ export declare class ViewerSelection {
|
|
|
20
20
|
/** The id of the selected object; undefined before the viewer is drawn, after it is gone and when nothing is selected. */
|
|
21
21
|
get selected(): string | undefined;
|
|
22
22
|
/**
|
|
23
|
-
* Selects an object the showing view shows, or clears the selection with `undefined`; the caller then publishes it as a host change (`onSelect` with `cause: "host"`; nothing is reported when the selection is already that).
|
|
23
|
+
* Selects an object the showing view shows, or a sky figure (`handle.skyFigures`), or clears the selection with `undefined`; the caller then publishes it as a host change (`onSelect` with `cause: "host"`; nothing is reported when the selection is already that).
|
|
24
24
|
* Any other id (unknown, hidden by the showing view, empty) or a non-string throws `bad-selection`; before the viewer is drawn or after it is gone, `not-mounted`.
|
|
25
25
|
*/
|
|
26
26
|
setSelected(id: unknown): void;
|
|
@@ -19,15 +19,15 @@ export class ViewerSelection {
|
|
|
19
19
|
/** The id of the selected object; undefined before the viewer is drawn, after it is gone and when nothing is selected. */
|
|
20
20
|
get selected() { return this.access.control()?.read().selected; }
|
|
21
21
|
/**
|
|
22
|
-
* Selects an object the showing view shows, or clears the selection with `undefined`; the caller then publishes it as a host change (`onSelect` with `cause: "host"`; nothing is reported when the selection is already that).
|
|
22
|
+
* Selects an object the showing view shows, or a sky figure (`handle.skyFigures`), or clears the selection with `undefined`; the caller then publishes it as a host change (`onSelect` with `cause: "host"`; nothing is reported when the selection is already that).
|
|
23
23
|
* Any other id (unknown, hidden by the showing view, empty) or a non-string throws `bad-selection`; before the viewer is drawn or after it is gone, `not-mounted`.
|
|
24
24
|
*/
|
|
25
25
|
setSelected(id) {
|
|
26
26
|
const control = this.access.open("setSelected");
|
|
27
27
|
if (id !== undefined) {
|
|
28
|
-
const shown = control.cameraTargets();
|
|
28
|
+
const shown = [...control.cameraTargets(), ...(control.skyFigures ?? []).map((figure) => figure.id)];
|
|
29
29
|
if (typeof id !== "string" || !shown.includes(id)) {
|
|
30
|
-
throw new SceneError("bad-selection", `setSelected: ${typeof id === "string" ? `"${id}"` : String(id)} is not an object the showing view shows (${shown.join(", ")}); give one of them, or undefined to clear`);
|
|
30
|
+
throw new SceneError("bad-selection", `setSelected: ${typeof id === "string" ? `"${id}"` : String(id)} is not an object the showing view shows, or a sky figure (${shown.join(", ")}); give one of them, or undefined to clear`);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
control.setSelected(id);
|