@nebula-spatial/studio 0.1.0 → 0.1.2

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 (50) hide show
  1. package/README.md +2 -0
  2. package/dist/assets/openusd_three_loader-DLiqJWUM.js +13769 -0
  3. package/dist/assets/usd-export-worker-BRxTLqer.js +182 -0
  4. package/dist/assets/usd-worker-DekqMsQv.js +1392 -0
  5. package/dist/{builders-BAXRR5o5.js → builders-lydx4-Rh.js} +1 -1
  6. package/dist/core/session-persistence-controller.d.ts +55 -0
  7. package/dist/doc/placement-policy.d.ts +4 -0
  8. package/dist/editor/editor.d.ts +3 -1
  9. package/dist/editor/index.d.ts +2 -0
  10. package/dist/editor/session-persistence.d.ts +54 -0
  11. package/dist/editor.js +727 -490
  12. package/dist/export-evidence-z2Ne7Trf.js +2387 -0
  13. package/dist/generalization.js +2 -2
  14. package/dist/index.d.ts +4 -2
  15. package/dist/index.js +314 -306
  16. package/dist/mjcf-visual-IOy-ucto.js +72 -0
  17. package/dist/mujoco-runtime-BYZnrvbR.js +467 -0
  18. package/dist/persist/indexeddb-store.d.ts +22 -2
  19. package/dist/persist/session.d.ts +22 -0
  20. package/dist/persist/snapshot.d.ts +24 -0
  21. package/dist/{physics-facts-tfQYyNTD.js → physics-facts-D-URIBrt.js} +8 -7
  22. package/dist/{placement-policy-DY_FNRDu.js → placement-policy-C6dV6Tf-.js} +161 -141
  23. package/dist/ports/persistence.d.ts +45 -1
  24. package/dist/project/contracts.d.ts +3 -0
  25. package/dist/remote-asset-resolver-D-UeyDMD.js +311 -0
  26. package/dist/{scene-graph-DBLKAhxa.js → scene-graph-DVOXjMmp.js} +2 -2
  27. package/dist/scene-session-PhoFXFCY.js +22006 -0
  28. package/dist/scene.js +2 -2
  29. package/dist/session-2bp8YOA4.js +963 -0
  30. package/dist/session-B3WbC7Y2.js +296 -0
  31. package/dist/session-B9kEf4xN.js +915 -0
  32. package/dist/session-DYThdzLZ.js +825 -0
  33. package/dist/studio/index.d.ts +5 -0
  34. package/dist/studio/indexeddb-persistence.d.ts +2 -0
  35. package/dist/studio/indexeddb-session-persistence.d.ts +11 -0
  36. package/dist/studio/scene-package-asset-sources.d.ts +14 -0
  37. package/dist/studio.js +1423 -1220
  38. package/dist/urdf-session-CRXL4bHf.js +1230 -0
  39. package/dist/usd-session-CTzInpNy.js +7385 -0
  40. package/dist/version.d.ts +1 -1
  41. package/dist/view/scene-session.d.ts +5 -1
  42. package/dist/wasm-module-DZn2AM1W.js +13 -0
  43. package/dist/xacro-IpPHTMYs.js +76 -0
  44. package/package.json +1 -1
  45. package/dist/asset-source-BExlEcRt.js +0 -444
  46. package/dist/assets/usd-export-worker-BsGubtAE.js +0 -1
  47. package/dist/editorial-BkAFWfbg.js +0 -83
  48. package/dist/export-evidence-B_0zRmb8.js +0 -5027
  49. package/dist/remote-asset-resolver-Cb8cfNmw.js +0 -136
  50. package/dist/scene-session-BV1HnxNh.js +0 -3506
