depthview-r3f-bridge 0.0.0-stage → 0.3.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.
@@ -0,0 +1,41 @@
1
+ // src/index.dev.tsx
2
+ import { useThree } from "@react-three/fiber";
3
+ import { useEffect } from "react";
4
+ var GLOBAL = "__DEPTHVIEW_BRIDGE__";
5
+ function DepthviewBridge({ timeline }) {
6
+ const get = useThree((state) => state.get);
7
+ useEffect(() => {
8
+ const api = {
9
+ version: 1,
10
+ getState: () => {
11
+ const s = get();
12
+ return { scene: s.scene, camera: s.camera, gl: s.gl };
13
+ },
14
+ // Runs one R3F frame synchronously (useFrame callbacks) without advancing the clock.
15
+ advance: () => {
16
+ const s = get();
17
+ s.advance(s.clock.elapsedTime, false);
18
+ },
19
+ timeline: timeline ?? null
20
+ };
21
+ const w = window;
22
+ w[GLOBAL] = api;
23
+ window.postMessage(
24
+ {
25
+ source: "depthview",
26
+ v: 1,
27
+ id: `bridge-${Date.now().toString(36)}`,
28
+ type: "bridge:ready",
29
+ payload: { version: 1, timeline: !!timeline }
30
+ },
31
+ window.location.origin === "null" ? "*" : window.location.origin
32
+ );
33
+ return () => {
34
+ if (w[GLOBAL] === api) delete w[GLOBAL];
35
+ };
36
+ }, [get, timeline]);
37
+ return null;
38
+ }
39
+ export {
40
+ DepthviewBridge
41
+ };
@@ -0,0 +1,7 @@
1
+ // src/index.prod.ts
2
+ function DepthviewBridge(_props) {
3
+ return null;
4
+ }
5
+ export {
6
+ DepthviewBridge
7
+ };