@lumencast/runtime 0.2.0 → 0.4.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 (55) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/animate/transitions.d.ts +50 -0
  3. package/dist/animate/transitions.d.ts.map +1 -1
  4. package/dist/animate/transitions.js +91 -0
  5. package/dist/animate/transitions.js.map +1 -1
  6. package/dist/{broadcast-DzDvyVhx.js → broadcast-DzZ8TVGZ.js} +3 -3
  7. package/dist/{broadcast-DzDvyVhx.js.map → broadcast-DzZ8TVGZ.js.map} +1 -1
  8. package/dist/{control-B6Yr-dDz.js → control-gbDGvdR0.js} +4 -4
  9. package/dist/{control-B6Yr-dDz.js.map → control-gbDGvdR0.js.map} +1 -1
  10. package/dist/{index-X6EOQGho.js → index-oteiocFe.js} +108 -74
  11. package/dist/index-oteiocFe.js.map +1 -0
  12. package/dist/index.html +1 -1
  13. package/dist/lumencast.js +2 -2
  14. package/dist/render/bundle.d.ts +8 -0
  15. package/dist/render/bundle.d.ts.map +1 -1
  16. package/dist/render/bundle.js.map +1 -1
  17. package/dist/render/primitives/frame.d.ts +1 -1
  18. package/dist/render/primitives/frame.d.ts.map +1 -1
  19. package/dist/render/primitives/frame.js +5 -14
  20. package/dist/render/primitives/frame.js.map +1 -1
  21. package/dist/render/primitives/image.d.ts +4 -2
  22. package/dist/render/primitives/image.d.ts.map +1 -1
  23. package/dist/render/primitives/image.js +9 -6
  24. package/dist/render/primitives/image.js.map +1 -1
  25. package/dist/render/primitives/index.d.ts +6 -0
  26. package/dist/render/primitives/index.d.ts.map +1 -1
  27. package/dist/render/primitives/index.js.map +1 -1
  28. package/dist/render/primitives/shape.d.ts +1 -1
  29. package/dist/render/primitives/shape.d.ts.map +1 -1
  30. package/dist/render/primitives/shape.js +5 -4
  31. package/dist/render/primitives/shape.js.map +1 -1
  32. package/dist/render/primitives/text.d.ts +3 -2
  33. package/dist/render/primitives/text.d.ts.map +1 -1
  34. package/dist/render/primitives/text.js +8 -6
  35. package/dist/render/primitives/text.js.map +1 -1
  36. package/dist/render/tree.js +1 -1
  37. package/dist/render/tree.js.map +1 -1
  38. package/dist/{status-pill-DpO4hqUL.js → status-pill-Cgdl9FtP.js} +2 -2
  39. package/dist/{status-pill-DpO4hqUL.js.map → status-pill-Cgdl9FtP.js.map} +1 -1
  40. package/dist/{test-Dr0J0H6Q.js → test-CAnkHA0n.js} +4 -4
  41. package/dist/{test-Dr0J0H6Q.js.map → test-CAnkHA0n.js.map} +1 -1
  42. package/dist/tree-DVYXwItH.js +512 -0
  43. package/dist/tree-DVYXwItH.js.map +1 -0
  44. package/package.json +4 -4
  45. package/src/animate/transitions.ts +106 -0
  46. package/src/render/bundle.ts +8 -0
  47. package/src/render/primitives/frame.tsx +11 -15
  48. package/src/render/primitives/image.tsx +10 -6
  49. package/src/render/primitives/index.ts +6 -0
  50. package/src/render/primitives/shape.tsx +7 -5
  51. package/src/render/primitives/text.tsx +9 -6
  52. package/src/render/tree.tsx +5 -1
  53. package/dist/index-X6EOQGho.js.map +0 -1
  54. package/dist/tree-B_wLlJ36.js +0 -500
  55. package/dist/tree-B_wLlJ36.js.map +0 -1
@@ -1,31 +1,31 @@
1
- import { batch as b, signal as d } from "@preact/signals-react";
2
- import { createRoot as C } from "react-dom/client";
3
- import { createContext as U, useContext as x, lazy as S, Suspense as P, createElement as q } from "react";
1
+ import { batch as k, signal as d } from "@preact/signals-react";
2
+ import { createRoot as U } from "react-dom/client";
3
+ import { createContext as P, useContext as $, lazy as b, Suspense as j, createElement as x } from "react";
4
4
  import { jsx as l } from "react/jsx-runtime";
5
- import { useSignals as N } from "@preact/signals-react/runtime";
6
- import { AnimatePresence as j, motion as W } from "framer-motion";
7
- import { SequenceTracker as B, encodeFrame as _, input as D, WS_SUBPROTOCOLS as F, WS_SUBPROTOCOL_V1_1 as H, subscribe as z, decodeServerFrame as G, LumencastError as I } from "@lumencast/protocol";
8
- const O = U(null);
5
+ import { useSignals as C } from "@preact/signals-react/runtime";
6
+ import { AnimatePresence as q, motion as D } from "framer-motion";
7
+ import { SequenceTracker as W, encodeFrame as _, input as B, WS_SUBPROTOCOLS as F, WS_SUBPROTOCOL_V1_1 as H, subscribe as z, decodeServerFrame as G, LumencastError as I } from "@lumencast/protocol";
8
+ const O = P(null);
9
9
  function K({
10
10
  value: t,
11
11
  children: e
12
12
  }) {
13
13
  return /* @__PURE__ */ l(O.Provider, { value: t, children: e });
14
14
  }
