@nebula-spatial/studio 0.1.1 → 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 (42) hide show
  1. package/README.md +2 -0
  2. package/dist/{builders-BAXRR5o5.js → builders-lydx4-Rh.js} +1 -1
  3. package/dist/core/session-persistence-controller.d.ts +55 -0
  4. package/dist/doc/placement-policy.d.ts +4 -0
  5. package/dist/editor/editor.d.ts +3 -1
  6. package/dist/editor/index.d.ts +2 -0
  7. package/dist/editor/session-persistence.d.ts +54 -0
  8. package/dist/editor.js +727 -490
  9. package/dist/{export-evidence-DMNRhgL9.js → export-evidence-z2Ne7Trf.js} +654 -972
  10. package/dist/generalization.js +2 -2
  11. package/dist/index.d.ts +4 -2
  12. package/dist/index.js +226 -219
  13. package/dist/{mjcf-visual-Bt4bUxd1.js → mjcf-visual-IOy-ucto.js} +1 -1
  14. package/dist/persist/indexeddb-store.d.ts +22 -2
  15. package/dist/persist/session.d.ts +22 -0
  16. package/dist/persist/snapshot.d.ts +24 -0
  17. package/dist/{physics-facts-tfQYyNTD.js → physics-facts-D-URIBrt.js} +8 -7
  18. package/dist/{placement-policy-DY_FNRDu.js → placement-policy-C6dV6Tf-.js} +161 -141
  19. package/dist/ports/persistence.d.ts +45 -1
  20. package/dist/project/contracts.d.ts +3 -0
  21. package/dist/remote-asset-resolver-D-UeyDMD.js +311 -0
  22. package/dist/{scene-graph-DBLKAhxa.js → scene-graph-DVOXjMmp.js} +2 -2
  23. package/dist/{scene-session-Cy6vDJ1l.js → scene-session-PhoFXFCY.js} +3365 -3340
  24. package/dist/scene.js +2 -2
  25. package/dist/{session-BRBrCLdd.js → session-2bp8YOA4.js} +2 -2
  26. package/dist/{session-q3uuG7OP.js → session-B3WbC7Y2.js} +1 -1
  27. package/dist/session-B9kEf4xN.js +915 -0
  28. package/dist/{session-DI5tPJxn.js → session-DYThdzLZ.js} +4 -4
  29. package/dist/studio/index.d.ts +5 -0
  30. package/dist/studio/indexeddb-persistence.d.ts +2 -0
  31. package/dist/studio/indexeddb-session-persistence.d.ts +11 -0
  32. package/dist/studio/scene-package-asset-sources.d.ts +14 -0
  33. package/dist/studio.js +1422 -1220
  34. package/dist/{urdf-session-CQir2nb2.js → urdf-session-CRXL4bHf.js} +3 -3
  35. package/dist/{usd-session-DZJnEEOs.js → usd-session-CTzInpNy.js} +2 -2
  36. package/dist/version.d.ts +1 -1
  37. package/dist/view/scene-session.d.ts +5 -1
  38. package/dist/{xacro-DLRXyk60.js → xacro-IpPHTMYs.js} +1 -1
  39. package/package.json +1 -1
  40. package/dist/asset-source-BExlEcRt.js +0 -444
  41. package/dist/editorial-BkAFWfbg.js +0 -83
  42. package/dist/remote-asset-resolver-Cb8cfNmw.js +0 -136
