@xpell/core 2.0.0-alpha.10 → 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.
@@ -1,14 +1,19 @@
1
- class X {
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(t, e) {
8
- if (!t) return e;
9
- const s = t.split(",").map((i) => i.trim()).filter(Boolean);
10
- for (const i of s) e[i] = "";
11
- return e;
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 X {
19
24
  * 3) Math.random() fallback (NOT crypto-secure, legacy fallback only)
20
25
  */
21
26
  guid() {
22
- const e = globalThis.crypto;
23
- if (e && typeof e.randomUUID == "function")
24
- return e.randomUUID();
25
- if (e && typeof e.getRandomValues == "function") {
26
- const r = new Uint8Array(16);
27
- e.getRandomValues(r), r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128;
28
- const a = Array.from(r, (c) => c.toString(16).padStart(2, "0"));
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"));
29
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(""), i = [];
32
- let n;
33
- i[8] = i[13] = i[18] = i[23] = "-", i[14] = "4";
34
- for (let r = 0; r < 36; r++)
35
- i[r] || (n = (0 | Math.random() * 16) >>> 0, i[r] = s[r === 19 ? n & 3 | 8 : n & 15]);
36
- return i.join("");
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 X {
41
46
  * @param defaults - defaults object
42
47
  * @param force - overwrite existing values
43
48
  */
44
- mergeDefaultsWithData(t, e, s = !1) {
45
- if (!t) return e;
46
- t._id || (t._id = t.id ?? this.guid());
47
- for (const i of Object.keys(e))
48
- (!(i in t) || s) && (t[i] = e[i]);
49
- return t;
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(t) {
55
- const e = globalThis;
56
- if (typeof e.btoa == "function") {
57
- const s = encodeURIComponent(String(t)).replace(
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
- (i, n) => String.fromCharCode(parseInt(n, 16))
64
+ (n, r) => String.fromCharCode(parseInt(r, 16))
60
65
  );
61
- return e.btoa(s);
66
+ return t.btoa(s);
62
67
  }
63
- if (e.Buffer && typeof e.Buffer.from == "function")
64
- return e.Buffer.from(String(t), "utf8").toString("base64");
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(t) {
71
- const e = globalThis;
72
- if (typeof e.atob == "function") {
73
- const s = e.atob(String(t)), i = Array.prototype.map.call(s, (n) => "%" + n.charCodeAt(0).toString(16).padStart(2, "0")).join("");
74
- return decodeURIComponent(i);
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 (e.Buffer && typeof e.Buffer.from == "function")
77
- return e.Buffer.from(String(t), "base64").toString("utf8");
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(t, e) {
85
- return t = Math.ceil(t), e = Math.floor(e), Math.floor(Math.random() * (e - t + 1)) + t;
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(t, e, s = 0) {
91
- return t?._params?.[e] ?? s;
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(t) {
99
- const e = globalThis;
100
- if (typeof e.requestAnimationFrame == "function")
101
- return (n) => e.requestAnimationFrame(n);
102
- const s = typeof t == "number" && isFinite(t) && t > 0 ? t : 60;
103
- if (typeof e.setImmediate == "function" && (!t || t >= 60))
104
- return (n) => e.setImmediate(n);
105
- const i = Math.max(1, Math.round(1e3 / s));
106
- return (n) => e.setTimeout(n, i);
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 p = new X();
110
- class k {
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(t = 0.05, e = 1) {
121
- const s = Number(t);
122
- this.#i = Number.isFinite(s) ? Math.min(1, Math.max(1e-3, s)) : 0.05;
123
- const i = Number(e);
124
- this.#n = Number.isFinite(i) ? Math.max(0, Math.floor(i)) : 1;
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 t = globalThis.performance;
128
- return t && typeof t.now == "function" ? t.now() : Date.now();
212
+ const e = globalThis.performance;
213
+ return e && typeof e.now == "function" ? e.now() : Date.now();
129
214
  }
130
215
  calc() {
131
- const t = this.now();
216
+ const e = this.now();
132
217
  if (this.#s === 0)
133
- return this.#s = t, this.#t;
134
- const e = t - this.#s;
135
- if (this.#s = t, !Number.isFinite(e) || e <= 0) return this.#t;
136
- this.#e === 0 ? this.#e = e : this.#e = (1 - this.#i) * this.#e + this.#i * e;
137
- const s = 1e3 / this.#e;
138
- if (!Number.isFinite(s) || s <= 0) return this.#t;
139
- const i = Math.round(s);
140
- return this.#t !== 0 && this.#n > 0 && Math.abs(i - this.#t) < this.#n ? this.#t : (this.#t = i, this.#t);
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.#t = 0, this.#e = 0, this.#s = 0;
228
+ this.#e = 0, this.#t = 0, this.#s = 0;
144
229
  }
145
230
  }
146
- class F {
147
- constructor(t) {
148
- this._enabled = !0, this._show_date = !1, this._show_time = !0, this._debug = !1, t && this.configure(t);
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(t) {
151
- typeof t._enabled == "boolean" && (this._enabled = t._enabled), typeof t._show_date == "boolean" && (this._show_date = t._show_date), typeof t._show_time == "boolean" && (this._show_time = t._show_time), typeof t._debug == "boolean" && (this._debug = t._debug);
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 t = /* @__PURE__ */ new Date(), e = this._show_date ? `${t.getDate()}.${t.getMonth()}.${t.getFullYear()} ` : "", s = this._show_time ? `${t.getHours()}:${t.getMinutes()}:${t.getSeconds()}.${t.getMilliseconds()}|` : "";
155
- return e + s;
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(t, ...e) {
158
- this._enabled && console.log(this._dt(), t, ...e);
242
+ log(e, ...t) {
243
+ this._enabled && console.log(this._dt(), e, ...t);
159
244
  }
160
- warn(t, ...e) {
161
- this._enabled && console.warn(this._dt(), t, ...e);
245
+ warn(e, ...t) {
246
+ this._enabled && console.warn(this._dt(), e, ...t);
162
247
  }
163
- error(t, ...e) {
164
- this._enabled && console.error(this._dt(), t, ...e);
248
+ error(e, ...t) {
249
+ this._enabled && console.error(this._dt(), e, ...t);
165
250
  }
166
- debug(t, ...e) {
167
- !this._enabled || !this._debug || console.debug(this._dt(), t, ...e);
251
+ debug(e, ...t) {
252
+ !this._enabled || !this._debug || console.debug(this._dt(), e, ...t);
168
253
  }
169
254
  }
170
- const _ = new F(), x = typeof process < "u" && !!process?.env && process.env.NODE_ENV === "production";
171
- x || console.info(
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 y = x ? _ : console;
175
- class S {
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 S {
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: (t, e, s) => {
187
- const i = String(e);
271
+ set: (e, t, s) => {
272
+ const n = String(t);
188
273
  return this._warn_legacy_writes && console.warn(
189
- `[XData] Legacy write: _o["${i}"] = ... ; prefer XData.set("${i}", value).`
190
- ), this._compat_writes ? this.set(i, s, { source: "legacy:_o" }) : t[i] = s, !0;
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: (t, e) => {
193
- const s = String(e);
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 t[s], !0;
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(t) {
202
- return this._objects[t];
286
+ get(e) {
287
+ return this._objects[e];
203
288
  }
204
289
  /** Preferred write API */
205
- set(t, e, s) {
206
- const i = this._objects[t];
207
- this._objects[t] = e, this._emit({ key: t, value: e, prev: i, ts: Date.now(), op: "set", meta: s });
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(t, e, s) {
211
- const i = this._objects[t], r = { ...i && typeof i == "object" ? i : {}, ...e };
212
- this._objects[t] = r, this._emit({ key: t, value: r, prev: i, ts: Date.now(), op: "patch", meta: s });
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(t, e) {
216
- const s = this._objects[t];
217
- this._emit({ key: t, value: s, prev: s, ts: Date.now(), op: "touch", meta: e });
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(t) {
220
- return Object.prototype.hasOwnProperty.call(this._objects, t);
304
+ has(e) {
305
+ return Object.prototype.hasOwnProperty.call(this._objects, e);
221
306
  }
222
- delete(t, e) {
223
- const s = this._objects[t];
224
- delete this._objects[t], this._emit({ key: t, value: void 0, prev: s, ts: Date.now(), op: "delete", meta: e });
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(t, e) {
227
- const s = this._objects[t];
228
- return this.delete(t, e), s;
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 S {
233
318
  // ----------------------------
234
319
  // Subscriptions
235
320
  // ----------------------------
236
- on(t, e) {
237
- let s = this._listeners.get(t);
238
- return s || this._listeners.set(t, s = /* @__PURE__ */ new Set()), s.add(e), () => this.off(t, e);
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(t, e) {
241
- const s = this._listeners.get(t);
242
- s && (s.delete(e), s.size === 0 && this._listeners.delete(t));
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(t) {
245
- return this._any_listeners.add(t), () => this._any_listeners.delete(t);
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(t) {
251
- this._verbose && t.meta?.trace && (t.stack = new Error().stack);
252
- const e = this._listeners.get(t.key);
253
- if (e) for (const s of e) s(t);
254
- for (const s of this._any_listeners) s(t);
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 u = new S();
258
- class M {
259
- constructor(t) {
260
- t && Object.keys(t).forEach((e) => {
261
- this[e] = t[e];
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,83 +356,83 @@ class M {
271
356
  * @param defaultValue the default value if none above exists
272
357
  * @returns {any} the actual parameter value
273
358
  */
274
- getParam(t, e, s) {
275
- return this._params?.hasOwnProperty(e) ? this._params[e] : this._params?.hasOwnProperty(t) ? this._params[t] : s;
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 w = {
363
+ const X = {
279
364
  type: "_type",
280
365
  children: "_children"
281
- }, f = class f {
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(t, e) {
288
- f.html2XMap.elements[t] = e;
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(t, e) {
295
- const s = t.split(" ");
296
- let i = new M();
297
- if (e ? (i._module = e, i._op = s[0]) : (i._module = s[0], i._op = s[1]), i._params = {}, s.length > 1)
298
- for (let n = 2; n < s.length; ++n) {
299
- const r = s[n];
300
- if (r.indexOf(":") > -1) {
301
- const c = r.split(":");
302
- i._params[c[0]] = c[1];
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
- i._params[n - 1] = s[n];
389
+ n._params[r - 1] = s[r];
305
390
  }
306
- return i;
391
+ return n;
307
392
  }
308
- static replaceSpacesInQuotes(t, e = "_%20_") {
309
- return t.replace(/(['"])(.*?)\1/g, (s, i, n) => {
310
- const r = String(n).replace(/\s/g, e);
311
- return `${i}${r}${i}`;
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(t, e) {
315
- t = f.replaceSpacesInQuotes(t);
316
- const s = t.trim().split(/\s+/), i = e || s.shift();
317
- if (!i) throw new Error("Missing module name");
318
- let n;
319
- if (s[0]?.startsWith("#") && (n = s.shift().slice(1), !n))
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 r = s.shift();
322
- if (!r) throw new Error("Missing operation");
406
+ const i = s.shift();
407
+ if (!i) throw new Error("Missing operation");
323
408
  const a = {};
324
- let c = null, h = null;
325
- if (s.forEach((l) => {
409
+ let _ = null, h = null;
410
+ if (s.forEach((u) => {
326
411
  if (h) {
327
- if (h += ` ${l}`, l.endsWith(h[0])) {
412
+ if (h += ` ${u}`, u.endsWith(h[0])) {
328
413
  const m = h.slice(1, -1).replace(/_%20_/g, " ");
329
- a[c] = m, h = null;
414
+ a[_] = m, h = null;
330
415
  }
331
416
  return;
332
417
  }
333
- if (l.startsWith('"') || l.startsWith("'")) {
334
- if (h = l, l.endsWith(l[0]) && l.length > 1) {
335
- const m = l.slice(1, -1).replace(/_%20_/g, " ");
336
- a[c] = m, h = null;
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 (l.includes(":")) {
341
- const m = l.split(":"), D = m[0], E = m.slice(1).join(":").replace(/_%20_/g, " ");
342
- a[D] = E, c = null;
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
- c = l.replace(/_%20_/g, " ");
430
+ _ = u.replace(/_%20_/g, " ");
346
431
  }), h) throw new Error("Unclosed quoted parameter value");
347
432
  return {
348
- _module: i,
349
- _object: n,
350
- _op: r,
433
+ _module: n,
434
+ _object: r,
435
+ _op: i,
351
436
  _params: a
352
437
  };
353
438
  }
@@ -356,9 +441,9 @@ const w = {
356
441
  * @param xmlString XML string
357
442
  * @returns
358
443
  */
359
- static xmlString2Xpell(t) {
360
- const s = new DOMParser().parseFromString(t, "text/xml");
361
- return s.childNodes.length > 0 ? f.xml2Xpell(s.childNodes[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(t, e) {
370
- const s = f.html2XMap;
371
- let i = {};
372
- i._children = [];
373
- const n = t.nodeName, r = t.nodeName;
374
- let a = e;
375
- if (e ? (i[w.type] = "xhtml", i._html_ns = "http://www.w3.org/2000/svg") : i._type = s.elements[n] ? s.elements[n] : n, t.attributes)
376
- for (let c = 0; c < t.attributes.length; ++c) {
377
- const h = t.attributes[c], l = s.attributes[h.name] ? s.attributes[h.name] : h.name;
378
- i[l] = h.value;
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 (t?.firstChild?.nodeValue && (i.text = t?.firstChild.nodeValue.trim()), i[w.type] == "xhtml" ? i._html_tag = r : i[w.type] == "svg" && (a = !0, i._html_ns = "http://www.w3.org/2000/svg"), t?.childNodes.length > 0)
381
- for (let c = 0; c < t.childNodes.length; ++c) {
382
- const h = t.childNodes[c];
383
- h.nodeName.startsWith("#") || i[w.children].push(f.xml2Xpell(h, a));
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 i;
470
+ return n;
386
471
  }
387
472
  };
388
- f.html2XMap = {
473
+ b.html2XMap = {
389
474
  elements: {
390
475
  div: "view",
391
476
  a: "link",
@@ -415,200 +500,500 @@ f.html2XMap = {
415
500
  id: "_id"
416
501
  }
417
502
  };
418
- let g = f;
419
- class I {
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(), a = {
437
- _id: r,
438
- _callback: e,
439
- _options: s,
440
- _owner: n,
441
- _tag: s?._tag
442
- };
443
- return this._events[t].push(a), 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 (a) {
463
- y.error(a);
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 I();
501
- class P {
502
- #t;
503
+ let w = b;
504
+ class te {
503
505
  #e;
506
+ #t;
504
507
  #s;
505
508
  constructor() {
506
- this.#t = {}, this.#e = {}, this.#s = {};
509
+ this.#e = {}, this.#t = {}, this.#s = {};
507
510
  }
508
511
  get _objects() {
509
- return this.#e;
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(t) {
517
- return this.#e.hasOwnProperty(t);
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(t) {
524
- Object.keys(t).forEach((s) => this.registerObject(s, t[s]));
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(t, e) {
532
- this.#t[t] = e;
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(t) {
540
- return this.#t.hasOwnProperty(t);
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(t) {
548
- return this.#t[t];
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.#t;
559
+ return this.getObjectClasses();
560
+ }
561
+ getObjectClasses() {
562
+ return this.#e;
556
563
  }
557
564
  get _classes() {
558
- return this.#t;
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(t) {
565
- t && t._id ? (this.#e[t._id] = t, (!t._name || t._name.length == 0) && (t._name = t._id), this.#s[t._name] = t._id) : _.log("unable to add object");
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(t) {
572
- const e = this.#e[t];
573
- e && (delete this.#s[e?._name], delete this.#e[t]);
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(t) {
581
- return this.#e[t];
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(t) {
589
- return this.getObject(t);
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(t) {
597
- return this.#s[t] ? this.getObject(this.#s[t]) : null;
603
+ getObjectByName(e) {
604
+ return this.#s[e] ? this.getObject(this.#s[e]) : null;
605
+ }
606
+ }
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 });
598
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 = [
698
+ "_nano_commands",
699
+ "_cache_cmd_txt",
700
+ "_cache_jcmd",
701
+ "_xporter",
702
+ "_event_listeners_ids",
703
+ "_parent",
704
+ "_children"
705
+ ];
706
+ function E(o) {
707
+ return se.includes(o);
708
+ }
709
+ function J(o) {
710
+ if (!o || typeof o != "object" || Array.isArray(o)) return !1;
711
+ const e = Object.getPrototypeOf(o);
712
+ return e === Object.prototype || e === null;
713
+ }
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."
738
+ }
739
+ }
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
+ }
769
+ }
770
+ }
771
+ ),
772
+ noop: g(
773
+ () => {
774
+ },
775
+ {
776
+ _name: "noop",
777
+ _scope: "object",
778
+ _description: "No-op command. Useful as a placeholder in sequences."
779
+ }
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
+ }
807
+ }
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
+ }
827
+ }
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
+ }
847
+ }
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;
856
+ }
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
+ ]
930
+ }
931
+ }
932
+ }
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 $;
599
943
  }
600
- const A = {
601
- info: (o, t) => {
602
- _.log("XObject id " + t?._id);
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."
603
966
  },
604
- log: (o, t) => {
605
- o._params && o._params[1] ? _.log(o._params[1]) : _.log(t);
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
+ ]
606
984
  },
607
- fire: (o, t) => {
608
- o._params && o._params[1] ? b.fire(o._params[1], o._params[2]) : o._params && o._params.event && b.fire(o._params.event, o._params.data);
609
- }
610
- }, j = { _children: "child nodes" };
611
- class v {
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 {
612
997
  /**
613
998
  * XObject constructor is creating the object and adding all the data keys to the XObject instance
614
999
  * @param data constructor input data (object)
@@ -616,7 +1001,7 @@ class v {
616
1001
  * @param skipParse - skip data parsing
617
1002
  * if override this method make sure to call super.init(data,skipParse) and to set skipParse to true
618
1003
  */
619
- constructor(t, e, s) {
1004
+ constructor(e, t, s) {
620
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 = {
621
1006
  _ignore_fields: [
622
1007
  "_to_xdata_ignore_fields",
@@ -637,14 +1022,46 @@ class v {
637
1022
  "_debug"
638
1023
  ],
639
1024
  _instance_xporters: {}
640
- }, e && p.mergeDefaultsWithData(t, e), this._id = t && t._id ? t._id : "xo-" + p.guid(), this._type = "object", this._children = [], this._nano_commands = {}, this.addNanoCommandPack(A), t && t.hasOwnProperty("_nano_commands") && t._nano_commands && (this.addNanoCommandPack(t._nano_commands), delete t._nano_commands), this.addXporterDataIgnoreFields(["_nano_commands"]), this.addXporterInstanceXporter(v, (i) => i.toXData()), this._xem_options = {
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 = {
641
1026
  // _instance:_xem
642
1027
  // _object: this
643
1028
  // _support_html: true
644
- }, !s && t && this.parse(t, j);
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
+ };
1040
+ }
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;
645
1044
  }
646
- log(t, ...e) {
647
- this._debug && t && _.log(this._type + "->" + this._id + "]", t, ...e);
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);
648
1065
  }
649
1066
  /**
650
1067
  * Initialize the XObject
@@ -652,82 +1069,72 @@ class v {
652
1069
  * @param skipParse - skip data parsing
653
1070
  * @deprecated - use parse method instead
654
1071
  */
655
- init(t, e) {
656
- !e && t && this.parse(t, j);
1072
+ init(e, t) {
1073
+ !t && e && this.parse(e, M);
657
1074
  }
658
- parseEvents(t) {
1075
+ parseEvents(e) {
659
1076
  if (!this._event_parsed) {
660
- t || (t = this._xem_options), Object.keys(this._on).forEach((s) => {
661
- this.addEventListener(s, this._on[s], t);
1077
+ e || (e = this._xem_options), Object.keys(this._on).forEach((s) => {
1078
+ this.addEventListener(s, this._on[s], e);
662
1079
  });
663
- const e = {};
664
- Object.assign(e, t), e._once = !0, Object.keys(this._once).forEach((s) => {
665
- this.addEventListener(s, this._once[s], e);
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);
666
1083
  }), this._event_parsed = !0;
667
1084
  }
668
1085
  }
669
- addEventListener(t, e, s) {
1086
+ addEventListener(e, t, s) {
670
1087
  s || (s = this._xem_options);
671
- let i;
672
- if (typeof e == "function")
673
- i = async (r) => {
674
- e(this, r);
675
- };
676
- else if (typeof e == "string")
677
- i = async (r) => {
678
- const a = this._id + " " + e + " event-data='" + JSON.stringify(r).replace(/'/g, "\\'") + "'";
679
- await this.run(a);
680
- };
681
- else
682
- throw new Error("event handler must be a function");
683
- const n = b.on(t, i, s, this);
684
- 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;
685
1092
  }
686
- removeEventListener(t) {
687
- const e = this._event_listeners_ids[t];
688
- e && e.length && (e.forEach((s) => {
689
- b.remove(s);
690
- }), delete this._event_listeners_ids[t]);
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]);
691
1098
  }
692
1099
  removeAllEventListeners() {
693
- Object.keys(this._event_listeners_ids).forEach((e) => this.removeEventListener(e));
1100
+ Object.keys(this._event_listeners_ids).forEach((t) => this.removeEventListener(t));
694
1101
  }
695
1102
  /**
696
1103
  * Append a child XObject to this XObject
697
1104
  * @param xobject
698
1105
  */
699
- append(t) {
700
- this._children?.push(t), t._parent = this;
1106
+ append(e) {
1107
+ this._children?.push(e), e._parent = this;
701
1108
  }
702
1109
  /**
703
1110
  * Add single nano command to the object
704
1111
  * @param commandName - the nano command name
705
1112
  * @param nanoCommandFunction
706
1113
  */
707
- addNanoCommand(t, e) {
708
- typeof e == "function" && (this._nano_commands[t] = e);
1114
+ addNanoCommand(e, t) {
1115
+ typeof t == "function" && (this._nano_commands[e] = t);
709
1116
  }
710
- addNanoCommandPack(t) {
711
- t && Object.keys(t).forEach((e) => {
712
- this.addNanoCommand(e, t[e]);
1117
+ addNanoCommandPack(e) {
1118
+ e && Object.keys(e).forEach((t) => {
1119
+ this.addNanoCommand(t, e[t]);
713
1120
  });
714
1121
  }
715
1122
  /**
716
1123
  * List of fields to ignore when exporting the xobject to XData or string format
717
1124
  * @param <string[]> ignoreFields - an array with all the fields to ignore
718
1125
  */
719
- addXporterDataIgnoreFields(t) {
720
- this._xporter._ignore_fields = this._xporter._ignore_fields.concat(t);
1126
+ addXporterDataIgnoreFields(e) {
1127
+ this._xporter._ignore_fields = this._xporter._ignore_fields.concat(e);
721
1128
  }
722
1129
  /**
723
1130
  * Add XData Xporter instance handler
724
1131
  * @param <XDataInstanceXporter> ie - the instance exporter object
725
1132
  */
726
- addXporterInstanceXporter(t, e) {
727
- const s = p.guid();
1133
+ addXporterInstanceXporter(e, t) {
1134
+ const s = l.guid();
728
1135
  this._xporter._instance_xporters[s] = {
729
- cls: t,
730
- handler: e
1136
+ cls: e,
1137
+ handler: t
731
1138
  };
732
1139
  }
733
1140
  /**
@@ -735,9 +1142,9 @@ class v {
735
1142
  * @param data data to parse
736
1143
  * @param ignore - lis of words to ignore in the parse process
737
1144
  */
738
- parse(t, e = j) {
739
- Object.keys(t).forEach((i) => {
740
- !e.hasOwnProperty(i) && t.hasOwnProperty(i) && (this[i] = t[i]);
1145
+ parse(e, t = M) {
1146
+ Object.keys(e).forEach((n) => {
1147
+ !t.hasOwnProperty(n) && e.hasOwnProperty(n) && (this[n] = e[n]);
741
1148
  });
742
1149
  }
743
1150
  /**
@@ -750,9 +1157,9 @@ class v {
750
1157
  * ...
751
1158
  * }
752
1159
  */
753
- parseFieldsFromXDataObject(t, e) {
754
- Object.keys(e).forEach((i) => {
755
- t.hasOwnProperty(i) ? this[i] = t[i] : this[i] = e[i];
1160
+ parseFieldsFromXDataObject(e, t) {
1161
+ Object.keys(t).forEach((n) => {
1162
+ e.hasOwnProperty(n) ? this[n] = e[n] : this[n] = t[n];
756
1163
  });
757
1164
  }
758
1165
  /**
@@ -761,13 +1168,13 @@ class v {
761
1168
  * @param {Array<string>} fields - array of field names (string)
762
1169
  * @param checkNonXParams - also check non Xpell fields (fields that not starting with "_" sign)
763
1170
  */
764
- parseFields(t, e, s) {
765
- e.forEach((i) => {
766
- if (t.hasOwnProperty(i))
767
- this[i] = t[i];
768
- else if (s && i.startsWith("_")) {
769
- const n = i.substring(1);
770
- t.hasOwnProperty(n) && (this[i] = t[n], this[n] = t[n]);
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]);
771
1178
  }
772
1179
  });
773
1180
  }
@@ -784,15 +1191,138 @@ class v {
784
1191
  async onCreate() {
785
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);
786
1193
  }
787
- async checkAndRunInternalFunction(t, ...e) {
788
- if (typeof t == "function")
789
- await t(this, ...e);
790
- else if (typeof t == "string")
791
- if (e.length > 0) {
792
- const s = e[0], i = JSON.stringify(s).replace(/'/g, "\\'");
793
- await this.run(`${this._id} ${t} data:'${i}'`);
794
- } else
795
- await this.run(`${this._id} ${t}`);
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;
1250
+ }
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);
1263
+ }
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;
1293
+ }
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
1299
+ );
1300
+ return;
1301
+ }
1302
+ const a = {
1303
+ ...r,
1304
+ _params: r._params ? { ...r._params } : {}
1305
+ };
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);
1321
+ }
1322
+ c.error(
1323
+ this._type + "->" + this._id + "] invalid handler in checkAndRunInternalFunction",
1324
+ e
1325
+ );
796
1326
  }
797
1327
  /**
798
1328
  * Triggers when the object is being mounted to other element
@@ -806,23 +1336,23 @@ class v {
806
1336
  async onMount() {
807
1337
  if (!this._mounted) {
808
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;
809
- for (const t of this._children)
810
- t.onMount && typeof t.onMount == "function" && t.onMount();
1339
+ for (const e of this._children)
1340
+ e.onMount && typeof e.onMount == "function" && e.onMount();
811
1341
  }
812
1342
  }
813
1343
  emptyDataSource() {
814
- const t = this._data_source;
815
- if (typeof t != "string" || t.length === 0) return;
816
- const e = this._type ?? this.constructor.name, s = this._id ?? "no-id";
817
- u.delete(t, { source: `${e}#${s}.emptyDataSource` });
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` });
818
1348
  }
819
1349
  /**
820
1350
  * Triggers when new data is being received from the data source
821
1351
  * @param data - the data
822
1352
  * if override this method make sure to call super.onData(data) to run the _on_data attribute
823
1353
  */
824
- async onData(t) {
825
- this._process_data && (this._on_data ? this.checkAndRunInternalFunction(this._on_data, t) : this._on && this._on.data ? this.checkAndRunInternalFunction(this._on.data, t) : this._once && this._once.data && this.checkAndRunInternalFunction(this._once.data, t));
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));
826
1356
  }
827
1357
  /**
828
1358
  * Triggers from Xpell frame every frame
@@ -844,19 +1374,19 @@ class v {
844
1374
  * _on_frame: "nano command text"
845
1375
  *
846
1376
  */
847
- async onFrame(t) {
848
- this._process_frame && (this._on_frame ? this.checkAndRunInternalFunction(this._on_frame, t) : this._on && this._on.frame ? this.checkAndRunInternalFunction(this._on.frame, t) : this._once && this._once.frame && this.checkAndRunInternalFunction(this._once.frame, t));
849
- for (const e of this._children)
850
- e.onFrame && typeof e.onFrame == "function" && e.onFrame(t);
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);
851
1381
  }
852
1382
  /**
853
1383
  * Runs object nano commands
854
1384
  * @param nanoCommand - object nano command (string)
855
1385
  * @param cache - cache last command to prevent multiple parsing on the same command
856
1386
  */
857
- async run(t, e = !0) {
858
- let s = this._cache_cmd_txt && this._cache_cmd_txt == t ? this._cache_jcmd : g.parseObjectCommand(t);
859
- e && (this._cache_cmd_txt = t, this._cache_jcmd = s), await this.execute(s);
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);
860
1390
  }
861
1391
  /**
862
1392
  * Execute XCommand within the XObject Nano Commands
@@ -869,39 +1399,62 @@ class v {
869
1399
  * }
870
1400
  *
871
1401
  */
872
- async execute(t) {
873
- if (t._op && this._nano_commands[t._op])
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)
1410
+ try {
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;
1420
+ }
1421
+ if (this._nano_commands[t])
874
1422
  try {
875
- await this._nano_commands[t._op](t, this);
876
- } catch (e) {
877
- _.error(this._id + " has error with command name " + t._op + " " + e);
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;
878
1432
  }
879
- else
880
- _.error(this._id + " has no command name " + t._op);
1433
+ c.error(this._id + " has no command name " + t);
881
1434
  }
882
1435
  /**
883
1436
  * Return an IXObjectData JSON representation of the XObject
884
1437
  * @returns IXObjectData
885
1438
  */
886
1439
  toXData() {
887
- const t = {};
888
- return Object.keys(this).forEach((e) => {
889
- if (!this._xporter._ignore_fields.includes(e) && this.hasOwnProperty(e) && this[e] !== void 0) {
890
- const s = this[e];
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];
891
1444
  if (typeof s == "function")
892
1445
  return;
893
1446
  if (typeof s == "object") {
894
- const i = Object.keys(this._xporter._instance_xporters);
895
- let n = !0;
896
- i.forEach((r) => {
897
- this._xporter._instance_xporters[r], s instanceof this._xporter._instance_xporters[r].cls && (t[e] = this._xporter._instance_xporters[r].handler(s), n = !1);
898
- }), n && (t[e] = s);
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);
899
1452
  } else
900
- t[e] = s;
1453
+ e[t] = s;
901
1454
  }
902
- }), t._children = [], this._children.length > 0 && this._children.forEach((e) => {
903
- typeof e.toXData == "function" && t._children?.push(e.toXData());
904
- }), t;
1455
+ }), e._children = [], this._children.length > 0 && this._children.forEach((t) => {
1456
+ typeof t.toXData == "function" && e._children?.push(t.toXData());
1457
+ }), e;
905
1458
  }
906
1459
  /**
907
1460
  * Return a string representation of the XObject
@@ -910,16 +1463,16 @@ class v {
910
1463
  toString() {
911
1464
  return JSON.stringify(this.toXData());
912
1465
  }
913
- clearAttributes(t) {
914
- t.forEach((e) => {
915
- this.hasOwnProperty(e) && (this[e] = null, delete this[e]);
1466
+ clearAttributes(e) {
1467
+ e.forEach((t) => {
1468
+ this.hasOwnProperty(t) && (this[t] = null, delete this[t]);
916
1469
  });
917
1470
  }
918
- bindDataSource(t, e) {
919
- const s = e?.initial ?? !0, i = t ?? this._data_source;
920
- typeof i != "string" || i.length === 0 || this._process_data && (this._xd_bound_key === i && this._xd_unsub || (this.unbindDataSource(), this._data_source = i, this._xd_bound_key = i, this._type ?? this.constructor.name, this._id, this._xd_unsub = u.on(i, async (n) => {
921
- await this.onData(n.value);
922
- }), s && u.has(i) && this.onData(u.get(i))));
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))));
923
1476
  }
924
1477
  unbindDataSource() {
925
1478
  this._xd_unsub?.(), this._xd_unsub = void 0, this._xd_bound_key = void 0;
@@ -929,11 +1482,11 @@ class v {
929
1482
  */
930
1483
  async dispose() {
931
1484
  if (this.unbindDataSource(), this._parent) {
932
- const t = this._parent._children.indexOf(this);
933
- t > -1 && this._parent._children.splice(t, 1);
1485
+ const e = this._parent._children.indexOf(this);
1486
+ e > -1 && this._parent._children.splice(e, 1);
934
1487
  }
935
- 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((t) => {
936
- typeof t.dispose == "function" && t.dispose();
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();
937
1490
  }), this._children = [];
938
1491
  }
939
1492
  /**
@@ -941,80 +1494,156 @@ class v {
941
1494
  * @param child - the child to
942
1495
  * @returns void
943
1496
  */
944
- removeChild(t, e = !1) {
945
- if (e)
946
- t.dispose();
1497
+ removeChild(e, t = !1) {
1498
+ if (t)
1499
+ e.dispose();
947
1500
  else {
948
- const s = this._children.indexOf(t);
949
- s > -1 && this._children.splice(s, 1), t._parent = null;
1501
+ const s = this._children.indexOf(e);
1502
+ s > -1 && this._children.splice(s, 1), e._parent = null;
950
1503
  }
951
1504
  }
952
1505
  /**
953
1506
  * @param child - the child to add
954
1507
  * @deprecated use append method instead
955
1508
  */
956
- addChild(t) {
957
- this.append(t);
1509
+ addChild(e) {
1510
+ this.append(e);
958
1511
  }
959
- }
960
- class B {
1512
+ };
1513
+ S._xtype = "object", S._skill = R;
1514
+ let F = S;
1515
+ class pe {
961
1516
  /**
962
1517
  * Get all registered object in this ObjectPack
963
1518
  * @returns XObject dictionary
964
1519
  */
965
1520
  static getObjects() {
966
1521
  return {
967
- object: v
1522
+ object: F
968
1523
  };
969
1524
  }
970
1525
  }
971
- const $ = "engine:module:num-of-objects:";
972
- class C {
973
- //engine: any; //deprecated remove after spell3d
974
- constructor(t) {
975
- this._log_rules = {
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 = {
976
1546
  createObject: !1,
977
1547
  removeObject: !1
978
- }, this.#t = new P(), this._name = t._name, this._id = p.guid();
1548
+ }, W(this, d, new te()), this._name = e._name, this._id = l.guid();
979
1549
  }
980
- #t;
981
- load() {
982
- _.log("Module " + this._name + " loaded");
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() {
983
1608
  }
984
1609
  /**
985
1610
  * Creates new XObject from data object
986
1611
  * @param data - The data of the new object (JSON)
987
1612
  * @return {XObject|*}
988
1613
  */
989
- create(t) {
990
- let e;
991
- if (t.hasOwnProperty("_type"))
992
- if (this.#t.hasObjectClass(t._type)) {
993
- let s = this.#t.getObjectClass(t._type);
994
- s.hasOwnProperty("defaults") && p.mergeDefaultsWithData(t, s.defaults), e = new s(t);
995
- } else
996
- throw "Xpell object '" + t._type + "' not found";
997
- else
998
- e = new v(t);
999
- return this.#t.addObject(e), t._children && t._children.forEach((s) => {
1000
- const i = this.create(s);
1001
- e.append(i);
1002
- }), e.onCreate(), e;
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;
1003
1632
  }
1004
1633
  /**
1005
1634
  * removes and XObject from the object manager
1006
1635
  * @param objectId op
1007
1636
  */
1008
- remove(t) {
1009
- const e = this.#t.getObject(t);
1010
- if (!e) return;
1011
- const s = [], i = (n) => {
1012
- n?._id && (s.push(n._id), (n._children ?? []).forEach((r) => i(r)));
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)));
1013
1642
  };
1014
- i(e), typeof e.dispose == "function" && e.dispose(), s.reverse().forEach((n) => this.#t.removeObject(n));
1643
+ n(t), typeof t.dispose == "function" && t.dispose(), s.reverse().forEach((r) => p(this, d).removeObject(r));
1015
1644
  }
1016
- _info(t) {
1017
- _.log("module info");
1645
+ _info(e) {
1646
+ c.log("module info");
1018
1647
  }
1019
1648
  //xpell interpreter
1020
1649
  /**
@@ -1023,11 +1652,11 @@ class C {
1023
1652
  * @param {string} XCommand input - text
1024
1653
  * @returns command execution result
1025
1654
  */
1026
- async run(t) {
1027
- if (t) {
1028
- let e = t.trim();
1029
- e.startsWith(this._name) || (e = this._name + " " + e);
1030
- let s = g.parse(e);
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);
1031
1660
  return await this.execute(s);
1032
1661
  } else
1033
1662
  throw "Unable to parse Xpell Command";
@@ -1038,32 +1667,32 @@ class C {
1038
1667
  * @returns command execution result
1039
1668
  */
1040
1669
  // inside XModule class
1041
- async execute(t) {
1042
- if (!t || !t._op)
1670
+ async execute(e) {
1671
+ if (!e || !e._op)
1043
1672
  throw new Error(`Invalid XCommand: missing _op (module: ${this._name})`);
1044
- const e = t._object;
1045
- if (e) {
1046
- const n = this.#t.getObject(e);
1047
- if (!n)
1048
- throw new Error(`Module '${this._name}' cant find object id: ${e}`);
1049
- return await n.execute(t);
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);
1050
1679
  }
1051
- const s = "_" + t._op.replaceAll("-", "_"), i = this[s];
1052
- if (typeof i == "function")
1053
- return await i.call(this, t);
1054
- throw new Error(`Module '${this._name}' cant find op: ${t._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}`);
1055
1684
  }
1056
1685
  /**
1057
1686
  * This method triggers every frame from the Xpell engine.
1058
1687
  * The method can be override by the extending module to support extended onFrame functionality
1059
1688
  * @param frameNumber Current frame number
1060
1689
  */
1061
- async onFrame(t) {
1062
- const e = this.#t._objects, s = Object.keys(e);
1063
- s.forEach((i) => {
1064
- const n = e[i];
1065
- n && n.onFrame && typeof n.onFrame == "function" && n?.onFrame(t);
1066
- }), u.set($ + this._id, s.length, {
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, {
1067
1696
  source: "xmodule"
1068
1697
  });
1069
1698
  }
@@ -1078,18 +1707,21 @@ class C {
1078
1707
  * getObject directly on the module instead of om.getObject
1079
1708
  */
1080
1709
  get om() {
1081
- return this.#t;
1710
+ return p(this, d);
1082
1711
  }
1083
1712
  get _object_manager() {
1084
- return this.#t;
1713
+ return p(this, d);
1085
1714
  }
1086
1715
  /**
1087
1716
  * Returns the XObject instance from the module Object Manager
1088
1717
  * @param objectId
1089
1718
  * @returns XObject
1090
1719
  */
1091
- getObject(t) {
1092
- return this.#t.getObject(t);
1720
+ getObject(e) {
1721
+ return p(this, d).getObject(e);
1722
+ }
1723
+ hasObject(e) {
1724
+ return p(this, d).hasObjectClass(e);
1093
1725
  }
1094
1726
  /**
1095
1727
  * Returns the XObject instance from the module Object Manager
@@ -1097,23 +1729,23 @@ class C {
1097
1729
  * xmodule._o["object-id"] is equivalent to xmodule.getObject("object-id")
1098
1730
  */
1099
1731
  get _o() {
1100
- return this.#t._objects;
1732
+ return p(this, d)._objects;
1101
1733
  }
1102
1734
  /**
1103
1735
  * Imports external object pack to the engine
1104
1736
  * The object class should be like XObjects with static implementation of getObjects() method
1105
1737
  * @param {XObjects} xObjectPack
1106
1738
  */
1107
- importObjectPack(t) {
1108
- this.#t.registerObjects(t.getObjects());
1739
+ importObjectPack(e) {
1740
+ p(this, d).registerObjects(e.getObjects());
1109
1741
  }
1110
1742
  /**
1111
1743
  * Imports external object pack to the engine
1112
1744
  * @deprecated - use importObjectPack instead
1113
1745
  * @param xObjectPack
1114
1746
  */
1115
- importObjects(t) {
1116
- this.importObjectPack(t);
1747
+ importObjects(e) {
1748
+ this.importObjectPack(e);
1117
1749
  }
1118
1750
  /**
1119
1751
  * Imports external objects to the engine
@@ -1121,19 +1753,19 @@ class C {
1121
1753
  * @param xObjectName
1122
1754
  * @param xObject
1123
1755
  */
1124
- importObject(t, e) {
1125
- this.#t.registerObject(t, e);
1756
+ importObject(e, t) {
1757
+ p(this, d).registerObject(e, t);
1126
1758
  }
1127
1759
  // In XModule
1128
- async _help(t) {
1129
- const e = t?._params?._op ?? t?._params?._command ?? "";
1130
- return this.help(e);
1760
+ async _help(e) {
1761
+ const t = e?._params?._op ?? e?._params?._command ?? "";
1762
+ return this.help(t);
1131
1763
  }
1132
1764
  /**
1133
1765
  * Override in modules to provide help text.
1134
1766
  * @param op optional: specific command name (e.g. "navigate")
1135
1767
  */
1136
- help(t) {
1768
+ help(e) {
1137
1769
  return {
1138
1770
  module: this._name,
1139
1771
  usage: `${this._name} help`,
@@ -1141,60 +1773,264 @@ class C {
1141
1773
  note: "No help() implemented for this module."
1142
1774
  };
1143
1775
  }
1144
- }
1145
- class L {
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 {
1146
1981
  /* -------------------------------------------------- */
1147
1982
  /* core helpers */
1148
1983
  /* -------------------------------------------------- */
1149
- static get(t, e, s) {
1150
- if (!t?._params) return s;
1151
- const i = t._params[e];
1152
- return i !== void 0 ? i : s;
1153
- }
1154
- static has(t, e) {
1155
- return t?._params && t._params[e] !== void 0;
1156
- }
1157
- static str(t, ...e) {
1158
- for (const s of e) {
1159
- const i = t?._params?.[s];
1160
- if (i != null)
1161
- return String(i);
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);
1162
1998
  }
1163
1999
  }
1164
2000
  /* -------------------------------------------------- */
1165
2001
  /* typed params */
1166
2002
  /* -------------------------------------------------- */
1167
- static bool(t, e, s = !1) {
1168
- const i = this.get(t, e, s);
1169
- if (typeof i == "boolean") return i;
1170
- if (typeof i == "number") return i !== 0;
1171
- if (typeof i == "string") {
1172
- const n = i.toLowerCase();
1173
- if (["1", "true", "yes", "on"].includes(n)) return !0;
1174
- if (["0", "false", "no", "off"].includes(n)) return !1;
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;
1175
2011
  }
1176
- return !!i;
2012
+ return !!r;
1177
2013
  }
1178
- static int(t, e, s = 0) {
1179
- const i = this.get(t, e, s), n = parseInt(String(i), 10);
1180
- return Number.isFinite(n) ? n : s;
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;
1181
2017
  }
1182
- static json(t, e, s) {
1183
- const i = this.get(t, e, s);
1184
- if (i == null) return s;
1185
- if (typeof i == "object") return i;
1186
- if (typeof i == "string")
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")
1187
2023
  try {
1188
- return JSON.parse(i);
2024
+ return JSON.parse(r);
1189
2025
  } catch {
1190
2026
  return s;
1191
2027
  }
1192
2028
  return s;
1193
2029
  }
1194
2030
  }
1195
- class O extends Error {
1196
- constructor(t, e, s) {
1197
- super(e), this.name = "XError", this._code = t, this._level = s?._level ?? "error", this._meta = s?._meta, this._cause = s?._cause;
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;
1198
2034
  }
1199
2035
  toXData() {
1200
2036
  return {
@@ -1215,33 +2051,33 @@ class O extends Error {
1215
2051
  };
1216
2052
  }
1217
2053
  }
1218
- class d {
1219
- constructor(t) {
1220
- this._ok = !1, this._ts = Date.now(), this._pt = 0, t && this.setXData(t);
2054
+ class y {
2055
+ constructor(e) {
2056
+ this._ok = !1, this._ts = Date.now(), this._pt = 0, e && this.setXData(e);
1221
2057
  }
1222
2058
  // ---------------------------------------------------------------------------
1223
2059
  // Factories
1224
2060
  // ---------------------------------------------------------------------------
1225
- static create(t) {
1226
- return new d(t);
2061
+ static create(e) {
2062
+ return new y(e);
1227
2063
  }
1228
- static ok(t) {
1229
- return new d({ _ok: !0, _result: t });
2064
+ static ok(e) {
2065
+ return new y({ _ok: !0, _result: e });
1230
2066
  }
1231
- static error(t) {
1232
- if (t instanceof O)
1233
- return new d({
2067
+ static error(e) {
2068
+ if (e instanceof K)
2069
+ return new y({
1234
2070
  _ok: !1,
1235
- _result: t.toXData()
2071
+ _result: e.toXData()
1236
2072
  });
1237
- const e = new O(
2073
+ const t = new K(
1238
2074
  "E_INTERNAL",
1239
- t?.message ?? String(t),
1240
- { _cause: t }
2075
+ e?.message ?? String(e),
2076
+ { _cause: e }
1241
2077
  );
1242
- return new d({
2078
+ return new y({
1243
2079
  _ok: !1,
1244
- _result: e.toXData()
2080
+ _result: t.toXData()
1245
2081
  });
1246
2082
  }
1247
2083
  // ---------------------------------------------------------------------------
@@ -1268,37 +2104,37 @@ class d {
1268
2104
  toString() {
1269
2105
  return JSON.stringify(this.toXData());
1270
2106
  }
1271
- setXData(t) {
1272
- t && ("_ok" in t && (this._ok = !!t._ok), "_ts" in t && typeof t._ts == "number" && (this._ts = t._ts), "_pt" in t && typeof t._pt == "number" && (this._pt = t._pt), "_result" in t && (this._result = t._result));
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));
1273
2109
  }
1274
2110
  }
1275
- class T extends d {
1276
- constructor(t) {
1277
- super(d.error(t).toXData());
2111
+ class fe extends y {
2112
+ constructor(e) {
2113
+ super(y.error(e).toXData());
1278
2114
  }
1279
2115
  }
1280
- class W extends d {
1281
- constructor(t) {
1282
- super({ _ok: !0, _result: t });
2116
+ class ge extends y {
2117
+ constructor(e) {
2118
+ super({ _ok: !0, _result: e });
1283
2119
  }
1284
2120
  }
1285
- const R = "engine:frame-number", N = "engine:fps";
1286
- class U {
1287
- constructor(t) {
1288
- this._log_rules = {}, this._modules = {}, this._schedule_frame = t?._schedule_frame ?? p.createDefaultScheduler(t?._target_fps), this._version = "0.0.1", this._engine_id = p.guid(), this._frame_number = 0, this._fps_calc = new k(), this.parser = g, this._modules = {}, b.fire("xpell-init"), _._enabled = !1;
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);
1289
2125
  }
1290
2126
  /**
1291
2127
  * @deprecated use _verbose instead
1292
2128
  * Enable Xpell logs to console
1293
2129
  */
1294
- set verbose(t) {
1295
- _._enabled = t;
2130
+ set verbose(e) {
2131
+ c._enabled = e;
1296
2132
  }
1297
2133
  /**
1298
2134
  * Enable Xpell logs to console
1299
2135
  */
1300
- set _verbose(t) {
1301
- _._enabled = t;
2136
+ set _verbose(e) {
2137
+ c._enabled = e;
1302
2138
  }
1303
2139
  /**
1304
2140
  * Logs message to console using Xpell logger
@@ -1307,36 +2143,52 @@ class U {
1307
2143
  * @param msg
1308
2144
  * @param optionalParams
1309
2145
  */
1310
- log(t, ...e) {
1311
- _.log(t, ...e);
2146
+ log(e, ...t) {
2147
+ c.log(e, ...t);
1312
2148
  }
1313
2149
  /**
1314
2150
  * Delay the execution of the next command
1315
2151
  * @param ms - delay in milliseconds
1316
2152
  * @returns
1317
2153
  */
1318
- async delay(t) {
1319
- return new Promise((e) => setTimeout(e, t));
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);
1320
2165
  }
1321
2166
  /**
1322
2167
  * Loads Xpell module into the engine
1323
2168
  * @param {XModule} xModule
1324
2169
  */
1325
- loadModule(t) {
1326
- this._modules.hasOwnProperty(t._name) ? _.log("Module " + t._name + " already loaded") : (this._modules[t._name] = t, t.load());
2170
+ loadModule(e) {
2171
+ this.addModule(e) && e.load();
1327
2172
  }
1328
2173
  /**
1329
2174
  * Loads multiple module at ones
1330
2175
  * @param {Array<XModule>} xModulesArray
1331
2176
  */
1332
- loadModules(...t) {
1333
- t.forEach((e) => this.loadModule(e));
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);
1334
2186
  }
1335
2187
  /**
1336
2188
  * Display information about the Xpell engine to the console
1337
2189
  */
1338
2190
  info() {
1339
- _.log(`Xpell information:
2191
+ c.log(`Xpell information:
1340
2192
  - Engine Id: ` + this._engine_id + `
1341
2193
  - Version ` + this._version);
1342
2194
  }
@@ -1344,10 +2196,10 @@ class U {
1344
2196
  * Run textual xCommand -
1345
2197
  * @param {cmd} - text command
1346
2198
  */
1347
- run(t) {
1348
- if (t?.length > 2) {
1349
- let e = g.parse(t);
1350
- return this.execute(e);
2199
+ run(e) {
2200
+ if (e?.length > 2) {
2201
+ let t = w.parse(e);
2202
+ return this.execute(t);
1351
2203
  } else
1352
2204
  throw "Unable to parse Xpell command";
1353
2205
  }
@@ -1355,10 +2207,10 @@ class U {
1355
2207
  * Execute Xpell Command
1356
2208
  * @param {XCommand}
1357
2209
  */
1358
- execute(t) {
1359
- if (t && t._module && this._modules[t._module])
1360
- return this._modules[t._module].execute(t);
1361
- throw "Xpell module " + t._module + " not loaded";
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";
1362
2214
  }
1363
2215
  /**
1364
2216
  * Main onFrame method
@@ -1366,63 +2218,85 @@ class U {
1366
2218
  */
1367
2219
  onFrame() {
1368
2220
  this._frame_number++;
1369
- for (const e of Object.keys(this._modules)) {
1370
- const s = this._modules[e];
2221
+ for (const t of Object.keys(this._modules)) {
2222
+ const s = this._modules[t];
1371
2223
  s?.onFrame && typeof s.onFrame == "function" && s.onFrame(this._frame_number);
1372
2224
  }
1373
- const t = this._fps_calc.calc();
1374
- u.set(R, this._frame_number, { source: "engine" }), u.set(N, t, { source: "engine" }), u._compat_legacy_keys && (u.set("frame-number", this._frame_number, { source: "engine:legacy" }), u.set("fps", t, { source: "engine:legacy" })), this._schedule_frame(() => this.onFrame());
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());
1375
2227
  }
1376
2228
  /**
1377
2229
  * Gets Xpell module by name
1378
2230
  * @param {string} moduleName - name of the loaded module
1379
2231
  * @returns {XModule}
1380
2232
  */
1381
- getModule(t) {
1382
- return this._modules[t];
2233
+ getModule(e) {
2234
+ return this._modules[e];
1383
2235
  }
1384
2236
  /**
1385
2237
  * Start Xpell engine for web browsers using requestAnimationFrame
1386
2238
  */
1387
2239
  start() {
1388
- _.log("Starting Xpell"), this.onFrame();
2240
+ c.log("Loading Xpell core modules...[xd, xem]"), this.loadModule(new L()), this.loadModule(new U()), c.log("Starting Xpell"), this.onFrame();
1389
2241
  }
1390
- /**
1391
- * deprecated - use XData._o directly
1392
- */
1393
- getParam(t, e) {
1394
- return t in u._o ? u._o[t] : e;
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
+ };
1395
2266
  }
1396
2267
  }
1397
- const J = new U();
2268
+ const be = new le();
1398
2269
  export {
1399
- M as XCommand,
1400
- N as XD_FPS,
1401
- R as XD_FRAME_NUMBER,
1402
- u as XData,
1403
- O as XError,
1404
- b as XEventManager,
1405
- _ as XLogger,
1406
- C as XModule,
1407
- v as XObject,
1408
- P as XObjectManager,
1409
- B as XObjectPack,
1410
- L as XParams,
1411
- g as XParser,
1412
- d as XResponse,
1413
- T as XResponseError,
1414
- W as XResponseOK,
1415
- p as XUtils,
1416
- J as Xpell,
1417
- U as XpellEngine,
1418
- S as _XData,
1419
- I as _XEventManager,
1420
- F as _XLogger,
1421
- X as _XUtils,
1422
- J as _x,
1423
- u as _xd,
1424
- b as _xem,
1425
- _ as _xlog,
1426
- p as _xu,
1427
- J as default
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
1428
2302
  };