aiecsjs 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +18 -1
  2. package/README.md +16 -14
  3. package/README_ZHTW.md +16 -14
  4. package/STABILITY.md +11 -8
  5. package/STABILITY_ZHTW.md +12 -9
  6. package/api.json +41 -16
  7. package/dist/{chunk-AGHSWLNQ.cjs → chunk-B777DQR7.cjs} +2 -2
  8. package/dist/{chunk-AGHSWLNQ.cjs.map → chunk-B777DQR7.cjs.map} +1 -1
  9. package/dist/{chunk-QOKIEF7C.js → chunk-CTESP3XL.js} +2 -2
  10. package/dist/{chunk-QOKIEF7C.js.map → chunk-CTESP3XL.js.map} +1 -1
  11. package/dist/{chunk-L5CMKMIP.js → chunk-F7KNZ27O.js} +2 -2
  12. package/dist/{chunk-L5CMKMIP.js.map → chunk-F7KNZ27O.js.map} +1 -1
  13. package/dist/{chunk-37HMYMJG.cjs → chunk-RHH5JA74.cjs} +2 -2
  14. package/dist/{chunk-37HMYMJG.cjs.map → chunk-RHH5JA74.cjs.map} +1 -1
  15. package/dist/{chunk-4RPFOVQC.cjs → chunk-SJDWI3OZ.cjs} +2 -2
  16. package/dist/{chunk-4RPFOVQC.cjs.map → chunk-SJDWI3OZ.cjs.map} +1 -1
  17. package/dist/{chunk-FDXCXNZK.js → chunk-SQWZUC2Q.js} +2 -2
  18. package/dist/{chunk-FDXCXNZK.js.map → chunk-SQWZUC2Q.js.map} +1 -1
  19. package/dist/commands.cjs +1 -1
  20. package/dist/commands.js +1 -1
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.d.cts +1 -1
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +1 -1
  25. package/dist/observers.cjs +1 -1
  26. package/dist/observers.js +1 -1
  27. package/dist/relations.cjs +1 -1
  28. package/dist/relations.cjs.map +1 -1
  29. package/dist/relations.d.cts +20 -1
  30. package/dist/relations.d.ts +20 -1
  31. package/dist/relations.js +1 -1
  32. package/dist/relations.js.map +1 -1
  33. package/dist/serialize.cjs +1 -1
  34. package/dist/serialize.js +1 -1
  35. package/dist/worker.cjs +1 -1
  36. package/dist/worker.js +1 -1
  37. package/llms-full.txt +45 -23
  38. package/package.json +7 -5
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/internal/query.ts"],"names":["nextQueryId","moduleQueryCache","descKey","d","all","c","a","b","any","none","defineQuery","arg","desc","key","cached","q","enterQuery","query","reactive","exitQuery","ensureQueryRegistered","state","ww","withMask","createMask","anyMask","noneMask","compId","info","getComponentInfoById","bit","getOrRegisterComponentBit","setBit","bundle","isMaskZero","involvedBits","listBits","s","getQueryArchetypes","words","list","i","arch","matches","queryArchetypes","world","getWorldState","ids","out","id","runQuery","buf","e","archIds","r","iterQuery","src","forEachEntity","fn","cols","buildColumnViews","callWithCols","ents","n","eid","comp","getComponentInfo","storage","recordEntityMaskChange","changedBit","prevMask","nextMask","involved","qid","wasMatch","isMatch","pushReactive","queryId","kind","ensureReactiveBuffer","componentId","lazyGetComponentInfo","_getComponentInfoFn","registerComponentLookup"],"mappings":"8EAsBA,IAAIA,EAAc,CAAA,CACZC,CAAAA,CAAmB,IAAI,GAAA,CAE7B,SAASC,CAAAA,CAAQC,CAAAA,CAA4B,CAC3C,IAAMC,GAAOD,CAAAA,CAAE,GAAA,EAAO,EAAC,EACpB,GAAA,CAAKE,GAAMA,CAAAA,CAAE,IAAI,CAAA,CACjB,IAAA,CAAK,CAACC,CAAAA,CAAGC,CAAAA,GAAMD,EAAIC,CAAC,CAAA,CACpB,KAAK,GAAG,CAAA,CACLC,CAAAA,CAAAA,CAAOL,CAAAA,CAAE,KAAO,EAAC,EACpB,IAAKE,CAAAA,EAAMA,CAAAA,CAAE,IAAI,CAAA,CACjB,IAAA,CAAK,CAACC,CAAAA,CAAGC,IAAMD,CAAAA,CAAIC,CAAC,EACpB,IAAA,CAAK,GAAG,EACLE,CAAAA,CAAAA,CAAQ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AA,IAAK/D,CAAAA,CAAiB,MAAA,EAAO,CAAG,CAEzC,GADI,CAAA,CAAE,gBAAkB4E,CAAAA,EACpB,CAAA,CAAE,eAAiBC,CAAAA,CAAM,SAE7B1D,CAAAA,CAAsBC,CAAAA,CAAO,CAAC,CAAA,CAC9B,IAAM8B,EAAM4B,CAAAA,CAAqB1D,CAAAA,CAAO,EAAE,EAAE,CAAA,CACxCyD,CAAAA,GAAS,OAAA,CAAS3B,EAAI,OAAA,CAAQ,IAAA,CAAKa,CAAa,CAAA,CAC/Cb,CAAAA,CAAI,OAAO,IAAA,CAAKa,CAAa,EACpC,CACF,CAEA,SAASe,CAAAA,CAAqB1D,EAAmBoD,CAAAA,CAA6B,CAC5E,IAAItB,CAAAA,CAAM9B,CAAAA,CAAM,eAAA,CAAgB,GAAA,CAAIoD,CAAG,CAAA,CACvC,OAAKtB,IACHA,CAAAA,CAAM,CAAE,QAAS,EAAC,CAAG,MAAA,CAAQ,EAAG,CAAA,CAChC9B,CAAAA,CAAM,gBAAgB,GAAA,CAAIoD,CAAAA,CAAKtB,CAAG,CAAA,CAAA,CAE7BA,CACT,CAIA,SAAStB,EAAqBmD,CAAAA,CAAoC,CAEhE,IAAMpD,CAAAA,CAAOqD,CAAAA,CAAqBD,CAAW,CAAA,CAC7C,GAAI,CAACpD,CAAAA,CAAM,MAAM,IAAI,KAAA,CAAM,yBAAyBoD,CAAW,CAAA,eAAA,CAAiB,EAChF,OAAOpD,CACT,CAEA,IAAIsD,EAA0E,IAAA,CACvE,SAASC,EAAwBzB,CAAAA,CAAqD,CAC3FwB,EAAsBxB,EACxB,CACA,SAASuB,CAAAA,CAAqBhC,EAAuC,CACnE,OAAOiC,EAAsBA,CAAAA,CAAoBjC,CAAE,EAAI,MACzD","file":"chunk-FDXCXNZK.js","sourcesContent":["import { createMask, isMaskZero, listBits, matches, setBit } from './bitmask.js'\nimport { getComponentInfo } from './component.js'\nimport type {\n Archetype,\n ComponentInfo,\n ComponentLike,\n EntityId,\n Query,\n QueryDescriptor,\n QueryInternal,\n QueryMaskBundle,\n ReactiveBuffer,\n World,\n WorldState,\n} from './types.js'\nimport {\n getOrRegisterComponentBit,\n getWorldState,\n readEntityMask,\n tryGetComponentBit,\n} from './world.js'\n\nlet nextQueryId = 1\nconst moduleQueryCache = new Map<string, QueryInternal>()\n\nfunction descKey(d: QueryDescriptor): string {\n const all = (d.all ?? [])\n .map((c) => c.__id)\n .sort((a, b) => a - b)\n .join('-')\n const any = (d.any ?? [])\n .map((c) => c.__id)\n .sort((a, b) => a - b)\n .join('-')\n const none = (d.none ?? [])\n .map((c) => c.__id)\n .sort((a, b) => a - b)\n .join('-')\n return `A${all}|Y${any}|N${none}`\n}\n\nexport function defineQuery(arg: ComponentLike[] | QueryDescriptor): Query {\n const desc: QueryDescriptor = Array.isArray(arg) ? { all: arg } : arg\n\n // Validate all members are components\n for (const c of [...(desc.all ?? []), ...(desc.any ?? []), ...(desc.none ?? [])]) {\n if (!c || typeof c !== 'object' || typeof (c as any).__id !== 'number') {\n throw new TypeError('aiecsjs: defineQuery received a non-component value')\n }\n }\n\n const key = descKey(desc)\n const cached = moduleQueryCache.get(key)\n if (cached) return cached\n\n const q: QueryInternal = {\n id: nextQueryId++,\n mask: [],\n all: (desc.all ?? []).map((c) => c.__id),\n any: (desc.any ?? []).map((c) => c.__id),\n none: (desc.none ?? []).map((c) => c.__id),\n columnViewCache: [...(desc.all ?? []), ...(desc.any ?? [])],\n reactiveKind: 'normal',\n sourceQueryId: -1,\n sourceQuery: null,\n }\n moduleQueryCache.set(key, q)\n return q\n}\n\nexport function enterQuery(query: Query): Query {\n const q = query as QueryInternal\n const key = `enter:${q.id}`\n const cached = moduleQueryCache.get(key)\n if (cached) return cached\n const reactive: QueryInternal = {\n id: nextQueryId++,\n mask: [],\n all: q.all,\n any: q.any,\n none: q.none,\n columnViewCache: q.columnViewCache,\n reactiveKind: 'enter',\n sourceQueryId: q.id,\n sourceQuery: q,\n }\n moduleQueryCache.set(key, reactive)\n return reactive\n}\n\nexport function exitQuery(query: Query): Query {\n const q = query as QueryInternal\n const key = `exit:${q.id}`\n const cached = moduleQueryCache.get(key)\n if (cached) return cached\n const reactive: QueryInternal = {\n id: nextQueryId++,\n mask: [],\n all: q.all,\n any: q.any,\n none: q.none,\n columnViewCache: q.columnViewCache,\n reactiveKind: 'exit',\n sourceQueryId: q.id,\n sourceQuery: q,\n }\n moduleQueryCache.set(key, reactive)\n return reactive\n}\n\n// --- Per-world query setup ---\n\nfunction ensureQueryRegistered(state: WorldState, q: QueryInternal): void {\n if (state.queries[q.id] === q && state.queryMasks.has(q.id)) return\n\n // Build per-world bitmasks (this may register new bits)\n const ww = state.options.maskWordCount\n const withMask = createMask(ww)\n const anyMask = createMask(ww)\n const noneMask = createMask(ww)\n for (const compId of q.all) {\n const info = getComponentInfoById(compId)\n const bit = getOrRegisterComponentBit(state, info)\n setBit(withMask, bit)\n }\n for (const compId of q.any) {\n const info = getComponentInfoById(compId)\n const bit = getOrRegisterComponentBit(state, info)\n setBit(anyMask, bit)\n }\n for (const compId of q.none) {\n const info = getComponentInfoById(compId)\n const bit = getOrRegisterComponentBit(state, info)\n setBit(noneMask, bit)\n }\n\n const bundle: QueryMaskBundle = {\n withMask,\n anyMask,\n noneMask,\n anyHasBits: !isMaskZero(anyMask),\n }\n state.queryMasks.set(q.id, bundle)\n\n state.queries[q.id] = q\n state.queryArchetypeCache[q.id] = null\n state.queryArchetypeStamp[q.id] = -1\n\n // Build bit → queries index for fast reactive lookup\n const involvedBits: number[] = [\n ...listBits(withMask),\n ...listBits(anyMask),\n ...listBits(noneMask),\n ]\n for (const b of involvedBits) {\n let s = state.bitToQueries.get(b)\n if (!s) {\n s = new Set<number>()\n state.bitToQueries.set(b, s)\n }\n s.add(q.id)\n }\n\n // Initialize reactive buffer for enter/exit queries\n if (q.reactiveKind !== 'normal') {\n if (!state.reactiveBuffers.has(q.id)) {\n state.reactiveBuffers.set(q.id, { entered: [], exited: [] })\n }\n // Also register the source query so recordEntityMaskChange will see it\n if (q.sourceQuery) ensureQueryRegistered(state, q.sourceQuery)\n }\n}\n\nfunction getQueryArchetypes(state: WorldState, q: QueryInternal): number[] {\n ensureQueryRegistered(state, q)\n if (state.queryArchetypeCache[q.id] && state.queryArchetypeStamp[q.id] === state.queryVersion) {\n return state.queryArchetypeCache[q.id]!\n }\n const bundle = state.queryMasks.get(q.id)!\n const words = state.options.maskWordCount\n const list: number[] = []\n for (let i = 0; i < state.archetypes.length; i++) {\n const arch = state.archetypes[i]!\n if (\n matches(arch.mask, bundle.withMask, bundle.anyMask, bundle.noneMask, bundle.anyHasBits, words)\n ) {\n list.push(i)\n }\n }\n state.queryArchetypeCache[q.id] = list\n state.queryArchetypeStamp[q.id] = state.queryVersion\n return list\n}\n\nexport function queryArchetypes(world: World, query: Query): readonly Archetype[] {\n const state = getWorldState(world)\n const q = query as QueryInternal\n const ids = getQueryArchetypes(state, q)\n const out: Archetype[] = []\n for (const id of ids) {\n const arch = state.archetypes[id]!\n out.push({ id: arch.id, mask: Array.from(arch.mask), size: arch.size })\n }\n return out\n}\n\nexport function runQuery(world: World, query: Query): readonly EntityId[] {\n const state = getWorldState(world)\n const q = query as QueryInternal\n const out: EntityId[] = []\n if (q.reactiveKind === 'enter') {\n const buf = state.reactiveBuffers.get(q.id)\n if (buf) {\n for (const e of buf.entered) out.push(e as EntityId)\n buf.entered.length = 0\n }\n return out\n }\n if (q.reactiveKind === 'exit') {\n const buf = state.reactiveBuffers.get(q.id)\n if (buf) {\n for (const e of buf.exited) out.push(e as EntityId)\n buf.exited.length = 0\n }\n return out\n }\n const archIds = getQueryArchetypes(state, q)\n for (const id of archIds) {\n const arch = state.archetypes[id]!\n for (let r = 0; r < arch.size; r++) {\n out.push(arch.entities[r] as EntityId)\n }\n }\n return out\n}\n\nexport function* iterQuery(world: World, query: Query): IterableIterator<EntityId> {\n const state = getWorldState(world)\n const q = query as QueryInternal\n if (q.reactiveKind !== 'normal') {\n const buf = state.reactiveBuffers.get(q.id)\n if (!buf) return\n const src = q.reactiveKind === 'enter' ? buf.entered : buf.exited\n for (const e of src) yield e as EntityId\n src.length = 0\n return\n }\n const archIds = getQueryArchetypes(state, q)\n for (const id of archIds) {\n const arch = state.archetypes[id]!\n for (let r = 0; r < arch.size; r++) {\n yield arch.entities[r] as EntityId\n }\n }\n}\n\nexport function forEachEntity(\n world: World,\n query: Query,\n fn: (eid: EntityId, ...cols: any[]) => void,\n): void {\n const state = getWorldState(world)\n const q = query as QueryInternal\n\n if (q.reactiveKind !== 'normal') {\n const buf = state.reactiveBuffers.get(q.id)\n if (!buf) return\n const src = q.reactiveKind === 'enter' ? buf.entered : buf.exited\n if (src.length === 0) return\n const cols = buildColumnViews(state, q)\n for (let i = 0; i < src.length; i++) {\n const e = src[i] as EntityId\n callWithCols(fn, e, cols)\n }\n src.length = 0\n return\n }\n\n ensureQueryRegistered(state, q)\n const archIds = getQueryArchetypes(state, q)\n const cols = buildColumnViews(state, q)\n for (const id of archIds) {\n const arch = state.archetypes[id]!\n const ents = arch.entities\n const n = arch.size\n for (let r = 0; r < n; r++) {\n callWithCols(fn, ents[r] as EntityId, cols)\n }\n }\n}\n\nfunction callWithCols(\n fn: (eid: EntityId, ...cols: any[]) => void,\n eid: EntityId,\n cols: any[],\n): void {\n // Specialise for low arities to avoid spread allocation.\n switch (cols.length) {\n case 0:\n fn(eid)\n break\n case 1:\n fn(eid, cols[0])\n break\n case 2:\n fn(eid, cols[0], cols[1])\n break\n case 3:\n fn(eid, cols[0], cols[1], cols[2])\n break\n case 4:\n fn(eid, cols[0], cols[1], cols[2], cols[3])\n break\n case 5:\n fn(eid, cols[0], cols[1], cols[2], cols[3], cols[4])\n break\n default:\n fn(eid, ...cols)\n }\n}\n\nfunction buildColumnViews(state: WorldState, q: QueryInternal): any[] {\n const out: any[] = []\n for (const comp of q.columnViewCache) {\n const info = getComponentInfo(comp)\n const bit = state.componentBitFor.get(info.id)\n if (bit === undefined) {\n out.push(undefined)\n continue\n }\n const storage = state.componentStorageByBit[bit]\n if (!storage) {\n out.push(undefined)\n continue\n }\n if (storage.kind === 'soa') out.push(storage.soa)\n else if (storage.kind === 'aos') out.push(storage.aos)\n else out.push(true) // tag\n }\n return out\n}\n\n// --- Reactive query updates (called from migration code) ---\n\nexport function recordEntityMaskChange(\n state: WorldState,\n eid: EntityId,\n changedBit: number,\n prevMask: Uint32Array,\n nextMask: Uint32Array,\n): void {\n // Lazy-register any reactive queries (and their sources) so we can correctly\n // determine match transitions even if the user only ever called enterQuery/exitQuery.\n for (const q of moduleQueryCache.values()) {\n if (q.reactiveKind === 'normal') continue\n if (q.sourceQuery && state.queries[q.sourceQuery.id] !== q.sourceQuery) {\n ensureQueryRegistered(state, q.sourceQuery)\n }\n }\n\n const involved = state.bitToQueries.get(changedBit)\n if (!involved) return\n const words = state.options.maskWordCount\n for (const qid of involved) {\n const q = state.queries[qid]\n if (!q) continue\n if (q.reactiveKind !== 'normal') continue\n const bundle = state.queryMasks.get(qid)\n if (!bundle) continue\n const wasMatch = matches(\n prevMask,\n bundle.withMask,\n bundle.anyMask,\n bundle.noneMask,\n bundle.anyHasBits,\n words,\n )\n const isMatch = matches(\n nextMask,\n bundle.withMask,\n bundle.anyMask,\n bundle.noneMask,\n bundle.anyHasBits,\n words,\n )\n if (!wasMatch && isMatch) {\n pushReactive(state, qid, 'enter', eid)\n } else if (wasMatch && !isMatch) {\n pushReactive(state, qid, 'exit', eid)\n }\n }\n}\n\nfunction pushReactive(\n state: WorldState,\n queryId: number,\n kind: 'enter' | 'exit',\n eid: EntityId,\n): void {\n // Walk the module cache (not just state.queries) so reactive variants that\n // haven't been registered with this world yet still receive events.\n for (const r of moduleQueryCache.values()) {\n if (r.sourceQueryId !== queryId) continue\n if (r.reactiveKind !== kind) continue\n // Lazily register the reactive query in this world so subsequent reads can find it\n ensureQueryRegistered(state, r)\n const buf = ensureReactiveBuffer(state, r.id)\n if (kind === 'enter') buf.entered.push(eid as number)\n else buf.exited.push(eid as number)\n }\n}\n\nfunction ensureReactiveBuffer(state: WorldState, qid: number): ReactiveBuffer {\n let buf = state.reactiveBuffers.get(qid)\n if (!buf) {\n buf = { entered: [], exited: [] }\n state.reactiveBuffers.set(qid, buf)\n }\n return buf\n}\n\n// --- Helpers ---\n\nfunction getComponentInfoById(componentId: number): ComponentInfo {\n // We need access to the component registry's lookup by id. Re-import dynamically to avoid cycles.\n const info = lazyGetComponentInfo(componentId)\n if (!info) throw new Error(`aiecsjs: component id ${componentId} not registered`)\n return info\n}\n\nlet _getComponentInfoFn: ((id: number) => ComponentInfo | undefined) | null = null\nexport function registerComponentLookup(fn: (id: number) => ComponentInfo | undefined): void {\n _getComponentInfoFn = fn\n}\nfunction lazyGetComponentInfo(id: number): ComponentInfo | undefined {\n return _getComponentInfoFn ? _getComponentInfoFn(id) : undefined\n}\n\nexport function _resetQueryRegistry_FOR_TESTS_ONLY(): void {\n moduleQueryCache.clear()\n nextQueryId = 1\n}\n"]}
1
+ {"version":3,"sources":["../src/internal/query.ts"],"names":["nextQueryId","moduleQueryCache","descKey","d","all","c","a","b","any","none","defineQuery","arg","desc","key","cached","q","enterQuery","query","reactive","exitQuery","ensureQueryRegistered","state","ww","withMask","createMask","anyMask","noneMask","compId","info","getComponentInfoById","bit","getOrRegisterComponentBit","setBit","bundle","isMaskZero","involvedBits","listBits","s","getQueryArchetypes","words","list","i","arch","matches","queryArchetypes","world","getWorldState","ids","out","id","runQuery","buf","e","archIds","r","iterQuery","src","forEachEntity","fn","cols","buildColumnViews","callWithCols","ents","n","eid","comp","getComponentInfo","storage","recordEntityMaskChange","changedBit","prevMask","nextMask","involved","qid","wasMatch","isMatch","pushReactive","queryId","kind","ensureReactiveBuffer","componentId","lazyGetComponentInfo","_getComponentInfoFn","registerComponentLookup"],"mappings":"8EAsBA,IAAIA,EAAc,CAAA,CACZC,CAAAA,CAAmB,IAAI,GAAA,CAE7B,SAASC,CAAAA,CAAQC,CAAAA,CAA4B,CAC3C,IAAMC,GAAOD,CA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,IAAI,KAAA,CAAM,yBAAyBoD,CAAW,CAAA,eAAA,CAAiB,EAChF,OAAOpD,CACT,CAEA,IAAIsD,EAA0E,IAAA,CACvE,SAASC,EAAwBzB,CAAAA,CAAqD,CAC3FwB,EAAsBxB,EACxB,CACA,SAASuB,CAAAA,CAAqBhC,EAAuC,CACnE,OAAOiC,EAAsBA,CAAAA,CAAoBjC,CAAE,EAAI,MACzD","file":"chunk-SQWZUC2Q.js","sourcesContent":["import { createMask, isMaskZero, listBits, matches, setBit } from './bitmask.js'\nimport { getComponentInfo } from './component.js'\nimport type {\n Archetype,\n ComponentInfo,\n ComponentLike,\n EntityId,\n Query,\n QueryDescriptor,\n QueryInternal,\n QueryMaskBundle,\n ReactiveBuffer,\n World,\n WorldState,\n} from './types.js'\nimport {\n getOrRegisterComponentBit,\n getWorldState,\n readEntityMask,\n tryGetComponentBit,\n} from './world.js'\n\nlet nextQueryId = 1\nconst moduleQueryCache = new Map<string, QueryInternal>()\n\nfunction descKey(d: QueryDescriptor): string {\n const all = (d.all ?? [])\n .map((c) => c.__id)\n .sort((a, b) => a - b)\n .join('-')\n const any = (d.any ?? [])\n .map((c) => c.__id)\n .sort((a, b) => a - b)\n .join('-')\n const none = (d.none ?? [])\n .map((c) => c.__id)\n .sort((a, b) => a - b)\n .join('-')\n return `A${all}|Y${any}|N${none}`\n}\n\nexport function defineQuery(arg: ComponentLike[] | QueryDescriptor): Query {\n const desc: QueryDescriptor = Array.isArray(arg) ? { all: arg } : arg\n\n // Validate all members are components\n for (const c of [...(desc.all ?? []), ...(desc.any ?? []), ...(desc.none ?? [])]) {\n if (!c || typeof c !== 'object' || typeof (c as any).__id !== 'number') {\n throw new TypeError('aiecsjs: defineQuery received a non-component value')\n }\n }\n\n const key = descKey(desc)\n const cached = moduleQueryCache.get(key)\n if (cached) return cached\n\n const q: QueryInternal = {\n id: nextQueryId++,\n mask: [],\n all: (desc.all ?? []).map((c) => c.__id),\n any: (desc.any ?? []).map((c) => c.__id),\n none: (desc.none ?? []).map((c) => c.__id),\n columnViewCache: [...(desc.all ?? []), ...(desc.any ?? [])],\n reactiveKind: 'normal',\n sourceQueryId: -1,\n sourceQuery: null,\n }\n moduleQueryCache.set(key, q)\n return q\n}\n\nexport function enterQuery(query: Query): Query {\n const q = query as QueryInternal\n const key = `enter:${q.id}`\n const cached = moduleQueryCache.get(key)\n if (cached) return cached\n const reactive: QueryInternal = {\n id: nextQueryId++,\n mask: [],\n all: q.all,\n any: q.any,\n none: q.none,\n columnViewCache: q.columnViewCache,\n reactiveKind: 'enter',\n sourceQueryId: q.id,\n sourceQuery: q,\n }\n moduleQueryCache.set(key, reactive)\n return reactive\n}\n\nexport function exitQuery(query: Query): Query {\n const q = query as QueryInternal\n const key = `exit:${q.id}`\n const cached = moduleQueryCache.get(key)\n if (cached) return cached\n const reactive: QueryInternal = {\n id: nextQueryId++,\n mask: [],\n all: q.all,\n any: q.any,\n none: q.none,\n columnViewCache: q.columnViewCache,\n reactiveKind: 'exit',\n sourceQueryId: q.id,\n sourceQuery: q,\n }\n moduleQueryCache.set(key, reactive)\n return reactive\n}\n\n// --- Per-world query setup ---\n\nfunction ensureQueryRegistered(state: WorldState, q: QueryInternal): void {\n if (state.queries[q.id] === q && state.queryMasks.has(q.id)) return\n\n // Build per-world bitmasks (this may register new bits)\n const ww = state.options.maskWordCount\n const withMask = createMask(ww)\n const anyMask = createMask(ww)\n const noneMask = createMask(ww)\n for (const compId of q.all) {\n const info = getComponentInfoById(compId)\n const bit = getOrRegisterComponentBit(state, info)\n setBit(withMask, bit)\n }\n for (const compId of q.any) {\n const info = getComponentInfoById(compId)\n const bit = getOrRegisterComponentBit(state, info)\n setBit(anyMask, bit)\n }\n for (const compId of q.none) {\n const info = getComponentInfoById(compId)\n const bit = getOrRegisterComponentBit(state, info)\n setBit(noneMask, bit)\n }\n\n const bundle: QueryMaskBundle = {\n withMask,\n anyMask,\n noneMask,\n anyHasBits: !isMaskZero(anyMask),\n }\n state.queryMasks.set(q.id, bundle)\n\n state.queries[q.id] = q\n state.queryArchetypeCache[q.id] = null\n state.queryArchetypeStamp[q.id] = -1\n\n // Build bit → queries index for fast reactive lookup\n const involvedBits: number[] = [\n ...listBits(withMask),\n ...listBits(anyMask),\n ...listBits(noneMask),\n ]\n for (const b of involvedBits) {\n let s = state.bitToQueries.get(b)\n if (!s) {\n s = new Set<number>()\n state.bitToQueries.set(b, s)\n }\n s.add(q.id)\n }\n\n // Initialize reactive buffer for enter/exit queries\n if (q.reactiveKind !== 'normal') {\n if (!state.reactiveBuffers.has(q.id)) {\n state.reactiveBuffers.set(q.id, { entered: [], exited: [] })\n }\n // Also register the source query so recordEntityMaskChange will see it\n if (q.sourceQuery) ensureQueryRegistered(state, q.sourceQuery)\n }\n}\n\nfunction getQueryArchetypes(state: WorldState, q: QueryInternal): number[] {\n ensureQueryRegistered(state, q)\n if (state.queryArchetypeCache[q.id] && state.queryArchetypeStamp[q.id] === state.queryVersion) {\n return state.queryArchetypeCache[q.id]!\n }\n const bundle = state.queryMasks.get(q.id)!\n const words = state.options.maskWordCount\n const list: number[] = []\n for (let i = 0; i < state.archetypes.length; i++) {\n const arch = state.archetypes[i]!\n if (\n matches(arch.mask, bundle.withMask, bundle.anyMask, bundle.noneMask, bundle.anyHasBits, words)\n ) {\n list.push(i)\n }\n }\n state.queryArchetypeCache[q.id] = list\n state.queryArchetypeStamp[q.id] = state.queryVersion\n return list\n}\n\nexport function queryArchetypes(world: World, query: Query): readonly Archetype[] {\n const state = getWorldState(world)\n const q = query as QueryInternal\n const ids = getQueryArchetypes(state, q)\n const out: Archetype[] = []\n for (const id of ids) {\n const arch = state.archetypes[id]!\n out.push({ id: arch.id, mask: Array.from(arch.mask), size: arch.size })\n }\n return out\n}\n\nexport function runQuery(world: World, query: Query): readonly EntityId[] {\n const state = getWorldState(world)\n const q = query as QueryInternal\n const out: EntityId[] = []\n if (q.reactiveKind === 'enter') {\n const buf = state.reactiveBuffers.get(q.id)\n if (buf) {\n for (const e of buf.entered) out.push(e as EntityId)\n buf.entered.length = 0\n }\n return out\n }\n if (q.reactiveKind === 'exit') {\n const buf = state.reactiveBuffers.get(q.id)\n if (buf) {\n for (const e of buf.exited) out.push(e as EntityId)\n buf.exited.length = 0\n }\n return out\n }\n const archIds = getQueryArchetypes(state, q)\n for (const id of archIds) {\n const arch = state.archetypes[id]!\n for (let r = 0; r < arch.size; r++) {\n out.push(arch.entities[r] as EntityId)\n }\n }\n return out\n}\n\nexport function* iterQuery(world: World, query: Query): IterableIterator<EntityId> {\n const state = getWorldState(world)\n const q = query as QueryInternal\n if (q.reactiveKind !== 'normal') {\n const buf = state.reactiveBuffers.get(q.id)\n if (!buf) return\n const src = q.reactiveKind === 'enter' ? buf.entered : buf.exited\n for (const e of src) yield e as EntityId\n src.length = 0\n return\n }\n const archIds = getQueryArchetypes(state, q)\n for (const id of archIds) {\n const arch = state.archetypes[id]!\n for (let r = 0; r < arch.size; r++) {\n yield arch.entities[r] as EntityId\n }\n }\n}\n\nexport function forEachEntity(\n world: World,\n query: Query,\n fn: (eid: EntityId, ...cols: any[]) => void,\n): void {\n const state = getWorldState(world)\n const q = query as QueryInternal\n\n if (q.reactiveKind !== 'normal') {\n const buf = state.reactiveBuffers.get(q.id)\n if (!buf) return\n const src = q.reactiveKind === 'enter' ? buf.entered : buf.exited\n if (src.length === 0) return\n const cols = buildColumnViews(state, q)\n for (let i = 0; i < src.length; i++) {\n const e = src[i] as EntityId\n callWithCols(fn, e, cols)\n }\n src.length = 0\n return\n }\n\n ensureQueryRegistered(state, q)\n const archIds = getQueryArchetypes(state, q)\n const cols = buildColumnViews(state, q)\n for (const id of archIds) {\n const arch = state.archetypes[id]!\n const ents = arch.entities\n const n = arch.size\n for (let r = 0; r < n; r++) {\n callWithCols(fn, ents[r] as EntityId, cols)\n }\n }\n}\n\nfunction callWithCols(\n fn: (eid: EntityId, ...cols: any[]) => void,\n eid: EntityId,\n cols: any[],\n): void {\n // Specialise for low arities to avoid spread allocation.\n switch (cols.length) {\n case 0:\n fn(eid)\n break\n case 1:\n fn(eid, cols[0])\n break\n case 2:\n fn(eid, cols[0], cols[1])\n break\n case 3:\n fn(eid, cols[0], cols[1], cols[2])\n break\n case 4:\n fn(eid, cols[0], cols[1], cols[2], cols[3])\n break\n case 5:\n fn(eid, cols[0], cols[1], cols[2], cols[3], cols[4])\n break\n default:\n fn(eid, ...cols)\n }\n}\n\nfunction buildColumnViews(state: WorldState, q: QueryInternal): any[] {\n const out: any[] = []\n for (const comp of q.columnViewCache) {\n const info = getComponentInfo(comp)\n const bit = state.componentBitFor.get(info.id)\n if (bit === undefined) {\n out.push(undefined)\n continue\n }\n const storage = state.componentStorageByBit[bit]\n if (!storage) {\n out.push(undefined)\n continue\n }\n if (storage.kind === 'soa') out.push(storage.soa)\n else if (storage.kind === 'aos') out.push(storage.aos)\n else out.push(true) // tag\n }\n return out\n}\n\n// --- Reactive query updates (called from migration code) ---\n\nexport function recordEntityMaskChange(\n state: WorldState,\n eid: EntityId,\n changedBit: number,\n prevMask: Uint32Array,\n nextMask: Uint32Array,\n): void {\n // Lazy-register any reactive queries (and their sources) so we can correctly\n // determine match transitions even if the user only ever called enterQuery/exitQuery.\n for (const q of moduleQueryCache.values()) {\n if (q.reactiveKind === 'normal') continue\n if (q.sourceQuery && state.queries[q.sourceQuery.id] !== q.sourceQuery) {\n ensureQueryRegistered(state, q.sourceQuery)\n }\n }\n\n const involved = state.bitToQueries.get(changedBit)\n if (!involved) return\n const words = state.options.maskWordCount\n for (const qid of involved) {\n const q = state.queries[qid]\n if (!q) continue\n if (q.reactiveKind !== 'normal') continue\n const bundle = state.queryMasks.get(qid)\n if (!bundle) continue\n const wasMatch = matches(\n prevMask,\n bundle.withMask,\n bundle.anyMask,\n bundle.noneMask,\n bundle.anyHasBits,\n words,\n )\n const isMatch = matches(\n nextMask,\n bundle.withMask,\n bundle.anyMask,\n bundle.noneMask,\n bundle.anyHasBits,\n words,\n )\n if (!wasMatch && isMatch) {\n pushReactive(state, qid, 'enter', eid)\n } else if (wasMatch && !isMatch) {\n pushReactive(state, qid, 'exit', eid)\n }\n }\n}\n\nfunction pushReactive(\n state: WorldState,\n queryId: number,\n kind: 'enter' | 'exit',\n eid: EntityId,\n): void {\n // Walk the module cache (not just state.queries) so reactive variants that\n // haven't been registered with this world yet still receive events.\n for (const r of moduleQueryCache.values()) {\n if (r.sourceQueryId !== queryId) continue\n if (r.reactiveKind !== kind) continue\n // Lazily register the reactive query in this world so subsequent reads can find it\n ensureQueryRegistered(state, r)\n const buf = ensureReactiveBuffer(state, r.id)\n if (kind === 'enter') buf.entered.push(eid as number)\n else buf.exited.push(eid as number)\n }\n}\n\nfunction ensureReactiveBuffer(state: WorldState, qid: number): ReactiveBuffer {\n let buf = state.reactiveBuffers.get(qid)\n if (!buf) {\n buf = { entered: [], exited: [] }\n state.reactiveBuffers.set(qid, buf)\n }\n return buf\n}\n\n// --- Helpers ---\n\nfunction getComponentInfoById(componentId: number): ComponentInfo {\n // We need access to the component registry's lookup by id. Re-import dynamically to avoid cycles.\n const info = lazyGetComponentInfo(componentId)\n if (!info) throw new Error(`aiecsjs: component id ${componentId} not registered`)\n return info\n}\n\nlet _getComponentInfoFn: ((id: number) => ComponentInfo | undefined) | null = null\nexport function registerComponentLookup(fn: (id: number) => ComponentInfo | undefined): void {\n _getComponentInfoFn = fn\n}\nfunction lazyGetComponentInfo(id: number): ComponentInfo | undefined {\n return _getComponentInfoFn ? _getComponentInfoFn(id) : undefined\n}\n\nexport function _resetQueryRegistry_FOR_TESTS_ONLY(): void {\n moduleQueryCache.clear()\n nextQueryId = 1\n}\n"]}
package/dist/commands.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var chunk4RPFOVQC_cjs=require('./chunk-4RPFOVQC.cjs');function l(n){let e={worldId:chunk4RPFOVQC_cjs.i(n).id,ops:[],nextPlaceholder:-1,flushing:false};return h(e)}function C(n){let o=y(n);if(!o.flushing){o.flushing=true;try{let e=B(o.worldId),r=new Map;for(let t of o.ops)t.kind==="create"&&r.set(t.placeholder,chunk4RPFOVQC_cjs.u(e));let d=t=>{let a=t;if(a<0){let f=r.get(a);if(f===void 0)throw new Error(`aiecsjs: unresolved placeholder ${a}`);return f}return t};for(let t of o.ops)t.kind==="add"?chunk4RPFOVQC_cjs.I(e,d(t.eid),t.component,t.initial):t.kind==="remove"&&chunk4RPFOVQC_cjs.J(e,d(t.eid),t.component);for(let t of o.ops)t.kind==="destroy"&&chunk4RPFOVQC_cjs.v(e,d(t.eid));o.ops.length=0,o.nextPlaceholder=-1;}finally{o.flushing=false;}}}function W(n,o){let e=l(n),r=o(e);return C(e),r}var p=new WeakMap;function h(n){let o={add(e,r,d){n.ops.push({kind:"add",eid:e,component:r,initial:d});},remove(e,r){n.ops.push({kind:"remove",eid:e,component:r});},destroy(e){n.ops.push({kind:"destroy",eid:e});},create(){let e=n.nextPlaceholder--;return n.ops.push({kind:"create",placeholder:e}),e}};return p.set(o,n),o}function y(n){let o=p.get(n);if(!o)throw new Error("aiecsjs: unknown CommandBuffer");return o}function B(n){let o=k(n);return {id:o.id,capacity:o.capacity,version:o.version}}function k(n){return chunk4RPFOVQC_cjs.i({id:n,capacity:0,version:"0.0.0"})}exports.createCommandBuffer=l;exports.flush=C;exports.withCommandBuffer=W;//# sourceMappingURL=commands.cjs.map
1
+ 'use strict';var chunkSJDWI3OZ_cjs=require('./chunk-SJDWI3OZ.cjs');function l(n){let e={worldId:chunkSJDWI3OZ_cjs.i(n).id,ops:[],nextPlaceholder:-1,flushing:false};return h(e)}function C(n){let o=y(n);if(!o.flushing){o.flushing=true;try{let e=B(o.worldId),r=new Map;for(let t of o.ops)t.kind==="create"&&r.set(t.placeholder,chunkSJDWI3OZ_cjs.u(e));let d=t=>{let a=t;if(a<0){let f=r.get(a);if(f===void 0)throw new Error(`aiecsjs: unresolved placeholder ${a}`);return f}return t};for(let t of o.ops)t.kind==="add"?chunkSJDWI3OZ_cjs.I(e,d(t.eid),t.component,t.initial):t.kind==="remove"&&chunkSJDWI3OZ_cjs.J(e,d(t.eid),t.component);for(let t of o.ops)t.kind==="destroy"&&chunkSJDWI3OZ_cjs.v(e,d(t.eid));o.ops.length=0,o.nextPlaceholder=-1;}finally{o.flushing=false;}}}function W(n,o){let e=l(n),r=o(e);return C(e),r}var p=new WeakMap;function h(n){let o={add(e,r,d){n.ops.push({kind:"add",eid:e,component:r,initial:d});},remove(e,r){n.ops.push({kind:"remove",eid:e,component:r});},destroy(e){n.ops.push({kind:"destroy",eid:e});},create(){let e=n.nextPlaceholder--;return n.ops.push({kind:"create",placeholder:e}),e}};return p.set(o,n),o}function y(n){let o=p.get(n);if(!o)throw new Error("aiecsjs: unknown CommandBuffer");return o}function B(n){let o=k(n);return {id:o.id,capacity:o.capacity,version:o.version}}function k(n){return chunkSJDWI3OZ_cjs.i({id:n,capacity:0,version:"0.0.0"})}exports.createCommandBuffer=l;exports.flush=C;exports.withCommandBuffer=W;//# sourceMappingURL=commands.cjs.map
2
2
  //# sourceMappingURL=commands.cjs.map
package/dist/commands.js CHANGED
@@ -1,2 +1,2 @@
1
- import {i,u,I,J,v}from'./chunk-L5CMKMIP.js';function l(n){let e={worldId:i(n).id,ops:[],nextPlaceholder:-1,flushing:false};return h(e)}function C(n){let o=y(n);if(!o.flushing){o.flushing=true;try{let e=B(o.worldId),r=new Map;for(let t of o.ops)t.kind==="create"&&r.set(t.placeholder,u(e));let d=t=>{let a=t;if(a<0){let f=r.get(a);if(f===void 0)throw new Error(`aiecsjs: unresolved placeholder ${a}`);return f}return t};for(let t of o.ops)t.kind==="add"?I(e,d(t.eid),t.component,t.initial):t.kind==="remove"&&J(e,d(t.eid),t.component);for(let t of o.ops)t.kind==="destroy"&&v(e,d(t.eid));o.ops.length=0,o.nextPlaceholder=-1;}finally{o.flushing=false;}}}function W(n,o){let e=l(n),r=o(e);return C(e),r}var p=new WeakMap;function h(n){let o={add(e,r,d){n.ops.push({kind:"add",eid:e,component:r,initial:d});},remove(e,r){n.ops.push({kind:"remove",eid:e,component:r});},destroy(e){n.ops.push({kind:"destroy",eid:e});},create(){let e=n.nextPlaceholder--;return n.ops.push({kind:"create",placeholder:e}),e}};return p.set(o,n),o}function y(n){let o=p.get(n);if(!o)throw new Error("aiecsjs: unknown CommandBuffer");return o}function B(n){let o=k(n);return {id:o.id,capacity:o.capacity,version:o.version}}function k(n){return i({id:n,capacity:0,version:"0.0.0"})}export{l as createCommandBuffer,C as flush,W as withCommandBuffer};//# sourceMappingURL=commands.js.map
1
+ import {i,u,I,J,v}from'./chunk-F7KNZ27O.js';function l(n){let e={worldId:i(n).id,ops:[],nextPlaceholder:-1,flushing:false};return h(e)}function C(n){let o=y(n);if(!o.flushing){o.flushing=true;try{let e=B(o.worldId),r=new Map;for(let t of o.ops)t.kind==="create"&&r.set(t.placeholder,u(e));let d=t=>{let a=t;if(a<0){let f=r.get(a);if(f===void 0)throw new Error(`aiecsjs: unresolved placeholder ${a}`);return f}return t};for(let t of o.ops)t.kind==="add"?I(e,d(t.eid),t.component,t.initial):t.kind==="remove"&&J(e,d(t.eid),t.component);for(let t of o.ops)t.kind==="destroy"&&v(e,d(t.eid));o.ops.length=0,o.nextPlaceholder=-1;}finally{o.flushing=false;}}}function W(n,o){let e=l(n),r=o(e);return C(e),r}var p=new WeakMap;function h(n){let o={add(e,r,d){n.ops.push({kind:"add",eid:e,component:r,initial:d});},remove(e,r){n.ops.push({kind:"remove",eid:e,component:r});},destroy(e){n.ops.push({kind:"destroy",eid:e});},create(){let e=n.nextPlaceholder--;return n.ops.push({kind:"create",placeholder:e}),e}};return p.set(o,n),o}function y(n){let o=p.get(n);if(!o)throw new Error("aiecsjs: unknown CommandBuffer");return o}function B(n){let o=k(n);return {id:o.id,capacity:o.capacity,version:o.version}}function k(n){return i({id:n,capacity:0,version:"0.0.0"})}export{l as createCommandBuffer,C as flush,W as withCommandBuffer};//# sourceMappingURL=commands.js.map
2
2
  //# sourceMappingURL=commands.js.map
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var chunk37HMYMJG_cjs=require('./chunk-37HMYMJG.cjs'),chunk4RPFOVQC_cjs=require('./chunk-4RPFOVQC.cjs');var K={i8:"i8",u8:"u8",i16:"i16",u16:"u16",i32:"i32",u32:"u32",f32:"f32",f64:"f64",eid:"eid",bool:"bool"};function $(...n){return n.length===0?e=>e:n.length===1?n[0]:(e,r)=>{let t=e;for(let o of n)t=o(t,r);return t}}var i=class extends Error{eid;constructor(e){super(`aiecsjs: entity ${e} is not alive`),this.name="EntityNotAliveError",this.eid=e;}};function J(n,e){let r=chunk4RPFOVQC_cjs.i(n);if(!chunk4RPFOVQC_cjs.x(r,e))throw new i(e);return Object.freeze({id:e,worldId:r.id})}function b(n,e){let r=chunk4RPFOVQC_cjs.i(n);if(e.worldId!==r.id)return null;let t=e.id,o=chunk4RPFOVQC_cjs.s(t,r.options);if(o<=0||o>=r.capacity)return null;let x=r.entityArchetype[o]??0,d=r.archetypes[x];if(!d||!d.entityRow.has(e.id))return null;let C=r.generations[o]??0,A=chunk4RPFOVQC_cjs.t(t,r.options);return C!==A?null:e.id}function X(n,e){return b(n,e)!==null}chunk37HMYMJG_cjs.i(n=>chunk4RPFOVQC_cjs.P(n));chunk4RPFOVQC_cjs.N((n,e,r,t,o)=>{chunk37HMYMJG_cjs.h(n,e,r,t,o);});var ae=typeof SharedArrayBuffer<"u";Object.defineProperty(exports,"defineQuery",{enumerable:true,get:function(){return chunk37HMYMJG_cjs.a}});Object.defineProperty(exports,"enterQuery",{enumerable:true,get:function(){return chunk37HMYMJG_cjs.b}});Object.defineProperty(exports,"exitQuery",{enumerable:true,get:function(){return chunk37HMYMJG_cjs.c}});Object.defineProperty(exports,"forEachEntity",{enumerable:true,get:function(){return chunk37HMYMJG_cjs.g}});Object.defineProperty(exports,"iterQuery",{enumerable:true,get:function(){return chunk37HMYMJG_cjs.f}});Object.defineProperty(exports,"queryArchetypes",{enumerable:true,get:function(){return chunk37HMYMJG_cjs.d}});Object.defineProperty(exports,"runQuery",{enumerable:true,get:function(){return chunk37HMYMJG_cjs.e}});Object.defineProperty(exports,"VERSION",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.a}});Object.defineProperty(exports,"addComponent",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.I}});Object.defineProperty(exports,"createEntity",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.u}});Object.defineProperty(exports,"createWorld",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.k}});Object.defineProperty(exports,"defineComponent",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.E}});Object.defineProperty(exports,"defineObjectComponent",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.G}});Object.defineProperty(exports,"defineTag",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.F}});Object.defineProperty(exports,"destroyEntity",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.v}});Object.defineProperty(exports,"destroyWorld",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.l}});Object.defineProperty(exports,"disposeWorld",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.l}});Object.defineProperty(exports,"entityExists",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.w}});Object.defineProperty(exports,"getComponent",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.L}});Object.defineProperty(exports,"getEntityGeneration",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.z}});Object.defineProperty(exports,"getEntityIndex",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.y}});Object.defineProperty(exports,"getWorldCapacity",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.o}});Object.defineProperty(exports,"getWorldSize",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.n}});Object.defineProperty(exports,"hasComponent",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.K}});Object.defineProperty(exports,"isEntity",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.B}});Object.defineProperty(exports,"isWorld",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.q}});Object.defineProperty(exports,"packEntity",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.A}});Object.defineProperty(exports,"removeComponent",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.J}});Object.defineProperty(exports,"resetWorld",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.m}});Object.defineProperty(exports,"setComponent",{enumerable:true,get:function(){return chunk4RPFOVQC_cjs.M}});exports.EntityNotAliveError=i;exports.IS_SAB_SUPPORTED=ae;exports.Types=K;exports.aliveRef=X;exports.deref=b;exports.pipe=$;exports.refOf=J;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var chunkRHH5JA74_cjs=require('./chunk-RHH5JA74.cjs'),chunkSJDWI3OZ_cjs=require('./chunk-SJDWI3OZ.cjs');var K={i8:"i8",u8:"u8",i16:"i16",u16:"u16",i32:"i32",u32:"u32",f32:"f32",f64:"f64",eid:"eid",bool:"bool"};function $(...n){return n.length===0?e=>e:n.length===1?n[0]:(e,r)=>{let t=e;for(let o of n)t=o(t,r);return t}}var i=class extends Error{eid;constructor(e){super(`aiecsjs: entity ${e} is not alive`),this.name="EntityNotAliveError",this.eid=e;}};function J(n,e){let r=chunkSJDWI3OZ_cjs.i(n);if(!chunkSJDWI3OZ_cjs.x(r,e))throw new i(e);return Object.freeze({id:e,worldId:r.id})}function b(n,e){let r=chunkSJDWI3OZ_cjs.i(n);if(e.worldId!==r.id)return null;let t=e.id,o=chunkSJDWI3OZ_cjs.s(t,r.options);if(o<=0||o>=r.capacity)return null;let x=r.entityArchetype[o]??0,d=r.archetypes[x];if(!d||!d.entityRow.has(e.id))return null;let C=r.generations[o]??0,A=chunkSJDWI3OZ_cjs.t(t,r.options);return C!==A?null:e.id}function X(n,e){return b(n,e)!==null}chunkRHH5JA74_cjs.i(n=>chunkSJDWI3OZ_cjs.P(n));chunkSJDWI3OZ_cjs.N((n,e,r,t,o)=>{chunkRHH5JA74_cjs.h(n,e,r,t,o);});var ae=typeof SharedArrayBuffer<"u";Object.defineProperty(exports,"defineQuery",{enumerable:true,get:function(){return chunkRHH5JA74_cjs.a}});Object.defineProperty(exports,"enterQuery",{enumerable:true,get:function(){return chunkRHH5JA74_cjs.b}});Object.defineProperty(exports,"exitQuery",{enumerable:true,get:function(){return chunkRHH5JA74_cjs.c}});Object.defineProperty(exports,"forEachEntity",{enumerable:true,get:function(){return chunkRHH5JA74_cjs.g}});Object.defineProperty(exports,"iterQuery",{enumerable:true,get:function(){return chunkRHH5JA74_cjs.f}});Object.defineProperty(exports,"queryArchetypes",{enumerable:true,get:function(){return chunkRHH5JA74_cjs.d}});Object.defineProperty(exports,"runQuery",{enumerable:true,get:function(){return chunkRHH5JA74_cjs.e}});Object.defineProperty(exports,"VERSION",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.a}});Object.defineProperty(exports,"addComponent",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.I}});Object.defineProperty(exports,"createEntity",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.u}});Object.defineProperty(exports,"createWorld",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.k}});Object.defineProperty(exports,"defineComponent",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.E}});Object.defineProperty(exports,"defineObjectComponent",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.G}});Object.defineProperty(exports,"defineTag",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.F}});Object.defineProperty(exports,"destroyEntity",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.v}});Object.defineProperty(exports,"destroyWorld",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.l}});Object.defineProperty(exports,"disposeWorld",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.l}});Object.defineProperty(exports,"entityExists",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.w}});Object.defineProperty(exports,"getComponent",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.L}});Object.defineProperty(exports,"getEntityGeneration",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.z}});Object.defineProperty(exports,"getEntityIndex",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.y}});Object.defineProperty(exports,"getWorldCapacity",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.o}});Object.defineProperty(exports,"getWorldSize",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.n}});Object.defineProperty(exports,"hasComponent",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.K}});Object.defineProperty(exports,"isEntity",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.B}});Object.defineProperty(exports,"isWorld",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.q}});Object.defineProperty(exports,"packEntity",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.A}});Object.defineProperty(exports,"removeComponent",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.J}});Object.defineProperty(exports,"resetWorld",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.m}});Object.defineProperty(exports,"setComponent",{enumerable:true,get:function(){return chunkSJDWI3OZ_cjs.M}});exports.EntityNotAliveError=i;exports.IS_SAB_SUPPORTED=ae;exports.Types=K;exports.aliveRef=X;exports.deref=b;exports.pipe=$;exports.refOf=J;//# sourceMappingURL=index.cjs.map
2
2
  //# sourceMappingURL=index.cjs.map
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { o as WorldOptions, W as World, E as EntityId, c as ComponentLike, b as ComponentInit, k as SoASchema, h as SoAComponent, A as AoSComponent, T as TagComponent, f as QueryDescriptor, Q as Query, a as Archetype, l as System } from './types-BGEeHad-.cjs';
2
2
  export { d as ComponentView, g as SoAColumns, i as SoAFieldDecl, j as SoAFieldType, n as Types } from './types-BGEeHad-.cjs';
