@xpell/core 2.0.0-alpha.11 → 2.0.1
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 +100 -61
- package/dist/XCommand.d.ts +1 -1
- package/dist/XDataModule.d.ts +41 -0
- package/dist/XEvenetManagerModule.d.ts +10 -0
- package/dist/XEventManager.d.ts +3 -6
- package/dist/XModule.d.ts +14 -1
- package/dist/XNanoCommands.d.ts +6 -34
- package/dist/XObject.d.ts +16 -4
- package/dist/XObjectManager.d.ts +2 -0
- package/dist/XParams.d.ts +1 -1
- package/dist/XRuntime.d.ts +2 -0
- package/dist/XSkills.d.ts +47 -0
- package/dist/XUtils.d.ts +35 -0
- package/dist/Xpell.d.ts +30 -7
- package/dist/xpell-core.cjs.js +2 -2
- package/dist/xpell-core.es.js +1491 -742
- package/docs/Codex_Skills/SKILL.md +184 -0
- package/docs/Codex_Skills/SKILL_API_MAP.md +122 -0
- package/docs/Codex_Skills/SKILL_CHECKLIST.md +18 -0
- package/package.json +5 -5
package/dist/xpell-core.es.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
var T = (o) => {
|
|
2
|
+
throw TypeError(o);
|
|
3
|
+
};
|
|
4
|
+
var q = (o, e, t) => e.has(o) || T("Cannot " + t);
|
|
5
|
+
var p = (o, e, t) => (q(o, e, "read from private field"), t ? t.call(o) : e.get(o)), B = (o, e, t) => e.has(o) ? T("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(o) : e.set(o, t), W = (o, e, t, s) => (q(o, e, "write to private field"), s ? s.call(o, t) : e.set(o, t), t);
|
|
6
|
+
class Q {
|
|
2
7
|
/**
|
|
3
8
|
* Create ignore list for parser to ignore spell words
|
|
4
9
|
* @param list - comma-separated list of words
|
|
5
10
|
* @param reservedWords - base reserved words map (mutated)
|
|
6
11
|
*/
|
|
7
|
-
createIgnoreList(
|
|
8
|
-
if (!
|
|
9
|
-
const s =
|
|
10
|
-
for (const
|
|
11
|
-
return
|
|
12
|
+
createIgnoreList(e, t) {
|
|
13
|
+
if (!e) return t;
|
|
14
|
+
const s = e.split(",").map((n) => n.trim()).filter(Boolean);
|
|
15
|
+
for (const n of s) t[n] = "";
|
|
16
|
+
return t;
|
|
12
17
|
}
|
|
13
18
|
/**
|
|
14
19
|
* GUID / UUID v4 (cross-platform)
|
|
@@ -19,21 +24,21 @@ class S {
|
|
|
19
24
|
* 3) Math.random() fallback (NOT crypto-secure, legacy fallback only)
|
|
20
25
|
*/
|
|
21
26
|
guid() {
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
return
|
|
25
|
-
if (
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
return
|
|
27
|
+
const t = globalThis.crypto;
|
|
28
|
+
if (t && typeof t.randomUUID == "function")
|
|
29
|
+
return t.randomUUID();
|
|
30
|
+
if (t && typeof t.getRandomValues == "function") {
|
|
31
|
+
const i = new Uint8Array(16);
|
|
32
|
+
t.getRandomValues(i), i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128;
|
|
33
|
+
const a = Array.from(i, (_) => _.toString(16).padStart(2, "0"));
|
|
34
|
+
return a.slice(0, 4).join("") + "-" + a.slice(4, 6).join("") + "-" + a.slice(6, 8).join("") + "-" + a.slice(8, 10).join("") + "-" + a.slice(10, 16).join("");
|
|
30
35
|
}
|
|
31
|
-
const s = "0123456789abcdef".split(""),
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
for (let
|
|
35
|
-
i
|
|
36
|
-
return
|
|
36
|
+
const s = "0123456789abcdef".split(""), n = [];
|
|
37
|
+
let r;
|
|
38
|
+
n[8] = n[13] = n[18] = n[23] = "-", n[14] = "4";
|
|
39
|
+
for (let i = 0; i < 36; i++)
|
|
40
|
+
n[i] || (r = (0 | Math.random() * 16) >>> 0, n[i] = s[i === 19 ? r & 3 | 8 : r & 15]);
|
|
41
|
+
return n.join("");
|
|
37
42
|
}
|
|
38
43
|
/**
|
|
39
44
|
* Merge defaults into data object (mutates data)
|
|
@@ -41,138 +46,218 @@ class S {
|
|
|
41
46
|
* @param defaults - defaults object
|
|
42
47
|
* @param force - overwrite existing values
|
|
43
48
|
*/
|
|
44
|
-
mergeDefaultsWithData(
|
|
45
|
-
if (!
|
|
46
|
-
|
|
47
|
-
for (const
|
|
48
|
-
(!(
|
|
49
|
-
return
|
|
49
|
+
mergeDefaultsWithData(e, t, s = !1) {
|
|
50
|
+
if (!e) return t;
|
|
51
|
+
e._id || (e._id = e.id ?? this.guid());
|
|
52
|
+
for (const n of Object.keys(t))
|
|
53
|
+
(!(n in e) || s) && (e[n] = t[n]);
|
|
54
|
+
return e;
|
|
50
55
|
}
|
|
51
56
|
/**
|
|
52
57
|
* Encode string to Base64 (UTF-8 safe, cross-platform)
|
|
53
58
|
*/
|
|
54
|
-
encode(
|
|
55
|
-
const
|
|
56
|
-
if (typeof
|
|
57
|
-
const s = encodeURIComponent(String(
|
|
59
|
+
encode(e) {
|
|
60
|
+
const t = globalThis;
|
|
61
|
+
if (typeof t.btoa == "function") {
|
|
62
|
+
const s = encodeURIComponent(String(e)).replace(
|
|
58
63
|
/%([0-9A-F]{2})/g,
|
|
59
|
-
(
|
|
64
|
+
(n, r) => String.fromCharCode(parseInt(r, 16))
|
|
60
65
|
);
|
|
61
|
-
return
|
|
66
|
+
return t.btoa(s);
|
|
62
67
|
}
|
|
63
|
-
if (
|
|
64
|
-
return
|
|
68
|
+
if (t.Buffer && typeof t.Buffer.from == "function")
|
|
69
|
+
return t.Buffer.from(String(e), "utf8").toString("base64");
|
|
65
70
|
throw new Error("Base64 encode not supported in this environment");
|
|
66
71
|
}
|
|
67
72
|
/**
|
|
68
73
|
* Decode Base64 string to UTF-8 (cross-platform)
|
|
69
74
|
*/
|
|
70
|
-
decode(
|
|
71
|
-
const
|
|
72
|
-
if (typeof
|
|
73
|
-
const s =
|
|
74
|
-
return decodeURIComponent(
|
|
75
|
+
decode(e) {
|
|
76
|
+
const t = globalThis;
|
|
77
|
+
if (typeof t.atob == "function") {
|
|
78
|
+
const s = t.atob(String(e)), n = Array.prototype.map.call(s, (r) => "%" + r.charCodeAt(0).toString(16).padStart(2, "0")).join("");
|
|
79
|
+
return decodeURIComponent(n);
|
|
75
80
|
}
|
|
76
|
-
if (
|
|
77
|
-
return
|
|
81
|
+
if (t.Buffer && typeof t.Buffer.from == "function")
|
|
82
|
+
return t.Buffer.from(String(e), "base64").toString("utf8");
|
|
78
83
|
throw new Error("Base64 decode not supported in this environment");
|
|
79
84
|
}
|
|
80
85
|
/**
|
|
81
86
|
* Returns a random integer between min and max (inclusive)
|
|
82
87
|
* NOTE: Not cryptographically secure (OK for UI, NOT for IDs)
|
|
83
88
|
*/
|
|
84
|
-
getRandomInt(
|
|
85
|
-
return
|
|
89
|
+
getRandomInt(e, t) {
|
|
90
|
+
return e = Math.ceil(e), t = Math.floor(t), Math.floor(Math.random() * (t - e + 1)) + e;
|
|
86
91
|
}
|
|
87
92
|
/**
|
|
88
93
|
* Extract parameter from XCommand
|
|
89
94
|
*/
|
|
90
|
-
getParam(
|
|
91
|
-
return
|
|
95
|
+
getParam(e, t, s = 0) {
|
|
96
|
+
return e?._params?.[t] ?? s;
|
|
92
97
|
}
|
|
93
98
|
/**
|
|
94
99
|
* Default frame scheduler (cross-platform)
|
|
95
100
|
* - Browser: requestAnimationFrame
|
|
96
101
|
* - Node / non-DOM: setImmediate (fast) or setTimeout (paced by target fps)
|
|
97
102
|
*/
|
|
98
|
-
createDefaultScheduler(
|
|
99
|
-
const
|
|
100
|
-
if (typeof
|
|
101
|
-
return (
|
|
102
|
-
const s = typeof
|
|
103
|
-
if (typeof
|
|
104
|
-
return (
|
|
105
|
-
const
|
|
106
|
-
return (
|
|
103
|
+
createDefaultScheduler(e) {
|
|
104
|
+
const t = globalThis;
|
|
105
|
+
if (typeof t.requestAnimationFrame == "function")
|
|
106
|
+
return (r) => t.requestAnimationFrame(r);
|
|
107
|
+
const s = typeof e == "number" && isFinite(e) && e > 0 ? e : 60;
|
|
108
|
+
if (typeof t.setImmediate == "function" && (!e || e >= 60))
|
|
109
|
+
return (r) => t.setImmediate(r);
|
|
110
|
+
const n = Math.max(1, Math.round(1e3 / s));
|
|
111
|
+
return (r) => t.setTimeout(r, n);
|
|
112
|
+
}
|
|
113
|
+
to_iso_now() {
|
|
114
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
115
|
+
}
|
|
116
|
+
is_plain_object(e) {
|
|
117
|
+
return typeof e == "object" && e !== null && !Array.isArray(e);
|
|
118
|
+
}
|
|
119
|
+
ensure_string(e, t) {
|
|
120
|
+
if (typeof e != "string" || !e.trim())
|
|
121
|
+
throw new Error(`Invalid '${t}'`);
|
|
122
|
+
return e.trim();
|
|
123
|
+
}
|
|
124
|
+
ensure_params(e) {
|
|
125
|
+
return this.is_plain_object(e) ? e : {};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Copy keys from source to target only when value is not null/undefined.
|
|
129
|
+
* Keeps valid falsy values (0, false, "").
|
|
130
|
+
*/
|
|
131
|
+
addIfNotNull(e, t, s) {
|
|
132
|
+
if (!(!e || !t || !Array.isArray(s)))
|
|
133
|
+
for (const n of s) {
|
|
134
|
+
const r = e[n];
|
|
135
|
+
r != null && (t[n] = r);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Add Last Slash
|
|
140
|
+
* adds a last slash to the url if it doesn't have one
|
|
141
|
+
*/
|
|
142
|
+
als(e) {
|
|
143
|
+
const t = String(e ?? "");
|
|
144
|
+
return t.endsWith("/") ? t : t + "/";
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Clear Last Slash
|
|
148
|
+
* removes the last slash if exists
|
|
149
|
+
*/
|
|
150
|
+
cls(e) {
|
|
151
|
+
const t = String(e ?? "");
|
|
152
|
+
return t.endsWith("/") ? t.slice(0, -1) : t;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Add First Slash
|
|
156
|
+
*/
|
|
157
|
+
afs(e) {
|
|
158
|
+
const t = String(e ?? "");
|
|
159
|
+
return t.startsWith("/") ? t : "/" + t;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Clear First Slash
|
|
163
|
+
*/
|
|
164
|
+
cfs(e) {
|
|
165
|
+
const t = String(e ?? "");
|
|
166
|
+
return t.startsWith("/") ? t.slice(1) : t;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Calculates expiration time based on short format:
|
|
170
|
+
* - 1h (hours)
|
|
171
|
+
* - 2d (days)
|
|
172
|
+
* - 3y (years, 365d)
|
|
173
|
+
* Returns epoch ms (now + delta).
|
|
174
|
+
*/
|
|
175
|
+
calculateExpiration(e) {
|
|
176
|
+
const s = String(e ?? "").trim().match(/^(\d+)([hdy])$/);
|
|
177
|
+
if (!s) throw new Error("Invalid expiration format. Use: 1h | 2d | 3y");
|
|
178
|
+
const n = Number.parseInt(s[1], 10), r = s[2], i = Date.now();
|
|
179
|
+
let a = 0;
|
|
180
|
+
switch (r) {
|
|
181
|
+
case "h":
|
|
182
|
+
a = n * 60 * 60 * 1e3;
|
|
183
|
+
break;
|
|
184
|
+
case "d":
|
|
185
|
+
a = n * 24 * 60 * 60 * 1e3;
|
|
186
|
+
break;
|
|
187
|
+
case "y":
|
|
188
|
+
a = n * 365 * 24 * 60 * 60 * 1e3;
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
return i + a;
|
|
107
192
|
}
|
|
108
193
|
}
|
|
109
|
-
const
|
|
110
|
-
class
|
|
111
|
-
#t = 0;
|
|
112
|
-
// displayed fps (stable)
|
|
194
|
+
const z = new Q(), l = z;
|
|
195
|
+
class Y {
|
|
113
196
|
#e = 0;
|
|
197
|
+
// displayed fps (stable)
|
|
198
|
+
#t = 0;
|
|
114
199
|
// EMA of ms/frame
|
|
115
200
|
#s = 0;
|
|
116
|
-
#i;
|
|
117
|
-
// weight of new samples (0..1)
|
|
118
201
|
#n;
|
|
202
|
+
// weight of new samples (0..1)
|
|
203
|
+
#r;
|
|
119
204
|
// minimum integer change to update displayed fps
|
|
120
|
-
constructor(
|
|
121
|
-
const s = Number(
|
|
122
|
-
this.#
|
|
123
|
-
const
|
|
124
|
-
this.#
|
|
205
|
+
constructor(e = 0.05, t = 1) {
|
|
206
|
+
const s = Number(e);
|
|
207
|
+
this.#n = Number.isFinite(s) ? Math.min(1, Math.max(1e-3, s)) : 0.05;
|
|
208
|
+
const n = Number(t);
|
|
209
|
+
this.#r = Number.isFinite(n) ? Math.max(0, Math.floor(n)) : 1;
|
|
125
210
|
}
|
|
126
211
|
now() {
|
|
127
|
-
const
|
|
128
|
-
return
|
|
212
|
+
const e = globalThis.performance;
|
|
213
|
+
return e && typeof e.now == "function" ? e.now() : Date.now();
|
|
129
214
|
}
|
|
130
215
|
calc() {
|
|
131
|
-
const
|
|
216
|
+
const e = this.now();
|
|
132
217
|
if (this.#s === 0)
|
|
133
|
-
return this.#s =
|
|
134
|
-
const
|
|
135
|
-
if (this.#s =
|
|
136
|
-
this.#
|
|
137
|
-
const s = 1e3 / this.#
|
|
138
|
-
if (!Number.isFinite(s) || s <= 0) return this.#
|
|
139
|
-
const
|
|
140
|
-
return this.#
|
|
218
|
+
return this.#s = e, this.#e;
|
|
219
|
+
const t = e - this.#s;
|
|
220
|
+
if (this.#s = e, !Number.isFinite(t) || t <= 0) return this.#e;
|
|
221
|
+
this.#t === 0 ? this.#t = t : this.#t = (1 - this.#n) * this.#t + this.#n * t;
|
|
222
|
+
const s = 1e3 / this.#t;
|
|
223
|
+
if (!Number.isFinite(s) || s <= 0) return this.#e;
|
|
224
|
+
const n = Math.round(s);
|
|
225
|
+
return this.#e !== 0 && this.#r > 0 && Math.abs(n - this.#e) < this.#r ? this.#e : (this.#e = n, this.#e);
|
|
141
226
|
}
|
|
142
227
|
reset() {
|
|
143
|
-
this.#
|
|
228
|
+
this.#e = 0, this.#t = 0, this.#s = 0;
|
|
144
229
|
}
|
|
145
230
|
}
|
|
146
|
-
class
|
|
147
|
-
constructor(
|
|
148
|
-
this._enabled = !0, this._show_date = !1, this._show_time = !0, this._debug = !1,
|
|
231
|
+
class Z {
|
|
232
|
+
constructor(e) {
|
|
233
|
+
this._enabled = !0, this._show_date = !1, this._show_time = !0, this._debug = !1, e && this.configure(e);
|
|
149
234
|
}
|
|
150
|
-
configure(
|
|
151
|
-
typeof
|
|
235
|
+
configure(e) {
|
|
236
|
+
typeof e._enabled == "boolean" && (this._enabled = e._enabled), typeof e._show_date == "boolean" && (this._show_date = e._show_date), typeof e._show_time == "boolean" && (this._show_time = e._show_time), typeof e._debug == "boolean" && (this._debug = e._debug);
|
|
152
237
|
}
|
|
153
238
|
_dt() {
|
|
154
|
-
const
|
|
155
|
-
return
|
|
239
|
+
const e = /* @__PURE__ */ new Date(), t = this._show_date ? `${e.getDate()}.${e.getMonth()}.${e.getFullYear()} ` : "", s = this._show_time ? `${e.getHours()}:${e.getMinutes()}:${e.getSeconds()}.${e.getMilliseconds()}|` : "";
|
|
240
|
+
return t + s;
|
|
156
241
|
}
|
|
157
|
-
log(
|
|
158
|
-
this._enabled && console.log(this._dt(),
|
|
242
|
+
log(e, ...t) {
|
|
243
|
+
this._enabled && console.log(this._dt(), e, ...t);
|
|
159
244
|
}
|
|
160
|
-
warn(
|
|
161
|
-
this._enabled && console.warn(this._dt(),
|
|
245
|
+
warn(e, ...t) {
|
|
246
|
+
this._enabled && console.warn(this._dt(), e, ...t);
|
|
162
247
|
}
|
|
163
|
-
error(
|
|
164
|
-
this._enabled && console.error(this._dt(),
|
|
248
|
+
error(e, ...t) {
|
|
249
|
+
this._enabled && console.error(this._dt(), e, ...t);
|
|
165
250
|
}
|
|
166
|
-
debug(
|
|
167
|
-
!this._enabled || !this._debug || console.debug(this._dt(),
|
|
251
|
+
debug(e, ...t) {
|
|
252
|
+
!this._enabled || !this._debug || console.debug(this._dt(), e, ...t);
|
|
168
253
|
}
|
|
169
254
|
}
|
|
170
|
-
const
|
|
171
|
-
|
|
255
|
+
const c = new Z(), G = typeof process < "u" && !!process?.env && process.env.NODE_ENV === "production";
|
|
256
|
+
G || console.info(
|
|
172
257
|
"[Xpell] _xlog is redirected to console in development mode. Tip: enable 'Show timestamps' in DevTools → Console for timed logs."
|
|
173
258
|
);
|
|
174
|
-
const
|
|
175
|
-
class
|
|
259
|
+
const j = G ? c : console;
|
|
260
|
+
class ee {
|
|
176
261
|
constructor() {
|
|
177
262
|
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 = {};
|
|
178
263
|
}
|
|
@@ -183,49 +268,49 @@ class A {
|
|
|
183
268
|
*/
|
|
184
269
|
get _o() {
|
|
185
270
|
return !this._compat_writes && !this._warn_legacy_writes ? this._objects : (this._o_proxy || (this._o_proxy = new Proxy(this._objects, {
|
|
186
|
-
set: (
|
|
187
|
-
const
|
|
271
|
+
set: (e, t, s) => {
|
|
272
|
+
const n = String(t);
|
|
188
273
|
return this._warn_legacy_writes && console.warn(
|
|
189
|
-
`[XData] Legacy write: _o["${
|
|
190
|
-
), this._compat_writes ? this.set(
|
|
274
|
+
`[XData] Legacy write: _o["${n}"] = ... ; prefer XData.set("${n}", value).`
|
|
275
|
+
), this._compat_writes ? this.set(n, s, { source: "legacy:_o" }) : e[n] = s, !0;
|
|
191
276
|
},
|
|
192
|
-
deleteProperty: (
|
|
193
|
-
const s = String(
|
|
277
|
+
deleteProperty: (e, t) => {
|
|
278
|
+
const s = String(t);
|
|
194
279
|
return this._warn_legacy_writes && console.warn(
|
|
195
280
|
`[XData] Legacy delete: delete _o["${s}"] ; prefer XData.delete("${s}").`
|
|
196
|
-
), this._compat_writes ? this.delete(s, { source: "legacy:_o" }) : delete
|
|
281
|
+
), this._compat_writes ? this.delete(s, { source: "legacy:_o" }) : delete e[s], !0;
|
|
197
282
|
}
|
|
198
283
|
})), this._o_proxy);
|
|
199
284
|
}
|
|
200
285
|
/** Preferred read API */
|
|
201
|
-
get(
|
|
202
|
-
return this._objects[
|
|
286
|
+
get(e) {
|
|
287
|
+
return this._objects[e];
|
|
203
288
|
}
|
|
204
289
|
/** Preferred write API */
|
|
205
|
-
set(
|
|
206
|
-
const
|
|
207
|
-
this._objects[
|
|
290
|
+
set(e, t, s) {
|
|
291
|
+
const n = this._objects[e];
|
|
292
|
+
this._objects[e] = t, this._emit({ key: e, value: t, prev: n, ts: Date.now(), op: "set", meta: s });
|
|
208
293
|
}
|
|
209
294
|
/** Shallow merge helper (nice for state objects) */
|
|
210
|
-
patch(
|
|
211
|
-
const
|
|
212
|
-
this._objects[
|
|
295
|
+
patch(e, t, s) {
|
|
296
|
+
const n = this._objects[e], i = { ...n && typeof n == "object" ? n : {}, ...t };
|
|
297
|
+
this._objects[e] = i, this._emit({ key: e, value: i, prev: n, ts: Date.now(), op: "patch", meta: s });
|
|
213
298
|
}
|
|
214
299
|
/** In-place mutation notifier */
|
|
215
|
-
touch(
|
|
216
|
-
const s = this._objects[
|
|
217
|
-
this._emit({ key:
|
|
300
|
+
touch(e, t) {
|
|
301
|
+
const s = this._objects[e];
|
|
302
|
+
this._emit({ key: e, value: s, prev: s, ts: Date.now(), op: "touch", meta: t });
|
|
218
303
|
}
|
|
219
|
-
has(
|
|
220
|
-
return Object.prototype.hasOwnProperty.call(this._objects,
|
|
304
|
+
has(e) {
|
|
305
|
+
return Object.prototype.hasOwnProperty.call(this._objects, e);
|
|
221
306
|
}
|
|
222
|
-
delete(
|
|
223
|
-
const s = this._objects[
|
|
224
|
-
delete this._objects[
|
|
307
|
+
delete(e, t) {
|
|
308
|
+
const s = this._objects[e];
|
|
309
|
+
delete this._objects[e], this._emit({ key: e, value: void 0, prev: s, ts: Date.now(), op: "delete", meta: t });
|
|
225
310
|
}
|
|
226
|
-
pick(
|
|
227
|
-
const s = this._objects[
|
|
228
|
-
return this.delete(
|
|
311
|
+
pick(e, t) {
|
|
312
|
+
const s = this._objects[e];
|
|
313
|
+
return this.delete(e, t), s;
|
|
229
314
|
}
|
|
230
315
|
clean() {
|
|
231
316
|
this._objects = {};
|
|
@@ -233,32 +318,32 @@ class A {
|
|
|
233
318
|
// ----------------------------
|
|
234
319
|
// Subscriptions
|
|
235
320
|
// ----------------------------
|
|
236
|
-
on(
|
|
237
|
-
let s = this._listeners.get(
|
|
238
|
-
return s || this._listeners.set(
|
|
321
|
+
on(e, t) {
|
|
322
|
+
let s = this._listeners.get(e);
|
|
323
|
+
return s || this._listeners.set(e, s = /* @__PURE__ */ new Set()), s.add(t), () => this.off(e, t);
|
|
239
324
|
}
|
|
240
|
-
off(
|
|
241
|
-
const s = this._listeners.get(
|
|
242
|
-
s && (s.delete(
|
|
325
|
+
off(e, t) {
|
|
326
|
+
const s = this._listeners.get(e);
|
|
327
|
+
s && (s.delete(t), s.size === 0 && this._listeners.delete(e));
|
|
243
328
|
}
|
|
244
|
-
onAny(
|
|
245
|
-
return this._any_listeners.add(
|
|
329
|
+
onAny(e) {
|
|
330
|
+
return this._any_listeners.add(e), () => this._any_listeners.delete(e);
|
|
246
331
|
}
|
|
247
332
|
// ----------------------------
|
|
248
333
|
// Emit
|
|
249
334
|
// ----------------------------
|
|
250
|
-
_emit(
|
|
251
|
-
this._verbose &&
|
|
252
|
-
const
|
|
253
|
-
if (
|
|
254
|
-
for (const s of this._any_listeners) s(
|
|
335
|
+
_emit(e) {
|
|
336
|
+
this._verbose && e.meta?.trace && (e.stack = new Error().stack);
|
|
337
|
+
const t = this._listeners.get(e.key);
|
|
338
|
+
if (t) for (const s of t) s(e);
|
|
339
|
+
for (const s of this._any_listeners) s(e);
|
|
255
340
|
}
|
|
256
341
|
}
|
|
257
|
-
const
|
|
258
|
-
class
|
|
259
|
-
constructor(
|
|
260
|
-
|
|
261
|
-
this[
|
|
342
|
+
const x = new ee(), f = x;
|
|
343
|
+
class I {
|
|
344
|
+
constructor(e) {
|
|
345
|
+
e && Object.keys(e).forEach((t) => {
|
|
346
|
+
this[t] = e[t];
|
|
262
347
|
}), this.d || (this.d = Date.now());
|
|
263
348
|
}
|
|
264
349
|
/**
|
|
@@ -271,84 +356,84 @@ class x {
|
|
|
271
356
|
* @param defaultValue the default value if none above exists
|
|
272
357
|
* @returns {any} the actual parameter value
|
|
273
358
|
*/
|
|
274
|
-
getParam(
|
|
275
|
-
return this._params?.hasOwnProperty(
|
|
359
|
+
getParam(e, t, s) {
|
|
360
|
+
return this._params?.hasOwnProperty(t) ? this._params[t] : this._params?.hasOwnProperty(e) ? this._params[e] : s;
|
|
276
361
|
}
|
|
277
362
|
}
|
|
278
|
-
const
|
|
363
|
+
const X = {
|
|
279
364
|
type: "_type",
|
|
280
365
|
children: "_children"
|
|
281
|
-
},
|
|
366
|
+
}, b = class b {
|
|
282
367
|
/**
|
|
283
368
|
* Adds HTML-Xpell Mapping item
|
|
284
369
|
* @param htmlElement HTML element to change from
|
|
285
370
|
* @param xpellElement Xpell element to change to
|
|
286
371
|
*/
|
|
287
|
-
static addHtml2XpellMapItem(
|
|
288
|
-
|
|
372
|
+
static addHtml2XpellMapItem(e, t) {
|
|
373
|
+
b.html2XMap.elements[e] = t;
|
|
289
374
|
}
|
|
290
375
|
/**
|
|
291
376
|
* convert text command to Xpell json command
|
|
292
377
|
* @param {string} txt
|
|
293
378
|
*/
|
|
294
|
-
static parse(
|
|
295
|
-
const s =
|
|
296
|
-
let
|
|
297
|
-
if (
|
|
298
|
-
for (let
|
|
299
|
-
const
|
|
300
|
-
if (
|
|
301
|
-
const _ =
|
|
302
|
-
|
|
379
|
+
static parse(e, t) {
|
|
380
|
+
const s = e.split(" ");
|
|
381
|
+
let n = new I();
|
|
382
|
+
if (t ? (n._module = t, n._op = s[0]) : (n._module = s[0], n._op = s[1]), n._params = {}, s.length > 1)
|
|
383
|
+
for (let r = 2; r < s.length; ++r) {
|
|
384
|
+
const i = s[r];
|
|
385
|
+
if (i.indexOf(":") > -1) {
|
|
386
|
+
const _ = i.split(":");
|
|
387
|
+
n._params[_[0]] = _[1];
|
|
303
388
|
} else
|
|
304
|
-
|
|
389
|
+
n._params[r - 1] = s[r];
|
|
305
390
|
}
|
|
306
|
-
return
|
|
391
|
+
return n;
|
|
307
392
|
}
|
|
308
|
-
static replaceSpacesInQuotes(
|
|
309
|
-
return
|
|
310
|
-
const
|
|
311
|
-
return `${
|
|
393
|
+
static replaceSpacesInQuotes(e, t = "_%20_") {
|
|
394
|
+
return e.replace(/(['"])(.*?)\1/g, (s, n, r) => {
|
|
395
|
+
const i = String(r).replace(/\s/g, t);
|
|
396
|
+
return `${n}${i}${n}`;
|
|
312
397
|
});
|
|
313
398
|
}
|
|
314
|
-
static parseObjectCommand(
|
|
315
|
-
|
|
316
|
-
const s =
|
|
317
|
-
if (!
|
|
318
|
-
let
|
|
319
|
-
if (s[0]?.startsWith("#") && (
|
|
399
|
+
static parseObjectCommand(e, t) {
|
|
400
|
+
e = b.replaceSpacesInQuotes(e);
|
|
401
|
+
const s = e.trim().split(/\s+/), n = t || s.shift();
|
|
402
|
+
if (!n) throw new Error("Missing module name");
|
|
403
|
+
let r;
|
|
404
|
+
if (s[0]?.startsWith("#") && (r = s.shift().slice(1), !r))
|
|
320
405
|
throw new Error("Invalid object selector '#'. Use '#<id>'");
|
|
321
|
-
const
|
|
322
|
-
if (!
|
|
323
|
-
const
|
|
406
|
+
const i = s.shift();
|
|
407
|
+
if (!i) throw new Error("Missing operation");
|
|
408
|
+
const a = {};
|
|
324
409
|
let _ = null, h = null;
|
|
325
|
-
if (s.forEach((
|
|
410
|
+
if (s.forEach((u) => {
|
|
326
411
|
if (h) {
|
|
327
|
-
if (h += ` ${
|
|
412
|
+
if (h += ` ${u}`, u.endsWith(h[0])) {
|
|
328
413
|
const m = h.slice(1, -1).replace(/_%20_/g, " ");
|
|
329
|
-
|
|
414
|
+
a[_] = m, h = null;
|
|
330
415
|
}
|
|
331
416
|
return;
|
|
332
417
|
}
|
|
333
|
-
if (
|
|
334
|
-
if (h =
|
|
335
|
-
const m =
|
|
336
|
-
|
|
418
|
+
if (u.startsWith('"') || u.startsWith("'")) {
|
|
419
|
+
if (h = u, u.endsWith(u[0]) && u.length > 1) {
|
|
420
|
+
const m = u.slice(1, -1).replace(/_%20_/g, " ");
|
|
421
|
+
a[_] = m, h = null;
|
|
337
422
|
}
|
|
338
423
|
return;
|
|
339
424
|
}
|
|
340
|
-
if (
|
|
341
|
-
const m =
|
|
342
|
-
|
|
425
|
+
if (u.includes(":")) {
|
|
426
|
+
const m = u.split(":"), O = m[0], H = m.slice(1).join(":").replace(/_%20_/g, " ");
|
|
427
|
+
a[O] = H, _ = null;
|
|
343
428
|
return;
|
|
344
429
|
}
|
|
345
|
-
_ =
|
|
430
|
+
_ = u.replace(/_%20_/g, " ");
|
|
346
431
|
}), h) throw new Error("Unclosed quoted parameter value");
|
|
347
432
|
return {
|
|
348
|
-
_module:
|
|
349
|
-
_object:
|
|
350
|
-
_op:
|
|
351
|
-
_params:
|
|
433
|
+
_module: n,
|
|
434
|
+
_object: r,
|
|
435
|
+
_op: i,
|
|
436
|
+
_params: a
|
|
352
437
|
};
|
|
353
438
|
}
|
|
354
439
|
/**
|
|
@@ -356,9 +441,9 @@ const w = {
|
|
|
356
441
|
* @param xmlString XML string
|
|
357
442
|
* @returns
|
|
358
443
|
*/
|
|
359
|
-
static xmlString2Xpell(
|
|
360
|
-
const s = new DOMParser().parseFromString(
|
|
361
|
-
return s.childNodes.length > 0 ?
|
|
444
|
+
static xmlString2Xpell(e) {
|
|
445
|
+
const s = new DOMParser().parseFromString(e, "text/xml");
|
|
446
|
+
return s.childNodes.length > 0 ? b.xml2Xpell(s.childNodes[0]) : {};
|
|
362
447
|
}
|
|
363
448
|
/**
|
|
364
449
|
* Converts XML/HTML Document to Xpell JSON
|
|
@@ -366,26 +451,26 @@ const w = {
|
|
|
366
451
|
* @param forceXhtml force Xpell XHTML for every unknown object
|
|
367
452
|
* @returns {} Xpell JSON
|
|
368
453
|
*/
|
|
369
|
-
static xml2Xpell(
|
|
370
|
-
const s =
|
|
371
|
-
let
|
|
372
|
-
|
|
373
|
-
const
|
|
374
|
-
let
|
|
375
|
-
if (
|
|
376
|
-
for (let _ = 0; _ <
|
|
377
|
-
const h =
|
|
378
|
-
|
|
454
|
+
static xml2Xpell(e, t) {
|
|
455
|
+
const s = b.html2XMap;
|
|
456
|
+
let n = {};
|
|
457
|
+
n._children = [];
|
|
458
|
+
const r = e.nodeName, i = e.nodeName;
|
|
459
|
+
let a = t;
|
|
460
|
+
if (t ? (n[X.type] = "xhtml", n._html_ns = "http://www.w3.org/2000/svg") : n._type = s.elements[r] ? s.elements[r] : r, e.attributes)
|
|
461
|
+
for (let _ = 0; _ < e.attributes.length; ++_) {
|
|
462
|
+
const h = e.attributes[_], u = s.attributes[h.name] ? s.attributes[h.name] : h.name;
|
|
463
|
+
n[u] = h.value;
|
|
379
464
|
}
|
|
380
|
-
if (
|
|
381
|
-
for (let _ = 0; _ <
|
|
382
|
-
const h =
|
|
383
|
-
h.nodeName.startsWith("#") ||
|
|
465
|
+
if (e?.firstChild?.nodeValue && (n.text = e?.firstChild.nodeValue.trim()), n[X.type] == "xhtml" ? n._html_tag = i : n[X.type] == "svg" && (a = !0, n._html_ns = "http://www.w3.org/2000/svg"), e?.childNodes.length > 0)
|
|
466
|
+
for (let _ = 0; _ < e.childNodes.length; ++_) {
|
|
467
|
+
const h = e.childNodes[_];
|
|
468
|
+
h.nodeName.startsWith("#") || n[X.children].push(b.xml2Xpell(h, a));
|
|
384
469
|
}
|
|
385
|
-
return
|
|
470
|
+
return n;
|
|
386
471
|
}
|
|
387
472
|
};
|
|
388
|
-
|
|
473
|
+
b.html2XMap = {
|
|
389
474
|
elements: {
|
|
390
475
|
div: "view",
|
|
391
476
|
a: "link",
|
|
@@ -415,189 +500,201 @@ f.html2XMap = {
|
|
|
415
500
|
id: "_id"
|
|
416
501
|
}
|
|
417
502
|
};
|
|
418
|
-
let
|
|
419
|
-
class
|
|
420
|
-
constructor() {
|
|
421
|
-
this._log_rules = {
|
|
422
|
-
register: !1,
|
|
423
|
-
remove: !1,
|
|
424
|
-
fire: !1
|
|
425
|
-
}, this._events = {}, this._listener_index = {};
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Register a listener on an event name (runtime bus only).
|
|
429
|
-
*
|
|
430
|
-
* Backward compatible:
|
|
431
|
-
* - Canonical: on(name, cb, { _once, _owner, _tag })
|
|
432
|
-
* - Legacy: on(name, cb, { _once }, owner)
|
|
433
|
-
*/
|
|
434
|
-
on(t, e, s = {}, i) {
|
|
435
|
-
this._events[t] || (this._events[t] = []);
|
|
436
|
-
const n = s?._owner ?? i, r = p.guid(), c = {
|
|
437
|
-
_id: r,
|
|
438
|
-
_callback: e,
|
|
439
|
-
_options: s,
|
|
440
|
-
_owner: n,
|
|
441
|
-
_tag: s?._tag
|
|
442
|
-
};
|
|
443
|
-
return this._events[t].push(c), this._listener_index[r] = t, this._log_rules.register && y.log("XEM Register", t, r), r;
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* Register a listener that will be removed after first fire.
|
|
447
|
-
*/
|
|
448
|
-
once(t, e, s) {
|
|
449
|
-
return this.on(t, e, { _once: !0, _owner: s });
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* Fire an event with optional payload.
|
|
453
|
-
*/
|
|
454
|
-
async fire(t, e) {
|
|
455
|
-
const s = this._events[t];
|
|
456
|
-
if (!s || s.length === 0) return;
|
|
457
|
-
this._log_rules.fire && y.log("XEM Fire", t, e);
|
|
458
|
-
const i = s.slice(), n = [];
|
|
459
|
-
for (const r of i) {
|
|
460
|
-
try {
|
|
461
|
-
r && r._callback && r._callback(e);
|
|
462
|
-
} catch (c) {
|
|
463
|
-
y.error(c);
|
|
464
|
-
}
|
|
465
|
-
r?._options?._once && n.push(r._id);
|
|
466
|
-
}
|
|
467
|
-
for (const r of n) this.remove(r);
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* Remove a listener by id.
|
|
471
|
-
*/
|
|
472
|
-
remove(t) {
|
|
473
|
-
const e = this._listener_index[t];
|
|
474
|
-
if (!e) return;
|
|
475
|
-
const s = this._events[e];
|
|
476
|
-
if (s && s.length) {
|
|
477
|
-
const i = s.findIndex((n) => n?._id === t);
|
|
478
|
-
i >= 0 && s.splice(i, 1), s.length === 0 && delete this._events[e];
|
|
479
|
-
}
|
|
480
|
-
delete this._listener_index[t], this._log_rules.remove && y.log("XEM Remove", e, t);
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Remove all listeners for a given owner reference.
|
|
484
|
-
*/
|
|
485
|
-
removeOwner(t) {
|
|
486
|
-
if (!t) return;
|
|
487
|
-
const e = [];
|
|
488
|
-
for (const s of Object.values(this._events))
|
|
489
|
-
for (const i of s)
|
|
490
|
-
(i?._owner ?? i?._options?._owner) === t && e.push(i._id);
|
|
491
|
-
e.forEach((s) => this.remove(s));
|
|
492
|
-
}
|
|
493
|
-
/**
|
|
494
|
-
* Clear the entire event bus (mostly for tests / hard reset).
|
|
495
|
-
*/
|
|
496
|
-
clear() {
|
|
497
|
-
this._events = {}, this._listener_index = {};
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
const b = new $();
|
|
501
|
-
class R {
|
|
502
|
-
#t;
|
|
503
|
+
let w = b;
|
|
504
|
+
class te {
|
|
503
505
|
#e;
|
|
506
|
+
#t;
|
|
504
507
|
#s;
|
|
505
508
|
constructor() {
|
|
506
|
-
this.#
|
|
509
|
+
this.#e = {}, this.#t = {}, this.#s = {};
|
|
507
510
|
}
|
|
508
511
|
get _objects() {
|
|
509
|
-
return this.#
|
|
512
|
+
return this.#t;
|
|
510
513
|
}
|
|
511
514
|
/**
|
|
512
515
|
* Checks if an object is found in the object manager
|
|
513
516
|
* @param xObjectId
|
|
514
517
|
* @returns
|
|
515
518
|
*/
|
|
516
|
-
hasObject(
|
|
517
|
-
return this.#
|
|
519
|
+
hasObject(e) {
|
|
520
|
+
return this.#t.hasOwnProperty(e);
|
|
518
521
|
}
|
|
519
522
|
/**
|
|
520
523
|
* Register multiple classes dictionary into the object manager
|
|
521
524
|
* @param xObjects - key value list -> \{"view":XView,...\}
|
|
522
525
|
*/
|
|
523
|
-
registerObjects(
|
|
524
|
-
Object.keys(
|
|
526
|
+
registerObjects(e) {
|
|
527
|
+
Object.keys(e).forEach((s) => this.registerObject(s, e[s]));
|
|
525
528
|
}
|
|
526
529
|
/**
|
|
527
530
|
* Registers single XObject
|
|
528
531
|
* @param name - name of the object
|
|
529
532
|
* @param xObjects The object class
|
|
530
533
|
*/
|
|
531
|
-
registerObject(
|
|
532
|
-
this.#
|
|
534
|
+
registerObject(e, t) {
|
|
535
|
+
this.#e[e] = t;
|
|
533
536
|
}
|
|
534
537
|
/**
|
|
535
538
|
* Checks if a class (name) is found in the object manager classes dictionary
|
|
536
539
|
* @param name - class name
|
|
537
540
|
* @returns {boolean}
|
|
538
541
|
*/
|
|
539
|
-
hasObjectClass(
|
|
540
|
-
return this.#
|
|
542
|
+
hasObjectClass(e) {
|
|
543
|
+
return this.#e.hasOwnProperty(e);
|
|
541
544
|
}
|
|
542
545
|
/**
|
|
543
546
|
* Retrieves XObject class instance
|
|
544
547
|
* @param name class name
|
|
545
548
|
* @returns {XObject}
|
|
546
549
|
*/
|
|
547
|
-
getObjectClass(
|
|
548
|
-
return this.#
|
|
550
|
+
getObjectClass(e) {
|
|
551
|
+
return this.#e[e];
|
|
549
552
|
}
|
|
550
553
|
/**
|
|
551
554
|
* Retrieves all the classes dictionary
|
|
552
555
|
* @returns XObjectManagerIndex
|
|
556
|
+
* @deprecated use getObjectClasses() instead
|
|
553
557
|
*/
|
|
554
558
|
getAllClasses() {
|
|
555
|
-
return this
|
|
559
|
+
return this.getObjectClasses();
|
|
560
|
+
}
|
|
561
|
+
getObjectClasses() {
|
|
562
|
+
return this.#e;
|
|
556
563
|
}
|
|
557
564
|
get _classes() {
|
|
558
|
-
return this.#
|
|
565
|
+
return this.#e;
|
|
559
566
|
}
|
|
560
567
|
/**
|
|
561
568
|
* Add XObject instance to the manager
|
|
562
569
|
* @param xObject XObject to maintain
|
|
563
570
|
*/
|
|
564
|
-
addObject(
|
|
565
|
-
|
|
571
|
+
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) : c.log("unable to add object");
|
|
566
573
|
}
|
|
567
574
|
/**
|
|
568
575
|
* Remove XObject from the manager
|
|
569
576
|
* @param xObjectId object id to remove
|
|
570
577
|
*/
|
|
571
|
-
removeObject(
|
|
572
|
-
const
|
|
573
|
-
|
|
578
|
+
removeObject(e) {
|
|
579
|
+
const t = this.#t[e];
|
|
580
|
+
t && (delete this.#s[t?._name], delete this.#t[e]);
|
|
574
581
|
}
|
|
575
582
|
/**
|
|
576
583
|
* Retrieves XObject instance
|
|
577
584
|
* @param xObjectId XObject id
|
|
578
585
|
* @returns {XObject}
|
|
579
586
|
*/
|
|
580
|
-
getObject(
|
|
581
|
-
return this.#e
|
|
587
|
+
getObject(e) {
|
|
588
|
+
return this.#t[e];
|
|
582
589
|
}
|
|
583
590
|
/**
|
|
584
591
|
* alias to getObject
|
|
585
592
|
* @param id
|
|
586
593
|
* @returns
|
|
587
594
|
*/
|
|
588
|
-
go(
|
|
589
|
-
return this.getObject(
|
|
595
|
+
go(e) {
|
|
596
|
+
return this.getObject(e);
|
|
590
597
|
}
|
|
591
598
|
/**
|
|
592
599
|
* Retrieves XObject instance
|
|
593
600
|
* @param objectName XObject name
|
|
594
601
|
* @returns {XObject}
|
|
595
602
|
*/
|
|
596
|
-
getObjectByName(
|
|
597
|
-
return this.#s[
|
|
603
|
+
getObjectByName(e) {
|
|
604
|
+
return this.#s[e] ? this.getObject(this.#s[e]) : null;
|
|
598
605
|
}
|
|
599
606
|
}
|
|
600
|
-
|
|
607
|
+
class ue {
|
|
608
|
+
constructor() {
|
|
609
|
+
this._log_rules = {
|
|
610
|
+
register: !1,
|
|
611
|
+
remove: !1,
|
|
612
|
+
fire: !1
|
|
613
|
+
}, this._events = {}, this._listener_index = {};
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Register a listener on an event name (runtime bus only).
|
|
617
|
+
*
|
|
618
|
+
* Backward compatible:
|
|
619
|
+
* - Canonical: on(name, cb, { _once, _owner, _tag })
|
|
620
|
+
* - Legacy: on(name, cb, { _once }, owner)
|
|
621
|
+
*/
|
|
622
|
+
on(e, t, s = {}, n) {
|
|
623
|
+
this._events[e] || (this._events[e] = []);
|
|
624
|
+
const r = s?._owner ?? n, i = l.guid(), a = {
|
|
625
|
+
_id: i,
|
|
626
|
+
_callback: t,
|
|
627
|
+
_options: s,
|
|
628
|
+
_owner: r,
|
|
629
|
+
_tag: s?._tag
|
|
630
|
+
};
|
|
631
|
+
return this._events[e].push(a), this._listener_index[i] = e, this._log_rules.register && j.log("XEM Register", e, i), i;
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Register a listener that will be removed after first fire.
|
|
635
|
+
*/
|
|
636
|
+
once(e, t, s) {
|
|
637
|
+
return this.on(e, t, { _once: !0, _owner: s });
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Fire an event with optional payload.
|
|
641
|
+
*/
|
|
642
|
+
async fire(e, t) {
|
|
643
|
+
const s = this._events[e];
|
|
644
|
+
if (!s || s.length === 0) return;
|
|
645
|
+
this._log_rules.fire && j.log("XEM Fire", e, t);
|
|
646
|
+
const n = s.slice(), r = [];
|
|
647
|
+
for (const i of n) {
|
|
648
|
+
try {
|
|
649
|
+
i && i._callback && i._callback(t);
|
|
650
|
+
} catch (a) {
|
|
651
|
+
j.error(a);
|
|
652
|
+
}
|
|
653
|
+
i?._options?._once && r.push(i._id);
|
|
654
|
+
}
|
|
655
|
+
for (const i of r) this.remove(i);
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Remove a listener by id.
|
|
659
|
+
*/
|
|
660
|
+
remove(e) {
|
|
661
|
+
const t = this._listener_index[e];
|
|
662
|
+
if (!t) return;
|
|
663
|
+
const s = this._events[t];
|
|
664
|
+
if (s && s.length) {
|
|
665
|
+
const n = s.findIndex((r) => r?._id === e);
|
|
666
|
+
n >= 0 && s.splice(n, 1), s.length === 0 && delete this._events[t];
|
|
667
|
+
}
|
|
668
|
+
delete this._listener_index[e], this._log_rules.remove && j.log("XEM Remove", t, e);
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* Remove all listeners for a given owner reference.
|
|
672
|
+
*/
|
|
673
|
+
removeOwner(e) {
|
|
674
|
+
if (!e) return;
|
|
675
|
+
const t = [];
|
|
676
|
+
for (const s of Object.values(this._events))
|
|
677
|
+
for (const n of s)
|
|
678
|
+
(n?._owner ?? n?._options?._owner) === e && t.push(n._id);
|
|
679
|
+
t.forEach((s) => this.remove(s));
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Clear the entire event bus (mostly for tests / hard reset).
|
|
683
|
+
*/
|
|
684
|
+
clear() {
|
|
685
|
+
this._events = {}, this._listener_index = {};
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
let P;
|
|
689
|
+
function de(o) {
|
|
690
|
+
P = o;
|
|
691
|
+
}
|
|
692
|
+
function D() {
|
|
693
|
+
if (!P)
|
|
694
|
+
throw new Error("XEventManager not set");
|
|
695
|
+
return P;
|
|
696
|
+
}
|
|
697
|
+
const se = [
|
|
601
698
|
"_nano_commands",
|
|
602
699
|
"_cache_cmd_txt",
|
|
603
700
|
"_cache_jcmd",
|
|
@@ -606,106 +703,297 @@ const N = [
|
|
|
606
703
|
"_parent",
|
|
607
704
|
"_children"
|
|
608
705
|
];
|
|
609
|
-
function
|
|
610
|
-
return
|
|
706
|
+
function E(o) {
|
|
707
|
+
return se.includes(o);
|
|
611
708
|
}
|
|
612
|
-
function
|
|
709
|
+
function J(o) {
|
|
613
710
|
if (!o || typeof o != "object" || Array.isArray(o)) return !1;
|
|
614
|
-
const
|
|
615
|
-
return
|
|
711
|
+
const e = Object.getPrototypeOf(o);
|
|
712
|
+
return e === Object.prototype || e === null;
|
|
616
713
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
o
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
714
|
+
function g(o, e) {
|
|
715
|
+
return o._skill = e, o.getSkill = () => e, o;
|
|
716
|
+
}
|
|
717
|
+
const V = {
|
|
718
|
+
info: g(
|
|
719
|
+
(o, e) => {
|
|
720
|
+
c.log("XObject id " + e?._id);
|
|
721
|
+
},
|
|
722
|
+
{
|
|
723
|
+
_name: "info",
|
|
724
|
+
_scope: "object",
|
|
725
|
+
_description: "Logs the current object's id."
|
|
726
|
+
}
|
|
727
|
+
),
|
|
728
|
+
log: g(
|
|
729
|
+
(o, e) => {
|
|
730
|
+
o._params && o._params[1] ? c.log(o._params[1]) : c.log(e);
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
_name: "log",
|
|
734
|
+
_scope: "object",
|
|
735
|
+
_description: "Logs a message or the current object.",
|
|
736
|
+
_params: {
|
|
737
|
+
1: "Optional message to log."
|
|
637
738
|
}
|
|
638
|
-
t[e] = s;
|
|
639
739
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
740
|
+
),
|
|
741
|
+
fire: g(
|
|
742
|
+
(o, e) => {
|
|
743
|
+
o._params && o._params[1] ? D().fire(
|
|
744
|
+
String(o._params[1]),
|
|
745
|
+
o._params[2]
|
|
746
|
+
) : o._params && o._params.event && D().fire(
|
|
747
|
+
String(o._params.event),
|
|
748
|
+
o._params.data
|
|
749
|
+
);
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
_name: "fire",
|
|
753
|
+
_scope: "object",
|
|
754
|
+
_description: "Fires an XEventManager event.",
|
|
755
|
+
_params: {
|
|
756
|
+
event: "Event name.",
|
|
757
|
+
data: "Optional event payload.",
|
|
758
|
+
1: "Event name shorthand.",
|
|
759
|
+
2: "Event payload shorthand."
|
|
760
|
+
},
|
|
761
|
+
_example: {
|
|
762
|
+
_op: "fire",
|
|
763
|
+
_params: {
|
|
764
|
+
event: "user:login",
|
|
765
|
+
data: {
|
|
766
|
+
source: "button"
|
|
767
|
+
}
|
|
768
|
+
}
|
|
648
769
|
}
|
|
649
|
-
delete t[e];
|
|
650
770
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
771
|
+
),
|
|
772
|
+
noop: g(
|
|
773
|
+
() => {
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
_name: "noop",
|
|
777
|
+
_scope: "object",
|
|
778
|
+
_description: "No-op command. Useful as a placeholder in sequences."
|
|
659
779
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
780
|
+
),
|
|
781
|
+
"set-field": g(
|
|
782
|
+
(o, e) => {
|
|
783
|
+
const t = o._params?.name, s = o._params?.value;
|
|
784
|
+
if (!(!e || typeof t != "string" || t.length === 0)) {
|
|
785
|
+
if (E(t)) {
|
|
786
|
+
c.error(`set-field denied for protected field: ${t}`);
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
e[t] = s;
|
|
790
|
+
}
|
|
791
|
+
},
|
|
792
|
+
{
|
|
793
|
+
_name: "set-field",
|
|
794
|
+
_scope: "object",
|
|
795
|
+
_description: "Sets a runtime field directly on the current object.",
|
|
796
|
+
_params: {
|
|
797
|
+
name: "Field name.",
|
|
798
|
+
value: "Value to assign."
|
|
799
|
+
},
|
|
800
|
+
_example: {
|
|
801
|
+
_op: "set-field",
|
|
802
|
+
_params: {
|
|
803
|
+
name: "_text",
|
|
804
|
+
value: "Hello"
|
|
805
|
+
}
|
|
806
|
+
}
|
|
670
807
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
808
|
+
),
|
|
809
|
+
"delete-field": g(
|
|
810
|
+
(o, e) => {
|
|
811
|
+
const t = o._params?.name;
|
|
812
|
+
if (!(!e || typeof t != "string" || t.length === 0)) {
|
|
813
|
+
if (E(t)) {
|
|
814
|
+
c.error(`delete-field denied for protected field: ${t}`);
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
delete e[t];
|
|
818
|
+
}
|
|
819
|
+
},
|
|
820
|
+
{
|
|
821
|
+
_name: "delete-field",
|
|
822
|
+
_scope: "object",
|
|
823
|
+
_description: "Deletes a runtime field from the current object.",
|
|
824
|
+
_params: {
|
|
825
|
+
name: "Field name to delete."
|
|
826
|
+
}
|
|
674
827
|
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
828
|
+
),
|
|
829
|
+
"toggle-field": g(
|
|
830
|
+
(o, e) => {
|
|
831
|
+
const t = o._params?.name;
|
|
832
|
+
if (!e || typeof t != "string" || t.length === 0) return;
|
|
833
|
+
if (E(t)) {
|
|
834
|
+
c.error(`toggle-field denied for protected field: ${t}`);
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
const s = e[t];
|
|
838
|
+
typeof s == "boolean" ? e[t] = !s : s == null ? e[t] = !0 : e[t] = !1;
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
_name: "toggle-field",
|
|
842
|
+
_scope: "object",
|
|
843
|
+
_description: "Toggles a runtime field using boolean-first semantics.",
|
|
844
|
+
_params: {
|
|
845
|
+
name: "Field name to toggle."
|
|
846
|
+
}
|
|
685
847
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
848
|
+
),
|
|
849
|
+
merge: g(
|
|
850
|
+
(o, e) => {
|
|
851
|
+
const t = o._params?.name, s = o._params?.value;
|
|
852
|
+
if (!e || typeof t != "string" || t.length === 0) return;
|
|
853
|
+
if (E(t)) {
|
|
854
|
+
c.error(`merge denied for protected field: ${t}`);
|
|
855
|
+
return;
|
|
690
856
|
}
|
|
691
|
-
if (s
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
857
|
+
if (!J(s)) {
|
|
858
|
+
c.error("merge expects _params.value as a plain object");
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
const n = e[t];
|
|
862
|
+
J(n) || (e[t] = {}), Object.assign(e[t], s);
|
|
863
|
+
},
|
|
864
|
+
{
|
|
865
|
+
_name: "merge",
|
|
866
|
+
_scope: "object",
|
|
867
|
+
_description: "Shallow-merges a plain object into a target object field.",
|
|
868
|
+
_params: {
|
|
869
|
+
name: "Target field name.",
|
|
870
|
+
value: "Plain object to merge."
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
),
|
|
874
|
+
"run-seq": g(
|
|
875
|
+
async (o, e) => {
|
|
876
|
+
if (!e) return;
|
|
877
|
+
const t = o._params?.seq;
|
|
878
|
+
if (!Array.isArray(t)) {
|
|
879
|
+
c.error("run-seq expects _params.seq as an array");
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
for (const s of t) {
|
|
883
|
+
if (typeof s == "string") {
|
|
884
|
+
await e.run(`${e._id} ${s}`);
|
|
885
|
+
continue;
|
|
886
|
+
}
|
|
887
|
+
if (s && typeof s == "object" && s._op) {
|
|
888
|
+
const n = s._object;
|
|
889
|
+
if (!(n == null || n === "this" || n === e._id)) {
|
|
890
|
+
c.error("run-seq rejected non-self _object target");
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
const i = {
|
|
894
|
+
_op: s._op,
|
|
895
|
+
_params: s._params ? { ...s._params } : void 0
|
|
896
|
+
};
|
|
897
|
+
await e.execute(i);
|
|
898
|
+
continue;
|
|
899
|
+
}
|
|
900
|
+
c.error(
|
|
901
|
+
"run-seq skipped invalid step; expected string or object with _op"
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
},
|
|
905
|
+
{
|
|
906
|
+
_name: "run-seq",
|
|
907
|
+
_scope: "object",
|
|
908
|
+
_description: "Runs a sequence of local nano-command steps in strict order.",
|
|
909
|
+
_params: {
|
|
910
|
+
seq: "Array of command strings or local command objects."
|
|
911
|
+
},
|
|
912
|
+
_example: {
|
|
913
|
+
_op: "run-seq",
|
|
914
|
+
_params: {
|
|
915
|
+
seq: [
|
|
916
|
+
{
|
|
917
|
+
_op: "set-field",
|
|
918
|
+
_params: {
|
|
919
|
+
name: "_debug",
|
|
920
|
+
value: !0
|
|
921
|
+
}
|
|
922
|
+
},
|
|
923
|
+
{
|
|
924
|
+
_op: "log",
|
|
925
|
+
_params: {
|
|
926
|
+
1: "Debug enabled"
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
]
|
|
696
930
|
}
|
|
697
|
-
const r = {
|
|
698
|
-
_op: s._op,
|
|
699
|
-
_params: s._params ? { ...s._params } : void 0
|
|
700
|
-
};
|
|
701
|
-
await t.execute(r);
|
|
702
|
-
continue;
|
|
703
931
|
}
|
|
704
|
-
a.error("run-seq skipped invalid step; expected string or object with _op");
|
|
705
932
|
}
|
|
706
|
-
|
|
707
|
-
}
|
|
708
|
-
|
|
933
|
+
)
|
|
934
|
+
};
|
|
935
|
+
let $;
|
|
936
|
+
function ne(o) {
|
|
937
|
+
$ = o;
|
|
938
|
+
}
|
|
939
|
+
function re() {
|
|
940
|
+
if (!$)
|
|
941
|
+
throw new Error("XRuntime not set");
|
|
942
|
+
return $;
|
|
943
|
+
}
|
|
944
|
+
const R = {
|
|
945
|
+
_id: "xobject",
|
|
946
|
+
_title: "XObject Core Runtime Contract",
|
|
947
|
+
_version: "1.0.0",
|
|
948
|
+
_active: !0,
|
|
949
|
+
_type: "runtime-api-skill",
|
|
950
|
+
_description: "Base runtime object for identity, typing, composition, lifecycle hooks, events, data binding, and nano-command execution.",
|
|
951
|
+
_fields: {
|
|
952
|
+
_id: "Unique object id.",
|
|
953
|
+
_type: "Registered runtime object type.",
|
|
954
|
+
_name: "Optional object name.",
|
|
955
|
+
_children: "Child objects/data.",
|
|
956
|
+
_data_source: "XData key to bind this object to.",
|
|
957
|
+
_on: "Event handlers map.",
|
|
958
|
+
_once: "One-time event handlers map.",
|
|
959
|
+
_on_create: "Lifecycle handler after object creation.",
|
|
960
|
+
_on_mount: "Lifecycle handler after mount.",
|
|
961
|
+
_on_frame: "Frame lifecycle handler.",
|
|
962
|
+
_on_data: "Data-source lifecycle handler.",
|
|
963
|
+
_process_frame: "Enable/disable frame processing.",
|
|
964
|
+
_process_data: "Enable/disable data-source processing.",
|
|
965
|
+
_debug: "Enable object debug logs."
|
|
966
|
+
},
|
|
967
|
+
_exports: {
|
|
968
|
+
_xui_fields: [
|
|
969
|
+
"_id",
|
|
970
|
+
"_type",
|
|
971
|
+
"_name",
|
|
972
|
+
"_children",
|
|
973
|
+
"_data_source",
|
|
974
|
+
"_on",
|
|
975
|
+
"_once",
|
|
976
|
+
"_on_create",
|
|
977
|
+
"_on_mount",
|
|
978
|
+
"_on_frame",
|
|
979
|
+
"_on_data",
|
|
980
|
+
"_process_frame",
|
|
981
|
+
"_process_data",
|
|
982
|
+
"_debug"
|
|
983
|
+
]
|
|
984
|
+
},
|
|
985
|
+
_core_rules: [
|
|
986
|
+
"All Xpell runtime objects inherit this contract.",
|
|
987
|
+
"Generated object JSON must be data-only.",
|
|
988
|
+
"Do not generate JavaScript functions.",
|
|
989
|
+
"Use _children for composition.",
|
|
990
|
+
"Use _on/_once with nano-command strings or data-only command objects."
|
|
991
|
+
],
|
|
992
|
+
_notes: [
|
|
993
|
+
"Runtime methods include parse, append, run, execute, bindDataSource, unbindDataSource, toXData, dispose, and removeChild.",
|
|
994
|
+
"Most prompts should use this skill as a compact dependency summary, not full context."
|
|
995
|
+
]
|
|
996
|
+
}, M = { _children: "child nodes" }, S = class S {
|
|
709
997
|
/**
|
|
710
998
|
* XObject constructor is creating the object and adding all the data keys to the XObject instance
|
|
711
999
|
* @param data constructor input data (object)
|
|
@@ -713,7 +1001,7 @@ class j {
|
|
|
713
1001
|
* @param skipParse - skip data parsing
|
|
714
1002
|
* if override this method make sure to call super.init(data,skipParse) and to set skipParse to true
|
|
715
1003
|
*/
|
|
716
|
-
constructor(
|
|
1004
|
+
constructor(e, t, s) {
|
|
717
1005
|
this._children = [], this._parent = null, this._on = {}, this._once = {}, this._process_frame = !0, this._process_data = !0, this._nano_commands = {}, this._event_listeners_ids = {}, this._event_parsed = !1, this._mounted = !1, this._xporter = {
|
|
718
1006
|
_ignore_fields: [
|
|
719
1007
|
"_to_xdata_ignore_fields",
|
|
@@ -734,14 +1022,46 @@ class j {
|
|
|
734
1022
|
"_debug"
|
|
735
1023
|
],
|
|
736
1024
|
_instance_xporters: {}
|
|
737
|
-
},
|
|
1025
|
+
}, t && l.mergeDefaultsWithData(e, t), this._id = e && e._id ? e._id : "xo-" + l.guid(), this._type = "object", this._children = [], this._nano_commands = {}, this.addNanoCommandPack(V), e && e.hasOwnProperty("_nano_commands") && e._nano_commands && (this.addNanoCommandPack(e._nano_commands), delete e._nano_commands), this.addXporterDataIgnoreFields(["_nano_commands"]), this.addXporterInstanceXporter(S, (n) => n.toXData()), this._xem_options = {
|
|
738
1026
|
// _instance:_xem
|
|
739
1027
|
// _object: this
|
|
740
1028
|
// _support_html: true
|
|
741
|
-
}, !s &&
|
|
1029
|
+
}, !s && e && this.parse(e, M);
|
|
1030
|
+
}
|
|
1031
|
+
static getOwnSkill() {
|
|
1032
|
+
const e = this, t = e._skill ?? R;
|
|
1033
|
+
return {
|
|
1034
|
+
...t,
|
|
1035
|
+
_exports: {
|
|
1036
|
+
...t._exports ?? {},
|
|
1037
|
+
_nano_commands: e.getNanoCommandSkills?.() ?? []
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
742
1040
|
}
|
|
743
|
-
|
|
744
|
-
this
|
|
1041
|
+
static getSkillChain() {
|
|
1042
|
+
const e = Object.getPrototypeOf(this), t = e && typeof e.getSkillChain == "function" ? e.getSkillChain() : [], s = Object.prototype.hasOwnProperty.call(this, "_skill") ? this.getOwnSkill() : null;
|
|
1043
|
+
return s ? [...t, s] : t;
|
|
1044
|
+
}
|
|
1045
|
+
static getOwnNanoCommands() {
|
|
1046
|
+
return {
|
|
1047
|
+
...V
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
static getNanoCommands() {
|
|
1051
|
+
return {
|
|
1052
|
+
...this.getOwnNanoCommands()
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
static getNanoCommandSkills() {
|
|
1056
|
+
return Object.prototype.hasOwnProperty.call(
|
|
1057
|
+
this,
|
|
1058
|
+
"getOwnNanoCommands"
|
|
1059
|
+
) ? Object.values(this.getOwnNanoCommands()).map(
|
|
1060
|
+
(t) => t.getSkill?.() ?? t._skill
|
|
1061
|
+
).filter(Boolean) : [];
|
|
1062
|
+
}
|
|
1063
|
+
log(e, ...t) {
|
|
1064
|
+
this._debug && e && c.log(this._type + "->" + this._id + "]", e, ...t);
|
|
745
1065
|
}
|
|
746
1066
|
/**
|
|
747
1067
|
* Initialize the XObject
|
|
@@ -749,82 +1069,72 @@ class j {
|
|
|
749
1069
|
* @param skipParse - skip data parsing
|
|
750
1070
|
* @deprecated - use parse method instead
|
|
751
1071
|
*/
|
|
752
|
-
init(
|
|
753
|
-
!
|
|
1072
|
+
init(e, t) {
|
|
1073
|
+
!t && e && this.parse(e, M);
|
|
754
1074
|
}
|
|
755
|
-
parseEvents(
|
|
1075
|
+
parseEvents(e) {
|
|
756
1076
|
if (!this._event_parsed) {
|
|
757
|
-
|
|
758
|
-
this.addEventListener(s, this._on[s],
|
|
1077
|
+
e || (e = this._xem_options), Object.keys(this._on).forEach((s) => {
|
|
1078
|
+
this.addEventListener(s, this._on[s], e);
|
|
759
1079
|
});
|
|
760
|
-
const
|
|
761
|
-
Object.assign(
|
|
762
|
-
this.addEventListener(s, this._once[s],
|
|
1080
|
+
const t = {};
|
|
1081
|
+
Object.assign(t, e), t._once = !0, Object.keys(this._once).forEach((s) => {
|
|
1082
|
+
this.addEventListener(s, this._once[s], t);
|
|
763
1083
|
}), this._event_parsed = !0;
|
|
764
1084
|
}
|
|
765
1085
|
}
|
|
766
|
-
addEventListener(
|
|
1086
|
+
addEventListener(e, t, s) {
|
|
767
1087
|
s || (s = this._xem_options);
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
};
|
|
773
|
-
else if (typeof e == "string")
|
|
774
|
-
i = async (r) => {
|
|
775
|
-
const c = this._id + " " + e + " event-data='" + JSON.stringify(r).replace(/'/g, "\\'") + "'";
|
|
776
|
-
await this.run(c);
|
|
777
|
-
};
|
|
778
|
-
else
|
|
779
|
-
throw new Error("event handler must be a function");
|
|
780
|
-
const n = b.on(t, i, s, this);
|
|
781
|
-
this._event_listeners_ids[t] || (this._event_listeners_ids[t] = []), this._event_listeners_ids[t].push(n);
|
|
1088
|
+
const n = async (i) => {
|
|
1089
|
+
await this.checkAndRunInternalFunction(t, i);
|
|
1090
|
+
}, r = D().on(e, n, s, this);
|
|
1091
|
+
return this._event_listeners_ids[e] || (this._event_listeners_ids[e] = []), this._event_listeners_ids[e].push(r), r;
|
|
782
1092
|
}
|
|
783
|
-
removeEventListener(
|
|
784
|
-
const
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
}), delete this._event_listeners_ids[
|
|
1093
|
+
removeEventListener(e) {
|
|
1094
|
+
const t = this._event_listeners_ids[e];
|
|
1095
|
+
t && t.length && (t.forEach((s) => {
|
|
1096
|
+
D().remove(s);
|
|
1097
|
+
}), delete this._event_listeners_ids[e]);
|
|
788
1098
|
}
|
|
789
1099
|
removeAllEventListeners() {
|
|
790
|
-
Object.keys(this._event_listeners_ids).forEach((
|
|
1100
|
+
Object.keys(this._event_listeners_ids).forEach((t) => this.removeEventListener(t));
|
|
791
1101
|
}
|
|
792
1102
|
/**
|
|
793
1103
|
* Append a child XObject to this XObject
|
|
794
1104
|
* @param xobject
|
|
795
1105
|
*/
|
|
796
|
-
append(
|
|
797
|
-
this._children?.push(
|
|
1106
|
+
append(e) {
|
|
1107
|
+
this._children?.push(e), e._parent = this;
|
|
798
1108
|
}
|
|
799
1109
|
/**
|
|
800
1110
|
* Add single nano command to the object
|
|
801
1111
|
* @param commandName - the nano command name
|
|
802
1112
|
* @param nanoCommandFunction
|
|
803
1113
|
*/
|
|
804
|
-
addNanoCommand(
|
|
805
|
-
typeof
|
|
1114
|
+
addNanoCommand(e, t) {
|
|
1115
|
+
typeof t == "function" && (this._nano_commands[e] = t);
|
|
806
1116
|
}
|
|
807
|
-
addNanoCommandPack(
|
|
808
|
-
|
|
809
|
-
this.addNanoCommand(
|
|
1117
|
+
addNanoCommandPack(e) {
|
|
1118
|
+
e && Object.keys(e).forEach((t) => {
|
|
1119
|
+
this.addNanoCommand(t, e[t]);
|
|
810
1120
|
});
|
|
811
1121
|
}
|
|
812
1122
|
/**
|
|
813
1123
|
* List of fields to ignore when exporting the xobject to XData or string format
|
|
814
1124
|
* @param <string[]> ignoreFields - an array with all the fields to ignore
|
|
815
1125
|
*/
|
|
816
|
-
addXporterDataIgnoreFields(
|
|
817
|
-
this._xporter._ignore_fields = this._xporter._ignore_fields.concat(
|
|
1126
|
+
addXporterDataIgnoreFields(e) {
|
|
1127
|
+
this._xporter._ignore_fields = this._xporter._ignore_fields.concat(e);
|
|
818
1128
|
}
|
|
819
1129
|
/**
|
|
820
1130
|
* Add XData Xporter instance handler
|
|
821
1131
|
* @param <XDataInstanceXporter> ie - the instance exporter object
|
|
822
1132
|
*/
|
|
823
|
-
addXporterInstanceXporter(
|
|
824
|
-
const s =
|
|
1133
|
+
addXporterInstanceXporter(e, t) {
|
|
1134
|
+
const s = l.guid();
|
|
825
1135
|
this._xporter._instance_xporters[s] = {
|
|
826
|
-
cls:
|
|
827
|
-
handler:
|
|
1136
|
+
cls: e,
|
|
1137
|
+
handler: t
|
|
828
1138
|
};
|
|
829
1139
|
}
|
|
830
1140
|
/**
|
|
@@ -832,9 +1142,9 @@ class j {
|
|
|
832
1142
|
* @param data data to parse
|
|
833
1143
|
* @param ignore - lis of words to ignore in the parse process
|
|
834
1144
|
*/
|
|
835
|
-
parse(
|
|
836
|
-
Object.keys(
|
|
837
|
-
!
|
|
1145
|
+
parse(e, t = M) {
|
|
1146
|
+
Object.keys(e).forEach((n) => {
|
|
1147
|
+
!t.hasOwnProperty(n) && e.hasOwnProperty(n) && (this[n] = e[n]);
|
|
838
1148
|
});
|
|
839
1149
|
}
|
|
840
1150
|
/**
|
|
@@ -847,9 +1157,9 @@ class j {
|
|
|
847
1157
|
* ...
|
|
848
1158
|
* }
|
|
849
1159
|
*/
|
|
850
|
-
parseFieldsFromXDataObject(
|
|
851
|
-
Object.keys(
|
|
852
|
-
|
|
1160
|
+
parseFieldsFromXDataObject(e, t) {
|
|
1161
|
+
Object.keys(t).forEach((n) => {
|
|
1162
|
+
e.hasOwnProperty(n) ? this[n] = e[n] : this[n] = t[n];
|
|
853
1163
|
});
|
|
854
1164
|
}
|
|
855
1165
|
/**
|
|
@@ -858,13 +1168,13 @@ class j {
|
|
|
858
1168
|
* @param {Array<string>} fields - array of field names (string)
|
|
859
1169
|
* @param checkNonXParams - also check non Xpell fields (fields that not starting with "_" sign)
|
|
860
1170
|
*/
|
|
861
|
-
parseFields(
|
|
862
|
-
|
|
863
|
-
if (
|
|
864
|
-
this[
|
|
865
|
-
else if (s &&
|
|
866
|
-
const
|
|
867
|
-
|
|
1171
|
+
parseFields(e, t, s) {
|
|
1172
|
+
t.forEach((n) => {
|
|
1173
|
+
if (e.hasOwnProperty(n))
|
|
1174
|
+
this[n] = e[n];
|
|
1175
|
+
else if (s && n.startsWith("_")) {
|
|
1176
|
+
const r = n.substring(1);
|
|
1177
|
+
e.hasOwnProperty(r) && (this[n] = e[r], this[r] = e[r]);
|
|
868
1178
|
}
|
|
869
1179
|
});
|
|
870
1180
|
}
|
|
@@ -881,43 +1191,138 @@ class j {
|
|
|
881
1191
|
async onCreate() {
|
|
882
1192
|
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);
|
|
883
1193
|
}
|
|
884
|
-
async runCmd(
|
|
885
|
-
const
|
|
886
|
-
await this.execute(
|
|
887
|
-
}
|
|
888
|
-
async checkAndRunInternalFunction(
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
1194
|
+
async runCmd(e) {
|
|
1195
|
+
const t = e instanceof I ? e : new I(e);
|
|
1196
|
+
await this.execute(t);
|
|
1197
|
+
}
|
|
1198
|
+
async checkAndRunInternalFunction(e, ...t) {
|
|
1199
|
+
const s = (r) => {
|
|
1200
|
+
if (typeof r == "string") {
|
|
1201
|
+
if (r === "$event") return t[0];
|
|
1202
|
+
if (r.startsWith("$event.")) {
|
|
1203
|
+
const i = r.slice(7).split(".");
|
|
1204
|
+
let a = t[0];
|
|
1205
|
+
for (const _ of i) {
|
|
1206
|
+
if (a == null) return;
|
|
1207
|
+
a = a[_];
|
|
1208
|
+
}
|
|
1209
|
+
return a;
|
|
1210
|
+
}
|
|
1211
|
+
if (r === "$data") return t[0];
|
|
1212
|
+
if (r.startsWith("$data.")) {
|
|
1213
|
+
const i = r.slice(6).split(".");
|
|
1214
|
+
let a = t[0];
|
|
1215
|
+
for (const _ of i) {
|
|
1216
|
+
if (a == null) return;
|
|
1217
|
+
a = a[_];
|
|
1218
|
+
}
|
|
1219
|
+
return a;
|
|
1220
|
+
}
|
|
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
|
+
return i;
|
|
1230
|
+
}
|
|
1231
|
+
return r;
|
|
1232
|
+
}, n = async (r, i) => (i !== void 0 && r && typeof r == "object" && !Array.isArray(r) && (r = {
|
|
1233
|
+
...r,
|
|
1234
|
+
_params: {
|
|
1235
|
+
...r._params ?? {},
|
|
1236
|
+
_prev: i
|
|
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
|
|
1248
|
+
);
|
|
1249
|
+
return r;
|
|
893
1250
|
}
|
|
894
|
-
if (typeof
|
|
895
|
-
await
|
|
896
|
-
|
|
1251
|
+
if (typeof e == "function")
|
|
1252
|
+
return await e(this, ...t);
|
|
1253
|
+
if (typeof e == "string") {
|
|
1254
|
+
const r = w.parseObjectCommand(
|
|
1255
|
+
`${this._id} ${e}`
|
|
1256
|
+
);
|
|
1257
|
+
if (t.length > 0) {
|
|
1258
|
+
r._params = r._params || {};
|
|
1259
|
+
const i = t[0];
|
|
1260
|
+
r._params._event = i, !r._params.data && !i?.target && (r._params.data = i);
|
|
1261
|
+
}
|
|
1262
|
+
return await this.execute(r);
|
|
897
1263
|
}
|
|
898
|
-
if (typeof
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
await
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
1264
|
+
if (e && typeof e == "object" && Array.isArray(e._commands)) {
|
|
1265
|
+
const r = e, i = typeof r._mode == "string" ? r._mode : "sequence", a = r._stop_on_error !== !1, _ = r._commands;
|
|
1266
|
+
if (i === "parallel") {
|
|
1267
|
+
const u = await Promise.allSettled(
|
|
1268
|
+
_.map(
|
|
1269
|
+
(O) => n(O)
|
|
1270
|
+
)
|
|
1271
|
+
), m = u.find(
|
|
1272
|
+
(O) => O.status === "rejected"
|
|
1273
|
+
);
|
|
1274
|
+
if (m && a)
|
|
1275
|
+
throw m.reason;
|
|
1276
|
+
return u;
|
|
1277
|
+
}
|
|
1278
|
+
let h;
|
|
1279
|
+
for (const u of _)
|
|
1280
|
+
try {
|
|
1281
|
+
h = await n(
|
|
1282
|
+
u,
|
|
1283
|
+
i === "chain" ? h : void 0
|
|
1284
|
+
);
|
|
1285
|
+
} catch (m) {
|
|
1286
|
+
if (c.error(
|
|
1287
|
+
this._type + "->" + this._id + "] command sequence failed",
|
|
1288
|
+
m
|
|
1289
|
+
), a)
|
|
1290
|
+
throw m;
|
|
1291
|
+
}
|
|
1292
|
+
return h;
|
|
905
1293
|
}
|
|
906
|
-
if (
|
|
907
|
-
const
|
|
908
|
-
if ((
|
|
909
|
-
|
|
910
|
-
"XObject JSON handler target not supported
|
|
1294
|
+
if (e && typeof e == "object" && e._op) {
|
|
1295
|
+
const r = e;
|
|
1296
|
+
if ((r._object === void 0 || r._object === null || r._object === "this" ? this._id : r._object) !== this._id) {
|
|
1297
|
+
c.error(
|
|
1298
|
+
"XObject JSON handler target not supported; expected _object omitted/'this'/" + this._id
|
|
911
1299
|
);
|
|
912
1300
|
return;
|
|
913
1301
|
}
|
|
914
|
-
const
|
|
915
|
-
|
|
916
|
-
_params:
|
|
1302
|
+
const a = {
|
|
1303
|
+
...r,
|
|
1304
|
+
_params: r._params ? { ...r._params } : {}
|
|
917
1305
|
};
|
|
918
|
-
|
|
919
|
-
|
|
1306
|
+
if (t.length > 0) {
|
|
1307
|
+
const _ = t[0];
|
|
1308
|
+
Object.prototype.hasOwnProperty.call(
|
|
1309
|
+
a._params,
|
|
1310
|
+
"data"
|
|
1311
|
+
) || (a._params.data = _), Object.prototype.hasOwnProperty.call(
|
|
1312
|
+
a._params,
|
|
1313
|
+
"_event"
|
|
1314
|
+
) || (a._params._event = _);
|
|
1315
|
+
}
|
|
1316
|
+
return a._params = s(a._params), this._debug && c.log(
|
|
1317
|
+
this._type + "->" + this._id + "]",
|
|
1318
|
+
"JSON handler executed locally",
|
|
1319
|
+
a
|
|
1320
|
+
), await this.execute(a);
|
|
920
1321
|
}
|
|
1322
|
+
c.error(
|
|
1323
|
+
this._type + "->" + this._id + "] invalid handler in checkAndRunInternalFunction",
|
|
1324
|
+
e
|
|
1325
|
+
);
|
|
921
1326
|
}
|
|
922
1327
|
/**
|
|
923
1328
|
* Triggers when the object is being mounted to other element
|
|
@@ -931,23 +1336,23 @@ class j {
|
|
|
931
1336
|
async onMount() {
|
|
932
1337
|
if (!this._mounted) {
|
|
933
1338
|
this.parseEvents(this._xem_options), this._process_data && typeof this._data_source == "string" && this._data_source.length > 0 && this.bindDataSource(this._data_source, { initial: !0 }), this._on_mount ? await this.checkAndRunInternalFunction(this._on_mount) : this._on && this._on.mount ? await this.checkAndRunInternalFunction(this._on.mount) : this._once && this._once.mount && await this.checkAndRunInternalFunction(this._once.mount), this._mounted = !0;
|
|
934
|
-
for (const
|
|
935
|
-
|
|
1339
|
+
for (const e of this._children)
|
|
1340
|
+
e.onMount && typeof e.onMount == "function" && e.onMount();
|
|
936
1341
|
}
|
|
937
1342
|
}
|
|
938
1343
|
emptyDataSource() {
|
|
939
|
-
const
|
|
940
|
-
if (typeof
|
|
941
|
-
const
|
|
942
|
-
|
|
1344
|
+
const e = this._data_source;
|
|
1345
|
+
if (typeof e != "string" || e.length === 0) return;
|
|
1346
|
+
const t = this._type ?? this.constructor.name, s = this._id ?? "no-id";
|
|
1347
|
+
x.delete(e, { source: `${t}#${s}.emptyDataSource` });
|
|
943
1348
|
}
|
|
944
1349
|
/**
|
|
945
1350
|
* Triggers when new data is being received from the data source
|
|
946
1351
|
* @param data - the data
|
|
947
1352
|
* if override this method make sure to call super.onData(data) to run the _on_data attribute
|
|
948
1353
|
*/
|
|
949
|
-
async onData(
|
|
950
|
-
this._process_data && (this._on_data ? this.checkAndRunInternalFunction(this._on_data,
|
|
1354
|
+
async onData(e) {
|
|
1355
|
+
this._process_data && (this._on_data ? this.checkAndRunInternalFunction(this._on_data, e) : this._on && this._on.data ? this.checkAndRunInternalFunction(this._on.data, e) : this._once && this._once.data && this.checkAndRunInternalFunction(this._once.data, e));
|
|
951
1356
|
}
|
|
952
1357
|
/**
|
|
953
1358
|
* Triggers from Xpell frame every frame
|
|
@@ -969,19 +1374,19 @@ class j {
|
|
|
969
1374
|
* _on_frame: "nano command text"
|
|
970
1375
|
*
|
|
971
1376
|
*/
|
|
972
|
-
async onFrame(
|
|
973
|
-
this._process_frame && (this._on_frame ? this.checkAndRunInternalFunction(this._on_frame,
|
|
974
|
-
for (const
|
|
975
|
-
|
|
1377
|
+
async onFrame(e) {
|
|
1378
|
+
this._process_frame && (this._on_frame ? this.checkAndRunInternalFunction(this._on_frame, e) : this._on && this._on.frame ? this.checkAndRunInternalFunction(this._on.frame, e) : this._once && this._once.frame && this.checkAndRunInternalFunction(this._once.frame, e));
|
|
1379
|
+
for (const t of this._children)
|
|
1380
|
+
t.onFrame && typeof t.onFrame == "function" && t.onFrame(e);
|
|
976
1381
|
}
|
|
977
1382
|
/**
|
|
978
1383
|
* Runs object nano commands
|
|
979
1384
|
* @param nanoCommand - object nano command (string)
|
|
980
1385
|
* @param cache - cache last command to prevent multiple parsing on the same command
|
|
981
1386
|
*/
|
|
982
|
-
async run(
|
|
983
|
-
let s = this._cache_cmd_txt && this._cache_cmd_txt ==
|
|
984
|
-
|
|
1387
|
+
async run(e, t = !0) {
|
|
1388
|
+
let s = this._cache_cmd_txt && this._cache_cmd_txt == e ? this._cache_jcmd : w.parseObjectCommand(e);
|
|
1389
|
+
t && (this._cache_cmd_txt = e, this._cache_jcmd = s), await this.execute(s);
|
|
985
1390
|
}
|
|
986
1391
|
/**
|
|
987
1392
|
* Execute XCommand within the XObject Nano Commands
|
|
@@ -994,39 +1399,62 @@ class j {
|
|
|
994
1399
|
* }
|
|
995
1400
|
*
|
|
996
1401
|
*/
|
|
997
|
-
async execute(
|
|
998
|
-
|
|
1402
|
+
async execute(e) {
|
|
1403
|
+
const t = e?._op;
|
|
1404
|
+
if (!t) {
|
|
1405
|
+
c.error(this._id + " missing _op in command");
|
|
1406
|
+
return;
|
|
1407
|
+
}
|
|
1408
|
+
const s = e?._module;
|
|
1409
|
+
if (s)
|
|
999
1410
|
try {
|
|
1000
|
-
await
|
|
1001
|
-
|
|
1002
|
-
|
|
1411
|
+
return await re().execute({
|
|
1412
|
+
...e,
|
|
1413
|
+
_module: s
|
|
1414
|
+
});
|
|
1415
|
+
} catch (n) {
|
|
1416
|
+
c.error(
|
|
1417
|
+
this._id + " module execution failed: " + s + "." + t + " " + n
|
|
1418
|
+
);
|
|
1419
|
+
return;
|
|
1003
1420
|
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1421
|
+
if (this._nano_commands[t])
|
|
1422
|
+
try {
|
|
1423
|
+
return await this._nano_commands[t](
|
|
1424
|
+
e,
|
|
1425
|
+
this
|
|
1426
|
+
);
|
|
1427
|
+
} catch (n) {
|
|
1428
|
+
c.error(
|
|
1429
|
+
this._id + " has error with command name " + t + " " + n
|
|
1430
|
+
);
|
|
1431
|
+
return;
|
|
1432
|
+
}
|
|
1433
|
+
c.error(this._id + " has no command name " + t);
|
|
1006
1434
|
}
|
|
1007
1435
|
/**
|
|
1008
1436
|
* Return an IXObjectData JSON representation of the XObject
|
|
1009
1437
|
* @returns IXObjectData
|
|
1010
1438
|
*/
|
|
1011
1439
|
toXData() {
|
|
1012
|
-
const
|
|
1013
|
-
return Object.keys(this).forEach((
|
|
1014
|
-
if (!this._xporter._ignore_fields.includes(
|
|
1015
|
-
const s = this[
|
|
1440
|
+
const e = {};
|
|
1441
|
+
return Object.keys(this).forEach((t) => {
|
|
1442
|
+
if (!this._xporter._ignore_fields.includes(t) && this.hasOwnProperty(t) && this[t] !== void 0) {
|
|
1443
|
+
const s = this[t];
|
|
1016
1444
|
if (typeof s == "function")
|
|
1017
1445
|
return;
|
|
1018
1446
|
if (typeof s == "object") {
|
|
1019
|
-
const
|
|
1020
|
-
let
|
|
1021
|
-
|
|
1022
|
-
this._xporter._instance_xporters[
|
|
1023
|
-
}),
|
|
1447
|
+
const n = Object.keys(this._xporter._instance_xporters);
|
|
1448
|
+
let r = !0;
|
|
1449
|
+
n.forEach((i) => {
|
|
1450
|
+
this._xporter._instance_xporters[i], s instanceof this._xporter._instance_xporters[i].cls && (e[t] = this._xporter._instance_xporters[i].handler(s), r = !1);
|
|
1451
|
+
}), r && (e[t] = s);
|
|
1024
1452
|
} else
|
|
1025
|
-
t
|
|
1453
|
+
e[t] = s;
|
|
1026
1454
|
}
|
|
1027
|
-
}),
|
|
1028
|
-
typeof
|
|
1029
|
-
}),
|
|
1455
|
+
}), e._children = [], this._children.length > 0 && this._children.forEach((t) => {
|
|
1456
|
+
typeof t.toXData == "function" && e._children?.push(t.toXData());
|
|
1457
|
+
}), e;
|
|
1030
1458
|
}
|
|
1031
1459
|
/**
|
|
1032
1460
|
* Return a string representation of the XObject
|
|
@@ -1035,16 +1463,16 @@ class j {
|
|
|
1035
1463
|
toString() {
|
|
1036
1464
|
return JSON.stringify(this.toXData());
|
|
1037
1465
|
}
|
|
1038
|
-
clearAttributes(
|
|
1039
|
-
|
|
1040
|
-
this.hasOwnProperty(
|
|
1466
|
+
clearAttributes(e) {
|
|
1467
|
+
e.forEach((t) => {
|
|
1468
|
+
this.hasOwnProperty(t) && (this[t] = null, delete this[t]);
|
|
1041
1469
|
});
|
|
1042
1470
|
}
|
|
1043
|
-
bindDataSource(
|
|
1044
|
-
const s =
|
|
1045
|
-
typeof
|
|
1046
|
-
await this.onData(
|
|
1047
|
-
}), s &&
|
|
1471
|
+
bindDataSource(e, t) {
|
|
1472
|
+
const s = t?.initial ?? !0, n = e ?? this._data_source;
|
|
1473
|
+
typeof n != "string" || n.length === 0 || this._process_data && (this._xd_bound_key === n && this._xd_unsub || (this.unbindDataSource(), this._data_source = n, this._xd_bound_key = n, this._type ?? this.constructor.name, this._id, this._xd_unsub = x.on(n, async (r) => {
|
|
1474
|
+
await this.onData(r.value);
|
|
1475
|
+
}), s && x.has(n) && this.onData(x.get(n))));
|
|
1048
1476
|
}
|
|
1049
1477
|
unbindDataSource() {
|
|
1050
1478
|
this._xd_unsub?.(), this._xd_unsub = void 0, this._xd_bound_key = void 0;
|
|
@@ -1054,11 +1482,11 @@ class j {
|
|
|
1054
1482
|
*/
|
|
1055
1483
|
async dispose() {
|
|
1056
1484
|
if (this.unbindDataSource(), this._parent) {
|
|
1057
|
-
const
|
|
1058
|
-
|
|
1485
|
+
const e = this._parent._children.indexOf(this);
|
|
1486
|
+
e > -1 && this._parent._children.splice(e, 1);
|
|
1059
1487
|
}
|
|
1060
|
-
this._process_data = !1, this._process_frame = !1, this.removeAllEventListeners(), this.clearAttributes(["_cache_cmd_txt", "_cache_jcmd", "_nano_commands", "_event_listeners_ids", "_parent", "_on", "_once", "_xem_options", "_xporter"]), this._children && this._children.forEach((
|
|
1061
|
-
typeof
|
|
1488
|
+
this._process_data = !1, this._process_frame = !1, this.removeAllEventListeners(), this.clearAttributes(["_cache_cmd_txt", "_cache_jcmd", "_nano_commands", "_event_listeners_ids", "_parent", "_on", "_once", "_xem_options", "_xporter"]), this._children && this._children.forEach((e) => {
|
|
1489
|
+
typeof e.dispose == "function" && e.dispose();
|
|
1062
1490
|
}), this._children = [];
|
|
1063
1491
|
}
|
|
1064
1492
|
/**
|
|
@@ -1066,80 +1494,156 @@ class j {
|
|
|
1066
1494
|
* @param child - the child to
|
|
1067
1495
|
* @returns void
|
|
1068
1496
|
*/
|
|
1069
|
-
removeChild(
|
|
1070
|
-
if (
|
|
1071
|
-
|
|
1497
|
+
removeChild(e, t = !1) {
|
|
1498
|
+
if (t)
|
|
1499
|
+
e.dispose();
|
|
1072
1500
|
else {
|
|
1073
|
-
const s = this._children.indexOf(
|
|
1074
|
-
s > -1 && this._children.splice(s, 1),
|
|
1501
|
+
const s = this._children.indexOf(e);
|
|
1502
|
+
s > -1 && this._children.splice(s, 1), e._parent = null;
|
|
1075
1503
|
}
|
|
1076
1504
|
}
|
|
1077
1505
|
/**
|
|
1078
1506
|
* @param child - the child to add
|
|
1079
1507
|
* @deprecated use append method instead
|
|
1080
1508
|
*/
|
|
1081
|
-
addChild(
|
|
1082
|
-
this.append(
|
|
1509
|
+
addChild(e) {
|
|
1510
|
+
this.append(e);
|
|
1083
1511
|
}
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1512
|
+
};
|
|
1513
|
+
S._xtype = "object", S._skill = R;
|
|
1514
|
+
let F = S;
|
|
1515
|
+
class pe {
|
|
1086
1516
|
/**
|
|
1087
1517
|
* Get all registered object in this ObjectPack
|
|
1088
1518
|
* @returns XObject dictionary
|
|
1089
1519
|
*/
|
|
1090
1520
|
static getObjects() {
|
|
1091
1521
|
return {
|
|
1092
|
-
object:
|
|
1522
|
+
object: F
|
|
1093
1523
|
};
|
|
1094
1524
|
}
|
|
1095
1525
|
}
|
|
1096
|
-
const
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1526
|
+
const ie = "engine:module:num-of-objects:", N = {
|
|
1527
|
+
_id: "xmodule",
|
|
1528
|
+
_title: "XModule Runtime Contract",
|
|
1529
|
+
_version: "1.0.0",
|
|
1530
|
+
_active: !0,
|
|
1531
|
+
_type: "runtime-api-skill",
|
|
1532
|
+
_description: "Base runtime module contract for object ownership, object packs, and executable underscore-prefixed commands.",
|
|
1533
|
+
_core_rules: [
|
|
1534
|
+
"Every module must have a unique _name.",
|
|
1535
|
+
"Modules expose commands through methods prefixed with underscore.",
|
|
1536
|
+
"Command names remove the leading underscore and convert dashes to underscores internally.",
|
|
1537
|
+
"Modules own and create registered XObject classes.",
|
|
1538
|
+
"Do not mutate another module's objects directly."
|
|
1539
|
+
]
|
|
1540
|
+
};
|
|
1541
|
+
var d;
|
|
1542
|
+
const C = class C {
|
|
1543
|
+
constructor(e) {
|
|
1544
|
+
B(this, d);
|
|
1545
|
+
this._loaded = !1, this._loading = !1, this._log_rules = {
|
|
1101
1546
|
createObject: !1,
|
|
1102
1547
|
removeObject: !1
|
|
1103
|
-
}, this
|
|
1548
|
+
}, W(this, d, new te()), this._name = e._name, this._id = l.guid();
|
|
1104
1549
|
}
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1550
|
+
static getOwnSkillBase() {
|
|
1551
|
+
return {
|
|
1552
|
+
...this._skill
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
getOwnSkill() {
|
|
1556
|
+
const t = this.constructor._skill ?? N;
|
|
1557
|
+
return {
|
|
1558
|
+
...t,
|
|
1559
|
+
_exports: {
|
|
1560
|
+
...t._exports ?? {},
|
|
1561
|
+
_modules: [
|
|
1562
|
+
{
|
|
1563
|
+
_name: this._name,
|
|
1564
|
+
_scope: t._type === "server-module-api" ? "server" : "client",
|
|
1565
|
+
_description: t._description,
|
|
1566
|
+
_ops: this.getCommandSkills()
|
|
1567
|
+
}
|
|
1568
|
+
]
|
|
1569
|
+
}
|
|
1570
|
+
};
|
|
1571
|
+
}
|
|
1572
|
+
getSkillChain() {
|
|
1573
|
+
return [this.getOwnSkill()];
|
|
1574
|
+
}
|
|
1575
|
+
getObjectSkills() {
|
|
1576
|
+
const e = [], t = /* @__PURE__ */ new Set();
|
|
1577
|
+
for (const s of Object.values(p(this, d).getObjectClasses())) {
|
|
1578
|
+
if (typeof s.getOwnSkill != "function") continue;
|
|
1579
|
+
const n = s.getOwnSkill();
|
|
1580
|
+
n?._id && (t.has(n._id) || (t.add(n._id), e.push(n)));
|
|
1581
|
+
}
|
|
1582
|
+
return e;
|
|
1583
|
+
}
|
|
1584
|
+
getCommandSkills() {
|
|
1585
|
+
const e = Object.getPrototypeOf(this), s = this.constructor._ops ?? {};
|
|
1586
|
+
return Object.getOwnPropertyNames(e).filter(
|
|
1587
|
+
(n) => n.startsWith("_") && !n.startsWith("__") && typeof this[n] == "function"
|
|
1588
|
+
).map((n) => {
|
|
1589
|
+
const r = n.slice(1).replaceAll("_", "-");
|
|
1590
|
+
return s[r] ?? {
|
|
1591
|
+
_name: r,
|
|
1592
|
+
_scope: "module",
|
|
1593
|
+
_description: `Runtime module command: ${r}`
|
|
1594
|
+
};
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
async load() {
|
|
1598
|
+
if (!(this._loaded || this._loading)) {
|
|
1599
|
+
this._loading = !0;
|
|
1600
|
+
try {
|
|
1601
|
+
await this.onLoad(), this._loaded = !0, c.log("Module " + this._name + " loaded");
|
|
1602
|
+
} finally {
|
|
1603
|
+
this._loading = !1;
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
async onLoad() {
|
|
1108
1608
|
}
|
|
1109
1609
|
/**
|
|
1110
1610
|
* Creates new XObject from data object
|
|
1111
1611
|
* @param data - The data of the new object (JSON)
|
|
1112
1612
|
* @return {XObject|*}
|
|
1113
1613
|
*/
|
|
1114
|
-
create(
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
throw
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1614
|
+
create(e) {
|
|
1615
|
+
e._debug && c.log("Creating object with data", e);
|
|
1616
|
+
let t;
|
|
1617
|
+
if (e.hasOwnProperty("_type")) {
|
|
1618
|
+
e._debug && c.log("Object type is", e._type, this.hasObject(e._type) ? "found" : "not found", "in module", this._name);
|
|
1619
|
+
const s = String(e._type), n = p(this, d).getObjectClass(s);
|
|
1620
|
+
if (!n)
|
|
1621
|
+
throw `Xpell object '${s}' not found in module '${this._name}'`;
|
|
1622
|
+
typeof n == "function" && n.hasOwnProperty("defaults") && l.mergeDefaultsWithData(
|
|
1623
|
+
e,
|
|
1624
|
+
n.defaults
|
|
1625
|
+
), t = new n(e);
|
|
1626
|
+
} else
|
|
1627
|
+
t = new F(e);
|
|
1628
|
+
return p(this, d).addObject(t), e._children && e._children.forEach((s) => {
|
|
1629
|
+
const n = this.create(s);
|
|
1630
|
+
t.append(n);
|
|
1631
|
+
}), t.onCreate(), t;
|
|
1128
1632
|
}
|
|
1129
1633
|
/**
|
|
1130
1634
|
* removes and XObject from the object manager
|
|
1131
1635
|
* @param objectId op
|
|
1132
1636
|
*/
|
|
1133
|
-
remove(
|
|
1134
|
-
const
|
|
1135
|
-
if (!
|
|
1136
|
-
const s = [],
|
|
1137
|
-
|
|
1637
|
+
remove(e) {
|
|
1638
|
+
const t = p(this, d).getObject(e);
|
|
1639
|
+
if (!t) return;
|
|
1640
|
+
const s = [], n = (r) => {
|
|
1641
|
+
r?._id && (s.push(r._id), (r._children ?? []).forEach((i) => n(i)));
|
|
1138
1642
|
};
|
|
1139
|
-
|
|
1643
|
+
n(t), typeof t.dispose == "function" && t.dispose(), s.reverse().forEach((r) => p(this, d).removeObject(r));
|
|
1140
1644
|
}
|
|
1141
|
-
_info(
|
|
1142
|
-
|
|
1645
|
+
_info(e) {
|
|
1646
|
+
c.log("module info");
|
|
1143
1647
|
}
|
|
1144
1648
|
//xpell interpreter
|
|
1145
1649
|
/**
|
|
@@ -1148,11 +1652,11 @@ class q {
|
|
|
1148
1652
|
* @param {string} XCommand input - text
|
|
1149
1653
|
* @returns command execution result
|
|
1150
1654
|
*/
|
|
1151
|
-
async run(
|
|
1152
|
-
if (
|
|
1153
|
-
let
|
|
1154
|
-
|
|
1155
|
-
let s =
|
|
1655
|
+
async run(e) {
|
|
1656
|
+
if (e) {
|
|
1657
|
+
let t = e.trim();
|
|
1658
|
+
t.startsWith(this._name) || (t = this._name + " " + t);
|
|
1659
|
+
let s = w.parse(t);
|
|
1156
1660
|
return await this.execute(s);
|
|
1157
1661
|
} else
|
|
1158
1662
|
throw "Unable to parse Xpell Command";
|
|
@@ -1163,32 +1667,32 @@ class q {
|
|
|
1163
1667
|
* @returns command execution result
|
|
1164
1668
|
*/
|
|
1165
1669
|
// inside XModule class
|
|
1166
|
-
async execute(
|
|
1167
|
-
if (!
|
|
1670
|
+
async execute(e) {
|
|
1671
|
+
if (!e || !e._op)
|
|
1168
1672
|
throw new Error(`Invalid XCommand: missing _op (module: ${this._name})`);
|
|
1169
|
-
const
|
|
1170
|
-
if (
|
|
1171
|
-
const
|
|
1172
|
-
if (!
|
|
1173
|
-
throw new Error(`Module '${this._name}' cant find object id: ${
|
|
1174
|
-
return await
|
|
1673
|
+
const t = e._object;
|
|
1674
|
+
if (t) {
|
|
1675
|
+
const r = p(this, d).getObject(t);
|
|
1676
|
+
if (!r)
|
|
1677
|
+
throw new Error(`Module '${this._name}' cant find object id: ${t}`);
|
|
1678
|
+
return await r.execute(e);
|
|
1175
1679
|
}
|
|
1176
|
-
const s = "_" +
|
|
1177
|
-
if (typeof
|
|
1178
|
-
return await
|
|
1179
|
-
throw new Error(`Module '${this._name}' cant find op: ${
|
|
1680
|
+
const s = "_" + e._op.replaceAll("-", "_"), n = this[s];
|
|
1681
|
+
if (typeof n == "function")
|
|
1682
|
+
return await n.call(this, e);
|
|
1683
|
+
throw new Error(`Module '${this._name}' cant find op: ${e._op}`);
|
|
1180
1684
|
}
|
|
1181
1685
|
/**
|
|
1182
1686
|
* This method triggers every frame from the Xpell engine.
|
|
1183
1687
|
* The method can be override by the extending module to support extended onFrame functionality
|
|
1184
1688
|
* @param frameNumber Current frame number
|
|
1185
1689
|
*/
|
|
1186
|
-
async onFrame(
|
|
1187
|
-
const
|
|
1188
|
-
s.forEach((
|
|
1189
|
-
const
|
|
1190
|
-
|
|
1191
|
-
}),
|
|
1690
|
+
async onFrame(e) {
|
|
1691
|
+
const t = p(this, d)._objects, s = Object.keys(t);
|
|
1692
|
+
s.forEach((n) => {
|
|
1693
|
+
const r = t[n];
|
|
1694
|
+
r && r.onFrame && typeof r.onFrame == "function" && r?.onFrame(e);
|
|
1695
|
+
}), f.set(ie + this._id, s.length, {
|
|
1192
1696
|
source: "xmodule"
|
|
1193
1697
|
});
|
|
1194
1698
|
}
|
|
@@ -1203,18 +1707,21 @@ class q {
|
|
|
1203
1707
|
* getObject directly on the module instead of om.getObject
|
|
1204
1708
|
*/
|
|
1205
1709
|
get om() {
|
|
1206
|
-
return this
|
|
1710
|
+
return p(this, d);
|
|
1207
1711
|
}
|
|
1208
1712
|
get _object_manager() {
|
|
1209
|
-
return this
|
|
1713
|
+
return p(this, d);
|
|
1210
1714
|
}
|
|
1211
1715
|
/**
|
|
1212
1716
|
* Returns the XObject instance from the module Object Manager
|
|
1213
1717
|
* @param objectId
|
|
1214
1718
|
* @returns XObject
|
|
1215
1719
|
*/
|
|
1216
|
-
getObject(
|
|
1217
|
-
return this
|
|
1720
|
+
getObject(e) {
|
|
1721
|
+
return p(this, d).getObject(e);
|
|
1722
|
+
}
|
|
1723
|
+
hasObject(e) {
|
|
1724
|
+
return p(this, d).hasObjectClass(e);
|
|
1218
1725
|
}
|
|
1219
1726
|
/**
|
|
1220
1727
|
* Returns the XObject instance from the module Object Manager
|
|
@@ -1222,23 +1729,23 @@ class q {
|
|
|
1222
1729
|
* xmodule._o["object-id"] is equivalent to xmodule.getObject("object-id")
|
|
1223
1730
|
*/
|
|
1224
1731
|
get _o() {
|
|
1225
|
-
return this
|
|
1732
|
+
return p(this, d)._objects;
|
|
1226
1733
|
}
|
|
1227
1734
|
/**
|
|
1228
1735
|
* Imports external object pack to the engine
|
|
1229
1736
|
* The object class should be like XObjects with static implementation of getObjects() method
|
|
1230
1737
|
* @param {XObjects} xObjectPack
|
|
1231
1738
|
*/
|
|
1232
|
-
importObjectPack(
|
|
1233
|
-
this
|
|
1739
|
+
importObjectPack(e) {
|
|
1740
|
+
p(this, d).registerObjects(e.getObjects());
|
|
1234
1741
|
}
|
|
1235
1742
|
/**
|
|
1236
1743
|
* Imports external object pack to the engine
|
|
1237
1744
|
* @deprecated - use importObjectPack instead
|
|
1238
1745
|
* @param xObjectPack
|
|
1239
1746
|
*/
|
|
1240
|
-
importObjects(
|
|
1241
|
-
this.importObjectPack(
|
|
1747
|
+
importObjects(e) {
|
|
1748
|
+
this.importObjectPack(e);
|
|
1242
1749
|
}
|
|
1243
1750
|
/**
|
|
1244
1751
|
* Imports external objects to the engine
|
|
@@ -1246,19 +1753,19 @@ class q {
|
|
|
1246
1753
|
* @param xObjectName
|
|
1247
1754
|
* @param xObject
|
|
1248
1755
|
*/
|
|
1249
|
-
importObject(
|
|
1250
|
-
this
|
|
1756
|
+
importObject(e, t) {
|
|
1757
|
+
p(this, d).registerObject(e, t);
|
|
1251
1758
|
}
|
|
1252
1759
|
// In XModule
|
|
1253
|
-
async _help(
|
|
1254
|
-
const
|
|
1255
|
-
return this.help(
|
|
1760
|
+
async _help(e) {
|
|
1761
|
+
const t = e?._params?._op ?? e?._params?._command ?? "";
|
|
1762
|
+
return this.help(t);
|
|
1256
1763
|
}
|
|
1257
1764
|
/**
|
|
1258
1765
|
* Override in modules to provide help text.
|
|
1259
1766
|
* @param op optional: specific command name (e.g. "navigate")
|
|
1260
1767
|
*/
|
|
1261
|
-
help(
|
|
1768
|
+
help(e) {
|
|
1262
1769
|
return {
|
|
1263
1770
|
module: this._name,
|
|
1264
1771
|
usage: `${this._name} help`,
|
|
@@ -1266,60 +1773,264 @@ class q {
|
|
|
1266
1773
|
note: "No help() implemented for this module."
|
|
1267
1774
|
};
|
|
1268
1775
|
}
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1776
|
+
};
|
|
1777
|
+
d = new WeakMap(), C._skill = N, C._ops = {
|
|
1778
|
+
help: {
|
|
1779
|
+
_name: "help",
|
|
1780
|
+
_scope: "module",
|
|
1781
|
+
_description: "Return module help or command-specific help."
|
|
1782
|
+
},
|
|
1783
|
+
info: {
|
|
1784
|
+
_name: "info",
|
|
1785
|
+
_scope: "module",
|
|
1786
|
+
_description: "Log basic module information."
|
|
1787
|
+
}
|
|
1788
|
+
};
|
|
1789
|
+
let A = C;
|
|
1790
|
+
const oe = {
|
|
1791
|
+
_id: "xdata",
|
|
1792
|
+
_title: "XData Runtime State Contract",
|
|
1793
|
+
_version: "1.0.0",
|
|
1794
|
+
_active: !0,
|
|
1795
|
+
_type: "xdata-skill",
|
|
1796
|
+
_description: "Shared runtime state store used by Xpell modules and objects for reactive data binding.",
|
|
1797
|
+
_requires: ["xmodule"],
|
|
1798
|
+
_core_rules: [
|
|
1799
|
+
"Use XData for shared runtime state.",
|
|
1800
|
+
"Use _data_source on objects to bind to an XData key.",
|
|
1801
|
+
"Use $xdata.key references in generated payloads when a flow or command needs current state.",
|
|
1802
|
+
"Do not use XData as hidden local component state.",
|
|
1803
|
+
"XData keys should be explicit and stable."
|
|
1804
|
+
],
|
|
1805
|
+
_fields: {
|
|
1806
|
+
_data_source: "XData key used by XObject/XUIObject for reactive data binding.",
|
|
1807
|
+
"$xdata.key": "Runtime payload reference to an XData value."
|
|
1808
|
+
}
|
|
1809
|
+
}, v = class v extends A {
|
|
1810
|
+
constructor() {
|
|
1811
|
+
super({ _name: v._name });
|
|
1812
|
+
}
|
|
1813
|
+
async _get(e) {
|
|
1814
|
+
const t = l.ensure_params(e?._params), s = l.ensure_string(t.key, "key");
|
|
1815
|
+
return {
|
|
1816
|
+
_ok: !0,
|
|
1817
|
+
_result: f.get(s)
|
|
1818
|
+
};
|
|
1819
|
+
}
|
|
1820
|
+
async _set(e) {
|
|
1821
|
+
const t = l.ensure_params(e?._params), s = l.ensure_string(t.key, "key");
|
|
1822
|
+
return t._debug && j.log("XD SET", { key: s, value: t.value }), f.set(s, t.value, {
|
|
1823
|
+
source: t.source ?? "xd:set"
|
|
1824
|
+
}), {
|
|
1825
|
+
_ok: !0,
|
|
1826
|
+
_result: { key: s }
|
|
1827
|
+
};
|
|
1828
|
+
}
|
|
1829
|
+
async _patch(e) {
|
|
1830
|
+
const t = l.ensure_params(e?._params), s = l.ensure_string(t.key, "key");
|
|
1831
|
+
if (!l.is_plain_object(t.value))
|
|
1832
|
+
throw new Error("xd patch expects value as plain object");
|
|
1833
|
+
return f.patch(s, t.value, {
|
|
1834
|
+
source: t.source ?? "xd:patch"
|
|
1835
|
+
}), {
|
|
1836
|
+
_ok: !0,
|
|
1837
|
+
_result: { key: s }
|
|
1838
|
+
};
|
|
1839
|
+
}
|
|
1840
|
+
async _delete(e) {
|
|
1841
|
+
const t = l.ensure_params(e?._params), s = l.ensure_string(t.key, "key");
|
|
1842
|
+
return f.delete(s, {
|
|
1843
|
+
source: t.source ?? "xd:delete"
|
|
1844
|
+
}), {
|
|
1845
|
+
_ok: !0,
|
|
1846
|
+
_result: { key: s }
|
|
1847
|
+
};
|
|
1848
|
+
}
|
|
1849
|
+
async _touch(e) {
|
|
1850
|
+
const t = l.ensure_params(e?._params), s = l.ensure_string(t.key, "key");
|
|
1851
|
+
return f.touch(s, {
|
|
1852
|
+
source: t.source ?? "xd:touch"
|
|
1853
|
+
}), {
|
|
1854
|
+
_ok: !0,
|
|
1855
|
+
_result: { key: s }
|
|
1856
|
+
};
|
|
1857
|
+
}
|
|
1858
|
+
async _has(e) {
|
|
1859
|
+
const t = l.ensure_params(e?._params), s = l.ensure_string(t.key, "key");
|
|
1860
|
+
return {
|
|
1861
|
+
_ok: !0,
|
|
1862
|
+
_result: f.has(s)
|
|
1863
|
+
};
|
|
1864
|
+
}
|
|
1865
|
+
};
|
|
1866
|
+
v._name = "xd", v._skill = oe, v._ops = {
|
|
1867
|
+
get: {
|
|
1868
|
+
_name: "get",
|
|
1869
|
+
_scope: "module",
|
|
1870
|
+
_description: "Get value from XData store.",
|
|
1871
|
+
_params: {
|
|
1872
|
+
key: "XData key."
|
|
1873
|
+
}
|
|
1874
|
+
},
|
|
1875
|
+
set: {
|
|
1876
|
+
_name: "set",
|
|
1877
|
+
_scope: "module",
|
|
1878
|
+
_description: "Set value in XData store.",
|
|
1879
|
+
_params: {
|
|
1880
|
+
key: "XData key.",
|
|
1881
|
+
value: "Value to store.",
|
|
1882
|
+
source: "Optional mutation source."
|
|
1883
|
+
}
|
|
1884
|
+
},
|
|
1885
|
+
patch: {
|
|
1886
|
+
_name: "patch",
|
|
1887
|
+
_scope: "module",
|
|
1888
|
+
_description: "Patch plain object into existing XData value.",
|
|
1889
|
+
_params: {
|
|
1890
|
+
key: "XData key.",
|
|
1891
|
+
value: "Plain object patch.",
|
|
1892
|
+
source: "Optional mutation source."
|
|
1893
|
+
}
|
|
1894
|
+
},
|
|
1895
|
+
delete: {
|
|
1896
|
+
_name: "delete",
|
|
1897
|
+
_scope: "module",
|
|
1898
|
+
_description: "Delete XData key.",
|
|
1899
|
+
_params: {
|
|
1900
|
+
key: "XData key.",
|
|
1901
|
+
source: "Optional mutation source."
|
|
1902
|
+
}
|
|
1903
|
+
},
|
|
1904
|
+
touch: {
|
|
1905
|
+
_name: "touch",
|
|
1906
|
+
_scope: "module",
|
|
1907
|
+
_description: "Trigger XData subscribers without changing value.",
|
|
1908
|
+
_params: {
|
|
1909
|
+
key: "XData key.",
|
|
1910
|
+
source: "Optional mutation source."
|
|
1911
|
+
}
|
|
1912
|
+
},
|
|
1913
|
+
has: {
|
|
1914
|
+
_name: "has",
|
|
1915
|
+
_scope: "module",
|
|
1916
|
+
_description: "Check if XData key exists.",
|
|
1917
|
+
_params: {
|
|
1918
|
+
key: "XData key."
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
};
|
|
1922
|
+
let L = v;
|
|
1923
|
+
const ae = {
|
|
1924
|
+
_id: "xem",
|
|
1925
|
+
_title: "XEventManager Runtime Event Bus",
|
|
1926
|
+
_version: "1.0.0",
|
|
1927
|
+
_active: !0,
|
|
1928
|
+
_type: "runtime-api-skill",
|
|
1929
|
+
_description: "Global runtime event bus for decoupled communication between Xpell modules, objects, flows, and UI components.",
|
|
1930
|
+
_requires: ["xmodule"],
|
|
1931
|
+
_core_rules: [
|
|
1932
|
+
"Use XEM for decoupled runtime events.",
|
|
1933
|
+
"Use explicit event names and explicit payload objects.",
|
|
1934
|
+
"Do not use XEM as state storage.",
|
|
1935
|
+
"Use XData for shared state and XEM for notifications/events.",
|
|
1936
|
+
"Prefer _on/_once on objects for local event handlers."
|
|
1937
|
+
],
|
|
1938
|
+
_fields: {
|
|
1939
|
+
_on: "Object event handler map.",
|
|
1940
|
+
_once: "Object one-time event handler map.",
|
|
1941
|
+
event: "Event name to fire.",
|
|
1942
|
+
data: "Optional event payload."
|
|
1943
|
+
},
|
|
1944
|
+
_notes: [
|
|
1945
|
+
"XEM is process-wide and listener order should not be assumed.",
|
|
1946
|
+
"Event payloads should be JSON/data-only."
|
|
1947
|
+
]
|
|
1948
|
+
}, k = class k extends A {
|
|
1949
|
+
constructor() {
|
|
1950
|
+
super({ _name: k._name });
|
|
1951
|
+
}
|
|
1952
|
+
async _fire(e) {
|
|
1953
|
+
const t = l.ensure_params(e?._params), s = l.ensure_string(t.event, "event"), n = t.data;
|
|
1954
|
+
t._debug && j.log("xem fire 🔥 ", s, n), await D().fire(s, n);
|
|
1955
|
+
}
|
|
1956
|
+
};
|
|
1957
|
+
k._name = "xem", k._skill = ae, k._ops = {
|
|
1958
|
+
fire: {
|
|
1959
|
+
_name: "fire",
|
|
1960
|
+
_scope: "module",
|
|
1961
|
+
_description: "Fire a global XEM event with optional payload data.",
|
|
1962
|
+
_params: {
|
|
1963
|
+
event: "Event name.",
|
|
1964
|
+
data: "Optional event payload.",
|
|
1965
|
+
_debug: "Optional debug log flag."
|
|
1966
|
+
},
|
|
1967
|
+
_example: {
|
|
1968
|
+
_module: "xem",
|
|
1969
|
+
_op: "fire",
|
|
1970
|
+
_params: {
|
|
1971
|
+
event: "user:login",
|
|
1972
|
+
data: {
|
|
1973
|
+
source: "login-button"
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
};
|
|
1979
|
+
let U = k;
|
|
1980
|
+
class me {
|
|
1271
1981
|
/* -------------------------------------------------- */
|
|
1272
1982
|
/* core helpers */
|
|
1273
1983
|
/* -------------------------------------------------- */
|
|
1274
|
-
static get(
|
|
1275
|
-
if (!
|
|
1276
|
-
const
|
|
1277
|
-
return
|
|
1278
|
-
}
|
|
1279
|
-
static has(
|
|
1280
|
-
return
|
|
1281
|
-
}
|
|
1282
|
-
static str(
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1984
|
+
static get(e, t, s) {
|
|
1985
|
+
if (!e?._params) return s;
|
|
1986
|
+
const n = e._params[t];
|
|
1987
|
+
return n !== void 0 ? n : s;
|
|
1988
|
+
}
|
|
1989
|
+
static has(e, t) {
|
|
1990
|
+
return (e?._params || e)[t] !== void 0;
|
|
1991
|
+
}
|
|
1992
|
+
static str(e, ...t) {
|
|
1993
|
+
const s = e?._params || e;
|
|
1994
|
+
for (const n of t) {
|
|
1995
|
+
const r = s?.[n];
|
|
1996
|
+
if (r != null)
|
|
1997
|
+
return String(r);
|
|
1287
1998
|
}
|
|
1288
1999
|
}
|
|
1289
2000
|
/* -------------------------------------------------- */
|
|
1290
2001
|
/* typed params */
|
|
1291
2002
|
/* -------------------------------------------------- */
|
|
1292
|
-
static bool(
|
|
1293
|
-
const
|
|
1294
|
-
if (typeof
|
|
1295
|
-
if (typeof
|
|
1296
|
-
if (typeof
|
|
1297
|
-
const
|
|
1298
|
-
if (["1", "true", "yes", "on"].includes(
|
|
1299
|
-
if (["0", "false", "no", "off"].includes(
|
|
2003
|
+
static bool(e, t, s = !1) {
|
|
2004
|
+
const n = e?._params || e, r = this.get(n, t, s);
|
|
2005
|
+
if (typeof r == "boolean") return r;
|
|
2006
|
+
if (typeof r == "number") return r !== 0;
|
|
2007
|
+
if (typeof r == "string") {
|
|
2008
|
+
const i = r.toLowerCase();
|
|
2009
|
+
if (["1", "true", "yes", "on"].includes(i)) return !0;
|
|
2010
|
+
if (["0", "false", "no", "off"].includes(i)) return !1;
|
|
1300
2011
|
}
|
|
1301
|
-
return !!
|
|
2012
|
+
return !!r;
|
|
1302
2013
|
}
|
|
1303
|
-
static int(
|
|
1304
|
-
const
|
|
1305
|
-
return Number.isFinite(
|
|
2014
|
+
static int(e, t, s = 0) {
|
|
2015
|
+
const n = e?._params || e, r = this.get(n, t, s), i = parseInt(String(r), 10);
|
|
2016
|
+
return Number.isFinite(i) ? i : s;
|
|
1306
2017
|
}
|
|
1307
|
-
static json(
|
|
1308
|
-
const
|
|
1309
|
-
if (
|
|
1310
|
-
if (typeof
|
|
1311
|
-
if (typeof
|
|
2018
|
+
static json(e, t, s) {
|
|
2019
|
+
const n = e?._params || e, r = this.get(n, t, s);
|
|
2020
|
+
if (r == null) return s;
|
|
2021
|
+
if (typeof r == "object") return r;
|
|
2022
|
+
if (typeof r == "string")
|
|
1312
2023
|
try {
|
|
1313
|
-
return JSON.parse(
|
|
2024
|
+
return JSON.parse(r);
|
|
1314
2025
|
} catch {
|
|
1315
2026
|
return s;
|
|
1316
2027
|
}
|
|
1317
2028
|
return s;
|
|
1318
2029
|
}
|
|
1319
2030
|
}
|
|
1320
|
-
class
|
|
1321
|
-
constructor(
|
|
1322
|
-
super(
|
|
2031
|
+
class K extends Error {
|
|
2032
|
+
constructor(e, t, s) {
|
|
2033
|
+
super(t), this.name = "XError", this._code = e, this._level = s?._level ?? "error", this._meta = s?._meta, this._cause = s?._cause;
|
|
1323
2034
|
}
|
|
1324
2035
|
toXData() {
|
|
1325
2036
|
return {
|
|
@@ -1340,33 +2051,33 @@ class E extends Error {
|
|
|
1340
2051
|
};
|
|
1341
2052
|
}
|
|
1342
2053
|
}
|
|
1343
|
-
class
|
|
1344
|
-
constructor(
|
|
1345
|
-
this._ok = !1, this._ts = Date.now(), this._pt = 0,
|
|
2054
|
+
class y {
|
|
2055
|
+
constructor(e) {
|
|
2056
|
+
this._ok = !1, this._ts = Date.now(), this._pt = 0, e && this.setXData(e);
|
|
1346
2057
|
}
|
|
1347
2058
|
// ---------------------------------------------------------------------------
|
|
1348
2059
|
// Factories
|
|
1349
2060
|
// ---------------------------------------------------------------------------
|
|
1350
|
-
static create(
|
|
1351
|
-
return new
|
|
2061
|
+
static create(e) {
|
|
2062
|
+
return new y(e);
|
|
1352
2063
|
}
|
|
1353
|
-
static ok(
|
|
1354
|
-
return new
|
|
2064
|
+
static ok(e) {
|
|
2065
|
+
return new y({ _ok: !0, _result: e });
|
|
1355
2066
|
}
|
|
1356
|
-
static error(
|
|
1357
|
-
if (
|
|
1358
|
-
return new
|
|
2067
|
+
static error(e) {
|
|
2068
|
+
if (e instanceof K)
|
|
2069
|
+
return new y({
|
|
1359
2070
|
_ok: !1,
|
|
1360
|
-
_result:
|
|
2071
|
+
_result: e.toXData()
|
|
1361
2072
|
});
|
|
1362
|
-
const
|
|
2073
|
+
const t = new K(
|
|
1363
2074
|
"E_INTERNAL",
|
|
1364
|
-
|
|
1365
|
-
{ _cause:
|
|
2075
|
+
e?.message ?? String(e),
|
|
2076
|
+
{ _cause: e }
|
|
1366
2077
|
);
|
|
1367
|
-
return new
|
|
2078
|
+
return new y({
|
|
1368
2079
|
_ok: !1,
|
|
1369
|
-
_result:
|
|
2080
|
+
_result: t.toXData()
|
|
1370
2081
|
});
|
|
1371
2082
|
}
|
|
1372
2083
|
// ---------------------------------------------------------------------------
|
|
@@ -1393,37 +2104,37 @@ class d {
|
|
|
1393
2104
|
toString() {
|
|
1394
2105
|
return JSON.stringify(this.toXData());
|
|
1395
2106
|
}
|
|
1396
|
-
setXData(
|
|
1397
|
-
|
|
2107
|
+
setXData(e) {
|
|
2108
|
+
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));
|
|
1398
2109
|
}
|
|
1399
2110
|
}
|
|
1400
|
-
class
|
|
1401
|
-
constructor(
|
|
1402
|
-
super(
|
|
2111
|
+
class fe extends y {
|
|
2112
|
+
constructor(e) {
|
|
2113
|
+
super(y.error(e).toXData());
|
|
1403
2114
|
}
|
|
1404
2115
|
}
|
|
1405
|
-
class
|
|
1406
|
-
constructor(
|
|
1407
|
-
super({ _ok: !0, _result:
|
|
2116
|
+
class ge extends y {
|
|
2117
|
+
constructor(e) {
|
|
2118
|
+
super({ _ok: !0, _result: e });
|
|
1408
2119
|
}
|
|
1409
2120
|
}
|
|
1410
|
-
const
|
|
1411
|
-
class
|
|
1412
|
-
constructor(
|
|
1413
|
-
this._log_rules = {}, this._modules = {}, this._schedule_frame =
|
|
2121
|
+
const ce = "engine:frame-number", _e = "engine:fps";
|
|
2122
|
+
class le {
|
|
2123
|
+
constructor(e) {
|
|
2124
|
+
this._log_rules = {}, this._modules = {}, this._schedule_frame = e?._schedule_frame ?? l.createDefaultScheduler(e?._target_fps), this._version = "0.0.1", this._engine_id = l.guid(), this._frame_number = 0, this._fps_calc = new Y(), this.parser = w, this._modules = {}, c._enabled = !1, ne(this);
|
|
1414
2125
|
}
|
|
1415
2126
|
/**
|
|
1416
2127
|
* @deprecated use _verbose instead
|
|
1417
2128
|
* Enable Xpell logs to console
|
|
1418
2129
|
*/
|
|
1419
|
-
set verbose(
|
|
1420
|
-
|
|
2130
|
+
set verbose(e) {
|
|
2131
|
+
c._enabled = e;
|
|
1421
2132
|
}
|
|
1422
2133
|
/**
|
|
1423
2134
|
* Enable Xpell logs to console
|
|
1424
2135
|
*/
|
|
1425
|
-
set _verbose(
|
|
1426
|
-
|
|
2136
|
+
set _verbose(e) {
|
|
2137
|
+
c._enabled = e;
|
|
1427
2138
|
}
|
|
1428
2139
|
/**
|
|
1429
2140
|
* Logs message to console using Xpell logger
|
|
@@ -1432,36 +2143,52 @@ class L {
|
|
|
1432
2143
|
* @param msg
|
|
1433
2144
|
* @param optionalParams
|
|
1434
2145
|
*/
|
|
1435
|
-
log(
|
|
1436
|
-
|
|
2146
|
+
log(e, ...t) {
|
|
2147
|
+
c.log(e, ...t);
|
|
1437
2148
|
}
|
|
1438
2149
|
/**
|
|
1439
2150
|
* Delay the execution of the next command
|
|
1440
2151
|
* @param ms - delay in milliseconds
|
|
1441
2152
|
* @returns
|
|
1442
2153
|
*/
|
|
1443
|
-
async delay(
|
|
1444
|
-
return new Promise((
|
|
2154
|
+
async delay(e) {
|
|
2155
|
+
return new Promise((t) => setTimeout(t, e));
|
|
2156
|
+
}
|
|
2157
|
+
/**
|
|
2158
|
+
* Module management
|
|
2159
|
+
* Modules are the main building blocks of Xpell applications, providing specific functionality (UI, data, etc.)
|
|
2160
|
+
* loadModule() is fire-and-forget.
|
|
2161
|
+
* Use loadModuleAsync() for deterministic startup.
|
|
2162
|
+
*/
|
|
2163
|
+
addModule(e) {
|
|
2164
|
+
return this._modules.hasOwnProperty(e._name) ? (c.log("Module " + e._name + " already loaded"), !1) : (this._modules[e._name] = e, !0);
|
|
1445
2165
|
}
|
|
1446
2166
|
/**
|
|
1447
2167
|
* Loads Xpell module into the engine
|
|
1448
2168
|
* @param {XModule} xModule
|
|
1449
2169
|
*/
|
|
1450
|
-
loadModule(
|
|
1451
|
-
this.
|
|
2170
|
+
loadModule(e) {
|
|
2171
|
+
this.addModule(e) && e.load();
|
|
1452
2172
|
}
|
|
1453
2173
|
/**
|
|
1454
2174
|
* Loads multiple module at ones
|
|
1455
2175
|
* @param {Array<XModule>} xModulesArray
|
|
1456
2176
|
*/
|
|
1457
|
-
loadModules(...
|
|
1458
|
-
|
|
2177
|
+
loadModules(...e) {
|
|
2178
|
+
e.forEach((t) => this.loadModule(t));
|
|
2179
|
+
}
|
|
2180
|
+
async loadModuleAsync(e) {
|
|
2181
|
+
this.addModule(e) && await e.load();
|
|
2182
|
+
}
|
|
2183
|
+
async loadModulesAsync(...e) {
|
|
2184
|
+
for (const t of e)
|
|
2185
|
+
await this.loadModuleAsync(t);
|
|
1459
2186
|
}
|
|
1460
2187
|
/**
|
|
1461
2188
|
* Display information about the Xpell engine to the console
|
|
1462
2189
|
*/
|
|
1463
2190
|
info() {
|
|
1464
|
-
|
|
2191
|
+
c.log(`Xpell information:
|
|
1465
2192
|
- Engine Id: ` + this._engine_id + `
|
|
1466
2193
|
- Version ` + this._version);
|
|
1467
2194
|
}
|
|
@@ -1469,10 +2196,10 @@ class L {
|
|
|
1469
2196
|
* Run textual xCommand -
|
|
1470
2197
|
* @param {cmd} - text command
|
|
1471
2198
|
*/
|
|
1472
|
-
run(
|
|
1473
|
-
if (
|
|
1474
|
-
let
|
|
1475
|
-
return this.execute(
|
|
2199
|
+
run(e) {
|
|
2200
|
+
if (e?.length > 2) {
|
|
2201
|
+
let t = w.parse(e);
|
|
2202
|
+
return this.execute(t);
|
|
1476
2203
|
} else
|
|
1477
2204
|
throw "Unable to parse Xpell command";
|
|
1478
2205
|
}
|
|
@@ -1480,10 +2207,10 @@ class L {
|
|
|
1480
2207
|
* Execute Xpell Command
|
|
1481
2208
|
* @param {XCommand}
|
|
1482
2209
|
*/
|
|
1483
|
-
execute(
|
|
1484
|
-
if (
|
|
1485
|
-
return this._modules[
|
|
1486
|
-
throw "Xpell module " +
|
|
2210
|
+
execute(e) {
|
|
2211
|
+
if (e && e._module && this._modules[e._module])
|
|
2212
|
+
return this._modules[e._module].execute(e);
|
|
2213
|
+
throw "Xpell module " + e._module + " not loaded";
|
|
1487
2214
|
}
|
|
1488
2215
|
/**
|
|
1489
2216
|
* Main onFrame method
|
|
@@ -1491,63 +2218,85 @@ class L {
|
|
|
1491
2218
|
*/
|
|
1492
2219
|
onFrame() {
|
|
1493
2220
|
this._frame_number++;
|
|
1494
|
-
for (const
|
|
1495
|
-
const s = this._modules[
|
|
2221
|
+
for (const t of Object.keys(this._modules)) {
|
|
2222
|
+
const s = this._modules[t];
|
|
1496
2223
|
s?.onFrame && typeof s.onFrame == "function" && s.onFrame(this._frame_number);
|
|
1497
2224
|
}
|
|
1498
|
-
const
|
|
1499
|
-
|
|
2225
|
+
const e = this._fps_calc.calc();
|
|
2226
|
+
f.set(ce, this._frame_number, { source: "engine" }), f.set(_e, e, { source: "engine" }), f._compat_legacy_keys && (f.set("frame-number", this._frame_number, { source: "engine:legacy" }), f.set("fps", e, { source: "engine:legacy" })), this._schedule_frame(() => this.onFrame());
|
|
1500
2227
|
}
|
|
1501
2228
|
/**
|
|
1502
2229
|
* Gets Xpell module by name
|
|
1503
2230
|
* @param {string} moduleName - name of the loaded module
|
|
1504
2231
|
* @returns {XModule}
|
|
1505
2232
|
*/
|
|
1506
|
-
getModule(
|
|
1507
|
-
return this._modules[
|
|
2233
|
+
getModule(e) {
|
|
2234
|
+
return this._modules[e];
|
|
1508
2235
|
}
|
|
1509
2236
|
/**
|
|
1510
2237
|
* Start Xpell engine for web browsers using requestAnimationFrame
|
|
1511
2238
|
*/
|
|
1512
2239
|
start() {
|
|
1513
|
-
|
|
2240
|
+
c.log("Loading Xpell core modules...[xd, xem]"), this.loadModule(new L()), this.loadModule(new U()), c.log("Starting Xpell"), this.onFrame();
|
|
1514
2241
|
}
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
2242
|
+
getCoreSkills() {
|
|
2243
|
+
return [
|
|
2244
|
+
N,
|
|
2245
|
+
R
|
|
2246
|
+
];
|
|
2247
|
+
}
|
|
2248
|
+
getModuleSkills() {
|
|
2249
|
+
return Object.values(this._modules).flatMap(
|
|
2250
|
+
(e) => typeof e.getSkillChain == "function" ? e.getSkillChain() : []
|
|
2251
|
+
);
|
|
2252
|
+
}
|
|
2253
|
+
getSkills() {
|
|
2254
|
+
return {
|
|
2255
|
+
_runtime: {
|
|
2256
|
+
_engine_id: this._engine_id,
|
|
2257
|
+
_version: this._version
|
|
2258
|
+
},
|
|
2259
|
+
_skills: this.getCoreSkills(),
|
|
2260
|
+
_modules: Object.values(this._modules).map((e) => ({
|
|
2261
|
+
_name: e._name,
|
|
2262
|
+
_skills: typeof e.getSkillChain == "function" ? e.getSkillChain() : [],
|
|
2263
|
+
_objects: typeof e.getObjectSkills == "function" ? e.getObjectSkills() : []
|
|
2264
|
+
}))
|
|
2265
|
+
};
|
|
1520
2266
|
}
|
|
1521
2267
|
}
|
|
1522
|
-
const
|
|
2268
|
+
const be = new le();
|
|
1523
2269
|
export {
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
Q as
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
2270
|
+
I as XCommand,
|
|
2271
|
+
_e as XD_FPS,
|
|
2272
|
+
ce as XD_FRAME_NUMBER,
|
|
2273
|
+
x as XData,
|
|
2274
|
+
L as XDataModule,
|
|
2275
|
+
K as XError,
|
|
2276
|
+
U as XEventManagerModule,
|
|
2277
|
+
c as XLogger,
|
|
2278
|
+
A as XModule,
|
|
2279
|
+
F as XObject,
|
|
2280
|
+
te as XObjectManager,
|
|
2281
|
+
pe as XObjectPack,
|
|
2282
|
+
me as XParams,
|
|
2283
|
+
w as XParser,
|
|
2284
|
+
y as XResponse,
|
|
2285
|
+
fe as XResponseError,
|
|
2286
|
+
ge as XResponseOK,
|
|
2287
|
+
z as XUtils,
|
|
2288
|
+
be as Xpell,
|
|
2289
|
+
le as XpellEngine,
|
|
2290
|
+
ee as _XData,
|
|
2291
|
+
ue as _XEventManager,
|
|
2292
|
+
Z as _XLogger,
|
|
2293
|
+
Q as _XUtils,
|
|
2294
|
+
be as _x,
|
|
2295
|
+
f as _xd,
|
|
2296
|
+
c as _xlog,
|
|
2297
|
+
l as _xu,
|
|
2298
|
+
g as createNanoCommandWithSkill,
|
|
2299
|
+
be as default,
|
|
2300
|
+
D as getXEventManager,
|
|
2301
|
+
de as setXEventManager
|
|
1553
2302
|
};
|