@relu-interactives/spatial-ecs 0.2.17 → 0.2.21

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 (54) hide show
  1. package/dist/{System-BeuJ1xt5.d.cts → System-me3iAcMF.d.cts} +150 -1
  2. package/dist/{System-BeuJ1xt5.d.ts → System-me3iAcMF.d.ts} +150 -1
  3. package/dist/{Video-Cym2C52L.d.ts → Video-DHnxjGhW.d.ts} +17 -3
  4. package/dist/{Video-D4B-z74P.d.cts → Video-U9hAnf9y.d.cts} +17 -3
  5. package/dist/{chunk-EPK6MA7X.js → chunk-5U3YS4JD.js} +1809 -8
  6. package/dist/chunk-5U3YS4JD.js.map +1 -0
  7. package/dist/{chunk-GRUK5TNL.js → chunk-AXRCGF63.js} +3 -3
  8. package/dist/{chunk-GRUK5TNL.js.map → chunk-AXRCGF63.js.map} +1 -1
  9. package/dist/{chunk-CJW6K3CL.js → chunk-K6KMKKJ6.js} +62 -5
  10. package/dist/chunk-K6KMKKJ6.js.map +1 -0
  11. package/dist/{chunk-FTIQQK62.js → chunk-V7BNVTJW.js} +50 -3
  12. package/dist/chunk-V7BNVTJW.js.map +1 -0
  13. package/dist/{chunk-R2WMVXZZ.js → chunk-ZXGHKX7N.js} +5 -3
  14. package/dist/chunk-ZXGHKX7N.js.map +1 -0
  15. package/dist/components/index.cjs +47 -0
  16. package/dist/components/index.cjs.map +1 -1
  17. package/dist/components/index.d.cts +3 -2
  18. package/dist/components/index.d.ts +3 -2
  19. package/dist/components/index.js +1 -1
  20. package/dist/docs/guide/components/material.md +4 -0
  21. package/dist/docs/guide/components/physics.md +10 -0
  22. package/dist/docs/guide/getting-started/editor/assets-browser.md +1 -1
  23. package/dist/docs/guide/prefabs.md +152 -0
  24. package/dist/docs/guide/world-api.md +1 -1
  25. package/dist/factories/index.cjs +136 -64
  26. package/dist/factories/index.cjs.map +1 -1
  27. package/dist/factories/index.d.cts +5 -4
  28. package/dist/factories/index.d.ts +5 -4
  29. package/dist/factories/index.js +3 -3
  30. package/dist/{index-BfoOC2CG.d.cts → index-CZo5I5Gs.d.cts} +76 -4
  31. package/dist/{index-BoJ3_6a3.d.ts → index-D7FSg0Au.d.ts} +76 -4
  32. package/dist/index.cjs +6386 -4962
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +313 -7
  35. package/dist/index.d.ts +313 -7
  36. package/dist/index.js +407 -926
  37. package/dist/index.js.map +1 -1
  38. package/dist/systems/index.cjs +1386 -0
  39. package/dist/systems/index.cjs.map +1 -1
  40. package/dist/systems/index.d.cts +2 -2
  41. package/dist/systems/index.d.ts +2 -2
  42. package/dist/systems/index.js +3 -3
  43. package/dist/types.d.cts +1 -1
  44. package/dist/types.d.ts +1 -1
  45. package/dist/worldSnapshotUtils.cjs +3 -1
  46. package/dist/worldSnapshotUtils.cjs.map +1 -1
  47. package/dist/worldSnapshotUtils.d.cts +1 -1
  48. package/dist/worldSnapshotUtils.d.ts +1 -1
  49. package/dist/worldSnapshotUtils.js +1 -1
  50. package/package.json +4 -2
  51. package/dist/chunk-CJW6K3CL.js.map +0 -1
  52. package/dist/chunk-EPK6MA7X.js.map +0 -1
  53. package/dist/chunk-FTIQQK62.js.map +0 -1
  54. package/dist/chunk-R2WMVXZZ.js.map +0 -1
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
- import { k as EcsSystem, C as Component, W as WorldEntityView, T as TransformComponent, l as World, m as ComponentClass, n as ParentLookup, o as EcsEntityKind, O as ObjectManagementSystem } from './System-BeuJ1xt5.cjs';
2
- export { A as AssetInput, p as CheckboxInput, q as ColorInput, r as ComponentFactory, s as ComponentInput, t as ComponentKind, u as DropdownInput, v as DropdownOption, w as EcsComponentFactoryKind, x as EcsEntityEditorKind, y as EntityId, z as EntityInput, F as FloatInput, I as InputSystem, B as IntersectionResult, K as KeyboardKey, G as KeyboardKeys, M as MouseButton, R as RenderSystem, S as SelectionListener, H as SliderInput, J as TextInput, L as ToggleInput, N as TransformSyncSystem, Q as Vec3, U as Vector2Input, X as Vector3Input } from './System-BeuJ1xt5.cjs';
1
+ import { k as EcsSystem, C as Component, W as WorldEntityView, T as TransformComponent, l as World, S as SpawnPrefabSource, m as SpawnPrefabOptions, n as ComponentClass, o as ParentLookup, p as EcsEntityKind, O as ObjectManagementSystem, q as SubtreeSnapshot, r as EntityId, s as ExternalRefWarning } from './System-me3iAcMF.cjs';
2
+ export { A as AssetInput, t as CheckboxInput, u as ColorInput, v as ComponentFactory, w as ComponentInput, x as ComponentKind, y as DropdownInput, z as DropdownOption, B as EcsComponentFactoryKind, F as EcsEntityEditorKind, G as EntityInput, H as FloatInput, I as InputSystem, J as IntersectionResult, K as KeyboardKey, L as KeyboardKeys, M as MouseButton, N as PREFAB_FILE_VERSION, Q as PREFAB_FILE_VERSION_NESTED, R as PrefabAsset, U as RemapSnapshotOptions, X as RenderSystem, Y as SelectionListener, Z as SliderInput, _ as TextInput, $ as ToggleInput, a0 as TransformSyncSystem, a1 as Vec3, a2 as Vector2Input, a3 as Vector3Input, a4 as clearPrefabCache, a5 as despawnPrefab, a6 as loadPrefab, a7 as parsePrefabAsset, a8 as prefabFileVersionFor, a9 as remapSnapshotEntityIds, aa as setPrefabAssetUrlResolver, ab as spawnPrefab } from './System-me3iAcMF.cjs';
3
3
  import * as THREE from 'three';