3
3
 
4
- declare const VERSION = "0.3.1";
4
+ declare const VERSION = "0.4.0";
5
5
 
6
6
  declare function createWorld(options?: WorldOptions): World;
7
7
  declare function destroyWorld(world: World): void;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { o as WorldOptions, W as World, E as EntityId, c as ComponentLike, b as ComponentInit, k as SoASchema, h as SoAComponent, A as AoSComponent, T as TagComponent, f as QueryDescriptor, Q as Query, a as Archetype, l as System } from './types-BGEeHad-.js';
2
2
  export { d as ComponentView, g as SoAColumns, i as SoAFieldDecl, j as SoAFieldType, n as Types } from './types-BGEeHad-.js';
3
3
 
4
- declare const VERSION = "0.3.1";
4
+ declare const VERSION = "0.4.0";
5
5
 
6
6
  declare function createWorld(options?: WorldOptions): World;
7
7
  declare function destroyWorld(world: World): void;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import {i as i$1,h}from'./chunk-FDXCXNZK.js';export{a as defineQuery,b as enterQuery,c as exitQuery,g as forEachEntity,f as iterQuery,d as queryArchetypes,e as runQuery}from'./chunk-FDXCXNZK.js';import {P,N,i as i$2,x,s,t}from'./chunk-L5CMKMIP.js';export{a as VERSION,I as addComponent,u as createEntity,k as createWorld,E as defineComponent,G as defineObjectComponent,F as defineTag,v as destroyEntity,l as destroyWorld,l as disposeWorld,w as entityExists,L as getComponent,z as getEntityGeneration,y as getEntityIndex,o as getWorldCapacity,n as getWorldSize,K as hasComponent,B as isEntity,q as isWorld,A as packEntity,J as removeComponent,m as resetWorld,M as setComponent}from'./chunk-L5CMKMIP.js';var K={i8:"i8",u8:"u8",i16:"i16",u16:"u16",i32:"i32",u32:"u32",f32:"f32",f64:"f64",eid:"eid",bool:"bool"};function $(...n){return n.length===0?e=>e:n.length===1?n[0]:(e,r)=>{let t=e;for(let o of n)t=o(t,r);return t}}var i=class extends Error{eid;constructor(e){super(`aiecsjs: entity ${e} is not alive`),this.name="EntityNotAliveError",this.eid=e;}};function J(n,e){let r=i$2(n);if(!x(r,e))throw new i(e);return Object.freeze({id:e,worldId:r.id})}function b(n,e){let r=i$2(n);if(e.worldId!==r.id)return null;let t$1=e.id,o=s(t$1,r.options);if(o<=0||o>=r.capacity)return null;let x=r.entityArchetype[o]??0,d=r.archetypes[x];if(!d||!d.entityRow.has(e.id))return null;let C=r.generations[o]??0,A=t(t$1,r.options);return C!==A?null:e.id}function X(n,e){return b(n,e)!==null}i$1(n=>P(n));N((n,e,r,t,o)=>{h(n,e,r,t,o);});var ae=typeof SharedArrayBuffer<"u";export{i as EntityNotAliveError,ae as IS_SAB_SUPPORTED,K as Types,X as aliveRef,b as deref,$ as pipe,J as refOf};//# sourceMappingURL=index.js.map
