@oasys/oecs 0.5.2 → 0.5.3

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/core/ecs/ecs_memory.d.cts +6 -6
  3. package/dist/core/ecs/ecs_memory.d.ts +6 -6
  4. package/dist/core/ecs/ecs_memory.d.ts.map +1 -1
  5. package/dist/core/store/allocator.d.cts +44 -19
  6. package/dist/core/store/allocator.d.ts +44 -19
  7. package/dist/core/store/allocator.d.ts.map +1 -1
  8. package/dist/core/store/column_store.d.cts +1 -1
  9. package/dist/core/store/column_store.d.ts +1 -1
  10. package/dist/core/store/extend.d.ts.map +1 -1
  11. package/dist/core/store/grow.d.ts.map +1 -1
  12. package/dist/core/store/layout_ops.d.cts +18 -0
  13. package/dist/core/store/layout_ops.d.ts +18 -0
  14. package/dist/core/store/layout_ops.d.ts.map +1 -1
  15. package/dist/{host_commands-BI8pEmjH.js → host_commands-3jyFfWNg.js} +2 -2
  16. package/dist/{host_commands-CxhpzMx9.cjs → host_commands-DNf0f6ko.cjs} +1 -1
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.d.cts +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.development.cjs +1 -1
  21. package/dist/index.development.js +197 -194
  22. package/dist/index.js +195 -192
  23. package/dist/{internal-BMDgWZbt.js → internal-C9jjL90H.js} +2 -2
  24. package/dist/{internal-LiTSB_tG.cjs → internal-RZN14uMw.cjs} +2 -2
  25. package/dist/internal.cjs +1 -1
  26. package/dist/internal.development.cjs +1 -1
  27. package/dist/internal.development.js +1 -1
  28. package/dist/internal.js +1 -1
  29. package/dist/shared-BMXh9hxm.cjs +1 -0
  30. package/dist/{shared-BU1Cd40h.js → shared-DQKK0i-E.js} +38 -32
  31. package/dist/shared.cjs +1 -1
  32. package/dist/shared.d.cts +1 -1
  33. package/dist/shared.d.ts +1 -1
  34. package/dist/shared.development.cjs +1 -1
  35. package/dist/shared.development.js +1 -1
  36. package/dist/shared.js +1 -1
  37. package/dist/version.d.cts +1 -1
  38. package/dist/version.d.ts +1 -1
  39. package/package.json +1 -1
  40. package/dist/shared-BymrGTyR.cjs +0 -1
@@ -1,4 +1,4 @@
1
- import { D as st, h as j, w as Ne, g as rt } from "./shared-BU1Cd40h.js";
1
+ import { D as st, h as j, w as Ne, g as rt } from "./shared-DQKK0i-E.js";
2
2
  import { S as ot, t as it } from "./topological_sort-DK6EjpWa.js";