@@ -0,0 +1,915 @@
1
+ var ee = Object.defineProperty;
2
+ var te = (e, t, o) => t in e ? ee(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
3
+ var x = (e, t, o) => te(e, typeof t != "symbol" ? t + "" : t, o);
4
+ import { k as u, s as g, g as v, a1 as oe, v as M } from "./builders-lydx4-Rh.js";
5
+ import { S as b, a as F, w as j } from "./scene-graph-DVOXjMmp.js";
6
+ const _ = "application/octet-stream", ne = {
7
+ ".usda": "model/vnd.usda",
8
+ ".usd": "model/vnd.usda",
9
+ ".usdc": "model/vnd.usdc",
10
+ ".usdz": "model/vnd.usdz+zip",
11
+ ".glb": "model/gltf-binary",
12
+ ".gltf": "model/gltf+json",
13
+ ".ply": "application/x-ply",
14
+ ".spz": "application/x-spz",
15
+ ".splat": "application/x-gaussian-splat",
16
+ ".ksplat": "application/x-ksplat",
17
+ ".rad": "application/x-rad",
18
+ ".zip": "application/zip",
19
+ ".json": "application/json",
20
+ ".png": "image/png",
21
+ ".jpg": "image/jpeg",
22
+ ".jpeg": "image/jpeg",
23
+ ".webp": "image/webp",
24
+ ".ktx2": "image/ktx2",
25
+ ".exr": "image/x-exr",
26
+ ".mdl": "text/plain"
27
+ }, re = /* @__PURE__ */ new Set([
28
+ _,
29
+ "binary/octet-stream"
30
+ ]);
31
+ function V(e) {
32
+ return ne[ae(e)] ?? null;
33
+ }
34
+ function ze(e) {
35
+ return V(e) ?? _;
36
+ }
37
+ function H(e, ...t) {
38
+ for (const o of t) {
39
+ const n = se(o);
40
+ if (n) return n;
41
+ }
42
+ return V(e);
43
+ }
44
+ function ae(e) {
45
+ const t = e.replaceAll("\\", "/"), o = t.slice(t.lastIndexOf("/") + 1).toLowerCase(), n = o.lastIndexOf(".");
46
+ return n >= 0 ? o.slice(n) : "";
47
+ }
48
+ function se(e) {
49
+ const t = e == null ? void 0 : e.trim();
50
+ return !t || re.has(t.toLowerCase()) ? null : t;
51
+ }
52
+ const C = "ASSET_SOURCE_INVALID_LOCATOR";
53
+ function I(e) {
54
+ if (!e || e.startsWith("/") || e.includes("\\"))
55
+ throw new u(
56
+ C,
57
+ `Package resource path must be a non-empty forward-slash relative path: ${e}.`
58
+ );
59
+ const t = [];
60
+ for (const n of e.split("/"))
61
+ if (!(!n || n === ".")) {
62
+ if (n === "..") {
63
+ if (t.length === 0)
64
+ throw new u(
65
+ C,
66
+ `Package resource path escapes its logical root: ${e}.`
67
+ );
68
+ t.pop();
69
+ continue;
70
+ }
71
+ t.push(n);
72
+ }
73
+ const o = t.join("/");
74
+ if (!o)
75
+ throw new u(
76
+ C,
77
+ `Package resource path normalizes to an empty value: ${e}.`
78
+ );
79
+ return o;
80
+ }
81
+ function O(e) {
82
+ const t = new URL(e);
83
+ if (t.protocol !== "http:" && t.protocol !== "https:" || t.username || t.password || t.hash)
84
+ throw new u(
85
+ C,
86
+ `Remote resource URL must be an absolute HTTP(S) URL without credentials or fragment: ${e}.`
87
+ );
88
+ return `${t.origin}${t.pathname}`;
89
+ }
90
+ function R(e) {
91
+ return e.kind === "package-path" ? { kind: "package-path", path: I(e.path) } : { kind: "remote-url", url: O(e.url) };
92
+ }
93
+ function l(e) {
94
+ const t = R(e);
95
+ return t.kind === "package-path" ? `package:${t.path}` : `remote:${t.url}`;
96
+ }
97
+ function ie(e, t) {
98
+ return `res_${g(`${l(e)}\0${t}`).slice(0, 32)}`;
99
+ }
100
+ function _e(e) {
101
+ return e.kind === "package-path" ? I(e.path) : null;
102
+ }
103
+ function Le(e) {
104
+ return e.kind === "remote-url" ? O(e.url) : null;
105
+ }
106
+ function Pe(e) {
107
+ const t = R(e);
108
+ if (t.kind === "package-path") return t.path;
109
+ const o = new URL(t.url), n = o.pathname.split("/").filter(Boolean), r = n.length === 0 ? "r-root" : [
110
+ `p-${encodeURIComponent(n[0])}`,
111
+ ...n.slice(1)
112
+ ].join("/");
113
+ return I(
114
+ `remote-assets/${encodeURIComponent(o.origin)}/${r}`
115
+ );
116
+ }
117
+ function Ue(e, t, o = []) {
118
+ const n = t.trim();
119
+ if (!n) return null;
120
+ const r = R(e), s = new Set(o.map(l));
121
+ if (r.kind === "remote-url")
122
+ try {
123
+ const d = new URL(n, r.url);
124
+ return {
125
+ kind: "remote-url",
126
+ url: O(d.href)
127
+ };
128
+ } catch {
129
+ return null;
130
+ }
131
+ if (/^[a-z][a-z\d+.-]*:/i.test(n)) return null;
132
+ if (n.startsWith("/"))
133
+ try {
134
+ return { kind: "package-path", path: I(n.slice(1)) };
135
+ } catch {
136
+ return null;
137
+ }
138
+ const i = r.path.split("/");
139
+ i.pop();
140
+ let a = null;
141
+ for (let d = i.length; d >= 0; d -= 1) {
142
+ const c = i.slice(0, d).join("/");
143
+ try {
144
+ const p = {
145
+ kind: "package-path",
146
+ path: I(c ? `${c}/${n}` : n)
147
+ };
148
+ if (a ?? (a = p), s.size === 0 || s.has(l(p)))
149
+ return p;
150
+ } catch {
151
+ }
152
+ }
153
+ return a;
154
+ }
155
+ const h = {
156
+ unavailable: "ASSET_SOURCE_UNAVAILABLE",
157
+ conflict: "SOURCE_REVISION_CONFLICT",
158
+ unverifiable: "SOURCE_FACTS_UNVERIFIABLE",
159
+ factsMismatch: "ASSET_SOURCE_FACTS_MISMATCH",
160
+ invalidLocator: "ASSET_SOURCE_INVALID_LOCATOR"
161
+ };
162
+ function q(e) {
163
+ const t = new URL(e.entryUrl);
164
+ if (t.protocol !== "http:" && t.protocol !== "https:" || t.username || t.password || t.hash)
165
+ throw new u(
166
+ h.invalidLocator,
167
+ `Remote asset entry URL must be an absolute HTTP(S) URL without credentials or fragment: ${e.entryUrl}.`
168
+ );
169
+ const o = e.allowedScopes ? e.allowedScopes.map(L) : void 0, n = {
170
+ kind: "remote-entry",
171
+ revisionId: e.revisionId,
172
+ entryUrl: t.href,
173
+ ...e.request ? { request: e.request } : {},
174
+ ...o ? { allowedScopes: o } : {}
175
+ };
176
+ if (!W(n, t))
177
+ throw new u(
178
+ h.invalidLocator,
179
+ `Remote asset entry URL is outside its allowed scopes: ${t.href}.`
180
+ );
181
+ return n;
182
+ }
183
+ function B(e) {
184
+ if (!e.allowedScopes) return [];
185
+ const t = /* @__PURE__ */ new Map();
186
+ for (const o of e.allowedScopes) {
187
+ const n = L(o);
188
+ t.set(`${n.origin}\0${n.pathPrefix}`, n);
189
+ }
190
+ return [...t.values()].sort((o, n) => o.origin.localeCompare(n.origin) || o.pathPrefix.localeCompare(n.pathPrefix));
191
+ }
192
+ function W(e, t) {
193
+ return e.allowedScopes ? B(e).some((o) => le(t, o)) : t.protocol === "http:" || t.protocol === "https:";
194
+ }
195
+ function ce(e, t) {
196
+ const o = Y(e), n = G(t), r = o.endsWith("/") ? o : `${o}/`;
197
+ return n === "/" || r === n || o.startsWith(n);
198
+ }
199
+ function le(e, t) {
200
+ const o = L(t);
201
+ return e.origin === o.origin && ce(e.pathname, o.pathPrefix);
202
+ }
203
+ function J(e) {
204
+ return O(e.entryUrl);
205
+ }
206
+ function L(e) {
207
+ const t = new URL(e.origin);
208
+ if (t.protocol !== "http:" && t.protocol !== "https:" || t.username || t.password || t.pathname !== "/" || t.search || t.hash)
209
+ throw new u(
210
+ h.invalidLocator,
211
+ `Asset scope origin must be a canonical HTTP(S) origin: ${e.origin}.`
212
+ );
213
+ return {
214
+ origin: t.origin,
215
+ pathPrefix: G(e.pathPrefix)
216
+ };
217
+ }
218
+ function G(e) {
219
+ if (!e.startsWith("/"))
220
+ throw new u(
221
+ h.invalidLocator,
222
+ `Asset scope pathPrefix must be absolute: ${e}.`
223
+ );
224
+ const t = Y(e);
225
+ return t.endsWith("/") ? t : `${t}/`;
226
+ }
227
+ function Y(e) {
228
+ const t = new URL(e, "https://scope.invalid");
229
+ let o;
230
+ try {
231
+ o = decodeURIComponent(t.pathname);
232
+ } catch {
233
+ throw new u(
234
+ h.invalidLocator,
235
+ `Asset resource path contains invalid URL escaping: ${e}.`
236
+ );
237
+ }
238
+ const n = [];
239
+ for (const r of o.split("/"))
240
+ !r || r === "." || (r === ".." ? n.pop() : n.push(r));
241
+ return `/${n.join("/")}${o.endsWith("/") && n.length ? "/" : ""}`;
242
+ }
243
+ function de(e) {
244
+ return "visualRevisionId" in e ? e.visualRevisionId : e.revisionId;
245
+ }
246
+ function xe(e) {
247
+ return e.kind === "local-package" ? {
248
+ kind: "local-package",
249
+ revisionId: e.revisionId,
250
+ entryPath: e.entryPath,
251
+ files: e.files.map((t) => ({ locator: t.locator, blob: t.blob }))
252
+ } : {
253
+ kind: "remote-entry",
254
+ revisionId: e.revisionId,
255
+ entryUrl: e.entryUrl,
256
+ ...e.request ? { request: e.request } : {},
257
+ ...e.allowedScopes ? { allowedScopes: e.allowedScopes.map((t) => ({ ...t })) } : {}
258
+ };
259
+ }
260
+ async function ue(e, t = {}) {
261
+ var i, a, d;
262
+ if ((i = t.signal) == null || i.throwIfAborted(), e.kind === "remote-entry") {
263
+ const c = q(e);
264
+ return {
265
+ source: c,
266
+ facts: [],
267
+ fingerprint: $(c)
268
+ };
269
+ }
270
+ const o = [];
271
+ for (const c of e.files) {
272
+ (a = t.signal) == null || a.throwIfAborted();
273
+ const p = R(c.locator);
274
+ if (p.kind !== "package-path")
275
+ throw new u(
276
+ h.invalidLocator,
277
+ `Local asset sources cannot contain remote resources: ${p.url}.`
278
+ );
279
+ const k = I(p.path), T = new Uint8Array(await c.blob.arrayBuffer());
280
+ (d = t.signal) == null || d.throwIfAborted(), o.push({
281
+ locator: { kind: "package-path", path: k },
282
+ blob: c.blob,
283
+ resourceId: ie(
284
+ { kind: "package-path", path: k },
285
+ g(T)
286
+ ),
287
+ sha256: g(T),
288
+ byteSize: T.byteLength,
289
+ mediaType: H(k, c.blob.type) ?? _
290
+ });
291
+ }
292
+ o.sort((c, p) => c.resourceId.localeCompare(p.resourceId));
293
+ const n = I(e.entryPath);
294
+ if (!o.some((c) => c.locator.kind === "package-path" && c.locator.path === n))
295
+ throw new u(
296
+ h.unverifiable,
297
+ `Local asset source is missing its entry: ${e.entryPath}.`
298
+ );
299
+ const r = {
300
+ kind: "local-package",
301
+ revisionId: e.revisionId,
302
+ entryPath: n,
303
+ files: o.map((c) => ({ locator: c.locator, blob: c.blob }))
304
+ }, s = o.map(({ resourceId: c, locator: p, sha256: k, byteSize: T, mediaType: Z }) => ({
305
+ resourceId: c,
306
+ locator: p,
307
+ sha256: k,
308
+ byteSize: T,
309
+ mediaType: Z
310
+ }));
311
+ return {
312
+ source: r,
313
+ facts: s,
314
+ fingerprint: $(r, s)
315
+ };
316
+ }
317
+ function pe(e, t) {
318
+ const o = de(t);
319
+ if (e.revisionId !== o)
320
+ throw m(
321
+ `Asset source revision ${e.revisionId} does not match requested revision ${o}.`
322
+ );
323
+ const n = t.resources.find((i) => i.resourceId === t.entryResourceId);
324
+ if (!n)
325
+ throw m(
326
+ `Asset source entry does not match revision facts for ${o}.`
327
+ );
328
+ if (e.kind === "remote-entry") {
329
+ if (q(e), n.locator.kind !== "remote-url" || n.locator.url !== J(e))
330
+ throw m(
331
+ `Remote asset source entry does not match revision facts for ${o}.`
332
+ );
333
+ for (const i of t.resources) {
334
+ if (i.locator.kind !== "remote-url")
335
+ throw m(
336
+ `Remote asset source does not authorize revision resource ${l(i.locator)}.`
337
+ );
338
+ const a = new URL(i.locator.url);
339
+ if (!W(e, a))
340
+ throw m(
341
+ `Remote asset source does not authorize revision resource ${l(i.locator)}.`
342
+ );
343
+ }
344
+ return;
345
+ }
346
+ if (n.locator.kind !== "package-path" || n.locator.path !== e.entryPath)
347
+ throw m(
348
+ `Local asset source entry does not match revision facts for ${o}.`
349
+ );
350
+ const r = new Map(t.resources.map((i) => [
351
+ l(i.locator),
352
+ i
353
+ ])), s = new Map(e.files.map((i) => [
354
+ l(i.locator),
355
+ i
356
+ ]));
357
+ if (r.size !== s.size)
358
+ throw m(`Local asset source path set does not match ${o}.`);
359
+ for (const [i, a] of s) {
360
+ const d = r.get(i);
361
+ if (!d || a.blob.size !== d.byteSize)
362
+ throw m(`Local asset source facts do not match ${o}/${i}.`);
363
+ }
364
+ }
365
+ async function $e(e, t, o = {}) {
366
+ var i;
367
+ if (pe(e, t), e.kind === "remote-entry") return;
368
+ const n = await ue(e, o), r = new Map(t.resources.map((a) => [
369
+ l(a.locator),
370
+ a
371
+ ])), s = new Map(e.files.map((a) => [
372
+ l(a.locator),
373
+ a.blob
374
+ ]));
375
+ for (const a of n.facts) {
376
+ const d = r.get(l(a.locator));
377
+ if (!d || d.sha256 !== a.sha256 || d.byteSize !== a.byteSize)
378
+ throw m(`Local asset source bytes do not match ${e.revisionId}/${l(a.locator)}.`);
379
+ const c = H(
380
+ a.locator.kind === "package-path" ? a.locator.path : a.locator.url,
381
+ (i = s.get(l(a.locator))) == null ? void 0 : i.type
382
+ );
383
+ if (c && c !== d.mediaType)
384
+ throw m(
385
+ `Local asset source mediaType does not match ${e.revisionId}/${l(a.locator)}.`
386
+ );
387
+ }
388
+ }
389
+ function $(e, t = []) {
390
+ return v(
391
+ e.kind === "local-package" ? {
392
+ kind: e.kind,
393
+ revisionId: e.revisionId,
394
+ entryPath: e.entryPath,
395
+ facts: t.map((o) => ({
396
+ locator: o.locator,
397
+ sha256: o.sha256,
398
+ byteSize: o.byteSize,
399
+ mediaType: o.mediaType
400
+ })).sort((o, n) => l(o.locator).localeCompare(
401
+ l(n.locator)
402
+ ))
403
+ } : {
404
+ kind: e.kind,
405
+ revisionId: e.revisionId,
406
+ entryUrl: J(e),
407
+ scopePolicy: e.allowedScopes === void 0 ? "unrestricted-http" : "explicit",
408
+ scopes: B(e).map((o) => `${o.origin}${o.pathPrefix}`)
409
+ }
410
+ );
411
+ }
412
+ function Ne(e) {
413
+ return {
414
+ assetId: e.revisionId,
415
+ entryLocator: { kind: "package-path", path: e.entryPath },
416
+ files: e.files.map((t) => ({ locator: t.locator, blob: t.blob }))
417
+ };
418
+ }
419
+ function m(e) {
420
+ return new u(h.factsMismatch, e);
421
+ }
422
+ const De = "document.json", Me = "sim-studio.document@7", w = {
423
+ notJson: "SCENE_FILE_NOT_JSON",
424
+ unsupportedFormat: "SCENE_FILE_UNSUPPORTED_FORMAT",
425
+ unsupportedVersion: "SCENE_FILE_UNSUPPORTED_VERSION",
426
+ migrated: "SCENE_FILE_MIGRATED",
427
+ invalidDocument: "SCENE_FILE_INVALID_DOCUMENT"
428
+ };
429
+ function P(e, t = {}) {
430
+ const o = {
431
+ schemaVersion: b,
432
+ sceneId: e.sceneId,
433
+ meta: { ...e.meta },
434
+ coordinateSystem: {
435
+ ...e.coordinateSystem,
436
+ units: { ...e.coordinateSystem.units },
437
+ origin: e.coordinateSystem.origin
438
+ },
439
+ environment: Ie(e.environment),
440
+ assets: [...e.assets].map(ge).sort((n, r) => n.revisionId.localeCompare(r.revisionId)),
441
+ visualAssets: [...e.visualAssets].map(Se).sort((n, r) => n.visualRevisionId.localeCompare(r.visualRevisionId)),
442
+ root: Q(e.root),
443
+ ...e.semantic ? { semantic: we(e.semantic) } : {},
444
+ ...e.domains ? { domains: fe(e.domains) } : {},
445
+ ...e.extensions ? { extensions: A(e.extensions) } : {}
446
+ };
447
+ return oe(o, t.domainExtensions);
448
+ }
449
+ function z(e, t = {}) {
450
+ return me(e, b, t);
451
+ }
452
+ function me(e, t, o = {}) {
453
+ const n = P(e, o), r = {
454
+ ...n,
455
+ schemaVersion: t
456
+ }, { updatedAt: s, ...i } = n.meta, a = {
457
+ ...r,
458
+ meta: i
459
+ };
460
+ return g(v(a));
461
+ }
462
+ function he(e, t = {}) {
463
+ const o = P(e, t), n = M(o, t);
464
+ return n.ok ? {
465
+ text: `${v(o)}
466
+ `,
467
+ contentHash: z(o, t),
468
+ diagnostics: n.diagnostics
469
+ } : {
470
+ text: "",
471
+ contentHash: z(o, t),
472
+ diagnostics: [
473
+ {
474
+ code: w.invalidDocument,
475
+ level: "error",
476
+ message: `Scene document does not satisfy schema version ${b}.`
477
+ },
478
+ ...n.diagnostics
479
+ ]
480
+ };
481
+ }
482
+ const Fe = he;
483
+ function K(e, t = {}) {
484
+ let o;
485
+ try {
486
+ o = JSON.parse(e);
487
+ } catch (s) {
488
+ return {
489
+ document: null,
490
+ contentHash: null,
491
+ migratedFrom: null,
492
+ diagnostics: [{
493
+ code: w.notJson,
494
+ level: "error",
495
+ message: `Scene document is not valid JSON: ${s instanceof Error ? s.message : String(s)}`
496
+ }]
497
+ };
498
+ }
499
+ if (!Ee(o))
500
+ return {
501
+ document: null,
502
+ contentHash: null,
503
+ migratedFrom: null,
504
+ diagnostics: [{
505
+ code: w.invalidDocument,
506
+ level: "error",
507
+ message: "Scene document must be a JSON object."
508
+ }]
509
+ };
510
+ if ("fileVersion" in o || "doc" in o || "assets" in o && !("schemaVersion" in o))
511
+ return {
512
+ document: null,
513
+ contentHash: null,
514
+ migratedFrom: null,
515
+ diagnostics: [{
516
+ code: w.unsupportedFormat,
517
+ level: "error",
518
+ message: "The legacy SceneFile envelope is unsupported. Export it once with the explicit migration tool before opening."
519
+ }]
520
+ };
521
+ if (o.schemaVersion !== b)
522
+ return {
523
+ document: null,
524
+ contentHash: null,
525
+ migratedFrom: null,
526
+ diagnostics: [{
527
+ code: w.unsupportedVersion,
528
+ level: "error",
529
+ message: `Scene schema version ${String(o.schemaVersion)} is unsupported; expected ${b}.`
530
+ }]
531
+ };
532
+ const n = M(o, t);
533
+ if (!n.ok)
534
+ return {
535
+ document: null,
536
+ contentHash: null,
537
+ migratedFrom: null,
538
+ diagnostics: [
539
+ {
540
+ code: w.invalidDocument,
541
+ level: "error",
542
+ message: `Scene document does not satisfy schema version ${b}.`
543
+ },
544
+ ...n.diagnostics
545
+ ]
546
+ };
547
+ const r = P(
548
+ o,
549
+ t
550
+ );
551
+ return {
552
+ document: r,
553
+ contentHash: z(r, t),
554
+ migratedFrom: null,
555
+ diagnostics: n.diagnostics
556
+ };
557
+ }
558
+ const je = K;
559
+ function Q(e) {
560
+ const t = {
561
+ nodeId: e.nodeId,
562
+ label: e.label,
563
+ localTransform: {
564
+ position: e.localTransform.position,
565
+ rotation: e.localTransform.rotation,
566
+ scale: e.localTransform.scale
567
+ },
568
+ ...e.origin ? { origin: { local: e.origin.local } } : {}
569
+ };
570
+ return e.nodeType === "group" ? {
571
+ ...t,
572
+ nodeType: "group",
573
+ children: [...e.children].map(Q).sort((o, n) => o.nodeId.localeCompare(n.nodeId))
574
+ } : e.nodeType === "visual" ? {
575
+ ...t,
576
+ nodeType: "visual",
577
+ visualRevisionId: e.visualRevisionId,
578
+ visible: e.visible,
579
+ renderLayer: e.renderLayer,
580
+ selectionMode: e.selectionMode,
581
+ ...e.appearance ? {
582
+ appearance: {
583
+ ...e.appearance,
584
+ ...e.appearance.color ? { color: e.appearance.color } : {}
585
+ }
586
+ } : {},
587
+ ...e.semantic ? { semantic: y(e.semantic) } : {}
588
+ } : e.nodeType === "placeholder" ? {
589
+ ...t,
590
+ nodeType: "placeholder",
591
+ placeholderVersion: 1,
592
+ size: e.size,
593
+ role: e.role,
594
+ visible: e.visible,
595
+ ...e.assetRevisionId ? { assetRevisionId: e.assetRevisionId } : {},
596
+ ...e.externalRef ? { externalRef: { ...e.externalRef } } : {},
597
+ ...e.semantic ? { semantic: y(e.semantic) } : {}
598
+ } : e.nodeType === "domain" ? {
599
+ ...t,
600
+ nodeType: "domain",
601
+ domainId: e.domainId,
602
+ dataVersion: e.dataVersion,
603
+ payload: F(e.payload),
604
+ visible: e.visible,
605
+ selectable: e.selectable,
606
+ ...e.bounds ? { bounds: { min: e.bounds.min, max: e.bounds.max } } : {},
607
+ ...e.semantic ? { semantic: y(e.semantic) } : {}
608
+ } : {
609
+ ...t,
610
+ nodeType: "asset",
611
+ assetRevisionId: e.assetRevisionId,
612
+ role: e.role,
613
+ visible: e.visible,
614
+ variantSelections: A(e.variantSelections),
615
+ ...e.appearance ? { appearance: { ...e.appearance } } : {},
616
+ physics: be(e.physics),
617
+ ...e.initialPose ? { initialPose: { joints: A(e.initialPose.joints) } } : {},
618
+ ...e.semantic ? { semantic: y(e.semantic) } : {}
619
+ };
620
+ }
621
+ function fe(e) {
622
+ return Object.fromEntries(
623
+ Object.entries(e).sort(([t], [o]) => t.localeCompare(o)).map(([t, o]) => [
624
+ t,
625
+ {
626
+ dataVersion: o.dataVersion,
627
+ data: F(o.data)
628
+ }
629
+ ])
630
+ );
631
+ }
632
+ function Se(e) {
633
+ return {
634
+ ...e,
635
+ resources: [...e.resources].map((t) => ({
636
+ ...t,
637
+ locator: R(t.locator)
638
+ })).sort((t, o) => l(t.locator).localeCompare(l(o.locator)) || t.resourceId.localeCompare(o.resourceId)),
639
+ suggestedScale: e.suggestedScale,
640
+ ...e.bounds ? { bounds: { min: e.bounds.min, max: e.bounds.max } } : {},
641
+ ...e.metrics ? { metrics: { ...e.metrics } } : {},
642
+ provenance: { ...e.provenance }
643
+ };
644
+ }
645
+ function ge(e) {
646
+ return {
647
+ ...e,
648
+ resources: [...e.resources].map((t) => ({
649
+ ...t,
650
+ locator: R(t.locator)
651
+ })).sort((t, o) => l(t.locator).localeCompare(l(o.locator)) || t.resourceId.localeCompare(o.resourceId)),
652
+ variantSets: [...e.variantSets].map((t) => ({
653
+ ...t,
654
+ options: [...new Set(t.options)].sort()
655
+ })).sort((t, o) => t.name.localeCompare(o.name)),
656
+ ...e.hints ? {
657
+ hints: {
658
+ ...e.hints,
659
+ ...e.hints.tags ? { tags: [...new Set(e.hints.tags)].sort() } : {}
660
+ }
661
+ } : {},
662
+ ...e.semantic ? { semantic: y(e.semantic) } : {},
663
+ provenance: {
664
+ ...e.provenance,
665
+ ...e.provenance.externalRef ? { externalRef: { ...e.provenance.externalRef } } : {},
666
+ repairs: [...e.provenance.repairs].sort((t, o) => t.at.localeCompare(o.at) || t.kind.localeCompare(o.kind) || t.detail.localeCompare(o.detail))
667
+ }
668
+ };
669
+ }
670
+ function Ie(e) {
671
+ return {
672
+ rendering: {
673
+ ...e.rendering,
674
+ background: { ...e.rendering.background }
675
+ },
676
+ physics: {
677
+ ...e.physics,
678
+ gravity: e.physics.gravity,
679
+ solver: { ...e.physics.solver }
680
+ }
681
+ };
682
+ }
683
+ function y(e) {
684
+ return {
685
+ ...e,
686
+ ...e.labels ? { labels: E(e.labels) } : {},
687
+ ...e.taxonomy ? { taxonomy: E(e.taxonomy) } : {},
688
+ ...e.tags ? { tags: E(e.tags) } : {},
689
+ ...e.attributes ? { attributes: A(e.attributes) } : {}
690
+ };
691
+ }
692
+ function we(e) {
693
+ return {
694
+ ...y(e),
695
+ ...e.task ? {
696
+ task: {
697
+ ...e.task,
698
+ ...e.task.tags ? { tags: E(e.task.tags) } : {}
699
+ }
700
+ } : {},
701
+ ...e.annotations ? { annotations: [...e.annotations].map(ye).sort((t, o) => t.annotationId.localeCompare(o.annotationId)) } : {}
702
+ };
703
+ }
704
+ function ye(e) {
705
+ return {
706
+ ...e,
707
+ targetNodeIds: E(e.targetNodeIds),
708
+ ...e.attributes ? { attributes: A(e.attributes) } : {}
709
+ };
710
+ }
711
+ function be(e) {
712
+ return {
713
+ ...e,
714
+ ...e.colliderPrimPaths ? { colliderPrimPaths: E(e.colliderPrimPaths) } : {},
715
+ ...e.physicsMaterial ? { physicsMaterial: { ...e.physicsMaterial } } : {},
716
+ ...e.jointOverrides ? {
717
+ jointOverrides: [...e.jointOverrides].map((t) => ({ ...t })).sort((t, o) => t.jointPrimPath.localeCompare(o.jointPrimPath))
718
+ } : {}
719
+ };
720
+ }
721
+ function E(e) {
722
+ return [...new Set(e)].sort();
723
+ }
724
+ function A(e) {
725
+ return Object.fromEntries(Object.entries(e).sort(([t], [o]) => t.localeCompare(o)));
726
+ }
727
+ function Ee(e) {
728
+ return typeof e == "object" && e !== null && !Array.isArray(e);
729
+ }
730
+ const ve = Object.freeze({ hidden: !1, locked: !1 });
731
+ function Ve(e) {
732
+ const o = ke(e.document).flatMap((i) => {
733
+ const a = e.editorial[i] ?? ve;
734
+ return a.hidden || a.locked ? [{ nodeId: i, hidden: a.hidden, locked: a.locked }] : [];
735
+ }), n = [...new Set(e.selection.instanceIds)], r = e.selection.primaryId, s = {
736
+ format: "sim-studio.editorial-state@1",
737
+ schemaVersion: 1,
738
+ selection: { nodeIds: n, primaryNodeId: r },
739
+ nodeStates: o,
740
+ camera: e.camera ? U(e.camera) : null
741
+ };
742
+ return X(s, e.document), s;
743
+ }
744
+ function X(e, t) {
745
+ if (e.format !== "sim-studio.editorial-state@1" || e.schemaVersion !== 1)
746
+ throw new Error("Unsupported editorial state format.");
747
+ const o = new Set(j(t.root).map((s) => s.nodeId)), n = /* @__PURE__ */ new Set();
748
+ for (const s of e.nodeStates) {
749
+ if (N(s.nodeId, o), n.has(s.nodeId))
750
+ throw new Error(`Editorial state repeats node ${s.nodeId}.`);
751
+ n.add(s.nodeId);
752
+ }
753
+ const r = /* @__PURE__ */ new Set();
754
+ for (const s of e.selection.nodeIds) {
755
+ if (N(s, o), r.has(s))
756
+ throw new Error(`Editorial selection repeats node ${s}.`);
757
+ r.add(s);
758
+ }
759
+ if (e.selection.primaryNodeId !== null && !r.has(e.selection.primaryNodeId))
760
+ throw new Error(`Editorial primary selection is not in the selection: ${e.selection.primaryNodeId}`);
761
+ e.camera && U(e.camera);
762
+ }
763
+ function He(e) {
764
+ return Object.freeze(Object.fromEntries(
765
+ e.nodeStates.map((t) => [
766
+ t.nodeId,
767
+ Object.freeze({ hidden: t.hidden, locked: t.locked })
768
+ ])
769
+ ));
770
+ }
771
+ function qe(e) {
772
+ return U(e);
773
+ }
774
+ function U(e) {
775
+ if (e.schemaVersion !== 1 || e.viewMode !== "2d" && e.viewMode !== "3d")
776
+ throw new Error("Editorial camera schema or view mode is invalid.");
777
+ if (e.viewMode === "2d" && !e.orthographic)
778
+ throw new Error("A 2D editorial camera requires orthographic facts.");
779
+ if (e.viewMode === "3d" && !e.orbit)
780
+ throw new Error("A 3D editorial camera requires orbit facts.");
781
+ for (const t of Re(e))
782
+ if (!Number.isFinite(t)) throw new Error("Editorial camera contains a non-finite value.");
783
+ return {
784
+ schemaVersion: 1,
785
+ viewMode: e.viewMode,
786
+ ...e.orbit ? { orbit: { ...e.orbit } } : {},
787
+ ...e.orthographic ? { orthographic: { ...e.orthographic } } : {}
788
+ };
789
+ }
790
+ function Re(e) {
791
+ return [
792
+ ...e.orbit ? Object.values(e.orbit) : [],
793
+ ...e.orthographic ? Object.values(e.orthographic) : []
794
+ ];
795
+ }
796
+ function ke(e) {
797
+ return j(e.root).filter((t) => t.nodeId !== e.root.nodeId).map((t) => t.nodeId).sort((t, o) => t.localeCompare(o));
798
+ }
799
+ function N(e, t) {
800
+ if (!t.has(e)) throw new Error(`Editorial state references unknown node ${e}.`);
801
+ }
802
+ function Be(e, t) {
803
+ return e.nodeStates.find((o) => o.nodeId === t) ?? { nodeId: t, hidden: !1, locked: !1 };
804
+ }
805
+ const f = {
806
+ invalidSnapshot: "STUDIO_SESSION_INVALID_SNAPSHOT",
807
+ documentHashMismatch: "STUDIO_SESSION_DOCUMENT_HASH_MISMATCH",
808
+ unsupportedFormat: "STUDIO_SESSION_UNSUPPORTED_FORMAT"
809
+ };
810
+ class S extends Error {
811
+ constructor(o, n) {
812
+ super(n);
813
+ x(this, "code");
814
+ this.name = "StudioSessionSnapshotError", this.code = o;
815
+ }
816
+ }
817
+ function Te(e) {
818
+ if (!e || e.format !== "sim-studio.session@1" || e.schemaVersion !== 1)
819
+ throw new S(
820
+ f.unsupportedFormat,
821
+ "Unsupported Sim Studio session snapshot format."
822
+ );
823
+ if (typeof e.documentText != "string" || !e.documentText || typeof e.documentHash != "string" || !e.documentHash)
824
+ throw new S(
825
+ f.invalidSnapshot,
826
+ "The Sim Studio session snapshot is missing its canonical document."
827
+ );
828
+ const t = K(e.documentText);
829
+ if (!t.document)
830
+ throw new S(
831
+ f.invalidSnapshot,
832
+ t.diagnostics.map((o) => o.message).join(`
833
+ `)
834
+ );
835
+ if (t.contentHash !== e.documentHash)
836
+ throw new S(
837
+ f.documentHashMismatch,
838
+ "The Sim Studio session document hash does not match its canonical text."
839
+ );
840
+ if (X(e.editorial, t.document), e.assetClosure && (D(e.assetClosure.catalogDigest, "asset catalog"), D(e.assetClosure.manifestDigest, "resource manifest"), !e.assetClosure.closureId.trim()))
841
+ throw new S(
842
+ f.invalidSnapshot,
843
+ "The Sim Studio session asset closure id is empty."
844
+ );
845
+ }
846
+ function We(e) {
847
+ return Te(e), g(v(e));
848
+ }
849
+ function Je(e) {
850
+ const t = {
851
+ closureId: e.closureId,
852
+ catalogDigest: g(v(e.assetCatalog)),
853
+ manifestDigest: g(v(e.resourceManifest))
854
+ };
855
+ if (!t.closureId.trim())
856
+ throw new S(
857
+ f.invalidSnapshot,
858
+ "The Sim Studio session asset closure id is empty."
859
+ );
860
+ return t;
861
+ }
862
+ function D(e, t) {
863
+ if (!/^[a-f0-9]{64}$/.test(e))
864
+ throw new S(
865
+ f.invalidSnapshot,
866
+ `The Sim Studio session ${t} digest must be SHA-256.`
867
+ );
868
+ }
869
+ export {
870
+ _e as A,
871
+ K as B,
872
+ ce as C,
873
+ ue as D,
874
+ je as E,
875
+ Le as F,
876
+ he as G,
877
+ Ne as H,
878
+ de as I,
879
+ $ as J,
880
+ We as K,
881
+ $e as L,
882
+ Fe as M,
883
+ me as N,
884
+ Pe as O,
885
+ ie as P,
886
+ _ as Q,
887
+ W as R,
888
+ De as S,
889
+ l as a,
890
+ Ue as b,
891
+ X as c,
892
+ O as d,
893
+ Me as e,
894
+ w as f,
895
+ h as g,
896
+ f as h,
897
+ S as i,
898
+ pe as j,
899
+ Te as k,
900
+ z as l,
901
+ ze as m,
902
+ R as n,
903
+ J as o,
904
+ xe as p,
905
+ Ve as q,
906
+ H as r,
907
+ Je as s,
908
+ Be as t,
909
+ He as u,
910
+ qe as v,
911
+ I as w,
912
+ q as x,
913
+ P as y,
914
+ B as z
915
+ };