@tinyactors/scxmljs 0.1.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/LICENSE +21 -0
- package/README.md +174 -0
- package/THIRD_PARTY_NOTICES +63 -0
- package/dist/bridge.d.ts +44 -0
- package/dist/bridge.js +254 -0
- package/dist/bridge.js.map +1 -0
- package/dist/clock.d.ts +113 -0
- package/dist/clock.js +310 -0
- package/dist/clock.js.map +1 -0
- package/dist/common.d.ts +15 -0
- package/dist/common.js +14 -0
- package/dist/common.js.map +1 -0
- package/dist/datamodel-base.d.ts +122 -0
- package/dist/datamodel-base.js +268 -0
- package/dist/datamodel-base.js.map +1 -0
- package/dist/datamodel-quickjs.d.ts +21 -0
- package/dist/datamodel-quickjs.js +286 -0
- package/dist/datamodel-quickjs.js.map +1 -0
- package/dist/datamodel-trusted.d.ts +1 -0
- package/dist/datamodel-trusted.js +149 -0
- package/dist/datamodel-trusted.js.map +1 -0
- package/dist/diagnostics.d.ts +39 -0
- package/dist/diagnostics.js +154 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/element-events.d.ts +85 -0
- package/dist/element-events.js +129 -0
- package/dist/element-events.js.map +1 -0
- package/dist/events.d.ts +31 -0
- package/dist/events.js +33 -0
- package/dist/events.js.map +1 -0
- package/dist/explorer/element.d.ts +150 -0
- package/dist/explorer/element.js +1791 -0
- package/dist/explorer/element.js.map +1 -0
- package/dist/explorer/layout.d.ts +43 -0
- package/dist/explorer/layout.js +50 -0
- package/dist/explorer/layout.js.map +1 -0
- package/dist/explorer/strings.d.ts +275 -0
- package/dist/explorer/strings.js +135 -0
- package/dist/explorer/strings.js.map +1 -0
- package/dist/explorer/styles.d.ts +10 -0
- package/dist/explorer/styles.js +265 -0
- package/dist/explorer/styles.js.map +1 -0
- package/dist/explorer/viewmodel.d.ts +284 -0
- package/dist/explorer/viewmodel.js +481 -0
- package/dist/explorer/viewmodel.js.map +1 -0
- package/dist/explorer.d.ts +21 -0
- package/dist/explorer.js +22 -0
- package/dist/explorer.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/model.d.ts +157 -0
- package/dist/model.js +485 -0
- package/dist/model.js.map +1 -0
- package/dist/session-events.d.ts +136 -0
- package/dist/session-events.js +114 -0
- package/dist/session-events.js.map +1 -0
- package/dist/session.d.ts +412 -0
- package/dist/session.js +1399 -0
- package/dist/session.js.map +1 -0
- package/dist/themes/tinyactors.css +44 -0
- package/dist/trusted.d.ts +15 -0
- package/dist/trusted.js +30 -0
- package/dist/trusted.js.map +1 -0
- package/dist/ui/announcer.d.ts +22 -0
- package/dist/ui/announcer.js +31 -0
- package/dist/ui/announcer.js.map +1 -0
- package/dist/ui/svg.d.ts +8 -0
- package/dist/ui/svg.js +29 -0
- package/dist/ui/svg.js.map +1 -0
- package/dist/ui/theme.d.ts +34 -0
- package/dist/ui/theme.js +151 -0
- package/dist/ui/theme.js.map +1 -0
- package/dist/view/element.d.ts +172 -0
- package/dist/view/element.js +1045 -0
- package/dist/view/element.js.map +1 -0
- package/dist/view/layout.d.ts +154 -0
- package/dist/view/layout.js +1122 -0
- package/dist/view/layout.js.map +1 -0
- package/dist/view/strings.d.ts +72 -0
- package/dist/view/strings.js +48 -0
- package/dist/view/strings.js.map +1 -0
- package/dist/view/styles.d.ts +1 -0
- package/dist/view/styles.js +115 -0
- package/dist/view/styles.js.map +1 -0
- package/dist/view.d.ts +20 -0
- package/dist/view.js +21 -0
- package/dist/view.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An SCXML session: a faithful implementation of the algorithm in
|
|
3
|
+
* W3C SCXML 1.0, Appendix D, plus executable content (§4), the data model
|
|
4
|
+
* rules (§5), `<send>` / `<invoke>` (§6) and the SCXML Event I/O Processor
|
|
5
|
+
* (Appendix C.1).
|
|
6
|
+
*
|
|
7
|
+
* Procedure names follow the spec so the two can be read side by side.
|
|
8
|
+
* Performance is a non-goal: sets are rebuilt freely, nothing is cached.
|
|
9
|
+
*
|
|
10
|
+
* Scheduling: the internal queue is drained synchronously (a macrostep).
|
|
11
|
+
* External events are processed one at a time on `clock.defer`, so the
|
|
12
|
+
* session is always idle between external events and never re-entered.
|
|
13
|
+
*/
|
|
14
|
+
import { type BindOptions, type ConnectOptions, type EventNameMapper } from "./bridge.js";
|
|
15
|
+
import { type Clock } from "./clock.js";
|
|
16
|
+
import type { DataModel, DataModelFactory } from "./datamodel-base.js";
|
|
17
|
+
import { type ReflectOptions } from "./element-events.js";
|
|
18
|
+
import { type SCXMLEvent } from "./events.js";
|
|
19
|
+
import { type InvokeNode, type Loader, type Model, type StateNode } from "./model.js";
|
|
20
|
+
import { MacrostepEvent, type SessionEventMap } from "./session-events.js";
|
|
21
|
+
/** A message produced by `<send>` for a non-SCXML Event I/O Processor. */
|
|
22
|
+
export interface OutboundSend {
|
|
23
|
+
/** The event name (`event` / `eventexpr`). */
|
|
24
|
+
event: string;
|
|
25
|
+
/** The target (`target` / `targetexpr`); what it means is up to the processor. */
|
|
26
|
+
target: string;
|
|
27
|
+
/** The processor's canonical type URI. */
|
|
28
|
+
type: string;
|
|
29
|
+
/** The payload: namelist/`<param>` values as an object, or the `<content>` value. */
|
|
30
|
+
data: unknown;
|
|
31
|
+
/** The send's id (`id`, or generated for `idlocation`), if it has one. */
|
|
32
|
+
sendid?: string;
|
|
33
|
+
}
|
|
34
|
+
/** The handle an I/O processor uses to talk to one session. */
|
|
35
|
+
export interface IOSession {
|
|
36
|
+
/** The session's id (as in `_sessionid`). */
|
|
37
|
+
readonly sessionId: string;
|
|
38
|
+
/** Deliver an inbound event to the session's external queue. */
|
|
39
|
+
deliver(name: string, data?: unknown, origin?: string): void;
|
|
40
|
+
}
|
|
41
|
+
/** An Event I/O Processor (spec §6.2.4, Appendix C). */
|
|
42
|
+
export interface IOProcessor {
|
|
43
|
+
/** Canonical type URI: key in `_ioprocessors`, and `_event.origintype` of inbound events. */
|
|
44
|
+
readonly type: string;
|
|
45
|
+
/** Short names accepted in `<send type="…">`. */
|
|
46
|
+
readonly aliases?: readonly string[];
|
|
47
|
+
/** The address other parties use to reach this session through the processor (`_ioprocessors[type].location`). */
|
|
48
|
+
location(session: IOSession): string;
|
|
49
|
+
/** Called when a session using the processor starts; keep the handle to deliver inbound events. */
|
|
50
|
+
attach?(session: IOSession): void;
|
|
51
|
+
/** Called when that session terminates or is disposed; stop delivering to it. */
|
|
52
|
+
detach?(session: IOSession): void;
|
|
53
|
+
/** Transport a message. Throwing places `error.communication` on the internal queue. */
|
|
54
|
+
send(message: OutboundSend, session: IOSession): void;
|
|
55
|
+
}
|
|
56
|
+
/** A running invoked service, as seen by the invoking session. */
|
|
57
|
+
export interface InvokedService {
|
|
58
|
+
/** Deliver an event from the parent (`#_<invokeid>` targets and autoforward). */
|
|
59
|
+
send(event: SCXMLEvent): void;
|
|
60
|
+
/** Cancel: the invoking state was exited. */
|
|
61
|
+
cancel(): void;
|
|
62
|
+
}
|
|
63
|
+
/** What a custom `Invoker` receives for one `<invoke>`. */
|
|
64
|
+
export interface InvokeContext {
|
|
65
|
+
/** The invocation's id: `id`, or a generated `stateid.platformid` (also stored in `idlocation`). */
|
|
66
|
+
invokeid: string;
|
|
67
|
+
/** The `type` / `typeexpr` value. */
|
|
68
|
+
type: string;
|
|
69
|
+
/** The `src` / `srcexpr` value, if any. */
|
|
70
|
+
src?: string;
|
|
71
|
+
/** Inline `<content>`: an Element, or the value of `content/@expr`. */
|
|
72
|
+
content?: unknown;
|
|
73
|
+
/** Values from namelist and `<param>`. */
|
|
74
|
+
params: Record<string, unknown>;
|
|
75
|
+
/** Send an event to the invoking session (it arrives with `invokeid` set). */
|
|
76
|
+
sendToParent(name: string, data?: unknown): void;
|
|
77
|
+
/** The service finished: the parent receives `done.invoke.<invokeid>`. */
|
|
78
|
+
done(data?: unknown): void;
|
|
79
|
+
}
|
|
80
|
+
/** Handler for a custom `<invoke type="…">`. */
|
|
81
|
+
export type Invoker = (ctx: InvokeContext) => InvokedService | Promise<InvokedService>;
|
|
82
|
+
/**
|
|
83
|
+
* A `DOMParser`: the browser's, or one from a DOM implementation such as
|
|
84
|
+
* happy-dom or linkedom. Only `parseFromString` is used, and its result only
|
|
85
|
+
* needs to behave like a standard XML `Document`; the return type is `unknown`
|
|
86
|
+
* so any implementation's own `Document` type is accepted without a cast.
|
|
87
|
+
*/
|
|
88
|
+
export interface DOMParserLike {
|
|
89
|
+
/** Parse `source` as the given MIME type (the session asks for `application/xml`). */
|
|
90
|
+
parseFromString(source: string, type: string): unknown;
|
|
91
|
+
}
|
|
92
|
+
/** A running invocation (see `SCXMLSession.invocations`). */
|
|
93
|
+
export interface Invocation {
|
|
94
|
+
/** The invocation's id. */
|
|
95
|
+
invokeid: string;
|
|
96
|
+
/** The invoke type (the SCXML type URI or a custom invoker's name). */
|
|
97
|
+
type: string;
|
|
98
|
+
/** The state whose `<invoke>` started it. */
|
|
99
|
+
state: StateNode;
|
|
100
|
+
/** The `<invoke>` itself. */
|
|
101
|
+
node: InvokeNode;
|
|
102
|
+
/** The child session, for SCXML invocations. */
|
|
103
|
+
session?: SCXMLSession;
|
|
104
|
+
}
|
|
105
|
+
/** How a session was invoked (see `SCXMLSession.parentSession`). */
|
|
106
|
+
export interface ParentInvocation {
|
|
107
|
+
/** The invoking session. */
|
|
108
|
+
session: SCXMLSession;
|
|
109
|
+
/** The invocation's id in the parent. */
|
|
110
|
+
invokeid: string;
|
|
111
|
+
}
|
|
112
|
+
/** What `waitFor` waits for: an active state id, several ids that must all be active, or a predicate. */
|
|
113
|
+
export type WaitCondition = string | readonly string[] | ((session: SCXMLSession) => boolean);
|
|
114
|
+
/** Options for `waitFor()`. */
|
|
115
|
+
export interface WaitForOptions {
|
|
116
|
+
/** Reject with `signal.reason` when it aborts. */
|
|
117
|
+
signal?: AbortSignal;
|
|
118
|
+
/** Reject with a `TimeoutError` after this many ms of the session's clock. */
|
|
119
|
+
timeoutMs?: number;
|
|
120
|
+
}
|
|
121
|
+
/** Options for `createSession()` and the `Session` constructors. */
|
|
122
|
+
export interface SessionOptions {
|
|
123
|
+
/**
|
|
124
|
+
* The ECMAScript engine. Set by the entry point you import: sandboxed
|
|
125
|
+
* (QuickJS/WebAssembly) from `@tinyactors/scxmljs`, trusted (the host's
|
|
126
|
+
* own engine) from `@tinyactors/scxmljs/trusted`. Invoked children inherit it.
|
|
127
|
+
*/
|
|
128
|
+
datamodel?: DataModelFactory;
|
|
129
|
+
/** The session's id (`_sessionid`, and the `#_scxml_<id>` address). Default: generated and unique. */
|
|
130
|
+
sessionId?: string;
|
|
131
|
+
/** Where time comes from: `realClock` (default), a `VirtualClock` for tests, a `PlaybackClock` for UIs. */
|
|
132
|
+
clock?: Clock;
|
|
133
|
+
/** Event I/O Processors in addition to the built-in SCXML one. */
|
|
134
|
+
ioprocessors?: IOProcessor[];
|
|
135
|
+
/** Handlers for `<invoke>` types other than SCXML. */
|
|
136
|
+
invokers?: Record<string, Invoker>;
|
|
137
|
+
/** Resolves `src` attributes (`<script>`, `<data>`, `<invoke>`). May return synchronously. */
|
|
138
|
+
loader?: Loader;
|
|
139
|
+
/** Needed to parse SCXML given as text (invoke src/srcexpr/content expressions). Defaults to the global DOMParser. */
|
|
140
|
+
domParser?: DOMParserLike;
|
|
141
|
+
/** Initial values overriding `<data>` of the same id (the host's or the invoker's params). */
|
|
142
|
+
data?: Record<string, unknown>;
|
|
143
|
+
/** Interrupt a single evaluation after this many ms (default 2000). Sandboxed data model only. */
|
|
144
|
+
scriptTimeoutMs?: number;
|
|
145
|
+
/** Memory limit of the session's QuickJS context, in bytes (default 64 MiB). Sandboxed data model only. */
|
|
146
|
+
memoryLimitBytes?: number;
|
|
147
|
+
/** Stop after this many microsteps in one macrostep, to keep a UI responsive (default 100000). */
|
|
148
|
+
maxMicrosteps?: number;
|
|
149
|
+
/**
|
|
150
|
+
* Dispatch bubbling `scxml:exit`, `scxml:transition`, `scxml:enter` and
|
|
151
|
+
* `scxml:done` events on the chart's own source elements. Off by default:
|
|
152
|
+
* sessions sharing one model would share its elements.
|
|
153
|
+
*/
|
|
154
|
+
elementEvents?: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Keep `data-active`, `data-enabled`, `data-fired`, `data-initial` and
|
|
157
|
+
* `data-status` attributes on the source elements in sync, for CSS. Off by default.
|
|
158
|
+
*/
|
|
159
|
+
reflect?: boolean | ReflectOptions;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Parse SCXML text into its `<scxml>` element.
|
|
163
|
+
*
|
|
164
|
+
* Browsers have a `DOMParser`; Node, Bun and Deno don't, so pass one there
|
|
165
|
+
* (any standards-compliant implementation, e.g. happy-dom's or linkedom's).
|
|
166
|
+
*
|
|
167
|
+
* @throws {SCXMLParseError} `code: "SCXML_NO_DOMPARSER"` when no parser is
|
|
168
|
+
* available, `code: "SCXML_PARSE"` when the text isn't well-formed XML.
|
|
169
|
+
*/
|
|
170
|
+
export declare function parseSCXML(source: string, domParser?: DOMParserLike): Element;
|
|
171
|
+
/**
|
|
172
|
+
* A running (or not yet started) SCXML session.
|
|
173
|
+
*
|
|
174
|
+
* This is the type every session has, whichever data model runs it — use it
|
|
175
|
+
* to type code that works with any session (renderers, tests, invoked
|
|
176
|
+
* children). To create sessions, use `createSession` or `Session` from
|
|
177
|
+
* `@tinyactors/scxmljs` (sandboxed) or `@tinyactors/scxmljs/trusted`.
|
|
178
|
+
*
|
|
179
|
+
* Lifetime: `start()` runs the chart; it ends by reaching a top-level final
|
|
180
|
+
* state or by `cancel()`. Every session holds resources until `dispose()` —
|
|
181
|
+
* a data model context (a QuickJS context, or an iframe / vm realm), timers,
|
|
182
|
+
* listeners it installed with `connect()` / `bind()`, and an entry in a
|
|
183
|
+
* page-wide registry used to route `<send target="#_scxml_<sessionid>">`
|
|
184
|
+
* between sessions. Call `dispose()` when you are done with a session, even
|
|
185
|
+
* a finished one.
|
|
186
|
+
*/
|
|
187
|
+
export declare class SCXMLSession extends EventTarget {
|
|
188
|
+
/** The compiled chart the session runs. */
|
|
189
|
+
readonly model: Model;
|
|
190
|
+
/** The session's id: `_sessionid`, and the address `#_scxml_<sessionId>`. */
|
|
191
|
+
readonly sessionId: string;
|
|
192
|
+
/** The session's data model (advanced: evaluate expressions against the running chart, for example in tools). */
|
|
193
|
+
readonly datamodel: DataModel;
|
|
194
|
+
private readonly opts;
|
|
195
|
+
/** The clock this session schedules on (delayed sends, deferred event processing). */
|
|
196
|
+
readonly clock: Clock;
|
|
197
|
+
private readonly configurationSet;
|
|
198
|
+
private readonly statesToInvoke;
|
|
199
|
+
private readonly internalQueue;
|
|
200
|
+
private readonly externalQueue;
|
|
201
|
+
private readonly historyValue;
|
|
202
|
+
private readonly lateBound;
|
|
203
|
+
private readonly invoked;
|
|
204
|
+
private readonly invokeIds;
|
|
205
|
+
private readonly delayed;
|
|
206
|
+
private readonly delayedBySendid;
|
|
207
|
+
private readonly processors;
|
|
208
|
+
private readonly ioSessions;
|
|
209
|
+
private parent?;
|
|
210
|
+
private readonly bridge?;
|
|
211
|
+
private running;
|
|
212
|
+
private started;
|
|
213
|
+
private exited;
|
|
214
|
+
private busy;
|
|
215
|
+
private scheduled;
|
|
216
|
+
private sendCounter;
|
|
217
|
+
private settleWaiters;
|
|
218
|
+
private resolveDone;
|
|
219
|
+
/**
|
|
220
|
+
* Resolves when the session terminates, with the top-level final state's
|
|
221
|
+
* `<donedata>` (or `undefined`). It never rejects: a session that is
|
|
222
|
+
* cancelled or disposed first resolves with `undefined` — check
|
|
223
|
+
* `session.cancelled` to tell the two apart.
|
|
224
|
+
*/
|
|
225
|
+
readonly done: Promise<unknown>;
|
|
226
|
+
constructor(model: Model, opts?: SessionOptions);
|
|
227
|
+
/**
|
|
228
|
+
* Listeners are wrapped so an exception in host code is reported and
|
|
229
|
+
* swallowed: it can never abort a step (in Bun an uncaught listener error
|
|
230
|
+
* would otherwise terminate the process).
|
|
231
|
+
*/
|
|
232
|
+
private readonly wrapped;
|
|
233
|
+
/**
|
|
234
|
+
* Listen to a session event (`microstep`, `macrostep`, `log`, `error`, `send`, `invoke`, `child`, `done`),
|
|
235
|
+
* typed through `SessionEventMap`. A listener that throws is logged and can't abort a step.
|
|
236
|
+
*/
|
|
237
|
+
addEventListener<K extends keyof SessionEventMap>(type: K, listener: (this: SCXMLSession, ev: SessionEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;
|
|
238
|
+
/** Any other event type (untyped). */
|
|
239
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;
|
|
240
|
+
/** Remove a listener added with `addEventListener`. */
|
|
241
|
+
removeEventListener<K extends keyof SessionEventMap>(type: K, listener: (this: SCXMLSession, ev: SessionEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void;
|
|
242
|
+
/** Any other event type (untyped). */
|
|
243
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void;
|
|
244
|
+
/** Active states, document order. */
|
|
245
|
+
get configuration(): StateNode[];
|
|
246
|
+
/** The ids of the active states, document order. */
|
|
247
|
+
activeStateIds(): string[];
|
|
248
|
+
/** Whether the state with this id is active. */
|
|
249
|
+
isActive(id: string): boolean;
|
|
250
|
+
/** Whether this state node is active. */
|
|
251
|
+
isActiveNode(s: StateNode): boolean;
|
|
252
|
+
/** Active invocations: what `<invoke>` started and is still running, with the child session for SCXML invokes. */
|
|
253
|
+
get invocations(): Invocation[];
|
|
254
|
+
/** The invoking session and invokeid, when this session was started by `<invoke>`. */
|
|
255
|
+
get parentSession(): ParentInvocation | undefined;
|
|
256
|
+
/** `"idle"` before `start()`, `"running"`, or `"done"` once the session has terminated (see `cancelled` for how). */
|
|
257
|
+
get status(): "idle" | "running" | "done";
|
|
258
|
+
/** The handle an I/O processor uses for this session. */
|
|
259
|
+
ioSession(p: IOProcessor): IOSession | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* A plain-data copy of every variable declared with `<data>`, keyed by id.
|
|
262
|
+
*
|
|
263
|
+
* Values are copied out of the data model the way JSON would copy them:
|
|
264
|
+
* objects and arrays are copied, functions are dropped, dates become ISO
|
|
265
|
+
* strings, and properties whose value is `undefined` may be omitted. XML
|
|
266
|
+
* values are serialised strings with the sandboxed data model and DOM nodes
|
|
267
|
+
* with the trusted one. Variables created by `<script>` without `<data>`
|
|
268
|
+
* are not included. After `dispose()` it returns `{}`.
|
|
269
|
+
*/
|
|
270
|
+
snapshot(): Record<string, unknown>;
|
|
271
|
+
/** Enqueue an external event. */
|
|
272
|
+
send(name: string, data?: unknown): void;
|
|
273
|
+
/** `interpret()` — spec Appendix D. */
|
|
274
|
+
start(): this;
|
|
275
|
+
/**
|
|
276
|
+
* Cancel the session from outside (like a parent cancelling an invoke):
|
|
277
|
+
* it exits all states, running `onexit` handlers, without a done event.
|
|
278
|
+
*/
|
|
279
|
+
cancel(): void;
|
|
280
|
+
/**
|
|
281
|
+
* Release everything the session holds: cancels it if it is still running
|
|
282
|
+
* (running `onexit` handlers, no done event), stops its timers, removes
|
|
283
|
+
* listeners installed by `connect()` / `bind()` and attributes set by
|
|
284
|
+
* `reflect`, frees the data model context and leaves the session registry.
|
|
285
|
+
* `done` resolves (with `undefined` if it hadn't finished). Safe to call
|
|
286
|
+
* more than once; the session can't be used afterwards.
|
|
287
|
+
*/
|
|
288
|
+
dispose(): void;
|
|
289
|
+
/** True when the session was ended by `cancel()` / `dispose()` rather than by reaching a final state. */
|
|
290
|
+
get cancelled(): boolean;
|
|
291
|
+
private wasCancelled;
|
|
292
|
+
private disposedDm;
|
|
293
|
+
private readonly lifetime;
|
|
294
|
+
/**
|
|
295
|
+
* Aborts when the session terminates (final state, cancel) or is disposed.
|
|
296
|
+
* Pass it to `addEventListener(…, { signal })` to tie host listeners to the session.
|
|
297
|
+
*/
|
|
298
|
+
get signal(): AbortSignal;
|
|
299
|
+
/**
|
|
300
|
+
* Send `scxmlEvent` whenever `target` fires `domType` (space-separated types or an array).
|
|
301
|
+
* `scxmlEvent` may be a function of the DOM event (null/undefined: don't send);
|
|
302
|
+
* `data` computes the event data. Returns a disposer; also disconnects on
|
|
303
|
+
* `options.signal` abort and when the session terminates.
|
|
304
|
+
*/
|
|
305
|
+
connect(target: EventTarget, domType: string | readonly string[], scxmlEvent: EventNameMapper, data?: (e: Event) => unknown, options?: ConnectOptions): () => void;
|
|
306
|
+
/**
|
|
307
|
+
* Declarative sends by event delegation on `root`: elements with
|
|
308
|
+
* `data-scxml-send` (see `bind` in bridge.ts for the attribute rules).
|
|
309
|
+
* Returns a disposer; also disconnects on `options.signal` abort and when
|
|
310
|
+
* the session terminates.
|
|
311
|
+
*/
|
|
312
|
+
bind(root: Element | Document, options?: BindOptions): () => void;
|
|
313
|
+
/**
|
|
314
|
+
* Resolves once the session is idle: both queues are empty and no
|
|
315
|
+
* processing is scheduled (or the session has terminated / not started).
|
|
316
|
+
* Pending delayed `<send>`s and replies still owed by I/O processors or
|
|
317
|
+
* invoked services do not count — the session is idle while it waits for them.
|
|
318
|
+
*
|
|
319
|
+
* It is driven by the session's own scheduler, never by polling: with a
|
|
320
|
+
* `VirtualClock`, nothing happens until the host calls `clock.run()`, and
|
|
321
|
+
* the promise resolves during that call.
|
|
322
|
+
*/
|
|
323
|
+
settled(): Promise<void>;
|
|
324
|
+
/**
|
|
325
|
+
* Resolves with the configuration at the first moment `what` holds:
|
|
326
|
+
* immediately, after a macrostep, or on entering a top-level final state
|
|
327
|
+
* (the configuration is cleared right after that, per the spec).
|
|
328
|
+
*
|
|
329
|
+
* `what`: a state id (active), several ids (all active) or a predicate.
|
|
330
|
+
* Rejects with `options.signal.reason` on abort, a `TimeoutError`
|
|
331
|
+
* DOMException after `timeoutMs` (measured on the session's clock), or an
|
|
332
|
+
* Error when the session terminates first.
|
|
333
|
+
*/
|
|
334
|
+
waitFor(what: WaitCondition, options?: WaitForOptions): Promise<StateNode[]>;
|
|
335
|
+
/**
|
|
336
|
+
* An async iterator over macrosteps, ending when the session terminates
|
|
337
|
+
* (or `options.signal` aborts). Macrosteps are buffered, so none are lost
|
|
338
|
+
* while the consumer is busy.
|
|
339
|
+
*
|
|
340
|
+
* for await (const step of session.steps()) render(step.configuration);
|
|
341
|
+
*/
|
|
342
|
+
steps(options?: {
|
|
343
|
+
signal?: AbortSignal;
|
|
344
|
+
}): AsyncIterableIterator<MacrostepEvent>;
|
|
345
|
+
private isIdle;
|
|
346
|
+
private checkSettled;
|
|
347
|
+
/**
|
|
348
|
+
* The part of `mainEventLoop` that runs until the session has to wait for
|
|
349
|
+
* an external event: macrosteps, then invokes, repeated while invoking
|
|
350
|
+
* produced internal events.
|
|
351
|
+
*/
|
|
352
|
+
private mainEventLoop;
|
|
353
|
+
/** Process one external event: the second half of `mainEventLoop`. */
|
|
354
|
+
private processExternalEvent;
|
|
355
|
+
private schedule;
|
|
356
|
+
private pump;
|
|
357
|
+
private enqueueExternal;
|
|
358
|
+
private enqueueInternal;
|
|
359
|
+
/** `exitInterpreter()` */
|
|
360
|
+
private exitInterpreter;
|
|
361
|
+
private returnDoneEvent;
|
|
362
|
+
private selectEventlessTransitions;
|
|
363
|
+
private selectTransitions;
|
|
364
|
+
private select;
|
|
365
|
+
private conditionMatch;
|
|
366
|
+
private removeConflictingTransitions;
|
|
367
|
+
private microstep;
|
|
368
|
+
/** The configuration is consistent again: tell the host (session event, then element events / attributes). */
|
|
369
|
+
private afterMicrostep;
|
|
370
|
+
private exitStates;
|
|
371
|
+
private computeExitSet;
|
|
372
|
+
private executeTransitionContent;
|
|
373
|
+
private enterStates;
|
|
374
|
+
private computeEntrySet;
|
|
375
|
+
private addDescendantStatesToEnter;
|
|
376
|
+
private addAncestorStatesToEnter;
|
|
377
|
+
private isInFinalState;
|
|
378
|
+
private getTransitionDomain;
|
|
379
|
+
private findLCCA;
|
|
380
|
+
private getEffectiveTargetStates;
|
|
381
|
+
private initializeDatamodel;
|
|
382
|
+
private bindData;
|
|
383
|
+
private declare;
|
|
384
|
+
/** Inline content of `<data>`, `<content>`, `<assign>` (spec §5.3, B.2): JSON, else a space-normalised string. */
|
|
385
|
+
private inlineValue;
|
|
386
|
+
/** Text content: JSON if it parses, XML if it is a document, else a whitespace-normalised string (spec B.2). */
|
|
387
|
+
private parseTextValue;
|
|
388
|
+
private evaluateCondition;
|
|
389
|
+
private evaluateDoneData;
|
|
390
|
+
/** namelist / `<param>` / `<content>` → event data. */
|
|
391
|
+
private evaluatePayload;
|
|
392
|
+
/** Execute a block. An error raises `error.execution` and ends the block (spec §4.9). */
|
|
393
|
+
private executeContent;
|
|
394
|
+
private execute;
|
|
395
|
+
private executeSend;
|
|
396
|
+
private prepareAndSend;
|
|
397
|
+
/** The SCXML Event I/O Processor (Appendix C.1). */
|
|
398
|
+
private dispatchScxml;
|
|
399
|
+
private communicationError;
|
|
400
|
+
private invoke;
|
|
401
|
+
private customInvoke;
|
|
402
|
+
/** SCXML child sessions. Synchronous unless the loader is asynchronous. */
|
|
403
|
+
private invokeScxml;
|
|
404
|
+
private cancelInvoke;
|
|
405
|
+
private applyFinalize;
|
|
406
|
+
private deliverToInvoke;
|
|
407
|
+
/** An event from an invoked child (or done.invoke): stamped with its invokeid. */
|
|
408
|
+
private receiveFromChild;
|
|
409
|
+
private raiseExecutionError;
|
|
410
|
+
private emitError;
|
|
411
|
+
private emit;
|
|
412
|
+
}
|