@relu-interactives/spatial-ecs 0.2.20 → 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 (41) hide show
  1. package/dist/{System-BjwOBx81.d.cts → System-me3iAcMF.d.cts} +5 -1
  2. package/dist/{System-BjwOBx81.d.ts → System-me3iAcMF.d.ts} +5 -1
  3. package/dist/{Video-B9z5AtIf.d.ts → Video-DHnxjGhW.d.ts} +1 -1
  4. package/dist/{Video-B8yVI1tF.d.cts → Video-U9hAnf9y.d.cts} +1 -1
  5. package/dist/{chunk-67MFQDHX.js → chunk-5U3YS4JD.js} +196 -33
  6. package/dist/chunk-5U3YS4JD.js.map +1 -0
  7. package/dist/{chunk-DY4ETMP2.js → chunk-AXRCGF63.js} +3 -3
  8. package/dist/{chunk-DY4ETMP2.js.map → chunk-AXRCGF63.js.map} +1 -1
  9. package/dist/{chunk-HUHN6IFD.js → chunk-K6KMKKJ6.js} +4 -4
  10. package/dist/{chunk-HUHN6IFD.js.map → chunk-K6KMKKJ6.js.map} +1 -1
  11. package/dist/{chunk-Z6OMYEXU.js → chunk-V7BNVTJW.js} +11 -3
  12. package/dist/chunk-V7BNVTJW.js.map +1 -0
  13. package/dist/components/index.cjs +9 -1
  14. package/dist/components/index.cjs.map +1 -1
  15. package/dist/components/index.d.cts +3 -3
  16. package/dist/components/index.d.ts +3 -3
  17. package/dist/components/index.js +1 -1
  18. package/dist/docs/guide/prefabs.md +24 -5
  19. package/dist/factories/index.d.cts +2 -2
  20. package/dist/factories/index.d.ts +2 -2
  21. package/dist/factories/index.js +3 -3
  22. package/dist/{index-LHLKpJhZ.d.cts → index-CZo5I5Gs.d.cts} +29 -13
  23. package/dist/{index-BBI2YdCu.d.ts → index-D7FSg0Au.d.ts} +29 -13
  24. package/dist/index.cjs +458 -40
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +108 -10
  27. package/dist/index.d.ts +108 -10
  28. package/dist/index.js +249 -11
  29. package/dist/index.js.map +1 -1
  30. package/dist/systems/index.cjs +26 -7
  31. package/dist/systems/index.cjs.map +1 -1
  32. package/dist/systems/index.d.cts +2 -2
  33. package/dist/systems/index.d.ts +2 -2
  34. package/dist/systems/index.js +3 -3
  35. package/dist/types.d.cts +1 -1
  36. package/dist/types.d.ts +1 -1
  37. package/dist/worldSnapshotUtils.d.cts +1 -1
  38. package/dist/worldSnapshotUtils.d.ts +1 -1
  39. package/package.json +1 -1
  40. package/dist/chunk-67MFQDHX.js.map +0 -1
  41. package/dist/chunk-Z6OMYEXU.js.map +0 -1
@@ -523,6 +523,10 @@ declare function remapSnapshotEntityIds(snapshot: SubtreeSnapshot, idMap: Map<nu
523
523
  };
524
524
 
525
525
  declare const PREFAB_FILE_VERSION = 1;