4
- import { O as Object3DRef } from './Video-D4B-z74P.cjs';
5
- export { a2 as AnimationStateCallbacks, a3 as AnimationStateMachine, a4 as AnimationStateManager, a5 as StateMachine } from './Video-D4B-z74P.cjs';
6
- export { i as CoreComponents } from './index-BfoOC2CG.cjs';
4
+ import { O as Object3DRef } from './Video-U9hAnf9y.cjs';
5
+ export { a3 as AnimationStateCallbacks, a4 as AnimationStateMachine, a5 as AnimationStateManager, a6 as StateMachine } from './Video-U9hAnf9y.cjs';
6
+ export { i as CoreComponents } from './index-CZo5I5Gs.cjs';
7
7
  export { AnimationSystem, AudioSystem, CameraSyncSystem, EnvironmentSyncSystem, InstancedMeshSystem, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, ObjectVisibilitySystem, PhysicsSyncSystem, PostprocessingSyncSystem, ScriptBehaviourSystem, SelectionContext, VideoSystem } from './systems/index.cjs';
8
8
  export { createAnimationComponent, createAudioComponent, createCameraComponent, createEntityTypeComponent, createEnvironmentComponent, createImageComponent, createImageTargetAnchorComponent, createImageTargetComponent, createInstanceSlotComponent, createInstancedMeshComponent, createLightComponent, createMaterialComponent, createMeshComponent, createMeshGeometryComponent, createModelComponent, createNameComponent, createObject3DRefComponent, createParentIdComponent, createPhysicsComponent, createPostprocessingComponent, createScriptComponent, createSelectableComponent, createSelectionTransformStateComponent, createSpriteComponent, createTransformComponent, createVideoComponent, registerDefaultComponentFactories, registerDefaultFactories } from './factories/index.cjs';
9
9
  import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader.js';
