@vehicle-sil/gui-client 0.0.0-stage → 0.2.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.ja.md +839 -0
  3. package/README.md +836 -2
  4. package/dist/elements.js +872 -0
  5. package/dist/index.js +5354 -0
  6. package/package.json +39 -4
  7. package/timeline/vehicle-sil-timeline.d.ts +108 -0
  8. package/timeline/vehicle-sil-timeline.js +4391 -0
  9. package/timeline/vehicle-sil-timeline.mjs +4393 -0
  10. package/types/client.d.ts +148 -0
  11. package/types/connection.d.ts +155 -0
  12. package/types/elements/index.d.ts +25 -0
  13. package/types/elements/outside-parts.d.ts +20 -0
  14. package/types/elements/page-intent.d.ts +10 -0
  15. package/types/elements/part.d.ts +48 -0
  16. package/types/elements/reasons.d.ts +12 -0
  17. package/types/elements/run-parts.d.ts +21 -0
  18. package/types/elements/scenario-parts.d.ts +18 -0
  19. package/types/elements/variable-parts.d.ts +28 -0
  20. package/types/front-actions.d.ts +122 -0
  21. package/types/front-compose.d.ts +61 -0
  22. package/types/front-outside.d.ts +19 -0
  23. package/types/front-types.d.ts +353 -0
  24. package/types/front-variable.d.ts +28 -0
  25. package/types/front.d.ts +50 -0
  26. package/types/http.d.ts +71 -0
  27. package/types/index.d.ts +28 -0
  28. package/types/protocol/launcher.d.ts +578 -0
  29. package/types/protocol/read.d.ts +72 -0
  30. package/types/protocol/server.d.ts +758 -0
  31. package/types/protocol.d.ts +15 -0
  32. package/types/run.d.ts +74 -0
  33. package/types/session-state.d.ts +289 -0
  34. package/types/session.d.ts +130 -0
  35. package/types/time.d.ts +133 -0
  36. package/types/token.d.ts +35 -0
  37. package/types/urls.d.ts +8 -0
  38. package/types/values.d.ts +54 -0
  39. package/types/variable-binding.d.ts +181 -0
  40. package/types/variable-state.d.ts +134 -0
  41. package/types/variables.d.ts +382 -0
