@uptimizr/replay 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/AGENTS.md +57 -0
  2. package/LICENSE +201 -0
  3. package/README.md +96 -0
  4. package/dist/drivers/babylon-lite.d.ts +134 -0
  5. package/dist/drivers/babylon-lite.d.ts.map +1 -0
  6. package/dist/drivers/babylon-lite.js +167 -0
  7. package/dist/drivers/babylon-lite.js.map +1 -0
  8. package/dist/drivers/babylon.d.ts +99 -0
  9. package/dist/drivers/babylon.d.ts.map +1 -0
  10. package/dist/drivers/babylon.js +176 -0
  11. package/dist/drivers/babylon.js.map +1 -0
  12. package/dist/drivers/playcanvas.d.ts +122 -0
  13. package/dist/drivers/playcanvas.d.ts.map +1 -0
  14. package/dist/drivers/playcanvas.js +206 -0
  15. package/dist/drivers/playcanvas.js.map +1 -0
  16. package/dist/drivers/three.d.ts +127 -0
  17. package/dist/drivers/three.d.ts.map +1 -0
  18. package/dist/drivers/three.js +194 -0
  19. package/dist/drivers/three.js.map +1 -0
  20. package/dist/fetchSession.d.ts +43 -0
  21. package/dist/fetchSession.d.ts.map +1 -0
  22. package/dist/fetchSession.js +103 -0
  23. package/dist/fetchSession.js.map +1 -0
  24. package/dist/global.d.ts +62 -0
  25. package/dist/global.d.ts.map +1 -0
  26. package/dist/global.js +95 -0
  27. package/dist/global.js.map +1 -0
  28. package/dist/index.d.ts +14 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +11 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/player.d.ts +35 -0
  33. package/dist/player.d.ts.map +1 -0
  34. package/dist/player.js +104 -0
  35. package/dist/player.js.map +1 -0
  36. package/dist/reconstruct.d.ts +74 -0
  37. package/dist/reconstruct.d.ts.map +1 -0
  38. package/dist/reconstruct.js +266 -0
  39. package/dist/reconstruct.js.map +1 -0
  40. package/dist/types.d.ts +39 -0
  41. package/dist/types.d.ts.map +1 -0
  42. package/dist/types.js +2 -0
  43. package/dist/types.js.map +1 -0
  44. package/dist/uptimizr-replay.global.js +71 -0
  45. package/llms.txt +17 -0
  46. package/package.json +100 -0