1
+ import {i as i$1,h}from'./chunk-SQWZUC2Q.js';export{a as defineQuery,b as enterQuery,c as exitQuery,g as forEachEntity,f as iterQuery,d as queryArchetypes,e as runQuery}from'./chunk-SQWZUC2Q.js';import {P,N,i as i$2,x,s,t}from'./chunk-F7KNZ27O.js';export{a as VERSION,I as addComponent,u as createEntity,k as createWorld,E as defineComponent,G as defineObjectComponent,F as defineTag,v as destroyEntity,l as destroyWorld,l as disposeWorld,w as entityExists,L as getComponent,z as getEntityGeneration,y as getEntityIndex,o as getWorldCapacity,n as getWorldSize,K as hasComponent,B as isEntity,q as isWorld,A as packEntity,J as removeComponent,m as resetWorld,M as setComponent}from'./chunk-F7KNZ27O.js';var K={i8:"i8",u8:"u8",i16:"i16",u16:"u16",i32:"i32",u32:"u32",f32:"f32",f64:"f64",eid:"eid",bool:"bool"};function $(...n){return n.length===0?e=>e:n.length===1?n[0]:(e,r)=>{let t=e;for(let o of n)t=o(t,r);return t}}var i=class extends Error{eid;constructor(e){super(`aiecsjs: entity ${e} is not alive`),this.name="EntityNotAliveError",this.eid=e;}};function J(n,e){let r=i$2(n);if(!x(r,e))throw new i(e);return Object.freeze({id:e,worldId:r.id})}function b(n,e){let r=i$2(n);if(e.worldId!==r.id)return null;let t$1=e.id,o=s(t$1,r.options);if(o<=0||o>=r.capacity)return null;let x=r.entityArchetype[o]??0,d=r.archetypes[x];if(!d||!d.entityRow.has(e.id))return null;let C=r.generations[o]??0,A=t(t$1,r.options);return C!==A?null:e.id}function X(n,e){return b(n,e)!==null}i$1(n=>P(n));N((n,e,r,t,o)=>{h(n,e,r,t,o);});var ae=typeof SharedArrayBuffer<"u";export{i as EntityNotAliveError,ae as IS_SAB_SUPPORTED,K as Types,X as aliveRef,b as deref,$ as pipe,J as refOf};//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- 'use strict';var chunk37HMYMJG_cjs=require('./chunk-37HMYMJG.cjs'),chunk4RPFOVQC_cjs=require('./chunk-4RPFOVQC.cjs');function f(n,e){if(!e)return n;if(e.aborted)return n(),()=>{};let o=()=>{n();};e.addEventListener("abort",o,{once:true});let t=false;return ()=>{t||(t=true,e.removeEventListener("abort",o),n());}}function w(n,e,o,t){return f(b(n,e,"add",o),t?.signal)}function x(n,e,o,t){return f(b(n,e,"remove",o),t?.signal)}function C(n,e,o,t){return f(b(n,e,"set",o),t?.signal)}function L(n,e,o,t,r){let s=chunk4RPFOVQC_cjs.i(n);chunk37HMYMJG_cjs.e(n,e);let i={event:o,componentBit:-1,queryId:e.id,handler:t};return s.observers.push(i),f(()=>{let d=s.observers.indexOf(i);d>=0&&s.observers.splice(d,1);},r?.signal)}function b(n,e,o,t){let r=chunk4RPFOVQC_cjs.i(n),s=chunk4RPFOVQC_cjs.H(e),i=r.componentBitFor.get(s.id);i===void 0&&(i=chunk4RPFOVQC_cjs.p(r,s));let u={event:o,componentBit:i,queryId:-1,handler:t};return r.observers.push(u),()=>{let d=r.observers.indexOf(u);d>=0&&r.observers.splice(d,1);}}function E(n,e,o){let t=Array.from(n.observers);for(let r of t)r.event==="add"&&r.componentBit===o&&n.observers.includes(r)&&r.handler(e);O(n,e,"add");}function M(n,e,o){let t=Array.from(n.observers);for(let r of t)r.event==="remove"&&r.componentBit===o&&n.observers.includes(r)&&r.handler(e);O(n,e,"remove");}function g(n,e,o,t){let r=Array.from(n.observers);for(let s of r)s.event==="set"&&n.observers.includes(s)&&(s.componentBit===o||s.queryId!==-1&&n.queries[s.queryId]?.all.includes(n.componentInfoByBit[o]?.id??-1))&&s.handler(e,t);}function O(n,e,o,t,r){let s=n.options.maskWordCount,i=(e&n.options.indexMask)*s,u=Array.from(n.observers);for(let d of u){if(d.event!==o||d.queryId===-1||!n.observers.includes(d))continue;let c=n.queryMasks.get(d.queryId);if(!c)continue;let l=chunk4RPFOVQC_cjs.h(n.entityMask,i,s,c.withMask,c.anyMask,c.noneMask,c.anyHasBits);o==="add"&&l&&d.handler(e),o==="remove"&&!l&&d.handler(e);}}chunk4RPFOVQC_cjs.O({fireAdd:E,fireRemove:M,fireSet:g});chunk4RPFOVQC_cjs.C({dispatchDestroyObservers(n,e){let o=n.options.maskWordCount,t=(e&n.options.indexMask)*o,r=new Uint32Array(o);for(let i=0;i<o;i++)r[i]=n.entityMask[t+i]??0;chunk4RPFOVQC_cjs.g(r,0,o,i=>{let u=Array.from(n.observers);for(let d of u)d.event==="remove"&&d.componentBit===i&&n.observers.includes(d)&&d.handler(e);});let s=Array.from(n.observers);for(let i of s){if(i.event!=="remove"||i.queryId===-1||!n.observers.includes(i))continue;let u=n.queryMasks.get(i.queryId);if(!u)continue;chunk4RPFOVQC_cjs.h(r,0,o,u.withMask,u.anyMask,u.noneMask,u.anyHasBits)&&i.handler(e);}}});exports.observe=L;exports.onAdd=w;exports.onRemove=x;exports.onSet=C;//# sourceMappingURL=observers.cjs.map
1
+ 'use strict';var chunkRHH5JA74_cjs=require('./chunk-RHH5JA74.cjs'),chunkSJDWI3OZ_cjs=require('./chunk-SJDWI3OZ.cjs');function f(n,e){if(!e)return n;if(e.aborted)return n(),()=>{};let o=()=>{n();};e.addEventListener("abort",o,{once:true});let t=false;return ()=>{t||(t=true,e.removeEventListener("abort",o),n());}}function w(n,e,o,t){return f(b(n,e,"add",o),t?.signal)}function x(n,e,o,t){return f(b(n,e,"remove",o),t?.signal)}function C(n,e,o,t){return f(b(n,e,"set",o),t?.signal)}function L(n,e,o,t,r){let s=chunkSJDWI3OZ_cjs.i(n);chunkRHH5JA74_cjs.e(n,e);let i={event:o,componentBit:-1,queryId:e.id,handler:t};return s.observers.push(i),f(()=>{let d=s.observers.indexOf(i);d>=0&&s.observers.splice(d,1);},r?.signal)}function b(n,e,o,t){let r=chunkSJDWI3OZ_cjs.i(n),s=chunkSJDWI3OZ_cjs.H(e),i=r.componentBitFor.get(s.id);i===void 0&&(i=chunkSJDWI3OZ_cjs.p(r,s));let u={event:o,componentBit:i,queryId:-1,handler:t};return r.observers.push(u),()=>{let d=r.observers.indexOf(u);d>=0&&r.observers.splice(d,1);}}function E(n,e,o){let t=Array.from(n.observers);for(let r of t)r.event==="add"&&r.componentBit===o&&n.observers.includes(r)&&r.handler(e);O(n,e,"add");}function M(n,e,o){let t=Array.from(n.observers);for(let r of t)r.event==="remove"&&r.componentBit===o&&n.observers.includes(r)&&r.handler(e);O(n,e,"remove");}function g(n,e,o,t){let r=Array.from(n.observers);for(let s of r)s.event==="set"&&n.observers.includes(s)&&(s.componentBit===o||s.queryId!==-1&&n.queries[s.queryId]?.all.includes(n.componentInfoByBit[o]?.id??-1))&&s.handler(e,t);}function O(n,e,o,t,r){let s=n.options.maskWordCount,i=(e&n.options.indexMask)*s,u=Array.from(n.observers);for(let d of u){if(d.event!==o||d.queryId===-1||!n.observers.includes(d))continue;let c=n.queryMasks.get(d.queryId);if(!c)continue;let l=chunkSJDWI3OZ_cjs.h(n.entityMask,i,s,c.withMask,c.anyMask,c.noneMask,c.anyHasBits);o==="add"&&l&&d.handler(e),o==="remove"&&!l&&d.handler(e);}}chunkSJDWI3OZ_cjs.O({fireAdd:E,fireRemove:M,fireSet:g});chunkSJDWI3OZ_cjs.C({dispatchDestroyObservers(n,e){let o=n.options.maskWordCount,t=(e&n.options.indexMask)*o,r=new Uint32Array(o);for(let i=0;i<o;i++)r[i]=n.entityMask[t+i]??0;chunkSJDWI3OZ_cjs.g(r,0,o,i=>{let u=Array.from(n.observers);for(let d of u)d.event==="remove"&&d.componentBit===i&&n.observers.includes(d)&&d.handler(e);});let s=Array.from(n.observers);for(let i of s){if(i.event!=="remove"||i.queryId===-1||!n.observers.includes(i))continue;let u=n.queryMasks.get(i.queryId);if(!u)continue;chunkSJDWI3OZ_cjs.h(r,0,o,u.withMask,u.anyMask,u.noneMask,u.anyHasBits)&&i.handler(e);}}});exports.observe=L;exports.onAdd=w;exports.onRemove=x;exports.onSet=C;//# sourceMappingURL=observers.cjs.map
2
2
  //# sourceMappingURL=observers.cjs.map