526
+ /** Written for files containing NESTED instances (parse accepts either). */
527
+ declare const PREFAB_FILE_VERSION_NESTED = 2;
528
+ /** File version to write for a given snapshot: 2 iff it nests instances. */
529
+ declare function prefabFileVersionFor(snapshot: SubtreeSnapshot): number;
526
530
  /**
527
531
  * Envelope of a `.prefab` asset file (and, later, `.scene` assets — same
528
532
  * shape with `type: "scene"`). `snapshot` is the same columnar world-snapshot
@@ -1114,4 +1118,4 @@ interface EcsSystem {
1114
1118
  dispose?(world: World): void;
1115
1119
  }
1116
1120
 
1117
- export { TransformSyncSystem as $, type AssetInput as A, type EcsComponentFactoryKind as B, Component as C, DEFAULT_ENVIRONMENT_STATE as D, Environment as E, type EcsEntityEditorKind as F, type EntityInput as G, type FloatInput as H, InputSystem as I, type IntersectionResult as J, type KeyboardKey as K, KeyboardKeys as L, type MouseButton as M, PREFAB_FILE_VERSION as N, ObjectManagementSystem as O, ParentId as P, type PrefabAsset as Q, type RemapSnapshotOptions as R, type SpawnPrefabSource as S, TransformComponent as T, RenderSystem as U, type Vec3$1 as V, type WorldEntityView$1 as W, type SelectionListener as X, type SliderInput as Y, type TextInput as Z, type ToggleInput as _, DEFAULT_POSTPROCESSING_STATE as a, type Vec3 as a0, type Vector2Input as a1, type Vector3Input as a2, clearPrefabCache as a3, despawnPrefab as a4, loadPrefab as a5, parsePrefabAsset as a6, remapSnapshotEntityIds as a7, setPrefabAssetUrlResolver as a8, spawnPrefab as a9, type AnyComponent as aa, DEBUG_CHANGE_IGNORED_SYSTEMS as ab, type WorldHistorySnapshot as ac, cloneHistoryValue as ad, normalizeDebugValue as ae, type EnvironmentFogState as b, type EnvironmentFogType as c, type EnvironmentGradientEffect as d, type EnvironmentSkyboxState as e, type EnvironmentSkyboxType as f, type EnvironmentState as g, Postprocessing as h, type PostprocessingState as i, type TransformData as j, type EcsSystem as k, World as l, type SpawnPrefabOptions as m, type ComponentClass as n, type ParentLookup as o, type EcsEntityKind as p, type EntityId as q, type SubtreeSnapshot as r, type ExternalRefWarning as s, type CheckboxInput as t, type ColorInput as u, type ComponentFactory as v, type ComponentInput as w, type ComponentKind as x, type DropdownInput as y, type DropdownOption as z };
1121
+ export { type ToggleInput as $, type AssetInput as A, type EcsComponentFactoryKind as B, Component as C, DEFAULT_ENVIRONMENT_STATE as D, Environment as E, type EcsEntityEditorKind as F, type EntityInput as G, type FloatInput as H, InputSystem as I, type IntersectionResult as J, type KeyboardKey as K, KeyboardKeys as L, type MouseButton as M, PREFAB_FILE_VERSION as N, ObjectManagementSystem as O, ParentId as P, PREFAB_FILE_VERSION_NESTED as Q, type PrefabAsset as R, type SpawnPrefabSource as S, TransformComponent as T, type RemapSnapshotOptions as U, type Vec3$1 as V, type WorldEntityView$1 as W, RenderSystem as X, type SelectionListener as Y, type SliderInput as Z, type TextInput as _, DEFAULT_POSTPROCESSING_STATE as a, TransformSyncSystem as a0, type Vec3 as a1, type Vector2Input as a2, type Vector3Input as a3, clearPrefabCache as a4, despawnPrefab as a5, loadPrefab as a6, parsePrefabAsset as a7, prefabFileVersionFor as a8, remapSnapshotEntityIds as a9, setPrefabAssetUrlResolver as aa, spawnPrefab as ab, type AnyComponent as ac, DEBUG_CHANGE_IGNORED_SYSTEMS as ad, type WorldHistorySnapshot as ae, cloneHistoryValue as af, normalizeDebugValue as ag, type EnvironmentFogState as b, type EnvironmentFogType as c, type EnvironmentGradientEffect as d, type EnvironmentSkyboxState as e, type EnvironmentSkyboxType as f, type EnvironmentState as g, Postprocessing as h, type PostprocessingState as i, type TransformData as j, type EcsSystem as k, World as l, type SpawnPrefabOptions as m, type ComponentClass as n, type ParentLookup as o, type EcsEntityKind as p, type SubtreeSnapshot as q, type EntityId as r, type ExternalRefWarning as s, type CheckboxInput as t, type ColorInput as u, type ComponentFactory as v, type ComponentInput as w, type ComponentKind as x, type DropdownInput as y, type DropdownOption as z };
@@ -523,6 +523,10 @@ declare function remapSnapshotEntityIds(snapshot: SubtreeSnapshot, idMap: Map<nu
523
523
  };
524
524
 
525
525
  declare const PREFAB_FILE_VERSION = 1;
526
+ /** Written for files containing NESTED instances (parse accepts either). */
527
+ declare const PREFAB_FILE_VERSION_NESTED = 2;
528
+ /** File version to write for a given snapshot: 2 iff it nests instances. */
529
+ declare function prefabFileVersionFor(snapshot: SubtreeSnapshot): number;
526
530
  /**
527
531
  * Envelope of a `.prefab` asset file (and, later, `.scene` assets — same
528
532
  * shape with `type: "scene"`). `snapshot` is the same columnar world-snapshot
@@ -1114,4 +1118,4 @@ interface EcsSystem {
1114
1118
  dispose?(world: World): void;
1115
1119
  }
1116
1120
 
1117
- export { TransformSyncSystem as $, type AssetInput as A, type EcsComponentFactoryKind as B, Component as C, DEFAULT_ENVIRONMENT_STATE as D, Environment as E, type EcsEntityEditorKind as F, type EntityInput as G, type FloatInput as H, InputSystem as I, type IntersectionResult as J, type KeyboardKey as K, KeyboardKeys as L, type MouseButton as M, PREFAB_FILE_VERSION as N, ObjectManagementSystem as O, ParentId as P, type PrefabAsset as Q, type RemapSnapshotOptions as R, type SpawnPrefabSource as S, TransformComponent as T, RenderSystem as U, type Vec3$1 as V, type WorldEntityView$1 as W, type SelectionListener as X, type SliderInput as Y, type TextInput as Z, type ToggleInput as _, DEFAULT_POSTPROCESSING_STATE as a, type Vec3 as a0, type Vector2Input as a1, type Vector3Input as a2, clearPrefabCache as a3, despawnPrefab as a4, loadPrefab as a5, parsePrefabAsset as a6, remapSnapshotEntityIds as a7, setPrefabAssetUrlResolver as a8, spawnPrefab as a9, type AnyComponent as aa, DEBUG_CHANGE_IGNORED_SYSTEMS as ab, type WorldHistorySnapshot as ac, cloneHistoryValue as ad, normalizeDebugValue as ae, type EnvironmentFogState as b, type EnvironmentFogType as c, type EnvironmentGradientEffect as d, type EnvironmentSkyboxState as e, type EnvironmentSkyboxType as f, type EnvironmentState as g, Postprocessing as h, type PostprocessingState as i, type TransformData as j, type EcsSystem as k, World as l, type SpawnPrefabOptions as m, type ComponentClass as n, type ParentLookup as o, type EcsEntityKind as p, type EntityId as q, type SubtreeSnapshot as r, type ExternalRefWarning as s, type CheckboxInput as t, type ColorInput as u, type ComponentFactory as v, type ComponentInput as w, type ComponentKind as x, type DropdownInput as y, type DropdownOption as z };
1121
+ export { type ToggleInput as $, type AssetInput as A, type EcsComponentFactoryKind as B, Component as C, DEFAULT_ENVIRONMENT_STATE as D, Environment as E, type EcsEntityEditorKind as F, type EntityInput as G, type FloatInput as H, InputSystem as I, type IntersectionResult as J, type KeyboardKey as K, KeyboardKeys as L, type MouseButton as M, PREFAB_FILE_VERSION as N, ObjectManagementSystem as O, ParentId as P, PREFAB_FILE_VERSION_NESTED as Q, type PrefabAsset as R, type SpawnPrefabSource as S, TransformComponent as T, type RemapSnapshotOptions as U, type Vec3$1 as V, type WorldEntityView$1 as W, RenderSystem as X, type SelectionListener as Y, type SliderInput as Z, type TextInput as _, DEFAULT_POSTPROCESSING_STATE as a, TransformSyncSystem as a0, type Vec3 as a1, type Vector2Input as a2, type Vector3Input as a3, clearPrefabCache as a4, despawnPrefab as a5, loadPrefab as a6, parsePrefabAsset as a7, prefabFileVersionFor as a8, remapSnapshotEntityIds as a9, setPrefabAssetUrlResolver as aa, spawnPrefab as ab, type AnyComponent as ac, DEBUG_CHANGE_IGNORED_SYSTEMS as ad, type WorldHistorySnapshot as ae, cloneHistoryValue as af, normalizeDebugValue as ag, type EnvironmentFogState as b, type EnvironmentFogType as c, type EnvironmentGradientEffect as d, type EnvironmentSkyboxState as e, type EnvironmentSkyboxType as f, type EnvironmentState as g, Postprocessing as h, type PostprocessingState as i, type TransformData as j, type EcsSystem as k, World as l, type SpawnPrefabOptions as m, type ComponentClass as n, type ParentLookup as o, type EcsEntityKind as p, type SubtreeSnapshot as q, type EntityId as r, type ExternalRefWarning as s, type CheckboxInput as t, type ColorInput as u, type ComponentFactory as v, type ComponentInput as w, type ComponentKind as x, type DropdownInput as y, type DropdownOption as z };
@@ -1,5 +1,5 @@
1
1
  import * as THREE from 'three';
2
- import { C as Component, p as EcsEntityKind, F as EcsEntityEditorKind, q as EntityId } from './System-BjwOBx81.js';
2
+ import { C as Component, p as EcsEntityKind, F as EcsEntityEditorKind, r as EntityId } from './System-me3iAcMF.js';
3
3
  import * as RAPIER from '@dimforge/rapier3d-compat';
4
4
 
5
5
  interface StateMachine {
@@ -1,5 +1,5 @@
1
1
  import * as THREE from 'three';
2
- import { C as Component, p as EcsEntityKind, F as EcsEntityEditorKind, q as EntityId } from './System-BjwOBx81.cjs';
2
+ import { C as Component, p as EcsEntityKind, F as EcsEntityEditorKind, r as EntityId } from './System-me3iAcMF.cjs';
3
3
  import * as RAPIER from '@dimforge/rapier3d-compat';
4
4
 
5
5
  interface StateMachine {
@@ -1,5 +1,5 @@
1
- import { resolveDracoDecoderPath, applyTransform } from './chunk-DY4ETMP2.js';
2
- import { AnimationComponent, ModelComponent, CameraComponent, Object3DRef, Environment, Postprocessing, TransformComponent, PhysicsComponent, LightComponent, MaterialComponent, DEFAULT_MESH_GEOMETRY_PARAMETERS, MeshGeometryComponent, InstancedMeshComponent, ParentId, ScriptComponent, InstanceSlotComponent, Name, ImageComponent, SpriteComponent, VideoComponent, AudioComponent, ImageTarget, Selectable, PrefabNode, PrefabInstance } from './chunk-Z6OMYEXU.js';
1
+ import { resolveDracoDecoderPath, applyTransform } from './chunk-AXRCGF63.js';
2
+ import { AnimationComponent, ModelComponent, CameraComponent, Object3DRef, Environment, Postprocessing, TransformComponent, PhysicsComponent, LightComponent, MaterialComponent, DEFAULT_MESH_GEOMETRY_PARAMETERS, MeshGeometryComponent, InstancedMeshComponent, ParentId, ScriptComponent, InstanceSlotComponent, Name, ImageComponent, SpriteComponent, VideoComponent, AudioComponent, ImageTarget, Selectable, PrefabNode, PrefabInstance } from './chunk-V7BNVTJW.js';
3
3
  import { __name } from './chunk-OY7ZODZP.js';
4
4
  import * as THREE7 from 'three';
5
5
  import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
@@ -3410,7 +3410,13 @@ function restoreComponentState(world, objectManagementSystem, targetEntityId, so
3410
3410
  ) : [];
3411
3411
  world.addComponent(
3412
3412
  targetEntityId,
3413
- new PrefabInstance(sourcePrefabInstance.url, overrides)
3413
+ new PrefabInstance(
3414
+ sourcePrefabInstance.url,
3415
+ overrides,
3416
+ // Preserve the placement identity; the constructor generates a
3417
+ // fresh one for legacy snapshots that predate instanceId.
3418
+ typeof sourcePrefabInstance.instanceId === "string" && sourcePrefabInstance.instanceId.length > 0 ? sourcePrefabInstance.instanceId : void 0
3419
+ )
3414
3420
  );
3415
3421
  }
3416
3422
  }
@@ -3657,6 +3663,148 @@ function hydrateWorldFromSnapshot(snapshot, world, objectManagementSystem) {
3657
3663
  }
3658
3664
  __name(hydrateWorldFromSnapshot, "hydrateWorldFromSnapshot");
3659
3665
 
3666
+ // core/prefab/nodeKeys.ts
3667
+ var NODE_KEY_SEPARATOR = "/";
3668
+ var ADDED_NODE_MARKER_COMPONENT = "+node";
3669
+ var asRecord2 = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : null, "asRecord");
3670
+ var readBlock = /* @__PURE__ */ __name((snapshot, component) => {
3671
+ const map = /* @__PURE__ */ new Map();
3672
+ const block = snapshot.components.find((b) => b.component === component);
3673
+ for (const entry of block?.entries ?? []) {
3674
+ const record = asRecord2(entry.value);
3675
+ if (record) {
3676
+ map.set(entry.entityId, record);
3677
+ }
3678
+ }
3679
+ return map;
3680
+ }, "readBlock");
3681
+ var fallbackInstanceId = /* @__PURE__ */ __name((entityId) => `e${entityId}`, "fallbackInstanceId");
3682
+ function buildNodeKeyMapsFromSnapshot(snapshot, options) {
3683
+ const parentValues = readBlock(snapshot, "ParentId");
3684
+ const nodeValues = readBlock(snapshot, "PrefabNode");
3685
+ const instanceValues = readBlock(snapshot, "PrefabInstance");
3686
+ const inDocument = new Set(snapshot.entities);
3687
+ const childrenByParent = /* @__PURE__ */ new Map();
3688
+ const rootIds = [];
3689
+ for (const entityId of snapshot.entities) {
3690
+ const parent = parentValues.get(entityId)?.value;
3691
+ if (typeof parent === "number" && inDocument.has(parent)) {
3692
+ const siblings = childrenByParent.get(parent);
3693
+ if (siblings) siblings.push(entityId);
3694
+ else childrenByParent.set(parent, [entityId]);
3695
+ } else {
3696
+ rootIds.push(entityId);
3697
+ }
3698
+ }
3699
+ const scopeRoots = options?.scopeRootEntityId !== void 0 ? [options.scopeRootEntityId] : rootIds;
3700
+ const idToKey = /* @__PURE__ */ new Map();
3701
+ const keyToId = /* @__PURE__ */ new Map();
3702
+ const boundaryIds = /* @__PURE__ */ new Map();
3703
+ const scopeRootSet = new Set(scopeRoots);
3704
+ const queue = scopeRoots.map(
3705
+ (entityId) => ({ entityId, prefix: "" })
3706
+ );
3707
+ while (queue.length > 0) {
3708
+ const { entityId, prefix } = queue.shift();
3709
+ const instance = instanceValues.get(entityId);
3710
+ const isBoundary = Boolean(
3711
+ instance && typeof instance.url === "string" && !scopeRootSet.has(entityId)
3712
+ );
3713
+ let ownPrefix = prefix;
3714
+ let childPrefix = prefix;
3715
+ if (isBoundary && instance) {
3716
+ const instanceId = typeof instance.instanceId === "string" && instance.instanceId.length > 0 ? instance.instanceId : fallbackInstanceId(entityId);
3717
+ childPrefix = `${prefix}${instanceId}${NODE_KEY_SEPARATOR}`;
3718
+ ownPrefix = childPrefix;
3719
+ boundaryIds.set(entityId, {
3720
+ url: instance.url,
3721
+ instanceId
3722
+ });
3723
+ }
3724
+ const nodeId = nodeValues.get(entityId)?.nodeId;
3725
+ if (typeof nodeId === "string" && nodeId.length > 0) {
3726
+ const key = `${ownPrefix}${nodeId}`;
3727
+ idToKey.set(entityId, key);
3728
+ keyToId.set(key, entityId);
3729
+ }
3730
+ for (const child of childrenByParent.get(entityId) ?? []) {
3731
+ queue.push({ entityId: child, prefix: childPrefix });
3732
+ }
3733
+ }
3734
+ const rootEntityId = scopeRoots[0];
3735
+ const rootNodeId = rootEntityId !== void 0 ? nodeValues.get(rootEntityId)?.nodeId : void 0;
3736
+ return {
3737
+ idToKey,
3738
+ keyToId,
3739
+ rootKey: typeof rootNodeId === "string" && rootNodeId.length > 0 ? rootNodeId : null,
3740
+ boundaryIds
3741
+ };
3742
+ }
3743
+ __name(buildNodeKeyMapsFromSnapshot, "buildNodeKeyMapsFromSnapshot");
3744
+ function collectSnapshotSubtreeIds(snapshot, rootEntityId) {
3745
+ const parentValues = readBlock(snapshot, "ParentId");
3746
+ const childrenByParent = /* @__PURE__ */ new Map();
3747
+ for (const entityId of snapshot.entities) {
3748
+ const parent = parentValues.get(entityId)?.value;
3749
+ if (typeof parent === "number") {
3750
+ const siblings = childrenByParent.get(parent);
3751
+ if (siblings) siblings.push(entityId);
3752
+ else childrenByParent.set(parent, [entityId]);
3753
+ }
3754
+ }
3755
+ const ordered = [];
3756
+ const seen = /* @__PURE__ */ new Set();
3757
+ const queue = [rootEntityId];
3758
+ while (queue.length > 0) {
3759
+ const entityId = queue.shift();
3760
+ if (seen.has(entityId)) continue;
3761
+ seen.add(entityId);
3762
+ ordered.push(entityId);
3763
+ queue.push(...childrenByParent.get(entityId) ?? []);
3764
+ }
3765
+ return ordered;
3766
+ }
3767
+ __name(collectSnapshotSubtreeIds, "collectSnapshotSubtreeIds");
3768
+ function findTopLevelNestedRegions(snapshot) {
3769
+ const parentValues = readBlock(snapshot, "ParentId");
3770
+ const instanceValues = readBlock(snapshot, "PrefabInstance");
3771
+ const inDocument = new Set(snapshot.entities);
3772
+ const roots = new Set(
3773
+ snapshot.entities.filter((entityId) => {
3774
+ const parent = parentValues.get(entityId)?.value;
3775
+ return typeof parent !== "number" || !inDocument.has(parent);
3776
+ })
3777
+ );
3778
+ const regions = [];
3779
+ for (const [entityId, instance] of instanceValues) {
3780
+ if (roots.has(entityId)) continue;
3781
+ if (typeof instance.url !== "string" || instance.url.length === 0) continue;
3782
+ let ancestor = parentValues.get(entityId)?.value;
3783
+ let nestedDeeper = false;
3784
+ let hops = 0;
3785
+ while (typeof ancestor === "number" && hops < 512) {
3786
+ if (instanceValues.has(ancestor) && !roots.has(ancestor)) {
3787
+ nestedDeeper = true;
3788
+ break;
3789
+ }
3790
+ ancestor = parentValues.get(ancestor)?.value;
3791
+ hops += 1;
3792
+ }
3793
+ if (nestedDeeper) continue;
3794
+ regions.push({
3795
+ rootEntityId: entityId,
3796
+ url: instance.url,
3797
+ instanceId: typeof instance.instanceId === "string" && instance.instanceId.length > 0 ? instance.instanceId : fallbackInstanceId(entityId),
3798
+ overrides: Array.isArray(instance.overrides) ? instance.overrides.filter(
3799
+ (entry) => typeof entry === "string"
3800
+ ) : []
3801
+ });
3802
+ }
3803
+ regions.sort((a, b) => a.rootEntityId - b.rootEntityId);
3804
+ return regions;
3805
+ }
3806
+ __name(findTopLevelNestedRegions, "findTopLevelNestedRegions");
3807
+
3660
3808
  // core/prefab/overrides.ts