@@ -0,0 +1,148 @@
1
+ import { ClientConnection, SocketFactory } from './connection.js';
2
+ import { HttpTransport } from './http.js';
3
+ import { AppInfo, CheckRequest, CheckTextRequest, ConfigText, DescribeRequest, CheckResult, ConfigList, Connections, ConnectionsRequest, DashboardResponse, Recording, SaveConfigRequest, SavedConfig, ScenarioList, SessionSummary } from './protocol.js';
4
+ import { ClientRun } from './run.js';
5
+ import { ClientSession } from './session.js';
6
+ import { ClientTime } from './time.js';
7
+ import { ClientVariables } from './variables.js';
8
+ import { ErrorSink, Readable } from './values.js';
9
+ /**
10
+ * Limits used while they are unknown (before the api/app answer). The same as the launcher's and server's defaults.
11
+ * During a run, the ranges of step and speed are the launcher's (`allowed.step`, `allowed.speed` of its state;
12
+ * `controls` of connect() carries them); the ones here are for choosing the speed of a run that has not started.
13
+ */
14
+ export declare const DEFAULT_LIMITS: AppInfo['limits'];
15
+ /** Options of createClient. */
16
+ export interface ClientOptions {
17
+ /**
18
+ * URL of the GUI server (`http://127.0.0.1:<port>/`: the URL the server printed, without `#token=...`).
19
+ * HTTP paths and the WebSocket (`ws`) are relative to it. In the browser, use the server's root
20
+ * (`new URL('/', location.href).href`). `document.baseURI` is the screen's route on a page without
21
+ * `<base href="/">`.
22
+ */
23
+ baseUrl: string;
24
+ /**
25
+ * The token (what follows `#token=` in the URL the server printed). A function is called each time the token is
26
+ * used. While it is null, the client does not connect. Switching to another token after a refusal does not
27
+ * reconnect (create a new client instead).
28
+ */
29
+ token: string | (() => string | null);
30
+ /**
31
+ * Origin to send with POST and the WebSocket handshake. Not needed in browsers, which add it themselves. In Node,
32
+ * the origin of baseUrl is sent if omitted (the server accepts only its own origin). Do not pass it in a Web Worker
33
+ * (a Worker's WebSocket cannot add handshake headers; the browser adds Origin).
34
+ */
35
+ origin?: string;
36
+ /** HTTP transport (default fetchTransport). */
37
+ http?: HttpTransport;
38
+ /** Function that opens the WebSocket (default webSocketFactory). */
39
+ socket?: SocketFactory;
40
+ /** How long to wait for the answer to a time command (ms; default ANSWER_TIMEOUT_MS). */
41
+ answerTimeoutMs?: number;
42
+ /**
43
+ * Receives what subscribers (functions passed to subscribe, onBatch, onMessages, onUnreadable) threw. The client
44
+ * carries on (other subscribers still get notified, and handling such as disconnecting after a refusal still
45
+ * completes). The default prints to console.error.
46
+ */
47
+ onError?: (error: unknown) => void;
48
+ }
49
+ /**
50
+ * Client for the GUI server. Holds the connection (WebSocket), the session copy, run and time control, and the server
51
+ * information. All state comes as readable values (Readable: get and subscribe). No framework needed; runs in browsers
52
+ * and in Node.
53
+ *
54
+ * Lifetime: connect() connects (calling it again while connected does nothing). close() disconnects, stops pending
55
+ * timers, stops waiting for answers to time commands and fails writes still waiting for their result (variable
56
+ * watches stay and resume on reconnect). connect() after close() connects again (the session copy is kept and
57
+ * resumes from what it already has). HTTP requests (loadApp() and so on) work without a connection. After the server
58
+ * refused the token (session.rejected) or the versions differ (session.incompatible), connect() does nothing (create a
59
+ * new client).
60
+ */
61
+ export interface GuiClient {
62
+ /** The WebSocket connection (state, number of failed handshakes, close reason, notifications received). */
63
+ readonly connection: ClientConnection;
64
+ /** The session copy (current session, whether it is complete, notices). */
65
+ readonly session: ClientSession;
66
+ /** Run control (start, stop). */
67
+ readonly run: ClientRun;
68
+ /** Time state and commands. */
69
+ readonly time: ClientTime;
70
+ /** ECU variables: list and state, value watches, writes and their results. */
71
+ readonly variables: ClientVariables;
72
+ /** Server and launcher information (`GET api/app`, after loadApp()). null until then. */
73
+ readonly app: Readable<AppInfo | null>;
74
+ /** Speed range and the limits of stepping and checks (the limits of app; DEFAULT_LIMITS until then). */
75
+ readonly limits: Readable<AppInfo['limits']>;
76
+ /** Connects through WebSocket (does nothing without a token, after a refusal, or after a version mismatch). */
77
+ connect(): void;
78
+ /** Disconnects and stops pending timers. */
79
+ close(): void;
80
+ /** Reads `GET api/app` into app. */
81
+ loadApp(): Promise<AppInfo>;
82
+ /** `GET api/configs`: the configuration files to choose from. */
83
+ configs(): Promise<ConfigList>;
84
+ /**
85
+ * `POST api/check`: checks a configuration file (a failed check still gets a successful answer; its result is then
86
+ * not passed). Waits twice the server's check limit (limits.check_timeout_s; waiting its turn, then checking) plus
87
+ * the default HTTP timeout. A check of a `text` may first describe the saved file in the same turn (the server does
88
+ * it when it has no saved descriptions); the second limit covers that.
89
+ */
90
+ check(request: CheckRequest | CheckTextRequest): Promise<CheckResult>;
91
+ /**
92
+ * `GET api/config`: the text of a configuration file as it is saved, with the SHA-256 of its bytes (`stamp`).
93
+ * Rejects with an HttpError (`not-a-configuration`, `config-too-large`, `config-unreadable`, ...).
94
+ */
95
+ config(file: string): Promise<ConfigText>;
96
+ /**
97
+ * `POST api/describe`: checks the saved file and saves its participants' descriptions again (after an executable
98
+ * was built again), and returns that check. Waits in the queue of the checks, as long as `check`.
99
+ */
100
+ describe(request: DescribeRequest): Promise<CheckResult>;
101
+ /**
102
+ * `POST api/config`: saves a text as a configuration file, with the `stamp` it was read with (null: a new file).
103
+ * Rejects with an HttpError (`save-disabled`, `commands-changed` (also a new file to a server started without
104
+ * `--allow-command-changes`), `config-changed`, `config-busy`,
105
+ * `config-unreadable`, `text-too-large`, ...). Waits in the queue of the checks, as long as `check`.
106
+ */
107
+ saveConfig(request: SaveConfigRequest): Promise<SavedConfig>;
108
+ /**
109
+ * `POST api/connections`: where one network of a configuration file can be connected on the computer of the GUI
110
+ * server. It starts that network's bridge to list (on Windows, Npcap may ask to raise the rights), so ask only when
111
+ * the user opens the choice. Waits in the queue of the checks, as long as `check`.
112
+ */
113
+ connections(request: ConnectionsRequest): Promise<Connections>;
114
+ /** `GET api/session`: summary of the current session (null if none). Also applied to the session copy. */
115
+ fetchSession(): Promise<SessionSummary | null>;
116
+ /**
117
+ * `GET api/dashboard`: reads the dashboard file next to the configuration file (relative to root) in the form the
118
+ * server checked (found is false if there is none; problems are in errors).
119
+ */
120
+ dashboard(file: string): Promise<DashboardResponse>;
121
+ /** `GET api/scenarios`: the scenario files in `scenarios` next to the configuration file (relative to root). */
122
+ scenarios(file: string): Promise<ScenarioList>;
123
+ /**
124
+ * `GET api/recording`: the values written through this server and applied in the current (or last) run, as scenario
125
+ * YAML (null if there has been no run yet). Not written to a file.
126
+ */
127
+ recording(): Promise<Recording | null>;
128
+ }
129
+ /**
130
+ * How long to wait for the answer to a start (`api/run`) and a check (`api/check`) (ms). The server runs one check at
131
+ * a time and spends up to check_timeout_s waiting and up to check_timeout_s checking (a start checks a changed
132
+ * configuration file again). Twice that, plus the launcher's start-up and an HTTP margin (DEFAULT_TIMEOUT_MS).
133
+ */
134
+ export declare function longRequestMs(limits: AppInfo['limits']): number;
135
+ /** Whether this runs on Node (only Node's WebSocket can add handshake headers). */
136
+ export declare function isNode(runtime?: object): boolean;
137
+ /** Default Origin outside the browser: the server's own origin on Node, none elsewhere. */
138
+ export declare function defaultOrigin(baseUrl: string, runtime?: object): string | undefined;
139
+ /** Creates a client for the GUI server. Creating it does not connect (call connect()). */
140
+ export declare function createClient(options: ClientOptions): GuiClient;
141
+ /** What the front (front.ts) needs besides the client: the transport and the error sink. */
142
+ export interface ClientParts {
143
+ client: GuiClient;
144
+ http: HttpTransport;
145
+ onError: ErrorSink;
146
+ }
147
+ /** createClient, and the parts the front door is built from. */
148
+ export declare function buildClient(options: ClientOptions): ClientParts;
@@ -0,0 +1,155 @@
1
+ import { ErrorSink, Readable } from './values.js';
2
+ /** closed: not connected (also while waiting to reconnect), connecting: connecting, open: connected. */
3
+ export type ConnectionState = 'connecting' | 'open' | 'closed';
4
+ /** Close code and reason text of a closed connection. */
5
+ export interface CloseInfo {
6
+ code: number;
7
+ reason: string;
8
+ }
9
+ /** Close code the server uses for "try again later". The client reconnects (the token was not refused). */
10
+ export declare const TRY_AGAIN_LATER = 1013;
11
+ /**
12
+ * Interval at which received notifications are passed on in batches (ms). However fast the log flows, subscribers are
13
+ * notified at most this many times a second. A refusal (unauthorized) is also noticed when a batch is passed on. This
14
+ * is shorter than the reconnect delay after the server closes (500 ms at first), so the client never reconnects with a
15
+ * refused token (if it were longer, the client would reconnect once and then stop).
16
+ */
17
+ export declare const BATCH_MS = 100;
18
+ /** Receives WebSocket events. Passed to SocketFactory. */
19
+ export interface SocketHandlers {
20
+ open(): void;
21
+ /** A text message received. */
22
+ message(text: string): void;
23
+ /** Closed (including closed before opening, and could not connect). Called once. */
24
+ close(code: number, reason: string): void;
25
+ }
26
+ /** The part of an open WebSocket that the library uses. */
27
+ export interface SocketLike {
28
+ send(text: string): void;
29
+ close(): void;
30
+ }
31
+ /** Opens a WebSocket. Default webSocketFactory(). Tests replace it with a fake (FakeWebSockets of testing). */
32
+ export type SocketFactory = (url: string, handlers: SocketHandlers) => SocketLike;
33
+ /** How long the connection must stay up before the count of restarts caused by non-JSON notifications is reset (ms). */
34
+ export declare const STEADY_MS = 30000;
35
+ /**
36
+ * SocketFactory that opens the standard WebSocket (browsers, Web Workers, globalThis.WebSocket of Node 22 or later).
37
+ * With origin, the handshake carries Origin (for Node; uses the `{headers}` extension of Node's WebSocket; browser and
38
+ * Worker WebSockets read a second argument as subprotocols, so it is not passed there). If the socket cannot be opened
39
+ * (a wrong URL and so on), this counts as closed, with the cause in the close reason text (`lastClose.reason`).
40
+ */
41
+ export declare function webSocketFactory(options?: {
42
+ origin?: string;
43
+ }): SocketFactory;
44
+ /** Reconnect delay: 0.5 s, doubled each attempt, capped at the limit. attempt starts at 1. */
45
+ export declare function backoffMs(attempt: number, maxMs?: number): number;
46
+ /** Options of Connection. */
47
+ export interface ConnectionOptions {
48
+ /** WebSocket URL (`ws://127.0.0.1:<port>/ws`). */
49
+ url: string;
50
+ /** Opens the WebSocket. */
51
+ socket: SocketFactory;
52
+ /** Message sent right after each open, reconnects included (sent as JSON). Called when connecting. */
53
+ greeting: () => readonly unknown[];
54
+ /**
55
+ * Messages sent right after greeting (those that follow authentication, such as variable subscriptions). Called on
56
+ * open (includes those added between connecting and opening).
57
+ */
58
+ afterGreeting?: () => readonly unknown[];
59
+ /** Upper limit of the reconnect delay. */
60
+ maxBackoffMs?: number;
61
+ /** Interval for batching received notifications. */
62
+ batchMs?: number;
63
+ /** Receives what subscribers threw. */
64
+ onError?: ErrorSink;
65
+ }
66
+ /**
67
+ * Read side of the connection (GuiClient.connection). Connect and disconnect with GuiClient's connect() and close().
68
+ */
69
+ export interface ClientConnection {
70
+ /** Connection state. */
71
+ readonly state: Readable<ConnectionState>;
72
+ /**
73
+ * Number of times the socket closed before opening (refused at the handshake, or never reached the server). The
74
+ * browser does not show why, so when this grows, ask over HTTP (`GET api/app`).
75
+ */
76
+ readonly failures: Readable<number>;
77
+ /** Code and reason of the last close. Back to null when a notification arrives after the close (reconnected). */
78
+ readonly lastClose: Readable<CloseInfo | null>;
79
+ /**
80
+ * Reason text with which the server closed the connection as "try again later" (1013): `too-many-connections`,
81
+ * `too-many-unauthenticated`. The client reconnects after a delay; null once reconnected.
82
+ */
83
+ readonly tryAgainReason: Readable<string | null>;
84
+ /**
85
+ * Receives the notifications that arrived (parsed JSON, contents unchecked, unknown types included), one batch at a
86
+ * time. Call the returned function to unsubscribe.
87
+ */
88
+ onBatch(listener: (batch: readonly unknown[]) => void): () => void;
89
+ /** Receives messages (text) that cannot be parsed as JSON. The connection then reconnects after a delay. */
90
+ onUnreadable(listener: (text: string) => void): () => void;
91
+ }
92
+ /**
93
+ * One WebSocket connection to the GUI server. No framework needed.
94
+ *
95
+ * - connect() connects and close() disconnects (no reconnect). connect() after close() connects again. connect() while
96
+ * connected (also while waiting to reconnect) does nothing.
97
+ * - When the connection drops (an error or the server closing it), reconnects after backoffMs. Each consecutive drop
98
+ * lengthens the delay (so a server that keeps closing with 1013 "try again later" is not hammered with reconnects);
99
+ * a readable notification resets it.
100
+ * - Sends greeting right after each open (authentication, and where to resend from).
101
+ * - Batches the received notifications (parsed JSON, contents unchecked) every batchMs and passes them to the onBatch
102
+ * subscribers. Each feature's reader (the session copy and so on) reads the contents. When something arrives that
103
+ * cannot be parsed as JSON, notifies onUnreadable and reconnects after a delay (receiving again from hello; when in
104
+ * doubt, readers rebuild from the summary).
105
+ */
106
+ export declare class Connection implements ClientConnection {
107
+ private readonly options;
108
+ private readonly onError;
109
+ private readonly stateValue;
110
+ private readonly failureCount;
111
+ private readonly lastCloseValue;
112
+ private readonly batchListeners;
113
+ private readonly unreadableListeners;
114
+ private socket;
115
+ private wanted;
116
+ /** Consecutive drops without a readable notification. */
117
+ private attempts;
118
+ /** Consecutive restarts (restart). */
119
+ private restarts;
120
+ private restartAsked;
121
+ /** Consecutive restarts caused by non-JSON notifications. Reset to 0 after staying connected for STEADY_MS. */
122
+ private garbled;
123
+ private steadyTimer;
124
+ private retryTimer;
125
+ private batchTimer;
126
+ private pending;
127
+ readonly state: Readable<ConnectionState>;
128
+ readonly failures: Readable<number>;
129
+ readonly lastClose: Readable<CloseInfo | null>;
130
+ readonly tryAgainReason: Readable<string | null>;
131
+ constructor(options: ConnectionOptions);
132
+ /** Connects (does nothing if connected or waiting to reconnect). */
133
+ connect(): void;
134
+ /** Disconnects, without reconnecting. Drops notifications still being batched. */
135
+ close(): void;
136
+ /**
137
+ * Drops the current connection and reconnects after a delay (when a reader could not rebuild its state from the
138
+ * notifications). The delay grows with each consecutive restart.
139
+ */
140
+ restart(): void;
141
+ private restartAfter;
142
+ /**
143
+ * Sends a notification to the server (one that follows authentication, such as a variable subscription). Sends only
144
+ * while open and returns whether it sent. What could not be sent goes out with afterGreeting on the next open.
145
+ */
146
+ send(message: unknown): boolean;
147
+ onBatch(listener: (batch: readonly unknown[]) => void): () => void;
148
+ onUnreadable(listener: (text: string) => void): () => void;
149
+ /** Passes on the batched notifications without waiting. */
150
+ flush(): void;
151
+ private dropPending;
152
+ private open;
153
+ private openSocket;
154
+ private scheduleRetry;
155
+ }
@@ -0,0 +1,25 @@
1
+ import { pageIntent } from './page-intent.js';
2
+ import { setReasonText } from './reasons.js';
3
+ import type { ReasonText } from './reasons.js';
4
+ import { VsilConnectElement, VsilOutsideElement } from './outside-parts.js';
5
+ import { VsilRunControlsElement, VsilStatusElement, VsilTimeControlsElement } from './run-parts.js';
6
+ import { VsilScenarioResultElement, VsilScenarioSelectElement, VsilTimelineElement } from './scenario-parts.js';
7
+ import { VsilSliderElement, VsilValueElement, VsilWriteElement } from './variable-parts.js';
8
+ export { pageIntent, setReasonText };
9
+ export type { ReasonText };
10
+ export { VsilConnectElement, VsilOutsideElement, VsilRunControlsElement, VsilScenarioResultElement, VsilScenarioSelectElement, VsilSliderElement, VsilStatusElement, VsilTimeControlsElement, VsilTimelineElement, VsilValueElement, VsilWriteElement, };
11
+ declare global {
12
+ interface HTMLElementTagNameMap {
13
+ 'vsil-status': VsilStatusElement;
14
+ 'vsil-run-controls': VsilRunControlsElement;
15
+ 'vsil-time-controls': VsilTimeControlsElement;
16
+ 'vsil-value': VsilValueElement;
17
+ 'vsil-slider': VsilSliderElement;
18
+ 'vsil-write': VsilWriteElement;
19
+ 'vsil-scenario-select': VsilScenarioSelectElement;
20
+ 'vsil-scenario-result': VsilScenarioResultElement;
21
+ 'vsil-timeline': VsilTimelineElement;
22
+ 'vsil-connect': VsilConnectElement;
23
+ 'vsil-outside': VsilOutsideElement;
24
+ }
25
+ }
@@ -0,0 +1,20 @@
1
+ import type { Front } from '../index.js';
2
+ import { Part } from './part.js';
3
+ /**
4
+ * `<vsil-connect network="N">`: where network N of the next run is connected outside the simulation. The first choice
5
+ * is SIL Kit only (`none`). The list of the GUI server's computer is asked for only when the user opens the select (a
6
+ * press, or a key other than Tab, Escape and the modifiers). When the part leaves the page, or `network` or `file`
7
+ * changes, N leaves `pageIntent.connect`: no run is connected by a choice that is not on the page. `file` names the
8
+ * configuration file that the page starts (default: the start-up file, as `run.start`).
9
+ */
10
+ export declare class VsilConnectElement extends Part {
11
+ static observedAttributes: string[];
12
+ protected draw(client: Front, root: HTMLElement, alive: () => boolean): void;
13
+ }
14
+ /**
15
+ * `<vsil-outside>`: the networks that the run connected outside (`client.outside`), one row each. Nothing is shown when
16
+ * there are none (also in a run that a `role: bridge` participant of the file connects).
17
+ */
18
+ export declare class VsilOutsideElement extends Part {
19
+ protected draw(client: Front, root: HTMLElement): void;
20
+ }
@@ -0,0 +1,10 @@
1
+ import type { Intent } from '../index.js';
2
+ type Listener = (intent: Intent) => void;
3
+ /** The page's selection for the next run (`<vsil-scenario-select>` writes it, `<vsil-run-controls>` starts with it). */
4
+ export declare const pageIntent: {
5
+ get: () => Intent;
6
+ subscribe(listener: Listener): () => void;
7
+ /** Merges `patch`; a field that is undefined or an empty string is removed. */
8
+ update(patch: Intent | { [K in keyof Intent]?: Intent[K] | ""; }): void;
9
+ };
10
+ export {};
@@ -0,0 +1,48 @@
1
+ import type { Front, OperationName } from '../index.js';
2
+ /** Creates an element with text and attributes. */
3
+ export declare function h<K extends keyof HTMLElementTagNameMap>(tag: K, attributes?: Record<string, string>, ...children: (Node | string)[]): HTMLElementTagNameMap[K];
4
+ /** Sets or removes a data attribute. */
5
+ export declare function setData(element: HTMLElement, name: string, value: string | null): void;
6
+ /** Runs an operation and drops its failure: `status.problem` (or the variable's `problem`) shows it. */
7
+ export declare function quietly(operation: () => Promise<void>): Promise<void>;
8
+ /**
9
+ * The base of the parts. Subclasses draw into `root` in `draw()` and register what to stop with `own()`.
10
+ *
11
+ * - The part draws into one `<span class="vsil">` that it adds; children the page put in the element stay.
12
+ * - It binds when it enters the document, unbinds when it leaves, and binds again when one of
13
+ * `observedAttributes` changes or `client` is set.
14
+ */
15
+ export declare abstract class Part extends HTMLElement {
16
+ #private;
17
+ static observedAttributes: string[];
18
+ /** Another connection than the page's (`connect()`). Setting it while the part is in the document binds it again. */
19
+ get client(): Front | null;
20
+ set client(value: Front | null);
21
+ constructor();
22
+ /**
23
+ * A property that the page set before this class was defined sits on the object itself and hides the accessor:
24
+ * take it off and set it again.
25
+ */
26
+ protected upgrade(name: string): void;
27
+ /** Draws and subscribes. `alive()` turns false when the part has left the document or was bound again. */
28
+ protected abstract draw(client: Front, root: HTMLElement, alive: () => boolean): void | Promise<void>;
29
+ /** Stops `stop` when the part is unbound. */
30
+ protected own(stop: () => void): void;
31
+ /** The attribute `name`, or `fallback` when it is not there. */
32
+ protected text(name: string, fallback: string): string;
33
+ connectedCallback(): void;
34
+ disconnectedCallback(): void;
35
+ attributeChangedCallback(_name: string, before: string | null, after: string | null): void;
36
+ /**
37
+ * Binds `element` to one control of `client.controls`: `aria-disabled` (the caller ignores input while it is true),
38
+ * `data-reason` and `data-caution` (the codes), and a sentence in an element that describes it (`aria-describedby`;
39
+ * returned, to be put next to `element`). A reason that only says there is nothing to do (`not-running`, `offline`)
40
+ * is in that element too, but hidden: a screen reader reads it, the page does not show it seven times.
41
+ */
42
+ protected describe(client: Front, control: OperationName, element: HTMLElement): HTMLElement;
43
+ /**
44
+ * A button bound to one control of `client.controls`. When it cannot be used it stays focusable (`aria-disabled`),
45
+ * the reason is in an element that describes it (`aria-describedby`) and its code is in `data-reason`.
46
+ */
47
+ protected button(client: Front, label: string, control: OperationName, action: () => Promise<void>): HTMLElement[];
48
+ }
@@ -0,0 +1,12 @@
1
+ import type { Reason } from '../index.js';
2
+ /** Returns the sentence to show for `reason`; null or undefined keeps the English sentence of the owner of the reason. */
3
+ export type ReasonText = (reason: Reason) => string | null | undefined;
4
+ /**
5
+ * Replaces the sentences that the parts show for reasons (`controls.*.reason`, `caution`, `status.problem`, and a
6
+ * variable's `why` and `problem`), for example to translate them: `fn` gets the reason (its `code` stays the same) and
7
+ * returns the sentence, or null to keep the English one. `null` removes it. Call it before the parts are in the page:
8
+ * a part draws the sentence again when its value changes.
9
+ */
10
+ export declare function setReasonText(fn: ReasonText | null): void;
11
+ /** The sentence for `reason`. */
12
+ export declare function reasonText(reason: Reason): string;
@@ -0,0 +1,21 @@
1
+ import type { Front, Intent } from '../index.js';
2
+ import { Part } from './part.js';
3
+ /** `<vsil-status>`: the connection, the run, the virtual time (marked when it falls behind real time) and the one problem. */
4
+ export declare class VsilStatusElement extends Part {
5
+ protected draw(client: Front, root: HTMLElement): void;
6
+ }
7
+ /** `<vsil-run-controls>`: Start (with the page's selection and the `intent` property), Stop and, after a first stop, force stop. */
8
+ export declare class VsilRunControlsElement extends Part {
9
+ #private;
10
+ static observedAttributes: string[];
11
+ /** What to start with, over what the choosing parts of the page selected. */
12
+ get intent(): Intent | null;
13
+ set intent(value: Intent | null);
14
+ constructor();
15
+ protected draw(client: Front, root: HTMLElement): void;
16
+ }
17
+ /** `<vsil-time-controls speeds="0.5 1 5 max" step-ms="10">`: pause, resume, step, run until and speed. */
18
+ export declare class VsilTimeControlsElement extends Part {
19
+ static observedAttributes: string[];
20
+ protected draw(client: Front, root: HTMLElement): void;
21
+ }
@@ -0,0 +1,18 @@
1
+ import type { Front } from '../index.js';
2
+ import { Part } from './part.js';
3
+ /** `<vsil-scenario-select>`: chooses the scenario of the next run, among the scenarios next to the run's configuration file. */
4
+ export declare class VsilScenarioSelectElement extends Part {
5
+ protected draw(client: Front, root: HTMLElement, alive: () => boolean): void;
6
+ }
7
+ /** `<vsil-scenario-result>`: the result and the steps of the run's scenario. */
8
+ export declare class VsilScenarioResultElement extends Part {
9
+ protected draw(client: Front, root: HTMLElement): void;
10
+ }
11
+ /**
12
+ * `<vsil-timeline>`: ties the `<vehicle-sil-timeline>` inside it to the timeline of the run's scenario. The page's own
13
+ * `<vehicle-sil-timeline>` (with its attributes) is used; when there is none, the part adds a default one. The part
14
+ * changes only `src` and `hidden` of it, and does not load the element's script: the page does.
15
+ */
16
+ export declare class VsilTimelineElement extends Part {
17
+ protected draw(client: Front): void;
18
+ }
@@ -0,0 +1,28 @@
1
+ import type { Front, FrontVariable, VariableView } from '../index.js';
2
+ import { Part } from './part.js';
3
+ /** A part that shows or sets the variable of its `variable` attribute (`"ECU.variable"`). */
4
+ declare abstract class VariablePart extends Part {
5
+ static observedAttributes: string[];
6
+ /** Whether the part writes (so that it says why it cannot). */
7
+ protected readonly writes: boolean;
8
+ /** Builds the controls once; returns what to do with each new view. */
9
+ protected abstract build(variable: FrontVariable, root: HTMLElement, note: HTMLElement): (view: VariableView) => void;
10
+ protected draw(client: Front, root: HTMLElement): void;
11
+ }
12
+ /** `<vsil-value variable="ECU.variable" [on="LOST" off="ok"] [no-unit]>`: the value and its unit; a bool shows as the `on` and `off` text. */
13
+ export declare class VsilValueElement extends VariablePart {
14
+ static observedAttributes: string[];
15
+ protected build(_variable: FrontVariable, root: HTMLElement, note: HTMLElement): (v: VariableView) => void;
16
+ }
17
+ /** `<vsil-slider variable="ECU.variable">`: a number in the variable's range; it is written when the knob is released. */
18
+ export declare class VsilSliderElement extends VariablePart {
19
+ protected readonly writes = true;
20
+ protected build(variable: FrontVariable, root: HTMLElement, note: HTMLElement): (v: VariableView) => void;
21
+ }
22
+ /** `<vsil-write variable="ECU.variable" value="false" label="Cut">`: writes one value when pressed (not when it already is that value). */
23
+ export declare class VsilWriteElement extends VariablePart {
24
+ static observedAttributes: string[];
25
+ protected readonly writes = true;
26
+ protected build(variable: FrontVariable, root: HTMLElement, note: HTMLElement): (v: VariableView) => void;
27
+ }
28
+ export {};
@@ -0,0 +1,122 @@
1
+ import type { GuiClient } from './client.js';
2
+ import { HttpTransport } from './http.js';
3
+ import type { FrontControls, Intent, OperationName, RunState } from './front-types.js';
4
+ import { ActionError } from './front-types.js';
5
+ import type { Snapshot } from './front-compose.js';
6
+ import type { CheckResult, ConfigText, SavedConfig } from './protocol.js';
7
+ import { ErrorSink, Readable } from './values.js';
8
+ /** A failed action, kept for `status.problem`. */
9
+ export interface Failure {
10
+ error: ActionError;
11
+ /** `status.run` when it happened: the failure goes when that changes. */
12
+ run: RunState;
13
+ /** Later is newer. */
14
+ stamp: number;
15
+ }
16
+ /** What the operations read from the rest of the front. */
17
+ export interface ActionSources {
18
+ low: GuiClient;
19
+ http: HttpTransport;
20
+ snapshot(): Snapshot;
21
+ controls(): FrontControls;
22
+ run(): RunState;
23
+ /** The start-up file (null if there is none). */
24
+ initialFile(): string | null;
25
+ /** How long to wait for the launcher's answer to a time command (ms). */
26
+ answerTimeoutMs: number;
27
+ onError: ErrorSink;
28
+ /** The next stamp (shared with the other sources of problems). */
29
+ stamp(): number;
30
+ }
31
+ /** Turns what went wrong on the way to the server into an ActionError. */
32
+ export declare function actionError(error: unknown): ActionError;
33
+ /** The refusal when there is no file to use. */
34
+ export declare const noFileError: () => ActionError;
35
+ export declare class FrontActions {
36
+ private readonly src;
37
+ private readonly busyValue;
38
+ private readonly failureValue;
39
+ private readonly waiting;
40
+ private readonly inFlight;
41
+ /** The checks not answered yet, in the order they are sent: the first is on its way, the others wait. */
42
+ private readonly checks;
43
+ /** Rejects when the client closes: a check that waits ends with it. */
44
+ private close;
45
+ private readonly closing;
46
+ private nextId;
47
+ private lastSim;
48
+ private readonly stops;
49
+ private disposed;
50
+ readonly busy: Readable<ReadonlySet<OperationName>>;
51
+ readonly failure: Readable<Failure | null>;
52
+ constructor(src: ActionSources,
53
+ /** Where the ids start (they must differ between pages that send to the same run). */
54
+ idStart?: number);
55
+ start(intent?: Intent, options?: {
56
+ file?: string;
57
+ }): Promise<void>;
58
+ /**
59
+ * Checks what `intent` would start (`api/check`). Its failure is the caller's: it is not kept for `status.problem`.
60
+ * One check at a time: a check is sent after the answer to the one before (the server runs them one at a time, and
61
+ * refuses with `check-busy` when too many wait). A check of the same request as one that waits or is on its way
62
+ * shares it (the parts and the screen of a page check the same page intent); with `fresh`, only one that waits (a
63
+ * check that the user asks for again reads the file as it is now). A check whose callers have all aborted
64
+ * (`signal`) while it waits is not sent, and neither is one that waits when the client closes (`closed`).
65
+ */
66
+ check(intent?: Intent, options?: {
67
+ file?: string;
68
+ text?: string;
69
+ signal?: AbortSignal;
70
+ fresh?: boolean;
71
+ }): Promise<CheckResult>;
72
+ /** Reads a configuration file as it is saved. Its failure is the caller's: it is not kept for `status.problem`. */
73
+ readConfig(options?: {
74
+ file?: string;
75
+ }): Promise<ConfigText>;
76
+ /** Saves a text as a configuration file. Its failure is the caller's: it is not kept for `status.problem`. */
77
+ saveConfig(options: {
78
+ file?: string;
79
+ text: string;
80
+ stamp: string | null;
81
+ }): Promise<SavedConfig>;
82
+ /** Describes the participants of the saved file again. It waits in the line of the checks; it shares only with a describe of the same file and variant. */
83
+ describeAgain(options?: {
84
+ file?: string;
85
+ variant?: string;
86
+ }): Promise<CheckResult>;
87
+ /** The line of the checks: one is sent after the answer to the one before. `key` null: nothing is shared. */
88
+ private enqueue;
89
+ /** The body of api/run and api/check for `intent`, or why it cannot be sent. */
90
+ private requestOf;
91
+ /** The body of api/check for a text: the server takes only the configuration (`variant`, `strict`), not a run's choices. */
92
+ private textRequestOf;
93
+ /** What the client refuses before it sends a start: the connection, and a start of this page still on its way. */
94
+ private refusalOfStart;
95
+ stop(): Promise<void>;
96
+ forceStop(): Promise<void>;
97
+ /** A stop asked again while its request is on its way is the same request (a double click sends nothing more). */
98
+ private once;
99
+ private guarded;
100
+ pause(): Promise<void>;
101
+ resume(): Promise<void>;
102
+ step(ms: number): Promise<void>;
103
+ setSpeed(value: number | 'max'): Promise<void>;
104
+ runUntil(ms: number): Promise<void>;
105
+ private time;
106
+ /** Ends a waiting command: with an error, or (null) as done. A command ended twice is ended once. */
107
+ private settle;
108
+ private stillSent;
109
+ private setBusy;
110
+ /** The launcher's events: an answer to a command of ours, and commands of other senders. */
111
+ private onMessages;
112
+ private answered;
113
+ /** Ends the steps and run_untils on their way (except `keep`) as interrupted. */
114
+ private interruptMoving;
115
+ /** Ends what the state of the run decides: the run is over, time has arrived, or a stop is on its way. */
116
+ private evaluate;
117
+ /** Keeps the error for `status.problem`. */
118
+ record(error: ActionError): ActionError;
119
+ private fail;
120
+ /** Stops waiting (the client closes): what is waiting ends as unknown, and a check that waits is not sent. */
121
+ dispose(): void;
122
+ }