@thinkersteps_labs/3d-viewer-react-native 0.0.0-stage → 1.0.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 (54) hide show
  1. package/dist/Viewer.d.ts +5 -0
  2. package/dist/Viewer.d.ts.map +1 -0
  3. package/dist/Viewer.js +73 -0
  4. package/dist/Viewer.js.map +1 -0
  5. package/dist/bridge/ar-launcher.d.ts +6 -0
  6. package/dist/bridge/ar-launcher.d.ts.map +1 -0
  7. package/dist/bridge/ar-launcher.js +18 -0
  8. package/dist/bridge/ar-launcher.js.map +1 -0
  9. package/dist/bridge/runtime-bundle.d.ts +2 -0
  10. package/dist/bridge/runtime-bundle.d.ts.map +1 -0
  11. package/dist/bridge/runtime-bundle.js +3 -0
  12. package/dist/bridge/runtime-bundle.js.map +1 -0
  13. package/dist/bridge/types.d.ts +110 -0
  14. package/dist/bridge/types.d.ts.map +1 -0
  15. package/dist/bridge/types.js +2 -0
  16. package/dist/bridge/types.js.map +1 -0
  17. package/dist/hooks/useViewerBridge.d.ts +16 -0
  18. package/dist/hooks/useViewerBridge.d.ts.map +1 -0
  19. package/dist/hooks/useViewerBridge.js +378 -0
  20. package/dist/hooks/useViewerBridge.js.map +1 -0
  21. package/dist/hooks/useViewerGestureLock.d.ts +23 -0
  22. package/dist/hooks/useViewerGestureLock.d.ts.map +1 -0
  23. package/dist/hooks/useViewerGestureLock.js +49 -0
  24. package/dist/hooks/useViewerGestureLock.js.map +1 -0
  25. package/dist/index.d.ts +9 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +7 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/swatches/JewelryCustomizer.d.ts +13 -0
  30. package/dist/swatches/JewelryCustomizer.d.ts.map +1 -0
  31. package/dist/swatches/JewelryCustomizer.js +28 -0
  32. package/dist/swatches/JewelryCustomizer.js.map +1 -0
  33. package/dist/swatches/MetalSwatches.d.ts +13 -0
  34. package/dist/swatches/MetalSwatches.d.ts.map +1 -0
  35. package/dist/swatches/MetalSwatches.js +81 -0
  36. package/dist/swatches/MetalSwatches.js.map +1 -0
  37. package/dist/swatches/StoneSwatches.d.ts +13 -0
  38. package/dist/swatches/StoneSwatches.d.ts.map +1 -0
  39. package/dist/swatches/StoneSwatches.js +81 -0
  40. package/dist/swatches/StoneSwatches.js.map +1 -0
  41. package/dist/swatches/index.d.ts +5 -0
  42. package/dist/swatches/index.d.ts.map +1 -0
  43. package/dist/swatches/index.js +5 -0
  44. package/dist/swatches/index.js.map +1 -0
  45. package/dist/swatches/useJewelryCustomizer.d.ts +23 -0
  46. package/dist/swatches/useJewelryCustomizer.d.ts.map +1 -0
  47. package/dist/swatches/useJewelryCustomizer.js +25 -0
  48. package/dist/swatches/useJewelryCustomizer.js.map +1 -0
  49. package/dist/types.d.ts +66 -0
  50. package/dist/types.d.ts.map +1 -0
  51. package/dist/types.js +2 -0
  52. package/dist/types.js.map +1 -0
  53. package/package.json +48 -4
  54. package/README.md +0 -3
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import type { ViewerProps, ViewerRef } from './types.js';
3
+ export declare const Viewer: React.ForwardRefExoticComponent<ViewerProps & React.RefAttributes<ViewerRef>>;
4
+ export default Viewer;
5
+ //# sourceMappingURL=Viewer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Viewer.d.ts","sourceRoot":"","sources":["../src/Viewer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoD,MAAM,OAAO,CAAA;AAUxE,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAOxD,eAAO,MAAM,MAAM,+EAkGjB,CAAA;AAoDF,eAAe,MAAM,CAAA"}
package/dist/Viewer.js ADDED
@@ -0,0 +1,73 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useImperativeHandle, useState } from 'react';
3
+ import { View, Modal, TouchableOpacity, Text, StyleSheet, } from 'react-native';
4
+ import { WebView } from 'react-native-webview';
5
+ import { useViewerBridge } from './hooks/useViewerBridge.js';
6
+ import { useViewerGestureLock } from './hooks/useViewerGestureLock.js';
7
+ import { DEFAULT_EMBEDDED_HTML } from './bridge/runtime-bundle.js';
8
+ const RNWebView = WebView;
9
+ export const Viewer = forwardRef(function Viewer(props, ref) {
10
+ const { viewerUrl, scrollRef, fullscreenButton = false, onTouchInteractionChange, style, } = props;
11
+ const [isFullscreen, setIsFullscreen] = useState(false);
12
+ const { webViewRef, viewerRefMethods, handleMessage, handleWebViewProcessTerminated, } = useViewerBridge(props);
13
+ const { containerTouchProps } = useViewerGestureLock({
14
+ scrollRef,
15
+ onTouchInteractionChange,
16
+ });
17
+ useImperativeHandle(ref, () => viewerRefMethods, [viewerRefMethods]);
18
+ const webViewSource = viewerUrl
19
+ ? { uri: viewerUrl }
20
+ : { html: DEFAULT_EMBEDDED_HTML, baseUrl: 'file:///' };
21
+ return (_jsxs(View, { style: [styles.container, style], ...containerTouchProps, children: [_jsx(RNWebView, { ref: webViewRef, source: webViewSource, originWhitelist: ['*'], javaScriptEnabled: true, domStorageEnabled: true, allowFileAccess: true, allowFileAccessFromFileURLs: true, allowUniversalAccessFromFileURLs: true, androidLayerType: "hardware", allowsInlineMediaPlayback: true, mediaPlaybackRequiresUserAction: false, allowingReadAccessToURL: "file:///", onMessage: handleMessage, onContentProcessDidTerminate: handleWebViewProcessTerminated, onRenderProcessGone: handleWebViewProcessTerminated, style: styles.webview }), fullscreenButton && (_jsx(TouchableOpacity, { accessibilityLabel: "Expand 3D Viewer", onPress: () => setIsFullscreen(true), style: styles.fullscreenBtn, children: _jsx(Text, { style: styles.fullscreenIcon, children: "\u26F6" }) })), fullscreenButton && (_jsx(Modal, { visible: isFullscreen, animationType: "fade", onRequestClose: () => setIsFullscreen(false), children: _jsxs(View, { style: styles.modalContainer, children: [_jsx(TouchableOpacity, { accessibilityLabel: "Close Fullscreen", onPress: () => setIsFullscreen(false), style: styles.closeBtn, children: _jsx(Text, { style: styles.closeText, children: "\u2715" }) }), _jsx(RNWebView, { source: webViewSource, originWhitelist: ['*'], javaScriptEnabled: true, domStorageEnabled: true, allowFileAccess: true, allowFileAccessFromFileURLs: true, allowUniversalAccessFromFileURLs: true, androidLayerType: "hardware", allowsInlineMediaPlayback: true, mediaPlaybackRequiresUserAction: false, allowingReadAccessToURL: "file:///", onMessage: handleMessage, style: styles.webview })] }) }))] }));
22
+ });
23
+ const styles = StyleSheet.create({
24
+ container: {
25
+ position: 'relative',
26
+ width: '100%',
27
+ height: '100%',
28
+ overflow: 'hidden',
29
+ },
30
+ webview: {
31
+ flex: 1,
32
+ backgroundColor: 'transparent',
33
+ },
34
+ fullscreenBtn: {
35
+ position: 'absolute',
36
+ top: 12,
37
+ right: 12,
38
+ zIndex: 10,
39
+ backgroundColor: 'rgba(0, 0, 0, 0.6)',
40
+ paddingHorizontal: 10,
41
+ paddingVertical: 6,
42
+ borderRadius: 6,
43
+ },
44
+ fullscreenIcon: {
45
+ color: '#ffffff',
46
+ fontSize: 14,
47
+ fontWeight: 'bold',
48
+ },
49
+ modalContainer: {
50
+ flex: 1,
51
+ backgroundColor: '#000000',
52
+ position: 'relative',
53
+ },
54
+ closeBtn: {
55
+ position: 'absolute',
56
+ top: 40,
57
+ right: 20,
58
+ zIndex: 20,
59
+ backgroundColor: 'rgba(255, 255, 255, 0.25)',
60
+ width: 36,
61
+ height: 36,
62
+ borderRadius: 18,
63
+ alignItems: 'center',
64
+ justifyContent: 'center',
65
+ },
66
+ closeText: {
67
+ color: '#ffffff',
68
+ fontSize: 18,
69
+ fontWeight: 'bold',
70
+ },
71
+ });
72
+ export default Viewer;
73
+ //# sourceMappingURL=Viewer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Viewer.js","sourceRoot":"","sources":["../src/Viewer.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,UAAU,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;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AAQ,EAAE,EAAE;QACZ,UAAU,EAAE,MAAM;KACnB;CACF,CAAC,CAAA;AAEF,eAAe,MAAM,CAAA"}
@@ -0,0 +1,6 @@
1
+ export declare function buildAndroidSceneViewerIntent(glbUrl: string): string;
2
+ export declare function launchPlatformAR(options: {
3
+ platform: 'ios' | 'android';
4
+ url: string;
5
+ }): Promise<void>;
6
+ //# sourceMappingURL=ar-launcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ar-launcher.d.ts","sourceRoot":"","sources":["../../src/bridge/ar-launcher.ts"],"names":[],"mappings":"AAGA,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAGpE;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE;IAC9C,QAAQ,EAAE,KAAK,GAAG,SAAS,CAAA;IAC3B,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,OAAO,CAAC,IAAI,CAAC,CAchB"}
@@ -0,0 +1,18 @@
1
+ import { Linking } from 'react-native';
2
+ export function buildAndroidSceneViewerIntent(glbUrl) {
3
+ const encodedGlb = encodeURIComponent(glbUrl);
4
+ return `intent://arvr.google.com/scene-viewer/1.0?file=${encodedGlb}&mode=ar_only#Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;end;`;
5
+ }
6
+ export async function launchPlatformAR(options) {
7
+ const targetUrl = options.platform === 'android'
8
+ ? buildAndroidSceneViewerIntent(options.url)
9
+ : options.url;
10
+ const canOpen = await Linking.canOpenURL(targetUrl).catch(() => false);
11
+ if (!canOpen) {
12
+ const err = new Error('AR not supported on this device');
13
+ err.code = 'AR_UNSUPPORTED';
14
+ throw err;
15
+ }
16
+ await Linking.openURL(targetUrl);
17
+ }
18
+ //# sourceMappingURL=ar-launcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ar-launcher.js","sourceRoot":"","sources":["../../src/bridge/ar-launcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC,MAAM,UAAU,6BAA6B,CAAC,MAAc;IAC1D,MAAM,UAAU,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAA;IAC7C,OAAO,kDAAkD,UAAU,qGAAqG,CAAA;AAC1K,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAGtC;IACC,MAAM,SAAS,GACb,OAAO,CAAC,QAAQ,KAAK,SAAS;QAC5B,CAAC,CAAC,6BAA6B,CAAC,OAAO,CAAC,GAAG,CAAC;QAC5C,CAAC,CAAC,OAAO,CAAC,GAAG,CAAA;IAEjB,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAA;IACtE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,iCAAiC,CAAgB,CAAA;QACvE,GAAG,CAAC,IAAI,GAAG,gBAAgB,CAAA;QAC3B,MAAM,GAAG,CAAA;IACX,CAAC;IAED,MAAM,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;AAClC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_EMBEDDED_HTML = "<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\" />\n <style>\n * { margin: 0; padding: 0; box-sizing: border-box; }\n html, body { width: 100%; height: 100%; overflow: hidden; background: transparent; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }\n #viewer-container { width: 100%; height: 100%; position: relative; }\n canvas#viewer-canvas { width: 100% !important; height: 100% !important; display: block; touch-action: none; }\n #ar-anchor { display: none; }\n </style>\n</head>\n<body>\n <div id=\"viewer-container\">\n <canvas id=\"viewer-canvas\"></canvas>\n <a id=\"ar-anchor\" rel=\"ar\" href=\"#\"><img alt=\"AR\" /></a>\n </div>\n <script>\n (function() {\n function postToRN(msg) {\n if (window.ReactNativeWebView && window.ReactNativeWebView.postMessage) {\n window.ReactNativeWebView.postMessage(JSON.stringify(msg));\n }\n }\n\n window.addEventListener('pagehide', function() {\n if (window.__viewer && typeof window.__viewer.dispose === 'function') {\n try { window.__viewer.dispose(); } catch(e) {}\n }\n });\n\n window.addEventListener('beforeunload', function() {\n if (window.__viewer && typeof window.__viewer.dispose === 'function') {\n try { window.__viewer.dispose(); } catch(e) {}\n }\n });\n\n document.addEventListener('visibilitychange', function() {\n if (document.hidden && window.__viewer && typeof window.__viewer.stopRotation === 'function') {\n try { window.__viewer.stopRotation(); } catch(e) {}\n }\n });\n\n window.addEventListener('DOMContentLoaded', function() {\n postToRN({ type: 'VIEWER_READY' });\n });\n\n // Also dispatch immediately in case DOMContentLoaded already fired before script execution\n if (document.readyState === 'complete' || document.readyState === 'interactive') {\n postToRN({ type: 'VIEWER_READY' });\n }\n\n window.addEventListener('message', function(e) {\n let cmd;\n try { cmd = typeof e.data === 'string' ? JSON.parse(e.data) : e.data; } catch(err) { return; }\n if (!cmd || !cmd.type) return;\n\n if (cmd.type === 'EXPORT_AR_PAYLOAD' && cmd.platform === 'ios' && cmd.usdzUrl) {\n const anchor = document.getElementById('ar-anchor');\n if (anchor) {\n anchor.setAttribute('href', cmd.usdzUrl);\n anchor.click();\n postToRN({ type: 'AR_PAYLOAD_READY', reqId: cmd.reqId, url: cmd.usdzUrl, launchedInWebView: true });\n }\n }\n });\n })();\n <\\/script>\n</body>\n</html>";
2
+ //# sourceMappingURL=runtime-bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-bundle.d.ts","sourceRoot":"","sources":["../../src/bridge/runtime-bundle.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,qBAAqB,yvFAAyvF,CAAC"}
@@ -0,0 +1,3 @@
1
+ // Auto-generated by scripts/bundle-runtime.mjs - DO NOT EDIT MANUALLY
2
+ export const DEFAULT_EMBEDDED_HTML = "<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\" />\n <style>\n * { margin: 0; padding: 0; box-sizing: border-box; }\n html, body { width: 100%; height: 100%; overflow: hidden; background: transparent; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }\n #viewer-container { width: 100%; height: 100%; position: relative; }\n canvas#viewer-canvas { width: 100% !important; height: 100% !important; display: block; touch-action: none; }\n #ar-anchor { display: none; }\n </style>\n</head>\n<body>\n <div id=\"viewer-container\">\n <canvas id=\"viewer-canvas\"></canvas>\n <a id=\"ar-anchor\" rel=\"ar\" href=\"#\"><img alt=\"AR\" /></a>\n </div>\n <script>\n (function() {\n function postToRN(msg) {\n if (window.ReactNativeWebView && window.ReactNativeWebView.postMessage) {\n window.ReactNativeWebView.postMessage(JSON.stringify(msg));\n }\n }\n\n window.addEventListener('pagehide', function() {\n if (window.__viewer && typeof window.__viewer.dispose === 'function') {\n try { window.__viewer.dispose(); } catch(e) {}\n }\n });\n\n window.addEventListener('beforeunload', function() {\n if (window.__viewer && typeof window.__viewer.dispose === 'function') {\n try { window.__viewer.dispose(); } catch(e) {}\n }\n });\n\n document.addEventListener('visibilitychange', function() {\n if (document.hidden && window.__viewer && typeof window.__viewer.stopRotation === 'function') {\n try { window.__viewer.stopRotation(); } catch(e) {}\n }\n });\n\n window.addEventListener('DOMContentLoaded', function() {\n postToRN({ type: 'VIEWER_READY' });\n });\n\n // Also dispatch immediately in case DOMContentLoaded already fired before script execution\n if (document.readyState === 'complete' || document.readyState === 'interactive') {\n postToRN({ type: 'VIEWER_READY' });\n }\n\n window.addEventListener('message', function(e) {\n let cmd;\n try { cmd = typeof e.data === 'string' ? JSON.parse(e.data) : e.data; } catch(err) { return; }\n if (!cmd || !cmd.type) return;\n\n if (cmd.type === 'EXPORT_AR_PAYLOAD' && cmd.platform === 'ios' && cmd.usdzUrl) {\n const anchor = document.getElementById('ar-anchor');\n if (anchor) {\n anchor.setAttribute('href', cmd.usdzUrl);\n anchor.click();\n postToRN({ type: 'AR_PAYLOAD_READY', reqId: cmd.reqId, url: cmd.usdzUrl, launchedInWebView: true });\n }\n }\n });\n })();\n <\\/script>\n</body>\n</html>";
3
+ //# sourceMappingURL=runtime-bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-bundle.js","sourceRoot":"","sources":["../../src/bridge/runtime-bundle.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,MAAM,CAAC,MAAM,qBAAqB,GAAG,svFAAsvF,CAAC"}
@@ -0,0 +1,110 @@
1
+ import type { MetalColorProp, StoneColorProp, ViewerSourceInput, PartInfo, MaterialSlotInfo, PartType, ViewerErrorCode } from '../types.js';
2
+ export interface CameraSphericalState {
3
+ radius: number;
4
+ phi: number;
5
+ theta: number;
6
+ target: [number, number, number];
7
+ }
8
+ export interface ViewerConfigState {
9
+ metalColor?: MetalColorProp;
10
+ stoneColor?: StoneColorProp;
11
+ materialColors?: Record<string, string>;
12
+ partColors?: Record<string, string>;
13
+ environment?: string;
14
+ exposure?: number;
15
+ quality?: 'low' | 'medium' | 'high';
16
+ autoRotate?: boolean;
17
+ fov?: number;
18
+ shadows?: boolean;
19
+ background?: string | number;
20
+ cameraState?: CameraSphericalState;
21
+ }
22
+ export type OutboundCommand = {
23
+ type: 'LOAD_MODEL';
24
+ source: ViewerSourceInput;
25
+ } | {
26
+ type: 'APPLY_CONFIG';
27
+ config: Partial<ViewerConfigState>;
28
+ } | {
29
+ type: 'SET_METAL';
30
+ color: MetalColorProp;
31
+ } | {
32
+ type: 'SET_STONE';
33
+ color: StoneColorProp;
34
+ } | {
35
+ type: 'SET_MATERIAL_COLOR';
36
+ slotId: string;
37
+ color: string;
38
+ } | {
39
+ type: 'CLEAR_MATERIAL_COLOR';
40
+ slotId: string;
41
+ } | {
42
+ type: 'SET_PART_COLOR';
43
+ partId: string;
44
+ color: string;
45
+ slotIndex?: number;
46
+ } | {
47
+ type: 'CLEAR_PART_COLOR';
48
+ partId: string;
49
+ slotIndex?: number;
50
+ } | {
51
+ type: 'SET_ENVIRONMENT';
52
+ environment?: string;
53
+ exposure?: number;
54
+ } | {
55
+ type: 'SET_AUTO_ROTATE';
56
+ enabled: boolean;
57
+ } | {
58
+ type: 'SET_RENDER_ACTIVE';
59
+ active: boolean;
60
+ } | {
61
+ type: 'SET_QUALITY';
62
+ quality: 'low' | 'medium' | 'high';
63
+ } | {
64
+ type: 'RESET_CAMERA';
65
+ } | {
66
+ type: 'CAPTURE_SNAPSHOT';
67
+ reqId: string;
68
+ format?: 'png' | 'jpeg';
69
+ quality?: number;
70
+ } | {
71
+ type: 'EXPORT_AR_PAYLOAD';
72
+ reqId: string;
73
+ platform: 'ios' | 'android';
74
+ usdzUrl?: string;
75
+ };
76
+ export type InboundEvent = {
77
+ type: 'VIEWER_READY';
78
+ } | {
79
+ type: 'VIEWER_LOADED';
80
+ parts: PartInfo[];
81
+ materials: MaterialSlotInfo[];
82
+ } | {
83
+ type: 'VIEWER_PROGRESS';
84
+ progress: number;
85
+ } | {
86
+ type: 'PART_SELECTED';
87
+ meshId: string;
88
+ partId?: string;
89
+ partType: PartType;
90
+ } | {
91
+ type: 'INTERACTION_START';
92
+ } | {
93
+ type: 'INTERACTION_END';
94
+ cameraState?: CameraSphericalState;
95
+ } | {
96
+ type: 'SNAPSHOT_READY';
97
+ reqId: string;
98
+ dataUrl: string;
99
+ } | {
100
+ type: 'AR_PAYLOAD_READY';
101
+ reqId: string;
102
+ url: string;
103
+ launchedInWebView?: boolean;
104
+ } | {
105
+ type: 'VIEWER_ERROR';
106
+ code: ViewerErrorCode;
107
+ message: string;
108
+ reqId?: string;
109
+ };
110
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/bridge/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAC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AK,EAAE,QAAQ,EAAE,CAAC;IAAC,SAAS,EAAE,gBAAgB,EAAE,CAAA;CAAE,GAC3E;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,GAC9E;IAAE,IAAI,EAAE,mBAAmB,CAAA;CAAE,GAC7B;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,WAAW,CAAC,EAAE,oBAAoB,CAAA;CAAE,GAC/D;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAE,GACrF;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/bridge/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ import type { WebView, WebViewMessageEvent } from 'react-native-webview';
2
+ import type { ViewerConfigState } from '../bridge/types.js';
3
+ import type { ViewerProps, ViewerRef, ViewerError, ViewerErrorCode, ViewerSourceInput } from '../types.js';
4
+ export declare function createViewerError(code: ViewerErrorCode, message: string, reqId?: string): ViewerError;
5
+ export declare function useViewerBridge(props: ViewerProps): {
6
+ webViewRef: import("react").MutableRefObject<WebView<undefined> | null>;
7
+ isReady: boolean;
8
+ viewerRefMethods: ViewerRef;
9
+ handleMessage: (event: WebViewMessageEvent) => void;
10
+ handleWebViewProcessTerminated: () => void;
11
+ lastKnownStateRef: import("react").MutableRefObject<{
12
+ source?: ViewerSourceInput;
13
+ config: ViewerConfigState;
14
+ }>;
15
+ };
16
+ //# sourceMappingURL=useViewerBridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useViewerBridge.d.ts","sourceRoot":"","sources":["../../src/hooks/useViewerBridge.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,WAAW,EACX,eAAe,EACf,iBAAiB,EAGlB,MAAM,aAAa,CAAA;AAWpB,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,GACb,WAAW,CAMb;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW;;;;2BA2EtC,mBAAmB;;;iBA7DlB,iBAAiB;gBAClB,iBAAiB;;EAyT5B"}