@@ -136,6 +136,31 @@ declare class Behaviour implements CustomEcsSystem {
136
136
  * @param world - The owning world at disposal time.
137
137
  */
138
138
  dispose?(world: World): void;
139
+ /**
140
+ * Instantiate a prefab asset into the world at runtime.
141
+ *
142
+ * `source` is typically an `AssetInput` field from this script's `data`
143
+ * (drag a `.prefab` from the asset browser onto the field in the editor),
144
+ * a URL string, or a pre-loaded `PrefabAsset`. Resolves with the new root
145
+ * entity id.
146
+ *
147
+ * ```ts
148
+ * data = { enemyPrefab: { path: "", type: "prefab" } };
149
+ * async onUpdate() {
150
+ * if (shouldSpawn) {
151
+ * const id = await this.spawnPrefab(this.data.enemyPrefab, {
152
+ * position: { x: 0, y: 0, z: -5 },
153
+ * });
154
+ * }
155
+ * }
156
+ * ```
157
+ */
158
+ spawnPrefab(source: SpawnPrefabSource, options?: SpawnPrefabOptions): Promise<number>;
159
+ /**
160
+ * Remove a spawned prefab instance (the root entity and all descendants).
161
+ * Returns the number of entities removed.
162
+ */
163
+ despawn(rootEntityId: number): number;
139
164
  /**
140
165
  * Returns the entity's world-space position as a new `THREE.Vector3`, or
141
166
  * `null` if the entity has no scene presence.
@@ -260,6 +285,32 @@ declare class Behaviour implements CustomEcsSystem {
260
285
  onTargetLost(target: WorldEntityView): void;
261
286
  }
262
287
 
288
+ type ComponentValueMaps = {
289
+ object3DRefValues: Map<number, unknown>;
290
+ nameValues: Map<number, unknown>;
291
+ transformValues: Map<number, unknown>;
292
+ modelValues: Map<number, unknown>;
293
+ imageValues: Map<number, unknown>;
294
+ spriteValues: Map<number, unknown>;
295
+ videoValues: Map<number, unknown>;
296
+ cameraValues: Map<number, unknown>;
297
+ environmentValues: Map<number, unknown>;
298
+ postprocessingValues: Map<number, unknown>;
299
+ audioValues: Map<number, unknown>;
300
+ imageTargetValues: Map<number, unknown>;
301
+ lightValues: Map<number, unknown>;
302
+ materialValues: Map<number, unknown>;
303
+ meshGeometryValues: Map<number, unknown>;
304
+ selectableValues: Map<number, unknown>;
305
+ physicsValues: Map<number, unknown>;
306
+ animationValues: Map<number, unknown>;
307
+ imageTargetAnchorValues: Map<number, unknown>;
308
+ scriptValues: Map<number, unknown>;
309
+ instancedMeshValues: Map<number, unknown>;
310
+ instanceSlotValues: Map<number, unknown>;
311
+ prefabNodeValues: Map<number, unknown>;
312
+ prefabInstanceValues: Map<number, unknown>;
313
+ };
263
314
  type EcsWorldComponentSnapshot = {
264
315
  component: string;
265
316
  entries: Array<{
@@ -275,12 +326,40 @@ type EcsWorldStateSnapshotLike = {
275
326
  type HydrateWorldFromSnapshotResult = {
276
327
  restoredCount: number;
277
328
  selectedEntityId: number | null;
329
+ /** Snapshot entity id → created live entity id for every hydrated entity. */
330
+ idMap: Map<number, number>;
331
+ };
332
+ /**
333
+ * Optional behavior tweaks for {@link hydrateWorldFromSnapshotDetailed}.
334
+ * Defaults preserve the historical full-world-load behavior; prefab/subtree
335
+ * instantiation passes stricter options.
336
+ */
337
+ type HydrateOptions = {
338
+ /**
339
+ * When false, no camera in the snapshot is promoted to the world camera.
340
+ * Defaults to true (full scene loads want their default camera active);
341
+ * prefab spawns pass false so a spawned camera never hijacks the view.
342
+ */
343
+ assignPrimaryCamera?: boolean;
344
+ /**
345
+ * "world" (default) re-applies local transforms for every entity in the
346
+ * world after parent links restore — correct for full scene loads.
347
+ * "created" limits the pass to entities created by THIS hydrate call, so
348
+ * mid-session spawns don't touch unrelated live entities.
349
+ */
350
+ applyTransformsScope?: "world" | "created";
278
351
  };
