@esengine/ecs-framework 2.4.0 → 2.4.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/index.es5.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function t(e,t,n,r,i,o,s){try{var a=e[o](s),c=a.value}catch(e){return void n(e)}a.done?t(c):Promise.resolve(c).then(r,i)}function n(e){return function(){var n=this,r=arguments;return new Promise(function(i,o){var s=e.apply(n,r);function a(e){t(s,i,o,a,c,"next",e)}function c(e){t(s,i,o,a,c,"throw",e)}a(void 0)})}}function r(e,t,n){if(l())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&f(i,n.prototype),i}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,p(r.key),r)}}function o(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(t,n){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,n){if(t){if("string"==typeof t)return e(t,n);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?e(t,n):void 0}}(t))||n){r&&(t=r);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},a.apply(null,arguments)}function c(e){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},c(e)}function u(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,f(e,t)}function l(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(l=function(){return!!e})()}function h(){
1
+ "use strict";function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=Array(t);n<t;n++)i[n]=e[n];return i}function t(e,t,n,i,r,o,s){try{var a=e[o](s),c=a.value}catch(e){return void n(e)}a.done?t(c):Promise.resolve(c).then(i,r)}function n(e){return function(){var n=this,i=arguments;return new Promise(function(r,o){var s=e.apply(n,i);function a(e){t(s,r,o,a,c,"next",e)}function c(e){t(s,r,o,a,c,"throw",e)}a(void 0)})}}function i(e,t,n){if(l())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,t);var r=new(e.bind.apply(e,i));return n&&f(r,n.prototype),r}function r(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,p(i.key),i)}}function o(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(t,n){var i="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(i)return(i=i.call(t)).next.bind(i);if(Array.isArray(t)||(i=function(t,n){if(t){if("string"==typeof t)return e(t,n);var i={}.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?e(t,n):void 0}}(t))||n){i&&(t=i);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)({}).hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},a.apply(null,arguments)}function c(e){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},c(e)}function u(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,f(e,t)}function l(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(l=function(){return!!e})()}function h(){
2
2
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
3
- var e,t,n="function"==typeof Symbol?Symbol:{},r=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function o(n,r,i,o){var c=r&&r.prototype instanceof a?r:a,u=Object.create(c.prototype);return d(u,"_invoke",function(n,r,i){var o,a,c,u=0,l=i||[],h=!1,d={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return o=t,a=0,c=e,d.n=n,s}};function f(n,r){for(a=n,c=r,t=0;!h&&u&&!i&&t<l.length;t++){var i,o=l[t],f=d.p,p=o[2];n>3?(i=p===r)&&(c=o[(a=o[4])?5:(a=3,3)],o[4]=o[5]=e):o[0]<=f&&((i=n<2&&f<o[1])?(a=0,d.v=r,d.n=o[1]):f<p&&(i=n<3||o[0]>r||r>p)&&(o[4]=n,o[5]=r,d.n=p,a=0))}if(i||n>1)return s;throw h=!0,r}return function(i,l,p){if(u>1)throw TypeError("Generator is already running");for(h&&1===l&&f(l,p),a=l,c=p;(t=a<2?e:c)||!h;){o||(a?a<3?(a>1&&(d.n=-1),f(a,c)):d.n=c:d.v=c);try{if(u=2,o){if(a||(i="next"),t=o[i]){if(!(t=t.call(o,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,a<2&&(a=0)}else 1===a&&(t=o.return)&&t.call(o),a<2&&(c=TypeError("The iterator does not provide a '"+i+"' method"),a=1);o=e}else if((t=(h=d.n<0)?c:n.call(r,d))!==s)break}catch(t){o=e,a=1,c=t}finally{u=1}}return{value:t,done:h}}}(n,i,o),!0),u}var s={};function a(){}function c(){}function u(){}t=Object.getPrototypeOf;var l=[][r]?t(t([][r]())):(d(t={},r,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,d(e,i,"GeneratorFunction")),e.prototype=Object.create(f),e}return c.prototype=u,d(f,"constructor",u),d(u,"constructor",c),c.displayName="GeneratorFunction",d(u,i,"GeneratorFunction"),d(f),d(f,i,"Generator"),d(f,r,function(){return this}),d(f,"toString",function(){return"[object Generator]"}),(h=function(){return{w:o,m:p}})()}function d(e,t,n,r){var i=Object.defineProperty;try{i({},"",{})}catch(e){i=0}d=function(e,t,n,r){function o(t,n){d(e,t,function(e){return this._invoke(t,n,e)})}t?i?i(e,t,{value:n,enumerable:!r,configurable:!r,writable:!r}):e[t]=n:(o("next",0),o("throw",1),o("return",2))},d(e,t,n,r)}function f(e,t){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},f(e,t)}function p(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t);if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e,"string");return"symbol"==typeof t?t:t+""}function m(e){var t="function"==typeof Map?new Map:void 0;return m=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return r(e,arguments,c(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),f(n,e)},m(e)}function v(e,t,n,r){var i,o=arguments.length,s=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(s=(o<3?i(s):o>3?i(t,n,s):i(t,n))||s);return o>3&&s&&Object.defineProperty(t,n,s),s}function y(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}"function"==typeof SuppressedError&&SuppressedError;var g=function(){function e(){}return e.update=function(e){this.unscaledDeltaTime=e,this.deltaTime=e*this.timeScale,this.unscaledTotalTime+=this.unscaledDeltaTime,this.totalTime+=this.deltaTime,this.frameCount++},e.sceneChanged=function(){this.frameCount=0,this.totalTime=0,this.unscaledTotalTime=0,this.deltaTime=0,this.unscaledDeltaTime=0},e.checkEvery=function(e,t){return this.totalTime-t>=e},e}();g.deltaTime=0,g.unscaledDeltaTime=0,g.totalTime=0,g.unscaledTotalTime=0,g.timeScale=1,g.frameCount=0;var _,S=function(){function e(){this._timeInSeconds=0,this._repeats=!1,this._isDone=!1,this._elapsedTime=0}var t=e.prototype;return t.getContext=function(){return this.context},t.reset=function(){this._elapsedTime=0},t.stop=function(){this._isDone=!0},t.tick=function(){return!this._isDone&&this._elapsedTime>this._timeInSeconds&&(this._elapsedTime-=this._timeInSeconds,this._onTime(this),this._isDone||this._repeats||(this._isDone=!0)),this._elapsedTime+=g.deltaTime,this._isDone},t.initialize=function(e,t,n,r){this._timeInSeconds=e,this._repeats=t,this.context=n,this._onTime=r.bind(n)},t.unload=function(){this.context=null,this._onTime=null},o(e,[{key:"isDone",get:function(){return this._isDone}},{key:"elapsedTime",get:function(){return this._elapsedTime}}])}(),C=new WeakMap,E=new WeakMap;function b(){return function(e){var t=C.get(e);C.set(e,a({injectable:!0,dependencies:[]},(null==t?void 0:t.properties)&&{properties:t.properties}))}}function T(e){return void 0===e&&(e=0),function(t){var n=t.prototype;if(!n||"function"!=typeof n.update)throw new Error("@Updatable() decorator requires class "+t.name+" to implement IUpdatable interface with update() method. Please add 'implements IUpdatable' and define update(deltaTime?: number): void method.");E.set(t,{updatable:!0,priority:e})}}function w(e){return function(t,n){var r=C.get(t.constructor);r||(r={injectable:!0,dependencies:[]},C.set(t.constructor,r)),r.properties||(r.properties=new Map),r.properties.set(n,e)}}function M(e){var t,n=C.get(e);return null!==(t=null==n?void 0:n.injectable)&&void 0!==t&&t}function x(e,t){var n=new e;return I(n,t),n}function I(e,t){var n,r=e.constructor,i=(n=r,C.get(n));if(null!=i&&i.properties&&0!==i.properties.size)for(var o,a=s(i.properties);!(o=a()).done;){var c=o.value,u=c[0],l=c[1],h=t.resolve(l);null!==h&&(e[u]=h)}}function A(e){var t,n=E.get(e);return null!==(t=null==n?void 0:n.updatable)&&void 0!==t&&t}function k(e){return E.get(e)}exports.TimerManager=function(){function e(){this._timers=[]}var t=e.prototype;return t.update=function(){for(var e=this._timers.length-1;e>=0;e--)this._timers[e].tick()&&(this._timers[e].unload(),this._timers.splice(e,1))},t.schedule=function(e,t,n,r){var i=new S;return i.initialize(e,t,n,r),this._timers.push(i),i},t.dispose=function(){for(var e,t=s(this._timers);!(e=t()).done;){e.value.unload()}this._timers=[]},e}(),exports.TimerManager=v([T()],exports.TimerManager),exports.PerformanceWarningType=void 0,(_=exports.PerformanceWarningType||(exports.PerformanceWarningType={})).HIGH_EXECUTION_TIME="high_execution_time",_.HIGH_MEMORY_USAGE="high_memory_usage",_.HIGH_CPU_USAGE="high_cpu_usage",_.FREQUENT_GC="frequent_gc",_.LOW_FPS="low_fps",_.HIGH_ENTITY_COUNT="high_entity_count";var P=function(){function e(){this._systemData=new Map,this._systemStats=new Map,this._isEnabled=!1,this._maxRecentSamples=60}var t=e.prototype;return t.enable=function(){this._isEnabled=!0},t.disable=function(){this._isEnabled=!1},t.startMonitoring=function(e){return this._isEnabled?performance.now():0},t.endMonitoring=function(e,t,n){if(void 0===n&&(n=0),this._isEnabled&&0!==t){var r=performance.now(),i=r-t,o={name:e,executionTime:i,entityCount:n,averageTimePerEntity:n>0?i/n:0,lastUpdateTime:r};this._systemData.set(e,o),this.updateStats(e,i)}},t.updateStats=function(e,t){var n=this._systemStats.get(e);n||(n={totalTime:0,averageTime:0,minTime:Number.MAX_VALUE,maxTime:0,executionCount:0,recentTimes:[],standardDeviation:0,percentile95:0,percentile99:0},this._systemStats.set(e,n)),n.totalTime+=t,n.executionCount++,n.averageTime=n.totalTime/n.executionCount,n.minTime=Math.min(n.minTime,t),n.maxTime=Math.max(n.maxTime,t),n.recentTimes.push(t),n.recentTimes.length>this._maxRecentSamples&&n.recentTimes.shift(),this.calculateAdvancedStats(n)},t.calculateAdvancedStats=function(e){if(0!==e.recentTimes.length){var t=e.recentTimes.reduce(function(e,t){return e+t},0)/e.recentTimes.length,n=e.recentTimes.reduce(function(e,n){return e+Math.pow(n-t,2)},0)/e.recentTimes.length;e.standardDeviation=Math.sqrt(n);var r=[].concat(e.recentTimes).sort(function(e,t){return e-t}),i=r.length;e.percentile95=r[Math.floor(.95*i)]||0,e.percentile99=r[Math.floor(.99*i)]||0}},t.getSystemData=function(e){return this._systemData.get(e)},t.getSystemStats=function(e){return this._systemStats.get(e)},t.getAllSystemData=function(){return new Map(this._systemData)},t.getAllSystemStats=function(){return new Map(this._systemStats)},t.getPerformanceReport=function(){if(!this._isEnabled)return"Performance monitoring is disabled.";var e=[];e.push("=== ECS Performance Report ==="),e.push("");for(var t,n=s(Array.from(this._systemStats.entries()).sort(function(e,t){return t[1].averageTime-e[1].averageTime}));!(t=n()).done;){var r=t.value,i=r[0],o=r[1],a=this._systemData.get(i);e.push("System: "+i),e.push(" Current: "+(null==a?void 0:a.executionTime.toFixed(2))+"ms ("+(null==a?void 0:a.entityCount)+" entities)"),e.push(" Average: "+o.averageTime.toFixed(2)+"ms"),e.push(" Min/Max: "+o.minTime.toFixed(2)+"ms / "+o.maxTime.toFixed(2)+"ms"),e.push(" Total: "+o.totalTime.toFixed(2)+"ms ("+o.executionCount+" calls)"),null!=a&&a.averageTimePerEntity&&a.averageTimePerEntity>0&&e.push(" Per Entity: "+a.averageTimePerEntity.toFixed(4)+"ms"),e.push("")}var c=Array.from(this._systemData.values()).reduce(function(e,t){return e+t.executionTime},0);return e.push("Total Frame Time: "+c.toFixed(2)+"ms"),e.push("Systems Count: "+this._systemData.size),e.join("\n")},t.reset=function(){this._systemData.clear(),this._systemStats.clear()},t.resetSystem=function(e){this._systemData.delete(e),this._systemStats.delete(e)},t.getPerformanceWarnings=function(e){void 0===e&&(e=16.67);for(var t,n=[],r=s(this._systemData.entries());!(t=r()).done;){var i=t.value,o=i[0],a=i[1];a.executionTime>e&&n.push(o+": "+a.executionTime.toFixed(2)+"ms (>"+e+"ms)")}return n},t.setMaxRecentSamples=function(e){this._maxRecentSamples=e;for(var t,n=s(this._systemStats.values());!(t=n()).done;)for(var r=t.value;r.recentTimes.length>e;)r.recentTimes.shift()},t.dispose=function(){this._systemData.clear(),this._systemStats.clear(),this._isEnabled=!1},o(e,[{key:"isEnabled",get:function(){return this._isEnabled}}])}(),O=function(){function e(e,t,n){void 0===t&&(t=100),void 0===n&&(n=1024),this._objects=[],this._createFn=e,this._maxSize=t,this._objectSize=n,this._stats={size:0,maxSize:t,totalCreated:0,totalObtained:0,totalReleased:0,hitRate:0,estimatedMemoryUsage:0}}e.getPool=function(t,n,r){void 0===n&&(n=100),void 0===r&&(r=1024);var i=this._pools.get(t);return i||(i=new e(function(){return new t},n,r),this._pools.set(t,i)),i};var t=e.prototype;return t.obtain=function(){if(this._stats.totalObtained++,this._objects.length>0){var e=this._objects.pop();return this._stats.size--,this._updateHitRate(),this._updateMemoryUsage(),e}return this._stats.totalCreated++,this._updateHitRate(),this._createFn()},t.release=function(e){e&&(this._stats.totalReleased++,this._stats.size<this._maxSize&&(e.reset(),this._objects.push(e),this._stats.size++,this._updateMemoryUsage()))},t.getStats=function(){return a({},this._stats)},t.clear=function(){for(var e,t=s(this._objects);!(e=t()).done;){e.value.reset()}this._objects.length=0,this._stats.size=0,this._updateMemoryUsage()},t.compact=function(e){for(var t=null!=e?e:Math.floor(this._objects.length/2);this._objects.length>t;){var n=this._objects.pop();n&&(n.reset(),this._stats.size--)}this._updateMemoryUsage()},t.prewarm=function(e){for(var t=Math.min(e,this._maxSize-this._objects.length),n=0;n<t;n++){var r=this._createFn();r.reset(),this._objects.push(r),this._stats.totalCreated++,this._stats.size++}this._updateMemoryUsage()},t.setMaxSize=function(e){this._maxSize=e,this._stats.maxSize=e,this._objects.length>e&&this.compact(e)},t.getAvailableCount=function(){return this._objects.length},t.isEmpty=function(){return 0===this._objects.length},t.isFull=function(){return this._objects.length>=this._maxSize},e.getAllPoolTypes=function(){return Array.from(this._pools.keys())},e.getAllPoolStats=function(){for(var e,t={},n=s(this._pools);!(e=n()).done;){var r=e.value,i=r[0],o=r[1];t[i.name||i.toString()]=o.getStats()}return t},e.compactAllPools=function(){for(var e,t=s(this._pools.values());!(e=t()).done;){e.value.compact()}},e.clearAllPools=function(){for(var e,t=s(this._pools.values());!(e=t()).done;){e.value.clear()}this._pools.clear()},e.getGlobalStatsString=function(){var e=this.getAllPoolStats(),t=["=== Object Pool Global Statistics ===",""];if(0===Object.keys(e).length)return t.push("No pools registered"),t.join("\n");for(var n=0,r=Object.entries(e);n<r.length;n++){var i=r[n],o=i[0],s=i[1];t.push(o+":"),t.push(" Size: "+s.size+"/"+s.maxSize),t.push(" Hit Rate: "+(100*s.hitRate).toFixed(1)+"%"),t.push(" Total Created: "+s.totalCreated),t.push(" Total Obtained: "+s.totalObtained),t.push(" Memory: "+(s.estimatedMemoryUsage/1024).toFixed(1)+" KB"),t.push("")}return t.join("\n")},t._updateHitRate=function(){if(0===this._stats.totalObtained)this._stats.hitRate=0;else{var e=this._stats.totalObtained-this._stats.totalCreated;this._stats.hitRate=e/this._stats.totalObtained}},t._updateMemoryUsage=function(){this._stats.estimatedMemoryUsage=this._stats.size*this._objectSize},e}();O._pools=new Map;var D,R=function(){function e(){this.pools=new Map,this.autoCompactInterval=6e4,this.lastCompactTime=0}var t=e.prototype;return t.registerPool=function(e,t){this.pools.set(e,t)},t.getPool=function(e){return this.pools.get(e)||null},t.update=function(){var e=Date.now();e-this.lastCompactTime>this.autoCompactInterval&&(this.compactAllPools(),this.lastCompactTime=e)},t.createPool=function(e,t,n,r){void 0===n&&(n=100),void 0===r&&(r=1024);var i=this.pools.get(e);return i||(i=new O(t,n,r),this.pools.set(e,i)),i},t.removePool=function(e){var t=this.pools.get(e);return!!t&&(t.clear(),this.pools.delete(e),!0)},t.getPoolNames=function(){return Array.from(this.pools.keys())},t.getPoolCount=function(){return this.pools.size},t.compactAllPools=function(){for(var e,t=s(this.pools.values());!(e=t()).done;){e.value.compact()}},t.clearAllPools=function(){for(var e,t=s(this.pools.values());!(e=t()).done;){e.value.clear()}},t.getAllStats=function(){for(var e,t=new Map,n=s(this.pools);!(e=n()).done;){var r=e.value,i=r[0],o=r[1];t.set(i,o.getStats())}return t},t.getGlobalStats=function(){for(var e,t=0,n=0,r=0,i=0,o=0,a=0,c=s(this.pools.values());!(e=c()).done;){var u=e.value.getStats();t+=u.size,n+=u.maxSize,r+=u.totalCreated,i+=u.totalObtained,o+=u.totalReleased,a+=u.estimatedMemoryUsage}return{size:t,maxSize:n,totalCreated:r,totalObtained:i,totalReleased:o,hitRate:0===i?0:(i-r)/i,estimatedMemoryUsage:a}},t.getStatsString=function(){var e=["=== Pool Manager Statistics ===",""];if(0===this.pools.size)return e.push("No pools registered"),e.join("\n");var t=this.getGlobalStats();e.push("Total Pools: "+this.pools.size),e.push("Global Hit Rate: "+(100*t.hitRate).toFixed(1)+"%"),e.push("Global Memory Usage: "+(t.estimatedMemoryUsage/1024).toFixed(1)+" KB"),e.push("");for(var n,r=s(this.pools);!(n=r()).done;){var i=n.value,o=i[0],a=i[1].getStats();e.push(o+":"),e.push(" Size: "+a.size+"/"+a.maxSize),e.push(" Hit Rate: "+(100*a.hitRate).toFixed(1)+"%"),e.push(" Memory: "+(a.estimatedMemoryUsage/1024).toFixed(1)+" KB"),e.push("")}return e.join("\n")},t.setAutoCompactInterval=function(e){this.autoCompactInterval=e},t.prewarmAllPools=function(){for(var e,t=s(this.pools.values());!(e=t()).done;){var n=e.value,r=n.getStats(),i=Math.floor(.2*r.maxSize);n.prewarm(i)}},t.reset=function(){this.clearAllPools(),this.pools.clear(),this.lastCompactTime=0},t.dispose=function(){this.reset()},e}(),z=Symbol("ComponentTypeName"),N=Symbol("ComponentDependencies"),F=Symbol("ComponentEditorOptions");function B(e){return!!e[z]}function L(e){var t=e[z];return t||(e.name||"UnknownComponent")}function H(e){return L(e.constructor)}function W(e){return e[F]}function j(e){var t,n=W(e);return null!==(t=null==n?void 0:n.hideInInspector)&&void 0!==t&&t}!function(e){e[e.LOW=0]="LOW",e[e.HIGH=1]="HIGH"}(D||(D={}));var G,U=function(){function e(){}return e.create=function(t){if(t<0)throw new Error("Bit index "+t+" out of range [0, ∞)");var n={base:[0,0]};return e.setBit(n,t),n},e.fromNumber=function(e){return{base:[e>>>0,0]}},e.hasAny=function(e,t){var n=t.base,r=e.base,i=t.segments,o=e.segments,s=0!==(r[D.LOW]&n[D.LOW])||0!==(r[D.HIGH]&n[D.HIGH]);return!s&&i&&o?o.some(function(e,t){var n=i[t];return n&&(0!==(e[D.LOW]&n[D.LOW])||0!==(e[D.HIGH]&n[D.HIGH]))}):s},e.hasAll=function(e,t){var n,r=e.base,i=t.base,o=e.segments,s=t.segments,a=(r[D.LOW]&i[D.LOW])===i[D.LOW]&&(r[D.HIGH]&i[D.HIGH])===i[D.HIGH];if(!a||!s)return a;var c=null!==(n=null==o?void 0:o.length)&&void 0!==n?n:0;if(o)for(var u=0;u<Math.min(c,s.length);u++){var l=o[u],h=s[u];if((l[D.LOW]&h[D.LOW])!==h[D.LOW]||(l[D.HIGH]&h[D.HIGH])!==h[D.HIGH])return!1}for(var d=c;d<s.length;d++){var f=s[d];if(0!==f[D.LOW]||0!==f[D.HIGH])return!1}return!0},e.hasNone=function(e,t){var n=e.base,r=t.base,i=e.segments,o=t.segments,s=0===(n[D.LOW]&r[D.LOW])&&0===(n[D.HIGH]&r[D.HIGH]);return i&&s&&o?i.every(function(e,t){var n=o[t];return!n||0===(e[D.LOW]&n[D.LOW])&&0===(e[D.HIGH]&n[D.HIGH])}):s},e.isZero=function(e){var t=0===e.base[D.LOW]&&0===e.base[D.HIGH];return e.segments&&t?e.segments.every(function(e){return 0===e[D.LOW]&&0===e[D.HIGH]}):t},e.equals=function(e,t){var n,r,i=e.base[D.LOW]===t.base[D.LOW]&&e.base[D.HIGH]===t.base[D.HIGH];if(!i||!e.segments&&!t.segments)return i;for(var o=null!==(n=e.segments)&&void 0!==n?n:[],s=null!==(r=t.segments)&&void 0!==r?r:[],a=0;a<Math.max(o.length,s.length);a++){var c=o[a],u=s[a];if(c&&!u){if(0!==c[D.LOW]||0!==c[D.HIGH])return!1}else if(!c&&u){if(0!==u[D.LOW]||0!==u[D.HIGH])return!1}else if(c&&u&&(c[D.LOW]!==u[D.LOW]||c[D.HIGH]!==u[D.HIGH]))return!1}return!0},e.setBit=function(t,n){if(n<0)throw new Error("Bit index "+n+" out of range [0, 63]");var r=e.getSegmentByBitIndex(t,n),i=63&n;i<32?r[D.LOW]|=1<<i:r[D.HIGH]|=1<<i-32},e.getBit=function(t,n){if(n<0)return!1;var r=e.getSegmentByBitIndex(t,n,!1);if(!r)return!1;var i=63&n;return i<32?!!(r[D.LOW]&1<<i):!!(r[D.HIGH]&1<<i-32)},e.clearBit=function(t,n){if(n<0)throw new Error("Bit index "+n+" out of range [0, 63]");var r=e.getSegmentByBitIndex(t,n,!1);if(r){var i=63&n;i<32?r[D.LOW]&=~(1<<i):r[D.HIGH]&=~(1<<i-32)}},e.orInPlace=function(e,t){e.base[D.LOW]|=t.base[D.LOW],e.base[D.HIGH]|=t.base[D.HIGH];var n=t.segments;if(n&&n.length>0){e.segments||(e.segments=[]);for(var r=e.segments;r.length<n.length;)r.push([0,0]);for(var i=0;i<n.length;i++){var o=r[i],s=n[i];o[D.LOW]|=s[D.LOW],o[D.HIGH]|=s[D.HIGH]}}},e.andInPlace=function(e,t){e.base[D.LOW]&=t.base[D.LOW],e.base[D.HIGH]&=t.base[D.HIGH];var n=t.segments;if(n&&n.length>0){e.segments||(e.segments=[]);for(var r=e.segments;r.length<n.length;)r.push([0,0]);for(var i=0;i<n.length;i++){var o=r[i],s=n[i];o[D.LOW]&=s[D.LOW],o[D.HIGH]&=s[D.HIGH]}}},e.xorInPlace=function(e,t){e.base[D.LOW]^=t.base[D.LOW],e.base[D.HIGH]^=t.base[D.HIGH];var n=t.segments;if(n&&0!=n.length){e.segments||(e.segments=[]);for(var r=e.segments;r.length<n.length;)r.push([0,0]);for(var i=0;i<n.length;i++){var o=r[i],s=n[i];o[D.LOW]^=s[D.LOW],o[D.HIGH]^=s[D.HIGH]}}},e.clear=function(e){if(e.base[D.LOW]=0,e.base[D.HIGH]=0,e.segments)for(var t=0;t<e.segments.length;t++){var n=e.segments[t];n[D.LOW]=0,n[D.HIGH]=0}},e.copy=function(t,n){if(e.clear(n),n.base[D.LOW]=t.base[D.LOW],n.base[D.HIGH]=t.base[D.HIGH],t.segments&&0!=t.segments.length)if(n.segments){for(var r=t.segments.length-n.segments.length,i=0;i<r;i++)n.segments.push([0,0]);for(var o=n.segments,s=t.segments,a=0;a<s.length;a++){var c=o[a],u=s[a];c[D.LOW]=u[D.LOW],c[D.HIGH]=u[D.HIGH]}}else n.segments=t.segments.map(function(e){return[].concat(e)})},e.clone=function(e){return a({base:e.base.slice()},e.segments&&{segments:e.segments.map(function(e){return[].concat(e)})})},e.toString=function(e,t,n){var r,i;void 0===t&&(t=2),void 0===n&&(n=!1),2!=t&&16!=t&&(t=2);var o=null!==(r=null===(i=e.segments)||void 0===i?void 0:i.length)&&void 0!==r?r:0,s="";if(n){var a=0;a=2===t?66:19;for(var c=0;c<=o;c++){s+=(0===c?"0 (Base):":c+" ("+64*c+"):").toString().padEnd(a)}s+="\n"}for(var u=-1;u<o;u++){var l="",h=-1==u?e.base:e.segments[u],d=h[D.HIGH],f=h[D.LOW];if(2==t){l=d.toString(2).padStart(32,"0")+"_"+f.toString(2).padStart(32,"0")}else{var p=d?d.toString(16).toUpperCase():"";n&&(p=p.padStart(8,"0"));var m=f.toString(16).toUpperCase();p&&(m=m.padStart(8,"0")),l="0x"+p+m}s+=-1===u?l:" "+l}return s},e.popCount=function(e){for(var t=0,n=-1;n<(null!==(r=null===(i=e.segments)||void 0===i?void 0:i.length)&&void 0!==r?r:0);n++){for(var r,i,o=-1==n?e.base:e.segments[n],s=o[D.LOW],a=o[D.HIGH];s;)s&=s-1,t++;for(;a;)a&=a-1,t++}return t},e.getSegmentByBitIndex=function(e,t,n){if(void 0===n&&(n=!0),t<=63)return e.base;var r,i=e.segments;if(!i){if(!n)return null;i=e.segments=[]}var o=(t>>6)-1;if(i.length<=o){if(!n)return null;for(var s=o-i.length+1,a=0;a<s;a++)i.push([0,0])}return null!==(r=i[o])&&void 0!==r?r:null},e}();U.ZERO={base:[0,0]},exports.LogLevel=void 0,(G=exports.LogLevel||(exports.LogLevel={}))[G.Debug=0]="Debug",G[G.Info=1]="Info",G[G.Warn=2]="Warn",G[G.Error=3]="Error",G[G.Fatal=4]="Fatal",G[G.None=5]="None";var q={BLACK:"",RED:"",GREEN:"",YELLOW:"",BLUE:"",MAGENTA:"",CYAN:"",WHITE:"",BRIGHT_BLACK:"",BRIGHT_RED:"",BRIGHT_GREEN:"",BRIGHT_YELLOW:"",BRIGHT_BLUE:"",BRIGHT_MAGENTA:"",BRIGHT_CYAN:"",BRIGHT_WHITE:"",RESET:"",BOLD:"",UNDERLINE:""},Q=function(){function e(e){void 0===e&&(e={}),this._config=a({level:exports.LogLevel.Info,enableTimestamp:!0,enableColors:"undefined"==typeof window},e)}var t=e.prototype;return t.debug=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[exports.LogLevel.Debug,e].concat(n))},t.info=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[exports.LogLevel.Info,e].concat(n))},t.warn=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[exports.LogLevel.Warn,e].concat(n))},t.error=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[exports.LogLevel.Error,e].concat(n))},t.fatal=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.log.apply(this,[exports.LogLevel.Fatal,e].concat(n))},t.setLevel=function(e){this._config.level=e},t.setColors=function(e){0===Object.keys(e).length?delete this._config.colors:this._config.colors=a({},this._config.colors,e)},t.setPrefix=function(e){this._config.prefix=e},t.log=function(e,t){if(!(e<this._config.level)){var n=t;if(this._config.enableTimestamp)n="["+(new Date).toISOString()+"] "+n;if(this._config.prefix&&(n="["+this._config.prefix+"] "+n),n="["+exports.LogLevel[e].toUpperCase()+"] "+n,this._config.output)this._config.output(e,n);else{for(var r=arguments.length,i=new Array(r>2?r-2:0),o=2;o<r;o++)i[o-2]=arguments[o];this.outputToConsole.apply(this,[e,n].concat(i))}}},t.outputToConsole=function(e,t){for(var n=this._config.enableColors?this.getColors():null,r=arguments.length,i=new Array(r>2?r-2:0),o=2;o<r;o++)i[o-2]=arguments[o];switch(e){case exports.LogLevel.Debug:var s,a;if(n)(s=console).debug.apply(s,[""+n.debug+t+n.reset].concat(i));else(a=console).debug.apply(a,[t].concat(i));break;case exports.LogLevel.Info:var c,u;if(n)(c=console).info.apply(c,[""+n.info+t+n.reset].concat(i));else(u=console).info.apply(u,[t].concat(i));break;case exports.LogLevel.Warn:var l,h;if(n)(l=console).warn.apply(l,[""+n.warn+t+n.reset].concat(i));else(h=console).warn.apply(h,[t].concat(i));break;case exports.LogLevel.Error:var d,f;if(n)(d=console).error.apply(d,[""+n.error+t+n.reset].concat(i));else(f=console).error.apply(f,[t].concat(i));break;case exports.LogLevel.Fatal:var p,m;if(n)(p=console).error.apply(p,[""+n.fatal+t+n.reset].concat(i));else(m=console).error.apply(m,[t].concat(i))}},t.getColors=function(){return a({},{debug:q.BRIGHT_BLACK,info:q.GREEN,warn:q.YELLOW,error:q.RED,fatal:q.BRIGHT_RED,reset:q.RESET},this._config.colors)},e}(),V=function(){function e(){this._loggers=new Map,this._defaultLevel=exports.LogLevel.Info}var t=e.prototype;return t.createDefaultLogger=function(){return this._loggerFactory?this._loggerFactory():new Q({level:this._defaultLevel})},e.getInstance=function(){return e._instance||(e._instance=new e),e._instance},t.getLogger=function(e){return e?this._loggerFactory?this._loggerFactory(e):(this._loggers.has(e)||this._loggers.set(e,new Q({prefix:e,level:this._defaultLevel})),this._loggers.get(e)):this.defaultLogger},t.setLogger=function(e,t){this._loggers.set(e,t)},t.setGlobalLevel=function(e){this._defaultLevel=e,this._defaultLogger instanceof Q&&this._defaultLogger.setLevel(e);for(var t,n=s(this._loggers.values());!(t=n()).done;){var r=t.value;r instanceof Q&&r.setLevel(e)}},t.createChildLogger=function(e,t){var n=e+"."+t;return this.getLogger(n)},t.setGlobalColors=function(e){this._defaultLogger instanceof Q&&this._defaultLogger.setColors(e);for(var t,n=s(this._loggers.values());!(t=n()).done;){var r=t.value;r instanceof Q&&r.setColors(e)}},t.resetColors=function(){this._defaultLogger instanceof Q&&this._defaultLogger.setColors({});for(var e,t=s(this._loggers.values());!(e=t()).done;){var n=e.value;n instanceof Q&&n.setColors({})}},t.setLoggerFactory=function(e){this._loggerFactory=e,delete this._defaultLogger,this._loggers.clear()},o(e,[{key:"defaultLogger",get:function(){return this._defaultLogger||(this._defaultLogger=this.createDefaultLogger()),this._defaultLogger}}])}(),Y=V.getInstance().getLogger();function J(e){return V.getInstance().getLogger(e)}var K=function(){function e(){}return e.register=function(e){var t=L(e);if(B(e)||this.warnedComponents.has(e)||(this.warnedComponents.add(e),console.warn('[ComponentRegistry] Component "'+t+"\" is missing @ECSComponent decorator. This may cause issues with serialization and code minification. Please add: @ECSComponent('"+t+"')")),this.componentTypes.has(e))return this.componentTypes.get(e);if(this.hotReloadEnabled&&this.componentNameToType.has(t)){var n=this.componentNameToType.get(t);if(n!==e){var r=this.componentTypes.get(n);return this.componentTypes.delete(n),this.componentTypes.set(e,r),this.bitIndexToType.set(r,e),this.componentNameToType.set(t,e),console.log('[ComponentRegistry] Hot reload: replaced component "'+t+'"'),r}}var i=this.nextBitIndex++;return this.componentTypes.set(e,i),this.bitIndexToType.set(i,e),this.componentNameToType.set(t,e),this.componentNameToId.set(t,i),i},e.getBitMask=function(e){var t=this.componentTypes.get(e);if(void 0===t){var n=L(e);throw new Error("Component type "+n+" is not registered")}return U.create(t)},e.getBitIndex=function(e){var t=this.componentTypes.get(e);if(void 0===t){var n=L(e);throw new Error("Component type "+n+" is not registered")}return t},e.isRegistered=function(e){return this.componentTypes.has(e)},e.getTypeByBitIndex=function(e){return this.bitIndexToType.get(e)||null},e.getRegisteredCount=function(){return this.nextBitIndex},e.getComponentType=function(e){return this.componentNameToType.get(e)||null},e.getAllRegisteredTypes=function(){return new Map(this.componentTypes)},e.getAllComponentNames=function(){return new Map(this.componentNameToType)},e.getComponentId=function(e){return this.componentNameToId.get(e)},e.registerComponentByName=function(e){if(this.componentNameToId.has(e))return this.componentNameToId.get(e);var t=this.nextBitIndex++;return this.componentNameToId.set(e,t),t},e.createSingleComponentMask=function(e){var t="single:"+e;if(this.maskCache.has(t))return this.maskCache.get(t);var n=this.getComponentId(e);if(void 0===n)throw new Error("Component type "+e+" is not registered");var r=U.create(n);return this.maskCache.set(t,r),r},e.createComponentMask=function(e){var t="multi:"+[].concat(e).sort().join(",");if(this.maskCache.has(t))return this.maskCache.get(t);for(var n,r=U.clone(U.ZERO),i=s(e);!(n=i()).done;){var o=n.value,a=this.getComponentId(o);if(void 0!==a){var c=U.create(a);U.orInPlace(r,c)}}return this.maskCache.set(t,r),r},e.clearMaskCache=function(){this.maskCache.clear()},e.enableHotReload=function(){this.hotReloadEnabled=!0},e.disableHotReload=function(){this.hotReloadEnabled=!1},e.isHotReloadEnabled=function(){return this.hotReloadEnabled},e.unregister=function(e){var t=this.componentNameToType.get(e);if(t){var n=this.componentTypes.get(t);this.componentTypes.delete(t),void 0!==n&&this.bitIndexToType.delete(n),this.componentNameToType.delete(e),this.componentNameToId.delete(e),this.clearMaskCache(),this._logger.debug("Component unregistered: "+e)}},e.getRegisteredComponents=function(){for(var e,t=[],n=s(this.componentNameToType);!(e=n()).done;){var r=e.value,i=r[0],o=r[1],a=this.componentTypes.get(o);void 0!==a&&t.push({name:i,type:o,bitIndex:a})}return t},e.reset=function(){this.componentTypes.clear(),this.bitIndexToType.clear(),this.componentNameToType.clear(),this.componentNameToId.clear(),this.maskCache.clear(),this.warnedComponents.clear(),this.nextBitIndex=0,this.hotReloadEnabled=!1},e}();K._logger=J("ComponentStorage"),K.componentTypes=new Map,K.bitIndexToType=new Map,K.componentNameToType=new Map,K.componentNameToId=new Map,K.maskCache=new Map,K.nextBitIndex=0,K.hotReloadEnabled=!1,K.warnedComponents=new Set;var Z=Symbol("SystemTypeName");function X(e,t){return function(n){if(!e||"string"!=typeof e)throw new Error("ECSComponent装饰器必须提供有效的类型名称");return n[z]=e,null!=t&&t.requires&&(n[N]=t.requires),null!=t&&t.editor&&(n[F]=t.editor),K.register(n),n}}function $(e){return e.__systemMetadata__}function ee(e){var t=e[Z];return t||(e.name||"UnknownSystem")}function te(e){return ee(e.constructor)}var ne=function(){function e(e){this._target=e}return e.prototype.deref=function(){return this._target},e}(),re="undefined"!=typeof globalThis&&globalThis.WeakRef||"undefined"!=typeof global&&global.WeakRef||"undefined"!=typeof window&&window.WeakRef||ne,ie=new Map;function oe(e){var t=ie.get(e);return(null==t?void 0:t.deref())||null}var se=function(){function e(){this._references=new Map}var t=e.prototype;return t.registerReference=function(e,t,n){var r=e.id,i=this._references.get(r);i||(i=new Set,this._references.set(r,i)),this._findRecord(i,t,n)||i.add({component:new re(t),propertyKey:n})},t.unregisterReference=function(e,t,n){var r=e.id,i=this._references.get(r);if(i){var o=this._findRecord(i,t,n);o&&(i.delete(o),0===i.size&&this._references.delete(r))}},t.clearReferencesTo=function(e){var t=this._references.get(e);if(t){for(var n,r=[],i=s(t);!(n=i()).done;){var o=n.value;o.component.deref()&&r.push(o)}for(var a=0,c=r;a<c.length;a++){var u=c[a],l=u.component.deref();l&&(l[u.propertyKey]=null)}this._references.delete(e)}},t.clearComponentReferences=function(e){for(var t,n=s(this._references.entries());!(t=n()).done;){for(var r,i=t.value,o=i[0],a=i[1],c=[],u=s(a);!(r=u()).done;){var l=r.value,h=l.component.deref();h&&h!==e||c.push(l)}for(var d=0,f=c;d<f.length;d++){var p=f[d];a.delete(p)}0===a.size&&this._references.delete(o)}},t.getReferencesTo=function(e){var t=this._references.get(e);if(!t)return[];for(var n,r=[],i=s(t);!(n=i()).done;){var o=n.value;o.component.deref()&&r.push(o)}return r},t.cleanup=function(){for(var e,t=[],n=s(this._references.entries());!(e=n()).done;){for(var r,i=e.value,o=i[0],a=i[1],c=[],u=s(a);!(r=u()).done;){var l=r.value;l.component.deref()||c.push(l)}for(var h=0,d=c;h<d.length;h++){var f=d[h];a.delete(f)}0===a.size&&t.push(o)}for(var p=0,m=t;p<m.length;p++){var v=m[p];this._references.delete(v)}},t.registerEntityScene=function(e,t){ie.set(e,new re(t))},t.unregisterEntityScene=function(e){ie.delete(e)},t.getDebugInfo=function(){for(var e,t={},n=s(this._references.entries());!(e=n()).done;){for(var r,i=e.value,o=i[0],a=[],c=s(i[1]);!(r=c()).done;){var u=r.value,l=u.component.deref();l&&a.push({componentId:l.id,propertyKey:u.propertyKey})}a.length>0&&(t["entity_"+o]=a)}return t},t._findRecord=function(e,t,n){for(var r,i=s(e);!(r=i()).done;){var o=r.value;if(o.component.deref()===t&&o.propertyKey===n)return o}},e}(),ae=J("EntityRefDecorator"),ce=Symbol("EntityRefMetadata"),ue=Symbol("EntityRefValues");function le(e){var t=e[ue];return t||(t=new Map,e[ue]=t),t}function he(e){return e&&("function"==typeof e?e:e.constructor)[ce]||null}function de(e,t){var n=he(e);return!!n&&n.properties.has(t)}var fe,pe="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},me={};!function(){return fe||(fe=1,function(e){!function(){var t="object"==typeof globalThis?globalThis:"object"==typeof pe?pe:"object"==typeof self?self:"object"==typeof this?this:function(){try{return Function("return this;")()}catch(e){}}()||function(){try{return(0,eval)("(function() { return this; })()")}catch(e){}}(),n=r(e);function r(e,t){return function(n,r){Object.defineProperty(e,n,{configurable:!0,writable:!0,value:r}),t&&t(n,r)}}void 0!==t.Reflect&&(n=r(t.Reflect,n)),function(e,t){var n=Object.prototype.hasOwnProperty,r="function"==typeof Symbol,i=r&&void 0!==Symbol.toPrimitive?Symbol.toPrimitive:"@@toPrimitive",o=r&&void 0!==Symbol.iterator?Symbol.iterator:"@@iterator",s="function"==typeof Object.create,a={__proto__:[]}instanceof Array,c=!s&&!a,u={create:s?function(){return he(Object.create(null))}:a?function(){return he({__proto__:null})}:function(){return he({})},has:c?function(e,t){return n.call(e,t)}:function(e,t){return t in e},get:c?function(e,t){return n.call(e,t)?e[t]:void 0}:function(e,t){return e[t]}},l=Object.getPrototypeOf(Function),h="function"==typeof Map&&"function"==typeof Map.prototype.entries?Map:ce(),d="function"==typeof Set&&"function"==typeof Set.prototype.entries?Set:ue(),f="function"==typeof WeakMap?WeakMap:le(),p=r?Symbol.for("@reflect-metadata:registry"):void 0,m=ie(),v=oe(m);function y(e,t,n,r){if(F(n)){if(!Q(e))throw new TypeError;if(!Y(t))throw new TypeError;return x(e,t)}if(!Q(e))throw new TypeError;if(!H(t))throw new TypeError;if(!H(r)&&!F(r)&&!B(r))throw new TypeError;return B(r)&&(r=void 0),I(e,t,n=q(n),r)}function g(e,t){function n(n,r){if(!H(n))throw new TypeError;if(!F(r)&&!J(r))throw new TypeError;D(e,t,n,r)}return n}function _(e,t,n,r){if(!H(n))throw new TypeError;return F(r)||(r=q(r)),D(e,t,n,r)}function S(e,t,n){if(!H(t))throw new TypeError;return F(n)||(n=q(n)),A(e,t,n)}function C(e,t,n){if(!H(t))throw new TypeError;return F(n)||(n=q(n)),k(e,t,n)}function E(e,t,n){if(!H(t))throw new TypeError;return F(n)||(n=q(n)),P(e,t,n)}function b(e,t,n){if(!H(t))throw new TypeError;return F(n)||(n=q(n)),O(e,t,n)}function T(e,t){if(!H(e))throw new TypeError;return F(t)||(t=q(t)),R(e,t)}function w(e,t){if(!H(e))throw new TypeError;return F(t)||(t=q(t)),z(e,t)}function M(e,t,n){if(!H(t))throw new TypeError;if(F(n)||(n=q(n)),!H(t))throw new TypeError;F(n)||(n=q(n));var r=ae(t,n,!1);return!F(r)&&r.OrdinaryDeleteMetadata(e,t,n)}function x(e,t){for(var n=e.length-1;n>=0;--n){var r=(0,e[n])(t);if(!F(r)&&!B(r)){if(!Y(r))throw new TypeError;t=r}}return t}function I(e,t,n,r){for(var i=e.length-1;i>=0;--i){var o=(0,e[i])(t,n,r);if(!F(o)&&!B(o)){if(!H(o))throw new TypeError;r=o}}return r}function A(e,t,n){if(k(e,t,n))return!0;var r=ne(t);return!B(r)&&A(e,r,n)}function k(e,t,n){var r=ae(t,n,!1);return!F(r)&&G(r.OrdinaryHasOwnMetadata(e,t,n))}function P(e,t,n){if(k(e,t,n))return O(e,t,n);var r=ne(t);return B(r)?void 0:P(e,r,n)}function O(e,t,n){var r=ae(t,n,!1);if(!F(r))return r.OrdinaryGetOwnMetadata(e,t,n)}function D(e,t,n,r){ae(n,r,!0).OrdinaryDefineOwnMetadata(e,t,n,r)}function R(e,t){var n=z(e,t),r=ne(e);if(null===r)return n;var i=R(r,t);if(i.length<=0)return n;if(n.length<=0)return i;for(var o=new d,s=[],a=0,c=n;a<c.length;a++){var u=c[a];o.has(u)||(o.add(u),s.push(u))}for(var l=0,h=i;l<h.length;l++){u=h[l];o.has(u)||(o.add(u),s.push(u))}return s}function z(e,t){var n=ae(e,t,!1);return n?n.OrdinaryOwnMetadataKeys(e,t):[]}function N(e){if(null===e)return 1;switch(typeof e){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return null===e?1:6;default:return 6}}function F(e){return void 0===e}function B(e){return null===e}function L(e){return"symbol"==typeof e}function H(e){return"object"==typeof e?null!==e:"function"==typeof e}function W(e,t){switch(N(e)){case 0:case 1:case 2:case 3:case 4:case 5:return e}var n="string",r=Z(e,i);if(void 0!==r){var o=r.call(e,n);if(H(o))throw new TypeError;return o}return j(e)}function j(e,t){var n,r,i=e.toString;if(V(i)&&!H(r=i.call(e)))return r;if(V(n=e.valueOf)&&!H(r=n.call(e)))return r;throw new TypeError}function G(e){return!!e}function U(e){return""+e}function q(e){var t=W(e);return L(t)?t:U(t)}function Q(e){return Array.isArray?Array.isArray(e):e instanceof Object?e instanceof Array:"[object Array]"===Object.prototype.toString.call(e)}function V(e){return"function"==typeof e}function Y(e){return"function"==typeof e}function J(e){switch(N(e)){case 3:case 4:return!0;default:return!1}}function K(e,t){return e===t||e!=e&&t!=t}function Z(e,t){var n=e[t];if(null!=n){if(!V(n))throw new TypeError;return n}}function X(e){var t=Z(e,o);if(!V(t))throw new TypeError;var n=t.call(e);if(!H(n))throw new TypeError;return n}function $(e){return e.value}function ee(e){var t=e.next();return!t.done&&t}function te(e){var t=e.return;t&&t.call(e)}function ne(e){var t=Object.getPrototypeOf(e);if("function"!=typeof e||e===l)return t;if(t!==l)return t;var n=e.prototype,r=n&&Object.getPrototypeOf(n);if(null==r||r===Object.prototype)return t;var i=r.constructor;return"function"!=typeof i||i===e?t:i}function re(){var e,n,r,i;F(p)||void 0===t.Reflect||p in t.Reflect||"function"!=typeof t.Reflect.defineMetadata||(e=se(t.Reflect));var o=new f,s={registerProvider:a,getProvider:u,setProvider:m};return s;function a(t){if(!Object.isExtensible(s))throw new Error("Cannot add provider to a frozen registry.");switch(!0){case e===t:break;case F(n):n=t;break;case n===t:break;case F(r):r=t;break;case r===t:break;default:void 0===i&&(i=new d),i.add(t)}}function c(t,o){if(!F(n)){if(n.isProviderFor(t,o))return n;if(!F(r)){if(r.isProviderFor(t,o))return n;if(!F(i))for(var s=X(i);;){var a=ee(s);if(!a)return;var c=$(a);if(c.isProviderFor(t,o))return te(s),c}}}if(!F(e)&&e.isProviderFor(t,o))return e}function u(e,t){var n,r=o.get(e);return F(r)||(n=r.get(t)),F(n)?(F(n=c(e,t))||(F(r)&&(r=new h,o.set(e,r)),r.set(t,n)),n):n}function l(e){if(F(e))throw new TypeError;return n===e||r===e||!F(i)&&i.has(e)}function m(e,t,n){if(!l(n))throw new Error("Metadata provider not registered.");var r=u(e,t);if(r!==n){if(!F(r))return!1;var i=o.get(e);F(i)&&(i=new h,o.set(e,i)),i.set(t,n)}return!0}}function ie(){var e;return!F(p)&&H(t.Reflect)&&Object.isExtensible(t.Reflect)&&(e=t.Reflect[p]),F(e)&&(e=re()),!F(p)&&H(t.Reflect)&&Object.isExtensible(t.Reflect)&&Object.defineProperty(t.Reflect,p,{enumerable:!1,configurable:!1,writable:!1,value:e}),e}function oe(e){var t=new f,n={isProviderFor:function(e,n){var r=t.get(e);return!F(r)&&r.has(n)},OrdinaryDefineOwnMetadata:s,OrdinaryHasOwnMetadata:i,OrdinaryGetOwnMetadata:o,OrdinaryOwnMetadataKeys:a,OrdinaryDeleteMetadata:c};return m.registerProvider(n),n;function r(r,i,o){var s=t.get(r),a=!1;if(F(s)){if(!o)return;s=new h,t.set(r,s),a=!0}var c=s.get(i);if(F(c)){if(!o)return;if(c=new h,s.set(i,c),!e.setProvider(r,i,n))throw s.delete(i),a&&t.delete(r),new Error("Wrong provider for target.")}return c}function i(e,t,n){var i=r(t,n,!1);return!F(i)&&G(i.has(e))}function o(e,t,n){var i=r(t,n,!1);if(!F(i))return i.get(e)}function s(e,t,n,i){r(n,i,!0).set(e,t)}function a(e,t){var n=[],i=r(e,t,!1);if(F(i))return n;for(var o=X(i.keys()),s=0;;){var a=ee(o);if(!a)return n.length=s,n;var c=$(a);try{n[s]=c}catch(e){try{te(o)}finally{throw e}}s++}}function c(e,n,i){var o=r(n,i,!1);if(F(o))return!1;if(!o.delete(e))return!1;if(0===o.size){var s=t.get(n);F(s)||(s.delete(i),0===s.size&&t.delete(s))}return!0}}function se(e){var t=e.defineMetadata,n=e.hasOwnMetadata,r=e.getOwnMetadata,i=e.getOwnMetadataKeys,o=e.deleteMetadata,s=new f;return{isProviderFor:function(e,t){var n=s.get(e);return!(F(n)||!n.has(t))||!!i(e,t).length&&(F(n)&&(n=new d,s.set(e,n)),n.add(t),!0)},OrdinaryDefineOwnMetadata:t,OrdinaryHasOwnMetadata:n,OrdinaryGetOwnMetadata:r,OrdinaryOwnMetadataKeys:i,OrdinaryDeleteMetadata:o}}function ae(e,t,n){var r=m.getProvider(e,t);if(!F(r))return r;if(n){if(m.setProvider(e,t,v))return v;throw new Error("Illegal state.")}}function ce(){var e={},t=[],n=function(){function e(e,t,n){this._index=0,this._keys=e,this._values=t,this._selector=n}return e.prototype["@@iterator"]=function(){return this},e.prototype[o]=function(){return this},e.prototype.next=function(){var e=this._index;if(e>=0&&e<this._keys.length){var n=this._selector(this._keys[e],this._values[e]);return e+1>=this._keys.length?(this._index=-1,this._keys=t,this._values=t):this._index++,{value:n,done:!1}}return{value:void 0,done:!0}},e.prototype.throw=function(e){throw this._index>=0&&(this._index=-1,this._keys=t,this._values=t),e},e.prototype.return=function(e){return this._index>=0&&(this._index=-1,this._keys=t,this._values=t),{value:e,done:!0}},e}();return function(){function t(){this._keys=[],this._values=[],this._cacheKey=e,this._cacheIndex=-2}return Object.defineProperty(t.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),t.prototype.has=function(e){return this._find(e,!1)>=0},t.prototype.get=function(e){var t=this._find(e,!1);return t>=0?this._values[t]:void 0},t.prototype.set=function(e,t){var n=this._find(e,!0);return this._values[n]=t,this},t.prototype.delete=function(t){var n=this._find(t,!1);if(n>=0){for(var r=this._keys.length,i=n+1;i<r;i++)this._keys[i-1]=this._keys[i],this._values[i-1]=this._values[i];return this._keys.length--,this._values.length--,K(t,this._cacheKey)&&(this._cacheKey=e,this._cacheIndex=-2),!0}return!1},t.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=e,this._cacheIndex=-2},t.prototype.keys=function(){return new n(this._keys,this._values,r)},t.prototype.values=function(){return new n(this._keys,this._values,i)},t.prototype.entries=function(){return new n(this._keys,this._values,s)},t.prototype["@@iterator"]=function(){return this.entries()},t.prototype[o]=function(){return this.entries()},t.prototype._find=function(e,t){if(!K(this._cacheKey,e)){this._cacheIndex=-1;for(var n=0;n<this._keys.length;n++)if(K(this._keys[n],e)){this._cacheIndex=n;break}}return this._cacheIndex<0&&t&&(this._cacheIndex=this._keys.length,this._keys.push(e),this._values.push(void 0)),this._cacheIndex},t}();function r(e,t){return e}function i(e,t){return t}function s(e,t){return[e,t]}}function ue(){return function(){function e(){this._map=new h}return Object.defineProperty(e.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),e.prototype.has=function(e){return this._map.has(e)},e.prototype.add=function(e){return this._map.set(e,e),this},e.prototype.delete=function(e){return this._map.delete(e)},e.prototype.clear=function(){this._map.clear()},e.prototype.keys=function(){return this._map.keys()},e.prototype.values=function(){return this._map.keys()},e.prototype.entries=function(){return this._map.entries()},e.prototype["@@iterator"]=function(){return this.keys()},e.prototype[o]=function(){return this.keys()},e}()}function le(){var e=16,t=u.create(),r=i();return function(){function e(){this._key=i()}return e.prototype.has=function(e){var t=o(e,!1);return void 0!==t&&u.has(t,this._key)},e.prototype.get=function(e){var t=o(e,!1);return void 0!==t?u.get(t,this._key):void 0},e.prototype.set=function(e,t){return o(e,!0)[this._key]=t,this},e.prototype.delete=function(e){var t=o(e,!1);return void 0!==t&&delete t[this._key]},e.prototype.clear=function(){this._key=i()},e}();function i(){var e;do{e="@@WeakMap@@"+c()}while(u.has(t,e));return t[e]=!0,e}function o(e,t){if(!n.call(e,r)){if(!t)return;Object.defineProperty(e,r,{value:u.create()})}return e[r]}function s(e,t){for(var n=0;n<t;++n)e[n]=255*Math.random()|0;return e}function a(e){if("function"==typeof Uint8Array){var t=new Uint8Array(e);return"undefined"!=typeof crypto?crypto.getRandomValues(t):"undefined"!=typeof msCrypto?msCrypto.getRandomValues(t):s(t,e),t}return s(new Array(e),e)}function c(){var t=a(e);t[6]=79&t[6]|64,t[8]=191&t[8]|128;for(var n="",r=0;r<e;++r){var i=t[r];4!==r&&6!==r&&8!==r||(n+="-"),i<16&&(n+="0"),n+=i.toString(16).toLowerCase()}return n}}function he(e){return e.__=void 0,delete e.__,e}e("decorate",y),e("metadata",g),e("defineMetadata",_),e("hasMetadata",S),e("hasOwnMetadata",C),e("getMetadata",E),e("getOwnMetadata",b),e("getMetadataKeys",T),e("getOwnMetadataKeys",w),e("deleteMetadata",M)}(n,t),void 0===t.Reflect&&(t.Reflect=e)}()}(e||(e={}))),me;var e}();var ve=Symbol.for("@esengine/property:metadata");var ye=Symbol("schedulingMetadata");function ge(e){var t=e;return t[ye]||(t[ye]={stage:"update",before:[],after:[],sets:[]}),t[ye]}function _e(e){for(var t=Object.getPrototypeOf(e);t;){var n=t[ye];if(n)return n;t=Object.getPrototypeOf(t)}}var Se=function(){function e(){}return e.getConstructor=function(e){return this.TYPE_CONSTRUCTORS[e]||Float32Array},e.getBytesPerElement=function(e){return this.TYPE_BYTES[e]||4},e.getTypeName=function(e){return e instanceof Float32Array?"float32":e instanceof Float64Array?"float64":e instanceof Int32Array?"int32":e instanceof Uint32Array?"uint32":e instanceof Int16Array?"int16":e instanceof Uint16Array?"uint16":e instanceof Int8Array?"int8":e instanceof Uint8Array?"uint8":e instanceof Uint8ClampedArray?"uint8clamped":"float32"},e.createSameType=function(e,t){var n=this.getTypeName(e);return new(this.getConstructor(n))(t)},e.extractFieldMetadata=function(e){var t=new e,n=new Map,r=e,i=new Map,o=function(e,t){if(e)for(var n,r=s(e);!(n=r()).done;){var o=n.value;i.set(o,t)}};o(r.__float64Fields,"float64"),o(r.__float32Fields,"float32"),o(r.__int32Fields,"int32"),o(r.__uint32Fields,"uint32"),o(r.__int16Fields,"int16"),o(r.__uint16Fields,"uint16"),o(r.__int8Fields,"int8"),o(r.__uint8Fields,"uint8"),o(r.__uint8ClampedFields,"uint8clamped");for(var a,c=Object.keys(t).filter(function(e){return"id"!==e}),u=s(c);!(a=u()).done;){var l,h,d,f,p=a.value,m=typeof t[p];if("function"!==m){var v={name:p,type:m},y=i.get(p);y?v.arrayType=y:"number"===m?v.arrayType="float32":"boolean"===m&&(v.arrayType="uint8"),null!==(l=r.__serializeMapFields)&&void 0!==l&&l.has(p)&&(v.isSerializedMap=!0),null!==(h=r.__serializeSetFields)&&void 0!==h&&h.has(p)&&(v.isSerializedSet=!0),null!==(d=r.__serializeArrayFields)&&void 0!==d&&d.has(p)&&(v.isSerializedArray=!0),null!==(f=r.__deepCopyFields)&&void 0!==f&&f.has(p)&&(v.isDeepCopy=!0),n.set(p,v)}}return n},e}();Se.TYPE_CONSTRUCTORS={float32:Float32Array,float64:Float64Array,int32:Int32Array,uint32:Uint32Array,int16:Int16Array,uint16:Uint16Array,int8:Int8Array,uint8:Uint8Array,uint8clamped:Uint8ClampedArray},Se.TYPE_BYTES={float32:4,float64:8,int32:4,uint32:4,int16:2,uint16:2,int8:1,uint8:1,uint8clamped:1};var Ce=function(){function e(){}return e.serialize=function(e,t,n){void 0===n&&(n={});try{return n.isMap&&e instanceof Map?JSON.stringify(Array.from(e.entries())):n.isSet&&e instanceof Set?JSON.stringify(Array.from(e)):(n.isArray&&Array.isArray(e),JSON.stringify(e))}catch(e){return this._logger.warn("SoA序列化字段 "+t+" 失败:",e),"{}"}},e.deserialize=function(e,t,n){void 0===n&&(n={});try{var r=JSON.parse(e);return n.isMap?new Map(r):n.isSet?new Set(r):r}catch(e){return this._logger.warn("SoA反序列化字段 "+t+" 失败:",e),null}},e.deepClone=function(e){var t=this;if(null===e||"object"!=typeof e)return e;if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(function(e){return t.deepClone(e)});if(e instanceof Map){for(var n,r=new Map,i=s(e.entries());!(n=i()).done;){var o=n.value,a=o[0],c=o[1];r.set(a,this.deepClone(c))}return r}if(e instanceof Set){for(var u,l=new Set,h=s(e.values());!(u=h()).done;){var d=u.value;l.add(this.deepClone(d))}return l}var f={};for(var p in e)Object.prototype.hasOwnProperty.call(e,p)&&(f[p]=this.deepClone(e[p]));return f},e}();function Ee(e,t){var n=String(t);e.constructor.__int32Fields||(e.constructor.__int32Fields=new Set),e.constructor.__int32Fields.add(n)}Ce._logger=J("SoASerializer");var be=function(){function e(e){this.fields=new Map,this.stringFields=new Map,this.serializedFields=new Map,this.complexFields=new Map,this.entityToIndex=new Map,this.indexToEntity=[],this.freeIndices=[],this._size=0,this._capacity=1e3,this.fieldTypes=new Map,this.serializeMapFields=new Set,this.serializeSetFields=new Set,this.serializeArrayFields=new Set,this.type=e,this.initializeFields(e)}var t=e.prototype;return t.initializeFields=function(e){var t=new e,n=e,r=n.__float64Fields||new Set,i=n.__float32Fields||new Set,o=n.__int32Fields||new Set,a=n.__uint32Fields||new Set,c=n.__int16Fields||new Set,u=n.__uint16Fields||new Set,l=n.__int8Fields||new Set,h=n.__uint8Fields||new Set,d=n.__uint8ClampedFields||new Set;this.serializeMapFields=n.__serializeMapFields||new Set,this.serializeSetFields=n.__serializeSetFields||new Set,this.serializeArrayFields=n.__serializeArrayFields||new Set;for(var f,p=new Map,m=s(r);!(f=m()).done;){var v=f.value;p.set(v,"float64")}for(var y,g=s(i);!(y=g()).done;){var _=y.value;p.set(_,"float32")}for(var S,C=s(o);!(S=C()).done;){var E=S.value;p.set(E,"int32")}for(var b,T=s(a);!(b=T()).done;){var w=b.value;p.set(w,"uint32")}for(var M,x=s(c);!(M=x()).done;){var I=M.value;p.set(I,"int16")}for(var A,k=s(u);!(A=k()).done;){var P=A.value;p.set(P,"uint16")}for(var O,D=s(l);!(O=D()).done;){var R=O.value;p.set(R,"int8")}for(var z,N=s(h);!(z=N()).done;){var F=z.value;p.set(F,"uint8")}for(var B,L=s(d);!(B=L()).done;){var H=B.value;p.set(H,"uint8clamped")}for(var W,j=Object.keys(t).filter(function(e){return"id"!==e}),G=s(j);!(W=G()).done;){var U=W.value,q=t[U],Q=typeof q;if("function"!==Q){var V=p.get(U),Y=V?"number":Q;if(this.fieldTypes.set(U,Y),V){var J=Se.getConstructor(V);this.fields.set(U,new J(this._capacity))}else"number"===Q?this.fields.set(U,new Float32Array(this._capacity)):"boolean"===Q?this.fields.set(U,new Uint8Array(this._capacity)):"string"===Q?this.stringFields.set(U,new Array(this._capacity)):"object"===Q&&null!==q&&(this.serializeMapFields.has(U)||this.serializeSetFields.has(U)||this.serializeArrayFields.has(U))&&this.serializedFields.set(U,new Array(this._capacity))}}},t.addComponent=function(e,t){if(this.entityToIndex.has(e)){var n=this.entityToIndex.get(e);this.updateComponentAtIndex(n,t)}else{var r;this.freeIndices.length>0?r=this.freeIndices.pop():(r=this._size)>=this._capacity&&this.resize(2*this._capacity),this.entityToIndex.set(e,r),this.indexToEntity[r]=e,this.updateComponentAtIndex(r,t),this._size++}},t.updateComponentAtIndex=function(e,t){var n=this.indexToEntity[e],r=new Map,i=this.type.__highPrecisionFields||new Set,o=this.type.__serializeMapFields||new Set,s=this.type.__serializeSetFields||new Set,a=this.type.__serializeArrayFields||new Set,c=this.type.__deepCopyFields||new Set;for(var u in t)if(t.hasOwnProperty(u)&&"id"!==u){var l=t[u],h=typeof l;if("number"===h)if(i.has(u)||!this.fields.has(u))r.set(u,l);else this.fields.get(u)[e]=l;else if("boolean"===h&&this.fields.has(u)){this.fields.get(u)[e]=l?1:0}else if(this.stringFields.has(u)){this.stringFields.get(u)[e]=String(l)}else if(this.serializedFields.has(u)){this.serializedFields.get(u)[e]=Ce.serialize(l,u,{isMap:o.has(u),isSet:s.has(u),isArray:a.has(u)})}else c.has(u)?r.set(u,Ce.deepClone(l)):r.set(u,l)}r.size>0&&this.complexFields.set(n,r)},t.getComponent=function(e){var t=this.entityToIndex.get(e);return void 0===t?null:this.createProxyView(e,t)},t.createProxyView=function(e,t){var n=this;return new Proxy({},{get:function(r,i){var o=String(i),s=n.fields.get(o);if(s)return"boolean"===n.getFieldType(o)?1===s[t]:s[t];var a=n.stringFields.get(o);if(a)return a[t];var c=n.serializedFields.get(o);if(c){var u=c[t];return u?Ce.deserialize(u,o,{isMap:n.serializeMapFields.has(o),isSet:n.serializeSetFields.has(o),isArray:n.serializeArrayFields.has(o)}):void 0}var l=n.complexFields.get(e);return null!=l&&l.has(o)?l.get(o):void 0},set:function(r,i,o){var s=String(i);if("entityId"===s)return!1;var a=n.fields.get(s);if(a){var c=n.getFieldType(s);return a[t]="boolean"===c?o?1:0:o,!0}var u=n.stringFields.get(s);if(u)return u[t]=String(o),!0;if(n.serializedFields.has(s))return n.serializedFields.get(s)[t]=Ce.serialize(o,s,{isMap:n.serializeMapFields.has(s),isSet:n.serializeSetFields.has(s),isArray:n.serializeArrayFields.has(s)}),!0;var l=n.complexFields.get(e);return l||(l=new Map,n.complexFields.set(e,l)),l.set(s,o),!0},has:function(t,r){var i,o=String(r);return n.fields.has(o)||n.stringFields.has(o)||n.serializedFields.has(o)||(null===(i=n.complexFields.get(e))||void 0===i?void 0:i.has(o))||!1},ownKeys:function(){for(var t,r=[],i=s(n.fields.keys());!(t=i()).done;){var o=t.value;r.push(o)}for(var a,c=s(n.stringFields.keys());!(a=c()).done;){var u=a.value;r.push(u)}for(var l,h=s(n.serializedFields.keys());!(l=h()).done;){var d=l.value;r.push(d)}var f=n.complexFields.get(e);if(f)for(var p,m=s(f.keys());!(p=m()).done;){var v=p.value;r.push(v)}return r},getOwnPropertyDescriptor:function(t,r){var i,o=String(r);if(n.fields.has(o)||n.stringFields.has(o)||n.serializedFields.has(o)||null!==(i=n.complexFields.get(e))&&void 0!==i&&i.has(o))return{enumerable:!0,configurable:!0,writable:"entityId"!==o}}})},t.getComponentSnapshot=function(e){var t=this.entityToIndex.get(e);if(void 0===t)return null;for(var n,r=new this.type,i=s(this.fields.entries());!(n=i()).done;){var o=n.value,a=o[0],c=o[1][t],u=this.getFieldType(a);r[a]="boolean"===u?1===c:c}for(var l,h=s(this.stringFields.entries());!(l=h()).done;){var d=l.value,f=d[0],p=d[1];r[f]=p[t]}for(var m,v=s(this.serializedFields.entries());!(m=v()).done;){var y=m.value,g=y[0],_=y[1][t];_&&(r[g]=Ce.deserialize(_,g,{isMap:this.serializeMapFields.has(g),isSet:this.serializeSetFields.has(g),isArray:this.serializeArrayFields.has(g)}))}var S=this.complexFields.get(e);if(S)for(var C,E=s(S.entries());!(C=E()).done;){var b=C.value,T=b[0],w=b[1];r[T]=w}return r},t.getFieldType=function(e){return this.fieldTypes.get(e)||"unknown"},t.hasComponent=function(e){return this.entityToIndex.has(e)},t.removeComponent=function(e){var t=this.entityToIndex.get(e);if(void 0===t)return null;var n=this.getComponent(e);return this.complexFields.delete(e),this.entityToIndex.delete(e),this.freeIndices.push(t),this._size--,n},t.resize=function(e){for(var t,n=s(this.fields.entries());!(t=n()).done;){var r=t.value,i=r[0],o=r[1],a=Se.createSameType(o,e);a.set(o),this.fields.set(i,a)}for(var c,u=s(this.stringFields.entries());!(c=u()).done;){for(var l=c.value,h=l[0],d=l[1],f=new Array(e),p=0;p<d.length;p++)f[p]=d[p];this.stringFields.set(h,f)}for(var m,v=s(this.serializedFields.entries());!(m=v()).done;){for(var y=m.value,g=y[0],_=y[1],S=new Array(e),C=0;C<_.length;C++)S[C]=_[C];this.serializedFields.set(g,S)}this._capacity=e},t.getActiveIndices=function(){return Array.from(this.entityToIndex.values())},t.getFieldArray=function(e){return this.fields.get(e)||null},t.getTypedFieldArray=function(e){return this.fields.get(String(e))||null},t.getEntityIndex=function(e){return this.entityToIndex.get(e)},t.getEntityIdByIndex=function(e){return this.indexToEntity[e]},t.size=function(){return this._size},t.clear=function(){this.entityToIndex.clear(),this.indexToEntity=[],this.freeIndices=[],this.complexFields.clear(),this._size=0;for(var e,t=s(this.fields.values());!(e=t()).done;){e.value.fill(0)}for(var n,r=s(this.stringFields.values());!(n=r()).done;)for(var i=n.value,o=0;o<i.length;o++)i[o]=void 0;for(var a,c=s(this.serializedFields.values());!(a=c()).done;)for(var u=a.value,l=0;l<u.length;l++)u[l]=void 0},t.compact=function(){if(0!==this.freeIndices.length){for(var e=Array.from(this.entityToIndex.entries()).sort(function(e,t){return e[1]-t[1]}),t=new Map,n=[],r=0;r<e.length;r++){var i=e[r];if(i){var o=i[0],a=i[1];if(t.set(o,r),n[r]=o,r!==a){for(var c,u=s(this.fields.entries());!(c=u()).done;){var l=c.value[1],h=l[a];void 0!==h&&(l[r]=h)}for(var d,f=s(this.stringFields.entries());!(d=f()).done;){var p=d.value[1],m=p[a];void 0!==m&&(p[r]=m)}for(var v,y=s(this.serializedFields.entries());!(v=y()).done;){var g=v.value[1],_=g[a];void 0!==_&&(g[r]=_)}}}}this.entityToIndex=t,this.indexToEntity=n,this.freeIndices=[],this._size=e.length}},t.getStats=function(){for(var e,t=0,n=new Map,r=s(this.fields.entries());!(e=r()).done;){var i=e.value,o=i[0],a=i[1],c=Se.getTypeName(a),u=Se.getBytesPerElement(c),l=a.length*u;t+=l,n.set(o,{size:this._size,capacity:a.length,type:c,memory:l})}return{size:this._size,capacity:this._capacity,usedSlots:this._size,fragmentation:this.freeIndices.length/this._capacity,memoryUsage:t,fieldStats:n}},t.performVectorizedOperation=function(e){var t=this.getActiveIndices();e(this.fields,t)},e}(),Te=function(){function e(){this.entityId=null,this._lastWriteEpoch=0,this.id=e.idGenerator++}var t=e.prototype;return t.markDirty=function(e){this._lastWriteEpoch=e},t.onAddedToEntity=function(){},t.onRemovedFromEntity=function(){},t.onDeserialized=function(){},o(e,[{key:"lastWriteEpoch",get:function(){return this._lastWriteEpoch}}])}();Te.idGenerator=0,v([Ee,y("design:type",Object)],Te.prototype,"entityId",void 0);var we=Symbol("SerializableMetadata"),Me=Symbol("SerializeField"),xe=Symbol("SerializeOptions");function Ie(e){return function(t){if(!e||"number"!=typeof e.version)throw new Error("Serializable装饰器必须提供有效的版本号");var n;if(Object.prototype.hasOwnProperty.call(t,we))(n=t[we]).options=e;else{var r=t[we];n={options:e,fields:r?new Map(r.fields):new Map,ignoredFields:r?new Set(r.ignoredFields):new Set},t[we]=n}return t}}function Ae(e){return function(t,n){var r,i=t.constructor;if(Object.prototype.hasOwnProperty.call(i,we))r=i[we];else{var o=i[we];r={options:o?a({},o.options):{version:1},fields:o?new Map(o.fields):new Map,ignoredFields:o?new Set(o.ignoredFields):new Set},i[we]=r}r.fields.set(n,e||{})}}function ke(e){return e&&("function"==typeof e?e:e.constructor)[we]||null}exports.HierarchyComponent=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).parentId=null,t.childIds=[],t.depth=0,t.bActiveInHierarchy=!0,t.bCacheDirty=!0,t}return u(t,e),t}(Te),v([Ae(),y("design:type",Object)],exports.HierarchyComponent.prototype,"parentId",void 0),v([Ae(),y("design:type",Array)],exports.HierarchyComponent.prototype,"childIds",void 0),exports.HierarchyComponent=v([X("Hierarchy",{editor:{hideInInspector:!0}}),Ie({version:1,typeId:"Hierarchy"})],exports.HierarchyComponent);var Pe=function(){function e(){this.condition={all:[],any:[],none:[]}}e.all=function(){var t=new e;return t.all.apply(t,arguments)},e.any=function(){var t=new e;return t.any.apply(t,arguments)},e.none=function(){var t=new e;return t.none.apply(t,arguments)},e.byTag=function(t){return(new e).withTag(t)},e.byName=function(t){return(new e).withName(t)},e.byComponent=function(t){return(new e).withComponent(t)},e.complex=function(){return new e},e.empty=function(){return new e},e.nothing=function(){var t=new e;return t.condition.matchNothing=!0,t};var t=e.prototype;return t.all=function(){var e;return(e=this.condition.all).push.apply(e,arguments),this},t.any=function(){var e;return(e=this.condition.any).push.apply(e,arguments),this},t.none=function(){var e;return(e=this.condition.none).push.apply(e,arguments),this},t.exclude=function(){return this.none.apply(this,arguments)},t.one=function(){return this.any.apply(this,arguments)},t.withTag=function(e){return this.condition.tag=e,this},t.withName=function(e){return this.condition.name=e,this},t.withComponent=function(e){return this.condition.component=e,this},t.withoutTag=function(){return delete this.condition.tag,this},t.withoutName=function(){return delete this.condition.name,this},t.withoutComponent=function(){return delete this.condition.component,this},t.getCondition=function(){return a({all:[].concat(this.condition.all),any:[].concat(this.condition.any),none:[].concat(this.condition.none)},void 0!==this.condition.tag&&{tag:this.condition.tag},void 0!==this.condition.name&&{name:this.condition.name},void 0!==this.condition.component&&{component:this.condition.component},this.condition.matchNothing&&{matchNothing:!0})},t.isEmpty=function(){return 0===this.condition.all.length&&0===this.condition.any.length&&0===this.condition.none.length&&void 0===this.condition.tag&&void 0===this.condition.name&&void 0===this.condition.component&&!this.condition.matchNothing},t.isNothing=function(){return!0===this.condition.matchNothing},t.reset=function(){return this.condition.all.length=0,this.condition.any.length=0,this.condition.none.length=0,delete this.condition.tag,delete this.condition.name,delete this.condition.component,delete this.condition.matchNothing,this},t.clone=function(){var t,n,r,i=new e;return(t=i.condition.all).push.apply(t,this.condition.all),(n=i.condition.any).push.apply(n,this.condition.any),(r=i.condition.none).push.apply(r,this.condition.none),void 0!==this.condition.tag&&(i.condition.tag=this.condition.tag),void 0!==this.condition.name&&(i.condition.name=this.condition.name),void 0!==this.condition.component&&(i.condition.component=this.condition.component),this.condition.matchNothing&&(i.condition.matchNothing=!0),i},t.toString=function(){if(this.condition.matchNothing)return"Matcher[nothing]";var e=[];return this.condition.all.length>0&&e.push("all("+this.condition.all.map(function(e){return L(e)}).join(", ")+")"),this.condition.any.length>0&&e.push("any("+this.condition.any.map(function(e){return L(e)}).join(", ")+")"),this.condition.none.length>0&&e.push("none("+this.condition.none.map(function(e){return L(e)}).join(", ")+")"),void 0!==this.condition.tag&&e.push("tag("+this.condition.tag+")"),void 0!==this.condition.name&&e.push("name("+this.condition.name+")"),void 0!==this.condition.component&&e.push("component("+L(this.condition.component)+")"),"Matcher["+e.join(" & ")+"]"},e}(),Oe=function(){function e(){this._frameCache=null,this._persistentCache=null,this._trackedEntities=new Set}var t=e.prototype;return t.getFrame=function(){return this._frameCache},t.setFrame=function(e){this._frameCache=e},t.getPersistent=function(){return this._persistentCache},t.setPersistent=function(e){this._persistentCache=e},t.getTracked=function(){return this._trackedEntities},t.addTracked=function(e){this._trackedEntities.add(e)},t.removeTracked=function(e){this._trackedEntities.delete(e)},t.isTracked=function(e){return this._trackedEntities.has(e)},t.invalidate=function(){this._persistentCache=null},t.clearFrame=function(){this._frameCache=null},t.clearAll=function(){this._frameCache=null,this._persistentCache=null,this._trackedEntities.clear()},t.hasPersistent=function(){return null!==this._persistentCache},t.hasFrame=function(){return null!==this._frameCache},t.getStats=function(){var e,t,n,r;return{hasFrame:null!==this._frameCache,hasPersistent:null!==this._persistentCache,trackedCount:this._trackedEntities.size,frameEntityCount:null!==(e=null===(t=this._frameCache)||void 0===t?void 0:t.length)&&void 0!==e?e:0,persistentEntityCount:null!==(n=null===(r=this._persistentCache)||void 0===r?void 0:r.length)&&void 0!==n?n:0}},e}(),De=function(){function e(e){this.dense=[],this.entityIds=[],this.entityToIndex=new Map,this.componentType=e}var t=e.prototype;return t.addComponent=function(e,t){if(this.entityToIndex.has(e))throw new Error("Entity "+e+" already has component "+L(this.componentType));var n=this.dense.length;this.dense.push(t),this.entityIds.push(e),this.entityToIndex.set(e,n)},t.getComponent=function(e){var t=this.entityToIndex.get(e);return void 0!==t?this.dense[t]:null},t.hasComponent=function(e){return this.entityToIndex.has(e)},t.removeComponent=function(e){var t=this.entityToIndex.get(e);if(void 0===t)return null;var n=this.dense[t],r=this.dense.length-1;if(t!==r){var i=this.dense[r],o=this.entityIds[r];this.dense[t]=i,this.entityIds[t]=o,this.entityToIndex.set(o,t)}return this.dense.pop(),this.entityIds.pop(),this.entityToIndex.delete(e),n},t.forEach=function(e){for(var t=0;t<this.dense.length;t++)e(this.dense[t],this.entityIds[t],t)},t.getDenseArray=function(){return{components:[].concat(this.dense),entityIds:[].concat(this.entityIds)}},t.clear=function(){this.dense.length=0,this.entityIds.length=0,this.entityToIndex.clear()},t.getStats=function(){return{totalSlots:this.dense.length,usedSlots:this.dense.length,freeSlots:0,fragmentation:0}},o(e,[{key:"size",get:function(){return this.dense.length}},{key:"type",get:function(){return this.componentType}}])}(),Re=function(){function e(){this.storages=new Map}var t=e.prototype;return t.isSoAStorage=function(e){return this.storages.get(e)instanceof be},t.getSoAStorage=function(e){var t=this.getStorage(e);return t instanceof be?t:null},t.getFieldArray=function(e,t){var n=this.getSoAStorage(e);return n?n.getFieldArray(t):null},t.getTypedFieldArray=function(e,t){var n=this.getSoAStorage(e);return n?n.getTypedFieldArray(t):null},t.getActiveIndices=function(e){var t=this.getSoAStorage(e);return t?t.getActiveIndices():[]},t.getEntityIndex=function(e,t){var n=this.getSoAStorage(e);return n?n.getEntityIndex(t):void 0},t.getEntityIdByIndex=function(e,t){var n=this.getSoAStorage(e);return n?n.getEntityIdByIndex(t):void 0},t.getStorage=function(t){var n=this.storages.get(t);n||(t.__enableSoA?(n=new be(t),e._logger.info("为 "+L(t)+" 启用SoA优化(适用于大规模批量操作)")):n=new De(t),this.storages.set(t,n));return n},t.addComponent=function(e,t){var n=t.constructor;this.getStorage(n).addComponent(e,t)},t.getComponent=function(e,t){var n=this.storages.get(t);return n?n.getComponent(e):null},t.hasComponent=function(e,t){var n=this.storages.get(t);return!!n&&n.hasComponent(e)},t.removeComponent=function(e,t){var n=this.storages.get(t);return n?n.removeComponent(e):null},t.removeAllComponents=function(e){for(var t,n=s(this.storages.values());!(t=n()).done;){t.value.removeComponent(e)}},t.getComponentMask=function(e){for(var t,n=U.clone(U.ZERO),r=s(this.storages.entries());!(t=r()).done;){var i=t.value,o=i[0];if(i[1].hasComponent(e)){var a=K.getBitMask(o);U.orInPlace(n,a)}}return n},t.getAllStats=function(){for(var e,t=new Map,n=s(this.storages.entries());!(e=n()).done;){var r=e.value,i=r[0],o=r[1],a=L(i);t.set(a,o.getStats())}return t},t.clear=function(){for(var e,t=s(this.storages.values());!(e=t()).done;){e.value.clear()}this.storages.clear()},e}();Re._logger=J("ComponentStorage");var ze,Ne=J("CommandBuffer");exports.CommandType=void 0,(ze=exports.CommandType||(exports.CommandType={})).ADD_COMPONENT="add_component",ze.REMOVE_COMPONENT="remove_component",ze.DESTROY_ENTITY="destroy_entity",ze.SET_ENTITY_ACTIVE="set_entity_active";var Fe=function(){function e(e,t){void 0===t&&(t=!1),this._pending=new Map,this._commands=[],this._scene=null,this._debug=!1,this._useDeduplication=!0,this._scene=null!=e?e:null,this._debug=t}var t=e.prototype;return t.setScene=function(e){this._scene=e},t.setDeduplication=function(e){this._useDeduplication=e},t.getPending=function(e){var t=this._pending.get(e);return t||(t={},this._pending.set(e,t)),t},t.getTypeId=function(e){return"function"==typeof e?K.getBitIndex(e):K.getBitIndex(e.constructor)},t.addComponent=function(e,t){if(this._useDeduplication){var n,r=this.getPending(e);if(r.bDestroy)return void(this._debug&&Ne.debug("CommandBuffer: 忽略添加组件,实体 "+e.name+" 已标记销毁"));var i=this.getTypeId(t);null===(n=r.removes)||void 0===n||n.delete(i),r.adds||(r.adds=new Map),r.adds.set(i,t),this._debug&&Ne.debug("CommandBuffer: 延迟添加组件 "+t.constructor.name+" 到实体 "+e.name)}else this._commands.push({type:exports.CommandType.ADD_COMPONENT,entity:e,component:t})},t.removeComponent=function(e,t){if(this._useDeduplication){var n,r=this.getPending(e);if(r.bDestroy)return void(this._debug&&Ne.debug("CommandBuffer: 忽略移除组件,实体 "+e.name+" 已标记销毁"));var i=this.getTypeId(t);null===(n=r.adds)||void 0===n||n.delete(i),r.removes||(r.removes=new Set),r.removes.add(i),this._debug&&Ne.debug("CommandBuffer: 延迟移除组件 "+t.name+" 从实体 "+e.name)}else this._commands.push({type:exports.CommandType.REMOVE_COMPONENT,entity:e,componentType:t})},t.destroyEntity=function(e){if(this._useDeduplication){var t,n,r=this.getPending(e);null===(t=r.adds)||void 0===t||t.clear(),null===(n=r.removes)||void 0===n||n.clear(),delete r.active,r.bDestroy=!0,this._debug&&Ne.debug("CommandBuffer: 延迟销毁实体 "+e.name)}else this._commands.push({type:exports.CommandType.DESTROY_ENTITY,entity:e})},t.setEntityActive=function(e,t){if(this._useDeduplication){var n=this.getPending(e);if(n.bDestroy)return void(this._debug&&Ne.debug("CommandBuffer: 忽略设置激活状态,实体 "+e.name+" 已标记销毁"));n.active=t,this._debug&&Ne.debug("CommandBuffer: 延迟设置实体 "+e.name+" 激活状态为 "+t)}else this._commands.push({type:exports.CommandType.SET_ENTITY_ACTIVE,entity:e,value:t})},t.flush=function(){return this._useDeduplication?this.flushDeduplication():this.flushLegacy()},t.flushDeduplication=function(){if(0===this._pending.size)return 0;var e=this._pending.size,t=0;this._debug&&Ne.debug("CommandBuffer: 开始执行 "+e+" 个实体的延迟命令");var n=this._pending;this._pending=new Map;for(var r,i=s(n);!(r=i()).done;){var o=r.value,a=o[0],c=o[1];if(!c.bDestroy&&a.scene&&(c.removes&&c.removes.size>0))for(var u,l=s(c.removes);!(u=l()).done;){var h=u.value;try{var d=K.getTypeByBitIndex(h);d&&(a.removeComponentByType(d),t++)}catch(e){Ne.error("CommandBuffer: 移除组件失败",{entity:a.name,typeId:h,error:e})}}}for(var f,p=s(n);!(f=p()).done;){var m=f.value,v=m[0],y=m[1];if(!y.bDestroy&&v.scene&&(y.adds&&y.adds.size>0))for(var g,_=s(y.adds.values());!(g=_()).done;){var S=g.value;try{v.addComponent(S),t++}catch(e){Ne.error("CommandBuffer: 添加组件失败",{entity:v.name,component:S.constructor.name,error:e})}}}for(var C,E=s(n);!(C=E()).done;){var b=C.value,T=b[0],w=b[1];if(!w.bDestroy&&T.scene&&void 0!==w.active)try{T.active=w.active,t++}catch(e){Ne.error("CommandBuffer: 设置激活状态失败",{entity:T.name,error:e})}}for(var M,x=s(n);!(M=x()).done;){var I=M.value,A=I[0];if(I[1].bDestroy&&A.scene)try{A.destroy(),t++}catch(e){Ne.error("CommandBuffer: 销毁实体失败",{entity:A.name,error:e})}}return this._debug&&Ne.debug("CommandBuffer: 完成执行 "+t+" 个延迟命令"),t},t.flushLegacy=function(){if(0===this._commands.length)return 0;var e=this._commands.length;this._debug&&Ne.debug("CommandBuffer: 开始执行 "+e+" 个延迟命令");var t=this._commands;this._commands=[];for(var n,r=s(t);!(n=r()).done;){var i=n.value;this.executeCommand(i)}return this._debug&&Ne.debug("CommandBuffer: 完成执行 "+e+" 个延迟命令"),e},t.executeCommand=function(e){if(e.entity.scene)try{switch(e.type){case exports.CommandType.ADD_COMPONENT:e.component&&e.entity.addComponent(e.component);break;case exports.CommandType.REMOVE_COMPONENT:e.componentType&&e.entity.removeComponentByType(e.componentType);break;case exports.CommandType.DESTROY_ENTITY:e.entity.destroy();break;case exports.CommandType.SET_ENTITY_ACTIVE:void 0!==e.value&&(e.entity.active=e.value)}}catch(t){Ne.error("CommandBuffer: 执行命令失败",{command:e,error:t})}else this._debug&&Ne.debug("CommandBuffer: 跳过命令,实体 "+e.entity.name+" 已无效")},t.clear=function(){if(this._debug){var e=this._useDeduplication?this._pending.size:this._commands.length;e>0&&Ne.debug("CommandBuffer: 清空 "+e+" 个未执行的命令")}this._pending.clear(),this._commands.length=0},t.dispose=function(){this.clear(),this._scene=null},o(e,[{key:"scene",get:function(){return this._scene}},{key:"pendingCount",get:function(){if(this._useDeduplication){for(var e,t=0,n=s(this._pending.values());!(e=n()).done;){var r=e.value;r.bDestroy&&t++,void 0!==r.active&&t++,r.adds&&(t+=r.adds.size),r.removes&&(t+=r.removes.size)}return t}return this._commands.length}},{key:"hasPending",get:function(){return this._useDeduplication?this._pending.size>0:this._commands.length>0}}])}(),Be=function(){function e(e){this.commands=new Fe,this._lastProcessEpoch=0,this._updateOrder=0,this._addOrder=0,this._enabled=!0,this._performanceMonitor=null,this._systemName=te(this),this._initialized=!1,this._matcher=e||Pe.empty(),this._eventListeners=[],this._scene=null,this._destroyed=!1,this._entityIdMap=null,this._entityIdMapVersion=-1,this.logger=J(this.getLoggerName()),this._entityCache=new Oe;var t=_e(this);this._schedulingMetadata=t?a({},t):{stage:"update",before:[],after:[],sets:[]}}var t=e.prototype;return t.setPerformanceMonitor=function(e){this._performanceMonitor=e},t.getPerformanceMonitor=function(){if(!this._performanceMonitor)throw new Error(this._systemName+": PerformanceMonitor未注入,请确保在Core.create()之后再添加System到Scene");return this._performanceMonitor},t.setUpdateOrder=function(e){var t;this._updateOrder!==e&&(this._updateOrder=e,null===(t=this._scene)||void 0===t||t.markSystemsOrderDirty())},t.stage=function(e){var t;return this._schedulingMetadata.stage=e,null===(t=this._scene)||void 0===t||t.markSystemsOrderDirty(),this},t.before=function(){var e,t;return(e=this._schedulingMetadata.before).push.apply(e,arguments),null===(t=this._scene)||void 0===t||t.markSystemsOrderDirty(),this},t.after=function(){var e,t;return(e=this._schedulingMetadata.after).push.apply(e,arguments),null===(t=this._scene)||void 0===t||t.markSystemsOrderDirty(),this},t.inSet=function(){var e,t;return(e=this._schedulingMetadata.sets).push.apply(e,arguments),null===(t=this._scene)||void 0===t||t.markSystemsOrderDirty(),this},t.getStage=function(){return this._schedulingMetadata.stage},t.getBefore=function(){return this._schedulingMetadata.before},t.getAfter=function(){return this._schedulingMetadata.after},t.getSets=function(){return this._schedulingMetadata.sets},t.initialize=function(){if(!this._initialized){if(this._initialized=!0,this.scene){this._entityCache.invalidate();for(var e,t=s(this.queryEntities());!(e=t()).done;){var n=e.value;this.onAdded(n)}}this.onInitialize()}},t.onInitialize=function(){},t.clearEntityCache=function(){this._entityCache.invalidate()},t.resetEntityTracking=function(){this._entityCache.clearAll(),this._entityIdMap=null,this._entityIdMapVersion=-1},t.reset=function(){this._destroyed||(this.scene=null,this._initialized=!1,this._entityCache.clearAll(),this._entityIdMap=null,this._entityIdMapVersion=-1,this.destroy())},t.queryEntities=function(){var e;if(null===(e=this.scene)||void 0===e||!e.querySystem||!this._matcher)return[];var t=this._matcher.getCondition(),n=this.scene.querySystem,r=[];return this._matcher.isNothing()?[]:(r=this._matcher.isEmpty()?n.getAllEntities():this.isSingleCondition(t)?this.executeSingleConditionQuery(t,n):this.executeComplexQuery(t,n),this.updateEntityTracking(r),r)},t.isSingleCondition=function(e){var t=(e.all.length>0?1:0)|(e.any.length>0?2:0)|(e.none.length>0?4:0)|(void 0!==e.tag?8:0)|(void 0!==e.name?16:0)|(void 0!==e.component?32:0);return 0!==t&&!(t&t-1)},t.executeSingleConditionQuery=function(e,t){return void 0!==e.tag?t.queryByTag(e.tag).entities:void 0!==e.name?t.queryByName(e.name).entities:void 0!==e.component?t.queryByComponent(e.component).entities:e.all.length>0&&0===e.any.length&&0===e.none.length?t.queryAll.apply(t,e.all).entities:0===e.all.length&&e.any.length>0&&0===e.none.length?t.queryAny.apply(t,e.any).entities:0===e.all.length&&0===e.any.length&&e.none.length>0?t.queryNone.apply(t,e.none).entities:[]},t.executeComplexQueryWithIdSets=function(e,t){var n=null;if(void 0!==e.tag){var r=t.queryByTag(e.tag);n=this.extractEntityIds(r.entities)}if(void 0!==e.name){var i=this.extractEntityIds(t.queryByName(e.name).entities);n=n?this.intersectIdSets(n,i):i}if(void 0!==e.component){var o=this.extractEntityIds(t.queryByComponent(e.component).entities);n=n?this.intersectIdSets(n,o):o}if(e.all.length>0){var s=this.extractEntityIds(t.queryAll.apply(t,e.all).entities);n=n?this.intersectIdSets(n,s):s}if(e.any.length>0){var a=this.extractEntityIds(t.queryAny.apply(t,e.any).entities);n=n?this.intersectIdSets(n,a):a}if(e.none.length>0){n||(n=this.extractEntityIds(t.getAllEntities()));var c=t.queryAny.apply(t,e.none),u=this.extractEntityIds(c.entities);n=this.differenceIdSets(n,u)}return n?this.idSetToEntityArray(n,t.getAllEntities()):[]},t.extractEntityIds=function(e){for(var t=e.length,n=new Set,r=0;r<t;r=r+1|0)n.add(0|e[r].id);return n},t.intersectIdSets=function(e,t){var n,r;e.size<=t.size?(n=e,r=t):(n=t,r=e);for(var i,o=new Set,a=s(n);!(i=a()).done;){var c=i.value;r.has(c)&&o.add(c)}return o},t.differenceIdSets=function(e,t){for(var n,r=new Set,i=s(e);!(n=i()).done;){var o=n.value;t.has(o)||r.add(o)}return r},t.getEntityIdMap=function(e){var t,n,r=null!==(t=null===(n=this.scene)||void 0===n||null===(n=n.querySystem)||void 0===n?void 0:n.version)&&void 0!==t?t:0;return null!==this._entityIdMap&&this._entityIdMapVersion===r?this._entityIdMap:this.rebuildEntityIdMap(e,r)},t.rebuildEntityIdMap=function(e,t){var n=this._entityIdMap;n?n.clear():n=new Map;for(var r=e.length,i=0;i<r;i=i+1|0){var o=e[i];n.set(0|o.id,o)}return this._entityIdMap=n,this._entityIdMapVersion=t,n},t.idSetToEntityArray=function(e,t){for(var n,r=this.getEntityIdMap(t),i=e.size,o=new Array(i),a=0,c=s(e);!(n=c()).done;){var u=n.value,l=r.get(u);void 0!==l&&(o[a]=l,a=a+1|0)}return a<i&&(o.length=a),o},t.executeComplexQuery=function(e,t){return this.executeComplexQueryWithIdSets(e,t)},t.update=function(){if(this._enabled&&this.onCheckProcessing()){var e=this.getPerformanceMonitor(),t=e.startMonitoring(this._systemName),n=0;try{this.onBegin();var r=this.queryEntities();this._entityCache.setFrame(r),n=r.length,this.process(r)}finally{e.endMonitoring(this._systemName,t,n)}}},t.lateUpdate=function(){if(this._enabled&&this.onCheckProcessing()){var e=this.getPerformanceMonitor(),t=e.startMonitoring(this._systemName+"_Late"),n=0;try{var r=this.queryEntities();this._entityCache.setFrame(r),n=r.length,this.lateProcess(r),this.onEnd()}finally{e.endMonitoring(this._systemName+"_Late",t,n),this._entityCache.clearFrame()}}},t.flushCommands=function(){return this.commands.flush()},t.onBegin=function(){},t.process=function(e){},t.lateProcess=function(e){},t.onEnd=function(){},t.onCheckProcessing=function(){return!0},t.getPerformanceData=function(){return this.getPerformanceMonitor().getSystemData(this._systemName)},t.getPerformanceStats=function(){return this.getPerformanceMonitor().getSystemStats(this._systemName)},t.resetPerformanceData=function(){this.getPerformanceMonitor().resetSystem(this._systemName)},t.toString=function(){var e=this.entities.length,t=this.getPerformanceData(),n=t?" ("+t.executionTime.toFixed(2)+"ms)":"";return this._systemName+"["+e+" entities]"+n},t.matchesEntity=function(e){if(!this._matcher)return!1;if(this._matcher.isNothing())return!1;if(this._matcher.isEmpty())return!0;for(var t,n=this._matcher.getCondition(),r=s(n.all);!(t=r()).done;){var i=t.value;if(!e.hasComponent(i))return!1}if(n.any.length>0){for(var o,a=!1,c=s(n.any);!(o=c()).done;){var u=o.value;if(e.hasComponent(u)){a=!0;break}}if(!a)return!1}for(var l,h=s(n.none);!(l=h()).done;){var d=l.value;if(e.hasComponent(d))return!1}return(void 0===n.tag||e.tag===n.tag)&&((void 0===n.name||e.name===n.name)&&!(void 0!==n.component&&!e.hasComponent(n.component)))},t.isTracking=function(e){return this._entityCache.isTracked(e)},t.handleEntityComponentChanged=function(e){if(this._matcher&&this._enabled){var t=this._entityCache.isTracked(e),n=this.matchesEntity(e);!t&&n?(this._entityCache.addTracked(e),this._entityCache.invalidate(),this.onAdded(e)):t&&!n&&(this._entityCache.removeTracked(e),this._entityCache.invalidate(),this.onRemoved(e))}},t.updateEntityTracking=function(e){for(var t,n=new Set(e),r=!1,i=s(e);!(t=i()).done;){var o=t.value;this._entityCache.isTracked(o)||(this._entityCache.addTracked(o),r=!0)}for(var a,c=s(this._entityCache.getTracked());!(a=c()).done;){var u=a.value;n.has(u)||(this._entityCache.removeTracked(u),r=!0)}r&&this._entityCache.invalidate()},t.onAdded=function(e){},t.onRemoved=function(e){},t.dispose=function(){this._destroyed||(this.cleanupManualEventListeners(),this.onDestroy(),this._entityCache.clearAll(),this._entityIdMap=null,this.commands.dispose(),this._initialized=!1,this._scene=null,this._destroyed=!0,this.logger.debug("System "+this._systemName+" disposed"))},t.addEventListener=function(e,t,n){var r;if(null===(r=this.scene)||void 0===r||!r.eventSystem)return this.logger.warn(this.systemName+": 无法添加事件监听器,scene.eventSystem 不可用"),null;var i=this.scene.eventSystem.on(e,t,n);return i&&this._eventListeners.push({eventSystem:this.scene.eventSystem,eventType:e,listenerRef:i}),i},t.removeEventListener=function(e,t){var n=this._eventListeners.findIndex(function(n){return n.eventType===e&&n.listenerRef===t});if(n>=0){var r=this._eventListeners[n];if(!r)return;r.eventSystem.off(e,r.listenerRef),this._eventListeners.splice(n,1)}},t.cleanupManualEventListeners=function(){for(var e,t=s(this._eventListeners);!(e=t()).done;){var n=e.value;try{n.eventSystem.off(n.eventType,n.listenerRef)}catch(e){this.logger.warn(this.systemName+': 移除事件监听器失败 "'+n.eventType+'"',e)}}this._eventListeners.length=0},t.destroy=function(){this._destroyed||(this.cleanupManualEventListeners(),this._destroyed=!0,this.onDestroy())},t.getLoggerName=function(){return te(this)},t.onDestroy=function(){},t.requireComponent=function(e,t){var n=e.getComponent(t);if(!n)throw new Error("Component "+t.name+" not found on entity "+e.name+" in "+this.systemName);return n},t.getComponents=function(e){for(var t=this,n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];return r.map(function(n){return t.requireComponent(e,n)})},t.forEach=function(e,t){for(var n=0;n<e.length;n++)t(e[n],n)},t.filterEntities=function(e,t){return Array.from(e).filter(t)},t.mapEntities=function(e,t){return Array.from(e).map(t)},t.findEntity=function(e,t){for(var n=0;n<e.length;n++)if(t(e[n],n))return e[n]},t.someEntity=function(e,t){for(var n=0;n<e.length;n++)if(t(e[n],n))return!0;return!1},t.everyEntity=function(e,t){for(var n=0;n<e.length;n++)if(!t(e[n],n))return!1;return!0},t.saveEpoch=function(){this._lastProcessEpoch=this.currentEpoch},t.forEachChanged=function(e,t,n,r){for(var i=null!=r?r:this._lastProcessEpoch,o=0;o<e.length;o++){for(var a,c=e[o],u=!1,l=s(t);!(a=l()).done;){var h=a.value,d=c.getComponent(h);if(d&&d.lastWriteEpoch>i){u=!0;break}}u&&n(c,o)}this._lastProcessEpoch=this.currentEpoch},t.filterChanged=function(e,t,n){for(var r=null!=n?n:this._lastProcessEpoch,i=[],o=0;o<e.length;o++)for(var a,c=e[o],u=s(t);!(a=u()).done;){var l=a.value,h=c.getComponent(l);if(h&&h.lastWriteEpoch>r){i.push(c);break}}return i},t.hasChanged=function(e,t,n){for(var r,i=null!=n?n:this._lastProcessEpoch,o=s(t);!(r=o()).done;){var a=r.value,c=e.getComponent(a);if(c&&c.lastWriteEpoch>i)return!0}return!1},o(e,[{key:"entities",get:function(){var e=this._entityCache.getFrame();return null!==e?e:(this._entityCache.hasPersistent()||this._entityCache.setPersistent(this.queryEntities()),this._entityCache.getPersistent())}},{key:"updateOrder",get:function(){return this._updateOrder},set:function(e){this.setUpdateOrder(e)}},{key:"addOrder",get:function(){return this._addOrder},set:function(e){this._addOrder=e}},{key:"enabled",get:function(){return this._enabled},set:function(e){this._enabled=e}},{key:"systemName",get:function(){return this._systemName}},{key:"scene",get:function(){return this._scene},set:function(e){this._scene=e,this.commands.setScene(e)}},{key:"matcher",get:function(){return this._matcher}},{key:"lastProcessEpoch",get:function(){return this._lastProcessEpoch}},{key:"currentEpoch",get:function(){var e,t;return null!==(e=null===(t=this._scene)||void 0===t||null===(t=t.epochManager)||void 0===t?void 0:t.current)&&void 0!==e?e:0}}])}(),Le=function(e){function t(){var t;return(t=e.call(this,Pe.empty().all(exports.HierarchyComponent))||this).dirtyEntities=new Set,t}u(t,e);var n=t.prototype;return n.process=function(e){if(0!==this.dirtyEntities.size){for(var t,n=s(this.dirtyEntities);!(t=n()).done;){var r=t.value;r.scene&&this.updateHierarchyCache(r)}this.dirtyEntities.clear()}},n.setParent=function(e,t){var n,r=e.getComponent(exports.HierarchyComponent);r||(r=new exports.HierarchyComponent,e.addComponent(r));var i=r.parentId;if(i!==(null!==(n=null==t?void 0:t.id)&&void 0!==n?n:null)){if(t&&this.isAncestorOf(e,t))throw new Error("Cannot set parent: would create circular reference");if(null!==i){var o,s=null===(o=this.scene)||void 0===o?void 0:o.findEntityById(i);if(s){var a=s.getComponent(exports.HierarchyComponent);if(a){var c=a.childIds.indexOf(e.id);-1!==c&&a.childIds.splice(c,1)}}}if(t){var u=t.getComponent(exports.HierarchyComponent);u||(u=new exports.HierarchyComponent,t.addComponent(u)),r.parentId=t.id,u.childIds.push(e.id)}else r.parentId=null;this.markCacheDirty(e)}},n.insertChildAt=function(e,t,n){var r=t.getComponent(exports.HierarchyComponent),i=e.getComponent(exports.HierarchyComponent);if(r||(r=new exports.HierarchyComponent,t.addComponent(r)),i||(i=new exports.HierarchyComponent,e.addComponent(i)),this.isAncestorOf(t,e))throw new Error("Cannot set parent: would create circular reference");if(null!==r.parentId&&r.parentId!==e.id){var o,s=null===(o=this.scene)||void 0===o?void 0:o.findEntityById(r.parentId);if(s){var a=s.getComponent(exports.HierarchyComponent);if(a){var c=a.childIds.indexOf(t.id);-1!==c&&a.childIds.splice(c,1)}}}r.parentId=e.id;var u=i.childIds.indexOf(t.id);-1!==u&&i.childIds.splice(u,1),n<0||n>=i.childIds.length?i.childIds.push(t.id):i.childIds.splice(n,0,t.id),this.markCacheDirty(t)},n.removeChild=function(e,t){var n=e.getComponent(exports.HierarchyComponent),r=t.getComponent(exports.HierarchyComponent);if(!n||!r)return!1;if(r.parentId!==e.id)return!1;var i=n.childIds.indexOf(t.id);return-1!==i&&n.childIds.splice(i,1),r.parentId=null,this.markCacheDirty(t),!0},n.removeAllChildren=function(e){var t=e.getComponent(exports.HierarchyComponent);if(t)for(var n,r=s([].concat(t.childIds));!(n=r()).done;){var i,o=n.value,a=null===(i=this.scene)||void 0===i?void 0:i.findEntityById(o);a&&this.removeChild(e,a)}},n.getParent=function(e){var t,n,r=e.getComponent(exports.HierarchyComponent);return r&&null!==r.parentId&&null!==(t=null===(n=this.scene)||void 0===n?void 0:n.findEntityById(r.parentId))&&void 0!==t?t:null},n.getChildren=function(e){var t=e.getComponent(exports.HierarchyComponent);if(!t)return[];for(var n,r=[],i=s(t.childIds);!(n=i()).done;){var o,a=n.value,c=null===(o=this.scene)||void 0===o?void 0:o.findEntityById(a);c&&r.push(c)}return r},n.getChildCount=function(e){var t,n=e.getComponent(exports.HierarchyComponent);return null!==(t=null==n?void 0:n.childIds.length)&&void 0!==t?t:0},n.hasChildren=function(e){return this.getChildCount(e)>0},n.isAncestorOf=function(e,n){for(var r=this.getParent(n),i=0;r&&i<t.MAX_DEPTH;){if(r.id===e.id)return!0;r=this.getParent(r),i++}return!1},n.isDescendantOf=function(e,t){return this.isAncestorOf(t,e)},n.getRoot=function(e){for(var n=e,r=this.getParent(n),i=0;r&&i<t.MAX_DEPTH;)n=r,r=this.getParent(n),i++;return n},n.getDepth=function(e){var n=e.getComponent(exports.HierarchyComponent);if(!n)return 0;if(!n.bCacheDirty)return n.depth;for(var r=0,i=this.getParent(e);i&&r<t.MAX_DEPTH;)r++,i=this.getParent(i);return n.depth=r,r},n.isActiveInHierarchy=function(e){if(!e.active)return!1;var t=e.getComponent(exports.HierarchyComponent);if(!t)return e.active;if(!t.bCacheDirty)return t.bActiveInHierarchy;var n=this.getParent(e);return t.bActiveInHierarchy=n?e.active&&this.isActiveInHierarchy(n):e.active,t.bActiveInHierarchy},n.getRootEntities=function(){for(var e,t=[],n=s(this.entities);!(e=n()).done;){var r=e.value,i=r.getComponent(exports.HierarchyComponent);i&&null===i.parentId&&t.push(r)}return t},n.findChild=function(e,t,n){void 0===n&&(n=!1);for(var r,i=this.getChildren(e),o=s(i);!(r=o()).done;){var a=r.value;if(a.name===t)return a}if(n)for(var c,u=s(i);!(c=u()).done;){var l=c.value,h=this.findChild(l,t,!0);if(h)return h}return null},n.findChildrenByTag=function(e,t,n){void 0===n&&(n=!1);for(var r,i=[],o=s(this.getChildren(e));!(r=o()).done;){var a=r.value;0!==(a.tag&t)&&i.push(a),n&&i.push.apply(i,this.findChildrenByTag(a,t,!0))}return i},n.forEachChild=function(e,t,n){void 0===n&&(n=!1);for(var r,i=s(this.getChildren(e));!(r=i()).done;){var o=r.value;t(o),n&&this.forEachChild(o,t,!0)}},n.flattenHierarchy=function(e){for(var t,n=this,r=[],i=function(t,o){var a=n.hasChildren(t),c=e.has(t.id);if(r.push({entity:t,depth:o,bHasChildren:a,bIsExpanded:c}),a&&c)for(var u,l=s(n.getChildren(t));!(u=l()).done;){var h=u.value;i(h,o+1)}},o=s(this.getRootEntities());!(t=o()).done;){var a=t.value;i(a,0)}return r},n.markCacheDirty=function(e){var t=e.getComponent(exports.HierarchyComponent);if(t&&!t.bCacheDirty){t.bCacheDirty=!0,this.dirtyEntities.add(e);for(var n,r=s(t.childIds);!(n=r()).done;){var i,o=n.value,a=null===(i=this.scene)||void 0===i?void 0:i.findEntityById(o);a&&this.markCacheDirty(a)}}},n.updateHierarchyCache=function(e){var t=e.getComponent(exports.HierarchyComponent);t&&(t.depth=this.getDepth(e),t.bActiveInHierarchy=this.isActiveInHierarchy(e),t.bCacheDirty=!1)},n.onAdded=function(e){var t=e.getComponent(exports.HierarchyComponent);t&&t.bCacheDirty&&this.dirtyEntities.add(e)},n.onRemoved=function(e){this.dirtyEntities.delete(e);var t=e.getComponent(exports.HierarchyComponent);if(t){if(null!==t.parentId){var n,r=null===(n=this.scene)||void 0===n?void 0:n.findEntityById(t.parentId);if(r){var i=r.getComponent(exports.HierarchyComponent);if(i){var o=i.childIds.indexOf(e.id);-1!==o&&i.childIds.splice(o,1)}}}for(var a,c=s(t.childIds);!(a=c()).done;){var u,l=a.value,h=null===(u=this.scene)||void 0===u?void 0:u.findEntityById(l);if(h){var d=h.getComponent(exports.HierarchyComponent);d&&(d.parentId=null,this.markCacheDirty(h))}}}},n.dispose=function(){this.dirtyEntities.clear()},o(t,[{key:"updateOrder",get:function(){return-1e3}}])}(Be);Le.MAX_DEPTH=32;var He=function(){function e(){}var t=e.prototype;return t.collectEntityData=function(e){if(!e)return this.getEmptyEntityDebugData();var t,n=e.entities;if(!n)return this.getEmptyEntityDebugData();try{t=n.getStats?n.getStats():this.calculateFallbackEntityStats(n)}catch(e){return{totalEntities:0,activeEntities:0,pendingAdd:0,pendingRemove:0,entitiesPerArchetype:[],topEntitiesByComponents:[],entityHierarchy:[],entityDetailsMap:{}}}var r=this.collectArchetypeData(e);return{totalEntities:t.totalEntities,activeEntities:t.activeEntities,pendingAdd:t.pendingAdd||0,pendingRemove:t.pendingRemove||0,entitiesPerArchetype:r.distribution,topEntitiesByComponents:r.topEntities,entityHierarchy:[],entityDetailsMap:{}}},t.getRawEntityList=function(e){if(!e)return[];var t=e.entities;if(null==t||!t.buffer)return[];var n=e.getSystem(Le);return t.buffer.map(function(e){var t,r,i,o,s=e.getComponent(exports.HierarchyComponent),a=null!==(t=null==n?void 0:n.isActiveInHierarchy(e))&&void 0!==t?t:e.active,c=null!==(r=null==n?void 0:n.getDepth(e))&&void 0!==r?r:0;return{id:e.id,name:e.name||"Entity_"+e.id,active:!1!==e.active,enabled:!1!==e.enabled,activeInHierarchy:a,componentCount:e.components.length,componentTypes:e.components.map(function(e){return H(e)}),parentId:null!==(i=null==s?void 0:s.parentId)&&void 0!==i?i:null,childIds:null!==(o=null==s?void 0:s.childIds)&&void 0!==o?o:[],depth:c,tag:e.tag||0,updateOrder:e.updateOrder||0}})},t.getEntityDetails=function(e,t){try{var n,r,i;if(!t)return null;var o=t.entities;if(null==o||!o.buffer)return null;var s=o.buffer.find(function(t){return t.id===e});if(!s)return null;var c=t.getSystem(Le),u=null==c?void 0:c.getParent(s),l=null!==(n=null==u?void 0:u.name)&&void 0!==n?n:null,h=s.getDebugInfo?s.getDebugInfo():this.buildFallbackEntityInfo(s,t,c),d=this.extractComponentDetails(s.components),f=this.getSceneInfo(t);return a({},h,{scene:f.name,sceneName:f.name,sceneType:f.type,parentName:l,components:d||[],componentCount:(null===(r=s.components)||void 0===r?void 0:r.length)||0,componentTypes:(null===(i=s.components)||void 0===i?void 0:i.map(function(e){return H(e)}))||[]})}catch(e){return{error:"获取实体详情失败: "+(e instanceof Error?e.message:String(e)),scene:"获取失败",components:[],componentCount:0,componentTypes:[]}}},t.getSceneInfo=function(e){var t="当前场景",n="Scene";try{if(e.name&&"string"==typeof e.name&&e.name.trim())t=e.name.trim();else if(e.constructor&&e.constructor.name)t=e.constructor.name,n=e.constructor.name;else if(e._name&&"string"==typeof e._name&&e._name.trim())t=e._name.trim();else{var r,i=null===(r=Object.getPrototypeOf(e))||void 0===r||null===(r=r.constructor)||void 0===r?void 0:r.name;i&&"Object"!==i&&(t=i,n=i)}}catch(e){t="场景名获取失败"}return{name:t,type:n}},t.collectEntityDataWithMemory=function(e){if(!e)return this.getEmptyEntityDebugData();var t,n=e.entities;if(!n)return this.getEmptyEntityDebugData();try{t=n.getStats?n.getStats():this.calculateFallbackEntityStats(n)}catch(e){return{totalEntities:0,activeEntities:0,pendingAdd:0,pendingRemove:0,entitiesPerArchetype:[],topEntitiesByComponents:[],entityHierarchy:[],entityDetailsMap:{}}}var r=this.collectArchetypeDataWithMemory(e);return{totalEntities:t.totalEntities,activeEntities:t.activeEntities,pendingAdd:t.pendingAdd||0,pendingRemove:t.pendingRemove||0,entitiesPerArchetype:r.distribution,topEntitiesByComponents:r.topEntities,entityHierarchy:this.buildEntityHierarchyTree(n,e),entityDetailsMap:this.buildEntityDetailsMap(n,e)}},t.collectArchetypeData=function(e){var t;if(e&&e.archetypeSystem&&"function"==typeof e.archetypeSystem.getAllArchetypes)return this.extractArchetypeStatistics(e.archetypeSystem);var n={entities:(null===(t=e.entities)||void 0===t?void 0:t.buffer)||[]};return{distribution:this.getArchetypeDistributionFast(n),topEntities:this.getTopEntitiesByComponentsFast(n)}},t.getArchetypeDistributionFast=function(e){var t=new Map;return e&&e.entities&&e.entities.forEach(function(e){var n,r=(null===(n=e.components)||void 0===n?void 0:n.map(function(e){return H(e)}))||[],i=r.length>0?r.sort().join(", "):"无组件",o=t.get(i);o?o.count++:t.set(i,{count:1,componentTypes:r})}),Array.from(t.entries()).map(function(e){return{signature:e[0],count:e[1].count,memory:0}}).sort(function(e,t){return t.count-e.count}).slice(0,20)},t.getTopEntitiesByComponentsFast=function(e){return e&&e.entities?e.entities.map(function(e){var t;return{id:e.id.toString(),name:e.name||"Entity_"+e.id,componentCount:(null===(t=e.components)||void 0===t?void 0:t.length)||0,memory:0}}).sort(function(e,t){return t.componentCount-e.componentCount}):[]},t.collectArchetypeDataWithMemory=function(e){var t;if(e&&e.archetypeSystem&&"function"==typeof e.archetypeSystem.getAllArchetypes)return this.extractArchetypeStatisticsWithMemory(e.archetypeSystem);var n={entities:(null===(t=e.entities)||void 0===t?void 0:t.buffer)||[]};return{distribution:this.getArchetypeDistributionWithMemory(n),topEntities:this.getTopEntitiesByComponentsWithMemory(n)}},t.extractArchetypeStatistics=function(e){var t=e.getAllArchetypes(),n=[],r=[];return t.forEach(function(e){var t,i,o=(null===(t=e.componentTypes)||void 0===t?void 0:t.map(function(e){return e.name}).join(","))||"Unknown",s=(null===(i=e.entities)||void 0===i?void 0:i.length)||0;n.push({signature:o,count:s,memory:0}),e.entities&&e.entities.forEach(function(e){var t;r.push({id:e.id.toString(),name:e.name||"Entity_"+e.id,componentCount:(null===(t=e.components)||void 0===t?void 0:t.length)||0,memory:0})})}),n.sort(function(e,t){return t.count-e.count}),r.sort(function(e,t){return t.componentCount-e.componentCount}),{distribution:n,topEntities:r}},t.extractArchetypeStatisticsWithMemory=function(e){var t=this,n=e.getAllArchetypes(),r=[],i=[];return n.forEach(function(e){var n,o,s=(null===(n=e.componentTypes)||void 0===n?void 0:n.map(function(e){return e.name}).join(","))||"Unknown",a=(null===(o=e.entities)||void 0===o?void 0:o.length)||0,c=0;if(e.entities&&e.entities.length>0){for(var u=Math.min(5,e.entities.length),l=0,h=0;h<u;h++)l+=t.estimateEntityMemoryUsage(e.entities[h]);c=l/u*a}r.push({signature:s,count:a,memory:c}),e.entities&&e.entities.forEach(function(e){var n;i.push({id:e.id.toString(),name:e.name||"Entity_"+e.id,componentCount:(null===(n=e.components)||void 0===n?void 0:n.length)||0,memory:t.estimateEntityMemoryUsage(e)})})}),r.sort(function(e,t){return t.count-e.count}),i.sort(function(e,t){return t.componentCount-e.componentCount}),{distribution:r,topEntities:i}},t.getArchetypeDistributionWithMemory=function(e){var t=this,n=new Map;return e&&e.entities&&e.entities.forEach(function(e){var r,i=(null===(r=e.components)||void 0===r?void 0:r.map(function(e){return H(e)}))||[],o=i.length>0?i.sort().join(", "):"无组件",s=n.get(o),a=t.estimateEntityMemoryUsage(e);(isNaN(a)||a<0)&&(a=0),s?(s.count++,s.memory+=a):n.set(o,{count:1,memory:a,componentTypes:i})}),Array.from(n.entries()).map(function(e){var t=e[0],n=e[1];return{signature:t,count:n.count,memory:isNaN(n.memory)?0:n.memory}}).sort(function(e,t){return t.count-e.count})},t.getTopEntitiesByComponentsWithMemory=function(e){var t=this;return e&&e.entities?e.entities.map(function(e){var n;return{id:e.id.toString(),name:e.name||"Entity_"+e.id,componentCount:(null===(n=e.components)||void 0===n?void 0:n.length)||0,memory:t.estimateEntityMemoryUsage(e)}}).sort(function(e,t){return t.componentCount-e.componentCount}):[]},t.getEmptyEntityDebugData=function(){return{totalEntities:0,activeEntities:0,pendingAdd:0,pendingRemove:0,entitiesPerArchetype:[],topEntitiesByComponents:[],entityHierarchy:[],entityDetailsMap:{}}},t.calculateFallbackEntityStats=function(e){var t=e.buffer||[],n=t.filter(function(e){return e.enabled&&!e.isDestroyed});return{totalEntities:t.length,activeEntities:n.length,pendingAdd:0,pendingRemove:0,averageComponentsPerEntity:n.length>0?t.reduce(function(e,t){var n;return e+((null===(n=t.components)||void 0===n?void 0:n.length)||0)},0)/n.length:0}},t.estimateEntityMemoryUsage=function(e){var t=this;try{var n=0,r=this.calculateObjectSize(e,["components","children","parent"]);return!isNaN(r)&&r>0&&(n+=r),e.components&&Array.isArray(e.components)&&e.components.forEach(function(e){var r=t.calculateObjectSize(e,["entity"]);!isNaN(r)&&r>0&&(n+=r)}),isNaN(n)||n<0?0:n}catch(e){return 0}},t.calculateObjectSize=function(e,t){if(void 0===t&&(t=[]),!e||"object"!=typeof e)return 0;var n=new WeakSet,r=function(e,i){if(void 0===i&&(i=0),!e||"object"!=typeof e||i>=2)return 0;if(n.has(e))return 0;n.add(e);var o=32;try{for(var s=Object.keys(e),a=Math.min(s.length,20),c=0;c<a;c++){var u=s[c];if(u&&!t.includes(u)&&"constructor"!==u&&"__proto__"!==u&&!u.startsWith("_cc_")&&!u.startsWith("__")){var l=e[u];o+=2*u.length,"string"==typeof l?o+=Math.min(2*l.length,200):"number"==typeof l?o+=8:"boolean"==typeof l?o+=4:Array.isArray(l)?o+=40+Math.min(8*l.length,160):"object"==typeof l&&null!==l&&(o+=r(l,i+1))}}}catch(e){return 64}return o};try{var i=r(e);return Math.max(i,32)}catch(e){return 64}},t.buildEntityHierarchyTree=function(e,t){var n=this;if(null==e||!e.buffer)return[];var r=null==t?void 0:t.getSystem(Le),i=[];return e.buffer.forEach(function(e){var t=e.getComponent(exports.HierarchyComponent);if(null===(null==t?void 0:t.parentId)||void 0===(null==t?void 0:t.parentId)){var o=n.buildEntityHierarchyNode(e,r);i.push(o)}}),i.sort(function(e,t){return e.name<t.name?-1:e.name>t.name?1:e.id-t.id}),i},t.buildEntityHierarchyNode=function(e,t){var n,r,i,o=this,s=e.getComponent(exports.HierarchyComponent),c=null!==(n=null==t?void 0:t.isActiveInHierarchy(e))&&void 0!==n?n:e.active,u=null!==(r=null==t?void 0:t.getDepth(e))&&void 0!==r?r:0,l={id:e.id,name:e.name||"Entity_"+e.id,active:!1!==e.active,enabled:!1!==e.enabled,activeInHierarchy:c,componentCount:e.components.length,componentTypes:e.components.map(function(e){return H(e)}),parentId:null!==(i=null==s?void 0:s.parentId)&&void 0!==i?i:null,children:[],depth:u,tag:e.tag||0,updateOrder:e.updateOrder||0};if(t){var h=t.getChildren(e);h.length>0&&(l.children=h.map(function(e){return o.buildEntityHierarchyNode(e,t)}))}"function"==typeof e.getDebugInfo&&(l=a({},l,e.getDebugInfo()));return e.components&&e.components.length>0&&(l.componentDetails=this.extractComponentDetails(e.components)),l},t.buildEntityDetailsMap=function(e,t){var n=this;if(null==e||!e.buffer)return{};for(var r=null==t?void 0:t.getSystem(Le),i={},o=e.buffer,s=0;s<o.length;s+=100){o.slice(s,s+100).forEach(function(e){var o,s=e.getDebugInfo?e.getDebugInfo():n.buildFallbackEntityInfo(e,t,r),c=e.getComponentCacheStats?e.getComponentCacheStats():null,u=n.extractComponentDetails(e.components),l=null==r?void 0:r.getParent(e),h=null!==(o=null==l?void 0:l.name)&&void 0!==o?o:null;i[e.id]=a({},s,{parentName:h,components:u,componentTypes:s.componentTypes||u.map(function(e){return e.typeName}),cachePerformance:c?{hitRate:c.cacheStats.hitRate,size:c.cacheStats.size,maxSize:c.cacheStats.maxSize}:null})})}return i},t.buildFallbackEntityInfo=function(e,t,n){var r,i,o,s,a,c,u,l=this.getSceneInfo(t),h=e.getComponent(exports.HierarchyComponent),d=null!==(r=null==n?void 0:n.isActiveInHierarchy(e))&&void 0!==r?r:e.active,f=null!==(i=null==n?void 0:n.getDepth(e))&&void 0!==i?i:0;return{name:e.name||"Entity_"+e.id,id:e.id,enabled:!1!==e.enabled,active:!1!==e.active,activeInHierarchy:d,destroyed:e.isDestroyed||!1,scene:l.name,sceneName:l.name,sceneType:l.type,componentCount:e.components.length,componentTypes:e.components.map(function(e){return H(e)}),componentMask:(null===(o=e.componentMask)||void 0===o?void 0:o.toString())||"0",parentId:null!==(s=null==h?void 0:h.parentId)&&void 0!==s?s:null,childCount:null!==(a=null==h||null===(c=h.childIds)||void 0===c?void 0:c.length)&&void 0!==a?a:0,childIds:null!==(u=null==h?void 0:h.childIds)&&void 0!==u?u:[],depth:f,tag:e.tag||0,updateOrder:e.updateOrder||0}},t.extractComponentDetails=function(e){var t=this;return e.map(function(e){var n=H(e),r={};try{Object.keys(e).forEach(function(n){if(!n.startsWith("_")&&"entity"!==n&&"constructor"!==n){var i=e[n];null!=i&&(r[n]=t.formatPropertyValue(i))}}),0===Object.keys(r).length&&(r._info="该组件没有公开属性",r._componentId=H(e))}catch(t){r._error="属性提取失败",r._componentId=H(e)}return{typeName:n,properties:r}})},t.getComponentProperties=function(e,t,n){var r=this;try{if(!n)return{};var i=n.entities;if(null==i||!i.buffer)return{};var o=i.buffer.find(function(t){return t.id===e});if(!o||t>=o.components.length)return{};var s=o.components[t];if(!s)return{};var a={};return Object.keys(s).forEach(function(e){if(!e.startsWith("_")&&"entity"!==e){var t=s[e];null!=t&&(a[e]=r.formatPropertyValue(t))}}),a}catch(e){return{_error:"属性提取失败"}}},t.formatPropertyValue=function(e,t){return void 0===t&&(t=0),null==e?e:"object"!=typeof e?"string"==typeof e&&e.length>200?"[长字符串: "+e.length+"字符] "+e.substring(0,100)+"...":e:0===t?this.formatObjectFirstLevel(e):this.createLazyLoadPlaceholder(e)},t.formatObjectFirstLevel=function(e){var t=this;try{if(Array.isArray(e)){if(0===e.length)return[];if(e.length>10){var n=e.slice(0,3).map(function(e){return t.formatPropertyValue(e,1)});return{_isLazyArray:!0,_arrayLength:e.length,_sample:n,_summary:"数组["+e.length+"个元素]"}}return e.map(function(e){return t.formatPropertyValue(e,1)})}var r=Object.keys(e);if(0===r.length)return{};for(var i={},o=0,s=0,a=r;s<a.length;s++){var c=a[s];if(o>=15){i._hasMoreProperties=!0,i._totalProperties=r.length,i._hiddenCount=r.length-o;break}if(!c.startsWith("_")&&!c.startsWith("$")&&"function"!=typeof e[c])try{var u=e[c];null!=u&&(i[c]=this.formatPropertyValue(u,1),o++)}catch(e){i[c]="[访问失败: "+(e instanceof Error?e.message:String(e))+"]",o++}}return i}catch(e){return"[对象解析失败: "+(e instanceof Error?e.message:String(e))+"]"}},t.createLazyLoadPlaceholder=function(e){try{var t,n=(null===(t=e.constructor)||void 0===t?void 0:t.name)||"Object";return{_isLazyObject:!0,_typeName:n,_summary:this.getObjectSummary(e,n),_objectId:this.generateObjectId(e)}}catch(e){return{_isLazyObject:!0,_typeName:"Unknown",_summary:"无法分析的对象: "+(e instanceof Error?e.message:String(e)),_objectId:Math.random().toString(36).substr(2,9)}}},t.getObjectSummary=function(e,t){try{if((t.toLowerCase().includes("vec")||t.toLowerCase().includes("vector"))&&void 0!==e.x&&void 0!==e.y){var n=void 0!==e.z?e.z:"";return t+"("+e.x+", "+e.y+(n?", "+n:"")+")"}if(t.toLowerCase().includes("color")&&void 0!==e.r&&void 0!==e.g&&void 0!==e.b){var r=void 0!==e.a?e.a:1;return t+"("+e.r+", "+e.g+", "+e.b+", "+r+")"}if(t.toLowerCase().includes("node"))return t+": "+(e.name||e._name||"未命名");if(t.toLowerCase().includes("component")){var i,o,s=(null===(i=e.node)||void 0===i?void 0:i.name)||(null===(o=e.node)||void 0===o?void 0:o._name)||"";return t+(s?" on "+s:"")}var a=Object.keys(e);return 0===a.length?t+" (空对象)":t+" ("+a.length+"个属性)"}catch(e){return t+" (无法分析)"}},t.generateObjectId=function(e){try{return void 0!==e.id?"obj_"+e.id:void 0!==e._id?"obj_"+e._id:void 0!==e.uuid?"obj_"+e.uuid:void 0!==e._uuid?"obj_"+e._uuid:"obj_"+Math.random().toString(36).substr(2,9)}catch(e){return"obj_"+Math.random().toString(36).substr(2,9)}},t.expandLazyObject=function(e,t,n,r){try{if(!r)return null;var i=r.entities;if(null==i||!i.buffer)return null;var o=i.buffer.find(function(t){return t.id===e});if(!o)return null;if(t>=o.components.length)return null;var s=o.components[t],a=this.getObjectByPath(s,n);return a?this.formatObjectFirstLevel(a):null}catch(e){return{error:"展开失败: "+(e instanceof Error?e.message:String(e))}}},t.getObjectByPath=function(e,t){if(!t)return e;for(var n,r=e,i=s(t.split("."));!(n=i()).done;){var o=n.value;if(null==r)return null;if(o.includes("[")&&o.includes("]")){var a=o.substring(0,o.indexOf("[")),c=parseInt(o.substring(o.indexOf("[")+1,o.indexOf("]")));if(a&&(r=r[a]),!(Array.isArray(r)&&c>=0&&c<r.length))return null;r=r[c]}else r=r[o]}return r},e}(),We=function(){function e(){}return e.prototype.collectSystemData=function(e,t){if(!t)return{totalSystems:0,systemsInfo:[]};var n=t.systems||[],r=new Map,i=new Map;if(e)try{r=e.getAllSystemStats(),i=e.getAllSystemData()}catch(e){}return{totalSystems:n.length,systemsInfo:n.map(function(e){var t,n=e.systemName||te(e),o=r.get(n),s=i.get(n);return{name:n,type:te(e),entityCount:(null===(t=e.entities)||void 0===t?void 0:t.length)||0,executionTime:(null==o?void 0:o.averageTime)||(null==s?void 0:s.executionTime)||0,minExecutionTime:(null==o?void 0:o.minTime)===Number.MAX_VALUE?0:(null==o?void 0:o.minTime)||0,maxExecutionTime:(null==o?void 0:o.maxTime)||0,executionTimeHistory:(null==o?void 0:o.recentTimes)||[],updateOrder:e.updateOrder||0,enabled:!1!==e.enabled,lastUpdateTime:(null==s?void 0:s.lastUpdateTime)||0}})}},e}(),je=function(){function e(){this.frameTimeHistory=[],this.maxHistoryLength=60,this.gcCollections=0,this.lastMemoryCheck=0}var t=e.prototype;return t.collectPerformanceData=function(e){var t=g.deltaTime,n=1e3*t,r=t>0?Math.round(1/t):0,i=this.getECSPerformanceData(e),o=i.totalExecutionTime,s=n>0?o/n*100:0,a=0;performance.memory&&(a=performance.memory.usedJSHeapSize/1024/1024),this.frameTimeHistory.push(o),this.frameTimeHistory.length>this.maxHistoryLength&&this.frameTimeHistory.shift();var c=this.frameTimeHistory.filter(function(e){return e>=0});return{frameTime:o,engineFrameTime:n,ecsPercentage:s,memoryUsage:a,fps:r,averageFrameTime:c.length>0?c.reduce(function(e,t){return e+t},0)/c.length:o,minFrameTime:c.length>0?Math.min.apply(Math,c):o,maxFrameTime:c.length>0?Math.max.apply(Math,c):o,frameTimeHistory:[].concat(this.frameTimeHistory),systemPerformance:this.getSystemPerformance(e),systemBreakdown:i.systemBreakdown,memoryDetails:this.getMemoryDetails()}},t.getECSPerformanceData=function(e){if(!e)return{totalExecutionTime:0,systemBreakdown:[]};if(!e.enabled){try{e.enabled=!0}catch(e){}return{totalExecutionTime:0,systemBreakdown:[]}}try{var t=0,n=[],r=e.getAllSystemStats();if(0===r.size)return{totalExecutionTime:0,systemBreakdown:[]};for(var i,o=s(r.entries());!(i=o()).done;){var a=i.value,c=a[0],u=a[1],l=u.recentTimes&&u.recentTimes.length>0?u.recentTimes[u.recentTimes.length-1]:u.averageTime||0;t+=l,n.push({systemName:c,executionTime:l,percentage:0})}return n.forEach(function(e){e.percentage=t>0?e.executionTime/t*100:0}),n.sort(function(e,t){return t.executionTime-e.executionTime}),{totalExecutionTime:t,systemBreakdown:n}}catch(e){return{totalExecutionTime:0,systemBreakdown:[]}}},t.getSystemPerformance=function(e){if(!e)return[];try{var t=e.getAllSystemStats(),n=e.getAllSystemData();return Array.from(t.entries()).map(function(e){var t=e[0],r=e[1],i=n.get(t);return{systemName:t,averageTime:r.averageTime||0,maxTime:r.maxTime||0,minTime:r.minTime===Number.MAX_VALUE?0:r.minTime||0,samples:r.executionCount||0,percentage:0,entityCount:(null==i?void 0:i.entityCount)||0,lastExecutionTime:(null==i?void 0:i.executionTime)||0}})}catch(e){return[]}},t.getMemoryDetails=function(){var e={entities:0,components:0,systems:0,pooled:0,totalMemory:0,usedMemory:0,freeMemory:0,gcCollections:this.updateGCCount()};try{if(performance.memory){var t=performance.memory;if(e.totalMemory=t.jsHeapSizeLimit||536870912,e.usedMemory=t.usedJSHeapSize||0,e.freeMemory=e.totalMemory-e.usedMemory,this.lastMemoryCheck>0)this.lastMemoryCheck-e.usedMemory>1048576&&this.gcCollections++;this.lastMemoryCheck=e.usedMemory}else e.totalMemory=536870912,e.freeMemory=536870912}catch(e){return{totalMemory:0,usedMemory:0,freeMemory:0,entityMemory:0,componentMemory:0,systemMemory:0,pooledMemory:0,gcCollections:this.gcCollections}}return e},t.updateGCCount=function(){try{return"undefined"!=typeof PerformanceObserver||performance.measureUserAgentSpecificMemory,this.gcCollections}catch(e){return this.gcCollections}},e}(),Ge=function(){function e(e,t,n,r){void 0===n&&(n=1e3),void 0===r&&(r=10),this.pool=[],this.stats={totalCreated:0,totalAcquired:0,totalReleased:0},this.createFn=e,t&&(this.resetFn=t),this.maxSize=n,this.minSize=Math.max(1,r)}var t=e.prototype;return t.acquire=function(){return this.stats.totalAcquired++,this.pool.length>0?this.pool.pop():(this.stats.totalCreated++,this.createFn())},t.release=function(e){this.stats.totalReleased++,this.pool.length>=this.maxSize||(this.resetFn&&this.resetFn(e),this.pool.push(e))},t.prewarm=function(e){for(var t=Math.min(e,this.maxSize),n=this.pool.length;n<t;n++){var r=this.createFn();this.resetFn&&this.resetFn(r),this.pool.push(r),this.stats.totalCreated++}},t.shrink=function(){for(;this.pool.length>this.minSize;)this.pool.pop()},t.clear=function(){this.pool.length=0},t.getAvailableCount=function(){return this.pool.length},t.getMaxSize=function(){return this.maxSize},t.getStats=function(){var e=0===this.stats.totalAcquired?0:(this.stats.totalAcquired-this.stats.totalCreated)/this.stats.totalAcquired;return{totalCreated:this.stats.totalCreated,totalAcquired:this.stats.totalAcquired,totalReleased:this.stats.totalReleased,hitRate:e,currentSize:this.pool.length,maxSize:this.maxSize,minSize:this.minSize,utilizationRate:this.pool.length/this.maxSize}},e}(),Ue=function(){function e(){this.pools=new Map,this.usageTracker=new Map,this.autoCleanupInterval=6e4,this.lastCleanupTime=0}e.getInstance=function(){return e.instance||(e.instance=new e),e.instance};var t=e.prototype;return t.registerPool=function(e,t,n,r,i){this.pools.set(e,new Ge(t,n,r,i)),this.usageTracker.set(e,{createCount:0,releaseCount:0,lastAccessTime:Date.now()})},t.acquireComponent=function(e){var t=this.pools.get(e);return this.trackUsage(e,"create"),t?t.acquire():null},t.releaseComponent=function(e,t){var n=this.pools.get(e);this.trackUsage(e,"release"),n&&n.release(t)},t.trackUsage=function(e,t){var n=this.usageTracker.get(e);n||(n={createCount:0,releaseCount:0,lastAccessTime:Date.now()},this.usageTracker.set(e,n)),"create"===t?n.createCount++:n.releaseCount++,n.lastAccessTime=Date.now()},t.update=function(){var e=Date.now();if(!(e-this.lastCleanupTime<this.autoCleanupInterval)){for(var t,n=s(this.usageTracker.entries());!(t=n()).done;){var r=t.value,i=r[0];if(e-r[1].lastAccessTime>12e4){var o=this.pools.get(i);o&&o.shrink()}}this.lastCleanupTime=e}},t.getHotComponents=function(e){return void 0===e&&(e=100),Array.from(this.usageTracker.entries()).filter(function(t){return t[0],t[1].createCount>e}).map(function(e){return e[0]})},t.prewarmAll=function(e){void 0===e&&(e=100);for(var t,n=s(this.pools.values());!(t=n()).done;){t.value.prewarm(e)}},t.clearAll=function(){for(var e,t=s(this.pools.values());!(e=t()).done;){e.value.clear()}},t.reset=function(){this.pools.clear(),this.usageTracker.clear()},t.getGlobalStats=function(){for(var e,t=[],n=s(this.pools.entries());!(e=n()).done;){var r=e.value,i=r[0],o=r[1];t.push({componentName:i,poolStats:o.getStats(),usage:this.usageTracker.get(i)})}return t},t.getPoolStats=function(){for(var e,t=new Map,n=s(this.pools);!(e=n()).done;){var r=e.value,i=r[0],o=r[1];t.set(i,{available:o.getAvailableCount(),maxSize:o.getMaxSize()})}return t},t.getPoolUtilization=function(){for(var e,t=new Map,n=s(this.pools);!(e=n()).done;){var r=e.value,i=r[0],o=r[1],a=o.getAvailableCount(),c=o.getMaxSize(),u=c-a,l=c>0?u/c*100:0;t.set(i,{used:u,total:c,utilization:l})}return t},t.getComponentUtilization=function(e){var t=this.pools.get(e);if(!t)return 0;var n=t.getAvailableCount(),r=t.getMaxSize();return r>0?(r-n)/r*100:0},e}(),qe=function(){function e(){}var t=e.prototype;return t.collectComponentData=function(e){var t=this;if(!e)return{componentTypes:0,componentInstances:0,componentStats:[]};var n=e.entities;if(null==n||!n.buffer)return{componentTypes:0,componentInstances:0,componentStats:[]};var r=new Map,i=0;n.buffer.forEach(function(e){e.components&&e.components.forEach(function(e){var t=H(e),n=r.get(t)||{count:0,entities:0};n.count++,i++,r.set(t,n)})});var o=new Map,a=new Map;try{for(var c,u=Ue.getInstance(),l=u.getPoolStats(),h=u.getPoolUtilization(),d=s(l.entries());!(c=d()).done;){var f=c.value,p=f[0],m=f[1];a.set(p,m.maxSize)}for(var v,y=s(h.entries());!(v=y()).done;){var g=v.value,_=g[0],S=g[1];o.set(_,S.utilization)}}catch(e){}return{componentTypes:r.size,componentInstances:i,componentStats:Array.from(r.entries()).map(function(r){var i=r[0],s=r[1],c=a.get(i)||0,u=o.get(i)||0,l=t.getEstimatedComponentSize(i,e);return{typeName:i,instanceCount:s.count,memoryPerInstance:l,totalMemory:s.count*l,poolSize:c,poolUtilization:u,averagePerEntity:s.count/n.buffer.length}})}},t.getEstimatedComponentSize=function(t,n){if(e.componentSizeCache.has(t))return e.componentSizeCache.get(t);if(!n)return 64;var r=n.entities;if(null==r||!r.buffer)return 64;var i=64;try{for(var o,a=s(r.buffer);!(o=a()).done;){var c=o.value;if(c.components){var u=c.components.find(function(e){return H(e)===t});if(u){i=this.calculateQuickObjectSize(u);break}}}}catch(e){i=64}return e.componentSizeCache.set(t,i),i},t.calculateQuickObjectSize=function(e){if(!e||"object"!=typeof e)return 8;var t=32,n=new WeakSet,r=function(e,t){if(void 0===t&&(t=0),!e||"object"!=typeof e||n.has(e)||t>3)return 0;n.add(e);var i=0;try{for(var o=Object.keys(e),s=0;s<Math.min(o.length,20);s++){var a=o[s];if(a&&"entity"!==a&&"_entity"!==a&&"constructor"!==a){var c=e[a];i+=2*a.length,"string"==typeof c?i+=Math.min(2*c.length,200):"number"==typeof c?i+=8:"boolean"==typeof c?i+=4:"object"==typeof c&&null!==c&&(i+=r(c,t+1))}}}catch(e){return 32}return i};return t+=r(e),Math.max(t,32)},t.calculateDetailedComponentMemory=function(e,t){if(!t)return this.getEstimatedComponentSize(e,t);var n=t.entities;if(null==n||!n.buffer)return this.getEstimatedComponentSize(e,t);try{for(var r,i=s(n.buffer);!(r=i()).done;){var o=r.value;if(o.components){var a=o.components.find(function(t){return H(t)===e});if(a)return this.estimateObjectSize(a)}}}catch(e){}return this.getEstimatedComponentSize(e,t)},t.estimateObjectSize=function(e,t,n){if(void 0===t&&(t=new WeakSet),void 0===n&&(n=0),null==e||n>10)return 0;if(t.has(e))return 0;var r=0;switch(typeof e){case"boolean":r=4;break;case"number":default:r=8;break;case"string":r=24+Math.min(2*e.length,1e3);break;case"object":if(t.add(e),Array.isArray(e)){r=40+8*e.length;for(var i=Math.min(e.length,50),o=0;o<i;o++)r+=this.estimateObjectSize(e[o],t,n+1)}else{r=32;try{for(var s=Object.getOwnPropertyNames(e),a=Math.min(s.length,30),c=0;c<a;c++){var u=s[c];if(u&&("constructor"!==u&&"__proto__"!==u&&"entity"!==u&&"_entity"!==u&&!u.startsWith("_cc_")&&!u.startsWith("__")))try{r+=16+2*u.length;var l=e[u];null!=l&&(r+=this.estimateObjectSize(l,t,n+1))}catch(e){continue}}}catch(e){r=128}}}return 8*Math.ceil(r/8)},e.clearCache=function(){e.componentSizeCache.clear()},e}();qe.componentSizeCache=new Map;var Qe,Ve=function(){function e(){this.sceneStartTime=Date.now()}var t=e.prototype;return t.collectSceneData=function(e){if(!e)return{currentSceneName:"No Scene",isInitialized:!1,sceneRunTime:0,sceneEntityCount:0,sceneSystemCount:0,sceneUptime:0};var t=(Date.now()-this.sceneStartTime)/1e3,n=e.getStats();return{currentSceneName:e.name||"Unnamed Scene",isInitialized:!0,sceneRunTime:t,sceneEntityCount:n.entityCount,sceneSystemCount:n.processorCount,sceneUptime:t}},t.setSceneStartTime=function(e){this.sceneStartTime=e},e}(),Ye=function(){function e(e,t){void 0===t&&(t=!0),this.isConnected=!1,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.url=e,this.autoReconnect=t}var t=e.prototype;return t.setMessageHandler=function(e){this.messageHandler=e},t.connect=function(){var e=this;return new Promise(function(t,n){try{e.ws=new WebSocket(e.url),e.ws.onopen=function(n){e.handleOpen(n),t()},e.ws.onclose=function(t){e.handleClose(t)},e.ws.onerror=function(t){e.handleError(t),n(t)},e.ws.onmessage=function(t){e.handleMessage(t)}}catch(t){e.handleConnectionFailure(t),n(t)}})},t.disconnect=function(){this.ws&&(this.autoReconnect=!1,this.ws.close(),delete this.ws),this.isConnected=!1},t.send=function(e){if(this.isConnected&&this.ws)try{var t="string"==typeof e?e:JSON.stringify(e);this.ws.send(t)}catch(e){}},t.getConnectionStatus=function(){return this.isConnected},t.setMaxReconnectAttempts=function(e){this.maxReconnectAttempts=e},t.scheduleReconnect=function(){var e=this;this.reconnectTimer&&clearTimeout(this.reconnectTimer);var t=Math.min(1e3*Math.pow(2,this.reconnectAttempts),3e4);this.reconnectAttempts++,this.reconnectTimer=setTimeout(function(){e.connect().catch(function(t){e.reconnectAttempts<e.maxReconnectAttempts&&e.scheduleReconnect()})},t)},t.handleMessage=function(e){try{var t=JSON.parse(e.data);this.messageHandler&&this.messageHandler(t)}catch(e){}},t.handleOpen=function(e){this.isConnected=!0,this.reconnectAttempts=0,this.onOpen&&this.onOpen(e)},t.handleClose=function(e){this.isConnected=!1,this.onClose&&this.onClose(e),this.autoReconnect&&this.reconnectAttempts<this.maxReconnectAttempts&&this.scheduleReconnect()},t.handleError=function(e){this.onError&&this.onError(e)},t.handleConnectionFailure=function(e){this.onError&&this.onError(e)},e}();exports.ProfileCategory=void 0,(Qe=exports.ProfileCategory||(exports.ProfileCategory={})).ECS="ECS",Qe.Rendering="Rendering",Qe.Physics="Physics",Qe.Audio="Audio",Qe.Network="Network",Qe.Script="Script",Qe.Memory="Memory",Qe.Animation="Animation",Qe.AI="AI",Qe.Input="Input",Qe.Loading="Loading",Qe.Custom="Custom";var Je={enabled:!1,maxFrameHistory:300,maxSampleDepth:32,collectMemory:!0,memorySampleInterval:100,detectLongTasks:!0,longTaskThreshold:50,enabledCategories:new Set(Object.values(exports.ProfileCategory))},Ke=0;var Ze=function(){function e(e){this.currentFrame=null,this.frameHistory=[],this.frameNumber=0,this.activeSamples=new Map,this.sampleStack=[],this.counters=new Map,this.callGraph=new Map,this.gcCount=0,this.previousHeapSize=0,this.longTasks=[],this.performanceObserver=null,this.config=a({},Je,e),this.config.detectLongTasks&&this.setupLongTaskObserver()}e.getInstance=function(t){return e.instance||(e.instance=new e(t)),e.instance},e.resetInstance=function(){e.instance&&(e.instance.dispose(),e.instance=null)},e.beginSample=function(t,n){return void 0===n&&(n=exports.ProfileCategory.Custom),e.getInstance().beginSample(t,n)},e.endSample=function(t){t&&e.getInstance().endSample(t)},e.measure=function(t,n,r){return void 0===r&&(r=exports.ProfileCategory.Custom),e.getInstance().measure(t,n,r)},e.measureAsync=function(){var t=n(h().m(function t(n,r,i){return h().w(function(t){for(;;)if(0===t.n)return void 0===i&&(i=exports.ProfileCategory.Custom),t.a(2,e.getInstance().measureAsync(n,r,i))},t)}));return function(e,n,r){return t.apply(this,arguments)}}(),e.beginFrame=function(){e.getInstance().beginFrame()},e.endFrame=function(){e.getInstance().endFrame()},e.incrementCounter=function(t,n,r){void 0===n&&(n=1),void 0===r&&(r=exports.ProfileCategory.Custom),e.getInstance().incrementCounter(t,n,r)},e.setGauge=function(t,n,r){void 0===r&&(r=exports.ProfileCategory.Custom),e.getInstance().setGauge(t,n,r)},e.setEnabled=function(t){e.getInstance().setEnabled(t)},e.isEnabled=function(){return e.getInstance().config.enabled},e.getCurrentFrame=function(){return e.getInstance().currentFrame},e.getFrameHistory=function(){return e.getInstance().frameHistory},e.getReport=function(t){return e.getInstance().generateReport(t)},e.reset=function(){e.getInstance().reset()};var t=e.prototype;return t.beginSample=function(e,t){if(void 0===t&&(t=exports.ProfileCategory.Custom),!this.config.enabled||!this.config.enabledCategories.has(t))return null;var n=this.sampleStack.length>0?this.sampleStack[this.sampleStack.length-1]:void 0;if(n&&this.sampleStack.length>=this.config.maxSampleDepth)return null;var r={id:"sample_"+ ++Ke+"_"+Date.now(),name:e,category:t,startTime:performance.now(),depth:this.sampleStack.length,parentId:null==n?void 0:n.id};return this.activeSamples.set(r.id,r),this.sampleStack.push(r),r},t.endSample=function(e){if(this.config.enabled&&this.activeSamples.has(e.id)){var t=performance.now(),n=t-e.startTime,r=e.parentId?this.activeSamples.get(e.parentId):void 0,i={id:e.id,name:e.name,category:e.category,startTime:e.startTime,endTime:t,duration:n,selfTime:n,parentId:e.parentId,parentName:null==r?void 0:r.name,depth:e.depth,callCount:1};this.currentFrame&&this.currentFrame.samples.push(i),this.updateCallGraph(e.name,e.category,n,r),this.activeSamples.delete(e.id);var o=this.sampleStack.indexOf(e);-1!==o&&this.sampleStack.splice(o,1)}},t.measure=function(e,t,n){void 0===n&&(n=exports.ProfileCategory.Custom);var r=this.beginSample(e,n);try{return t()}finally{r&&this.endSample(r)}},t.measureAsync=function(){var e=n(h().m(function e(t,n,r){var i;return h().w(function(e){for(;;)switch(e.p=e.n){case 0:return void 0===r&&(r=exports.ProfileCategory.Custom),i=this.beginSample(t,r),e.p=1,e.n=2,n();case 2:return e.a(2,e.v);case 3:return e.p=3,i&&this.endSample(i),e.f(3);case 4:return e.a(2)}},e,this,[[1,,3,4]])}));return function(t,n,r){return e.apply(this,arguments)}}(),t.beginFrame=function(){this.config.enabled&&(this.frameNumber++,this.currentFrame={frameNumber:this.frameNumber,startTime:performance.now(),endTime:0,duration:0,samples:[],sampleStats:[],counters:new Map(this.counters),memory:this.captureMemory(),categoryStats:new Map},this.resetFrameCounters())},t.endFrame=function(){if(this.config.enabled&&this.currentFrame){for(this.currentFrame.endTime=performance.now(),this.currentFrame.duration=this.currentFrame.endTime-this.currentFrame.startTime,this.calculateSampleStats(),this.calculateCategoryStats(),this.frameHistory.push(this.currentFrame);this.frameHistory.length>this.config.maxFrameHistory;)this.frameHistory.shift();this.sampleStack=[],this.activeSamples.clear()}},t.incrementCounter=function(e,t,n){if(void 0===t&&(t=1),void 0===n&&(n=exports.ProfileCategory.Custom),this.config.enabled){var r=this.counters.get(e);r||(r={name:e,category:n,value:0,type:"counter",history:[]},this.counters.set(e,r)),r.value+=t,r.history.push({time:performance.now(),value:r.value}),r.history.length>100&&r.history.shift()}},t.setGauge=function(e,t,n){if(void 0===n&&(n=exports.ProfileCategory.Custom),this.config.enabled){var r=this.counters.get(e);r||(r={name:e,category:n,value:0,type:"gauge",history:[]},this.counters.set(e,r)),r.value=t,r.history.push({time:performance.now(),value:t}),r.history.length>100&&r.history.shift()}},t.setEnabled=function(e){this.config.enabled=e,e&&this.config.detectLongTasks&&!this.performanceObserver&&this.setupLongTaskObserver()},t.reset=function(){this.frameHistory=[],this.currentFrame=null,this.frameNumber=0,this.activeSamples.clear(),this.sampleStack=[],this.counters.clear(),this.callGraph.clear(),this.gcCount=0,this.longTasks=[]},t.generateReport=function(e){var t,n,r=e?this.frameHistory.slice(-e):this.frameHistory;if(0===r.length)return this.createEmptyReport();var i=r.map(function(e){return e.duration}),o=[].concat(i).sort(function(e,t){return e-t}),s=this.aggregateSampleStats(r).sort(function(e,t){return t.inclusiveTime-e.inclusiveTime}).slice(0,20),a=this.aggregateCategoryStats(r),c=this.buildCallGraphFromFrames(r),u=r[0],l=r[r.length-1];return{startTime:null!==(t=null==u?void 0:u.startTime)&&void 0!==t?t:0,endTime:null!==(n=null==l?void 0:l.endTime)&&void 0!==n?n:0,totalFrames:r.length,averageFrameTime:i.reduce(function(e,t){return e+t},0)/i.length,minFrameTime:Math.min.apply(Math,i),maxFrameTime:Math.max.apply(Math,i),p95FrameTime:o[Math.floor(.95*o.length)]||0,p99FrameTime:o[Math.floor(.99*o.length)]||0,hotspots:s,callGraph:c,categoryBreakdown:a,memoryTrend:r.map(function(e){return e.memory}),longTasks:[].concat(this.longTasks)}},t.buildCallGraphFromFrames=function(e){for(var t,n=new Map,r=s(e);!(t=r()).done;)for(var i,o=s(t.value.samples);!(i=o()).done;){var a=i.value,c=n.get(a.name);if(c||(c={category:a.category,callCount:0,totalTime:0,callers:new Map,callees:new Map},n.set(a.name,c)),c.callCount++,c.totalTime+=a.duration,a.parentName){var u=c.callers.get(a.parentName)||{count:0,totalTime:0};u.count++,u.totalTime+=a.duration,c.callers.set(a.parentName,u);var l=n.get(a.parentName);l||(l={category:a.category,callCount:0,totalTime:0,callers:new Map,callees:new Map},n.set(a.parentName,l));var h=l.callees.get(a.name)||{count:0,totalTime:0};h.count++,h.totalTime+=a.duration,l.callees.set(a.name,h)}}for(var d,f=new Map,p=s(n);!(d=p()).done;){for(var m,v=d.value,y=v[0],g=v[1],_=new Map,S=s(g.callers);!(m=S()).done;){var C=m.value,E=C[0],b=C[1];_.set(E,{count:b.count,totalTime:b.count>0?b.totalTime/b.count:0})}for(var T,w=new Map,M=s(g.callees);!(T=M()).done;){var x=T.value,I=x[0],A=x[1];w.set(I,{count:A.count,totalTime:A.count>0?A.totalTime/A.count:0})}f.set(y,{name:y,category:g.category,callCount:g.callCount,totalTime:g.callCount>0?g.totalTime/g.callCount:0,callers:_,callees:w})}return f},t.getCallGraph=function(){return new Map(this.callGraph)},t.getFunctionCallInfo=function(e){var t=this.callGraph.get(e);return t?{callers:Array.from(t.callers.entries()).map(function(e){return a({name:e[0]},e[1])}),callees:Array.from(t.callees.entries()).map(function(e){return a({name:e[0]},e[1])})}:null},t.dispose=function(){this.performanceObserver&&(this.performanceObserver.disconnect(),this.performanceObserver=null),this.reset()},t.captureMemory=function(){var e=performance.now(),t=0,n=0,r=0,i=performance;return i.memory&&(t=i.memory.usedJSHeapSize||0,n=i.memory.totalJSHeapSize||0,r=i.memory.jsHeapSizeLimit||0,this.previousHeapSize>0&&t<this.previousHeapSize-1048576&&this.gcCount++,this.previousHeapSize=t),{timestamp:e,usedHeapSize:t,totalHeapSize:n,heapSizeLimit:r,utilizationPercent:r>0?t/r*100:0,gcCount:this.gcCount}},t.resetFrameCounters=function(){for(var e,t=s(this.counters.values());!(e=t()).done;){var n=e.value;"counter"===n.type&&(n.value=0)}},t.calculateSampleStats=function(){var e=this;if(this.currentFrame){for(var t,n=new Map,r=s(this.currentFrame.samples);!(t=r()).done;){var i=t.value,o=n.get(i.name);o||(o={name:i.name,category:i.category,inclusiveTime:0,exclusiveTime:0,callCount:0,averageTime:0,minTime:Number.MAX_VALUE,maxTime:0,percentOfFrame:0,percentOfParent:0,children:[],depth:i.depth},n.set(i.name,o)),o.inclusiveTime+=i.duration,o.callCount+=1,o.minTime=Math.min(o.minTime,i.duration),o.maxTime=Math.max(o.maxTime,i.duration)}for(var a,c=function(){var t=a.value;if(t.parentId){var r=e.currentFrame.samples.find(function(e){return e.id===t.parentId});if(r){var i=n.get(r.name);if(i){i.exclusiveTime=i.inclusiveTime;for(var o,c=s(e.currentFrame.samples);!(o=c()).done;){var u=o.value;u.parentId===r.id&&(i.exclusiveTime-=u.duration)}}}}},u=s(this.currentFrame.samples);!(a=u()).done;)c();for(var l,h=this.currentFrame.duration||1,d=s(n.values());!(l=d()).done;){var f=l.value;f.averageTime=f.inclusiveTime/f.callCount,f.percentOfFrame=f.inclusiveTime/h*100,0===f.exclusiveTime&&(f.exclusiveTime=f.inclusiveTime)}this.currentFrame.sampleStats=Array.from(n.values()).sort(function(e,t){return t.inclusiveTime-e.inclusiveTime})}},t.calculateCategoryStats=function(){if(this.currentFrame){for(var e,t=new Map,n=s(this.currentFrame.samples);!(e=n()).done;){var r=e.value;if(0===r.depth){var i=t.get(r.category);i||(i={totalTime:0,sampleCount:0},t.set(r.category,i)),i.totalTime+=r.duration,i.sampleCount+=1}}for(var o,c=this.currentFrame.duration||1,u=s(t);!(o=u()).done;){var l=o.value,h=l[0],d=l[1];this.currentFrame.categoryStats.set(h,a({},d,{percentOfFrame:d.totalTime/c*100}))}}},t.updateCallGraph=function(e,t,n,r){var i=this.callGraph.get(e);if(i||(i={name:e,category:t,callCount:0,totalTime:0,callers:new Map,callees:new Map},this.callGraph.set(e,i)),i.callCount++,i.totalTime+=n,r){var o=i.callers.get(r.name)||{count:0,totalTime:0};o.count++,o.totalTime+=n,i.callers.set(r.name,o);var s=this.callGraph.get(r.name);s||(s={name:r.name,category:r.category,callCount:0,totalTime:0,callers:new Map,callees:new Map},this.callGraph.set(r.name,s));var a=s.callees.get(e)||{count:0,totalTime:0};a.count++,a.totalTime+=n,s.callees.set(e,a)}},t.aggregateSampleStats=function(e){for(var t,n=new Map,r=s(e);!(t=r()).done;)for(var i,o=s(t.value.sampleStats);!(i=o()).done;){var c=i.value,u=n.get(c.name);u?(u.inclusiveTime+=c.inclusiveTime,u.exclusiveTime+=c.exclusiveTime,u.callCount+=c.callCount,u.minTime=Math.min(u.minTime,c.minTime),u.maxTime=Math.max(u.maxTime,c.maxTime)):(u=a({},c,{minTime:Number.MAX_VALUE}),n.set(c.name,u))}for(var l,h=e.reduce(function(e,t){return e+t.duration},0),d=s(n.values());!(l=d()).done;){var f=l.value;f.averageTime=f.inclusiveTime/f.callCount,f.percentOfFrame=f.inclusiveTime/h*100}return Array.from(n.values())},t.aggregateCategoryStats=function(e){for(var t,n=new Map,r=s(e);!(t=r()).done;)for(var i,o=s(t.value.categoryStats);!(i=o()).done;){var a=i.value,c=a[0],u=a[1],l=n.get(c);l||(l={totalTime:0,frameCount:0},n.set(c,l)),l.totalTime+=u.totalTime,l.frameCount++}for(var h,d=e.reduce(function(e,t){return e+t.duration},0),f=new Map,p=s(n);!(h=p()).done;){var m=h.value,v=m[0],y=m[1];f.set(v,{totalTime:y.totalTime,averageTime:y.frameCount>0?y.totalTime/y.frameCount:0,percentOfTotal:d>0?y.totalTime/d*100:0})}return f},t.setupLongTaskObserver=function(){var e=this;if("undefined"!=typeof PerformanceObserver)try{this.performanceObserver=new PerformanceObserver(function(t){for(var n,r=s(t.getEntries());!(n=r()).done;){var i,o=n.value;if(o.duration>e.config.longTaskThreshold)e.longTasks.push({startTime:o.startTime,duration:o.duration,attribution:(null===(i=o.attribution)||void 0===i?void 0:i.map(function(e){return e.name}))||[]}),e.longTasks.length>100&&e.longTasks.shift()}}),this.performanceObserver.observe({entryTypes:["longtask"]})}catch(e){}},t.createEmptyReport=function(){return{startTime:0,endTime:0,totalFrames:0,averageFrameTime:0,minFrameTime:0,maxFrameTime:0,p95FrameTime:0,p99FrameTime:0,hotspots:[],callGraph:new Map,categoryBreakdown:new Map,memoryTrend:[],longTasks:[]}},e}();Ze.instance=null;var Xe=function(){function e(){this.selectedFunction=null,this.peakMemory=0}var t=e.prototype;return t.setSelectedFunction=function(e){this.selectedFunction=e},t.collectAdvancedData=function(e){var t=Ze.getFrameHistory(),n=Ze.getCurrentFrame(),r=Ze.getReport(300),i=(null==n?void 0:n.memory)||this.getDefaultMemory();return i.usedHeapSize>this.peakMemory&&(this.peakMemory=i.usedHeapSize),{currentFrame:this.buildCurrentFrameData(n),frameTimeHistory:this.buildFrameTimeHistory(t),categoryStats:this.buildCategoryStats(n,e),hotspots:this.buildHotspots(r),callGraph:this.buildCallGraph(r),longTasks:r.longTasks,memoryTrend:this.buildMemoryTrend(r.memoryTrend),summary:this.buildSummary(r,i)}},t.collectFromLegacyMonitor=function(e){var t,n;if(!e)return this.createEmptyData();var r=(null===(t=e.getAllSystemStats)||void 0===t?void 0:t.call(e))||new Map,i=(null===(n=e.getAllSystemData)||void 0===n?void 0:n.call(e))||new Map,o=1e3*g.deltaTime,s=o>0?Math.round(1e3/o):0,a=this.buildCategoryStatsFromLegacy(r,i,o),c=this.buildHotspotsFromLegacy(r,i,o);return{currentFrame:{frameNumber:0,frameTime:o,fps:s,memory:this.getCurrentMemory()},frameTimeHistory:[],categoryStats:a,hotspots:c,callGraph:{currentFunction:this.selectedFunction,callers:[],callees:[]},longTasks:[],memoryTrend:[],summary:{totalFrames:0,averageFrameTime:o,minFrameTime:o,maxFrameTime:o,p95FrameTime:o,p99FrameTime:o,currentMemoryMB:this.getCurrentMemory().usedHeapSize/1048576,peakMemoryMB:this.peakMemory/1048576,gcCount:0,longTaskCount:0}}},t.buildCurrentFrameData=function(e){if(!e){var t=1e3*g.deltaTime;return{frameNumber:0,frameTime:t,fps:t>0?Math.round(1e3/t):0,memory:this.getCurrentMemory()}}return{frameNumber:e.frameNumber,frameTime:e.duration,fps:e.duration>0?Math.round(1e3/e.duration):0,memory:e.memory}},t.buildFrameTimeHistory=function(e){return e.map(function(e){return{frameNumber:e.frameNumber,time:e.startTime,duration:e.duration}})},t.buildCategoryStats=function(e,t){var n=[];if(e&&e.categoryStats.size>0)for(var r,i=e.duration||1,o=function(){var t=r.value,o=t[0],s=t[1],a=e.sampleStats.filter(function(e){return e.category===o}).map(function(e){return{name:e.name,inclusiveTime:e.inclusiveTime,exclusiveTime:e.exclusiveTime,callCount:e.callCount,percentOfCategory:s.totalTime>0?e.inclusiveTime/s.totalTime*100:0,percentOfFrame:e.inclusiveTime/i*100}}).sort(function(e,t){return t.inclusiveTime-e.inclusiveTime});n.push({category:o,totalTime:s.totalTime,percentOfFrame:s.percentOfFrame,sampleCount:s.sampleCount,items:a})},a=s(e.categoryStats);!(r=a()).done;)o();if(t&&0===n.length){var c,u,l=(null===(c=t.getAllSystemStats)||void 0===c?void 0:c.call(t))||new Map,h=(null===(u=t.getAllSystemData)||void 0===u?void 0:u.call(t))||new Map,d=1e3*g.deltaTime||1;return this.buildCategoryStatsFromLegacy(l,h,d)}return n.sort(function(e,t){return t.totalTime-e.totalTime})},t.buildCategoryStatsFromLegacy=function(e,t,n){for(var r,i=[],o=0,a=s(e.entries());!(r=a()).done;){var c=r.value,u=c[0],l=c[1],h=t.get(u),d=(null==h?void 0:h.executionTime)||(null==l?void 0:l.averageTime)||0;o+=d,i.push({name:u,inclusiveTime:d,exclusiveTime:d,callCount:1,percentOfCategory:0,percentOfFrame:n>0?d/n*100:0})}for(var f=0,p=i;f<p.length;f++){var m=p[f];m.percentOfCategory=o>0?m.inclusiveTime/o*100:0}return i.sort(function(e,t){return t.inclusiveTime-e.inclusiveTime}),0===i.length?[]:[{category:exports.ProfileCategory.ECS,totalTime:o,percentOfFrame:n>0?o/n*100:0,sampleCount:i.length,items:i}]},t.buildHotspots=function(e){for(var t,n=e.hotspots.reduce(function(e,t){return e+t.inclusiveTime},0)||1,r=new Set,i=new Set,o=s(e.callGraph);!(t=o()).done;){var a=t.value,c=a[0],u=a[1];if(0===u.callers.size)r.add(c);else{for(var l,h=!1,d=s(u.callers.keys());!(l=d()).done;){var f=l.value;if(e.callGraph.has(f)){h=!0,i.add(c);break}}h||r.add(c)}}for(var p,m=function(t,r,i){if(i.has(t))return null;i.add(t);var o=e.hotspots.find(function(e){return e.name===t}),a=e.callGraph.get(t);if(!o&&!a)return null;var c=(null==o?void 0:o.inclusiveTime)||(null==a?void 0:a.totalTime)||0,u=(null==o?void 0:o.exclusiveTime)||c,l=(null==o?void 0:o.callCount)||(null==a?void 0:a.callCount)||1,h=[];if(a&&r<5){for(var d,f=s(a.callees);!(d=f()).done;){var p=d.value[0],v=m(p,r+1,i);v&&h.push(v)}h.sort(function(e,t){return t.inclusiveTime-e.inclusiveTime})}return{name:t,category:(null==o?void 0:o.category)||(null==a?void 0:a.category)||exports.ProfileCategory.Custom,inclusiveTime:c,inclusiveTimePercent:c/n*100,exclusiveTime:u,exclusiveTimePercent:u/n*100,callCount:l,avgCallTime:l>0?c/l:0,depth:r,children:h.length>0?h:void 0}},v=[],y=new Set,g=s(r);!(p=g()).done;){var _=p.value,S=m(_,0,y);S&&v.push(S)}return v.sort(function(e,t){return t.inclusiveTime-e.inclusiveTime}),v.slice(0,50)},t.buildHotspotsFromLegacy=function(e,t,n){for(var r,i=[],o=s(e.entries());!(r=o()).done;){var a=r.value,c=a[0],u=a[1],l=t.get(c),h=(null==l?void 0:l.executionTime)||(null==u?void 0:u.averageTime)||0;i.push({name:c,category:exports.ProfileCategory.ECS,inclusiveTime:h,inclusiveTimePercent:n>0?h/n*100:0,exclusiveTime:h,exclusiveTimePercent:n>0?h/n*100:0,callCount:(null==u?void 0:u.executionCount)||1,avgCallTime:(null==u?void 0:u.averageTime)||h,depth:0})}return i.sort(function(e,t){return t.inclusiveTime-e.inclusiveTime}).slice(0,50)},t.buildCallGraph=function(e){if(!this.selectedFunction)return{currentFunction:null,callers:[],callees:[]};var t=e.callGraph.get(this.selectedFunction);if(!t)return{currentFunction:this.selectedFunction,callers:[],callees:[]};for(var n,r=0,i=s(t.callers.values());!(n=i()).done;){var o=n.value;r+=o.count}var a=Array.from(t.callers.entries()).map(function(e){var t=e[0],n=e[1];return{name:t,callCount:n.count,totalTime:n.totalTime,percentOfCurrent:r>0?n.count/r*100:0}}).sort(function(e,t){return t.callCount-e.callCount}),c=Array.from(t.callees.entries()).map(function(e){var n=e[0],r=e[1];return{name:n,callCount:r.count,totalTime:r.totalTime,percentOfCurrent:t.totalTime>0?r.totalTime/t.totalTime*100:0}}).sort(function(e,t){return t.totalTime-e.totalTime});return{currentFunction:this.selectedFunction,callers:a,callees:c}},t.buildMemoryTrend=function(e){return e.map(function(e){return{time:e.timestamp,usedMB:e.usedHeapSize/1048576,totalMB:e.totalHeapSize/1048576,gcCount:e.gcCount}})},t.buildSummary=function(e,t){return{totalFrames:e.totalFrames,averageFrameTime:e.averageFrameTime,minFrameTime:e.minFrameTime,maxFrameTime:e.maxFrameTime,p95FrameTime:e.p95FrameTime,p99FrameTime:e.p99FrameTime,currentMemoryMB:t.usedHeapSize/1048576,peakMemoryMB:this.peakMemory/1048576,gcCount:t.gcCount,longTaskCount:e.longTasks.length}},t.getCurrentMemory=function(){var e,t,n,r=performance,i=(null===(e=r.memory)||void 0===e?void 0:e.usedJSHeapSize)||0,o=(null===(t=r.memory)||void 0===t?void 0:t.totalJSHeapSize)||0,s=(null===(n=r.memory)||void 0===n?void 0:n.jsHeapSizeLimit)||0;return{timestamp:performance.now(),usedHeapSize:i,totalHeapSize:o,heapSizeLimit:s,utilizationPercent:s>0?i/s*100:0,gcCount:0}},t.getDefaultMemory=function(){return{timestamp:performance.now(),usedHeapSize:0,totalHeapSize:0,heapSizeLimit:0,utilizationPercent:0,gcCount:0}},t.createEmptyData=function(){return{currentFrame:{frameNumber:0,frameTime:0,fps:0,memory:this.getDefaultMemory()},frameTimeHistory:[],categoryStats:[],hotspots:[],callGraph:{currentFunction:null,callers:[],callees:[]},longTasks:[],memoryTrend:[],summary:{totalFrames:0,averageFrameTime:0,minFrameTime:0,maxFrameTime:0,p95FrameTime:0,p99FrameTime:0,currentMemoryMB:0,peakMemoryMB:0,gcCount:0,longTaskCount:0}}},e}();function $e(){return"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():function(){if("undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues){var e=new Uint8Array(16);return crypto.getRandomValues(e),e[6]=15&e[6]|64,e[8]=63&e[8]|128,function(e){var t=Array.from(e,function(e){return e.toString(16).padStart(2,"0")}).join("");return t.slice(0,8)+"-"+t.slice(8,12)+"-"+t.slice(12,16)+"-"+t.slice(16,20)+"-"+t.slice(20)}(e)}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}()}var et=268435455,tt=1048575,nt=1<<28,rt=1<<20;function it(e,t){return(t&tt)*nt+(e&et)}function ot(e){return e&et}function st(e){return Math.floor(e/nt)&tt}function at(e){return 0!==e}var ct=function(){function e(){}return e.prototype.compare=function(e,t){var n=e.updateOrder-t.updateOrder;return 0==n&&(n=e.id-t.id),n},e}(),ut=function(){function e(e,t,n){this._handle=0,this.scene=null,this._isDestroyed=!1,this._active=!0,this._tag=0,this._enabled=!0,this._updateOrder=0,this._componentMask=U.clone(U.ZERO),this._componentCache=null,this._lifecyclePolicy=0,this.name=e,this.id=t,this.persistentId=null!=n?n:$e()}var t=e.prototype;return t.setHandle=function(e){this._handle=e},t.setPersistent=function(){return this._lifecyclePolicy=1,this},t.setSceneLocal=function(){return this._lifecyclePolicy=0,this},t.setDestroyedState=function(e){this._isDestroyed=e},t._rebuildComponentCache=function(){var e,t=[];if(null!==(e=this.scene)&&void 0!==e&&e.componentStorageManager){for(var n=this._componentMask,r=K.getRegisteredCount(),i=0;i<r;i++)if(U.getBit(n,i)){var o=K.getTypeByBitIndex(i);if(o){var s=this.scene.componentStorageManager.getComponent(this.id,o);s&&t.push(s)}}this._componentCache=t}else this._componentCache=t},t.createComponent=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];var o=r(e,n);return this.addComponent(o)},t.addComponentInternal=function(e){var t=e.constructor,n=K.getBitMask(t);return U.orInPlace(this._componentMask,n),this._componentCache=null,e},t.notifyQuerySystems=function(e){this.scene&&this.scene.querySystem&&(this.scene.querySystem.updateEntity(this),this.scene.clearSystemEntityCaches(),this.scene.notifyEntityComponentChanged&&this.scene.notifyEntityComponentChanged(this,e))},t.addComponent=function(e){var t,n=e.constructor;if(!this.scene)throw new Error("Entity must be added to Scene before adding components. Use scene.createEntity() instead of new Entity()");if(!this.scene.componentStorageManager)throw new Error("Scene does not have componentStorageManager");if(this.hasComponent(n))throw new Error("Entity "+this.name+" already has component "+L(n));(this.addComponentInternal(e),this.scene.componentStorageManager.addComponent(this.id,e),e.entityId=this.id,this.scene.referenceTracker&&this.scene.referenceTracker.registerEntityScene(this.id,this.scene),this.scene.isEditorMode?this.scene.queueDeferredComponentCallback(function(){e.onAddedToEntity()}):e.onAddedToEntity(),this.scene&&this.scene.eventSystem)&&this.scene.eventSystem.emitSync("component:added",{timestamp:Date.now(),source:"Entity",entityId:this.id,entityName:this.name,entityTag:null===(t=this.tag)||void 0===t?void 0:t.toString(),componentType:L(n),component:e});return this.notifyQuerySystems(n),e},t.getComponent=function(e){var t;return this.hasComponent(e)&&null!==(t=this.scene)&&void 0!==t&&t.componentStorageManager?this.scene.componentStorageManager.getComponent(this.id,e):null},t.hasComponent=function(e){if(!K.isRegistered(e))return!1;var t=K.getBitMask(e);return U.hasAny(this._componentMask,t)},t.getOrCreateComponent=function(e){var t=this.getComponent(e);if(!t){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];t=this.createComponent.apply(this,[e].concat(r))}return t},t.markDirty=function(){if(this.scene){for(var e=this.scene.epochManager.current,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];for(var i=0,o=n;i<o.length;i++){o[i].markDirty(e)}}},t.removeComponent=function(e){var t,n,r=e.constructor;if(K.isRegistered(r)){var i,o=K.getBitIndex(r);if(U.clearBit(this._componentMask,o),this._componentCache=null,null!==(t=this.scene)&&void 0!==t&&t.componentStorageManager&&this.scene.componentStorageManager.removeComponent(this.id,r),null!==(n=this.scene)&&void 0!==n&&n.referenceTracker&&this.scene.referenceTracker.clearComponentReferences(e),e.onRemovedFromEntity&&e.onRemovedFromEntity(),e.entityId=null,this.scene&&this.scene.eventSystem)this.scene.eventSystem.emitSync("component:removed",{timestamp:Date.now(),source:"Entity",entityId:this.id,entityName:this.name,entityTag:null===(i=this.tag)||void 0===i?void 0:i.toString(),componentType:L(r),component:e});this.notifyQuerySystems(r)}},t.removeComponentByType=function(e){var t=this.getComponent(e);return t?(this.removeComponent(t),t):null},t.removeAllComponents=function(){var e=[].concat(this.components);U.clear(this._componentMask),this._componentCache=null;for(var t,n=s(e);!(t=n()).done;){var r,i=t.value,o=i.constructor;null!==(r=this.scene)&&void 0!==r&&r.componentStorageManager&&this.scene.componentStorageManager.removeComponent(this.id,o),i.onRemovedFromEntity()}this.notifyQuerySystems()},t.addComponents=function(t){for(var n,r=[],i=s(t);!(n=i()).done;){var o=n.value;try{r.push(this.addComponent(o))}catch(t){e._logger.warn("添加组件失败 "+H(o)+":",t)}}return r},t.removeComponentsByTypes=function(e){for(var t,n=[],r=s(e);!(t=r()).done;){var i=t.value;n.push(this.removeComponentByType(i))}return n},t.getComponents=function(e){for(var t,n=[],r=s(this.components);!(t=r()).done;){var i=t.value;i instanceof e&&n.push(i)}return n},t.getComponentByType=function(e){for(var t,n=s(this.components);!(t=n()).done;){var r=t.value;if(r instanceof e)return r}return null},t.onActiveChanged=function(){for(var e,t=s(this.components);!(e=t()).done;){var n=e.value;"onActiveChanged"in n&&"function"==typeof n.onActiveChanged&&n.onActiveChanged()}this.scene&&this.scene.eventSystem&&this.scene.eventSystem.emitSync("entity:activeChanged",{entity:this,active:this._active})},t.destroy=function(){this._isDestroyed||(this._isDestroyed=!0,this.scene&&this.scene.referenceTracker&&(this.scene.referenceTracker.clearReferencesTo(this.id),this.scene.referenceTracker.unregisterEntityScene(this.id)),this.removeAllComponents(),this.scene&&(this.scene.querySystem&&this.scene.querySystem.removeEntity(this),this.scene.entities&&this.scene.entities.remove(this)))},t.compareTo=function(e){return ct.prototype.compare(this,e)},t.toString=function(){return"Entity["+this.name+":"+this.id+":"+this.persistentId.slice(0,8)+"]"},t.getDebugInfo=function(){return{name:this.name,id:this.id,persistentId:this.persistentId,enabled:this._enabled,active:this._active,destroyed:this._isDestroyed,componentCount:this.components.length,componentTypes:this.components.map(function(e){return H(e)}),componentMask:U.toString(this._componentMask,2),cacheBuilt:null!==this._componentCache}},o(e,[{key:"lifecyclePolicy",get:function(){return this._lifecyclePolicy}},{key:"isPersistent",get:function(){return 1===this._lifecyclePolicy}},{key:"handle",get:function(){return this._handle}},{key:"isDestroyed",get:function(){return this._isDestroyed}},{key:"components",get:function(){return null===this._componentCache&&this._rebuildComponentCache(),this._componentCache}},{key:"active",get:function(){return this._active},set:function(e){this._active!==e&&(this._active=e,this.onActiveChanged())}},{key:"tag",get:function(){return this._tag},set:function(e){this._tag=e}},{key:"enabled",get:function(){return this._enabled},set:function(e){this._enabled=e}},{key:"updateOrder",get:function(){return this._updateOrder},set:function(e){this._updateOrder=e}},{key:"componentMask",get:function(){return this._componentMask}}])}();ut._logger=J("Entity"),ut.entityComparer=new ct;var lt=function(){function e(e){this.buffer=[],this._idToEntity=new Map,this._nameToEntities=new Map,this._entitiesToAdd=[],this._entitiesToRemove=[],this._scene=e}var t=e.prototype;return t.add=function(e){this.addImmediate(e)},t.addImmediate=function(e){this._idToEntity.has(e.id)||(this.buffer.push(e),this._idToEntity.set(e.id,e),this.updateNameIndex(e,!0))},t.remove=function(e){this.removeImmediate(e)},t.removeImmediate=function(e){var t=this.buffer.indexOf(e);-1!==t&&(this.buffer.splice(t,1),this._idToEntity.delete(e.id),this.updateNameIndex(e,!1),this._scene&&this._scene.identifierPool&&this._scene.identifierPool.checkIn(e.id))},t.removeAllEntities=function(){for(var e=[],t=this.buffer.length-1;t>=0;t--)e.push(this.buffer[t].id),this.buffer[t].destroy();if(this._scene&&this._scene.identifierPool)for(var n,r=s(e);!(n=r()).done;){var i=n.value;this._scene.identifierPool.checkIn(i)}this.buffer.length=0,this._idToEntity.clear(),this._nameToEntities.clear(),this._entitiesToAdd.length=0,this._entitiesToRemove.length=0},t.updateLists=function(){if(this._entitiesToAdd.length>0){for(var e,t=s(this._entitiesToAdd);!(e=t()).done;){var n=e.value;this.addImmediate(n)}this._entitiesToAdd.length=0}if(this._entitiesToRemove.length>0){for(var r,i=s(this._entitiesToRemove);!(r=i()).done;){var o=r.value;this.removeImmediate(o)}this._entitiesToRemove.length=0}},t.update=function(){this.updateLists()},t.findEntity=function(e){var t=this._nameToEntities.get(e);return t&&t.length>0?t[0]:null},t.findEntitiesByName=function(e){return this._nameToEntities.get(e)||[]},t.findEntityById=function(e){return this._idToEntity.get(e)||null},t.findEntitiesByTag=function(e){for(var t,n=[],r=s(this.buffer);!(t=r()).done;){var i=t.value;i.tag===e&&n.push(i)}return n},t.findEntitiesWithComponent=function(e){for(var t,n=[],r=s(this.buffer);!(t=r()).done;){var i=t.value;i.hasComponent(e)&&n.push(i)}return n},t.forEach=function(e){for(var t,n=s(this.buffer);!(t=n()).done;){e(t.value)}},t.forEachWhere=function(e,t){for(var n,r=s(this.buffer);!(n=r()).done;){var i=n.value;e(i)&&t(i)}},t.updateNameIndex=function(e,t){if(e.name)if(t){var n=this._nameToEntities.get(e.name);n||(n=[],this._nameToEntities.set(e.name,n)),n.push(e)}else{var r=this._nameToEntities.get(e.name);if(r){var i=r.indexOf(e);-1!==i&&(r.splice(i,1),0===r.length&&this._nameToEntities.delete(e.name))}}},t.reorderEntity=function(e,t){var n=this._idToEntity.get(e);if(n){var r=this.buffer.indexOf(n);if(-1!==r&&r!==t){var i=Math.max(0,Math.min(t,this.buffer.length-1));this.buffer.splice(r,1),this.buffer.splice(i,0,n)}}},t.getStats=function(){for(var e,t=0,n=s(this.buffer);!(e=n()).done;){var r=e.value;r.enabled&&!r.isDestroyed&&t++}return{totalEntities:this.buffer.length,activeEntities:t,pendingAdd:this._entitiesToAdd.length,pendingRemove:this._entitiesToRemove.length,nameIndexSize:this._nameToEntities.size}},o(e,[{key:"count",get:function(){return this.buffer.length}}])}(),ht=function(){function e(e,t){void 0===e&&(e=100),void 0===t&&(t=1024),this._nextAvailableIndex=0,this._freeIndices=[],this._generations=new Map,this._pendingRecycle=[],this._recycleDelay=100,this._stats={totalAllocated:0,totalRecycled:0,currentActive:0,memoryExpansions:0},this._recycleDelay=e,this._expansionBlockSize=t,this._preAllocateGenerations(0,this._expansionBlockSize)}var t=e.prototype;return t.checkOut=function(){var t;if(this._processDelayedRecycle(),this._freeIndices.length>0)t=this._freeIndices.pop();else{if(this._nextAvailableIndex>e.MAX_INDEX)throw new Error("实体索引已达到框架设计限制 ("+e.MAX_INDEX+")。这意味着您已经分配了超过65535个不同的实体索引。这是16位索引设计的限制,考虑优化实体回收策略或升级到64位ID设计。");t=this._nextAvailableIndex++,this._ensureGenerationCapacity(t)}var n=this._generations.get(t)||1;return this._stats.totalAllocated++,this._stats.currentActive++,this._packId(t,n)},t.checkIn=function(e){var t=this._unpackIndex(e),n=this._unpackGeneration(e);return!!this._isValidId(t,n)&&(!this._pendingRecycle.some(function(e){return e.index===t&&e.generation===n})&&(this._pendingRecycle.push({index:t,generation:n,timestamp:Date.now()}),this._stats.currentActive--,this._stats.totalRecycled++,!0))},t.isValid=function(e){var t=this._unpackIndex(e),n=this._unpackGeneration(e);return this._isValidId(t,n)},t.getStats=function(){for(var t,n=0,r=0,i=s(this._generations);!(t=i()).done;){var o=t.value,a=o[0],c=o[1];a<this._nextAvailableIndex&&(n+=c,r++)}var u=r>0?n/r:1;return{totalAllocated:this._stats.totalAllocated,totalRecycled:this._stats.totalRecycled,currentActive:this._stats.currentActive,currentlyFree:this._freeIndices.length,pendingRecycle:this._pendingRecycle.length,maxPossibleEntities:e.MAX_INDEX+1,maxUsedIndex:this._nextAvailableIndex-1,memoryUsage:this._calculateMemoryUsage(),memoryExpansions:this._stats.memoryExpansions,averageGeneration:Math.round(100*u)/100,generationStorageSize:this._generations.size}},t.forceProcessDelayedRecycle=function(){this._processDelayedRecycle(!0)},t._processDelayedRecycle=function(t){if(void 0===t&&(t=!1),0!==this._pendingRecycle.length){for(var n,r=Date.now(),i=[],o=[],a=s(this._pendingRecycle);!(n=a()).done;){var c=n.value;t||r-c.timestamp>=this._recycleDelay?i.push(c):o.push(c)}for(var u=0,l=i;u<l.length;u++){var h=l[u];if(this._isValidId(h.index,h.generation)){var d=h.generation+1;d>e.MAX_GENERATION&&(d=1),this._generations.set(h.index,d),this._freeIndices.push(h.index)}}this._pendingRecycle=o}},t._preAllocateGenerations=function(t,n){for(var r=0;r<n;r++){var i=t+r;i<=e.MAX_INDEX&&this._generations.set(i,1)}this._stats.memoryExpansions++},t._ensureGenerationCapacity=function(e){if(!this._generations.has(e)){var t=Math.floor(e/this._expansionBlockSize)*this._expansionBlockSize;this._preAllocateGenerations(t,this._expansionBlockSize)}},t._calculateMemoryUsage=function(){return 16*this._generations.size+8*this._freeIndices.length+32*this._pendingRecycle.length},t._packId=function(e,t){return t<<16|e},t._unpackIndex=function(e){return 65535&e},t._unpackGeneration=function(e){return e>>>16&65535},t._isValidId=function(e,t){if(e<0||e>=this._nextAvailableIndex)return!1;var n=this._generations.get(e);return void 0!==n&&n===t},e}();ht.MAX_INDEX=65535,ht.MAX_GENERATION=65535;var dt=function(){function e(){this._processors=[],this._isDirty=!1}var t=e.prototype;return t.setDirty=function(){this._isDirty=!0},t.add=function(e){this._processors.push(e),this.setDirty()},t.remove=function(e){var t=this._processors.indexOf(e);-1!==t&&this._processors.splice(t,1)},t.getProcessor=function(e){for(var t,n=s(this._processors);!(t=n()).done;){var r=t.value;if(r instanceof e)return r}return null},t.begin=function(){this.sortProcessors()},t.end=function(){for(var t,n=s(this._processors);!(t=n()).done;){var r=t.value;try{r.reset()}catch(t){e._logger.error("Error in processor "+te(r)+":",t)}}this._isDirty=!1,this._processors.length=0},t.update=function(){this.sortProcessors();for(var t,n=s(this._processors);!(t=n()).done;){var r=t.value;try{r.update()}catch(t){e._logger.error("Error in processor "+te(r)+":",t)}}},t.lateUpdate=function(){for(var e,t=s(this._processors);!(e=t()).done;){e.value.lateUpdate()}},t.sortProcessors=function(){this._isDirty&&(this._processors.sort(function(e,t){return e.updateOrder-t.updateOrder}),this._isDirty=!1)},o(e,[{key:"processors",get:function(){return this._processors}},{key:"count",get:function(){return this._processors.length}}])}();dt._logger=J("EntityProcessorList");var ft=function(){function e(e){if(e&&"object"==typeof e)this._value=U.clone(e);else if("number"==typeof e)this._value=U.fromNumber(e);else if("string"==typeof e){var t=parseInt(e,10);this._value=U.fromNumber(t)}else this._value=U.clone(U.ZERO)}var t=e.prototype;return t.set=function(e){if(e<0)throw new Error("Bit index cannot be negative");U.setBit(this._value,e)},t.clear=function(e){if(e<0)throw new Error("Bit index cannot be negative");U.clearBit(this._value,e)},t.get=function(e){return U.getBit(this._value,e)},t.containsAll=function(e){return U.hasAll(this._value,e._value)},t.intersects=function(e){return U.hasAny(this._value,e._value)},t.excludes=function(e){return U.hasNone(this._value,e._value)},t.clearAll=function(){U.clear(this._value)},t.isEmpty=function(){return U.isZero(this._value)},t.cardinality=function(){return U.popCount(this._value)},t.and=function(t){var n=new e;return U.copy(this._value,n._value),U.andInPlace(n._value,t._value),n},t.or=function(t){var n=new e;return U.copy(this._value,n._value),U.orInPlace(n._value,t._value),n},t.xor=function(t){var n=new e;return U.copy(this._value,n._value),U.xorInPlace(n._value,t._value),n},t.not=function(t){void 0===t&&(t=64),t>64&&(t=64);var n=new e;if(U.copy(this._value,n._value),t<=32){var r=(1<<t)-1;n._value.base[D.LOW]=~n._value.base[D.LOW]&r,n._value.base[D.HIGH]=0}else if(n._value.base[D.LOW]=~n._value.base[D.LOW],t<64){var i=(1<<t-32)-1;n._value.base[D.HIGH]=~n._value.base[D.HIGH]&i}else n._value.base[D.HIGH]=~n._value.base[D.HIGH];return n},t.copyFrom=function(e){U.copy(e._value,this._value)},t.clone=function(){return new e(this._value)},t.getValue=function(){return this._value},t.setValue=function(e){if("object"==typeof e)U.copy(e,this._value);else if("number"==typeof e)this._value=U.fromNumber(e);else{var t=parseInt(e,10);this._value=U.fromNumber(t)}},t.toString=function(){for(var e=[],t=0;t<64;t++)this.get(t)&&e.push(t.toString());return"Bits["+e.join(", ")+"]"},t.toBinaryString=function(e){void 0===e&&(e=0),0==e&&(e=64+(this._value.segments?64*this._value.segments.length:0));for(var t="",n=e-1;n>=0;n--)t+=this.get(n)?"1":"0",n%8==0&&n>0&&(t+=" ");return t},t.toHexString=function(){return U.toString(this._value,16)},e.fromBinaryString=function(t){var n,r=t.replace(/\s/g,"");if(r.length<=32){n={base:[parseInt(r,2)>>>0,0]}}else{var i=r.substring(r.length-32),o=r.substring(0,r.length-32);n={base:[parseInt(i,2)>>>0,parseInt(o,2)>>>0]}}return new e(n)},e.fromHexString=function(t){var n,r=t.replace(/^0x/i,"");if(r.length<=8){n={base:[parseInt(r,16)>>>0,0]}}else{var i=r.substring(r.length-8),o=r.substring(0,r.length-8);n={base:[parseInt(i,16)>>>0,parseInt(o,16)>>>0]}}return new e(n)},t.equals=function(e){return U.equals(this._value,e._value)},t.getHighestBitIndex=function(){if(U.isZero(this._value))return-1;if(0!==this._value.base[D.HIGH])for(var e=31;e>=0;e--)if(this._value.base[D.HIGH]&1<<e)return e+32;for(var t=31;t>=0;t--)if(this._value.base[D.LOW]&1<<t)return t;return-1},t.getLowestBitIndex=function(){if(U.isZero(this._value))return-1;for(var e=0;e<32;e++)if(this._value.base[D.LOW]&1<<e)return e;for(var t=0;t<32;t++)if(this._value.base[D.HIGH]&1<<t)return t+32;return-1},e}(),pt=function(){function e(){this._dense=[],this._sparse=new Map}var t=e.prototype;return t.add=function(e){if(this._sparse.has(e))return!1;var t=this._dense.length;return this._dense.push(e),this._sparse.set(e,t),!0},t.remove=function(e){var t=this._sparse.get(e);if(void 0===t)return!1;var n=this._dense.length-1;if(t!==n){var r=this._dense[n];this._dense[t]=r,this._sparse.set(r,t)}return this._dense.pop(),this._sparse.delete(e),!0},t.has=function(e){return this._sparse.has(e)},t.getIndex=function(e){return this._sparse.get(e)},t.getByIndex=function(e){return this._dense[e]},t.forEach=function(e){for(var t=0;t<this._dense.length;t++)e(this._dense[t],t)},t.map=function(e){for(var t=[],n=0;n<this._dense.length;n++)t.push(e(this._dense[n],n));return t},t.filter=function(e){for(var t=[],n=0;n<this._dense.length;n++)e(this._dense[n],n)&&t.push(this._dense[n]);return t},t.find=function(e){for(var t=0;t<this._dense.length;t++)if(e(this._dense[t],t))return this._dense[t]},t.some=function(e){for(var t=0;t<this._dense.length;t++)if(e(this._dense[t],t))return!0;return!1},t.every=function(e){for(var t=0;t<this._dense.length;t++)if(!e(this._dense[t],t))return!1;return!0},t.getDenseArray=function(){return[].concat(this._dense)},t.getDenseArrayUnsafe=function(){return this._dense},t.clear=function(){this._dense.length=0,this._sparse.clear()},t.toArray=function(){return[].concat(this._dense)},t.toSet=function(){return new Set(this._dense)},t.getMemoryStats=function(){var e=8*this._dense.length,t=16*this._sparse.size;return{denseArraySize:e,sparseMapSize:t,totalMemory:e+t}},t.validate=function(){if(this._dense.length!==this._sparse.size)return!1;for(var e=0;e<this._dense.length;e++){var t=this._dense[e];if(this._sparse.get(t)!==e)return!1}for(var n,r=s(this._sparse);!(n=r()).done;){var i=n.value,o=i[0],a=i[1];if(a>=this._dense.length||this._dense[a]!==o)return!1}return!0},o(e,[{key:"size",get:function(){return this._dense.length}},{key:"isEmpty",get:function(){return 0===this._dense.length}}])}(),mt=function(e){function t(){return e.call(this)||this}return u(t,e),t.prototype.reset=function(){this.clear()},t}(m(Set)),vt=function(){function e(){this._componentMasks=[],this._componentToEntities=new Map,this._entities=new pt}var t=e.prototype;return t.addEntity=function(e){this._entities.has(e)&&this.removeEntity(e);for(var t,n=U.clone(U.ZERO),r=new Set,i=s(e.components);!(t=i()).done;){var o=t.value.constructor;r.add(o);var a=K.getBitMask(o);U.orInPlace(n,a)}this._entities.add(e);for(var c=this._entities.getIndex(e);this._componentMasks.length<=c;)this._componentMasks.push(U.clone(U.ZERO));this._componentMasks[c]=n,this.updateComponentMappings(e,r,!0)},t.removeEntity=function(e){var t=this._entities.getIndex(e);if(void 0!==t){var n=this.getEntityComponentTypes(e);this.updateComponentMappings(e,n,!1),this._entities.remove(e);var r=this._componentMasks.length-1;t!==r&&(this._componentMasks[t]=this._componentMasks[r]),this._componentMasks.pop()}},t.queryByComponent=function(e){var t=this._componentToEntities.get(e);return t?new Set(t):new Set},t.queryMultipleAnd=function(t){var n=this;if(0===t.length)return new Set;if(1===t.length)return this.queryByComponent(t[0]);for(var r,i=U.clone(U.ZERO),o=s(t);!(r=o()).done;){var a=r.value;if(!K.isRegistered(a))return new Set;var c=K.getBitMask(a);U.orInPlace(i,c)}var u=e._entitySetPool.obtain();return this._entities.forEach(function(e,t){var r=n._componentMasks[t];U.hasAll(r,i)&&u.add(e)}),u},t.queryMultipleOr=function(t){var n=this;if(0===t.length)return new Set;if(1===t.length)return this.queryByComponent(t[0]);for(var r,i=U.clone(U.ZERO),o=s(t);!(r=o()).done;){var a=r.value;if(K.isRegistered(a)){var c=K.getBitMask(a);U.orInPlace(i,c)}}if(U.equals(i,U.ZERO))return new Set;var u=e._entitySetPool.obtain();return this._entities.forEach(function(e,t){var r=n._componentMasks[t];U.hasAny(r,i)&&u.add(e)}),u},t.hasComponent=function(e,t){var n=this._entities.getIndex(e);if(void 0===n)return!1;if(!K.isRegistered(t))return!1;var r=this._componentMasks[n],i=K.getBitMask(t);return U.hasAny(r,i)},t.getEntityMask=function(e){var t=this._entities.getIndex(e);if(void 0!==t)return this._componentMasks[t]},t.getAllEntities=function(){return this._entities.toArray()},t.forEach=function(e){var t=this;this._entities.forEach(function(n,r){e(n,t._componentMasks[r],r)})},t.clear=function(){this._entities.clear(),this._componentMasks.length=0;for(var t,n=s(this._componentToEntities.values());!(t=n()).done;){var r=t.value;e._entitySetPool.release(r)}this._componentToEntities.clear()},t.getMemoryStats=function(){for(var e,t=this._entities.getMemoryStats(),n=16*this._componentMasks.length,r=16*this._componentToEntities.size,i=s(this._componentToEntities.values());!(e=i()).done;){r+=8*e.value.size}return{entitiesMemory:t.totalMemory,masksMemory:n,mappingsMemory:r,totalMemory:t.totalMemory+n+r}},t.validate=function(){if(!this._entities.validate())return!1;if(this._componentMasks.length!==this._entities.size)return!1;for(var e,t=new Set,n=s(this._componentToEntities.values());!(e=n()).done;)for(var r,i=s(e.value);!(r=i()).done;){var o=r.value;t.add(o)}for(var a,c=s(t);!(a=c()).done;){var u=a.value;if(!this._entities.has(u))return!1}return!0},t.getEntityComponentTypes=function(e){for(var t,n=new Set,r=s(e.components);!(t=r()).done;){var i=t.value;n.add(i.constructor)}return n},t.updateComponentMappings=function(t,n,r){for(var i,o=s(n);!(i=o()).done;){var a=i.value,c=this._componentToEntities.get(a);r?(c||(c=e._entitySetPool.obtain(),this._componentToEntities.set(a,c)),c.add(t)):c&&(c.delete(t),0===c.size&&(this._componentToEntities.delete(a),e._entitySetPool.release(c)))}},o(e,[{key:"size",get:function(){return this._entities.size}},{key:"isEmpty",get:function(){return this._entities.isEmpty}}])}();vt._entitySetPool=O.getPool(mt,50,512);var yt,gt=function(){function e(){this.buckets=new Map,this._size=0}var t=e.prototype;return t.murmur32=function(e,t){var n=t>>>0,r=function(e){e=(e=Math.imul(e,3432918353)>>>0)<<15|e>>>17,e=Math.imul(e,461845907)>>>0,n=(n^=e)<<13|n>>>19,n=Math.imul(n,5)+3864292196>>>0};if(r(e.base[0]>>>0),r(e.base[1]>>>0),e.segments)for(var i,o=s(e.segments);!(i=o()).done;){var a=i.value;r(a[0]>>>0),r(a[1]>>>0)}return n^=e.segments?8*e.segments.length:8,n^=n>>>16,n=Math.imul(n,2246822507)>>>0,n^=n>>>13,n=Math.imul(n,3266489909)>>>0,(n^=n>>>16)>>>0},t.getHashes=function(e){return[this.murmur32(e,2538058380),this.murmur32(e,305419896)]},t.set=function(e,t){var n=this.getHashes(e),r=n[0],i=n[1],o=this.buckets.get(r);o||(o=[],this.buckets.set(r,o));for(var s=0;s<o.length;s++)if(o[s][0]===i)return o[s][1]=t,this;return o.push([i,t]),this._size++,this},t.get=function(e){var t=this.getHashes(e),n=t[0],r=t[1],i=this.buckets.get(n);if(i)for(var o=0;o<i.length;o++)if(i[o][0]===r)return i[o][1]},t.has=function(e){return void 0!==this.get(e)},t.delete=function(e){var t=this.getHashes(e),n=t[0],r=t[1],i=this.buckets.get(n);if(!i)return!1;for(var o=0;o<i.length;o++)if(i[o][0]===r)return i.splice(o,1),this._size--,0===i.length&&this.buckets.delete(n),!0;return!1},t.clear=function(){this.buckets.clear(),this._size=0},t.entries=h().m(function e(){var t,n,r,i,o,a,c,u;return h().w(function(e){for(;;)switch(e.n){case 0:t=s(this.buckets);case 1:if((n=t()).done){e.n=5;break}(r=n.value)[0],i=r[1],o=s(i);case 2:if((a=o()).done){e.n=4;break}return(c=a.value)[0],u=c[1],e.n=3,[void 0,u];case 3:e.n=2;break;case 4:e.n=1;break;case 5:return e.a(2)}},e,this)}),t.values=h().m(function e(){var t,n,r,i,o,a,c;return h().w(function(e){for(;;)switch(e.n){case 0:t=s(this.buckets.values());case 1:if((n=t()).done){e.n=5;break}r=n.value,i=s(r);case 2:if((o=i()).done){e.n=4;break}return(a=o.value)[0],c=a[1],e.n=3,c;case 3:e.n=2;break;case 4:e.n=1;break;case 5:return e.a(2)}},e,this)}),o(e,[{key:"size",get:function(){return this._size}},{key:"innerBuckets",get:function(){return this.buckets}}])}(),_t=function(){function e(){this._archetypes=new gt,this._entityToArchetype=new Map,this._componentToArchetypes=new Map,this._entityComponentTypesCache=new Map,this._allArchetypes=[]}var t=e.prototype;return t.addEntity=function(e){var t=this.getEntityComponentTypes(e),n=this.generateArchetypeId(t),r=this._archetypes.get(n);r||(r=this.createArchetype(t)),r.entities.add(e),this._entityToArchetype.set(e,r)},t.removeEntity=function(e){var t=this._entityToArchetype.get(e);t&&(t.entities.delete(e),this._entityComponentTypesCache.delete(e),this._entityToArchetype.delete(e))},t.updateEntity=function(e){var t=this._entityToArchetype.get(e);this._entityComponentTypesCache.delete(e);var n=this.getEntityComponentTypes(e),r=this.generateArchetypeId(n);if(!t||t.id!==r){t&&t.entities.delete(e);var i=this._archetypes.get(r);i||(i=this.createArchetype(n)),i.entities.add(e),this._entityToArchetype.set(e,i)}},t.queryArchetypes=function(e,t){void 0===t&&(t="AND");var n=[],r=0;if("AND"===t){if(0===e.length){for(var i,o=s(this._allArchetypes);!(i=o()).done;){var a=i.value;n.push(a),r+=a.entities.size}return{archetypes:n,totalEntities:r}}if(1===e.length){var c=this._componentToArchetypes.get(e[0]);if(c)for(var u,l=s(c);!(u=l()).done;){var h=u.value;n.push(h),r+=h.entities.size}return{archetypes:n,totalEntities:r}}for(var d,f,p=1/0,m=s(e);!(f=m()).done;){var v=f.value,y=this._componentToArchetypes.get(v);if(!y||0===y.size)return{archetypes:[],totalEntities:0};y.size<p&&(p=y.size,d=y)}var g=this.generateArchetypeId(e);if(d)for(var _,S=s(d);!(_=S()).done;){var C=_.value;U.hasAll(C.id,g)&&(n.push(C),r+=C.entities.size)}}else{for(var E,b=new Set,T=s(e);!(E=T()).done;){var w=E.value,M=this._componentToArchetypes.get(w);if(M)for(var x,I=s(M);!(x=I()).done;){var A=x.value;b.add(A)}}for(var k,P=s(b);!(k=P()).done;){var O=k.value;n.push(O),r+=O.entities.size}}return{archetypes:n,totalEntities:r}},t.getEntityArchetype=function(e){return this._entityToArchetype.get(e)},t.getAllArchetypes=function(){return this._allArchetypes.slice()},t.getEntitiesByComponent=function(e){var t=this._componentToArchetypes.get(e);if(!t||0===t.size)return[];for(var n,r=[],i=s(t);!(n=i()).done;)for(var o,a=s(n.value.entities);!(o=a()).done;){var c=o.value;r.push(c)}return r},t.clear=function(){this._archetypes.clear(),this._entityToArchetype.clear(),this._componentToArchetypes.clear(),this._entityComponentTypesCache.clear(),this._allArchetypes=[]},t.updateAllArchetypeArrays=function(){this._allArchetypes=[];for(var e,t=s(this._archetypes.values());!(e=t()).done;){var n=e.value;this._allArchetypes.push(n)}},t.getEntityComponentTypes=function(e){var t=this._entityComponentTypesCache.get(e);return t||(t=e.components.map(function(e){return e.constructor}),this._entityComponentTypesCache.set(e,t)),t},t.generateArchetypeId=function(e){for(var t,n=U.clone(U.ZERO),r=s(e);!(t=r()).done;){var i=t.value,o=K.getBitMask(i);U.orInPlace(n,o)}return n},t.createArchetype=function(e){var t=this.generateArchetypeId(e),n={id:t,componentTypes:[].concat(e),entities:new Set};this._archetypes.set(t,n),this.updateAllArchetypeArrays();for(var r,i=s(e);!(r=i()).done;){var o=r.value,a=this._componentToArchetypes.get(o);a||(a=new Set,this._componentToArchetypes.set(o,a)),a.add(n)}return n},e}();!function(e){e.ALL="all",e.ANY="any",e.NONE="none"}(yt||(yt={}));var St,Ct=J("ReactiveQuery");exports.ReactiveQueryChangeType=void 0,(St=exports.ReactiveQueryChangeType||(exports.ReactiveQueryChangeType={})).ADDED="added",St.REMOVED="removed",St.BATCH_UPDATE="batch_update";var Et=function(){function e(e,t){var n,r,i;void 0===t&&(t={}),this._entities=[],this._entityIdSet=new Set,this._snapshot=null,this._listeners=[],this._active=!0,this._condition=e,this._config={enableBatchMode:null===(n=t.enableBatchMode)||void 0===n||n,batchDelay:null!==(r=t.batchDelay)&&void 0!==r?r:16,debug:null!==(i=t.debug)&&void 0!==i&&i},this._id=this.generateQueryId(),this._batchChanges={added:[],removed:[],timer:null},this._config.debug&&Ct.debug("创建ReactiveQuery: "+this._id)}var t=e.prototype;return t.generateQueryId=function(){return this._condition.type+":"+this._condition.componentTypes.map(function(e){return e.name}).sort().join(",")},t.subscribe=function(e){var t=this;if(!this._active)throw new Error("Cannot subscribe to disposed ReactiveQuery "+this._id);if("function"!=typeof e)throw new TypeError("Listener must be a function");return this._listeners.push(e),this._config.debug&&Ct.debug("订阅ReactiveQuery: "+this._id+", 监听器数量: "+this._listeners.length),function(){var n=t._listeners.indexOf(e);-1!==n&&t._listeners.splice(n,1)}},t.unsubscribeAll=function(){this._listeners.length=0},t.getEntities=function(){return null!==this._snapshot||(this._snapshot=[].concat(this._entities)),this._snapshot},t.matches=function(e){var t=e.componentMask;switch(this._condition.type){case yt.ALL:return U.hasAll(t,this._condition.mask);case yt.ANY:return U.hasAny(t,this._condition.mask);case yt.NONE:return U.hasNone(t,this._condition.mask);default:return!1}},t.notifyEntityAdded=function(e){this._active&&this.matches(e)&&(this._entityIdSet.has(e.id)||(this._entities.push(e),this._entityIdSet.add(e.id),this._snapshot=null,this._config.enableBatchMode?this.addToBatch("added",e):this.notifyListeners({type:exports.ReactiveQueryChangeType.ADDED,entity:e}),this._config.debug&&Ct.debug("ReactiveQuery "+this._id+": 实体添加 "+e.name+"("+e.id+")")))},t.notifyEntityRemoved=function(e){if(this._active&&this._entityIdSet.has(e.id)){var t=this._entities.indexOf(e);-1!==t&&this._entities.splice(t,1),this._entityIdSet.delete(e.id),this._snapshot=null,this._config.enableBatchMode?this.addToBatch("removed",e):this.notifyListeners({type:exports.ReactiveQueryChangeType.REMOVED,entity:e}),this._config.debug&&Ct.debug("ReactiveQuery "+this._id+": 实体移除 "+e.name+"("+e.id+")")}},t.notifyEntityChanged=function(e){if(this._active){var t=this._entityIdSet.has(e.id),n=this.matches(e);t&&!n?this.notifyEntityRemoved(e):!t&&n&&this.notifyEntityAdded(e)}},t.initializeWith=function(e){this._entities.length=0,this._entityIdSet.clear(),this._snapshot=null;for(var t,n=s(e);!(t=n()).done;){var r=t.value;this.matches(r)&&(this._entities.push(r),this._entityIdSet.add(r.id))}this._config.debug&&Ct.debug("ReactiveQuery "+this._id+": 初始化 "+this._entities.length+" 个实体")},t.addToBatch=function(e,t){var n=this;"added"===e?this._batchChanges.added.push(t):this._batchChanges.removed.push(t),null===this._batchChanges.timer&&(this._batchChanges.timer=setTimeout(function(){n.flushBatchChanges()},this._config.batchDelay))},t.flushBatchChanges=function(){if(0!==this._batchChanges.added.length||0!==this._batchChanges.removed.length){var e=[].concat(this._batchChanges.added),t=[].concat(this._batchChanges.removed);this._batchChanges.added.length=0,this._batchChanges.removed.length=0,this._batchChanges.timer=null,this.notifyListeners({type:exports.ReactiveQueryChangeType.BATCH_UPDATE,added:e,removed:t,entities:this._entities}),this._config.debug&&Ct.debug("ReactiveQuery "+this._id+": 批量更新 +"+e.length+" -"+t.length)}else this._batchChanges.timer=null},t.notifyListeners=function(e){for(var t,n=s([].concat(this._listeners));!(t=n()).done;){var r=t.value;try{r(e)}catch(e){Ct.error("ReactiveQuery "+this._id+": 监听器执行出错",e)}}},t.pause=function(){this._active=!1,null!==this._batchChanges.timer&&(clearTimeout(this._batchChanges.timer),this._batchChanges.timer=null),this._batchChanges.added.length=0,this._batchChanges.removed.length=0},t.resume=function(){this._active=!0},t.dispose=function(){null!==this._batchChanges.timer&&(clearTimeout(this._batchChanges.timer),this._batchChanges.timer=null),this._batchChanges.added.length=0,this._batchChanges.removed.length=0,this._active=!1,this.unsubscribeAll(),this._entities.length=0,this._entityIdSet.clear(),this._snapshot=null,this._config.debug&&Ct.debug("ReactiveQuery "+this._id+": 已销毁")},o(e,[{key:"count",get:function(){return this._entities.length}},{key:"condition",get:function(){return this._condition}},{key:"id",get:function(){return this._id}},{key:"active",get:function(){return this._active}},{key:"listenerCount",get:function(){return this._listeners.length}}])}(),bt=function(){function e(e){this._lastVersion=-1,this._cachedEntities=[],this._querySystem=e;for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this._componentTypes=n}var t=e.prototype;return t._refreshCache=function(){var e=this._querySystem.version;if(this._lastVersion!==e){var t,n=(t=this._querySystem).queryAll.apply(t,this._componentTypes);this._cachedEntities=n.entities,this._lastVersion=e}},t.forEach=function(e){for(var t=this.entities,n=this._componentTypes,r=n.length,i=0,o=t.length;i<o;i++){for(var s=t[i],a=new Array(r),c=0;c<r;c++){var u=s.getComponent(n[c]);u&&(a[c]=u)}e.apply(void 0,[s].concat(a))}},t.forEachChanged=function(e,t){for(var n=this.entities,r=this._componentTypes,i=r.length,o=0,s=n.length;o<s;o++){for(var a=n[o],c=new Array(i),u=!1,l=0;l<i;l++){var h=a.getComponent(r[l]);h&&(c[l]=h,h.lastWriteEpoch>e&&(u=!0))}u&&t.apply(void 0,[a].concat(c))}},t.first=function(){var e=this.entities;if(0===e.length)return null;for(var t,n=e[0],r=[],i=s(this._componentTypes);!(t=i()).done;){var o=t.value,a=n.getComponent(o);if(!a)return null;r.push(a)}return[n].concat(r)},t.toArray=function(){var e=[];return this.forEach(function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];e.push([t].concat(r))}),e},t.map=function(e){var t=[];return this.forEach(function(n){for(var r=arguments.length,i=new Array(r>1?r-1:0),o=1;o<r;o++)i[o-1]=arguments[o];t.push(e.apply(void 0,[n].concat(i)))}),t},t.filter=function(e){var t=[];return this.forEach(function(n){for(var r=arguments.length,i=new Array(r>1?r-1:0),o=1;o<r;o++)i[o-1]=arguments[o];e.apply(void 0,[n].concat(i))&&t.push(n)}),t},t.find=function(e){for(var t=this.entities,n=this._componentTypes,r=n.length,i=0,o=t.length;i<o;i++){for(var s=t[i],a=new Array(r),c=0;c<r;c++){var u=s.getComponent(n[c]);u&&(a[c]=u)}if(e.apply(void 0,[s].concat(a)))return s}},t.any=function(){return this.count>0},t.empty=function(){return 0===this.count},o(e,[{key:"componentTypes",get:function(){return this._componentTypes}},{key:"entities",get:function(){return this._refreshCache(),this._cachedEntities}},{key:"count",get:function(){return this.entities.length}}])}(),Tt=function(){function e(){this._logger=J("QuerySystem"),this._entities=[],this._version=0,this._queryCache=new Map,this._cacheMaxSize=1e3,this._cacheTimeout=5e3,this._componentMaskCache=new Map,this._queryStats={totalQueries:0,cacheHits:0,indexHits:0,linearScans:0,archetypeHits:0,dirtyChecks:0},this._reactiveQueries=new Map,this._reactiveQueriesByComponent=new Map,this._entityIndex={byTag:new Map,byName:new Map},this._archetypeSystem=new _t}var t=e.prototype;return t.setEntities=function(e){this._entities=e,this.clearQueryCache(),this.clearReactiveQueries(),this.rebuildIndexes()},t.addEntity=function(e,t){void 0===t&&(t=!1),this._entities.includes(e)||(this._entities.push(e),this.addEntityToIndexes(e),this._archetypeSystem.addEntity(e),this.notifyReactiveQueriesEntityAdded(e),t||this.clearQueryCache(),this._version++)},t.addEntities=function(e){if(0!==e.length){for(var t,n=new Set(this._entities.map(function(e){return e.id})),r=0,i=s(e);!(t=i()).done;){var o=t.value;n.has(o.id)||(this._entities.push(o),this.addEntityToIndexes(o),this._archetypeSystem.addEntity(o),n.add(o.id),r++)}r>0&&this.clearQueryCache()}},t.addEntitiesUnchecked=function(e){if(0!==e.length){for(var t,n=s(e);!(t=n()).done;){var r=t.value;this._entities.push(r)}for(var i,o=s(e);!(i=o()).done;){var a=i.value;this.addEntityToIndexes(a),this._archetypeSystem.addEntity(a)}this.clearQueryCache()}},t.removeEntity=function(e){var t=this._entities.indexOf(e);if(-1!==t){for(var n,r=[],i=s(e.components);!(n=i()).done;){var o=n.value;r.push(o.constructor)}this._entities.splice(t,1),this.removeEntityFromIndexes(e),this._archetypeSystem.removeEntity(e),r.length>0?this.notifyReactiveQueriesEntityRemoved(e,r):this.notifyReactiveQueriesEntityRemovedFallback(e),this.clearQueryCache(),this._version++}},t.updateEntity=function(e){this._entities.includes(e)?(this.removeEntityFromIndexes(e),this._archetypeSystem.updateEntity(e),this.addEntityToIndexes(e),this.notifyReactiveQueriesEntityChanged(e),this.clearQueryCache(),this._version++):this.addEntity(e)},t.addEntityToIndexes=function(e){var t=e.tag;void 0!==t&&(this._entityIndex.byTag.get(t)||this.createAndSetTagIndex(t)).add(e);var n=e.name;n&&(this._entityIndex.byName.get(n)||this.createAndSetNameIndex(n)).add(e)},t.createAndSetTagIndex=function(e){var t=new Set;return this._entityIndex.byTag.set(e,t),t},t.createAndSetNameIndex=function(e){var t=new Set;return this._entityIndex.byName.set(e,t),t},t.removeEntityFromIndexes=function(e){if(void 0!==e.tag){var t=this._entityIndex.byTag.get(e.tag);t&&(t.delete(e),0===t.size&&this._entityIndex.byTag.delete(e.tag))}if(e.name){var n=this._entityIndex.byName.get(e.name);n&&(n.delete(e),0===n.size&&this._entityIndex.byName.delete(e.name))}},t.rebuildIndexes=function(){this._entityIndex.byTag.clear(),this._entityIndex.byName.clear(),this._archetypeSystem.clear();for(var e,t=s(this._entities);!(e=t()).done;){var n=e.value;this.addEntityToIndexes(n),this._archetypeSystem.addEntity(n)}},t.queryAll=function(){var e=performance.now();this._queryStats.totalQueries++;for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];var i=this.getOrCreateReactiveQuery(yt.ALL,n).getEntities();return this._queryStats.cacheHits++,{entities:i,count:i.length,executionTime:performance.now()-e,fromCache:!0}},t.queryAny=function(){var e=performance.now();this._queryStats.totalQueries++;for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];var i=this.getOrCreateReactiveQuery(yt.ANY,n).getEntities();return this._queryStats.cacheHits++,{entities:i,count:i.length,executionTime:performance.now()-e,fromCache:!0}},t.queryNone=function(){var e=performance.now();this._queryStats.totalQueries++;for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];var i=this.getOrCreateReactiveQuery(yt.NONE,n).getEntities();return this._queryStats.cacheHits++,{entities:i,count:i.length,executionTime:performance.now()-e,fromCache:!0}},t.queryByTag=function(e){var t=performance.now();this._queryStats.totalQueries++;var n="tag:"+e,r=this.getFromCache(n);if(r)return this._queryStats.cacheHits++,{entities:r,count:r.length,executionTime:performance.now()-t,fromCache:!0};this._queryStats.indexHits++;var i=Array.from(this._entityIndex.byTag.get(e)||[]);return this.addToCache(n,i),{entities:i,count:i.length,executionTime:performance.now()-t,fromCache:!1}},t.queryByName=function(e){var t=performance.now();this._queryStats.totalQueries++;var n="name:"+e,r=this.getFromCache(n);if(r)return this._queryStats.cacheHits++,{entities:r,count:r.length,executionTime:performance.now()-t,fromCache:!0};this._queryStats.indexHits++;var i=Array.from(this._entityIndex.byName.get(e)||[]);return this.addToCache(n,i),{entities:i,count:i.length,executionTime:performance.now()-t,fromCache:!1}},t.queryChangedSince=function(e){var t=performance.now();this._queryStats.totalQueries++,this._queryStats.dirtyChecks++;for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];for(var o,a=[],c=s(this.queryAll.apply(this,r).entities);!(o=c()).done;){for(var u,l=o.value,h=!1,d=s(r);!(u=d()).done;){var f=u.value,p=l.getComponent(f);if(p&&p.lastWriteEpoch>e){h=!0;break}}h&&a.push(l)}return{entities:a,count:a.length,executionTime:performance.now()-t,fromCache:!1}},t.queryByComponent=function(e){var t=performance.now();this._queryStats.totalQueries++;var n=this.generateCacheKey("component",[e]),r=this.getFromCache(n);if(r)return this._queryStats.cacheHits++,{entities:r,count:r.length,executionTime:performance.now()-t,fromCache:!0};this._queryStats.indexHits++;var i=this._archetypeSystem.getEntitiesByComponent(e);return this.addToCache(n,i),{entities:i,count:i.length,executionTime:performance.now()-t,fromCache:!1}},t.getFromCache=function(e){var t=this._queryCache.get(e);return t?Date.now()-t.timestamp>this._cacheTimeout||t.version!==this._version?(this._queryCache.delete(e),null):(t.hitCount++,t.entities):null},t.addToCache=function(e,t){this._queryCache.size>=this._cacheMaxSize&&this.cleanupCache(),this._queryCache.set(e,{entities:t,timestamp:Date.now(),hitCount:0,version:this._version})},t.cleanupCache=function(){for(var e,t=Date.now(),n=s(this._queryCache.entries());!(e=n()).done;){var r=e.value,i=r[0];t-r[1].timestamp>this._cacheTimeout&&this._queryCache.delete(i)}if(this._queryCache.size>=this._cacheMaxSize){for(var o,a=1/0,c="",u=1/0,l=s(this._queryCache.entries());!(o=l()).done;){var h=o.value,d=h[0],f=h[1];(f.hitCount<a||f.hitCount===a&&f.timestamp<u)&&(a=f.hitCount,c=d,u=f.timestamp)}c&&this._queryCache.delete(c)}},t.clearQueryCache=function(){this._queryCache.clear(),this._componentMaskCache.clear()},t.clearReactiveQueries=function(){for(var e,t=s(this._reactiveQueries.values());!(e=t()).done;){e.value.dispose()}this._reactiveQueries.clear(),this._reactiveQueriesByComponent.clear()},t.generateCacheKey=function(e,t){return 1===t.length?e+":"+L(t[0]):e+":"+t.map(function(e){return L(e)}).sort().join(",")},t.clearCache=function(){this.clearQueryCache(),this.clearReactiveQueries()},t.compile=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return r(bt,[this].concat(t))},t.createReactiveQuery=function(e,t){if(!e||0===e.length)throw new Error("组件类型列表不能为空");var n=this.createComponentMask(e),r={type:yt.ALL,componentTypes:e,mask:n},i=new Et(r,t),o=this.executeTraditionalQuery(yt.ALL,e);i.initializeWith(o);var a=this.generateCacheKey("all",e);this._reactiveQueries.set(a,i);for(var c,u=s(e);!(c=u()).done;){var l=c.value,h=this._reactiveQueriesByComponent.get(l);h||(h=new Set,this._reactiveQueriesByComponent.set(l,h)),h.add(i)}return i},t.destroyReactiveQuery=function(e){if(e){var t=e.id;this._reactiveQueries.delete(t);for(var n,r=s(e.condition.componentTypes);!(n=r()).done;){var i=n.value,o=this._reactiveQueriesByComponent.get(i);o&&(o.delete(e),0===o.size&&this._reactiveQueriesByComponent.delete(i))}e.dispose()}},t.createComponentMask=function(e){var t=e.map(function(e){return L(e)}).sort().join(","),n=this._componentMaskCache.get(t);if(n)return n;for(var r,i=U.clone(U.ZERO),o=s(e);!(r=o()).done;){var a=r.value,c=K.getBitMask(a);U.orInPlace(i,c)}return this._componentMaskCache.set(t,i),i},t.getAllEntities=function(){return this._entities},t.getStats=function(){return{entityCount:this._entities.length,indexStats:{componentIndexSize:this._archetypeSystem.getAllArchetypes().length,tagIndexSize:this._entityIndex.byTag.size,nameIndexSize:this._entityIndex.byName.size},queryStats:a({},this._queryStats,{cacheHitRate:this._queryStats.totalQueries>0?(this._queryStats.cacheHits/this._queryStats.totalQueries*100).toFixed(2)+"%":"0%"}),optimizationStats:{archetypeSystem:this._archetypeSystem.getAllArchetypes().map(function(e){return{id:e.id,componentTypes:e.componentTypes.map(function(e){return L(e)}),entityCount:e.entities.size}})},cacheStats:{size:this._reactiveQueries.size,hitRate:this._queryStats.totalQueries>0?(this._queryStats.cacheHits/this._queryStats.totalQueries*100).toFixed(2)+"%":"0%"}}},t.getEntityArchetype=function(e){return this._archetypeSystem.getEntityArchetype(e)},t.getOrCreateReactiveQuery=function(e,t){var n=this.generateCacheKey(e,t),r=this._reactiveQueries.get(n);if(!r){var i=this.createComponentMask(t);r=new Et({type:e,componentTypes:t,mask:i},{enableBatchMode:!1,debug:!1});var o=this.executeTraditionalQuery(e,t);r.initializeWith(o),this._reactiveQueries.set(n,r);for(var a,c=s(t);!(a=c()).done;){var u=a.value,l=this._reactiveQueriesByComponent.get(u);l||(l=new Set,this._reactiveQueriesByComponent.set(u,l)),l.add(r)}this._logger.debug("创建内部响应式查询缓存: "+n)}return r},t.executeTraditionalQuery=function(e,t){switch(e){case yt.ALL:for(var n,r=[],i=s(this._archetypeSystem.queryArchetypes(t,"AND").archetypes);!(n=i()).done;)for(var o,a=s(n.value.entities);!(o=a()).done;){var c=o.value;r.push(c)}return r;case yt.ANY:for(var u,l=[],h=s(this._archetypeSystem.queryArchetypes(t,"OR").archetypes);!(u=h()).done;)for(var d,f=s(u.value.entities);!(d=f()).done;){var p=d.value;l.push(p)}return l;case yt.NONE:var m=this.createComponentMask(t);return this._entities.filter(function(e){return U.hasNone(e.componentMask,m)});default:return[]}},t.notifyReactiveQueriesEntityAdded=function(e){if(0!==this._reactiveQueries.size)for(var t,n=new Set,r=s(e.components);!(t=r()).done;){var i=t.value.constructor,o=this._reactiveQueriesByComponent.get(i);if(o)for(var a,c=s(o);!(a=c()).done;){var u=a.value;n.has(u)||(u.notifyEntityAdded(e),n.add(u))}}},t.notifyReactiveQueriesEntityRemoved=function(e,t){if(0!==this._reactiveQueries.size)for(var n,r=new Set,i=s(t);!(n=i()).done;){var o=n.value,a=this._reactiveQueriesByComponent.get(o);if(a)for(var c,u=s(a);!(c=u()).done;){var l=c.value;r.has(l)||(l.notifyEntityRemoved(e),r.add(l))}}},t.notifyReactiveQueriesEntityRemovedFallback=function(e){if(0!==this._reactiveQueries.size)for(var t,n=s(this._reactiveQueries.values());!(t=n()).done;){t.value.notifyEntityRemoved(e)}},t.notifyReactiveQueriesEntityChanged=function(e){if(0!==this._reactiveQueries.size){for(var t,n=new Set,r=s(e.components);!(t=r()).done;){var i=t.value.constructor,o=this._reactiveQueriesByComponent.get(i);if(o)for(var a,c=s(o);!(a=c()).done;){var u=a.value;n.has(u)||(u.notifyEntityChanged(e),n.add(u))}}for(var l,h=s(this._reactiveQueries.values());!(l=h()).done;){var d=l.value;n.has(d)||d.notifyEntityChanged(e)}}},o(e,[{key:"version",get:function(){return this._version}}])}(),wt=function(){function e(e){this._logger=J("QueryBuilder"),this.conditions=[],this.querySystem=e}var t=e.prototype;return t.withAll=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return this.conditions.push({type:yt.ALL,componentTypes:t,mask:this.createComponentMask(t)}),this},t.withAny=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return this.conditions.push({type:yt.ANY,componentTypes:t,mask:this.createComponentMask(t)}),this},t.without=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return this.conditions.push({type:yt.NONE,componentTypes:t,mask:this.createComponentMask(t)}),this},t.execute=function(){var e,t,n,r=performance.now();if(1===this.conditions.length){var i=this.conditions[0];switch(i.type){case yt.ALL:return(e=this.querySystem).queryAll.apply(e,i.componentTypes);case yt.ANY:return(t=this.querySystem).queryAny.apply(t,i.componentTypes);case yt.NONE:return(n=this.querySystem).queryNone.apply(n,i.componentTypes)}}return{entities:[],count:0,executionTime:performance.now()-r,fromCache:!1}},t.createComponentMask=function(e){for(var t,n=U.clone(U.ZERO),r=s(e);!(t=r()).done;){var i=t.value;try{var o=K.getBitMask(i);U.orInPlace(n,o)}catch(e){this._logger.warn("组件类型 "+L(i)+" 未注册,跳过")}}return n},t.reset=function(){return this.conditions=[],this},e}(),Mt=function(){function e(){this.listeners=new Map,this.stats=new Map,this.batchQueue=new Map,this.batchTimers=new Map,this.batchConfigs=new Map,this.nextListenerId=0,this.isEnabled=!0,this.maxListeners=100}var t=e.prototype;return t.on=function(e,t,n){return void 0===n&&(n={}),this.addListener(e,t,n)},t.once=function(e,t,n){return void 0===n&&(n={}),this.addListener(e,t,a({},n,{once:!0}))},t.onAsync=function(e,t,n){return void 0===n&&(n={}),this.addListener(e,t,a({},n,{async:!0}))},t.off=function(e,t){var n=this.listeners.get(e);if(!n)return!1;var r=n.findIndex(function(e){return e.id===t});return-1!==r&&(n.splice(r,1),0===n.length&&(this.listeners.delete(e),this.stats.delete(e)),!0)},t.offAll=function(e){this.listeners.delete(e),this.stats.delete(e),this.clearBatch(e)},t.emit=function(){var e=n(h().m(function e(t,n){var r;return h().w(function(e){for(;;)switch(e.n){case 0:if(this.isEnabled){e.n=1;break}return e.a(2);case 1:if(null==(r=this.batchConfigs.get(t))||!r.enabled){e.n=2;break}return this.addToBatch(t,n),e.a(2);case 2:return e.n=3,this.executeEvent(t,n);case 3:return e.a(2)}},e,this)}));return function(t,n){return e.apply(this,arguments)}}(),t.emitSync=function(t,n){if(this.isEnabled){var r=this.listeners.get(t);if(r&&0!==r.length){for(var i,o=performance.now(),a=[],c=s(this.sortListenersByPriority(r));!(i=c()).done;){var u=i.value;if(!u.config.async)try{u.config.thisArg?u.handler.call(u.config.thisArg,n):u.handler(n),u.config.once&&a.push(u.id)}catch(n){e._logger.error("事件处理器执行错误 "+t+":",n)}}this.removeListeners(t,a),this.updateStats(t,performance.now()-o)}}},t.setBatchConfig=function(e,t){this.batchConfigs.set(e,t)},t.flushBatch=function(e){var t=this.batchQueue.get(e);if(t&&0!==t.length){var n=this.batchTimers.get(e);n&&(clearTimeout(n),this.batchTimers.delete(e)),this.processBatch(e,t),this.batchQueue.delete(e)}},t.getStats=function(e){return e?this.stats.get(e)||this.createEmptyStats(e):new Map(this.stats)},t.resetStats=function(e){e?this.stats.delete(e):this.stats.clear()},t.setEnabled=function(e){this.isEnabled=e},t.hasListeners=function(e){var t=this.listeners.get(e);return!!t&&t.length>0},t.getListenerCount=function(e){var t=this.listeners.get(e);return t?t.length:0},t.clear=function(){this.listeners.clear(),this.stats.clear(),this.clearAllBatches()},t.setMaxListeners=function(e){this.maxListeners=e},t.addListener=function(t,n,r){var i=this.listeners.get(t);if(i||(i=[],this.listeners.set(t,i)),i.length>=this.maxListeners)return e._logger.warn("事件类型 "+t+" 的监听器数量超过最大限制 ("+this.maxListeners+")"),"";var o="listener_"+this.nextListenerId++,s={handler:n,config:a({priority:0},r),id:o};return i.push(s),this.stats.has(t)||this.stats.set(t,this.createEmptyStats(t)),o},t.executeEvent=function(){var t=n(h().m(function t(r,i){var o,a,c,u,l,d,f,p,m,v;return h().w(function(t){for(;;)switch(t.n){case 0:if((o=this.listeners.get(r))&&0!==o.length){t.n=1;break}return t.a(2);case 1:for(a=performance.now(),c=[],u=this.sortListenersByPriority(o),l=u.filter(function(e){return!e.config.async}),d=u.filter(function(e){return e.config.async}),f=s(l);!(p=f()).done;){m=p.value;try{m.config.thisArg?m.handler.call(m.config.thisArg,i):m.handler(i),m.config.once&&c.push(m.id)}catch(t){e._logger.error("同步事件处理器执行错误 "+r+":",t)}}return v=d.map(function(){var t=n(h().m(function t(n){var o;return h().w(function(t){for(;;)switch(t.p=t.n){case 0:if(t.p=0,!n.config.thisArg){t.n=2;break}return t.n=1,n.handler.call(n.config.thisArg,i);case 1:t.n=3;break;case 2:return t.n=3,n.handler(i);case 3:n.config.once&&c.push(n.id),t.n=5;break;case 4:t.p=4,o=t.v,e._logger.error("异步事件处理器执行错误 "+r+":",o);case 5:return t.a(2)}},t,null,[[0,4]])}));return function(e){return t.apply(this,arguments)}}()),t.n=2,Promise.all(v);case 2:this.removeListeners(r,c),this.updateStats(r,performance.now()-a);case 3:return t.a(2)}},t,this)}));return function(e,n){return t.apply(this,arguments)}}(),t.sortListenersByPriority=function(e){return e.slice().sort(function(e,t){return(t.config.priority||0)-(e.config.priority||0)})},t.removeListeners=function(e,t){if(0!==t.length){var n=this.listeners.get(e);if(n){for(var r,i=function(){var e=r.value,t=n.findIndex(function(t){return t.id===e});-1!==t&&n.splice(t,1)},o=s(t);!(r=o()).done;)i();0===n.length&&(this.listeners.delete(e),this.stats.delete(e))}}},t.addToBatch=function(e,t){var n=this,r=this.batchQueue.get(e);r||(r=[],this.batchQueue.set(e,r)),r.push(t);var i=this.batchConfigs.get(e);if(r.length>=i.batchSize)this.flushBatch(e);else if(!this.batchTimers.has(e)){var o=setTimeout(function(){n.flushBatch(e)},i.delay);this.batchTimers.set(e,o)}},t.processBatch=function(){var e=n(h().m(function e(t,n){var r;return h().w(function(e){for(;;)switch(e.n){case 0:return r={type:t,events:n,count:n.length,timestamp:Date.now()},e.n=1,this.executeEvent(t+":batch",r);case 1:return e.a(2)}},e,this)}));return function(t,n){return e.apply(this,arguments)}}(),t.clearBatch=function(e){this.batchQueue.delete(e);var t=this.batchTimers.get(e);t&&(clearTimeout(t),this.batchTimers.delete(e))},t.clearAllBatches=function(){this.batchQueue.clear();for(var e,t=s(this.batchTimers.values());!(e=t()).done;){var n=e.value;clearTimeout(n)}this.batchTimers.clear(),this.batchConfigs.clear()},t.updateStats=function(e,t){var n=this.stats.get(e);n||(n=this.createEmptyStats(e),this.stats.set(e,n)),n.triggerCount++,n.totalExecutionTime+=t,n.averageExecutionTime=n.totalExecutionTime/n.triggerCount,n.lastTriggerTime=Date.now(),n.listenerCount=this.getListenerCount(e)},t.createEmptyStats=function(e){return{eventType:e,listenerCount:0,triggerCount:0,totalExecutionTime:0,averageExecutionTime:0,lastTriggerTime:0}},e}();Mt._logger=J("EventSystem");var xt=function(){function e(e,t){this._entities=e,this._componentTypes=t}var t=e.prototype;return t.forEach=function(e){this._entities.forEach(e)},t.map=function(e){return this._entities.map(e)},t.filter=function(t){return new e(this._entities.filter(t),this._componentTypes)},t.find=function(e){return this._entities.find(e)},t.some=function(e){return this._entities.some(e)},t.every=function(e){return this._entities.every(e)},t.get=function(e){return this._entities[e]},t.toArray=function(){return[].concat(this._entities)},t.getComponentTypes=function(){return this._componentTypes},t[Symbol.iterator]=function(){return this._entities[Symbol.iterator]()},o(e,[{key:"entities",get:function(){return this._entities}},{key:"length",get:function(){return this._entities.length}},{key:"first",get:function(){return this._entities[0]}},{key:"last",get:function(){return this._entities[this._entities.length-1]}},{key:"isEmpty",get:function(){return 0===this._entities.length}}])}(),It=function(){function e(e,t,n,r,i){this._all=e||[],this._any=t||[],this._none=n||[],void 0!==r&&(this._tag=r),void 0!==i&&(this._name=i)}var t=e.prototype;return t.withAll=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return new e([].concat(this._all,n),this._any,this._none,this._tag,this._name)},t.withAny=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return new e(this._all,[].concat(this._any,n),this._none,this._tag,this._name)},t.withNone=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return new e(this._all,this._any,[].concat(this._none,n),this._tag,this._name)},t.withTag=function(t){return new e(this._all,this._any,this._none,t,this._name)},t.withName=function(t){return new e(this._all,this._any,this._none,this._tag,t)},t.buildMatcher=function(){var e,t,n,r=Pe.complex();this._all.length>0&&(r=(e=r).all.apply(e,this._all));this._any.length>0&&(r=(t=r).any.apply(t,this._any));this._none.length>0&&(r=(n=r).none.apply(n,this._none));return void 0!==this._tag&&(r=r.withTag(this._tag)),void 0!==this._name&&(r=r.withName(this._name)),r},t.getCondition=function(){return a({all:[].concat(this._all),any:[].concat(this._any),none:[].concat(this._none)},void 0!==this._tag&&{tag:this._tag},void 0!==this._name&&{name:this._name})},t.getRequiredTypes=function(){return this._all},t.clone=function(){return new e([].concat(this._all),[].concat(this._any),[].concat(this._none),this._tag,this._name)},e}();var At,kt=function(){function e(){}return e.serialize=function(e){var t=ke(e);if(!t)return null;for(var n,r=e.constructor,i=t.options.typeId||L(r),o={},a=s(t.fields);!(n=a()).done;){var c=n.value,u=c[0],l=c[1],h="symbol"==typeof u?u.toString():u,d=e[u];if(!t.ignoredFields.has(u)){var f=void 0;f=de(e,h)?this.serializeEntityRef(d):l.serializer?l.serializer(d):this.serializeValue(d),o[l.alias||h]=f}}return{type:i,version:t.options.version,data:o}},e.deserialize=function(e,t,n){var r=t.get(e.type);if(!r)return console.warn("未找到组件类型: "+e.type),null;var i=ke(r);if(!i)return console.warn("组件 "+e.type+" 不可序列化"),null;for(var o,a=new r,c=s(i.fields);!(o=c()).done;){var u=o.value,l=u[0],h=u[1],d="symbol"==typeof l?l.toString():l,f=h.alias||d,p=e.data[f];if(void 0!==p)if(this.isSerializedEntityRef(p)){if(n){var m=p.__entityRef;n.registerPendingRef(a,d,m.id,m.guid)}a[l]=null}else{var v=h.deserializer?h.deserializer(p):this.deserializeValue(p);a[l]=v}}return a},e.serializeComponents=function(e){for(var t,n=[],r=s(e);!(t=r()).done;){var i=t.value,o=this.serialize(i);o&&n.push(o)}return n},e.deserializeComponents=function(e,t,n){for(var r,i=[],o=s(e);!(r=o()).done;){var a=r.value,c=this.deserialize(a,t,n);c&&i.push(c)}return i},e.serializeValue=function(e){var t=this;if(null==e)return e;var n=typeof e;if("string"===n||"number"===n||"boolean"===n)return e;if(e instanceof Date)return{__type:"Date",value:e.toISOString()};if(Array.isArray(e))return e.map(function(e){return t.serializeValue(e)});if(e instanceof Map)return{__type:"Map",value:Array.from(e.entries())};if(e instanceof Set)return{__type:"Set",value:Array.from(e)};if("object"===n&&"object"==typeof e&&!Array.isArray(e)){var r={},i=e;for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&(r[o]=this.serializeValue(i[o]));return r}},e.deserializeValue=function(e){var t=this;if(null==e)return e;var n=typeof e;if("string"===n||"number"===n||"boolean"===n)return e;if("object"===n&&"object"==typeof e&&"__type"in e){var r=e;switch(r.__type){case"Date":return{__type:"Date",value:"string"==typeof r.value?r.value:String(r.value)};case"Map":return{__type:"Map",value:r.value};case"Set":return{__type:"Set",value:r.value}}}if(Array.isArray(e))return e.map(function(e){return t.deserializeValue(e)});if("object"===n&&"object"==typeof e&&!Array.isArray(e)){var i={},o=e;for(var s in o)Object.prototype.hasOwnProperty.call(o,s)&&(i[s]=this.deserializeValue(o[s]));return i}return e},e.validateVersion=function(e,t){return e.version===t},e.getSerializationInfo=function(e){var t=ke(e);if(!t)return{type:"unknown",version:0,fields:[],ignoredFields:[],isSerializable:!1};var n="function"==typeof e?e:e.constructor;return{type:t.options.typeId||L(n),version:t.options.version,fields:Array.from(t.fields.keys()).map(function(e){return"symbol"==typeof e?e.toString():e}),ignoredFields:Array.from(t.ignoredFields).map(function(e){return"symbol"==typeof e?e.toString():e}),isSerializable:!0}},e.serializeEntityRef=function(e){return e?{__entityRef:{id:e.id,guid:e.persistentId}}:null},e.isSerializedEntityRef=function(e){return"object"==typeof e&&null!==e&&"__entityRef"in e},e}(),Pt=function(){function e(){}return e.serialize=function(e,t,n){void 0===t&&(t=!0);var r=kt.serializeComponents(Array.from(e.components)),i={id:e.id,guid:e.persistentId,name:e.name,tag:e.tag,active:e.active,enabled:e.enabled,updateOrder:e.updateOrder,components:r,children:[]},o=e.getComponent(exports.HierarchyComponent);if(null!==(null==o?void 0:o.parentId)&&void 0!==(null==o?void 0:o.parentId)&&(i.parentId=o.parentId),t&&o&&o.childIds.length>0){var a,c=null!==(a=null==n?void 0:n.scene)&&void 0!==a?a:e.scene;if(c)for(var u,l=s(o.childIds);!(u=l()).done;){var h=u.value,d=c.findEntityById(h);d&&i.children.push(this.serialize(d,!0,n))}}return i},e.deserialize=function(e,t,n,r,i,o,a,c){void 0===r&&(r=!1);var u=r?e.id:n(),l=new ut(e.name,u,e.guid);null==a||a.set(l.id,l),c&&c.registerEntity(l,e.id,e.guid),i&&(l.scene=i),l.tag=e.tag,l.active=e.active,l.enabled=e.enabled,l.updateOrder=e.updateOrder;for(var h,d=s(kt.deserializeComponents(e.components,t,c));!(h=d()).done;){var f=h.value;l.addComponent(f)}var p=l.getComponent(exports.HierarchyComponent);p&&(p.parentId=null,p.childIds=[]);for(var m,v=s(e.children);!(m=v()).done;){var y=m.value,g=this.deserialize(y,t,n,r,i,o,a,c);null==o||o.setParent(g,l)}return l},e.serializeEntities=function(e,t,n){void 0===t&&(t=!0);for(var r,i=[],o=s(e);!(r=o()).done;){var a=r.value,c=a.getComponent(exports.HierarchyComponent);null!==(null==c?void 0:c.parentId)&&void 0!==(null==c?void 0:c.parentId)&&t||i.push(this.serialize(a,t,n))}return i},e.deserializeEntities=function(e,t,n,r,i,o,a){void 0===r&&(r=!1);for(var c,u=[],l=new Map,h=s(e);!(c=h()).done;){var d=c.value,f=this.deserialize(d,t,n,r,i,o,l,a);u.push(f)}return{rootEntities:u,allEntities:l}},e.clone=function(e,t,n){var r=this.serialize(e,!0);return this.deserialize(r,t,n,!1)},e}(),Ot=function(){function e(){}return e.stringToUtf8=function(e){for(var t=e.length,n=0,r=[],i=0;i<t;i++){var o=e.charCodeAt(i);if(o>=55296&&o<=56319&&i+1<t){var s=o,a=e.charCodeAt(i+1);a>=56320&&a<=57343&&(o=65536+(s-55296<<10)+(a-56320),i++)}o<128?r[n++]=o:o<2048?(r[n++]=192|o>>6,r[n++]=128|63&o):o<65536?(r[n++]=224|o>>12,r[n++]=128|o>>6&63,r[n++]=128|63&o):(r[n++]=240|o>>18,r[n++]=128|o>>12&63,r[n++]=128|o>>6&63,r[n++]=128|63&o)}return new Uint8Array(r)},e.utf8ToString=function(e){for(var t=e.length,n="",r=0;r<t;){var i=e[r++];if(void 0===i)break;if(i<128)n+=String.fromCharCode(i);else if(192==(224&i)){var o=e[r++];if(void 0===o)break;n+=String.fromCharCode((31&i)<<6|63&o)}else if(224==(240&i)){var s=e[r++],a=e[r++];if(void 0===s||void 0===a)break;n+=String.fromCharCode((15&i)<<12|(63&s)<<6|63&a)}else if(240==(248&i)){var c=e[r++],u=e[r++],l=e[r++];if(void 0===c||void 0===u||void 0===l)break;var h=(7&i)<<18|(63&c)<<12|(63&u)<<6|63&l;h-=65536,n+=String.fromCharCode(55296+(h>>10),56320+(1023&h))}}return n},e.encode=function(e){var t=JSON.stringify(e);return this.stringToUtf8(t)},e.decode=function(e){var t=this.utf8ToString(e);return JSON.parse(t)},e}(),Dt=function(){function e(){this._idRemapping=new Map,this._guidLookup=new Map,this._pendingRefs=[],this._preserveIds=!1}var t=e.prototype;return t.setPreserveIds=function(e){this._preserveIds=e},t.registerEntity=function(e,t,n){var r=null!=n?n:e.persistentId;this._guidLookup.set(r,e),void 0!==t&&this._idRemapping.set(t,e)},t.getEntityById=function(e){var t;return null!==(t=this._idRemapping.get(e))&&void 0!==t?t:null},t.getEntityByGuid=function(e){var t;return null!==(t=this._guidLookup.get(e))&&void 0!==t?t:null},t.resolveEntityRef=function(e){if(!e)return null;if(e.guid){var t=this._guidLookup.get(e.guid);if(t)return t}if(void 0!==e.id){var n=this._idRemapping.get(e.id);if(n)return n}return null},t.registerPendingRef=function(e,t,n,r){this._pendingRefs.push({component:e,propertyKey:t,originalId:n,originalGuid:r})},t.resolveAllReferences=function(){for(var e,t=0,n=s(this._pendingRefs);!(e=n()).done;){var r=e.value,i=this.resolveEntityRef({id:r.originalId,guid:r.originalGuid});i&&(r.component[r.propertyKey]=i,t++)}return t},t.getUnresolvedCount=function(){for(var e,t=0,n=s(this._pendingRefs);!(e=n()).done;){var r=e.value;this.resolveEntityRef({id:r.originalId,guid:r.originalGuid})||t++}return t},t.getPendingCount=function(){return this._pendingRefs.length},t.getRegisteredEntityCount=function(){return this._guidLookup.size},t.clear=function(){this._idRemapping.clear(),this._guidLookup.clear(),this._pendingRefs=[]},t.getDebugInfo=function(){return{registeredEntities:this._guidLookup.size,pendingRefs:this._pendingRefs.length,unresolvedRefs:this.getUnresolvedCount(),preserveIds:this._preserveIds}},o(e,[{key:"preserveIds",get:function(){return this._preserveIds}}])}(),Rt=function(){function e(){}return e.serialize=function(e,t){var n=a({systems:!1,format:"json",pretty:!0,includeMetadata:!0},t),r=this.filterEntities(e,n),i=e.getSystem(Le),o=Pt.serializeEntities(r,!0,null!=i?i:void 0),s=this.buildComponentTypeRegistry(r),c=this.serializeSceneData(e.sceneData),u={name:e.name,version:this.SERIALIZATION_VERSION,entities:o,componentTypeRegistry:s};return c&&Object.keys(c).length>0&&(u.sceneData=c),n.includeMetadata&&(u.timestamp=Date.now(),u.metadata={entityCount:o.length,componentTypeCount:s.length,serializationOptions:n}),"json"===n.format?n.pretty?JSON.stringify(u,null,2):JSON.stringify(u):Ot.encode(u)},e.deserialize=function(e,t,n){var r,i=a({strategy:"replace",preserveIds:!1},n);try{r="string"==typeof t?JSON.parse(t):Ot.decode(t)}catch(e){throw new Error("Failed to parse save data: "+e)}i.migration&&r.version!==this.SERIALIZATION_VERSION&&(r=i.migration(r.version,this.SERIALIZATION_VERSION,r));var o=i.componentRegistry||this.getGlobalComponentRegistry();"replace"===i.strategy&&e.destroyAllEntities();var c=e.getSystem(Le),u=new Dt;u.setPreserveIds(i.preserveIds||!1);for(var l,h=Pt.deserializeEntities(r.entities,o,function(){return e.identifierPool.checkOut()},i.preserveIds||!1,e,c,u),d=h.rootEntities,f=h.allEntities,p=s(d);!(l=p()).done;){var m=l.value;e.addEntity(m,!0),this.addChildrenRecursively(m,e,c,f)}e.querySystem.clearCache(),e.clearSystemEntityCaches();var v=u.resolveAllReferences(),y=u.getUnresolvedCount();y>0&&console.warn("[SceneSerializer] "+y+" EntityRef(s) could not be resolved. Resolved: "+v+", Total pending: "+u.getPendingCount()),r.sceneData&&this.deserializeSceneData(r.sceneData,e.sceneData);for(var g,_=[],S=s(f.values());!(g=S()).done;){var C=g.value;this.callOnDeserializedForEntity(C,_)}_.length>0&&Promise.all(_).catch(function(e){console.error("Error in onDeserialized:",e)})},e.callOnDeserializedForEntity=function(e,t){for(var n,r=s(e.components);!(n=r()).done;){var i=n.value;try{var o=i.onDeserialized();o instanceof Promise&&t.push(o)}catch(e){console.error("Error calling onDeserialized on component "+i.constructor.name+":",e)}}},e.addChildrenRecursively=function(e,t,n,r){var i=e.getComponent(exports.HierarchyComponent);if(i&&0!==i.childIds.length)for(var o,a=s(i.childIds);!(o=a()).done;){var c,u=o.value,l=null!==(c=null==r?void 0:r.get(u))&&void 0!==c?c:t.findEntityById(u);l&&(t.addEntity(l,!0),this.addChildrenRecursively(l,t,n,r))}},e.serializeSceneData=function(e){for(var t,n={},r=s(e);!(t=r()).done;){var i=t.value,o=i[0],a=i[1];n[o]=this.serializeValue(a)}return n},e.deserializeSceneData=function(e,t){t.clear();for(var n=0,r=Object.entries(e);n<r.length;n++){var i=r[n],o=i[0],s=i[1];t.set(o,this.deserializeValue(s))}},e.serializeValue=function(e){var t=this;if(null==e)return e;var n=typeof e;if("string"===n||"number"===n||"boolean"===n)return e;if(e instanceof Date)return{__type:"Date",value:e.toISOString()};if(e instanceof Map)return{__type:"Map",value:Array.from(e.entries())};if(e instanceof Set)return{__type:"Set",value:Array.from(e)};if(Array.isArray(e))return e.map(function(e){return t.serializeValue(e)});if("object"===n){var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=this.serializeValue(e[i]));return r}},e.deserializeValue=function(e){var t=this;if(null==e)return e;var n=typeof e;if("string"===n||"number"===n||"boolean"===n)return e;if("object"===n&&e.__type)switch(e.__type){case"Date":return new Date(e.value);case"Map":return new Map(e.value);case"Set":return new Set(e.value)}if(Array.isArray(e))return e.map(function(e){return t.deserializeValue(e)});if("object"===n){var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=this.deserializeValue(e[i]));return r}return e},e.filterEntities=function(e,t){var n=Array.from(e.entities.buffer);if(t.components&&t.components.length>0){var r=new Set(t.components);return n.filter(function(e){return Array.from(e.components).some(function(e){return r.has(e.constructor)})})}return n},e.buildComponentTypeRegistry=function(e){for(var t,n=new Map,r=s(e);!(t=r()).done;)for(var i,o=s(t.value.components);!(i=o()).done;){var a=i.value,c=L(a.constructor),u=ke(a);u&&!n.has(c)&&n.set(c,u.options.version)}return Array.from(n.entries()).map(function(e){return{typeName:e[0],version:e[1]}})},e.getGlobalComponentRegistry=function(){return K.getAllComponentNames()},e.validate=function(e){var t=[];try{var n=JSON.parse(e);return n.version||t.push("Missing version field"),n.entities&&Array.isArray(n.entities)||t.push("Missing or invalid entities field"),n.componentTypeRegistry&&Array.isArray(n.componentTypeRegistry)||t.push("Missing or invalid componentTypeRegistry field"),a({valid:0===t.length,version:n.version},t.length>0&&{errors:t})}catch(e){return{valid:!1,errors:["JSON parse error: "+e]}}},e.getInfo=function(e){try{var t,n=JSON.parse(e);return a({name:n.name,version:n.version},void 0!==n.timestamp&&{timestamp:n.timestamp},{entityCount:(null===(t=n.metadata)||void 0===t?void 0:t.entityCount)||n.entities.length,componentTypeCount:n.componentTypeRegistry.length})}catch(e){return null}},e}();Rt.SERIALIZATION_VERSION=1,exports.ChangeOperation=void 0,(At=exports.ChangeOperation||(exports.ChangeOperation={})).EntityAdded="entity_added",At.EntityRemoved="entity_removed",At.EntityUpdated="entity_updated",At.ComponentAdded="component_added",At.ComponentRemoved="component_removed",At.ComponentUpdated="component_updated",At.SceneDataUpdated="scene_data_updated";var zt=function(){function e(){}return e.createSnapshot=function(e,t){for(var n,r=a({deepComponentComparison:!0,trackSceneData:!0,compressSnapshot:!1},t),i={version:++this.snapshotVersion,entityIds:new Set,entities:new Map,components:new Map,sceneData:new Map},o=s(e.entities.buffer);!(n=o()).done;){var c=n.value;i.entityIds.add(c.id);var u=c.getComponent(exports.HierarchyComponent),l=null==u?void 0:u.parentId;if(i.entities.set(c.id,a({name:c.name,tag:c.tag,active:c.active,enabled:c.enabled,updateOrder:c.updateOrder},null!=l&&{parentId:l})),r.deepComponentComparison){for(var h,d=new Map,f=s(c.components);!(h=f()).done;){var p=h.value,m=kt.serialize(p);m&&d.set(m.type,JSON.stringify(m.data))}d.size>0&&i.components.set(c.id,d)}}if(r.trackSceneData)for(var v,y=s(e.sceneData);!(v=y()).done;){var g=v.value,_=g[0],S=g[1];i.sceneData.set(_,JSON.stringify(S))}return i},e.computeIncremental=function(e,t,n){for(var r,i=a({deepComponentComparison:!0,trackSceneData:!0},n),o={version:++this.snapshotVersion,timestamp:Date.now(),sceneName:e.name,baseVersion:t.version,entityChanges:[],componentChanges:[],sceneDataChanges:[]},c=new Set,u=s(e.entities.buffer);!(r=u()).done;){var l=r.value;c.add(l.id);var h=l.getComponent(exports.HierarchyComponent),d=null==h?void 0:h.parentId;if(t.entityIds.has(l.id)){var f=t.entities.get(l.id);(f.name!==l.name||f.tag!==l.tag||f.active!==l.active||f.enabled!==l.enabled||f.updateOrder!==l.updateOrder||f.parentId!==d)&&o.entityChanges.push({operation:exports.ChangeOperation.EntityUpdated,entityId:l.id,entityData:a({name:l.name,tag:l.tag,active:l.active,enabled:l.enabled,updateOrder:l.updateOrder},null!=d&&{parentId:d})}),i.deepComponentComparison&&this.detectComponentChanges(l,t,o.componentChanges)}else{o.entityChanges.push({operation:exports.ChangeOperation.EntityAdded,entityId:l.id,entityName:l.name,entityData:a({id:l.id,name:l.name,tag:l.tag,active:l.active,enabled:l.enabled,updateOrder:l.updateOrder},null!=d&&{parentId:d},{components:[],children:[]})});for(var p,m=s(l.components);!(p=m()).done;){var v=p.value,y=kt.serialize(v);y&&o.componentChanges.push({operation:exports.ChangeOperation.ComponentAdded,entityId:l.id,componentType:y.type,componentData:y})}}}for(var g,_=s(t.entityIds);!(g=_()).done;){var S=g.value;c.has(S)||o.entityChanges.push({operation:exports.ChangeOperation.EntityRemoved,entityId:S})}return i.trackSceneData&&this.detectSceneDataChanges(e,t,o.sceneDataChanges),o},e.detectComponentChanges=function(e,t,n){for(var r,i=t.components.get(e.id),o=new Map,a=s(e.components);!(r=a()).done;){var c=r.value,u=kt.serialize(c);u&&o.set(u.type,u)}for(var l,h=s(o);!(l=h()).done;){var d=l.value,f=d[0],p=d[1],m=JSON.stringify(p.data);i&&i.has(f)?i.get(f)!==m&&n.push({operation:exports.ChangeOperation.ComponentUpdated,entityId:e.id,componentType:f,componentData:p}):n.push({operation:exports.ChangeOperation.ComponentAdded,entityId:e.id,componentType:f,componentData:p})}if(i)for(var v,y=s(i.keys());!(v=y()).done;){var g=v.value;o.has(g)||n.push({operation:exports.ChangeOperation.ComponentRemoved,entityId:e.id,componentType:g})}},e.detectSceneDataChanges=function(e,t,n){for(var r,i=new Set,o=s(e.sceneData);!(r=o()).done;){var a=r.value,c=a[0],u=a[1];i.add(c);var l=JSON.stringify(u),h=t.sceneData.get(c);h&&h===l||n.push({operation:exports.ChangeOperation.SceneDataUpdated,key:c,value:u})}for(var d,f=s(t.sceneData.keys());!(d=f()).done;){var p=d.value;i.has(p)||n.push({operation:exports.ChangeOperation.SceneDataUpdated,key:p,value:void 0,deleted:!0})}},e.applyIncremental=function(e,t,n){for(var r,i=s(t.entityChanges);!(r=i()).done;){var o=r.value;switch(o.operation){case exports.ChangeOperation.EntityAdded:this.applyEntityAdded(e,o);break;case exports.ChangeOperation.EntityRemoved:this.applyEntityRemoved(e,o);break;case exports.ChangeOperation.EntityUpdated:this.applyEntityUpdated(e,o)}}for(var a,c=s(t.componentChanges);!(a=c()).done;){var u=a.value;switch(u.operation){case exports.ChangeOperation.ComponentAdded:this.applyComponentAdded(e,u,n);break;case exports.ChangeOperation.ComponentRemoved:this.applyComponentRemoved(e,u,n);break;case exports.ChangeOperation.ComponentUpdated:this.applyComponentUpdated(e,u,n)}}for(var l,h=s(t.sceneDataChanges);!(l=h()).done;){var d=l.value;d.deleted?e.sceneData.delete(d.key):e.sceneData.set(d.key,d.value)}},e.applyEntityAdded=function(e,t){var n,r;if(t.entityData){var i=new ut(t.entityName||"Entity",t.entityId);i.tag=t.entityData.tag||0,i.active=null===(n=t.entityData.active)||void 0===n||n,i.enabled=null===(r=t.entityData.enabled)||void 0===r||r,i.updateOrder=t.entityData.updateOrder||0,e.addEntity(i)}},e.applyEntityRemoved=function(e,t){var n=e.entities.findEntityById(t.entityId);n&&n.destroy()},e.applyEntityUpdated=function(e,t){if(t.entityData){var n=e.entities.findEntityById(t.entityId);if(n){void 0!==t.entityData.name&&(n.name=t.entityData.name),void 0!==t.entityData.tag&&(n.tag=t.entityData.tag),void 0!==t.entityData.active&&(n.active=t.entityData.active),void 0!==t.entityData.enabled&&(n.enabled=t.entityData.enabled),void 0!==t.entityData.updateOrder&&(n.updateOrder=t.entityData.updateOrder);var r=e.getSystem(Le);if(r){var i=n.getComponent(exports.HierarchyComponent),o=null==i?void 0:i.parentId;if(void 0!==t.entityData.parentId){var s=e.entities.findEntityById(t.entityData.parentId);s&&o!==t.entityData.parentId&&r.setParent(n,s)}else null!=o&&r.setParent(n,null)}}}},e.applyComponentAdded=function(e,t,n){if(t.componentData){var r=e.entities.findEntityById(t.entityId);if(r){var i=kt.deserialize(t.componentData,n);i&&r.addComponent(i)}}},e.applyComponentRemoved=function(e,t,n){var r=e.entities.findEntityById(t.entityId);if(r){var i=n.get(t.componentType);i&&r.removeComponentByType(i)}},e.applyComponentUpdated=function(e,t,n){if(t.componentData){var r=e.entities.findEntityById(t.entityId);if(r){var i=n.get(t.componentType);if(i){r.removeComponentByType(i);var o=kt.deserialize(t.componentData,n);o&&r.addComponent(o)}}}},e.serializeIncremental=function(e,t){var n=a({format:"json",pretty:!1},t);return"binary"===n.format?Ot.encode(e):n.pretty?JSON.stringify(e,null,2):JSON.stringify(e)},e.deserializeIncremental=function(e){return"string"==typeof e?JSON.parse(e):Ot.decode(e)},e.getIncrementalStats=function(e){return{totalChanges:e.entityChanges.length+e.componentChanges.length+e.sceneDataChanges.length,entityChanges:e.entityChanges.length,componentChanges:e.componentChanges.length,sceneDataChanges:e.sceneDataChanges.length,addedEntities:e.entityChanges.filter(function(e){return e.operation===exports.ChangeOperation.EntityAdded}).length,removedEntities:e.entityChanges.filter(function(e){return e.operation===exports.ChangeOperation.EntityRemoved}).length,updatedEntities:e.entityChanges.filter(function(e){return e.operation===exports.ChangeOperation.EntityUpdated}).length,addedComponents:e.componentChanges.filter(function(e){return e.operation===exports.ChangeOperation.ComponentAdded}).length,removedComponents:e.componentChanges.filter(function(e){return e.operation===exports.ChangeOperation.ComponentRemoved}).length,updatedComponents:e.componentChanges.filter(function(e){return e.operation===exports.ChangeOperation.ComponentUpdated}).length}},e.resetVersion=function(){this.snapshotVersion=0},e}();zt.snapshotVersion=0;var Nt={enabled:!0,sampleInterval:10,minDuration:.1,trackAsync:!0,excludePatterns:[/^_/,/^get[A-Z]/,/^set[A-Z]/,/^is[A-Z]/,/^has[A-Z]/],maxBufferSize:1e4},Ft=function(){function e(e){this.wrappedObjects=new WeakMap,this.samplingProfiler=null,this.registeredClasses=new Map,this.config=a({},Nt,e)}e.getInstance=function(t){return e.instance||(e.instance=new e(t)),e.instance},e.resetInstance=function(){e.instance&&(e.instance.dispose(),e.instance=null)},e.setEnabled=function(t){e.getInstance().setEnabled(t)},e.registerClass=function(t,n,r){return void 0===n&&(n=exports.ProfileCategory.Custom),e.getInstance().registerClass(t,n,r)},e.wrapInstance=function(t,n,r){return void 0===r&&(r=exports.ProfileCategory.Custom),e.getInstance().wrapInstance(t,n,r)},e.wrapFunction=function(t,n,r){return void 0===r&&(r=exports.ProfileCategory.Custom),e.getInstance().wrapFunction(t,n,r)},e.startSampling=function(){e.getInstance().startSampling()},e.stopSampling=function(){return e.getInstance().stopSampling()};var t=e.prototype;return t.setEnabled=function(e){this.config.enabled=e,!e&&this.samplingProfiler&&this.samplingProfiler.stop()},t.registerClass=function(e,t,n){void 0===t&&(t=exports.ProfileCategory.Custom);var r=n||e.name;this.registeredClasses.set(r,{constructor:e,category:t});var i=this;return new Proxy(e,{construct:function(e,n,o){var s=Reflect.construct(e,n,o);return i.config.enabled&&i.wrapInstance(s,r,t),s}})},t.wrapInstance=function(e,t,n){if(void 0===n&&(n=exports.ProfileCategory.Custom),!this.config.enabled)return e;if(this.wrappedObjects.has(e))return e;var r=new Map;this.wrappedObjects.set(e,r);for(var i,o=s(this.getAllMethodNames(e));!(i=o()).done;){var a=i.value;if(!this.shouldExcludeMethod(a)){var c=this.getPropertyDescriptor(e,a);if(c&&"function"==typeof c.value){var u=c.value,l=this.createWrappedMethod(u,t,a,n);r.set(a,{className:t,methodName:a,category:n,original:u});try{e[a]=l}catch(e){}}}}return e},t.wrapFunction=function(e,t,n){if(void 0===n&&(n=exports.ProfileCategory.Custom),!this.config.enabled)return e;var r=this,i=function(){var i=Ze.beginSample(t,n);try{for(var o=arguments.length,s=new Array(o),a=0;a<o;a++)s[a]=arguments[a];var c=e.apply(this,s);return r.config.trackAsync&&c instanceof Promise?c.finally(function(){Ze.endSample(i)}):(Ze.endSample(i),c)}catch(e){throw Ze.endSample(i),e}};return Object.defineProperty(i,"name",{value:e.name||t}),Object.defineProperty(i,"length",{value:e.length}),i},t.startSampling=function(){this.samplingProfiler||(this.samplingProfiler=new Bt(this.config)),this.samplingProfiler.start()},t.stopSampling=function(){return this.samplingProfiler?this.samplingProfiler.stop():[]},t.dispose=function(){this.samplingProfiler&&(this.samplingProfiler.stop(),this.samplingProfiler=null),this.registeredClasses.clear()},t.createWrappedMethod=function(e,t,n,r){var i=this,o=t+"."+n,s=this.config.minDuration;return function(){for(var t=arguments.length,n=new Array(t),a=0;a<t;a++)n[a]=arguments[a];if(!i.config.enabled||!Ze.isEnabled())return e.apply(this,n);var c=performance.now(),u=Ze.beginSample(o,r);try{var l=e.apply(this,n);return i.config.trackAsync&&l instanceof Promise?l.then(function(e){return performance.now()-c>=s&&Ze.endSample(u),e},function(e){throw Ze.endSample(u),e}):(performance.now()-c>=s&&Ze.endSample(u),l)}catch(e){throw Ze.endSample(u),e}}},t.getAllMethodNames=function(e){for(var t=new Set,n=e;n&&n!==Object.prototype;){for(var r,i=s(Object.getOwnPropertyNames(n));!(r=i()).done;){var o=r.value;"constructor"!==o&&t.add(o)}n=Object.getPrototypeOf(n)}return Array.from(t)},t.getPropertyDescriptor=function(e,t){for(var n=e;n&&n!==Object.prototype;){var r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=Object.getPrototypeOf(n)}},t.shouldExcludeMethod=function(e){if("constructor"===e||e.startsWith("__"))return!0;for(var t,n=s(this.config.excludePatterns);!(t=n()).done;){if(t.value.test(e))return!0}return!1},e}();Ft.instance=null;var Bt=function(){function e(e){this.samples=[],this.intervalId=null,this.isRunning=!1,this.config=e}var t=e.prototype;return t.start=function(){var e=this;if(!this.isRunning){this.isRunning=!0,this.samples=[];var t=function(){if(e.isRunning){var n=e.captureStack();n.length>0&&(e.samples.push({timestamp:performance.now(),stack:n}),e.samples.length>e.config.maxBufferSize&&e.samples.shift()),e.config.sampleInterval,e.intervalId=setTimeout(t,e.config.sampleInterval)}};t()}},t.stop=function(){return this.isRunning=!1,null!==this.intervalId&&(clearTimeout(this.intervalId),this.intervalId=null),[].concat(this.samples)},t.captureStack=function(){try{for(var e,t=((new Error).stack||"").split("\n").slice(3),n=[],r=s(t);!(e=r()).done;){var i=e.value,o=this.parseStackFrame(i);o&&!this.isInternalFrame(o)&&n.push(o)}return n}catch(e){return[]}},t.parseStackFrame=function(e){var t=(e=e.trim()).match(/at\s+(.+?)\s+\(/);if(t&&t[1])return t[1];if((t=e.match(/at\s+(.+)/))&&t[1]){var n=t[1];if(!n.includes("("))return n}return(t=e.match(/^(.+?)@/))&&t[1]?t[1]:null},t.isInternalFrame=function(e){return["SamplingProfiler","AutoProfiler","ProfilerSDK","setTimeout","setInterval","requestAnimationFrame","<anonymous>","eval"].some(function(t){return e.includes(t)})},e}();var Lt,Ht=J("ServiceContainer");exports.ServiceLifetime=void 0,(Lt=exports.ServiceLifetime||(exports.ServiceLifetime={})).Singleton="singleton",Lt.Transient="transient";var Wt=function(){function e(){this._services=new Map,this._resolving=new Set,this._updatableServices=[]}var t=e.prototype;return t.registerSingleton=function(e,t){this._services.has(e)?Ht.warn("Service "+e.name+" is already registered"):(this._services.set(e,a({identifier:e,type:e},t&&{factory:t},{lifetime:exports.ServiceLifetime.Singleton})),Ht.debug("Registered singleton service: "+e.name))},t.registerTransient=function(e,t){this._services.has(e)?Ht.warn("Service "+e.name+" is already registered"):(this._services.set(e,a({identifier:e,type:e},t&&{factory:t},{lifetime:exports.ServiceLifetime.Transient})),Ht.debug("Registered transient service: "+e.name))},t.registerInstance=function(e,t){if(this._services.has(e)){var n="symbol"==typeof e?e.description:e.name;Ht.warn("Service "+n+" is already registered")}else{if(this._services.set(e,{identifier:e,instance:t,lifetime:exports.ServiceLifetime.Singleton}),"symbol"!=typeof e&&A(e)){var r,i=k(e),o=null!==(r=null==i?void 0:i.priority)&&void 0!==r?r:0;this._updatableServices.push({instance:t,priority:o}),this._updatableServices.sort(function(e,t){return e.priority-t.priority}),Ht.debug("Service "+e.name+" is updatable (priority: "+o+"), added to update list")}var s="symbol"==typeof e?e.description:e.name;Ht.debug("Registered service instance: "+s)}},t.resolve=function(e){var t=this._services.get(e),n="symbol"==typeof e?e.description:e.name;if(!t)throw new Error("Service "+n+" is not registered");if(this._resolving.has(e)){var r=Array.from(this._resolving).map(function(e){return"symbol"==typeof e?e.description:e.name}).join(" -> ");throw new Error("Circular dependency detected: "+r+" -> "+n)}if(t.lifetime===exports.ServiceLifetime.Singleton&&t.instance)return t.instance;this._resolving.add(e);try{var i;if(t.factory)i=t.factory(this);else{if(!t.type)throw new Error("Service "+n+" has no factory or type to construct");i=new t.type}if(t.lifetime===exports.ServiceLifetime.Singleton&&(t.instance=i,t.type&&A(t.type))){var o,s=k(t.type),a=null!==(o=null==s?void 0:s.priority)&&void 0!==o?o:0;this._updatableServices.push({instance:i,priority:a}),this._updatableServices.sort(function(e,t){return e.priority-t.priority}),Ht.debug("Service "+n+" is updatable (priority: "+a+"), added to update list")}return i}finally{this._resolving.delete(e)}},t.tryResolve=function(e){try{return this.resolve(e)}catch(e){return null}},t.isRegistered=function(e){return this._services.has(e)},t.unregister=function(e){var t=this._services.get(e);if(!t)return!1;if(t.instance){var n=this._updatableServices.findIndex(function(e){return e.instance===t.instance});-1!==n&&this._updatableServices.splice(n,1),t.instance.dispose()}this._services.delete(e);var r="symbol"==typeof e?e.description:e.name;return Ht.debug("Unregistered service: "+r),!0},t.clear=function(){for(var e,t=s(this._services);!(e=t()).done;){var n=e.value[1];n.instance&&n.instance.dispose()}this._services.clear(),this._updatableServices=[],Ht.debug("Cleared all services")},t.getRegisteredServices=function(){return Array.from(this._services.keys())},t.updateAll=function(e){for(var t,n=s(this._updatableServices);!(t=n()).done;){t.value.instance.update(e)}},t.getUpdatableCount=function(){return this._updatableServices.length},t.getAll=function(){for(var e,t=[],n=s(this._services.values());!(e=n()).done;){var r=e.value;r.instance&&t.push(r.instance)}return t},e}(),jt=function(e){function t(n){var r,i="[SystemDependencyGraph] 检测到循环依赖 | Cycle dependency detected: "+n.join(" -> ");return(r=e.call(this,i)||this).name="CycleDependencyError",r.involvedNodes=n,Object.setPrototypeOf(r,(this instanceof t?this.constructor:void 0).prototype),r}return u(t,e),t}(m(Error)),Gt="set:",Ut=function(){function e(){this._nodes=new Map}var t=e.prototype;return t.addSystemNode=function(e){this.getOrCreateNode(e,!1)},t.addSetNode=function(e){var t=Gt+e;this.getOrCreateNode(t,!0)},t.addEdge=function(e,t){if(e!==t){var n=this.getOrCreateNode(e,e.startsWith(Gt)),r=this.getOrCreateNode(t,t.startsWith(Gt));n.outEdges.add(t),r.inEdges.add(e)}},t.buildFromSystems=function(e){this.clear();for(var t,n=s(e);!(t=n()).done;){var r=t.value;this.addSystemNode(r.name);for(var i,o=s(r.sets);!(i=o()).done;){var a=i.value;this.addSetNode(a)}}for(var c,u=s(e);!(c=u()).done;){for(var l,h=c.value,d=s(h.sets);!(l=d()).done;){var f=l.value,p=Gt+f;this.addEdge(p,h.name)}for(var m,v=s(h.before);!(m=v()).done;){var y=m.value,g=this.resolveTargetId(y);this.addEdge(h.name,g)}for(var _,S=s(h.after);!(_=S()).done;){var C=_.value,E=this.resolveTargetId(C);this.addEdge(E,h.name)}}},t.topologicalSort=function(){for(var e,t=new Map,n=s(this._nodes);!(e=n()).done;){var r=e.value,i=r[0],o=r[1];t.set(i,o.inEdges.size)}for(var a,c=[],u=s(t);!(a=u()).done;){var l=a.value,h=l[0];0===l[1]&&c.push(h)}for(var d=[],f=0;c.length>0;){var p=c.shift();f++;var m=this._nodes.get(p);if(m){m.bIsVirtual||d.push(p);for(var v,y=s(m.outEdges);!(v=y()).done;){var g,_=v.value,S=(null!==(g=t.get(_))&&void 0!==g?g:0)-1;t.set(_,S),0===S&&c.push(_)}}}if(f<this._nodes.size){for(var C,E=[],b=s(t);!(C=b()).done;){var T=C.value,w=T[0];T[1]>0&&E.push(w)}throw new jt(E)}return d},t.clear=function(){this._nodes.clear()},t.getOrCreateNode=function(e,t){var n=this._nodes.get(e);return n||(n={id:e,bIsVirtual:t,inEdges:new Set,outEdges:new Set},this._nodes.set(e,n)),n},t.resolveTargetId=function(e){return e.startsWith(Gt),e},o(e,[{key:"size",get:function(){return this._nodes.size}}])}(),qt=["startup","preUpdate","update","postUpdate","cleanup"],Qt=function(){function e(){this._sortedByStage=new Map,this._dirty=!0,this._graph=new Ut,this._useDependencySort=!0}var t=e.prototype;return t.setUseDependencySort=function(e){this._useDependencySort!==e&&(this._useDependencySort=e,this._dirty=!0)},t.markDirty=function(){this._dirty=!0},t.getSortedSystems=function(e,t){var n;if(this.ensureBuilt(e),t)return null!==(n=this._sortedByStage.get(t))&&void 0!==n?n:[];for(var r=[],i=0,o=qt;i<o.length;i++){var s=o[i],a=this._sortedByStage.get(s);a&&r.push.apply(r,a)}return r},t.getAllSortedSystems=function(e){return this.getSortedSystems(e)},t.ensureBuilt=function(e){this._dirty&&(this._sortedByStage.clear(),this._useDependencySort&&this.hasDependencies(e)?this.buildWithDependencyGraph(e):this.buildWithUpdateOrder(e),this._dirty=!1)},t.hasDependencies=function(e){for(var t,n=s(e);!(t=n()).done;){var r=t.value,i=this.getSchedulingMetadata(r);if(i.before.length>0||i.after.length>0||i.sets.length>0)return!0;if("update"!==i.stage)return!0}return!1},t.buildWithUpdateOrder=function(e){var t=[].concat(e).sort(function(e,t){var n=e.updateOrder-t.updateOrder;return 0!==n?n:e.addOrder-t.addOrder});this._sortedByStage.set("update",t)},t.buildWithDependencyGraph=function(e){for(var t=new Map,n=0,r=qt;n<r.length;n++){var i=r[n];t.set(i,[])}for(var o,a=s(e);!(o=a()).done;){var c=o.value,u=this.getSchedulingMetadata(c).stage,l=t.get(u);l?l.push(c):t.get("update").push(c)}for(var h,d=s(t);!(h=d()).done;){var f=h.value,p=f[0],m=f[1];if(0!==m.length){var v=this.sortSystemsInStage(m);this._sortedByStage.set(p,v)}else this._sortedByStage.set(p,[])}},t.sortSystemsInStage=function(e){for(var t,n=new Map,r=[],i=s(e);!(t=i()).done;){var o=t.value,a=o.systemName;n.set(a,o);var c=this.getSchedulingMetadata(o);r.push({name:a,before:c.before,after:c.after,sets:c.sets})}this._graph.buildFromSystems(r);try{for(var u,l=this._graph.topologicalSort(),h=[],d=s(l);!(u=d()).done;){var f=u.value,p=n.get(f);p&&h.push(p)}return this.stableSortByUpdateOrder(h)}catch(t){if(t instanceof jt)throw t;return console.warn("[SystemScheduler] 拓扑排序失败,回退到 updateOrder 排序",t),this.fallbackSort(e)}},t.stableSortByUpdateOrder=function(e){return e},t.fallbackSort=function(e){return[].concat(e).sort(function(e,t){var n=e.updateOrder-t.updateOrder;return 0!==n?n:e.addOrder-t.addOrder})},t.getSchedulingMetadata=function(e){return{stage:e.getStage(),before:[].concat(e.getBefore()),after:[].concat(e.getAfter()),sets:[].concat(e.getSets())}},e}(),Vt=function(){function e(e){void 0===e&&(e=1024),this._freeList=[],this._nextIndex=1,this._aliveCount=0,this._capacity=e,this._generations=new Uint32Array(e),this._alive=new Uint8Array(e),this._enabled=new Uint8Array(e),this._alive[0]=0,this._enabled[0]=0}var t=e.prototype;return t.create=function(){var e;this._freeList.length>0?e=this._freeList.pop():(e=this._nextIndex++)>=this._capacity&&this.grow(e);var t=this._generations[e];return this._alive[e]=1,this._enabled[e]=1,this._aliveCount++,it(e,t)},t.destroy=function(e){var t=ot(e),n=st(e);if(t>=this._capacity||0===t)return!1;if(this._generations[t]!==n)return!1;if(1!==this._alive[t])return!1;this._alive[t]=0,this._enabled[t]=0,this._aliveCount--;var r=(n+1)%rt;return this._generations[t]=r,this._freeList.push(t),!0},t.isAlive=function(e){var t=ot(e),n=st(e);return!(t>=this._capacity||0===t)&&(1===this._alive[t]&&this._generations[t]===n)},t.isEnabled=function(e){if(!this.isAlive(e))return!1;var t=ot(e);return 1===this._enabled[t]},t.setEnabled=function(e,t){if(!this.isAlive(e))return!1;var n=ot(e);return this._enabled[n]=t?1:0,!0},t.validate=function(e){return this.isAlive(e)},t.grow=function(e){for(var t=this._capacity;t<=e;)t<<=1;if(t>nt&&e>=(t=nt))throw new Error("EntityHandleManager: 超过最大实体数量 "+nt);var n=new Uint32Array(t),r=new Uint8Array(t),i=new Uint8Array(t);n.set(this._generations),r.set(this._alive),i.set(this._enabled),this._generations=n,this._alive=r,this._enabled=i,this._capacity=t},t.reset=function(){this._generations.fill(0),this._alive.fill(0),this._enabled.fill(0),this._freeList.length=0,this._nextIndex=1,this._aliveCount=0},t.forEach=function(e){for(var t=1;t<this._nextIndex;t++){if(1===this._alive[t])e(it(t,this._generations[t]))}},t.getAllAlive=function(){var e=[];return this.forEach(function(t){return e.push(t)}),e},o(e,[{key:"aliveCount",get:function(){return this._aliveCount}},{key:"capacity",get:function(){return this._capacity}}])}(),Yt=function(){function e(){this._current=1}var t=e.prototype;return t.increment=function(){this._current++,this._current>=Number.MAX_SAFE_INTEGER&&(this._current=1)},t.reset=function(){this._current=1},t.isChangedSince=function(e,t){return e>t},o(e,[{key:"current",get:function(){return this._current}}])}(),Jt=function(){function e(e){this.name="",this.sceneData=new Map,this._handleToEntity=new Map,this.epochManager=new Yt,this._performanceMonitor=null,this._didSceneBegin=!1,this.isEditorMode=!1,this._deferredComponentCallbacks=[],this._cachedSystems=null,this._systemsOrderDirty=!0,this._systemErrorCount=new Map,this._maxErrorCount=10,this._systemAddCounter=0,this._systemScheduler=new Qt,this._componentIdToSystems=new Map,this._globalNotifySystems=new Set,this.entities=new lt(this),this.identifierPool=new ht,this.componentStorageManager=new Re,this.querySystem=new Tt,this.eventSystem=new Mt,this.referenceTracker=new se,this.handleManager=new Vt,this._services=new Wt,this.logger=J("Scene"),null!=e&&e.name&&(this.name=e.name)}var t=e.prototype;return t._rebuildSystemsCache=function(){var e=this._services.getAll(),t=this._filterEntitySystems(e);try{return this._systemScheduler.markDirty(),this._systemScheduler.getAllSortedSystems(t)}catch(e){return e instanceof jt?this.logger.error("[Scene] 系统存在循环依赖,回退到 updateOrder 排序 | Cycle dependency detected, falling back to updateOrder sort",e.involvedNodes):this.logger.error("[Scene] 系统排序失败 | System sorting failed",e),this._sortSystemsByUpdateOrder(t)}},t._filterEntitySystems=function(e){return e.filter(function(e){return e instanceof Be})},t._sortSystemsByUpdateOrder=function(e){return e.sort(function(e,t){var n=e.updateOrder-t.updateOrder;return 0!==n?n:e.addOrder-t.addOrder})},t.getSystem=function(e){return this._services.tryResolve(e)},t.markSystemsOrderDirty=function(){this._systemsOrderDirty=!0},t.initialize=function(){},t.onStart=function(){},t.unload=function(){},t.queueDeferredComponentCallback=function(e){this._deferredComponentCallbacks.push(e)},t.begin=function(){if(this._didSceneBegin=!0,this._deferredComponentCallbacks.length>0){for(var e,t=s(this._deferredComponentCallbacks);!(e=t()).done;){var n=e.value;try{n()}catch(e){this.logger.error("Error executing deferred component callback:",e)}}this._deferredComponentCallbacks=[]}this.onStart()},t.end=function(){this._didSceneBegin=!1,this.unload(),this.entities.removeAllEntities(),this.querySystem.setEntities([]),this.componentStorageManager.clear(),this._services.clear(),this._cachedSystems=null,this._systemsOrderDirty=!0,this._componentIdToSystems.clear(),this._globalNotifySystems.clear(),this._handleToEntity.clear(),this.handleManager.reset(),this.epochManager.reset()},t.update=function(){this.epochManager.increment(),Ze.beginFrame();var e=Ze.beginSample("Scene.update",exports.ProfileCategory.ECS);try{Ue.getInstance().update(),this.entities.updateLists();var t=this.systems,n=Ze.beginSample("Systems.update",exports.ProfileCategory.ECS);try{for(var r,i=s(t);!(r=i()).done;){var o=r.value;if(o.enabled){var a=Ze.beginSample(o.systemName,exports.ProfileCategory.ECS);try{o.update()}catch(e){this._handleSystemError(o,"update",e)}finally{Ze.endSample(a)}}}}finally{Ze.endSample(n)}var c=Ze.beginSample("Systems.lateUpdate",exports.ProfileCategory.ECS);try{for(var u,l=s(t);!(u=l()).done;){var h=u.value;if(h.enabled){var d=Ze.beginSample(h.systemName+".late",exports.ProfileCategory.ECS);try{h.lateUpdate()}catch(e){this._handleSystemError(h,"lateUpdate",e)}finally{Ze.endSample(d)}}}}finally{Ze.endSample(c)}this.flushCommandBuffers(t)}finally{Ze.endSample(e),Ze.endFrame()}},t.flushCommandBuffers=function(e){var t=Ze.beginSample("Scene.flushCommandBuffers",exports.ProfileCategory.ECS);try{for(var n,r=s(e);!(n=r()).done;){var i=n.value;try{i.flushCommands()}catch(e){this.logger.error("Error flushing commands for system "+i.systemName+":",e)}}}finally{Ze.endSample(t)}},t._handleSystemError=function(e,t,n){var r=(this._systemErrorCount.get(e)||0)+1;this._systemErrorCount.set(e,r),this.logger.error("Error in system "+e.constructor.name+"."+t+"() ["+r+"/"+this._maxErrorCount+"]:",n),r>=this._maxErrorCount&&(e.enabled=!1,this.logger.error("System "+e.constructor.name+" has been disabled due to excessive errors ("+r+" errors)"))},t.createEntity=function(e){var t=new ut(e,this.identifierPool.checkOut()),n=this.handleManager.create();return t.setHandle(n),this._handleToEntity.set(n,t),this.eventSystem.emitSync("entity:created",{entityName:e,entity:t,scene:this}),this.addEntity(t)},t.clearSystemEntityCaches=function(){for(var e,t=s(this.systems);!(e=t()).done;){e.value.clearEntityCache()}},t.notifyEntityComponentChanged=function(e,t){var n=new Set;if(t&&K.isRegistered(t)){var r=K.getBitIndex(t),i=this._componentIdToSystems.get(r);if(i)for(var o,a=s(i);!(o=a()).done;){var c=o.value;c.handleEntityComponentChanged(e),n.add(c)}}for(var u,l=s(this._globalNotifySystems);!(u=l()).done;){var h=u.value;n.has(h)||(h.handleEntityComponentChanged(e),n.add(h))}if(!t)for(var d,f=s(this.systems);!(d=f()).done;){var p=d.value;n.has(p)||p.handleEntityComponentChanged(e)}},t.indexSystemByComponents=function(e){var t=e.matcher;if(t&&!t.isNothing()){var n=t.getCondition();if((n.none.length>0||void 0!==n.tag||void 0!==n.name)&&this._globalNotifySystems.add(e),t.isEmpty())this._globalNotifySystems.add(e);else{for(var r,i=s(n.all);!(r=i()).done;){var o=r.value;this.addSystemToComponentIndex(o,e)}for(var a,c=s(n.any);!(a=c()).done;){var u=a.value;this.addSystemToComponentIndex(u,e)}n.component&&this.addSystemToComponentIndex(n.component,e)}}},t.addSystemToComponentIndex=function(e,t){var n=K.getBitIndex(e),r=this._componentIdToSystems.get(n);r||(r=new Set,this._componentIdToSystems.set(n,r)),r.add(t)},t.removeSystemFromIndex=function(e){this._globalNotifySystems.delete(e);for(var t,n=s(this._componentIdToSystems.values());!(t=n()).done;){t.value.delete(e)}},t.addEntity=function(e,t){return void 0===t&&(t=!1),this.entities.add(e),e.scene=this,this.querySystem.addEntity(e,t),t||this.clearSystemEntityCaches(),this.eventSystem.emitSync("entity:added",{entity:e,scene:this}),e},t.createEntities=function(e,t){void 0===t&&(t="Entity");for(var n=[],r=0;r<e;r++){var i=new ut(t+"_"+r,this.identifierPool.checkOut());i.scene=this;var o=this.handleManager.create();i.setHandle(o),this._handleToEntity.set(o,i),n.push(i)}for(var s=0,a=n;s<a.length;s++){var c=a[s];this.entities.add(c)}return this.querySystem.addEntitiesUnchecked(n),this.eventSystem.emitSync("entities:batch_added",{entities:n,scene:this,count:e}),n},t.destroyEntities=function(e){if(0!==e.length){for(var t,n=s(e);!(t=n()).done;){t.value.setDestroyedState(!0)}for(var r,i=s(e);!(r=i()).done;){r.value.removeAllComponents()}for(var o,a=s(e);!(o=a()).done;){var c=o.value;this.entities.remove(c),this.querySystem.removeEntity(c),at(c.handle)&&(this._handleToEntity.delete(c.handle),this.handleManager.destroy(c.handle))}this.querySystem.clearCache(),this.clearSystemEntityCaches()}},t.destroyAllEntities=function(){this.entities.removeAllEntities(),this.querySystem.setEntities([])},t.findEntity=function(e){return this.entities.findEntity(e)},t.findEntityById=function(e){return this.entities.findEntityById(e)},t.findEntityByHandle=function(e){var t;return at(e)&&this.handleManager.isAlive(e)&&null!==(t=this._handleToEntity.get(e))&&void 0!==t?t:null},t.findEntitiesByTag=function(e){for(var t,n=[],r=s(this.entities.buffer);!(t=r()).done;){var i=t.value;i.tag===e&&n.push(i)}return n},t.findPersistentEntities=function(){return this.entities.buffer.filter(function(e){return e.isPersistent})},t.extractPersistentEntities=function(){for(var e,t=this.findPersistentEntities(),n=s(t);!(e=n()).done;){var r=e.value;this.entities.remove(r),this.querySystem.removeEntity(r),r.scene=null}return t},t.receiveMigratedEntities=function(e){for(var t,n=s(e);!(t=n()).done;){var r=t.value;r.scene=this,this.entities.add(r),this.querySystem.addEntity(r);for(var i,o=s(r.components);!(i=o()).done;){var a,c=i.value;this.componentStorageManager.addComponent(r.id,c),null===(a=this.referenceTracker)||void 0===a||a.registerEntityScene(r.id,this)}}e.length>0&&this.clearSystemEntityCaches()},t.getEntityByName=function(e){return this.findEntity(e)},t.getEntitiesByTag=function(e){return this.findEntitiesByTag(e)},t.queryAll=function(){var e;return(e=this.querySystem).queryAll.apply(e,arguments)},t.queryAny=function(){var e;return(e=this.querySystem).queryAny.apply(e,arguments)},t.queryNone=function(){var e;return(e=this.querySystem).queryNone.apply(e,arguments)},t.query=function(){return new It},t.addEntityProcessor=function(e){var t,n;if("function"==typeof e){if(n=e,this._services.isRegistered(n)){var r=this._services.resolve(n);return this.logger.debug("System "+n.name+" already registered, returning existing instance"),r}t=M(n)?x(n,this._services):new n}else if(n=(t=e).constructor,this._services.isRegistered(n)){var i=this._services.resolve(n);return i===t?(this.logger.debug("System "+n.name+" instance already registered, returning it"),t):(this.logger.warn("Attempting to register a different instance of "+n.name+", but type is already registered. Returning existing instance."),i)}t.scene=this,t.addOrder=this._systemAddCounter++,t.setPerformanceMonitor(this.performanceMonitor);var o=$(n);return void 0!==(null==o?void 0:o.updateOrder)&&t.setUpdateOrder(o.updateOrder),void 0!==(null==o?void 0:o.enabled)&&(t.enabled=o.enabled),this._services.registerInstance(n,t),this.markSystemsOrderDirty(),this.indexSystemByComponents(t),I(t,this._services),Ze.isEnabled()&&Ft.wrapInstance(t,t.systemName,exports.ProfileCategory.ECS),t.initialize(),this.logger.debug("System "+n.name+" registered and initialized"),t},t.registerSystems=function(e){for(var t,n=[],r=s(e);!(t=r()).done;){var i=t.value,o=this.addEntityProcessor(i);n.push(o)}return n},t.addSystem=function(e){return this.addEntityProcessor(e)},t.removeEntityProcessor=function(e){var t=e.constructor;this._services.unregister(t),this.markSystemsOrderDirty(),this.removeSystemFromIndex(e),e.reset()},t.removeSystem=function(e){this.removeEntityProcessor(e)},t.getEntityProcessor=function(e){return this._services.tryResolve(e)},t.getStats=function(){return{entityCount:this.entities.count,processorCount:this.systems.length,componentStorageStats:this.componentStorageManager.getAllStats()}},t.getDebugInfo=function(){var e=this.systems;return{name:this.name||this.constructor.name,entityCount:this.entities.count,processorCount:e.length,isRunning:this._didSceneBegin,entities:this.entities.buffer.map(function(e){return{name:e.name,id:e.id,componentCount:e.components.length,componentTypes:e.components.map(function(e){return H(e)})}}),processors:e.map(function(e){return{name:te(e),updateOrder:e.updateOrder,entityCount:e.entities.length}}),componentStats:this.componentStorageManager.getAllStats()}},t.serialize=function(e){return Rt.serialize(this,e)},t.deserialize=function(e,t){Rt.deserialize(this,e,t)},t.createIncrementalSnapshot=function(e){this._incrementalBaseSnapshot=zt.createSnapshot(this,e)},t.serializeIncremental=function(e){if(!this._incrementalBaseSnapshot)throw new Error("必须先调用 createIncrementalSnapshot() 创建基础快照");return zt.computeIncremental(this,this._incrementalBaseSnapshot,e)},t.applyIncremental=function(e,t){var n="string"==typeof e||e instanceof Uint8Array?zt.deserializeIncremental(e):e,r=t||K.getAllComponentNames();zt.applyIncremental(this,n,r)},t.updateIncrementalSnapshot=function(e){this.createIncrementalSnapshot(e)},t.clearIncrementalSnapshot=function(){this._incrementalBaseSnapshot=void 0},t.hasIncrementalSnapshot=function(){return void 0!==this._incrementalBaseSnapshot},o(e,[{key:"systems",get:function(){return!this._systemsOrderDirty&&this._cachedSystems||(this._cachedSystems=this._rebuildSystemsCache(),this._systemsOrderDirty=!1),this._cachedSystems}},{key:"services",get:function(){return this._services}},{key:"performanceMonitor",get:function(){var e;this._performanceMonitor||(this._performanceMonitor=null!==(e=this._services.tryResolve(P))&&void 0!==e?e:new P);return this._performanceMonitor}}])}(),Kt=function(){function e(e,t){this.scene=e,this.storageManager=t;var n=e.identifierPool.checkOut();this.entity=new ut("",n),this.entity.scene=this.scene}var t=e.prototype;return t.named=function(e){return this.entity.name=e,this},t.tagged=function(e){return this.entity.tag=e,this},t.with=function(e){return this.entity.addComponent(e),this},t.withComponents=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=0,i=t;r<i.length;r++){var o=i[r];this.entity.addComponent(o)}return this},t.withIf=function(e,t){return e&&this.entity.addComponent(t),this},t.withFactory=function(e){var t=e();return this.entity.addComponent(t),this},t.configure=function(e,t){var n=this.entity.getComponent(e);return n&&t(n),this},t.enabled=function(e){return void 0===e&&(e=!0),this.entity.enabled=e,this},t.active=function(e){return void 0===e&&(e=!0),this.entity.active=e,this},t.withChild=function(e){var t=e.build(),n=this.scene.getSystem(Le);return null==n||n.setParent(t,this.entity),this},t.withChildren=function(){for(var e=this.scene.getSystem(Le),t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];for(var i=0,o=n;i<o.length;i++){var s=o[i].build();null==e||e.setParent(s,this.entity)}return this},t.withChildFactory=function(e){var t=e(this.entity).build(),n=this.scene.getSystem(Le);return null==n||n.setParent(t,this.entity),this},t.withChildIf=function(e,t){if(e){var n=t.build(),r=this.scene.getSystem(Le);null==r||r.setParent(n,this.entity)}return this},t.build=function(){return this.entity},t.spawn=function(){return this.scene.addEntity(this.entity),this.entity},t.clone=function(){var t=new e(this.scene,this.storageManager);return t.entity=this.entity,t},e}(),Zt=function(){function e(){this.scene=new Jt}var t=e.prototype;return t.named=function(e){return this.scene.name=e,this},t.withEntity=function(e){return this.scene.addEntity(e),this},t.withEntityBuilder=function(e){var t=e(new Kt(this.scene,this.scene.componentStorageManager)).build();return this.scene.addEntity(t),this},t.withEntities=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=0,i=t;r<i.length;r++){var o=i[r];this.scene.addEntity(o)}return this},t.withSystem=function(e){return this.scene.addSystem(e),this},t.withSystems=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var r=0,i=t;r<i.length;r++){var o=i[r];this.scene.addSystem(o)}return this},t.build=function(){return this.scene},e}(),Xt=function(){function e(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];this.component=r(e,n)}var t=e.prototype;return t.set=function(e,t){return this.component[e]=t,this},t.configure=function(e){return e(this.component),this},t.setIf=function(e,t,n){return e&&(this.component[t]=n),this},t.build=function(){return this.component},e}(),$t=function(){function e(e){this.entities=e}var t=e.prototype;return t.addComponent=function(e){for(var t,n=s(this.entities);!(t=n()).done;){t.value.addComponent(e)}return this},t.removeComponent=function(e){for(var t,n=s(this.entities);!(t=n()).done;){t.value.removeComponentByType(e)}return this},t.setActive=function(e){for(var t,n=s(this.entities);!(t=n()).done;){t.value.active=e}return this},t.setTag=function(e){for(var t,n=s(this.entities);!(t=n()).done;){t.value.tag=e}return this},t.forEach=function(e){return this.entities.forEach(e),this},t.filter=function(t){return new e(this.entities.filter(t))},t.toArray=function(){return this.entities.slice()},t.count=function(){return this.entities.length},e}(),en=function(){function e(e,t,n){this.scene=e,this.querySystem=t,this.eventSystem=n}var t=e.prototype;return t.createEntity=function(){return new Kt(this.scene,this.scene.componentStorageManager)},t.createScene=function(){return new Zt},t.createComponent=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];return r(Xt,[e].concat(n))},t.query=function(){return new wt(this.querySystem)},t.find=function(){var e;return(e=this.querySystem).queryAll.apply(e,arguments).entities},t.findFirst=function(){var e,t=(e=this.querySystem).queryAll.apply(e,arguments);return t.entities.length>0?t.entities[0]:null},t.findByName=function(e){return this.scene.findEntity(e)},t.findByTag=function(e){return this.scene.findEntitiesByTag(e)},t.emit=function(e,t){this.eventSystem.emitSync(e,t)},t.emitAsync=function(){var e=n(h().m(function e(t,n){return h().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.eventSystem.emit(t,n);case 1:return e.a(2)}},e,this)}));return function(t,n){return e.apply(this,arguments)}}(),t.on=function(e,t){return this.eventSystem.on(e,t)},t.once=function(e,t){return this.eventSystem.once(e,t)},t.off=function(e,t){this.eventSystem.off(e,t)},t.batch=function(e){return new $t(e)},t.getStats=function(){return{entityCount:this.scene.entities.count,systemCount:this.scene.systems.length,componentStats:this.scene.componentStorageManager.getAllStats(),queryStats:this.querySystem.getStats(),eventStats:this.eventSystem.getStats()}},e}();function tn(e,t,n){return new en(e,t,n)}var nn,rn=J("World"),on=function(){function e(e){void 0===e&&(e={}),this._scenes=new Map,this._activeScenes=new Set,this._globalSystems=[],this._isActive=!1,this._config=a({name:"World",debug:!1,maxScenes:10,autoCleanup:!0},e),this.name=this._config.name,this._createdAt=Date.now(),this._services=new Wt}var t=e.prototype;return t.createScene=function(e,t){if(!e||"string"!=typeof e||""===e.trim())throw new Error("Scene name不能为空");if(this._scenes.has(e))throw new Error("Scene name '"+e+"' 已存在于World '"+this.name+"' 中");if(this._scenes.size>=this._config.maxScenes)throw new Error("World '"+this.name+"' 已达到最大Scene数量限制: "+this._config.maxScenes);var n=t||new Jt;if(this._config.debug){var r=new P;r.enable(),n.services.registerInstance(P,r)}return"id"in n&&(n.id=e),"name"in n&&!n.name&&(n.name=e),this._scenes.set(e,n),n.initialize(),n},t.removeScene=function(e){var t=this._scenes.get(e);return!!t&&(this._activeScenes.has(e)&&this.setSceneActive(e,!1),t.end(),this._scenes.delete(e),rn.info("从World '"+this.name+"' 中移除Scene: "+e),!0)},t.getScene=function(e){return this._scenes.get(e)||null},t.getSceneIds=function(){return Array.from(this._scenes.keys())},t.getAllScenes=function(){return Array.from(this._scenes.values())},t.removeAllScenes=function(){for(var e=0,t=Array.from(this._scenes.keys());e<t.length;e++){var n=t[e];this.removeScene(n)}rn.info("从World '"+this.name+"' 中移除所有Scene")},t.setSceneActive=function(e,t){var n=this._scenes.get(e);n?t?(this._activeScenes.add(e),n.begin&&n.begin(),rn.debug("在World '"+this.name+"' 中激活Scene: "+e)):(this._activeScenes.delete(e),rn.debug("在World '"+this.name+"' 中停用Scene: "+e)):rn.warn("Scene '"+e+"' 不存在于World '"+this.name+"' 中")},t.isSceneActive=function(e){return this._activeScenes.has(e)},t.getActiveSceneCount=function(){return this._activeScenes.size},t.addGlobalSystem=function(e){return this._globalSystems.includes(e)||(this._globalSystems.push(e),e.initialize&&e.initialize(),rn.debug("在World '"+this.name+"' 中添加全局System: "+e.name)),e},t.removeGlobalSystem=function(e){var t=this._globalSystems.indexOf(e);return-1!==t&&(this._globalSystems.splice(t,1),e.reset&&e.reset(),rn.debug("从World '"+this.name+"' 中移除全局System: "+e.name),!0)},t.getGlobalSystem=function(e){for(var t,n=s(this._globalSystems);!(t=n()).done;){var r=t.value;if(r instanceof e)return r}return null},t.start=function(){if(!this._isActive){this._isActive=!0;for(var e,t=s(this._globalSystems);!(e=t()).done;){var n=e.value;n.initialize&&n.initialize()}rn.info("启动World: "+this.name)}},t.stop=function(){if(this._isActive){for(var e,t=s(this._activeScenes);!(e=t()).done;){var n=e.value;this.setSceneActive(n,!1)}for(var r,i=s(this._globalSystems);!(r=i()).done;){var o=r.value;o.reset&&o.reset()}this._isActive=!1,rn.info("停止World: "+this.name)}},t.updateGlobalSystems=function(){if(this._isActive)for(var e,t=s(this._globalSystems);!(e=t()).done;){var n=e.value;n.update&&n.update()}},t.updateScenes=function(){if(this._isActive){for(var e,t=s(this._activeScenes);!(e=t()).done;){var n=e.value,r=this._scenes.get(n);r&&r.update&&r.update()}this._config.autoCleanup&&this.shouldAutoCleanup()&&this.cleanup()}},t.destroy=function(){rn.info("销毁World: "+this.name),this.stop();for(var e=0,t=Array.from(this._scenes.keys());e<t.length;e++){var n=t[e];this.removeScene(n)}for(var r,i=s(this._globalSystems);!(r=i()).done;){var o=r.value;o.destroy?o.destroy():o.reset&&o.reset()}this._globalSystems.length=0,this._services.clear(),this._scenes.clear(),this._activeScenes.clear()},t.getStatus=function(){var e=this;return{name:this.name,isActive:this._isActive,sceneCount:this._scenes.size,activeSceneCount:this._activeScenes.size,globalSystemCount:this._globalSystems.length,createdAt:this._createdAt,config:a({},this._config),scenes:Array.from(this._scenes.keys()).map(function(t){var n;return{id:t,isActive:e._activeScenes.has(t),name:(null===(n=e._scenes.get(t))||void 0===n?void 0:n.name)||t}})}},t.getStats=function(){for(var e,t={totalEntities:0,totalSystems:this._globalSystems.length,memoryUsage:0,performance:{averageUpdateTime:0,maxUpdateTime:0}},n=s(this._scenes.values());!(e=n()).done;){var r=e.value;r.entities&&(t.totalEntities+=r.entities.count),r.systems&&(t.totalSystems+=r.systems.length)}return t},t.shouldAutoCleanup=function(){for(var e,t=Date.now(),n=s(this._scenes);!(e=n()).done;){var r=e.value,i=r[0],o=r[1];if(!this._activeScenes.has(i)&&o.entities&&0===o.entities.count&&t-this._createdAt>3e5)return!0}return!1},t.cleanup=function(){for(var e=Array.from(this._scenes.keys()),t=Date.now(),n=0,r=e;n<r.length;n++){var i=r[n],o=this._scenes.get(i);o&&!this._activeScenes.has(i)&&o.entities&&0===o.entities.count&&t-this._createdAt>3e5&&(this.removeScene(i),rn.debug("自动清理空Scene: "+i+" from World "+this.name))}},o(e,[{key:"services",get:function(){return this._services}},{key:"isActive",get:function(){return this._isActive}},{key:"sceneCount",get:function(){return this._scenes.size}},{key:"createdAt",get:function(){return this._createdAt}}])}(),sn=function(){function e(e){this._nextScene=null,this._ecsAPI=null,this._logger=J("SceneManager"),this._performanceMonitor=null,this._pendingPersistentEntities=[],this._defaultWorld=new on({name:"__default__"}),this._defaultWorld.start(),this._performanceMonitor=e||null}var t=e.prototype;return t.setSceneChangedCallback=function(e){this._onSceneChangedCallback=e},t.setScene=function(t){var n=this.currentScene;return n&&n instanceof Jt&&(this._pendingPersistentEntities=n.extractPersistentEntities(),this._pendingPersistentEntities.length>0&&this._logger.debug("Extracted "+this._pendingPersistentEntities.length+" persistent entities for migration")),this._defaultWorld.removeAllScenes(),this._performanceMonitor&&t.services.registerInstance(P,this._performanceMonitor),this._defaultWorld.createScene(e.DEFAULT_SCENE_ID,t),this._defaultWorld.setSceneActive(e.DEFAULT_SCENE_ID,!0),this._pendingPersistentEntities.length>0&&t instanceof Jt&&(t.receiveMigratedEntities(this._pendingPersistentEntities),this._logger.debug("Migrated "+this._pendingPersistentEntities.length+" persistent entities to new scene"),this._pendingPersistentEntities=[]),t.querySystem&&t.eventSystem?this._ecsAPI=tn(t,t.querySystem,t.eventSystem):this._ecsAPI=null,g.sceneChanged(),this._onSceneChangedCallback&&this._onSceneChangedCallback(),this._logger.info("Scene changed to: "+t.name),t},t.loadScene=function(e){this._nextScene=e,this._logger.info("Scheduled scene load: "+e.name)},t.update=function(){this._nextScene&&(this.setScene(this._nextScene),this._nextScene=null),this._defaultWorld.updateGlobalSystems(),this._defaultWorld.updateScenes()},t.destroy=function(){this._logger.info("SceneManager destroying"),this._defaultWorld.destroy(),this._nextScene=null,this._ecsAPI=null,this._logger.info("SceneManager destroyed")},t.dispose=function(){this.destroy()},o(e,[{key:"currentScene",get:function(){return this._defaultWorld.getScene(e.DEFAULT_SCENE_ID)}},{key:"api",get:function(){return this._ecsAPI}},{key:"hasScene",get:function(){return null!==this._defaultWorld.getScene(e.DEFAULT_SCENE_ID)}},{key:"hasPendingScene",get:function(){return null!==this._nextScene}}])}();sn.DEFAULT_SCENE_ID="__main__",exports.DebugConfigService=function(){function e(){this._config={enabled:!1,websocketUrl:"",debugFrameRate:30,autoReconnect:!0,channels:{entities:!0,systems:!0,performance:!0,components:!0,scenes:!0}}}var t=e.prototype;return t.setConfig=function(e){this._config=e},t.getConfig=function(){return this._config},t.isEnabled=function(){return this._config.enabled},t.dispose=function(){},e}(),exports.DebugConfigService=v([b(),y("design:paramtypes",[])],exports.DebugConfigService),exports.DebugManager=function(){function e(){this.frameCounter=0,this.lastSendTime=0,this.sendInterval=0,this.isRunning=!1,this.originalConsole={log:console.log.bind(console),debug:console.debug.bind(console),info:console.info.bind(console),warn:console.warn.bind(console),error:console.error.bind(console)}}var t=e.prototype;return t.onInitialize=function(){this.config=this.configService.getConfig(),this.entityCollector=new He,this.systemCollector=new We,this.performanceCollector=new je,this.componentCollector=new qe,this.sceneCollector=new Ve,this.advancedProfilerCollector=new Xe,Ze.setEnabled(!0),this.webSocketManager=new Ye(this.config.websocketUrl,!1!==this.config.autoReconnect),this.webSocketManager.setMessageHandler(this.handleMessage.bind(this));var e=this.config.debugFrameRate||30;this.sendInterval=1e3/e,this.interceptConsole(),this.start()},t.start=function(){this.isRunning||(this.isRunning=!0,this.connectWebSocket())},t.stop=function(){this.isRunning&&(this.isRunning=!1,this.webSocketManager.disconnect())},t.interceptConsole=function(){var e=this;console.log=function(){for(var t,n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];e.sendLog("info",e.formatLogMessage(r)),(t=e.originalConsole).log.apply(t,r)},console.debug=function(){for(var t,n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];e.sendLog("debug",e.formatLogMessage(r)),(t=e.originalConsole).debug.apply(t,r)},console.info=function(){for(var t,n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];e.sendLog("info",e.formatLogMessage(r)),(t=e.originalConsole).info.apply(t,r)},console.warn=function(){for(var t,n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];e.sendLog("warn",e.formatLogMessage(r)),(t=e.originalConsole).warn.apply(t,r)},console.error=function(){for(var t,n=arguments.length,r=new Array(n),i=0;i<n;i++)r[i]=arguments[i];e.sendLog("error",e.formatLogMessage(r)),(t=e.originalConsole).error.apply(t,r)}},t.formatLogMessage=function(e){var t=this;return e.map(function(e){if("string"==typeof e)return e;if(e instanceof Error)return e.name+": "+e.message;if(null===e)return"null";if(void 0===e)return"undefined";if("object"==typeof e)try{return t.safeStringify(e,6)}catch(t){return Object.prototype.toString.call(e)}return String(e)}).join(" ")},t.safeStringify=function(e,t){void 0===t&&(t=6);var n=new WeakSet,r=function(e,i){if(null===e)return null;if(void 0!==e){if("object"!=typeof e)return e;if(i>=t)return"[Max Depth Reached]";if(n.has(e))return"[Circular]";if(n.add(e),Array.isArray(e)){var o=e.map(function(e){return r(e,i+1)});return n.delete(e),o}var s={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(s[a]=r(e[a],i+1));return n.delete(e),s}};return JSON.stringify(r(e,0))},t.sendLog=function(e,t){if(this.webSocketManager.getConnectionStatus())try{this.webSocketManager.send({type:"log",data:{level:e,message:t,timestamp:(new Date).toISOString()}})}catch(e){}},t.updateConfig=function(e){this.config=e;var t=e.debugFrameRate||30;this.sendInterval=1e3/t,this.webSocketManager&&e.websocketUrl&&(this.webSocketManager.disconnect(),this.webSocketManager=new Ye(e.websocketUrl,!1!==e.autoReconnect),this.webSocketManager.setMessageHandler(this.handleMessage.bind(this)),this.connectWebSocket())},t.update=function(e){if(this.isRunning&&this.config.enabled){this.frameCounter++;var t=Date.now();t-this.lastSendTime>=this.sendInterval&&(this.sendDebugData(),this.lastSendTime=t)}},t.onSceneChanged=function(){this.isRunning&&this.config.enabled&&this.sendDebugData()},t.handleMessage=function(e){try{switch(e.type){case"capture_memory_snapshot":this.handleMemorySnapshotRequest();break;case"config_update":e.config&&this.updateConfig(a({},this.config,e.config));break;case"expand_lazy_object":this.handleExpandLazyObjectRequest(e);break;case"get_component_properties":this.handleGetComponentPropertiesRequest(e);break;case"get_raw_entity_list":this.handleGetRawEntityListRequest(e);break;case"get_entity_details":this.handleGetEntityDetailsRequest(e);break;case"get_advanced_profiler_data":this.handleGetAdvancedProfilerDataRequest(e);break;case"set_profiler_selected_function":this.handleSetProfilerSelectedFunction(e);break;case"ping":this.webSocketManager.send({type:"pong",timestamp:Date.now()})}}catch(t){e.requestId&&this.webSocketManager.send({type:"error_response",requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}},t.handleExpandLazyObjectRequest=function(e){try{var t=e.entityId,n=e.componentIndex,r=e.propertyPath,i=e.requestId;if(void 0===t||void 0===n||!r)return void this.webSocketManager.send({type:"expand_lazy_object_response",requestId:i,error:"缺少必要参数"});var o=this.sceneManager.currentScene,s=this.entityCollector.expandLazyObject(t,n,r,o);this.webSocketManager.send({type:"expand_lazy_object_response",requestId:i,data:s})}catch(t){this.webSocketManager.send({type:"expand_lazy_object_response",requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}},t.handleGetComponentPropertiesRequest=function(e){try{var t=e.entityId,n=e.componentIndex,r=e.requestId;if(void 0===t||void 0===n)return void this.webSocketManager.send({type:"get_component_properties_response",requestId:r,error:"缺少必要参数"});var i=this.sceneManager.currentScene,o=this.entityCollector.getComponentProperties(t,n,i);this.webSocketManager.send({type:"get_component_properties_response",requestId:r,data:o})}catch(t){this.webSocketManager.send({type:"get_component_properties_response",requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}},t.handleGetRawEntityListRequest=function(e){try{var t=e.requestId,n=this.sceneManager.currentScene,r=this.entityCollector.getRawEntityList(n);this.webSocketManager.send({type:"get_raw_entity_list_response",requestId:t,data:r})}catch(t){this.webSocketManager.send({type:"get_raw_entity_list_response",requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}},t.handleGetEntityDetailsRequest=function(e){try{var t=e.entityId,n=e.requestId;if(void 0===t)return void this.webSocketManager.send({type:"get_entity_details_response",requestId:n,error:"缺少实体ID参数"});var r=this.sceneManager.currentScene,i=this.entityCollector.getEntityDetails(t,r);this.webSocketManager.send({type:"get_entity_details_response",requestId:n,data:i})}catch(t){this.webSocketManager.send({type:"get_entity_details_response",requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}},t.handleGetAdvancedProfilerDataRequest=function(e){try{var t=e.requestId,n=Ze.isEnabled()?this.advancedProfilerCollector.collectAdvancedData(this.performanceMonitor):this.advancedProfilerCollector.collectFromLegacyMonitor(this.performanceMonitor);this.webSocketManager.send({type:"get_advanced_profiler_data_response",requestId:t,data:n})}catch(t){this.webSocketManager.send({type:"get_advanced_profiler_data_response",requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}},t.handleSetProfilerSelectedFunction=function(e){try{var t=e.functionName,n=e.requestId;this.advancedProfilerCollector.setSelectedFunction(t||null),this.sendDebugData(),this.webSocketManager.send({type:"set_profiler_selected_function_response",requestId:n,success:!0})}catch(t){this.webSocketManager.send({type:"set_profiler_selected_function_response",requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}},t.handleMemorySnapshotRequest=function(){try{var e=this.captureMemorySnapshot();this.webSocketManager.send({type:"memory_snapshot_response",data:e})}catch(e){this.webSocketManager.send({type:"memory_snapshot_error",error:e instanceof Error?e.message:"内存快照捕获失败"})}},t.captureMemorySnapshot=function(){var e=Date.now(),t=this.collectBaseMemoryInfo(),n=this.sceneManager.currentScene,r=this.entityCollector.collectEntityDataWithMemory(n),i=null!=n&&n.entities?this.collectComponentMemoryStats(n.entities):{totalMemory:0,componentTypes:0,totalInstances:0,breakdown:[]},o=this.collectSystemMemoryStats(),s=this.collectPoolMemoryStats(),a=this.collectPerformanceStats(),c=r.entitiesPerArchetype.reduce(function(e,t){return e+t.memory},0);return{timestamp:e,version:"2.0",summary:{totalEntities:r.totalEntities,totalMemoryUsage:t.usedMemory,totalMemoryLimit:t.totalMemory,memoryUtilization:t.usedMemory/t.totalMemory*100,gcCollections:t.gcCollections,entityMemory:c,componentMemory:i.totalMemory,systemMemory:o.totalMemory,poolMemory:s.totalMemory},baseMemory:t,entities:{totalMemory:c,entityCount:r.totalEntities,archetypes:r.entitiesPerArchetype,largestEntities:r.topEntitiesByComponents},components:i,systems:o,pools:s,performance:a}},t.collectBaseMemoryInfo=function(){var e={totalMemory:0,usedMemory:0,freeMemory:0,gcCollections:0,heapInfo:null,detailedMemory:void 0};try{var t=performance;if(t.memory){var n=t.memory;e.totalMemory=n.jsHeapSizeLimit||536870912,e.usedMemory=n.usedJSHeapSize||0,e.freeMemory=e.totalMemory-e.usedMemory,e.heapInfo={totalJSHeapSize:n.totalJSHeapSize||0,usedJSHeapSize:n.usedJSHeapSize||0,jsHeapSizeLimit:n.jsHeapSizeLimit||0}}else e.totalMemory=536870912,e.freeMemory=536870912;t.measureUserAgentSpecificMemory&&t.measureUserAgentSpecificMemory().then(function(t){e.detailedMemory=t}).catch(function(){})}catch(e){}return e},t.collectComponentMemoryStats=function(e){for(var t,n=new Map,r=0,i=new Map,o=s(e.buffer);!(t=o()).done;){var a=t.value;if(a&&!a.destroyed&&a.components)for(var c,u=s(a.components);!(c=u()).done;){var l=H(c.value);i.set(l,(i.get(l)||0)+1)}}for(var h,d=s(i.entries());!(h=d()).done;){var f=h.value,p=f[0],m=f[1],v=this.componentCollector.calculateDetailedComponentMemory(p),y=v*m;r+=y;for(var g,_=[],S=0,C=s(e.buffer);!(g=C()).done;){var E=g.value;if(E&&!E.destroyed&&E.components){for(var b,T=s(E.components);!(b=T()).done;){if(H(b.value)===p&&(_.push({entityId:E.id,entityName:E.name||"Entity_"+E.id,memory:v}),++S>=100))break}if(S>=100)break}}n.set(p,{count:m,totalMemory:y,instances:_.slice(0,10)})}var w=Array.from(n.entries()).map(function(e){var t=e[0],n=e[1];return{typeName:t,instanceCount:n.count,totalMemory:n.totalMemory,averageMemory:n.totalMemory/n.count,percentage:r>0?n.totalMemory/r*100:0,largestInstances:n.instances.sort(function(e,t){return t.memory-e.memory}).slice(0,3)}}).sort(function(e,t){return t.totalMemory-e.totalMemory});return{totalMemory:r,componentTypes:n.size,totalInstances:Array.from(n.values()).reduce(function(e,t){return e+t.count},0),breakdown:w}},t.collectSystemMemoryStats=function(){var e=this.sceneManager.currentScene,t=0,n=[];try{var r=null==e?void 0:e.systems;if(r)for(var i,o=new Map,a=s(r);!(i=a()).done;){var c=i.value,u=te(c),l=void 0;o.has(u)?l=o.get(u):(l=this.calculateQuickSystemSize(c),o.set(u,l)),t+=l,n.push({name:u,memory:l,enabled:!1!==c.enabled,updateOrder:c.updateOrder||0})}}catch(e){}return{totalMemory:t,systemCount:n.length,breakdown:n.sort(function(e,t){return t.memory-e.memory})}},t.calculateQuickSystemSize=function(e){if(!e||"object"!=typeof e)return 64;var t=128;try{for(var n=Object.keys(e),r=0;r<Math.min(n.length,15);r++){var i=n[r];if(i&&"entities"!==i&&"scene"!==i&&"constructor"!==i){var o=e[i];t+=2*i.length,"string"==typeof o?t+=Math.min(2*o.length,100):"number"==typeof o?t+=8:"boolean"==typeof o?t+=4:Array.isArray(o)?t+=40+Math.min(8*o.length,200):"object"==typeof o&&null!==o&&(t+=64)}}}catch(e){return 128}return Math.max(t,64)},t.collectPoolMemoryStats=function(){var e=0,t=[];try{for(var n,r=s(Ue.getInstance().getPoolStats().entries());!(n=r()).done;){var i=n.value,o=i[0],a=i[1],c=32*a.maxSize;e+=c,t.push({typeName:o,maxSize:a.maxSize,currentSize:a.currentSize||0,estimatedMemory:c,utilization:a.currentSize?a.currentSize/a.maxSize*100:0})}}catch(e){}try{for(var u=O.getAllPoolStats(),l=0,h=Object.entries(u);l<h.length;l++){var d=h[l],f=d[0],p=d[1];e+=p.estimatedMemoryUsage,t.push({typeName:"Pool_"+f,maxSize:p.maxSize,currentSize:p.size,estimatedMemory:p.estimatedMemoryUsage,utilization:p.size/p.maxSize*100,hitRate:100*p.hitRate})}}catch(e){}return{totalMemory:e,poolCount:t.length,breakdown:t.sort(function(e,t){return t.estimatedMemory-e.estimatedMemory})}},t.collectPerformanceStats=function(){try{var e;if(!this.performanceMonitor)return{enabled:!1};var t=this.performanceMonitor.getAllSystemStats(),n=this.performanceMonitor.getPerformanceWarnings();return{enabled:null!==(e=this.performanceMonitor.enabled)&&void 0!==e&&e,systemCount:t.size,warnings:n.slice(0,10),topSystems:Array.from(t.entries()).map(function(e){var t=e[0],n=e[1];return{name:t,averageTime:n.averageTime,maxTime:n.maxTime,samples:n.executionCount}}).sort(function(e,t){return t.averageTime-e.averageTime}).slice(0,5)}}catch(e){return{enabled:!1,error:e instanceof Error?e.message:String(e)}}},t.getDebugData=function(){var e=Date.now(),t=this.sceneManager.currentScene,n={timestamp:e,frameworkVersion:"1.0.0",isRunning:this.isRunning,frameworkLoaded:!0,currentScene:(null==t?void 0:t.name)||"Unknown"};return this.config.channels.entities&&(n.entities=this.entityCollector.collectEntityData(t)),this.config.channels.systems&&(n.systems=this.systemCollector.collectSystemData(this.performanceMonitor,t)),this.config.channels.performance&&(n.performance=this.performanceCollector.collectPerformanceData(this.performanceMonitor)),this.config.channels.components&&(n.components=this.componentCollector.collectComponentData(t)),this.config.channels.scenes&&(n.scenes=this.sceneCollector.collectSceneData(t)),n},t.connectWebSocket=function(){var e=n(h().m(function e(){return h().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,e.n=1,this.webSocketManager.connect();case 1:e.n=3;break;case 2:e.p=2,e.v;case 3:return e.a(2)}},e,this,[[0,2]])}));return function(){return e.apply(this,arguments)}}(),t.sendDebugData=function(){if(this.webSocketManager.getConnectionStatus())try{var e={type:"debug_data",data:this.getDebugData(),advancedProfiler:Ze.isEnabled()?this.advancedProfilerCollector.collectAdvancedData(this.performanceMonitor):null};this.webSocketManager.send(e)}catch(e){}},t.dispose=function(){this.stop(),console.log=this.originalConsole.log,console.debug=this.originalConsole.debug,console.info=this.originalConsole.info,console.warn=this.originalConsole.warn,console.error=this.originalConsole.error},e}(),v([w(sn),y("design:type",sn)],exports.DebugManager.prototype,"sceneManager",void 0),v([w(P),y("design:type",P)],exports.DebugManager.prototype,"performanceMonitor",void 0),v([w(exports.DebugConfigService),y("design:type",exports.DebugConfigService)],exports.DebugManager.prototype,"configService",void 0),exports.DebugManager=v([b(),T()],exports.DebugManager),exports.PluginState=void 0,(nn=exports.PluginState||(exports.PluginState={})).NotInstalled="not_installed",nn.Installed="installed",nn.Failed="failed";var an=J("PluginManager"),cn=function(){function e(){this._plugins=new Map,this._metadata=new Map,this._core=null,this._services=null}var t=e.prototype;return t.initialize=function(e,t){this._core=e,this._services=t,an.info("PluginManager initialized")},t.install=function(){var e=n(h().m(function e(t){var n,r;return h().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this._core&&this._services){e.n=1;break}throw new Error("PluginManager not initialized. Call initialize() first.");case 1:if(!this._plugins.has(t.name)){e.n=2;break}return an.warn("Plugin "+t.name+" is already installed"),e.a(2);case 2:return t.dependencies&&t.dependencies.length>0&&this._checkDependencies(t),n={name:t.name,version:t.version,state:exports.PluginState.NotInstalled,installedAt:Date.now()},this._metadata.set(t.name,n),e.p=3,an.info("Installing plugin: "+t.name+" v"+t.version),e.n=4,t.install(this._core,this._services);case 4:this._plugins.set(t.name,t),n.state=exports.PluginState.Installed,an.info("Plugin "+t.name+" installed successfully"),e.n=6;break;case 5:throw e.p=5,r=e.v,n.state=exports.PluginState.Failed,n.error=r instanceof Error?r.message:String(r),an.error("Failed to install plugin "+t.name+":",r),r;case 6:return e.a(2)}},e,this,[[3,5]])}));return function(t){return e.apply(this,arguments)}}(),t.uninstall=function(){var e=n(h().m(function e(t){var n,r;return h().w(function(e){for(;;)switch(e.p=e.n){case 0:if(n=this._plugins.get(t)){e.n=1;break}throw new Error("Plugin "+t+" is not installed");case 1:return this._checkDependents(t),e.p=2,an.info("Uninstalling plugin: "+t),e.n=3,n.uninstall();case 3:this._plugins.delete(t),this._metadata.delete(t),an.info("Plugin "+t+" uninstalled successfully"),e.n=5;break;case 4:throw e.p=4,r=e.v,an.error("Failed to uninstall plugin "+t+":",r),r;case 5:return e.a(2)}},e,this,[[2,4]])}));return function(t){return e.apply(this,arguments)}}(),t.getPlugin=function(e){return this._plugins.get(e)},t.getMetadata=function(e){return this._metadata.get(e)},t.getAllPlugins=function(){return Array.from(this._plugins.values())},t.getAllMetadata=function(){return Array.from(this._metadata.values())},t.isInstalled=function(e){return this._plugins.has(e)},t._checkDependencies=function(e){if(e.dependencies){for(var t,n=[],r=s(e.dependencies);!(t=r()).done;){var i=t.value;this._plugins.has(i)||n.push(i)}if(n.length>0)throw new Error("Plugin "+e.name+" has unmet dependencies: "+n.join(", "))}},t._checkDependents=function(e){for(var t,n=[],r=s(this._plugins.values());!(t=r()).done;){var i=t.value;i.dependencies&&i.dependencies.includes(e)&&n.push(i.name)}if(n.length>0)throw new Error("Cannot uninstall plugin "+e+": it is required by "+n.join(", "))},t.dispose=function(){for(var e,t=s(Array.from(this._plugins.values()).reverse());!(e=t()).done;){var n=e.value;try{an.info("Disposing plugin: "+n.name),n.uninstall()}catch(e){an.error("Error disposing plugin "+n.name+":",e)}}this._plugins.clear(),this._metadata.clear(),this._core=null,this._services=null,an.info("PluginManager disposed")},e}();function un(e){var t="@esengine/service:"+e;return{id:Symbol.for(t),name:e}}var ln=function(){function e(){this._services=new Map}var t=e.prototype;return t.register=function(e,t){this._services.set(e.id,t)},t.get=function(e){return this._services.get(e.id)},t.require=function(e){var t=this._services.get(e.id);if(void 0===t)throw new Error("Service not found: "+e.name);return t},t.has=function(e){return this._services.has(e.id)},t.unregister=function(e){return this._services.delete(e.id)},t.clear=function(){this._services.clear()},t.dispose=function(){this.clear()},e}(),hn=J("WorldManager"),dn=function(){function e(e){void 0===e&&(e={}),this._worlds=new Map,this._isRunning=!1,this._framesSinceCleanup=0,this._config=a({maxWorlds:50,autoCleanup:!0,cleanupFrameInterval:1800,debug:!1},e),this._isRunning=!0,hn.info("WorldManager已初始化",{maxWorlds:this._config.maxWorlds,autoCleanup:this._config.autoCleanup,cleanupFrameInterval:this._config.cleanupFrameInterval})}var t=e.prototype;return t.createWorld=function(e,t){var n,r;if(!e||"string"!=typeof e||""===e.trim())throw new Error("World name不能为空");if(this._worlds.has(e))throw new Error("World name '"+e+"' 已存在");if(this._worlds.size>=this._config.maxWorlds)throw new Error("已达到最大World数量限制: "+this._config.maxWorlds);var i=a({name:e,debug:null!==(n=null!==(r=null==t?void 0:t.debug)&&void 0!==r?r:this._config.debug)&&void 0!==n&&n},void 0!==(null==t?void 0:t.maxScenes)&&{maxScenes:t.maxScenes},void 0!==(null==t?void 0:t.autoCleanup)&&{autoCleanup:t.autoCleanup}),o=new on(i);return this._worlds.set(e,o),o},t.removeWorld=function(e){var t=this._worlds.get(e);return!!t&&(t.destroy(),this._worlds.delete(e),hn.info("移除World: "+e),!0)},t.getWorld=function(e){return this._worlds.get(e)||null},t.getWorldIds=function(){return Array.from(this._worlds.keys())},t.getAllWorlds=function(){return Array.from(this._worlds.values())},t.setWorldActive=function(e,t){var n=this._worlds.get(e);n?t?(n.start(),hn.debug("激活World: "+e)):(n.stop(),hn.debug("停用World: "+e)):hn.warn("World '"+e+"' 不存在")},t.isWorldActive=function(e){var t,n=this._worlds.get(e);return null!==(t=null==n?void 0:n.isActive)&&void 0!==t&&t},t.updateAll=function(){if(this._isRunning){for(var e,t=s(this._worlds.values());!(e=t()).done;){var n=e.value;n.isActive&&(n.updateGlobalSystems(),n.updateScenes())}this._config.autoCleanup&&(this._framesSinceCleanup++,this._framesSinceCleanup>=this._config.cleanupFrameInterval&&(this.cleanup(),this._framesSinceCleanup=0,this._config.debug&&hn.debug("执行定期清理World (间隔: "+this._config.cleanupFrameInterval+" 帧)")))}},t.getActiveWorlds=function(){for(var e,t=[],n=s(this._worlds.values());!(e=n()).done;){var r=e.value;r.isActive&&t.push(r)}return t},t.startAll=function(){this._isRunning=!0;for(var e,t=s(this._worlds.values());!(e=t()).done;){e.value.start()}hn.info("启动所有World")},t.stopAll=function(){this._isRunning=!1;for(var e,t=s(this._worlds.values());!(e=t()).done;){e.value.stop()}hn.info("停止所有World")},t.findWorlds=function(e){for(var t,n=[],r=s(this._worlds.values());!(t=r()).done;){var i=t.value;e(i)&&n.push(i)}return n},t.findWorldByName=function(e){for(var t,n=s(this._worlds.values());!(t=n()).done;){var r=t.value;if(r.name===e)return r}return null},t.getStats=function(){for(var e,t={totalWorlds:this._worlds.size,activeWorlds:this.activeWorldCount,totalScenes:0,totalEntities:0,totalSystems:0,memoryUsage:0,isRunning:this._isRunning,config:a({},this._config),worlds:[]},n=s(this._worlds);!(e=n()).done;){var r=e.value,i=r[0],o=r[1],c=o.getStats();t.totalScenes+=c.totalSystems,t.totalEntities+=c.totalEntities,t.totalSystems+=c.totalSystems,t.worlds.push(a({id:i,name:o.name,isActive:o.isActive,sceneCount:o.sceneCount},c))}return t},t.getDetailedStatus=function(){return a({},this.getStats(),{worlds:Array.from(this._worlds.entries()).map(function(e){var t=e[0],n=e[1];return{id:t,isActive:n.isActive,status:n.getStatus()}})})},t.cleanup=function(){for(var e,t=[],n=s(this._worlds);!(e=n()).done;){var r=e.value,i=r[0],o=r[1];this.shouldCleanupWorld(o)&&t.push(i)}for(var a=0,c=t;a<c.length;a++){var u=c[a];this.removeWorld(u)}return t.length>0&&hn.debug("清理了 "+t.length+" 个World"),t.length},t.destroy=function(){hn.info("正在销毁WorldManager..."),this.stopAll();for(var e=0,t=Array.from(this._worlds.keys());e<t.length;e++){var n=t[e];this.removeWorld(n)}this._worlds.clear(),this._isRunning=!1,hn.info("WorldManager已销毁")},t.dispose=function(){this.destroy()},t.shouldCleanupWorld=function(e){if(e.isActive)return!1;var t=Date.now()-e.createdAt>6e5;return(0===e.sceneCount||!e.getAllScenes().some(function(e){return e.entities&&e.entities.count>0}))&&t},o(e,[{key:"worldCount",get:function(){return this._worlds.size}},{key:"activeWorldCount",get:function(){for(var e,t=0,n=s(this._worlds.values());!(e=n()).done;){e.value.isActive&&t++}return t}},{key:"isRunning",get:function(){return this._isRunning}},{key:"config",get:function(){return a({},this._config)}}])}(),fn=function(){function e(t){var n,r,i=this;if(void 0===t&&(t={}),e._instance=this,this._config=a({debug:!0},t),this._serviceContainer=new Wt,this._timerManager=new exports.TimerManager,this._serviceContainer.registerInstance(exports.TimerManager,this._timerManager),this._performanceMonitor=new P,this._serviceContainer.registerInstance(P,this._performanceMonitor),this._config.debug&&this._performanceMonitor.enable(),this._poolManager=new R,this._serviceContainer.registerInstance(R,this._poolManager),this._sceneManager=new sn(this._performanceMonitor),this._serviceContainer.registerInstance(sn,this._sceneManager),this._sceneManager.setSceneChangedCallback(function(){i._debugManager&&i._debugManager.onSceneChanged()}),this._worldManager=new dn(a({debug:!!this._config.debug},this._config.worldManagerConfig)),this._serviceContainer.registerInstance(dn,this._worldManager),this._pluginManager=new cn,this._pluginManager.initialize(this,this._serviceContainer),this._serviceContainer.registerInstance(cn,this._pluginManager),this._pluginServiceRegistry=new ln,this._serviceContainer.registerInstance(ln,this._pluginServiceRegistry),this.debug=null===(n=this._config.debug)||void 0===n||n,null!==(r=this._config.debugConfig)&&void 0!==r&&r.enabled){var o=new exports.DebugConfigService;o.setConfig(this._config.debugConfig),this._serviceContainer.registerInstance(exports.DebugConfigService,o),this._serviceContainer.registerSingleton(exports.DebugManager,function(e){return x(exports.DebugManager,e)}),this._debugManager=this._serviceContainer.resolve(exports.DebugManager),this._debugManager.onInitialize()}this.initialize()}e.create=function(t){if(void 0===t&&(t=!0),null==this._instance){var n="boolean"==typeof t?{debug:t}:t;this._instance=new e(n)}else this._logger.warn("Core实例已创建,返回现有实例");return this._instance},e.setScene=function(t){if(!this._instance)throw e._logger.warn("Core实例未创建,请先调用Core.create()"),new Error("Core实例未创建");return this._instance._sceneManager.setScene(t)},e.loadScene=function(t){this._instance?this._instance._sceneManager.loadScene(t):e._logger.warn("Core实例未创建,请先调用Core.create()")},e.update=function(t){this._instance?this._instance.updateInternal(t):e._logger.warn("Core实例未创建,请先调用Core.create()")},e.schedule=function(e,t,n,r){if(void 0===t&&(t=!1),!this._instance)throw new Error("Core实例未创建,请先调用Core.create()");if(!r)throw new Error("onTime callback is required");return this._instance._timerManager.schedule(e,t,n,r)},e.enableDebug=function(t){if(this._instance){if(this._instance._debugManager)this._instance._debugManager.updateConfig(t);else{var n=new exports.DebugConfigService;n.setConfig(t),this._instance._serviceContainer.registerInstance(exports.DebugConfigService,n),this._instance._serviceContainer.registerSingleton(exports.DebugManager,function(e){return x(exports.DebugManager,e)}),this._instance._debugManager=this._instance._serviceContainer.resolve(exports.DebugManager),this._instance._debugManager.onInitialize()}this._instance._config.debugConfig=t}else e._logger.warn("Core实例未创建,请先调用Core.create()")},e.disableDebug=function(){this._instance&&(this._instance._debugManager&&(this._instance._debugManager.stop(),delete this._instance._debugManager),this._instance._config.debugConfig&&(this._instance._config.debugConfig.enabled=!1))},e.getDebugData=function(){var e;return null!==(e=this._instance)&&void 0!==e&&e._debugManager?this._instance._debugManager.getDebugData():null},e.installPlugin=function(){var e=n(h().m(function e(t){return h().w(function(e){for(;;)switch(e.n){case 0:if(this._instance){e.n=1;break}throw new Error("Core实例未创建,请先调用Core.create()");case 1:return e.n=2,this._instance._pluginManager.install(t);case 2:return e.a(2)}},e,this)}));return function(t){return e.apply(this,arguments)}}(),e.uninstallPlugin=function(){var e=n(h().m(function e(t){return h().w(function(e){for(;;)switch(e.n){case 0:if(this._instance){e.n=1;break}throw new Error("Core实例未创建,请先调用Core.create()");case 1:return e.n=2,this._instance._pluginManager.uninstall(t);case 2:return e.a(2)}},e,this)}));return function(t){return e.apply(this,arguments)}}(),e.getPlugin=function(e){if(this._instance)return this._instance._pluginManager.getPlugin(e)},e.isPluginInstalled=function(e){return!!this._instance&&this._instance._pluginManager.isInstalled(e)};var t=e.prototype;return t.initialize=function(){var t;e._logger.info("Core initialized",{debug:this.debug,debugEnabled:(null===(t=this._config.debugConfig)||void 0===t?void 0:t.enabled)||!1})},t.updateInternal=function(t){if(!e.paused){var n=this._performanceMonitor.startMonitoring("Core.update");g.update(t),"updateFPS"in this._performanceMonitor&&"function"==typeof this._performanceMonitor.updateFPS&&this._performanceMonitor.updateFPS(g.deltaTime);var r=this._performanceMonitor.startMonitoring("Services.update");this._serviceContainer.updateAll(t),this._performanceMonitor.endMonitoring("Services.update",r,this._serviceContainer.getUpdatableCount()),this._poolManager.update(),this._sceneManager.update(),this._worldManager.updateAll(),this._performanceMonitor.endMonitoring("Core.update",n)}},e.destroy=function(){this._instance&&(this._instance._debugManager&&this._instance._debugManager.stop(),this._instance._serviceContainer.clear(),e._logger.info("Core destroyed"),this._instance=null)},o(e,null,[{key:"Instance",get:function(){return this._instance}},{key:"services",get:function(){if(!this._instance)throw new Error("Core实例未创建,请先调用Core.create()");return this._instance._serviceContainer}},{key:"pluginServices",get:function(){if(!this._instance)throw new Error("Core实例未创建,请先调用Core.create()");return this._instance._pluginServiceRegistry}},{key:"worldManager",get:function(){if(!this._instance)throw new Error("Core实例未创建,请先调用Core.create()");return this._instance._worldManager}},{key:"scene",get:function(){return this._instance?this._instance._sceneManager.currentScene:null}},{key:"ecsAPI",get:function(){return this._instance?this._instance._sceneManager.api:null}},{key:"isDebugEnabled",get:function(){var e;return(null===(e=this._instance)||void 0===e||null===(e=e._config.debugConfig)||void 0===e?void 0:e.enabled)||!1}},{key:"performanceMonitor",get:function(){var e;return(null===(e=this._instance)||void 0===e?void 0:e._performanceMonitor)||null}}])}();fn.paused=!1,fn._instance=null,fn._logger=J("Core");var pn=un("runtimeMode"),mn=function(){function e(e){var t,n,r;void 0===e&&(e={}),this._callbacks=new Set,this._isEditor=null!==(t=e.isEditor)&&void 0!==t&&t,this._isPlaying=null!==(n=e.isPlaying)&&void 0!==n&&n,this._isPreview=null!==(r=e.isPreview)&&void 0!==r&&r}var t=e.prototype;return t.onModeChanged=function(e){var t=this;return this._callbacks.add(e),function(){t._callbacks.delete(e)}},t.setEditorMode=function(e){this._isEditor!==e&&(this._isEditor=e,this._notifyChange())},t.setPlaying=function(e){this._isPlaying!==e&&(this._isPlaying=e,this._notifyChange())},t.setPreview=function(e){this._isPreview!==e&&(this._isPreview=e,this._notifyChange())},t.updateMode=function(e){var t=!1;void 0!==e.isEditor&&this._isEditor!==e.isEditor&&(this._isEditor=e.isEditor,t=!0),void 0!==e.isPlaying&&this._isPlaying!==e.isPlaying&&(this._isPlaying=e.isPlaying,t=!0),void 0!==e.isPreview&&this._isPreview!==e.isPreview&&(this._isPreview=e.isPreview,t=!0),t&&this._notifyChange()},t._notifyChange=function(){for(var e,t=s(this._callbacks);!(e=t()).done;){var n=e.value;try{n(this)}catch(e){console.error("[RuntimeModeService] Callback error:",e)}}},t.dispose=function(){this._callbacks.clear()},o(e,[{key:"isEditor",get:function(){return this._isEditor}},{key:"isPlaying",get:function(){return this._isPlaying}},{key:"isPreview",get:function(){return this._isPreview}},{key:"isStandalone",get:function(){return!this._isEditor}}])}();var vn=J("DebugPlugin");exports.DebugPlugin=function(){function e(e){var t,n;this.name="@esengine/debug-plugin",this.version="1.0.0",this.worldManager=null,this.updateTimer=null,this.autoStart=null!==(t=null==e?void 0:e.autoStart)&&void 0!==t&&t,this.updateInterval=null!==(n=null==e?void 0:e.updateInterval)&&void 0!==n?n:1e3}var t=e.prototype;return t.install=function(){var e=n(h().m(function e(t,n){return h().w(function(e){for(;;)switch(e.n){case 0:this.worldManager=n.resolve(dn),vn.info("ECS Debug Plugin installed"),this.autoStart&&this.start();case 1:return e.a(2)}},e,this)}));return function(t,n){return e.apply(this,arguments)}}(),t.uninstall=function(){var e=n(h().m(function e(){return h().w(function(e){for(;;)switch(e.n){case 0:this.stop(),this.worldManager=null,vn.info("ECS Debug Plugin uninstalled");case 1:return e.a(2)}},e,this)}));return function(){return e.apply(this,arguments)}}(),t.dispose=function(){this.stop(),this.worldManager=null},t.start=function(){var e=this;this.updateTimer?vn.warn("Debug monitoring already started"):(vn.info("Starting debug monitoring"),this.updateTimer=setInterval(function(){e.logStats()},this.updateInterval))},t.stop=function(){this.updateTimer&&(clearInterval(this.updateTimer),this.updateTimer=null,vn.info("Debug monitoring stopped"))},t.getStats=function(){if(!this.worldManager)throw new Error("Plugin not installed");for(var e,t=[],n=0,r=0,i=s(this.worldManager.getAllWorlds());!(e=i()).done;)for(var o,a=s(e.value.getAllScenes());!(o=a()).done;){var c=o.value,u=this.getSceneInfo(c);t.push(u),n+=u.entityCount,r+=u.systems.length}return{scenes:t,totalEntities:n,totalSystems:r,timestamp:Date.now()}},t.getSceneInfo=function(e){var t=this,n=e.entities.buffer,r=e.systems;return{name:e.name,entityCount:n.length,systems:r.map(function(e){return t.getSystemInfo(e)}),entities:n.map(function(e){return t.getEntityInfo(e)})}},t.getSystemInfo=function(e){var t=e.getPerformanceStats(),n=t?{avgExecutionTime:t.averageTime,maxExecutionTime:t.maxTime,totalCalls:t.executionCount}:void 0;return a({name:e.constructor.name,enabled:e.enabled,updateOrder:e.updateOrder,entityCount:e.entities.length},void 0!==n&&{performance:n})},t.getEntityInfo=function(e){var t=this,n=e.components;return{id:e.id,name:e.name,enabled:e.enabled,tag:e.tag,componentCount:n.length,components:n.map(function(e){return t.getComponentInfo(e)})}},t.getComponentInfo=function(e){for(var t=e.constructor.name,n={},r=0,i=Object.keys(e);r<i.length;r++){var o=i[r];if(!o.startsWith("_")){var s=e[o];"function"!=typeof s&&(n[o]=s)}}return{type:t,data:n}},t.queryEntities=function(e){if(!this.worldManager)throw new Error("Plugin not installed");for(var t,n=[],r=s(this.worldManager.getAllWorlds());!(t=r()).done;)for(var i,o=s(t.value.getAllScenes());!(i=o()).done;){var a=i.value;if(!e.sceneName||a.name===e.sceneName)for(var c,u=s(a.entities.buffer);!(c=u()).done;){var l=c.value;if((void 0===e.tag||l.tag===e.tag)&&(!e.name||l.name.includes(e.name))){if(e.hasComponent)if(!l.components.some(function(t){return t.constructor.name===e.hasComponent}))continue;n.push(this.getEntityInfo(l))}}}return n},t.logStats=function(){var e=this.getStats();vn.info("=== ECS Debug Stats ==="),vn.info("Total Entities: "+e.totalEntities),vn.info("Total Systems: "+e.totalSystems),vn.info("Scenes: "+e.scenes.length);for(var t,n=s(e.scenes);!(t=n()).done;){var r=t.value;vn.info("\n[Scene: "+r.name+"]"),vn.info(" Entities: "+r.entityCount),vn.info(" Systems: "+r.systems.length);for(var i,o=s(r.systems);!(i=o()).done;){var a=i.value,c=a.performance?" | Avg: "+a.performance.avgExecutionTime.toFixed(2)+"ms, Max: "+a.performance.maxExecutionTime.toFixed(2)+"ms":"";vn.info(" - "+a.name+" ("+(a.enabled?"enabled":"disabled")+") | Entities: "+a.entityCount+c)}}vn.info("========================\n")},t.exportJSON=function(){var e=this.getStats();return JSON.stringify(e,null,2)},e}(),exports.DebugPlugin=v([b(),y("design:paramtypes",[Object])],exports.DebugPlugin);var yn,gn,_n=function(e,t){this.func=e,this.context=t},Sn=function(){function e(){this._messageTable=new Map}var t=e.prototype;return t.addObserver=function(e,t,n){var r=this._messageTable.get(e);r||(r=[],this._messageTable.set(e,r)),this.hasObserver(e,t)||r.push(new _n(t,n))},t.removeObserver=function(e,t){var n=this._messageTable.get(e);if(n){var r=n.findIndex(function(e){return e.func==t});-1!=r&&n.splice(r,1)}},t.emit=function(e){var t=this._messageTable.get(e);if(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++)r[i-1]=arguments[i];for(var o,a=s(t);!(o=a()).done;){var c,u=o.value;(c=u.func).call.apply(c,[u.context].concat(r))}}},t.hasObserver=function(e,t){var n=this._messageTable.get(e);return!!n&&n.some(function(e){return e.func===t})},t.removeAllObservers=function(e){void 0!==e?this._messageTable.delete(e):this._messageTable.clear()},t.dispose=function(){this._messageTable.clear()},t.getEventTypeCount=function(){return this._messageTable.size},t.getObserverCount=function(e){var t=this._messageTable.get(e);return t?t.length:0},e}(),Cn=function(){function e(){this._enabled=!1}var t=e.prototype;return t.setEnabled=function(e){this._enabled!=e&&(this._enabled=e,this._enabled?this.onEnabled():this.onDisabled())},t.onEnabled=function(){},t.onDisabled=function(){},t.update=function(){},o(e,[{key:"enabled",get:function(){return this._enabled},set:function(e){this.setEnabled(e)}}])}();exports.ECSEventType=void 0,(yn=exports.ECSEventType||(exports.ECSEventType={})).ENTITY_CREATED="entity:created",yn.ENTITY_DESTROYED="entity:destroyed",yn.ENTITY_ENABLED="entity:enabled",yn.ENTITY_DISABLED="entity:disabled",yn.ENTITY_TAG_ADDED="entity:tag:added",yn.ENTITY_TAG_REMOVED="entity:tag:removed",yn.ENTITY_NAME_CHANGED="entity:name:changed",yn.COMPONENT_ADDED="component:added",yn.COMPONENT_REMOVED="component:removed",yn.COMPONENT_MODIFIED="component:modified",yn.COMPONENT_ENABLED="component:enabled",yn.COMPONENT_DISABLED="component:disabled",yn.SYSTEM_ADDED="system:added",yn.SYSTEM_REMOVED="system:removed",yn.SYSTEM_ENABLED="system:enabled",yn.SYSTEM_DISABLED="system:disabled",yn.SYSTEM_PROCESSING_START="system:processing:start",yn.SYSTEM_PROCESSING_END="system:processing:end",yn.SYSTEM_ERROR="system:error",yn.SCENE_CREATED="scene:created",yn.SCENE_DESTROYED="scene:destroyed",yn.SCENE_ACTIVATED="scene:activated",yn.SCENE_DEACTIVATED="scene:deactivated",yn.SCENE_PAUSED="scene:paused",yn.SCENE_RESUMED="scene:resumed",yn.QUERY_EXECUTED="query:executed",yn.QUERY_CACHE_HIT="query:cache:hit",yn.QUERY_CACHE_MISS="query:cache:miss",yn.QUERY_OPTIMIZED="query:optimized",yn.PERFORMANCE_WARNING="performance:warning",yn.PERFORMANCE_CRITICAL="performance:critical",yn.MEMORY_USAGE_HIGH="memory:usage:high",yn.FRAME_RATE_DROP="frame:rate:drop",yn.INDEX_CREATED="index:created",yn.INDEX_UPDATED="index:updated",yn.INDEX_OPTIMIZED="index:optimized",yn.ARCHETYPE_CREATED="archetype:created",yn.ARCHETYPE_ENTITY_ADDED="archetype:entity:added",yn.ARCHETYPE_ENTITY_REMOVED="archetype:entity:removed",yn.DIRTY_MARK_ADDED="dirty:mark:added",yn.DIRTY_BATCH_PROCESSED="dirty:batch:processed",yn.ERROR_OCCURRED="error:occurred",yn.WARNING_ISSUED="warning:issued",yn.FRAMEWORK_INITIALIZED="framework:initialized",yn.FRAMEWORK_SHUTDOWN="framework:shutdown",yn.DEBUG_INFO="debug:info",yn.DEBUG_STATS_UPDATED="debug:stats:updated",exports.EventPriority=void 0,(gn=exports.EventPriority||(exports.EventPriority={}))[gn.LOWEST=0]="LOWEST",gn[gn.LOW=25]="LOW",gn[gn.NORMAL=50]="NORMAL",gn[gn.HIGH=75]="HIGH",gn[gn.HIGHEST=100]="HIGHEST",gn[gn.CRITICAL=200]="CRITICAL";var En={ENTITY:{CREATED:exports.ECSEventType.ENTITY_CREATED,DESTROYED:exports.ECSEventType.ENTITY_DESTROYED,ENABLED:exports.ECSEventType.ENTITY_ENABLED,DISABLED:exports.ECSEventType.ENTITY_DISABLED,TAG_ADDED:exports.ECSEventType.ENTITY_TAG_ADDED,TAG_REMOVED:exports.ECSEventType.ENTITY_TAG_REMOVED,NAME_CHANGED:exports.ECSEventType.ENTITY_NAME_CHANGED},COMPONENT:{ADDED:exports.ECSEventType.COMPONENT_ADDED,REMOVED:exports.ECSEventType.COMPONENT_REMOVED,MODIFIED:exports.ECSEventType.COMPONENT_MODIFIED,ENABLED:exports.ECSEventType.COMPONENT_ENABLED,DISABLED:exports.ECSEventType.COMPONENT_DISABLED},SYSTEM:{ADDED:exports.ECSEventType.SYSTEM_ADDED,REMOVED:exports.ECSEventType.SYSTEM_REMOVED,ENABLED:exports.ECSEventType.SYSTEM_ENABLED,DISABLED:exports.ECSEventType.SYSTEM_DISABLED,PROCESSING_START:exports.ECSEventType.SYSTEM_PROCESSING_START,PROCESSING_END:exports.ECSEventType.SYSTEM_PROCESSING_END,ERROR:exports.ECSEventType.SYSTEM_ERROR},PERFORMANCE:{WARNING:exports.ECSEventType.PERFORMANCE_WARNING,CRITICAL:exports.ECSEventType.PERFORMANCE_CRITICAL,MEMORY_HIGH:exports.ECSEventType.MEMORY_USAGE_HIGH,FRAME_DROP:exports.ECSEventType.FRAME_RATE_DROP}},bn=function(){function e(){}return e.isValid=function(e){return this.validTypes.has(e)},e.getAllValidTypes=function(){return Array.from(this.validTypes)},e.addCustomType=function(e){this.validTypes.add(e)},e.removeCustomType=function(e){this.validTypes.delete(e)},e}();bn.validTypes=new Set([].concat(Object.values(exports.ECSEventType),Object.values(En.ENTITY),Object.values(En.COMPONENT),Object.values(En.SYSTEM),Object.values(En.PERFORMANCE)));var Tn=function(e){function t(t){return e.call(this,t)||this}return u(t,e),t.prototype.process=function(e){this.processSystem()},t}(Be),wn=function(e){function t(t){return e.call(this,t)||this}return u(t,e),t.prototype.process=function(e){},t}(Be),Mn=function(e){function t(t,n){var r;return(r=e.call(this,n)||this).acc=0,r.intervalRemainder=0,r.interval=t,r}u(t,e);var n=t.prototype;return n.onCheckProcessing=function(){return this.acc+=g.deltaTime,this.acc>=this.interval&&(this.intervalRemainder=this.acc-this.interval,this.acc=0,!0)},n.getIntervalDelta=function(){return this.interval+this.intervalRemainder},t}(Be),xn=function(){function e(){this.adapter=null,this.logger=J("PlatformManager")}e.getInstance=function(){return e.instance||(e.instance=new e),e.instance};var t=e.prototype;return t.getAdapter=function(){if(!this.adapter)throw new Error("平台适配器未注册,请调用 registerAdapter() 注册适配器");return this.adapter},t.registerAdapter=function(e){this.adapter=e,this.logger.info("平台适配器已注册: "+e.name,{name:e.name,version:e.version,supportsWorker:e.isWorkerSupported(),supportsSharedArrayBuffer:e.isSharedArrayBufferSupported(),hardwareConcurrency:e.getHardwareConcurrency()})},t.hasAdapter=function(){return null!==this.adapter},t.getAdapterInfo=function(){return this.adapter?{name:this.adapter.name,version:this.adapter.version,config:this.adapter.getPlatformConfig()}:null},t.supportsFeature=function(e){if(!this.adapter)return!1;var t=this.adapter.getPlatformConfig();switch(e){case"worker":return this.adapter.isWorkerSupported();case"shared-array-buffer":return this.adapter.isSharedArrayBufferSupported();case"transferable-objects":return t.supportsTransferableObjects;case"module-worker":return t.supportsModuleWorker;default:return!1}},t.getBasicWorkerConfig=function(){if(!this.adapter)return{platformSupportsWorker:!1,platformSupportsSharedArrayBuffer:!1,platformMaxWorkerCount:1,platformLimitations:{}};var e=this.adapter.getPlatformConfig();return{platformSupportsWorker:this.adapter.isWorkerSupported(),platformSupportsSharedArrayBuffer:this.adapter.isSharedArrayBufferSupported(),platformMaxWorkerCount:e.maxWorkerCount,platformLimitations:e.limitations||{}}},t.getFullPlatformConfig=function(){var e=n(h().m(function e(){return h().w(function(e){for(;;)switch(e.n){case 0:if(this.adapter){e.n=1;break}throw new Error("平台适配器未注册");case 1:if("function"!=typeof this.adapter.getPlatformConfigAsync){e.n=3;break}return e.n=2,this.adapter.getPlatformConfigAsync();case 2:return e.a(2,e.v);case 3:return e.a(2,this.adapter.getPlatformConfig())}},e,this)}));return function(){return e.apply(this,arguments)}}(),e}(),In=function(e){function t(t,n){var r,i,o,s,c,u;void 0===n&&(n={}),(u=e.call(this,t)||this).workerPool=null,u.isProcessing=!1,u.sharedBuffer=null,u.sharedFloatArray=null,u.hasLoggedSyncMode=!1,u.platformAdapter=xn.getInstance().getAdapter();var l=null!==(r=n.workerCount)&&void 0!==r?r:u.getMaxSystemWorkerCount(),h=u.getMaxSystemWorkerCount(),d=Math.min(l,h);return l>h&&u.logger.warn("请求 "+l+" 个Worker,但系统最多支持 "+h+" 个。实际使用 "+d+" 个Worker。"),u.config=a({enableWorker:null===(i=n.enableWorker)||void 0===i||i,workerCount:d,systemConfig:n.systemConfig},void 0!==n.entitiesPerWorker&&{entitiesPerWorker:n.entitiesPerWorker},{useSharedArrayBuffer:null!==(o=n.useSharedArrayBuffer)&&void 0!==o?o:u.isSharedArrayBufferSupported(),entityDataSize:null!==(s=n.entityDataSize)&&void 0!==s?s:u.getDefaultEntityDataSize(),maxEntities:null!==(c=n.maxEntities)&&void 0!==c?c:1e4},void 0!==n.workerScriptPath&&{workerScriptPath:n.workerScriptPath}),u.config.enableWorker&&u.isWorkerSupported()&&(u.config.useSharedArrayBuffer&&u.initializeSharedArrayBuffer(),u.initializeWorkerPool()),u}u(t,e);var r=t.prototype;return r.isWorkerSupported=function(){return this.platformAdapter.isWorkerSupported()},r.isSharedArrayBufferSupported=function(){return this.platformAdapter.isSharedArrayBufferSupported()},r.getMaxSystemWorkerCount=function(){return this.platformAdapter.getPlatformConfig().maxWorkerCount},r.initializeSharedArrayBuffer=function(){try{if(!this.isSharedArrayBufferSupported())return this.logger.warn(this.systemName+": 平台不支持SharedArrayBuffer,降级到单Worker模式以保证数据处理完整性"),this.config.useSharedArrayBuffer=!1,void(this.config.workerCount=1);var e=this.config.maxEntities*this.config.entityDataSize*4;this.sharedBuffer=this.platformAdapter.createSharedArrayBuffer(e),this.sharedBuffer&&(this.sharedFloatArray=new Float32Array(this.sharedBuffer)),this.logger.info(this.systemName+": SharedArrayBuffer初始化成功 ("+e+" 字节)")}catch(e){this.logger.warn(this.systemName+": SharedArrayBuffer初始化失败,降级到单Worker模式以保证数据处理完整性",e),this.config.useSharedArrayBuffer=!1,this.sharedBuffer=null,this.sharedFloatArray=null,this.config.workerCount=1}},r.initializeWorkerPool=function(){try{var e,t,n=this.platformAdapter.getPlatformConfig(),r=[];if(this.config.workerScriptPath)t=this.config.workerScriptPath,this.logger.info(this.systemName+": 使用外部Worker文件: "+t);else{if(null!==(e=n.limitations)&&void 0!==e&&e.noEval)return this.logger.error(this.systemName+": 当前平台不支持动态Worker脚本,请配置 workerScriptPath 指定预编译的Worker文件"),void(this.config.enableWorker=!1);var i=this.createWorkerScript();t=(n.workerScriptPrefix||"")+i}for(var o=0;o<this.config.workerCount;o++)try{var s=this.platformAdapter.createWorker(t,{name:"WorkerEntitySystem-"+o});r.push(s)}catch(e){throw this.logger.error("创建Worker "+o+" 失败:",e),e}this.workerPool=new An(r)}catch(e){this.logger.error(this.systemName+": Worker池初始化失败",e),this.config.enableWorker=!1}},r.createWorkerScript=function(){var e,t=this.workerProcess.toString().match(/\{([\s\S]*)\}/);if(!t)throw new Error("无法解析workerProcess方法");var n=t[1],r=this.config.entityDataSize,i=(null===(e=this.getSharedArrayBufferProcessFunction)||void 0===e?void 0:e.call(this))||null,o="";if(i){var s,a=i.toString().match(/\{([\s\S]*)\}/);if(a)o=null!==(s=a[1])&&void 0!==s?s:""}return"\n // Worker脚本 - 支持SharedArrayBuffer\n let sharedFloatArray = null;\n const ENTITY_DATA_SIZE = "+r+";\n\n self.onmessage = function(e) {\n const { type, id, entities, deltaTime, systemConfig, startIndex, endIndex, sharedBuffer } = e.data;\n\n\n try {\n // 处理SharedArrayBuffer初始化\n if (type === 'init' && sharedBuffer) {\n sharedFloatArray = new Float32Array(sharedBuffer);\n self.postMessage({ type: 'init', success: true });\n return;\n }\n\n // 处理SharedArrayBuffer数据\n if (type === 'shared' && sharedFloatArray) {\n processSharedArrayBuffer(startIndex, endIndex, deltaTime, systemConfig);\n self.postMessage({ id, result: null }); // SharedArrayBuffer不需要返回数据\n return;\n }\n\n // 传统处理方式\n if (entities) {\n // 定义处理函数\n function workerProcess(entities, deltaTime, systemConfig) {\n "+n+"\n }\n\n // 执行处理\n const result = workerProcess(entities, deltaTime, systemConfig);\n\n // 处理Promise返回值\n if (result && typeof result.then === 'function') {\n result.then(finalResult => {\n self.postMessage({ id, result: finalResult });\n }).catch(error => {\n self.postMessage({ id, error: error.message });\n });\n } else {\n self.postMessage({ id, result });\n }\n }\n } catch (error) {\n self.postMessage({ id, error: error.message });\n }\n };\n\n // SharedArrayBuffer处理函数 - 由子类定义\n function processSharedArrayBuffer(startIndex, endIndex, deltaTime, systemConfig) {\n if (!sharedFloatArray) return;\n\n "+(o?"\n // 用户定义的处理函数\n const userProcessFunction = function(sharedFloatArray, startIndex, endIndex, deltaTime, systemConfig) {\n "+o+"\n };\n userProcessFunction(sharedFloatArray, startIndex, endIndex, deltaTime, systemConfig);\n ":"")+"\n }\n "},r.process=function(e){var t=this;if(!this.isProcessing){this.isProcessing=!0;try{this.config.enableWorker&&this.workerPool?this.config.useSharedArrayBuffer&&this.sharedFloatArray&&this.isSharedArrayBufferSupported()?this.processWithSharedArrayBuffer(e).finally(function(){t.isProcessing=!1}):(this.config.useSharedArrayBuffer&&this.logger.info(this.systemName+": 本帧降级到传统Worker模式"),this.processWithWorker(e).finally(function(){t.isProcessing=!1})):(this.hasLoggedSyncMode||(this.logger.info(this.systemName+": Worker不可用,使用同步处理"),this.hasLoggedSyncMode=!0),this.processSynchronously(e),this.isProcessing=!1)}catch(e){throw this.isProcessing=!1,this.logger.error(this.systemName+": 处理失败",e),e}}},r.processWithSharedArrayBuffer=function(){var e=n(h().m(function e(t){var n;return h().w(function(e){for(;;)switch(e.n){case 0:if(this.sharedFloatArray){e.n=1;break}throw new Error("SharedArrayBuffer not initialized");case 1:return this.writeEntitiesToSharedBuffer(t),n=this.createSharedArrayBufferTasks(t.length),e.n=2,Promise.all(n);case 2:this.readResultsFromSharedBuffer(t);case 3:return e.a(2)}},e,this)}));return function(t){return e.apply(this,arguments)}}(),r.processWithWorker=function(){var e=n(h().m(function e(t){var n,r,i,o,a,c,u,l,d,f,p,m,v,y,_=this;return h().w(function(e){for(;;)switch(e.n){case 0:for(n=[],r=0;r<t.length;r++)n[r]=this.extractEntityData(t[r]);return i=this.createBatches(n),o=g.deltaTime,a=i.map(function(e){return _.workerPool.execute({entities:e,deltaTime:o,systemConfig:_.config.systemConfig})}),e.n=1,Promise.all(a);case 1:for(c=e.v,u=0,l=s(c);!(d=l()).done;)for(f=d.value,p=s(f);!(m=p()).done;)v=m.value,u<t.length&&(y=t[u])&&v&&this.applyResult(y,v),u++;case 2:return e.a(2)}},e,this)}));return function(t){return e.apply(this,arguments)}}(),r.processSynchronously=function(e){var t=this,n=e.map(function(e){return t.extractEntityData(e)}),r=g.deltaTime,i=this.workerProcess(n,r,this.config.systemConfig);i&&"function"==typeof i.then?i.then(function(n){e.forEach(function(e,r){t.applyResult(e,n[r])})}):e.forEach(function(e,n){t.applyResult(e,i[n])})},r.createBatches=function(e){var t=this.config.workerCount,n=[];if(this.config.entitiesPerWorker){for(var r=this.config.entitiesPerWorker,i=0;i<e.length;i+=r){var o=Math.min(i+r,e.length);n.push(e.slice(i,o))}n.length>t&&this.logger.warn(this.systemName+": 创建了 "+n.length+" 个批次,但只有 "+t+" 个Worker。某些Worker将依次处理多个批次。")}else for(var s=Math.ceil(e.length/t),a=0;a<t;a++){var c=a*s,u=Math.min(c+s,e.length);c<e.length&&n.push(e.slice(c,u))}return n},r.writeEntitiesToSharedBuffer=function(e){if(this.sharedFloatArray)for(var t=0;t<e.length&&t<this.config.maxEntities;t++){var n=e[t],r=this.extractEntityData(n),i=t*this.config.entityDataSize;this.writeEntityToBuffer(r,i)}},r.createSharedArrayBufferTasks=function(e){var t=[];if(this.config.entitiesPerWorker){var n=this.config.entitiesPerWorker,r=Math.ceil(e/n),i=this.config.workerCount;r>i&&this.logger.warn(this.systemName+": 需要 "+r+" 个任务处理 "+e+" 个实体(每任务 "+n+" 个),但只有 "+i+" 个Worker。某些Worker将依次处理多个任务。");for(var o=0;o<e;o+=n){var s=o,a=Math.min(o+n,e),c=this.workerPool.executeSharedBuffer({startIndex:s,endIndex:a,deltaTime:g.deltaTime,systemConfig:this.config.systemConfig});t.push(c)}}else for(var u=Math.ceil(e/this.config.workerCount),l=0;l<this.config.workerCount;l++){var h=l*u,d=Math.min(h+u,e);if(h<e){var f=this.workerPool.executeSharedBuffer({startIndex:h,endIndex:d,deltaTime:g.deltaTime,systemConfig:this.config.systemConfig});t.push(f)}}return t},r.readResultsFromSharedBuffer=function(e){if(this.sharedFloatArray)for(var t=0;t<e.length&&t<this.config.maxEntities;t++){var n=e[t],r=t*this.config.entityDataSize,i=this.readEntityFromBuffer(r);i&&this.applyResult(n,i)}},r.updateConfig=function(e){var t=a({},this.config);if(void 0!==e.workerCount){var n=this.getMaxSystemWorkerCount(),r=Math.min(e.workerCount,n);e.workerCount>n&&this.logger.warn("请求 "+e.workerCount+" 个Worker,但系统最多支持 "+n+" 个。实际使用 "+r+" 个Worker。"),e.workerCount=r}Object.assign(this.config,e),t.useSharedArrayBuffer===this.config.useSharedArrayBuffer?t.workerCount===this.config.workerCount?(!this.config.enableWorker&&this.workerPool&&(this.workerPool.destroy(),this.workerPool=null),this.config.enableWorker&&!this.workerPool&&this.isWorkerSupported()&&this.initializeWorkerPool()):this.reinitializeWorkerPool():this.reinitializeWorkerSystem()},r.reinitializeWorkerSystem=function(){this.workerPool&&(this.workerPool.destroy(),this.workerPool=null),this.sharedBuffer=null,this.sharedFloatArray=null,this.config.useSharedArrayBuffer||(this.config.workerCount=1),this.config.enableWorker&&this.isWorkerSupported()&&(this.config.useSharedArrayBuffer&&this.initializeSharedArrayBuffer(),this.initializeWorkerPool())},r.reinitializeWorkerPool=function(){this.workerPool&&(this.workerPool.destroy(),this.workerPool=null),this.config.enableWorker&&this.isWorkerSupported()&&this.initializeWorkerPool()},r.getWorkerInfo=function(){var e="sync";return this.config.enableWorker&&this.workerPool&&(e=this.config.useSharedArrayBuffer&&this.sharedFloatArray&&this.isSharedArrayBufferSupported()?"shared-buffer":"worker"),a({enabled:this.config.enableWorker,workerCount:this.config.workerCount},void 0!==this.config.entitiesPerWorker&&{entitiesPerWorker:this.config.entitiesPerWorker},{maxSystemWorkerCount:this.getMaxSystemWorkerCount(),isProcessing:this.isProcessing,sharedArrayBufferSupported:this.isSharedArrayBufferSupported(),sharedArrayBufferEnabled:this.config.useSharedArrayBuffer,currentMode:e})},r.onDestroy=function(){e.prototype.onDestroy.call(this),this.workerPool&&(this.workerPool.destroy(),this.workerPool=null)},r.getLoggerName=function(){return te(this)},t}(Be),An=function(){function e(e){var t=this;this.workers=[],this.taskQueue=[],this.busyWorkers=new Set,this.taskCounter=0,this.workers=e;for(var n=function(n){var r=e[n];if(!r)return 1;r.onMessage(function(e){return t.handleWorkerMessage(n,e.data)}),r.onError(function(e){return t.handleWorkerError(n,e)})},r=0;r<e.length;r++)n(r)}var t=e.prototype;return t.executeSharedBuffer=function(e){var t=this;return new Promise(function(n,r){var i={id:"shared-task-"+ ++t.taskCounter,data:a({},e,{type:"shared"}),resolve:function(){return n()},reject:r};t.taskQueue.push(i),t.processQueue()})},t.execute=function(e){var t=this;return new Promise(function(n,r){var i={id:"task-"+ ++t.taskCounter,data:e,resolve:function(e){n(e)},reject:r};t.taskQueue.push(i),t.processQueue()})},t.processQueue=function(){if(0!==this.taskQueue.length)for(var e=0;e<this.workers.length;e++)if(!this.busyWorkers.has(e)&&this.taskQueue.length>0){var t=this.taskQueue.shift();this.busyWorkers.add(e);var n=this.workers[e];n.postMessage(a({id:t.id},t.data)),n._currentTask=t}},t.handleWorkerMessage=function(e,t){var n=this.workers[e],r=n._currentTask;r&&(this.busyWorkers.delete(e),n._currentTask=null,t.error?r.reject(new Error(t.error)):r.resolve(t.result),this.processQueue())},t.handleWorkerError=function(e,t){var n=this.workers[e],r=n._currentTask;r&&(this.busyWorkers.delete(e),n._currentTask=null,r.reject(new Error(t.message))),this.processQueue()},t.destroy=function(){for(var e,t=s(this.workers);!(e=t()).done;){e.value.terminate()}this.workers.length=0,this.taskQueue.length=0,this.busyWorkers.clear()},e}();exports.PrefabInstanceComponent=function(e){function t(t,n,r){var i;return void 0===t&&(t=""),void 0===n&&(n=""),void 0===r&&(r=!1),(i=e.call(this)||this).sourcePrefabGuid="",i.sourcePrefabPath="",i.isRoot=!1,i.rootInstanceEntityId=null,i.modifiedProperties=[],i.instantiatedAt=0,i.originalValues={},i.sourcePrefabGuid=t,i.sourcePrefabPath=n,i.isRoot=r,i.instantiatedAt=Date.now(),i}u(t,e);var n=t.prototype;return n.markPropertyModified=function(e,t){var n=e+"."+t;this.modifiedProperties.includes(n)||this.modifiedProperties.push(n)},n.isPropertyModified=function(e,t){var n=e+"."+t;return this.modifiedProperties.includes(n)},n.clearPropertyModified=function(e,t){var n=e+"."+t,r=this.modifiedProperties.indexOf(n);-1!==r&&this.modifiedProperties.splice(r,1)},n.clearAllModifications=function(){this.modifiedProperties=[],this.originalValues={}},n.storeOriginalValue=function(e,t,n){var r=e+"."+t;r in this.originalValues||(this.originalValues[r]=this.deepClone(n))},n.getOriginalValue=function(e){return this.originalValues[e]},n.hasOriginalValue=function(e,t){return e+"."+t in this.originalValues},n.deepClone=function(e){if(null==e)return e;if("object"==typeof e)try{return JSON.parse(JSON.stringify(e))}catch(t){return e}return e},t}(Te),v([Ae(),y("design:type",String)],exports.PrefabInstanceComponent.prototype,"sourcePrefabGuid",void 0),v([Ae(),y("design:type",String)],exports.PrefabInstanceComponent.prototype,"sourcePrefabPath",void 0),v([Ae(),y("design:type",Boolean)],exports.PrefabInstanceComponent.prototype,"isRoot",void 0),v([Ae(),y("design:type",Object)],exports.PrefabInstanceComponent.prototype,"rootInstanceEntityId",void 0),v([Ae(),y("design:type",Array)],exports.PrefabInstanceComponent.prototype,"modifiedProperties",void 0),v([Ae(),y("design:type",Number)],exports.PrefabInstanceComponent.prototype,"instantiatedAt",void 0),v([Ae(),y("design:type",Object)],exports.PrefabInstanceComponent.prototype,"originalValues",void 0),exports.PrefabInstanceComponent=v([X("PrefabInstance",{editor:{hideInInspector:!0}}),Ie({version:1,typeId:"PrefabInstance"}),y("design:paramtypes",[String,String,Boolean])],exports.PrefabInstanceComponent);var kn=function(){function e(e){void 0===e&&(e=!1),this.eventIdCounter=0,this.isDebugMode=!1,this.eventSystem=new Mt,this.isDebugMode=e}var t=e.prototype;return t.emit=function(t,n,r){void 0===r&&(r=!1),this.validateEventType(t);var i=r?this.enhanceEventData(t,n):n;this.isDebugMode&&e._logger.info("发射事件: "+t,i),this.eventSystem.emitSync(t,i)},t.emitAsync=function(){var t=n(h().m(function t(n,r,i){var o;return h().w(function(t){for(;;)switch(t.n){case 0:return void 0===i&&(i=!1),this.validateEventType(n),o=i?this.enhanceEventData(n,r):r,this.isDebugMode&&e._logger.info("发射异步事件: "+n,o),t.n=1,this.eventSystem.emit(n,o);case 1:return t.a(2)}},t,this)}));return function(e,n,r){return t.apply(this,arguments)}}(),t.on=function(t,n,r){void 0===r&&(r={}),this.validateEventType(t);var i={once:r.once||!1,priority:r.priority||exports.EventPriority.NORMAL,async:r.async||!1};return r.thisArg&&(i.thisArg=r.thisArg),this.isDebugMode&&e._logger.info("添加监听器: "+t,i),this.eventSystem.on(t,n,i)},t.once=function(e,t,n){return void 0===n&&(n={}),this.on(e,t,a({},n,{once:!0}))},t.onAsync=function(e,t,n){return void 0===n&&(n={}),this.on(e,t,a({},n,{async:!0}))},t.off=function(t,n){return this.isDebugMode&&e._logger.info("移除监听器: "+n+" 事件: "+t),this.eventSystem.off(t,n)},t.offAll=function(t){this.isDebugMode&&e._logger.info("移除所有监听器: "+t),this.eventSystem.offAll(t)},t.hasListeners=function(e){return this.eventSystem.hasListeners(e)},t.getStats=function(e){var t=this,n=this.eventSystem.getStats(e);if(n instanceof Map){var r=new Map;return n.forEach(function(e,n){r.set(n,t.convertEventStats(e))}),r}return this.convertEventStats(n)},t.clear=function(){this.isDebugMode&&e._logger.info("清空所有监听器"),this.eventSystem.clear()},t.setEnabled=function(e){this.eventSystem.setEnabled(e)},t.setDebugMode=function(e){this.isDebugMode=e},t.setMaxListeners=function(e){this.eventSystem.setMaxListeners(e)},t.getListenerCount=function(e){return this.eventSystem.getListenerCount(e)},t.setBatchConfig=function(e,t,n){this.eventSystem.setBatchConfig(e,{batchSize:t,delay:n,enabled:!0})},t.flushBatch=function(e){this.eventSystem.flushBatch(e)},t.resetStats=function(e){this.eventSystem.resetStats(e)},t.emitEntityCreated=function(e){this.emit(exports.ECSEventType.ENTITY_CREATED,e)},t.emitEntityDestroyed=function(e){this.emit(exports.ECSEventType.ENTITY_DESTROYED,e)},t.emitComponentAdded=function(e){this.emit(exports.ECSEventType.COMPONENT_ADDED,e)},t.emitComponentRemoved=function(e){this.emit(exports.ECSEventType.COMPONENT_REMOVED,e)},t.emitSystemAdded=function(e){this.emit(exports.ECSEventType.SYSTEM_ADDED,e)},t.emitSystemRemoved=function(e){this.emit(exports.ECSEventType.SYSTEM_REMOVED,e)},t.emitSceneChanged=function(e){this.emit(exports.ECSEventType.SCENE_ACTIVATED,e)},t.emitPerformanceWarning=function(e){this.emit(exports.ECSEventType.PERFORMANCE_WARNING,e)},t.onEntityCreated=function(e,t){return this.on(exports.ECSEventType.ENTITY_CREATED,e,t)},t.onComponentAdded=function(e,t){return this.on(exports.ECSEventType.COMPONENT_ADDED,e,t)},t.onSystemError=function(e,t){return this.on(exports.ECSEventType.SYSTEM_ERROR,e,t)},t.onPerformanceWarning=function(e,t){return this.on(exports.ECSEventType.PERFORMANCE_WARNING,e,t)},t.validateEventType=function(t){this.isDebugMode&&(bn.isValid(t)||(e._logger.warn("未知事件类型: "+t),bn.addCustomType(t)))},t.enhanceEventData=function(e,t){if(null==t)return{timestamp:Date.now(),eventId:e+"_"+ ++this.eventIdCounter,source:"EventBus"};var n=t;return n.timestamp||(n.timestamp=Date.now()),n.eventId||(n.eventId=e+"_"+ ++this.eventIdCounter),n.source||(n.source="EventBus"),n},t.convertEventStats=function(e){return{eventType:e.eventType,listenerCount:e.listenerCount,triggerCount:e.triggerCount,totalExecutionTime:e.totalExecutionTime,averageExecutionTime:e.averageExecutionTime,lastTriggerTime:e.lastTriggerTime}},e}();kn._logger=J("EventBus");var Pn=function(){function e(){}return e.getInstance=function(e){return void 0===e&&(e=!1),this.instance||(this.instance=new kn(e)),this.instance},e.reset=function(e){return void 0===e&&(e=!1),this.instance&&this.instance.clear(),this.instance=new kn(e),this.instance},e}(),On=function(){function e(){}return e.registerComponentMigration=function(e,t,n,r){this.componentMigrations.has(e)||this.componentMigrations.set(e,new Map),this.componentMigrations.get(e).set(t,r)},e.registerSceneMigration=function(e,t,n){this.sceneMigrations.set(e,n)},e.migrateComponent=function(e,t){var n=e.version;if(n===t)return e;var r=this.componentMigrations.get(e.type);if(!r)return console.warn("No migration path found for component "+e.type),e;for(var i=a({},e),o=n;o<t;){var s=r.get(o);if(!s){console.warn("Missing migration from version "+o+" to "+(o+1)+" for "+e.type);break}i.data=s(i.data,o,o+1),o++}return i.version=o,i},e.migrateScene=function(e,t){var n=e.version;if(n===t)return e;for(var r=a({},e),i=n;i<t;){var o=this.sceneMigrations.get(i);if(!o){console.warn("Missing scene migration from version "+i+" to "+(i+1));break}r=o(r,i,i+1),i++}return r.version=i,r=this.migrateSceneComponents(r)},e.migrateSceneComponents=function(e){var t=this,n=a({},e);return n.entities=e.entities.map(function(n){return a({},n,{components:n.components.map(function(n){var r=e.componentTypeRegistry.find(function(e){return e.typeName===n.type});return r&&r.version!==n.version?t.migrateComponent(n,r.version):n}),children:t.migrateEntitiesComponents(n.children,e.componentTypeRegistry)})}),n},e.migrateEntitiesComponents=function(e,t){var n=this;return e.map(function(e){return a({},e,{components:e.components.map(function(e){var r=t.find(function(t){return t.typeName===e.type});return r&&r.version!==e.version?n.migrateComponent(e,r.version):e}),children:n.migrateEntitiesComponents(e.children,t)})})},e.clearMigrations=function(){this.componentMigrations.clear(),this.sceneMigrations.clear()},e.getComponentMigrationPath=function(e){var t=this.componentMigrations.get(e);return t?Array.from(t.keys()).sort(function(e,t){return e-t}):[]},e.getSceneMigrationPath=function(){return Array.from(this.sceneMigrations.keys()).sort(function(e,t){return e-t})},e.canMigrateComponent=function(e,t,n){if(t===n)return!0;var r=this.componentMigrations.get(e);if(!r)return!1;for(var i=t;i<n;i++)if(!r.has(i))return!1;return!0},e.canMigrateScene=function(e,t){if(e===t)return!0;for(var n=e;n<t;n++)if(!this.sceneMigrations.has(n))return!1;return!0},e}();On.componentMigrations=new Map,On.sceneMigrations=new Map;var Dn=function(){function e(){this.fromVersion=1,this.toVersion=2}var t=e.prototype;return t.forComponent=function(e){return this.componentType=e,this},t.fromVersionToVersion=function(e,t){return this.fromVersion=e,this.toVersion=t,this},t.migrate=function(e){this.componentType?On.registerComponentMigration(this.componentType,this.fromVersion,this.toVersion,e):On.registerSceneMigration(this.fromVersion,this.toVersion,e)},e}(),Rn=function(){function e(){}return e.createPrefab=function(e,t,n){var r,i=null===(r=t.includeChildren)||void 0===r||r,o=Pt.serialize(e,i,n),s=this.toPrefabEntity(o,!0),a=this.collectComponentTypes(s),c=a.componentTypes,u=a.componentTypeRegistry,l=Date.now(),h={name:t.name,createdAt:l,modifiedAt:l,componentTypes:c,referencedAssets:[]};return t.description&&(h.description=t.description),t.tags&&(h.tags=t.tags),{version:1,metadata:h,root:s,componentTypeRegistry:u}},e.instantiate=function(e,t,n,r){var i;void 0===r&&(r={});var o=r,a=o.parentId,c=o.name,u=o.preserveIds,l=void 0!==u&&u,h=o.trackInstance,d=void 0===h||h,f=null!==(i=t.getSystem(Le))&&void 0!==i?i:null,p=1,m=Pt.deserializeEntities([e.root],n,function(){for(;t.findEntityById(p);)p++;return p++},l,t,f),v=m.rootEntities,y=m.allEntities,g=v[0];if(!g)throw new Error("Failed to instantiate prefab: no root entity created");c&&(g.name=c);for(var _,S=s(y.values());!(_=S()).done;){var C=_.value;t.entities.add(C)}if(void 0!==a&&f){var E=t.findEntityById(a);E&&f.setParent(g,E)}if(d){var b=e.metadata.guid||"";this.addPrefabInstanceComponents(g,y,b,"",f)}return g},e.toPrefabEntity=function(e,t){var n=this;return a({},e,{isPrefabRoot:t,children:e.children.map(function(e){return n.toPrefabEntity(e,!1)})})},e.collectComponentTypes=function(e){var t=new Map,n=function(e){for(var r,i=s(e.components);!(r=i()).done;){var o=r.value;t.has(o.type)||t.set(o.type,o.version)}for(var a,c=s(e.children);!(a=c()).done;){var u=a.value;n(u)}};return n(e),{componentTypes:Array.from(t.keys()),componentTypeRegistry:Array.from(t.entries()).map(function(e){return{typeName:e[0],version:e[1]}})}},e.addPrefabInstanceComponents=function(e,t,n,r,i){var o=e.id,a=new exports.PrefabInstanceComponent(n,r,!0);a.rootInstanceEntityId=o,e.addComponent(a);for(var c,u=s(t.values());!(c=u()).done;){var l=c.value;if(l.id!==o){var h=new exports.PrefabInstanceComponent(n,r,!1);h.rootInstanceEntityId=o,l.addComponent(h)}}},e.isPrefabInstance=function(e){return e.hasComponent(exports.PrefabInstanceComponent)},e.getSourcePrefabGuid=function(e){var t=e.getComponent(exports.PrefabInstanceComponent);return(null==t?void 0:t.sourcePrefabGuid)||null},e.getPrefabInstanceRoot=function(e){var t=e.getComponent(exports.PrefabInstanceComponent);if(!t||!t.rootInstanceEntityId)return null;var n=e.scene;return n&&n.findEntityById(t.rootInstanceEntityId)||null},e.serialize=function(e,t){return void 0===t&&(t=!0),JSON.stringify(e,null,t?2:void 0)},e.deserialize=function(e){var t=JSON.parse(e);if(!t.version||!t.metadata||!t.root)throw new Error("Invalid prefab data format");return t},e.validate=function(e){var t=[];return"number"!=typeof e.version&&t.push("Invalid or missing version"),e.metadata?(e.metadata.name||t.push("Missing metadata.name"),Array.isArray(e.metadata.componentTypes)||t.push("Invalid metadata.componentTypes")):t.push("Missing metadata"),e.root?this.validateEntity(e.root,t,"root"):t.push("Missing root entity"),Array.isArray(e.componentTypeRegistry)||t.push("Invalid componentTypeRegistry"),t.length>0?{valid:!1,errors:t}:{valid:!0}},e.validateEntity=function(e,t,n){var r=this;"number"!=typeof e.id&&t.push(n+": Invalid or missing id"),"string"!=typeof e.name&&t.push(n+": Invalid or missing name"),Array.isArray(e.components)||t.push(n+": Invalid or missing components"),Array.isArray(e.children)?e.children.forEach(function(e,i){r.validateEntity(e,t,n+".children["+i+"]")}):t.push(n+": Invalid or missing children")},e}(),zn={NONE:0,FOLDER:4096,HIDDEN:8192,LOCKED:16384,EDITOR_ONLY:32768,PREFAB_INSTANCE:256,PREFAB_ROOT:512};function Nn(e,t){return 0!==(e&t)}var Fn=function(){function e(e){this._entity=e}var t=e.prototype;return t.with=function(e){return this._entity.addComponent(e),this},t.withConfigured=function(e,t){return this._entity.addComponent(e),t(e),this},t.withTag=function(e){return this._entity.tag=e,this},t.withName=function(e){return this._entity.name=e,this},t.withActive=function(e){return this._entity.active=e,this},t.withEnabled=function(e){return this._entity.enabled=e,this},t.withUpdateOrder=function(e){return this._entity.updateOrder=e,this},t.withChild=function(e){var t,n=null===(t=this._entity.scene)||void 0===t?void 0:t.getSystem(Le);return null==n||n.setParent(e,this._entity),this},t.build=function(){return this._entity},o(e,[{key:"entity",get:function(){return this._entity}}])}();var Bn=function(){function e(){}return e.getType=function(e){return e.constructor},e}(),Ln=function(){function e(){}return e.toNumber=function(e){return null==e?0:Number(e)},e}();function Hn(e){return"function"==typeof e&&e.prototype instanceof Te}var Wn=function(){function e(){}return e.detect=function(){var e,t=[],n="unknown",r=!1;return"undefined"!=typeof globalThis&&t.push("globalThis"),"undefined"!=typeof window&&t.push("window"),"undefined"!=typeof self&&t.push("self"),this.isNodeJS()?(n="nodejs",r=!0,e="NodeAdapter",t.push("nodejs","process","require")):this.isWeChatMiniGame()?(n="wechat-minigame",r=!0,e="WeChatMiniGameAdapter",t.push("wx","wechat-minigame")):this.isByteDanceMiniGame()?(n="bytedance-minigame",r=!0,e="ByteDanceMiniGameAdapter",t.push("tt","bytedance-minigame")):this.isAlipayMiniGame()?(n="alipay-minigame",r=!0,e="AlipayMiniGameAdapter",t.push("my","alipay-minigame")):this.isBaiduMiniGame()?(n="baidu-minigame",r=!0,e="BaiduMiniGameAdapter",t.push("swan","baidu-minigame")):this.isBrowser()&&(n="browser",r=!0,e="BrowserAdapter",t.push("browser")),"undefined"!=typeof Worker&&t.push("Worker"),"undefined"!=typeof SharedArrayBuffer&&t.push("SharedArrayBuffer"),"undefined"!=typeof navigator&&navigator.hardwareConcurrency&&t.push("hardwareConcurrency"),"undefined"!=typeof performance&&"function"==typeof performance.now&&t.push("performance.now"),"undefined"!=typeof Blob&&t.push("Blob"),"undefined"!=typeof URL&&"function"==typeof URL.createObjectURL&&t.push("URL.createObjectURL"),a({platform:n,confident:r,features:t},e&&{adapterClass:e})},e.isWeChatMiniGame=function(){if(void 0!==globalThis.wx){var e=globalThis.wx;return!!(e.getSystemInfo&&e.createCanvas&&e.createImage)}return!1},e.isByteDanceMiniGame=function(){if(void 0!==globalThis.tt){var e=globalThis.tt;return!!(e.getSystemInfo&&e.createCanvas&&e.createImage)}return!1},e.isNodeJS=function(){try{return!("undefined"==typeof process||!process.versions||!process.versions.node||"undefined"==typeof require||"undefined"==typeof module||"undefined"==typeof exports||"undefined"!=typeof window||"undefined"!=typeof document)}catch(e){return!1}},e.isAlipayMiniGame=function(){if(void 0!==globalThis.my){var e=globalThis.my;return!(!e.getSystemInfo||!e.createCanvas)}return!1},e.isBaiduMiniGame=function(){if(void 0!==globalThis.swan){var e=globalThis.swan;return!(!e.getSystemInfo||!e.createCanvas)}return!1},e.isBrowser=function(){return"undefined"!=typeof window&&"undefined"!=typeof document&&"undefined"!=typeof navigator&&void 0!==window.location},e.isTauriEnvironment=function(){return"undefined"!=typeof window&&("__TAURI__"in window||"__TAURI_INTERNALS__"in window)},e.isEditorEnvironment=function(){return"undefined"!=typeof window&&(!!this.isTauriEnvironment()||"__ESENGINE_EDITOR__"in window)},e.getDetailedInfo=function(){var e={};return e.userAgent="undefined"!=typeof navigator?navigator.userAgent:"unknown",e.platform="undefined"!=typeof navigator?navigator.platform:"unknown",e.globalObjects={window:"undefined"!=typeof window,document:"undefined"!=typeof document,navigator:"undefined"!=typeof navigator,wx:void 0!==globalThis.wx,tt:void 0!==globalThis.tt,my:void 0!==globalThis.my,swan:void 0!==globalThis.swan},e.workerSupport={Worker:"undefined"!=typeof Worker,SharedWorker:"undefined"!=typeof SharedWorker,ServiceWorker:"undefined"!=typeof navigator&&"serviceWorker"in navigator,SharedArrayBuffer:"undefined"!=typeof SharedArrayBuffer,crossOriginIsolated:"undefined"!=typeof self&&self.crossOriginIsolated},e.performance={performanceNow:"undefined"!=typeof performance&&"function"==typeof performance.now,hardwareConcurrency:"undefined"!=typeof navigator?navigator.hardwareConcurrency:void 0},e.apiSupport={Blob:"undefined"!=typeof Blob,URL:"undefined"!=typeof URL,createObjectURL:"undefined"!=typeof URL&&"function"==typeof URL.createObjectURL,ArrayBuffer:"undefined"!=typeof ArrayBuffer,TypedArrays:"undefined"!=typeof Float32Array},e},e}();exports.AdvancedProfilerCollector=Xe,exports.After=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){var n;return(n=ge(e.prototype).after).push.apply(n,t),e}},exports.AutoProfiler=Ft,exports.Before=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){var n;return(n=ge(e.prototype).before).push.apply(n,t),e}},exports.BinarySerializer=Ot,exports.BitMask64Utils=U,exports.Bits=ft,exports.COMPONENT_DEPENDENCIES=N,exports.COMPONENT_EDITOR_OPTIONS=F,exports.COMPONENT_TYPE_NAME=z,exports.Colors=q,exports.CommandBuffer=Fe,exports.CompiledQuery=bt,exports.Component=Te,exports.ComponentDataCollector=qe,exports.ComponentPool=Ge,exports.ComponentPoolManager=Ue,exports.ComponentRegistry=K,exports.ComponentSerializer=kt,exports.ComponentSparseSet=vt,exports.ComponentStorage=De,exports.ConsoleLogger=Q,exports.Core=fn,exports.CycleDependencyError=jt,exports.DEFAULT_PROFILER_CONFIG=Je,exports.DEFAULT_STAGE_ORDER=qt,exports.DeepCopy=function(e,t){var n=String(t);e.constructor.__deepCopyFields||(e.constructor.__deepCopyFields=new Set),e.constructor.__deepCopyFields.add(n)},exports.ECSComponent=X,exports.ECSFluentAPI=en,exports.ECSSystem=function(e,t){return function(n){if(!e||"string"!=typeof e)throw new Error("ECSSystem装饰器必须提供有效的类型名称");return n[Z]=e,t&&(n.__systemMetadata__=t),n}},exports.EMPTY_GUID="00000000-0000-0000-0000-000000000000",exports.ENTITY_REF_METADATA=ce,exports.EVENT_TYPES=En,exports.Emitter=Sn,exports.EnableSoA=function(e){return e.__enableSoA=!0,e},exports.Entity=ut,exports.EntityDataCollector=He,exports.EntityHandleManager=Vt,exports.EntityList=lt,exports.EntityProcessorList=dt,exports.EntityRef=function(){return function(e,t){var n=e.constructor,r=n[ce];r||(r={properties:new Set},n[ce]=r);var i="symbol"==typeof t?t.toString():t;r.properties.add(i),Object.defineProperty(e,t,{get:function(){return le(this).get(i)||null},set:function(e){var t=le(this),n=t.get(i)||null;if(n!==e){var r=null!==this.entityId?oe(this.entityId):null;if(r&&r.referenceTracker){var o=r.referenceTracker;if(n&&o.unregisterReference(n,this,i),e){var s;if(e.scene!==r)return void ae.error("Cannot reference Entity from different Scene. Entity: "+e.name+", Scene: "+((null===(s=e.scene)||void 0===s?void 0:s.name)||"null"));if(e.isDestroyed)return ae.warn("Cannot reference destroyed Entity: "+e.name),void t.set(i,null);o.registerReference(e,this,i)}t.set(i,e)}else t.set(i,e)}},enumerable:!0,configurable:!0})}},exports.EntitySerializer=Pt,exports.EntitySystem=Be,exports.EntityTags=zn,exports.EpochManager=Yt,exports.EventBus=kn,exports.EventTypeValidator=bn,exports.Float32=function(e,t){var n=String(t);e.constructor.__float32Fields||(e.constructor.__float32Fields=new Set),e.constructor.__float32Fields.add(n)},exports.Float64=function(e,t){var n=String(t);e.constructor.__float64Fields||(e.constructor.__float64Fields=new Set),e.constructor.__float64Fields.add(n)},exports.FuncPack=_n,exports.GEN_BITS=20,exports.GEN_MASK=tt,exports.GlobalEventBus=Pn,exports.GlobalManager=Cn,exports.HierarchySystem=Le,exports.INDEX_BITS=28,exports.INDEX_MASK=et,exports.IdentifierPool=ht,exports.IgnoreSerialization=function(){return function(e,t){var n,r=e.constructor;if(Object.prototype.hasOwnProperty.call(r,we))n=r[we];else{var i=r[we];n={options:i?a({},i.options):{version:1},fields:i?new Map(i.fields):new Map,ignoredFields:i?new Set(i.ignoredFields):new Set},r[we]=n}n.ignoredFields.add(t)}},exports.InSet=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){var n;return(n=ge(e.prototype).sets).push.apply(n,t),e}},exports.IncrementalSerializer=zt,exports.InjectProperty=w,exports.Injectable=b,exports.Int16=function(e,t){var n=String(t);e.constructor.__int16Fields||(e.constructor.__int16Fields=new Set),e.constructor.__int16Fields.add(n)},exports.Int32=Ee,exports.Int8=function(e,t){var n=String(t);e.constructor.__int8Fields||(e.constructor.__int8Fields=new Set),e.constructor.__int8Fields.add(n)},exports.IntervalSystem=Mn,exports.Logger=Y,exports.LoggerManager=V,exports.MAX_ENTITIES=nt,exports.MAX_GENERATION=rt,exports.Matcher=Pe,exports.MigrationBuilder=Dn,exports.NULL_HANDLE=0,exports.NumberExtension=Ln,exports.PREFAB_FORMAT_VERSION=1,exports.PROPERTY_METADATA=ve,exports.PassiveSystem=wn,exports.PerformanceDataCollector=je,exports.PerformanceMonitor=P,exports.PlatformDetector=Wn,exports.PlatformManager=xn,exports.PluginManager=cn,exports.PluginServiceRegistry=ln,exports.Pool=O,exports.PoolManager=R,exports.PrefabSerializer=Rn,exports.ProcessingSystem=Tn,exports.Profile=function(e,t){return void 0===t&&(t=exports.ProfileCategory.Custom),function(n,r,i){var o=i.value,s=e||n.constructor.name+"."+String(r);return i.value=function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];if(!Ze.isEnabled())return o.apply(this,n);var i=Ze.beginSample(s,t);try{var a=o.apply(this,n);return a instanceof Promise?a.finally(function(){Ze.endSample(i)}):(Ze.endSample(i),a)}catch(e){throw Ze.endSample(i),e}},i}},exports.ProfileClass=function(e){return void 0===e&&(e=exports.ProfileCategory.Custom),function(t){return Ft.registerClass(t,e)}},exports.ProfilerSDK=Ze,exports.Property=function(e){return function(t,n){var r=t.constructor,i=Reflect.getMetadata(ve,r)||{};i[n]=e,Reflect.defineMetadata(ve,i,r)}},exports.QuerySystem=Tt,exports.ReactiveQuery=Et,exports.ReferenceTracker=se,exports.RuntimeModeService=mn,exports.RuntimeModeToken=pn,exports.SCHEDULING_METADATA=ye,exports.SERIALIZABLE_METADATA=we,exports.SERIALIZE_FIELD=Me,exports.SERIALIZE_OPTIONS=xe,exports.SYSTEM_TYPE_NAME=Z,exports.Scene=Jt,exports.SceneDataCollector=Ve,exports.SceneManager=sn,exports.SceneSerializer=Rt,exports.Serializable=Ie,exports.SerializationContext=Dt,exports.Serialize=Ae,exports.SerializeArray=function(e,t){var n=String(t);e.constructor.__serializeArrayFields||(e.constructor.__serializeArrayFields=new Set),e.constructor.__serializeArrayFields.add(n)},exports.SerializeAsMap=function(){return function(e,t){Ae({serializer:function(e){return e instanceof Map?Array.from(e.entries()):null},deserializer:function(e){return Array.isArray(e)?new Map(e):new Map}})(e,t)}},exports.SerializeAsSet=function(){return function(e,t){Ae({serializer:function(e){return e instanceof Set?Array.from(e):null},deserializer:function(e){return Array.isArray(e)?new Set(e):new Set}})(e,t)}},exports.SerializeMap=function(e,t){var n=String(t);e.constructor.__serializeMapFields||(e.constructor.__serializeMapFields=new Set),e.constructor.__serializeMapFields.add(n)},exports.SerializeSet=function(e,t){var n=String(t);e.constructor.__serializeSetFields||(e.constructor.__serializeSetFields=new Set),e.constructor.__serializeSetFields.add(n)},exports.ServiceContainer=Wt,exports.SoAStorage=be,exports.SparseSet=pt,exports.Stage=function(e){return function(t){return ge(t.prototype).stage=e,t}},exports.SystemDataCollector=We,exports.SystemDependencyGraph=Ut,exports.SystemScheduler=Qt,exports.Time=g,exports.Timer=S,exports.TypeSafeEventSystem=Mt,exports.TypeUtils=Bn,exports.TypedEntityBuilder=Fn,exports.TypedQueryBuilder=It,exports.TypedQueryResult=xt,exports.Uint16=function(e,t){var n=String(t);e.constructor.__uint16Fields||(e.constructor.__uint16Fields=new Set),e.constructor.__uint16Fields.add(n)},exports.Uint32=function(e,t){var n=String(t);e.constructor.__uint32Fields||(e.constructor.__uint32Fields=new Set),e.constructor.__uint32Fields.add(n)},exports.Uint8=function(e,t){var n=String(t);e.constructor.__uint8Fields||(e.constructor.__uint8Fields=new Set),e.constructor.__uint8Fields.add(n)},exports.Uint8Clamped=function(e,t){var n=String(t);e.constructor.__uint8ClampedFields||(e.constructor.__uint8ClampedFields=new Set),e.constructor.__uint8ClampedFields.add(n)},exports.Updatable=T,exports.VersionMigrationManager=On,exports.WebSocketManager=Ye,exports.WorkerEntitySystem=In,exports.World=on,exports.WorldManager=dn,exports.addAndConfigure=function(e,t,n){return e.addComponent(t),n(t),e},exports.addEntityTag=function(e,t){return e|t},exports.buildEntity=function(e){return new Fn(e)},exports.createECSAPI=tn,exports.createEditorModeService=function(){return new mn({isEditor:!0,isPlaying:!1,isPreview:!1})},exports.createInstance=x,exports.createLogger=J,exports.createQuery=function(){return new It},exports.createServiceToken=un,exports.createStandaloneModeService=function(){return new mn({isEditor:!1,isPlaying:!0,isPreview:!1})},exports.genOf=st,exports.generateGUID=$e,exports.getBasicWorkerConfig=function(){return xn.getInstance().getBasicWorkerConfig()},exports.getComponentDependencies=function(e){return e[N]},exports.getComponentEditorOptions=W,exports.getComponentInstanceEditorOptions=function(e){return W(e.constructor)},exports.getComponentInstanceTypeName=H,exports.getComponentTypeName=L,exports.getComponents=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return n.map(function(t){return e.getComponent(t)})},exports.getCurrentAdapter=function(){return xn.getInstance().getAdapter()},exports.getEntityRefMetadata=he,exports.getEntityRefProperties=function(e){var t=he(e);return t?Array.from(t.properties):[]},exports.getFullPlatformConfig=function(){return xn.getInstance().getFullPlatformConfig()},exports.getOrAddComponent=function(e,t,n){var r=e.getComponent(t);return r||(r=n(),e.addComponent(r)),r},exports.getPropertyInjectMetadata=function(e){var t=C.get(e);return(null==t?void 0:t.properties)||new Map},exports.getPropertyMetadata=function(e){return Reflect.getMetadata(ve,e)},exports.getSceneByEntityId=oe,exports.getSchedulingMetadata=_e,exports.getSerializationMetadata=ke,exports.getSystemInstanceTypeName=te,exports.getSystemMetadata=$,exports.getSystemTypeName=ee,exports.getUpdatableMetadata=k,exports.handleEquals=function(e,t){return e===t},exports.handleToString=function(e){return 0===e?"Entity(NULL)":"Entity(idx="+ot(e)+", gen="+st(e)+")"},exports.hasAdapter=function(){return xn.getInstance().hasAdapter()},exports.hasAnyComponent=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return n.some(function(t){return e.hasComponent(t)})},exports.hasComponents=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return n.every(function(t){return e.hasComponent(t)})},exports.hasECSComponentDecorator=B,exports.hasEntityRef=function(e){return null!==he(e)},exports.hasEntityTag=Nn,exports.hasPropertyMetadata=function(e){return Reflect.hasMetadata(ve,e)},exports.hasSchedulingMetadata=function(e){return void 0!==_e(e)},exports.indexOf=ot,exports.injectProperties=I,exports.isComponentArray=function(e){return e.every(Hn)},exports.isComponentHiddenInInspector=j,exports.isComponentInstanceHiddenInInspector=function(e){return j(e.constructor)},exports.isComponentType=Hn,exports.isEntityRefProperty=de,exports.isFolder=function(e){return Nn(e,zn.FOLDER)},exports.isHidden=function(e){return Nn(e,zn.HIDDEN)},exports.isLocked=function(e){return Nn(e,zn.LOCKED)},exports.isSerializable=function(e){return null!==ke(e)},exports.isUpdatable=A,exports.isValidGUID=function(e){return/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e)},exports.isValidHandle=at,exports.makeHandle=it,exports.queryFor=function(e){return new It([e])},exports.queryForAll=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return new It(t)},exports.registerInjectable=function(e,t,n){if(void 0===n&&(n=!0),!M(t))throw new Error(t.name+" is not marked as @Injectable(). Please add @Injectable() decorator to the class.");var r=function(e){return x(t,e)};n?e.registerSingleton(t,r):e.registerTransient(t,r)},exports.registerPlatformAdapter=function(e){return xn.getInstance().registerAdapter(e)},exports.removeEntityTag=function(e,t){return e&~t},exports.requireComponent=function(e,t){var n=e.getComponent(t);if(!n)throw new Error("Component "+t.name+" not found on entity "+e.name+" (id: "+e.id+")");return n},exports.resetLoggerColors=function(){V.getInstance().resetColors()},exports.setGlobalLogLevel=function(e){V.getInstance().setGlobalLevel(e)},exports.setLoggerColors=function(e){V.getInstance().setGlobalColors(e)},exports.setLoggerFactory=function(e){V.getInstance().setLoggerFactory(e)},exports.supportsFeature=function(e){return xn.getInstance().supportsFeature(e)},exports.tryGetComponent=function(e,t){var n=e.getComponent(t);return null!==n?n:void 0},exports.updateComponent=function(e,t,n){var r=e.getComponent(t);return!!r&&(Object.assign(r,n),!0)};
3
+ var e,t,n="function"==typeof Symbol?Symbol:{},i=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function o(n,i,r,o){var c=i&&i.prototype instanceof a?i:a,u=Object.create(c.prototype);return d(u,"_invoke",function(n,i,r){var o,a,c,u=0,l=r||[],h=!1,d={p:0,n:0,v:e,a:f,f:f.bind(e,4),d:function(t,n){return o=t,a=0,c=e,d.n=n,s}};function f(n,i){for(a=n,c=i,t=0;!h&&u&&!r&&t<l.length;t++){var r,o=l[t],f=d.p,p=o[2];n>3?(r=p===i)&&(c=o[(a=o[4])?5:(a=3,3)],o[4]=o[5]=e):o[0]<=f&&((r=n<2&&f<o[1])?(a=0,d.v=i,d.n=o[1]):f<p&&(r=n<3||o[0]>i||i>p)&&(o[4]=n,o[5]=i,d.n=p,a=0))}if(r||n>1)return s;throw h=!0,i}return function(r,l,p){if(u>1)throw TypeError("Generator is already running");for(h&&1===l&&f(l,p),a=l,c=p;(t=a<2?e:c)||!h;){o||(a?a<3?(a>1&&(d.n=-1),f(a,c)):d.n=c:d.v=c);try{if(u=2,o){if(a||(r="next"),t=o[r]){if(!(t=t.call(o,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,a<2&&(a=0)}else 1===a&&(t=o.return)&&t.call(o),a<2&&(c=TypeError("The iterator does not provide a '"+r+"' method"),a=1);o=e}else if((t=(h=d.n<0)?c:n.call(i,d))!==s)break}catch(t){o=e,a=1,c=t}finally{u=1}}return{value:t,done:h}}}(n,r,o),!0),u}var s={};function a(){}function c(){}function u(){}t=Object.getPrototypeOf;var l=[][i]?t(t([][i]())):(d(t={},i,function(){return this}),t),f=u.prototype=a.prototype=Object.create(l);function p(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,u):(e.__proto__=u,d(e,r,"GeneratorFunction")),e.prototype=Object.create(f),e}return c.prototype=u,d(f,"constructor",u),d(u,"constructor",c),c.displayName="GeneratorFunction",d(u,r,"GeneratorFunction"),d(f),d(f,r,"Generator"),d(f,i,function(){return this}),d(f,"toString",function(){return"[object Generator]"}),(h=function(){return{w:o,m:p}})()}function d(e,t,n,i){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}d=function(e,t,n,i){function o(t,n){d(e,t,function(e){return this._invoke(t,n,e)})}t?r?r(e,t,{value:n,enumerable:!i,configurable:!i,writable:!i}):e[t]=n:(o("next",0),o("throw",1),o("return",2))},d(e,t,n,i)}function f(e,t){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},f(e,t)}function p(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t);if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e,"string");return"symbol"==typeof t?t:t+""}function m(e){var t="function"==typeof Map?new Map:void 0;return m=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return i(e,arguments,c(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),f(n,e)},m(e)}function v(e,t,n,i){var r,o=arguments.length,s=o<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,i);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(s=(o<3?r(s):o>3?r(t,n,s):r(t,n))||s);return o>3&&s&&Object.defineProperty(t,n,s),s}function g(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}"function"==typeof SuppressedError&&SuppressedError;var y=function(){function e(){}return e.update=function(e){this.unscaledDeltaTime=e,this.deltaTime=e*this.timeScale,this.unscaledTotalTime+=this.unscaledDeltaTime,this.totalTime+=this.deltaTime,this.frameCount++},e.sceneChanged=function(){this.frameCount=0,this.totalTime=0,this.unscaledTotalTime=0,this.deltaTime=0,this.unscaledDeltaTime=0},e.checkEvery=function(e,t){return this.totalTime-t>=e},e}();y.deltaTime=0,y.unscaledDeltaTime=0,y.totalTime=0,y.unscaledTotalTime=0,y.timeScale=1,y.frameCount=0;var _,S=function(){function e(){this._timeInSeconds=0,this._repeats=!1,this._isDone=!1,this._elapsedTime=0}var t=e.prototype;return t.getContext=function(){return this.context},t.reset=function(){this._elapsedTime=0},t.stop=function(){this._isDone=!0},t.tick=function(){return!this._isDone&&this._elapsedTime>this._timeInSeconds&&(this._elapsedTime-=this._timeInSeconds,this._onTime(this),this._isDone||this._repeats||(this._isDone=!0)),this._elapsedTime+=y.deltaTime,this._isDone},t.initialize=function(e,t,n,i){this._timeInSeconds=e,this._repeats=t,this.context=n,this._onTime=i.bind(n)},t.unload=function(){this.context=null,this._onTime=null},o(e,[{key:"isDone",get:function(){return this._isDone}},{key:"elapsedTime",get:function(){return this._elapsedTime}}])}(),C=new WeakMap,E=new WeakMap;function b(){return function(e){var t=C.get(e);C.set(e,a({injectable:!0,dependencies:[]},(null==t?void 0:t.properties)&&{properties:t.properties}))}}function T(e){return void 0===e&&(e=0),function(t){var n=t.prototype;if(!n||"function"!=typeof n.update)throw new Error("@Updatable() decorator requires class "+t.name+" to implement IUpdatable interface with update() method. Please add 'implements IUpdatable' and define update(deltaTime?: number): void method.");E.set(t,{updatable:!0,priority:e})}}function w(e){return function(t,n){var i=C.get(t.constructor);i||(i={injectable:!0,dependencies:[]},C.set(t.constructor,i)),i.properties||(i.properties=new Map),i.properties.set(n,e)}}function I(e){var t,n=C.get(e);return null!==(t=null==n?void 0:n.injectable)&&void 0!==t&&t}function x(e,t){var n=new e;return M(n,t),n}function M(e,t){var n,i=e.constructor,r=(n=i,C.get(n));if(null!=r&&r.properties&&0!==r.properties.size)for(var o,a=s(r.properties);!(o=a()).done;){var c=o.value,u=c[0],l=c[1],h=t.resolve(l);null!==h&&(e[u]=h)}}function A(e){var t,n=E.get(e);return null!==(t=null==n?void 0:n.updatable)&&void 0!==t&&t}function k(e){return E.get(e)}exports.TimerManager=function(){function e(){this._timers=[]}var t=e.prototype;return t.update=function(){for(var e=this._timers.length-1;e>=0;e--)this._timers[e].tick()&&(this._timers[e].unload(),this._timers.splice(e,1))},t.schedule=function(e,t,n,i){var r=new S;return r.initialize(e,t,n,i),this._timers.push(r),r},t.dispose=function(){for(var e,t=s(this._timers);!(e=t()).done;){e.value.unload()}this._timers=[]},e}(),exports.TimerManager=v([T()],exports.TimerManager),exports.PerformanceWarningType=void 0,(_=exports.PerformanceWarningType||(exports.PerformanceWarningType={})).HIGH_EXECUTION_TIME="high_execution_time",_.HIGH_MEMORY_USAGE="high_memory_usage",_.HIGH_CPU_USAGE="high_cpu_usage",_.FREQUENT_GC="frequent_gc",_.LOW_FPS="low_fps",_.HIGH_ENTITY_COUNT="high_entity_count";var D=function(){function e(){this._systemData=new Map,this._systemStats=new Map,this._isEnabled=!1,this._maxRecentSamples=60}var t=e.prototype;return t.enable=function(){this._isEnabled=!0},t.disable=function(){this._isEnabled=!1},t.startMonitoring=function(e){return this._isEnabled?performance.now():0},t.endMonitoring=function(e,t,n){if(void 0===n&&(n=0),this._isEnabled&&0!==t){var i=performance.now(),r=i-t,o={name:e,executionTime:r,entityCount:n,averageTimePerEntity:n>0?r/n:0,lastUpdateTime:i};this._systemData.set(e,o),this.updateStats(e,r)}},t.updateStats=function(e,t){var n=this._systemStats.get(e);n||(n={totalTime:0,averageTime:0,minTime:Number.MAX_VALUE,maxTime:0,executionCount:0,recentTimes:[],standardDeviation:0,percentile95:0,percentile99:0},this._systemStats.set(e,n)),n.totalTime+=t,n.executionCount++,n.averageTime=n.totalTime/n.executionCount,n.minTime=Math.min(n.minTime,t),n.maxTime=Math.max(n.maxTime,t),n.recentTimes.push(t),n.recentTimes.length>this._maxRecentSamples&&n.recentTimes.shift(),this.calculateAdvancedStats(n)},t.calculateAdvancedStats=function(e){if(0!==e.recentTimes.length){var t=e.recentTimes.reduce(function(e,t){return e+t},0)/e.recentTimes.length,n=e.recentTimes.reduce(function(e,n){return e+Math.pow(n-t,2)},0)/e.recentTimes.length;e.standardDeviation=Math.sqrt(n);var i=[].concat(e.recentTimes).sort(function(e,t){return e-t}),r=i.length;e.percentile95=i[Math.floor(.95*r)]||0,e.percentile99=i[Math.floor(.99*r)]||0}},t.getSystemData=function(e){return this._systemData.get(e)},t.getSystemStats=function(e){return this._systemStats.get(e)},t.getAllSystemData=function(){return new Map(this._systemData)},t.getAllSystemStats=function(){return new Map(this._systemStats)},t.getPerformanceReport=function(){if(!this._isEnabled)return"Performance monitoring is disabled.";var e=[];e.push("=== ECS Performance Report ==="),e.push("");for(var t,n=s(Array.from(this._systemStats.entries()).sort(function(e,t){return t[1].averageTime-e[1].averageTime}));!(t=n()).done;){var i=t.value,r=i[0],o=i[1],a=this._systemData.get(r);e.push("System: "+r),e.push(" Current: "+(null==a?void 0:a.executionTime.toFixed(2))+"ms ("+(null==a?void 0:a.entityCount)+" entities)"),e.push(" Average: "+o.averageTime.toFixed(2)+"ms"),e.push(" Min/Max: "+o.minTime.toFixed(2)+"ms / "+o.maxTime.toFixed(2)+"ms"),e.push(" Total: "+o.totalTime.toFixed(2)+"ms ("+o.executionCount+" calls)"),null!=a&&a.averageTimePerEntity&&a.averageTimePerEntity>0&&e.push(" Per Entity: "+a.averageTimePerEntity.toFixed(4)+"ms"),e.push("")}var c=Array.from(this._systemData.values()).reduce(function(e,t){return e+t.executionTime},0);return e.push("Total Frame Time: "+c.toFixed(2)+"ms"),e.push("Systems Count: "+this._systemData.size),e.join("\n")},t.reset=function(){this._systemData.clear(),this._systemStats.clear()},t.resetSystem=function(e){this._systemData.delete(e),this._systemStats.delete(e)},t.getPerformanceWarnings=function(e){void 0===e&&(e=16.67);for(var t,n=[],i=s(this._systemData.entries());!(t=i()).done;){var r=t.value,o=r[0],a=r[1];a.executionTime>e&&n.push(o+": "+a.executionTime.toFixed(2)+"ms (>"+e+"ms)")}return n},t.setMaxRecentSamples=function(e){this._maxRecentSamples=e;for(var t,n=s(this._systemStats.values());!(t=n()).done;)for(var i=t.value;i.recentTimes.length>e;)i.recentTimes.shift()},t.dispose=function(){this._systemData.clear(),this._systemStats.clear(),this._isEnabled=!1},o(e,[{key:"isEnabled",get:function(){return this._isEnabled}}])}(),P=function(){function e(e,t,n){void 0===t&&(t=100),void 0===n&&(n=1024),this._objects=[],this._createFn=e,this._maxSize=t,this._objectSize=n,this._stats={size:0,maxSize:t,totalCreated:0,totalObtained:0,totalReleased:0,hitRate:0,estimatedMemoryUsage:0}}e.getPool=function(t,n,i){void 0===n&&(n=100),void 0===i&&(i=1024);var r=this._pools.get(t);return r||(r=new e(function(){return new t},n,i),this._pools.set(t,r)),r};var t=e.prototype;return t.obtain=function(){if(this._stats.totalObtained++,this._objects.length>0){var e=this._objects.pop();return this._stats.size--,this._updateHitRate(),this._updateMemoryUsage(),e}return this._stats.totalCreated++,this._updateHitRate(),this._createFn()},t.release=function(e){e&&(this._stats.totalReleased++,this._stats.size<this._maxSize&&(e.reset(),this._objects.push(e),this._stats.size++,this._updateMemoryUsage()))},t.getStats=function(){return a({},this._stats)},t.clear=function(){for(var e,t=s(this._objects);!(e=t()).done;){e.value.reset()}this._objects.length=0,this._stats.size=0,this._updateMemoryUsage()},t.compact=function(e){for(var t=null!=e?e:Math.floor(this._objects.length/2);this._objects.length>t;){var n=this._objects.pop();n&&(n.reset(),this._stats.size--)}this._updateMemoryUsage()},t.prewarm=function(e){for(var t=Math.min(e,this._maxSize-this._objects.length),n=0;n<t;n++){var i=this._createFn();i.reset(),this._objects.push(i),this._stats.totalCreated++,this._stats.size++}this._updateMemoryUsage()},t.setMaxSize=function(e){this._maxSize=e,this._stats.maxSize=e,this._objects.length>e&&this.compact(e)},t.getAvailableCount=function(){return this._objects.length},t.isEmpty=function(){return 0===this._objects.length},t.isFull=function(){return this._objects.length>=this._maxSize},e.getAllPoolTypes=function(){return Array.from(this._pools.keys())},e.getAllPoolStats=function(){for(var e,t={},n=s(this._pools);!(e=n()).done;){var i=e.value,r=i[0],o=i[1];t[r.name||r.toString()]=o.getStats()}return t},e.compactAllPools=function(){for(var e,t=s(this._pools.values());!(e=t()).done;){e.value.compact()}},e.clearAllPools=function(){for(var e,t=s(this._pools.values());!(e=t()).done;){e.value.clear()}this._pools.clear()},e.getGlobalStatsString=function(){var e=this.getAllPoolStats(),t=["=== Object Pool Global Statistics ===",""];if(0===Object.keys(e).length)return t.push("No pools registered"),t.join("\n");for(var n=0,i=Object.entries(e);n<i.length;n++){var r=i[n],o=r[0],s=r[1];t.push(o+":"),t.push(" Size: "+s.size+"/"+s.maxSize),t.push(" Hit Rate: "+(100*s.hitRate).toFixed(1)+"%"),t.push(" Total Created: "+s.totalCreated),t.push(" Total Obtained: "+s.totalObtained),t.push(" Memory: "+(s.estimatedMemoryUsage/1024).toFixed(1)+" KB"),t.push("")}return t.join("\n")},t._updateHitRate=function(){if(0===this._stats.totalObtained)this._stats.hitRate=0;else{var e=this._stats.totalObtained-this._stats.totalCreated;this._stats.hitRate=e/this._stats.totalObtained}},t._updateMemoryUsage=function(){this._stats.estimatedMemoryUsage=this._stats.size*this._objectSize},e}();P._pools=new Map;var O,R=function(){function e(){this.pools=new Map,this.autoCompactInterval=6e4,this.lastCompactTime=0}var t=e.prototype;return t.registerPool=function(e,t){this.pools.set(e,t)},t.getPool=function(e){return this.pools.get(e)||null},t.update=function(){var e=Date.now();e-this.lastCompactTime>this.autoCompactInterval&&(this.compactAllPools(),this.lastCompactTime=e)},t.createPool=function(e,t,n,i){void 0===n&&(n=100),void 0===i&&(i=1024);var r=this.pools.get(e);return r||(r=new P(t,n,i),this.pools.set(e,r)),r},t.removePool=function(e){var t=this.pools.get(e);return!!t&&(t.clear(),this.pools.delete(e),!0)},t.getPoolNames=function(){return Array.from(this.pools.keys())},t.getPoolCount=function(){return this.pools.size},t.compactAllPools=function(){for(var e,t=s(this.pools.values());!(e=t()).done;){e.value.compact()}},t.clearAllPools=function(){for(var e,t=s(this.pools.values());!(e=t()).done;){e.value.clear()}},t.getAllStats=function(){for(var e,t=new Map,n=s(this.pools);!(e=n()).done;){var i=e.value,r=i[0],o=i[1];t.set(r,o.getStats())}return t},t.getGlobalStats=function(){for(var e,t=0,n=0,i=0,r=0,o=0,a=0,c=s(this.pools.values());!(e=c()).done;){var u=e.value.getStats();t+=u.size,n+=u.maxSize,i+=u.totalCreated,r+=u.totalObtained,o+=u.totalReleased,a+=u.estimatedMemoryUsage}return{size:t,maxSize:n,totalCreated:i,totalObtained:r,totalReleased:o,hitRate:0===r?0:(r-i)/r,estimatedMemoryUsage:a}},t.getStatsString=function(){var e=["=== Pool Manager Statistics ===",""];if(0===this.pools.size)return e.push("No pools registered"),e.join("\n");var t=this.getGlobalStats();e.push("Total Pools: "+this.pools.size),e.push("Global Hit Rate: "+(100*t.hitRate).toFixed(1)+"%"),e.push("Global Memory Usage: "+(t.estimatedMemoryUsage/1024).toFixed(1)+" KB"),e.push("");for(var n,i=s(this.pools);!(n=i()).done;){var r=n.value,o=r[0],a=r[1].getStats();e.push(o+":"),e.push(" Size: "+a.size+"/"+a.maxSize),e.push(" Hit Rate: "+(100*a.hitRate).toFixed(1)+"%"),e.push(" Memory: "+(a.estimatedMemoryUsage/1024).toFixed(1)+" KB"),e.push("")}return e.join("\n")},t.setAutoCompactInterval=function(e){this.autoCompactInterval=e},t.prewarmAllPools=function(){for(var e,t=s(this.pools.values());!(e=t()).done;){var n=e.value,i=n.getStats(),r=Math.floor(.2*i.maxSize);n.prewarm(r)}},t.reset=function(){this.clearAllPools(),this.pools.clear(),this.lastCompactTime=0},t.dispose=function(){this.reset()},e}(),z=Symbol("ComponentTypeName"),N=Symbol("ComponentDependencies"),F=Symbol("ComponentEditorOptions");function B(e){return void 0!==e[z]}function L(e){var t=e[z];return t||(e.name||"UnknownComponent")}function H(e){return L(e.constructor)}function W(e){return e[F]}function G(e){var t,n=W(e);return null!==(t=null==n?void 0:n.hideInInspector)&&void 0!==t&&t}!function(e){e[e.LOW=0]="LOW",e[e.HIGH=1]="HIGH"}(O||(O={}));var j,U=function(){function e(){}return e.create=function(t){if(t<0)throw new Error("Bit index "+t+" out of range [0, ∞)");var n={base:[0,0]};return e.setBit(n,t),n},e.fromNumber=function(e){return{base:[e>>>0,0]}},e.hasAny=function(e,t){var n=t.base,i=e.base,r=t.segments,o=e.segments,s=0!==(i[O.LOW]&n[O.LOW])||0!==(i[O.HIGH]&n[O.HIGH]);return!s&&r&&o?o.some(function(e,t){var n=r[t];return n&&(0!==(e[O.LOW]&n[O.LOW])||0!==(e[O.HIGH]&n[O.HIGH]))}):s},e.hasAll=function(e,t){var n,i=e.base,r=t.base,o=e.segments,s=t.segments,a=(i[O.LOW]&r[O.LOW])===r[O.LOW]&&(i[O.HIGH]&r[O.HIGH])===r[O.HIGH];if(!a||!s)return a;var c=null!==(n=null==o?void 0:o.length)&&void 0!==n?n:0;if(o)for(var u=0;u<Math.min(c,s.length);u++){var l=o[u],h=s[u];if((l[O.LOW]&h[O.LOW])!==h[O.LOW]||(l[O.HIGH]&h[O.HIGH])!==h[O.HIGH])return!1}for(var d=c;d<s.length;d++){var f=s[d];if(0!==f[O.LOW]||0!==f[O.HIGH])return!1}return!0},e.hasNone=function(e,t){var n=e.base,i=t.base,r=e.segments,o=t.segments,s=0===(n[O.LOW]&i[O.LOW])&&0===(n[O.HIGH]&i[O.HIGH]);return r&&s&&o?r.every(function(e,t){var n=o[t];return!n||0===(e[O.LOW]&n[O.LOW])&&0===(e[O.HIGH]&n[O.HIGH])}):s},e.isZero=function(e){var t=0===e.base[O.LOW]&&0===e.base[O.HIGH];return e.segments&&t?e.segments.every(function(e){return 0===e[O.LOW]&&0===e[O.HIGH]}):t},e.equals=function(e,t){var n,i,r=e.base[O.LOW]===t.base[O.LOW]&&e.base[O.HIGH]===t.base[O.HIGH];if(!r||!e.segments&&!t.segments)return r;for(var o=null!==(n=e.segments)&&void 0!==n?n:[],s=null!==(i=t.segments)&&void 0!==i?i:[],a=0;a<Math.max(o.length,s.length);a++){var c=o[a],u=s[a];if(c&&!u){if(0!==c[O.LOW]||0!==c[O.HIGH])return!1}else if(!c&&u){if(0!==u[O.LOW]||0!==u[O.HIGH])return!1}else if(c&&u&&(c[O.LOW]!==u[O.LOW]||c[O.HIGH]!==u[O.HIGH]))return!1}return!0},e.setBit=function(t,n){if(n<0)throw new Error("Bit index "+n+" out of range [0, 63]");var i=e.getSegmentByBitIndex(t,n),r=63&n;r<32?i[O.LOW]|=1<<r:i[O.HIGH]|=1<<r-32},e.getBit=function(t,n){if(n<0)return!1;var i=e.getSegmentByBitIndex(t,n,!1);if(!i)return!1;var r=63&n;return r<32?!!(i[O.LOW]&1<<r):!!(i[O.HIGH]&1<<r-32)},e.clearBit=function(t,n){if(n<0)throw new Error("Bit index "+n+" out of range [0, 63]");var i=e.getSegmentByBitIndex(t,n,!1);if(i){var r=63&n;r<32?i[O.LOW]&=~(1<<r):i[O.HIGH]&=~(1<<r-32)}},e.orInPlace=function(e,t){e.base[O.LOW]|=t.base[O.LOW],e.base[O.HIGH]|=t.base[O.HIGH];var n=t.segments;if(n&&n.length>0){e.segments||(e.segments=[]);for(var i=e.segments;i.length<n.length;)i.push([0,0]);for(var r=0;r<n.length;r++){var o=i[r],s=n[r];o[O.LOW]|=s[O.LOW],o[O.HIGH]|=s[O.HIGH]}}},e.andInPlace=function(e,t){e.base[O.LOW]&=t.base[O.LOW],e.base[O.HIGH]&=t.base[O.HIGH];var n=t.segments;if(n&&n.length>0){e.segments||(e.segments=[]);for(var i=e.segments;i.length<n.length;)i.push([0,0]);for(var r=0;r<n.length;r++){var o=i[r],s=n[r];o[O.LOW]&=s[O.LOW],o[O.HIGH]&=s[O.HIGH]}}},e.xorInPlace=function(e,t){e.base[O.LOW]^=t.base[O.LOW],e.base[O.HIGH]^=t.base[O.HIGH];var n=t.segments;if(n&&0!=n.length){e.segments||(e.segments=[]);for(var i=e.segments;i.length<n.length;)i.push([0,0]);for(var r=0;r<n.length;r++){var o=i[r],s=n[r];o[O.LOW]^=s[O.LOW],o[O.HIGH]^=s[O.HIGH]}}},e.clear=function(e){if(e.base[O.LOW]=0,e.base[O.HIGH]=0,e.segments)for(var t=0;t<e.segments.length;t++){var n=e.segments[t];n[O.LOW]=0,n[O.HIGH]=0}},e.copy=function(t,n){if(e.clear(n),n.base[O.LOW]=t.base[O.LOW],n.base[O.HIGH]=t.base[O.HIGH],t.segments&&0!=t.segments.length)if(n.segments){for(var i=t.segments.length-n.segments.length,r=0;r<i;r++)n.segments.push([0,0]);for(var o=n.segments,s=t.segments,a=0;a<s.length;a++){var c=o[a],u=s[a];c[O.LOW]=u[O.LOW],c[O.HIGH]=u[O.HIGH]}}else n.segments=t.segments.map(function(e){return[].concat(e)})},e.clone=function(e){return a({base:e.base.slice()},e.segments&&{segments:e.segments.map(function(e){return[].concat(e)})})},e.toString=function(e,t,n){var i,r;void 0===t&&(t=2),void 0===n&&(n=!1),2!=t&&16!=t&&(t=2);var o=null!==(i=null===(r=e.segments)||void 0===r?void 0:r.length)&&void 0!==i?i:0,s="";if(n){var a=0;a=2===t?66:19;for(var c=0;c<=o;c++){s+=(0===c?"0 (Base):":c+" ("+64*c+"):").toString().padEnd(a)}s+="\n"}for(var u=-1;u<o;u++){var l="",h=-1==u?e.base:e.segments[u],d=h[O.HIGH],f=h[O.LOW];if(2==t){l=d.toString(2).padStart(32,"0")+"_"+f.toString(2).padStart(32,"0")}else{var p=d?d.toString(16).toUpperCase():"";n&&(p=p.padStart(8,"0"));var m=f.toString(16).toUpperCase();p&&(m=m.padStart(8,"0")),l="0x"+p+m}s+=-1===u?l:" "+l}return s},e.popCount=function(e){for(var t=0,n=-1;n<(null!==(i=null===(r=e.segments)||void 0===r?void 0:r.length)&&void 0!==i?i:0);n++){for(var i,r,o=-1==n?e.base:e.segments[n],s=o[O.LOW],a=o[O.HIGH];s;)s&=s-1,t++;for(;a;)a&=a-1,t++}return t},e.getSegmentByBitIndex=function(e,t,n){if(void 0===n&&(n=!0),t<=63)return e.base;var i,r=e.segments;if(!r){if(!n)return null;r=e.segments=[]}var o=(t>>6)-1;if(r.length<=o){if(!n)return null;for(var s=o-r.length+1,a=0;a<s;a++)r.push([0,0])}return null!==(i=r[o])&&void 0!==i?i:null},e}();U.ZERO={base:[0,0]},exports.LogLevel=void 0,(j=exports.LogLevel||(exports.LogLevel={}))[j.Debug=0]="Debug",j[j.Info=1]="Info",j[j.Warn=2]="Warn",j[j.Error=3]="Error",j[j.Fatal=4]="Fatal",j[j.None=5]="None";var q={BLACK:"",RED:"",GREEN:"",YELLOW:"",BLUE:"",MAGENTA:"",CYAN:"",WHITE:"",BRIGHT_BLACK:"",BRIGHT_RED:"",BRIGHT_GREEN:"",BRIGHT_YELLOW:"",BRIGHT_BLUE:"",BRIGHT_MAGENTA:"",BRIGHT_CYAN:"",BRIGHT_WHITE:"",RESET:"",BOLD:"",UNDERLINE:""},Q=function(){function e(e){void 0===e&&(e={}),this._config=a({level:exports.LogLevel.Info,enableTimestamp:!0,enableColors:"undefined"==typeof window},e)}var t=e.prototype;return t.debug=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];this.log.apply(this,[exports.LogLevel.Debug,e].concat(n))},t.info=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];this.log.apply(this,[exports.LogLevel.Info,e].concat(n))},t.warn=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];this.log.apply(this,[exports.LogLevel.Warn,e].concat(n))},t.error=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];this.log.apply(this,[exports.LogLevel.Error,e].concat(n))},t.fatal=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];this.log.apply(this,[exports.LogLevel.Fatal,e].concat(n))},t.setLevel=function(e){this._config.level=e},t.setColors=function(e){0===Object.keys(e).length?delete this._config.colors:this._config.colors=a({},this._config.colors,e)},t.setPrefix=function(e){this._config.prefix=e},t.log=function(e,t){if(!(e<this._config.level)){var n=t;if(this._config.enableTimestamp)n="["+(new Date).toISOString()+"] "+n;if(this._config.prefix&&(n="["+this._config.prefix+"] "+n),n="["+exports.LogLevel[e].toUpperCase()+"] "+n,this._config.output)this._config.output(e,n);else{for(var i=arguments.length,r=new Array(i>2?i-2:0),o=2;o<i;o++)r[o-2]=arguments[o];this.outputToConsole.apply(this,[e,n].concat(r))}}},t.outputToConsole=function(e,t){for(var n=this._config.enableColors?this.getColors():null,i=arguments.length,r=new Array(i>2?i-2:0),o=2;o<i;o++)r[o-2]=arguments[o];switch(e){case exports.LogLevel.Debug:var s,a;if(n)(s=console).debug.apply(s,[""+n.debug+t+n.reset].concat(r));else(a=console).debug.apply(a,[t].concat(r));break;case exports.LogLevel.Info:var c,u;if(n)(c=console).info.apply(c,[""+n.info+t+n.reset].concat(r));else(u=console).info.apply(u,[t].concat(r));break;case exports.LogLevel.Warn:var l,h;if(n)(l=console).warn.apply(l,[""+n.warn+t+n.reset].concat(r));else(h=console).warn.apply(h,[t].concat(r));break;case exports.LogLevel.Error:var d,f;if(n)(d=console).error.apply(d,[""+n.error+t+n.reset].concat(r));else(f=console).error.apply(f,[t].concat(r));break;case exports.LogLevel.Fatal:var p,m;if(n)(p=console).error.apply(p,[""+n.fatal+t+n.reset].concat(r));else(m=console).error.apply(m,[t].concat(r))}},t.getColors=function(){return a({},{debug:q.BRIGHT_BLACK,info:q.GREEN,warn:q.YELLOW,error:q.RED,fatal:q.BRIGHT_RED,reset:q.RESET},this._config.colors)},e}(),V=function(){function e(){this._loggers=new Map,this._defaultLevel=exports.LogLevel.Info}var t=e.prototype;return t.createDefaultLogger=function(){return this._loggerFactory?this._loggerFactory():new Q({level:this._defaultLevel})},e.getInstance=function(){return e._instance||(e._instance=new e),e._instance},t.getLogger=function(e){return e?this._loggerFactory?this._loggerFactory(e):(this._loggers.has(e)||this._loggers.set(e,new Q({prefix:e,level:this._defaultLevel})),this._loggers.get(e)):this.defaultLogger},t.setLogger=function(e,t){this._loggers.set(e,t)},t.setGlobalLevel=function(e){this._defaultLevel=e,this._defaultLogger instanceof Q&&this._defaultLogger.setLevel(e);for(var t,n=s(this._loggers.values());!(t=n()).done;){var i=t.value;i instanceof Q&&i.setLevel(e)}},t.createChildLogger=function(e,t){var n=e+"."+t;return this.getLogger(n)},t.setGlobalColors=function(e){this._defaultLogger instanceof Q&&this._defaultLogger.setColors(e);for(var t,n=s(this._loggers.values());!(t=n()).done;){var i=t.value;i instanceof Q&&i.setColors(e)}},t.resetColors=function(){this._defaultLogger instanceof Q&&this._defaultLogger.setColors({});for(var e,t=s(this._loggers.values());!(e=t()).done;){var n=e.value;n instanceof Q&&n.setColors({})}},t.setLoggerFactory=function(e){this._loggerFactory=e,delete this._defaultLogger,this._loggers.clear()},o(e,[{key:"defaultLogger",get:function(){return this._defaultLogger||(this._defaultLogger=this.createDefaultLogger()),this._defaultLogger}}])}(),Y=V.getInstance().getLogger();function J(e){return V.getInstance().getLogger(e)}var Z=J("ComponentRegistry"),X=function(){function e(){this._componentTypes=new Map,this._bitIndexToType=new Map,this._componentNameToType=new Map,this._componentNameToId=new Map,this._maskCache=new Map,this._nextBitIndex=0,this._hotReloadEnabled=!1,this._warnedComponents=new Set}var t=e.prototype;return t.register=function(e){var t=L(e);if(B(e)||this._warnedComponents.has(e)||(this._warnedComponents.add(e),console.warn('[ComponentRegistry] Component "'+t+"\" is missing @ECSComponent decorator. This may cause issues with serialization and code minification. Please add: @ECSComponent('"+t+"')")),this._componentTypes.has(e))return this._componentTypes.get(e);if(this._hotReloadEnabled&&this._componentNameToType.has(t)){var n=this._componentNameToType.get(t);if(n!==e){var i=this._componentTypes.get(n);return this._componentTypes.delete(n),this._componentTypes.set(e,i),this._bitIndexToType.set(i,e),this._componentNameToType.set(t,e),Z.debug('Hot reload: replaced component "'+t+'"'),i}}var r=this._nextBitIndex++;return this._componentTypes.set(e,r),this._bitIndexToType.set(r,e),this._componentNameToType.set(t,e),this._componentNameToId.set(t,r),r},t.getBitMask=function(e){var t=this._componentTypes.get(e);if(void 0===t){var n=L(e);throw new Error("Component type "+n+" is not registered")}return U.create(t)},t.getBitIndex=function(e){var t=this._componentTypes.get(e);if(void 0===t){var n=L(e);throw new Error("Component type "+n+" is not registered")}return t},t.isRegistered=function(e){return this._componentTypes.has(e)},t.getTypeByBitIndex=function(e){return this._bitIndexToType.get(e)||null},t.getRegisteredCount=function(){return this._nextBitIndex},t.getComponentType=function(e){return this._componentNameToType.get(e)||null},t.getAllRegisteredTypes=function(){return new Map(this._componentTypes)},t.getAllComponentNames=function(){return new Map(this._componentNameToType)},t.getComponentId=function(e){return this._componentNameToId.get(e)},t.registerComponentByName=function(e){if(this._componentNameToId.has(e))return this._componentNameToId.get(e);var t=this._nextBitIndex++;return this._componentNameToId.set(e,t),t},t.createSingleComponentMask=function(e){var t="single:"+e;if(this._maskCache.has(t))return this._maskCache.get(t);var n=this.getComponentId(e);if(void 0===n)throw new Error("Component type "+e+" is not registered");var i=U.create(n);return this._maskCache.set(t,i),i},t.createComponentMask=function(e){var t="multi:"+[].concat(e).sort().join(",");if(this._maskCache.has(t))return this._maskCache.get(t);for(var n,i=U.clone(U.ZERO),r=s(e);!(n=r()).done;){var o=n.value,a=this.getComponentId(o);if(void 0!==a){var c=U.create(a);U.orInPlace(i,c)}}return this._maskCache.set(t,i),i},t.clearMaskCache=function(){this._maskCache.clear()},t.enableHotReload=function(){this._hotReloadEnabled=!0},t.disableHotReload=function(){this._hotReloadEnabled=!1},t.isHotReloadEnabled=function(){return this._hotReloadEnabled},t.unregister=function(e){var t=this._componentNameToType.get(e);if(t){var n=this._componentTypes.get(t);this._componentTypes.delete(t),void 0!==n&&this._bitIndexToType.delete(n),this._componentNameToType.delete(e),this._componentNameToId.delete(e),this.clearMaskCache(),Z.debug("Component unregistered: "+e)}},t.getRegisteredComponents=function(){for(var e,t=[],n=s(this._componentNameToType);!(e=n()).done;){var i=e.value,r=i[0],o=i[1],a=this._componentTypes.get(o);void 0!==a&&t.push({name:r,type:o,bitIndex:a})}return t},t.reset=function(){this._componentTypes.clear(),this._bitIndexToType.clear(),this._componentNameToType.clear(),this._componentNameToId.clear(),this._maskCache.clear(),this._warnedComponents.clear(),this._nextBitIndex=0,this._hotReloadEnabled=!1},t.cloneFrom=function(e){for(var t,n=s(e.getAllRegisteredTypes());!(t=n()).done;){var i=t.value,r=i[0],o=i[1];this._componentTypes.set(r,o),this._bitIndexToType.set(o,r);var a=L(r);this._componentNameToType.set(a,r),this._componentNameToId.set(a,o)}this._nextBitIndex=e.getRegisteredCount(),this._hotReloadEnabled=e.isHotReloadEnabled()},e}(),K=new X,$=Symbol("SystemTypeName");function ee(e,t){return function(n){if(!e||"string"!=typeof e)throw new Error("ECSComponent装饰器必须提供有效的类型名称");var i=n;return i[z]=e,null!=t&&t.requires&&(i[N]=t.requires),null!=t&&t.editor&&(i[F]=t.editor),K.register(n),n}}function te(e){return e.__systemMetadata__}function ne(e){return te(e.constructor)}function ie(e){var t=e[$];return t||(e.name||"UnknownSystem")}function re(e){return ie(e.constructor)}var oe=function(){function e(e){this._target=e}return e.prototype.deref=function(){return this._target},e}(),se="undefined"!=typeof globalThis&&globalThis.WeakRef||"undefined"!=typeof global&&global.WeakRef||"undefined"!=typeof window&&window.WeakRef||oe,ae=new Map;function ce(e){var t=ae.get(e);return(null==t?void 0:t.deref())||null}var ue=function(){function e(){this._references=new Map}var t=e.prototype;return t.registerReference=function(e,t,n){var i=e.id,r=this._references.get(i);r||(r=new Set,this._references.set(i,r)),this._findRecord(r,t,n)||r.add({component:new se(t),propertyKey:n})},t.unregisterReference=function(e,t,n){var i=e.id,r=this._references.get(i);if(r){var o=this._findRecord(r,t,n);o&&(r.delete(o),0===r.size&&this._references.delete(i))}},t.clearReferencesTo=function(e){var t=this._references.get(e);if(t){for(var n,i=[],r=s(t);!(n=r()).done;){var o=n.value;o.component.deref()&&i.push(o)}for(var a=0,c=i;a<c.length;a++){var u=c[a],l=u.component.deref();l&&(l[u.propertyKey]=null)}this._references.delete(e)}},t.clearComponentReferences=function(e){for(var t,n=s(this._references.entries());!(t=n()).done;){for(var i,r=t.value,o=r[0],a=r[1],c=[],u=s(a);!(i=u()).done;){var l=i.value,h=l.component.deref();h&&h!==e||c.push(l)}for(var d=0,f=c;d<f.length;d++){var p=f[d];a.delete(p)}0===a.size&&this._references.delete(o)}},t.getReferencesTo=function(e){var t=this._references.get(e);if(!t)return[];for(var n,i=[],r=s(t);!(n=r()).done;){var o=n.value;o.component.deref()&&i.push(o)}return i},t.cleanup=function(){for(var e,t=[],n=s(this._references.entries());!(e=n()).done;){for(var i,r=e.value,o=r[0],a=r[1],c=[],u=s(a);!(i=u()).done;){var l=i.value;l.component.deref()||c.push(l)}for(var h=0,d=c;h<d.length;h++){var f=d[h];a.delete(f)}0===a.size&&t.push(o)}for(var p=0,m=t;p<m.length;p++){var v=m[p];this._references.delete(v)}},t.registerEntityScene=function(e,t){ae.set(e,new se(t))},t.unregisterEntityScene=function(e){ae.delete(e)},t.getDebugInfo=function(){for(var e,t={},n=s(this._references.entries());!(e=n()).done;){for(var i,r=e.value,o=r[0],a=[],c=s(r[1]);!(i=c()).done;){var u=i.value,l=u.component.deref();l&&a.push({componentId:l.id,propertyKey:u.propertyKey})}a.length>0&&(t["entity_"+o]=a)}return t},t._findRecord=function(e,t,n){for(var i,r=s(e);!(i=r()).done;){var o=i.value;if(o.component.deref()===t&&o.propertyKey===n)return o}},e}(),le=J("EntityRefDecorator"),he=Symbol("EntityRefMetadata"),de=Symbol("EntityRefValues");function fe(e){var t=e[de];return t||(t=new Map,e[de]=t),t}function pe(e){return e&&("function"==typeof e?e:e.constructor)[he]||null}function me(e,t){var n=pe(e);return!!n&&n.properties.has(t)}var ve=new WeakMap,ge=Symbol.for("@esengine/property:metadata");var ye=Symbol("schedulingMetadata");function _e(e){var t=e;return t[ye]||(t[ye]={stage:"update",before:[],after:[],sets:[]}),t[ye]}function Se(e){for(var t=Object.getPrototypeOf(e);t;){var n=t[ye];if(n)return n;t=Object.getPrototypeOf(t)}}var Ce=function(){function e(){}return e.getConstructor=function(e){return this.TYPE_CONSTRUCTORS[e]||Float32Array},e.getBytesPerElement=function(e){return this.TYPE_BYTES[e]||4},e.getTypeName=function(e){return e instanceof Float32Array?"float32":e instanceof Float64Array?"float64":e instanceof Int32Array?"int32":e instanceof Uint32Array?"uint32":e instanceof Int16Array?"int16":e instanceof Uint16Array?"uint16":e instanceof Int8Array?"int8":e instanceof Uint8Array?"uint8":e instanceof Uint8ClampedArray?"uint8clamped":"float32"},e.createSameType=function(e,t){var n=this.getTypeName(e);return new(this.getConstructor(n))(t)},e.extractFieldMetadata=function(e){var t=new e,n=new Map,i=e,r=new Map,o=function(e,t){if(e)for(var n,i=s(e);!(n=i()).done;){var o=n.value;r.set(o,t)}};o(i.__float64Fields,"float64"),o(i.__float32Fields,"float32"),o(i.__int32Fields,"int32"),o(i.__uint32Fields,"uint32"),o(i.__int16Fields,"int16"),o(i.__uint16Fields,"uint16"),o(i.__int8Fields,"int8"),o(i.__uint8Fields,"uint8"),o(i.__uint8ClampedFields,"uint8clamped");for(var a,c=Object.keys(t).filter(function(e){return"id"!==e}),u=s(c);!(a=u()).done;){var l,h,d,f,p=a.value,m=typeof t[p];if("function"!==m){var v={name:p,type:m},g=r.get(p);g?v.arrayType=g:"number"===m?v.arrayType="float32":"boolean"===m&&(v.arrayType="uint8"),null!==(l=i.__serializeMapFields)&&void 0!==l&&l.has(p)&&(v.isSerializedMap=!0),null!==(h=i.__serializeSetFields)&&void 0!==h&&h.has(p)&&(v.isSerializedSet=!0),null!==(d=i.__serializeArrayFields)&&void 0!==d&&d.has(p)&&(v.isSerializedArray=!0),null!==(f=i.__deepCopyFields)&&void 0!==f&&f.has(p)&&(v.isDeepCopy=!0),n.set(p,v)}}return n},e}();Ce.TYPE_CONSTRUCTORS={float32:Float32Array,float64:Float64Array,int32:Int32Array,uint32:Uint32Array,int16:Int16Array,uint16:Uint16Array,int8:Int8Array,uint8:Uint8Array,uint8clamped:Uint8ClampedArray},Ce.TYPE_BYTES={float32:4,float64:8,int32:4,uint32:4,int16:2,uint16:2,int8:1,uint8:1,uint8clamped:1};var Ee=function(){function e(){}return e.serialize=function(e,t,n){void 0===n&&(n={});try{return n.isMap&&e instanceof Map?JSON.stringify(Array.from(e.entries())):n.isSet&&e instanceof Set?JSON.stringify(Array.from(e)):(n.isArray&&Array.isArray(e),JSON.stringify(e))}catch(e){return this._logger.warn("SoA序列化字段 "+t+" 失败:",e),"{}"}},e.deserialize=function(e,t,n){void 0===n&&(n={});try{var i=JSON.parse(e);return n.isMap?new Map(i):n.isSet?new Set(i):i}catch(e){return this._logger.warn("SoA反序列化字段 "+t+" 失败:",e),null}},e.deepClone=function(e){var t=this;if(null===e||"object"!=typeof e)return e;if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(function(e){return t.deepClone(e)});if(e instanceof Map){for(var n,i=new Map,r=s(e.entries());!(n=r()).done;){var o=n.value,a=o[0],c=o[1];i.set(a,this.deepClone(c))}return i}if(e instanceof Set){for(var u,l=new Set,h=s(e.values());!(u=h()).done;){var d=u.value;l.add(this.deepClone(d))}return l}var f={};for(var p in e)Object.prototype.hasOwnProperty.call(e,p)&&(f[p]=this.deepClone(e[p]));return f},e}();function be(e,t){var n=String(t);e.constructor.__int32Fields||(e.constructor.__int32Fields=new Set),e.constructor.__int32Fields.add(n)}Ee._logger=J("SoASerializer");var Te=function(){function e(e){this.fields=new Map,this.stringFields=new Map,this.serializedFields=new Map,this.complexFields=new Map,this.entityToIndex=new Map,this.indexToEntity=[],this.freeIndices=[],this._size=0,this._capacity=1e3,this.fieldTypes=new Map,this.serializeMapFields=new Set,this.serializeSetFields=new Set,this.serializeArrayFields=new Set,this.type=e,this.initializeFields(e)}var t=e.prototype;return t.initializeFields=function(e){var t=new e,n=e,i=n.__float64Fields||new Set,r=n.__float32Fields||new Set,o=n.__int32Fields||new Set,a=n.__uint32Fields||new Set,c=n.__int16Fields||new Set,u=n.__uint16Fields||new Set,l=n.__int8Fields||new Set,h=n.__uint8Fields||new Set,d=n.__uint8ClampedFields||new Set;this.serializeMapFields=n.__serializeMapFields||new Set,this.serializeSetFields=n.__serializeSetFields||new Set,this.serializeArrayFields=n.__serializeArrayFields||new Set;for(var f,p=new Map,m=s(i);!(f=m()).done;){var v=f.value;p.set(v,"float64")}for(var g,y=s(r);!(g=y()).done;){var _=g.value;p.set(_,"float32")}for(var S,C=s(o);!(S=C()).done;){var E=S.value;p.set(E,"int32")}for(var b,T=s(a);!(b=T()).done;){var w=b.value;p.set(w,"uint32")}for(var I,x=s(c);!(I=x()).done;){var M=I.value;p.set(M,"int16")}for(var A,k=s(u);!(A=k()).done;){var D=A.value;p.set(D,"uint16")}for(var P,O=s(l);!(P=O()).done;){var R=P.value;p.set(R,"int8")}for(var z,N=s(h);!(z=N()).done;){var F=z.value;p.set(F,"uint8")}for(var B,L=s(d);!(B=L()).done;){var H=B.value;p.set(H,"uint8clamped")}for(var W,G=Object.keys(t).filter(function(e){return"id"!==e}),j=s(G);!(W=j()).done;){var U=W.value,q=t[U],Q=typeof q;if("function"!==Q){var V=p.get(U),Y=V?"number":Q;if(this.fieldTypes.set(U,Y),V){var J=Ce.getConstructor(V);this.fields.set(U,new J(this._capacity))}else"number"===Q?this.fields.set(U,new Float32Array(this._capacity)):"boolean"===Q?this.fields.set(U,new Uint8Array(this._capacity)):"string"===Q?this.stringFields.set(U,new Array(this._capacity)):"object"===Q&&null!==q&&(this.serializeMapFields.has(U)||this.serializeSetFields.has(U)||this.serializeArrayFields.has(U))&&this.serializedFields.set(U,new Array(this._capacity))}}},t.addComponent=function(e,t){if(this.entityToIndex.has(e)){var n=this.entityToIndex.get(e);this.updateComponentAtIndex(n,t)}else{var i;this.freeIndices.length>0?i=this.freeIndices.pop():(i=this._size)>=this._capacity&&this.resize(2*this._capacity),this.entityToIndex.set(e,i),this.indexToEntity[i]=e,this.updateComponentAtIndex(i,t),this._size++}},t.updateComponentAtIndex=function(e,t){var n=this.indexToEntity[e],i=new Map,r=this.type.__highPrecisionFields||new Set,o=this.type.__serializeMapFields||new Set,s=this.type.__serializeSetFields||new Set,a=this.type.__serializeArrayFields||new Set,c=this.type.__deepCopyFields||new Set;for(var u in t)if(t.hasOwnProperty(u)&&"id"!==u){var l=t[u],h=typeof l;if("number"===h)if(r.has(u)||!this.fields.has(u))i.set(u,l);else this.fields.get(u)[e]=l;else if("boolean"===h&&this.fields.has(u)){this.fields.get(u)[e]=l?1:0}else if(this.stringFields.has(u)){this.stringFields.get(u)[e]=String(l)}else if(this.serializedFields.has(u)){this.serializedFields.get(u)[e]=Ee.serialize(l,u,{isMap:o.has(u),isSet:s.has(u),isArray:a.has(u)})}else c.has(u)?i.set(u,Ee.deepClone(l)):i.set(u,l)}i.size>0&&this.complexFields.set(n,i)},t.getComponent=function(e){var t=this.entityToIndex.get(e);return void 0===t?null:this.createProxyView(e,t)},t.createProxyView=function(e,t){var n=this;return new Proxy({},{get:function(i,r){var o=String(r),s=n.fields.get(o);if(s)return"boolean"===n.getFieldType(o)?1===s[t]:s[t];var a=n.stringFields.get(o);if(a)return a[t];var c=n.serializedFields.get(o);if(c){var u=c[t];return u?Ee.deserialize(u,o,{isMap:n.serializeMapFields.has(o),isSet:n.serializeSetFields.has(o),isArray:n.serializeArrayFields.has(o)}):void 0}var l=n.complexFields.get(e);return null!=l&&l.has(o)?l.get(o):void 0},set:function(i,r,o){var s=String(r);if("entityId"===s)return!1;var a=n.fields.get(s);if(a){var c=n.getFieldType(s);return a[t]="boolean"===c?o?1:0:o,!0}var u=n.stringFields.get(s);if(u)return u[t]=String(o),!0;if(n.serializedFields.has(s))return n.serializedFields.get(s)[t]=Ee.serialize(o,s,{isMap:n.serializeMapFields.has(s),isSet:n.serializeSetFields.has(s),isArray:n.serializeArrayFields.has(s)}),!0;var l=n.complexFields.get(e);return l||(l=new Map,n.complexFields.set(e,l)),l.set(s,o),!0},has:function(t,i){var r,o=String(i);return n.fields.has(o)||n.stringFields.has(o)||n.serializedFields.has(o)||(null===(r=n.complexFields.get(e))||void 0===r?void 0:r.has(o))||!1},ownKeys:function(){for(var t,i=[],r=s(n.fields.keys());!(t=r()).done;){var o=t.value;i.push(o)}for(var a,c=s(n.stringFields.keys());!(a=c()).done;){var u=a.value;i.push(u)}for(var l,h=s(n.serializedFields.keys());!(l=h()).done;){var d=l.value;i.push(d)}var f=n.complexFields.get(e);if(f)for(var p,m=s(f.keys());!(p=m()).done;){var v=p.value;i.push(v)}return i},getOwnPropertyDescriptor:function(t,i){var r,o=String(i);if(n.fields.has(o)||n.stringFields.has(o)||n.serializedFields.has(o)||null!==(r=n.complexFields.get(e))&&void 0!==r&&r.has(o))return{enumerable:!0,configurable:!0,writable:"entityId"!==o}}})},t.getComponentSnapshot=function(e){var t=this.entityToIndex.get(e);if(void 0===t)return null;for(var n,i=new this.type,r=s(this.fields.entries());!(n=r()).done;){var o=n.value,a=o[0],c=o[1][t],u=this.getFieldType(a);i[a]="boolean"===u?1===c:c}for(var l,h=s(this.stringFields.entries());!(l=h()).done;){var d=l.value,f=d[0],p=d[1];i[f]=p[t]}for(var m,v=s(this.serializedFields.entries());!(m=v()).done;){var g=m.value,y=g[0],_=g[1][t];_&&(i[y]=Ee.deserialize(_,y,{isMap:this.serializeMapFields.has(y),isSet:this.serializeSetFields.has(y),isArray:this.serializeArrayFields.has(y)}))}var S=this.complexFields.get(e);if(S)for(var C,E=s(S.entries());!(C=E()).done;){var b=C.value,T=b[0],w=b[1];i[T]=w}return i},t.getFieldType=function(e){return this.fieldTypes.get(e)||"unknown"},t.hasComponent=function(e){return this.entityToIndex.has(e)},t.removeComponent=function(e){var t=this.entityToIndex.get(e);if(void 0===t)return null;var n=this.getComponent(e);return this.complexFields.delete(e),this.entityToIndex.delete(e),this.freeIndices.push(t),this._size--,n},t.resize=function(e){for(var t,n=s(this.fields.entries());!(t=n()).done;){var i=t.value,r=i[0],o=i[1],a=Ce.createSameType(o,e);a.set(o),this.fields.set(r,a)}for(var c,u=s(this.stringFields.entries());!(c=u()).done;){for(var l=c.value,h=l[0],d=l[1],f=new Array(e),p=0;p<d.length;p++)f[p]=d[p];this.stringFields.set(h,f)}for(var m,v=s(this.serializedFields.entries());!(m=v()).done;){for(var g=m.value,y=g[0],_=g[1],S=new Array(e),C=0;C<_.length;C++)S[C]=_[C];this.serializedFields.set(y,S)}this._capacity=e},t.getActiveIndices=function(){return Array.from(this.entityToIndex.values())},t.getFieldArray=function(e){return this.fields.get(e)||null},t.getTypedFieldArray=function(e){return this.fields.get(String(e))||null},t.getEntityIndex=function(e){return this.entityToIndex.get(e)},t.getEntityIdByIndex=function(e){return this.indexToEntity[e]},t.size=function(){return this._size},t.clear=function(){this.entityToIndex.clear(),this.indexToEntity=[],this.freeIndices=[],this.complexFields.clear(),this._size=0;for(var e,t=s(this.fields.values());!(e=t()).done;){e.value.fill(0)}for(var n,i=s(this.stringFields.values());!(n=i()).done;)for(var r=n.value,o=0;o<r.length;o++)r[o]=void 0;for(var a,c=s(this.serializedFields.values());!(a=c()).done;)for(var u=a.value,l=0;l<u.length;l++)u[l]=void 0},t.compact=function(){if(0!==this.freeIndices.length){for(var e=Array.from(this.entityToIndex.entries()).sort(function(e,t){return e[1]-t[1]}),t=new Map,n=[],i=0;i<e.length;i++){var r=e[i];if(r){var o=r[0],a=r[1];if(t.set(o,i),n[i]=o,i!==a){for(var c,u=s(this.fields.entries());!(c=u()).done;){var l=c.value[1],h=l[a];void 0!==h&&(l[i]=h)}for(var d,f=s(this.stringFields.entries());!(d=f()).done;){var p=d.value[1],m=p[a];void 0!==m&&(p[i]=m)}for(var v,g=s(this.serializedFields.entries());!(v=g()).done;){var y=v.value[1],_=y[a];void 0!==_&&(y[i]=_)}}}}this.entityToIndex=t,this.indexToEntity=n,this.freeIndices=[],this._size=e.length}},t.getStats=function(){for(var e,t=0,n=new Map,i=s(this.fields.entries());!(e=i()).done;){var r=e.value,o=r[0],a=r[1],c=Ce.getTypeName(a),u=Ce.getBytesPerElement(c),l=a.length*u;t+=l,n.set(o,{size:this._size,capacity:a.length,type:c,memory:l})}return{size:this._size,capacity:this._capacity,usedSlots:this._size,fragmentation:this.freeIndices.length/this._capacity,memoryUsage:t,fieldStats:n}},t.performVectorizedOperation=function(e){var t=this.getActiveIndices();e(this.fields,t)},e}(),we=function(){function e(){this.entityId=null,this._lastWriteEpoch=0,this.id=e.idGenerator++}var t=e.prototype;return t.markDirty=function(e){this._lastWriteEpoch=e},t.onAddedToEntity=function(){},t.onRemovedFromEntity=function(){},t.onDeserialized=function(){},o(e,[{key:"lastWriteEpoch",get:function(){return this._lastWriteEpoch}}])}();we.idGenerator=0,v([be,g("design:type",Object)],we.prototype,"entityId",void 0);var Ie=Symbol("SerializableMetadata"),xe=Symbol("SerializeField"),Me=Symbol("SerializeOptions");function Ae(e){return function(t){if(!e||"number"!=typeof e.version)throw new Error("Serializable装饰器必须提供有效的版本号");var n;if(Object.prototype.hasOwnProperty.call(t,Ie))(n=t[Ie]).options=e;else{var i=t[Ie];n={options:e,fields:i?new Map(i.fields):new Map,ignoredFields:i?new Set(i.ignoredFields):new Set},t[Ie]=n}return t}}function ke(e){return function(t,n){var i,r=t.constructor;if(Object.prototype.hasOwnProperty.call(r,Ie))i=r[Ie];else{var o=r[Ie];i={options:o?a({},o.options):{version:1},fields:o?new Map(o.fields):new Map,ignoredFields:o?new Set(o.ignoredFields):new Set},r[Ie]=i}i.fields.set(n,e||{})}}function De(e){return e&&("function"==typeof e?e:e.constructor)[Ie]||null}exports.HierarchyComponent=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).parentId=null,t.childIds=[],t.depth=0,t.bActiveInHierarchy=!0,t.bCacheDirty=!0,t}return u(t,e),t}(we),v([ke(),g("design:type",Object)],exports.HierarchyComponent.prototype,"parentId",void 0),v([ke(),g("design:type",Array)],exports.HierarchyComponent.prototype,"childIds",void 0),exports.HierarchyComponent=v([ee("Hierarchy",{editor:{hideInInspector:!0}}),Ae({version:1,typeId:"Hierarchy"})],exports.HierarchyComponent);var Pe=function(){function e(){this.condition={all:[],any:[],none:[]}}e.all=function(){var t=new e;return t.all.apply(t,arguments)},e.any=function(){var t=new e;return t.any.apply(t,arguments)},e.none=function(){var t=new e;return t.none.apply(t,arguments)},e.byTag=function(t){return(new e).withTag(t)},e.byName=function(t){return(new e).withName(t)},e.byComponent=function(t){return(new e).withComponent(t)},e.complex=function(){return new e},e.empty=function(){return new e},e.nothing=function(){var t=new e;return t.condition.matchNothing=!0,t};var t=e.prototype;return t.all=function(){var e;return(e=this.condition.all).push.apply(e,arguments),this},t.any=function(){var e;return(e=this.condition.any).push.apply(e,arguments),this},t.none=function(){var e;return(e=this.condition.none).push.apply(e,arguments),this},t.exclude=function(){return this.none.apply(this,arguments)},t.one=function(){return this.any.apply(this,arguments)},t.withTag=function(e){return this.condition.tag=e,this},t.withName=function(e){return this.condition.name=e,this},t.withComponent=function(e){return this.condition.component=e,this},t.withoutTag=function(){return delete this.condition.tag,this},t.withoutName=function(){return delete this.condition.name,this},t.withoutComponent=function(){return delete this.condition.component,this},t.getCondition=function(){return a({all:[].concat(this.condition.all),any:[].concat(this.condition.any),none:[].concat(this.condition.none)},void 0!==this.condition.tag&&{tag:this.condition.tag},void 0!==this.condition.name&&{name:this.condition.name},void 0!==this.condition.component&&{component:this.condition.component},this.condition.matchNothing&&{matchNothing:!0})},t.isEmpty=function(){return 0===this.condition.all.length&&0===this.condition.any.length&&0===this.condition.none.length&&void 0===this.condition.tag&&void 0===this.condition.name&&void 0===this.condition.component&&!this.condition.matchNothing},t.isNothing=function(){return!0===this.condition.matchNothing},t.reset=function(){return this.condition.all.length=0,this.condition.any.length=0,this.condition.none.length=0,delete this.condition.tag,delete this.condition.name,delete this.condition.component,delete this.condition.matchNothing,this},t.clone=function(){var t,n,i,r=new e;return(t=r.condition.all).push.apply(t,this.condition.all),(n=r.condition.any).push.apply(n,this.condition.any),(i=r.condition.none).push.apply(i,this.condition.none),void 0!==this.condition.tag&&(r.condition.tag=this.condition.tag),void 0!==this.condition.name&&(r.condition.name=this.condition.name),void 0!==this.condition.component&&(r.condition.component=this.condition.component),this.condition.matchNothing&&(r.condition.matchNothing=!0),r},t.toString=function(){if(this.condition.matchNothing)return"Matcher[nothing]";var e=[];return this.condition.all.length>0&&e.push("all("+this.condition.all.map(function(e){return L(e)}).join(", ")+")"),this.condition.any.length>0&&e.push("any("+this.condition.any.map(function(e){return L(e)}).join(", ")+")"),this.condition.none.length>0&&e.push("none("+this.condition.none.map(function(e){return L(e)}).join(", ")+")"),void 0!==this.condition.tag&&e.push("tag("+this.condition.tag+")"),void 0!==this.condition.name&&e.push("name("+this.condition.name+")"),void 0!==this.condition.component&&e.push("component("+L(this.condition.component)+")"),"Matcher["+e.join(" & ")+"]"},e}(),Oe=function(){function e(){this._frameCache=null,this._persistentCache=null,this._trackedEntities=new Set}var t=e.prototype;return t.getFrame=function(){return this._frameCache},t.setFrame=function(e){this._frameCache=e},t.getPersistent=function(){return this._persistentCache},t.setPersistent=function(e){this._persistentCache=e},t.getTracked=function(){return this._trackedEntities},t.addTracked=function(e){this._trackedEntities.add(e)},t.removeTracked=function(e){this._trackedEntities.delete(e)},t.isTracked=function(e){return this._trackedEntities.has(e)},t.invalidate=function(){this._persistentCache=null},t.clearFrame=function(){this._frameCache=null},t.clearAll=function(){this._frameCache=null,this._persistentCache=null,this._trackedEntities.clear()},t.hasPersistent=function(){return null!==this._persistentCache},t.hasFrame=function(){return null!==this._frameCache},t.getStats=function(){var e,t,n,i;return{hasFrame:null!==this._frameCache,hasPersistent:null!==this._persistentCache,trackedCount:this._trackedEntities.size,frameEntityCount:null!==(e=null===(t=this._frameCache)||void 0===t?void 0:t.length)&&void 0!==e?e:0,persistentEntityCount:null!==(n=null===(i=this._persistentCache)||void 0===i?void 0:i.length)&&void 0!==n?n:0}},e}(),Re=function(){function e(e){this.dense=[],this.entityIds=[],this.entityToIndex=new Map,this.componentType=e}var t=e.prototype;return t.addComponent=function(e,t){if(this.entityToIndex.has(e))throw new Error("Entity "+e+" already has component "+L(this.componentType));var n=this.dense.length;this.dense.push(t),this.entityIds.push(e),this.entityToIndex.set(e,n)},t.getComponent=function(e){var t=this.entityToIndex.get(e);return void 0!==t?this.dense[t]:null},t.hasComponent=function(e){return this.entityToIndex.has(e)},t.removeComponent=function(e){var t=this.entityToIndex.get(e);if(void 0===t)return null;var n=this.dense[t],i=this.dense.length-1;if(t!==i){var r=this.dense[i],o=this.entityIds[i];this.dense[t]=r,this.entityIds[t]=o,this.entityToIndex.set(o,t)}return this.dense.pop(),this.entityIds.pop(),this.entityToIndex.delete(e),n},t.forEach=function(e){for(var t=0;t<this.dense.length;t++)e(this.dense[t],this.entityIds[t],t)},t.getDenseArray=function(){return{components:[].concat(this.dense),entityIds:[].concat(this.entityIds)}},t.clear=function(){this.dense.length=0,this.entityIds.length=0,this.entityToIndex.clear()},t.getStats=function(){return{totalSlots:this.dense.length,usedSlots:this.dense.length,freeSlots:0,fragmentation:0}},o(e,[{key:"size",get:function(){return this.dense.length}},{key:"type",get:function(){return this.componentType}}])}(),ze=function(){function e(){this.storages=new Map}var t=e.prototype;return t.isSoAStorage=function(e){return this.storages.get(e)instanceof Te},t.getSoAStorage=function(e){var t=this.getStorage(e);return t instanceof Te?t:null},t.getFieldArray=function(e,t){var n=this.getSoAStorage(e);return n?n.getFieldArray(t):null},t.getTypedFieldArray=function(e,t){var n=this.getSoAStorage(e);return n?n.getTypedFieldArray(t):null},t.getActiveIndices=function(e){var t=this.getSoAStorage(e);return t?t.getActiveIndices():[]},t.getEntityIndex=function(e,t){var n=this.getSoAStorage(e);return n?n.getEntityIndex(t):void 0},t.getEntityIdByIndex=function(e,t){var n=this.getSoAStorage(e);return n?n.getEntityIdByIndex(t):void 0},t.getStorage=function(t){var n=this.storages.get(t);n||(t.__enableSoA?(n=new Te(t),e._logger.info("为 "+L(t)+" 启用SoA优化(适用于大规模批量操作)")):n=new Re(t),this.storages.set(t,n));return n},t.addComponent=function(e,t){var n=t.constructor;this.getStorage(n).addComponent(e,t)},t.getComponent=function(e,t){var n=this.storages.get(t);return n?n.getComponent(e):null},t.hasComponent=function(e,t){var n=this.storages.get(t);return!!n&&n.hasComponent(e)},t.removeComponent=function(e,t){var n=this.storages.get(t);return n?n.removeComponent(e):null},t.removeAllComponents=function(e){for(var t,n=s(this.storages.values());!(t=n()).done;){t.value.removeComponent(e)}},t.getComponentMask=function(e,t){void 0===t&&(t=K);for(var n,i=U.clone(U.ZERO),r=s(this.storages.entries());!(n=r()).done;){var o=n.value,a=o[0];if(o[1].hasComponent(e)){var c=t.getBitMask(a);U.orInPlace(i,c)}}return i},t.getAllStats=function(){for(var e,t=new Map,n=s(this.storages.entries());!(e=n()).done;){var i=e.value,r=i[0],o=i[1],a=L(r);t.set(a,o.getStats())}return t},t.clear=function(){for(var e,t=s(this.storages.values());!(e=t()).done;){e.value.clear()}this.storages.clear()},e}();ze._logger=J("ComponentStorage");var Ne,Fe=J("CommandBuffer");exports.CommandType=void 0,(Ne=exports.CommandType||(exports.CommandType={})).ADD_COMPONENT="add_component",Ne.REMOVE_COMPONENT="remove_component",Ne.DESTROY_ENTITY="destroy_entity",Ne.SET_ENTITY_ACTIVE="set_entity_active";var Be=function(){function e(e,t){void 0===t&&(t=!1),this._pending=new Map,this._commands=[],this._scene=null,this._debug=!1,this._useDeduplication=!0,this._scene=null!=e?e:null,this._debug=t}var t=e.prototype;return t.setScene=function(e){this._scene=e},t.setDeduplication=function(e){this._useDeduplication=e},t.getPending=function(e){var t=this._pending.get(e);return t||(t={},this._pending.set(e,t)),t},t.getTypeId=function(e){return"function"==typeof e?K.getBitIndex(e):K.getBitIndex(e.constructor)},t.addComponent=function(e,t){if(this._useDeduplication){var n,i=this.getPending(e);if(i.bDestroy)return void(this._debug&&Fe.debug("CommandBuffer: 忽略添加组件,实体 "+e.name+" 已标记销毁"));var r=this.getTypeId(t);null===(n=i.removes)||void 0===n||n.delete(r),i.adds||(i.adds=new Map),i.adds.set(r,t),this._debug&&Fe.debug("CommandBuffer: 延迟添加组件 "+t.constructor.name+" 到实体 "+e.name)}else this._commands.push({type:exports.CommandType.ADD_COMPONENT,entity:e,component:t})},t.removeComponent=function(e,t){if(this._useDeduplication){var n,i=this.getPending(e);if(i.bDestroy)return void(this._debug&&Fe.debug("CommandBuffer: 忽略移除组件,实体 "+e.name+" 已标记销毁"));var r=this.getTypeId(t);null===(n=i.adds)||void 0===n||n.delete(r),i.removes||(i.removes=new Set),i.removes.add(r),this._debug&&Fe.debug("CommandBuffer: 延迟移除组件 "+t.name+" 从实体 "+e.name)}else this._commands.push({type:exports.CommandType.REMOVE_COMPONENT,entity:e,componentType:t})},t.destroyEntity=function(e){if(this._useDeduplication){var t,n,i=this.getPending(e);null===(t=i.adds)||void 0===t||t.clear(),null===(n=i.removes)||void 0===n||n.clear(),delete i.active,i.bDestroy=!0,this._debug&&Fe.debug("CommandBuffer: 延迟销毁实体 "+e.name)}else this._commands.push({type:exports.CommandType.DESTROY_ENTITY,entity:e})},t.setEntityActive=function(e,t){if(this._useDeduplication){var n=this.getPending(e);if(n.bDestroy)return void(this._debug&&Fe.debug("CommandBuffer: 忽略设置激活状态,实体 "+e.name+" 已标记销毁"));n.active=t,this._debug&&Fe.debug("CommandBuffer: 延迟设置实体 "+e.name+" 激活状态为 "+t)}else this._commands.push({type:exports.CommandType.SET_ENTITY_ACTIVE,entity:e,value:t})},t.flush=function(){return this._useDeduplication?this.flushDeduplication():this.flushLegacy()},t.flushDeduplication=function(){if(0===this._pending.size)return 0;var e=this._pending.size,t=0;this._debug&&Fe.debug("CommandBuffer: 开始执行 "+e+" 个实体的延迟命令");var n=this._pending;this._pending=new Map;for(var i,r=s(n);!(i=r()).done;){var o=i.value,a=o[0],c=o[1];if(!c.bDestroy&&a.scene&&(c.removes&&c.removes.size>0))for(var u,l=s(c.removes);!(u=l()).done;){var h=u.value;try{var d=K.getTypeByBitIndex(h);d&&(a.removeComponentByType(d),t++)}catch(e){Fe.error("CommandBuffer: 移除组件失败",{entity:a.name,typeId:h,error:e})}}}for(var f,p=s(n);!(f=p()).done;){var m=f.value,v=m[0],g=m[1];if(!g.bDestroy&&v.scene&&(g.adds&&g.adds.size>0))for(var y,_=s(g.adds.values());!(y=_()).done;){var S=y.value;try{v.addComponent(S),t++}catch(e){Fe.error("CommandBuffer: 添加组件失败",{entity:v.name,component:S.constructor.name,error:e})}}}for(var C,E=s(n);!(C=E()).done;){var b=C.value,T=b[0],w=b[1];if(!w.bDestroy&&T.scene&&void 0!==w.active)try{T.active=w.active,t++}catch(e){Fe.error("CommandBuffer: 设置激活状态失败",{entity:T.name,error:e})}}for(var I,x=s(n);!(I=x()).done;){var M=I.value,A=M[0];if(M[1].bDestroy&&A.scene)try{A.destroy(),t++}catch(e){Fe.error("CommandBuffer: 销毁实体失败",{entity:A.name,error:e})}}return this._debug&&Fe.debug("CommandBuffer: 完成执行 "+t+" 个延迟命令"),t},t.flushLegacy=function(){if(0===this._commands.length)return 0;var e=this._commands.length;this._debug&&Fe.debug("CommandBuffer: 开始执行 "+e+" 个延迟命令");var t=this._commands;this._commands=[];for(var n,i=s(t);!(n=i()).done;){var r=n.value;this.executeCommand(r)}return this._debug&&Fe.debug("CommandBuffer: 完成执行 "+e+" 个延迟命令"),e},t.executeCommand=function(e){if(e.entity.scene)try{switch(e.type){case exports.CommandType.ADD_COMPONENT:e.component&&e.entity.addComponent(e.component);break;case exports.CommandType.REMOVE_COMPONENT:e.componentType&&e.entity.removeComponentByType(e.componentType);break;case exports.CommandType.DESTROY_ENTITY:e.entity.destroy();break;case exports.CommandType.SET_ENTITY_ACTIVE:void 0!==e.value&&(e.entity.active=e.value)}}catch(t){Fe.error("CommandBuffer: 执行命令失败",{command:e,error:t})}else this._debug&&Fe.debug("CommandBuffer: 跳过命令,实体 "+e.entity.name+" 已无效")},t.clear=function(){if(this._debug){var e=this._useDeduplication?this._pending.size:this._commands.length;e>0&&Fe.debug("CommandBuffer: 清空 "+e+" 个未执行的命令")}this._pending.clear(),this._commands.length=0},t.dispose=function(){this.clear(),this._scene=null},o(e,[{key:"scene",get:function(){return this._scene}},{key:"pendingCount",get:function(){if(this._useDeduplication){for(var e,t=0,n=s(this._pending.values());!(e=n()).done;){var i=e.value;i.bDestroy&&t++,void 0!==i.active&&t++,i.adds&&(t+=i.adds.size),i.removes&&(t+=i.removes.size)}return t}return this._commands.length}},{key:"hasPending",get:function(){return this._useDeduplication?this._pending.size>0:this._commands.length>0}}])}(),Le=function(){function e(e){this.commands=new Be,this._lastProcessEpoch=0,this._shouldProcessThisFrame=!1,this._updateOrder=0,this._addOrder=0,this._enabled=!0,this._performanceMonitor=null,this._systemName=re(this),this._initialized=!1,this._matcher=e||Pe.empty(),this._eventListeners=[],this._scene=null,this._destroyed=!1,this._entityIdMap=null,this._entityIdMapVersion=-1,this.logger=J(this.getLoggerName()),this._entityCache=new Oe;var t=Se(this);this._schedulingMetadata=t?a({},t):{stage:"update",before:[],after:[],sets:[]}}var t=e.prototype;return t.setPerformanceMonitor=function(e){this._performanceMonitor=e},t.getPerformanceMonitor=function(){if(!this._performanceMonitor)throw new Error(this._systemName+": PerformanceMonitor未注入,请确保在Core.create()之后再添加System到Scene");return this._performanceMonitor},t.setUpdateOrder=function(e){var t;this._updateOrder!==e&&(this._updateOrder=e,null===(t=this._scene)||void 0===t||t.markSystemsOrderDirty())},t.stage=function(e){var t;return this._schedulingMetadata.stage=e,null===(t=this._scene)||void 0===t||t.markSystemsOrderDirty(),this},t.before=function(){var e,t;return(e=this._schedulingMetadata.before).push.apply(e,arguments),null===(t=this._scene)||void 0===t||t.markSystemsOrderDirty(),this},t.after=function(){var e,t;return(e=this._schedulingMetadata.after).push.apply(e,arguments),null===(t=this._scene)||void 0===t||t.markSystemsOrderDirty(),this},t.inSet=function(){var e,t;return(e=this._schedulingMetadata.sets).push.apply(e,arguments),null===(t=this._scene)||void 0===t||t.markSystemsOrderDirty(),this},t.getStage=function(){return this._schedulingMetadata.stage},t.getBefore=function(){return this._schedulingMetadata.before},t.getAfter=function(){return this._schedulingMetadata.after},t.getSets=function(){return this._schedulingMetadata.sets},t.initialize=function(){if(!this._initialized){if(this._initialized=!0,this.scene){this._entityCache.invalidate();for(var e,t=s(this.queryEntities());!(e=t()).done;){var n=e.value;this.onAdded(n)}}this.onInitialize()}},t.onInitialize=function(){},t.clearEntityCache=function(){this._entityCache.invalidate()},t.resetEntityTracking=function(){this._entityCache.clearAll(),this._entityIdMap=null,this._entityIdMapVersion=-1},t.reset=function(){this._destroyed||(this.scene=null,this._initialized=!1,this._entityCache.clearAll(),this._entityIdMap=null,this._entityIdMapVersion=-1,this.destroy())},t.queryEntities=function(){var e;if(null===(e=this.scene)||void 0===e||!e.querySystem||!this._matcher)return[];var t=this._matcher.getCondition(),n=this.scene.querySystem,i=[];return this._matcher.isNothing()?[]:(i=this._matcher.isEmpty()?n.getAllEntities():this.isSingleCondition(t)?this.executeSingleConditionQuery(t,n):this.executeComplexQuery(t,n),this.updateEntityTracking(i),i)},t.isSingleCondition=function(e){var t=(e.all.length>0?1:0)|(e.any.length>0?2:0)|(e.none.length>0?4:0)|(void 0!==e.tag?8:0)|(void 0!==e.name?16:0)|(void 0!==e.component?32:0);return 0!==t&&!(t&t-1)},t.executeSingleConditionQuery=function(e,t){return void 0!==e.tag?t.queryByTag(e.tag).entities:void 0!==e.name?t.queryByName(e.name).entities:void 0!==e.component?t.queryByComponent(e.component).entities:e.all.length>0&&0===e.any.length&&0===e.none.length?t.queryAll.apply(t,e.all).entities:0===e.all.length&&e.any.length>0&&0===e.none.length?t.queryAny.apply(t,e.any).entities:0===e.all.length&&0===e.any.length&&e.none.length>0?t.queryNone.apply(t,e.none).entities:[]},t.executeComplexQueryWithIdSets=function(e,t){var n=null;if(void 0!==e.tag){var i=t.queryByTag(e.tag);n=this.extractEntityIds(i.entities)}if(void 0!==e.name){var r=this.extractEntityIds(t.queryByName(e.name).entities);n=n?this.intersectIdSets(n,r):r}if(void 0!==e.component){var o=this.extractEntityIds(t.queryByComponent(e.component).entities);n=n?this.intersectIdSets(n,o):o}if(e.all.length>0){var s=this.extractEntityIds(t.queryAll.apply(t,e.all).entities);n=n?this.intersectIdSets(n,s):s}if(e.any.length>0){var a=this.extractEntityIds(t.queryAny.apply(t,e.any).entities);n=n?this.intersectIdSets(n,a):a}if(e.none.length>0){n||(n=this.extractEntityIds(t.getAllEntities()));var c=t.queryAny.apply(t,e.none),u=this.extractEntityIds(c.entities);n=this.differenceIdSets(n,u)}return n?this.idSetToEntityArray(n,t.getAllEntities()):[]},t.extractEntityIds=function(e){for(var t=e.length,n=new Set,i=0;i<t;i=i+1|0)n.add(0|e[i].id);return n},t.intersectIdSets=function(e,t){var n,i;e.size<=t.size?(n=e,i=t):(n=t,i=e);for(var r,o=new Set,a=s(n);!(r=a()).done;){var c=r.value;i.has(c)&&o.add(c)}return o},t.differenceIdSets=function(e,t){for(var n,i=new Set,r=s(e);!(n=r()).done;){var o=n.value;t.has(o)||i.add(o)}return i},t.getEntityIdMap=function(e){var t,n,i=null!==(t=null===(n=this.scene)||void 0===n||null===(n=n.querySystem)||void 0===n?void 0:n.version)&&void 0!==t?t:0;return null!==this._entityIdMap&&this._entityIdMapVersion===i?this._entityIdMap:this.rebuildEntityIdMap(e,i)},t.rebuildEntityIdMap=function(e,t){var n=this._entityIdMap;n?n.clear():n=new Map;for(var i=e.length,r=0;r<i;r=r+1|0){var o=e[r];n.set(0|o.id,o)}return this._entityIdMap=n,this._entityIdMapVersion=t,n},t.idSetToEntityArray=function(e,t){for(var n,i=this.getEntityIdMap(t),r=e.size,o=new Array(r),a=0,c=s(e);!(n=c()).done;){var u=n.value,l=i.get(u);void 0!==l&&(o[a]=l,a=a+1|0)}return a<r&&(o.length=a),o},t.executeComplexQuery=function(e,t){return this.executeComplexQueryWithIdSets(e,t)},t.update=function(){if(this._shouldProcessThisFrame=this._enabled&&this.onCheckProcessing(),this._shouldProcessThisFrame){var e=this.getPerformanceMonitor(),t=e.startMonitoring(this._systemName),n=0;try{this.onBegin();var i=this.queryEntities();this._entityCache.setFrame(i),n=i.length,this.process(i)}finally{e.endMonitoring(this._systemName,t,n)}}},t.lateUpdate=function(){if(this._shouldProcessThisFrame){var e=this.getPerformanceMonitor(),t=e.startMonitoring(this._systemName+"_Late"),n=0;try{var i=this.queryEntities();this._entityCache.setFrame(i),n=i.length,this.lateProcess(i),this.onEnd()}finally{e.endMonitoring(this._systemName+"_Late",t,n),this._entityCache.clearFrame()}}},t.flushCommands=function(){return this.commands.flush()},t.onBegin=function(){},t.process=function(e){},t.lateProcess=function(e){},t.onEnd=function(){},t.onCheckProcessing=function(){return!0},t.getPerformanceData=function(){return this.getPerformanceMonitor().getSystemData(this._systemName)},t.getPerformanceStats=function(){return this.getPerformanceMonitor().getSystemStats(this._systemName)},t.resetPerformanceData=function(){this.getPerformanceMonitor().resetSystem(this._systemName)},t.toString=function(){var e=this.entities.length,t=this.getPerformanceData(),n=t?" ("+t.executionTime.toFixed(2)+"ms)":"";return this._systemName+"["+e+" entities]"+n},t.matchesEntity=function(e){if(!this._matcher)return!1;if(this._matcher.isNothing())return!1;if(this._matcher.isEmpty())return!0;for(var t,n=this._matcher.getCondition(),i=s(n.all);!(t=i()).done;){var r=t.value;if(!e.hasComponent(r))return!1}if(n.any.length>0){for(var o,a=!1,c=s(n.any);!(o=c()).done;){var u=o.value;if(e.hasComponent(u)){a=!0;break}}if(!a)return!1}for(var l,h=s(n.none);!(l=h()).done;){var d=l.value;if(e.hasComponent(d))return!1}return(void 0===n.tag||e.tag===n.tag)&&((void 0===n.name||e.name===n.name)&&!(void 0!==n.component&&!e.hasComponent(n.component)))},t.isTracking=function(e){return this._entityCache.isTracked(e)},t.handleEntityComponentChanged=function(e){if(this._matcher&&this._enabled){var t=this._entityCache.isTracked(e),n=this.matchesEntity(e);!t&&n?(this._entityCache.addTracked(e),this._entityCache.invalidate(),this.onAdded(e)):t&&!n&&(this._entityCache.removeTracked(e),this._entityCache.invalidate(),this.onRemoved(e))}},t.updateEntityTracking=function(e){for(var t,n=new Set(e),i=!1,r=s(e);!(t=r()).done;){var o=t.value;this._entityCache.isTracked(o)||(this._entityCache.addTracked(o),i=!0)}for(var a,c=s(this._entityCache.getTracked());!(a=c()).done;){var u=a.value;n.has(u)||(this._entityCache.removeTracked(u),i=!0)}i&&this._entityCache.invalidate()},t.onAdded=function(e){},t.onRemoved=function(e){},t.dispose=function(){this._destroyed||(this.cleanupManualEventListeners(),this.onDestroy(),this._entityCache.clearAll(),this._entityIdMap=null,this.commands.dispose(),this._initialized=!1,this._scene=null,this._destroyed=!0,this.logger.debug("System "+this._systemName+" disposed"))},t.addEventListener=function(e,t,n){var i;if(null===(i=this.scene)||void 0===i||!i.eventSystem)return this.logger.warn(this.systemName+": 无法添加事件监听器,scene.eventSystem 不可用"),null;var r=this.scene.eventSystem.on(e,t,n);return r&&this._eventListeners.push({eventSystem:this.scene.eventSystem,eventType:e,listenerRef:r}),r},t.removeEventListener=function(e,t){var n=this._eventListeners.findIndex(function(n){return n.eventType===e&&n.listenerRef===t});if(n>=0){var i=this._eventListeners[n];if(!i)return;i.eventSystem.off(e,i.listenerRef),this._eventListeners.splice(n,1)}},t.cleanupManualEventListeners=function(){for(var e,t=s(this._eventListeners);!(e=t()).done;){var n=e.value;try{n.eventSystem.off(n.eventType,n.listenerRef)}catch(e){this.logger.warn(this.systemName+': 移除事件监听器失败 "'+n.eventType+'"',e)}}this._eventListeners.length=0},t.destroy=function(){this._destroyed||(this.cleanupManualEventListeners(),this._destroyed=!0,this.onDestroy())},t.getLoggerName=function(){return re(this)},t.onDestroy=function(){},t.requireComponent=function(e,t){var n=e.getComponent(t);if(!n)throw new Error("Component "+t.name+" not found on entity "+e.name+" in "+this.systemName);return n},t.getComponents=function(e){for(var t=this,n=arguments.length,i=new Array(n>1?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];return i.map(function(n){return t.requireComponent(e,n)})},t.forEach=function(e,t){for(var n=0;n<e.length;n++)t(e[n],n)},t.filterEntities=function(e,t){return Array.from(e).filter(t)},t.mapEntities=function(e,t){return Array.from(e).map(t)},t.findEntity=function(e,t){for(var n=0;n<e.length;n++)if(t(e[n],n))return e[n]},t.someEntity=function(e,t){for(var n=0;n<e.length;n++)if(t(e[n],n))return!0;return!1},t.everyEntity=function(e,t){for(var n=0;n<e.length;n++)if(!t(e[n],n))return!1;return!0},t.saveEpoch=function(){this._lastProcessEpoch=this.currentEpoch},t.forEachChanged=function(e,t,n,i){for(var r=null!=i?i:this._lastProcessEpoch,o=0;o<e.length;o++){for(var a,c=e[o],u=!1,l=s(t);!(a=l()).done;){var h=a.value,d=c.getComponent(h);if(d&&d.lastWriteEpoch>r){u=!0;break}}u&&n(c,o)}this._lastProcessEpoch=this.currentEpoch},t.filterChanged=function(e,t,n){for(var i=null!=n?n:this._lastProcessEpoch,r=[],o=0;o<e.length;o++)for(var a,c=e[o],u=s(t);!(a=u()).done;){var l=a.value,h=c.getComponent(l);if(h&&h.lastWriteEpoch>i){r.push(c);break}}return r},t.hasChanged=function(e,t,n){for(var i,r=null!=n?n:this._lastProcessEpoch,o=s(t);!(i=o()).done;){var a=i.value,c=e.getComponent(a);if(c&&c.lastWriteEpoch>r)return!0}return!1},o(e,[{key:"entities",get:function(){var e=this._entityCache.getFrame();return null!==e?e:(this._entityCache.hasPersistent()||this._entityCache.setPersistent(this.queryEntities()),this._entityCache.getPersistent())}},{key:"updateOrder",get:function(){return this._updateOrder},set:function(e){this.setUpdateOrder(e)}},{key:"addOrder",get:function(){return this._addOrder},set:function(e){this._addOrder=e}},{key:"enabled",get:function(){return this._enabled},set:function(e){this._enabled=e}},{key:"systemName",get:function(){return this._systemName}},{key:"scene",get:function(){return this._scene},set:function(e){this._scene=e,this.commands.setScene(e)}},{key:"matcher",get:function(){return this._matcher}},{key:"lastProcessEpoch",get:function(){return this._lastProcessEpoch}},{key:"currentEpoch",get:function(){var e,t;return null!==(e=null===(t=this._scene)||void 0===t||null===(t=t.epochManager)||void 0===t?void 0:t.current)&&void 0!==e?e:0}}])}(),He=function(e){function t(){var t;return(t=e.call(this,Pe.empty().all(exports.HierarchyComponent))||this).dirtyEntities=new Set,t}u(t,e);var n=t.prototype;return n.process=function(e){if(0!==this.dirtyEntities.size){for(var t,n=s(this.dirtyEntities);!(t=n()).done;){var i=t.value;i.scene&&this.updateHierarchyCache(i)}this.dirtyEntities.clear()}},n.setParent=function(e,t){var n,i=e.getComponent(exports.HierarchyComponent);i||(i=new exports.HierarchyComponent,e.addComponent(i));var r=i.parentId;if(r!==(null!==(n=null==t?void 0:t.id)&&void 0!==n?n:null)){if(t&&this.isAncestorOf(e,t))throw new Error("Cannot set parent: would create circular reference");if(null!==r){var o,s=null===(o=this.scene)||void 0===o?void 0:o.findEntityById(r);if(s){var a=s.getComponent(exports.HierarchyComponent);if(a){var c=a.childIds.indexOf(e.id);-1!==c&&a.childIds.splice(c,1)}}}if(t){var u=t.getComponent(exports.HierarchyComponent);u||(u=new exports.HierarchyComponent,t.addComponent(u)),i.parentId=t.id,u.childIds.push(e.id)}else i.parentId=null;this.markCacheDirty(e)}},n.insertChildAt=function(e,t,n){var i=t.getComponent(exports.HierarchyComponent),r=e.getComponent(exports.HierarchyComponent);if(i||(i=new exports.HierarchyComponent,t.addComponent(i)),r||(r=new exports.HierarchyComponent,e.addComponent(r)),this.isAncestorOf(t,e))throw new Error("Cannot set parent: would create circular reference");if(null!==i.parentId&&i.parentId!==e.id){var o,s=null===(o=this.scene)||void 0===o?void 0:o.findEntityById(i.parentId);if(s){var a=s.getComponent(exports.HierarchyComponent);if(a){var c=a.childIds.indexOf(t.id);-1!==c&&a.childIds.splice(c,1)}}}i.parentId=e.id;var u=r.childIds.indexOf(t.id);-1!==u&&r.childIds.splice(u,1),n<0||n>=r.childIds.length?r.childIds.push(t.id):r.childIds.splice(n,0,t.id),this.markCacheDirty(t)},n.removeChild=function(e,t){var n=e.getComponent(exports.HierarchyComponent),i=t.getComponent(exports.HierarchyComponent);if(!n||!i)return!1;if(i.parentId!==e.id)return!1;var r=n.childIds.indexOf(t.id);return-1!==r&&n.childIds.splice(r,1),i.parentId=null,this.markCacheDirty(t),!0},n.removeAllChildren=function(e){var t=e.getComponent(exports.HierarchyComponent);if(t)for(var n,i=s([].concat(t.childIds));!(n=i()).done;){var r,o=n.value,a=null===(r=this.scene)||void 0===r?void 0:r.findEntityById(o);a&&this.removeChild(e,a)}},n.getParent=function(e){var t,n,i=e.getComponent(exports.HierarchyComponent);return i&&null!==i.parentId&&null!==(t=null===(n=this.scene)||void 0===n?void 0:n.findEntityById(i.parentId))&&void 0!==t?t:null},n.getChildren=function(e){var t=e.getComponent(exports.HierarchyComponent);if(!t)return[];for(var n,i=[],r=s(t.childIds);!(n=r()).done;){var o,a=n.value,c=null===(o=this.scene)||void 0===o?void 0:o.findEntityById(a);c&&i.push(c)}return i},n.getChildCount=function(e){var t,n=e.getComponent(exports.HierarchyComponent);return null!==(t=null==n?void 0:n.childIds.length)&&void 0!==t?t:0},n.hasChildren=function(e){return this.getChildCount(e)>0},n.isAncestorOf=function(e,n){for(var i=this.getParent(n),r=0;i&&r<t.MAX_DEPTH;){if(i.id===e.id)return!0;i=this.getParent(i),r++}return!1},n.isDescendantOf=function(e,t){return this.isAncestorOf(t,e)},n.getRoot=function(e){for(var n=e,i=this.getParent(n),r=0;i&&r<t.MAX_DEPTH;)n=i,i=this.getParent(n),r++;return n},n.getDepth=function(e){var n=e.getComponent(exports.HierarchyComponent);if(!n)return 0;if(!n.bCacheDirty)return n.depth;for(var i=0,r=this.getParent(e);r&&i<t.MAX_DEPTH;)i++,r=this.getParent(r);return n.depth=i,i},n.isActiveInHierarchy=function(e){if(!e.active)return!1;var t=e.getComponent(exports.HierarchyComponent);if(!t)return e.active;if(!t.bCacheDirty)return t.bActiveInHierarchy;var n=this.getParent(e);return t.bActiveInHierarchy=n?e.active&&this.isActiveInHierarchy(n):e.active,t.bActiveInHierarchy},n.getRootEntities=function(){for(var e,t=[],n=s(this.entities);!(e=n()).done;){var i=e.value,r=i.getComponent(exports.HierarchyComponent);r&&null===r.parentId&&t.push(i)}return t},n.findChild=function(e,t,n){void 0===n&&(n=!1);for(var i,r=this.getChildren(e),o=s(r);!(i=o()).done;){var a=i.value;if(a.name===t)return a}if(n)for(var c,u=s(r);!(c=u()).done;){var l=c.value,h=this.findChild(l,t,!0);if(h)return h}return null},n.findChildrenByTag=function(e,t,n){void 0===n&&(n=!1);for(var i,r=[],o=s(this.getChildren(e));!(i=o()).done;){var a=i.value;0!==(a.tag&t)&&r.push(a),n&&r.push.apply(r,this.findChildrenByTag(a,t,!0))}return r},n.forEachChild=function(e,t,n){void 0===n&&(n=!1);for(var i,r=s(this.getChildren(e));!(i=r()).done;){var o=i.value;t(o),n&&this.forEachChild(o,t,!0)}},n.flattenHierarchy=function(e){for(var t,n=this,i=[],r=function(t,o){var a=n.hasChildren(t),c=e.has(t.id);if(i.push({entity:t,depth:o,bHasChildren:a,bIsExpanded:c}),a&&c)for(var u,l=s(n.getChildren(t));!(u=l()).done;){var h=u.value;r(h,o+1)}},o=s(this.getRootEntities());!(t=o()).done;){var a=t.value;r(a,0)}return i},n.markCacheDirty=function(e){var t=e.getComponent(exports.HierarchyComponent);if(t&&!t.bCacheDirty){t.bCacheDirty=!0,this.dirtyEntities.add(e);for(var n,i=s(t.childIds);!(n=i()).done;){var r,o=n.value,a=null===(r=this.scene)||void 0===r?void 0:r.findEntityById(o);a&&this.markCacheDirty(a)}}},n.updateHierarchyCache=function(e){var t=e.getComponent(exports.HierarchyComponent);t&&(t.depth=this.getDepth(e),t.bActiveInHierarchy=this.isActiveInHierarchy(e),t.bCacheDirty=!1)},n.onAdded=function(e){var t=e.getComponent(exports.HierarchyComponent);t&&t.bCacheDirty&&this.dirtyEntities.add(e)},n.onRemoved=function(e){this.dirtyEntities.delete(e);var t=e.getComponent(exports.HierarchyComponent);if(t){if(null!==t.parentId){var n,i=null===(n=this.scene)||void 0===n?void 0:n.findEntityById(t.parentId);if(i){var r=i.getComponent(exports.HierarchyComponent);if(r){var o=r.childIds.indexOf(e.id);-1!==o&&r.childIds.splice(o,1)}}}for(var a,c=s(t.childIds);!(a=c()).done;){var u,l=a.value,h=null===(u=this.scene)||void 0===u?void 0:u.findEntityById(l);if(h){var d=h.getComponent(exports.HierarchyComponent);d&&(d.parentId=null,this.markCacheDirty(h))}}}},n.dispose=function(){this.dirtyEntities.clear()},o(t,[{key:"updateOrder",get:function(){return-1e3}}])}(Le);He.MAX_DEPTH=32;var We=function(){function e(){}var t=e.prototype;return t.collectEntityData=function(e){if(!e)return this.getEmptyEntityDebugData();var t,n=e.entities;if(!n)return this.getEmptyEntityDebugData();try{t=n.getStats?n.getStats():this.calculateFallbackEntityStats(n)}catch(e){return{totalEntities:0,activeEntities:0,pendingAdd:0,pendingRemove:0,entitiesPerArchetype:[],topEntitiesByComponents:[],entityHierarchy:[],entityDetailsMap:{}}}var i=this.collectArchetypeData(e);return{totalEntities:t.totalEntities,activeEntities:t.activeEntities,pendingAdd:t.pendingAdd||0,pendingRemove:t.pendingRemove||0,entitiesPerArchetype:i.distribution,topEntitiesByComponents:i.topEntities,entityHierarchy:[],entityDetailsMap:{}}},t.getRawEntityList=function(e){if(!e)return[];var t=e.entities;if(null==t||!t.buffer)return[];var n=e.getSystem(He);return t.buffer.map(function(e){var t,i,r,o,s=e.getComponent(exports.HierarchyComponent),a=null!==(t=null==n?void 0:n.isActiveInHierarchy(e))&&void 0!==t?t:e.active,c=null!==(i=null==n?void 0:n.getDepth(e))&&void 0!==i?i:0;return{id:e.id,name:e.name||"Entity_"+e.id,active:!1!==e.active,enabled:!1!==e.enabled,activeInHierarchy:a,componentCount:e.components.length,componentTypes:e.components.map(function(e){return H(e)}),parentId:null!==(r=null==s?void 0:s.parentId)&&void 0!==r?r:null,childIds:null!==(o=null==s?void 0:s.childIds)&&void 0!==o?o:[],depth:c,tag:e.tag||0,updateOrder:e.updateOrder||0}})},t.getEntityDetails=function(e,t){try{var n,i,r;if(!t)return null;var o=t.entities;if(null==o||!o.buffer)return null;var s=o.buffer.find(function(t){return t.id===e});if(!s)return null;var c=t.getSystem(He),u=null==c?void 0:c.getParent(s),l=null!==(n=null==u?void 0:u.name)&&void 0!==n?n:null,h=s.getDebugInfo?s.getDebugInfo():this.buildFallbackEntityInfo(s,t,c),d=this.extractComponentDetails(s.components),f=this.getSceneInfo(t);return a({},h,{scene:f.name,sceneName:f.name,sceneType:f.type,parentName:l,components:d||[],componentCount:(null===(i=s.components)||void 0===i?void 0:i.length)||0,componentTypes:(null===(r=s.components)||void 0===r?void 0:r.map(function(e){return H(e)}))||[]})}catch(e){return{error:"获取实体详情失败: "+(e instanceof Error?e.message:String(e)),scene:"获取失败",components:[],componentCount:0,componentTypes:[]}}},t.getSceneInfo=function(e){var t="当前场景",n="Scene";try{if(e.name&&"string"==typeof e.name&&e.name.trim())t=e.name.trim();else if(e.constructor&&e.constructor.name)t=e.constructor.name,n=e.constructor.name;else if(e._name&&"string"==typeof e._name&&e._name.trim())t=e._name.trim();else{var i,r=null===(i=Object.getPrototypeOf(e))||void 0===i||null===(i=i.constructor)||void 0===i?void 0:i.name;r&&"Object"!==r&&(t=r,n=r)}}catch(e){t="场景名获取失败"}return{name:t,type:n}},t.collectEntityDataWithMemory=function(e){if(!e)return this.getEmptyEntityDebugData();var t,n=e.entities;if(!n)return this.getEmptyEntityDebugData();try{t=n.getStats?n.getStats():this.calculateFallbackEntityStats(n)}catch(e){return{totalEntities:0,activeEntities:0,pendingAdd:0,pendingRemove:0,entitiesPerArchetype:[],topEntitiesByComponents:[],entityHierarchy:[],entityDetailsMap:{}}}var i=this.collectArchetypeDataWithMemory(e);return{totalEntities:t.totalEntities,activeEntities:t.activeEntities,pendingAdd:t.pendingAdd||0,pendingRemove:t.pendingRemove||0,entitiesPerArchetype:i.distribution,topEntitiesByComponents:i.topEntities,entityHierarchy:this.buildEntityHierarchyTree(n,e),entityDetailsMap:this.buildEntityDetailsMap(n,e)}},t.collectArchetypeData=function(e){var t;if(e&&e.archetypeSystem&&"function"==typeof e.archetypeSystem.getAllArchetypes)return this.extractArchetypeStatistics(e.archetypeSystem);var n={entities:(null===(t=e.entities)||void 0===t?void 0:t.buffer)||[]};return{distribution:this.getArchetypeDistributionFast(n),topEntities:this.getTopEntitiesByComponentsFast(n)}},t.getArchetypeDistributionFast=function(e){var t=new Map;return e&&e.entities&&e.entities.forEach(function(e){var n,i=(null===(n=e.components)||void 0===n?void 0:n.map(function(e){return H(e)}))||[],r=i.length>0?i.sort().join(", "):"无组件",o=t.get(r);o?o.count++:t.set(r,{count:1,componentTypes:i})}),Array.from(t.entries()).map(function(e){return{signature:e[0],count:e[1].count,memory:0}}).sort(function(e,t){return t.count-e.count}).slice(0,20)},t.getTopEntitiesByComponentsFast=function(e){return e&&e.entities?e.entities.map(function(e){var t;return{id:e.id.toString(),name:e.name||"Entity_"+e.id,componentCount:(null===(t=e.components)||void 0===t?void 0:t.length)||0,memory:0}}).sort(function(e,t){return t.componentCount-e.componentCount}):[]},t.collectArchetypeDataWithMemory=function(e){var t;if(e&&e.archetypeSystem&&"function"==typeof e.archetypeSystem.getAllArchetypes)return this.extractArchetypeStatisticsWithMemory(e.archetypeSystem);var n={entities:(null===(t=e.entities)||void 0===t?void 0:t.buffer)||[]};return{distribution:this.getArchetypeDistributionWithMemory(n),topEntities:this.getTopEntitiesByComponentsWithMemory(n)}},t.extractArchetypeStatistics=function(e){var t=e.getAllArchetypes(),n=[],i=[];return t.forEach(function(e){var t,r,o=(null===(t=e.componentTypes)||void 0===t?void 0:t.map(function(e){return e.name}).join(","))||"Unknown",s=(null===(r=e.entities)||void 0===r?void 0:r.length)||0;n.push({signature:o,count:s,memory:0}),e.entities&&e.entities.forEach(function(e){var t;i.push({id:e.id.toString(),name:e.name||"Entity_"+e.id,componentCount:(null===(t=e.components)||void 0===t?void 0:t.length)||0,memory:0})})}),n.sort(function(e,t){return t.count-e.count}),i.sort(function(e,t){return t.componentCount-e.componentCount}),{distribution:n,topEntities:i}},t.extractArchetypeStatisticsWithMemory=function(e){var t=this,n=e.getAllArchetypes(),i=[],r=[];return n.forEach(function(e){var n,o,s=(null===(n=e.componentTypes)||void 0===n?void 0:n.map(function(e){return e.name}).join(","))||"Unknown",a=(null===(o=e.entities)||void 0===o?void 0:o.length)||0,c=0;if(e.entities&&e.entities.length>0){for(var u=Math.min(5,e.entities.length),l=0,h=0;h<u;h++)l+=t.estimateEntityMemoryUsage(e.entities[h]);c=l/u*a}i.push({signature:s,count:a,memory:c}),e.entities&&e.entities.forEach(function(e){var n;r.push({id:e.id.toString(),name:e.name||"Entity_"+e.id,componentCount:(null===(n=e.components)||void 0===n?void 0:n.length)||0,memory:t.estimateEntityMemoryUsage(e)})})}),i.sort(function(e,t){return t.count-e.count}),r.sort(function(e,t){return t.componentCount-e.componentCount}),{distribution:i,topEntities:r}},t.getArchetypeDistributionWithMemory=function(e){var t=this,n=new Map;return e&&e.entities&&e.entities.forEach(function(e){var i,r=(null===(i=e.components)||void 0===i?void 0:i.map(function(e){return H(e)}))||[],o=r.length>0?r.sort().join(", "):"无组件",s=n.get(o),a=t.estimateEntityMemoryUsage(e);(isNaN(a)||a<0)&&(a=0),s?(s.count++,s.memory+=a):n.set(o,{count:1,memory:a,componentTypes:r})}),Array.from(n.entries()).map(function(e){var t=e[0],n=e[1];return{signature:t,count:n.count,memory:isNaN(n.memory)?0:n.memory}}).sort(function(e,t){return t.count-e.count})},t.getTopEntitiesByComponentsWithMemory=function(e){var t=this;return e&&e.entities?e.entities.map(function(e){var n;return{id:e.id.toString(),name:e.name||"Entity_"+e.id,componentCount:(null===(n=e.components)||void 0===n?void 0:n.length)||0,memory:t.estimateEntityMemoryUsage(e)}}).sort(function(e,t){return t.componentCount-e.componentCount}):[]},t.getEmptyEntityDebugData=function(){return{totalEntities:0,activeEntities:0,pendingAdd:0,pendingRemove:0,entitiesPerArchetype:[],topEntitiesByComponents:[],entityHierarchy:[],entityDetailsMap:{}}},t.calculateFallbackEntityStats=function(e){var t=e.buffer||[],n=t.filter(function(e){return e.enabled&&!e.isDestroyed});return{totalEntities:t.length,activeEntities:n.length,pendingAdd:0,pendingRemove:0,averageComponentsPerEntity:n.length>0?t.reduce(function(e,t){var n;return e+((null===(n=t.components)||void 0===n?void 0:n.length)||0)},0)/n.length:0}},t.estimateEntityMemoryUsage=function(e){var t=this;try{var n=0,i=this.calculateObjectSize(e,["components","children","parent"]);return!isNaN(i)&&i>0&&(n+=i),e.components&&Array.isArray(e.components)&&e.components.forEach(function(e){var i=t.calculateObjectSize(e,["entity"]);!isNaN(i)&&i>0&&(n+=i)}),isNaN(n)||n<0?0:n}catch(e){return 0}},t.calculateObjectSize=function(e,t){if(void 0===t&&(t=[]),!e||"object"!=typeof e)return 0;var n=new WeakSet,i=function(e,r){if(void 0===r&&(r=0),!e||"object"!=typeof e||r>=2)return 0;if(n.has(e))return 0;n.add(e);var o=32;try{for(var s=Object.keys(e),a=Math.min(s.length,20),c=0;c<a;c++){var u=s[c];if(u&&!t.includes(u)&&"constructor"!==u&&"__proto__"!==u&&!u.startsWith("_cc_")&&!u.startsWith("__")){var l=e[u];o+=2*u.length,"string"==typeof l?o+=Math.min(2*l.length,200):"number"==typeof l?o+=8:"boolean"==typeof l?o+=4:Array.isArray(l)?o+=40+Math.min(8*l.length,160):"object"==typeof l&&null!==l&&(o+=i(l,r+1))}}}catch(e){return 64}return o};try{var r=i(e);return Math.max(r,32)}catch(e){return 64}},t.buildEntityHierarchyTree=function(e,t){var n=this;if(null==e||!e.buffer)return[];var i=null==t?void 0:t.getSystem(He),r=[];return e.buffer.forEach(function(e){var t=e.getComponent(exports.HierarchyComponent);if(null===(null==t?void 0:t.parentId)||void 0===(null==t?void 0:t.parentId)){var o=n.buildEntityHierarchyNode(e,i);r.push(o)}}),r.sort(function(e,t){return e.name<t.name?-1:e.name>t.name?1:e.id-t.id}),r},t.buildEntityHierarchyNode=function(e,t){var n,i,r,o=this,s=e.getComponent(exports.HierarchyComponent),c=null!==(n=null==t?void 0:t.isActiveInHierarchy(e))&&void 0!==n?n:e.active,u=null!==(i=null==t?void 0:t.getDepth(e))&&void 0!==i?i:0,l={id:e.id,name:e.name||"Entity_"+e.id,active:!1!==e.active,enabled:!1!==e.enabled,activeInHierarchy:c,componentCount:e.components.length,componentTypes:e.components.map(function(e){return H(e)}),parentId:null!==(r=null==s?void 0:s.parentId)&&void 0!==r?r:null,children:[],depth:u,tag:e.tag||0,updateOrder:e.updateOrder||0};if(t){var h=t.getChildren(e);h.length>0&&(l.children=h.map(function(e){return o.buildEntityHierarchyNode(e,t)}))}"function"==typeof e.getDebugInfo&&(l=a({},l,e.getDebugInfo()));return e.components&&e.components.length>0&&(l.componentDetails=this.extractComponentDetails(e.components)),l},t.buildEntityDetailsMap=function(e,t){var n=this;if(null==e||!e.buffer)return{};for(var i=null==t?void 0:t.getSystem(He),r={},o=e.buffer,s=0;s<o.length;s+=100){o.slice(s,s+100).forEach(function(e){var o,s=e.getDebugInfo?e.getDebugInfo():n.buildFallbackEntityInfo(e,t,i),c=e.getComponentCacheStats?e.getComponentCacheStats():null,u=n.extractComponentDetails(e.components),l=null==i?void 0:i.getParent(e),h=null!==(o=null==l?void 0:l.name)&&void 0!==o?o:null;r[e.id]=a({},s,{parentName:h,components:u,componentTypes:s.componentTypes||u.map(function(e){return e.typeName}),cachePerformance:c?{hitRate:c.cacheStats.hitRate,size:c.cacheStats.size,maxSize:c.cacheStats.maxSize}:null})})}return r},t.buildFallbackEntityInfo=function(e,t,n){var i,r,o,s,a,c,u,l=this.getSceneInfo(t),h=e.getComponent(exports.HierarchyComponent),d=null!==(i=null==n?void 0:n.isActiveInHierarchy(e))&&void 0!==i?i:e.active,f=null!==(r=null==n?void 0:n.getDepth(e))&&void 0!==r?r:0;return{name:e.name||"Entity_"+e.id,id:e.id,enabled:!1!==e.enabled,active:!1!==e.active,activeInHierarchy:d,destroyed:e.isDestroyed||!1,scene:l.name,sceneName:l.name,sceneType:l.type,componentCount:e.components.length,componentTypes:e.components.map(function(e){return H(e)}),componentMask:(null===(o=e.componentMask)||void 0===o?void 0:o.toString())||"0",parentId:null!==(s=null==h?void 0:h.parentId)&&void 0!==s?s:null,childCount:null!==(a=null==h||null===(c=h.childIds)||void 0===c?void 0:c.length)&&void 0!==a?a:0,childIds:null!==(u=null==h?void 0:h.childIds)&&void 0!==u?u:[],depth:f,tag:e.tag||0,updateOrder:e.updateOrder||0}},t.extractComponentDetails=function(e){var t=this;return e.map(function(e){var n=H(e),i={};try{Object.keys(e).forEach(function(n){if(!n.startsWith("_")&&"entity"!==n&&"constructor"!==n){var r=e[n];null!=r&&(i[n]=t.formatPropertyValue(r))}}),0===Object.keys(i).length&&(i._info="该组件没有公开属性",i._componentId=H(e))}catch(t){i._error="属性提取失败",i._componentId=H(e)}return{typeName:n,properties:i}})},t.getComponentProperties=function(e,t,n){var i=this;try{if(!n)return{};var r=n.entities;if(null==r||!r.buffer)return{};var o=r.buffer.find(function(t){return t.id===e});if(!o||t>=o.components.length)return{};var s=o.components[t];if(!s)return{};var a={};return Object.keys(s).forEach(function(e){if(!e.startsWith("_")&&"entity"!==e){var t=s[e];null!=t&&(a[e]=i.formatPropertyValue(t))}}),a}catch(e){return{_error:"属性提取失败"}}},t.formatPropertyValue=function(e,t){return void 0===t&&(t=0),null==e?e:"object"!=typeof e?"string"==typeof e&&e.length>200?"[长字符串: "+e.length+"字符] "+e.substring(0,100)+"...":e:0===t?this.formatObjectFirstLevel(e):this.createLazyLoadPlaceholder(e)},t.formatObjectFirstLevel=function(e){var t=this;try{if(Array.isArray(e)){if(0===e.length)return[];if(e.length>10){var n=e.slice(0,3).map(function(e){return t.formatPropertyValue(e,1)});return{_isLazyArray:!0,_arrayLength:e.length,_sample:n,_summary:"数组["+e.length+"个元素]"}}return e.map(function(e){return t.formatPropertyValue(e,1)})}var i=Object.keys(e);if(0===i.length)return{};for(var r={},o=0,s=0,a=i;s<a.length;s++){var c=a[s];if(o>=15){r._hasMoreProperties=!0,r._totalProperties=i.length,r._hiddenCount=i.length-o;break}if(!c.startsWith("_")&&!c.startsWith("$")&&"function"!=typeof e[c])try{var u=e[c];null!=u&&(r[c]=this.formatPropertyValue(u,1),o++)}catch(e){r[c]="[访问失败: "+(e instanceof Error?e.message:String(e))+"]",o++}}return r}catch(e){return"[对象解析失败: "+(e instanceof Error?e.message:String(e))+"]"}},t.createLazyLoadPlaceholder=function(e){try{var t,n=(null===(t=e.constructor)||void 0===t?void 0:t.name)||"Object";return{_isLazyObject:!0,_typeName:n,_summary:this.getObjectSummary(e,n),_objectId:this.generateObjectId(e)}}catch(e){return{_isLazyObject:!0,_typeName:"Unknown",_summary:"无法分析的对象: "+(e instanceof Error?e.message:String(e)),_objectId:Math.random().toString(36).substr(2,9)}}},t.getObjectSummary=function(e,t){try{if((t.toLowerCase().includes("vec")||t.toLowerCase().includes("vector"))&&void 0!==e.x&&void 0!==e.y){var n=void 0!==e.z?e.z:"";return t+"("+e.x+", "+e.y+(n?", "+n:"")+")"}if(t.toLowerCase().includes("color")&&void 0!==e.r&&void 0!==e.g&&void 0!==e.b){var i=void 0!==e.a?e.a:1;return t+"("+e.r+", "+e.g+", "+e.b+", "+i+")"}if(t.toLowerCase().includes("node"))return t+": "+(e.name||e._name||"未命名");if(t.toLowerCase().includes("component")){var r,o,s=(null===(r=e.node)||void 0===r?void 0:r.name)||(null===(o=e.node)||void 0===o?void 0:o._name)||"";return t+(s?" on "+s:"")}var a=Object.keys(e);return 0===a.length?t+" (空对象)":t+" ("+a.length+"个属性)"}catch(e){return t+" (无法分析)"}},t.generateObjectId=function(e){try{return void 0!==e.id?"obj_"+e.id:void 0!==e._id?"obj_"+e._id:void 0!==e.uuid?"obj_"+e.uuid:void 0!==e._uuid?"obj_"+e._uuid:"obj_"+Math.random().toString(36).substr(2,9)}catch(e){return"obj_"+Math.random().toString(36).substr(2,9)}},t.expandLazyObject=function(e,t,n,i){try{if(!i)return null;var r=i.entities;if(null==r||!r.buffer)return null;var o=r.buffer.find(function(t){return t.id===e});if(!o)return null;if(t>=o.components.length)return null;var s=o.components[t],a=this.getObjectByPath(s,n);return a?this.formatObjectFirstLevel(a):null}catch(e){return{error:"展开失败: "+(e instanceof Error?e.message:String(e))}}},t.getObjectByPath=function(e,t){if(!t)return e;for(var n,i=e,r=s(t.split("."));!(n=r()).done;){var o=n.value;if(null==i)return null;if(o.includes("[")&&o.includes("]")){var a=o.substring(0,o.indexOf("[")),c=parseInt(o.substring(o.indexOf("[")+1,o.indexOf("]")));if(a&&(i=i[a]),!(Array.isArray(i)&&c>=0&&c<i.length))return null;i=i[c]}else i=i[o]}return i},e}(),Ge=function(){function e(){}return e.prototype.collectSystemData=function(e,t){if(!t)return{totalSystems:0,systemsInfo:[]};var n=t.systems||[],i=new Map,r=new Map;if(e)try{i=e.getAllSystemStats(),r=e.getAllSystemData()}catch(e){}return{totalSystems:n.length,systemsInfo:n.map(function(e){var t,n=e.systemName||re(e),o=i.get(n),s=r.get(n);return{name:n,type:re(e),entityCount:(null===(t=e.entities)||void 0===t?void 0:t.length)||0,executionTime:(null==o?void 0:o.averageTime)||(null==s?void 0:s.executionTime)||0,minExecutionTime:(null==o?void 0:o.minTime)===Number.MAX_VALUE?0:(null==o?void 0:o.minTime)||0,maxExecutionTime:(null==o?void 0:o.maxTime)||0,executionTimeHistory:(null==o?void 0:o.recentTimes)||[],updateOrder:e.updateOrder||0,enabled:!1!==e.enabled,lastUpdateTime:(null==s?void 0:s.lastUpdateTime)||0}})}},e}(),je=function(){function e(){this.frameTimeHistory=[],this.maxHistoryLength=60,this.gcCollections=0,this.lastMemoryCheck=0}var t=e.prototype;return t.collectPerformanceData=function(e){var t=y.deltaTime,n=1e3*t,i=t>0?Math.round(1/t):0,r=this.getECSPerformanceData(e),o=r.totalExecutionTime,s=n>0?o/n*100:0,a=0;performance.memory&&(a=performance.memory.usedJSHeapSize/1024/1024),this.frameTimeHistory.push(o),this.frameTimeHistory.length>this.maxHistoryLength&&this.frameTimeHistory.shift();var c=this.frameTimeHistory.filter(function(e){return e>=0});return{frameTime:o,engineFrameTime:n,ecsPercentage:s,memoryUsage:a,fps:i,averageFrameTime:c.length>0?c.reduce(function(e,t){return e+t},0)/c.length:o,minFrameTime:c.length>0?Math.min.apply(Math,c):o,maxFrameTime:c.length>0?Math.max.apply(Math,c):o,frameTimeHistory:[].concat(this.frameTimeHistory),systemPerformance:this.getSystemPerformance(e),systemBreakdown:r.systemBreakdown,memoryDetails:this.getMemoryDetails()}},t.getECSPerformanceData=function(e){if(!e)return{totalExecutionTime:0,systemBreakdown:[]};if(!e.enabled){try{e.enabled=!0}catch(e){}return{totalExecutionTime:0,systemBreakdown:[]}}try{var t=0,n=[],i=e.getAllSystemStats();if(0===i.size)return{totalExecutionTime:0,systemBreakdown:[]};for(var r,o=s(i.entries());!(r=o()).done;){var a=r.value,c=a[0],u=a[1],l=u.recentTimes&&u.recentTimes.length>0?u.recentTimes[u.recentTimes.length-1]:u.averageTime||0;t+=l,n.push({systemName:c,executionTime:l,percentage:0})}return n.forEach(function(e){e.percentage=t>0?e.executionTime/t*100:0}),n.sort(function(e,t){return t.executionTime-e.executionTime}),{totalExecutionTime:t,systemBreakdown:n}}catch(e){return{totalExecutionTime:0,systemBreakdown:[]}}},t.getSystemPerformance=function(e){if(!e)return[];try{var t=e.getAllSystemStats(),n=e.getAllSystemData();return Array.from(t.entries()).map(function(e){var t=e[0],i=e[1],r=n.get(t);return{systemName:t,averageTime:i.averageTime||0,maxTime:i.maxTime||0,minTime:i.minTime===Number.MAX_VALUE?0:i.minTime||0,samples:i.executionCount||0,percentage:0,entityCount:(null==r?void 0:r.entityCount)||0,lastExecutionTime:(null==r?void 0:r.executionTime)||0}})}catch(e){return[]}},t.getMemoryDetails=function(){var e={entities:0,components:0,systems:0,pooled:0,totalMemory:0,usedMemory:0,freeMemory:0,gcCollections:this.updateGCCount()};try{if(performance.memory){var t=performance.memory;if(e.totalMemory=t.jsHeapSizeLimit||536870912,e.usedMemory=t.usedJSHeapSize||0,e.freeMemory=e.totalMemory-e.usedMemory,this.lastMemoryCheck>0)this.lastMemoryCheck-e.usedMemory>1048576&&this.gcCollections++;this.lastMemoryCheck=e.usedMemory}else e.totalMemory=536870912,e.freeMemory=536870912}catch(e){return{totalMemory:0,usedMemory:0,freeMemory:0,entityMemory:0,componentMemory:0,systemMemory:0,pooledMemory:0,gcCollections:this.gcCollections}}return e},t.updateGCCount=function(){try{return"undefined"!=typeof PerformanceObserver||performance.measureUserAgentSpecificMemory,this.gcCollections}catch(e){return this.gcCollections}},e}(),Ue=function(){function e(e,t,n,i){void 0===n&&(n=1e3),void 0===i&&(i=10),this.pool=[],this.stats={totalCreated:0,totalAcquired:0,totalReleased:0},this.createFn=e,t&&(this.resetFn=t),this.maxSize=n,this.minSize=Math.max(1,i)}var t=e.prototype;return t.acquire=function(){return this.stats.totalAcquired++,this.pool.length>0?this.pool.pop():(this.stats.totalCreated++,this.createFn())},t.release=function(e){this.stats.totalReleased++,this.pool.length>=this.maxSize||(this.resetFn&&this.resetFn(e),this.pool.push(e))},t.prewarm=function(e){for(var t=Math.min(e,this.maxSize),n=this.pool.length;n<t;n++){var i=this.createFn();this.resetFn&&this.resetFn(i),this.pool.push(i),this.stats.totalCreated++}},t.shrink=function(){for(;this.pool.length>this.minSize;)this.pool.pop()},t.clear=function(){this.pool.length=0},t.getAvailableCount=function(){return this.pool.length},t.getMaxSize=function(){return this.maxSize},t.getStats=function(){var e=0===this.stats.totalAcquired?0:(this.stats.totalAcquired-this.stats.totalCreated)/this.stats.totalAcquired;return{totalCreated:this.stats.totalCreated,totalAcquired:this.stats.totalAcquired,totalReleased:this.stats.totalReleased,hitRate:e,currentSize:this.pool.length,maxSize:this.maxSize,minSize:this.minSize,utilizationRate:this.pool.length/this.maxSize}},e}(),qe=function(){function e(){this.pools=new Map,this.usageTracker=new Map,this.autoCleanupInterval=6e4,this.lastCleanupTime=0}e.getInstance=function(){return e.instance||(e.instance=new e),e.instance};var t=e.prototype;return t.registerPool=function(e,t,n,i,r){this.pools.set(e,new Ue(t,n,i,r)),this.usageTracker.set(e,{createCount:0,releaseCount:0,lastAccessTime:Date.now()})},t.acquireComponent=function(e){var t=this.pools.get(e);return this.trackUsage(e,"create"),t?t.acquire():null},t.releaseComponent=function(e,t){var n=this.pools.get(e);this.trackUsage(e,"release"),n&&n.release(t)},t.trackUsage=function(e,t){var n=this.usageTracker.get(e);n||(n={createCount:0,releaseCount:0,lastAccessTime:Date.now()},this.usageTracker.set(e,n)),"create"===t?n.createCount++:n.releaseCount++,n.lastAccessTime=Date.now()},t.update=function(){var e=Date.now();if(!(e-this.lastCleanupTime<this.autoCleanupInterval)){for(var t,n=s(this.usageTracker.entries());!(t=n()).done;){var i=t.value,r=i[0];if(e-i[1].lastAccessTime>12e4){var o=this.pools.get(r);o&&o.shrink()}}this.lastCleanupTime=e}},t.getHotComponents=function(e){return void 0===e&&(e=100),Array.from(this.usageTracker.entries()).filter(function(t){return t[0],t[1].createCount>e}).map(function(e){return e[0]})},t.prewarmAll=function(e){void 0===e&&(e=100);for(var t,n=s(this.pools.values());!(t=n()).done;){t.value.prewarm(e)}},t.clearAll=function(){for(var e,t=s(this.pools.values());!(e=t()).done;){e.value.clear()}},t.reset=function(){this.pools.clear(),this.usageTracker.clear()},t.getGlobalStats=function(){for(var e,t=[],n=s(this.pools.entries());!(e=n()).done;){var i=e.value,r=i[0],o=i[1];t.push({componentName:r,poolStats:o.getStats(),usage:this.usageTracker.get(r)})}return t},t.getPoolStats=function(){for(var e,t=new Map,n=s(this.pools);!(e=n()).done;){var i=e.value,r=i[0],o=i[1];t.set(r,{available:o.getAvailableCount(),maxSize:o.getMaxSize()})}return t},t.getPoolUtilization=function(){for(var e,t=new Map,n=s(this.pools);!(e=n()).done;){var i=e.value,r=i[0],o=i[1],a=o.getAvailableCount(),c=o.getMaxSize(),u=c-a,l=c>0?u/c*100:0;t.set(r,{used:u,total:c,utilization:l})}return t},t.getComponentUtilization=function(e){var t=this.pools.get(e);if(!t)return 0;var n=t.getAvailableCount(),i=t.getMaxSize();return i>0?(i-n)/i*100:0},e}(),Qe=function(){function e(){}var t=e.prototype;return t.collectComponentData=function(e){var t=this;if(!e)return{componentTypes:0,componentInstances:0,componentStats:[]};var n=e.entities;if(null==n||!n.buffer)return{componentTypes:0,componentInstances:0,componentStats:[]};var i=new Map,r=0;n.buffer.forEach(function(e){e.components&&e.components.forEach(function(e){var t=H(e),n=i.get(t)||{count:0,entities:0};n.count++,r++,i.set(t,n)})});var o=new Map,a=new Map;try{for(var c,u=qe.getInstance(),l=u.getPoolStats(),h=u.getPoolUtilization(),d=s(l.entries());!(c=d()).done;){var f=c.value,p=f[0],m=f[1];a.set(p,m.maxSize)}for(var v,g=s(h.entries());!(v=g()).done;){var y=v.value,_=y[0],S=y[1];o.set(_,S.utilization)}}catch(e){}return{componentTypes:i.size,componentInstances:r,componentStats:Array.from(i.entries()).map(function(i){var r=i[0],s=i[1],c=a.get(r)||0,u=o.get(r)||0,l=t.getEstimatedComponentSize(r,e);return{typeName:r,instanceCount:s.count,memoryPerInstance:l,totalMemory:s.count*l,poolSize:c,poolUtilization:u,averagePerEntity:s.count/n.buffer.length}})}},t.getEstimatedComponentSize=function(t,n){if(e.componentSizeCache.has(t))return e.componentSizeCache.get(t);if(!n)return 64;var i=n.entities;if(null==i||!i.buffer)return 64;var r=64;try{for(var o,a=s(i.buffer);!(o=a()).done;){var c=o.value;if(c.components){var u=c.components.find(function(e){return H(e)===t});if(u){r=this.calculateQuickObjectSize(u);break}}}}catch(e){r=64}return e.componentSizeCache.set(t,r),r},t.calculateQuickObjectSize=function(e){if(!e||"object"!=typeof e)return 8;var t=32,n=new WeakSet,i=function(e,t){if(void 0===t&&(t=0),!e||"object"!=typeof e||n.has(e)||t>3)return 0;n.add(e);var r=0;try{for(var o=Object.keys(e),s=0;s<Math.min(o.length,20);s++){var a=o[s];if(a&&"entity"!==a&&"_entity"!==a&&"constructor"!==a){var c=e[a];r+=2*a.length,"string"==typeof c?r+=Math.min(2*c.length,200):"number"==typeof c?r+=8:"boolean"==typeof c?r+=4:"object"==typeof c&&null!==c&&(r+=i(c,t+1))}}}catch(e){return 32}return r};return t+=i(e),Math.max(t,32)},t.calculateDetailedComponentMemory=function(e,t){if(!t)return this.getEstimatedComponentSize(e,t);var n=t.entities;if(null==n||!n.buffer)return this.getEstimatedComponentSize(e,t);try{for(var i,r=s(n.buffer);!(i=r()).done;){var o=i.value;if(o.components){var a=o.components.find(function(t){return H(t)===e});if(a)return this.estimateObjectSize(a)}}}catch(e){}return this.getEstimatedComponentSize(e,t)},t.estimateObjectSize=function(e,t,n){if(void 0===t&&(t=new WeakSet),void 0===n&&(n=0),null==e||n>10)return 0;if(t.has(e))return 0;var i=0;switch(typeof e){case"boolean":i=4;break;case"number":default:i=8;break;case"string":i=24+Math.min(2*e.length,1e3);break;case"object":if(t.add(e),Array.isArray(e)){i=40+8*e.length;for(var r=Math.min(e.length,50),o=0;o<r;o++)i+=this.estimateObjectSize(e[o],t,n+1)}else{i=32;try{for(var s=Object.getOwnPropertyNames(e),a=Math.min(s.length,30),c=0;c<a;c++){var u=s[c];if(u&&("constructor"!==u&&"__proto__"!==u&&"entity"!==u&&"_entity"!==u&&!u.startsWith("_cc_")&&!u.startsWith("__")))try{i+=16+2*u.length;var l=e[u];null!=l&&(i+=this.estimateObjectSize(l,t,n+1))}catch(e){continue}}}catch(e){i=128}}}return 8*Math.ceil(i/8)},e.clearCache=function(){e.componentSizeCache.clear()},e}();Qe.componentSizeCache=new Map;var Ve,Ye=function(){function e(){this.sceneStartTime=Date.now()}var t=e.prototype;return t.collectSceneData=function(e){if(!e)return{currentSceneName:"No Scene",isInitialized:!1,sceneRunTime:0,sceneEntityCount:0,sceneSystemCount:0,sceneUptime:0};var t=(Date.now()-this.sceneStartTime)/1e3,n=e.getStats();return{currentSceneName:e.name||"Unnamed Scene",isInitialized:!0,sceneRunTime:t,sceneEntityCount:n.entityCount,sceneSystemCount:n.processorCount,sceneUptime:t}},t.setSceneStartTime=function(e){this.sceneStartTime=e},e}(),Je=function(){function e(e,t){void 0===t&&(t=!0),this.isConnected=!1,this.reconnectAttempts=0,this.maxReconnectAttempts=5,this.url=e,this.autoReconnect=t}var t=e.prototype;return t.setMessageHandler=function(e){this.messageHandler=e},t.connect=function(){var e=this;return new Promise(function(t,n){try{e.ws=new WebSocket(e.url),e.ws.onopen=function(n){e.handleOpen(n),t()},e.ws.onclose=function(t){e.handleClose(t)},e.ws.onerror=function(t){e.handleError(t),n(t)},e.ws.onmessage=function(t){e.handleMessage(t)}}catch(t){e.handleConnectionFailure(t),n(t)}})},t.disconnect=function(){this.ws&&(this.autoReconnect=!1,this.ws.close(),delete this.ws),this.isConnected=!1},t.send=function(e){if(this.isConnected&&this.ws)try{var t="string"==typeof e?e:JSON.stringify(e);this.ws.send(t)}catch(e){}},t.getConnectionStatus=function(){return this.isConnected},t.setMaxReconnectAttempts=function(e){this.maxReconnectAttempts=e},t.scheduleReconnect=function(){var e=this;this.reconnectTimer&&clearTimeout(this.reconnectTimer);var t=Math.min(1e3*Math.pow(2,this.reconnectAttempts),3e4);this.reconnectAttempts++,this.reconnectTimer=setTimeout(function(){e.connect().catch(function(t){e.reconnectAttempts<e.maxReconnectAttempts&&e.scheduleReconnect()})},t)},t.handleMessage=function(e){try{var t=JSON.parse(e.data);this.messageHandler&&this.messageHandler(t)}catch(e){}},t.handleOpen=function(e){this.isConnected=!0,this.reconnectAttempts=0,this.onOpen&&this.onOpen(e)},t.handleClose=function(e){this.isConnected=!1,this.onClose&&this.onClose(e),this.autoReconnect&&this.reconnectAttempts<this.maxReconnectAttempts&&this.scheduleReconnect()},t.handleError=function(e){this.onError&&this.onError(e)},t.handleConnectionFailure=function(e){this.onError&&this.onError(e)},e}();exports.ProfileCategory=void 0,(Ve=exports.ProfileCategory||(exports.ProfileCategory={})).ECS="ECS",Ve.Rendering="Rendering",Ve.Physics="Physics",Ve.Audio="Audio",Ve.Network="Network",Ve.Script="Script",Ve.Memory="Memory",Ve.Animation="Animation",Ve.AI="AI",Ve.Input="Input",Ve.Loading="Loading",Ve.Custom="Custom";var Ze={enabled:!1,maxFrameHistory:300,maxSampleDepth:32,collectMemory:!0,memorySampleInterval:100,detectLongTasks:!0,longTaskThreshold:50,enabledCategories:new Set(Object.values(exports.ProfileCategory))},Xe=0;var Ke=function(){function e(e){this.currentFrame=null,this.frameHistory=[],this.frameNumber=0,this.activeSamples=new Map,this.sampleStack=[],this.counters=new Map,this.callGraph=new Map,this.gcCount=0,this.previousHeapSize=0,this.longTasks=[],this.performanceObserver=null,this.config=a({},Ze,e),this.config.detectLongTasks&&this.setupLongTaskObserver()}e.getInstance=function(t){return e.instance||(e.instance=new e(t)),e.instance},e.resetInstance=function(){e.instance&&(e.instance.dispose(),e.instance=null)},e.beginSample=function(t,n){return void 0===n&&(n=exports.ProfileCategory.Custom),e.getInstance().beginSample(t,n)},e.endSample=function(t){t&&e.getInstance().endSample(t)},e.measure=function(t,n,i){return void 0===i&&(i=exports.ProfileCategory.Custom),e.getInstance().measure(t,n,i)},e.measureAsync=function(){var t=n(h().m(function t(n,i,r){return h().w(function(t){for(;;)if(0===t.n)return void 0===r&&(r=exports.ProfileCategory.Custom),t.a(2,e.getInstance().measureAsync(n,i,r))},t)}));return function(e,n,i){return t.apply(this,arguments)}}(),e.beginFrame=function(){e.getInstance().beginFrame()},e.endFrame=function(){e.getInstance().endFrame()},e.incrementCounter=function(t,n,i){void 0===n&&(n=1),void 0===i&&(i=exports.ProfileCategory.Custom),e.getInstance().incrementCounter(t,n,i)},e.setGauge=function(t,n,i){void 0===i&&(i=exports.ProfileCategory.Custom),e.getInstance().setGauge(t,n,i)},e.setEnabled=function(t){e.getInstance().setEnabled(t)},e.isEnabled=function(){return e.getInstance().config.enabled},e.getCurrentFrame=function(){return e.getInstance().currentFrame},e.getFrameHistory=function(){return e.getInstance().frameHistory},e.getReport=function(t){return e.getInstance().generateReport(t)},e.reset=function(){e.getInstance().reset()};var t=e.prototype;return t.beginSample=function(e,t){if(void 0===t&&(t=exports.ProfileCategory.Custom),!this.config.enabled||!this.config.enabledCategories.has(t))return null;var n=this.sampleStack.length>0?this.sampleStack[this.sampleStack.length-1]:void 0;if(n&&this.sampleStack.length>=this.config.maxSampleDepth)return null;var i={id:"sample_"+ ++Xe+"_"+Date.now(),name:e,category:t,startTime:performance.now(),depth:this.sampleStack.length,parentId:null==n?void 0:n.id};return this.activeSamples.set(i.id,i),this.sampleStack.push(i),i},t.endSample=function(e){if(this.config.enabled&&this.activeSamples.has(e.id)){var t=performance.now(),n=t-e.startTime,i=e.parentId?this.activeSamples.get(e.parentId):void 0,r={id:e.id,name:e.name,category:e.category,startTime:e.startTime,endTime:t,duration:n,selfTime:n,parentId:e.parentId,parentName:null==i?void 0:i.name,depth:e.depth,callCount:1};this.currentFrame&&this.currentFrame.samples.push(r),this.updateCallGraph(e.name,e.category,n,i),this.activeSamples.delete(e.id);var o=this.sampleStack.indexOf(e);-1!==o&&this.sampleStack.splice(o,1)}},t.measure=function(e,t,n){void 0===n&&(n=exports.ProfileCategory.Custom);var i=this.beginSample(e,n);try{return t()}finally{i&&this.endSample(i)}},t.measureAsync=function(){var e=n(h().m(function e(t,n,i){var r;return h().w(function(e){for(;;)switch(e.p=e.n){case 0:return void 0===i&&(i=exports.ProfileCategory.Custom),r=this.beginSample(t,i),e.p=1,e.n=2,n();case 2:return e.a(2,e.v);case 3:return e.p=3,r&&this.endSample(r),e.f(3);case 4:return e.a(2)}},e,this,[[1,,3,4]])}));return function(t,n,i){return e.apply(this,arguments)}}(),t.beginFrame=function(){this.config.enabled&&(this.frameNumber++,this.currentFrame={frameNumber:this.frameNumber,startTime:performance.now(),endTime:0,duration:0,samples:[],sampleStats:[],counters:new Map(this.counters),memory:this.captureMemory(),categoryStats:new Map},this.resetFrameCounters())},t.endFrame=function(){if(this.config.enabled&&this.currentFrame){for(this.currentFrame.endTime=performance.now(),this.currentFrame.duration=this.currentFrame.endTime-this.currentFrame.startTime,this.calculateSampleStats(),this.calculateCategoryStats(),this.frameHistory.push(this.currentFrame);this.frameHistory.length>this.config.maxFrameHistory;)this.frameHistory.shift();this.sampleStack=[],this.activeSamples.clear()}},t.incrementCounter=function(e,t,n){if(void 0===t&&(t=1),void 0===n&&(n=exports.ProfileCategory.Custom),this.config.enabled){var i=this.counters.get(e);i||(i={name:e,category:n,value:0,type:"counter",history:[]},this.counters.set(e,i)),i.value+=t,i.history.push({time:performance.now(),value:i.value}),i.history.length>100&&i.history.shift()}},t.setGauge=function(e,t,n){if(void 0===n&&(n=exports.ProfileCategory.Custom),this.config.enabled){var i=this.counters.get(e);i||(i={name:e,category:n,value:0,type:"gauge",history:[]},this.counters.set(e,i)),i.value=t,i.history.push({time:performance.now(),value:t}),i.history.length>100&&i.history.shift()}},t.setEnabled=function(e){this.config.enabled=e,e&&this.config.detectLongTasks&&!this.performanceObserver&&this.setupLongTaskObserver()},t.reset=function(){this.frameHistory=[],this.currentFrame=null,this.frameNumber=0,this.activeSamples.clear(),this.sampleStack=[],this.counters.clear(),this.callGraph.clear(),this.gcCount=0,this.longTasks=[]},t.generateReport=function(e){var t,n,i=e?this.frameHistory.slice(-e):this.frameHistory;if(0===i.length)return this.createEmptyReport();var r=i.map(function(e){return e.duration}),o=[].concat(r).sort(function(e,t){return e-t}),s=this.aggregateSampleStats(i).sort(function(e,t){return t.inclusiveTime-e.inclusiveTime}).slice(0,20),a=this.aggregateCategoryStats(i),c=this.buildCallGraphFromFrames(i),u=i[0],l=i[i.length-1];return{startTime:null!==(t=null==u?void 0:u.startTime)&&void 0!==t?t:0,endTime:null!==(n=null==l?void 0:l.endTime)&&void 0!==n?n:0,totalFrames:i.length,averageFrameTime:r.reduce(function(e,t){return e+t},0)/r.length,minFrameTime:Math.min.apply(Math,r),maxFrameTime:Math.max.apply(Math,r),p95FrameTime:o[Math.floor(.95*o.length)]||0,p99FrameTime:o[Math.floor(.99*o.length)]||0,hotspots:s,callGraph:c,categoryBreakdown:a,memoryTrend:i.map(function(e){return e.memory}),longTasks:[].concat(this.longTasks)}},t.buildCallGraphFromFrames=function(e){for(var t,n=new Map,i=s(e);!(t=i()).done;)for(var r,o=s(t.value.samples);!(r=o()).done;){var a=r.value,c=n.get(a.name);if(c||(c={category:a.category,callCount:0,totalTime:0,callers:new Map,callees:new Map},n.set(a.name,c)),c.callCount++,c.totalTime+=a.duration,a.parentName){var u=c.callers.get(a.parentName)||{count:0,totalTime:0};u.count++,u.totalTime+=a.duration,c.callers.set(a.parentName,u);var l=n.get(a.parentName);l||(l={category:a.category,callCount:0,totalTime:0,callers:new Map,callees:new Map},n.set(a.parentName,l));var h=l.callees.get(a.name)||{count:0,totalTime:0};h.count++,h.totalTime+=a.duration,l.callees.set(a.name,h)}}for(var d,f=new Map,p=s(n);!(d=p()).done;){for(var m,v=d.value,g=v[0],y=v[1],_=new Map,S=s(y.callers);!(m=S()).done;){var C=m.value,E=C[0],b=C[1];_.set(E,{count:b.count,totalTime:b.count>0?b.totalTime/b.count:0})}for(var T,w=new Map,I=s(y.callees);!(T=I()).done;){var x=T.value,M=x[0],A=x[1];w.set(M,{count:A.count,totalTime:A.count>0?A.totalTime/A.count:0})}f.set(g,{name:g,category:y.category,callCount:y.callCount,totalTime:y.callCount>0?y.totalTime/y.callCount:0,callers:_,callees:w})}return f},t.getCallGraph=function(){return new Map(this.callGraph)},t.getFunctionCallInfo=function(e){var t=this.callGraph.get(e);return t?{callers:Array.from(t.callers.entries()).map(function(e){return a({name:e[0]},e[1])}),callees:Array.from(t.callees.entries()).map(function(e){return a({name:e[0]},e[1])})}:null},t.dispose=function(){this.performanceObserver&&(this.performanceObserver.disconnect(),this.performanceObserver=null),this.reset()},t.captureMemory=function(){var e=performance.now(),t=0,n=0,i=0,r=performance;return r.memory&&(t=r.memory.usedJSHeapSize||0,n=r.memory.totalJSHeapSize||0,i=r.memory.jsHeapSizeLimit||0,this.previousHeapSize>0&&t<this.previousHeapSize-1048576&&this.gcCount++,this.previousHeapSize=t),{timestamp:e,usedHeapSize:t,totalHeapSize:n,heapSizeLimit:i,utilizationPercent:i>0?t/i*100:0,gcCount:this.gcCount}},t.resetFrameCounters=function(){for(var e,t=s(this.counters.values());!(e=t()).done;){var n=e.value;"counter"===n.type&&(n.value=0)}},t.calculateSampleStats=function(){var e=this;if(this.currentFrame){for(var t,n=new Map,i=s(this.currentFrame.samples);!(t=i()).done;){var r=t.value,o=n.get(r.name);o||(o={name:r.name,category:r.category,inclusiveTime:0,exclusiveTime:0,callCount:0,averageTime:0,minTime:Number.MAX_VALUE,maxTime:0,percentOfFrame:0,percentOfParent:0,children:[],depth:r.depth},n.set(r.name,o)),o.inclusiveTime+=r.duration,o.callCount+=1,o.minTime=Math.min(o.minTime,r.duration),o.maxTime=Math.max(o.maxTime,r.duration)}for(var a,c=function(){var t=a.value;if(t.parentId){var i=e.currentFrame.samples.find(function(e){return e.id===t.parentId});if(i){var r=n.get(i.name);if(r){r.exclusiveTime=r.inclusiveTime;for(var o,c=s(e.currentFrame.samples);!(o=c()).done;){var u=o.value;u.parentId===i.id&&(r.exclusiveTime-=u.duration)}}}}},u=s(this.currentFrame.samples);!(a=u()).done;)c();for(var l,h=this.currentFrame.duration||1,d=s(n.values());!(l=d()).done;){var f=l.value;f.averageTime=f.inclusiveTime/f.callCount,f.percentOfFrame=f.inclusiveTime/h*100,0===f.exclusiveTime&&(f.exclusiveTime=f.inclusiveTime)}this.currentFrame.sampleStats=Array.from(n.values()).sort(function(e,t){return t.inclusiveTime-e.inclusiveTime})}},t.calculateCategoryStats=function(){if(this.currentFrame){for(var e,t=new Map,n=s(this.currentFrame.samples);!(e=n()).done;){var i=e.value;if(0===i.depth){var r=t.get(i.category);r||(r={totalTime:0,sampleCount:0},t.set(i.category,r)),r.totalTime+=i.duration,r.sampleCount+=1}}for(var o,c=this.currentFrame.duration||1,u=s(t);!(o=u()).done;){var l=o.value,h=l[0],d=l[1];this.currentFrame.categoryStats.set(h,a({},d,{percentOfFrame:d.totalTime/c*100}))}}},t.updateCallGraph=function(e,t,n,i){var r=this.callGraph.get(e);if(r||(r={name:e,category:t,callCount:0,totalTime:0,callers:new Map,callees:new Map},this.callGraph.set(e,r)),r.callCount++,r.totalTime+=n,i){var o=r.callers.get(i.name)||{count:0,totalTime:0};o.count++,o.totalTime+=n,r.callers.set(i.name,o);var s=this.callGraph.get(i.name);s||(s={name:i.name,category:i.category,callCount:0,totalTime:0,callers:new Map,callees:new Map},this.callGraph.set(i.name,s));var a=s.callees.get(e)||{count:0,totalTime:0};a.count++,a.totalTime+=n,s.callees.set(e,a)}},t.aggregateSampleStats=function(e){for(var t,n=new Map,i=s(e);!(t=i()).done;)for(var r,o=s(t.value.sampleStats);!(r=o()).done;){var c=r.value,u=n.get(c.name);u?(u.inclusiveTime+=c.inclusiveTime,u.exclusiveTime+=c.exclusiveTime,u.callCount+=c.callCount,u.minTime=Math.min(u.minTime,c.minTime),u.maxTime=Math.max(u.maxTime,c.maxTime)):(u=a({},c,{minTime:Number.MAX_VALUE}),n.set(c.name,u))}for(var l,h=e.reduce(function(e,t){return e+t.duration},0),d=s(n.values());!(l=d()).done;){var f=l.value;f.averageTime=f.inclusiveTime/f.callCount,f.percentOfFrame=f.inclusiveTime/h*100}return Array.from(n.values())},t.aggregateCategoryStats=function(e){for(var t,n=new Map,i=s(e);!(t=i()).done;)for(var r,o=s(t.value.categoryStats);!(r=o()).done;){var a=r.value,c=a[0],u=a[1],l=n.get(c);l||(l={totalTime:0,frameCount:0},n.set(c,l)),l.totalTime+=u.totalTime,l.frameCount++}for(var h,d=e.reduce(function(e,t){return e+t.duration},0),f=new Map,p=s(n);!(h=p()).done;){var m=h.value,v=m[0],g=m[1];f.set(v,{totalTime:g.totalTime,averageTime:g.frameCount>0?g.totalTime/g.frameCount:0,percentOfTotal:d>0?g.totalTime/d*100:0})}return f},t.setupLongTaskObserver=function(){var e=this;if("undefined"!=typeof PerformanceObserver)try{this.performanceObserver=new PerformanceObserver(function(t){for(var n,i=s(t.getEntries());!(n=i()).done;){var r,o=n.value;if(o.duration>e.config.longTaskThreshold)e.longTasks.push({startTime:o.startTime,duration:o.duration,attribution:(null===(r=o.attribution)||void 0===r?void 0:r.map(function(e){return e.name}))||[]}),e.longTasks.length>100&&e.longTasks.shift()}}),this.performanceObserver.observe({entryTypes:["longtask"]})}catch(e){}},t.createEmptyReport=function(){return{startTime:0,endTime:0,totalFrames:0,averageFrameTime:0,minFrameTime:0,maxFrameTime:0,p95FrameTime:0,p99FrameTime:0,hotspots:[],callGraph:new Map,categoryBreakdown:new Map,memoryTrend:[],longTasks:[]}},e}();Ke.instance=null;var $e=function(){function e(){this.selectedFunction=null,this.peakMemory=0}var t=e.prototype;return t.setSelectedFunction=function(e){this.selectedFunction=e},t.collectAdvancedData=function(e){var t=Ke.getFrameHistory(),n=Ke.getCurrentFrame(),i=Ke.getReport(300),r=(null==n?void 0:n.memory)||this.getDefaultMemory();return r.usedHeapSize>this.peakMemory&&(this.peakMemory=r.usedHeapSize),{currentFrame:this.buildCurrentFrameData(n),frameTimeHistory:this.buildFrameTimeHistory(t),categoryStats:this.buildCategoryStats(n,e),hotspots:this.buildHotspots(i),callGraph:this.buildCallGraph(i),longTasks:i.longTasks,memoryTrend:this.buildMemoryTrend(i.memoryTrend),summary:this.buildSummary(i,r)}},t.collectFromLegacyMonitor=function(e){var t,n;if(!e)return this.createEmptyData();var i=(null===(t=e.getAllSystemStats)||void 0===t?void 0:t.call(e))||new Map,r=(null===(n=e.getAllSystemData)||void 0===n?void 0:n.call(e))||new Map,o=1e3*y.deltaTime,s=o>0?Math.round(1e3/o):0,a=this.buildCategoryStatsFromLegacy(i,r,o),c=this.buildHotspotsFromLegacy(i,r,o);return{currentFrame:{frameNumber:0,frameTime:o,fps:s,memory:this.getCurrentMemory()},frameTimeHistory:[],categoryStats:a,hotspots:c,callGraph:{currentFunction:this.selectedFunction,callers:[],callees:[]},longTasks:[],memoryTrend:[],summary:{totalFrames:0,averageFrameTime:o,minFrameTime:o,maxFrameTime:o,p95FrameTime:o,p99FrameTime:o,currentMemoryMB:this.getCurrentMemory().usedHeapSize/1048576,peakMemoryMB:this.peakMemory/1048576,gcCount:0,longTaskCount:0}}},t.buildCurrentFrameData=function(e){if(!e){var t=1e3*y.deltaTime;return{frameNumber:0,frameTime:t,fps:t>0?Math.round(1e3/t):0,memory:this.getCurrentMemory()}}return{frameNumber:e.frameNumber,frameTime:e.duration,fps:e.duration>0?Math.round(1e3/e.duration):0,memory:e.memory}},t.buildFrameTimeHistory=function(e){return e.map(function(e){return{frameNumber:e.frameNumber,time:e.startTime,duration:e.duration}})},t.buildCategoryStats=function(e,t){var n=[];if(e&&e.categoryStats.size>0)for(var i,r=e.duration||1,o=function(){var t=i.value,o=t[0],s=t[1],a=e.sampleStats.filter(function(e){return e.category===o}).map(function(e){return{name:e.name,inclusiveTime:e.inclusiveTime,exclusiveTime:e.exclusiveTime,callCount:e.callCount,percentOfCategory:s.totalTime>0?e.inclusiveTime/s.totalTime*100:0,percentOfFrame:e.inclusiveTime/r*100}}).sort(function(e,t){return t.inclusiveTime-e.inclusiveTime});n.push({category:o,totalTime:s.totalTime,percentOfFrame:s.percentOfFrame,sampleCount:s.sampleCount,items:a})},a=s(e.categoryStats);!(i=a()).done;)o();if(t&&0===n.length){var c,u,l=(null===(c=t.getAllSystemStats)||void 0===c?void 0:c.call(t))||new Map,h=(null===(u=t.getAllSystemData)||void 0===u?void 0:u.call(t))||new Map,d=1e3*y.deltaTime||1;return this.buildCategoryStatsFromLegacy(l,h,d)}return n.sort(function(e,t){return t.totalTime-e.totalTime})},t.buildCategoryStatsFromLegacy=function(e,t,n){for(var i,r=[],o=0,a=s(e.entries());!(i=a()).done;){var c=i.value,u=c[0],l=c[1],h=t.get(u),d=(null==h?void 0:h.executionTime)||(null==l?void 0:l.averageTime)||0;o+=d,r.push({name:u,inclusiveTime:d,exclusiveTime:d,callCount:1,percentOfCategory:0,percentOfFrame:n>0?d/n*100:0})}for(var f=0,p=r;f<p.length;f++){var m=p[f];m.percentOfCategory=o>0?m.inclusiveTime/o*100:0}return r.sort(function(e,t){return t.inclusiveTime-e.inclusiveTime}),0===r.length?[]:[{category:exports.ProfileCategory.ECS,totalTime:o,percentOfFrame:n>0?o/n*100:0,sampleCount:r.length,items:r}]},t.buildHotspots=function(e){for(var t,n=e.hotspots.reduce(function(e,t){return e+t.inclusiveTime},0)||1,i=new Set,r=new Set,o=s(e.callGraph);!(t=o()).done;){var a=t.value,c=a[0],u=a[1];if(0===u.callers.size)i.add(c);else{for(var l,h=!1,d=s(u.callers.keys());!(l=d()).done;){var f=l.value;if(e.callGraph.has(f)){h=!0,r.add(c);break}}h||i.add(c)}}for(var p,m=function(t,i,r){if(r.has(t))return null;r.add(t);var o=e.hotspots.find(function(e){return e.name===t}),a=e.callGraph.get(t);if(!o&&!a)return null;var c=(null==o?void 0:o.inclusiveTime)||(null==a?void 0:a.totalTime)||0,u=(null==o?void 0:o.exclusiveTime)||c,l=(null==o?void 0:o.callCount)||(null==a?void 0:a.callCount)||1,h=[];if(a&&i<5){for(var d,f=s(a.callees);!(d=f()).done;){var p=d.value[0],v=m(p,i+1,r);v&&h.push(v)}h.sort(function(e,t){return t.inclusiveTime-e.inclusiveTime})}return{name:t,category:(null==o?void 0:o.category)||(null==a?void 0:a.category)||exports.ProfileCategory.Custom,inclusiveTime:c,inclusiveTimePercent:c/n*100,exclusiveTime:u,exclusiveTimePercent:u/n*100,callCount:l,avgCallTime:l>0?c/l:0,depth:i,children:h.length>0?h:void 0}},v=[],g=new Set,y=s(i);!(p=y()).done;){var _=p.value,S=m(_,0,g);S&&v.push(S)}return v.sort(function(e,t){return t.inclusiveTime-e.inclusiveTime}),v.slice(0,50)},t.buildHotspotsFromLegacy=function(e,t,n){for(var i,r=[],o=s(e.entries());!(i=o()).done;){var a=i.value,c=a[0],u=a[1],l=t.get(c),h=(null==l?void 0:l.executionTime)||(null==u?void 0:u.averageTime)||0;r.push({name:c,category:exports.ProfileCategory.ECS,inclusiveTime:h,inclusiveTimePercent:n>0?h/n*100:0,exclusiveTime:h,exclusiveTimePercent:n>0?h/n*100:0,callCount:(null==u?void 0:u.executionCount)||1,avgCallTime:(null==u?void 0:u.averageTime)||h,depth:0})}return r.sort(function(e,t){return t.inclusiveTime-e.inclusiveTime}).slice(0,50)},t.buildCallGraph=function(e){if(!this.selectedFunction)return{currentFunction:null,callers:[],callees:[]};var t=e.callGraph.get(this.selectedFunction);if(!t)return{currentFunction:this.selectedFunction,callers:[],callees:[]};for(var n,i=0,r=s(t.callers.values());!(n=r()).done;){var o=n.value;i+=o.count}var a=Array.from(t.callers.entries()).map(function(e){var t=e[0],n=e[1];return{name:t,callCount:n.count,totalTime:n.totalTime,percentOfCurrent:i>0?n.count/i*100:0}}).sort(function(e,t){return t.callCount-e.callCount}),c=Array.from(t.callees.entries()).map(function(e){var n=e[0],i=e[1];return{name:n,callCount:i.count,totalTime:i.totalTime,percentOfCurrent:t.totalTime>0?i.totalTime/t.totalTime*100:0}}).sort(function(e,t){return t.totalTime-e.totalTime});return{currentFunction:this.selectedFunction,callers:a,callees:c}},t.buildMemoryTrend=function(e){return e.map(function(e){return{time:e.timestamp,usedMB:e.usedHeapSize/1048576,totalMB:e.totalHeapSize/1048576,gcCount:e.gcCount}})},t.buildSummary=function(e,t){return{totalFrames:e.totalFrames,averageFrameTime:e.averageFrameTime,minFrameTime:e.minFrameTime,maxFrameTime:e.maxFrameTime,p95FrameTime:e.p95FrameTime,p99FrameTime:e.p99FrameTime,currentMemoryMB:t.usedHeapSize/1048576,peakMemoryMB:this.peakMemory/1048576,gcCount:t.gcCount,longTaskCount:e.longTasks.length}},t.getCurrentMemory=function(){var e,t,n,i=performance,r=(null===(e=i.memory)||void 0===e?void 0:e.usedJSHeapSize)||0,o=(null===(t=i.memory)||void 0===t?void 0:t.totalJSHeapSize)||0,s=(null===(n=i.memory)||void 0===n?void 0:n.jsHeapSizeLimit)||0;return{timestamp:performance.now(),usedHeapSize:r,totalHeapSize:o,heapSizeLimit:s,utilizationPercent:s>0?r/s*100:0,gcCount:0}},t.getDefaultMemory=function(){return{timestamp:performance.now(),usedHeapSize:0,totalHeapSize:0,heapSizeLimit:0,utilizationPercent:0,gcCount:0}},t.createEmptyData=function(){return{currentFrame:{frameNumber:0,frameTime:0,fps:0,memory:this.getDefaultMemory()},frameTimeHistory:[],categoryStats:[],hotspots:[],callGraph:{currentFunction:null,callers:[],callees:[]},longTasks:[],memoryTrend:[],summary:{totalFrames:0,averageFrameTime:0,minFrameTime:0,maxFrameTime:0,p95FrameTime:0,p99FrameTime:0,currentMemoryMB:0,peakMemoryMB:0,gcCount:0,longTaskCount:0}}},e}();function et(){return"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():function(){if("undefined"!=typeof crypto&&"function"==typeof crypto.getRandomValues){var e=new Uint8Array(16);return crypto.getRandomValues(e),e[6]=15&e[6]|64,e[8]=63&e[8]|128,function(e){var t=Array.from(e,function(e){return e.toString(16).padStart(2,"0")}).join("");return t.slice(0,8)+"-"+t.slice(8,12)+"-"+t.slice(12,16)+"-"+t.slice(16,20)+"-"+t.slice(20)}(e)}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}()}var tt=268435455,nt=1048575,it=1<<28,rt=1<<20;function ot(e,t){return(t&nt)*it+(e&tt)}function st(e){return e&tt}function at(e){return Math.floor(e/it)&nt}function ct(e){return 0!==e}var ut=function(){function e(){}return e.prototype.compare=function(e,t){var n=e.updateOrder-t.updateOrder;return 0==n&&(n=e.id-t.id),n},e}(),lt=function(){function e(e,t,n){this._handle=0,this.scene=null,this._isDestroyed=!1,this._active=!0,this._tag=0,this._enabled=!0,this._updateOrder=0,this._componentMask=U.clone(U.ZERO),this._componentCache=null,this._lifecyclePolicy=0,this.name=e,this.id=t,this.persistentId=null!=n?n:et()}var t=e.prototype;return t.setHandle=function(e){this._handle=e},t.setPersistent=function(){return this._lifecyclePolicy=1,this},t.setSceneLocal=function(){return this._lifecyclePolicy=0,this},t.setDestroyedState=function(e){this._isDestroyed=e},t._rebuildComponentCache=function(){var e,t=[];if(null!==(e=this.scene)&&void 0!==e&&e.componentStorageManager){for(var n=this._componentMask,i=this.scene.componentRegistry,r=i.getRegisteredCount(),o=0;o<r;o++)if(U.getBit(n,o)){var s=i.getTypeByBitIndex(o);if(s){var a=this.scene.componentStorageManager.getComponent(this.id,s);a&&t.push(a)}}this._componentCache=t}else this._componentCache=t},t.createComponent=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var o=i(e,n);return this.addComponent(o)},t.addComponentInternal=function(e){var t,n,i=e.constructor,r=(null!==(t=null===(n=this.scene)||void 0===n?void 0:n.componentRegistry)&&void 0!==t?t:K).getBitMask(i);return U.orInPlace(this._componentMask,r),this._componentCache=null,e},t.notifyQuerySystems=function(e){this.scene&&this.scene.querySystem&&(this.scene.querySystem.updateEntity(this),this.scene.clearSystemEntityCaches(),this.scene.notifyEntityComponentChanged&&this.scene.notifyEntityComponentChanged(this,e))},t.addComponent=function(e){var t,n=e.constructor;if(!this.scene)throw new Error("Entity must be added to Scene before adding components. Use scene.createEntity() instead of new Entity()");if(!this.scene.componentStorageManager)throw new Error("Scene does not have componentStorageManager");if(this.hasComponent(n))throw new Error("Entity "+this.name+" already has component "+L(n));(this.addComponentInternal(e),this.scene.componentStorageManager.addComponent(this.id,e),e.entityId=this.id,this.scene.referenceTracker&&this.scene.referenceTracker.registerEntityScene(this.id,this.scene),this.scene.isEditorMode?this.scene.queueDeferredComponentCallback(function(){e.onAddedToEntity()}):e.onAddedToEntity(),this.scene&&this.scene.eventSystem)&&this.scene.eventSystem.emitSync("component:added",{timestamp:Date.now(),source:"Entity",entityId:this.id,entityName:this.name,entityTag:null===(t=this.tag)||void 0===t?void 0:t.toString(),componentType:L(n),component:e});return this.notifyQuerySystems(n),e},t.getComponent=function(e){var t;return this.hasComponent(e)&&null!==(t=this.scene)&&void 0!==t&&t.componentStorageManager?this.scene.componentStorageManager.getComponent(this.id,e):null},t.hasComponent=function(e){var t,n,i=null!==(t=null===(n=this.scene)||void 0===n?void 0:n.componentRegistry)&&void 0!==t?t:K;if(!i.isRegistered(e))return!1;var r=i.getBitMask(e);return U.hasAny(this._componentMask,r)},t.getOrCreateComponent=function(e){var t=this.getComponent(e);if(!t){for(var n=arguments.length,i=new Array(n>1?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];t=this.createComponent.apply(this,[e].concat(i))}return t},t.markDirty=function(){if(this.scene){for(var e=this.scene.epochManager.current,t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];for(var r=0,o=n;r<o.length;r++){o[r].markDirty(e)}}},t.removeComponent=function(e){var t,n,i,r,o=e.constructor,s=null!==(t=null===(n=this.scene)||void 0===n?void 0:n.componentRegistry)&&void 0!==t?t:K;if(s.isRegistered(o)){var a,c=s.getBitIndex(o);if(U.clearBit(this._componentMask,c),this._componentCache=null,null!==(i=this.scene)&&void 0!==i&&i.componentStorageManager&&this.scene.componentStorageManager.removeComponent(this.id,o),null!==(r=this.scene)&&void 0!==r&&r.referenceTracker&&this.scene.referenceTracker.clearComponentReferences(e),e.onRemovedFromEntity&&e.onRemovedFromEntity(),e.entityId=null,this.scene&&this.scene.eventSystem)this.scene.eventSystem.emitSync("component:removed",{timestamp:Date.now(),source:"Entity",entityId:this.id,entityName:this.name,entityTag:null===(a=this.tag)||void 0===a?void 0:a.toString(),componentType:L(o),component:e});this.notifyQuerySystems(o)}},t.removeComponentByType=function(e){var t=this.getComponent(e);return t?(this.removeComponent(t),t):null},t.removeAllComponents=function(){var e=[].concat(this.components);U.clear(this._componentMask),this._componentCache=null;for(var t,n=s(e);!(t=n()).done;){var i,r=t.value,o=r.constructor;null!==(i=this.scene)&&void 0!==i&&i.componentStorageManager&&this.scene.componentStorageManager.removeComponent(this.id,o),r.onRemovedFromEntity()}this.notifyQuerySystems()},t.addComponents=function(t){for(var n,i=[],r=s(t);!(n=r()).done;){var o=n.value;try{i.push(this.addComponent(o))}catch(t){e._logger.warn("添加组件失败 "+H(o)+":",t)}}return i},t.removeComponentsByTypes=function(e){for(var t,n=[],i=s(e);!(t=i()).done;){var r=t.value;n.push(this.removeComponentByType(r))}return n},t.getComponents=function(e){for(var t,n=[],i=s(this.components);!(t=i()).done;){var r=t.value;r instanceof e&&n.push(r)}return n},t.getComponentByType=function(e){for(var t,n=s(this.components);!(t=n()).done;){var i=t.value;if(i instanceof e)return i}return null},t.onActiveChanged=function(){for(var e,t=s(this.components);!(e=t()).done;){var n=e.value;"onActiveChanged"in n&&"function"==typeof n.onActiveChanged&&n.onActiveChanged()}this.scene&&this.scene.eventSystem&&this.scene.eventSystem.emitSync("entity:activeChanged",{entity:this,active:this._active})},t.destroy=function(){this._isDestroyed||(this._isDestroyed=!0,this.scene&&this.scene.referenceTracker&&(this.scene.referenceTracker.clearReferencesTo(this.id),this.scene.referenceTracker.unregisterEntityScene(this.id)),this.removeAllComponents(),this.scene&&(this.scene.querySystem&&this.scene.querySystem.removeEntity(this),this.scene.entities&&this.scene.entities.remove(this)))},t.compareTo=function(e){return ut.prototype.compare(this,e)},t.toString=function(){return"Entity["+this.name+":"+this.id+":"+this.persistentId.slice(0,8)+"]"},t.getDebugInfo=function(){return{name:this.name,id:this.id,persistentId:this.persistentId,enabled:this._enabled,active:this._active,destroyed:this._isDestroyed,componentCount:this.components.length,componentTypes:this.components.map(function(e){return H(e)}),componentMask:U.toString(this._componentMask,2),cacheBuilt:null!==this._componentCache}},o(e,[{key:"lifecyclePolicy",get:function(){return this._lifecyclePolicy}},{key:"isPersistent",get:function(){return 1===this._lifecyclePolicy}},{key:"handle",get:function(){return this._handle}},{key:"isDestroyed",get:function(){return this._isDestroyed}},{key:"components",get:function(){return null===this._componentCache&&this._rebuildComponentCache(),this._componentCache}},{key:"active",get:function(){return this._active},set:function(e){this._active!==e&&(this._active=e,this.onActiveChanged())}},{key:"tag",get:function(){return this._tag},set:function(e){this._tag=e}},{key:"enabled",get:function(){return this._enabled},set:function(e){this._enabled=e}},{key:"updateOrder",get:function(){return this._updateOrder},set:function(e){this._updateOrder=e}},{key:"componentMask",get:function(){return this._componentMask}}])}();lt._logger=J("Entity"),lt.entityComparer=new ut;var ht=function(){function e(e){this.buffer=[],this._idToEntity=new Map,this._nameToEntities=new Map,this._entitiesToAdd=[],this._entitiesToRemove=[],this._scene=e}var t=e.prototype;return t.add=function(e){this.addImmediate(e)},t.addImmediate=function(e){this._idToEntity.has(e.id)||(this.buffer.push(e),this._idToEntity.set(e.id,e),this.updateNameIndex(e,!0))},t.remove=function(e){this.removeImmediate(e)},t.removeImmediate=function(e){var t=this.buffer.indexOf(e);-1!==t&&(this.buffer.splice(t,1),this._idToEntity.delete(e.id),this.updateNameIndex(e,!1),this._scene&&this._scene.identifierPool&&this._scene.identifierPool.checkIn(e.id))},t.removeAllEntities=function(){for(var e=[],t=this.buffer.length-1;t>=0;t--)e.push(this.buffer[t].id),this.buffer[t].destroy();for(var n,i=s(this._entitiesToAdd);!(n=i()).done;){var r=n.value;e.push(r.id),r.destroy()}if(this._scene&&this._scene.identifierPool)for(var o,a=s(e);!(o=a()).done;){var c=o.value;this._scene.identifierPool.checkIn(c)}this.buffer.length=0,this._idToEntity.clear(),this._nameToEntities.clear(),this._entitiesToAdd.length=0,this._entitiesToRemove.length=0},t.updateLists=function(){if(this._entitiesToAdd.length>0){for(var e,t=s(this._entitiesToAdd);!(e=t()).done;){var n=e.value;this.addImmediate(n)}this._entitiesToAdd.length=0}if(this._entitiesToRemove.length>0){for(var i,r=s(this._entitiesToRemove);!(i=r()).done;){var o=i.value;this.removeImmediate(o)}this._entitiesToRemove.length=0}},t.update=function(){this.updateLists()},t.findEntity=function(e){var t=this._nameToEntities.get(e);return t&&t.length>0?t[0]:null},t.findEntitiesByName=function(e){return this._nameToEntities.get(e)||[]},t.findEntityById=function(e){return this._idToEntity.get(e)||null},t.findEntitiesByTag=function(e){for(var t,n=[],i=s(this.buffer);!(t=i()).done;){var r=t.value;r.tag===e&&n.push(r)}return n},t.findEntitiesWithComponent=function(e){for(var t,n=[],i=s(this.buffer);!(t=i()).done;){var r=t.value;r.hasComponent(e)&&n.push(r)}return n},t.forEach=function(e){for(var t,n=s(this.buffer);!(t=n()).done;){e(t.value)}},t.forEachWhere=function(e,t){for(var n,i=s(this.buffer);!(n=i()).done;){var r=n.value;e(r)&&t(r)}},t.updateNameIndex=function(e,t){if(e.name)if(t){var n=this._nameToEntities.get(e.name);n||(n=[],this._nameToEntities.set(e.name,n)),n.push(e)}else{var i=this._nameToEntities.get(e.name);if(i){var r=i.indexOf(e);-1!==r&&(i.splice(r,1),0===i.length&&this._nameToEntities.delete(e.name))}}},t.reorderEntity=function(e,t){var n=this._idToEntity.get(e);if(n){var i=this.buffer.indexOf(n);if(-1!==i&&i!==t){var r=Math.max(0,Math.min(t,this.buffer.length-1));this.buffer.splice(i,1),this.buffer.splice(r,0,n)}}},t.getStats=function(){for(var e,t=0,n=s(this.buffer);!(e=n()).done;){var i=e.value;i.enabled&&!i.isDestroyed&&t++}return{totalEntities:this.buffer.length,activeEntities:t,pendingAdd:this._entitiesToAdd.length,pendingRemove:this._entitiesToRemove.length,nameIndexSize:this._nameToEntities.size}},o(e,[{key:"count",get:function(){return this.buffer.length}}])}(),dt=function(){function e(e,t){void 0===e&&(e=100),void 0===t&&(t=1024),this._nextAvailableIndex=0,this._freeIndices=[],this._generations=new Map,this._pendingRecycle=[],this._recycleDelay=100,this._stats={totalAllocated:0,totalRecycled:0,currentActive:0,memoryExpansions:0},this._recycleDelay=e,this._expansionBlockSize=t,this._preAllocateGenerations(0,this._expansionBlockSize)}var t=e.prototype;return t.checkOut=function(){var t;if(this._processDelayedRecycle(),this._freeIndices.length>0)t=this._freeIndices.pop();else{if(this._nextAvailableIndex>e.MAX_INDEX)throw new Error("实体索引已达到框架设计限制 ("+e.MAX_INDEX+")。这意味着您已经分配了超过65535个不同的实体索引。这是16位索引设计的限制,考虑优化实体回收策略或升级到64位ID设计。");t=this._nextAvailableIndex++,this._ensureGenerationCapacity(t)}var n=this._generations.get(t)||1;return this._stats.totalAllocated++,this._stats.currentActive++,this._packId(t,n)},t.checkIn=function(e){var t=this._unpackIndex(e),n=this._unpackGeneration(e);return!!this._isValidId(t,n)&&(!this._pendingRecycle.some(function(e){return e.index===t&&e.generation===n})&&(this._pendingRecycle.push({index:t,generation:n,timestamp:Date.now()}),this._stats.currentActive--,this._stats.totalRecycled++,!0))},t.isValid=function(e){var t=this._unpackIndex(e),n=this._unpackGeneration(e);return this._isValidId(t,n)},t.getStats=function(){for(var t,n=0,i=0,r=s(this._generations);!(t=r()).done;){var o=t.value,a=o[0],c=o[1];a<this._nextAvailableIndex&&(n+=c,i++)}var u=i>0?n/i:1;return{totalAllocated:this._stats.totalAllocated,totalRecycled:this._stats.totalRecycled,currentActive:this._stats.currentActive,currentlyFree:this._freeIndices.length,pendingRecycle:this._pendingRecycle.length,maxPossibleEntities:e.MAX_INDEX+1,maxUsedIndex:this._nextAvailableIndex-1,memoryUsage:this._calculateMemoryUsage(),memoryExpansions:this._stats.memoryExpansions,averageGeneration:Math.round(100*u)/100,generationStorageSize:this._generations.size}},t.forceProcessDelayedRecycle=function(){this._processDelayedRecycle(!0)},t._processDelayedRecycle=function(t){if(void 0===t&&(t=!1),0!==this._pendingRecycle.length){for(var n,i=Date.now(),r=[],o=[],a=s(this._pendingRecycle);!(n=a()).done;){var c=n.value;t||i-c.timestamp>=this._recycleDelay?r.push(c):o.push(c)}for(var u=0,l=r;u<l.length;u++){var h=l[u];if(this._isValidId(h.index,h.generation)){var d=h.generation+1;d>e.MAX_GENERATION&&(d=1),this._generations.set(h.index,d),this._freeIndices.push(h.index)}}this._pendingRecycle=o}},t._preAllocateGenerations=function(t,n){for(var i=0;i<n;i++){var r=t+i;r<=e.MAX_INDEX&&this._generations.set(r,1)}this._stats.memoryExpansions++},t._ensureGenerationCapacity=function(e){if(!this._generations.has(e)){var t=Math.floor(e/this._expansionBlockSize)*this._expansionBlockSize;this._preAllocateGenerations(t,this._expansionBlockSize)}},t._calculateMemoryUsage=function(){return 16*this._generations.size+8*this._freeIndices.length+32*this._pendingRecycle.length},t._packId=function(e,t){return t<<16|e},t._unpackIndex=function(e){return 65535&e},t._unpackGeneration=function(e){return e>>>16&65535},t._isValidId=function(e,t){if(e<0||e>=this._nextAvailableIndex)return!1;var n=this._generations.get(e);return void 0!==n&&n===t},e}();dt.MAX_INDEX=65535,dt.MAX_GENERATION=65535;var ft=function(){function e(){this._processors=[],this._isDirty=!1}var t=e.prototype;return t.setDirty=function(){this._isDirty=!0},t.add=function(e){this._processors.push(e),this.setDirty()},t.remove=function(e){var t=this._processors.indexOf(e);-1!==t&&this._processors.splice(t,1)},t.getProcessor=function(e){for(var t,n=s(this._processors);!(t=n()).done;){var i=t.value;if(i instanceof e)return i}return null},t.begin=function(){this.sortProcessors()},t.end=function(){for(var t,n=s(this._processors);!(t=n()).done;){var i=t.value;try{i.reset()}catch(t){e._logger.error("Error in processor "+re(i)+":",t)}}this._isDirty=!1,this._processors.length=0},t.update=function(){this.sortProcessors();for(var t,n=s(this._processors);!(t=n()).done;){var i=t.value;try{i.update()}catch(t){e._logger.error("Error in processor "+re(i)+":",t)}}},t.lateUpdate=function(){for(var e,t=s(this._processors);!(e=t()).done;){e.value.lateUpdate()}},t.sortProcessors=function(){this._isDirty&&(this._processors.sort(function(e,t){return e.updateOrder-t.updateOrder}),this._isDirty=!1)},o(e,[{key:"processors",get:function(){return this._processors}},{key:"count",get:function(){return this._processors.length}}])}();ft._logger=J("EntityProcessorList");var pt=function(){function e(e){if(e&&"object"==typeof e)this._value=U.clone(e);else if("number"==typeof e)this._value=U.fromNumber(e);else if("string"==typeof e){var t=parseInt(e,10);this._value=U.fromNumber(t)}else this._value=U.clone(U.ZERO)}var t=e.prototype;return t.set=function(e){if(e<0)throw new Error("Bit index cannot be negative");U.setBit(this._value,e)},t.clear=function(e){if(e<0)throw new Error("Bit index cannot be negative");U.clearBit(this._value,e)},t.get=function(e){return U.getBit(this._value,e)},t.containsAll=function(e){return U.hasAll(this._value,e._value)},t.intersects=function(e){return U.hasAny(this._value,e._value)},t.excludes=function(e){return U.hasNone(this._value,e._value)},t.clearAll=function(){U.clear(this._value)},t.isEmpty=function(){return U.isZero(this._value)},t.cardinality=function(){return U.popCount(this._value)},t.and=function(t){var n=new e;return U.copy(this._value,n._value),U.andInPlace(n._value,t._value),n},t.or=function(t){var n=new e;return U.copy(this._value,n._value),U.orInPlace(n._value,t._value),n},t.xor=function(t){var n=new e;return U.copy(this._value,n._value),U.xorInPlace(n._value,t._value),n},t.not=function(t){void 0===t&&(t=64),t>64&&(t=64);var n=new e;if(U.copy(this._value,n._value),t<=32){var i=(1<<t)-1;n._value.base[O.LOW]=~n._value.base[O.LOW]&i,n._value.base[O.HIGH]=0}else if(n._value.base[O.LOW]=~n._value.base[O.LOW],t<64){var r=(1<<t-32)-1;n._value.base[O.HIGH]=~n._value.base[O.HIGH]&r}else n._value.base[O.HIGH]=~n._value.base[O.HIGH];return n},t.copyFrom=function(e){U.copy(e._value,this._value)},t.clone=function(){return new e(this._value)},t.getValue=function(){return this._value},t.setValue=function(e){if("object"==typeof e)U.copy(e,this._value);else if("number"==typeof e)this._value=U.fromNumber(e);else{var t=parseInt(e,10);this._value=U.fromNumber(t)}},t.toString=function(){for(var e=[],t=0;t<64;t++)this.get(t)&&e.push(t.toString());return"Bits["+e.join(", ")+"]"},t.toBinaryString=function(e){void 0===e&&(e=0),0==e&&(e=64+(this._value.segments?64*this._value.segments.length:0));for(var t="",n=e-1;n>=0;n--)t+=this.get(n)?"1":"0",n%8==0&&n>0&&(t+=" ");return t},t.toHexString=function(){return U.toString(this._value,16)},e.fromBinaryString=function(t){var n,i=t.replace(/\s/g,"");if(i.length<=32){n={base:[parseInt(i,2)>>>0,0]}}else{var r=i.substring(i.length-32),o=i.substring(0,i.length-32);n={base:[parseInt(r,2)>>>0,parseInt(o,2)>>>0]}}return new e(n)},e.fromHexString=function(t){var n,i=t.replace(/^0x/i,"");if(i.length<=8){n={base:[parseInt(i,16)>>>0,0]}}else{var r=i.substring(i.length-8),o=i.substring(0,i.length-8);n={base:[parseInt(r,16)>>>0,parseInt(o,16)>>>0]}}return new e(n)},t.equals=function(e){return U.equals(this._value,e._value)},t.getHighestBitIndex=function(){if(U.isZero(this._value))return-1;if(0!==this._value.base[O.HIGH])for(var e=31;e>=0;e--)if(this._value.base[O.HIGH]&1<<e)return e+32;for(var t=31;t>=0;t--)if(this._value.base[O.LOW]&1<<t)return t;return-1},t.getLowestBitIndex=function(){if(U.isZero(this._value))return-1;for(var e=0;e<32;e++)if(this._value.base[O.LOW]&1<<e)return e;for(var t=0;t<32;t++)if(this._value.base[O.HIGH]&1<<t)return t+32;return-1},e}(),mt=function(){function e(){this._dense=[],this._sparse=new Map}var t=e.prototype;return t.add=function(e){if(this._sparse.has(e))return!1;var t=this._dense.length;return this._dense.push(e),this._sparse.set(e,t),!0},t.remove=function(e){var t=this._sparse.get(e);if(void 0===t)return!1;var n=this._dense.length-1;if(t!==n){var i=this._dense[n];this._dense[t]=i,this._sparse.set(i,t)}return this._dense.pop(),this._sparse.delete(e),!0},t.has=function(e){return this._sparse.has(e)},t.getIndex=function(e){return this._sparse.get(e)},t.getByIndex=function(e){return this._dense[e]},t.forEach=function(e){for(var t=0;t<this._dense.length;t++)e(this._dense[t],t)},t.map=function(e){for(var t=[],n=0;n<this._dense.length;n++)t.push(e(this._dense[n],n));return t},t.filter=function(e){for(var t=[],n=0;n<this._dense.length;n++)e(this._dense[n],n)&&t.push(this._dense[n]);return t},t.find=function(e){for(var t=0;t<this._dense.length;t++)if(e(this._dense[t],t))return this._dense[t]},t.some=function(e){for(var t=0;t<this._dense.length;t++)if(e(this._dense[t],t))return!0;return!1},t.every=function(e){for(var t=0;t<this._dense.length;t++)if(!e(this._dense[t],t))return!1;return!0},t.getDenseArray=function(){return[].concat(this._dense)},t.getDenseArrayUnsafe=function(){return this._dense},t.clear=function(){this._dense.length=0,this._sparse.clear()},t.toArray=function(){return[].concat(this._dense)},t.toSet=function(){return new Set(this._dense)},t.getMemoryStats=function(){var e=8*this._dense.length,t=16*this._sparse.size;return{denseArraySize:e,sparseMapSize:t,totalMemory:e+t}},t.validate=function(){if(this._dense.length!==this._sparse.size)return!1;for(var e=0;e<this._dense.length;e++){var t=this._dense[e];if(this._sparse.get(t)!==e)return!1}for(var n,i=s(this._sparse);!(n=i()).done;){var r=n.value,o=r[0],a=r[1];if(a>=this._dense.length||this._dense[a]!==o)return!1}return!0},o(e,[{key:"size",get:function(){return this._dense.length}},{key:"isEmpty",get:function(){return 0===this._dense.length}}])}(),vt=function(e){function t(){return e.call(this)||this}return u(t,e),t.prototype.reset=function(){this.clear()},t}(m(Set)),gt=function(){function e(){this._componentMasks=[],this._componentToEntities=new Map,this._entities=new mt}var t=e.prototype;return t.addEntity=function(e){this._entities.has(e)&&this.removeEntity(e);for(var t,n=U.clone(U.ZERO),i=new Set,r=s(e.components);!(t=r()).done;){var o=t.value.constructor;i.add(o);var a=K.getBitMask(o);U.orInPlace(n,a)}this._entities.add(e);for(var c=this._entities.getIndex(e);this._componentMasks.length<=c;)this._componentMasks.push(U.clone(U.ZERO));this._componentMasks[c]=n,this.updateComponentMappings(e,i,!0)},t.removeEntity=function(e){var t=this._entities.getIndex(e);if(void 0!==t){var n=this.getEntityComponentTypes(e);this.updateComponentMappings(e,n,!1),this._entities.remove(e);var i=this._componentMasks.length-1;t!==i&&(this._componentMasks[t]=this._componentMasks[i]),this._componentMasks.pop()}},t.queryByComponent=function(e){var t=this._componentToEntities.get(e);return t?new Set(t):new Set},t.queryMultipleAnd=function(t){var n=this;if(0===t.length)return new Set;if(1===t.length)return this.queryByComponent(t[0]);for(var i,r=U.clone(U.ZERO),o=s(t);!(i=o()).done;){var a=i.value;if(!K.isRegistered(a))return new Set;var c=K.getBitMask(a);U.orInPlace(r,c)}var u=e._entitySetPool.obtain();return this._entities.forEach(function(e,t){var i=n._componentMasks[t];U.hasAll(i,r)&&u.add(e)}),u},t.queryMultipleOr=function(t){var n=this;if(0===t.length)return new Set;if(1===t.length)return this.queryByComponent(t[0]);for(var i,r=U.clone(U.ZERO),o=s(t);!(i=o()).done;){var a=i.value;if(K.isRegistered(a)){var c=K.getBitMask(a);U.orInPlace(r,c)}}if(U.equals(r,U.ZERO))return new Set;var u=e._entitySetPool.obtain();return this._entities.forEach(function(e,t){var i=n._componentMasks[t];U.hasAny(i,r)&&u.add(e)}),u},t.hasComponent=function(e,t){var n=this._entities.getIndex(e);if(void 0===n)return!1;if(!K.isRegistered(t))return!1;var i=this._componentMasks[n],r=K.getBitMask(t);return U.hasAny(i,r)},t.getEntityMask=function(e){var t=this._entities.getIndex(e);if(void 0!==t)return this._componentMasks[t]},t.getAllEntities=function(){return this._entities.toArray()},t.forEach=function(e){var t=this;this._entities.forEach(function(n,i){e(n,t._componentMasks[i],i)})},t.clear=function(){this._entities.clear(),this._componentMasks.length=0;for(var t,n=s(this._componentToEntities.values());!(t=n()).done;){var i=t.value;e._entitySetPool.release(i)}this._componentToEntities.clear()},t.getMemoryStats=function(){for(var e,t=this._entities.getMemoryStats(),n=16*this._componentMasks.length,i=16*this._componentToEntities.size,r=s(this._componentToEntities.values());!(e=r()).done;){i+=8*e.value.size}return{entitiesMemory:t.totalMemory,masksMemory:n,mappingsMemory:i,totalMemory:t.totalMemory+n+i}},t.validate=function(){if(!this._entities.validate())return!1;if(this._componentMasks.length!==this._entities.size)return!1;for(var e,t=new Set,n=s(this._componentToEntities.values());!(e=n()).done;)for(var i,r=s(e.value);!(i=r()).done;){var o=i.value;t.add(o)}for(var a,c=s(t);!(a=c()).done;){var u=a.value;if(!this._entities.has(u))return!1}return!0},t.getEntityComponentTypes=function(e){for(var t,n=new Set,i=s(e.components);!(t=i()).done;){var r=t.value;n.add(r.constructor)}return n},t.updateComponentMappings=function(t,n,i){for(var r,o=s(n);!(r=o()).done;){var a=r.value,c=this._componentToEntities.get(a);i?(c||(c=e._entitySetPool.obtain(),this._componentToEntities.set(a,c)),c.add(t)):c&&(c.delete(t),0===c.size&&(this._componentToEntities.delete(a),e._entitySetPool.release(c)))}},o(e,[{key:"size",get:function(){return this._entities.size}},{key:"isEmpty",get:function(){return this._entities.isEmpty}}])}();gt._entitySetPool=P.getPool(vt,50,512);var yt,_t=function(){function e(){this.buckets=new Map,this._size=0}var t=e.prototype;return t.murmur32=function(e,t){var n=t>>>0,i=function(e){e=(e=Math.imul(e,3432918353)>>>0)<<15|e>>>17,e=Math.imul(e,461845907)>>>0,n=(n^=e)<<13|n>>>19,n=Math.imul(n,5)+3864292196>>>0};if(i(e.base[0]>>>0),i(e.base[1]>>>0),e.segments)for(var r,o=s(e.segments);!(r=o()).done;){var a=r.value;i(a[0]>>>0),i(a[1]>>>0)}return n^=e.segments?8*e.segments.length:8,n^=n>>>16,n=Math.imul(n,2246822507)>>>0,n^=n>>>13,n=Math.imul(n,3266489909)>>>0,(n^=n>>>16)>>>0},t.getHashes=function(e){return[this.murmur32(e,2538058380),this.murmur32(e,305419896)]},t.set=function(e,t){var n=this.getHashes(e),i=n[0],r=n[1],o=this.buckets.get(i);o||(o=[],this.buckets.set(i,o));for(var s=0;s<o.length;s++)if(o[s][0]===r)return o[s][1]=t,this;return o.push([r,t]),this._size++,this},t.get=function(e){var t=this.getHashes(e),n=t[0],i=t[1],r=this.buckets.get(n);if(r)for(var o=0;o<r.length;o++)if(r[o][0]===i)return r[o][1]},t.has=function(e){return void 0!==this.get(e)},t.delete=function(e){var t=this.getHashes(e),n=t[0],i=t[1],r=this.buckets.get(n);if(!r)return!1;for(var o=0;o<r.length;o++)if(r[o][0]===i)return r.splice(o,1),this._size--,0===r.length&&this.buckets.delete(n),!0;return!1},t.clear=function(){this.buckets.clear(),this._size=0},t.entries=h().m(function e(){var t,n,i,r,o,a,c,u;return h().w(function(e){for(;;)switch(e.n){case 0:t=s(this.buckets);case 1:if((n=t()).done){e.n=5;break}(i=n.value)[0],r=i[1],o=s(r);case 2:if((a=o()).done){e.n=4;break}return(c=a.value)[0],u=c[1],e.n=3,[void 0,u];case 3:e.n=2;break;case 4:e.n=1;break;case 5:return e.a(2)}},e,this)}),t.values=h().m(function e(){var t,n,i,r,o,a,c;return h().w(function(e){for(;;)switch(e.n){case 0:t=s(this.buckets.values());case 1:if((n=t()).done){e.n=5;break}i=n.value,r=s(i);case 2:if((o=r()).done){e.n=4;break}return(a=o.value)[0],c=a[1],e.n=3,c;case 3:e.n=2;break;case 4:e.n=1;break;case 5:return e.a(2)}},e,this)}),o(e,[{key:"size",get:function(){return this._size}},{key:"innerBuckets",get:function(){return this.buckets}}])}(),St=function(){function e(){this._archetypes=new _t,this._entityToArchetype=new Map,this._componentToArchetypes=new Map,this._entityComponentTypesCache=new Map,this._allArchetypes=[]}var t=e.prototype;return t.addEntity=function(e){var t=this.getEntityComponentTypes(e),n=this.generateArchetypeId(t),i=this._archetypes.get(n);i||(i=this.createArchetype(t)),i.entities.add(e),this._entityToArchetype.set(e,i)},t.removeEntity=function(e){var t=this._entityToArchetype.get(e);t&&(t.entities.delete(e),this._entityComponentTypesCache.delete(e),this._entityToArchetype.delete(e))},t.updateEntity=function(e){var t=this._entityToArchetype.get(e);this._entityComponentTypesCache.delete(e);var n=this.getEntityComponentTypes(e),i=this.generateArchetypeId(n);if(!t||t.id!==i){t&&t.entities.delete(e);var r=this._archetypes.get(i);r||(r=this.createArchetype(n)),r.entities.add(e),this._entityToArchetype.set(e,r)}},t.queryArchetypes=function(e,t){void 0===t&&(t="AND");var n=[],i=0;if("AND"===t){if(0===e.length){for(var r,o=s(this._allArchetypes);!(r=o()).done;){var a=r.value;n.push(a),i+=a.entities.size}return{archetypes:n,totalEntities:i}}if(1===e.length){var c=this._componentToArchetypes.get(e[0]);if(c)for(var u,l=s(c);!(u=l()).done;){var h=u.value;n.push(h),i+=h.entities.size}return{archetypes:n,totalEntities:i}}for(var d,f,p=1/0,m=s(e);!(f=m()).done;){var v=f.value,g=this._componentToArchetypes.get(v);if(!g||0===g.size)return{archetypes:[],totalEntities:0};g.size<p&&(p=g.size,d=g)}var y=this.generateArchetypeId(e);if(d)for(var _,S=s(d);!(_=S()).done;){var C=_.value;U.hasAll(C.id,y)&&(n.push(C),i+=C.entities.size)}}else{for(var E,b=new Set,T=s(e);!(E=T()).done;){var w=E.value,I=this._componentToArchetypes.get(w);if(I)for(var x,M=s(I);!(x=M()).done;){var A=x.value;b.add(A)}}for(var k,D=s(b);!(k=D()).done;){var P=k.value;n.push(P),i+=P.entities.size}}return{archetypes:n,totalEntities:i}},t.getEntityArchetype=function(e){return this._entityToArchetype.get(e)},t.getAllArchetypes=function(){return this._allArchetypes.slice()},t.getEntitiesByComponent=function(e){var t=this._componentToArchetypes.get(e);if(!t||0===t.size)return[];for(var n,i=[],r=s(t);!(n=r()).done;)for(var o,a=s(n.value.entities);!(o=a()).done;){var c=o.value;i.push(c)}return i},t.clear=function(){this._archetypes.clear(),this._entityToArchetype.clear(),this._componentToArchetypes.clear(),this._entityComponentTypesCache.clear(),this._allArchetypes=[]},t.updateAllArchetypeArrays=function(){this._allArchetypes=[];for(var e,t=s(this._archetypes.values());!(e=t()).done;){var n=e.value;this._allArchetypes.push(n)}},t.getEntityComponentTypes=function(e){var t=this._entityComponentTypesCache.get(e);return t||(t=e.components.map(function(e){return e.constructor}),this._entityComponentTypesCache.set(e,t)),t},t.generateArchetypeId=function(e){for(var t,n=U.clone(U.ZERO),i=s(e);!(t=i()).done;){var r=t.value,o=K.getBitMask(r);U.orInPlace(n,o)}return n},t.createArchetype=function(e){var t=this.generateArchetypeId(e),n={id:t,componentTypes:[].concat(e),entities:new Set};this._archetypes.set(t,n),this.updateAllArchetypeArrays();for(var i,r=s(e);!(i=r()).done;){var o=i.value,a=this._componentToArchetypes.get(o);a||(a=new Set,this._componentToArchetypes.set(o,a)),a.add(n)}return n},e}();!function(e){e.ALL="all",e.ANY="any",e.NONE="none"}(yt||(yt={}));var Ct,Et=J("ReactiveQuery");exports.ReactiveQueryChangeType=void 0,(Ct=exports.ReactiveQueryChangeType||(exports.ReactiveQueryChangeType={})).ADDED="added",Ct.REMOVED="removed",Ct.BATCH_UPDATE="batch_update";var bt=function(){function e(e,t){var n,i,r;void 0===t&&(t={}),this._entities=[],this._entityIdSet=new Set,this._snapshot=null,this._listeners=[],this._active=!0,this._condition=e,this._config={enableBatchMode:null===(n=t.enableBatchMode)||void 0===n||n,batchDelay:null!==(i=t.batchDelay)&&void 0!==i?i:16,debug:null!==(r=t.debug)&&void 0!==r&&r},this._id=this.generateQueryId(),this._batchChanges={added:[],removed:[],timer:null},this._config.debug&&Et.debug("创建ReactiveQuery: "+this._id)}var t=e.prototype;return t.generateQueryId=function(){return this._condition.type+":"+this._condition.componentTypes.map(function(e){return e.name}).sort().join(",")},t.subscribe=function(e){var t=this;if(!this._active)throw new Error("Cannot subscribe to disposed ReactiveQuery "+this._id);if("function"!=typeof e)throw new TypeError("Listener must be a function");return this._listeners.push(e),this._config.debug&&Et.debug("订阅ReactiveQuery: "+this._id+", 监听器数量: "+this._listeners.length),function(){var n=t._listeners.indexOf(e);-1!==n&&t._listeners.splice(n,1)}},t.unsubscribeAll=function(){this._listeners.length=0},t.getEntities=function(){return null!==this._snapshot||(this._snapshot=[].concat(this._entities)),this._snapshot},t.matches=function(e){var t=e.componentMask;switch(this._condition.type){case yt.ALL:return U.hasAll(t,this._condition.mask);case yt.ANY:return U.hasAny(t,this._condition.mask);case yt.NONE:return U.hasNone(t,this._condition.mask);default:return!1}},t.notifyEntityAdded=function(e){this._active&&this.matches(e)&&(this._entityIdSet.has(e.id)||(this._entities.push(e),this._entityIdSet.add(e.id),this._snapshot=null,this._config.enableBatchMode?this.addToBatch("added",e):this.notifyListeners({type:exports.ReactiveQueryChangeType.ADDED,entity:e}),this._config.debug&&Et.debug("ReactiveQuery "+this._id+": 实体添加 "+e.name+"("+e.id+")")))},t.notifyEntityRemoved=function(e){if(this._active&&this._entityIdSet.has(e.id)){var t=this._entities.indexOf(e);-1!==t&&this._entities.splice(t,1),this._entityIdSet.delete(e.id),this._snapshot=null,this._config.enableBatchMode?this.addToBatch("removed",e):this.notifyListeners({type:exports.ReactiveQueryChangeType.REMOVED,entity:e}),this._config.debug&&Et.debug("ReactiveQuery "+this._id+": 实体移除 "+e.name+"("+e.id+")")}},t.notifyEntityChanged=function(e){if(this._active){var t=this._entityIdSet.has(e.id),n=this.matches(e);t&&!n?this.notifyEntityRemoved(e):!t&&n&&this.notifyEntityAdded(e)}},t.initializeWith=function(e){this._entities.length=0,this._entityIdSet.clear(),this._snapshot=null;for(var t,n=s(e);!(t=n()).done;){var i=t.value;this.matches(i)&&(this._entities.push(i),this._entityIdSet.add(i.id))}this._config.debug&&Et.debug("ReactiveQuery "+this._id+": 初始化 "+this._entities.length+" 个实体")},t.addToBatch=function(e,t){var n=this;"added"===e?this._batchChanges.added.push(t):this._batchChanges.removed.push(t),null===this._batchChanges.timer&&(this._batchChanges.timer=setTimeout(function(){n.flushBatchChanges()},this._config.batchDelay))},t.flushBatchChanges=function(){if(0!==this._batchChanges.added.length||0!==this._batchChanges.removed.length){var e=[].concat(this._batchChanges.added),t=[].concat(this._batchChanges.removed);this._batchChanges.added.length=0,this._batchChanges.removed.length=0,this._batchChanges.timer=null,this.notifyListeners({type:exports.ReactiveQueryChangeType.BATCH_UPDATE,added:e,removed:t,entities:this._entities}),this._config.debug&&Et.debug("ReactiveQuery "+this._id+": 批量更新 +"+e.length+" -"+t.length)}else this._batchChanges.timer=null},t.notifyListeners=function(e){for(var t,n=s([].concat(this._listeners));!(t=n()).done;){var i=t.value;try{i(e)}catch(e){Et.error("ReactiveQuery "+this._id+": 监听器执行出错",e)}}},t.pause=function(){this._active=!1,null!==this._batchChanges.timer&&(clearTimeout(this._batchChanges.timer),this._batchChanges.timer=null),this._batchChanges.added.length=0,this._batchChanges.removed.length=0},t.resume=function(){this._active=!0},t.dispose=function(){null!==this._batchChanges.timer&&(clearTimeout(this._batchChanges.timer),this._batchChanges.timer=null),this._batchChanges.added.length=0,this._batchChanges.removed.length=0,this._active=!1,this.unsubscribeAll(),this._entities.length=0,this._entityIdSet.clear(),this._snapshot=null,this._config.debug&&Et.debug("ReactiveQuery "+this._id+": 已销毁")},o(e,[{key:"count",get:function(){return this._entities.length}},{key:"condition",get:function(){return this._condition}},{key:"id",get:function(){return this._id}},{key:"active",get:function(){return this._active}},{key:"listenerCount",get:function(){return this._listeners.length}}])}(),Tt=function(){function e(e){this._lastVersion=-1,this._cachedEntities=[],this._querySystem=e;for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];this._componentTypes=n}var t=e.prototype;return t._refreshCache=function(){var e=this._querySystem.version;if(this._lastVersion!==e){var t,n=(t=this._querySystem).queryAll.apply(t,this._componentTypes);this._cachedEntities=n.entities,this._lastVersion=e}},t.forEach=function(e){for(var t=this.entities,n=this._componentTypes,i=n.length,r=0,o=t.length;r<o;r++){for(var s=t[r],a=new Array(i),c=0;c<i;c++){var u=s.getComponent(n[c]);u&&(a[c]=u)}e.apply(void 0,[s].concat(a))}},t.forEachChanged=function(e,t){for(var n=this.entities,i=this._componentTypes,r=i.length,o=0,s=n.length;o<s;o++){for(var a=n[o],c=new Array(r),u=!1,l=0;l<r;l++){var h=a.getComponent(i[l]);h&&(c[l]=h,h.lastWriteEpoch>e&&(u=!0))}u&&t.apply(void 0,[a].concat(c))}},t.first=function(){var e=this.entities;if(0===e.length)return null;for(var t,n=e[0],i=[],r=s(this._componentTypes);!(t=r()).done;){var o=t.value,a=n.getComponent(o);if(!a)return null;i.push(a)}return[n].concat(i)},t.toArray=function(){var e=[];return this.forEach(function(t){for(var n=arguments.length,i=new Array(n>1?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];e.push([t].concat(i))}),e},t.map=function(e){var t=[];return this.forEach(function(n){for(var i=arguments.length,r=new Array(i>1?i-1:0),o=1;o<i;o++)r[o-1]=arguments[o];t.push(e.apply(void 0,[n].concat(r)))}),t},t.filter=function(e){var t=[];return this.forEach(function(n){for(var i=arguments.length,r=new Array(i>1?i-1:0),o=1;o<i;o++)r[o-1]=arguments[o];e.apply(void 0,[n].concat(r))&&t.push(n)}),t},t.find=function(e){for(var t=this.entities,n=this._componentTypes,i=n.length,r=0,o=t.length;r<o;r++){for(var s=t[r],a=new Array(i),c=0;c<i;c++){var u=s.getComponent(n[c]);u&&(a[c]=u)}if(e.apply(void 0,[s].concat(a)))return s}},t.any=function(){return this.count>0},t.empty=function(){return 0===this.count},o(e,[{key:"componentTypes",get:function(){return this._componentTypes}},{key:"entities",get:function(){return this._refreshCache(),this._cachedEntities}},{key:"count",get:function(){return this.entities.length}}])}(),wt=function(){function e(){this._logger=J("QuerySystem"),this._entities=[],this._version=0,this._queryCache=new Map,this._cacheMaxSize=1e3,this._cacheTimeout=5e3,this._componentMaskCache=new Map,this._queryStats={totalQueries:0,cacheHits:0,indexHits:0,linearScans:0,archetypeHits:0,dirtyChecks:0},this._reactiveQueries=new Map,this._reactiveQueriesByComponent=new Map,this._entityIndex={byTag:new Map,byName:new Map},this._archetypeSystem=new St}var t=e.prototype;return t.setEntities=function(e){this._entities=e,this.clearQueryCache(),this.clearReactiveQueries(),this.rebuildIndexes()},t.addEntity=function(e,t){void 0===t&&(t=!1),this._entities.includes(e)||(this._entities.push(e),this.addEntityToIndexes(e),this._archetypeSystem.addEntity(e),this.notifyReactiveQueriesEntityAdded(e),t||this.clearQueryCache(),this._version++)},t.addEntities=function(e){if(0!==e.length){for(var t,n=new Set(this._entities.map(function(e){return e.id})),i=0,r=s(e);!(t=r()).done;){var o=t.value;n.has(o.id)||(this._entities.push(o),this.addEntityToIndexes(o),this._archetypeSystem.addEntity(o),n.add(o.id),i++)}i>0&&this.clearQueryCache()}},t.addEntitiesUnchecked=function(e){if(0!==e.length){for(var t,n=s(e);!(t=n()).done;){var i=t.value;this._entities.push(i)}for(var r,o=s(e);!(r=o()).done;){var a=r.value;this.addEntityToIndexes(a),this._archetypeSystem.addEntity(a)}this.clearQueryCache()}},t.removeEntity=function(e){var t=this._entities.indexOf(e);if(-1!==t){for(var n,i=[],r=s(e.components);!(n=r()).done;){var o=n.value;i.push(o.constructor)}this._entities.splice(t,1),this.removeEntityFromIndexes(e),this._archetypeSystem.removeEntity(e),i.length>0?this.notifyReactiveQueriesEntityRemoved(e,i):this.notifyReactiveQueriesEntityRemovedFallback(e),this.clearQueryCache(),this._version++}},t.updateEntity=function(e){this._entities.includes(e)?(this.removeEntityFromIndexes(e),this._archetypeSystem.updateEntity(e),this.addEntityToIndexes(e),this.notifyReactiveQueriesEntityChanged(e),this.clearQueryCache(),this._version++):this.addEntity(e)},t.addEntityToIndexes=function(e){var t=e.tag;void 0!==t&&(this._entityIndex.byTag.get(t)||this.createAndSetTagIndex(t)).add(e);var n=e.name;n&&(this._entityIndex.byName.get(n)||this.createAndSetNameIndex(n)).add(e)},t.createAndSetTagIndex=function(e){var t=new Set;return this._entityIndex.byTag.set(e,t),t},t.createAndSetNameIndex=function(e){var t=new Set;return this._entityIndex.byName.set(e,t),t},t.removeEntityFromIndexes=function(e){if(void 0!==e.tag){var t=this._entityIndex.byTag.get(e.tag);t&&(t.delete(e),0===t.size&&this._entityIndex.byTag.delete(e.tag))}if(e.name){var n=this._entityIndex.byName.get(e.name);n&&(n.delete(e),0===n.size&&this._entityIndex.byName.delete(e.name))}},t.rebuildIndexes=function(){this._entityIndex.byTag.clear(),this._entityIndex.byName.clear(),this._archetypeSystem.clear();for(var e,t=s(this._entities);!(e=t()).done;){var n=e.value;this.addEntityToIndexes(n),this._archetypeSystem.addEntity(n)}},t.queryAll=function(){var e=performance.now();this._queryStats.totalQueries++;for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];var r=this.getOrCreateReactiveQuery(yt.ALL,n).getEntities();return this._queryStats.cacheHits++,{entities:r,count:r.length,executionTime:performance.now()-e,fromCache:!0}},t.queryAny=function(){var e=performance.now();this._queryStats.totalQueries++;for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];var r=this.getOrCreateReactiveQuery(yt.ANY,n).getEntities();return this._queryStats.cacheHits++,{entities:r,count:r.length,executionTime:performance.now()-e,fromCache:!0}},t.queryNone=function(){var e=performance.now();this._queryStats.totalQueries++;for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];var r=this.getOrCreateReactiveQuery(yt.NONE,n).getEntities();return this._queryStats.cacheHits++,{entities:r,count:r.length,executionTime:performance.now()-e,fromCache:!0}},t.queryByTag=function(e){var t=performance.now();this._queryStats.totalQueries++;var n="tag:"+e,i=this.getFromCache(n);if(i)return this._queryStats.cacheHits++,{entities:i,count:i.length,executionTime:performance.now()-t,fromCache:!0};this._queryStats.indexHits++;var r=Array.from(this._entityIndex.byTag.get(e)||[]);return this.addToCache(n,r),{entities:r,count:r.length,executionTime:performance.now()-t,fromCache:!1}},t.queryByName=function(e){var t=performance.now();this._queryStats.totalQueries++;var n="name:"+e,i=this.getFromCache(n);if(i)return this._queryStats.cacheHits++,{entities:i,count:i.length,executionTime:performance.now()-t,fromCache:!0};this._queryStats.indexHits++;var r=Array.from(this._entityIndex.byName.get(e)||[]);return this.addToCache(n,r),{entities:r,count:r.length,executionTime:performance.now()-t,fromCache:!1}},t.queryChangedSince=function(e){var t=performance.now();this._queryStats.totalQueries++,this._queryStats.dirtyChecks++;for(var n=arguments.length,i=new Array(n>1?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];for(var o,a=[],c=s(this.queryAll.apply(this,i).entities);!(o=c()).done;){for(var u,l=o.value,h=!1,d=s(i);!(u=d()).done;){var f=u.value,p=l.getComponent(f);if(p&&p.lastWriteEpoch>e){h=!0;break}}h&&a.push(l)}return{entities:a,count:a.length,executionTime:performance.now()-t,fromCache:!1}},t.queryByComponent=function(e){var t=performance.now();this._queryStats.totalQueries++;var n=this.generateCacheKey("component",[e]),i=this.getFromCache(n);if(i)return this._queryStats.cacheHits++,{entities:i,count:i.length,executionTime:performance.now()-t,fromCache:!0};this._queryStats.indexHits++;var r=this._archetypeSystem.getEntitiesByComponent(e);return this.addToCache(n,r),{entities:r,count:r.length,executionTime:performance.now()-t,fromCache:!1}},t.getFromCache=function(e){var t=this._queryCache.get(e);return t?Date.now()-t.timestamp>this._cacheTimeout||t.version!==this._version?(this._queryCache.delete(e),null):(t.hitCount++,t.entities):null},t.addToCache=function(e,t){this._queryCache.size>=this._cacheMaxSize&&this.cleanupCache(),this._queryCache.set(e,{entities:t,timestamp:Date.now(),hitCount:0,version:this._version})},t.cleanupCache=function(){for(var e,t=Date.now(),n=s(this._queryCache.entries());!(e=n()).done;){var i=e.value,r=i[0];t-i[1].timestamp>this._cacheTimeout&&this._queryCache.delete(r)}if(this._queryCache.size>=this._cacheMaxSize){for(var o,a=1/0,c="",u=1/0,l=s(this._queryCache.entries());!(o=l()).done;){var h=o.value,d=h[0],f=h[1];(f.hitCount<a||f.hitCount===a&&f.timestamp<u)&&(a=f.hitCount,c=d,u=f.timestamp)}c&&this._queryCache.delete(c)}},t.clearQueryCache=function(){this._queryCache.clear(),this._componentMaskCache.clear()},t.clearReactiveQueries=function(){for(var e,t=s(this._reactiveQueries.values());!(e=t()).done;){e.value.dispose()}this._reactiveQueries.clear(),this._reactiveQueriesByComponent.clear()},t.generateCacheKey=function(e,t){return 1===t.length?e+":"+L(t[0]):e+":"+t.map(function(e){return L(e)}).sort().join(",")},t.clearCache=function(){this.clearQueryCache(),this.clearReactiveQueries()},t.compile=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return i(Tt,[this].concat(t))},t.createReactiveQuery=function(e,t){if(!e||0===e.length)throw new Error("组件类型列表不能为空");var n=this.createComponentMask(e),i={type:yt.ALL,componentTypes:e,mask:n},r=new bt(i,t),o=this.executeTraditionalQuery(yt.ALL,e);r.initializeWith(o);var a=this.generateCacheKey("all",e);this._reactiveQueries.set(a,r);for(var c,u=s(e);!(c=u()).done;){var l=c.value,h=this._reactiveQueriesByComponent.get(l);h||(h=new Set,this._reactiveQueriesByComponent.set(l,h)),h.add(r)}return r},t.destroyReactiveQuery=function(e){if(e){var t=e.id;this._reactiveQueries.delete(t);for(var n,i=s(e.condition.componentTypes);!(n=i()).done;){var r=n.value,o=this._reactiveQueriesByComponent.get(r);o&&(o.delete(e),0===o.size&&this._reactiveQueriesByComponent.delete(r))}e.dispose()}},t.createComponentMask=function(e){var t=e.map(function(e){return L(e)}).sort().join(","),n=this._componentMaskCache.get(t);if(n)return n;for(var i,r=U.clone(U.ZERO),o=s(e);!(i=o()).done;){var a=i.value,c=K.getBitMask(a);U.orInPlace(r,c)}return this._componentMaskCache.set(t,r),r},t.getAllEntities=function(){return this._entities},t.getStats=function(){return{entityCount:this._entities.length,indexStats:{componentIndexSize:this._archetypeSystem.getAllArchetypes().length,tagIndexSize:this._entityIndex.byTag.size,nameIndexSize:this._entityIndex.byName.size},queryStats:a({},this._queryStats,{cacheHitRate:this._queryStats.totalQueries>0?(this._queryStats.cacheHits/this._queryStats.totalQueries*100).toFixed(2)+"%":"0%"}),optimizationStats:{archetypeSystem:this._archetypeSystem.getAllArchetypes().map(function(e){return{id:e.id,componentTypes:e.componentTypes.map(function(e){return L(e)}),entityCount:e.entities.size}})},cacheStats:{size:this._reactiveQueries.size,hitRate:this._queryStats.totalQueries>0?(this._queryStats.cacheHits/this._queryStats.totalQueries*100).toFixed(2)+"%":"0%"}}},t.getEntityArchetype=function(e){return this._archetypeSystem.getEntityArchetype(e)},t.getOrCreateReactiveQuery=function(e,t){var n=this.generateCacheKey(e,t),i=this._reactiveQueries.get(n);if(!i){var r=this.createComponentMask(t);i=new bt({type:e,componentTypes:t,mask:r},{enableBatchMode:!1,debug:!1});var o=this.executeTraditionalQuery(e,t);i.initializeWith(o),this._reactiveQueries.set(n,i);for(var a,c=s(t);!(a=c()).done;){var u=a.value,l=this._reactiveQueriesByComponent.get(u);l||(l=new Set,this._reactiveQueriesByComponent.set(u,l)),l.add(i)}this._logger.debug("创建内部响应式查询缓存: "+n)}return i},t.executeTraditionalQuery=function(e,t){switch(e){case yt.ALL:for(var n,i=[],r=s(this._archetypeSystem.queryArchetypes(t,"AND").archetypes);!(n=r()).done;)for(var o,a=s(n.value.entities);!(o=a()).done;){var c=o.value;i.push(c)}return i;case yt.ANY:for(var u,l=[],h=s(this._archetypeSystem.queryArchetypes(t,"OR").archetypes);!(u=h()).done;)for(var d,f=s(u.value.entities);!(d=f()).done;){var p=d.value;l.push(p)}return l;case yt.NONE:var m=this.createComponentMask(t);return this._entities.filter(function(e){return U.hasNone(e.componentMask,m)});default:return[]}},t.notifyReactiveQueriesEntityAdded=function(e){if(0!==this._reactiveQueries.size)for(var t,n=new Set,i=s(e.components);!(t=i()).done;){var r=t.value.constructor,o=this._reactiveQueriesByComponent.get(r);if(o)for(var a,c=s(o);!(a=c()).done;){var u=a.value;n.has(u)||(u.notifyEntityAdded(e),n.add(u))}}},t.notifyReactiveQueriesEntityRemoved=function(e,t){if(0!==this._reactiveQueries.size)for(var n,i=new Set,r=s(t);!(n=r()).done;){var o=n.value,a=this._reactiveQueriesByComponent.get(o);if(a)for(var c,u=s(a);!(c=u()).done;){var l=c.value;i.has(l)||(l.notifyEntityRemoved(e),i.add(l))}}},t.notifyReactiveQueriesEntityRemovedFallback=function(e){if(0!==this._reactiveQueries.size)for(var t,n=s(this._reactiveQueries.values());!(t=n()).done;){t.value.notifyEntityRemoved(e)}},t.notifyReactiveQueriesEntityChanged=function(e){if(0!==this._reactiveQueries.size){for(var t,n=new Set,i=s(e.components);!(t=i()).done;){var r=t.value.constructor,o=this._reactiveQueriesByComponent.get(r);if(o)for(var a,c=s(o);!(a=c()).done;){var u=a.value;n.has(u)||(u.notifyEntityChanged(e),n.add(u))}}for(var l,h=s(this._reactiveQueries.values());!(l=h()).done;){var d=l.value;n.has(d)||d.notifyEntityChanged(e)}}},o(e,[{key:"version",get:function(){return this._version}}])}(),It=function(){function e(e){this._logger=J("QueryBuilder"),this.conditions=[],this.querySystem=e}var t=e.prototype;return t.withAll=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return this.conditions.push({type:yt.ALL,componentTypes:t,mask:this.createComponentMask(t)}),this},t.withAny=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return this.conditions.push({type:yt.ANY,componentTypes:t,mask:this.createComponentMask(t)}),this},t.without=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return this.conditions.push({type:yt.NONE,componentTypes:t,mask:this.createComponentMask(t)}),this},t.execute=function(){var e,t,n,i=performance.now();if(1===this.conditions.length){var r=this.conditions[0];switch(r.type){case yt.ALL:return(e=this.querySystem).queryAll.apply(e,r.componentTypes);case yt.ANY:return(t=this.querySystem).queryAny.apply(t,r.componentTypes);case yt.NONE:return(n=this.querySystem).queryNone.apply(n,r.componentTypes)}}return{entities:[],count:0,executionTime:performance.now()-i,fromCache:!1}},t.createComponentMask=function(e){for(var t,n=U.clone(U.ZERO),i=s(e);!(t=i()).done;){var r=t.value;try{var o=K.getBitMask(r);U.orInPlace(n,o)}catch(e){this._logger.warn("组件类型 "+L(r)+" 未注册,跳过")}}return n},t.reset=function(){return this.conditions=[],this},e}(),xt=function(){function e(){this.listeners=new Map,this.stats=new Map,this.batchQueue=new Map,this.batchTimers=new Map,this.batchConfigs=new Map,this.nextListenerId=0,this.isEnabled=!0,this.maxListeners=100}var t=e.prototype;return t.on=function(e,t,n){return void 0===n&&(n={}),this.addListener(e,t,n)},t.once=function(e,t,n){return void 0===n&&(n={}),this.addListener(e,t,a({},n,{once:!0}))},t.onAsync=function(e,t,n){return void 0===n&&(n={}),this.addListener(e,t,a({},n,{async:!0}))},t.off=function(e,t){var n=this.listeners.get(e);if(!n)return!1;var i=n.findIndex(function(e){return e.id===t});return-1!==i&&(n.splice(i,1),0===n.length&&(this.listeners.delete(e),this.stats.delete(e)),!0)},t.offAll=function(e){this.listeners.delete(e),this.stats.delete(e),this.clearBatch(e)},t.emit=function(){var e=n(h().m(function e(t,n){var i;return h().w(function(e){for(;;)switch(e.n){case 0:if(this.isEnabled){e.n=1;break}return e.a(2);case 1:if(null==(i=this.batchConfigs.get(t))||!i.enabled){e.n=2;break}return this.addToBatch(t,n),e.a(2);case 2:return e.n=3,this.executeEvent(t,n);case 3:return e.a(2)}},e,this)}));return function(t,n){return e.apply(this,arguments)}}(),t.emitSync=function(t,n){if(this.isEnabled){var i=this.listeners.get(t);if(i&&0!==i.length){for(var r,o=performance.now(),a=[],c=s(this.sortListenersByPriority(i));!(r=c()).done;){var u=r.value;if(!u.config.async)try{u.config.thisArg?u.handler.call(u.config.thisArg,n):u.handler(n),u.config.once&&a.push(u.id)}catch(n){e._logger.error("事件处理器执行错误 "+t+":",n)}}this.removeListeners(t,a),this.updateStats(t,performance.now()-o)}}},t.setBatchConfig=function(e,t){this.batchConfigs.set(e,t)},t.flushBatch=function(e){var t=this.batchQueue.get(e);if(t&&0!==t.length){var n=this.batchTimers.get(e);n&&(clearTimeout(n),this.batchTimers.delete(e)),this.processBatch(e,t),this.batchQueue.delete(e)}},t.getStats=function(e){return e?this.stats.get(e)||this.createEmptyStats(e):new Map(this.stats)},t.resetStats=function(e){e?this.stats.delete(e):this.stats.clear()},t.setEnabled=function(e){this.isEnabled=e},t.hasListeners=function(e){var t=this.listeners.get(e);return!!t&&t.length>0},t.getListenerCount=function(e){var t=this.listeners.get(e);return t?t.length:0},t.clear=function(){this.listeners.clear(),this.stats.clear(),this.clearAllBatches()},t.setMaxListeners=function(e){this.maxListeners=e},t.addListener=function(t,n,i){var r=this.listeners.get(t);if(r||(r=[],this.listeners.set(t,r)),r.length>=this.maxListeners)return e._logger.warn("事件类型 "+t+" 的监听器数量超过最大限制 ("+this.maxListeners+")"),"";var o="listener_"+this.nextListenerId++,s={handler:n,config:a({priority:0},i),id:o};return r.push(s),this.stats.has(t)||this.stats.set(t,this.createEmptyStats(t)),o},t.executeEvent=function(){var t=n(h().m(function t(i,r){var o,a,c,u,l,d,f,p,m,v;return h().w(function(t){for(;;)switch(t.n){case 0:if((o=this.listeners.get(i))&&0!==o.length){t.n=1;break}return t.a(2);case 1:for(a=performance.now(),c=[],u=this.sortListenersByPriority(o),l=u.filter(function(e){return!e.config.async}),d=u.filter(function(e){return e.config.async}),f=s(l);!(p=f()).done;){m=p.value;try{m.config.thisArg?m.handler.call(m.config.thisArg,r):m.handler(r),m.config.once&&c.push(m.id)}catch(t){e._logger.error("同步事件处理器执行错误 "+i+":",t)}}return v=d.map(function(){var t=n(h().m(function t(n){var o;return h().w(function(t){for(;;)switch(t.p=t.n){case 0:if(t.p=0,!n.config.thisArg){t.n=2;break}return t.n=1,n.handler.call(n.config.thisArg,r);case 1:t.n=3;break;case 2:return t.n=3,n.handler(r);case 3:n.config.once&&c.push(n.id),t.n=5;break;case 4:t.p=4,o=t.v,e._logger.error("异步事件处理器执行错误 "+i+":",o);case 5:return t.a(2)}},t,null,[[0,4]])}));return function(e){return t.apply(this,arguments)}}()),t.n=2,Promise.all(v);case 2:this.removeListeners(i,c),this.updateStats(i,performance.now()-a);case 3:return t.a(2)}},t,this)}));return function(e,n){return t.apply(this,arguments)}}(),t.sortListenersByPriority=function(e){return e.slice().sort(function(e,t){return(t.config.priority||0)-(e.config.priority||0)})},t.removeListeners=function(e,t){if(0!==t.length){var n=this.listeners.get(e);if(n){for(var i,r=function(){var e=i.value,t=n.findIndex(function(t){return t.id===e});-1!==t&&n.splice(t,1)},o=s(t);!(i=o()).done;)r();0===n.length&&(this.listeners.delete(e),this.stats.delete(e))}}},t.addToBatch=function(e,t){var n=this,i=this.batchQueue.get(e);i||(i=[],this.batchQueue.set(e,i)),i.push(t);var r=this.batchConfigs.get(e);if(i.length>=r.batchSize)this.flushBatch(e);else if(!this.batchTimers.has(e)){var o=setTimeout(function(){n.flushBatch(e)},r.delay);this.batchTimers.set(e,o)}},t.processBatch=function(){var e=n(h().m(function e(t,n){var i;return h().w(function(e){for(;;)switch(e.n){case 0:return i={type:t,events:n,count:n.length,timestamp:Date.now()},e.n=1,this.executeEvent(t+":batch",i);case 1:return e.a(2)}},e,this)}));return function(t,n){return e.apply(this,arguments)}}(),t.clearBatch=function(e){this.batchQueue.delete(e);var t=this.batchTimers.get(e);t&&(clearTimeout(t),this.batchTimers.delete(e))},t.clearAllBatches=function(){this.batchQueue.clear();for(var e,t=s(this.batchTimers.values());!(e=t()).done;){var n=e.value;clearTimeout(n)}this.batchTimers.clear(),this.batchConfigs.clear()},t.updateStats=function(e,t){var n=this.stats.get(e);n||(n=this.createEmptyStats(e),this.stats.set(e,n)),n.triggerCount++,n.totalExecutionTime+=t,n.averageExecutionTime=n.totalExecutionTime/n.triggerCount,n.lastTriggerTime=Date.now(),n.listenerCount=this.getListenerCount(e)},t.createEmptyStats=function(e){return{eventType:e,listenerCount:0,triggerCount:0,totalExecutionTime:0,averageExecutionTime:0,lastTriggerTime:0}},e}();xt._logger=J("EventSystem");var Mt=function(){function e(e,t){this._entities=e,this._componentTypes=t}var t=e.prototype;return t.forEach=function(e){this._entities.forEach(e)},t.map=function(e){return this._entities.map(e)},t.filter=function(t){return new e(this._entities.filter(t),this._componentTypes)},t.find=function(e){return this._entities.find(e)},t.some=function(e){return this._entities.some(e)},t.every=function(e){return this._entities.every(e)},t.get=function(e){return this._entities[e]},t.toArray=function(){return[].concat(this._entities)},t.getComponentTypes=function(){return this._componentTypes},t[Symbol.iterator]=function(){return this._entities[Symbol.iterator]()},o(e,[{key:"entities",get:function(){return this._entities}},{key:"length",get:function(){return this._entities.length}},{key:"first",get:function(){return this._entities[0]}},{key:"last",get:function(){return this._entities[this._entities.length-1]}},{key:"isEmpty",get:function(){return 0===this._entities.length}}])}(),At=function(){function e(e,t,n,i,r){this._all=e||[],this._any=t||[],this._none=n||[],void 0!==i&&(this._tag=i),void 0!==r&&(this._name=r)}var t=e.prototype;return t.withAll=function(){for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];return new e([].concat(this._all,n),this._any,this._none,this._tag,this._name)},t.withAny=function(){for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];return new e(this._all,[].concat(this._any,n),this._none,this._tag,this._name)},t.withNone=function(){for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];return new e(this._all,this._any,[].concat(this._none,n),this._tag,this._name)},t.withTag=function(t){return new e(this._all,this._any,this._none,t,this._name)},t.withName=function(t){return new e(this._all,this._any,this._none,this._tag,t)},t.buildMatcher=function(){var e,t,n,i=Pe.complex();this._all.length>0&&(i=(e=i).all.apply(e,this._all));this._any.length>0&&(i=(t=i).any.apply(t,this._any));this._none.length>0&&(i=(n=i).none.apply(n,this._none));return void 0!==this._tag&&(i=i.withTag(this._tag)),void 0!==this._name&&(i=i.withName(this._name)),i},t.getCondition=function(){return a({all:[].concat(this._all),any:[].concat(this._any),none:[].concat(this._none)},void 0!==this._tag&&{tag:this._tag},void 0!==this._name&&{name:this._name})},t.getRequiredTypes=function(){return this._all},t.clone=function(){return new e([].concat(this._all),[].concat(this._any),[].concat(this._none),this._tag,this._name)},e}();var kt=new Map;function Dt(e,t){kt.set(e,t)}Dt("Date",{check:function(e){return e instanceof Date},serialize:function(e){return{__type:"Date",value:e.toISOString()}},deserialize:function(e){return new Date(e.value)}}),Dt("Map",{check:function(e){return e instanceof Map},serialize:function(e,t){return{__type:"Map",value:[].concat(e).map(function(e){var n=e[0],i=e[1];return[t(n),t(i)]})}},deserialize:function(e){return new Map(e.value)}}),Dt("Set",{check:function(e){return e instanceof Set},serialize:function(e,t){return{__type:"Set",value:[].concat(e).map(t)}},deserialize:function(e){return new Set(e.value)}});var Pt,Ot={serialize:function e(t,n){if(void 0===n&&(n=new WeakSet),null==t)return t;var i=typeof t;if("string"===i||"number"===i||"boolean"===i)return t;if("function"!==i){var r=t;if(!n.has(r)){n.add(r);for(var o,a=s(kt);!(o=a()).done;){var c=o.value[1];if(c.check(t))return c.serialize(t,function(t){return e(t,n)})}if(Array.isArray(t))return t.map(function(t){return e(t,n)});for(var u={},l=0,h=Object.keys(t);l<h.length;l++){var d=h[l];u[d]=e(t[d],n)}return u}}},deserialize:function e(t){if(null==t)return t;var n=typeof t;if("string"===n||"number"===n||"boolean"===n)return t;if(function(e){if(null===e||"object"!=typeof e)return!1;return"__type"in e}(t)){var i=kt.get(t.__type);return i?i.deserialize(t):t}if(Array.isArray(t))return t.map(e);for(var r={},o=0,s=Object.keys(t);o<s.length;o++){var a=s[o];r[a]=e(t[a])}return r},register:Dt},Rt=function(){function e(){}return e.serialize=function(e){var t=De(e);if(!t)return null;for(var n,i=e.constructor,r=t.options.typeId||L(i),o={},a=s(t.fields);!(n=a()).done;){var c=n.value,u=c[0],l=c[1];if(!t.ignoredFields.has(u)){var h="symbol"==typeof u?u.toString():u,d=e[u],f=void 0;f=me(e,h)?this.serializeEntityRef(d):l.serializer?l.serializer(d):Ot.serialize(d),o[l.alias||h]=f}}return{type:r,version:t.options.version,data:o}},e.deserialize=function(e,t,n){var i=t.get(e.type);if(!i)return console.warn("Component type not found: "+e.type),null;var r=De(i);if(!r)return console.warn("Component "+e.type+" is not serializable"),null;for(var o,a=new i,c=s(r.fields);!(o=c()).done;){var u=o.value,l=u[0],h=u[1],d="symbol"==typeof l?l.toString():l,f=h.alias||d,p=e.data[f];if(void 0!==p)if(this.isSerializedEntityRef(p)){if(n){var m=p.__entityRef;n.registerPendingRef(a,d,m.id,m.guid)}a[l]=null}else{var v=h.deserializer?h.deserializer(p):Ot.deserialize(p);a[l]=v}}return a},e.serializeComponents=function(e){var t=this;return e.map(function(e){return t.serialize(e)}).filter(function(e){return null!==e})},e.deserializeComponents=function(e,t,n){var i=this;return e.map(function(e){return i.deserialize(e,t,n)}).filter(function(e){return null!==e})},e.validateVersion=function(e,t){return e.version===t},e.getSerializationInfo=function(e){var t=De(e);if(!t)return{type:"unknown",version:0,fields:[],ignoredFields:[],isSerializable:!1};var n="function"==typeof e?e:e.constructor;return{type:t.options.typeId||L(n),version:t.options.version,fields:Array.from(t.fields.keys()).map(function(e){return"symbol"==typeof e?e.toString():e}),ignoredFields:Array.from(t.ignoredFields).map(function(e){return"symbol"==typeof e?e.toString():e}),isSerializable:!0}},e.serializeEntityRef=function(e){return e?{__entityRef:{id:e.id,guid:e.persistentId}}:null},e.isSerializedEntityRef=function(e){return"object"==typeof e&&null!==e&&"__entityRef"in e},e}(),zt=function(){function e(){}return e.serialize=function(e,t,n){void 0===t&&(t=!0);var i=Rt.serializeComponents(Array.from(e.components)),r={id:e.id,guid:e.persistentId,name:e.name,tag:e.tag,active:e.active,enabled:e.enabled,updateOrder:e.updateOrder,components:i,children:[]},o=e.getComponent(exports.HierarchyComponent);if(null!==(null==o?void 0:o.parentId)&&void 0!==(null==o?void 0:o.parentId)&&(r.parentId=o.parentId),t&&o&&o.childIds.length>0){var a,c=null!==(a=null==n?void 0:n.scene)&&void 0!==a?a:e.scene;if(c)for(var u,l=s(o.childIds);!(u=l()).done;){var h=u.value,d=c.findEntityById(h);d&&r.children.push(this.serialize(d,!0,n))}}return r},e.deserialize=function(e,t,n,i,r,o,a,c){void 0===i&&(i=!1);var u=i?e.id:n(),l=new lt(e.name,u,e.guid);null==a||a.set(l.id,l),c&&c.registerEntity(l,e.id,e.guid),r&&(l.scene=r),l.tag=e.tag,l.active=e.active,l.enabled=e.enabled,l.updateOrder=e.updateOrder;for(var h,d=s(Rt.deserializeComponents(e.components,t,c));!(h=d()).done;){var f=h.value;l.addComponent(f)}var p=l.getComponent(exports.HierarchyComponent);p&&(p.parentId=null,p.childIds=[]);for(var m,v=s(e.children);!(m=v()).done;){var g=m.value,y=this.deserialize(g,t,n,i,r,o,a,c);null==o||o.setParent(y,l)}return l},e.serializeEntities=function(e,t,n){void 0===t&&(t=!0);for(var i,r=[],o=s(e);!(i=o()).done;){var a=i.value,c=a.getComponent(exports.HierarchyComponent);null!==(null==c?void 0:c.parentId)&&void 0!==(null==c?void 0:c.parentId)&&t||r.push(this.serialize(a,t,n))}return r},e.deserializeEntities=function(e,t,n,i,r,o,a){void 0===i&&(i=!1);for(var c,u=[],l=new Map,h=s(e);!(c=h()).done;){var d=c.value,f=this.deserialize(d,t,n,i,r,o,l,a);u.push(f)}return{rootEntities:u,allEntities:l}},e.clone=function(e,t,n){var i=this.serialize(e,!0);return this.deserialize(i,t,n,!1)},e}(),Nt=function(){function e(){}return e.stringToUtf8=function(e){for(var t=e.length,n=0,i=[],r=0;r<t;r++){var o=e.charCodeAt(r);if(o>=55296&&o<=56319&&r+1<t){var s=o,a=e.charCodeAt(r+1);a>=56320&&a<=57343&&(o=65536+(s-55296<<10)+(a-56320),r++)}o<128?i[n++]=o:o<2048?(i[n++]=192|o>>6,i[n++]=128|63&o):o<65536?(i[n++]=224|o>>12,i[n++]=128|o>>6&63,i[n++]=128|63&o):(i[n++]=240|o>>18,i[n++]=128|o>>12&63,i[n++]=128|o>>6&63,i[n++]=128|63&o)}return new Uint8Array(i)},e.utf8ToString=function(e){for(var t=e.length,n="",i=0;i<t;){var r=e[i++];if(void 0===r)break;if(r<128)n+=String.fromCharCode(r);else if(192==(224&r)){var o=e[i++];if(void 0===o)break;n+=String.fromCharCode((31&r)<<6|63&o)}else if(224==(240&r)){var s=e[i++],a=e[i++];if(void 0===s||void 0===a)break;n+=String.fromCharCode((15&r)<<12|(63&s)<<6|63&a)}else if(240==(248&r)){var c=e[i++],u=e[i++],l=e[i++];if(void 0===c||void 0===u||void 0===l)break;var h=(7&r)<<18|(63&c)<<12|(63&u)<<6|63&l;h-=65536,n+=String.fromCharCode(55296+(h>>10),56320+(1023&h))}}return n},e.encode=function(e){var t=JSON.stringify(e);return this.stringToUtf8(t)},e.decode=function(e){var t=this.utf8ToString(e);return JSON.parse(t)},e}(),Ft=function(){function e(){this._idRemapping=new Map,this._guidLookup=new Map,this._pendingRefs=[],this._preserveIds=!1}var t=e.prototype;return t.setPreserveIds=function(e){this._preserveIds=e},t.registerEntity=function(e,t,n){var i=null!=n?n:e.persistentId;this._guidLookup.set(i,e),void 0!==t&&this._idRemapping.set(t,e)},t.getEntityById=function(e){var t;return null!==(t=this._idRemapping.get(e))&&void 0!==t?t:null},t.getEntityByGuid=function(e){var t;return null!==(t=this._guidLookup.get(e))&&void 0!==t?t:null},t.resolveEntityRef=function(e){if(!e)return null;if(e.guid){var t=this._guidLookup.get(e.guid);if(t)return t}if(void 0!==e.id){var n=this._idRemapping.get(e.id);if(n)return n}return null},t.registerPendingRef=function(e,t,n,i){this._pendingRefs.push({component:e,propertyKey:t,originalId:n,originalGuid:i})},t.resolveAllReferences=function(){for(var e,t=0,n=s(this._pendingRefs);!(e=n()).done;){var i=e.value,r=this.resolveEntityRef({id:i.originalId,guid:i.originalGuid});r&&(i.component[i.propertyKey]=r,t++)}return t},t.getUnresolvedCount=function(){for(var e,t=0,n=s(this._pendingRefs);!(e=n()).done;){var i=e.value;this.resolveEntityRef({id:i.originalId,guid:i.originalGuid})||t++}return t},t.getPendingCount=function(){return this._pendingRefs.length},t.getRegisteredEntityCount=function(){return this._guidLookup.size},t.clear=function(){this._idRemapping.clear(),this._guidLookup.clear(),this._pendingRefs=[]},t.getDebugInfo=function(){return{registeredEntities:this._guidLookup.size,pendingRefs:this._pendingRefs.length,unresolvedRefs:this.getUnresolvedCount(),preserveIds:this._preserveIds}},o(e,[{key:"preserveIds",get:function(){return this._preserveIds}}])}(),Bt=function(){function e(){}return e.serialize=function(e,t){var n=a({systems:!1,format:"json",pretty:!0,includeMetadata:!0},t),i=this.filterEntities(e,n),r=e.getSystem(He),o=zt.serializeEntities(i,!0,null!=r?r:void 0),s=this.buildComponentTypeRegistry(i),c=this.serializeSceneData(e.sceneData),u={name:e.name,version:this.SERIALIZATION_VERSION,entities:o,componentTypeRegistry:s};return c&&Object.keys(c).length>0&&(u.sceneData=c),n.includeMetadata&&(u.timestamp=Date.now(),u.metadata={entityCount:o.length,componentTypeCount:s.length,serializationOptions:n}),"json"===n.format?n.pretty?JSON.stringify(u,null,2):JSON.stringify(u):Nt.encode(u)},e.deserialize=function(e,t,n){var i,r=a({strategy:"replace",preserveIds:!1},n);try{i="string"==typeof t?JSON.parse(t):Nt.decode(t)}catch(e){throw new Error("Failed to parse save data: "+e)}r.migration&&i.version!==this.SERIALIZATION_VERSION&&(i=r.migration(i.version,this.SERIALIZATION_VERSION,i));var o=r.componentRegistry||this.getGlobalComponentRegistry();"replace"===r.strategy&&e.destroyAllEntities();var c=e.getSystem(He),u=new Ft;u.setPreserveIds(r.preserveIds||!1);for(var l,h=zt.deserializeEntities(i.entities,o,function(){return e.identifierPool.checkOut()},r.preserveIds||!1,e,c,u),d=h.rootEntities,f=h.allEntities,p=s(d);!(l=p()).done;){var m=l.value;e.addEntity(m,!0),this.addChildrenRecursively(m,e,c,f)}e.querySystem.clearCache(),e.clearSystemEntityCaches();var v=u.resolveAllReferences(),g=u.getUnresolvedCount();g>0&&console.warn("[SceneSerializer] "+g+" EntityRef(s) could not be resolved. Resolved: "+v+", Total pending: "+u.getPendingCount()),i.sceneData&&this.deserializeSceneData(i.sceneData,e.sceneData);for(var y,_=[],S=s(f.values());!(y=S()).done;){var C=y.value;this.callOnDeserializedForEntity(C,_)}_.length>0&&Promise.all(_).catch(function(e){console.error("Error in onDeserialized:",e)})},e.callOnDeserializedForEntity=function(e,t){for(var n,i=s(e.components);!(n=i()).done;){var r=n.value;try{var o=r.onDeserialized();o instanceof Promise&&t.push(o)}catch(e){console.error("Error calling onDeserialized on component "+r.constructor.name+":",e)}}},e.addChildrenRecursively=function(e,t,n,i){var r=e.getComponent(exports.HierarchyComponent);if(r&&0!==r.childIds.length)for(var o,a=s(r.childIds);!(o=a()).done;){var c,u=o.value,l=null!==(c=null==i?void 0:i.get(u))&&void 0!==c?c:t.findEntityById(u);l&&(t.addEntity(l,!0),this.addChildrenRecursively(l,t,n,i))}},e.serializeSceneData=function(e){for(var t,n={},i=s(e);!(t=i()).done;){var r=t.value,o=r[0],a=r[1];n[o]=Ot.serialize(a)}return n},e.deserializeSceneData=function(e,t){t.clear();for(var n=0,i=Object.entries(e);n<i.length;n++){var r=i[n],o=r[0],s=r[1];t.set(o,Ot.deserialize(s))}},e.filterEntities=function(e,t){var n=Array.from(e.entities.buffer);if(t.components&&t.components.length>0){var i=new Set(t.components);return n.filter(function(e){return Array.from(e.components).some(function(e){return i.has(e.constructor)})})}return n},e.buildComponentTypeRegistry=function(e){for(var t,n=new Map,i=s(e);!(t=i()).done;)for(var r,o=s(t.value.components);!(r=o()).done;){var a=r.value,c=L(a.constructor),u=De(a);u&&!n.has(c)&&n.set(c,u.options.version)}return Array.from(n.entries()).map(function(e){return{typeName:e[0],version:e[1]}})},e.getGlobalComponentRegistry=function(){return K.getAllComponentNames()},e.validate=function(e){var t=[];try{var n=JSON.parse(e);return n.version||t.push("Missing version field"),n.entities&&Array.isArray(n.entities)||t.push("Missing or invalid entities field"),n.componentTypeRegistry&&Array.isArray(n.componentTypeRegistry)||t.push("Missing or invalid componentTypeRegistry field"),a({valid:0===t.length,version:n.version},t.length>0&&{errors:t})}catch(e){return{valid:!1,errors:["JSON parse error: "+e]}}},e.getInfo=function(e){try{var t,n=JSON.parse(e);return a({name:n.name,version:n.version},void 0!==n.timestamp&&{timestamp:n.timestamp},{entityCount:(null===(t=n.metadata)||void 0===t?void 0:t.entityCount)||n.entities.length,componentTypeCount:n.componentTypeRegistry.length})}catch(e){return null}},e}();Bt.SERIALIZATION_VERSION=1,exports.ChangeOperation=void 0,(Pt=exports.ChangeOperation||(exports.ChangeOperation={})).EntityAdded="entity_added",Pt.EntityRemoved="entity_removed",Pt.EntityUpdated="entity_updated",Pt.ComponentAdded="component_added",Pt.ComponentRemoved="component_removed",Pt.ComponentUpdated="component_updated",Pt.SceneDataUpdated="scene_data_updated";var Lt=function(){function e(){}return e.createSnapshot=function(e,t){for(var n,i=a({deepComponentComparison:!0,trackSceneData:!0,compressSnapshot:!1},t),r={version:++this.snapshotVersion,entityIds:new Set,entities:new Map,components:new Map,sceneData:new Map},o=s(e.entities.buffer);!(n=o()).done;){var c=n.value;r.entityIds.add(c.id);var u=c.getComponent(exports.HierarchyComponent),l=null==u?void 0:u.parentId;if(r.entities.set(c.id,a({name:c.name,tag:c.tag,active:c.active,enabled:c.enabled,updateOrder:c.updateOrder},null!=l&&{parentId:l})),i.deepComponentComparison){for(var h,d=new Map,f=s(c.components);!(h=f()).done;){var p=h.value,m=Rt.serialize(p);m&&d.set(m.type,JSON.stringify(m.data))}d.size>0&&r.components.set(c.id,d)}}if(i.trackSceneData)for(var v,g=s(e.sceneData);!(v=g()).done;){var y=v.value,_=y[0],S=y[1];r.sceneData.set(_,JSON.stringify(S))}return r},e.computeIncremental=function(e,t,n){for(var i,r=a({deepComponentComparison:!0,trackSceneData:!0},n),o={version:++this.snapshotVersion,timestamp:Date.now(),sceneName:e.name,baseVersion:t.version,entityChanges:[],componentChanges:[],sceneDataChanges:[]},c=new Set,u=s(e.entities.buffer);!(i=u()).done;){var l=i.value;c.add(l.id);var h=l.getComponent(exports.HierarchyComponent),d=null==h?void 0:h.parentId;if(t.entityIds.has(l.id)){var f=t.entities.get(l.id);(f.name!==l.name||f.tag!==l.tag||f.active!==l.active||f.enabled!==l.enabled||f.updateOrder!==l.updateOrder||f.parentId!==d)&&o.entityChanges.push({operation:exports.ChangeOperation.EntityUpdated,entityId:l.id,entityData:a({name:l.name,tag:l.tag,active:l.active,enabled:l.enabled,updateOrder:l.updateOrder},null!=d&&{parentId:d})}),r.deepComponentComparison&&this.detectComponentChanges(l,t,o.componentChanges)}else{o.entityChanges.push({operation:exports.ChangeOperation.EntityAdded,entityId:l.id,entityName:l.name,entityData:a({id:l.id,name:l.name,tag:l.tag,active:l.active,enabled:l.enabled,updateOrder:l.updateOrder},null!=d&&{parentId:d},{components:[],children:[]})});for(var p,m=s(l.components);!(p=m()).done;){var v=p.value,g=Rt.serialize(v);g&&o.componentChanges.push({operation:exports.ChangeOperation.ComponentAdded,entityId:l.id,componentType:g.type,componentData:g})}}}for(var y,_=s(t.entityIds);!(y=_()).done;){var S=y.value;c.has(S)||o.entityChanges.push({operation:exports.ChangeOperation.EntityRemoved,entityId:S})}return r.trackSceneData&&this.detectSceneDataChanges(e,t,o.sceneDataChanges),o},e.detectComponentChanges=function(e,t,n){for(var i,r=t.components.get(e.id),o=new Map,a=s(e.components);!(i=a()).done;){var c=i.value,u=Rt.serialize(c);u&&o.set(u.type,u)}for(var l,h=s(o);!(l=h()).done;){var d=l.value,f=d[0],p=d[1],m=JSON.stringify(p.data);r&&r.has(f)?r.get(f)!==m&&n.push({operation:exports.ChangeOperation.ComponentUpdated,entityId:e.id,componentType:f,componentData:p}):n.push({operation:exports.ChangeOperation.ComponentAdded,entityId:e.id,componentType:f,componentData:p})}if(r)for(var v,g=s(r.keys());!(v=g()).done;){var y=v.value;o.has(y)||n.push({operation:exports.ChangeOperation.ComponentRemoved,entityId:e.id,componentType:y})}},e.detectSceneDataChanges=function(e,t,n){for(var i,r=new Set,o=s(e.sceneData);!(i=o()).done;){var a=i.value,c=a[0],u=a[1];r.add(c);var l=JSON.stringify(u),h=t.sceneData.get(c);h&&h===l||n.push({operation:exports.ChangeOperation.SceneDataUpdated,key:c,value:u})}for(var d,f=s(t.sceneData.keys());!(d=f()).done;){var p=d.value;r.has(p)||n.push({operation:exports.ChangeOperation.SceneDataUpdated,key:p,value:void 0,deleted:!0})}},e.applyIncremental=function(e,t,n){for(var i,r=s(t.entityChanges);!(i=r()).done;){var o=i.value;switch(o.operation){case exports.ChangeOperation.EntityAdded:this.applyEntityAdded(e,o);break;case exports.ChangeOperation.EntityRemoved:this.applyEntityRemoved(e,o);break;case exports.ChangeOperation.EntityUpdated:this.applyEntityUpdated(e,o)}}for(var a,c=s(t.componentChanges);!(a=c()).done;){var u=a.value;switch(u.operation){case exports.ChangeOperation.ComponentAdded:this.applyComponentAdded(e,u,n);break;case exports.ChangeOperation.ComponentRemoved:this.applyComponentRemoved(e,u,n);break;case exports.ChangeOperation.ComponentUpdated:this.applyComponentUpdated(e,u,n)}}for(var l,h=s(t.sceneDataChanges);!(l=h()).done;){var d=l.value;d.deleted?e.sceneData.delete(d.key):e.sceneData.set(d.key,d.value)}},e.applyEntityAdded=function(e,t){var n,i;if(t.entityData){var r=new lt(t.entityName||"Entity",t.entityId);r.tag=t.entityData.tag||0,r.active=null===(n=t.entityData.active)||void 0===n||n,r.enabled=null===(i=t.entityData.enabled)||void 0===i||i,r.updateOrder=t.entityData.updateOrder||0,e.addEntity(r)}},e.applyEntityRemoved=function(e,t){var n=e.entities.findEntityById(t.entityId);n&&n.destroy()},e.applyEntityUpdated=function(e,t){if(t.entityData){var n=e.entities.findEntityById(t.entityId);if(n){void 0!==t.entityData.name&&(n.name=t.entityData.name),void 0!==t.entityData.tag&&(n.tag=t.entityData.tag),void 0!==t.entityData.active&&(n.active=t.entityData.active),void 0!==t.entityData.enabled&&(n.enabled=t.entityData.enabled),void 0!==t.entityData.updateOrder&&(n.updateOrder=t.entityData.updateOrder);var i=e.getSystem(He);if(i){var r=n.getComponent(exports.HierarchyComponent),o=null==r?void 0:r.parentId;if(void 0!==t.entityData.parentId){var s=e.entities.findEntityById(t.entityData.parentId);s&&o!==t.entityData.parentId&&i.setParent(n,s)}else null!=o&&i.setParent(n,null)}}}},e.applyComponentAdded=function(e,t,n){if(t.componentData){var i=e.entities.findEntityById(t.entityId);if(i){var r=Rt.deserialize(t.componentData,n);r&&i.addComponent(r)}}},e.applyComponentRemoved=function(e,t,n){var i=e.entities.findEntityById(t.entityId);if(i){var r=n.get(t.componentType);r&&i.removeComponentByType(r)}},e.applyComponentUpdated=function(e,t,n){if(t.componentData){var i=e.entities.findEntityById(t.entityId);if(i){var r=n.get(t.componentType);if(r){i.removeComponentByType(r);var o=Rt.deserialize(t.componentData,n);o&&i.addComponent(o)}}}},e.serializeIncremental=function(e,t){var n=a({format:"json",pretty:!1},t);return"binary"===n.format?Nt.encode(e):n.pretty?JSON.stringify(e,null,2):JSON.stringify(e)},e.deserializeIncremental=function(e){return"string"==typeof e?JSON.parse(e):Nt.decode(e)},e.getIncrementalStats=function(e){return{totalChanges:e.entityChanges.length+e.componentChanges.length+e.sceneDataChanges.length,entityChanges:e.entityChanges.length,componentChanges:e.componentChanges.length,sceneDataChanges:e.sceneDataChanges.length,addedEntities:e.entityChanges.filter(function(e){return e.operation===exports.ChangeOperation.EntityAdded}).length,removedEntities:e.entityChanges.filter(function(e){return e.operation===exports.ChangeOperation.EntityRemoved}).length,updatedEntities:e.entityChanges.filter(function(e){return e.operation===exports.ChangeOperation.EntityUpdated}).length,addedComponents:e.componentChanges.filter(function(e){return e.operation===exports.ChangeOperation.ComponentAdded}).length,removedComponents:e.componentChanges.filter(function(e){return e.operation===exports.ChangeOperation.ComponentRemoved}).length,updatedComponents:e.componentChanges.filter(function(e){return e.operation===exports.ChangeOperation.ComponentUpdated}).length}},e.resetVersion=function(){this.snapshotVersion=0},e}();Lt.snapshotVersion=0;var Ht={enabled:!0,sampleInterval:10,minDuration:.1,trackAsync:!0,excludePatterns:[/^_/,/^get[A-Z]/,/^set[A-Z]/,/^is[A-Z]/,/^has[A-Z]/],maxBufferSize:1e4},Wt=function(){function e(e){this.wrappedObjects=new WeakMap,this.samplingProfiler=null,this.registeredClasses=new Map,this.config=a({},Ht,e)}e.getInstance=function(t){return e.instance||(e.instance=new e(t)),e.instance},e.resetInstance=function(){e.instance&&(e.instance.dispose(),e.instance=null)},e.setEnabled=function(t){e.getInstance().setEnabled(t)},e.registerClass=function(t,n,i){return void 0===n&&(n=exports.ProfileCategory.Custom),e.getInstance().registerClass(t,n,i)},e.wrapInstance=function(t,n,i){return void 0===i&&(i=exports.ProfileCategory.Custom),e.getInstance().wrapInstance(t,n,i)},e.wrapFunction=function(t,n,i){return void 0===i&&(i=exports.ProfileCategory.Custom),e.getInstance().wrapFunction(t,n,i)},e.startSampling=function(){e.getInstance().startSampling()},e.stopSampling=function(){return e.getInstance().stopSampling()};var t=e.prototype;return t.setEnabled=function(e){this.config.enabled=e,!e&&this.samplingProfiler&&this.samplingProfiler.stop()},t.registerClass=function(e,t,n){void 0===t&&(t=exports.ProfileCategory.Custom);var i=n||e.name;this.registeredClasses.set(i,{constructor:e,category:t});var r=this;return new Proxy(e,{construct:function(e,n,o){var s=Reflect.construct(e,n,o);return r.config.enabled&&r.wrapInstance(s,i,t),s}})},t.wrapInstance=function(e,t,n){if(void 0===n&&(n=exports.ProfileCategory.Custom),!this.config.enabled)return e;if(this.wrappedObjects.has(e))return e;var i=new Map;this.wrappedObjects.set(e,i);for(var r,o=s(this.getAllMethodNames(e));!(r=o()).done;){var a=r.value;if(!this.shouldExcludeMethod(a)){var c=this.getPropertyDescriptor(e,a);if(c&&"function"==typeof c.value){var u=c.value,l=this.createWrappedMethod(u,t,a,n);i.set(a,{className:t,methodName:a,category:n,original:u});try{e[a]=l}catch(e){}}}}return e},t.wrapFunction=function(e,t,n){if(void 0===n&&(n=exports.ProfileCategory.Custom),!this.config.enabled)return e;var i=this,r=function(){var r=Ke.beginSample(t,n);try{for(var o=arguments.length,s=new Array(o),a=0;a<o;a++)s[a]=arguments[a];var c=e.apply(this,s);return i.config.trackAsync&&c instanceof Promise?c.finally(function(){Ke.endSample(r)}):(Ke.endSample(r),c)}catch(e){throw Ke.endSample(r),e}};return Object.defineProperty(r,"name",{value:e.name||t}),Object.defineProperty(r,"length",{value:e.length}),r},t.startSampling=function(){this.samplingProfiler||(this.samplingProfiler=new Gt(this.config)),this.samplingProfiler.start()},t.stopSampling=function(){return this.samplingProfiler?this.samplingProfiler.stop():[]},t.dispose=function(){this.samplingProfiler&&(this.samplingProfiler.stop(),this.samplingProfiler=null),this.registeredClasses.clear()},t.createWrappedMethod=function(e,t,n,i){var r=this,o=t+"."+n,s=this.config.minDuration;return function(){for(var t=arguments.length,n=new Array(t),a=0;a<t;a++)n[a]=arguments[a];if(!r.config.enabled||!Ke.isEnabled())return e.apply(this,n);var c=performance.now(),u=Ke.beginSample(o,i);try{var l=e.apply(this,n);return r.config.trackAsync&&l instanceof Promise?l.then(function(e){return performance.now()-c>=s&&Ke.endSample(u),e},function(e){throw Ke.endSample(u),e}):(performance.now()-c>=s&&Ke.endSample(u),l)}catch(e){throw Ke.endSample(u),e}}},t.getAllMethodNames=function(e){for(var t=new Set,n=e;n&&n!==Object.prototype;){for(var i,r=s(Object.getOwnPropertyNames(n));!(i=r()).done;){var o=i.value;"constructor"!==o&&t.add(o)}n=Object.getPrototypeOf(n)}return Array.from(t)},t.getPropertyDescriptor=function(e,t){for(var n=e;n&&n!==Object.prototype;){var i=Object.getOwnPropertyDescriptor(n,t);if(i)return i;n=Object.getPrototypeOf(n)}},t.shouldExcludeMethod=function(e){if("constructor"===e||e.startsWith("__"))return!0;for(var t,n=s(this.config.excludePatterns);!(t=n()).done;){if(t.value.test(e))return!0}return!1},e}();Wt.instance=null;var Gt=function(){function e(e){this.samples=[],this.intervalId=null,this.isRunning=!1,this.config=e}var t=e.prototype;return t.start=function(){var e=this;if(!this.isRunning){this.isRunning=!0,this.samples=[];var t=function(){if(e.isRunning){var n=e.captureStack();n.length>0&&(e.samples.push({timestamp:performance.now(),stack:n}),e.samples.length>e.config.maxBufferSize&&e.samples.shift()),e.config.sampleInterval,e.intervalId=setTimeout(t,e.config.sampleInterval)}};t()}},t.stop=function(){return this.isRunning=!1,null!==this.intervalId&&(clearTimeout(this.intervalId),this.intervalId=null),[].concat(this.samples)},t.captureStack=function(){try{for(var e,t=((new Error).stack||"").split("\n").slice(3),n=[],i=s(t);!(e=i()).done;){var r=e.value,o=this.parseStackFrame(r);o&&!this.isInternalFrame(o)&&n.push(o)}return n}catch(e){return[]}},t.parseStackFrame=function(e){var t=(e=e.trim()).match(/at\s+(.+?)\s+\(/);if(t&&t[1])return t[1];if((t=e.match(/at\s+(.+)/))&&t[1]){var n=t[1];if(!n.includes("("))return n}return(t=e.match(/^(.+?)@/))&&t[1]?t[1]:null},t.isInternalFrame=function(e){return["SamplingProfiler","AutoProfiler","ProfilerSDK","setTimeout","setInterval","requestAnimationFrame","<anonymous>","eval"].some(function(t){return e.includes(t)})},e}();var jt,Ut=J("ServiceContainer");exports.ServiceLifetime=void 0,(jt=exports.ServiceLifetime||(exports.ServiceLifetime={})).Singleton="singleton",jt.Transient="transient";var qt=function(){function e(){this._services=new Map,this._resolving=new Set,this._updatableServices=[]}var t=e.prototype;return t.registerSingleton=function(e,t){this._services.has(e)?Ut.warn("Service "+e.name+" is already registered"):(this._services.set(e,a({identifier:e,type:e},t&&{factory:t},{lifetime:exports.ServiceLifetime.Singleton})),Ut.debug("Registered singleton service: "+e.name))},t.registerTransient=function(e,t){this._services.has(e)?Ut.warn("Service "+e.name+" is already registered"):(this._services.set(e,a({identifier:e,type:e},t&&{factory:t},{lifetime:exports.ServiceLifetime.Transient})),Ut.debug("Registered transient service: "+e.name))},t.registerInstance=function(e,t){if(this._services.has(e)){var n="symbol"==typeof e?e.description:e.name;Ut.warn("Service "+n+" is already registered")}else{if(this._services.set(e,{identifier:e,instance:t,lifetime:exports.ServiceLifetime.Singleton}),"symbol"!=typeof e&&A(e)){var i,r=k(e),o=null!==(i=null==r?void 0:r.priority)&&void 0!==i?i:0;this._updatableServices.push({instance:t,priority:o}),this._updatableServices.sort(function(e,t){return e.priority-t.priority}),Ut.debug("Service "+e.name+" is updatable (priority: "+o+"), added to update list")}var s="symbol"==typeof e?e.description:e.name;Ut.debug("Registered service instance: "+s)}},t.resolve=function(e){var t=this._services.get(e),n="symbol"==typeof e?e.description:e.name;if(!t)throw new Error("Service "+n+" is not registered");if(this._resolving.has(e)){var i=Array.from(this._resolving).map(function(e){return"symbol"==typeof e?e.description:e.name}).join(" -> ");throw new Error("Circular dependency detected: "+i+" -> "+n)}if(t.lifetime===exports.ServiceLifetime.Singleton&&t.instance)return t.instance;this._resolving.add(e);try{var r;if(t.factory)r=t.factory(this);else{if(!t.type)throw new Error("Service "+n+" has no factory or type to construct");r=new t.type}if(t.lifetime===exports.ServiceLifetime.Singleton&&(t.instance=r,t.type&&A(t.type))){var o,s=k(t.type),a=null!==(o=null==s?void 0:s.priority)&&void 0!==o?o:0;this._updatableServices.push({instance:r,priority:a}),this._updatableServices.sort(function(e,t){return e.priority-t.priority}),Ut.debug("Service "+n+" is updatable (priority: "+a+"), added to update list")}return r}finally{this._resolving.delete(e)}},t.tryResolve=function(e){try{return this.resolve(e)}catch(e){return null}},t.isRegistered=function(e){return this._services.has(e)},t.unregister=function(e){var t=this._services.get(e);if(!t)return!1;if(t.instance){var n=this._updatableServices.findIndex(function(e){return e.instance===t.instance});-1!==n&&this._updatableServices.splice(n,1),t.instance.dispose()}this._services.delete(e);var i="symbol"==typeof e?e.description:e.name;return Ut.debug("Unregistered service: "+i),!0},t.clear=function(){for(var e,t=s(this._services);!(e=t()).done;){var n=e.value[1];n.instance&&n.instance.dispose()}this._services.clear(),this._updatableServices=[],Ut.debug("Cleared all services")},t.getRegisteredServices=function(){return Array.from(this._services.keys())},t.updateAll=function(e){for(var t,n=s(this._updatableServices);!(t=n()).done;){t.value.instance.update(e)}},t.getUpdatableCount=function(){return this._updatableServices.length},t.getAll=function(){for(var e,t=[],n=s(this._services.values());!(e=n()).done;){var i=e.value;i.instance&&t.push(i.instance)}return t},e}(),Qt=function(e){function t(n){var i,r="[SystemDependencyGraph] 检测到循环依赖 | Cycle dependency detected: "+n.join(" -> ");return(i=e.call(this,r)||this).name="CycleDependencyError",i.involvedNodes=n,Object.setPrototypeOf(i,(this instanceof t?this.constructor:void 0).prototype),i}return u(t,e),t}(m(Error)),Vt="set:",Yt=function(){function e(){this._nodes=new Map}var t=e.prototype;return t.addSystemNode=function(e){this.getOrCreateNode(e,!1)},t.addSetNode=function(e){var t=Vt+e;this.getOrCreateNode(t,!0)},t.addEdge=function(e,t){if(e!==t){var n=this.getOrCreateNode(e,e.startsWith(Vt)),i=this.getOrCreateNode(t,t.startsWith(Vt));n.outEdges.add(t),i.inEdges.add(e)}},t.buildFromSystems=function(e){this.clear();for(var t,n=s(e);!(t=n()).done;){var i=t.value;this.addSystemNode(i.name);for(var r,o=s(i.sets);!(r=o()).done;){var a=r.value;this.addSetNode(a)}}for(var c,u=s(e);!(c=u()).done;){for(var l,h=c.value,d=s(h.sets);!(l=d()).done;){var f=l.value,p=Vt+f;this.addEdge(p,h.name)}for(var m,v=s(h.before);!(m=v()).done;){var g=m.value,y=this.resolveTargetId(g);this.addEdge(h.name,y)}for(var _,S=s(h.after);!(_=S()).done;){var C=_.value,E=this.resolveTargetId(C);this.addEdge(E,h.name)}}},t.topologicalSort=function(){for(var e,t=new Map,n=s(this._nodes);!(e=n()).done;){var i=e.value,r=i[0],o=i[1];t.set(r,o.inEdges.size)}for(var a,c=[],u=s(t);!(a=u()).done;){var l=a.value,h=l[0];0===l[1]&&c.push(h)}for(var d=[],f=0;c.length>0;){var p=c.shift();f++;var m=this._nodes.get(p);if(m){m.bIsVirtual||d.push(p);for(var v,g=s(m.outEdges);!(v=g()).done;){var y,_=v.value,S=(null!==(y=t.get(_))&&void 0!==y?y:0)-1;t.set(_,S),0===S&&c.push(_)}}}if(f<this._nodes.size){for(var C,E=[],b=s(t);!(C=b()).done;){var T=C.value,w=T[0];T[1]>0&&E.push(w)}throw new Qt(E)}return d},t.clear=function(){this._nodes.clear()},t.getOrCreateNode=function(e,t){var n=this._nodes.get(e);return n||(n={id:e,bIsVirtual:t,inEdges:new Set,outEdges:new Set},this._nodes.set(e,n)),n},t.resolveTargetId=function(e){return e.startsWith(Vt),e},o(e,[{key:"size",get:function(){return this._nodes.size}}])}(),Jt=["startup","preUpdate","update","postUpdate","cleanup"],Zt=function(){function e(){this._sortedByStage=new Map,this._dirty=!0,this._graph=new Yt,this._useDependencySort=!0}var t=e.prototype;return t.setUseDependencySort=function(e){this._useDependencySort!==e&&(this._useDependencySort=e,this._dirty=!0)},t.markDirty=function(){this._dirty=!0},t.getSortedSystems=function(e,t){var n;if(this.ensureBuilt(e),t)return null!==(n=this._sortedByStage.get(t))&&void 0!==n?n:[];for(var i=[],r=0,o=Jt;r<o.length;r++){var s=o[r],a=this._sortedByStage.get(s);a&&i.push.apply(i,a)}return i},t.getAllSortedSystems=function(e){return this.getSortedSystems(e)},t.ensureBuilt=function(e){this._dirty&&(this._sortedByStage.clear(),this._useDependencySort&&this.hasDependencies(e)?this.buildWithDependencyGraph(e):this.buildWithUpdateOrder(e),this._dirty=!1)},t.hasDependencies=function(e){for(var t,n=s(e);!(t=n()).done;){var i=t.value,r=this.getSchedulingMetadata(i);if(r.before.length>0||r.after.length>0||r.sets.length>0)return!0;if("update"!==r.stage)return!0}return!1},t.buildWithUpdateOrder=function(e){var t=[].concat(e).sort(function(e,t){var n=e.updateOrder-t.updateOrder;return 0!==n?n:e.addOrder-t.addOrder});this._sortedByStage.set("update",t)},t.buildWithDependencyGraph=function(e){for(var t=new Map,n=0,i=Jt;n<i.length;n++){var r=i[n];t.set(r,[])}for(var o,a=s(e);!(o=a()).done;){var c=o.value,u=this.getSchedulingMetadata(c).stage,l=t.get(u);l?l.push(c):t.get("update").push(c)}for(var h,d=s(t);!(h=d()).done;){var f=h.value,p=f[0],m=f[1];if(0!==m.length){var v=this.sortSystemsInStage(m);this._sortedByStage.set(p,v)}else this._sortedByStage.set(p,[])}},t.sortSystemsInStage=function(e){for(var t,n=new Map,i=[],r=s(e);!(t=r()).done;){var o=t.value,a=o.systemName;n.set(a,o);var c=this.getSchedulingMetadata(o);i.push({name:a,before:c.before,after:c.after,sets:c.sets})}this._graph.buildFromSystems(i);try{for(var u,l=this._graph.topologicalSort(),h=[],d=s(l);!(u=d()).done;){var f=u.value,p=n.get(f);p&&h.push(p)}return this.stableSortByUpdateOrder(h)}catch(t){if(t instanceof Qt)throw t;return console.warn("[SystemScheduler] 拓扑排序失败,回退到 updateOrder 排序",t),this.fallbackSort(e)}},t.stableSortByUpdateOrder=function(e){return e},t.fallbackSort=function(e){return[].concat(e).sort(function(e,t){var n=e.updateOrder-t.updateOrder;return 0!==n?n:e.addOrder-t.addOrder})},t.getSchedulingMetadata=function(e){return{stage:e.getStage(),before:[].concat(e.getBefore()),after:[].concat(e.getAfter()),sets:[].concat(e.getSets())}},e}(),Xt=function(){function e(e){void 0===e&&(e=1024),this._freeList=[],this._nextIndex=1,this._aliveCount=0,this._capacity=e,this._generations=new Uint32Array(e),this._alive=new Uint8Array(e),this._enabled=new Uint8Array(e),this._alive[0]=0,this._enabled[0]=0}var t=e.prototype;return t.create=function(){var e;this._freeList.length>0?e=this._freeList.pop():(e=this._nextIndex++)>=this._capacity&&this.grow(e);var t=this._generations[e];return this._alive[e]=1,this._enabled[e]=1,this._aliveCount++,ot(e,t)},t.destroy=function(e){var t=st(e),n=at(e);if(t>=this._capacity||0===t)return!1;if(this._generations[t]!==n)return!1;if(1!==this._alive[t])return!1;this._alive[t]=0,this._enabled[t]=0,this._aliveCount--;var i=(n+1)%rt;return this._generations[t]=i,this._freeList.push(t),!0},t.isAlive=function(e){var t=st(e),n=at(e);return!(t>=this._capacity||0===t)&&(1===this._alive[t]&&this._generations[t]===n)},t.isEnabled=function(e){if(!this.isAlive(e))return!1;var t=st(e);return 1===this._enabled[t]},t.setEnabled=function(e,t){if(!this.isAlive(e))return!1;var n=st(e);return this._enabled[n]=t?1:0,!0},t.validate=function(e){return this.isAlive(e)},t.grow=function(e){for(var t=this._capacity;t<=e;)t<<=1;if(t>it&&e>=(t=it))throw new Error("EntityHandleManager: 超过最大实体数量 "+it);var n=new Uint32Array(t),i=new Uint8Array(t),r=new Uint8Array(t);n.set(this._generations),i.set(this._alive),r.set(this._enabled),this._generations=n,this._alive=i,this._enabled=r,this._capacity=t},t.reset=function(){this._generations.fill(0),this._alive.fill(0),this._enabled.fill(0),this._freeList.length=0,this._nextIndex=1,this._aliveCount=0},t.forEach=function(e){for(var t=1;t<this._nextIndex;t++){if(1===this._alive[t])e(ot(t,this._generations[t]))}},t.getAllAlive=function(){var e=[];return this.forEach(function(t){return e.push(t)}),e},o(e,[{key:"aliveCount",get:function(){return this._aliveCount}},{key:"capacity",get:function(){return this._capacity}}])}(),Kt=function(){function e(){this._current=1}var t=e.prototype;return t.increment=function(){this._current++,this._current>=Number.MAX_SAFE_INTEGER&&(this._current=1)},t.reset=function(){this._current=1},t.isChangedSince=function(e,t){return e>t},o(e,[{key:"current",get:function(){return this._current}}])}(),$t=function(){function e(e){this.name="",this.sceneData=new Map,this._handleToEntity=new Map,this.epochManager=new Kt,this._performanceMonitor=null,this._didSceneBegin=!1,this.isEditorMode=!1,this._deferredComponentCallbacks=[],this._cachedSystems=null,this._systemsOrderDirty=!0,this._systemErrorCount=new Map,this._maxErrorCount=10,this._systemAddCounter=0,this._systemScheduler=new Zt,this._componentIdToSystems=new Map,this._globalNotifySystems=new Set,this.entities=new ht(this),this.identifierPool=new dt,this.componentStorageManager=new ze,this.componentRegistry=new X,!1!==(null==e?void 0:e.inheritGlobalRegistry)&&this.componentRegistry.cloneFrom(K),this.querySystem=new wt,this.eventSystem=new xt,this.referenceTracker=new ue,this.handleManager=new Xt,this._services=new qt,this.logger=J("Scene"),null!=e&&e.name&&(this.name=e.name)}var t=e.prototype;return t._rebuildSystemsCache=function(){var e=this._services.getAll(),t=this._filterEntitySystems(e);try{return this._systemScheduler.markDirty(),this._systemScheduler.getAllSortedSystems(t)}catch(e){return e instanceof Qt?this.logger.error("[Scene] 系统存在循环依赖,回退到 updateOrder 排序 | Cycle dependency detected, falling back to updateOrder sort",e.involvedNodes):this.logger.error("[Scene] 系统排序失败 | System sorting failed",e),this._sortSystemsByUpdateOrder(t)}},t._filterEntitySystems=function(e){return e.filter(function(e){return e instanceof Le})},t._sortSystemsByUpdateOrder=function(e){return e.sort(function(e,t){var n=e.updateOrder-t.updateOrder;return 0!==n?n:e.addOrder-t.addOrder})},t.getSystem=function(e){return this._services.tryResolve(e)},t.markSystemsOrderDirty=function(){this._systemsOrderDirty=!0},t.initialize=function(){},t.onStart=function(){},t.unload=function(){},t.queueDeferredComponentCallback=function(e){this._deferredComponentCallbacks.push(e)},t.begin=function(){if(this._didSceneBegin=!0,this._deferredComponentCallbacks.length>0){for(var e,t=s(this._deferredComponentCallbacks);!(e=t()).done;){var n=e.value;try{n()}catch(e){this.logger.error("Error executing deferred component callback:",e)}}this._deferredComponentCallbacks=[]}this.onStart()},t.end=function(){this._didSceneBegin=!1,this.unload(),this.entities.removeAllEntities(),this.querySystem.setEntities([]),this.componentStorageManager.clear(),this._services.clear(),this._cachedSystems=null,this._systemsOrderDirty=!0,this._componentIdToSystems.clear(),this._globalNotifySystems.clear(),this._handleToEntity.clear(),this.handleManager.reset(),this.epochManager.reset()},t.update=function(){this.epochManager.increment(),Ke.beginFrame();var e=Ke.beginSample("Scene.update",exports.ProfileCategory.ECS);try{qe.getInstance().update(),this.entities.updateLists();var t=this.systems,n=Ke.beginSample("Systems.update",exports.ProfileCategory.ECS);try{for(var i,r=s(t);!(i=r()).done;){var o=i.value;if(this._shouldSystemRun(o)){var a=Ke.beginSample(o.systemName,exports.ProfileCategory.ECS);try{o.update()}catch(e){this._handleSystemError(o,"update",e)}finally{Ke.endSample(a)}}}}finally{Ke.endSample(n)}var c=Ke.beginSample("Systems.lateUpdate",exports.ProfileCategory.ECS);try{for(var u,l=s(t);!(u=l()).done;){var h=u.value;if(this._shouldSystemRun(h)){var d=Ke.beginSample(h.systemName+".late",exports.ProfileCategory.ECS);try{h.lateUpdate()}catch(e){this._handleSystemError(h,"lateUpdate",e)}finally{Ke.endSample(d)}}}}finally{Ke.endSample(c)}this.flushCommandBuffers(t)}finally{Ke.endSample(e),Ke.endFrame()}},t._shouldSystemRun=function(e){if(!e.enabled)return!1;if(!this.isEditorMode)return!0;var t=ne(e);return!1!==(null==t?void 0:t.runInEditMode)},t.flushCommandBuffers=function(e){var t=Ke.beginSample("Scene.flushCommandBuffers",exports.ProfileCategory.ECS);try{for(var n,i=s(e);!(n=i()).done;){var r=n.value;try{r.flushCommands()}catch(e){this.logger.error("Error flushing commands for system "+r.systemName+":",e)}}}finally{Ke.endSample(t)}},t._handleSystemError=function(e,t,n){var i=(this._systemErrorCount.get(e)||0)+1;this._systemErrorCount.set(e,i),this.logger.error("Error in system "+e.constructor.name+"."+t+"() ["+i+"/"+this._maxErrorCount+"]:",n),i>=this._maxErrorCount&&(e.enabled=!1,this.logger.error("System "+e.constructor.name+" has been disabled due to excessive errors ("+i+" errors)"))},t.createEntity=function(e){var t=new lt(e,this.identifierPool.checkOut()),n=this.handleManager.create();return t.setHandle(n),this._handleToEntity.set(n,t),this.eventSystem.emitSync("entity:created",{entityName:e,entity:t,scene:this}),this.addEntity(t)},t.clearSystemEntityCaches=function(){for(var e,t=s(this.systems);!(e=t()).done;){e.value.clearEntityCache()}},t.notifyEntityComponentChanged=function(e,t){var n=new Set;if(t&&this.componentRegistry.isRegistered(t)){var i=this.componentRegistry.getBitIndex(t),r=this._componentIdToSystems.get(i);if(r)for(var o,a=s(r);!(o=a()).done;){var c=o.value;c.handleEntityComponentChanged(e),n.add(c)}}for(var u,l=s(this._globalNotifySystems);!(u=l()).done;){var h=u.value;n.has(h)||(h.handleEntityComponentChanged(e),n.add(h))}if(!t)for(var d,f=s(this.systems);!(d=f()).done;){var p=d.value;n.has(p)||p.handleEntityComponentChanged(e)}},t.indexSystemByComponents=function(e){var t=e.matcher;if(t&&!t.isNothing()){var n=t.getCondition();if((n.none.length>0||void 0!==n.tag||void 0!==n.name)&&this._globalNotifySystems.add(e),t.isEmpty())this._globalNotifySystems.add(e);else{for(var i,r=s(n.all);!(i=r()).done;){var o=i.value;this.addSystemToComponentIndex(o,e)}for(var a,c=s(n.any);!(a=c()).done;){var u=a.value;this.addSystemToComponentIndex(u,e)}n.component&&this.addSystemToComponentIndex(n.component,e)}}},t.addSystemToComponentIndex=function(e,t){var n=this.componentRegistry.getBitIndex(e),i=this._componentIdToSystems.get(n);i||(i=new Set,this._componentIdToSystems.set(n,i)),i.add(t)},t.removeSystemFromIndex=function(e){this._globalNotifySystems.delete(e);for(var t,n=s(this._componentIdToSystems.values());!(t=n()).done;){t.value.delete(e)}},t.addEntity=function(e,t){return void 0===t&&(t=!1),this.entities.add(e),e.scene=this,this.querySystem.addEntity(e,t),t||this.clearSystemEntityCaches(),this.eventSystem.emitSync("entity:added",{entity:e,scene:this}),e},t.createEntities=function(e,t){void 0===t&&(t="Entity");for(var n=[],i=0;i<e;i++){var r=new lt(t+"_"+i,this.identifierPool.checkOut());r.scene=this;var o=this.handleManager.create();r.setHandle(o),this._handleToEntity.set(o,r),n.push(r)}for(var s=0,a=n;s<a.length;s++){var c=a[s];this.entities.add(c)}return this.querySystem.addEntitiesUnchecked(n),this.eventSystem.emitSync("entities:batch_added",{entities:n,scene:this,count:e}),n},t.destroyEntities=function(e){if(0!==e.length){for(var t,n=s(e);!(t=n()).done;){t.value.setDestroyedState(!0)}for(var i,r=s(e);!(i=r()).done;){i.value.removeAllComponents()}for(var o,a=s(e);!(o=a()).done;){var c=o.value;this.entities.remove(c),this.querySystem.removeEntity(c),ct(c.handle)&&(this._handleToEntity.delete(c.handle),this.handleManager.destroy(c.handle))}this.querySystem.clearCache(),this.clearSystemEntityCaches()}},t.destroyAllEntities=function(){this.entities.removeAllEntities(),this.querySystem.setEntities([])},t.findEntity=function(e){return this.entities.findEntity(e)},t.findEntityById=function(e){return this.entities.findEntityById(e)},t.findEntityByHandle=function(e){var t;return ct(e)&&this.handleManager.isAlive(e)&&null!==(t=this._handleToEntity.get(e))&&void 0!==t?t:null},t.findEntitiesByTag=function(e){for(var t,n=[],i=s(this.entities.buffer);!(t=i()).done;){var r=t.value;r.tag===e&&n.push(r)}return n},t.findPersistentEntities=function(){return this.entities.buffer.filter(function(e){return e.isPersistent})},t.extractPersistentEntities=function(){for(var e,t=this.findPersistentEntities(),n=s(t);!(e=n()).done;){var i=e.value;this.entities.remove(i),this.querySystem.removeEntity(i),i.scene=null}return t},t.receiveMigratedEntities=function(e){for(var t,n=s(e);!(t=n()).done;){var i=t.value;i.scene=this,this.entities.add(i),this.querySystem.addEntity(i);for(var r,o=s(i.components);!(r=o()).done;){var a,c=r.value;this.componentStorageManager.addComponent(i.id,c),null===(a=this.referenceTracker)||void 0===a||a.registerEntityScene(i.id,this)}}e.length>0&&this.clearSystemEntityCaches()},t.getEntityByName=function(e){return this.findEntity(e)},t.getEntitiesByTag=function(e){return this.findEntitiesByTag(e)},t.queryAll=function(){var e;return(e=this.querySystem).queryAll.apply(e,arguments)},t.queryAny=function(){var e;return(e=this.querySystem).queryAny.apply(e,arguments)},t.queryNone=function(){var e;return(e=this.querySystem).queryNone.apply(e,arguments)},t.query=function(){return new At},t.addEntityProcessor=function(e){var t,n;if("function"==typeof e){if(n=e,this._services.isRegistered(n)){var i=this._services.resolve(n);return this.logger.debug("System "+n.name+" already registered, returning existing instance"),i}t=I(n)?x(n,this._services):new n}else if(n=(t=e).constructor,this._services.isRegistered(n)){var r=this._services.resolve(n);return r===t?(this.logger.debug("System "+n.name+" instance already registered, returning it"),t):(this.logger.warn("Attempting to register a different instance of "+n.name+", but type is already registered. Returning existing instance."),r)}t.scene=this,t.addOrder=this._systemAddCounter++,t.setPerformanceMonitor(this.performanceMonitor);var o=te(n);return void 0!==(null==o?void 0:o.updateOrder)&&t.setUpdateOrder(o.updateOrder),void 0!==(null==o?void 0:o.enabled)&&(t.enabled=o.enabled),this._services.registerInstance(n,t),this.markSystemsOrderDirty(),this.indexSystemByComponents(t),M(t,this._services),Ke.isEnabled()&&Wt.wrapInstance(t,t.systemName,exports.ProfileCategory.ECS),t.initialize(),this.logger.debug("System "+n.name+" registered and initialized"),t},t.registerSystems=function(e){for(var t,n=[],i=s(e);!(t=i()).done;){var r=t.value,o=this.addEntityProcessor(r);n.push(o)}return n},t.addSystem=function(e){return this.addEntityProcessor(e)},t.removeEntityProcessor=function(e){var t=e.constructor;this._services.unregister(t),this.markSystemsOrderDirty(),this.removeSystemFromIndex(e),e.reset()},t.removeSystem=function(e){this.removeEntityProcessor(e)},t.getEntityProcessor=function(e){return this._services.tryResolve(e)},t.getStats=function(){return{entityCount:this.entities.count,processorCount:this.systems.length,componentStorageStats:this.componentStorageManager.getAllStats()}},t.getDebugInfo=function(){var e=this.systems;return{name:this.name||this.constructor.name,entityCount:this.entities.count,processorCount:e.length,isRunning:this._didSceneBegin,entities:this.entities.buffer.map(function(e){return{name:e.name,id:e.id,componentCount:e.components.length,componentTypes:e.components.map(function(e){return H(e)})}}),processors:e.map(function(e){return{name:re(e),updateOrder:e.updateOrder,entityCount:e.entities.length}}),componentStats:this.componentStorageManager.getAllStats()}},t.serialize=function(e){return Bt.serialize(this,e)},t.deserialize=function(e,t){Bt.deserialize(this,e,t)},t.createIncrementalSnapshot=function(e){this._incrementalBaseSnapshot=Lt.createSnapshot(this,e)},t.serializeIncremental=function(e){if(!this._incrementalBaseSnapshot)throw new Error("必须先调用 createIncrementalSnapshot() 创建基础快照");return Lt.computeIncremental(this,this._incrementalBaseSnapshot,e)},t.applyIncremental=function(e,t){var n="string"==typeof e||e instanceof Uint8Array?Lt.deserializeIncremental(e):e,i=t||this.componentRegistry.getAllComponentNames();Lt.applyIncremental(this,n,i)},t.updateIncrementalSnapshot=function(e){this.createIncrementalSnapshot(e)},t.clearIncrementalSnapshot=function(){this._incrementalBaseSnapshot=void 0},t.hasIncrementalSnapshot=function(){return void 0!==this._incrementalBaseSnapshot},o(e,[{key:"systems",get:function(){return!this._systemsOrderDirty&&this._cachedSystems||(this._cachedSystems=this._rebuildSystemsCache(),this._systemsOrderDirty=!1),this._cachedSystems}},{key:"services",get:function(){return this._services}},{key:"performanceMonitor",get:function(){var e;this._performanceMonitor||(this._performanceMonitor=null!==(e=this._services.tryResolve(D))&&void 0!==e?e:new D);return this._performanceMonitor}}])}(),en=function(){function e(e,t){this.scene=e,this.storageManager=t;var n=e.identifierPool.checkOut();this.entity=new lt("",n),this.entity.scene=this.scene}var t=e.prototype;return t.named=function(e){return this.entity.name=e,this},t.tagged=function(e){return this.entity.tag=e,this},t.with=function(e){return this.entity.addComponent(e),this},t.withComponents=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var i=0,r=t;i<r.length;i++){var o=r[i];this.entity.addComponent(o)}return this},t.withIf=function(e,t){return e&&this.entity.addComponent(t),this},t.withFactory=function(e){var t=e();return this.entity.addComponent(t),this},t.configure=function(e,t){var n=this.entity.getComponent(e);return n&&t(n),this},t.enabled=function(e){return void 0===e&&(e=!0),this.entity.enabled=e,this},t.active=function(e){return void 0===e&&(e=!0),this.entity.active=e,this},t.withChild=function(e){var t=e.build(),n=this.scene.getSystem(He);return null==n||n.setParent(t,this.entity),this},t.withChildren=function(){for(var e=this.scene.getSystem(He),t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];for(var r=0,o=n;r<o.length;r++){var s=o[r].build();null==e||e.setParent(s,this.entity)}return this},t.withChildFactory=function(e){var t=e(this.entity).build(),n=this.scene.getSystem(He);return null==n||n.setParent(t,this.entity),this},t.withChildIf=function(e,t){if(e){var n=t.build(),i=this.scene.getSystem(He);null==i||i.setParent(n,this.entity)}return this},t.build=function(){return this.entity},t.spawn=function(){return this.scene.addEntity(this.entity),this.entity},t.clone=function(){var t=new e(this.scene,this.storageManager);return t.entity=this.entity,t},e}(),tn=function(){function e(){this.scene=new $t}var t=e.prototype;return t.named=function(e){return this.scene.name=e,this},t.withEntity=function(e){return this.scene.addEntity(e),this},t.withEntityBuilder=function(e){var t=e(new en(this.scene,this.scene.componentStorageManager)).build();return this.scene.addEntity(t),this},t.withEntities=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var i=0,r=t;i<r.length;i++){var o=r[i];this.scene.addEntity(o)}return this},t.withSystem=function(e){return this.scene.addSystem(e),this},t.withSystems=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var i=0,r=t;i<r.length;i++){var o=r[i];this.scene.addSystem(o)}return this},t.build=function(){return this.scene},e}(),nn=function(){function e(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];this.component=i(e,n)}var t=e.prototype;return t.set=function(e,t){return this.component[e]=t,this},t.configure=function(e){return e(this.component),this},t.setIf=function(e,t,n){return e&&(this.component[t]=n),this},t.build=function(){return this.component},e}(),rn=function(){function e(e){this.entities=e}var t=e.prototype;return t.addComponent=function(e){for(var t,n=s(this.entities);!(t=n()).done;){t.value.addComponent(e)}return this},t.removeComponent=function(e){for(var t,n=s(this.entities);!(t=n()).done;){t.value.removeComponentByType(e)}return this},t.setActive=function(e){for(var t,n=s(this.entities);!(t=n()).done;){t.value.active=e}return this},t.setTag=function(e){for(var t,n=s(this.entities);!(t=n()).done;){t.value.tag=e}return this},t.forEach=function(e){return this.entities.forEach(e),this},t.filter=function(t){return new e(this.entities.filter(t))},t.toArray=function(){return this.entities.slice()},t.count=function(){return this.entities.length},e}(),on=function(){function e(e,t,n){this.scene=e,this.querySystem=t,this.eventSystem=n}var t=e.prototype;return t.createEntity=function(){return new en(this.scene,this.scene.componentStorageManager)},t.createScene=function(){return new tn},t.createComponent=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return i(nn,[e].concat(n))},t.query=function(){return new It(this.querySystem)},t.find=function(){var e;return(e=this.querySystem).queryAll.apply(e,arguments).entities},t.findFirst=function(){var e,t=(e=this.querySystem).queryAll.apply(e,arguments);return t.entities.length>0?t.entities[0]:null},t.findByName=function(e){return this.scene.findEntity(e)},t.findByTag=function(e){return this.scene.findEntitiesByTag(e)},t.emit=function(e,t){this.eventSystem.emitSync(e,t)},t.emitAsync=function(){var e=n(h().m(function e(t,n){return h().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.eventSystem.emit(t,n);case 1:return e.a(2)}},e,this)}));return function(t,n){return e.apply(this,arguments)}}(),t.on=function(e,t){return this.eventSystem.on(e,t)},t.once=function(e,t){return this.eventSystem.once(e,t)},t.off=function(e,t){this.eventSystem.off(e,t)},t.batch=function(e){return new rn(e)},t.getStats=function(){return{entityCount:this.scene.entities.count,systemCount:this.scene.systems.length,componentStats:this.scene.componentStorageManager.getAllStats(),queryStats:this.querySystem.getStats(),eventStats:this.eventSystem.getStats()}},e}();function sn(e,t,n){return new on(e,t,n)}var an,cn=J("World"),un=function(){function e(e){void 0===e&&(e={}),this._scenes=new Map,this._activeScenes=new Set,this._globalSystems=[],this._isActive=!1,this._config=a({name:"World",debug:!1,maxScenes:10,autoCleanup:!0},e),this.name=this._config.name,this._createdAt=Date.now(),this._services=new qt}var t=e.prototype;return t.createScene=function(e,t){if(!e||"string"!=typeof e||""===e.trim())throw new Error("Scene name不能为空");if(this._scenes.has(e))throw new Error("Scene name '"+e+"' 已存在于World '"+this.name+"' 中");if(this._scenes.size>=this._config.maxScenes)throw new Error("World '"+this.name+"' 已达到最大Scene数量限制: "+this._config.maxScenes);var n=t||new $t;if(this._config.debug){var i=new D;i.enable(),n.services.registerInstance(D,i)}return"id"in n&&(n.id=e),"name"in n&&!n.name&&(n.name=e),this._scenes.set(e,n),n.initialize(),n},t.removeScene=function(e){var t=this._scenes.get(e);return!!t&&(this._activeScenes.has(e)&&this.setSceneActive(e,!1),t.end(),this._scenes.delete(e),cn.info("从World '"+this.name+"' 中移除Scene: "+e),!0)},t.getScene=function(e){return this._scenes.get(e)||null},t.getSceneIds=function(){return Array.from(this._scenes.keys())},t.getAllScenes=function(){return Array.from(this._scenes.values())},t.removeAllScenes=function(){for(var e=0,t=Array.from(this._scenes.keys());e<t.length;e++){var n=t[e];this.removeScene(n)}cn.info("从World '"+this.name+"' 中移除所有Scene")},t.setSceneActive=function(e,t){var n=this._scenes.get(e);n?t?(this._activeScenes.add(e),n.begin&&n.begin(),cn.debug("在World '"+this.name+"' 中激活Scene: "+e)):(this._activeScenes.delete(e),cn.debug("在World '"+this.name+"' 中停用Scene: "+e)):cn.warn("Scene '"+e+"' 不存在于World '"+this.name+"' 中")},t.isSceneActive=function(e){return this._activeScenes.has(e)},t.getActiveSceneCount=function(){return this._activeScenes.size},t.addGlobalSystem=function(e){return this._globalSystems.includes(e)||(this._globalSystems.push(e),e.initialize&&e.initialize(),cn.debug("在World '"+this.name+"' 中添加全局System: "+e.name)),e},t.removeGlobalSystem=function(e){var t=this._globalSystems.indexOf(e);return-1!==t&&(this._globalSystems.splice(t,1),e.reset&&e.reset(),cn.debug("从World '"+this.name+"' 中移除全局System: "+e.name),!0)},t.getGlobalSystem=function(e){for(var t,n=s(this._globalSystems);!(t=n()).done;){var i=t.value;if(i instanceof e)return i}return null},t.start=function(){if(!this._isActive){this._isActive=!0;for(var e,t=s(this._globalSystems);!(e=t()).done;){var n=e.value;n.initialize&&n.initialize()}cn.info("启动World: "+this.name)}},t.stop=function(){if(this._isActive){for(var e,t=s(this._activeScenes);!(e=t()).done;){var n=e.value;this.setSceneActive(n,!1)}for(var i,r=s(this._globalSystems);!(i=r()).done;){var o=i.value;o.reset&&o.reset()}this._isActive=!1,cn.info("停止World: "+this.name)}},t.updateGlobalSystems=function(){if(this._isActive)for(var e,t=s(this._globalSystems);!(e=t()).done;){var n=e.value;n.update&&n.update()}},t.updateScenes=function(){if(this._isActive){for(var e,t=s(this._activeScenes);!(e=t()).done;){var n=e.value,i=this._scenes.get(n);i&&i.update&&i.update()}this._config.autoCleanup&&this.shouldAutoCleanup()&&this.cleanup()}},t.destroy=function(){cn.info("销毁World: "+this.name),this.stop();for(var e=0,t=Array.from(this._scenes.keys());e<t.length;e++){var n=t[e];this.removeScene(n)}for(var i,r=s(this._globalSystems);!(i=r()).done;){var o=i.value;o.destroy?o.destroy():o.reset&&o.reset()}this._globalSystems.length=0,this._services.clear(),this._scenes.clear(),this._activeScenes.clear()},t.getStatus=function(){var e=this;return{name:this.name,isActive:this._isActive,sceneCount:this._scenes.size,activeSceneCount:this._activeScenes.size,globalSystemCount:this._globalSystems.length,createdAt:this._createdAt,config:a({},this._config),scenes:Array.from(this._scenes.keys()).map(function(t){var n;return{id:t,isActive:e._activeScenes.has(t),name:(null===(n=e._scenes.get(t))||void 0===n?void 0:n.name)||t}})}},t.getStats=function(){for(var e,t={totalEntities:0,totalSystems:this._globalSystems.length,memoryUsage:0,performance:{averageUpdateTime:0,maxUpdateTime:0}},n=s(this._scenes.values());!(e=n()).done;){var i=e.value;i.entities&&(t.totalEntities+=i.entities.count),i.systems&&(t.totalSystems+=i.systems.length)}return t},t.shouldAutoCleanup=function(){for(var e,t=Date.now(),n=s(this._scenes);!(e=n()).done;){var i=e.value,r=i[0],o=i[1];if(!this._activeScenes.has(r)&&o.entities&&0===o.entities.count&&t-this._createdAt>3e5)return!0}return!1},t.cleanup=function(){for(var e=Array.from(this._scenes.keys()),t=Date.now(),n=0,i=e;n<i.length;n++){var r=i[n],o=this._scenes.get(r);o&&!this._activeScenes.has(r)&&o.entities&&0===o.entities.count&&t-this._createdAt>3e5&&(this.removeScene(r),cn.debug("自动清理空Scene: "+r+" from World "+this.name))}},o(e,[{key:"services",get:function(){return this._services}},{key:"isActive",get:function(){return this._isActive}},{key:"sceneCount",get:function(){return this._scenes.size}},{key:"createdAt",get:function(){return this._createdAt}}])}(),ln=function(){function e(e){this._nextScene=null,this._ecsAPI=null,this._logger=J("SceneManager"),this._performanceMonitor=null,this._pendingPersistentEntities=[],this._defaultWorld=new un({name:"__default__"}),this._defaultWorld.start(),this._performanceMonitor=e||null}var t=e.prototype;return t.setSceneChangedCallback=function(e){this._onSceneChangedCallback=e},t.setScene=function(t){var n=this.currentScene;return n&&n instanceof $t&&(this._pendingPersistentEntities=n.extractPersistentEntities(),this._pendingPersistentEntities.length>0&&this._logger.debug("Extracted "+this._pendingPersistentEntities.length+" persistent entities for migration")),this._defaultWorld.removeAllScenes(),this._performanceMonitor&&t.services.registerInstance(D,this._performanceMonitor),this._defaultWorld.createScene(e.DEFAULT_SCENE_ID,t),this._defaultWorld.setSceneActive(e.DEFAULT_SCENE_ID,!0),this._pendingPersistentEntities.length>0&&t instanceof $t&&(t.receiveMigratedEntities(this._pendingPersistentEntities),this._logger.debug("Migrated "+this._pendingPersistentEntities.length+" persistent entities to new scene"),this._pendingPersistentEntities=[]),t.querySystem&&t.eventSystem?this._ecsAPI=sn(t,t.querySystem,t.eventSystem):this._ecsAPI=null,y.sceneChanged(),this._onSceneChangedCallback&&this._onSceneChangedCallback(),this._logger.info("Scene changed to: "+t.name),t},t.loadScene=function(e){this._nextScene=e,this._logger.info("Scheduled scene load: "+e.name)},t.update=function(){this._nextScene&&(this.setScene(this._nextScene),this._nextScene=null),this._defaultWorld.updateGlobalSystems(),this._defaultWorld.updateScenes()},t.destroy=function(){this._logger.info("SceneManager destroying"),this._defaultWorld.destroy(),this._nextScene=null,this._ecsAPI=null,this._logger.info("SceneManager destroyed")},t.dispose=function(){this.destroy()},o(e,[{key:"currentScene",get:function(){return this._defaultWorld.getScene(e.DEFAULT_SCENE_ID)}},{key:"api",get:function(){return this._ecsAPI}},{key:"hasScene",get:function(){return null!==this._defaultWorld.getScene(e.DEFAULT_SCENE_ID)}},{key:"hasPendingScene",get:function(){return null!==this._nextScene}}])}();ln.DEFAULT_SCENE_ID="__main__",exports.DebugConfigService=function(){function e(){this._config={enabled:!1,websocketUrl:"",debugFrameRate:30,autoReconnect:!0,channels:{entities:!0,systems:!0,performance:!0,components:!0,scenes:!0}}}var t=e.prototype;return t.setConfig=function(e){this._config=e},t.getConfig=function(){return this._config},t.isEnabled=function(){return this._config.enabled},t.dispose=function(){},e}(),exports.DebugConfigService=v([b(),g("design:paramtypes",[])],exports.DebugConfigService),exports.DebugManager=function(){function e(){this.frameCounter=0,this.lastSendTime=0,this.sendInterval=0,this.isRunning=!1,this.originalConsole={log:console.log.bind(console),debug:console.debug.bind(console),info:console.info.bind(console),warn:console.warn.bind(console),error:console.error.bind(console)}}var t=e.prototype;return t.onInitialize=function(){this.config=this.configService.getConfig(),this.entityCollector=new We,this.systemCollector=new Ge,this.performanceCollector=new je,this.componentCollector=new Qe,this.sceneCollector=new Ye,this.advancedProfilerCollector=new $e,Ke.setEnabled(!0),this.webSocketManager=new Je(this.config.websocketUrl,!1!==this.config.autoReconnect),this.webSocketManager.setMessageHandler(this.handleMessage.bind(this));var e=this.config.debugFrameRate||30;this.sendInterval=1e3/e,this.interceptConsole(),this.start()},t.start=function(){this.isRunning||(this.isRunning=!0,this.connectWebSocket())},t.stop=function(){this.isRunning&&(this.isRunning=!1,this.webSocketManager.disconnect())},t.interceptConsole=function(){var e=this;console.log=function(){for(var t,n=arguments.length,i=new Array(n),r=0;r<n;r++)i[r]=arguments[r];e.sendLog("info",e.formatLogMessage(i)),(t=e.originalConsole).log.apply(t,i)},console.debug=function(){for(var t,n=arguments.length,i=new Array(n),r=0;r<n;r++)i[r]=arguments[r];e.sendLog("debug",e.formatLogMessage(i)),(t=e.originalConsole).debug.apply(t,i)},console.info=function(){for(var t,n=arguments.length,i=new Array(n),r=0;r<n;r++)i[r]=arguments[r];e.sendLog("info",e.formatLogMessage(i)),(t=e.originalConsole).info.apply(t,i)},console.warn=function(){for(var t,n=arguments.length,i=new Array(n),r=0;r<n;r++)i[r]=arguments[r];e.sendLog("warn",e.formatLogMessage(i)),(t=e.originalConsole).warn.apply(t,i)},console.error=function(){for(var t,n=arguments.length,i=new Array(n),r=0;r<n;r++)i[r]=arguments[r];e.sendLog("error",e.formatLogMessage(i)),(t=e.originalConsole).error.apply(t,i)}},t.formatLogMessage=function(e){var t=this;return e.map(function(e){if("string"==typeof e)return e;if(e instanceof Error)return e.name+": "+e.message;if(null===e)return"null";if(void 0===e)return"undefined";if("object"==typeof e)try{return t.safeStringify(e,6)}catch(t){return Object.prototype.toString.call(e)}return String(e)}).join(" ")},t.safeStringify=function(e,t){void 0===t&&(t=6);var n=new WeakSet,i=function(e,r){if(null===e)return null;if(void 0!==e){if("object"!=typeof e)return e;if(r>=t)return"[Max Depth Reached]";if(n.has(e))return"[Circular]";if(n.add(e),Array.isArray(e)){var o=e.map(function(e){return i(e,r+1)});return n.delete(e),o}var s={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(s[a]=i(e[a],r+1));return n.delete(e),s}};return JSON.stringify(i(e,0))},t.sendLog=function(e,t){if(this.webSocketManager.getConnectionStatus())try{this.webSocketManager.send({type:"log",data:{level:e,message:t,timestamp:(new Date).toISOString()}})}catch(e){}},t.updateConfig=function(e){this.config=e;var t=e.debugFrameRate||30;this.sendInterval=1e3/t,this.webSocketManager&&e.websocketUrl&&(this.webSocketManager.disconnect(),this.webSocketManager=new Je(e.websocketUrl,!1!==e.autoReconnect),this.webSocketManager.setMessageHandler(this.handleMessage.bind(this)),this.connectWebSocket())},t.update=function(e){if(this.isRunning&&this.config.enabled){this.frameCounter++;var t=Date.now();t-this.lastSendTime>=this.sendInterval&&(this.sendDebugData(),this.lastSendTime=t)}},t.onSceneChanged=function(){this.isRunning&&this.config.enabled&&this.sendDebugData()},t.handleMessage=function(e){try{switch(e.type){case"capture_memory_snapshot":this.handleMemorySnapshotRequest();break;case"config_update":e.config&&this.updateConfig(a({},this.config,e.config));break;case"expand_lazy_object":this.handleExpandLazyObjectRequest(e);break;case"get_component_properties":this.handleGetComponentPropertiesRequest(e);break;case"get_raw_entity_list":this.handleGetRawEntityListRequest(e);break;case"get_entity_details":this.handleGetEntityDetailsRequest(e);break;case"get_advanced_profiler_data":this.handleGetAdvancedProfilerDataRequest(e);break;case"set_profiler_selected_function":this.handleSetProfilerSelectedFunction(e);break;case"ping":this.webSocketManager.send({type:"pong",timestamp:Date.now()})}}catch(t){e.requestId&&this.webSocketManager.send({type:"error_response",requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}},t.handleExpandLazyObjectRequest=function(e){try{var t=e.entityId,n=e.componentIndex,i=e.propertyPath,r=e.requestId;if(void 0===t||void 0===n||!i)return void this.webSocketManager.send({type:"expand_lazy_object_response",requestId:r,error:"缺少必要参数"});var o=this.sceneManager.currentScene,s=this.entityCollector.expandLazyObject(t,n,i,o);this.webSocketManager.send({type:"expand_lazy_object_response",requestId:r,data:s})}catch(t){this.webSocketManager.send({type:"expand_lazy_object_response",requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}},t.handleGetComponentPropertiesRequest=function(e){try{var t=e.entityId,n=e.componentIndex,i=e.requestId;if(void 0===t||void 0===n)return void this.webSocketManager.send({type:"get_component_properties_response",requestId:i,error:"缺少必要参数"});var r=this.sceneManager.currentScene,o=this.entityCollector.getComponentProperties(t,n,r);this.webSocketManager.send({type:"get_component_properties_response",requestId:i,data:o})}catch(t){this.webSocketManager.send({type:"get_component_properties_response",requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}},t.handleGetRawEntityListRequest=function(e){try{var t=e.requestId,n=this.sceneManager.currentScene,i=this.entityCollector.getRawEntityList(n);this.webSocketManager.send({type:"get_raw_entity_list_response",requestId:t,data:i})}catch(t){this.webSocketManager.send({type:"get_raw_entity_list_response",requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}},t.handleGetEntityDetailsRequest=function(e){try{var t=e.entityId,n=e.requestId;if(void 0===t)return void this.webSocketManager.send({type:"get_entity_details_response",requestId:n,error:"缺少实体ID参数"});var i=this.sceneManager.currentScene,r=this.entityCollector.getEntityDetails(t,i);this.webSocketManager.send({type:"get_entity_details_response",requestId:n,data:r})}catch(t){this.webSocketManager.send({type:"get_entity_details_response",requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}},t.handleGetAdvancedProfilerDataRequest=function(e){try{var t=e.requestId,n=Ke.isEnabled()?this.advancedProfilerCollector.collectAdvancedData(this.performanceMonitor):this.advancedProfilerCollector.collectFromLegacyMonitor(this.performanceMonitor);this.webSocketManager.send({type:"get_advanced_profiler_data_response",requestId:t,data:n})}catch(t){this.webSocketManager.send({type:"get_advanced_profiler_data_response",requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}},t.handleSetProfilerSelectedFunction=function(e){try{var t=e.functionName,n=e.requestId;this.advancedProfilerCollector.setSelectedFunction(t||null),this.sendDebugData(),this.webSocketManager.send({type:"set_profiler_selected_function_response",requestId:n,success:!0})}catch(t){this.webSocketManager.send({type:"set_profiler_selected_function_response",requestId:e.requestId,error:t instanceof Error?t.message:String(t)})}},t.handleMemorySnapshotRequest=function(){try{var e=this.captureMemorySnapshot();this.webSocketManager.send({type:"memory_snapshot_response",data:e})}catch(e){this.webSocketManager.send({type:"memory_snapshot_error",error:e instanceof Error?e.message:"内存快照捕获失败"})}},t.captureMemorySnapshot=function(){var e=Date.now(),t=this.collectBaseMemoryInfo(),n=this.sceneManager.currentScene,i=this.entityCollector.collectEntityDataWithMemory(n),r=null!=n&&n.entities?this.collectComponentMemoryStats(n.entities):{totalMemory:0,componentTypes:0,totalInstances:0,breakdown:[]},o=this.collectSystemMemoryStats(),s=this.collectPoolMemoryStats(),a=this.collectPerformanceStats(),c=i.entitiesPerArchetype.reduce(function(e,t){return e+t.memory},0);return{timestamp:e,version:"2.0",summary:{totalEntities:i.totalEntities,totalMemoryUsage:t.usedMemory,totalMemoryLimit:t.totalMemory,memoryUtilization:t.usedMemory/t.totalMemory*100,gcCollections:t.gcCollections,entityMemory:c,componentMemory:r.totalMemory,systemMemory:o.totalMemory,poolMemory:s.totalMemory},baseMemory:t,entities:{totalMemory:c,entityCount:i.totalEntities,archetypes:i.entitiesPerArchetype,largestEntities:i.topEntitiesByComponents},components:r,systems:o,pools:s,performance:a}},t.collectBaseMemoryInfo=function(){var e={totalMemory:0,usedMemory:0,freeMemory:0,gcCollections:0,heapInfo:null,detailedMemory:void 0};try{var t=performance;if(t.memory){var n=t.memory;e.totalMemory=n.jsHeapSizeLimit||536870912,e.usedMemory=n.usedJSHeapSize||0,e.freeMemory=e.totalMemory-e.usedMemory,e.heapInfo={totalJSHeapSize:n.totalJSHeapSize||0,usedJSHeapSize:n.usedJSHeapSize||0,jsHeapSizeLimit:n.jsHeapSizeLimit||0}}else e.totalMemory=536870912,e.freeMemory=536870912;t.measureUserAgentSpecificMemory&&t.measureUserAgentSpecificMemory().then(function(t){e.detailedMemory=t}).catch(function(){})}catch(e){}return e},t.collectComponentMemoryStats=function(e){for(var t,n=new Map,i=0,r=new Map,o=s(e.buffer);!(t=o()).done;){var a=t.value;if(a&&!a.destroyed&&a.components)for(var c,u=s(a.components);!(c=u()).done;){var l=H(c.value);r.set(l,(r.get(l)||0)+1)}}for(var h,d=s(r.entries());!(h=d()).done;){var f=h.value,p=f[0],m=f[1],v=this.componentCollector.calculateDetailedComponentMemory(p),g=v*m;i+=g;for(var y,_=[],S=0,C=s(e.buffer);!(y=C()).done;){var E=y.value;if(E&&!E.destroyed&&E.components){for(var b,T=s(E.components);!(b=T()).done;){if(H(b.value)===p&&(_.push({entityId:E.id,entityName:E.name||"Entity_"+E.id,memory:v}),++S>=100))break}if(S>=100)break}}n.set(p,{count:m,totalMemory:g,instances:_.slice(0,10)})}var w=Array.from(n.entries()).map(function(e){var t=e[0],n=e[1];return{typeName:t,instanceCount:n.count,totalMemory:n.totalMemory,averageMemory:n.totalMemory/n.count,percentage:i>0?n.totalMemory/i*100:0,largestInstances:n.instances.sort(function(e,t){return t.memory-e.memory}).slice(0,3)}}).sort(function(e,t){return t.totalMemory-e.totalMemory});return{totalMemory:i,componentTypes:n.size,totalInstances:Array.from(n.values()).reduce(function(e,t){return e+t.count},0),breakdown:w}},t.collectSystemMemoryStats=function(){var e=this.sceneManager.currentScene,t=0,n=[];try{var i=null==e?void 0:e.systems;if(i)for(var r,o=new Map,a=s(i);!(r=a()).done;){var c=r.value,u=re(c),l=void 0;o.has(u)?l=o.get(u):(l=this.calculateQuickSystemSize(c),o.set(u,l)),t+=l,n.push({name:u,memory:l,enabled:!1!==c.enabled,updateOrder:c.updateOrder||0})}}catch(e){}return{totalMemory:t,systemCount:n.length,breakdown:n.sort(function(e,t){return t.memory-e.memory})}},t.calculateQuickSystemSize=function(e){if(!e||"object"!=typeof e)return 64;var t=128;try{for(var n=Object.keys(e),i=0;i<Math.min(n.length,15);i++){var r=n[i];if(r&&"entities"!==r&&"scene"!==r&&"constructor"!==r){var o=e[r];t+=2*r.length,"string"==typeof o?t+=Math.min(2*o.length,100):"number"==typeof o?t+=8:"boolean"==typeof o?t+=4:Array.isArray(o)?t+=40+Math.min(8*o.length,200):"object"==typeof o&&null!==o&&(t+=64)}}}catch(e){return 128}return Math.max(t,64)},t.collectPoolMemoryStats=function(){var e=0,t=[];try{for(var n,i=s(qe.getInstance().getPoolStats().entries());!(n=i()).done;){var r=n.value,o=r[0],a=r[1],c=32*a.maxSize;e+=c,t.push({typeName:o,maxSize:a.maxSize,currentSize:a.currentSize||0,estimatedMemory:c,utilization:a.currentSize?a.currentSize/a.maxSize*100:0})}}catch(e){}try{for(var u=P.getAllPoolStats(),l=0,h=Object.entries(u);l<h.length;l++){var d=h[l],f=d[0],p=d[1];e+=p.estimatedMemoryUsage,t.push({typeName:"Pool_"+f,maxSize:p.maxSize,currentSize:p.size,estimatedMemory:p.estimatedMemoryUsage,utilization:p.size/p.maxSize*100,hitRate:100*p.hitRate})}}catch(e){}return{totalMemory:e,poolCount:t.length,breakdown:t.sort(function(e,t){return t.estimatedMemory-e.estimatedMemory})}},t.collectPerformanceStats=function(){try{var e;if(!this.performanceMonitor)return{enabled:!1};var t=this.performanceMonitor.getAllSystemStats(),n=this.performanceMonitor.getPerformanceWarnings();return{enabled:null!==(e=this.performanceMonitor.enabled)&&void 0!==e&&e,systemCount:t.size,warnings:n.slice(0,10),topSystems:Array.from(t.entries()).map(function(e){var t=e[0],n=e[1];return{name:t,averageTime:n.averageTime,maxTime:n.maxTime,samples:n.executionCount}}).sort(function(e,t){return t.averageTime-e.averageTime}).slice(0,5)}}catch(e){return{enabled:!1,error:e instanceof Error?e.message:String(e)}}},t.getDebugData=function(){var e=Date.now(),t=this.sceneManager.currentScene,n={timestamp:e,frameworkVersion:"1.0.0",isRunning:this.isRunning,frameworkLoaded:!0,currentScene:(null==t?void 0:t.name)||"Unknown"};return this.config.channels.entities&&(n.entities=this.entityCollector.collectEntityData(t)),this.config.channels.systems&&(n.systems=this.systemCollector.collectSystemData(this.performanceMonitor,t)),this.config.channels.performance&&(n.performance=this.performanceCollector.collectPerformanceData(this.performanceMonitor)),this.config.channels.components&&(n.components=this.componentCollector.collectComponentData(t)),this.config.channels.scenes&&(n.scenes=this.sceneCollector.collectSceneData(t)),n},t.connectWebSocket=function(){var e=n(h().m(function e(){return h().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,e.n=1,this.webSocketManager.connect();case 1:e.n=3;break;case 2:e.p=2,e.v;case 3:return e.a(2)}},e,this,[[0,2]])}));return function(){return e.apply(this,arguments)}}(),t.sendDebugData=function(){if(this.webSocketManager.getConnectionStatus())try{var e={type:"debug_data",data:this.getDebugData(),advancedProfiler:Ke.isEnabled()?this.advancedProfilerCollector.collectAdvancedData(this.performanceMonitor):null};this.webSocketManager.send(e)}catch(e){}},t.dispose=function(){this.stop(),console.log=this.originalConsole.log,console.debug=this.originalConsole.debug,console.info=this.originalConsole.info,console.warn=this.originalConsole.warn,console.error=this.originalConsole.error},e}(),v([w(ln),g("design:type",ln)],exports.DebugManager.prototype,"sceneManager",void 0),v([w(D),g("design:type",D)],exports.DebugManager.prototype,"performanceMonitor",void 0),v([w(exports.DebugConfigService),g("design:type",exports.DebugConfigService)],exports.DebugManager.prototype,"configService",void 0),exports.DebugManager=v([b(),T()],exports.DebugManager),exports.PluginState=void 0,(an=exports.PluginState||(exports.PluginState={})).NotInstalled="not_installed",an.Installed="installed",an.Failed="failed";var hn=J("PluginManager"),dn=function(){function e(){this._plugins=new Map,this._metadata=new Map,this._core=null,this._services=null}var t=e.prototype;return t.initialize=function(e,t){this._core=e,this._services=t,hn.info("PluginManager initialized")},t.install=function(){var e=n(h().m(function e(t){var n,i;return h().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this._core&&this._services){e.n=1;break}throw new Error("PluginManager not initialized. Call initialize() first.");case 1:if(!this._plugins.has(t.name)){e.n=2;break}return hn.warn("Plugin "+t.name+" is already installed"),e.a(2);case 2:return t.dependencies&&t.dependencies.length>0&&this._checkDependencies(t),n={name:t.name,version:t.version,state:exports.PluginState.NotInstalled,installedAt:Date.now()},this._metadata.set(t.name,n),e.p=3,hn.info("Installing plugin: "+t.name+" v"+t.version),e.n=4,t.install(this._core,this._services);case 4:this._plugins.set(t.name,t),n.state=exports.PluginState.Installed,hn.info("Plugin "+t.name+" installed successfully"),e.n=6;break;case 5:throw e.p=5,i=e.v,n.state=exports.PluginState.Failed,n.error=i instanceof Error?i.message:String(i),hn.error("Failed to install plugin "+t.name+":",i),i;case 6:return e.a(2)}},e,this,[[3,5]])}));return function(t){return e.apply(this,arguments)}}(),t.uninstall=function(){var e=n(h().m(function e(t){var n,i;return h().w(function(e){for(;;)switch(e.p=e.n){case 0:if(n=this._plugins.get(t)){e.n=1;break}throw new Error("Plugin "+t+" is not installed");case 1:return this._checkDependents(t),e.p=2,hn.info("Uninstalling plugin: "+t),e.n=3,n.uninstall();case 3:this._plugins.delete(t),this._metadata.delete(t),hn.info("Plugin "+t+" uninstalled successfully"),e.n=5;break;case 4:throw e.p=4,i=e.v,hn.error("Failed to uninstall plugin "+t+":",i),i;case 5:return e.a(2)}},e,this,[[2,4]])}));return function(t){return e.apply(this,arguments)}}(),t.getPlugin=function(e){return this._plugins.get(e)},t.getMetadata=function(e){return this._metadata.get(e)},t.getAllPlugins=function(){return Array.from(this._plugins.values())},t.getAllMetadata=function(){return Array.from(this._metadata.values())},t.isInstalled=function(e){return this._plugins.has(e)},t._checkDependencies=function(e){if(e.dependencies){for(var t,n=[],i=s(e.dependencies);!(t=i()).done;){var r=t.value;this._plugins.has(r)||n.push(r)}if(n.length>0)throw new Error("Plugin "+e.name+" has unmet dependencies: "+n.join(", "))}},t._checkDependents=function(e){for(var t,n=[],i=s(this._plugins.values());!(t=i()).done;){var r=t.value;r.dependencies&&r.dependencies.includes(e)&&n.push(r.name)}if(n.length>0)throw new Error("Cannot uninstall plugin "+e+": it is required by "+n.join(", "))},t.dispose=function(){for(var e,t=s(Array.from(this._plugins.values()).reverse());!(e=t()).done;){var n=e.value;try{hn.info("Disposing plugin: "+n.name),n.uninstall()}catch(e){hn.error("Error disposing plugin "+n.name+":",e)}}this._plugins.clear(),this._metadata.clear(),this._core=null,this._services=null,hn.info("PluginManager disposed")},e}();function fn(e){var t="@esengine/service:"+e;return{id:Symbol.for(t),name:e}}var pn=function(){function e(){this._services=new Map}var t=e.prototype;return t.register=function(e,t){this._services.set(e.id,t)},t.get=function(e){return this._services.get(e.id)},t.require=function(e){var t=this._services.get(e.id);if(void 0===t)throw new Error("Service not found: "+e.name);return t},t.has=function(e){return this._services.has(e.id)},t.unregister=function(e){return this._services.delete(e.id)},t.clear=function(){this._services.clear()},t.dispose=function(){this.clear()},e}(),mn=J("WorldManager"),vn=function(){function e(e){void 0===e&&(e={}),this._worlds=new Map,this._isRunning=!1,this._framesSinceCleanup=0,this._config=a({maxWorlds:50,autoCleanup:!0,cleanupFrameInterval:1800,debug:!1},e),this._isRunning=!0,mn.info("WorldManager已初始化",{maxWorlds:this._config.maxWorlds,autoCleanup:this._config.autoCleanup,cleanupFrameInterval:this._config.cleanupFrameInterval})}var t=e.prototype;return t.createWorld=function(e,t){var n,i;if(!e||"string"!=typeof e||""===e.trim())throw new Error("World name不能为空");if(this._worlds.has(e))throw new Error("World name '"+e+"' 已存在");if(this._worlds.size>=this._config.maxWorlds)throw new Error("已达到最大World数量限制: "+this._config.maxWorlds);var r=a({name:e,debug:null!==(n=null!==(i=null==t?void 0:t.debug)&&void 0!==i?i:this._config.debug)&&void 0!==n&&n},void 0!==(null==t?void 0:t.maxScenes)&&{maxScenes:t.maxScenes},void 0!==(null==t?void 0:t.autoCleanup)&&{autoCleanup:t.autoCleanup}),o=new un(r);return this._worlds.set(e,o),o},t.removeWorld=function(e){var t=this._worlds.get(e);return!!t&&(t.destroy(),this._worlds.delete(e),mn.info("移除World: "+e),!0)},t.getWorld=function(e){return this._worlds.get(e)||null},t.getWorldIds=function(){return Array.from(this._worlds.keys())},t.getAllWorlds=function(){return Array.from(this._worlds.values())},t.setWorldActive=function(e,t){var n=this._worlds.get(e);n?t?(n.start(),mn.debug("激活World: "+e)):(n.stop(),mn.debug("停用World: "+e)):mn.warn("World '"+e+"' 不存在")},t.isWorldActive=function(e){var t,n=this._worlds.get(e);return null!==(t=null==n?void 0:n.isActive)&&void 0!==t&&t},t.updateAll=function(){if(this._isRunning){for(var e,t=s(this._worlds.values());!(e=t()).done;){var n=e.value;n.isActive&&(n.updateGlobalSystems(),n.updateScenes())}this._config.autoCleanup&&(this._framesSinceCleanup++,this._framesSinceCleanup>=this._config.cleanupFrameInterval&&(this.cleanup(),this._framesSinceCleanup=0,this._config.debug&&mn.debug("执行定期清理World (间隔: "+this._config.cleanupFrameInterval+" 帧)")))}},t.getActiveWorlds=function(){for(var e,t=[],n=s(this._worlds.values());!(e=n()).done;){var i=e.value;i.isActive&&t.push(i)}return t},t.startAll=function(){this._isRunning=!0;for(var e,t=s(this._worlds.values());!(e=t()).done;){e.value.start()}mn.info("启动所有World")},t.stopAll=function(){this._isRunning=!1;for(var e,t=s(this._worlds.values());!(e=t()).done;){e.value.stop()}mn.info("停止所有World")},t.findWorlds=function(e){for(var t,n=[],i=s(this._worlds.values());!(t=i()).done;){var r=t.value;e(r)&&n.push(r)}return n},t.findWorldByName=function(e){for(var t,n=s(this._worlds.values());!(t=n()).done;){var i=t.value;if(i.name===e)return i}return null},t.getStats=function(){for(var e,t={totalWorlds:this._worlds.size,activeWorlds:this.activeWorldCount,totalScenes:0,totalEntities:0,totalSystems:0,memoryUsage:0,isRunning:this._isRunning,config:a({},this._config),worlds:[]},n=s(this._worlds);!(e=n()).done;){var i=e.value,r=i[0],o=i[1],c=o.getStats();t.totalScenes+=c.totalSystems,t.totalEntities+=c.totalEntities,t.totalSystems+=c.totalSystems,t.worlds.push(a({id:r,name:o.name,isActive:o.isActive,sceneCount:o.sceneCount},c))}return t},t.getDetailedStatus=function(){return a({},this.getStats(),{worlds:Array.from(this._worlds.entries()).map(function(e){var t=e[0],n=e[1];return{id:t,isActive:n.isActive,status:n.getStatus()}})})},t.cleanup=function(){for(var e,t=[],n=s(this._worlds);!(e=n()).done;){var i=e.value,r=i[0],o=i[1];this.shouldCleanupWorld(o)&&t.push(r)}for(var a=0,c=t;a<c.length;a++){var u=c[a];this.removeWorld(u)}return t.length>0&&mn.debug("清理了 "+t.length+" 个World"),t.length},t.destroy=function(){mn.info("正在销毁WorldManager..."),this.stopAll();for(var e=0,t=Array.from(this._worlds.keys());e<t.length;e++){var n=t[e];this.removeWorld(n)}this._worlds.clear(),this._isRunning=!1,mn.info("WorldManager已销毁")},t.dispose=function(){this.destroy()},t.shouldCleanupWorld=function(e){if(e.isActive)return!1;var t=Date.now()-e.createdAt>6e5;return(0===e.sceneCount||!e.getAllScenes().some(function(e){return e.entities&&e.entities.count>0}))&&t},o(e,[{key:"worldCount",get:function(){return this._worlds.size}},{key:"activeWorldCount",get:function(){for(var e,t=0,n=s(this._worlds.values());!(e=n()).done;){e.value.isActive&&t++}return t}},{key:"isRunning",get:function(){return this._isRunning}},{key:"config",get:function(){return a({},this._config)}}])}(),gn=function(){function e(t){var n,i,r=this;if(void 0===t&&(t={}),e._instance=this,this._config=a({debug:!0},t),this._serviceContainer=new qt,this._timerManager=new exports.TimerManager,this._serviceContainer.registerInstance(exports.TimerManager,this._timerManager),this._performanceMonitor=new D,this._serviceContainer.registerInstance(D,this._performanceMonitor),this._config.debug&&this._performanceMonitor.enable(),this._poolManager=new R,this._serviceContainer.registerInstance(R,this._poolManager),this._sceneManager=new ln(this._performanceMonitor),this._serviceContainer.registerInstance(ln,this._sceneManager),this._sceneManager.setSceneChangedCallback(function(){r._debugManager&&r._debugManager.onSceneChanged()}),this._worldManager=new vn(a({debug:!!this._config.debug},this._config.worldManagerConfig)),this._serviceContainer.registerInstance(vn,this._worldManager),this._pluginManager=new dn,this._pluginManager.initialize(this,this._serviceContainer),this._serviceContainer.registerInstance(dn,this._pluginManager),this._pluginServiceRegistry=new pn,this._serviceContainer.registerInstance(pn,this._pluginServiceRegistry),this.debug=null===(n=this._config.debug)||void 0===n||n,null!==(i=this._config.debugConfig)&&void 0!==i&&i.enabled){var o=new exports.DebugConfigService;o.setConfig(this._config.debugConfig),this._serviceContainer.registerInstance(exports.DebugConfigService,o),this._serviceContainer.registerSingleton(exports.DebugManager,function(e){return x(exports.DebugManager,e)}),this._debugManager=this._serviceContainer.resolve(exports.DebugManager),this._debugManager.onInitialize()}this.initialize()}e.create=function(t){if(void 0===t&&(t=!0),null==this._instance){var n="boolean"==typeof t?{debug:t}:t;this._instance=new e(n)}else this._logger.warn("Core实例已创建,返回现有实例");return this._instance},e.setScene=function(t){if(!this._instance)throw e._logger.warn("Core实例未创建,请先调用Core.create()"),new Error("Core实例未创建");return this._instance._sceneManager.setScene(t)},e.loadScene=function(t){this._instance?this._instance._sceneManager.loadScene(t):e._logger.warn("Core实例未创建,请先调用Core.create()")},e.update=function(t){this._instance?this._instance.updateInternal(t):e._logger.warn("Core实例未创建,请先调用Core.create()")},e.schedule=function(e,t,n,i){if(void 0===t&&(t=!1),!this._instance)throw new Error("Core实例未创建,请先调用Core.create()");if(!i)throw new Error("onTime callback is required");return this._instance._timerManager.schedule(e,t,n,i)},e.enableDebug=function(t){if(this._instance){if(this._instance._debugManager)this._instance._debugManager.updateConfig(t);else{var n=new exports.DebugConfigService;n.setConfig(t),this._instance._serviceContainer.registerInstance(exports.DebugConfigService,n),this._instance._serviceContainer.registerSingleton(exports.DebugManager,function(e){return x(exports.DebugManager,e)}),this._instance._debugManager=this._instance._serviceContainer.resolve(exports.DebugManager),this._instance._debugManager.onInitialize()}this._instance._config.debugConfig=t}else e._logger.warn("Core实例未创建,请先调用Core.create()")},e.disableDebug=function(){this._instance&&(this._instance._debugManager&&(this._instance._debugManager.stop(),delete this._instance._debugManager),this._instance._config.debugConfig&&(this._instance._config.debugConfig.enabled=!1))},e.getDebugData=function(){var e;return null!==(e=this._instance)&&void 0!==e&&e._debugManager?this._instance._debugManager.getDebugData():null},e.installPlugin=function(){var e=n(h().m(function e(t){return h().w(function(e){for(;;)switch(e.n){case 0:if(this._instance){e.n=1;break}throw new Error("Core实例未创建,请先调用Core.create()");case 1:return e.n=2,this._instance._pluginManager.install(t);case 2:return e.a(2)}},e,this)}));return function(t){return e.apply(this,arguments)}}(),e.uninstallPlugin=function(){var e=n(h().m(function e(t){return h().w(function(e){for(;;)switch(e.n){case 0:if(this._instance){e.n=1;break}throw new Error("Core实例未创建,请先调用Core.create()");case 1:return e.n=2,this._instance._pluginManager.uninstall(t);case 2:return e.a(2)}},e,this)}));return function(t){return e.apply(this,arguments)}}(),e.getPlugin=function(e){if(this._instance)return this._instance._pluginManager.getPlugin(e)},e.isPluginInstalled=function(e){return!!this._instance&&this._instance._pluginManager.isInstalled(e)};var t=e.prototype;return t.initialize=function(){var t;e._logger.info("Core initialized",{debug:this.debug,debugEnabled:(null===(t=this._config.debugConfig)||void 0===t?void 0:t.enabled)||!1})},t.updateInternal=function(t){if(!e.paused){var n=this._performanceMonitor.startMonitoring("Core.update");y.update(t),"updateFPS"in this._performanceMonitor&&"function"==typeof this._performanceMonitor.updateFPS&&this._performanceMonitor.updateFPS(y.deltaTime);var i=this._performanceMonitor.startMonitoring("Services.update");this._serviceContainer.updateAll(t),this._performanceMonitor.endMonitoring("Services.update",i,this._serviceContainer.getUpdatableCount()),this._poolManager.update(),this._sceneManager.update(),this._worldManager.updateAll(),this._performanceMonitor.endMonitoring("Core.update",n)}},e.destroy=function(){this._instance&&(this._instance._debugManager&&this._instance._debugManager.stop(),this._instance._serviceContainer.clear(),e._logger.info("Core destroyed"),this._instance=null)},o(e,null,[{key:"Instance",get:function(){return this._instance}},{key:"services",get:function(){if(!this._instance)throw new Error("Core实例未创建,请先调用Core.create()");return this._instance._serviceContainer}},{key:"pluginServices",get:function(){if(!this._instance)throw new Error("Core实例未创建,请先调用Core.create()");return this._instance._pluginServiceRegistry}},{key:"worldManager",get:function(){if(!this._instance)throw new Error("Core实例未创建,请先调用Core.create()");return this._instance._worldManager}},{key:"scene",get:function(){return this._instance?this._instance._sceneManager.currentScene:null}},{key:"ecsAPI",get:function(){return this._instance?this._instance._sceneManager.api:null}},{key:"isDebugEnabled",get:function(){var e;return(null===(e=this._instance)||void 0===e||null===(e=e._config.debugConfig)||void 0===e?void 0:e.enabled)||!1}},{key:"performanceMonitor",get:function(){var e;return(null===(e=this._instance)||void 0===e?void 0:e._performanceMonitor)||null}}])}();gn.paused=!1,gn._instance=null,gn._logger=J("Core");var yn=fn("runtimeMode"),_n=function(){function e(e){var t,n,i;void 0===e&&(e={}),this._callbacks=new Set,this._isEditor=null!==(t=e.isEditor)&&void 0!==t&&t,this._isPlaying=null!==(n=e.isPlaying)&&void 0!==n&&n,this._isPreview=null!==(i=e.isPreview)&&void 0!==i&&i}var t=e.prototype;return t.onModeChanged=function(e){var t=this;return this._callbacks.add(e),function(){t._callbacks.delete(e)}},t.setEditorMode=function(e){this._isEditor!==e&&(this._isEditor=e,this._notifyChange())},t.setPlaying=function(e){this._isPlaying!==e&&(this._isPlaying=e,this._notifyChange())},t.setPreview=function(e){this._isPreview!==e&&(this._isPreview=e,this._notifyChange())},t.updateMode=function(e){var t=!1;void 0!==e.isEditor&&this._isEditor!==e.isEditor&&(this._isEditor=e.isEditor,t=!0),void 0!==e.isPlaying&&this._isPlaying!==e.isPlaying&&(this._isPlaying=e.isPlaying,t=!0),void 0!==e.isPreview&&this._isPreview!==e.isPreview&&(this._isPreview=e.isPreview,t=!0),t&&this._notifyChange()},t._notifyChange=function(){for(var e,t=s(this._callbacks);!(e=t()).done;){var n=e.value;try{n(this)}catch(e){console.error("[RuntimeModeService] Callback error:",e)}}},t.dispose=function(){this._callbacks.clear()},o(e,[{key:"isEditor",get:function(){return this._isEditor}},{key:"isPlaying",get:function(){return this._isPlaying}},{key:"isPreview",get:function(){return this._isPreview}},{key:"isStandalone",get:function(){return!this._isEditor}}])}();var Sn=J("DebugPlugin");exports.DebugPlugin=function(){function e(e){var t,n;this.name="@esengine/debug-plugin",this.version="1.0.0",this.worldManager=null,this.updateTimer=null,this.autoStart=null!==(t=null==e?void 0:e.autoStart)&&void 0!==t&&t,this.updateInterval=null!==(n=null==e?void 0:e.updateInterval)&&void 0!==n?n:1e3}var t=e.prototype;return t.install=function(){var e=n(h().m(function e(t,n){return h().w(function(e){for(;;)switch(e.n){case 0:this.worldManager=n.resolve(vn),Sn.info("ECS Debug Plugin installed"),this.autoStart&&this.start();case 1:return e.a(2)}},e,this)}));return function(t,n){return e.apply(this,arguments)}}(),t.uninstall=function(){var e=n(h().m(function e(){return h().w(function(e){for(;;)switch(e.n){case 0:this.stop(),this.worldManager=null,Sn.info("ECS Debug Plugin uninstalled");case 1:return e.a(2)}},e,this)}));return function(){return e.apply(this,arguments)}}(),t.dispose=function(){this.stop(),this.worldManager=null},t.start=function(){var e=this;this.updateTimer?Sn.warn("Debug monitoring already started"):(Sn.info("Starting debug monitoring"),this.updateTimer=setInterval(function(){e.logStats()},this.updateInterval))},t.stop=function(){this.updateTimer&&(clearInterval(this.updateTimer),this.updateTimer=null,Sn.info("Debug monitoring stopped"))},t.getStats=function(){if(!this.worldManager)throw new Error("Plugin not installed");for(var e,t=[],n=0,i=0,r=s(this.worldManager.getAllWorlds());!(e=r()).done;)for(var o,a=s(e.value.getAllScenes());!(o=a()).done;){var c=o.value,u=this.getSceneInfo(c);t.push(u),n+=u.entityCount,i+=u.systems.length}return{scenes:t,totalEntities:n,totalSystems:i,timestamp:Date.now()}},t.getSceneInfo=function(e){var t=this,n=e.entities.buffer,i=e.systems;return{name:e.name,entityCount:n.length,systems:i.map(function(e){return t.getSystemInfo(e)}),entities:n.map(function(e){return t.getEntityInfo(e)})}},t.getSystemInfo=function(e){var t=e.getPerformanceStats(),n=t?{avgExecutionTime:t.averageTime,maxExecutionTime:t.maxTime,totalCalls:t.executionCount}:void 0;return a({name:e.constructor.name,enabled:e.enabled,updateOrder:e.updateOrder,entityCount:e.entities.length},void 0!==n&&{performance:n})},t.getEntityInfo=function(e){var t=this,n=e.components;return{id:e.id,name:e.name,enabled:e.enabled,tag:e.tag,componentCount:n.length,components:n.map(function(e){return t.getComponentInfo(e)})}},t.getComponentInfo=function(e){for(var t=e.constructor.name,n={},i=0,r=Object.keys(e);i<r.length;i++){var o=r[i];if(!o.startsWith("_")){var s=e[o];"function"!=typeof s&&(n[o]=s)}}return{type:t,data:n}},t.queryEntities=function(e){if(!this.worldManager)throw new Error("Plugin not installed");for(var t,n=[],i=s(this.worldManager.getAllWorlds());!(t=i()).done;)for(var r,o=s(t.value.getAllScenes());!(r=o()).done;){var a=r.value;if(!e.sceneName||a.name===e.sceneName)for(var c,u=s(a.entities.buffer);!(c=u()).done;){var l=c.value;if((void 0===e.tag||l.tag===e.tag)&&(!e.name||l.name.includes(e.name))){if(e.hasComponent)if(!l.components.some(function(t){return t.constructor.name===e.hasComponent}))continue;n.push(this.getEntityInfo(l))}}}return n},t.logStats=function(){var e=this.getStats();Sn.info("=== ECS Debug Stats ==="),Sn.info("Total Entities: "+e.totalEntities),Sn.info("Total Systems: "+e.totalSystems),Sn.info("Scenes: "+e.scenes.length);for(var t,n=s(e.scenes);!(t=n()).done;){var i=t.value;Sn.info("\n[Scene: "+i.name+"]"),Sn.info(" Entities: "+i.entityCount),Sn.info(" Systems: "+i.systems.length);for(var r,o=s(i.systems);!(r=o()).done;){var a=r.value,c=a.performance?" | Avg: "+a.performance.avgExecutionTime.toFixed(2)+"ms, Max: "+a.performance.maxExecutionTime.toFixed(2)+"ms":"";Sn.info(" - "+a.name+" ("+(a.enabled?"enabled":"disabled")+") | Entities: "+a.entityCount+c)}}Sn.info("========================\n")},t.exportJSON=function(){var e=this.getStats();return JSON.stringify(e,null,2)},e}(),exports.DebugPlugin=v([b(),g("design:paramtypes",[Object])],exports.DebugPlugin);var Cn,En,bn=function(e,t){this.func=e,this.context=t},Tn=function(){function e(){this._messageTable=new Map}var t=e.prototype;return t.addObserver=function(e,t,n){var i=this._messageTable.get(e);i||(i=[],this._messageTable.set(e,i)),this.hasObserver(e,t)||i.push(new bn(t,n))},t.removeObserver=function(e,t){var n=this._messageTable.get(e);if(n){var i=n.findIndex(function(e){return e.func==t});-1!=i&&n.splice(i,1)}},t.emit=function(e){var t=this._messageTable.get(e);if(t){for(var n=arguments.length,i=new Array(n>1?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];for(var o,a=s(t);!(o=a()).done;){var c,u=o.value;(c=u.func).call.apply(c,[u.context].concat(i))}}},t.hasObserver=function(e,t){var n=this._messageTable.get(e);return!!n&&n.some(function(e){return e.func===t})},t.removeAllObservers=function(e){void 0!==e?this._messageTable.delete(e):this._messageTable.clear()},t.dispose=function(){this._messageTable.clear()},t.getEventTypeCount=function(){return this._messageTable.size},t.getObserverCount=function(e){var t=this._messageTable.get(e);return t?t.length:0},e}(),wn=function(){function e(){this._enabled=!1}var t=e.prototype;return t.setEnabled=function(e){this._enabled!=e&&(this._enabled=e,this._enabled?this.onEnabled():this.onDisabled())},t.onEnabled=function(){},t.onDisabled=function(){},t.update=function(){},o(e,[{key:"enabled",get:function(){return this._enabled},set:function(e){this.setEnabled(e)}}])}();exports.ECSEventType=void 0,(Cn=exports.ECSEventType||(exports.ECSEventType={})).ENTITY_CREATED="entity:created",Cn.ENTITY_DESTROYED="entity:destroyed",Cn.ENTITY_ENABLED="entity:enabled",Cn.ENTITY_DISABLED="entity:disabled",Cn.ENTITY_TAG_ADDED="entity:tag:added",Cn.ENTITY_TAG_REMOVED="entity:tag:removed",Cn.ENTITY_NAME_CHANGED="entity:name:changed",Cn.COMPONENT_ADDED="component:added",Cn.COMPONENT_REMOVED="component:removed",Cn.COMPONENT_MODIFIED="component:modified",Cn.COMPONENT_ENABLED="component:enabled",Cn.COMPONENT_DISABLED="component:disabled",Cn.SYSTEM_ADDED="system:added",Cn.SYSTEM_REMOVED="system:removed",Cn.SYSTEM_ENABLED="system:enabled",Cn.SYSTEM_DISABLED="system:disabled",Cn.SYSTEM_PROCESSING_START="system:processing:start",Cn.SYSTEM_PROCESSING_END="system:processing:end",Cn.SYSTEM_ERROR="system:error",Cn.SCENE_CREATED="scene:created",Cn.SCENE_DESTROYED="scene:destroyed",Cn.SCENE_ACTIVATED="scene:activated",Cn.SCENE_DEACTIVATED="scene:deactivated",Cn.SCENE_PAUSED="scene:paused",Cn.SCENE_RESUMED="scene:resumed",Cn.QUERY_EXECUTED="query:executed",Cn.QUERY_CACHE_HIT="query:cache:hit",Cn.QUERY_CACHE_MISS="query:cache:miss",Cn.QUERY_OPTIMIZED="query:optimized",Cn.PERFORMANCE_WARNING="performance:warning",Cn.PERFORMANCE_CRITICAL="performance:critical",Cn.MEMORY_USAGE_HIGH="memory:usage:high",Cn.FRAME_RATE_DROP="frame:rate:drop",Cn.INDEX_CREATED="index:created",Cn.INDEX_UPDATED="index:updated",Cn.INDEX_OPTIMIZED="index:optimized",Cn.ARCHETYPE_CREATED="archetype:created",Cn.ARCHETYPE_ENTITY_ADDED="archetype:entity:added",Cn.ARCHETYPE_ENTITY_REMOVED="archetype:entity:removed",Cn.DIRTY_MARK_ADDED="dirty:mark:added",Cn.DIRTY_BATCH_PROCESSED="dirty:batch:processed",Cn.ERROR_OCCURRED="error:occurred",Cn.WARNING_ISSUED="warning:issued",Cn.FRAMEWORK_INITIALIZED="framework:initialized",Cn.FRAMEWORK_SHUTDOWN="framework:shutdown",Cn.DEBUG_INFO="debug:info",Cn.DEBUG_STATS_UPDATED="debug:stats:updated",exports.EventPriority=void 0,(En=exports.EventPriority||(exports.EventPriority={}))[En.LOWEST=0]="LOWEST",En[En.LOW=25]="LOW",En[En.NORMAL=50]="NORMAL",En[En.HIGH=75]="HIGH",En[En.HIGHEST=100]="HIGHEST",En[En.CRITICAL=200]="CRITICAL";var In={ENTITY:{CREATED:exports.ECSEventType.ENTITY_CREATED,DESTROYED:exports.ECSEventType.ENTITY_DESTROYED,ENABLED:exports.ECSEventType.ENTITY_ENABLED,DISABLED:exports.ECSEventType.ENTITY_DISABLED,TAG_ADDED:exports.ECSEventType.ENTITY_TAG_ADDED,TAG_REMOVED:exports.ECSEventType.ENTITY_TAG_REMOVED,NAME_CHANGED:exports.ECSEventType.ENTITY_NAME_CHANGED},COMPONENT:{ADDED:exports.ECSEventType.COMPONENT_ADDED,REMOVED:exports.ECSEventType.COMPONENT_REMOVED,MODIFIED:exports.ECSEventType.COMPONENT_MODIFIED,ENABLED:exports.ECSEventType.COMPONENT_ENABLED,DISABLED:exports.ECSEventType.COMPONENT_DISABLED},SYSTEM:{ADDED:exports.ECSEventType.SYSTEM_ADDED,REMOVED:exports.ECSEventType.SYSTEM_REMOVED,ENABLED:exports.ECSEventType.SYSTEM_ENABLED,DISABLED:exports.ECSEventType.SYSTEM_DISABLED,PROCESSING_START:exports.ECSEventType.SYSTEM_PROCESSING_START,PROCESSING_END:exports.ECSEventType.SYSTEM_PROCESSING_END,ERROR:exports.ECSEventType.SYSTEM_ERROR},PERFORMANCE:{WARNING:exports.ECSEventType.PERFORMANCE_WARNING,CRITICAL:exports.ECSEventType.PERFORMANCE_CRITICAL,MEMORY_HIGH:exports.ECSEventType.MEMORY_USAGE_HIGH,FRAME_DROP:exports.ECSEventType.FRAME_RATE_DROP}},xn=function(){function e(){}return e.isValid=function(e){return this.validTypes.has(e)},e.getAllValidTypes=function(){return Array.from(this.validTypes)},e.addCustomType=function(e){this.validTypes.add(e)},e.removeCustomType=function(e){this.validTypes.delete(e)},e}();xn.validTypes=new Set([].concat(Object.values(exports.ECSEventType),Object.values(In.ENTITY),Object.values(In.COMPONENT),Object.values(In.SYSTEM),Object.values(In.PERFORMANCE)));var Mn=function(e){function t(t){return e.call(this,t)||this}return u(t,e),t.prototype.process=function(e){this.processSystem()},t}(Le),An=function(e){function t(t){return e.call(this,t)||this}return u(t,e),t.prototype.process=function(e){},t}(Le),kn=function(e){function t(t,n){var i;return(i=e.call(this,n)||this).acc=0,i.intervalRemainder=0,i.interval=t,i}u(t,e);var n=t.prototype;return n.onCheckProcessing=function(){return this.acc+=y.deltaTime,this.acc>=this.interval&&(this.intervalRemainder=this.acc-this.interval,this.acc=0,!0)},n.getIntervalDelta=function(){return this.interval+this.intervalRemainder},t}(Le),Dn=function(){function e(){this.adapter=null,this.logger=J("PlatformManager")}e.getInstance=function(){return e.instance||(e.instance=new e),e.instance};var t=e.prototype;return t.getAdapter=function(){if(!this.adapter)throw new Error("平台适配器未注册,请调用 registerAdapter() 注册适配器");return this.adapter},t.registerAdapter=function(e){this.adapter=e,this.logger.info("平台适配器已注册: "+e.name,{name:e.name,version:e.version,supportsWorker:e.isWorkerSupported(),supportsSharedArrayBuffer:e.isSharedArrayBufferSupported(),hardwareConcurrency:e.getHardwareConcurrency()})},t.hasAdapter=function(){return null!==this.adapter},t.getAdapterInfo=function(){return this.adapter?{name:this.adapter.name,version:this.adapter.version,config:this.adapter.getPlatformConfig()}:null},t.supportsFeature=function(e){if(!this.adapter)return!1;var t=this.adapter.getPlatformConfig();switch(e){case"worker":return this.adapter.isWorkerSupported();case"shared-array-buffer":return this.adapter.isSharedArrayBufferSupported();case"transferable-objects":return t.supportsTransferableObjects;case"module-worker":return t.supportsModuleWorker;default:return!1}},t.getBasicWorkerConfig=function(){if(!this.adapter)return{platformSupportsWorker:!1,platformSupportsSharedArrayBuffer:!1,platformMaxWorkerCount:1,platformLimitations:{}};var e=this.adapter.getPlatformConfig();return{platformSupportsWorker:this.adapter.isWorkerSupported(),platformSupportsSharedArrayBuffer:this.adapter.isSharedArrayBufferSupported(),platformMaxWorkerCount:e.maxWorkerCount,platformLimitations:e.limitations||{}}},t.getFullPlatformConfig=function(){var e=n(h().m(function e(){return h().w(function(e){for(;;)switch(e.n){case 0:if(this.adapter){e.n=1;break}throw new Error("平台适配器未注册");case 1:if("function"!=typeof this.adapter.getPlatformConfigAsync){e.n=3;break}return e.n=2,this.adapter.getPlatformConfigAsync();case 2:return e.a(2,e.v);case 3:return e.a(2,this.adapter.getPlatformConfig())}},e,this)}));return function(){return e.apply(this,arguments)}}(),e}(),Pn=function(e){function t(t,n){var i,r,o,s,c,u;void 0===n&&(n={}),(u=e.call(this,t)||this).workerPool=null,u.isProcessing=!1,u.sharedBuffer=null,u.sharedFloatArray=null,u.hasLoggedSyncMode=!1,u.platformAdapter=Dn.getInstance().getAdapter();var l=null!==(i=n.workerCount)&&void 0!==i?i:u.getMaxSystemWorkerCount(),h=u.getMaxSystemWorkerCount(),d=Math.min(l,h);return l>h&&u.logger.warn("请求 "+l+" 个Worker,但系统最多支持 "+h+" 个。实际使用 "+d+" 个Worker。"),u.config=a({enableWorker:null===(r=n.enableWorker)||void 0===r||r,workerCount:d,systemConfig:n.systemConfig},void 0!==n.entitiesPerWorker&&{entitiesPerWorker:n.entitiesPerWorker},{useSharedArrayBuffer:null!==(o=n.useSharedArrayBuffer)&&void 0!==o?o:u.isSharedArrayBufferSupported(),entityDataSize:null!==(s=n.entityDataSize)&&void 0!==s?s:u.getDefaultEntityDataSize(),maxEntities:null!==(c=n.maxEntities)&&void 0!==c?c:1e4},void 0!==n.workerScriptPath&&{workerScriptPath:n.workerScriptPath}),u.config.enableWorker&&u.isWorkerSupported()&&(u.config.useSharedArrayBuffer&&u.initializeSharedArrayBuffer(),u.initializeWorkerPool()),u}u(t,e);var i=t.prototype;return i.isWorkerSupported=function(){return this.platformAdapter.isWorkerSupported()},i.isSharedArrayBufferSupported=function(){return this.platformAdapter.isSharedArrayBufferSupported()},i.getMaxSystemWorkerCount=function(){return this.platformAdapter.getPlatformConfig().maxWorkerCount},i.initializeSharedArrayBuffer=function(){try{if(!this.isSharedArrayBufferSupported())return this.logger.warn(this.systemName+": 平台不支持SharedArrayBuffer,降级到单Worker模式以保证数据处理完整性"),this.config.useSharedArrayBuffer=!1,void(this.config.workerCount=1);var e=this.config.maxEntities*this.config.entityDataSize*4;this.sharedBuffer=this.platformAdapter.createSharedArrayBuffer(e),this.sharedBuffer&&(this.sharedFloatArray=new Float32Array(this.sharedBuffer)),this.logger.info(this.systemName+": SharedArrayBuffer初始化成功 ("+e+" 字节)")}catch(e){this.logger.warn(this.systemName+": SharedArrayBuffer初始化失败,降级到单Worker模式以保证数据处理完整性",e),this.config.useSharedArrayBuffer=!1,this.sharedBuffer=null,this.sharedFloatArray=null,this.config.workerCount=1}},i.initializeWorkerPool=function(){try{var e,t,n=this.platformAdapter.getPlatformConfig(),i=[];if(this.config.workerScriptPath)t=this.config.workerScriptPath,this.logger.info(this.systemName+": 使用外部Worker文件: "+t);else{if(null!==(e=n.limitations)&&void 0!==e&&e.noEval)return this.logger.error(this.systemName+": 当前平台不支持动态Worker脚本,请配置 workerScriptPath 指定预编译的Worker文件"),void(this.config.enableWorker=!1);var r=this.createWorkerScript();t=(n.workerScriptPrefix||"")+r}for(var o=0;o<this.config.workerCount;o++)try{var s=this.platformAdapter.createWorker(t,{name:"WorkerEntitySystem-"+o});i.push(s)}catch(e){throw this.logger.error("创建Worker "+o+" 失败:",e),e}this.workerPool=new On(i)}catch(e){this.logger.error(this.systemName+": Worker池初始化失败",e),this.config.enableWorker=!1}},i.createWorkerScript=function(){var e,t=this.workerProcess.toString().match(/\{([\s\S]*)\}/);if(!t)throw new Error("无法解析workerProcess方法");var n=t[1],i=this.config.entityDataSize,r=(null===(e=this.getSharedArrayBufferProcessFunction)||void 0===e?void 0:e.call(this))||null,o="";if(r){var s,a=r.toString().match(/\{([\s\S]*)\}/);if(a)o=null!==(s=a[1])&&void 0!==s?s:""}return"\n // Worker脚本 - 支持SharedArrayBuffer\n let sharedFloatArray = null;\n const ENTITY_DATA_SIZE = "+i+";\n\n self.onmessage = function(e) {\n const { type, id, entities, deltaTime, systemConfig, startIndex, endIndex, sharedBuffer } = e.data;\n\n\n try {\n // 处理SharedArrayBuffer初始化\n if (type === 'init' && sharedBuffer) {\n sharedFloatArray = new Float32Array(sharedBuffer);\n self.postMessage({ type: 'init', success: true });\n return;\n }\n\n // 处理SharedArrayBuffer数据\n if (type === 'shared' && sharedFloatArray) {\n processSharedArrayBuffer(startIndex, endIndex, deltaTime, systemConfig);\n self.postMessage({ id, result: null }); // SharedArrayBuffer不需要返回数据\n return;\n }\n\n // 传统处理方式\n if (entities) {\n // 定义处理函数\n function workerProcess(entities, deltaTime, systemConfig) {\n "+n+"\n }\n\n // 执行处理\n const result = workerProcess(entities, deltaTime, systemConfig);\n\n // 处理Promise返回值\n if (result && typeof result.then === 'function') {\n result.then(finalResult => {\n self.postMessage({ id, result: finalResult });\n }).catch(error => {\n self.postMessage({ id, error: error.message });\n });\n } else {\n self.postMessage({ id, result });\n }\n }\n } catch (error) {\n self.postMessage({ id, error: error.message });\n }\n };\n\n // SharedArrayBuffer处理函数 - 由子类定义\n function processSharedArrayBuffer(startIndex, endIndex, deltaTime, systemConfig) {\n if (!sharedFloatArray) return;\n\n "+(o?"\n // 用户定义的处理函数\n const userProcessFunction = function(sharedFloatArray, startIndex, endIndex, deltaTime, systemConfig) {\n "+o+"\n };\n userProcessFunction(sharedFloatArray, startIndex, endIndex, deltaTime, systemConfig);\n ":"")+"\n }\n "},i.process=function(e){var t=this;if(!this.isProcessing){this.isProcessing=!0;try{this.config.enableWorker&&this.workerPool?this.config.useSharedArrayBuffer&&this.sharedFloatArray&&this.isSharedArrayBufferSupported()?this.processWithSharedArrayBuffer(e).finally(function(){t.isProcessing=!1}):(this.config.useSharedArrayBuffer&&this.logger.info(this.systemName+": 本帧降级到传统Worker模式"),this.processWithWorker(e).finally(function(){t.isProcessing=!1})):(this.hasLoggedSyncMode||(this.logger.info(this.systemName+": Worker不可用,使用同步处理"),this.hasLoggedSyncMode=!0),this.processSynchronously(e),this.isProcessing=!1)}catch(e){throw this.isProcessing=!1,this.logger.error(this.systemName+": 处理失败",e),e}}},i.processWithSharedArrayBuffer=function(){var e=n(h().m(function e(t){var n;return h().w(function(e){for(;;)switch(e.n){case 0:if(this.sharedFloatArray){e.n=1;break}throw new Error("SharedArrayBuffer not initialized");case 1:return this.writeEntitiesToSharedBuffer(t),n=this.createSharedArrayBufferTasks(t.length),e.n=2,Promise.all(n);case 2:this.readResultsFromSharedBuffer(t);case 3:return e.a(2)}},e,this)}));return function(t){return e.apply(this,arguments)}}(),i.processWithWorker=function(){var e=n(h().m(function e(t){var n,i,r,o,a,c,u,l,d,f,p,m,v,g,_=this;return h().w(function(e){for(;;)switch(e.n){case 0:for(n=[],i=0;i<t.length;i++)n[i]=this.extractEntityData(t[i]);return r=this.createBatches(n),o=y.deltaTime,a=r.map(function(e){return _.workerPool.execute({entities:e,deltaTime:o,systemConfig:_.config.systemConfig})}),e.n=1,Promise.all(a);case 1:for(c=e.v,u=0,l=s(c);!(d=l()).done;)for(f=d.value,p=s(f);!(m=p()).done;)v=m.value,u<t.length&&(g=t[u])&&v&&this.applyResult(g,v),u++;case 2:return e.a(2)}},e,this)}));return function(t){return e.apply(this,arguments)}}(),i.processSynchronously=function(e){var t=this,n=e.map(function(e){return t.extractEntityData(e)}),i=y.deltaTime,r=this.workerProcess(n,i,this.config.systemConfig);r&&"function"==typeof r.then?r.then(function(n){e.forEach(function(e,i){t.applyResult(e,n[i])})}):e.forEach(function(e,n){t.applyResult(e,r[n])})},i.createBatches=function(e){var t=this.config.workerCount,n=[];if(this.config.entitiesPerWorker){for(var i=this.config.entitiesPerWorker,r=0;r<e.length;r+=i){var o=Math.min(r+i,e.length);n.push(e.slice(r,o))}n.length>t&&this.logger.warn(this.systemName+": 创建了 "+n.length+" 个批次,但只有 "+t+" 个Worker。某些Worker将依次处理多个批次。")}else for(var s=Math.ceil(e.length/t),a=0;a<t;a++){var c=a*s,u=Math.min(c+s,e.length);c<e.length&&n.push(e.slice(c,u))}return n},i.writeEntitiesToSharedBuffer=function(e){if(this.sharedFloatArray)for(var t=0;t<e.length&&t<this.config.maxEntities;t++){var n=e[t],i=this.extractEntityData(n),r=t*this.config.entityDataSize;this.writeEntityToBuffer(i,r)}},i.createSharedArrayBufferTasks=function(e){var t=[];if(this.config.entitiesPerWorker){var n=this.config.entitiesPerWorker,i=Math.ceil(e/n),r=this.config.workerCount;i>r&&this.logger.warn(this.systemName+": 需要 "+i+" 个任务处理 "+e+" 个实体(每任务 "+n+" 个),但只有 "+r+" 个Worker。某些Worker将依次处理多个任务。");for(var o=0;o<e;o+=n){var s=o,a=Math.min(o+n,e),c=this.workerPool.executeSharedBuffer({startIndex:s,endIndex:a,deltaTime:y.deltaTime,systemConfig:this.config.systemConfig});t.push(c)}}else for(var u=Math.ceil(e/this.config.workerCount),l=0;l<this.config.workerCount;l++){var h=l*u,d=Math.min(h+u,e);if(h<e){var f=this.workerPool.executeSharedBuffer({startIndex:h,endIndex:d,deltaTime:y.deltaTime,systemConfig:this.config.systemConfig});t.push(f)}}return t},i.readResultsFromSharedBuffer=function(e){if(this.sharedFloatArray)for(var t=0;t<e.length&&t<this.config.maxEntities;t++){var n=e[t],i=t*this.config.entityDataSize,r=this.readEntityFromBuffer(i);r&&this.applyResult(n,r)}},i.updateConfig=function(e){var t=a({},this.config);if(void 0!==e.workerCount){var n=this.getMaxSystemWorkerCount(),i=Math.min(e.workerCount,n);e.workerCount>n&&this.logger.warn("请求 "+e.workerCount+" 个Worker,但系统最多支持 "+n+" 个。实际使用 "+i+" 个Worker。"),e.workerCount=i}Object.assign(this.config,e),t.useSharedArrayBuffer===this.config.useSharedArrayBuffer?t.workerCount===this.config.workerCount?(!this.config.enableWorker&&this.workerPool&&(this.workerPool.destroy(),this.workerPool=null),this.config.enableWorker&&!this.workerPool&&this.isWorkerSupported()&&this.initializeWorkerPool()):this.reinitializeWorkerPool():this.reinitializeWorkerSystem()},i.reinitializeWorkerSystem=function(){this.workerPool&&(this.workerPool.destroy(),this.workerPool=null),this.sharedBuffer=null,this.sharedFloatArray=null,this.config.useSharedArrayBuffer||(this.config.workerCount=1),this.config.enableWorker&&this.isWorkerSupported()&&(this.config.useSharedArrayBuffer&&this.initializeSharedArrayBuffer(),this.initializeWorkerPool())},i.reinitializeWorkerPool=function(){this.workerPool&&(this.workerPool.destroy(),this.workerPool=null),this.config.enableWorker&&this.isWorkerSupported()&&this.initializeWorkerPool()},i.getWorkerInfo=function(){var e="sync";return this.config.enableWorker&&this.workerPool&&(e=this.config.useSharedArrayBuffer&&this.sharedFloatArray&&this.isSharedArrayBufferSupported()?"shared-buffer":"worker"),a({enabled:this.config.enableWorker,workerCount:this.config.workerCount},void 0!==this.config.entitiesPerWorker&&{entitiesPerWorker:this.config.entitiesPerWorker},{maxSystemWorkerCount:this.getMaxSystemWorkerCount(),isProcessing:this.isProcessing,sharedArrayBufferSupported:this.isSharedArrayBufferSupported(),sharedArrayBufferEnabled:this.config.useSharedArrayBuffer,currentMode:e})},i.onDestroy=function(){e.prototype.onDestroy.call(this),this.workerPool&&(this.workerPool.destroy(),this.workerPool=null)},i.getLoggerName=function(){return re(this)},t}(Le),On=function(){function e(e){var t=this;this.workers=[],this.taskQueue=[],this.busyWorkers=new Set,this.taskCounter=0,this.workers=e;for(var n=function(n){var i=e[n];if(!i)return 1;i.onMessage(function(e){return t.handleWorkerMessage(n,e.data)}),i.onError(function(e){return t.handleWorkerError(n,e)})},i=0;i<e.length;i++)n(i)}var t=e.prototype;return t.executeSharedBuffer=function(e){var t=this;return new Promise(function(n,i){var r={id:"shared-task-"+ ++t.taskCounter,data:a({},e,{type:"shared"}),resolve:function(){return n()},reject:i};t.taskQueue.push(r),t.processQueue()})},t.execute=function(e){var t=this;return new Promise(function(n,i){var r={id:"task-"+ ++t.taskCounter,data:e,resolve:function(e){n(e)},reject:i};t.taskQueue.push(r),t.processQueue()})},t.processQueue=function(){if(0!==this.taskQueue.length)for(var e=0;e<this.workers.length;e++)if(!this.busyWorkers.has(e)&&this.taskQueue.length>0){var t=this.taskQueue.shift();this.busyWorkers.add(e);var n=this.workers[e];n.postMessage(a({id:t.id},t.data)),n._currentTask=t}},t.handleWorkerMessage=function(e,t){var n=this.workers[e],i=n._currentTask;i&&(this.busyWorkers.delete(e),n._currentTask=null,t.error?i.reject(new Error(t.error)):i.resolve(t.result),this.processQueue())},t.handleWorkerError=function(e,t){var n=this.workers[e],i=n._currentTask;i&&(this.busyWorkers.delete(e),n._currentTask=null,i.reject(new Error(t.message))),this.processQueue()},t.destroy=function(){for(var e,t=s(this.workers);!(e=t()).done;){e.value.terminate()}this.workers.length=0,this.taskQueue.length=0,this.busyWorkers.clear()},e}();exports.PrefabInstanceComponent=function(e){function t(t,n,i){var r;return void 0===t&&(t=""),void 0===n&&(n=""),void 0===i&&(i=!1),(r=e.call(this)||this).sourcePrefabGuid="",r.sourcePrefabPath="",r.isRoot=!1,r.rootInstanceEntityId=null,r.modifiedProperties=[],r.instantiatedAt=0,r.originalValues={},r.sourcePrefabGuid=t,r.sourcePrefabPath=n,r.isRoot=i,r.instantiatedAt=Date.now(),r}u(t,e);var n=t.prototype;return n.markPropertyModified=function(e,t){var n=e+"."+t;this.modifiedProperties.includes(n)||this.modifiedProperties.push(n)},n.isPropertyModified=function(e,t){var n=e+"."+t;return this.modifiedProperties.includes(n)},n.clearPropertyModified=function(e,t){var n=e+"."+t,i=this.modifiedProperties.indexOf(n);-1!==i&&this.modifiedProperties.splice(i,1)},n.clearAllModifications=function(){this.modifiedProperties=[],this.originalValues={}},n.storeOriginalValue=function(e,t,n){var i=e+"."+t;i in this.originalValues||(this.originalValues[i]=this.deepClone(n))},n.getOriginalValue=function(e){return this.originalValues[e]},n.hasOriginalValue=function(e,t){return e+"."+t in this.originalValues},n.deepClone=function(e){if(null==e)return e;if("object"==typeof e)try{return JSON.parse(JSON.stringify(e))}catch(t){return e}return e},t}(we),v([ke(),g("design:type",String)],exports.PrefabInstanceComponent.prototype,"sourcePrefabGuid",void 0),v([ke(),g("design:type",String)],exports.PrefabInstanceComponent.prototype,"sourcePrefabPath",void 0),v([ke(),g("design:type",Boolean)],exports.PrefabInstanceComponent.prototype,"isRoot",void 0),v([ke(),g("design:type",Object)],exports.PrefabInstanceComponent.prototype,"rootInstanceEntityId",void 0),v([ke(),g("design:type",Array)],exports.PrefabInstanceComponent.prototype,"modifiedProperties",void 0),v([ke(),g("design:type",Number)],exports.PrefabInstanceComponent.prototype,"instantiatedAt",void 0),v([ke(),g("design:type",Object)],exports.PrefabInstanceComponent.prototype,"originalValues",void 0),exports.PrefabInstanceComponent=v([ee("PrefabInstance",{editor:{hideInInspector:!0}}),Ae({version:1,typeId:"PrefabInstance"}),g("design:paramtypes",[String,String,Boolean])],exports.PrefabInstanceComponent);var Rn=function(){function e(e){void 0===e&&(e=!1),this.eventIdCounter=0,this.isDebugMode=!1,this.eventSystem=new xt,this.isDebugMode=e}var t=e.prototype;return t.emit=function(t,n,i){void 0===i&&(i=!1),this.validateEventType(t);var r=i?this.enhanceEventData(t,n):n;this.isDebugMode&&e._logger.info("发射事件: "+t,r),this.eventSystem.emitSync(t,r)},t.emitAsync=function(){var t=n(h().m(function t(n,i,r){var o;return h().w(function(t){for(;;)switch(t.n){case 0:return void 0===r&&(r=!1),this.validateEventType(n),o=r?this.enhanceEventData(n,i):i,this.isDebugMode&&e._logger.info("发射异步事件: "+n,o),t.n=1,this.eventSystem.emit(n,o);case 1:return t.a(2)}},t,this)}));return function(e,n,i){return t.apply(this,arguments)}}(),t.on=function(t,n,i){void 0===i&&(i={}),this.validateEventType(t);var r={once:i.once||!1,priority:i.priority||exports.EventPriority.NORMAL,async:i.async||!1};return i.thisArg&&(r.thisArg=i.thisArg),this.isDebugMode&&e._logger.info("添加监听器: "+t,r),this.eventSystem.on(t,n,r)},t.once=function(e,t,n){return void 0===n&&(n={}),this.on(e,t,a({},n,{once:!0}))},t.onAsync=function(e,t,n){return void 0===n&&(n={}),this.on(e,t,a({},n,{async:!0}))},t.off=function(t,n){return this.isDebugMode&&e._logger.info("移除监听器: "+n+" 事件: "+t),this.eventSystem.off(t,n)},t.offAll=function(t){this.isDebugMode&&e._logger.info("移除所有监听器: "+t),this.eventSystem.offAll(t)},t.hasListeners=function(e){return this.eventSystem.hasListeners(e)},t.getStats=function(e){var t=this,n=this.eventSystem.getStats(e);if(n instanceof Map){var i=new Map;return n.forEach(function(e,n){i.set(n,t.convertEventStats(e))}),i}return this.convertEventStats(n)},t.clear=function(){this.isDebugMode&&e._logger.info("清空所有监听器"),this.eventSystem.clear()},t.setEnabled=function(e){this.eventSystem.setEnabled(e)},t.setDebugMode=function(e){this.isDebugMode=e},t.setMaxListeners=function(e){this.eventSystem.setMaxListeners(e)},t.getListenerCount=function(e){return this.eventSystem.getListenerCount(e)},t.setBatchConfig=function(e,t,n){this.eventSystem.setBatchConfig(e,{batchSize:t,delay:n,enabled:!0})},t.flushBatch=function(e){this.eventSystem.flushBatch(e)},t.resetStats=function(e){this.eventSystem.resetStats(e)},t.emitEntityCreated=function(e){this.emit(exports.ECSEventType.ENTITY_CREATED,e)},t.emitEntityDestroyed=function(e){this.emit(exports.ECSEventType.ENTITY_DESTROYED,e)},t.emitComponentAdded=function(e){this.emit(exports.ECSEventType.COMPONENT_ADDED,e)},t.emitComponentRemoved=function(e){this.emit(exports.ECSEventType.COMPONENT_REMOVED,e)},t.emitSystemAdded=function(e){this.emit(exports.ECSEventType.SYSTEM_ADDED,e)},t.emitSystemRemoved=function(e){this.emit(exports.ECSEventType.SYSTEM_REMOVED,e)},t.emitSceneChanged=function(e){this.emit(exports.ECSEventType.SCENE_ACTIVATED,e)},t.emitPerformanceWarning=function(e){this.emit(exports.ECSEventType.PERFORMANCE_WARNING,e)},t.onEntityCreated=function(e,t){return this.on(exports.ECSEventType.ENTITY_CREATED,e,t)},t.onComponentAdded=function(e,t){return this.on(exports.ECSEventType.COMPONENT_ADDED,e,t)},t.onSystemError=function(e,t){return this.on(exports.ECSEventType.SYSTEM_ERROR,e,t)},t.onPerformanceWarning=function(e,t){return this.on(exports.ECSEventType.PERFORMANCE_WARNING,e,t)},t.validateEventType=function(t){this.isDebugMode&&(xn.isValid(t)||(e._logger.warn("未知事件类型: "+t),xn.addCustomType(t)))},t.enhanceEventData=function(e,t){if(null==t)return{timestamp:Date.now(),eventId:e+"_"+ ++this.eventIdCounter,source:"EventBus"};var n=t;return n.timestamp||(n.timestamp=Date.now()),n.eventId||(n.eventId=e+"_"+ ++this.eventIdCounter),n.source||(n.source="EventBus"),n},t.convertEventStats=function(e){return{eventType:e.eventType,listenerCount:e.listenerCount,triggerCount:e.triggerCount,totalExecutionTime:e.totalExecutionTime,averageExecutionTime:e.averageExecutionTime,lastTriggerTime:e.lastTriggerTime}},e}();Rn._logger=J("EventBus");var zn=function(){function e(){}return e.getInstance=function(e){return void 0===e&&(e=!1),this.instance||(this.instance=new Rn(e)),this.instance},e.reset=function(e){return void 0===e&&(e=!1),this.instance&&this.instance.clear(),this.instance=new Rn(e),this.instance},e}(),Nn=function(){function e(){}return e.registerComponentMigration=function(e,t,n,i){this.componentMigrations.has(e)||this.componentMigrations.set(e,new Map),this.componentMigrations.get(e).set(t,i)},e.registerSceneMigration=function(e,t,n){this.sceneMigrations.set(e,n)},e.migrateComponent=function(e,t){var n=e.version;if(n===t)return e;var i=this.componentMigrations.get(e.type);if(!i)return console.warn("No migration path found for component "+e.type),e;for(var r=a({},e),o=n;o<t;){var s=i.get(o);if(!s){console.warn("Missing migration from version "+o+" to "+(o+1)+" for "+e.type);break}r.data=s(r.data,o,o+1),o++}return r.version=o,r},e.migrateScene=function(e,t){var n=e.version;if(n===t)return e;for(var i=a({},e),r=n;r<t;){var o=this.sceneMigrations.get(r);if(!o){console.warn("Missing scene migration from version "+r+" to "+(r+1));break}i=o(i,r,r+1),r++}return i.version=r,i=this.migrateSceneComponents(i)},e.migrateSceneComponents=function(e){var t=this,n=a({},e);return n.entities=e.entities.map(function(n){return a({},n,{components:n.components.map(function(n){var i=e.componentTypeRegistry.find(function(e){return e.typeName===n.type});return i&&i.version!==n.version?t.migrateComponent(n,i.version):n}),children:t.migrateEntitiesComponents(n.children,e.componentTypeRegistry)})}),n},e.migrateEntitiesComponents=function(e,t){var n=this;return e.map(function(e){return a({},e,{components:e.components.map(function(e){var i=t.find(function(t){return t.typeName===e.type});return i&&i.version!==e.version?n.migrateComponent(e,i.version):e}),children:n.migrateEntitiesComponents(e.children,t)})})},e.clearMigrations=function(){this.componentMigrations.clear(),this.sceneMigrations.clear()},e.getComponentMigrationPath=function(e){var t=this.componentMigrations.get(e);return t?Array.from(t.keys()).sort(function(e,t){return e-t}):[]},e.getSceneMigrationPath=function(){return Array.from(this.sceneMigrations.keys()).sort(function(e,t){return e-t})},e.canMigrateComponent=function(e,t,n){if(t===n)return!0;var i=this.componentMigrations.get(e);if(!i)return!1;for(var r=t;r<n;r++)if(!i.has(r))return!1;return!0},e.canMigrateScene=function(e,t){if(e===t)return!0;for(var n=e;n<t;n++)if(!this.sceneMigrations.has(n))return!1;return!0},e}();Nn.componentMigrations=new Map,Nn.sceneMigrations=new Map;var Fn=function(){function e(){this.fromVersion=1,this.toVersion=2}var t=e.prototype;return t.forComponent=function(e){return this.componentType=e,this},t.fromVersionToVersion=function(e,t){return this.fromVersion=e,this.toVersion=t,this},t.migrate=function(e){this.componentType?Nn.registerComponentMigration(this.componentType,this.fromVersion,this.toVersion,e):Nn.registerSceneMigration(this.fromVersion,this.toVersion,e)},e}(),Bn=function(){function e(){}return e.createPrefab=function(e,t,n){var i,r=null===(i=t.includeChildren)||void 0===i||i,o=zt.serialize(e,r,n),s=this.toPrefabEntity(o,!0),a=this.collectComponentTypes(s),c=a.componentTypes,u=a.componentTypeRegistry,l=Date.now(),h={name:t.name,createdAt:l,modifiedAt:l,componentTypes:c,referencedAssets:[]};return t.description&&(h.description=t.description),t.tags&&(h.tags=t.tags),{version:1,metadata:h,root:s,componentTypeRegistry:u}},e.instantiate=function(e,t,n,i){var r;void 0===i&&(i={});var o=i,a=o.parentId,c=o.name,u=o.preserveIds,l=void 0!==u&&u,h=o.trackInstance,d=void 0===h||h,f=null!==(r=t.getSystem(He))&&void 0!==r?r:null,p=1,m=zt.deserializeEntities([e.root],n,function(){for(;t.findEntityById(p);)p++;return p++},l,t,f),v=m.rootEntities,g=m.allEntities,y=v[0];if(!y)throw new Error("Failed to instantiate prefab: no root entity created");c&&(y.name=c);for(var _,S=s(g.values());!(_=S()).done;){var C=_.value;t.entities.add(C)}if(void 0!==a&&f){var E=t.findEntityById(a);E&&f.setParent(y,E)}if(d){var b=e.metadata.guid||"";this.addPrefabInstanceComponents(y,g,b,"",f)}return y},e.toPrefabEntity=function(e,t){var n=this;return a({},e,{isPrefabRoot:t,children:e.children.map(function(e){return n.toPrefabEntity(e,!1)})})},e.collectComponentTypes=function(e){var t=new Map,n=function(e){for(var i,r=s(e.components);!(i=r()).done;){var o=i.value;t.has(o.type)||t.set(o.type,o.version)}for(var a,c=s(e.children);!(a=c()).done;){var u=a.value;n(u)}};return n(e),{componentTypes:Array.from(t.keys()),componentTypeRegistry:Array.from(t.entries()).map(function(e){return{typeName:e[0],version:e[1]}})}},e.addPrefabInstanceComponents=function(e,t,n,i,r){var o=e.id,a=new exports.PrefabInstanceComponent(n,i,!0);a.rootInstanceEntityId=o,e.addComponent(a);for(var c,u=s(t.values());!(c=u()).done;){var l=c.value;if(l.id!==o){var h=new exports.PrefabInstanceComponent(n,i,!1);h.rootInstanceEntityId=o,l.addComponent(h)}}},e.isPrefabInstance=function(e){return e.hasComponent(exports.PrefabInstanceComponent)},e.getSourcePrefabGuid=function(e){var t=e.getComponent(exports.PrefabInstanceComponent);return(null==t?void 0:t.sourcePrefabGuid)||null},e.getPrefabInstanceRoot=function(e){var t=e.getComponent(exports.PrefabInstanceComponent);if(!t||!t.rootInstanceEntityId)return null;var n=e.scene;return n&&n.findEntityById(t.rootInstanceEntityId)||null},e.serialize=function(e,t){return void 0===t&&(t=!0),JSON.stringify(e,null,t?2:void 0)},e.deserialize=function(e){var t=JSON.parse(e);if(!t.version||!t.metadata||!t.root)throw new Error("Invalid prefab data format");return t},e.validate=function(e){var t=[];return"number"!=typeof e.version&&t.push("Invalid or missing version"),e.metadata?(e.metadata.name||t.push("Missing metadata.name"),Array.isArray(e.metadata.componentTypes)||t.push("Invalid metadata.componentTypes")):t.push("Missing metadata"),e.root?this.validateEntity(e.root,t,"root"):t.push("Missing root entity"),Array.isArray(e.componentTypeRegistry)||t.push("Invalid componentTypeRegistry"),t.length>0?{valid:!1,errors:t}:{valid:!0}},e.validateEntity=function(e,t,n){var i=this;"number"!=typeof e.id&&t.push(n+": Invalid or missing id"),"string"!=typeof e.name&&t.push(n+": Invalid or missing name"),Array.isArray(e.components)||t.push(n+": Invalid or missing components"),Array.isArray(e.children)?e.children.forEach(function(e,r){i.validateEntity(e,t,n+".children["+r+"]")}):t.push(n+": Invalid or missing children")},e}(),Ln={NONE:0,FOLDER:4096,HIDDEN:8192,LOCKED:16384,EDITOR_ONLY:32768,PREFAB_INSTANCE:256,PREFAB_ROOT:512};function Hn(e,t){return 0!==(e&t)}var Wn=function(){function e(e){this._entity=e}var t=e.prototype;return t.with=function(e){return this._entity.addComponent(e),this},t.withConfigured=function(e,t){return this._entity.addComponent(e),t(e),this},t.withTag=function(e){return this._entity.tag=e,this},t.withName=function(e){return this._entity.name=e,this},t.withActive=function(e){return this._entity.active=e,this},t.withEnabled=function(e){return this._entity.enabled=e,this},t.withUpdateOrder=function(e){return this._entity.updateOrder=e,this},t.withChild=function(e){var t,n=null===(t=this._entity.scene)||void 0===t?void 0:t.getSystem(He);return null==n||n.setParent(e,this._entity),this},t.build=function(){return this._entity},o(e,[{key:"entity",get:function(){return this._entity}}])}();var Gn=function(){function e(){}return e.getType=function(e){return e.constructor},e}(),jn=function(){function e(){}return e.toNumber=function(e){return null==e?0:Number(e)},e}();function Un(e){return"function"==typeof e&&e.prototype instanceof we}var qn=function(){function e(){}return e.detect=function(){var e,t=[],n="unknown",i=!1;return"undefined"!=typeof globalThis&&t.push("globalThis"),"undefined"!=typeof window&&t.push("window"),"undefined"!=typeof self&&t.push("self"),this.isNodeJS()?(n="nodejs",i=!0,e="NodeAdapter",t.push("nodejs","process","require")):this.isWeChatMiniGame()?(n="wechat-minigame",i=!0,e="WeChatMiniGameAdapter",t.push("wx","wechat-minigame")):this.isByteDanceMiniGame()?(n="bytedance-minigame",i=!0,e="ByteDanceMiniGameAdapter",t.push("tt","bytedance-minigame")):this.isAlipayMiniGame()?(n="alipay-minigame",i=!0,e="AlipayMiniGameAdapter",t.push("my","alipay-minigame")):this.isBaiduMiniGame()?(n="baidu-minigame",i=!0,e="BaiduMiniGameAdapter",t.push("swan","baidu-minigame")):this.isBrowser()&&(n="browser",i=!0,e="BrowserAdapter",t.push("browser")),"undefined"!=typeof Worker&&t.push("Worker"),"undefined"!=typeof SharedArrayBuffer&&t.push("SharedArrayBuffer"),"undefined"!=typeof navigator&&navigator.hardwareConcurrency&&t.push("hardwareConcurrency"),"undefined"!=typeof performance&&"function"==typeof performance.now&&t.push("performance.now"),"undefined"!=typeof Blob&&t.push("Blob"),"undefined"!=typeof URL&&"function"==typeof URL.createObjectURL&&t.push("URL.createObjectURL"),a({platform:n,confident:i,features:t},e&&{adapterClass:e})},e.isWeChatMiniGame=function(){if(void 0!==globalThis.wx){var e=globalThis.wx;return!!(e.getSystemInfo&&e.createCanvas&&e.createImage)}return!1},e.isByteDanceMiniGame=function(){if(void 0!==globalThis.tt){var e=globalThis.tt;return!!(e.getSystemInfo&&e.createCanvas&&e.createImage)}return!1},e.isNodeJS=function(){try{return!("undefined"==typeof process||!process.versions||!process.versions.node||"undefined"==typeof require||"undefined"==typeof module||"undefined"==typeof exports||"undefined"!=typeof window||"undefined"!=typeof document)}catch(e){return!1}},e.isAlipayMiniGame=function(){if(void 0!==globalThis.my){var e=globalThis.my;return!(!e.getSystemInfo||!e.createCanvas)}return!1},e.isBaiduMiniGame=function(){if(void 0!==globalThis.swan){var e=globalThis.swan;return!(!e.getSystemInfo||!e.createCanvas)}return!1},e.isBrowser=function(){return"undefined"!=typeof window&&"undefined"!=typeof document&&"undefined"!=typeof navigator&&void 0!==window.location},e.isTauriEnvironment=function(){return"undefined"!=typeof window&&("__TAURI__"in window||"__TAURI_INTERNALS__"in window)},e.isEditorEnvironment=function(){return"undefined"!=typeof window&&(!!this.isTauriEnvironment()||"__ESENGINE_EDITOR__"in window)},e.getDetailedInfo=function(){var e={};return e.userAgent="undefined"!=typeof navigator?navigator.userAgent:"unknown",e.platform="undefined"!=typeof navigator?navigator.platform:"unknown",e.globalObjects={window:"undefined"!=typeof window,document:"undefined"!=typeof document,navigator:"undefined"!=typeof navigator,wx:void 0!==globalThis.wx,tt:void 0!==globalThis.tt,my:void 0!==globalThis.my,swan:void 0!==globalThis.swan},e.workerSupport={Worker:"undefined"!=typeof Worker,SharedWorker:"undefined"!=typeof SharedWorker,ServiceWorker:"undefined"!=typeof navigator&&"serviceWorker"in navigator,SharedArrayBuffer:"undefined"!=typeof SharedArrayBuffer,crossOriginIsolated:"undefined"!=typeof self&&self.crossOriginIsolated},e.performance={performanceNow:"undefined"!=typeof performance&&"function"==typeof performance.now,hardwareConcurrency:"undefined"!=typeof navigator?navigator.hardwareConcurrency:void 0},e.apiSupport={Blob:"undefined"!=typeof Blob,URL:"undefined"!=typeof URL,createObjectURL:"undefined"!=typeof URL&&"function"==typeof URL.createObjectURL,ArrayBuffer:"undefined"!=typeof ArrayBuffer,TypedArrays:"undefined"!=typeof Float32Array},e},e}();exports.AdvancedProfilerCollector=$e,exports.After=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){var n;return(n=_e(e.prototype).after).push.apply(n,t),e}},exports.AutoProfiler=Wt,exports.Before=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){var n;return(n=_e(e.prototype).before).push.apply(n,t),e}},exports.BinarySerializer=Nt,exports.BitMask64Utils=U,exports.Bits=pt,exports.COMPONENT_DEPENDENCIES=N,exports.COMPONENT_EDITOR_OPTIONS=F,exports.COMPONENT_TYPE_NAME=z,exports.Colors=q,exports.CommandBuffer=Be,exports.CompiledQuery=Tt,exports.Component=we,exports.ComponentDataCollector=Qe,exports.ComponentPoolManager=qe,exports.ComponentRegistry=X,exports.ComponentSerializer=Rt,exports.ComponentSparseSet=gt,exports.ComponentStorage=Re,exports.ConsoleLogger=Q,exports.Core=gn,exports.CycleDependencyError=Qt,exports.DEFAULT_PROFILER_CONFIG=Ze,exports.DEFAULT_STAGE_ORDER=Jt,exports.DeepCopy=function(e,t){var n=String(t);e.constructor.__deepCopyFields||(e.constructor.__deepCopyFields=new Set),e.constructor.__deepCopyFields.add(n)},exports.ECSComponent=ee,exports.ECSFluentAPI=on,exports.ECSSystem=function(e,t){return function(n){if(!e||"string"!=typeof e)throw new Error("ECSSystem装饰器必须提供有效的类型名称");var i=n;return i[$]=e,t&&(i.__systemMetadata__=t),n}},exports.EMPTY_GUID="00000000-0000-0000-0000-000000000000",exports.ENTITY_REF_METADATA=he,exports.EVENT_TYPES=In,exports.Emitter=Tn,exports.EnableSoA=function(e){return e.__enableSoA=!0,e},exports.Entity=lt,exports.EntityDataCollector=We,exports.EntityHandleManager=Xt,exports.EntityList=ht,exports.EntityProcessorList=ft,exports.EntityRef=function(){return function(e,t){var n=e.constructor,i=n[he];i||(i={properties:new Set},n[he]=i);var r="symbol"==typeof t?t.toString():t;i.properties.add(r),Object.defineProperty(e,t,{get:function(){return fe(this).get(r)||null},set:function(e){var t=fe(this),n=t.get(r)||null;if(n!==e){var i=null!==this.entityId?ce(this.entityId):null;if(i&&i.referenceTracker){var o=i.referenceTracker;if(n&&o.unregisterReference(n,this,r),e){var s;if(e.scene!==i)return void le.error("Cannot reference Entity from different Scene. Entity: "+e.name+", Scene: "+((null===(s=e.scene)||void 0===s?void 0:s.name)||"null"));if(e.isDestroyed)return le.warn("Cannot reference destroyed Entity: "+e.name),void t.set(r,null);o.registerReference(e,this,r)}t.set(r,e)}else t.set(r,e)}},enumerable:!0,configurable:!0})}},exports.EntitySerializer=zt,exports.EntitySystem=Le,exports.EntityTags=Ln,exports.EpochManager=Kt,exports.EventBus=Rn,exports.EventTypeValidator=xn,exports.Float32=function(e,t){var n=String(t);e.constructor.__float32Fields||(e.constructor.__float32Fields=new Set),e.constructor.__float32Fields.add(n)},exports.Float64=function(e,t){var n=String(t);e.constructor.__float64Fields||(e.constructor.__float64Fields=new Set),e.constructor.__float64Fields.add(n)},exports.FuncPack=bn,exports.GEN_BITS=20,exports.GEN_MASK=nt,exports.GlobalComponentRegistry=K,exports.GlobalEventBus=zn,exports.GlobalManager=wn,exports.HierarchySystem=He,exports.INDEX_BITS=28,exports.INDEX_MASK=tt,exports.IdentifierPool=dt,exports.IgnoreSerialization=function(){return function(e,t){var n,i=e.constructor;if(Object.prototype.hasOwnProperty.call(i,Ie))n=i[Ie];else{var r=i[Ie];n={options:r?a({},r.options):{version:1},fields:r?new Map(r.fields):new Map,ignoredFields:r?new Set(r.ignoredFields):new Set},i[Ie]=n}n.ignoredFields.add(t)}},exports.InSet=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){var n;return(n=_e(e.prototype).sets).push.apply(n,t),e}},exports.IncrementalSerializer=Lt,exports.InjectProperty=w,exports.Injectable=b,exports.Int16=function(e,t){var n=String(t);e.constructor.__int16Fields||(e.constructor.__int16Fields=new Set),e.constructor.__int16Fields.add(n)},exports.Int32=be,exports.Int8=function(e,t){var n=String(t);e.constructor.__int8Fields||(e.constructor.__int8Fields=new Set),e.constructor.__int8Fields.add(n)},exports.IntervalSystem=kn,exports.Logger=Y,exports.LoggerManager=V,exports.MAX_ENTITIES=it,exports.MAX_GENERATION=rt,exports.Matcher=Pe,exports.MigrationBuilder=Fn,exports.NULL_HANDLE=0,exports.NumberExtension=jn,exports.PREFAB_FORMAT_VERSION=1,exports.PROPERTY_METADATA=ge,exports.PassiveSystem=An,exports.PerformanceDataCollector=je,exports.PerformanceMonitor=D,exports.PlatformDetector=qn,exports.PlatformManager=Dn,exports.PluginManager=dn,exports.PluginServiceRegistry=pn,exports.Pool=P,exports.PoolManager=R,exports.PrefabSerializer=Bn,exports.ProcessingSystem=Mn,exports.Profile=function(e,t){return void 0===t&&(t=exports.ProfileCategory.Custom),function(n,i,r){var o=r.value,s=e||n.constructor.name+"."+String(i);return r.value=function(){for(var e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];if(!Ke.isEnabled())return o.apply(this,n);var r=Ke.beginSample(s,t);try{var a=o.apply(this,n);return a instanceof Promise?a.finally(function(){Ke.endSample(r)}):(Ke.endSample(r),a)}catch(e){throw Ke.endSample(r),e}},r}},exports.ProfileClass=function(e){return void 0===e&&(e=exports.ProfileCategory.Custom),function(t){return Wt.registerClass(t,e)}},exports.ProfilerSDK=Ke,exports.Property=function(e){return function(t,n){var i=t.constructor,r=ve.get(i)||{};r[n]=e,ve.set(i,r)}},exports.QuerySystem=wt,exports.ReactiveQuery=bt,exports.ReferenceTracker=ue,exports.RuntimeModeService=_n,exports.RuntimeModeToken=yn,exports.SCHEDULING_METADATA=ye,exports.SERIALIZABLE_METADATA=Ie,exports.SERIALIZE_FIELD=xe,exports.SERIALIZE_OPTIONS=Me,exports.SYSTEM_TYPE_NAME=$,exports.Scene=$t,exports.SceneDataCollector=Ye,exports.SceneManager=ln,exports.SceneSerializer=Bt,exports.Serializable=Ae,exports.SerializationContext=Ft,exports.Serialize=ke,exports.SerializeArray=function(e,t){var n=String(t);e.constructor.__serializeArrayFields||(e.constructor.__serializeArrayFields=new Set),e.constructor.__serializeArrayFields.add(n)},exports.SerializeAsMap=function(){return function(e,t){ke({serializer:function(e){return e instanceof Map?Array.from(e.entries()):null},deserializer:function(e){return Array.isArray(e)?new Map(e):new Map}})(e,t)}},exports.SerializeAsSet=function(){return function(e,t){ke({serializer:function(e){return e instanceof Set?Array.from(e):null},deserializer:function(e){return Array.isArray(e)?new Set(e):new Set}})(e,t)}},exports.SerializeMap=function(e,t){var n=String(t);e.constructor.__serializeMapFields||(e.constructor.__serializeMapFields=new Set),e.constructor.__serializeMapFields.add(n)},exports.SerializeSet=function(e,t){var n=String(t);e.constructor.__serializeSetFields||(e.constructor.__serializeSetFields=new Set),e.constructor.__serializeSetFields.add(n)},exports.ServiceContainer=qt,exports.SoAStorage=Te,exports.SparseSet=mt,exports.Stage=function(e){return function(t){return _e(t.prototype).stage=e,t}},exports.SystemDataCollector=Ge,exports.SystemDependencyGraph=Yt,exports.SystemScheduler=Zt,exports.Time=y,exports.Timer=S,exports.TypeSafeEventSystem=xt,exports.TypeUtils=Gn,exports.TypedEntityBuilder=Wn,exports.TypedQueryBuilder=At,exports.TypedQueryResult=Mt,exports.Uint16=function(e,t){var n=String(t);e.constructor.__uint16Fields||(e.constructor.__uint16Fields=new Set),e.constructor.__uint16Fields.add(n)},exports.Uint32=function(e,t){var n=String(t);e.constructor.__uint32Fields||(e.constructor.__uint32Fields=new Set),e.constructor.__uint32Fields.add(n)},exports.Uint8=function(e,t){var n=String(t);e.constructor.__uint8Fields||(e.constructor.__uint8Fields=new Set),e.constructor.__uint8Fields.add(n)},exports.Uint8Clamped=function(e,t){var n=String(t);e.constructor.__uint8ClampedFields||(e.constructor.__uint8ClampedFields=new Set),e.constructor.__uint8ClampedFields.add(n)},exports.Updatable=T,exports.ValueSerializer=Ot,exports.VersionMigrationManager=Nn,exports.WebSocketManager=Je,exports.WorkerEntitySystem=Pn,exports.World=un,exports.WorldManager=vn,exports.addAndConfigure=function(e,t,n){return e.addComponent(t),n(t),e},exports.addEntityTag=function(e,t){return e|t},exports.buildEntity=function(e){return new Wn(e)},exports.createECSAPI=sn,exports.createEditorModeService=function(){return new _n({isEditor:!0,isPlaying:!1,isPreview:!1})},exports.createInstance=x,exports.createLogger=J,exports.createQuery=function(){return new At},exports.createServiceToken=fn,exports.createStandaloneModeService=function(){return new _n({isEditor:!1,isPlaying:!0,isPreview:!1})},exports.genOf=at,exports.generateGUID=et,exports.getBasicWorkerConfig=function(){return Dn.getInstance().getBasicWorkerConfig()},exports.getComponentDependencies=function(e){return e[N]},exports.getComponentEditorOptions=W,exports.getComponentInstanceEditorOptions=function(e){return W(e.constructor)},exports.getComponentInstanceTypeName=H,exports.getComponentTypeName=L,exports.getComponents=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];return n.map(function(t){return e.getComponent(t)})},exports.getCurrentAdapter=function(){return Dn.getInstance().getAdapter()},exports.getEntityRefMetadata=pe,exports.getEntityRefProperties=function(e){var t=pe(e);return t?Array.from(t.properties):[]},exports.getFullPlatformConfig=function(){return Dn.getInstance().getFullPlatformConfig()},exports.getOrAddComponent=function(e,t,n){var i=e.getComponent(t);return i||(i=n(),e.addComponent(i)),i},exports.getPropertyInjectMetadata=function(e){var t=C.get(e);return(null==t?void 0:t.properties)||new Map},exports.getPropertyMetadata=function(e){return ve.get(e)},exports.getSceneByEntityId=ce,exports.getSchedulingMetadata=Se,exports.getSerializationMetadata=De,exports.getSystemInstanceMetadata=ne,exports.getSystemInstanceTypeName=re,exports.getSystemMetadata=te,exports.getSystemTypeName=ie,exports.getUpdatableMetadata=k,exports.handleEquals=function(e,t){return e===t},exports.handleToString=function(e){return 0===e?"Entity(NULL)":"Entity(idx="+st(e)+", gen="+at(e)+")"},exports.hasAdapter=function(){return Dn.getInstance().hasAdapter()},exports.hasAnyComponent=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];return n.some(function(t){return e.hasComponent(t)})},exports.hasComponents=function(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];return n.every(function(t){return e.hasComponent(t)})},exports.hasECSComponentDecorator=B,exports.hasEntityRef=function(e){return null!==pe(e)},exports.hasEntityTag=Hn,exports.hasPropertyMetadata=function(e){return ve.has(e)},exports.hasSchedulingMetadata=function(e){return void 0!==Se(e)},exports.indexOf=st,exports.injectProperties=M,exports.isComponentArray=function(e){return e.every(Un)},exports.isComponentHiddenInInspector=G,exports.isComponentInstanceHiddenInInspector=function(e){return G(e.constructor)},exports.isComponentType=Un,exports.isEntityRefProperty=me,exports.isFolder=function(e){return Hn(e,Ln.FOLDER)},exports.isHidden=function(e){return Hn(e,Ln.HIDDEN)},exports.isLocked=function(e){return Hn(e,Ln.LOCKED)},exports.isSerializable=function(e){return null!==De(e)},exports.isUpdatable=A,exports.isValidGUID=function(e){return/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e)},exports.isValidHandle=ct,exports.makeHandle=ot,exports.queryFor=function(e){return new At([e])},exports.queryForAll=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return new At(t)},exports.registerInjectable=function(e,t,n){if(void 0===n&&(n=!0),!I(t))throw new Error(t.name+" is not marked as @Injectable(). Please add @Injectable() decorator to the class.");var i=function(e){return x(t,e)};n?e.registerSingleton(t,i):e.registerTransient(t,i)},exports.registerPlatformAdapter=function(e){return Dn.getInstance().registerAdapter(e)},exports.removeEntityTag=function(e,t){return e&~t},exports.requireComponent=function(e,t){var n=e.getComponent(t);if(!n)throw new Error("Component "+t.name+" not found on entity "+e.name+" (id: "+e.id+")");return n},exports.resetLoggerColors=function(){V.getInstance().resetColors()},exports.setGlobalLogLevel=function(e){V.getInstance().setGlobalLevel(e)},exports.setLoggerColors=function(e){V.getInstance().setGlobalColors(e)},exports.setLoggerFactory=function(e){V.getInstance().setLoggerFactory(e)},exports.supportsFeature=function(e){return Dn.getInstance().supportsFeature(e)},exports.tryGetComponent=function(e,t){var n=e.getComponent(t);return null!==n?n:void 0},exports.updateComponent=function(e,t,n){var i=e.getComponent(t);return!!i&&(Object.assign(i,n),!0)};
4
4
  //# sourceMappingURL=index.es5.js.map