@nebula-spatial/studio 0.0.0-stage → 0.1.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 (251) hide show
  1. package/README.md +206 -3
  2. package/dist/ai/contract.d.ts +73 -0
  3. package/dist/ai/host.d.ts +28 -0
  4. package/dist/asset/dependency-scan.d.ts +78 -0
  5. package/dist/asset/intake.d.ts +84 -0
  6. package/dist/asset/layout-detect.d.ts +40 -0
  7. package/dist/asset/media-type.d.ts +10 -0
  8. package/dist/asset/model-inspection.d.ts +127 -0
  9. package/dist/asset/record.d.ts +35 -0
  10. package/dist/asset/remote-asset-resolver.d.ts +36 -0
  11. package/dist/asset/repairs.d.ts +53 -0
  12. package/dist/asset/resource-locator.d.ts +15 -0
  13. package/dist/asset/revision-diff.d.ts +33 -0
  14. package/dist/asset/source-contracts.d.ts +21 -0
  15. package/dist/asset/source-paths.d.ts +15 -0
  16. package/dist/asset/usd-inspection.d.ts +39 -0
  17. package/dist/asset/usd-source-metadata.d.ts +142 -0
  18. package/dist/asset/visual-intake.d.ts +27 -0
  19. package/dist/asset/visual-record.d.ts +22 -0
  20. package/dist/asset/web-intake.d.ts +46 -0
  21. package/dist/asset-source-BExlEcRt.js +444 -0
  22. package/dist/assets/usd-export-worker-BsGubtAE.js +1 -0
  23. package/dist/builders-BAXRR5o5.js +1854 -0
  24. package/dist/core/asset-task.d.ts +105 -0
  25. package/dist/core/context.d.ts +23 -0
  26. package/dist/core/host.d.ts +432 -0
  27. package/dist/core/persistence-controller.d.ts +58 -0
  28. package/dist/core/plugins.d.ts +139 -0
  29. package/dist/core/scene-tree.d.ts +62 -0
  30. package/dist/core/versions.d.ts +2 -0
  31. package/dist/core/when.d.ts +13 -0
  32. package/dist/core/write-policy.d.ts +29 -0
  33. package/dist/delivery/build-plan.d.ts +2 -0
  34. package/dist/delivery/contracts.d.ts +362 -0
  35. package/dist/delivery/digest.d.ts +3 -0
  36. package/dist/delivery/evidence.d.ts +10 -0
  37. package/dist/delivery/export-evidence.d.ts +3 -0
  38. package/dist/delivery/index.d.ts +9 -0
  39. package/dist/delivery/prim-name.d.ts +17 -0
  40. package/dist/delivery/profile.d.ts +4 -0
  41. package/dist/doc/builders.d.ts +99 -0
  42. package/dist/doc/command.d.ts +195 -0
  43. package/dist/doc/domain-extensions.d.ts +34 -0
  44. package/dist/doc/node-facts.d.ts +87 -0
  45. package/dist/doc/physics-facts.d.ts +74 -0
  46. package/dist/doc/placement-policy.d.ts +71 -0
  47. package/dist/doc/random-placement.d.ts +30 -0
  48. package/dist/doc/scene-graph.d.ts +80 -0
  49. package/dist/doc/scene-regions.d.ts +29 -0
  50. package/dist/doc/schema.d.ts +452 -0
  51. package/dist/doc/task.d.ts +71 -0
  52. package/dist/doc/validate.d.ts +68 -0
  53. package/dist/editor/asset-source.d.ts +15 -0
  54. package/dist/editor/editor.d.ts +246 -0
  55. package/dist/editor/index.d.ts +22 -0
  56. package/dist/editor/shortcuts.d.ts +2 -0
  57. package/dist/editor/types.d.ts +143 -0
  58. package/dist/editor/ui-plugins.d.ts +64 -0
  59. package/dist/editor.js +1755 -0
  60. package/dist/editorial-BkAFWfbg.js +83 -0
  61. package/dist/export-evidence-B_0zRmb8.js +5027 -0
  62. package/dist/generalization/domain.d.ts +10 -0
  63. package/dist/generalization/generalization.d.ts +371 -0
  64. package/dist/generalization/index.d.ts +11 -0
  65. package/dist/generalization.js +1659 -0
  66. package/dist/history/undo-stack.d.ts +74 -0
  67. package/dist/index.d.ts +91 -0
  68. package/dist/index.js +2839 -0
  69. package/dist/persist/content-addressed.d.ts +11 -0
  70. package/dist/persist/create-scene-package-from-host.d.ts +7 -0
  71. package/dist/persist/indexeddb-store.d.ts +69 -0
  72. package/dist/persist/scene-file.d.ts +52 -0
  73. package/dist/persist/scene-package.d.ts +8 -0
  74. package/dist/persist/snapshot.d.ts +5 -0
  75. package/dist/physics-facts-tfQYyNTD.js +337 -0
  76. package/dist/placement-policy-DY_FNRDu.js +405 -0
  77. package/dist/ports/asset-ingestor.d.ts +41 -0
  78. package/dist/ports/asset-source.d.ts +57 -0
  79. package/dist/ports/delivery.d.ts +13 -0
  80. package/dist/ports/persistence.d.ts +29 -0
  81. package/dist/project/asset-catalog.d.ts +21 -0
  82. package/dist/project/contracts.d.ts +272 -0
  83. package/dist/project/editorial.d.ts +16 -0
  84. package/dist/project/identity.d.ts +20 -0
  85. package/dist/project/index.d.ts +9 -0
  86. package/dist/project/scene-document.d.ts +5 -0
  87. package/dist/project/source-dependencies.d.ts +7 -0
  88. package/dist/remote-asset-resolver-Cb8cfNmw.js +136 -0
  89. package/dist/scene/index.d.ts +12 -0
  90. package/dist/scene-graph-DBLKAhxa.js +681 -0
  91. package/dist/scene-session-BV1HnxNh.js +3506 -0
  92. package/dist/scene.js +244 -0
  93. package/dist/studio/delivery-catalog.d.ts +28 -0
  94. package/dist/studio/in-memory-asset-source.d.ts +15 -0
  95. package/dist/studio/index.d.ts +31 -0
  96. package/dist/studio/indexeddb-asset-source.d.ts +32 -0
  97. package/dist/studio/indexeddb-persistence.d.ts +13 -0
  98. package/dist/studio/remote-asset-importer.d.ts +56 -0
  99. package/dist/studio/source-package.d.ts +9 -0
  100. package/dist/studio/usd-export-client.d.ts +13 -0
  101. package/dist/studio/usd-export-protocol.d.ts +98 -0
  102. package/dist/studio/usd-export-worker.d.ts +1 -0
  103. package/dist/studio/usd-zip-reader.d.ts +14 -0
  104. package/dist/studio/web-asset-ingestor.d.ts +10 -0
  105. package/dist/studio/web-host.d.ts +8 -0
  106. package/dist/studio.js +5544 -0
  107. package/dist/util/asset-facts.d.ts +3 -0
  108. package/dist/util/data.d.ts +17 -0
  109. package/dist/util/diagnostics.d.ts +38 -0
  110. package/dist/util/geometry.d.ts +11 -0
  111. package/dist/util/hash.d.ts +9 -0
  112. package/dist/util/ids.d.ts +20 -0
  113. package/dist/util/math.d.ts +47 -0
  114. package/dist/util/ply-metadata.d.ts +19 -0
  115. package/dist/util/studio-source.d.ts +23 -0
  116. package/dist/version.d.ts +5 -0
  117. package/dist/view/appearance.d.ts +13 -0
  118. package/dist/view/authoring-appearance.d.ts +25 -0
  119. package/dist/view/bounds-preview.d.ts +34 -0
  120. package/dist/view/bounds.d.ts +11 -0
  121. package/dist/view/camera-zoom.d.ts +3 -0
  122. package/dist/view/geometry-anchors.d.ts +20 -0
  123. package/dist/view/gizmo-appearance.d.ts +5 -0
  124. package/dist/view/gizmo.d.ts +81 -0
  125. package/dist/view/group-selection.d.ts +13 -0
  126. package/dist/view/node-features.d.ts +39 -0
  127. package/dist/view/picking.d.ts +49 -0
  128. package/dist/view/placement.d.ts +48 -0
  129. package/dist/view/region-editing.d.ts +25 -0
  130. package/dist/view/rotation-guide.d.ts +36 -0
  131. package/dist/view/runtime-capabilities.d.ts +22 -0
  132. package/dist/view/scene-session.d.ts +258 -0
  133. package/dist/view/screen-bounds.d.ts +17 -0
  134. package/dist/view/selection-transform.d.ts +20 -0
  135. package/node_modules/@nebula-spatial/cad-loader/CHANGELOG.md +48 -0
  136. package/node_modules/@nebula-spatial/cad-loader/README.md +108 -0
  137. package/node_modules/@nebula-spatial/cad-loader/dist/core/cad-types.d.ts +26 -0
  138. package/node_modules/@nebula-spatial/cad-loader/dist/core/errors.d.ts +5 -0
  139. package/node_modules/@nebula-spatial/cad-loader/dist/core/index.d.ts +24 -0
  140. package/node_modules/@nebula-spatial/cad-loader/dist/core/index.js +2354 -0
  141. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/bin-group-reader.d.ts +9 -0
  142. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/bin-parser.d.ts +78 -0
  143. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/dxbs-sidecar.d.ts +24 -0
  144. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/geometry-segments.d.ts +20 -0
  145. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/text-roundtrip.d.ts +4 -0
  146. package/node_modules/@nebula-spatial/cad-loader/dist/core/parser/types.d.ts +81 -0
  147. package/node_modules/@nebula-spatial/cad-loader/dist/core/runtime-text-decoder.d.ts +8 -0
  148. package/node_modules/@nebula-spatial/cad-loader/dist/core/types.d.ts +153 -0
  149. package/node_modules/@nebula-spatial/cad-loader/dist/core/utils/insert-bbox.d.ts +10 -0
  150. package/node_modules/@nebula-spatial/cad-loader/dist/core/utils/viewport-rect.d.ts +21 -0
  151. package/node_modules/@nebula-spatial/cad-loader/dist/index.d.ts +36 -0
  152. package/node_modules/@nebula-spatial/cad-loader/dist/index.js +5829 -0
  153. package/node_modules/@nebula-spatial/cad-loader/dist/loader/geo-loader.d.ts +59 -0
  154. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/automatic-external-resources.d.ts +26 -0
  155. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/external-variant-sidecar-fetch.d.ts +13 -0
  156. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/flow-control.d.ts +29 -0
  157. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/frame-budget-scheduler.d.ts +21 -0
  158. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-compact-executor.d.ts +19 -0
  159. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-loader-local-adapter.d.ts +2 -0
  160. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-loader-pipeline.d.ts +92 -0
  161. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-loader-worker-adapter.d.ts +13 -0
  162. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-node-builder.d.ts +34 -0
  163. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-node-load-sink.d.ts +28 -0
  164. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-node.d.ts +304 -0
  165. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-prepare-worker-types.d.ts +94 -0
  166. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-prepare.d.ts +38 -0
  167. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/geo-prepare.worker.d.ts +1 -0
  168. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/insert-model-builder.d.ts +10 -0
  169. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/insert-runtime-geometry.d.ts +15 -0
  170. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/line-canonical.d.ts +37 -0
  171. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/line-quality.d.ts +9 -0
  172. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/prepare-credit-gate.d.ts +20 -0
  173. package/node_modules/@nebula-spatial/cad-loader/dist/loader/internal/transport.d.ts +2 -0
  174. package/node_modules/@nebula-spatial/cad-loader/dist/render-resource/cad-render-node.d.ts +80 -0
  175. package/node_modules/@nebula-spatial/cad-loader/dist/render-resource/geo-node-cad-render-node.d.ts +12 -0
  176. package/node_modules/@nebula-spatial/cad-loader/dist/scene/geo-cad-line-geometry.d.ts +28 -0
  177. package/node_modules/@nebula-spatial/cad-loader/dist/scene/geo-cad-line-material.d.ts +18 -0
  178. package/node_modules/@nebula-spatial/cad-loader/dist/scene/instancing/block-geometry-registry.d.ts +35 -0
  179. package/node_modules/@nebula-spatial/cad-loader/dist/scene/instancing/insert-instance-table.d.ts +23 -0
  180. package/node_modules/@nebula-spatial/cad-loader/dist/scene/instancing/viewport-instance-presenter.d.ts +66 -0
  181. package/node_modules/@nebula-spatial/cad-loader/dist/selection/cad-insert-selection.d.ts +35 -0
  182. package/node_modules/@nebula-spatial/cad-loader/dist/selection/cad-text-selection.d.ts +31 -0
  183. package/node_modules/@nebula-spatial/cad-loader/dist/session/annotation-idle-gate.d.ts +14 -0
  184. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-document-session.d.ts +187 -0
  185. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-font-runtime.d.ts +11 -0
  186. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-insert-id.d.ts +6 -0
  187. package/node_modules/@nebula-spatial/cad-loader/dist/session/cad-text-warmup.d.ts +38 -0
  188. package/node_modules/@nebula-spatial/cad-loader/dist/session/create-cad-document-session.d.ts +5 -0
  189. package/node_modules/@nebula-spatial/cad-loader/dist/session/load-session.d.ts +90 -0
  190. package/node_modules/@nebula-spatial/cad-loader/dist/session/viewport-coverage.d.ts +32 -0
  191. package/node_modules/@nebula-spatial/cad-loader/dist/shared/abort.d.ts +3 -0
  192. package/node_modules/@nebula-spatial/cad-loader/dist/shared/cad-display-color.d.ts +55 -0
  193. package/node_modules/@nebula-spatial/cad-loader/dist/shared/cad-load-source.d.ts +8 -0
  194. package/node_modules/@nebula-spatial/cad-loader/dist/shared/color-buffer.d.ts +6 -0
  195. package/node_modules/@nebula-spatial/cad-loader/dist/shared/constants.d.ts +11 -0
  196. package/node_modules/@nebula-spatial/cad-loader/dist/shared/display-color-buffer.d.ts +27 -0
  197. package/node_modules/@nebula-spatial/cad-loader/dist/shared/errors.d.ts +2 -0
  198. package/node_modules/@nebula-spatial/cad-loader/dist/shared/text-builder.d.ts +25 -0
  199. package/node_modules/@nebula-spatial/cad-loader/dist/shared/text-font.d.ts +12 -0
  200. package/node_modules/@nebula-spatial/cad-loader/dist/shared/types.d.ts +57 -0
  201. package/node_modules/@nebula-spatial/cad-loader/dist/shared/utils/insert-bbox.d.ts +1 -0
  202. package/node_modules/@nebula-spatial/cad-loader/dist/shared/utils/timing.d.ts +2 -0
  203. package/node_modules/@nebula-spatial/cad-loader/dist/shared/utils/viewport-rect.d.ts +1 -0
  204. package/node_modules/@nebula-spatial/cad-loader/dist/shared/viewer-theme.d.ts +2 -0
  205. package/node_modules/@nebula-spatial/cad-loader/dist/workers/geo-prepare.worker.js +2264 -0
  206. package/node_modules/@nebula-spatial/cad-loader/package.json +62 -0
  207. package/node_modules/@nebula-spatial/viewer/CHANGELOG.md +426 -0
  208. package/node_modules/@nebula-spatial/viewer/FBX-MATERIAL-CONVERSION.md +97 -0
  209. package/node_modules/@nebula-spatial/viewer/README.md +1056 -0
  210. package/node_modules/@nebula-spatial/viewer/USD-VISUAL-MATERIAL-SUPPORT.md +89 -0
  211. package/node_modules/@nebula-spatial/viewer/basis/basis_transcoder.js +19 -0
  212. package/node_modules/@nebula-spatial/viewer/basis/basis_transcoder.wasm +0 -0
  213. package/node_modules/@nebula-spatial/viewer/dist/asset-ir-DEOK9SqE.js +382 -0
  214. package/node_modules/@nebula-spatial/viewer/dist/assets/ground-grid.d.ts +6 -0
  215. package/node_modules/@nebula-spatial/viewer/dist/assets/source-types.d.ts +19 -0
  216. package/node_modules/@nebula-spatial/viewer/dist/assets/types.d.ts +393 -0
  217. package/node_modules/@nebula-spatial/viewer/dist/assets/usd-worker-Bom5cjz3.js +1392 -0
  218. package/node_modules/@nebula-spatial/viewer/dist/cad/text.d.ts +2 -0
  219. package/node_modules/@nebula-spatial/viewer/dist/cad/types.d.ts +368 -0
  220. package/node_modules/@nebula-spatial/viewer/dist/index-ByBlfVc0.js +12132 -0
  221. package/node_modules/@nebula-spatial/viewer/dist/index.d.ts +32 -0
  222. package/node_modules/@nebula-spatial/viewer/dist/index.js +26 -0
  223. package/node_modules/@nebula-spatial/viewer/dist/inspection/types.d.ts +112 -0
  224. package/node_modules/@nebula-spatial/viewer/dist/mjcf-visual-DVRa0w90.js +72 -0
  225. package/node_modules/@nebula-spatial/viewer/dist/mujoco-runtime-Dhx6Ua2u.js +463 -0
  226. package/node_modules/@nebula-spatial/viewer/dist/plugins.d.ts +179 -0
  227. package/node_modules/@nebula-spatial/viewer/dist/scene/instances.d.ts +36 -0
  228. package/node_modules/@nebula-spatial/viewer/dist/scene/types.d.ts +258 -0
  229. package/node_modules/@nebula-spatial/viewer/dist/session-B-j6KdA-.js +389 -0
  230. package/node_modules/@nebula-spatial/viewer/dist/session-B4AICTeJ.js +963 -0
  231. package/node_modules/@nebula-spatial/viewer/dist/session-BAG5cDYe.js +9153 -0
  232. package/node_modules/@nebula-spatial/viewer/dist/simulation/mujoco-runtime.d.ts +118 -0
  233. package/node_modules/@nebula-spatial/viewer/dist/simulation/mujoco-wasm-module.d.ts +11 -0
  234. package/node_modules/@nebula-spatial/viewer/dist/simulation/openusd-wasm-module.d.ts +10 -0
  235. package/node_modules/@nebula-spatial/viewer/dist/simulation/physics-runtime-state.d.ts +75 -0
  236. package/node_modules/@nebula-spatial/viewer/dist/simulation/types.d.ts +129 -0
  237. package/node_modules/@nebula-spatial/viewer/dist/simulation/usd-inspection.d.ts +66 -0
  238. package/node_modules/@nebula-spatial/viewer/dist/simulation/usd-query.d.ts +50 -0
  239. package/node_modules/@nebula-spatial/viewer/dist/simulation/usd-resource-policy.d.ts +28 -0
  240. package/node_modules/@nebula-spatial/viewer/dist/types.d.ts +278 -0
  241. package/node_modules/@nebula-spatial/viewer/dist/ui/types.d.ts +48 -0
  242. package/node_modules/@nebula-spatial/viewer/dist/urdf-session-kemAnBn8.js +3231 -0
  243. package/node_modules/@nebula-spatial/viewer/dist/usd-session-QtwGKI7v.js +6771 -0
  244. package/node_modules/@nebula-spatial/viewer/dist/version.d.ts +5 -0
  245. package/node_modules/@nebula-spatial/viewer/dist/viewer.d.ts +2 -0
  246. package/node_modules/@nebula-spatial/viewer/dist/xacro-CYTPS7mh.js +1537 -0
  247. package/node_modules/@nebula-spatial/viewer/openusd/openusd-runtime-manifest.json +15 -0
  248. package/node_modules/@nebula-spatial/viewer/openusd/openusd_probe.js +14 -0
  249. package/node_modules/@nebula-spatial/viewer/openusd/openusd_probe.wasm +0 -0
  250. package/node_modules/@nebula-spatial/viewer/package.json +66 -0
  251. package/package.json +87 -6
