@codehz/ecs 0.3.15 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.mts CHANGED
@@ -1,793 +1,2 @@
1
- //#region src/entity.d.ts
2
- /**
3
- * Unique symbol brand for associating component type information with EntityId
4
- */
5
- declare const __componentTypeMarker: unique symbol;
6
- /**
7
- * Unique symbol brand for tagging the kind of EntityId (e.g., 'component', 'entity-relation')
8
- */
9
- declare const __entityIdTypeTag: unique symbol;
10
- /**
11
- * Entity ID type for ECS architecture
12
- * Based on 52-bit integers within safe integer range
13
- * - Component IDs: 1-1023
14
- * - Entity IDs: 1024+
15
- * - Relation IDs: negative numbers encoding component and entity associations
16
- */
17
- type EntityId<T = void, U$1 = unknown> = number & {
18
- readonly [__componentTypeMarker]: T;
19
- readonly [__entityIdTypeTag]: U$1;
20
- };
21
- type ComponentId<T = void> = EntityId<T, "component">;
22
- type EntityRelationId<T = void> = EntityId<T, "entity-relation">;
23
- type ComponentRelationId<T = void> = EntityId<T, "component-relation">;
24
- type WildcardRelationId<T = void> = EntityId<T, "wildcard-relation">;
25
- type RelationId<T = void> = EntityRelationId<T> | ComponentRelationId<T> | WildcardRelationId<T>;
26
- /**
27
- * Type for relation ID based on component and target types
28
- */
29
- type RelationIdType<T, R> = R extends ComponentId<infer U> ? U extends void ? ComponentRelationId<T> : ComponentRelationId<T extends void ? U : T> : R extends EntityId<any> ? EntityRelationId<T> : never;
30
- /**
31
- * Create a relation ID by associating a component with another ID (entity or component)
32
- * @param componentId The component ID (0-1023)
33
- * @param targetId The target ID (entity, component, or '*' for wildcard)
34
- */
35
- declare function relation<T>(componentId: ComponentId<T>, targetId: "*"): WildcardRelationId<T>;
36
- declare function relation<T, R extends EntityId<any>>(componentId: ComponentId<T>, targetId: R): RelationIdType<T, R>;
37
- /**
38
- * Check if an ID is a component ID
39
- */
40
- declare function isComponentId<T>(id: EntityId<T>): id is ComponentId<T>;
41
- /**
42
- * Check if an ID is an entity ID
43
- */
44
- declare function isEntityId<T>(id: EntityId<T>): id is EntityId<T>;
45
- /**
46
- * Check if an ID is a relation ID
47
- */
48
- declare function isRelationId<T>(id: EntityId<T>): id is RelationId<T>;
49
- /**
50
- * Check if an ID is a wildcard relation id
51
- */
52
- declare function isWildcardRelationId<T>(id: EntityId<T>): id is WildcardRelationId<T>;
53
- /**
54
- * Decode a relation ID into component and target IDs
55
- * @param relationId The relation ID (must be negative)
56
- * @returns Object with componentId, targetId, and relation type
57
- */
58
- declare function decodeRelationId(relationId: RelationId<any>): {
59
- componentId: ComponentId<any>;
60
- targetId: EntityId<any>;
61
- type: "entity" | "component" | "wildcard";
62
- };
63
- /**
64
- * Component options that define intrinsic properties
65
- */
66
- interface ComponentOptions {
67
- /**
68
- * Optional name for the component (for serialization/debugging)
69
- */
70
- name?: string;
71
- /**
72
- * If true, an entity can have at most one relation per base component.
73
- * When adding a new relation with the same base component, any existing relations
74
- * with that base component are automatically removed.
75
- * Only applicable to relation components.
76
- */
77
- exclusive?: boolean;
78
- /**
79
- * If true, when a relation target entity is deleted, all entities that reference
80
- * it through this component will also be deleted (cascade delete).
81
- * Only applicable to entity-relation components.
82
- */
83
- cascadeDelete?: boolean;
84
- /**
85
- * If true, relations with this component will not cause archetype fragmentation.
86
- * Entities with different target entities for this relation component will be stored
87
- * in the same archetype, preventing fragmentation when there are many different targets.
88
- * Only applicable to relation components.
89
- * Inspired by Flecs' DontFragment trait.
90
- */
91
- dontFragment?: boolean;
92
- }
93
- /**
94
- * Allocate a new component ID from the global allocator.
95
- * @param nameOrOptions Optional name for the component (for serialization/debugging) or options object
96
- * @returns The allocated component ID
97
- * @example
98
- * // Just a name
99
- * const Position = component<Position>("Position");
100
- *
101
- * // With options
102
- * const ChildOf = component({ exclusive: true, cascadeDelete: true });
103
- *
104
- * // With name and options
105
- * const ChildOf = component({ name: "ChildOf", exclusive: true });
106
- */
107
- declare function component<T = void>(nameOrOptions?: string | ComponentOptions): ComponentId<T>;
108
- /**
109
- * Get a component ID by its registered name
110
- * @param name The component name
111
- * @returns The component ID if found, undefined otherwise
112
- */
113
- declare function getComponentIdByName(name: string): ComponentId<any> | undefined;
114
- /** Get a component name by its ID
115
- * @param id The component ID
116
- * @returns The component name if found, undefined otherwise
117
- */
118
- declare function getComponentNameById(id: ComponentId<any>): string | undefined;
119
- //#endregion
120
- //#region src/types.d.ts
121
- /**
122
- * Hook types for component lifecycle events
123
- */
124
- interface LifecycleHook<T = unknown> {
125
- /**
126
- * Called when a component is added to an entity
127
- */
128
- on_init?: (entityId: EntityId, componentType: EntityId<T>, component: T) => void;
129
- /**
130
- * Called when a component is added to an entity
131
- */
132
- on_set?: (entityId: EntityId, componentType: EntityId<T>, component: T) => void;
133
- /**
134
- * Called when a component is deleted from an entity
135
- */
136
- on_remove?: (entityId: EntityId, componentType: EntityId<T>, component: T) => void;
137
- }
138
- type ComponentType<T> = EntityId<T> | OptionalEntityId<T>;
139
- type OptionalEntityId<T> = {
140
- optional: EntityId<T>;
141
- };
142
- type ComponentTypeToData<T> = T extends {
143
- optional: infer U;
144
- } ? {
145
- value: ComponentTypeToData<U>;
146
- } | undefined : T extends WildcardRelationId<infer U> ? [EntityId<unknown>, U][] : T extends EntityId<infer U> ? U : never;
147
- /**
148
- * Type helper for component tuples extracted from EntityId array
149
- */
150
- type ComponentTuple<T extends readonly ComponentType<any>[]> = { readonly [K in keyof T]: ComponentTypeToData<T[K]> };
151
- //#endregion
152
- //#region src/archetype.d.ts
153
- /**
154
- * Archetype class for ECS architecture
155
- * Represents a group of entities that share the same set of components
156
- * Optimized for fast iteration and component access
157
- */
158
- declare class Archetype {
159
- /**
160
- * The component types that define this archetype
161
- */
162
- readonly componentTypes: EntityId<any>[];
163
- /**
164
- * List of entities in this archetype
165
- */
166
- private entities;
167
- /**
168
- * Component data storage - maps component type to array of component data
169
- * Each array index corresponds to the entity index in the entities array
170
- */
171
- private componentData;
172
- /**
173
- * Reverse mapping from entity to its index in this archetype
174
- */
175
- private entityToIndex;
176
- /**
177
- * Reference to dontFragment relations storage from World
178
- * This allows entities with different relation targets to share the same archetype
179
- * Stored in World to avoid migration overhead when entities change archetypes
180
- */
181
- private dontFragmentRelations;
182
- /**
183
- * Cache for pre-computed component data sources to avoid repeated calculations
184
- * For regular components: data array
185
- * For wildcards: matching relation types array
186
- */
187
- private componentDataSourcesCache;
188
- /**
189
- * Create a new archetype with the specified component types
190
- * @param componentTypes The component types that define this archetype
191
- * @param dontFragmentRelations Reference to the World's dontFragmentRelations storage
192
- */
193
- constructor(componentTypes: EntityId<any>[], dontFragmentRelations: Map<EntityId, Map<EntityId<any>, any>>);
194
- /**
195
- * Get the number of entities in this archetype
196
- */
197
- get size(): number;
198
- /**
199
- * Check if this archetype matches the given component types
200
- * @param componentTypes The component types to check
201
- */
202
- matches(componentTypes: EntityId<any>[]): boolean;
203
- /**
204
- * Add an entity to this archetype with initial component data
205
- * @param entityId The entity to add
206
- * @param componentData Map of component type to component data (includes both regular and dontFragment components)
207
- */
208
- addEntity(entityId: EntityId, componentData: Map<EntityId<any>, any>): void;
209
- /**
210
- * Get all component data for a specific entity
211
- * @param entityId The entity to get data for
212
- * @returns Map of component type to component data (includes both regular and dontFragment components)
213
- */
214
- getEntity(entityId: EntityId): Map<EntityId<any>, any> | undefined;
215
- /**
216
- * Dump all entities and their component data in this archetype
217
- * @returns Array of objects with entity and component data (includes both regular and dontFragment components)
218
- */
219
- dump(): Array<{
220
- entity: EntityId;
221
- components: Map<EntityId<any>, any>;
222
- }>;
223
- /**
224
- * Remove an entity from this archetype
225
- * @param entityId The entity to remove
226
- * @returns The component data of the removed entity (includes both regular and dontFragment components)
227
- */
228
- removeEntity(entityId: EntityId): Map<EntityId<any>, any> | undefined;
229
- /**
230
- * Check if an entity is in this archetype
231
- * @param entityId The entity to check
232
- */
233
- exists(entityId: EntityId): boolean;
234
- /**
235
- * Get component data for a specific entity and wildcard relation type
236
- * Returns an array of all matching relation instances
237
- * @param entityId The entity
238
- * @param componentType The wildcard relation type
239
- */
240
- get<T>(entityId: EntityId, componentType: WildcardRelationId<T>): [EntityId<unknown>, any][];
241
- /**
242
- * Get component data for a specific entity and component type
243
- * @param entityId The entity
244
- * @param componentType The component type
245
- */
246
- get<T>(entityId: EntityId, componentType: EntityId<T>): T;
247
- /**
248
- * Set component data for a specific entity and component type
249
- * @param entityId The entity
250
- * @param componentType The component type
251
- * @param data The component data
252
- */
253
- set<T>(entityId: EntityId, componentType: EntityId<T>, data: T): void;
254
- /**
255
- * Get all entities in this archetype
256
- */
257
- getEntities(): EntityId[];
258
- /**
259
- * Get the mapping of entities to their indices in this archetype
260
- */
261
- getEntityToIndexMap(): Map<EntityId, number>;
262
- /**
263
- * Get component data for all entities of a specific component type
264
- * @param componentType The component type
265
- */
266
- getComponentData<T>(componentType: EntityId<T>): T[];
267
- /**
268
- * Get optional component data for all entities of a specific component type
269
- * @param componentType The component type
270
- * @returns An array of component data or undefined if not present
271
- */
272
- getOptionalComponentData<T>(componentType: EntityId<T>): T[] | undefined;
273
- /**
274
- * Helper: compute or return cached data sources for provided componentTypes
275
- */
276
- private getCachedComponentDataSources;
277
- /**
278
- * Build cache key for component types
279
- */
280
- private buildCacheKey;
281
- /**
282
- * Get data source for a single component type
283
- */
284
- private getComponentDataSource;
285
- /**
286
- * Get data source for wildcard relations
287
- */
288
- private getWildcardRelationDataSource;
289
- /**
290
- * Helper: build component tuples for a specific entity index using precomputed data sources
291
- */
292
- private buildComponentsForIndex;
293
- /**
294
- * Build a single component value from its data source
295
- */
296
- private buildSingleComponent;
297
- /**
298
- * Build wildcard relation value from matching relations
299
- */
300
- private buildWildcardRelationValue;
301
- /**
302
- * Build regular component value from data source
303
- */
304
- private buildRegularComponentValue;
305
- /**
306
- * Get entities with their component data for specified component types
307
- * Optimized for bulk component access with pre-computed indices
308
- * @param componentTypes Array of component types to retrieve
309
- * @returns Array of objects with entity and component data
310
- */
311
- getEntitiesWithComponents<const T extends readonly ComponentType<any>[]>(componentTypes: T): Array<{
312
- entity: EntityId;
313
- components: ComponentTuple<T>;
314
- }>;
315
- /**
316
- * Iterate over entities with their component data for specified component types
317
- * implemented as a generator returning each entity/components pair lazily
318
- * @param componentTypes Array of component types to retrieve
319
- */
320
- iterateWithComponents<const T extends readonly ComponentType<any>[]>(componentTypes: T): IterableIterator<[EntityId, ...ComponentTuple<T>]>;
321
- /**
322
- * Iterate over entities with their component data for specified component types
323
- * Optimized for bulk component access
324
- * @param componentTypes Array of component types to retrieve
325
- * @param callback Function called for each entity with its components
326
- */
327
- forEachWithComponents<const T extends readonly ComponentType<any>[]>(componentTypes: T, callback: (entity: EntityId, ...components: ComponentTuple<T>) => void): void;
328
- /**
329
- * Iterate over all entities with their component data
330
- * @param callback Function called for each entity with its component data
331
- */
332
- forEach(callback: (entityId: EntityId, components: Map<EntityId<any>, any>) => void): void;
333
- /**
334
- * Check if any entity in this archetype has a relation matching the given component ID
335
- * This includes both regular relations in componentTypes and dontFragment relations
336
- * @param componentId The component ID to match
337
- * @returns true if any entity has a matching relation
338
- */
339
- hasRelationWithComponentId(componentId: EntityId<any>): boolean;
340
- }
341
- //#endregion
342
- //#region src/changeset.d.ts
343
- /**
344
- * @internal Represents a set of component changes to be applied to an entity
345
- */
346
- declare class ComponentChangeset {
347
- readonly adds: Map<EntityId<any>, any>;
348
- readonly removes: Set<EntityId<any>>;
349
- /**
350
- * Add a component to the changeset
351
- */
352
- set<T>(componentType: EntityId<T>, component: T): void;
353
- /**
354
- * Remove a component from the changeset
355
- */
356
- delete<T>(componentType: EntityId<T>): void;
357
- /**
358
- * Check if the changeset has any changes
359
- */
360
- hasChanges(): boolean;
361
- /**
362
- * Clear all changes
363
- */
364
- clear(): void;
365
- /**
366
- * Merge another changeset into this one
367
- */
368
- merge(other: ComponentChangeset): void;
369
- /**
370
- * Apply the changeset to existing components and return the final state
371
- */
372
- applyTo(existingComponents: Map<EntityId<any>, any>): Map<EntityId<any>, any>;
373
- /**
374
- * Get the final component types after applying the changeset
375
- * @param existingComponentTypes - The current component types on the entity
376
- * @returns The final component types or undefined if no changes
377
- */
378
- getFinalComponentTypes(existingComponentTypes: EntityId<any>[]): EntityId<any>[] | undefined;
379
- }
380
- //#endregion
381
- //#region src/command-buffer.d.ts
382
- /**
383
- * Command for deferred execution
384
- */
385
- interface Command {
386
- type: "set" | "delete" | "destroy";
387
- entityId: EntityId;
388
- componentType?: EntityId<any>;
389
- component?: any;
390
- }
391
- //#endregion
392
- //#region src/query-filter.d.ts
393
- /**
394
- * Filter options for queries
395
- */
396
- interface QueryFilter {
397
- negativeComponentTypes?: EntityId<any>[];
398
- }
399
- //#endregion
400
- //#region src/query.d.ts
401
- /**
402
- * Query class for efficient entity queries with cached archetypes
403
- */
404
- declare class Query {
405
- private world;
406
- private componentTypes;
407
- private filter;
408
- private cachedArchetypes;
409
- private isDisposed;
410
- constructor(world: World<any[]>, componentTypes: EntityId<any>[], filter?: QueryFilter);
411
- /**
412
- * Check if query is disposed and throw error if so
413
- */
414
- private ensureNotDisposed;
415
- /**
416
- * Get all entities matching the query
417
- */
418
- getEntities(): EntityId[];
419
- /**
420
- * Get entities with their component data
421
- * @param componentTypes Array of component types to retrieve
422
- * @returns Array of objects with entity and component data
423
- */
424
- getEntitiesWithComponents<const T extends readonly ComponentType<any>[]>(componentTypes: T): Array<{
425
- entity: EntityId;
426
- components: ComponentTuple<T>;
427
- }>;
428
- /**
429
- * Iterate over entities with their component data
430
- * @param componentTypes Array of component types to retrieve
431
- * @param callback Function called for each entity with its components
432
- */
433
- forEach<const T extends readonly ComponentType<any>[]>(componentTypes: T, callback: (entity: EntityId, ...components: ComponentTuple<T>) => void): void;
434
- /**
435
- * Iterate over entities with their component data (generator)
436
- * @param componentTypes Array of component types to retrieve
437
- */
438
- iterate<const T extends readonly ComponentType<any>[]>(componentTypes: T): IterableIterator<[EntityId, ...ComponentTuple<T>]>;
439
- /**
440
- * Get component data arrays for all matching entities
441
- * @param componentType The component type to retrieve
442
- * @returns Array of component data for all matching entities
443
- */
444
- getComponentData<T>(componentType: EntityId<T>): T[];
445
- /**
446
- * Update the cached archetypes
447
- * Called when new archetypes are created
448
- */
449
- updateCache(): void;
450
- /**
451
- * Check if a new archetype matches this query and add to cache if it does
452
- */
453
- checkNewArchetype(archetype: Archetype): void;
454
- /**
455
- * Remove an archetype from the cached archetypes
456
- */
457
- removeArchetype(archetype: Archetype): void;
458
- /**
459
- * Dispose the query and disconnect from world
460
- */
461
- /**
462
- * Request disposal of this query.
463
- * This will decrement the world's reference count for the query.
464
- * The query will only be fully disposed when the ref count reaches zero.
465
- */
466
- dispose(): void;
467
- /**
468
- * Internal full dispose called by World when refCount reaches zero.
469
- */
470
- _disposeInternal(): void;
471
- /**
472
- * Symbol.dispose implementation for automatic resource management
473
- */
474
- [Symbol.dispose](): void;
475
- /**
476
- * Check if the query has been disposed
477
- */
478
- get disposed(): boolean;
479
- }
480
- //#endregion
481
- //#region src/system.d.ts
482
- /**
483
- * Base System interface
484
- */
485
- interface System<UpdateParams extends any[] = []> {
486
- /**
487
- * Update the system
488
- */
489
- update(...params: UpdateParams): void | Promise<void>;
490
- /**
491
- * Dependencies of this system (systems that must run before this one)
492
- */
493
- readonly dependencies?: readonly System<UpdateParams>[];
494
- }
495
- //#endregion
496
- //#region src/world.d.ts
497
- /**
498
- * World class for ECS architecture
499
- * Manages entities, components, and systems
500
- */
501
- declare class World<UpdateParams extends any[] = []> {
502
- /** Manages allocation and deallocation of entity IDs */
503
- private entityIdManager;
504
- /** Array of all archetypes in the world */
505
- private archetypes;
506
- /** Maps archetype signatures (component type signatures) to archetype instances */
507
- private archetypeBySignature;
508
- /** Maps entity IDs to their current archetype */
509
- private entityToArchetype;
510
- /** Maps component types to arrays of archetypes that contain them */
511
- private archetypesByComponent;
512
- /** Tracks which entities reference each entity as a component type */
513
- private entityReferences;
514
- /** Storage for dontFragment relations - maps entity ID to a map of relation type to component data */
515
- private dontFragmentRelations;
516
- /** Array of all active queries for archetype change notifications */
517
- private queries;
518
- /** Cache for queries keyed by component types and filter signatures */
519
- private queryCache;
520
- /** Schedules and executes systems in dependency order */
521
- private systemScheduler;
522
- /** Buffers structural changes for deferred execution */
523
- private commandBuffer;
524
- /** Stores lifecycle hooks for component and relation events */
525
- private hooks;
526
- /**
527
- * Create a new World.
528
- * If an optional snapshot object is provided (previously produced by `world.serialize()`),
529
- * the world will be restored from that snapshot. The snapshot may contain non-JSON values.
530
- */
531
- constructor(snapshot?: SerializedWorld);
532
- /**
533
- * Generate a signature string for component types array
534
- * @returns A string signature for the component types
535
- */
536
- private createArchetypeSignature;
537
- /**
538
- * Create a new entity
539
- * @returns The ID of the newly created entity
540
- */
541
- new(): EntityId;
542
- /**
543
- * Destroy an entity and remove all its components (immediate execution)
544
- */
545
- private destroyEntityImmediate;
546
- /**
547
- * Check if an entity exists
548
- */
549
- exists(entityId: EntityId): boolean;
550
- /**
551
- * Add a component to an entity (deferred)
552
- */
553
- set(entityId: EntityId, componentType: EntityId<void>): void;
554
- set<T>(entityId: EntityId, componentType: EntityId<T>, component: NoInfer<T>): void;
555
- /**
556
- * Remove a component from an entity (deferred)
557
- */
558
- remove<T>(entityId: EntityId, componentType: EntityId<T>): void;
559
- /**
560
- * Destroy an entity and remove all its components (deferred)
561
- */
562
- delete(entityId: EntityId): void;
563
- /**
564
- * Check if an entity has a specific component
565
- */
566
- has<T>(entityId: EntityId, componentType: EntityId<T>): boolean;
567
- /**
568
- * Get component data for a specific entity and wildcard relation type
569
- * Returns an array of all matching relation instances
570
- * @param entityId The entity
571
- * @param componentType The wildcard relation type
572
- * @returns Array of [targetEntityId, componentData] pairs for all matching relations
573
- */
574
- get<T>(entityId: EntityId, componentType: WildcardRelationId<T>): [EntityId<unknown>, T][];
575
- /**
576
- * Get component data for a specific entity and component type
577
- * @param entityId The entity
578
- * @param componentType The component type
579
- * @returns The component data
580
- */
581
- get<T>(entityId: EntityId, componentType: EntityId<T>): T;
582
- /**
583
- * Register a system with optional dependencies
584
- */
585
- registerSystem(system: System<UpdateParams>, additionalDeps?: System<UpdateParams>[]): void;
586
- /**
587
- * Register a lifecycle hook for component or wildcard relation events
588
- */
589
- hook<T>(componentType: EntityId<T>, hook: LifecycleHook<T>): void;
590
- /**
591
- * Unregister a lifecycle hook for component or wildcard relation events
592
- */
593
- unhook<T>(componentType: EntityId<T>, hook: LifecycleHook<T>): void;
594
- /**
595
- * Update the world (run all systems in dependency order)
596
- * This function is synchronous when all systems are synchronous,
597
- * and asynchronous (returns a Promise) when any system is asynchronous.
598
- */
599
- update(...params: UpdateParams): Promise<void> | void;
600
- /**
601
- * Execute all deferred commands immediately without running systems
602
- */
603
- sync(): void;
604
- /**
605
- * Create a cached query for efficient entity lookups
606
- * @returns A Query object for the specified component types and filter
607
- */
608
- createQuery(componentTypes: EntityId<any>[], filter?: QueryFilter): Query;
609
- /**
610
- * @internal Register a query for archetype update notifications
611
- */
612
- _registerQuery(query: Query): void;
613
- /**
614
- * @internal Unregister a query
615
- */
616
- _unregisterQuery(query: Query): void;
617
- /**
618
- * Release a query reference obtained from createQuery.
619
- * Decrements the refCount and fully disposes the query when it reaches zero.
620
- */
621
- releaseQuery(query: Query): void;
622
- /**
623
- * @internal Get archetypes that match specific component types (for internal use by queries)
624
- */
625
- getMatchingArchetypes(componentTypes: EntityId<any>[]): Archetype[];
626
- /**
627
- * Query entities with specific components
628
- * @returns Array of entity IDs that have all the specified components
629
- */
630
- query(componentTypes: EntityId<any>[]): EntityId[];
631
- query<const T extends readonly EntityId<any>[]>(componentTypes: T, includeComponents: true): Array<{
632
- entity: EntityId;
633
- components: ComponentTuple<T>;
634
- }>;
635
- /**
636
- * @internal Execute commands for a single entity (for internal use by CommandBuffer)
637
- * @returns ComponentChangeset describing the changes made
638
- */
639
- executeEntityCommands(entityId: EntityId, commands: Command[]): ComponentChangeset;
640
- /**
641
- * Process commands and populate the changeset
642
- */
643
- private processCommands;
644
- /**
645
- * Process a set command, handling exclusive relations
646
- */
647
- private processSetCommand;
648
- /**
649
- * Remove all relations with the same base component (for exclusive relations)
650
- */
651
- private removeExclusiveRelations;
652
- private isRelationWithComponent;
653
- /**
654
- * Process a delete command, handling wildcard relations
655
- */
656
- private processDeleteCommand;
657
- /**
658
- * Remove all relations matching a wildcard component ID
659
- */
660
- private removeWildcardRelations;
661
- /**
662
- * Remove a single component from an entity immediately, handling dontFragment relations correctly.
663
- * Used by destroyEntityImmediate for non-cascade relation cleanup.
664
- */
665
- private removeComponentImmediate;
666
- /**
667
- * Apply changeset to entity, moving to new archetype if needed
668
- * @returns Map of removed components with their data
669
- */
670
- private applyChangeset;
671
- /**
672
- * Move entity to a new archetype with updated components
673
- */
674
- private moveEntityToNewArchetype;
675
- /**
676
- * Update entity in same archetype (no archetype change needed)
677
- */
678
- private updateEntityInSameArchetype;
679
- /**
680
- * Apply dontFragment relation changes directly to World's storage
681
- * This is much more efficient than the removeEntity + addEntity approach
682
- */
683
- private applyDontFragmentChanges;
684
- /**
685
- * Update entity reference tracking based on changeset
686
- */
687
- private updateEntityReferences;
688
- /**
689
- * Get or create an archetype for the given component types
690
- * Filters out dontFragment relations from the archetype signature
691
- * @returns The archetype for the given component types (excluding dontFragment relations)
692
- */
693
- private ensureArchetype;
694
- /**
695
- * Compare two arrays of component types for equality (order-independent)
696
- */
697
- private areComponentTypesEqual;
698
- /**
699
- * Filter out dontFragment relations from component types, but keep wildcard markers
700
- */
701
- private filterRegularComponentTypes;
702
- /**
703
- * Create a new archetype and register it with all tracking structures
704
- */
705
- private createNewArchetype;
706
- /**
707
- * Register archetype in the component-to-archetype index
708
- */
709
- private registerArchetypeInComponentIndex;
710
- /**
711
- * Notify all queries to check the new archetype
712
- */
713
- private notifyQueriesOfNewArchetype;
714
- /**
715
- * Add a component reference to the reverse index when an entity is used as a component type
716
- * @param sourceEntityId The entity that has the component
717
- * @param componentType The component type (which may be an entity ID used as component type)
718
- * @param targetEntityId The entity being used as component type
719
- */
720
- private trackEntityReference;
721
- /**
722
- * Remove a component reference from the reverse index
723
- * @param sourceEntityId The entity that has the component
724
- * @param componentType The component type
725
- * @param targetEntityId The entity being used as component type
726
- */
727
- private untrackEntityReference;
728
- /**
729
- * Get all component references where a target entity is used as a component type
730
- * @param targetEntityId The target entity
731
- * @returns A MultiMap of sourceEntityId to componentTypes that reference the target entity
732
- */
733
- private getEntityReferences;
734
- /**
735
- * Check if an archetype's signature references a specific entity
736
- * (via entity-relation targeting the entity, or using entity as component type)
737
- */
738
- private archetypeReferencesEntity;
739
- /**
740
- * Cleanup empty archetypes that reference a specific deleted entity
741
- * Only removes archetypes whose component types reference the entity
742
- */
743
- private cleanupArchetypesReferencingEntity;
744
- /**
745
- * Remove an empty archetype from all internal data structures
746
- */
747
- private cleanupEmptyArchetype;
748
- /**
749
- * Remove archetype from the main archetypes list
750
- */
751
- private removeArchetypeFromList;
752
- /**
753
- * Remove archetype from the signature-to-archetype map
754
- */
755
- private removeArchetypeFromSignatureMap;
756
- /**
757
- * Remove archetype from the component-to-archetypes index
758
- */
759
- private removeArchetypeFromComponentIndex;
760
- /**
761
- * Remove archetype from all queries
762
- */
763
- private removeArchetypeFromQueries;
764
- /**
765
- * Execute component lifecycle hooks for added and removed components
766
- */
767
- private triggerLifecycleHooks;
768
- /**
769
- * Convert the world into a plain snapshot object.
770
- * This returns an in-memory structure and does not perform JSON stringification.
771
- * Component values are stored as-is (they may be non-JSON-serializable).
772
- */
773
- serialize(): SerializedWorld;
774
- }
775
- type SerializedWorld = {
776
- version: number;
777
- entityManager: any;
778
- entities: SerializedEntity[];
779
- };
780
- type SerializedEntity = {
781
- id: number;
782
- components: SerializedComponent[];
783
- };
784
- type SerializedComponent = {
785
- type: number | string | {
786
- component: string;
787
- target: number | string;
788
- };
789
- value: any;
790
- };
791
- //#endregion
792
- export { type ComponentId, type ComponentOptions, type ComponentRelationId, type ComponentTuple, type ComponentType, type EntityId, type EntityRelationId, type LifecycleHook, Query, type RelationId, type SerializedWorld, type System, type WildcardRelationId, World, component, decodeRelationId, getComponentIdByName, getComponentNameById, isComponentId, isEntityId, isRelationId, isWildcardRelationId, relation };
793
- //# sourceMappingURL=index.d.mts.map
1
+ import { S as relation, _ as getComponentNameById, a as ComponentType, b as isRelationId, c as ComponentOptions, d as EntityRelationId, f as RelationId, g as getComponentIdByName, h as decodeRelationId, i as ComponentTuple, l as ComponentRelationId, m as component, n as World, o as LifecycleHook, p as WildcardRelationId, r as Query, s as ComponentId, t as SerializedWorld, u as EntityId, v as isComponentId, x as isWildcardRelationId, y as isEntityId } from "./world.mjs";
2
+ export { type ComponentId, type ComponentOptions, type ComponentRelationId, type ComponentTuple, type ComponentType, type EntityId, type EntityRelationId, type LifecycleHook, Query, type RelationId, type SerializedWorld, type WildcardRelationId, World, component, decodeRelationId, getComponentIdByName, getComponentNameById, isComponentId, isEntityId, isRelationId, isWildcardRelationId, relation };