package/dist/observers.js CHANGED
@@ -1,2 +1,2 @@
1
- import {e}from'./chunk-FDXCXNZK.js';import {O as O$1,C as C$1,g as g$1,h,i,H,p}from'./chunk-L5CMKMIP.js';function f(n,e){if(!e)return n;if(e.aborted)return n(),()=>{};let o=()=>{n();};e.addEventListener("abort",o,{once:true});let t=false;return ()=>{t||(t=true,e.removeEventListener("abort",o),n());}}function w(n,e,o,t){return f(b(n,e,"add",o),t?.signal)}function x(n,e,o,t){return f(b(n,e,"remove",o),t?.signal)}function C(n,e,o,t){return f(b(n,e,"set",o),t?.signal)}function L(n,e$1,o,t,r){let s=i(n);e(n,e$1);let i$1={event:o,componentBit:-1,queryId:e$1.id,handler:t};return s.observers.push(i$1),f(()=>{let d=s.observers.indexOf(i$1);d>=0&&s.observers.splice(d,1);},r?.signal)}function b(n,e,o,t){let r=i(n),s=H(e),i$1=r.componentBitFor.get(s.id);i$1===void 0&&(i$1=p(r,s));let u={event:o,componentBit:i$1,queryId:-1,handler:t};return r.observers.push(u),()=>{let d=r.observers.indexOf(u);d>=0&&r.observers.splice(d,1);}}function E(n,e,o){let t=Array.from(n.observers);for(let r of t)r.event==="add"&&r.componentBit===o&&n.observers.includes(r)&&r.handler(e);O(n,e,"add");}function M(n,e,o){let t=Array.from(n.observers);for(let r of t)r.event==="remove"&&r.componentBit===o&&n.observers.includes(r)&&r.handler(e);O(n,e,"remove");}function g(n,e,o,t){let r=Array.from(n.observers);for(let s of r)s.event==="set"&&n.observers.includes(s)&&(s.componentBit===o||s.queryId!==-1&&n.queries[s.queryId]?.all.includes(n.componentInfoByBit[o]?.id??-1))&&s.handler(e,t);}function O(n,e,o,t,r){let s=n.options.maskWordCount,i=(e&n.options.indexMask)*s,u=Array.from(n.observers);for(let d of u){if(d.event!==o||d.queryId===-1||!n.observers.includes(d))continue;let c=n.queryMasks.get(d.queryId);if(!c)continue;let l=h(n.entityMask,i,s,c.withMask,c.anyMask,c.noneMask,c.anyHasBits);o==="add"&&l&&d.handler(e),o==="remove"&&!l&&d.handler(e);}}O$1({fireAdd:E,fireRemove:M,fireSet:g});C$1({dispatchDestroyObservers(n,e){let o=n.options.maskWordCount,t=(e&n.options.indexMask)*o,r=new Uint32Array(o);for(let i=0;i<o;i++)r[i]=n.entityMask[t+i]??0;g$1(r,0,o,i=>{let u=Array.from(n.observers);for(let d of u)d.event==="remove"&&d.componentBit===i&&n.observers.includes(d)&&d.handler(e);});let s=Array.from(n.observers);for(let i of s){if(i.event!=="remove"||i.queryId===-1||!n.observers.includes(i))continue;let u=n.queryMasks.get(i.queryId);if(!u)continue;h(r,0,o,u.withMask,u.anyMask,u.noneMask,u.anyHasBits)&&i.handler(e);}}});export{L as observe,w as onAdd,x as onRemove,C as onSet};//# sourceMappingURL=observers.js.map
1
+ import {e}from'./chunk-SQWZUC2Q.js';import {O as O$1,C as C$1,g as g$1,h,i,H,p}from'./chunk-F7KNZ27O.js';function f(n,e){if(!e)return n;if(e.aborted)return n(),()=>{};let o=()=>{n();};e.addEventListener("abort",o,{once:true});let t=false;return ()=>{t||(t=true,e.removeEventListener("abort",o),n());}}function w(n,e,o,t){return f(b(n,e,"add",o),t?.signal)}function x(n,e,o,t){return f(b(n,e,"remove",o),t?.signal)}function C(n,e,o,t){return f(b(n,e,"set",o),t?.signal)}function L(n,e$1,o,t,r){let s=i(n);e(n,e$1);let i$1={event:o,componentBit:-1,queryId:e$1.id,handler:t};return s.observers.push(i$1),f(()=>{let d=s.observers.indexOf(i$1);d>=0&&s.observers.splice(d,1);},r?.signal)}function b(n,e,o,t){let r=i(n),s=H(e),i$1=r.componentBitFor.get(s.id);i$1===void 0&&(i$1=p(r,s));let u={event:o,componentBit:i$1,queryId:-1,handler:t};return r.observers.push(u),()=>{let d=r.observers.indexOf(u);d>=0&&r.observers.splice(d,1);}}function E(n,e,o){let t=Array.from(n.observers);for(let r of t)r.event==="add"&&r.componentBit===o&&n.observers.includes(r)&&r.handler(e);O(n,e,"add");}function M(n,e,o){let t=Array.from(n.observers);for(let r of t)r.event==="remove"&&r.componentBit===o&&n.observers.includes(r)&&r.handler(e);O(n,e,"remove");}function g(n,e,o,t){let r=Array.from(n.observers);for(let s of r)s.event==="set"&&n.observers.includes(s)&&(s.componentBit===o||s.queryId!==-1&&n.queries[s.queryId]?.all.includes(n.componentInfoByBit[o]?.id??-1))&&s.handler(e,t);}function O(n,e,o,t,r){let s=n.options.maskWordCount,i=(e&n.options.indexMask)*s,u=Array.from(n.observers);for(let d of u){if(d.event!==o||d.queryId===-1||!n.observers.includes(d))continue;let c=n.queryMasks.get(d.queryId);if(!c)continue;let l=h(n.entityMask,i,s,c.withMask,c.anyMask,c.noneMask,c.anyHasBits);o==="add"&&l&&d.handler(e),o==="remove"&&!l&&d.handler(e);}}O$1({fireAdd:E,fireRemove:M,fireSet:g});C$1({dispatchDestroyObservers(n,e){let o=n.options.maskWordCount,t=(e&n.options.indexMask)*o,r=new Uint32Array(o);for(let i=0;i<o;i++)r[i]=n.entityMask[t+i]??0;g$1(r,0,o,i=>{let u=Array.from(n.observers);for(let d of u)d.event==="remove"&&d.componentBit===i&&n.observers.includes(d)&&d.handler(e);});let s=Array.from(n.observers);for(let i of s){if(i.event!=="remove"||i.queryId===-1||!n.observers.includes(i))continue;let u=n.queryMasks.get(i.queryId);if(!u)continue;h(r,0,o,u.withMask,u.anyMask,u.noneMask,u.anyHasBits)&&i.handler(e);}}});export{L as observe,w as onAdd,x as onRemove,C as onSet};//# sourceMappingURL=observers.js.map
2
2
  //# sourceMappingURL=observers.js.map
