catalyst-core 0.2.0-beta.3 → 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 (160) 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/androidSetup.js +300 -8
  8. package/dist/native/bridge/WebBridge.js +481 -59
  9. package/dist/native/bridge/constants/NativeInterfaces.js +290 -45
  10. package/dist/native/bridge/errors.js +250 -26
  11. package/dist/native/bridge/hooks/index.js +125 -1
  12. package/dist/native/bridge/hooks/useCamera.js +347 -9
  13. package/dist/native/bridge/hooks/useDataProtection.js +200 -2
  14. package/dist/native/bridge/hooks/useDeviceInfo.js +71 -2
  15. package/dist/native/bridge/hooks/useFilePicker.js +429 -2
  16. package/dist/native/bridge/hooks/useGoogleSignIn.js +81 -1
  17. package/dist/native/bridge/hooks/useHapticFeedback.js +196 -1
  18. package/dist/native/bridge/hooks/useIntent.js +95 -1
  19. package/dist/native/bridge/hooks/useNativeTransition.js +202 -27
  20. package/dist/native/bridge/hooks/useNetworkStatus.js +84 -3
  21. package/dist/native/bridge/hooks/useNotification.js +318 -2
  22. package/dist/native/bridge/hooks/useSafeArea.js +84 -2
  23. package/dist/native/bridge/hooks/useVideoStream.js +434 -6
  24. package/dist/native/bridge/hooks/utils.js +27 -1
  25. package/dist/native/bridge/hooks.js +16 -1
  26. package/dist/native/bridge/perf/collectors/ApiCollector.js +66 -3
  27. package/dist/native/bridge/perf/collectors/CacheCollector.js +186 -11
  28. package/dist/native/bridge/perf/collectors/HookCollector.js +141 -19
  29. package/dist/native/bridge/perf/collectors/InsightsCollector.js +481 -23
  30. package/dist/native/bridge/perf/collectors/InteractionCollector.js +245 -10
  31. package/dist/native/bridge/perf/collectors/KeyboardCollector.js +107 -8
  32. package/dist/native/bridge/perf/collectors/NavigationCollector.js +273 -32
  33. package/dist/native/bridge/perf/collectors/NetworkTimingCollector.js +178 -2
  34. package/dist/native/bridge/perf/collectors/RenderCollector.js +258 -14
  35. package/dist/native/bridge/perf/collectors/ScrollCollector.js +95 -9
  36. package/dist/native/bridge/perf/collectors/ThreadCollector.js +90 -6
  37. package/dist/native/bridge/perf/core/constants.js +103 -20
  38. package/dist/native/bridge/perf/core/measure.js +179 -30
  39. package/dist/native/bridge/perf/core/session.js +89 -23
  40. package/dist/native/bridge/perf/core/store.js +554 -1
  41. package/dist/native/bridge/perf/core/summary.js +174 -1
  42. package/dist/native/bridge/perf/core/traceExport.js +240 -1
  43. package/dist/native/bridge/perf/core/waterfalls.js +146 -1
  44. package/dist/native/bridge/perf/index.js +359 -38
  45. package/dist/native/bridge/safeArea.js +53 -5
  46. package/dist/native/bridge/standardizedHooks.js +595 -82
  47. package/dist/native/bridge/useBaseHook.js +274 -38
  48. package/dist/native/bridge/utils/CameraUtils.js +201 -56
  49. package/dist/native/bridge/utils/FileObjectConverter.js +129 -18
  50. package/dist/native/bridge/utils/NativeBridge.js +425 -141
  51. package/dist/native/buildAndroid/assets.js +510 -13
  52. package/dist/native/buildAndroid/build.js +296 -19
  53. package/dist/native/buildAndroid/config.js +87 -1
  54. package/dist/native/buildAndroid/index.js +374 -1
  55. package/dist/native/buildAppAndroid.js +34 -2
  56. package/dist/native/buildAppIos.js +62 -2
  57. package/dist/native/buildIos/assets.js +609 -8
  58. package/dist/native/buildIos/build.js +639 -20
  59. package/dist/native/buildIos/config.js +294 -12
  60. package/dist/native/buildIos/index.js +343 -6
  61. package/dist/native/buildIos/plugins.js +343 -16
  62. package/dist/native/internal-plugins/device-info-plugin/android/DeviceInfoPlugin.kt +43 -0
  63. package/dist/native/internal-plugins/device-info-plugin/ios/DeviceInfoPlugin.swift +28 -0
  64. package/dist/native/internal-plugins/device-info-plugin/manifest.json +19 -0
  65. package/dist/native/internalPluginUtils.js +232 -7
  66. package/dist/native/package.json +3 -0
  67. package/dist/native/plugin-bridge/PluginBridge.js +227 -1
  68. package/dist/native/pluginComposerAndroid.js +407 -23
  69. package/dist/native/pluginComposerIos.js +435 -11
  70. package/dist/native/renameAndroidProject.js +1094 -88
  71. package/dist/native/setupEmulatorIos.js +289 -22
  72. package/dist/native/setupServer.js +160 -19
  73. package/dist/native/terminalProgress.js +199 -11
  74. package/dist/native/utils.js +193 -15
  75. package/dist/offline/catalyst-sw.js +145 -1
  76. package/dist/offline/registerServiceWorker.js +33 -1
  77. package/dist/otel.js +375 -46
  78. package/dist/router/ClientRouter.js +14 -2
  79. package/dist/router/ServerRouter.js +9 -1
  80. package/dist/router.js +1 -1
  81. package/dist/scripts/build.js +112 -3
  82. package/dist/scripts/checkVersion.js +3 -1
  83. package/dist/scripts/cleanCache.js +30 -1
  84. package/dist/scripts/generateOfflineManifest.js +116 -1
  85. package/dist/scripts/loadEnvironmentVariables.js +32 -6
  86. package/dist/scripts/plugins.js +309 -1
  87. package/dist/scripts/preServerInit.js +13 -0
  88. package/dist/scripts/scriptUtils.js +54 -3
  89. package/dist/scripts/serve.js +51 -4
  90. package/dist/scripts/start.js +47 -10
  91. package/dist/scripts/validator.js +149 -1
  92. package/dist/sentry.cjs +127 -0
  93. package/dist/sentry.js +125 -5
  94. package/dist/server/expressServer.js +250 -5
  95. package/dist/server/manifestCache.js +36 -0
  96. package/dist/server/renderer/ChunkExtractor.js +144 -0
  97. package/dist/server/renderer/document/Body.jsx +59 -0
  98. package/dist/server/renderer/document/FastRefresh.jsx +20 -0
  99. package/dist/server/renderer/document/Head.jsx +60 -0
  100. package/dist/server/renderer/document/index.jsx +2 -0
  101. package/dist/server/renderer/extract.js +149 -31
  102. package/dist/server/renderer/handler.jsx +433 -0
  103. package/dist/server/renderer/index.js +8 -1
  104. package/dist/server/renderer/render.js +47 -0
  105. package/dist/server/utils/botDetectionMiddleware.js +29 -0
  106. package/dist/server/utils/cjsRequire.js +10 -0
  107. package/dist/server/utils/userAgentUtil.js +87 -9
  108. package/dist/server/utils/validator.js +164 -1
  109. package/dist/vite/FastRefresh.jsx +20 -0
  110. package/dist/vite/inject-cache-key-plugin.js +276 -0
  111. package/dist/vite/loadCustomViteConfig.js +22 -0
  112. package/dist/vite/manifest-categorization-plugin.js +455 -0
  113. package/dist/vite/node-loader.mjs +458 -0
  114. package/dist/vite/scssParams.js +21 -0
  115. package/dist/vite/vite.config.client.js +130 -0
  116. package/dist/vite/vite.config.js +422 -0
  117. package/dist/vite/vite.config.server.js +84 -0
  118. package/dist/web-router/components/MetaTag.jsx +34 -0
  119. package/dist/web-router/components/RouterDataProvider.jsx +332 -0
  120. package/dist/web-router/components/Split.jsx +200 -0
  121. package/dist/web-router/components/SplitInview.jsx +106 -0
  122. package/dist/web-router/components/SsrRequestContext.jsx +14 -0
  123. package/dist/web-router/context.jsx +12 -0
  124. package/dist/web-router/hooks.jsx +72 -0
  125. package/dist/web-router/types/components/MetaTag.d.ts +2 -0
  126. package/dist/web-router/types/components/RouterDataProvider.d.ts +95 -0
  127. package/dist/web-router/types/context.d.ts +14 -0
  128. package/dist/web-router/types/hooks.d.ts +1 -0
  129. package/dist/web-router/types/index.d.ts +3 -0
  130. package/dist/web-router/types/utils/metaDataUtils.d.ts +24 -0
  131. package/dist/web-router/utils/metaDataUtils.jsx +119 -0
  132. package/mcp_v2/conversion-tasks.json +35 -17
  133. package/mcp_v2/knowledge-base.json +124 -13
  134. package/mcp_v2/lib/helpers.js +10 -0
  135. package/mcp_v2/mcp.js +4 -4
  136. package/mcp_v2/package.json +1 -0
  137. package/mcp_v2/tools/build.js +116 -20
  138. package/mcp_v2/tools/conversion.js +106 -5
  139. package/mcp_v2/tools/tasks.js +18 -14
  140. package/package.json +35 -68
  141. package/babel.config.js +0 -32
  142. package/dist/index.js +0 -1
  143. package/dist/scripts/devBuild.js +0 -3
  144. package/dist/scripts/devServe.js +0 -3
  145. package/dist/scripts/loadScriptsBeforeServerStarts.js +0 -4
  146. package/dist/scripts/registerAliases.js +0 -6
  147. package/dist/server/renderer/document/Body.js +0 -11
  148. package/dist/server/renderer/document/Head.js +0 -9
  149. package/dist/server/renderer/document/index.js +0 -1
  150. package/dist/server/renderer/handler.js +0 -47
  151. package/dist/server/startServer.js +0 -57
  152. package/dist/webpack/babel-plugins/remove-client.plugin.js +0 -5
  153. package/dist/webpack/babel-plugins/remove-ssr.plugin.js +0 -5
  154. package/dist/webpack/babel.config.client.js +0 -1
  155. package/dist/webpack/babel.config.ssr.js +0 -1
  156. package/dist/webpack/base.babel.js +0 -7
  157. package/dist/webpack/development.client.babel.js +0 -10
  158. package/dist/webpack/production.client.babel.js +0 -4
  159. package/dist/webpack/production.ssr.babel.js +0 -8
  160. package/dist/webpack/scssParams.js +0 -9