package/AGENTS.md ADDED
@@ -0,0 +1,57 @@
1
+ # AGENTS.md — @uptimizr/replay
2
+
3
+ > Packaged agent guide. For the human reference see [README.md](./README.md); for design
4
+ > rationale see the project ADRs at https://github.com/RaananW/Uptimizr/tree/main/docs/adr.
5
+
6
+ ## What this package is
7
+
8
+ Re-drives a captured session in the framework user's **own** 3D scene (ADR 0006). Because the
9
+ event schema is replay-complete, the same ordered stream that powers analytics reconstructs the
10
+ session: camera pose, pointer travel, and picks. The core is framework-agnostic; engine drivers
11
+ live behind subpaths. A replay driver only reads/writes the scene — it **never emits analytics**.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pnpm add @uptimizr/replay
17
+ # @babylonjs/core is an optional peer dependency — only for the Babylon driver.
18
+ ```
19
+
20
+ ## Canonical usage
21
+
22
+ ```ts
23
+ import { ReplayPlayer, fetchSessionEvents } from "@uptimizr/replay";
24
+ import { createBabylonReplayDriver } from "@uptimizr/replay/babylon";
25
+
26
+ const events = await fetchSessionEvents({
27
+ endpoint: "https://collect.example.com",
28
+ apiKey: "utk_…",
29
+ sessionId: "…",
30
+ });
31
+
32
+ const driver = createBabylonReplayDriver({
33
+ scene,
34
+ onPointer: (screen, hitPoint, hitMesh) => {
35
+ /* render a pointer marker */
36
+ },
37
+ });
38
+
39
+ const player = new ReplayPlayer(events, driver, { speed: 1, onComplete: () => {} });
40
+ player.play(); // play / pause / seek(ms) / stop
41
+ ```
42
+
43
+ The replay endpoint requires `ENABLE_RAW_SESSION_RETENTION` on the collector.
44
+
45
+ ## Rules for agents
46
+
47
+ - Replay is **read-only** on the data side: a driver must never emit analytics events (ADR 0006).
48
+ - `ReplayPlayer` is driven by a pure `update(elapsedMs)`; seeking backward resets the driver and
49
+ replays from the start, so playback stays deterministic — preserve this contract.
50
+ - To support another engine, implement the `ReplayDriver` `{ reset, apply }` interface and pass it
51
+ to `ReplayPlayer`.
52
+ - Treat `@babylonjs/core` as an optional peer dependency.
53
+
54
+ ## More
55
+
56
+ - Package reference: [README.md](./README.md)
57
+ - Integration guide: https://github.com/RaananW/Uptimizr/blob/main/docs/integration.md
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and do
117
+ not modify the License. You may add Your own attribution notices
118
+ within Derivative Works that You distribute, alongside or as an
119
+ addendum to the NOTICE text from the Work, provided that such
120
+ additional attribution notices cannot be construed as modifying
121
+ the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions for
125
+ use, reproduction, or distribution of Your modifications, or for any
126
+ such Derivative Works as a whole, provided Your use, reproduction,
127
+ and distribution of the Work otherwise complies with the conditions
128
+ stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Uptimizr Contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # @uptimizr/replay
2
+
3
+ Re-drive a captured session in the framework user's **own** 3D scene.
4
+ The event schema is replay-complete, so the same ordered stream that powers
5
+ analytics also reconstructs the session: camera pose, pointer travel, and picks.
6
+
7
+ The core is **framework-agnostic**; engine drivers live behind subpaths. A replay
8
+ driver only reads/writes the scene — it **never emits analytics events**.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @uptimizr/replay
14
+ # Plus the engine you replay into (optional peer deps), e.g. Babylon:
15
+ npm install @babylonjs/core
16
+ ```
17
+
18
+ The engine packages (`@babylonjs/core`, `@babylonjs/lite`, `three`, `playcanvas`)
19
+ are **optional peer dependencies** — install only the driver(s) you use. Replay is
20
+ a developer/debug tool and never emits analytics.
21
+
22
+ ## Usage
23
+
24
+ ```ts
25
+ import { ReplayPlayer, fetchSessionEvents } from "@uptimizr/replay";
26
+ import { createBabylonReplayDriver } from "@uptimizr/replay/babylon";
27
+
28
+ const events = await fetchSessionEvents({
29
+ endpoint: "https://collect.example.com",
30
+ apiKey: "utk_…",
31
+ sessionId: "…",
32
+ });
33
+
34
+ const driver = createBabylonReplayDriver({
35
+ scene,
36
+ onPointer: (screen, hitPoint, hitMesh) => {
37
+ /* render a pointer marker */
38
+ },
39
+ });
40
+
41
+ const player = new ReplayPlayer(events, driver, { speed: 1, onComplete: () => {} });
42
+ player.play(); // play / pause / seek(ms) / stop
43
+ ```
44
+
45
+ ### three.js
46
+
47
+ The three driver lives at `@uptimizr/replay/three`. three has no
48
+ `scene.activeCamera`, so the `camera` is an explicit option:
49
+
50
+ ```ts
51
+ import { ReplayPlayer, fetchSessionEvents } from "@uptimizr/replay";
52
+ import { createThreeReplayDriver } from "@uptimizr/replay/three";
53
+
54
+ const events = await fetchSessionEvents({ endpoint, apiKey, sessionId });
55
+
56
+ const driver = createThreeReplayDriver({
57
+ scene,
58
+ camera, // required — three has no scene.activeCamera
59
+ onPointer: (screen, hitPoint, hitMesh, type) => {
60
+ /* render a pointer marker */
61
+ },
62
+ });
63
+
64
+ new ReplayPlayer(events, driver, { speed: 1 }).play();
65
+ ```
66
+
67
+ Canonical (left-handed) world data is converted back to three's right-handed
68
+ frame, and camera orientation is applied via `camera.lookAt(target)` so three
69
+ resolves its −Z-forward convention internally. `three` is an **optional peer
70
+ dependency** — only needed if you use the three driver.
71
+
72
+ The replay endpoint requires `ENABLE_RAW_SESSION_RETENTION` on the collector.
73
+
74
+ ## Design
75
+
76
+ - `ReplayPlayer` is driven by a pure `update(elapsedMs)`; `play()` just ticks it
77
+ from an animation loop. Seeking backward resets the driver and replays from the
78
+ start, so playback is deterministic.
79
+ - `ReplayDriver` is the engine extension point: implement `{ reset, apply }` for
80
+ another engine and pass it to `ReplayPlayer`. Babylon (`@uptimizr/replay/babylon`)
81
+ and three.js (`@uptimizr/replay/three`) drivers ship in the box.
82
+
83
+ `@babylonjs/core` and `three` are both **optional peer dependencies** — you only
84
+ need the one whose driver you import.
85
+
86
+ ## Develop
87
+
88
+ ```bash
89
+ pnpm --filter @uptimizr/replay build
90
+ pnpm --filter @uptimizr/replay typecheck
91
+ pnpm --filter @uptimizr/replay test
92
+ ```
93
+
94
+ ## License
95
+
96
+ [Apache-2.0](./LICENSE) © Uptimizr.
@@ -0,0 +1,134 @@
1
+ import type { CustomPropValue } from "@uptimizr/schema";
2
+ import type { ReplayDriver } from "../types.js";
3
+ /**
4
+ * Structural view of the Babylon Lite `ArcRotateCamera` this driver re-drives.
5
+ * Kept minimal and structural so `@babylonjs/lite` stays an **optional peer
6
+ * dependency** — the driver never imports Lite at runtime; the host page owns the
7
+ * camera. Lite's `ArcRotateCamera` recomputes its world matrix from
8
+ * `alpha`/`beta`/`radius`/`target` each frame, so those are the source of truth
9
+ * (there is no settable world `position`).
10
+ */
11
+ interface LiteReplayArcCamera {
12
+ alpha: number;
13
+ beta: number;
14
+ radius: number;
15
+ target: {
16
+ x: number;
17
+ y: number;
18
+ z: number;
19
+ };
20
+ /** Vertical FOV in **radians** (Lite convention — matches the canonical wire). */
21
+ fov?: number;
22
+ }
23
+ /** A Babylon Lite node a replay can drive (a `TransformNode`/mesh). */
24
+ export type BabylonLiteReplayNode = object;
25
+ export interface BabylonLiteReplayDriverOptions {
26
+ /**
27
+ * Camera to move. Re-driving requires a Lite `ArcRotateCamera` (it exposes
28
+ * settable orbit state); other cameras have no settable world pose, so their
29
+ * `camera_sample` pose is skipped (other events still forward).
30
+ */
31
+ camera: LiteReplayArcCamera | {
32
+ [key: string]: unknown;
33
+ };
34
+ /** Called for each replayed pointer event, so the host can render a marker. */
35
+ onPointer?: (screen: [number, number] | undefined, hitPoint: [number, number, number] | undefined, hitMesh: string | undefined, type: "pointer_move" | "pointer_click" | "pointer_down" | "pointer_up") => void;
36
+ /** Called for each replayed mesh interaction, so the host can highlight it. */
37
+ onMeshInteraction?: (mesh: string, kind: string, point: [number, number, number] | undefined) => void;
38
+ /**
39
+ * Scene-actor resolvers for `node_transform` drive-back (ADR 0027). Maps a
40
+ * recorded `nodeId` to the live Lite node (`TransformNode`/mesh) to re-drive — a
41
+ * direct reference or a `() => node` resolver. Lite is left-handed, so the
42
+ * canonical world transform is applied as-is to the node's local
43
+ * `position`/`rotationQuaternion`/`scaling` (correct for root actors). Tier-2
44
+ * bone samples are forwarded via {@link onNodeTransform} only (skeleton
45
+ * drive-back is Babylon-core-specific).
46
+ */
47
+ nodes?: Record<string, BabylonLiteReplayNode | (() => BabylonLiteReplayNode | null | undefined)>;
48
+ /**
49
+ * Called for **every** replayed `node_transform` (Tier 1 and Tier 2), after any
50
+ * node drive-back. Lite shares the canonical frame, so values are forwarded
51
+ * unconverted; `boneId` is set for Tier-2 samples.
52
+ */
53
+ onNodeTransform?: (nodeId: string, transform: {
54
+ boneId: string | undefined;
55
+ position: [number, number, number];
56
+ rotation: [number, number, number, number];
57
+ scale: [number, number, number] | undefined;
58
+ }, ts: number) => void;
59
+ /**
60
+ * Called for each replayed developer-defined `custom` event. The driver can't
61
+ * know how to render an arbitrary domain event, so it forwards the name, props,
62
+ * and timestamp for the host to visualize (marker, toast, log, ...).
63
+ */
64
+ onCustom?: (name: string, props: Record<string, CustomPropValue> | undefined, ts: number) => void;
65
+ /**
66
+ * Called for each replayed `input_action` (discrete keyboard/gamepad action,
67
+ * ADR 0023). Forwarded with the action, raw `code`/`button`, source, and
68
+ * timestamp so a replay UI can annotate the timeline.
69
+ */
70
+ onInputAction?: (input: {
71
+ action: string;
72
+ code: string | undefined;
73
+ button: number | undefined;
74
+ pressed: boolean | undefined;
75
+ source: string | undefined;
76
+ }, ts: number) => void;
77
+ /**
78
+ * Called for each replayed browser/engine lifecycle event (viewport resize, tab
79
+ * visibility, window focus, GPU context loss/restore). The driver doesn't
80
+ * re-drive these — it forwards them so a replay UI can annotate the timeline.
81
+ */
82
+ onLifecycle?: (event: {
83
+ type: "viewport_resize";
84
+ width: number;
85
+ height: number;
86
+ dpr: number | undefined;
87
+ } | {
88
+ type: "visibility_change";
89
+ state: "visible" | "hidden";
90
+ } | {
91
+ type: "focus_change";
92
+ focused: boolean;
93
+ } | {
94
+ type: "context_lost";
95
+ } | {
96
+ type: "context_restored";
97
+ }, ts: number) => void;
98
+ /**
99
+ * Called for each replayed `runtime_error` event (opt-in capture, ADR 0013).
100
+ * Forwarded so a replay UI can mark where a JS error or unhandled rejection
101
+ * interrupted the session.
102
+ */
103
+ onError?: (error: {
104
+ kind: "error" | "unhandledrejection";
105
+ message: string;
106
+ source: string | undefined;
107
+ lineno: number | undefined;
108
+ colno: number | undefined;
109
+ stack: string | undefined;
110
+ }, ts: number) => void;
111
+ }
112
+ /**
113
+ * Babylon Lite replay driver. Re-drives an `ArcRotateCamera` pose (and surfaces
114
+ * pointer/mesh/custom/input/lifecycle/error events to host callbacks) in the
115
+ * user's own Lite scene.
116
+ *
117
+ * ## Coordinate frame (canonical → Lite)
118
+ * Events arrive in the canonical **left-handed, y-up** frame (ADR 0018). Babylon
119
+ * Lite is **left-handed** too — the same frame — so `fromCanonical*` is the
120
+ * identity. It is still called for symmetry with the right-handed drivers (three,
121
+ * PlayCanvas), where it performs the real Z-negation.
122
+ *
123
+ * ## Camera re-drive
124
+ * Lite's `ArcRotateCamera` derives its world matrix from `alpha`/`beta`/`radius`/
125
+ * `target` each frame, so a recorded world position is mapped back to spherical
126
+ * orbit state (Babylon's left-handed convention:
127
+ * `pos = target + radius·(cos α·sin β, cos β, sin α·sin β)`). The recorded
128
+ * `target` is used when present; otherwise it is derived from `position + direction`.
129
+ *
130
+ * It only reads/writes the scene — it never emits analytics events (ADR 0006).
131
+ */
132
+ export declare function createBabylonLiteReplayDriver(options: BabylonLiteReplayDriverOptions): ReplayDriver;
133
+ export {};
134
+ //# sourceMappingURL=babylon-lite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babylon-lite.d.ts","sourceRoot":"","sources":["../../src/drivers/babylon-lite.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;GAOG;AACH,UAAU,mBAAmB;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5C,kFAAkF;IAClF,GAAG,CAAC,EAAE,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AS,CAAC;KAC3B,EACD,EAAE,EAAE,MAAM,KACP,IAAI,CAAC;CACX;AAQD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,8BAA8B,GACtC,YAAY,CA4Id"}
@@ -0,0 +1,167 @@
1
+ import { fromCanonicalDirection, fromCanonicalPosition } from "@uptimizr/sdk-core";
2
+ /** Resolve a node entry (direct ref or `() => node`) to a live node, or `null`. */
3
+ function resolveReplayNode(entry) {
4
+ if (!entry)
5
+ return null;
6
+ if (typeof entry === "function") {
7
+ return entry() ?? null;
8
+ }
9
+ return entry;
10
+ }
11
+ /** True when the camera exposes Lite's settable orbit state. */
12
+ function isArcRotate(cam) {
13
+ const c = cam;
14
+ return typeof c.alpha === "number" && c.target != null;
15
+ }
16
+ /**
17
+ * Babylon Lite replay driver. Re-drives an `ArcRotateCamera` pose (and surfaces
18
+ * pointer/mesh/custom/input/lifecycle/error events to host callbacks) in the
19
+ * user's own Lite scene.
20
+ *
21
+ * ## Coordinate frame (canonical → Lite)
22
+ * Events arrive in the canonical **left-handed, y-up** frame (ADR 0018). Babylon
23
+ * Lite is **left-handed** too — the same frame — so `fromCanonical*` is the
24
+ * identity. It is still called for symmetry with the right-handed drivers (three,
25
+ * PlayCanvas), where it performs the real Z-negation.
26
+ *
27
+ * ## Camera re-drive
28
+ * Lite's `ArcRotateCamera` derives its world matrix from `alpha`/`beta`/`radius`/
29
+ * `target` each frame, so a recorded world position is mapped back to spherical
30
+ * orbit state (Babylon's left-handed convention:
31
+ * `pos = target + radius·(cos α·sin β, cos β, sin α·sin β)`). The recorded
32
+ * `target` is used when present; otherwise it is derived from `position + direction`.
33
+ *
34
+ * It only reads/writes the scene — it never emits analytics events (ADR 0006).
35
+ */
36
+ export function createBabylonLiteReplayDriver(options) {
37
+ return {
38
+ reset() {
39
+ // Camera state is fully determined by the next camera_sample, so there is
40
+ // nothing to restore; host-rendered markers are the host's responsibility.
41
+ },
42
+ apply(event) {
43
+ switch (event.type) {
44
+ case "camera_sample": {
45
+ if (!isArcRotate(options.camera))
46
+ return;
47
+ const cam = options.camera;
48
+ // Lite is left-handed → fromCanonical* is identity (symmetry with RHS drivers).
49
+ const [px, py, pz] = fromCanonicalPosition(event.position, "left");
50
+ let tx;
51
+ let ty;
52
+ let tz;
53
+ if (event.target) {
54
+ [tx, ty, tz] = fromCanonicalPosition(event.target, "left");
55
+ }
56
+ else {
57
+ const [dx, dy, dz] = fromCanonicalDirection(event.direction, "left");
58
+ tx = px + dx;
59
+ ty = py + dy;
60
+ tz = pz + dz;
61
+ }
62
+ // Invert Babylon's spherical mapping to recover orbit state.
63
+ const ox = px - tx;
64
+ const oy = py - ty;
65
+ const oz = pz - tz;
66
+ const radius = Math.hypot(ox, oy, oz);
67
+ cam.target.x = tx;
68
+ cam.target.y = ty;
69
+ cam.target.z = tz;
70
+ cam.radius = radius;
71
+ if (radius > 1e-6) {
72
+ const cosBeta = Math.min(1, Math.max(-1, oy / radius));
73
+ cam.beta = Math.acos(cosBeta);
74
+ cam.alpha = Math.atan2(oz, ox);
75
+ }
76
+ // Lite FOV is in radians — matches the canonical wire, so no conversion.
77
+ if (typeof event.fov === "number")
78
+ cam.fov = event.fov;
79
+ break;
80
+ }
81
+ case "pointer_move":
82
+ case "pointer_click":
83
+ case "pointer_down":
84
+ case "pointer_up": {
85
+ const hitPoint = event.hitPoint
86
+ ? fromCanonicalPosition(event.hitPoint, "left")
87
+ : undefined;
88
+ options.onPointer?.(event.screen, hitPoint, event.hitMesh, event.type);
89
+ break;
90
+ }
91
+ case "mesh_interaction": {
92
+ const point = event.point ? fromCanonicalPosition(event.point, "left") : undefined;
93
+ options.onMeshInteraction?.(event.mesh, event.kind, point);
94
+ break;
95
+ }
96
+ case "custom":
97
+ options.onCustom?.(event.name, event.props, event.ts);
98
+ break;
99
+ case "input_action":
100
+ options.onInputAction?.({
101
+ action: event.action,
102
+ code: event.code,
103
+ button: event.button,
104
+ pressed: event.pressed,
105
+ source: event.source,
106
+ }, event.ts);
107
+ break;
108
+ case "viewport_resize":
109
+ options.onLifecycle?.({ type: "viewport_resize", width: event.width, height: event.height, dpr: event.dpr }, event.ts);
110
+ break;
111
+ case "visibility_change":
112
+ options.onLifecycle?.({ type: "visibility_change", state: event.state }, event.ts);
113
+ break;
114
+ case "focus_change":
115
+ options.onLifecycle?.({ type: "focus_change", focused: event.focused }, event.ts);
116
+ break;
117
+ case "context_lost":
118
+ options.onLifecycle?.({ type: "context_lost" }, event.ts);
119
+ break;
120
+ case "context_restored":
121
+ options.onLifecycle?.({ type: "context_restored" }, event.ts);
122
+ break;
123
+ case "runtime_error":
124
+ options.onError?.({
125
+ kind: event.kind,
126
+ message: event.message,
127
+ source: event.source,
128
+ lineno: event.lineno,
129
+ colno: event.colno,
130
+ stack: event.stack,
131
+ }, event.ts);
132
+ break;
133
+ case "camera_gesture":
134
+ // Derived navigation annotation (ADR 0025); the camera trajectory is
135
+ // reconstructed from camera_sample, so replay intentionally ignores it.
136
+ break;
137
+ case "node_transform": {
138
+ if (event.boneId === undefined) {
139
+ const node = resolveReplayNode(options.nodes?.[event.nodeId]);
140
+ if (node) {
141
+ // Lite is left-handed → fromCanonical* is identity (no conversion).
142
+ const [px, py, pz] = fromCanonicalPosition(event.position, "left");
143
+ node.position?.set(px, py, pz);
144
+ const [qx, qy, qz, qw] = event.rotation;
145
+ node.rotationQuaternion?.set(qx, qy, qz, qw);
146
+ if (event.scale) {
147
+ node.scaling?.set(event.scale[0], event.scale[1], event.scale[2]);
148
+ }
149
+ }
150
+ }
151
+ // Forward the sample so the host can render a proxy marker or annotate
152
+ // the timeline (Tier-2 bone driving is Babylon-core-specific).
153
+ options.onNodeTransform?.(event.nodeId, {
154
+ boneId: event.boneId,
155
+ position: fromCanonicalPosition(event.position, "left"),
156
+ rotation: event.rotation,
157
+ scale: event.scale,
158
+ }, event.ts);
159
+ break;
160
+ }
161
+ default:
162
+ break;
163
+ }
164
+ },
165
+ };
166
+ }
167
+ //# sourceMappingURL=babylon-lite.js.map