3
3
  class Ye extends Error {
4
4
  constructor(e, n, r) {
@@ -2056,7 +2056,7 @@ function ms(t) {
2056
2056
  intentLabel: `pure-TS heap backing (${S(s)} growable cap, no SharedArrayBuffer)`,
2057
2057
  budgetEntities: null,
2058
2058
  derivation: [
2059
- `backing = heap_arraybuffer_allocator(${S(s)}) — resizable ArrayBuffer, no SAB / no COOP+COEP (is_in_place ✓)`,
2059
+ `backing = heap_arraybuffer_allocator(${S(s)}) — fixed ArrayBuffer reserved at the cap, no SAB / no COOP+COEP (is_in_place ✓)`,
2060
2060
  "trade-off: no worker offload / no WASM backend (both need a transferable SharedArrayBuffer)",
2061
2061
  `column_capacity = ${o} (${n !== void 0 ? "pinned" : "default"})`,
2062
2062
  `entity_index = floor_pow2(cap/4 ÷ ${R} B) = ${i} slots`
@@ -1,2 +1,2 @@
1
- "use strict";const P=require("./shared-BymrGTyR.cjs"),We=require("./topological_sort-BDvEyb9W.cjs");class ze extends Error{constructor(e,n,r){super(e),this.isOperational=n,this.context=r,this.name=this.constructor.name,Error.captureStackTrace(this,this.constructor)}}var Se=(t=>(t.ASSERTION_FAIL_CONDITION="ASSERTION_FAIL_CONDITION",t.VALIDATION_FAIL_CONDITION="VALIDATION_FAIL_CONDITION",t.ASSERTION_FAIL_NON_NULLABLE="ASSERTION_FAIL_NON_NULLABLE",t.ASSERTION_FAIL_UNREACHABLE="ASSERTION_FAIL_UNREACHABLE",t))(Se||{});class qe extends ze{constructor(e,n,r){super(n,!1,r),this.category=e}}const Et=t=>Number.isInteger(t)&&t>=0;function mt(t,e,n){if(!e(t))throw new qe(Se.VALIDATION_FAIL_CONDITION,`Expected value to meet validation: ${n}`);return t}function gt(t){return t}function pt(t,e){throw new qe(Se.ASSERTION_FAIL_UNREACHABLE,`Unhandled ${e}: ${String(t)}`)}var p=(t=>(t.EID_MAX_INDEX_OVERFLOW="EID_MAX_INDEX_OVERFLOW",t.EID_MAX_GEN_OVERFLOW="EID_MAX_GEN_OVERFLOW",t.COMPONENT_NOT_REGISTERED="COMPONENT_NOT_REGISTERED",t.COMPONENT_LIMIT_EXCEEDED="COMPONENT_LIMIT_EXCEEDED",t.ENTITY_NOT_ALIVE="ENTITY_NOT_ALIVE",t.CIRCULAR_SYSTEM_DEPENDENCY="CIRCULAR_SYSTEM_DEPENDENCY",t.DUPLICATE_SYSTEM="DUPLICATE_SYSTEM",t.ARCHETYPE_NOT_FOUND="ARCHETYPE_NOT_FOUND",t.RESOURCE_NOT_REGISTERED="RESOURCE_NOT_REGISTERED",t.RESOURCE_ALREADY_REGISTERED="RESOURCE_ALREADY_REGISTERED",t.EVENT_ALREADY_REGISTERED="EVENT_ALREADY_REGISTERED",t.EVENT_NOT_REGISTERED="EVENT_NOT_REGISTERED",t.FIELD_NOT_REGISTERED="FIELD_NOT_REGISTERED",t.RELATION_NOT_REGISTERED="RELATION_NOT_REGISTERED",t.RELATION_MODE_INVALID="RELATION_MODE_INVALID",t.RELATION_MODE_MISMATCH="RELATION_MODE_MISMATCH",t.RELATION_CYCLE="RELATION_CYCLE",t.SPARSE_CACHE_KEY_OVERFLOW="SPARSE_CACHE_KEY_OVERFLOW",t.SPARSE_QUERY_DENSE_PATH="SPARSE_QUERY_DENSE_PATH",t.HIERARCHY_ALREADY_SET="HIERARCHY_ALREADY_SET",t.HIERARCHY_INVALID_MAX_DEPTH="HIERARCHY_INVALID_MAX_DEPTH",t.OBSERVER_NON_CONVERGENT="OBSERVER_NON_CONVERGENT",t.OBSERVER_INVALID_CONFIG="OBSERVER_INVALID_CONFIG",t.OBSERVER_ONSET_EMIT="OBSERVER_ONSET_EMIT",t.INVALID_FIXED_TIMESTEP="INVALID_FIXED_TIMESTEP",t.INVALID_MAX_FIXED_STEPS="INVALID_MAX_FIXED_STEPS",t.INVALID_RECORDER_SCHEDULE="INVALID_RECORDER_SCHEDULE",t.EMPTY_ARCHETYPE_MATERIALIZE="EMPTY_ARCHETYPE_MATERIALIZE",t.COMPONENT_INDEX_INVARIANT="COMPONENT_INDEX_INVARIANT",t.OPTIONAL_TERM_NOT_DECLARED="OPTIONAL_TERM_NOT_DECLARED",t.QUERY_ACCESS_UNDECLARED="QUERY_ACCESS_UNDECLARED",t.ACCESS_UNDECLARED="ACCESS_UNDECLARED",t.QUERY_NOT_SINGLETON="QUERY_NOT_SINGLETON",t.INVALID_RUN_CONDITION="INVALID_RUN_CONDITION",t.SYSTEM_FN_ARITY="SYSTEM_FN_ARITY",t.PARTITION_APPEND_NEEDS_ENTITY_ROW="PARTITION_APPEND_NEEDS_ENTITY_ROW",t.PARTITION_BULK_INTO_DISABLED="PARTITION_BULK_INTO_DISABLED",t.ENTITY_NOT_DISABLED="ENTITY_NOT_DISABLED",t.STRUCTURAL_DURING_ITERATION="STRUCTURAL_DURING_ITERATION",t.BACKEND_ALREADY_ATTACHED="BACKEND_ALREADY_ATTACHED",t.DETERMINISM_DISABLED="DETERMINISM_DISABLED",t.NON_DETERMINISTIC_COLUMN_TYPE="NON_DETERMINISTIC_COLUMN_TYPE",t.INVALID_MEMORY_OPTIONS="INVALID_MEMORY_OPTIONS",t.STORE_CAP_EXCEEDED="STORE_CAP_EXCEEDED",t.REGION_NOT_DECLARED="REGION_NOT_DECLARED",t.COMMAND_LOG_TAG_COLLISION="COMMAND_LOG_TAG_COLLISION",t.INVALID_FRAME_STEP="INVALID_FRAME_STEP",t))(p||{});class T extends ze{constructor(e,n,r){super(n??e,!0,r),this.category=e}}function Tt(t){return t instanceof T}const At=-1,yt=-1,It=Object.freeze(Object.create(null)),St=2654435769,wt=1367130551,F=1024,Nt=0,Rt=31,Dt=1/60,Ot=4,Ct=0,W=20,we=(1<<W)-1,L=we,bt=Rt-W,J=(1<<bt)-1,Ut=J,vt=J-1,ge=J<<W|L,Lt=(t,e)=>{{if(t<0||t>L)throw new T(p.EID_MAX_INDEX_OVERFLOW);if(e<0||e>J)throw new T(p.EID_MAX_GEN_OVERFLOW)}return e<<W|t},v=t=>t&we,pe=t=>t>>W,Mt=(t,e,n)=>new T(p.ENTITY_NOT_ALIVE,`${t}: entity ${e} (index ${v(e)}, generation ${pe(e)}) is not alive${n?` — ${n}`:""} (destroyed, never created, or a stale handle; guard with isAlive() first)`,{entity:e,index:v(e),generation:pe(e),op:t}),Ne=new WeakMap;function Pt(t,e){Ne.set(t,e)}function $t(t){return Ne.get(t)}function Ke(t){const e=Ne.get(t);return e!==void 0?`'${e}' (component ${t.id})`:`component ${t.id}`}const je=827148627,Qe=0,Q=4,Ze=52,E={magic:0,sim_abi_version:4,view_stamp:8,capacity:12,archetype_count:16,layout_descriptor_off:20,command_ring_off:24,action_ring_off:28,entity_index_off:32,event_ring_off:36,region_table_off:40,region_table_count:44,bindings_off:48},ee=12,$={region_id:0,byte_offset:4,byte_length:8},ce=16,O={component_id:0,field_id:2,type_tag:4,byte_off:8,stride:12},de=36,N={archetype_id:0,component_mask:4,row_count:20,row_capacity:24,column_count:28,enabled_count:32};function Bt(t,e){t.setUint32(E.magic,e.magic,!0),t.setUint32(E.sim_abi_version,e.simAbiVersion,!0),t.setUint32(E.view_stamp,e.viewStamp,!0),t.setUint32(E.capacity,e.capacity,!0),t.setUint32(E.archetype_count,e.archetypeCount,!0),t.setUint32(E.layout_descriptor_off,e.layoutDescriptorOff,!0),t.setUint32(E.command_ring_off,e.commandRingOff,!0),t.setUint32(E.action_ring_off,e.actionRingOff,!0),t.setUint32(E.entity_index_off,e.entityIndexOff,!0),t.setUint32(E.event_ring_off,e.eventRingOff,!0),t.setUint32(E.region_table_off,e.regionTableOff,!0),t.setUint32(E.region_table_count,e.regionTableCount,!0),t.setUint32(E.bindings_off,e.bindingsOff,!0)}function Ft(t){return{magic:t.getUint32(E.magic,!0),simAbiVersion:t.getUint32(E.sim_abi_version,!0),viewStamp:t.getUint32(E.view_stamp,!0),capacity:t.getUint32(E.capacity,!0),archetypeCount:t.getUint32(E.archetype_count,!0),layoutDescriptorOff:t.getUint32(E.layout_descriptor_off,!0),commandRingOff:t.getUint32(E.command_ring_off,!0),actionRingOff:t.getUint32(E.action_ring_off,!0),entityIndexOff:t.getUint32(E.entity_index_off,!0),eventRingOff:t.getUint32(E.event_ring_off,!0),regionTableOff:t.getUint32(E.region_table_off,!0),regionTableCount:t.getUint32(E.region_table_count,!0),bindingsOff:t.getUint32(E.bindings_off,!0)}}const g={u8:0,i8:1,u16:2,i16:3,u32:4,i32:5,f32:6,f64:7},Te=Object.freeze({[g.u8]:1,[g.i8]:1,[g.u16]:2,[g.i16]:2,[g.u32]:4,[g.i32]:4,[g.f32]:4,[g.f64]:8}),xt={u8:g.u8,i8:g.i8,u16:g.u16,i16:g.i16,u32:g.u32,i32:g.i32,f32:g.f32,f64:g.f64};function Yt(t,e,n){t.setUint16(e+O.component_id,n.componentId,!0),t.setUint16(e+O.field_id,n.fieldId,!0),t.setUint8(e+O.type_tag,n.typeTag),t.setUint32(e+O.byte_off,n.byteOff,!0),t.setUint16(e+O.stride,n.stride,!0)}function kt(t,e){return{componentId:t.getUint16(e+O.component_id,!0),fieldId:t.getUint16(e+O.field_id,!0),typeTag:t.getUint8(e+O.type_tag),byteOff:t.getUint32(e+O.byte_off,!0),stride:t.getUint16(e+O.stride,!0)}}const Gt=Q*32;function Re(t){return de+t*ce}function Je(t,e,n){t.setUint32(e+N.archetype_id,n.archetypeId,!0);for(let s=0;s<Q;s++)t.setUint32(e+N.component_mask+s*4,n.componentMask[s]??0,!0);t.setUint32(e+N.row_count,n.rowCount,!0),t.setUint32(e+N.row_capacity,n.rowCapacity,!0),t.setUint32(e+N.column_count,n.columns.length,!0),t.setUint32(e+N.enabled_count,n.enabledCount,!0);let r=e+de;for(let s=0;s<n.columns.length;s++)Yt(t,r,n.columns[s]),r+=ce;return r}function Ht(t,e){const n=t.getUint32(e+N.column_count,!0),r=new Array(n);let s=e+de;for(let i=0;i<n;i++)r[i]=kt(t,s),s+=ce;const o=new Array(Q);for(let i=0;i<Q;i++)o[i]=t.getUint32(e+N.component_mask+i*4,!0);return{archetypeId:t.getUint32(e+N.archetype_id,!0),componentMask:o,rowCount:t.getUint32(e+N.row_count,!0),rowCapacity:t.getUint32(e+N.row_capacity,!0),enabledCount:t.getUint32(e+N.enabled_count,!0),columns:r}}function Vt(t,e,n){let r=e;for(let s=0;s<n.length;s++)r=Je(t,r,n[s]);return r}function Xt(t,e,n){const r=new Array(n);let s=e;for(let o=0;o<n;o++){const i=Ht(t,s);r[o]=i,s+=Re(i.columns.length)}return r}function Wt(t){let e=0;for(let n=0;n<t.length;n++)e+=Re(t[n].columns.length);return e}const et=16,x=16,zt=256,C={write_head:0,read_head:4,capacity_slots:8,overflow_flag:12},De=0;function $e(t){return et+t*x}function qt(t){return t>0&&(t&t-1)===0}class M extends Error{constructor(e){super(e),this.name="CommandRingError"}}function Kt(t,e,n){if(!qt(n))throw new M(`command ring capacity_slots must be a positive power of two (got ${n})`);t.setUint32(e+C.write_head,0,!0),t.setUint32(e+C.read_head,0,!0),t.setUint32(e+C.capacity_slots,n,!0),t.setUint32(e+C.overflow_flag,0,!0)}function jt(t,e){return t.getUint32(e+C.write_head,!0)}function Qt(t,e){return t.getUint32(e+C.read_head,!0)}function Zt(t,e){return t.getUint32(e+C.capacity_slots,!0)}function Jt(t,e,n){if(n.byteLength!==x-1)throw new M(`out_payload must be ${x-1} bytes (got ${n.byteLength})`);const r=jt(t,e),s=Qt(t,e);if(r===s)return De;const o=Zt(t,e),i=s&o-1,a=e+et+i*x,c=t.getUint8(a),l=new Uint8Array(t.buffer,a+1,x-1);return n.set(l),t.setUint32(e+C.read_head,s+1>>>0,!0),c}function en(t,e,n){let r=0;const s=new Uint8Array(x-1);for(;;){const o=Jt(t,e,s);if(o===De)return r;n(o,s.slice()),r++}}const te=16,R=12,Z={length:0,capacity:4},U=1<<20;function Be(t){if(t<0||!Number.isInteger(t))throw new tt(`entity_index capacity must be a non-negative integer (got ${t})`);return te+t*R}function tn(t){return t+te}function nn(t,e){return t+te+e*4}function sn(t,e){return t+te+e*8}class tt extends Error{constructor(e){super(e),this.name="EntityIndexError"}}function rn(t,e,n){if(n<0||!Number.isInteger(n))throw new tt(`entity_index capacity must be a non-negative integer (got ${n})`);t.setUint32(e+Z.length,0,!0),t.setUint32(e+Z.capacity,n,!0)}function on(t,e,n){return{generations:new Int32Array(t,tn(e),n),archetypes:new Int32Array(t,nn(e,n),n),rows:new Int32Array(t,sn(e,n),n)}}const an=16,cn=16,dn=256,H={write_head:0,read_head:4,capacity_slots:8,overflow_flag:12};function Fe(t){return an+t*cn}function ln(t){return t>0&&(t&t-1)===0}class un extends Error{constructor(e){super(e),this.name="EventRingError"}}function _n(t,e,n){if(!ln(n))throw new un(`event ring capacity_slots must be a positive power of two (got ${n})`);t.setUint32(e+H.write_head,0,!0),t.setUint32(e+H.read_head,0,!0),t.setUint32(e+H.capacity_slots,n,!0),t.setUint32(e+H.overflow_flag,0,!0)}const fn=16,hn=16,En=256,V={write_head:0,read_head:4,capacity_slots:8,overflow_flag:12},mn=V.write_head/4,gn=V.read_head/4,pn=V.capacity_slots/4,Tn=V.overflow_flag/4;function An(t,e){return new Int32Array(t.buffer,t.byteOffset+e,4)}function xe(t){return fn+t*hn}function yn(t){return t>0&&(t&t-1)===0}class Ye extends Error{constructor(e){super(e),this.name="ActionRingError"}}function In(t,e,n){if(!yn(n))throw new Ye(`action ring capacity_slots must be a positive power of two (got ${n})`);if((t.byteOffset+e)%4!==0)throw new Ye(`action ring header must be 4-byte aligned for Atomics (view.byteOffset ${t.byteOffset} + ring_off ${e} is not a multiple of 4)`);const r=An(t,e);Atomics.store(r,mn,0),Atomics.store(r,gn,0),Atomics.store(r,pn,n),Atomics.store(r,Tn,0)}const q=[{name:"command_ring",headerOff:"command_ring_off",sizeFromOptions:t=>t.commandRingCapacitySlots!==void 0?$e(t.commandRingCapacitySlots):0,init:(t,e,n)=>Kt(t,e,n.commandRingCapacitySlots),regionBytes:(t,e)=>$e(t.getUint32(e+C.capacity_slots,!0)),readOptions:(t,e,n)=>{n.commandRingCapacitySlots=t.getUint32(e+C.capacity_slots,!0)}},{name:"entity_index",headerOff:"entity_index_off",sizeFromOptions:t=>t.entityIndexCapacity!==void 0?Be(t.entityIndexCapacity):0,init:(t,e,n)=>rn(t,e,n.entityIndexCapacity),regionBytes:(t,e)=>Be(t.getUint32(e+Z.capacity,!0)),readOptions:(t,e,n)=>{n.entityIndexCapacity=t.getUint32(e+Z.capacity,!0)}},{name:"event_ring",headerOff:"event_ring_off",sizeFromOptions:t=>t.eventRingCapacitySlots!==void 0?Fe(t.eventRingCapacitySlots):0,init:(t,e,n)=>_n(t,e,n.eventRingCapacitySlots),regionBytes:(t,e)=>Fe(t.getUint32(e+H.capacity_slots,!0)),readOptions:(t,e,n)=>{n.eventRingCapacitySlots=t.getUint32(e+H.capacity_slots,!0)}},{name:"action_ring",headerOff:"action_ring_off",sizeFromOptions:t=>t.actionRingCapacitySlots!==void 0?xe(t.actionRingCapacitySlots):0,init:(t,e,n)=>In(t,e,n.actionRingCapacitySlots),regionBytes:(t,e)=>xe(t.getUint32(e+V.capacity_slots,!0)),readOptions:(t,e,n)=>{n.actionRingCapacitySlots=t.getUint32(e+V.capacity_slots,!0)}}];class se extends Error{constructor(e){super(e),this.name="RegionRegistryError"}}function nt(t){return t*ee}function Oe(t,e){const n=t.getUint32(E.region_table_count,!0);if(e+nt(n)>t.byteLength)throw new se(`region table of ${n} entries at byte ${e} overruns the buffer (${t.byteLength} bytes)`);return n}function Sn(t){const e=new Set;for(let n=0;n<t.length;n++){const r=t[n];if(!Number.isInteger(r.id)||r.id<=0)throw new se(`region "${r.name}" has invalid id ${r.id} — region ids must be positive integers (0 is the absent sentinel)`);if(e.has(r.id))throw new se(`duplicate region id ${r.id} (region "${r.name}") — ids must be distinct within a consumer's region set`);if(e.add(r.id),!Number.isInteger(r.bytes)||r.bytes<=0)throw new se(`region "${r.name}" (id ${r.id}) has invalid byte size ${r.bytes} — must be a positive integer`)}}function wn(t,e,n){t.setUint32(e+$.region_id,n.regionId,!0),t.setUint32(e+$.byte_offset,n.byteOffset,!0),t.setUint32(e+$.byte_length,n.byteLength,!0)}function st(t,e){return{regionId:t.getUint32(e+$.region_id,!0),byteOffset:t.getUint32(e+$.byte_offset,!0),byteLength:t.getUint32(e+$.byte_length,!0)}}function Nn(t,e,n){for(let r=0;r<n.length;r++)wn(t,e+r*ee,n[r])}function Rn(t,e,n){const r=new Array(n);for(let s=0;s<n;s++)r[s]=st(t,e+s*ee);return r}function Dn(t){const e=t.getUint32(E.region_table_off,!0);if(e===0)return[];const n=Oe(t,e);return Rn(t,e,n)}function On(t,e){const n=t.getUint32(E.region_table_off,!0);if(n===0)return 0;const r=Oe(t,n);for(let s=0;s<r;s++){const o=n+s*ee;if(t.getUint32(o+$.region_id,!0)===e)return t.getUint32(o+$.byte_offset,!0)}return 0}function Cn(t,e){const n=t.getUint32(E.region_table_off,!0);if(n===0)return null;const r=Oe(t,n);for(let s=0;s<r;s++){const o=st(t,n+s*ee);if(o.regionId===e)return o}return null}function rt(t,e){return t<<16|e}const le=2**31;class Ce extends Error{constructor(e){super(`SAB column layout offset ${e} reaches or exceeds the 2³¹ (${le}-byte) ceiling. Past 2 GiB the signed-32-bit bitwise alignment math wraps to negative/misaligned offsets. This is a structural limit independent of the (default 256 MiB) allocator cap — a single SAB cannot back more than ~2 GiB of column data (#382).`),this.name="StoreLayoutOverflowError"}}function be(t,e){if(t+e>le)throw new Ce(t);return t+(e-1)&~(e-1)}function bn(t,e,n,r){switch(e){case g.u8:return new Uint8Array(t,n,r);case g.i8:return new Int8Array(t,n,r);case g.u16:return new Uint16Array(t,n,r);case g.i16:return new Int16Array(t,n,r);case g.u32:return new Uint32Array(t,n,r);case g.i32:return new Int32Array(t,n,r);case g.f32:return new Float32Array(t,n,r);case g.f64:return new Float64Array(t,n,r)}}function Un(t,e,n=0){const s=Wt(t.map(a=>({archetypeId:a.archetypeId,componentMask:a.componentMask,rowCount:0,enabledCount:0,rowCapacity:a.rowCapacity,columns:a.columns.map(c=>({componentId:c.componentId,fieldId:c.fieldId,typeTag:c.typeTag,byteOff:0,stride:Te[c.typeTag]}))})))+n;let o=e+s;const i=new Array(t.length);for(let a=0;a<t.length;a++){const c=t[a],l=new Array(c.columns.length);for(let d=0;d<c.columns.length;d++){const _=c.columns[d],f=Te[_.typeTag];o=be(o,f),l[d]={componentId:_.componentId,fieldId:_.fieldId,typeTag:_.typeTag,byteOff:o,stride:f},o+=f*c.rowCapacity}i[a]={archetypeId:c.archetypeId,componentMask:c.componentMask,rowCount:0,enabledCount:0,rowCapacity:c.rowCapacity,columns:l}}if(o>le)throw new Ce(o);return{descriptors:i,totalBytes:o,regionBytes:s}}function vn(t){const e=t;return typeof e._regionBytes=="number"&&typeof e._allocator=="function"&&typeof e._reservedDescriptorBytes=="number"}function Ln(t,e=P.DEFAULT_SAB_ALLOCATOR,n={}){const r={};let s=Ze;for(let S=0;S<q.length;S++){const b=q[S],z=b.sizeFromOptions(n);r[b.headerOff]=z===0?0:s,s+=z}const o=n.regions??[];Sn(o);const i=o.length,a=i>0?s:0;s+=nt(i);const c=new Array(i);for(let S=0;S<o.length;S++){const b=o[S];c[S]={regionId:b.id,byteOffset:s,byteLength:b.bytes},s+=b.bytes}const l=n.bindingsRegionBytes??0,d=l===0?0:s;s+=l;const _=s,{descriptors:f,totalBytes:m,regionBytes:y}=Un(t,_,n.reservedDescriptorBytes??0),u=e(m),h=new DataView(u),I={magic:je,simAbiVersion:Qe,viewStamp:0,capacity:m,archetypeCount:t.length,layoutDescriptorOff:_,bindingsOff:d,regionTableOff:a,regionTableCount:i,commandRingOff:r.command_ring_off,entityIndexOff:r.entity_index_off,eventRingOff:r.event_ring_off,actionRingOff:r.action_ring_off};Bt(h,I),l>0&&new Uint8Array(u,d,l).fill(0);for(let S=0;S<q.length;S++){const b=q[S],z=r[b.headerOff];z!==0&&b.init(h,z,n)}a!==0&&Nn(h,a,c);for(let S=0;S<o.length;S++)o[S].init(h,c[S].byteOffset);Vt(h,_,f);const Y=ot(u,f);return{buffer:u,view:h,header:I,archetypes:Y,_regionBytes:y,_allocator:e,_reservedDescriptorBytes:n.reservedDescriptorBytes??0}}function ot(t,e){const n=new Map;for(let r=0;r<e.length;r++){const s=e[r],o=new Array(s.columns.length),i=new Map;for(let a=0;a<s.columns.length;a++){const c=s.columns[a],l={componentId:c.componentId,fieldId:c.fieldId,typeTag:c.typeTag,byteOff:c.byteOff,stride:c.stride,view:bn(t,c.typeTag,c.byteOff,s.rowCapacity)};o[a]=l,i.set(rt(c.componentId,c.fieldId),l)}n.set(s.archetypeId,{archetypeId:s.archetypeId,componentMask:s.componentMask,rowCapacity:s.rowCapacity,columns:i,columnsInOrder:o})}return n}const it=2166136261,Ue=16777619;function fe(t,e){return t=(t^e&255)>>>0,Math.imul(t,Ue)>>>0}function Mn(t,e){return t=(t^e>>>0)>>>0,Math.imul(t,Ue)>>>0}class Pn{_data=new We.SparseMap;fieldNames;fieldTypes;fieldIndex;constructor(e,n){this.fieldNames=e,this.fieldTypes=n;const r=Object.create(null);for(let s=0;s<e.length;s++)r[e[s]]=s;this.fieldIndex=r}get size(){return this._data.size}get indices(){return this._data.keys}canonicalIndices(){return this._data.keys.slice().sort((e,n)=>e-n)}getRow(e){return this._data.get(e)}clear(){this._data.clear()}setRawRow(e,n){this._data.set(e,n)}has(e){return this._data.has(e)}setRow(e,n){const r=this.fieldNames,s=new Array(r.length);for(let o=0;o<r.length;o++){const i=n[r[o]];s[o]=i===void 0?0:i}this._data.set(e,s)}remove(e){return this._data.delete(e)}getField(e,n){const r=this._data.get(e);return r===void 0?void 0:r[n]}setField(e,n,r){const s=this._data.get(e);return s===void 0?!1:(s[n]=r,!0)}}class A extends Error{constructor(e){super(e),this.name="SparseRestoreError"}}const ve=12,Le=4,X=8;function Me(t,e){let n=it;const r=s=>{for(let o=0;o<s.length;o++)n=fe(n,s.charCodeAt(o))};for(let s=0;s<t.length;s++)r(t[s]),n=fe(n,31),r(e[s]),n=fe(n,30);return n>>>0}function $n(t){let e=4;for(let o=0;o<t.length;o++){const i=t[o],a=i.fieldNames.length;e+=ve+i.size*(Le+a*X)}const n=new Uint8Array(e),r=new DataView(n.buffer);let s=0;r.setUint32(s,t.length,!0),s+=4;for(let o=0;o<t.length;o++){const i=t[o],a=i.fieldNames.length,c=i.canonicalIndices();r.setUint32(s,a,!0),s+=4,r.setUint32(s,Me(i.fieldNames,i.fieldTypes),!0),s+=4,r.setUint32(s,c.length,!0),s+=4;for(let l=0;l<c.length;l++){const d=c[l];r.setUint32(s,d,!0),s+=4;const _=i.getRow(d);for(let f=0;f<a;f++)r.setFloat64(s,_[f],!0),s+=X}}return n}function Bn(t,e){const n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=e.byteLength;let s=0;const o=a=>{if(s+a>r)throw new A(`sparse snapshot truncated: need ${a} more bytes at offset ${s}, have ${r-s}`)};o(4);const i=n.getUint32(s,!0);if(s+=4,i!==t.length)throw new A(`sparse store count mismatch: snapshot=${i}, registered=${t.length}`);for(let a=0;a<t.length;a++){const c=t[a];o(ve);const l=n.getUint32(s,!0);s+=4;const d=n.getUint32(s,!0);s+=4;const _=n.getUint32(s,!0);if(s+=4,l!==c.fieldNames.length)throw new A(`sparse store ${a} field-count mismatch: snapshot=${l}, registered=${c.fieldNames.length}`);const f=Me(c.fieldNames,c.fieldTypes);if(d!==f)throw new A(`sparse store ${a} schema identity mismatch: snapshot hash=${d}, registered=${f} (same field count, different field names/types — likely a registration-order divergence between the snapshot and restore worlds)`);c.clear();for(let m=0;m<_;m++){o(Le+l*X);const y=n.getUint32(s,!0);if(s+=4,y>L)throw new A(`sparse store ${a} member ${m} entity index ${y} exceeds MAX_INDEX (${L})`);const u=new Array(l);for(let h=0;h<l;h++)u[h]=n.getFloat64(s,!0),s+=X;c.setRawRow(y,u)}}if(s!==r)throw new A(`sparse snapshot has ${r-s} trailing bytes after the last store (not a canonical encoding)`)}function Fn(t,e){const n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=e.byteLength;let s=0;const o=a=>{if(s+a>r)throw new A(`sparse snapshot truncated: need ${a} more bytes at offset ${s}, have ${r-s}`)};o(4);const i=n.getUint32(s,!0);if(s+=4,i!==t.length)throw new A(`sparse store count mismatch: snapshot=${i}, registered=${t.length}`);for(let a=0;a<t.length;a++){const c=t[a];o(ve);const l=n.getUint32(s,!0);s+=4;const d=n.getUint32(s,!0);s+=4;const _=n.getUint32(s,!0);if(s+=4,l!==c.fieldNames.length)throw new A(`sparse store ${a} field-count mismatch: snapshot=${l}, registered=${c.fieldNames.length}`);const f=Me(c.fieldNames,c.fieldTypes);if(d!==f)throw new A(`sparse store ${a} schema identity mismatch: snapshot hash=${d}, registered=${f} (same field count, different field names/types — likely a registration-order divergence between the snapshot and restore worlds)`);for(let m=0;m<_;m++){o(Le+l*X);const y=n.getUint32(s,!0);if(s+=4,y>L)throw new A(`sparse store ${a} member ${m} entity index ${y} exceeds MAX_INDEX (${L})`);s+=l*X}}if(s!==r)throw new A(`sparse snapshot has ${r-s} trailing bytes after the last store (not a canonical encoding)`)}const Ae=2147483647,xn="orphan",at="target",Yn=Object.freeze({});class ct{exclusive;sparse;onDeleteTarget;_store;_reverse=new Map;constructor(e,n,r,s){this.exclusive=e,this.sparse=n,this._store=r,this.onDeleteTarget=s}linkReverse(e,n){let r=this._reverse.get(e);r===void 0&&(r=new Set,this._reverse.set(e,r)),r.add(n)}unlinkReverse(e,n){const r=this._reverse.get(e);r!==void 0&&(r.delete(n),r.size===0&&this._reverse.delete(e))}pruneDeadReverse(e){let n=0;for(const r of this._reverse.keys())e(r)||(this._reverse.delete(r),n++);return n}sourcesOf(e){const n=this._reverse.get(e);if(n===void 0||n.size===0)return[];const r=new Array(n.size);let s=0;return n.forEach(o=>{r[s++]=o}),r.sort((o,i)=>o-i),r}resetIndices(){this._reverse.clear(),this._resetForward()}}class kn extends ct{constructor(e,n,r){super(!0,e,n,r)}_resetForward(){}link(e,n){const r=v(e),s=this._store.getField(r,0);if(s!==void 0){if(s===n)return;this.unlinkReverse(s,e)}this._store.setRow(r,{[at]:n}),this.linkReverse(n,e)}unlink(e,n){const r=v(e),s=this._store.getField(r,0);s!==void 0&&(n!==void 0&&s!==n||(this.unlinkReverse(s,e),this._store.remove(r)))}purgeSource(e){const n=v(e),r=this._store.getField(n,0);r!==void 0&&this.unlinkReverse(r,e)}singleTarget(e){const n=this._store.getField(e,0);return n===void 0?void 0:n}targetsOf(e){const n=this._store.getField(e,0);return n===void 0?[]:[n]}has(e){return this._store.has(e)}forEachCanonicalTargetSet(e){}forEachCanonicalPair(e,n){const r=this._store.canonicalIndices();for(let s=0;s<r.length;s++){const o=r[s];n(e(o),this._store.getField(o,0))}}rebuildReverseFromForward(e){const n=this._store.indices;for(let r=0;r<n.length;r++){const s=n[r];this.linkReverse(this._store.getField(s,0),e(s))}}restoreAddTarget(){throw new A("exclusive relation has no multi forward sources to restore (snapshot header should have guarded this)")}}class Gn extends ct{_forward=new Map;constructor(e,n,r){super(!1,e,n,r)}_resetForward(){this._forward.clear()}link(e,n){const r=v(e);let s=this._forward.get(r);s===void 0&&(s=new Set,this._forward.set(r,s),this._store.setRow(r,Yn)),s.add(n),this.linkReverse(n,e)}unlink(e,n){const r=v(e),s=this._forward.get(r);if(s!==void 0){if(n===void 0){this._forward.delete(r),s.forEach(o=>this.unlinkReverse(o,e)),this._store.remove(r);return}s.has(n)&&(s.delete(n),this.unlinkReverse(n,e),s.size===0&&(this._forward.delete(r),this._store.remove(r)))}}purgeSource(e){const n=v(e),r=this._forward.get(n);r!==void 0&&(this._forward.delete(n),r.forEach(s=>this.unlinkReverse(s,e)))}singleTarget(){}targetsOf(e){const n=this._forward.get(e);if(n===void 0||n.size===0)return[];const r=new Array(n.size);let s=0;return n.forEach(o=>{r[s++]=o}),r.sort((o,i)=>o-i),r}has(e){return this._store.has(e)}forEachCanonicalTargetSet(e){const n=Array.from(this._forward.keys()).sort((r,s)=>r-s);for(let r=0;r<n.length;r++){const s=this.targetsOf(n[r]);s.length!==0&&e(n[r],s)}}forEachCanonicalPair(e,n){this.forEachCanonicalTargetSet((r,s)=>{const o=e(r);for(let i=0;i<s.length;i++)n(o,s[i])})}rebuildReverseFromForward(){}restoreAddTarget(e,n,r){let s=this._forward.get(e);s===void 0&&(s=new Set,this._forward.set(e,s)),s.add(n),this.linkReverse(n,r)}}function Hn(t,e,n,r){return t?new kn(e,n,r):new Gn(e,n,r)}const dt=4,lt=4,ut=8,re=8;function Vn(t){const e=new Array(t.length);let n=4;for(let i=0;i<t.length;i++){n+=dt;const a=t[i];if(a.exclusive){e[i]=null;continue}const c=[];a.forEachCanonicalTargetSet((l,d)=>c.push([l,d])),e[i]=c,n+=lt;for(let l=0;l<c.length;l++)n+=ut+c[l][1].length*re}const r=new Uint8Array(n),s=new DataView(r.buffer);let o=0;s.setUint32(o,t.length,!0),o+=4;for(let i=0;i<t.length;i++){s.setUint32(o,t[i].exclusive?0:1,!0),o+=4;const a=e[i];if(a!==null){s.setUint32(o,a.length,!0),o+=4;for(let c=0;c<a.length;c++){const l=a[c][0],d=a[c][1];s.setUint32(o,l,!0),o+=4,s.setUint32(o,d.length,!0),o+=4;for(let _=0;_<d.length;_++)s.setFloat64(o,d[_],!0),o+=re}}}return r}function Xn(t,e,n){const r=new DataView(e.buffer,e.byteOffset,e.byteLength),s=e.byteLength;let o=0;const i=c=>{if(o+c>s)throw new A(`relation snapshot truncated: need ${c} more bytes at offset ${o}, have ${s-o}`)};for(let c=0;c<t.length;c++)t[c].resetIndices();i(4);const a=r.getUint32(o,!0);if(o+=4,a!==t.length)throw new A(`relation count mismatch: snapshot=${a}, registered=${t.length}`);for(let c=0;c<t.length;c++){const l=t[c];i(dt);const d=r.getUint32(o,!0);if(o+=4,d===1===l.exclusive)throw new A(`relation ${c} cardinality mismatch: snapshot ${d?"multi":"exclusive"}, registered ${l.exclusive?"exclusive":"multi"}`);if(l.exclusive)continue;i(lt);const _=r.getUint32(o,!0);o+=4;for(let f=0;f<_;f++){i(ut);const m=r.getUint32(o,!0);o+=4;const y=r.getUint32(o,!0);if(o+=4,m>L)throw new A(`relation ${c} source index ${m} exceeds MAX_INDEX (${L})`);i(y*re);const u=n(m);for(let h=0;h<y;h++){const I=r.getFloat64(o,!0);o+=re;const Y=I;if(!Number.isInteger(Y)||Y<0||Y>ge)throw new A(`relation ${c} target ${Y} is not a well-formed packed EntityID (expected an integer in [0, ${ge}])`);l.restoreAddTarget(m,I,u)}}}if(o!==s)throw new A(`relation snapshot has ${s-o} trailing bytes after the last relation (not a canonical encoding)`)}const ke=new WeakMap;function Wn(t){const e=new Set,n=new Set,r=new Set,s=new Set,o=new Set,i=new Set,a=new Set,c=new Set,l=new Set,d=new Set;for(let u=0;u<t.writes.length;u++){const h=t.writes[u].id;n.add(h),e.add(h),r.add(h)}for(let u=0;u<t.reads.length;u++)e.add(t.reads[u].id);for(let u=0;u<t.spawns.length;u++){const h=t.spawns[u];for(let I=0;I<h.length;I++)r.add(h[I].id)}for(let u=0;u<t.transitions.length;u++){const h=t.transitions[u];if(h.add)for(let I=0;I<h.add.length;I++)r.add(h.add[I].id);if(h.remove)for(let I=0;I<h.remove.length;I++)s.add(h.remove[I].id)}for(let u=0;u<t.despawns.length;u++)s.add(t.despawns[u].id);for(let u=0;u<t.resourceReads.length;u++)o.add(t.resourceReads[u]);for(let u=0;u<t.resourceWrites.length;u++){const h=t.resourceWrites[u];i.add(h),o.add(h)}const _=t.sparseWrites;if(_!==void 0)for(let u=0;u<_.length;u++){const h=_[u];c.add(h),a.add(h)}const f=t.sparseReads;if(f!==void 0)for(let u=0;u<f.length;u++)a.add(f[u]);const m=t.relationWrites;if(m!==void 0)for(let u=0;u<m.length;u++){const h=m[u];d.add(h),l.add(h)}const y=t.relationReads;if(y!==void 0)for(let u=0;u<y.length;u++)l.add(y[u]);return{reads:e,writes:n,addAllowed:r,removeAllowed:s,hasDespawns:t.despawns.length>0,resourceReads:o,resourceWrites:i,sparseReads:a,sparseWrites:c,relationReads:l,relationWrites:d}}function zn(t){const e=ke.get(t);if(e!==void 0)return e;const n=Wn(t);return ke.set(t,n),n}const Ge=new WeakMap;function qn(t){const e=new Set,n=new Set;if(t.reads!==void 0)for(let r=0;r<t.reads.length;r++)e.add(t.reads[r].id);if(t.resourceReads!==void 0)for(let r=0;r<t.resourceReads.length;r++)n.add(t.resourceReads[r]);return{reads:e,writes:new Set,addAllowed:new Set,removeAllowed:new Set,hasDespawns:!1,resourceReads:n,resourceWrites:new Set,sparseReads:new Set,sparseWrites:new Set,relationReads:new Set,relationWrites:new Set}}function Kn(t){const e=Ge.get(t);if(e!==void 0)return e;const n=qn(t);return Ge.set(t,n),n}class jn{active=null;sets=null;activeName=null;exclusive=!1;enter(e){this.active=e,this.activeName=e.name??`system_${e.id}`,this.exclusive=e.exclusive===!0,this.sets=this.exclusive?null:zn(e)}enterCondition(e){this.active=null,this.activeName=e.name,this.sets=Kn(e)}leave(){this.active=null,this.activeName=null,this.sets=null,this.exclusive=!1}isActive(){return this.sets!==null||this.exclusive}current(){return this.active}checkRead(e){this.sets!==null&&(this.sets.reads.has(e.id)||this.failComponent("read",e,"reads"))}checkWrite(e){this.sets!==null&&(this.sets.writes.has(e.id)||this.failComponent("write",e,"writes"))}checkAdd(e){this.sets!==null&&(this.sets.addAllowed.has(e.id)||this.failComponent("addComponent",e,"spawns / transitions.add / writes"))}checkRemove(e){this.sets!==null&&(this.sets.removeAllowed.has(e.id)||this.failComponent("removeComponent",e,"despawns / transitions.remove"))}checkDestroy(){if(this.sets===null||this.sets.hasDespawns)return;const e=this.activeName;throw new T(p.ACCESS_UNDECLARED,`system '${e}' called despawn but didn't declare any despawns — declare the components this system removes via despawn in its 'despawns'`,{system:e,op:"despawn"})}checkResourceRead(e){if(this.sets===null)return;const n=e;this.sets.resourceReads.has(n)||this.failResource("read",e,"resourceReads")}checkResourceWrite(e){if(this.sets===null)return;const n=e;this.sets.resourceWrites.has(n)||this.failResource("write",e,"resourceWrites")}checkSparseRead(e){if(this.sets===null)return;const n=e;this.sets.sparseReads.has(n)||this.failSparse("read",n,"sparseReads")}checkSparseWrite(e){if(this.sets===null)return;const n=e;this.sets.sparseWrites.has(n)||this.failSparse("write",n,"sparseWrites")}checkRelationRead(e){if(this.sets===null)return;const n=e;this.sets.relationReads.has(n)||this.failRelation("read",n,"relationReads")}checkRelationWrite(e){if(this.sets===null)return;const n=e;this.sets.relationWrites.has(n)||this.failRelation("write",n,"relationWrites")}checkRelationReadAny(){this.sets!==null&&(this.sets.relationReads.has(Ae)||this.failRelation("(*, T) wildcard read",Ae,"relationReads (as ANY_RELATION)"))}optionalScopes=[];enterOptionalScope(e){this.optionalScopes.push(e)}leaveOptionalScope(){this.optionalScopes.pop()}checkOptionalFetch(e){const n=this.optionalScopes.length;if(n===0)return;const r=this.optionalScopes[n-1],s=e.id;for(let o=0;o<r.length;o++)if(r[o]===s)return;throw new T(p.OPTIONAL_TERM_NOT_DECLARED,`getOptionalColumnRead fetched optional component ${s} but the iterating query didn't declare it — add .optional(component) to the query before fetching it`)}failComponent(e,n,r){const s=this.activeName,o=Ke(n);throw new T(p.ACCESS_UNDECLARED,`system '${s}' performed ${e} on ${o} but didn't declare it — add it to '${r}' (see docs/api/systems.md)`,{system:s,op:e,component:n.id})}failSparse(e,n,r){const s=this.activeName;throw new T(p.ACCESS_UNDECLARED,`system '${s}' performed ${e} on sparse component ${n} but didn't declare it — add it to '${r}' (see docs/api/systems.md)`,{system:s,op:e,sparse:n})}failRelation(e,n,r){const s=this.activeName;throw new T(p.ACCESS_UNDECLARED,`system '${s}' performed ${e} on relation ${n} but didn't declare it — add it to '${r}' (see docs/api/systems.md)`,{system:s,op:e,relation:n})}failResource(e,n,r){const s=this.activeName,o=n.description??"<unnamed>";throw new T(p.ACCESS_UNDECLARED,`system '${s}' performed resource ${e} on '${o}' but didn't declare it — add the resource key to '${r}' (see docs/api/systems.md)`,{system:s,op:e,resource:o})}}const K=new jn,Qn="/packages/engine/src/core/ecs/";class Zn{activeCache=null;repoRootCache=null;buf=new Map;callsiteCache=new Map;isActive(){if(this.activeCache!==null)return this.activeCache;const n=globalThis.process?.env?.VISUAL_INTEL_TRACE;return this.activeCache=n==="1"||n==="true"}repoRoot(){if(this.repoRootCache!==null)return this.repoRootCache;const e=globalThis.process;return this.repoRootCache=e?.cwd?.()??""}resolveCallsite(){return es(new Error().stack??null,this.repoRoot(),this.callsiteCache)}record(e,n,r){const s=this.resolveCallsite();if(!s)return;const o=`${e} ${n} ${r} ${s}`;this.buf.set(o,(this.buf.get(o)??0)+1)}recordEmit(e){this.record("ecs-events","emit",e)}recordRead(e){this.record("ecs-events","read",e)}recordResourceRead(e){this.record("resources","read",e)}recordResourceWrite(e){this.record("resources","write",e)}recordResourceRegister(e){this.record("resources","register",e)}recordResourceRemove(e){this.record("resources","remove",e)}recordSendAction(e){this.record("actions","send_action",e)}recordHandleAction(e){this.record("actions","handle_action",e)}snapshot(){const e={"ecs-events":{emit:[],read:[]},actions:{send_action:[],handle_action:[]},resources:{read:[],write:[],register:[],remove:[]}};for(const[n,r]of this.buf.entries()){const[s,o,i,a]=n.split(" ");if(!s||!o||a===void 0)continue;const l={key:s==="actions"?Number(i):i,file:a,count:r},_=e[s][o];_&&_.push(l)}for(const n of Object.values(e))for(const r of Object.values(n))r.sort((s,o)=>{if(s.file!==o.file)return s.file<o.file?-1:1;const i=String(s.key),a=String(o.key);return i<a?-1:i>a?1:0});return{schemaVersion:1,capturedAt:new Date().toISOString(),channels:e}}reset(){this.buf.clear(),this.callsiteCache.clear(),this.activeCache=null,this.repoRootCache=null}}function Jn(t){const e=/\(([^)]+):\d+:\d+\)\s*$/.exec(t);if(e)return e[1]??null;const n=/at\s+([^\s][^()]*?):\d+:\d+\s*$/.exec(t);return n&&(n[1]??"").trim()||null}function es(t,e,n){if(!t)return null;const r=t.split(`
2
- `);for(let s=0;s<r.length;s++){const o=r[s],i=n?.get(o);if(i!==void 0){if(i===null)continue;return i}const a=Jn(o);if(!a){n?.set(o,null);continue}if(a.includes(Qn)){n?.set(o,null);continue}const c=ts(a,e);return n?.set(o,c),c}return null}function ts(t,e){let n=t;return n.startsWith("file://")&&(n=n.slice(7)),e&&n.startsWith(e+"/")&&(n=n.slice(e.length+1)),n.replace(/\\/g,"/")}const ns=new Zn;var B=(t=>(t.PRE_STARTUP="PRE_STARTUP",t.STARTUP="STARTUP",t.POST_STARTUP="POST_STARTUP",t.FIXED_UPDATE="FIXED_UPDATE",t.PRE_UPDATE="PRE_UPDATE",t.UPDATE="UPDATE",t.POST_UPDATE="POST_UPDATE",t))(B||{});const he=["PRE_STARTUP","STARTUP","POST_STARTUP"],Ee=["PRE_UPDATE","UPDATE","POST_UPDATE"];function ss(t){return Object.freeze({name:t})}function rs(t){return!("fn"in t)}const j=Object.freeze([]);function me(t){return t===void 0?j:Array.isArray(t)?t:[t]}class os{labelSystems=new Map;sortedCache=new Map;systemIndex=new Map;systemLastRun=new Map;gatedSystems=new Map;setConditions=new Map;setOrdering=new Map;nextInsertionOrder=0;_backend=null;onWarn;constructor(e){this.onWarn=e??(n=>console.warn(n));for(let n=0;n<he.length;n++)this.labelSystems.set(he[n],[]);this.labelSystems.set("FIXED_UPDATE",[]);for(let n=0;n<Ee.length;n++)this.labelSystems.set(Ee[n],[])}addSystems(e,...n){for(const r of n){const s="system"in r,o=s?r.system:r,i=s?r.ordering:void 0,a=s?me(r.runIf):j,c=s?me(r.set):j;if(this.systemIndex.has(o))throw new T(p.DUPLICATE_SYSTEM,`System ${o.name??o.id} is already scheduled`);const l={descriptor:o,insertionOrder:this.nextInsertionOrder++,before:new Set(i?.before??[]),after:new Set(i?.after??[]),conditions:a,sets:c};this.labelSystems.get(e).push(l),this.systemIndex.set(o,e),this.systemLastRun.set(o,0),(a.length>0||c.length>0)&&this.gatedSystems.set(o,l),this.sortedCache.delete(e)}}configureSet(e,n){const r=me(n.runIf);if(r.length>0){const s=this.setConditions.get(e);s===void 0?this.setConditions.set(e,[...r]):s.push(...r)}if(n.before!==void 0||n.after!==void 0){let s=this.setOrdering.get(e);s===void 0&&(s={before:new Set,after:new Set},this.setOrdering.set(e,s));for(const o of n.before??j)s.before.add(o);for(const o of n.after??j)s.after.add(o);this.sortedCache.clear()}}removeSystem(e){const n=this.systemIndex.get(e);if(n===void 0)return;const r=this.labelSystems.get(n),s=r.findIndex(o=>o.descriptor===e);if(s!==-1){const o=r.length-1;s!==o&&(r[s]=r[o]),r.pop();for(const i of r)i.before.delete(e),i.after.delete(e)}this.systemIndex.delete(e),this.systemLastRun.delete(e),this.gatedSystems.delete(e),this.sortedCache.delete(n)}setBackend(e){this._backend=e}runStartup(e,n){for(const r of he)this.runLabel(r,e,Ct,n)}runUpdate(e,n,r){for(const s of Ee)this.runLabel(s,e,n,r)}runFixedUpdate(e,n,r){this.runLabel("FIXED_UPDATE",e,n,r)}hasFixedSystems(){return this.labelSystems.get("FIXED_UPDATE").length>0}getAllSystems(){const e=[];for(const n of this.labelSystems.values())for(const r of n)e.push(r.descriptor);return e}hasSystem(e){return this.systemIndex.has(e)}clear(){for(const e of this.labelSystems.values())e.length=0;this.sortedCache.clear(),this.systemIndex.clear(),this.systemLastRun.clear(),this.gatedSystems.clear(),this.setConditions.clear(),this.setOrdering.clear()}runLabel(e,n,r,s){const o=this.getSorted(e),i=this.gatedSystems.size>0,a=this._backend,c=i?new Map:void 0;for(let l=0;l<o.length;l++){const d=o[l];if(i){const f=this.gatedSystems.get(d);if(f!==void 0&&!this.shouldRun(f,n,c))continue}n.lastRunTick=this.systemLastRun.get(d)??0;const _=a!==null?d.backendHandle:void 0;K.enter(d),n._trace?.systemStart(d,e);try{_!==void 0?a.run(_):d.fn?.(n,r)}finally{n._trace?.systemEnd(d),K.leave()}this.systemLastRun.set(d,s)}n._trace?.flushBegin(e),n.flush(),n._trace?.flushEnd(e),n._trace?.phaseBoundary(e)}shouldRun(e,n,r){if(e.conditions.length>0&&!this.evalConditions(e.conditions,n))return!1;for(let s=0;s<e.sets.length;s++){const o=e.sets[s];let i=r.get(o);if(i===void 0){const a=this.setConditions.get(o);i=a===void 0||a.length===0?!0:this.evalConditions(a,n),r.set(o,i)}if(!i)return!1}return!0}evalConditions(e,n){for(let r=0;r<e.length;r++){const s=e[r];K.enterCondition(s);let o;try{o=s.evaluate(n)}finally{K.leave()}if(!o)return!1}return!0}getSorted(e){const n=this.sortedCache.get(e);if(n!==void 0)return n;const r=this.labelSystems.get(e),s=this.sortSystems(r,e);return this.sortedCache.set(e,s),s}sortSystems(e,n){if(e.length===0)return[];const r=[],s=new Map,o=new Set,i=new Map;for(const d of e){r.push(d.descriptor),s.set(d.descriptor,d.insertionOrder),o.add(d.descriptor);for(let _=0;_<d.sets.length;_++){const f=d.sets[_];let m=i.get(f);m===void 0&&(m=[],i.set(f,m)),m.push(d.descriptor)}}const a=new Map;for(const d of e)a.set(d.descriptor,[]);for(const d of e){this.resolveEdges(d.descriptor,d.before,"before",o,i,a,n),this.resolveEdges(d.descriptor,d.after,"after",o,i,a,n);for(let _=0;_<d.sets.length;_++){const f=this.setOrdering.get(d.sets[_]);f!==void 0&&(this.resolveEdges(d.descriptor,f.before,"before",o,i,a,n),this.resolveEdges(d.descriptor,f.after,"after",o,i,a,n))}}const c=(d,_)=>s.get(d)-s.get(_),l=d=>d.name??`system_${d.id}`;try{return We.topologicalSort(r,a,c,l)}catch(d){throw d instanceof TypeError?new T(p.CIRCULAR_SYSTEM_DEPENDENCY,`Circular system dependency detected in ${n}: ${d.message}`):d}}resolveEdges(e,n,r,s,o,i,a){for(const c of n){if(rs(c)){const l=o.get(c);if(l===void 0)continue;for(let d=0;d<l.length;d++){const _=l[d];_!==e&&this.addDirectedEdge(e,_,r,i)}continue}if(!s.has(c)){this.warnDroppedEdge(e,c,r,a);continue}this.addDirectedEdge(e,c,r,i)}}addDirectedEdge(e,n,r,s){r==="before"?s.get(e).push(n):s.get(n).push(e)}warnDroppedEdge(e,n,r,s){if(this.systemIndex.has(n))return;const o=i=>i.name??`system_${i.id}`;this.onWarn(`Schedule[${s}]: \`${o(e)}\` declares \`${r}\` ordering against \`${o(n)}\`, which is not registered in any phase — the constraint is ignored. Check for a typo or a missing add_systems() call.`)}}const oe=1024,ie=1024*oe,He=64*oe,G=256*ie,ye=3,_t=64,ft=8,Ve=4*ie,Xe=t=>2**Math.ceil(Math.log2(Math.max(1,t))),ne=t=>2**Math.floor(Math.log2(Math.max(1,t))),k=(t,e,n)=>Math.min(n,Math.max(e,t)),w=t=>t>=ie?`${(t/ie).toFixed(1)} MiB`:t>=oe?`${(t/oe).toFixed(0)} KiB`:`${t} B`;function D(t,e){if(!Number.isInteger(e)||e<=0)throw new T(p.INVALID_MEMORY_OPTIONS,`memory.${t} must be a positive integer (got ${e})`)}function is(t){const e=["budget","maxBytes","wasm","allocator","heap","shared"].filter(s=>t!==void 0&&t[s]!==void 0);if(e.length>1)throw new T(p.INVALID_MEMORY_OPTIONS,`memory takes at most one of budget | maxBytes | wasm | allocator | heap | shared (got: ${e.join(", ")})`);const n=t?.columnCapacity;if(n!==void 0&&D("column_capacity",n),t?.budget!==void 0){const{entities:s}=t.budget,o=t.budget.archetypes??ft,i=t.budget.bytesPerEntity??_t;if(D("budget.entities",s),D("budget.archetypes",o),D("budget.bytes_per_entity",i),s>1<<20)throw new T(p.INVALID_MEMORY_OPTIONS,`memory.budget.entities=${s} exceeds the EntityID index space (1<<20 = ${1<<20})`);const a=n??k(Xe(Math.ceil(s/o)),64,1<<20),c=k(Xe(s*2),4096,1<<20),l=c*R,d=s*i*ye,_=be(Math.max(l+d,Ve),He);return{source:"budget",allocator:P.heapArraybufferAllocator(_),columnCapacity:a,entityIndexCapacity:c,capBytes:_,intentLabel:`budget of ${s} entities`,budgetEntities:s,derivation:[`column_capacity = ${n!==void 0?`${a} (pinned)`:`pow2(${s}/${o} per archetype) = ${a}`}`,`entity_index = pow2(2 × ${s}) = ${c} slots × ${R} B = ${w(l)}`,`columns = ${s} × ${i} B × ${ye} (double+holes headroom) = ${w(d)}`,`cap = align64K(max(index + columns, ${w(Ve)} floor)) = ${w(_)}`],wasmMemory:null}}if(t?.maxBytes!==void 0){D("maxBytes",t.maxBytes);const s=n??F,o=k(ne(t.maxBytes/4/R),4096,U);return{source:"max_bytes",allocator:P.heapArraybufferAllocator(t.maxBytes),columnCapacity:s,entityIndexCapacity:o,capBytes:t.maxBytes,intentLabel:`explicit cap of ${w(t.maxBytes)}`,budgetEntities:null,derivation:[`cap = ${w(t.maxBytes)} (caller-declared)`,`column_capacity = ${s} (${n!==void 0?"pinned":"default"})`,`entity_index = floor_pow2(cap/4 ÷ ${R} B) = ${o} slots`],wasmMemory:null}}if(t?.wasm!==void 0){const s=t.wasm,o=n??F;if(s.memory!==void 0){if(!(s.memory.buffer instanceof SharedArrayBuffer))throw new T(p.INVALID_MEMORY_OPTIONS,"memory.wasm.memory must be constructed with `shared: true` — the SAB substrate requires a SharedArrayBuffer-backed WebAssembly.Memory (ADR-0004 / ADR-0018)");return{source:"wasm",allocator:P.wasmMemoryAllocator(s.memory),columnCapacity:o,entityIndexCapacity:U,capBytes:null,intentLabel:"caller-supplied WebAssembly.Memory",budgetEntities:null,derivation:["backing = wasm_memory_allocator(memory) — zero-copy with the sim (is_in_place ✓)","cap = the Memory's own `maximum` (declared by the caller; not readable from JS)",`column_capacity = ${o} (${n!==void 0?"pinned":"default"})`],wasmMemory:s.memory}}D("wasm.maximum_pages",s.maximumPages);const i=s.initialPages??Math.min(32,s.maximumPages);if(D("wasm.initial_pages",i),i>s.maximumPages)throw new T(p.INVALID_MEMORY_OPTIONS,`memory.wasm.initial_pages (${i}) exceeds maximum_pages (${s.maximumPages})`);const a=new WebAssembly.Memory({initial:i,maximum:s.maximumPages,shared:!0}),c=s.maximumPages*He,l=k(ne(c/4/R),4096,U);return{source:"wasm",allocator:P.wasmMemoryAllocator(a),columnCapacity:o,entityIndexCapacity:l,capBytes:c,intentLabel:`engine-constructed WebAssembly.Memory (max ${s.maximumPages} pages)`,budgetEntities:null,derivation:[`cap = ${s.maximumPages} pages × 64 KiB = ${w(c)} (Memory maximum)`,`initial = ${i} pages (${s.initialPages!==void 0?"declared":"default"})`,`entity_index = floor_pow2(cap/4 ÷ ${R} B) = ${l} slots`,`column_capacity = ${o} (${n!==void 0?"pinned":"default"})`],wasmMemory:a}}if(t?.allocator!==void 0){if(t.allocator.isInPlace!==!0)throw new T(p.INVALID_MEMORY_OPTIONS,"memory.allocator must declare `is_in_place: true` (ADR-0008): a live Store's flush loops hoist entity-index views across grows, so a non-in-place allocator (e.g. DEFAULT_SAB_ALLOCATOR) corrupts the entity→row mapping. Use growable_sab_allocator / wasm_memory_allocator; non-in-place allocators are snapshot/test sizing only.");const s=n??F,o=t.capBytesHint;return o!==void 0&&D("cap_bytes_hint",o),{source:"allocator",allocator:t.allocator,columnCapacity:s,entityIndexCapacity:U,capBytes:o??null,intentLabel:o!==void 0?`custom in-place allocator (cap hint ${w(o)})`:"custom in-place allocator",budgetEntities:null,derivation:["backing = caller allocator (is_in_place ✓ checked at construction)",o!==void 0?`cap = ${w(o)} (caller hint — diagnostics only; the allocator owns the real cap)`:"cap = allocator-owned (no hint)",`column_capacity = ${s} (${n!==void 0?"pinned":"default"})`],wasmMemory:null}}if(t?.heap!==void 0){t.heap.maxBytes!==void 0&&D("heap.maxBytes",t.heap.maxBytes);const s=t.heap.maxBytes??G,o=n??F,i=k(ne(s/4/R),4096,U);return{source:"heap",allocator:P.heapArraybufferAllocator(s),columnCapacity:o,entityIndexCapacity:i,capBytes:s,intentLabel:`pure-TS heap backing (${w(s)} growable cap, no SharedArrayBuffer)`,budgetEntities:null,derivation:[`backing = heap_arraybuffer_allocator(${w(s)}) — resizable ArrayBuffer, no SAB / no COOP+COEP (is_in_place ✓)`,"trade-off: no worker offload / no WASM backend (both need a transferable SharedArrayBuffer)",`column_capacity = ${o} (${n!==void 0?"pinned":"default"})`,`entity_index = floor_pow2(cap/4 ÷ ${R} B) = ${i} slots`],wasmMemory:null}}if(t?.shared!==void 0){t.shared.maxBytes!==void 0&&D("shared.maxBytes",t.shared.maxBytes);const s=t.shared.maxBytes??G,o=n??F,i=k(ne(s/4/R),4096,U);return{source:"shared",allocator:P.growableSabAllocator(s),columnCapacity:o,entityIndexCapacity:i,capBytes:s,intentLabel:`shared SharedArrayBuffer backing (${w(s)} growable cap, needs COOP/COEP)`,budgetEntities:null,derivation:[`backing = growable_sab_allocator(${w(s)}) — growable SharedArrayBuffer (is_in_place ✓); needs cross-origin isolation`,"enables worker offload + a WASM compute backend (transferable SharedArrayBuffer)",`column_capacity = ${o} (${n!==void 0?"pinned":"default"})`,`entity_index = floor_pow2(cap/4 ÷ ${R} B) = ${i} slots`],wasmMemory:null}}const r=n??F;return{source:"default",allocator:P.heapArraybufferAllocator(),columnCapacity:r,entityIndexCapacity:U,capBytes:G,intentLabel:`default sizing (${w(G)} growable cap)`,budgetEntities:null,derivation:[`cap = ${w(G)} (heap_arraybuffer_allocator default)`,`column_capacity = ${r} (${n!==void 0?"pinned":"DEFAULT_COLUMN_CAPACITY"})`,`entity_index = ${U} slots (full EntityID space, ~12 MiB virtual)`],wasmMemory:null}}function as(t,e){return{def:t,values:e}}function ae(t,e){switch(e.kind){case"spawn":{const n=t.commands.spawn();for(const r of e.components)t.commands.add(n,r.def,r.values);return e.onSpawned?.(n),n}case"despawn":t.commands.despawn(e.eid);return;case"add_component":t.commands.add(e.eid,e.def,e.values);return;case"remove_component":t.commands.remove(e.eid,e.def);return;case"set_field":if(!t.hasComponent(e.eid,e.def))throw new T(p.COMPONENT_NOT_REGISTERED,`host set_field on entity ${e.eid} targets a component it does not have. If you added that component via a host command this same frame, the add is deferred to the phase flush while set_field is immediate — carry the value in add_component/spawn_entry instead of a separate set_field, or set it next frame. (#681 host write seam)`);t.setField(e.eid,e.def,e.field,e.value);return;case"disable":t.commands.disable(e.eid);return;case"enable":t.commands.enable(e.eid);return;default:return pt(e,"HostCommand kind")}}class ht{queued=[];spawn(e,n){return this.queued.push({kind:"spawn",components:e,onSpawned:n}),this}despawn(e){return this.queued.push({kind:"despawn",eid:e}),this}add(e,n,r){return this.queued.push({kind:"add_component",eid:e,def:n,values:r}),this}remove(e,n){return this.queued.push({kind:"remove_component",eid:e,def:n}),this}setField(e,n,r,s){return this.queued.push({kind:"set_field",eid:e,def:n,field:r,value:s}),this}disable(e){return this.queued.push({kind:"disable",eid:e}),this}enable(e){return this.queued.push({kind:"enable",eid:e}),this}push(e){return this.queued.push(e),this}get pending(){return this.queued.length}clear(){const e=this.queued.length;return this.queued.length=0,e}drain(e,n){const r=this.queued.length;if(r===0)return 0;if(n===void 0)for(let s=0;s<r;s++)ae(e,this.queued[s]);else for(let s=0;s<r;s++){const o=this.queued[s];n(o),ae(e,o)}return this.queued.splice(0,r),r}}const Pe=x-1;function cs(t){if(t===De)throw new M("cannot bind op_code 0 (reserved as the command-ring empty-slot marker)");if(t<0||t>255||!Number.isInteger(t))throw new M(`command op_code must be a u8 in [1, 255] (got ${t})`)}function ue(t){const e=new Uint8Array(Pe);return new DataView(e.buffer).setUint32(0,t,!0),e}function _e(t){return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint32(0,!0)}function ds(t,e){return{encode(n){if(n.kind!=="set_field")throw new M(`ringSetFieldCodec encodes a "set_field" command (got "${n.kind}")`);const r=new Uint8Array(Pe),s=new DataView(r.buffer);return s.setUint32(0,n.eid,!0),s.setFloat64(4,n.value,!0),r},decode(n){const r=new DataView(n.buffer,n.byteOffset,n.byteLength);return{kind:"set_field",eid:r.getUint32(0,!0),def:t,field:e,value:r.getFloat64(4,!0)}}}}function ls(){return{encode(t){if(t.kind!=="despawn")throw new M(`ring_despawn_codec encodes a "despawn" command (got "${t.kind}")`);return ue(t.eid)},decode:t=>({kind:"despawn",eid:_e(t)})}}function us(){return{encode(t){if(t.kind!=="disable")throw new M(`ring_disable_codec encodes a "disable" command (got "${t.kind}")`);return ue(t.eid)},decode:t=>({kind:"disable",eid:_e(t)})}}function _s(){return{encode(t){if(t.kind!=="enable")throw new M(`ring_enable_codec encodes an "enable" command (got "${t.kind}")`);return ue(t.eid)},decode:t=>({kind:"enable",eid:_e(t)})}}function fs(t){return{encode(e){if(e.kind!=="remove_component")throw new M(`ringRemoveComponentCodec encodes a "remove_component" command (got "${e.kind}")`);return ue(e.eid)},decode:e=>({kind:"remove_component",eid:_e(e),def:t})}}class hs{appliers=new Map;on(e,n){return cs(e),this.appliers.set(e,n),this}off(e){return this.appliers.delete(e)}onCommand(e,n){return this.on(e,(r,s,o)=>{const i=n.decode(s);o?.(i),ae(r,i)})}drain(e,n,r,s){return en(n,r,(o,i)=>{const a=this.appliers.get(o);a!==void 0&&a(e,i,s)})}}const Es=new Set([B.PRE_STARTUP,B.STARTUP,B.POST_STARTUP]),Ie=new WeakMap;function ms(t,e){const n=Ie.get(e);if(n===void 0)return!1;for(const r of n)t.removeSystem(r);return Ie.delete(e),e.clear(),!0}function gs(t,e){const n=new ht,r=[];Ie.set(n,r);const s=e?.name??"host_command_apply",o=e?.ring,i=e?.recorder,a=i?.record,c=e?.schedules??[B.PRE_STARTUP,B.PRE_UPDATE];if(i!==void 0&&c.includes(B.FIXED_UPDATE))throw new T(p.INVALID_RECORDER_SCHEDULE,"install_host_command_seam: a recorder cannot drain on SCHEDULE.FIXED_UPDATE — it would log the fixed-step dt instead of the host update(dt) and diverge on replay. Use a variable-update phase (PRE_UPDATE/UPDATE/POST_UPDATE).");for(const l of c){const d=!Es.has(l),_=t.registerSystem({name:`${s}:${l}`,reads:[],writes:[],exclusive:!0,fn:(f,m)=>{if(i!==void 0&&d&&i.openTick(f.ecsTick,m),n.drain(f,a),o!==void 0){const y=t.columnStore,u=y.header.commandRingOff;u!==0&&o.drain(f,y.view,u,a)}}});t.addSystems(l,_),r.push(_)}return n}exports.ACTION_RING_DEFAULT_CAPACITY_SLOTS=En;exports.ANY_RELATION=Ae;exports.ARCHETYPE_DESCRIPTOR_HEADER_BYTES=de;exports.ARCHETYPE_DESCRIPTOR_OFFSETS=N;exports.BUDGET_DEFAULT_ARCHETYPES=ft;exports.BUDGET_DEFAULT_BYTES_PER_ENTITY=_t;exports.BUDGET_GROWTH_HEADROOM=ye;exports.COLUMN_DESCRIPTOR_BYTES=ce;exports.COMMAND_RING_DEFAULT_CAPACITY_SLOTS=zt;exports.COMPONENT_MASK_WORDS=Q;exports.DEFAULT_COLUMN_CAPACITY=F;exports.DEFAULT_ECS_CAP_BYTES=G;exports.DEFAULT_FIXED_TIMESTEP=Dt;exports.DEFAULT_MAX_FIXED_STEPS=Ot;exports.DEFAULT_ON_DELETE_TARGET=xn;exports.ECSError=T;exports.ECS_ERROR=p;exports.EMPTY_VALUES=It;exports.ENTITY_INDEX_DEFAULT_CAPACITY=U;exports.ENTITY_INDEX_HEADER_BYTES=te;exports.ENTITY_INDEX_HEADER_OFFSETS=Z;exports.EVENT_RING_DEFAULT_CAPACITY_SLOTS=dn;exports.FNV1A_OFFSET_BASIS=it;exports.FNV1A_PRIME=Ue;exports.HASH_GOLDEN_RATIO=St;exports.HASH_SECONDARY_PRIME=wt;exports.HOST_COMMAND_PAYLOAD_BYTES=Pe;exports.HostCommandDispatcher=hs;exports.HostCommandQueue=ht;exports.INDEX_BITS=W;exports.INDEX_MASK=we;exports.INITIAL_GENERATION=Nt;exports.MAX_ENTITY_ID=ge;exports.MAX_GENERATION=J;exports.MAX_INDEX=L;exports.MAX_LIVE_GENERATION=vt;exports.NO_SWAP=yt;exports.RELATION_TARGET_FIELD=at;exports.RETIRED_GENERATION=Ut;exports.SCHEDULE=B;exports.SIM_ABI_VERSION=Qe;exports.STORE_DESCRIPTOR_COMPONENT_LIMIT=Gt;exports.STORE_HEADER_BYTES=Ze;exports.STORE_HEADER_OFFSETS=E;exports.STORE_MAGIC=je;exports.STORE_MAX_BYTE_OFFSET=le;exports.STORE_PREFIX_REGIONS=q;exports.Schedule=os;exports.SparseComponentStore=Pn;exports.SparseRestoreError=A;exports.StoreLayoutOverflowError=Ce;exports.TYPED_ARRAY_TAG_TO_TYPE_TAG=xt;exports.TYPE_TAG_STRIDE=Te;exports.UNASSIGNED=At;exports.accessCheck=K;exports.alignUp=be;exports.applyHostCommand=ae;exports.archetypeDescriptorBytes=Re;exports.buildArchetypeViews=ot;exports.buildEntityIndexViews=on;exports.columnKey=rt;exports.componentDebugName=$t;exports.componentLabel=Ke;exports.createColumnStore=Ln;exports.createEntityId=Lt;exports.dispatchTrace=ns;exports.entityNotAliveError=Mt;exports.findRegionEntry=Cn;exports.findRegionOffset=On;exports.fnv1aStepWord=Mn;exports.getEntityGeneration=pe;exports.getEntityIndex=v;exports.installHostCommandSeam=gs;exports.isColumnStoreInternal=vn;exports.isEcsError=Tt;exports.isNonNegativeInteger=Et;exports.makeRelationStore=Hn;exports.readHeaderRegionTable=Dn;exports.readLayoutDescriptorRegion=Xt;exports.readStoreHeader=Ft;exports.resolveECSMemory=is;exports.restoreRelations=Xn;exports.restoreSparseStores=Bn;exports.ringDespawnCodec=ls;exports.ringDisableCodec=us;exports.ringEnableCodec=_s;exports.ringRemoveComponentCodec=fs;exports.ringSetFieldCodec=ds;exports.setComponentDebugName=Pt;exports.snapshotRelations=Vn;exports.snapshotSparseStores=$n;exports.spawnEntry=as;exports.systemSet=ss;exports.uninstallHostCommandSeam=ms;exports.unsafeCast=gt;exports.validateAndCast=mt;exports.validateSparseStores=Fn;exports.writeArchetypeDescriptor=Je;
1
+ "use strict";const P=require("./shared-BMXh9hxm.cjs"),We=require("./topological_sort-BDvEyb9W.cjs");class ze extends Error{constructor(e,n,r){super(e),this.isOperational=n,this.context=r,this.name=this.constructor.name,Error.captureStackTrace(this,this.constructor)}}var Se=(t=>(t.ASSERTION_FAIL_CONDITION="ASSERTION_FAIL_CONDITION",t.VALIDATION_FAIL_CONDITION="VALIDATION_FAIL_CONDITION",t.ASSERTION_FAIL_NON_NULLABLE="ASSERTION_FAIL_NON_NULLABLE",t.ASSERTION_FAIL_UNREACHABLE="ASSERTION_FAIL_UNREACHABLE",t))(Se||{});class qe extends ze{constructor(e,n,r){super(n,!1,r),this.category=e}}const Et=t=>Number.isInteger(t)&&t>=0;function mt(t,e,n){if(!e(t))throw new qe(Se.VALIDATION_FAIL_CONDITION,`Expected value to meet validation: ${n}`);return t}function gt(t){return t}function pt(t,e){throw new qe(Se.ASSERTION_FAIL_UNREACHABLE,`Unhandled ${e}: ${String(t)}`)}var p=(t=>(t.EID_MAX_INDEX_OVERFLOW="EID_MAX_INDEX_OVERFLOW",t.EID_MAX_GEN_OVERFLOW="EID_MAX_GEN_OVERFLOW",t.COMPONENT_NOT_REGISTERED="COMPONENT_NOT_REGISTERED",t.COMPONENT_LIMIT_EXCEEDED="COMPONENT_LIMIT_EXCEEDED",t.ENTITY_NOT_ALIVE="ENTITY_NOT_ALIVE",t.CIRCULAR_SYSTEM_DEPENDENCY="CIRCULAR_SYSTEM_DEPENDENCY",t.DUPLICATE_SYSTEM="DUPLICATE_SYSTEM",t.ARCHETYPE_NOT_FOUND="ARCHETYPE_NOT_FOUND",t.RESOURCE_NOT_REGISTERED="RESOURCE_NOT_REGISTERED",t.RESOURCE_ALREADY_REGISTERED="RESOURCE_ALREADY_REGISTERED",t.EVENT_ALREADY_REGISTERED="EVENT_ALREADY_REGISTERED",t.EVENT_NOT_REGISTERED="EVENT_NOT_REGISTERED",t.FIELD_NOT_REGISTERED="FIELD_NOT_REGISTERED",t.RELATION_NOT_REGISTERED="RELATION_NOT_REGISTERED",t.RELATION_MODE_INVALID="RELATION_MODE_INVALID",t.RELATION_MODE_MISMATCH="RELATION_MODE_MISMATCH",t.RELATION_CYCLE="RELATION_CYCLE",t.SPARSE_CACHE_KEY_OVERFLOW="SPARSE_CACHE_KEY_OVERFLOW",t.SPARSE_QUERY_DENSE_PATH="SPARSE_QUERY_DENSE_PATH",t.HIERARCHY_ALREADY_SET="HIERARCHY_ALREADY_SET",t.HIERARCHY_INVALID_MAX_DEPTH="HIERARCHY_INVALID_MAX_DEPTH",t.OBSERVER_NON_CONVERGENT="OBSERVER_NON_CONVERGENT",t.OBSERVER_INVALID_CONFIG="OBSERVER_INVALID_CONFIG",t.OBSERVER_ONSET_EMIT="OBSERVER_ONSET_EMIT",t.INVALID_FIXED_TIMESTEP="INVALID_FIXED_TIMESTEP",t.INVALID_MAX_FIXED_STEPS="INVALID_MAX_FIXED_STEPS",t.INVALID_RECORDER_SCHEDULE="INVALID_RECORDER_SCHEDULE",t.EMPTY_ARCHETYPE_MATERIALIZE="EMPTY_ARCHETYPE_MATERIALIZE",t.COMPONENT_INDEX_INVARIANT="COMPONENT_INDEX_INVARIANT",t.OPTIONAL_TERM_NOT_DECLARED="OPTIONAL_TERM_NOT_DECLARED",t.QUERY_ACCESS_UNDECLARED="QUERY_ACCESS_UNDECLARED",t.ACCESS_UNDECLARED="ACCESS_UNDECLARED",t.QUERY_NOT_SINGLETON="QUERY_NOT_SINGLETON",t.INVALID_RUN_CONDITION="INVALID_RUN_CONDITION",t.SYSTEM_FN_ARITY="SYSTEM_FN_ARITY",t.PARTITION_APPEND_NEEDS_ENTITY_ROW="PARTITION_APPEND_NEEDS_ENTITY_ROW",t.PARTITION_BULK_INTO_DISABLED="PARTITION_BULK_INTO_DISABLED",t.ENTITY_NOT_DISABLED="ENTITY_NOT_DISABLED",t.STRUCTURAL_DURING_ITERATION="STRUCTURAL_DURING_ITERATION",t.BACKEND_ALREADY_ATTACHED="BACKEND_ALREADY_ATTACHED",t.DETERMINISM_DISABLED="DETERMINISM_DISABLED",t.NON_DETERMINISTIC_COLUMN_TYPE="NON_DETERMINISTIC_COLUMN_TYPE",t.INVALID_MEMORY_OPTIONS="INVALID_MEMORY_OPTIONS",t.STORE_CAP_EXCEEDED="STORE_CAP_EXCEEDED",t.REGION_NOT_DECLARED="REGION_NOT_DECLARED",t.COMMAND_LOG_TAG_COLLISION="COMMAND_LOG_TAG_COLLISION",t.INVALID_FRAME_STEP="INVALID_FRAME_STEP",t))(p||{});class T extends ze{constructor(e,n,r){super(n??e,!0,r),this.category=e}}function Tt(t){return t instanceof T}const At=-1,yt=-1,It=Object.freeze(Object.create(null)),St=2654435769,wt=1367130551,F=1024,Nt=0,Rt=31,Dt=1/60,Ot=4,Ct=0,W=20,we=(1<<W)-1,L=we,bt=Rt-W,J=(1<<bt)-1,Ut=J,vt=J-1,ge=J<<W|L,Lt=(t,e)=>{{if(t<0||t>L)throw new T(p.EID_MAX_INDEX_OVERFLOW);if(e<0||e>J)throw new T(p.EID_MAX_GEN_OVERFLOW)}return e<<W|t},v=t=>t&we,pe=t=>t>>W,Mt=(t,e,n)=>new T(p.ENTITY_NOT_ALIVE,`${t}: entity ${e} (index ${v(e)}, generation ${pe(e)}) is not alive${n?` — ${n}`:""} (destroyed, never created, or a stale handle; guard with isAlive() first)`,{entity:e,index:v(e),generation:pe(e),op:t}),Ne=new WeakMap;function Pt(t,e){Ne.set(t,e)}function $t(t){return Ne.get(t)}function Ke(t){const e=Ne.get(t);return e!==void 0?`'${e}' (component ${t.id})`:`component ${t.id}`}const je=827148627,Qe=0,Q=4,Ze=52,E={magic:0,sim_abi_version:4,view_stamp:8,capacity:12,archetype_count:16,layout_descriptor_off:20,command_ring_off:24,action_ring_off:28,entity_index_off:32,event_ring_off:36,region_table_off:40,region_table_count:44,bindings_off:48},ee=12,$={region_id:0,byte_offset:4,byte_length:8},ce=16,O={component_id:0,field_id:2,type_tag:4,byte_off:8,stride:12},de=36,N={archetype_id:0,component_mask:4,row_count:20,row_capacity:24,column_count:28,enabled_count:32};function Bt(t,e){t.setUint32(E.magic,e.magic,!0),t.setUint32(E.sim_abi_version,e.simAbiVersion,!0),t.setUint32(E.view_stamp,e.viewStamp,!0),t.setUint32(E.capacity,e.capacity,!0),t.setUint32(E.archetype_count,e.archetypeCount,!0),t.setUint32(E.layout_descriptor_off,e.layoutDescriptorOff,!0),t.setUint32(E.command_ring_off,e.commandRingOff,!0),t.setUint32(E.action_ring_off,e.actionRingOff,!0),t.setUint32(E.entity_index_off,e.entityIndexOff,!0),t.setUint32(E.event_ring_off,e.eventRingOff,!0),t.setUint32(E.region_table_off,e.regionTableOff,!0),t.setUint32(E.region_table_count,e.regionTableCount,!0),t.setUint32(E.bindings_off,e.bindingsOff,!0)}function Ft(t){return{magic:t.getUint32(E.magic,!0),simAbiVersion:t.getUint32(E.sim_abi_version,!0),viewStamp:t.getUint32(E.view_stamp,!0),capacity:t.getUint32(E.capacity,!0),archetypeCount:t.getUint32(E.archetype_count,!0),layoutDescriptorOff:t.getUint32(E.layout_descriptor_off,!0),commandRingOff:t.getUint32(E.command_ring_off,!0),actionRingOff:t.getUint32(E.action_ring_off,!0),entityIndexOff:t.getUint32(E.entity_index_off,!0),eventRingOff:t.getUint32(E.event_ring_off,!0),regionTableOff:t.getUint32(E.region_table_off,!0),regionTableCount:t.getUint32(E.region_table_count,!0),bindingsOff:t.getUint32(E.bindings_off,!0)}}const g={u8:0,i8:1,u16:2,i16:3,u32:4,i32:5,f32:6,f64:7},Te=Object.freeze({[g.u8]:1,[g.i8]:1,[g.u16]:2,[g.i16]:2,[g.u32]:4,[g.i32]:4,[g.f32]:4,[g.f64]:8}),xt={u8:g.u8,i8:g.i8,u16:g.u16,i16:g.i16,u32:g.u32,i32:g.i32,f32:g.f32,f64:g.f64};function Yt(t,e,n){t.setUint16(e+O.component_id,n.componentId,!0),t.setUint16(e+O.field_id,n.fieldId,!0),t.setUint8(e+O.type_tag,n.typeTag),t.setUint32(e+O.byte_off,n.byteOff,!0),t.setUint16(e+O.stride,n.stride,!0)}function kt(t,e){return{componentId:t.getUint16(e+O.component_id,!0),fieldId:t.getUint16(e+O.field_id,!0),typeTag:t.getUint8(e+O.type_tag),byteOff:t.getUint32(e+O.byte_off,!0),stride:t.getUint16(e+O.stride,!0)}}const Gt=Q*32;function Re(t){return de+t*ce}function Je(t,e,n){t.setUint32(e+N.archetype_id,n.archetypeId,!0);for(let s=0;s<Q;s++)t.setUint32(e+N.component_mask+s*4,n.componentMask[s]??0,!0);t.setUint32(e+N.row_count,n.rowCount,!0),t.setUint32(e+N.row_capacity,n.rowCapacity,!0),t.setUint32(e+N.column_count,n.columns.length,!0),t.setUint32(e+N.enabled_count,n.enabledCount,!0);let r=e+de;for(let s=0;s<n.columns.length;s++)Yt(t,r,n.columns[s]),r+=ce;return r}function Ht(t,e){const n=t.getUint32(e+N.column_count,!0),r=new Array(n);let s=e+de;for(let i=0;i<n;i++)r[i]=kt(t,s),s+=ce;const o=new Array(Q);for(let i=0;i<Q;i++)o[i]=t.getUint32(e+N.component_mask+i*4,!0);return{archetypeId:t.getUint32(e+N.archetype_id,!0),componentMask:o,rowCount:t.getUint32(e+N.row_count,!0),rowCapacity:t.getUint32(e+N.row_capacity,!0),enabledCount:t.getUint32(e+N.enabled_count,!0),columns:r}}function Vt(t,e,n){let r=e;for(let s=0;s<n.length;s++)r=Je(t,r,n[s]);return r}function Xt(t,e,n){const r=new Array(n);let s=e;for(let o=0;o<n;o++){const i=Ht(t,s);r[o]=i,s+=Re(i.columns.length)}return r}function Wt(t){let e=0;for(let n=0;n<t.length;n++)e+=Re(t[n].columns.length);return e}const et=16,x=16,zt=256,C={write_head:0,read_head:4,capacity_slots:8,overflow_flag:12},De=0;function $e(t){return et+t*x}function qt(t){return t>0&&(t&t-1)===0}class M extends Error{constructor(e){super(e),this.name="CommandRingError"}}function Kt(t,e,n){if(!qt(n))throw new M(`command ring capacity_slots must be a positive power of two (got ${n})`);t.setUint32(e+C.write_head,0,!0),t.setUint32(e+C.read_head,0,!0),t.setUint32(e+C.capacity_slots,n,!0),t.setUint32(e+C.overflow_flag,0,!0)}function jt(t,e){return t.getUint32(e+C.write_head,!0)}function Qt(t,e){return t.getUint32(e+C.read_head,!0)}function Zt(t,e){return t.getUint32(e+C.capacity_slots,!0)}function Jt(t,e,n){if(n.byteLength!==x-1)throw new M(`out_payload must be ${x-1} bytes (got ${n.byteLength})`);const r=jt(t,e),s=Qt(t,e);if(r===s)return De;const o=Zt(t,e),i=s&o-1,a=e+et+i*x,c=t.getUint8(a),l=new Uint8Array(t.buffer,a+1,x-1);return n.set(l),t.setUint32(e+C.read_head,s+1>>>0,!0),c}function en(t,e,n){let r=0;const s=new Uint8Array(x-1);for(;;){const o=Jt(t,e,s);if(o===De)return r;n(o,s.slice()),r++}}const te=16,R=12,Z={length:0,capacity:4},U=1<<20;function Be(t){if(t<0||!Number.isInteger(t))throw new tt(`entity_index capacity must be a non-negative integer (got ${t})`);return te+t*R}function tn(t){return t+te}function nn(t,e){return t+te+e*4}function sn(t,e){return t+te+e*8}class tt extends Error{constructor(e){super(e),this.name="EntityIndexError"}}function rn(t,e,n){if(n<0||!Number.isInteger(n))throw new tt(`entity_index capacity must be a non-negative integer (got ${n})`);t.setUint32(e+Z.length,0,!0),t.setUint32(e+Z.capacity,n,!0)}function on(t,e,n){return{generations:new Int32Array(t,tn(e),n),archetypes:new Int32Array(t,nn(e,n),n),rows:new Int32Array(t,sn(e,n),n)}}const an=16,cn=16,dn=256,H={write_head:0,read_head:4,capacity_slots:8,overflow_flag:12};function Fe(t){return an+t*cn}function ln(t){return t>0&&(t&t-1)===0}class un extends Error{constructor(e){super(e),this.name="EventRingError"}}function _n(t,e,n){if(!ln(n))throw new un(`event ring capacity_slots must be a positive power of two (got ${n})`);t.setUint32(e+H.write_head,0,!0),t.setUint32(e+H.read_head,0,!0),t.setUint32(e+H.capacity_slots,n,!0),t.setUint32(e+H.overflow_flag,0,!0)}const fn=16,hn=16,En=256,V={write_head:0,read_head:4,capacity_slots:8,overflow_flag:12},mn=V.write_head/4,gn=V.read_head/4,pn=V.capacity_slots/4,Tn=V.overflow_flag/4;function An(t,e){return new Int32Array(t.buffer,t.byteOffset+e,4)}function xe(t){return fn+t*hn}function yn(t){return t>0&&(t&t-1)===0}class Ye extends Error{constructor(e){super(e),this.name="ActionRingError"}}function In(t,e,n){if(!yn(n))throw new Ye(`action ring capacity_slots must be a positive power of two (got ${n})`);if((t.byteOffset+e)%4!==0)throw new Ye(`action ring header must be 4-byte aligned for Atomics (view.byteOffset ${t.byteOffset} + ring_off ${e} is not a multiple of 4)`);const r=An(t,e);Atomics.store(r,mn,0),Atomics.store(r,gn,0),Atomics.store(r,pn,n),Atomics.store(r,Tn,0)}const q=[{name:"command_ring",headerOff:"command_ring_off",sizeFromOptions:t=>t.commandRingCapacitySlots!==void 0?$e(t.commandRingCapacitySlots):0,init:(t,e,n)=>Kt(t,e,n.commandRingCapacitySlots),regionBytes:(t,e)=>$e(t.getUint32(e+C.capacity_slots,!0)),readOptions:(t,e,n)=>{n.commandRingCapacitySlots=t.getUint32(e+C.capacity_slots,!0)}},{name:"entity_index",headerOff:"entity_index_off",sizeFromOptions:t=>t.entityIndexCapacity!==void 0?Be(t.entityIndexCapacity):0,init:(t,e,n)=>rn(t,e,n.entityIndexCapacity),regionBytes:(t,e)=>Be(t.getUint32(e+Z.capacity,!0)),readOptions:(t,e,n)=>{n.entityIndexCapacity=t.getUint32(e+Z.capacity,!0)}},{name:"event_ring",headerOff:"event_ring_off",sizeFromOptions:t=>t.eventRingCapacitySlots!==void 0?Fe(t.eventRingCapacitySlots):0,init:(t,e,n)=>_n(t,e,n.eventRingCapacitySlots),regionBytes:(t,e)=>Fe(t.getUint32(e+H.capacity_slots,!0)),readOptions:(t,e,n)=>{n.eventRingCapacitySlots=t.getUint32(e+H.capacity_slots,!0)}},{name:"action_ring",headerOff:"action_ring_off",sizeFromOptions:t=>t.actionRingCapacitySlots!==void 0?xe(t.actionRingCapacitySlots):0,init:(t,e,n)=>In(t,e,n.actionRingCapacitySlots),regionBytes:(t,e)=>xe(t.getUint32(e+V.capacity_slots,!0)),readOptions:(t,e,n)=>{n.actionRingCapacitySlots=t.getUint32(e+V.capacity_slots,!0)}}];class se extends Error{constructor(e){super(e),this.name="RegionRegistryError"}}function nt(t){return t*ee}function Oe(t,e){const n=t.getUint32(E.region_table_count,!0);if(e+nt(n)>t.byteLength)throw new se(`region table of ${n} entries at byte ${e} overruns the buffer (${t.byteLength} bytes)`);return n}function Sn(t){const e=new Set;for(let n=0;n<t.length;n++){const r=t[n];if(!Number.isInteger(r.id)||r.id<=0)throw new se(`region "${r.name}" has invalid id ${r.id} — region ids must be positive integers (0 is the absent sentinel)`);if(e.has(r.id))throw new se(`duplicate region id ${r.id} (region "${r.name}") — ids must be distinct within a consumer's region set`);if(e.add(r.id),!Number.isInteger(r.bytes)||r.bytes<=0)throw new se(`region "${r.name}" (id ${r.id}) has invalid byte size ${r.bytes} — must be a positive integer`)}}function wn(t,e,n){t.setUint32(e+$.region_id,n.regionId,!0),t.setUint32(e+$.byte_offset,n.byteOffset,!0),t.setUint32(e+$.byte_length,n.byteLength,!0)}function st(t,e){return{regionId:t.getUint32(e+$.region_id,!0),byteOffset:t.getUint32(e+$.byte_offset,!0),byteLength:t.getUint32(e+$.byte_length,!0)}}function Nn(t,e,n){for(let r=0;r<n.length;r++)wn(t,e+r*ee,n[r])}function Rn(t,e,n){const r=new Array(n);for(let s=0;s<n;s++)r[s]=st(t,e+s*ee);return r}function Dn(t){const e=t.getUint32(E.region_table_off,!0);if(e===0)return[];const n=Oe(t,e);return Rn(t,e,n)}function On(t,e){const n=t.getUint32(E.region_table_off,!0);if(n===0)return 0;const r=Oe(t,n);for(let s=0;s<r;s++){const o=n+s*ee;if(t.getUint32(o+$.region_id,!0)===e)return t.getUint32(o+$.byte_offset,!0)}return 0}function Cn(t,e){const n=t.getUint32(E.region_table_off,!0);if(n===0)return null;const r=Oe(t,n);for(let s=0;s<r;s++){const o=st(t,n+s*ee);if(o.regionId===e)return o}return null}function rt(t,e){return t<<16|e}const le=2**31;class Ce extends Error{constructor(e){super(`SAB column layout offset ${e} reaches or exceeds the 2³¹ (${le}-byte) ceiling. Past 2 GiB the signed-32-bit bitwise alignment math wraps to negative/misaligned offsets. This is a structural limit independent of the (default 256 MiB) allocator cap — a single SAB cannot back more than ~2 GiB of column data (#382).`),this.name="StoreLayoutOverflowError"}}function be(t,e){if(t+e>le)throw new Ce(t);return t+(e-1)&~(e-1)}function bn(t,e,n,r){switch(e){case g.u8:return new Uint8Array(t,n,r);case g.i8:return new Int8Array(t,n,r);case g.u16:return new Uint16Array(t,n,r);case g.i16:return new Int16Array(t,n,r);case g.u32:return new Uint32Array(t,n,r);case g.i32:return new Int32Array(t,n,r);case g.f32:return new Float32Array(t,n,r);case g.f64:return new Float64Array(t,n,r)}}function Un(t,e,n=0){const s=Wt(t.map(a=>({archetypeId:a.archetypeId,componentMask:a.componentMask,rowCount:0,enabledCount:0,rowCapacity:a.rowCapacity,columns:a.columns.map(c=>({componentId:c.componentId,fieldId:c.fieldId,typeTag:c.typeTag,byteOff:0,stride:Te[c.typeTag]}))})))+n;let o=e+s;const i=new Array(t.length);for(let a=0;a<t.length;a++){const c=t[a],l=new Array(c.columns.length);for(let d=0;d<c.columns.length;d++){const _=c.columns[d],f=Te[_.typeTag];o=be(o,f),l[d]={componentId:_.componentId,fieldId:_.fieldId,typeTag:_.typeTag,byteOff:o,stride:f},o+=f*c.rowCapacity}i[a]={archetypeId:c.archetypeId,componentMask:c.componentMask,rowCount:0,enabledCount:0,rowCapacity:c.rowCapacity,columns:l}}if(o>le)throw new Ce(o);return{descriptors:i,totalBytes:o,regionBytes:s}}function vn(t){const e=t;return typeof e._regionBytes=="number"&&typeof e._allocator=="function"&&typeof e._reservedDescriptorBytes=="number"}function Ln(t,e=P.DEFAULT_SAB_ALLOCATOR,n={}){const r={};let s=Ze;for(let S=0;S<q.length;S++){const b=q[S],z=b.sizeFromOptions(n);r[b.headerOff]=z===0?0:s,s+=z}const o=n.regions??[];Sn(o);const i=o.length,a=i>0?s:0;s+=nt(i);const c=new Array(i);for(let S=0;S<o.length;S++){const b=o[S];c[S]={regionId:b.id,byteOffset:s,byteLength:b.bytes},s+=b.bytes}const l=n.bindingsRegionBytes??0,d=l===0?0:s;s+=l;const _=s,{descriptors:f,totalBytes:m,regionBytes:y}=Un(t,_,n.reservedDescriptorBytes??0),u=e(m),h=new DataView(u),I={magic:je,simAbiVersion:Qe,viewStamp:0,capacity:m,archetypeCount:t.length,layoutDescriptorOff:_,bindingsOff:d,regionTableOff:a,regionTableCount:i,commandRingOff:r.command_ring_off,entityIndexOff:r.entity_index_off,eventRingOff:r.event_ring_off,actionRingOff:r.action_ring_off};Bt(h,I),l>0&&new Uint8Array(u,d,l).fill(0);for(let S=0;S<q.length;S++){const b=q[S],z=r[b.headerOff];z!==0&&b.init(h,z,n)}a!==0&&Nn(h,a,c);for(let S=0;S<o.length;S++)o[S].init(h,c[S].byteOffset);Vt(h,_,f);const Y=ot(u,f);return{buffer:u,view:h,header:I,archetypes:Y,_regionBytes:y,_allocator:e,_reservedDescriptorBytes:n.reservedDescriptorBytes??0}}function ot(t,e){const n=new Map;for(let r=0;r<e.length;r++){const s=e[r],o=new Array(s.columns.length),i=new Map;for(let a=0;a<s.columns.length;a++){const c=s.columns[a],l={componentId:c.componentId,fieldId:c.fieldId,typeTag:c.typeTag,byteOff:c.byteOff,stride:c.stride,view:bn(t,c.typeTag,c.byteOff,s.rowCapacity)};o[a]=l,i.set(rt(c.componentId,c.fieldId),l)}n.set(s.archetypeId,{archetypeId:s.archetypeId,componentMask:s.componentMask,rowCapacity:s.rowCapacity,columns:i,columnsInOrder:o})}return n}const it=2166136261,Ue=16777619;function fe(t,e){return t=(t^e&255)>>>0,Math.imul(t,Ue)>>>0}function Mn(t,e){return t=(t^e>>>0)>>>0,Math.imul(t,Ue)>>>0}class Pn{_data=new We.SparseMap;fieldNames;fieldTypes;fieldIndex;constructor(e,n){this.fieldNames=e,this.fieldTypes=n;const r=Object.create(null);for(let s=0;s<e.length;s++)r[e[s]]=s;this.fieldIndex=r}get size(){return this._data.size}get indices(){return this._data.keys}canonicalIndices(){return this._data.keys.slice().sort((e,n)=>e-n)}getRow(e){return this._data.get(e)}clear(){this._data.clear()}setRawRow(e,n){this._data.set(e,n)}has(e){return this._data.has(e)}setRow(e,n){const r=this.fieldNames,s=new Array(r.length);for(let o=0;o<r.length;o++){const i=n[r[o]];s[o]=i===void 0?0:i}this._data.set(e,s)}remove(e){return this._data.delete(e)}getField(e,n){const r=this._data.get(e);return r===void 0?void 0:r[n]}setField(e,n,r){const s=this._data.get(e);return s===void 0?!1:(s[n]=r,!0)}}class A extends Error{constructor(e){super(e),this.name="SparseRestoreError"}}const ve=12,Le=4,X=8;function Me(t,e){let n=it;const r=s=>{for(let o=0;o<s.length;o++)n=fe(n,s.charCodeAt(o))};for(let s=0;s<t.length;s++)r(t[s]),n=fe(n,31),r(e[s]),n=fe(n,30);return n>>>0}function $n(t){let e=4;for(let o=0;o<t.length;o++){const i=t[o],a=i.fieldNames.length;e+=ve+i.size*(Le+a*X)}const n=new Uint8Array(e),r=new DataView(n.buffer);let s=0;r.setUint32(s,t.length,!0),s+=4;for(let o=0;o<t.length;o++){const i=t[o],a=i.fieldNames.length,c=i.canonicalIndices();r.setUint32(s,a,!0),s+=4,r.setUint32(s,Me(i.fieldNames,i.fieldTypes),!0),s+=4,r.setUint32(s,c.length,!0),s+=4;for(let l=0;l<c.length;l++){const d=c[l];r.setUint32(s,d,!0),s+=4;const _=i.getRow(d);for(let f=0;f<a;f++)r.setFloat64(s,_[f],!0),s+=X}}return n}function Bn(t,e){const n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=e.byteLength;let s=0;const o=a=>{if(s+a>r)throw new A(`sparse snapshot truncated: need ${a} more bytes at offset ${s}, have ${r-s}`)};o(4);const i=n.getUint32(s,!0);if(s+=4,i!==t.length)throw new A(`sparse store count mismatch: snapshot=${i}, registered=${t.length}`);for(let a=0;a<t.length;a++){const c=t[a];o(ve);const l=n.getUint32(s,!0);s+=4;const d=n.getUint32(s,!0);s+=4;const _=n.getUint32(s,!0);if(s+=4,l!==c.fieldNames.length)throw new A(`sparse store ${a} field-count mismatch: snapshot=${l}, registered=${c.fieldNames.length}`);const f=Me(c.fieldNames,c.fieldTypes);if(d!==f)throw new A(`sparse store ${a} schema identity mismatch: snapshot hash=${d}, registered=${f} (same field count, different field names/types — likely a registration-order divergence between the snapshot and restore worlds)`);c.clear();for(let m=0;m<_;m++){o(Le+l*X);const y=n.getUint32(s,!0);if(s+=4,y>L)throw new A(`sparse store ${a} member ${m} entity index ${y} exceeds MAX_INDEX (${L})`);const u=new Array(l);for(let h=0;h<l;h++)u[h]=n.getFloat64(s,!0),s+=X;c.setRawRow(y,u)}}if(s!==r)throw new A(`sparse snapshot has ${r-s} trailing bytes after the last store (not a canonical encoding)`)}function Fn(t,e){const n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=e.byteLength;let s=0;const o=a=>{if(s+a>r)throw new A(`sparse snapshot truncated: need ${a} more bytes at offset ${s}, have ${r-s}`)};o(4);const i=n.getUint32(s,!0);if(s+=4,i!==t.length)throw new A(`sparse store count mismatch: snapshot=${i}, registered=${t.length}`);for(let a=0;a<t.length;a++){const c=t[a];o(ve);const l=n.getUint32(s,!0);s+=4;const d=n.getUint32(s,!0);s+=4;const _=n.getUint32(s,!0);if(s+=4,l!==c.fieldNames.length)throw new A(`sparse store ${a} field-count mismatch: snapshot=${l}, registered=${c.fieldNames.length}`);const f=Me(c.fieldNames,c.fieldTypes);if(d!==f)throw new A(`sparse store ${a} schema identity mismatch: snapshot hash=${d}, registered=${f} (same field count, different field names/types — likely a registration-order divergence between the snapshot and restore worlds)`);for(let m=0;m<_;m++){o(Le+l*X);const y=n.getUint32(s,!0);if(s+=4,y>L)throw new A(`sparse store ${a} member ${m} entity index ${y} exceeds MAX_INDEX (${L})`);s+=l*X}}if(s!==r)throw new A(`sparse snapshot has ${r-s} trailing bytes after the last store (not a canonical encoding)`)}const Ae=2147483647,xn="orphan",at="target",Yn=Object.freeze({});class ct{exclusive;sparse;onDeleteTarget;_store;_reverse=new Map;constructor(e,n,r,s){this.exclusive=e,this.sparse=n,this._store=r,this.onDeleteTarget=s}linkReverse(e,n){let r=this._reverse.get(e);r===void 0&&(r=new Set,this._reverse.set(e,r)),r.add(n)}unlinkReverse(e,n){const r=this._reverse.get(e);r!==void 0&&(r.delete(n),r.size===0&&this._reverse.delete(e))}pruneDeadReverse(e){let n=0;for(const r of this._reverse.keys())e(r)||(this._reverse.delete(r),n++);return n}sourcesOf(e){const n=this._reverse.get(e);if(n===void 0||n.size===0)return[];const r=new Array(n.size);let s=0;return n.forEach(o=>{r[s++]=o}),r.sort((o,i)=>o-i),r}resetIndices(){this._reverse.clear(),this._resetForward()}}class kn extends ct{constructor(e,n,r){super(!0,e,n,r)}_resetForward(){}link(e,n){const r=v(e),s=this._store.getField(r,0);if(s!==void 0){if(s===n)return;this.unlinkReverse(s,e)}this._store.setRow(r,{[at]:n}),this.linkReverse(n,e)}unlink(e,n){const r=v(e),s=this._store.getField(r,0);s!==void 0&&(n!==void 0&&s!==n||(this.unlinkReverse(s,e),this._store.remove(r)))}purgeSource(e){const n=v(e),r=this._store.getField(n,0);r!==void 0&&this.unlinkReverse(r,e)}singleTarget(e){const n=this._store.getField(e,0);return n===void 0?void 0:n}targetsOf(e){const n=this._store.getField(e,0);return n===void 0?[]:[n]}has(e){return this._store.has(e)}forEachCanonicalTargetSet(e){}forEachCanonicalPair(e,n){const r=this._store.canonicalIndices();for(let s=0;s<r.length;s++){const o=r[s];n(e(o),this._store.getField(o,0))}}rebuildReverseFromForward(e){const n=this._store.indices;for(let r=0;r<n.length;r++){const s=n[r];this.linkReverse(this._store.getField(s,0),e(s))}}restoreAddTarget(){throw new A("exclusive relation has no multi forward sources to restore (snapshot header should have guarded this)")}}class Gn extends ct{_forward=new Map;constructor(e,n,r){super(!1,e,n,r)}_resetForward(){this._forward.clear()}link(e,n){const r=v(e);let s=this._forward.get(r);s===void 0&&(s=new Set,this._forward.set(r,s),this._store.setRow(r,Yn)),s.add(n),this.linkReverse(n,e)}unlink(e,n){const r=v(e),s=this._forward.get(r);if(s!==void 0){if(n===void 0){this._forward.delete(r),s.forEach(o=>this.unlinkReverse(o,e)),this._store.remove(r);return}s.has(n)&&(s.delete(n),this.unlinkReverse(n,e),s.size===0&&(this._forward.delete(r),this._store.remove(r)))}}purgeSource(e){const n=v(e),r=this._forward.get(n);r!==void 0&&(this._forward.delete(n),r.forEach(s=>this.unlinkReverse(s,e)))}singleTarget(){}targetsOf(e){const n=this._forward.get(e);if(n===void 0||n.size===0)return[];const r=new Array(n.size);let s=0;return n.forEach(o=>{r[s++]=o}),r.sort((o,i)=>o-i),r}has(e){return this._store.has(e)}forEachCanonicalTargetSet(e){const n=Array.from(this._forward.keys()).sort((r,s)=>r-s);for(let r=0;r<n.length;r++){const s=this.targetsOf(n[r]);s.length!==0&&e(n[r],s)}}forEachCanonicalPair(e,n){this.forEachCanonicalTargetSet((r,s)=>{const o=e(r);for(let i=0;i<s.length;i++)n(o,s[i])})}rebuildReverseFromForward(){}restoreAddTarget(e,n,r){let s=this._forward.get(e);s===void 0&&(s=new Set,this._forward.set(e,s)),s.add(n),this.linkReverse(n,r)}}function Hn(t,e,n,r){return t?new kn(e,n,r):new Gn(e,n,r)}const dt=4,lt=4,ut=8,re=8;function Vn(t){const e=new Array(t.length);let n=4;for(let i=0;i<t.length;i++){n+=dt;const a=t[i];if(a.exclusive){e[i]=null;continue}const c=[];a.forEachCanonicalTargetSet((l,d)=>c.push([l,d])),e[i]=c,n+=lt;for(let l=0;l<c.length;l++)n+=ut+c[l][1].length*re}const r=new Uint8Array(n),s=new DataView(r.buffer);let o=0;s.setUint32(o,t.length,!0),o+=4;for(let i=0;i<t.length;i++){s.setUint32(o,t[i].exclusive?0:1,!0),o+=4;const a=e[i];if(a!==null){s.setUint32(o,a.length,!0),o+=4;for(let c=0;c<a.length;c++){const l=a[c][0],d=a[c][1];s.setUint32(o,l,!0),o+=4,s.setUint32(o,d.length,!0),o+=4;for(let _=0;_<d.length;_++)s.setFloat64(o,d[_],!0),o+=re}}}return r}function Xn(t,e,n){const r=new DataView(e.buffer,e.byteOffset,e.byteLength),s=e.byteLength;let o=0;const i=c=>{if(o+c>s)throw new A(`relation snapshot truncated: need ${c} more bytes at offset ${o}, have ${s-o}`)};for(let c=0;c<t.length;c++)t[c].resetIndices();i(4);const a=r.getUint32(o,!0);if(o+=4,a!==t.length)throw new A(`relation count mismatch: snapshot=${a}, registered=${t.length}`);for(let c=0;c<t.length;c++){const l=t[c];i(dt);const d=r.getUint32(o,!0);if(o+=4,d===1===l.exclusive)throw new A(`relation ${c} cardinality mismatch: snapshot ${d?"multi":"exclusive"}, registered ${l.exclusive?"exclusive":"multi"}`);if(l.exclusive)continue;i(lt);const _=r.getUint32(o,!0);o+=4;for(let f=0;f<_;f++){i(ut);const m=r.getUint32(o,!0);o+=4;const y=r.getUint32(o,!0);if(o+=4,m>L)throw new A(`relation ${c} source index ${m} exceeds MAX_INDEX (${L})`);i(y*re);const u=n(m);for(let h=0;h<y;h++){const I=r.getFloat64(o,!0);o+=re;const Y=I;if(!Number.isInteger(Y)||Y<0||Y>ge)throw new A(`relation ${c} target ${Y} is not a well-formed packed EntityID (expected an integer in [0, ${ge}])`);l.restoreAddTarget(m,I,u)}}}if(o!==s)throw new A(`relation snapshot has ${s-o} trailing bytes after the last relation (not a canonical encoding)`)}const ke=new WeakMap;function Wn(t){const e=new Set,n=new Set,r=new Set,s=new Set,o=new Set,i=new Set,a=new Set,c=new Set,l=new Set,d=new Set;for(let u=0;u<t.writes.length;u++){const h=t.writes[u].id;n.add(h),e.add(h),r.add(h)}for(let u=0;u<t.reads.length;u++)e.add(t.reads[u].id);for(let u=0;u<t.spawns.length;u++){const h=t.spawns[u];for(let I=0;I<h.length;I++)r.add(h[I].id)}for(let u=0;u<t.transitions.length;u++){const h=t.transitions[u];if(h.add)for(let I=0;I<h.add.length;I++)r.add(h.add[I].id);if(h.remove)for(let I=0;I<h.remove.length;I++)s.add(h.remove[I].id)}for(let u=0;u<t.despawns.length;u++)s.add(t.despawns[u].id);for(let u=0;u<t.resourceReads.length;u++)o.add(t.resourceReads[u]);for(let u=0;u<t.resourceWrites.length;u++){const h=t.resourceWrites[u];i.add(h),o.add(h)}const _=t.sparseWrites;if(_!==void 0)for(let u=0;u<_.length;u++){const h=_[u];c.add(h),a.add(h)}const f=t.sparseReads;if(f!==void 0)for(let u=0;u<f.length;u++)a.add(f[u]);const m=t.relationWrites;if(m!==void 0)for(let u=0;u<m.length;u++){const h=m[u];d.add(h),l.add(h)}const y=t.relationReads;if(y!==void 0)for(let u=0;u<y.length;u++)l.add(y[u]);return{reads:e,writes:n,addAllowed:r,removeAllowed:s,hasDespawns:t.despawns.length>0,resourceReads:o,resourceWrites:i,sparseReads:a,sparseWrites:c,relationReads:l,relationWrites:d}}function zn(t){const e=ke.get(t);if(e!==void 0)return e;const n=Wn(t);return ke.set(t,n),n}const Ge=new WeakMap;function qn(t){const e=new Set,n=new Set;if(t.reads!==void 0)for(let r=0;r<t.reads.length;r++)e.add(t.reads[r].id);if(t.resourceReads!==void 0)for(let r=0;r<t.resourceReads.length;r++)n.add(t.resourceReads[r]);return{reads:e,writes:new Set,addAllowed:new Set,removeAllowed:new Set,hasDespawns:!1,resourceReads:n,resourceWrites:new Set,sparseReads:new Set,sparseWrites:new Set,relationReads:new Set,relationWrites:new Set}}function Kn(t){const e=Ge.get(t);if(e!==void 0)return e;const n=qn(t);return Ge.set(t,n),n}class jn{active=null;sets=null;activeName=null;exclusive=!1;enter(e){this.active=e,this.activeName=e.name??`system_${e.id}`,this.exclusive=e.exclusive===!0,this.sets=this.exclusive?null:zn(e)}enterCondition(e){this.active=null,this.activeName=e.name,this.sets=Kn(e)}leave(){this.active=null,this.activeName=null,this.sets=null,this.exclusive=!1}isActive(){return this.sets!==null||this.exclusive}current(){return this.active}checkRead(e){this.sets!==null&&(this.sets.reads.has(e.id)||this.failComponent("read",e,"reads"))}checkWrite(e){this.sets!==null&&(this.sets.writes.has(e.id)||this.failComponent("write",e,"writes"))}checkAdd(e){this.sets!==null&&(this.sets.addAllowed.has(e.id)||this.failComponent("addComponent",e,"spawns / transitions.add / writes"))}checkRemove(e){this.sets!==null&&(this.sets.removeAllowed.has(e.id)||this.failComponent("removeComponent",e,"despawns / transitions.remove"))}checkDestroy(){if(this.sets===null||this.sets.hasDespawns)return;const e=this.activeName;throw new T(p.ACCESS_UNDECLARED,`system '${e}' called despawn but didn't declare any despawns — declare the components this system removes via despawn in its 'despawns'`,{system:e,op:"despawn"})}checkResourceRead(e){if(this.sets===null)return;const n=e;this.sets.resourceReads.has(n)||this.failResource("read",e,"resourceReads")}checkResourceWrite(e){if(this.sets===null)return;const n=e;this.sets.resourceWrites.has(n)||this.failResource("write",e,"resourceWrites")}checkSparseRead(e){if(this.sets===null)return;const n=e;this.sets.sparseReads.has(n)||this.failSparse("read",n,"sparseReads")}checkSparseWrite(e){if(this.sets===null)return;const n=e;this.sets.sparseWrites.has(n)||this.failSparse("write",n,"sparseWrites")}checkRelationRead(e){if(this.sets===null)return;const n=e;this.sets.relationReads.has(n)||this.failRelation("read",n,"relationReads")}checkRelationWrite(e){if(this.sets===null)return;const n=e;this.sets.relationWrites.has(n)||this.failRelation("write",n,"relationWrites")}checkRelationReadAny(){this.sets!==null&&(this.sets.relationReads.has(Ae)||this.failRelation("(*, T) wildcard read",Ae,"relationReads (as ANY_RELATION)"))}optionalScopes=[];enterOptionalScope(e){this.optionalScopes.push(e)}leaveOptionalScope(){this.optionalScopes.pop()}checkOptionalFetch(e){const n=this.optionalScopes.length;if(n===0)return;const r=this.optionalScopes[n-1],s=e.id;for(let o=0;o<r.length;o++)if(r[o]===s)return;throw new T(p.OPTIONAL_TERM_NOT_DECLARED,`getOptionalColumnRead fetched optional component ${s} but the iterating query didn't declare it — add .optional(component) to the query before fetching it`)}failComponent(e,n,r){const s=this.activeName,o=Ke(n);throw new T(p.ACCESS_UNDECLARED,`system '${s}' performed ${e} on ${o} but didn't declare it — add it to '${r}' (see docs/api/systems.md)`,{system:s,op:e,component:n.id})}failSparse(e,n,r){const s=this.activeName;throw new T(p.ACCESS_UNDECLARED,`system '${s}' performed ${e} on sparse component ${n} but didn't declare it — add it to '${r}' (see docs/api/systems.md)`,{system:s,op:e,sparse:n})}failRelation(e,n,r){const s=this.activeName;throw new T(p.ACCESS_UNDECLARED,`system '${s}' performed ${e} on relation ${n} but didn't declare it — add it to '${r}' (see docs/api/systems.md)`,{system:s,op:e,relation:n})}failResource(e,n,r){const s=this.activeName,o=n.description??"<unnamed>";throw new T(p.ACCESS_UNDECLARED,`system '${s}' performed resource ${e} on '${o}' but didn't declare it — add the resource key to '${r}' (see docs/api/systems.md)`,{system:s,op:e,resource:o})}}const K=new jn,Qn="/packages/engine/src/core/ecs/";class Zn{activeCache=null;repoRootCache=null;buf=new Map;callsiteCache=new Map;isActive(){if(this.activeCache!==null)return this.activeCache;const n=globalThis.process?.env?.VISUAL_INTEL_TRACE;return this.activeCache=n==="1"||n==="true"}repoRoot(){if(this.repoRootCache!==null)return this.repoRootCache;const e=globalThis.process;return this.repoRootCache=e?.cwd?.()??""}resolveCallsite(){return es(new Error().stack??null,this.repoRoot(),this.callsiteCache)}record(e,n,r){const s=this.resolveCallsite();if(!s)return;const o=`${e} ${n} ${r} ${s}`;this.buf.set(o,(this.buf.get(o)??0)+1)}recordEmit(e){this.record("ecs-events","emit",e)}recordRead(e){this.record("ecs-events","read",e)}recordResourceRead(e){this.record("resources","read",e)}recordResourceWrite(e){this.record("resources","write",e)}recordResourceRegister(e){this.record("resources","register",e)}recordResourceRemove(e){this.record("resources","remove",e)}recordSendAction(e){this.record("actions","send_action",e)}recordHandleAction(e){this.record("actions","handle_action",e)}snapshot(){const e={"ecs-events":{emit:[],read:[]},actions:{send_action:[],handle_action:[]},resources:{read:[],write:[],register:[],remove:[]}};for(const[n,r]of this.buf.entries()){const[s,o,i,a]=n.split(" ");if(!s||!o||a===void 0)continue;const l={key:s==="actions"?Number(i):i,file:a,count:r},_=e[s][o];_&&_.push(l)}for(const n of Object.values(e))for(const r of Object.values(n))r.sort((s,o)=>{if(s.file!==o.file)return s.file<o.file?-1:1;const i=String(s.key),a=String(o.key);return i<a?-1:i>a?1:0});return{schemaVersion:1,capturedAt:new Date().toISOString(),channels:e}}reset(){this.buf.clear(),this.callsiteCache.clear(),this.activeCache=null,this.repoRootCache=null}}function Jn(t){const e=/\(([^)]+):\d+:\d+\)\s*$/.exec(t);if(e)return e[1]??null;const n=/at\s+([^\s][^()]*?):\d+:\d+\s*$/.exec(t);return n&&(n[1]??"").trim()||null}function es(t,e,n){if(!t)return null;const r=t.split(`
2
+ `);for(let s=0;s<r.length;s++){const o=r[s],i=n?.get(o);if(i!==void 0){if(i===null)continue;return i}const a=Jn(o);if(!a){n?.set(o,null);continue}if(a.includes(Qn)){n?.set(o,null);continue}const c=ts(a,e);return n?.set(o,c),c}return null}function ts(t,e){let n=t;return n.startsWith("file://")&&(n=n.slice(7)),e&&n.startsWith(e+"/")&&(n=n.slice(e.length+1)),n.replace(/\\/g,"/")}const ns=new Zn;var B=(t=>(t.PRE_STARTUP="PRE_STARTUP",t.STARTUP="STARTUP",t.POST_STARTUP="POST_STARTUP",t.FIXED_UPDATE="FIXED_UPDATE",t.PRE_UPDATE="PRE_UPDATE",t.UPDATE="UPDATE",t.POST_UPDATE="POST_UPDATE",t))(B||{});const he=["PRE_STARTUP","STARTUP","POST_STARTUP"],Ee=["PRE_UPDATE","UPDATE","POST_UPDATE"];function ss(t){return Object.freeze({name:t})}function rs(t){return!("fn"in t)}const j=Object.freeze([]);function me(t){return t===void 0?j:Array.isArray(t)?t:[t]}class os{labelSystems=new Map;sortedCache=new Map;systemIndex=new Map;systemLastRun=new Map;gatedSystems=new Map;setConditions=new Map;setOrdering=new Map;nextInsertionOrder=0;_backend=null;onWarn;constructor(e){this.onWarn=e??(n=>console.warn(n));for(let n=0;n<he.length;n++)this.labelSystems.set(he[n],[]);this.labelSystems.set("FIXED_UPDATE",[]);for(let n=0;n<Ee.length;n++)this.labelSystems.set(Ee[n],[])}addSystems(e,...n){for(const r of n){const s="system"in r,o=s?r.system:r,i=s?r.ordering:void 0,a=s?me(r.runIf):j,c=s?me(r.set):j;if(this.systemIndex.has(o))throw new T(p.DUPLICATE_SYSTEM,`System ${o.name??o.id} is already scheduled`);const l={descriptor:o,insertionOrder:this.nextInsertionOrder++,before:new Set(i?.before??[]),after:new Set(i?.after??[]),conditions:a,sets:c};this.labelSystems.get(e).push(l),this.systemIndex.set(o,e),this.systemLastRun.set(o,0),(a.length>0||c.length>0)&&this.gatedSystems.set(o,l),this.sortedCache.delete(e)}}configureSet(e,n){const r=me(n.runIf);if(r.length>0){const s=this.setConditions.get(e);s===void 0?this.setConditions.set(e,[...r]):s.push(...r)}if(n.before!==void 0||n.after!==void 0){let s=this.setOrdering.get(e);s===void 0&&(s={before:new Set,after:new Set},this.setOrdering.set(e,s));for(const o of n.before??j)s.before.add(o);for(const o of n.after??j)s.after.add(o);this.sortedCache.clear()}}removeSystem(e){const n=this.systemIndex.get(e);if(n===void 0)return;const r=this.labelSystems.get(n),s=r.findIndex(o=>o.descriptor===e);if(s!==-1){const o=r.length-1;s!==o&&(r[s]=r[o]),r.pop();for(const i of r)i.before.delete(e),i.after.delete(e)}this.systemIndex.delete(e),this.systemLastRun.delete(e),this.gatedSystems.delete(e),this.sortedCache.delete(n)}setBackend(e){this._backend=e}runStartup(e,n){for(const r of he)this.runLabel(r,e,Ct,n)}runUpdate(e,n,r){for(const s of Ee)this.runLabel(s,e,n,r)}runFixedUpdate(e,n,r){this.runLabel("FIXED_UPDATE",e,n,r)}hasFixedSystems(){return this.labelSystems.get("FIXED_UPDATE").length>0}getAllSystems(){const e=[];for(const n of this.labelSystems.values())for(const r of n)e.push(r.descriptor);return e}hasSystem(e){return this.systemIndex.has(e)}clear(){for(const e of this.labelSystems.values())e.length=0;this.sortedCache.clear(),this.systemIndex.clear(),this.systemLastRun.clear(),this.gatedSystems.clear(),this.setConditions.clear(),this.setOrdering.clear()}runLabel(e,n,r,s){const o=this.getSorted(e),i=this.gatedSystems.size>0,a=this._backend,c=i?new Map:void 0;for(let l=0;l<o.length;l++){const d=o[l];if(i){const f=this.gatedSystems.get(d);if(f!==void 0&&!this.shouldRun(f,n,c))continue}n.lastRunTick=this.systemLastRun.get(d)??0;const _=a!==null?d.backendHandle:void 0;K.enter(d),n._trace?.systemStart(d,e);try{_!==void 0?a.run(_):d.fn?.(n,r)}finally{n._trace?.systemEnd(d),K.leave()}this.systemLastRun.set(d,s)}n._trace?.flushBegin(e),n.flush(),n._trace?.flushEnd(e),n._trace?.phaseBoundary(e)}shouldRun(e,n,r){if(e.conditions.length>0&&!this.evalConditions(e.conditions,n))return!1;for(let s=0;s<e.sets.length;s++){const o=e.sets[s];let i=r.get(o);if(i===void 0){const a=this.setConditions.get(o);i=a===void 0||a.length===0?!0:this.evalConditions(a,n),r.set(o,i)}if(!i)return!1}return!0}evalConditions(e,n){for(let r=0;r<e.length;r++){const s=e[r];K.enterCondition(s);let o;try{o=s.evaluate(n)}finally{K.leave()}if(!o)return!1}return!0}getSorted(e){const n=this.sortedCache.get(e);if(n!==void 0)return n;const r=this.labelSystems.get(e),s=this.sortSystems(r,e);return this.sortedCache.set(e,s),s}sortSystems(e,n){if(e.length===0)return[];const r=[],s=new Map,o=new Set,i=new Map;for(const d of e){r.push(d.descriptor),s.set(d.descriptor,d.insertionOrder),o.add(d.descriptor);for(let _=0;_<d.sets.length;_++){const f=d.sets[_];let m=i.get(f);m===void 0&&(m=[],i.set(f,m)),m.push(d.descriptor)}}const a=new Map;for(const d of e)a.set(d.descriptor,[]);for(const d of e){this.resolveEdges(d.descriptor,d.before,"before",o,i,a,n),this.resolveEdges(d.descriptor,d.after,"after",o,i,a,n);for(let _=0;_<d.sets.length;_++){const f=this.setOrdering.get(d.sets[_]);f!==void 0&&(this.resolveEdges(d.descriptor,f.before,"before",o,i,a,n),this.resolveEdges(d.descriptor,f.after,"after",o,i,a,n))}}const c=(d,_)=>s.get(d)-s.get(_),l=d=>d.name??`system_${d.id}`;try{return We.topologicalSort(r,a,c,l)}catch(d){throw d instanceof TypeError?new T(p.CIRCULAR_SYSTEM_DEPENDENCY,`Circular system dependency detected in ${n}: ${d.message}`):d}}resolveEdges(e,n,r,s,o,i,a){for(const c of n){if(rs(c)){const l=o.get(c);if(l===void 0)continue;for(let d=0;d<l.length;d++){const _=l[d];_!==e&&this.addDirectedEdge(e,_,r,i)}continue}if(!s.has(c)){this.warnDroppedEdge(e,c,r,a);continue}this.addDirectedEdge(e,c,r,i)}}addDirectedEdge(e,n,r,s){r==="before"?s.get(e).push(n):s.get(n).push(e)}warnDroppedEdge(e,n,r,s){if(this.systemIndex.has(n))return;const o=i=>i.name??`system_${i.id}`;this.onWarn(`Schedule[${s}]: \`${o(e)}\` declares \`${r}\` ordering against \`${o(n)}\`, which is not registered in any phase — the constraint is ignored. Check for a typo or a missing add_systems() call.`)}}const oe=1024,ie=1024*oe,He=64*oe,G=256*ie,ye=3,_t=64,ft=8,Ve=4*ie,Xe=t=>2**Math.ceil(Math.log2(Math.max(1,t))),ne=t=>2**Math.floor(Math.log2(Math.max(1,t))),k=(t,e,n)=>Math.min(n,Math.max(e,t)),w=t=>t>=ie?`${(t/ie).toFixed(1)} MiB`:t>=oe?`${(t/oe).toFixed(0)} KiB`:`${t} B`;function D(t,e){if(!Number.isInteger(e)||e<=0)throw new T(p.INVALID_MEMORY_OPTIONS,`memory.${t} must be a positive integer (got ${e})`)}function is(t){const e=["budget","maxBytes","wasm","allocator","heap","shared"].filter(s=>t!==void 0&&t[s]!==void 0);if(e.length>1)throw new T(p.INVALID_MEMORY_OPTIONS,`memory takes at most one of budget | maxBytes | wasm | allocator | heap | shared (got: ${e.join(", ")})`);const n=t?.columnCapacity;if(n!==void 0&&D("column_capacity",n),t?.budget!==void 0){const{entities:s}=t.budget,o=t.budget.archetypes??ft,i=t.budget.bytesPerEntity??_t;if(D("budget.entities",s),D("budget.archetypes",o),D("budget.bytes_per_entity",i),s>1<<20)throw new T(p.INVALID_MEMORY_OPTIONS,`memory.budget.entities=${s} exceeds the EntityID index space (1<<20 = ${1<<20})`);const a=n??k(Xe(Math.ceil(s/o)),64,1<<20),c=k(Xe(s*2),4096,1<<20),l=c*R,d=s*i*ye,_=be(Math.max(l+d,Ve),He);return{source:"budget",allocator:P.heapArraybufferAllocator(_),columnCapacity:a,entityIndexCapacity:c,capBytes:_,intentLabel:`budget of ${s} entities`,budgetEntities:s,derivation:[`column_capacity = ${n!==void 0?`${a} (pinned)`:`pow2(${s}/${o} per archetype) = ${a}`}`,`entity_index = pow2(2 × ${s}) = ${c} slots × ${R} B = ${w(l)}`,`columns = ${s} × ${i} B × ${ye} (double+holes headroom) = ${w(d)}`,`cap = align64K(max(index + columns, ${w(Ve)} floor)) = ${w(_)}`],wasmMemory:null}}if(t?.maxBytes!==void 0){D("maxBytes",t.maxBytes);const s=n??F,o=k(ne(t.maxBytes/4/R),4096,U);return{source:"max_bytes",allocator:P.heapArraybufferAllocator(t.maxBytes),columnCapacity:s,entityIndexCapacity:o,capBytes:t.maxBytes,intentLabel:`explicit cap of ${w(t.maxBytes)}`,budgetEntities:null,derivation:[`cap = ${w(t.maxBytes)} (caller-declared)`,`column_capacity = ${s} (${n!==void 0?"pinned":"default"})`,`entity_index = floor_pow2(cap/4 ÷ ${R} B) = ${o} slots`],wasmMemory:null}}if(t?.wasm!==void 0){const s=t.wasm,o=n??F;if(s.memory!==void 0){if(!(s.memory.buffer instanceof SharedArrayBuffer))throw new T(p.INVALID_MEMORY_OPTIONS,"memory.wasm.memory must be constructed with `shared: true` — the SAB substrate requires a SharedArrayBuffer-backed WebAssembly.Memory (ADR-0004 / ADR-0018)");return{source:"wasm",allocator:P.wasmMemoryAllocator(s.memory),columnCapacity:o,entityIndexCapacity:U,capBytes:null,intentLabel:"caller-supplied WebAssembly.Memory",budgetEntities:null,derivation:["backing = wasm_memory_allocator(memory) — zero-copy with the sim (is_in_place ✓)","cap = the Memory's own `maximum` (declared by the caller; not readable from JS)",`column_capacity = ${o} (${n!==void 0?"pinned":"default"})`],wasmMemory:s.memory}}D("wasm.maximum_pages",s.maximumPages);const i=s.initialPages??Math.min(32,s.maximumPages);if(D("wasm.initial_pages",i),i>s.maximumPages)throw new T(p.INVALID_MEMORY_OPTIONS,`memory.wasm.initial_pages (${i}) exceeds maximum_pages (${s.maximumPages})`);const a=new WebAssembly.Memory({initial:i,maximum:s.maximumPages,shared:!0}),c=s.maximumPages*He,l=k(ne(c/4/R),4096,U);return{source:"wasm",allocator:P.wasmMemoryAllocator(a),columnCapacity:o,entityIndexCapacity:l,capBytes:c,intentLabel:`engine-constructed WebAssembly.Memory (max ${s.maximumPages} pages)`,budgetEntities:null,derivation:[`cap = ${s.maximumPages} pages × 64 KiB = ${w(c)} (Memory maximum)`,`initial = ${i} pages (${s.initialPages!==void 0?"declared":"default"})`,`entity_index = floor_pow2(cap/4 ÷ ${R} B) = ${l} slots`,`column_capacity = ${o} (${n!==void 0?"pinned":"default"})`],wasmMemory:a}}if(t?.allocator!==void 0){if(t.allocator.isInPlace!==!0)throw new T(p.INVALID_MEMORY_OPTIONS,"memory.allocator must declare `is_in_place: true` (ADR-0008): a live Store's flush loops hoist entity-index views across grows, so a non-in-place allocator (e.g. DEFAULT_SAB_ALLOCATOR) corrupts the entity→row mapping. Use growable_sab_allocator / wasm_memory_allocator; non-in-place allocators are snapshot/test sizing only.");const s=n??F,o=t.capBytesHint;return o!==void 0&&D("cap_bytes_hint",o),{source:"allocator",allocator:t.allocator,columnCapacity:s,entityIndexCapacity:U,capBytes:o??null,intentLabel:o!==void 0?`custom in-place allocator (cap hint ${w(o)})`:"custom in-place allocator",budgetEntities:null,derivation:["backing = caller allocator (is_in_place ✓ checked at construction)",o!==void 0?`cap = ${w(o)} (caller hint — diagnostics only; the allocator owns the real cap)`:"cap = allocator-owned (no hint)",`column_capacity = ${s} (${n!==void 0?"pinned":"default"})`],wasmMemory:null}}if(t?.heap!==void 0){t.heap.maxBytes!==void 0&&D("heap.maxBytes",t.heap.maxBytes);const s=t.heap.maxBytes??G,o=n??F,i=k(ne(s/4/R),4096,U);return{source:"heap",allocator:P.heapArraybufferAllocator(s),columnCapacity:o,entityIndexCapacity:i,capBytes:s,intentLabel:`pure-TS heap backing (${w(s)} growable cap, no SharedArrayBuffer)`,budgetEntities:null,derivation:[`backing = heap_arraybuffer_allocator(${w(s)}) — fixed ArrayBuffer reserved at the cap, no SAB / no COOP+COEP (is_in_place ✓)`,"trade-off: no worker offload / no WASM backend (both need a transferable SharedArrayBuffer)",`column_capacity = ${o} (${n!==void 0?"pinned":"default"})`,`entity_index = floor_pow2(cap/4 ÷ ${R} B) = ${i} slots`],wasmMemory:null}}if(t?.shared!==void 0){t.shared.maxBytes!==void 0&&D("shared.maxBytes",t.shared.maxBytes);const s=t.shared.maxBytes??G,o=n??F,i=k(ne(s/4/R),4096,U);return{source:"shared",allocator:P.growableSabAllocator(s),columnCapacity:o,entityIndexCapacity:i,capBytes:s,intentLabel:`shared SharedArrayBuffer backing (${w(s)} growable cap, needs COOP/COEP)`,budgetEntities:null,derivation:[`backing = growable_sab_allocator(${w(s)}) — growable SharedArrayBuffer (is_in_place ✓); needs cross-origin isolation`,"enables worker offload + a WASM compute backend (transferable SharedArrayBuffer)",`column_capacity = ${o} (${n!==void 0?"pinned":"default"})`,`entity_index = floor_pow2(cap/4 ÷ ${R} B) = ${i} slots`],wasmMemory:null}}const r=n??F;return{source:"default",allocator:P.heapArraybufferAllocator(),columnCapacity:r,entityIndexCapacity:U,capBytes:G,intentLabel:`default sizing (${w(G)} growable cap)`,budgetEntities:null,derivation:[`cap = ${w(G)} (heap_arraybuffer_allocator default)`,`column_capacity = ${r} (${n!==void 0?"pinned":"DEFAULT_COLUMN_CAPACITY"})`,`entity_index = ${U} slots (full EntityID space, ~12 MiB virtual)`],wasmMemory:null}}function as(t,e){return{def:t,values:e}}function ae(t,e){switch(e.kind){case"spawn":{const n=t.commands.spawn();for(const r of e.components)t.commands.add(n,r.def,r.values);return e.onSpawned?.(n),n}case"despawn":t.commands.despawn(e.eid);return;case"add_component":t.commands.add(e.eid,e.def,e.values);return;case"remove_component":t.commands.remove(e.eid,e.def);return;case"set_field":if(!t.hasComponent(e.eid,e.def))throw new T(p.COMPONENT_NOT_REGISTERED,`host set_field on entity ${e.eid} targets a component it does not have. If you added that component via a host command this same frame, the add is deferred to the phase flush while set_field is immediate — carry the value in add_component/spawn_entry instead of a separate set_field, or set it next frame. (#681 host write seam)`);t.setField(e.eid,e.def,e.field,e.value);return;case"disable":t.commands.disable(e.eid);return;case"enable":t.commands.enable(e.eid);return;default:return pt(e,"HostCommand kind")}}class ht{queued=[];spawn(e,n){return this.queued.push({kind:"spawn",components:e,onSpawned:n}),this}despawn(e){return this.queued.push({kind:"despawn",eid:e}),this}add(e,n,r){return this.queued.push({kind:"add_component",eid:e,def:n,values:r}),this}remove(e,n){return this.queued.push({kind:"remove_component",eid:e,def:n}),this}setField(e,n,r,s){return this.queued.push({kind:"set_field",eid:e,def:n,field:r,value:s}),this}disable(e){return this.queued.push({kind:"disable",eid:e}),this}enable(e){return this.queued.push({kind:"enable",eid:e}),this}push(e){return this.queued.push(e),this}get pending(){return this.queued.length}clear(){const e=this.queued.length;return this.queued.length=0,e}drain(e,n){const r=this.queued.length;if(r===0)return 0;if(n===void 0)for(let s=0;s<r;s++)ae(e,this.queued[s]);else for(let s=0;s<r;s++){const o=this.queued[s];n(o),ae(e,o)}return this.queued.splice(0,r),r}}const Pe=x-1;function cs(t){if(t===De)throw new M("cannot bind op_code 0 (reserved as the command-ring empty-slot marker)");if(t<0||t>255||!Number.isInteger(t))throw new M(`command op_code must be a u8 in [1, 255] (got ${t})`)}function ue(t){const e=new Uint8Array(Pe);return new DataView(e.buffer).setUint32(0,t,!0),e}function _e(t){return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint32(0,!0)}function ds(t,e){return{encode(n){if(n.kind!=="set_field")throw new M(`ringSetFieldCodec encodes a "set_field" command (got "${n.kind}")`);const r=new Uint8Array(Pe),s=new DataView(r.buffer);return s.setUint32(0,n.eid,!0),s.setFloat64(4,n.value,!0),r},decode(n){const r=new DataView(n.buffer,n.byteOffset,n.byteLength);return{kind:"set_field",eid:r.getUint32(0,!0),def:t,field:e,value:r.getFloat64(4,!0)}}}}function ls(){return{encode(t){if(t.kind!=="despawn")throw new M(`ring_despawn_codec encodes a "despawn" command (got "${t.kind}")`);return ue(t.eid)},decode:t=>({kind:"despawn",eid:_e(t)})}}function us(){return{encode(t){if(t.kind!=="disable")throw new M(`ring_disable_codec encodes a "disable" command (got "${t.kind}")`);return ue(t.eid)},decode:t=>({kind:"disable",eid:_e(t)})}}function _s(){return{encode(t){if(t.kind!=="enable")throw new M(`ring_enable_codec encodes an "enable" command (got "${t.kind}")`);return ue(t.eid)},decode:t=>({kind:"enable",eid:_e(t)})}}function fs(t){return{encode(e){if(e.kind!=="remove_component")throw new M(`ringRemoveComponentCodec encodes a "remove_component" command (got "${e.kind}")`);return ue(e.eid)},decode:e=>({kind:"remove_component",eid:_e(e),def:t})}}class hs{appliers=new Map;on(e,n){return cs(e),this.appliers.set(e,n),this}off(e){return this.appliers.delete(e)}onCommand(e,n){return this.on(e,(r,s,o)=>{const i=n.decode(s);o?.(i),ae(r,i)})}drain(e,n,r,s){return en(n,r,(o,i)=>{const a=this.appliers.get(o);a!==void 0&&a(e,i,s)})}}const Es=new Set([B.PRE_STARTUP,B.STARTUP,B.POST_STARTUP]),Ie=new WeakMap;function ms(t,e){const n=Ie.get(e);if(n===void 0)return!1;for(const r of n)t.removeSystem(r);return Ie.delete(e),e.clear(),!0}function gs(t,e){const n=new ht,r=[];Ie.set(n,r);const s=e?.name??"host_command_apply",o=e?.ring,i=e?.recorder,a=i?.record,c=e?.schedules??[B.PRE_STARTUP,B.PRE_UPDATE];if(i!==void 0&&c.includes(B.FIXED_UPDATE))throw new T(p.INVALID_RECORDER_SCHEDULE,"install_host_command_seam: a recorder cannot drain on SCHEDULE.FIXED_UPDATE — it would log the fixed-step dt instead of the host update(dt) and diverge on replay. Use a variable-update phase (PRE_UPDATE/UPDATE/POST_UPDATE).");for(const l of c){const d=!Es.has(l),_=t.registerSystem({name:`${s}:${l}`,reads:[],writes:[],exclusive:!0,fn:(f,m)=>{if(i!==void 0&&d&&i.openTick(f.ecsTick,m),n.drain(f,a),o!==void 0){const y=t.columnStore,u=y.header.commandRingOff;u!==0&&o.drain(f,y.view,u,a)}}});t.addSystems(l,_),r.push(_)}return n}exports.ACTION_RING_DEFAULT_CAPACITY_SLOTS=En;exports.ANY_RELATION=Ae;exports.ARCHETYPE_DESCRIPTOR_HEADER_BYTES=de;exports.ARCHETYPE_DESCRIPTOR_OFFSETS=N;exports.BUDGET_DEFAULT_ARCHETYPES=ft;exports.BUDGET_DEFAULT_BYTES_PER_ENTITY=_t;exports.BUDGET_GROWTH_HEADROOM=ye;exports.COLUMN_DESCRIPTOR_BYTES=ce;exports.COMMAND_RING_DEFAULT_CAPACITY_SLOTS=zt;exports.COMPONENT_MASK_WORDS=Q;exports.DEFAULT_COLUMN_CAPACITY=F;exports.DEFAULT_ECS_CAP_BYTES=G;exports.DEFAULT_FIXED_TIMESTEP=Dt;exports.DEFAULT_MAX_FIXED_STEPS=Ot;exports.DEFAULT_ON_DELETE_TARGET=xn;exports.ECSError=T;exports.ECS_ERROR=p;exports.EMPTY_VALUES=It;exports.ENTITY_INDEX_DEFAULT_CAPACITY=U;exports.ENTITY_INDEX_HEADER_BYTES=te;exports.ENTITY_INDEX_HEADER_OFFSETS=Z;exports.EVENT_RING_DEFAULT_CAPACITY_SLOTS=dn;exports.FNV1A_OFFSET_BASIS=it;exports.FNV1A_PRIME=Ue;exports.HASH_GOLDEN_RATIO=St;exports.HASH_SECONDARY_PRIME=wt;exports.HOST_COMMAND_PAYLOAD_BYTES=Pe;exports.HostCommandDispatcher=hs;exports.HostCommandQueue=ht;exports.INDEX_BITS=W;exports.INDEX_MASK=we;exports.INITIAL_GENERATION=Nt;exports.MAX_ENTITY_ID=ge;exports.MAX_GENERATION=J;exports.MAX_INDEX=L;exports.MAX_LIVE_GENERATION=vt;exports.NO_SWAP=yt;exports.RELATION_TARGET_FIELD=at;exports.RETIRED_GENERATION=Ut;exports.SCHEDULE=B;exports.SIM_ABI_VERSION=Qe;exports.STORE_DESCRIPTOR_COMPONENT_LIMIT=Gt;exports.STORE_HEADER_BYTES=Ze;exports.STORE_HEADER_OFFSETS=E;exports.STORE_MAGIC=je;exports.STORE_MAX_BYTE_OFFSET=le;exports.STORE_PREFIX_REGIONS=q;exports.Schedule=os;exports.SparseComponentStore=Pn;exports.SparseRestoreError=A;exports.StoreLayoutOverflowError=Ce;exports.TYPED_ARRAY_TAG_TO_TYPE_TAG=xt;exports.TYPE_TAG_STRIDE=Te;exports.UNASSIGNED=At;exports.accessCheck=K;exports.alignUp=be;exports.applyHostCommand=ae;exports.archetypeDescriptorBytes=Re;exports.buildArchetypeViews=ot;exports.buildEntityIndexViews=on;exports.columnKey=rt;exports.componentDebugName=$t;exports.componentLabel=Ke;exports.createColumnStore=Ln;exports.createEntityId=Lt;exports.dispatchTrace=ns;exports.entityNotAliveError=Mt;exports.findRegionEntry=Cn;exports.findRegionOffset=On;exports.fnv1aStepWord=Mn;exports.getEntityGeneration=pe;exports.getEntityIndex=v;exports.installHostCommandSeam=gs;exports.isColumnStoreInternal=vn;exports.isEcsError=Tt;exports.isNonNegativeInteger=Et;exports.makeRelationStore=Hn;exports.readHeaderRegionTable=Dn;exports.readLayoutDescriptorRegion=Xt;exports.readStoreHeader=Ft;exports.resolveECSMemory=is;exports.restoreRelations=Xn;exports.restoreSparseStores=Bn;exports.ringDespawnCodec=ls;exports.ringDisableCodec=us;exports.ringEnableCodec=_s;exports.ringRemoveComponentCodec=fs;exports.ringSetFieldCodec=ds;exports.setComponentDebugName=Pt;exports.snapshotRelations=Vn;exports.snapshotSparseStores=$n;exports.spawnEntry=as;exports.systemSet=ss;exports.uninstallHostCommandSeam=ms;exports.unsafeCast=gt;exports.validateAndCast=mt;exports.validateSparseStores=Fn;exports.writeArchetypeDescriptor=Je;
package/dist/internal.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./host_commands-CxhpzMx9.cjs"),d="/packages/engine/src/core/ecs/";class h{activeCache=null;repoRootCache=null;buf=new Map;callsiteCache=new Map;isActive(){if(this.activeCache!==null)return this.activeCache;const t=globalThis.process?.env?.VISUAL_INTEL_TRACE;return this.activeCache=t==="1"||t==="true"}repoRoot(){if(this.repoRootCache!==null)return this.repoRootCache;const e=globalThis.process;return this.repoRootCache=e?.cwd?.()??""}resolveCallsite(){return T(new Error().stack??null,this.repoRoot(),this.callsiteCache)}record(e,t,l){const s=this.resolveCallsite();if(!s)return;const o=`${e} ${t} ${l} ${s}`;this.buf.set(o,(this.buf.get(o)??0)+1)}recordEmit(e){this.record("ecs-events","emit",e)}recordRead(e){this.record("ecs-events","read",e)}recordResourceRead(e){this.record("resources","read",e)}recordResourceWrite(e){this.record("resources","write",e)}recordResourceRegister(e){this.record("resources","register",e)}recordResourceRemove(e){this.record("resources","remove",e)}recordSendAction(e){this.record("actions","send_action",e)}recordHandleAction(e){this.record("actions","handle_action",e)}snapshot(){const e={"ecs-events":{emit:[],read:[]},actions:{send_action:[],handle_action:[]},resources:{read:[],write:[],register:[],remove:[]}};for(const[t,l]of this.buf.entries()){const[s,o,n,c]=t.split(" ");if(!s||!o||c===void 0)continue;const u={key:s==="actions"?Number(n):n,file:c,count:l},E=e[s][o];E&&E.push(u)}for(const t of Object.values(e))for(const l of Object.values(t))l.sort((s,o)=>{if(s.file!==o.file)return s.file<o.file?-1:1;const n=String(s.key),c=String(o.key);return n<c?-1:n>c?1:0});return{schemaVersion:1,capturedAt:new Date().toISOString(),channels:e}}reset(){this.buf.clear(),this.callsiteCache.clear(),this.activeCache=null,this.repoRootCache=null}}function _(i){const e=/\(([^)]+):\d+:\d+\)\s*$/.exec(i);if(e)return e[1]??null;const t=/at\s+([^\s][^()]*?):\d+:\d+\s*$/.exec(i);return t&&(t[1]??"").trim()||null}function T(i,e,t){if(!i)return null;const l=i.split(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./host_commands-DNf0f6ko.cjs"),d="/packages/engine/src/core/ecs/";class h{activeCache=null;repoRootCache=null;buf=new Map;callsiteCache=new Map;isActive(){if(this.activeCache!==null)return this.activeCache;const t=globalThis.process?.env?.VISUAL_INTEL_TRACE;return this.activeCache=t==="1"||t==="true"}repoRoot(){if(this.repoRootCache!==null)return this.repoRootCache;const e=globalThis.process;return this.repoRootCache=e?.cwd?.()??""}resolveCallsite(){return T(new Error().stack??null,this.repoRoot(),this.callsiteCache)}record(e,t,l){const s=this.resolveCallsite();if(!s)return;const o=`${e} ${t} ${l} ${s}`;this.buf.set(o,(this.buf.get(o)??0)+1)}recordEmit(e){this.record("ecs-events","emit",e)}recordRead(e){this.record("ecs-events","read",e)}recordResourceRead(e){this.record("resources","read",e)}recordResourceWrite(e){this.record("resources","write",e)}recordResourceRegister(e){this.record("resources","register",e)}recordResourceRemove(e){this.record("resources","remove",e)}recordSendAction(e){this.record("actions","send_action",e)}recordHandleAction(e){this.record("actions","handle_action",e)}snapshot(){const e={"ecs-events":{emit:[],read:[]},actions:{send_action:[],handle_action:[]},resources:{read:[],write:[],register:[],remove:[]}};for(const[t,l]of this.buf.entries()){const[s,o,n,c]=t.split(" ");if(!s||!o||c===void 0)continue;const u={key:s==="actions"?Number(n):n,file:c,count:l},E=e[s][o];E&&E.push(u)}for(const t of Object.values(e))for(const l of Object.values(t))l.sort((s,o)=>{if(s.file!==o.file)return s.file<o.file?-1:1;const n=String(s.key),c=String(o.key);return n<c?-1:n>c?1:0});return{schemaVersion:1,capturedAt:new Date().toISOString(),channels:e}}reset(){this.buf.clear(),this.callsiteCache.clear(),this.activeCache=null,this.repoRootCache=null}}function _(i){const e=/\(([^)]+):\d+:\d+\)\s*$/.exec(i);if(e)return e[1]??null;const t=/at\s+([^\s][^()]*?):\d+:\d+\s*$/.exec(i);return t&&(t[1]??"").trim()||null}function T(i,e,t){if(!i)return null;const l=i.split(`
2
2
  `);for(let s=0;s<l.length;s++){const o=l[s],n=t?.get(o);if(n!==void 0){if(n===null)continue;return n}const c=_(o);if(!c){t?.set(o,null);continue}if(c.includes(d)){t?.set(o,null);continue}const a=C(c,e);return t?.set(o,a),a}return null}function C(i,e){let t=i;return t.startsWith("file://")&&(t=t.slice(7)),e&&t.startsWith(e+"/")&&(t=t.slice(e.length+1)),t.replace(/\\/g,"/")}const R=new h;exports.BUDGET_DEFAULT_ARCHETYPES=r.BUDGET_DEFAULT_ARCHETYPES;exports.BUDGET_DEFAULT_BYTES_PER_ENTITY=r.BUDGET_DEFAULT_BYTES_PER_ENTITY;exports.BUDGET_GROWTH_HEADROOM=r.BUDGET_GROWTH_HEADROOM;exports.DEFAULT_ECS_CAP_BYTES=r.DEFAULT_ECS_CAP_BYTES;exports.HOST_COMMAND_PAYLOAD_BYTES=r.HOST_COMMAND_PAYLOAD_BYTES;exports.HostCommandDispatcher=r.HostCommandDispatcher;exports.MAX_ENTITY_ID=r.MAX_ENTITY_ID;exports.MAX_GENERATION=r.MAX_GENERATION;exports.MAX_INDEX=r.MAX_INDEX;exports.MAX_LIVE_GENERATION=r.MAX_LIVE_GENERATION;exports.RETIRED_GENERATION=r.RETIRED_GENERATION;exports.accessCheck=r.accessCheck;exports.createEntityId=r.createEntityId;exports.getEntityGeneration=r.getEntityGeneration;exports.resolveECSMemory=r.resolveECSMemory;exports.ringDespawnCodec=r.ringDespawnCodec;exports.ringDisableCodec=r.ringDisableCodec;exports.ringEnableCodec=r.ringEnableCodec;exports.ringRemoveComponentCodec=r.ringRemoveComponentCodec;exports.ringSetFieldCodec=r.ringSetFieldCodec;exports.dispatchTrace=R;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./internal-LiTSB_tG.cjs");exports.BUDGET_DEFAULT_ARCHETYPES=e.BUDGET_DEFAULT_ARCHETYPES;exports.BUDGET_DEFAULT_BYTES_PER_ENTITY=e.BUDGET_DEFAULT_BYTES_PER_ENTITY;exports.BUDGET_GROWTH_HEADROOM=e.BUDGET_GROWTH_HEADROOM;exports.DEFAULT_ECS_CAP_BYTES=e.DEFAULT_ECS_CAP_BYTES;exports.HOST_COMMAND_PAYLOAD_BYTES=e.HOST_COMMAND_PAYLOAD_BYTES;exports.HostCommandDispatcher=e.HostCommandDispatcher;exports.MAX_ENTITY_ID=e.MAX_ENTITY_ID;exports.MAX_GENERATION=e.MAX_GENERATION;exports.MAX_INDEX=e.MAX_INDEX;exports.MAX_LIVE_GENERATION=e.MAX_LIVE_GENERATION;exports.RETIRED_GENERATION=e.RETIRED_GENERATION;exports.accessCheck=e.accessCheck;exports.createEntityId=e.createEntityId;exports.dispatchTrace=e.dispatchTrace;exports.getEntityGeneration=e.getEntityGeneration;exports.resolveECSMemory=e.resolveECSMemory;exports.ringDespawnCodec=e.ringDespawnCodec;exports.ringDisableCodec=e.ringDisableCodec;exports.ringEnableCodec=e.ringEnableCodec;exports.ringRemoveComponentCodec=e.ringRemoveComponentCodec;exports.ringSetFieldCodec=e.ringSetFieldCodec;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./internal-RZN14uMw.cjs");exports.BUDGET_DEFAULT_ARCHETYPES=e.BUDGET_DEFAULT_ARCHETYPES;exports.BUDGET_DEFAULT_BYTES_PER_ENTITY=e.BUDGET_DEFAULT_BYTES_PER_ENTITY;exports.BUDGET_GROWTH_HEADROOM=e.BUDGET_GROWTH_HEADROOM;exports.DEFAULT_ECS_CAP_BYTES=e.DEFAULT_ECS_CAP_BYTES;exports.HOST_COMMAND_PAYLOAD_BYTES=e.HOST_COMMAND_PAYLOAD_BYTES;exports.HostCommandDispatcher=e.HostCommandDispatcher;exports.MAX_ENTITY_ID=e.MAX_ENTITY_ID;exports.MAX_GENERATION=e.MAX_GENERATION;exports.MAX_INDEX=e.MAX_INDEX;exports.MAX_LIVE_GENERATION=e.MAX_LIVE_GENERATION;exports.RETIRED_GENERATION=e.RETIRED_GENERATION;exports.accessCheck=e.accessCheck;exports.createEntityId=e.createEntityId;exports.dispatchTrace=e.dispatchTrace;exports.getEntityGeneration=e.getEntityGeneration;exports.resolveECSMemory=e.resolveECSMemory;exports.ringDespawnCodec=e.ringDespawnCodec;exports.ringDisableCodec=e.ringDisableCodec;exports.ringEnableCodec=e.ringEnableCodec;exports.ringRemoveComponentCodec=e.ringRemoveComponentCodec;exports.ringSetFieldCodec=e.ringSetFieldCodec;
