@lumencast/runtime 0.8.0 → 0.10.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 (99) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/animate/keyframes.js +8 -1
  3. package/dist/animate/keyframes.js.map +1 -1
  4. package/dist/app.d.ts +9 -1
  5. package/dist/app.d.ts.map +1 -1
  6. package/dist/app.js +4 -1
  7. package/dist/app.js.map +1 -1
  8. package/dist/{broadcast-Gcd-dmC7.js → broadcast-L5wm2I6J.js} +3 -3
  9. package/dist/{broadcast-Gcd-dmC7.js.map → broadcast-L5wm2I6J.js.map} +1 -1
  10. package/dist/{control-C5TfClga.js → control-eEUG7unp.js} +4 -4
  11. package/dist/{control-C5TfClga.js.map → control-eEUG7unp.js.map} +1 -1
  12. package/dist/index-Clrya_9l.js +1281 -0
  13. package/dist/index-Clrya_9l.js.map +1 -0
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.html +1 -1
  17. package/dist/index.js +11 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/lumencast.js +17 -12
  20. package/dist/mount.d.ts.map +1 -1
  21. package/dist/mount.js +16 -0
  22. package/dist/mount.js.map +1 -1
  23. package/dist/overlay/runtime-context.d.ts +21 -0
  24. package/dist/overlay/runtime-context.d.ts.map +1 -1
  25. package/dist/overlay/runtime-context.js +8 -0
  26. package/dist/overlay/runtime-context.js.map +1 -1
  27. package/dist/render/bundle.d.ts +1 -1
  28. package/dist/render/bundle.d.ts.map +1 -1
  29. package/dist/render/bundle.js +4 -0
  30. package/dist/render/bundle.js.map +1 -1
  31. package/dist/render/keyframe-player.d.ts.map +1 -1
  32. package/dist/render/keyframe-player.js +15 -1
  33. package/dist/render/keyframe-player.js.map +1 -1
  34. package/dist/render/primitives/capture.d.ts +49 -0
  35. package/dist/render/primitives/capture.d.ts.map +1 -0
  36. package/dist/render/primitives/capture.js +203 -0
  37. package/dist/render/primitives/capture.js.map +1 -0
  38. package/dist/render/primitives/index.d.ts.map +1 -1
  39. package/dist/render/primitives/index.js +7 -0
  40. package/dist/render/primitives/index.js.map +1 -1
  41. package/dist/render/primitives/live-peer-video.d.ts +27 -0
  42. package/dist/render/primitives/live-peer-video.d.ts.map +1 -0
  43. package/dist/render/primitives/live-peer-video.js +64 -0
  44. package/dist/render/primitives/live-peer-video.js.map +1 -0
  45. package/dist/render/primitives/media.d.ts +37 -12
  46. package/dist/render/primitives/media.d.ts.map +1 -1
  47. package/dist/render/primitives/media.js +43 -17
  48. package/dist/render/primitives/media.js.map +1 -1
  49. package/dist/render/primitives/meet-peer.d.ts +31 -0
  50. package/dist/render/primitives/meet-peer.d.ts.map +1 -0
  51. package/dist/render/primitives/meet-peer.js +46 -0
  52. package/dist/render/primitives/meet-peer.js.map +1 -0
  53. package/dist/render/prop-allowlist.d.ts.map +1 -1
  54. package/dist/render/prop-allowlist.js +32 -1
  55. package/dist/render/prop-allowlist.js.map +1 -1
  56. package/dist/render/tree.js +42 -8
  57. package/dist/render/tree.js.map +1 -1
  58. package/dist/{status-pill-BaLQoIDl.js → status-pill-elORkMrh.js} +2 -2
  59. package/dist/{status-pill-BaLQoIDl.js.map → status-pill-elORkMrh.js.map} +1 -1
  60. package/dist/{test-CA30C2By.js → test-7q_KJkdX.js} +4 -4
  61. package/dist/{test-CA30C2By.js.map → test-7q_KJkdX.js.map} +1 -1
  62. package/dist/{tree-1coZ32nd.js → tree-BMxx5170.js} +773 -604
  63. package/dist/tree-BMxx5170.js.map +1 -0
  64. package/dist/types.d.ts +23 -0
  65. package/dist/types.d.ts.map +1 -1
  66. package/dist/webrtc/index.d.ts +76 -0
  67. package/dist/webrtc/index.d.ts.map +1 -0
  68. package/dist/webrtc/index.js +180 -0
  69. package/dist/webrtc/index.js.map +1 -0
  70. package/dist/webrtc/meet-viewer.d.ts +139 -0
  71. package/dist/webrtc/meet-viewer.d.ts.map +1 -0
  72. package/dist/webrtc/meet-viewer.js +379 -0
  73. package/dist/webrtc/meet-viewer.js.map +1 -0
  74. package/dist/webrtc/peer-stream-registry.d.ts +21 -0
  75. package/dist/webrtc/peer-stream-registry.d.ts.map +1 -0
  76. package/dist/webrtc/peer-stream-registry.js +77 -0
  77. package/dist/webrtc/peer-stream-registry.js.map +1 -0
  78. package/package.json +4 -4
  79. package/src/animate/keyframes.ts +8 -1
  80. package/src/app.tsx +14 -0
  81. package/src/index.ts +40 -0
  82. package/src/mount.ts +16 -0
  83. package/src/overlay/runtime-context.tsx +24 -0
  84. package/src/render/bundle.ts +19 -1
  85. package/src/render/keyframe-player.tsx +14 -1
  86. package/src/render/primitives/capture.tsx +255 -0
  87. package/src/render/primitives/index.ts +7 -0
  88. package/src/render/primitives/live-peer-video.tsx +90 -0
  89. package/src/render/primitives/media.tsx +66 -17
  90. package/src/render/primitives/meet-peer.tsx +57 -0
  91. package/src/render/prop-allowlist.ts +32 -1
  92. package/src/render/tree.tsx +44 -8
  93. package/src/types.ts +23 -0
  94. package/src/webrtc/index.ts +252 -0
  95. package/src/webrtc/meet-viewer.ts +497 -0
  96. package/src/webrtc/peer-stream-registry.ts +93 -0
  97. package/dist/index-N-VqrIxN.js +0 -885
  98. package/dist/index-N-VqrIxN.js.map +0 -1
  99. package/dist/tree-1coZ32nd.js.map +0 -1
