@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
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tinyactors/scxmljs — a correctness-first SCXML 1.0 interpreter for the
|
|
3
|
+
* ECMAScript data model, running directly on DOM elements.
|
|
4
|
+
*
|
|
5
|
+
* This entry point uses the SANDBOXED data model: every session evaluates its
|
|
6
|
+
* ECMAScript in its own QuickJS (WebAssembly) context. Use it for charts that
|
|
7
|
+
* users author. For charts you trust and a smaller download, import
|
|
8
|
+
* `@tinyactors/scxmljs/trusted` instead — same API.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
import { loadQuickJS } from "./datamodel-quickjs.js";
|
|
13
|
+
import type { Model } from "./model.js";
|
|
14
|
+
import { SCXMLSession, type SessionOptions } from "./session.js";
|
|
15
|
+
export * from "./common.js";
|
|
16
|
+
export { loadQuickJS };
|
|
17
|
+
/**
|
|
18
|
+
* A session with the sandboxed data model (QuickJS/WebAssembly).
|
|
19
|
+
*
|
|
20
|
+
* Constructing one directly requires QuickJS to be loaded: `await loadQuickJS()`
|
|
21
|
+
* once first (`createSession` does it for you). Use this to create many
|
|
22
|
+
* sessions synchronously from one compiled model.
|
|
23
|
+
*/
|
|
24
|
+
export declare class Session extends SCXMLSession {
|
|
25
|
+
constructor(model: Model, opts?: SessionOptions);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Load QuickJS (once), compile the document and create a session. The session
|
|
29
|
+
* is not started: call `start()`. Call `dispose()` when you are done with it.
|
|
30
|
+
*
|
|
31
|
+
* `source` is SCXML text, an `<scxml>` element or a model from `compile()`.
|
|
32
|
+
* Parsing text outside browsers needs `opts.domParser`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createSession(source: string | Element | Model, opts?: SessionOptions): Promise<Session>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tinyactors/scxmljs — a correctness-first SCXML 1.0 interpreter for the
|
|
3
|
+
* ECMAScript data model, running directly on DOM elements.
|
|
4
|
+
*
|
|
5
|
+
* This entry point uses the SANDBOXED data model: every session evaluates its
|
|
6
|
+
* ECMAScript in its own QuickJS (WebAssembly) context. Use it for charts that
|
|
7
|
+
* users author. For charts you trust and a smaller download, import
|
|
8
|
+
* `@tinyactors/scxmljs/trusted` instead — same API.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
import { loadQuickJS, sandboxedDataModel } from "./datamodel-quickjs.js";
|
|
13
|
+
import { resolveModel, SCXMLSession } from "./session.js";
|
|
14
|
+
export * from "./common.js";
|
|
15
|
+
export { loadQuickJS };
|
|
16
|
+
/**
|
|
17
|
+
* A session with the sandboxed data model (QuickJS/WebAssembly).
|
|
18
|
+
*
|
|
19
|
+
* Constructing one directly requires QuickJS to be loaded: `await loadQuickJS()`
|
|
20
|
+
* once first (`createSession` does it for you). Use this to create many
|
|
21
|
+
* sessions synchronously from one compiled model.
|
|
22
|
+
*/
|
|
23
|
+
export class Session extends SCXMLSession {
|
|
24
|
+
constructor(model, opts = {}) {
|
|
25
|
+
super(model, { datamodel: sandboxedDataModel, ...opts });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Load QuickJS (once), compile the document and create a session. The session
|
|
30
|
+
* is not started: call `start()`. Call `dispose()` when you are done with it.
|
|
31
|
+
*
|
|
32
|
+
* `source` is SCXML text, an `<scxml>` element or a model from `compile()`.
|
|
33
|
+
* Parsing text outside browsers needs `opts.domParser`.
|
|
34
|
+
*/
|
|
35
|
+
export async function createSession(source, opts = {}) {
|
|
36
|
+
await loadQuickJS();
|
|
37
|
+
return new Session(await resolveModel(source, opts), opts);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAuB,MAAM,cAAc,CAAC;AAE/E,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB;;;;;;GAMG;AACH,MAAM,OAAO,OAAQ,SAAQ,YAAY;IACvC,YAAY,KAAY,EAAE,IAAI,GAAmB,EAAE;QACjD,KAAK,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,kBAAkB,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAgC,EAAE,IAAI,GAAmB,EAAE;IAC7F,MAAM,WAAW,EAAE,CAAC;IACpB,OAAO,IAAI,OAAO,CAAC,MAAM,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;AAC7D,CAAC","sourcesContent":["/**\n * @tinyactors/scxmljs — a correctness-first SCXML 1.0 interpreter for the\n * ECMAScript data model, running directly on DOM elements.\n *\n * This entry point uses the SANDBOXED data model: every session evaluates its\n * ECMAScript in its own QuickJS (WebAssembly) context. Use it for charts that\n * users author. For charts you trust and a smaller download, import\n * `@tinyactors/scxmljs/trusted` instead — same API.\n *\n * @packageDocumentation\n */\nimport { loadQuickJS, sandboxedDataModel } from \"./datamodel-quickjs.ts\";\nimport type { Model } from \"./model.ts\";\nimport { resolveModel, SCXMLSession, type SessionOptions } from \"./session.ts\";\n\nexport * from \"./common.ts\";\nexport { loadQuickJS };\n\n/**\n * A session with the sandboxed data model (QuickJS/WebAssembly).\n *\n * Constructing one directly requires QuickJS to be loaded: `await loadQuickJS()`\n * once first (`createSession` does it for you). Use this to create many\n * sessions synchronously from one compiled model.\n */\nexport class Session extends SCXMLSession {\n constructor(model: Model, opts: SessionOptions = {}) {\n super(model, { datamodel: sandboxedDataModel, ...opts });\n }\n}\n\n/**\n * Load QuickJS (once), compile the document and create a session. The session\n * is not started: call `start()`. Call `dispose()` when you are done with it.\n *\n * `source` is SCXML text, an `<scxml>` element or a model from `compile()`.\n * Parsing text outside browsers needs `opts.domParser`.\n */\nexport async function createSession(source: string | Element | Model, opts: SessionOptions = {}): Promise<Session> {\n await loadQuickJS();\n return new Session(await resolveModel(source, opts), opts);\n}\n"]}
|
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compiles an `<scxml>` DOM element into an immutable, validated model.
|
|
3
|
+
*
|
|
4
|
+
* The model keeps a reference to every source element, so renderers can map
|
|
5
|
+
* live state back onto the document. Validation follows the constraints of
|
|
6
|
+
* spec §3 (ids, targets, initial states, history, executable content);
|
|
7
|
+
* a non-conformant document raises `SCXMLValidationError` listing every problem.
|
|
8
|
+
*/
|
|
9
|
+
import { type Diagnostic } from "./diagnostics.js";
|
|
10
|
+
/** The element a state node was compiled from (`scxml` is the root). */
|
|
11
|
+
export type StateKind = "scxml" | "state" | "parallel" | "final" | "history";
|
|
12
|
+
/**
|
|
13
|
+
* A state of a compiled chart. Every node keeps its source `element`, so
|
|
14
|
+
* renderers can map live state back onto the document.
|
|
15
|
+
*/
|
|
16
|
+
export interface StateNode {
|
|
17
|
+
/** Which element it is. */
|
|
18
|
+
kind: StateKind;
|
|
19
|
+
/** The `id` attribute, or a generated one (see `generatedId`). */
|
|
20
|
+
id: string;
|
|
21
|
+
/** True when the author omitted `id` and one was generated (spec §3.14). */
|
|
22
|
+
generatedId: boolean;
|
|
23
|
+
/** The source element (`<state>`, `<parallel>`, …). */
|
|
24
|
+
element: Element;
|
|
25
|
+
/** The containing state; `null` for the root. */
|
|
26
|
+
parent: StateNode | null;
|
|
27
|
+
/** `<state>`, `<parallel>` and `<final>` children — spec `getChildStates`. */
|
|
28
|
+
children: StateNode[];
|
|
29
|
+
/** `<history>` children. */
|
|
30
|
+
history: StateNode[];
|
|
31
|
+
/** Document order. */
|
|
32
|
+
order: number;
|
|
33
|
+
/** Nesting depth: the root is 0. */
|
|
34
|
+
depth: number;
|
|
35
|
+
/** Its `<transition>`s, in document order. */
|
|
36
|
+
transitions: TransitionNode[];
|
|
37
|
+
/** Each `<onentry>` / `<onexit>` element is a separate executable block. */
|
|
38
|
+
onentry: Element[];
|
|
39
|
+
/** The `<onexit>` blocks, in document order. */
|
|
40
|
+
onexit: Element[];
|
|
41
|
+
/** Its `<invoke>`s, in document order. */
|
|
42
|
+
invokes: InvokeNode[];
|
|
43
|
+
/** `<data>` elements of this state's own `<datamodel>`. */
|
|
44
|
+
data: Element[];
|
|
45
|
+
/** Initial transition, for compound states and `<scxml>`. */
|
|
46
|
+
initial: TransitionNode | null;
|
|
47
|
+
/** For `<history>` nodes: whether it remembers only direct children (`shallow`) or the full descendant configuration (`deep`). */
|
|
48
|
+
historyType?: "shallow" | "deep";
|
|
49
|
+
/** For `<final>` states: the `<donedata>` element, if any. */
|
|
50
|
+
donedata: Element | null;
|
|
51
|
+
}
|
|
52
|
+
/** A transition of a compiled chart. */
|
|
53
|
+
export interface TransitionNode {
|
|
54
|
+
/** `null` for initial transitions synthesised from an `initial` attribute or default. */
|
|
55
|
+
element: Element | null;
|
|
56
|
+
/** The state it belongs to. */
|
|
57
|
+
source: StateNode;
|
|
58
|
+
/** The event descriptors of the `event` attribute (empty for eventless transitions). */
|
|
59
|
+
events: string[];
|
|
60
|
+
/** The `cond` expression, or `null`. */
|
|
61
|
+
cond: string | null;
|
|
62
|
+
/** The targets (empty for targetless transitions). */
|
|
63
|
+
targets: StateNode[];
|
|
64
|
+
/** The `type` attribute: `internal` doesn't exit its source state when the targets are its descendants. */
|
|
65
|
+
type: "internal" | "external";
|
|
66
|
+
/** Document order. */
|
|
67
|
+
order: number;
|
|
68
|
+
}
|
|
69
|
+
/** An `<invoke>` of a compiled chart. */
|
|
70
|
+
export interface InvokeNode {
|
|
71
|
+
/** The `<invoke>` element. */
|
|
72
|
+
element: Element;
|
|
73
|
+
/** The state it belongs to (invoked while that state is active). */
|
|
74
|
+
state: StateNode;
|
|
75
|
+
/** Document order. */
|
|
76
|
+
order: number;
|
|
77
|
+
/** The `autoforward` attribute: external events are forwarded to the invoked service. */
|
|
78
|
+
autoforward: boolean;
|
|
79
|
+
/** The `<finalize>` element, if any. */
|
|
80
|
+
finalize: Element | null;
|
|
81
|
+
}
|
|
82
|
+
/** A compiled, validated chart. Sessions only read it, so one model can serve many sessions. */
|
|
83
|
+
export interface Model {
|
|
84
|
+
/** The SCXML namespace the document uses. */
|
|
85
|
+
ns: string | null;
|
|
86
|
+
/** The `<scxml>` element's node. */
|
|
87
|
+
root: StateNode;
|
|
88
|
+
/** All states (including history and the root) in document order. */
|
|
89
|
+
states: StateNode[];
|
|
90
|
+
/** States by id (generated ids included). */
|
|
91
|
+
byId: Map<string, StateNode>;
|
|
92
|
+
/** States by source element. */
|
|
93
|
+
byElement: Map<Element, StateNode>;
|
|
94
|
+
/** Transitions by source `<transition>` element. */
|
|
95
|
+
transitionsByElement: Map<Element, TransitionNode>;
|
|
96
|
+
/** The `<scxml name>` attribute (`""` when absent). */
|
|
97
|
+
name: string;
|
|
98
|
+
/** The `binding` attribute: when `<data>` is initialised. */
|
|
99
|
+
binding: "early" | "late";
|
|
100
|
+
/** `<script>` children of `<scxml>`. */
|
|
101
|
+
scripts: Element[];
|
|
102
|
+
/** Every `<data>` element, document order. */
|
|
103
|
+
allData: Element[];
|
|
104
|
+
/** Pre-loaded `src` contents for `<script src>` and `<data src>` (value: text, or an Error). */
|
|
105
|
+
resources: Map<Element, string | Error>;
|
|
106
|
+
/** Likely mistakes that are still valid SCXML (see `Diagnostic`); empty for most charts. */
|
|
107
|
+
warnings: Diagnostic[];
|
|
108
|
+
}
|
|
109
|
+
/** The document isn't valid SCXML. `problems` lists every problem found. */
|
|
110
|
+
export declare class SCXMLValidationError extends Error {
|
|
111
|
+
/** Always `"SCXML_INVALID"`. */
|
|
112
|
+
readonly code: "SCXML_INVALID";
|
|
113
|
+
/** Every problem found, one line each (they are also listed in `message`). */
|
|
114
|
+
readonly problems: string[];
|
|
115
|
+
/** @param problems every problem found, one line each */
|
|
116
|
+
constructor(problems: string[]);
|
|
117
|
+
}
|
|
118
|
+
/** SCXML text couldn't be parsed (or there is no `DOMParser` to parse it with). */
|
|
119
|
+
export declare class SCXMLParseError extends Error {
|
|
120
|
+
readonly code: "SCXML_PARSE" | "SCXML_NO_DOMPARSER";
|
|
121
|
+
/**
|
|
122
|
+
* @param code `SCXML_PARSE`: the text isn't well-formed XML (or has no `<scxml>` root);
|
|
123
|
+
* `SCXML_NO_DOMPARSER`: there is no `DOMParser` (outside browsers: pass `domParser`).
|
|
124
|
+
*/
|
|
125
|
+
constructor(code: "SCXML_PARSE" | "SCXML_NO_DOMPARSER", message: string);
|
|
126
|
+
}
|
|
127
|
+
/** Resolves `src` attributes (`<script>`, `<data>`, `<invoke>`) to their text; may be synchronous. */
|
|
128
|
+
export type Loader = (src: string) => string | Promise<string>;
|
|
129
|
+
/** A state without child states (or a `<final>`). */
|
|
130
|
+
export declare const isAtomic: (s: StateNode) => boolean;
|
|
131
|
+
/** A `<state>` with child states. */
|
|
132
|
+
export declare const isCompound: (s: StateNode) => boolean;
|
|
133
|
+
export declare const isCompoundOrRoot: (s: StateNode) => boolean;
|
|
134
|
+
/** True when `a` is a proper descendant of `b`. */
|
|
135
|
+
export declare function isDescendant(a: StateNode, b: StateNode): boolean;
|
|
136
|
+
/** Ancestors of `s` up to (excluding) `upTo`; with `upTo = null`, up to and including the root. */
|
|
137
|
+
export declare function properAncestors(s: StateNode, upTo: StateNode | null): StateNode[];
|
|
138
|
+
/** A comparator for `Array.sort`: document order. */
|
|
139
|
+
export declare const documentOrder: (a: {
|
|
140
|
+
order: number;
|
|
141
|
+
}, b: {
|
|
142
|
+
order: number;
|
|
143
|
+
}) => number;
|
|
144
|
+
export declare const exitOrder: (a: {
|
|
145
|
+
order: number;
|
|
146
|
+
}, b: {
|
|
147
|
+
order: number;
|
|
148
|
+
}) => number;
|
|
149
|
+
/** SCXML-namespace child elements (foreign elements are ignored everywhere). */
|
|
150
|
+
export declare function scxmlChildren(el: Element, ns: string | null): Element[];
|
|
151
|
+
/**
|
|
152
|
+
* Compile an `<scxml>` element. `src` attributes on `<script>` and `<data>`
|
|
153
|
+
* are fetched with `loader`; the result is synchronous when the loader is.
|
|
154
|
+
*/
|
|
155
|
+
export declare function compile(root: Element, opts?: {
|
|
156
|
+
loader?: Loader;
|
|
157
|
+
}): Model | Promise<Model>;
|