catalyst-core 0.2.0-beta.2 → 0.3.0-beta.1

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 (184) hide show
  1. package/babel.native.config.cjs +8 -0
  2. package/bin/catalyst.js +49 -105
  3. package/changelog.md +8 -0
  4. package/dist/caching.js +1 -1
  5. package/dist/index.jsx +8 -0
  6. package/dist/logger.js +74 -3
  7. package/dist/native/androidProject/app/build.gradle.kts +1 -0
  8. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/CustomWebview.kt +143 -4
  9. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MainActivity.kt +26 -6
  10. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/MetricsMonitor.kt +143 -17
  11. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/NativeBridge.kt +6 -0
  12. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/WebCacheManager.kt +26 -0
  13. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/BridgeUtils.kt +56 -1
  14. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/KeyboardUtil.kt +48 -8
  15. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/PerfDeliveryState.kt +36 -0
  16. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/PerfEventBuffer.kt +289 -0
  17. package/dist/native/androidProject/app/src/main/java/io/yourname/androidproject/utils/ProfilerNavigationState.kt +13 -0
  18. package/dist/native/androidProject/app/src/test/java/io/yourname/androidproject/ProfilerLifecycleTest.kt +51 -0
  19. package/dist/native/androidSetup.js +300 -8
  20. package/dist/native/bridge/WebBridge.js +481 -59
  21. package/dist/native/bridge/constants/NativeInterfaces.js +290 -44
  22. package/dist/native/bridge/errors.js +250 -26
  23. package/dist/native/bridge/hooks/index.js +125 -1
  24. package/dist/native/bridge/hooks/useCamera.js +347 -9
  25. package/dist/native/bridge/hooks/useDataProtection.js +200 -2
  26. package/dist/native/bridge/hooks/useDeviceInfo.js +71 -2
  27. package/dist/native/bridge/hooks/useFilePicker.js +429 -2
  28. package/dist/native/bridge/hooks/useGoogleSignIn.js +81 -1
  29. package/dist/native/bridge/hooks/useHapticFeedback.js +196 -1
  30. package/dist/native/bridge/hooks/useIntent.js +95 -1
  31. package/dist/native/bridge/hooks/useNativeTransition.js +202 -27
  32. package/dist/native/bridge/hooks/useNetworkStatus.js +84 -3
  33. package/dist/native/bridge/hooks/useNotification.js +318 -2
  34. package/dist/native/bridge/hooks/useSafeArea.js +84 -2
  35. package/dist/native/bridge/hooks/useVideoStream.js +434 -6
  36. package/dist/native/bridge/hooks/utils.js +27 -1
  37. package/dist/native/bridge/hooks.js +16 -1
  38. package/dist/native/bridge/perf/collectors/ApiCollector.js +85 -0
  39. package/dist/native/bridge/perf/collectors/CacheCollector.js +215 -0
  40. package/dist/native/bridge/perf/collectors/HookCollector.js +165 -0
  41. package/dist/native/bridge/perf/collectors/InsightsCollector.js +505 -0
  42. package/dist/native/bridge/perf/collectors/InteractionCollector.js +273 -0
  43. package/dist/native/bridge/perf/collectors/KeyboardCollector.js +124 -0
  44. package/dist/native/bridge/perf/collectors/NavigationCollector.js +294 -0
  45. package/dist/native/bridge/perf/collectors/NetworkTimingCollector.js +183 -0
  46. package/dist/native/bridge/perf/collectors/RenderCollector.js +284 -0
  47. package/dist/native/bridge/perf/collectors/ScrollCollector.js +111 -0
  48. package/dist/native/bridge/perf/collectors/ThreadCollector.js +111 -0
  49. package/dist/native/bridge/perf/core/constants.js +126 -0
  50. package/dist/native/bridge/perf/core/measure.js +189 -0
  51. package/dist/native/bridge/perf/core/session.js +100 -0
  52. package/dist/native/bridge/perf/core/store.js +554 -0
  53. package/dist/native/bridge/perf/core/summary.js +174 -0
  54. package/dist/native/bridge/perf/core/traceExport.js +240 -0
  55. package/dist/native/bridge/perf/core/waterfalls.js +146 -0
  56. package/dist/native/bridge/perf/index.js +402 -0
  57. package/dist/native/bridge/safeArea.js +53 -5
  58. package/dist/native/bridge/standardizedHooks.js +595 -82
  59. package/dist/native/bridge/useBaseHook.js +274 -38
  60. package/dist/native/bridge/utils/CameraUtils.js +201 -56
  61. package/dist/native/bridge/utils/FileObjectConverter.js +129 -18
  62. package/dist/native/bridge/utils/NativeBridge.js +425 -141
  63. package/dist/native/buildAndroid/assets.js +510 -13
  64. package/dist/native/buildAndroid/build.js +296 -19
  65. package/dist/native/buildAndroid/config.js +87 -1
  66. package/dist/native/buildAndroid/index.js +374 -1
  67. package/dist/native/buildAppAndroid.js +34 -2
  68. package/dist/native/buildAppIos.js +62 -2
  69. package/dist/native/buildIos/assets.js +609 -8
  70. package/dist/native/buildIos/build.js +639 -20
  71. package/dist/native/buildIos/config.js +294 -12
  72. package/dist/native/buildIos/index.js +343 -6
  73. package/dist/native/buildIos/plugins.js +343 -16
  74. package/dist/native/internal-plugins/device-info-plugin/android/DeviceInfoPlugin.kt +43 -0
  75. package/dist/native/internal-plugins/device-info-plugin/ios/DeviceInfoPlugin.swift +28 -0
  76. package/dist/native/internal-plugins/device-info-plugin/manifest.json +19 -0
  77. package/dist/native/internalPluginUtils.js +232 -7
  78. package/dist/native/iosnativeWebView/Sources/Core/Constants/CatalystConstants.swift +19 -0
  79. package/dist/native/iosnativeWebView/Sources/Core/Constants/ConfigConstants.swift +4 -0
  80. package/dist/native/iosnativeWebView/Sources/Core/Utils/BootTimingUtility.swift +5 -1
  81. package/dist/native/iosnativeWebView/Sources/Core/Utils/CacheManager.swift +10 -0
  82. package/dist/native/iosnativeWebView/Sources/Core/Utils/DisplayLinkPerfMonitor.swift +89 -0
  83. package/dist/native/iosnativeWebView/Sources/Core/Utils/PerfEventBuffer.swift +373 -0
  84. package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeFileHandler.swift +35 -1
  85. package/dist/native/iosnativeWebView/Sources/Core/WebView/BridgeMessageValidator.swift +24 -11
  86. package/dist/native/iosnativeWebView/Sources/Core/WebView/NativeBridge.swift +9 -0
  87. package/dist/native/iosnativeWebView/Sources/Core/WebView/WebView.swift +126 -0
  88. package/dist/native/iosnativeWebView/Sources/Core/WebView/WebViewNavigationDelegate.swift +75 -1
  89. package/dist/native/iosnativeWebView/iosnativeWebViewTests/BridgeMessageValidatorTests.swift +13 -0
  90. package/dist/native/package.json +3 -0
  91. package/dist/native/plugin-bridge/PluginBridge.js +227 -1
  92. package/dist/native/pluginComposerAndroid.js +407 -23
  93. package/dist/native/pluginComposerIos.js +435 -11
  94. package/dist/native/renameAndroidProject.js +1094 -88
  95. package/dist/native/setupEmulatorIos.js +289 -22
  96. package/dist/native/setupServer.js +160 -19
  97. package/dist/native/terminalProgress.js +199 -11
  98. package/dist/native/utils.js +193 -15
  99. package/dist/offline/catalyst-sw.js +145 -1
  100. package/dist/offline/registerServiceWorker.js +33 -1
  101. package/dist/otel.js +375 -46
  102. package/dist/router/ClientRouter.js +14 -2
  103. package/dist/router/ServerRouter.js +9 -1
  104. package/dist/router.js +1 -1
  105. package/dist/scripts/build.js +112 -3
  106. package/dist/scripts/checkVersion.js +3 -1
  107. package/dist/scripts/cleanCache.js +30 -1
  108. package/dist/scripts/generateOfflineManifest.js +116 -1
  109. package/dist/scripts/loadEnvironmentVariables.js +32 -6
  110. package/dist/scripts/plugins.js +309 -1
  111. package/dist/scripts/preServerInit.js +13 -0
  112. package/dist/scripts/scriptUtils.js +54 -3
  113. package/dist/scripts/serve.js +51 -4
  114. package/dist/scripts/start.js +47 -10
  115. package/dist/scripts/validator.js +149 -1
  116. package/dist/sentry.cjs +127 -0
  117. package/dist/sentry.js +125 -5
  118. package/dist/server/expressServer.js +250 -5
  119. package/dist/server/manifestCache.js +36 -0
  120. package/dist/server/renderer/ChunkExtractor.js +144 -0
  121. package/dist/server/renderer/document/Body.jsx +59 -0
  122. package/dist/server/renderer/document/FastRefresh.jsx +20 -0
  123. package/dist/server/renderer/document/Head.jsx +60 -0
  124. package/dist/server/renderer/document/index.jsx +2 -0
  125. package/dist/server/renderer/extract.js +149 -31
  126. package/dist/server/renderer/handler.jsx +433 -0
  127. package/dist/server/renderer/index.js +8 -1
  128. package/dist/server/renderer/render.js +47 -0
  129. package/dist/server/utils/botDetectionMiddleware.js +29 -0
  130. package/dist/server/utils/cjsRequire.js +10 -0
  131. package/dist/server/utils/userAgentUtil.js +87 -9
  132. package/dist/server/utils/validator.js +164 -1
  133. package/dist/vite/FastRefresh.jsx +20 -0
  134. package/dist/vite/inject-cache-key-plugin.js +276 -0
  135. package/dist/vite/loadCustomViteConfig.js +22 -0
  136. package/dist/vite/manifest-categorization-plugin.js +455 -0
  137. package/dist/vite/node-loader.mjs +458 -0
  138. package/dist/vite/scssParams.js +21 -0
  139. package/dist/vite/vite.config.client.js +130 -0
  140. package/dist/vite/vite.config.js +422 -0
  141. package/dist/vite/vite.config.server.js +84 -0
  142. package/dist/web-router/components/MetaTag.jsx +34 -0
  143. package/dist/web-router/components/RouterDataProvider.jsx +332 -0
  144. package/dist/web-router/components/Split.jsx +200 -0
  145. package/dist/web-router/components/SplitInview.jsx +106 -0
  146. package/dist/web-router/components/SsrRequestContext.jsx +14 -0
  147. package/dist/web-router/context.jsx +12 -0
  148. package/dist/web-router/hooks.jsx +72 -0
  149. package/dist/web-router/types/components/MetaTag.d.ts +2 -0
  150. package/dist/web-router/types/components/RouterDataProvider.d.ts +95 -0
  151. package/dist/web-router/types/context.d.ts +14 -0
  152. package/dist/web-router/types/hooks.d.ts +1 -0
  153. package/dist/web-router/types/index.d.ts +3 -0
  154. package/dist/web-router/types/utils/metaDataUtils.d.ts +24 -0
  155. package/dist/web-router/utils/metaDataUtils.jsx +119 -0
  156. package/mcp_v2/conversion-tasks.json +35 -17
  157. package/mcp_v2/knowledge-base.json +124 -13
  158. package/mcp_v2/lib/helpers.js +10 -0
  159. package/mcp_v2/mcp.js +4 -4
  160. package/mcp_v2/package.json +1 -0
  161. package/mcp_v2/tools/build.js +116 -20
  162. package/mcp_v2/tools/conversion.js +106 -5
  163. package/mcp_v2/tools/tasks.js +18 -14
  164. package/package.json +35 -68
  165. package/babel.config.js +0 -32
  166. package/dist/index.js +0 -1
  167. package/dist/scripts/devBuild.js +0 -3
  168. package/dist/scripts/devServe.js +0 -3
  169. package/dist/scripts/loadScriptsBeforeServerStarts.js +0 -4
  170. package/dist/scripts/registerAliases.js +0 -6
  171. package/dist/server/renderer/document/Body.js +0 -11
  172. package/dist/server/renderer/document/Head.js +0 -9
  173. package/dist/server/renderer/document/index.js +0 -1
  174. package/dist/server/renderer/handler.js +0 -47
  175. package/dist/server/startServer.js +0 -57
  176. package/dist/webpack/babel-plugins/remove-client.plugin.js +0 -5
  177. package/dist/webpack/babel-plugins/remove-ssr.plugin.js +0 -5
  178. package/dist/webpack/babel.config.client.js +0 -1
  179. package/dist/webpack/babel.config.ssr.js +0 -1
  180. package/dist/webpack/base.babel.js +0 -7
  181. package/dist/webpack/development.client.babel.js +0 -10
  182. package/dist/webpack/production.client.babel.js +0 -4
  183. package/dist/webpack/production.ssr.babel.js +0 -8
  184. package/dist/webpack/scssParams.js +0 -9
