eligius 4.0.0 → 4.2.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/README.md +80 -1
- package/dist/configuration-api.d.mts +22 -310
- package/dist/configuration-api.mjs +148 -240
- package/dist/configuration-api.mjs.map +1 -1
- package/dist/engine-factory-39T5FByM.mjs +14431 -0
- package/dist/engine-factory-39T5FByM.mjs.map +1 -0
- package/dist/index.d.mts +839 -9881
- package/dist/index.mjs +1553 -15895
- package/dist/index.mjs.map +1 -1
- package/dist/lint.d.mts +5025 -0
- package/dist/lint.mjs +4412 -0
- package/dist/lint.mjs.map +1 -0
- package/dist/locale-manager-CJy3musb.d.mts +8558 -0
- package/dist/metadata.d.mts +21 -555
- package/dist/metadata.mjs +141 -278
- package/dist/metadata.mjs.map +1 -1
- package/dist/{rolldown-runtime-BOlb2svz.mjs → rolldown-runtime-CGzGPw9x.mjs} +1 -2
- package/dist/runtime.d.mts +3 -0
- package/dist/runtime.mjs +4 -0
- package/package.json +22 -4
package/dist/lint.mjs
ADDED
|
@@ -0,0 +1,4412 @@
|
|
|
1
|
+
|
|
2
|
+
import { t as __exportAll } from "./rolldown-runtime-CGzGPw9x.mjs";
|
|
3
|
+
import { isDefined } from "ts-is-present";
|
|
4
|
+
|
|
5
|
+
// src/operation/helper/flow-control-names.ts
|
|
6
|
+
/**
|
|
7
|
+
* System names of the control-flow operations, in one place so that the
|
|
8
|
+
* operations and the flow-control scans can share them without importing
|
|
9
|
+
* each other.
|
|
10
|
+
*/
|
|
11
|
+
const whenSystemName = "when";
|
|
12
|
+
const otherwiseSystemName = "otherwise";
|
|
13
|
+
const endWhenSystemName = "endWhen";
|
|
14
|
+
const forEachSystemName = "forEach";
|
|
15
|
+
const endForEachSystemName = "endForEach";
|
|
16
|
+
const breakForEachSystemName = "breakForEach";
|
|
17
|
+
const continueForEachSystemName = "continueForEach";
|
|
18
|
+
|
|
19
|
+
// src/operation/helper/assert-safe-property-chain.ts
|
|
20
|
+
/**
|
|
21
|
+
* Property chain segments that lead to an object's prototype or constructor.
|
|
22
|
+
* Reading or writing through them allows prototype pollution or reaching the
|
|
23
|
+
* global `Function` constructor, so property chains may never contain them.
|
|
24
|
+
*/
|
|
25
|
+
const forbiddenPropertyChainSegments = /* @__PURE__ */ new Set([
|
|
26
|
+
"__proto__",
|
|
27
|
+
"prototype",
|
|
28
|
+
"constructor"
|
|
29
|
+
]);
|
|
30
|
+
/**
|
|
31
|
+
* Returns true when the given segment is one of {@link forbiddenPropertyChainSegments}.
|
|
32
|
+
*/
|
|
33
|
+
function isForbiddenPropertyChainSegment(segment) {
|
|
34
|
+
return forbiddenPropertyChainSegments.has(segment);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/operation/helper/chain-cache.ts
|
|
38
|
+
const bracketPattern = /\[(\d+)\]/g;
|
|
39
|
+
/**
|
|
40
|
+
* Expands bracket indices into their own segments and drops empty segments,
|
|
41
|
+
* so `items[2].label` and `items.2.label` resolve the same way.
|
|
42
|
+
*/
|
|
43
|
+
function expandSegments(unexpanded) {
|
|
44
|
+
const segments = [];
|
|
45
|
+
for (const segment of unexpanded) {
|
|
46
|
+
if (!segment.includes("[") && !segment.includes(".")) {
|
|
47
|
+
if (segment.length > 0) segments.push(segment);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
for (const part of segment.replace(bracketPattern, ".$1").split(".")) if (part.length > 0) segments.push(part);
|
|
51
|
+
}
|
|
52
|
+
return segments;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns the first segment whose name (before a `+suffix`) is forbidden.
|
|
56
|
+
*/
|
|
57
|
+
function findForbiddenSegment(segments) {
|
|
58
|
+
for (const segment of segments) {
|
|
59
|
+
const name = segment.split("+")[0];
|
|
60
|
+
if (isForbiddenPropertyChainSegment(name)) return name;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Parses chain segments once.
|
|
65
|
+
*
|
|
66
|
+
* @param unexpanded The segments as written, split on dots
|
|
67
|
+
* @param writtenChain The whole chain as written in the configuration. When
|
|
68
|
+
* given, a forbidden segment found before expansion is reported with this
|
|
69
|
+
* text; one found only after expansion is reported with the expanded chain.
|
|
70
|
+
*/
|
|
71
|
+
function parseSegments(unexpanded, writtenChain) {
|
|
72
|
+
let forbidden;
|
|
73
|
+
if (writtenChain !== void 0) {
|
|
74
|
+
const segment = findForbiddenSegment(unexpanded);
|
|
75
|
+
if (segment !== void 0) forbidden = {
|
|
76
|
+
chainText: writtenChain,
|
|
77
|
+
segment
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const segments = expandSegments(unexpanded);
|
|
81
|
+
const chainText = segments.join(".");
|
|
82
|
+
if (forbidden === void 0) {
|
|
83
|
+
const segment = findForbiddenSegment(segments);
|
|
84
|
+
if (segment !== void 0) forbidden = {
|
|
85
|
+
chainText,
|
|
86
|
+
segment
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const last = segments.length > 0 ? segments[segments.length - 1] : "";
|
|
90
|
+
const plus = last.indexOf("+");
|
|
91
|
+
return {
|
|
92
|
+
segments,
|
|
93
|
+
chainText,
|
|
94
|
+
lastProperty: plus >= 0 ? last.substring(0, plus) : last,
|
|
95
|
+
suffix: plus >= 0 ? last.substring(plus + 1).split("+")[0] : null,
|
|
96
|
+
head: unexpanded[0] ?? "",
|
|
97
|
+
forbidden
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function messagePrefix(operationName) {
|
|
101
|
+
return operationName ? `${operationName}: property chain` : "Property chain";
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Throws when the parsed chain contains a forbidden segment.
|
|
105
|
+
*
|
|
106
|
+
* @throws Error naming the operation, the chain and the segment
|
|
107
|
+
*/
|
|
108
|
+
function assertParsedChainSafe(parsed, operationName) {
|
|
109
|
+
if (parsed.forbidden === void 0) return;
|
|
110
|
+
throw new Error(`${messagePrefix(operationName)} '${parsed.forbidden.chainText}' contains forbidden segment '${parsed.forbidden.segment}'. Property chains may not contain __proto__, prototype or constructor.`);
|
|
111
|
+
}
|
|
112
|
+
function globalObjectError(operationName, parsed, index) {
|
|
113
|
+
return /* @__PURE__ */ new Error(`${messagePrefix(operationName)} '${parsed.chainText}' reaches the global object at '${parsed.segments.slice(0, index).join(".")}'. Property chains may not access the global object.`);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Returns true for the global object (`window`), including the window of another frame.
|
|
117
|
+
*/
|
|
118
|
+
function isGlobalObject(value) {
|
|
119
|
+
return value === globalThis || typeof value === "object" && value !== null && Object.prototype.toString.call(value) === "[object Window]";
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Reads a parsed chain from `sourceObject`.
|
|
123
|
+
*
|
|
124
|
+
* An empty chain returns `sourceObject`. Only null and undefined cannot be
|
|
125
|
+
* indexed; `''`, `0` and `false` are valid intermediates. A `+suffix` on the
|
|
126
|
+
* last segment is appended to the value; an empty suffix returns the value
|
|
127
|
+
* as it is.
|
|
128
|
+
*
|
|
129
|
+
* @throws When an intermediate value is null or undefined (the message names
|
|
130
|
+
* the part of the chain that did resolve), or when the chain passes through
|
|
131
|
+
* or ends at the global object
|
|
132
|
+
*/
|
|
133
|
+
function walkChain(parsed, sourceObject, operationName) {
|
|
134
|
+
const { segments } = parsed;
|
|
135
|
+
const count = segments.length;
|
|
136
|
+
let current = sourceObject;
|
|
137
|
+
for (let index = 0; index < count; index++) {
|
|
138
|
+
if (current === null || current === void 0) throw new Error(`${messagePrefix(operationName)} '${parsed.chainText}' cannot be resolved: '${segments.slice(0, index).join(".")}' is ${current}.`);
|
|
139
|
+
if (index > 0 && isGlobalObject(current)) throw globalObjectError(operationName, parsed, index);
|
|
140
|
+
current = current[index === count - 1 ? parsed.lastProperty : segments[index]];
|
|
141
|
+
}
|
|
142
|
+
if (count > 0 && isGlobalObject(current)) throw globalObjectError(operationName, parsed, count);
|
|
143
|
+
return parsed.suffix ? `${current}${parsed.suffix}` : current;
|
|
144
|
+
}
|
|
145
|
+
const prefixes = {
|
|
146
|
+
"$operationdata.": "operationdata",
|
|
147
|
+
"$globaldata.": "globaldata",
|
|
148
|
+
"$scope.": "scope"
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Returns the kind of external chain `value` is, or undefined when it is not
|
|
152
|
+
* one. The prefix is matched without regard to case, like before.
|
|
153
|
+
*/
|
|
154
|
+
function externalPrefixOf(value) {
|
|
155
|
+
if (value.charCodeAt(0) !== 36) return;
|
|
156
|
+
const dot = value.indexOf(".");
|
|
157
|
+
if (dot < 0) return;
|
|
158
|
+
return prefixes[value.substring(0, dot + 1).toLocaleLowerCase()];
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The cache is cleared when it grows past this size, so chains built at
|
|
162
|
+
* runtime cannot leak memory.
|
|
163
|
+
*/
|
|
164
|
+
const MAX_CACHED_CHAINS = 2e3;
|
|
165
|
+
const parsedChains = /* @__PURE__ */ new Map();
|
|
166
|
+
/**
|
|
167
|
+
* Returns the parsed form of an external property chain, parsing it on the
|
|
168
|
+
* first use, or null when `value` is not an external chain.
|
|
169
|
+
*/
|
|
170
|
+
function getParsedChain(value) {
|
|
171
|
+
const cached = parsedChains.get(value);
|
|
172
|
+
if (cached !== void 0) return cached;
|
|
173
|
+
const prefix = externalPrefixOf(value);
|
|
174
|
+
if (prefix === void 0) return null;
|
|
175
|
+
const unexpanded = value.split(".");
|
|
176
|
+
unexpanded.shift();
|
|
177
|
+
const parsed = {
|
|
178
|
+
...parseSegments(unexpanded, value),
|
|
179
|
+
prefix
|
|
180
|
+
};
|
|
181
|
+
if (parsedChains.size >= MAX_CACHED_CHAINS) parsedChains.clear();
|
|
182
|
+
parsedChains.set(value, parsed);
|
|
183
|
+
return parsed;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/util/guards/is-plain-object.ts
|
|
187
|
+
const functionToString = Function.prototype.toString;
|
|
188
|
+
/** Source text of `Object`, the same in every realm */
|
|
189
|
+
const objectConstructorSource = functionToString.call(Object);
|
|
190
|
+
/**
|
|
191
|
+
* Returns true for plain data objects: object literals, parsed JSON objects
|
|
192
|
+
* and `Object.create(null)` objects, also when they were created in another
|
|
193
|
+
* realm (an iframe, a worker, the realm `fetch` parses JSON in). Returns false
|
|
194
|
+
* for arrays, class instances, `Date`, `Map`, DOM nodes, jQuery objects and
|
|
195
|
+
* objects that inherit from another object.
|
|
196
|
+
*
|
|
197
|
+
* @param value - Any value
|
|
198
|
+
* @returns Whether `value` is a plain data object
|
|
199
|
+
*/
|
|
200
|
+
function isPlainObject(value) {
|
|
201
|
+
if (value === null || typeof value !== "object") return false;
|
|
202
|
+
const prototype = Object.getPrototypeOf(value);
|
|
203
|
+
if (prototype === null || prototype === Object.prototype) return true;
|
|
204
|
+
if (Object.getPrototypeOf(prototype) !== null) return false;
|
|
205
|
+
const objectConstructor = Object.hasOwn(prototype, "constructor") ? prototype.constructor : void 0;
|
|
206
|
+
return typeof objectConstructor === "function" && functionToString.call(objectConstructor) === objectConstructorSource;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/operation/helper/deep-copy.ts
|
|
210
|
+
const copyFunction = typeof structuredClone !== "undefined" ? structuredClone : (original) => JSON.parse(JSON.stringify(original));
|
|
211
|
+
/**
|
|
212
|
+
* Deep-copies plain data: arrays and plain objects are copied recursively (cycles are preserved),
|
|
213
|
+
* Date, RegExp, Map, Set, Error, ArrayBuffer and typed arrays are cloned, and everything else
|
|
214
|
+
* (functions, jQuery objects, DOM nodes, class instances) is kept by reference.
|
|
215
|
+
*
|
|
216
|
+
* An own `__proto__` key (as `JSON.parse` creates) stays an own data property of the copy.
|
|
217
|
+
*
|
|
218
|
+
* This runs for every execution of every operation with nested configured data, so it avoids
|
|
219
|
+
* work on the common shapes: the cycle map is only created once a nested object or array
|
|
220
|
+
* appears, and plain keys are assigned instead of defined.
|
|
221
|
+
*
|
|
222
|
+
* @param original The value to copy
|
|
223
|
+
* @returns The copy, or the value itself when it is not copied
|
|
224
|
+
*/
|
|
225
|
+
function deepCopy(original) {
|
|
226
|
+
if (original === null || typeof original !== "object" || isReferenceOnly(original)) return original;
|
|
227
|
+
return copyObject(original, { seen: null });
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Copies a child value of `parentValue`, whose copy is `parentCopy`.
|
|
231
|
+
*/
|
|
232
|
+
function copyChild(child, parentValue, parentCopy, context) {
|
|
233
|
+
if (child === null || typeof child !== "object" || isReferenceOnly(child)) return child;
|
|
234
|
+
if (context.seen === null) {
|
|
235
|
+
context.seen = /* @__PURE__ */ new WeakMap();
|
|
236
|
+
context.seen.set(parentValue, parentCopy);
|
|
237
|
+
}
|
|
238
|
+
return copyObject(child, context);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Copies an object that is not reference-only.
|
|
242
|
+
*/
|
|
243
|
+
function copyObject(value, context) {
|
|
244
|
+
const { seen } = context;
|
|
245
|
+
const prior = seen?.get(value);
|
|
246
|
+
if (prior !== void 0) return prior;
|
|
247
|
+
if (Array.isArray(value)) {
|
|
248
|
+
const copy = new Array(value.length);
|
|
249
|
+
if (seen !== null) seen.set(value, copy);
|
|
250
|
+
value.forEach((item, index) => {
|
|
251
|
+
copy[index] = copyChild(item, value, copy, context);
|
|
252
|
+
});
|
|
253
|
+
return copy;
|
|
254
|
+
}
|
|
255
|
+
if (isPlainObject(value)) {
|
|
256
|
+
const copy = {};
|
|
257
|
+
if (seen !== null) seen.set(value, copy);
|
|
258
|
+
for (const key of Object.keys(value)) {
|
|
259
|
+
const copied = copyChild(value[key], value, copy, context);
|
|
260
|
+
if (key === "__proto__") Object.defineProperty(copy, key, {
|
|
261
|
+
value: copied,
|
|
262
|
+
writable: true,
|
|
263
|
+
enumerable: true,
|
|
264
|
+
configurable: true
|
|
265
|
+
});
|
|
266
|
+
else copy[key] = copied;
|
|
267
|
+
}
|
|
268
|
+
return copy;
|
|
269
|
+
}
|
|
270
|
+
if (!isStructuredCloneable(value)) return value;
|
|
271
|
+
const copy = copyFunction(value);
|
|
272
|
+
if (seen !== null) seen.set(value, copy);
|
|
273
|
+
return copy;
|
|
274
|
+
}
|
|
275
|
+
function isReferenceOnly(value) {
|
|
276
|
+
return typeof value.jquery === "string" || typeof Node !== "undefined" && value instanceof Node;
|
|
277
|
+
}
|
|
278
|
+
function isStructuredCloneable(value) {
|
|
279
|
+
return cloneableTags.has(Object.prototype.toString.call(value)) || ArrayBuffer.isView(value);
|
|
280
|
+
}
|
|
281
|
+
const cloneableTags = /* @__PURE__ */ new Set([
|
|
282
|
+
"[object Date]",
|
|
283
|
+
"[object RegExp]",
|
|
284
|
+
"[object Map]",
|
|
285
|
+
"[object Set]",
|
|
286
|
+
"[object Error]",
|
|
287
|
+
"[object ArrayBuffer]"
|
|
288
|
+
]);
|
|
289
|
+
|
|
290
|
+
// src/operation/helper/resolve-external-property-chain.ts
|
|
291
|
+
/**
|
|
292
|
+
* Returns true when the value is a `$operationdata.`, `$globaldata.` or
|
|
293
|
+
* `$scope.` property chain. The prefix is matched without regard to case.
|
|
294
|
+
*/
|
|
295
|
+
function isExternalProperty(value) {
|
|
296
|
+
return typeof value === "string" && externalPrefixOf(value) !== void 0;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// src/operation/helper/parse-operand.ts
|
|
300
|
+
const numberPattern = /^[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?$/;
|
|
301
|
+
const quotedPattern = /^'(.*)'$/s;
|
|
302
|
+
const chainPattern = /^\$(operationdata|globaldata|scope)\.[^\s.'"]+(\.[^\s.'"]+)*$/i;
|
|
303
|
+
const keywords = {
|
|
304
|
+
true: true,
|
|
305
|
+
false: false,
|
|
306
|
+
null: null
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* Parses one operand of a condition expression. The tokenizer in `parse-expression.ts`
|
|
310
|
+
* calls it for every operand it finds, so this function is the single definition of the
|
|
311
|
+
* operand grammar.
|
|
312
|
+
*
|
|
313
|
+
* The operand grammar:
|
|
314
|
+
* - a number: `100`, `-1.5`, `2e3` (the whole token must be numeric, so `10px` is invalid);
|
|
315
|
+
* - a string in single quotes: `'John'`;
|
|
316
|
+
* - the keywords `true`, `false` and `null`;
|
|
317
|
+
* - a property chain starting with `$operationdata.`, `$globaldata.` or `$scope.` (the prefix
|
|
318
|
+
* is case-insensitive), for example `$scope.variables.count`.
|
|
319
|
+
*
|
|
320
|
+
* @param token The operand text, already trimmed.
|
|
321
|
+
* @param operationName The operation parsing the expression, named in the error.
|
|
322
|
+
* @param expression The whole expression, quoted in the error.
|
|
323
|
+
* @param position The 0-based position of the operand in the expression, named in the error
|
|
324
|
+
* when given.
|
|
325
|
+
* @returns The parsed operand.
|
|
326
|
+
* @throws When the token matches none of the forms above.
|
|
327
|
+
*/
|
|
328
|
+
function parseOperand(token, operationName, expression, position) {
|
|
329
|
+
const quoted = quotedPattern.exec(token);
|
|
330
|
+
if (quoted) return {
|
|
331
|
+
kind: "literal",
|
|
332
|
+
value: quoted[1]
|
|
333
|
+
};
|
|
334
|
+
if (Object.hasOwn(keywords, token)) return {
|
|
335
|
+
kind: "literal",
|
|
336
|
+
value: keywords[token]
|
|
337
|
+
};
|
|
338
|
+
if (numberPattern.test(token)) return {
|
|
339
|
+
kind: "literal",
|
|
340
|
+
value: Number(token)
|
|
341
|
+
};
|
|
342
|
+
if (isExternalProperty(token) && chainPattern.test(token)) return {
|
|
343
|
+
kind: "chain",
|
|
344
|
+
chain: token
|
|
345
|
+
};
|
|
346
|
+
throw new Error(`${operationName}: unknown operand '${token}' in expression '${expression}'${position === void 0 ? "" : ` at position ${position}`}. Use a number, a quoted string ('text'), true, false, null, or a property chain starting with $operationdata., $globaldata. or $scope.`);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// src/operation/helper/parse-expression.ts
|
|
350
|
+
const symbols = [
|
|
351
|
+
"&&",
|
|
352
|
+
"||",
|
|
353
|
+
"==",
|
|
354
|
+
"!=",
|
|
355
|
+
">=",
|
|
356
|
+
"<=",
|
|
357
|
+
">",
|
|
358
|
+
"<",
|
|
359
|
+
"!",
|
|
360
|
+
"(",
|
|
361
|
+
")"
|
|
362
|
+
];
|
|
363
|
+
const comparisonOperators = /* @__PURE__ */ new Set([
|
|
364
|
+
"==",
|
|
365
|
+
"!=",
|
|
366
|
+
">=",
|
|
367
|
+
"<=",
|
|
368
|
+
">",
|
|
369
|
+
"<"
|
|
370
|
+
]);
|
|
371
|
+
const delimiterPattern = /[\s()!=<>&|]/;
|
|
372
|
+
function isDelimiter(char) {
|
|
373
|
+
return char === void 0 || delimiterPattern.test(char);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Parses a condition expression into a tree that {@link evaluateExpression} evaluates.
|
|
377
|
+
*
|
|
378
|
+
* The grammar, from lowest to highest precedence:
|
|
379
|
+
*
|
|
380
|
+
* ```
|
|
381
|
+
* or := and ('||' and)*
|
|
382
|
+
* and := comparison ('&&' comparison)*
|
|
383
|
+
* comparison := unary (('==' | '!=' | '>=' | '<=' | '>' | '<') unary)?
|
|
384
|
+
* unary := '!' unary | primary
|
|
385
|
+
* primary := '(' or ')' | operand
|
|
386
|
+
* ```
|
|
387
|
+
*
|
|
388
|
+
* Operands are parsed by {@link parseOperand}: numbers, single-quoted strings, `true`,
|
|
389
|
+
* `false`, `null` and `$operationdata.`, `$globaldata.` or `$scope.` property chains.
|
|
390
|
+
* Inside a quoted string, operators and parentheses are part of the text. A quote ends the
|
|
391
|
+
* string only when it is followed by whitespace, an operator, a parenthesis or the end of the
|
|
392
|
+
* expression, so an apostrophe inside the text (`'it's'`) needs no escaping.
|
|
393
|
+
*
|
|
394
|
+
* Comparisons do not chain (`1<x<3` is an error, write `1<x && x<3`). Arithmetic is not
|
|
395
|
+
* supported. Nothing in the expression is executed as code.
|
|
396
|
+
*
|
|
397
|
+
* @param expression The expression text.
|
|
398
|
+
* @param operationName The operation parsing the expression, named in the error messages.
|
|
399
|
+
* @returns The root node of the parsed expression.
|
|
400
|
+
* @throws When the expression is not a string or is empty, contains an unknown operand, an
|
|
401
|
+
* unterminated string, an unknown or misplaced operator, or unbalanced parentheses. The message
|
|
402
|
+
* names the operation, the problem, its position (0-based) and the expression.
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* parseExpression("$scope.variables.score>=5 && !$operationdata.skipped", 'when');
|
|
406
|
+
*/
|
|
407
|
+
function parseExpression(expression, operationName) {
|
|
408
|
+
if (typeof expression !== "string") throw new Error(`${operationName}: expression must be a string, received ${expression === null ? "null" : typeof expression}.`);
|
|
409
|
+
const tokens = tokenize(expression, operationName);
|
|
410
|
+
if (!tokens.length) throw new Error(`${operationName}: empty expression '${expression}'.`);
|
|
411
|
+
let index = 0;
|
|
412
|
+
const fail = (message, position, hint) => {
|
|
413
|
+
throw new Error(`${operationName}: ${message} at position ${position} in expression '${expression}'.${hint ? ` ${hint}` : ""}`);
|
|
414
|
+
};
|
|
415
|
+
const unexpected = (token, hint) => token ? fail(`unexpected '${token.text}'`, token.position, hint) : fail("unexpected end of expression", expression.length, hint);
|
|
416
|
+
const peekSymbol = () => {
|
|
417
|
+
const token = tokens[index];
|
|
418
|
+
return token?.type === "symbol" ? token.text : void 0;
|
|
419
|
+
};
|
|
420
|
+
const parseOr = () => {
|
|
421
|
+
let left = parseAnd();
|
|
422
|
+
while (peekSymbol() === "||") {
|
|
423
|
+
index++;
|
|
424
|
+
left = {
|
|
425
|
+
kind: "or",
|
|
426
|
+
left,
|
|
427
|
+
right: parseAnd()
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
return left;
|
|
431
|
+
};
|
|
432
|
+
const parseAnd = () => {
|
|
433
|
+
let left = parseComparison();
|
|
434
|
+
while (peekSymbol() === "&&") {
|
|
435
|
+
index++;
|
|
436
|
+
left = {
|
|
437
|
+
kind: "and",
|
|
438
|
+
left,
|
|
439
|
+
right: parseComparison()
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
return left;
|
|
443
|
+
};
|
|
444
|
+
const parseComparison = () => {
|
|
445
|
+
const left = parseUnary();
|
|
446
|
+
const operator = peekSymbol();
|
|
447
|
+
if (operator && comparisonOperators.has(operator)) {
|
|
448
|
+
index++;
|
|
449
|
+
return {
|
|
450
|
+
kind: "comparison",
|
|
451
|
+
operator,
|
|
452
|
+
left,
|
|
453
|
+
right: parseUnary()
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
return left;
|
|
457
|
+
};
|
|
458
|
+
const parseUnary = () => {
|
|
459
|
+
if (peekSymbol() === "!") {
|
|
460
|
+
index++;
|
|
461
|
+
return {
|
|
462
|
+
kind: "not",
|
|
463
|
+
operand: parseUnary()
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
return parsePrimary();
|
|
467
|
+
};
|
|
468
|
+
const parsePrimary = () => {
|
|
469
|
+
const token = tokens[index];
|
|
470
|
+
if (token?.type === "operand") {
|
|
471
|
+
index++;
|
|
472
|
+
return {
|
|
473
|
+
kind: "operand",
|
|
474
|
+
operand: token.operand
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
if (token?.text === "(") {
|
|
478
|
+
index++;
|
|
479
|
+
const node = parseOr();
|
|
480
|
+
const closing = tokens[index];
|
|
481
|
+
if (!closing) return fail("missing ')' for the '('", token.position);
|
|
482
|
+
if (closing.text !== ")") return unexpected(closing, "Expected ')' or an operator.");
|
|
483
|
+
index++;
|
|
484
|
+
return node;
|
|
485
|
+
}
|
|
486
|
+
return unexpected(token);
|
|
487
|
+
};
|
|
488
|
+
const root = parseOr();
|
|
489
|
+
if (index < tokens.length) {
|
|
490
|
+
const token = tokens[index];
|
|
491
|
+
unexpected(token, token.text === ")" ? "It has no matching '('." : token.type === "symbol" && comparisonOperators.has(token.text) ? "Comparisons do not chain, combine them with && or use parentheses." : "Expected && or || between the parts of the condition.");
|
|
492
|
+
}
|
|
493
|
+
return root;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Splits the expression into symbols and operands. Operands are parsed with
|
|
497
|
+
* {@link parseOperand}, so the operand grammar has one source.
|
|
498
|
+
*/
|
|
499
|
+
function tokenize(expression, operationName) {
|
|
500
|
+
const tokens = [];
|
|
501
|
+
let i = 0;
|
|
502
|
+
while (i < expression.length) {
|
|
503
|
+
const char = expression[i];
|
|
504
|
+
if (/\s/.test(char)) {
|
|
505
|
+
i++;
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
const symbol = symbols.find((s) => expression.startsWith(s, i));
|
|
509
|
+
if (symbol) {
|
|
510
|
+
tokens.push({
|
|
511
|
+
type: "symbol",
|
|
512
|
+
text: symbol,
|
|
513
|
+
position: i
|
|
514
|
+
});
|
|
515
|
+
i += symbol.length;
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
if (char === "=" || char === "&" || char === "|") throw new Error(`${operationName}: unexpected '${char}' at position ${i} in expression '${expression}'. Did you mean '${char}${char}'?`);
|
|
519
|
+
const end = char === "'" ? endOfString(expression, i) : endOfWord(expression, i);
|
|
520
|
+
if (end < 0) throw new Error(`${operationName}: unterminated string at position ${i} in expression '${expression}'.`);
|
|
521
|
+
const text = expression.substring(i, end);
|
|
522
|
+
tokens.push({
|
|
523
|
+
type: "operand",
|
|
524
|
+
text,
|
|
525
|
+
position: i,
|
|
526
|
+
operand: parseOperand(text, operationName, expression, i)
|
|
527
|
+
});
|
|
528
|
+
i = end;
|
|
529
|
+
}
|
|
530
|
+
return tokens;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Returns the index after the quote that closes the string starting at `start`, or -1 when the
|
|
534
|
+
* string is not closed. A quote closes the string only when a delimiter or the end follows it.
|
|
535
|
+
*/
|
|
536
|
+
function endOfString(expression, start) {
|
|
537
|
+
for (let i = start + 1; i < expression.length; i++) if (expression[i] === "'" && isDelimiter(expression[i + 1])) return i + 1;
|
|
538
|
+
return -1;
|
|
539
|
+
}
|
|
540
|
+
function endOfWord(expression, start) {
|
|
541
|
+
let i = start;
|
|
542
|
+
while (i < expression.length && !isDelimiter(expression[i])) i++;
|
|
543
|
+
return i;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// src/util/guards/is-promise.ts
|
|
547
|
+
/**
|
|
548
|
+
* Returns true for promises and other thenables.
|
|
549
|
+
*
|
|
550
|
+
* @param obj - Any value
|
|
551
|
+
* @returns Whether `obj` is an object with a `then` method
|
|
552
|
+
*/
|
|
553
|
+
function isPromise(obj) {
|
|
554
|
+
return typeof obj === "object" && obj !== null && typeof obj.then === "function";
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// src/action/action.ts
|
|
558
|
+
var Action = class {
|
|
559
|
+
name;
|
|
560
|
+
startOperations;
|
|
561
|
+
eventbus;
|
|
562
|
+
id = "";
|
|
563
|
+
/**
|
|
564
|
+
* Scope stack used by {@link executeOperation} when it is called without an
|
|
565
|
+
* explicit stack. `start()` and `end()` each create their own stack, so
|
|
566
|
+
* overlapping executions of the same action never share scopes.
|
|
567
|
+
*
|
|
568
|
+
* @deprecated Calling {@link executeOperation} without a scope stack is
|
|
569
|
+
* deprecated; this fallback will be removed in the next major version.
|
|
570
|
+
*/
|
|
571
|
+
_scopeStack = [];
|
|
572
|
+
/**
|
|
573
|
+
* The configured `forEach` operation data copied when a loop starts, keyed
|
|
574
|
+
* by the loop's scope. Later iterations of the same loop merge this copy
|
|
575
|
+
* again instead of deep-copying the collection on every iteration.
|
|
576
|
+
*/
|
|
577
|
+
_loopOperationData = /* @__PURE__ */ new WeakMap();
|
|
578
|
+
constructor(name, startOperations, eventbus) {
|
|
579
|
+
this.name = name;
|
|
580
|
+
this.startOperations = startOperations;
|
|
581
|
+
this.eventbus = eventbus;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Runs the start operations.
|
|
585
|
+
*
|
|
586
|
+
* A failure is not logged here: the returned promise rejects with the
|
|
587
|
+
* error (annotated with the failing operation), and the caller reports it.
|
|
588
|
+
* The engine reports it through its `error` event, the eventbus through
|
|
589
|
+
* its `onHandlerError` option, and `init()` by rejecting.
|
|
590
|
+
*
|
|
591
|
+
* @param initOperationData - Operation data the first start operation receives
|
|
592
|
+
* @returns The operation data of the last start operation
|
|
593
|
+
*/
|
|
594
|
+
start(initOperationData) {
|
|
595
|
+
return this._runOperations(this.startOperations, initOperationData);
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Runs the given operations with a scope stack that belongs to this
|
|
599
|
+
* execution only.
|
|
600
|
+
*
|
|
601
|
+
* @param operations - The operations to run
|
|
602
|
+
* @param initOperationData - Operation data the first operation receives
|
|
603
|
+
* @param onSettled - Called the moment the operations have completed or
|
|
604
|
+
* failed, before the returned promise settles. Operations that complete
|
|
605
|
+
* synchronously call it synchronously.
|
|
606
|
+
* @returns The operation data of the last operation
|
|
607
|
+
*/
|
|
608
|
+
_runOperations(operations, initOperationData, onSettled) {
|
|
609
|
+
const scopeStack = this._createScopeStack(operations);
|
|
610
|
+
return new Promise((resolve, reject) => {
|
|
611
|
+
this.executeOperation(operations, 0, onSettled ? (value) => {
|
|
612
|
+
onSettled();
|
|
613
|
+
resolve(value);
|
|
614
|
+
} : resolve, onSettled ? (reason) => {
|
|
615
|
+
onSettled();
|
|
616
|
+
reject(reason);
|
|
617
|
+
} : reject, initOperationData, scopeStack);
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
_createScopeStack(operations) {
|
|
621
|
+
return [{
|
|
622
|
+
currentIndex: -1,
|
|
623
|
+
eventbus: this.eventbus,
|
|
624
|
+
operations
|
|
625
|
+
}];
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* @deprecated Unused: `start()` and `end()` create a scope stack for each
|
|
629
|
+
* execution. Will be removed in the next major version.
|
|
630
|
+
*/
|
|
631
|
+
_initializeScopeStack() {
|
|
632
|
+
this._scopeStack = this._createScopeStack(this.startOperations);
|
|
633
|
+
}
|
|
634
|
+
_pushScope(scopeStack, parentScope) {
|
|
635
|
+
const newScope = {
|
|
636
|
+
get currentIndex() {
|
|
637
|
+
return parentScope.currentIndex;
|
|
638
|
+
},
|
|
639
|
+
set currentIndex(value) {
|
|
640
|
+
parentScope.currentIndex = value;
|
|
641
|
+
},
|
|
642
|
+
get eventbus() {
|
|
643
|
+
return parentScope.eventbus;
|
|
644
|
+
},
|
|
645
|
+
get operations() {
|
|
646
|
+
return parentScope.operations;
|
|
647
|
+
},
|
|
648
|
+
parent: parentScope
|
|
649
|
+
};
|
|
650
|
+
scopeStack.push(newScope);
|
|
651
|
+
return newScope;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Executes `operations` starting at `operationIndex`.
|
|
655
|
+
*
|
|
656
|
+
* Synchronous operations run in a loop, so the stack depth does not grow with
|
|
657
|
+
* the number of executed operations (large `forEach` loops are safe). When an
|
|
658
|
+
* operation returns a promise, execution continues once it resolves.
|
|
659
|
+
*/
|
|
660
|
+
executeOperation(operations, operationIndex, resolve, reject, previousOperationData = {}, scopeStack = this._scopeStack) {
|
|
661
|
+
let index = operationIndex;
|
|
662
|
+
let operationData = previousOperationData ?? {};
|
|
663
|
+
let failingOperation;
|
|
664
|
+
let failingIndex = operationIndex;
|
|
665
|
+
try {
|
|
666
|
+
while (true) {
|
|
667
|
+
let scope = scopeStack[scopeStack.length - 1];
|
|
668
|
+
if (scope.newIndex !== void 0) {
|
|
669
|
+
index = scope.newIndex;
|
|
670
|
+
delete scope.newIndex;
|
|
671
|
+
}
|
|
672
|
+
scope.currentIndex = index;
|
|
673
|
+
if (index >= operations.length) {
|
|
674
|
+
resolve(operationData);
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
const operationInfo = operations[index];
|
|
678
|
+
failingOperation = operationInfo;
|
|
679
|
+
failingIndex = index;
|
|
680
|
+
const isLoopIteration = operationInfo.systemName === "forEach" && scope.owner === operationInfo;
|
|
681
|
+
const configuredData = (isLoopIteration ? this._loopOperationData.get(scope) : void 0) ?? copyConfiguredOperationData(operationInfo.operationData, operationInfo.systemName);
|
|
682
|
+
const mergedOperationData = Object.assign(operationData, configuredData);
|
|
683
|
+
if (operationInfo.systemName === "when") scope = this._pushScope(scopeStack, scope);
|
|
684
|
+
else if (operationInfo.systemName === "forEach" && !isLoopIteration) {
|
|
685
|
+
scope = this._pushScope(scopeStack, scope);
|
|
686
|
+
scope.owner = operationInfo;
|
|
687
|
+
this._loopOperationData.set(scope, configuredData);
|
|
688
|
+
}
|
|
689
|
+
const operationResult = operationInfo.instance.call(scope, mergedOperationData);
|
|
690
|
+
if (operationInfo.systemName === "endWhen" || operationInfo.systemName === "endForEach" && scope.newIndex === void 0) scopeStack.pop();
|
|
691
|
+
index++;
|
|
692
|
+
if (isPromise(operationResult)) {
|
|
693
|
+
const nextIndex = index;
|
|
694
|
+
const asyncOperation = operationInfo;
|
|
695
|
+
const asyncIndex = index - 1;
|
|
696
|
+
operationResult.then((promisedOperationResult) => this.executeOperation(operations, nextIndex, resolve, reject, promisedOperationResult, scopeStack), (error) => reject(withOperationContext(error, asyncOperation, asyncIndex))).catch(reject);
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
operationData = operationResult ?? {};
|
|
700
|
+
}
|
|
701
|
+
} catch (error) {
|
|
702
|
+
reject(failingOperation ? withOperationContext(error, failingOperation, failingIndex) : error);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
/**
|
|
707
|
+
* Adds the failing operation's system name and index to an error, unless an
|
|
708
|
+
* inner action already did (the innermost operation is the most specific),
|
|
709
|
+
* and prepends the operation to the error's path, so that every action frame
|
|
710
|
+
* the error passes through adds exactly one entry, outermost first.
|
|
711
|
+
* Non-Error values are wrapped in an Error that keeps their message.
|
|
712
|
+
*/
|
|
713
|
+
function withOperationContext(error, operation, index) {
|
|
714
|
+
const annotated = error instanceof Error ? error : new Error(String(error), { cause: error });
|
|
715
|
+
if (annotated.operationSystemName === void 0) {
|
|
716
|
+
annotated.operationSystemName = operation.systemName;
|
|
717
|
+
annotated.operationIndex = index;
|
|
718
|
+
}
|
|
719
|
+
annotated.operationPath = [{
|
|
720
|
+
systemName: operation.systemName,
|
|
721
|
+
index
|
|
722
|
+
}, ...annotated.operationPath ?? []];
|
|
723
|
+
return annotated;
|
|
724
|
+
}
|
|
725
|
+
const emptyOperationData = Object.freeze({});
|
|
726
|
+
/**
|
|
727
|
+
* Configured operation data already checked by {@link assertNoProtoKeys}.
|
|
728
|
+
* Configured data is not changed after resolution, so each object is walked
|
|
729
|
+
* once, not on every run of its operation.
|
|
730
|
+
*/
|
|
731
|
+
const checkedOperationData = /* @__PURE__ */ new WeakSet();
|
|
732
|
+
/**
|
|
733
|
+
* Throws when an own `__proto__` key occurs anywhere in the configured
|
|
734
|
+
* operation data (JSON.parse creates one as a normal property). Merging with
|
|
735
|
+
* Object.assign would run the `__proto__` setter at the top level, and
|
|
736
|
+
* operations that assign or merge nested data could do the same below it.
|
|
737
|
+
* Arrays and plain objects are walked; class instances, jQuery objects and
|
|
738
|
+
* DOM nodes are not.
|
|
739
|
+
*
|
|
740
|
+
* @throws Error naming the operation and the path of the key
|
|
741
|
+
*/
|
|
742
|
+
function assertNoProtoKeys(operationData, systemName) {
|
|
743
|
+
if (checkedOperationData.has(operationData)) return;
|
|
744
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
745
|
+
const walk = (value, path) => {
|
|
746
|
+
if (value === null || typeof value !== "object" || visiting.has(value)) return;
|
|
747
|
+
if (Array.isArray(value)) {
|
|
748
|
+
visiting.add(value);
|
|
749
|
+
value.forEach((item, index) => {
|
|
750
|
+
walk(item, `${path}[${index}]`);
|
|
751
|
+
});
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
if (!isPlainObject(value)) return;
|
|
755
|
+
visiting.add(value);
|
|
756
|
+
if (Object.hasOwn(value, "__proto__")) {
|
|
757
|
+
const at = path ? `${path}.__proto__` : "__proto__";
|
|
758
|
+
throw new Error(`${systemName}: operation data must not contain a '__proto__' key (found at '${at}')`);
|
|
759
|
+
}
|
|
760
|
+
for (const key of Object.keys(value)) walk(value[key], path ? `${path}.${key}` : key);
|
|
761
|
+
};
|
|
762
|
+
walk(operationData, "");
|
|
763
|
+
checkedOperationData.add(operationData);
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Returns the configured operation data in a form that is safe to merge into
|
|
767
|
+
* the running operation data.
|
|
768
|
+
*
|
|
769
|
+
* Merging copies the top-level properties, so operations that delete or
|
|
770
|
+
* reassign properties (such as `@erased` ones) never touch the configured
|
|
771
|
+
* object. Only nested objects and arrays can be mutated through the merged
|
|
772
|
+
* data, so a deep copy is made only when the configured data contains one.
|
|
773
|
+
* Empty data and data holding only primitives and functions is returned as-is.
|
|
774
|
+
*
|
|
775
|
+
* @throws Error when the data contains a `__proto__` key at any depth
|
|
776
|
+
*/
|
|
777
|
+
function copyConfiguredOperationData(operationData, systemName) {
|
|
778
|
+
if (!operationData) return emptyOperationData;
|
|
779
|
+
assertNoProtoKeys(operationData, systemName);
|
|
780
|
+
for (const key in operationData) {
|
|
781
|
+
const value = operationData[key];
|
|
782
|
+
if (typeof value === "object" && value !== null && Object.hasOwn(operationData, key)) return deepCopy(operationData);
|
|
783
|
+
}
|
|
784
|
+
return operationData;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// src/action/endable-action.ts
|
|
788
|
+
var EndableAction = class extends Action {
|
|
789
|
+
endOperations;
|
|
790
|
+
constructor(name, startOperations, endOperations, eventBus) {
|
|
791
|
+
super(name, startOperations, eventBus);
|
|
792
|
+
this.endOperations = endOperations;
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Runs the end operations.
|
|
796
|
+
*
|
|
797
|
+
* A failure is not logged here: the returned promise rejects with the
|
|
798
|
+
* error (annotated with the failing operation), and the caller reports it.
|
|
799
|
+
* The engine reports it through its `error` event.
|
|
800
|
+
*
|
|
801
|
+
* @param initOperationData - Operation data the first end operation receives
|
|
802
|
+
* @returns The operation data of the last end operation
|
|
803
|
+
*/
|
|
804
|
+
end(initOperationData) {
|
|
805
|
+
if (!this.endOperations.length) return Promise.resolve(initOperationData ?? {});
|
|
806
|
+
return this._runOperations(this.endOperations, initOperationData);
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
// src/action/timeline-action.ts
|
|
811
|
+
var TimelineAction = class extends EndableAction {
|
|
812
|
+
duration;
|
|
813
|
+
_active = false;
|
|
814
|
+
/** True while start or end operations of this action are running */
|
|
815
|
+
_running = false;
|
|
816
|
+
/** Starts and ends called while operations were running, in call order */
|
|
817
|
+
_waiting = [];
|
|
818
|
+
/**
|
|
819
|
+
* Finishes the run that `_execute` is starting; handed to the operations
|
|
820
|
+
* run (see `_runOperations`) so it is called the moment they settle.
|
|
821
|
+
*/
|
|
822
|
+
_finishPending;
|
|
823
|
+
/**
|
|
824
|
+
* True from the moment `start()` is called until `end()` is called, whether
|
|
825
|
+
* or not the action has end operations. Both transitions happen
|
|
826
|
+
* synchronously, so a second dispatch of the same start or end (a seek
|
|
827
|
+
* while playing, a revisited key) is a no-op.
|
|
828
|
+
*/
|
|
829
|
+
get active() {
|
|
830
|
+
return this._active;
|
|
831
|
+
}
|
|
832
|
+
constructor(name, startOperations, endOperations, duration, eventBus) {
|
|
833
|
+
super(name, startOperations, endOperations, eventBus);
|
|
834
|
+
this.duration = duration;
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Starts the action, unless it is already active.
|
|
838
|
+
*
|
|
839
|
+
* `active` becomes true at once. When the operations of an earlier start
|
|
840
|
+
* or end are still running (an asynchronous end at a loop wrap, a start
|
|
841
|
+
* awaiting a fetch when its range is skipped), these start operations run
|
|
842
|
+
* once those have finished, so the start and end operations of one action
|
|
843
|
+
* never interleave. Otherwise they run right away.
|
|
844
|
+
*
|
|
845
|
+
* @param initOperationData - Operation data the first start operation receives
|
|
846
|
+
* @returns The operation data of the last start operation
|
|
847
|
+
*/
|
|
848
|
+
start(initOperationData) {
|
|
849
|
+
if (this._active) return Promise.resolve({});
|
|
850
|
+
this._active = true;
|
|
851
|
+
return this._sequence(() => super.start(initOperationData));
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Ends the action, unless it is not active.
|
|
855
|
+
*
|
|
856
|
+
* `active` becomes false at once. Like {@link start}, the end operations
|
|
857
|
+
* wait for operations of this action that are still running.
|
|
858
|
+
*
|
|
859
|
+
* @param initOperationData - Operation data the first end operation receives
|
|
860
|
+
* @returns The operation data of the last end operation
|
|
861
|
+
*/
|
|
862
|
+
end(initOperationData) {
|
|
863
|
+
if (!this._active) return Promise.resolve({});
|
|
864
|
+
this._active = false;
|
|
865
|
+
return this._sequence(() => super.end(initOperationData));
|
|
866
|
+
}
|
|
867
|
+
_sequence(run) {
|
|
868
|
+
if (!this._running) return this._execute(run);
|
|
869
|
+
return new Promise((resolve, reject) => {
|
|
870
|
+
this._waiting.push(() => {
|
|
871
|
+
this._execute(run).then(resolve, reject);
|
|
872
|
+
});
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Runs `run`, marking the action as running until its operations settle.
|
|
877
|
+
* Operations that complete synchronously finish the run synchronously, so
|
|
878
|
+
* a start and end called back to back both run within the same call stack.
|
|
879
|
+
*/
|
|
880
|
+
_execute(run) {
|
|
881
|
+
let finished = false;
|
|
882
|
+
const finish = () => {
|
|
883
|
+
if (finished) return;
|
|
884
|
+
finished = true;
|
|
885
|
+
this._running = false;
|
|
886
|
+
this._waiting.shift()?.();
|
|
887
|
+
};
|
|
888
|
+
this._running = true;
|
|
889
|
+
this._finishPending = finish;
|
|
890
|
+
let result;
|
|
891
|
+
try {
|
|
892
|
+
result = run();
|
|
893
|
+
} catch (error) {
|
|
894
|
+
result = Promise.reject(error);
|
|
895
|
+
}
|
|
896
|
+
if (this._finishPending === finish) {
|
|
897
|
+
this._finishPending = void 0;
|
|
898
|
+
finish();
|
|
899
|
+
}
|
|
900
|
+
return result;
|
|
901
|
+
}
|
|
902
|
+
_runOperations(operations, initOperationData, onSettled) {
|
|
903
|
+
const finish = this._finishPending;
|
|
904
|
+
this._finishPending = void 0;
|
|
905
|
+
return super._runOperations(operations, initOperationData, () => {
|
|
906
|
+
onSettled?.();
|
|
907
|
+
finish?.();
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
|
|
912
|
+
// src/configuration/timeline-provider-overrides.ts
|
|
913
|
+
/**
|
|
914
|
+
* Merges a per-timeline override over the settings of the timeline's type.
|
|
915
|
+
*
|
|
916
|
+
* - Without an override the type's settings are returned as they are.
|
|
917
|
+
* - An override that leaves out `systemName`, or names the same class as the
|
|
918
|
+
* type's settings, is merged over them property by property (shallow).
|
|
919
|
+
* - An override that names a different class replaces the type's settings,
|
|
920
|
+
* so options meant for one class never reach another.
|
|
921
|
+
*
|
|
922
|
+
* @param base - The settings of the timeline's type, if any
|
|
923
|
+
* @param override - The timeline's override, if any
|
|
924
|
+
* @returns The effective settings, or undefined when neither is given
|
|
925
|
+
*/
|
|
926
|
+
function mergeProviderConfig(base, override) {
|
|
927
|
+
if (!override) return base;
|
|
928
|
+
if (!base) return { ...override };
|
|
929
|
+
if (override.systemName !== void 0 && override.systemName !== base.systemName) return { ...override };
|
|
930
|
+
return {
|
|
931
|
+
...base,
|
|
932
|
+
...override
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* The effective position source settings of a timeline: its
|
|
937
|
+
* `positionSource` override merged over the settings of its type (see
|
|
938
|
+
* {@link mergeProviderConfig}).
|
|
939
|
+
*/
|
|
940
|
+
function effectivePositionSource(timeline, typeSettings) {
|
|
941
|
+
return mergeProviderConfig(typeSettings?.positionSource, timeline.positionSource);
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* The effective container provider settings of a timeline: its
|
|
945
|
+
* `containerProvider` override merged over the `container` settings of its
|
|
946
|
+
* type (see {@link mergeProviderConfig}).
|
|
947
|
+
*/
|
|
948
|
+
function effectiveContainerProvider(timeline, typeSettings) {
|
|
949
|
+
return mergeProviderConfig(typeSettings?.container, timeline.containerProvider);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
// src/operation/helper/flow-control-structure.ts
|
|
953
|
+
const closerOf = {
|
|
954
|
+
[whenSystemName]: endWhenSystemName,
|
|
955
|
+
[forEachSystemName]: endForEachSystemName
|
|
956
|
+
};
|
|
957
|
+
/**
|
|
958
|
+
* Checks that the `when`/`otherwise`/`endWhen` and `forEach`/`endForEach`
|
|
959
|
+
* blocks of an operation list are balanced and nested, and that
|
|
960
|
+
* `breakForEach` and `continueForEach` sit inside a `forEach`.
|
|
961
|
+
*
|
|
962
|
+
* The interpreter does not check this. An `endWhen` that closes a `forEach`,
|
|
963
|
+
* or an `endWhen` without a `when`, pops the wrong scope at runtime, and the
|
|
964
|
+
* action then fails with a TypeError on the next operation, or runs with the
|
|
965
|
+
* wrong scope. A block that is never closed runs to the end of the list.
|
|
966
|
+
*
|
|
967
|
+
* @param systemNames The system names of the operations, in order
|
|
968
|
+
* @returns The problems in list order, empty when the blocks are well formed
|
|
969
|
+
*/
|
|
970
|
+
function findFlowControlProblems(systemNames) {
|
|
971
|
+
const problems = [];
|
|
972
|
+
const stack = [];
|
|
973
|
+
const close = (closer, expected, index) => {
|
|
974
|
+
const top = stack[stack.length - 1];
|
|
975
|
+
if (!top) {
|
|
976
|
+
problems.push({
|
|
977
|
+
index,
|
|
978
|
+
message: `${closer} at index ${index} has no open ${expected} to close.`
|
|
979
|
+
});
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
if (top.name !== expected) problems.push({
|
|
983
|
+
index,
|
|
984
|
+
message: `${closer} at index ${index} closes the ${top.name} at index ${top.index}, which must be closed with ${closerOf[top.name]} first: blocks must nest.`
|
|
985
|
+
});
|
|
986
|
+
stack.pop();
|
|
987
|
+
};
|
|
988
|
+
systemNames.forEach((name, index) => {
|
|
989
|
+
switch (name) {
|
|
990
|
+
case whenSystemName:
|
|
991
|
+
case forEachSystemName:
|
|
992
|
+
stack.push({
|
|
993
|
+
name,
|
|
994
|
+
index,
|
|
995
|
+
hasOtherwise: false
|
|
996
|
+
});
|
|
997
|
+
break;
|
|
998
|
+
case otherwiseSystemName: {
|
|
999
|
+
const top = stack[stack.length - 1];
|
|
1000
|
+
if (!top || top.name !== "when") problems.push({
|
|
1001
|
+
index,
|
|
1002
|
+
message: top ? `otherwise at index ${index} is inside the forEach at index ${top.index}, not directly inside a when.` : `otherwise at index ${index} has no open when.`
|
|
1003
|
+
});
|
|
1004
|
+
else if (top.hasOtherwise) problems.push({
|
|
1005
|
+
index,
|
|
1006
|
+
message: `otherwise at index ${index} is the second otherwise of the when at index ${top.index}.`
|
|
1007
|
+
});
|
|
1008
|
+
else top.hasOtherwise = true;
|
|
1009
|
+
break;
|
|
1010
|
+
}
|
|
1011
|
+
case endWhenSystemName:
|
|
1012
|
+
close(endWhenSystemName, whenSystemName, index);
|
|
1013
|
+
break;
|
|
1014
|
+
case endForEachSystemName:
|
|
1015
|
+
close(endForEachSystemName, forEachSystemName, index);
|
|
1016
|
+
break;
|
|
1017
|
+
case breakForEachSystemName:
|
|
1018
|
+
case continueForEachSystemName: if (!stack.some((block) => block.name === "forEach")) problems.push({
|
|
1019
|
+
index,
|
|
1020
|
+
message: `${name} at index ${index} is not inside a forEach.`
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
});
|
|
1024
|
+
for (const open of stack) problems.push({
|
|
1025
|
+
index: open.index,
|
|
1026
|
+
message: `${open.name} at index ${open.index} is never closed with ${closerOf[open.name]}.`
|
|
1027
|
+
});
|
|
1028
|
+
return problems.sort((a, b) => a.index - b.index);
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
// src/operation/helper/get-property-chain-value.ts
|
|
1032
|
+
/**
|
|
1033
|
+
* Gets the value for the given property chain. A property chain is defined by a string array.
|
|
1034
|
+
*
|
|
1035
|
+
* For example, this property chain: `[mySource, subSource, element, value]` should be extracted from an object of this shape:
|
|
1036
|
+
* ```ts
|
|
1037
|
+
* const foo = {
|
|
1038
|
+
* mySource: {
|
|
1039
|
+
* subSource: {
|
|
1040
|
+
* element: {
|
|
1041
|
+
* value: 'bar'
|
|
1042
|
+
* }
|
|
1043
|
+
* }
|
|
1044
|
+
* }
|
|
1045
|
+
* }
|
|
1046
|
+
* ```
|
|
1047
|
+
*
|
|
1048
|
+
* The result of the invocation `getPropertyChainValue([mySource, subSource, element, value], foo)` would then yield the value `bar`.
|
|
1049
|
+
*
|
|
1050
|
+
* Chains containing a `__proto__`, `prototype` or `constructor` segment are rejected to
|
|
1051
|
+
* prevent prototype pollution and access to the `Function` constructor. Chains that pass
|
|
1052
|
+
* through or end at the global object (`window`), for example
|
|
1053
|
+
* `selectedElement.0.ownerDocument.defaultView`, are rejected too, so configuration cannot
|
|
1054
|
+
* reach `eval`, `Function`, timers or other globals.
|
|
1055
|
+
*
|
|
1056
|
+
* Bracket indices are expanded into their own segments, so `eventArgs[0]` resolves like
|
|
1057
|
+
* `eventArgs.0` and `items[2].label` like `items.2.label`. The parsing is shared with the
|
|
1058
|
+
* cached external chains, see `chain-cache.ts`.
|
|
1059
|
+
*
|
|
1060
|
+
* @param propertyChain The chain segments. Segments may use dot or bracket notation themselves.
|
|
1061
|
+
* @param sourceObject The object to resolve the chain against.
|
|
1062
|
+
* @param operationName The operation resolving the chain, named in the error messages.
|
|
1063
|
+
* @throws When an intermediate value is null or undefined (the message names the part of the
|
|
1064
|
+
* chain that did not resolve), when the chain contains a forbidden segment, or when it reaches
|
|
1065
|
+
* the global object.
|
|
1066
|
+
*/
|
|
1067
|
+
function getPropertyChainValue(propertyChain, sourceObject, operationName) {
|
|
1068
|
+
const parsed = parseSegments(propertyChain);
|
|
1069
|
+
assertParsedChainSafe(parsed, operationName);
|
|
1070
|
+
return walkChain(parsed, sourceObject, operationName);
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
// src/operation/helper/resolve-property-chain.ts
|
|
1074
|
+
/**
|
|
1075
|
+
* Gets the value for the given property chain. A property chain is defined by a period delimited string.
|
|
1076
|
+
*
|
|
1077
|
+
* For example, this property chain: `mySource.subSource.element.value` should be extracted from an object of this shape:
|
|
1078
|
+
* ```ts
|
|
1079
|
+
* const foo = {
|
|
1080
|
+
* mySource: {
|
|
1081
|
+
* subSource: {
|
|
1082
|
+
* element: {
|
|
1083
|
+
* value: 'bar'
|
|
1084
|
+
* }
|
|
1085
|
+
* }
|
|
1086
|
+
* }
|
|
1087
|
+
* }
|
|
1088
|
+
* ```
|
|
1089
|
+
*
|
|
1090
|
+
* The result of the invocation `resolvePropertyChain('mySource.subSource.element.value', foo)` would then yield the value `bar`.
|
|
1091
|
+
*
|
|
1092
|
+
* Chains containing `__proto__`, `prototype` or `constructor` segments are rejected.
|
|
1093
|
+
*
|
|
1094
|
+
* @throws When the chain cannot be resolved or contains a forbidden segment.
|
|
1095
|
+
*/
|
|
1096
|
+
function resolvePropertyChain(propertyChain, sourceObject, operationName) {
|
|
1097
|
+
const properties = propertyChain.split(".");
|
|
1098
|
+
return getPropertyChainValue(properties, sourceObject, operationName);
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
// src/util/find-closest-names.ts
|
|
1102
|
+
/**
|
|
1103
|
+
* Returns the known names closest to `name`, for "did you mean" hints in error
|
|
1104
|
+
* messages. Matching ignores case and uses the Levenshtein edit distance; only
|
|
1105
|
+
* names within `max(2, floor(name.length / 3))` edits are returned, closest
|
|
1106
|
+
* first.
|
|
1107
|
+
*
|
|
1108
|
+
* @param name - The unknown name, as written in the configuration
|
|
1109
|
+
* @param knownNames - The names that are registered
|
|
1110
|
+
* @param max - The maximum number of suggestions to return
|
|
1111
|
+
* @returns Up to `max` known names, closest first; empty when none is close
|
|
1112
|
+
*/
|
|
1113
|
+
function findClosestNames(name, knownNames, max = 3) {
|
|
1114
|
+
const lowerName = name.toLowerCase();
|
|
1115
|
+
const maxDistance = Math.max(2, Math.floor(name.length / 3));
|
|
1116
|
+
return knownNames.map((knownName) => ({
|
|
1117
|
+
knownName,
|
|
1118
|
+
distance: levenshtein(lowerName, knownName.toLowerCase())
|
|
1119
|
+
})).filter(({ distance }) => distance <= maxDistance).sort((a, b) => a.distance - b.distance).slice(0, max).map(({ knownName }) => knownName);
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* Formats suggestions from {@link findClosestNames} as a sentence.
|
|
1123
|
+
*
|
|
1124
|
+
* @param suggestions - The suggested names
|
|
1125
|
+
* @returns `Did you mean 'a', 'b'?`, or an empty string when there are no suggestions
|
|
1126
|
+
*/
|
|
1127
|
+
function formatDidYouMean(suggestions) {
|
|
1128
|
+
if (!suggestions.length) return "";
|
|
1129
|
+
return `Did you mean ${suggestions.map((name) => `'${name}'`).join(", ")}?`;
|
|
1130
|
+
}
|
|
1131
|
+
function levenshtein(a, b) {
|
|
1132
|
+
let previous = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
1133
|
+
for (let i = 1; i <= a.length; i++) {
|
|
1134
|
+
const current = [i];
|
|
1135
|
+
for (let j = 1; j <= b.length; j++) {
|
|
1136
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
1137
|
+
current[j] = Math.min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + cost);
|
|
1138
|
+
}
|
|
1139
|
+
previous = current;
|
|
1140
|
+
}
|
|
1141
|
+
return previous[b.length];
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
// src/util/guards/is-function.ts
|
|
1145
|
+
function isFunction(value) {
|
|
1146
|
+
return typeof value === "function";
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
// src/util/guards/is-object.ts
|
|
1150
|
+
/**
|
|
1151
|
+
* Returns true for any non-null, non-array object: plain objects, but also
|
|
1152
|
+
* class instances, `Date`, `Map`, DOM nodes and jQuery objects.
|
|
1153
|
+
*
|
|
1154
|
+
* The narrowed type is a loose record. When the value must be a plain data
|
|
1155
|
+
* object (an object literal or parsed JSON), use `isPlainObject` instead.
|
|
1156
|
+
*
|
|
1157
|
+
* @param value - Any value
|
|
1158
|
+
* @returns Whether `value` is a non-null, non-array object
|
|
1159
|
+
*/
|
|
1160
|
+
function isObject(value) {
|
|
1161
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
// src/util/guards/is-string.ts
|
|
1165
|
+
function isString(value) {
|
|
1166
|
+
return typeof value === "string";
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
// src/configuration/configuration-resolver.ts
|
|
1170
|
+
/**
|
|
1171
|
+
* The default warning handler: writes the warning to the console.
|
|
1172
|
+
*/
|
|
1173
|
+
function warnToConsole(warning) {
|
|
1174
|
+
console.warn(`Eligius configuration warning at ${warning.path}: ${warning.message}`);
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Takes an `IEngineConfiguration` instance and return an `IResolvedEngineConfiguration`.
|
|
1178
|
+
* This means all system names within the configuration will be resolved to their associated instances.
|
|
1179
|
+
*
|
|
1180
|
+
* If the given configuration includes event actions, then those will be registered in the given
|
|
1181
|
+
* `ActionRegistryEventbusListener`. They are registered only after the whole configuration
|
|
1182
|
+
* has been accepted, so a configuration that `process` rejects leaves the listener untouched.
|
|
1183
|
+
*
|
|
1184
|
+
* Every error names the JSON path of the offending value.
|
|
1185
|
+
*
|
|
1186
|
+
* @throws When an operation's `systemName` does not resolve to an operation function (including
|
|
1187
|
+
* controller, timeline provider, custom function and class exports of the importer). The message
|
|
1188
|
+
* suggests the closest operation names the importer lists, which include the custom operations
|
|
1189
|
+
* registered with `EligiusResourceImporter`.
|
|
1190
|
+
* @throws When two actions (or an action and an event action) share the same name.
|
|
1191
|
+
* @throws When `actions`, `initActions`, `timelines`, an action's `startOperations` or
|
|
1192
|
+
* `endOperations`, or a timeline's `timelineActions` is not an array.
|
|
1193
|
+
* @throws When a timeline action has no valid `duration`, or when a timeline's `type` has no
|
|
1194
|
+
* entry in `timelineProviderSettings` and the timeline has no `positionSource` with a `systemName`
|
|
1195
|
+
* of its own.
|
|
1196
|
+
* @throws When a timeline's `positionSource` or `containerProvider` override is not an object,
|
|
1197
|
+
* names a `systemName` the importer does not provide, or leaves out a setting that the provider
|
|
1198
|
+
* requires (for example `selector` of `ScrollPositionSource`) once it is merged over the type's
|
|
1199
|
+
* settings.
|
|
1200
|
+
* @throws When a VideoPositionSource has an 'options' key, at timelineProviderSettings.<type>.positionSource
|
|
1201
|
+
* or at a timeline's positionSource override (also when the override inherits VideoPositionSource from its
|
|
1202
|
+
* type). 4.0.0 removed the video.js player options.
|
|
1203
|
+
* @throws When a `template:`, `json:` or `config:` placeholder cannot be resolved.
|
|
1204
|
+
*
|
|
1205
|
+
* Control-flow blocks that are not well formed (an `endWhen` without a `when`,
|
|
1206
|
+
* an `endWhen` that closes a `forEach`, a `when` that is never closed, a
|
|
1207
|
+
* `breakForEach` outside a `forEach`) are reported as warnings through
|
|
1208
|
+
* {@link IConfigurationResolverOptions.onWarning}, by default on the console.
|
|
1209
|
+
* The interpreter runs them as before: an operation list with such a block
|
|
1210
|
+
* fails at runtime, or runs with the wrong scope. They become errors in the
|
|
1211
|
+
* next major version. `eligius/lint` reports the same shapes as errors.
|
|
1212
|
+
*/
|
|
1213
|
+
var ConfigurationResolver = class {
|
|
1214
|
+
importer;
|
|
1215
|
+
eventbus;
|
|
1216
|
+
_warn;
|
|
1217
|
+
/**
|
|
1218
|
+
* @param importer - Resolves system names to operations, controllers and providers
|
|
1219
|
+
* @param eventbus - The eventbus the resolved actions run on
|
|
1220
|
+
* @param options - Optional. `onWarning` receives the configuration
|
|
1221
|
+
* warnings instead of the console.
|
|
1222
|
+
*/
|
|
1223
|
+
constructor(importer, eventbus, options = {}) {
|
|
1224
|
+
this.importer = importer;
|
|
1225
|
+
this.eventbus = eventbus;
|
|
1226
|
+
this._warn = options.onWarning ?? warnToConsole;
|
|
1227
|
+
}
|
|
1228
|
+
process(configuration, actionRegistryListener) {
|
|
1229
|
+
const imported = /* @__PURE__ */ new WeakSet();
|
|
1230
|
+
resolvePlaceholders(configuration, configuration, this.importer, "import", imported, "");
|
|
1231
|
+
resolvePlaceholders(configuration, configuration, this.importer, "config", imported, "");
|
|
1232
|
+
if (!isObject(configuration.timelineProviderSettings) && !(configuration.timelineProviderSettings === void 0 && everyTimelineHasOwnPositionSource(configuration.timelines))) throw new Error(`Configuration incomplete: it needs to have at least one timeline provider setting at timelineProviderSettings, got ${describeValue(configuration.timelineProviderSettings)}.`);
|
|
1233
|
+
const resolvedConfig = {
|
|
1234
|
+
id: configuration.id,
|
|
1235
|
+
engine: { ...configuration.engine },
|
|
1236
|
+
timelineProviderSettings: deepCopy(configuration.timelineProviderSettings) ?? {},
|
|
1237
|
+
containerSelector: configuration.containerSelector,
|
|
1238
|
+
cssFiles: deepCopy(configuration.cssFiles),
|
|
1239
|
+
language: configuration.language,
|
|
1240
|
+
layoutTemplate: configuration.layoutTemplate,
|
|
1241
|
+
availableLanguages: deepCopy(configuration.availableLanguages),
|
|
1242
|
+
actions: resolveActions(configuration.actions, this.importer, this.eventbus, "actions", this._warn),
|
|
1243
|
+
initActions: resolveActions(configuration.initActions, this.importer, this.eventbus, "initActions", this._warn),
|
|
1244
|
+
timelineFlow: deepCopy(configuration.timelineFlow),
|
|
1245
|
+
timelines: resolveTimelines(configuration.timelines, this.importer, this.eventbus, this._warn)
|
|
1246
|
+
};
|
|
1247
|
+
assertTimelineProviderSettings(configuration, this.importer);
|
|
1248
|
+
let eventActions = [];
|
|
1249
|
+
if (isDefined(configuration.eventActions)) {
|
|
1250
|
+
assertArray(configuration.eventActions, "eventActions");
|
|
1251
|
+
if (actionRegistryListener) eventActions = resolveEventActions(configuration.eventActions, this.importer, this.eventbus, this._warn);
|
|
1252
|
+
}
|
|
1253
|
+
const actionsLookup = createActionsLookup([...resolvedConfig.actions.map((action, index) => [action, `actions[${index}]`]), ...eventActions.map(({ action }, index) => [action, `eventActions[${index}]`])]);
|
|
1254
|
+
for (const { action, eventName, eventTopic } of eventActions) actionRegistryListener?.registerAction(action, eventName, eventTopic);
|
|
1255
|
+
return [actionsLookup, resolvedConfig];
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
/**
|
|
1259
|
+
* Describes a value for an error message by its kind only, so configuration
|
|
1260
|
+
* data never ends up in a message.
|
|
1261
|
+
*/
|
|
1262
|
+
function describeValue(value) {
|
|
1263
|
+
if (value === null) return "null";
|
|
1264
|
+
if (Array.isArray(value)) return "an array";
|
|
1265
|
+
switch (typeof value) {
|
|
1266
|
+
case "undefined": return "undefined";
|
|
1267
|
+
case "object": return "an object";
|
|
1268
|
+
case "number": return Number.isFinite(value) ? String(value) : "a non-finite number";
|
|
1269
|
+
case "string": return "a string";
|
|
1270
|
+
case "boolean": return "a boolean";
|
|
1271
|
+
default: return `a ${typeof value}`;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
function assertArray(value, path) {
|
|
1275
|
+
if (!Array.isArray(value)) throw new Error(`Invalid configuration at ${path}: expected an array, got ${describeValue(value)}.`);
|
|
1276
|
+
}
|
|
1277
|
+
/**
|
|
1278
|
+
* Every timeline needs a position source: from the provider settings of its
|
|
1279
|
+
* type, or from a `positionSource` override with a `systemName` of its own.
|
|
1280
|
+
* Otherwise the engine silently has no position source for it.
|
|
1281
|
+
*
|
|
1282
|
+
* Overrides are checked here so a mistake fails at resolution with its JSON
|
|
1283
|
+
* path, not at init or on the first switch to the timeline.
|
|
1284
|
+
*/
|
|
1285
|
+
function assertTimelineProviderSettings(configuration, importer) {
|
|
1286
|
+
const settings = configuration.timelineProviderSettings ?? {};
|
|
1287
|
+
for (const [type, typeSettings] of Object.entries(settings)) if (isObject(typeSettings) && isObject(typeSettings.positionSource)) assertNoVideoOptions(typeSettings.positionSource, typeSettings.positionSource.systemName, `timelineProviderSettings.${type}.positionSource`);
|
|
1288
|
+
configuration.timelines.forEach((timeline, index) => {
|
|
1289
|
+
const path = `timelines[${index}]`;
|
|
1290
|
+
const { type } = timeline;
|
|
1291
|
+
const typeSettings = Object.hasOwn(settings, type) && isObject(settings[type]) ? settings[type] : void 0;
|
|
1292
|
+
assertProviderOverride(timeline.positionSource, `${path}.positionSource`, "position source", importer);
|
|
1293
|
+
assertProviderOverride(timeline.containerProvider, `${path}.containerProvider`, "container provider", importer);
|
|
1294
|
+
if (isObject(timeline.positionSource)) assertNoVideoOptions(timeline.positionSource, effectivePositionSource(timeline, typeSettings)?.systemName, `${path}.positionSource`);
|
|
1295
|
+
if (!typeSettings && !isString(timeline.positionSource?.systemName)) throw new Error(`Missing timeline provider settings at timelineProviderSettings.${type} for ${path} (type '${type}'). Add a provider for the '${type}' timeline type, or give ${path}.positionSource a systemName of its own.`);
|
|
1296
|
+
if (isDefined(timeline.positionSource)) assertMergedProviderSettings(effectivePositionSource(timeline, typeSettings), `${path}.positionSource`, `timelineProviderSettings.${type}.positionSource`, "position source");
|
|
1297
|
+
if (isDefined(timeline.containerProvider)) assertMergedProviderSettings(effectiveContainerProvider(timeline, typeSettings), `${path}.containerProvider`, `timelineProviderSettings.${type}.container`, "container provider");
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* True when there are timelines and every one names its own position source,
|
|
1302
|
+
* so the configuration needs no `timelineProviderSettings`.
|
|
1303
|
+
*/
|
|
1304
|
+
function everyTimelineHasOwnPositionSource(timelines) {
|
|
1305
|
+
return Array.isArray(timelines) && timelines.length > 0 && timelines.every((timeline) => isObject(timeline) && isObject(timeline.positionSource) && isString(timeline.positionSource.systemName));
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Settings that the built-in providers cannot work without. They are checked
|
|
1309
|
+
* for timelines that override their provider settings, after the merge.
|
|
1310
|
+
*/
|
|
1311
|
+
const REQUIRED_PROVIDER_SETTINGS = {
|
|
1312
|
+
ScrollPositionSource: ["selector"],
|
|
1313
|
+
VideoPositionSource: ["selector", "sources"],
|
|
1314
|
+
DomContainerProvider: ["selector"]
|
|
1315
|
+
};
|
|
1316
|
+
/**
|
|
1317
|
+
* VideoPositionSource took video.js player options under `options` until
|
|
1318
|
+
* 4.0.0 removed video.js. Other position sources may still take an
|
|
1319
|
+
* `options` key, so only the effective system name `VideoPositionSource` is
|
|
1320
|
+
* checked.
|
|
1321
|
+
*
|
|
1322
|
+
* @param positionSource - The settings object as written in the configuration
|
|
1323
|
+
* @param systemName - The effective system name (inherited for overrides without one)
|
|
1324
|
+
* @param path - JSON path of `positionSource`
|
|
1325
|
+
* @throws When a VideoPositionSource has an `options` key
|
|
1326
|
+
*/
|
|
1327
|
+
function assertNoVideoOptions(positionSource, systemName, path) {
|
|
1328
|
+
if (systemName !== "VideoPositionSource" || !Object.hasOwn(positionSource, "options")) return;
|
|
1329
|
+
throw new Error(`Invalid configuration at ${path}.options: VideoPositionSource no longer accepts 'options' (the video.js player options were removed in 4.0.0). Put 'sources' and 'poster' directly in ${path} and delete 'options'. See the 4.0.0 migration steps in CHANGELOG.md.`);
|
|
1330
|
+
}
|
|
1331
|
+
/**
|
|
1332
|
+
* Checks the shape of a per-timeline provider override and that its
|
|
1333
|
+
* `systemName`, when given, is provided by the importer.
|
|
1334
|
+
*/
|
|
1335
|
+
function assertProviderOverride(override, path, kind, importer) {
|
|
1336
|
+
if (!isDefined(override)) return;
|
|
1337
|
+
if (!isObject(override)) throw new Error(`Invalid configuration at ${path}: expected an object with ${kind} settings, got ${describeValue(override)}.`);
|
|
1338
|
+
const { systemName } = override;
|
|
1339
|
+
if (!isDefined(systemName)) return;
|
|
1340
|
+
if (!isString(systemName)) throw new Error(`Invalid configuration at ${path}.systemName: expected the name of a ${kind} class, got ${describeValue(systemName)}.`);
|
|
1341
|
+
let entry;
|
|
1342
|
+
try {
|
|
1343
|
+
entry = importer.import(systemName)?.[systemName];
|
|
1344
|
+
} catch {
|
|
1345
|
+
entry = void 0;
|
|
1346
|
+
}
|
|
1347
|
+
if (!isFunction(entry)) {
|
|
1348
|
+
const didYouMean = formatDidYouMean(findClosestNames(systemName, getImporterNames(importer, "getProviderNames")));
|
|
1349
|
+
throw new Error(`Unknown ${kind} '${systemName}' at ${path}.systemName. ${didYouMean || `Check the spelling, or make sure the ${kind} is available from the resource importer.`}`);
|
|
1350
|
+
}
|
|
1351
|
+
const isListedAs = (getterName) => getImporterNames(importer, getterName).includes(systemName);
|
|
1352
|
+
if (!isListedAs("getProviderNames") && (isListedAs("getOperationNames") || isListedAs("getControllerNames"))) throw new Error(`Unknown ${kind} '${systemName}' at ${path}.systemName: '${systemName}' is an operation or controller, not a ${kind}.`);
|
|
1353
|
+
}
|
|
1354
|
+
/**
|
|
1355
|
+
* Checks the settings a timeline ends up with once its override is merged
|
|
1356
|
+
* over the settings of its type: a `systemName`, and the settings the
|
|
1357
|
+
* built-in provider of that name requires.
|
|
1358
|
+
*/
|
|
1359
|
+
function assertMergedProviderSettings(merged, path, typePath, kind) {
|
|
1360
|
+
const systemName = merged?.systemName;
|
|
1361
|
+
if (!merged || !isString(systemName)) throw new Error(`Missing systemName at ${path}.systemName: there are no settings at ${typePath} to merge the override over, so it has to name the ${kind} class.`);
|
|
1362
|
+
const required = Object.hasOwn(REQUIRED_PROVIDER_SETTINGS, systemName) ? REQUIRED_PROVIDER_SETTINGS[systemName] : [];
|
|
1363
|
+
for (const key of required) if (!hasRequiredSetting(merged, key)) throw new Error(`Missing setting at ${path}.${key}: '${systemName}' requires '${key}', and neither ${path} nor ${typePath} provides it.`);
|
|
1364
|
+
}
|
|
1365
|
+
function hasRequiredSetting(settings, key) {
|
|
1366
|
+
if (key === "sources") return isNonEmptyArray(settings.sources);
|
|
1367
|
+
const value = settings[key];
|
|
1368
|
+
return isString(value) ? value.length > 0 : isDefined(value);
|
|
1369
|
+
}
|
|
1370
|
+
function isNonEmptyArray(value) {
|
|
1371
|
+
return Array.isArray(value) && value.length > 0;
|
|
1372
|
+
}
|
|
1373
|
+
function createActionsLookup(actions) {
|
|
1374
|
+
const lookup = Object.create(null);
|
|
1375
|
+
const paths = Object.create(null);
|
|
1376
|
+
for (const [action, path] of actions) {
|
|
1377
|
+
if (Object.hasOwn(lookup, action.name)) throw new Error(`Duplicate action name '${action.name}' at ${paths[action.name]}.name and ${path}.name. Action names must be unique across actions and eventActions, rename one of them.`);
|
|
1378
|
+
lookup[action.name] = action;
|
|
1379
|
+
paths[action.name] = path;
|
|
1380
|
+
}
|
|
1381
|
+
return lookup;
|
|
1382
|
+
}
|
|
1383
|
+
/**
|
|
1384
|
+
* Creates the event actions without registering them.
|
|
1385
|
+
*/
|
|
1386
|
+
function resolveEventActions(eventActionConfigurations, importer, eventbus, warn) {
|
|
1387
|
+
return eventActionConfigurations.map((config, index) => resolveActionConfiguration(config, importer, `eventActions[${index}]`, warn)).map((config, index) => {
|
|
1388
|
+
const { eventName, eventTopic } = eventActionConfigurations[index];
|
|
1389
|
+
return {
|
|
1390
|
+
action: new Action(config.name, config.startOperations, eventbus),
|
|
1391
|
+
eventName,
|
|
1392
|
+
eventTopic
|
|
1393
|
+
};
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
function resolveTimelines(timelines, importer, eventbus, warn) {
|
|
1397
|
+
assertArray(timelines, "timelines");
|
|
1398
|
+
return timelines.map((config, timelineIndex) => {
|
|
1399
|
+
const path = `timelines[${timelineIndex}]`;
|
|
1400
|
+
assertArray(config.timelineActions, `${path}.timelineActions`);
|
|
1401
|
+
return {
|
|
1402
|
+
...config,
|
|
1403
|
+
...isDefined(config.positionSource) && { positionSource: deepCopy(config.positionSource) },
|
|
1404
|
+
...isDefined(config.containerProvider) && { containerProvider: deepCopy(config.containerProvider) },
|
|
1405
|
+
timelineActions: config.timelineActions.map((actionConfig, index) => resolveTimelineAction(importer, eventbus, actionConfig, `${path}.timelineActions[${index}]`, warn))
|
|
1406
|
+
};
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1409
|
+
function resolveOperation(importer, operationConfig, path) {
|
|
1410
|
+
const { systemName } = operationConfig;
|
|
1411
|
+
let instance;
|
|
1412
|
+
try {
|
|
1413
|
+
instance = importer.import(systemName)?.[systemName];
|
|
1414
|
+
} catch (error) {
|
|
1415
|
+
throw new Error(createUnknownOperationMessage(importer, systemName, path), { cause: error });
|
|
1416
|
+
}
|
|
1417
|
+
if (!isFunction(instance)) throw new Error(createUnknownOperationMessage(importer, systemName, path));
|
|
1418
|
+
const notAnOperation = describeNonOperation(importer, systemName, instance);
|
|
1419
|
+
if (notAnOperation) throw new Error(`Unknown operation '${systemName}' at ${path}.systemName. ${notAnOperation}`);
|
|
1420
|
+
return {
|
|
1421
|
+
id: operationConfig.id,
|
|
1422
|
+
systemName,
|
|
1423
|
+
operationData: deepCopy(operationConfig.operationData) ?? {},
|
|
1424
|
+
instance
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
/**
|
|
1428
|
+
* Returns why the given importer export is not an operation, or `undefined`
|
|
1429
|
+
* when it may be one.
|
|
1430
|
+
*/
|
|
1431
|
+
function describeNonOperation(importer, systemName, instance) {
|
|
1432
|
+
const isListedAs = (getterName) => getImporterNames(importer, getterName).includes(systemName);
|
|
1433
|
+
if (!isListedAs("getOperationNames")) {
|
|
1434
|
+
if (isListedAs("getControllerNames")) return `'${systemName}' is a controller, not an operation: attach it with the addControllerToElement operation.`;
|
|
1435
|
+
if (isListedAs("getProviderNames")) return `'${systemName}' is a timeline provider export, not an operation: configure it in timelineProviderSettings.`;
|
|
1436
|
+
if (isListedAs("getFunctionNames")) return `'${systemName}' is a custom function, not an operation: call it with the customFunction operation ({systemName: '${systemName}'}).`;
|
|
1437
|
+
}
|
|
1438
|
+
if (isClass(instance)) return `'${systemName}' is a class, not an operation function.`;
|
|
1439
|
+
}
|
|
1440
|
+
function isClass(value) {
|
|
1441
|
+
return /^class[\s{]/.test(Function.prototype.toString.call(value));
|
|
1442
|
+
}
|
|
1443
|
+
function resolveOperations(importer, operationConfigs, path, warn) {
|
|
1444
|
+
assertArray(operationConfigs, path);
|
|
1445
|
+
const resolved = operationConfigs.map((operationConfig, index) => resolveOperation(importer, operationConfig, `${path}[${index}]`));
|
|
1446
|
+
for (const problem of findFlowControlProblems(resolved.map((operation) => operation.systemName))) warn({
|
|
1447
|
+
path: `${path}[${problem.index}].systemName`,
|
|
1448
|
+
message: `${problem.message} This will be a configuration error in the next major version.`
|
|
1449
|
+
});
|
|
1450
|
+
return resolved;
|
|
1451
|
+
}
|
|
1452
|
+
function createUnknownOperationMessage(importer, systemName, path) {
|
|
1453
|
+
const message = `Unknown operation '${systemName}' at ${path}.systemName.`;
|
|
1454
|
+
const knownNames = getImporterNames(importer, "getOperationNames");
|
|
1455
|
+
const didYouMean = formatDidYouMean(findClosestNames(String(systemName), knownNames));
|
|
1456
|
+
if (didYouMean) return `${message} ${didYouMean}`;
|
|
1457
|
+
return `${message} Check the spelling, or make sure the operation is available from the resource importer.`;
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* Calls one of the optional `IResourceImporter` name getters, an empty list when
|
|
1461
|
+
* the importer does not have it.
|
|
1462
|
+
*/
|
|
1463
|
+
function getImporterNames(importer, getterName) {
|
|
1464
|
+
const getter = importer[getterName];
|
|
1465
|
+
if (isFunction(getter)) {
|
|
1466
|
+
const names = getter.call(importer);
|
|
1467
|
+
return Array.isArray(names) ? names : [];
|
|
1468
|
+
}
|
|
1469
|
+
return [];
|
|
1470
|
+
}
|
|
1471
|
+
function resolveActionConfiguration(config, importer, path, warn) {
|
|
1472
|
+
return {
|
|
1473
|
+
id: config.id,
|
|
1474
|
+
name: config.name,
|
|
1475
|
+
startOperations: resolveOperations(importer, config.startOperations, `${path}.startOperations`, warn)
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
function resolveEndableActionConfiguration(config, importer, path, warn) {
|
|
1479
|
+
return {
|
|
1480
|
+
...resolveActionConfiguration(config, importer, path, warn),
|
|
1481
|
+
endOperations: resolveOperations(importer, config.endOperations, `${path}.endOperations`, warn)
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
/**
|
|
1485
|
+
* Validates a timeline action duration: `start` is a number >= 0, `end` is
|
|
1486
|
+
* optional and, when given, not lower than `start`. An `end` of -1 marks an
|
|
1487
|
+
* open end, like a missing `end`.
|
|
1488
|
+
*/
|
|
1489
|
+
function resolveDuration(duration, path) {
|
|
1490
|
+
if (!isObject(duration)) throw new Error(`Invalid configuration at ${path}: expected {start: number, end?: number}, got ${describeValue(duration)}.`);
|
|
1491
|
+
const { start, end } = duration;
|
|
1492
|
+
if (typeof start !== "number" || !Number.isFinite(start) || start < 0) throw new Error(`Invalid configuration at ${path}.start: expected a number >= 0, got ${describeValue(start)}.`);
|
|
1493
|
+
if (!isDefined(end) || end === -1) return {
|
|
1494
|
+
start,
|
|
1495
|
+
end: -1
|
|
1496
|
+
};
|
|
1497
|
+
if (typeof end !== "number" || !Number.isFinite(end)) throw new Error(`Invalid configuration at ${path}.end: expected a number or no end, got ${describeValue(end)}.`);
|
|
1498
|
+
if (end < start) throw new Error(`Invalid configuration at ${path}.end: end (${end}) must not be lower than start (${start}).`);
|
|
1499
|
+
return {
|
|
1500
|
+
start,
|
|
1501
|
+
end
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
function resolveTimelineAction(importer, eventbus, actionConfiguration, path, warn) {
|
|
1505
|
+
const duration = resolveDuration(actionConfiguration.duration, `${path}.duration`);
|
|
1506
|
+
const { id, name, endOperations, startOperations } = resolveEndableActionConfiguration(actionConfiguration, importer, path, warn);
|
|
1507
|
+
const action = new TimelineAction(name, startOperations, endOperations, duration, eventbus);
|
|
1508
|
+
action.id = id;
|
|
1509
|
+
return action;
|
|
1510
|
+
}
|
|
1511
|
+
function resolveActions(actionConfigurations, importer, eventbus, path, warn) {
|
|
1512
|
+
assertArray(actionConfigurations, path);
|
|
1513
|
+
return actionConfigurations.map((config, index) => {
|
|
1514
|
+
return resolveEndableActionConfiguration(config, importer, `${path}[${index}]`, warn);
|
|
1515
|
+
}).map((resolvedConfig) => {
|
|
1516
|
+
const { name, endOperations, startOperations } = resolvedConfig;
|
|
1517
|
+
const action = new EndableAction(name, startOperations, endOperations, eventbus);
|
|
1518
|
+
action.id = resolvedConfig.id;
|
|
1519
|
+
return action;
|
|
1520
|
+
});
|
|
1521
|
+
}
|
|
1522
|
+
/**
|
|
1523
|
+
* Walks arrays and plain data objects only. Class instances, jQuery objects and
|
|
1524
|
+
* other non-plain values (from the TypeScript API) are kept as they are.
|
|
1525
|
+
*/
|
|
1526
|
+
function resolvePlaceholders(configFragment, rootConfig, importer, pass, imported, path) {
|
|
1527
|
+
if (!isDefined(configFragment) || imported.has(configFragment)) return;
|
|
1528
|
+
if (Array.isArray(configFragment)) configFragment.forEach((_item, index) => {
|
|
1529
|
+
resolvePlaceholder(index, configFragment, rootConfig, importer, pass, imported, `${path}[${index}]`);
|
|
1530
|
+
});
|
|
1531
|
+
else if (isPlainObject(configFragment)) Object.keys(configFragment).forEach((key) => {
|
|
1532
|
+
resolvePlaceholder(key, configFragment, rootConfig, importer, pass, imported, path ? `${path}.${key}` : key);
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
function resolvePlaceholder(key, configFragment, rootConfig, importer, pass, imported, path) {
|
|
1536
|
+
const configValue = configFragment[key];
|
|
1537
|
+
if (isString(configValue)) {
|
|
1538
|
+
if (pass === "config") {
|
|
1539
|
+
if (configValue.startsWith("config:")) configFragment[key] = resolveConfigPlaceholder(configValue, rootConfig, path);
|
|
1540
|
+
} else if (configValue.startsWith("template:")) configFragment[key] = importPlaceholder(importer, configValue.substring(9, configValue.length), configValue, path);
|
|
1541
|
+
else if (configValue.startsWith("json:")) {
|
|
1542
|
+
const jsonKey = configValue.substring(5, configValue.length);
|
|
1543
|
+
const json = deepCopy(importPlaceholder(importer, jsonKey, configValue, path));
|
|
1544
|
+
configFragment[key] = json;
|
|
1545
|
+
if (isPlainObject(json) || Array.isArray(json)) imported.add(json);
|
|
1546
|
+
}
|
|
1547
|
+
} else if (isPlainObject(configValue) || Array.isArray(configValue)) resolvePlaceholders(configValue, rootConfig, importer, pass, imported, path);
|
|
1548
|
+
}
|
|
1549
|
+
/**
|
|
1550
|
+
* Imports the value for a `template:` or `json:` placeholder. An importer that
|
|
1551
|
+
* throws for an unknown name gets its error wrapped, and an importer that returns
|
|
1552
|
+
* a record without an entry for the name is reported as an unknown name. Both
|
|
1553
|
+
* messages name the placeholder and its JSON path. An entry that is present but
|
|
1554
|
+
* `undefined` is accepted.
|
|
1555
|
+
*/
|
|
1556
|
+
function importPlaceholder(importer, name, placeholder, path) {
|
|
1557
|
+
let record;
|
|
1558
|
+
try {
|
|
1559
|
+
record = importer.import(name);
|
|
1560
|
+
} catch (error) {
|
|
1561
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
1562
|
+
throw new Error(`Unable to resolve placeholder '${placeholder}' at ${path}: ${reason}`, { cause: error });
|
|
1563
|
+
}
|
|
1564
|
+
if (!isObject(record) || !Object.hasOwn(record, name)) throw new Error(`Unable to resolve placeholder '${placeholder}' at ${path}: unknown name '${name}'.`);
|
|
1565
|
+
return record[name];
|
|
1566
|
+
}
|
|
1567
|
+
/**
|
|
1568
|
+
* Resolves a `config:` placeholder against the root configuration. When the target
|
|
1569
|
+
* is itself a `config:` placeholder, that one is followed as well.
|
|
1570
|
+
*
|
|
1571
|
+
* @throws When the property chain cannot be resolved or yields `undefined`.
|
|
1572
|
+
*/
|
|
1573
|
+
function resolveConfigPlaceholder(placeholder, rootConfig, path, visited = /* @__PURE__ */ new Set()) {
|
|
1574
|
+
if (visited.has(placeholder)) throw new Error(`Circular config: placeholder '${placeholder}' at ${path} (chain: ${[...visited, placeholder].join(" -> ")})`);
|
|
1575
|
+
visited.add(placeholder);
|
|
1576
|
+
const configProperty = placeholder.substring(7, placeholder.length);
|
|
1577
|
+
let value;
|
|
1578
|
+
try {
|
|
1579
|
+
value = resolvePropertyChain(configProperty, rootConfig);
|
|
1580
|
+
} catch (error) {
|
|
1581
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
1582
|
+
throw new Error(`Unable to resolve placeholder '${placeholder}' at ${path}: ${reason}`, { cause: error });
|
|
1583
|
+
}
|
|
1584
|
+
if (value === void 0) throw new Error(`Unable to resolve placeholder '${placeholder}' at ${path}: the configuration has no value at '${configProperty}'.`);
|
|
1585
|
+
if (isString(value) && value.startsWith("config:")) return resolveConfigPlaceholder(value, rootConfig, path, visited);
|
|
1586
|
+
return value;
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
// src/eventbus/actionregistry-eventbus-listener.ts
|
|
1590
|
+
/**
|
|
1591
|
+
* The `IEventbusListener` first registers a number of actions that are then
|
|
1592
|
+
* executed when the specified event is broadcast.
|
|
1593
|
+
*/
|
|
1594
|
+
var ActionRegistryEventbusListener = class {
|
|
1595
|
+
_actionRegistry = /* @__PURE__ */ new Map();
|
|
1596
|
+
registerAction(action, eventName, eventTopic) {
|
|
1597
|
+
if (eventTopic?.length) eventName = `${eventName}:${eventTopic}`;
|
|
1598
|
+
if (!this._actionRegistry.has(eventName)) this._actionRegistry.set(eventName, []);
|
|
1599
|
+
this._actionRegistry.get(eventName)?.push(action);
|
|
1600
|
+
}
|
|
1601
|
+
/**
|
|
1602
|
+
* Starts every action registered for the event.
|
|
1603
|
+
*
|
|
1604
|
+
* @returns A promise that settles once all started actions have finished,
|
|
1605
|
+
* or undefined when no action is registered. It rejects with the failing
|
|
1606
|
+
* action's error, or with an AggregateError when several fail. The Eventbus
|
|
1607
|
+
* watches this promise and reports a rejection like any handler error.
|
|
1608
|
+
*/
|
|
1609
|
+
handleEvent(eventName, eventTopic, args) {
|
|
1610
|
+
if (eventTopic) eventName = `${eventName}:${eventTopic}`;
|
|
1611
|
+
const actions = this._actionRegistry.get(eventName);
|
|
1612
|
+
if (!actions?.length) return;
|
|
1613
|
+
const runs = actions.map((action) => action.start({ eventArgs: Array.isArray(args) ? [...args] : args }));
|
|
1614
|
+
return Promise.allSettled(runs).then((results) => {
|
|
1615
|
+
const errors = results.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
1616
|
+
if (errors.length === 1) throw errors[0];
|
|
1617
|
+
if (errors.length > 1) throw new AggregateError(errors, `${errors.length} event actions failed for '${eventName}'`);
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
|
|
1622
|
+
// src/eventbus/eventbus.ts
|
|
1623
|
+
/**
|
|
1624
|
+
* Maps each once() decorator to the handler it wraps, so off() can remove a
|
|
1625
|
+
* once() registration by the original function.
|
|
1626
|
+
*/
|
|
1627
|
+
const onceOriginals = /* @__PURE__ */ new WeakMap();
|
|
1628
|
+
/**
|
|
1629
|
+
* Central event bus for pub/sub communication and synchronous request/response queries.
|
|
1630
|
+
*
|
|
1631
|
+
* The eventbus supports:
|
|
1632
|
+
* - **Pub/Sub**: `on()`, `once()`, `off()`, `broadcast()`, `broadcastForTopic()`
|
|
1633
|
+
* - **Request/Response**: `onRequest()`, `request()`, `requestForTopic()` for synchronous queries
|
|
1634
|
+
* - **Interceptors**: Transform event arguments before handlers receive them
|
|
1635
|
+
* - **Listeners**: Global event observers for logging/debugging
|
|
1636
|
+
*
|
|
1637
|
+
* @example Pub/Sub pattern
|
|
1638
|
+
* ```ts
|
|
1639
|
+
* const remover = eventbus.on('timeline-play', () => console.log('Playing'));
|
|
1640
|
+
* eventbus.broadcast('timeline-play', []);
|
|
1641
|
+
* remover(); // Unsubscribe
|
|
1642
|
+
* ```
|
|
1643
|
+
*
|
|
1644
|
+
* @example Request/Response pattern
|
|
1645
|
+
* ```ts
|
|
1646
|
+
* eventbus.onRequest('request-instance', (name) => new MyClass(name));
|
|
1647
|
+
* const instance = eventbus.request<MyClass>('request-instance', 'test');
|
|
1648
|
+
* ```
|
|
1649
|
+
*
|
|
1650
|
+
* Broadcasts isolate errors: a handler, listener or interceptor that throws, or
|
|
1651
|
+
* returns a promise that rejects, is reported and the others still run. Request
|
|
1652
|
+
* responders are not isolated; their errors reach the requester.
|
|
1653
|
+
*
|
|
1654
|
+
* @example Observing handler errors
|
|
1655
|
+
* ```ts
|
|
1656
|
+
* const eventbus = new Eventbus({
|
|
1657
|
+
* onHandlerError: (error, {eventName, eventTopic, source}) =>
|
|
1658
|
+
* myLogger.warn(`${source} failed for ${eventName}`, error),
|
|
1659
|
+
* });
|
|
1660
|
+
* ```
|
|
1661
|
+
*/
|
|
1662
|
+
var Eventbus = class {
|
|
1663
|
+
eventHandlers = /* @__PURE__ */ new Map();
|
|
1664
|
+
eventInterceptors = /* @__PURE__ */ new Map();
|
|
1665
|
+
eventListeners = [];
|
|
1666
|
+
requestResponders = /* @__PURE__ */ new Map();
|
|
1667
|
+
onHandlerError;
|
|
1668
|
+
/**
|
|
1669
|
+
* @param options - Optional settings. `onHandlerError` observes errors raised
|
|
1670
|
+
* by handlers, listeners and interceptors during a broadcast. It survives
|
|
1671
|
+
* {@link Eventbus.clear}.
|
|
1672
|
+
*/
|
|
1673
|
+
constructor(options) {
|
|
1674
|
+
this.onHandlerError = options?.onHandlerError;
|
|
1675
|
+
this.clear();
|
|
1676
|
+
}
|
|
1677
|
+
/**
|
|
1678
|
+
* Clears all handlers, listeners, interceptors, and request responders.
|
|
1679
|
+
*/
|
|
1680
|
+
clear() {
|
|
1681
|
+
this.eventHandlers = /* @__PURE__ */ new Map();
|
|
1682
|
+
this.eventListeners = [];
|
|
1683
|
+
this.eventInterceptors = /* @__PURE__ */ new Map();
|
|
1684
|
+
this.requestResponders = /* @__PURE__ */ new Map();
|
|
1685
|
+
}
|
|
1686
|
+
_getEventInterceptors(eventName, eventTopic) {
|
|
1687
|
+
if (eventTopic) eventName = `${eventName}:${eventTopic}`;
|
|
1688
|
+
if (!this.eventInterceptors.has(eventName)) this.eventInterceptors.set(eventName, []);
|
|
1689
|
+
return this.eventInterceptors.get(eventName);
|
|
1690
|
+
}
|
|
1691
|
+
_getEventHandlers(eventName, eventTopic) {
|
|
1692
|
+
if (eventTopic) eventName = `${eventName}:${eventTopic}`;
|
|
1693
|
+
if (!this.eventHandlers.has(eventName)) this.eventHandlers.set(eventName, []);
|
|
1694
|
+
return this.eventHandlers.get(eventName);
|
|
1695
|
+
}
|
|
1696
|
+
on(eventName, eventHandler, eventTopic) {
|
|
1697
|
+
this._getEventHandlers(eventName, eventTopic).push(eventHandler);
|
|
1698
|
+
return () => {
|
|
1699
|
+
this.off(eventName, eventHandler, eventTopic);
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
once(eventName, eventHandler, eventTopic) {
|
|
1703
|
+
let called = false;
|
|
1704
|
+
const eventHandlerDecorator = (...args) => {
|
|
1705
|
+
if (called) return;
|
|
1706
|
+
called = true;
|
|
1707
|
+
this.off(eventName, eventHandlerDecorator, eventTopic);
|
|
1708
|
+
return eventHandler(...args);
|
|
1709
|
+
};
|
|
1710
|
+
onceOriginals.set(eventHandlerDecorator, eventHandler);
|
|
1711
|
+
this.on(eventName, eventHandlerDecorator, eventTopic);
|
|
1712
|
+
return () => {
|
|
1713
|
+
this.off(eventName, eventHandlerDecorator, eventTopic);
|
|
1714
|
+
};
|
|
1715
|
+
}
|
|
1716
|
+
/**
|
|
1717
|
+
* Removes one registration of the handler. A handler registered with
|
|
1718
|
+
* {@link Eventbus.once} can be removed by passing the original function. An
|
|
1719
|
+
* exact registration (through `on()`) is preferred over a `once()` one.
|
|
1720
|
+
*/
|
|
1721
|
+
off(eventName, eventHandler, eventTopic) {
|
|
1722
|
+
const handlers = this._getEventHandlers(eventName, eventTopic);
|
|
1723
|
+
let idx = handlers.indexOf(eventHandler);
|
|
1724
|
+
if (idx === -1) idx = handlers.findIndex((h) => onceOriginals.get(h) === eventHandler);
|
|
1725
|
+
if (idx > -1) handlers.splice(idx, 1);
|
|
1726
|
+
}
|
|
1727
|
+
broadcast(eventName, args) {
|
|
1728
|
+
this._callHandlers(eventName, void 0, args);
|
|
1729
|
+
}
|
|
1730
|
+
broadcastForTopic(eventName, eventTopic, args) {
|
|
1731
|
+
this._callHandlers(eventName, eventTopic, args);
|
|
1732
|
+
}
|
|
1733
|
+
registerEventlistener(eventbusListener) {
|
|
1734
|
+
this.eventListeners.push(eventbusListener);
|
|
1735
|
+
return () => {
|
|
1736
|
+
const index = this.eventListeners.indexOf(eventbusListener);
|
|
1737
|
+
if (index > -1) this.eventListeners.splice(index, 1);
|
|
1738
|
+
};
|
|
1739
|
+
}
|
|
1740
|
+
registerInterceptor(eventName, interceptor, eventTopic) {
|
|
1741
|
+
const interceptors = this._getEventInterceptors(eventName, eventTopic);
|
|
1742
|
+
interceptors.push(interceptor);
|
|
1743
|
+
return () => {
|
|
1744
|
+
const index = interceptors.indexOf(interceptor);
|
|
1745
|
+
if (index > -1) interceptors.splice(index, 1);
|
|
1746
|
+
};
|
|
1747
|
+
}
|
|
1748
|
+
onRequest(eventName, responder, eventTopic) {
|
|
1749
|
+
const responders = this._getRequestResponders(eventName, eventTopic);
|
|
1750
|
+
responders.push(responder);
|
|
1751
|
+
return () => {
|
|
1752
|
+
const index = responders.indexOf(responder);
|
|
1753
|
+
if (index > -1) responders.splice(index, 1);
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
request(eventName, ...args) {
|
|
1757
|
+
return this._callResponder(eventName, void 0, args);
|
|
1758
|
+
}
|
|
1759
|
+
requestForTopic(eventName, eventTopic, ...args) {
|
|
1760
|
+
return this._callResponder(eventName, eventTopic, args);
|
|
1761
|
+
}
|
|
1762
|
+
_getRequestResponders(eventName, eventTopic) {
|
|
1763
|
+
if (eventTopic) eventName = `${eventName}:${eventTopic}`;
|
|
1764
|
+
if (!this.requestResponders.has(eventName)) this.requestResponders.set(eventName, []);
|
|
1765
|
+
return this.requestResponders.get(eventName);
|
|
1766
|
+
}
|
|
1767
|
+
_callResponder(eventName, eventTopic, args) {
|
|
1768
|
+
const responders = this._getRequestResponders(eventName, eventTopic);
|
|
1769
|
+
if (responders.length === 0) return;
|
|
1770
|
+
return responders[0](...args);
|
|
1771
|
+
}
|
|
1772
|
+
_callHandlers(eventName, eventTopic, args = []) {
|
|
1773
|
+
const handlers = this._getEventHandlers(eventName, eventTopic);
|
|
1774
|
+
if (handlers) {
|
|
1775
|
+
const interceptors = this._getEventInterceptors(eventName, eventTopic).slice();
|
|
1776
|
+
const listeners = this.eventListeners.slice();
|
|
1777
|
+
const snapshot = handlers.slice();
|
|
1778
|
+
for (const interceptor of interceptors) try {
|
|
1779
|
+
args = interceptor.intercept(args);
|
|
1780
|
+
} catch (error) {
|
|
1781
|
+
this._reportError(error, eventName, eventTopic, "interceptor");
|
|
1782
|
+
}
|
|
1783
|
+
for (const listener of listeners) try {
|
|
1784
|
+
this._watchResult(listener.handleEvent(eventName, eventTopic, args), eventName, eventTopic, "listener");
|
|
1785
|
+
} catch (error) {
|
|
1786
|
+
this._reportError(error, eventName, eventTopic, "listener");
|
|
1787
|
+
}
|
|
1788
|
+
const hasArgs = args?.length > 0;
|
|
1789
|
+
for (const handler of snapshot) {
|
|
1790
|
+
if (!this._getEventHandlers(eventName, eventTopic).includes(handler)) continue;
|
|
1791
|
+
try {
|
|
1792
|
+
this._watchResult(hasArgs ? handler(...args) : handler(), eventName, eventTopic, "handler");
|
|
1793
|
+
} catch (error) {
|
|
1794
|
+
this._reportError(error, eventName, eventTopic, "handler");
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
/**
|
|
1800
|
+
* Handlers are typed to return void, but async ones return a promise that
|
|
1801
|
+
* nobody awaits. Report its rejection like a synchronous throw.
|
|
1802
|
+
*/
|
|
1803
|
+
_watchResult(result, eventName, eventTopic, source) {
|
|
1804
|
+
if (result && isPromise(result)) result.then(void 0, (error) => this._reportError(error, eventName, eventTopic, source));
|
|
1805
|
+
}
|
|
1806
|
+
/**
|
|
1807
|
+
* Reports an error a component caught, the same way as a failing handler:
|
|
1808
|
+
* `console.error` naming the source, then the `onHandlerError` option with
|
|
1809
|
+
* source `'reported'`. Never throws.
|
|
1810
|
+
*
|
|
1811
|
+
* @param error - The caught error
|
|
1812
|
+
* @param context - The reporting component and, if any, the event it was
|
|
1813
|
+
* handling
|
|
1814
|
+
*/
|
|
1815
|
+
reportError(error, context) {
|
|
1816
|
+
const { source, eventName } = context;
|
|
1817
|
+
const event = eventName ? ` for "${eventName}"` : "";
|
|
1818
|
+
console.error(`Error reported by ${source}${event}:`, error);
|
|
1819
|
+
this._notifyErrorHook(error, {
|
|
1820
|
+
eventName: eventName ?? "",
|
|
1821
|
+
eventTopic: void 0,
|
|
1822
|
+
source: "reported",
|
|
1823
|
+
reporter: source
|
|
1824
|
+
}, `${source}${event}`);
|
|
1825
|
+
}
|
|
1826
|
+
/**
|
|
1827
|
+
* Logs the error with the event name and topic, never the event arguments
|
|
1828
|
+
* (they can carry configuration or user data), then passes it to the
|
|
1829
|
+
* `onHandlerError` option.
|
|
1830
|
+
*/
|
|
1831
|
+
_reportError(error, eventName, eventTopic, source) {
|
|
1832
|
+
const topic = eventTopic ? ` (topic "${eventTopic}")` : "";
|
|
1833
|
+
console.error(`Error in eventbus ${source} for "${eventName}"${topic}:`, error);
|
|
1834
|
+
this._notifyErrorHook(error, {
|
|
1835
|
+
eventName,
|
|
1836
|
+
eventTopic,
|
|
1837
|
+
source
|
|
1838
|
+
}, `"${eventName}"${topic}`);
|
|
1839
|
+
}
|
|
1840
|
+
_notifyErrorHook(error, context, description) {
|
|
1841
|
+
if (!this.onHandlerError) return;
|
|
1842
|
+
try {
|
|
1843
|
+
this.onHandlerError(error, context);
|
|
1844
|
+
} catch (hookError) {
|
|
1845
|
+
console.error(`Error in eventbus onHandlerError for ${description}:`, hookError);
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
};
|
|
1849
|
+
|
|
1850
|
+
// src/controllers/metadata/dom-event-listener-controller.ts
|
|
1851
|
+
function DOMEventListenerController() {
|
|
1852
|
+
return {
|
|
1853
|
+
description: `This controller attaches to the given selected element and adds a DOM event listener for the specified event name that
|
|
1854
|
+
executes the given actions with the given operation data.
|
|
1855
|
+
|
|
1856
|
+
By default the \`start\` operations of the specified actions are executed. To execute the \`end\` operations instead,
|
|
1857
|
+
prefix the action name with \`end:\`.
|
|
1858
|
+
|
|
1859
|
+
The actions receive a copy of \`actionOperationData\` plus \`eventTarget\` (the event's target) and, for key events,
|
|
1860
|
+
\`eventKey\` (the \`KeyboardEvent.key\`). They run in order, each receiving the operation data the previous one
|
|
1861
|
+
returned. When an action fails, the
|
|
1862
|
+
remaining actions are skipped and the failure is reported through the eventbus's \`reportError\` (an error naming
|
|
1863
|
+
this controller, the action and the DOM event, with the original error as \`cause\`), or logged with
|
|
1864
|
+
\`console.error\` when the eventbus has no \`reportError\`.`,
|
|
1865
|
+
dependentProperties: ["selectedElement"],
|
|
1866
|
+
properties: {
|
|
1867
|
+
eventName: {
|
|
1868
|
+
type: "ParameterType:eventName",
|
|
1869
|
+
required: true
|
|
1870
|
+
},
|
|
1871
|
+
actions: {
|
|
1872
|
+
type: "ParameterType:array",
|
|
1873
|
+
itemType: "ParameterType:string"
|
|
1874
|
+
},
|
|
1875
|
+
actionOperationData: { type: "ParameterType:object" }
|
|
1876
|
+
}
|
|
1877
|
+
};
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
// src/controllers/metadata/keyboard-controller.ts
|
|
1881
|
+
function KeyboardController() {
|
|
1882
|
+
return {
|
|
1883
|
+
description: `This controller runs the given actions when one of the given keys is pressed.
|
|
1884
|
+
|
|
1885
|
+
By default the \`start\` operations of the specified actions are executed. To execute the \`end\` operations instead,
|
|
1886
|
+
prefix the action name with \`end:\`.
|
|
1887
|
+
|
|
1888
|
+
The actions receive a copy of \`actionOperationData\` plus \`eventTarget\` (the focused element, or the body when
|
|
1889
|
+
nothing has focus) and \`eventKey\` (the \`KeyboardEvent.key\`). They run in order, each receiving the operation data
|
|
1890
|
+
the previous one returned. When an action fails, the remaining actions are skipped and the failure is reported
|
|
1891
|
+
through the eventbus's \`reportError\`, or logged with \`console.error\` when the eventbus has no \`reportError\`.
|
|
1892
|
+
|
|
1893
|
+
With \`scope: 'document'\` (the default) the keys work while the focus is inside the engine root, or while nothing
|
|
1894
|
+
has focus. With \`scope: 'element'\` they only work while the focus is inside the selected element. Presses in
|
|
1895
|
+
\`input\`, \`select\`, \`textarea\` and contenteditable elements are ignored, so typing keeps working. A handled press
|
|
1896
|
+
has its default action prevented (no scrolling for arrow keys and space); a held key runs the actions once, not
|
|
1897
|
+
again for every key repeat.
|
|
1898
|
+
|
|
1899
|
+
When the keys include the play toggle hotkey of the engine (space by default), or a key that the engine's
|
|
1900
|
+
KeyboardStepSource binds (the arrow keys, \`shift+left\`/\`shift+right\`, \`home\` and \`end\`), the controller wins: a
|
|
1901
|
+
press it handles runs its actions and does not toggle playback or step the timeline. A press it ignores (for
|
|
1902
|
+
example outside the selected element with \`scope: 'element'\`) still does.
|
|
1903
|
+
|
|
1904
|
+
The keys are bound in the hotkeys-js \`'all'\` scope, so they work whatever scope a KeyboardStepSource sets. The
|
|
1905
|
+
hotkeys-js global \`filter\` still applies. Detaching removes only this controller's handler.`,
|
|
1906
|
+
dependentProperties: ["selectedElement"],
|
|
1907
|
+
properties: {
|
|
1908
|
+
keys: {
|
|
1909
|
+
type: "ParameterType:string",
|
|
1910
|
+
required: true
|
|
1911
|
+
},
|
|
1912
|
+
actions: {
|
|
1913
|
+
type: "ParameterType:array",
|
|
1914
|
+
itemType: "ParameterType:string"
|
|
1915
|
+
},
|
|
1916
|
+
actionOperationData: { type: "ParameterType:object" },
|
|
1917
|
+
scope: { type: [{ value: "document" }, { value: "element" }] }
|
|
1918
|
+
}
|
|
1919
|
+
};
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
// src/controllers/metadata/label-controller.ts
|
|
1923
|
+
function LabelController() {
|
|
1924
|
+
return {
|
|
1925
|
+
description: `This controller attaches to the given selected element and renders the text
|
|
1926
|
+
associated with the given translation key.
|
|
1927
|
+
|
|
1928
|
+
Translations may contain simple inline markup. They are passed through
|
|
1929
|
+
\`sanitizeHtml\` before insertion, so \`<br>\`, \`<strong>\`, \`<em>\`,
|
|
1930
|
+
\`<span>\` and http(s)/mailto/relative links render, while scripts, event
|
|
1931
|
+
handlers, \`javascript:\` URLs, images, iframes and SVG are removed.
|
|
1932
|
+
|
|
1933
|
+
The controller listens for the \`language-change\` event and re-renders the text
|
|
1934
|
+
with the new language after such an event.
|
|
1935
|
+
|
|
1936
|
+
Uses the rosetta-based locale system via \`request-translation\` event.`,
|
|
1937
|
+
dependentProperties: ["selectedElement"],
|
|
1938
|
+
properties: {
|
|
1939
|
+
translationKey: {
|
|
1940
|
+
type: "ParameterType:string",
|
|
1941
|
+
required: true
|
|
1942
|
+
},
|
|
1943
|
+
attributeName: { type: "ParameterType:string" }
|
|
1944
|
+
}
|
|
1945
|
+
};
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
// src/controllers/metadata/lottie-controller.ts
|
|
1949
|
+
function LottieController() {
|
|
1950
|
+
return {
|
|
1951
|
+
description: `This controller renders a [lottie-web](https://github.com/airbnb/lottie-web) animation inside the given selected element.
|
|
1952
|
+
|
|
1953
|
+
The url may encode freeze and end positions like this: my-url/filename[freeze=10,end=21].json
|
|
1954
|
+
|
|
1955
|
+
lottie-web is an optional peer dependency. It is loaded with a dynamic
|
|
1956
|
+
\`import()\` the first time a LottieController attaches, so applications that
|
|
1957
|
+
never use this controller do not need it installed.`,
|
|
1958
|
+
properties: { url: { type: "ParameterType:url" } }
|
|
1959
|
+
};
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
// src/controllers/metadata/mutation-observer-controller.ts
|
|
1963
|
+
function MutationObserverController() {
|
|
1964
|
+
return {
|
|
1965
|
+
description: `Controller that observes DOM mutations on a selected element and broadcasts events.
|
|
1966
|
+
|
|
1967
|
+
This controller creates a MutationObserver to monitor DOM changes (attributes, child nodes,
|
|
1968
|
+
text content) on a specified element. All detected mutations are broadcasted through the
|
|
1969
|
+
Eligius eventbus, enabling reactive behavior in response to DOM changes.
|
|
1970
|
+
|
|
1971
|
+
The controller follows the standard Eligius lifecycle:
|
|
1972
|
+
- init(): Store configuration metadata
|
|
1973
|
+
- attach(): Create and start the MutationObserver
|
|
1974
|
+
- detach(): Disconnect the observer and clean up resources`,
|
|
1975
|
+
dependentProperties: ["selectedElement"],
|
|
1976
|
+
properties: {
|
|
1977
|
+
observeAttributes: { type: "ParameterType:boolean" },
|
|
1978
|
+
observeChildList: { type: "ParameterType:boolean" },
|
|
1979
|
+
observeCharacterData: { type: "ParameterType:boolean" },
|
|
1980
|
+
observeSubtree: { type: "ParameterType:boolean" },
|
|
1981
|
+
attributeOldValue: { type: "ParameterType:boolean" },
|
|
1982
|
+
characterDataOldValue: { type: "ParameterType:boolean" },
|
|
1983
|
+
attributeFilter: {
|
|
1984
|
+
type: "ParameterType:array",
|
|
1985
|
+
itemType: "ParameterType:string"
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
};
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
// src/controllers/metadata/navigation-controller.ts
|
|
1992
|
+
function NavigationController() {
|
|
1993
|
+
return {
|
|
1994
|
+
description: `Renders a navigation menu in the selected element and keeps it in sync with
|
|
1995
|
+
the active navigation entry.
|
|
1996
|
+
|
|
1997
|
+
Activating a menu item (click, Enter or Space) navigates to its entry:
|
|
1998
|
+
- an entry with a \`timelineUri\` broadcasts \`request-timeline-uri\`
|
|
1999
|
+
[timelineUri, position], which the engine handles by switching timelines;
|
|
2000
|
+
- an entry without one broadcasts the legacy \`request-video-url\`
|
|
2001
|
+
[videoUrlIndex, position], which the engine does not handle.
|
|
2002
|
+
|
|
2003
|
+
With \`autoNext\`, the next entry is started when the active entry's timeline
|
|
2004
|
+
completes (\`timeline-complete\`) or, for legacy entries, on \`video-complete\`.
|
|
2005
|
+
When the engine switches to a timeline that an entry names
|
|
2006
|
+
(\`timeline-current-timeline-change\`), that entry becomes the active one.`,
|
|
2007
|
+
dependentProperties: ["selectedElement"],
|
|
2008
|
+
properties: { json: {
|
|
2009
|
+
type: "ParameterType:object",
|
|
2010
|
+
required: true
|
|
2011
|
+
} }
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
// src/controllers/metadata/progressbar-controller.ts
|
|
2016
|
+
function ProgressbarController() {
|
|
2017
|
+
return {
|
|
2018
|
+
description: `This controller renders a progressbar that displays the progress of the current timeline in the given selected element.
|
|
2019
|
+
|
|
2020
|
+
The current progress as a percentage is rendered in the given text element.`,
|
|
2021
|
+
dependentProperties: ["selectedElement", "textElement"]
|
|
2022
|
+
};
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
// src/controllers/metadata/routing-controller.ts
|
|
2026
|
+
function RoutingController() {
|
|
2027
|
+
return {
|
|
2028
|
+
description: `Keeps the browser history in sync with the navigation entries: each entry
|
|
2029
|
+
gets a \`#/<id>/<position>\` URL, and back/forward navigation requests the
|
|
2030
|
+
entry in the URL.
|
|
2031
|
+
|
|
2032
|
+
Requests go to the engine as \`request-timeline-uri\` for entries with a
|
|
2033
|
+
\`timelineUri\`, and as the legacy \`request-video-url\` otherwise. Before the
|
|
2034
|
+
engine switches timelines (\`before-request-timeline-uri\`, or the legacy
|
|
2035
|
+
\`before-request-video-url\`), the current entry is saved with its position.
|
|
2036
|
+
|
|
2037
|
+
This is a work in progress, do not use this yet please....`,
|
|
2038
|
+
properties: { json: {
|
|
2039
|
+
type: "ParameterType:object",
|
|
2040
|
+
required: true
|
|
2041
|
+
} }
|
|
2042
|
+
};
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
// src/controllers/metadata/subtitles-controller.ts
|
|
2046
|
+
function SubtitlesController() {
|
|
2047
|
+
return {
|
|
2048
|
+
description: `This controller shows the subtitle whose duration contains the current
|
|
2049
|
+
timeline position in the selected element, in the current language, and
|
|
2050
|
+
re-renders it after a \`language-change\` event.
|
|
2051
|
+
|
|
2052
|
+
The starting language is the locale's current language
|
|
2053
|
+
(\`request-current-language\`); the configured \`language\` is only used when
|
|
2054
|
+
nothing answers that request.
|
|
2055
|
+
|
|
2056
|
+
Subtitle texts may contain simple inline markup. They are passed through
|
|
2057
|
+
\`sanitizeHtml\` before insertion, so \`<br>\`, \`<i>\`, \`<em>\`,
|
|
2058
|
+
\`<strong>\` and \`<span>\` render, while scripts, event handlers,
|
|
2059
|
+
\`javascript:\` URLs, images, iframes and SVG are removed.`,
|
|
2060
|
+
dependentProperties: ["selectedElement"],
|
|
2061
|
+
properties: {
|
|
2062
|
+
language: { type: "ParameterType:languagecode" },
|
|
2063
|
+
subtitleData: { type: "ParameterType:array" }
|
|
2064
|
+
}
|
|
2065
|
+
};
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
// src/controllers/metadata/index.ts
|
|
2069
|
+
var metadata_exports$1 = /* @__PURE__ */ __exportAll({
|
|
2070
|
+
DOMEventListenerController: () => DOMEventListenerController,
|
|
2071
|
+
KeyboardController: () => KeyboardController,
|
|
2072
|
+
LabelController: () => LabelController,
|
|
2073
|
+
LottieController: () => LottieController,
|
|
2074
|
+
MutationObserverController: () => MutationObserverController,
|
|
2075
|
+
NavigationController: () => NavigationController,
|
|
2076
|
+
ProgressbarController: () => ProgressbarController,
|
|
2077
|
+
RoutingController: () => RoutingController,
|
|
2078
|
+
SubtitlesController: () => SubtitlesController
|
|
2079
|
+
});
|
|
2080
|
+
|
|
2081
|
+
// src/operation/metadata/add-class.ts
|
|
2082
|
+
function addClass() {
|
|
2083
|
+
return {
|
|
2084
|
+
description: `This operation adds the specified class name to the specified selected element.`,
|
|
2085
|
+
category: `DOM`,
|
|
2086
|
+
dependentProperties: ["selectedElement"],
|
|
2087
|
+
properties: { className: {
|
|
2088
|
+
type: "ParameterType:className",
|
|
2089
|
+
required: true,
|
|
2090
|
+
erased: true
|
|
2091
|
+
} }
|
|
2092
|
+
};
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
// src/operation/metadata/add-controller-to-element.ts
|
|
2096
|
+
function addControllerToElement() {
|
|
2097
|
+
return {
|
|
2098
|
+
description: `This operation adds the specified controller instance to the given selected element.
|
|
2099
|
+
|
|
2100
|
+
The controller is registered on the element only once \`init\` and a synchronous \`attach\`
|
|
2101
|
+
have succeeded. When \`attach\` returns a promise, the controller is registered before
|
|
2102
|
+
that promise settles (so detaching the element can still reach it) and is removed from
|
|
2103
|
+
the element again when the promise rejects.`,
|
|
2104
|
+
category: `Controller`,
|
|
2105
|
+
dependentProperties: ["selectedElement", "controllerInstance"]
|
|
2106
|
+
};
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2109
|
+
// src/operation/metadata/add-globals-to-operation.ts
|
|
2110
|
+
function addGlobalsToOperation() {
|
|
2111
|
+
return {
|
|
2112
|
+
description: `This operation adds the specified global property names to the current operation data.
|
|
2113
|
+
It finally removes the \`globalProperties\` property from the current operation data.
|
|
2114
|
+
|
|
2115
|
+
Plain data is copied, so changing it does not change the global store. jQuery objects, DOM
|
|
2116
|
+
nodes, functions and class instances (such as controllers) are added by reference.`,
|
|
2117
|
+
category: `Data`,
|
|
2118
|
+
properties: { globalProperties: {
|
|
2119
|
+
type: "ParameterType:array",
|
|
2120
|
+
itemType: "ParameterType:string",
|
|
2121
|
+
required: true,
|
|
2122
|
+
erased: true
|
|
2123
|
+
} }
|
|
2124
|
+
};
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
// src/operation/metadata/animate-with-class.ts
|
|
2128
|
+
function animateWithClass() {
|
|
2129
|
+
return {
|
|
2130
|
+
description: `This operation adds the specified class name to the specified selected element and assumes that this
|
|
2131
|
+
class triggers an animation on the selected element. It then waits for this animation to complete
|
|
2132
|
+
before it resolves.
|
|
2133
|
+
|
|
2134
|
+
The class must put the animation on the selected element itself: \`animationend\` events that bubble up
|
|
2135
|
+
from descendants are ignored, and with several selected elements the operation waits for all of them.
|
|
2136
|
+
Set \`includeDescendants\` to true for a class that only animates descendants; the operation then resolves
|
|
2137
|
+
on the first \`animationend\` from the element or its subtree.
|
|
2138
|
+
|
|
2139
|
+
The operation resolves immediately when the selection is empty, or when the class gives none of the
|
|
2140
|
+
selected elements a CSS animation (for example under \`prefers-reduced-motion: reduce\`). When an
|
|
2141
|
+
\`animationend\` event never arrives, for example because the element was hidden or removed while
|
|
2142
|
+
animating, it resolves shortly after the longest computed animation should have ended. An infinite
|
|
2143
|
+
animation is waited for until it is ended by an \`animationend\` event.`,
|
|
2144
|
+
category: `Animation`,
|
|
2145
|
+
dependentProperties: ["selectedElement"],
|
|
2146
|
+
properties: {
|
|
2147
|
+
className: {
|
|
2148
|
+
type: "ParameterType:className",
|
|
2149
|
+
required: true,
|
|
2150
|
+
erased: true
|
|
2151
|
+
},
|
|
2152
|
+
removeClass: {
|
|
2153
|
+
type: "ParameterType:boolean",
|
|
2154
|
+
erased: true
|
|
2155
|
+
},
|
|
2156
|
+
includeDescendants: {
|
|
2157
|
+
type: "ParameterType:boolean",
|
|
2158
|
+
erased: true
|
|
2159
|
+
}
|
|
2160
|
+
}
|
|
2161
|
+
};
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
// src/operation/metadata/animate.ts
|
|
2165
|
+
function animate() {
|
|
2166
|
+
return {
|
|
2167
|
+
description: `This operation animates the specified selected element with the given [jQuery animation](https://api.jquery.com/animate/) properties, duration and easing.
|
|
2168
|
+
It resolves after the animation completes, or immediately when the selected element set is empty.`,
|
|
2169
|
+
category: `Animation`,
|
|
2170
|
+
dependentProperties: ["selectedElement"],
|
|
2171
|
+
properties: {
|
|
2172
|
+
animationEasing: {
|
|
2173
|
+
type: "ParameterType:string",
|
|
2174
|
+
erased: true
|
|
2175
|
+
},
|
|
2176
|
+
animationProperties: {
|
|
2177
|
+
type: "ParameterType:object",
|
|
2178
|
+
required: true,
|
|
2179
|
+
erased: true
|
|
2180
|
+
},
|
|
2181
|
+
animationDuration: {
|
|
2182
|
+
type: "ParameterType:number",
|
|
2183
|
+
required: true,
|
|
2184
|
+
erased: true
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
};
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
// src/operation/metadata/announce-to-screen-reader.ts
|
|
2191
|
+
function announceToScreenReader() {
|
|
2192
|
+
return {
|
|
2193
|
+
description: `Announces a message to screen readers using an ARIA live region.
|
|
2194
|
+
|
|
2195
|
+
The live region (\`#aria-live-region\`) is created empty on first use. The region is emptied
|
|
2196
|
+
and the message is written 100 milliseconds later, so that a new region
|
|
2197
|
+
and a message repeated verbatim are both announced. The message is removed again after 5 seconds.
|
|
2198
|
+
A newer announcement replaces a pending one.
|
|
2199
|
+
|
|
2200
|
+
The operation returns at once and does not wait for the message to be written.`,
|
|
2201
|
+
category: `Accessibility`,
|
|
2202
|
+
properties: {
|
|
2203
|
+
message: {
|
|
2204
|
+
type: "ParameterType:string",
|
|
2205
|
+
required: true,
|
|
2206
|
+
erased: true
|
|
2207
|
+
},
|
|
2208
|
+
priority: {
|
|
2209
|
+
type: [{ value: "polite" }, { value: "assertive" }],
|
|
2210
|
+
erased: true
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
};
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
// src/operation/metadata/break-for-each.ts
|
|
2217
|
+
function breakForEach() {
|
|
2218
|
+
return {
|
|
2219
|
+
description: `This operation should only be used within a loop, so between a {@link forEach} and {@link endForEach}
|
|
2220
|
+
operation. This operation immediately moves to the loop end index, effectively stopping the loop.
|
|
2221
|
+
|
|
2222
|
+
It can be placed inside a \`when\`/\`otherwise\`/\`endWhen\` block within the loop, to break conditionally.`,
|
|
2223
|
+
category: `Control Flow`
|
|
2224
|
+
};
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
// src/operation/metadata/broadcast-event.ts
|
|
2228
|
+
function broadcastEvent() {
|
|
2229
|
+
return {
|
|
2230
|
+
description: `This operation broadcasts the given event through the eventbus, along with the
|
|
2231
|
+
event arguments and optional event topic.`,
|
|
2232
|
+
category: `Utility`,
|
|
2233
|
+
properties: {
|
|
2234
|
+
eventArgs: {
|
|
2235
|
+
type: "ParameterType:array",
|
|
2236
|
+
required: true,
|
|
2237
|
+
erased: true
|
|
2238
|
+
},
|
|
2239
|
+
eventTopic: {
|
|
2240
|
+
type: "ParameterType:eventTopic",
|
|
2241
|
+
erased: true
|
|
2242
|
+
},
|
|
2243
|
+
eventName: {
|
|
2244
|
+
type: "ParameterType:eventName",
|
|
2245
|
+
required: true,
|
|
2246
|
+
erased: true
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
};
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
// src/operation/metadata/calc.ts
|
|
2253
|
+
function calc() {
|
|
2254
|
+
return {
|
|
2255
|
+
description: `This operation calculates the given left and right hand operands using the specified operator.
|
|
2256
|
+
|
|
2257
|
+
\`left\`, \`right\` and \`operator\` may be property chains (\`$operationdata.\`, \`$globaldata.\`,
|
|
2258
|
+
\`$scope.\`). Only these three inputs are resolved; the rest of the operation data is left as
|
|
2259
|
+
it is.`,
|
|
2260
|
+
category: `Utility`,
|
|
2261
|
+
properties: {
|
|
2262
|
+
left: {
|
|
2263
|
+
type: "ParameterType:number",
|
|
2264
|
+
required: true,
|
|
2265
|
+
erased: true
|
|
2266
|
+
},
|
|
2267
|
+
right: {
|
|
2268
|
+
type: "ParameterType:number",
|
|
2269
|
+
required: true,
|
|
2270
|
+
erased: true
|
|
2271
|
+
},
|
|
2272
|
+
operator: {
|
|
2273
|
+
type: [
|
|
2274
|
+
{ value: "+" },
|
|
2275
|
+
{ value: "-" },
|
|
2276
|
+
{ value: "*" },
|
|
2277
|
+
{ value: "/" },
|
|
2278
|
+
{ value: "%" },
|
|
2279
|
+
{ value: "**" }
|
|
2280
|
+
],
|
|
2281
|
+
required: true,
|
|
2282
|
+
erased: true
|
|
2283
|
+
}
|
|
2284
|
+
},
|
|
2285
|
+
outputProperties: { calculationResult: { type: "ParameterType:number" } }
|
|
2286
|
+
};
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2289
|
+
// src/operation/metadata/clear-element.ts
|
|
2290
|
+
function clearElement() {
|
|
2291
|
+
return {
|
|
2292
|
+
description: `This operation removes all of the children from the given selected element.
|
|
2293
|
+
|
|
2294
|
+
Controllers attached to the removed children or their descendants (by \`addControllerToElement\`)
|
|
2295
|
+
are detached first. Controllers on the selected element itself stay attached.`,
|
|
2296
|
+
category: `DOM`,
|
|
2297
|
+
dependentProperties: ["selectedElement"]
|
|
2298
|
+
};
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2301
|
+
// src/operation/metadata/clear-operation-data.ts
|
|
2302
|
+
function clearOperationData() {
|
|
2303
|
+
return {
|
|
2304
|
+
description: `This operation removes all of the properties on the current operation date.
|
|
2305
|
+
Or, if the \`properties\` property is set only removes the properties defined by that list.`,
|
|
2306
|
+
category: `Data`,
|
|
2307
|
+
properties: { properties: {
|
|
2308
|
+
type: "ParameterType:array",
|
|
2309
|
+
itemType: "ParameterType:string",
|
|
2310
|
+
erased: true
|
|
2311
|
+
} }
|
|
2312
|
+
};
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
// src/operation/metadata/clear-storage.ts
|
|
2316
|
+
function clearStorage() {
|
|
2317
|
+
return {
|
|
2318
|
+
description: `Clears data from browser storage (localStorage or sessionStorage).
|
|
2319
|
+
|
|
2320
|
+
If \`key\` is provided, removes only that key. If \`key\` is omitted, clears all storage.
|
|
2321
|
+
A \`key\` that is present but empty, blank or not a string is rejected, so a value resolved
|
|
2322
|
+
from missing data never wipes the whole storage.`,
|
|
2323
|
+
category: `Data`,
|
|
2324
|
+
properties: {
|
|
2325
|
+
key: {
|
|
2326
|
+
type: "ParameterType:string",
|
|
2327
|
+
erased: true
|
|
2328
|
+
},
|
|
2329
|
+
storageType: {
|
|
2330
|
+
type: [{ value: "local" }, { value: "session" }],
|
|
2331
|
+
required: true,
|
|
2332
|
+
erased: true
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
};
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
// src/operation/metadata/compare-date.ts
|
|
2339
|
+
function compareDate() {
|
|
2340
|
+
return {
|
|
2341
|
+
description: `Compares two dates.
|
|
2342
|
+
comparison: -1 (before), 0 (equal), 1 (after)`,
|
|
2343
|
+
category: `Date`,
|
|
2344
|
+
properties: {
|
|
2345
|
+
date1: {
|
|
2346
|
+
type: "ParameterType:string|ParameterType:number|ParameterType:Date",
|
|
2347
|
+
required: true,
|
|
2348
|
+
erased: true
|
|
2349
|
+
},
|
|
2350
|
+
date2: {
|
|
2351
|
+
type: "ParameterType:string|ParameterType:number|ParameterType:Date",
|
|
2352
|
+
required: true,
|
|
2353
|
+
erased: true
|
|
2354
|
+
}
|
|
2355
|
+
},
|
|
2356
|
+
outputProperties: {
|
|
2357
|
+
comparison: { type: "ParameterType:number" },
|
|
2358
|
+
isEqual: { type: "ParameterType:boolean" },
|
|
2359
|
+
isBefore: { type: "ParameterType:boolean" },
|
|
2360
|
+
isAfter: { type: "ParameterType:boolean" }
|
|
2361
|
+
}
|
|
2362
|
+
};
|
|
2363
|
+
}
|
|
2364
|
+
|
|
2365
|
+
// src/operation/metadata/concatenate-strings.ts
|
|
2366
|
+
function concatenateStrings() {
|
|
2367
|
+
return {
|
|
2368
|
+
description: `Concatenates multiple strings with an optional separator.`,
|
|
2369
|
+
category: `String`,
|
|
2370
|
+
properties: {
|
|
2371
|
+
strings: {
|
|
2372
|
+
type: "ParameterType:array",
|
|
2373
|
+
itemType: "ParameterType:string",
|
|
2374
|
+
required: true,
|
|
2375
|
+
erased: true
|
|
2376
|
+
},
|
|
2377
|
+
separator: {
|
|
2378
|
+
type: "ParameterType:string",
|
|
2379
|
+
erased: true
|
|
2380
|
+
}
|
|
2381
|
+
},
|
|
2382
|
+
outputProperties: { result: { type: "ParameterType:string" } }
|
|
2383
|
+
};
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2386
|
+
// src/operation/metadata/continue-for-each.ts
|
|
2387
|
+
function continueForEach() {
|
|
2388
|
+
return {
|
|
2389
|
+
description: `This operation should only be used within a loop, so between a {@link forEach} and {@link endForEach}
|
|
2390
|
+
operation. This operation immediately moves to the next loop index, effectively canceling the rest
|
|
2391
|
+
of the operations in the current iteration.
|
|
2392
|
+
|
|
2393
|
+
It can be placed inside a \`when\`/\`otherwise\`/\`endWhen\` block within the loop, to continue conditionally.`,
|
|
2394
|
+
category: `Control Flow`
|
|
2395
|
+
};
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
// src/operation/metadata/create-element.ts
|
|
2399
|
+
function createElement() {
|
|
2400
|
+
return {
|
|
2401
|
+
description: `This operation creates the DOM element described by the given elementName and attributes and assigns
|
|
2402
|
+
the instance to the \`template\` property on the current operation data.
|
|
2403
|
+
|
|
2404
|
+
The element is built with DOM APIs: attribute values are set with \`.attr()\` and \`text\` is set as
|
|
2405
|
+
text content, so neither is parsed as HTML.
|
|
2406
|
+
|
|
2407
|
+
Values may be resolved from user data, so nothing that runs script is created: \`script\`
|
|
2408
|
+
elements, event handler (\`on*\`) and \`srcdoc\` attributes, and \`javascript:\` or \`vbscript:\`
|
|
2409
|
+
URLs in URL attributes such as \`href\`, \`src\` and \`formaction\` are refused.`,
|
|
2410
|
+
category: `DOM`,
|
|
2411
|
+
properties: {
|
|
2412
|
+
elementName: {
|
|
2413
|
+
type: "ParameterType:htmlElementName",
|
|
2414
|
+
required: true,
|
|
2415
|
+
erased: true
|
|
2416
|
+
},
|
|
2417
|
+
text: {
|
|
2418
|
+
type: "ParameterType:string",
|
|
2419
|
+
erased: true
|
|
2420
|
+
},
|
|
2421
|
+
attributes: {
|
|
2422
|
+
type: "ParameterType:object",
|
|
2423
|
+
erased: true
|
|
2424
|
+
}
|
|
2425
|
+
},
|
|
2426
|
+
outputProperties: { template: { type: "ParameterType:object" } }
|
|
2427
|
+
};
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2430
|
+
// src/operation/metadata/custom-function.ts
|
|
2431
|
+
function customFunction() {
|
|
2432
|
+
return {
|
|
2433
|
+
description: `This operation retrieves a custom function defined by the given system name
|
|
2434
|
+
and invokes it with the current operation data and eventbus.
|
|
2435
|
+
|
|
2436
|
+
The function is looked up with the \`request-function\` event, which the
|
|
2437
|
+
\`EngineFactory\` answers from its resource importer. Register the function
|
|
2438
|
+
with the \`EligiusResourceImporter\` constructor:
|
|
2439
|
+
\`new EligiusResourceImporter({functions: {myFunction}})\`.
|
|
2440
|
+
|
|
2441
|
+
The function is called with the current operation data as its argument, and with \`this\`
|
|
2442
|
+
set to a view of the operation scope. Reading a property from \`this\` returns it from the
|
|
2443
|
+
innermost scope that has it, so inside a \`when\` block in a loop \`this.currentItem\`,
|
|
2444
|
+
\`this.loopIndex\` and \`this.variables\` return the loop's and the action's values, the same
|
|
2445
|
+
as \`$scope.\` chains. Assigning to \`this\` (for example \`this.newIndex\`) writes to the scope the
|
|
2446
|
+
operation runs in.`,
|
|
2447
|
+
category: `Utility`,
|
|
2448
|
+
properties: { systemName: {
|
|
2449
|
+
type: "ParameterType:systemName",
|
|
2450
|
+
required: true,
|
|
2451
|
+
erased: true
|
|
2452
|
+
} }
|
|
2453
|
+
};
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
// src/operation/metadata/end-action.ts
|
|
2457
|
+
function endAction() {
|
|
2458
|
+
return {
|
|
2459
|
+
description: `This operation invokes the {@link EndableAction}.end method on the specified action instance.
|
|
2460
|
+
|
|
2461
|
+
The action receives its own copy of the current operation data merged with the action
|
|
2462
|
+
operation data. Whatever the action's end operations add, change or remove in that copy stays
|
|
2463
|
+
with the action: once it has completed, this operation continues with the operation data it
|
|
2464
|
+
had before, without the \`actionOperationData\` property.`,
|
|
2465
|
+
category: `Action`,
|
|
2466
|
+
dependentProperties: ["actionInstance"],
|
|
2467
|
+
properties: { actionOperationData: {
|
|
2468
|
+
type: "ParameterType:object",
|
|
2469
|
+
erased: true
|
|
2470
|
+
} }
|
|
2471
|
+
};
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2474
|
+
// src/operation/metadata/end-for-each.ts
|
|
2475
|
+
function endForEach() {
|
|
2476
|
+
return {
|
|
2477
|
+
description: `This operation checks if the current loop should end or start the next iteration.`,
|
|
2478
|
+
category: `Control Flow`
|
|
2479
|
+
};
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2482
|
+
// src/operation/metadata/end-when.ts
|
|
2483
|
+
function endWhen() {
|
|
2484
|
+
return {
|
|
2485
|
+
description: `This operation cleans up after the {@link when}/{@link otherwise}/{@link endWhen} control flow ends.`,
|
|
2486
|
+
category: `Control Flow`
|
|
2487
|
+
};
|
|
2488
|
+
}
|
|
2489
|
+
|
|
2490
|
+
// src/operation/metadata/extend-controller.ts
|
|
2491
|
+
function extendController() {
|
|
2492
|
+
return {
|
|
2493
|
+
description: `Extends the current controller with given extension.
|
|
2494
|
+
|
|
2495
|
+
The extension's own properties are copied onto the controller instance.`,
|
|
2496
|
+
category: `Controller`,
|
|
2497
|
+
dependentProperties: ["controllerInstance"],
|
|
2498
|
+
properties: { controllerExtension: {
|
|
2499
|
+
type: "ParameterType:object",
|
|
2500
|
+
required: true,
|
|
2501
|
+
erased: true
|
|
2502
|
+
} }
|
|
2503
|
+
};
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
// src/operation/metadata/filter-array.ts
|
|
2507
|
+
function filterArray() {
|
|
2508
|
+
return {
|
|
2509
|
+
description: `Filters an array based on property equality or custom predicate function.
|
|
2510
|
+
|
|
2511
|
+
Operates on arrayData passed from previous operations.
|
|
2512
|
+
Supports two filtering modes:
|
|
2513
|
+
1. Property equality: \`filterProperty\` and \`filterValue\` to filter by property match
|
|
2514
|
+
2. Custom predicate: \`filterPredicate\` function for complex filtering logic`,
|
|
2515
|
+
category: `Array`,
|
|
2516
|
+
dependentProperties: ["arrayData"],
|
|
2517
|
+
properties: {
|
|
2518
|
+
filterProperty: {
|
|
2519
|
+
type: "ParameterType:string",
|
|
2520
|
+
erased: true
|
|
2521
|
+
},
|
|
2522
|
+
filterValue: {
|
|
2523
|
+
type: "ParameterType:object",
|
|
2524
|
+
erased: true
|
|
2525
|
+
},
|
|
2526
|
+
filterPredicate: {
|
|
2527
|
+
type: "ParameterType:function",
|
|
2528
|
+
erased: true
|
|
2529
|
+
}
|
|
2530
|
+
},
|
|
2531
|
+
outputProperties: { filteredArray: { type: "ParameterType:array" } }
|
|
2532
|
+
};
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2535
|
+
// src/operation/metadata/find-in-array.ts
|
|
2536
|
+
function findInArray() {
|
|
2537
|
+
return {
|
|
2538
|
+
description: `Finds the first element in an array matching criteria.
|
|
2539
|
+
|
|
2540
|
+
Operates on arrayData passed from previous operations.
|
|
2541
|
+
Supports two search modes:
|
|
2542
|
+
1. Property equality: \`findProperty\` and \`findValue\` to find by property match
|
|
2543
|
+
2. Custom predicate: \`findPredicate\` function for complex search logic
|
|
2544
|
+
|
|
2545
|
+
Returns \`undefined\` for \`foundItem\` and \`-1\` for \`foundIndex\` if no match found.`,
|
|
2546
|
+
category: `Array`,
|
|
2547
|
+
dependentProperties: ["arrayData"],
|
|
2548
|
+
properties: {
|
|
2549
|
+
findProperty: {
|
|
2550
|
+
type: "ParameterType:string",
|
|
2551
|
+
erased: true
|
|
2552
|
+
},
|
|
2553
|
+
findValue: {
|
|
2554
|
+
type: "ParameterType:object",
|
|
2555
|
+
erased: true
|
|
2556
|
+
},
|
|
2557
|
+
findPredicate: {
|
|
2558
|
+
type: "ParameterType:function",
|
|
2559
|
+
erased: true
|
|
2560
|
+
}
|
|
2561
|
+
},
|
|
2562
|
+
outputProperties: {
|
|
2563
|
+
foundItem: { type: "ParameterType:object" },
|
|
2564
|
+
foundIndex: { type: "ParameterType:number" }
|
|
2565
|
+
}
|
|
2566
|
+
};
|
|
2567
|
+
}
|
|
2568
|
+
|
|
2569
|
+
// src/operation/metadata/for-each.ts
|
|
2570
|
+
function forEach() {
|
|
2571
|
+
return {
|
|
2572
|
+
description: `This operation iterates over the given collection.
|
|
2573
|
+
|
|
2574
|
+
Each iteration the current item from the specified collection is
|
|
2575
|
+
assigned to the {@link IOperationScope.currentItem |currentItem} property on the {@link IOperationScope |operation scope}.
|
|
2576
|
+
|
|
2577
|
+
At the start of the loop, the associated {@link endForEach} operation is determined and when
|
|
2578
|
+
the last iteration is completed the flow control is set to the index of that operation.
|
|
2579
|
+
|
|
2580
|
+
The {@link continueForEach |continue} and {@link breakForEach |break} operations can be used to control the
|
|
2581
|
+
loop iterations.
|
|
2582
|
+
|
|
2583
|
+
The collection is resolved once, when the loop starts, and the loop iterates over a snapshot
|
|
2584
|
+
of it. Changing, replacing or removing the source collection inside the loop body does not
|
|
2585
|
+
change the items or the number of iterations of the running loop.`,
|
|
2586
|
+
category: `Control Flow`,
|
|
2587
|
+
properties: { collection: {
|
|
2588
|
+
type: "ParameterType:array|ParameterType:string",
|
|
2589
|
+
required: true
|
|
2590
|
+
} }
|
|
2591
|
+
};
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2594
|
+
// src/operation/metadata/format-date.ts
|
|
2595
|
+
function formatDate() {
|
|
2596
|
+
return {
|
|
2597
|
+
description: `Formats a date with a simple token pattern, in the local time zone.
|
|
2598
|
+
|
|
2599
|
+
Supported tokens (every occurrence is replaced, other characters are kept as is):
|
|
2600
|
+
- \`YYYY\`: four digit year
|
|
2601
|
+
- \`MM\`: month, 01-12
|
|
2602
|
+
- \`DD\`: day of the month, 01-31
|
|
2603
|
+
- \`HH\`: hours, 00-23
|
|
2604
|
+
- \`mm\`: minutes, 00-59
|
|
2605
|
+
- \`ss\`: seconds, 00-59`,
|
|
2606
|
+
category: `Date`,
|
|
2607
|
+
dependentProperties: ["date"],
|
|
2608
|
+
properties: { format: {
|
|
2609
|
+
type: "ParameterType:string",
|
|
2610
|
+
required: true,
|
|
2611
|
+
erased: true
|
|
2612
|
+
} },
|
|
2613
|
+
outputProperties: { formattedDate: { type: "ParameterType:string" } }
|
|
2614
|
+
};
|
|
2615
|
+
}
|
|
2616
|
+
|
|
2617
|
+
// src/operation/metadata/format-text.ts
|
|
2618
|
+
function formatText() {
|
|
2619
|
+
return {
|
|
2620
|
+
description: `Transforms text using format operations: uppercase, lowercase, capitalize, titlecase, or trim.
|
|
2621
|
+
|
|
2622
|
+
Operates on textContent passed from previous operations (e.g., getTextContent).
|
|
2623
|
+
|
|
2624
|
+
Transformations:
|
|
2625
|
+
- \`uppercase\`: Convert all characters to uppercase
|
|
2626
|
+
- \`lowercase\`: Convert all characters to lowercase
|
|
2627
|
+
- \`capitalize\`: Capitalize only the first letter
|
|
2628
|
+
- \`titlecase\`: Capitalize first letter of each word
|
|
2629
|
+
- \`trim\`: Remove leading and trailing whitespace`,
|
|
2630
|
+
category: `Text`,
|
|
2631
|
+
dependentProperties: ["textContent"],
|
|
2632
|
+
properties: { transformation: {
|
|
2633
|
+
type: [
|
|
2634
|
+
{ value: "uppercase" },
|
|
2635
|
+
{ value: "lowercase" },
|
|
2636
|
+
{ value: "capitalize" },
|
|
2637
|
+
{ value: "titlecase" },
|
|
2638
|
+
{ value: "trim" }
|
|
2639
|
+
],
|
|
2640
|
+
required: true,
|
|
2641
|
+
erased: true
|
|
2642
|
+
} },
|
|
2643
|
+
outputProperties: { formattedText: { type: "ParameterType:string" } }
|
|
2644
|
+
};
|
|
2645
|
+
}
|
|
2646
|
+
|
|
2647
|
+
// src/operation/metadata/get-attributes-from-element.ts
|
|
2648
|
+
function getAttributesFromElement() {
|
|
2649
|
+
return {
|
|
2650
|
+
description: `This operation retrieves the values for the specified attribute names from the given selected element.`,
|
|
2651
|
+
category: `DOM`,
|
|
2652
|
+
dependentProperties: ["selectedElement"],
|
|
2653
|
+
properties: { attributeNames: {
|
|
2654
|
+
type: "ParameterType:array",
|
|
2655
|
+
itemType: "ParameterType:string",
|
|
2656
|
+
required: true,
|
|
2657
|
+
erased: true
|
|
2658
|
+
} },
|
|
2659
|
+
outputProperties: { attributeValues: { type: "ParameterType:object" } }
|
|
2660
|
+
};
|
|
2661
|
+
}
|
|
2662
|
+
|
|
2663
|
+
// src/operation/metadata/get-controller-from-element.ts
|
|
2664
|
+
function getControllerFromElement() {
|
|
2665
|
+
return {
|
|
2666
|
+
description: `This operation retrieves the controller instance with the specified name that is assigned to the given selected element.`,
|
|
2667
|
+
category: `Controller`,
|
|
2668
|
+
dependentProperties: ["selectedElement"],
|
|
2669
|
+
properties: { controllerName: {
|
|
2670
|
+
type: "ParameterType:controllerName",
|
|
2671
|
+
required: true,
|
|
2672
|
+
erased: true
|
|
2673
|
+
} },
|
|
2674
|
+
outputProperties: { controllerInstance: { type: "ParameterType:object" } }
|
|
2675
|
+
};
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
// src/operation/metadata/get-controller-instance.ts
|
|
2679
|
+
function getControllerInstance() {
|
|
2680
|
+
return {
|
|
2681
|
+
description: `This operation retrieves an instance of the given controller name.
|
|
2682
|
+
It assigns this instance to the \`controllerInstance\` property on the current operation data`,
|
|
2683
|
+
category: `Controller`,
|
|
2684
|
+
properties: { systemName: {
|
|
2685
|
+
type: "ParameterType:controllerName",
|
|
2686
|
+
required: true,
|
|
2687
|
+
erased: true
|
|
2688
|
+
} },
|
|
2689
|
+
outputProperties: { controllerInstance: { type: "ParameterType:object" } }
|
|
2690
|
+
};
|
|
2691
|
+
}
|
|
2692
|
+
|
|
2693
|
+
// src/operation/metadata/get-current-time.ts
|
|
2694
|
+
function getCurrentTime() {
|
|
2695
|
+
return {
|
|
2696
|
+
description: `Gets the current time as timestamp and Date object.`,
|
|
2697
|
+
category: `Date`,
|
|
2698
|
+
outputProperties: {
|
|
2699
|
+
timestamp: { type: "ParameterType:number" },
|
|
2700
|
+
date: { type: "ParameterType:Date" }
|
|
2701
|
+
}
|
|
2702
|
+
};
|
|
2703
|
+
}
|
|
2704
|
+
|
|
2705
|
+
// src/operation/metadata/get-element-dimensions.ts
|
|
2706
|
+
function getElementDimensions() {
|
|
2707
|
+
return {
|
|
2708
|
+
description: `This operation calculates the width and height of the given selected element.
|
|
2709
|
+
It assigns this struct to the dimensions property on the current operation data.
|
|
2710
|
+
Optionally the width and height can be modified using the given modifier string.
|
|
2711
|
+
|
|
2712
|
+
The modifier string is formatted in the following way:
|
|
2713
|
+
|
|
2714
|
+
<operator><amount><optional-side><optional-precentage>|<ratio-definition>
|
|
2715
|
+
|
|
2716
|
+
Where the ratio modifier is formatted in the following way:
|
|
2717
|
+
<side>[ar=<ratio-left>-<ratio-right>]
|
|
2718
|
+
|
|
2719
|
+
For example, this modifier '+100h|w[ar=8-1]' will modifiy the dimensions like this:
|
|
2720
|
+
it will add a value of 100 to the height and modify the width by a ratio of 8 to 1 relative to the height.`,
|
|
2721
|
+
category: `DOM`,
|
|
2722
|
+
dependentProperties: ["selectedElement"],
|
|
2723
|
+
properties: { modifier: {
|
|
2724
|
+
type: "ParameterType:dimensionsModifier",
|
|
2725
|
+
erased: true
|
|
2726
|
+
} },
|
|
2727
|
+
outputProperties: { dimensions: { type: "ParameterType:object" } }
|
|
2728
|
+
};
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
// src/operation/metadata/get-focused-element.ts
|
|
2732
|
+
function getFocusedElement() {
|
|
2733
|
+
return {
|
|
2734
|
+
description: `Gets the currently focused element.`,
|
|
2735
|
+
category: `Focus`,
|
|
2736
|
+
outputProperties: { focusedElement: { type: "ParameterType:jQuery" } }
|
|
2737
|
+
};
|
|
2738
|
+
}
|
|
2739
|
+
|
|
2740
|
+
// src/operation/metadata/get-form-data.ts
|
|
2741
|
+
function getFormData() {
|
|
2742
|
+
return {
|
|
2743
|
+
description: `Extracts all input, select, and textarea values from form element into operation data.
|
|
2744
|
+
|
|
2745
|
+
This operation reads form field values and returns them as an object with field names as keys.
|
|
2746
|
+
Only processes form elements that are enabled and not hidden. Handles checkboxes, radio buttons,
|
|
2747
|
+
select elements, textareas, and text inputs.`,
|
|
2748
|
+
category: `Form`,
|
|
2749
|
+
dependentProperties: ["selectedElement"],
|
|
2750
|
+
outputProperties: { formData: { type: "ParameterType:object" } }
|
|
2751
|
+
};
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2754
|
+
// src/operation/metadata/get-import.ts
|
|
2755
|
+
function getImport() {
|
|
2756
|
+
return {
|
|
2757
|
+
description: `This operation retrieves the import specified by the given \`systemName\` and
|
|
2758
|
+
assigns it to the \`importedInstance\` property on the current operaton date.
|
|
2759
|
+
|
|
2760
|
+
The import is looked up with the \`request-function\` event, which the
|
|
2761
|
+
\`EngineFactory\` answers from its resource importer. Functions, templates
|
|
2762
|
+
and JSON registered with the \`EligiusResourceImporter\` constructor
|
|
2763
|
+
(\`new EligiusResourceImporter({json: {settings}})\`) can be imported this
|
|
2764
|
+
way, as can every built-in operation, controller and provider export.`,
|
|
2765
|
+
category: `Utility`,
|
|
2766
|
+
properties: { systemName: {
|
|
2767
|
+
type: "ParameterType:systemName",
|
|
2768
|
+
required: true,
|
|
2769
|
+
erased: true
|
|
2770
|
+
} },
|
|
2771
|
+
outputProperties: { importedInstance: { type: "ParameterType:object" } }
|
|
2772
|
+
};
|
|
2773
|
+
}
|
|
2774
|
+
|
|
2775
|
+
// src/operation/metadata/get-query-params.ts
|
|
2776
|
+
function getQueryParams() {
|
|
2777
|
+
return {
|
|
2778
|
+
description: `This operation retrieves the current query parameters from the browser's address bar and places
|
|
2779
|
+
them on the returned operation data.`,
|
|
2780
|
+
category: `Utility`,
|
|
2781
|
+
properties: { defaultValues: {
|
|
2782
|
+
type: "ParameterType:object",
|
|
2783
|
+
erased: true
|
|
2784
|
+
} },
|
|
2785
|
+
outputProperties: { queryParams: { type: "ParameterType:object" } }
|
|
2786
|
+
};
|
|
2787
|
+
}
|
|
2788
|
+
|
|
2789
|
+
// src/operation/metadata/get-scroll-position.ts
|
|
2790
|
+
function getScrollPosition() {
|
|
2791
|
+
return {
|
|
2792
|
+
description: `Gets the current scroll position of the viewport.
|
|
2793
|
+
|
|
2794
|
+
Returns x (horizontal) and y (vertical) scroll positions in pixels.
|
|
2795
|
+
Uses cross-browser compatible methods to retrieve scroll position.`,
|
|
2796
|
+
category: `Scroll`,
|
|
2797
|
+
outputProperties: {
|
|
2798
|
+
scrollX: { type: "ParameterType:number" },
|
|
2799
|
+
scrollY: { type: "ParameterType:number" }
|
|
2800
|
+
}
|
|
2801
|
+
};
|
|
2802
|
+
}
|
|
2803
|
+
|
|
2804
|
+
// src/operation/metadata/get-text-content.ts
|
|
2805
|
+
function getTextContent() {
|
|
2806
|
+
return {
|
|
2807
|
+
description: `Extracts text content from element, stripping all HTML markup.
|
|
2808
|
+
|
|
2809
|
+
Uses jQuery's \`.text()\` method which is XSS-safe and returns only the text content
|
|
2810
|
+
without any HTML tags. Preserves whitespace and text from nested elements.`,
|
|
2811
|
+
category: `Text`,
|
|
2812
|
+
dependentProperties: ["selectedElement"],
|
|
2813
|
+
outputProperties: { textContent: { type: "ParameterType:string" } }
|
|
2814
|
+
};
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2817
|
+
// src/operation/metadata/http-delete.ts
|
|
2818
|
+
function httpDelete() {
|
|
2819
|
+
return {
|
|
2820
|
+
description: `Performs an HTTP DELETE request to the specified URL.`,
|
|
2821
|
+
category: `HTTP`,
|
|
2822
|
+
properties: {
|
|
2823
|
+
url: {
|
|
2824
|
+
type: "ParameterType:string",
|
|
2825
|
+
required: true,
|
|
2826
|
+
erased: true
|
|
2827
|
+
},
|
|
2828
|
+
headers: {
|
|
2829
|
+
type: "ParameterType:object",
|
|
2830
|
+
erased: true
|
|
2831
|
+
}
|
|
2832
|
+
},
|
|
2833
|
+
outputProperties: {
|
|
2834
|
+
response: { type: "ParameterType:object" },
|
|
2835
|
+
status: { type: "ParameterType:number" }
|
|
2836
|
+
}
|
|
2837
|
+
};
|
|
2838
|
+
}
|
|
2839
|
+
|
|
2840
|
+
// src/operation/metadata/http-post.ts
|
|
2841
|
+
function httpPost() {
|
|
2842
|
+
return {
|
|
2843
|
+
description: `Performs an HTTP POST request to the specified URL.
|
|
2844
|
+
|
|
2845
|
+
The body is sent as JSON with \`Content-Type: application/json\`, unless the caller's headers set
|
|
2846
|
+
another content type (header names are case-insensitive). With a non-JSON content type, a string
|
|
2847
|
+
body is sent as is; other bodies are still JSON encoded.`,
|
|
2848
|
+
category: `HTTP`,
|
|
2849
|
+
properties: {
|
|
2850
|
+
url: {
|
|
2851
|
+
type: "ParameterType:string",
|
|
2852
|
+
required: true,
|
|
2853
|
+
erased: true
|
|
2854
|
+
},
|
|
2855
|
+
body: {
|
|
2856
|
+
type: "ParameterType:object",
|
|
2857
|
+
erased: true
|
|
2858
|
+
},
|
|
2859
|
+
headers: {
|
|
2860
|
+
type: "ParameterType:object",
|
|
2861
|
+
erased: true
|
|
2862
|
+
}
|
|
2863
|
+
},
|
|
2864
|
+
outputProperties: {
|
|
2865
|
+
response: { type: "ParameterType:object" },
|
|
2866
|
+
status: { type: "ParameterType:number" }
|
|
2867
|
+
}
|
|
2868
|
+
};
|
|
2869
|
+
}
|
|
2870
|
+
|
|
2871
|
+
// src/operation/metadata/http-put.ts
|
|
2872
|
+
function httpPut() {
|
|
2873
|
+
return {
|
|
2874
|
+
description: `Performs an HTTP PUT request to the specified URL.
|
|
2875
|
+
|
|
2876
|
+
The body is sent as JSON with \`Content-Type: application/json\`, unless the caller's headers set
|
|
2877
|
+
another content type (header names are case-insensitive). With a non-JSON content type, a string
|
|
2878
|
+
body is sent as is; other bodies are still JSON encoded.`,
|
|
2879
|
+
category: `HTTP`,
|
|
2880
|
+
properties: {
|
|
2881
|
+
url: {
|
|
2882
|
+
type: "ParameterType:string",
|
|
2883
|
+
required: true,
|
|
2884
|
+
erased: true
|
|
2885
|
+
},
|
|
2886
|
+
body: {
|
|
2887
|
+
type: "ParameterType:object",
|
|
2888
|
+
erased: true
|
|
2889
|
+
},
|
|
2890
|
+
headers: {
|
|
2891
|
+
type: "ParameterType:object",
|
|
2892
|
+
erased: true
|
|
2893
|
+
}
|
|
2894
|
+
},
|
|
2895
|
+
outputProperties: {
|
|
2896
|
+
response: { type: "ParameterType:object" },
|
|
2897
|
+
status: { type: "ParameterType:number" }
|
|
2898
|
+
}
|
|
2899
|
+
};
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2902
|
+
// src/operation/metadata/invoke-object-method.ts
|
|
2903
|
+
function invokeObjectMethod() {
|
|
2904
|
+
return {
|
|
2905
|
+
description: `This operation invokes the specified method on the given object with the given optional arguments
|
|
2906
|
+
and assigns the result to the \`methodResult\` operationdata property. When the method returns a
|
|
2907
|
+
promise, the operation waits for it and assigns the resolved value.
|
|
2908
|
+
|
|
2909
|
+
The operation only calls application code: methods of controllers, of other instances of
|
|
2910
|
+
application classes, and of plain objects. It refuses, and throws for:
|
|
2911
|
+
- an \`instance\` that is a function, the global object (\`window\`), a document, a DOM node,
|
|
2912
|
+
a jQuery object, or any other built-in or host object (arrays, maps, promises, \`location\`,
|
|
2913
|
+
storage, ...);
|
|
2914
|
+
- a method that is a built-in (native) function, such as \`eval\`, \`Function\`, \`setTimeout\`,
|
|
2915
|
+
\`setInterval\`, \`document.write\`, \`Reflect.apply\` or a bound function, or a jQuery function;
|
|
2916
|
+
- the method names \`constructor\`, \`__proto__\` and \`prototype\`;
|
|
2917
|
+
- arguments that are such functions.
|
|
2918
|
+
|
|
2919
|
+
These checks stop configuration from reaching the platform's code-executing functions through
|
|
2920
|
+
this operation. They cannot vouch for what an application method does with its arguments, so
|
|
2921
|
+
only expose methods that are safe to call with configured data.`,
|
|
2922
|
+
category: `Utility`,
|
|
2923
|
+
dependentProperties: ["instance"],
|
|
2924
|
+
properties: {
|
|
2925
|
+
methodName: {
|
|
2926
|
+
type: "ParameterType:string",
|
|
2927
|
+
required: true,
|
|
2928
|
+
erased: true
|
|
2929
|
+
},
|
|
2930
|
+
methodArguments: {
|
|
2931
|
+
type: "ParameterType:array",
|
|
2932
|
+
erased: true
|
|
2933
|
+
}
|
|
2934
|
+
},
|
|
2935
|
+
outputProperties: { methodResult: { type: "ParameterType:object" } }
|
|
2936
|
+
};
|
|
2937
|
+
}
|
|
2938
|
+
|
|
2939
|
+
// src/operation/metadata/is-element-in-viewport.ts
|
|
2940
|
+
function isElementInViewport() {
|
|
2941
|
+
return {
|
|
2942
|
+
description: `Checks if an element is currently visible within the viewport.
|
|
2943
|
+
|
|
2944
|
+
Uses \`getBoundingClientRect()\` to determine if the element is within the viewport boundaries.`,
|
|
2945
|
+
category: `DOM`,
|
|
2946
|
+
dependentProperties: ["selectedElement"],
|
|
2947
|
+
outputProperties: { isInViewport: { type: "ParameterType:boolean" } }
|
|
2948
|
+
};
|
|
2949
|
+
}
|
|
2950
|
+
|
|
2951
|
+
// src/operation/metadata/load-from-storage.ts
|
|
2952
|
+
function loadFromStorage() {
|
|
2953
|
+
return {
|
|
2954
|
+
description: `Loads data from browser storage (localStorage or sessionStorage).
|
|
2955
|
+
|
|
2956
|
+
Deserializes the stored JSON value. Returns \`null\` if key doesn't exist.
|
|
2957
|
+
When \`storageType\` is omitted, localStorage is used.`,
|
|
2958
|
+
category: `Data`,
|
|
2959
|
+
properties: {
|
|
2960
|
+
key: {
|
|
2961
|
+
type: "ParameterType:string",
|
|
2962
|
+
required: true,
|
|
2963
|
+
erased: true
|
|
2964
|
+
},
|
|
2965
|
+
storageType: {
|
|
2966
|
+
type: [{ value: "local" }, { value: "session" }],
|
|
2967
|
+
required: true,
|
|
2968
|
+
erased: true
|
|
2969
|
+
}
|
|
2970
|
+
},
|
|
2971
|
+
outputProperties: { loadedValue: { type: "ParameterType:object" } }
|
|
2972
|
+
};
|
|
2973
|
+
}
|
|
2974
|
+
|
|
2975
|
+
// src/operation/metadata/load-json.ts
|
|
2976
|
+
function loadJson() {
|
|
2977
|
+
return {
|
|
2978
|
+
description: `This operation loads a JSON file from the specified url and assigns it to the json
|
|
2979
|
+
property on the current operation data.
|
|
2980
|
+
|
|
2981
|
+
If the cache property is set to true and a cached value already exists, a copy of it is assigned
|
|
2982
|
+
instead of re-retrieving it from the url. Mutating the returned json never changes the cache.
|
|
2983
|
+
|
|
2984
|
+
The cache is shared by every engine. It is emptied when the last live engine created by
|
|
2985
|
+
\`EngineFactory\` is destroyed; call {@link clearJsonCache} to empty it earlier.`,
|
|
2986
|
+
category: `Utility`,
|
|
2987
|
+
properties: {
|
|
2988
|
+
url: {
|
|
2989
|
+
type: "ParameterType:string",
|
|
2990
|
+
required: true,
|
|
2991
|
+
erased: true
|
|
2992
|
+
},
|
|
2993
|
+
cache: {
|
|
2994
|
+
type: "ParameterType:boolean",
|
|
2995
|
+
erased: true
|
|
2996
|
+
}
|
|
2997
|
+
},
|
|
2998
|
+
outputProperties: { json: { type: "ParameterType:object" } }
|
|
2999
|
+
};
|
|
3000
|
+
}
|
|
3001
|
+
|
|
3002
|
+
// src/operation/metadata/log.ts
|
|
3003
|
+
function log() {
|
|
3004
|
+
return {
|
|
3005
|
+
description: `This operation logs the specified value, or, when no logValue property has been assigned
|
|
3006
|
+
it will log the current operation data, global data and scope to the console`,
|
|
3007
|
+
category: `Utility`,
|
|
3008
|
+
properties: {
|
|
3009
|
+
logValue: {
|
|
3010
|
+
type: "ParameterType:object|ParameterType:string|ParameterType:number|ParameterType:boolean|ParameterType:array",
|
|
3011
|
+
erased: true
|
|
3012
|
+
},
|
|
3013
|
+
logName: {
|
|
3014
|
+
type: "ParameterType:string",
|
|
3015
|
+
erased: true
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
};
|
|
3019
|
+
}
|
|
3020
|
+
|
|
3021
|
+
// src/operation/metadata/map-array.ts
|
|
3022
|
+
function mapArray() {
|
|
3023
|
+
return {
|
|
3024
|
+
description: `Transforms each element of an array using a mapping function.
|
|
3025
|
+
|
|
3026
|
+
Operates on arrayData passed from previous operations.
|
|
3027
|
+
The mapFunction receives each item and optionally its index.`,
|
|
3028
|
+
category: `Array`,
|
|
3029
|
+
dependentProperties: ["arrayData"],
|
|
3030
|
+
properties: { mapFunction: {
|
|
3031
|
+
type: "ParameterType:function",
|
|
3032
|
+
required: true,
|
|
3033
|
+
erased: true
|
|
3034
|
+
} },
|
|
3035
|
+
outputProperties: { mappedArray: { type: "ParameterType:array" } }
|
|
3036
|
+
};
|
|
3037
|
+
}
|
|
3038
|
+
|
|
3039
|
+
// src/operation/metadata/math.ts
|
|
3040
|
+
function math() {
|
|
3041
|
+
return {
|
|
3042
|
+
description: `This operation performs the given math function with the specified arguments.
|
|
3043
|
+
|
|
3044
|
+
\`args\` and \`functionName\` may contain property chains (\`$operationdata.\`, \`$globaldata.\`,
|
|
3045
|
+
\`$scope.\`). Only these two inputs are resolved; the rest of the operation data is left as it
|
|
3046
|
+
is. Arguments that name a Math constant (such as \`'PI'\`) are replaced by its value.`,
|
|
3047
|
+
category: `Utility`,
|
|
3048
|
+
properties: {
|
|
3049
|
+
args: {
|
|
3050
|
+
type: "ParameterType:array",
|
|
3051
|
+
required: true,
|
|
3052
|
+
erased: true
|
|
3053
|
+
},
|
|
3054
|
+
functionName: {
|
|
3055
|
+
type: "ParameterType:mathfunction",
|
|
3056
|
+
required: true,
|
|
3057
|
+
erased: true
|
|
3058
|
+
}
|
|
3059
|
+
},
|
|
3060
|
+
outputProperties: { mathResult: { type: "ParameterType:number" } }
|
|
3061
|
+
};
|
|
3062
|
+
}
|
|
3063
|
+
|
|
3064
|
+
// src/operation/metadata/otherwise.ts
|
|
3065
|
+
function otherwise() {
|
|
3066
|
+
return {
|
|
3067
|
+
description: `If the preceeding {@link when} operation evaluates to \`true\` subsequent operations will
|
|
3068
|
+
be skipped until an {@link endWhen} operation is encountered.`,
|
|
3069
|
+
category: `Control Flow`
|
|
3070
|
+
};
|
|
3071
|
+
}
|
|
3072
|
+
|
|
3073
|
+
// src/operation/metadata/remove-class.ts
|
|
3074
|
+
function removeClass() {
|
|
3075
|
+
return {
|
|
3076
|
+
description: `This operation removes the spcified class name from the given selected element.`,
|
|
3077
|
+
category: `DOM`,
|
|
3078
|
+
dependentProperties: ["selectedElement"],
|
|
3079
|
+
properties: { className: {
|
|
3080
|
+
type: "ParameterType:className",
|
|
3081
|
+
required: true,
|
|
3082
|
+
erased: true
|
|
3083
|
+
} }
|
|
3084
|
+
};
|
|
3085
|
+
}
|
|
3086
|
+
|
|
3087
|
+
// src/operation/metadata/remove-controller-from-element.ts
|
|
3088
|
+
function removeControllerFromElement() {
|
|
3089
|
+
return {
|
|
3090
|
+
description: `This operation removes the controller with the specified name from the given selected element.`,
|
|
3091
|
+
category: `Controller`,
|
|
3092
|
+
dependentProperties: ["selectedElement"],
|
|
3093
|
+
properties: { controllerName: {
|
|
3094
|
+
type: "ParameterType:controllerName",
|
|
3095
|
+
required: true,
|
|
3096
|
+
erased: true
|
|
3097
|
+
} }
|
|
3098
|
+
};
|
|
3099
|
+
}
|
|
3100
|
+
|
|
3101
|
+
// src/operation/metadata/remove-element.ts
|
|
3102
|
+
function removeElement() {
|
|
3103
|
+
return {
|
|
3104
|
+
description: `This operation removes the given selected element from the DOM.
|
|
3105
|
+
|
|
3106
|
+
Controllers attached to the element or its descendants (by \`addControllerToElement\`) are
|
|
3107
|
+
detached first, so their eventbus and window listeners do not outlive the element.`,
|
|
3108
|
+
category: `DOM`,
|
|
3109
|
+
dependentProperties: ["selectedElement"]
|
|
3110
|
+
};
|
|
3111
|
+
}
|
|
3112
|
+
|
|
3113
|
+
// src/operation/metadata/remove-properties-from-operation-data.ts
|
|
3114
|
+
function removePropertiesFromOperationData() {
|
|
3115
|
+
return {
|
|
3116
|
+
description: `This operation removes the given list of properties from the current operation data.
|
|
3117
|
+
It will also remove the property \`propertyNames\` from the result.`,
|
|
3118
|
+
category: `Data`,
|
|
3119
|
+
properties: { propertyNames: {
|
|
3120
|
+
type: "ParameterType:array",
|
|
3121
|
+
itemType: "ParameterType:string",
|
|
3122
|
+
required: true,
|
|
3123
|
+
erased: true
|
|
3124
|
+
} }
|
|
3125
|
+
};
|
|
3126
|
+
}
|
|
3127
|
+
|
|
3128
|
+
// src/operation/metadata/reparent-element.ts
|
|
3129
|
+
function reparentElement() {
|
|
3130
|
+
return {
|
|
3131
|
+
description: `This operation moves the given selected element to the new parent that is defined
|
|
3132
|
+
by the specified \`newParentSelector\`. jQuery data, event handlers and attached controllers
|
|
3133
|
+
are preserved.
|
|
3134
|
+
|
|
3135
|
+
The selector is resolved inside the engine root (the root itself included), the same way
|
|
3136
|
+
\`selectElement\` resolves its selector, and must match exactly one element. HTML strings are
|
|
3137
|
+
not accepted.`,
|
|
3138
|
+
category: `DOM`,
|
|
3139
|
+
dependentProperties: ["selectedElement"],
|
|
3140
|
+
properties: { newParentSelector: {
|
|
3141
|
+
type: "ParameterType:selector",
|
|
3142
|
+
required: true,
|
|
3143
|
+
erased: true
|
|
3144
|
+
} }
|
|
3145
|
+
};
|
|
3146
|
+
}
|
|
3147
|
+
|
|
3148
|
+
// src/operation/metadata/replace-string.ts
|
|
3149
|
+
function replaceString() {
|
|
3150
|
+
return {
|
|
3151
|
+
description: `Replaces occurrences of a pattern in a string (alias for replaceText for string context).
|
|
3152
|
+
|
|
3153
|
+
Like replaceText, a string pattern replaces every occurrence and inserts the replacement
|
|
3154
|
+
literally (\`$&\`, \`$1\` and similar are not expanded). A RegExp pattern follows
|
|
3155
|
+
\`String.prototype.replace\`: only a global RegExp replaces every match, and \`$\` patterns
|
|
3156
|
+
in the replacement are expanded. Unlike replaceText, the result is written to \`result\`
|
|
3157
|
+
and \`textContent\` is left unchanged.`,
|
|
3158
|
+
category: `String`,
|
|
3159
|
+
dependentProperties: ["textContent"],
|
|
3160
|
+
properties: {
|
|
3161
|
+
pattern: {
|
|
3162
|
+
type: "ParameterType:string|ParameterType:RegExp",
|
|
3163
|
+
required: true,
|
|
3164
|
+
erased: true
|
|
3165
|
+
},
|
|
3166
|
+
replacement: {
|
|
3167
|
+
type: "ParameterType:string",
|
|
3168
|
+
required: true,
|
|
3169
|
+
erased: true
|
|
3170
|
+
}
|
|
3171
|
+
},
|
|
3172
|
+
outputProperties: { result: { type: "ParameterType:string" } }
|
|
3173
|
+
};
|
|
3174
|
+
}
|
|
3175
|
+
|
|
3176
|
+
// src/operation/metadata/replace-text.ts
|
|
3177
|
+
function replaceText() {
|
|
3178
|
+
return {
|
|
3179
|
+
description: `Finds and replaces text using literal string or regex pattern.
|
|
3180
|
+
|
|
3181
|
+
Operates on textContent passed from previous operations (e.g., getTextContent).
|
|
3182
|
+
Supports regex patterns with global flag for multiple replacements.
|
|
3183
|
+
Updates textContent with replaced text and sets replacementCount.
|
|
3184
|
+
|
|
3185
|
+
A string pattern replaces every occurrence and inserts the replacement literally.`,
|
|
3186
|
+
category: `Text`,
|
|
3187
|
+
dependentProperties: ["textContent"],
|
|
3188
|
+
properties: {
|
|
3189
|
+
searchPattern: {
|
|
3190
|
+
type: "ParameterType:string|ParameterType:RegExp",
|
|
3191
|
+
required: true,
|
|
3192
|
+
erased: true
|
|
3193
|
+
},
|
|
3194
|
+
replacement: {
|
|
3195
|
+
type: "ParameterType:string",
|
|
3196
|
+
required: true,
|
|
3197
|
+
erased: true
|
|
3198
|
+
}
|
|
3199
|
+
},
|
|
3200
|
+
outputProperties: { replacementCount: { type: "ParameterType:number" } }
|
|
3201
|
+
};
|
|
3202
|
+
}
|
|
3203
|
+
|
|
3204
|
+
// src/operation/metadata/request-action.ts
|
|
3205
|
+
function requestAction() {
|
|
3206
|
+
return {
|
|
3207
|
+
description: `This operation requests an action instance with the specified name and assigns it
|
|
3208
|
+
to the \`actionInstance\` property on the current operation data.`,
|
|
3209
|
+
category: `Action`,
|
|
3210
|
+
properties: { systemName: {
|
|
3211
|
+
type: "ParameterType:actionName",
|
|
3212
|
+
required: true,
|
|
3213
|
+
erased: true
|
|
3214
|
+
} },
|
|
3215
|
+
outputProperties: { actionInstance: { type: "ParameterType:object" } }
|
|
3216
|
+
};
|
|
3217
|
+
}
|
|
3218
|
+
|
|
3219
|
+
// src/operation/metadata/save-to-storage.ts
|
|
3220
|
+
function saveToStorage() {
|
|
3221
|
+
return {
|
|
3222
|
+
description: `Saves data to browser storage (localStorage or sessionStorage).
|
|
3223
|
+
|
|
3224
|
+
Serializes the value as JSON before storing. Supports any JSON-serializable data type.
|
|
3225
|
+
Use \`null\` to store an empty value; \`undefined\` cannot be stored as JSON and is rejected.
|
|
3226
|
+
When \`storageType\` is omitted, localStorage is used.`,
|
|
3227
|
+
category: `Data`,
|
|
3228
|
+
properties: {
|
|
3229
|
+
key: {
|
|
3230
|
+
type: "ParameterType:string",
|
|
3231
|
+
required: true,
|
|
3232
|
+
erased: true
|
|
3233
|
+
},
|
|
3234
|
+
value: {
|
|
3235
|
+
type: "ParameterType:object",
|
|
3236
|
+
required: true,
|
|
3237
|
+
erased: true
|
|
3238
|
+
},
|
|
3239
|
+
storageType: {
|
|
3240
|
+
type: [{ value: "local" }, { value: "session" }],
|
|
3241
|
+
required: true,
|
|
3242
|
+
erased: true
|
|
3243
|
+
}
|
|
3244
|
+
}
|
|
3245
|
+
};
|
|
3246
|
+
}
|
|
3247
|
+
|
|
3248
|
+
// src/operation/metadata/scroll-to-element.ts
|
|
3249
|
+
function scrollToElement() {
|
|
3250
|
+
return {
|
|
3251
|
+
description: `Scrolls the viewport to bring the selected element into view.
|
|
3252
|
+
|
|
3253
|
+
Uses the browser's \`scrollIntoView\` API with configurable behavior.`,
|
|
3254
|
+
category: `Scroll`,
|
|
3255
|
+
dependentProperties: ["selectedElement"],
|
|
3256
|
+
properties: {
|
|
3257
|
+
behavior: {
|
|
3258
|
+
type: [{ value: "auto" }, { value: "smooth" }],
|
|
3259
|
+
erased: true
|
|
3260
|
+
},
|
|
3261
|
+
block: {
|
|
3262
|
+
type: [
|
|
3263
|
+
{ value: "start" },
|
|
3264
|
+
{ value: "center" },
|
|
3265
|
+
{ value: "end" },
|
|
3266
|
+
{ value: "nearest" }
|
|
3267
|
+
],
|
|
3268
|
+
erased: true
|
|
3269
|
+
},
|
|
3270
|
+
inline: {
|
|
3271
|
+
type: [
|
|
3272
|
+
{ value: "start" },
|
|
3273
|
+
{ value: "center" },
|
|
3274
|
+
{ value: "end" },
|
|
3275
|
+
{ value: "nearest" }
|
|
3276
|
+
],
|
|
3277
|
+
erased: true
|
|
3278
|
+
}
|
|
3279
|
+
}
|
|
3280
|
+
};
|
|
3281
|
+
}
|
|
3282
|
+
|
|
3283
|
+
// src/operation/metadata/scroll-to-position.ts
|
|
3284
|
+
function scrollToPosition() {
|
|
3285
|
+
return {
|
|
3286
|
+
description: `Scrolls the viewport to a specific x,y coordinate position.
|
|
3287
|
+
|
|
3288
|
+
Uses the browser's \`window.scrollTo\` API with configurable behavior.`,
|
|
3289
|
+
category: `Scroll`,
|
|
3290
|
+
properties: {
|
|
3291
|
+
x: {
|
|
3292
|
+
type: "ParameterType:number",
|
|
3293
|
+
required: true,
|
|
3294
|
+
erased: true
|
|
3295
|
+
},
|
|
3296
|
+
y: {
|
|
3297
|
+
type: "ParameterType:number",
|
|
3298
|
+
required: true,
|
|
3299
|
+
erased: true
|
|
3300
|
+
},
|
|
3301
|
+
behavior: {
|
|
3302
|
+
type: [{ value: "auto" }, { value: "smooth" }],
|
|
3303
|
+
erased: true
|
|
3304
|
+
}
|
|
3305
|
+
}
|
|
3306
|
+
};
|
|
3307
|
+
}
|
|
3308
|
+
|
|
3309
|
+
// src/operation/metadata/select-element.ts
|
|
3310
|
+
function selectElement() {
|
|
3311
|
+
return {
|
|
3312
|
+
description: `This operation selects one or more elements using the specified selector.
|
|
3313
|
+
|
|
3314
|
+
If \`useSelectedElementAsRoot\` is set to true and a valid DOM element is assigned
|
|
3315
|
+
to the current operation data's \`selectedElement\` property
|
|
3316
|
+
then the element will be looked for only in the descendant elements of this DOM element.`,
|
|
3317
|
+
category: `DOM`,
|
|
3318
|
+
properties: {
|
|
3319
|
+
selector: {
|
|
3320
|
+
type: "ParameterType:selector",
|
|
3321
|
+
required: true,
|
|
3322
|
+
erased: true
|
|
3323
|
+
},
|
|
3324
|
+
useSelectedElementAsRoot: {
|
|
3325
|
+
type: "ParameterType:boolean",
|
|
3326
|
+
erased: true
|
|
3327
|
+
}
|
|
3328
|
+
},
|
|
3329
|
+
outputProperties: { selectedElement: { type: "ParameterType:object" } }
|
|
3330
|
+
};
|
|
3331
|
+
}
|
|
3332
|
+
|
|
3333
|
+
// src/operation/metadata/set-data.ts
|
|
3334
|
+
function setData() {
|
|
3335
|
+
return {
|
|
3336
|
+
description: `This operation assigns the specified properties to the specified data targets.`,
|
|
3337
|
+
category: `Data`,
|
|
3338
|
+
properties: { properties: {
|
|
3339
|
+
type: "ParameterType:object",
|
|
3340
|
+
required: true,
|
|
3341
|
+
erased: true
|
|
3342
|
+
} }
|
|
3343
|
+
};
|
|
3344
|
+
}
|
|
3345
|
+
|
|
3346
|
+
// src/operation/metadata/set-element-attributes.ts
|
|
3347
|
+
function setElementAttributes() {
|
|
3348
|
+
return {
|
|
3349
|
+
description: `This operation sets the specified set of attributes on the given selected element.
|
|
3350
|
+
|
|
3351
|
+
Event handler (\`on*\`) and \`srcdoc\` attributes, and \`javascript:\` or \`vbscript:\` URLs in URL
|
|
3352
|
+
attributes such as \`href\`, \`src\` and \`formaction\`, are refused, the same as in \`createElement\`.`,
|
|
3353
|
+
category: `DOM`,
|
|
3354
|
+
dependentProperties: ["selectedElement"],
|
|
3355
|
+
properties: { attributes: {
|
|
3356
|
+
type: "ParameterType:object",
|
|
3357
|
+
required: true,
|
|
3358
|
+
erased: true
|
|
3359
|
+
} }
|
|
3360
|
+
};
|
|
3361
|
+
}
|
|
3362
|
+
|
|
3363
|
+
// src/operation/metadata/set-element-content.ts
|
|
3364
|
+
function setElementContent() {
|
|
3365
|
+
return {
|
|
3366
|
+
description: `This operation sets the specified content defined by the value assigned to the template property
|
|
3367
|
+
to the given selected element.
|
|
3368
|
+
|
|
3369
|
+
When the \`insertionType\` is set to \`overwrite\` the contents of the selected element are replaced
|
|
3370
|
+
by the given template.
|
|
3371
|
+
When set to \`append\` the new content will be inserted after the current content.
|
|
3372
|
+
When set to \`prepend\` the new content will be inserted before the current content.
|
|
3373
|
+
|
|
3374
|
+
With \`overwrite\`, controllers attached to the replaced content (by \`addControllerToElement\`) are
|
|
3375
|
+
detached first. Controllers on the selected element itself stay attached.
|
|
3376
|
+
|
|
3377
|
+
The template is inserted as HTML: a string template is parsed by jQuery, which also runs the
|
|
3378
|
+
scripts and inline event handlers it contains. Only use string templates from the configuration
|
|
3379
|
+
or the resource importer; build content from user data with \`createElement\`, whose \`text\` is
|
|
3380
|
+
never parsed as HTML.`,
|
|
3381
|
+
category: `DOM`,
|
|
3382
|
+
dependentProperties: ["selectedElement"],
|
|
3383
|
+
properties: {
|
|
3384
|
+
template: {
|
|
3385
|
+
type: "ParameterType:string|ParameterType:Element|ParameterType:Text|ParameterType:Comment|ParameterType:Document|ParameterType:DocumentFragment",
|
|
3386
|
+
erased: true
|
|
3387
|
+
},
|
|
3388
|
+
insertionType: {
|
|
3389
|
+
type: [
|
|
3390
|
+
{ value: "overwrite" },
|
|
3391
|
+
{ value: "append" },
|
|
3392
|
+
{ value: "prepend" }
|
|
3393
|
+
],
|
|
3394
|
+
erased: true
|
|
3395
|
+
}
|
|
3396
|
+
}
|
|
3397
|
+
};
|
|
3398
|
+
}
|
|
3399
|
+
|
|
3400
|
+
// src/operation/metadata/set-focus.ts
|
|
3401
|
+
function setFocus() {
|
|
3402
|
+
return {
|
|
3403
|
+
description: `Sets focus to the selected element.`,
|
|
3404
|
+
category: `Focus`,
|
|
3405
|
+
dependentProperties: ["selectedElement"]
|
|
3406
|
+
};
|
|
3407
|
+
}
|
|
3408
|
+
|
|
3409
|
+
// src/operation/metadata/set-form-value.ts
|
|
3410
|
+
function setFormValue() {
|
|
3411
|
+
return {
|
|
3412
|
+
description: `Sets the value of an input, select, or textarea element.
|
|
3413
|
+
|
|
3414
|
+
Handles different input types appropriately:
|
|
3415
|
+
- Text inputs, textareas, selects: sets value directly
|
|
3416
|
+
- Checkboxes: sets checked property for boolean values
|
|
3417
|
+
- Radio buttons: sets checked property for boolean values
|
|
3418
|
+
- Number inputs: converts to string`,
|
|
3419
|
+
category: `Form`,
|
|
3420
|
+
dependentProperties: ["selectedElement"],
|
|
3421
|
+
properties: { value: {
|
|
3422
|
+
type: "ParameterType:string|ParameterType:number|ParameterType:boolean",
|
|
3423
|
+
required: true,
|
|
3424
|
+
erased: true
|
|
3425
|
+
} }
|
|
3426
|
+
};
|
|
3427
|
+
}
|
|
3428
|
+
|
|
3429
|
+
// src/operation/metadata/set-global-data.ts
|
|
3430
|
+
function setGlobalData() {
|
|
3431
|
+
return {
|
|
3432
|
+
description: `This operation copies the specified properties from the operationData to the global data.
|
|
3433
|
+
|
|
3434
|
+
Plain data is stored as a deep copy, so changing the operation data afterwards does not change
|
|
3435
|
+
the global data. jQuery objects, DOM nodes, functions and class instances (such as controllers)
|
|
3436
|
+
are stored by reference.`,
|
|
3437
|
+
category: `Data`,
|
|
3438
|
+
properties: { propertyNames: {
|
|
3439
|
+
type: "ParameterType:array",
|
|
3440
|
+
itemType: "ParameterType:string",
|
|
3441
|
+
required: true,
|
|
3442
|
+
erased: true
|
|
3443
|
+
} }
|
|
3444
|
+
};
|
|
3445
|
+
}
|
|
3446
|
+
|
|
3447
|
+
// src/operation/metadata/set-operation-data.ts
|
|
3448
|
+
function setOperationData() {
|
|
3449
|
+
return {
|
|
3450
|
+
description: `This operation assigns the specified properties to the current operation data.
|
|
3451
|
+
When override is set to true the properties replace the current operation data entirely.`,
|
|
3452
|
+
category: `Data`,
|
|
3453
|
+
properties: {
|
|
3454
|
+
override: {
|
|
3455
|
+
type: "ParameterType:boolean",
|
|
3456
|
+
erased: true
|
|
3457
|
+
},
|
|
3458
|
+
properties: {
|
|
3459
|
+
type: "ParameterType:object",
|
|
3460
|
+
required: true,
|
|
3461
|
+
erased: true
|
|
3462
|
+
}
|
|
3463
|
+
}
|
|
3464
|
+
};
|
|
3465
|
+
}
|
|
3466
|
+
|
|
3467
|
+
// src/operation/metadata/set-style.ts
|
|
3468
|
+
function setStyle() {
|
|
3469
|
+
return {
|
|
3470
|
+
description: `This operation assigns the specified CSS style properties to the
|
|
3471
|
+
given selected element.`,
|
|
3472
|
+
category: `DOM`,
|
|
3473
|
+
dependentProperties: ["selectedElement"],
|
|
3474
|
+
properties: { properties: {
|
|
3475
|
+
type: "ParameterType:cssProperties",
|
|
3476
|
+
required: true,
|
|
3477
|
+
erased: true
|
|
3478
|
+
} }
|
|
3479
|
+
};
|
|
3480
|
+
}
|
|
3481
|
+
|
|
3482
|
+
// src/operation/metadata/set-variable.ts
|
|
3483
|
+
function setVariable() {
|
|
3484
|
+
return {
|
|
3485
|
+
description: `This operation sets a variable with the specified name on the scope with the specified value.
|
|
3486
|
+
|
|
3487
|
+
Variables belong to the action: a variable set inside a \`when\` or \`forEach\` block is the
|
|
3488
|
+
same variable outside it, so it keeps its value after \`endWhen\` or \`endForEach\`, and
|
|
3489
|
+
variables set before the block can be read and changed inside it. Read variables with
|
|
3490
|
+
\`$scope.variables.<name>\`.`,
|
|
3491
|
+
category: `Data`,
|
|
3492
|
+
properties: {
|
|
3493
|
+
name: {
|
|
3494
|
+
type: "ParameterType:string",
|
|
3495
|
+
required: true,
|
|
3496
|
+
erased: true
|
|
3497
|
+
},
|
|
3498
|
+
value: {
|
|
3499
|
+
type: "ParameterType:object|ParameterType:string|ParameterType:number|ParameterType:boolean|ParameterType:array",
|
|
3500
|
+
required: true,
|
|
3501
|
+
erased: true
|
|
3502
|
+
}
|
|
3503
|
+
}
|
|
3504
|
+
};
|
|
3505
|
+
}
|
|
3506
|
+
|
|
3507
|
+
// src/operation/metadata/sort-array.ts
|
|
3508
|
+
function sortArray() {
|
|
3509
|
+
return {
|
|
3510
|
+
description: `Sorts an array by property, natural order, or custom comparator function.
|
|
3511
|
+
|
|
3512
|
+
Operates on arrayData passed from previous operations.
|
|
3513
|
+
Supports three sorting modes:
|
|
3514
|
+
1. Property sort: \`sortProperty\` and \`sortOrder\` to sort objects by property
|
|
3515
|
+
2. Natural sort: \`sortOrder\` alone for primitive arrays
|
|
3516
|
+
3. Custom comparator: \`sortComparator\` function for complex sorting logic`,
|
|
3517
|
+
category: `Array`,
|
|
3518
|
+
dependentProperties: ["arrayData"],
|
|
3519
|
+
properties: {
|
|
3520
|
+
sortProperty: {
|
|
3521
|
+
type: "ParameterType:string",
|
|
3522
|
+
erased: true
|
|
3523
|
+
},
|
|
3524
|
+
sortOrder: {
|
|
3525
|
+
type: [{ value: "asc" }, { value: "desc" }],
|
|
3526
|
+
erased: true
|
|
3527
|
+
},
|
|
3528
|
+
sortComparator: {
|
|
3529
|
+
type: "ParameterType:function",
|
|
3530
|
+
erased: true
|
|
3531
|
+
}
|
|
3532
|
+
},
|
|
3533
|
+
outputProperties: { sortedArray: { type: "ParameterType:array" } }
|
|
3534
|
+
};
|
|
3535
|
+
}
|
|
3536
|
+
|
|
3537
|
+
// src/operation/metadata/split-string.ts
|
|
3538
|
+
function splitString() {
|
|
3539
|
+
return {
|
|
3540
|
+
description: `Splits a string into an array by delimiter (string or regex).`,
|
|
3541
|
+
category: `String`,
|
|
3542
|
+
dependentProperties: ["textContent"],
|
|
3543
|
+
properties: {
|
|
3544
|
+
delimiter: {
|
|
3545
|
+
type: "ParameterType:string|ParameterType:RegExp",
|
|
3546
|
+
required: true,
|
|
3547
|
+
erased: true
|
|
3548
|
+
},
|
|
3549
|
+
limit: {
|
|
3550
|
+
type: "ParameterType:number",
|
|
3551
|
+
erased: true
|
|
3552
|
+
}
|
|
3553
|
+
},
|
|
3554
|
+
outputProperties: { resultArray: {
|
|
3555
|
+
type: "ParameterType:array",
|
|
3556
|
+
itemType: "ParameterType:string"
|
|
3557
|
+
} }
|
|
3558
|
+
};
|
|
3559
|
+
}
|
|
3560
|
+
|
|
3561
|
+
// src/operation/metadata/start-action.ts
|
|
3562
|
+
function startAction() {
|
|
3563
|
+
return {
|
|
3564
|
+
description: `This operation starts the specified action instance using the given action operation data.
|
|
3565
|
+
|
|
3566
|
+
The action receives its own copy of the current operation data merged with the action
|
|
3567
|
+
operation data. Whatever the action's operations add, change or remove in that copy stays
|
|
3568
|
+
with the action: once it has completed, this operation continues with the operation data it
|
|
3569
|
+
had before, plus \`actionInstance\`, without the \`actionOperationData\` property.`,
|
|
3570
|
+
category: `Action`,
|
|
3571
|
+
dependentProperties: ["actionInstance"],
|
|
3572
|
+
properties: { actionOperationData: {
|
|
3573
|
+
type: "ParameterType:object",
|
|
3574
|
+
erased: true
|
|
3575
|
+
} }
|
|
3576
|
+
};
|
|
3577
|
+
}
|
|
3578
|
+
|
|
3579
|
+
// src/operation/metadata/substring-text.ts
|
|
3580
|
+
function substringText() {
|
|
3581
|
+
return {
|
|
3582
|
+
description: `Extracts a substring from text between start and end indices.`,
|
|
3583
|
+
category: `Text`,
|
|
3584
|
+
dependentProperties: ["textContent"],
|
|
3585
|
+
properties: {
|
|
3586
|
+
start: {
|
|
3587
|
+
type: "ParameterType:number",
|
|
3588
|
+
required: true,
|
|
3589
|
+
erased: true
|
|
3590
|
+
},
|
|
3591
|
+
end: {
|
|
3592
|
+
type: "ParameterType:number",
|
|
3593
|
+
erased: true
|
|
3594
|
+
}
|
|
3595
|
+
},
|
|
3596
|
+
outputProperties: { substring: { type: "ParameterType:string" } }
|
|
3597
|
+
};
|
|
3598
|
+
}
|
|
3599
|
+
|
|
3600
|
+
// src/operation/metadata/toggle-class.ts
|
|
3601
|
+
function toggleClass() {
|
|
3602
|
+
return {
|
|
3603
|
+
description: `This operation toggles the specfied class name on the given selected element.
|
|
3604
|
+
|
|
3605
|
+
Meaning, if the specified class name exists on the given element it will be removed,
|
|
3606
|
+
otherwise it will be added.`,
|
|
3607
|
+
category: `DOM`,
|
|
3608
|
+
dependentProperties: ["selectedElement"],
|
|
3609
|
+
properties: { className: {
|
|
3610
|
+
type: "ParameterType:className",
|
|
3611
|
+
required: true,
|
|
3612
|
+
erased: true
|
|
3613
|
+
} }
|
|
3614
|
+
};
|
|
3615
|
+
}
|
|
3616
|
+
|
|
3617
|
+
// src/operation/metadata/toggle-element.ts
|
|
3618
|
+
function toggleElement() {
|
|
3619
|
+
return {
|
|
3620
|
+
description: `This operation toggles the visibility of the given selected element.
|
|
3621
|
+
|
|
3622
|
+
Meaning, if the element is hidden, it will be made visible, otherwise
|
|
3623
|
+
it will be hidden.`,
|
|
3624
|
+
category: `DOM`,
|
|
3625
|
+
dependentProperties: ["selectedElement"]
|
|
3626
|
+
};
|
|
3627
|
+
}
|
|
3628
|
+
|
|
3629
|
+
// src/operation/metadata/toggle-form-element.ts
|
|
3630
|
+
function toggleFormElement() {
|
|
3631
|
+
return {
|
|
3632
|
+
description: `Enables or disables form input elements (inputs, selects, textareas, buttons).
|
|
3633
|
+
|
|
3634
|
+
Sets the \`disabled\` property on the element. When \`enabled\` is true, removes the disabled
|
|
3635
|
+
attribute; when false, adds the disabled attribute.`,
|
|
3636
|
+
category: `Form`,
|
|
3637
|
+
dependentProperties: ["selectedElement"],
|
|
3638
|
+
properties: { enabled: {
|
|
3639
|
+
type: "ParameterType:boolean",
|
|
3640
|
+
required: true,
|
|
3641
|
+
erased: true
|
|
3642
|
+
} }
|
|
3643
|
+
};
|
|
3644
|
+
}
|
|
3645
|
+
|
|
3646
|
+
// src/operation/metadata/validate-form.ts
|
|
3647
|
+
function validateForm() {
|
|
3648
|
+
return {
|
|
3649
|
+
description: `Validates form fields against HTML5 validation and custom rules.
|
|
3650
|
+
|
|
3651
|
+
Uses HTML5 validation API (checkValidity()) for native validation, and supports
|
|
3652
|
+
custom validation rules for: required, minLength, maxLength, pattern (regex), and email format.
|
|
3653
|
+
|
|
3654
|
+
Checkboxes and radio buttons are validated once per name: \`required\` passes when at least one
|
|
3655
|
+
of them is checked, and the string rules do not apply to them. For a \`<select multiple>\`,
|
|
3656
|
+
\`required\`, \`minLength\` and \`maxLength\` count the selected options, and \`pattern\` and \`email\`
|
|
3657
|
+
apply to each selected value.`,
|
|
3658
|
+
category: `Form`,
|
|
3659
|
+
dependentProperties: ["selectedElement"],
|
|
3660
|
+
properties: { validationRules: {
|
|
3661
|
+
type: "ParameterType:object",
|
|
3662
|
+
erased: true
|
|
3663
|
+
} },
|
|
3664
|
+
outputProperties: {
|
|
3665
|
+
validationErrors: { type: "ParameterType:object" },
|
|
3666
|
+
isValid: { type: "ParameterType:boolean" }
|
|
3667
|
+
}
|
|
3668
|
+
};
|
|
3669
|
+
}
|
|
3670
|
+
|
|
3671
|
+
// src/operation/metadata/wait.ts
|
|
3672
|
+
function wait() {
|
|
3673
|
+
return {
|
|
3674
|
+
description: `This operation waits for the specified amount of milliseconds.`,
|
|
3675
|
+
category: `Utility`,
|
|
3676
|
+
properties: { milliseconds: {
|
|
3677
|
+
type: "ParameterType:number",
|
|
3678
|
+
required: true,
|
|
3679
|
+
erased: true
|
|
3680
|
+
} }
|
|
3681
|
+
};
|
|
3682
|
+
}
|
|
3683
|
+
|
|
3684
|
+
// src/operation/metadata/when.ts
|
|
3685
|
+
function when() {
|
|
3686
|
+
return {
|
|
3687
|
+
description: `When the given expression evaluates to false, subsequent operations will be skipped
|
|
3688
|
+
until an {@link endWhen} or {@link otherwise} operation is encountered.
|
|
3689
|
+
|
|
3690
|
+
Practically, this means an \`if\` or \`if\`/\`else\` statement control flow implementation in a list of operations.
|
|
3691
|
+
|
|
3692
|
+
The expression is passed in as a formatted string. An operand can be one of:
|
|
3693
|
+
|
|
3694
|
+
'constant': for a constant string (operators and parentheses inside the quotes are text)
|
|
3695
|
+
100: for a constant number (the whole operand must be numeric, \`10px\` is invalid)
|
|
3696
|
+
true, false, null: for a boolean or null constant
|
|
3697
|
+
$operationData.foo: for an operation data value
|
|
3698
|
+
$globaldata.foo: for a global data value
|
|
3699
|
+
$scope.loopIndex: for a scope value
|
|
3700
|
+
$scope.variables.foo: for a variable set with \`setVariable\`
|
|
3701
|
+
|
|
3702
|
+
Any other operand is an error, so a misspelled chain prefix fails instead of being compared
|
|
3703
|
+
as a string.
|
|
3704
|
+
|
|
3705
|
+
Operands are combined with these operators, from highest to lowest precedence:
|
|
3706
|
+
|
|
3707
|
+
\`!\`: negation
|
|
3708
|
+
\`==\`, \`!=\`, \`>\`, \`<\`, \`>=\`, \`<=\`: comparison (\`==\` and \`!=\` compare strictly, without type
|
|
3709
|
+
conversion; comparisons do not chain, so write \`0<$scope.loopIndex && $scope.loopIndex<5\`)
|
|
3710
|
+
\`&&\`: and
|
|
3711
|
+
\`||\`: or
|
|
3712
|
+
|
|
3713
|
+
Parentheses group. A bare operand is true when its value is truthy, so \`'false'\` and \`'0'\`
|
|
3714
|
+
are true and \`0\`, \`''\`, \`null\` and a missing value are false. \`!\`, \`&&\` and \`||\` always
|
|
3715
|
+
produce \`true\` or \`false\`. \`!\` binds tighter than a comparison: \`!$operationdata.a==1\`
|
|
3716
|
+
compares \`!$operationdata.a\` with 1, write \`!($operationdata.a==1)\` to negate the comparison.
|
|
3717
|
+
\`&&\` and \`||\` short-circuit: when the left side decides the result, the right side is not
|
|
3718
|
+
resolved, so \`$operationdata.user && $operationdata.user.name=='John'\` does not fail when
|
|
3719
|
+
\`user\` is missing.
|
|
3720
|
+
|
|
3721
|
+
Arithmetic (\`+\`, \`-\`, \`*\`, \`/\`) is not supported: \`-\` is a valid character in a property
|
|
3722
|
+
chain, so \`$operationdata.a-1\` would be ambiguous. Nothing in the expression is executed as
|
|
3723
|
+
code, and property chains are resolved with the usual prototype-pollution and global-object
|
|
3724
|
+
guards.`,
|
|
3725
|
+
category: `Control Flow`,
|
|
3726
|
+
properties: { expression: {
|
|
3727
|
+
type: "ParameterType:expression",
|
|
3728
|
+
required: true,
|
|
3729
|
+
erased: true
|
|
3730
|
+
} }
|
|
3731
|
+
};
|
|
3732
|
+
}
|
|
3733
|
+
|
|
3734
|
+
// src/operation/metadata/index.ts
|
|
3735
|
+
var metadata_exports = /* @__PURE__ */ __exportAll({
|
|
3736
|
+
addClass: () => addClass,
|
|
3737
|
+
addControllerToElement: () => addControllerToElement,
|
|
3738
|
+
addGlobalsToOperation: () => addGlobalsToOperation,
|
|
3739
|
+
animate: () => animate,
|
|
3740
|
+
animateWithClass: () => animateWithClass,
|
|
3741
|
+
announceToScreenReader: () => announceToScreenReader,
|
|
3742
|
+
breakForEach: () => breakForEach,
|
|
3743
|
+
broadcastEvent: () => broadcastEvent,
|
|
3744
|
+
calc: () => calc,
|
|
3745
|
+
clearElement: () => clearElement,
|
|
3746
|
+
clearOperationData: () => clearOperationData,
|
|
3747
|
+
clearStorage: () => clearStorage,
|
|
3748
|
+
compareDate: () => compareDate,
|
|
3749
|
+
concatenateStrings: () => concatenateStrings,
|
|
3750
|
+
continueForEach: () => continueForEach,
|
|
3751
|
+
createElement: () => createElement,
|
|
3752
|
+
customFunction: () => customFunction,
|
|
3753
|
+
endAction: () => endAction,
|
|
3754
|
+
endForEach: () => endForEach,
|
|
3755
|
+
endWhen: () => endWhen,
|
|
3756
|
+
extendController: () => extendController,
|
|
3757
|
+
filterArray: () => filterArray,
|
|
3758
|
+
findInArray: () => findInArray,
|
|
3759
|
+
forEach: () => forEach,
|
|
3760
|
+
formatDate: () => formatDate,
|
|
3761
|
+
formatText: () => formatText,
|
|
3762
|
+
getAttributesFromElement: () => getAttributesFromElement,
|
|
3763
|
+
getControllerFromElement: () => getControllerFromElement,
|
|
3764
|
+
getControllerInstance: () => getControllerInstance,
|
|
3765
|
+
getCurrentTime: () => getCurrentTime,
|
|
3766
|
+
getElementDimensions: () => getElementDimensions,
|
|
3767
|
+
getFocusedElement: () => getFocusedElement,
|
|
3768
|
+
getFormData: () => getFormData,
|
|
3769
|
+
getImport: () => getImport,
|
|
3770
|
+
getQueryParams: () => getQueryParams,
|
|
3771
|
+
getScrollPosition: () => getScrollPosition,
|
|
3772
|
+
getTextContent: () => getTextContent,
|
|
3773
|
+
httpDelete: () => httpDelete,
|
|
3774
|
+
httpPost: () => httpPost,
|
|
3775
|
+
httpPut: () => httpPut,
|
|
3776
|
+
invokeObjectMethod: () => invokeObjectMethod,
|
|
3777
|
+
isElementInViewport: () => isElementInViewport,
|
|
3778
|
+
loadFromStorage: () => loadFromStorage,
|
|
3779
|
+
loadJson: () => loadJson,
|
|
3780
|
+
log: () => log,
|
|
3781
|
+
mapArray: () => mapArray,
|
|
3782
|
+
math: () => math,
|
|
3783
|
+
otherwise: () => otherwise,
|
|
3784
|
+
removeClass: () => removeClass,
|
|
3785
|
+
removeControllerFromElement: () => removeControllerFromElement,
|
|
3786
|
+
removeElement: () => removeElement,
|
|
3787
|
+
removePropertiesFromOperationData: () => removePropertiesFromOperationData,
|
|
3788
|
+
reparentElement: () => reparentElement,
|
|
3789
|
+
replaceString: () => replaceString,
|
|
3790
|
+
replaceText: () => replaceText,
|
|
3791
|
+
requestAction: () => requestAction,
|
|
3792
|
+
saveToStorage: () => saveToStorage,
|
|
3793
|
+
scrollToElement: () => scrollToElement,
|
|
3794
|
+
scrollToPosition: () => scrollToPosition,
|
|
3795
|
+
selectElement: () => selectElement,
|
|
3796
|
+
setData: () => setData,
|
|
3797
|
+
setElementAttributes: () => setElementAttributes,
|
|
3798
|
+
setElementContent: () => setElementContent,
|
|
3799
|
+
setFocus: () => setFocus,
|
|
3800
|
+
setFormValue: () => setFormValue,
|
|
3801
|
+
setGlobalData: () => setGlobalData,
|
|
3802
|
+
setOperationData: () => setOperationData,
|
|
3803
|
+
setStyle: () => setStyle,
|
|
3804
|
+
setVariable: () => setVariable,
|
|
3805
|
+
sortArray: () => sortArray,
|
|
3806
|
+
splitString: () => splitString,
|
|
3807
|
+
startAction: () => startAction,
|
|
3808
|
+
substringText: () => substringText,
|
|
3809
|
+
toggleClass: () => toggleClass,
|
|
3810
|
+
toggleElement: () => toggleElement,
|
|
3811
|
+
toggleFormElement: () => toggleFormElement,
|
|
3812
|
+
validateForm: () => validateForm,
|
|
3813
|
+
wait: () => wait,
|
|
3814
|
+
when: () => when
|
|
3815
|
+
});
|
|
3816
|
+
|
|
3817
|
+
// src/lint/built-in-names.ts
|
|
3818
|
+
/**
|
|
3819
|
+
* The names `EligiusResourceImporter` lists, without importing the
|
|
3820
|
+
* implementations: the linter must stay free of jquery and lottie-web.
|
|
3821
|
+
*
|
|
3822
|
+
* Operation and controller names come from the generated metadata. The
|
|
3823
|
+
* timeline provider exports have no metadata, so they are listed here, in
|
|
3824
|
+
* the order of `src/timelineproviders/index.ts`; the conformance test in
|
|
3825
|
+
* `src/test/unit/lint/built-in-names.spec.ts` keeps the three lists equal to
|
|
3826
|
+
* what the runtime importer returns.
|
|
3827
|
+
*/
|
|
3828
|
+
const builtInOperationNames = Object.keys(metadata_exports);
|
|
3829
|
+
const builtInControllerNames = Object.keys(metadata_exports$1);
|
|
3830
|
+
const builtInProviderNames = [
|
|
3831
|
+
"isSeekable",
|
|
3832
|
+
"BasePositionSource",
|
|
3833
|
+
"KeyboardStepSource",
|
|
3834
|
+
"RafPositionSource",
|
|
3835
|
+
"ScrollPositionSource",
|
|
3836
|
+
"VideoPositionSource",
|
|
3837
|
+
"DomContainerProvider",
|
|
3838
|
+
"SimplePlaylist"
|
|
3839
|
+
];
|
|
3840
|
+
|
|
3841
|
+
// src/lint/lint-importer.ts
|
|
3842
|
+
function stubOperation(operationData) {
|
|
3843
|
+
return operationData;
|
|
3844
|
+
}
|
|
3845
|
+
function stubFunction() {}
|
|
3846
|
+
var StubController = class {
|
|
3847
|
+
name = "StubController";
|
|
3848
|
+
init() {}
|
|
3849
|
+
attach() {}
|
|
3850
|
+
detach() {}
|
|
3851
|
+
};
|
|
3852
|
+
var StubProvider = class {};
|
|
3853
|
+
/**
|
|
3854
|
+
* Creates the importer the linter runs the real `ConfigurationResolver` with.
|
|
3855
|
+
* It serves a stand-in for every built-in and declared name, so the resolver
|
|
3856
|
+
* does the same name checks it does at runtime, without loading jquery or
|
|
3857
|
+
* lottie-web.
|
|
3858
|
+
*
|
|
3859
|
+
* @param options - The declared custom resources
|
|
3860
|
+
* @param placeholders - The placeholder names found in the configuration
|
|
3861
|
+
*/
|
|
3862
|
+
function createLintImporter(options, placeholders) {
|
|
3863
|
+
const operations = [...builtInOperationNames, ...options.customOperations ?? []];
|
|
3864
|
+
const controllers = [...builtInControllerNames, ...options.customControllers ?? []];
|
|
3865
|
+
const providers = [...builtInProviderNames, ...options.customProviders ?? []];
|
|
3866
|
+
const functions = [...options.customFunctions ?? []];
|
|
3867
|
+
const operationSet = new Set(operations);
|
|
3868
|
+
const controllerSet = new Set(controllers);
|
|
3869
|
+
const providerSet = new Set(providers);
|
|
3870
|
+
const functionSet = new Set(functions);
|
|
3871
|
+
const placeholderValue = (kind, name, fallback) => {
|
|
3872
|
+
const declared = options[kind];
|
|
3873
|
+
if (declared === void 0) return fallback;
|
|
3874
|
+
const names = Array.isArray(declared) ? declared : Object.keys(declared);
|
|
3875
|
+
if (!names.includes(name)) {
|
|
3876
|
+
const what = kind === "templates" ? "template" : "JSON value";
|
|
3877
|
+
const didYouMean = formatDidYouMean(findClosestNames(name, names));
|
|
3878
|
+
throw new Error(`eligius/lint: unknown ${what} '${name}'. ${didYouMean || `Add it to the '${kind}' lint option.`}`);
|
|
3879
|
+
}
|
|
3880
|
+
return Array.isArray(declared) ? fallback : declared[name];
|
|
3881
|
+
};
|
|
3882
|
+
return {
|
|
3883
|
+
getOperationNames: () => [...operations],
|
|
3884
|
+
getControllerNames: () => [...controllers],
|
|
3885
|
+
getProviderNames: () => [...providers],
|
|
3886
|
+
getFunctionNames: () => [...functions],
|
|
3887
|
+
import(name) {
|
|
3888
|
+
if (operationSet.has(name)) return { [name]: stubOperation };
|
|
3889
|
+
if (controllerSet.has(name)) return { [name]: StubController };
|
|
3890
|
+
if (providerSet.has(name)) return { [name]: StubProvider };
|
|
3891
|
+
if (functionSet.has(name)) return { [name]: stubFunction };
|
|
3892
|
+
if (placeholders.templates.has(name)) return { [name]: placeholderValue("templates", name, "") };
|
|
3893
|
+
if (placeholders.json.has(name)) return { [name]: placeholderValue("json", name, {}) };
|
|
3894
|
+
const didYouMean = formatDidYouMean(findClosestNames(String(name), [
|
|
3895
|
+
...operations,
|
|
3896
|
+
...controllers,
|
|
3897
|
+
...providers,
|
|
3898
|
+
...functions
|
|
3899
|
+
]));
|
|
3900
|
+
throw new Error(`eligius/lint: unknown system name '${name}'.${didYouMean ? ` ${didYouMean}` : ""}`);
|
|
3901
|
+
}
|
|
3902
|
+
};
|
|
3903
|
+
}
|
|
3904
|
+
|
|
3905
|
+
// src/lint/operation-lists.ts
|
|
3906
|
+
/**
|
|
3907
|
+
* True when `value` is shaped like an operation configuration: a plain
|
|
3908
|
+
* object with a string `systemName`.
|
|
3909
|
+
*/
|
|
3910
|
+
function isOperationConfiguration(value) {
|
|
3911
|
+
return isPlainObject(value) && typeof value.systemName === "string";
|
|
3912
|
+
}
|
|
3913
|
+
/**
|
|
3914
|
+
* Collects every operation list of the configuration in document order.
|
|
3915
|
+
* Values that are not arrays are skipped; the resolver reports those.
|
|
3916
|
+
*/
|
|
3917
|
+
function collectOperationLists(configuration) {
|
|
3918
|
+
const lists = [];
|
|
3919
|
+
const add = (owner, path, key, startsEmpty) => {
|
|
3920
|
+
if (isPlainObject(owner) && Array.isArray(owner[key])) lists.push({
|
|
3921
|
+
operations: owner[key],
|
|
3922
|
+
path: `${path}.${key}`,
|
|
3923
|
+
startsEmpty
|
|
3924
|
+
});
|
|
3925
|
+
};
|
|
3926
|
+
const addEndable = (owner, path, startsEmpty, withEnd) => {
|
|
3927
|
+
add(owner, path, "startOperations", startsEmpty);
|
|
3928
|
+
if (withEnd) add(owner, path, "endOperations", startsEmpty);
|
|
3929
|
+
};
|
|
3930
|
+
const each = (items, path, visit) => {
|
|
3931
|
+
if (Array.isArray(items)) items.forEach((item, index) => visit(item, `${path}[${index}]`));
|
|
3932
|
+
};
|
|
3933
|
+
each(configuration.initActions, "initActions", (action, path) => addEndable(action, path, true, true));
|
|
3934
|
+
each(configuration.actions, "actions", (action, path) => addEndable(action, path, false, true));
|
|
3935
|
+
each(configuration.eventActions, "eventActions", (action, path) => addEndable(action, path, false, false));
|
|
3936
|
+
each(configuration.timelines, "timelines", (timeline, path) => {
|
|
3937
|
+
if (isPlainObject(timeline)) each(timeline.timelineActions, `${path}.timelineActions`, (action, p) => addEndable(action, p, true, true));
|
|
3938
|
+
});
|
|
3939
|
+
return lists;
|
|
3940
|
+
}
|
|
3941
|
+
|
|
3942
|
+
// src/lint/operation-metadata.ts
|
|
3943
|
+
const factories = metadata_exports;
|
|
3944
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3945
|
+
/**
|
|
3946
|
+
* Returns the generated metadata of a built-in operation, or undefined for
|
|
3947
|
+
* any other name. The metadata is created once per name.
|
|
3948
|
+
*/
|
|
3949
|
+
function getOperationMetadata(systemName) {
|
|
3950
|
+
if (!Object.hasOwn(factories, systemName)) return;
|
|
3951
|
+
let metadata = cache.get(systemName);
|
|
3952
|
+
if (metadata === void 0) {
|
|
3953
|
+
metadata = factories[systemName]();
|
|
3954
|
+
cache.set(systemName, metadata);
|
|
3955
|
+
}
|
|
3956
|
+
return metadata;
|
|
3957
|
+
}
|
|
3958
|
+
function isRequiredProperty(property) {
|
|
3959
|
+
return typeof property === "object" && property.required === true;
|
|
3960
|
+
}
|
|
3961
|
+
function isErasedProperty(property) {
|
|
3962
|
+
return typeof property === "object" && property.erased === true;
|
|
3963
|
+
}
|
|
3964
|
+
/**
|
|
3965
|
+
* The values a property restricted to a literal union accepts, or undefined
|
|
3966
|
+
* when the property takes any value of its type.
|
|
3967
|
+
*/
|
|
3968
|
+
function literalValuesOf(property) {
|
|
3969
|
+
if (typeof property !== "object" || !Array.isArray(property.type)) return;
|
|
3970
|
+
return property.type.map((constant) => constant.value);
|
|
3971
|
+
}
|
|
3972
|
+
const producersByProperty = /* @__PURE__ */ new Map();
|
|
3973
|
+
/**
|
|
3974
|
+
* The built-in operations whose `outputProperties` include `property`, for
|
|
3975
|
+
* the hint in a missing-dependency warning.
|
|
3976
|
+
*/
|
|
3977
|
+
function findProducers(property) {
|
|
3978
|
+
let producers = producersByProperty.get(property);
|
|
3979
|
+
if (producers === void 0) {
|
|
3980
|
+
producers = Object.keys(factories).filter((name) => {
|
|
3981
|
+
const output = getOperationMetadata(name)?.outputProperties;
|
|
3982
|
+
return output !== void 0 && Object.hasOwn(output, property);
|
|
3983
|
+
});
|
|
3984
|
+
producersByProperty.set(property, producers);
|
|
3985
|
+
}
|
|
3986
|
+
return producers;
|
|
3987
|
+
}
|
|
3988
|
+
|
|
3989
|
+
// src/lint/resolving-fields.ts
|
|
3990
|
+
/**
|
|
3991
|
+
* The operation data fields in which an operation resolves `$operationdata.`,
|
|
3992
|
+
* `$globaldata.` and `$scope.` property chains. A chain in any other field of
|
|
3993
|
+
* any operation is passed on as text, which the linter reports (W150).
|
|
3994
|
+
*
|
|
3995
|
+
* This list is maintained by hand. The conformance test in
|
|
3996
|
+
* `src/test/unit/lint/resolving-fields.spec.ts` checks that exactly the
|
|
3997
|
+
* operations listed here import a chain-resolving helper, so a new resolving
|
|
3998
|
+
* operation cannot be forgotten and a removed one cannot linger.
|
|
3999
|
+
*/
|
|
4000
|
+
const RESOLVING_FIELDS = {
|
|
4001
|
+
broadcastEvent: ["eventArgs"],
|
|
4002
|
+
calc: [
|
|
4003
|
+
"left",
|
|
4004
|
+
"right",
|
|
4005
|
+
"operator"
|
|
4006
|
+
],
|
|
4007
|
+
createElement: [
|
|
4008
|
+
"elementName",
|
|
4009
|
+
"attributes",
|
|
4010
|
+
"text"
|
|
4011
|
+
],
|
|
4012
|
+
forEach: ["collection"],
|
|
4013
|
+
math: ["args", "functionName"],
|
|
4014
|
+
selectElement: ["selector"],
|
|
4015
|
+
setData: ["properties"],
|
|
4016
|
+
setOperationData: ["properties"],
|
|
4017
|
+
setStyle: ["properties"],
|
|
4018
|
+
when: ["expression"]
|
|
4019
|
+
};
|
|
4020
|
+
/**
|
|
4021
|
+
* True when `systemName` resolves chains in its `field`.
|
|
4022
|
+
*/
|
|
4023
|
+
function resolvesField(systemName, field) {
|
|
4024
|
+
return Object.hasOwn(RESOLVING_FIELDS, systemName) && RESOLVING_FIELDS[systemName].includes(field);
|
|
4025
|
+
}
|
|
4026
|
+
|
|
4027
|
+
// src/lint/rules.ts
|
|
4028
|
+
/**
|
|
4029
|
+
* Scope fields the engine uses to run an action. Writing them with `setData`
|
|
4030
|
+
* breaks the action; `newIndex` is left out because writing it is the
|
|
4031
|
+
* documented way to jump.
|
|
4032
|
+
*/
|
|
4033
|
+
const RESERVED_SCOPE_KEYS = /* @__PURE__ */ new Set([
|
|
4034
|
+
"eventbus",
|
|
4035
|
+
"operations",
|
|
4036
|
+
"currentIndex",
|
|
4037
|
+
"parent",
|
|
4038
|
+
"owner",
|
|
4039
|
+
"loopIndex",
|
|
4040
|
+
"loopLength",
|
|
4041
|
+
"loopStartIndex",
|
|
4042
|
+
"loopEndIndex"
|
|
4043
|
+
]);
|
|
4044
|
+
const DATA_TARGETS = [
|
|
4045
|
+
"scope",
|
|
4046
|
+
"operationdata",
|
|
4047
|
+
"globaldata"
|
|
4048
|
+
];
|
|
4049
|
+
const identifierPattern = /^[A-Za-z_$][\w$]*$/;
|
|
4050
|
+
/**
|
|
4051
|
+
* Appends a key to a JSON path, in the resolver's notation: dots for plain
|
|
4052
|
+
* keys, brackets for everything else.
|
|
4053
|
+
*/
|
|
4054
|
+
function childPath(path, key) {
|
|
4055
|
+
if (typeof key === "number") return `${path}[${key}]`;
|
|
4056
|
+
return identifierPattern.test(key) ? `${path}.${key}` : `${path}['${key.replace(/'/g, "\\'")}']`;
|
|
4057
|
+
}
|
|
4058
|
+
/**
|
|
4059
|
+
* The operation data keys that are known to be present when an operation
|
|
4060
|
+
* runs, following the list from its start. It never removes a key: a key
|
|
4061
|
+
* erased or cleared inside a branch may still be present on another path,
|
|
4062
|
+
* so the rules only report what is missing on every path.
|
|
4063
|
+
*/
|
|
4064
|
+
var DataFlow = class {
|
|
4065
|
+
_known = /* @__PURE__ */ new Set();
|
|
4066
|
+
/**
|
|
4067
|
+
* True once the data can hold anything: the list started with caller-owned
|
|
4068
|
+
* data, or an operation ran whose effect on the data is not described.
|
|
4069
|
+
*/
|
|
4070
|
+
_unknown;
|
|
4071
|
+
constructor(startsEmpty) {
|
|
4072
|
+
this._unknown = !startsEmpty;
|
|
4073
|
+
}
|
|
4074
|
+
/** True when the absence of a key is certain, not merely undescribed */
|
|
4075
|
+
get certain() {
|
|
4076
|
+
return !this._unknown;
|
|
4077
|
+
}
|
|
4078
|
+
has(key) {
|
|
4079
|
+
return this._known.has(key);
|
|
4080
|
+
}
|
|
4081
|
+
/**
|
|
4082
|
+
* Records what `operation` leaves in the data for the operations after it.
|
|
4083
|
+
*/
|
|
4084
|
+
after(operation, data, metadata) {
|
|
4085
|
+
if (metadata === void 0) this._unknown = true;
|
|
4086
|
+
switch (operation.systemName) {
|
|
4087
|
+
case "setOperationData":
|
|
4088
|
+
if (data && isPlainObject(data.properties)) for (const key of Object.keys(data.properties)) this._known.add(key);
|
|
4089
|
+
break;
|
|
4090
|
+
case "setData":
|
|
4091
|
+
if (data && isPlainObject(data.properties)) for (const target of Object.keys(data.properties)) {
|
|
4092
|
+
const segments = target.split(".");
|
|
4093
|
+
if (segments[0].toLowerCase() === "$operationdata" && segments.length === 2) this._known.add(segments[1]);
|
|
4094
|
+
}
|
|
4095
|
+
break;
|
|
4096
|
+
case "addGlobalsToOperation":
|
|
4097
|
+
if (data && Array.isArray(data.globalProperties)) {
|
|
4098
|
+
for (const name of data.globalProperties) if (typeof name === "string") this._known.add(name);
|
|
4099
|
+
}
|
|
4100
|
+
break;
|
|
4101
|
+
case "customFunction":
|
|
4102
|
+
case "startAction":
|
|
4103
|
+
case "endAction": this._unknown = true;
|
|
4104
|
+
}
|
|
4105
|
+
if (metadata?.outputProperties) for (const key of Object.keys(metadata.outputProperties)) this._known.add(key);
|
|
4106
|
+
if (data) {
|
|
4107
|
+
for (const key of Object.keys(data)) if (data[key] !== void 0 && !isErasedProperty(metadata?.properties?.[key])) this._known.add(key);
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4110
|
+
};
|
|
4111
|
+
/**
|
|
4112
|
+
* Runs every operation-level rule over one operation list.
|
|
4113
|
+
*/
|
|
4114
|
+
function lintOperationList(list, context) {
|
|
4115
|
+
const report = (code, severity, path, message) => {
|
|
4116
|
+
context.diagnostics.push({
|
|
4117
|
+
code,
|
|
4118
|
+
severity,
|
|
4119
|
+
path,
|
|
4120
|
+
message
|
|
4121
|
+
});
|
|
4122
|
+
};
|
|
4123
|
+
const systemNames = list.operations.map((operation) => isOperationConfiguration(operation) ? operation.systemName : "");
|
|
4124
|
+
for (const problem of findFlowControlProblems(systemNames)) report("E101", "error", childPath(childPath(list.path, problem.index), "systemName"), `${problem.message} The engine pops the wrong scope at runtime, and the action fails or runs with the wrong data.`);
|
|
4125
|
+
const flow = new DataFlow(list.startsEmpty);
|
|
4126
|
+
list.operations.forEach((operation, index) => {
|
|
4127
|
+
if (!isOperationConfiguration(operation)) return;
|
|
4128
|
+
const { systemName } = operation;
|
|
4129
|
+
const operationPath = childPath(list.path, index);
|
|
4130
|
+
const dataPath = childPath(operationPath, "operationData");
|
|
4131
|
+
const data = isPlainObject(operation.operationData) ? operation.operationData : void 0;
|
|
4132
|
+
const metadata = getOperationMetadata(systemName);
|
|
4133
|
+
const isCustom = context.customOperations.has(systemName);
|
|
4134
|
+
const hasOwnData = (key) => data !== void 0 && Object.hasOwn(data, key) && data[key] !== void 0;
|
|
4135
|
+
const isAvailable = (key) => flow.has(key) || hasOwnData(key);
|
|
4136
|
+
const reportUnknownRead = (chain, head, path) => {
|
|
4137
|
+
if (flow.certain && head !== "" && !isAvailable(head)) report("W151", "warning", path, `${systemName}: '${chain}' reads '${head}' from the operation data, but no operation before it in this list provides '${head}'.`);
|
|
4138
|
+
};
|
|
4139
|
+
if (data !== void 0) {
|
|
4140
|
+
walkData(data, dataPath, (value, path) => {
|
|
4141
|
+
if (isPlainObject(value) && Object.hasOwn(value, "__proto__")) report("E141", "error", childPath(path, "__proto__"), `${systemName}: operation data must not contain a '__proto__' key. The engine rejects the operation when it runs.`);
|
|
4142
|
+
});
|
|
4143
|
+
walkData(data, dataPath, (value, path, topKey) => {
|
|
4144
|
+
if (typeof value !== "string" || topKey === void 0) return;
|
|
4145
|
+
if (systemName === "when" && topKey === "expression") return;
|
|
4146
|
+
const parsed = getParsedChain(value);
|
|
4147
|
+
if (parsed === null) return;
|
|
4148
|
+
if (parsed.forbidden !== void 0) {
|
|
4149
|
+
report("E140", "error", path, `${systemName}: property chain '${value}' contains forbidden segment '${parsed.forbidden.segment}'. Property chains may not contain __proto__, prototype or constructor.`);
|
|
4150
|
+
return;
|
|
4151
|
+
}
|
|
4152
|
+
if (!resolvesField(systemName, topKey)) {
|
|
4153
|
+
if (!isCustom && metadata !== void 0) report("W150", "warning", path, `${systemName}: '${value}' in '${topKey}' is passed on as text, ${systemName} does not resolve property chains in '${topKey}'. Resolve it first with setOperationData, or use a literal value.`);
|
|
4154
|
+
return;
|
|
4155
|
+
}
|
|
4156
|
+
if (parsed.prefix === "operationdata") reportUnknownRead(value, parsed.segments[0] ?? "", path);
|
|
4157
|
+
});
|
|
4158
|
+
}
|
|
4159
|
+
if (systemName === "when") lintWhen(data, dataPath, report, reportUnknownRead);
|
|
4160
|
+
if (systemName === "setData") lintSetData(data, dataPath, report, reportUnknownRead);
|
|
4161
|
+
if (systemName === "requestAction") lintRequestAction(data, dataPath, context, report);
|
|
4162
|
+
if (metadata !== void 0) {
|
|
4163
|
+
for (const [key, property] of Object.entries(metadata.properties ?? {})) if (isRequiredProperty(property) && !isAvailable(key)) report(flow.certain ? "E111" : "W111", flow.certain ? "error" : "warning", dataPath, `${systemName}: '${key}' is required, and neither its operation data nor an operation before it in this list provides it.`);
|
|
4164
|
+
for (const [key, property] of Object.entries(metadata.properties ?? {})) {
|
|
4165
|
+
const values = literalValuesOf(property);
|
|
4166
|
+
const value = data?.[key];
|
|
4167
|
+
if (values !== void 0 && typeof value === "string" && getParsedChain(value) === null && !values.includes(value)) report("E120", "error", childPath(dataPath, key), `${systemName}: '${key}' must be one of ${values.map((v) => `'${v}'`).join(", ")}, got '${value}'.`);
|
|
4168
|
+
}
|
|
4169
|
+
for (const dependency of metadata.dependentProperties ?? []) {
|
|
4170
|
+
const key = String(dependency);
|
|
4171
|
+
if (flow.certain && !isAvailable(key)) {
|
|
4172
|
+
const producers = findProducers(key);
|
|
4173
|
+
const hint = producers.length > 0 ? ` Operations that provide it: ${producers.slice(0, 4).join(", ")}.` : "";
|
|
4174
|
+
report("W110", "warning", operationPath, `${systemName}: '${key}' must be provided by an earlier operation in this list, but none before it provides it.${hint}`);
|
|
4175
|
+
}
|
|
4176
|
+
}
|
|
4177
|
+
}
|
|
4178
|
+
flow.after(operation, data, metadata);
|
|
4179
|
+
});
|
|
4180
|
+
}
|
|
4181
|
+
function lintWhen(data, dataPath, report, reportUnknownRead) {
|
|
4182
|
+
const expression = data?.expression;
|
|
4183
|
+
if (expression === void 0) return;
|
|
4184
|
+
const path = childPath(dataPath, "expression");
|
|
4185
|
+
let parsed;
|
|
4186
|
+
try {
|
|
4187
|
+
parsed = parseExpression(expression, "when");
|
|
4188
|
+
} catch (error) {
|
|
4189
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4190
|
+
report(/unknown operand/.test(message) ? "E131" : "E130", "error", path, message);
|
|
4191
|
+
return;
|
|
4192
|
+
}
|
|
4193
|
+
for (const chain of collectChainOperands(parsed)) {
|
|
4194
|
+
const parsedChain = getParsedChain(chain);
|
|
4195
|
+
if (parsedChain === null) continue;
|
|
4196
|
+
if (parsedChain.forbidden !== void 0) report("E140", "error", path, `when: property chain '${chain}' contains forbidden segment '${parsedChain.forbidden.segment}'. Property chains may not contain __proto__, prototype or constructor.`);
|
|
4197
|
+
else if (parsedChain.prefix === "operationdata") reportUnknownRead(chain, parsedChain.segments[0] ?? "", path);
|
|
4198
|
+
}
|
|
4199
|
+
}
|
|
4200
|
+
function collectChainOperands(node) {
|
|
4201
|
+
switch (node.kind) {
|
|
4202
|
+
case "operand": return node.operand.kind === "chain" ? [node.operand.chain] : [];
|
|
4203
|
+
case "not": return collectChainOperands(node.operand);
|
|
4204
|
+
default: return [...collectChainOperands(node.left), ...collectChainOperands(node.right)];
|
|
4205
|
+
}
|
|
4206
|
+
}
|
|
4207
|
+
function lintSetData(data, dataPath, report, reportUnknownRead) {
|
|
4208
|
+
const properties = data?.properties;
|
|
4209
|
+
if (!isPlainObject(properties)) return;
|
|
4210
|
+
for (const target of Object.keys(properties)) {
|
|
4211
|
+
const path = childPath(childPath(dataPath, "properties"), target);
|
|
4212
|
+
const segments = target.split(".");
|
|
4213
|
+
const root = segments[0].toLowerCase().substring(1);
|
|
4214
|
+
if (!segments[0].startsWith("$") || !DATA_TARGETS.includes(root)) {
|
|
4215
|
+
report("E160", "error", path, `setData: unrecognized target '${target}'; a target starts with $scope, $operationdata or $globaldata.`);
|
|
4216
|
+
continue;
|
|
4217
|
+
}
|
|
4218
|
+
const rest = segments.slice(1);
|
|
4219
|
+
const forbidden = findForbiddenSegment(rest);
|
|
4220
|
+
if (forbidden !== void 0) {
|
|
4221
|
+
report("E140", "error", path, `setData: property chain '${target}' contains forbidden segment '${forbidden}'. Property chains may not contain __proto__, prototype or constructor.`);
|
|
4222
|
+
continue;
|
|
4223
|
+
}
|
|
4224
|
+
if (root === "scope" && rest.length === 1 && RESERVED_SCOPE_KEYS.has(rest[0])) report("W160", "warning", path, `setData: '${target}' overwrites '${rest[0]}', which the engine uses to run the action. Use $scope.variables.${rest[0]} for your own value.`);
|
|
4225
|
+
if (root === "operationdata" && rest.length > 1) reportUnknownRead(target, rest[0], path);
|
|
4226
|
+
}
|
|
4227
|
+
}
|
|
4228
|
+
function lintRequestAction(data, dataPath, context, report) {
|
|
4229
|
+
const name = data?.systemName;
|
|
4230
|
+
if (typeof name !== "string" || getParsedChain(name) !== null || context.actionNames.has(name)) return;
|
|
4231
|
+
const didYouMean = formatDidYouMean(findClosestNames(name, [...context.actionNames]));
|
|
4232
|
+
report("E310", "error", childPath(dataPath, "systemName"), `requestAction: there is no action named '${name}'. ${didYouMean || "Action names come from actions[].name and eventActions[].name."}`);
|
|
4233
|
+
}
|
|
4234
|
+
/**
|
|
4235
|
+
* Visits every value in the operation data, depth first, with its JSON path
|
|
4236
|
+
* and the top-level key it sits under.
|
|
4237
|
+
*/
|
|
4238
|
+
function walkData(data, dataPath, visit) {
|
|
4239
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
4240
|
+
const walk = (value, path, topKey) => {
|
|
4241
|
+
visit(value, path, topKey);
|
|
4242
|
+
if (value === null || typeof value !== "object" || visiting.has(value)) return;
|
|
4243
|
+
if (Array.isArray(value)) {
|
|
4244
|
+
visiting.add(value);
|
|
4245
|
+
value.forEach((item, index) => walk(item, childPath(path, index), topKey));
|
|
4246
|
+
visiting.delete(value);
|
|
4247
|
+
return;
|
|
4248
|
+
}
|
|
4249
|
+
if (!isPlainObject(value)) return;
|
|
4250
|
+
visiting.add(value);
|
|
4251
|
+
for (const key of Object.keys(value)) walk(value[key], childPath(path, key), topKey ?? key);
|
|
4252
|
+
visiting.delete(value);
|
|
4253
|
+
};
|
|
4254
|
+
walk(data, dataPath, void 0);
|
|
4255
|
+
}
|
|
4256
|
+
|
|
4257
|
+
// src/lint/lint-configuration.ts
|
|
4258
|
+
/**
|
|
4259
|
+
* Checks a configuration without a DOM and without running it, and returns
|
|
4260
|
+
* what the engine would reject or what is likely wrong.
|
|
4261
|
+
*
|
|
4262
|
+
* The real `ConfigurationResolver` runs first, with a stand-in for every
|
|
4263
|
+
* operation, controller and timeline provider, so every error it throws at
|
|
4264
|
+
* `createEngine` time is reported here with the same message and JSON path
|
|
4265
|
+
* (code `E001`). The structural and data-flow rules then run over every
|
|
4266
|
+
* operation list:
|
|
4267
|
+
*
|
|
4268
|
+
* - `E101` control-flow blocks that are not balanced or do not nest
|
|
4269
|
+
* - `E111` a required property that nothing provides (`W111` when the list
|
|
4270
|
+
* starts with caller-owned data)
|
|
4271
|
+
* - `E120` a literal outside its allowed values
|
|
4272
|
+
* - `E130`, `E131` a `when` expression that does not parse, an unknown operand
|
|
4273
|
+
* - `E140` a property chain with a forbidden segment
|
|
4274
|
+
* - `E141` a `__proto__` key in operation data
|
|
4275
|
+
* - `E160` an unrecognized `setData` target, `W160` a reserved scope field
|
|
4276
|
+
* - `E310` a `requestAction` name that no action has
|
|
4277
|
+
* - `W110` a dependency on an earlier operation that no earlier operation provides
|
|
4278
|
+
* - `W150` a property chain in a field the operation does not resolve
|
|
4279
|
+
* - `W151` an `$operationdata` read of a property that nothing provides
|
|
4280
|
+
*
|
|
4281
|
+
* Errors are certain: the engine throws, or the operation fails when it
|
|
4282
|
+
* runs. Warnings are likely mistakes. Data-flow warnings are only reported
|
|
4283
|
+
* for the operation lists that start with empty data (timeline actions and
|
|
4284
|
+
* init actions), and never after an operation whose effect on the data is
|
|
4285
|
+
* not described (a custom operation, `customFunction`, `startAction`).
|
|
4286
|
+
*
|
|
4287
|
+
* The configuration is not changed.
|
|
4288
|
+
*
|
|
4289
|
+
* @param configuration - The configuration to check
|
|
4290
|
+
* @param options - The custom resources the host registers, so their names
|
|
4291
|
+
* are accepted
|
|
4292
|
+
* @returns The diagnostics, resolver errors first, then in document order.
|
|
4293
|
+
* Empty when nothing was found.
|
|
4294
|
+
*
|
|
4295
|
+
* @example
|
|
4296
|
+
* ```ts
|
|
4297
|
+
* import {lintConfiguration} from 'eligius/lint';
|
|
4298
|
+
*
|
|
4299
|
+
* const diagnostics = lintConfiguration(configuration, {
|
|
4300
|
+
* customOperations: ['trackEvent'],
|
|
4301
|
+
* });
|
|
4302
|
+
* for (const {severity, code, path, message} of diagnostics) {
|
|
4303
|
+
* console.log(`${severity} ${code} at ${path}: ${message}`);
|
|
4304
|
+
* }
|
|
4305
|
+
* ```
|
|
4306
|
+
*/
|
|
4307
|
+
function lintConfiguration(configuration, options = {}) {
|
|
4308
|
+
if (!isPlainObject(configuration)) return [{
|
|
4309
|
+
code: "E001",
|
|
4310
|
+
severity: "error",
|
|
4311
|
+
path: "",
|
|
4312
|
+
message: `The configuration must be an object, got ${describeKind(configuration)}.`
|
|
4313
|
+
}];
|
|
4314
|
+
const diagnostics = [];
|
|
4315
|
+
const copy = deepCopy(configuration);
|
|
4316
|
+
const importer = createLintImporter(options, collectPlaceholderNames(copy));
|
|
4317
|
+
const resolver = new ConfigurationResolver(importer, new Eventbus(), { onWarning: () => {} });
|
|
4318
|
+
try {
|
|
4319
|
+
resolver.process(copy, new ActionRegistryEventbusListener());
|
|
4320
|
+
} catch (error) {
|
|
4321
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4322
|
+
diagnostics.push({
|
|
4323
|
+
code: "E001",
|
|
4324
|
+
severity: "error",
|
|
4325
|
+
path: extractPath(message),
|
|
4326
|
+
message
|
|
4327
|
+
});
|
|
4328
|
+
}
|
|
4329
|
+
const context = {
|
|
4330
|
+
diagnostics,
|
|
4331
|
+
actionNames: collectActionNames(configuration),
|
|
4332
|
+
customOperations: new Set(options.customOperations ?? [])
|
|
4333
|
+
};
|
|
4334
|
+
for (const list of collectOperationLists(configuration)) lintOperationList(list, context);
|
|
4335
|
+
return diagnostics;
|
|
4336
|
+
}
|
|
4337
|
+
function describeKind(value) {
|
|
4338
|
+
if (value === null) return "null";
|
|
4339
|
+
if (Array.isArray(value)) return "an array";
|
|
4340
|
+
return typeof value === "undefined" ? "undefined" : `a ${typeof value}`;
|
|
4341
|
+
}
|
|
4342
|
+
const TOP_LEVEL_KEYS = /* @__PURE__ */ new Set([
|
|
4343
|
+
"id",
|
|
4344
|
+
"engine",
|
|
4345
|
+
"timelineProviderSettings",
|
|
4346
|
+
"containerSelector",
|
|
4347
|
+
"cssFiles",
|
|
4348
|
+
"language",
|
|
4349
|
+
"layoutTemplate",
|
|
4350
|
+
"availableLanguages",
|
|
4351
|
+
"initActions",
|
|
4352
|
+
"actions",
|
|
4353
|
+
"eventActions",
|
|
4354
|
+
"timelines",
|
|
4355
|
+
"timelineFlow",
|
|
4356
|
+
"locales"
|
|
4357
|
+
]);
|
|
4358
|
+
const pathPattern = /\bat ((?:[A-Za-z_$][\w$]*)(?:\.[A-Za-z_$][\w$]*|\[\d+\]|\['[^']*'\])*)/g;
|
|
4359
|
+
/**
|
|
4360
|
+
* The JSON path a resolver message names: the first `at <path>` whose first
|
|
4361
|
+
* segment is a top-level configuration key.
|
|
4362
|
+
*/
|
|
4363
|
+
function extractPath(message) {
|
|
4364
|
+
for (const match of message.matchAll(pathPattern)) {
|
|
4365
|
+
const path = match[1];
|
|
4366
|
+
const firstSegment = path.split(/[.[]/, 1)[0];
|
|
4367
|
+
if (TOP_LEVEL_KEYS.has(firstSegment)) return path.replace(/[.,:]$/, "");
|
|
4368
|
+
}
|
|
4369
|
+
return "";
|
|
4370
|
+
}
|
|
4371
|
+
function collectActionNames(configuration) {
|
|
4372
|
+
const names = /* @__PURE__ */ new Set();
|
|
4373
|
+
for (const list of [configuration.actions, configuration.eventActions]) if (Array.isArray(list)) {
|
|
4374
|
+
for (const action of list) if (isPlainObject(action) && typeof action.name === "string") names.add(action.name);
|
|
4375
|
+
}
|
|
4376
|
+
return names;
|
|
4377
|
+
}
|
|
4378
|
+
/**
|
|
4379
|
+
* The names the `template:` and `json:` placeholders of the configuration
|
|
4380
|
+
* ask the importer for. Walks what the resolver walks: plain objects and
|
|
4381
|
+
* arrays.
|
|
4382
|
+
*/
|
|
4383
|
+
function collectPlaceholderNames(configuration) {
|
|
4384
|
+
const templates = /* @__PURE__ */ new Set();
|
|
4385
|
+
const json = /* @__PURE__ */ new Set();
|
|
4386
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
4387
|
+
const walk = (value) => {
|
|
4388
|
+
if (typeof value === "string") {
|
|
4389
|
+
if (value.startsWith("template:")) templates.add(value.substring(9));
|
|
4390
|
+
else if (value.startsWith("json:")) json.add(value.substring(5));
|
|
4391
|
+
return;
|
|
4392
|
+
}
|
|
4393
|
+
if (value === null || typeof value !== "object" || visiting.has(value)) return;
|
|
4394
|
+
if (Array.isArray(value)) {
|
|
4395
|
+
visiting.add(value);
|
|
4396
|
+
value.forEach(walk);
|
|
4397
|
+
visiting.delete(value);
|
|
4398
|
+
} else if (isPlainObject(value)) {
|
|
4399
|
+
visiting.add(value);
|
|
4400
|
+
for (const key of Object.keys(value)) walk(value[key]);
|
|
4401
|
+
visiting.delete(value);
|
|
4402
|
+
}
|
|
4403
|
+
};
|
|
4404
|
+
walk(configuration);
|
|
4405
|
+
return {
|
|
4406
|
+
templates,
|
|
4407
|
+
json
|
|
4408
|
+
};
|
|
4409
|
+
}
|
|
4410
|
+
|
|
4411
|
+
export { findFlowControlProblems, lintConfiguration };
|
|
4412
|
+
//# sourceMappingURL=lint.mjs.map
|