279
352
  declare const HYDRATABLE_ENTITY_KINDS: Set<EcsEntityKind>;
280
353
 
281
- declare function hydrateWorldFromSnapshotDetailed(snapshot: EcsWorldStateSnapshotLike | null | undefined, world: World, objectManagementSystem: ObjectManagementSystem): HydrateWorldFromSnapshotResult;
354
+ declare function hydrateWorldFromSnapshotDetailed(snapshot: EcsWorldStateSnapshotLike | null | undefined, world: World, objectManagementSystem: ObjectManagementSystem, options?: HydrateOptions): HydrateWorldFromSnapshotResult;
282
355
  declare function hydrateWorldFromSnapshot(snapshot: EcsWorldStateSnapshotLike | null | undefined, world: World, objectManagementSystem: ObjectManagementSystem): number;
283
356
 
357
+ declare function buildComponentValueMaps(snapshot: EcsWorldStateSnapshotLike): ComponentValueMaps;
358
+
359
+ declare function restoreComponentState(world: World, objectManagementSystem: ObjectManagementSystem, targetEntityId: number, sourceEntityId: number, entityType: string | null, values: ComponentValueMaps): void;
360
+
361
+ declare function restorePostCreateComponents(world: World, objectManagementSystem: ObjectManagementSystem, targetEntityId: number, sourceEntityId: number, entityType: string | null, values: ComponentValueMaps, idMap: Map<number, number>): void;
362
+
284
363
  /**
285
364
  * Override where the DRACO decoder files (draco_wasm_wrapper.js,
286
365
  * draco_decoder.wasm, draco_decoder.js) are fetched from. Embedding apps
@@ -311,4 +390,231 @@ declare function loadSharedGltf(url: string, load: () => Promise<GLTF>): Promise
311
390
  */
312
391
  declare function clearModelCache(url?: string): void;
313
392
 