@@ -1,2 +1,2 @@
1
- 'use strict';var chunk4RPFOVQC_cjs=require('./chunk-4RPFOVQC.cjs');var x=1;function v(r){return {__kind:"relation",__id:x++,__exclusive:r?.exclusive??false,__hasData:false}}var _=v({exclusive:true});function p(r,l){let o=r.relationStorage.get(l.__id);return o||(o={rel:l,exclusive:l.__exclusive?new Int32Array(r.capacity).fill(-1):null,outgoing:new Map,data:new Map},r.relationStorage.set(l.__id,o),o)}function R(r,l,o,n,i){let e=chunk4RPFOVQC_cjs.i(r);if(e.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");let t=p(e,o),s=l&e.options.indexMask,c=n&e.options.indexMask;if(t.exclusive){if(s>=t.exclusive.length){let a=new Int32Array(Math.max(s+1,t.exclusive.length*2)).fill(-1);a.set(t.exclusive),t.exclusive=a;}t.exclusive[s]=c;}else {let a=t.outgoing.get(s);a||(a=[],t.outgoing.set(s,a)),a.includes(c)||a.push(c);}if(i!==void 0){let a=t.data.get(s);a||(a=new Map,t.data.set(s,a)),a.set(c,i);}}function h(r,l,o,n){let i=chunk4RPFOVQC_cjs.i(r);if(i.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");let e=i.relationStorage.get(o.__id);if(!e)return;let t=l&i.options.indexMask,s=n&i.options.indexMask;if(e.exclusive)t<e.exclusive.length&&e.exclusive[t]===s&&(e.exclusive[t]=-1);else {let a=e.outgoing.get(t);if(a){let g=a.indexOf(s);g>=0&&a.splice(g,1),a.length===0&&e.outgoing.delete(t);}}let c=e.data.get(t);c&&(c.delete(s),c.size===0&&e.data.delete(t));}function w(r,l,o){let n=chunk4RPFOVQC_cjs.i(r),i=n.relationStorage.get(o.__id);if(!i)return [];let e=l&n.options.indexMask;if(i.exclusive){if(e<i.exclusive.length){let s=i.exclusive[e]??-1;if(s>=0){let c=n.generations[s]??0;return [chunk4RPFOVQC_cjs.r(s,c,n.options)]}}return []}let t=i.outgoing.get(e);return t?t.map(s=>{let c=n.generations[s]??0;return chunk4RPFOVQC_cjs.r(s,c,n.options)}):[]}chunk4RPFOVQC_cjs.D((r,l)=>{let o=l&r.options.indexMask;for(let n of r.relationStorage.values()){if(n.exclusive){o<n.exclusive.length&&(n.exclusive[o]=-1);for(let i=0;i<n.exclusive.length;i++)n.exclusive[i]===o&&(n.exclusive[i]=-1);}n.outgoing.delete(o);for(let[i,e]of n.outgoing){let t=e.indexOf(o);t>=0&&(e.splice(t,1),e.length===0&&n.outgoing.delete(i));}n.data.delete(o);for(let[i,e]of n.data)e.delete(o),e.size===0&&n.data.delete(i);}});exports.ChildOf=_;exports.addRelation=R;exports.defineRelation=v;exports.getRelationTargets=w;exports.removeRelation=h;//# sourceMappingURL=relations.cjs.map
1
+ 'use strict';var chunkSJDWI3OZ_cjs=require('./chunk-SJDWI3OZ.cjs');var x=1;function p(r){return {__kind:"relation",__id:x++,__exclusive:r?.exclusive??false,__hasData:false}}var _=p({exclusive:true});function v(r,l){let s=r.relationStorage.get(l.__id);return s||(s={rel:l,exclusive:l.__exclusive?new Int32Array(r.capacity).fill(-1):null,outgoing:new Map,data:new Map},r.relationStorage.set(l.__id,s),s)}function R(r,l,s,i,n){let t=chunkSJDWI3OZ_cjs.i(r);if(t.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");let e=v(t,s),o=l&t.options.indexMask,d=i&t.options.indexMask;if(e.exclusive){if(o>=e.exclusive.length){let c=new Int32Array(Math.max(o+1,e.exclusive.length*2)).fill(-1);c.set(e.exclusive),e.exclusive=c;}let a=e.exclusive[o]??-1;if(a>=0&&a!==d){let c=e.data.get(o);c?.delete(a),c&&c.size===0&&e.data.delete(o);}e.exclusive[o]=d;}else {let a=e.outgoing.get(o);a||(a=[],e.outgoing.set(o,a)),a.includes(d)||a.push(d);}if(n!==void 0){let a=e.data.get(o);a||(a=new Map,e.data.set(o,a)),a.set(d,n);}}function b(r,l,s,i){let n=chunkSJDWI3OZ_cjs.i(r);if(n.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");let t=n.relationStorage.get(s.__id);if(!t)return;let e=l&n.options.indexMask,o=i&n.options.indexMask;if(t.exclusive)e<t.exclusive.length&&t.exclusive[e]===o&&(t.exclusive[e]=-1);else {let a=t.outgoing.get(e);if(a){let c=a.indexOf(o);c>=0&&a.splice(c,1),a.length===0&&t.outgoing.delete(e);}}let d=t.data.get(e);d&&(d.delete(o),d.size===0&&t.data.delete(e));}function h(r,l,s){let i=chunkSJDWI3OZ_cjs.i(r),n=i.relationStorage.get(s.__id);if(!n)return [];let t=l&i.options.indexMask;if(n.exclusive){if(t<n.exclusive.length){let o=n.exclusive[t]??-1;if(o>=0){let d=i.generations[o]??0;return [chunkSJDWI3OZ_cjs.r(o,d,i.options)]}}return []}let e=n.outgoing.get(t);return e?e.map(o=>{let d=i.generations[o]??0;return chunkSJDWI3OZ_cjs.r(o,d,i.options)}):[]}function w(r,l,s,i){let n=chunkSJDWI3OZ_cjs.i(r),t=n.relationStorage.get(s.__id);if(!t)return;let e=l&n.options.indexMask,o=i&n.options.indexMask;return t.data.get(e)?.get(o)}chunkSJDWI3OZ_cjs.D((r,l)=>{let s=l&r.options.indexMask;for(let i of r.relationStorage.values()){if(i.exclusive){s<i.exclusive.length&&(i.exclusive[s]=-1);for(let n=0;n<i.exclusive.length;n++)i.exclusive[n]===s&&(i.exclusive[n]=-1);}i.outgoing.delete(s);for(let[n,t]of i.outgoing){let e=t.indexOf(s);e>=0&&(t.splice(e,1),t.length===0&&i.outgoing.delete(n));}i.data.delete(s);for(let[n,t]of i.data)t.delete(s),t.size===0&&i.data.delete(n);}});exports.ChildOf=_;exports.addRelation=R;exports.defineRelation=p;exports.getRelationData=w;exports.getRelationTargets=h;exports.removeRelation=b;//# sourceMappingURL=relations.cjs.map
2
2
  //# sourceMappingURL=relations.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/relations.ts"],"names":["nextRelationId","defineRelation","options","ChildOf","getOrCreateStorage","state","rel","storage","addRelation","world","source","target","data","getWorldState","src","tgt","next","list","inner","removeRelation","idx","getRelationTargets","gen","packEid","tIdx","registerRelationsCleanup","eid","e"],"mappings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AAU,MAAA,GAAQA,CAAAA,CAAQ,SAAA,CAAUoB,CAAC,CAAA,CAAI,EAAA,CAAA,CAEzD,IAAA,IAAS,CAAA,CAAI,CAAA,CAAG,CAAA,CAAIpB,CAAAA,CAAQ,SAAA,CAAU,MAAA,CAAQ,CAAA,EAAA,CACxCA,CAAAA,CAAQ,SAAA,CAAU,CAAC,CAAA,GAAMoB,CAAAA,GAAGpB,CAAAA,CAAQ,SAAA,CAAU,CAAC,CAAA,CAAI,EAAA,EAE3D,CACAA,CAAAA,CAAQ,QAAA,CAAS,MAAA,CAAOoB,CAAC,CAAA,CACzB,IAAA,GAAW,CAACb,CAAAA,CAAKG,CAAI,CAAA,GAAKV,CAAAA,CAAQ,QAAA,CAAU,CAC1C,IAAMa,CAAAA,CAAMH,CAAAA,CAAK,OAAA,CAAQU,CAAC,CAAA,CACtBP,CAAAA,EAAO,CAAA,GACTH,CAAAA,CAAK,MAAA,CAAOG,CAAAA,CAAK,CAAC,EACdH,CAAAA,CAAK,MAAA,GAAW,CAAA,EAAGV,CAAAA,CAAQ,QAAA,CAAS,MAAA,CAAOO,CAAG,CAAA,EAEtD,CAIAP,CAAAA,CAAQ,IAAA,CAAK,MAAA,CAAOoB,CAAC,CAAA,CACrB,IAAA,GAAW,CAACb,EAAKI,CAAK,CAAA,GAAKX,CAAAA,CAAQ,IAAA,CACjCW,CAAAA,CAAM,MAAA,CAAOS,CAAC,CAAA,CACVT,CAAAA,CAAM,IAAA,GAAS,CAAA,EAAGX,CAAAA,CAAQ,IAAA,CAAK,MAAA,CAAOO,CAAG,EAEjD,CACF,CAAC,CAAA","file":"relations.cjs","sourcesContent":["// aiecsjs/relations — entity-to-entity relations (experimental in 0.1).\n\nimport { packEid, registerRelationsCleanup } from './internal/entity.js'\nimport type { EntityId, Relation, RelationStorage, World, WorldState } from './internal/types.js'\nimport { getWorldState } from './internal/world.js'\n\nlet nextRelationId = 1\n\nexport function defineRelation<T = void>(options?: { exclusive?: boolean }): Relation<T> {\n const id = nextRelationId++\n return {\n __kind: 'relation',\n __id: id,\n __exclusive: options?.exclusive ?? false,\n __hasData: false,\n } as Relation<T>\n}\n\nexport const ChildOf: Relation = defineRelation({ exclusive: true })\n\nfunction getOrCreateStorage(state: WorldState, rel: Relation<any>): RelationStorage {\n let storage = state.relationStorage.get(rel.__id)\n if (storage) return storage\n storage = {\n rel,\n exclusive: rel.__exclusive ? new Int32Array(state.capacity).fill(-1) : null,\n outgoing: new Map<number, number[]>(),\n data: new Map<number, Map<number, unknown>>(),\n }\n state.relationStorage.set(rel.__id, storage)\n return storage\n}\n\nexport function addRelation<T>(\n world: World,\n source: EntityId,\n rel: Relation<T>,\n target: EntityId,\n data?: T,\n): void {\n const state = getWorldState(world)\n if (state.readOnly) throw new Error('aiecsjs: cannot mutate a read-only world')\n const storage = getOrCreateStorage(state, rel as Relation<any>)\n // Use raw idx as keys in relation storage so slot reuse invalidation is consistent\n const src = (source as number) & state.options.indexMask\n const tgt = (target as number) & state.options.indexMask\n\n if (storage.exclusive) {\n if (src >= storage.exclusive.length) {\n const next = new Int32Array(Math.max(src + 1, storage.exclusive.length * 2)).fill(-1)\n next.set(storage.exclusive)\n storage.exclusive = next\n }\n storage.exclusive[src] = tgt\n } else {\n let list = storage.outgoing.get(src)\n if (!list) {\n list = []\n storage.outgoing.set(src, list)\n }\n if (!list.includes(tgt)) list.push(tgt)\n }\n\n if (data !== undefined) {\n let inner = storage.data.get(src)\n if (!inner) {\n inner = new Map<number, unknown>()\n storage.data.set(src, inner)\n }\n inner.set(tgt, data)\n }\n}\n\nexport function removeRelation(\n world: World,\n source: EntityId,\n rel: Relation,\n target: EntityId,\n): void {\n const state = getWorldState(world)\n if (state.readOnly) throw new Error('aiecsjs: cannot mutate a read-only world')\n const storage = state.relationStorage.get(rel.__id)\n if (!storage) return\n const src = (source as number) & state.options.indexMask\n const tgt = (target as number) & state.options.indexMask\n if (storage.exclusive) {\n if (src < storage.exclusive.length && storage.exclusive[src] === tgt) {\n storage.exclusive[src] = -1\n }\n } else {\n const list = storage.outgoing.get(src)\n if (list) {\n const idx = list.indexOf(tgt)\n if (idx >= 0) list.splice(idx, 1)\n if (list.length === 0) storage.outgoing.delete(src)\n }\n }\n const inner = storage.data.get(src)\n if (inner) {\n inner.delete(tgt)\n if (inner.size === 0) storage.data.delete(src)\n }\n}\n\nexport function getRelationTargets(\n world: World,\n source: EntityId,\n rel: Relation,\n): readonly EntityId[] {\n const state = getWorldState(world)\n const storage = state.relationStorage.get(rel.__id)\n if (!storage) return []\n const src = (source as number) & state.options.indexMask\n if (storage.exclusive) {\n if (src < storage.exclusive.length) {\n const tgt = storage.exclusive[src] ?? -1\n if (tgt >= 0) {\n const gen = state.generations[tgt] ?? 0\n return [packEid(tgt, gen, state.options)]\n }\n }\n return []\n }\n const list = storage.outgoing.get(src)\n if (!list) return []\n return list.map((tIdx) => {\n const gen = state.generations[tIdx] ?? 0\n return packEid(tIdx, gen, state.options)\n })\n}\n\n// Cleanup hook: when an entity is destroyed, remove all relations involving it.\nregisterRelationsCleanup((state: WorldState, eid: EntityId) => {\n const e = (eid as number) & state.options.indexMask\n for (const storage of state.relationStorage.values()) {\n if (storage.exclusive) {\n if (e < storage.exclusive.length) storage.exclusive[e] = -1\n // Also clear any references TO this entity as target\n for (let i = 0; i < storage.exclusive.length; i++) {\n if (storage.exclusive[i] === e) storage.exclusive[i] = -1\n }\n }\n storage.outgoing.delete(e)\n for (const [src, list] of storage.outgoing) {\n const idx = list.indexOf(e)\n if (idx >= 0) {\n list.splice(idx, 1)\n if (list.length === 0) storage.outgoing.delete(src)\n }\n }\n // Clear data entries involving this entity. The outer key is the source\n // eid; entries whose source IS this entity drop entirely. Entries that\n // reference this entity as a target are pruned from each inner map.\n storage.data.delete(e)\n for (const [src, inner] of storage.data) {\n inner.delete(e)\n if (inner.size === 0) storage.data.delete(src)\n }\n }\n})\n"]}