15
- function Te() {
16
- const t = x(O);
15
+ function Ie() {
16
+ const t = $(O);
17
17
  if (!t)
18
18
  throw new Error(
19
19
  "Lumencast overlay components must be rendered inside LumencastRuntimeProvider"
20
20
  );
21
21
  return t;
22
22
  }
23
- const J = S(
24
- () => import("./broadcast-DzDvyVhx.js").then((t) => ({ default: t.BroadcastMode }))
25
- ), Q = S(
26
- () => import("./control-B6Yr-dDz.js").then((t) => ({ default: t.ControlMode }))
27
- ), X = S(() => import("./test-Dr0J0H6Q.js").then((t) => ({ default: t.TestMode })));
28
- function Y({
23
+ const Y = b(
24
+ () => import("./broadcast-DzZ8TVGZ.js").then((t) => ({ default: t.BroadcastMode }))
25
+ ), J = b(
26
+ () => import("./control-gbDGvdR0.js").then((t) => ({ default: t.ControlMode }))
27
+ ), Q = b(() => import("./test-CAnkHA0n.js").then((t) => ({ default: t.TestMode })));
28
+ function X({
29
29
  mode: t,
30
30
  store: e,
31
31
  bundleSignal: s,
@@ -33,12 +33,12 @@ function Y({
33
33
  crossfadeKeySignal: r,
34
34
  sendInput: c
35
35
  }) {
36
- N();
36
+ C();
37
37
  const i = s.value, m = n.value, h = r.value;
38
38
  if (!i) return null;
39
- const a = t === "broadcast" ? J : t === "control" ? Q : X;
40
- return /* @__PURE__ */ l(j, { mode: "sync", children: /* @__PURE__ */ l(
41
- W.div,
39
+ const a = t === "broadcast" ? Y : t === "control" ? J : Q;
40
+ return /* @__PURE__ */ l(q, { mode: "sync", children: /* @__PURE__ */ l(
41
+ D.div,
42
42
  {
43
43
  initial: { opacity: 0 },
44
44
  animate: { opacity: 1 },
@@ -55,7 +55,7 @@ function Y({
55
55
  status: m,
56
56
  sendInput: c
57
57
  },
58
- children: /* @__PURE__ */ l(P, { fallback: null, children: /* @__PURE__ */ l(a, {}) })
58
+ children: /* @__PURE__ */ l(j, { fallback: null, children: /* @__PURE__ */ l(a, {}) })
59
59
  }
60
60
  )
61
61
  },
@@ -68,7 +68,7 @@ const Z = { duration: 0 }, V = {
68
68
  "cubic-out": "easeOut",
69
69
  "cubic-in-out": "easeInOut"
70
70
  };
71
- function _e(t) {
71
+ function Re(t) {
72
72
  return !t || t.kind === "none" ? Z : t.kind === "tween" ? {
73
73
  type: "tween",
74
74
  duration: (t.duration_ms ?? 0) / 1e3,
@@ -83,13 +83,45 @@ function _e(t) {
83
83
  ease: "easeInOut"
84
84
  };
85
85
  }
86
- function ee(t) {
86
+ const ee = {
87
+ opacity: 1,
88
+ scale: 1,
89
+ rotate: 0,
90
+ x: 0,
91
+ y: 0
92
+ }, te = {
93
+ kind: "tween",
94
+ duration_ms: 400,
95
+ ease: "cubic-out"
96
+ };
97
+ function Oe(t, e, s) {
98
+ for (const n of e) {
99
+ const r = t(n);
100
+ if (r !== void 0) return r;
101
+ }
102
+ if (s && Object.keys(s).length > 0) {
103
+ for (const n of Object.keys(s)) {
104
+ const r = t(n);
105
+ if (r !== void 0) return r;
106
+ }
107
+ return te;
108
+ }
109
+ }
110
+ function Ae(t, e) {
111
+ if (!e || Object.keys(e).length === 0)
112
+ return { initial: t, animate: t };
113
+ const s = { ...t };
114
+ for (const n of Object.keys(e))
115
+ n in s || (s[n] = ee[n] ?? 0);
116
+ return { initial: e, animate: s };
117
+ }
118
+ function se(t) {
87
119
  if (typeof t != "object" || t === null) return;
88
120
  const e = t, s = e.kind;
89
121
  if (s === "snap")
90
122
  return { kind: "none" };
91
123
  if (s === "tween") {
92
- const n = typeof e.duration_ms == "number" ? e.duration_ms : 0, r = te[e.easing] ?? "cubic-out";
124
+ const n = typeof e.duration_ms == "number" ? e.duration_ms : 0, r = ne[e.easing] ?? "cubic-out";
93
125
  return { kind: "tween", duration_ms: n, ease: r };
94
126
  }
95
127
  if (s === "spring") {
@@ -97,24 +129,24 @@ function ee(t) {
97
129
  return typeof e.stiffness == "number" && (n.stiffness = e.stiffness), typeof e.damping == "number" && (n.damping = e.damping), n;
98
130
  }
99
131
  }
100
- const te = {
132
+ const ne = {
101
133
  linear: "linear",
102
134
  "ease-in": "cubic-in",
103
135
  "ease-out": "cubic-out",
104
136
  "ease-in-out": "cubic-in-out"
105
137
  };
106
- function se(t, e) {
107
- b(() => {
138
+ function re(t, e) {
139
+ k(() => {
108
140
  for (const s of e.patches) {
109
- const n = ee(s.transition);
141
+ const n = se(s.transition);
110
142
  n !== void 0 ? t.setWithTransition(s.path, s.value, n) : t.set(s.path, s.value);
111
143
  }
112
144
  });
113
145
  }
114
- function ne(t, e) {
146
+ function oe(t, e) {
115
147
  t.reset(e.state);
116
148
  }
117
- class re {
149
+ class ie {
118
150
  signals = /* @__PURE__ */ new Map();
119
151
  transitions = /* @__PURE__ */ new Map();
120
152
  signal(e) {
@@ -130,7 +162,7 @@ class re {
130
162
  v(n.peek(), s) || (n.value = s);
131
163
  }
132
164
  setWithTransition(e, s, n) {
133
- b(() => {
165
+ k(() => {
134
166
  const r = this.transitionSignal(e);
135
167
  r.peek() !== n && (r.value = n);
136
168
  const c = this.signal(e);
@@ -138,7 +170,7 @@ class re {
138
170
  });
139
171
  }
140
172
  reset(e) {
141
- b(() => {
173
+ k(() => {
142
174
  const s = /* @__PURE__ */ new Set();
143
175
  for (const [n, r] of Object.entries(e)) {
144
176
  s.add(n);
@@ -161,8 +193,8 @@ class re {
161
193
  return e;
162
194
  }
163
195
  }
164
- function oe() {
165
- return new re();
196
+ function ce() {
197
+ return new ie();
166
198
  }
167
199
  function v(t, e) {
168
200
  if (t === e) return !0;
@@ -179,10 +211,10 @@ function v(t, e) {
179
211
  if (s[i] !== n[i]) return !1;
180
212
  return !0;
181
213
  }
182
- const ie = /* @__PURE__ */ new Set([
214
+ const ae = /* @__PURE__ */ new Set([
183
215
  "x-lumencast.color-srgb-1.0"
184
216
  ]);
185
- class ce extends Error {
217
+ class ue extends Error {
186
218
  code = "BUNDLE_INCOMPATIBLE";
187
219
  unsupportedProfiles;
188
220
  constructor(e) {
@@ -193,14 +225,14 @@ class ce extends Error {
193
225
  ), this.name = "BundleIncompatibleError", this.unsupportedProfiles = e;
194
226
  }
195
227
  }
196
- function R(t, e = ie) {
228
+ function R(t, e = ae) {
197
229
  const s = t.profiles;
198
230
  if (!s || s.length === 0) return;
199
231
  const n = s.filter((r) => !e.has(r));
200
232
  if (n.length > 0)
201
- throw new ce(n);
233
+ throw new ue(n);
202
234
  }
203
- class ae {
235
+ class le {
204
236
  cache = /* @__PURE__ */ new Map();
205
237
  baseUrl;
206
238
  pathPrefix;
@@ -225,8 +257,8 @@ class ae {
225
257
  return R(i), this.cache.set(s, i), i;
226
258
  }
227
259
  }
228
- function ue(t) {
229
- return new ae(t);
260
+ function he(t) {
261
+ return new le(t);
230
262
  }
231
263
  const p = {
232
264
  initial: 200,
@@ -234,7 +266,7 @@ const p = {
234
266
  factor: 2,
235
267
  jitter: 0.2
236
268
  };
237
- class le {
269
+ class de {
238
270
  constructor(e, s) {
239
271
  this.opts = e, this.random = s;
240
272
  }
@@ -258,7 +290,7 @@ class le {
258
290
  this._attempt = 0;
259
291
  }
260
292
  }
261
- function he(t = {}) {
293
+ function fe(t = {}) {
262
294
  const e = {
263
295
  initial: t.initial ?? p.initial,
264
296
  max: t.max ?? p.max,
@@ -269,7 +301,7 @@ function he(t = {}) {
269
301
  if (e.max < e.initial) throw new RangeError("max must be >= initial");
270
302
  if (e.factor < 1) throw new RangeError("factor must be >= 1");
271
303
  if (e.jitter < 0 || e.jitter > 1) throw new RangeError("jitter must be within [0, 1]");
272
- return new le(e, t.random ?? Math.random);
304
+ return new de(e, t.random ?? Math.random);
273
305
  }
274
306
  class u extends Error {
275
307
  recoverable;
@@ -279,14 +311,14 @@ class u extends Error {
279
311
  super(e), this.name = "TransportError", this.recoverable = s, this.code = n, this.cause = r;
280
312
  }
281
313
  }
282
- class de {
314
+ class pe {
283
315
  status = "disconnected";
284
316
  socket = null;
285
317
  token;
286
318
  url;
287
319
  WebSocketCtor;
288
320
  schedule;
289
- seq = new B();
321
+ seq = new W();
290
322
  opts;
291
323
  scheduler;
292
324
  reconnectTimer = null;
@@ -298,7 +330,7 @@ class de {
298
330
  throw new TypeError(
299
331
  "Lumencast WsClient: no WebSocket implementation found in this environment"
300
332
  );
301
- this.WebSocketCtor = s, this.schedule = he(e.reconnect), this.scheduler = e.scheduler ?? {
333
+ this.WebSocketCtor = s, this.schedule = fe(e.reconnect), this.scheduler = e.scheduler ?? {
302
334
  setTimeout: globalThis.setTimeout.bind(globalThis),
303
335
  clearTimeout: globalThis.clearTimeout.bind(globalThis)
304
336
  };
@@ -309,7 +341,7 @@ class de {
309
341
  }
310
342
  /** Send `input` patches to the server. No-op if not connected. */
311
343
  sendInput(e) {
312
- !this.socket || this.socket.readyState !== this.WebSocketCtor.OPEN || e.length !== 0 && this.socket.send(_(D(e)));
344
+ !this.socket || this.socket.readyState !== this.WebSocketCtor.OPEN || e.length !== 0 && this.socket.send(_(B(e)));
313
345
  }
314
346
  /** Replace the auth token. Closes and reopens with the new token. */
315
347
  setToken(e) {
@@ -325,7 +357,7 @@ class de {
325
357
  this.setStatus("connecting");
326
358
  let e;
327
359
  try {
328
- e = await fe(this.token);
360
+ e = await me(this.token);
329
361
  } catch (n) {
330
362
  this.opts.onTransportError?.(
331
363
  new u(
@@ -456,10 +488,10 @@ class de {
456
488
  this.status !== e && (this.status = e, this.opts.onStatus?.(e));
457
489
  }
458
490
  }
459
- async function fe(t) {
491
+ async function me(t) {
460
492
  return typeof t == "string" ? t : await t.fetch();
461
493
  }
462
- function pe(t) {
494
+ function ge(t) {
463
495
  if (!(t.target instanceof HTMLElement))
464
496
  throw new TypeError("mount: `target` must be an HTMLElement");
465
497
  if (typeof t.serverUrl != "string" || t.serverUrl.length === 0)
@@ -471,15 +503,15 @@ function pe(t) {
471
503
  throw new TypeError("mount: `scene` is required when mode === 'test'");
472
504
  }
473
505
  }
474
- function Ie(t) {
475
- pe(t), t.onStatus?.("disconnected");
476
- const e = oe(), s = ge(t.serverUrl), n = ue({ baseUrl: s }), r = d(null), c = d("disconnected"), i = d("__initial__"), m = (o) => {
506
+ function Le(t) {
507
+ ge(t), t.onStatus?.("disconnected");
508
+ const e = ce(), s = ke(t.serverUrl), n = he({ baseUrl: s }), r = d(null), c = d("disconnected"), i = d("__initial__"), m = (o) => {
477
509
  c.value = o, t.onStatus?.(o);
478
510
  }, h = (o) => {
479
511
  t.onError?.(o);
480
512
  };
481
513
  let a = !0;
482
- const f = new de({
514
+ const f = new pe({
483
515
  url: t.serverUrl,
484
516
  token: t.token,
485
517
  ...t.scene !== void 0 ? { scene: t.scene } : {},
@@ -492,7 +524,7 @@ function Ie(t) {
492
524
  i,
493
525
  o.scene_id,
494
526
  o.scene_version,
495
- () => ne(e, o),
527
+ () => oe(e, o),
496
528
  h
497
529
  ), t.onMetric?.({
498
530
  name: "snapshot_received",
@@ -503,7 +535,7 @@ function Ie(t) {
503
535
  onDelta: (o) => {
504
536
  if (!a) return;
505
537
  const g = performance.now();
506
- se(e, o), t.onMetric?.({
538
+ re(e, o), t.onMetric?.({
507
539
  name: "delta_applied",
508
540
  duration_ms: performance.now() - g
509
541
  }), t.onMetric?.({ name: "delta_received", count: 1, path_count: o.patches.length });
@@ -523,13 +555,13 @@ function Ie(t) {
523
555
  });
524
556
  },
525
557
  onTransportError: (o) => {
526
- h(me(o));
558
+ h(ve(o));
527
559
  }
528
560
  });
529
561
  f.start();
530
- const k = C(t.target);
531
- return k.render(
532
- q(Y, {
562
+ const S = U(t.target);
563
+ return S.render(
564
+ x(X, {
533
565
  mode: t.mode,
534
566
  store: e,
535
567
  bundleSignal: r,
@@ -539,35 +571,35 @@ function Ie(t) {
539
571
  })
540
572
  ), {
541
573
  disconnect() {
542
- a && (a = !1, f.close(), k.unmount());
574
+ a && (a = !1, f.close(), S.unmount());
543
575
  },
544
576
  setToken(o) {
545
577
  a && f.setToken(o);
546
578
  }
547
579
  };
548
- async function A(o, g, L, w, E, M, $) {
549
- let y;
580
+ async function A(o, g, L, y, T, M, N) {
581
+ let w;
550
582
  try {
551
- y = await o.get(w, E);
552
- } catch (T) {
553
- $({
583
+ w = await o.get(y, T);
584
+ } catch (E) {
585
+ N({
554
586
  code: "BUNDLE_FETCH_FAILED",
555
- message: T instanceof Error ? T.message : "render bundle fetch failed",
587
+ message: E instanceof Error ? E.message : "render bundle fetch failed",
556
588
  recoverable: !0
557
589
  });
558
590
  return;
559
591
  }
560
- a && (M(), g.value = y, L.value = `${w}::${E}`);
592
+ a && (M(), g.value = w, L.value = `${y}::${T}`);
561
593
  }
562
594
  }
563
- function me(t) {
595
+ function ve(t) {
564
596
  return {
565
597
  code: t.code,
566
598
  message: t.message,
567
599
  recoverable: t.recoverable
568
600
  };
569
601
  }
570
- function ge(t) {
602
+ function ke(t) {
571
603
  try {
572
604
  const e = new URL(t);
573
605
  return `${e.protocol === "wss:" ? "https:" : "http:"}//${e.host}`;
@@ -576,8 +608,10 @@ function ge(t) {
576
608
  }
577
609
  }
578
610
  export {
579
- Ie as m,
580
- _e as t,
581
- Te as u
611
+ Le as a,
612
+ Ae as m,
613
+ Oe as r,
614
+ Re as t,
615
+ Ie as u
582
616
  };
583
- //# sourceMappingURL=index-X6EOQGho.js.map
617
+ //# sourceMappingURL=index-oteiocFe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-oteiocFe.js","sources":["../src/overlay/runtime-context.tsx","../src/app.tsx","../src/animate/transitions.ts","../src/state/apply-delta.ts","../src/state/apply-snapshot.ts","../src/state/store.ts","../src/render/bundle.ts","../src/transport/reconnect.ts","../src/transport/ws.ts","../src/internal/validate-options.ts","../src/mount.ts"],"sourcesContent":["import { createContext, useContext, type ReactNode } from \"react\";\nimport type { Patch } from \"@lumencast/protocol\";\nimport type { Store } from \"../state/store\";\nimport type { RenderBundle } from \"../render/bundle\";\nimport type { ConnectionStatus } from \"../transport/ws\";\nimport type { LumencastMode } from \"../types\";\n\nexport interface LumencastRuntime {\n mode: LumencastMode;\n store: Store;\n bundle: RenderBundle;\n status: ConnectionStatus;\n /** Send LSDP/1 input patches to the server. */\n sendInput: (patches: Patch[]) => void;\n}\n\nconst Ctx = createContext<LumencastRuntime | null>(null);\n\nexport function LumencastRuntimeProvider({\n value,\n children,\n}: {\n value: LumencastRuntime;\n children: ReactNode;\n}) {\n return <Ctx.Provider value={value}>{children}</Ctx.Provider>;\n}\n\nexport function useLumencastRuntime(): LumencastRuntime {\n const v = useContext(Ctx);\n if (!v) {\n throw new Error(\n \"Lumencast overlay components must be rendered inside LumencastRuntimeProvider\",\n );\n }\n return v;\n}\n","// Top-level React component for a mounted Lumencast instance. Reads the runtime\n// signals (bundle / status) and dispatches to the right mode.\n//\n// Per-mode code splitting: BroadcastMode / ControlMode / TestMode live in\n// separate chunks loaded only when the corresponding mode is requested. A\n// broadcast mount never downloads the overlay or test code — the broadcast\n// chunk is the bare minimum a CEF host needs to render the scene.\n//\n// Crossfade: AnimatePresence freezes the props of an exiting child so its render\n// tree keeps using the values it held at the moment it started exiting.\n\nimport { useSignals } from \"@preact/signals-react/runtime\";\nimport type { Signal } from \"@preact/signals-react\";\nimport { AnimatePresence, motion } from \"framer-motion\";\nimport { lazy, Suspense } from \"react\";\nimport type { Patch } from \"@lumencast/protocol\";\nimport type { Store } from \"./state/store.js\";\nimport type { RenderBundle } from \"./render/bundle.js\";\nimport type { ConnectionStatus } from \"./transport/ws.js\";\nimport { LumencastRuntimeProvider } from \"./overlay/runtime-context.js\";\nimport type { LumencastMode } from \"./types.js\";\n\nconst LazyBroadcastMode = lazy(() =>\n import(\"./modes/broadcast.js\").then((m) => ({ default: m.BroadcastMode })),\n);\nconst LazyControlMode = lazy(() =>\n import(\"./modes/control.js\").then((m) => ({ default: m.ControlMode })),\n);\nconst LazyTestMode = lazy(() => import(\"./modes/test.js\").then((m) => ({ default: m.TestMode })));\n\nexport interface LumencastAppProps {\n mode: LumencastMode;\n store: Store;\n bundleSignal: Signal<RenderBundle | null>;\n statusSignal: Signal<ConnectionStatus>;\n crossfadeKeySignal: Signal<string>;\n sendInput: (patches: Patch[]) => void;\n}\n\nexport function LumencastApp({\n mode,\n store,\n bundleSignal,\n statusSignal,\n crossfadeKeySignal,\n sendInput,\n}: LumencastAppProps) {\n useSignals();\n\n const bundle = bundleSignal.value;\n const status = statusSignal.value;\n const trackKey = crossfadeKeySignal.value;\n if (!bundle) return null;\n\n const ModeComponent =\n mode === \"broadcast\" ? LazyBroadcastMode : mode === \"control\" ? LazyControlMode : LazyTestMode;\n\n return (\n <AnimatePresence mode=\"sync\">\n <motion.div\n key={trackKey}\n initial={{ opacity: 0 }}\n animate={{ opacity: 1 }}\n exit={{ opacity: 0 }}\n transition={{ duration: 0.4, ease: \"easeInOut\" }}\n style={{ position: \"absolute\", inset: 0 }}\n >\n <LumencastRuntimeProvider\n value={{\n mode,\n store,\n bundle,\n status,\n sendInput,\n }}\n >\n <Suspense fallback={null}>\n <ModeComponent />\n </Suspense>\n </LumencastRuntimeProvider>\n </motion.div>\n </AnimatePresence>\n );\n}\n","// Local Transition type + Framer Motion translation.\n//\n// LSML 1.0 §6 declares `animate` directives at the primitive level (transition,\n// transform, opacity, filter). LSDP/1.1 §3.2.2 added per-leaf transition\n// directives on delta patches — incoming deltas can carry a transition hint\n// that overrides the bundle-level default for the next animation cycle.\n// `parseWireTransition` ingests the wire shape ; `Store.lastTransition(path)`\n// surfaces the most-recent directive to the renderer.\n//\n// We deliberately animate only GPU-friendly properties (transform, opacity,\n// filter). Primitives enforce this at the DOM level by exposing those props as\n// motion-bindable values rather than raw CSS.\n\nexport type TransitionKind = \"none\" | \"tween\" | \"spring\" | \"crossfade\";\n\nexport interface TweenTransition {\n kind: \"tween\";\n duration_ms: number;\n ease?: \"linear\" | \"cubic-in\" | \"cubic-out\" | \"cubic-in-out\";\n}\n\nexport interface SpringTransition {\n kind: \"spring\";\n stiffness?: number;\n damping?: number;\n}\n\nexport interface CrossfadeTransition {\n kind: \"crossfade\";\n duration_ms?: number;\n}\n\nexport interface NoTransition {\n kind: \"none\";\n}\n\nexport type Transition = NoTransition | TweenTransition | SpringTransition | CrossfadeTransition;\n\nexport type FramerEasing = \"linear\" | \"easeIn\" | \"easeOut\" | \"easeInOut\";\n\nexport interface FramerTransition {\n duration?: number;\n ease?: FramerEasing;\n type?: \"tween\" | \"spring\";\n stiffness?: number;\n damping?: number;\n}\n\nconst NO_ANIMATION: FramerTransition = { duration: 0 };\n\nconst EASE_MAP: Record<string, FramerEasing> = {\n linear: \"linear\",\n \"cubic-in\": \"easeIn\",\n \"cubic-out\": \"easeOut\",\n \"cubic-in-out\": \"easeInOut\",\n};\n\nexport function toFramer(t: Transition | undefined): FramerTransition {\n if (!t || t.kind === \"none\") return NO_ANIMATION;\n if (t.kind === \"tween\") {\n return {\n type: \"tween\",\n duration: (t.duration_ms ?? 0) / 1000,\n ease: t.ease ? (EASE_MAP[t.ease] ?? \"easeOut\") : \"easeOut\",\n };\n }\n if (t.kind === \"spring\") {\n return {\n type: \"spring\",\n ...(t.stiffness !== undefined ? { stiffness: t.stiffness } : {}),\n ...(t.damping !== undefined ? { damping: t.damping } : {}),\n };\n }\n // crossfade at the per-prop level degenerates into a tween on opacity.\n return {\n type: \"tween\",\n duration: (t.duration_ms ?? 400) / 1000,\n ease: \"easeInOut\",\n };\n}\n\n// --- mount-play (LSML 1.1 `animate.from`) ---------------------------\n\n/** Identity (animation-end) value for each framer key an `animate.from`\n * may declare. A primitive that doesn't natively animate a given key\n * still converges it to this neutral value on mount so the element ends\n * up visually correct (e.g. a `from.scale: 0.85` settles at `scale: 1`). */\nconst INITIAL_IDENTITY: Record<string, number> = {\n opacity: 1,\n scale: 1,\n rotate: 0,\n x: 0,\n y: 0,\n};\n\nexport interface MountPlay {\n initial: Record<string, number | string>;\n animate: Record<string, number | string>;\n}\n\n/**\n * Default mount-play timing — applies when a node carries an\n * `animate_initial` (LSML 1.1 `animate.from`) but no per-prop\n * `transitions` entry resolves for any animated key. The compiler\n * documents that `from` without an explicit `transition` mount-plays\n * \"with the runtime's default timing\" ; before this constant existed the\n * fallback was `toFramer(undefined)` → `{ duration: 0 }`, which snapped\n * the element straight to its settled state (the mount-play never\n * visibly played). 400 ms ease-out matches the runtime's other implicit\n * timings (crossfade fallback, scene-track fade).\n */\nexport const DEFAULT_MOUNT_PLAY_TRANSITION: Transition = {\n kind: \"tween\",\n duration_ms: 400,\n ease: \"cubic-out\",\n};\n\n/**\n * Resolve the transition a primitive should hand framer-motion.\n *\n * `keys` are the primitive's native animated prop keys, scanned in\n * order (e.g. `[\"opacity\", \"src\"]` for Image). When the node also\n * carries an `animate_initial`, the lookup widens to the keys the\n * mount-play actually moves (`from.scale` may have lowered a `scale`\n * transition that an opacity-only primitive would otherwise never look\n * up), and — critically — falls back to\n * `DEFAULT_MOUNT_PLAY_TRANSITION` instead of \"no animation\" : a\n * mount-play must tween, never complete in zero frames.\n *\n * Without `animate_initial` the prior behaviour is preserved exactly :\n * first declared transition among `keys`, else `undefined` (deltas\n * snap unless a transition is declared).\n */\nexport function resolveTransition(\n transitionFor: (key: string) => Transition | undefined,\n keys: string[],\n animateInitial?: Record<string, number | string>,\n): Transition | undefined {\n for (const key of keys) {\n const t = transitionFor(key);\n if (t !== undefined) return t;\n }\n if (animateInitial && Object.keys(animateInitial).length > 0) {\n for (const key of Object.keys(animateInitial)) {\n const t = transitionFor(key);\n if (t !== undefined) return t;\n }\n return DEFAULT_MOUNT_PLAY_TRANSITION;\n }\n return undefined;\n}\n\n/**\n * Build framer-motion `initial` / `animate` props for a primitive that\n * may carry an LSML 1.1 `animate.from` initial state.\n *\n * `base` is the primitive's own animated target (e.g. `{ opacity }` for\n * Image/Text/Shape, or `{ opacity, x, y, scale, rotate }` for Frame).\n * `initial` is the lowered `animate.from` map (or `undefined`).\n *\n * When `initial` is absent, this returns `{ initial: base, animate: base }`\n * — framer mounts at the target and never moves, exactly the prior\n * no-mount-play behaviour (backward compatible). When `initial` is\n * present, the element mounts at `initial` and animates to `base`,\n * augmented with identity convergence for any `from` key the primitive\n * doesn't already drive — so the mount-play plays out and settles\n * correctly even on opacity-only primitives.\n */\nexport function mountPlay(\n base: Record<string, number | string>,\n initial: Record<string, number | string> | undefined,\n): MountPlay {\n if (!initial || Object.keys(initial).length === 0) {\n // No `from` → mount directly at target. Pinning `initial` to the\n // target (rather than letting framer infer from current style)\n // preserves the existing \"no jump, no mount-play\" behaviour.\n return { initial: base, animate: base };\n }\n const animate: Record<string, number | string> = { ...base };\n for (const key of Object.keys(initial)) {\n if (!(key in animate)) {\n animate[key] = INITIAL_IDENTITY[key] ?? 0;\n }\n }\n return { initial, animate };\n}\n\n/**\n * Parse a wire-format `TransitionSpec` (LSDP/1.1 §3.2.2) into the\n * runtime's local Transition type. Returns `undefined` for malformed\n * input so the caller falls back to whatever bundle-level default\n * applies. The wire shape uses kebab-case `easing` values\n * (`linear`, `ease-in`, `ease-out`, `ease-in-out`) which we map to\n * the runtime's `cubic-*` vocabulary.\n */\nexport function parseWireTransition(value: unknown): Transition | undefined {\n if (typeof value !== \"object\" || value === null) return undefined;\n const v = value as Record<string, unknown>;\n const kind = v.kind;\n if (kind === \"snap\") {\n return { kind: \"none\" };\n }\n if (kind === \"tween\") {\n const duration_ms = typeof v.duration_ms === \"number\" ? v.duration_ms : 0;\n const easing = WIRE_EASING_MAP[v.easing as string] ?? \"cubic-out\";\n return { kind: \"tween\", duration_ms, ease: easing };\n }\n if (kind === \"spring\") {\n const out: SpringTransition = { kind: \"spring\" };\n if (typeof v.stiffness === \"number\") out.stiffness = v.stiffness;\n if (typeof v.damping === \"number\") out.damping = v.damping;\n return out;\n }\n return undefined;\n}\n\nconst WIRE_EASING_MAP: Record<string, \"linear\" | \"cubic-in\" | \"cubic-out\" | \"cubic-in-out\"> = {\n linear: \"linear\",\n \"ease-in\": \"cubic-in\",\n \"ease-out\": \"cubic-out\",\n \"ease-in-out\": \"cubic-in-out\",\n};\n","import { batch } from \"@preact/signals-react\";\nimport type { DeltaFrame } from \"@lumencast/protocol\";\nimport type { Store } from \"./store.js\";\nimport { parseWireTransition } from \"../animate/transitions\";\n\n/** Apply an LSDP/1 delta. All patches in the frame land in a single signals\n * batch — components reading multiple paths see them flip in one render pass.\n *\n * LSDP/1.1 §3.2.2 — a patch may carry a `transition` directive overriding\n * the bundle-level default for the next animation cycle on that leaf. We\n * thread it through the store so the renderer reads the correct directive\n * alongside the new value. */\nexport function applyDelta(store: Store, frame: DeltaFrame): void {\n batch(() => {\n for (const patch of frame.patches) {\n const transition = parseWireTransition(patch.transition);\n if (transition !== undefined) {\n store.setWithTransition(patch.path, patch.value, transition);\n } else {\n store.set(patch.path, patch.value);\n }\n }\n });\n}\n","import type { SnapshotFrame } from \"@lumencast/protocol\";\nimport type { Store } from \"./store.js\";\n\n/** Apply an LSDP/1 snapshot to the store. Replaces the entire state — paths\n * not present in the snapshot are reset to `undefined`. */\nexport function applySnapshot(store: Store, frame: SnapshotFrame): void {\n store.reset(frame.state);\n}\n","// State store — one signal per leaf path.\n//\n// Integration point between the WS layer (snapshot + delta) and the render\n// layer. Each path Lumencast has ever seen owns a `Signal<unknown>`;\n// readers subscribe via @preact/signals-react `useSignals()` and re-render\n// only when their path's value changes.\n//\n// LSDP/1.1 §3.2.2 — incoming deltas may carry a per-leaf `transition`\n// directive. The store keeps the most-recent directive per path so the\n// renderer can pick it up on the next animation cycle. Snapshots clear\n// any pending transitions for the affected paths (snapshots are not\n// animated transitions).\n\nimport { signal, type Signal, batch } from \"@preact/signals-react\";\nimport type { Transition } from \"../animate/transitions\";\n\nexport interface Store {\n /** Get-or-create the signal for a path. New paths start as `undefined`. */\n signal(path: string): Signal<unknown>;\n /** Apply a single leaf write. */\n set(path: string, value: unknown): void;\n /** Apply a single leaf write with an LSDP/1.1 §3.2.2 transition directive.\n * The directive lives in a separate signal so the renderer can subscribe\n * to it independently. Passing `undefined` clears any pending directive. */\n setWithTransition(path: string, value: unknown, transition: Transition | undefined): void;\n /** Read the most-recent transition directive for a path (or undefined\n * when no directive has been applied since the last snapshot). The\n * returned signal is reactive — components reading via `useSignals()`\n * re-render when the directive changes. */\n transitionSignal(path: string): Signal<Transition | undefined>;\n /**\n * Replace the whole state — used by `apply-snapshot`. Existing signals are\n * reused (subscribers stay attached); paths missing from the snapshot reset\n * to `undefined`. Pending per-path transitions are cleared (a snapshot is\n * a state restore, not an animated change).\n */\n reset(state: Record<string, unknown>): void;\n /** Snapshot of every known path → current value. For debug / state inspector. */\n toRecord(): Record<string, unknown>;\n}\n\nclass StoreImpl implements Store {\n private readonly signals = new Map<string, Signal<unknown>>();\n private readonly transitions = new Map<string, Signal<Transition | undefined>>();\n\n signal(path: string): Signal<unknown> {\n let s = this.signals.get(path);\n if (!s) {\n s = signal<unknown>(undefined);\n this.signals.set(path, s);\n }\n return s;\n }\n\n transitionSignal(path: string): Signal<Transition | undefined> {\n let s = this.transitions.get(path);\n if (!s) {\n s = signal<Transition | undefined>(undefined);\n this.transitions.set(path, s);\n }\n return s;\n }\n\n set(path: string, value: unknown): void {\n const s = this.signal(path);\n if (!shallowEqual(s.peek(), value)) {\n s.value = value;\n }\n }\n\n setWithTransition(path: string, value: unknown, transition: Transition | undefined): void {\n batch(() => {\n const ts = this.transitionSignal(path);\n // Update transition before value so the render that observes the\n // new value sees the correct transition.\n if (ts.peek() !== transition) ts.value = transition;\n const s = this.signal(path);\n if (!shallowEqual(s.peek(), value)) s.value = value;\n });\n }\n\n reset(state: Record<string, unknown>): void {\n batch(() => {\n const seen = new Set<string>();\n for (const [path, value] of Object.entries(state)) {\n seen.add(path);\n const s = this.signal(path);\n if (!shallowEqual(s.peek(), value)) {\n s.value = value;\n }\n // Snapshots are not animated transitions — clear any pending\n // per-path directive (LSDP/1.1 §3.2.2 — directives apply to\n // the NEXT delta only, snapshots reseed state authoritatively).\n const ts = this.transitions.get(path);\n if (ts && ts.peek() !== undefined) ts.value = undefined;\n }\n for (const path of this.signals.keys()) {\n if (!seen.has(path)) {\n const s = this.signals.get(path);\n if (s && s.peek() !== undefined) s.value = undefined;\n }\n }\n });\n }\n\n toRecord(): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const [path, s] of this.signals.entries()) {\n out[path] = s.peek();\n }\n return out;\n }\n}\n\nexport function createStore(): Store {\n return new StoreImpl();\n}\n\nfunction shallowEqual(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (a === null || b === null) return false;\n if (typeof a !== typeof b) return false;\n if (typeof a !== \"object\") return false;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n }\n const ao = a as Record<string, unknown>;\n const bo = b as Record<string, unknown>;\n const ak = Object.keys(ao);\n const bk = Object.keys(bo);\n if (ak.length !== bk.length) return false;\n for (const k of ak) {\n if (ao[k] !== bo[k]) return false;\n }\n return true;\n}\n","// Render bundle — the runtime's flat, pre-compiled representation of a scene.\n//\n// The bundle is content-addressed by `scene_version` (sha256 of the\n// canonical JSON form). Lumencast fetches it once per `scene_version` and\n// caches forever; the server serves it with long-TTL immutable cache headers.\n//\n// Note on shape: this `RenderBundle` is the flat, runtime-internal form. The\n// canonical *authoring* format (LSML 1.0, see lumencast-protocol/spec/LSML-1.md)\n// uses inline `bind: { value: \"path\" }` per primitive instead of a `bindings`\n// map. A compiler step (forthcoming `@lumencast/compiler`) will translate\n// LSML 1.0 → RenderBundle. For now, callers who want to feed an LSML 1.0\n// bundle pre-compile or use a hand-rolled adapter.\n\nimport type { Transition } from \"../animate/transitions.js\";\nimport type { Keyframes } from \"../animate/keyframes.js\";\n\n// --- bundle shape ----------------------------------------------------\n\nexport type RenderKind =\n | \"stack\"\n | \"grid\"\n | \"frame\"\n | \"text\"\n | \"image\"\n | \"shape\"\n | \"media\"\n | \"repeat\"\n | \"instance\";\n\nexport interface RenderNode {\n kind: RenderKind;\n /** Stable identifier for keyed reconciliation. */\n id?: string;\n /** Static props (frozen at build/compile time). */\n props?: Record<string, unknown>;\n /** Prop name → state path. The render layer subscribes the path's signal\n * and applies the value to the named prop on each change. */\n bindings?: Record<string, string>;\n /** Default transition per bound prop. Aligns with LSML 1.0 §6 `animate`\n * directives. The runtime applies these as CSS transitions / Framer Motion\n * configs at render time. */\n transitions?: Record<string, Transition>;\n /** LSML 1.1 §6 `animate.from` — mount-time initial state, lowered to a\n * flat framer-motion `initial` map (keys: `opacity`, `scale`, `rotate`,\n * `x`, `y`, `filter`). When present, the rendering primitive passes this\n * as framer-motion `initial={...}` so the element mounts in this state\n * and animates to its declared target on mount (mount-play). When absent,\n * the primitive applies no `initial` and the prior no-mount-play\n * behaviour holds (backward compatible). */\n animate_initial?: Record<string, number | string>;\n /** LSML 1.1 §6.6 — multi-step keyframe sequence played on mount or\n * whenever `keyframes.key` (LeafPath) changes. Coexists with\n * `transitions` ; the runtime applies whichever was last triggered\n * (no blending — see §6.6 last paragraph). */\n keyframes?: Keyframes;\n /** LSML 1.1 §6.7 — only meaningful on `repeat`. Each iteration's\n * animations start `index * stagger_ms` after iteration 0. */\n stagger_ms?: number;\n /** Children — already-inlined primitives only. */\n children?: RenderNode[];\n}\n\nexport type OperatorInputType =\n | \"boolean\"\n | \"number\"\n | \"text\"\n | \"select\"\n | \"enum\"\n | \"path-ref\"\n | \"colour\"\n | \"duration\";\n\nexport interface OperatorInput {\n path: string;\n label: string;\n type: OperatorInputType;\n default?: unknown;\n group?: string;\n writable_by?: string[];\n [extra: string]: unknown;\n}\n\nexport interface ExternalAdapter {\n key: string;\n label: string;\n kind: string;\n target_paths: string[];\n [extra: string]: unknown;\n}\n\nexport interface Asset {\n id: string;\n url: string;\n kind: string;\n [extra: string]: unknown;\n}\n\nexport interface RenderBundle {\n scene_version: string;\n root: RenderNode;\n operator_inputs?: OperatorInput[];\n external_adapters?: ExternalAdapter[];\n assets?: Asset[];\n /** LSML 1.1 §17.3 — capability profiles required for correct rendering.\n * Each entry is a `<vendor>.<name>-<version>` string. The runtime\n * checks every entry against its supported list ; an unrecognised\n * profile raises BUNDLE_INCOMPATIBLE per §17.3.1. */\n profiles?: string[];\n}\n\n/**\n * Profiles the JS runtime advertises support for. Bundle authors who\n * declare `profiles: [...]` get a hard `BUNDLE_INCOMPATIBLE` rejection\n * when any entry is not in this set (LSML 1.1 §17.3.1).\n *\n * 1.1 ships with no standard profiles ; future minors / vendor specs\n * register here. The `x-lumencast.color-srgb-1.0` entry is the\n * default-color-space marker ; bundles that opt into a perceptual\n * space (OKLCH) would request a different profile and currently\n * reject.\n */\nexport const SUPPORTED_PROFILES: ReadonlySet<string> = new Set<string>([\n \"x-lumencast.color-srgb-1.0\",\n]);\n\nexport class BundleIncompatibleError extends Error {\n public readonly code = \"BUNDLE_INCOMPATIBLE\" as const;\n public readonly unsupportedProfiles: string[];\n constructor(unsupportedProfiles: string[]) {\n super(\n `BUNDLE_INCOMPATIBLE: profile(s) not supported by this runtime: ${unsupportedProfiles.join(\n \", \",\n )}`,\n );\n this.name = \"BundleIncompatibleError\";\n this.unsupportedProfiles = unsupportedProfiles;\n }\n}\n\n/** Validate a bundle's `profiles[]` against the runtime's supported\n * set. Throws `BundleIncompatibleError` listing every offending entry\n * when at least one is not supported. */\nexport function validateBundleProfiles(\n bundle: { profiles?: string[] },\n supported: ReadonlySet<string> = SUPPORTED_PROFILES,\n): void {\n const profiles = bundle.profiles;\n if (!profiles || profiles.length === 0) return;\n const missing = profiles.filter((p) => !supported.has(p));\n if (missing.length > 0) {\n throw new BundleIncompatibleError(missing);\n }\n}\n\n// --- fetch + cache ---------------------------------------------------\n\nexport interface BundleFetcher {\n /** Fetch the bundle for a scene version. Cached forever by hash. */\n get(sceneId: string, sceneVersion: string): Promise<RenderBundle>;\n /** Inject a bundle directly — used by tests and for the \"scene already in\n * flight\" handoff path. */\n preload(bundle: RenderBundle): void;\n}\n\nexport interface BundleFetcherOptions {\n /** Base URL of the server. The fetcher constructs\n * `${baseUrl}/lsdp/v1/scenes/{id}/bundle?v={hash}`. */\n baseUrl: string;\n /** Path prefix for bundle resolution. Defaults to `/lsdp/v1/scenes`. */\n pathPrefix?: string;\n fetchImpl?: typeof fetch;\n}\n\nclass FetcherImpl implements BundleFetcher {\n private readonly cache = new Map<string, RenderBundle>();\n private readonly baseUrl: string;\n private readonly pathPrefix: string;\n private readonly fetchImpl: typeof fetch;\n\n constructor(opts: BundleFetcherOptions) {\n this.baseUrl = opts.baseUrl.replace(/\\/$/, \"\");\n this.pathPrefix = (opts.pathPrefix ?? \"/lsdp/v1/scenes\").replace(/\\/$/, \"\");\n this.fetchImpl = opts.fetchImpl ?? globalThis.fetch.bind(globalThis);\n }\n\n preload(bundle: RenderBundle): void {\n // LSML 1.1 §17.3.1 — reject early if any declared profile is\n // unsupported by this runtime. Authors get an actionable error\n // instead of a silent rendering glitch.\n validateBundleProfiles(bundle);\n this.cache.set(bundle.scene_version, bundle);\n }\n\n async get(sceneId: string, sceneVersion: string): Promise<RenderBundle> {\n const cached = this.cache.get(sceneVersion);\n if (cached) return cached;\n const url = `${this.baseUrl}${this.pathPrefix}/${encodeURIComponent(sceneId)}/bundle?v=${encodeURIComponent(sceneVersion)}`;\n const response = await this.fetchImpl(url);\n if (!response.ok) {\n throw new Error(`bundle fetch failed: ${response.status} ${response.statusText}`);\n }\n const json = (await response.json()) as RenderBundle;\n if (json.scene_version !== sceneVersion) {\n throw new Error(\n `bundle scene_version mismatch: expected ${sceneVersion}, got ${json.scene_version}`,\n );\n }\n validateBundleProfiles(json);\n this.cache.set(sceneVersion, json);\n return json;\n }\n}\n\nexport function createBundleFetcher(opts: BundleFetcherOptions): BundleFetcher {\n return new FetcherImpl(opts);\n}\n","// Exponential backoff schedule for the WS reconnect loop.\n//\n// Aggressive at first (200 ms, 400 ms, 800 ms…) then capped at 5 s so a\n// sustained outage doesn't hammer the gateway. Jittered to avoid thundering\n// herds when several Lumencast instances reconnect together (e.g. a CEF\n// host + a webview waking from suspend at the same time).\n//\n// The reference schedule in LSDP/1 §7 is \"0 ms, 500 ms, 1 s, 2 s, 4 s, 8 s,\n// 15 s, 30 s, 60 s cap\". This implementation defaults are tighter; both are\n// MAY-bounded by the spec.\n\nexport interface ReconnectScheduleOptions {\n /** First delay in milliseconds. */\n initial?: number;\n /** Maximum delay in milliseconds. */\n max?: number;\n /** Multiplicative factor between attempts (>= 1). */\n factor?: number;\n /** Jitter as a fraction of the delay (0 disables, 0.2 = ±20 %). */\n jitter?: number;\n /** Random source — only injected for tests. */\n random?: () => number;\n}\n\nconst DEFAULTS: Required<Omit<ReconnectScheduleOptions, \"random\">> = {\n initial: 200,\n max: 5_000,\n factor: 2,\n jitter: 0.2,\n};\n\nexport interface ReconnectSchedule {\n /** Returns the delay to wait before the n-th attempt (1-indexed). */\n delayFor(attempt: number): number;\n /** Reset to attempt 1 (called on a successful connection). */\n reset(): void;\n /** Current attempt counter. */\n readonly attempt: number;\n}\n\nclass ScheduleImpl implements ReconnectSchedule {\n private _attempt = 0;\n constructor(\n private readonly opts: Required<Omit<ReconnectScheduleOptions, \"random\">>,\n private readonly random: () => number,\n ) {}\n\n get attempt(): number {\n return this._attempt;\n }\n\n delayFor(attempt: number): number {\n if (!Number.isInteger(attempt) || attempt < 1) {\n throw new RangeError(`attempt must be a positive integer, got ${attempt}`);\n }\n this._attempt = attempt;\n const base = Math.min(\n this.opts.initial * Math.pow(this.opts.factor, attempt - 1),\n this.opts.max,\n );\n if (this.opts.jitter <= 0) return base;\n const offset = (this.random() * 2 - 1) * this.opts.jitter * base;\n return Math.max(0, base + offset);\n }\n\n reset(): void {\n this._attempt = 0;\n }\n}\n\nexport function createReconnectSchedule(opts: ReconnectScheduleOptions = {}): ReconnectSchedule {\n const merged = {\n initial: opts.initial ?? DEFAULTS.initial,\n max: opts.max ?? DEFAULTS.max,\n factor: opts.factor ?? DEFAULTS.factor,\n jitter: opts.jitter ?? DEFAULTS.jitter,\n };\n if (merged.initial <= 0) throw new RangeError(\"initial must be > 0\");\n if (merged.max < merged.initial) throw new RangeError(\"max must be >= initial\");\n if (merged.factor < 1) throw new RangeError(\"factor must be >= 1\");\n if (merged.jitter < 0 || merged.jitter > 1) throw new RangeError(\"jitter must be within [0, 1]\");\n return new ScheduleImpl(merged, opts.random ?? Math.random);\n}\n","// LSDP/1 WebSocket client.\n//\n// Lifecycle (LSDP/1 §6):\n// 1. open() — opens the WS with subprotocol `lsdp.v1`\n// 2. on open: send `subscribe` with the resolved token (and scene + session\n// for test mode)\n// 3. server replies `snapshot` (seq=1) → emit onSnapshot\n// 4. subsequent `delta` / `scene_changed` / `error` / `pong` are dispatched\n// 5. on a sequence gap → close + reconnect (fresh snapshot)\n// 6. on close → reconnect with backoff, unless close was triggered by close()\n// 7. setToken() opens a parallel WS with the new token; once its snapshot\n// lands, atomically swap and close the old socket — no rendering gap\n\nimport {\n decodeServerFrame,\n encodeFrame,\n LumencastError,\n SequenceTracker,\n WS_SUBPROTOCOL_V1_1,\n WS_SUBPROTOCOLS,\n input as inputFrame,\n subscribe as subscribeFrame,\n type DeltaFrame,\n type ErrorCode,\n type ErrorFrame,\n type Patch,\n type SceneChangedFrame,\n type SnapshotFrame,\n} from \"@lumencast/protocol\";\nimport type { LumencastToken } from \"../types.js\";\nimport {\n createReconnectSchedule,\n type ReconnectSchedule,\n type ReconnectScheduleOptions,\n} from \"./reconnect.js\";\n\nexport type ConnectionStatus = \"disconnected\" | \"connecting\" | \"live\";\n\nexport interface WsClientOptions {\n url: string;\n token: LumencastToken;\n /** Optional scene identifier (test mode). */\n scene?: string;\n /** Optional session identifier (test mode). */\n session?: string;\n /** Override the WebSocket constructor (for tests / non-browser hosts). */\n webSocketImpl?: typeof WebSocket;\n /** Reconnect tuning. */\n reconnect?: ReconnectScheduleOptions;\n /** Inject scheduler for tests. */\n scheduler?: {\n setTimeout: typeof globalThis.setTimeout;\n clearTimeout: typeof globalThis.clearTimeout;\n };\n\n onStatus?: (status: ConnectionStatus) => void;\n onSnapshot?: (frame: SnapshotFrame) => void;\n onDelta?: (frame: DeltaFrame) => void;\n onSceneChanged?: (frame: SceneChangedFrame) => void;\n onServerError?: (frame: ErrorFrame) => void;\n /** Wire-level / codec / unrecoverable errors. */\n onTransportError?: (err: TransportError) => void;\n}\n\nexport class TransportError extends Error {\n public readonly recoverable: boolean;\n public readonly code: ErrorCode;\n public override readonly cause?: unknown;\n constructor(\n message: string,\n recoverable: boolean,\n code: ErrorCode = \"INTERNAL\",\n cause?: unknown,\n ) {\n super(message);\n this.name = \"TransportError\";\n this.recoverable = recoverable;\n this.code = code;\n this.cause = cause;\n }\n}\n\ntype Timer = ReturnType<typeof setTimeout>;\n\ninterface InternalScheduler {\n setTimeout: typeof globalThis.setTimeout;\n clearTimeout: typeof globalThis.clearTimeout;\n}\n\nexport class WsClient {\n private status: ConnectionStatus = \"disconnected\";\n private socket: WebSocket | null = null;\n private token: LumencastToken;\n private readonly url: string;\n private readonly WebSocketCtor: typeof WebSocket;\n private readonly schedule: ReconnectSchedule;\n private readonly seq = new SequenceTracker();\n private readonly opts: WsClientOptions;\n private readonly scheduler: InternalScheduler;\n\n private reconnectTimer: Timer | null = null;\n private active = true;\n\n constructor(opts: WsClientOptions) {\n this.opts = opts;\n this.url = opts.url;\n this.token = opts.token;\n const ctor = opts.webSocketImpl ?? globalThis.WebSocket;\n if (!ctor) {\n throw new TypeError(\n \"Lumencast WsClient: no WebSocket implementation found in this environment\",\n );\n }\n this.WebSocketCtor = ctor;\n this.schedule = createReconnectSchedule(opts.reconnect);\n this.scheduler = opts.scheduler ?? {\n setTimeout: globalThis.setTimeout.bind(globalThis),\n clearTimeout: globalThis.clearTimeout.bind(globalThis),\n };\n }\n\n /** Open and start the connection lifecycle. Idempotent. */\n start(): void {\n if (!this.active) return;\n if (this.socket || this.status === \"connecting\") return;\n void this.openSocket();\n }\n\n /** Send `input` patches to the server. No-op if not connected. */\n sendInput(patches: Patch[]): void {\n if (!this.socket || this.socket.readyState !== this.WebSocketCtor.OPEN) return;\n if (patches.length === 0) return;\n this.socket.send(encodeFrame(inputFrame(patches)));\n }\n\n /** Replace the auth token. Closes and reopens with the new token. */\n setToken(token: LumencastToken): void {\n this.token = token;\n if (!this.active) return;\n if (this.socket) {\n this.closeSocket();\n this.scheduleReconnect(true);\n }\n }\n\n /** Tear down for good. No more reconnect attempts. */\n close(): void {\n if (!this.active) return;\n this.active = false;\n this.cancelReconnect();\n this.closeSocket();\n this.setStatus(\"disconnected\");\n }\n\n // --- internals --------------------------------------------------\n\n private async openSocket(): Promise<void> {\n if (!this.active) return;\n this.setStatus(\"connecting\");\n\n let resolvedToken: string;\n try {\n resolvedToken = await resolveToken(this.token);\n } catch (err) {\n this.opts.onTransportError?.(\n new TransportError(\n `failed to resolve token: ${(err as Error).message}`,\n true,\n \"AUTH_DENIED\",\n err,\n ),\n );\n this.scheduleReconnect();\n return;\n }\n if (!this.active) return;\n\n let socket: WebSocket;\n try {\n // Advertise both 1.1 (preferred) and 1.0 (fallback) ; the server\n // picks one. Spread to a mutable array — the WebSocket constructor\n // type expects string[].\n socket = new this.WebSocketCtor(this.url, [...WS_SUBPROTOCOLS]);\n } catch (err) {\n this.opts.onTransportError?.(\n new TransportError(\n `failed to open WebSocket: ${(err as Error).message}`,\n true,\n \"INTERNAL\",\n err,\n ),\n );\n this.scheduleReconnect();\n return;\n }\n\n this.socket = socket;\n socket.onopen = () => this.handleOpen(resolvedToken);\n socket.onmessage = (event) => this.handleMessage(event);\n socket.onerror = (event) => this.handleError(event);\n socket.onclose = (event) => this.handleClose(event);\n }\n\n private handleOpen(token: string): void {\n if (!this.socket) return;\n // LSDP/1.1 §4.1, §18 — if we have a previously-observed seq AND the\n // negotiated subprotocol is 1.1, request an incremental resume.\n // The server will EITHER ship buffered deltas (cache stays valid)\n // OR a fresh snapshot which we rebase via observeSnapshot.\n const subprotocol = this.socket.protocol;\n const canResume = subprotocol === WS_SUBPROTOCOL_V1_1 && this.seq.last > 0;\n const sinceSequence = canResume ? this.seq.last : undefined;\n if (!canResume) {\n // Fresh subscription (no resume) — reset the tracker baseline.\n this.seq.reset();\n }\n const frame = subscribeFrame({\n token,\n ...(this.opts.scene !== undefined ? { scene: this.opts.scene } : {}),\n ...(this.opts.session !== undefined ? { session: this.opts.session } : {}),\n ...(sinceSequence !== undefined ? { since_sequence: sinceSequence } : {}),\n });\n this.socket.send(encodeFrame(frame));\n }\n\n private handleMessage(event: MessageEvent): void {\n const data = typeof event.data === \"string\" ? event.data : \"\";\n if (!data) return;\n let frame;\n try {\n frame = decodeServerFrame(data);\n } catch (err) {\n const message = err instanceof LumencastError ? err.message : (err as Error).message;\n const code: ErrorCode = err instanceof LumencastError ? err.code : \"INTERNAL\";\n this.opts.onTransportError?.(new TransportError(`codec: ${message}`, true, code, err));\n this.closeSocket();\n this.scheduleReconnect();\n return;\n }\n if (frame === null) return; // unknown frame type — forward-compat ignore\n\n switch (frame.type) {\n case \"snapshot\": {\n // LSDP/1.1 §18.1.1 — snapshot rebases the tracker to its seq\n // value. This is the ONLY valid way to set or change the\n // tracker's baseline (handles fresh sub, scene_changed, and\n // back-pressure recovery uniformly).\n if (frame.seq < 1) {\n this.opts.onTransportError?.(\n new TransportError(`snapshot seq must be >= 1, got ${frame.seq}`, true, \"VERSION_GAP\"),\n );\n this.closeSocket();\n this.scheduleReconnect();\n return;\n }\n this.seq.observeSnapshot(frame.seq);\n this.schedule.reset();\n this.setStatus(\"live\");\n this.opts.onSnapshot?.(frame);\n return;\n }\n case \"delta\": {\n const obs = this.seq.observe(frame.seq);\n if (obs.kind === \"gap\") {\n this.opts.onTransportError?.(\n new TransportError(\n `sequence gap: expected ${this.seq.last + 1}, got ${frame.seq}`,\n true,\n \"VERSION_GAP\",\n ),\n );\n this.closeSocket();\n this.scheduleReconnect();\n return;\n }\n if (obs.kind === \"duplicate\") return; // silent drop per LSDP/1 §5\n this.opts.onDelta?.(frame);\n return;\n }\n case \"scene_changed\": {\n // The next snapshot will rebase the tracker via observeSnapshot.\n // Reset here so the tracker doesn't fault on the SceneChanged's\n // own seq (which advances prev's counter one final step).\n this.seq.reset();\n this.opts.onSceneChanged?.(frame);\n return;\n }\n case \"error\": {\n this.opts.onServerError?.(frame);\n if (!frame.recoverable) this.close();\n return;\n }\n case \"pong\":\n return;\n }\n }\n\n private handleError(_event: Event): void {\n // The browser does not give us a real reason — `close` will follow.\n }\n\n private handleClose(event: CloseEvent): void {\n this.socket = null;\n if (!this.active) {\n this.setStatus(\"disconnected\");\n return;\n }\n if (event.code === 4401 || event.code === 4403 || event.code === 1008) {\n // Auth-related close codes: not recoverable without operator intervention.\n this.opts.onTransportError?.(\n new TransportError(`server closed: ${event.code} ${event.reason}`, false, \"AUTH_DENIED\"),\n );\n this.close();\n return;\n }\n this.scheduleReconnect();\n }\n\n private scheduleReconnect(immediate = false): void {\n if (!this.active) return;\n this.cancelReconnect();\n const attempt = (this.schedule.attempt || 0) + 1;\n const delay = immediate ? 0 : this.schedule.delayFor(attempt);\n this.setStatus(\"disconnected\");\n this.reconnectTimer = this.scheduler.setTimeout(() => {\n this.reconnectTimer = null;\n void this.openSocket();\n }, delay);\n }\n\n private cancelReconnect(): void {\n if (this.reconnectTimer) {\n this.scheduler.clearTimeout(this.reconnectTimer);\n this.reconnectTimer = null;\n }\n }\n\n private closeSocket(): void {\n if (this.socket) {\n try {\n this.socket.close(1000, \"client closing\");\n } catch {\n // ignore\n }\n this.socket = null;\n }\n }\n\n private setStatus(next: ConnectionStatus): void {\n if (this.status === next) return;\n this.status = next;\n this.opts.onStatus?.(next);\n }\n}\n\nasync function resolveToken(token: LumencastToken): Promise<string> {\n if (typeof token === \"string\") return token;\n return await token.fetch();\n}\n","import type { MountOptions } from \"../types\";\n\n/** Throws on invalid mount options. Exposed separately so unit tests\n * can exercise it without mounting a real React root. */\nexport function validateOptions(options: MountOptions): void {\n if (!(options.target instanceof HTMLElement)) {\n throw new TypeError(\"mount: `target` must be an HTMLElement\");\n }\n if (typeof options.serverUrl !== \"string\" || options.serverUrl.length === 0) {\n throw new TypeError(\"mount: `serverUrl` must be a non-empty string\");\n }\n if (options.mode === \"test\") {\n if (!options.testSession) {\n throw new TypeError(\"mount: `testSession` is required when mode === 'test'\");\n }\n if (!options.scene) {\n throw new TypeError(\"mount: `scene` is required when mode === 'test'\");\n }\n }\n}\n","// Public mount() entry — the only surface a host (browser, CEF, OBS plugin,\n// iframe) interacts with. Lifecycle and contract: see RUNTIME-API.md.\n\nimport { signal } from \"@preact/signals-react\";\nimport { createRoot, type Root } from \"react-dom/client\";\nimport { createElement } from \"react\";\nimport { LumencastApp } from \"./app.js\";\nimport { applyDelta } from \"./state/apply-delta.js\";\nimport { applySnapshot } from \"./state/apply-snapshot.js\";\nimport { createStore } from \"./state/store.js\";\nimport { createBundleFetcher, type BundleFetcher, type RenderBundle } from \"./render/bundle.js\";\nimport { WsClient, type ConnectionStatus, type TransportError } from \"./transport/ws.js\";\nimport { validateOptions } from \"./internal/validate-options.js\";\nimport type { LumencastError, LumencastHandle, LumencastToken, MountOptions } from \"./types.js\";\n\nexport function mount(options: MountOptions): LumencastHandle {\n validateOptions(options);\n options.onStatus?.(\"disconnected\");\n\n const store = createStore();\n const baseUrl = deriveBaseUrl(options.serverUrl);\n const bundleFetcher = createBundleFetcher({ baseUrl });\n\n const bundleSignal = signal<RenderBundle | null>(null);\n const statusSignal = signal<ConnectionStatus>(\"disconnected\");\n const crossfadeKeySignal = signal<string>(\"__initial__\");\n\n const setStatus = (status: ConnectionStatus): void => {\n statusSignal.value = status;\n options.onStatus?.(status);\n };\n\n const reportError = (err: LumencastError): void => {\n options.onError?.(err);\n };\n\n let active = true;\n\n const ws = new WsClient({\n url: options.serverUrl,\n token: options.token,\n ...(options.scene !== undefined ? { scene: options.scene } : {}),\n ...(options.testSession !== undefined ? { session: options.testSession } : {}),\n onStatus: setStatus,\n onSnapshot: (frame) => {\n if (!active) return;\n void onSnapshot(\n bundleFetcher,\n bundleSignal,\n crossfadeKeySignal,\n frame.scene_id,\n frame.scene_version,\n () => applySnapshot(store, frame),\n reportError,\n );\n options.onMetric?.({\n name: \"snapshot_received\",\n scene_id: frame.scene_id,\n path_count: Object.keys(frame.state).length,\n });\n },\n onDelta: (frame) => {\n if (!active) return;\n const start = performance.now();\n applyDelta(store, frame);\n options.onMetric?.({\n name: \"delta_applied\",\n duration_ms: performance.now() - start,\n });\n options.onMetric?.({ name: \"delta_received\", count: 1, path_count: frame.patches.length });\n },\n onSceneChanged: (frame) => {\n if (!active) return;\n // The fresh snapshot that follows is the source of truth — it carries\n // the new scene_version, drives the bundle fetch, and flips the\n // crossfade key. Nothing eager to do here.\n options.onMetric?.({\n name: \"scene_changed\",\n from: bundleSignal.value?.scene_version ?? null,\n to: frame.scene_version,\n });\n },\n onServerError: (frame) => {\n reportError({\n code: frame.code,\n message: frame.message,\n recoverable: frame.recoverable,\n });\n },\n onTransportError: (err) => {\n reportError(transportToLumencastError(err));\n },\n });\n\n ws.start();\n\n const root: Root = createRoot(options.target);\n root.render(\n createElement(LumencastApp, {\n mode: options.mode,\n store,\n bundleSignal,\n statusSignal,\n crossfadeKeySignal,\n sendInput: (patches) => ws.sendInput(patches),\n }),\n );\n\n return {\n disconnect() {\n if (!active) return;\n active = false;\n ws.close();\n root.unmount();\n },\n setToken(token: LumencastToken) {\n if (!active) return;\n ws.setToken(token);\n },\n };\n\n // --- helpers ----------------------------------------------------------\n\n async function onSnapshot(\n fetcher: BundleFetcher,\n bSignal: typeof bundleSignal,\n cSignal: typeof crossfadeKeySignal,\n sceneId: string,\n sceneVersion: string,\n applyState: () => void,\n onErr: (err: LumencastError) => void,\n ): Promise<void> {\n let bundle: RenderBundle;\n try {\n bundle = await fetcher.get(sceneId, sceneVersion);\n } catch (err) {\n onErr({\n code: \"BUNDLE_FETCH_FAILED\",\n message: err instanceof Error ? err.message : \"render bundle fetch failed\",\n recoverable: true,\n });\n return;\n }\n if (!active) return;\n applyState();\n bSignal.value = bundle;\n cSignal.value = `${sceneId}::${sceneVersion}`;\n }\n}\n\nfunction transportToLumencastError(err: TransportError): LumencastError {\n return {\n code: err.code,\n message: err.message,\n recoverable: err.recoverable,\n };\n}\n\nfunction deriveBaseUrl(wsUrl: string): string {\n // wss://<host>/lsdp/v1 → https://<host>\n // ws://<host>/lsdp/v1 → http://<host>\n try {\n const u = new URL(wsUrl);\n const httpScheme = u.protocol === \"wss:\" ? \"https:\" : \"http:\";\n return `${httpScheme}//${u.host}`;\n } catch {\n return \"\";\n }\n}\n"],"names":["Ctx","createContext","LumencastRuntimeProvider","value","children","jsx","useLumencastRuntime","v","useContext","LazyBroadcastMode","lazy","m","LazyControlMode","LazyTestMode","LumencastApp","mode","store","bundleSignal","statusSignal","crossfadeKeySignal","sendInput","useSignals","bundle","status","trackKey","ModeComponent","AnimatePresence","motion","Suspense","NO_ANIMATION","EASE_MAP","toFramer","INITIAL_IDENTITY","DEFAULT_MOUNT_PLAY_TRANSITION","resolveTransition","transitionFor","keys","animateInitial","key","t","mountPlay","base","initial","animate","parseWireTransition","kind","duration_ms","easing","WIRE_EASING_MAP","out","applyDelta","frame","batch","patch","transition","applySnapshot","StoreImpl","path","signal","s","shallowEqual","ts","state","seen","createStore","a","b","ao","bo","ak","bk","k","SUPPORTED_PROFILES","BundleIncompatibleError","unsupportedProfiles","validateBundleProfiles","supported","profiles","missing","p","FetcherImpl","opts","sceneId","sceneVersion","cached","url","response","json","createBundleFetcher","DEFAULTS","ScheduleImpl","random","attempt","offset","createReconnectSchedule","merged","TransportError","message","recoverable","code","cause","WsClient","SequenceTracker","ctor","patches","encodeFrame","inputFrame","token","resolvedToken","resolveToken","err","socket","WS_SUBPROTOCOLS","event","canResume","WS_SUBPROTOCOL_V1_1","sinceSequence","subscribeFrame","data","decodeServerFrame","LumencastError","obs","_event","immediate","delay","next","validateOptions","options","mount","baseUrl","deriveBaseUrl","bundleFetcher","setStatus","reportError","active","ws","onSnapshot","start","transportToLumencastError","root","createRoot","createElement","fetcher","bSignal","cSignal","applyState","onErr","wsUrl","u"],"mappings":";;;;;;;AAgBA,MAAMA,IAAMC,EAAuC,IAAI;AAEhD,SAASC,EAAyB;AAAA,EACvC,OAAAC;AAAA,EACA,UAAAC;AACF,GAGG;AACD,SAAO,gBAAAC,EAACL,EAAI,UAAJ,EAAa,OAAAG,GAAe,UAAAC,EAAA,CAAS;AAC/C;AAEO,SAASE,KAAwC;AACtD,QAAMC,IAAIC,EAAWR,CAAG;AACxB,MAAI,CAACO;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAGJ,SAAOA;AACT;ACdA,MAAME,IAAoBC;AAAA,EAAK,MAC7B,OAAO,yBAAsB,EAAE,KAAK,CAACC,OAAO,EAAE,SAASA,EAAE,gBAAgB;AAC3E,GACMC,IAAkBF;AAAA,EAAK,MAC3B,OAAO,uBAAoB,EAAE,KAAK,CAACC,OAAO,EAAE,SAASA,EAAE,cAAc;AACvE,GACME,IAAeH,EAAK,MAAM,OAAO,oBAAiB,EAAE,KAAK,CAACC,OAAO,EAAE,SAASA,EAAE,SAAA,EAAW,CAAC;AAWzF,SAASG,EAAa;AAAA,EAC3B,MAAAC;AAAA,EACA,OAAAC;AAAA,EACA,cAAAC;AAAA,EACA,cAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,WAAAC;AACF,GAAsB;AACpB,EAAAC,EAAA;AAEA,QAAMC,IAASL,EAAa,OACtBM,IAASL,EAAa,OACtBM,IAAWL,EAAmB;AACpC,MAAI,CAACG,EAAQ,QAAO;AAEpB,QAAMG,IACJV,MAAS,cAAcN,IAAoBM,MAAS,YAAYH,IAAkBC;AAEpF,SACE,gBAAAR,EAACqB,GAAA,EAAgB,MAAK,QACpB,UAAA,gBAAArB;AAAA,IAACsB,EAAO;AAAA,IAAP;AAAA,MAEC,SAAS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ACjC,QAAQ;AACN,WAAO;AAAA,EACT;AACF;"}
package/dist/index.html CHANGED
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
- <meta name="generator" content="@lumencast/runtime 0.2.0" />
6
+ <meta name="generator" content="@lumencast/runtime 0.4.0" />
7
7
  <title>Lumencast</title>
8
8
  <style>
9
9
  html, body { margin: 0; padding: 0; height: 100%; background: #000; }
package/dist/lumencast.js CHANGED
@@ -1,5 +1,5 @@
1
- import { m as r } from "./index-X6EOQGho.js";
1
+ import { a as m } from "./index-oteiocFe.js";
2
2
  export {
3
- r as mount
3
+ m as mount
4
4
  };
5
5
  //# sourceMappingURL=lumencast.js.map
@@ -14,6 +14,14 @@ export interface RenderNode {
14
14
  * directives. The runtime applies these as CSS transitions / Framer Motion
15
15
  * configs at render time. */
16
16
  transitions?: Record<string, Transition>;
17
+ /** LSML 1.1 §6 `animate.from` — mount-time initial state, lowered to a
18
+ * flat framer-motion `initial` map (keys: `opacity`, `scale`, `rotate`,
19
+ * `x`, `y`, `filter`). When present, the rendering primitive passes this
20
+ * as framer-motion `initial={...}` so the element mounts in this state
21
+ * and animates to its declared target on mount (mount-play). When absent,
22
+ * the primitive applies no `initial` and the prior no-mount-play
23
+ * behaviour holds (backward compatible). */
24
+ animate_initial?: Record<string, number | string>;
17
25
  /** LSML 1.1 §6.6 — multi-step keyframe sequence played on mount or
18
26
  * whenever `keyframes.key` (LeafPath) changes. Coexists with
19
27
  * `transitions` ; the runtime applies whichever was last triggered
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/render/bundle.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAIzD,MAAM,MAAM,UAAU,GAClB,OAAO,GACP,MAAM,GACN,OA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