entt-js 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +552 -0
- package/dist/browser/entt.js +4004 -0
- package/dist/browser/entt.min.js +1 -0
- package/dist/browser/index.js +3929 -0
- package/dist/browser/index.min.js +1 -0
- package/dist/entt.d.ts +1069 -0
- package/dist/entt.js +3944 -0
- package/dist/entt.min.js +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=(function(){class e extends TypeError{constructor(e){super(e)}}return Object.defineProperty(e.prototype,`name`,{value:`NotConstructorError`,configurable:!0}),e})();function t(e,t){if(typeof e.clone==`function`)return e.clone();let r=Object.getOwnPropertyDescriptors(e);t??=Object.create(Object.getPrototypeOf(e));for(let[e,i]of Object.entries(r))Object.defineProperty(t,e,{...i,...`value`in i?{value:n(i.value)}:void 0});return t}function n(e){let r=typeof e;if(r!==`object`||e===null){if(r===`symbol`){if(Symbol.keyFor(e)!=null)throw Error(`Cannot clone global symbol`);return Symbol(e.description)}return r===`function`?function(){return e.apply(this,arguments)}:e}if(Array.isArray(e)||e instanceof ArrayBuffer||ArrayBuffer.isView(e)||e instanceof DataView||e instanceof Date||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof Error||e instanceof Number||e instanceof String||e instanceof Boolean)try{let t=structuredClone(e);return Object.setPrototypeOf(t,Object.getPrototypeOf(e)),t}catch{if(Array.isArray(e))return e.map(e=>n(e));if(e instanceof ArrayBuffer)return e.slice(0);if(ArrayBuffer.isView(e))return new e.constructor(e.buffer,e.byteOffset,e.byteLength/e.constructor.BYTES_PER_ELEMENT);if(e instanceof DataView)return new DataView(e.buffer,e.byteOffset,e.byteLength);if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof Map){let t=new Map;return e.forEach((e,r)=>{t.set(n(r),n(e))}),t}if(e instanceof Set){let t=new Set;return e.forEach(e=>{t.add(n(e))}),t}if(e instanceof Error)return t(e,new e.constructor(e.message));if(e instanceof Number||e instanceof String||e instanceof Boolean){let t=e.constructor;return new t(e.valueOf())}}return e instanceof Promise?e.then(n):t(e)}function r(e){let t=typeof e==`bigint`;t||(e>>>=0);let n=t?BigInt(1):1;return e?Number((e&n)+(t?BigInt(r(e>>n)):r(e>>>n))):0}function i(e,t,n){Object.defineProperty(e,t,{value:n,configurable:!0,writable:!0})}function a(e,t){Object.setPrototypeOf(e,t),Object.setPrototypeOf(e.prototype,t.prototype),Object.defineProperty(e,`super_`,{value:t,writable:!0,configurable:!0})}function o(e,t){return Number(e&t-1n)}function s(e,t){let n=e;do{if(t.includes(n))return n;n=Object.getPrototypeOf(n)}while(n!=null);return null}const c=(e,t)=>e<t?-1:e>t?1:0;function l(e,t=c){return e.sort(t)}function u(e,t=c){let n=e.length;if(n>0)for(let r=1;r<n;++r){let n=e[r],i=r;for(;i>0&&t(n,e[i-1])<0;--i)e[i]=e[i-1];e[i]=n}return e}function d(e){return Array.isArray(e)?e:typeof e==`function`||e===void 0?[e,e]:[null,e]}var f=class{value;constructor(e){this.value=e}get(){return this.value}set(e){this.value=e}};const p=(function(){let e=function(e){return typeof e==`bigint`?Math.fround(Number(e&BigInt(255))):e&255};return a(e,Number),Object.defineProperty(e,`MIN_VALUE`,{value:0}),Object.defineProperty(e,`MAX_VALUE`,{value:255}),i(e,`is`,function(t){return typeof t==`number`||Object.getPrototypeOf(t)===Number.prototype?e(t)===Number(t):!1}),e})(),m=(function(){let e=function(e){return typeof e==`bigint`?Math.fround(Number(e&BigInt(4294967295))|0):Math.fround(e??0)};return a(e,Number),e})(),h=(function(){let e=function(e){return Number(e??0)};return a(e,Number),e})(),ee=(function(){let e=function(e){return typeof e==`bigint`?Number(e&BigInt(255))<<24>>24:e<<24>>24};return a(e,Number),Object.defineProperty(e,`MIN_VALUE`,{value:-128}),Object.defineProperty(e,`MAX_VALUE`,{value:127}),i(e,`is`,function(t){return typeof t==`number`||Object.getPrototypeOf(t)===Number.prototype?e(t)===Number(t):!1}),e})(),g=(function(){let e=function(e){return typeof e==`bigint`?Number(e&BigInt(65535)):e&65535};return a(e,Number),Object.defineProperty(e,`MIN_VALUE`,{value:0}),Object.defineProperty(e,`MAX_VALUE`,{value:65535}),i(e,`is`,function(t){return typeof t==`number`||Object.getPrototypeOf(t)===Number.prototype?e(t)===Number(t):!1}),e})(),te=(function(){let e=function(e){return typeof e==`bigint`?Number(e&BigInt(65535))<<16>>16:e<<16>>16};return a(e,Number),Object.defineProperty(e,`MIN_VALUE`,{value:-32768}),Object.defineProperty(e,`MAX_VALUE`,{value:32767}),i(e,`is`,function(t){return typeof t==`number`||Object.getPrototypeOf(t)===Number.prototype?e(t)===Number(t):!1}),e})(),_=(function(){let e=function(e){return typeof e==`bigint`?Number(e&BigInt(4294967295)):(e|0)>>>0};return a(e,Number),Object.defineProperty(e,`MIN_VALUE`,{value:0}),Object.defineProperty(e,`MAX_VALUE`,{value:4294967295}),i(e,`is`,function(t){return typeof t==`number`||Object.getPrototypeOf(t)===Number.prototype?e(t)===Number(t):!1}),e})(),v=(function(){let e=function(e){return typeof e==`bigint`?Number(e&BigInt(4294967295))|0:e|0};return a(e,Number),Object.defineProperty(e,`MIN_VALUE`,{value:-2147483648}),Object.defineProperty(e,`MAX_VALUE`,{value:2147483647}),i(e,`is`,function(t){return typeof t==`number`||Object.getPrototypeOf(t)===Number.prototype?e(t)===Number(t):!1}),e})(),y=BigInt(`0xFFFFFFFFFFFFFFFF`),b=(function(){let e=function(e){if(e==null)return BigInt(0);try{return BigInt(e)&y}catch{return BigInt(0)}};return a(e,BigInt),Object.defineProperty(e,`MIN_VALUE`,{value:BigInt(0)}),Object.defineProperty(e,`MAX_VALUE`,{value:y}),i(e,`is`,function(t){return typeof t==`bigint`||Object.getPrototypeOf(t)===BigInt.prototype?e(t)===BigInt(t):!1}),e})(),ne=(function(){let e=-BigInt(`0x8000000000000000`),t=BigInt(`0x7FFFFFFFFFFFFFFF`),n=function(n){if(n==null)return BigInt(0);try{let r=BigInt(n);return r<e?r&y:r>t?(r&y)-(y+BigInt(1)):r}catch{return BigInt(0)}};return a(n,BigInt),Object.defineProperty(n,`MIN_VALUE`,{value:e}),Object.defineProperty(n,`MAX_VALUE`,{value:t}),i(n,`is`,function(e){return typeof e==`bigint`||Object.getPrototypeOf(e)===BigInt.prototype?n(e)===BigInt(e):!1}),n})(),x=(function(){let e=function(e){return _(e)};return a(e,_),e})(),S={Disabled:0,Static:1,0:`Disabled`,1:`Static`},C=(e,...t)=>e(...t),w=(()=>{let e=new WeakMap;return e.set(Boolean,C),e.set(Number,C),e.set(String,C),e.set(Symbol,C),e.set(x,C),e.set(p,C),e.set(ee,C),e.set(g,C),e.set(te,C),e.set(_,C),e.set(v,C),e.set(b,C),e.set(ne,C),e.set(m,C),e.set(h,C),e.set(BigInt,(e,...t)=>e(t.length===0?0:t[0])),{customCalls:e,emptyClasses:new WeakMap,eto:typeof ENTT_NO_ETO<`u`&&ENTT_NO_ETO?S.Disabled:S.Static,mixin:typeof ENTT_NO_MIXIN<`u`?!ENTT_NO_MIXIN:!0,sparsePage:typeof ENTT_SPARSE_PAGE<`u`?Number(ENTT_SPARSE_PAGE):4096,packedPage:typeof ENTT_PACKED_PAGE<`u`?Number(ENTT_PACKED_PAGE):1024}})();function T(t){if(w.customCalls.has(t)){let e=w.customCalls.get(t);return(...n)=>e(t,...n)}return(...n)=>{try{return new t(...n)}catch(r){if(r instanceof e||r instanceof TypeError&&r.message.includes(`is not a constructor`))return t(...n);throw r}}}function re(e,t){if(!t)return``;let n=0,r=t.index+t[0].length-1,i=r;do{let t=e[i];t===`{`?n++:t===`}`&&n--,i++}while(n>0&&i<e.length);return e.slice(r,i)}function ie(e){if(w.eto===S.Disabled||typeof e!=`function`||e.prototype==null)return!1;if(w.emptyClasses.has(e))return w.emptyClasses.get(e);if(w.eto===S.Static){let t=``;try{t=Function.prototype.toString.call(e)}catch{return!1}if(t.startsWith(`class`)){let n=t.match(/^class\s+\w*(\s+extends\s+[\w$]+)?\s*{/),r=re(t,n);if(!r)throw Error(`impossible`);return/^\{\s*(\r?\n)*\s*\}$/.test(r)?n[1]?ie(Object.getPrototypeOf(e)):!0:!1}else if(t.startsWith(`function`)){let e=re(t,t.match(/^function\s+\w*\s*\(([^)]*)\)\s*{/));if(e)return e===`{ [native code] }`?!1:!/this|return/.test(e);throw Error(`impossible`)}else return!1}return!1}const E=new WeakMap;let ae=0;function oe(e){let t=typeof e,n=e&&e.constructor,r=n===Date;if(Object(e)===e&&!r&&n!=RegExp){let t=E.get(e);if(t)return t;t=++ae+`~`,E.set(e,t);let r;if(n===Array){for(t=`@`,r=0;r<e.length;r++)t+=oe(e[r])+`,`;E.set(e,t)}else if(n===Object){t=`#`;let n=Object.keys(e).sort();for(;(r=n.pop())!==void 0;)e[r]!==void 0&&(t+=r+`:`+oe(e[r])+`,`);E.set(e,t)}return t}return r?e.toJSON():t===`symbol`?e.toString():t===`string`?JSON.stringify(e):``+e}var D=oe;const O=(function(){class e{dispose(){}[Symbol.dispose](){this.dispose()}}return typeof Symbol.dispose!=`symbol`&&delete e.prototype[Symbol.dispose],e})();var se=class extends O{_registry;_specializations;instantiate;defaultRender;constructor(e,t=[]){super();let n=new Map;this._registry=n,this.defaultRender=e,this._specializations=t.map(e=>({...e,userland:!1})),this.instantiate=function(...t){let r=this.selectSpecialization(...t)??e,i=D([r,t]);if(n.has(i))return n.get(i);let a=r.apply(this,t);return n.set(i,a),a}}selectSpecialization(...e){for(let t of this._specializations)if(t.predicate.apply(this,e))return t.render;return null}addSpecialization(e){this._specializations.push({...e,userland:!0})}removeSpecialization(e){let t=this._specializations.findIndex(t=>t.predicate===e.predicate&&t.render===e.render&&t.userland);t!==-1&&this._specializations.splice(t,1)}removeAllUserlandSpecializations(){this._specializations=this._specializations.filter(e=>!e.userland)}dispose(){this._registry.clear(),this._specializations.length=0}};function k(e,t=[]){return new se(e,t)}const ce=k(function(e){if(typeof e==`function`&&e.prototype!=null){let t=s(e,[Number,BigInt,_,b]);if(t){let n=this.selectSpecialization(t).call(this,t);return n.ValueType=e,n}let n=e.EntityType;if(!n)throw TypeError(`Invalid EntityType`);let r=ce.instantiate(n);return r.ValueType=e,r}throw TypeError(`Invalid ValueType`)},[{predicate:e=>e===Number,render:function(){return{ValueType:Number,EntityType:Number,VersionType:Number,entityMask:1048575,versionMask:4095}}},{predicate:e=>e===BigInt,render:function(){return{ValueType:BigInt,EntityType:BigInt,VersionType:Number,entityMask:BigInt(4294967295),versionMask:BigInt(4294967295)}}},{predicate:e=>e===_,render:function(){return{ValueType:_,EntityType:_,VersionType:g,entityMask:_(1048575),versionMask:_(4095)}}},{predicate:e=>e===b,render:function(){return{ValueType:b,EntityType:b,VersionType:_,entityMask:b(4294967295),versionMask:b(4294967295)}}}]),le=k(function(e){let{ValueType:t,EntityType:n,VersionType:i,entityMask:a,versionMask:o}=e,c=r(a),l=T(t),u=n===Number?e=>n(e)>>>0:e=>n(e),d=(e=>u(e)&a),f=i===Number?e=>i(o?u(e)>>n(c)&o:0)>>>0:e=>i(o?u(e)>>n(c)&o:0),p=s(t,[Number,BigInt])?e=>t(e):e=>l(e),m=(e,t)=>{let r=n(e)&a;return o&&(r|=(n(t)&o)<<n(c)),r},h=n===Number?(e,t)=>p(m(e,t)>>>0):(e,t)=>p(n(m(e,t))),ee=(e=>{let t=f(e)+i(1);return h(u(e),t+i(t===o?1:0))}),g=(e,t)=>{let r=n(e)&a;return o&&(r|=n(t)&o<<n(c)),r},te=n===Number?(e,t)=>p(g(e,t)>>>0):(e,t)=>p(n(g(e,t))),_=h(a,o),v=h(a,o);return{ValueType:t,EntityType:n,VersionType:i,entityMask:a,versionMask:o,length:c,null:_,tombstone:v,toIntegral:u,toEntity:d,toVersion:f,next:ee,construct:h,combine:te,isNull:e=>d(e)===d(_),isTombstone:o?e=>f(e)===f(v):e=>u(e)===u(v)}}),A=k(function(e){let t=ce.instantiate(e),n=le.instantiate(t);return{...n,BaseType:n,pageSize:w.sparsePage}});var j=class e{it;constructor(e){this.it=e.clone()}clone(t){return t?(this===t||this.it.clone(t.it),t):new e(this.it)}swap(e){this!==e&&this.it.swap(e.it)}base(){return this.it.clone()}selfPlus(e=1){return this.it.selfMinus(e),this}selfMinus(e=1){return this.it.selfPlus(e),this}plus(t){return new e(this.it.minus(t))}minus(t){return new e(this.it.plus(t))}diff(e){return e.it.diff(this.it)}equals(e){return this.it.equals(e.it)}lt(e){return this.it.gt(e.it)}gt(e){return this.it.lt(e.it)}le(e){return this.it.ge(e.it)}ge(e){return this.it.le(e.it)}deref(){return this.it.clone().selfMinus().deref()}write(e){return this.it.write(e)}access(e){return this.it.access(-1-e)}set(e,t){this.it.set(-1-e,t)}};function M(e){return new j(e)}function N(e,t){return[t==null?e.begin():e.clone(),t==null?e.end():t.clone()]}var P=class extends Iterator{first;curr;last;constructor(e,t){super(),this.first=e.clone(),this.last=t.clone(),this.curr=e.clone()}begin(){return this.first.clone()}end(){return this.last.clone()}next(){if(this.curr.equals(this.last))return{done:!0,value:void 0};let e=this.curr.deref();return this.curr.selfPlus(),{done:!1,value:e}}[Symbol.iterator](){return this}},F=class e{pointers;constructor(e){this.pointers=e}base(){return this.pointers[0]}deref(){return this.pointers.map(e=>e.deref())}write(e){return this.pointers.forEach((t,n)=>t.write(e[n])),e}clone(t){return t?(this===t||this.pointers.forEach((e,n)=>{t.pointers[n]=e.clone()}),t):new e(this.pointers.map(e=>e.clone()))}swap(e){if(this===e)return;let t=this.pointers;this.pointers=e.pointers,e.pointers=t}selfPlus(){return this.pointers.forEach(e=>e.selfPlus()),this}equals(e){return this.pointers.every((t,n)=>t.equals(e.pointers[n]))}};function I(e,t){let[n,r]=N(e,t);return new P(n,r)}var ue=class e{array;pos;constructor(e,t){this.array=e,this.pos=t}clone(t){return t?this===t?t:(t.array=this.array,t.pos=this.pos,t):new e(this.array,this.pos)}swap(e){if(this===e)return;let t=this.array,n=this.pos;this.array=e.array,this.pos=e.pos,e.array=t,e.pos=n}selfPlus(e=1){return this.pos+=e,this}plus(t){return new e(this.array,this.pos+t)}selfMinus(e=1){return this.pos-=e,this}minus(t){return new e(this.array,this.pos-t)}diff(e){return this.pos-e.pos}lt(e){return this.pos<e.pos}gt(e){return this.pos>e.pos}le(e){return this.pos<=e.pos}ge(e){return this.pos>=e.pos}equals(e){return this.pos===e.pos}deref(){return this.array[this.pos]}write(e){return this.array[this.pos]=e,e}access(e){return this.array[this.pos+e]}set(e,t){this.array[this.pos+e]=t}},de=class{array;constructor(e){this.array=e}data(){return this.array}begin(){return new ue(this.array,0)}end(){return new ue(this.array,this.array.length)}rbegin(){return new j(this.end())}rend(){return new j(this.begin())}[Symbol.iterator](){return I(this)}};function L(e){if(Array.isArray(e))return new de(e);throw Error(`Invalid argument`)}function fe(e,t){if(e=e.clone(),t=t.clone(),typeof e.diff==`function`&&typeof t.diff==`function`)return t.diff(e);let n=0;for(;!e.equals(t);e.selfPlus())++n;return n}const R={SwapAndPop:0,InPlace:1,SwapOnly:2,Unspecified:0,0:`SwapAndPop`,1:`InPlace`,2:`SwapOnly`};var z=class e{packed;offset;constructor(e=null,t=0){this.packed=e,this.offset=t}clone(t){return t?this===t?t:(t.packed=this.packed,t.offset=this.offset,t):new e(this.packed,this.offset)}swap(e){if(this===e)return;let t=this.packed;this.packed=e.packed,e.packed=t;let n=this.offset;this.offset=e.offset,e.offset=n}data(){return this.packed}selfPlus(e=1){return this.offset-=e,this}selfMinus(e=1){return this.offset+=e,this}plus(t){return new e(this.packed,this.offset-t)}minus(t){return new e(this.packed,this.offset+t)}diff(e){return e.index()-this.index()}equals(e){return this.index()===e.index()}lt(e){return this.index()>e.index()}gt(e){return this.index()<e.index()}le(e){return!this.gt(e)}ge(e){return!this.lt(e)}deref(){return this.access(0)}write(e){return this.set(0,e),e}access(e){let t=this.index()-e;return this.packed[t]}set(e,t){let n=this.index()-e;this.packed[n]=t}index(){return this.offset-1}[Symbol.toPrimitive](e){let t=this.packed.length-1-this.index();return e===`string`?t.toString():t}};const B=k(function(e){let t=A.instantiate(e),n=t.ValueType.name,r=b(t.toEntity(t.null)),i=b(t.pageSize),a=e=>e===R.SwapOnly?b(0):r,c=e=>b(t.toEntity(e)),u=e=>e/i,d=(()=>{let e=t.entityMask,n=t.toIntegral(t.null)&~e;return s(t.EntityType,[Number])?(e,r)=>{let i=e.sparsePtr(r);return i==null?!1:(n&t.toIntegral(r)^t.toIntegral(i))>>>0<t.entityMask}:(e,r)=>{let i=e.sparsePtr(r);return i==null?!1:t.EntityType(n&t.toIntegral(r)^t.toIntegral(i))<t.entityMask}})();return class e extends O{static BasicIterator=z;static Iterator=e.BasicIterator;static ReverseIterator=j;static TraitsType=t;static EntityType=t.ValueType;sparse;packed;mode;head;Type;sparsePtr(e){let t=c(e),n=u(t);return n<this.sparse.length&&this.sparse[n]?this.sparse[n][o(t,i)]:null}sparseRef(e){let t=c(e),n=u(t),r=o(t,i);return{get:()=>this.sparse[n][r],set:e=>{this.sparse[n][r]=e}}}assureAtLeast(e){let n=c(e),r=u(n);for(;this.sparse.length<=r;)this.sparse.push(Array(t.pageSize).fill(t.null));let a=o(n,i);return{get:()=>this.sparse[r][a],set:e=>{this.sparse[r][a]=e}}}static isNull(e){return t.isNull(e)}static isTombstone(e){return t.isTombstone(e)}constructor(e,t){super(),this.sparse=[],this.packed=[];let n=typeof e==`number`?e:t??R.SwapAndPop;this.mode=n,this.head=a(n),this.Type=typeof e==`function`?e:void 0}dispose(){this.clear()}reserve(e){e>this.packed.length&&(this.packed.length=e)}data(){return this.packed}policy(){return this.mode}isNull(e){return t.isNull(e)}isTombstone(e){return t.isTombstone(e)}type(){return this.Type}empty(){return this.packed.length===0}get size(){return this.packed.length}freeList(e){return e!=null&&(this.head=b(e)),this.head}contiguous(){return this.mode!==R.InPlace||this.head===r}access(e){return this.packed[e]}swapAt(e,n){let r=this.packed[e],i=this.packed[n];this.sparseRef(r).set(t.combine(t.EntityType(n),t.toIntegral(r))),this.sparseRef(i).set(t.combine(t.EntityType(e),t.toIntegral(i))),this.packed[e]=i,this.packed[n]=r}tryEmplace(n,i=!1,a){let o=e.prototype.assureAtLeast.call(this,n),s=this.size;switch(this.mode){case R.InPlace:if(this.head!==r&&!i){s=Number(this.head),o.set(t.combine(t.EntityType(this.head),t.toIntegral(n))),this.head=b(t.toEntity(this.packed[s])),this.packed[s]=n;break}case R.SwapAndPop:this.packed.push(n),o.set(t.combine(t.EntityType(this.packed.length-1),t.toIntegral(n)));break;case R.SwapOnly:o.get()==null||t.isNull(o.get())?(this.packed.push(n),o.set(t.combine(t.EntityType(this.packed.length-1),t.toIntegral(n)))):this.bump(n),s=Number(this.head),this.head++,e.prototype.swapAt.call(this,c(o.get()),s);break;default:throw Error(`Unsupported operation`)}return new e.BasicIterator(this.packed,s+1)}push(e,t){return this.tryEmplace(e,!1,t)}pushRange(t,n){let r;n==null?(r=t.begin(),n=t.end()):(r=t.clone(),n=n.clone());let i=e.prototype.end.call(this);for(;!r.equals(n);r.selfPlus())i=this.tryEmplace(r.deref(),!0);return i}add(e){return this.push(e),this}contains(e){return d(this,e)}has(e){return this.contains(e)}swapAndPop(e){let n=this.sparseRef(e),r=t.toEntity(n.get());this.sparseRef(this.packed[this.packed.length-1]).set(t.combine(r,t.toIntegral(this.packed[this.packed.length-1]))),this.packed[r]=this.packed[this.packed.length-1],n.set(t.null),this.packed.pop()}inPlacePop(e){let n=this.sparseRef(e),r=n.get();n.set(t.null);let i=c(r),a=this.head;this.head=b(t.EntityType(i)),this.packed[i]=t.combine(t.EntityType(a),t.EntityType(t.tombstone))}swapOnly(n){let r=this.index(n);this.bump(t.next(n)),r<this.head&&this.head--,e.prototype.swapAt.call(this,r,this.head)}pop(e,t){if(e=e.clone(),t=t.clone(),this.mode===R.SwapAndPop)for(;!e.equals(t);e.selfPlus())this.swapAndPop(e.deref());else if(this.mode===R.InPlace)for(;!e.equals(t);e.selfPlus())this.inPlacePop(e.deref());else if(this.mode===R.SwapOnly)for(;!e.equals(t);e.selfPlus())this.swapOnly(e.deref());else throw Error(`Unsupported operation`)}popAll(){switch(this.mode){case R.InPlace:if(this.head!==r){for(let e of this.packed)t.isTombstone(e)||this.sparseRef(e).set(t.null);break}case R.SwapOnly:case R.SwapAndPop:for(let e of this.packed)this.sparseRef(e).set(t.null);break}this.head=a(this.mode),this.packed.length=0}erase(e,t){if(t!=null)if(e instanceof z&&t instanceof z)this.pop(e,t);else{let n=e.clone();for(t=t.clone();!n.equals(t);n.selfPlus())this.erase(n.deref())}else{let t=this.toIterator(e);this.pop(t,t.plus(1))}}remove(e,t){if(t!=null){let n=0,r=e.clone(),i=t.clone();if(e instanceof z&&t instanceof z)for(;!r.equals(i);){for(;!r.equals(i)&&!this.contains(r.deref());)r.selfPlus();let e=r.clone();for(;!r.equals(i)&&this.contains(r.deref());)r.selfPlus();n+=r.diff(e),this.erase(e,r)}else for(;!r.equals(i);r.selfPlus())n+=Number(this.remove(r.deref()));return n}else return this.has(e)?(this.erase(e),!0):!1}delete(e){return this.remove(e)}clear(){this.popAll(),this.head=a(this.mode),this.packed.length=0}forEach(e,t){for(let n=this.packed.length-1;n>=0;--n){let r=this.packed[n];e.call(t,r,r,this)}}at(e){return this.packed[(this.packed.length-1-e)%this.packed.length]}keys(){return this[Symbol.iterator]()}values(){return this[Symbol.iterator]()}entries(){let t=e.prototype.begin.call(this),n=e.prototype.end.call(this);return I(new F([t,t.clone()]),new F([n,n.clone()]))}current(e){let n=this.sparsePtr(e);return n==null?t.toVersion(t.tombstone):t.toVersion(n)}bump(e){let n=this.sparseRef(e);return n.set(t.combine(t.toIntegral(n.get()),t.toIntegral(e))),this.packed[c(n.get())]=e,t.toVersion(e)}index(e){return Number(c(this.sparsePtr(e)))}find(t){return this.has(t)?this.toIterator(t):e.prototype.end.call(this)}begin(){return new e.BasicIterator(this.packed,this.packed.length)}end(){return new e.BasicIterator(this.packed,0)}rbegin(){return M(e.prototype.end.call(this))}rend(){return M(e.prototype.begin.call(this))}toIterator(t){return e.prototype.end.call(this).minus(this.index(t)).selfMinus()}bindAny(e){}bind(e){this.bindAny(e)}swapOrMove(e,t){}compact(){if(this.mode===R.InPlace){let e=this.packed.length,n=this.head;for(this.head=r;e&&t.isTombstone(this.packed[e-1]);--e);for(;n!==r;){let r=n;if(n=b(c(this.packed[n])),r<e){--e,this.swapOrMove(e,Number(r)),this.packed[r]=this.packed[e];let n=t.EntityType(r);for(this.sparseRef(this.packed[r]).set(t.combine(n,t.toIntegral(this.packed[r])));e&&t.isTombstone(this.packed[e-1]);--e);}}this.packed.length=e}}sort(e,t=l){let n=this.mode===R.SwapOnly?Number(this.head):this.packed.length;this.sortN(n,e,t)}sortN(e,n,r=l){let i=this.packed.slice(0,e).reverse();r(i,n);for(let t=0;t<e;++t)this.packed[e-1-t]=i[t];for(let n=0;n<e;++n){let e=n,r=this.index(this.packed[e]);for(;e!==r;){let n=this.index(this.packed[r]),i=this.packed[e];this.swapOrMove(r,n);let a=t.EntityType(e);this.sparseRef(i).set(t.combine(a,t.toIntegral(this.packed[e])));let o=r;r=n,e=o}}}swapElements(t,n){let r=this.index(t),i=this.index(n);this.swapOrMove(r,i),e.prototype.swapAt.call(this,r,i)}sortAs(n,r){let i=r==null?n.begin():n.clone(),a=r==null?n.end():r.clone(),o=this.mode===R.SwapOnly?Number(this.head):this.packed.length,s=e.prototype.end.call(this).minus(o),c=e.prototype.end.call(this);for(;!s.equals(c)&&!i.equals(a);i.selfPlus()){let e=i.deref();if(this.contains(e)){let n=s.deref();t.toIntegral(n)!==t.toIntegral(e)&&this.swapElements(n,e),s.selfPlus()}}return s}get[Symbol.toStringTag](){return`BasicSparseSet<${n}>`}[Symbol.iterator](){return I(e.prototype.begin.call(this),e.prototype.end.call(this))}}}),V=(()=>B.instantiate(x))(),H=k(function(e,t){return{ElementType:e,EntityType:t,pageSize:e==null?0:`pageSize`in e?e.pageSize:ie(e)?0:w.packedPage,inPlaceDelete:e!=null&&`inPlaceDelete`in e?e.inPlaceDelete:!1}});var pe=class extends O{fn;instance;constructor(e,t){super(),this.fn=e,this.instance=t}dispose(){this.reset()}reset(){this.fn=null,this.instance=null}empty(){return this.fn==null}connect(e,t){this.fn=e,this.instance=t}invoke(...e){let t=this.fn;return this.instance?t.apply(this.instance,e):t(...e)}},U=class e extends O{signal;constructor(e){super(),this.signal=e}dispose(){this.signal?.dispose(),this.signal=void 0}empty(){return this.signal.calls.length===0}disconnectIf(e){for(let t=this.signal.calls.length-1;t>=0;--t){let n=this.signal.calls[t];if(e(n)){let e=this.signal.calls[t];this.signal.calls[t]=this.signal.calls[this.signal.calls.length-1],this.signal.calls[this.signal.calls.length-1]=e,this.signal.calls.pop()}}}disconnect(e,t){e!=null&&t!=null?this.disconnectIf(n=>Object.is(n.fn,e)&&Object.is(n.instance,t)):e==null?t==null?this.signal.calls.length=0:this.disconnectIf(e=>Object.is(e.instance,t)):this.disconnectIf(t=>Object.is(t.fn,e))}connect(t,n){this.disconnect(t,n);let r=new pe(t,n);return this.signal.calls.push(r),new me(new pe(function(n){new e(n).disconnect(t,this)},n),this.signal)}},W=class extends O{calls;static SinkType=U;constructor(){super(),this.calls=[]}dispose(){this.calls.length=0}get size(){return this.calls.length}empty(){return this.calls.length===0}publish(...e){for(let t=this.calls.length-1;t>=0;--t)this.calls[t].invoke(...e)}collect(e,...t){for(let n=this.calls.length-1;n>=0&&!e(this.calls[n].invoke(...t));--n);}},me=class{signal;disconnect;constructor(e,t){this.disconnect=e,this.signal=t}empty(){return this.disconnect.empty()}release(){this.disconnect.empty()||(this.disconnect.invoke(this.signal),this.disconnect.reset())}},he=class extends O{conn;constructor(e){super(),this.conn=e}dispose(){this.conn.release()}empty(){return this.conn.empty()}release(){this.conn.release()}},ge=class extends O{};const _e=k(function(e){let t=T(e);return class extends ge{signal;events;constructor(){super(),this.signal=new W,this.events=[]}dispose(){this.signal.dispose(),this.events.length=0}publish(){for(;this.events.length>0;){let e=this.events.shift();this.signal.publish(e)}}disconnect(e){new W.SinkType(this.signal).disconnect(void 0,e)}clear(){this.events.length=0}bucket(){return new W.SinkType(this.signal)}trigger(e){this.signal.publish(e)}enqueue(...e){this.events.push(t(...e))}get size(){return this.events.length}}});var ve=class extends O{pools;constructor(){super(),this.pools=new Map}dispose(){this.pools.forEach(e=>{e.dispose()}),this.pools.clear()}assure(e){if(!this.pools.has(e)){let t=new(_e.instantiate(e));return this.pools.set(e,t),t}return this.pools.get(e)}constAssure(e){return this.pools.get(e)}size(e){if(e!=null){let t=this.constAssure(e);return t?t.size:0}let t=0;return this.pools.forEach(e=>{t+=e.size}),t}sink(e){return this.assure(e).bucket()}trigger(e,t){this.assure(e).trigger(t)}enqueue(e,...t){this.assure(e).enqueue(...t)}disconnect(e){this.pools.forEach(t=>{t.disconnect(e)})}clear(e){e==null?this.pools.forEach(e=>{e.clear()}):this.assure(e).clear()}update(e){e==null?this.pools.forEach(e=>{e.publish()}):this.assure(e).publish()}},ye=class extends O{handlers;constructor(){super(),this.handlers=new Map}dispose(){this.handlers.clear()}on(e,t){this.handlers.set(e,e=>{t(e,this)})}publish(e){let t=e.constructor,n=this.handlers.get(t);n&&n(e)}erase(e){this.handlers.delete(e)}clear(){this.handlers.clear()}contains(e){return this.handlers.has(e)}empty(){return this.handlers.size===0}};const be=k(function(e){let t=e;return class extends e{static UnderlyingType=t;owner;construction;destruction;update;constructor(...e){super(...e),this.owner=null,this.construction=new W,this.destruction=new W,this.update=new W}dispose(){this.construction.dispose(),this.destruction.dispose(),this.update.dispose(),super.dispose(),this.owner=null}ownerOrAssert(){return this.owner}pop(e,t){let n=this.ownerOrAssert();if(this.destruction.empty())super.pop(e,t);else for(e=e.clone(),t=t.clone();!e.equals(t);e.selfPlus()){let t=e.deref();this.destruction.publish(n,t);let r=super.find(t);super.pop(r,r.plus(1))}}popAll(){let e=this.ownerOrAssert();if(!this.destruction.empty())if(`ElementType`in t&&`EntityType`in t&&t.ElementType===t.EntityType)for(let t=0,n=super.freeList();t<n;++t)this.destruction.publish(e,super.access(t));else for(let n of t.BaseType.prototype[Symbol.iterator].call(this))t.storagePolicy===R.InPlace&&this.isTombstone(n)||this.destruction.publish(e,n);super.popAll()}tryEmplace(e,t,n){let r=this.ownerOrAssert(),i=super.tryEmplace(e,t,n);this.construction.empty()||this.construction.publish(r,i.deref())}insert(e,t,...n){let r=super.size;super.insert(e,t,...n);let i=this.ownerOrAssert();if(!this.construction.empty()){let e=super.size;for(;r!==e;++r)this.construction.publish(i,super.access(r))}}bindAny(e){this.owner=e,super.bindAny(e)}onConstruct(){return new U(this.construction)}onUpdate(){return new U(this.update)}onDestroy(){return new U(this.destruction)}registry(){return this.ownerOrAssert()}generate(e){let t=super.generate(e);return this.construction.empty()||this.construction.publish(this.ownerOrAssert(),t),t}generateRange(e,t){super.generateRange(e,t);let n=this.ownerOrAssert();if(!this.construction.empty()){let[r,i]=N(e,t);for(;!r.equals(i);r.selfPlus())this.construction.publish(n,r.deref())}}emplace(e,...t){return super.emplace(e,...t),this.construction.empty()||this.construction.publish(this.ownerOrAssert(),e),this.get(e)}patch(e,...t){return super.patch(e,...t),this.update.empty()||this.update.publish(this.ownerOrAssert(),e),this.get(e)}}});var G=class e{payload;offset;pageSize;constructor(e,t,n){this.pageSize=e??0,this.payload=t??null,this.offset=n??0}dispose(){this.payload=null,this.offset=0,this.pageSize=0}clone(t){return t?t===this?t:(t.payload=this.payload,t.offset=this.offset,t.pageSize=this.pageSize,t):new e(this.pageSize,this.payload,this.offset)}swap(e){if(this===e)return;let t=this.payload;this.payload=e.payload,e.payload=t;let n=this.offset;this.offset=e.offset,e.offset=n;let r=this.pageSize;this.pageSize=e.pageSize,e.pageSize=r}data(){return this.payload}selfPlus(e=1){return this.offset-=e,this}selfMinus(e=1){return this.offset+=e,this}plus(t){return new e(this.pageSize,this.payload,this.offset-t)}minus(t){return new e(this.pageSize,this.payload,this.offset+t)}diff(e){return e.index()-this.index()}equals(e){return this.index()===e.index()}lt(e){return this.index()>e.index()}gt(e){return this.index()<e.index()}le(e){return!this.gt(e)}ge(e){return!this.lt(e)}deref(){return this.access(0)}write(e){return this.set(0,e),e}access(e){let t=this.index()-e;return this.pageSize===0?this.payload[0][t]:this.payload[t/this.pageSize>>>0][(t&this.pageSize-1)>>>0]}set(e,t){let n=this.index()-e;this.pageSize===0?this.payload[0][n]=t:this.payload[n/this.pageSize>>>0][(n&this.pageSize-1)>>>0]=t}index(){return this.offset-1}};const K=k(function(e,t){let r=B.instantiate(t),i=H.instantiate(e,t),a=T(i.ElementType),o=i.inPlaceDelete?R.InPlace:R.SwapAndPop;if(i.pageSize===0)return class extends r{static TraitsType=i;static storagePolicy=o;static EntityType=t;static ElementType=e;static BaseType=r;static ValueType=void 0;constructor(){super(i.ElementType,o)}get(e){}getAsRef(e){return{get:()=>{},set:()=>{}}}getAsTuple(e){return[]}emplace(e,...t){super.tryEmplace(e,!1)}insert(e,t,n){for(e=e.clone(),t=t.clone();!e.equals(t);e.selfPlus()){let t=e.deref();super.tryEmplace(t,!0)}}patch(e,...t){for(let e of t)e()}[Symbol.iterator](){return I(this)}each(){let e=super.begin(),t=super.end();return I(new F([e]),new F([t]))}reach(){let e=super.rbegin(),t=super.rend();return I(new F([e]),new F([t]))}};let s=class extends r{payload;static TraitsType=i;static Iterator=G;static ReverseIterator=j;static storagePolicy=o;static EntityType=t;static ElementType=e;static BaseType=r;static ValueType=e;elementAt(e){return this.payload[e/i.pageSize>>>0]?.[(e&i.pageSize-1)>>>0]}elementSet(e,t){let n=this.assureAtLeast(e);this.payload[n][(e&i.pageSize-1)>>>0]=t}assureAtLeast(e){let t=e/i.pageSize>>>0;for(;this.payload.length<=t;)this.payload.length===t?this.payload.push(Array(((e&i.pageSize-1)>>>0)+1)):this.payload.push(Array(i.pageSize).fill(void 0));return t}constructor(){super(i.ElementType,o),this.payload=[]}dispose(){this.payload.length=0,super.dispose()}reserve(e){e!==0&&(super.reserve(e),this.assureAtLeast(e-1))}get(e){return this.elementAt(super.index(e))}getAsRef(e){return{get:()=>this.elementAt(super.index(e)),set:t=>{this.elementSet(super.index(e),t)}}}getAsTuple(e){return[this.get(e)]}emplaceElement(e,t,...r){let o=super.tryEmplace(e,t),s;try{s=r.length===1&&r[0]instanceof i.ElementType?n(r[0]):a(...r),this.elementSet(o.index(),s)}catch(e){throw super.pop(o,o.plus(1)),e}return o}tryEmplace(e,t,n){return n==null?this.emplaceElement(e,t):this.emplaceElement(e,t,n)}emplace(e,...t){let n=this.emplaceElement(e,!1,...t);return this.elementAt(n.index())}insert(e,t,n=a()){for(e=e.clone(),t=t.clone();!e.equals(t);e.selfPlus()){let t=e.deref();this.emplaceElement(t,!0,n)}return this.begin()}insertRange(e,t,n){for(e=e.clone(),t=t.clone(),n=n.clone();!e.equals(t);e.selfPlus(),n.selfPlus()){let t=e.deref();this.emplaceElement(t,!0,n.deref())}return this.begin()}patch(e,...t){let n=super.index(e),r;for(let e of t){r=this.elementAt(n);let t=e(r);t!=null&&(this.elementSet(n,t),r=t)}return r}pop(e,t){for(e=e.clone(),t=t.clone();!e.equals(t);e.selfPlus())if(i.inPlaceDelete){let t=e.deref(),n=super.index(t);super.inPlacePop(t),this.elementSet(n,void 0)}else{let t=super.size-1,n=e.deref(),r=super.index(n);if(r!==t){let e=this.elementAt(t);this.elementSet(r,e),this.elementSet(t,void 0)}else this.elementSet(t,void 0);super.swapAndPop(n)}}popAll(){for(let e=super.begin();!(e.index()<0);e.selfPlus())i.inPlaceDelete?this.isTombstone(e.deref())||(super.inPlacePop(e.deref()),this.elementSet(e.index(),void 0)):(super.swapAndPop(e.deref()),this.elementSet(e.index(),void 0))}swapAt(e,t){let n=this.elementAt(e);this.elementSet(e,this.elementAt(t)),this.elementSet(t,n)}moveTo(e,t){let n=this.elementAt(e);this.elementSet(e,void 0),this.elementSet(t,n)}swapOrMove(e,t){if(this.mode===R.InPlace){let n=super.access(t);n!=null&&r.TraitsType.isTombstone(n)?this.moveTo(e,t):s.prototype.swapAt.call(this,e,t)}else s.prototype.swapAt.call(this,e,t)}[Symbol.iterator](){return I(this)}entries(){let e=super.begin(),t=this.begin(),n=super.end(),r=this.end();return I(new F([e,t]),new F([n,r]))}capacity(){return this.payload.length*i.pageSize}begin(){return new G(i.pageSize,this.payload,this.size)}end(){return new G(i.pageSize,this.payload,0)}rbegin(){return M(this.end())}rend(){return M(this.begin())}each(){return this.entries()}reach(){let e=super.rbegin(),t=this.rbegin(),n=super.rend(),r=this.rend();return I(new F([e,t]),new F([n,r]))}forEach(e,t){let n=this.begin(),r=this.end();for(;!n.equals(r);n.selfPlus()){let r=n.deref(),i=this.data()[n.index()];e.call(t,r,i,this)}}};return s},[{predicate:(e,t)=>t===void 0||Object.is(t,e),render:(e=>{let t=B.instantiate(e),n=A.instantiate(e),r=R.SwapOnly;return class extends t{placeholder;static TraitsType=n;static storagePolicy=r;static EntityType=e;static ElementType=e;static BaseType=t;static ValueType=void 0;static Iterator=z;static ReverseIterator=j;constructor(){super(n.ValueType,r),this.placeholder=0n}dispose(){this.placeholder=0n,super.dispose()}fromPlaceholder(){let e=n.combine(n.EntityType(this.placeholder),n.EntityType(0)),t=n.isNull(e);return this.placeholder+=t?0n:1n,e}next(){let e=this.fromPlaceholder();for(;super.current(e)!==n.toVersion(n.tombstone)&&!n.isNull(e);)e=this.fromPlaceholder();return e}popAll(){super.popAll(),this.placeholder=0n}tryEmplace(e){return super.find(this.generate(e))}get(e){}getAsRef(e){return{get:()=>{},set:()=>{}}}getAsTuple(e){return[]}startFrom(e){this.placeholder=BigInt(n.toEntity(e))}generate(e){if(e!=null&&!n.isNull(e)&&!n.isTombstone(e)){let t=n.construct(n.toEntity(e),super.current(e));if(n.isTombstone(t)||super.index(t)>=super.freeList())return super.tryEmplace(e,!0).deref()}let t=super.freeList(),r=t===b(super.size)?this.next():super.data()[t];return super.tryEmplace(r,!0).deref()}generateRange(e,t){let[n,r]=N(e,t),i=b(super.size);for(;!n.equals(r)&&super.freeList()!==i;n.selfPlus())n.write(super.tryEmplace(super.data()[super.freeList()],!0).deref());for(;!n.equals(r);n.selfPlus())n.write(super.tryEmplace(this.next(),!0).deref())}insert(e,t){for(e=e.clone(),t=t.clone();!e.equals(t);e.selfPlus()){let t=e.deref();super.tryEmplace(t,!0)}}patch(e,...t){for(let e of t)e()}each(){let e=super.end(),t=super.freeList();return I(new F([e.minus(Number(t))]),new F([e]))}reach(){let e=super.rbegin(),t=super.freeList();return I(new F([new j(e)]),new F([new j(e.plus(Number(t)))]))}}})}]),xe=k(function(e){return K.instantiate(e,x)}),Se=k(function(e,t){return class{static Type=w.mixin?be.instantiate(K.instantiate(e,t)):K.instantiate(e,t)}}),q=k(function(...e){return Se.instantiate(...e).Type}),Ce=(...e)=>e.length===1&&e[0].storagePolicy===R.InPlace,we=new Map,Te=e=>{if(!we.has(e)){let t=new e;return we.set(e,t),t}return we.get(e)};function J(e,t,n){for(e=e.clone(),t=t.clone();!e.equals(t)&&e.deref().contains(n);e.selfPlus());return e.equals(t)}function Ee(e,t,n){for(e=e.clone(),t=t.clone();!e.equals(t)&&!e.deref().contains(n);e.selfPlus());return e.equals(t)}function De(e,t,n){for(e=e.clone(),t=t.clone();!e.equals(t)&&e.deref()!==n;e.selfPlus());return e.equals(t)}function Oe(e,t){if(e===t)return e;let n=e;for(;n!=null;){let e=t;for(;e!=null;){if(n===e)return n;e=Object.getPrototypeOf(e)}n=Object.getPrototypeOf(n)}return null}function Y(...e){if(e.length===0)throw Error(`No storage type provided`);let t=e[0];for(let n=1;n<e.length;++n){let r=e[n];if(t=Oe(t,r),t==null)throw Error(`No common storage type found`)}return t}const ke=k(function(e,t,n,r){let i=e.Iterator;class a{it;pools;filter;index;valid(i){let a=L(this.pools),o=L(this.filter);return(!t||!e.isTombstone(i))&&(n===1||J(a.begin(),a.begin().plus(this.index),i)&&J(a.begin().plus(this.index+1),a.end(),i))&&(r===0||Ee(o.begin(),o.end(),i))}seekNext(){for(let e=new i;!this.it.equals(e)&&!this.valid(this.it.deref());this.it.selfPlus());}constructor(e,t,a,o){e!=null&&t!=null&&a!=null&&o!=null?(this.it=e.clone(),this.pools=t,this.filter=a,this.index=o,this.seekNext()):(this.it=new i,this.pools=Array(n),this.filter=Array(r),this.index=0)}selfPlus(){return this.it.selfPlus(),this.seekNext(),this}write(e){throw Error(`Unsupported operation`)}deref(){return this.it.deref()}equals(e){return this.it.equals(e.it)}clone(e){return e?this===e?e:(this.it.clone(e.it),e.pools=this.pools,e.filter=this.filter,e.index=this.index,e):new a(this.it,this.pools,this.filter,this.index)}swap(e){if(this===e)return;let t=this.it;this.it=e.it,e.it=t;let n=this.pools;this.pools=e.pools,e.pools=n;let r=this.filter;this.filter=e.filter,e.filter=r;let i=this.index;this.index=e.index,e.index=i}}return a});var X=class e{it;constructor(e){this.it=e.clone()}selfPlus(){return this.it.selfPlus(),this}write(e){throw Error(`Unsupported operation`)}deref(){return[this.it.deref(),...this.it.pools.flatMap(e=>e.getAsTuple(this.it.deref()))]}equals(e){return this.it.equals(e.it)}clone(t){return t?(this===t||this.it.clone(t.it),t):new e(this.it)}swap(e){this!==e&&this.it.swap(e.it)}base(){return this.it.clone()}};const Ae=k(function(e,t,n,r){let i=class{pools;filter;index;placeholder;static Iterator=ke.instantiate(e,t,n,r);static CommonType=e;static EntityType=e.EntityType;offset(){return this.pools[this.index].policy()===R.SwapOnly?Number(this.pools[this.index].freeList()):this.pools[this.index].size}uncheckedRefresh(){if(this.index=0,n>1)for(let e=1;e<n;++e)this.pools[e].size<this.pools[this.index].size&&(this.index=e)}constructor(t,i){if(this.placeholder=Te(e),Array.isArray(t)&&Array.isArray(i))this.pools=t,this.filter=i,this.index=n,this.uncheckedRefresh();else{this.pools=Array(n),this.filter=Array(r),this.index=n;for(let e=0,t=this.filter.length;e<t;++e)this.filter[e]=this.placeholder}}poolAt(e,t){if(e<0||e>=n)throw Error(`View pool index out of range`);if(t!==void 0)this.pools[e]=t,this.refresh();else return this.pools[e]}filterAt(e,t){if(e<0||e>=r)throw Error(`View filter index out of range`);if(t!==void 0)this.filter[e]=t;else return this.filter[e]===this.placeholder?null:this.filter[e]}noneOf(e){let t=L(this.filter);return Ee(t.begin(),t.end(),e)}use(e){this.index=this.index===n?n:e}refresh(){let e=Number(this.index!==n)*n;for(;e<n&&this.pools[e]!=null;++e);e===n&&this.uncheckedRefresh()}handle(){return this.index===n?null:this.pools[this.index]}sizeHint(){return this.index===n?0:this.offset()}begin(){return this.index===n?new i.Iterator:new i.Iterator(e.prototype.end.call(this.pools[this.index]).minus(this.offset()),this.pools,this.filter,this.index)}end(){return this.index===n?new i.Iterator:new i.Iterator(e.prototype.end.call(this.pools[this.index]),this.pools,this.filter,this.index)}front(){let t=this.begin();return t.equals(this.end())?e.TraitsType.null:t.deref()}back(){if(this.index!==n){let t=this.pools[this.index].rbegin(),n=t.plus(this.offset());for(let e=this.index;!t.equals(n)&&!(J(L(this.pools).begin(),L(this.pools).begin().plus(e),t.deref())&&J(L(this.pools).begin().plus(e).plus(1),L(this.pools).end(),t.deref())&&Ee(L(this.filter).begin(),L(this.filter).end(),t.deref()));t.selfPlus());return t.equals(n)?e.TraitsType.null:t.deref()}return e.TraitsType.null}find(e){return this.contains(e)?new i.Iterator(this.pools[this.index].find(e),this.pools,this.filter,this.index):this.end()}ok(){return this.index!==n&&De(L(this.filter).begin(),L(this.filter).end(),this.placeholder)}[Symbol.toPrimitive](){return this.ok()}contains(r){return this.index!==n&&(t?!e.isTombstone(r):!0)&&J(L(this.pools).begin(),L(this.pools).begin().plus(this.index),r)&&J(L(this.pools).begin().plus(this.index+1),L(this.pools).end(),r)&&this.noneOf(r)}[Symbol.iterator](){return I(this)}};return i}),Z=k(function(e,t){throw Error(`Invalid BasicView instantiation`)},[{predicate:(e,t)=>e.length===1&&(t==null||t.length===0),render(e,t){let n=e[0].constructor,r=Me.instantiate(n.BaseType,n.storagePolicy),i=r;class a extends r{static CommonType=i.CommonType;static EntityType=i.EntityType;static Iterator=i.Iterator;static ReverseIterator=i.ReverseIterator;constructor(e,t){super(Array.isArray(e)?e[0]:e)}getStorageByElementType(e){return this.getStorageByIndex(0)}getStorageByIndex(e=0){return super.handle()}setStorageByType(e){this.setStorage(0,e)}setStorage(e,t){this.leading=t}access(e){return this.getStorageByIndex()?.get(e)}getByElementType(e,t){if(t!==n.ElementType)throw Error(`Invalid element type`);return this.get(e,0)}get(e,t){return t==null?this.getStorageByIndex()?.getAsTuple(e)??[void 0]:this.getStorageByIndex(t)?.get(e)}each(e,t){if(e!=null&&typeof e==`function`){if(t)if(n.storagePolicy===R.SwapAndPop||n.storagePolicy===R.SwapOnly)if(n.ValueType===void 0)for(let t=super.size;t;--t)e.call(this);else{let t=super.size;if(t!==0)for(let n=this.getStorageByIndex().end(),r=n.minus(t);!r.equals(n);r.selfPlus())e.call(this,r.deref())}else for(let t of this.each())e.call(this,...t.slice(1));else for(let t of this.each())e.apply(this,t);return}return n.storagePolicy===R.SwapAndPop||n.storagePolicy===R.SwapOnly?super.handle()?this.getStorageByIndex().each():I(new F([new z]),new F([new z])):I(new X(super.begin()),new X(super.end()))}bitOr(e){let t=[this.leading,...e.pools??[e.leading]],n=Te(Y(...t.map(e=>e.constructor.BaseType))),r=e=>e??n,i=e.filter?[...e.filter.map((t,n)=>r(e.getStorageByIndex(e.pools.length+n)))]:[],a=new(Z.instantiate(t,i));return a.pools=t,a.filter=i,a.refresh(),a}}return a}},{predicate:(e,t)=>e.length!==0,render(e,t){let n=Ae.instantiate(Y(...e.map(e=>e.constructor.BaseType)),Ce(...e),e.length,t.length),r=n;class i extends n{static BaseType=r;static indexOf=n=>[...e.map(e=>e.constructor.ElementType),...t.map(e=>e.constructor.ElementType)].indexOf(n);get(e,...t){return t.map(t=>this.getStorageByIndex(t)?.getAsTuple(e)??[]).flat()}dispatchGet(e,t,n){return e===t?[n[e+1]]:this.getStorageByIndex(t)?.getAsTuple(n[0])??[]}_each(t,n,r,...i){let a=this.getStorageByIndex(t);for(let o of a.each()){let s=o[0];if((!Ce(...e)||!a.isTombstone(s))&&i.every(e=>t===e||super.poolAt(e).contains(s))&&super.noneOf(s)){let e=i.flatMap(e=>this.dispatchGet(t,e,o));r?n.apply(this,e):n.call(this,s,...e)}}}pickAndEach(e,t,...n){let r=super.handle();r!=null&&n.forEach(i=>{r===super.poolAt(i)&&this._each(i,e,t,...n)})}static CommonType=r.CommonType;static EntityType=r.EntityType;static Iterator=r.Iterator;constructor(e,t=[]){Array.isArray(e)&&Array.isArray(t)?super([...e],[...t]):super()}useByType(e){this.use(i.indexOf(e))}use(e){this.use(e)}getStorageByElementType(e){return this.getStorageByIndex(i.indexOf(e))}getStorageByIndex(t){return t<e.length?super.poolAt(t):super.filterAt(t-e.length)}setStorageByType(e){let t=i.indexOf(e.constructor.ElementType);this.setStorage(t,e)}setStorage(n,r){if(n<0||n>=e.length+t.length)throw Error(`View storage index out of range`);n<e.length?super.poolAt(n,r):super.filterAt(n-e.length,r)}access(e){return this.get(e)}getByElementType(e,...t){let n=this.get(e,...t.map(e=>i.indexOf(e)));return n.length===1?n[0]:n}getByIndexes(e,...t){return t.length===0?this.get(e):t.length===1?this.getStorageByIndex(t[0])?.get(e):t.map(t=>this.getStorageByIndex(t)?.getAsTuple(e)).flat()}each(t,n){if(t!=null&&typeof t==`function`)this.pickAndEach(t,n,...Array.from({length:e.length},(e,t)=>t));else return I(new X(super.begin()),new X(super.end()))}bitOr(e){let t=[...this.pools,...e.pools??[e.leading]],n=Te(Y(...t.map(e=>e.constructor.BaseType))),r=e=>e??n,i=[...this.filter.map((e,t)=>r(this.getStorageByIndex(this.pools.length+t))),...e.filter?e.filter.map((t,n)=>r(e.getStorageByIndex(e.pools.length+n))):[]],a=new(Z.instantiate(t,i));return a.pools=t,a.filter=i,a.refresh(),a}}return i}}]);function je(e,t=[]){return new(Z.instantiate(e,t))(e,t)}const Me=k(function(e,t){class n{leading;static CommonType=e;static EntityType=e.EntityType;static Iterator=t===R.InPlace?ke.instantiate(e,!0,1,0):e.Iterator;static ReverseIterator=t===R.InPlace?void 0:e.ReverseIterator;constructor(e){this.leading=e??null}handle(){return this.leading}get size(){if(t===R.InPlace)throw Error(`Size not available for in-place storage views`);return t===R.SwapAndPop?this.leading==null?0:Number(this.leading.size):this.leading==null?0:Number(this.leading.freeList())}sizeHint(){if(t!==R.InPlace)throw Error(`Size hint not available for non in-place storage views`);return this.leading==null?0:Number(this.leading.size)}empty(){if(t===R.InPlace)throw Error(`Empty not available for in-place storage views`);return t===R.SwapAndPop?!this.leading||this.leading.empty():!this.leading||Number(this.leading.freeList())===0}begin(){return t===R.SwapAndPop?this.leading?e.prototype.begin.call(this.leading):new n.Iterator:t===R.SwapOnly?this.leading?e.prototype.end.call(this.leading).minus(Number(this.leading.freeList())):new n.Iterator:this.leading?new n.Iterator(e.prototype.begin.call(this.leading),[this.leading],[],0):new n.Iterator}end(){return t===R.SwapAndPop||t===R.SwapOnly?this.leading?e.prototype.end.call(this.leading):new n.Iterator:this.leading?new n.Iterator(e.prototype.end.call(this.leading),[this.leading],[],0):new n.Iterator}rbegin(){if(t===R.InPlace)throw Error(`Reverse begin not available for in-place storage views`);return this.leading?e.prototype.rbegin.call(this.leading):new n.ReverseIterator(new e.BasicIterator)}rend(){if(t===R.InPlace)throw Error(`Reverse end not available for in-place storage views`);return t===R.SwapAndPop?this.leading?e.prototype.rend.call(this.leading):new n.ReverseIterator(new e.BasicIterator):this.leading?e.prototype.rend.call(this.leading).plus(Number(this.leading.freeList())):new n.ReverseIterator(new e.BasicIterator)}front(){if(t===R.SwapAndPop)return this.empty()?e.TraitsType.null:e.prototype.begin.call(this.leading).deref();if(t===R.SwapOnly)return this.empty()?e.TraitsType.null:e.prototype.end.call(this.leading).minus(Number(this.leading.freeList())).deref();{let t=this.begin();return t.equals(this.end())?e.TraitsType.null:t.deref()}}back(){if(t===R.SwapAndPop||t===R.SwapOnly)return this.empty()?e.TraitsType.null:e.prototype.rbegin.call(this.leading).deref();if(this.leading!=null){let t=e.prototype.rbegin.call(this.leading),n=e.prototype.rend.call(this.leading);for(;!t.equals(n)&&e.isTombstone(t.deref());t.selfPlus());return t.equals(n)?e.TraitsType.null:t.deref()}return e.TraitsType.null}find(e){if(t===R.SwapAndPop)return this.leading==null?new n.Iterator:this.leading.find(e);if(t===R.SwapOnly){let t=this.leading==null?new n.Iterator:this.leading.find(e);return this.leading!=null&&t.index()<Number(this.leading.freeList())?t:new n.Iterator}else return this.leading==null?new n.Iterator:new n.Iterator(this.leading.find(e),[this.leading],[],0)}ok(){return this.leading!=null}contains(e){return t===R.SwapAndPop||t===R.InPlace?this.leading?.contains(e):this.leading!=null&&this.leading.contains(e)&&this.leading.index(e)<Number(this.leading.freeList())}[Symbol.iterator](){return I(this)}}return n});var Ne=class e{it;owned;get;get pools(){return[...this.owned,...this.get]}indexToElement(e){return e.constructor.ValueType==null?[]:[e.rbegin().access(this.it.index())]}constructor(e,t,n){e&&t&&n?(this.it=e.clone(),this.owned=t,this.get=n):(this.it=new e,this.owned=[],this.get=[])}selfPlus(){return this.it.selfPlus(),this}write(e){return this.it.write(e),e}deref(){return[this.it.deref(),...this.owned.flatMap(e=>this.indexToElement(e)),...this.get.flatMap(e=>e.getAsTuple(this.it.deref()))]}equals(e){return this.it.equals(e.it)}clone(t){return t?this===t?t:(this.it.clone(t.it),this.owned=t.owned.slice(),this.get=t.get.slice(),t):new e(this.it,this.owned,this.get)}swap(e){if(this===e)return;this.it.swap(e.it);let t=this.owned;this.owned=e.owned,e.owned=t;let n=this.get;this.get=e.get,e.get=n}base(){return this.it.clone()}},Pe=class extends O{owned(e){return!1}};const Fe=k(function(e,t,n,r){class i extends Pe{static EntityType=e.EntityType;pools;filter;len;swapElements(e,n){for(let r=0;r<t;++r)this.pools[r].swapElements(this.pools[r].access(e),n)}pushOnConstruct(e){let t=this.len;((...n)=>{let[r,...i]=n;return r.contains(e)&&!(r.index(e)<t)&&i.every(t=>t.contains(e))})(...this.pools)&&((...t)=>t.every(t=>!t.contains(e)))(...this.filter)&&this.swapElements(this.len++,e)}pushOnDestroy(e){let t=this.len;((...n)=>{let[r,...i]=n;return r.contains(e)&&!(r.index(e)<t)&&i.every(t=>t.contains(e))})(...this.pools)&&((...t)=>t.reduce((t,n)=>t+Number(n.contains(e)),0)===1)(...this.filter)&&this.swapElements(this.len++,e)}removeIf(e){let t=this.pools;t[0].contains(e)&&t[0].index(e)<this.len&&this.swapElements(--this.len,e)}commonSetup(){let t=this.pools;for(let n=e.prototype.rbegin.call(t[0]),r=n.plus(t[0].size);!n.equals(r);n.selfPlus())this.pushOnConstruct(n.deref())}CommonType=e;constructor(e,a){super(),this.pools=Array(t+n),this.filter=Array(r);for(let r=0;r<t+n;++r)this.pools[r]=e[r];for(let e=0;e<r;++e)this.filter[e]=a[e];this.len=0,e.forEach(e=>{e.onConstruct().connect(function(e,t){i.prototype.pushOnConstruct.call(this,t)},this),e.onDestroy().connect(function(e,t){i.prototype.removeIf.call(this,t)},this)}),a.forEach(e=>{e.onConstruct().connect(function(e,t){i.prototype.removeIf.call(this,t)},this),e.onDestroy().connect(function(e,t){i.prototype.pushOnDestroy.call(this,t)},this)}),this.commonSetup()}owned(e){for(let n=0;n<t;++n)if(Object.is(this.pools[n].type(),e)||D(this.pools[n].type())===e)return!0;return!1}length(){return this.len}storage(e){return e<t+n?this.pools[e]:this.filter[e-(t+n)]}}return i},[{predicate:(e,t,n,r)=>t===0||r===void 0,render:(e,t,n,r)=>{r===void 0&&(r=n,n=t,t=0);let i=T(e);class a extends Pe{static EntityType=e.EntityType;pools;filter;elem;pushOnConstruct(e){!this.elem.contains(e)&&this.pools.every(t=>t.contains(e))&&this.filter.every(t=>!t.contains(e))&&this.elem.push(e)}pushOnDestroy(e){this.elem.contains(e)&&this.pools.every(t=>t.contains(e))&&this.filter.reduce((t,n)=>t+Number(n.contains(e)),0)===1&&this.elem.remove(e)}removeIf(e){this.elem.remove(e)}commonSetup(){let t=I(e.prototype.begin.call(this.pools[0]),e.prototype.end.call(this.pools[0]));for(let e of t)this.pushOnConstruct(e)}static CommonType=e;constructor(e,t){super(),this.pools=Array(n),this.filter=Array(r);for(let t=0;t<n;++t)this.pools[t]=e[t];for(let e=0;e<r;++e)this.filter[e]=t[e];this.elem=i(),e.forEach(e=>{e.onConstruct().connect(function(e,t){a.prototype.pushOnConstruct.call(this,t)},this),e.onDestroy().connect(function(e,t){a.prototype.removeIf.call(this,t)},this)}),t.forEach(e=>{e.onConstruct().connect(function(e,t){a.prototype.removeIf.call(this,t)},this),e.onDestroy().connect(function(e,t){a.prototype.pushOnDestroy.call(this,t)},this)}),this.commonSetup()}handle(){return this.elem}storage(e){return e<n?this.pools[e]:this.filter[e-n]}}return a}}]),Q=k(function(e,t,n){throw Error(`Invalid BasicGroup instantiation`)},[{predicate:(e,t,n)=>e.length===0||e==null||Array.isArray(e)&&Array.isArray(t)&&n===void 0,render(e,t,n){Array.isArray(e)&&Array.isArray(t)&&n===void 0&&(n=t,t=e);let r=Y(...t.map(e=>e.constructor.BaseType),...n.map(e=>e.constructor.BaseType)),i=r.EntityType,a=Fe.instantiate(r,0,t.length,n.length);if(t.length===0)throw Error(`Non-owning group must have at least one get type`);class o{static BaseType=r;static UnderlyingType=i;static indexOf(e){return[...t.map(e=>e.constructor.ElementType),...n.map(e=>e.constructor.ElementType)].indexOf(e)}poolsFor(...e){return this.descriptor?e.map(e=>this.descriptor.storage(e)):[]}static EntityType=i;static CommonType=r;static Iterator=r.Iterator;static ReverseIterator=r.ReverseIterator;static Handler=a;descriptor;static groupId(){return D([`non-owning`,...t,...n])}constructor(e){this.descriptor=e??null}handle(){return this.descriptor.handle()}storage(e){return typeof e==`number`?this.ok()?this.descriptor.storage(e):null:this.storage(o.indexOf(e))}ok(){return this.descriptor!=null}get size(){return this.ok()?this.handle().size:0}capacity(){return this.ok()?this.handle().capacity():0}empty(){return!this.ok()||this.handle().empty()}begin(){return this.ok()?this.handle().begin():new r.Iterator}end(){return this.ok()?this.handle().end():new r.Iterator}rbegin(){return this.ok()?this.handle().rbegin():new r.ReverseIterator(new r.Iterator)}rend(){return this.ok()?this.handle().rend():new r.ReverseIterator(new r.Iterator)}front(){let e=this.begin();return e.equals(this.end())?r.TraitsType.null:e.deref()}back(){let e=this.rbegin();return e.equals(this.rend())?r.TraitsType.null:e.deref()}find(e){return this.ok()?this.handle().find(e):new r.Iterator}access(e){return this.begin().access(e)}contains(e){return this.ok()&&this.handle().contains(e)}get(e,...t){return this.getByIndexes(e,...t.map(e=>o.indexOf(e)))}getByIndexes(e,...n){let r=this.poolsFor(...Array.from({length:t.length},(e,t)=>t));return n.length===0?r.flatMap(t=>t.getAsTuple(e)):n.length===1?r[n[0]].get(e):n.flatMap(t=>r[t].getAsTuple(e))}each(e,n){if(typeof e==`function`)for(let t of this){let r=this.get(t);n?e.apply(this,r):e.call(this,t,...r)}else{let e=this.poolsFor(...Array.from({length:t.length},(e,t)=>t));return new P(new Ne(this.begin(),[],e),new Ne(this.end(),[],e))}}[Symbol.iterator](){return I(this)}sort(e,t,n=l){this.sortByIndexes(e,t.map(e=>o.indexOf(e)),n)}sortByIndexes(e,t,n=l){if(this.ok())if(t.length===0)this.descriptor.handle().sort(e,n);else{let r=this.poolsFor(...t);this.descriptor.handle().sort((n,i)=>t.length===1?e(r[t[0]].get(n),r[t[0]].get(i)):e(t.map(e=>r[e].get(n)),t.map(e=>r[e].get(i))),n)}}sortAs(e,t){this.ok()&&this.descriptor.handle().sortAs(e,t)}}return o}},{predicate:(e,t,n)=>e.length>0,render(e,t,n){let r=Y(...e.map(e=>e.constructor.BaseType),...t.map(e=>e.constructor.BaseType),...n.map(e=>e.constructor.BaseType)),i=r.EntityType,a=Fe.instantiate(r,e.length,t.length,n.length);class o{static BaseType=r;static UnderlyingType=i;static indexOf(r){return[...e.map(e=>e.constructor.ElementType),...t.map(e=>e.constructor.ElementType),...n.map(e=>e.constructor.ElementType)].indexOf(r)}poolsFor(t,n){return this.descriptor?[...t.map(e=>this.descriptor.storage(e)),...n.map(t=>this.descriptor.storage(t+e.length))]:[]}static EntityType=i;static CommonType=r;static Iterator=r.Iterator;static ReverseIterator=r.ReverseIterator;static Handler=a;descriptor;static groupId(){return D([e,t,n])}constructor(e){this.descriptor=e??null}handle(){return this.storage(0)}ok(){return this.descriptor!=null}storage(e){return typeof e==`number`?this.ok()?this.descriptor.storage(e):null:this.storage(o.indexOf(e))}get size(){return this.ok()?this.descriptor.length():0}empty(){return!this.ok()||!this.descriptor.length()}begin(){return this.ok()?r.prototype.end.call(this.handle()).minus(this.descriptor.length()):new r.Iterator}end(){return this.ok()?r.prototype.end.call(this.handle()):new r.Iterator}rbegin(){return this.ok()?r.prototype.rbegin.call(this.handle()):new r.ReverseIterator(new r.Iterator)}rend(){return this.ok()?r.prototype.rbegin.call(this.handle()).plus(this.descriptor.length()):new r.ReverseIterator(new r.Iterator)}front(){let e=this.begin();return e.equals(this.end())?r.TraitsType.null:e.deref()}back(){let e=this.rbegin();return e.equals(this.rend())?r.TraitsType.null:e.deref()}find(e){let t=this.ok()?this.handle().find(e):new r.Iterator;return t.gte(this.begin())?t:new r.Iterator}access(e){return this.begin().access(e)}contains(e){return this.ok()&&this.handle().contains(e)&&this.handle().index(e)<this.descriptor.length()}get(e,...t){return this.getByIndexes(e,...t.map(e=>o.indexOf(e)))}getByIndexes(n,...r){let i=this.poolsFor(Array.from({length:e.length},(e,t)=>t),Array.from({length:t.length},(e,t)=>t));return r.length===0?i.flatMap(e=>e.getAsTuple(n)):r.length===1?i[r[0]].get(n):r.flatMap(e=>i[e].getAsTuple(n))}each(n,r){if(typeof n==`function`)for(let e of this.each())r?n.apply(this,e.slice(1)):n.apply(this,e);else{let n=this.poolsFor(Array.from({length:e.length},(e,t)=>t),Array.from({length:t.length},(e,t)=>t)),r=this.begin(),i=this.end();return new P(new Ne(r,n.slice(0,e.length),n.slice(e.length)),new Ne(i,n.slice(0,e.length),n.slice(e.length)))}}[Symbol.iterator](){return I(this)}sort(e,t,n=l){this.sortByIndexes(e,t.map(e=>o.indexOf(e)),n)}sortByIndexes(n,r,i=l){let a=this.poolsFor(Array.from({length:e.length},(e,t)=>t),Array.from({length:t.length},(e,t)=>t));r.length===0?this.storage(0).sortN(this.descriptor.length(),n,i):this.storage(0).sortN(this.descriptor.length(),(e,t)=>r.length===1?n(a[r[0]].get(e),a[r[0]].get(t)):n(r.map(t=>a[t].get(e)),r.map(e=>a[e].get(t))),i),((...e)=>{let[t,...n]=e;for(let e=this.descriptor.length();e;--e){let r=e-1,i=t.data()[r];n.forEach(e=>{e.swapElements(e.data()[r],i)})}}).apply(this,a)}}return o}}]);function Ie(e,t,n=[]){return new(Q.instantiate(e,t,n))}const Le=k(function(e){let t=q.instantiate(e,e),n=t.TraitsType,r=n.ValueType,i=B.instantiate(e);return class extends O{static TraitsType=n;static EntityType=r;static CommonType=i;entities;vars;groups;pools;constructor(){super(),this.entities=new t,this.entities.bind(this),this.vars=Object.create(null),this.groups=new Map,this.pools=new Map}dispose(){for(let e of this.groups.values())e.dispose();this.groups.clear();for(let e of this.pools.values())e.dispose();this.pools.clear(),this.entities.dispose(),Object.keys(this.vars).forEach((e,t)=>{delete this.vars[t]})}assure(e){let[t,n]=d(e);if(typeof t!=`function`&&t!==void 0)throw Error(`Invalid component type`);if(Object.is(t,r))return this.entities;if(this.pools.has(n))return this.pools.get(n),this.pools.get(n);let i=new(q.instantiate(t,r));return this.pools.set(n,i),i.bind(this),i}constAssure(e){let[t,n]=d(e);if((typeof t==`function`||t===void 0)&&Object.is(t,r))return this.entities;let i=this.pools.get(n);if(i)return i}ctx(){return this.vars}create(e){return this.entities.generate(e)}createRange(e,t){this.entities.generateRange(e,t)}insert(e,t,n,r){n=n.clone(),this.assure(e).insert(t,n,r)}insertRange(e,t,n,r){n=n.clone(),this.assure(e).insertRange(t,n,r)}storage(){return this.pools.entries()}getStorage(e,t=!1){return!t&&(typeof e==`function`||Array.isArray(e)||e===void 0)?this.assure(e):this.constAssure(e)}reset(e){return this.pools.delete(e)}valid(e){let t=this.entities.find(e).index();return t>=0&&t<this.entities.freeList()}current(e){return this.entities.current(e)}destroy(e,t){let r=[...this.pools.values()];for(let t=r.length-1;t>=0;--t)r[t].remove(e);this.entities.erase(e);let i=this.entities.current(e);if(t!==void 0){let r=n.construct(n.toEntity(e),t);return this.entities.bump(n.isTombstone(r)?n.next(r):r)}return i}destroyRange(e,t){let n=t==null?this.entities.sortAs(e):this.entities.sortAs(e,t),r=this.entities.end().minus(Number(this.entities.freeList()));for(let e of this.pools.values())e.remove(r,n);this.entities.erase(r,n)}emplace(e,t,...n){return this.assure(t).emplace(e,...n)}emplaceOrReplace(e,t,...n){let r=this.assure(t);return r.has(e)?r.patch(e,()=>T(r.type())(...n)):r.emplace(e,...n)}patch(e,t,...n){return this.assure(t).patch(e,...n)}replace(e,t,...n){let r=this.assure(t);return r.patch(e,()=>T(r.type())(...n))}remove(e,...t){let n=0;for(let r of t)this.assure(r).delete(e)&&++n;return n}removeRange(e,t,...n){let r=0;if(e=e.clone(),t=t.clone(),e instanceof z&&t instanceof z){let i=n.map(e=>this.assure(e)),a=L(i),o=a.begin(),s=a.end();for(;!o.equals(s);o.selfPlus()){if(n.length>1&&o.deref().data()===e.data()){let e=o.deref();o.write(i[i.length-1]),i[i.length-1]=e}r+=o.deref().remove(e,t)}}else for(let i=n.map(e=>this.assure(e));!e.equals(t);e.selfPlus()){let t=e.deref();for(let e of i)r+=e.remove(t)?1:0}return r}eraseIf(e,t){for(let[n,r]of this.storage())r.contains(e)&&t(n,r)&&r.erase(e)}erase(e,...t){for(let n of t)this.assure(n).erase(e)}eraseRange(e,t,...n){if(e=e.clone(),t=t.clone(),e instanceof z&&t instanceof z){let r=n.map(e=>this.assure(e)),i=L(r),a=i.begin(),o=i.end();for(;!a.equals(o);a.selfPlus()){if(n.length>1&&a.deref().data()===e.data()){let e=a.deref();a.write(r[r.length-1]),r[r.length-1]=e}a.deref().erase(e,t)}}else for(let r=n.map(e=>this.assure(e));!e.equals(t);e.selfPlus()){let t=e.deref();for(let e of r)e.erase(t)}}compact(...e){if(e.length===0)for(let e of this.pools.values())e.compact();else for(let t of e)this.assure(t).compact()}allOf(e,...t){if(t.length===1){let n=this.constAssure(t[0]);return n!=null&&n?.has(e)}return t.every(t=>this.allOf(e,t))}anyOf(e,...t){return t.some(t=>this.allOf(e,t))}tryGet(e,...t){if(t.length===1){let n=this.constAssure(t[0]);return n&&n.has(e)?n.get(e):void 0}return t.map(t=>this.tryGet(e,t))}get(e,...t){return t.length===1?this.assure(t[0]).get(e):t.map(t=>this.get(e,t))}getOrEmplace(e,t,...n){let r=this.assure(t);return r.has(e)?r.get(e):r.emplace(e,...n)}clear(...e){if(e.length===0){let e=[...this.pools.values()];for(let t=e.length-1;t>=0;--t)e[t].clear();let t=this.entities.each();this.entities.erase(t.begin().base(),t.end().base())}else e.forEach(e=>{this.assure(e).clear()})}orphan(e){return![...this.pools.values()].some(t=>t.has(e))}onConstruct(e){return this.assure(e).onConstruct()}onUpdate(e){return this.assure(e).onUpdate()}onDestroy(e){return this.assure(e).onDestroy()}sort(e,t,n=l){let r=this.assure(e);r.sort((e,n)=>t(r.get(e),r.get(n)),n)}sortByEntity(e,t,n=l){this.assure(e).sort(t,n)}sortAs(e,t){let n=this.assure(t);this.assure(e).sortAs(n.begin(),n.end())}view(e,t=[]){let n=e.map(e=>this.assure(e)),r=t.map(e=>this.assure(e));return new(Z.instantiate(n,r))(n,r)}group(e,t=[],n=[]){let r=e.map(e=>this.assure(e)),i=t.map(e=>this.assure(e)),a=n.map(e=>this.assure(e)),o=Q.instantiate(r,i,a),s=o.Handler;if(this.groups.has(o.groupId()))return new o(this.groups.get(o.groupId()));let c;return c=r.length===0?new s(i,a):new s([...r,...i],a),this.groups.set(o.groupId(),c),new o(c)}groupIfExists(e,t=[],n=[]){let r=e.map(e=>this.assure(e)),i=t.map(e=>this.assure(e)),a=n.map(e=>this.assure(e)),o=Q.instantiate(r,i,a);return this.groups.has(o.groupId())?new o(this.groups.get(o.groupId())):new o}owned(...e){for(let t of this.groups.values())if(e.some(e=>t.owned(e)))return!0;return!1}}}),Re=(()=>Le.instantiate(x))();var $=class e{pools;filter;it;tombstoneCheck;valid(){let e=this.it.deref();return(!this.tombstoneCheck||!this.pools[0].isTombstone(e))&&this.pools.every(t=>t.contains(e))&&!this.filter.some(t=>t?.contains(e))}constructor(e,t,n){e!=null&&t!=null&&n!=null?(this.pools=e,this.it=t.clone(),this.filter=n,this.tombstoneCheck=e.length===1&&e[0].policy()===R.InPlace,!this.it.equals(V.prototype.end.call(e[0]))&&!this.valid()&&this.selfPlus()):(this.pools=[],this.it=new z,this.filter=[],this.tombstoneCheck=!1)}clone(t){if(t)return t===this?this:(t.pools=this.pools.slice(),t.it=this.it.clone(),t.filter=this.filter.slice(),t.tombstoneCheck=this.tombstoneCheck,t);let n=new e;return n.pools=this.pools.slice(),n.it=this.it.clone(),n.filter=this.filter.slice(),n.tombstoneCheck=this.tombstoneCheck,n}swap(e){if(this===e)return;this.it.swap(e.it);let t=this.pools,n=this.filter,r=this.tombstoneCheck;this.pools=e.pools,this.filter=e.filter,this.tombstoneCheck=e.tombstoneCheck,e.pools=t,e.filter=n,e.tombstoneCheck=r}write(e){return this.it.write(e)}deref(){return this.it.deref()}selfPlus(){this.it.selfPlus();for(let e=V.prototype.end.call(this.pools[0]);!this.it.equals(e)&&!this.valid();this.it.selfPlus());return this}selfMinus(){this.it.selfMinus();for(let e=V.prototype.begin.call(this.pools[0]);!this.it.equals(e)&&!this.valid();this.it.selfMinus());return this}equals(e){return this.it.equals(e.it)}};const ze=k(function(e){class t extends O{pools;filter;offset(){let e=this.pools[0];return e.policy()===R.SwapOnly?Number(e.freeList()):e.size}static EntityType=e.EntityType;static CommonType=e;static Iterator=$;constructor(){super(),this.pools=[],this.filter=[]}dispose(){this.pools.length=0,this.filter.length=0}clear(){this.pools.length=0,this.filter.length=0}iterate(e){if(this.pools.length===0||!(e.size<this.pools[0].size))this.pools.push(e);else{let t=this.pools[0];this.pools[0]=e,this.pools.push(t)}return this}exclude(e){return this.filter.push(e),this}sizeHint(){return this.pools.length===0?0:this.offset()}begin(){return this.pools.length===0?new $:new $(this.pools,e.prototype.end.call(this.pools[0]).minus(this.offset()),this.filter)}end(){return this.pools.length===0?new $:new $(this.pools,e.prototype.end.call(this.pools[0]),this.filter)}ok(){return!(this.pools.length===0&&this.filter.length===0)}contains(e){return this.pools.length!==0&&this.pools.every(t=>t.contains(e))&&!this.filter.some(t=>t?.contains(e))&&this.pools[0].index(e)<this.offset()}each(e){for(let t of this)e(t)}[Symbol.iterator](){return I(this.begin(),this.end())}}return t}),Be=(()=>ze.instantiate(V))();function Ve(e){let t=e.getStorage(e.constructor.EntityType);for(let n of t)e.orphan(n)&&t.erase(n)}const He=k(function(e){let t=A.instantiate(e.EntityType),n=e.EntityType;class r extends O{static TraitsType=t;static RegistryType=e;static EntityType=n;reg;constructor(e){super(),this.reg=e}dispose(){this.reg=null}get(r,i){let[a]=d(i),o=this.reg.getStorage(i,!0);if(o){let i=o;if(r.saveSize(t.EntityType(o.size)),a===n){r.saveSize(t.EntityType(o.freeList()));let n=e.CommonType.prototype.rbegin.call(i),a=e.CommonType.prototype.rend.call(i);for(;!n.equals(a);n.selfPlus())r.saveEntity(n.deref())}else if(q.instantiate(a,e.EntityType).storagePolicy===R.InPlace){let n=e.CommonType.prototype.rbegin.call(i),a=e.CommonType.prototype.rend.call(i);for(;!n.equals(a);n.selfPlus()){let i=n.deref();if(e.CommonType.isTombstone(i))r.saveEntity(t.null);else{r.saveEntity(i);let e=o.getAsTuple(i);for(let t=0;t<e.length;++t)r.saveComponent(e[t])}}}else for(let e of o.reach())r.saveEntity(e[0]),e.length>1&&r.saveComponent(e[1])}else r.saveSize(t.EntityType(0));return this}getRange(e,n,r,i){let[a]=d(i),o=this.reg.getStorage(i,!0);if(o&&!o.empty())for(e.saveSize(t.EntityType(fe(n,r))),n=n.clone(),r=r.clone();!n.equals(r);n.selfPlus()){let r=n.deref();if(o.contains(r)){e.saveEntity(r);let t=o.getAsTuple(r);for(let n=0;n<t.length;++n)e.saveComponent(t[n])}else e.saveEntity(t.null)}else e.saveSize(t.EntityType(0));return this}}return r}),Ue=k(function(e){let t=A.instantiate(e.EntityType),n=e.EntityType,r=T(n);class i extends O{static TraitsType=t;static RegistryType=e;static EntityType=n;reg;constructor(e){super(),this.reg=e}dispose(){this.reg=null}get(e,i){let[a]=d(i),o=this.reg.getStorage(i),s=new f(t.EntityType(0));if(e.loadSize(s),a===n){let n=new f(t.EntityType(0)),i=r();o.reserve(s.value),e.loadSize(n);let a=new f(t.null);for(;s.value>0;--s.value)e.loadEntity(a),o.generate(a.value),i=a.value>i?a.value:i;o.startFrom(t.next(i)),o.freeList(n.value)}else{let r=this.reg.getStorage(n),i=new f(t.null),c=H.instantiate(o.constructor.ElementType,o.constructor.EntityType).pageSize===0,l=c?(()=>void 0):T(a);for(;s.value--;)if(e.loadEntity(i),!t.isNull(i.value)){let t=r.contains(i.value)?i.value:r.generate(i.value);if(c)o.emplace(t);else{let n=new f(l());e.loadComponent(n),o.emplace(t,n.value)}}}return this}orphans(){return Ve(this.reg),this}}return i}),We=k(function(e){let t=A.instantiate(e.EntityType),n=e.EntityType;class r extends O{static RegistryType=e;static EntityType=n;static TraitsType=t;remloc;reg;restore(e){let n=t.toEntity(e),r=this.remloc.get(n);r!==void 0&&t.toIntegral(r[0])===t.toIntegral(e)?this.reg.valid(r[1])||(r[1]=this.reg.create()):this.remloc.set(n,[e,this.reg.create()])}constructor(e){super(),this.remloc=new Map,this.reg=e}dispose(){this.remloc.clear(),this.reg=null}get(e,r){let[i]=d(r),a=this.reg.getStorage(r),o=new f(t.EntityType(0)),s=new f(t.null);if(e.loadSize(o),i===n){let n=new f(t.EntityType(0));a.reserve(o.value),e.loadSize(n);for(let t=0;t<n.value;++t)e.loadEntity(s),this.restore(s.value);for(let r=n.value;r<o.value;++r){e.loadEntity(s);let n=t.toEntity(s.value),r=this.remloc.get(n);r!==void 0&&(this.reg.valid(r[1])&&this.reg.destroy(r[1]),this.remloc.delete(n))}}else{for(let e of this.remloc.values())a.remove(e[1]);let n=H.instantiate(a.constructor.ElementType,a.constructor.EntityType).pageSize===0,r=n?(()=>void 0):T(i);for(;o.value--;)if(e.loadEntity(s),!t.isNull(s.value))if(this.restore(s.value),n)a.emplace(this.map(s.value));else{let t=new f(r());e.loadComponent(t),a.emplace(this.map(s.value),t.value)}}return this}orphans(){return Ve(this.reg),this}contains(e){let n=this.remloc.get(t.toEntity(e));return n!==void 0&&t.toIntegral(n[0])===t.toIntegral(e)}map(e){let n=this.remloc.get(t.toEntity(e));return n!==void 0&&t.toIntegral(n[0])===t.toIntegral(e)?n[1]:t.null}}return r}),Ge=(()=>He.instantiate(Re))(),Ke=(()=>Ue.instantiate(Re))(),qe=(()=>We.instantiate(Re))(),Je=`0.0.0`;export{F as AggregatePointer,ue as ArrayPointer,de as ArrayRange,ve as BasicDispatcher,me as Connection,qe as ContinuousLoader,pe as Delegate,R as DeletionPolicy,O as Disposable,ye as Emitter,S as EmptyTypeOptimization,x as Entity,m as Float32,h as Float64,Pe as GroupDescriptor,te as Int16,v as Int32,ne as Int64,ee as Int8,e as NotConstructorError,P as RangeIterator,Re as Registry,j as ReversePointer,Be as RuntimeView,$ as RuntimeViewIterator,he as ScopedConnection,W as Sigh,U as Sink,Ge as Snapshot,Ke as SnapshotLoader,V as SparseSet,z as SparseSetPointer,G as StoragePointer,se as Template,g as Uint16,_ as Uint32,b as Uint64,p as Uint8,We as basicContinuousLoaderTemplate,le as basicEnttTraitsTemplate,Q as basicGroupTemplate,Le as basicRegistryTemplate,ze as basicRuntimeViewTemplate,be as basicSighMixinTemplate,Ue as basicSnapshotLoaderTemplate,He as basicSnapshotTemplate,B as basicSparseSetTemplate,K as basicStorageTemplate,Z as basicViewTemplate,Y as commonType,H as componentTraitsTemplate,w as config,T as createSafeNew,k as defineTemplate,C as directCall,fe as distance,A as enttTraitsTemplate,u as insertionSort,ce as internalEnttTraits,ie as isEmptyClass,Ie as makeGroup,N as makeRangePointer,M as makeReversePointer,je as makeView,l as stdSort,xe as storageTemplate,q as storageTypeTTemplate,Se as storageTypeTemplate,I as toIterator,L as toRange,Je as version};
|