package/dist/editor.js ADDED
@@ -0,0 +1,1755 @@
1
+ var we = Object.defineProperty;
2
+ var ye = (l, e, t) => e in l ? we(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t;
3
+ var I = (l, e, t) => ye(l, typeof e != "symbol" ? e + "" : e, t);
4
+ import { a as A, Y as ce, b as le, d as Ee, U as B, J as Ae, P as Te, L as Ne, I as Oe, q as Pe, f as _e, x as De, t as Re, V as Ve, e as Ce } from "./builders-BAXRR5o5.js";
5
+ import { z as y, d as Q, a as q, V as X, s as x, E as Le, w as V, W as k, Z as de, k as xe, U as he, M as G, N as $, X as Me, _ as Fe, $ as Ue, a0 as j, a1 as Be, B as H, a2 as ue, a3 as ke } from "./scene-graph-DBLKAhxa.js";
6
+ import { p as Ge, q as $e } from "./asset-source-BExlEcRt.js";
7
+ import { v as je, D as We, n as Ye, q as pe, h as me } from "./placement-policy-DY_FNRDu.js";
8
+ import { e as W, g as Ke, f as ze } from "./physics-facts-tfQYyNTD.js";
9
+ import { c as Xe, t as He } from "./scene-session-BV1HnxNh.js";
10
+ import { S as ge, i as Ze } from "./remote-asset-resolver-Cb8cfNmw.js";
11
+ import { c as Je, a as Qe } from "./editorial-BkAFWfbg.js";
12
+ const M = (l) => l !== null && typeof l == "object" && !Array.isArray(l) ? l : null, Y = (l) => Array.isArray(l) ? l.map(M).filter((e) => e !== null) : null, qe = (l, e) => Array.isArray(l) && l.length === e && l.every((t) => typeof t == "number" && Number.isFinite(t)), et = (l) => typeof l == "number" && Number.isFinite(l) && l > 0;
13
+ function E(l, e, t, s, o = !1) {
14
+ return { present: l, available: e, canVisualize: o, source: t, reason: s };
15
+ }
16
+ function K(l, e, t, s = !1) {
17
+ if (!l) return null;
18
+ const n = l.map((a) => {
19
+ var i;
20
+ return t === "authored" ? (i = M(a.mass)) == null ? void 0 : i[e] : a[e];
21
+ }).filter((a) => a != null);
22
+ if (!n.length) return null;
23
+ const d = n.every((a) => qe(a, 3) && (e === "centerOfMass" || a.every((i) => i > 0)));
24
+ return E(!0, d, t, d ? s ? "Finite body data is available and the mounted runtime can display its inspection guide." : "Finite body data is available; the mounted runtime does not expose a viewport overlay for it." : "The feature is declared, but its values are incomplete or invalid.", d && s);
25
+ }
26
+ function tt(l, e, t) {
27
+ var se, oe, ie, ne, re;
28
+ const s = y(l.root, e);
29
+ if (!s) return null;
30
+ const o = s.nodeType === "asset" ? l.assets.find((w) => w.revisionId === s.assetRevisionId) : void 0, n = s.nodeType === "visual" ? l.visualAssets.find((w) => w.visualRevisionId === s.visualRevisionId) : void 0, d = s.nodeType !== "asset" || (o == null ? void 0 : o.fileKind) === "glb" || (o == null ? void 0 : o.capabilities.physics) === "none", a = M((se = t == null ? void 0 : t.visualDiagnostics) == null ? void 0 : se.usd), i = M(a == null ? void 0 : a.stage), c = M(a == null ? void 0 : a.physics), h = Y(c == null ? void 0 : c.colliders), u = Y(c == null ? void 0 : c.rigidBodies), p = Y(c == null ? void 0 : c.joints), v = t != null && t.physicsRuntime ? t.physicsRuntime.bodies.filter((w) => {
31
+ var ae;
32
+ return ((ae = t.physicsRuntime) == null ? void 0 : ae.worldKind) !== "scene-unified" || w.instanceId === e;
33
+ }) : null, S = Y((oe = t == null ? void 0 : t.physicsProperties) == null ? void 0 : oe.bodies), r = v != null && v.length ? v.map((w) => ({ centerOfMass: w.centerOfMass, inertia: w.inertia })) : S, f = t == null ? void 0 : t.inspectionOverlays, m = (w) => d || c ? E(!1, !1, "none", `${w} is not present in this node's inspected data.`) : E(null, !1, "unknown", `${w} has not been established; source inspection is unavailable.`), T = ((ie = t == null ? void 0 : t.capabilities) == null ? void 0 : ie.canToggleCollision) === !0 ? E(!0, !0, "runtime", "The mounted instance supports collision geometry display.", !0) : h ? h.length ? E(!0, !1, "authored", "Collision geometry is authored, but the mounted instance cannot currently display it.") : E(!1, !1, "none", "The inspected asset has no authored collision geometry.") : o != null && o.capabilities.colliderGeometry ? E(!0, !1, "authored", "The asset declares collision geometry; its runtime display is not ready.") : m("Collision geometry"), _ = typeof (i == null ? void 0 : i.upAxis) == "string" ? i.upAxis.toUpperCase() : null, D = _ === "X" || _ === "Y" || _ === "Z" ? _ : null, N = D ?? (n ? n.upAxis === "y-down" ? "-Y" : n.upAxis.toUpperCase() : null) ?? ((o == null ? void 0 : o.fileKind) === "glb" ? "Y" : null), F = et(i == null ? void 0 : i.metersPerUnit) ? i.metersPerUnit : (o == null ? void 0 : o.fileKind) === "glb" || (n == null ? void 0 : n.format) === "glb" || (n == null ? void 0 : n.format) === "gltf" ? 1 : null, R = D || n ? "authored" : (o == null ? void 0 : o.fileKind) === "glb" ? "format" : "unknown", z = {
34
+ ...E(
35
+ N ? !0 : s.nodeType === "asset" ? null : !0,
36
+ !0,
37
+ R,
38
+ N ? "Source axis and the scene coordinate convention are available. Scene transforms use the scene convention." : "The scene coordinate convention is available; the source asset axis has not been established.",
39
+ // Coordinate axes are drawn by Sim Studio's authoring overlay rather
40
+ // than by a format/runtime inspection session. They are therefore
41
+ // available for every rendered node, even before its asset is mounted;
42
+ // a pre-mount request is reported as `pending` by the session API.
43
+ s.nodeType !== "domain"
44
+ ),
45
+ scene: l.coordinateSystem,
46
+ sourceUpAxis: N,
47
+ sourceMetersPerUnit: F
48
+ }, C = (p == null ? void 0 : p.filter((w) => w.axis !== void 0 && w.axis !== null)) ?? [], O = C.length ? E(
49
+ !0,
50
+ C.every((w) => typeof w.axis == "string" && /^[XYZ]$/i.test(w.axis)),
51
+ "authored",
52
+ (f == null ? void 0 : f.jointAxis) === !0 ? "Joint axis declarations and the mounted runtime inspection guide are available." : "Joint axis declarations can be inspected; the mounted runtime does not expose a joint-axis viewport overlay.",
53
+ (f == null ? void 0 : f.jointAxis) === !0
54
+ ) : (f == null ? void 0 : f.jointAxis) === !0 ? E(!0, !0, "runtime", "The mounted URDF inspection runtime can display joint-axis guides.", !0) : m("Joint axes"), U = K(r, "centerOfMass", "runtime", (f == null ? void 0 : f.centerOfMass) === !0) ?? K(u, "centerOfMass", "authored", (f == null ? void 0 : f.centerOfMass) === !0) ?? ((f == null ? void 0 : f.centerOfMass) === !0 ? E(!0, !0, "runtime", "The mounted URDF inspection runtime can display center-of-mass guides.", !0) : null) ?? m("Center of mass"), Ie = K(r, "inertia", "runtime", (f == null ? void 0 : f.inertia) === !0) ?? K(u, "diagonalInertia", "authored", (f == null ? void 0 : f.inertia) === !0) ?? ((f == null ? void 0 : f.inertia) === !0 ? E(!0, !0, "runtime", "The mounted URDF inspection runtime can display inertia guides.", !0) : null) ?? m("Inertia"), P = t == null ? void 0 : t.physics, L = P == null ? void 0 : P.status, Se = (o == null ? void 0 : o.capabilities.physics) === "authored", te = ((ne = t == null ? void 0 : t.capabilities) == null ? void 0 : ne.hasPhysics) === !0 || Se, be = L === "unavailable" ? E(te ? !0 : null, !1, "runtime", (P == null ? void 0 : P.status) === "unavailable" ? P.issue.message : "Physics runtime is unavailable.") : L === "initializing" ? E(!0, !1, "runtime", "The physics runtime is still initializing.") : L === "not-authored" ? E(!1, !1, "none", "The mounted instance has no authored simulation physics.") : L === "ready" || L === "available" || ((re = t == null ? void 0 : t.capabilities) == null ? void 0 : re.hasPhysics) === !0 && t.capabilities.canPlay === !0 ? E(!0, !0, "runtime", "The mounted instance supports physics simulation.") : te ? E(!0, !1, "authored", "Physics is authored, but the runtime is not ready.") : m("Simulation physics");
55
+ return Q(q({ nodeId: e, nodeType: s.nodeType, collider: T, coordinateSystem: z, jointAxes: O, centerOfMass: U, inertia: Ie, simulation: be }));
56
+ }
57
+ async function ve(l, e, t = {}) {
58
+ var d;
59
+ if (l.kind === "local-package")
60
+ return {
61
+ source: {
62
+ kind: "files",
63
+ entry: l.entryPath,
64
+ files: l.files.map((a) => {
65
+ const i = Ge(a.locator);
66
+ if (!i) throw new Error("Local asset source contains a remote resource.");
67
+ return { path: i, file: a.blob };
68
+ })
69
+ },
70
+ filename: l.entryPath,
71
+ ...e.length ? { openOptions: { usdVariantSelections: e } } : {}
72
+ };
73
+ const s = t.remoteResolver ?? new ge(l), o = await s.entryBlob(t.signal), n = new URL(l.entryUrl).pathname.split("/").pop() || "root.usda";
74
+ return {
75
+ source: {
76
+ kind: "remote-entry",
77
+ entryPath: n,
78
+ entryUrl: l.entryUrl,
79
+ entry: o,
80
+ ...(d = t.resourcePaths) != null && d.length ? { resourcePaths: [...new Set(t.resourcePaths)] } : {},
81
+ resourceResolver: {
82
+ resolve: (a, i) => s.resolve(a, i)
83
+ }
84
+ },
85
+ filename: n,
86
+ openOptions: {
87
+ usdExternalReferenceMode: "complete",
88
+ ...e.length ? { usdVariantSelections: e } : {}
89
+ }
90
+ };
91
+ }
92
+ async function st(l, e, t, s = {}) {
93
+ const o = await ve(l, [], s);
94
+ return {
95
+ ...o,
96
+ openOptions: {
97
+ ...o.openOptions,
98
+ upAxis: e.upAxis,
99
+ visualSelectionMode: t.selectionMode,
100
+ ...t.appearance ? {
101
+ visualAppearance: {
102
+ ...t.appearance.color ? { color: t.appearance.color } : {},
103
+ ...t.appearance.opacity !== void 0 ? { opacity: t.appearance.opacity } : {}
104
+ }
105
+ } : {}
106
+ }
107
+ };
108
+ }
109
+ function ot(l, e) {
110
+ const t = l.ownerDocument;
111
+ if (!(t != null && t.addEventListener) || !l.addEventListener) return () => {
112
+ };
113
+ const s = l.getAttribute("tabindex");
114
+ s === null && (l.tabIndex = 0);
115
+ const o = l.closest("[data-viewer-layout-host]") ?? l.parentElement ?? l, n = (a) => {
116
+ const i = a.composedPath()[0], c = typeof (i == null ? void 0 : i.closest) == "function" && i.closest('input,textarea,select,button,a[href],[contenteditable]:not([contenteditable="false"]),[role="textbox"],[role="button"],[data-studio-ui-plugin],dialog');
117
+ i === l || i && !c && o.contains(i) ? l.focus({ preventScroll: !0 }) : l.getRootNode().activeElement === l && l.blur();
118
+ }, d = (a) => {
119
+ const i = l.getRootNode();
120
+ if (a.defaultPrevented || a.isComposing || i.activeElement !== l) return;
121
+ const c = a.composedPath();
122
+ !c.includes(l) || c.some((h) => h === l || typeof h.matches != "function" ? !1 : h.matches('input,textarea,select,button,a[href],[contenteditable]:not([contenteditable="false"]),[role="textbox"],[data-studio-ui-plugin],dialog')) || e(a) && (a.preventDefault(), a.stopPropagation());
123
+ };
124
+ return t.addEventListener("pointerdown", n, !0), t.addEventListener("keydown", d), () => {
125
+ t.removeEventListener("pointerdown", n, !0), t.removeEventListener("keydown", d), s === null && l.getAttribute("tabindex") === "0" && l.removeAttribute("tabindex");
126
+ };
127
+ }
128
+ class g extends Error {
129
+ constructor(e, t) {
130
+ super(t), this.code = e, this.name = "StudioEditorError";
131
+ }
132
+ }
133
+ class it {
134
+ constructor(e, t = {}) {
135
+ I(this, "host");
136
+ I(this, "session");
137
+ I(this, "ready");
138
+ I(this, "listeners", /* @__PURE__ */ new Set());
139
+ I(this, "unsubscribeHost");
140
+ I(this, "writePolicy");
141
+ I(this, "releaseWritePolicy");
142
+ I(this, "actionReader", Object.freeze({
143
+ getSnapshot: () => this.getSnapshot(),
144
+ getNodeFrame: (e) => this.getNodeFrame(e),
145
+ getNodeOriginAnchors: (e) => this.getNodeOriginAnchors(e),
146
+ getNodeOrigin: (e) => this.getNodeOrigin(e),
147
+ getNodeOrientation: (e) => this.getNodeOrientation(e),
148
+ getSelectionFrame: () => this.getSelectionFrame(),
149
+ getAssetDimensions: (e) => this.getAssetDimensions(e),
150
+ getPhysicsFacts: (e) => this.getPhysicsFacts(e)
151
+ }));
152
+ I(this, "actionDefinitions", /* @__PURE__ */ new Map());
153
+ I(this, "actionControllers", /* @__PURE__ */ new Map());
154
+ I(this, "remoteResolvers", /* @__PURE__ */ new Map());
155
+ I(this, "coreActionBusy", /* @__PURE__ */ new Set());
156
+ I(this, "sceneSessionId", `session_${A()}`);
157
+ I(this, "selectionVersion", 0);
158
+ I(this, "contextVersion", 0);
159
+ I(this, "overlaySequence", 0);
160
+ I(this, "mode", "translate");
161
+ I(this, "snap", !1);
162
+ I(this, "transactionBounds", /* @__PURE__ */ new Map());
163
+ I(this, "placementPolicy", We);
164
+ I(this, "transformSpace", "world");
165
+ I(this, "actionVisibility", /* @__PURE__ */ new Map());
166
+ I(this, "transformOrigins", /* @__PURE__ */ new Map());
167
+ I(this, "groundVisible", !0);
168
+ I(this, "collisionVisible", !1);
169
+ I(this, "editingEnabled", !0);
170
+ I(this, "previewMode", !1);
171
+ I(this, "previewSelection", "none");
172
+ I(this, "boxSelectionEnabled", !1);
173
+ I(this, "previewDocument", null);
174
+ I(this, "placementPreviewActive", !1);
175
+ I(this, "sceneStatus", null);
176
+ I(this, "overlay", { x: 0, y: 0, visible: !1, transforming: !1, hiddenReason: "no-selection" });
177
+ I(this, "disposed", !1);
178
+ I(this, "disposal", null);
179
+ I(this, "syncEpoch", 0);
180
+ I(this, "releaseShortcuts");
181
+ var o, n, d, a;
182
+ this.options = e, this.host = e.host, this.writePolicy = {
183
+ check: (i) => {
184
+ var u;
185
+ if ((u = this.session) != null && u.isSimulationRunning())
186
+ return {
187
+ allowed: !1,
188
+ code: "SIMULATION_RUNNING",
189
+ message: "Pause or stop the simulation before writing, navigating history or replacing the scene."
190
+ };
191
+ if (i.kind === "open" || i.kind === "replace")
192
+ return { allowed: !0 };
193
+ if (this.previewDocument)
194
+ return {
195
+ allowed: !1,
196
+ code: "PREVIEW_READ_ONLY",
197
+ message: "Document writes are disabled while an isolated preview is active."
198
+ };
199
+ if (this.previewMode)
200
+ return {
201
+ allowed: !1,
202
+ code: "PREVIEW_READ_ONLY",
203
+ message: "Document writes are disabled while preview mode is active."
204
+ };
205
+ if (!this.editingEnabled)
206
+ return {
207
+ allowed: !1,
208
+ code: "EDITING_DISABLED",
209
+ message: "The current editor session is read-only."
210
+ };
211
+ if (this.gestureActive() && !i.gestureCommit && ["document", "editorial", "asset"].includes(i.kind))
212
+ return {
213
+ allowed: !1,
214
+ code: "GESTURE_ACTIVE",
215
+ message: "Finish or cancel the active gesture before writing the scene."
216
+ };
217
+ const c = i.kind === "editorial" ? void 0 : i.targetNodeIds.find((p) => X(
218
+ this.host.document.root,
219
+ p,
220
+ this.host.getSnapshot().editorial
221
+ ));
222
+ if (c)
223
+ return {
224
+ allowed: !1,
225
+ code: "NODE_LOCKED",
226
+ message: `Scene node is locked: ${c}`
227
+ };
228
+ const h = i.nextDocument;
229
+ if (h)
230
+ try {
231
+ this.assertProjectionRepresentable(h.root);
232
+ } catch (p) {
233
+ if (p instanceof g)
234
+ return { allowed: !1, code: p.code, message: p.message };
235
+ throw p;
236
+ }
237
+ if (h && this.placementPolicy.preventOverlap) {
238
+ const p = je(
239
+ this.host.document,
240
+ h,
241
+ this.placementPolicy,
242
+ (v) => {
243
+ var m;
244
+ const S = this.transactionBounds.get(v.nodeId);
245
+ if (S) return S;
246
+ const r = y(this.host.document.root, v.nodeId);
247
+ return !r || r.nodeType !== v.nodeType || v.nodeType === "asset" && (r.nodeType !== "asset" || v.assetRevisionId !== r.assetRevisionId) || v.nodeType === "visual" && (r.nodeType !== "visual" || v.visualRevisionId !== r.visualRevisionId) || !x(
248
+ W(this.host.document, r),
249
+ W(h, v)
250
+ ) ? null : ((m = this.session.getNodeFrame(v.nodeId)) == null ? void 0 : m.localBounds) ?? null;
251
+ },
252
+ new Set(i.allowOverlapNodeIds ?? []),
253
+ i.supportContacts
254
+ );
255
+ if (p.length)
256
+ return {
257
+ allowed: !1,
258
+ code: p[0].code,
259
+ message: p.map((v) => v.message).join("; ")
260
+ };
261
+ }
262
+ return { allowed: !0 };
263
+ }
264
+ }, this.releaseWritePolicy = Ze(this.host, this.writePolicy), this.installBuiltInActions();
265
+ const s = e.sessionOptions ?? {};
266
+ this.session = (t.createSession ?? Xe)({
267
+ ...s,
268
+ viewport: e.viewport,
269
+ canvas: e.canvas,
270
+ resolveSource: e.resolveSource ?? (async (i, c, h, u) => {
271
+ u == null || u.stage("resolving-source", "正在解析资产来源...");
272
+ const p = await this.host.resolveAssetSource(i, { signal: h }), v = Object.entries((c == null ? void 0 : c.variantSelections) ?? {}).map(([f, m]) => ({ primPath: "/", setName: f, selection: m }));
273
+ if (!p) return null;
274
+ u == null || u.stage("downloading", "正在读取资产入口...");
275
+ const S = this.remoteResourcePathsFor(i), r = await ve(p, v, {
276
+ ...h ? { signal: h } : {},
277
+ ...S.length ? { resourcePaths: S } : {},
278
+ ...p.kind === "remote-entry" ? { remoteResolver: this.remoteResolverFor(p) } : {}
279
+ });
280
+ return u == null || u.stage("validating", "正在校验资产入口..."), r;
281
+ }),
282
+ resolveVisualSource: e.resolveVisualSource ?? (async (i, c, h, u) => {
283
+ u == null || u.stage("resolving-source", "正在解析视觉资产来源...");
284
+ const [p, v] = await Promise.all([
285
+ this.host.resolveVisualAssetSource(i, { signal: h }),
286
+ Promise.resolve(Le(this.host.document, i))
287
+ ]);
288
+ if (!p || !v) return null;
289
+ u == null || u.stage("downloading", "正在读取视觉资产入口...");
290
+ const S = await st(p, v, c, {
291
+ ...h ? { signal: h } : {},
292
+ ...p.kind === "remote-entry" ? { remoteResolver: this.remoteResolverFor(p) } : {}
293
+ });
294
+ return u == null || u.stage("validating", "正在校验视觉资产入口..."), S;
295
+ }),
296
+ onPick: (i, c, h) => {
297
+ var u;
298
+ if (!this.disposed && !this.previewDocument && (!this.previewMode || this.previewSelection === "inspect")) {
299
+ const p = this.host.getSelection(), v = i === null ? [] : c ? p.instanceIds.includes(i) ? p.instanceIds.filter((S) => S !== i) : [...p.instanceIds, i] : [i];
300
+ this.select(v, i && v.includes(i) ? i : void 0), (u = s.onPick) == null || u.call(s, i, c, h);
301
+ }
302
+ },
303
+ onBoxSelect: (i, c) => {
304
+ var h;
305
+ this.disposed || !this.previewDocument && (!this.previewMode || this.previewSelection === "inspect") && (this.select(c ? [...this.host.getSelection().instanceIds, ...i] : i), (h = s.onBoxSelect) == null || h.call(s, i, c));
306
+ },
307
+ onTransform: (i, c, h) => {
308
+ var u;
309
+ if (!this.disposed)
310
+ try {
311
+ this.commitTransform(i, c, !0, h), (u = s.onTransform) == null || u.call(s, i, c);
312
+ } catch (p) {
313
+ this.report(p), this.sync().catch((v) => this.report(v));
314
+ }
315
+ },
316
+ onNodeOriginChange: (i, c) => {
317
+ var h;
318
+ if (!this.disposed)
319
+ try {
320
+ this.setNodeOrigin(i, { local: c }), (h = s.onNodeOriginChange) == null || h.call(s, i, c);
321
+ } catch (u) {
322
+ this.report(u), this.sync().catch((p) => this.report(p));
323
+ }
324
+ },
325
+ onRegionTransform: (i, c) => {
326
+ var h;
327
+ this.disposed || this.previewDocument || this.previewMode || !this.editingEnabled || (h = s.onRegionTransform) == null || h.call(s, i, c);
328
+ },
329
+ onRegionShapeChange: (i, c) => {
330
+ var h;
331
+ this.disposed || this.previewDocument || this.previewMode || !this.editingEnabled || (h = s.onRegionShapeChange) == null || h.call(s, i, c);
332
+ },
333
+ onStatus: (i) => {
334
+ var c;
335
+ this.disposed || (this.sceneStatus = i, this.contextVersion += 1, this.emit("status.change"), this.emit("toolbar.change"), (c = s.onStatus) == null || c.call(s, i));
336
+ },
337
+ onAssetLoadStatus: (i) => {
338
+ var c;
339
+ this.disposed || (c = s.onAssetLoadStatus) == null || c.call(s, i);
340
+ },
341
+ onSelectionOverlayChange: (i) => {
342
+ var c;
343
+ if (!this.disposed) {
344
+ if (!x(this.overlay, i)) {
345
+ const h = this.overlay.transforming !== i.transforming || this.overlay.hiddenReason === "selecting" != (i.hiddenReason === "selecting");
346
+ this.overlay = i, this.overlaySequence += 1, this.emit("overlay.change"), h && this.changed();
347
+ }
348
+ (c = s.onSelectionOverlayChange) == null || c.call(s, i);
349
+ }
350
+ },
351
+ onError: (i) => {
352
+ var c;
353
+ this.report(new Error(i)), (c = s.onError) == null || c.call(s, i);
354
+ }
355
+ }), this.unsubscribeHost = this.host.subscribe((i) => {
356
+ var c, h;
357
+ if (!this.disposed) {
358
+ if (i.type === "selection.change")
359
+ this.selectionVersion += 1, this.overlay = { x: 0, y: 0, visible: !1, transforming: !1, hiddenReason: i.selection.instanceIds.length ? "anchor-unavailable" : "no-selection" }, this.overlaySequence += 1, this.session.select(i.selection.instanceIds, i.selection.primaryId);
360
+ else if (i.type === "document.change" || i.type === "asset.loaded") {
361
+ if (i.type === "document.change" && (i.origin === "open" || i.origin === "replace")) {
362
+ this.sceneSessionId = `session_${A()}`, this.selectionVersion = 0, this.overlaySequence = 0, this.previewDocument = null;
363
+ for (const u of this.transformOrigins.keys())
364
+ (h = (c = this.session).setTransformOrigin) == null || h.call(c, u, null);
365
+ this.transformOrigins.clear(), this.syncInteractionMode(), this.overlay = { x: 0, y: 0, visible: !1, transforming: !1, hiddenReason: "no-selection" };
366
+ }
367
+ this.sync().catch((u) => this.report(u));
368
+ } else i.type === "editorial.change" && (this.session.setEditorial(i.snapshot.editorial), this.session.select(i.snapshot.selection.instanceIds, i.snapshot.selection.primaryId));
369
+ this.contextVersion += 1, this.emit("toolbar.change"), this.emitEvent({ type: "host.change", snapshot: this.getSnapshot(), event: i });
370
+ }
371
+ }), (n = (o = this.session).setSurfaceSnap) == null || n.call(o, this.placementPolicy.surfaceSnap), (a = (d = this.session).setOverlapPrevention) == null || a.call(d, this.placementPolicy.preventOverlap), this.releaseShortcuts = e.shortcuts === !1 ? () => {
372
+ } : ot(e.canvas, (i) => this.handleShortcut(i)), this.ready = this.host.ready().then(async () => {
373
+ this.disposed || await this.sync();
374
+ }).catch((i) => {
375
+ if (!this.disposed) throw i;
376
+ }), this.ready.catch((i) => this.report(i));
377
+ }
378
+ getSnapshot() {
379
+ return {
380
+ host: this.host.getSnapshot(),
381
+ toolbar: this.getToolbarState(),
382
+ sceneStatus: this.sceneStatus,
383
+ mode: this.mode,
384
+ snap: this.snap,
385
+ snapStepM: this.session.getSnapStepM(),
386
+ transformSpace: this.transformSpace,
387
+ groundVisible: this.groundVisible,
388
+ collisionVisible: this.collisionVisible,
389
+ editingEnabled: this.editingEnabled,
390
+ previewMode: this.previewMode,
391
+ previewSelection: this.previewSelection,
392
+ previewing: this.previewDocument !== null,
393
+ boxSelectionEnabled: this.boxSelectionEnabled,
394
+ placementPreviewActive: this.placementPreviewActive,
395
+ placementPolicy: this.placementPolicy,
396
+ runtimeProjection: this.session.getRuntimeProjectionCapabilities()
397
+ };
398
+ }
399
+ /**
400
+ * Returns the immutable scene-tree projection used by tree and inspector
401
+ * clients. The projection includes effective editorial state and the
402
+ * current selection, so consumers should refresh it after `host.change` or
403
+ * a selection event instead of retaining individual node objects.
404
+ */
405
+ getSceneTreeSnapshot() {
406
+ return this.assertActive(), this.host.getSceneTreeSnapshot();
407
+ }
408
+ /**
409
+ * Reads the semantic and physical feature availability for a mounted node.
410
+ * This deliberately combines authored facts with the current runtime
411
+ * inspection result; callers can distinguish unavailable data from a
412
+ * feature that is present but whose visualization is not mounted.
413
+ */
414
+ getNodeFeatures(e) {
415
+ return this.assertActive(), tt(this.host.document, e, this.session.getRuntime(e));
416
+ }
417
+ getAssetLoadStatus(e) {
418
+ return this.assertActive(), this.session.getAssetLoadStatus(e);
419
+ }
420
+ remoteResolverFor(e) {
421
+ const t = $e(e), s = this.remoteResolvers.get(e.revisionId);
422
+ if ((s == null ? void 0 : s.fingerprint) === t && s.request === e.request)
423
+ return s.resolver;
424
+ const o = this.host.getAsset(e.revisionId) ?? this.host.getVisualAsset(e.revisionId) ?? void 0, n = new ge(e, o);
425
+ return this.remoteResolvers.set(e.revisionId, {
426
+ fingerprint: t,
427
+ request: e.request,
428
+ resolver: n
429
+ }), n;
430
+ }
431
+ remoteResourcePathsFor(e) {
432
+ const t = this.host.getAsset(e) ?? this.host.getVisualAsset(e);
433
+ return (t == null ? void 0 : t.resources.flatMap((s) => s.locator.kind === "remote-url" ? [s.locator.url] : [])) ?? [];
434
+ }
435
+ captureEditorialState() {
436
+ this.assertActive();
437
+ const e = this.host.getSnapshot(), t = this.session.getCameraState();
438
+ return Je({
439
+ document: this.host.document,
440
+ editorial: e.editorial,
441
+ selection: e.selection,
442
+ camera: t ? rt(t) : null
443
+ });
444
+ }
445
+ applyEditorialState(e) {
446
+ this.assertActive(), this.assertEditable(), Qe(e, this.host.document), this.session.cancelActiveGesture();
447
+ const t = Object.fromEntries(e.nodeStates.map((s) => [
448
+ s.nodeId,
449
+ { hidden: s.hidden, locked: s.locked }
450
+ ]));
451
+ this.host.replaceEditorialState(t, {
452
+ instanceIds: e.selection.nodeIds,
453
+ primaryId: e.selection.primaryNodeId
454
+ }), this.session.setEditorial(t), this.session.select(e.selection.nodeIds, e.selection.primaryNodeId), e.camera && this.session.setCameraState({
455
+ ...e.camera,
456
+ ...e.camera.orthographic ? { orthographic: { ...e.camera.orthographic } } : {},
457
+ ...e.camera.orbit ? { orbit: { ...e.camera.orbit } } : {}
458
+ }), this.changed();
459
+ }
460
+ subscribe(e, t = {}) {
461
+ return this.assertActive(), this.listeners.add(e), t.emitCurrent && this.notify(e, { type: "snapshot", snapshot: this.getSnapshot() }), () => {
462
+ this.listeners.delete(e);
463
+ };
464
+ }
465
+ registerAction(e) {
466
+ if (this.assertActive(), !e.id.trim()) throw new g("ACTION_ID_REQUIRED", "Editor actions require a non-empty id.");
467
+ if (this.actionDefinitions.has(e.id))
468
+ throw new g("ACTION_EXISTS", `Editor action already registered: ${e.id}`);
469
+ return this.actionDefinitions.set(e.id, e), this.changed(), () => this.unregisterAction(e.id);
470
+ }
471
+ unregisterAction(e) {
472
+ var t;
473
+ this.actionVisibility.delete(e), !this.disposed && ((t = this.actionControllers.get(e)) == null || t.abort(), this.actionControllers.delete(e), this.coreActionBusy.delete(e), this.actionDefinitions.delete(e) && this.changed());
474
+ }
475
+ cancelAction(e) {
476
+ var t, s, o;
477
+ (s = (t = this.actionDefinitions.get(e)) == null ? void 0 : t.cancel) == null || s.call(t), (o = this.actionControllers.get(e)) == null || o.abort(), this.actionControllers.delete(e), this.coreActionBusy.delete(e), this.changed();
478
+ }
479
+ async sync() {
480
+ var o, n, d, a, i, c;
481
+ this.assertActive();
482
+ const e = ++this.syncEpoch, t = this.previewDocument ?? this.host.document;
483
+ try {
484
+ await this.session.sync(
485
+ t,
486
+ this.host.getSnapshot().editorial,
487
+ ((n = (o = this.options).resolveRegionOverlays) == null ? void 0 : n.call(o, t)) ?? []
488
+ );
489
+ } catch (h) {
490
+ if (this.disposed) return;
491
+ throw h;
492
+ }
493
+ if (this.disposed || e !== this.syncEpoch) return;
494
+ for (const [h, u] of this.transformOrigins)
495
+ y(t.root, h) && ((a = (d = this.session).setTransformOrigin) == null || a.call(d, h, [...u]));
496
+ if (!this.previewDocument) {
497
+ const h = new Set(V(this.host.document.root).map((u) => u.nodeId));
498
+ for (const u of this.transformOrigins.keys())
499
+ h.has(u) || (this.transformOrigins.delete(u), (c = (i = this.session).setTransformOrigin) == null || c.call(i, u, null));
500
+ }
501
+ const s = this.host.getSelection();
502
+ this.session.select(s.instanceIds, s.primaryId);
503
+ }
504
+ async setPreviewDocument(e) {
505
+ this.assertActive(), this.session.cancelActiveGesture(), this.previewDocument = e, this.syncInteractionMode(), this.contextVersion += 1, this.emit("toolbar.change"), await this.sync();
506
+ }
507
+ async beginPlacementPreview(e, t) {
508
+ this.assertEditable();
509
+ const s = await this.session.beginPlacementPreview(e, t);
510
+ return this.placementPreviewActive = s, this.changed(), s;
511
+ }
512
+ async updatePlacementPreview(e) {
513
+ this.assertActive();
514
+ const t = await this.session.updatePlacementPreview(e);
515
+ return this.placementPreviewActive = t, this.changed(), t;
516
+ }
517
+ async confirmPlacementPreview(e) {
518
+ this.assertEditable();
519
+ const t = this.host.getSnapshot(), s = await this.session.confirmPlacementPreview();
520
+ if (this.placementPreviewActive = !1, this.changed(), !s) return null;
521
+ const o = this.host.getAsset(e.revisionId);
522
+ if (!o) throw new g("ASSET_NOT_FOUND", `Asset revision not found: ${e.revisionId}`);
523
+ const n = ce(o, {
524
+ revisionId: o.revisionId,
525
+ label: e.label,
526
+ role: e.role,
527
+ localTransform: s,
528
+ ...e.nodeId ? { nodeId: e.nodeId } : {},
529
+ ...e.variantSelections ? { variantSelections: e.variantSelections } : {},
530
+ ...e.physics ? { physics: e.physics } : {}
531
+ });
532
+ return this.host.commit({
533
+ commands: [le(n, e.parentNodeId ?? t.document.root.nodeId, {
534
+ label: `Place ${n.label}`,
535
+ source: "human",
536
+ batchId: `batch_${A()}`
537
+ })],
538
+ expectedDocumentVersion: t.documentVersion,
539
+ expectedSceneEpoch: t.sceneEpoch
540
+ });
541
+ }
542
+ async cancelPlacementPreview() {
543
+ this.disposed || (await this.session.cancelPlacementPreview(), this.placementPreviewActive = !1, this.changed());
544
+ }
545
+ select(e, t) {
546
+ if (this.assertActive(), this.previewMode && this.previewSelection === "none" && e.length > 0)
547
+ throw new g(
548
+ "PREVIEW_SELECTION_DISABLED",
549
+ "Selection is disabled in this preview mode."
550
+ );
551
+ return this.host.select(e, t);
552
+ }
553
+ dispatch(e) {
554
+ return this.applyCommands(e, !1);
555
+ }
556
+ applyCommands(e, t, s = [], o = []) {
557
+ this.assertEditable(t);
558
+ const n = Array.isArray(e) ? e : [e];
559
+ for (const i of n) {
560
+ const c = i.payload;
561
+ if (!("nodeId" in c)) continue;
562
+ const u = (c.type === "node.remove" || c.type === "node.duplicate" || c.type === "node.transform" ? ee(y(this.host.document.root, c.nodeId)) : [c.nodeId]).find((p) => this.host.getEditorialState(p).locked);
563
+ if (u)
564
+ throw new g("NODE_LOCKED", `Scene node is locked: ${u}`);
565
+ }
566
+ const d = Ee(this.host.document, n);
567
+ d.diagnostics.some((i) => i.level === "error") || this.assertProjectionRepresentable(d.doc.root);
568
+ const a = this.host.getSnapshot();
569
+ return this.host.commit({
570
+ commands: n,
571
+ expectedDocumentVersion: a.documentVersion,
572
+ expectedSceneEpoch: a.sceneEpoch,
573
+ ...t ? { gestureCommit: !0 } : {},
574
+ ...s.length ? { allowOverlapNodeIds: s } : {},
575
+ ...o.length ? { supportContacts: o } : {}
576
+ });
577
+ }
578
+ async captureViewport(e = {}) {
579
+ this.assertActive();
580
+ const t = this.host.getSnapshot(), s = await this.session.captureViewport(e);
581
+ this.assertActive();
582
+ const o = this.host.getSnapshot();
583
+ if (t.sceneEpoch !== o.sceneEpoch || t.documentVersion !== o.documentVersion)
584
+ throw new g("CONTEXT_STALE", "The scene changed during capture.");
585
+ return s;
586
+ }
587
+ getPlacementPolicy() {
588
+ return this.placementPolicy;
589
+ }
590
+ setPlacementPolicy(e) {
591
+ var t, s, o, n;
592
+ this.assertActive(), this.placementPolicy = Ye(e, this.placementPolicy), (s = (t = this.session).setSurfaceSnap) == null || s.call(t, this.placementPolicy.surfaceSnap), (n = (o = this.session).setOverlapPrevention) == null || n.call(o, this.placementPolicy.preventOverlap), this.changed();
593
+ }
594
+ async prepareAssetPlacement(e) {
595
+ var v, S;
596
+ this.assertEditable(), (v = e.signal) == null || v.throwIfAborted();
597
+ const t = this.host.getSnapshot();
598
+ if (!this.host.getAsset(e.revisionId))
599
+ throw new g("ASSET_NOT_FOUND", "Asset revision is not registered.");
600
+ const s = e.parentNodeId ?? t.document.root.nodeId, o = y(t.document.root, s);
601
+ if ((o == null ? void 0 : o.nodeType) !== "group")
602
+ throw new g(
603
+ "PLACEMENT_PARENT_INVALID",
604
+ "Placement parent must be a scene group."
605
+ );
606
+ const n = await this.session.measureAssetBounds(e.revisionId);
607
+ if ((S = e.signal) == null || S.throwIfAborted(), this.assertActive(), this.host.getSnapshot().sceneEpoch !== t.sceneEpoch || this.host.getSnapshot().documentVersion !== t.documentVersion)
608
+ throw new g("CONTEXT_STALE", "Scene changed while measuring placement.");
609
+ const d = V(t.document.root).filter(
610
+ (r) => r.nodeType !== "group" && k(t.document.root, r.nodeId, {})
611
+ ).map((r) => {
612
+ var f;
613
+ return {
614
+ nodeId: r.nodeId,
615
+ bounds: ((f = this.getNodeFrame(r.nodeId)) == null ? void 0 : f.localBounds) ?? W(t.document, r),
616
+ transform: de(t.document.root, r.nodeId),
617
+ container: pe(t.document, r)
618
+ };
619
+ }), a = e.allowOverlap ? { ...this.placementPolicy, preventOverlap: !1 } : this.placementPolicy;
620
+ if (a.preventOverlap && d.some((r) => !r.bounds))
621
+ throw new g(
622
+ "PLACEMENT_BOUNDS_UNAVAILABLE",
623
+ "Overlap prevention requires known obstacle bounds."
624
+ );
625
+ const i = !e.surface && (!!e.point || !e.worldTransform), c = e.surface ?? (i ? { nodeId: null, point: e.point ?? [0, 0, 0], normal: [0, 0, 1] } : null), h = me({
626
+ bounds: n,
627
+ transform: e.worldTransform ?? xe(),
628
+ surface: c,
629
+ policy: i ? { ...a, surfaceSnap: !0, alignToSurface: !1 } : a,
630
+ obstacles: d.flatMap(
631
+ (r) => r.bounds ? [{ ...r, bounds: r.bounds }] : []
632
+ )
633
+ }), u = he(t.document.root, s), p = u ? G(h.transform, u) : null;
634
+ if (!p)
635
+ throw new g(
636
+ "TRANSFORM_NOT_REPRESENTABLE",
637
+ "Placement requires shear below this parent."
638
+ );
639
+ return Q(
640
+ q({
641
+ revisionId: e.revisionId,
642
+ parentNodeId: s,
643
+ sceneEpoch: t.sceneEpoch,
644
+ documentVersion: t.documentVersion,
645
+ policy: this.placementPolicy,
646
+ sourceBounds: n,
647
+ evaluation: h,
648
+ localTransform: p
649
+ })
650
+ );
651
+ }
652
+ commitAssetPlacement(e, t) {
653
+ this.assertEditable();
654
+ const s = this.host.getSnapshot();
655
+ if (s.sceneEpoch !== e.sceneEpoch || s.documentVersion !== e.documentVersion || !x(e.policy, this.placementPolicy))
656
+ throw new g("CONTEXT_STALE", "The placement plan is stale.");
657
+ if (!e.evaluation.valid)
658
+ throw new g(
659
+ e.evaluation.reason ?? "PLACEMENT_INVALID",
660
+ "The placement violates the active policy."
661
+ );
662
+ const o = this.host.getAsset(e.revisionId);
663
+ if (!o) throw new g("ASSET_NOT_FOUND", "Asset revision not found.");
664
+ const n = ce(o, {
665
+ revisionId: o.revisionId,
666
+ label: t.label,
667
+ role: t.role,
668
+ localTransform: e.localTransform,
669
+ ...t.nodeId ? { nodeId: t.nodeId } : {}
670
+ });
671
+ this.transactionBounds.set(n.nodeId, e.sourceBounds);
672
+ try {
673
+ return this.applyCommands(
674
+ le(n, e.parentNodeId, {
675
+ label: "Place " + t.label,
676
+ source: "human",
677
+ batchId: "batch_" + A()
678
+ }),
679
+ !1,
680
+ [],
681
+ Z(
682
+ n.nodeId,
683
+ e.evaluation.supportNodeId,
684
+ e.evaluation.supportSurfaceZ
685
+ )
686
+ );
687
+ } finally {
688
+ this.transactionBounds.delete(n.nodeId);
689
+ }
690
+ }
691
+ prepareNodePlacement(e) {
692
+ var u;
693
+ this.assertEditable();
694
+ const t = this.host.getSnapshot(), s = y(t.document.root, e.nodeId), o = (u = this.getNodeFrame(e.nodeId)) == null ? void 0 : u.localBounds;
695
+ if (!s || !o)
696
+ throw new g(
697
+ "PLACEMENT_BOUNDS_UNAVAILABLE",
698
+ "Placement requires known source bounds."
699
+ );
700
+ const n = new Set(ee(s)), d = V(t.document.root).filter(
701
+ (p) => p.nodeType !== "group" && !n.has(p.nodeId) && k(t.document.root, p.nodeId, {})
702
+ ).map((p) => {
703
+ var v;
704
+ return {
705
+ nodeId: p.nodeId,
706
+ bounds: ((v = this.getNodeFrame(p.nodeId)) == null ? void 0 : v.localBounds) ?? W(t.document, p),
707
+ transform: de(t.document.root, p.nodeId),
708
+ container: pe(t.document, p)
709
+ };
710
+ }), a = e.allowOverlap ? { ...this.placementPolicy, preventOverlap: !1 } : this.placementPolicy;
711
+ if (a.preventOverlap && d.some((p) => !p.bounds))
712
+ throw new g(
713
+ "PLACEMENT_BOUNDS_UNAVAILABLE",
714
+ "An obstacle has no known source bounds."
715
+ );
716
+ const i = me({
717
+ bounds: o,
718
+ transform: e.worldTransform,
719
+ surface: e.surface,
720
+ policy: a,
721
+ obstacles: d.flatMap(
722
+ (p) => p.bounds ? [{ ...p, bounds: p.bounds }] : []
723
+ )
724
+ }), c = $(t.document.root, e.nodeId), h = c ? G(i.transform, c) : null;
725
+ if (!h)
726
+ throw new g(
727
+ "TRANSFORM_NOT_REPRESENTABLE",
728
+ "Placement cannot be expressed below this parent."
729
+ );
730
+ return Q(
731
+ q({
732
+ nodeId: e.nodeId,
733
+ sceneEpoch: t.sceneEpoch,
734
+ documentVersion: t.documentVersion,
735
+ policy: this.placementPolicy,
736
+ evaluation: i,
737
+ localTransform: h
738
+ })
739
+ );
740
+ }
741
+ commitPlacement(e) {
742
+ this.assertEditable();
743
+ const t = this.host.getSnapshot();
744
+ if (t.sceneEpoch !== e.sceneEpoch || t.documentVersion !== e.documentVersion || !x(this.placementPolicy, e.policy))
745
+ throw new g("CONTEXT_STALE", "The placement plan is stale.");
746
+ if (!e.evaluation.valid)
747
+ throw new g(
748
+ e.evaluation.reason ?? "PLACEMENT_INVALID",
749
+ "The placement violates the active policy."
750
+ );
751
+ return this.applyCommands(
752
+ B(t.document, e.nodeId, e.localTransform, {
753
+ label: "Place node",
754
+ source: "human",
755
+ batchId: "batch_" + A()
756
+ }),
757
+ !1,
758
+ [],
759
+ Z(
760
+ e.nodeId,
761
+ e.evaluation.supportNodeId,
762
+ e.evaluation.supportSurfaceZ
763
+ )
764
+ );
765
+ }
766
+ getPhysicsFacts(e) {
767
+ return this.assertActive(), this.session.getPhysicsFacts(e);
768
+ }
769
+ getNodeFrame(e) {
770
+ return this.assertActive(), this.session.getNodeFrame(e);
771
+ }
772
+ getNodeOriginAnchors(e) {
773
+ return this.assertActive(), this.session.measureNodeOriginAnchors(e);
774
+ }
775
+ getSelectionFrame() {
776
+ return this.assertActive(), this.session.getSelectionFrame();
777
+ }
778
+ getNodeOrigin(e) {
779
+ var t;
780
+ return ((t = this.getNodeFrame(e)) == null ? void 0 : t.origin) ?? null;
781
+ }
782
+ /** Runtime-only transform pivot, kept separate from authored scene data. */
783
+ getTransformOrigin(e) {
784
+ var s, o;
785
+ const t = this.transformOrigins.get(e) ?? ((o = (s = this.session).getTransformOrigin) == null ? void 0 : o.call(s, e)) ?? null;
786
+ return t ? [...t] : null;
787
+ }
788
+ setTransformOrigin(e, t) {
789
+ var o, n;
790
+ if (this.assertActive(), !y(this.host.document.root, e) || !t && t !== null || t && (t.length !== 3 || t.some((d) => !Number.isFinite(d)))) return !1;
791
+ if (this.assertEditable(!0), X(this.host.document.root, e, this.host.getSnapshot().editorial))
792
+ throw new g("NODE_LOCKED", `Scene node is locked: ${e}`);
793
+ return t ? this.transformOrigins.set(e, [...t]) : this.transformOrigins.delete(e), (n = (o = this.session).setTransformOrigin) == null || n.call(o, e, t ? [...t] : null), !0;
794
+ }
795
+ getNodeOrientation(e) {
796
+ var t;
797
+ return ((t = this.getNodeFrame(e)) == null ? void 0 : t.orientation) ?? null;
798
+ }
799
+ setNodeOrigin(e, t) {
800
+ this.assertEditable(), t && nt(t);
801
+ const s = y(this.host.document.root, e);
802
+ if (!s) throw new g("NODE_NOT_FOUND", `Scene node not found: ${e}`);
803
+ if (s.nodeId === this.host.document.root.nodeId)
804
+ throw new g("ORIGIN_NOT_EDITABLE", "The scene root does not expose a transform origin.");
805
+ return this.dispatch(
806
+ Ae(this.host.document, e, t, {
807
+ label: "Set node origin",
808
+ source: "human",
809
+ batchId: "batch_" + A()
810
+ })
811
+ );
812
+ }
813
+ setNodeUpDirection(e, t) {
814
+ this.assertEditable();
815
+ const s = Math.hypot(...t);
816
+ if (t.length !== 3 || t.some((a) => !Number.isFinite(a)) || !Number.isFinite(s) || s <= 1e-12)
817
+ throw new g(
818
+ "ORIENTATION_DIRECTION_INVALID",
819
+ "Orientation direction must be a finite, non-zero three-component vector."
820
+ );
821
+ const o = y(this.host.document.root, e);
822
+ if (!o) throw new g("NODE_NOT_FOUND", `Scene node not found: ${e}`);
823
+ const n = t.map((a) => a / s), d = Me(n);
824
+ return this.changeTransform(
825
+ e,
826
+ { ...o.localTransform, rotation: d },
827
+ { space: "local", scope: "node" }
828
+ );
829
+ }
830
+ getAssetDimensions(e) {
831
+ var t;
832
+ return this.assertActive(), Ke(
833
+ this.host.document,
834
+ e,
835
+ (t = this.session.getNodeFrame(e)) == null ? void 0 : t.localBounds
836
+ );
837
+ }
838
+ focusSelection(e) {
839
+ if (this.assertActive(), (e == null ? void 0 : e.padding) !== void 0 && (!Number.isFinite(e.padding) || e.padding < 1))
840
+ throw new g(
841
+ "FOCUS_OPTIONS_INVALID",
842
+ "Focus padding must be finite and at least one."
843
+ );
844
+ return this.session.focusNodes(this.host.getSelection().instanceIds, e);
845
+ }
846
+ setTransformSpace(e) {
847
+ if (this.assertActive(), e !== "local" && e !== "world")
848
+ throw new g(
849
+ "TRANSFORM_SPACE_INVALID",
850
+ "Transform space must be local or world."
851
+ );
852
+ this.session.setTransformSpace(e), this.transformSpace = e, this.changed();
853
+ }
854
+ setNodeDimensions(e, t, s = {}) {
855
+ var i, c;
856
+ this.assertEditable();
857
+ const o = this.getAssetDimensions(e), n = y(this.host.document.root, e);
858
+ if (!n || !(o != null && o.editable) || !o.sourceDimensions)
859
+ throw new g(
860
+ (o == null ? void 0 : o.reason) ?? "NODE_NOT_FOUND",
861
+ "Node dimensions cannot be edited: " + e
862
+ );
863
+ if (t.length !== 3 || t.some((h) => !Number.isFinite(h) || h <= 0))
864
+ throw new g(
865
+ "DIMENSIONS_INVALID",
866
+ "Dimensions must be three positive finite metre values."
867
+ );
868
+ if (s.anchor && s.anchor !== "node-origin" && s.anchor !== "bounds-center")
869
+ throw new g("DIMENSIONS_ANCHOR_INVALID", "Unknown dimensions anchor.");
870
+ const d = t.map(
871
+ (h, u) => h / o.sourceDimensions[u]
872
+ );
873
+ let a = n.localTransform.position;
874
+ if (s.anchor === "bounds-center") {
875
+ const h = (i = this.getNodeFrame(e)) == null ? void 0 : i.localBounds;
876
+ if (!h)
877
+ throw new g(
878
+ "BOUNDS_UNAVAILABLE",
879
+ "A bounds center requires source bounds."
880
+ );
881
+ const u = ze(h), p = ((c = n.origin) == null ? void 0 : c.local) ?? [0, 0, 0], v = u.map(
882
+ (r, f) => r - p[f]
883
+ ), S = Fe(
884
+ n.localTransform.rotation,
885
+ v.map(
886
+ (r, f) => r * (n.localTransform.scale[f] - d[f])
887
+ )
888
+ );
889
+ a = a.map((r, f) => r + S[f]);
890
+ }
891
+ return this.dispatch(
892
+ B(
893
+ this.host.document,
894
+ e,
895
+ { ...n.localTransform, position: a, scale: d },
896
+ { label: "Set node dimensions", source: "human", batchId: "batch_" + A() }
897
+ )
898
+ );
899
+ }
900
+ setNodesVisible(e, t) {
901
+ if (this.assertEditable(), typeof t != "boolean")
902
+ throw new g("VISIBILITY_INVALID", "Authored visibility must be boolean.");
903
+ const s = /* @__PURE__ */ new Map();
904
+ for (const n of e) {
905
+ const d = y(this.host.document.root, n);
906
+ if (!d || n === this.host.document.root.nodeId)
907
+ throw new g("NODE_NOT_FOUND", "Scene node not found: " + n);
908
+ for (const a of d.nodeType === "group" ? V(d) : [d])
909
+ "visible" in a && s.set(a.nodeId, a);
910
+ }
911
+ const o = "batch_" + A();
912
+ return this.dispatch(
913
+ [...s.values()].filter((n) => "visible" in n && n.visible !== t).map(
914
+ (n) => Te(this.host.document, n.nodeId, t, {
915
+ label: "Set authored visibility",
916
+ source: "human",
917
+ batchId: o
918
+ })
919
+ )
920
+ );
921
+ }
922
+ updateEditorialState(e, t) {
923
+ this.assertEditable(), this.host.updateEditorialState(e, t);
924
+ }
925
+ hideNodes(e) {
926
+ this.updateEditorialState(e, { hidden: !0 });
927
+ }
928
+ hideSelection() {
929
+ this.hideNodes(this.host.getSelection().instanceIds);
930
+ }
931
+ selectFromTree(e) {
932
+ return this.assertActive(), this.host.selectFromTree(e);
933
+ }
934
+ /** Explicit selection API for clients that own a viewport picker. */
935
+ selectFromViewport(e, t) {
936
+ return this.assertActive(), this.host.selectFromViewport(e, t);
937
+ }
938
+ /** Set temporary editor visibility without changing authored scene data. */
939
+ setNodesHidden(e, t) {
940
+ if (this.assertActive(), typeof t != "boolean")
941
+ throw new g("VISIBILITY_INVALID", "Hidden state must be boolean.");
942
+ this.updateEditorialState(e, { hidden: t });
943
+ }
944
+ showNodes(e) {
945
+ this.setNodesHidden(e, !1);
946
+ }
947
+ /** Set temporary editor lock state without adding a document command. */
948
+ setNodesLocked(e, t) {
949
+ if (this.assertActive(), typeof t != "boolean")
950
+ throw new g("LOCK_INVALID", "Locked state must be boolean.");
951
+ this.updateEditorialState(e, { locked: t });
952
+ }
953
+ setNodePhysics(e, t) {
954
+ return this.dispatch(
955
+ Ne(this.host.document, e, t, {
956
+ label: "Set node physics",
957
+ source: "human",
958
+ batchId: "batch_" + A()
959
+ })
960
+ );
961
+ }
962
+ setNodeInitialPose(e, t) {
963
+ return this.dispatch(
964
+ Oe(this.host.document, e, t, {
965
+ label: "Set initial joint pose",
966
+ source: "human",
967
+ batchId: "batch_" + A()
968
+ })
969
+ );
970
+ }
971
+ setActionVisibility(e, t) {
972
+ if (this.assertActive(), !this.actionDefinitions.has(e) && !this.host.getActions().some((s) => s.id === e))
973
+ throw new g("ACTION_UNKNOWN", "Unknown action: " + e);
974
+ if (t !== null && typeof t != "boolean")
975
+ throw new g(
976
+ "ACTION_VISIBILITY_INVALID",
977
+ "Action visibility must be boolean or null."
978
+ );
979
+ t === null ? this.actionVisibility.delete(e) : this.actionVisibility.set(e, t), this.changed();
980
+ }
981
+ projectActionVisibility(e) {
982
+ return {
983
+ ...e,
984
+ visible: e.visible && this.actionVisibility.get(e.id) !== !1,
985
+ busy: e.busy || this.actionControllers.has(e.id)
986
+ };
987
+ }
988
+ changeTransform(e, t, s = {}) {
989
+ if (s.space && s.space !== "local" && s.space !== "world" || s.scope && s.scope !== "node" && s.scope !== "selection")
990
+ throw new g("TRANSFORM_OPTIONS_INVALID", "Invalid transform space or scope.");
991
+ if (s.scope === "node") {
992
+ const n = $(this.host.document.root, e), d = s.space === "local" ? t : n ? G(t, n) : null;
993
+ if (!d)
994
+ throw new g(
995
+ "TRANSFORM_NOT_REPRESENTABLE",
996
+ "Transform cannot be expressed below this parent."
997
+ );
998
+ return this.dispatch(
999
+ B(this.host.document, e, d, {
1000
+ label: "Transform node",
1001
+ source: "human",
1002
+ batchId: "batch_" + A()
1003
+ })
1004
+ );
1005
+ }
1006
+ const o = s.space === "local" ? Ue($(this.host.document.root, e), t) : t;
1007
+ if (!o)
1008
+ throw new g("TRANSFORM_NOT_REPRESENTABLE", "Transform requires shear.");
1009
+ return this.commitTransform(e, o, !1);
1010
+ }
1011
+ commitTransform(e, t, s, o = {}) {
1012
+ if (this.assertEditable(s), !y(this.host.document.root, e) || j(
1013
+ this.host.document.root,
1014
+ e,
1015
+ this.host.getSnapshot().editorial
1016
+ ))
1017
+ throw new g("NODE_NOT_EDITABLE", `Scene node is not editable: ${e}`);
1018
+ const d = this.host.getSelection(), a = /* @__PURE__ */ new Set([e, ...d.instanceIds]), i = this.sceneInstances().filter((r) => a.has(r.nodeId)).map((r) => ({
1019
+ ...r,
1020
+ visible: k(
1021
+ this.host.document.root,
1022
+ r.nodeId,
1023
+ this.host.getSnapshot().editorial
1024
+ ),
1025
+ localTransform: he(this.host.document.root, r.nodeId) ?? r.localTransform
1026
+ })), c = Object.fromEntries(i.map((r) => [
1027
+ r.nodeId,
1028
+ Be(
1029
+ this.host.document.root,
1030
+ r.nodeId,
1031
+ this.host.getSnapshot().editorial
1032
+ )
1033
+ ])), h = new Set(this.selectionClosure([...a]).map((r) => r.nodeId)), u = He(i, e, t, c).filter((r) => h.has(r.nodeId)).flatMap((r) => {
1034
+ const f = $(this.host.document.root, r.nodeId), m = f ? G(r.localTransform, f) : null;
1035
+ if (!m)
1036
+ throw new g(
1037
+ "TRANSFORM_NOT_REPRESENTABLE",
1038
+ `World transform cannot be represented below the parent of ${r.nodeId}.`
1039
+ );
1040
+ const b = y(this.host.document.root, r.nodeId);
1041
+ return b && !x(b.localTransform, m) ? [{ nodeId: r.nodeId, localTransform: m }] : [];
1042
+ }), p = `batch_${A()}`, v = o.supportNodeId, S = o.supportSurfaceZ;
1043
+ return this.applyCommands(
1044
+ u.map((r) => B(
1045
+ this.host.document,
1046
+ r.nodeId,
1047
+ r.localTransform,
1048
+ { label: "Transform selection", source: "human", batchId: p }
1049
+ )),
1050
+ s,
1051
+ o.allowOverlap === !0 ? [e, ...d.instanceIds] : [],
1052
+ v && Number.isFinite(S) ? u.flatMap((r) => Z(
1053
+ r.nodeId,
1054
+ v,
1055
+ S
1056
+ )) : []
1057
+ );
1058
+ }
1059
+ duplicateSelection(e = this.host.getSelection().instanceIds) {
1060
+ this.assertEditable();
1061
+ const t = this.editableTargets(e), s = `batch_${A()}`, o = [], n = t.map((a) => {
1062
+ var u;
1063
+ const i = ((u = H(this.host.document.root, a.nodeId)) == null ? void 0 : u.parent.nodeId) ?? this.host.document.root.nodeId, c = Pe(this.host.document, a.nodeId, i, { label: "Duplicate selection", source: "human", batchId: s });
1064
+ if (c.payload.type !== "node.duplicate") throw new Error("Invalid duplicate command");
1065
+ const h = c.payload.created;
1066
+ return o.push(h.nodeId), _e({ ...c.payload, created: { ...h, localTransform: {
1067
+ ...h.localTransform,
1068
+ position: [h.localTransform.position[0] + 0.25, h.localTransform.position[1] + 0.25, h.localTransform.position[2]]
1069
+ } } }, { label: "Duplicate selection", source: "human", batchId: s });
1070
+ }), d = this.dispatch(n);
1071
+ return d.changed && this.select(o), d;
1072
+ }
1073
+ deleteSelection(e = this.host.getSelection().instanceIds) {
1074
+ this.assertEditable();
1075
+ const t = `batch_${A()}`;
1076
+ return this.dispatch(this.editableTargets(e).map((s) => De(this.host.document, s.nodeId, { label: "Delete selection", source: "human", batchId: t })));
1077
+ }
1078
+ groupSelection(e = this.host.getSelection().instanceIds) {
1079
+ this.assertEditable();
1080
+ const t = this.editableTargets(e);
1081
+ if (t.length < 2) throw new g("GROUP_REQUIRES_MULTIPLE", "Grouping requires at least two editable nodes.");
1082
+ const s = new Set(t.map((d) => {
1083
+ var a;
1084
+ return ((a = H(this.host.document.root, d.nodeId)) == null ? void 0 : a.parent.nodeId) ?? this.host.document.root.nodeId;
1085
+ })), o = s.size === 1 ? [...s][0] : this.host.document.root.nodeId, n = `batch_${A()}`;
1086
+ return this.dispatch(Re(
1087
+ this.host.document,
1088
+ t.map((d) => d.nodeId),
1089
+ o,
1090
+ {
1091
+ label: "Group selection",
1092
+ source: "human",
1093
+ batchId: n,
1094
+ groupLabel: `Group ${this.host.document.root.children.length + 1}`
1095
+ }
1096
+ ));
1097
+ }
1098
+ ungroupSelection(e = this.host.getSelection().instanceIds) {
1099
+ this.assertEditable();
1100
+ const t = this.removableGroupIds(
1101
+ this.editableTargets(e).map((d) => d.nodeId)
1102
+ );
1103
+ if (t.length === 0)
1104
+ throw new g(
1105
+ "NO_PARENT_GROUP",
1106
+ "The selection does not contain an editable group or child of one."
1107
+ );
1108
+ const s = `batch_${A()}`, o = [];
1109
+ let n = this.host.document;
1110
+ for (const d of t) {
1111
+ const a = Ve(n, d, {
1112
+ label: "Ungroup selection",
1113
+ source: "human",
1114
+ batchId: s
1115
+ });
1116
+ o.push(...a), n = a.reduce((i, c) => {
1117
+ const h = Ce(i, c.payload);
1118
+ if (h.diagnostics.some((u) => u.level === "error"))
1119
+ throw new g(
1120
+ "UNGROUP_REJECTED",
1121
+ h.diagnostics.map((u) => u.message).join(`
1122
+ `)
1123
+ );
1124
+ return h.doc;
1125
+ }, n);
1126
+ }
1127
+ return this.dispatch(o);
1128
+ }
1129
+ setSelectionLocked(e, t = this.host.getSelection().instanceIds) {
1130
+ this.assertEditable(), this.session.cancelActiveGesture();
1131
+ for (const s of this.selectionClosure(t))
1132
+ this.host.setEditorialState(s.nodeId, { locked: e });
1133
+ }
1134
+ setMode(e) {
1135
+ this.assertActive(), this.mode = e, this.session.setMode(e), this.changed();
1136
+ }
1137
+ setSnap(e) {
1138
+ this.assertActive(), this.snap = e, this.session.setSnap(e), this.changed();
1139
+ }
1140
+ setGroundVisible(e) {
1141
+ this.assertActive(), this.groundVisible = e, this.session.setGroundVisible(e), this.changed();
1142
+ }
1143
+ setCollisionVisible(e) {
1144
+ this.assertActive(), this.collisionVisible = e, this.session.setCollisionVisible(e), this.changed();
1145
+ }
1146
+ setEditingEnabled(e) {
1147
+ this.assertActive(), this.editingEnabled = e, this.syncInteractionMode(), this.changed();
1148
+ }
1149
+ setPreviewMode(e, t = {}) {
1150
+ this.assertActive();
1151
+ const s = e ? t.selection ?? (this.previewMode ? this.previewSelection : "none") : "none";
1152
+ this.previewMode === e && this.previewSelection === s || (this.previewMode = e, this.previewSelection = s, e && (this.boxSelectionEnabled = !1, this.session.setBoxSelectionEnabled(!1), this.session.cancelActiveGesture()), (!e || this.previewSelection === "none") && this.host.select([], null), this.syncInteractionMode(), this.changed());
1153
+ }
1154
+ setPreviewSelection(e) {
1155
+ if (this.assertActive(), !this.previewMode)
1156
+ throw new g(
1157
+ "PREVIEW_MODE_INACTIVE",
1158
+ "Preview selection can only be changed while preview mode is active."
1159
+ );
1160
+ this.previewSelection !== e && (this.previewSelection = e, e === "none" && this.host.select([], null), this.syncInteractionMode(), this.changed());
1161
+ }
1162
+ setBoxSelectionEnabled(e) {
1163
+ this.assertActive(), this.boxSelectionEnabled = e, this.session.setBoxSelectionEnabled(e), this.changed();
1164
+ }
1165
+ fit() {
1166
+ return this.assertActive(), this.session.fit();
1167
+ }
1168
+ zoomIn(e = 1.2) {
1169
+ if (this.assertActive(), !Number.isFinite(e) || e <= 1)
1170
+ throw new g("ZOOM_FACTOR_INVALID", "Zoom factor must be finite and greater than one.");
1171
+ return this.session.zoomIn(e);
1172
+ }
1173
+ zoomOut(e = 1.2) {
1174
+ if (this.assertActive(), !Number.isFinite(e) || e <= 1)
1175
+ throw new g("ZOOM_FACTOR_INVALID", "Zoom factor must be finite and greater than one.");
1176
+ return this.session.zoomOut(e);
1177
+ }
1178
+ setAxisView(e, t) {
1179
+ return this.assertActive(), this.session.setAxisView(e, t);
1180
+ }
1181
+ setTheme(e) {
1182
+ this.assertActive(), this.session.setTheme(e);
1183
+ }
1184
+ cancelActiveGesture() {
1185
+ this.assertActive(), this.session.cancelActiveGesture();
1186
+ }
1187
+ playScene() {
1188
+ this.assertActive();
1189
+ const e = this.session.playScene();
1190
+ return this.syncInteractionMode(), this.changed(), e;
1191
+ }
1192
+ pauseScene() {
1193
+ this.assertActive();
1194
+ const e = this.session.pauseScene();
1195
+ return this.syncInteractionMode(), this.changed(), e;
1196
+ }
1197
+ stepScene(e) {
1198
+ this.assertActive();
1199
+ const t = this.session.stepScene(e);
1200
+ return this.changed(), t;
1201
+ }
1202
+ resetScene() {
1203
+ this.assertActive();
1204
+ const e = this.session.resetScene();
1205
+ return this.syncInteractionMode(), this.changed(), e;
1206
+ }
1207
+ stopScene() {
1208
+ this.assertActive();
1209
+ const e = this.session.pauseScene(), t = this.session.resetScene();
1210
+ return this.syncInteractionMode(), this.changed(), e || t;
1211
+ }
1212
+ getNodeActions(e) {
1213
+ const t = [...new Set(e)], s = this.selectionClosure(t), o = s.map((m) => m.nodeId), n = this.editableTargets(o).map((m) => m.nodeId), d = new Set(n), a = o.filter((m) => !d.has(m)).map((m) => ({
1214
+ nodeId: m,
1215
+ reasonCode: j(
1216
+ this.host.document.root,
1217
+ m,
1218
+ this.host.getSnapshot().editorial
1219
+ ) ? "NODE_LOCKED" : "NODE_NOT_EDITABLE"
1220
+ })), i = s.length > 0, c = this.editingEnabled && !this.previewMode && !this.previewDocument, h = this.overlay.transforming || this.overlay.hiddenReason === "selecting", u = this.session.isSimulationRunning(), p = (m, b, T = {}) => ({
1221
+ id: m,
1222
+ scope: "selection",
1223
+ visible: i,
1224
+ enabled: b && c && !h && !u,
1225
+ busy: !1,
1226
+ targetIds: n,
1227
+ execution: "eligible-subset",
1228
+ ...a.length ? { excludedTargets: a } : {},
1229
+ ...u ? { reason: { code: "SIMULATION_RUNNING" } } : c ? h ? { reason: { code: "GESTURE_ACTIVE" } } : b ? {} : { reason: { code: "NO_EDITABLE_TARGETS", nodeIds: o } } : { reason: { code: this.previewMode || this.previewDocument ? "PREVIEW_READ_ONLY" : "EDITING_DISABLED" } },
1230
+ ...T
1231
+ }), v = this.host.getSnapshot().editorial, S = i && s.every((m) => j(this.host.document.root, m.nodeId, v)), r = s.some((m) => j(this.host.document.root, m.nodeId, v));
1232
+ return [
1233
+ ...[
1234
+ ...["translate", "rotate", "scale"].map((m) => p(`tools.${m}`, n.length > 0, { active: this.mode === m })),
1235
+ p("nodes.duplicate", n.length > 0),
1236
+ p("nodes.remove", n.length > 0),
1237
+ p("nodes.group", n.length >= 2),
1238
+ p("nodes.ungroup", this.removableGroupIds(n).length > 0),
1239
+ p("nodes.hide", i, { targetIds: s.map((m) => m.nodeId) }),
1240
+ p("nodes.visibility", i, { targetIds: s.map((m) => m.nodeId), valueState: s.every((m) => !("visible" in m) || m.visible) ? "on" : s.every((m) => "visible" in m && !m.visible) ? "off" : "mixed" }),
1241
+ p("camera.focus", i, { enabled: i, targetIds: s.map((m) => m.nodeId) }),
1242
+ p("nodes.lock", i, { targetIds: s.map((m) => m.nodeId), execution: "atomic", excludedTargets: [], active: S, valueState: S ? "on" : r ? "mixed" : "off" })
1243
+ ].filter((m) => {
1244
+ var b;
1245
+ return ((b = this.actionDefinitions.get(m.id)) == null ? void 0 : b.scope) === "selection";
1246
+ }),
1247
+ ...this.registeredToolbarActions("selection", o),
1248
+ ...this.coreToolbarActions("selection", o)
1249
+ ].map((m) => this.projectActionVisibility(m));
1250
+ }
1251
+ getToolbarState() {
1252
+ var c, h, u;
1253
+ const e = this.host.getSelection(), t = e.instanceIds.length, s = (p, v, S = {}) => ({
1254
+ id: p,
1255
+ scope: "scene",
1256
+ visible: !0,
1257
+ enabled: v && !this.gestureActive(),
1258
+ busy: !1,
1259
+ targetIds: [],
1260
+ execution: "atomic",
1261
+ ...this.gestureActive() ? { reason: { code: "GESTURE_ACTIVE" } } : v ? {} : { reason: {
1262
+ code: p === "camera.fit" ? "SCENE_EMPTY" : this.session.isSimulationRunning() ? "SIMULATION_RUNNING" : this.previewMode || this.previewDocument ? "PREVIEW_READ_ONLY" : this.editingEnabled ? p.startsWith("history.") ? "HISTORY_EMPTY" : "CAPABILITY_UNAVAILABLE" : "EDITING_DISABLED"
1263
+ } },
1264
+ ...S
1265
+ }), o = this.host.getHistoryState(), n = ((c = this.sceneStatus) == null ? void 0 : c.physics.status) === "ready", d = this.session.isSimulationRunning(), a = this.editingEnabled && !this.previewMode && !this.previewDocument && !d, i = {
1266
+ sceneSessionId: this.sceneSessionId,
1267
+ selectionVersion: this.selectionVersion,
1268
+ sequence: this.overlaySequence,
1269
+ anchor: t && this.overlay.visible && Number.isFinite(this.overlay.x) && Number.isFinite(this.overlay.y) ? { x: this.overlay.x, y: this.overlay.y } : null,
1270
+ visible: t > 0 && this.overlay.visible && !this.overlay.transforming && this.editingEnabled && !this.previewMode,
1271
+ hiddenReason: t ? !this.editingEnabled || this.previewMode ? "editing-disabled" : this.overlay.transforming ? "transforming" : this.overlay.hiddenReason ?? (this.overlay.visible ? null : "anchor-unavailable") : "no-selection"
1272
+ };
1273
+ return {
1274
+ sceneSessionId: this.sceneSessionId,
1275
+ contextVersion: this.contextVersion,
1276
+ selection: {
1277
+ version: this.selectionVersion,
1278
+ nodeIds: [...e.instanceIds],
1279
+ primaryId: e.primaryId,
1280
+ kind: t === 0 ? "none" : t === 1 ? "single" : "multiple",
1281
+ typeCounts: this.selectionTypeCounts(e.instanceIds)
1282
+ },
1283
+ scene: { visible: !0, actions: [
1284
+ s("selection.click", a, { active: !this.boxSelectionEnabled }),
1285
+ s("selection.box", a, { active: this.boxSelectionEnabled }),
1286
+ s("camera.fit", (((h = this.sceneStatus) == null ? void 0 : h.instances.length) ?? 0) > 0),
1287
+ s("tools.snap", a, { active: this.snap, valueState: this.snap ? "on" : "off" }),
1288
+ s("viewport.ground", !0, { active: this.groundVisible, valueState: this.groundVisible ? "on" : "off" }),
1289
+ s("history.undo", a && o.canUndo),
1290
+ s("history.redo", a && o.canRedo),
1291
+ s("viewport.collision", !0, { active: this.collisionVisible, valueState: this.collisionVisible ? "on" : "off" }),
1292
+ s("simulation.play", n && !d, { active: d }),
1293
+ s("simulation.pause", n && d, { active: !d && n }),
1294
+ s("simulation.step", n && !d),
1295
+ s("simulation.reset", n),
1296
+ s("simulation.stop", n && (d || (((u = this.sceneStatus) == null ? void 0 : u.instances.length) ?? 0) > 0))
1297
+ ].filter((p) => {
1298
+ var v;
1299
+ return ((v = this.actionDefinitions.get(p.id)) == null ? void 0 : v.scope) === "scene";
1300
+ }).concat(this.registeredToolbarActions("scene", [])).concat(this.coreToolbarActions("scene", [])).map((p) => this.projectActionVisibility(p)) },
1301
+ object: { actions: this.getNodeActions(e.instanceIds), overlay: i }
1302
+ };
1303
+ }
1304
+ async executeAction(e) {
1305
+ this.assertActive();
1306
+ const t = this.getToolbarState();
1307
+ if (e.expectedSceneSessionId !== t.sceneSessionId)
1308
+ throw new g("CONTEXT_STALE", "The scene session has changed.");
1309
+ const s = [...t.scene.actions, ...t.object.actions].find(
1310
+ (a) => a.id === e.actionId
1311
+ );
1312
+ if (s != null && s.busy)
1313
+ throw new g("ACTION_BUSY", "Action is already running: " + e.actionId);
1314
+ if (!s || !s.visible || !s.enabled)
1315
+ throw new g(
1316
+ "ACTION_UNAVAILABLE",
1317
+ `Action is unavailable: ${e.actionId}`
1318
+ );
1319
+ if (s.scope === "selection" && e.expectedSelectionVersion !== t.selection.version)
1320
+ throw new g("CONTEXT_STALE", "The selection has changed.");
1321
+ if (!J(e.targetIds, s.targetIds))
1322
+ throw new g("CONTEXT_STALE", "The action targets have changed.");
1323
+ const o = this.actionDefinitions.get(e.actionId);
1324
+ if (o) {
1325
+ if (o.scope !== s.scope)
1326
+ throw new g(
1327
+ "ACTION_SCOPE_MISMATCH",
1328
+ `Action scope changed: ${e.actionId}`
1329
+ );
1330
+ const a = new AbortController();
1331
+ this.actionControllers.set(e.actionId, a), this.changed();
1332
+ const i = this.getSnapshot();
1333
+ let c = !1;
1334
+ try {
1335
+ return await o.execute(
1336
+ {
1337
+ editor: this.actionReader,
1338
+ snapshot: i,
1339
+ signal: a.signal,
1340
+ commit: (h) => {
1341
+ if (this.assertEditable(), a.signal.aborted || this.actionControllers.get(e.actionId) !== a)
1342
+ throw new g(
1343
+ "ACTION_CANCELLED",
1344
+ "The action has been cancelled or unloaded."
1345
+ );
1346
+ if (c)
1347
+ throw new g(
1348
+ "ACTION_ALREADY_COMMITTED",
1349
+ "An action commits one atomic transaction."
1350
+ );
1351
+ const u = this.host.getSnapshot();
1352
+ if (u.sceneEpoch !== i.host.sceneEpoch || u.documentVersion !== i.host.documentVersion)
1353
+ throw new g("CONTEXT_STALE", "Action document context changed.");
1354
+ if (s.scope === "selection" && (u.selectionVersion !== i.host.selectionVersion || !J(
1355
+ this.host.getSelection().instanceIds,
1356
+ i.host.selection.instanceIds
1357
+ )))
1358
+ throw new g("CONTEXT_STALE", "Action selection changed.");
1359
+ const p = this.host.commit({
1360
+ commands: h,
1361
+ expectedSceneEpoch: i.host.sceneEpoch,
1362
+ expectedDocumentVersion: i.host.documentVersion,
1363
+ ...s.scope === "selection" ? { expectedSelectionVersion: i.host.selectionVersion } : {}
1364
+ });
1365
+ return c = p.changed, p;
1366
+ }
1367
+ },
1368
+ e
1369
+ );
1370
+ } finally {
1371
+ this.actionControllers.get(e.actionId) === a && this.actionControllers.delete(e.actionId), this.changed();
1372
+ }
1373
+ }
1374
+ if (!this.host.getActions().find((a) => a.id === e.actionId && a.scope === s.scope))
1375
+ throw new g("ACTION_UNKNOWN", `Unknown action: ${e.actionId}`);
1376
+ const d = new AbortController();
1377
+ this.actionControllers.set(e.actionId, d), this.coreActionBusy.add(e.actionId), this.changed();
1378
+ try {
1379
+ const a = this.getToolbarState(), i = [...a.scene.actions, ...a.object.actions].find(
1380
+ (h) => h.id === e.actionId
1381
+ );
1382
+ if (!(i != null && i.enabled) || a.sceneSessionId !== e.expectedSceneSessionId || i.scope === "selection" && a.selection.version !== e.expectedSelectionVersion || !J(i.targetIds, e.targetIds))
1383
+ throw new g(
1384
+ "CONTEXT_STALE",
1385
+ "The action context changed before execution."
1386
+ );
1387
+ const c = this.getSnapshot().host;
1388
+ return await this.host.runAction(e.actionId, e, {
1389
+ signal: d.signal,
1390
+ expectedDocumentVersion: c.documentVersion,
1391
+ expectedSceneEpoch: c.sceneEpoch,
1392
+ expectedSelectionVersion: c.selectionVersion,
1393
+ targetIds: i.targetIds
1394
+ });
1395
+ } finally {
1396
+ this.actionControllers.get(e.actionId) === d && this.actionControllers.delete(e.actionId), this.coreActionBusy.delete(e.actionId), this.changed();
1397
+ }
1398
+ }
1399
+ dispose() {
1400
+ if (this.disposal) return this.disposal;
1401
+ this.disposed = !0, this.syncEpoch += 1, this.releaseShortcuts(), this.releaseWritePolicy();
1402
+ for (const e of this.actionControllers.values()) e.abort();
1403
+ return this.actionControllers.clear(), this.coreActionBusy.clear(), this.remoteResolvers.clear(), this.transformOrigins.clear(), this.unsubscribeHost(), this.emit("disposed"), this.listeners.clear(), this.disposal = this.session.dispose().then(async () => {
1404
+ this.options.ownsHost && await this.host.dispose();
1405
+ }), this.disposal;
1406
+ }
1407
+ handleShortcut(e) {
1408
+ if (this.disposed || this.session.isSimulationRunning()) return !1;
1409
+ const t = e.key.toLowerCase(), s = e.ctrlKey || e.metaKey;
1410
+ return s && !e.altKey && t === "z" ? this.runShortcutAction(e.shiftKey ? "history.redo" : "history.undo") : s && !e.altKey && t === "y" ? this.runShortcutAction("history.redo") : s && !e.altKey && t === "d" ? this.runShortcutAction("nodes.duplicate") : s || e.altKey ? !1 : t === "delete" || t === "backspace" ? this.runShortcutAction("nodes.remove") : t === "w" || t === "e" || t === "r" ? this.runShortcutAction({
1411
+ w: "tools.translate",
1412
+ e: "tools.rotate",
1413
+ r: "tools.scale"
1414
+ }[t]) : !e.repeat && t === "l" ? this.runShortcutAction("nodes.lock") : t === "f" ? this.host.getSelection().instanceIds.length > 0 ? this.focusSelection() : this.fit() : !1;
1415
+ }
1416
+ runShortcutAction(e) {
1417
+ const t = this.getToolbarState(), s = [...t.scene.actions, ...t.object.actions].find((o) => o.id === e);
1418
+ return !(s != null && s.visible) || !s.enabled ? !1 : (this.executeAction({
1419
+ actionId: e,
1420
+ targetIds: s.targetIds,
1421
+ expectedSceneSessionId: t.sceneSessionId,
1422
+ expectedSelectionVersion: t.selection.version
1423
+ }).catch((o) => this.report(o)), !0);
1424
+ }
1425
+ editableTargets(e) {
1426
+ const t = this.host.getSnapshot().editorial;
1427
+ return this.selectionClosure(e).filter((s) => k(this.host.document.root, s.nodeId, t) && !X(this.host.document.root, s.nodeId, t));
1428
+ }
1429
+ assertProjectionRepresentable(e) {
1430
+ const t = new Set(ue(this.host.document.root).map(fe)), s = ue(e).find((o) => !t.has(fe(o)));
1431
+ if (s)
1432
+ throw new g(
1433
+ "TRANSFORM_NOT_REPRESENTABLE",
1434
+ `Flat viewer projection would require shear at ${s.nodeId} below ${s.parentNodeId}.`
1435
+ );
1436
+ }
1437
+ selectionClosure(e) {
1438
+ const t = [...new Set(e)], s = new Set(t);
1439
+ return t.map((o) => y(this.host.document.root, o)).filter((o) => o !== null).filter((o) => !ke(this.host.document.root, o.nodeId).slice(0, -1).some((n) => s.has(n.nodeId)));
1440
+ }
1441
+ removableGroupIds(e) {
1442
+ var s;
1443
+ const t = /* @__PURE__ */ new Set();
1444
+ for (const o of e) {
1445
+ const n = y(this.host.document.root, o);
1446
+ if ((n == null ? void 0 : n.nodeType) === "group") {
1447
+ t.add(o);
1448
+ continue;
1449
+ }
1450
+ const d = (s = H(this.host.document.root, o)) == null ? void 0 : s.parent;
1451
+ d && d.nodeId !== this.host.document.root.nodeId && d.nodeType === "group" && t.add(d.nodeId);
1452
+ }
1453
+ return [...t];
1454
+ }
1455
+ sceneInstances() {
1456
+ return V(this.host.document.root);
1457
+ }
1458
+ selectionTypeCounts(e) {
1459
+ const t = {};
1460
+ for (const s of e) {
1461
+ const o = y(this.host.document.root, s);
1462
+ if (!o) continue;
1463
+ const n = o.nodeType === "group" ? "group" : o.nodeType === "visual" ? "visual-instance" : o.nodeType === "placeholder" ? "placeholder" : o.nodeType === "domain" ? "domain-instance" : "asset-instance";
1464
+ t[n] = (t[n] ?? 0) + 1;
1465
+ }
1466
+ return t;
1467
+ }
1468
+ assertActive() {
1469
+ if (this.disposed) throw new g("EDITOR_DISPOSED", "The editor has been disposed.");
1470
+ }
1471
+ installBuiltInActions() {
1472
+ const e = (t, s, o) => {
1473
+ this.actionDefinitions.set(t, { id: t, scope: s, execute: o });
1474
+ };
1475
+ e("tools.translate", "selection", () => this.setMode("translate")), e("tools.rotate", "selection", () => this.setMode("rotate")), e("tools.scale", "selection", () => this.setMode("scale")), e("nodes.duplicate", "selection", (t, s) => this.duplicateSelection(s.targetIds)), e("nodes.remove", "selection", (t, s) => this.deleteSelection(s.targetIds)), e("nodes.group", "selection", (t, s) => this.groupSelection(s.targetIds)), e("nodes.ungroup", "selection", (t, s) => this.ungroupSelection(s.targetIds)), e("nodes.hide", "selection", (t, s) => this.hideNodes(s.targetIds)), e("nodes.visibility", "selection", (t, s) => {
1476
+ const o = s.targetIds.flatMap((n) => {
1477
+ const d = y(this.host.document.root, n);
1478
+ return (d == null ? void 0 : d.nodeType) === "group" ? V(d) : d ? [d] : [];
1479
+ });
1480
+ return this.setNodesVisible(s.targetIds, !o.filter((n) => "visible" in n).every((n) => "visible" in n && n.visible));
1481
+ }), e("camera.focus", "selection", (t, s) => this.session.focusNodes(s.targetIds)), e("nodes.lock", "selection", (t, s) => {
1482
+ const o = s.targetIds.length > 0 && s.targetIds.every((n) => this.host.getEditorialState(n).locked);
1483
+ return this.setSelectionLocked(!o, s.targetIds);
1484
+ }), e("selection.click", "scene", () => this.setBoxSelectionEnabled(!1)), e("selection.box", "scene", () => this.setBoxSelectionEnabled(!0)), e("camera.fit", "scene", () => this.session.fit()), e("tools.snap", "scene", () => this.setSnap(!this.snap)), e("viewport.ground", "scene", () => this.setGroundVisible(!this.groundVisible)), e("viewport.collision", "scene", () => this.setCollisionVisible(!this.collisionVisible)), e("simulation.play", "scene", () => this.playScene()), e("simulation.pause", "scene", () => this.pauseScene()), e("simulation.step", "scene", () => this.stepScene()), e("simulation.reset", "scene", () => this.resetScene()), e("simulation.stop", "scene", () => this.stopScene()), e("history.undo", "scene", () => (this.assertEditable(), this.host.undo())), e("history.redo", "scene", () => (this.assertEditable(), this.host.redo()));
1485
+ }
1486
+ registeredToolbarActions(e, t) {
1487
+ const s = {
1488
+ editor: this.actionReader,
1489
+ selectionIds: t,
1490
+ editingEnabled: this.editingEnabled,
1491
+ previewMode: this.previewMode,
1492
+ previewSelection: this.previewSelection,
1493
+ previewing: this.previewDocument !== null,
1494
+ gestureActive: this.gestureActive()
1495
+ };
1496
+ return [...this.actionDefinitions.values()].filter((o) => o.scope === e && o.getState).map((o) => {
1497
+ const n = o.getState(s), d = e === "selection" ? this.selectionClosure(n.targetIds).map((a) => a.nodeId) : n.targetIds;
1498
+ return {
1499
+ ...n,
1500
+ targetIds: d,
1501
+ busy: n.busy || this.actionControllers.has(o.id)
1502
+ };
1503
+ }).filter((o) => o.scope === e);
1504
+ }
1505
+ coreToolbarActions(e, t) {
1506
+ const s = this.editingEnabled && !this.previewMode && !this.previewDocument, o = this.gestureActive();
1507
+ return this.host.getActions().filter((n) => n.scope === e).map((n) => {
1508
+ const d = e === "selection" ? [...t] : [], a = s && !o && (e === "scene" || d.length > 0);
1509
+ return {
1510
+ id: n.id,
1511
+ scope: e,
1512
+ visible: !0,
1513
+ enabled: a,
1514
+ busy: this.coreActionBusy.has(n.id),
1515
+ targetIds: d,
1516
+ execution: n.scope === "selection" ? "eligible-subset" : "atomic",
1517
+ ...a ? {} : {
1518
+ reason: {
1519
+ code: this.previewMode || this.previewDocument ? "PREVIEW_READ_ONLY" : this.editingEnabled ? o ? "GESTURE_ACTIVE" : "NO_EDITABLE_TARGETS" : "EDITING_DISABLED"
1520
+ }
1521
+ }
1522
+ };
1523
+ });
1524
+ }
1525
+ gestureActive() {
1526
+ return this.overlay.transforming || this.overlay.hiddenReason === "selecting";
1527
+ }
1528
+ syncInteractionMode() {
1529
+ const e = this.session.isSimulationRunning();
1530
+ this.session.setEditingEnabled(
1531
+ this.editingEnabled && !this.previewMode && !this.previewDocument && !e
1532
+ ), this.session.setSelectionInspectionEnabled(
1533
+ this.previewMode && this.previewSelection === "inspect" && !e
1534
+ );
1535
+ }
1536
+ assertEditable(e = !1) {
1537
+ if (this.assertActive(), this.previewMode || this.previewDocument) throw new g("PREVIEW_READ_ONLY", "The current scene is read-only.");
1538
+ if (!this.editingEnabled) throw new g("EDITING_DISABLED", "The current scene is read-only.");
1539
+ if (this.session.isSimulationRunning()) throw new g("SIMULATION_RUNNING", "Pause or stop the simulation before editing the scene.");
1540
+ if (!e && this.gestureActive()) throw new g("GESTURE_ACTIVE", "Finish or cancel the active gesture before editing the scene.");
1541
+ }
1542
+ changed() {
1543
+ this.contextVersion += 1, this.emit("toolbar.change");
1544
+ }
1545
+ emit(e) {
1546
+ this.emitEvent({ type: e, snapshot: this.getSnapshot() });
1547
+ }
1548
+ emitEvent(e) {
1549
+ for (const t of [...this.listeners]) this.notify(t, e);
1550
+ }
1551
+ notify(e, t) {
1552
+ var s, o;
1553
+ try {
1554
+ e(t);
1555
+ } catch (n) {
1556
+ try {
1557
+ (o = (s = this.options).onError) == null || o.call(s, n);
1558
+ } catch {
1559
+ }
1560
+ }
1561
+ }
1562
+ report(e) {
1563
+ var t, s;
1564
+ if (!this.disposed) {
1565
+ try {
1566
+ (s = (t = this.options).onError) == null || s.call(t, e);
1567
+ } catch {
1568
+ }
1569
+ this.emitEvent({ type: "error", snapshot: this.getSnapshot(), error: e });
1570
+ }
1571
+ }
1572
+ }
1573
+ function ee(l) {
1574
+ return l ? l.nodeType === "group" ? [l.nodeId, ...l.children.flatMap((e) => ee(e))] : [l.nodeId] : [];
1575
+ }
1576
+ function nt(l) {
1577
+ if (!Array.isArray(l.local) || l.local.length !== 3 || l.local.some((e) => !Number.isFinite(e)))
1578
+ throw new g(
1579
+ "ORIGIN_OFFSET_INVALID",
1580
+ "Node origin.local must contain three finite source-content metre values."
1581
+ );
1582
+ }
1583
+ function Z(l, e, t) {
1584
+ return e && Number.isFinite(t) ? [{ movedNodeId: l, supportNodeId: e, surfaceZ: t }] : [];
1585
+ }
1586
+ function fe(l) {
1587
+ return `${l.parentNodeId}\0${l.nodeId}`;
1588
+ }
1589
+ function J(l, e) {
1590
+ const t = new Set(l), s = new Set(e);
1591
+ return t.size === s.size && [...t].every((o) => s.has(o));
1592
+ }
1593
+ function vt(l, e) {
1594
+ return new it(l, e);
1595
+ }
1596
+ function rt(l) {
1597
+ return {
1598
+ schemaVersion: 1,
1599
+ viewMode: l.viewMode,
1600
+ ...l.orbit ? { orbit: { ...l.orbit } } : {},
1601
+ ...l.orthographic ? { orthographic: { ...l.orthographic } } : {}
1602
+ };
1603
+ }
1604
+ const at = 1;
1605
+ function It(l) {
1606
+ const { editor: e } = l, t = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
1607
+ let o = !1, n = !1, d, a = 0;
1608
+ function i(r) {
1609
+ try {
1610
+ l.onError ? l.onError(r) : console.error(`[sim-studio UI plugin ${r.pluginId}] ${r.phase}`, r.error);
1611
+ } catch {
1612
+ }
1613
+ }
1614
+ function c() {
1615
+ if (n) throw new Error("The Studio UI plugin host has been disposed.");
1616
+ }
1617
+ function h(r, f, m) {
1618
+ try {
1619
+ f();
1620
+ } catch (b) {
1621
+ i({ pluginId: r.plugin.id, viewId: m, phase: "dispose", error: b });
1622
+ }
1623
+ }
1624
+ function u(r) {
1625
+ if (!r.removed) {
1626
+ r.removed = !0, r.active = !1, r.listeners.clear();
1627
+ for (const f of [...r.cleanups].reverse()) h(r, f);
1628
+ r.cleanups.clear(), t.get(r.plugin.id) === r && t.delete(r.plugin.id);
1629
+ }
1630
+ }
1631
+ function p(r, f) {
1632
+ var C;
1633
+ if (r.removed) throw new Error(`Plugin ${r.plugin.id} has been removed.`);
1634
+ if (!f.id.trim()) throw new Error("UI view IDs must be non-empty.");
1635
+ const m = JSON.stringify([r.plugin.id, f.id]);
1636
+ if (s.has(m)) throw new Error(`Duplicate UI view ${m}.`);
1637
+ const b = l.slots[f.slot];
1638
+ if (!b) throw new Error(`No frontend container provided for UI slot ${f.slot}.`);
1639
+ const T = b.ownerDocument.createElement("div");
1640
+ T.dataset.studioUiPlugin = r.plugin.id, T.dataset.studioUiView = f.id, T.dataset.studioUiSlot = f.slot;
1641
+ const _ = a++, D = [...s.values()].filter((O) => O.contribution.slot === f.slot).sort((O, U) => (O.contribution.order ?? 0) - (U.contribution.order ?? 0) || O.sequence - U.sequence).find((O) => (O.contribution.order ?? 0) > (f.order ?? 0));
1642
+ b.insertBefore(T, (D == null ? void 0 : D.container) ?? null);
1643
+ let N;
1644
+ try {
1645
+ N = f.mount(T, { editor: e, snapshot: e.getSnapshot() });
1646
+ } catch (O) {
1647
+ throw T.remove(), i({ pluginId: r.plugin.id, viewId: f.id, phase: "mount", error: O }), O;
1648
+ }
1649
+ let F = !1;
1650
+ const R = () => {
1651
+ if (!F) {
1652
+ F = !0, s.delete(m), r.cleanups.delete(R);
1653
+ try {
1654
+ typeof N == "function" ? N() : N == null || N.dispose();
1655
+ } finally {
1656
+ T.remove();
1657
+ }
1658
+ }
1659
+ }, z = {
1660
+ owner: r,
1661
+ contribution: f,
1662
+ container: T,
1663
+ sequence: _,
1664
+ update: typeof N == "object" && N ? (C = N.update) == null ? void 0 : C.bind(N) : void 0,
1665
+ dispose: R
1666
+ };
1667
+ return s.set(m, z), r.cleanups.add(R), () => h(r, R, f.id);
1668
+ }
1669
+ function v(r) {
1670
+ if (!(r.active || r.removed)) {
1671
+ r.active = !0;
1672
+ try {
1673
+ const f = r.plugin.activate({
1674
+ editor: e,
1675
+ contributions: { addView: (m) => p(r, m) },
1676
+ events: {
1677
+ subscribe(m) {
1678
+ if (r.removed) throw new Error(`Plugin ${r.plugin.id} has been removed.`);
1679
+ return r.listeners.add(m), () => {
1680
+ r.listeners.delete(m);
1681
+ };
1682
+ }
1683
+ }
1684
+ });
1685
+ f && r.cleanups.add(f);
1686
+ } catch (f) {
1687
+ throw u(r), i({ pluginId: r.plugin.id, phase: "activate", error: f }), f;
1688
+ }
1689
+ }
1690
+ }
1691
+ function S(r) {
1692
+ if (n) return;
1693
+ const f = e.getSnapshot();
1694
+ for (const m of [...s.values()])
1695
+ if (!(m.owner.removed || !m.update))
1696
+ try {
1697
+ m.update({ editor: e, snapshot: f });
1698
+ } catch (b) {
1699
+ i({ pluginId: m.owner.plugin.id, viewId: m.contribution.id, phase: "update", error: b }), h(m.owner, m.dispose, m.contribution.id);
1700
+ }
1701
+ for (const m of [...t.values()])
1702
+ if (!(!m.active || m.removed))
1703
+ for (const b of [...m.listeners]) {
1704
+ if (m.removed) break;
1705
+ try {
1706
+ b(r);
1707
+ } catch (T) {
1708
+ i({ pluginId: m.plugin.id, phase: "event", error: T });
1709
+ }
1710
+ }
1711
+ }
1712
+ return {
1713
+ register(r) {
1714
+ if (c(), !r.id.trim()) throw new Error("UI plugin IDs must be non-empty.");
1715
+ if (r.apiVersion !== at)
1716
+ throw new Error(`Unsupported UI plugin API version for ${r.id}: ${r.apiVersion}.`);
1717
+ if (t.has(r.id)) throw new Error(`Duplicate UI plugin ${r.id}.`);
1718
+ const f = {
1719
+ plugin: r,
1720
+ cleanups: /* @__PURE__ */ new Set(),
1721
+ listeners: /* @__PURE__ */ new Set(),
1722
+ active: !1,
1723
+ removed: !1
1724
+ };
1725
+ return t.set(r.id, f), o && v(f), () => u(f);
1726
+ },
1727
+ start() {
1728
+ if (c(), o) return;
1729
+ o = !0;
1730
+ const r = [];
1731
+ for (const f of [...t.values()])
1732
+ try {
1733
+ v(f);
1734
+ } catch (m) {
1735
+ r.push(m);
1736
+ }
1737
+ if (d = e.subscribe(S), r.length) throw new AggregateError(r, "One or more Studio UI plugins failed to activate.");
1738
+ },
1739
+ dispose() {
1740
+ if (!n) {
1741
+ n = !0, d == null || d(), d = void 0;
1742
+ for (const r of [...t.values()].reverse()) u(r);
1743
+ }
1744
+ }
1745
+ };
1746
+ }
1747
+ export {
1748
+ at as STUDIO_UI_PLUGIN_API_VERSION,
1749
+ it as StudioEditor,
1750
+ g as StudioEditorError,
1751
+ vt as createStudioEditor,
1752
+ It as createStudioUiPluginHost,
1753
+ ve as sceneSourceFromResolution,
1754
+ st as visualSceneSourceFromResolution
1755
+ };