@@ -1,4 +1,4 @@
1
- import { ax as s, aw as e, av as T, au as _, aE as A, ay as o, a4 as D, aG as n, aF as C, aH as r, p as t, h as c, o as i, ad as d, a3 as I, af as N, aA as R, aB as G, aC as O, aD as M, az as S } from "./internal-BMDgWZbt.js";
1
+ import { ax as s, aw as e, av as T, au as _, aE as A, ay as o, a4 as D, aG as n, aF as C, aH as r, p as t, h as c, o as i, ad as d, a3 as I, af as N, aA as R, aB as G, aC as O, aD as M, az as S } from "./internal-C9jjL90H.js";
2
2
  export {
3
3
  s as BUDGET_DEFAULT_ARCHETYPES,
4
4
  e as BUDGET_DEFAULT_BYTES_PER_ENTITY,
package/dist/internal.js CHANGED
@@ -1,4 +1,4 @@
1
- import { b as v, a as A, B as g, D as m, i as D, H as S, n as b, l as I, M, m as N, R as O, c as k, j as w, k as y, r as G, e as F, f as B, g as H, h as L, d as U } from "./host_commands-BI8pEmjH.js";
1
+ import { b as v, a as A, B as g, D as m, i as D, H as S, n as b, l as I, M, m as N, R as O, c as k, j as w, k as y, r as G, e as F, f as B, g as H, h as L, d as U } from "./host_commands-3jyFfWNg.js";
2
2
  const h = "/packages/engine/src/core/ecs/";
3
3
  class d {
4
4
  activeCache = null;
@@ -0,0 +1 @@
1
+ "use strict";class s extends Error{constructor(t,e,a,n){super(t,n),this.requestedBytes=e,this.capBytes=a,this.name="StoreCapExceededError"}}class l extends Error{constructor(){super("SharedArrayBuffer is not available in this runtime. The chosen world backing is SAB-based and cannot start without it. In browsers this requires cross-origin isolation: serve the page with `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp` (or `credentialless`). Alternatively choose the pure-TS heap profile (`memory: { heap: {} }`), which is backed by a plain ArrayBuffer and needs no SAB / no COOP+COEP. In Bun/Node SAB is available unconditionally — if you see this there, the runtime is older than expected or the global was shadowed."),this.name="SabUnavailableError"}}const h=r=>{if(typeof SharedArrayBuffer>"u")throw new l;return new SharedArrayBuffer(r)},d=64*1024;function f(r,t,e){if(e<=0||!Number.isInteger(e))throw new Error(`${r}: maxBytes must be a positive integer (got ${e})`);let a=null;const n=o=>{if(o>e)throw new s(`${r}: requested ${o} bytes exceeds the by-design maxBytes cap of ${e}. This is a hard ceiling with no grow-beyond-cap fallback (#380); a real workload stays ~16 MiB. Reaching it signals runaway entity/column growth upstream — diagnose that rather than raising the cap blindly.`,o,e);return a===null?(a=t.create(o,e),a):(o>a.byteLength&&t.growTo(a,o),a)};return Object.defineProperty(n,"isInPlace",{value:!0,enumerable:!0}),n}function w(r=256*1024*1024){if(typeof SharedArrayBuffer>"u")throw new l;return f("growable_sab_allocator",{create:(t,e)=>{const a=SharedArrayBuffer;return new a(t,{maxByteLength:e})},growTo:(t,e)=>t.grow(e)},r)}function b(r=256*1024*1024){return f("heap_arraybuffer_allocator",{create:(t,e)=>new ArrayBuffer(e),growTo:()=>{throw new Error("heap_arraybuffer_allocator: the heap buffer is fixed at maxBytes and must never grow — growth relocates columns within the buffer, not the buffer itself")}},r)}function A(r){if(!(r.buffer instanceof SharedArrayBuffer))throw new Error("wasm_memory_allocator: WebAssembly.Memory must be constructed with `shared: true` so its buffer is a SharedArrayBuffer");const t=()=>r.buffer,e=a=>{const n=r.buffer.byteLength;if(a<=n)return t();const o=Math.ceil((a-n)/d),u=i=>new s(`wasm_memory_allocator: memory.grow(${o}) failed (current=${n} bytes, requested=${a} bytes, maximum may be reached)`,a,null,{cause:i});let c;try{c=r.grow(o)}catch(i){throw u(i)}if(c===-1)throw u();return t()};return Object.defineProperty(e,"isInPlace",{value:!0,enumerable:!0}),e}exports.DEFAULT_SAB_ALLOCATOR=h;exports.SabUnavailableError=l;exports.StoreCapExceededError=s;exports.growableSabAllocator=w;exports.heapArraybufferAllocator=b;exports.wasmMemoryAllocator=A;
@@ -1,6 +1,6 @@
1
1
  class u extends Error {
2
- constructor(t, e, r, n) {
3
- super(t, n), this.requestedBytes = e, this.capBytes = r, this.name = "StoreCapExceededError";
2
+ constructor(t, e, a, n) {
3
+ super(t, n), this.requestedBytes = e, this.capBytes = a, this.name = "StoreCapExceededError";
4
4
  }
5
5
  }
6
6
  class c extends Error {
@@ -10,80 +10,86 @@ class c extends Error {
10
10
  ), this.name = "SabUnavailableError";
11
11
  }
12
12
  }
13
- const d = (a) => {
13
+ const d = (r) => {
14
14
  if (typeof SharedArrayBuffer > "u") throw new c();
15
- return new SharedArrayBuffer(a);
15
+ return new SharedArrayBuffer(r);
16
16
  }, h = 64 * 1024;
17
- function f(a, t, e) {
17
+ function f(r, t, e) {
18
18
  if (e <= 0 || !Number.isInteger(e))
19
- throw new Error(`${a}: maxBytes must be a positive integer (got ${e})`);
20
- let r = null;
19
+ throw new Error(`${r}: maxBytes must be a positive integer (got ${e})`);
20
+ let a = null;
21
21
  const n = (o) => {
22
22
  if (o > e)
23
23
  throw new u(
24
- `${a}: requested ${o} bytes exceeds the by-design maxBytes cap of ${e}. This is a hard ceiling with no grow-beyond-cap fallback (#380); a real workload stays ~16 MiB. Reaching it signals runaway entity/column growth upstream — diagnose that rather than raising the cap blindly.`,
24
+ `${r}: requested ${o} bytes exceeds the by-design maxBytes cap of ${e}. This is a hard ceiling with no grow-beyond-cap fallback (#380); a real workload stays ~16 MiB. Reaching it signals runaway entity/column growth upstream — diagnose that rather than raising the cap blindly.`,
25
25
  o,
26
26
  e
27
27
  );
28
- return r === null ? (r = t.create(o, e), r) : (o > r.byteLength && t.growTo(r, o), r);
28
+ return a === null ? (a = t.create(o, e), a) : (o > a.byteLength && t.growTo(a, o), a);
29
29
  };
30
30
  return Object.defineProperty(n, "isInPlace", { value: !0, enumerable: !0 }), n;
31
31
  }
32
- function w(a = 256 * 1024 * 1024) {
32
+ function w(r = 256 * 1024 * 1024) {
33
33
  if (typeof SharedArrayBuffer > "u") throw new c();
34
34
  return f(
35
35
  "growable_sab_allocator",
36
36
  {
37
37
  create: (t, e) => {
38
- const r = SharedArrayBuffer;
39
- return new r(t, { maxByteLength: e });
38
+ const a = SharedArrayBuffer;
39
+ return new a(t, { maxByteLength: e });
40
40
  },
41
41
  // boundary: SharedArrayBuffer.grow is in the spec but not in all
42
42
  // lib types; widen here so the rest of the layer doesn't need to.
43
43
  growTo: (t, e) => t.grow(e)
44
44
  },
45
- a
45
+ r
46
46
  );
47
47
  }
48
- function b(a = 256 * 1024 * 1024) {
48
+ function b(r = 256 * 1024 * 1024) {
49
49
  return f(
50
50
  "heap_arraybuffer_allocator",
51
51
  {
52
- create: (t, e) => {
53
- const r = ArrayBuffer;
54
- return new r(t, { maxByteLength: e });
55
- },
56
- // boundary: `ArrayBuffer.prototype.resize` is ES2024, not in the ES2022
57
- // lib types; widen here. Resize keeps the same buffer object and
58
- // preserves existing views (the in-place contract).
59
- growTo: (t, e) => t.resize(e)
52
+ // Reserve the whole cap as ONE fixed buffer. `byteLength` (the current
53
+ // need) is ignored: the buffer never resizes, so it must be born at the
54
+ // ceiling. Lazy page-faulting keeps RSS proportional to real use.
55
+ create: (t, e) => new ArrayBuffer(e),
56
+ // Unreachable: the buffer is created at `maxByteLength`, so
57
+ // `makeGrowableAllocator`'s `bytes > buffer.byteLength` guard never fires
58
+ // (a byte count past the cap throws first). A fixed `ArrayBuffer` has no
59
+ // `.resize()`; assert loudly rather than attempt one, in case the guard
60
+ // logic ever changes.
61
+ growTo: () => {
62
+ throw new Error(
63
+ "heap_arraybuffer_allocator: the heap buffer is fixed at maxBytes and must never grow — growth relocates columns within the buffer, not the buffer itself"
64
+ );
65
+ }
60
66
  },
61
- a
67
+ r
62
68
  );
63
69
  }
64
- function g(a) {
65
- if (!(a.buffer instanceof SharedArrayBuffer))
70
+ function g(r) {
71
+ if (!(r.buffer instanceof SharedArrayBuffer))
66
72
  throw new Error(
67
73
  "wasm_memory_allocator: WebAssembly.Memory must be constructed with `shared: true` so its buffer is a SharedArrayBuffer"
68
74
  );
69
- const t = () => a.buffer, e = (r) => {
70
- const n = a.buffer.byteLength;
71
- if (r <= n)
75
+ const t = () => r.buffer, e = (a) => {
76
+ const n = r.buffer.byteLength;
77
+ if (a <= n)
72
78
  return t();
73
- const o = Math.ceil((r - n) / h), s = (i) => (
79
+ const o = Math.ceil((a - n) / h), s = (i) => (
74
80
  // The JS API doesn't expose the Memory's `maximum`, so the cap is
75
81
  // reported as unknowable (`null`) — the caller declared it at
76
82
  // `new WebAssembly.Memory({ maximum })` time.
77
83
  new u(
78
- `wasm_memory_allocator: memory.grow(${o}) failed (current=${n} bytes, requested=${r} bytes, maximum may be reached)`,
79
- r,
84
+ `wasm_memory_allocator: memory.grow(${o}) failed (current=${n} bytes, requested=${a} bytes, maximum may be reached)`,
85
+ a,
80
86
  null,
81
87
  { cause: i }
82
88
  )
83
89
  );
84
90
  let l;
85
91
  try {
86
- l = a.grow(o);
92
+ l = r.grow(o);
87
93
  } catch (i) {
88
94
  throw s(i);
89
95
  }
package/dist/shared.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./shared-BymrGTyR.cjs");exports.DEFAULT_SAB_ALLOCATOR=a.DEFAULT_SAB_ALLOCATOR;exports.SabUnavailableError=a.SabUnavailableError;exports.growableSabAllocator=a.growableSabAllocator;exports.wasmMemoryAllocator=a.wasmMemoryAllocator;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./shared-BMXh9hxm.cjs");exports.DEFAULT_SAB_ALLOCATOR=a.DEFAULT_SAB_ALLOCATOR;exports.SabUnavailableError=a.SabUnavailableError;exports.growableSabAllocator=a.growableSabAllocator;exports.wasmMemoryAllocator=a.wasmMemoryAllocator;
package/dist/shared.d.cts CHANGED
@@ -2,7 +2,7 @@
2
2
  * `@oasys/oecs/shared` — the opt-in SharedArrayBuffer / WASM profile.
3
3
  *
4
4
  * The default `@oasys/oecs` profile runs the column store over a plain
5
- * resizable `ArrayBuffer` (no cross-origin isolation). This entry surfaces the
5
+ * fixed `ArrayBuffer` (no cross-origin isolation). This entry surfaces the
6
6
  * `SharedArrayBuffer`-backed allocators for worlds that opt into worker offload
7
7
  * or a WASM compute backend — construct with `new ECS({ memory: { shared: {} } })`,
8
8
  * or pass one of these allocators through `memory: { allocator }`.
package/dist/shared.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * `@oasys/oecs/shared` — the opt-in SharedArrayBuffer / WASM profile.
3
3
  *
4
4
  * The default `@oasys/oecs` profile runs the column store over a plain
5
- * resizable `ArrayBuffer` (no cross-origin isolation). This entry surfaces the
5
+ * fixed `ArrayBuffer` (no cross-origin isolation). This entry surfaces the
6
6
  * `SharedArrayBuffer`-backed allocators for worlds that opt into worker offload
7
7
  * or a WASM compute backend — construct with `new ECS({ memory: { shared: {} } })`,
8
8
  * or pass one of these allocators through `memory: { allocator }`.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./shared-BymrGTyR.cjs");exports.DEFAULT_SAB_ALLOCATOR=a.DEFAULT_SAB_ALLOCATOR;exports.SabUnavailableError=a.SabUnavailableError;exports.growableSabAllocator=a.growableSabAllocator;exports.wasmMemoryAllocator=a.wasmMemoryAllocator;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./shared-BMXh9hxm.cjs");exports.DEFAULT_SAB_ALLOCATOR=a.DEFAULT_SAB_ALLOCATOR;exports.SabUnavailableError=a.SabUnavailableError;exports.growableSabAllocator=a.growableSabAllocator;exports.wasmMemoryAllocator=a.wasmMemoryAllocator;
@@ -1,4 +1,4 @@
1
- import { D as r, a as l, g as A, w as s } from "./shared-BU1Cd40h.js";
1
+ import { D as r, a as l, g as A, w as s } from "./shared-DQKK0i-E.js";
2
2
  export {
3
3
  r as DEFAULT_SAB_ALLOCATOR,
4
4
  l as SabUnavailableError,
package/dist/shared.js CHANGED
@@ -1,4 +1,4 @@
1
- import { D as r, a as l, g as A, w as s } from "./shared-BU1Cd40h.js";
1
+ import { D as r, a as l, g as A, w as s } from "./shared-DQKK0i-E.js";
2
2
  export {
3
3
  r as DEFAULT_SAB_ALLOCATOR,
4
4
  l as SabUnavailableError,
@@ -6,5 +6,5 @@
6
6
  * `jsr.json` by `src/__tests__/version_sync.test.ts` — bump all three
7
7
  * together.
8
8
  */
9
- export declare const VERSION = "0.5.2";
9
+ export declare const VERSION = "0.5.3";
10
10
  //# sourceMappingURL=version.d.ts.map
package/dist/version.d.ts CHANGED
@@ -6,5 +6,5 @@
6
6
  * `jsr.json` by `src/__tests__/version_sync.test.ts` — bump all three
7
7
  * together.
8
8
  */
9
- export declare const VERSION = "0.5.2";
9
+ export declare const VERSION = "0.5.3";
10
10
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oasys/oecs",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "Archetype-based Entity Component System",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1 +0,0 @@
1
- "use strict";class s extends Error{constructor(o,r,e,n){super(o,n),this.requestedBytes=r,this.capBytes=e,this.name="StoreCapExceededError"}}class l extends Error{constructor(){super("SharedArrayBuffer is not available in this runtime. The chosen world backing is SAB-based and cannot start without it. In browsers this requires cross-origin isolation: serve the page with `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp` (or `credentialless`). Alternatively choose the pure-TS heap profile (`memory: { heap: {} }`), which is backed by a plain ArrayBuffer and needs no SAB / no COOP+COEP. In Bun/Node SAB is available unconditionally — if you see this there, the runtime is older than expected or the global was shadowed."),this.name="SabUnavailableError"}}const h=a=>{if(typeof SharedArrayBuffer>"u")throw new l;return new SharedArrayBuffer(a)},d=64*1024;function f(a,o,r){if(r<=0||!Number.isInteger(r))throw new Error(`${a}: maxBytes must be a positive integer (got ${r})`);let e=null;const n=t=>{if(t>r)throw new s(`${a}: requested ${t} bytes exceeds the by-design maxBytes cap of ${r}. This is a hard ceiling with no grow-beyond-cap fallback (#380); a real workload stays ~16 MiB. Reaching it signals runaway entity/column growth upstream — diagnose that rather than raising the cap blindly.`,t,r);return e===null?(e=o.create(t,r),e):(t>e.byteLength&&o.growTo(e,t),e)};return Object.defineProperty(n,"isInPlace",{value:!0,enumerable:!0}),n}function b(a=256*1024*1024){if(typeof SharedArrayBuffer>"u")throw new l;return f("growable_sab_allocator",{create:(o,r)=>{const e=SharedArrayBuffer;return new e(o,{maxByteLength:r})},growTo:(o,r)=>o.grow(r)},a)}function w(a=256*1024*1024){return f("heap_arraybuffer_allocator",{create:(o,r)=>{const e=ArrayBuffer;return new e(o,{maxByteLength:r})},growTo:(o,r)=>o.resize(r)},a)}function A(a){if(!(a.buffer instanceof SharedArrayBuffer))throw new Error("wasm_memory_allocator: WebAssembly.Memory must be constructed with `shared: true` so its buffer is a SharedArrayBuffer");const o=()=>a.buffer,r=e=>{const n=a.buffer.byteLength;if(e<=n)return o();const t=Math.ceil((e-n)/d),c=i=>new s(`wasm_memory_allocator: memory.grow(${t}) failed (current=${n} bytes, requested=${e} bytes, maximum may be reached)`,e,null,{cause:i});let u;try{u=a.grow(t)}catch(i){throw c(i)}if(u===-1)throw c();return o()};return Object.defineProperty(r,"isInPlace",{value:!0,enumerable:!0}),r}exports.DEFAULT_SAB_ALLOCATOR=h;exports.SabUnavailableError=l;exports.StoreCapExceededError=s;exports.growableSabAllocator=b;exports.heapArraybufferAllocator=w;exports.wasmMemoryAllocator=A;