1
+ {"version":3,"sources":["../src/relations.ts"],"names":["nextRelationId","defineRelation","options","ChildOf","getOrCreateStorage","state","rel","storage","addRelation","world","source","target","data","getWorldState","src","tgt","next","prevTgt","prevInner","list","inner","removeRelation","idx","getRelationTargets","gen","packEid","tIdx","getRelationData","registerRelationsCleanup","eid","e","i"],"mappings":"mEAMA,IAAIA,CAAAA,CAAiB,CAAA,CAEd,SAASC,CAAAA,CAAyBC,EAAgD,CAEvF,OAAO,CACL,MAAA,CAAQ,WACR,IAAA,CAHSF,CAAAA,EAAAA,CAIT,WAAA,CAAaE,CAAAA,EAAS,WAAa,KAAA,CACnC,SAAA,CAAW,KACb,CACF,CAEO,IAAMC,CAAAA,CAAoBF,CAAAA,CAAe,CAAE,SAAA,CAAW,IAAK,CAAC,EAEnE,SAASG,CAAAA,CAAmBC,CAAAA,CAAmBC,CAAAA,CAAqC,CAClF,IAAIC,CAAAA,CAAUF,CAAAA,CAAM,eAAA,CAAgB,GAAA,CAAIC,CAAAA,CAAI,IAAI,CAAA,CAChD,OAAIC,IACJA,CAAAA,CAAU,CACR,GAAA,CAAAD,CAAAA,CACA,UAAWA,CAAAA,CAAI,WAAA,CAAc,IAAI,UAAA,CAAWD,EAAM,QAAQ,CAAA,CAAE,IAAA,CAAK,EAAE,EAAI,IAAA,CACvE,QAAA,CAAU,IAAI,GAAA,CACd,KAAM,IAAI,GACZ,CAAA,CACAA,CAAAA,CAAM,gBAAgB,GAAA,CAAIC,CAAAA,CAAI,IAAA,CAAMC,CAAO,EACpCA,CAAAA,CACT,CAEO,SAASC,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACAJ,CAAAA,CACAK,CAAAA,CACAC,EACM,CACN,IAAMP,CAAAA,CAAQQ,mBAAAA,CAAcJ,CAAK,CAAA,CACjC,GAAIJ,CAAAA,CAAM,QAAA,CAAU,MAAM,IAAI,KAAA,CAAM,0CAA0C,CAAA,CAC9E,IAAME,CAAAA,CAAUH,CAAAA,CAAmBC,CAAAA,CAAOC,CAAoB,EAExDQ,CAAAA,CAAOJ,CAAAA,CAAoBL,CAAAA,CAAM,OAAA,CA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OG,CAAAA,CAAK,CAAC,CAAA,CACdH,CAAAA,CAAK,MAAA,GAAW,CAAA,EAAGZ,EAAQ,QAAA,CAAS,MAAA,CAAOO,CAAG,CAAA,EAEtD,CAIAP,CAAAA,CAAQ,IAAA,CAAK,MAAA,CAAOuB,CAAC,EACrB,IAAA,GAAW,CAAChB,CAAAA,CAAKM,CAAK,IAAKb,CAAAA,CAAQ,IAAA,CACjCa,CAAAA,CAAM,MAAA,CAAOU,CAAC,CAAA,CACVV,CAAAA,CAAM,IAAA,GAAS,CAAA,EAAGb,EAAQ,IAAA,CAAK,MAAA,CAAOO,CAAG,EAEjD,CACF,CAAC,CAAA","file":"relations.cjs","sourcesContent":["// aiecsjs/relations — entity-to-entity relations (experimental in 0.1).\n\nimport { packEid, registerRelationsCleanup } from './internal/entity.js'\nimport type { EntityId, Relation, RelationStorage, World, WorldState } from './internal/types.js'\nimport { getWorldState } from './internal/world.js'\n\nlet nextRelationId = 1\n\nexport function defineRelation<T = void>(options?: { exclusive?: boolean }): Relation<T> {\n const id = nextRelationId++\n return {\n __kind: 'relation',\n __id: id,\n __exclusive: options?.exclusive ?? false,\n __hasData: false,\n } as Relation<T>\n}\n\nexport const ChildOf: Relation = defineRelation({ exclusive: true })\n\nfunction getOrCreateStorage(state: WorldState, rel: Relation<any>): RelationStorage {\n let storage = state.relationStorage.get(rel.__id)\n if (storage) return storage\n storage = {\n rel,\n exclusive: rel.__exclusive ? new Int32Array(state.capacity).fill(-1) : null,\n outgoing: new Map<number, number[]>(),\n data: new Map<number, Map<number, unknown>>(),\n }\n state.relationStorage.set(rel.__id, storage)\n return storage\n}\n\nexport function addRelation<T>(\n world: World,\n source: EntityId,\n rel: Relation<T>,\n target: EntityId,\n data?: T,\n): void {\n const state = getWorldState(world)\n if (state.readOnly) throw new Error('aiecsjs: cannot mutate a read-only world')\n const storage = getOrCreateStorage(state, rel as Relation<any>)\n // Use raw idx as keys in relation storage so slot reuse invalidation is consistent\n const src = (source as number) & state.options.indexMask\n const tgt = (target as number) & state.options.indexMask\n\n if (storage.exclusive) {\n if (src >= storage.exclusive.length) {\n const next = new Int32Array(Math.max(src + 1, storage.exclusive.length * 2)).fill(-1)\n next.set(storage.exclusive)\n storage.exclusive = next\n }\n // Exclusive redirect: if this source already pointed at a different target,\n // drop that previous target's data entry so getRelationData stays consistent\n // with getRelationTargets, which reports only the current exclusive target.\n const prevTgt = storage.exclusive[src] ?? -1\n if (prevTgt >= 0 && prevTgt !== tgt) {\n const prevInner = storage.data.get(src)\n prevInner?.delete(prevTgt)\n if (prevInner && prevInner.size === 0) storage.data.delete(src)\n }\n storage.exclusive[src] = tgt\n } else {\n let list = storage.outgoing.get(src)\n if (!list) {\n list = []\n storage.outgoing.set(src, list)\n }\n if (!list.includes(tgt)) list.push(tgt)\n }\n\n if (data !== undefined) {\n let inner = storage.data.get(src)\n if (!inner) {\n inner = new Map<number, unknown>()\n storage.data.set(src, inner)\n }\n inner.set(tgt, data)\n }\n}\n\nexport function removeRelation(\n world: World,\n source: EntityId,\n rel: Relation,\n target: EntityId,\n): void {\n const state = getWorldState(world)\n if (state.readOnly) throw new Error('aiecsjs: cannot mutate a read-only world')\n const storage = state.relationStorage.get(rel.__id)\n if (!storage) return\n const src = (source as number) & state.options.indexMask\n const tgt = (target as number) & state.options.indexMask\n if (storage.exclusive) {\n if (src < storage.exclusive.length && storage.exclusive[src] === tgt) {\n storage.exclusive[src] = -1\n }\n } else {\n const list = storage.outgoing.get(src)\n if (list) {\n const idx = list.indexOf(tgt)\n if (idx >= 0) list.splice(idx, 1)\n if (list.length === 0) storage.outgoing.delete(src)\n }\n }\n const inner = storage.data.get(src)\n if (inner) {\n inner.delete(tgt)\n if (inner.size === 0) storage.data.delete(src)\n }\n}\n\nexport function getRelationTargets(\n world: World,\n source: EntityId,\n rel: Relation,\n): readonly EntityId[] {\n const state = getWorldState(world)\n const storage = state.relationStorage.get(rel.__id)\n if (!storage) return []\n const src = (source as number) & state.options.indexMask\n if (storage.exclusive) {\n if (src < storage.exclusive.length) {\n const tgt = storage.exclusive[src] ?? -1\n if (tgt >= 0) {\n const gen = state.generations[tgt] ?? 0\n return [packEid(tgt, gen, state.options)]\n }\n }\n return []\n }\n const list = storage.outgoing.get(src)\n if (!list) return []\n return list.map((tIdx) => {\n const gen = state.generations[tIdx] ?? 0\n return packEid(tIdx, gen, state.options)\n })\n}\n\n/**\n * Read the data payload attached to a relation edge.\n *\n * Returns the `data` value that was supplied to {@link addRelation} for the\n * `(source, rel, target)` triple, or `undefined` when:\n * - the relation has never been stored for this world,\n * - no edge from `source` to `target` via `rel` exists, or\n * - the edge was added without a data argument.\n *\n * **Slot-keying semantic (ABA caveat):** relation storage keys edges by raw\n * entity slot index (`entityId & indexMask`), not by the full packed EntityId\n * that includes the generation counter. This means that if entity A is\n * destroyed and a *different* entity B is later created in the same slot, B\n * will inherit any edges that A had — unless the destroy cleanup hook ran\n * (which it does when `destroyEntity` is called). Callers that cache a\n * source/target EntityId should validate liveness with `entityExists` before\n * calling `getRelationData` if slot recycling is a concern.\n */\nexport function getRelationData<T>(\n world: World,\n source: EntityId,\n rel: Relation<T>,\n target: EntityId,\n): T | undefined {\n const state = getWorldState(world)\n const storage = state.relationStorage.get(rel.__id)\n if (!storage) return undefined\n const src = (source as number) & state.options.indexMask\n const tgt = (target as number) & state.options.indexMask\n return storage.data.get(src)?.get(tgt) as T | undefined\n}\n\n// Cleanup hook: when an entity is destroyed, remove all relations involving it.\nregisterRelationsCleanup((state: WorldState, eid: EntityId) => {\n const e = (eid as number) & state.options.indexMask\n for (const storage of state.relationStorage.values()) {\n if (storage.exclusive) {\n if (e < storage.exclusive.length) storage.exclusive[e] = -1\n // Also clear any references TO this entity as target\n for (let i = 0; i < storage.exclusive.length; i++) {\n if (storage.exclusive[i] === e) storage.exclusive[i] = -1\n }\n }\n storage.outgoing.delete(e)\n for (const [src, list] of storage.outgoing) {\n const idx = list.indexOf(e)\n if (idx >= 0) {\n list.splice(idx, 1)\n if (list.length === 0) storage.outgoing.delete(src)\n }\n }\n // Clear data entries involving this entity. The outer key is the source\n // eid; entries whose source IS this entity drop entirely. Entries that\n // reference this entity as a target are pruned from each inner map.\n storage.data.delete(e)\n for (const [src, inner] of storage.data) {\n inner.delete(e)\n if (inner.size === 0) storage.data.delete(src)\n }\n }\n})\n"]}
@@ -7,5 +7,24 @@ declare const ChildOf: Relation;
7
7
  declare function addRelation<T>(world: World, source: EntityId, rel: Relation<T>, target: EntityId, data?: T): void;
8
8
  declare function removeRelation(world: World, source: EntityId, rel: Relation, target: EntityId): void;
9
9
  declare function getRelationTargets(world: World, source: EntityId, rel: Relation): readonly EntityId[];
10
+ /**
11
+ * Read the data payload attached to a relation edge.
12
+ *
13
+ * Returns the `data` value that was supplied to {@link addRelation} for the
14
+ * `(source, rel, target)` triple, or `undefined` when:
15
+ * - the relation has never been stored for this world,
16
+ * - no edge from `source` to `target` via `rel` exists, or
17
+ * - the edge was added without a data argument.
18
+ *
19
+ * **Slot-keying semantic (ABA caveat):** relation storage keys edges by raw
20
+ * entity slot index (`entityId & indexMask`), not by the full packed EntityId
21
+ * that includes the generation counter. This means that if entity A is
22
+ * destroyed and a *different* entity B is later created in the same slot, B
23
+ * will inherit any edges that A had — unless the destroy cleanup hook ran
24
+ * (which it does when `destroyEntity` is called). Callers that cache a
25
+ * source/target EntityId should validate liveness with `entityExists` before
26
+ * calling `getRelationData` if slot recycling is a concern.
27
+ */
28
+ declare function getRelationData<T>(world: World, source: EntityId, rel: Relation<T>, target: EntityId): T | undefined;
10
29
 
11
- export { ChildOf, addRelation, defineRelation, getRelationTargets, removeRelation };
30
+ export { ChildOf, addRelation, defineRelation, getRelationData, getRelationTargets, removeRelation };
@@ -7,5 +7,24 @@ declare const ChildOf: Relation;
7
7
  declare function addRelation<T>(world: World, source: EntityId, rel: Relation<T>, target: EntityId, data?: T): void;
8
8
  declare function removeRelation(world: World, source: EntityId, rel: Relation, target: EntityId): void;
9
9
  declare function getRelationTargets(world: World, source: EntityId, rel: Relation): readonly EntityId[];
10
+ /**
11
+ * Read the data payload attached to a relation edge.
12
+ *
13
+ * Returns the `data` value that was supplied to {@link addRelation} for the
14
+ * `(source, rel, target)` triple, or `undefined` when:
15
+ * - the relation has never been stored for this world,
16
+ * - no edge from `source` to `target` via `rel` exists, or
17
+ * - the edge was added without a data argument.
18
+ *
19
+ * **Slot-keying semantic (ABA caveat):** relation storage keys edges by raw
20
+ * entity slot index (`entityId & indexMask`), not by the full packed EntityId
21
+ * that includes the generation counter. This means that if entity A is
22
+ * destroyed and a *different* entity B is later created in the same slot, B
23
+ * will inherit any edges that A had — unless the destroy cleanup hook ran
24
+ * (which it does when `destroyEntity` is called). Callers that cache a
25
+ * source/target EntityId should validate liveness with `entityExists` before
26
+ * calling `getRelationData` if slot recycling is a concern.
27
+ */
28
+ declare function getRelationData<T>(world: World, source: EntityId, rel: Relation<T>, target: EntityId): T | undefined;
10
29
 