@@ -0,0 +1,311 @@
1
+ var T = Object.defineProperty;
2
+ var R = (s, e, t) => e in s ? T(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var n = (s, e, t) => R(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import { K as w, x as A, o as g, a as l, d as m, r as b, Q as M, R as _ } from "./session-B9kEf4xN.js";
5
+ import { a as D, s as U, k as C } from "./builders-lydx4-Rh.js";
6
+ const v = /* @__PURE__ */ new WeakMap();
7
+ let I = 0;
8
+ function B(s, e) {
9
+ const t = Symbol(`studio-write-policy-${I++}`), r = v.get(s) ?? /* @__PURE__ */ new Map();
10
+ return r.set(t, { policy: e }), v.set(s, r), () => {
11
+ const i = v.get(s);
12
+ i && (i.delete(t), i.size === 0 && v.delete(s));
13
+ };
14
+ }
15
+ function $(s, e) {
16
+ const t = v.get(s);
17
+ if (!t) return { allowed: !0 };
18
+ for (const { policy: r } of t.values()) {
19
+ const i = r.check(e);
20
+ if (!i.allowed) return i;
21
+ }
22
+ return { allowed: !0 };
23
+ }
24
+ class z {
25
+ constructor(e) {
26
+ n(this, "state", {
27
+ available: !0,
28
+ dirty: !0,
29
+ saving: !1,
30
+ lastSavedRevision: null,
31
+ lastSavedEtag: null,
32
+ lastSavedAt: null,
33
+ conflict: null,
34
+ error: null
35
+ });
36
+ n(this, "running", null);
37
+ n(this, "requestedMode", null);
38
+ n(this, "activeSaveController", null);
39
+ n(this, "autosaveTimer", null);
40
+ n(this, "disposed", !1);
41
+ this.options = e;
42
+ }
43
+ getState() {
44
+ return this.state;
45
+ }
46
+ markDirty() {
47
+ this.disposed || this.state.dirty || this.setState({
48
+ ...this.state,
49
+ dirty: !0,
50
+ conflict: null,
51
+ error: null
52
+ });
53
+ }
54
+ scheduleAutosave() {
55
+ this.disposed || (this.markDirty(), this.autosaveTimer && clearTimeout(this.autosaveTimer), this.autosaveTimer = setTimeout(() => {
56
+ this.autosaveTimer = null, this.save("autosave").catch(() => {
57
+ });
58
+ }, this.options.autosaveDelayMs ?? 750));
59
+ }
60
+ restoreBaseline(e) {
61
+ this.disposed || (this.clearAutosaveTimer(), this.setState({
62
+ ...this.state,
63
+ dirty: e === null,
64
+ saving: !1,
65
+ lastSavedRevision: (e == null ? void 0 : e.revision) ?? null,
66
+ lastSavedEtag: (e == null ? void 0 : e.etag) ?? null,
67
+ lastSavedAt: (e == null ? void 0 : e.savedAt) ?? null,
68
+ conflict: null,
69
+ error: null
70
+ }));
71
+ }
72
+ clearConflict() {
73
+ this.state.conflict && this.setState({ ...this.state, conflict: null });
74
+ }
75
+ clearError() {
76
+ this.state.error && this.setState({ ...this.state, error: null });
77
+ }
78
+ save(e = "autosave") {
79
+ return this.disposed ? Promise.reject(new Error("Studio session persistence controller is disposed.")) : (this.clearAutosaveTimer(), this.requestedMode = O(this.requestedMode, e), this.running || (this.running = this.drain().finally(() => {
80
+ this.running = null;
81
+ })), this.running);
82
+ }
83
+ flush(e = "checkpoint") {
84
+ return this.save(e);
85
+ }
86
+ retry(e = "checkpoint") {
87
+ return this.clearError(), this.save(e);
88
+ }
89
+ cancel() {
90
+ var e;
91
+ this.clearAutosaveTimer(), this.requestedMode = null, (e = this.activeSaveController) == null || e.abort(
92
+ new DOMException("Studio session save was cancelled.", "AbortError")
93
+ );
94
+ }
95
+ async dispose(e = !0) {
96
+ var t, r;
97
+ if (!this.disposed) {
98
+ this.disposed = !0, this.cancel();
99
+ try {
100
+ this.running && await this.running.catch(() => {
101
+ });
102
+ } finally {
103
+ e && await ((r = (t = this.options.adapter).close) == null ? void 0 : r.call(t));
104
+ }
105
+ }
106
+ }
107
+ async drain() {
108
+ let e = null;
109
+ for (; this.requestedMode !== null; ) {
110
+ const t = this.requestedMode;
111
+ if (this.requestedMode = null, e = await this.performSave(t), e.status === "conflict") {
112
+ this.requestedMode = null;
113
+ break;
114
+ }
115
+ }
116
+ if (!e) throw new Error("No Sim Studio session save was requested.");
117
+ return e;
118
+ }
119
+ async performSave(e) {
120
+ var h, d, S, a;
121
+ if (e === "autosave" && !this.state.dirty && this.state.lastSavedRevision !== null)
122
+ return {
123
+ status: "saved",
124
+ revision: this.state.lastSavedRevision,
125
+ etag: this.state.lastSavedEtag ?? this.state.lastSavedRevision,
126
+ savedAt: this.state.lastSavedAt ?? ((d = (h = this.options).now) == null ? void 0 : d.call(h)) ?? (/* @__PURE__ */ new Date()).toISOString(),
127
+ snapshotDigest: this.options.currentSignature()
128
+ };
129
+ const t = this.options.capture(), r = w(t);
130
+ this.setState({
131
+ ...this.state,
132
+ dirty: !0,
133
+ saving: !0,
134
+ conflict: null,
135
+ error: null
136
+ });
137
+ const i = new AbortController();
138
+ this.activeSaveController = i;
139
+ try {
140
+ const o = await this.options.adapter.save(t, {
141
+ mode: e,
142
+ expectedRevision: this.state.lastSavedRevision,
143
+ expectedEtag: this.state.lastSavedEtag,
144
+ idempotencyKey: ((a = (S = this.options).createId) == null ? void 0 : a.call(S)) ?? D(),
145
+ signal: i.signal
146
+ });
147
+ if (o.status === "conflict")
148
+ return this.setState({
149
+ ...this.state,
150
+ dirty: !0,
151
+ saving: !1,
152
+ conflict: o.conflict,
153
+ error: null
154
+ }), o;
155
+ const c = this.options.currentSignature() !== r;
156
+ return this.setState({
157
+ ...this.state,
158
+ dirty: c,
159
+ saving: !1,
160
+ lastSavedRevision: o.revision,
161
+ lastSavedEtag: o.etag,
162
+ lastSavedAt: o.savedAt,
163
+ conflict: null,
164
+ error: null
165
+ }), o;
166
+ } catch (o) {
167
+ const c = i.signal.aborted;
168
+ throw this.setState({
169
+ ...this.state,
170
+ dirty: !0,
171
+ saving: !1,
172
+ conflict: null,
173
+ error: {
174
+ code: c ? "STUDIO_SESSION_SAVE_CANCELLED" : "STUDIO_SESSION_SAVE_FAILED",
175
+ message: o instanceof Error ? o.message : String(o)
176
+ }
177
+ }), o;
178
+ } finally {
179
+ this.activeSaveController === i && (this.activeSaveController = null);
180
+ }
181
+ }
182
+ clearAutosaveTimer() {
183
+ this.autosaveTimer && (clearTimeout(this.autosaveTimer), this.autosaveTimer = null);
184
+ }
185
+ setState(e) {
186
+ var t, r;
187
+ this.state = Object.freeze(e), (r = (t = this.options).onState) == null || r.call(t, this.state);
188
+ }
189
+ }
190
+ function O(s, e) {
191
+ const t = {
192
+ autosave: 0,
193
+ checkpoint: 1,
194
+ publish: 2
195
+ };
196
+ return s === null || t[e] > t[s] ? e : s;
197
+ }
198
+ const f = {
199
+ scopeDenied: "ASSET_REMOTE_SCOPE_DENIED",
200
+ redirectDenied: "ASSET_REMOTE_REDIRECT_DENIED",
201
+ requestFailed: "ASSET_REMOTE_REQUEST_FAILED",
202
+ responseUrlMismatch: "ASSET_REMOTE_RESPONSE_URL_MISMATCH"
203
+ };
204
+ class N {
205
+ constructor(e, t) {
206
+ n(this, "source");
207
+ n(this, "entryUrl");
208
+ n(this, "blobs", /* @__PURE__ */ new Map());
209
+ n(this, "factsByKey", /* @__PURE__ */ new Map());
210
+ this.revision = t, this.source = A(e), this.entryUrl = new URL(this.source.entryUrl);
211
+ }
212
+ get entryLocator() {
213
+ return { kind: "remote-url", url: g(this.source) };
214
+ }
215
+ async entryBlob(e) {
216
+ return this.fetch(this.entryUrl, e);
217
+ }
218
+ async resolve(e, t = {}) {
219
+ const r = t.url ? new URL(t.url) : this.entryUrl, i = new URL(e, r);
220
+ return this.fetch(i, t.signal);
221
+ }
222
+ facts() {
223
+ return [...this.factsByKey.values()].sort((e, t) => l(e.locator).localeCompare(l(t.locator)));
224
+ }
225
+ blob(e) {
226
+ return this.blobs.get(l(e)) ?? null;
227
+ }
228
+ async fetch(e, t) {
229
+ t == null || t.throwIfAborted();
230
+ const r = m(e.href), i = { kind: "remote-url", url: r }, h = l(i);
231
+ this.assertScope(e);
232
+ const d = this.blobs.get(h);
233
+ if (d) return d;
234
+ const S = {
235
+ signal: t,
236
+ redirect: "error"
237
+ }, a = await (this.source.request ? this.source.request(e.href, S) : fetch(e.href, S));
238
+ if (t == null || t.throwIfAborted(), a.redirected)
239
+ throw u(
240
+ f.redirectDenied,
241
+ `Remote USD resource redirects are not allowed: ${e.href}.`
242
+ );
243
+ if (!a.ok)
244
+ throw u(
245
+ f.requestFailed,
246
+ `Remote USD resource request failed (${a.status}): ${e.href}.`
247
+ );
248
+ if (a.url) {
249
+ const E = new URL(a.url);
250
+ if (this.assertScope(E), m(E.href) !== r)
251
+ throw u(
252
+ f.responseUrlMismatch,
253
+ `Remote USD response URL does not match the requested canonical resource: ${a.url}.`
254
+ );
255
+ }
256
+ const o = await a.blob(), c = new Uint8Array(await o.arrayBuffer()), p = {
257
+ locator: i,
258
+ sha256: U(c),
259
+ byteSize: c.byteLength,
260
+ mediaType: b(
261
+ e.pathname,
262
+ o.type,
263
+ a.headers.get("content-type") ?? void 0
264
+ ) ?? M
265
+ };
266
+ this.assertRevisionFact(p);
267
+ const y = o.type ? o : new Blob([c], { type: p.mediaType });
268
+ return this.blobs.set(h, y), this.factsByKey.set(h, p), y;
269
+ }
270
+ assertScope(e) {
271
+ if (!_(this.source, e))
272
+ throw u(
273
+ f.scopeDenied,
274
+ `Remote USD resource is outside the allowed scopes: ${e.href}.`
275
+ );
276
+ }
277
+ assertRevisionFact(e) {
278
+ const t = this.factsByKey.get(l(e.locator));
279
+ if (t && (t.sha256 !== e.sha256 || t.byteSize !== e.byteSize))
280
+ throw u(
281
+ "ASSET_SOURCE_FACTS_MISMATCH",
282
+ `Remote resource bytes changed within one load: ${e.locator.kind === "remote-url" ? e.locator.url : e.locator.path}.`
283
+ );
284
+ if (!this.revision) return;
285
+ const r = this.revision.resources.find((i) => l(i.locator) === l(e.locator));
286
+ if (!r) {
287
+ const i = "visualRevisionId" in this.revision ? this.revision.visualRevisionId : this.revision.revisionId;
288
+ throw u(
289
+ "ASSET_SOURCE_FACTS_MISMATCH",
290
+ `Remote resource is not declared by revision ${i}.`
291
+ );
292
+ }
293
+ q(e, r);
294
+ }
295
+ }
296
+ function q(s, e) {
297
+ if (s.sha256 !== e.sha256 || s.byteSize !== e.byteSize || s.mediaType !== e.mediaType)
298
+ throw u(
299
+ "ASSET_SOURCE_FACTS_MISMATCH",
300
+ `Remote resource facts do not match revision resource ${l(e.locator)}.`
301
+ );
302
+ }
303
+ function u(s, e) {
304
+ return new C(s, e);
305
+ }
306
+ export {
307
+ N as S,
308
+ z as a,
309
+ $ as e,
310
+ B as i
311
+ };
@@ -615,7 +615,7 @@ function Ce(e, n, t) {
615
615
  ));
616
616
  }
617
617
  export {
618
- V as $,
618
+ N as $,
619
619
  ae as A,
620
620
  E as B,
621
621
  Ee as C,
@@ -642,7 +642,7 @@ export {
642
642
  ve as X,
643
643
  ee as Y,
644
644
  _e as Z,
645
- N as _,
645
+ V as _,
646
646
  w as a,
647
647
  O as a0,
648
648
  Te as a1,