3661
3809
  var OVERRIDE_DIFF_EXCLUDED_COMPONENTS = /* @__PURE__ */ new Set([
3662
3810
  "PrefabNode",
@@ -3670,10 +3818,10 @@ var OVERRIDE_ROOT_EXCLUDED_COMPONENTS = /* @__PURE__ */ new Set([
3670
3818
  "Name",
3671
3819
  "ParentId"
3672
3820
  ]);
3673
- var asRecord2 = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : null, "asRecord");
3821
+ var asRecord3 = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : null, "asRecord");
3674
3822
  var clone = /* @__PURE__ */ __name((value) => value === void 0 ? value : structuredClone(value), "clone");
3675
3823
  var isNodeRef = /* @__PURE__ */ __name((value) => {
3676
- const record = asRecord2(value);
3824
+ const record = asRecord3(value);
3677
3825
  return Boolean(
3678
3826
  record && typeof record.$node === "string" && Object.keys(record).length === 1
3679
3827
  );
@@ -3685,7 +3833,7 @@ function findSnapshotRootEntityIds(snapshot) {
3685
3833
  );
3686
3834
  const parentByEntity = /* @__PURE__ */ new Map();
3687
3835
  for (const entry of parentBlock?.entries ?? []) {
3688
- parentByEntity.set(entry.entityId, asRecord2(entry.value)?.value ?? null);
3836
+ parentByEntity.set(entry.entityId, asRecord3(entry.value)?.value ?? null);
3689
3837
  }
3690
3838
  return snapshot.entities.filter(
3691
3839
  (entityId) => typeof parentByEntity.get(entityId) !== "number"
@@ -3699,7 +3847,7 @@ function buildNodeMapsFromSnapshot(snapshot) {
3699
3847
  (block) => block.component === "PrefabNode"
3700
3848
  );
3701
3849
  for (const entry of nodeBlock?.entries ?? []) {
3702
- const nodeId = asRecord2(entry.value)?.nodeId;
3850
+ const nodeId = asRecord3(entry.value)?.nodeId;
3703
3851
  if (typeof nodeId === "string" && nodeId.length > 0) {
3704
3852
  idToNode.set(entry.entityId, nodeId);
3705
3853
  nodeToId.set(nodeId, entry.entityId);
@@ -3731,7 +3879,7 @@ var toRefOrRaw = /* @__PURE__ */ __name((id, idToNode) => {
3731
3879
  }, "toRefOrRaw");
3732
3880
  function canonicalizeComponentValue(componentName, value, idToNode) {
3733
3881
  const cloned = clone(value);
3734
- const record = asRecord2(cloned);
3882
+ const record = asRecord3(cloned);
3735
3883
  if (!record) {
3736
3884
  return cloned;
3737
3885
  }
@@ -3750,14 +3898,14 @@ function canonicalizeComponentValue(componentName, value, idToNode) {
3750
3898
  const entries = Array.isArray(record.entries) ? record.entries : [];
3751
3899
  return {
3752
3900
  entries: entries.map((rawEntry) => {
3753
- const entry = asRecord2(rawEntry);
3901
+ const entry = asRecord3(rawEntry);
3754
3902
  if (!entry) {
3755
3903
  return rawEntry;
3756
3904
  }
3757
- const data = asRecord2(entry.data) ?? {};
3905
+ const data = asRecord3(entry.data) ?? {};
3758
3906
  const canonicalData = {};
3759
3907
  for (const [key, fieldValue] of Object.entries(data)) {
3760
- const field = asRecord2(fieldValue);
3908
+ const field = asRecord3(fieldValue);
3761
3909
  if (field?.type === "entity" && typeof field.value === "number") {
3762
3910
  canonicalData[key] = {
3763
3911
  ...field,
@@ -3765,7 +3913,7 @@ function canonicalizeComponentValue(componentName, value, idToNode) {
3765
3913
  };
3766
3914
  continue;
3767
3915
  }
3768
- const componentRef = asRecord2(field?.value);
3916
+ const componentRef = asRecord3(field?.value);
3769
3917
  if (field?.type === "component" && componentRef && typeof componentRef.entityId === "number") {
3770
3918
  canonicalData[key] = {
3771
3919
  ...field,
@@ -3811,7 +3959,7 @@ function decanonicalizeComponentValue(value, nodeToId) {
3811
3959
  if (Array.isArray(value)) {
3812
3960
  return value.map((item) => decanonicalizeComponentValue(item, nodeToId));
3813
3961
  }
3814
- const record = asRecord2(value);
3962
+ const record = asRecord3(value);
3815
3963
  if (record) {
3816
3964
  const result = {};
3817
3965
  for (const [key, item] of Object.entries(record)) {
@@ -3914,15 +4062,20 @@ function collectDiffPaths(base, current, prefix = "", out = []) {
3914
4062
  return out;
3915
4063
  }
3916
4064
  __name(collectDiffPaths, "collectDiffPaths");
3917
- function computeInstanceOverrides(baseSnapshot, instanceSnapshot) {
3918
- const baseMaps = buildNodeMapsFromSnapshot(baseSnapshot);
3919
- const instanceMaps = buildNodeMapsFromSnapshot(instanceSnapshot);
4065
+ function computeInstanceOverrides(baseSnapshot, instanceSnapshot, options) {
4066
+ const baseMaps = buildNodeKeyMapsFromSnapshot(baseSnapshot);
4067
+ const instanceMaps = buildNodeKeyMapsFromSnapshot(instanceSnapshot);
3920
4068
  const baseByEntity = indexSnapshotByEntity(baseSnapshot);
3921
4069
  const instanceByEntity = indexSnapshotByEntity(instanceSnapshot);
3922
4070
  const overrides = [];
3923
- for (const [nodeId, instanceEntityId] of instanceMaps.nodeToId) {
3924
- const baseEntityId = baseMaps.nodeToId.get(nodeId);
4071
+ for (const [nodeKey, instanceEntityId] of instanceMaps.keyToId) {
4072
+ const baseEntityId = baseMaps.keyToId.get(nodeKey);
3925
4073
  if (baseEntityId === void 0) {
4074
+ if (options?.emitAdditionMarkers) {
4075
+ overrides.push(
4076
+ encodeOverride(nodeKey, ADDED_NODE_MARKER_COMPONENT, "")
4077
+ );
4078
+ }
3926
4079
  continue;
3927
4080
  }
3928
4081
  const baseComponents = baseByEntity.get(baseEntityId);
@@ -3930,7 +4083,7 @@ function computeInstanceOverrides(baseSnapshot, instanceSnapshot) {
3930
4083
  if (!baseComponents) {
3931
4084
  continue;
3932
4085
  }
3933
- const isRoot = nodeId === baseMaps.rootNodeId;
4086
+ const isRoot = nodeKey === baseMaps.rootKey;
3934
4087
  for (const [componentName, baseRaw] of baseComponents) {
3935
4088
  if (OVERRIDE_DIFF_EXCLUDED_COMPONENTS.has(componentName)) {
3936
4089
  continue;
@@ -3945,15 +4098,15 @@ function computeInstanceOverrides(baseSnapshot, instanceSnapshot) {
3945
4098
  const baseCanonical = canonicalizeComponentValue(
3946
4099
  componentName,
3947
4100
  baseRaw,
3948
- baseMaps.idToNode
4101
+ baseMaps.idToKey
3949
4102
  );
3950
4103
  const instanceCanonical = canonicalizeComponentValue(
3951
4104
  componentName,
3952
4105
  instanceRaw,
3953
- instanceMaps.idToNode
4106
+ instanceMaps.idToKey
3954
4107
  );
3955
4108
  for (const path of collectDiffPaths(baseCanonical, instanceCanonical)) {
3956
- overrides.push(encodeOverride(nodeId, componentName, path));
4109
+ overrides.push(encodeOverride(nodeKey, componentName, path));
3957
4110
  }
3958
4111
  }
3959
4112
  }
@@ -3967,7 +4120,7 @@ function getAtPath(value, tokens) {
3967
4120
  if (Array.isArray(cursor)) {
3968
4121
  cursor = cursor[Number(token)];
3969
4122
  } else {
3970
- const record = asRecord2(cursor);
4123
+ const record = asRecord3(cursor);
3971
4124
  if (!record) {
3972
4125
  return void 0;
3973
4126
  }
@@ -3987,7 +4140,7 @@ function setAtPath(target, tokens, value) {
3987
4140
  if (Array.isArray(cursor)) {
3988
4141
  cursor = cursor[Number(token)];
3989
4142
  } else {
3990
- const record = asRecord2(cursor);
4143
+ const record = asRecord3(cursor);
3991
4144
  if (!record) {
3992
4145
  return;
3993
4146
  }
@@ -4001,7 +4154,7 @@ function setAtPath(target, tokens, value) {
4001
4154
  if (Array.isArray(cursor)) {
4002
4155
  cursor[Number(last)] = value;
4003
4156
  } else {
4004
- const record = asRecord2(cursor);
4157
+ const record = asRecord3(cursor);
4005
4158
  if (record) {
4006
4159
  if (value === void 0) {
4007
4160
  delete record[last];
@@ -4033,15 +4186,20 @@ __name(mergeComponentValue, "mergeComponentValue");
4033
4186
  var INSTANTIATE_EXCLUDED_COMPONENTS = /* @__PURE__ */ new Set([
4034
4187
  "Environment",
4035
4188
  "Postprocessing",
4036
- "SelectionTransformState",
4037
- "PrefabInstance"
4189
+ "SelectionTransformState"
4038
4190
  ]);
4039
4191
  function instantiateSubtree(world, objectManagementSystem, snapshot) {
4192
+ const snapshotRootIds = new Set(findSnapshotRootEntityIds(snapshot));
4040
4193
  const safeSnapshot = {
4041
4194
  entities: snapshot.entities,
4042
- components: snapshot.components.filter(
4043
- (block) => !INSTANTIATE_EXCLUDED_COMPONENTS.has(block.component)
4044
- )
4195
+ components: snapshot.components.filter((block) => !INSTANTIATE_EXCLUDED_COMPONENTS.has(block.component)).map(
4196
+ (block) => block.component === "PrefabInstance" ? {
4197
+ component: block.component,
4198
+ entries: block.entries.filter(
4199
+ (entry) => !snapshotRootIds.has(entry.entityId)
4200
+ )
4201
+ } : block
4202
+ ).filter((block) => block.entries.length > 0)
4045
4203
  };
4046
4204
  const result = hydrateWorldFromSnapshotDetailed(
4047
4205
  safeSnapshot,
@@ -4061,6 +4219,11 @@ __name(instantiateSubtree, "instantiateSubtree");
4061
4219
 
4062
4220
  // core/prefab/types.ts
4063
4221
  var PREFAB_FILE_VERSION = 1;
4222
+ var PREFAB_FILE_VERSION_NESTED = 2;
4223
+ function prefabFileVersionFor(snapshot) {
4224
+ return findTopLevelNestedRegions(snapshot).length > 0 ? PREFAB_FILE_VERSION_NESTED : PREFAB_FILE_VERSION;
4225
+ }
4226
+ __name(prefabFileVersionFor, "prefabFileVersionFor");
4064
4227
  var isRecord = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && !Array.isArray(value), "isRecord");
4065
4228
  function parsePrefabAsset(json) {
4066
4229
  if (!isRecord(json)) {
@@ -5282,6 +5445,6 @@ var _VideoSystem = class _VideoSystem {
5282
5445
  __name(_VideoSystem, "VideoSystem");
5283
5446
  var VideoSystem = _VideoSystem;
5284
5447
 
5285
- export { AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, HYDRATABLE_ENTITY_KINDS, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, OVERRIDE_DIFF_EXCLUDED_COMPONENTS, OVERRIDE_ROOT_EXCLUDED_COMPONENTS, ObjectVisibilitySystem, PREFAB_FILE_VERSION, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, ScriptBehaviourSystem, TransformSyncSystem, VideoSystem, buildComponentValueMaps, buildNodeMapsFromSnapshot, canonicalizeComponentValue, clearPrefabCache, collectDiffPaths, collectEntitySubtree, computeInstanceOverrides, decanonicalizeComponentValue, despawnPrefab, encodeOverride, findSnapshotRootEntityIds, groupOverridePaths, hydrateWorldFromSnapshot, hydrateWorldFromSnapshotDetailed, indexSnapshotByEntity, instantiateSubtree, loadPrefab, mergeComponentValue, parseOverride, parsePrefabAsset, restoreComponentState, restorePostCreateComponents, setPrefabAssetUrlResolver, spawnPrefab };
5286
- //# sourceMappingURL=chunk-67MFQDHX.js.map
5287
- //# sourceMappingURL=chunk-67MFQDHX.js.map
5448
+ export { ADDED_NODE_MARKER_COMPONENT, AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, HYDRATABLE_ENTITY_KINDS, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, NODE_KEY_SEPARATOR, OVERRIDE_DIFF_EXCLUDED_COMPONENTS, OVERRIDE_ROOT_EXCLUDED_COMPONENTS, ObjectVisibilitySystem, PREFAB_FILE_VERSION, PREFAB_FILE_VERSION_NESTED, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, ScriptBehaviourSystem, TransformSyncSystem, VideoSystem, buildComponentValueMaps, buildNodeKeyMapsFromSnapshot, buildNodeMapsFromSnapshot, canonicalizeComponentValue, clearPrefabCache, collectDiffPaths, collectEntitySubtree, collectSnapshotSubtreeIds, computeInstanceOverrides, decanonicalizeComponentValue, despawnPrefab, encodeOverride, findSnapshotRootEntityIds, findTopLevelNestedRegions, groupOverridePaths, hydrateWorldFromSnapshot, hydrateWorldFromSnapshotDetailed, indexSnapshotByEntity, instantiateSubtree, loadPrefab, mergeComponentValue, parseOverride, parsePrefabAsset, prefabFileVersionFor, restoreComponentState, restorePostCreateComponents, setPrefabAssetUrlResolver, spawnPrefab };
5449
+ //# sourceMappingURL=chunk-5U3YS4JD.js.map
5450
+ //# sourceMappingURL=chunk-5U3YS4JD.js.map