@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.
- package/README.md +100 -61
- package/dist/XCommand.d.ts +2 -2
- package/dist/XData.d.ts +1 -0
- package/dist/XDataModule.d.ts +41 -0
- package/dist/XEvenetManagerModule.d.ts +10 -0
- package/dist/XEventManager.d.ts +3 -6
- package/dist/XModule.d.ts +14 -1
- package/dist/XNanoCommands.d.ts +6 -34
- package/dist/XObject.d.ts +28 -14
- package/dist/XObjectManager.d.ts +2 -0
- package/dist/XParams.d.ts +1 -1
- package/dist/XRuntime.d.ts +2 -0
- package/dist/XSkills.d.ts +47 -0
- package/dist/XUtils.d.ts +35 -0
- package/dist/Xpell.d.ts +31 -8
- package/dist/xpell-core.cjs.js +2 -2
- package/dist/xpell-core.es.js +1518 -644
- package/docs/Codex_Skills/SKILL.md +184 -0
- package/docs/Codex_Skills/SKILL_API_MAP.md +122 -0
- package/docs/Codex_Skills/SKILL_CHECKLIST.md +18 -0
- package/docs/nano-commands2.md +457 -0
- package/package.json +5 -5
package/dist/Xpell.d.ts
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
import XCommand, { XCommandData } from "./XCommand";
|
|
35
35
|
import { XFrameScheduler } from "./XUtils";
|
|
36
36
|
import XParser from "./XParser";
|
|
37
|
-
import XModule from "./XModule";
|
|
37
|
+
import { XModule } from "./XModule";
|
|
38
38
|
export declare const XD_FRAME_NUMBER = "engine:frame-number";
|
|
39
39
|
export declare const XD_FPS = "engine:fps";
|
|
40
40
|
/**
|
|
@@ -76,6 +76,13 @@ export declare class XpellEngine {
|
|
|
76
76
|
* @returns
|
|
77
77
|
*/
|
|
78
78
|
delay(ms: number): Promise<unknown>;
|
|
79
|
+
/**
|
|
80
|
+
* Module management
|
|
81
|
+
* Modules are the main building blocks of Xpell applications, providing specific functionality (UI, data, etc.)
|
|
82
|
+
* loadModule() is fire-and-forget.
|
|
83
|
+
* Use loadModuleAsync() for deterministic startup.
|
|
84
|
+
*/
|
|
85
|
+
private addModule;
|
|
79
86
|
/**
|
|
80
87
|
* Loads Xpell module into the engine
|
|
81
88
|
* @param {XModule} xModule
|
|
@@ -86,6 +93,8 @@ export declare class XpellEngine {
|
|
|
86
93
|
* @param {Array<XModule>} xModulesArray
|
|
87
94
|
*/
|
|
88
95
|
loadModules(...xModulesArray: Array<XModule>): void;
|
|
96
|
+
loadModuleAsync(xModule: XModule): Promise<void>;
|
|
97
|
+
loadModulesAsync(...xModulesArray: Array<XModule>): Promise<void>;
|
|
89
98
|
/**
|
|
90
99
|
* Display information about the Xpell engine to the console
|
|
91
100
|
*/
|
|
@@ -115,10 +124,20 @@ export declare class XpellEngine {
|
|
|
115
124
|
* Start Xpell engine for web browsers using requestAnimationFrame
|
|
116
125
|
*/
|
|
117
126
|
start(): void;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
127
|
+
getCoreSkills(): import("./XSkills").XpellSkill[];
|
|
128
|
+
getModuleSkills(): any[];
|
|
129
|
+
getSkills(): {
|
|
130
|
+
_runtime: {
|
|
131
|
+
_engine_id: string;
|
|
132
|
+
_version: string;
|
|
133
|
+
};
|
|
134
|
+
_skills: import("./XSkills").XpellSkill[];
|
|
135
|
+
_modules: {
|
|
136
|
+
_name: any;
|
|
137
|
+
_skills: any;
|
|
138
|
+
_objects: any;
|
|
139
|
+
}[];
|
|
140
|
+
};
|
|
122
141
|
}
|
|
123
142
|
/**
|
|
124
143
|
* Xpell Engine instance
|
|
@@ -127,16 +146,20 @@ export declare class XpellEngine {
|
|
|
127
146
|
export declare const Xpell: XpellEngine;
|
|
128
147
|
export default Xpell;
|
|
129
148
|
export { Xpell as _x };
|
|
130
|
-
export {
|
|
131
|
-
export { XData,
|
|
149
|
+
export { _XUtils, XUtils, _xu, type XFrameScheduler } from "./XUtils";
|
|
150
|
+
export { XData, _xd, type XDataStore, _XData } from "./XData";
|
|
151
|
+
export { XDataModule } from "./XDataModule";
|
|
132
152
|
export { XParser } from "./XParser";
|
|
133
153
|
export { XCommand, type XCommandData } from "./XCommand";
|
|
134
154
|
export { XLogger, XLogger as _xlog, _XLogger } from "./XLogger";
|
|
135
155
|
export { XModule, type XModuleData, } from "./XModule";
|
|
136
156
|
export { XObject, XObjectPack, type XValue, type IXData, type XDataXporter, type XDataXporterHandler, type XObjectData, type XObjectOnEventIndex, type XObjectOnEventHandler } from "./XObject";
|
|
137
157
|
export { XObjectManager } from "./XObjectManager";
|
|
138
|
-
export {
|
|
158
|
+
export { setXEventManager, getXEventManager, _XEventManager, type XEventListener, type XEventListenerOptions, } from "./XEventManager.js";
|
|
159
|
+
export { XEventManagerModule } from "./XEvenetManagerModule";
|
|
139
160
|
export { type XNanoCommandPack, type XNanoCommand } from "./XNanoCommands";
|
|
161
|
+
export { createNanoCommandWithSkill } from "./XNanoCommands";
|
|
140
162
|
export { XParams } from "./XParams";
|
|
141
163
|
export { XError, type XErrorOptions, type XErrorLevel, type XErrorMeta } from "./XError";
|
|
142
164
|
export { type XResponseData, XResponse, XResponseOK, XResponseError } from "./XProtocol";
|
|
165
|
+
export type { XpellSkill, XpellSkillType, XpellSkillCommand, XpellSkillModule } from "./XSkills";
|
package/dist/xpell-core.cjs.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class x{createIgnoreList(t,e){if(!t)return e;const s=t.split(",").map(i=>i.trim()).filter(Boolean);for(const i of s)e[i]="";return e}guid(){const e=globalThis.crypto;if(e&&typeof e.randomUUID=="function")return e.randomUUID();if(e&&typeof e.getRandomValues=="function"){const r=new Uint8Array(16);e.getRandomValues(r),r[6]=r[6]&15|64,r[8]=r[8]&63|128;const a=Array.from(r,_=>_.toString(16).padStart(2,"0"));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("")}const s="0123456789abcdef".split(""),i=[];let n;i[8]=i[13]=i[18]=i[23]="-",i[14]="4";for(let r=0;r<36;r++)i[r]||(n=(0|Math.random()*16)>>>0,i[r]=s[r===19?n&3|8:n&15]);return i.join("")}mergeDefaultsWithData(t,e,s=!1){if(!t)return e;t._id||(t._id=t.id??this.guid());for(const i of Object.keys(e))(!(i in t)||s)&&(t[i]=e[i]);return t}encode(t){const e=globalThis;if(typeof e.btoa=="function"){const s=encodeURIComponent(String(t)).replace(/%([0-9A-F]{2})/g,(i,n)=>String.fromCharCode(parseInt(n,16)));return e.btoa(s)}if(e.Buffer&&typeof e.Buffer.from=="function")return e.Buffer.from(String(t),"utf8").toString("base64");throw new Error("Base64 encode not supported in this environment")}decode(t){const e=globalThis;if(typeof e.atob=="function"){const s=e.atob(String(t)),i=Array.prototype.map.call(s,n=>"%"+n.charCodeAt(0).toString(16).padStart(2,"0")).join("");return decodeURIComponent(i)}if(e.Buffer&&typeof e.Buffer.from=="function")return e.Buffer.from(String(t),"base64").toString("utf8");throw new Error("Base64 decode not supported in this environment")}getRandomInt(t,e){return t=Math.ceil(t),e=Math.floor(e),Math.floor(Math.random()*(e-t+1))+t}getParam(t,e,s=0){return t?._params?.[e]??s}createDefaultScheduler(t){const e=globalThis;if(typeof e.requestAnimationFrame=="function")return n=>e.requestAnimationFrame(n);const s=typeof t=="number"&&isFinite(t)&&t>0?t:60;if(typeof e.setImmediate=="function"&&(!t||t>=60))return n=>e.setImmediate(n);const i=Math.max(1,Math.round(1e3/s));return n=>e.setTimeout(n,i)}}const f=new x;class N{#t=0;#e=0;#s=0;#i;#n;constructor(t=.05,e=1){const s=Number(t);this.#i=Number.isFinite(s)?Math.min(1,Math.max(.001,s)):.05;const i=Number(e);this.#n=Number.isFinite(i)?Math.max(0,Math.floor(i)):1}now(){const t=globalThis.performance;return t&&typeof t.now=="function"?t.now():Date.now()}calc(){const t=this.now();if(this.#s===0)return this.#s=t,this.#t;const e=t-this.#s;if(this.#s=t,!Number.isFinite(e)||e<=0)return this.#t;this.#e===0?this.#e=e:this.#e=(1-this.#i)*this.#e+this.#i*e;const s=1e3/this.#e;if(!Number.isFinite(s)||s<=0)return this.#t;const i=Math.round(s);return this.#t!==0&&this.#n>0&&Math.abs(i-this.#t)<this.#n?this.#t:(this.#t=i,this.#t)}reset(){this.#t=0,this.#e=0,this.#s=0}}class E{constructor(t){this._enabled=!0,this._show_date=!1,this._show_time=!0,this._debug=!1,t&&this.configure(t)}configure(t){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)}_dt(){const t=new Date,e=this._show_date?`${t.getDate()}.${t.getMonth()}.${t.getFullYear()} `:"",s=this._show_time?`${t.getHours()}:${t.getMinutes()}:${t.getSeconds()}.${t.getMilliseconds()}|`:"";return e+s}log(t,...e){this._enabled&&console.log(this._dt(),t,...e)}warn(t,...e){this._enabled&&console.warn(this._dt(),t,...e)}error(t,...e){this._enabled&&console.error(this._dt(),t,...e)}debug(t,...e){!this._enabled||!this._debug||console.debug(this._dt(),t,...e)}}const c=new E,D=typeof process<"u"&&!!process?.env&&process.env.NODE_ENV==="production";D||console.info("[Xpell] _xlog is redirected to console in development mode. Tip: enable 'Show timestamps' in DevTools → Console for timed logs.");const w=D?c:console;class k{constructor(){this._objects={},this._listeners=new Map,this._any_listeners=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={}}get _o(){return!this._compat_writes&&!this._warn_legacy_writes?this._objects:(this._o_proxy||(this._o_proxy=new Proxy(this._objects,{set:(t,e,s)=>{const i=String(e);return this._warn_legacy_writes&&console.warn(`[XData] Legacy write: _o["${i}"] = ... ; prefer XData.set("${i}", value).`),this._compat_writes?this.set(i,s,{source:"legacy:_o"}):t[i]=s,!0},deleteProperty:(t,e)=>{const s=String(e);return this._warn_legacy_writes&&console.warn(`[XData] Legacy delete: delete _o["${s}"] ; prefer XData.delete("${s}").`),this._compat_writes?this.delete(s,{source:"legacy:_o"}):delete t[s],!0}})),this._o_proxy)}get(t){return this._objects[t]}set(t,e,s){const i=this._objects[t];this._objects[t]=e,this._emit({key:t,value:e,prev:i,ts:Date.now(),op:"set",meta:s})}patch(t,e,s){const i=this._objects[t],r={...i&&typeof i=="object"?i:{},...e};this._objects[t]=r,this._emit({key:t,value:r,prev:i,ts:Date.now(),op:"patch",meta:s})}touch(t,e){const s=this._objects[t];this._emit({key:t,value:s,prev:s,ts:Date.now(),op:"touch",meta:e})}has(t){return Object.prototype.hasOwnProperty.call(this._objects,t)}delete(t,e){const s=this._objects[t];delete this._objects[t],this._emit({key:t,value:void 0,prev:s,ts:Date.now(),op:"delete",meta:e})}pick(t,e){const s=this._objects[t];return this.delete(t,e),s}clean(){this._objects={}}on(t,e){let s=this._listeners.get(t);return s||this._listeners.set(t,s=new Set),s.add(e),()=>this.off(t,e)}off(t,e){const s=this._listeners.get(t);s&&(s.delete(e),s.size===0&&this._listeners.delete(t))}onAny(t){return this._any_listeners.add(t),()=>this._any_listeners.delete(t)}_emit(t){this._verbose&&t.meta?.trace&&(t.stack=new Error().stack);const e=this._listeners.get(t.key);if(e)for(const s of e)s(t);for(const s of this._any_listeners)s(t)}}const u=new k;class F{constructor(t){t&&Object.keys(t).forEach(e=>{this[e]=t[e]}),this.d||(this.d=Date.now())}getParam(t,e,s){return this._params?.hasOwnProperty(e)?this._params[e]:this._params?.hasOwnProperty(t)?this._params[t]:s}}const v={type:"_type",children:"_children"},p=class p{static addHtml2XpellMapItem(t,e){p.html2XMap.elements[t]=e}static parse(t,e){const s=t.split(" ");let i=new F;if(e?(i._module=e,i._op=s[0]):(i._module=s[0],i._op=s[1]),i._params={},s.length>1)for(let n=2;n<s.length;++n){const r=s[n];if(r.indexOf(":")>-1){const _=r.split(":");i._params[_[0]]=_[1]}else i._params[n-1]=s[n]}return i}static replaceSpacesInQuotes(t,e="_%20_"){return t.replace(/(['"])(.*?)\1/g,(s,i,n)=>{const r=String(n).replace(/\s/g,e);return`${i}${r}${i}`})}static parseObjectCommand(t,e){t=p.replaceSpacesInQuotes(t);const s=t.trim().split(/\s+/),i=e||s.shift();if(!i)throw new Error("Missing module name");let n;if(s[0]?.startsWith("#")&&(n=s.shift().slice(1),!n))throw new Error("Invalid object selector '#'. Use '#<id>'");const r=s.shift();if(!r)throw new Error("Missing operation");const a={};let _=null,h=null;if(s.forEach(l=>{if(h){if(h+=` ${l}`,l.endsWith(h[0])){const b=h.slice(1,-1).replace(/_%20_/g," ");a[_]=b,h=null}return}if(l.startsWith('"')||l.startsWith("'")){if(h=l,l.endsWith(l[0])&&l.length>1){const b=l.slice(1,-1).replace(/_%20_/g," ");a[_]=b,h=null}return}if(l.includes(":")){const b=l.split(":"),$=b[0],R=b.slice(1).join(":").replace(/_%20_/g," ");a[$]=R,_=null;return}_=l.replace(/_%20_/g," ")}),h)throw new Error("Unclosed quoted parameter value");return{_module:i,_object:n,_op:r,_params:a}}static xmlString2Xpell(t){const s=new DOMParser().parseFromString(t,"text/xml");return s.childNodes.length>0?p.xml2Xpell(s.childNodes[0]):{}}static xml2Xpell(t,e){const s=p.html2XMap;let i={};i._children=[];const n=t.nodeName,r=t.nodeName;let a=e;if(e?(i[v.type]="xhtml",i._html_ns="http://www.w3.org/2000/svg"):i._type=s.elements[n]?s.elements[n]:n,t.attributes)for(let _=0;_<t.attributes.length;++_){const h=t.attributes[_],l=s.attributes[h.name]?s.attributes[h.name]:h.name;i[l]=h.value}if(t?.firstChild?.nodeValue&&(i.text=t?.firstChild.nodeValue.trim()),i[v.type]=="xhtml"?i._html_tag=r:i[v.type]=="svg"&&(a=!0,i._html_ns="http://www.w3.org/2000/svg"),t?.childNodes.length>0)for(let _=0;_<t.childNodes.length;++_){const h=t.childNodes[_];h.nodeName.startsWith("#")||i[v.children].push(p.xml2Xpell(h,a))}return i}};p.html2XMap={elements:{div:"view",a:"link",b:"xhtml",h1:"xhtml",h2:"xhtml",h3:"xhtml",h4:"xhtml",h5:"xhtml",p:"xhtml",small:"xhtml",aside:"xhtml",span:"xhtml",table:"xhtml",th:"xhtml",td:"xhtml",tr:"xhtml",thead:"xhtml",tbody:"xhtml",ul:"xhtml",li:"xhtml",ol:"xhtml",canvas:"xhtml",img:"image"},attributes:{id:"_id"}};let m=p;class M{constructor(){this._log_rules={register:!1,remove:!1,fire:!1},this._events={},this._listener_index={}}on(t,e,s={},i){this._events[t]||(this._events[t]=[]);const n=s?._owner??i,r=f.guid(),a={_id:r,_callback:e,_options:s,_owner:n,_tag:s?._tag};return this._events[t].push(a),this._listener_index[r]=t,this._log_rules.register&&w.log("XEM Register",t,r),r}once(t,e,s){return this.on(t,e,{_once:!0,_owner:s})}async fire(t,e){const s=this._events[t];if(!s||s.length===0)return;this._log_rules.fire&&w.log("XEM Fire",t,e);const i=s.slice(),n=[];for(const r of i){try{r&&r._callback&&r._callback(e)}catch(a){w.error(a)}r?._options?._once&&n.push(r._id)}for(const r of n)this.remove(r)}remove(t){const e=this._listener_index[t];if(!e)return;const s=this._events[e];if(s&&s.length){const i=s.findIndex(n=>n?._id===t);i>=0&&s.splice(i,1),s.length===0&&delete this._events[e]}delete this._listener_index[t],this._log_rules.remove&&w.log("XEM Remove",e,t)}removeOwner(t){if(!t)return;const e=[];for(const s of Object.values(this._events))for(const i of s)(i?._owner??i?._options?._owner)===t&&e.push(i._id);e.forEach(s=>this.remove(s))}clear(){this._events={},this._listener_index={}}}const g=new M;class S{#t;#e;#s;constructor(){this.#t={},this.#e={},this.#s={}}get _objects(){return this.#e}hasObject(t){return this.#e.hasOwnProperty(t)}registerObjects(t){Object.keys(t).forEach(s=>this.registerObject(s,t[s]))}registerObject(t,e){this.#t[t]=e}hasObjectClass(t){return this.#t.hasOwnProperty(t)}getObjectClass(t){return this.#t[t]}getAllClasses(){return this.#t}get _classes(){return this.#t}addObject(t){t&&t._id?(this.#e[t._id]=t,(!t._name||t._name.length==0)&&(t._name=t._id),this.#s[t._name]=t._id):c.log("unable to add object")}removeObject(t){const e=this.#e[t];e&&(delete this.#s[e?._name],delete this.#e[t])}getObject(t){return this.#e[t]}go(t){return this.getObject(t)}getObjectByName(t){return this.#s[t]?this.getObject(this.#s[t]):null}}const U={info:(o,t)=>{c.log("XObject id "+t?._id)},log:(o,t)=>{o._params&&o._params[1]?c.log(o._params[1]):c.log(t)},fire:(o,t)=>{o._params&&o._params[1]?g.fire(o._params[1],o._params[2]):o._params&&o._params.event&&g.fire(o._params.event,o._params.data)}},j={_children:"child nodes"};class y{constructor(t,e,s){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={_ignore_fields:["_to_xdata_ignore_fields","_xporter","_children","_on","_once","_on_create","_on_mount","_on_frame","_on_data","_process_frame","_process_data","_parent","_event_listeners_ids","_event_parsed","_mounted","_debug"],_instance_xporters:{}},e&&f.mergeDefaultsWithData(t,e),this._id=t&&t._id?t._id:"xo-"+f.guid(),this._type="object",this._children=[],this._nano_commands={},this.addNanoCommandPack(U),t&&t.hasOwnProperty("_nano_commands")&&t._nano_commands&&(this.addNanoCommandPack(t._nano_commands),delete t._nano_commands),this.addXporterDataIgnoreFields(["_nano_commands"]),this.addXporterInstanceXporter(y,i=>i.toXData()),this._xem_options={},!s&&t&&this.parse(t,j)}log(t,...e){this._debug&&t&&c.log(this._type+"->"+this._id+"]",t,...e)}init(t,e){!e&&t&&this.parse(t,j)}parseEvents(t){if(!this._event_parsed){t||(t=this._xem_options),Object.keys(this._on).forEach(s=>{this.addEventListener(s,this._on[s],t)});const e={};Object.assign(e,t),e._once=!0,Object.keys(this._once).forEach(s=>{this.addEventListener(s,this._once[s],e)}),this._event_parsed=!0}}addEventListener(t,e,s){s||(s=this._xem_options);let i;if(typeof e=="function")i=async r=>{e(this,r)};else if(typeof e=="string")i=async r=>{const a=this._id+" "+e+" event-data='"+JSON.stringify(r).replace(/'/g,"\\'")+"'";await this.run(a)};else throw new Error("event handler must be a function");const n=g.on(t,i,s,this);this._event_listeners_ids[t]||(this._event_listeners_ids[t]=[]),this._event_listeners_ids[t].push(n)}removeEventListener(t){const e=this._event_listeners_ids[t];e&&e.length&&(e.forEach(s=>{g.remove(s)}),delete this._event_listeners_ids[t])}removeAllEventListeners(){Object.keys(this._event_listeners_ids).forEach(e=>this.removeEventListener(e))}append(t){this._children?.push(t),t._parent=this}addNanoCommand(t,e){typeof e=="function"&&(this._nano_commands[t]=e)}addNanoCommandPack(t){t&&Object.keys(t).forEach(e=>{this.addNanoCommand(e,t[e])})}addXporterDataIgnoreFields(t){this._xporter._ignore_fields=this._xporter._ignore_fields.concat(t)}addXporterInstanceXporter(t,e){const s=f.guid();this._xporter._instance_xporters[s]={cls:t,handler:e}}parse(t,e=j){Object.keys(t).forEach(i=>{!e.hasOwnProperty(i)&&t.hasOwnProperty(i)&&(this[i]=t[i])})}parseFieldsFromXDataObject(t,e){Object.keys(e).forEach(i=>{t.hasOwnProperty(i)?this[i]=t[i]:this[i]=e[i]})}parseFields(t,e,s){e.forEach(i=>{if(t.hasOwnProperty(i))this[i]=t[i];else if(s&&i.startsWith("_")){const n=i.substring(1);t.hasOwnProperty(n)&&(this[i]=t[n],this[n]=t[n])}})}async onCreate(){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)}async checkAndRunInternalFunction(t,...e){if(typeof t=="function")await t(this,...e);else if(typeof t=="string")if(e.length>0){const s=e[0],i=JSON.stringify(s).replace(/'/g,"\\'");await this.run(`${this._id} ${t} data:'${i}'`)}else await this.run(`${this._id} ${t}`)}async onMount(){if(!this._mounted){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;for(const t of this._children)t.onMount&&typeof t.onMount=="function"&&t.onMount()}}emptyDataSource(){const t=this._data_source;if(typeof t!="string"||t.length===0)return;const e=this._type??this.constructor.name,s=this._id??"no-id";u.delete(t,{source:`${e}#${s}.emptyDataSource`})}async onData(t){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))}async onFrame(t){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));for(const e of this._children)e.onFrame&&typeof e.onFrame=="function"&&e.onFrame(t)}async run(t,e=!0){let s=this._cache_cmd_txt&&this._cache_cmd_txt==t?this._cache_jcmd:m.parseObjectCommand(t);e&&(this._cache_cmd_txt=t,this._cache_jcmd=s),await this.execute(s)}async execute(t){if(t._op&&this._nano_commands[t._op])try{await this._nano_commands[t._op](t,this)}catch(e){c.error(this._id+" has error with command name "+t._op+" "+e)}else c.error(this._id+" has no command name "+t._op)}toXData(){const t={};return Object.keys(this).forEach(e=>{if(!this._xporter._ignore_fields.includes(e)&&this.hasOwnProperty(e)&&this[e]!==void 0){const s=this[e];if(typeof s=="function")return;if(typeof s=="object"){const i=Object.keys(this._xporter._instance_xporters);let n=!0;i.forEach(r=>{this._xporter._instance_xporters[r],s instanceof this._xporter._instance_xporters[r].cls&&(t[e]=this._xporter._instance_xporters[r].handler(s),n=!1)}),n&&(t[e]=s)}else t[e]=s}}),t._children=[],this._children.length>0&&this._children.forEach(e=>{typeof e.toXData=="function"&&t._children?.push(e.toXData())}),t}toString(){return JSON.stringify(this.toXData())}clearAttributes(t){t.forEach(e=>{this.hasOwnProperty(e)&&(this[e]=null,delete this[e])})}bindDataSource(t,e){const s=e?.initial??!0,i=t??this._data_source;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=>{await this.onData(n.value)}),s&&u.has(i)&&this.onData(u.get(i))))}unbindDataSource(){this._xd_unsub?.(),this._xd_unsub=void 0,this._xd_bound_key=void 0}async dispose(){if(this.unbindDataSource(),this._parent){const t=this._parent._children.indexOf(this);t>-1&&this._parent._children.splice(t,1)}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=>{typeof t.dispose=="function"&&t.dispose()}),this._children=[]}removeChild(t,e=!1){if(e)t.dispose();else{const s=this._children.indexOf(t);s>-1&&this._children.splice(s,1),t._parent=null}}addChild(t){this.append(t)}}class L{static getObjects(){return{object:y}}}const B="engine:module:num-of-objects:";class C{constructor(t){this._log_rules={createObject:!1,removeObject:!1},this.#t=new S,this._name=t._name,this._id=f.guid()}#t;load(){c.log("Module "+this._name+" loaded")}create(t){let e;if(t.hasOwnProperty("_type"))if(this.#t.hasObjectClass(t._type)){let s=this.#t.getObjectClass(t._type);s.hasOwnProperty("defaults")&&f.mergeDefaultsWithData(t,s.defaults),e=new s(t)}else throw"Xpell object '"+t._type+"' not found";else e=new y(t);return this.#t.addObject(e),t._children&&t._children.forEach(s=>{const i=this.create(s);e.append(i)}),e.onCreate(),e}remove(t){const e=this.#t.getObject(t);if(!e)return;const s=[],i=n=>{n?._id&&(s.push(n._id),(n._children??[]).forEach(r=>i(r)))};i(e),typeof e.dispose=="function"&&e.dispose(),s.reverse().forEach(n=>this.#t.removeObject(n))}_info(t){c.log("module info")}async run(t){if(t){let e=t.trim();e.startsWith(this._name)||(e=this._name+" "+e);let s=m.parse(e);return await this.execute(s)}else throw"Unable to parse Xpell Command"}async execute(t){if(!t||!t._op)throw new Error(`Invalid XCommand: missing _op (module: ${this._name})`);const e=t._object;if(e){const n=this.#t.getObject(e);if(!n)throw new Error(`Module '${this._name}' cant find object id: ${e}`);return await n.execute(t)}const s="_"+t._op.replaceAll("-","_"),i=this[s];if(typeof i=="function")return await i.call(this,t);throw new Error(`Module '${this._name}' cant find op: ${t._op}`)}async onFrame(t){const e=this.#t._objects,s=Object.keys(e);s.forEach(i=>{const n=e[i];n&&n.onFrame&&typeof n.onFrame=="function"&&n?.onFrame(t)}),u.set(B+this._id,s.length,{source:"xmodule"})}get om(){return this.#t}get _object_manager(){return this.#t}getObject(t){return this.#t.getObject(t)}get _o(){return this.#t._objects}importObjectPack(t){this.#t.registerObjects(t.getObjects())}importObjects(t){this.importObjectPack(t)}importObject(t,e){this.#t.registerObject(t,e)}async _help(t){const e=t?._params?._op??t?._params?._command??"";return this.help(e)}help(t){return{module:this._name,usage:`${this._name} help`,ops:["help"],note:"No help() implemented for this module."}}}class T{static get(t,e,s){if(!t?._params)return s;const i=t._params[e];return i!==void 0?i:s}static has(t,e){return t?._params&&t._params[e]!==void 0}static str(t,...e){for(const s of e){const i=t?._params?.[s];if(i!=null)return String(i)}}static bool(t,e,s=!1){const i=this.get(t,e,s);if(typeof i=="boolean")return i;if(typeof i=="number")return i!==0;if(typeof i=="string"){const n=i.toLowerCase();if(["1","true","yes","on"].includes(n))return!0;if(["0","false","no","off"].includes(n))return!1}return!!i}static int(t,e,s=0){const i=this.get(t,e,s),n=parseInt(String(i),10);return Number.isFinite(n)?n:s}static json(t,e,s){const i=this.get(t,e,s);if(i==null)return s;if(typeof i=="object")return i;if(typeof i=="string")try{return JSON.parse(i)}catch{return s}return s}}class O extends Error{constructor(t,e,s){super(e),this.name="XError",this._code=t,this._level=s?._level??"error",this._meta=s?._meta,this._cause=s?._cause}toXData(){return{_code:this._code,_level:this._level,_meta:this._meta,_cause:this._cause,name:this.name,message:this.message}}toJSON(){return{...this.toXData(),stack:this.stack}}}class d{constructor(t){this._ok=!1,this._ts=Date.now(),this._pt=0,t&&this.setXData(t)}static create(t){return new d(t)}static ok(t){return new d({_ok:!0,_result:t})}static error(t){if(t instanceof O)return new d({_ok:!1,_result:t.toXData()});const e=new O("E_INTERNAL",t?.message??String(t),{_cause:t});return new d({_ok:!1,_result:e.toXData()})}stopProcessTimeCounter(){this._pt=Date.now()-this._ts}toXData(){return this.stopProcessTimeCounter(),{_ok:this._ok,_ts:this._ts,_pt:this._pt,_result:this._result}}toString(){return JSON.stringify(this.toXData())}setXData(t){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))}}class W extends d{constructor(t){super(d.error(t).toXData())}}class J extends d{constructor(t){super({_ok:!0,_result:t})}}const I="engine:frame-number",P="engine:fps";class A{constructor(t){this._log_rules={},this._modules={},this._schedule_frame=t?._schedule_frame??f.createDefaultScheduler(t?._target_fps),this._version="0.0.1",this._engine_id=f.guid(),this._frame_number=0,this._fps_calc=new N,this.parser=m,this._modules={},g.fire("xpell-init"),c._enabled=!1}set verbose(t){c._enabled=t}set _verbose(t){c._enabled=t}log(t,...e){c.log(t,...e)}async delay(t){return new Promise(e=>setTimeout(e,t))}loadModule(t){this._modules.hasOwnProperty(t._name)?c.log("Module "+t._name+" already loaded"):(this._modules[t._name]=t,t.load())}loadModules(...t){t.forEach(e=>this.loadModule(e))}info(){c.log(`Xpell information:
|
|
1
|
+
"use strict";var B=i=>{throw TypeError(i)};var W=(i,e,t)=>e.has(i)||B("Cannot "+t);var p=(i,e,t)=>(W(i,e,"read from private field"),t?t.call(i):e.get(i)),J=(i,e,t)=>e.has(i)?B("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(i):e.set(i,t),V=(i,e,t,s)=>(W(i,e,"write to private field"),s?s.call(i,t):e.set(i,t),t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class H{createIgnoreList(e,t){if(!e)return t;const s=e.split(",").map(n=>n.trim()).filter(Boolean);for(const n of s)t[n]="";return t}guid(){const t=globalThis.crypto;if(t&&typeof t.randomUUID=="function")return t.randomUUID();if(t&&typeof t.getRandomValues=="function"){const o=new Uint8Array(16);t.getRandomValues(o),o[6]=o[6]&15|64,o[8]=o[8]&63|128;const a=Array.from(o,_=>_.toString(16).padStart(2,"0"));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("")}const s="0123456789abcdef".split(""),n=[];let r;n[8]=n[13]=n[18]=n[23]="-",n[14]="4";for(let o=0;o<36;o++)n[o]||(r=(0|Math.random()*16)>>>0,n[o]=s[o===19?r&3|8:r&15]);return n.join("")}mergeDefaultsWithData(e,t,s=!1){if(!e)return t;e._id||(e._id=e.id??this.guid());for(const n of Object.keys(t))(!(n in e)||s)&&(e[n]=t[n]);return e}encode(e){const t=globalThis;if(typeof t.btoa=="function"){const s=encodeURIComponent(String(e)).replace(/%([0-9A-F]{2})/g,(n,r)=>String.fromCharCode(parseInt(r,16)));return t.btoa(s)}if(t.Buffer&&typeof t.Buffer.from=="function")return t.Buffer.from(String(e),"utf8").toString("base64");throw new Error("Base64 encode not supported in this environment")}decode(e){const t=globalThis;if(typeof t.atob=="function"){const s=t.atob(String(e)),n=Array.prototype.map.call(s,r=>"%"+r.charCodeAt(0).toString(16).padStart(2,"0")).join("");return decodeURIComponent(n)}if(t.Buffer&&typeof t.Buffer.from=="function")return t.Buffer.from(String(e),"base64").toString("utf8");throw new Error("Base64 decode not supported in this environment")}getRandomInt(e,t){return e=Math.ceil(e),t=Math.floor(t),Math.floor(Math.random()*(t-e+1))+e}getParam(e,t,s=0){return e?._params?.[t]??s}createDefaultScheduler(e){const t=globalThis;if(typeof t.requestAnimationFrame=="function")return r=>t.requestAnimationFrame(r);const s=typeof e=="number"&&isFinite(e)&&e>0?e:60;if(typeof t.setImmediate=="function"&&(!e||e>=60))return r=>t.setImmediate(r);const n=Math.max(1,Math.round(1e3/s));return r=>t.setTimeout(r,n)}to_iso_now(){return new Date().toISOString()}is_plain_object(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}ensure_string(e,t){if(typeof e!="string"||!e.trim())throw new Error(`Invalid '${t}'`);return e.trim()}ensure_params(e){return this.is_plain_object(e)?e:{}}addIfNotNull(e,t,s){if(!(!e||!t||!Array.isArray(s)))for(const n of s){const r=e[n];r!=null&&(t[n]=r)}}als(e){const t=String(e??"");return t.endsWith("/")?t:t+"/"}cls(e){const t=String(e??"");return t.endsWith("/")?t.slice(0,-1):t}afs(e){const t=String(e??"");return t.startsWith("/")?t:"/"+t}cfs(e){const t=String(e??"");return t.startsWith("/")?t.slice(1):t}calculateExpiration(e){const s=String(e??"").trim().match(/^(\d+)([hdy])$/);if(!s)throw new Error("Invalid expiration format. Use: 1h | 2d | 3y");const n=Number.parseInt(s[1],10),r=s[2],o=Date.now();let a=0;switch(r){case"h":a=n*60*60*1e3;break;case"d":a=n*24*60*60*1e3;break;case"y":a=n*365*24*60*60*1e3;break}return o+a}}const Q=new H,l=Q;class oe{#e=0;#t=0;#s=0;#n;#r;constructor(e=.05,t=1){const s=Number(e);this.#n=Number.isFinite(s)?Math.min(1,Math.max(.001,s)):.05;const n=Number(t);this.#r=Number.isFinite(n)?Math.max(0,Math.floor(n)):1}now(){const e=globalThis.performance;return e&&typeof e.now=="function"?e.now():Date.now()}calc(){const e=this.now();if(this.#s===0)return this.#s=e,this.#e;const t=e-this.#s;if(this.#s=e,!Number.isFinite(t)||t<=0)return this.#e;this.#t===0?this.#t=t:this.#t=(1-this.#n)*this.#t+this.#n*t;const s=1e3/this.#t;if(!Number.isFinite(s)||s<=0)return this.#e;const n=Math.round(s);return this.#e!==0&&this.#r>0&&Math.abs(n-this.#e)<this.#r?this.#e:(this.#e=n,this.#e)}reset(){this.#e=0,this.#t=0,this.#s=0}}class z{constructor(e){this._enabled=!0,this._show_date=!1,this._show_time=!0,this._debug=!1,e&&this.configure(e)}configure(e){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)}_dt(){const e=new Date,t=this._show_date?`${e.getDate()}.${e.getMonth()}.${e.getFullYear()} `:"",s=this._show_time?`${e.getHours()}:${e.getMinutes()}:${e.getSeconds()}.${e.getMilliseconds()}|`:"";return t+s}log(e,...t){this._enabled&&console.log(this._dt(),e,...t)}warn(e,...t){this._enabled&&console.warn(this._dt(),e,...t)}error(e,...t){this._enabled&&console.error(this._dt(),e,...t)}debug(e,...t){!this._enabled||!this._debug||console.debug(this._dt(),e,...t)}}const c=new z,Y=typeof process<"u"&&!!process?.env&&process.env.NODE_ENV==="production";Y||console.info("[Xpell] _xlog is redirected to console in development mode. Tip: enable 'Show timestamps' in DevTools → Console for timed logs.");const j=Y?c:console;class Z{constructor(){this._objects={},this._listeners=new Map,this._any_listeners=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={}}get _o(){return!this._compat_writes&&!this._warn_legacy_writes?this._objects:(this._o_proxy||(this._o_proxy=new Proxy(this._objects,{set:(e,t,s)=>{const n=String(t);return this._warn_legacy_writes&&console.warn(`[XData] Legacy write: _o["${n}"] = ... ; prefer XData.set("${n}", value).`),this._compat_writes?this.set(n,s,{source:"legacy:_o"}):e[n]=s,!0},deleteProperty:(e,t)=>{const s=String(t);return this._warn_legacy_writes&&console.warn(`[XData] Legacy delete: delete _o["${s}"] ; prefer XData.delete("${s}").`),this._compat_writes?this.delete(s,{source:"legacy:_o"}):delete e[s],!0}})),this._o_proxy)}get(e){return this._objects[e]}set(e,t,s){const n=this._objects[e];this._objects[e]=t,this._emit({key:e,value:t,prev:n,ts:Date.now(),op:"set",meta:s})}patch(e,t,s){const n=this._objects[e],o={...n&&typeof n=="object"?n:{},...t};this._objects[e]=o,this._emit({key:e,value:o,prev:n,ts:Date.now(),op:"patch",meta:s})}touch(e,t){const s=this._objects[e];this._emit({key:e,value:s,prev:s,ts:Date.now(),op:"touch",meta:t})}has(e){return Object.prototype.hasOwnProperty.call(this._objects,e)}delete(e,t){const s=this._objects[e];delete this._objects[e],this._emit({key:e,value:void 0,prev:s,ts:Date.now(),op:"delete",meta:t})}pick(e,t){const s=this._objects[e];return this.delete(e,t),s}clean(){this._objects={}}on(e,t){let s=this._listeners.get(e);return s||this._listeners.set(e,s=new Set),s.add(t),()=>this.off(e,t)}off(e,t){const s=this._listeners.get(e);s&&(s.delete(t),s.size===0&&this._listeners.delete(e))}onAny(e){return this._any_listeners.add(e),()=>this._any_listeners.delete(e)}_emit(e){this._verbose&&e.meta?.trace&&(e.stack=new Error().stack);const t=this._listeners.get(e.key);if(t)for(const s of t)s(e);for(const s of this._any_listeners)s(e)}}const v=new Z,m=v;class A{constructor(e){e&&Object.keys(e).forEach(t=>{this[t]=e[t]}),this.d||(this.d=Date.now())}getParam(e,t,s){return this._params?.hasOwnProperty(t)?this._params[t]:this._params?.hasOwnProperty(e)?this._params[e]:s}}const M={type:"_type",children:"_children"},y=class y{static addHtml2XpellMapItem(e,t){y.html2XMap.elements[e]=t}static parse(e,t){const s=e.split(" ");let n=new A;if(t?(n._module=t,n._op=s[0]):(n._module=s[0],n._op=s[1]),n._params={},s.length>1)for(let r=2;r<s.length;++r){const o=s[r];if(o.indexOf(":")>-1){const _=o.split(":");n._params[_[0]]=_[1]}else n._params[r-1]=s[r]}return n}static replaceSpacesInQuotes(e,t="_%20_"){return e.replace(/(['"])(.*?)\1/g,(s,n,r)=>{const o=String(r).replace(/\s/g,t);return`${n}${o}${n}`})}static parseObjectCommand(e,t){e=y.replaceSpacesInQuotes(e);const s=e.trim().split(/\s+/),n=t||s.shift();if(!n)throw new Error("Missing module name");let r;if(s[0]?.startsWith("#")&&(r=s.shift().slice(1),!r))throw new Error("Invalid object selector '#'. Use '#<id>'");const o=s.shift();if(!o)throw new Error("Missing operation");const a={};let _=null,h=null;if(s.forEach(u=>{if(h){if(h+=` ${u}`,u.endsWith(h[0])){const f=h.slice(1,-1).replace(/_%20_/g," ");a[_]=f,h=null}return}if(u.startsWith('"')||u.startsWith("'")){if(h=u,u.endsWith(u[0])&&u.length>1){const f=u.slice(1,-1).replace(/_%20_/g," ");a[_]=f,h=null}return}if(u.includes(":")){const f=u.split(":"),X=f[0],re=f.slice(1).join(":").replace(/_%20_/g," ");a[X]=re,_=null;return}_=u.replace(/_%20_/g," ")}),h)throw new Error("Unclosed quoted parameter value");return{_module:n,_object:r,_op:o,_params:a}}static xmlString2Xpell(e){const s=new DOMParser().parseFromString(e,"text/xml");return s.childNodes.length>0?y.xml2Xpell(s.childNodes[0]):{}}static xml2Xpell(e,t){const s=y.html2XMap;let n={};n._children=[];const r=e.nodeName,o=e.nodeName;let a=t;if(t?(n[M.type]="xhtml",n._html_ns="http://www.w3.org/2000/svg"):n._type=s.elements[r]?s.elements[r]:r,e.attributes)for(let _=0;_<e.attributes.length;++_){const h=e.attributes[_],u=s.attributes[h.name]?s.attributes[h.name]:h.name;n[u]=h.value}if(e?.firstChild?.nodeValue&&(n.text=e?.firstChild.nodeValue.trim()),n[M.type]=="xhtml"?n._html_tag=o:n[M.type]=="svg"&&(a=!0,n._html_ns="http://www.w3.org/2000/svg"),e?.childNodes.length>0)for(let _=0;_<e.childNodes.length;++_){const h=e.childNodes[_];h.nodeName.startsWith("#")||n[M.children].push(y.xml2Xpell(h,a))}return n}};y.html2XMap={elements:{div:"view",a:"link",b:"xhtml",h1:"xhtml",h2:"xhtml",h3:"xhtml",h4:"xhtml",h5:"xhtml",p:"xhtml",small:"xhtml",aside:"xhtml",span:"xhtml",table:"xhtml",th:"xhtml",td:"xhtml",tr:"xhtml",thead:"xhtml",tbody:"xhtml",ul:"xhtml",li:"xhtml",ol:"xhtml",canvas:"xhtml",img:"image"},attributes:{id:"_id"}};let w=y;class ee{#e;#t;#s;constructor(){this.#e={},this.#t={},this.#s={}}get _objects(){return this.#t}hasObject(e){return this.#t.hasOwnProperty(e)}registerObjects(e){Object.keys(e).forEach(s=>this.registerObject(s,e[s]))}registerObject(e,t){this.#e[e]=t}hasObjectClass(e){return this.#e.hasOwnProperty(e)}getObjectClass(e){return this.#e[e]}getAllClasses(){return this.getObjectClasses()}getObjectClasses(){return this.#e}get _classes(){return this.#e}addObject(e){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")}removeObject(e){const t=this.#t[e];t&&(delete this.#s[t?._name],delete this.#t[e])}getObject(e){return this.#t[e]}go(e){return this.getObject(e)}getObjectByName(e){return this.#s[e]?this.getObject(this.#s[e]):null}}class ie{constructor(){this._log_rules={register:!1,remove:!1,fire:!1},this._events={},this._listener_index={}}on(e,t,s={},n){this._events[e]||(this._events[e]=[]);const r=s?._owner??n,o=l.guid(),a={_id:o,_callback:t,_options:s,_owner:r,_tag:s?._tag};return this._events[e].push(a),this._listener_index[o]=e,this._log_rules.register&&j.log("XEM Register",e,o),o}once(e,t,s){return this.on(e,t,{_once:!0,_owner:s})}async fire(e,t){const s=this._events[e];if(!s||s.length===0)return;this._log_rules.fire&&j.log("XEM Fire",e,t);const n=s.slice(),r=[];for(const o of n){try{o&&o._callback&&o._callback(t)}catch(a){j.error(a)}o?._options?._once&&r.push(o._id)}for(const o of r)this.remove(o)}remove(e){const t=this._listener_index[e];if(!t)return;const s=this._events[t];if(s&&s.length){const n=s.findIndex(r=>r?._id===e);n>=0&&s.splice(n,1),s.length===0&&delete this._events[t]}delete this._listener_index[e],this._log_rules.remove&&j.log("XEM Remove",t,e)}removeOwner(e){if(!e)return;const t=[];for(const s of Object.values(this._events))for(const n of s)(n?._owner??n?._options?._owner)===e&&t.push(n._id);t.forEach(s=>this.remove(s))}clear(){this._events={},this._listener_index={}}}let $;function ae(i){$=i}function x(){if(!$)throw new Error("XEventManager not set");return $}const ce=["_nano_commands","_cache_cmd_txt","_cache_jcmd","_xporter","_event_listeners_ids","_parent","_children"];function F(i){return ce.includes(i)}function K(i){if(!i||typeof i!="object"||Array.isArray(i))return!1;const e=Object.getPrototypeOf(i);return e===Object.prototype||e===null}function g(i,e){return i._skill=e,i.getSkill=()=>e,i}const G={info:g((i,e)=>{c.log("XObject id "+e?._id)},{_name:"info",_scope:"object",_description:"Logs the current object's id."}),log:g((i,e)=>{i._params&&i._params[1]?c.log(i._params[1]):c.log(e)},{_name:"log",_scope:"object",_description:"Logs a message or the current object.",_params:{1:"Optional message to log."}}),fire:g((i,e)=>{i._params&&i._params[1]?x().fire(String(i._params[1]),i._params[2]):i._params&&i._params.event&&x().fire(String(i._params.event),i._params.data)},{_name:"fire",_scope:"object",_description:"Fires an XEventManager event.",_params:{event:"Event name.",data:"Optional event payload.",1:"Event name shorthand.",2:"Event payload shorthand."},_example:{_op:"fire",_params:{event:"user:login",data:{source:"button"}}}}),noop:g(()=>{},{_name:"noop",_scope:"object",_description:"No-op command. Useful as a placeholder in sequences."}),"set-field":g((i,e)=>{const t=i._params?.name,s=i._params?.value;if(!(!e||typeof t!="string"||t.length===0)){if(F(t)){c.error(`set-field denied for protected field: ${t}`);return}e[t]=s}},{_name:"set-field",_scope:"object",_description:"Sets a runtime field directly on the current object.",_params:{name:"Field name.",value:"Value to assign."},_example:{_op:"set-field",_params:{name:"_text",value:"Hello"}}}),"delete-field":g((i,e)=>{const t=i._params?.name;if(!(!e||typeof t!="string"||t.length===0)){if(F(t)){c.error(`delete-field denied for protected field: ${t}`);return}delete e[t]}},{_name:"delete-field",_scope:"object",_description:"Deletes a runtime field from the current object.",_params:{name:"Field name to delete."}}),"toggle-field":g((i,e)=>{const t=i._params?.name;if(!e||typeof t!="string"||t.length===0)return;if(F(t)){c.error(`toggle-field denied for protected field: ${t}`);return}const s=e[t];typeof s=="boolean"?e[t]=!s:s==null?e[t]=!0:e[t]=!1},{_name:"toggle-field",_scope:"object",_description:"Toggles a runtime field using boolean-first semantics.",_params:{name:"Field name to toggle."}}),merge:g((i,e)=>{const t=i._params?.name,s=i._params?.value;if(!e||typeof t!="string"||t.length===0)return;if(F(t)){c.error(`merge denied for protected field: ${t}`);return}if(!K(s)){c.error("merge expects _params.value as a plain object");return}const n=e[t];K(n)||(e[t]={}),Object.assign(e[t],s)},{_name:"merge",_scope:"object",_description:"Shallow-merges a plain object into a target object field.",_params:{name:"Target field name.",value:"Plain object to merge."}}),"run-seq":g(async(i,e)=>{if(!e)return;const t=i._params?.seq;if(!Array.isArray(t)){c.error("run-seq expects _params.seq as an array");return}for(const s of t){if(typeof s=="string"){await e.run(`${e._id} ${s}`);continue}if(s&&typeof s=="object"&&s._op){const n=s._object;if(!(n==null||n==="this"||n===e._id)){c.error("run-seq rejected non-self _object target");return}const o={_op:s._op,_params:s._params?{...s._params}:void 0};await e.execute(o);continue}c.error("run-seq skipped invalid step; expected string or object with _op")}},{_name:"run-seq",_scope:"object",_description:"Runs a sequence of local nano-command steps in strict order.",_params:{seq:"Array of command strings or local command objects."},_example:{_op:"run-seq",_params:{seq:[{_op:"set-field",_params:{name:"_debug",value:!0}},{_op:"log",_params:{1:"Debug enabled"}}]}}})};let N;function _e(i){N=i}function le(){if(!N)throw new Error("XRuntime not set");return N}const L={_id:"xobject",_title:"XObject Core Runtime Contract",_version:"1.0.0",_active:!0,_type:"runtime-api-skill",_description:"Base runtime object for identity, typing, composition, lifecycle hooks, events, data binding, and nano-command execution.",_fields:{_id:"Unique object id.",_type:"Registered runtime object type.",_name:"Optional object name.",_children:"Child objects/data.",_data_source:"XData key to bind this object to.",_on:"Event handlers map.",_once:"One-time event handlers map.",_on_create:"Lifecycle handler after object creation.",_on_mount:"Lifecycle handler after mount.",_on_frame:"Frame lifecycle handler.",_on_data:"Data-source lifecycle handler.",_process_frame:"Enable/disable frame processing.",_process_data:"Enable/disable data-source processing.",_debug:"Enable object debug logs."},_exports:{_xui_fields:["_id","_type","_name","_children","_data_source","_on","_once","_on_create","_on_mount","_on_frame","_on_data","_process_frame","_process_data","_debug"]},_core_rules:["All Xpell runtime objects inherit this contract.","Generated object JSON must be data-only.","Do not generate JavaScript functions.","Use _children for composition.","Use _on/_once with nano-command strings or data-only command objects."],_notes:["Runtime methods include parse, append, run, execute, bindDataSource, unbindDataSource, toXData, dispose, and removeChild.","Most prompts should use this skill as a compact dependency summary, not full context."]},R={_children:"child nodes"},S=class S{constructor(e,t,s){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={_ignore_fields:["_to_xdata_ignore_fields","_xporter","_children","_on","_once","_on_create","_on_mount","_on_frame","_on_data","_process_frame","_process_data","_parent","_event_listeners_ids","_event_parsed","_mounted","_debug"],_instance_xporters:{}},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(G),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={},!s&&e&&this.parse(e,R)}static getOwnSkill(){const e=this,t=e._skill??L;return{...t,_exports:{...t._exports??{},_nano_commands:e.getNanoCommandSkills?.()??[]}}}static getSkillChain(){const e=Object.getPrototypeOf(this),t=e&&typeof e.getSkillChain=="function"?e.getSkillChain():[],s=Object.prototype.hasOwnProperty.call(this,"_skill")?this.getOwnSkill():null;return s?[...t,s]:t}static getOwnNanoCommands(){return{...G}}static getNanoCommands(){return{...this.getOwnNanoCommands()}}static getNanoCommandSkills(){return Object.prototype.hasOwnProperty.call(this,"getOwnNanoCommands")?Object.values(this.getOwnNanoCommands()).map(t=>t.getSkill?.()??t._skill).filter(Boolean):[]}log(e,...t){this._debug&&e&&c.log(this._type+"->"+this._id+"]",e,...t)}init(e,t){!t&&e&&this.parse(e,R)}parseEvents(e){if(!this._event_parsed){e||(e=this._xem_options),Object.keys(this._on).forEach(s=>{this.addEventListener(s,this._on[s],e)});const t={};Object.assign(t,e),t._once=!0,Object.keys(this._once).forEach(s=>{this.addEventListener(s,this._once[s],t)}),this._event_parsed=!0}}addEventListener(e,t,s){s||(s=this._xem_options);const n=async o=>{await this.checkAndRunInternalFunction(t,o)},r=x().on(e,n,s,this);return this._event_listeners_ids[e]||(this._event_listeners_ids[e]=[]),this._event_listeners_ids[e].push(r),r}removeEventListener(e){const t=this._event_listeners_ids[e];t&&t.length&&(t.forEach(s=>{x().remove(s)}),delete this._event_listeners_ids[e])}removeAllEventListeners(){Object.keys(this._event_listeners_ids).forEach(t=>this.removeEventListener(t))}append(e){this._children?.push(e),e._parent=this}addNanoCommand(e,t){typeof t=="function"&&(this._nano_commands[e]=t)}addNanoCommandPack(e){e&&Object.keys(e).forEach(t=>{this.addNanoCommand(t,e[t])})}addXporterDataIgnoreFields(e){this._xporter._ignore_fields=this._xporter._ignore_fields.concat(e)}addXporterInstanceXporter(e,t){const s=l.guid();this._xporter._instance_xporters[s]={cls:e,handler:t}}parse(e,t=R){Object.keys(e).forEach(n=>{!t.hasOwnProperty(n)&&e.hasOwnProperty(n)&&(this[n]=e[n])})}parseFieldsFromXDataObject(e,t){Object.keys(t).forEach(n=>{e.hasOwnProperty(n)?this[n]=e[n]:this[n]=t[n]})}parseFields(e,t,s){t.forEach(n=>{if(e.hasOwnProperty(n))this[n]=e[n];else if(s&&n.startsWith("_")){const r=n.substring(1);e.hasOwnProperty(r)&&(this[n]=e[r],this[r]=e[r])}})}async onCreate(){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)}async runCmd(e){const t=e instanceof A?e:new A(e);await this.execute(t)}async checkAndRunInternalFunction(e,...t){const s=r=>{if(typeof r=="string"){if(r==="$event")return t[0];if(r.startsWith("$event.")){const o=r.slice(7).split(".");let a=t[0];for(const _ of o){if(a==null)return;a=a[_]}return a}if(r==="$data")return t[0];if(r.startsWith("$data.")){const o=r.slice(6).split(".");let a=t[0];for(const _ of o){if(a==null)return;a=a[_]}return a}return r}if(Array.isArray(r))return r.map(s);if(r&&typeof r=="object"){const o={};for(const a of Object.keys(r))o[a]=s(r[a]);return o}return r},n=async(r,o)=>(o!==void 0&&r&&typeof r=="object"&&!Array.isArray(r)&&(r={...r,_params:{...r._params??{},_prev:o}}),await this.checkAndRunInternalFunction(r,...t));if(Array.isArray(e)){let r;for(const o of e)r=await n(o,r);return r}if(typeof e=="function")return await e(this,...t);if(typeof e=="string"){const r=w.parseObjectCommand(`${this._id} ${e}`);if(t.length>0){r._params=r._params||{};const o=t[0];r._params._event=o,!r._params.data&&!o?.target&&(r._params.data=o)}return await this.execute(r)}if(e&&typeof e=="object"&&Array.isArray(e._commands)){const r=e,o=typeof r._mode=="string"?r._mode:"sequence",a=r._stop_on_error!==!1,_=r._commands;if(o==="parallel"){const u=await Promise.allSettled(_.map(X=>n(X))),f=u.find(X=>X.status==="rejected");if(f&&a)throw f.reason;return u}let h;for(const u of _)try{h=await n(u,o==="chain"?h:void 0)}catch(f){if(c.error(this._type+"->"+this._id+"] command sequence failed",f),a)throw f}return h}if(e&&typeof e=="object"&&e._op){const r=e;if((r._object===void 0||r._object===null||r._object==="this"?this._id:r._object)!==this._id){c.error("XObject JSON handler target not supported; expected _object omitted/'this'/"+this._id);return}const a={...r,_params:r._params?{...r._params}:{}};if(t.length>0){const _=t[0];Object.prototype.hasOwnProperty.call(a._params,"data")||(a._params.data=_),Object.prototype.hasOwnProperty.call(a._params,"_event")||(a._params._event=_)}return a._params=s(a._params),this._debug&&c.log(this._type+"->"+this._id+"]","JSON handler executed locally",a),await this.execute(a)}c.error(this._type+"->"+this._id+"] invalid handler in checkAndRunInternalFunction",e)}async onMount(){if(!this._mounted){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;for(const e of this._children)e.onMount&&typeof e.onMount=="function"&&e.onMount()}}emptyDataSource(){const e=this._data_source;if(typeof e!="string"||e.length===0)return;const t=this._type??this.constructor.name,s=this._id??"no-id";v.delete(e,{source:`${t}#${s}.emptyDataSource`})}async onData(e){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))}async onFrame(e){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));for(const t of this._children)t.onFrame&&typeof t.onFrame=="function"&&t.onFrame(e)}async run(e,t=!0){let s=this._cache_cmd_txt&&this._cache_cmd_txt==e?this._cache_jcmd:w.parseObjectCommand(e);t&&(this._cache_cmd_txt=e,this._cache_jcmd=s),await this.execute(s)}async execute(e){const t=e?._op;if(!t){c.error(this._id+" missing _op in command");return}const s=e?._module;if(s)try{return await le().execute({...e,_module:s})}catch(n){c.error(this._id+" module execution failed: "+s+"."+t+" "+n);return}if(this._nano_commands[t])try{return await this._nano_commands[t](e,this)}catch(n){c.error(this._id+" has error with command name "+t+" "+n);return}c.error(this._id+" has no command name "+t)}toXData(){const e={};return Object.keys(this).forEach(t=>{if(!this._xporter._ignore_fields.includes(t)&&this.hasOwnProperty(t)&&this[t]!==void 0){const s=this[t];if(typeof s=="function")return;if(typeof s=="object"){const n=Object.keys(this._xporter._instance_xporters);let r=!0;n.forEach(o=>{this._xporter._instance_xporters[o],s instanceof this._xporter._instance_xporters[o].cls&&(e[t]=this._xporter._instance_xporters[o].handler(s),r=!1)}),r&&(e[t]=s)}else e[t]=s}}),e._children=[],this._children.length>0&&this._children.forEach(t=>{typeof t.toXData=="function"&&e._children?.push(t.toXData())}),e}toString(){return JSON.stringify(this.toXData())}clearAttributes(e){e.forEach(t=>{this.hasOwnProperty(t)&&(this[t]=null,delete this[t])})}bindDataSource(e,t){const s=t?.initial??!0,n=e??this._data_source;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=v.on(n,async r=>{await this.onData(r.value)}),s&&v.has(n)&&this.onData(v.get(n))))}unbindDataSource(){this._xd_unsub?.(),this._xd_unsub=void 0,this._xd_bound_key=void 0}async dispose(){if(this.unbindDataSource(),this._parent){const e=this._parent._children.indexOf(this);e>-1&&this._parent._children.splice(e,1)}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=>{typeof e.dispose=="function"&&e.dispose()}),this._children=[]}removeChild(e,t=!1){if(t)e.dispose();else{const s=this._children.indexOf(e);s>-1&&this._children.splice(s,1),e._parent=null}}addChild(e){this.append(e)}};S._xtype="object",S._skill=L;let D=S;class he{static getObjects(){return{object:D}}}const ue="engine:module:num-of-objects:",U={_id:"xmodule",_title:"XModule Runtime Contract",_version:"1.0.0",_active:!0,_type:"runtime-api-skill",_description:"Base runtime module contract for object ownership, object packs, and executable underscore-prefixed commands.",_core_rules:["Every module must have a unique _name.","Modules expose commands through methods prefixed with underscore.","Command names remove the leading underscore and convert dashes to underscores internally.","Modules own and create registered XObject classes.","Do not mutate another module's objects directly."]};var d;const P=class P{constructor(e){J(this,d);this._loaded=!1,this._loading=!1,this._log_rules={createObject:!1,removeObject:!1},V(this,d,new ee),this._name=e._name,this._id=l.guid()}static getOwnSkillBase(){return{...this._skill}}getOwnSkill(){const t=this.constructor._skill??U;return{...t,_exports:{...t._exports??{},_modules:[{_name:this._name,_scope:t._type==="server-module-api"?"server":"client",_description:t._description,_ops:this.getCommandSkills()}]}}}getSkillChain(){return[this.getOwnSkill()]}getObjectSkills(){const e=[],t=new Set;for(const s of Object.values(p(this,d).getObjectClasses())){if(typeof s.getOwnSkill!="function")continue;const n=s.getOwnSkill();n?._id&&(t.has(n._id)||(t.add(n._id),e.push(n)))}return e}getCommandSkills(){const e=Object.getPrototypeOf(this),s=this.constructor._ops??{};return Object.getOwnPropertyNames(e).filter(n=>n.startsWith("_")&&!n.startsWith("__")&&typeof this[n]=="function").map(n=>{const r=n.slice(1).replaceAll("_","-");return s[r]??{_name:r,_scope:"module",_description:`Runtime module command: ${r}`}})}async load(){if(!(this._loaded||this._loading)){this._loading=!0;try{await this.onLoad(),this._loaded=!0,c.log("Module "+this._name+" loaded")}finally{this._loading=!1}}}async onLoad(){}create(e){e._debug&&c.log("Creating object with data",e);let t;if(e.hasOwnProperty("_type")){e._debug&&c.log("Object type is",e._type,this.hasObject(e._type)?"found":"not found","in module",this._name);const s=String(e._type),n=p(this,d).getObjectClass(s);if(!n)throw`Xpell object '${s}' not found in module '${this._name}'`;typeof n=="function"&&n.hasOwnProperty("defaults")&&l.mergeDefaultsWithData(e,n.defaults),t=new n(e)}else t=new D(e);return p(this,d).addObject(t),e._children&&e._children.forEach(s=>{const n=this.create(s);t.append(n)}),t.onCreate(),t}remove(e){const t=p(this,d).getObject(e);if(!t)return;const s=[],n=r=>{r?._id&&(s.push(r._id),(r._children??[]).forEach(o=>n(o)))};n(t),typeof t.dispose=="function"&&t.dispose(),s.reverse().forEach(r=>p(this,d).removeObject(r))}_info(e){c.log("module info")}async run(e){if(e){let t=e.trim();t.startsWith(this._name)||(t=this._name+" "+t);let s=w.parse(t);return await this.execute(s)}else throw"Unable to parse Xpell Command"}async execute(e){if(!e||!e._op)throw new Error(`Invalid XCommand: missing _op (module: ${this._name})`);const t=e._object;if(t){const r=p(this,d).getObject(t);if(!r)throw new Error(`Module '${this._name}' cant find object id: ${t}`);return await r.execute(e)}const s="_"+e._op.replaceAll("-","_"),n=this[s];if(typeof n=="function")return await n.call(this,e);throw new Error(`Module '${this._name}' cant find op: ${e._op}`)}async onFrame(e){const t=p(this,d)._objects,s=Object.keys(t);s.forEach(n=>{const r=t[n];r&&r.onFrame&&typeof r.onFrame=="function"&&r?.onFrame(e)}),m.set(ue+this._id,s.length,{source:"xmodule"})}get om(){return p(this,d)}get _object_manager(){return p(this,d)}getObject(e){return p(this,d).getObject(e)}hasObject(e){return p(this,d).hasObjectClass(e)}get _o(){return p(this,d)._objects}importObjectPack(e){p(this,d).registerObjects(e.getObjects())}importObjects(e){this.importObjectPack(e)}importObject(e,t){p(this,d).registerObject(e,t)}async _help(e){const t=e?._params?._op??e?._params?._command??"";return this.help(t)}help(e){return{module:this._name,usage:`${this._name} help`,ops:["help"],note:"No help() implemented for this module."}}};d=new WeakMap,P._skill=U,P._ops={help:{_name:"help",_scope:"module",_description:"Return module help or command-specific help."},info:{_name:"info",_scope:"module",_description:"Log basic module information."}};let E=P;const de={_id:"xdata",_title:"XData Runtime State Contract",_version:"1.0.0",_active:!0,_type:"xdata-skill",_description:"Shared runtime state store used by Xpell modules and objects for reactive data binding.",_requires:["xmodule"],_core_rules:["Use XData for shared runtime state.","Use _data_source on objects to bind to an XData key.","Use $xdata.key references in generated payloads when a flow or command needs current state.","Do not use XData as hidden local component state.","XData keys should be explicit and stable."],_fields:{_data_source:"XData key used by XObject/XUIObject for reactive data binding.","$xdata.key":"Runtime payload reference to an XData value."}},k=class k extends E{constructor(){super({_name:k._name})}async _get(e){const t=l.ensure_params(e?._params),s=l.ensure_string(t.key,"key");return{_ok:!0,_result:m.get(s)}}async _set(e){const t=l.ensure_params(e?._params),s=l.ensure_string(t.key,"key");return t._debug&&j.log("XD SET",{key:s,value:t.value}),m.set(s,t.value,{source:t.source??"xd:set"}),{_ok:!0,_result:{key:s}}}async _patch(e){const t=l.ensure_params(e?._params),s=l.ensure_string(t.key,"key");if(!l.is_plain_object(t.value))throw new Error("xd patch expects value as plain object");return m.patch(s,t.value,{source:t.source??"xd:patch"}),{_ok:!0,_result:{key:s}}}async _delete(e){const t=l.ensure_params(e?._params),s=l.ensure_string(t.key,"key");return m.delete(s,{source:t.source??"xd:delete"}),{_ok:!0,_result:{key:s}}}async _touch(e){const t=l.ensure_params(e?._params),s=l.ensure_string(t.key,"key");return m.touch(s,{source:t.source??"xd:touch"}),{_ok:!0,_result:{key:s}}}async _has(e){const t=l.ensure_params(e?._params),s=l.ensure_string(t.key,"key");return{_ok:!0,_result:m.has(s)}}};k._name="xd",k._skill=de,k._ops={get:{_name:"get",_scope:"module",_description:"Get value from XData store.",_params:{key:"XData key."}},set:{_name:"set",_scope:"module",_description:"Set value in XData store.",_params:{key:"XData key.",value:"Value to store.",source:"Optional mutation source."}},patch:{_name:"patch",_scope:"module",_description:"Patch plain object into existing XData value.",_params:{key:"XData key.",value:"Plain object patch.",source:"Optional mutation source."}},delete:{_name:"delete",_scope:"module",_description:"Delete XData key.",_params:{key:"XData key.",source:"Optional mutation source."}},touch:{_name:"touch",_scope:"module",_description:"Trigger XData subscribers without changing value.",_params:{key:"XData key.",source:"Optional mutation source."}},has:{_name:"has",_scope:"module",_description:"Check if XData key exists.",_params:{key:"XData key."}}};let C=k;const pe={_id:"xem",_title:"XEventManager Runtime Event Bus",_version:"1.0.0",_active:!0,_type:"runtime-api-skill",_description:"Global runtime event bus for decoupled communication between Xpell modules, objects, flows, and UI components.",_requires:["xmodule"],_core_rules:["Use XEM for decoupled runtime events.","Use explicit event names and explicit payload objects.","Do not use XEM as state storage.","Use XData for shared state and XEM for notifications/events.","Prefer _on/_once on objects for local event handlers."],_fields:{_on:"Object event handler map.",_once:"Object one-time event handler map.",event:"Event name to fire.",data:"Optional event payload."},_notes:["XEM is process-wide and listener order should not be assumed.","Event payloads should be JSON/data-only."]},O=class O extends E{constructor(){super({_name:O._name})}async _fire(e){const t=l.ensure_params(e?._params),s=l.ensure_string(t.event,"event"),n=t.data;t._debug&&j.log("xem fire 🔥 ",s,n),await x().fire(s,n)}};O._name="xem",O._skill=pe,O._ops={fire:{_name:"fire",_scope:"module",_description:"Fire a global XEM event with optional payload data.",_params:{event:"Event name.",data:"Optional event payload.",_debug:"Optional debug log flag."},_example:{_module:"xem",_op:"fire",_params:{event:"user:login",data:{source:"login-button"}}}}};let I=O;class me{static get(e,t,s){if(!e?._params)return s;const n=e._params[t];return n!==void 0?n:s}static has(e,t){return(e?._params||e)[t]!==void 0}static str(e,...t){const s=e?._params||e;for(const n of t){const r=s?.[n];if(r!=null)return String(r)}}static bool(e,t,s=!1){const n=e?._params||e,r=this.get(n,t,s);if(typeof r=="boolean")return r;if(typeof r=="number")return r!==0;if(typeof r=="string"){const o=r.toLowerCase();if(["1","true","yes","on"].includes(o))return!0;if(["0","false","no","off"].includes(o))return!1}return!!r}static int(e,t,s=0){const n=e?._params||e,r=this.get(n,t,s),o=parseInt(String(r),10);return Number.isFinite(o)?o:s}static json(e,t,s){const n=e?._params||e,r=this.get(n,t,s);if(r==null)return s;if(typeof r=="object")return r;if(typeof r=="string")try{return JSON.parse(r)}catch{return s}return s}}class T extends Error{constructor(e,t,s){super(t),this.name="XError",this._code=e,this._level=s?._level??"error",this._meta=s?._meta,this._cause=s?._cause}toXData(){return{_code:this._code,_level:this._level,_meta:this._meta,_cause:this._cause,name:this.name,message:this.message}}toJSON(){return{...this.toXData(),stack:this.stack}}}class b{constructor(e){this._ok=!1,this._ts=Date.now(),this._pt=0,e&&this.setXData(e)}static create(e){return new b(e)}static ok(e){return new b({_ok:!0,_result:e})}static error(e){if(e instanceof T)return new b({_ok:!1,_result:e.toXData()});const t=new T("E_INTERNAL",e?.message??String(e),{_cause:e});return new b({_ok:!1,_result:t.toXData()})}stopProcessTimeCounter(){this._pt=Date.now()-this._ts}toXData(){return this.stopProcessTimeCounter(),{_ok:this._ok,_ts:this._ts,_pt:this._pt,_result:this._result}}toString(){return JSON.stringify(this.toXData())}setXData(e){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))}}class fe extends b{constructor(e){super(b.error(e).toXData())}}class ge extends b{constructor(e){super({_ok:!0,_result:e})}}const te="engine:frame-number",se="engine:fps";class ne{constructor(e){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 oe,this.parser=w,this._modules={},c._enabled=!1,_e(this)}set verbose(e){c._enabled=e}set _verbose(e){c._enabled=e}log(e,...t){c.log(e,...t)}async delay(e){return new Promise(t=>setTimeout(t,e))}addModule(e){return this._modules.hasOwnProperty(e._name)?(c.log("Module "+e._name+" already loaded"),!1):(this._modules[e._name]=e,!0)}loadModule(e){this.addModule(e)&&e.load()}loadModules(...e){e.forEach(t=>this.loadModule(t))}async loadModuleAsync(e){this.addModule(e)&&await e.load()}async loadModulesAsync(...e){for(const t of e)await this.loadModuleAsync(t)}info(){c.log(`Xpell information:
|
|
2
2
|
- Engine Id: `+this._engine_id+`
|
|
3
|
-
- Version `+this._version)}run(
|
|
3
|
+
- Version `+this._version)}run(e){if(e?.length>2){let t=w.parse(e);return this.execute(t)}else throw"Unable to parse Xpell command"}execute(e){if(e&&e._module&&this._modules[e._module])return this._modules[e._module].execute(e);throw"Xpell module "+e._module+" not loaded"}onFrame(){this._frame_number++;for(const t of Object.keys(this._modules)){const s=this._modules[t];s?.onFrame&&typeof s.onFrame=="function"&&s.onFrame(this._frame_number)}const e=this._fps_calc.calc();m.set(te,this._frame_number,{source:"engine"}),m.set(se,e,{source:"engine"}),m._compat_legacy_keys&&(m.set("frame-number",this._frame_number,{source:"engine:legacy"}),m.set("fps",e,{source:"engine:legacy"})),this._schedule_frame(()=>this.onFrame())}getModule(e){return this._modules[e]}start(){c.log("Loading Xpell core modules...[xd, xem]"),this.loadModule(new C),this.loadModule(new I),c.log("Starting Xpell"),this.onFrame()}getCoreSkills(){return[U,L]}getModuleSkills(){return Object.values(this._modules).flatMap(e=>typeof e.getSkillChain=="function"?e.getSkillChain():[])}getSkills(){return{_runtime:{_engine_id:this._engine_id,_version:this._version},_skills:this.getCoreSkills(),_modules:Object.values(this._modules).map(e=>({_name:e._name,_skills:typeof e.getSkillChain=="function"?e.getSkillChain():[],_objects:typeof e.getObjectSkills=="function"?e.getObjectSkills():[]}))}}}const q=new ne;exports.XCommand=A;exports.XD_FPS=se;exports.XD_FRAME_NUMBER=te;exports.XData=v;exports.XDataModule=C;exports.XError=T;exports.XEventManagerModule=I;exports.XLogger=c;exports.XModule=E;exports.XObject=D;exports.XObjectManager=ee;exports.XObjectPack=he;exports.XParams=me;exports.XParser=w;exports.XResponse=b;exports.XResponseError=fe;exports.XResponseOK=ge;exports.XUtils=Q;exports.Xpell=q;exports.XpellEngine=ne;exports._XData=Z;exports._XEventManager=ie;exports._XLogger=z;exports._XUtils=H;exports._x=q;exports._xd=m;exports._xlog=c;exports._xu=l;exports.createNanoCommandWithSkill=g;exports.default=q;exports.getXEventManager=x;exports.setXEventManager=ae;
|