@@ -1,885 +0,0 @@
1
- import { batch as w, signal as p } from "@preact/signals-react";
2
- import { createRoot as $ } from "react-dom/client";
3
- import { createContext as Y, useContext as K, lazy as S, Suspense as Z, createElement as J, StrictMode as Q } from "react";
4
- import { jsx as l } from "react/jsx-runtime";
5
- import { useSignals as V } from "@preact/signals-react/runtime";
6
- import { AnimatePresence as ee, motion as te } from "framer-motion";
7
- import { SequenceTracker as se, encodeFrame as R, input as ne, WS_SUBPROTOCOLS as re, WS_SUBPROTOCOL_V1_1 as ie, subscribe as oe, decodeServerFrame as ce, LumencastError as O } from "@lumencast/protocol";
8
- const D = Y(null);
9
- function F({
10
- value: t,
11
- children: e
12
- }) {
13
- return /* @__PURE__ */ l(D.Provider, { value: t, children: e });
14
- }
15
- function Ve() {
16
- const t = K(D);
17
- if (!t)
18
- throw new Error(
19
- "Lumencast overlay components must be rendered inside LumencastRuntimeProvider"
20
- );
21
- return t;
22
- }
23
- const ae = S(
24
- () => import("./broadcast-Gcd-dmC7.js").then((t) => ({ default: t.BroadcastMode }))
25
- ), ue = S(
26
- () => import("./control-C5TfClga.js").then((t) => ({ default: t.ControlMode }))
27
- ), le = S(() => import("./test-CA30C2By.js").then((t) => ({ default: t.TestMode })));
28
- function he({
29
- mode: t,
30
- store: e,
31
- bundleSignal: s,
32
- statusSignal: n,
33
- crossfadeKeySignal: r,
34
- sendInput: i
35
- }) {
36
- V();
37
- const c = s.value, a = n.value, f = r.value;
38
- if (!c) return null;
39
- const u = t === "broadcast" ? ae : t === "control" ? ue : le;
40
- return /* @__PURE__ */ l(ee, { mode: "sync", children: /* @__PURE__ */ l(
41
- te.div,
42
- {
43
- initial: { opacity: 0 },
44
- animate: { opacity: 1 },
45
- exit: { opacity: 0 },
46
- transition: { duration: 0.4, ease: "easeInOut" },
47
- style: { position: "absolute", inset: 0 },
48
- children: /* @__PURE__ */ l(
49
- F,
50
- {
51
- value: {
52
- mode: t,
53
- store: e,
54
- bundle: c,
55
- status: a,
56
- sendInput: i
57
- },
58
- children: /* @__PURE__ */ l(Z, { fallback: null, children: /* @__PURE__ */ l(u, {}) })
59
- }
60
- )
61
- },
62
- f
63
- ) });
64
- }
65
- const fe = "<anon>", v = /* @__PURE__ */ new Set();
66
- function C(t) {
67
- return v.add(t), () => {
68
- v.delete(t);
69
- };
70
- }
71
- function q(t, e, s) {
72
- const n = { nodeId: t ?? fe, field: e, reason: s };
73
- if (v.size > 0) {
74
- for (const r of v)
75
- try {
76
- r(n);
77
- } catch {
78
- }
79
- return;
80
- }
81
- }
82
- const de = 100, me = 4, pe = 64, ge = {
83
- blur: de,
84
- brightness: me
85
- };
86
- function L(t, e) {
87
- if (typeof e != "number" || !Number.isFinite(e) || e < 0 || Object.is(e, -0)) return null;
88
- const s = ge[t];
89
- return e > s ? s : e;
90
- }
91
- const ve = /^blur\((\d{1,7}(?:\.\d{1,4})?)px\) brightness\((\d{1,7}(?:\.\d{1,4})?)\)$/, et = "blur(0px) brightness(1)";
92
- function be(t) {
93
- if (typeof t != "string" || t.length === 0 || t.length > pe) return null;
94
- const e = ve.exec(t);
95
- if (!e) return null;
96
- const s = L("blur", Number(e[1])), n = L("brightness", Number(e[2]));
97
- return s === null || n === null ? null : `blur(${s}px) brightness(${n})`;
98
- }
99
- function ye(t, e) {
100
- q(
101
- e,
102
- t,
103
- "rejected unsafe filter value : outside the R8 caps or not a finite number >= 0"
104
- );
105
- }
106
- const ke = { duration: 0 }, we = {
107
- linear: "linear",
108
- "cubic-in": "easeIn",
109
- "cubic-out": "easeOut",
110
- "cubic-in-out": "easeInOut"
111
- };
112
- function tt(t) {
113
- return !t || t.kind === "none" ? ke : t.kind === "tween" ? {
114
- type: "tween",
115
- duration: (t.duration_ms ?? 0) / 1e3,
116
- ease: t.ease ? we[t.ease] ?? "easeOut" : "easeOut"
117
- } : t.kind === "spring" ? {
118
- type: "spring",
119
- ...t.stiffness !== void 0 ? { stiffness: t.stiffness } : {},
120
- ...t.damping !== void 0 ? { damping: t.damping } : {},
121
- ...t.mass !== void 0 ? { mass: t.mass } : {}
122
- } : {
123
- type: "tween",
124
- duration: (t.duration_ms ?? 400) / 1e3,
125
- ease: "easeInOut"
126
- };
127
- }
128
- const Se = {
129
- opacity: 1,
130
- scale: 1,
131
- scaleX: 1,
132
- scaleY: 1,
133
- rotate: 0,
134
- x: 0,
135
- y: 0,
136
- // LSML §6.1 filter identity — both functions are always present so
137
- // framer interpolates between structurally-identical filter lists
138
- // (the compiler emits the same two-function form, clamped per R8).
139
- filter: "blur(0px) brightness(1)"
140
- }, Te = {
141
- kind: "tween",
142
- duration_ms: 400,
143
- ease: "cubic-out"
144
- };
145
- function st(t, e, s) {
146
- for (const n of e) {
147
- const r = t(n);
148
- if (r !== void 0) return r;
149
- }
150
- if (s && Object.keys(s).length > 0) {
151
- for (const n of Object.keys(s)) {
152
- const r = t(n);
153
- if (r !== void 0) return r;
154
- }
155
- return Te;
156
- }
157
- }
158
- function nt(t, e, s) {
159
- if (!e || Object.keys(e).length === 0)
160
- return { initial: t, animate: t };
161
- let n = e;
162
- if (e.filter !== void 0) {
163
- const i = be(e.filter);
164
- n = { ...e }, i === null ? (ye("animate_initial.filter", s), delete n.filter) : n.filter = i;
165
- }
166
- const r = { ...t };
167
- for (const i of Object.keys(n))
168
- i in r || (r[i] = Se[i] ?? 0);
169
- return { initial: n, animate: r };
170
- }
171
- function _e(t) {
172
- if (typeof t != "object" || t === null) return;
173
- const e = t, s = e.kind;
174
- if (s === "snap")
175
- return { kind: "none" };
176
- if (s === "tween") {
177
- const n = typeof e.duration_ms == "number" ? e.duration_ms : 0, r = Ee[e.easing] ?? "cubic-out";
178
- return { kind: "tween", duration_ms: n, ease: r };
179
- }
180
- if (s === "spring") {
181
- const n = { kind: "spring" };
182
- return typeof e.stiffness == "number" && (n.stiffness = e.stiffness), typeof e.damping == "number" && (n.damping = e.damping), typeof e.mass == "number" && (n.mass = e.mass), n;
183
- }
184
- }
185
- const Ee = {
186
- linear: "linear",
187
- "ease-in": "cubic-in",
188
- "ease-out": "cubic-out",
189
- "ease-in-out": "cubic-in-out"
190
- };
191
- function Ie(t, e) {
192
- w(() => {
193
- for (const s of e.patches) {
194
- const n = _e(s.transition);
195
- n !== void 0 ? t.setWithTransition(s.path, s.value, n) : t.set(s.path, s.value);
196
- }
197
- });
198
- }
199
- function Ae(t, e) {
200
- t.reset(e.state);
201
- }
202
- class Re {
203
- signals = /* @__PURE__ */ new Map();
204
- transitions = /* @__PURE__ */ new Map();
205
- signal(e) {
206
- let s = this.signals.get(e);
207
- return s || (s = p(void 0), this.signals.set(e, s)), s;
208
- }
209
- transitionSignal(e) {
210
- let s = this.transitions.get(e);
211
- return s || (s = p(void 0), this.transitions.set(e, s)), s;
212
- }
213
- set(e, s) {
214
- const n = this.signal(e);
215
- k(n.peek(), s) || (n.value = s);
216
- }
217
- setWithTransition(e, s, n) {
218
- w(() => {
219
- const r = this.transitionSignal(e);
220
- r.peek() !== n && (r.value = n);
221
- const i = this.signal(e);
222
- k(i.peek(), s) || (i.value = s);
223
- });
224
- }
225
- reset(e) {
226
- w(() => {
227
- const s = /* @__PURE__ */ new Set();
228
- for (const [n, r] of Object.entries(e)) {
229
- s.add(n);
230
- const i = this.signal(n);
231
- k(i.peek(), r) || (i.value = r);
232
- const c = this.transitions.get(n);
233
- c && c.peek() !== void 0 && (c.value = void 0);
234
- }
235
- for (const n of this.signals.keys())
236
- if (!s.has(n)) {
237
- const r = this.signals.get(n);
238
- r && r.peek() !== void 0 && (r.value = void 0);
239
- }
240
- });
241
- }
242
- toRecord() {
243
- const e = {};
244
- for (const [s, n] of this.signals.entries())
245
- e[s] = n.peek();
246
- return e;
247
- }
248
- }
249
- function B() {
250
- return new Re();
251
- }
252
- function k(t, e) {
253
- if (t === e) return !0;
254
- if (t === null || e === null || typeof t != typeof e || typeof t != "object" || Array.isArray(t) !== Array.isArray(e)) return !1;
255
- if (Array.isArray(t) && Array.isArray(e)) {
256
- if (t.length !== e.length) return !1;
257
- for (let c = 0; c < t.length; c++)
258
- if (t[c] !== e[c]) return !1;
259
- return !0;
260
- }
261
- const s = t, n = e, r = Object.keys(s), i = Object.keys(n);
262
- if (r.length !== i.length) return !1;
263
- for (const c of r)
264
- if (s[c] !== n[c]) return !1;
265
- return !0;
266
- }
267
- const Oe = /* @__PURE__ */ new Set([
268
- "x-lumencast.color-srgb-1.0"
269
- ]), Le = /^x-[a-z0-9-]+(?:\.[a-z0-9-]+)*$/, Ne = /^(?:0|[1-9][0-9]*)$/, N = ".authoring";
270
- function Ue(t) {
271
- const e = t.indexOf("/");
272
- if (e < 0) return !1;
273
- const s = t.slice(0, e), n = t.slice(e + 1);
274
- return !Ne.test(n) || !s.endsWith(N) ? !1 : Le.test(s.slice(0, -N.length));
275
- }
276
- class U extends Error {
277
- code = "BUNDLE_INCOMPATIBLE";
278
- unsupportedProfiles;
279
- constructor(e) {
280
- super(
281
- `BUNDLE_INCOMPATIBLE: profile(s) not supported by this runtime: ${e.join(
282
- ", "
283
- )}`
284
- ), this.name = "BundleIncompatibleError", this.unsupportedProfiles = e;
285
- }
286
- }
287
- function x(t, e = Oe) {
288
- const s = t.profiles;
289
- if (!s) return;
290
- if (!Array.isArray(s))
291
- throw new U(["<malformed: profiles is not an array>"]);
292
- if (s.length === 0) return;
293
- const n = s.filter((r) => typeof r != "string" || !Ue(r) && !e.has(r)).map((r) => typeof r == "string" ? r : "<malformed: non-string profile entry>");
294
- if (n.length > 0)
295
- throw new U(n);
296
- }
297
- class xe {
298
- cache = /* @__PURE__ */ new Map();
299
- baseUrl;
300
- pathPrefix;
301
- resolveUrl;
302
- getAuthToken;
303
- fetchImpl;
304
- constructor(e) {
305
- this.baseUrl = e.baseUrl.replace(/\/$/, ""), this.pathPrefix = (e.pathPrefix ?? "/lsdp/v1/scenes").replace(/\/$/, ""), this.resolveUrl = e.resolveUrl, this.getAuthToken = e.getAuthToken, this.fetchImpl = e.fetchImpl ?? globalThis.fetch.bind(globalThis);
306
- }
307
- /** Build the request init carrying the bearer token, if any. Returns
308
- * `undefined` when no token is available — the fetch stays header-less,
309
- * preserving v0.5.0 behaviour. */
310
- async buildInit() {
311
- if (!this.getAuthToken) return;
312
- const e = await this.getAuthToken();
313
- if (e)
314
- return { headers: { Authorization: `Bearer ${e}` } };
315
- }
316
- buildUrl(e, s) {
317
- return this.resolveUrl ? this.resolveUrl(e, s) : `${this.baseUrl}${this.pathPrefix}/${encodeURIComponent(e)}/bundle?v=${encodeURIComponent(s)}`;
318
- }
319
- preload(e) {
320
- x(e), this.cache.set(e.scene_version, e);
321
- }
322
- async get(e, s) {
323
- const n = this.cache.get(s);
324
- if (n) return n;
325
- const r = this.buildUrl(e, s), i = await this.buildInit(), c = i ? await this.fetchImpl(r, i) : await this.fetchImpl(r);
326
- if (!c.ok)
327
- throw new Error(`bundle fetch failed: ${c.status} ${c.statusText}`);
328
- const a = await c.json();
329
- if (a.scene_version !== s)
330
- throw new Error(
331
- `bundle scene_version mismatch: expected ${s}, got ${a.scene_version}`
332
- );
333
- return x(a), this.cache.set(s, a), a;
334
- }
335
- }
336
- function Pe(t) {
337
- return new xe(t);
338
- }
339
- const g = {
340
- initial: 200,
341
- max: 5e3,
342
- factor: 2,
343
- jitter: 0.2
344
- };
345
- class je {
346
- constructor(e, s) {
347
- this.opts = e, this.random = s;
348
- }
349
- _attempt = 0;
350
- get attempt() {
351
- return this._attempt;
352
- }
353
- delayFor(e) {
354
- if (!Number.isInteger(e) || e < 1)
355
- throw new RangeError(`attempt must be a positive integer, got ${e}`);
356
- this._attempt = e;
357
- const s = Math.min(
358
- this.opts.initial * Math.pow(this.opts.factor, e - 1),
359
- this.opts.max
360
- );
361
- if (this.opts.jitter <= 0) return s;
362
- const n = (this.random() * 2 - 1) * this.opts.jitter * s;
363
- return Math.max(0, s + n);
364
- }
365
- reset() {
366
- this._attempt = 0;
367
- }
368
- }
369
- function Me(t = {}) {
370
- const e = {
371
- initial: t.initial ?? g.initial,
372
- max: t.max ?? g.max,
373
- factor: t.factor ?? g.factor,
374
- jitter: t.jitter ?? g.jitter
375
- };
376
- if (e.initial <= 0) throw new RangeError("initial must be > 0");
377
- if (e.max < e.initial) throw new RangeError("max must be >= initial");
378
- if (e.factor < 1) throw new RangeError("factor must be >= 1");
379
- if (e.jitter < 0 || e.jitter > 1) throw new RangeError("jitter must be within [0, 1]");
380
- return new je(e, t.random ?? Math.random);
381
- }
382
- class m extends Error {
383
- recoverable;
384
- code;
385
- cause;
386
- constructor(e, s, n = "INTERNAL", r) {
387
- super(e), this.name = "TransportError", this.recoverable = s, this.code = n, this.cause = r;
388
- }
389
- }
390
- class $e {
391
- status = "disconnected";
392
- socket = null;
393
- token;
394
- url;
395
- WebSocketCtor;
396
- schedule;
397
- seq = new se();
398
- opts;
399
- scheduler;
400
- reconnectTimer = null;
401
- active = !0;
402
- constructor(e) {
403
- this.opts = e, this.url = e.url, this.token = e.token;
404
- const s = e.webSocketImpl ?? globalThis.WebSocket;
405
- if (!s)
406
- throw new TypeError(
407
- "Lumencast WsClient: no WebSocket implementation found in this environment"
408
- );
409
- this.WebSocketCtor = s, this.schedule = Me(e.reconnect), this.scheduler = e.scheduler ?? {
410
- setTimeout: globalThis.setTimeout.bind(globalThis),
411
- clearTimeout: globalThis.clearTimeout.bind(globalThis)
412
- };
413
- }
414
- /** Open and start the connection lifecycle. Idempotent. */
415
- start() {
416
- this.active && (this.socket || this.status === "connecting" || this.openSocket());
417
- }
418
- /** Resolve the current session token (the one used for the WS
419
- * subscription). Mirrors `setToken` swaps. Used by the bundle fetcher to
420
- * authenticate the render-bundle GET with the same credential. A
421
- * `LumencastTokenProvider` is awaited. */
422
- resolveCurrentToken() {
423
- return P(this.token);
424
- }
425
- /** Send `input` patches to the server. No-op if not connected. */
426
- sendInput(e) {
427
- !this.socket || this.socket.readyState !== this.WebSocketCtor.OPEN || e.length !== 0 && this.socket.send(R(ne(e)));
428
- }
429
- /** Replace the auth token. Closes and reopens with the new token. */
430
- setToken(e) {
431
- this.token = e, this.active && this.socket && (this.closeSocket(), this.scheduleReconnect(!0));
432
- }
433
- /** Tear down for good. No more reconnect attempts. */
434
- close() {
435
- this.active && (this.active = !1, this.cancelReconnect(), this.closeSocket(), this.setStatus("disconnected"));
436
- }
437
- // --- internals --------------------------------------------------
438
- async openSocket() {
439
- if (!this.active) return;
440
- this.setStatus("connecting");
441
- let e;
442
- try {
443
- e = await P(this.token);
444
- } catch (n) {
445
- this.opts.onTransportError?.(
446
- new m(
447
- `failed to resolve token: ${n.message}`,
448
- !0,
449
- "AUTH_DENIED",
450
- n
451
- )
452
- ), this.scheduleReconnect();
453
- return;
454
- }
455
- if (!this.active) return;
456
- let s;
457
- try {
458
- s = new this.WebSocketCtor(this.url, [...re]);
459
- } catch (n) {
460
- this.opts.onTransportError?.(
461
- new m(
462
- `failed to open WebSocket: ${n.message}`,
463
- !0,
464
- "INTERNAL",
465
- n
466
- )
467
- ), this.scheduleReconnect();
468
- return;
469
- }
470
- this.socket = s, s.onopen = () => this.handleOpen(e), s.onmessage = (n) => this.handleMessage(n), s.onerror = (n) => this.handleError(n), s.onclose = (n) => this.handleClose(n);
471
- }
472
- handleOpen(e) {
473
- if (!this.socket) return;
474
- const n = this.socket.protocol === ie && this.seq.last > 0, r = n ? this.seq.last : void 0;
475
- n || this.seq.reset();
476
- const i = oe({
477
- token: e,
478
- ...this.opts.scene !== void 0 ? { scene: this.opts.scene } : {},
479
- ...this.opts.session !== void 0 ? { session: this.opts.session } : {},
480
- ...r !== void 0 ? { since_sequence: r } : {}
481
- });
482
- this.socket.send(R(i));
483
- }
484
- handleMessage(e) {
485
- const s = typeof e.data == "string" ? e.data : "";
486
- if (!s) return;
487
- let n;
488
- try {
489
- n = ce(s);
490
- } catch (r) {
491
- const i = (r instanceof O, r.message), c = r instanceof O ? r.code : "INTERNAL";
492
- this.opts.onTransportError?.(new m(`codec: ${i}`, !0, c, r)), this.closeSocket(), this.scheduleReconnect();
493
- return;
494
- }
495
- if (n !== null)
496
- switch (n.type) {
497
- case "snapshot": {
498
- if (n.seq < 1) {
499
- this.opts.onTransportError?.(
500
- new m(`snapshot seq must be >= 1, got ${n.seq}`, !0, "VERSION_GAP")
501
- ), this.closeSocket(), this.scheduleReconnect();
502
- return;
503
- }
504
- this.seq.observeSnapshot(n.seq), this.schedule.reset(), this.setStatus("live"), this.opts.onSnapshot?.(n);
505
- return;
506
- }
507
- case "delta": {
508
- const r = this.seq.observe(n.seq);
509
- if (r.kind === "gap") {
510
- this.opts.onTransportError?.(
511
- new m(
512
- `sequence gap: expected ${this.seq.last + 1}, got ${n.seq}`,
513
- !0,
514
- "VERSION_GAP"
515
- )
516
- ), this.closeSocket(), this.scheduleReconnect();
517
- return;
518
- }
519
- if (r.kind === "duplicate") return;
520
- this.opts.onDelta?.(n);
521
- return;
522
- }
523
- case "scene_changed": {
524
- this.seq.reset(), this.opts.onSceneChanged?.(n);
525
- return;
526
- }
527
- case "error": {
528
- this.opts.onServerError?.(n), n.recoverable || this.close();
529
- return;
530
- }
531
- case "pong":
532
- return;
533
- }
534
- }
535
- handleError(e) {
536
- }
537
- handleClose(e) {
538
- if (this.socket = null, !this.active) {
539
- this.setStatus("disconnected");
540
- return;
541
- }
542
- if (e.code === 4401 || e.code === 4403 || e.code === 1008) {
543
- this.opts.onTransportError?.(
544
- new m(`server closed: ${e.code} ${e.reason}`, !1, "AUTH_DENIED")
545
- ), this.close();
546
- return;
547
- }
548
- this.scheduleReconnect();
549
- }
550
- scheduleReconnect(e = !1) {
551
- if (!this.active) return;
552
- this.cancelReconnect();
553
- const s = (this.schedule.attempt || 0) + 1, n = e ? 0 : this.schedule.delayFor(s);
554
- this.setStatus("disconnected"), this.reconnectTimer = this.scheduler.setTimeout(() => {
555
- this.reconnectTimer = null, this.openSocket();
556
- }, n);
557
- }
558
- cancelReconnect() {
559
- this.reconnectTimer && (this.scheduler.clearTimeout(this.reconnectTimer), this.reconnectTimer = null);
560
- }
561
- closeSocket() {
562
- if (this.socket) {
563
- try {
564
- this.socket.close(1e3, "client closing");
565
- } catch {
566
- }
567
- this.socket = null;
568
- }
569
- }
570
- setStatus(e) {
571
- this.status !== e && (this.status = e, this.opts.onStatus?.(e));
572
- }
573
- }
574
- async function P(t) {
575
- return typeof t == "string" ? t : await t.fetch();
576
- }
577
- function De(t) {
578
- if (!(t.target instanceof HTMLElement))
579
- throw new TypeError("mount: `target` must be an HTMLElement");
580
- if (typeof t.serverUrl != "string" || t.serverUrl.length === 0)
581
- throw new TypeError("mount: `serverUrl` must be a non-empty string");
582
- if (t.mode === "test") {
583
- if (!t.testSession)
584
- throw new TypeError("mount: `testSession` is required when mode === 'test'");
585
- if (!t.scene)
586
- throw new TypeError("mount: `scene` is required when mode === 'test'");
587
- }
588
- }
589
- function rt(t) {
590
- De(t), t.onStatus?.("disconnected");
591
- const e = B(), s = Ce(t.serverUrl), n = Pe({
592
- baseUrl: s,
593
- ...t.resolveBundleUrl !== void 0 ? { resolveUrl: t.resolveBundleUrl } : {},
594
- getAuthToken: () => d.resolveCurrentToken()
595
- }), r = p(null), i = p("disconnected"), c = p("__initial__"), a = (o) => {
596
- i.value = o, t.onStatus?.(o);
597
- }, f = (o) => {
598
- t.onError?.(o);
599
- };
600
- let u = !0;
601
- const b = t.onDiagnostic ? C(t.onDiagnostic) : void 0, d = new $e({
602
- url: t.serverUrl,
603
- token: t.token,
604
- ...t.scene !== void 0 ? { scene: t.scene } : {},
605
- ...t.testSession !== void 0 ? { session: t.testSession } : {},
606
- onStatus: a,
607
- onSnapshot: (o) => {
608
- u && (z(
609
- n,
610
- r,
611
- c,
612
- o.scene_id,
613
- o.scene_version,
614
- () => Ae(e, o),
615
- f
616
- ), t.onMetric?.({
617
- name: "snapshot_received",
618
- scene_id: o.scene_id,
619
- path_count: Object.keys(o.state).length
620
- }));
621
- },
622
- onDelta: (o) => {
623
- if (!u) return;
624
- const y = performance.now();
625
- Ie(e, o), t.onMetric?.({
626
- name: "delta_applied",
627
- duration_ms: performance.now() - y
628
- }), t.onMetric?.({ name: "delta_received", count: 1, path_count: o.patches.length });
629
- },
630
- onSceneChanged: (o) => {
631
- u && t.onMetric?.({
632
- name: "scene_changed",
633
- from: r.value?.scene_version ?? null,
634
- to: o.scene_version
635
- });
636
- },
637
- onServerError: (o) => {
638
- f({
639
- code: o.code,
640
- message: o.message,
641
- recoverable: o.recoverable
642
- });
643
- },
644
- onTransportError: (o) => {
645
- f(Fe(o));
646
- }
647
- });
648
- d.start();
649
- const T = $(t.target);
650
- return T.render(
651
- J(he, {
652
- mode: t.mode,
653
- store: e,
654
- bundleSignal: r,
655
- statusSignal: i,
656
- crossfadeKeySignal: c,
657
- sendInput: (o) => d.sendInput(o)
658
- })
659
- ), {
660
- disconnect() {
661
- u && (u = !1, b?.(), d.close(), T.unmount());
662
- },
663
- setToken(o) {
664
- u && d.setToken(o);
665
- }
666
- };
667
- async function z(o, y, H, _, E, G, X) {
668
- let I;
669
- try {
670
- I = await o.get(_, E);
671
- } catch (A) {
672
- X({
673
- code: "BUNDLE_FETCH_FAILED",
674
- message: A instanceof Error ? A.message : "render bundle fetch failed",
675
- recoverable: !0
676
- });
677
- return;
678
- }
679
- u && (G(), y.value = I, H.value = `${_}::${E}`);
680
- }
681
- }
682
- function Fe(t) {
683
- return {
684
- code: t.code,
685
- message: t.message,
686
- recoverable: t.recoverable
687
- };
688
- }
689
- function Ce(t) {
690
- try {
691
- const e = new URL(t);
692
- return `${e.protocol === "wss:" ? "https:" : "http:"}//${e.host}`;
693
- } catch {
694
- return "";
695
- }
696
- }
697
- const qe = [
698
- "visible",
699
- "opacity",
700
- "universal_opacity",
701
- "rotation",
702
- "sizing",
703
- "x",
704
- "y",
705
- "width",
706
- "height",
707
- // ADR 002 §3.2 (D2 / #D) — `blendMode` is consumed universally by the
708
- // wrapper (→ CSS `mix-blend-mode`) on every primitive.
709
- "blendMode",
710
- // ADR 002 §3.2 (#E) — a typed `mask` is lowered onto EVERY primitive by the
711
- // compiler and consumed by the Tree (built into a `<mask>` SVG element).
712
- "mask"
713
- ];
714
- function h(t) {
715
- return /* @__PURE__ */ new Set([...qe, ...t]);
716
- }
717
- const Be = {
718
- stack: h(["direction", "gap", "wrap", "crossGap", "align", "justify"]),
719
- grid: h(["cols", "rows", "gap"]),
720
- frame: h([
721
- "x",
722
- "y",
723
- "width",
724
- "height",
725
- "scale",
726
- "rotate",
727
- "background",
728
- "backgrounds",
729
- "clipsContent"
730
- ]),
731
- text: h([
732
- "value",
733
- "size",
734
- "font",
735
- "weight",
736
- "colour",
737
- "align",
738
- "lineHeight",
739
- "letterSpacing",
740
- "textTransform",
741
- "textDecoration",
742
- "fontStyle",
743
- "maxLines"
744
- ]),
745
- image: h(["src", "alt", "fit", "position", "width", "height"]),
746
- shape: h([
747
- "geometry",
748
- "kind",
749
- "width",
750
- "height",
751
- "radius",
752
- "fill",
753
- "fills",
754
- "stroke",
755
- "stroke_width",
756
- "strokes",
757
- "pathData",
758
- "paths",
759
- "ariaLabel"
760
- ]),
761
- media: h(["src", "loop", "mute", "autoplay", "fit"]),
762
- instance: h(["scene_id", "scene_version", "size", "position"]),
763
- // `repeat` is dispatched specially by the tree ; its only consumed
764
- // binding is `items`.
765
- repeat: /* @__PURE__ */ new Set(["items"])
766
- };
767
- function We(t, e) {
768
- const s = Be[t];
769
- return !!(s === void 0 || s.has(e) || t === "instance" && (e === "params" || e.startsWith("params.")));
770
- }
771
- const j = /* @__PURE__ */ new WeakSet();
772
- function it(t) {
773
- if (j.has(t)) return;
774
- j.add(t);
775
- const e = /* @__PURE__ */ new Set([
776
- ...Object.keys(t.props ?? {}),
777
- ...Object.keys(t.bindings ?? {})
778
- ]);
779
- for (const s of e)
780
- We(t.kind, s) || q(
781
- t.id,
782
- `${t.kind}.${s}`,
783
- "is not consumed by this primitive's renderer ; the prop is ignored (anti-silent-drop, ADR 001 §3.4)"
784
- );
785
- }
786
- const ze = { width: 1920, height: 1080 }, He = () => {
787
- };
788
- function ot(t) {
789
- const e = t.stage ?? ze, s = t.target;
790
- s.style.position ||= "relative", s.style.width = `${e.width}px`, s.style.height = `${e.height}px`, s.style.overflow = "hidden";
791
- const n = t.onDiagnostic ? C(t.onDiagnostic) : void 0, r = B();
792
- r.reset(t.defaults ?? {});
793
- const i = $(s);
794
- return {
795
- ready: new Promise((a) => {
796
- import("./broadcast-Gcd-dmC7.js").then(({ BroadcastMode: f }) => {
797
- i.render(
798
- /* @__PURE__ */ l(Q, { children: /* @__PURE__ */ l(
799
- F,
800
- {
801
- value: {
802
- mode: "broadcast",
803
- store: r,
804
- bundle: t.bundle,
805
- status: "live",
806
- sendInput: He
807
- },
808
- children: /* @__PURE__ */ l(f, {})
809
- }
810
- ) })
811
- );
812
- const u = new Promise((d) => {
813
- requestAnimationFrame(() => requestAnimationFrame(() => d()));
814
- }), b = typeof document < "u" && document.fonts ? document.fonts.ready.then(() => {
815
- }) : Promise.resolve();
816
- Promise.all([u, b]).then(() => a());
817
- });
818
- }),
819
- unmount() {
820
- n?.(), i.unmount();
821
- }
822
- };
823
- }
824
- function W(t, e) {
825
- if (typeof t != "string") return t;
826
- if (e[t]) return e[t];
827
- const s = /^assets\/([A-Za-z0-9]+)\.[A-Za-z0-9]+$/.exec(t);
828
- return s && s[1] !== void 0 && e[s[1]] ? e[s[1]] : t;
829
- }
830
- function M(t, e) {
831
- if (t === null || typeof t != "object") return;
832
- if (Array.isArray(t)) {
833
- for (const n of t) M(n, e);
834
- return;
835
- }
836
- const s = t;
837
- "src" in s && (s.src = W(s.src, e));
838
- for (const n of Object.values(s))
839
- n && typeof n == "object" && M(n, e);
840
- }
841
- function ct(t, e) {
842
- const s = { ...t };
843
- for (const [n, r] of Object.entries(s))
844
- n.startsWith("__lit.image.") && (s[n] = W(r, e));
845
- return s;
846
- }
847
- async function at(t) {
848
- const e = [];
849
- for (const s of t)
850
- try {
851
- const n = new FontFace(s.family, s.src, {
852
- weight: String(s.weight),
853
- style: s.style ?? "normal"
854
- });
855
- await n.load(), document.fonts.add(n), e.push(s.family);
856
- } catch {
857
- }
858
- return e;
859
- }
860
- export {
861
- fe as A,
862
- U as B,
863
- et as F,
864
- Be as P,
865
- Oe as S,
866
- it as a,
867
- C as b,
868
- L as c,
869
- Ue as d,
870
- q as e,
871
- rt as f,
872
- ot as g,
873
- W as h,
874
- at as i,
875
- ct as j,
876
- M as k,
877
- nt as m,
878
- st as r,
879
- be as s,
880
- tt as t,
881
- Ve as u,
882
- x as v,
883
- ye as w
884
- };
885
- //# sourceMappingURL=index-N-VqrIxN.js.map