314
- export { Behaviour, Component, EcsEntityKind, EcsSystem, type EcsWorldComponentSnapshot, type EcsWorldStateSnapshotLike, HYDRATABLE_ENTITY_KINDS, type HydrateWorldFromSnapshotResult, ObjectManagementSystem, ParentLookup, SHARED_MODEL_RESOURCE_FLAG, World, WorldEntityView, clearModelCache, hydrateWorldFromSnapshot, hydrateWorldFromSnapshotDetailed, loadSharedGltf, resolveDracoDecoderPath, setDracoDecoderPath };
393
+ /**
394
+ * Pure JSON-space prefab patching: apply a nested prefab's NEW definition to
395
+ * every top-level-relative instance region inside a HOST document snapshot,
396
+ * honoring the region's stored per-property overrides. This is how edits to
397
+ * a child prefab cascade through the `.prefab` files that nest it (no live
398
+ * world exists for files). Reused later by `.scene` assets.
399
+ *
400
+ * Trust model: the region's stored override list (refreshed at every host
401
+ * save with `+node` addition markers) IS the user state — no old base is
402
+ * needed. Consequently the operation is idempotent: re-applying the same
403
+ * definition yields `changed: false`.
404
+ */
405
+
406
+ type ApplyPrefabToSnapshotResult = {
407
+ snapshot: SubtreeSnapshot;
408
+ changed: boolean;
409
+ };
410
+ /**
411
+ * Patch every top-level-relative nested instance of `nestedUrl` inside
412
+ * `hostSnapshot` with `newNestedSnapshot`. Deeper nesting (B inside C inside
413
+ * A) is NOT touched here — it cascades through C's own file.
414
+ */
415
+ declare function applyPrefabToSnapshotInstances(hostSnapshot: SubtreeSnapshot, nestedUrl: string, newNestedSnapshot: SubtreeSnapshot): ApplyPrefabToSnapshotResult;
416
+
417
+ /**
418
+ * Collect the given roots plus every descendant, BFS parent-first, using the
419
+ * `ParentId` component edges. Parent-first ordering matters: serialization
420
+ * renumbers ids in this order and instantiation creates entities in file
421
+ * order, so parents always exist before their children are linked.
422
+ */
423
+ declare function collectEntitySubtree(world: World, rootIds: EntityId[]): EntityId[];
424
+
425
+ /**
426
+ * Direct (top-level-relative) prefab urls a document depends on — the edges
427
+ * of the nesting graph. Deeper nesting is reached transitively through each
428
+ * dependency's own file, never directly.
429
+ */
430
+ declare function collectDirectPrefabDependencies(snapshot: SubtreeSnapshot): string[];
431
+
432
+ /**
433
+ * Scoped node identity for (possibly nested) prefab documents.
434
+ *
435
+ * A nodeKey identifies an entity within one prefab document even when the
436
+ * document contains nested instances of other prefabs (whose nodeIds repeat
437
+ * per instance). Formula (parent-first walk from the scope root, inherited
438
+ * `prefix`; the scope root's prefix is "" even if it carries PrefabInstance):
439
+ *
440
+ * - entity WITHOUT PrefabInstance: key = prefix + nodeId, children inherit
441
+ * the same prefix;
442
+ * - entity WITH PrefabInstance (non-scope-root): childPrefix = prefix +
443
+ * instanceId + "/"; key = childPrefix + nodeId (self-inclusive — sibling
444
+ * instances of the SAME prefab get distinct keys); children inherit
445
+ * childPrefix.
446
+ *
447
+ * Documents with no nested instances degenerate to bare nodeIds, so v1 files
448
+ * and override lists keep their exact meaning.
449
+ */
450
+
451
+ declare const NODE_KEY_SEPARATOR = "/";
452
+ /**
453
+ * Reserved override "component" marking a node ADDED by the host document
454
+ * inside a nested instance region (`"<nodeKey>|+node|"`). File patching
455
+ * trusts stored overrides (the old base is unavailable), so without the
456
+ * marker a host-authored node inside the region would be indistinguishable
457
+ * from a node the child prefab removed — and get deleted.
458
+ */
459
+ declare const ADDED_NODE_MARKER_COMPONENT = "+node";
460
+ type NodeKeyMaps = {
461
+ idToKey: Map<number, string>;
462
+ keyToId: Map<string, number>;
463
+ /** nodeKey of the scope root (bare nodeId), or null when it has none. */
464
+ rootKey: string | null;
465
+ /** Entity ids of NESTED instance roots (non-scope-root PrefabInstance). */
466
+ boundaryIds: Map<number, {
467
+ url: string;
468
+ instanceId: string;
469
+ }>;
470
+ };
471
+ declare function buildNodeKeyMapsFromSnapshot(snapshot: SubtreeSnapshot, options?: {
472
+ scopeRootEntityId?: number;
473
+ }): NodeKeyMaps;
474
+ /** JSON-space subtree ids (root first, BFS) via ParentId edges. */
475
+ declare function collectSnapshotSubtreeIds(snapshot: SubtreeSnapshot, rootEntityId: number): number[];
476
+ type NestedRegion = {
477
+ rootEntityId: number;
478
+ url: string;
479
+ instanceId: string;
480
+ overrides: string[];
481
+ };
482
+ /**
483
+ * TOP-LEVEL-RELATIVE nested instance regions of a document: instance roots
484
+ * that are not the scope root and not themselves inside another region.
485
+ * Deeper nesting is reached by cascading through the intermediate prefab's
486
+ * own file, never directly.
487
+ */
488
+ declare function findTopLevelNestedRegions(snapshot: SubtreeSnapshot): NestedRegion[];
489
+
490
+ type InstantiateSubtreeResult = {
491
+ /** Live entity id of the subtree root, or null when nothing hydrated. */
492
+ rootId: EntityId | null;
493
+ /** Snapshot entity id → live entity id. */
494
+ idMap: Map<number, number>;
495
+ };
496
+ /**
497
+ * Hydrate a self-contained subtree snapshot (a prefab file's `snapshot`)
498
+ * into a LIVE world: fresh entity ids, internal references remapped, no
499
+ * camera promotion, transform pass scoped to the created entities.
500
+ */
501
+ declare function instantiateSubtree(world: World, objectManagementSystem: ObjectManagementSystem, snapshot: SubtreeSnapshot): InstantiateSubtreeResult;
502
+
503
+ /**
504
+ * Per-property prefab override model — pure JSON-space functions shared by
505
+ * the editor (diff/merge at apply time) and future `.scene` tooling.
506
+ *
507
+ * The core problem: an instance's entity ids differ from the prefab file's
508
+ * ids by construction, so raw values can't be compared. Both sides are first
509
+ * CANONICALIZED into nodeId-space: every entity-id-bearing field (kept in
510
+ * sync with `snapshotIdUtils.ts`) becomes `{ $node: "<nodeId>" }` when the id
511
+ * maps to a node inside the same document, or stays a raw id when external.
512
+ * Two canonical values are equal iff they describe the same state relative
513
+ * to their own subtree.
514
+ *
515
+ * Override encoding (stored in `PrefabInstance.overrides`):
516
+ * "<nodeId>|<ComponentName>|<slash/separated/path>"
517
+ * "<nodeId>|<ComponentName>|" // empty path = whole component overridden
518
+ */
519
+
520
+ /** Components that never participate in override diffing/merging. */
521
+ declare const OVERRIDE_DIFF_EXCLUDED_COMPONENTS: Set<string>;
522
+ /**
523
+ * Components excluded ONLY on the instance ROOT node — these are per-instance
524
+ * by definition (where the instance sits in the scene and what it's called).
525
+ */
526
+ declare const OVERRIDE_ROOT_EXCLUDED_COMPONENTS: Set<string>;
527
+ type NodeMaps = {
528
+ idToNode: Map<number, string>;
529
+ nodeToId: Map<string, number>;
530
+ /** nodeId of the subtree root (entity whose ParentId is null/absent). */
531
+ rootNodeId: string | null;
532
+ };
533
+ /** Entity ids of entities whose ParentId is null or absent. */
534
+ declare function findSnapshotRootEntityIds(snapshot: SubtreeSnapshot): number[];
535
+ declare function buildNodeMapsFromSnapshot(snapshot: SubtreeSnapshot): NodeMaps;
536
+ /** Invert the columnar snapshot into entityId → (componentName → value). */
537
+ declare function indexSnapshotByEntity(snapshot: SubtreeSnapshot): Map<number, Map<string, unknown>>;
538
+ /**
539
+ * Canonicalize a serialized component value into nodeId-space:
540
+ * - entity-id fields → `{$node}` (internal) or raw id (external)
541
+ * - ScriptComponent entries keep only `{className, scriptUrl, enabled, data}`
542
+ * (entityId/runtimeState/runtimeMessage are per-instance transients)
543
+ * - Object3DRef keeps only `{visibility}` (the rest is a live object ref)
544
+ *
545
+ * Keep the id-bearing field list in sync with `snapshotIdUtils.ts`.
546
+ */
547
+ declare function canonicalizeComponentValue(componentName: string, value: unknown, idToNode: Map<number, string>): unknown;
548
+ /**
549
+ * Replace every `{$node}` marker (at any depth) with the mapped entity id
550
+ * from `nodeToId`, or null when the node no longer exists. Exact inverse of
551
+ * canonicalization for the id-bearing positions.
552
+ */
553
+ declare function decanonicalizeComponentValue(value: unknown, nodeToId: Map<string, number>): unknown;
554
+ declare const encodeOverride: (nodeId: string, componentName: string, path: string) => string;
555
+ declare function parseOverride(encoded: string): {
556
+ nodeId: string;
557
+ componentName: string;
558
+ path: string;
559
+ } | null;
560
+ /** nodeId → componentName → set of overridden paths. */
561
+ declare function groupOverridePaths(overrides: string[]): Map<string, Map<string, Set<string>>>;
562
+ /**
563
+ * Collect leaf paths where two canonical values differ. Semantics:
564
+ * - `{$node}` refs compare atomically by nodeId
565
+ * - arrays of differing length are ONE atomic override (the array path);
566
+ * equal lengths recurse per index
567
+ * - object key present on one side only marks that key's path
568
+ * - type mismatches mark the current path
569
+ * An empty-string path means the values differ at the top level.
570
+ */
571
+ declare function collectDiffPaths(base: unknown, current: unknown, prefix?: string, out?: string[]): string[];
572
+ /**
573
+ * Diff a live instance subtree against its prefab base (both as serialized
574
+ * subtree snapshots carrying PrefabNode identity) and return the encoded
575
+ * override list: every path where the instance deviates from the base.
576
+ *
577
+ * Identity is nodeKey-scoped ({@link buildNodeKeyMapsFromSnapshot}), so
578
+ * nested instance regions diff correctly; for nested-free documents the
579
+ * keys degenerate to bare nodeIds (v1 behavior unchanged).
580
+ *
581
+ * Policies: components missing on the instance produce no override (apply
582
+ * re-adds them); components/nodes only on the instance are local additions
583
+ * and produce no override — EXCEPT when `emitAdditionMarkers` is set
584
+ * (file-space callers), which records `"<key>|+node|"` for instance nodes
585
+ * absent from the base so pure-JSON patching never deletes host-authored
586
+ * nodes inside nested regions.
587
+ */
588
+ declare function computeInstanceOverrides(baseSnapshot: SubtreeSnapshot, instanceSnapshot: SubtreeSnapshot, options?: {
589
+ emitAdditionMarkers?: boolean;
590
+ }): string[];
591
+ /**
592
+ * Merge a component's NEW canonical file value with an instance's canonical
593
+ * value, preserving the instance side at every overridden path. An empty
594
+ * path ("") means the whole component is overridden → instance wins.
595
+ */
596
+ declare function mergeComponentValue(newFileCanonical: unknown, instanceCanonical: unknown, overridePaths: Set<string> | undefined): unknown;
597
+
598
+ type SerializeEntitySubtreeResult = {
599
+ snapshot: SubtreeSnapshot;
600
+ /**
601
+ * References that pointed OUTSIDE the subtree and were nulled out
602
+ * (ids are LIVE world ids so callers can name the offending entities).
603
+ * The root's own external parent link is nulled silently — it is expected.
604
+ */
605
+ warnings: ExternalRefWarning[];
606
+ /** Component types stripped because they are scene singletons. */
607
+ strippedComponents: string[];
608
+ };
609
+ /**
610
+ * Serialize `rootId` + all descendants into a self-contained snapshot:
611
+ * entity ids renumbered 1..N in BFS parent-first order, all internal id
612
+ * references remapped, external references nulled + reported, root ParentId
613
+ * forced to null. The result is directly consumable by
614
+ * `hydrateWorldFromSnapshotDetailed` / `instantiateSubtree`.
615
+ */
616
+ declare function serializeEntitySubtree(world: World, rootId: EntityId, options?: {
617
+ maxDepth?: number;
618
+ }): SerializeEntitySubtreeResult;
619
+
620
+ export { ADDED_NODE_MARKER_COMPONENT, type ApplyPrefabToSnapshotResult, Behaviour, Component, type ComponentValueMaps, EcsEntityKind, EcsSystem, type EcsWorldComponentSnapshot, type EcsWorldStateSnapshotLike, EntityId, ExternalRefWarning, HYDRATABLE_ENTITY_KINDS, type HydrateOptions, type HydrateWorldFromSnapshotResult, type InstantiateSubtreeResult, NODE_KEY_SEPARATOR, type NestedRegion, type NodeKeyMaps, type NodeMaps, OVERRIDE_DIFF_EXCLUDED_COMPONENTS, OVERRIDE_ROOT_EXCLUDED_COMPONENTS, ObjectManagementSystem, ParentLookup, SHARED_MODEL_RESOURCE_FLAG, type SerializeEntitySubtreeResult, SpawnPrefabOptions, SpawnPrefabSource, SubtreeSnapshot, World, WorldEntityView, applyPrefabToSnapshotInstances, buildComponentValueMaps, buildNodeKeyMapsFromSnapshot, buildNodeMapsFromSnapshot, canonicalizeComponentValue, clearModelCache, collectDiffPaths, collectDirectPrefabDependencies, collectEntitySubtree, collectSnapshotSubtreeIds, computeInstanceOverrides, decanonicalizeComponentValue, encodeOverride, findSnapshotRootEntityIds, findTopLevelNestedRegions, groupOverridePaths, hydrateWorldFromSnapshot, hydrateWorldFromSnapshotDetailed, indexSnapshotByEntity, instantiateSubtree, loadSharedGltf, mergeComponentValue, parseOverride, resolveDracoDecoderPath, restoreComponentState, restorePostCreateComponents, serializeEntitySubtree, setDracoDecoderPath };