@retor/react-native 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.
- package/LICENSE +21 -0
- package/README.md +148 -0
- package/dist/index.d.mts +113 -0
- package/dist/index.d.ts +113 -0
- package/dist/index.js +216 -0
- package/dist/index.mjs +186 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bag of Marshmallows
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# @retor/react-native
|
|
2
|
+
|
|
3
|
+
Embed Retor 3D experiences in a React Native / Expo app via `react-native-webview`.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the peer dependency:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Expo
|
|
11
|
+
npx expo install react-native-webview
|
|
12
|
+
|
|
13
|
+
# bare React Native
|
|
14
|
+
npm install react-native-webview
|
|
15
|
+
cd ios && pod install
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Then install the SDK:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @retor/react-native
|
|
22
|
+
# or
|
|
23
|
+
pnpm add @retor/react-native
|
|
24
|
+
# or
|
|
25
|
+
yarn add @retor/react-native
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { View } from "react-native";
|
|
32
|
+
import { Viewer, Hud } from "@retor/react-native";
|
|
33
|
+
|
|
34
|
+
export default function Scene() {
|
|
35
|
+
return (
|
|
36
|
+
<View style={{ flex: 1 }}>
|
|
37
|
+
<Viewer projectId="abc123" style={{ flex: 1 }}>
|
|
38
|
+
<Hud />
|
|
39
|
+
</Viewer>
|
|
40
|
+
</View>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Custom Bottom Sheet
|
|
46
|
+
|
|
47
|
+
Listen to events and drive a native UI on top of the viewer. Use the `useViewer` hook from any component to control the viewer without threading refs around.
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { useState } from "react";
|
|
51
|
+
import { View, Text, Pressable, FlatList } from "react-native";
|
|
52
|
+
import { Viewer, useViewer, type RetorLine } from "@retor/react-native";
|
|
53
|
+
|
|
54
|
+
function Sheet({ lines, activeLine, closestTagId }: {
|
|
55
|
+
lines: RetorLine[];
|
|
56
|
+
activeLine: RetorLine | null;
|
|
57
|
+
closestTagId: string | null;
|
|
58
|
+
}) {
|
|
59
|
+
const { openLine, exitLine, scrollToTag } = useViewer();
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<View style={{ position: "absolute", bottom: 32, left: 16, right: 16 }}>
|
|
63
|
+
{activeLine ? (
|
|
64
|
+
<View style={{ backgroundColor: "rgba(0,0,0,0.85)", borderRadius: 24, padding: 16 }}>
|
|
65
|
+
<Text style={{ color: "white", fontSize: 18, fontWeight: "600" }}>{activeLine.name}</Text>
|
|
66
|
+
<FlatList
|
|
67
|
+
data={activeLine.tags}
|
|
68
|
+
keyExtractor={(t) => t._id}
|
|
69
|
+
renderItem={({ item }) => (
|
|
70
|
+
<Pressable onPress={() => scrollToTag(item._id)}>
|
|
71
|
+
<Text style={{ color: item._id === closestTagId ? "white" : "gray" }}>
|
|
72
|
+
{item.name}
|
|
73
|
+
</Text>
|
|
74
|
+
</Pressable>
|
|
75
|
+
)}
|
|
76
|
+
/>
|
|
77
|
+
<Pressable onPress={() => exitLine()}>
|
|
78
|
+
<Text style={{ color: "white" }}>Done</Text>
|
|
79
|
+
</Pressable>
|
|
80
|
+
</View>
|
|
81
|
+
) : (
|
|
82
|
+
<FlatList
|
|
83
|
+
horizontal
|
|
84
|
+
data={lines}
|
|
85
|
+
keyExtractor={(l) => l._id}
|
|
86
|
+
renderItem={({ item }) => (
|
|
87
|
+
<Pressable onPress={() => openLine(item._id)}>
|
|
88
|
+
<Text style={{ color: "white", padding: 16 }}>{item.name}</Text>
|
|
89
|
+
</Pressable>
|
|
90
|
+
)}
|
|
91
|
+
/>
|
|
92
|
+
)}
|
|
93
|
+
</View>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export default function Scene() {
|
|
98
|
+
const [lines, setLines] = useState<RetorLine[]>([]);
|
|
99
|
+
const [activeLine, setActiveLine] = useState<RetorLine | null>(null);
|
|
100
|
+
const [closestTagId, setClosestTagId] = useState<string | null>(null);
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<View style={{ flex: 1 }}>
|
|
104
|
+
<Viewer
|
|
105
|
+
projectId="abc123"
|
|
106
|
+
style={{ flex: 1 }}
|
|
107
|
+
onInit={(data) => setLines(data.lines)}
|
|
108
|
+
onLineOpen={({ lineId }) => {
|
|
109
|
+
const line = lines.find((l) => l._id === lineId);
|
|
110
|
+
if (line) setActiveLine(line);
|
|
111
|
+
}}
|
|
112
|
+
onLineClose={() => setActiveLine(null)}
|
|
113
|
+
onLineProgress={({ closestTagId }) => setClosestTagId(closestTagId)}
|
|
114
|
+
/>
|
|
115
|
+
<Sheet lines={lines} activeLine={activeLine} closestTagId={closestTagId} />
|
|
116
|
+
</View>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Notes on WebView setup
|
|
122
|
+
|
|
123
|
+
- The SDK sets `originWhitelist=["*"]`, `javaScriptEnabled`, and `domStorageEnabled` automatically
|
|
124
|
+
- Inline media playback is enabled without user gesture
|
|
125
|
+
- Messages are JSON-stringified across the bridge — handled transparently
|
|
126
|
+
- On Android, inbound messages are dispatched via `injectJavaScript`
|
|
127
|
+
|
|
128
|
+
## Passing in Notes
|
|
129
|
+
|
|
130
|
+
Use `<Notes>` as a child of the Viewer to push user-generated tags into the 3D scene. Same API as the React SDK — re-render with an updated array to sync changes.
|
|
131
|
+
|
|
132
|
+
```tsx
|
|
133
|
+
import { Viewer, Notes, type RetorTag } from "@retor/react-native";
|
|
134
|
+
|
|
135
|
+
const [notes, setNotes] = useState<RetorTag[]>([]);
|
|
136
|
+
|
|
137
|
+
<Viewer projectId="..." style={{ flex: 1 }}>
|
|
138
|
+
<Notes notes={notes} />
|
|
139
|
+
</Viewer>
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## API
|
|
143
|
+
|
|
144
|
+
Identical to the [React SDK](https://www.npmjs.com/package/@retor/react) — same props, same imperative methods, same `useViewer` hook.
|
|
145
|
+
|
|
146
|
+
## License
|
|
147
|
+
|
|
148
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
interface RetorTag {
|
|
5
|
+
_id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
subtitle?: string;
|
|
9
|
+
index?: number;
|
|
10
|
+
position: {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
z: number;
|
|
14
|
+
};
|
|
15
|
+
split?: boolean;
|
|
16
|
+
color?: string;
|
|
17
|
+
tagType?: string;
|
|
18
|
+
iconName?: string;
|
|
19
|
+
}
|
|
20
|
+
interface RetorLine {
|
|
21
|
+
_id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
subtitle?: string;
|
|
25
|
+
autoplay?: boolean;
|
|
26
|
+
autoplaySpeed?: number;
|
|
27
|
+
scrollType?: "track" | "observe";
|
|
28
|
+
closed?: boolean;
|
|
29
|
+
notesSupported?: boolean;
|
|
30
|
+
tags: RetorTag[];
|
|
31
|
+
}
|
|
32
|
+
interface RetorProject {
|
|
33
|
+
_id: string;
|
|
34
|
+
name?: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
startViewId?: string;
|
|
37
|
+
}
|
|
38
|
+
interface InitPayload {
|
|
39
|
+
project: RetorProject;
|
|
40
|
+
lines: RetorLine[];
|
|
41
|
+
}
|
|
42
|
+
interface LineProgressPayload {
|
|
43
|
+
progress: number;
|
|
44
|
+
closestTagId: string | null;
|
|
45
|
+
}
|
|
46
|
+
interface ViewerHandle {
|
|
47
|
+
openLine: (lineId: string) => void;
|
|
48
|
+
exitLine: () => void;
|
|
49
|
+
scrollToTag: (tagId: string) => void;
|
|
50
|
+
toggleAutoplay: () => void;
|
|
51
|
+
setAutoplay: (playing: boolean) => void;
|
|
52
|
+
}
|
|
53
|
+
interface ViewerProps {
|
|
54
|
+
projectId: string;
|
|
55
|
+
/** Identifier for this viewer instance. Used by `useViewer(id)`. Defaults to "default". */
|
|
56
|
+
id?: string;
|
|
57
|
+
/** Base URL where Retor is hosted. Defaults to https://retor.app */
|
|
58
|
+
baseUrl?: string;
|
|
59
|
+
onInit?: (data: InitPayload) => void;
|
|
60
|
+
onLineOpen?: (data: {
|
|
61
|
+
lineId: string;
|
|
62
|
+
}) => void;
|
|
63
|
+
onLineClose?: () => void;
|
|
64
|
+
onLineProgress?: (data: LineProgressPayload) => void;
|
|
65
|
+
onMessage?: (type: string, payload: unknown) => void;
|
|
66
|
+
style?: StyleProp<ViewStyle>;
|
|
67
|
+
children?: React.ReactNode;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Hook that returns a destructured set of viewer controls.
|
|
71
|
+
*
|
|
72
|
+
* Usage with an ID (default "default"):
|
|
73
|
+
* ```tsx
|
|
74
|
+
* <Viewer projectId="..." /> // id defaults to "default"
|
|
75
|
+
* const { openLine, exitLine } = useViewer();
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* With an explicit ID (multiple viewers on one screen):
|
|
79
|
+
* ```tsx
|
|
80
|
+
* <Viewer id="left" projectId="..." />
|
|
81
|
+
* <Viewer id="right" projectId="..." />
|
|
82
|
+
* const left = useViewer("left");
|
|
83
|
+
* left.openLine("...");
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* With a ref (if you prefer imperative style):
|
|
87
|
+
* ```tsx
|
|
88
|
+
* const ref = useRef<ViewerHandle>(null);
|
|
89
|
+
* <Viewer ref={ref} projectId="..." />
|
|
90
|
+
* const { openLine } = useViewer(ref);
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
declare function useViewer(target?: string | React.RefObject<ViewerHandle | null>): ViewerHandle;
|
|
94
|
+
/**
|
|
95
|
+
* Include as a child of `<Viewer>` to show Retor's built-in UI
|
|
96
|
+
* (info card, tag list, autoplay controls). Without it, the viewer runs in
|
|
97
|
+
* vanilla mode — you build your own UI around the 3D scene using the props.
|
|
98
|
+
*/
|
|
99
|
+
declare function Hud(): React.ReactElement | null;
|
|
100
|
+
interface NotesProps {
|
|
101
|
+
/** Array of notes (same shape as RetorTag) to pass into the 3D scene. */
|
|
102
|
+
notes: RetorTag[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Pass user-generated notes into the Retor scene as a child of `<Viewer>`.
|
|
106
|
+
* The notes use the same shape as a RetorTag — Retor will render them in
|
|
107
|
+
* the scene and tag lists. Persistence is handled entirely by your app:
|
|
108
|
+
* re-render with an updated `notes` array to sync changes.
|
|
109
|
+
*/
|
|
110
|
+
declare function Notes(_props: NotesProps): React.ReactElement | null;
|
|
111
|
+
declare const Viewer: React.ForwardRefExoticComponent<ViewerProps & React.RefAttributes<ViewerHandle>>;
|
|
112
|
+
|
|
113
|
+
export { Hud, type InitPayload, type LineProgressPayload, Notes, type NotesProps, type RetorLine, type RetorProject, type RetorTag, Viewer, type ViewerHandle, type ViewerProps, useViewer };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
interface RetorTag {
|
|
5
|
+
_id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
subtitle?: string;
|
|
9
|
+
index?: number;
|
|
10
|
+
position: {
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
|
+
z: number;
|
|
14
|
+
};
|
|
15
|
+
split?: boolean;
|
|
16
|
+
color?: string;
|
|
17
|
+
tagType?: string;
|
|
18
|
+
iconName?: string;
|
|
19
|
+
}
|
|
20
|
+
interface RetorLine {
|
|
21
|
+
_id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
subtitle?: string;
|
|
25
|
+
autoplay?: boolean;
|
|
26
|
+
autoplaySpeed?: number;
|
|
27
|
+
scrollType?: "track" | "observe";
|
|
28
|
+
closed?: boolean;
|
|
29
|
+
notesSupported?: boolean;
|
|
30
|
+
tags: RetorTag[];
|
|
31
|
+
}
|
|
32
|
+
interface RetorProject {
|
|
33
|
+
_id: string;
|
|
34
|
+
name?: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
startViewId?: string;
|
|
37
|
+
}
|
|
38
|
+
interface InitPayload {
|
|
39
|
+
project: RetorProject;
|
|
40
|
+
lines: RetorLine[];
|
|
41
|
+
}
|
|
42
|
+
interface LineProgressPayload {
|
|
43
|
+
progress: number;
|
|
44
|
+
closestTagId: string | null;
|
|
45
|
+
}
|
|
46
|
+
interface ViewerHandle {
|
|
47
|
+
openLine: (lineId: string) => void;
|
|
48
|
+
exitLine: () => void;
|
|
49
|
+
scrollToTag: (tagId: string) => void;
|
|
50
|
+
toggleAutoplay: () => void;
|
|
51
|
+
setAutoplay: (playing: boolean) => void;
|
|
52
|
+
}
|
|
53
|
+
interface ViewerProps {
|
|
54
|
+
projectId: string;
|
|
55
|
+
/** Identifier for this viewer instance. Used by `useViewer(id)`. Defaults to "default". */
|
|
56
|
+
id?: string;
|
|
57
|
+
/** Base URL where Retor is hosted. Defaults to https://retor.app */
|
|
58
|
+
baseUrl?: string;
|
|
59
|
+
onInit?: (data: InitPayload) => void;
|
|
60
|
+
onLineOpen?: (data: {
|
|
61
|
+
lineId: string;
|
|
62
|
+
}) => void;
|
|
63
|
+
onLineClose?: () => void;
|
|
64
|
+
onLineProgress?: (data: LineProgressPayload) => void;
|
|
65
|
+
onMessage?: (type: string, payload: unknown) => void;
|
|
66
|
+
style?: StyleProp<ViewStyle>;
|
|
67
|
+
children?: React.ReactNode;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Hook that returns a destructured set of viewer controls.
|
|
71
|
+
*
|
|
72
|
+
* Usage with an ID (default "default"):
|
|
73
|
+
* ```tsx
|
|
74
|
+
* <Viewer projectId="..." /> // id defaults to "default"
|
|
75
|
+
* const { openLine, exitLine } = useViewer();
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* With an explicit ID (multiple viewers on one screen):
|
|
79
|
+
* ```tsx
|
|
80
|
+
* <Viewer id="left" projectId="..." />
|
|
81
|
+
* <Viewer id="right" projectId="..." />
|
|
82
|
+
* const left = useViewer("left");
|
|
83
|
+
* left.openLine("...");
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* With a ref (if you prefer imperative style):
|
|
87
|
+
* ```tsx
|
|
88
|
+
* const ref = useRef<ViewerHandle>(null);
|
|
89
|
+
* <Viewer ref={ref} projectId="..." />
|
|
90
|
+
* const { openLine } = useViewer(ref);
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
declare function useViewer(target?: string | React.RefObject<ViewerHandle | null>): ViewerHandle;
|
|
94
|
+
/**
|
|
95
|
+
* Include as a child of `<Viewer>` to show Retor's built-in UI
|
|
96
|
+
* (info card, tag list, autoplay controls). Without it, the viewer runs in
|
|
97
|
+
* vanilla mode — you build your own UI around the 3D scene using the props.
|
|
98
|
+
*/
|
|
99
|
+
declare function Hud(): React.ReactElement | null;
|
|
100
|
+
interface NotesProps {
|
|
101
|
+
/** Array of notes (same shape as RetorTag) to pass into the 3D scene. */
|
|
102
|
+
notes: RetorTag[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Pass user-generated notes into the Retor scene as a child of `<Viewer>`.
|
|
106
|
+
* The notes use the same shape as a RetorTag — Retor will render them in
|
|
107
|
+
* the scene and tag lists. Persistence is handled entirely by your app:
|
|
108
|
+
* re-render with an updated `notes` array to sync changes.
|
|
109
|
+
*/
|
|
110
|
+
declare function Notes(_props: NotesProps): React.ReactElement | null;
|
|
111
|
+
declare const Viewer: React.ForwardRefExoticComponent<ViewerProps & React.RefAttributes<ViewerHandle>>;
|
|
112
|
+
|
|
113
|
+
export { Hud, type InitPayload, type LineProgressPayload, Notes, type NotesProps, type RetorLine, type RetorProject, type RetorTag, Viewer, type ViewerHandle, type ViewerProps, useViewer };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.tsx
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
Hud: () => Hud,
|
|
34
|
+
Notes: () => Notes,
|
|
35
|
+
Viewer: () => Viewer,
|
|
36
|
+
useViewer: () => useViewer
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(index_exports);
|
|
39
|
+
var import_react = __toESM(require("react"));
|
|
40
|
+
var import_react_native_webview = require("react-native-webview");
|
|
41
|
+
var viewerRegistry = /* @__PURE__ */ new Map();
|
|
42
|
+
var registryListeners = /* @__PURE__ */ new Set();
|
|
43
|
+
function registerViewer(id, handle) {
|
|
44
|
+
viewerRegistry.set(id, handle);
|
|
45
|
+
registryListeners.forEach((l) => l());
|
|
46
|
+
return () => {
|
|
47
|
+
viewerRegistry.delete(id);
|
|
48
|
+
registryListeners.forEach((l) => l());
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function subscribeRegistry(cb) {
|
|
52
|
+
registryListeners.add(cb);
|
|
53
|
+
return () => {
|
|
54
|
+
registryListeners.delete(cb);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function useViewer(target = "default") {
|
|
58
|
+
const subscribe = (0, import_react.useCallback)(
|
|
59
|
+
(cb) => typeof target === "string" ? subscribeRegistry(cb) : () => {
|
|
60
|
+
},
|
|
61
|
+
[target]
|
|
62
|
+
);
|
|
63
|
+
const getSnapshot = (0, import_react.useCallback)(
|
|
64
|
+
() => typeof target === "string" ? viewerRegistry.get(target) ?? null : target.current ?? null,
|
|
65
|
+
[target]
|
|
66
|
+
);
|
|
67
|
+
const handle = (0, import_react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
68
|
+
return (0, import_react.useMemo)(() => {
|
|
69
|
+
const resolve = () => typeof target === "string" ? viewerRegistry.get(target) ?? null : target.current ?? null;
|
|
70
|
+
return {
|
|
71
|
+
openLine: (lineId) => {
|
|
72
|
+
resolve()?.openLine(lineId);
|
|
73
|
+
},
|
|
74
|
+
exitLine: () => {
|
|
75
|
+
resolve()?.exitLine();
|
|
76
|
+
},
|
|
77
|
+
scrollToTag: (tagId) => {
|
|
78
|
+
resolve()?.scrollToTag(tagId);
|
|
79
|
+
},
|
|
80
|
+
toggleAutoplay: () => {
|
|
81
|
+
resolve()?.toggleAutoplay();
|
|
82
|
+
},
|
|
83
|
+
setAutoplay: (playing) => {
|
|
84
|
+
resolve()?.setAutoplay(playing);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}, [target, handle]);
|
|
88
|
+
}
|
|
89
|
+
function Hud() {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
Hud.__isHud = true;
|
|
93
|
+
function hasHud(children) {
|
|
94
|
+
let found = false;
|
|
95
|
+
import_react.default.Children.forEach(children, (child) => {
|
|
96
|
+
if (!import_react.default.isValidElement(child)) return;
|
|
97
|
+
const type = child.type;
|
|
98
|
+
if (type?.__isHud) found = true;
|
|
99
|
+
});
|
|
100
|
+
return found;
|
|
101
|
+
}
|
|
102
|
+
function Notes(_props) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
Notes.__isNotes = true;
|
|
106
|
+
function extractNotes(children) {
|
|
107
|
+
let notes = null;
|
|
108
|
+
import_react.default.Children.forEach(children, (child) => {
|
|
109
|
+
if (!import_react.default.isValidElement(child)) return;
|
|
110
|
+
const type = child.type;
|
|
111
|
+
if (type?.__isNotes) {
|
|
112
|
+
const props = child.props;
|
|
113
|
+
notes = props.notes ?? [];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return notes;
|
|
117
|
+
}
|
|
118
|
+
var Viewer = (0, import_react.forwardRef)(
|
|
119
|
+
function Viewer2({ projectId, id = "default", baseUrl = "https://retor.app", onInit, onLineOpen, onLineClose, onLineProgress, onMessage, style, children }, ref) {
|
|
120
|
+
const webviewRef = (0, import_react.useRef)(null);
|
|
121
|
+
const showHud = hasHud(children);
|
|
122
|
+
const notes = extractNotes(children);
|
|
123
|
+
const readyRef = (0, import_react.useRef)(false);
|
|
124
|
+
(0, import_react.useEffect)(() => {
|
|
125
|
+
const handle = {
|
|
126
|
+
openLine: (lineId) => send("open-line", { lineId }),
|
|
127
|
+
exitLine: () => send("exit-line"),
|
|
128
|
+
scrollToTag: (tagId) => send("scroll-to-tag", { tagId }),
|
|
129
|
+
toggleAutoplay: () => send("toggle-autoplay"),
|
|
130
|
+
setAutoplay: (playing) => send("set-autoplay", { playing })
|
|
131
|
+
};
|
|
132
|
+
return registerViewer(id, handle);
|
|
133
|
+
}, [id]);
|
|
134
|
+
const uri = (0, import_react.useMemo)(() => {
|
|
135
|
+
const params = [];
|
|
136
|
+
if (!showHud) params.push("vanilla=true");
|
|
137
|
+
const qs = params.length ? `?${params.join("&")}` : "";
|
|
138
|
+
return `${baseUrl}/p/${projectId}${qs}`;
|
|
139
|
+
}, [baseUrl, projectId, showHud]);
|
|
140
|
+
const send = (0, import_react.useCallback)((type, payload) => {
|
|
141
|
+
const message = JSON.stringify({ source: "retor-host", type, payload });
|
|
142
|
+
const escaped = message.replace(/\\/g, "\\\\").replace(/`/g, "\\`");
|
|
143
|
+
const script = `
|
|
144
|
+
(function(){
|
|
145
|
+
try {
|
|
146
|
+
var msg = JSON.parse(\`${escaped}\`);
|
|
147
|
+
window.dispatchEvent(new MessageEvent('message', { data: msg }));
|
|
148
|
+
} catch(e) {}
|
|
149
|
+
true;
|
|
150
|
+
})();
|
|
151
|
+
`;
|
|
152
|
+
webviewRef.current?.injectJavaScript(script);
|
|
153
|
+
}, []);
|
|
154
|
+
(0, import_react.useImperativeHandle)(ref, () => ({
|
|
155
|
+
openLine: (lineId) => send("open-line", { lineId }),
|
|
156
|
+
exitLine: () => send("exit-line"),
|
|
157
|
+
scrollToTag: (tagId) => send("scroll-to-tag", { tagId }),
|
|
158
|
+
toggleAutoplay: () => send("toggle-autoplay"),
|
|
159
|
+
setAutoplay: (playing) => send("set-autoplay", { playing })
|
|
160
|
+
}), [send]);
|
|
161
|
+
(0, import_react.useEffect)(() => {
|
|
162
|
+
if (!notes || !readyRef.current) return;
|
|
163
|
+
send("set-notes", { notes });
|
|
164
|
+
}, [notes, send]);
|
|
165
|
+
const handleMessage = (0, import_react.useCallback)((event) => {
|
|
166
|
+
let data = null;
|
|
167
|
+
try {
|
|
168
|
+
data = JSON.parse(event.nativeEvent.data);
|
|
169
|
+
} catch {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (!data || data.source !== "retor" || !data.type) return;
|
|
173
|
+
switch (data.type) {
|
|
174
|
+
case "init":
|
|
175
|
+
if (!readyRef.current) {
|
|
176
|
+
readyRef.current = true;
|
|
177
|
+
if (notes) send("set-notes", { notes });
|
|
178
|
+
}
|
|
179
|
+
onInit?.(data.payload);
|
|
180
|
+
break;
|
|
181
|
+
case "line-open":
|
|
182
|
+
onLineOpen?.(data.payload);
|
|
183
|
+
break;
|
|
184
|
+
case "line-close":
|
|
185
|
+
onLineClose?.();
|
|
186
|
+
break;
|
|
187
|
+
case "line-progress":
|
|
188
|
+
onLineProgress?.(data.payload);
|
|
189
|
+
break;
|
|
190
|
+
default:
|
|
191
|
+
onMessage?.(data.type, data.payload);
|
|
192
|
+
}
|
|
193
|
+
}, [notes, send, onInit, onLineOpen, onLineClose, onLineProgress, onMessage]);
|
|
194
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
195
|
+
import_react_native_webview.WebView,
|
|
196
|
+
{
|
|
197
|
+
ref: webviewRef,
|
|
198
|
+
source: { uri },
|
|
199
|
+
style,
|
|
200
|
+
onMessage: handleMessage,
|
|
201
|
+
originWhitelist: ["*"],
|
|
202
|
+
javaScriptEnabled: true,
|
|
203
|
+
domStorageEnabled: true,
|
|
204
|
+
allowsInlineMediaPlayback: true,
|
|
205
|
+
mediaPlaybackRequiresUserAction: false
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
);
|
|
210
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
211
|
+
0 && (module.exports = {
|
|
212
|
+
Hud,
|
|
213
|
+
Notes,
|
|
214
|
+
Viewer,
|
|
215
|
+
useViewer
|
|
216
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// src/index.tsx
|
|
2
|
+
import React, {
|
|
3
|
+
forwardRef,
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
useImperativeHandle,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
useSyncExternalStore
|
|
10
|
+
} from "react";
|
|
11
|
+
import { WebView } from "react-native-webview";
|
|
12
|
+
var viewerRegistry = /* @__PURE__ */ new Map();
|
|
13
|
+
var registryListeners = /* @__PURE__ */ new Set();
|
|
14
|
+
function registerViewer(id, handle) {
|
|
15
|
+
viewerRegistry.set(id, handle);
|
|
16
|
+
registryListeners.forEach((l) => l());
|
|
17
|
+
return () => {
|
|
18
|
+
viewerRegistry.delete(id);
|
|
19
|
+
registryListeners.forEach((l) => l());
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function subscribeRegistry(cb) {
|
|
23
|
+
registryListeners.add(cb);
|
|
24
|
+
return () => {
|
|
25
|
+
registryListeners.delete(cb);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function useViewer(target = "default") {
|
|
29
|
+
const subscribe = useCallback(
|
|
30
|
+
(cb) => typeof target === "string" ? subscribeRegistry(cb) : () => {
|
|
31
|
+
},
|
|
32
|
+
[target]
|
|
33
|
+
);
|
|
34
|
+
const getSnapshot = useCallback(
|
|
35
|
+
() => typeof target === "string" ? viewerRegistry.get(target) ?? null : target.current ?? null,
|
|
36
|
+
[target]
|
|
37
|
+
);
|
|
38
|
+
const handle = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
39
|
+
return useMemo(() => {
|
|
40
|
+
const resolve = () => typeof target === "string" ? viewerRegistry.get(target) ?? null : target.current ?? null;
|
|
41
|
+
return {
|
|
42
|
+
openLine: (lineId) => {
|
|
43
|
+
resolve()?.openLine(lineId);
|
|
44
|
+
},
|
|
45
|
+
exitLine: () => {
|
|
46
|
+
resolve()?.exitLine();
|
|
47
|
+
},
|
|
48
|
+
scrollToTag: (tagId) => {
|
|
49
|
+
resolve()?.scrollToTag(tagId);
|
|
50
|
+
},
|
|
51
|
+
toggleAutoplay: () => {
|
|
52
|
+
resolve()?.toggleAutoplay();
|
|
53
|
+
},
|
|
54
|
+
setAutoplay: (playing) => {
|
|
55
|
+
resolve()?.setAutoplay(playing);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}, [target, handle]);
|
|
59
|
+
}
|
|
60
|
+
function Hud() {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
Hud.__isHud = true;
|
|
64
|
+
function hasHud(children) {
|
|
65
|
+
let found = false;
|
|
66
|
+
React.Children.forEach(children, (child) => {
|
|
67
|
+
if (!React.isValidElement(child)) return;
|
|
68
|
+
const type = child.type;
|
|
69
|
+
if (type?.__isHud) found = true;
|
|
70
|
+
});
|
|
71
|
+
return found;
|
|
72
|
+
}
|
|
73
|
+
function Notes(_props) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
Notes.__isNotes = true;
|
|
77
|
+
function extractNotes(children) {
|
|
78
|
+
let notes = null;
|
|
79
|
+
React.Children.forEach(children, (child) => {
|
|
80
|
+
if (!React.isValidElement(child)) return;
|
|
81
|
+
const type = child.type;
|
|
82
|
+
if (type?.__isNotes) {
|
|
83
|
+
const props = child.props;
|
|
84
|
+
notes = props.notes ?? [];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return notes;
|
|
88
|
+
}
|
|
89
|
+
var Viewer = forwardRef(
|
|
90
|
+
function Viewer2({ projectId, id = "default", baseUrl = "https://retor.app", onInit, onLineOpen, onLineClose, onLineProgress, onMessage, style, children }, ref) {
|
|
91
|
+
const webviewRef = useRef(null);
|
|
92
|
+
const showHud = hasHud(children);
|
|
93
|
+
const notes = extractNotes(children);
|
|
94
|
+
const readyRef = useRef(false);
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
const handle = {
|
|
97
|
+
openLine: (lineId) => send("open-line", { lineId }),
|
|
98
|
+
exitLine: () => send("exit-line"),
|
|
99
|
+
scrollToTag: (tagId) => send("scroll-to-tag", { tagId }),
|
|
100
|
+
toggleAutoplay: () => send("toggle-autoplay"),
|
|
101
|
+
setAutoplay: (playing) => send("set-autoplay", { playing })
|
|
102
|
+
};
|
|
103
|
+
return registerViewer(id, handle);
|
|
104
|
+
}, [id]);
|
|
105
|
+
const uri = useMemo(() => {
|
|
106
|
+
const params = [];
|
|
107
|
+
if (!showHud) params.push("vanilla=true");
|
|
108
|
+
const qs = params.length ? `?${params.join("&")}` : "";
|
|
109
|
+
return `${baseUrl}/p/${projectId}${qs}`;
|
|
110
|
+
}, [baseUrl, projectId, showHud]);
|
|
111
|
+
const send = useCallback((type, payload) => {
|
|
112
|
+
const message = JSON.stringify({ source: "retor-host", type, payload });
|
|
113
|
+
const escaped = message.replace(/\\/g, "\\\\").replace(/`/g, "\\`");
|
|
114
|
+
const script = `
|
|
115
|
+
(function(){
|
|
116
|
+
try {
|
|
117
|
+
var msg = JSON.parse(\`${escaped}\`);
|
|
118
|
+
window.dispatchEvent(new MessageEvent('message', { data: msg }));
|
|
119
|
+
} catch(e) {}
|
|
120
|
+
true;
|
|
121
|
+
})();
|
|
122
|
+
`;
|
|
123
|
+
webviewRef.current?.injectJavaScript(script);
|
|
124
|
+
}, []);
|
|
125
|
+
useImperativeHandle(ref, () => ({
|
|
126
|
+
openLine: (lineId) => send("open-line", { lineId }),
|
|
127
|
+
exitLine: () => send("exit-line"),
|
|
128
|
+
scrollToTag: (tagId) => send("scroll-to-tag", { tagId }),
|
|
129
|
+
toggleAutoplay: () => send("toggle-autoplay"),
|
|
130
|
+
setAutoplay: (playing) => send("set-autoplay", { playing })
|
|
131
|
+
}), [send]);
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
if (!notes || !readyRef.current) return;
|
|
134
|
+
send("set-notes", { notes });
|
|
135
|
+
}, [notes, send]);
|
|
136
|
+
const handleMessage = useCallback((event) => {
|
|
137
|
+
let data = null;
|
|
138
|
+
try {
|
|
139
|
+
data = JSON.parse(event.nativeEvent.data);
|
|
140
|
+
} catch {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (!data || data.source !== "retor" || !data.type) return;
|
|
144
|
+
switch (data.type) {
|
|
145
|
+
case "init":
|
|
146
|
+
if (!readyRef.current) {
|
|
147
|
+
readyRef.current = true;
|
|
148
|
+
if (notes) send("set-notes", { notes });
|
|
149
|
+
}
|
|
150
|
+
onInit?.(data.payload);
|
|
151
|
+
break;
|
|
152
|
+
case "line-open":
|
|
153
|
+
onLineOpen?.(data.payload);
|
|
154
|
+
break;
|
|
155
|
+
case "line-close":
|
|
156
|
+
onLineClose?.();
|
|
157
|
+
break;
|
|
158
|
+
case "line-progress":
|
|
159
|
+
onLineProgress?.(data.payload);
|
|
160
|
+
break;
|
|
161
|
+
default:
|
|
162
|
+
onMessage?.(data.type, data.payload);
|
|
163
|
+
}
|
|
164
|
+
}, [notes, send, onInit, onLineOpen, onLineClose, onLineProgress, onMessage]);
|
|
165
|
+
return /* @__PURE__ */ React.createElement(
|
|
166
|
+
WebView,
|
|
167
|
+
{
|
|
168
|
+
ref: webviewRef,
|
|
169
|
+
source: { uri },
|
|
170
|
+
style,
|
|
171
|
+
onMessage: handleMessage,
|
|
172
|
+
originWhitelist: ["*"],
|
|
173
|
+
javaScriptEnabled: true,
|
|
174
|
+
domStorageEnabled: true,
|
|
175
|
+
allowsInlineMediaPlayback: true,
|
|
176
|
+
mediaPlaybackRequiresUserAction: false
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
);
|
|
181
|
+
export {
|
|
182
|
+
Hud,
|
|
183
|
+
Notes,
|
|
184
|
+
Viewer,
|
|
185
|
+
useViewer
|
|
186
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@retor/react-native",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React Native SDK for embedding Retor 3D experiences",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"retor",
|
|
22
|
+
"3d",
|
|
23
|
+
"gaussian-splat",
|
|
24
|
+
"react-native",
|
|
25
|
+
"expo"
|
|
26
|
+
],
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": ">=18",
|
|
30
|
+
"react-native": ">=0.72",
|
|
31
|
+
"react-native-webview": ">=13"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/react": "^19.0.0",
|
|
35
|
+
"react": "19.1.0",
|
|
36
|
+
"react-native": "0.81.4",
|
|
37
|
+
"react-native-webview": "^13.13.0",
|
|
38
|
+
"tsup": "^8.0.0",
|
|
39
|
+
"typescript": "^5.4.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup src/index.tsx --format cjs,esm --dts --clean --external react --external react-native --external react-native-webview",
|
|
43
|
+
"dev": "tsup src/index.tsx --format cjs,esm --dts --watch --external react --external react-native --external react-native-webview",
|
|
44
|
+
"typecheck": "tsc --noEmit"
|
|
45
|
+
}
|
|
46
|
+
}
|