@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/model.js
ADDED
|
@@ -0,0 +1,485 @@
|
|
|
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 { lint } from "./diagnostics.js";
|
|
10
|
+
import { SCXML_NS } from "./events.js";
|
|
11
|
+
/** The document isn't valid SCXML. `problems` lists every problem found. */
|
|
12
|
+
export class SCXMLValidationError extends Error {
|
|
13
|
+
/** Always `"SCXML_INVALID"`. */
|
|
14
|
+
code = "SCXML_INVALID";
|
|
15
|
+
/** Every problem found, one line each (they are also listed in `message`). */
|
|
16
|
+
problems;
|
|
17
|
+
/** @param problems every problem found, one line each */
|
|
18
|
+
constructor(problems) {
|
|
19
|
+
super(`Invalid SCXML document:\n - ${problems.join("\n - ")}`);
|
|
20
|
+
this.problems = problems;
|
|
21
|
+
this.name = "SCXMLValidationError";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** SCXML text couldn't be parsed (or there is no `DOMParser` to parse it with). */
|
|
25
|
+
export class SCXMLParseError extends Error {
|
|
26
|
+
code;
|
|
27
|
+
/**
|
|
28
|
+
* @param code `SCXML_PARSE`: the text isn't well-formed XML (or has no `<scxml>` root);
|
|
29
|
+
* `SCXML_NO_DOMPARSER`: there is no `DOMParser` (outside browsers: pass `domParser`).
|
|
30
|
+
*/
|
|
31
|
+
constructor(code, message) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.code = code;
|
|
34
|
+
this.name = "SCXMLParseError";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const EXECUTABLE = new Set(["raise", "if", "elseif", "else", "foreach", "log", "assign", "script", "send", "cancel"]);
|
|
38
|
+
// ─────────────────────────────── queries ───────────────────────────────
|
|
39
|
+
/** A state without child states (or a `<final>`). */
|
|
40
|
+
export const isAtomic = (s) => s.kind === "final" || (s.kind === "state" && s.children.length === 0);
|
|
41
|
+
/** A `<state>` with child states. */
|
|
42
|
+
export const isCompound = (s) => s.kind === "state" && s.children.length > 0;
|
|
43
|
+
export const isCompoundOrRoot = (s) => s.kind === "scxml" || isCompound(s);
|
|
44
|
+
/** True when `a` is a proper descendant of `b`. */
|
|
45
|
+
export function isDescendant(a, b) {
|
|
46
|
+
for (let p = a.parent; p; p = p.parent)
|
|
47
|
+
if (p === b)
|
|
48
|
+
return true;
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
/** Ancestors of `s` up to (excluding) `upTo`; with `upTo = null`, up to and including the root. */
|
|
52
|
+
export function properAncestors(s, upTo) {
|
|
53
|
+
const out = [];
|
|
54
|
+
for (let p = s.parent; p && p !== upTo; p = p.parent)
|
|
55
|
+
out.push(p);
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
/** A comparator for `Array.sort`: document order. */
|
|
59
|
+
export const documentOrder = (a, b) => a.order - b.order;
|
|
60
|
+
export const exitOrder = (a, b) => b.order - a.order;
|
|
61
|
+
/** SCXML-namespace child elements (foreign elements are ignored everywhere). */
|
|
62
|
+
export function scxmlChildren(el, ns) {
|
|
63
|
+
return Array.from(el.children).filter((c) => c.namespaceURI === ns);
|
|
64
|
+
}
|
|
65
|
+
// ─────────────────────────────── compile ───────────────────────────────
|
|
66
|
+
/**
|
|
67
|
+
* Compile an `<scxml>` element. `src` attributes on `<script>` and `<data>`
|
|
68
|
+
* are fetched with `loader`; the result is synchronous when the loader is.
|
|
69
|
+
*/
|
|
70
|
+
export function compile(root, opts = {}) {
|
|
71
|
+
const model = build(root);
|
|
72
|
+
const pending = [];
|
|
73
|
+
for (const el of [...model.scripts, ...scriptsIn(model), ...model.allData]) {
|
|
74
|
+
const src = el.getAttribute("src");
|
|
75
|
+
if (src == null)
|
|
76
|
+
continue;
|
|
77
|
+
if (!opts.loader) {
|
|
78
|
+
model.resources.set(el, new Error(`no loader to fetch "${src}"`));
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
const r = opts.loader(src);
|
|
83
|
+
if (typeof r === "string")
|
|
84
|
+
model.resources.set(el, r);
|
|
85
|
+
else
|
|
86
|
+
pending.push(r.then((text) => void model.resources.set(el, text), (e) => void model.resources.set(el, toError(e))));
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
model.resources.set(el, toError(e));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const finish = () => {
|
|
93
|
+
// a <script src> that cannot be fetched makes the document invalid (spec §5.8)
|
|
94
|
+
const bad = [...model.resources].filter(([el, v]) => el.localName === "script" && v instanceof Error);
|
|
95
|
+
if (bad.length)
|
|
96
|
+
throw new SCXMLValidationError(bad.map(([el, v]) => `<script src="${el.getAttribute("src")}">: ${v.message}`));
|
|
97
|
+
return model;
|
|
98
|
+
};
|
|
99
|
+
return pending.length ? Promise.all(pending).then(finish) : finish();
|
|
100
|
+
}
|
|
101
|
+
function scriptsIn(model) {
|
|
102
|
+
const out = [];
|
|
103
|
+
const walk = (el) => {
|
|
104
|
+
for (const c of scxmlChildren(el, model.ns)) {
|
|
105
|
+
if (c.localName === "script" && el !== model.root.element)
|
|
106
|
+
out.push(c);
|
|
107
|
+
if (c.localName !== "content")
|
|
108
|
+
walk(c); // don't descend into inline child documents
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
walk(model.root.element);
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
function toError(e) {
|
|
115
|
+
return e instanceof Error ? e : new Error(String(e));
|
|
116
|
+
}
|
|
117
|
+
function build(rootEl) {
|
|
118
|
+
const problems = [];
|
|
119
|
+
const ns = rootEl.namespaceURI;
|
|
120
|
+
if (rootEl.localName !== "scxml")
|
|
121
|
+
throw new SCXMLValidationError([`root element is <${rootEl.localName}>, expected <scxml>`]);
|
|
122
|
+
if (ns !== SCXML_NS)
|
|
123
|
+
problems.push(`<scxml> must be in the namespace ${SCXML_NS} (found ${ns ?? "none"})`);
|
|
124
|
+
const dm = rootEl.getAttribute("datamodel");
|
|
125
|
+
// "null" (spec B.1) is a subset: its only expressions are In(), which the ECMAScript engine evaluates
|
|
126
|
+
if (dm != null && dm !== "ecmascript" && dm !== "null")
|
|
127
|
+
problems.push(`unsupported datamodel "${dm}" (supported: "ecmascript", "null")`);
|
|
128
|
+
if (dm === "null") {
|
|
129
|
+
const forbidden = ["data", "assign", "script", "foreach"];
|
|
130
|
+
for (const name of forbidden)
|
|
131
|
+
if (rootEl.getElementsByTagNameNS(SCXML_NS, name).length)
|
|
132
|
+
problems.push(`<${name}> is not available in the null data model`);
|
|
133
|
+
}
|
|
134
|
+
const binding = rootEl.getAttribute("binding") ?? "early";
|
|
135
|
+
if (binding !== "early" && binding !== "late")
|
|
136
|
+
problems.push(`invalid binding "${binding}"`);
|
|
137
|
+
let order = 0;
|
|
138
|
+
const states = [];
|
|
139
|
+
const byElement = new Map();
|
|
140
|
+
const transitionsByElement = new Map();
|
|
141
|
+
const allData = [];
|
|
142
|
+
const kids = (el) => scxmlChildren(el, ns);
|
|
143
|
+
const pendingTargets = [];
|
|
144
|
+
const makeState = (el, kind, parent) => {
|
|
145
|
+
const s = {
|
|
146
|
+
kind,
|
|
147
|
+
id: el.getAttribute("id") ?? "",
|
|
148
|
+
generatedId: false,
|
|
149
|
+
element: el,
|
|
150
|
+
parent,
|
|
151
|
+
children: [],
|
|
152
|
+
history: [],
|
|
153
|
+
order: order++,
|
|
154
|
+
depth: parent ? parent.depth + 1 : 0,
|
|
155
|
+
transitions: [],
|
|
156
|
+
onentry: [],
|
|
157
|
+
onexit: [],
|
|
158
|
+
invokes: [],
|
|
159
|
+
data: [],
|
|
160
|
+
initial: null,
|
|
161
|
+
donedata: null,
|
|
162
|
+
};
|
|
163
|
+
states.push(s);
|
|
164
|
+
byElement.set(el, s);
|
|
165
|
+
const where = () => `<${el.localName}${s.id ? ` id="${s.id}"` : ""}>`;
|
|
166
|
+
if (kind === "history") {
|
|
167
|
+
const type = el.getAttribute("type") ?? "shallow";
|
|
168
|
+
if (type !== "shallow" && type !== "deep")
|
|
169
|
+
problems.push(`${where()}: invalid history type "${type}"`);
|
|
170
|
+
s.historyType = type === "deep" ? "deep" : "shallow";
|
|
171
|
+
}
|
|
172
|
+
for (const c of kids(el)) {
|
|
173
|
+
const name = c.localName;
|
|
174
|
+
switch (name) {
|
|
175
|
+
case "state":
|
|
176
|
+
case "parallel":
|
|
177
|
+
case "final":
|
|
178
|
+
if (kind === "final" || kind === "history")
|
|
179
|
+
problems.push(`${where()} cannot contain <${name}>`);
|
|
180
|
+
s.children.push(makeState(c, name, s));
|
|
181
|
+
break;
|
|
182
|
+
case "history":
|
|
183
|
+
if (kind !== "state" && kind !== "parallel")
|
|
184
|
+
problems.push(`${where()} cannot contain <history>`);
|
|
185
|
+
s.history.push(makeState(c, "history", s));
|
|
186
|
+
break;
|
|
187
|
+
case "transition": {
|
|
188
|
+
if (kind === "final" || kind === "scxml")
|
|
189
|
+
problems.push(`${where()} cannot contain <transition>`);
|
|
190
|
+
const t = makeTransition(c, s);
|
|
191
|
+
s.transitions.push(t);
|
|
192
|
+
checkExecutable(c, `${where()} <transition>`);
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
case "initial": {
|
|
196
|
+
order++;
|
|
197
|
+
const ts = kids(c).filter((x) => x.localName === "transition");
|
|
198
|
+
if (ts.length !== 1)
|
|
199
|
+
problems.push(`${where()} <initial> must contain exactly one <transition>`);
|
|
200
|
+
if (ts[0]) {
|
|
201
|
+
const t = makeTransition(ts[0], s);
|
|
202
|
+
if (t.events.length || t.cond)
|
|
203
|
+
problems.push(`${where()} <initial> transition must not have event or cond`);
|
|
204
|
+
if (!ts[0].getAttribute("target"))
|
|
205
|
+
problems.push(`${where()} <initial> transition needs a target`);
|
|
206
|
+
if (s.initial)
|
|
207
|
+
problems.push(`${where()} has more than one initial specification`);
|
|
208
|
+
t.type = "internal"; // same object: its targets are resolved below
|
|
209
|
+
s.initial = t;
|
|
210
|
+
checkExecutable(ts[0], `${where()} <initial>`);
|
|
211
|
+
}
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
case "onentry":
|
|
215
|
+
order++;
|
|
216
|
+
s.onentry.push(c);
|
|
217
|
+
checkExecutable(c, `${where()} <onentry>`);
|
|
218
|
+
break;
|
|
219
|
+
case "onexit":
|
|
220
|
+
order++;
|
|
221
|
+
s.onexit.push(c);
|
|
222
|
+
checkExecutable(c, `${where()} <onexit>`);
|
|
223
|
+
break;
|
|
224
|
+
case "datamodel":
|
|
225
|
+
order++;
|
|
226
|
+
for (const d of kids(c)) {
|
|
227
|
+
if (d.localName !== "data") {
|
|
228
|
+
problems.push(`<datamodel> may only contain <data>, found <${d.localName}>`);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
order++;
|
|
232
|
+
if (!d.getAttribute("id"))
|
|
233
|
+
problems.push(`<data> requires an id`);
|
|
234
|
+
const sources = ["expr", "src"].filter((a) => d.hasAttribute(a)).length + (hasContent(d) ? 1 : 0);
|
|
235
|
+
if (sources > 1)
|
|
236
|
+
problems.push(`<data id="${d.getAttribute("id")}"> may have only one of expr, src, or content`);
|
|
237
|
+
s.data.push(d);
|
|
238
|
+
allData.push(d);
|
|
239
|
+
}
|
|
240
|
+
break;
|
|
241
|
+
case "invoke":
|
|
242
|
+
if (kind === "scxml" || kind === "final" || kind === "history")
|
|
243
|
+
problems.push(`${where()} cannot contain <invoke>`);
|
|
244
|
+
s.invokes.push(makeInvoke(c, s));
|
|
245
|
+
break;
|
|
246
|
+
case "donedata":
|
|
247
|
+
if (kind !== "final")
|
|
248
|
+
problems.push(`<donedata> is only allowed in <final>`);
|
|
249
|
+
s.donedata = c;
|
|
250
|
+
break;
|
|
251
|
+
case "script":
|
|
252
|
+
if (kind !== "scxml")
|
|
253
|
+
problems.push(`${where()}: <script> directly inside a state is not allowed`);
|
|
254
|
+
checkScript(c);
|
|
255
|
+
order++;
|
|
256
|
+
break;
|
|
257
|
+
default:
|
|
258
|
+
problems.push(`${where()}: unexpected <${name}>`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (kind === "state" && s.children.length === 0 && el.hasAttribute("initial"))
|
|
262
|
+
problems.push(`${where()}: atomic state cannot have an initial attribute`);
|
|
263
|
+
if (kind === "state" && el.hasAttribute("initial") && s.initial)
|
|
264
|
+
problems.push(`${where()}: has both an initial attribute and an <initial> element`);
|
|
265
|
+
if (kind === "history") {
|
|
266
|
+
if (s.transitions.length > 1)
|
|
267
|
+
problems.push(`${where()} must have at most one <transition>`);
|
|
268
|
+
const t = s.transitions[0];
|
|
269
|
+
if (t && (t.events.length || t.cond))
|
|
270
|
+
problems.push(`${where()} default transition must not have event or cond`);
|
|
271
|
+
}
|
|
272
|
+
return s;
|
|
273
|
+
};
|
|
274
|
+
const makeTransition = (el, source) => {
|
|
275
|
+
const t = {
|
|
276
|
+
element: el,
|
|
277
|
+
source,
|
|
278
|
+
events: (el.getAttribute("event") ?? "").split(/\s+/).filter(Boolean),
|
|
279
|
+
cond: el.getAttribute("cond"),
|
|
280
|
+
targets: [],
|
|
281
|
+
type: el.getAttribute("type") === "internal" ? "internal" : "external",
|
|
282
|
+
order: order++,
|
|
283
|
+
};
|
|
284
|
+
const type = el.getAttribute("type");
|
|
285
|
+
if (type != null && type !== "internal" && type !== "external")
|
|
286
|
+
problems.push(`<transition> has invalid type "${type}"`);
|
|
287
|
+
if (!el.hasAttribute("event") && !el.hasAttribute("cond") && !el.hasAttribute("target") && source.kind !== "history")
|
|
288
|
+
problems.push(`<transition> in "${source.id}" needs at least one of event, cond, or target`);
|
|
289
|
+
const target = el.getAttribute("target");
|
|
290
|
+
if (target != null)
|
|
291
|
+
pendingTargets.push({ t, attr: target, where: `transition in "${source.id || "(anonymous)"}"` });
|
|
292
|
+
transitionsByElement.set(el, t);
|
|
293
|
+
return t;
|
|
294
|
+
};
|
|
295
|
+
const makeInvoke = (el, state) => {
|
|
296
|
+
const o = order++;
|
|
297
|
+
const exclusive = (a, b) => {
|
|
298
|
+
if (el.hasAttribute(a) && el.hasAttribute(b))
|
|
299
|
+
problems.push(`<invoke> may not have both ${a} and ${b}`);
|
|
300
|
+
};
|
|
301
|
+
exclusive("type", "typeexpr");
|
|
302
|
+
exclusive("src", "srcexpr");
|
|
303
|
+
exclusive("id", "idlocation");
|
|
304
|
+
const content = kids(el).filter((c) => c.localName === "content");
|
|
305
|
+
if (content.length > 1)
|
|
306
|
+
problems.push(`<invoke> may contain at most one <content>`);
|
|
307
|
+
if (content.length && (el.hasAttribute("src") || el.hasAttribute("srcexpr")))
|
|
308
|
+
problems.push(`<invoke> may not have both src and <content>`);
|
|
309
|
+
const params = kids(el).filter((c) => c.localName === "param");
|
|
310
|
+
if (params.length && el.hasAttribute("namelist"))
|
|
311
|
+
problems.push(`<invoke> may not have both namelist and <param>`);
|
|
312
|
+
const finalize = kids(el).find((c) => c.localName === "finalize") ?? null;
|
|
313
|
+
if (finalize)
|
|
314
|
+
checkExecutable(finalize, "<finalize>");
|
|
315
|
+
return { element: el, state, order: o, autoforward: el.getAttribute("autoforward") === "true", finalize };
|
|
316
|
+
};
|
|
317
|
+
const checkScript = (el) => {
|
|
318
|
+
if (el.hasAttribute("src") && (el.textContent ?? "").trim())
|
|
319
|
+
problems.push(`<script> may not have both src and content`);
|
|
320
|
+
};
|
|
321
|
+
const checkExecutable = (block, where) => {
|
|
322
|
+
for (const c of kids(block)) {
|
|
323
|
+
const n = c.localName;
|
|
324
|
+
// the <initial>/<finalize>/<transition> containers hold executable content directly
|
|
325
|
+
if (!EXECUTABLE.has(n)) {
|
|
326
|
+
problems.push(`${where}: <${n}> is not executable content`);
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
order++;
|
|
330
|
+
if ((n === "elseif" || n === "else") && block.localName !== "if")
|
|
331
|
+
problems.push(`${where}: <${n}> outside <if>`);
|
|
332
|
+
if ((n === "if" || n === "elseif") && !c.hasAttribute("cond"))
|
|
333
|
+
problems.push(`${where}: <${n}> requires cond`);
|
|
334
|
+
if (n === "raise" && !c.getAttribute("event"))
|
|
335
|
+
problems.push(`${where}: <raise> requires event`);
|
|
336
|
+
if (n === "assign" && !c.getAttribute("location"))
|
|
337
|
+
problems.push(`${where}: <assign> requires location`);
|
|
338
|
+
if (n === "foreach" && (!c.hasAttribute("array") || !c.hasAttribute("item")))
|
|
339
|
+
problems.push(`${where}: <foreach> requires array and item`);
|
|
340
|
+
if (n === "script")
|
|
341
|
+
checkScript(c);
|
|
342
|
+
if (n === "send") {
|
|
343
|
+
for (const [a, b] of [
|
|
344
|
+
["event", "eventexpr"],
|
|
345
|
+
["target", "targetexpr"],
|
|
346
|
+
["type", "typeexpr"],
|
|
347
|
+
["id", "idlocation"],
|
|
348
|
+
["delay", "delayexpr"],
|
|
349
|
+
])
|
|
350
|
+
if (c.hasAttribute(a) && c.hasAttribute(b))
|
|
351
|
+
problems.push(`${where}: <send> may not have both ${a} and ${b}`);
|
|
352
|
+
const hasContentEl = kids(c).some((x) => x.localName === "content");
|
|
353
|
+
if (hasContentEl && (c.hasAttribute("namelist") || kids(c).some((x) => x.localName === "param")))
|
|
354
|
+
problems.push(`${where}: <send> may not combine <content> with namelist or <param>`);
|
|
355
|
+
if (hasContentEl && !c.hasAttribute("event") && !c.hasAttribute("eventexpr")) {
|
|
356
|
+
/* allowed: content-only sends to external processors */
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
if (n === "cancel" && !c.hasAttribute("sendid") && !c.hasAttribute("sendidexpr"))
|
|
360
|
+
problems.push(`${where}: <cancel> requires sendid or sendidexpr`);
|
|
361
|
+
if (n === "if" || n === "foreach")
|
|
362
|
+
checkExecutable(c, where);
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
const root = makeState(rootEl, "scxml", null);
|
|
366
|
+
// ids: explicit ones must be unique; missing ones are generated
|
|
367
|
+
const byId = new Map();
|
|
368
|
+
for (const s of states) {
|
|
369
|
+
if (!s.id)
|
|
370
|
+
continue;
|
|
371
|
+
if (byId.has(s.id))
|
|
372
|
+
problems.push(`duplicate id "${s.id}"`);
|
|
373
|
+
byId.set(s.id, s);
|
|
374
|
+
}
|
|
375
|
+
let gen = 0;
|
|
376
|
+
for (const s of states) {
|
|
377
|
+
if (s.id || s.kind === "scxml")
|
|
378
|
+
continue;
|
|
379
|
+
let id;
|
|
380
|
+
do
|
|
381
|
+
id = `__${s.kind}${++gen}`;
|
|
382
|
+
while (byId.has(id));
|
|
383
|
+
s.id = id;
|
|
384
|
+
s.generatedId = true;
|
|
385
|
+
byId.set(id, s);
|
|
386
|
+
}
|
|
387
|
+
const resolve = (ids, where) => ids
|
|
388
|
+
.split(/\s+/)
|
|
389
|
+
.filter(Boolean)
|
|
390
|
+
.flatMap((id) => {
|
|
391
|
+
const s = byId.get(id);
|
|
392
|
+
if (!s || s.kind === "scxml") {
|
|
393
|
+
problems.push(`${where}: unknown target "${id}"`);
|
|
394
|
+
return [];
|
|
395
|
+
}
|
|
396
|
+
return [s];
|
|
397
|
+
});
|
|
398
|
+
for (const { t, attr, where } of pendingTargets)
|
|
399
|
+
t.targets = resolve(attr, where);
|
|
400
|
+
// initial transitions
|
|
401
|
+
for (const s of states) {
|
|
402
|
+
if (!(s.kind === "scxml" || isCompound(s)))
|
|
403
|
+
continue;
|
|
404
|
+
const attr = s.element.getAttribute("initial");
|
|
405
|
+
if (attr != null) {
|
|
406
|
+
s.initial = {
|
|
407
|
+
element: null,
|
|
408
|
+
source: s,
|
|
409
|
+
events: [],
|
|
410
|
+
cond: null,
|
|
411
|
+
targets: resolve(attr, `initial of "${s.id || "scxml"}"`),
|
|
412
|
+
type: "internal",
|
|
413
|
+
order: s.order,
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
else if (!s.initial) {
|
|
417
|
+
const first = s.children[0];
|
|
418
|
+
s.initial = { element: null, source: s, events: [], cond: null, targets: first ? [first] : [], type: "internal", order: s.order };
|
|
419
|
+
}
|
|
420
|
+
for (const t of s.initial.targets)
|
|
421
|
+
if (!isDescendant(t, s))
|
|
422
|
+
problems.push(`initial target "${t.id}" is not a descendant of "${s.id || "scxml"}"`);
|
|
423
|
+
checkLegalTargets(s.initial.targets, `initial of "${s.id || "scxml"}"`);
|
|
424
|
+
}
|
|
425
|
+
if (root.children.length === 0)
|
|
426
|
+
problems.push(`<scxml> has no states`);
|
|
427
|
+
// history default transitions
|
|
428
|
+
for (const h of states.filter((s) => s.kind === "history")) {
|
|
429
|
+
const t = h.transitions[0];
|
|
430
|
+
if (!t) {
|
|
431
|
+
problems.push(`history "${h.id}" needs a default <transition>`);
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
if (!t.targets.length)
|
|
435
|
+
problems.push(`history "${h.id}" default transition needs a target`);
|
|
436
|
+
for (const target of t.targets) {
|
|
437
|
+
const ok = h.historyType === "deep" ? isDescendant(target, h.parent) : target.parent === h.parent && target.kind !== "history";
|
|
438
|
+
if (!ok)
|
|
439
|
+
problems.push(`history "${h.id}" default target "${target.id}" is not a ${h.historyType === "deep" ? "descendant" : "child"} of its parent`);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
for (const s of states)
|
|
443
|
+
for (const t of s.transitions)
|
|
444
|
+
checkLegalTargets(t.targets, `transition in "${s.id}"`);
|
|
445
|
+
function checkLegalTargets(ts, where) {
|
|
446
|
+
// no target may be an ancestor of another, and at most one target per compound state (spec §3.11)
|
|
447
|
+
for (const a of ts)
|
|
448
|
+
for (const b of ts) {
|
|
449
|
+
if (a === b)
|
|
450
|
+
continue;
|
|
451
|
+
if (isDescendant(a, b))
|
|
452
|
+
problems.push(`${where}: targets "${b.id}" and "${a.id}" are nested`);
|
|
453
|
+
else if (a.order < b.order) {
|
|
454
|
+
let lca = a.parent;
|
|
455
|
+
while (lca && !isDescendant(b, lca))
|
|
456
|
+
lca = lca.parent;
|
|
457
|
+
if (lca && lca.kind !== "parallel")
|
|
458
|
+
problems.push(`${where}: targets "${a.id}" and "${b.id}" cannot be active together`);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
const scripts = kids(rootEl).filter((c) => c.localName === "script");
|
|
463
|
+
if (problems.length)
|
|
464
|
+
throw new SCXMLValidationError(problems);
|
|
465
|
+
const model = {
|
|
466
|
+
ns,
|
|
467
|
+
root,
|
|
468
|
+
states,
|
|
469
|
+
byId,
|
|
470
|
+
byElement,
|
|
471
|
+
transitionsByElement,
|
|
472
|
+
name: rootEl.getAttribute("name") ?? "",
|
|
473
|
+
binding: binding === "late" ? "late" : "early",
|
|
474
|
+
scripts,
|
|
475
|
+
allData,
|
|
476
|
+
resources: new Map(),
|
|
477
|
+
warnings: [],
|
|
478
|
+
};
|
|
479
|
+
model.warnings = lint(model);
|
|
480
|
+
return model;
|
|
481
|
+
}
|
|
482
|
+
function hasContent(el) {
|
|
483
|
+
return el.children.length > 0 || (el.textContent ?? "").trim().length > 0;
|
|
484
|
+
}
|
|
485
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAmB,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AA0GvC,4EAA4E;AAC5E,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,gCAAgC;IACvB,IAAI,GAAG,eAAwB,CAAC;IACzC,8EAA8E;IACrE,QAAQ,CAAW;IAC5B,yDAAyD;IACzD,YAAY,QAAkB;QAC5B,KAAK,CAAC,gCAAgC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACjE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAED,mFAAmF;AACnF,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAM7B,IAAI;IALf;;;OAGG;IACH,YACW,IAA0C,EACnD,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;oBAHN,IAAI;QAIb,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAA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,OAAO;QACP,SAAS,EAAE,IAAI,GAAG,EAAE;QACpB,QAAQ,EAAE,EAAE;KACb,CAAC;IACF,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7B,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,UAAU,CAAC,EAAW;IAC7B,OAAO,EAAE,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["/**\n * Compiles an `<scxml>` DOM element into an immutable, validated model.\n *\n * The model keeps a reference to every source element, so renderers can map\n * live state back onto the document. Validation follows the constraints of\n * spec §3 (ids, targets, initial states, history, executable content);\n * a non-conformant document raises `SCXMLValidationError` listing every problem.\n */\nimport { type Diagnostic, lint } from \"./diagnostics.ts\";\nimport { SCXML_NS } from \"./events.ts\";\n\n/** The element a state node was compiled from (`scxml` is the root). */\nexport type StateKind = \"scxml\" | \"state\" | \"parallel\" | \"final\" | \"history\";\n\n/**\n * A state of a compiled chart. Every node keeps its source `element`, so\n * renderers can map live state back onto the document.\n */\nexport interface StateNode {\n /** Which element it is. */\n kind: StateKind;\n /** The `id` attribute, or a generated one (see `generatedId`). */\n id: string;\n /** True when the author omitted `id` and one was generated (spec §3.14). */\n generatedId: boolean;\n /** The source element (`<state>`, `<parallel>`, …). */\n element: Element;\n /** The containing state; `null` for the root. */\n parent: StateNode | null;\n /** `<state>`, `<parallel>` and `<final>` children — spec `getChildStates`. */\n children: StateNode[];\n /** `<history>` children. */\n history: StateNode[];\n /** Document order. */\n order: number;\n /** Nesting depth: the root is 0. */\n depth: number;\n /** Its `<transition>`s, in document order. */\n transitions: TransitionNode[];\n /** Each `<onentry>` / `<onexit>` element is a separate executable block. */\n onentry: Element[];\n /** The `<onexit>` blocks, in document order. */\n onexit: Element[];\n /** Its `<invoke>`s, in document order. */\n invokes: InvokeNode[];\n /** `<data>` elements of this state's own `<datamodel>`. */\n data: Element[];\n /** Initial transition, for compound states and `<scxml>`. */\n initial: TransitionNode | null;\n /** For `<history>` nodes: whether it remembers only direct children (`shallow`) or the full descendant configuration (`deep`). */\n historyType?: \"shallow\" | \"deep\";\n /** For `<final>` states: the `<donedata>` element, if any. */\n donedata: Element | null;\n}\n\n/** A transition of a compiled chart. */\nexport interface TransitionNode {\n /** `null` for initial transitions synthesised from an `initial` attribute or default. */\n element: Element | null;\n /** The state it belongs to. */\n source: StateNode;\n /** The event descriptors of the `event` attribute (empty for eventless transitions). */\n events: string[];\n /** The `cond` expression, or `null`. */\n cond: string | null;\n /** The targets (empty for targetless transitions). */\n targets: StateNode[];\n /** The `type` attribute: `internal` doesn't exit its source state when the targets are its descendants. */\n type: \"internal\" | \"external\";\n /** Document order. */\n order: number;\n}\n\n/** An `<invoke>` of a compiled chart. */\nexport interface InvokeNode {\n /** The `<invoke>` element. */\n element: Element;\n /** The state it belongs to (invoked while that state is active). */\n state: StateNode;\n /** Document order. */\n order: number;\n /** The `autoforward` attribute: external events are forwarded to the invoked service. */\n autoforward: boolean;\n /** The `<finalize>` element, if any. */\n finalize: Element | null;\n}\n\n/** A compiled, validated chart. Sessions only read it, so one model can serve many sessions. */\nexport interface Model {\n /** The SCXML namespace the document uses. */\n ns: string | null;\n /** The `<scxml>` element's node. */\n root: StateNode;\n /** All states (including history and the root) in document order. */\n states: StateNode[];\n /** States by id (generated ids included). */\n byId: Map<string, StateNode>;\n /** States by source element. */\n byElement: Map<Element, StateNode>;\n /** Transitions by source `<transition>` element. */\n transitionsByElement: Map<Element, TransitionNode>;\n /** The `<scxml name>` attribute (`\"\"` when absent). */\n name: string;\n /** The `binding` attribute: when `<data>` is initialised. */\n binding: \"early\" | \"late\";\n /** `<script>` children of `<scxml>`. */\n scripts: Element[];\n /** Every `<data>` element, document order. */\n allData: Element[];\n /** Pre-loaded `src` contents for `<script src>` and `<data src>` (value: text, or an Error). */\n resources: Map<Element, string | Error>;\n /** Likely mistakes that are still valid SCXML (see `Diagnostic`); empty for most charts. */\n warnings: Diagnostic[];\n}\n\n/** The document isn't valid SCXML. `problems` lists every problem found. */\nexport class SCXMLValidationError extends Error {\n /** Always `\"SCXML_INVALID\"`. */\n readonly code = \"SCXML_INVALID\" as const;\n /** Every problem found, one line each (they are also listed in `message`). */\n readonly problems: string[];\n /** @param problems every problem found, one line each */\n constructor(problems: string[]) {\n super(`Invalid SCXML document:\\n - ${problems.join(\"\\n - \")}`);\n this.problems = problems;\n this.name = \"SCXMLValidationError\";\n }\n}\n\n/** SCXML text couldn't be parsed (or there is no `DOMParser` to parse it with). */\nexport class SCXMLParseError extends Error {\n /**\n * @param code `SCXML_PARSE`: the text isn't well-formed XML (or has no `<scxml>` root);\n * `SCXML_NO_DOMPARSER`: there is no `DOMParser` (outside browsers: pass `domParser`).\n */\n constructor(\n readonly code: \"SCXML_PARSE\" | \"SCXML_NO_DOMPARSER\",\n message: string,\n ) {\n super(message);\n this.name = \"SCXMLParseError\";\n }\n}\n\n/** Resolves `src` attributes (`<script>`, `<data>`, `<invoke>`) to their text; may be synchronous. */\nexport type Loader = (src: string) => string | Promise<string>;\n\nconst EXECUTABLE = new Set([\"raise\", \"if\", \"elseif\", \"else\", \"foreach\", \"log\", \"assign\", \"script\", \"send\", \"cancel\"]);\n\n// ─────────────────────────────── queries ───────────────────────────────\n\n/** A state without child states (or a `<final>`). */\nexport const isAtomic = (s: StateNode) => s.kind === \"final\" || (s.kind === \"state\" && s.children.length === 0);\n/** A `<state>` with child states. */\nexport const isCompound = (s: StateNode) => s.kind === \"state\" && s.children.length > 0;\nexport const isCompoundOrRoot = (s: StateNode) => s.kind === \"scxml\" || isCompound(s);\n\n/** True when `a` is a proper descendant of `b`. */\nexport function isDescendant(a: StateNode, b: StateNode): boolean {\n for (let p = a.parent; p; p = p.parent) if (p === b) return true;\n return false;\n}\n\n/** Ancestors of `s` up to (excluding) `upTo`; with `upTo = null`, up to and including the root. */\nexport function properAncestors(s: StateNode, upTo: StateNode | null): StateNode[] {\n const out: StateNode[] = [];\n for (let p = s.parent; p && p !== upTo; p = p.parent) out.push(p);\n return out;\n}\n\n/** A comparator for `Array.sort`: document order. */\nexport const documentOrder = (a: { order: number }, b: { order: number }) => a.order - b.order;\nexport const exitOrder = (a: { order: number }, b: { order: number }) => b.order - a.order;\n\n/** SCXML-namespace child elements (foreign elements are ignored everywhere). */\nexport function scxmlChildren(el: Element, ns: string | null): Element[] {\n return Array.from(el.children).filter((c) => c.namespaceURI === ns);\n}\n\n// ─────────────────────────────── compile ───────────────────────────────\n\n/**\n * Compile an `<scxml>` element. `src` attributes on `<script>` and `<data>`\n * are fetched with `loader`; the result is synchronous when the loader is.\n */\nexport function compile(root: Element, opts: { loader?: Loader } = {}): Model | Promise<Model> {\n const model = build(root);\n const pending: Promise<void>[] = [];\n for (const el of [...model.scripts, ...scriptsIn(model), ...model.allData]) {\n const src = el.getAttribute(\"src\");\n if (src == null) continue;\n if (!opts.loader) {\n model.resources.set(el, new Error(`no loader to fetch \"${src}\"`));\n continue;\n }\n try {\n const r = opts.loader(src);\n if (typeof r === \"string\") model.resources.set(el, r);\n else\n pending.push(\n r.then(\n (text) => void model.resources.set(el, text),\n (e) => void model.resources.set(el, toError(e)),\n ),\n );\n } catch (e) {\n model.resources.set(el, toError(e));\n }\n }\n const finish = () => {\n // a <script src> that cannot be fetched makes the document invalid (spec §5.8)\n const bad = [...model.resources].filter(([el, v]) => el.localName === \"script\" && v instanceof Error);\n if (bad.length)\n throw new SCXMLValidationError(bad.map(([el, v]) => `<script src=\"${el.getAttribute(\"src\")}\">: ${(v as Error).message}`));\n return model;\n };\n return pending.length ? Promise.all(pending).then(finish) : finish();\n}\n\nfunction scriptsIn(model: Model): Element[] {\n const out: Element[] = [];\n const walk = (el: Element) => {\n for (const c of scxmlChildren(el, model.ns)) {\n if (c.localName === \"script\" && el !== model.root.element) out.push(c);\n if (c.localName !== \"content\") walk(c); // don't descend into inline child documents\n }\n };\n walk(model.root.element);\n return out;\n}\n\nfunction toError(e: unknown) {\n return e instanceof Error ? e : new Error(String(e));\n}\n\nfunction build(rootEl: Element): Model {\n const problems: string[] = [];\n const ns = rootEl.namespaceURI;\n if (rootEl.localName !== \"scxml\") throw new SCXMLValidationError([`root element is <${rootEl.localName}>, expected <scxml>`]);\n if (ns !== SCXML_NS) problems.push(`<scxml> must be in the namespace ${SCXML_NS} (found ${ns ?? \"none\"})`);\n const dm = rootEl.getAttribute(\"datamodel\");\n // \"null\" (spec B.1) is a subset: its only expressions are In(), which the ECMAScript engine evaluates\n if (dm != null && dm !== \"ecmascript\" && dm !== \"null\") problems.push(`unsupported datamodel \"${dm}\" (supported: \"ecmascript\", \"null\")`);\n if (dm === \"null\") {\n const forbidden = [\"data\", \"assign\", \"script\", \"foreach\"];\n for (const name of forbidden)\n if (rootEl.getElementsByTagNameNS(SCXML_NS, name).length) problems.push(`<${name}> is not available in the null data model`);\n }\n const binding = rootEl.getAttribute(\"binding\") ?? \"early\";\n if (binding !== \"early\" && binding !== \"late\") problems.push(`invalid binding \"${binding}\"`);\n\n let order = 0;\n const states: StateNode[] = [];\n const byElement = new Map<Element, StateNode>();\n const transitionsByElement = new Map<Element, TransitionNode>();\n const allData: Element[] = [];\n const kids = (el: Element) => scxmlChildren(el, ns);\n const pendingTargets: { t: TransitionNode; attr: string; where: string }[] = [];\n\n const makeState = (el: Element, kind: StateKind, parent: StateNode | null): StateNode => {\n const s: StateNode = {\n kind,\n id: el.getAttribute(\"id\") ?? \"\",\n generatedId: false,\n element: el,\n parent,\n children: [],\n history: [],\n order: order++,\n depth: parent ? parent.depth + 1 : 0,\n transitions: [],\n onentry: [],\n onexit: [],\n invokes: [],\n data: [],\n initial: null,\n donedata: null,\n };\n states.push(s);\n byElement.set(el, s);\n const where = () => `<${el.localName}${s.id ? ` id=\"${s.id}\"` : \"\"}>`;\n\n if (kind === \"history\") {\n const type = el.getAttribute(\"type\") ?? \"shallow\";\n if (type !== \"shallow\" && type !== \"deep\") problems.push(`${where()}: invalid history type \"${type}\"`);\n s.historyType = type === \"deep\" ? \"deep\" : \"shallow\";\n }\n\n for (const c of kids(el)) {\n const name = c.localName;\n switch (name) {\n case \"state\":\n case \"parallel\":\n case \"final\":\n if (kind === \"final\" || kind === \"history\") problems.push(`${where()} cannot contain <${name}>`);\n s.children.push(makeState(c, name, s));\n break;\n case \"history\":\n if (kind !== \"state\" && kind !== \"parallel\") problems.push(`${where()} cannot contain <history>`);\n s.history.push(makeState(c, \"history\", s));\n break;\n case \"transition\": {\n if (kind === \"final\" || kind === \"scxml\") problems.push(`${where()} cannot contain <transition>`);\n const t = makeTransition(c, s);\n s.transitions.push(t);\n checkExecutable(c, `${where()} <transition>`);\n break;\n }\n case \"initial\": {\n order++;\n const ts = kids(c).filter((x) => x.localName === \"transition\");\n if (ts.length !== 1) problems.push(`${where()} <initial> must contain exactly one <transition>`);\n if (ts[0]) {\n const t = makeTransition(ts[0], s);\n if (t.events.length || t.cond) problems.push(`${where()} <initial> transition must not have event or cond`);\n if (!ts[0].getAttribute(\"target\")) problems.push(`${where()} <initial> transition needs a target`);\n if (s.initial) problems.push(`${where()} has more than one initial specification`);\n t.type = \"internal\"; // same object: its targets are resolved below\n s.initial = t;\n checkExecutable(ts[0], `${where()} <initial>`);\n }\n break;\n }\n case \"onentry\":\n order++;\n s.onentry.push(c);\n checkExecutable(c, `${where()} <onentry>`);\n break;\n case \"onexit\":\n order++;\n s.onexit.push(c);\n checkExecutable(c, `${where()} <onexit>`);\n break;\n case \"datamodel\":\n order++;\n for (const d of kids(c)) {\n if (d.localName !== \"data\") {\n problems.push(`<datamodel> may only contain <data>, found <${d.localName}>`);\n continue;\n }\n order++;\n if (!d.getAttribute(\"id\")) problems.push(`<data> requires an id`);\n const sources = [\"expr\", \"src\"].filter((a) => d.hasAttribute(a)).length + (hasContent(d) ? 1 : 0);\n if (sources > 1) problems.push(`<data id=\"${d.getAttribute(\"id\")}\"> may have only one of expr, src, or content`);\n s.data.push(d);\n allData.push(d);\n }\n break;\n case \"invoke\":\n if (kind === \"scxml\" || kind === \"final\" || kind === \"history\") problems.push(`${where()} cannot contain <invoke>`);\n s.invokes.push(makeInvoke(c, s));\n break;\n case \"donedata\":\n if (kind !== \"final\") problems.push(`<donedata> is only allowed in <final>`);\n s.donedata = c;\n break;\n case \"script\":\n if (kind !== \"scxml\") problems.push(`${where()}: <script> directly inside a state is not allowed`);\n checkScript(c);\n order++;\n break;\n default:\n problems.push(`${where()}: unexpected <${name}>`);\n }\n }\n if (kind === \"state\" && s.children.length === 0 && el.hasAttribute(\"initial\"))\n problems.push(`${where()}: atomic state cannot have an initial attribute`);\n if (kind === \"state\" && el.hasAttribute(\"initial\") && s.initial)\n problems.push(`${where()}: has both an initial attribute and an <initial> element`);\n if (kind === \"history\") {\n if (s.transitions.length > 1) problems.push(`${where()} must have at most one <transition>`);\n const t = s.transitions[0];\n if (t && (t.events.length || t.cond)) problems.push(`${where()} default transition must not have event or cond`);\n }\n return s;\n };\n\n const makeTransition = (el: Element, source: StateNode): TransitionNode => {\n const t: TransitionNode = {\n element: el,\n source,\n events: (el.getAttribute(\"event\") ?? \"\").split(/\\s+/).filter(Boolean),\n cond: el.getAttribute(\"cond\"),\n targets: [],\n type: el.getAttribute(\"type\") === \"internal\" ? \"internal\" : \"external\",\n order: order++,\n };\n const type = el.getAttribute(\"type\");\n if (type != null && type !== \"internal\" && type !== \"external\") problems.push(`<transition> has invalid type \"${type}\"`);\n if (!el.hasAttribute(\"event\") && !el.hasAttribute(\"cond\") && !el.hasAttribute(\"target\") && source.kind !== \"history\")\n problems.push(`<transition> in \"${source.id}\" needs at least one of event, cond, or target`);\n const target = el.getAttribute(\"target\");\n if (target != null) pendingTargets.push({ t, attr: target, where: `transition in \"${source.id || \"(anonymous)\"}\"` });\n transitionsByElement.set(el, t);\n return t;\n };\n\n const makeInvoke = (el: Element, state: StateNode): InvokeNode => {\n const o = order++;\n const exclusive = (a: string, b: string) => {\n if (el.hasAttribute(a) && el.hasAttribute(b)) problems.push(`<invoke> may not have both ${a} and ${b}`);\n };\n exclusive(\"type\", \"typeexpr\");\n exclusive(\"src\", \"srcexpr\");\n exclusive(\"id\", \"idlocation\");\n const content = kids(el).filter((c) => c.localName === \"content\");\n if (content.length > 1) problems.push(`<invoke> may contain at most one <content>`);\n if (content.length && (el.hasAttribute(\"src\") || el.hasAttribute(\"srcexpr\")))\n problems.push(`<invoke> may not have both src and <content>`);\n const params = kids(el).filter((c) => c.localName === \"param\");\n if (params.length && el.hasAttribute(\"namelist\")) problems.push(`<invoke> may not have both namelist and <param>`);\n const finalize = kids(el).find((c) => c.localName === \"finalize\") ?? null;\n if (finalize) checkExecutable(finalize, \"<finalize>\");\n return { element: el, state, order: o, autoforward: el.getAttribute(\"autoforward\") === \"true\", finalize };\n };\n\n const checkScript = (el: Element) => {\n if (el.hasAttribute(\"src\") && (el.textContent ?? \"\").trim()) problems.push(`<script> may not have both src and content`);\n };\n\n const checkExecutable = (block: Element, where: string) => {\n for (const c of kids(block)) {\n const n = c.localName;\n // the <initial>/<finalize>/<transition> containers hold executable content directly\n if (!EXECUTABLE.has(n)) {\n problems.push(`${where}: <${n}> is not executable content`);\n continue;\n }\n order++;\n if ((n === \"elseif\" || n === \"else\") && block.localName !== \"if\") problems.push(`${where}: <${n}> outside <if>`);\n if ((n === \"if\" || n === \"elseif\") && !c.hasAttribute(\"cond\")) problems.push(`${where}: <${n}> requires cond`);\n if (n === \"raise\" && !c.getAttribute(\"event\")) problems.push(`${where}: <raise> requires event`);\n if (n === \"assign\" && !c.getAttribute(\"location\")) problems.push(`${where}: <assign> requires location`);\n if (n === \"foreach\" && (!c.hasAttribute(\"array\") || !c.hasAttribute(\"item\")))\n problems.push(`${where}: <foreach> requires array and item`);\n if (n === \"script\") checkScript(c);\n if (n === \"send\") {\n for (const [a, b] of [\n [\"event\", \"eventexpr\"],\n [\"target\", \"targetexpr\"],\n [\"type\", \"typeexpr\"],\n [\"id\", \"idlocation\"],\n [\"delay\", \"delayexpr\"],\n ])\n if (c.hasAttribute(a!) && c.hasAttribute(b!)) problems.push(`${where}: <send> may not have both ${a} and ${b}`);\n const hasContentEl = kids(c).some((x) => x.localName === \"content\");\n if (hasContentEl && (c.hasAttribute(\"namelist\") || kids(c).some((x) => x.localName === \"param\")))\n problems.push(`${where}: <send> may not combine <content> with namelist or <param>`);\n if (hasContentEl && !c.hasAttribute(\"event\") && !c.hasAttribute(\"eventexpr\")) {\n /* allowed: content-only sends to external processors */\n }\n }\n if (n === \"cancel\" && !c.hasAttribute(\"sendid\") && !c.hasAttribute(\"sendidexpr\"))\n problems.push(`${where}: <cancel> requires sendid or sendidexpr`);\n if (n === \"if\" || n === \"foreach\") checkExecutable(c, where);\n }\n };\n\n const root = makeState(rootEl, \"scxml\", null);\n\n // ids: explicit ones must be unique; missing ones are generated\n const byId = new Map<string, StateNode>();\n for (const s of states) {\n if (!s.id) continue;\n if (byId.has(s.id)) problems.push(`duplicate id \"${s.id}\"`);\n byId.set(s.id, s);\n }\n let gen = 0;\n for (const s of states) {\n if (s.id || s.kind === \"scxml\") continue;\n let id: string;\n do id = `__${s.kind}${++gen}`;\n while (byId.has(id));\n s.id = id;\n s.generatedId = true;\n byId.set(id, s);\n }\n\n const resolve = (ids: string, where: string): StateNode[] =>\n ids\n .split(/\\s+/)\n .filter(Boolean)\n .flatMap((id) => {\n const s = byId.get(id);\n if (!s || s.kind === \"scxml\") {\n problems.push(`${where}: unknown target \"${id}\"`);\n return [];\n }\n return [s];\n });\n\n for (const { t, attr, where } of pendingTargets) t.targets = resolve(attr, where);\n\n // initial transitions\n for (const s of states) {\n if (!(s.kind === \"scxml\" || isCompound(s))) continue;\n const attr = s.element.getAttribute(\"initial\");\n if (attr != null) {\n s.initial = {\n element: null,\n source: s,\n events: [],\n cond: null,\n targets: resolve(attr, `initial of \"${s.id || \"scxml\"}\"`),\n type: \"internal\",\n order: s.order,\n };\n } else if (!s.initial) {\n const first = s.children[0];\n s.initial = { element: null, source: s, events: [], cond: null, targets: first ? [first] : [], type: \"internal\", order: s.order };\n }\n for (const t of s.initial.targets)\n if (!isDescendant(t, s)) problems.push(`initial target \"${t.id}\" is not a descendant of \"${s.id || \"scxml\"}\"`);\n checkLegalTargets(s.initial.targets, `initial of \"${s.id || \"scxml\"}\"`);\n }\n if (root.children.length === 0) problems.push(`<scxml> has no states`);\n\n // history default transitions\n for (const h of states.filter((s) => s.kind === \"history\")) {\n const t = h.transitions[0];\n if (!t) {\n problems.push(`history \"${h.id}\" needs a default <transition>`);\n continue;\n }\n if (!t.targets.length) problems.push(`history \"${h.id}\" default transition needs a target`);\n for (const target of t.targets) {\n const ok = h.historyType === \"deep\" ? isDescendant(target, h.parent!) : target.parent === h.parent && target.kind !== \"history\";\n if (!ok)\n problems.push(\n `history \"${h.id}\" default target \"${target.id}\" is not a ${h.historyType === \"deep\" ? \"descendant\" : \"child\"} of its parent`,\n );\n }\n }\n for (const s of states) for (const t of s.transitions) checkLegalTargets(t.targets, `transition in \"${s.id}\"`);\n\n function checkLegalTargets(ts: StateNode[], where: string) {\n // no target may be an ancestor of another, and at most one target per compound state (spec §3.11)\n for (const a of ts)\n for (const b of ts) {\n if (a === b) continue;\n if (isDescendant(a, b)) problems.push(`${where}: targets \"${b.id}\" and \"${a.id}\" are nested`);\n else if (a.order < b.order) {\n let lca = a.parent;\n while (lca && !isDescendant(b, lca)) lca = lca.parent;\n if (lca && lca.kind !== \"parallel\") problems.push(`${where}: targets \"${a.id}\" and \"${b.id}\" cannot be active together`);\n }\n }\n }\n\n const scripts = kids(rootEl).filter((c) => c.localName === \"script\");\n if (problems.length) throw new SCXMLValidationError(problems);\n\n const model: Model = {\n ns,\n root,\n states,\n byId,\n byElement,\n transitionsByElement,\n name: rootEl.getAttribute(\"name\") ?? \"\",\n binding: binding === \"late\" ? \"late\" : \"early\",\n scripts,\n allData,\n resources: new Map(),\n warnings: [],\n };\n model.warnings = lint(model);\n return model;\n}\n\nfunction hasContent(el: Element) {\n return el.children.length > 0 || (el.textContent ?? \"\").trim().length > 0;\n}\n"]}
|