@@ -1,144 +1,428 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports.NativeBridgeUtil=void 0;var _NativeInterfaces=require("../constants/NativeInterfaces.js");/**
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.NativeBridgeUtil = void 0;
7
+ var _NativeInterfaces = require("../constants/NativeInterfaces.js");
8
+ /**
2
9
  * NativeBridge Utility
3
10
  * Handles communication from Web to Native platforms
4
11
  * Supports both Android (window.NativeBridge) and iOS (webkit.messageHandlers)
5
- */class NativeBridgeUtil{constructor(){this.isAndroid=this._detectAndroid();this.isIOS=this._detectIOS();this.isNativeEnvironment=this.isAndroid||this.isIOS;if(typeof window!=="undefined"){this._logEnvironmentInfo();}}/**
6
- * Detect if running on Android WebView
7
- */_detectAndroid(){if(typeof window==="undefined")return false;return!!(window.NativeBridge&&typeof window.NativeBridge==="object");}/**
8
- * Detect if running on iOS WebView
9
- */_detectIOS(){if(typeof window==="undefined")return false;return!!window.webkit?.messageHandlers?.NativeBridge;}/**
10
- * Log environment detection info for debugging
11
- */_logEnvironmentInfo(){console.log("🌉 NativeBridge Environment Detection:",{isAndroid:this.isAndroid,isIOS:this.isIOS,isNativeEnvironment:this.isNativeEnvironment,hasAndroidBridge:!!window.NativeBridge,hasIOSBridge:!!window.webkit?.messageHandlers?.NativeBridge});}/**
12
- * Validate command before execution
13
- */_validateCommand(command){if(!command){throw new Error("Command is required");}if(!(0,_NativeInterfaces.isValidCommand)(command)){throw new Error(`Invalid command: ${command}. Available commands: ${Object.values(_NativeInterfaces.NATIVE_COMMANDS).join(", ")}`);}if(!this.isAvailable()){throw new Error("Native bridge not available. Ensure you are running in a native WebView environment.");}}/**
14
- * Execute command on Android platform
15
- */_executeAndroidCommand(command,data){try{if(typeof window.NativeBridge[command]==="function"){console.log("🌉 Calling Android method",command,data?{data}:"(no data)");// Always pass data parameter to match Kotlin method signatures
16
- window.NativeBridge[command](data);return true;}else{console.error(`Android bridge method '${command}' not found`);return false;}}catch(error){console.error("Error executing Android command:",command,error);return false;}}/**
17
- * Execute command on iOS platform
18
- */_executeIOSCommand(command,data){try{// For iOS, we always send a message object
19
- const message={command:command,data:data// This can be null/undefined, iOS bridge should handle it
20
- };console.log("🌉 Calling iOS method",command,data?{data}:"(no data)");window.webkit.messageHandlers.NativeBridge.postMessage(message);return true;}catch(error){console.error("Error executing iOS command:",command,error);throw error;}}/**
21
- * Main method to call native commands
22
- * @param {string} command - The command to execute (from NATIVE_COMMANDS)
23
- * @param {any} data - Optional data to pass to the native side
24
- * @returns {boolean} - Success status
25
- */call(command,data=null){try{// Validate environment and command
26
- this._validateCommand(command);console.log("🌉 Executing native command:",command,data?{data}:"");// Execute on appropriate platform
27
- if(this.isAndroid){return this._executeAndroidCommand(command,data);}else if(this.isIOS){return this._executeIOSCommand(command,data);}return false;}catch(error){console.error("🌉 Failed to execute command:",command,error);// In development, we might want to show user-friendly errors
28
- if(process.env.NODE_ENV==="development"){console.warn(`🌉 Development mode: Native command '${command}' failed. This is expected when running in browser.`);}throw error;}}/**
29
- * Video stream methods
30
- */videoStream={/**
31
- * Start native camera video stream
32
- * @param {Object} options - Stream options
33
- * facing: 'back' | 'front'
34
- * format: 'qr' | 'barcode' | 'all' — format filter (default: 'all')
35
- * zoom: { auto: true, initial: 1.0 } — auto-zoom via ML Kit, initial is multiplier (1.0=1x)
36
- * zoom: { auto: false, initial: 2.0 } — manual, starts at 2x
37
- */start:(options={})=>this.call(_NativeInterfaces.NATIVE_COMMANDS.START_VIDEO_STREAM,options),/**
38
- * Stop native camera video stream
39
- */stop:()=>this.call(_NativeInterfaces.NATIVE_COMMANDS.STOP_VIDEO_STREAM),/**
40
- * Set zoom level multiplier (e.g. 1.0 = 1x, 2.0 = 2x)
41
- * @param {number} zoomPct - multiplier >= 1.0
42
- */setZoom:zoomPct=>{if(zoomPct==null||typeof zoomPct!=="number"||isNaN(zoomPct)){console.warn("[NativeBridge] setZoom: invalid value, ignoring:",zoomPct);return false;}return this.call(_NativeInterfaces.NATIVE_COMMANDS.SET_VIDEO_STREAM_ZOOM,zoomPct.toString());},/**
43
- * Enable or disable torch (back camera only)
44
- * @param {boolean} on
45
- */setTorch:on=>this.call(_NativeInterfaces.NATIVE_COMMANDS.SET_VIDEO_STREAM_TORCH,JSON.stringify({on:!!on})),/**
46
- * Set target FPS range — triggers session restart
47
- * @param {number|null} min - minimum fps (e.g. 15), null to clear
48
- * @param {number|null} max - maximum fps (e.g. 30), null to clear
49
- */setFps:(min,max)=>this.call(_NativeInterfaces.NATIVE_COMMANDS.SET_VIDEO_STREAM_FPS,JSON.stringify({min:min??null,max:max??null})),/**
50
- * Flip between front and back camera — restarts the native session internally
51
- * Torch resets to off after flip; ON_TORCH_CHANGED(false) fires automatically.
52
- */flip:()=>this.call(_NativeInterfaces.NATIVE_COMMANDS.FLIP_VIDEO_STREAM)};/**
53
- * Camera-specific methods for easier usage
54
- */camera={/**
55
- * Open camera for photo capture
56
- * @param {string} options - JSON string of camera options
57
- */open:(options=null)=>this.call(_NativeInterfaces.NATIVE_COMMANDS.OPEN_CAMERA,options),/**
58
- * Request camera permission
59
- * @param {string} config - JSON string of permission config
60
- */requestPermission:(config=null)=>this.call(_NativeInterfaces.NATIVE_COMMANDS.REQUEST_CAMERA_PERMISSION,config)};/**
61
- * File-specific methods for easier usage
62
- */file={/**
63
- * Open file picker
64
- * @param {string|Object|null} options - MIME type string or options object with advanced config
65
- */pick:(options="*/*")=>{if(options==null){return this.call(_NativeInterfaces.NATIVE_COMMANDS.PICK_FILE,"*/*");}if(typeof options==="string"){const mimeType=options.trim()||"*/*";return this.call(_NativeInterfaces.NATIVE_COMMANDS.PICK_FILE,mimeType);}const payload={...options};if(!payload.mimeType||typeof payload.mimeType!=="string"){payload.mimeType="*/*";}return this.call(_NativeInterfaces.NATIVE_COMMANDS.PICK_FILE,JSON.stringify(payload));},/**
66
- * Open file with external app
67
- * @param {string} fileUrl - URL of the file to open
68
- * @param {string} mimeType - Optional MIME type
69
- */openWithIntent:(fileUrl,mimeType=null)=>{const params=mimeType?`${fileUrl}|${mimeType}`:fileUrl;return this.call(_NativeInterfaces.NATIVE_COMMANDS.OPEN_FILE_WITH_INTENT,params);}};/**
70
- * Network helpers
71
- */network={/**
72
- * Request current network status from native side
73
- */getStatus:()=>this.call(_NativeInterfaces.NATIVE_COMMANDS.GET_NETWORK_STATUS)};/**
74
- * Haptic feedback methods
75
- */haptic={/**
76
- * Request haptic feedback
77
- * @param {string} feedbackType - Type of haptic feedback
78
- */feedback:(feedbackType="light")=>this.call(_NativeInterfaces.NATIVE_COMMANDS.REQUEST_HAPTIC_FEEDBACK,feedbackType)};/**
79
- * Notification methods for local and push notifications
80
- */notification={/**
81
- * Schedule a local notification
82
- * @param {Object} config - Notification configuration object
83
- */scheduleLocal:config=>this.call(_NativeInterfaces.NATIVE_COMMANDS.SCHEDULE_LOCAL_NOTIFICATION,JSON.stringify(config)),/**
84
- * Cancel a local notification
85
- * @param {string} notificationId - ID of the notification to cancel
86
- */cancelLocal:notificationId=>this.call(_NativeInterfaces.NATIVE_COMMANDS.CANCEL_LOCAL_NOTIFICATION,notificationId),/**
87
- * Request notification permission
88
- */requestPermission:()=>this.call(_NativeInterfaces.NATIVE_COMMANDS.REQUEST_NOTIFICATION_PERMISSION),/**
89
- * Register for push notifications
90
- */registerForPush:()=>this.call(_NativeInterfaces.NATIVE_COMMANDS.REGISTER_FOR_PUSH_NOTIFICATIONS),/**
91
- * Update badge count
92
- * @param {number} count - Badge count number
93
- */updateBadge:count=>this.call(_NativeInterfaces.NATIVE_COMMANDS.UPDATE_BADGE_COUNT,count?.toString()),/**
94
- * Subscribe to push notification topic
95
- * @param {string} topic - Topic name to subscribe to
96
- */subscribeToTopic:topic=>this.call(_NativeInterfaces.NATIVE_COMMANDS.SUBSCRIBE_TO_TOPIC,JSON.stringify({topic})),/**
97
- * Unsubscribe from push notification topic
98
- * @param {string} topic - Topic name to unsubscribe from
99
- */unsubscribeFromTopic:topic=>this.call(_NativeInterfaces.NATIVE_COMMANDS.UNSUBSCRIBE_FROM_TOPIC,JSON.stringify({topic})),/**
100
- * Get list of subscribed topics
101
- */getSubscribedTopics:()=>this.call(_NativeInterfaces.NATIVE_COMMANDS.GET_SUBSCRIBED_TOPICS)};/**
102
- * Device info methods
103
- */device={/**
104
- * Get device information
105
- * @returns {Promise} - Returns device info through callback
106
- */getDeviceInfo:()=>this.call(_NativeInterfaces.NATIVE_COMMANDS.GET_DEVICE_INFO)};/**
107
- * Auth methods
108
- */auth={/**
109
- * Trigger Google Sign-In (Credential Manager)
110
- * @param {Object} options - config (clientId, nonce, autoSelect, etc.)
111
- */googleSignIn:(options={})=>{const payload=options&&typeof options==="object"?JSON.stringify(options):options?.toString?.();return this.call(_NativeInterfaces.NATIVE_COMMANDS.GOOGLE_SIGN_IN,payload);}};/** Safe area methods
112
- */safeArea={/**
113
- * Get current safe area insets
114
- * Returns insets through ON_SAFE_AREA_INSETS_UPDATED callback
115
- */get:()=>this.call(_NativeInterfaces.NATIVE_COMMANDS.GET_SAFE_AREA)};/**
116
- * Security methods
117
- */security={/**
118
- * Enable or disable FLAG_SECURE (prevents screenshots / app-switcher caching)
119
- * @param {boolean} enable - true to secure, false to unsecure
120
- */setScreenSecure:enable=>this.call(_NativeInterfaces.NATIVE_COMMANDS.SET_SCREEN_SECURE,JSON.stringify({enable})),/**
121
- * Query current FLAG_SECURE status
122
- * Returns result through ON_SCREEN_SECURE_SET callback
123
- */getScreenSecure:()=>this.call(_NativeInterfaces.NATIVE_COMMANDS.GET_SCREEN_SECURE),/**
124
- * Clear all WebView data (cache, history, cookies, WebStorage)
125
- * Returns result through ON_WEB_DATA_CLEARED / ON_WEB_DATA_CLEAR_ERROR callback
126
- */clearWebData:()=>this.call(_NativeInterfaces.NATIVE_COMMANDS.CLEAR_WEB_DATA)};transition={/**
127
- * Begin a native transition — native takes a snapshot/overlay of the current screen.
128
- * @param {Object} options
129
- * type: 'slide' | 'fade'
130
- * direction: 'left' | 'right' | 'up' | 'down' (slide only)
131
- * duration: number (ms, default 300)
132
- * timeout: number (ms, safety timer — native force-fades overlay if commitTransition is never called)
133
- */start:(options={})=>this.call(_NativeInterfaces.NATIVE_COMMANDS.START_TRANSITION,JSON.stringify(options)),/**
134
- * Commit the transition — native animates the snapshot overlay out, revealing the new page.
135
- */commit:()=>this.call(_NativeInterfaces.NATIVE_COMMANDS.COMMIT_TRANSITION),/**
136
- * Cancel the transition — native removes the overlay immediately without animating.
137
- */cancel:()=>this.call(_NativeInterfaces.NATIVE_COMMANDS.CANCEL_TRANSITION)};/**
138
- * Get environment info
139
- */getEnvironmentInfo(){return{isAndroid:this.isAndroid,isIOS:this.isIOS,isNativeEnvironment:this.isNativeEnvironment,platform:this.isAndroid?"android":this.isIOS?"ios":"web"};}/**
140
- * Check if native bridge is available — live check, never stale
141
- */isAvailable(){return this._detectAndroid()||this._detectIOS();}/**
142
- * Debug method to test native bridge connectivity
143
- */testConnection(){console.group("🌉 NativeBridge Connection Test");console.log("Environment:",this.getEnvironmentInfo());console.log("Available commands:",Object.values(_NativeInterfaces.NATIVE_COMMANDS));if(this.isAndroid&&window.NativeBridge){console.log("Android bridge methods:",Object.getOwnPropertyNames(window.NativeBridge));}if(this.isIOS&&window.webkit?.messageHandlers?.NativeBridge){console.log("iOS webkit bridge available");}console.groupEnd();}}// Export singleton instance
144
- exports.NativeBridgeUtil=NativeBridgeUtil;const nativeBridge=new NativeBridgeUtil();var _default=exports.default=nativeBridge;// Also export the class for advanced usage
12
+ */
13
+ class NativeBridgeUtil {
14
+ constructor() {
15
+ this.isAndroid = this._detectAndroid();
16
+ this.isIOS = this._detectIOS();
17
+ this.isNativeEnvironment = this.isAndroid || this.isIOS;
18
+ if (typeof window !== "undefined") {
19
+ this._logEnvironmentInfo();
20
+ }
21
+ }
22
+
23
+ /**
24
+ * Detect if running on Android WebView
25
+ */
26
+ _detectAndroid() {
27
+ if (typeof window === "undefined") return false;
28
+ return !!(window.NativeBridge && typeof window.NativeBridge === "object");
29
+ }
30
+
31
+ /**
32
+ * Detect if running on iOS WebView
33
+ */
34
+ _detectIOS() {
35
+ if (typeof window === "undefined") return false;
36
+ return !!window.webkit?.messageHandlers?.NativeBridge;
37
+ }
38
+
39
+ /**
40
+ * Log environment detection info for debugging
41
+ */
42
+ _logEnvironmentInfo() {
43
+ console.log("🌉 NativeBridge Environment Detection:", {
44
+ isAndroid: this.isAndroid,
45
+ isIOS: this.isIOS,
46
+ isNativeEnvironment: this.isNativeEnvironment,
47
+ hasAndroidBridge: !!window.NativeBridge,
48
+ hasIOSBridge: !!window.webkit?.messageHandlers?.NativeBridge
49
+ });
50
+ }
51
+
52
+ /**
53
+ * Validate command before execution
54
+ */
55
+ _validateCommand(command) {
56
+ if (!command) {
57
+ throw new Error("Command is required");
58
+ }
59
+ if (!(0, _NativeInterfaces.isValidCommand)(command)) {
60
+ throw new Error(`Invalid command: ${command}. Available commands: ${Object.values(_NativeInterfaces.NATIVE_COMMANDS).join(", ")}`);
61
+ }
62
+ if (!this.isAvailable()) {
63
+ throw new Error("Native bridge not available. Ensure you are running in a native WebView environment.");
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Execute command on Android platform
69
+ */
70
+ _executeAndroidCommand(command, data) {
71
+ try {
72
+ if (typeof window.NativeBridge[command] === "function") {
73
+ console.log("🌉 Calling Android method", command, data ? {
74
+ data
75
+ } : "(no data)");
76
+ // Always pass data parameter to match Kotlin method signatures
77
+ window.NativeBridge[command](data);
78
+ return true;
79
+ } else {
80
+ console.error(`Android bridge method '${command}' not found`);
81
+ return false;
82
+ }
83
+ } catch (error) {
84
+ console.error("Error executing Android command:", command, error);
85
+ return false;
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Execute command on iOS platform
91
+ */
92
+ _executeIOSCommand(command, data) {
93
+ try {
94
+ // For iOS, we always send a message object
95
+ const message = {
96
+ command: command,
97
+ data: data // This can be null/undefined, iOS bridge should handle it
98
+ };
99
+ console.log("🌉 Calling iOS method", command, data ? {
100
+ data
101
+ } : "(no data)");
102
+ window.webkit.messageHandlers.NativeBridge.postMessage(message);
103
+ return true;
104
+ } catch (error) {
105
+ console.error("Error executing iOS command:", command, error);
106
+ throw error;
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Main method to call native commands
112
+ * @param {string} command - The command to execute (from NATIVE_COMMANDS)
113
+ * @param {any} data - Optional data to pass to the native side
114
+ * @returns {boolean} - Success status
115
+ */
116
+ call(command, data = null) {
117
+ try {
118
+ // Validate environment and command
119
+ this._validateCommand(command);
120
+ console.log("🌉 Executing native command:", command, data ? {
121
+ data
122
+ } : "");
123
+
124
+ // Execute on appropriate platform
125
+ if (this.isAndroid) {
126
+ return this._executeAndroidCommand(command, data);
127
+ } else if (this.isIOS) {
128
+ return this._executeIOSCommand(command, data);
129
+ }
130
+ return false;
131
+ } catch (error) {
132
+ console.error("🌉 Failed to execute command:", command, error);
133
+
134
+ // In development, we might want to show user-friendly errors
135
+ if (process.env.NODE_ENV === "development") {
136
+ console.warn(`🌉 Development mode: Native command '${command}' failed. This is expected when running in browser.`);
137
+ }
138
+ throw error;
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Video stream methods
144
+ */
145
+ videoStream = {
146
+ /**
147
+ * Start native camera video stream
148
+ * @param {Object} options - Stream options
149
+ * facing: 'back' | 'front'
150
+ * format: 'qr' | 'barcode' | 'all' — format filter (default: 'all')
151
+ * zoom: { auto: true, initial: 1.0 } — auto-zoom via ML Kit, initial is multiplier (1.0=1x)
152
+ * zoom: { auto: false, initial: 2.0 } — manual, starts at 2x
153
+ */
154
+ start: (options = {}) => this.call(_NativeInterfaces.NATIVE_COMMANDS.START_VIDEO_STREAM, options),
155
+ /**
156
+ * Stop native camera video stream
157
+ */
158
+ stop: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.STOP_VIDEO_STREAM),
159
+ /**
160
+ * Set zoom level multiplier (e.g. 1.0 = 1x, 2.0 = 2x)
161
+ * @param {number} zoomPct - multiplier >= 1.0
162
+ */
163
+ setZoom: zoomPct => {
164
+ if (zoomPct == null || typeof zoomPct !== "number" || isNaN(zoomPct)) {
165
+ console.warn("[NativeBridge] setZoom: invalid value, ignoring:", zoomPct);
166
+ return false;
167
+ }
168
+ return this.call(_NativeInterfaces.NATIVE_COMMANDS.SET_VIDEO_STREAM_ZOOM, zoomPct.toString());
169
+ },
170
+ /**
171
+ * Enable or disable torch (back camera only)
172
+ * @param {boolean} on
173
+ */
174
+ setTorch: on => this.call(_NativeInterfaces.NATIVE_COMMANDS.SET_VIDEO_STREAM_TORCH, JSON.stringify({
175
+ on: !!on
176
+ })),
177
+ /**
178
+ * Set target FPS range — triggers session restart
179
+ * @param {number|null} min - minimum fps (e.g. 15), null to clear
180
+ * @param {number|null} max - maximum fps (e.g. 30), null to clear
181
+ */
182
+ setFps: (min, max) => this.call(_NativeInterfaces.NATIVE_COMMANDS.SET_VIDEO_STREAM_FPS, JSON.stringify({
183
+ min: min ?? null,
184
+ max: max ?? null
185
+ })),
186
+ /**
187
+ * Flip between front and back camera — restarts the native session internally
188
+ * Torch resets to off after flip; ON_TORCH_CHANGED(false) fires automatically.
189
+ */
190
+ flip: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.FLIP_VIDEO_STREAM)
191
+ };
192
+
193
+ /**
194
+ * Camera-specific methods for easier usage
195
+ */
196
+ camera = {
197
+ /**
198
+ * Open camera for photo capture
199
+ * @param {string} options - JSON string of camera options
200
+ */
201
+ open: (options = null) => this.call(_NativeInterfaces.NATIVE_COMMANDS.OPEN_CAMERA, options),
202
+ /**
203
+ * Request camera permission
204
+ * @param {string} config - JSON string of permission config
205
+ */
206
+ requestPermission: (config = null) => this.call(_NativeInterfaces.NATIVE_COMMANDS.REQUEST_CAMERA_PERMISSION, config)
207
+ };
208
+
209
+ /**
210
+ * File-specific methods for easier usage
211
+ */
212
+ file = {
213
+ /**
214
+ * Open file picker
215
+ * @param {string|Object|null} options - MIME type string or options object with advanced config
216
+ */
217
+ pick: (options = "*/*") => {
218
+ if (options == null) {
219
+ return this.call(_NativeInterfaces.NATIVE_COMMANDS.PICK_FILE, "*/*");
220
+ }
221
+ if (typeof options === "string") {
222
+ const mimeType = options.trim() || "*/*";
223
+ return this.call(_NativeInterfaces.NATIVE_COMMANDS.PICK_FILE, mimeType);
224
+ }
225
+ const payload = {
226
+ ...options
227
+ };
228
+ if (!payload.mimeType || typeof payload.mimeType !== "string") {
229
+ payload.mimeType = "*/*";
230
+ }
231
+ return this.call(_NativeInterfaces.NATIVE_COMMANDS.PICK_FILE, JSON.stringify(payload));
232
+ },
233
+ /**
234
+ * Open file with external app
235
+ * @param {string} fileUrl - URL of the file to open
236
+ * @param {string} mimeType - Optional MIME type
237
+ */
238
+ openWithIntent: (fileUrl, mimeType = null) => {
239
+ const params = mimeType ? `${fileUrl}|${mimeType}` : fileUrl;
240
+ return this.call(_NativeInterfaces.NATIVE_COMMANDS.OPEN_FILE_WITH_INTENT, params);
241
+ }
242
+ };
243
+
244
+ /**
245
+ * Network helpers
246
+ */
247
+ network = {
248
+ /**
249
+ * Request current network status from native side
250
+ */
251
+ getStatus: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.GET_NETWORK_STATUS)
252
+ };
253
+
254
+ /**
255
+ * Haptic feedback methods
256
+ */
257
+ haptic = {
258
+ /**
259
+ * Request haptic feedback
260
+ * @param {string} feedbackType - Type of haptic feedback
261
+ */
262
+ feedback: (feedbackType = "light") => this.call(_NativeInterfaces.NATIVE_COMMANDS.REQUEST_HAPTIC_FEEDBACK, feedbackType)
263
+ };
264
+
265
+ /**
266
+ * Notification methods for local and push notifications
267
+ */
268
+ notification = {
269
+ /**
270
+ * Schedule a local notification
271
+ * @param {Object} config - Notification configuration object
272
+ */
273
+ scheduleLocal: config => this.call(_NativeInterfaces.NATIVE_COMMANDS.SCHEDULE_LOCAL_NOTIFICATION, JSON.stringify(config)),
274
+ /**
275
+ * Cancel a local notification
276
+ * @param {string} notificationId - ID of the notification to cancel
277
+ */
278
+ cancelLocal: notificationId => this.call(_NativeInterfaces.NATIVE_COMMANDS.CANCEL_LOCAL_NOTIFICATION, notificationId),
279
+ /**
280
+ * Request notification permission
281
+ */
282
+ requestPermission: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.REQUEST_NOTIFICATION_PERMISSION),
283
+ /**
284
+ * Register for push notifications
285
+ */
286
+ registerForPush: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.REGISTER_FOR_PUSH_NOTIFICATIONS),
287
+ /**
288
+ * Update badge count
289
+ * @param {number} count - Badge count number
290
+ */
291
+ updateBadge: count => this.call(_NativeInterfaces.NATIVE_COMMANDS.UPDATE_BADGE_COUNT, count?.toString()),
292
+ /**
293
+ * Subscribe to push notification topic
294
+ * @param {string} topic - Topic name to subscribe to
295
+ */
296
+ subscribeToTopic: topic => this.call(_NativeInterfaces.NATIVE_COMMANDS.SUBSCRIBE_TO_TOPIC, JSON.stringify({
297
+ topic
298
+ })),
299
+ /**
300
+ * Unsubscribe from push notification topic
301
+ * @param {string} topic - Topic name to unsubscribe from
302
+ */
303
+ unsubscribeFromTopic: topic => this.call(_NativeInterfaces.NATIVE_COMMANDS.UNSUBSCRIBE_FROM_TOPIC, JSON.stringify({
304
+ topic
305
+ })),
306
+ /**
307
+ * Get list of subscribed topics
308
+ */
309
+ getSubscribedTopics: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.GET_SUBSCRIBED_TOPICS)
310
+ };
311
+
312
+ /**
313
+ * Device info methods
314
+ */
315
+ device = {
316
+ /**
317
+ * Get device information
318
+ * @returns {Promise} - Returns device info through callback
319
+ */
320
+ getDeviceInfo: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.GET_DEVICE_INFO)
321
+ };
322
+
323
+ /**
324
+ * Auth methods
325
+ */
326
+ auth = {
327
+ /**
328
+ * Trigger Google Sign-In (Credential Manager)
329
+ * @param {Object} options - config (clientId, nonce, autoSelect, etc.)
330
+ */
331
+ googleSignIn: (options = {}) => {
332
+ const payload = options && typeof options === "object" ? JSON.stringify(options) : options?.toString?.();
333
+ return this.call(_NativeInterfaces.NATIVE_COMMANDS.GOOGLE_SIGN_IN, payload);
334
+ }
335
+ };
336
+
337
+ /** Safe area methods
338
+ */
339
+ safeArea = {
340
+ /**
341
+ * Get current safe area insets
342
+ * Returns insets through ON_SAFE_AREA_INSETS_UPDATED callback
343
+ */
344
+ get: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.GET_SAFE_AREA)
345
+ };
346
+
347
+ /**
348
+ * Security methods
349
+ */
350
+ security = {
351
+ /**
352
+ * Enable or disable FLAG_SECURE (prevents screenshots / app-switcher caching)
353
+ * @param {boolean} enable - true to secure, false to unsecure
354
+ */
355
+ setScreenSecure: enable => this.call(_NativeInterfaces.NATIVE_COMMANDS.SET_SCREEN_SECURE, JSON.stringify({
356
+ enable
357
+ })),
358
+ /**
359
+ * Query current FLAG_SECURE status
360
+ * Returns result through ON_SCREEN_SECURE_SET callback
361
+ */
362
+ getScreenSecure: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.GET_SCREEN_SECURE),
363
+ /**
364
+ * Clear all WebView data (cache, history, cookies, WebStorage)
365
+ * Returns result through ON_WEB_DATA_CLEARED / ON_WEB_DATA_CLEAR_ERROR callback
366
+ */
367
+ clearWebData: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.CLEAR_WEB_DATA)
368
+ };
369
+ transition = {
370
+ /**
371
+ * Begin a native transition — native takes a snapshot/overlay of the current screen.
372
+ * @param {Object} options
373
+ * type: 'slide' | 'fade'
374
+ * direction: 'left' | 'right' | 'up' | 'down' (slide only)
375
+ * duration: number (ms, default 300)
376
+ * timeout: number (ms, safety timer — native force-fades overlay if commitTransition is never called)
377
+ */
378
+ start: (options = {}) => this.call(_NativeInterfaces.NATIVE_COMMANDS.START_TRANSITION, JSON.stringify(options)),
379
+ /**
380
+ * Commit the transition — native animates the snapshot overlay out, revealing the new page.
381
+ */
382
+ commit: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.COMMIT_TRANSITION),
383
+ /**
384
+ * Cancel the transition — native removes the overlay immediately without animating.
385
+ */
386
+ cancel: () => this.call(_NativeInterfaces.NATIVE_COMMANDS.CANCEL_TRANSITION)
387
+ };
388
+
389
+ /**
390
+ * Get environment info
391
+ */
392
+ getEnvironmentInfo() {
393
+ return {
394
+ isAndroid: this.isAndroid,
395
+ isIOS: this.isIOS,
396
+ isNativeEnvironment: this.isNativeEnvironment,
397
+ platform: this.isAndroid ? "android" : this.isIOS ? "ios" : "web"
398
+ };
399
+ }
400
+
401
+ /**
402
+ * Check if native bridge is available — live check, never stale
403
+ */
404
+ isAvailable() {
405
+ return this._detectAndroid() || this._detectIOS();
406
+ }
407
+
408
+ /**
409
+ * Debug method to test native bridge connectivity
410
+ */
411
+ testConnection() {
412
+ console.group("🌉 NativeBridge Connection Test");
413
+ console.log("Environment:", this.getEnvironmentInfo());
414
+ console.log("Available commands:", Object.values(_NativeInterfaces.NATIVE_COMMANDS));
415
+ if (this.isAndroid && window.NativeBridge) {
416
+ console.log("Android bridge methods:", Object.getOwnPropertyNames(window.NativeBridge));
417
+ }
418
+ if (this.isIOS && window.webkit?.messageHandlers?.NativeBridge) {
419
+ console.log("iOS webkit bridge available");
420
+ }
421
+ console.groupEnd();
422
+ }
423
+ }
424
+
425
+ // Export singleton instance
426
+ exports.NativeBridgeUtil = NativeBridgeUtil;
427
+ const nativeBridge = new NativeBridgeUtil();
428
+ var _default = exports.default = nativeBridge; // Also export the class for advanced usage