11
- export { ChildOf, addRelation, defineRelation, getRelationTargets, removeRelation };
30
+ export { ChildOf, addRelation, defineRelation, getRelationData, getRelationTargets, removeRelation };
package/dist/relations.js CHANGED
@@ -1,2 +1,2 @@
1
- import {D,i,r}from'./chunk-L5CMKMIP.js';var x=1;function v(r){return {__kind:"relation",__id:x++,__exclusive:r?.exclusive??false,__hasData:false}}var _=v({exclusive:true});function p(r,l){let o=r.relationStorage.get(l.__id);return o||(o={rel:l,exclusive:l.__exclusive?new Int32Array(r.capacity).fill(-1):null,outgoing:new Map,data:new Map},r.relationStorage.set(l.__id,o),o)}function R(r,l,o,n,i$1){let e=i(r);if(e.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");let t=p(e,o),s=l&e.options.indexMask,c=n&e.options.indexMask;if(t.exclusive){if(s>=t.exclusive.length){let a=new Int32Array(Math.max(s+1,t.exclusive.length*2)).fill(-1);a.set(t.exclusive),t.exclusive=a;}t.exclusive[s]=c;}else {let a=t.outgoing.get(s);a||(a=[],t.outgoing.set(s,a)),a.includes(c)||a.push(c);}if(i$1!==void 0){let a=t.data.get(s);a||(a=new Map,t.data.set(s,a)),a.set(c,i$1);}}function h(r,l,o,n){let i$1=i(r);if(i$1.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");let e=i$1.relationStorage.get(o.__id);if(!e)return;let t=l&i$1.options.indexMask,s=n&i$1.options.indexMask;if(e.exclusive)t<e.exclusive.length&&e.exclusive[t]===s&&(e.exclusive[t]=-1);else {let a=e.outgoing.get(t);if(a){let g=a.indexOf(s);g>=0&&a.splice(g,1),a.length===0&&e.outgoing.delete(t);}}let c=e.data.get(t);c&&(c.delete(s),c.size===0&&e.data.delete(t));}function w(r$1,l,o){let n=i(r$1),i$1=n.relationStorage.get(o.__id);if(!i$1)return [];let e=l&n.options.indexMask;if(i$1.exclusive){if(e<i$1.exclusive.length){let s=i$1.exclusive[e]??-1;if(s>=0){let c=n.generations[s]??0;return [r(s,c,n.options)]}}return []}let t=i$1.outgoing.get(e);return t?t.map(s=>{let c=n.generations[s]??0;return r(s,c,n.options)}):[]}D((r,l)=>{let o=l&r.options.indexMask;for(let n of r.relationStorage.values()){if(n.exclusive){o<n.exclusive.length&&(n.exclusive[o]=-1);for(let i=0;i<n.exclusive.length;i++)n.exclusive[i]===o&&(n.exclusive[i]=-1);}n.outgoing.delete(o);for(let[i,e]of n.outgoing){let t=e.indexOf(o);t>=0&&(e.splice(t,1),e.length===0&&n.outgoing.delete(i));}n.data.delete(o);for(let[i,e]of n.data)e.delete(o),e.size===0&&n.data.delete(i);}});export{_ as ChildOf,R as addRelation,v as defineRelation,w as getRelationTargets,h as removeRelation};//# sourceMappingURL=relations.js.map
1
+ import {D,i,r}from'./chunk-F7KNZ27O.js';var x=1;function p(r){return {__kind:"relation",__id:x++,__exclusive:r?.exclusive??false,__hasData:false}}var _=p({exclusive:true});function v(r,l){let s=r.relationStorage.get(l.__id);return s||(s={rel:l,exclusive:l.__exclusive?new Int32Array(r.capacity).fill(-1):null,outgoing:new Map,data:new Map},r.relationStorage.set(l.__id,s),s)}function R(r,l,s,i$1,n){let t=i(r);if(t.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");let e=v(t,s),o=l&t.options.indexMask,d=i$1&t.options.indexMask;if(e.exclusive){if(o>=e.exclusive.length){let c=new Int32Array(Math.max(o+1,e.exclusive.length*2)).fill(-1);c.set(e.exclusive),e.exclusive=c;}let a=e.exclusive[o]??-1;if(a>=0&&a!==d){let c=e.data.get(o);c?.delete(a),c&&c.size===0&&e.data.delete(o);}e.exclusive[o]=d;}else {let a=e.outgoing.get(o);a||(a=[],e.outgoing.set(o,a)),a.includes(d)||a.push(d);}if(n!==void 0){let a=e.data.get(o);a||(a=new Map,e.data.set(o,a)),a.set(d,n);}}function b(r,l,s,i$1){let n=i(r);if(n.readOnly)throw new Error("aiecsjs: cannot mutate a read-only world");let t=n.relationStorage.get(s.__id);if(!t)return;let e=l&n.options.indexMask,o=i$1&n.options.indexMask;if(t.exclusive)e<t.exclusive.length&&t.exclusive[e]===o&&(t.exclusive[e]=-1);else {let a=t.outgoing.get(e);if(a){let c=a.indexOf(o);c>=0&&a.splice(c,1),a.length===0&&t.outgoing.delete(e);}}let d=t.data.get(e);d&&(d.delete(o),d.size===0&&t.data.delete(e));}function h(r$1,l,s){let i$1=i(r$1),n=i$1.relationStorage.get(s.__id);if(!n)return [];let t=l&i$1.options.indexMask;if(n.exclusive){if(t<n.exclusive.length){let o=n.exclusive[t]??-1;if(o>=0){let d=i$1.generations[o]??0;return [r(o,d,i$1.options)]}}return []}let e=n.outgoing.get(t);return e?e.map(o=>{let d=i$1.generations[o]??0;return r(o,d,i$1.options)}):[]}function w(r,l,s,i$1){let n=i(r),t=n.relationStorage.get(s.__id);if(!t)return;let e=l&n.options.indexMask,o=i$1&n.options.indexMask;return t.data.get(e)?.get(o)}D((r,l)=>{let s=l&r.options.indexMask;for(let i of r.relationStorage.values()){if(i.exclusive){s<i.exclusive.length&&(i.exclusive[s]=-1);for(let n=0;n<i.exclusive.length;n++)i.exclusive[n]===s&&(i.exclusive[n]=-1);}i.outgoing.delete(s);for(let[n,t]of i.outgoing){let e=t.indexOf(s);e>=0&&(t.splice(e,1),t.length===0&&i.outgoing.delete(n));}i.data.delete(s);for(let[n,t]of i.data)t.delete(s),t.size===0&&i.data.delete(n);}});export{_ as ChildOf,R as addRelation,p as defineRelation,w as getRelationData,h as getRelationTargets,b as removeRelation};//# sourceMappingURL=relations.js.map
2
2
  //# sourceMappingURL=relations.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/relations.ts"],"names":["nextRelationId","defineRelation","options","ChildOf","getOrCreateStorage","state","rel","storage","addRelation","world","source","target","data","getWorldState","src","tgt","next","list","inner","removeRelation","idx","getRelationTargets","gen","packEid","tIdx","registerRelationsCleanup","eid","e"],"mappings":"wCAMA,IAAIA,CAAAA,CAAiB,CAAA,CAEd,SAASC,CAAAA,CAAyBC,CAAAA,CAAgD,CAEvF,OAAO,CACL,MAAA,CAAQ,UAAA,CACR,IAAA,CAHSF,CAAAA,EAAAA,CAIT,WAAA,CAAaE,CAAAA,EAAS,SAAA,EAAa,KAAA,CACnC,SAAA,CAAW,KACb,CACF,CAEO,IAAMC,CAAAA,CAAoBF,CAAAA,CAAe,CAAE,SAAA,CAAW,IAAK,CAAC,EAEnE,SAASG,CAAAA,CAAmBC,CAAAA,CAAmBC,CAAAA,CAAqC,CAClF,IAAIC,CAAAA,CAAUF,CAAAA,CAAM,eAAA,CAAgB,GAAA,CAAIC,CAAAA,CAAI,IAAI,CAAA,CAChD,OAAIC,CAAAA,GACJA,CAAAA,CAAU,CACR,IAAAD,CAAAA,CACA,SAAA,CAAWA,CAAAA,CAAI,WAAA,CAAc,IAAI,UAAA,CAAWD,CAAAA,CAAM,QAAQ,CAAA,CAAE,IAAA,CAAK,EAAE,CAAA,CAAI,IAAA,CACvE,QAAA,CAAU,IAAI,GAAA,CACd,KAAM,IAAI,GACZ,CAAA,CACAA,CAAAA,CAAM,eAAA,CAAgB,GAAA,CAAIC,CAAAA,CAAI,IAAA,CAAM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,GAAW,CAACb,EAAKI,CAAK,CAAA,GAAKX,CAAAA,CAAQ,IAAA,CACjCW,CAAAA,CAAM,MAAA,CAAOS,CAAC,CAAA,CACVT,CAAAA,CAAM,IAAA,GAAS,CAAA,EAAGX,CAAAA,CAAQ,IAAA,CAAK,MAAA,CAAOO,CAAG,EAEjD,CACF,CAAC,CAAA","file":"relations.js","sourcesContent":["// aiecsjs/relations — entity-to-entity relations (experimental in 0.1).\n\nimport { packEid, registerRelationsCleanup } from './internal/entity.js'\nimport type { EntityId, Relation, RelationStorage, World, WorldState } from './internal/types.js'\nimport { getWorldState } from './internal/world.js'\n\nlet nextRelationId = 1\n\nexport function defineRelation<T = void>(options?: { exclusive?: boolean }): Relation<T> {\n const id = nextRelationId++\n return {\n __kind: 'relation',\n __id: id,\n __exclusive: options?.exclusive ?? false,\n __hasData: false,\n } as Relation<T>\n}\n\nexport const ChildOf: Relation = defineRelation({ exclusive: true })\n\nfunction getOrCreateStorage(state: WorldState, rel: Relation<any>): RelationStorage {\n let storage = state.relationStorage.get(rel.__id)\n if (storage) return storage\n storage = {\n rel,\n exclusive: rel.__exclusive ? new Int32Array(state.capacity).fill(-1) : null,\n outgoing: new Map<number, number[]>(),\n data: new Map<number, Map<number, unknown>>(),\n }\n state.relationStorage.set(rel.__id, storage)\n return storage\n}\n\nexport function addRelation<T>(\n world: World,\n source: EntityId,\n rel: Relation<T>,\n target: EntityId,\n data?: T,\n): void {\n const state = getWorldState(world)\n if (state.readOnly) throw new Error('aiecsjs: cannot mutate a read-only world')\n const storage = getOrCreateStorage(state, rel as Relation<any>)\n // Use raw idx as keys in relation storage so slot reuse invalidation is consistent\n const src = (source as number) & state.options.indexMask\n const tgt = (target as number) & state.options.indexMask\n\n if (storage.exclusive) {\n if (src >= storage.exclusive.length) {\n const next = new Int32Array(Math.max(src + 1, storage.exclusive.length * 2)).fill(-1)\n next.set(storage.exclusive)\n storage.exclusive = next\n }\n storage.exclusive[src] = tgt\n } else {\n let list = storage.outgoing.get(src)\n if (!list) {\n list = []\n storage.outgoing.set(src, list)\n }\n if (!list.includes(tgt)) list.push(tgt)\n }\n\n if (data !== undefined) {\n let inner = storage.data.get(src)\n if (!inner) {\n inner = new Map<number, unknown>()\n storage.data.set(src, inner)\n }\n inner.set(tgt, data)\n }\n}\n\nexport function removeRelation(\n world: World,\n source: EntityId,\n rel: Relation,\n target: EntityId,\n): void {\n const state = getWorldState(world)\n if (state.readOnly) throw new Error('aiecsjs: cannot mutate a read-only world')\n const storage = state.relationStorage.get(rel.__id)\n if (!storage) return\n const src = (source as number) & state.options.indexMask\n const tgt = (target as number) & state.options.indexMask\n if (storage.exclusive) {\n if (src < storage.exclusive.length && storage.exclusive[src] === tgt) {\n storage.exclusive[src] = -1\n }\n } else {\n const list = storage.outgoing.get(src)\n if (list) {\n const idx = list.indexOf(tgt)\n if (idx >= 0) list.splice(idx, 1)\n if (list.length === 0) storage.outgoing.delete(src)\n }\n }\n const inner = storage.data.get(src)\n if (inner) {\n inner.delete(tgt)\n if (inner.size === 0) storage.data.delete(src)\n }\n}\n\nexport function getRelationTargets(\n world: World,\n source: EntityId,\n rel: Relation,\n): readonly EntityId[] {\n const state = getWorldState(world)\n const storage = state.relationStorage.get(rel.__id)\n if (!storage) return []\n const src = (source as number) & state.options.indexMask\n if (storage.exclusive) {\n if (src < storage.exclusive.length) {\n const tgt = storage.exclusive[src] ?? -1\n if (tgt >= 0) {\n const gen = state.generations[tgt] ?? 0\n return [packEid(tgt, gen, state.options)]\n }\n }\n return []\n }\n const list = storage.outgoing.get(src)\n if (!list) return []\n return list.map((tIdx) => {\n const gen = state.generations[tIdx] ?? 0\n return packEid(tIdx, gen, state.options)\n })\n}\n\n// Cleanup hook: when an entity is destroyed, remove all relations involving it.\nregisterRelationsCleanup((state: WorldState, eid: EntityId) => {\n const e = (eid as number) & state.options.indexMask\n for (const storage of state.relationStorage.values()) {\n if (storage.exclusive) {\n if (e < storage.exclusive.length) storage.exclusive[e] = -1\n // Also clear any references TO this entity as target\n for (let i = 0; i < storage.exclusive.length; i++) {\n if (storage.exclusive[i] === e) storage.exclusive[i] = -1\n }\n }\n storage.outgoing.delete(e)\n for (const [src, list] of storage.outgoing) {\n const idx = list.indexOf(e)\n if (idx >= 0) {\n list.splice(idx, 1)\n if (list.length === 0) storage.outgoing.delete(src)\n }\n }\n // Clear data entries involving this entity. The outer key is the source\n // eid; entries whose source IS this entity drop entirely. Entries that\n // reference this entity as a target are pruned from each inner map.\n storage.data.delete(e)\n for (const [src, inner] of storage.data) {\n inner.delete(e)\n if (inner.size === 0) storage.data.delete(src)\n }\n }\n})\n"]}
1
+ {"version":3,"sources":["../src/relations.ts"],"names":["nextRelationId","defineRelation","options","ChildOf","getOrCreateStorage","state","rel","storage","addRelation","world","source","target","data","getWorldState","src","tgt","next","prevTgt","prevInner","list","inner","removeRelation","idx","getRelationTargets","gen","packEid","tIdx","getRelationData","registerRelationsCleanup","eid","e","i"],"mappings":"wCAMA,IAAIA,CAAAA,CAAiB,CAAA,CAEd,SAASC,CAAAA,CAAyBC,EAAgD,CAEvF,OAAO,CACL,MAAA,CAAQ,WACR,IAAA,CAHSF,CAAAA,EAAAA,CAIT,WAAA,CAAaE,CAAAA,EAAS,WAAa,KAAA,CACnC,SAAA,CAAW,KACb,CACF,CAEO,IAAMC,CAAAA,CAAoBF,CAAAA,CAAe,CAAE,SAAA,CAAW,IAAK,CAAC,EAEnE,SAASG,CAAAA,CAAmBC,CAAAA,CAAmBC,CAAAA,CAAqC,CAClF,IAAIC,CAAAA,CAAUF,CAAAA,CAAM,eAAA,CAAgB,GAAA,CAAIC,CAAAA,CAAI,IAAI,CAAA,CAChD,OAAIC,IACJA,CAAAA,CAAU,CACR,GAAA,CAAAD,CAAAA,CACA,UAAWA,CAAAA,CAAI,WAAA,CAAc,IAAI,UAAA,CAAWD,EAAM,QAAQ,CAAA,CAAE,IAAA,CAAK,EAAE,EAAI,IAAA,CACvE,QAAA,CAAU,IAAI,GAAA,CACd,KAAM,IAA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AI,CAAA,CAAGA,CAAAA,CAAIxB,CAAAA,CAAQ,SAAA,CAAU,MAAA,CAAQwB,CAAAA,EAAAA,CACxCxB,CAAAA,CAAQ,UAAUwB,CAAC,CAAA,GAAMD,CAAAA,GAAGvB,CAAAA,CAAQ,UAAUwB,CAAC,CAAA,CAAI,EAAA,EAE3D,CACAxB,EAAQ,QAAA,CAAS,MAAA,CAAOuB,CAAC,CAAA,CACzB,OAAW,CAAChB,CAAAA,CAAKK,CAAI,CAAA,GAAKZ,EAAQ,QAAA,CAAU,CAC1C,IAAMe,CAAAA,CAAMH,EAAK,OAAA,CAAQW,CAAC,CAAA,CACtBR,CAAAA,EAAO,IACTH,CAAAA,CAAK,MAAA,CAAOG,CAAAA,CAAK,CAAC,CAAA,CACdH,CAAAA,CAAK,MAAA,GAAW,CAAA,EAAGZ,EAAQ,QAAA,CAAS,MAAA,CAAOO,CAAG,CAAA,EAEtD,CAIAP,CAAAA,CAAQ,IAAA,CAAK,MAAA,CAAOuB,CAAC,EACrB,IAAA,GAAW,CAAChB,CAAAA,CAAKM,CAAK,IAAKb,CAAAA,CAAQ,IAAA,CACjCa,CAAAA,CAAM,MAAA,CAAOU,CAAC,CAAA,CACVV,CAAAA,CAAM,IAAA,GAAS,CAAA,EAAGb,EAAQ,IAAA,CAAK,MAAA,CAAOO,CAAG,EAEjD,CACF,CAAC,CAAA","file":"relations.js","sourcesContent":["// aiecsjs/relations — entity-to-entity relations (experimental in 0.1).\n\nimport { packEid, registerRelationsCleanup } from './internal/entity.js'\nimport type { EntityId, Relation, RelationStorage, World, WorldState } from './internal/types.js'\nimport { getWorldState } from './internal/world.js'\n\nlet nextRelationId = 1\n\nexport function defineRelation<T = void>(options?: { exclusive?: boolean }): Relation<T> {\n const id = nextRelationId++\n return {\n __kind: 'relation',\n __id: id,\n __exclusive: options?.exclusive ?? false,\n __hasData: false,\n } as Relation<T>\n}\n\nexport const ChildOf: Relation = defineRelation({ exclusive: true })\n\nfunction getOrCreateStorage(state: WorldState, rel: Relation<any>): RelationStorage {\n let storage = state.relationStorage.get(rel.__id)\n if (storage) return storage\n storage = {\n rel,\n exclusive: rel.__exclusive ? new Int32Array(state.capacity).fill(-1) : null,\n outgoing: new Map<number, number[]>(),\n data: new Map<number, Map<number, unknown>>(),\n }\n state.relationStorage.set(rel.__id, storage)\n return storage\n}\n\nexport function addRelation<T>(\n world: World,\n source: EntityId,\n rel: Relation<T>,\n target: EntityId,\n data?: T,\n): void {\n const state = getWorldState(world)\n if (state.readOnly) throw new Error('aiecsjs: cannot mutate a read-only world')\n const storage = getOrCreateStorage(state, rel as Relation<any>)\n // Use raw idx as keys in relation storage so slot reuse invalidation is consistent\n const src = (source as number) & state.options.indexMask\n const tgt = (target as number) & state.options.indexMask\n\n if (storage.exclusive) {\n if (src >= storage.exclusive.length) {\n const next = new Int32Array(Math.max(src + 1, storage.exclusive.length * 2)).fill(-1)\n next.set(storage.exclusive)\n storage.exclusive = next\n }\n // Exclusive redirect: if this source already pointed at a different target,\n // drop that previous target's data entry so getRelationData stays consistent\n // with getRelationTargets, which reports only the current exclusive target.\n const prevTgt = storage.exclusive[src] ?? -1\n if (prevTgt >= 0 && prevTgt !== tgt) {\n const prevInner = storage.data.get(src)\n prevInner?.delete(prevTgt)\n if (prevInner && prevInner.size === 0) storage.data.delete(src)\n }\n storage.exclusive[src] = tgt\n } else {\n let list = storage.outgoing.get(src)\n if (!list) {\n list = []\n storage.outgoing.set(src, list)\n }\n if (!list.includes(tgt)) list.push(tgt)\n }\n\n if (data !== undefined) {\n let inner = storage.data.get(src)\n if (!inner) {\n inner = new Map<number, unknown>()\n storage.data.set(src, inner)\n }\n inner.set(tgt, data)\n }\n}\n\nexport function removeRelation(\n world: World,\n source: EntityId,\n rel: Relation,\n target: EntityId,\n): void {\n const state = getWorldState(world)\n if (state.readOnly) throw new Error('aiecsjs: cannot mutate a read-only world')\n const storage = state.relationStorage.get(rel.__id)\n if (!storage) return\n const src = (source as number) & state.options.indexMask\n const tgt = (target as number) & state.options.indexMask\n if (storage.exclusive) {\n if (src < storage.exclusive.length && storage.exclusive[src] === tgt) {\n storage.exclusive[src] = -1\n }\n } else {\n const list = storage.outgoing.get(src)\n if (list) {\n const idx = list.indexOf(tgt)\n if (idx >= 0) list.splice(idx, 1)\n if (list.length === 0) storage.outgoing.delete(src)\n }\n }\n const inner = storage.data.get(src)\n if (inner) {\n inner.delete(tgt)\n if (inner.size === 0) storage.data.delete(src)\n }\n}\n\nexport function getRelationTargets(\n world: World,\n source: EntityId,\n rel: Relation,\n): readonly EntityId[] {\n const state = getWorldState(world)\n const storage = state.relationStorage.get(rel.__id)\n if (!storage) return []\n const src = (source as number) & state.options.indexMask\n if (storage.exclusive) {\n if (src < storage.exclusive.length) {\n const tgt = storage.exclusive[src] ?? -1\n if (tgt >= 0) {\n const gen = state.generations[tgt] ?? 0\n return [packEid(tgt, gen, state.options)]\n }\n }\n return []\n }\n const list = storage.outgoing.get(src)\n if (!list) return []\n return list.map((tIdx) => {\n const gen = state.generations[tIdx] ?? 0\n return packEid(tIdx, gen, state.options)\n })\n}\n\n/**\n * Read the data payload attached to a relation edge.\n *\n * Returns the `data` value that was supplied to {@link addRelation} for the\n * `(source, rel, target)` triple, or `undefined` when:\n * - the relation has never been stored for this world,\n * - no edge from `source` to `target` via `rel` exists, or\n * - the edge was added without a data argument.\n *\n * **Slot-keying semantic (ABA caveat):** relation storage keys edges by raw\n * entity slot index (`entityId & indexMask`), not by the full packed EntityId\n * that includes the generation counter. This means that if entity A is\n * destroyed and a *different* entity B is later created in the same slot, B\n * will inherit any edges that A had — unless the destroy cleanup hook ran\n * (which it does when `destroyEntity` is called). Callers that cache a\n * source/target EntityId should validate liveness with `entityExists` before\n * calling `getRelationData` if slot recycling is a concern.\n */\nexport function getRelationData<T>(\n world: World,\n source: EntityId,\n rel: Relation<T>,\n target: EntityId,\n): T | undefined {\n const state = getWorldState(world)\n const storage = state.relationStorage.get(rel.__id)\n if (!storage) return undefined\n const src = (source as number) & state.options.indexMask\n const tgt = (target as number) & state.options.indexMask\n return storage.data.get(src)?.get(tgt) as T | undefined\n}\n\n// Cleanup hook: when an entity is destroyed, remove all relations involving it.\nregisterRelationsCleanup((state: WorldState, eid: EntityId) => {\n const e = (eid as number) & state.options.indexMask\n for (const storage of state.relationStorage.values()) {\n if (storage.exclusive) {\n if (e < storage.exclusive.length) storage.exclusive[e] = -1\n // Also clear any references TO this entity as target\n for (let i = 0; i < storage.exclusive.length; i++) {\n if (storage.exclusive[i] === e) storage.exclusive[i] = -1\n }\n }\n storage.outgoing.delete(e)\n for (const [src, list] of storage.outgoing) {\n const idx = list.indexOf(e)\n if (idx >= 0) {\n list.splice(idx, 1)\n if (list.length === 0) storage.outgoing.delete(src)\n }\n }\n // Clear data entries involving this entity. The outer key is the source\n // eid; entries whose source IS this entity drop entirely. Entries that\n // reference this entity as a target are pruned from each inner map.\n storage.data.delete(e)\n for (const [src, inner] of storage.data) {\n inner.delete(e)\n if (inner.size === 0) storage.data.delete(src)\n }\n }\n})\n"]}
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkAGHSWLNQ_cjs=require('./chunk-AGHSWLNQ.cjs');require('./chunk-4RPFOVQC.cjs');Object.defineProperty(exports,"createDeltaSerializer",{enumerable:true,get:function(){return chunkAGHSWLNQ_cjs.e}});Object.defineProperty(exports,"deserializeWorld",{enumerable:true,get:function(){return chunkAGHSWLNQ_cjs.b}});Object.defineProperty(exports,"fromJSON",{enumerable:true,get:function(){return chunkAGHSWLNQ_cjs.d}});Object.defineProperty(exports,"serializeWorld",{enumerable:true,get:function(){return chunkAGHSWLNQ_cjs.a}});Object.defineProperty(exports,"toJSON",{enumerable:true,get:function(){return chunkAGHSWLNQ_cjs.c}});//# sourceMappingURL=serialize.cjs.map
1
+ 'use strict';var chunkB777DQR7_cjs=require('./chunk-B777DQR7.cjs');require('./chunk-SJDWI3OZ.cjs');Object.defineProperty(exports,"createDeltaSerializer",{enumerable:true,get:function(){return chunkB777DQR7_cjs.e}});Object.defineProperty(exports,"deserializeWorld",{enumerable:true,get:function(){return chunkB777DQR7_cjs.b}});Object.defineProperty(exports,"fromJSON",{enumerable:true,get:function(){return chunkB777DQR7_cjs.d}});Object.defineProperty(exports,"serializeWorld",{enumerable:true,get:function(){return chunkB777DQR7_cjs.a}});Object.defineProperty(exports,"toJSON",{enumerable:true,get:function(){return chunkB777DQR7_cjs.c}});//# sourceMappingURL=serialize.cjs.map
2
2
  //# sourceMappingURL=serialize.cjs.map
package/dist/serialize.js CHANGED
@@ -1,2 +1,2 @@
1
- export{e as createDeltaSerializer,b as deserializeWorld,d as fromJSON,a as serializeWorld,c as toJSON}from'./chunk-QOKIEF7C.js';import'./chunk-L5CMKMIP.js';//# sourceMappingURL=serialize.js.map
1
+ export{e as createDeltaSerializer,b as deserializeWorld,d as fromJSON,a as serializeWorld,c as toJSON}from'./chunk-CTESP3XL.js';import'./chunk-F7KNZ27O.js';//# sourceMappingURL=serialize.js.map
2
2
  //# sourceMappingURL=serialize.js.map
package/dist/worker.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkAGHSWLNQ_cjs=require('./chunk-AGHSWLNQ.cjs'),chunk4RPFOVQC_cjs=require('./chunk-4RPFOVQC.cjs');var l=1095320899;function W(r){let e=chunk4RPFOVQC_cjs.i(r),o=chunkAGHSWLNQ_cjs.a(r);if(typeof SharedArrayBuffer>"u"){let n=new ArrayBuffer(o.byteLength);return new Uint8Array(n).set(o),{buffer:n,meta:p(e)}}let t=new SharedArrayBuffer(o.byteLength);return new Uint8Array(t).set(o),{buffer:t,meta:p(e)}}function b(r){m(r.meta);let e=new Uint8Array(r.buffer);return chunkAGHSWLNQ_cjs.b(e)}function S(r,e){let o=new Uint8Array(r),t=chunkAGHSWLNQ_cjs.b(o);if(e?.readOnly){let n=chunk4RPFOVQC_cjs.i(t);n.readOnly=true;}return t}function w(r){chunk4RPFOVQC_cjs.j(r.id)&&chunk4RPFOVQC_cjs.l(r);}function p(r){let e=[];for(let o of r.componentInfoByBit)o&&e.push({id:o.id,kind:o.kind,schema:o.schema});return {magic:l,formatVersion:1,aiecsjsVersion:chunk4RPFOVQC_cjs.a,indexBits:r.options.indexBits,generationBits:r.options.generationBits,maxComponents:r.options.maxComponents,maskWordCount:r.options.maskWordCount,capacity:r.capacity,componentSchemas:e}}function m(r){if(r.magic!==l)throw new Error("aiecsjs: invalid snapshot meta (wrong magic)");if(r.formatVersion!==1)throw new Error(`aiecsjs: unsupported snapshot format version ${r.formatVersion}`)}exports.adoptSnapshot=b;exports.attachWorld=S;exports.detachWorld=w;exports.transferableSnapshot=W;//# sourceMappingURL=worker.cjs.map
1
+ 'use strict';var chunkB777DQR7_cjs=require('./chunk-B777DQR7.cjs'),chunkSJDWI3OZ_cjs=require('./chunk-SJDWI3OZ.cjs');var l=1095320899;function W(r){let e=chunkSJDWI3OZ_cjs.i(r),o=chunkB777DQR7_cjs.a(r);if(typeof SharedArrayBuffer>"u"){let n=new ArrayBuffer(o.byteLength);return new Uint8Array(n).set(o),{buffer:n,meta:p(e)}}let t=new SharedArrayBuffer(o.byteLength);return new Uint8Array(t).set(o),{buffer:t,meta:p(e)}}function b(r){m(r.meta);let e=new Uint8Array(r.buffer);return chunkB777DQR7_cjs.b(e)}function S(r,e){let o=new Uint8Array(r),t=chunkB777DQR7_cjs.b(o);if(e?.readOnly){let n=chunkSJDWI3OZ_cjs.i(t);n.readOnly=true;}return t}function w(r){chunkSJDWI3OZ_cjs.j(r.id)&&chunkSJDWI3OZ_cjs.l(r);}function p(r){let e=[];for(let o of r.componentInfoByBit)o&&e.push({id:o.id,kind:o.kind,schema:o.schema});return {magic:l,formatVersion:1,aiecsjsVersion:chunkSJDWI3OZ_cjs.a,indexBits:r.options.indexBits,generationBits:r.options.generationBits,maxComponents:r.options.maxComponents,maskWordCount:r.options.maskWordCount,capacity:r.capacity,componentSchemas:e}}function m(r){if(r.magic!==l)throw new Error("aiecsjs: invalid snapshot meta (wrong magic)");if(r.formatVersion!==1)throw new Error(`aiecsjs: unsupported snapshot format version ${r.formatVersion}`)}exports.adoptSnapshot=b;exports.attachWorld=S;exports.detachWorld=w;exports.transferableSnapshot=W;//# sourceMappingURL=worker.cjs.map
2
2
  //# sourceMappingURL=worker.cjs.map
package/dist/worker.js CHANGED
@@ -1,2 +1,2 @@
1
- import {a,b as b$1}from'./chunk-QOKIEF7C.js';import {i,j,l as l$1,a as a$1}from'./chunk-L5CMKMIP.js';var l=1095320899;function W(r){let e=i(r),o=a(r);if(typeof SharedArrayBuffer>"u"){let n=new ArrayBuffer(o.byteLength);return new Uint8Array(n).set(o),{buffer:n,meta:p(e)}}let t=new SharedArrayBuffer(o.byteLength);return new Uint8Array(t).set(o),{buffer:t,meta:p(e)}}function b(r){m(r.meta);let e=new Uint8Array(r.buffer);return b$1(e)}function S(r,e){let o=new Uint8Array(r),t=b$1(o);if(e?.readOnly){let n=i(t);n.readOnly=true;}return t}function w(r){j(r.id)&&l$1(r);}function p(r){let e=[];for(let o of r.componentInfoByBit)o&&e.push({id:o.id,kind:o.kind,schema:o.schema});return {magic:l,formatVersion:1,aiecsjsVersion:a$1,indexBits:r.options.indexBits,generationBits:r.options.generationBits,maxComponents:r.options.maxComponents,maskWordCount:r.options.maskWordCount,capacity:r.capacity,componentSchemas:e}}function m(r){if(r.magic!==l)throw new Error("aiecsjs: invalid snapshot meta (wrong magic)");if(r.formatVersion!==1)throw new Error(`aiecsjs: unsupported snapshot format version ${r.formatVersion}`)}export{b as adoptSnapshot,S as attachWorld,w as detachWorld,W as transferableSnapshot};//# sourceMappingURL=worker.js.map
1
+ import {a,b as b$1}from'./chunk-CTESP3XL.js';import {i,j,l as l$1,a as a$1}from'./chunk-F7KNZ27O.js';var l=1095320899;function W(r){let e=i(r),o=a(r);if(typeof SharedArrayBuffer>"u"){let n=new ArrayBuffer(o.byteLength);return new Uint8Array(n).set(o),{buffer:n,meta:p(e)}}let t=new SharedArrayBuffer(o.byteLength);return new Uint8Array(t).set(o),{buffer:t,meta:p(e)}}function b(r){m(r.meta);let e=new Uint8Array(r.buffer);return b$1(e)}function S(r,e){let o=new Uint8Array(r),t=b$1(o);if(e?.readOnly){let n=i(t);n.readOnly=true;}return t}function w(r){j(r.id)&&l$1(r);}function p(r){let e=[];for(let o of r.componentInfoByBit)o&&e.push({id:o.id,kind:o.kind,schema:o.schema});return {magic:l,formatVersion:1,aiecsjsVersion:a$1,indexBits:r.options.indexBits,generationBits:r.options.generationBits,maxComponents:r.options.maxComponents,maskWordCount:r.options.maskWordCount,capacity:r.capacity,componentSchemas:e}}function m(r){if(r.magic!==l)throw new Error("aiecsjs: invalid snapshot meta (wrong magic)");if(r.formatVersion!==1)throw new Error(`aiecsjs: unsupported snapshot format version ${r.formatVersion}`)}export{b as adoptSnapshot,S as attachWorld,w as detachWorld,W as transferableSnapshot};//# sourceMappingURL=worker.js.map
2
2
  //# sourceMappingURL=worker.js.map