@xpell/core 2.0.1 → 2.0.3
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/dist/FPSCalc.d.ts +18 -0
- package/dist/XDataModule.d.ts +12 -0
- package/dist/XObject.d.ts +24 -1
- package/dist/XUtils.d.ts +93 -18
- package/dist/Xpell.d.ts +1 -1
- package/dist/xpell-core.cjs.js +3 -2
- package/dist/xpell-core.es.js +884 -507
- package/docs/AGENTS.md +10 -0
- package/package.json +2 -2
- package/docs/Codex.md +0 -138
- package/docs/Codex_Skills/SKILL.md +0 -184
- package/docs/Codex_Skills/SKILL_API_MAP.md +0 -122
- package/docs/Codex_Skills/SKILL_CHECKLIST.md +0 -18
package/dist/xpell-core.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
1
|
+
var B = (o) => {
|
|
2
2
|
throw TypeError(o);
|
|
3
3
|
};
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
class
|
|
4
|
+
var z = (o, e, t) => e.has(o) || B("Cannot " + t);
|
|
5
|
+
var f = (o, e, t) => (z(o, e, "read from private field"), t ? t.call(o) : e.get(o)), J = (o, e, t) => e.has(o) ? B("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(o) : e.set(o, t), V = (o, e, t, s) => (z(o, e, "write to private field"), s ? s.call(o, t) : e.set(o, t), t);
|
|
6
|
+
class Y {
|
|
7
7
|
/**
|
|
8
8
|
* Create ignore list for parser to ignore spell words
|
|
9
9
|
* @param list - comma-separated list of words
|
|
@@ -11,8 +11,8 @@ class Q {
|
|
|
11
11
|
*/
|
|
12
12
|
createIgnoreList(e, t) {
|
|
13
13
|
if (!e) return t;
|
|
14
|
-
const s = e.split(",").map((
|
|
15
|
-
for (const
|
|
14
|
+
const s = e.split(",").map((r) => r.trim()).filter(Boolean);
|
|
15
|
+
for (const r of s) t[r] = "";
|
|
16
16
|
return t;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
@@ -30,15 +30,15 @@ class Q {
|
|
|
30
30
|
if (t && typeof t.getRandomValues == "function") {
|
|
31
31
|
const i = new Uint8Array(16);
|
|
32
32
|
t.getRandomValues(i), i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128;
|
|
33
|
-
const
|
|
34
|
-
return
|
|
33
|
+
const c = Array.from(i, (a) => a.toString(16).padStart(2, "0"));
|
|
34
|
+
return c.slice(0, 4).join("") + "-" + c.slice(4, 6).join("") + "-" + c.slice(6, 8).join("") + "-" + c.slice(8, 10).join("") + "-" + c.slice(10, 16).join("");
|
|
35
35
|
}
|
|
36
|
-
const s = "0123456789abcdef".split(""),
|
|
37
|
-
let
|
|
38
|
-
|
|
36
|
+
const s = "0123456789abcdef".split(""), r = [];
|
|
37
|
+
let n;
|
|
38
|
+
r[8] = r[13] = r[18] = r[23] = "-", r[14] = "4";
|
|
39
39
|
for (let i = 0; i < 36; i++)
|
|
40
|
-
|
|
41
|
-
return
|
|
40
|
+
r[i] || (n = (0 | Math.random() * 16) >>> 0, r[i] = s[i === 19 ? n & 3 | 8 : n & 15]);
|
|
41
|
+
return r.join("");
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* Merge defaults into data object (mutates data)
|
|
@@ -49,10 +49,20 @@ class Q {
|
|
|
49
49
|
mergeDefaultsWithData(e, t, s = !1) {
|
|
50
50
|
if (!e) return t;
|
|
51
51
|
e._id || (e._id = e.id ?? this.guid());
|
|
52
|
-
for (const
|
|
53
|
-
(!(
|
|
52
|
+
for (const r of Object.keys(t))
|
|
53
|
+
(!(r in e) || s) && (e[r] = t[r]);
|
|
54
54
|
return e;
|
|
55
55
|
}
|
|
56
|
+
deepMergeDefaults(e, t) {
|
|
57
|
+
if (!e || typeof e != "object" || Array.isArray(e))
|
|
58
|
+
return structuredClone(t);
|
|
59
|
+
const s = structuredClone(t);
|
|
60
|
+
for (const r of Object.keys(e)) {
|
|
61
|
+
const n = e[r], i = t?.[r];
|
|
62
|
+
n && typeof n == "object" && !Array.isArray(n) && i && typeof i == "object" && !Array.isArray(i) ? s[r] = this.deepMergeDefaults(n, i) : s[r] = n;
|
|
63
|
+
}
|
|
64
|
+
return s;
|
|
65
|
+
}
|
|
56
66
|
/**
|
|
57
67
|
* Encode string to Base64 (UTF-8 safe, cross-platform)
|
|
58
68
|
*/
|
|
@@ -61,7 +71,7 @@ class Q {
|
|
|
61
71
|
if (typeof t.btoa == "function") {
|
|
62
72
|
const s = encodeURIComponent(String(e)).replace(
|
|
63
73
|
/%([0-9A-F]{2})/g,
|
|
64
|
-
(
|
|
74
|
+
(r, n) => String.fromCharCode(parseInt(n, 16))
|
|
65
75
|
);
|
|
66
76
|
return t.btoa(s);
|
|
67
77
|
}
|
|
@@ -75,8 +85,8 @@ class Q {
|
|
|
75
85
|
decode(e) {
|
|
76
86
|
const t = globalThis;
|
|
77
87
|
if (typeof t.atob == "function") {
|
|
78
|
-
const s = t.atob(String(e)),
|
|
79
|
-
return decodeURIComponent(
|
|
88
|
+
const s = t.atob(String(e)), r = Array.prototype.map.call(s, (n) => "%" + n.charCodeAt(0).toString(16).padStart(2, "0")).join("");
|
|
89
|
+
return decodeURIComponent(r);
|
|
80
90
|
}
|
|
81
91
|
if (t.Buffer && typeof t.Buffer.from == "function")
|
|
82
92
|
return t.Buffer.from(String(e), "base64").toString("utf8");
|
|
@@ -103,12 +113,12 @@ class Q {
|
|
|
103
113
|
createDefaultScheduler(e) {
|
|
104
114
|
const t = globalThis;
|
|
105
115
|
if (typeof t.requestAnimationFrame == "function")
|
|
106
|
-
return (
|
|
116
|
+
return (n) => t.requestAnimationFrame(n);
|
|
107
117
|
const s = typeof e == "number" && isFinite(e) && e > 0 ? e : 60;
|
|
108
118
|
if (typeof t.setImmediate == "function" && (!e || e >= 60))
|
|
109
|
-
return (
|
|
110
|
-
const
|
|
111
|
-
return (
|
|
119
|
+
return (n) => t.setImmediate(n);
|
|
120
|
+
const r = Math.max(1, Math.round(1e3 / s));
|
|
121
|
+
return (n) => t.setTimeout(n, r);
|
|
112
122
|
}
|
|
113
123
|
to_iso_now() {
|
|
114
124
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -116,11 +126,28 @@ class Q {
|
|
|
116
126
|
is_plain_object(e) {
|
|
117
127
|
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
118
128
|
}
|
|
129
|
+
ensure_object(e, t) {
|
|
130
|
+
if (!this.is_plain_object(e))
|
|
131
|
+
throw new Error(`Invalid '${t}'`);
|
|
132
|
+
return e;
|
|
133
|
+
}
|
|
119
134
|
ensure_string(e, t) {
|
|
120
135
|
if (typeof e != "string" || !e.trim())
|
|
121
136
|
throw new Error(`Invalid '${t}'`);
|
|
122
137
|
return e.trim();
|
|
123
138
|
}
|
|
139
|
+
ensure_boolean(e, t) {
|
|
140
|
+
if (typeof e == "boolean") return e;
|
|
141
|
+
if (e === "true") return !0;
|
|
142
|
+
if (e === "false") return !1;
|
|
143
|
+
throw new Error(`Invalid '${t}'`);
|
|
144
|
+
}
|
|
145
|
+
ensure_number(e, t) {
|
|
146
|
+
const s = Number(e);
|
|
147
|
+
if (isNaN(s))
|
|
148
|
+
throw new Error(`Invalid '${t}'`);
|
|
149
|
+
return s;
|
|
150
|
+
}
|
|
124
151
|
ensure_params(e) {
|
|
125
152
|
return this.is_plain_object(e) ? e : {};
|
|
126
153
|
}
|
|
@@ -130,9 +157,9 @@ class Q {
|
|
|
130
157
|
*/
|
|
131
158
|
addIfNotNull(e, t, s) {
|
|
132
159
|
if (!(!e || !t || !Array.isArray(s)))
|
|
133
|
-
for (const
|
|
134
|
-
const
|
|
135
|
-
|
|
160
|
+
for (const r of s) {
|
|
161
|
+
const n = e[r];
|
|
162
|
+
n != null && (t[r] = n);
|
|
136
163
|
}
|
|
137
164
|
}
|
|
138
165
|
/**
|
|
@@ -175,38 +202,269 @@ class Q {
|
|
|
175
202
|
calculateExpiration(e) {
|
|
176
203
|
const s = String(e ?? "").trim().match(/^(\d+)([hdy])$/);
|
|
177
204
|
if (!s) throw new Error("Invalid expiration format. Use: 1h | 2d | 3y");
|
|
178
|
-
const
|
|
179
|
-
let
|
|
180
|
-
switch (
|
|
205
|
+
const r = Number.parseInt(s[1], 10), n = s[2], i = Date.now();
|
|
206
|
+
let c = 0;
|
|
207
|
+
switch (n) {
|
|
181
208
|
case "h":
|
|
182
|
-
|
|
209
|
+
c = r * 60 * 60 * 1e3;
|
|
183
210
|
break;
|
|
184
211
|
case "d":
|
|
185
|
-
|
|
212
|
+
c = r * 24 * 60 * 60 * 1e3;
|
|
186
213
|
break;
|
|
187
214
|
case "y":
|
|
188
|
-
|
|
215
|
+
c = r * 365 * 24 * 60 * 60 * 1e3;
|
|
189
216
|
break;
|
|
190
217
|
}
|
|
191
|
-
return i +
|
|
218
|
+
return i + c;
|
|
219
|
+
}
|
|
220
|
+
// ============================================================================
|
|
221
|
+
// AI / Runtime Primitive Helpers
|
|
222
|
+
// ============================================================================
|
|
223
|
+
normalize_prompt(e) {
|
|
224
|
+
return String(e ?? "").normalize("NFKC").replace(/\s+/g, " ").trim();
|
|
225
|
+
}
|
|
226
|
+
normalize_prompt_key(e) {
|
|
227
|
+
return this.normalize_prompt(e).toLowerCase().replace(/[_/]+/g, " ");
|
|
228
|
+
}
|
|
229
|
+
is_non_empty_string(e) {
|
|
230
|
+
return typeof e == "string" && e.trim().length > 0;
|
|
231
|
+
}
|
|
232
|
+
has_value(e) {
|
|
233
|
+
return e == null ? !1 : Array.isArray(e) ? e.length > 0 : typeof e == "object" ? Object.keys(e).length > 0 : !0;
|
|
234
|
+
}
|
|
235
|
+
ensure_array(e) {
|
|
236
|
+
return Array.isArray(e) ? e : e == null ? [] : [e];
|
|
237
|
+
}
|
|
238
|
+
to_record(e) {
|
|
239
|
+
return this.is_plain_object(e) ? e : {};
|
|
240
|
+
}
|
|
241
|
+
safe_json_parse(e, t) {
|
|
242
|
+
if (typeof e != "string") return t;
|
|
243
|
+
try {
|
|
244
|
+
return JSON.parse(e);
|
|
245
|
+
} catch {
|
|
246
|
+
return t;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
safe_json_stringify(e, t = "{}") {
|
|
250
|
+
try {
|
|
251
|
+
return JSON.stringify(e);
|
|
252
|
+
} catch {
|
|
253
|
+
return t;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
clone_json(e) {
|
|
257
|
+
return this.safe_json_parse(
|
|
258
|
+
this.safe_json_stringify(e, "null"),
|
|
259
|
+
e
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
get_path(e, t, s) {
|
|
263
|
+
const r = Array.isArray(t) ? t : String(t ?? "").split(".").filter(Boolean);
|
|
264
|
+
let n = e;
|
|
265
|
+
for (const i of r) {
|
|
266
|
+
if (n == null) return s;
|
|
267
|
+
n = n[i];
|
|
268
|
+
}
|
|
269
|
+
return n === void 0 ? s : n;
|
|
270
|
+
}
|
|
271
|
+
set_path(e, t, s) {
|
|
272
|
+
const r = Array.isArray(t) ? t : String(t ?? "").split(".").filter(Boolean);
|
|
273
|
+
if (!r.length) return e;
|
|
274
|
+
let n = e;
|
|
275
|
+
for (let i = 0; i < r.length - 1; i++) {
|
|
276
|
+
const c = r[i];
|
|
277
|
+
this.is_plain_object(n[c]) || (n[c] = {}), n = n[c];
|
|
278
|
+
}
|
|
279
|
+
return n[r[r.length - 1]] = s, e;
|
|
280
|
+
}
|
|
281
|
+
pick_defined(e, t) {
|
|
282
|
+
const s = {};
|
|
283
|
+
if (!this.is_plain_object(e) || !Array.isArray(t)) return s;
|
|
284
|
+
for (const r of t) {
|
|
285
|
+
const n = e[r];
|
|
286
|
+
n != null && (s[r] = n);
|
|
287
|
+
}
|
|
288
|
+
return s;
|
|
289
|
+
}
|
|
290
|
+
omit_undefined(e) {
|
|
291
|
+
const t = {};
|
|
292
|
+
if (!this.is_plain_object(e)) return t;
|
|
293
|
+
for (const [s, r] of Object.entries(e))
|
|
294
|
+
r !== void 0 && (t[s] = r);
|
|
295
|
+
return t;
|
|
296
|
+
}
|
|
297
|
+
escape_regexp(e) {
|
|
298
|
+
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
299
|
+
}
|
|
300
|
+
matches_keyword(e, t) {
|
|
301
|
+
const s = /^[a-z0-9]+$/.test(t) ? "s?" : "";
|
|
302
|
+
return new RegExp(
|
|
303
|
+
`(^|[^a-z0-9])${this.escape_regexp(t)}${s}($|[^a-z0-9])`
|
|
304
|
+
).test(e);
|
|
305
|
+
}
|
|
306
|
+
match_keywords(e, t) {
|
|
307
|
+
return t.filter((s) => this.matches_keyword(e, s));
|
|
308
|
+
}
|
|
309
|
+
contains_keyword(e, t) {
|
|
310
|
+
return this.match_keywords(e, t).length > 0;
|
|
311
|
+
}
|
|
312
|
+
read_optional_string(e, t) {
|
|
313
|
+
if (e != null) {
|
|
314
|
+
if (typeof e != "string" || e.trim().length === 0)
|
|
315
|
+
throw new Error(`Invalid '${t}': expected non-empty string`);
|
|
316
|
+
return e.trim();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
read_optional_boolean(e, t) {
|
|
320
|
+
if (e != null) {
|
|
321
|
+
if (typeof e != "boolean")
|
|
322
|
+
throw new Error(`Invalid '${t}': expected boolean`);
|
|
323
|
+
return e;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
read_optional_number(e, t) {
|
|
327
|
+
if (e != null) {
|
|
328
|
+
if (typeof e != "number" || !isFinite(e))
|
|
329
|
+
throw new Error(`Invalid '${t}': expected finite number`);
|
|
330
|
+
return e;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
read_optional_object(e, t) {
|
|
334
|
+
if (e != null) {
|
|
335
|
+
if (!this.is_plain_object(e))
|
|
336
|
+
throw new Error(`Invalid '${t}': expected plain object`);
|
|
337
|
+
return e;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Returns unique string values while preserving insertion order.
|
|
342
|
+
*
|
|
343
|
+
* Example:
|
|
344
|
+
* ["a", "b", "a"] -> ["a", "b"]
|
|
345
|
+
*/
|
|
346
|
+
unique_strings(e) {
|
|
347
|
+
return Array.from(new Set(e));
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Normalizes IDs (trim + lowercase) and removes duplicates.
|
|
351
|
+
*
|
|
352
|
+
* Example:
|
|
353
|
+
* [" User ", "user", "ADMIN"] -> ["user", "admin"]
|
|
354
|
+
*/
|
|
355
|
+
unique_normalized_ids(e) {
|
|
356
|
+
return Array.from(
|
|
357
|
+
new Set(
|
|
358
|
+
e.map((t) => t.trim().toLowerCase()).filter((t) => t.length > 0)
|
|
359
|
+
)
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Truncates long text while preserving the beginning.
|
|
364
|
+
* Appends a truncation marker when the text exceeds max_chars.
|
|
365
|
+
*/
|
|
366
|
+
truncate_text(e, t) {
|
|
367
|
+
return e.length <= t ? e : `${e.slice(0, Math.max(0, t - 18))}
|
|
368
|
+
...[truncated]`;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Serializes a value as formatted JSON and truncates the result
|
|
372
|
+
* when it exceeds the specified character limit.
|
|
373
|
+
*/
|
|
374
|
+
compact_json(e, t = 5e3) {
|
|
375
|
+
return this.truncate_text(
|
|
376
|
+
JSON.stringify(e, null, 2),
|
|
377
|
+
t
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Serializes a value as compact single-line JSON and truncates
|
|
382
|
+
* the result when it exceeds the specified character limit.
|
|
383
|
+
*/
|
|
384
|
+
compact_inline_json(e, t = 5e3) {
|
|
385
|
+
return this.truncate_text(
|
|
386
|
+
JSON.stringify(e),
|
|
387
|
+
t
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Safe version of compact_inline_json().
|
|
392
|
+
* Returns an empty string when serialization fails.
|
|
393
|
+
*/
|
|
394
|
+
safe_compact_inline_json(e, t = 5e3) {
|
|
395
|
+
try {
|
|
396
|
+
return this.compact_inline_json(e, t);
|
|
397
|
+
} catch {
|
|
398
|
+
return "";
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Returns the first max_items items from an array.
|
|
403
|
+
* Returns an empty array for non-array values.
|
|
404
|
+
*/
|
|
405
|
+
compact_array(e, t = 20) {
|
|
406
|
+
return Array.isArray(e) ? e.slice(0, t) : [];
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Normalizes arbitrary text into a stable identifier.
|
|
410
|
+
*
|
|
411
|
+
* Example:
|
|
412
|
+
* "User Profile" -> "user-profile"
|
|
413
|
+
* "user_profile" -> "user-profile"
|
|
414
|
+
*/
|
|
415
|
+
normalize_id(e) {
|
|
416
|
+
if (typeof e != "string") return;
|
|
417
|
+
const t = e.toLowerCase().trim().replace(/[_\s]+/gu, "-").replace(/[^a-z0-9-]+/gu, "-").replace(/-+/gu, "-").replace(/^-|-$/gu, "");
|
|
418
|
+
return t.length > 0 ? t : void 0;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Normalizes an array of identifiers and removes duplicates.
|
|
422
|
+
*
|
|
423
|
+
* Example:
|
|
424
|
+
* ["User Profile", "user-profile"]
|
|
425
|
+
* -> ["user-profile"]
|
|
426
|
+
*/
|
|
427
|
+
normalize_id_array(e) {
|
|
428
|
+
return Array.isArray(e) ? e.map((t) => this.normalize_id(t)).filter((t) => typeof t == "string").filter((t, s, r) => r.indexOf(t) === s) : [];
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* @deprecated Use normalize_id_array().
|
|
432
|
+
*/
|
|
433
|
+
normalize_string_array(e) {
|
|
434
|
+
return this.normalize_id_array(e);
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Returns only plain object items from an array.
|
|
438
|
+
* Non-object values, nulls, and arrays are ignored.
|
|
439
|
+
*/
|
|
440
|
+
ensure_object_array(e) {
|
|
441
|
+
return Array.isArray(e) ? e.filter(
|
|
442
|
+
(t) => this.is_plain_object(t)
|
|
443
|
+
) : [];
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* @deprecated Use ensure_object_array().
|
|
447
|
+
*/
|
|
448
|
+
read_object_array(e) {
|
|
449
|
+
return this.ensure_object_array(e);
|
|
192
450
|
}
|
|
193
451
|
}
|
|
194
|
-
const
|
|
195
|
-
class
|
|
452
|
+
const Z = new Y(), u = Z;
|
|
453
|
+
class ee {
|
|
196
454
|
#e = 0;
|
|
197
455
|
// displayed fps (stable)
|
|
198
456
|
#t = 0;
|
|
199
457
|
// EMA of ms/frame
|
|
200
458
|
#s = 0;
|
|
201
|
-
#n;
|
|
202
|
-
// weight of new samples (0..1)
|
|
203
459
|
#r;
|
|
460
|
+
// weight of new samples (0..1)
|
|
461
|
+
#n;
|
|
204
462
|
// minimum integer change to update displayed fps
|
|
205
463
|
constructor(e = 0.05, t = 1) {
|
|
206
464
|
const s = Number(e);
|
|
207
|
-
this.#
|
|
208
|
-
const
|
|
209
|
-
this.#
|
|
465
|
+
this.#r = Number.isFinite(s) ? Math.min(1, Math.max(1e-3, s)) : 0.05;
|
|
466
|
+
const r = Number(t);
|
|
467
|
+
this.#n = Number.isFinite(r) ? Math.max(0, Math.floor(r)) : 1;
|
|
210
468
|
}
|
|
211
469
|
now() {
|
|
212
470
|
const e = globalThis.performance;
|
|
@@ -218,17 +476,17 @@ class Y {
|
|
|
218
476
|
return this.#s = e, this.#e;
|
|
219
477
|
const t = e - this.#s;
|
|
220
478
|
if (this.#s = e, !Number.isFinite(t) || t <= 0) return this.#e;
|
|
221
|
-
this.#t === 0 ? this.#t = t : this.#t = (1 - this.#
|
|
479
|
+
this.#t === 0 ? this.#t = t : this.#t = (1 - this.#r) * this.#t + this.#r * t;
|
|
222
480
|
const s = 1e3 / this.#t;
|
|
223
481
|
if (!Number.isFinite(s) || s <= 0) return this.#e;
|
|
224
|
-
const
|
|
225
|
-
return this.#e !== 0 && this.#
|
|
482
|
+
const r = Math.round(s);
|
|
483
|
+
return this.#e !== 0 && this.#n > 0 && Math.abs(r - this.#e) < this.#n ? this.#e : (this.#e = r, this.#e);
|
|
226
484
|
}
|
|
227
485
|
reset() {
|
|
228
486
|
this.#e = 0, this.#t = 0, this.#s = 0;
|
|
229
487
|
}
|
|
230
488
|
}
|
|
231
|
-
class
|
|
489
|
+
class te {
|
|
232
490
|
constructor(e) {
|
|
233
491
|
this._enabled = !0, this._show_date = !1, this._show_time = !0, this._debug = !1, e && this.configure(e);
|
|
234
492
|
}
|
|
@@ -252,12 +510,12 @@ class Z {
|
|
|
252
510
|
!this._enabled || !this._debug || console.debug(this._dt(), e, ...t);
|
|
253
511
|
}
|
|
254
512
|
}
|
|
255
|
-
const
|
|
256
|
-
|
|
513
|
+
const h = new te(), Q = typeof process < "u" && !!process?.env && process.env.NODE_ENV === "production";
|
|
514
|
+
Q || console.info(
|
|
257
515
|
"[Xpell] _xlog is redirected to console in development mode. Tip: enable 'Show timestamps' in DevTools → Console for timed logs."
|
|
258
516
|
);
|
|
259
|
-
const
|
|
260
|
-
class
|
|
517
|
+
const x = Q ? h : console;
|
|
518
|
+
class se {
|
|
261
519
|
constructor() {
|
|
262
520
|
this._objects = {}, this._listeners = /* @__PURE__ */ new Map(), this._any_listeners = /* @__PURE__ */ new Set(), this._compat_writes = !0, this._warn_legacy_writes = !0, this._verbose = !1, this._compat_legacy_keys = !0, this._o_proxy = null, this._objects = {};
|
|
263
521
|
}
|
|
@@ -269,10 +527,10 @@ class ee {
|
|
|
269
527
|
get _o() {
|
|
270
528
|
return !this._compat_writes && !this._warn_legacy_writes ? this._objects : (this._o_proxy || (this._o_proxy = new Proxy(this._objects, {
|
|
271
529
|
set: (e, t, s) => {
|
|
272
|
-
const
|
|
530
|
+
const r = String(t);
|
|
273
531
|
return this._warn_legacy_writes && console.warn(
|
|
274
|
-
`[XData] Legacy write: _o["${
|
|
275
|
-
), this._compat_writes ? this.set(
|
|
532
|
+
`[XData] Legacy write: _o["${r}"] = ... ; prefer XData.set("${r}", value).`
|
|
533
|
+
), this._compat_writes ? this.set(r, s, { source: "legacy:_o" }) : e[r] = s, !0;
|
|
276
534
|
},
|
|
277
535
|
deleteProperty: (e, t) => {
|
|
278
536
|
const s = String(t);
|
|
@@ -288,13 +546,13 @@ class ee {
|
|
|
288
546
|
}
|
|
289
547
|
/** Preferred write API */
|
|
290
548
|
set(e, t, s) {
|
|
291
|
-
const
|
|
292
|
-
this._objects[e] = t, this._emit({ key: e, value: t, prev:
|
|
549
|
+
const r = this._objects[e];
|
|
550
|
+
this._objects[e] = t, this._emit({ key: e, value: t, prev: r, ts: Date.now(), op: "set", meta: s });
|
|
293
551
|
}
|
|
294
552
|
/** Shallow merge helper (nice for state objects) */
|
|
295
553
|
patch(e, t, s) {
|
|
296
|
-
const
|
|
297
|
-
this._objects[e] = i, this._emit({ key: e, value: i, prev:
|
|
554
|
+
const r = this._objects[e], i = { ...r && typeof r == "object" ? r : {}, ...t };
|
|
555
|
+
this._objects[e] = i, this._emit({ key: e, value: i, prev: r, ts: Date.now(), op: "patch", meta: s });
|
|
298
556
|
}
|
|
299
557
|
/** In-place mutation notifier */
|
|
300
558
|
touch(e, t) {
|
|
@@ -339,8 +597,8 @@ class ee {
|
|
|
339
597
|
for (const s of this._any_listeners) s(e);
|
|
340
598
|
}
|
|
341
599
|
}
|
|
342
|
-
const
|
|
343
|
-
class
|
|
600
|
+
const v = new se(), m = v;
|
|
601
|
+
class N {
|
|
344
602
|
constructor(e) {
|
|
345
603
|
e && Object.keys(e).forEach((t) => {
|
|
346
604
|
this[t] = e[t];
|
|
@@ -360,17 +618,17 @@ class I {
|
|
|
360
618
|
return this._params?.hasOwnProperty(t) ? this._params[t] : this._params?.hasOwnProperty(e) ? this._params[e] : s;
|
|
361
619
|
}
|
|
362
620
|
}
|
|
363
|
-
const
|
|
621
|
+
const E = {
|
|
364
622
|
type: "_type",
|
|
365
623
|
children: "_children"
|
|
366
|
-
},
|
|
624
|
+
}, j = class j {
|
|
367
625
|
/**
|
|
368
626
|
* Adds HTML-Xpell Mapping item
|
|
369
627
|
* @param htmlElement HTML element to change from
|
|
370
628
|
* @param xpellElement Xpell element to change to
|
|
371
629
|
*/
|
|
372
630
|
static addHtml2XpellMapItem(e, t) {
|
|
373
|
-
|
|
631
|
+
j.html2XMap.elements[e] = t;
|
|
374
632
|
}
|
|
375
633
|
/**
|
|
376
634
|
* convert text command to Xpell json command
|
|
@@ -378,62 +636,62 @@ const X = {
|
|
|
378
636
|
*/
|
|
379
637
|
static parse(e, t) {
|
|
380
638
|
const s = e.split(" ");
|
|
381
|
-
let
|
|
382
|
-
if (t ? (
|
|
383
|
-
for (let
|
|
384
|
-
const i = s[
|
|
639
|
+
let r = new N();
|
|
640
|
+
if (t ? (r._module = t, r._op = s[0]) : (r._module = s[0], r._op = s[1]), r._params = {}, s.length > 1)
|
|
641
|
+
for (let n = 2; n < s.length; ++n) {
|
|
642
|
+
const i = s[n];
|
|
385
643
|
if (i.indexOf(":") > -1) {
|
|
386
|
-
const
|
|
387
|
-
|
|
644
|
+
const a = i.split(":");
|
|
645
|
+
r._params[a[0]] = a[1];
|
|
388
646
|
} else
|
|
389
|
-
|
|
647
|
+
r._params[n - 1] = s[n];
|
|
390
648
|
}
|
|
391
|
-
return
|
|
649
|
+
return r;
|
|
392
650
|
}
|
|
393
651
|
static replaceSpacesInQuotes(e, t = "_%20_") {
|
|
394
|
-
return e.replace(/(['"])(.*?)\1/g, (s,
|
|
395
|
-
const i = String(
|
|
396
|
-
return `${
|
|
652
|
+
return e.replace(/(['"])(.*?)\1/g, (s, r, n) => {
|
|
653
|
+
const i = String(n).replace(/\s/g, t);
|
|
654
|
+
return `${r}${i}${r}`;
|
|
397
655
|
});
|
|
398
656
|
}
|
|
399
657
|
static parseObjectCommand(e, t) {
|
|
400
|
-
e =
|
|
401
|
-
const s = e.trim().split(/\s+/),
|
|
402
|
-
if (!
|
|
403
|
-
let
|
|
404
|
-
if (s[0]?.startsWith("#") && (
|
|
658
|
+
e = j.replaceSpacesInQuotes(e);
|
|
659
|
+
const s = e.trim().split(/\s+/), r = t || s.shift();
|
|
660
|
+
if (!r) throw new Error("Missing module name");
|
|
661
|
+
let n;
|
|
662
|
+
if (s[0]?.startsWith("#") && (n = s.shift().slice(1), !n))
|
|
405
663
|
throw new Error("Invalid object selector '#'. Use '#<id>'");
|
|
406
664
|
const i = s.shift();
|
|
407
665
|
if (!i) throw new Error("Missing operation");
|
|
408
|
-
const
|
|
409
|
-
let
|
|
410
|
-
if (s.forEach((
|
|
411
|
-
if (
|
|
412
|
-
if (
|
|
413
|
-
const
|
|
414
|
-
a
|
|
666
|
+
const c = {};
|
|
667
|
+
let a = null, _ = null;
|
|
668
|
+
if (s.forEach((l) => {
|
|
669
|
+
if (_) {
|
|
670
|
+
if (_ += ` ${l}`, l.endsWith(_[0])) {
|
|
671
|
+
const d = _.slice(1, -1).replace(/_%20_/g, " ");
|
|
672
|
+
c[a] = d, _ = null;
|
|
415
673
|
}
|
|
416
674
|
return;
|
|
417
675
|
}
|
|
418
|
-
if (
|
|
419
|
-
if (
|
|
420
|
-
const
|
|
421
|
-
a
|
|
676
|
+
if (l.startsWith('"') || l.startsWith("'")) {
|
|
677
|
+
if (_ = l, l.endsWith(l[0]) && l.length > 1) {
|
|
678
|
+
const d = l.slice(1, -1).replace(/_%20_/g, " ");
|
|
679
|
+
c[a] = d, _ = null;
|
|
422
680
|
}
|
|
423
681
|
return;
|
|
424
682
|
}
|
|
425
|
-
if (
|
|
426
|
-
const
|
|
427
|
-
|
|
683
|
+
if (l.includes(":")) {
|
|
684
|
+
const d = l.split(":"), y = d[0], g = d.slice(1).join(":").replace(/_%20_/g, " ");
|
|
685
|
+
c[y] = g, a = null;
|
|
428
686
|
return;
|
|
429
687
|
}
|
|
430
|
-
|
|
431
|
-
}),
|
|
688
|
+
a = l.replace(/_%20_/g, " ");
|
|
689
|
+
}), _) throw new Error("Unclosed quoted parameter value");
|
|
432
690
|
return {
|
|
433
|
-
_module:
|
|
434
|
-
_object:
|
|
691
|
+
_module: r,
|
|
692
|
+
_object: n,
|
|
435
693
|
_op: i,
|
|
436
|
-
_params:
|
|
694
|
+
_params: c
|
|
437
695
|
};
|
|
438
696
|
}
|
|
439
697
|
/**
|
|
@@ -443,7 +701,7 @@ const X = {
|
|
|
443
701
|
*/
|
|
444
702
|
static xmlString2Xpell(e) {
|
|
445
703
|
const s = new DOMParser().parseFromString(e, "text/xml");
|
|
446
|
-
return s.childNodes.length > 0 ?
|
|
704
|
+
return s.childNodes.length > 0 ? j.xml2Xpell(s.childNodes[0]) : {};
|
|
447
705
|
}
|
|
448
706
|
/**
|
|
449
707
|
* Converts XML/HTML Document to Xpell JSON
|
|
@@ -452,25 +710,25 @@ const X = {
|
|
|
452
710
|
* @returns {} Xpell JSON
|
|
453
711
|
*/
|
|
454
712
|
static xml2Xpell(e, t) {
|
|
455
|
-
const s =
|
|
456
|
-
let
|
|
457
|
-
|
|
458
|
-
const
|
|
459
|
-
let
|
|
460
|
-
if (t ? (
|
|
461
|
-
for (let
|
|
462
|
-
const
|
|
463
|
-
|
|
713
|
+
const s = j.html2XMap;
|
|
714
|
+
let r = {};
|
|
715
|
+
r._children = [];
|
|
716
|
+
const n = e.nodeName, i = e.nodeName;
|
|
717
|
+
let c = t;
|
|
718
|
+
if (t ? (r[E.type] = "xhtml", r._html_ns = "http://www.w3.org/2000/svg") : r._type = s.elements[n] ? s.elements[n] : n, e.attributes)
|
|
719
|
+
for (let a = 0; a < e.attributes.length; ++a) {
|
|
720
|
+
const _ = e.attributes[a], l = s.attributes[_.name] ? s.attributes[_.name] : _.name;
|
|
721
|
+
r[l] = _.value;
|
|
464
722
|
}
|
|
465
|
-
if (e?.firstChild?.nodeValue && (
|
|
466
|
-
for (let
|
|
467
|
-
const
|
|
468
|
-
|
|
723
|
+
if (e?.firstChild?.nodeValue && (r.text = e?.firstChild.nodeValue.trim()), r[E.type] == "xhtml" ? r._html_tag = i : r[E.type] == "svg" && (c = !0, r._html_ns = "http://www.w3.org/2000/svg"), e?.childNodes.length > 0)
|
|
724
|
+
for (let a = 0; a < e.childNodes.length; ++a) {
|
|
725
|
+
const _ = e.childNodes[a];
|
|
726
|
+
_.nodeName.startsWith("#") || r[E.children].push(j.xml2Xpell(_, c));
|
|
469
727
|
}
|
|
470
|
-
return
|
|
728
|
+
return r;
|
|
471
729
|
}
|
|
472
730
|
};
|
|
473
|
-
|
|
731
|
+
j.html2XMap = {
|
|
474
732
|
elements: {
|
|
475
733
|
div: "view",
|
|
476
734
|
a: "link",
|
|
@@ -500,8 +758,8 @@ b.html2XMap = {
|
|
|
500
758
|
id: "_id"
|
|
501
759
|
}
|
|
502
760
|
};
|
|
503
|
-
let
|
|
504
|
-
class
|
|
761
|
+
let O = j;
|
|
762
|
+
class re {
|
|
505
763
|
#e;
|
|
506
764
|
#t;
|
|
507
765
|
#s;
|
|
@@ -569,7 +827,7 @@ class te {
|
|
|
569
827
|
* @param xObject XObject to maintain
|
|
570
828
|
*/
|
|
571
829
|
addObject(e) {
|
|
572
|
-
e && e._id ? (this.#t[e._id] = e, (!e._name || e._name.length == 0) && (e._name = e._id), this.#s[e._name] = e._id) :
|
|
830
|
+
e && e._id ? (this.#t[e._id] = e, (!e._name || e._name.length == 0) && (e._name = e._id), this.#s[e._name] = e._id) : h.log("unable to add object");
|
|
573
831
|
}
|
|
574
832
|
/**
|
|
575
833
|
* Remove XObject from the manager
|
|
@@ -604,7 +862,7 @@ class te {
|
|
|
604
862
|
return this.#s[e] ? this.getObject(this.#s[e]) : null;
|
|
605
863
|
}
|
|
606
864
|
}
|
|
607
|
-
class
|
|
865
|
+
class pe {
|
|
608
866
|
constructor() {
|
|
609
867
|
this._log_rules = {
|
|
610
868
|
register: !1,
|
|
@@ -619,16 +877,16 @@ class ue {
|
|
|
619
877
|
* - Canonical: on(name, cb, { _once, _owner, _tag })
|
|
620
878
|
* - Legacy: on(name, cb, { _once }, owner)
|
|
621
879
|
*/
|
|
622
|
-
on(e, t, s = {},
|
|
880
|
+
on(e, t, s = {}, r) {
|
|
623
881
|
this._events[e] || (this._events[e] = []);
|
|
624
|
-
const
|
|
882
|
+
const n = s?._owner ?? r, i = u.guid(), c = {
|
|
625
883
|
_id: i,
|
|
626
884
|
_callback: t,
|
|
627
885
|
_options: s,
|
|
628
|
-
_owner:
|
|
886
|
+
_owner: n,
|
|
629
887
|
_tag: s?._tag
|
|
630
888
|
};
|
|
631
|
-
return this._events[e].push(
|
|
889
|
+
return this._events[e].push(c), this._listener_index[i] = e, this._log_rules.register && x.log("XEM Register", e, i), i;
|
|
632
890
|
}
|
|
633
891
|
/**
|
|
634
892
|
* Register a listener that will be removed after first fire.
|
|
@@ -642,17 +900,17 @@ class ue {
|
|
|
642
900
|
async fire(e, t) {
|
|
643
901
|
const s = this._events[e];
|
|
644
902
|
if (!s || s.length === 0) return;
|
|
645
|
-
this._log_rules.fire &&
|
|
646
|
-
const
|
|
647
|
-
for (const i of
|
|
903
|
+
this._log_rules.fire && x.log("XEM Fire", e, t);
|
|
904
|
+
const r = s.slice(), n = [];
|
|
905
|
+
for (const i of r) {
|
|
648
906
|
try {
|
|
649
907
|
i && i._callback && i._callback(t);
|
|
650
|
-
} catch (
|
|
651
|
-
|
|
908
|
+
} catch (c) {
|
|
909
|
+
x.error(c);
|
|
652
910
|
}
|
|
653
|
-
i?._options?._once &&
|
|
911
|
+
i?._options?._once && n.push(i._id);
|
|
654
912
|
}
|
|
655
|
-
for (const i of
|
|
913
|
+
for (const i of n) this.remove(i);
|
|
656
914
|
}
|
|
657
915
|
/**
|
|
658
916
|
* Remove a listener by id.
|
|
@@ -662,10 +920,10 @@ class ue {
|
|
|
662
920
|
if (!t) return;
|
|
663
921
|
const s = this._events[t];
|
|
664
922
|
if (s && s.length) {
|
|
665
|
-
const
|
|
666
|
-
|
|
923
|
+
const r = s.findIndex((n) => n?._id === e);
|
|
924
|
+
r >= 0 && s.splice(r, 1), s.length === 0 && delete this._events[t];
|
|
667
925
|
}
|
|
668
|
-
delete this._listener_index[e], this._log_rules.remove &&
|
|
926
|
+
delete this._listener_index[e], this._log_rules.remove && x.log("XEM Remove", t, e);
|
|
669
927
|
}
|
|
670
928
|
/**
|
|
671
929
|
* Remove all listeners for a given owner reference.
|
|
@@ -674,8 +932,8 @@ class ue {
|
|
|
674
932
|
if (!e) return;
|
|
675
933
|
const t = [];
|
|
676
934
|
for (const s of Object.values(this._events))
|
|
677
|
-
for (const
|
|
678
|
-
(
|
|
935
|
+
for (const r of s)
|
|
936
|
+
(r?._owner ?? r?._options?._owner) === e && t.push(r._id);
|
|
679
937
|
t.forEach((s) => this.remove(s));
|
|
680
938
|
}
|
|
681
939
|
/**
|
|
@@ -685,16 +943,16 @@ class ue {
|
|
|
685
943
|
this._events = {}, this._listener_index = {};
|
|
686
944
|
}
|
|
687
945
|
}
|
|
688
|
-
let
|
|
689
|
-
function
|
|
690
|
-
|
|
946
|
+
let R;
|
|
947
|
+
function fe(o) {
|
|
948
|
+
R = o;
|
|
691
949
|
}
|
|
692
|
-
function
|
|
693
|
-
if (!
|
|
950
|
+
function X() {
|
|
951
|
+
if (!R)
|
|
694
952
|
throw new Error("XEventManager not set");
|
|
695
|
-
return
|
|
953
|
+
return R;
|
|
696
954
|
}
|
|
697
|
-
const
|
|
955
|
+
const ne = [
|
|
698
956
|
"_nano_commands",
|
|
699
957
|
"_cache_cmd_txt",
|
|
700
958
|
"_cache_jcmd",
|
|
@@ -703,21 +961,21 @@ const se = [
|
|
|
703
961
|
"_parent",
|
|
704
962
|
"_children"
|
|
705
963
|
];
|
|
706
|
-
function
|
|
707
|
-
return
|
|
964
|
+
function $(o) {
|
|
965
|
+
return ne.includes(o);
|
|
708
966
|
}
|
|
709
|
-
function
|
|
967
|
+
function K(o) {
|
|
710
968
|
if (!o || typeof o != "object" || Array.isArray(o)) return !1;
|
|
711
969
|
const e = Object.getPrototypeOf(o);
|
|
712
970
|
return e === Object.prototype || e === null;
|
|
713
971
|
}
|
|
714
|
-
function
|
|
972
|
+
function b(o, e) {
|
|
715
973
|
return o._skill = e, o.getSkill = () => e, o;
|
|
716
974
|
}
|
|
717
|
-
const
|
|
718
|
-
info:
|
|
975
|
+
const G = {
|
|
976
|
+
info: b(
|
|
719
977
|
(o, e) => {
|
|
720
|
-
|
|
978
|
+
h.log("XObject id " + e?._id);
|
|
721
979
|
},
|
|
722
980
|
{
|
|
723
981
|
_name: "info",
|
|
@@ -725,9 +983,9 @@ const V = {
|
|
|
725
983
|
_description: "Logs the current object's id."
|
|
726
984
|
}
|
|
727
985
|
),
|
|
728
|
-
log:
|
|
986
|
+
log: b(
|
|
729
987
|
(o, e) => {
|
|
730
|
-
o._params && o._params[1] ?
|
|
988
|
+
o._params && o._params[1] ? h.log(o._params[1]) : h.log(e);
|
|
731
989
|
},
|
|
732
990
|
{
|
|
733
991
|
_name: "log",
|
|
@@ -738,12 +996,12 @@ const V = {
|
|
|
738
996
|
}
|
|
739
997
|
}
|
|
740
998
|
),
|
|
741
|
-
fire:
|
|
999
|
+
fire: b(
|
|
742
1000
|
(o, e) => {
|
|
743
|
-
o._params && o._params[1] ?
|
|
1001
|
+
o._params && o._params[1] ? X().fire(
|
|
744
1002
|
String(o._params[1]),
|
|
745
1003
|
o._params[2]
|
|
746
|
-
) : o._params && o._params.event &&
|
|
1004
|
+
) : o._params && o._params.event && X().fire(
|
|
747
1005
|
String(o._params.event),
|
|
748
1006
|
o._params.data
|
|
749
1007
|
);
|
|
@@ -769,7 +1027,7 @@ const V = {
|
|
|
769
1027
|
}
|
|
770
1028
|
}
|
|
771
1029
|
),
|
|
772
|
-
noop:
|
|
1030
|
+
noop: b(
|
|
773
1031
|
() => {
|
|
774
1032
|
},
|
|
775
1033
|
{
|
|
@@ -778,12 +1036,12 @@ const V = {
|
|
|
778
1036
|
_description: "No-op command. Useful as a placeholder in sequences."
|
|
779
1037
|
}
|
|
780
1038
|
),
|
|
781
|
-
"set-field":
|
|
1039
|
+
"set-field": b(
|
|
782
1040
|
(o, e) => {
|
|
783
1041
|
const t = o._params?.name, s = o._params?.value;
|
|
784
1042
|
if (!(!e || typeof t != "string" || t.length === 0)) {
|
|
785
|
-
if (
|
|
786
|
-
|
|
1043
|
+
if ($(t)) {
|
|
1044
|
+
h.error(`set-field denied for protected field: ${t}`);
|
|
787
1045
|
return;
|
|
788
1046
|
}
|
|
789
1047
|
e[t] = s;
|
|
@@ -806,12 +1064,12 @@ const V = {
|
|
|
806
1064
|
}
|
|
807
1065
|
}
|
|
808
1066
|
),
|
|
809
|
-
"delete-field":
|
|
1067
|
+
"delete-field": b(
|
|
810
1068
|
(o, e) => {
|
|
811
1069
|
const t = o._params?.name;
|
|
812
1070
|
if (!(!e || typeof t != "string" || t.length === 0)) {
|
|
813
|
-
if (
|
|
814
|
-
|
|
1071
|
+
if ($(t)) {
|
|
1072
|
+
h.error(`delete-field denied for protected field: ${t}`);
|
|
815
1073
|
return;
|
|
816
1074
|
}
|
|
817
1075
|
delete e[t];
|
|
@@ -826,12 +1084,12 @@ const V = {
|
|
|
826
1084
|
}
|
|
827
1085
|
}
|
|
828
1086
|
),
|
|
829
|
-
"toggle-field":
|
|
1087
|
+
"toggle-field": b(
|
|
830
1088
|
(o, e) => {
|
|
831
1089
|
const t = o._params?.name;
|
|
832
1090
|
if (!e || typeof t != "string" || t.length === 0) return;
|
|
833
|
-
if (
|
|
834
|
-
|
|
1091
|
+
if ($(t)) {
|
|
1092
|
+
h.error(`toggle-field denied for protected field: ${t}`);
|
|
835
1093
|
return;
|
|
836
1094
|
}
|
|
837
1095
|
const s = e[t];
|
|
@@ -846,20 +1104,20 @@ const V = {
|
|
|
846
1104
|
}
|
|
847
1105
|
}
|
|
848
1106
|
),
|
|
849
|
-
merge:
|
|
1107
|
+
merge: b(
|
|
850
1108
|
(o, e) => {
|
|
851
1109
|
const t = o._params?.name, s = o._params?.value;
|
|
852
1110
|
if (!e || typeof t != "string" || t.length === 0) return;
|
|
853
|
-
if (
|
|
854
|
-
|
|
1111
|
+
if ($(t)) {
|
|
1112
|
+
h.error(`merge denied for protected field: ${t}`);
|
|
855
1113
|
return;
|
|
856
1114
|
}
|
|
857
|
-
if (!
|
|
858
|
-
|
|
1115
|
+
if (!K(s)) {
|
|
1116
|
+
h.error("merge expects _params.value as a plain object");
|
|
859
1117
|
return;
|
|
860
1118
|
}
|
|
861
|
-
const
|
|
862
|
-
|
|
1119
|
+
const r = e[t];
|
|
1120
|
+
K(r) || (e[t] = {}), Object.assign(e[t], s);
|
|
863
1121
|
},
|
|
864
1122
|
{
|
|
865
1123
|
_name: "merge",
|
|
@@ -871,12 +1129,12 @@ const V = {
|
|
|
871
1129
|
}
|
|
872
1130
|
}
|
|
873
1131
|
),
|
|
874
|
-
"run-seq":
|
|
1132
|
+
"run-seq": b(
|
|
875
1133
|
async (o, e) => {
|
|
876
1134
|
if (!e) return;
|
|
877
1135
|
const t = o._params?.seq;
|
|
878
1136
|
if (!Array.isArray(t)) {
|
|
879
|
-
|
|
1137
|
+
h.error("run-seq expects _params.seq as an array");
|
|
880
1138
|
return;
|
|
881
1139
|
}
|
|
882
1140
|
for (const s of t) {
|
|
@@ -885,9 +1143,9 @@ const V = {
|
|
|
885
1143
|
continue;
|
|
886
1144
|
}
|
|
887
1145
|
if (s && typeof s == "object" && s._op) {
|
|
888
|
-
const
|
|
889
|
-
if (!(
|
|
890
|
-
|
|
1146
|
+
const r = s._object;
|
|
1147
|
+
if (!(r == null || r === "this" || r === e._id)) {
|
|
1148
|
+
h.error("run-seq rejected non-self _object target");
|
|
891
1149
|
return;
|
|
892
1150
|
}
|
|
893
1151
|
const i = {
|
|
@@ -897,7 +1155,7 @@ const V = {
|
|
|
897
1155
|
await e.execute(i);
|
|
898
1156
|
continue;
|
|
899
1157
|
}
|
|
900
|
-
|
|
1158
|
+
h.error(
|
|
901
1159
|
"run-seq skipped invalid step; expected string or object with _op"
|
|
902
1160
|
);
|
|
903
1161
|
}
|
|
@@ -932,16 +1190,16 @@ const V = {
|
|
|
932
1190
|
}
|
|
933
1191
|
)
|
|
934
1192
|
};
|
|
935
|
-
let
|
|
936
|
-
function
|
|
937
|
-
|
|
1193
|
+
let L;
|
|
1194
|
+
function ie(o) {
|
|
1195
|
+
L = o;
|
|
938
1196
|
}
|
|
939
|
-
function
|
|
940
|
-
if (
|
|
1197
|
+
function oe() {
|
|
1198
|
+
if (!L)
|
|
941
1199
|
throw new Error("XRuntime not set");
|
|
942
|
-
return
|
|
1200
|
+
return L;
|
|
943
1201
|
}
|
|
944
|
-
const
|
|
1202
|
+
const U = {
|
|
945
1203
|
_id: "xobject",
|
|
946
1204
|
_title: "XObject Core Runtime Contract",
|
|
947
1205
|
_version: "1.0.0",
|
|
@@ -993,7 +1251,7 @@ const R = {
|
|
|
993
1251
|
"Runtime methods include parse, append, run, execute, bindDataSource, unbindDataSource, toXData, dispose, and removeChild.",
|
|
994
1252
|
"Most prompts should use this skill as a compact dependency summary, not full context."
|
|
995
1253
|
]
|
|
996
|
-
},
|
|
1254
|
+
}, P = { _children: "child nodes" }, A = class A {
|
|
997
1255
|
/**
|
|
998
1256
|
* XObject constructor is creating the object and adding all the data keys to the XObject instance
|
|
999
1257
|
* @param data constructor input data (object)
|
|
@@ -1022,14 +1280,14 @@ const R = {
|
|
|
1022
1280
|
"_debug"
|
|
1023
1281
|
],
|
|
1024
1282
|
_instance_xporters: {}
|
|
1025
|
-
}, t &&
|
|
1283
|
+
}, t && u.mergeDefaultsWithData(e, t), this._id = e && e._id ? e._id : "xo-" + u.guid(), this._type = "object", this._children = [], this._nano_commands = {}, this.addNanoCommandPack(G), e && e.hasOwnProperty("_nano_commands") && e._nano_commands && (this.addNanoCommandPack(e._nano_commands), delete e._nano_commands), this.addXporterDataIgnoreFields(["_nano_commands"]), this.addXporterInstanceXporter(A, (r) => r.toXData()), this._xem_options = {
|
|
1026
1284
|
// _instance:_xem
|
|
1027
1285
|
// _object: this
|
|
1028
1286
|
// _support_html: true
|
|
1029
|
-
}, !s && e && this.parse(e,
|
|
1287
|
+
}, !s && e && this.parse(e, P);
|
|
1030
1288
|
}
|
|
1031
1289
|
static getOwnSkill() {
|
|
1032
|
-
const e = this, t = e._skill ??
|
|
1290
|
+
const e = this, t = e._skill ?? U;
|
|
1033
1291
|
return {
|
|
1034
1292
|
...t,
|
|
1035
1293
|
_exports: {
|
|
@@ -1044,7 +1302,7 @@ const R = {
|
|
|
1044
1302
|
}
|
|
1045
1303
|
static getOwnNanoCommands() {
|
|
1046
1304
|
return {
|
|
1047
|
-
...
|
|
1305
|
+
...G
|
|
1048
1306
|
};
|
|
1049
1307
|
}
|
|
1050
1308
|
static getNanoCommands() {
|
|
@@ -1060,8 +1318,32 @@ const R = {
|
|
|
1060
1318
|
(t) => t.getSkill?.() ?? t._skill
|
|
1061
1319
|
).filter(Boolean) : [];
|
|
1062
1320
|
}
|
|
1321
|
+
static getArtifactStrategy() {
|
|
1322
|
+
return "canonical";
|
|
1323
|
+
}
|
|
1324
|
+
static generateArtifact(e = {}) {
|
|
1325
|
+
const t = this.getOwnSkill?.(), s = t?._canonical_examples?.[0], r = s ? this.cloneArtifact(s) : { _type: this._xtype ?? t?._id ?? "object" };
|
|
1326
|
+
return this.applyArtifactIntent(r, e);
|
|
1327
|
+
}
|
|
1328
|
+
static cloneArtifact(e) {
|
|
1329
|
+
return typeof structuredClone == "function" ? structuredClone(e) : JSON.parse(JSON.stringify(e));
|
|
1330
|
+
}
|
|
1331
|
+
static applyArtifactIntent(e, t = {}) {
|
|
1332
|
+
const s = e;
|
|
1333
|
+
return t._id && (s._id = t._id), t._label && ("_label" in s ? s._label = t._label : "_text" in s ? s._text = t._label : "_title" in s && (s._title = t._label)), t._text && "_text" in s && (s._text = t._text), t._title && "_title" in s && (s._title = t._title), t._description && "_description" in s && (s._description = t._description), t._variant && "_variant" in s && (s._variant = t._variant), t._tone && "_tone" in s && (s._tone = t._tone), t._size && "_size" in s && (s._size = t._size), t._density && "_density" in s && (s._density = t._density), t._elevation && "_elevation" in s && (s._elevation = t._elevation), t.class && (s.class = t.class), t._placeholder && ("placeholder" in s ? s.placeholder = t._placeholder : "_placeholder" in s && (s._placeholder = t._placeholder)), t._data_output && "_data_output" in s && (s._data_output = t._data_output), Array.isArray(t._children) && (s._children = t._children), Array.isArray(t._actions) && (s._actions = t._actions), Array.isArray(t._items) && (s._items = t._items), t._flow_id && (s._flow = {
|
|
1334
|
+
_id: t._flow_id,
|
|
1335
|
+
_payload: t._payload ?? {}
|
|
1336
|
+
}), t._flow_event && (s._flow_event = t._flow_event), s;
|
|
1337
|
+
}
|
|
1338
|
+
static validateArtifact(e) {
|
|
1339
|
+
const t = [];
|
|
1340
|
+
return (!e || typeof e != "object") && t.push("artifact must be an object"), e._type || t.push("artifact requires _type"), {
|
|
1341
|
+
_ok: t.length === 0,
|
|
1342
|
+
_errors: t
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1063
1345
|
log(e, ...t) {
|
|
1064
|
-
this._debug && e &&
|
|
1346
|
+
this._debug && e && h.log(this._type + "->" + this._id + "]", e, ...t);
|
|
1065
1347
|
}
|
|
1066
1348
|
/**
|
|
1067
1349
|
* Initialize the XObject
|
|
@@ -1070,7 +1352,7 @@ const R = {
|
|
|
1070
1352
|
* @deprecated - use parse method instead
|
|
1071
1353
|
*/
|
|
1072
1354
|
init(e, t) {
|
|
1073
|
-
!t && e && this.parse(e,
|
|
1355
|
+
!t && e && this.parse(e, P);
|
|
1074
1356
|
}
|
|
1075
1357
|
parseEvents(e) {
|
|
1076
1358
|
if (!this._event_parsed) {
|
|
@@ -1085,19 +1367,36 @@ const R = {
|
|
|
1085
1367
|
}
|
|
1086
1368
|
addEventListener(e, t, s) {
|
|
1087
1369
|
s || (s = this._xem_options);
|
|
1088
|
-
const
|
|
1370
|
+
const r = async (i) => {
|
|
1089
1371
|
await this.checkAndRunInternalFunction(t, i);
|
|
1090
|
-
},
|
|
1091
|
-
return this._event_listeners_ids[e] || (this._event_listeners_ids[e] = []), this._event_listeners_ids[e].push(
|
|
1372
|
+
}, n = X().on(e, r, s, this);
|
|
1373
|
+
return this._event_listeners_ids[e] || (this._event_listeners_ids[e] = []), this._event_listeners_ids[e].push(n), n;
|
|
1092
1374
|
}
|
|
1093
1375
|
removeEventListener(e) {
|
|
1094
|
-
const t = this._event_listeners_ids
|
|
1095
|
-
t
|
|
1096
|
-
|
|
1097
|
-
|
|
1376
|
+
const t = this._event_listeners_ids;
|
|
1377
|
+
if (!t || typeof t != "object" || Array.isArray(t)) {
|
|
1378
|
+
this._event_listeners_ids = {};
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1381
|
+
(Array.isArray(t[e]) ? [...t[e]] : []).forEach((r) => {
|
|
1382
|
+
try {
|
|
1383
|
+
X().remove(r);
|
|
1384
|
+
} catch {
|
|
1385
|
+
}
|
|
1386
|
+
}), delete t[e];
|
|
1098
1387
|
}
|
|
1099
|
-
removeAllEventListeners() {
|
|
1100
|
-
|
|
1388
|
+
removeAllEventListeners(e) {
|
|
1389
|
+
const t = this._event_listeners_ids;
|
|
1390
|
+
if (!t || typeof t != "object" || Array.isArray(t)) {
|
|
1391
|
+
this._event_listeners_ids = {};
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
(e ? [e] : Object.keys(t)).forEach((r) => {
|
|
1395
|
+
try {
|
|
1396
|
+
this.removeEventListener(r);
|
|
1397
|
+
} catch {
|
|
1398
|
+
}
|
|
1399
|
+
});
|
|
1101
1400
|
}
|
|
1102
1401
|
/**
|
|
1103
1402
|
* Append a child XObject to this XObject
|
|
@@ -1131,7 +1430,7 @@ const R = {
|
|
|
1131
1430
|
* @param <XDataInstanceXporter> ie - the instance exporter object
|
|
1132
1431
|
*/
|
|
1133
1432
|
addXporterInstanceXporter(e, t) {
|
|
1134
|
-
const s =
|
|
1433
|
+
const s = u.guid();
|
|
1135
1434
|
this._xporter._instance_xporters[s] = {
|
|
1136
1435
|
cls: e,
|
|
1137
1436
|
handler: t
|
|
@@ -1142,9 +1441,9 @@ const R = {
|
|
|
1142
1441
|
* @param data data to parse
|
|
1143
1442
|
* @param ignore - lis of words to ignore in the parse process
|
|
1144
1443
|
*/
|
|
1145
|
-
parse(e, t =
|
|
1146
|
-
Object.keys(e).forEach((
|
|
1147
|
-
!t.hasOwnProperty(
|
|
1444
|
+
parse(e, t = P) {
|
|
1445
|
+
Object.keys(e).forEach((r) => {
|
|
1446
|
+
!t.hasOwnProperty(r) && e.hasOwnProperty(r) && (this[r] = e[r]);
|
|
1148
1447
|
});
|
|
1149
1448
|
}
|
|
1150
1449
|
/**
|
|
@@ -1158,8 +1457,8 @@ const R = {
|
|
|
1158
1457
|
* }
|
|
1159
1458
|
*/
|
|
1160
1459
|
parseFieldsFromXDataObject(e, t) {
|
|
1161
|
-
Object.keys(t).forEach((
|
|
1162
|
-
e.hasOwnProperty(
|
|
1460
|
+
Object.keys(t).forEach((r) => {
|
|
1461
|
+
e.hasOwnProperty(r) ? this[r] = e[r] : this[r] = t[r];
|
|
1163
1462
|
});
|
|
1164
1463
|
}
|
|
1165
1464
|
/**
|
|
@@ -1169,12 +1468,12 @@ const R = {
|
|
|
1169
1468
|
* @param checkNonXParams - also check non Xpell fields (fields that not starting with "_" sign)
|
|
1170
1469
|
*/
|
|
1171
1470
|
parseFields(e, t, s) {
|
|
1172
|
-
t.forEach((
|
|
1173
|
-
if (e.hasOwnProperty(
|
|
1174
|
-
this[
|
|
1175
|
-
else if (s &&
|
|
1176
|
-
const
|
|
1177
|
-
e.hasOwnProperty(
|
|
1471
|
+
t.forEach((r) => {
|
|
1472
|
+
if (e.hasOwnProperty(r))
|
|
1473
|
+
this[r] = e[r];
|
|
1474
|
+
else if (s && r.startsWith("_")) {
|
|
1475
|
+
const n = r.substring(1);
|
|
1476
|
+
e.hasOwnProperty(n) && (this[r] = e[n], this[n] = e[n]);
|
|
1178
1477
|
}
|
|
1179
1478
|
});
|
|
1180
1479
|
}
|
|
@@ -1192,137 +1491,168 @@ const R = {
|
|
|
1192
1491
|
this._on_create ? this.checkAndRunInternalFunction(this._on_create) : this._on && this._on.create ? this.checkAndRunInternalFunction(this._on.create) : this._once && this._once.create && this.checkAndRunInternalFunction(this._once.create);
|
|
1193
1492
|
}
|
|
1194
1493
|
async runCmd(e) {
|
|
1195
|
-
const t = e instanceof
|
|
1494
|
+
const t = e instanceof N ? e : new N(e);
|
|
1196
1495
|
await this.execute(t);
|
|
1197
1496
|
}
|
|
1198
1497
|
async checkAndRunInternalFunction(e, ...t) {
|
|
1199
|
-
const s = (
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1498
|
+
const s = (i, c) => {
|
|
1499
|
+
const a = c.split(".");
|
|
1500
|
+
let _ = i;
|
|
1501
|
+
for (const l of a) {
|
|
1502
|
+
if (_ == null) return;
|
|
1503
|
+
_ = _[l];
|
|
1504
|
+
}
|
|
1505
|
+
return _;
|
|
1506
|
+
}, r = (i, c, a) => {
|
|
1507
|
+
if (typeof i == "string") {
|
|
1508
|
+
if (i === "$prev") return c;
|
|
1509
|
+
if (i.startsWith("$prev."))
|
|
1510
|
+
return s(
|
|
1511
|
+
c,
|
|
1512
|
+
i.slice(6)
|
|
1513
|
+
);
|
|
1514
|
+
if (i === "$event") return t[0];
|
|
1515
|
+
if (i.startsWith("$event."))
|
|
1516
|
+
return s(
|
|
1517
|
+
t[0],
|
|
1518
|
+
i.slice(7)
|
|
1519
|
+
);
|
|
1520
|
+
if (i === "$data") return t[0];
|
|
1521
|
+
if (i.startsWith("$data."))
|
|
1522
|
+
return s(
|
|
1523
|
+
t[0],
|
|
1524
|
+
i.slice(6)
|
|
1525
|
+
);
|
|
1526
|
+
if (i.startsWith("$xdata:") || i.startsWith("$xdata.")) {
|
|
1527
|
+
const l = (i.startsWith("$xdata:"), i.slice(7)).split(".");
|
|
1528
|
+
for (let d = l.length; d > 0; d--) {
|
|
1529
|
+
const y = l.slice(0, d).join(".");
|
|
1530
|
+
if (v.has(y)) {
|
|
1531
|
+
const g = v.get(y), w = l.slice(d).join(".");
|
|
1532
|
+
return w ? u.get_path(g, w) : g;
|
|
1533
|
+
}
|
|
1208
1534
|
}
|
|
1209
|
-
return
|
|
1535
|
+
return;
|
|
1210
1536
|
}
|
|
1211
|
-
if (
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1537
|
+
if (i.startsWith("$") && a && typeof a == "object") {
|
|
1538
|
+
const _ = i.slice(1), l = _.indexOf("."), d = l === -1 ? _ : _.slice(0, l), y = l === -1 ? "" : _.slice(l + 1);
|
|
1539
|
+
if (Object.prototype.hasOwnProperty.call(
|
|
1540
|
+
a,
|
|
1541
|
+
d
|
|
1542
|
+
)) {
|
|
1543
|
+
const g = a[d];
|
|
1544
|
+
return y ? s(g, y) : g;
|
|
1218
1545
|
}
|
|
1219
|
-
return a;
|
|
1220
1546
|
}
|
|
1221
|
-
return r;
|
|
1222
|
-
}
|
|
1223
|
-
if (Array.isArray(r))
|
|
1224
|
-
return r.map(s);
|
|
1225
|
-
if (r && typeof r == "object") {
|
|
1226
|
-
const i = {};
|
|
1227
|
-
for (const a of Object.keys(r))
|
|
1228
|
-
i[a] = s(r[a]);
|
|
1229
1547
|
return i;
|
|
1230
1548
|
}
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
}), await this.checkAndRunInternalFunction(
|
|
1239
|
-
r,
|
|
1240
|
-
...t
|
|
1241
|
-
));
|
|
1242
|
-
if (Array.isArray(e)) {
|
|
1243
|
-
let r;
|
|
1244
|
-
for (const i of e)
|
|
1245
|
-
r = await n(
|
|
1246
|
-
i,
|
|
1247
|
-
r
|
|
1549
|
+
if (Array.isArray(i))
|
|
1550
|
+
return i.map(
|
|
1551
|
+
(_) => r(
|
|
1552
|
+
_,
|
|
1553
|
+
c,
|
|
1554
|
+
a
|
|
1555
|
+
)
|
|
1248
1556
|
);
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
r._params = r._params || {};
|
|
1259
|
-
const i = t[0];
|
|
1260
|
-
r._params._event = i, !r._params.data && !i?.target && (r._params.data = i);
|
|
1557
|
+
if (i && typeof i == "object") {
|
|
1558
|
+
const _ = {};
|
|
1559
|
+
for (const l of Object.keys(i))
|
|
1560
|
+
_[l] = r(
|
|
1561
|
+
i[l],
|
|
1562
|
+
c,
|
|
1563
|
+
a
|
|
1564
|
+
);
|
|
1565
|
+
return _;
|
|
1261
1566
|
}
|
|
1262
|
-
return
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1567
|
+
return i;
|
|
1568
|
+
}, n = async (i, c) => {
|
|
1569
|
+
if (Array.isArray(i)) {
|
|
1570
|
+
let a;
|
|
1571
|
+
for (const _ of i)
|
|
1572
|
+
a = await n(_, a);
|
|
1573
|
+
return a;
|
|
1574
|
+
}
|
|
1575
|
+
if (typeof i == "function")
|
|
1576
|
+
return await i(this, ...t);
|
|
1577
|
+
if (typeof i == "string") {
|
|
1578
|
+
const a = O.parseObjectCommand(
|
|
1579
|
+
`${this._id} ${i}`
|
|
1273
1580
|
);
|
|
1274
|
-
if (
|
|
1275
|
-
|
|
1276
|
-
|
|
1581
|
+
if (t.length > 0) {
|
|
1582
|
+
a._params = a._params || {};
|
|
1583
|
+
const _ = t[0];
|
|
1584
|
+
a._params._event = _, !a._params.data && !_?.target && (a._params.data = _);
|
|
1585
|
+
}
|
|
1586
|
+
return await this.execute(a);
|
|
1277
1587
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1588
|
+
if (i && typeof i == "object" && Array.isArray(i._commands)) {
|
|
1589
|
+
const a = i, _ = typeof a._mode == "string" ? a._mode : "sequence", l = a._stop_on_error !== !1, d = a._commands;
|
|
1590
|
+
if (_ === "parallel") {
|
|
1591
|
+
const g = await Promise.allSettled(
|
|
1592
|
+
d.map(
|
|
1593
|
+
(M) => n(M, c)
|
|
1594
|
+
)
|
|
1595
|
+
), w = g.find(
|
|
1596
|
+
(M) => M.status === "rejected"
|
|
1284
1597
|
);
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
m
|
|
1289
|
-
), a)
|
|
1290
|
-
throw m;
|
|
1598
|
+
if (w && l)
|
|
1599
|
+
throw w.reason;
|
|
1600
|
+
return g;
|
|
1291
1601
|
}
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1602
|
+
let y = c;
|
|
1603
|
+
for (const g of d)
|
|
1604
|
+
try {
|
|
1605
|
+
y = await n(
|
|
1606
|
+
g,
|
|
1607
|
+
_ === "chain" ? y : c
|
|
1608
|
+
);
|
|
1609
|
+
} catch (w) {
|
|
1610
|
+
if (h.error(
|
|
1611
|
+
this._type + "->" + this._id + "] command sequence failed",
|
|
1612
|
+
w
|
|
1613
|
+
), l)
|
|
1614
|
+
throw w;
|
|
1615
|
+
}
|
|
1616
|
+
return y;
|
|
1301
1617
|
}
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
a._params
|
|
1313
|
-
|
|
1314
|
-
|
|
1618
|
+
if (i && typeof i == "object" && i._op) {
|
|
1619
|
+
const a = i;
|
|
1620
|
+
if ((a._object === void 0 || a._object === null || a._object === "this" ? this._id : a._object) !== this._id) {
|
|
1621
|
+
h.error(
|
|
1622
|
+
"XObject JSON handler target not supported; expected _object omitted/'this'/" + this._id
|
|
1623
|
+
);
|
|
1624
|
+
return;
|
|
1625
|
+
}
|
|
1626
|
+
const l = {
|
|
1627
|
+
...a,
|
|
1628
|
+
_params: a._params ? { ...a._params } : {}
|
|
1629
|
+
};
|
|
1630
|
+
if (t.length > 0) {
|
|
1631
|
+
const d = t[0];
|
|
1632
|
+
Object.prototype.hasOwnProperty.call(
|
|
1633
|
+
l._params,
|
|
1634
|
+
"data"
|
|
1635
|
+
) || (l._params.data = d), Object.prototype.hasOwnProperty.call(
|
|
1636
|
+
l._params,
|
|
1637
|
+
"_event"
|
|
1638
|
+
) || (l._params._event = d);
|
|
1639
|
+
}
|
|
1640
|
+
return l._params = r(
|
|
1641
|
+
l._params,
|
|
1642
|
+
c,
|
|
1643
|
+
this._context
|
|
1644
|
+
), this._debug && h.log(
|
|
1645
|
+
this._type + "->" + this._id + "]",
|
|
1646
|
+
"JSON handler executed locally",
|
|
1647
|
+
l
|
|
1648
|
+
), await this.execute(l);
|
|
1315
1649
|
}
|
|
1316
|
-
|
|
1317
|
-
this._type + "->" + this._id + "]",
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
c.error(
|
|
1323
|
-
this._type + "->" + this._id + "] invalid handler in checkAndRunInternalFunction",
|
|
1324
|
-
e
|
|
1325
|
-
);
|
|
1650
|
+
h.error(
|
|
1651
|
+
this._type + "->" + this._id + "] invalid handler in checkAndRunInternalFunction",
|
|
1652
|
+
i
|
|
1653
|
+
);
|
|
1654
|
+
};
|
|
1655
|
+
return await n(e);
|
|
1326
1656
|
}
|
|
1327
1657
|
/**
|
|
1328
1658
|
* Triggers when the object is being mounted to other element
|
|
@@ -1344,7 +1674,7 @@ const R = {
|
|
|
1344
1674
|
const e = this._data_source;
|
|
1345
1675
|
if (typeof e != "string" || e.length === 0) return;
|
|
1346
1676
|
const t = this._type ?? this.constructor.name, s = this._id ?? "no-id";
|
|
1347
|
-
|
|
1677
|
+
v.delete(e, { source: `${t}#${s}.emptyDataSource` });
|
|
1348
1678
|
}
|
|
1349
1679
|
/**
|
|
1350
1680
|
* Triggers when new data is being received from the data source
|
|
@@ -1385,7 +1715,7 @@ const R = {
|
|
|
1385
1715
|
* @param cache - cache last command to prevent multiple parsing on the same command
|
|
1386
1716
|
*/
|
|
1387
1717
|
async run(e, t = !0) {
|
|
1388
|
-
let s = this._cache_cmd_txt && this._cache_cmd_txt == e ? this._cache_jcmd :
|
|
1718
|
+
let s = this._cache_cmd_txt && this._cache_cmd_txt == e ? this._cache_jcmd : O.parseObjectCommand(e);
|
|
1389
1719
|
t && (this._cache_cmd_txt = e, this._cache_jcmd = s), await this.execute(s);
|
|
1390
1720
|
}
|
|
1391
1721
|
/**
|
|
@@ -1400,37 +1730,42 @@ const R = {
|
|
|
1400
1730
|
*
|
|
1401
1731
|
*/
|
|
1402
1732
|
async execute(e) {
|
|
1403
|
-
const t = e?._op;
|
|
1404
|
-
if (!
|
|
1405
|
-
|
|
1733
|
+
const t = e?._op, s = typeof t == "string" && t.startsWith("_") && t.length > 1 ? t.slice(1) : t;
|
|
1734
|
+
if (!s) {
|
|
1735
|
+
h.error(this._id + " missing _op in command");
|
|
1406
1736
|
return;
|
|
1407
1737
|
}
|
|
1408
|
-
const
|
|
1409
|
-
if (
|
|
1738
|
+
const r = e?._module;
|
|
1739
|
+
if (r)
|
|
1410
1740
|
try {
|
|
1411
|
-
return await
|
|
1741
|
+
return await oe().execute({
|
|
1412
1742
|
...e,
|
|
1413
|
-
_module:
|
|
1743
|
+
_module: r,
|
|
1744
|
+
_op: s
|
|
1414
1745
|
});
|
|
1415
1746
|
} catch (n) {
|
|
1416
|
-
|
|
1417
|
-
this._id + " module execution failed: " +
|
|
1747
|
+
h.error(
|
|
1748
|
+
this._id + " module execution failed: " + r + "." + s + " " + n
|
|
1418
1749
|
);
|
|
1419
1750
|
return;
|
|
1420
1751
|
}
|
|
1421
|
-
if (this._nano_commands[
|
|
1752
|
+
if (this._nano_commands[s])
|
|
1422
1753
|
try {
|
|
1423
|
-
|
|
1424
|
-
e,
|
|
1754
|
+
const n = {
|
|
1755
|
+
...e,
|
|
1756
|
+
_op: s
|
|
1757
|
+
};
|
|
1758
|
+
return await this._nano_commands[s](
|
|
1759
|
+
n,
|
|
1425
1760
|
this
|
|
1426
1761
|
);
|
|
1427
1762
|
} catch (n) {
|
|
1428
|
-
|
|
1429
|
-
this._id + " has error with command name " +
|
|
1763
|
+
h.error(
|
|
1764
|
+
this._id + " has error with command name " + s + " " + n
|
|
1430
1765
|
);
|
|
1431
1766
|
return;
|
|
1432
1767
|
}
|
|
1433
|
-
|
|
1768
|
+
h.error(this._id + " has no command name " + s);
|
|
1434
1769
|
}
|
|
1435
1770
|
/**
|
|
1436
1771
|
* Return an IXObjectData JSON representation of the XObject
|
|
@@ -1444,11 +1779,11 @@ const R = {
|
|
|
1444
1779
|
if (typeof s == "function")
|
|
1445
1780
|
return;
|
|
1446
1781
|
if (typeof s == "object") {
|
|
1447
|
-
const
|
|
1448
|
-
let
|
|
1449
|
-
|
|
1450
|
-
this._xporter._instance_xporters[i], s instanceof this._xporter._instance_xporters[i].cls && (e[t] = this._xporter._instance_xporters[i].handler(s),
|
|
1451
|
-
}),
|
|
1782
|
+
const r = Object.keys(this._xporter._instance_xporters);
|
|
1783
|
+
let n = !0;
|
|
1784
|
+
r.forEach((i) => {
|
|
1785
|
+
this._xporter._instance_xporters[i], s instanceof this._xporter._instance_xporters[i].cls && (e[t] = this._xporter._instance_xporters[i].handler(s), n = !1);
|
|
1786
|
+
}), n && (e[t] = s);
|
|
1452
1787
|
} else
|
|
1453
1788
|
e[t] = s;
|
|
1454
1789
|
}
|
|
@@ -1469,10 +1804,10 @@ const R = {
|
|
|
1469
1804
|
});
|
|
1470
1805
|
}
|
|
1471
1806
|
bindDataSource(e, t) {
|
|
1472
|
-
const s = t?.initial ?? !0,
|
|
1473
|
-
typeof
|
|
1474
|
-
await this.onData(
|
|
1475
|
-
}), s &&
|
|
1807
|
+
const s = t?.initial ?? !0, r = e ?? this._data_source;
|
|
1808
|
+
typeof r != "string" || r.length === 0 || this._process_data && (this._xd_bound_key === r && this._xd_unsub || (this.unbindDataSource(), this._data_source = r, this._xd_bound_key = r, this._type ?? this.constructor.name, this._id, this._xd_unsub = v.on(r, async (n) => {
|
|
1809
|
+
await this.onData(n.value);
|
|
1810
|
+
}), s && v.has(r) && this.onData(v.get(r))));
|
|
1476
1811
|
}
|
|
1477
1812
|
unbindDataSource() {
|
|
1478
1813
|
this._xd_unsub?.(), this._xd_unsub = void 0, this._xd_bound_key = void 0;
|
|
@@ -1510,20 +1845,20 @@ const R = {
|
|
|
1510
1845
|
this.append(e);
|
|
1511
1846
|
}
|
|
1512
1847
|
};
|
|
1513
|
-
|
|
1514
|
-
let
|
|
1515
|
-
class
|
|
1848
|
+
A._xtype = "object", A._skill = U;
|
|
1849
|
+
let C = A;
|
|
1850
|
+
class me {
|
|
1516
1851
|
/**
|
|
1517
1852
|
* Get all registered object in this ObjectPack
|
|
1518
1853
|
* @returns XObject dictionary
|
|
1519
1854
|
*/
|
|
1520
1855
|
static getObjects() {
|
|
1521
1856
|
return {
|
|
1522
|
-
object:
|
|
1857
|
+
object: C
|
|
1523
1858
|
};
|
|
1524
1859
|
}
|
|
1525
1860
|
}
|
|
1526
|
-
const
|
|
1861
|
+
const ae = "engine:module:num-of-objects:", W = {
|
|
1527
1862
|
_id: "xmodule",
|
|
1528
1863
|
_title: "XModule Runtime Contract",
|
|
1529
1864
|
_version: "1.0.0",
|
|
@@ -1538,14 +1873,14 @@ const ie = "engine:module:num-of-objects:", N = {
|
|
|
1538
1873
|
"Do not mutate another module's objects directly."
|
|
1539
1874
|
]
|
|
1540
1875
|
};
|
|
1541
|
-
var
|
|
1542
|
-
const
|
|
1876
|
+
var p;
|
|
1877
|
+
const I = class I {
|
|
1543
1878
|
constructor(e) {
|
|
1544
|
-
|
|
1879
|
+
J(this, p);
|
|
1545
1880
|
this._loaded = !1, this._loading = !1, this._log_rules = {
|
|
1546
1881
|
createObject: !1,
|
|
1547
1882
|
removeObject: !1
|
|
1548
|
-
},
|
|
1883
|
+
}, V(this, p, new re()), this._name = e._name, this._id = u.guid();
|
|
1549
1884
|
}
|
|
1550
1885
|
static getOwnSkillBase() {
|
|
1551
1886
|
return {
|
|
@@ -1553,7 +1888,7 @@ const C = class C {
|
|
|
1553
1888
|
};
|
|
1554
1889
|
}
|
|
1555
1890
|
getOwnSkill() {
|
|
1556
|
-
const t = this.constructor._skill ??
|
|
1891
|
+
const t = this.constructor._skill ?? W;
|
|
1557
1892
|
return {
|
|
1558
1893
|
...t,
|
|
1559
1894
|
_exports: {
|
|
@@ -1574,23 +1909,23 @@ const C = class C {
|
|
|
1574
1909
|
}
|
|
1575
1910
|
getObjectSkills() {
|
|
1576
1911
|
const e = [], t = /* @__PURE__ */ new Set();
|
|
1577
|
-
for (const s of Object.values(
|
|
1912
|
+
for (const s of Object.values(f(this, p).getObjectClasses())) {
|
|
1578
1913
|
if (typeof s.getOwnSkill != "function") continue;
|
|
1579
|
-
const
|
|
1580
|
-
|
|
1914
|
+
const r = s.getOwnSkill();
|
|
1915
|
+
r?._id && (t.has(r._id) || (t.add(r._id), e.push(r)));
|
|
1581
1916
|
}
|
|
1582
1917
|
return e;
|
|
1583
1918
|
}
|
|
1584
1919
|
getCommandSkills() {
|
|
1585
1920
|
const e = Object.getPrototypeOf(this), s = this.constructor._ops ?? {};
|
|
1586
1921
|
return Object.getOwnPropertyNames(e).filter(
|
|
1587
|
-
(
|
|
1588
|
-
).map((
|
|
1589
|
-
const
|
|
1590
|
-
return s[
|
|
1591
|
-
_name:
|
|
1922
|
+
(r) => r.startsWith("_") && !r.startsWith("__") && typeof this[r] == "function"
|
|
1923
|
+
).map((r) => {
|
|
1924
|
+
const n = r.slice(1).replaceAll("_", "-");
|
|
1925
|
+
return s[n] ?? {
|
|
1926
|
+
_name: n,
|
|
1592
1927
|
_scope: "module",
|
|
1593
|
-
_description: `Runtime module command: ${
|
|
1928
|
+
_description: `Runtime module command: ${n}`
|
|
1594
1929
|
};
|
|
1595
1930
|
});
|
|
1596
1931
|
}
|
|
@@ -1598,7 +1933,7 @@ const C = class C {
|
|
|
1598
1933
|
if (!(this._loaded || this._loading)) {
|
|
1599
1934
|
this._loading = !0;
|
|
1600
1935
|
try {
|
|
1601
|
-
await this.onLoad(), this._loaded = !0,
|
|
1936
|
+
await this.onLoad(), this._loaded = !0, h.log("Module " + this._name + " loaded");
|
|
1602
1937
|
} finally {
|
|
1603
1938
|
this._loading = !1;
|
|
1604
1939
|
}
|
|
@@ -1612,22 +1947,22 @@ const C = class C {
|
|
|
1612
1947
|
* @return {XObject|*}
|
|
1613
1948
|
*/
|
|
1614
1949
|
create(e) {
|
|
1615
|
-
e._debug &&
|
|
1950
|
+
e._debug && h.log("Creating object with data", e);
|
|
1616
1951
|
let t;
|
|
1617
1952
|
if (e.hasOwnProperty("_type")) {
|
|
1618
|
-
e._debug &&
|
|
1619
|
-
const s = String(e._type),
|
|
1620
|
-
if (!
|
|
1953
|
+
e._debug && h.log("Object type is", e._type, this.hasObject(e._type) ? "found" : "not found", "in module", this._name);
|
|
1954
|
+
const s = String(e._type), r = f(this, p).getObjectClass(s);
|
|
1955
|
+
if (!r)
|
|
1621
1956
|
throw `Xpell object '${s}' not found in module '${this._name}'`;
|
|
1622
|
-
typeof
|
|
1957
|
+
typeof r == "function" && r.hasOwnProperty("defaults") && u.mergeDefaultsWithData(
|
|
1623
1958
|
e,
|
|
1624
|
-
|
|
1625
|
-
), t = new
|
|
1959
|
+
r.defaults
|
|
1960
|
+
), t = new r(e);
|
|
1626
1961
|
} else
|
|
1627
|
-
t = new
|
|
1628
|
-
return
|
|
1629
|
-
const
|
|
1630
|
-
t.append(
|
|
1962
|
+
t = new C(e);
|
|
1963
|
+
return f(this, p).addObject(t), e._children && e._children.forEach((s) => {
|
|
1964
|
+
const r = this.create(s);
|
|
1965
|
+
t.append(r);
|
|
1631
1966
|
}), t.onCreate(), t;
|
|
1632
1967
|
}
|
|
1633
1968
|
/**
|
|
@@ -1635,15 +1970,15 @@ const C = class C {
|
|
|
1635
1970
|
* @param objectId op
|
|
1636
1971
|
*/
|
|
1637
1972
|
remove(e) {
|
|
1638
|
-
const t =
|
|
1973
|
+
const t = f(this, p).getObject(e);
|
|
1639
1974
|
if (!t) return;
|
|
1640
|
-
const s = [],
|
|
1641
|
-
|
|
1975
|
+
const s = [], r = (n) => {
|
|
1976
|
+
n?._id && (s.push(n._id), (n._children ?? []).forEach((i) => r(i)));
|
|
1642
1977
|
};
|
|
1643
|
-
|
|
1978
|
+
r(t), typeof t.dispose == "function" && t.dispose(), s.reverse().forEach((n) => f(this, p).removeObject(n));
|
|
1644
1979
|
}
|
|
1645
1980
|
_info(e) {
|
|
1646
|
-
|
|
1981
|
+
h.log("module info");
|
|
1647
1982
|
}
|
|
1648
1983
|
//xpell interpreter
|
|
1649
1984
|
/**
|
|
@@ -1656,7 +1991,7 @@ const C = class C {
|
|
|
1656
1991
|
if (e) {
|
|
1657
1992
|
let t = e.trim();
|
|
1658
1993
|
t.startsWith(this._name) || (t = this._name + " " + t);
|
|
1659
|
-
let s =
|
|
1994
|
+
let s = O.parse(t);
|
|
1660
1995
|
return await this.execute(s);
|
|
1661
1996
|
} else
|
|
1662
1997
|
throw "Unable to parse Xpell Command";
|
|
@@ -1672,14 +2007,14 @@ const C = class C {
|
|
|
1672
2007
|
throw new Error(`Invalid XCommand: missing _op (module: ${this._name})`);
|
|
1673
2008
|
const t = e._object;
|
|
1674
2009
|
if (t) {
|
|
1675
|
-
const
|
|
1676
|
-
if (!
|
|
2010
|
+
const c = f(this, p).getObject(t);
|
|
2011
|
+
if (!c)
|
|
1677
2012
|
throw new Error(`Module '${this._name}' cant find object id: ${t}`);
|
|
1678
|
-
return await
|
|
2013
|
+
return await c.execute(e);
|
|
1679
2014
|
}
|
|
1680
|
-
const s = "_" +
|
|
1681
|
-
if (typeof
|
|
1682
|
-
return await
|
|
2015
|
+
const s = e._op, n = "_" + (s.startsWith("_") && s.length > 1 ? s.slice(1) : s).replaceAll("-", "_"), i = this[n];
|
|
2016
|
+
if (typeof i == "function")
|
|
2017
|
+
return await i.call(this, e);
|
|
1683
2018
|
throw new Error(`Module '${this._name}' cant find op: ${e._op}`);
|
|
1684
2019
|
}
|
|
1685
2020
|
/**
|
|
@@ -1688,11 +2023,11 @@ const C = class C {
|
|
|
1688
2023
|
* @param frameNumber Current frame number
|
|
1689
2024
|
*/
|
|
1690
2025
|
async onFrame(e) {
|
|
1691
|
-
const t =
|
|
1692
|
-
s.forEach((
|
|
1693
|
-
const
|
|
1694
|
-
|
|
1695
|
-
}),
|
|
2026
|
+
const t = f(this, p)._objects, s = Object.keys(t);
|
|
2027
|
+
s.forEach((r) => {
|
|
2028
|
+
const n = t[r];
|
|
2029
|
+
n && n.onFrame && typeof n.onFrame == "function" && n?.onFrame(e);
|
|
2030
|
+
}), m.set(ae + this._id, s.length, {
|
|
1696
2031
|
source: "xmodule"
|
|
1697
2032
|
});
|
|
1698
2033
|
}
|
|
@@ -1707,10 +2042,10 @@ const C = class C {
|
|
|
1707
2042
|
* getObject directly on the module instead of om.getObject
|
|
1708
2043
|
*/
|
|
1709
2044
|
get om() {
|
|
1710
|
-
return
|
|
2045
|
+
return f(this, p);
|
|
1711
2046
|
}
|
|
1712
2047
|
get _object_manager() {
|
|
1713
|
-
return
|
|
2048
|
+
return f(this, p);
|
|
1714
2049
|
}
|
|
1715
2050
|
/**
|
|
1716
2051
|
* Returns the XObject instance from the module Object Manager
|
|
@@ -1718,10 +2053,10 @@ const C = class C {
|
|
|
1718
2053
|
* @returns XObject
|
|
1719
2054
|
*/
|
|
1720
2055
|
getObject(e) {
|
|
1721
|
-
return
|
|
2056
|
+
return f(this, p).getObject(e);
|
|
1722
2057
|
}
|
|
1723
2058
|
hasObject(e) {
|
|
1724
|
-
return
|
|
2059
|
+
return f(this, p).hasObjectClass(e);
|
|
1725
2060
|
}
|
|
1726
2061
|
/**
|
|
1727
2062
|
* Returns the XObject instance from the module Object Manager
|
|
@@ -1729,7 +2064,7 @@ const C = class C {
|
|
|
1729
2064
|
* xmodule._o["object-id"] is equivalent to xmodule.getObject("object-id")
|
|
1730
2065
|
*/
|
|
1731
2066
|
get _o() {
|
|
1732
|
-
return
|
|
2067
|
+
return f(this, p)._objects;
|
|
1733
2068
|
}
|
|
1734
2069
|
/**
|
|
1735
2070
|
* Imports external object pack to the engine
|
|
@@ -1737,7 +2072,7 @@ const C = class C {
|
|
|
1737
2072
|
* @param {XObjects} xObjectPack
|
|
1738
2073
|
*/
|
|
1739
2074
|
importObjectPack(e) {
|
|
1740
|
-
|
|
2075
|
+
f(this, p).registerObjects(e.getObjects());
|
|
1741
2076
|
}
|
|
1742
2077
|
/**
|
|
1743
2078
|
* Imports external object pack to the engine
|
|
@@ -1754,7 +2089,7 @@ const C = class C {
|
|
|
1754
2089
|
* @param xObject
|
|
1755
2090
|
*/
|
|
1756
2091
|
importObject(e, t) {
|
|
1757
|
-
|
|
2092
|
+
f(this, p).registerObject(e, t);
|
|
1758
2093
|
}
|
|
1759
2094
|
// In XModule
|
|
1760
2095
|
async _help(e) {
|
|
@@ -1774,7 +2109,7 @@ const C = class C {
|
|
|
1774
2109
|
};
|
|
1775
2110
|
}
|
|
1776
2111
|
};
|
|
1777
|
-
|
|
2112
|
+
p = new WeakMap(), I._skill = W, I._ops = {
|
|
1778
2113
|
help: {
|
|
1779
2114
|
_name: "help",
|
|
1780
2115
|
_scope: "module",
|
|
@@ -1786,8 +2121,8 @@ d = new WeakMap(), C._skill = N, C._ops = {
|
|
|
1786
2121
|
_description: "Log basic module information."
|
|
1787
2122
|
}
|
|
1788
2123
|
};
|
|
1789
|
-
let
|
|
1790
|
-
const
|
|
2124
|
+
let F = I;
|
|
2125
|
+
const ce = {
|
|
1791
2126
|
_id: "xdata",
|
|
1792
2127
|
_title: "XData Runtime State Contract",
|
|
1793
2128
|
_version: "1.0.0",
|
|
@@ -1806,20 +2141,20 @@ const oe = {
|
|
|
1806
2141
|
_data_source: "XData key used by XObject/XUIObject for reactive data binding.",
|
|
1807
2142
|
"$xdata.key": "Runtime payload reference to an XData value."
|
|
1808
2143
|
}
|
|
1809
|
-
},
|
|
2144
|
+
}, S = class S extends F {
|
|
1810
2145
|
constructor() {
|
|
1811
|
-
super({ _name:
|
|
2146
|
+
super({ _name: S._name });
|
|
1812
2147
|
}
|
|
1813
2148
|
async _get(e) {
|
|
1814
|
-
const t =
|
|
2149
|
+
const t = u.ensure_params(e?._params), s = u.ensure_string(t.key, "key");
|
|
1815
2150
|
return {
|
|
1816
2151
|
_ok: !0,
|
|
1817
|
-
_result:
|
|
2152
|
+
_result: m.get(s)
|
|
1818
2153
|
};
|
|
1819
2154
|
}
|
|
1820
2155
|
async _set(e) {
|
|
1821
|
-
const t =
|
|
1822
|
-
return t._debug &&
|
|
2156
|
+
const t = u.ensure_params(e?._params), s = u.ensure_string(t.key, "key");
|
|
2157
|
+
return t._debug && x.log("XD SET", { key: s, value: t.value }), m.set(s, t.value, {
|
|
1823
2158
|
source: t.source ?? "xd:set"
|
|
1824
2159
|
}), {
|
|
1825
2160
|
_ok: !0,
|
|
@@ -1827,10 +2162,10 @@ const oe = {
|
|
|
1827
2162
|
};
|
|
1828
2163
|
}
|
|
1829
2164
|
async _patch(e) {
|
|
1830
|
-
const t =
|
|
1831
|
-
if (!
|
|
2165
|
+
const t = u.ensure_params(e?._params), s = u.ensure_string(t.key, "key");
|
|
2166
|
+
if (!u.is_plain_object(t.value))
|
|
1832
2167
|
throw new Error("xd patch expects value as plain object");
|
|
1833
|
-
return
|
|
2168
|
+
return m.patch(s, t.value, {
|
|
1834
2169
|
source: t.source ?? "xd:patch"
|
|
1835
2170
|
}), {
|
|
1836
2171
|
_ok: !0,
|
|
@@ -1838,8 +2173,8 @@ const oe = {
|
|
|
1838
2173
|
};
|
|
1839
2174
|
}
|
|
1840
2175
|
async _delete(e) {
|
|
1841
|
-
const t =
|
|
1842
|
-
return
|
|
2176
|
+
const t = u.ensure_params(e?._params), s = u.ensure_string(t.key, "key");
|
|
2177
|
+
return m.delete(s, {
|
|
1843
2178
|
source: t.source ?? "xd:delete"
|
|
1844
2179
|
}), {
|
|
1845
2180
|
_ok: !0,
|
|
@@ -1847,8 +2182,8 @@ const oe = {
|
|
|
1847
2182
|
};
|
|
1848
2183
|
}
|
|
1849
2184
|
async _touch(e) {
|
|
1850
|
-
const t =
|
|
1851
|
-
return
|
|
2185
|
+
const t = u.ensure_params(e?._params), s = u.ensure_string(t.key, "key");
|
|
2186
|
+
return m.touch(s, {
|
|
1852
2187
|
source: t.source ?? "xd:touch"
|
|
1853
2188
|
}), {
|
|
1854
2189
|
_ok: !0,
|
|
@@ -1856,14 +2191,47 @@ const oe = {
|
|
|
1856
2191
|
};
|
|
1857
2192
|
}
|
|
1858
2193
|
async _has(e) {
|
|
1859
|
-
const t =
|
|
2194
|
+
const t = u.ensure_params(e?._params), s = u.ensure_string(t.key, "key");
|
|
1860
2195
|
return {
|
|
1861
2196
|
_ok: !0,
|
|
1862
|
-
_result:
|
|
2197
|
+
_result: m.has(s)
|
|
2198
|
+
};
|
|
2199
|
+
}
|
|
2200
|
+
async _get_path(e) {
|
|
2201
|
+
const t = u.ensure_params(e?._params), s = u.ensure_string(t.key, "key"), r = u.ensure_string(t.path, "path"), n = m.get(s);
|
|
2202
|
+
return {
|
|
2203
|
+
_ok: !0,
|
|
2204
|
+
_result: u.get_path(
|
|
2205
|
+
n,
|
|
2206
|
+
r,
|
|
2207
|
+
t.fallback
|
|
2208
|
+
)
|
|
2209
|
+
};
|
|
2210
|
+
}
|
|
2211
|
+
async _log(e) {
|
|
2212
|
+
const t = u.ensure_params(e?._params), s = u.ensure_string(t.key, "key"), r = m.get(s), n = u.read_optional_string(
|
|
2213
|
+
t.path,
|
|
2214
|
+
"path"
|
|
2215
|
+
), i = n ? u.get_path(
|
|
2216
|
+
r,
|
|
2217
|
+
n,
|
|
2218
|
+
t.fallback
|
|
2219
|
+
) : r;
|
|
2220
|
+
return x.log("XDATA LOG", {
|
|
2221
|
+
key: s,
|
|
2222
|
+
path: n,
|
|
2223
|
+
value: i
|
|
2224
|
+
}), {
|
|
2225
|
+
_ok: !0,
|
|
2226
|
+
_result: {
|
|
2227
|
+
key: s,
|
|
2228
|
+
path: n,
|
|
2229
|
+
value: i
|
|
2230
|
+
}
|
|
1863
2231
|
};
|
|
1864
2232
|
}
|
|
1865
2233
|
};
|
|
1866
|
-
|
|
2234
|
+
S._name = "xd", S._skill = ce, S._ops = {
|
|
1867
2235
|
get: {
|
|
1868
2236
|
_name: "get",
|
|
1869
2237
|
_scope: "module",
|
|
@@ -1917,10 +2285,20 @@ v._name = "xd", v._skill = oe, v._ops = {
|
|
|
1917
2285
|
_params: {
|
|
1918
2286
|
key: "XData key."
|
|
1919
2287
|
}
|
|
2288
|
+
},
|
|
2289
|
+
get_path: {
|
|
2290
|
+
_name: "get_path",
|
|
2291
|
+
_scope: "module",
|
|
2292
|
+
_description: "Get nested value from an XData value.",
|
|
2293
|
+
_params: {
|
|
2294
|
+
key: "XData key.",
|
|
2295
|
+
path: "Nested path inside the stored value.",
|
|
2296
|
+
fallback: "Optional fallback value."
|
|
2297
|
+
}
|
|
1920
2298
|
}
|
|
1921
2299
|
};
|
|
1922
|
-
let
|
|
1923
|
-
const
|
|
2300
|
+
let q = S;
|
|
2301
|
+
const _e = {
|
|
1924
2302
|
_id: "xem",
|
|
1925
2303
|
_title: "XEventManager Runtime Event Bus",
|
|
1926
2304
|
_version: "1.0.0",
|
|
@@ -1945,16 +2323,16 @@ const ae = {
|
|
|
1945
2323
|
"XEM is process-wide and listener order should not be assumed.",
|
|
1946
2324
|
"Event payloads should be JSON/data-only."
|
|
1947
2325
|
]
|
|
1948
|
-
},
|
|
2326
|
+
}, D = class D extends F {
|
|
1949
2327
|
constructor() {
|
|
1950
|
-
super({ _name:
|
|
2328
|
+
super({ _name: D._name });
|
|
1951
2329
|
}
|
|
1952
2330
|
async _fire(e) {
|
|
1953
|
-
const t =
|
|
1954
|
-
t._debug &&
|
|
2331
|
+
const t = u.ensure_params(e?._params), s = u.ensure_string(t.event, "event"), r = t.data;
|
|
2332
|
+
t._debug && x.log("xem fire 🔥 ", s, r), await X().fire(s, r);
|
|
1955
2333
|
}
|
|
1956
2334
|
};
|
|
1957
|
-
|
|
2335
|
+
D._name = "xem", D._skill = _e, D._ops = {
|
|
1958
2336
|
fire: {
|
|
1959
2337
|
_name: "fire",
|
|
1960
2338
|
_scope: "module",
|
|
@@ -1976,59 +2354,58 @@ k._name = "xem", k._skill = ae, k._ops = {
|
|
|
1976
2354
|
}
|
|
1977
2355
|
}
|
|
1978
2356
|
};
|
|
1979
|
-
let
|
|
1980
|
-
class
|
|
2357
|
+
let T = D;
|
|
2358
|
+
class ge {
|
|
1981
2359
|
/* -------------------------------------------------- */
|
|
1982
2360
|
/* core helpers */
|
|
1983
2361
|
/* -------------------------------------------------- */
|
|
1984
2362
|
static get(e, t, s) {
|
|
1985
|
-
|
|
1986
|
-
const n = e._params[t];
|
|
2363
|
+
const n = (e?._params ?? e)?.[t];
|
|
1987
2364
|
return n !== void 0 ? n : s;
|
|
1988
2365
|
}
|
|
1989
2366
|
static has(e, t) {
|
|
1990
|
-
return (e?._params
|
|
2367
|
+
return (e?._params ?? e)[t] !== void 0;
|
|
1991
2368
|
}
|
|
1992
2369
|
static str(e, ...t) {
|
|
1993
|
-
const s = e?._params
|
|
1994
|
-
for (const
|
|
1995
|
-
const
|
|
1996
|
-
if (
|
|
1997
|
-
return String(
|
|
2370
|
+
const s = e?._params ?? e;
|
|
2371
|
+
for (const r of t) {
|
|
2372
|
+
const n = s?.[r];
|
|
2373
|
+
if (n != null)
|
|
2374
|
+
return String(n);
|
|
1998
2375
|
}
|
|
1999
2376
|
}
|
|
2000
2377
|
/* -------------------------------------------------- */
|
|
2001
2378
|
/* typed params */
|
|
2002
2379
|
/* -------------------------------------------------- */
|
|
2003
2380
|
static bool(e, t, s = !1) {
|
|
2004
|
-
const
|
|
2005
|
-
if (typeof
|
|
2006
|
-
if (typeof
|
|
2007
|
-
if (typeof
|
|
2008
|
-
const i =
|
|
2381
|
+
const r = e?._params ?? e, n = this.get(r, t, s);
|
|
2382
|
+
if (typeof n == "boolean") return n;
|
|
2383
|
+
if (typeof n == "number") return n !== 0;
|
|
2384
|
+
if (typeof n == "string") {
|
|
2385
|
+
const i = n.toLowerCase();
|
|
2009
2386
|
if (["1", "true", "yes", "on"].includes(i)) return !0;
|
|
2010
2387
|
if (["0", "false", "no", "off"].includes(i)) return !1;
|
|
2011
2388
|
}
|
|
2012
|
-
return !!
|
|
2389
|
+
return !!n;
|
|
2013
2390
|
}
|
|
2014
2391
|
static int(e, t, s = 0) {
|
|
2015
|
-
const
|
|
2392
|
+
const r = e?._params ?? e, n = this.get(r, t, s), i = parseInt(String(n), 10);
|
|
2016
2393
|
return Number.isFinite(i) ? i : s;
|
|
2017
2394
|
}
|
|
2018
2395
|
static json(e, t, s) {
|
|
2019
|
-
const
|
|
2020
|
-
if (
|
|
2021
|
-
if (typeof
|
|
2022
|
-
if (typeof
|
|
2396
|
+
const r = e?._params ?? e, n = this.get(r, t, s);
|
|
2397
|
+
if (n == null) return s;
|
|
2398
|
+
if (typeof n == "object") return n;
|
|
2399
|
+
if (typeof n == "string")
|
|
2023
2400
|
try {
|
|
2024
|
-
return JSON.parse(
|
|
2401
|
+
return JSON.parse(n);
|
|
2025
2402
|
} catch {
|
|
2026
2403
|
return s;
|
|
2027
2404
|
}
|
|
2028
2405
|
return s;
|
|
2029
2406
|
}
|
|
2030
2407
|
}
|
|
2031
|
-
class
|
|
2408
|
+
class H extends Error {
|
|
2032
2409
|
constructor(e, t, s) {
|
|
2033
2410
|
super(t), this.name = "XError", this._code = e, this._level = s?._level ?? "error", this._meta = s?._meta, this._cause = s?._cause;
|
|
2034
2411
|
}
|
|
@@ -2051,7 +2428,7 @@ class K extends Error {
|
|
|
2051
2428
|
};
|
|
2052
2429
|
}
|
|
2053
2430
|
}
|
|
2054
|
-
class
|
|
2431
|
+
class k {
|
|
2055
2432
|
constructor(e) {
|
|
2056
2433
|
this._ok = !1, this._ts = Date.now(), this._pt = 0, e && this.setXData(e);
|
|
2057
2434
|
}
|
|
@@ -2059,23 +2436,23 @@ class y {
|
|
|
2059
2436
|
// Factories
|
|
2060
2437
|
// ---------------------------------------------------------------------------
|
|
2061
2438
|
static create(e) {
|
|
2062
|
-
return new
|
|
2439
|
+
return new k(e);
|
|
2063
2440
|
}
|
|
2064
2441
|
static ok(e) {
|
|
2065
|
-
return new
|
|
2442
|
+
return new k({ _ok: !0, _result: e });
|
|
2066
2443
|
}
|
|
2067
2444
|
static error(e) {
|
|
2068
|
-
if (e instanceof
|
|
2069
|
-
return new
|
|
2445
|
+
if (e instanceof H)
|
|
2446
|
+
return new k({
|
|
2070
2447
|
_ok: !1,
|
|
2071
2448
|
_result: e.toXData()
|
|
2072
2449
|
});
|
|
2073
|
-
const t = new
|
|
2450
|
+
const t = new H(
|
|
2074
2451
|
"E_INTERNAL",
|
|
2075
2452
|
e?.message ?? String(e),
|
|
2076
2453
|
{ _cause: e }
|
|
2077
2454
|
);
|
|
2078
|
-
return new
|
|
2455
|
+
return new k({
|
|
2079
2456
|
_ok: !1,
|
|
2080
2457
|
_result: t.toXData()
|
|
2081
2458
|
});
|
|
@@ -2108,33 +2485,33 @@ class y {
|
|
|
2108
2485
|
e && ("_ok" in e && (this._ok = !!e._ok), "_ts" in e && typeof e._ts == "number" && (this._ts = e._ts), "_pt" in e && typeof e._pt == "number" && (this._pt = e._pt), "_result" in e && (this._result = e._result));
|
|
2109
2486
|
}
|
|
2110
2487
|
}
|
|
2111
|
-
class
|
|
2488
|
+
class ye extends k {
|
|
2112
2489
|
constructor(e) {
|
|
2113
|
-
super(
|
|
2490
|
+
super(k.error(e).toXData());
|
|
2114
2491
|
}
|
|
2115
2492
|
}
|
|
2116
|
-
class
|
|
2493
|
+
class be extends k {
|
|
2117
2494
|
constructor(e) {
|
|
2118
2495
|
super({ _ok: !0, _result: e });
|
|
2119
2496
|
}
|
|
2120
2497
|
}
|
|
2121
|
-
const
|
|
2122
|
-
class
|
|
2498
|
+
const le = "engine:frame-number", he = "engine:fps";
|
|
2499
|
+
class ue {
|
|
2123
2500
|
constructor(e) {
|
|
2124
|
-
this._log_rules = {}, this._modules = {}, this._schedule_frame = e?._schedule_frame ??
|
|
2501
|
+
this._log_rules = {}, this._modules = {}, this._schedule_frame = e?._schedule_frame ?? u.createDefaultScheduler(e?._target_fps), this._version = "0.0.1", this._engine_id = u.guid(), this._frame_number = 0, this._fps_calc = new ee(), this.parser = O, this._modules = {}, h._enabled = !1, ie(this);
|
|
2125
2502
|
}
|
|
2126
2503
|
/**
|
|
2127
2504
|
* @deprecated use _verbose instead
|
|
2128
2505
|
* Enable Xpell logs to console
|
|
2129
2506
|
*/
|
|
2130
2507
|
set verbose(e) {
|
|
2131
|
-
|
|
2508
|
+
h._enabled = e;
|
|
2132
2509
|
}
|
|
2133
2510
|
/**
|
|
2134
2511
|
* Enable Xpell logs to console
|
|
2135
2512
|
*/
|
|
2136
2513
|
set _verbose(e) {
|
|
2137
|
-
|
|
2514
|
+
h._enabled = e;
|
|
2138
2515
|
}
|
|
2139
2516
|
/**
|
|
2140
2517
|
* Logs message to console using Xpell logger
|
|
@@ -2144,7 +2521,7 @@ class le {
|
|
|
2144
2521
|
* @param optionalParams
|
|
2145
2522
|
*/
|
|
2146
2523
|
log(e, ...t) {
|
|
2147
|
-
|
|
2524
|
+
h.log(e, ...t);
|
|
2148
2525
|
}
|
|
2149
2526
|
/**
|
|
2150
2527
|
* Delay the execution of the next command
|
|
@@ -2161,7 +2538,7 @@ class le {
|
|
|
2161
2538
|
* Use loadModuleAsync() for deterministic startup.
|
|
2162
2539
|
*/
|
|
2163
2540
|
addModule(e) {
|
|
2164
|
-
return this._modules.hasOwnProperty(e._name) ? (
|
|
2541
|
+
return this._modules.hasOwnProperty(e._name) ? (h.log("Module " + e._name + " already loaded"), !1) : (this._modules[e._name] = e, !0);
|
|
2165
2542
|
}
|
|
2166
2543
|
/**
|
|
2167
2544
|
* Loads Xpell module into the engine
|
|
@@ -2188,7 +2565,7 @@ class le {
|
|
|
2188
2565
|
* Display information about the Xpell engine to the console
|
|
2189
2566
|
*/
|
|
2190
2567
|
info() {
|
|
2191
|
-
|
|
2568
|
+
h.log(`Xpell information:
|
|
2192
2569
|
- Engine Id: ` + this._engine_id + `
|
|
2193
2570
|
- Version ` + this._version);
|
|
2194
2571
|
}
|
|
@@ -2198,7 +2575,7 @@ class le {
|
|
|
2198
2575
|
*/
|
|
2199
2576
|
run(e) {
|
|
2200
2577
|
if (e?.length > 2) {
|
|
2201
|
-
let t =
|
|
2578
|
+
let t = O.parse(e);
|
|
2202
2579
|
return this.execute(t);
|
|
2203
2580
|
} else
|
|
2204
2581
|
throw "Unable to parse Xpell command";
|
|
@@ -2223,7 +2600,7 @@ class le {
|
|
|
2223
2600
|
s?.onFrame && typeof s.onFrame == "function" && s.onFrame(this._frame_number);
|
|
2224
2601
|
}
|
|
2225
2602
|
const e = this._fps_calc.calc();
|
|
2226
|
-
|
|
2603
|
+
m.set(le, this._frame_number, { source: "engine" }), m.set(he, e, { source: "engine" }), m._compat_legacy_keys && (m.set("frame-number", this._frame_number, { source: "engine:legacy" }), m.set("fps", e, { source: "engine:legacy" })), this._schedule_frame(() => this.onFrame());
|
|
2227
2604
|
}
|
|
2228
2605
|
/**
|
|
2229
2606
|
* Gets Xpell module by name
|
|
@@ -2237,12 +2614,12 @@ class le {
|
|
|
2237
2614
|
* Start Xpell engine for web browsers using requestAnimationFrame
|
|
2238
2615
|
*/
|
|
2239
2616
|
start() {
|
|
2240
|
-
|
|
2617
|
+
h.log("Loading Xpell core modules...[xd, xem]"), this.loadModule(new q()), this.loadModule(new T()), h.log("Starting Xpell"), this.onFrame();
|
|
2241
2618
|
}
|
|
2242
2619
|
getCoreSkills() {
|
|
2243
2620
|
return [
|
|
2244
|
-
|
|
2245
|
-
|
|
2621
|
+
W,
|
|
2622
|
+
U
|
|
2246
2623
|
];
|
|
2247
2624
|
}
|
|
2248
2625
|
getModuleSkills() {
|
|
@@ -2265,38 +2642,38 @@ class le {
|
|
|
2265
2642
|
};
|
|
2266
2643
|
}
|
|
2267
2644
|
}
|
|
2268
|
-
const
|
|
2645
|
+
const we = new ue();
|
|
2269
2646
|
export {
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2647
|
+
N as XCommand,
|
|
2648
|
+
he as XD_FPS,
|
|
2649
|
+
le as XD_FRAME_NUMBER,
|
|
2650
|
+
v as XData,
|
|
2651
|
+
q as XDataModule,
|
|
2652
|
+
H as XError,
|
|
2653
|
+
T as XEventManagerModule,
|
|
2654
|
+
h as XLogger,
|
|
2655
|
+
F as XModule,
|
|
2656
|
+
C as XObject,
|
|
2657
|
+
re as XObjectManager,
|
|
2658
|
+
me as XObjectPack,
|
|
2659
|
+
ge as XParams,
|
|
2660
|
+
O as XParser,
|
|
2661
|
+
k as XResponse,
|
|
2662
|
+
ye as XResponseError,
|
|
2663
|
+
be as XResponseOK,
|
|
2664
|
+
Z as XUtils,
|
|
2665
|
+
we as Xpell,
|
|
2666
|
+
ue as XpellEngine,
|
|
2667
|
+
se as _XData,
|
|
2668
|
+
pe as _XEventManager,
|
|
2669
|
+
te as _XLogger,
|
|
2670
|
+
Y as _XUtils,
|
|
2671
|
+
we as _x,
|
|
2672
|
+
m as _xd,
|
|
2673
|
+
h as _xlog,
|
|
2674
|
+
u as _xu,
|
|
2675
|
+
b as createNanoCommandWithSkill,
|
|
2676
|
+
we as default,
|
|
2677
|
+
X as getXEventManager,
|
|
2678
|
+
fe as setXEventManager
|
|
2302
2679
|
};
|