@@ -1,47 +1,283 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.useEnvironmentInfo=exports.useBaseHook=exports.PROGRESS_STATES=void 0;var _react=require("react");var _NativeBridge=_interopRequireDefault(require("./utils/NativeBridge.js"));var _errors=require("./errors");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e};}/**
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useEnvironmentInfo = exports.useBaseHook = exports.PROGRESS_STATES = void 0;
7
+ var _react = require("react");
8
+ var _NativeBridge = _interopRequireDefault(require("./utils/NativeBridge.js"));
9
+ var _errors = require("./errors");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ /**
2
12
  * Base hook utility that provides standardized interface for all Catalyst hooks
3
13
  * Handles environment detection, error standardization, and common state management
4
14
  *
5
15
  * @param {string} hookName - Name of the hook for debugging purposes
6
16
  * @returns {Object} Base hook interface with common functionality
7
- */const useBaseHook=(hookName,{hasWebFallback=false,webFallback}={})=>{// Environment detection — live check at call time, never stale from SSR
8
- const isNative=(0,_react.useCallback)(()=>{if(typeof window==="undefined")return false;return!!(window.WebBridge&&_NativeBridge.default.isAvailable());},[]);const isWeb=(0,_react.useCallback)(()=>{return!isNative();},[isNative]);// Web fallback state — only meaningful when isWeb() and hook declared hasWebFallback:true
9
- // State tracks imperative setWebFallback() calls. The prop is the synchronous source of truth
10
- // when provided — prop wins so there is no async gap between prop change and disabled state.
11
- const[webFallbackState,setWebFallback]=(0,_react.useState)(true);// When prop is explicitly provided, use it directly (synchronous). When undefined, fall back to state.
12
- const webFallbackResolved=webFallback!==undefined?!!webFallback:webFallbackState;const webFallbackActive=isWeb()&&hasWebFallback&&webFallbackResolved;const webFallbackDisabled=isWeb()&&hasWebFallback&&!webFallbackResolved;// Common state management
13
- const[data,setData]=(0,_react.useState)(null);const[loading,setLoading]=(0,_react.useState)(false);const[error,setError]=(0,_react.useState)(null);const[progress,setProgress]=(0,_react.useState)({state:"idle",// 'idle' | 'opening' | 'processing' | 'routing' | 'complete' | 'error'
14
- percentage:null,// 0-100 or null
15
- message:null,// Human readable message or null
16
- phase:null,// Operation specific phase or null
17
- transport:null,// Transport method being used
18
- bytesLoaded:null,// Bytes processed
19
- bytesTotal:null// Total bytes
20
- });// Progress management utilities
21
- const updateProgress=(0,_react.useCallback)(updates=>{setProgress(prev=>({...prev,...updates}));},[]);const resetProgress=(0,_react.useCallback)(()=>{setProgress({state:"idle",percentage:null,message:null,phase:null,transport:null,bytesLoaded:null,bytesTotal:null});},[]);const startProgress=(0,_react.useCallback)((phase=null,message=null)=>{updateProgress({state:"active",phase,message,percentage:null});},[updateProgress]);const completeProgress=(0,_react.useCallback)(()=>{updateProgress({state:"complete",percentage:100});},[updateProgress]);const errorProgress=(0,_react.useCallback)(()=>{updateProgress({state:"error"});},[updateProgress]);// Error handling utilities
22
- const handleNativeError=(0,_react.useCallback)(nativeError=>{const standardError=(0,_errors.translateError)(nativeError);setError(standardError);setLoading(false);errorProgress();// Development logging
23
- if((0,_errors.isDevelopment)()){console.group(`🚨 ${hookName} Error`);console.log("Standard Error:",standardError);console.log("Native Error:",nativeError);console.groupEnd();}return standardError;},[hookName,errorProgress]);const clearError=(0,_react.useCallback)(()=>{setError(null);if(progress.state==="error"){resetProgress();}},[progress.state,resetProgress]);// Data management utilities
24
- const setDataAndComplete=(0,_react.useCallback)(newData=>{setData(newData);setLoading(false);completeProgress();setError(null);if((0,_errors.isDevelopment)()){console.log("✅ Native hook success:",hookName,newData);}},[hookName,completeProgress]);const clear=(0,_react.useCallback)(()=>{setData(null);setError(null);resetProgress();if((0,_errors.isDevelopment)()){console.log(`🗑️ ${hookName} Cleared`);}},[hookName,resetProgress]);// Fire-and-forget native call — no-ops silently on web, routes errors through handleNativeError on native
25
- const callNative=(0,_react.useCallback)(fn=>{if(!isNative()){if((0,_errors.isDevelopment)()){console.warn(`${hookName} callNative skipped — not in native environment`);}return;}try{fn();}catch(err){if((0,_errors.isDevelopment)()){console.warn("Native hook call failed silently:",hookName,err);}}},[hookName,isNative]);// Operation wrapper that handles common patterns
26
- const executeOperation=(0,_react.useCallback)((operationCallback,operationName="operation")=>{try{if(isWeb()){console.warn(`${hookName} requires web fallback implementation (isWeb: true)`);return;}if(!isNative()){console.error(`${hookName} executeOperation: Native bridge not available`);return;}setLoading(true);setError(null);startProgress("starting",`Starting ${operationName}...`);if((0,_errors.isDevelopment)()){console.log(`🚀 ${hookName} ${operationName} started`);}// Execute the actual operation
27
- operationCallback();}catch(err){handleNativeError(err);console.error("❌ Native hook operation failed:",hookName,operationName,err);}},[hookName,isWeb,isNative,startProgress,handleNativeError]);// Environment flags (computed values, not functions)
28
- const environmentFlags={isWeb:isWeb(),isNative:isNative()};// Return standardized interface
29
- return{// Data state
30
- data,// Loading states
31
- loading,progress,// Error handling
32
- error,// Environment detection
33
- ...environmentFlags,// Web fallback control
34
- webFallbackActive,webFallbackDisabled,setWebFallback,// Actions
35
- clear,clearError,// Internal utilities for specific hooks
36
- setData,setLoading,setError,setProgress,updateProgress,resetProgress,startProgress,completeProgress,errorProgress,setDataAndComplete,handleNativeError,callNative,executeOperation};};/**
17
+ */
18
+ const useBaseHook = (hookName, {
19
+ hasWebFallback = false,
20
+ webFallback
21
+ } = {}) => {
22
+ // Environment detection — live check at call time, never stale from SSR
23
+ const isNative = (0, _react.useCallback)(() => {
24
+ if (typeof window === "undefined") return false;
25
+ return !!(window.WebBridge && _NativeBridge.default.isAvailable());
26
+ }, []);
27
+ const isWeb = (0, _react.useCallback)(() => {
28
+ return !isNative();
29
+ }, [isNative]);
30
+
31
+ // Web fallback state — only meaningful when isWeb() and hook declared hasWebFallback:true
32
+ // State tracks imperative setWebFallback() calls. The prop is the synchronous source of truth
33
+ // when provided — prop wins so there is no async gap between prop change and disabled state.
34
+ const [webFallbackState, setWebFallback] = (0, _react.useState)(true);
35
+
36
+ // When prop is explicitly provided, use it directly (synchronous). When undefined, fall back to state.
37
+ const webFallbackResolved = webFallback !== undefined ? !!webFallback : webFallbackState;
38
+ const webFallbackActive = isWeb() && hasWebFallback && webFallbackResolved;
39
+ const webFallbackDisabled = isWeb() && hasWebFallback && !webFallbackResolved;
40
+
41
+ // Common state management
42
+ const [data, setData] = (0, _react.useState)(null);
43
+ const [loading, setLoading] = (0, _react.useState)(false);
44
+ const [error, setError] = (0, _react.useState)(null);
45
+ const [progress, setProgress] = (0, _react.useState)({
46
+ state: "idle",
47
+ // 'idle' | 'opening' | 'processing' | 'routing' | 'complete' | 'error'
48
+ percentage: null,
49
+ // 0-100 or null
50
+ message: null,
51
+ // Human readable message or null
52
+ phase: null,
53
+ // Operation specific phase or null
54
+ transport: null,
55
+ // Transport method being used
56
+ bytesLoaded: null,
57
+ // Bytes processed
58
+ bytesTotal: null // Total bytes
59
+ });
60
+
61
+ // Progress management utilities
62
+ const updateProgress = (0, _react.useCallback)(updates => {
63
+ setProgress(prev => ({
64
+ ...prev,
65
+ ...updates
66
+ }));
67
+ }, []);
68
+ const resetProgress = (0, _react.useCallback)(() => {
69
+ setProgress({
70
+ state: "idle",
71
+ percentage: null,
72
+ message: null,
73
+ phase: null,
74
+ transport: null,
75
+ bytesLoaded: null,
76
+ bytesTotal: null
77
+ });
78
+ }, []);
79
+ const startProgress = (0, _react.useCallback)((phase = null, message = null) => {
80
+ updateProgress({
81
+ state: "active",
82
+ phase,
83
+ message,
84
+ percentage: null
85
+ });
86
+ }, [updateProgress]);
87
+ const completeProgress = (0, _react.useCallback)(() => {
88
+ updateProgress({
89
+ state: "complete",
90
+ percentage: 100
91
+ });
92
+ }, [updateProgress]);
93
+ const errorProgress = (0, _react.useCallback)(() => {
94
+ updateProgress({
95
+ state: "error"
96
+ });
97
+ }, [updateProgress]);
98
+
99
+ // Error handling utilities
100
+ const handleNativeError = (0, _react.useCallback)(nativeError => {
101
+ const standardError = (0, _errors.translateError)(nativeError);
102
+ setError(standardError);
103
+ setLoading(false);
104
+ errorProgress();
105
+
106
+ // Development logging
107
+ if ((0, _errors.isDevelopment)()) {
108
+ console.group(`🚨 ${hookName} Error`);
109
+ console.log("Standard Error:", standardError);
110
+ console.log("Native Error:", nativeError);
111
+ console.groupEnd();
112
+ }
113
+ return standardError;
114
+ }, [hookName, errorProgress]);
115
+ const clearError = (0, _react.useCallback)(() => {
116
+ setError(null);
117
+ if (progress.state === "error") {
118
+ resetProgress();
119
+ }
120
+ }, [progress.state, resetProgress]);
121
+
122
+ // Data management utilities
123
+ const setDataAndComplete = (0, _react.useCallback)(newData => {
124
+ setData(newData);
125
+ setLoading(false);
126
+ completeProgress();
127
+ setError(null);
128
+ if ((0, _errors.isDevelopment)()) {
129
+ console.log("✅ Native hook success:", hookName, newData);
130
+ }
131
+ }, [hookName, completeProgress]);
132
+ const clear = (0, _react.useCallback)(() => {
133
+ setData(null);
134
+ setError(null);
135
+ resetProgress();
136
+ if ((0, _errors.isDevelopment)()) {
137
+ console.log(`🗑️ ${hookName} Cleared`);
138
+ }
139
+ }, [hookName, resetProgress]);
140
+
141
+ // Fire-and-forget native call — no-ops silently on web, routes errors through handleNativeError on native
142
+ const callNative = (0, _react.useCallback)(fn => {
143
+ if (!isNative()) {
144
+ if ((0, _errors.isDevelopment)()) {
145
+ console.warn(`${hookName} callNative skipped — not in native environment`);
146
+ }
147
+ return;
148
+ }
149
+ try {
150
+ fn();
151
+ } catch (err) {
152
+ if ((0, _errors.isDevelopment)()) {
153
+ console.warn("Native hook call failed silently:", hookName, err);
154
+ }
155
+ }
156
+ }, [hookName, isNative]);
157
+
158
+ // Operation wrapper that handles common patterns
159
+ const executeOperation = (0, _react.useCallback)((operationCallback, operationName = "operation") => {
160
+ try {
161
+ if (isWeb()) {
162
+ console.warn(`${hookName} requires web fallback implementation (isWeb: true)`);
163
+ return;
164
+ }
165
+ if (!isNative()) {
166
+ console.error(`${hookName} executeOperation: Native bridge not available`);
167
+ return;
168
+ }
169
+ setLoading(true);
170
+ setError(null);
171
+ startProgress("starting", `Starting ${operationName}...`);
172
+ if ((0, _errors.isDevelopment)()) {
173
+ console.log(`🚀 ${hookName} ${operationName} started`);
174
+ }
175
+
176
+ // Execute the actual operation
177
+ operationCallback();
178
+ } catch (err) {
179
+ handleNativeError(err);
180
+ console.error("❌ Native hook operation failed:", hookName, operationName, err);
181
+ }
182
+ }, [hookName, isWeb, isNative, startProgress, handleNativeError]);
183
+
184
+ // Environment flags (computed values, not functions)
185
+ const environmentFlags = {
186
+ isWeb: isWeb(),
187
+ isNative: isNative()
188
+ };
189
+
190
+ // Return standardized interface
191
+ return {
192
+ // Data state
193
+ data,
194
+ // Loading states
195
+ loading,
196
+ progress,
197
+ // Error handling
198
+ error,
199
+ // Environment detection
200
+ ...environmentFlags,
201
+ // Web fallback control
202
+ webFallbackActive,
203
+ webFallbackDisabled,
204
+ setWebFallback,
205
+ // Actions
206
+ clear,
207
+ clearError,
208
+ // Internal utilities for specific hooks
209
+ setData,
210
+ setLoading,
211
+ setError,
212
+ setProgress,
213
+ updateProgress,
214
+ resetProgress,
215
+ startProgress,
216
+ completeProgress,
217
+ errorProgress,
218
+ setDataAndComplete,
219
+ handleNativeError,
220
+ callNative,
221
+ executeOperation
222
+ };
223
+ };
224
+
225
+ /**
37
226
  * Hook for development debugging and testing
38
227
  * @param {string} hookName
39
228
  * @returns {Object} Environment information and utilities
40
- */exports.useBaseHook=useBaseHook;const useEnvironmentInfo=hookName=>{const isNativeAvailable=()=>{if(typeof window==="undefined")return false;return!!(window.WebBridge&&_NativeBridge.default.isAvailable());};const getEnvironmentDetails=()=>{const details={hasWindow:typeof window!=="undefined",hasWebBridge:typeof window!=="undefined"&&!!window.WebBridge,nativeBridgeAvailable:false,userAgent:typeof navigator!=="undefined"?navigator.userAgent:"SSR",timestamp:new Date().toISOString()};if(details.hasWebBridge){details.nativeBridgeAvailable=_NativeBridge.default.isAvailable();}return details;};if((0,_errors.isDevelopment)()){console.log("🔍 Native hook environment:",hookName,getEnvironmentDetails());}return{isNative:isNativeAvailable(),isWeb:!isNativeAvailable(),environmentDetails:getEnvironmentDetails()};};/**
229
+ */
230
+ exports.useBaseHook = useBaseHook;
231
+ const useEnvironmentInfo = hookName => {
232
+ const isNativeAvailable = () => {
233
+ if (typeof window === "undefined") return false;
234
+ return !!(window.WebBridge && _NativeBridge.default.isAvailable());
235
+ };
236
+ const getEnvironmentDetails = () => {
237
+ const details = {
238
+ hasWindow: typeof window !== "undefined",
239
+ hasWebBridge: typeof window !== "undefined" && !!window.WebBridge,
240
+ nativeBridgeAvailable: false,
241
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : "SSR",
242
+ timestamp: new Date().toISOString()
243
+ };
244
+ if (details.hasWebBridge) {
245
+ details.nativeBridgeAvailable = _NativeBridge.default.isAvailable();
246
+ }
247
+ return details;
248
+ };
249
+ if ((0, _errors.isDevelopment)()) {
250
+ console.log("🔍 Native hook environment:", hookName, getEnvironmentDetails());
251
+ }
252
+ return {
253
+ isNative: isNativeAvailable(),
254
+ isWeb: !isNativeAvailable(),
255
+ environmentDetails: getEnvironmentDetails()
256
+ };
257
+ };
258
+
259
+ /**
41
260
  * Progress state constants for consistency across hooks
42
- */exports.useEnvironmentInfo=useEnvironmentInfo;const PROGRESS_STATES=exports.PROGRESS_STATES={// Common states
43
- IDLE:"idle",STARTING:"starting",COMPLETE:"complete",ERROR:"error",// File Picker states
44
- OPENING:"opening",PROCESSING:"processing",ROUTING:"routing",// Camera states
45
- REQUESTING:"requesting",CAPTURING:"capturing",// Intent states
46
- DOWNLOADING:"downloading",OPENING_FILE:"opening_file",// Server states
47
- CONNECTING:"connecting",UPLOADING:"uploading",SERVING:"serving"};
261
+ */
262
+ exports.useEnvironmentInfo = useEnvironmentInfo;
263
+ const PROGRESS_STATES = exports.PROGRESS_STATES = {
264
+ // Common states
265
+ IDLE: "idle",
266
+ STARTING: "starting",
267
+ COMPLETE: "complete",
268
+ ERROR: "error",
269
+ // File Picker states
270
+ OPENING: "opening",
271
+ PROCESSING: "processing",
272
+ ROUTING: "routing",
273
+ // Camera states
274
+ REQUESTING: "requesting",
275
+ CAPTURING: "capturing",
276
+ // Intent states
277
+ DOWNLOADING: "downloading",
278
+ OPENING_FILE: "opening_file",
279
+ // Server states
280
+ CONNECTING: "connecting",
281
+ UPLOADING: "uploading",
282
+ SERVING: "serving"
283
+ };
@@ -1,58 +1,203 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _NativeInterfaces=require("../constants/NativeInterfaces.js");var _NativeBridge=_interopRequireDefault(require("./NativeBridge.js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e};}/**
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _NativeInterfaces = require("../constants/NativeInterfaces.js");
8
+ var _NativeBridge = _interopRequireDefault(require("./NativeBridge.js"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ /**
2
11
  * Camera Utility Module
3
12
  * Provides Promise-based camera operations with proper option validation
4
- */class CameraUtils{/**
5
- * Open camera and capture image
6
- * @param {Object} options - Camera options
7
- * @param {string} options.quality - Image quality: 'high', 'medium', 'low'
8
- * @param {string} options.format - Image format: 'jpeg', 'png'
9
- * @param {string} options.cameraDevice - Camera device: 'front', 'rear'
10
- * @param {string} options.flashMode - Flash mode: 'auto', 'on', 'off'
11
- * @param {boolean} options.allowEditing - Allow image editing after capture
12
- * @param {Function} registerCallback - Callback registration function
13
- * @param {Function} unregisterCallback - Callback unregistration function
14
- * @returns {Promise<Object>} - Promise that resolves with camera result or rejects with error
15
- */static openCamera(options={},registerCallback,unregisterCallback){return new Promise((resolve,reject)=>{const cleanup=()=>{unregisterCallback(_NativeInterfaces.NATIVE_CALLBACKS.ON_CAMERA_CAPTURE);unregisterCallback(_NativeInterfaces.NATIVE_CALLBACKS.ON_CAMERA_ERROR);};// Validate and set defaults for options
16
- const cameraOptions=CameraUtils.validateCameraOptions(options);registerCallback(_NativeInterfaces.NATIVE_CALLBACKS.ON_CAMERA_CAPTURE,data=>{cleanup();try{const result=typeof data==="string"?JSON.parse(data):data;if(result.error){reject(new Error(result.error));}else{resolve(result);}}catch(error){reject(error);}});registerCallback(_NativeInterfaces.NATIVE_CALLBACKS.ON_CAMERA_ERROR,error=>{cleanup();const errorMessage=typeof error==="string"?error:error.error||error.message||"Unknown camera error";reject(new Error(errorMessage));});try{_NativeBridge.default.camera.open(JSON.stringify(cameraOptions));}catch(error){cleanup();reject(error);}});}/**
17
- * Request camera permission
18
- * @param {Object} config - Permission configuration
19
- * @param {boolean} config.includeDetails - Include detailed permission info in response
20
- * @param {Function} registerCallback - Callback registration function
21
- * @param {Function} unregisterCallback - Callback unregistration function
22
- * @returns {Promise<Object>} - Promise that resolves with permission status or rejects with error
23
- */static requestCameraPermission(config={},registerCallback,unregisterCallback){return new Promise((resolve,reject)=>{const cleanup=()=>{unregisterCallback(_NativeInterfaces.NATIVE_CALLBACKS.CAMERA_PERMISSION_STATUS);};// Validate and set defaults for config
24
- const permissionConfig={includeDetails:config.includeDetails||false,...config};registerCallback(_NativeInterfaces.NATIVE_CALLBACKS.CAMERA_PERMISSION_STATUS,data=>{cleanup();try{const result=typeof data==="string"?JSON.parse(data):data;if(result.error){reject(new Error(result.error));}else{resolve(result);}}catch(error){reject(error);}});try{_NativeBridge.default.camera.requestPermission(JSON.stringify(permissionConfig));}catch(error){cleanup();reject(error);}});}/**
25
- * Validate camera options and set defaults
26
- * @param {Object} options - Raw camera options
27
- * @returns {Object} - Validated camera options with defaults
28
- */static validateCameraOptions(options){const validated={};// Quality validation
29
- if(options.quality&&Object.values(_NativeInterfaces.CAMERA_QUALITY).includes(options.quality.toLowerCase())){validated.quality=options.quality.toLowerCase();}else{validated.quality=_NativeInterfaces.CAMERA_QUALITY.MEDIUM;// Default
30
- }// Format validation
31
- if(options.format&&Object.values(_NativeInterfaces.CAMERA_FORMAT).includes(options.format.toLowerCase())){validated.format=options.format.toLowerCase();}else{validated.format=_NativeInterfaces.CAMERA_FORMAT.JPEG;// Default
32
- }// Camera device validation
33
- if(options.cameraDevice&&Object.values(_NativeInterfaces.CAMERA_DEVICE).includes(options.cameraDevice.toLowerCase())){validated.cameraDevice=options.cameraDevice.toLowerCase();}// Flash mode validation
34
- if(options.flashMode&&Object.values(_NativeInterfaces.CAMERA_FLASH_MODE).includes(options.flashMode.toLowerCase())){validated.flashMode=options.flashMode.toLowerCase();}// Allow editing validation
35
- if(typeof options.allowEditing==="boolean"){validated.allowEditing=options.allowEditing;}else{validated.allowEditing=false;// Default
36
- }return validated;}/**
37
- * Get default camera options
38
- * @returns {Object} - Default camera options
39
- */static getDefaultOptions(){return{quality:_NativeInterfaces.CAMERA_QUALITY.MEDIUM,format:_NativeInterfaces.CAMERA_FORMAT.JPEG,allowEditing:false};}/**
40
- * Get default permission config
41
- * @returns {Object} - Default permission config
42
- */static getDefaultPermissionConfig(){return{includeDetails:false};}/**
43
- * Validate camera quality
44
- * @param {string} quality - Quality string to validate
45
- * @returns {boolean} - True if valid quality
46
- */static isValidQuality(quality){return quality&&Object.values(_NativeInterfaces.CAMERA_QUALITY).includes(quality.toLowerCase());}/**
47
- * Validate camera format
48
- * @param {string} format - Format string to validate
49
- * @returns {boolean} - True if valid format
50
- */static isValidFormat(format){return format&&Object.values(_NativeInterfaces.CAMERA_FORMAT).includes(format.toLowerCase());}/**
51
- * Validate camera device
52
- * @param {string} device - Device string to validate
53
- * @returns {boolean} - True if valid device
54
- */static isValidDevice(device){return device&&Object.values(_NativeInterfaces.CAMERA_DEVICE).includes(device.toLowerCase());}/**
55
- * Validate flash mode
56
- * @param {string} flashMode - Flash mode string to validate
57
- * @returns {boolean} - True if valid flash mode
58
- */static isValidFlashMode(flashMode){return flashMode&&Object.values(_NativeInterfaces.CAMERA_FLASH_MODE).includes(flashMode.toLowerCase());}}var _default=exports.default=CameraUtils;
13
+ */
14
+ class CameraUtils {
15
+ /**
16
+ * Open camera and capture image
17
+ * @param {Object} options - Camera options
18
+ * @param {string} options.quality - Image quality: 'high', 'medium', 'low'
19
+ * @param {string} options.format - Image format: 'jpeg', 'png'
20
+ * @param {string} options.cameraDevice - Camera device: 'front', 'rear'
21
+ * @param {string} options.flashMode - Flash mode: 'auto', 'on', 'off'
22
+ * @param {boolean} options.allowEditing - Allow image editing after capture
23
+ * @param {Function} registerCallback - Callback registration function
24
+ * @param {Function} unregisterCallback - Callback unregistration function
25
+ * @returns {Promise<Object>} - Promise that resolves with camera result or rejects with error
26
+ */
27
+ static openCamera(options = {}, registerCallback, unregisterCallback) {
28
+ return new Promise((resolve, reject) => {
29
+ const cleanup = () => {
30
+ unregisterCallback(_NativeInterfaces.NATIVE_CALLBACKS.ON_CAMERA_CAPTURE);
31
+ unregisterCallback(_NativeInterfaces.NATIVE_CALLBACKS.ON_CAMERA_ERROR);
32
+ };
33
+
34
+ // Validate and set defaults for options
35
+ const cameraOptions = CameraUtils.validateCameraOptions(options);
36
+ registerCallback(_NativeInterfaces.NATIVE_CALLBACKS.ON_CAMERA_CAPTURE, data => {
37
+ cleanup();
38
+ try {
39
+ const result = typeof data === "string" ? JSON.parse(data) : data;
40
+ if (result.error) {
41
+ reject(new Error(result.error));
42
+ } else {
43
+ resolve(result);
44
+ }
45
+ } catch (error) {
46
+ reject(error);
47
+ }
48
+ });
49
+ registerCallback(_NativeInterfaces.NATIVE_CALLBACKS.ON_CAMERA_ERROR, error => {
50
+ cleanup();
51
+ const errorMessage = typeof error === "string" ? error : error.error || error.message || "Unknown camera error";
52
+ reject(new Error(errorMessage));
53
+ });
54
+ try {
55
+ _NativeBridge.default.camera.open(JSON.stringify(cameraOptions));
56
+ } catch (error) {
57
+ cleanup();
58
+ reject(error);
59
+ }
60
+ });
61
+ }
62
+
63
+ /**
64
+ * Request camera permission
65
+ * @param {Object} config - Permission configuration
66
+ * @param {boolean} config.includeDetails - Include detailed permission info in response
67
+ * @param {Function} registerCallback - Callback registration function
68
+ * @param {Function} unregisterCallback - Callback unregistration function
69
+ * @returns {Promise<Object>} - Promise that resolves with permission status or rejects with error
70
+ */
71
+ static requestCameraPermission(config = {}, registerCallback, unregisterCallback) {
72
+ return new Promise((resolve, reject) => {
73
+ const cleanup = () => {
74
+ unregisterCallback(_NativeInterfaces.NATIVE_CALLBACKS.CAMERA_PERMISSION_STATUS);
75
+ };
76
+
77
+ // Validate and set defaults for config
78
+ const permissionConfig = {
79
+ includeDetails: config.includeDetails || false,
80
+ ...config
81
+ };
82
+ registerCallback(_NativeInterfaces.NATIVE_CALLBACKS.CAMERA_PERMISSION_STATUS, data => {
83
+ cleanup();
84
+ try {
85
+ const result = typeof data === "string" ? JSON.parse(data) : data;
86
+ if (result.error) {
87
+ reject(new Error(result.error));
88
+ } else {
89
+ resolve(result);
90
+ }
91
+ } catch (error) {
92
+ reject(error);
93
+ }
94
+ });
95
+ try {
96
+ _NativeBridge.default.camera.requestPermission(JSON.stringify(permissionConfig));
97
+ } catch (error) {
98
+ cleanup();
99
+ reject(error);
100
+ }
101
+ });
102
+ }
103
+
104
+ /**
105
+ * Validate camera options and set defaults
106
+ * @param {Object} options - Raw camera options
107
+ * @returns {Object} - Validated camera options with defaults
108
+ */
109
+ static validateCameraOptions(options) {
110
+ const validated = {};
111
+
112
+ // Quality validation
113
+ if (options.quality && Object.values(_NativeInterfaces.CAMERA_QUALITY).includes(options.quality.toLowerCase())) {
114
+ validated.quality = options.quality.toLowerCase();
115
+ } else {
116
+ validated.quality = _NativeInterfaces.CAMERA_QUALITY.MEDIUM; // Default
117
+ }
118
+
119
+ // Format validation
120
+ if (options.format && Object.values(_NativeInterfaces.CAMERA_FORMAT).includes(options.format.toLowerCase())) {
121
+ validated.format = options.format.toLowerCase();
122
+ } else {
123
+ validated.format = _NativeInterfaces.CAMERA_FORMAT.JPEG; // Default
124
+ }
125
+
126
+ // Camera device validation
127
+ if (options.cameraDevice && Object.values(_NativeInterfaces.CAMERA_DEVICE).includes(options.cameraDevice.toLowerCase())) {
128
+ validated.cameraDevice = options.cameraDevice.toLowerCase();
129
+ }
130
+
131
+ // Flash mode validation
132
+ if (options.flashMode && Object.values(_NativeInterfaces.CAMERA_FLASH_MODE).includes(options.flashMode.toLowerCase())) {
133
+ validated.flashMode = options.flashMode.toLowerCase();
134
+ }
135
+
136
+ // Allow editing validation
137
+ if (typeof options.allowEditing === "boolean") {
138
+ validated.allowEditing = options.allowEditing;
139
+ } else {
140
+ validated.allowEditing = false; // Default
141
+ }
142
+ return validated;
143
+ }
144
+
145
+ /**
146
+ * Get default camera options
147
+ * @returns {Object} - Default camera options
148
+ */
149
+ static getDefaultOptions() {
150
+ return {
151
+ quality: _NativeInterfaces.CAMERA_QUALITY.MEDIUM,
152
+ format: _NativeInterfaces.CAMERA_FORMAT.JPEG,
153
+ allowEditing: false
154
+ };
155
+ }
156
+
157
+ /**
158
+ * Get default permission config
159
+ * @returns {Object} - Default permission config
160
+ */
161
+ static getDefaultPermissionConfig() {
162
+ return {
163
+ includeDetails: false
164
+ };
165
+ }
166
+
167
+ /**
168
+ * Validate camera quality
169
+ * @param {string} quality - Quality string to validate
170
+ * @returns {boolean} - True if valid quality
171
+ */
172
+ static isValidQuality(quality) {
173
+ return quality && Object.values(_NativeInterfaces.CAMERA_QUALITY).includes(quality.toLowerCase());
174
+ }
175
+
176
+ /**
177
+ * Validate camera format
178
+ * @param {string} format - Format string to validate
179
+ * @returns {boolean} - True if valid format
180
+ */
181
+ static isValidFormat(format) {
182
+ return format && Object.values(_NativeInterfaces.CAMERA_FORMAT).includes(format.toLowerCase());
183
+ }
184
+
185
+ /**
186
+ * Validate camera device
187
+ * @param {string} device - Device string to validate
188
+ * @returns {boolean} - True if valid device
189
+ */
190
+ static isValidDevice(device) {
191
+ return device && Object.values(_NativeInterfaces.CAMERA_DEVICE).includes(device.toLowerCase());
192
+ }
193
+
194
+ /**
195
+ * Validate flash mode
196
+ * @param {string} flashMode - Flash mode string to validate
197
+ * @returns {boolean} - True if valid flash mode
198
+ */
199
+ static isValidFlashMode(flashMode) {
200
+ return flashMode && Object.values(_NativeInterfaces.CAMERA_FLASH_MODE).includes(flashMode.toLowerCase());
201
+ }
202
+ }
203
+ var _default = exports.default = CameraUtils;