astraeus 0.7.0 → 0.8.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 +176 -0
- package/README.md +185 -37
- package/package.json +5 -4
- package/src/api/AstraeusScene.d.ts +21 -5
- package/src/api/AstraeusScene.js +34 -10
- package/src/api/AstraeusScene.node.js +34 -10
- package/src/api/assembleScene.d.ts +36 -0
- package/src/api/assembleScene.js +175 -0
- package/src/api/bodySetChecks.d.ts +10 -0
- package/src/api/bodySetChecks.js +117 -0
- package/src/api/bodySetInput.d.ts +81 -0
- package/src/api/bodySetInput.js +1 -0
- package/src/api/containingBlock.d.ts +6 -0
- package/src/api/containingBlock.js +16 -0
- package/src/api/data.d.ts +17 -5
- package/src/api/data.js +28 -10
- package/src/api/definitionOf.d.ts +16 -0
- package/src/api/definitionOf.js +20 -0
- package/src/api/errors.d.ts +61 -1
- package/src/api/frozenCopy.d.ts +6 -0
- package/src/api/frozenCopy.js +26 -0
- package/src/api/group.d.ts +8 -2
- package/src/api/group.js +24 -5
- package/src/api/index.d.ts +18 -7
- package/src/api/index.js +2 -2
- package/src/api/index.node.js +2 -2
- package/src/api/listeners.d.ts +5 -0
- package/src/api/listeners.js +25 -0
- package/src/api/look.d.ts +47 -0
- package/src/api/look.js +1 -0
- package/src/api/lookInput.d.ts +3 -0
- package/src/api/lookInput.js +41 -0
- package/src/api/moonPanelInput.d.ts +60 -0
- package/src/api/moonPanelInput.js +1 -0
- package/src/api/mount.d.ts +9 -19
- package/src/api/mount.js +27 -13
- package/src/api/mount.node.js +27 -13
- package/src/api/pathProvenance.js +1 -1
- package/src/api/pickerInput.d.ts +25 -0
- package/src/api/pickerInput.js +1 -0
- package/src/api/planBodies.d.ts +72 -0
- package/src/api/planBodies.js +300 -0
- package/src/api/planBodySets.d.ts +68 -0
- package/src/api/planBodySets.js +234 -0
- package/src/api/planCamera.d.ts +83 -0
- package/src/api/planCamera.js +184 -0
- package/src/api/planGroups.d.ts +36 -0
- package/src/api/planGroups.js +103 -0
- package/src/api/planMoonPanel.d.ts +19 -0
- package/src/api/planMoonPanel.js +104 -0
- package/src/api/planPaths.d.ts +40 -0
- package/src/api/planPaths.js +212 -0
- package/src/api/planPicker.d.ts +12 -0
- package/src/api/planPicker.js +40 -0
- package/src/api/planPlaces.d.ts +16 -0
- package/src/api/planPlaces.js +99 -0
- package/src/api/planStory.d.ts +26 -0
- package/src/api/planStory.js +66 -0
- package/src/api/planTimeline.d.ts +27 -0
- package/src/api/planTimeline.js +68 -0
- package/src/api/planViews.d.ts +25 -0
- package/src/api/planViews.js +35 -0
- package/src/api/prepared.js +4 -1
- package/src/api/renamedInputs.d.ts +15 -0
- package/src/api/renamedInputs.js +39 -0
- package/src/api/scene.d.ts +162 -68
- package/src/api/scene.js +247 -793
- package/src/api/sceneFreeze.d.ts +4 -0
- package/src/api/sceneFreeze.js +10 -0
- package/src/api/sceneReads.d.ts +171 -0
- package/src/api/sceneReads.js +6 -0
- package/src/api/story.d.ts +49 -19
- package/src/api/story.js +54 -22
- package/src/api/sunOrbit.js +9 -11
- package/src/api/time.d.ts +2 -1
- package/src/api/time.js +2 -1
- package/src/api/viewerCamera.d.ts +22 -0
- package/src/api/viewerCamera.js +84 -0
- package/src/api/viewerClock.d.ts +30 -0
- package/src/api/viewerClock.js +85 -0
- package/src/api/viewerFirstDraw.d.ts +14 -0
- package/src/api/viewerFirstDraw.js +26 -0
- package/src/api/viewerHandle.d.ts +79 -0
- package/src/api/viewerHandle.js +31 -0
- package/src/api/viewerLink.d.ts +87 -15
- package/src/api/viewerLink.js +111 -75
- package/src/api/viewerLooks.d.ts +19 -0
- package/src/api/viewerLooks.js +37 -0
- package/src/api/viewerPicker.d.ts +22 -0
- package/src/api/viewerPicker.js +49 -0
- package/src/api/viewerSelection.d.ts +25 -0
- package/src/api/viewerSelection.js +31 -0
- package/src/api/viewerViews.d.ts +10 -0
- package/src/api/viewerViews.js +18 -0
- package/src/api/viewerZones.d.ts +20 -0
- package/src/api/viewerZones.js +47 -0
- package/src/api/views.d.ts +4 -5
- package/src/api/views.js +7 -5
- package/src/app/App.d.ts +5 -3
- package/src/app/App.js +191 -82
- package/src/app/App.node.js +191 -82
- package/src/app/AstraeusScene.d.ts +16 -2
- package/src/app/AstraeusScene.js +4 -4
- package/src/app/BodyView.d.ts +4 -1
- package/src/app/BodyView.js +2 -2
- package/src/app/CameraController.d.ts +6 -0
- package/src/app/DeveloperSettings.d.ts +1 -4
- package/src/app/DeveloperSettings.js +6 -10
- package/src/app/FeatureMarkers.d.ts +4 -3
- package/src/app/FeatureMarkers.js +8 -13
- package/src/app/FrameRateSection.js +2 -1
- package/src/app/OrbitSetView.js +1 -1
- package/src/app/SettingControls.d.ts +11 -3
- package/src/app/SettingControls.js +10 -2
- package/src/app/SkyView.d.ts +3 -10
- package/src/app/SkyView.js +6 -28
- package/src/app/address.d.ts +16 -0
- package/src/app/address.js +31 -0
- package/src/app/bodyDraw.d.ts +10 -7
- package/src/app/bodyDraw.js +12 -32
- package/src/app/bodyMetrics.js +2 -2
- package/src/app/bodySet.d.ts +4 -20
- package/src/app/bodySet.js +5 -16
- package/src/app/debugReadout.js +1 -1
- package/src/app/displaySwitches.d.ts +4 -0
- package/src/app/displaySwitches.js +6 -0
- package/src/app/experienceDefinition.d.ts +11 -23
- package/src/app/listSwitch.d.ts +8 -14
- package/src/app/listSwitch.js +3 -10
- package/src/app/liveLook.d.ts +39 -0
- package/src/app/liveLook.js +66 -0
- package/src/app/look.d.ts +36 -0
- package/src/app/look.js +61 -0
- package/src/app/mission.d.ts +1 -1
- package/src/app/mission.js +1 -1
- package/src/app/openClock.d.ts +3 -2
- package/src/app/openClock.js +3 -3
- package/src/app/sceneCamera.js +9 -0
- package/src/app/sceneFrame.d.ts +4 -4
- package/src/app/sceneFrame.js +13 -8
- package/src/app/sceneHooks.js +3 -2
- package/src/app/style.css +114 -139
- package/src/app/trackedMetrics.d.ts +10 -3
- package/src/app/trackedMetrics.js +22 -11
- package/src/app/viewLink.d.ts +10 -32
- package/src/app/viewLink.js +10 -49
- package/src/app/viewerPort.d.ts +50 -0
- package/src/app/views.d.ts +1 -0
- package/src/assets/bodies/galileanMoons.js +1 -2
- package/src/assets/bodies/io.js +2 -2
- package/src/assets/bodies/listedMoons.d.ts +1 -1
- package/src/assets/bodies/listedMoons.js +2 -3
- package/src/assets/bodies/planetSystemMaps.js +2 -3
- package/src/assets/bodies/venus.js +2 -6
- package/src/assets/catalogue.js +1 -2
- package/src/assets/licence.d.ts +3 -3
- package/src/assets/licence.js +3 -3
- package/src/assets/pictures.d.ts +15 -12
- package/src/assets/pictures.js +24 -20
- package/src/assets/sky.d.ts +6 -5
- package/src/assets/sky.js +6 -9
- package/src/assets/visual.d.ts +4 -0
- package/src/core/bodies/index.d.ts +0 -4
- package/src/core/bodies/index.js +1 -6
- package/src/core/bodies/jupiterData.d.ts +0 -1
- package/src/core/bodies/jupiterData.js +2 -5
- package/src/core/bodies/moonSystem.d.ts +1 -1
- package/src/core/bodies/moonSystem.js +102 -55
- package/src/core/bodies/outerPlanetRingData.js +2 -2
- package/src/core/bodies/planetTrajectory.js +1 -1
- package/src/core/bodySetFamilies.d.ts +20 -0
- package/src/core/bodySetFamilies.js +14 -0
- package/src/core/chebyshevEphemeris.js +1 -1
- package/src/core/elementsBody.d.ts +8 -4
- package/src/core/elementsBody.js +32 -11
- package/src/core/elementsGroup.d.ts +27 -0
- package/src/core/elementsGroup.js +85 -0
- package/src/core/events.d.ts +2 -0
- package/src/core/events.js +2 -0
- package/src/core/illumination.js +1 -1
- package/src/core/listedOrbitGroup.d.ts +2 -0
- package/src/core/listedOrbitGroup.js +11 -7
- package/src/core/moonListText.d.ts +6 -0
- package/src/core/moonListText.js +19 -0
- package/src/core/moonTrajectory.js +1 -1
- package/src/core/pacing.d.ts +38 -3
- package/src/core/pacing.js +55 -4
- package/src/core/planetModels.js +2 -2
- package/src/core/planetSeries.d.ts +8 -0
- package/src/core/planetSeries.js +16 -2
- package/src/core/pointGroup.js +1 -1
- package/src/core/provenance.d.ts +2 -1
- package/src/core/provenance.js +2 -2
- package/src/core/referenceCenters.js +5 -5
- package/src/core/sampledTrajectory.js +1 -1
- package/src/core/scalePolicy.d.ts +1 -0
- package/src/core/startView.d.ts +19 -0
- package/src/core/startView.js +28 -0
- package/src/core/state.d.ts +6 -2
- package/src/core/state.js +3 -3
- package/src/core/storyPanels.d.ts +63 -0
- package/src/core/storyPanels.js +111 -0
- package/src/core/sunCentredSources.d.ts +4 -0
- package/src/core/sunCentredSources.js +9 -2
- package/src/core/timeInput.d.ts +4 -0
- package/src/core/timeInput.js +4 -0
- package/src/shell/AstraeusShell.d.ts +5 -1
- package/src/shell/AstraeusShell.js +20 -11
- package/src/shell/AstraeusShell.node.js +20 -11
- package/src/shell/Collapsible.d.ts +4 -3
- package/src/shell/Collapsible.js +5 -5
- package/src/shell/ControlsDrawer.d.ts +1 -1
- package/src/shell/ControlsDrawer.js +3 -1
- package/src/shell/DisplaySwitches.js +2 -1
- package/src/shell/InfoPanel.d.ts +3 -1
- package/src/shell/InfoPanel.js +5 -4
- package/src/shell/MoonFamilyPanel.js +1 -1
- package/src/shell/ObjectControls.d.ts +3 -1
- package/src/shell/ObjectControls.js +2 -2
- package/src/shell/Sources.d.ts +5 -3
- package/src/shell/Sources.js +5 -5
- package/src/shell/StoryPanelView.d.ts +4 -3
- package/src/shell/StoryPanelView.js +8 -6
- package/src/shell/SwitchControl.d.ts +5 -11
- package/src/shell/SwitchControl.js +2 -20
- package/src/shell/TimelineBar.css +81 -81
- package/src/shell/TimelineBar.d.ts +5 -2
- package/src/shell/TimelineBar.js +9 -8
- package/src/shell/TimelineBar.node.js +9 -8
- package/src/shell/TopBar.css +22 -22
- package/src/shell/TopBar.d.ts +5 -1
- package/src/shell/TopBar.js +2 -2
- package/src/shell/TopBar.node.js +2 -2
- package/src/shell/bootLoader.d.ts +4 -10
- package/src/shell/bootLoader.js +6 -52
- package/src/shell/embedded.css +18 -18
- package/src/shell/experience.d.ts +1 -1
- package/src/shell/moonFamilies.d.ts +2 -6
- package/src/shell/moonFamilies.js +2 -18
- package/src/shell/phone.css +58 -58
- package/src/shell/storyPanels.d.ts +2 -53
- package/src/shell/storyPanels.js +1 -106
- package/src/shell/style.css +153 -134
- package/src/shell/useDrawers.d.ts +3 -2
- package/src/shell/useDrawers.js +4 -3
- package/src/shell/viewerKeys.d.ts +8 -0
- package/src/shell/viewerKeys.js +16 -0
- package/src/synthetic/syntheticDefinition.js +20 -24
- package/src/synthetic/syntheticJourneyScene.js +3 -3
- package/src/synthetic/syntheticProbeDefinition.js +2 -1
- package/src/synthetic/syntheticViewsDefinition.d.ts +0 -3
- package/src/synthetic/syntheticViewsDefinition.js +10 -16
- package/data/moons/jupiter.json +0 -3333
- package/data/moons/neptune.json +0 -555
- package/data/moons/pluto.json +0 -205
- package/data/moons/saturn.json +0 -8267
- package/data/moons/uranus.json +0 -887
- package/src/app/addressNavigation.d.ts +0 -17
- package/src/app/addressNavigation.js +0 -16
- package/src/assets/bodies/jupiterMoonCatalogue.d.ts +0 -3
- package/src/assets/bodies/jupiterMoonCatalogue.js +0 -4
- package/src/assets/bodies/outerPlanetCatalogues.d.ts +0 -7
- package/src/assets/bodies/outerPlanetCatalogues.js +0 -8
- package/src/assets/bodies/swiftTuttle.d.ts +0 -12
- package/src/assets/bodies/swiftTuttle.js +0 -13
- package/src/assets/moonCatalogue.d.ts +0 -49
- package/src/assets/moonCatalogue.js +0 -80
- package/src/core/bodies/outerPlanetData.d.ts +0 -4
- package/src/core/bodies/outerPlanetData.js +0 -13
- package/src/core/bodies/swiftTuttle.d.ts +0 -46
- package/src/core/bodies/swiftTuttle.js +0 -106
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createProvenance } from "../core/provenance.js";
|
|
2
|
+
import { SceneError } from "./errors.js";
|
|
3
|
+
import { frozenCopy } from "./frozenCopy.js";
|
|
4
|
+
import { idOf } from "./bodySetChecks.js";
|
|
5
|
+
import { frozenList } from "./sceneReads.js";
|
|
6
|
+
const HEX = /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/;
|
|
7
|
+
const bad = (body, message) => new SceneError("bad-places", `addPlaces("${String(body)}"): ${message}`);
|
|
8
|
+
const isText = (value) => typeof value === "string" && value !== "";
|
|
9
|
+
const isNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
10
|
+
/** Checks the categories; returns nothing, throws `bad-places`. */
|
|
11
|
+
function checkCategories(body, categories) {
|
|
12
|
+
if (!Array.isArray(categories))
|
|
13
|
+
throw bad(body, "categories must be a list");
|
|
14
|
+
const keys = new Set();
|
|
15
|
+
for (const category of categories) {
|
|
16
|
+
if (!isText(category?.key))
|
|
17
|
+
throw bad(body, "every category needs a non-empty key");
|
|
18
|
+
if (keys.has(category.key))
|
|
19
|
+
throw bad(body, `category "${category.key}" appears twice`);
|
|
20
|
+
keys.add(category.key);
|
|
21
|
+
if (!isText(category.label))
|
|
22
|
+
throw bad(body, `category "${category.key}" needs a label`);
|
|
23
|
+
if (typeof category.color !== "string" || !HEX.test(category.color))
|
|
24
|
+
throw bad(body, `category "${category.key}": color "${String(category.color)}" is not a hex colour such as "#9de3a8"`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Checks one place: its words, its position and its details. */
|
|
28
|
+
function checkPlace(body, place) {
|
|
29
|
+
for (const field of ["name", "kind", "category", "description"])
|
|
30
|
+
if (!isText(place[field]))
|
|
31
|
+
throw bad(body, `place "${place.id}": ${field} must be a non-empty text`);
|
|
32
|
+
if (!isNumber(place.latitudeDeg) || place.latitudeDeg < -90 || place.latitudeDeg > 90)
|
|
33
|
+
throw bad(body, `place "${place.id}": latitudeDeg must be a number from -90 to 90`);
|
|
34
|
+
if (!isNumber(place.longitudeDeg))
|
|
35
|
+
throw bad(body, `place "${place.id}": longitudeDeg must be a finite number`);
|
|
36
|
+
const details = place.details;
|
|
37
|
+
if (details !== undefined && !(Array.isArray(details) && details.every((fact) => isText(fact?.label) && isText(fact.value))))
|
|
38
|
+
throw bad(body, `place "${place.id}": details must be a list of { label, value } with both texts non-empty`);
|
|
39
|
+
}
|
|
40
|
+
/** Checks the categories, places, provenance and limits of one body's places. */
|
|
41
|
+
function checkInput(body, input) {
|
|
42
|
+
if (typeof input !== "object" || input === null)
|
|
43
|
+
throw bad(body, "give a { categories, places, provenance } object");
|
|
44
|
+
checkCategories(body, input.categories);
|
|
45
|
+
if (!Array.isArray(input.places) || input.places.length === 0)
|
|
46
|
+
throw bad(body, "give at least one place");
|
|
47
|
+
const ids = new Set();
|
|
48
|
+
for (const place of input.places) {
|
|
49
|
+
if (!isText(place?.id))
|
|
50
|
+
throw bad(body, "every place needs a non-empty id");
|
|
51
|
+
if (ids.has(place.id))
|
|
52
|
+
throw bad(body, `place "${place.id}" appears twice`);
|
|
53
|
+
ids.add(place.id);
|
|
54
|
+
checkPlace(body, place);
|
|
55
|
+
}
|
|
56
|
+
if (typeof input.provenance !== "object" || input.provenance === null)
|
|
57
|
+
throw bad(body, "the places need a provenance");
|
|
58
|
+
try {
|
|
59
|
+
createProvenance(input.provenance);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
throw bad(body, `provenance: ${error instanceof Error ? error.message : String(error)}`);
|
|
63
|
+
}
|
|
64
|
+
if (input.knownLimitations !== undefined && !(Array.isArray(input.knownLimitations) && input.knownLimitations.every(isText)))
|
|
65
|
+
throw bad(body, "knownLimitations must be a list of non-empty texts");
|
|
66
|
+
}
|
|
67
|
+
/** What a `Scene` has planned for its tagged surface places, by body. */
|
|
68
|
+
export class PlacesPlan {
|
|
69
|
+
sets = new Map();
|
|
70
|
+
add(body, input) {
|
|
71
|
+
const id = idOf(body);
|
|
72
|
+
if (!isText(id))
|
|
73
|
+
throw bad(id, "name the body: a body or its id");
|
|
74
|
+
if (this.sets.has(id))
|
|
75
|
+
throw new SceneError("duplicate-id", `addPlaces("${id}"): that body already has places; give them all in one call`);
|
|
76
|
+
checkInput(id, input);
|
|
77
|
+
this.sets.set(id, frozenCopy(input));
|
|
78
|
+
}
|
|
79
|
+
/** The places in the order added. */
|
|
80
|
+
reads() {
|
|
81
|
+
return frozenList([...this.sets].map(([body, input]) => ({ body, count: input.places.length })));
|
|
82
|
+
}
|
|
83
|
+
/** The shell's sets, once the finished scene says which bodies it holds (`labels` maps them to their labels). */
|
|
84
|
+
featureSets(labels) {
|
|
85
|
+
return [...this.sets].map(([body, input]) => {
|
|
86
|
+
const label = labels.get(body);
|
|
87
|
+
if (label === undefined)
|
|
88
|
+
throw bad(body, "the body has not been added to the scene");
|
|
89
|
+
return {
|
|
90
|
+
bodyId: body,
|
|
91
|
+
bodyLabel: label,
|
|
92
|
+
categories: input.categories.map(({ key, label: categoryLabel, color }) => ({ key, label: categoryLabel, color })),
|
|
93
|
+
features: input.places.map((place) => ({ id: place.id, name: place.name, featureType: place.kind, category: place.category, latitude: place.latitudeDeg, longitude: place.longitudeDeg, description: place.description, details: (place.details ?? []).map(({ label: factLabel, value }) => ({ label: factLabel, value })) })),
|
|
94
|
+
provenance: createProvenance(input.provenance),
|
|
95
|
+
...(input.knownLimitations === undefined ? {} : { knownLimitations: [...input.knownLimitations] }),
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TimelineEvent } from "../core/events.js";
|
|
2
|
+
import type { TimeBounds } from "../core/trajectory.js";
|
|
3
|
+
import { type StoryPanelSet } from "../core/storyPanels.js";
|
|
4
|
+
import type { ExperienceConfig } from "../shell/experience.js";
|
|
5
|
+
import { type AddEventsOptions, type EventInput, type StoryPanelInput, type StoryPanelPlaybackInput } from "./story.js";
|
|
6
|
+
import type { Tracked } from "./planPaths.js";
|
|
7
|
+
import { type SceneEventRead, type ScenePanelRead } from "./sceneReads.js";
|
|
8
|
+
/** What a `Scene` has planned for its story layer: events, where their times come from, and story panels. */
|
|
9
|
+
export declare class StoryPlan {
|
|
10
|
+
#private;
|
|
11
|
+
events: readonly TimelineEvent[];
|
|
12
|
+
addEvents(events: readonly EventInput[], options: AddEventsOptions): void;
|
|
13
|
+
/** Appends a batch; one that fails its checks adds nothing. */
|
|
14
|
+
addPanels(panels: readonly StoryPanelInput[]): void;
|
|
15
|
+
setPanelPlayback(playback: StoryPanelPlaybackInput): void;
|
|
16
|
+
/** The events name only objects the scene holds. */
|
|
17
|
+
checkObjects(ids: ReadonlySet<string>): void;
|
|
18
|
+
/** The story panels, resolved against this scene's events, the anchors of its paths, its objects and timeline span. */
|
|
19
|
+
panels(window: TimeBounds, tracked: Iterable<Tracked>, objectIds: readonly string[]): StoryPanelSet | undefined;
|
|
20
|
+
/** The events sorted by time, each with its own provenance, else the batch's. */
|
|
21
|
+
eventReads(): readonly SceneEventRead[];
|
|
22
|
+
/** The story panels as the public list states them (resolved as `panels` resolves them); empty when none were added. */
|
|
23
|
+
panelReads(window: TimeBounds, tracked: Iterable<Tracked>, objectIds: readonly string[]): readonly ScenePanelRead[];
|
|
24
|
+
/** The event provenance entries of the experience: the batch's, and each event's own. */
|
|
25
|
+
provenanceEntries(): Pick<ExperienceConfig, "eventProvenance" | "eventProvenanceById">;
|
|
26
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { DEFAULT_PANEL_PLAYBACK } from "../core/storyPanels.js";
|
|
2
|
+
import { checkEventObjects, eventProvenanceOf, eventsOf, panelBatchOf, panelPlaybackOf, panelsOf } from "./story.js";
|
|
3
|
+
import { frozenList } from "./sceneReads.js";
|
|
4
|
+
/** What a `Scene` has planned for its story layer: events, where their times come from, and story panels. */
|
|
5
|
+
export class StoryPlan {
|
|
6
|
+
events = [];
|
|
7
|
+
#eventProvenance;
|
|
8
|
+
#eventOwnProvenance = new Map();
|
|
9
|
+
#panels;
|
|
10
|
+
#playback = DEFAULT_PANEL_PLAYBACK;
|
|
11
|
+
addEvents(events, options) {
|
|
12
|
+
const merged = eventsOf(events, this.events);
|
|
13
|
+
const own = events.flatMap((event) => event.provenance === undefined ? [] : [[event.id, eventProvenanceOf(event.provenance, event.id)]]);
|
|
14
|
+
const batch = options.provenance === undefined ? undefined : eventProvenanceOf(options.provenance);
|
|
15
|
+
this.events = merged;
|
|
16
|
+
for (const [id, provenance] of own)
|
|
17
|
+
this.#eventOwnProvenance.set(id, provenance);
|
|
18
|
+
if (batch !== undefined)
|
|
19
|
+
this.#eventProvenance = batch;
|
|
20
|
+
}
|
|
21
|
+
/** Appends a batch; one that fails its checks adds nothing. */
|
|
22
|
+
addPanels(panels) {
|
|
23
|
+
const known = this.#panels ?? [];
|
|
24
|
+
this.#panels = [...known, ...panelBatchOf(panels, known)];
|
|
25
|
+
}
|
|
26
|
+
setPanelPlayback(playback) {
|
|
27
|
+
this.#playback = panelPlaybackOf(playback);
|
|
28
|
+
}
|
|
29
|
+
/** The events name only objects the scene holds. */
|
|
30
|
+
checkObjects(ids) {
|
|
31
|
+
checkEventObjects(this.events, ids);
|
|
32
|
+
}
|
|
33
|
+
/** The story panels, resolved against this scene's events, the anchors of its paths, its objects and timeline span. */
|
|
34
|
+
panels(window, tracked, objectIds) {
|
|
35
|
+
if (this.#panels === undefined)
|
|
36
|
+
return undefined;
|
|
37
|
+
const anchors = new Map();
|
|
38
|
+
for (const { body } of tracked)
|
|
39
|
+
body.anchorLabels?.forEach((label, index) => { if (!anchors.has(label))
|
|
40
|
+
anchors.set(label, body.anchorTimesUtcMs[index]); });
|
|
41
|
+
return panelsOf(this.#panels, this.#playback, { events: this.events, anchors, objectIds, window });
|
|
42
|
+
}
|
|
43
|
+
/** The events sorted by time, each with its own provenance, else the batch's. */
|
|
44
|
+
eventReads() {
|
|
45
|
+
return frozenList(this.events.map(({ id, label, timeUtcMs, type, object, withinMs }) => {
|
|
46
|
+
const provenance = this.#eventOwnProvenance.get(id) ?? this.#eventProvenance;
|
|
47
|
+
return { id, label, timeUtcMs, ...(type === undefined ? {} : { type }), ...(object === undefined ? {} : { object }), ...(withinMs === undefined ? {} : { withinSeconds: withinMs / 1000 }), ...(provenance === undefined ? {} : { provenance }) };
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
/** The story panels as the public list states them (resolved as `panels` resolves them); empty when none were added. */
|
|
51
|
+
panelReads(window, tracked, objectIds) {
|
|
52
|
+
const set = this.panels(window, tracked, objectIds);
|
|
53
|
+
return frozenList((set?.panels ?? []).map(({ id, timeUtcMs, title, body, details, provenance, objectId }) => ({
|
|
54
|
+
id, timeUtcMs, title, provenance,
|
|
55
|
+
body: Object.freeze([...body]), details: Object.freeze([...details]),
|
|
56
|
+
...(objectId === undefined ? {} : { object: objectId }),
|
|
57
|
+
})));
|
|
58
|
+
}
|
|
59
|
+
/** The event provenance entries of the experience: the batch's, and each event's own. */
|
|
60
|
+
provenanceEntries() {
|
|
61
|
+
return {
|
|
62
|
+
...(this.#eventProvenance === undefined ? {} : { eventProvenance: this.#eventProvenance }),
|
|
63
|
+
...(this.#eventOwnProvenance.size === 0 ? {} : { eventProvenanceById: Object.fromEntries(this.#eventOwnProvenance) }),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TimelineEvent } from "../core/events.js";
|
|
2
|
+
import type { TimeBounds } from "../core/trajectory.js";
|
|
3
|
+
import type { ExperienceDefinition } from "../app/experienceDefinition.js";
|
|
4
|
+
import { type TimeInput } from "./time.js";
|
|
5
|
+
import type { SceneTimelineRead } from "./sceneReads.js";
|
|
6
|
+
import { type TimelineInput, type TimelineSetting } from "./story.js";
|
|
7
|
+
/** What a `Scene` has planned for its timeline: the opening time, the timeline setting, and from them the span, clock, rates and pacing. */
|
|
8
|
+
export declare class TimelinePlan {
|
|
9
|
+
#private;
|
|
10
|
+
/** The timeline the caller set, if any. */
|
|
11
|
+
setting: TimelineSetting | undefined;
|
|
12
|
+
setTime(time: TimeInput): void;
|
|
13
|
+
setTimeline(timeline: TimelineInput): void;
|
|
14
|
+
/** The speeds offered: the caller's, else 1 minute, 1 hour and 1 day per second. */
|
|
15
|
+
rates(): readonly number[];
|
|
16
|
+
/** The timeline span and the moment the clock opens at; a moment outside a span the caller set is a `bad-timeline`. */
|
|
17
|
+
span(tracked: readonly TimeBounds[]): {
|
|
18
|
+
readonly window: TimeBounds;
|
|
19
|
+
readonly startUtcMs: number;
|
|
20
|
+
};
|
|
21
|
+
/** The timeline as the public read states it, over the spans of the paths and activities. */
|
|
22
|
+
read(spans: readonly TimeBounds[]): SceneTimelineRead;
|
|
23
|
+
/** The clock's opening: 60 times real time unless set; with no timeline and no rate, frozen. */
|
|
24
|
+
clock(startUtcMs: number): ExperienceDefinition["clock"];
|
|
25
|
+
/** The pacing the timeline asked for, laid over the scene's events; a rule naming an event type with no events throws `bad-timeline`. */
|
|
26
|
+
pacing(events: readonly TimelineEvent[]): Pick<ExperienceDefinition, "pacing" | "eventZones">;
|
|
27
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { SceneError } from "./errors.js";
|
|
2
|
+
import { toUtcMs } from "./time.js";
|
|
3
|
+
import { eventZonesOf } from "../core/pacing.js";
|
|
4
|
+
import { pacingFor, timelineOf } from "./story.js";
|
|
5
|
+
const DAY_MS = 86_400_000;
|
|
6
|
+
/** What a `Scene` has planned for its timeline: the opening time, the timeline setting, and from them the span, clock, rates and pacing. */
|
|
7
|
+
export class TimelinePlan {
|
|
8
|
+
#timeUtcMs;
|
|
9
|
+
/** The timeline the caller set, if any. */
|
|
10
|
+
setting;
|
|
11
|
+
setTime(time) {
|
|
12
|
+
this.#timeUtcMs = toUtcMs(time, "setTime");
|
|
13
|
+
}
|
|
14
|
+
setTimeline(timeline) {
|
|
15
|
+
this.setting = timelineOf(timeline);
|
|
16
|
+
}
|
|
17
|
+
/** The speeds offered: the caller's, else 1 minute, 1 hour and 1 day per second. */
|
|
18
|
+
rates() {
|
|
19
|
+
return this.setting?.rates ?? [60, 3_600, DAY_MS / 1000];
|
|
20
|
+
}
|
|
21
|
+
/** The timeline span and the moment the clock opens at; a moment outside a span the caller set is a `bad-timeline`. */
|
|
22
|
+
span(tracked) {
|
|
23
|
+
const timeline = this.setting;
|
|
24
|
+
const setTime = (timeline?.none === true ? timeline.atUtcMs : undefined) ?? this.#timeUtcMs;
|
|
25
|
+
// With nothing setting a span or a moment, the month window is centred on now and the clock opens at now (not at the window's start).
|
|
26
|
+
const now = setTime === undefined && timeline?.window === undefined && tracked.length === 0 ? Date.now() : undefined;
|
|
27
|
+
const window = timeline?.window ?? windowOf(tracked, setTime ?? now);
|
|
28
|
+
if (timeline?.window !== undefined && setTime !== undefined && (setTime < window.startUtcMs || setTime > window.endUtcMs)) {
|
|
29
|
+
throw new SceneError("bad-timeline", `setTime ${new Date(setTime).toISOString()} is outside the timeline (${new Date(window.startUtcMs).toISOString()} to ${new Date(window.endUtcMs).toISOString()})`);
|
|
30
|
+
}
|
|
31
|
+
return { window, startUtcMs: setTime ?? now ?? window.startUtcMs };
|
|
32
|
+
}
|
|
33
|
+
/** The timeline as the public read states it, over the spans of the paths and activities. */
|
|
34
|
+
read(spans) {
|
|
35
|
+
const { window, startUtcMs } = this.span(spans);
|
|
36
|
+
return Object.freeze({
|
|
37
|
+
windowStartUtcMs: window.startUtcMs,
|
|
38
|
+
windowEndUtcMs: window.endUtcMs,
|
|
39
|
+
openUtcMs: startUtcMs,
|
|
40
|
+
rates: Object.freeze([...this.rates()]),
|
|
41
|
+
rate: this.clock(startUtcMs).rate,
|
|
42
|
+
loop: this.setting?.none !== true && this.setting?.loop === true,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** The clock's opening: 60 times real time unless set; with no timeline and no rate, frozen. */
|
|
46
|
+
clock(startUtcMs) {
|
|
47
|
+
const timeline = this.setting;
|
|
48
|
+
return { startUtcMs, rate: timeline?.rate ?? 60, ...(timeline?.none === true && timeline.rate === undefined ? { playing: false } : {}) };
|
|
49
|
+
}
|
|
50
|
+
/** The pacing the timeline asked for, laid over the scene's events; a rule naming an event type with no events throws `bad-timeline`. */
|
|
51
|
+
pacing(events) {
|
|
52
|
+
const timeline = this.setting;
|
|
53
|
+
const pacing = timeline === undefined ? undefined : pacingFor(timeline, events, timeline.rate ?? 60);
|
|
54
|
+
const eventZones = eventZonesOf(events, pacing?.zones ?? []);
|
|
55
|
+
return { ...(pacing === undefined ? {} : { pacing }), ...(eventZones.length === 0 ? {} : { eventZones }) };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** The timeline span: the union of the trajectories' and activities' spans, else a month about the chosen time (or about now). */
|
|
59
|
+
function windowOf(tracked, timeUtcMs) {
|
|
60
|
+
if (tracked.length > 0) {
|
|
61
|
+
const start = Math.min(...tracked.map((bounds) => bounds.startUtcMs));
|
|
62
|
+
const end = Math.max(...tracked.map((bounds) => bounds.endUtcMs));
|
|
63
|
+
if (timeUtcMs === undefined || (timeUtcMs >= start && timeUtcMs <= end))
|
|
64
|
+
return { startUtcMs: start, endUtcMs: end };
|
|
65
|
+
}
|
|
66
|
+
const centre = timeUtcMs ?? Date.now();
|
|
67
|
+
return { startUtcMs: centre - 15 * DAY_MS, endUtcMs: centre + 15 * DAY_MS };
|
|
68
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DisplaySwitchSettings } from "../app/displaySwitches.js";
|
|
2
|
+
import type { ViewSettings } from "../app/views.js";
|
|
3
|
+
import type { StoryPanelSet } from "../core/storyPanels.js";
|
|
4
|
+
import { type SwitchesInput } from "./switches.js";
|
|
5
|
+
import type { SceneViewsRead } from "./sceneReads.js";
|
|
6
|
+
import { type ViewInput, type ViewScope, type ViewsOptions } from "./views.js";
|
|
7
|
+
/** What a `Scene` has planned for its presentation: the display switches and the named views. */
|
|
8
|
+
export declare class ViewPlan {
|
|
9
|
+
#private;
|
|
10
|
+
setSwitches(switches: SwitchesInput): void;
|
|
11
|
+
setViews(views: readonly ViewInput[], options: ViewsOptions): void;
|
|
12
|
+
/** The views as the public read states them, each with the objects, events and panels it shows (the lists the viewer uses, resolved against the finished scene); absent when none were named. `scope` is asked for only when views were named. */
|
|
13
|
+
read(scope: () => ViewScope): SceneViewsRead | undefined;
|
|
14
|
+
/** The `displaySwitches` entry of the definition (absent when none were placed). */
|
|
15
|
+
switchesEntry(): {
|
|
16
|
+
displaySwitches?: DisplaySwitchSettings;
|
|
17
|
+
};
|
|
18
|
+
/** The `views` entry of the definition: the views resolved against the finished scene once (absent when none was named). */
|
|
19
|
+
viewsEntry(scene: {
|
|
20
|
+
readonly objects: readonly string[];
|
|
21
|
+
readonly events: readonly string[];
|
|
22
|
+
}, storyPanels: StoryPanelSet | undefined): {
|
|
23
|
+
views?: ViewSettings;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { switchesOf } from "./switches.js";
|
|
2
|
+
import { resolveViews, viewsOf } from "./views.js";
|
|
3
|
+
import { frozenList } from "./sceneReads.js";
|
|
4
|
+
/** What a `Scene` has planned for its presentation: the display switches and the named views. */
|
|
5
|
+
export class ViewPlan {
|
|
6
|
+
#switches;
|
|
7
|
+
#views;
|
|
8
|
+
setSwitches(switches) {
|
|
9
|
+
this.#switches = switchesOf(switches, this.#switches);
|
|
10
|
+
}
|
|
11
|
+
setViews(views, options) {
|
|
12
|
+
this.#views = viewsOf(views, options);
|
|
13
|
+
}
|
|
14
|
+
/** The views as the public read states them, each with the objects, events and panels it shows (the lists the viewer uses, resolved against the finished scene); absent when none were named. `scope` is asked for only when views were named. */
|
|
15
|
+
read(scope) {
|
|
16
|
+
const plan = this.#views;
|
|
17
|
+
if (plan === undefined)
|
|
18
|
+
return undefined;
|
|
19
|
+
const { place, start, views } = resolveViews(plan, scope());
|
|
20
|
+
return Object.freeze({
|
|
21
|
+
startId: start, place,
|
|
22
|
+
items: frozenList(views.map(({ id, label, objects, events, panels }) => ({ id, label, objects: Object.freeze([...objects]), events: Object.freeze([...events]), panels: Object.freeze([...panels]) }))),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** The `displaySwitches` entry of the definition (absent when none were placed). */
|
|
26
|
+
switchesEntry() {
|
|
27
|
+
return this.#switches === undefined ? {} : { displaySwitches: this.#switches };
|
|
28
|
+
}
|
|
29
|
+
/** The `views` entry of the definition: the views resolved against the finished scene once (absent when none was named). */
|
|
30
|
+
viewsEntry(scene, storyPanels) {
|
|
31
|
+
if (this.#views === undefined)
|
|
32
|
+
return {};
|
|
33
|
+
return { views: resolveViews(this.#views, { objects: scene.objects, events: scene.events, panels: storyPanels?.panels.map(({ id }) => id) ?? [] }) };
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/api/prepared.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { definitionOf } from "./definitionOf.js";
|
|
2
|
+
import { markMounted } from "./sceneFreeze.js";
|
|
1
3
|
/** Builds the definition (throws a `SceneError` for a missing data package or an empty scene) and starts loading its data. */
|
|
2
4
|
export function prepareScene(scene, data = []) {
|
|
3
|
-
const definition = scene
|
|
5
|
+
const definition = definitionOf(scene, data);
|
|
6
|
+
markMounted(scene);
|
|
4
7
|
return { definition, ready: definition.prepare?.() ?? Promise.resolve() };
|
|
5
8
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** One input field that was renamed: where a caller gives it (`scope`, the receiving call reads that shape), the old name, the new name and the call named in the message. */
|
|
2
|
+
export interface RenamedInput {
|
|
3
|
+
readonly scope: string;
|
|
4
|
+
readonly call: string;
|
|
5
|
+
readonly old: string;
|
|
6
|
+
readonly use: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Every input field renamed in 0.8.0, old to new, in one place (O-057 T-276). A plain JavaScript caller who passes an old name would otherwise see it ignored without a word,
|
|
10
|
+
* so each receiving call hands the object it was given to `rejectRenamed` with its `scope`; the old name is refused, never accepted. Inputs only: a removed method fails by itself
|
|
11
|
+
* and a renamed read is covered by the migration table. Every row's `scope` must be read by some call (`tests/renamedInputs.test.ts` proves it).
|
|
12
|
+
*/
|
|
13
|
+
export declare const RENAMED_INPUTS: readonly RenamedInput[];
|
|
14
|
+
/** Throws `renamed` when `value` carries an old name of the `scope`, naming its replacement; a value that is not an object is left to the caller's own checks. `where` leads the message, such as `setTimeline: pacing[1]`. */
|
|
15
|
+
export declare function rejectRenamed(scope: string, value: unknown, where: string): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SceneError } from "./errors.js";
|
|
2
|
+
/** The replacement of the old `addStoryPanels({ panels, pauseSeconds, autoOpen })` object: a list, and a call of its own for the two settings. */
|
|
3
|
+
const PANELS_CALLS = "addStoryPanels(list) with setStoryPanelPlayback({ pauseSeconds, autoOpen })";
|
|
4
|
+
/**
|
|
5
|
+
* Every input field renamed in 0.8.0, old to new, in one place (O-057 T-276). A plain JavaScript caller who passes an old name would otherwise see it ignored without a word,
|
|
6
|
+
* so each receiving call hands the object it was given to `rejectRenamed` with its `scope`; the old name is refused, never accepted. Inputs only: a removed method fails by itself
|
|
7
|
+
* and a renamed read is covered by the migration table. Every row's `scope` must be read by some call (`tests/renamedInputs.test.ts` proves it).
|
|
8
|
+
*/
|
|
9
|
+
export const RENAMED_INPUTS = Object.freeze([
|
|
10
|
+
{ scope: "MoonPositions", call: "mount", old: "centre", use: "center" },
|
|
11
|
+
{ scope: "TextureRefDesktop", call: "mount", old: "minViewportWidth", use: "minViewportWidthPx" },
|
|
12
|
+
{ scope: "PacingSpan", call: "setTimeline", old: "from", use: "start" },
|
|
13
|
+
{ scope: "PacingSpan", call: "setTimeline", old: "to", use: "end" },
|
|
14
|
+
{ scope: "PacingSpan", call: "setTimeline", old: "ramp", use: "rampSeconds" },
|
|
15
|
+
{ scope: "PacingRule", call: "setTimeline", old: "ramp", use: "rampSeconds" },
|
|
16
|
+
{ scope: "PacingNear", call: "setTimeline", old: "within", use: "withinSeconds" },
|
|
17
|
+
{ scope: "ViewInput", call: "setViews", old: "paths", use: "objects" },
|
|
18
|
+
{ scope: "ViewInput", call: "setViews", old: "bodies", use: "objects" },
|
|
19
|
+
{ scope: "AddBodyOptions", call: "addBody", old: "labelReach", use: "labelReachEarthRadii" },
|
|
20
|
+
{ scope: "TrajectoryInput", call: "addTrajectory", old: "labelReach", use: "labelReachEarthRadii" },
|
|
21
|
+
{ scope: "ElementsBodyRecord", call: "addBodyFromElements", old: "frame", use: "plane" },
|
|
22
|
+
{ scope: "ElementsAccuracy", call: "addBodyFromElements", old: "validFromUtc", use: "valid.start" },
|
|
23
|
+
{ scope: "ElementsAccuracy", call: "addBodyFromElements", old: "validToUtc", use: "valid.end" },
|
|
24
|
+
{ scope: "StoryPanelInput", call: "addStoryPanels", old: "badge", use: "provenance.sourceType" },
|
|
25
|
+
{ scope: "StoryPanelInput", call: "addStoryPanels", old: "sources", use: "provenance.sources" },
|
|
26
|
+
{ scope: "StoryPanelAt", call: "addStoryPanels", old: "utc", use: "time" },
|
|
27
|
+
{ scope: "AddStoryPanelsCall", call: "addStoryPanels", old: "panels", use: PANELS_CALLS },
|
|
28
|
+
{ scope: "AddStoryPanelsCall", call: "addStoryPanels", old: "pauseSeconds", use: PANELS_CALLS },
|
|
29
|
+
{ scope: "AddStoryPanelsCall", call: "addStoryPanels", old: "autoOpen", use: PANELS_CALLS },
|
|
30
|
+
].map((row) => Object.freeze(row)));
|
|
31
|
+
/** Throws `renamed` when `value` carries an old name of the `scope`, naming its replacement; a value that is not an object is left to the caller's own checks. `where` leads the message, such as `setTimeline: pacing[1]`. */
|
|
32
|
+
export function rejectRenamed(scope, value, where) {
|
|
33
|
+
if (typeof value !== "object" || value === null)
|
|
34
|
+
return;
|
|
35
|
+
for (const row of RENAMED_INPUTS) {
|
|
36
|
+
if (row.scope === scope && Object.hasOwn(value, row.old))
|
|
37
|
+
throw new SceneError("renamed", `${where}: \`${row.old}\` is now \`${row.use}\` (the old name is not accepted)`);
|
|
38
|
+
}
|
|
39
|
+
}
|