@retion-miniapp/react-native 0.13.5 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +12 -9
- package/dist/index.mjs +12 -9
- package/docs/NATIVE_APIS.md +10 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -270,6 +270,38 @@ interface MiniAppBridgeOptions {
|
|
|
270
270
|
app_id: string;
|
|
271
271
|
instance_id: string;
|
|
272
272
|
}) => void | Promise<void>;
|
|
273
|
+
/**
|
|
274
|
+
* Thay nhận dạng giọng nói có sẵn (expo-speech-recognition) bằng của app — vd trợ lý voice AI.
|
|
275
|
+
* Web vẫn gọi speech.start / speech.stop và nhận speech.partial / speech.final / speech.end / speech.error như cũ
|
|
276
|
+
* (không phải cập nhật mini app web). Không truyền → dùng nhận dạng có sẵn.
|
|
277
|
+
*/
|
|
278
|
+
speech?: MiniAppSpeechProvider;
|
|
279
|
+
}
|
|
280
|
+
/** Ngữ cảnh 1 lần web gọi speech.start (provider của app tự quản phiên). */
|
|
281
|
+
interface MiniAppSpeechStartContext {
|
|
282
|
+
/** WebView đang gọi — dùng làm khoá phiên cho stop / release */
|
|
283
|
+
owner: string;
|
|
284
|
+
app_id: string;
|
|
285
|
+
/** Tham số web truyền (đã kiểm tra hợp lệ) */
|
|
286
|
+
options: {
|
|
287
|
+
lang?: string;
|
|
288
|
+
continuous?: boolean;
|
|
289
|
+
interimResults?: boolean;
|
|
290
|
+
addsPunctuation?: boolean;
|
|
291
|
+
requiresOnDeviceRecognition?: boolean;
|
|
292
|
+
};
|
|
293
|
+
/** Gửi event về đúng WebView: speech.partial / speech.final ({ text }), speech.end, speech.error ({ code, message }) */
|
|
294
|
+
emit: (event: 'speech.partial' | 'speech.final' | 'speech.end' | 'speech.error', data?: unknown) => void;
|
|
295
|
+
/** false = mini app đã đóng / ẩn */
|
|
296
|
+
isActive: () => boolean;
|
|
297
|
+
}
|
|
298
|
+
interface MiniAppSpeechProvider {
|
|
299
|
+
/** Bắt đầu nghe. Resolve khi đã bắt đầu; throw MiniAppHostError (BUSY / PERMISSION_DENIED…) nếu không được. */
|
|
300
|
+
start: (context: MiniAppSpeechStartContext) => Promise<void>;
|
|
301
|
+
/** Web gọi speech.stop (chỉ chủ phiên). Provider tự quyết gửi speech.final / speech.end sau đó. */
|
|
302
|
+
stop: (owner: string) => void | Promise<void>;
|
|
303
|
+
/** Mini app đóng / ẩn / app xuống nền: huỷ phiên của owner, không cần gửi event. */
|
|
304
|
+
release?: (owner: string) => void;
|
|
273
305
|
}
|
|
274
306
|
/** Biometric verification on this device; does not issue a backend login token. */
|
|
275
307
|
type MiniAppBiometryType = 'FaceID' | 'TouchID' | 'Biometrics';
|
|
@@ -711,6 +743,8 @@ interface ScannerOptions {
|
|
|
711
743
|
hint?: string;
|
|
712
744
|
/** Quét liên tiếp: camera ở trên web (top, mặc định) hoặc phủ kín (full). */
|
|
713
745
|
layout?: ScannerLayout;
|
|
746
|
+
/** Layout top: camera nằm đè lên web, web giữ nguyên kích thước (web tự chừa chỗ theo chiều cao host báo). */
|
|
747
|
+
absolute?: boolean;
|
|
714
748
|
}
|
|
715
749
|
interface ScannerResult {
|
|
716
750
|
value: string;
|
|
@@ -770,4 +804,4 @@ interface UploadCapabilities {
|
|
|
770
804
|
/** XHR (không phải fetch) để có tiến trình upload; RN đọc file từ uri (cả content://), không nạp vào JS. */
|
|
771
805
|
declare const uploadToUrl: MiniAppUploader;
|
|
772
806
|
|
|
773
|
-
export { CodeType, DefaultMiniAppSplash, type LocationOptions, type LocationResult, MINIAPP_PLATFORM_URL, type MiniAppBiometricAvailability, type MiniAppBiometricRequest, type MiniAppBiometricResult, type MiniAppBiometrics, type MiniAppBiometryType, type MiniAppBridgeOptions, type MiniAppCatalogEntry, type MiniAppCatalogItem, type MiniAppChannel, type MiniAppConfig, type MiniAppContainerProps, type MiniAppContext, type MiniAppDownloadState, type MiniAppDownloadStatus, type MiniAppDownloadTask, type MiniAppEvent, type MiniAppFileSystem, type MiniAppHandlerContext, type MiniAppHapticType, _default as MiniAppHost, type MiniAppHostData, BridgeError as MiniAppHostError, type MiniAppHostProps, type MiniAppKeepAlive, type MiniAppLaunch, type MiniAppLocalBundle, type MiniAppManifest, type MiniAppNativeHandlers, type MiniAppPaymentRequest, type MiniAppPaymentResult, type MiniAppPermission, type MiniAppPickedFile, type MiniAppSplashProps, type MiniAppStorage, type MiniAppSyncResult, type MiniAppUpdate, type MiniAppUploadCaller, type MiniAppUploadOptions, type MiniAppUploadProcessOptions, type MiniAppUploadProcessor, type MiniAppUploadRequest, type MiniAppUploadSource, type MiniAppUploadSourceRequest, type MiniAppUploadTarget, type MiniAppUploader, type MiniAppUrlUploadTarget, type OpenMiniAppArgs, type ReactNativeBiometricsLike, ScannerEndReason, ScannerEvent, ScannerLayout, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, ToastType, type UploadCapabilities, type UploadFileType, type UploadFilesResult, type UploadedFile, closeMiniApp, configureMiniApp, createMmkvStorage, createReactNativeBiometrics, createRnfsFileSystem, ensureMiniApp, getLocalMiniApp, getMiniAppCatalog, getMiniAppCatalogEntry, getMiniAppStatuses, getMiniAppUpdate, installBundledMiniApp, onMiniAppEvent, openMiniApp, pauseMiniApp, pauseMiniAppDownloads, preloadMiniApp, releaseSpeechFor, restoreMiniApp, resumeMiniApp, resumeMiniAppDownloads, sendEventToWeb, syncMiniAppCatalog, uninstallMiniApp, updateMiniApp, uploadToUrl, useMiniAppDownload, useMiniAppDownloadsPaused };
|
|
807
|
+
export { CodeType, DefaultMiniAppSplash, type LocationOptions, type LocationResult, MINIAPP_PLATFORM_URL, type MiniAppBiometricAvailability, type MiniAppBiometricRequest, type MiniAppBiometricResult, type MiniAppBiometrics, type MiniAppBiometryType, type MiniAppBridgeOptions, type MiniAppCatalogEntry, type MiniAppCatalogItem, type MiniAppChannel, type MiniAppConfig, type MiniAppContainerProps, type MiniAppContext, type MiniAppDownloadState, type MiniAppDownloadStatus, type MiniAppDownloadTask, type MiniAppEvent, type MiniAppFileSystem, type MiniAppHandlerContext, type MiniAppHapticType, _default as MiniAppHost, type MiniAppHostData, BridgeError as MiniAppHostError, type MiniAppHostProps, type MiniAppKeepAlive, type MiniAppLaunch, type MiniAppLocalBundle, type MiniAppManifest, type MiniAppNativeHandlers, type MiniAppPaymentRequest, type MiniAppPaymentResult, type MiniAppPermission, type MiniAppPickedFile, type MiniAppSpeechProvider, type MiniAppSpeechStartContext, type MiniAppSplashProps, type MiniAppStorage, type MiniAppSyncResult, type MiniAppUpdate, type MiniAppUploadCaller, type MiniAppUploadOptions, type MiniAppUploadProcessOptions, type MiniAppUploadProcessor, type MiniAppUploadRequest, type MiniAppUploadSource, type MiniAppUploadSourceRequest, type MiniAppUploadTarget, type MiniAppUploader, type MiniAppUrlUploadTarget, type OpenMiniAppArgs, type ReactNativeBiometricsLike, ScannerEndReason, ScannerEvent, ScannerLayout, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, ToastType, type UploadCapabilities, type UploadFileType, type UploadFilesResult, type UploadedFile, closeMiniApp, configureMiniApp, createMmkvStorage, createReactNativeBiometrics, createRnfsFileSystem, ensureMiniApp, getLocalMiniApp, getMiniAppCatalog, getMiniAppCatalogEntry, getMiniAppStatuses, getMiniAppUpdate, installBundledMiniApp, onMiniAppEvent, openMiniApp, pauseMiniApp, pauseMiniAppDownloads, preloadMiniApp, releaseSpeechFor, restoreMiniApp, resumeMiniApp, resumeMiniAppDownloads, sendEventToWeb, syncMiniAppCatalog, uninstallMiniApp, updateMiniApp, uploadToUrl, useMiniAppDownload, useMiniAppDownloadsPaused };
|
package/dist/index.d.ts
CHANGED
|
@@ -270,6 +270,38 @@ interface MiniAppBridgeOptions {
|
|
|
270
270
|
app_id: string;
|
|
271
271
|
instance_id: string;
|
|
272
272
|
}) => void | Promise<void>;
|
|
273
|
+
/**
|
|
274
|
+
* Thay nhận dạng giọng nói có sẵn (expo-speech-recognition) bằng của app — vd trợ lý voice AI.
|
|
275
|
+
* Web vẫn gọi speech.start / speech.stop và nhận speech.partial / speech.final / speech.end / speech.error như cũ
|
|
276
|
+
* (không phải cập nhật mini app web). Không truyền → dùng nhận dạng có sẵn.
|
|
277
|
+
*/
|
|
278
|
+
speech?: MiniAppSpeechProvider;
|
|
279
|
+
}
|
|
280
|
+
/** Ngữ cảnh 1 lần web gọi speech.start (provider của app tự quản phiên). */
|
|
281
|
+
interface MiniAppSpeechStartContext {
|
|
282
|
+
/** WebView đang gọi — dùng làm khoá phiên cho stop / release */
|
|
283
|
+
owner: string;
|
|
284
|
+
app_id: string;
|
|
285
|
+
/** Tham số web truyền (đã kiểm tra hợp lệ) */
|
|
286
|
+
options: {
|
|
287
|
+
lang?: string;
|
|
288
|
+
continuous?: boolean;
|
|
289
|
+
interimResults?: boolean;
|
|
290
|
+
addsPunctuation?: boolean;
|
|
291
|
+
requiresOnDeviceRecognition?: boolean;
|
|
292
|
+
};
|
|
293
|
+
/** Gửi event về đúng WebView: speech.partial / speech.final ({ text }), speech.end, speech.error ({ code, message }) */
|
|
294
|
+
emit: (event: 'speech.partial' | 'speech.final' | 'speech.end' | 'speech.error', data?: unknown) => void;
|
|
295
|
+
/** false = mini app đã đóng / ẩn */
|
|
296
|
+
isActive: () => boolean;
|
|
297
|
+
}
|
|
298
|
+
interface MiniAppSpeechProvider {
|
|
299
|
+
/** Bắt đầu nghe. Resolve khi đã bắt đầu; throw MiniAppHostError (BUSY / PERMISSION_DENIED…) nếu không được. */
|
|
300
|
+
start: (context: MiniAppSpeechStartContext) => Promise<void>;
|
|
301
|
+
/** Web gọi speech.stop (chỉ chủ phiên). Provider tự quyết gửi speech.final / speech.end sau đó. */
|
|
302
|
+
stop: (owner: string) => void | Promise<void>;
|
|
303
|
+
/** Mini app đóng / ẩn / app xuống nền: huỷ phiên của owner, không cần gửi event. */
|
|
304
|
+
release?: (owner: string) => void;
|
|
273
305
|
}
|
|
274
306
|
/** Biometric verification on this device; does not issue a backend login token. */
|
|
275
307
|
type MiniAppBiometryType = 'FaceID' | 'TouchID' | 'Biometrics';
|
|
@@ -711,6 +743,8 @@ interface ScannerOptions {
|
|
|
711
743
|
hint?: string;
|
|
712
744
|
/** Quét liên tiếp: camera ở trên web (top, mặc định) hoặc phủ kín (full). */
|
|
713
745
|
layout?: ScannerLayout;
|
|
746
|
+
/** Layout top: camera nằm đè lên web, web giữ nguyên kích thước (web tự chừa chỗ theo chiều cao host báo). */
|
|
747
|
+
absolute?: boolean;
|
|
714
748
|
}
|
|
715
749
|
interface ScannerResult {
|
|
716
750
|
value: string;
|
|
@@ -770,4 +804,4 @@ interface UploadCapabilities {
|
|
|
770
804
|
/** XHR (không phải fetch) để có tiến trình upload; RN đọc file từ uri (cả content://), không nạp vào JS. */
|
|
771
805
|
declare const uploadToUrl: MiniAppUploader;
|
|
772
806
|
|
|
773
|
-
export { CodeType, DefaultMiniAppSplash, type LocationOptions, type LocationResult, MINIAPP_PLATFORM_URL, type MiniAppBiometricAvailability, type MiniAppBiometricRequest, type MiniAppBiometricResult, type MiniAppBiometrics, type MiniAppBiometryType, type MiniAppBridgeOptions, type MiniAppCatalogEntry, type MiniAppCatalogItem, type MiniAppChannel, type MiniAppConfig, type MiniAppContainerProps, type MiniAppContext, type MiniAppDownloadState, type MiniAppDownloadStatus, type MiniAppDownloadTask, type MiniAppEvent, type MiniAppFileSystem, type MiniAppHandlerContext, type MiniAppHapticType, _default as MiniAppHost, type MiniAppHostData, BridgeError as MiniAppHostError, type MiniAppHostProps, type MiniAppKeepAlive, type MiniAppLaunch, type MiniAppLocalBundle, type MiniAppManifest, type MiniAppNativeHandlers, type MiniAppPaymentRequest, type MiniAppPaymentResult, type MiniAppPermission, type MiniAppPickedFile, type MiniAppSplashProps, type MiniAppStorage, type MiniAppSyncResult, type MiniAppUpdate, type MiniAppUploadCaller, type MiniAppUploadOptions, type MiniAppUploadProcessOptions, type MiniAppUploadProcessor, type MiniAppUploadRequest, type MiniAppUploadSource, type MiniAppUploadSourceRequest, type MiniAppUploadTarget, type MiniAppUploader, type MiniAppUrlUploadTarget, type OpenMiniAppArgs, type ReactNativeBiometricsLike, ScannerEndReason, ScannerEvent, ScannerLayout, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, ToastType, type UploadCapabilities, type UploadFileType, type UploadFilesResult, type UploadedFile, closeMiniApp, configureMiniApp, createMmkvStorage, createReactNativeBiometrics, createRnfsFileSystem, ensureMiniApp, getLocalMiniApp, getMiniAppCatalog, getMiniAppCatalogEntry, getMiniAppStatuses, getMiniAppUpdate, installBundledMiniApp, onMiniAppEvent, openMiniApp, pauseMiniApp, pauseMiniAppDownloads, preloadMiniApp, releaseSpeechFor, restoreMiniApp, resumeMiniApp, resumeMiniAppDownloads, sendEventToWeb, syncMiniAppCatalog, uninstallMiniApp, updateMiniApp, uploadToUrl, useMiniAppDownload, useMiniAppDownloadsPaused };
|
|
807
|
+
export { CodeType, DefaultMiniAppSplash, type LocationOptions, type LocationResult, MINIAPP_PLATFORM_URL, type MiniAppBiometricAvailability, type MiniAppBiometricRequest, type MiniAppBiometricResult, type MiniAppBiometrics, type MiniAppBiometryType, type MiniAppBridgeOptions, type MiniAppCatalogEntry, type MiniAppCatalogItem, type MiniAppChannel, type MiniAppConfig, type MiniAppContainerProps, type MiniAppContext, type MiniAppDownloadState, type MiniAppDownloadStatus, type MiniAppDownloadTask, type MiniAppEvent, type MiniAppFileSystem, type MiniAppHandlerContext, type MiniAppHapticType, _default as MiniAppHost, type MiniAppHostData, BridgeError as MiniAppHostError, type MiniAppHostProps, type MiniAppKeepAlive, type MiniAppLaunch, type MiniAppLocalBundle, type MiniAppManifest, type MiniAppNativeHandlers, type MiniAppPaymentRequest, type MiniAppPaymentResult, type MiniAppPermission, type MiniAppPickedFile, type MiniAppSpeechProvider, type MiniAppSpeechStartContext, type MiniAppSplashProps, type MiniAppStorage, type MiniAppSyncResult, type MiniAppUpdate, type MiniAppUploadCaller, type MiniAppUploadOptions, type MiniAppUploadProcessOptions, type MiniAppUploadProcessor, type MiniAppUploadRequest, type MiniAppUploadSource, type MiniAppUploadSourceRequest, type MiniAppUploadTarget, type MiniAppUploader, type MiniAppUrlUploadTarget, type OpenMiniAppArgs, type ReactNativeBiometricsLike, ScannerEndReason, ScannerEvent, ScannerLayout, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, ToastType, type UploadCapabilities, type UploadFileType, type UploadFilesResult, type UploadedFile, closeMiniApp, configureMiniApp, createMmkvStorage, createReactNativeBiometrics, createRnfsFileSystem, ensureMiniApp, getLocalMiniApp, getMiniAppCatalog, getMiniAppCatalogEntry, getMiniAppStatuses, getMiniAppUpdate, installBundledMiniApp, onMiniAppEvent, openMiniApp, pauseMiniApp, pauseMiniAppDownloads, preloadMiniApp, releaseSpeechFor, restoreMiniApp, resumeMiniApp, resumeMiniAppDownloads, sendEventToWeb, syncMiniAppCatalog, uninstallMiniApp, updateMiniApp, uploadToUrl, useMiniAppDownload, useMiniAppDownloadsPaused };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var tr=Object.create;var ut=Object.defineProperty;var nr=Object.getOwnPropertyDescriptor;var or=Object.getOwnPropertyNames;var rr=Object.getPrototypeOf,ir=Object.prototype.hasOwnProperty;var sr=(e,t)=>{for(var n in t)ut(e,n,{get:t[n],enumerable:!0})},fn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of or(t))!ir.call(e,r)&&r!==n&&ut(e,r,{get:()=>t[r],enumerable:!(o=nr(t,r))||o.enumerable});return e};var se=(e,t,n)=>(n=e!=null?tr(rr(e)):{},fn(t||!e||!e.__esModule?ut(n,"default",{value:e,enumerable:!0}):n,e)),ar=e=>fn(ut({},"__esModule",{value:!0}),e);var si={};sr(si,{CodeType:()=>Q,DefaultMiniAppSplash:()=>dn,MINIAPP_PLATFORM_URL:()=>dt,MiniAppHost:()=>er,MiniAppHostError:()=>g,ScannerEndReason:()=>qe,ScannerEvent:()=>_t,ScannerLayout:()=>Me,ScannerMethod:()=>We,ToastType:()=>de,closeMiniApp:()=>Je,configureMiniApp:()=>yn,createMmkvStorage:()=>bn,createReactNativeBiometrics:()=>Ut,createRnfsFileSystem:()=>_n,ensureMiniApp:()=>lt,getLocalMiniApp:()=>B,getMiniAppCatalog:()=>Yo,getMiniAppCatalogEntry:()=>Ge,getMiniAppStatuses:()=>qo,getMiniAppUpdate:()=>pn,installBundledMiniApp:()=>vo,onMiniAppEvent:()=>Bo,openMiniApp:()=>Lo,pauseMiniApp:()=>jo,pauseMiniAppDownloads:()=>Jo,preloadMiniApp:()=>Fo,releaseSpeechFor:()=>ve,restoreMiniApp:()=>Wo,resumeMiniApp:()=>Ho,resumeMiniAppDownloads:()=>Go,sendEventToWeb:()=>Eo,syncMiniAppCatalog:()=>Lt,uninstallMiniApp:()=>zo,updateMiniApp:()=>Ko,uploadToUrl:()=>$t,useMiniAppDownload:()=>kt,useMiniAppDownloadsPaused:()=>Vo});module.exports=ar(si);var dt="https://retion-miniapp-platform.vercel.app",Ue=null,hn=new Set,yn=e=>{Ue=e,hn.forEach(t=>t())},q=()=>{if(!Ue)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Ue},wn=e=>{hn.add(e),Ue&&e()},ue=(...e)=>{Ue!=null&&Ue.debug&&console.log("[miniapp]",...e)};var _n=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:l,contentLength:c})=>r==null?void 0:r(l,c)});return{promise:a.then(({statusCode:l})=>({status:l})),cancel:()=>e.stopDownload(i)}}}),bn=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var A=se(require("react")),L=require("react-native"),Qo=se(require("react-native-webview"));var nt=require("react-native");var Ut=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),gt,Vt=()=>(gt||(gt=import("react-native-biometrics").then(({default:e})=>Ut(new e({allowDeviceCredentials:!1}))).catch(e=>{throw gt=void 0,new g("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),gt);var Se=require("react-native");var An=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new g("INVALID_PARAMS","Tu\u1EF3 ch\u1ECDn v\u1ECB tr\xED ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.enableHighAccuracy!==void 0&&typeof t.enableHighAccuracy!="boolean")throw new g("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,l]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let c=t[i];if(c!==void 0&&(typeof c!="number"||!Number.isFinite(c)||c<a||c>l))throw new g("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${l} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Sn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(c,s)=>{r||(r=!0,clearTimeout(a),c?o(c):n(s))},a=setTimeout(()=>i(new g("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),l=()=>r?!1:t()?!0:(i(new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!l())return;let c;try{c=(await import("@react-native-community/geolocation")).default}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(l()){if(Se.Platform.OS==="android"){let s=Se.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,d=Se.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,m=await Se.PermissionsAndroid.check(s);if(!l())return;let h=m||await Se.PermissionsAndroid.check(d);if(!l())return;if(!m&&!h){let p=await Se.PermissionsAndroid.requestMultiple([s,d]);if(!l())return;if(p[s]!==Se.PermissionsAndroid.RESULTS.GRANTED&&p[d]!==Se.PermissionsAndroid.RESULTS.GRANTED)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}l()&&c.getCurrentPosition(s=>{l()&&i(void 0,s)},s=>{var m;if(!l())return;let d=(m={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?m:"LOCATION_ERROR";i(new g(d,s.message))},e)}})().catch(c=>i(c))});var qt=require("react-native");var Bt=20,vn=20,Pn=/^[a-z][a-z0-9_-]{0,31}$/,cr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,lr=["low","medium","high"],Ce=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Y=e=>new g("INVALID_PARAMS",e),Qe=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Mn=(e,t)=>{if(e===void 0)return{};if(!Ce(e)||Object.keys(e).length>vn||Object.values(e).some(n=>typeof n!="string"))throw Y(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${vn} key)`);return e},Cn=e=>{var n,o,r,i;if(e!==void 0&&!Ce(e))throw Y("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!Pn.test(t.source)))throw Y("source ph\u1EA3i l\xE0 t\xEAn ngu\u1ED3n, vd library | camera | document");if(t.accept!==void 0&&(!Array.isArray(t.accept)||t.accept.length>50||t.accept.some(a=>typeof a!="string"||!cr.test(a))))throw Y("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!Qe(t.max_count,1,Bt))throw Y(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Bt}`);if(t.max_size!==void 0&&!Qe(t.max_size,1,Number.MAX_SAFE_INTEGER))throw Y("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!Qe(t.concurrency,1,5))throw Y("concurrency ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u20135");return{source:(n=t.source)!=null?n:"library",accept:((o=t.accept)!=null?o:[]).map(a=>a.toLowerCase()),max_count:(r=t.max_count)!=null?r:1,max_size:t.max_size,process:pr(t.process),target:ur(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},pr=e=>{if(e===void 0)return{};if(!Ce(e))throw Y("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Ce(n))throw Y("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!Qe(n[o],1,1e4))throw Y(`process.image.${o} ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u201310000`);if(n.quality!==void 0&&(typeof n.quality!="number"||n.quality<=0||n.quality>1))throw Y("process.image.quality ph\u1EA3i trong kho\u1EA3ng (0, 1]");t.image={max_width:n.max_width,max_height:n.max_height,quality:n.quality}}if(e.video!==void 0){let n=e.video;if(!Ce(n))throw Y("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!Qe(n.max_duration,1,3600))throw Y("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!lr.includes(n.quality))throw Y("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},ur=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Ce(e))throw Y("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!Pn.test(t))throw Y("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!Ce(e.params))throw Y("upload.params ph\u1EA3i l\xE0 object");return{target:t,params:(o=e.params)!=null?o:{}}}if(typeof e.url!="string"||!/^https:\/\//i.test(e.url))throw Y("upload.url ph\u1EA3i l\xE0 https");for(let a of["field_name","url_field"])if(e[a]!==void 0&&(typeof e[a]!="string"||!e[a]))throw Y(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:Mn(e.headers,"upload.headers"),form_data:Mn(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},On=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},dr=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=On(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},gr=e=>{let t=e.length>0&&e.every(o=>o.startsWith("image/")),n=e.length>0&&e.every(o=>o.startsWith("video/"));return t?"image":n?"video":"mixed"},Ye,mr=()=>(Ye!=null||(Ye=import("react-native-image-picker").catch(e=>{throw Ye=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),Ye),xn=e=>async({accept:t,max_count:n,process:o})=>{var c,s,d,m,h,p,y,C,R;let r=await mr(),i=gr(t),a={mediaType:i==="image"?"photo":i,maxWidth:(c=o.image)==null?void 0:c.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(m=(d=o.image)==null?void 0:d.quality)!=null?m:.8,videoQuality:(p=(h=o.video)==null?void 0:h.quality)!=null?p:"medium",durationLimit:(y=o.video)==null?void 0:y.max_duration,assetRepresentationMode:"compatible"},l=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(l.didCancel)return[];if(l.errorCode){let T=l.errorCode==="permission"?"PERMISSION_DENIED":l.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new g(T,(C=l.errorMessage)!=null?C:l.errorCode)}return((R=l.assets)!=null?R:[]).filter(T=>T.uri).map((T,M)=>{var b,K,te;return{uri:T.uri,name:(b=T.fileName)!=null?b:`file_${M+1}`,mime_type:(K=T.type)!=null?K:"application/octet-stream",size:T.fileSize,width:T.width,height:T.height,duration:T.duration,processed:!((te=T.type)!=null&&te.startsWith("video/"))||qt.Platform.OS==="ios"}})},fr={"image/*":"images","video/*":"video","audio/*":"audio","text/plain":"plainText","text/csv":"csv","application/pdf":"pdf","application/json":"json","application/zip":"zip","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx"},hr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},yr=e=>async({accept:t,max_count:n})=>{var i,a,l,c;let o=t.map(s=>{var d;return(d=fr[s])!=null?d:hr[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let d=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(p=>p.uri&&!p.error).map((p,y)=>{var C,R,T;return{uri:p.uri,name:(C=p.name)!=null?C:`file_${y+1}`,mime_type:(R=p.type)!=null?R:"application/octet-stream",size:(T=p.size)!=null?T:void 0}});if(qt.Platform.OS!=="android"||!e.keepLocalCopy||!d.some(p=>p.uri.startsWith("content://")))return d;let m=await e.keepLocalCopy({files:d.map(p=>({uri:p.uri,fileName:p.name})),destination:"cachesDirectory"}),h=new Map(m.map(p=>[p.sourceUri,p.status==="success"?p.localUri:void 0]));return d.map(p=>{var y;return{...p,uri:(y=h.get(p.uri))!=null?y:p.uri}})}catch(s){let d=s==null?void 0:s.code;if(d===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw d===((c=(l=e.errorCodes)==null?void 0:l.IN_PROGRESS)!=null?c:"ASYNC_OP_IN_PROGRESS")?new g("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},Xe,wr=async e=>(Xe!=null||(Xe=import("@react-native-documents/picker").then(t=>yr(t)).catch(t=>{throw Xe=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await Xe)(e)),kn={library:xn("library"),camera:xn("camera"),document:wr},En={type:"image",label:"\u1EA2nh",accept:["image/*"]},Rn={type:"video",label:"Video",accept:["video/*"]},Tn={library:[En,Rn],camera:[En,Rn],document:[{type:"any",label:"M\u1ECDi file",accept:[]},{type:"pdf",label:"PDF",accept:["application/pdf"]},{type:"word",label:"Word",accept:[".doc",".docx"]},{type:"excel",label:"Excel",accept:[".xls",".xlsx"]},{type:"powerpoint",label:"PowerPoint",accept:[".ppt",".pptx"]}]},Ze,In=()=>(Ze!=null||(Ze=import("react-native-compressor").catch(()=>(Ze=void 0,null))),Ze),Ln=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},_r=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),br={low:640,medium:1280,high:1920},Ar=async(e,{image:t})=>{var o;if(!t||!_r.has(e.mime_type.toLowerCase()))return e;let n=await In();if(!n)return e;try{let r=await n.Image.compress(e.uri,{compressionMethod:"manual",maxWidth:t.max_width,maxHeight:t.max_height,quality:(o=t.quality)!=null?o:.8,output:"jpg"});return{...e,uri:r,mime_type:"image/jpeg",name:e.name.replace(/\.[^.]+$/,"")+".jpg",size:await Ln(n,r,e.size),processed:!0}}catch{return e}},Sr=async(e,{video:t})=>{var o;let n=await In();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:br[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await Ln(n,r,e.size),processed:!0}}catch{return e}},vr={image:Ar,video:Sr},Mr=(e,t)=>t.split(".").reduce((n,o)=>Ce(n)?n[o]:void 0,e),$t=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new g("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let l=new XMLHttpRequest,c=new FormData;Object.entries(a.form_data).forEach(([m,h])=>c.append(m,h)),c.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>l.abort();o.addEventListener("abort",s);let d=m=>{o.removeEventListener("abort",s),m()};l.open("POST",a.url),Object.entries(a.headers).forEach(([m,h])=>l.setRequestHeader(m,h)),l.upload.onprogress=m=>n(m.loaded,m.total||e.size||0),l.onload=()=>d(()=>{let m=l.responseText;try{m=JSON.parse(l.responseText)}catch{}if(l.status<200||l.status>=300){i(new g("UPLOAD_FAILED",`HTTP ${l.status}`));return}let h=Mr(m,a.url_field);if(typeof h!="string"||!h){i(new g("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:h,response:m})}),l.onerror=()=>d(()=>i(new g("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),l.onabort=()=>d(()=>i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),l.send(c)}),Fn=e=>{var o,r;let t={...kn};for(let[i,a]of Object.entries((o=e==null?void 0:e.sources)!=null?o:{}))a?t[i]=a:delete t[i];let n={url:$t};for(let[i,a]of Object.entries((r=e==null?void 0:e.targets)!=null?r:{}))i!=="url"&&a&&(n[i]=a);return{sources:t,targets:n}},Dn=e=>{let{sources:t,targets:n}=Fn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===kn[i]&&Tn[i]).map(i=>[i,Tn[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Bt}},ft=new Map,Nn=(e,t)=>`${e}:${t}`,xr=0,Un=(e,t)=>{var n;typeof t=="string"&&((n=ft.get(Nn(e,t)))==null||n.abort())},Ve=e=>{for(let[t,n]of ft)t.startsWith(`${e}:`)&&n.abort()},mt=()=>new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),Er=(e,t)=>{var n;return{name:e,code:typeof(t==null?void 0:t.code)=="string"?t.code:"UPLOAD_FAILED",message:String((n=t==null?void 0:t.message)!=null?n:t)}},Vn=async(e,t)=>{var c;let{sources:n,targets:o}=Fn(t.config),r=n[e.source];if(!r)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=o[e.target.target];if(!i)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,l=Nn(t.instance_id,(c=t.task_id)!=null?c:`auto-${++xr}`);ft.set(l,a);try{return await Rr(e,t,r,i,a.signal)}finally{ft.delete(l)}},Rr=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:l=m=>m()},c,s,d)=>{var w,x,J;let m={app_id:n!=null?n:"",instance_id:t,context:{...(w=o==null?void 0:o())!=null?w:{}}},h=(await l(()=>c({accept:e.accept,max_count:e.max_count,process:e.process,caller:m}))).slice(0,e.max_count);if(d.aborted)throw mt();if(!h.length)throw new g("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let p=[],y=h.filter(P=>dr(P,e.accept)?!0:(p.push({name:P.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${P.mime_type||On(P.name)}`}),!1)),C=y.map(()=>0),R=y.map(P=>{var F;return(F=P.size)!=null?F:0}),T=0,M=0,b=(P=!1)=>{if(!a||!r)return;let F=Date.now();if(!P&&F-M<200)return;M=F;let N=R.reduce((U,ne)=>U+ne,0),z=C.reduce((U,ne)=>U+ne,0);a("upload.progress",{task_id:r,loaded:z,total:N,percent:N?Math.min(100,Math.round(z/N*100)):0,done_count:T,count:y.length})},K=[],te=0,re=async()=>{var P,F,N;for(;te<y.length;){let z=te++,U=y[z];try{if(d.aborted)throw mt();let ne=U.mime_type.startsWith("image/")?"image":U.mime_type.startsWith("video/")?"video":void 0,De=ne&&!U.processed?(F=(P=i==null?void 0:i.processors)==null?void 0:P[ne])!=null?F:vr[ne]:void 0;if(De&&(U=await De(U,e.process),R[z]=(N=U.size)!=null?N:R[z],d.aborted))throw mt();if(e.max_size&&U.size&&U.size>e.max_size)throw new g("FILE_TOO_LARGE",`File ${U.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let ye=(Ee,Re)=>{C[z]=Ee,Re&&(R[z]=Re),b()},ie=await s({file:U,target:e.target,onProgress:ye,signal:d,caller:m});if(typeof(ie==null?void 0:ie.url)!="string"||!ie.url)throw new g("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:Ne,...xe}=ie;K[z]={url:Ne,name:U.name,mime_type:U.mime_type,size:U.size,width:U.width,height:U.height,duration:U.duration,...Object.keys(xe).length?{response:"response"in xe?xe.response:xe}:{}},C[z]=R[z]}catch(ne){p.push(Er(y[z].name,ne))}finally{T++,b(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,y.length)},re)),d.aborted)throw mt();let Ae=K.filter(P=>!!P);if(!Ae.length){let P=p[0];throw new g((x=P==null?void 0:P.code)!=null?x:"UPLOAD_FAILED",(J=P==null?void 0:P.message)!=null?J:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:Ae,failed:p}};var ht=require("react"),Oe=e=>{let t=e,n=new Set;return{getState:()=>t,setState:o=>{let r=typeof o=="function"?o(t):o;t={...t,...r},n.forEach(i=>i())},subscribe:o=>(n.add(o),()=>{n.delete(o)})}},j=(e,t,n=Object.is)=>{let o=(0,ht.useRef)(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let l=t(i),c=a&&n(a.value,l)?a.value:l;return o.current={state:i,selector:t,value:c},c};return(0,ht.useSyncExternalStore)(e.subscribe,r)};var de={info:"info",success:"success",error:"error"},Tr=200,Bn={info:2e3,success:2e3,error:3e3},et=Oe({message:"",type:de.info,tick:0}),qn=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Tr);return o?{message:o,type:Object.values(de).includes(n)?n:de.info}:null},$n=(e,t=de.info)=>{et.setState(n=>({message:e,type:t,tick:n.tick+1}))};var me=require("react-native");var Be=require("react-native");var ge,zn=()=>Be.Platform.OS==="android"&&!!(ge!=null&&ge.requesting_permission),Pr=1500,yt=()=>new Promise(e=>{if(Be.Platform.OS!=="android"||Be.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Pr),o=Be.AppState.addEventListener("change",r=>{r==="active"&&t()})}),zt=e=>{var t;if(ge===e&&(ge=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Be.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Wn=async(e,t,n,o=()=>!0)=>{var i,a,l,c,s;if(ge)throw new g("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};ge=r;try{let d;try{d=await import("expo-speech-recognition")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let m=d.ExpoSpeechRecognitionModule;if(r.native=m,r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let h;try{h=await m.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await yt(),r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!h.granted)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await m.getStateAsync()!=="inactive")throw new g("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(m.addListener("result",p=>{var y,C;ge!==r||r.cancelled||n(p.isFinal?"speech.final":"speech.partial",{...p,text:(C=(y=p.results[0])==null?void 0:y.transcript)!=null?C:""})}),m.addListener("error",p=>{ge===r&&!r.cancelled&&n("speech.error",{...p,code:p.error})}),m.addListener("end",()=>{ge===r&&(zt(r),n("speech.end"))})),r.started=!0,m.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(l=t.interimResults)!=null?l:!0,addsPunctuation:(c=t.addsPunctuation)!=null?c:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:d.AVAudioSessionCategory.playAndRecord,categoryOptions:[d.AVAudioSessionCategoryOptions.defaultToSpeaker,d.AVAudioSessionCategoryOptions.allowBluetooth],mode:d.AVAudioSessionMode.measurement}})}catch(d){throw zt(r),d}},jn=e=>{let t=ge;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},ve=e=>{let t=ge;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{zt(t)}};var Hn={qr:"qr",ean13:"ean-13",ean8:"ean-8",upcA:"upc-a",upcE:"upc-e",code128:"code-128",code39:"code-39",code93:"code-93",codabar:"codabar",itf:"itf",pdf417:"pdf-417",aztec:"aztec",dataMatrix:"data-matrix"},Q={...Hn,all:Object.values(Hn)},We={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},_t={result:"scanner.result",end:"scanner.end"},qe={user:"user",web:"web",closed:"closed",error:"error"},Me={top:"top",full:"full"},$e={once:"once",continuous:"continuous"},Cr=1500,Jn=6e4,V,X=Oe({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),Kn=()=>me.Platform.OS==="android"&&!!(V!=null&&V.requesting_permission),jt=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r}=e!=null?e:{},i={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(a=>Q.all.includes(a)))throw new g("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");i.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>Jn)throw new g("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${Jn}`);i.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new g("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");i.hint=o}if(r!==void 0){if(!Object.values(Me).includes(r))throw new g("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");i.layout=r}return i},Ht=e=>V!==e?!1:(V=void 0,X.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Or=()=>me.Alert.alert("Ch\u01B0a c\u1EA5p quy\u1EC1n camera","H\xE3y b\u1EADt quy\u1EC1n camera trong C\xE0i \u0111\u1EB7t \u0111\u1EC3 qu\xE9t m\xE3.",[{text:"Hu\u1EF7",style:"cancel"},{text:"M\u1EDF C\xE0i \u0111\u1EB7t",onPress:()=>{me.Linking.openSettings().catch(()=>{})}}]),Yn=async(e,t)=>{if(V)throw new g("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");V=e;let n=()=>{if(e.cancelled||!t())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=me.Platform.OS==="ios"&&r==="denied";e.requesting_permission=!0;let l;try{l=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await yt(),n(),l!=="granted")throw a&&Or(),new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new g("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await Jt();n(),X.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw Ht(e),o}},wt;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{wt=e==null?void 0:e.insets}).catch(()=>{});var bt=()=>{var e;return wt!=null?wt:{top:me.Platform.OS==="ios"?54:(e=me.StatusBar.currentHeight)!=null?e:0,bottom:me.Platform.OS==="ios"?34:48}},Jt=async()=>{if(me.Platform.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},Xn=(e,t,n)=>{var o,r,i;return{owner:e,mode:t,types:(o=n.types)!=null?o:Q.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Cr,hint:n.hint,layout:t===$e.once?Me.full:(i=n.layout)!=null?i:Me.top,cancelled:!1,requesting_permission:!1,last_seen:new Map}},Zn=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=Xn(e,$e.once,t);a.onHit=o,a.resolve=r,a.reject=i,Yn(a,n).catch(i)}),Qn=(e,t,n,o=()=>!0,r)=>{let i=Xn(e,$e.continuous,t);return i.emit=n,i.onHit=r,Yn(i,o)},At=(e,t,n)=>{var o,r;if(!X.getState().active){e.cancelled=!0;return}if(Ht(e)){if(e.mode===$e.once){(o=e.reject)==null||o.call(e,t===qe.error?new g("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new g("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,_t.end,n?{reason:t,message:n}:{reason:t})}},eo=e=>{(V==null?void 0:V.owner)===e&&At(V,qe.web)},ke=e=>{(V==null?void 0:V.owner)===e&&At(V,qe.closed)},Gt=()=>{V&&At(V,qe.user)},to=e=>{V&&At(V,qe.error,e)},Kt=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=V;if(!(!o||!X.getState().active))for(let{value:l,type:c}of e){if(!l)continue;let s=o.last_seen.get(l);if(o.last_seen.set(l,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===$e.once){Ht(o),(i=o.resolve)==null||i.call(o,{value:l,type:c});return}X.setState(d=>({last_value:l,hit_tick:d.hit_tick+1,scan_count:d.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,_t.result,{value:l,type:c})}}},kr={1:Q.code128,2:Q.code39,4:Q.code93,8:Q.codabar,16:Q.dataMatrix,32:Q.ean13,64:Q.ean8,128:Q.itf,256:Q.qr,512:Q.upcA,1024:Q.upcE,2048:Q.pdf417,4096:Q.aztec},Ir=2500,Gn=2e3,Wt=e=>{X.setState({notice:e}),setTimeout(()=>{X.getState().notice===e&&X.setState({notice:null})},Ir)},no=async()=>{var t,n;let e=V;if(!(!e||X.getState().is_picking)){e.requesting_permission=!0,X.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:Gn,maxHeight:Gn}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||V!==e)return;if(r.errorCode||!i){Wt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),l=await a.scan(i);if(V!==e)return;let c=l.map(({value:s,format:d})=>({value:s,code_type:kr[d]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:d})=>({value:s,type:d!=null?d:"unknown"}));if(!c.length){Wt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}Kt(c,Date.now(),!0)}catch{V===e&&Wt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await yt(),e.requesting_permission=!1,V===e&&X.setState({is_picking:!1})}}};var vt=1,g=class extends Error{constructor(n,o){super(o);this.code=n}},oo=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===vt&&typeof t.method=="string"?t:null}catch{return null}},ot=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,ro=(e,t)=>ot({id:e,result:t}),io=(e,t)=>ot({id:e,error:{code:t.code,message:t.message}}),so=(e,t)=>ot({event:e,data:t}),Xt=e=>ot({event:"context",data:e});var ao=()=>`(function () {
|
|
1
|
+
"use strict";var pr=Object.create;var ht=Object.defineProperty;var ur=Object.getOwnPropertyDescriptor;var dr=Object.getOwnPropertyNames;var gr=Object.getPrototypeOf,mr=Object.prototype.hasOwnProperty;var fr=(e,t)=>{for(var n in t)ht(e,n,{get:t[n],enumerable:!0})},Sn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of dr(t))!mr.call(e,r)&&r!==n&&ht(e,r,{get:()=>t[r],enumerable:!(o=ur(t,r))||o.enumerable});return e};var le=(e,t,n)=>(n=e!=null?pr(gr(e)):{},Sn(t||!e||!e.__esModule?ht(n,"default",{value:e,enumerable:!0}):n,e)),hr=e=>Sn(ht({},"__esModule",{value:!0}),e);var hi={};fr(hi,{CodeType:()=>ee,DefaultMiniAppSplash:()=>bn,MINIAPP_PLATFORM_URL:()=>yt,MiniAppHost:()=>lr,MiniAppHostError:()=>m,ScannerEndReason:()=>ze,ScannerEvent:()=>xt,ScannerLayout:()=>pe,ScannerMethod:()=>He,ToastType:()=>fe,closeMiniApp:()=>Ke,configureMiniApp:()=>Mn,createMmkvStorage:()=>Rn,createReactNativeBiometrics:()=>Wt,createRnfsFileSystem:()=>En,ensureMiniApp:()=>gt,getLocalMiniApp:()=>B,getMiniAppCatalog:()=>ir,getMiniAppCatalogEntry:()=>Ye,getMiniAppStatuses:()=>Yo,getMiniAppUpdate:()=>yn,installBundledMiniApp:()=>ko,onMiniAppEvent:()=>Ko,openMiniApp:()=>zo,pauseMiniApp:()=>er,pauseMiniAppDownloads:()=>nr,preloadMiniApp:()=>Wo,releaseSpeechFor:()=>Re,restoreMiniApp:()=>Qo,resumeMiniApp:()=>tr,resumeMiniAppDownloads:()=>or,sendEventToWeb:()=>Fo,syncMiniAppCatalog:()=>Bt,uninstallMiniApp:()=>Zo,updateMiniApp:()=>rr,uploadToUrl:()=>Gt,useMiniAppDownload:()=>Ut,useMiniAppDownloadsPaused:()=>Go});module.exports=hr(hi);var yt="https://retion-miniapp-platform.vercel.app",Be=null,vn=new Set,Mn=e=>{Be=e,vn.forEach(t=>t())},$=()=>{if(!Be)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Be},xn=e=>{vn.add(e),Be&&e()},me=(...e)=>{Be!=null&&Be.debug&&console.log("[miniapp]",...e)};var En=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:c,contentLength:l})=>r==null?void 0:r(c,l)});return{promise:a.then(({statusCode:c})=>({status:c})),cancel:()=>e.stopDownload(i)}}}),Rn=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var A=le(require("react")),L=require("react-native"),cr=le(require("react-native-webview"));var st=require("react-native");var Wt=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),wt,jt=()=>(wt||(wt=import("react-native-biometrics").then(({default:e})=>Wt(new e({allowDeviceCredentials:!1}))).catch(e=>{throw wt=void 0,new m("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),wt);var Ee=require("react-native");var Pn=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new m("INVALID_PARAMS","Tu\u1EF3 ch\u1ECDn v\u1ECB tr\xED ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.enableHighAccuracy!==void 0&&typeof t.enableHighAccuracy!="boolean")throw new m("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,c]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let l=t[i];if(l!==void 0&&(typeof l!="number"||!Number.isFinite(l)||l<a||l>c))throw new m("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${c} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Tn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(l,s)=>{r||(r=!0,clearTimeout(a),l?o(l):n(s))},a=setTimeout(()=>i(new m("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),c=()=>r?!1:t()?!0:(i(new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!c())return;let l;try{l=(await import("@react-native-community/geolocation")).default}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(Ee.Platform.OS==="android"){let s=Ee.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,g=Ee.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,d=await Ee.PermissionsAndroid.check(s);if(!c())return;let y=d||await Ee.PermissionsAndroid.check(g);if(!c())return;if(!d&&!y){let u=await Ee.PermissionsAndroid.requestMultiple([s,g]);if(!c())return;if(u[s]!==Ee.PermissionsAndroid.RESULTS.GRANTED&&u[g]!==Ee.PermissionsAndroid.RESULTS.GRANTED)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}c()&&l.getCurrentPosition(s=>{c()&&i(void 0,s)},s=>{var d;if(!c())return;let g=(d={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?d:"LOCATION_ERROR";i(new m(g,s.message))},e)}})().catch(l=>i(l))});var Jt=require("react-native");var Ht=20,Cn=20,Dn=/^[a-z][a-z0-9_-]{0,31}$/,yr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,wr=["low","medium","high"],ke=e=>!!e&&typeof e=="object"&&!Array.isArray(e),Y=e=>new m("INVALID_PARAMS",e),ot=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,On=(e,t)=>{if(e===void 0)return{};if(!ke(e)||Object.keys(e).length>Cn||Object.values(e).some(n=>typeof n!="string"))throw Y(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Cn} key)`);return e},Nn=e=>{var n,o,r,i;if(e!==void 0&&!ke(e))throw Y("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!Dn.test(t.source)))throw Y("source ph\u1EA3i l\xE0 t\xEAn ngu\u1ED3n, vd library | camera | document");if(t.accept!==void 0&&(!Array.isArray(t.accept)||t.accept.length>50||t.accept.some(a=>typeof a!="string"||!yr.test(a))))throw Y("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!ot(t.max_count,1,Ht))throw Y(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Ht}`);if(t.max_size!==void 0&&!ot(t.max_size,1,Number.MAX_SAFE_INTEGER))throw Y("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!ot(t.concurrency,1,5))throw Y("concurrency ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u20135");return{source:(n=t.source)!=null?n:"library",accept:((o=t.accept)!=null?o:[]).map(a=>a.toLowerCase()),max_count:(r=t.max_count)!=null?r:1,max_size:t.max_size,process:br(t.process),target:_r(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},br=e=>{if(e===void 0)return{};if(!ke(e))throw Y("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!ke(n))throw Y("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!ot(n[o],1,1e4))throw Y(`process.image.${o} ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u201310000`);if(n.quality!==void 0&&(typeof n.quality!="number"||n.quality<=0||n.quality>1))throw Y("process.image.quality ph\u1EA3i trong kho\u1EA3ng (0, 1]");t.image={max_width:n.max_width,max_height:n.max_height,quality:n.quality}}if(e.video!==void 0){let n=e.video;if(!ke(n))throw Y("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!ot(n.max_duration,1,3600))throw Y("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!wr.includes(n.quality))throw Y("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},_r=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!ke(e))throw Y("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!Dn.test(t))throw Y("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!ke(e.params))throw Y("upload.params ph\u1EA3i l\xE0 object");return{target:t,params:(o=e.params)!=null?o:{}}}if(typeof e.url!="string"||!/^https:\/\//i.test(e.url))throw Y("upload.url ph\u1EA3i l\xE0 https");for(let a of["field_name","url_field"])if(e[a]!==void 0&&(typeof e[a]!="string"||!e[a]))throw Y(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:On(e.headers,"upload.headers"),form_data:On(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},Un=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},Ar=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=Un(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},Sr=e=>{let t=e.length>0&&e.every(o=>o.startsWith("image/")),n=e.length>0&&e.every(o=>o.startsWith("video/"));return t?"image":n?"video":"mixed"},et,vr=()=>(et!=null||(et=import("react-native-image-picker").catch(e=>{throw et=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),et),kn=e=>async({accept:t,max_count:n,process:o})=>{var l,s,g,d,y,u,w,I,P;let r=await vr(),i=Sr(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(d=(g=o.image)==null?void 0:g.quality)!=null?d:.8,videoQuality:(u=(y=o.video)==null?void 0:y.quality)!=null?u:"medium",durationLimit:(w=o.video)==null?void 0:w.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let E=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new m(E,(I=c.errorMessage)!=null?I:c.errorCode)}return((P=c.assets)!=null?P:[]).filter(E=>E.uri).map((E,M)=>{var N,z,ne;return{uri:E.uri,name:(N=E.fileName)!=null?N:`file_${M+1}`,mime_type:(z=E.type)!=null?z:"application/octet-stream",size:E.fileSize,width:E.width,height:E.height,duration:E.duration,processed:!((ne=E.type)!=null&&ne.startsWith("video/"))||Jt.Platform.OS==="ios"}})},Mr={"image/*":"images","video/*":"video","audio/*":"audio","text/plain":"plainText","text/csv":"csv","application/pdf":"pdf","application/json":"json","application/zip":"zip","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx"},xr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},Er=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var g;return(g=Mr[s])!=null?g:xr[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let g=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(u=>u.uri&&!u.error).map((u,w)=>{var I,P,E;return{uri:u.uri,name:(I=u.name)!=null?I:`file_${w+1}`,mime_type:(P=u.type)!=null?P:"application/octet-stream",size:(E=u.size)!=null?E:void 0}});if(Jt.Platform.OS!=="android"||!e.keepLocalCopy||!g.some(u=>u.uri.startsWith("content://")))return g;let d=await e.keepLocalCopy({files:g.map(u=>({uri:u.uri,fileName:u.name})),destination:"cachesDirectory"}),y=new Map(d.map(u=>[u.sourceUri,u.status==="success"?u.localUri:void 0]));return g.map(u=>{var w;return{...u,uri:(w=y.get(u.uri))!=null?w:u.uri}})}catch(s){let g=s==null?void 0:s.code;if(g===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw g===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new m("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},tt,Rr=async e=>(tt!=null||(tt=import("@react-native-documents/picker").then(t=>Er(t)).catch(t=>{throw tt=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await tt)(e)),Vn={library:kn("library"),camera:kn("camera"),document:Rr},In={type:"image",label:"\u1EA2nh",accept:["image/*"]},Ln={type:"video",label:"Video",accept:["video/*"]},Fn={library:[In,Ln],camera:[In,Ln],document:[{type:"any",label:"M\u1ECDi file",accept:[]},{type:"pdf",label:"PDF",accept:["application/pdf"]},{type:"word",label:"Word",accept:[".doc",".docx"]},{type:"excel",label:"Excel",accept:[".xls",".xlsx"]},{type:"powerpoint",label:"PowerPoint",accept:[".ppt",".pptx"]}]},nt,Bn=()=>(nt!=null||(nt=import("react-native-compressor").catch(()=>(nt=void 0,null))),nt),qn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},Pr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),Tr={low:640,medium:1280,high:1920},Cr=async(e,{image:t})=>{var o;if(!t||!Pr.has(e.mime_type.toLowerCase()))return e;let n=await Bn();if(!n)return e;try{let r=await n.Image.compress(e.uri,{compressionMethod:"manual",maxWidth:t.max_width,maxHeight:t.max_height,quality:(o=t.quality)!=null?o:.8,output:"jpg"});return{...e,uri:r,mime_type:"image/jpeg",name:e.name.replace(/\.[^.]+$/,"")+".jpg",size:await qn(n,r,e.size),processed:!0}}catch{return e}},Or=async(e,{video:t})=>{var o;let n=await Bn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:Tr[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await qn(n,r,e.size),processed:!0}}catch{return e}},kr={image:Cr,video:Or},Ir=(e,t)=>t.split(".").reduce((n,o)=>ke(n)?n[o]:void 0,e),Gt=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new m("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([d,y])=>l.append(d,y)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let g=d=>{o.removeEventListener("abort",s),d()};c.open("POST",a.url),Object.entries(a.headers).forEach(([d,y])=>c.setRequestHeader(d,y)),c.upload.onprogress=d=>n(d.loaded,d.total||e.size||0),c.onload=()=>g(()=>{let d=c.responseText;try{d=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new m("UPLOAD_FAILED",`HTTP ${c.status}`));return}let y=Ir(d,a.url_field);if(typeof y!="string"||!y){i(new m("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:y,response:d})}),c.onerror=()=>g(()=>i(new m("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>g(()=>i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),$n=e=>{var o,r;let t={...Vn};for(let[i,a]of Object.entries((o=e==null?void 0:e.sources)!=null?o:{}))a?t[i]=a:delete t[i];let n={url:Gt};for(let[i,a]of Object.entries((r=e==null?void 0:e.targets)!=null?r:{}))i!=="url"&&a&&(n[i]=a);return{sources:t,targets:n}},zn=e=>{let{sources:t,targets:n}=$n(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===Vn[i]&&Fn[i]).map(i=>[i,Fn[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Ht}},_t=new Map,Wn=(e,t)=>`${e}:${t}`,Lr=0,jn=(e,t)=>{var n;typeof t=="string"&&((n=_t.get(Wn(e,t)))==null||n.abort())},qe=e=>{for(let[t,n]of _t)t.startsWith(`${e}:`)&&n.abort()},bt=()=>new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),Fr=(e,t)=>{var n;return{name:e,code:typeof(t==null?void 0:t.code)=="string"?t.code:"UPLOAD_FAILED",message:String((n=t==null?void 0:t.message)!=null?n:t)}},Hn=async(e,t)=>{var l;let{sources:n,targets:o}=$n(t.config),r=n[e.source];if(!r)throw new m("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=o[e.target.target];if(!i)throw new m("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=Wn(t.instance_id,(l=t.task_id)!=null?l:`auto-${++Lr}`);_t.set(c,a);try{return await Dr(e,t,r,i,a.signal)}finally{_t.delete(c)}},Dr=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=d=>d()},l,s,g)=>{var p,x,q;let d={app_id:n!=null?n:"",instance_id:t,context:{...(p=o==null?void 0:o())!=null?p:{}}},y=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:d}))).slice(0,e.max_count);if(g.aborted)throw bt();if(!y.length)throw new m("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let u=[],w=y.filter(T=>Ar(T,e.accept)?!0:(u.push({name:T.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${T.mime_type||Un(T.name)}`}),!1)),I=w.map(()=>0),P=w.map(T=>{var ce;return(ce=T.size)!=null?ce:0}),E=0,M=0,N=(T=!1)=>{if(!a||!r)return;let ce=Date.now();if(!T&&ce-M<200)return;M=ce;let _e=P.reduce((O,oe)=>O+oe,0),K=I.reduce((O,oe)=>O+oe,0);a("upload.progress",{task_id:r,loaded:K,total:_e,percent:_e?Math.min(100,Math.round(K/_e*100)):0,done_count:E,count:w.length})},z=[],ne=0,Pe=async()=>{var T,ce,_e;for(;ne<w.length;){let K=ne++,O=w[K];try{if(g.aborted)throw bt();let oe=O.mime_type.startsWith("image/")?"image":O.mime_type.startsWith("video/")?"video":void 0,J=oe&&!O.processed?(ce=(T=i==null?void 0:i.processors)==null?void 0:T[oe])!=null?ce:kr[oe]:void 0;if(J&&(O=await J(O,e.process),P[K]=(_e=O.size)!=null?_e:P[K],g.aborted))throw bt();if(e.max_size&&O.size&&O.size>e.max_size)throw new m("FILE_TOO_LARGE",`File ${O.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let Q=(je,xe)=>{I[K]=je,xe&&(P[K]=xe),N()},re=await s({file:O,target:e.target,onProgress:Q,signal:g,caller:d});if(typeof(re==null?void 0:re.url)!="string"||!re.url)throw new m("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:ve,...Me}=re;z[K]={url:ve,name:O.name,mime_type:O.mime_type,size:O.size,width:O.width,height:O.height,duration:O.duration,...Object.keys(Me).length?{response:"response"in Me?Me.response:Me}:{}},I[K]=P[K]}catch(oe){u.push(Fr(w[K].name,oe))}finally{E++,N(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,w.length)},Pe)),g.aborted)throw bt();let ae=z.filter(T=>!!T);if(!ae.length){let T=u[0];throw new m((x=T==null?void 0:T.code)!=null?x:"UPLOAD_FAILED",(q=T==null?void 0:T.message)!=null?q:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:ae,failed:u}};var At=require("react"),Ie=e=>{let t=e,n=new Set;return{getState:()=>t,setState:o=>{let r=typeof o=="function"?o(t):o;t={...t,...r},n.forEach(i=>i())},subscribe:o=>(n.add(o),()=>{n.delete(o)})}},j=(e,t,n=Object.is)=>{let o=(0,At.useRef)(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let c=t(i),l=a&&n(a.value,c)?a.value:c;return o.current={state:i,selector:t,value:l},l};return(0,At.useSyncExternalStore)(e.subscribe,r)};var fe={info:"info",success:"success",error:"error"},Nr=200,Jn={info:2e3,success:2e3,error:3e3},rt=Ie({message:"",type:fe.info,tick:0}),Gn=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Nr);return o?{message:o,type:Object.values(fe).includes(n)?n:fe.info}:null},Kn=(e,t=fe.info)=>{rt.setState(n=>({message:e,type:t,tick:n.tick+1}))};var ye=require("react-native");var $e=require("react-native");var he,St=new Map,Yn=(e,t)=>{St.set(e,t)},Xn=e=>{St.delete(e)},Zn=()=>$e.Platform.OS==="android"&&!!(he!=null&&he.requesting_permission),Ur=1500,vt=()=>new Promise(e=>{if($e.Platform.OS!=="android"||$e.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Ur),o=$e.AppState.addEventListener("change",r=>{r==="active"&&t()})}),Kt=e=>{var t;if(he===e&&(he=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&$e.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Qn=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(he)throw new m("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};he=r;try{let g;try{g=await import("expo-speech-recognition")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let d=g.ExpoSpeechRecognitionModule;if(r.native=d,r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let y;try{y=await d.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await vt(),r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!y.granted)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await d.getStateAsync()!=="inactive")throw new m("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(d.addListener("result",u=>{var w,I;he!==r||r.cancelled||n(u.isFinal?"speech.final":"speech.partial",{...u,text:(I=(w=u.results[0])==null?void 0:w.transcript)!=null?I:""})}),d.addListener("error",u=>{he===r&&!r.cancelled&&n("speech.error",{...u,code:u.error})}),d.addListener("end",()=>{he===r&&(Kt(r),n("speech.end"))})),r.started=!0,d.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(c=t.interimResults)!=null?c:!0,addsPunctuation:(l=t.addsPunctuation)!=null?l:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:g.AVAudioSessionCategory.playAndRecord,categoryOptions:[g.AVAudioSessionCategoryOptions.defaultToSpeaker,g.AVAudioSessionCategoryOptions.allowBluetooth],mode:g.AVAudioSessionMode.measurement}})}catch(g){throw Kt(r),g}},eo=e=>{let t=he;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Re=e=>{var o;let t=St.get(e);if(t){St.delete(e);try{(o=t.release)==null||o.call(t,e)}catch{}return}let n=he;if(!(!n||n.owner!==e||n.cancelled)&&(n.cancelled=!0,n.started))try{n.native.abort()}catch{Kt(n)}};var to={qr:"qr",ean13:"ean-13",ean8:"ean-8",upcA:"upc-a",upcE:"upc-e",code128:"code-128",code39:"code-39",code93:"code-93",codabar:"codabar",itf:"itf",pdf417:"pdf-417",aztec:"aztec",dataMatrix:"data-matrix"},ee={...to,all:Object.values(to)},He={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},xt={result:"scanner.result",end:"scanner.end"},ze={user:"user",web:"web",closed:"closed",error:"error"},pe={top:"top",full:"full"},Le={once:"once",continuous:"continuous"},Vr=1500,no=6e4,V,X=Ie({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),ro=()=>ye.Platform.OS==="android"&&!!(V!=null&&V.requesting_permission),Xt=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r,absolute:i}=e!=null?e:{},a={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(c=>ee.all.includes(c)))throw new m("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");a.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>no)throw new m("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${no}`);a.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new m("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");a.hint=o}if(r!==void 0){if(!Object.values(pe).includes(r))throw new m("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");a.layout=r}if(i!==void 0){if(typeof i!="boolean")throw new m("INVALID_PARAMS","absolute ph\u1EA3i l\xE0 boolean");a.absolute=i}return a},Zt=e=>V!==e?!1:(V=void 0,X.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Br=()=>ye.Alert.alert("Ch\u01B0a c\u1EA5p quy\u1EC1n camera","H\xE3y b\u1EADt quy\u1EC1n camera trong C\xE0i \u0111\u1EB7t \u0111\u1EC3 qu\xE9t m\xE3.",[{text:"Hu\u1EF7",style:"cancel"},{text:"M\u1EDF C\xE0i \u0111\u1EB7t",onPress:()=>{ye.Linking.openSettings().catch(()=>{})}}]),io=async(e,t)=>{if(V)throw new m("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");V=e;let n=()=>{if(e.cancelled||!t())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=ye.Platform.OS==="ios"&&r==="denied";e.requesting_permission=!0;let c;try{c=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await vt(),n(),c!=="granted")throw a&&Br(),new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new m("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await Qt();n(),X.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,absolute:e.absolute,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw Zt(e),o}},Mt;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{Mt=e==null?void 0:e.insets}).catch(()=>{});var Et=()=>{var e;return Mt!=null?Mt:{top:ye.Platform.OS==="ios"?54:(e=ye.StatusBar.currentHeight)!=null?e:0,bottom:ye.Platform.OS==="ios"?34:48}},Qt=async()=>{if(ye.Platform.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},so=(e,t,n)=>{var o,r,i,a;return{owner:e,mode:t,types:(o=n.types)!=null?o:ee.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Vr,hint:n.hint,layout:t===Le.once?pe.full:(i=n.layout)!=null?i:pe.top,absolute:t!==Le.once&&((a=n.layout)!=null?a:pe.top)===pe.top&&n.absolute===!0,cancelled:!1,requesting_permission:!1,last_seen:new Map}},ao=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=so(e,Le.once,t);a.onHit=o,a.resolve=r,a.reject=i,io(a,n).catch(i)}),co=(e,t,n,o=()=>!0,r)=>{let i=so(e,Le.continuous,t);return i.emit=n,i.onHit=r,io(i,o)},Rt=(e,t,n)=>{var o,r;if(!X.getState().active){e.cancelled=!0;return}if(Zt(e)){if(e.mode===Le.once){(o=e.reject)==null||o.call(e,t===ze.error?new m("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new m("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,xt.end,n?{reason:t,message:n}:{reason:t})}},lo=e=>{(V==null?void 0:V.owner)===e&&Rt(V,ze.web)},Fe=e=>{(V==null?void 0:V.owner)===e&&Rt(V,ze.closed)},en=()=>{V&&Rt(V,ze.user)},po=e=>{V&&Rt(V,ze.error,e)},tn=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=V;if(!(!o||!X.getState().active))for(let{value:c,type:l}of e){if(!c)continue;let s=o.last_seen.get(c);if(o.last_seen.set(c,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===Le.once){Zt(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}X.setState(g=>({last_value:c,hit_tick:g.hit_tick+1,scan_count:g.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,xt.result,{value:c,type:l})}}},qr={1:ee.code128,2:ee.code39,4:ee.code93,8:ee.codabar,16:ee.dataMatrix,32:ee.ean13,64:ee.ean8,128:ee.itf,256:ee.qr,512:ee.upcA,1024:ee.upcE,2048:ee.pdf417,4096:ee.aztec},$r=2500,oo=2e3,Yt=e=>{X.setState({notice:e}),setTimeout(()=>{X.getState().notice===e&&X.setState({notice:null})},$r)},uo=async()=>{var t,n;let e=V;if(!(!e||X.getState().is_picking)){e.requesting_permission=!0,X.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:oo,maxHeight:oo}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||V!==e)return;if(r.errorCode||!i){Yt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),c=await a.scan(i);if(V!==e)return;let l=c.map(({value:s,format:g})=>({value:s,code_type:qr[g]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:g})=>({value:s,type:g!=null?g:"unknown"}));if(!l.length){Yt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}tn(l,Date.now(),!0)}catch{V===e&&Yt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await vt(),e.requesting_permission=!1,V===e&&X.setState({is_picking:!1})}}};var Tt=1,m=class extends Error{constructor(n,o){super(o);this.code=n}},go=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===Tt&&typeof t.method=="string"?t:null}catch{return null}},at=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,mo=(e,t)=>at({id:e,result:t}),fo=(e,t)=>at({id:e,error:{code:t.code,message:t.message}}),ho=(e,t)=>at({event:e,data:t}),on=e=>at({event:"context",data:e});var yo=()=>`(function () {
|
|
2
2
|
var post = function (level, args) {
|
|
3
3
|
try {
|
|
4
4
|
var parts = [];
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
else if (typeof a === 'object') { try { parts.push(JSON.stringify(a).slice(0, 800)); } catch (e) { parts.push(String(a)); } }
|
|
9
9
|
else { parts.push(String(a)); }
|
|
10
10
|
}
|
|
11
|
-
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${
|
|
11
|
+
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${Tt}, method: 'log', level: level, text: parts.join(' ') }));
|
|
12
12
|
} catch (e) {}
|
|
13
13
|
};
|
|
14
14
|
['log', 'info', 'warn', 'error'].forEach(function (level) {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
window.addEventListener('unhandledrejection', function (e) { post('error', ['[unhandledrejection]', e.reason]); });
|
|
20
20
|
// Kh\xF4ng log query (c\xF3 th\u1EC3 ch\u1EE9a token) \u2014 ch\u1EC9 \u0111\u01B0\u1EDDng d\u1EABn + route.
|
|
21
21
|
post('info', ['[page] ' + location.pathname + location.hash]);
|
|
22
|
-
})(); true;`,
|
|
22
|
+
})(); true;`,wo=()=>`(function () {
|
|
23
23
|
function atTop(el) {
|
|
24
24
|
for (var n = el; n && n !== document.documentElement; n = n.parentElement) {
|
|
25
25
|
if (n.scrollTop > 0) { return false; }
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
function report(at_top) {
|
|
31
31
|
if (at_top === last) { return; }
|
|
32
32
|
last = at_top;
|
|
33
|
-
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${
|
|
33
|
+
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${Tt}, method: 'touchAtTop', at_top: at_top }));
|
|
34
34
|
}
|
|
35
35
|
document.addEventListener('touchstart', function (e) { report(atTop(e.target)); }, { capture: true, passive: true });
|
|
36
36
|
// Cu\u1ED9n r\u1EDDi \u0111\u1EA7u trang \u2192 b\xE1o ngay, kh\xF4ng \u0111\u1EE3i l\u1EA7n ch\u1EA1m sau (tr\xE1nh host d\xF9ng gi\xE1 tr\u1ECB c\u0169 "\u0111ang \u1EDF \u0111\u1EA7u").
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
var el = e.target === document ? document.documentElement : e.target;
|
|
39
39
|
if (el && el.scrollTop > 0) { report(false); }
|
|
40
40
|
}, { capture: true, passive: true });
|
|
41
|
-
})(); true;`,
|
|
41
|
+
})(); true;`,bo=()=>`(function () {
|
|
42
42
|
if (window.__retionSafeAreaFrozen) { return; }
|
|
43
43
|
window.__retionSafeAreaFrozen = true;
|
|
44
44
|
var max = {};
|
|
@@ -59,11 +59,14 @@
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
|
-
})(); true;`,
|
|
63
|
-
${
|
|
62
|
+
})(); true;`,_o=e=>at({event:e}),Ao=(e,t)=>{let n=So(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
|
|
63
|
+
${on(e)}`},So=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),vo=(e,t={})=>{let n=So(t);return`window.__RETION_MINIAPP_HOST__ = { protocol: ${Tt} };
|
|
64
64
|
window.__RETION_MINIAPP_CONTEXT__ = ${JSON.stringify(e)};
|
|
65
65
|
${n?`try { history.replaceState(history.state, '', location.pathname + '?' + ${JSON.stringify(n)} + location.hash); } catch (e) {}`:""}
|
|
66
|
-
true;`},
|
|
66
|
+
true;`},Mo={partner:"partner_token",chatbox:"chatbox_token"},xo=(e,t)=>{let n={...e};for(let o of Object.values(Mo))t.includes(o)||delete n[o];return n},nn=new Set,it=async(e,t)=>{if(nn.has(e))throw new m("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);nn.add(e);try{return await t()}finally{nn.delete(e)}},rn=e=>`(function () {
|
|
67
|
+
window.__retionScannerHeight = ${Math.max(0,Math.round(e))};
|
|
68
|
+
window.dispatchEvent(new Event('retionscannerheight'));
|
|
69
|
+
})(); true;`,Eo=()=>`(function () {
|
|
67
70
|
try {
|
|
68
71
|
var AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
69
72
|
if (!AudioCtx) { return; }
|
|
@@ -82,4 +85,4 @@
|
|
|
82
85
|
// iOS c\xF3 th\u1EC3 \u0111\u1EC3 context \u1EDF suspended / interrupted (vd. khi camera m\u1EDF phi\xEAn quay): ch\u1EA1y l\u1EA1i xong m\u1EDBi ph\xE1t.
|
|
83
86
|
if (ctx.state === 'running') { play(); } else { ctx.resume().then(play).catch(function () {}); }
|
|
84
87
|
} catch (e) {}
|
|
85
|
-
})(); true;`,Lr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),St=(e,t)=>{if(typeof e!="string"||!e)throw new g("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},wo=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:l,instance_id:c,options:s,emit:d,isActive:m,playBeep:h})=>{var T,M,b,K,te,re,Ae;let p=s==null?void 0:s.handlers,y={app_id:l,instance_id:c,close:a},C=()=>{var w;(w=s==null?void 0:s.haptic)==null||w.call(s,"impactLight"),h==null||h()},R=()=>new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let w=An(t);return tt(e,()=>Sn(w,m))}case"speech.start":{if(!d)throw R();let w={};if((t==null?void 0:t.lang)!==void 0){if(typeof t.lang!="string"||!/^[a-zA-Z]{2,8}(-[a-zA-Z0-9]{1,8})*$/.test(t.lang))throw new g("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");w.lang=t.lang}for(let x of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[x])!==void 0){if(typeof t[x]!="boolean")throw new g("INVALID_PARAMS",`${x} ph\u1EA3i l\xE0 boolean`);w[x]=t[x]}return Wn(c,w,d,m)}case"speech.stop":return jn(c);case We.scan:return Zn(c,jt(t),m,C);case We.start:{if(!d)throw R();return Qn(c,jt(t),d,m,C)}case We.stop:return eo(c);case"uploadFiles":{let{task_id:w,...x}=t!=null?t:{};if(w!==void 0&&(typeof w!="string"||!w))throw new g("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return Vn(Cn(x),{instance_id:c,app_id:l,getContext:r,task_id:w,config:s==null?void 0:s.upload,emit:d,exclusivePick:J=>tt("uploadFiles.pick",J)})}case"uploadFiles.cancel":Un(c,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Dn(s==null?void 0:s.upload);case"getBiometricAvailability":return((T=s==null?void 0:s.biometrics)!=null?T:await Vt()).getAvailability();case"authenticateBiometric":{let w=St(t==null?void 0:t.reason,"reason").trim();if(!w||w.length>200)throw new g("INVALID_PARAMS","reason must contain 1\u2013200 characters");let x=t==null?void 0:t.cancelButtonText;if(x!==void 0&&(typeof x!="string"||!x.trim()||x.length>80))throw new g("INVALID_PARAMS","Invalid cancelButtonText");return tt(e,async()=>{var P;return((P=s==null?void 0:s.biometrics)!=null?P:await Vt()).authenticate({reason:w,cancelButtonText:x})})}case"requestPayment":{let w=p==null?void 0:p.requestPayment;if(!w)throw R();let x=t==null?void 0:t.amount;if(typeof x!="number"||!Number.isFinite(x)||x<=0)throw new g("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let J={...t,amount:x,currency:St(t==null?void 0:t.currency,"currency")};return tt(e,()=>w(J,y))}case"printImage":{let w=p==null?void 0:p.printImage;if(!w)throw R();let x=St(t==null?void 0:t.image,"image");await tt(e,()=>w({image:x},y));return}case"openScreen":if(!(p!=null&&p.openScreen))throw R();await p.openScreen({screen:St(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},y);return;case"closeApp":a();return;case"openWebview":{let w=String((M=t==null?void 0:t.url)!=null?M:"");if(!/^https?:\/\//i.test(w))throw new g("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(w):nt.Linking.openURL(w));return}case"openLink":{let w=String((b=t==null?void 0:t.url)!=null?b:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(w)||/^(javascript|file|data|about|blob):/i.test(w))throw new g("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(w):nt.Linking.openURL(w))}catch(x){throw new g("NOT_SUPPORTED",String((te=(K=x==null?void 0:x.message)!=null?K:x)!=null?te:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let w=qn(t);if(!w||(m==null?void 0:m())===!1)return;s!=null&&s.showToast?s.showToast(w.message,{type:w.type}):$n(w.message,w.type);return}case"haptic":{let w=Lr.has(t==null?void 0:t.type)?t.type:"selection";(re=s==null?void 0:s.haptic)==null||re.call(s,w);return}case"getSystemInfo":return{platform:nt.Platform.OS==="ios"?"ios":"android",appVersion:(Ae=s==null?void 0:s.app_version)!=null?Ae:"",theme:i?"dark":"light"};case"getAccessToken":{let w=n().access_token;if(!w)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return w}case"getToken":{let w=t==null?void 0:t.type;if(w==="access"){let P=n().access_token;if(!P)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return P}if(w!=="partner"&&w!=="chatbox")throw new g("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(w)}`);let x=fo[w];if(!o().includes(x))throw new g("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${x} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let J=w==="partner"?n().partner_token:n().chatbox_token;if(!J)throw new g("HOST_ERROR",`Kh\xF4ng c\xF3 ${x}`);return J}case"getUserInfo":{let w=n().user;if(!w)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return w}case"getPageInfo":{let w=n().page;if(!w)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return w}case"sendMessage":case"insertText":throw new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new g("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var Qt=e=>`bundle:${e}`,en=()=>`${q().file_system.document_dir}/miniapps`,tn=en,nn=(e,t,n="index.html",o=!1,r=[])=>{let i=`${tn()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},Zt=e=>{var t;q().storage.setString(Qt(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},Fr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,B=e=>{let t=q().storage.getString(Qt(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return nn(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Te=e=>q().file_system.exists(e.entry_uri.replace("file://","")),on=async e=>{let t=B(e.app_id);return(t==null?void 0:t.version)===e.version&&await Te(t)},bo=async(e,t)=>{let n=q().file_system,o=`${tn()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},Ao=async e=>{var t;await((t=it[e])==null?void 0:t.catch(()=>{})),q().storage.setString(Qt(e),""),await q().file_system.remove(`${tn()}/${e}`).catch(()=>{})},je=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},it={},So=(e,t)=>{var i;let o=((i=it[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return it[e]=r,r.then(()=>{it[e]===r&&delete it[e]}),o},Dr=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let l=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(l)return l}return 0},vo=({manifest:e,zip_path:t})=>So(e.app_id,async()=>{var i;let n=q().file_system,o=B(e.app_id);if(o&&Dr(o.version,e.version)>=0&&await Te(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=nn(e.app_id,e.version,e.entry,!!e.context_update,(i=e.permissions)!=null?i:[]);return await n.remove(r.dir).catch(()=>{}),await n.mkdir(r.dir),await n.unzip(t,r.dir),Zt(e),ue("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),bo(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),rn=(e,{base_url:t,onProgress:n}={})=>{let o=q().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,l=()=>{if(i)throw new je},c=async()=>{var m;l();let s=B(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return Zt(e),B(e.app_id);l();let d=o.download({url:t?Fr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(h,p)=>{var C;let y=p>0?p:(C=e.size)!=null?C:0;y>0&&(n==null||n(Math.min(1,h/y)))}});r=d;try{let{status:h}=await d.promise;if(l(),h!==200)throw new Error(`bundle ${h}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else ue("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);l();let p=nn(e.app_id,e.version,e.entry,!!e.context_update,(m=e.permissions)!=null?m:[]);return await o.remove(p.dir).catch(()=>{}),await o.mkdir(p.dir),await o.unzip(a,p.dir),Zt(e),bo(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),p}catch(h){throw i?new je:h}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:So(e.app_id,c),cancel:()=>{i=!0,r==null||r.cancel()}}},rt={},Nr=__DEV__?0:60*1e3,_o={},Mo=(e,t)=>{var o,r;let n=B(e);return n&&Date.now()-((o=_o[t])!=null?o:0)<Nr?Promise.resolve(n):((r=rt[e])!=null||(rt[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),l=await rn(a,{base_url:t}).promise;return _o[t]=Date.now(),l})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),B(e))).finally(()=>{rt[e]=void 0})),rt[e])};var Mt=new Map,xo=(e,t)=>(Mt.set(e,t),()=>{Mt.get(e)===t&&Mt.delete(e)}),Eo=(e,t)=>{let n=Mt.get(e);return n?n(t):!1};var $=require("react"),_=require("react-native");var S=require("react/jsx-runtime"),st="#22C55E",Ur="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",Vr=2,Et=18,Br=1600,at=14,qr=2e3,Po=.38,$r=40,Ro=2,zr=8,Wr=2e3,He=2e3,jr=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:at},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:at},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:at},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:at}],To=({color:e})=>(0,S.jsx)(S.Fragment,{children:jr.map((t,n)=>(0,S.jsx)(_.View,{style:[v.corner,t,{borderColor:e}]},n))}),xt=({style:e,children:t,...n})=>{let o=(0,$.useRef)(new _.Animated.Value(1)).current,r=i=>_.Animated.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return(0,S.jsx)(_.Pressable,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:(0,S.jsx)(_.Animated.View,{style:[e,{transform:[{scale:o}]}],children:t})})},an=({scanner:e})=>{var Ke,f;let{vision:t,types:n,mode:o,layout:r,hint:i,glass_view:a}=e,l=r===Me.top,c=t.useCameraDevice("back"),s=(0,$.useRef)(new _.Animated.Value(1)).current,[d,m]=(0,$.useState)(!1),[h,p]=(0,$.useState)(1),y=(0,$.useRef)(null),[C,R]=(0,$.useState)(()=>{let{width:u,height:I}=_.Dimensions.get("window");return{width:u,height:l?I*Po:I,window_y:0}}),T=j(X,u=>u.last_value),M=j(X,u=>u.hit_tick),b=j(X,u=>u.scan_count),K=j(X,u=>u.notice),te=j(X,u=>u.is_picking),re=(0,$.useRef)(null),Ae=bt(),w=Ae.top,x=(0,$.useRef)(new _.Animated.Value(0)).current,J=(0,$.useRef)(new _.Animated.Value(0)).current,P=(0,$.useRef)(new _.Animated.Value(0)).current,F=Math.round(C.width*(l?.8:.78)),N=Math.round(l?C.height*.46:F*.78),z=Math.round((C.height-N)/2),U=Math.round((C.width-F)/2),ne=t.useCodeScanner({codeTypes:n,onCodeScanned:(0,$.useCallback)(u=>Kt(u),[])});(0,$.useEffect)(()=>{let u=_.BackHandler.addEventListener("hardwareBackPress",()=>(Gt(),!0));return()=>u.remove()},[]);let De=(0,$.useRef)(M);(0,$.useEffect)(()=>{if(M===De.current)return;x.setValue(1),P.setValue(1);let u=_.Animated.parallel([_.Animated.timing(x,{toValue:0,duration:450,useNativeDriver:!0}),_.Animated.sequence([_.Animated.delay(qr),_.Animated.timing(P,{toValue:0,duration:250,useNativeDriver:!0})])]);return u.start(),()=>u.stop()},[M,x,P]),(0,$.useEffect)(()=>{let u=oe=>_.Animated.timing(J,{toValue:oe,duration:Br,easing:_.Easing.inOut(_.Easing.quad),useNativeDriver:!0}),I=_.Animated.loop(_.Animated.sequence([u(1),u(0)]));return I.start(),()=>I.stop()},[J]);let ye=(0,$.useCallback)(()=>{_.Animated.timing(s,{toValue:0,duration:220,useNativeDriver:!0}).start()},[s]);(0,$.useEffect)(()=>{let u=setTimeout(ye,Wr);return()=>clearTimeout(u)},[ye]);let[ie,Ne]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let u=requestAnimationFrame(()=>{u=requestAnimationFrame(()=>Ne(!0))});return()=>cancelAnimationFrame(u)},[]);let xe=!!(c!=null&&c.hasTorch),Ee=(Ke=c==null?void 0:c.neutralZoom)!=null?Ke:1,Re=c?Math.min(c.maxZoom/Ee,zr):1,Ft=Ee*Math.min(h,Re),Dt=u=>{var le;let{touches:I}=u.nativeEvent;if(I.length!==2){y.current=null;return}let oe=Math.hypot(I[0].pageX-I[1].pageX,I[0].pageY-I[1].pageY);(le=y.current)!=null||(y.current={distance:oe,level:h}),p(Math.max(1,Math.min(Re,y.current.level*(oe/y.current.distance))))},pt=(0,S.jsx)(_.Text,{style:[v.hint,!!K&&v.hint_notice],numberOfLines:1,children:(f=K!=null?K:i)!=null?f:Ur});return(0,S.jsx)(_.View,{ref:re,onTouchMove:Dt,onTouchEnd:()=>{y.current=null},style:l?v.top:v.full,onLayout:({nativeEvent:{layout:u}})=>{var I;(I=re.current)==null||I.measureInWindow((oe,le)=>{R({width:u.width,height:u.height,window_y:le||0})})},children:(0,S.jsxs)(_.View,{style:v.content,children:[c&&ie&&(0,S.jsx)(t.Camera,{style:_.StyleSheet.absoluteFill,device:c,isActive:!te,codeScanner:ne,torch:d&&xe?"on":"off",zoom:Ft,onPreviewStarted:ye,onError:u=>to(u.message)}),(0,S.jsx)(_.Animated.View,{style:[v.preview_cover,{opacity:s}],pointerEvents:"none"}),C.height>0&&(0,S.jsxs)(_.View,{style:v.overlay,pointerEvents:"none",children:[(0,S.jsx)(_.View,{style:[v.dim_ring,{top:z-He,left:U-He,width:F+He*2,height:N+He*2}]}),(0,S.jsxs)(_.View,{style:{position:"absolute",top:z,left:U,width:F,height:N},children:[(0,S.jsx)(To,{color:"#FFFFFF"}),(0,S.jsx)(_.Animated.View,{style:[_.StyleSheet.absoluteFill,{opacity:x}],children:(0,S.jsx)(To,{color:st})}),(0,S.jsxs)(_.Animated.View,{style:[v.scan_line_wrap,{transform:[{translateY:J.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,N-Et)]})}]}],children:[(0,S.jsx)(_.View,{style:v.scan_glow_outer}),(0,S.jsx)(_.View,{style:v.scan_glow_inner}),(0,S.jsx)(_.View,{style:v.scan_line})]})]}),(0,S.jsx)(_.View,{style:[v.hint_slot,l?{top:0,height:z-6,justifyContent:"flex-end"}:{top:z+N+20}],children:pt}),o===$e.continuous&&!!T&&(0,S.jsx)(_.Animated.View,{style:[v.result_slot,{top:l?z+N-$r:z+N+52},{opacity:P}],children:(0,S.jsxs)(_.View,{style:v.result,children:[(0,S.jsx)(_.View,{style:v.check_badge,children:(0,S.jsx)(_.View,{style:v.check_mark})}),(0,S.jsx)(_.Text,{style:v.result_text,numberOfLines:1,children:T}),(0,S.jsxs)(_.Text,{style:v.result_count,children:["\xB7 ",b," m\xE3"]})]})})]}),C.height>0&&(0,S.jsx)(_.View,{style:[v.close_slot,l?v.close_slot_top:{top:Math.max(12,w-C.window_y+12)}],children:(0,S.jsxs)(xt,{style:[v.close_button,!!a&&v.glass_surface],onPress:Gt,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[a&&(0,S.jsx)(a,{style:v.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,S.jsx)(_.View,{style:[v.close_bar,v.close_bar_a]}),(0,S.jsx)(_.View,{style:[v.close_bar,v.close_bar_b]})]})}),(0,S.jsx)(_.View,{style:[v.toolbar_wrap,!l&&{bottom:Ae.bottom+20}],pointerEvents:"box-none",children:(0,S.jsxs)(_.View,{style:[v.toolbar,!!a&&v.glass_surface],children:[a&&(0,S.jsx)(a,{style:v.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,S.jsx)(xt,{style:v.tool,onPress:no,disabled:te,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:(0,S.jsxs)(_.View,{style:v.image_icon,children:[(0,S.jsx)(_.View,{style:v.image_icon_dot}),(0,S.jsx)(_.View,{style:v.image_icon_hill})]})}),!!c&&Re>=Ro&&(0,S.jsx)(xt,{style:[v.tool,h>1&&v.tool_on],onPress:()=>p(u=>u>1?1:Ro),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:(0,S.jsxs)(_.Text,{style:[v.zoom_text,h>1&&v.zoom_text_on],children:[Math.round(h*10)/10,"x"]})}),xe&&(0,S.jsx)(xt,{style:[v.tool,d&&v.tool_on],onPress:()=>m(u=>!u),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:d},children:(0,S.jsx)(_.Text,{style:[v.torch_icon,d&&v.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},Hr="rgba(0,0,0,0.5)",sn=50,v=_.StyleSheet.create({top:{height:`${Po*100}%`,overflow:"hidden",backgroundColor:"#000000"},full:{position:"absolute",top:0,left:0,right:0,bottom:0},content:{flex:1,backgroundColor:"#000000"},preview_cover:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"#000000"},overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,overflow:"hidden"},dim_ring:{position:"absolute",borderWidth:He,borderColor:Hr,borderRadius:He+at},hint_slot:{position:"absolute",left:16,right:16,alignItems:"center"},hint:{color:"#FFFFFF",fontSize:14,fontWeight:"500"},hint_notice:{color:"#FCA5A5"},corner:{position:"absolute",width:28,height:28},scan_line_wrap:{position:"absolute",top:0,left:10,right:10,height:Et,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:Et,borderRadius:Et/2,backgroundColor:st,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:st,opacity:.2},scan_line:{height:Vr,borderRadius:1,backgroundColor:st},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_slot_top:{bottom:15},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:sn,height:sn,borderRadius:sn/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result:{maxWidth:"100%",flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:12,paddingVertical:6,borderRadius:999,backgroundColor:"rgba(39,39,42,0.9)"},check_badge:{width:18,height:18,borderRadius:9,alignItems:"center",justifyContent:"center",backgroundColor:st},check_mark:{width:5,height:9,marginTop:-2,borderRightWidth:2,borderBottomWidth:2,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_text:{flexShrink:1,color:"#FFFFFF",fontWeight:"600",fontSize:13},result_count:{color:"#A1A1AA",fontSize:13}});var fe=require("react"),E=require("react-native");var H=require("react/jsx-runtime"),cn={[de.info]:"#3B82F6",[de.success]:"#22C55E",[de.error]:"#EF4444"},Co=-120,Rt=E.Platform.OS==="android",Oo=({type:e})=>e===de.success?(0,H.jsx)(E.View,{style:ee.check_mark}):e===de.error?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(E.View,{style:[ee.cross_bar,ee.cross_a]}),(0,H.jsx)(E.View,{style:[ee.cross_bar,ee.cross_b]})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(E.View,{style:ee.info_dot}),(0,H.jsx)(E.View,{style:ee.info_bar})]}),ko=()=>{let e=j(et,h=>h.message),t=j(et,h=>h.type),n=j(et,h=>h.tick),o=(0,fe.useRef)(new E.Animated.Value(Co)).current,r=(0,fe.useRef)(new E.Animated.Value(0)).current,i=(0,fe.useRef)(new E.Animated.Value(.92)).current,a=(0,fe.useRef)(new E.Animated.Value(0)).current,[l,c]=(0,fe.useState)(),[s,d]=(0,fe.useState)(!1);(0,fe.useEffect)(()=>{let h=!0;return Jt().then(p=>{h&&p&&c(()=>p)}),()=>{h=!1}},[]);let m=(0,fe.useRef)(n);return(0,fe.useEffect)(()=>{if(n===m.current)return;E.AccessibilityInfo.announceForAccessibility(e),d(!0),a.setValue(0),i.setValue(.92);let h=E.Animated.sequence([E.Animated.parallel([E.Animated.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),E.Animated.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),E.Animated.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),E.Animated.sequence([E.Animated.delay(90),E.Animated.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),E.Animated.delay(Bn[t]),E.Animated.parallel([E.Animated.timing(o,{toValue:Co,duration:240,useNativeDriver:!0}),E.Animated.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return h.start(({finished:p})=>{p&&d(!1)}),()=>h.stop()},[n]),s?(0,H.jsx)(E.View,{style:[ee.layer,{top:bt().top+(Rt?12:8)}],pointerEvents:"none",children:(0,H.jsxs)(E.Animated.View,{style:[ee.toast,Rt&&ee.toast_android,!!l&&ee.toast_glass,{opacity:l?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[l&&(0,H.jsx)(l,{style:ee.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),Rt?(0,H.jsx)(E.Animated.View,{style:[ee.badge_halo,{backgroundColor:`${cn[t]}33`,transform:[{scale:a}]}],children:(0,H.jsx)(E.View,{style:[ee.badge,{backgroundColor:cn[t]}],children:(0,H.jsx)(Oo,{type:t})})}):(0,H.jsx)(E.Animated.View,{style:[ee.badge,{backgroundColor:cn[t],transform:[{scale:a}]}],children:(0,H.jsx)(Oo,{type:t})}),(0,H.jsx)(E.Text,{style:[ee.message,Rt&&ee.message_android],numberOfLines:2,children:e})]})}):null},ee=E.StyleSheet.create({layer:{position:"absolute",left:16,right:16,alignItems:"center",zIndex:9999,elevation:9999},toast:{maxWidth:"100%",minHeight:50,flexDirection:"row",alignItems:"center",gap:10,paddingLeft:11,paddingRight:18,paddingVertical:11,borderRadius:25,backgroundColor:"#18181B",shadowColor:"#000000",shadowOpacity:.32,shadowRadius:18,shadowOffset:{width:0,height:8},elevation:12},toast_android:{width:"100%",minHeight:60,gap:12,paddingLeft:10,paddingRight:16,paddingVertical:10,borderRadius:20,borderWidth:E.StyleSheet.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ae=Oe({active_key:null,instances:{}}),Io=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var l;let a=(l=q().keep_alive)==null?void 0:l.max_webviews;ae.setState(c=>{let s=t!=null?t:e.app_id,d={...c.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},m=Object.keys(d);return a&&a>0&&m.length>a&&m.filter(h=>h!==s).sort((h,p)=>d[h].last_used_at-d[p].last_used_at).slice(0,m.length-a).forEach(h=>{delete d[h]}),i?{active_key:s,instances:d}:{instances:d}})},Lo=e=>Io(e,!0),Fo=e=>Io(e,!1),Je=()=>ae.setState({active_key:null}),Tt=e=>{ae.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var Do="catalog",Jr="paused_apps",Gr="removed_apps",Kr=10*1e3,Yr=2,Xr=3e3,Zr=()=>{var e;try{return JSON.parse((e=q().storage.getString(Do))!=null?e:"{}")}catch{return{}}},D=Oe({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),No=e=>{var t;return!!((t=q().manual_update)!=null&&t.includes(e))},Ot=new Set,Uo=e=>{let t=new Set,n=()=>q().storage.setString(e,JSON.stringify([...t]));return{has:o=>t.has(o),values:()=>[...t],add:o=>t.has(o)?!1:(t.add(o),n(),!0),delete:o=>t.delete(o)?(n(),!0):!1,load:()=>{var o;t.clear();try{let r=JSON.parse((o=q().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},be=Uo(Jr),Fe=Uo(Gr);wn(()=>{be.load(),Fe.load();let e=Zr(),t={};Object.keys(e).filter(n=>!Fe.has(n)).forEach(n=>{let o=B(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:be.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),D.setState({catalog:e,downloads:t})});var kt=e=>j(D,t=>e?t.downloads[e]:void 0),Vo=()=>j(D,e=>e.pause_reasons.length>0),_e=(...e)=>ue("queue",...e),Z=[],Pe={},O=null,Pt=new Set,ze={},ln=new Set,Ie=e=>{ln.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Bo=e=>(ln.add(e),()=>{ln.delete(e)}),qo=()=>D.getState().downloads,ce=(e,t)=>{let n=!!B(e),o=D.getState().downloads[e],r=t.status==="downloading"&&n?"updating":t.status,i={...o!=null?o:{status:"queued",progress:0},...t,...r?{status:r}:{},has_local:n};D.setState(a=>({downloads:{...a.downloads,[e]:i}})),(o==null?void 0:o.status)!==i.status||(o==null?void 0:o.version)!==i.version||(o==null?void 0:o.has_local)!==i.has_local?Ie({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Ie({type:"progress",app_id:e,progress:i.progress,version:i.version})},Ct=(e,t)=>{var n;(n=ze[e])==null||n.forEach(o=>o(t)),delete ze[e]},Qr=()=>D.getState().pause_reasons.length>0,Le=e=>{var l;if(O)return;let t=e?Z.indexOf(e):Qr()?-1:Z.findIndex(c=>!be.has(c));if(t<0||t>=Z.length)return;let[n]=Z.splice(t,1),o=D.getState().catalog[n];if(!o){Ct(n,B(n)),Le();return}let r=Date.now();Pe[n]=((l=Pe[n])!=null?l:0)+1,ce(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=rn(o,{onProgress:c=>{let s=Math.floor(c*100);s!==i&&(i=s,ce(n,{progress:s/100,version:o.version}))}});O={app_id:n,handle:a,forced:!!e},_e("start",n,o.version,e?"(forced)":""),a.promise.then(c=>{_e("installed",n,o.version,`${Date.now()-r}ms`),ce(n,{status:"installed",progress:1,version:o.version}),Ct(n,c)}).catch(c=>{var d;if(c instanceof je){if(Pt.has(n))return;_e("paused",n),Pe[n]-=1,Z.unshift(n),ce(n,{status:be.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((d=c==null?void 0:c.message)!=null?d:c);if(console.warn("[miniapp-queue] failed",n,s),Pe[n]<Yr){ce(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var m;Z.includes(n)||(O==null?void 0:O.app_id)===n||(Z.push(n),Le((m=ze[n])!=null&&m.length?n:void 0))},Xr);return}ce(n,{status:"failed",progress:0,version:o.version,error:s}),Ct(n,B(n))}).finally(()=>{O=null;let c=Z.find(s=>{var d;return(d=ze[s])==null?void 0:d.length});Le(c)})},It=(e,{front:t=!1}={})=>{if((O==null?void 0:O.app_id)===e)return;let n=Z.indexOf(e);if(n>=0){if(!t)return;Z.splice(n,1)}t?Z.unshift(e):Z.push(e)},ei=async e=>{let{host_id:t,client_token:n}=q(),o=new AbortController,r=setTimeout(()=>o.abort(),Kr);try{let i=`${dt}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(c=>({...c,channel:e}))}finally{clearTimeout(r)}},ct=null,Lt=()=>(ct!=null||(ct=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(q().channels.map(ei)),o={};[...n].reverse().flat().forEach(c=>{o[c.app_id]=c});let r=Object.keys(D.getState().catalog).filter(c=>!o[c]);q().storage.setString(Do,JSON.stringify(o)),D.setState({catalog:o}),await Promise.all(r.map(c=>$o(c,{by_user:!1}))),r.forEach(c=>Fe.delete(c));let i=Object.keys(o).filter(c=>!Fe.has(c)),a=[],l={};for(let c of i.map(s=>o[s])){if(await on(c)){ce(c.app_id,{status:"installed",progress:1,version:c.version});continue}let s=B(c.app_id);if(No(c.app_id)&&!Ot.has(c.app_id)&&s&&await Te(s)){ce(c.app_id,{status:"installed",progress:1,version:s.version}),l[c.app_id]={app_id:c.app_id,current_version:s.version,next_version:c.version};continue}a.push(c)}return D.setState({updates:l}),a.forEach(c=>{Pe[c.app_id]=0,ce(c.app_id,{status:be.has(c.app_id)?"paused":"queued",progress:0,version:c.version,error:void 0}),It(c.app_id)}),_e("catalog",i.length,"apps, outdated",a.map(c=>c.app_id),"removed",r,`${Date.now()-e}ms`),Ie({type:"sync_complete",app_ids:i,removed:r}),Object.values(l).forEach(c=>Ie({type:"update_available",...c})),Le(),{ok:!0,app_ids:i,removed:r}}catch(n){let o=String((n==null?void 0:n.name)==="AbortError"?"timeout":(t=n==null?void 0:n.message)!=null?t:n);return console.warn("[miniapp-queue] sync catalog failed",o),Ie({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{ct=null}})()),ct),$o=async(e,{by_user:t})=>{var r,i,a,l;if(t&&Fe.add(e),Pt.has(e))return;Pt.add(e),be.delete(e);let n=Z.indexOf(e);n>=0&&Z.splice(n,1),(O==null?void 0:O.app_id)===e&&O.handle.cancel();let o=(l=(a=(r=D.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=B(e))==null?void 0:i.version)!=null?l:"";ce(e,{status:"uninstalling",progress:0,version:o}),await Ao(e),Tt(e),D.setState(c=>{let s={...c.downloads};return delete s[e],{downloads:s}}),delete Pe[e],Pt.delete(e),Ct(e,null),_e("uninstalled",e,t?"(user)":"(not in list)"),Ie({type:"uninstalled",app_id:e})},zo=e=>$o(e,{by_user:!0}),Wo=e=>{let t=Ge(e);return t?(Fe.delete(e),(O==null?void 0:O.app_id)===e||Z.includes(e)||(Pe[e]=0,ce(e,{status:be.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),It(e),Le(),_e("restore",e)),!0):!1},jo=e=>{if(be.has(e))return;if(be.add(e),_e("pause app",e),(O==null?void 0:O.app_id)===e&&!O.forced){O.handle.cancel();return}let t=D.getState().downloads[e];Z.includes(e)&&t&&ce(e,{status:"paused",progress:0,version:t.version})},Ho=e=>{if(!be.delete(e))return;_e("resume app",e);let t=D.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!Z.includes(e)&&Ge(e)&&(Pe[e]=0,It(e)),Z.includes(e)&&t&&ce(e,{status:"queued",progress:0,version:t.version}),Le()},Jo=e=>{let{pause_reasons:t}=D.getState();t.includes(e)||(D.setState({pause_reasons:[...t,e]}),_e("pause",e),t.length===0&&Ie({type:"pause_change",paused:!0,reasons:[e]}),O&&!O.forced&&O.handle.cancel())},Go=e=>{let{pause_reasons:t}=D.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);D.setState({pause_reasons:n}),_e("resume",e),n.length===0&&Ie({type:"pause_change",paused:!1,reasons:n}),Le()},pn=e=>D.getState().updates[e],Ko=async e=>{var n,o;let t=pn(e);Ot.add(e);try{let r=await lt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=Ge(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(D.setState(a=>{var c;let l={...a.updates};return delete l[e],{updates:l,apply_ticks:{...a.apply_ticks,[e]:((c=a.apply_ticks[e])!=null?c:0)+1}}}),_e("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Ot.delete(e)}},Yo=()=>Object.values(D.getState().catalog).map(e=>({...e,installed:!!B(e.app_id),removed_by_user:Fe.has(e.app_id)})),Ge=e=>D.getState().catalog[e],lt=async e=>{let t=Ge(e);if(!t)return;if(be.delete(e),Fe.delete(e),await on(t))return B(e);let n=B(e);if(No(e)&&!Ot.has(e)&&n&&await Te(n))return n;let o=new Promise(r=>{var i;((i=ze[e])!=null?i:ze[e]=[]).push(r)});return(O==null?void 0:O.app_id)===e?O.forced=!0:(Pe[e]=0,It(e,{front:!0}),O&&!O.forced?O.handle.cancel():Le(e)),o};var k=require("react/jsx-runtime"),un=e=>(e!=null?e:"").replace(/\?[^#]*/,""),Xo=0,ti=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},ni=A.default.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:l,opaque_background:c,allow_embedded_miniapps:s,onWebLoadEnd:d})=>{var pt,Ke;let m=(0,A.useRef)(null),h=(0,A.useRef)(!1),p=j(ae,f=>f.instances[e]),y=p==null?void 0:p.app.app_id,C=p==null?void 0:p.app.manifest_url,R=p==null?void 0:p.context,T=p==null?void 0:p.url_params,M=j(X,f=>{var u;return((u=f.active)==null?void 0:u.owner)===e?f.active:null}),[b,K]=(0,A.useState)(()=>y?B(y):null),[te,re]=(0,A.useState)(!1),[Ae,w]=(0,A.useState)(0),[x,J]=(0,A.useState)(0),[P,F]=(0,A.useState)(!1),N=(0,A.useRef)(null),z=f=>{N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{N.current=null,F(!0)},f)};(0,A.useEffect)(()=>()=>{N.current&&clearTimeout(N.current)},[]),(0,A.useEffect)(()=>{if(!y||!t&&b)return;let f=!0;return re(!1),(async()=>{let u=B(y),I=u?await Te(u):!1;if(!f||(K(I?we=>!we||we.version!==u.version||we.permissions.join(",")!==u.permissions.join(",")?u:we:null),__DEV__&&Date.now()-Xo>1e4&&(Xo=Date.now(),await Lt()),!f))return;let oe=await lt(y),le=oe!==void 0?oe:C?await Mo(y,C):B(y);if(f){if(!le){re(!0);return}K(we=>we!=null?we:le)}})(),()=>{f=!1}},[t,y,C,Ae]),(0,A.useEffect)(()=>xo(e,f=>m.current?(m.current.postMessage(f),!0):!1),[e]);let U=j(D,f=>{let u=y?f.downloads[y]:void 0;return(u==null?void 0:u.status)==="installed"?u.version:void 0});(0,A.useEffect)(()=>{if(t||!y||!b)return;let f=B(y);if(!f||f.version===b.version)return;let u=!0;return Te(f).then(I=>{!u||!I||(ue(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",b.version,"\u2192",f.version),K(f))}),()=>{u=!1}},[t,y,U,b==null?void 0:b.version]);let ne=j(D,f=>{var u;return y&&(u=f.apply_ticks[y])!=null?u:0});(0,A.useEffect)(()=>{if(!ne||!y)return;let f=B(y);if(!f||f.version===(b==null?void 0:b.version))return;let u=!0;return Te(f).then(I=>{!u||!I||(ue(`webview:${e}`,"c\u1EADp nh\u1EADt",b==null?void 0:b.version,"\u2192",f.version),F(!1),K(f))}),()=>{u=!1}},[ne]),(0,A.useEffect)(()=>{var I;let f=(I=q().keep_alive)==null?void 0:I.idle_close_ms;if(t||!f||f<=0)return;let u=setTimeout(()=>{Tt(e)},f);return()=>clearTimeout(u)},[t,e]),(0,A.useEffect)(()=>{r>0&&(re(!1),F(!1),J(f=>f+1),w(f=>f+1))},[r]);let De=(0,A.useRef)(t);(0,A.useEffect)(()=>{var f;De.current!==t&&(De.current=t,h.current&&((f=m.current)==null||f.injectJavaScript(po(t?"resumed":"paused"))))},[t]);let ye=`${(pt=b==null?void 0:b.version)!=null?pt:"none"}:${(Ke=b==null?void 0:b.permissions.join(","))!=null?Ke:""}:${x}`,ie=(0,A.useMemo)(()=>JSON.stringify([R!=null?R:{},T!=null?T:{}]),[R,T]),Ne=(0,A.useMemo)(()=>{var f;return ho(T!=null?T:{},(f=b==null?void 0:b.permissions)!=null?f:[])},[ie,b==null?void 0:b.permissions]),xe=(0,A.useMemo)(()=>mo(R!=null?R:{},Ne)+co()+lo()+(q().debug?ao():""),[Ne]),Ee=(0,A.useRef)(null),Re=(0,A.useRef)(null);(0,A.useEffect)(()=>{var u,I,oe;if(!b)return;if(Re.current!==ye){Re.current=ye,Ee.current=ie;return}if(Ee.current===ie)return;let f=((I=JSON.parse((u=Ee.current)!=null?u:"[]")[0])!=null?I:{}).org_id;if(Ee.current=ie,f===(R==null?void 0:R.org_id)&&h.current){F(!1),z(1500),(oe=m.current)==null||oe.injectJavaScript(uo(R!=null?R:{},Ne));return}F(!1),J(le=>le+1)},[ie,b,ye]),(0,A.useEffect)(()=>(t||(ve(e),ke(e),Ve(e)),()=>{ve(e),ke(e),Ve(e)}),[t,e,ye,r]),(0,A.useEffect)(()=>{let f=L.AppState.addEventListener("change",u=>{u==="background"&&!zn()&&ve(e),u==="background"&&!Kn()&&ke(e)});return()=>f.remove()},[e]);let Ft=(0,A.useCallback)(async f=>{var I,oe,le,we,Nt,gn;let u=oo(f.nativeEvent.data);if(!u){if(y&&(l!=null&&l.onWebEvent))try{Promise.resolve(l.onWebEvent(f.nativeEvent.data,{app_id:y,instance_id:e})).catch(W=>{console.warn("[miniapp] onWebEvent l\u1ED7i",y,W)})}catch(W){console.warn("[miniapp] onWebEvent l\u1ED7i",y,W)}return}if(u.method==="log"){let{level:W,text:G}=u;ue(`web:${e}`,W!=null?W:"log",G!=null?G:"");return}if(u.method==="pong"){N.current||F(!0);return}if(u.method==="touchAtTop"){i.emit(!!u.at_top);return}if(u.method==="contextApplied"){N.current&&clearTimeout(N.current),N.current=null,F(!0);return}if(u.method==="ready"){h.current=!0,F(!0);let W=(I=ae.getState().instances[e])==null?void 0:I.context;W&&((oe=m.current)==null||oe.injectJavaScript(Xt(W)));return}try{let W=await wo(u,{getHostData:()=>{var G,pe;return(pe=(G=ae.getState().instances[e])==null?void 0:G.host_data)!=null?pe:{}},getPermissions:()=>{var G,pe;return y?(pe=(G=B(y))==null?void 0:G.permissions)!=null?pe:[]:[]},getContext:()=>{var G,pe;return(pe=(G=ae.getState().instances[e])==null?void 0:G.context)!=null?pe:{}},is_dark:o,close:Je,app_id:y!=null?y:"",instance_id:e,options:l,emit:(G,pe)=>{var mn;(mn=m.current)==null||mn.injectJavaScript(so(G,pe))},playBeep:(le=l==null?void 0:l.playScannerBeep)!=null?le:(()=>{var G;(G=m.current)==null||G.injectJavaScript(yo())}),isActive:()=>ae.getState().active_key===e&&L.AppState.currentState!=="background"});u.id&&((we=m.current)==null||we.injectJavaScript(ro(u.id,W)))}catch(W){if(!u.id)return;let G=W==null?void 0:W.code,pe=W instanceof g?W:new g(typeof G=="string"?G:"HOST_ERROR",String((Nt=W==null?void 0:W.message)!=null?Nt:W));(gn=m.current)==null||gn.injectJavaScript(io(u.id,pe))}},[e,o,y,i,l]),Dt=(0,A.useCallback)(()=>{re(!1),J(f=>f+1),w(f=>f+1)},[]);return(0,k.jsxs)(L.View,{style:[L.StyleSheet.absoluteFill,c&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&he.behind],pointerEvents:t?"auto":"none",children:[(M==null?void 0:M.layout)===Me.top&&(0,k.jsx)(an,{scanner:M}),b?(0,k.jsx)(Qo.default,{ref:m,source:{uri:b.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?en():b.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:xe,onMessage:Ft,bounces:!1,overScrollMode:"never",onLoadStart:f=>{ve(e),ke(e),Ve(e),ue(`webview:${e}`,"load start",un(f.nativeEvent.url)),h.current=!1,F(!1)},onError:f=>{ve(e),ke(e),Ve(e),ue(`webview:${e}`,"load error",un(f.nativeEvent.url),f.nativeEvent.description),re(!0),F(!1)},onLoadEnd:f=>{let u=f.nativeEvent.url;ue(`webview:${e}`,"load end",un(u)),y&&(d==null||d({app_id:y,instance_id:e,url:u})),z(1500)},onContentProcessDidTerminate:()=>{ve(e),ke(e),Ve(e),h.current=!1,F(!1),J(f=>f+1)},onRenderProcessGone:()=>(ve(e),ke(e),Ve(e),h.current=!1,F(!1),J(f=>f+1),!0),style:he.webview},ye):null,(M==null?void 0:M.layout)===Me.full&&(0,k.jsx)(an,{scanner:M}),p&&(0,k.jsx)(ri,{visible:!b||!P,interactive:te,children:(0,k.jsx)(oi,{splash:a,app:p.app,is_dark:o,error:te,has_bundle:!!b,retry:Dt})})]})}),oi=A.default.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,l=kt(t.app_id),c=o?"error":!r&&(l==null?void 0:l.status)==="downloading"?"downloading":"loading";return(0,k.jsx)(a,{app:t,is_dark:n,status:c,progress:c==="downloading"?l==null?void 0:l.progress:void 0,retry:i})}),ri=({visible:e,interactive:t,children:n})=>{let o=(0,A.useRef)(new L.Animated.Value(e?1:0)).current,[r,i]=(0,A.useState)(e);return(0,A.useEffect)(()=>{if(e){i(!0),o.setValue(1);return}let a=L.Animated.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:l})=>{l&&i(!1)}),()=>a.stop()},[e,o]),r?(0,k.jsx)(L.Animated.View,{style:[L.StyleSheet.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},dn=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return(0,k.jsxs)(L.View,{style:[he.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,k.jsx)(L.View,{style:[he.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,k.jsx)(L.Image,{source:{uri:e.icon},style:he.splash_icon_image}):(0,k.jsx)(L.Text,{style:he.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,k.jsx)(L.Text,{style:[he.splash_name,{color:i}],children:e.name}),n==="error"?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(L.Text,{style:he.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,k.jsx)(L.TouchableOpacity,{activeOpacity:.7,style:[he.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:(0,k.jsx)(L.Text,{style:[he.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(L.ActivityIndicator,{style:he.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,k.jsxs)(L.Text,{style:he.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},Zo=(e,t)=>{let n=(0,A.useRef)(t),o=(0,A.useRef)(!1);__DEV__&&!o.current&&n.current!==t&&(o.current=!0,console.warn(`[miniapp] MiniAppHost prop "${e}" \u0111\u1ED5i gi\u1EEFa c\xE1c l\u1EA7n render \u2192 m\u1ECDi WebView b\u1ECB mount l\u1EA1i. Khai b\xE1o component b\xEAn ngo\xE0i render.`))},ii=({container:e,splash:t=dn,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:l})=>{Zo("container",e),Zo("splash",t);let c=e,s=j(ae,M=>M.active_key),d=(0,A.useRef)(s);s&&(d.current=s);let m=j(ae,M=>Object.keys(M.instances).join("|")),h=j(ae,M=>{var b;return M.active_key?(b=M.instances[M.active_key])==null?void 0:b.app.name:void 0}),p=(0,A.useMemo)(()=>m?m.split("|"):[],[m]),[y,C]=(0,A.useState)({}),R=(0,A.useRef)(ti()).current;(0,A.useEffect)(()=>{if(!s||!r)return;let M=L.BackHandler.addEventListener("hardwareBackPress",()=>(Je(),!0));return()=>M.remove()},[s,r]);let T=(0,A.useCallback)(()=>{let M=ae.getState().active_key;M&&C(b=>({...b,[M]:(b[M]||0)+1}))},[]);return p.length?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(c,{visible:!!s,title:h!=null?h:"",is_dark:n,close:Je,reload:T,subscribeWebAtTop:R.subscribe,children:p.map(M=>(0,k.jsx)(ni,{instance_key:M,is_active:s===M,is_front:(s!=null?s:d.current)===M,is_dark:n,reload_tick:y[M]||0,web_at_top:R,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:l},M))}),(0,k.jsx)(ko,{})]}):null},he=L.StyleSheet.create({webview:{flex:1,backgroundColor:"transparent"},behind:{zIndex:-1},splash:{flex:1,alignItems:"center",justifyContent:"center",gap:12},splash_icon:{width:72,height:72,borderRadius:20,alignItems:"center",justifyContent:"center",overflow:"hidden"},splash_icon_image:{width:72,height:72},splash_letter:{fontSize:28,fontWeight:"700",color:"#1D4ED8"},splash_name:{fontSize:16,fontWeight:"600"},splash_hint:{color:"#71717A"},splash_spinner:{marginTop:8},retry_button:{marginTop:4,paddingHorizontal:20,paddingVertical:10,borderRadius:999},retry_text:{fontWeight:"600"}}),er=A.default.memo(ii);0&&(module.exports={CodeType,DefaultMiniAppSplash,MINIAPP_PLATFORM_URL,MiniAppHost,MiniAppHostError,ScannerEndReason,ScannerEvent,ScannerLayout,ScannerMethod,ToastType,closeMiniApp,configureMiniApp,createMmkvStorage,createReactNativeBiometrics,createRnfsFileSystem,ensureMiniApp,getLocalMiniApp,getMiniAppCatalog,getMiniAppCatalogEntry,getMiniAppStatuses,getMiniAppUpdate,installBundledMiniApp,onMiniAppEvent,openMiniApp,pauseMiniApp,pauseMiniAppDownloads,preloadMiniApp,releaseSpeechFor,restoreMiniApp,resumeMiniApp,resumeMiniAppDownloads,sendEventToWeb,syncMiniAppCatalog,uninstallMiniApp,updateMiniApp,uploadToUrl,useMiniAppDownload,useMiniAppDownloadsPaused});
|
|
88
|
+
})(); true;`,zr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Pt=(e,t)=>{if(typeof e!="string"||!e)throw new m("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},Ro=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:c,instance_id:l,options:s,emit:g,isActive:d,playBeep:y})=>{var E,M,N,z,ne,Pe,ae;let u=s==null?void 0:s.handlers,w={app_id:c,instance_id:l,close:a},I=()=>{var p;(p=s==null?void 0:s.haptic)==null||p.call(s,"impactLight"),y==null||y()},P=()=>new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let p=Pn(t);return it(e,()=>Tn(p,d))}case"speech.start":{if(!g)throw P();let p={};if((t==null?void 0:t.lang)!==void 0){if(typeof t.lang!="string"||!/^[a-zA-Z]{2,8}(-[a-zA-Z0-9]{1,8})*$/.test(t.lang))throw new m("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");p.lang=t.lang}for(let q of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[q])!==void 0){if(typeof t[q]!="boolean")throw new m("INVALID_PARAMS",`${q} ph\u1EA3i l\xE0 boolean`);p[q]=t[q]}let x=s==null?void 0:s.speech;if(x){Yn(l,x);try{return await x.start({owner:l,app_id:c,options:p,emit:g,isActive:d!=null?d:(()=>!0)})}catch(q){throw Xn(l),q}}return Qn(l,p,g,d)}case"speech.stop":return s!=null&&s.speech?s.speech.stop(l):eo(l);case He.scan:return ao(l,Xt(t),d,I);case He.start:{if(!g)throw P();return co(l,Xt(t),g,d,I)}case He.stop:return lo(l);case"uploadFiles":{let{task_id:p,...x}=t!=null?t:{};if(p!==void 0&&(typeof p!="string"||!p))throw new m("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return Hn(Nn(x),{instance_id:l,app_id:c,getContext:r,task_id:p,config:s==null?void 0:s.upload,emit:g,exclusivePick:q=>it("uploadFiles.pick",q)})}case"uploadFiles.cancel":jn(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return zn(s==null?void 0:s.upload);case"getBiometricAvailability":return((E=s==null?void 0:s.biometrics)!=null?E:await jt()).getAvailability();case"authenticateBiometric":{let p=Pt(t==null?void 0:t.reason,"reason").trim();if(!p||p.length>200)throw new m("INVALID_PARAMS","reason must contain 1\u2013200 characters");let x=t==null?void 0:t.cancelButtonText;if(x!==void 0&&(typeof x!="string"||!x.trim()||x.length>80))throw new m("INVALID_PARAMS","Invalid cancelButtonText");return it(e,async()=>{var T;return((T=s==null?void 0:s.biometrics)!=null?T:await jt()).authenticate({reason:p,cancelButtonText:x})})}case"requestPayment":{let p=u==null?void 0:u.requestPayment;if(!p)throw P();let x=t==null?void 0:t.amount;if(typeof x!="number"||!Number.isFinite(x)||x<=0)throw new m("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let q={...t,amount:x,currency:Pt(t==null?void 0:t.currency,"currency")};return it(e,()=>p(q,w))}case"printImage":{let p=u==null?void 0:u.printImage;if(!p)throw P();let x=Pt(t==null?void 0:t.image,"image");await it(e,()=>p({image:x},w));return}case"openScreen":if(!(u!=null&&u.openScreen))throw P();await u.openScreen({screen:Pt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},w);return;case"closeApp":a();return;case"openWebview":{let p=String((M=t==null?void 0:t.url)!=null?M:"");if(!/^https?:\/\//i.test(p))throw new m("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(p):st.Linking.openURL(p));return}case"openLink":{let p=String((N=t==null?void 0:t.url)!=null?N:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(p)||/^(javascript|file|data|about|blob):/i.test(p))throw new m("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(p):st.Linking.openURL(p))}catch(x){throw new m("NOT_SUPPORTED",String((ne=(z=x==null?void 0:x.message)!=null?z:x)!=null?ne:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let p=Gn(t);if(!p||(d==null?void 0:d())===!1)return;s!=null&&s.showToast?s.showToast(p.message,{type:p.type}):Kn(p.message,p.type);return}case"haptic":{let p=zr.has(t==null?void 0:t.type)?t.type:"selection";(Pe=s==null?void 0:s.haptic)==null||Pe.call(s,p);return}case"getSystemInfo":return{platform:st.Platform.OS==="ios"?"ios":"android",appVersion:(ae=s==null?void 0:s.app_version)!=null?ae:"",theme:i?"dark":"light"};case"getAccessToken":{let p=n().access_token;if(!p)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return p}case"getToken":{let p=t==null?void 0:t.type;if(p==="access"){let T=n().access_token;if(!T)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return T}if(p!=="partner"&&p!=="chatbox")throw new m("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(p)}`);let x=Mo[p];if(!o().includes(x))throw new m("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${x} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let q=p==="partner"?n().partner_token:n().chatbox_token;if(!q)throw new m("HOST_ERROR",`Kh\xF4ng c\xF3 ${x}`);return q}case"getUserInfo":{let p=n().user;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return p}case"getPageInfo":{let p=n().page;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return p}case"sendMessage":case"insertText":throw new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new m("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var an=e=>`bundle:${e}`,cn=()=>`${$().file_system.document_dir}/miniapps`,ln=cn,pn=(e,t,n="index.html",o=!1,r=[])=>{let i=`${ln()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},sn=e=>{var t;$().storage.setString(an(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},Wr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,B=e=>{let t=$().storage.getString(an(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return pn(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Ce=e=>$().file_system.exists(e.entry_uri.replace("file://","")),un=async e=>{let t=B(e.app_id);return(t==null?void 0:t.version)===e.version&&await Ce(t)},To=async(e,t)=>{let n=$().file_system,o=`${ln()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},Co=async e=>{var t;await((t=lt[e])==null?void 0:t.catch(()=>{})),$().storage.setString(an(e),""),await $().file_system.remove(`${ln()}/${e}`).catch(()=>{})},Je=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},lt={},Oo=(e,t)=>{var i;let o=((i=lt[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return lt[e]=r,r.then(()=>{lt[e]===r&&delete lt[e]}),o},jr=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let c=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(c)return c}return 0},ko=({manifest:e,zip_path:t})=>Oo(e.app_id,async()=>{var i;let n=$().file_system,o=B(e.app_id);if(o&&jr(o.version,e.version)>=0&&await Ce(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=pn(e.app_id,e.version,e.entry,!!e.context_update,(i=e.permissions)!=null?i:[]);return await n.remove(r.dir).catch(()=>{}),await n.mkdir(r.dir),await n.unzip(t,r.dir),sn(e),me("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),To(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),dn=(e,{base_url:t,onProgress:n}={})=>{let o=$().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,c=()=>{if(i)throw new Je},l=async()=>{var d;c();let s=B(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return sn(e),B(e.app_id);c();let g=o.download({url:t?Wr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(y,u)=>{var I;let w=u>0?u:(I=e.size)!=null?I:0;w>0&&(n==null||n(Math.min(1,y/w)))}});r=g;try{let{status:y}=await g.promise;if(c(),y!==200)throw new Error(`bundle ${y}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else me("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let u=pn(e.app_id,e.version,e.entry,!!e.context_update,(d=e.permissions)!=null?d:[]);return await o.remove(u.dir).catch(()=>{}),await o.mkdir(u.dir),await o.unzip(a,u.dir),sn(e),To(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),u}catch(y){throw i?new Je:y}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:Oo(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},ct={},Hr=__DEV__?0:60*1e3,Po={},Io=(e,t)=>{var o,r;let n=B(e);return n&&Date.now()-((o=Po[t])!=null?o:0)<Hr?Promise.resolve(n):((r=ct[e])!=null||(ct[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),c=await dn(a,{base_url:t}).promise;return Po[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),B(e))).finally(()=>{ct[e]=void 0})),ct[e])};var Ct=new Map,Lo=(e,t)=>(Ct.set(e,t),()=>{Ct.get(e)===t&&Ct.delete(e)}),Fo=(e,t)=>{let n=Ct.get(e);return n?n(t):!1};var F=require("react"),h=require("react-native");var v=require("react/jsx-runtime"),pt="#22C55E",Jr="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",Gr=2,kt=18,Kr=1600,ut=14,Yr=2e3,Uo=.38,Xr=40,Do=2,Zr=8,Qr=2e3,ei=250,Ge=2e3,ti=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:ut},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:ut},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:ut},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:ut}],No=({color:e})=>(0,v.jsx)(v.Fragment,{children:ti.map((t,n)=>(0,v.jsx)(h.View,{style:[S.corner,t,{borderColor:e}]},n))}),Ot=({style:e,children:t,...n})=>{let o=(0,F.useRef)(new h.Animated.Value(1)).current,r=i=>h.Animated.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return(0,v.jsx)(h.Pressable,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:(0,v.jsx)(h.Animated.View,{style:[e,{transform:[{scale:o}]}],children:t})})},mn=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var f,_;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:g}=e,d=c===pe.top,y=(0,F.useRef)(new h.Animated.Value(0)).current,u=r.useCameraDevice("back"),w=(0,F.useRef)(new h.Animated.Value(1)).current,[I,P]=(0,F.useState)(!1),[E,M]=(0,F.useState)(1),N=(0,F.useRef)(null),[z,ne]=(0,F.useState)(()=>{let{width:b,height:U}=h.Dimensions.get("window");return{width:b,height:d?U*Uo:U,window_y:0}}),Pe=j(X,b=>b.last_value),ae=j(X,b=>b.hit_tick),p=j(X,b=>b.scan_count),x=j(X,b=>b.notice),q=j(X,b=>b.is_picking),T=(0,F.useRef)(null),ce=Et(),_e=ce.top,K=(0,F.useRef)(new h.Animated.Value(0)).current,O=(0,F.useRef)(new h.Animated.Value(0)).current,oe=(0,F.useRef)(new h.Animated.Value(0)).current,J=(0,F.useRef)(n);J.current=n,(0,F.useEffect)(()=>{if(!t)return;y.setValue(z.height);let b=h.Animated.timing(y,{toValue:0,duration:ei,easing:h.Easing.out(h.Easing.cubic),useNativeDriver:!1});return b.start(({finished:U})=>{var ie;U&&((ie=J.current)==null||ie.call(J))}),()=>b.stop()},[t,y]);let Q=Math.round(z.width*(d?.8:.78)),re=Math.round(d?z.height*.46:Q*.78),ve=Math.round((z.height-re)/2),Me=Math.round((z.width-Q)/2),je=r.useCodeScanner({codeTypes:i,onCodeScanned:(0,F.useCallback)(b=>tn(b),[])});(0,F.useEffect)(()=>{let b=h.BackHandler.addEventListener("hardwareBackPress",()=>(en(),!0));return()=>b.remove()},[]);let xe=(0,F.useRef)(ae);(0,F.useEffect)(()=>{if(ae===xe.current)return;K.setValue(1),oe.setValue(1);let b=h.Animated.parallel([h.Animated.timing(K,{toValue:0,duration:450,useNativeDriver:!0}),h.Animated.sequence([h.Animated.delay(Yr),h.Animated.timing(oe,{toValue:0,duration:250,useNativeDriver:!0})])]);return b.start(),()=>b.stop()},[ae,K,oe]),(0,F.useEffect)(()=>{let b=ie=>h.Animated.timing(O,{toValue:ie,duration:Kr,easing:h.Easing.inOut(h.Easing.quad),useNativeDriver:!0}),U=h.Animated.loop(h.Animated.sequence([b(1),b(0)]));return U.start(),()=>U.stop()},[O]);let Te=(0,F.useCallback)(()=>{h.Animated.timing(w,{toValue:0,duration:220,useNativeDriver:!0}).start()},[w]);(0,F.useEffect)(()=>{let b=setTimeout(Te,Qr);return()=>clearTimeout(b)},[Te]);let[Xe,qt]=(0,F.useState)(!1);(0,F.useEffect)(()=>{let b=requestAnimationFrame(()=>{b=requestAnimationFrame(()=>qt(!0))});return()=>cancelAnimationFrame(b)},[]);let Ve=!!(u!=null&&u.hasTorch),Ze=(f=u==null?void 0:u.neutralZoom)!=null?f:1,Qe=u?Math.min(u.maxZoom/Ze,Zr):1,$t=Ze*Math.min(E,Qe),mt=b=>{var se;let{touches:U}=b.nativeEvent;if(U.length!==2){N.current=null;return}let ie=Math.hypot(U[0].pageX-U[1].pageX,U[0].pageY-U[1].pageY);(se=N.current)!=null||(N.current={distance:ie,level:E}),M(Math.max(1,Math.min(Qe,N.current.level*(ie/N.current.distance))))},ft=(0,v.jsx)(h.Text,{style:[S.hint,!!x&&S.hint_notice],numberOfLines:1,children:(_=x!=null?x:l)!=null?_:Jr});return(0,v.jsx)(h.Animated.View,{ref:T,onTouchMove:mt,onTouchEnd:()=>{N.current=null},pointerEvents:t?"none":"auto",style:d?[S.top,g&&S.top_absolute,t&&{height:y}]:S.full,onLayout:({nativeEvent:{layout:b}})=>{var U;t||(o==null||o(b.height),(U=T.current)==null||U.measureInWindow((ie,se)=>{ne({width:b.width,height:b.height,window_y:se||0})}))},children:(0,v.jsxs)(h.View,{style:t?[S.content_closing,{height:z.height}]:S.content,children:[u&&Xe&&(0,v.jsx)(r.Camera,{style:h.StyleSheet.absoluteFill,device:u,isActive:!q,codeScanner:je,torch:I&&Ve?"on":"off",zoom:$t,onPreviewStarted:Te,onError:b=>po(b.message)}),(0,v.jsx)(h.Animated.View,{style:[S.preview_cover,{opacity:w}],pointerEvents:"none"}),z.height>0&&(0,v.jsxs)(h.View,{style:S.overlay,pointerEvents:"none",children:[(0,v.jsx)(h.View,{style:[S.dim_ring,{top:ve-Ge,left:Me-Ge,width:Q+Ge*2,height:re+Ge*2}]}),(0,v.jsxs)(h.View,{style:{position:"absolute",top:ve,left:Me,width:Q,height:re},children:[(0,v.jsx)(No,{color:"#FFFFFF"}),(0,v.jsx)(h.Animated.View,{style:[h.StyleSheet.absoluteFill,{opacity:K}],children:(0,v.jsx)(No,{color:pt})}),(0,v.jsxs)(h.Animated.View,{style:[S.scan_line_wrap,{transform:[{translateY:O.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,re-kt)]})}]}],children:[(0,v.jsx)(h.View,{style:S.scan_glow_outer}),(0,v.jsx)(h.View,{style:S.scan_glow_inner}),(0,v.jsx)(h.View,{style:S.scan_line})]})]}),(0,v.jsx)(h.View,{style:[S.hint_slot,d?{top:0,height:ve-6,justifyContent:"flex-end"}:{top:ve+re+20}],children:ft}),a===Le.continuous&&!!Pe&&(0,v.jsx)(h.Animated.View,{style:[S.result_slot,{top:d?ve+re-Xr:ve+re+52},{opacity:oe}],children:(0,v.jsxs)(h.View,{style:S.result,children:[(0,v.jsx)(h.View,{style:S.check_badge,children:(0,v.jsx)(h.View,{style:S.check_mark})}),(0,v.jsx)(h.Text,{style:S.result_text,numberOfLines:1,children:Pe}),(0,v.jsxs)(h.Text,{style:S.result_count,children:["\xB7 ",p," m\xE3"]})]})})]}),z.height>0&&(0,v.jsx)(h.View,{style:[S.close_slot,d?S.close_slot_top:{top:Math.max(12,_e-z.window_y+12)}],children:(0,v.jsxs)(Ot,{style:[S.close_button,!!s&&S.glass_surface],onPress:en,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[s&&(0,v.jsx)(s,{style:S.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(h.View,{style:[S.close_bar,S.close_bar_a]}),(0,v.jsx)(h.View,{style:[S.close_bar,S.close_bar_b]})]})}),(0,v.jsx)(h.View,{style:[S.toolbar_wrap,!d&&{bottom:ce.bottom+20}],pointerEvents:"box-none",children:(0,v.jsxs)(h.View,{style:[S.toolbar,!!s&&S.glass_surface],children:[s&&(0,v.jsx)(s,{style:S.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(Ot,{style:S.tool,onPress:uo,disabled:q,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:(0,v.jsxs)(h.View,{style:S.image_icon,children:[(0,v.jsx)(h.View,{style:S.image_icon_dot}),(0,v.jsx)(h.View,{style:S.image_icon_hill})]})}),!!u&&Qe>=Do&&(0,v.jsx)(Ot,{style:[S.tool,E>1&&S.tool_on],onPress:()=>M(b=>b>1?1:Do),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:(0,v.jsxs)(h.Text,{style:[S.zoom_text,E>1&&S.zoom_text_on],children:[Math.round(E*10)/10,"x"]})}),Ve&&(0,v.jsx)(Ot,{style:[S.tool,I&&S.tool_on],onPress:()=>P(b=>!b),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:I},children:(0,v.jsx)(h.Text,{style:[S.torch_icon,I&&S.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},ni="rgba(0,0,0,0.5)",gn=50,S=h.StyleSheet.create({top:{height:`${Uo*100}%`,overflow:"hidden",backgroundColor:"#000000"},full:{position:"absolute",top:0,left:0,right:0,bottom:0},content:{flex:1,backgroundColor:"#000000"},top_absolute:{position:"absolute",top:0,left:0,right:0,zIndex:1},content_closing:{position:"absolute",left:0,right:0,bottom:0,backgroundColor:"#000000"},preview_cover:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"#000000"},overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,overflow:"hidden"},dim_ring:{position:"absolute",borderWidth:Ge,borderColor:ni,borderRadius:Ge+ut},hint_slot:{position:"absolute",left:16,right:16,alignItems:"center"},hint:{color:"#FFFFFF",fontSize:14,fontWeight:"500"},hint_notice:{color:"#FCA5A5"},corner:{position:"absolute",width:28,height:28},scan_line_wrap:{position:"absolute",top:0,left:10,right:10,height:kt,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:kt,borderRadius:kt/2,backgroundColor:pt,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:pt,opacity:.2},scan_line:{height:Gr,borderRadius:1,backgroundColor:pt},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_slot_top:{bottom:15},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:gn,height:gn,borderRadius:gn/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result:{maxWidth:"100%",flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:12,paddingVertical:6,borderRadius:999,backgroundColor:"rgba(39,39,42,0.9)"},check_badge:{width:18,height:18,borderRadius:9,alignItems:"center",justifyContent:"center",backgroundColor:pt},check_mark:{width:5,height:9,marginTop:-2,borderRightWidth:2,borderBottomWidth:2,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_text:{flexShrink:1,color:"#FFFFFF",fontWeight:"600",fontSize:13},result_count:{color:"#A1A1AA",fontSize:13}});var we=require("react"),R=require("react-native");var H=require("react/jsx-runtime"),fn={[fe.info]:"#3B82F6",[fe.success]:"#22C55E",[fe.error]:"#EF4444"},Vo=-120,It=R.Platform.OS==="android",Bo=({type:e})=>e===fe.success?(0,H.jsx)(R.View,{style:te.check_mark}):e===fe.error?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(R.View,{style:[te.cross_bar,te.cross_a]}),(0,H.jsx)(R.View,{style:[te.cross_bar,te.cross_b]})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(R.View,{style:te.info_dot}),(0,H.jsx)(R.View,{style:te.info_bar})]}),qo=()=>{let e=j(rt,y=>y.message),t=j(rt,y=>y.type),n=j(rt,y=>y.tick),o=(0,we.useRef)(new R.Animated.Value(Vo)).current,r=(0,we.useRef)(new R.Animated.Value(0)).current,i=(0,we.useRef)(new R.Animated.Value(.92)).current,a=(0,we.useRef)(new R.Animated.Value(0)).current,[c,l]=(0,we.useState)(),[s,g]=(0,we.useState)(!1);(0,we.useEffect)(()=>{let y=!0;return Qt().then(u=>{y&&u&&l(()=>u)}),()=>{y=!1}},[]);let d=(0,we.useRef)(n);return(0,we.useEffect)(()=>{if(n===d.current)return;R.AccessibilityInfo.announceForAccessibility(e),g(!0),a.setValue(0),i.setValue(.92);let y=R.Animated.sequence([R.Animated.parallel([R.Animated.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),R.Animated.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),R.Animated.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),R.Animated.sequence([R.Animated.delay(90),R.Animated.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),R.Animated.delay(Jn[t]),R.Animated.parallel([R.Animated.timing(o,{toValue:Vo,duration:240,useNativeDriver:!0}),R.Animated.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return y.start(({finished:u})=>{u&&g(!1)}),()=>y.stop()},[n]),s?(0,H.jsx)(R.View,{style:[te.layer,{top:Et().top+(It?12:8)}],pointerEvents:"none",children:(0,H.jsxs)(R.Animated.View,{style:[te.toast,It&&te.toast_android,!!c&&te.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&(0,H.jsx)(c,{style:te.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),It?(0,H.jsx)(R.Animated.View,{style:[te.badge_halo,{backgroundColor:`${fn[t]}33`,transform:[{scale:a}]}],children:(0,H.jsx)(R.View,{style:[te.badge,{backgroundColor:fn[t]}],children:(0,H.jsx)(Bo,{type:t})})}):(0,H.jsx)(R.Animated.View,{style:[te.badge,{backgroundColor:fn[t],transform:[{scale:a}]}],children:(0,H.jsx)(Bo,{type:t})}),(0,H.jsx)(R.Text,{style:[te.message,It&&te.message_android],numberOfLines:2,children:e})]})}):null},te=R.StyleSheet.create({layer:{position:"absolute",left:16,right:16,alignItems:"center",zIndex:9999,elevation:9999},toast:{maxWidth:"100%",minHeight:50,flexDirection:"row",alignItems:"center",gap:10,paddingLeft:11,paddingRight:18,paddingVertical:11,borderRadius:25,backgroundColor:"#18181B",shadowColor:"#000000",shadowOpacity:.32,shadowRadius:18,shadowOffset:{width:0,height:8},elevation:12},toast_android:{width:"100%",minHeight:60,gap:12,paddingLeft:10,paddingRight:16,paddingVertical:10,borderRadius:20,borderWidth:R.StyleSheet.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ue=Ie({active_key:null,instances:{}}),$o=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=$().keep_alive)==null?void 0:c.max_webviews;ue.setState(l=>{let s=t!=null?t:e.app_id,g={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},d=Object.keys(g);return a&&a>0&&d.length>a&&d.filter(y=>y!==s).sort((y,u)=>g[y].last_used_at-g[u].last_used_at).slice(0,d.length-a).forEach(y=>{delete g[y]}),i?{active_key:s,instances:g}:{instances:g}})},zo=e=>$o(e,!0),Wo=e=>$o(e,!1),Ke=()=>ue.setState({active_key:null}),Lt=e=>{ue.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var jo="catalog",oi="paused_apps",ri="removed_apps",ii=10*1e3,si=2,ai=3e3,ci=()=>{var e;try{return JSON.parse((e=$().storage.getString(jo))!=null?e:"{}")}catch{return{}}},D=Ie({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),Ho=e=>{var t;return!!((t=$().manual_update)!=null&&t.includes(e))},Nt=new Set,Jo=e=>{let t=new Set,n=()=>$().storage.setString(e,JSON.stringify([...t]));return{has:o=>t.has(o),values:()=>[...t],add:o=>t.has(o)?!1:(t.add(o),n(),!0),delete:o=>t.delete(o)?(n(),!0):!1,load:()=>{var o;t.clear();try{let r=JSON.parse((o=$().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},Se=Jo(oi),Ue=Jo(ri);xn(()=>{Se.load(),Ue.load();let e=ci(),t={};Object.keys(e).filter(n=>!Ue.has(n)).forEach(n=>{let o=B(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:Se.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),D.setState({catalog:e,downloads:t})});var Ut=e=>j(D,t=>e?t.downloads[e]:void 0),Go=()=>j(D,e=>e.pause_reasons.length>0),Ae=(...e)=>me("queue",...e),Z=[],Oe={},C=null,Ft=new Set,We={},hn=new Set,De=e=>{hn.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Ko=e=>(hn.add(e),()=>{hn.delete(e)}),Yo=()=>D.getState().downloads,de=(e,t)=>{let n=!!B(e),o=D.getState().downloads[e],r=t.status==="downloading"&&n?"updating":t.status,i={...o!=null?o:{status:"queued",progress:0},...t,...r?{status:r}:{},has_local:n};D.setState(a=>({downloads:{...a.downloads,[e]:i}})),(o==null?void 0:o.status)!==i.status||(o==null?void 0:o.version)!==i.version||(o==null?void 0:o.has_local)!==i.has_local?De({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&De({type:"progress",app_id:e,progress:i.progress,version:i.version})},Dt=(e,t)=>{var n;(n=We[e])==null||n.forEach(o=>o(t)),delete We[e]},li=()=>D.getState().pause_reasons.length>0,Ne=e=>{var c;if(C)return;let t=e?Z.indexOf(e):li()?-1:Z.findIndex(l=>!Se.has(l));if(t<0||t>=Z.length)return;let[n]=Z.splice(t,1),o=D.getState().catalog[n];if(!o){Dt(n,B(n)),Ne();return}let r=Date.now();Oe[n]=((c=Oe[n])!=null?c:0)+1,de(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=dn(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,de(n,{progress:s/100,version:o.version}))}});C={app_id:n,handle:a,forced:!!e},Ae("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{Ae("installed",n,o.version,`${Date.now()-r}ms`),de(n,{status:"installed",progress:1,version:o.version}),Dt(n,l)}).catch(l=>{var g;if(l instanceof Je){if(Ft.has(n))return;Ae("paused",n),Oe[n]-=1,Z.unshift(n),de(n,{status:Se.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((g=l==null?void 0:l.message)!=null?g:l);if(console.warn("[miniapp-queue] failed",n,s),Oe[n]<si){de(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var d;Z.includes(n)||(C==null?void 0:C.app_id)===n||(Z.push(n),Ne((d=We[n])!=null&&d.length?n:void 0))},ai);return}de(n,{status:"failed",progress:0,version:o.version,error:s}),Dt(n,B(n))}).finally(()=>{C=null;let l=Z.find(s=>{var g;return(g=We[s])==null?void 0:g.length});Ne(l)})},Vt=(e,{front:t=!1}={})=>{if((C==null?void 0:C.app_id)===e)return;let n=Z.indexOf(e);if(n>=0){if(!t)return;Z.splice(n,1)}t?Z.unshift(e):Z.push(e)},pi=async e=>{let{host_id:t,client_token:n}=$(),o=new AbortController,r=setTimeout(()=>o.abort(),ii);try{let i=`${yt}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(l=>({...l,channel:e}))}finally{clearTimeout(r)}},dt=null,Bt=()=>(dt!=null||(dt=(async()=>{var t;let e=Date.now();try{let n=await Promise.all($().channels.map(pi)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(D.getState().catalog).filter(l=>!o[l]);$().storage.setString(jo,JSON.stringify(o)),D.setState({catalog:o}),await Promise.all(r.map(l=>Xo(l,{by_user:!1}))),r.forEach(l=>Ue.delete(l));let i=Object.keys(o).filter(l=>!Ue.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await un(l)){de(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=B(l.app_id);if(Ho(l.app_id)&&!Nt.has(l.app_id)&&s&&await Ce(s)){de(l.app_id,{status:"installed",progress:1,version:s.version}),c[l.app_id]={app_id:l.app_id,current_version:s.version,next_version:l.version};continue}a.push(l)}return D.setState({updates:c}),a.forEach(l=>{Oe[l.app_id]=0,de(l.app_id,{status:Se.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),Vt(l.app_id)}),Ae("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),De({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>De({type:"update_available",...l})),Ne(),{ok:!0,app_ids:i,removed:r}}catch(n){let o=String((n==null?void 0:n.name)==="AbortError"?"timeout":(t=n==null?void 0:n.message)!=null?t:n);return console.warn("[miniapp-queue] sync catalog failed",o),De({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{dt=null}})()),dt),Xo=async(e,{by_user:t})=>{var r,i,a,c;if(t&&Ue.add(e),Ft.has(e))return;Ft.add(e),Se.delete(e);let n=Z.indexOf(e);n>=0&&Z.splice(n,1),(C==null?void 0:C.app_id)===e&&C.handle.cancel();let o=(c=(a=(r=D.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=B(e))==null?void 0:i.version)!=null?c:"";de(e,{status:"uninstalling",progress:0,version:o}),await Co(e),Lt(e),D.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Oe[e],Ft.delete(e),Dt(e,null),Ae("uninstalled",e,t?"(user)":"(not in list)"),De({type:"uninstalled",app_id:e})},Zo=e=>Xo(e,{by_user:!0}),Qo=e=>{let t=Ye(e);return t?(Ue.delete(e),(C==null?void 0:C.app_id)===e||Z.includes(e)||(Oe[e]=0,de(e,{status:Se.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Vt(e),Ne(),Ae("restore",e)),!0):!1},er=e=>{if(Se.has(e))return;if(Se.add(e),Ae("pause app",e),(C==null?void 0:C.app_id)===e&&!C.forced){C.handle.cancel();return}let t=D.getState().downloads[e];Z.includes(e)&&t&&de(e,{status:"paused",progress:0,version:t.version})},tr=e=>{if(!Se.delete(e))return;Ae("resume app",e);let t=D.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!Z.includes(e)&&Ye(e)&&(Oe[e]=0,Vt(e)),Z.includes(e)&&t&&de(e,{status:"queued",progress:0,version:t.version}),Ne()},nr=e=>{let{pause_reasons:t}=D.getState();t.includes(e)||(D.setState({pause_reasons:[...t,e]}),Ae("pause",e),t.length===0&&De({type:"pause_change",paused:!0,reasons:[e]}),C&&!C.forced&&C.handle.cancel())},or=e=>{let{pause_reasons:t}=D.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);D.setState({pause_reasons:n}),Ae("resume",e),n.length===0&&De({type:"pause_change",paused:!1,reasons:n}),Ne()},yn=e=>D.getState().updates[e],rr=async e=>{var n,o;let t=yn(e);Nt.add(e);try{let r=await gt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=Ye(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(D.setState(a=>{var l;let c={...a.updates};return delete c[e],{updates:c,apply_ticks:{...a.apply_ticks,[e]:((l=a.apply_ticks[e])!=null?l:0)+1}}}),Ae("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Nt.delete(e)}},ir=()=>Object.values(D.getState().catalog).map(e=>({...e,installed:!!B(e.app_id),removed_by_user:Ue.has(e.app_id)})),Ye=e=>D.getState().catalog[e],gt=async e=>{let t=Ye(e);if(!t)return;if(Se.delete(e),Ue.delete(e),await un(t))return B(e);let n=B(e);if(Ho(e)&&!Nt.has(e)&&n&&await Ce(n))return n;let o=new Promise(r=>{var i;((i=We[e])!=null?i:We[e]=[]).push(r)});return(C==null?void 0:C.app_id)===e?C.forced=!0:(Oe[e]=0,Vt(e,{front:!0}),C&&!C.forced?C.handle.cancel():Ne(e)),o};var k=require("react/jsx-runtime"),wn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),sr=0,ui=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},di=A.default.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:g})=>{var mt,ft;let d=(0,A.useRef)(null),y=(0,A.useRef)(!1),u=j(ue,f=>f.instances[e]),w=u==null?void 0:u.app.app_id,I=u==null?void 0:u.app.manifest_url,P=u==null?void 0:u.context,E=u==null?void 0:u.url_params,M=j(X,f=>{var _;return((_=f.active)==null?void 0:_.owner)===e?f.active:null}),[N,z]=(0,A.useState)(null),[ne,Pe]=(0,A.useState)(M);M!==ne&&(Pe(M),M?z(null):(ne==null?void 0:ne.layout)===pe.top&&z(ne));let ae=(M==null?void 0:M.layout)===pe.top?M:N,[p,x]=(0,A.useState)(()=>w?B(w):null),[q,T]=(0,A.useState)(!1),[ce,_e]=(0,A.useState)(0),[K,O]=(0,A.useState)(0),[oe,J]=(0,A.useState)(!1),Q=(0,A.useRef)(null),re=f=>{Q.current&&clearTimeout(Q.current),Q.current=setTimeout(()=>{Q.current=null,J(!0)},f)};(0,A.useEffect)(()=>()=>{Q.current&&clearTimeout(Q.current)},[]),(0,A.useEffect)(()=>{if(!w||!t&&p)return;let f=!0;return T(!1),(async()=>{let _=B(w),b=_?await Ce(_):!1;if(!f||(x(b?se=>!se||se.version!==_.version||se.permissions.join(",")!==_.permissions.join(",")?_:se:null),__DEV__&&Date.now()-sr>1e4&&(sr=Date.now(),await Bt()),!f))return;let U=await gt(w),ie=U!==void 0?U:I?await Io(w,I):B(w);if(f){if(!ie){T(!0);return}x(se=>se!=null?se:ie)}})(),()=>{f=!1}},[t,w,I,ce]),(0,A.useEffect)(()=>Lo(e,f=>d.current?(d.current.postMessage(f),!0):!1),[e]);let ve=j(D,f=>{let _=w?f.downloads[w]:void 0;return(_==null?void 0:_.status)==="installed"?_.version:void 0});(0,A.useEffect)(()=>{if(t||!w||!p)return;let f=B(w);if(!f||f.version===p.version)return;let _=!0;return Ce(f).then(b=>{!_||!b||(me(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",p.version,"\u2192",f.version),x(f))}),()=>{_=!1}},[t,w,ve,p==null?void 0:p.version]);let Me=j(D,f=>{var _;return w&&(_=f.apply_ticks[w])!=null?_:0});(0,A.useEffect)(()=>{if(!Me||!w)return;let f=B(w);if(!f||f.version===(p==null?void 0:p.version))return;let _=!0;return Ce(f).then(b=>{!_||!b||(me(`webview:${e}`,"c\u1EADp nh\u1EADt",p==null?void 0:p.version,"\u2192",f.version),J(!1),x(f))}),()=>{_=!1}},[Me]),(0,A.useEffect)(()=>{var b;let f=(b=$().keep_alive)==null?void 0:b.idle_close_ms;if(t||!f||f<=0)return;let _=setTimeout(()=>{Lt(e)},f);return()=>clearTimeout(_)},[t,e]),(0,A.useEffect)(()=>{r>0&&(T(!1),J(!1),O(f=>f+1),_e(f=>f+1))},[r]);let je=(0,A.useRef)(t);(0,A.useEffect)(()=>{var f;je.current!==t&&(je.current=t,y.current&&((f=d.current)==null||f.injectJavaScript(_o(t?"resumed":"paused"))))},[t]);let xe=`${(mt=p==null?void 0:p.version)!=null?mt:"none"}:${(ft=p==null?void 0:p.permissions.join(","))!=null?ft:""}:${K}`,Te=(0,A.useMemo)(()=>JSON.stringify([P!=null?P:{},E!=null?E:{}]),[P,E]),Xe=(0,A.useMemo)(()=>{var f;return xo(E!=null?E:{},(f=p==null?void 0:p.permissions)!=null?f:[])},[Te,p==null?void 0:p.permissions]),qt=(0,A.useMemo)(()=>vo(P!=null?P:{},Xe)+wo()+bo()+($().debug?yo():""),[Xe]),Ve=(0,A.useRef)(null),Ze=(0,A.useRef)(null);(0,A.useEffect)(()=>{var _,b,U;if(!p)return;if(Ze.current!==xe){Ze.current=xe,Ve.current=Te;return}if(Ve.current===Te)return;let f=((b=JSON.parse((_=Ve.current)!=null?_:"[]")[0])!=null?b:{}).org_id;if(Ve.current=Te,f===(P==null?void 0:P.org_id)&&y.current){J(!1),re(1500),(U=d.current)==null||U.injectJavaScript(Ao(P!=null?P:{},Xe));return}J(!1),O(ie=>ie+1)},[Te,p,xe]),(0,A.useEffect)(()=>(t||(Re(e),Fe(e),qe(e)),()=>{Re(e),Fe(e),qe(e)}),[t,e,xe,r]),(0,A.useEffect)(()=>{let f=L.AppState.addEventListener("change",_=>{_==="background"&&!Zn()&&Re(e),_==="background"&&!ro()&&Fe(e)});return()=>f.remove()},[e]);let Qe=(0,A.useCallback)(async f=>{var b,U,ie,se,zt,_n;let _=go(f.nativeEvent.data);if(!_){if(w&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(f.nativeEvent.data,{app_id:w,instance_id:e})).catch(W=>{console.warn("[miniapp] onWebEvent l\u1ED7i",w,W)})}catch(W){console.warn("[miniapp] onWebEvent l\u1ED7i",w,W)}return}if(_.method==="log"){let{level:W,text:G}=_;me(`web:${e}`,W!=null?W:"log",G!=null?G:"");return}if(_.method==="pong"){Q.current||J(!0);return}if(_.method==="touchAtTop"){i.emit(!!_.at_top);return}if(_.method==="contextApplied"){Q.current&&clearTimeout(Q.current),Q.current=null,J(!0);return}if(_.method==="ready"){y.current=!0,J(!0);let W=(b=ue.getState().instances[e])==null?void 0:b.context;W&&((U=d.current)==null||U.injectJavaScript(on(W)));return}try{let W=await Ro(_,{getHostData:()=>{var G,ge;return(ge=(G=ue.getState().instances[e])==null?void 0:G.host_data)!=null?ge:{}},getPermissions:()=>{var G,ge;return w?(ge=(G=B(w))==null?void 0:G.permissions)!=null?ge:[]:[]},getContext:()=>{var G,ge;return(ge=(G=ue.getState().instances[e])==null?void 0:G.context)!=null?ge:{}},is_dark:o,close:Ke,app_id:w!=null?w:"",instance_id:e,options:c,emit:(G,ge)=>{var An;(An=d.current)==null||An.injectJavaScript(ho(G,ge))},playBeep:(ie=c==null?void 0:c.playScannerBeep)!=null?ie:(()=>{var G;(G=d.current)==null||G.injectJavaScript(Eo())}),isActive:()=>ue.getState().active_key===e&&L.AppState.currentState!=="background"});_.id&&((se=d.current)==null||se.injectJavaScript(mo(_.id,W)))}catch(W){if(!_.id)return;let G=W==null?void 0:W.code,ge=W instanceof m?W:new m(typeof G=="string"?G:"HOST_ERROR",String((zt=W==null?void 0:W.message)!=null?zt:W));(_n=d.current)==null||_n.injectJavaScript(fo(_.id,ge))}},[e,o,w,i,c]),$t=(0,A.useCallback)(()=>{T(!1),O(f=>f+1),_e(f=>f+1)},[]);return(0,k.jsxs)(L.View,{style:[L.StyleSheet.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&be.behind],pointerEvents:t?"auto":"none",children:[ae&&(0,k.jsx)(mn,{scanner:ae,closing:ae===N,onClosed:()=>{var f;z(null),ae.absolute&&((f=d.current)==null||f.injectJavaScript(rn(0)))},onHeight:ae.absolute?f=>{var _;return(_=d.current)==null?void 0:_.injectJavaScript(rn(f))}:void 0}),p?(0,k.jsx)(cr.default,{ref:d,source:{uri:p.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?cn():p.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:qt,onMessage:Qe,bounces:!1,overScrollMode:"never",onLoadStart:f=>{Re(e),Fe(e),qe(e),me(`webview:${e}`,"load start",wn(f.nativeEvent.url)),y.current=!1,J(!1)},onError:f=>{Re(e),Fe(e),qe(e),me(`webview:${e}`,"load error",wn(f.nativeEvent.url),f.nativeEvent.description),T(!0),J(!1)},onLoadEnd:f=>{let _=f.nativeEvent.url;me(`webview:${e}`,"load end",wn(_)),w&&(g==null||g({app_id:w,instance_id:e,url:_})),re(1500)},onContentProcessDidTerminate:()=>{Re(e),Fe(e),qe(e),y.current=!1,J(!1),O(f=>f+1)},onRenderProcessGone:()=>(Re(e),Fe(e),qe(e),y.current=!1,J(!1),O(f=>f+1),!0),style:be.webview},xe):null,(M==null?void 0:M.layout)===pe.full&&(0,k.jsx)(mn,{scanner:M}),u&&(0,k.jsx)(mi,{visible:!p||!oe,interactive:q,children:(0,k.jsx)(gi,{splash:a,app:u.app,is_dark:o,error:q,has_bundle:!!p,retry:$t})})]})}),gi=A.default.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=Ut(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return(0,k.jsx)(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),mi=({visible:e,interactive:t,children:n})=>{let o=(0,A.useRef)(new L.Animated.Value(e?1:0)).current,[r,i]=(0,A.useState)(e);return(0,A.useEffect)(()=>{if(e){i(!0),o.setValue(1);return}let a=L.Animated.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?(0,k.jsx)(L.Animated.View,{style:[L.StyleSheet.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},bn=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return(0,k.jsxs)(L.View,{style:[be.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,k.jsx)(L.View,{style:[be.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,k.jsx)(L.Image,{source:{uri:e.icon},style:be.splash_icon_image}):(0,k.jsx)(L.Text,{style:be.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,k.jsx)(L.Text,{style:[be.splash_name,{color:i}],children:e.name}),n==="error"?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(L.Text,{style:be.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,k.jsx)(L.TouchableOpacity,{activeOpacity:.7,style:[be.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:(0,k.jsx)(L.Text,{style:[be.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(L.ActivityIndicator,{style:be.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,k.jsxs)(L.Text,{style:be.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},ar=(e,t)=>{let n=(0,A.useRef)(t),o=(0,A.useRef)(!1);__DEV__&&!o.current&&n.current!==t&&(o.current=!0,console.warn(`[miniapp] MiniAppHost prop "${e}" \u0111\u1ED5i gi\u1EEFa c\xE1c l\u1EA7n render \u2192 m\u1ECDi WebView b\u1ECB mount l\u1EA1i. Khai b\xE1o component b\xEAn ngo\xE0i render.`))},fi=({container:e,splash:t=bn,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{ar("container",e),ar("splash",t);let l=e,s=j(ue,M=>M.active_key),g=(0,A.useRef)(s);s&&(g.current=s);let d=j(ue,M=>Object.keys(M.instances).join("|")),y=j(ue,M=>{var N;return M.active_key?(N=M.instances[M.active_key])==null?void 0:N.app.name:void 0}),u=(0,A.useMemo)(()=>d?d.split("|"):[],[d]),[w,I]=(0,A.useState)({}),P=(0,A.useRef)(ui()).current;(0,A.useEffect)(()=>{if(!s||!r)return;let M=L.BackHandler.addEventListener("hardwareBackPress",()=>(Ke(),!0));return()=>M.remove()},[s,r]);let E=(0,A.useCallback)(()=>{let M=ue.getState().active_key;M&&I(N=>({...N,[M]:(N[M]||0)+1}))},[]);return u.length?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(l,{visible:!!s,title:y!=null?y:"",is_dark:n,close:Ke,reload:E,subscribeWebAtTop:P.subscribe,children:u.map(M=>(0,k.jsx)(di,{instance_key:M,is_active:s===M,is_front:(s!=null?s:g.current)===M,is_dark:n,reload_tick:w[M]||0,web_at_top:P,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},M))}),(0,k.jsx)(qo,{})]}):null},be=L.StyleSheet.create({webview:{flex:1,backgroundColor:"transparent"},behind:{zIndex:-1},splash:{flex:1,alignItems:"center",justifyContent:"center",gap:12},splash_icon:{width:72,height:72,borderRadius:20,alignItems:"center",justifyContent:"center",overflow:"hidden"},splash_icon_image:{width:72,height:72},splash_letter:{fontSize:28,fontWeight:"700",color:"#1D4ED8"},splash_name:{fontSize:16,fontWeight:"600"},splash_hint:{color:"#71717A"},splash_spinner:{marginTop:8},retry_button:{marginTop:4,paddingHorizontal:20,paddingVertical:10,borderRadius:999},retry_text:{fontWeight:"600"}}),lr=A.default.memo(fi);0&&(module.exports={CodeType,DefaultMiniAppSplash,MINIAPP_PLATFORM_URL,MiniAppHost,MiniAppHostError,ScannerEndReason,ScannerEvent,ScannerLayout,ScannerMethod,ToastType,closeMiniApp,configureMiniApp,createMmkvStorage,createReactNativeBiometrics,createRnfsFileSystem,ensureMiniApp,getLocalMiniApp,getMiniAppCatalog,getMiniAppCatalogEntry,getMiniAppStatuses,getMiniAppUpdate,installBundledMiniApp,onMiniAppEvent,openMiniApp,pauseMiniApp,pauseMiniAppDownloads,preloadMiniApp,releaseSpeechFor,restoreMiniApp,resumeMiniApp,resumeMiniAppDownloads,sendEventToWeb,syncMiniAppCatalog,uninstallMiniApp,updateMiniApp,uploadToUrl,useMiniAppDownload,useMiniAppDownloadsPaused});
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Vt="https://retion-miniapp-platform.vercel.app",De=null,Mn=new Set,or=e=>{De=e,Mn.forEach(t=>t())},D=()=>{if(!De)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return De},xn=e=>{Mn.add(e),De&&e()},le=(...e)=>{De!=null&&De.debug&&console.log("[miniapp]",...e)};var rr=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:l,contentLength:c})=>r==null?void 0:r(l,c)});return{promise:a.then(({statusCode:l})=>({status:l})),cancel:()=>e.stopDownload(i)}}}),ir=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});import bn,{useCallback as yn,useEffect as se,useMemo as Ft,useRef as ye,useState as $e}from"react";import{AppState as Qo,ActivityIndicator as Ti,Animated as fn,BackHandler as Pi,Image as Ci,StyleSheet as An,Text as gt,TouchableOpacity as Oi,View as wn}from"react-native";import ki from"react-native-webview";import{Linking as go,Platform as Ur}from"react-native";var En=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),ft,Bt=()=>(ft||(ft=import("react-native-biometrics").then(({default:e})=>En(new e({allowDeviceCredentials:!1}))).catch(e=>{throw ft=void 0,new g("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),ft);import{PermissionsAndroid as Ne,Platform as sr}from"react-native";var Rn=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new g("INVALID_PARAMS","Tu\u1EF3 ch\u1ECDn v\u1ECB tr\xED ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.enableHighAccuracy!==void 0&&typeof t.enableHighAccuracy!="boolean")throw new g("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,l]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let c=t[i];if(c!==void 0&&(typeof c!="number"||!Number.isFinite(c)||c<a||c>l))throw new g("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${l} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Tn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(c,s)=>{r||(r=!0,clearTimeout(a),c?o(c):n(s))},a=setTimeout(()=>i(new g("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),l=()=>r?!1:t()?!0:(i(new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!l())return;let c;try{c=(await import("@react-native-community/geolocation")).default}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(l()){if(sr.OS==="android"){let s=Ne.PERMISSIONS.ACCESS_FINE_LOCATION,d=Ne.PERMISSIONS.ACCESS_COARSE_LOCATION,m=await Ne.check(s);if(!l())return;let h=m||await Ne.check(d);if(!l())return;if(!m&&!h){let p=await Ne.requestMultiple([s,d]);if(!l())return;if(p[s]!==Ne.RESULTS.GRANTED&&p[d]!==Ne.RESULTS.GRANTED)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}l()&&c.getCurrentPosition(s=>{l()&&i(void 0,s)},s=>{var m;if(!l())return;let d=(m={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?m:"LOCATION_ERROR";i(new g(d,s.message))},e)}})().catch(c=>i(c))});import{Platform as Fn}from"react-native";var qt=20,Pn=20,Dn=/^[a-z][a-z0-9_-]{0,31}$/,ar=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,cr=["low","medium","high"],Re=e=>!!e&&typeof e=="object"&&!Array.isArray(e),j=e=>new g("INVALID_PARAMS",e),Xe=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Cn=(e,t)=>{if(e===void 0)return{};if(!Re(e)||Object.keys(e).length>Pn||Object.values(e).some(n=>typeof n!="string"))throw j(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Pn} key)`);return e},Nn=e=>{var n,o,r,i;if(e!==void 0&&!Re(e))throw j("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!Dn.test(t.source)))throw j("source ph\u1EA3i l\xE0 t\xEAn ngu\u1ED3n, vd library | camera | document");if(t.accept!==void 0&&(!Array.isArray(t.accept)||t.accept.length>50||t.accept.some(a=>typeof a!="string"||!ar.test(a))))throw j("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!Xe(t.max_count,1,qt))throw j(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${qt}`);if(t.max_size!==void 0&&!Xe(t.max_size,1,Number.MAX_SAFE_INTEGER))throw j("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!Xe(t.concurrency,1,5))throw j("concurrency ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u20135");return{source:(n=t.source)!=null?n:"library",accept:((o=t.accept)!=null?o:[]).map(a=>a.toLowerCase()),max_count:(r=t.max_count)!=null?r:1,max_size:t.max_size,process:lr(t.process),target:pr(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},lr=e=>{if(e===void 0)return{};if(!Re(e))throw j("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Re(n))throw j("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!Xe(n[o],1,1e4))throw j(`process.image.${o} ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u201310000`);if(n.quality!==void 0&&(typeof n.quality!="number"||n.quality<=0||n.quality>1))throw j("process.image.quality ph\u1EA3i trong kho\u1EA3ng (0, 1]");t.image={max_width:n.max_width,max_height:n.max_height,quality:n.quality}}if(e.video!==void 0){let n=e.video;if(!Re(n))throw j("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!Xe(n.max_duration,1,3600))throw j("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!cr.includes(n.quality))throw j("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},pr=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Re(e))throw j("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!Dn.test(t))throw j("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!Re(e.params))throw j("upload.params ph\u1EA3i l\xE0 object");return{target:t,params:(o=e.params)!=null?o:{}}}if(typeof e.url!="string"||!/^https:\/\//i.test(e.url))throw j("upload.url ph\u1EA3i l\xE0 https");for(let a of["field_name","url_field"])if(e[a]!==void 0&&(typeof e[a]!="string"||!e[a]))throw j(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:Cn(e.headers,"upload.headers"),form_data:Cn(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},Un=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},ur=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=Un(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},dr=e=>{let t=e.length>0&&e.every(o=>o.startsWith("image/")),n=e.length>0&&e.every(o=>o.startsWith("video/"));return t?"image":n?"video":"mixed"},Ge,gr=()=>(Ge!=null||(Ge=import("react-native-image-picker").catch(e=>{throw Ge=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),Ge),On=e=>async({accept:t,max_count:n,process:o})=>{var c,s,d,m,h,p,y,E,v;let r=await gr(),i=dr(t),a={mediaType:i==="image"?"photo":i,maxWidth:(c=o.image)==null?void 0:c.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(m=(d=o.image)==null?void 0:d.quality)!=null?m:.8,videoQuality:(p=(h=o.video)==null?void 0:h.quality)!=null?p:"medium",durationLimit:(y=o.video)==null?void 0:y.max_duration,assetRepresentationMode:"compatible"},l=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(l.didCancel)return[];if(l.errorCode){let M=l.errorCode==="permission"?"PERMISSION_DENIED":l.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new g(M,(E=l.errorMessage)!=null?E:l.errorCode)}return((v=l.assets)!=null?v:[]).filter(M=>M.uri).map((M,A)=>{var _,W,Z;return{uri:M.uri,name:(_=M.fileName)!=null?_:`file_${A+1}`,mime_type:(W=M.type)!=null?W:"application/octet-stream",size:M.fileSize,width:M.width,height:M.height,duration:M.duration,processed:!((Z=M.type)!=null&&Z.startsWith("video/"))||Fn.OS==="ios"}})},mr={"image/*":"images","video/*":"video","audio/*":"audio","text/plain":"plainText","text/csv":"csv","application/pdf":"pdf","application/json":"json","application/zip":"zip","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx"},fr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},hr=e=>async({accept:t,max_count:n})=>{var i,a,l,c;let o=t.map(s=>{var d;return(d=mr[s])!=null?d:fr[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let d=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(p=>p.uri&&!p.error).map((p,y)=>{var E,v,M;return{uri:p.uri,name:(E=p.name)!=null?E:`file_${y+1}`,mime_type:(v=p.type)!=null?v:"application/octet-stream",size:(M=p.size)!=null?M:void 0}});if(Fn.OS!=="android"||!e.keepLocalCopy||!d.some(p=>p.uri.startsWith("content://")))return d;let m=await e.keepLocalCopy({files:d.map(p=>({uri:p.uri,fileName:p.name})),destination:"cachesDirectory"}),h=new Map(m.map(p=>[p.sourceUri,p.status==="success"?p.localUri:void 0]));return d.map(p=>{var y;return{...p,uri:(y=h.get(p.uri))!=null?y:p.uri}})}catch(s){let d=s==null?void 0:s.code;if(d===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw d===((c=(l=e.errorCodes)==null?void 0:l.IN_PROGRESS)!=null?c:"ASYNC_OP_IN_PROGRESS")?new g("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},Ke,yr=async e=>(Ke!=null||(Ke=import("@react-native-documents/picker").then(t=>hr(t)).catch(t=>{throw Ke=void 0,new g("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await Ke)(e)),Vn={library:On("library"),camera:On("camera"),document:yr},kn={type:"image",label:"\u1EA2nh",accept:["image/*"]},In={type:"video",label:"Video",accept:["video/*"]},Ln={library:[kn,In],camera:[kn,In],document:[{type:"any",label:"M\u1ECDi file",accept:[]},{type:"pdf",label:"PDF",accept:["application/pdf"]},{type:"word",label:"Word",accept:[".doc",".docx"]},{type:"excel",label:"Excel",accept:[".xls",".xlsx"]},{type:"powerpoint",label:"PowerPoint",accept:[".ppt",".pptx"]}]},Ye,Bn=()=>(Ye!=null||(Ye=import("react-native-compressor").catch(()=>(Ye=void 0,null))),Ye),qn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},wr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),_r={low:640,medium:1280,high:1920},br=async(e,{image:t})=>{var o;if(!t||!wr.has(e.mime_type.toLowerCase()))return e;let n=await Bn();if(!n)return e;try{let r=await n.Image.compress(e.uri,{compressionMethod:"manual",maxWidth:t.max_width,maxHeight:t.max_height,quality:(o=t.quality)!=null?o:.8,output:"jpg"});return{...e,uri:r,mime_type:"image/jpeg",name:e.name.replace(/\.[^.]+$/,"")+".jpg",size:await qn(n,r,e.size),processed:!0}}catch{return e}},Ar=async(e,{video:t})=>{var o;let n=await Bn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:_r[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await qn(n,r,e.size),processed:!0}}catch{return e}},Sr={image:br,video:Ar},vr=(e,t)=>t.split(".").reduce((n,o)=>Re(n)?n[o]:void 0,e),$n=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new g("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let l=new XMLHttpRequest,c=new FormData;Object.entries(a.form_data).forEach(([m,h])=>c.append(m,h)),c.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>l.abort();o.addEventListener("abort",s);let d=m=>{o.removeEventListener("abort",s),m()};l.open("POST",a.url),Object.entries(a.headers).forEach(([m,h])=>l.setRequestHeader(m,h)),l.upload.onprogress=m=>n(m.loaded,m.total||e.size||0),l.onload=()=>d(()=>{let m=l.responseText;try{m=JSON.parse(l.responseText)}catch{}if(l.status<200||l.status>=300){i(new g("UPLOAD_FAILED",`HTTP ${l.status}`));return}let h=vr(m,a.url_field);if(typeof h!="string"||!h){i(new g("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:h,response:m})}),l.onerror=()=>d(()=>i(new g("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),l.onabort=()=>d(()=>i(new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),l.send(c)}),zn=e=>{var o,r;let t={...Vn};for(let[i,a]of Object.entries((o=e==null?void 0:e.sources)!=null?o:{}))a?t[i]=a:delete t[i];let n={url:$n};for(let[i,a]of Object.entries((r=e==null?void 0:e.targets)!=null?r:{}))i!=="url"&&a&&(n[i]=a);return{sources:t,targets:n}},Wn=e=>{let{sources:t,targets:n}=zn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===Vn[i]&&Ln[i]).map(i=>[i,Ln[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:qt}},yt=new Map,jn=(e,t)=>`${e}:${t}`,Mr=0,Hn=(e,t)=>{var n;typeof t=="string"&&((n=yt.get(jn(e,t)))==null||n.abort())},Ue=e=>{for(let[t,n]of yt)t.startsWith(`${e}:`)&&n.abort()},ht=()=>new g("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),xr=(e,t)=>{var n;return{name:e,code:typeof(t==null?void 0:t.code)=="string"?t.code:"UPLOAD_FAILED",message:String((n=t==null?void 0:t.message)!=null?n:t)}},Jn=async(e,t)=>{var c;let{sources:n,targets:o}=zn(t.config),r=n[e.source];if(!r)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=o[e.target.target];if(!i)throw new g("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,l=jn(t.instance_id,(c=t.task_id)!=null?c:`auto-${++Mr}`);yt.set(l,a);try{return await Er(e,t,r,i,a.signal)}finally{yt.delete(l)}},Er=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:l=m=>m()},c,s,d)=>{var w,S,q;let m={app_id:n!=null?n:"",instance_id:t,context:{...(w=o==null?void 0:o())!=null?w:{}}},h=(await l(()=>c({accept:e.accept,max_count:e.max_count,process:e.process,caller:m}))).slice(0,e.max_count);if(d.aborted)throw ht();if(!h.length)throw new g("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let p=[],y=h.filter(x=>ur(x,e.accept)?!0:(p.push({name:x.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${x.mime_type||Un(x.name)}`}),!1)),E=y.map(()=>0),v=y.map(x=>{var C;return(C=x.size)!=null?C:0}),M=0,A=0,_=(x=!1)=>{if(!a||!r)return;let C=Date.now();if(!x&&C-A<200)return;A=C;let k=v.reduce((I,Q)=>I+Q,0),N=E.reduce((I,Q)=>I+Q,0);a("upload.progress",{task_id:r,loaded:N,total:k,percent:k?Math.min(100,Math.round(N/k*100)):0,done_count:M,count:y.length})},W=[],Z=0,te=async()=>{var x,C,k;for(;Z<y.length;){let N=Z++,I=y[N];try{if(d.aborted)throw ht();let Q=I.mime_type.startsWith("image/")?"image":I.mime_type.startsWith("video/")?"video":void 0,Le=Q&&!I.processed?(C=(x=i==null?void 0:i.processors)==null?void 0:x[Q])!=null?C:Sr[Q]:void 0;if(Le&&(I=await Le(I,e.process),v[N]=(k=I.size)!=null?k:v[N],d.aborted))throw ht();if(e.max_size&&I.size&&I.size>e.max_size)throw new g("FILE_TOO_LARGE",`File ${I.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let de=(Ae,Se)=>{E[N]=Ae,Se&&(v[N]=Se),_()},ne=await s({file:I,target:e.target,onProgress:de,signal:d,caller:m});if(typeof(ne==null?void 0:ne.url)!="string"||!ne.url)throw new g("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:Fe,...be}=ne;W[N]={url:Fe,name:I.name,mime_type:I.mime_type,size:I.size,width:I.width,height:I.height,duration:I.duration,...Object.keys(be).length?{response:"response"in be?be.response:be}:{}},E[N]=v[N]}catch(Q){p.push(xr(y[N].name,Q))}finally{M++,_(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,y.length)},te)),d.aborted)throw ht();let we=W.filter(x=>!!x);if(!we.length){let x=p[0];throw new g((S=x==null?void 0:x.code)!=null?S:"UPLOAD_FAILED",(q=x==null?void 0:x.message)!=null?q:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:we,failed:p}};import{useRef as Rr,useSyncExternalStore as Tr}from"react";var Te=e=>{let t=e,n=new Set;return{getState:()=>t,setState:o=>{let r=typeof o=="function"?o(t):o;t={...t,...r},n.forEach(i=>i())},subscribe:o=>(n.add(o),()=>{n.delete(o)})}},V=(e,t,n=Object.is)=>{let o=Rr(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let l=t(i),c=a&&n(a.value,l)?a.value:l;return o.current={state:i,selector:t,value:c},c};return Tr(e.subscribe,r)};var me={info:"info",success:"success",error:"error"},Pr=200,Gn={info:2e3,success:2e3,error:3e3},Ze=Te({message:"",type:me.info,tick:0}),Kn=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Pr);return o?{message:o,type:Object.values(me).includes(n)?n:me.info}:null},Yn=(e,t=me.info)=>{Ze.setState(n=>({message:e,type:t,tick:n.tick+1}))};import{Alert as Or,Linking as kr,Platform as Qe,StatusBar as Ir}from"react-native";import{AppState as Xn,Platform as zt}from"react-native";var pe,Zn=()=>zt.OS==="android"&&!!(pe!=null&&pe.requesting_permission),Cr=1500,wt=()=>new Promise(e=>{if(zt.OS!=="android"||Xn.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Cr),o=Xn.addEventListener("change",r=>{r==="active"&&t()})}),$t=e=>{var t;if(pe===e&&(pe=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&zt.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Qn=async(e,t,n,o=()=>!0)=>{var i,a,l,c,s;if(pe)throw new g("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};pe=r;try{let d;try{d=await import("expo-speech-recognition")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let m=d.ExpoSpeechRecognitionModule;if(r.native=m,r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let h;try{h=await m.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await wt(),r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!h.granted)throw new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await m.getStateAsync()!=="inactive")throw new g("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(m.addListener("result",p=>{var y,E;pe!==r||r.cancelled||n(p.isFinal?"speech.final":"speech.partial",{...p,text:(E=(y=p.results[0])==null?void 0:y.transcript)!=null?E:""})}),m.addListener("error",p=>{pe===r&&!r.cancelled&&n("speech.error",{...p,code:p.error})}),m.addListener("end",()=>{pe===r&&($t(r),n("speech.end"))})),r.started=!0,m.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(l=t.interimResults)!=null?l:!0,addsPunctuation:(c=t.addsPunctuation)!=null?c:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:d.AVAudioSessionCategory.playAndRecord,categoryOptions:[d.AVAudioSessionCategoryOptions.defaultToSpeaker,d.AVAudioSessionCategoryOptions.allowBluetooth],mode:d.AVAudioSessionMode.measurement}})}catch(d){throw $t(r),d}},eo=e=>{let t=pe;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},ve=e=>{let t=pe;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{$t(t)}};var to={qr:"qr",ean13:"ean-13",ean8:"ean-8",upcA:"upc-a",upcE:"upc-e",code128:"code-128",code39:"code-39",code93:"code-93",codabar:"codabar",itf:"itf",pdf417:"pdf-417",aztec:"aztec",dataMatrix:"data-matrix"},X={...to,all:Object.values(to)},et={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},jt={result:"scanner.result",end:"scanner.end"},ze={user:"user",web:"web",closed:"closed",error:"error"},Me={top:"top",full:"full"},Ve={once:"once",continuous:"continuous"},Lr=1500,no=6e4,L,H=Te({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),ro=()=>Qe.OS==="android"&&!!(L!=null&&L.requesting_permission),Ht=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r}=e!=null?e:{},i={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(a=>X.all.includes(a)))throw new g("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");i.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>no)throw new g("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${no}`);i.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new g("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");i.hint=o}if(r!==void 0){if(!Object.values(Me).includes(r))throw new g("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");i.layout=r}return i},Jt=e=>L!==e?!1:(L=void 0,H.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Fr=()=>Or.alert("Ch\u01B0a c\u1EA5p quy\u1EC1n camera","H\xE3y b\u1EADt quy\u1EC1n camera trong C\xE0i \u0111\u1EB7t \u0111\u1EC3 qu\xE9t m\xE3.",[{text:"Hu\u1EF7",style:"cancel"},{text:"M\u1EDF C\xE0i \u0111\u1EB7t",onPress:()=>{kr.openSettings().catch(()=>{})}}]),io=async(e,t)=>{if(L)throw new g("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new g("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");L=e;let n=()=>{if(e.cancelled||!t())throw new g("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new g("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=Qe.OS==="ios"&&r==="denied";e.requesting_permission=!0;let l;try{l=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await wt(),n(),l!=="granted")throw a&&Fr(),new g("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new g("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await Gt();n(),H.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw Jt(e),o}},_t;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{_t=e==null?void 0:e.insets}).catch(()=>{});var bt=()=>{var e;return _t!=null?_t:{top:Qe.OS==="ios"?54:(e=Ir.currentHeight)!=null?e:0,bottom:Qe.OS==="ios"?34:48}},Gt=async()=>{if(Qe.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},so=(e,t,n)=>{var o,r,i;return{owner:e,mode:t,types:(o=n.types)!=null?o:X.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Lr,hint:n.hint,layout:t===Ve.once?Me.full:(i=n.layout)!=null?i:Me.top,cancelled:!1,requesting_permission:!1,last_seen:new Map}},ao=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=so(e,Ve.once,t);a.onHit=o,a.resolve=r,a.reject=i,io(a,n).catch(i)}),co=(e,t,n,o=()=>!0,r)=>{let i=so(e,Ve.continuous,t);return i.emit=n,i.onHit=r,io(i,o)},At=(e,t,n)=>{var o,r;if(!H.getState().active){e.cancelled=!0;return}if(Jt(e)){if(e.mode===Ve.once){(o=e.reject)==null||o.call(e,t===ze.error?new g("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new g("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,jt.end,n?{reason:t,message:n}:{reason:t})}},lo=e=>{(L==null?void 0:L.owner)===e&&At(L,ze.web)},Pe=e=>{(L==null?void 0:L.owner)===e&&At(L,ze.closed)},Kt=()=>{L&&At(L,ze.user)},po=e=>{L&&At(L,ze.error,e)},Yt=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=L;if(!(!o||!H.getState().active))for(let{value:l,type:c}of e){if(!l)continue;let s=o.last_seen.get(l);if(o.last_seen.set(l,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===Ve.once){Jt(o),(i=o.resolve)==null||i.call(o,{value:l,type:c});return}H.setState(d=>({last_value:l,hit_tick:d.hit_tick+1,scan_count:d.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,jt.result,{value:l,type:c})}}},Dr={1:X.code128,2:X.code39,4:X.code93,8:X.codabar,16:X.dataMatrix,32:X.ean13,64:X.ean8,128:X.itf,256:X.qr,512:X.upcA,1024:X.upcE,2048:X.pdf417,4096:X.aztec},Nr=2500,oo=2e3,Wt=e=>{H.setState({notice:e}),setTimeout(()=>{H.getState().notice===e&&H.setState({notice:null})},Nr)},uo=async()=>{var t,n;let e=L;if(!(!e||H.getState().is_picking)){e.requesting_permission=!0,H.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:oo,maxHeight:oo}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||L!==e)return;if(r.errorCode||!i){Wt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),l=await a.scan(i);if(L!==e)return;let c=l.map(({value:s,format:d})=>({value:s,code_type:Dr[d]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:d})=>({value:s,type:d!=null?d:"unknown"}));if(!c.length){Wt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}Yt(c,Date.now(),!0)}catch{L===e&&Wt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await wt(),e.requesting_permission=!1,L===e&&H.setState({is_picking:!1})}}};var vt=1,g=class extends Error{constructor(n,o){super(o);this.code=n}},mo=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===vt&&typeof t.method=="string"?t:null}catch{return null}},nt=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,fo=(e,t)=>nt({id:e,result:t}),ho=(e,t)=>nt({id:e,error:{code:t.code,message:t.message}}),yo=(e,t)=>nt({event:e,data:t}),Zt=e=>nt({event:"context",data:e});var wo=()=>`(function () {
|
|
1
|
+
var Ht="https://retion-miniapp-platform.vercel.app",Ve=null,kn=new Set,dr=e=>{Ve=e,kn.forEach(t=>t())},D=()=>{if(!Ve)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Ve},In=e=>{kn.add(e),Ve&&e()},ue=(...e)=>{Ve!=null&&Ve.debug&&console.log("[miniapp]",...e)};var gr=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:c,contentLength:l})=>r==null?void 0:r(c,l)});return{promise:a.then(({statusCode:c})=>({status:c})),cancel:()=>e.stopDownload(i)}}}),mr=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});import Pn,{useCallback as xn,useEffect as le,useMemo as $t,useRef as be,useState as Ce}from"react";import{AppState as cr,ActivityIndicator as Ui,Animated as vn,BackHandler as Vi,Image as Bi,StyleSheet as Tn,Text as yt,TouchableOpacity as qi,View as En}from"react-native";import $i from"react-native-webview";import{Linking as vo,Platform as Jr}from"react-native";var Ln=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),_t,Jt=()=>(_t||(_t=import("react-native-biometrics").then(({default:e})=>Ln(new e({allowDeviceCredentials:!1}))).catch(e=>{throw _t=void 0,new m("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),_t);import{PermissionsAndroid as Be,Platform as fr}from"react-native";var Fn=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new m("INVALID_PARAMS","Tu\u1EF3 ch\u1ECDn v\u1ECB tr\xED ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.enableHighAccuracy!==void 0&&typeof t.enableHighAccuracy!="boolean")throw new m("INVALID_PARAMS","enableHighAccuracy ph\u1EA3i l\xE0 boolean");for(let[i,a,c]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let l=t[i];if(l!==void 0&&(typeof l!="number"||!Number.isFinite(l)||l<a||l>c))throw new m("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${c} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Dn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(l,s)=>{r||(r=!0,clearTimeout(a),l?o(l):n(s))},a=setTimeout(()=>i(new m("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),c=()=>r?!1:t()?!0:(i(new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!c())return;let l;try{l=(await import("@react-native-community/geolocation")).default}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(fr.OS==="android"){let s=Be.PERMISSIONS.ACCESS_FINE_LOCATION,g=Be.PERMISSIONS.ACCESS_COARSE_LOCATION,d=await Be.check(s);if(!c())return;let h=d||await Be.check(g);if(!c())return;if(!d&&!h){let u=await Be.requestMultiple([s,g]);if(!c())return;if(u[s]!==Be.RESULTS.GRANTED&&u[g]!==Be.RESULTS.GRANTED)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}c()&&l.getCurrentPosition(s=>{c()&&i(void 0,s)},s=>{var d;if(!c())return;let g=(d={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?d:"LOCATION_ERROR";i(new m(g,s.message))},e)}})().catch(l=>i(l))});import{Platform as zn}from"react-native";var Gt=20,Nn=20,Wn=/^[a-z][a-z0-9_-]{0,31}$/,hr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,yr=["low","medium","high"],Oe=e=>!!e&&typeof e=="object"&&!Array.isArray(e),j=e=>new m("INVALID_PARAMS",e),nt=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Un=(e,t)=>{if(e===void 0)return{};if(!Oe(e)||Object.keys(e).length>Nn||Object.values(e).some(n=>typeof n!="string"))throw j(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Nn} key)`);return e},jn=e=>{var n,o,r,i;if(e!==void 0&&!Oe(e))throw j("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!Wn.test(t.source)))throw j("source ph\u1EA3i l\xE0 t\xEAn ngu\u1ED3n, vd library | camera | document");if(t.accept!==void 0&&(!Array.isArray(t.accept)||t.accept.length>50||t.accept.some(a=>typeof a!="string"||!hr.test(a))))throw j("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!nt(t.max_count,1,Gt))throw j(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Gt}`);if(t.max_size!==void 0&&!nt(t.max_size,1,Number.MAX_SAFE_INTEGER))throw j("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!nt(t.concurrency,1,5))throw j("concurrency ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u20135");return{source:(n=t.source)!=null?n:"library",accept:((o=t.accept)!=null?o:[]).map(a=>a.toLowerCase()),max_count:(r=t.max_count)!=null?r:1,max_size:t.max_size,process:wr(t.process),target:br(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},wr=e=>{if(e===void 0)return{};if(!Oe(e))throw j("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Oe(n))throw j("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!nt(n[o],1,1e4))throw j(`process.image.${o} ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u201310000`);if(n.quality!==void 0&&(typeof n.quality!="number"||n.quality<=0||n.quality>1))throw j("process.image.quality ph\u1EA3i trong kho\u1EA3ng (0, 1]");t.image={max_width:n.max_width,max_height:n.max_height,quality:n.quality}}if(e.video!==void 0){let n=e.video;if(!Oe(n))throw j("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!nt(n.max_duration,1,3600))throw j("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!yr.includes(n.quality))throw j("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},br=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Oe(e))throw j("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!Wn.test(t))throw j("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!Oe(e.params))throw j("upload.params ph\u1EA3i l\xE0 object");return{target:t,params:(o=e.params)!=null?o:{}}}if(typeof e.url!="string"||!/^https:\/\//i.test(e.url))throw j("upload.url ph\u1EA3i l\xE0 https");for(let a of["field_name","url_field"])if(e[a]!==void 0&&(typeof e[a]!="string"||!e[a]))throw j(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:Un(e.headers,"upload.headers"),form_data:Un(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},Hn=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},_r=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=Hn(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},Ar=e=>{let t=e.length>0&&e.every(o=>o.startsWith("image/")),n=e.length>0&&e.every(o=>o.startsWith("video/"));return t?"image":n?"video":"mixed"},Qe,Sr=()=>(Qe!=null||(Qe=import("react-native-image-picker").catch(e=>{throw Qe=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),Qe),Vn=e=>async({accept:t,max_count:n,process:o})=>{var l,s,g,d,h,u,y,T,M;let r=await Sr(),i=Ar(t),a={mediaType:i==="image"?"photo":i,maxWidth:(l=o.image)==null?void 0:l.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(d=(g=o.image)==null?void 0:g.quality)!=null?d:.8,videoQuality:(u=(h=o.video)==null?void 0:h.quality)!=null?u:"medium",durationLimit:(y=o.video)==null?void 0:y.max_duration,assetRepresentationMode:"compatible"},c=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(c.didCancel)return[];if(c.errorCode){let v=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new m(v,(T=c.errorMessage)!=null?T:c.errorCode)}return((M=c.assets)!=null?M:[]).filter(v=>v.uri).map((v,A)=>{var O,U,Z;return{uri:v.uri,name:(O=v.fileName)!=null?O:`file_${A+1}`,mime_type:(U=v.type)!=null?U:"application/octet-stream",size:v.fileSize,width:v.width,height:v.height,duration:v.duration,processed:!((Z=v.type)!=null&&Z.startsWith("video/"))||zn.OS==="ios"}})},vr={"image/*":"images","video/*":"video","audio/*":"audio","text/plain":"plainText","text/csv":"csv","application/pdf":"pdf","application/json":"json","application/zip":"zip","application/msword":"doc","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","application/vnd.ms-excel":"xls","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","application/vnd.ms-powerpoint":"ppt","application/vnd.openxmlformats-officedocument.presentationml.presentation":"pptx"},Mr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},xr=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var g;return(g=vr[s])!=null?g:Mr[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let g=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(u=>u.uri&&!u.error).map((u,y)=>{var T,M,v;return{uri:u.uri,name:(T=u.name)!=null?T:`file_${y+1}`,mime_type:(M=u.type)!=null?M:"application/octet-stream",size:(v=u.size)!=null?v:void 0}});if(zn.OS!=="android"||!e.keepLocalCopy||!g.some(u=>u.uri.startsWith("content://")))return g;let d=await e.keepLocalCopy({files:g.map(u=>({uri:u.uri,fileName:u.name})),destination:"cachesDirectory"}),h=new Map(d.map(u=>[u.sourceUri,u.status==="success"?u.localUri:void 0]));return g.map(u=>{var y;return{...u,uri:(y=h.get(u.uri))!=null?y:u.uri}})}catch(s){let g=s==null?void 0:s.code;if(g===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw g===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new m("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},et,Er=async e=>(et!=null||(et=import("@react-native-documents/picker").then(t=>xr(t)).catch(t=>{throw et=void 0,new m("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await et)(e)),Jn={library:Vn("library"),camera:Vn("camera"),document:Er},Bn={type:"image",label:"\u1EA2nh",accept:["image/*"]},qn={type:"video",label:"Video",accept:["video/*"]},$n={library:[Bn,qn],camera:[Bn,qn],document:[{type:"any",label:"M\u1ECDi file",accept:[]},{type:"pdf",label:"PDF",accept:["application/pdf"]},{type:"word",label:"Word",accept:[".doc",".docx"]},{type:"excel",label:"Excel",accept:[".xls",".xlsx"]},{type:"powerpoint",label:"PowerPoint",accept:[".ppt",".pptx"]}]},tt,Gn=()=>(tt!=null||(tt=import("react-native-compressor").catch(()=>(tt=void 0,null))),tt),Kn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},Rr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),Pr={low:640,medium:1280,high:1920},Tr=async(e,{image:t})=>{var o;if(!t||!Rr.has(e.mime_type.toLowerCase()))return e;let n=await Gn();if(!n)return e;try{let r=await n.Image.compress(e.uri,{compressionMethod:"manual",maxWidth:t.max_width,maxHeight:t.max_height,quality:(o=t.quality)!=null?o:.8,output:"jpg"});return{...e,uri:r,mime_type:"image/jpeg",name:e.name.replace(/\.[^.]+$/,"")+".jpg",size:await Kn(n,r,e.size),processed:!0}}catch{return e}},Cr=async(e,{video:t})=>{var o;let n=await Gn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:Pr[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await Kn(n,r,e.size),processed:!0}}catch{return e}},Or={image:Tr,video:Cr},kr=(e,t)=>t.split(".").reduce((n,o)=>Oe(n)?n[o]:void 0,e),Yn=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new m("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([d,h])=>l.append(d,h)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let g=d=>{o.removeEventListener("abort",s),d()};c.open("POST",a.url),Object.entries(a.headers).forEach(([d,h])=>c.setRequestHeader(d,h)),c.upload.onprogress=d=>n(d.loaded,d.total||e.size||0),c.onload=()=>g(()=>{let d=c.responseText;try{d=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new m("UPLOAD_FAILED",`HTTP ${c.status}`));return}let h=kr(d,a.url_field);if(typeof h!="string"||!h){i(new m("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:h,response:d})}),c.onerror=()=>g(()=>i(new m("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>g(()=>i(new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),Xn=e=>{var o,r;let t={...Jn};for(let[i,a]of Object.entries((o=e==null?void 0:e.sources)!=null?o:{}))a?t[i]=a:delete t[i];let n={url:Yn};for(let[i,a]of Object.entries((r=e==null?void 0:e.targets)!=null?r:{}))i!=="url"&&a&&(n[i]=a);return{sources:t,targets:n}},Zn=e=>{let{sources:t,targets:n}=Xn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===Jn[i]&&$n[i]).map(i=>[i,$n[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Gt}},St=new Map,Qn=(e,t)=>`${e}:${t}`,Ir=0,eo=(e,t)=>{var n;typeof t=="string"&&((n=St.get(Qn(e,t)))==null||n.abort())},qe=e=>{for(let[t,n]of St)t.startsWith(`${e}:`)&&n.abort()},At=()=>new m("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),Lr=(e,t)=>{var n;return{name:e,code:typeof(t==null?void 0:t.code)=="string"?t.code:"UPLOAD_FAILED",message:String((n=t==null?void 0:t.message)!=null?n:t)}},to=async(e,t)=>{var l;let{sources:n,targets:o}=Xn(t.config),r=n[e.source];if(!r)throw new m("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=o[e.target.target];if(!i)throw new m("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=Qn(t.instance_id,(l=t.task_id)!=null?l:`auto-${++Ir}`);St.set(c,a);try{return await Fr(e,t,r,i,a.signal)}finally{St.delete(c)}},Fr=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=d=>d()},l,s,g)=>{var p,S,L;let d={app_id:n!=null?n:"",instance_id:t,context:{...(p=o==null?void 0:o())!=null?p:{}}},h=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:d}))).slice(0,e.max_count);if(g.aborted)throw At();if(!h.length)throw new m("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let u=[],y=h.filter(x=>_r(x,e.accept)?!0:(u.push({name:x.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${x.mime_type||Hn(x.name)}`}),!1)),T=y.map(()=>0),M=y.map(x=>{var ie;return(ie=x.size)!=null?ie:0}),v=0,A=0,O=(x=!1)=>{if(!a||!r)return;let ie=Date.now();if(!x&&ie-A<200)return;A=ie;let fe=M.reduce((P,Q)=>P+Q,0),W=T.reduce((P,Q)=>P+Q,0);a("upload.progress",{task_id:r,loaded:W,total:fe,percent:fe?Math.min(100,Math.round(W/fe*100)):0,done_count:v,count:y.length})},U=[],Z=0,xe=async()=>{var x,ie,fe;for(;Z<y.length;){let W=Z++,P=y[W];try{if(g.aborted)throw At();let Q=P.mime_type.startsWith("image/")?"image":P.mime_type.startsWith("video/")?"video":void 0,q=Q&&!P.processed?(ie=(x=i==null?void 0:i.processors)==null?void 0:x[Q])!=null?ie:Or[Q]:void 0;if(q&&(P=await q(P,e.process),M[W]=(fe=P.size)!=null?fe:M[W],g.aborted))throw At();if(e.max_size&&P.size&&P.size>e.max_size)throw new m("FILE_TOO_LARGE",`File ${P.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let Y=(We,Se)=>{T[W]=We,Se&&(M[W]=Se),O()},ee=await s({file:P,target:e.target,onProgress:Y,signal:g,caller:d});if(typeof(ee==null?void 0:ee.url)!="string"||!ee.url)throw new m("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:_e,...Ae}=ee;U[W]={url:_e,name:P.name,mime_type:P.mime_type,size:P.size,width:P.width,height:P.height,duration:P.duration,...Object.keys(Ae).length?{response:"response"in Ae?Ae.response:Ae}:{}},T[W]=M[W]}catch(Q){u.push(Lr(y[W].name,Q))}finally{v++,O(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,y.length)},xe)),g.aborted)throw At();let re=U.filter(x=>!!x);if(!re.length){let x=u[0];throw new m((S=x==null?void 0:x.code)!=null?S:"UPLOAD_FAILED",(L=x==null?void 0:x.message)!=null?L:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:re,failed:u}};import{useRef as Dr,useSyncExternalStore as Nr}from"react";var ke=e=>{let t=e,n=new Set;return{getState:()=>t,setState:o=>{let r=typeof o=="function"?o(t):o;t={...t,...r},n.forEach(i=>i())},subscribe:o=>(n.add(o),()=>{n.delete(o)})}},B=(e,t,n=Object.is)=>{let o=Dr(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let c=t(i),l=a&&n(a.value,c)?a.value:c;return o.current={state:i,selector:t,value:l},l};return Nr(e.subscribe,r)};var he={info:"info",success:"success",error:"error"},Ur=200,no={info:2e3,success:2e3,error:3e3},ot=ke({message:"",type:he.info,tick:0}),oo=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Ur);return o?{message:o,type:Object.values(he).includes(n)?n:he.info}:null},ro=(e,t=he.info)=>{ot.setState(n=>({message:e,type:t,tick:n.tick+1}))};import{Alert as Br,Linking as qr,Platform as rt,StatusBar as $r}from"react-native";import{AppState as io,Platform as Yt}from"react-native";var de,vt=new Map,so=(e,t)=>{vt.set(e,t)},ao=e=>{vt.delete(e)},co=()=>Yt.OS==="android"&&!!(de!=null&&de.requesting_permission),Vr=1500,Mt=()=>new Promise(e=>{if(Yt.OS!=="android"||io.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Vr),o=io.addEventListener("change",r=>{r==="active"&&t()})}),Kt=e=>{var t;if(de===e&&(de=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Yt.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},lo=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(de)throw new m("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};de=r;try{let g;try{g=await import("expo-speech-recognition")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let d=g.ExpoSpeechRecognitionModule;if(r.native=d,r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let h;try{h=await d.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await Mt(),r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!h.granted)throw new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await d.getStateAsync()!=="inactive")throw new m("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(r.cancelled||!o())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(d.addListener("result",u=>{var y,T;de!==r||r.cancelled||n(u.isFinal?"speech.final":"speech.partial",{...u,text:(T=(y=u.results[0])==null?void 0:y.transcript)!=null?T:""})}),d.addListener("error",u=>{de===r&&!r.cancelled&&n("speech.error",{...u,code:u.error})}),d.addListener("end",()=>{de===r&&(Kt(r),n("speech.end"))})),r.started=!0,d.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(a=t.continuous)!=null?a:!0,interimResults:(c=t.interimResults)!=null?c:!0,addsPunctuation:(l=t.addsPunctuation)!=null?l:!0,requiresOnDeviceRecognition:(s=t.requiresOnDeviceRecognition)!=null?s:!1,iosCategory:{category:g.AVAudioSessionCategory.playAndRecord,categoryOptions:[g.AVAudioSessionCategoryOptions.defaultToSpeaker,g.AVAudioSessionCategoryOptions.allowBluetooth],mode:g.AVAudioSessionMode.measurement}})}catch(g){throw Kt(r),g}},po=e=>{let t=de;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Re=e=>{var o;let t=vt.get(e);if(t){vt.delete(e);try{(o=t.release)==null||o.call(t,e)}catch{}return}let n=de;if(!(!n||n.owner!==e||n.cancelled)&&(n.cancelled=!0,n.started))try{n.native.abort()}catch{Kt(n)}};var uo={qr:"qr",ean13:"ean-13",ean8:"ean-8",upcA:"upc-a",upcE:"upc-e",code128:"code-128",code39:"code-39",code93:"code-93",codabar:"codabar",itf:"itf",pdf417:"pdf-417",aztec:"aztec",dataMatrix:"data-matrix"},oe={...uo,all:Object.values(uo)},it={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},Zt={result:"scanner.result",end:"scanner.end"},je={user:"user",web:"web",closed:"closed",error:"error"},ge={top:"top",full:"full"},Ie={once:"once",continuous:"continuous"},zr=1500,go=6e4,I,H=ke({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),fo=()=>rt.OS==="android"&&!!(I!=null&&I.requesting_permission),Qt=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r,absolute:i}=e!=null?e:{},a={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(c=>oe.all.includes(c)))throw new m("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");a.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>go)throw new m("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${go}`);a.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new m("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");a.hint=o}if(r!==void 0){if(!Object.values(ge).includes(r))throw new m("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");a.layout=r}if(i!==void 0){if(typeof i!="boolean")throw new m("INVALID_PARAMS","absolute ph\u1EA3i l\xE0 boolean");a.absolute=i}return a},en=e=>I!==e?!1:(I=void 0,H.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Wr=()=>Br.alert("Ch\u01B0a c\u1EA5p quy\u1EC1n camera","H\xE3y b\u1EADt quy\u1EC1n camera trong C\xE0i \u0111\u1EB7t \u0111\u1EC3 qu\xE9t m\xE3.",[{text:"Hu\u1EF7",style:"cancel"},{text:"M\u1EDF C\xE0i \u0111\u1EB7t",onPress:()=>{qr.openSettings().catch(()=>{})}}]),ho=async(e,t)=>{if(I)throw new m("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new m("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");I=e;let n=()=>{if(e.cancelled||!t())throw new m("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new m("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n();let r=o.Camera.getCameraPermissionStatus();if(r!=="granted"){let a=rt.OS==="ios"&&r==="denied";e.requesting_permission=!0;let c;try{c=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await Mt(),n(),c!=="granted")throw a&&Wr(),new m("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera")}if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new m("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await tn();n(),H.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,absolute:e.absolute,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw en(e),o}},xt;import("react-native-safe-area-context").then(({initialWindowMetrics:e})=>{xt=e==null?void 0:e.insets}).catch(()=>{});var Et=()=>{var e;return xt!=null?xt:{top:rt.OS==="ios"?54:(e=$r.currentHeight)!=null?e:0,bottom:rt.OS==="ios"?34:48}},tn=async()=>{if(rt.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},yo=(e,t,n)=>{var o,r,i,a;return{owner:e,mode:t,types:(o=n.types)!=null?o:oe.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:zr,hint:n.hint,layout:t===Ie.once?ge.full:(i=n.layout)!=null?i:ge.top,absolute:t!==Ie.once&&((a=n.layout)!=null?a:ge.top)===ge.top&&n.absolute===!0,cancelled:!1,requesting_permission:!1,last_seen:new Map}},wo=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=yo(e,Ie.once,t);a.onHit=o,a.resolve=r,a.reject=i,ho(a,n).catch(i)}),bo=(e,t,n,o=()=>!0,r)=>{let i=yo(e,Ie.continuous,t);return i.emit=n,i.onHit=r,ho(i,o)},Rt=(e,t,n)=>{var o,r;if(!H.getState().active){e.cancelled=!0;return}if(en(e)){if(e.mode===Ie.once){(o=e.reject)==null||o.call(e,t===je.error?new m("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new m("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,Zt.end,n?{reason:t,message:n}:{reason:t})}},_o=e=>{(I==null?void 0:I.owner)===e&&Rt(I,je.web)},Le=e=>{(I==null?void 0:I.owner)===e&&Rt(I,je.closed)},nn=()=>{I&&Rt(I,je.user)},Ao=e=>{I&&Rt(I,je.error,e)},on=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=I;if(!(!o||!H.getState().active))for(let{value:c,type:l}of e){if(!c)continue;let s=o.last_seen.get(c);if(o.last_seen.set(c,t),!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if((r=o.onHit)==null||r.call(o),o.mode===Ie.once){en(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}H.setState(g=>({last_value:c,hit_tick:g.hit_tick+1,scan_count:g.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,Zt.result,{value:c,type:l})}}},jr={1:oe.code128,2:oe.code39,4:oe.code93,8:oe.codabar,16:oe.dataMatrix,32:oe.ean13,64:oe.ean8,128:oe.itf,256:oe.qr,512:oe.upcA,1024:oe.upcE,2048:oe.pdf417,4096:oe.aztec},Hr=2500,mo=2e3,Xt=e=>{H.setState({notice:e}),setTimeout(()=>{H.getState().notice===e&&H.setState({notice:null})},Hr)},So=async()=>{var t,n;let e=I;if(!(!e||H.getState().is_picking)){e.requesting_permission=!0,H.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1,maxWidth:mo,maxHeight:mo}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||I!==e)return;if(r.errorCode||!i){Xt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),c=await a.scan(i);if(I!==e)return;let l=c.map(({value:s,format:g})=>({value:s,code_type:jr[g]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:g})=>({value:s,type:g!=null?g:"unknown"}));if(!l.length){Xt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}on(l,Date.now(),!0)}catch{I===e&&Xt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await Mt(),e.requesting_permission=!1,I===e&&H.setState({is_picking:!1})}}};var Tt=1,m=class extends Error{constructor(n,o){super(o);this.code=n}},Mo=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===Tt&&typeof t.method=="string"?t:null}catch{return null}},at=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,xo=(e,t)=>at({id:e,result:t}),Eo=(e,t)=>at({id:e,error:{code:t.code,message:t.message}}),Ro=(e,t)=>at({event:e,data:t}),sn=e=>at({event:"context",data:e});var Po=()=>`(function () {
|
|
2
2
|
var post = function (level, args) {
|
|
3
3
|
try {
|
|
4
4
|
var parts = [];
|
|
@@ -8,7 +8,7 @@ var Vt="https://retion-miniapp-platform.vercel.app",De=null,Mn=new Set,or=e=>{De
|
|
|
8
8
|
else if (typeof a === 'object') { try { parts.push(JSON.stringify(a).slice(0, 800)); } catch (e) { parts.push(String(a)); } }
|
|
9
9
|
else { parts.push(String(a)); }
|
|
10
10
|
}
|
|
11
|
-
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${
|
|
11
|
+
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${Tt}, method: 'log', level: level, text: parts.join(' ') }));
|
|
12
12
|
} catch (e) {}
|
|
13
13
|
};
|
|
14
14
|
['log', 'info', 'warn', 'error'].forEach(function (level) {
|
|
@@ -19,7 +19,7 @@ var Vt="https://retion-miniapp-platform.vercel.app",De=null,Mn=new Set,or=e=>{De
|
|
|
19
19
|
window.addEventListener('unhandledrejection', function (e) { post('error', ['[unhandledrejection]', e.reason]); });
|
|
20
20
|
// Kh\xF4ng log query (c\xF3 th\u1EC3 ch\u1EE9a token) \u2014 ch\u1EC9 \u0111\u01B0\u1EDDng d\u1EABn + route.
|
|
21
21
|
post('info', ['[page] ' + location.pathname + location.hash]);
|
|
22
|
-
})(); true;`,
|
|
22
|
+
})(); true;`,To=()=>`(function () {
|
|
23
23
|
function atTop(el) {
|
|
24
24
|
for (var n = el; n && n !== document.documentElement; n = n.parentElement) {
|
|
25
25
|
if (n.scrollTop > 0) { return false; }
|
|
@@ -30,7 +30,7 @@ var Vt="https://retion-miniapp-platform.vercel.app",De=null,Mn=new Set,or=e=>{De
|
|
|
30
30
|
function report(at_top) {
|
|
31
31
|
if (at_top === last) { return; }
|
|
32
32
|
last = at_top;
|
|
33
|
-
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${
|
|
33
|
+
window.ReactNativeWebView && window.ReactNativeWebView.postMessage(JSON.stringify({ __retion: ${Tt}, method: 'touchAtTop', at_top: at_top }));
|
|
34
34
|
}
|
|
35
35
|
document.addEventListener('touchstart', function (e) { report(atTop(e.target)); }, { capture: true, passive: true });
|
|
36
36
|
// Cu\u1ED9n r\u1EDDi \u0111\u1EA7u trang \u2192 b\xE1o ngay, kh\xF4ng \u0111\u1EE3i l\u1EA7n ch\u1EA1m sau (tr\xE1nh host d\xF9ng gi\xE1 tr\u1ECB c\u0169 "\u0111ang \u1EDF \u0111\u1EA7u").
|
|
@@ -38,7 +38,7 @@ var Vt="https://retion-miniapp-platform.vercel.app",De=null,Mn=new Set,or=e=>{De
|
|
|
38
38
|
var el = e.target === document ? document.documentElement : e.target;
|
|
39
39
|
if (el && el.scrollTop > 0) { report(false); }
|
|
40
40
|
}, { capture: true, passive: true });
|
|
41
|
-
})(); true;`,
|
|
41
|
+
})(); true;`,Co=()=>`(function () {
|
|
42
42
|
if (window.__retionSafeAreaFrozen) { return; }
|
|
43
43
|
window.__retionSafeAreaFrozen = true;
|
|
44
44
|
var max = {};
|
|
@@ -59,11 +59,14 @@ var Vt="https://retion-miniapp-platform.vercel.app",De=null,Mn=new Set,or=e=>{De
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
|
-
})(); true;`,
|
|
63
|
-
${
|
|
62
|
+
})(); true;`,Oo=e=>at({event:e}),ko=(e,t)=>{let n=Io(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
|
|
63
|
+
${sn(e)}`},Io=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),Lo=(e,t={})=>{let n=Io(t);return`window.__RETION_MINIAPP_HOST__ = { protocol: ${Tt} };
|
|
64
64
|
window.__RETION_MINIAPP_CONTEXT__ = ${JSON.stringify(e)};
|
|
65
65
|
${n?`try { history.replaceState(history.state, '', location.pathname + '?' + ${JSON.stringify(n)} + location.hash); } catch (e) {}`:""}
|
|
66
|
-
true;`},
|
|
66
|
+
true;`},Fo={partner:"partner_token",chatbox:"chatbox_token"},Do=(e,t)=>{let n={...e};for(let o of Object.values(Fo))t.includes(o)||delete n[o];return n},rn=new Set,st=async(e,t)=>{if(rn.has(e))throw new m("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);rn.add(e);try{return await t()}finally{rn.delete(e)}},an=e=>`(function () {
|
|
67
|
+
window.__retionScannerHeight = ${Math.max(0,Math.round(e))};
|
|
68
|
+
window.dispatchEvent(new Event('retionscannerheight'));
|
|
69
|
+
})(); true;`,No=()=>`(function () {
|
|
67
70
|
try {
|
|
68
71
|
var AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
69
72
|
if (!AudioCtx) { return; }
|
|
@@ -82,4 +85,4 @@ var Vt="https://retion-miniapp-platform.vercel.app",De=null,Mn=new Set,or=e=>{De
|
|
|
82
85
|
// iOS c\xF3 th\u1EC3 \u0111\u1EC3 context \u1EDF suspended / interrupted (vd. khi camera m\u1EDF phi\xEAn quay): ch\u1EA1y l\u1EA1i xong m\u1EDBi ph\xE1t.
|
|
83
86
|
if (ctx.state === 'running') { play(); } else { ctx.resume().then(play).catch(function () {}); }
|
|
84
87
|
} catch (e) {}
|
|
85
|
-
})(); true;`,Vr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),St=(e,t)=>{if(typeof e!="string"||!e)throw new g("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},To=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:l,instance_id:c,options:s,emit:d,isActive:m,playBeep:h})=>{var M,A,_,W,Z,te,we;let p=s==null?void 0:s.handlers,y={app_id:l,instance_id:c,close:a},E=()=>{var w;(w=s==null?void 0:s.haptic)==null||w.call(s,"impactLight"),h==null||h()},v=()=>new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let w=Rn(t);return tt(e,()=>Tn(w,m))}case"speech.start":{if(!d)throw v();let w={};if((t==null?void 0:t.lang)!==void 0){if(typeof t.lang!="string"||!/^[a-zA-Z]{2,8}(-[a-zA-Z0-9]{1,8})*$/.test(t.lang))throw new g("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");w.lang=t.lang}for(let S of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[S])!==void 0){if(typeof t[S]!="boolean")throw new g("INVALID_PARAMS",`${S} ph\u1EA3i l\xE0 boolean`);w[S]=t[S]}return Qn(c,w,d,m)}case"speech.stop":return eo(c);case et.scan:return ao(c,Ht(t),m,E);case et.start:{if(!d)throw v();return co(c,Ht(t),d,m,E)}case et.stop:return lo(c);case"uploadFiles":{let{task_id:w,...S}=t!=null?t:{};if(w!==void 0&&(typeof w!="string"||!w))throw new g("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return Jn(Nn(S),{instance_id:c,app_id:l,getContext:r,task_id:w,config:s==null?void 0:s.upload,emit:d,exclusivePick:q=>tt("uploadFiles.pick",q)})}case"uploadFiles.cancel":Hn(c,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Wn(s==null?void 0:s.upload);case"getBiometricAvailability":return((M=s==null?void 0:s.biometrics)!=null?M:await Bt()).getAvailability();case"authenticateBiometric":{let w=St(t==null?void 0:t.reason,"reason").trim();if(!w||w.length>200)throw new g("INVALID_PARAMS","reason must contain 1\u2013200 characters");let S=t==null?void 0:t.cancelButtonText;if(S!==void 0&&(typeof S!="string"||!S.trim()||S.length>80))throw new g("INVALID_PARAMS","Invalid cancelButtonText");return tt(e,async()=>{var x;return((x=s==null?void 0:s.biometrics)!=null?x:await Bt()).authenticate({reason:w,cancelButtonText:S})})}case"requestPayment":{let w=p==null?void 0:p.requestPayment;if(!w)throw v();let S=t==null?void 0:t.amount;if(typeof S!="number"||!Number.isFinite(S)||S<=0)throw new g("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let q={...t,amount:S,currency:St(t==null?void 0:t.currency,"currency")};return tt(e,()=>w(q,y))}case"printImage":{let w=p==null?void 0:p.printImage;if(!w)throw v();let S=St(t==null?void 0:t.image,"image");await tt(e,()=>w({image:S},y));return}case"openScreen":if(!(p!=null&&p.openScreen))throw v();await p.openScreen({screen:St(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},y);return;case"closeApp":a();return;case"openWebview":{let w=String((A=t==null?void 0:t.url)!=null?A:"");if(!/^https?:\/\//i.test(w))throw new g("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(w):go.openURL(w));return}case"openLink":{let w=String((_=t==null?void 0:t.url)!=null?_:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(w)||/^(javascript|file|data|about|blob):/i.test(w))throw new g("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(w):go.openURL(w))}catch(S){throw new g("NOT_SUPPORTED",String((Z=(W=S==null?void 0:S.message)!=null?W:S)!=null?Z:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let w=Kn(t);if(!w||(m==null?void 0:m())===!1)return;s!=null&&s.showToast?s.showToast(w.message,{type:w.type}):Yn(w.message,w.type);return}case"haptic":{let w=Vr.has(t==null?void 0:t.type)?t.type:"selection";(te=s==null?void 0:s.haptic)==null||te.call(s,w);return}case"getSystemInfo":return{platform:Ur.OS==="ios"?"ios":"android",appVersion:(we=s==null?void 0:s.app_version)!=null?we:"",theme:i?"dark":"light"};case"getAccessToken":{let w=n().access_token;if(!w)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return w}case"getToken":{let w=t==null?void 0:t.type;if(w==="access"){let x=n().access_token;if(!x)throw new g("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return x}if(w!=="partner"&&w!=="chatbox")throw new g("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(w)}`);let S=xo[w];if(!o().includes(S))throw new g("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${S} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let q=w==="partner"?n().partner_token:n().chatbox_token;if(!q)throw new g("HOST_ERROR",`Kh\xF4ng c\xF3 ${S}`);return q}case"getUserInfo":{let w=n().user;if(!w)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return w}case"getPageInfo":{let w=n().page;if(!w)throw new g("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return w}case"sendMessage":case"insertText":throw new g("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new g("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var en=e=>`bundle:${e}`,tn=()=>`${D().file_system.document_dir}/miniapps`,nn=tn,on=(e,t,n="index.html",o=!1,r=[])=>{let i=`${nn()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},Qt=e=>{var t;D().storage.setString(en(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},Br=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,F=e=>{let t=D().storage.getString(en(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return on(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},xe=e=>D().file_system.exists(e.entry_uri.replace("file://","")),rn=async e=>{let t=F(e.app_id);return(t==null?void 0:t.version)===e.version&&await xe(t)},Co=async(e,t)=>{let n=D().file_system,o=`${nn()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},Oo=async e=>{var t;await((t=rt[e])==null?void 0:t.catch(()=>{})),D().storage.setString(en(e),""),await D().file_system.remove(`${nn()}/${e}`).catch(()=>{})},We=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},rt={},ko=(e,t)=>{var i;let o=((i=rt[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return rt[e]=r,r.then(()=>{rt[e]===r&&delete rt[e]}),o},qr=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let l=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(l)return l}return 0},$r=({manifest:e,zip_path:t})=>ko(e.app_id,async()=>{var i;let n=D().file_system,o=F(e.app_id);if(o&&qr(o.version,e.version)>=0&&await xe(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=on(e.app_id,e.version,e.entry,!!e.context_update,(i=e.permissions)!=null?i:[]);return await n.remove(r.dir).catch(()=>{}),await n.mkdir(r.dir),await n.unzip(t,r.dir),Qt(e),le("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),Co(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),sn=(e,{base_url:t,onProgress:n}={})=>{let o=D().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,l=()=>{if(i)throw new We},c=async()=>{var m;l();let s=F(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return Qt(e),F(e.app_id);l();let d=o.download({url:t?Br(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(h,p)=>{var E;let y=p>0?p:(E=e.size)!=null?E:0;y>0&&(n==null||n(Math.min(1,h/y)))}});r=d;try{let{status:h}=await d.promise;if(l(),h!==200)throw new Error(`bundle ${h}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else le("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);l();let p=on(e.app_id,e.version,e.entry,!!e.context_update,(m=e.permissions)!=null?m:[]);return await o.remove(p.dir).catch(()=>{}),await o.mkdir(p.dir),await o.unzip(a,p.dir),Qt(e),Co(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),p}catch(h){throw i?new We:h}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:ko(e.app_id,c),cancel:()=>{i=!0,r==null||r.cancel()}}},ot={},zr=__DEV__?0:60*1e3,Po={},Io=(e,t)=>{var o,r;let n=F(e);return n&&Date.now()-((o=Po[t])!=null?o:0)<zr?Promise.resolve(n):((r=ot[e])!=null||(ot[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),l=await sn(a,{base_url:t}).promise;return Po[t]=Date.now(),l})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),F(e))).finally(()=>{ot[e]=void 0})),ot[e])};var Mt=new Map,Lo=(e,t)=>(Mt.set(e,t),()=>{Mt.get(e)===t&&Mt.delete(e)}),Wr=(e,t)=>{let n=Mt.get(e);return n?n(t):!1};import{useCallback as Fo,useEffect as it,useRef as Ce,useState as xt}from"react";import{Animated as z,BackHandler as jr,Dimensions as Hr,Easing as Do,Pressable as Jr,StyleSheet as cn,Text as st,View as B}from"react-native";import{Fragment as oi,jsx as R,jsxs as _e}from"react/jsx-runtime";var at="#22C55E",Gr="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",Kr=2,Rt=18,Yr=1600,ct=14,Xr=2e3,Vo=.38,Zr=40,No=2,Qr=8,ei=2e3,je=2e3,ti=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:ct},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:ct},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:ct},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:ct}],Uo=({color:e})=>R(oi,{children:ti.map((t,n)=>R(B,{style:[b.corner,t,{borderColor:e}]},n))}),Et=({style:e,children:t,...n})=>{let o=Ce(new z.Value(1)).current,r=i=>z.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return R(Jr,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:R(z.View,{style:[e,{transform:[{scale:o}]}],children:t})})},ln=({scanner:e})=>{var Je,f;let{vision:t,types:n,mode:o,layout:r,hint:i,glass_view:a}=e,l=r===Me.top,c=t.useCameraDevice("back"),s=Ce(new z.Value(1)).current,[d,m]=xt(!1),[h,p]=xt(1),y=Ce(null),[E,v]=xt(()=>{let{width:u,height:P}=Hr.get("window");return{width:u,height:l?P*Vo:P,window_y:0}}),M=V(H,u=>u.last_value),A=V(H,u=>u.hit_tick),_=V(H,u=>u.scan_count),W=V(H,u=>u.notice),Z=V(H,u=>u.is_picking),te=Ce(null),we=bt(),w=we.top,S=Ce(new z.Value(0)).current,q=Ce(new z.Value(0)).current,x=Ce(new z.Value(0)).current,C=Math.round(E.width*(l?.8:.78)),k=Math.round(l?E.height*.46:C*.78),N=Math.round((E.height-k)/2),I=Math.round((E.width-C)/2),Q=t.useCodeScanner({codeTypes:n,onCodeScanned:Fo(u=>Yt(u),[])});it(()=>{let u=jr.addEventListener("hardwareBackPress",()=>(Kt(),!0));return()=>u.remove()},[]);let Le=Ce(A);it(()=>{if(A===Le.current)return;S.setValue(1),x.setValue(1);let u=z.parallel([z.timing(S,{toValue:0,duration:450,useNativeDriver:!0}),z.sequence([z.delay(Xr),z.timing(x,{toValue:0,duration:250,useNativeDriver:!0})])]);return u.start(),()=>u.stop()},[A,S,x]),it(()=>{let u=ee=>z.timing(q,{toValue:ee,duration:Yr,easing:Do.inOut(Do.quad),useNativeDriver:!0}),P=z.loop(z.sequence([u(1),u(0)]));return P.start(),()=>P.stop()},[q]);let de=Fo(()=>{z.timing(s,{toValue:0,duration:220,useNativeDriver:!0}).start()},[s]);it(()=>{let u=setTimeout(de,ei);return()=>clearTimeout(u)},[de]);let[ne,Fe]=xt(!1);it(()=>{let u=requestAnimationFrame(()=>{u=requestAnimationFrame(()=>Fe(!0))});return()=>cancelAnimationFrame(u)},[]);let be=!!(c!=null&&c.hasTorch),Ae=(Je=c==null?void 0:c.neutralZoom)!=null?Je:1,Se=c?Math.min(c.maxZoom/Ae,Qr):1,Dt=Ae*Math.min(h,Se),Nt=u=>{var ae;let{touches:P}=u.nativeEvent;if(P.length!==2){y.current=null;return}let ee=Math.hypot(P[0].pageX-P[1].pageX,P[0].pageY-P[1].pageY);(ae=y.current)!=null||(y.current={distance:ee,level:h}),p(Math.max(1,Math.min(Se,y.current.level*(ee/y.current.distance))))},mt=R(st,{style:[b.hint,!!W&&b.hint_notice],numberOfLines:1,children:(f=W!=null?W:i)!=null?f:Gr});return R(B,{ref:te,onTouchMove:Nt,onTouchEnd:()=>{y.current=null},style:l?b.top:b.full,onLayout:({nativeEvent:{layout:u}})=>{var P;(P=te.current)==null||P.measureInWindow((ee,ae)=>{v({width:u.width,height:u.height,window_y:ae||0})})},children:_e(B,{style:b.content,children:[c&&ne&&R(t.Camera,{style:cn.absoluteFill,device:c,isActive:!Z,codeScanner:Q,torch:d&&be?"on":"off",zoom:Dt,onPreviewStarted:de,onError:u=>po(u.message)}),R(z.View,{style:[b.preview_cover,{opacity:s}],pointerEvents:"none"}),E.height>0&&_e(B,{style:b.overlay,pointerEvents:"none",children:[R(B,{style:[b.dim_ring,{top:N-je,left:I-je,width:C+je*2,height:k+je*2}]}),_e(B,{style:{position:"absolute",top:N,left:I,width:C,height:k},children:[R(Uo,{color:"#FFFFFF"}),R(z.View,{style:[cn.absoluteFill,{opacity:S}],children:R(Uo,{color:at})}),_e(z.View,{style:[b.scan_line_wrap,{transform:[{translateY:q.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,k-Rt)]})}]}],children:[R(B,{style:b.scan_glow_outer}),R(B,{style:b.scan_glow_inner}),R(B,{style:b.scan_line})]})]}),R(B,{style:[b.hint_slot,l?{top:0,height:N-6,justifyContent:"flex-end"}:{top:N+k+20}],children:mt}),o===Ve.continuous&&!!M&&R(z.View,{style:[b.result_slot,{top:l?N+k-Zr:N+k+52},{opacity:x}],children:_e(B,{style:b.result,children:[R(B,{style:b.check_badge,children:R(B,{style:b.check_mark})}),R(st,{style:b.result_text,numberOfLines:1,children:M}),_e(st,{style:b.result_count,children:["\xB7 ",_," m\xE3"]})]})})]}),E.height>0&&R(B,{style:[b.close_slot,l?b.close_slot_top:{top:Math.max(12,w-E.window_y+12)}],children:_e(Et,{style:[b.close_button,!!a&&b.glass_surface],onPress:Kt,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[a&&R(a,{style:b.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),R(B,{style:[b.close_bar,b.close_bar_a]}),R(B,{style:[b.close_bar,b.close_bar_b]})]})}),R(B,{style:[b.toolbar_wrap,!l&&{bottom:we.bottom+20}],pointerEvents:"box-none",children:_e(B,{style:[b.toolbar,!!a&&b.glass_surface],children:[a&&R(a,{style:b.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),R(Et,{style:b.tool,onPress:uo,disabled:Z,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:_e(B,{style:b.image_icon,children:[R(B,{style:b.image_icon_dot}),R(B,{style:b.image_icon_hill})]})}),!!c&&Se>=No&&R(Et,{style:[b.tool,h>1&&b.tool_on],onPress:()=>p(u=>u>1?1:No),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:_e(st,{style:[b.zoom_text,h>1&&b.zoom_text_on],children:[Math.round(h*10)/10,"x"]})}),be&&R(Et,{style:[b.tool,d&&b.tool_on],onPress:()=>m(u=>!u),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:d},children:R(st,{style:[b.torch_icon,d&&b.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},ni="rgba(0,0,0,0.5)",an=50,b=cn.create({top:{height:`${Vo*100}%`,overflow:"hidden",backgroundColor:"#000000"},full:{position:"absolute",top:0,left:0,right:0,bottom:0},content:{flex:1,backgroundColor:"#000000"},preview_cover:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"#000000"},overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,overflow:"hidden"},dim_ring:{position:"absolute",borderWidth:je,borderColor:ni,borderRadius:je+ct},hint_slot:{position:"absolute",left:16,right:16,alignItems:"center"},hint:{color:"#FFFFFF",fontSize:14,fontWeight:"500"},hint_notice:{color:"#FCA5A5"},corner:{position:"absolute",width:28,height:28},scan_line_wrap:{position:"absolute",top:0,left:10,right:10,height:Rt,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:Rt,borderRadius:Rt/2,backgroundColor:at,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:at,opacity:.2},scan_line:{height:Kr,borderRadius:1,backgroundColor:at},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_slot_top:{bottom:15},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:an,height:an,borderRadius:an/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result:{maxWidth:"100%",flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:12,paddingVertical:6,borderRadius:999,backgroundColor:"rgba(39,39,42,0.9)"},check_badge:{width:18,height:18,borderRadius:9,alignItems:"center",justifyContent:"center",backgroundColor:at},check_mark:{width:5,height:9,marginTop:-2,borderRightWidth:2,borderBottomWidth:2,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_text:{flexShrink:1,color:"#FFFFFF",fontWeight:"600",fontSize:13},result_count:{color:"#A1A1AA",fontSize:13}});import{useEffect as Bo,useRef as lt,useState as qo}from"react";import{AccessibilityInfo as ri,Animated as J,Platform as ii,StyleSheet as $o,Text as si,View as Be}from"react-native";import{Fragment as jo,jsx as oe,jsxs as un}from"react/jsx-runtime";var pn={[me.info]:"#3B82F6",[me.success]:"#22C55E",[me.error]:"#EF4444"},zo=-120,Tt=ii.OS==="android",Wo=({type:e})=>e===me.success?oe(Be,{style:Y.check_mark}):e===me.error?un(jo,{children:[oe(Be,{style:[Y.cross_bar,Y.cross_a]}),oe(Be,{style:[Y.cross_bar,Y.cross_b]})]}):un(jo,{children:[oe(Be,{style:Y.info_dot}),oe(Be,{style:Y.info_bar})]}),Ho=()=>{let e=V(Ze,h=>h.message),t=V(Ze,h=>h.type),n=V(Ze,h=>h.tick),o=lt(new J.Value(zo)).current,r=lt(new J.Value(0)).current,i=lt(new J.Value(.92)).current,a=lt(new J.Value(0)).current,[l,c]=qo(),[s,d]=qo(!1);Bo(()=>{let h=!0;return Gt().then(p=>{h&&p&&c(()=>p)}),()=>{h=!1}},[]);let m=lt(n);return Bo(()=>{if(n===m.current)return;ri.announceForAccessibility(e),d(!0),a.setValue(0),i.setValue(.92);let h=J.sequence([J.parallel([J.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),J.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),J.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),J.sequence([J.delay(90),J.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),J.delay(Gn[t]),J.parallel([J.timing(o,{toValue:zo,duration:240,useNativeDriver:!0}),J.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return h.start(({finished:p})=>{p&&d(!1)}),()=>h.stop()},[n]),s?oe(Be,{style:[Y.layer,{top:bt().top+(Tt?12:8)}],pointerEvents:"none",children:un(J.View,{style:[Y.toast,Tt&&Y.toast_android,!!l&&Y.toast_glass,{opacity:l?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[l&&oe(l,{style:Y.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),Tt?oe(J.View,{style:[Y.badge_halo,{backgroundColor:`${pn[t]}33`,transform:[{scale:a}]}],children:oe(Be,{style:[Y.badge,{backgroundColor:pn[t]}],children:oe(Wo,{type:t})})}):oe(J.View,{style:[Y.badge,{backgroundColor:pn[t],transform:[{scale:a}]}],children:oe(Wo,{type:t})}),oe(si,{style:[Y.message,Tt&&Y.message_android],numberOfLines:2,children:e})]})}):null},Y=$o.create({layer:{position:"absolute",left:16,right:16,alignItems:"center",zIndex:9999,elevation:9999},toast:{maxWidth:"100%",minHeight:50,flexDirection:"row",alignItems:"center",gap:10,paddingLeft:11,paddingRight:18,paddingVertical:11,borderRadius:25,backgroundColor:"#18181B",shadowColor:"#000000",shadowOpacity:.32,shadowRadius:18,shadowOffset:{width:0,height:8},elevation:12},toast_android:{width:"100%",minHeight:60,gap:12,paddingLeft:10,paddingRight:16,paddingVertical:10,borderRadius:20,borderWidth:$o.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var re=Te({active_key:null,instances:{}}),Jo=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var l;let a=(l=D().keep_alive)==null?void 0:l.max_webviews;re.setState(c=>{let s=t!=null?t:e.app_id,d={...c.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},m=Object.keys(d);return a&&a>0&&m.length>a&&m.filter(h=>h!==s).sort((h,p)=>d[h].last_used_at-d[p].last_used_at).slice(0,m.length-a).forEach(h=>{delete d[h]}),i?{active_key:s,instances:d}:{instances:d}})},ai=e=>Jo(e,!0),ci=e=>Jo(e,!1),pt=()=>re.setState({active_key:null}),Pt=e=>{re.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var Go="catalog",li="paused_apps",pi="removed_apps",ui=10*1e3,di=2,gi=3e3,mi=()=>{var e;try{return JSON.parse((e=D().storage.getString(Go))!=null?e:"{}")}catch{return{}}},O=Te({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),Ko=e=>{var t;return!!((t=D().manual_update)!=null&&t.includes(e))},kt=new Set,Yo=e=>{let t=new Set,n=()=>D().storage.setString(e,JSON.stringify([...t]));return{has:o=>t.has(o),values:()=>[...t],add:o=>t.has(o)?!1:(t.add(o),n(),!0),delete:o=>t.delete(o)?(n(),!0):!1,load:()=>{var o;t.clear();try{let r=JSON.parse((o=D().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},he=Yo(li),Ie=Yo(pi);xn(()=>{he.load(),Ie.load();let e=mi(),t={};Object.keys(e).filter(n=>!Ie.has(n)).forEach(n=>{let o=F(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:he.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),O.setState({catalog:e,downloads:t})});var gn=e=>V(O,t=>e?t.downloads[e]:void 0),fi=()=>V(O,e=>e.pause_reasons.length>0),fe=(...e)=>le("queue",...e),G=[],Ee={},T=null,Ct=new Set,qe={},dn=new Set,Oe=e=>{dn.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},hi=e=>(dn.add(e),()=>{dn.delete(e)}),yi=()=>O.getState().downloads,ie=(e,t)=>{let n=!!F(e),o=O.getState().downloads[e],r=t.status==="downloading"&&n?"updating":t.status,i={...o!=null?o:{status:"queued",progress:0},...t,...r?{status:r}:{},has_local:n};O.setState(a=>({downloads:{...a.downloads,[e]:i}})),(o==null?void 0:o.status)!==i.status||(o==null?void 0:o.version)!==i.version||(o==null?void 0:o.has_local)!==i.has_local?Oe({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Oe({type:"progress",app_id:e,progress:i.progress,version:i.version})},Ot=(e,t)=>{var n;(n=qe[e])==null||n.forEach(o=>o(t)),delete qe[e]},wi=()=>O.getState().pause_reasons.length>0,ke=e=>{var l;if(T)return;let t=e?G.indexOf(e):wi()?-1:G.findIndex(c=>!he.has(c));if(t<0||t>=G.length)return;let[n]=G.splice(t,1),o=O.getState().catalog[n];if(!o){Ot(n,F(n)),ke();return}let r=Date.now();Ee[n]=((l=Ee[n])!=null?l:0)+1,ie(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=sn(o,{onProgress:c=>{let s=Math.floor(c*100);s!==i&&(i=s,ie(n,{progress:s/100,version:o.version}))}});T={app_id:n,handle:a,forced:!!e},fe("start",n,o.version,e?"(forced)":""),a.promise.then(c=>{fe("installed",n,o.version,`${Date.now()-r}ms`),ie(n,{status:"installed",progress:1,version:o.version}),Ot(n,c)}).catch(c=>{var d;if(c instanceof We){if(Ct.has(n))return;fe("paused",n),Ee[n]-=1,G.unshift(n),ie(n,{status:he.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((d=c==null?void 0:c.message)!=null?d:c);if(console.warn("[miniapp-queue] failed",n,s),Ee[n]<di){ie(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var m;G.includes(n)||(T==null?void 0:T.app_id)===n||(G.push(n),ke((m=qe[n])!=null&&m.length?n:void 0))},gi);return}ie(n,{status:"failed",progress:0,version:o.version,error:s}),Ot(n,F(n))}).finally(()=>{T=null;let c=G.find(s=>{var d;return(d=qe[s])==null?void 0:d.length});ke(c)})},It=(e,{front:t=!1}={})=>{if((T==null?void 0:T.app_id)===e)return;let n=G.indexOf(e);if(n>=0){if(!t)return;G.splice(n,1)}t?G.unshift(e):G.push(e)},_i=async e=>{let{host_id:t,client_token:n}=D(),o=new AbortController,r=setTimeout(()=>o.abort(),ui);try{let i=`${Vt}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(c=>({...c,channel:e}))}finally{clearTimeout(r)}},ut=null,mn=()=>(ut!=null||(ut=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(D().channels.map(_i)),o={};[...n].reverse().flat().forEach(c=>{o[c.app_id]=c});let r=Object.keys(O.getState().catalog).filter(c=>!o[c]);D().storage.setString(Go,JSON.stringify(o)),O.setState({catalog:o}),await Promise.all(r.map(c=>Xo(c,{by_user:!1}))),r.forEach(c=>Ie.delete(c));let i=Object.keys(o).filter(c=>!Ie.has(c)),a=[],l={};for(let c of i.map(s=>o[s])){if(await rn(c)){ie(c.app_id,{status:"installed",progress:1,version:c.version});continue}let s=F(c.app_id);if(Ko(c.app_id)&&!kt.has(c.app_id)&&s&&await xe(s)){ie(c.app_id,{status:"installed",progress:1,version:s.version}),l[c.app_id]={app_id:c.app_id,current_version:s.version,next_version:c.version};continue}a.push(c)}return O.setState({updates:l}),a.forEach(c=>{Ee[c.app_id]=0,ie(c.app_id,{status:he.has(c.app_id)?"paused":"queued",progress:0,version:c.version,error:void 0}),It(c.app_id)}),fe("catalog",i.length,"apps, outdated",a.map(c=>c.app_id),"removed",r,`${Date.now()-e}ms`),Oe({type:"sync_complete",app_ids:i,removed:r}),Object.values(l).forEach(c=>Oe({type:"update_available",...c})),ke(),{ok:!0,app_ids:i,removed:r}}catch(n){let o=String((n==null?void 0:n.name)==="AbortError"?"timeout":(t=n==null?void 0:n.message)!=null?t:n);return console.warn("[miniapp-queue] sync catalog failed",o),Oe({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{ut=null}})()),ut),Xo=async(e,{by_user:t})=>{var r,i,a,l;if(t&&Ie.add(e),Ct.has(e))return;Ct.add(e),he.delete(e);let n=G.indexOf(e);n>=0&&G.splice(n,1),(T==null?void 0:T.app_id)===e&&T.handle.cancel();let o=(l=(a=(r=O.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=F(e))==null?void 0:i.version)!=null?l:"";ie(e,{status:"uninstalling",progress:0,version:o}),await Oo(e),Pt(e),O.setState(c=>{let s={...c.downloads};return delete s[e],{downloads:s}}),delete Ee[e],Ct.delete(e),Ot(e,null),fe("uninstalled",e,t?"(user)":"(not in list)"),Oe({type:"uninstalled",app_id:e})},bi=e=>Xo(e,{by_user:!0}),Ai=e=>{let t=dt(e);return t?(Ie.delete(e),(T==null?void 0:T.app_id)===e||G.includes(e)||(Ee[e]=0,ie(e,{status:he.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),It(e),ke(),fe("restore",e)),!0):!1},Si=e=>{if(he.has(e))return;if(he.add(e),fe("pause app",e),(T==null?void 0:T.app_id)===e&&!T.forced){T.handle.cancel();return}let t=O.getState().downloads[e];G.includes(e)&&t&&ie(e,{status:"paused",progress:0,version:t.version})},vi=e=>{if(!he.delete(e))return;fe("resume app",e);let t=O.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!G.includes(e)&&dt(e)&&(Ee[e]=0,It(e)),G.includes(e)&&t&&ie(e,{status:"queued",progress:0,version:t.version}),ke()},Mi=e=>{let{pause_reasons:t}=O.getState();t.includes(e)||(O.setState({pause_reasons:[...t,e]}),fe("pause",e),t.length===0&&Oe({type:"pause_change",paused:!0,reasons:[e]}),T&&!T.forced&&T.handle.cancel())},xi=e=>{let{pause_reasons:t}=O.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);O.setState({pause_reasons:n}),fe("resume",e),n.length===0&&Oe({type:"pause_change",paused:!1,reasons:n}),ke()},Zo=e=>O.getState().updates[e],Ei=async e=>{var n,o;let t=Zo(e);kt.add(e);try{let r=await Lt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=dt(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(O.setState(a=>{var c;let l={...a.updates};return delete l[e],{updates:l,apply_ticks:{...a.apply_ticks,[e]:((c=a.apply_ticks[e])!=null?c:0)+1}}}),fe("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{kt.delete(e)}},Ri=()=>Object.values(O.getState().catalog).map(e=>({...e,installed:!!F(e.app_id),removed_by_user:Ie.has(e.app_id)})),dt=e=>O.getState().catalog[e],Lt=async e=>{let t=dt(e);if(!t)return;if(he.delete(e),Ie.delete(e),await rn(t))return F(e);let n=F(e);if(Ko(e)&&!kt.has(e)&&n&&await xe(n))return n;let o=new Promise(r=>{var i;((i=qe[e])!=null?i:qe[e]=[]).push(r)});return(T==null?void 0:T.app_id)===e?T.forced=!0:(Ee[e]=0,It(e,{front:!0}),T&&!T.forced?T.handle.cancel():ke(e)),o};import{Fragment as _n,jsx as K,jsxs as He}from"react/jsx-runtime";var hn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),er=0,Ii=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},Li=bn.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:l,opaque_background:c,allow_embedded_miniapps:s,onWebLoadEnd:d})=>{var mt,Je;let m=ye(null),h=ye(!1),p=V(re,f=>f.instances[e]),y=p==null?void 0:p.app.app_id,E=p==null?void 0:p.app.manifest_url,v=p==null?void 0:p.context,M=p==null?void 0:p.url_params,A=V(H,f=>{var u;return((u=f.active)==null?void 0:u.owner)===e?f.active:null}),[_,W]=$e(()=>y?F(y):null),[Z,te]=$e(!1),[we,w]=$e(0),[S,q]=$e(0),[x,C]=$e(!1),k=ye(null),N=f=>{k.current&&clearTimeout(k.current),k.current=setTimeout(()=>{k.current=null,C(!0)},f)};se(()=>()=>{k.current&&clearTimeout(k.current)},[]),se(()=>{if(!y||!t&&_)return;let f=!0;return te(!1),(async()=>{let u=F(y),P=u?await xe(u):!1;if(!f||(W(P?ge=>!ge||ge.version!==u.version||ge.permissions.join(",")!==u.permissions.join(",")?u:ge:null),__DEV__&&Date.now()-er>1e4&&(er=Date.now(),await mn()),!f))return;let ee=await Lt(y),ae=ee!==void 0?ee:E?await Io(y,E):F(y);if(f){if(!ae){te(!0);return}W(ge=>ge!=null?ge:ae)}})(),()=>{f=!1}},[t,y,E,we]),se(()=>Lo(e,f=>m.current?(m.current.postMessage(f),!0):!1),[e]);let I=V(O,f=>{let u=y?f.downloads[y]:void 0;return(u==null?void 0:u.status)==="installed"?u.version:void 0});se(()=>{if(t||!y||!_)return;let f=F(y);if(!f||f.version===_.version)return;let u=!0;return xe(f).then(P=>{!u||!P||(le(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",_.version,"\u2192",f.version),W(f))}),()=>{u=!1}},[t,y,I,_==null?void 0:_.version]);let Q=V(O,f=>{var u;return y&&(u=f.apply_ticks[y])!=null?u:0});se(()=>{if(!Q||!y)return;let f=F(y);if(!f||f.version===(_==null?void 0:_.version))return;let u=!0;return xe(f).then(P=>{!u||!P||(le(`webview:${e}`,"c\u1EADp nh\u1EADt",_==null?void 0:_.version,"\u2192",f.version),C(!1),W(f))}),()=>{u=!1}},[Q]),se(()=>{var P;let f=(P=D().keep_alive)==null?void 0:P.idle_close_ms;if(t||!f||f<=0)return;let u=setTimeout(()=>{Pt(e)},f);return()=>clearTimeout(u)},[t,e]),se(()=>{r>0&&(te(!1),C(!1),q(f=>f+1),w(f=>f+1))},[r]);let Le=ye(t);se(()=>{var f;Le.current!==t&&(Le.current=t,h.current&&((f=m.current)==null||f.injectJavaScript(Ao(t?"resumed":"paused"))))},[t]);let de=`${(mt=_==null?void 0:_.version)!=null?mt:"none"}:${(Je=_==null?void 0:_.permissions.join(","))!=null?Je:""}:${S}`,ne=Ft(()=>JSON.stringify([v!=null?v:{},M!=null?M:{}]),[v,M]),Fe=Ft(()=>{var f;return Eo(M!=null?M:{},(f=_==null?void 0:_.permissions)!=null?f:[])},[ne,_==null?void 0:_.permissions]),be=Ft(()=>Mo(v!=null?v:{},Fe)+_o()+bo()+(D().debug?wo():""),[Fe]),Ae=ye(null),Se=ye(null);se(()=>{var u,P,ee;if(!_)return;if(Se.current!==de){Se.current=de,Ae.current=ne;return}if(Ae.current===ne)return;let f=((P=JSON.parse((u=Ae.current)!=null?u:"[]")[0])!=null?P:{}).org_id;if(Ae.current=ne,f===(v==null?void 0:v.org_id)&&h.current){C(!1),N(1500),(ee=m.current)==null||ee.injectJavaScript(So(v!=null?v:{},Fe));return}C(!1),q(ae=>ae+1)},[ne,_,de]),se(()=>(t||(ve(e),Pe(e),Ue(e)),()=>{ve(e),Pe(e),Ue(e)}),[t,e,de,r]),se(()=>{let f=Qo.addEventListener("change",u=>{u==="background"&&!Zn()&&ve(e),u==="background"&&!ro()&&Pe(e)});return()=>f.remove()},[e]);let Dt=yn(async f=>{var P,ee,ae,ge,Ut,Sn;let u=mo(f.nativeEvent.data);if(!u){if(y&&(l!=null&&l.onWebEvent))try{Promise.resolve(l.onWebEvent(f.nativeEvent.data,{app_id:y,instance_id:e})).catch(U=>{console.warn("[miniapp] onWebEvent l\u1ED7i",y,U)})}catch(U){console.warn("[miniapp] onWebEvent l\u1ED7i",y,U)}return}if(u.method==="log"){let{level:U,text:$}=u;le(`web:${e}`,U!=null?U:"log",$!=null?$:"");return}if(u.method==="pong"){k.current||C(!0);return}if(u.method==="touchAtTop"){i.emit(!!u.at_top);return}if(u.method==="contextApplied"){k.current&&clearTimeout(k.current),k.current=null,C(!0);return}if(u.method==="ready"){h.current=!0,C(!0);let U=(P=re.getState().instances[e])==null?void 0:P.context;U&&((ee=m.current)==null||ee.injectJavaScript(Zt(U)));return}try{let U=await To(u,{getHostData:()=>{var $,ce;return(ce=($=re.getState().instances[e])==null?void 0:$.host_data)!=null?ce:{}},getPermissions:()=>{var $,ce;return y?(ce=($=F(y))==null?void 0:$.permissions)!=null?ce:[]:[]},getContext:()=>{var $,ce;return(ce=($=re.getState().instances[e])==null?void 0:$.context)!=null?ce:{}},is_dark:o,close:pt,app_id:y!=null?y:"",instance_id:e,options:l,emit:($,ce)=>{var vn;(vn=m.current)==null||vn.injectJavaScript(yo($,ce))},playBeep:(ae=l==null?void 0:l.playScannerBeep)!=null?ae:(()=>{var $;($=m.current)==null||$.injectJavaScript(Ro())}),isActive:()=>re.getState().active_key===e&&Qo.currentState!=="background"});u.id&&((ge=m.current)==null||ge.injectJavaScript(fo(u.id,U)))}catch(U){if(!u.id)return;let $=U==null?void 0:U.code,ce=U instanceof g?U:new g(typeof $=="string"?$:"HOST_ERROR",String((Ut=U==null?void 0:U.message)!=null?Ut:U));(Sn=m.current)==null||Sn.injectJavaScript(ho(u.id,ce))}},[e,o,y,i,l]),Nt=yn(()=>{te(!1),q(f=>f+1),w(f=>f+1)},[]);return He(wn,{style:[An.absoluteFill,c&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&ue.behind],pointerEvents:t?"auto":"none",children:[(A==null?void 0:A.layout)===Me.top&&K(ln,{scanner:A}),_?K(ki,{ref:m,source:{uri:_.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?tn():_.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:be,onMessage:Dt,bounces:!1,overScrollMode:"never",onLoadStart:f=>{ve(e),Pe(e),Ue(e),le(`webview:${e}`,"load start",hn(f.nativeEvent.url)),h.current=!1,C(!1)},onError:f=>{ve(e),Pe(e),Ue(e),le(`webview:${e}`,"load error",hn(f.nativeEvent.url),f.nativeEvent.description),te(!0),C(!1)},onLoadEnd:f=>{let u=f.nativeEvent.url;le(`webview:${e}`,"load end",hn(u)),y&&(d==null||d({app_id:y,instance_id:e,url:u})),N(1500)},onContentProcessDidTerminate:()=>{ve(e),Pe(e),Ue(e),h.current=!1,C(!1),q(f=>f+1)},onRenderProcessGone:()=>(ve(e),Pe(e),Ue(e),h.current=!1,C(!1),q(f=>f+1),!0),style:ue.webview},de):null,(A==null?void 0:A.layout)===Me.full&&K(ln,{scanner:A}),p&&K(Di,{visible:!_||!x,interactive:Z,children:K(Fi,{splash:a,app:p.app,is_dark:o,error:Z,has_bundle:!!_,retry:Nt})})]})}),Fi=bn.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,l=gn(t.app_id),c=o?"error":!r&&(l==null?void 0:l.status)==="downloading"?"downloading":"loading";return K(a,{app:t,is_dark:n,status:c,progress:c==="downloading"?l==null?void 0:l.progress:void 0,retry:i})}),Di=({visible:e,interactive:t,children:n})=>{let o=ye(new fn.Value(e?1:0)).current,[r,i]=$e(e);return se(()=>{if(e){i(!0),o.setValue(1);return}let a=fn.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:l})=>{l&&i(!1)}),()=>a.stop()},[e,o]),r?K(fn.View,{style:[An.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},nr=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return He(wn,{style:[ue.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[K(wn,{style:[ue.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?K(Ci,{source:{uri:e.icon},style:ue.splash_icon_image}):K(gt,{style:ue.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),K(gt,{style:[ue.splash_name,{color:i}],children:e.name}),n==="error"?He(_n,{children:[K(gt,{style:ue.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),K(Oi,{activeOpacity:.7,style:[ue.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:K(gt,{style:[ue.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):He(_n,{children:[K(Ti,{style:ue.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&He(gt,{style:ue.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},tr=(e,t)=>{let n=ye(t),o=ye(!1);__DEV__&&!o.current&&n.current!==t&&(o.current=!0,console.warn(`[miniapp] MiniAppHost prop "${e}" \u0111\u1ED5i gi\u1EEFa c\xE1c l\u1EA7n render \u2192 m\u1ECDi WebView b\u1ECB mount l\u1EA1i. Khai b\xE1o component b\xEAn ngo\xE0i render.`))},Ni=({container:e,splash:t=nr,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:l})=>{tr("container",e),tr("splash",t);let c=e,s=V(re,A=>A.active_key),d=ye(s);s&&(d.current=s);let m=V(re,A=>Object.keys(A.instances).join("|")),h=V(re,A=>{var _;return A.active_key?(_=A.instances[A.active_key])==null?void 0:_.app.name:void 0}),p=Ft(()=>m?m.split("|"):[],[m]),[y,E]=$e({}),v=ye(Ii()).current;se(()=>{if(!s||!r)return;let A=Pi.addEventListener("hardwareBackPress",()=>(pt(),!0));return()=>A.remove()},[s,r]);let M=yn(()=>{let A=re.getState().active_key;A&&E(_=>({..._,[A]:(_[A]||0)+1}))},[]);return p.length?He(_n,{children:[K(c,{visible:!!s,title:h!=null?h:"",is_dark:n,close:pt,reload:M,subscribeWebAtTop:v.subscribe,children:p.map(A=>K(Li,{instance_key:A,is_active:s===A,is_front:(s!=null?s:d.current)===A,is_dark:n,reload_tick:y[A]||0,web_at_top:v,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:l},A))}),K(Ho,{})]}):null},ue=An.create({webview:{flex:1,backgroundColor:"transparent"},behind:{zIndex:-1},splash:{flex:1,alignItems:"center",justifyContent:"center",gap:12},splash_icon:{width:72,height:72,borderRadius:20,alignItems:"center",justifyContent:"center",overflow:"hidden"},splash_icon_image:{width:72,height:72},splash_letter:{fontSize:28,fontWeight:"700",color:"#1D4ED8"},splash_name:{fontSize:16,fontWeight:"600"},splash_hint:{color:"#71717A"},splash_spinner:{marginTop:8},retry_button:{marginTop:4,paddingHorizontal:20,paddingVertical:10,borderRadius:999},retry_text:{fontWeight:"600"}}),Ui=bn.memo(Ni);export{X as CodeType,nr as DefaultMiniAppSplash,Vt as MINIAPP_PLATFORM_URL,Ui as MiniAppHost,g as MiniAppHostError,ze as ScannerEndReason,jt as ScannerEvent,Me as ScannerLayout,et as ScannerMethod,me as ToastType,pt as closeMiniApp,or as configureMiniApp,ir as createMmkvStorage,En as createReactNativeBiometrics,rr as createRnfsFileSystem,Lt as ensureMiniApp,F as getLocalMiniApp,Ri as getMiniAppCatalog,dt as getMiniAppCatalogEntry,yi as getMiniAppStatuses,Zo as getMiniAppUpdate,$r as installBundledMiniApp,hi as onMiniAppEvent,ai as openMiniApp,Si as pauseMiniApp,Mi as pauseMiniAppDownloads,ci as preloadMiniApp,ve as releaseSpeechFor,Ai as restoreMiniApp,vi as resumeMiniApp,xi as resumeMiniAppDownloads,Wr as sendEventToWeb,mn as syncMiniAppCatalog,bi as uninstallMiniApp,Ei as updateMiniApp,$n as uploadToUrl,gn as useMiniAppDownload,fi as useMiniAppDownloadsPaused};
|
|
88
|
+
})(); true;`,Gr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Pt=(e,t)=>{if(typeof e!="string"||!e)throw new m("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},Uo=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:c,instance_id:l,options:s,emit:g,isActive:d,playBeep:h})=>{var v,A,O,U,Z,xe,re;let u=s==null?void 0:s.handlers,y={app_id:c,instance_id:l,close:a},T=()=>{var p;(p=s==null?void 0:s.haptic)==null||p.call(s,"impactLight"),h==null||h()},M=()=>new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let p=Fn(t);return st(e,()=>Dn(p,d))}case"speech.start":{if(!g)throw M();let p={};if((t==null?void 0:t.lang)!==void 0){if(typeof t.lang!="string"||!/^[a-zA-Z]{2,8}(-[a-zA-Z0-9]{1,8})*$/.test(t.lang))throw new m("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");p.lang=t.lang}for(let L of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[L])!==void 0){if(typeof t[L]!="boolean")throw new m("INVALID_PARAMS",`${L} ph\u1EA3i l\xE0 boolean`);p[L]=t[L]}let S=s==null?void 0:s.speech;if(S){so(l,S);try{return await S.start({owner:l,app_id:c,options:p,emit:g,isActive:d!=null?d:(()=>!0)})}catch(L){throw ao(l),L}}return lo(l,p,g,d)}case"speech.stop":return s!=null&&s.speech?s.speech.stop(l):po(l);case it.scan:return wo(l,Qt(t),d,T);case it.start:{if(!g)throw M();return bo(l,Qt(t),g,d,T)}case it.stop:return _o(l);case"uploadFiles":{let{task_id:p,...S}=t!=null?t:{};if(p!==void 0&&(typeof p!="string"||!p))throw new m("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return to(jn(S),{instance_id:l,app_id:c,getContext:r,task_id:p,config:s==null?void 0:s.upload,emit:g,exclusivePick:L=>st("uploadFiles.pick",L)})}case"uploadFiles.cancel":eo(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Zn(s==null?void 0:s.upload);case"getBiometricAvailability":return((v=s==null?void 0:s.biometrics)!=null?v:await Jt()).getAvailability();case"authenticateBiometric":{let p=Pt(t==null?void 0:t.reason,"reason").trim();if(!p||p.length>200)throw new m("INVALID_PARAMS","reason must contain 1\u2013200 characters");let S=t==null?void 0:t.cancelButtonText;if(S!==void 0&&(typeof S!="string"||!S.trim()||S.length>80))throw new m("INVALID_PARAMS","Invalid cancelButtonText");return st(e,async()=>{var x;return((x=s==null?void 0:s.biometrics)!=null?x:await Jt()).authenticate({reason:p,cancelButtonText:S})})}case"requestPayment":{let p=u==null?void 0:u.requestPayment;if(!p)throw M();let S=t==null?void 0:t.amount;if(typeof S!="number"||!Number.isFinite(S)||S<=0)throw new m("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let L={...t,amount:S,currency:Pt(t==null?void 0:t.currency,"currency")};return st(e,()=>p(L,y))}case"printImage":{let p=u==null?void 0:u.printImage;if(!p)throw M();let S=Pt(t==null?void 0:t.image,"image");await st(e,()=>p({image:S},y));return}case"openScreen":if(!(u!=null&&u.openScreen))throw M();await u.openScreen({screen:Pt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},y);return;case"closeApp":a();return;case"openWebview":{let p=String((A=t==null?void 0:t.url)!=null?A:"");if(!/^https?:\/\//i.test(p))throw new m("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(p):vo.openURL(p));return}case"openLink":{let p=String((O=t==null?void 0:t.url)!=null?O:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(p)||/^(javascript|file|data|about|blob):/i.test(p))throw new m("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(p):vo.openURL(p))}catch(S){throw new m("NOT_SUPPORTED",String((Z=(U=S==null?void 0:S.message)!=null?U:S)!=null?Z:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let p=oo(t);if(!p||(d==null?void 0:d())===!1)return;s!=null&&s.showToast?s.showToast(p.message,{type:p.type}):ro(p.message,p.type);return}case"haptic":{let p=Gr.has(t==null?void 0:t.type)?t.type:"selection";(xe=s==null?void 0:s.haptic)==null||xe.call(s,p);return}case"getSystemInfo":return{platform:Jr.OS==="ios"?"ios":"android",appVersion:(re=s==null?void 0:s.app_version)!=null?re:"",theme:i?"dark":"light"};case"getAccessToken":{let p=n().access_token;if(!p)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return p}case"getToken":{let p=t==null?void 0:t.type;if(p==="access"){let x=n().access_token;if(!x)throw new m("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return x}if(p!=="partner"&&p!=="chatbox")throw new m("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(p)}`);let S=Fo[p];if(!o().includes(S))throw new m("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${S} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let L=p==="partner"?n().partner_token:n().chatbox_token;if(!L)throw new m("HOST_ERROR",`Kh\xF4ng c\xF3 ${S}`);return L}case"getUserInfo":{let p=n().user;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return p}case"getPageInfo":{let p=n().page;if(!p)throw new m("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return p}case"sendMessage":case"insertText":throw new m("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new m("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var ln=e=>`bundle:${e}`,pn=()=>`${D().file_system.document_dir}/miniapps`,un=pn,dn=(e,t,n="index.html",o=!1,r=[])=>{let i=`${un()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},cn=e=>{var t;D().storage.setString(ln(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},Kr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,F=e=>{let t=D().storage.getString(ln(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return dn(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Pe=e=>D().file_system.exists(e.entry_uri.replace("file://","")),gn=async e=>{let t=F(e.app_id);return(t==null?void 0:t.version)===e.version&&await Pe(t)},Bo=async(e,t)=>{let n=D().file_system,o=`${un()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},qo=async e=>{var t;await((t=lt[e])==null?void 0:t.catch(()=>{})),D().storage.setString(ln(e),""),await D().file_system.remove(`${un()}/${e}`).catch(()=>{})},He=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},lt={},$o=(e,t)=>{var i;let o=((i=lt[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return lt[e]=r,r.then(()=>{lt[e]===r&&delete lt[e]}),o},Yr=(e,t)=>{var r,i;let n=e.split(".").map(a=>parseInt(a,10)||0),o=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,o.length);a++){let c=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(c)return c}return 0},Xr=({manifest:e,zip_path:t})=>$o(e.app_id,async()=>{var i;let n=D().file_system,o=F(e.app_id);if(o&&Yr(o.version,e.version)>=0&&await Pe(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=dn(e.app_id,e.version,e.entry,!!e.context_update,(i=e.permissions)!=null?i:[]);return await n.remove(r.dir).catch(()=>{}),await n.mkdir(r.dir),await n.unzip(t,r.dir),cn(e),ue("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),Bo(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),mn=(e,{base_url:t,onProgress:n}={})=>{let o=D().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,c=()=>{if(i)throw new He},l=async()=>{var d;c();let s=F(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return cn(e),F(e.app_id);c();let g=o.download({url:t?Kr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(h,u)=>{var T;let y=u>0?u:(T=e.size)!=null?T:0;y>0&&(n==null||n(Math.min(1,h/y)))}});r=g;try{let{status:h}=await g.promise;if(c(),h!==200)throw new Error(`bundle ${h}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else ue("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let u=dn(e.app_id,e.version,e.entry,!!e.context_update,(d=e.permissions)!=null?d:[]);return await o.remove(u.dir).catch(()=>{}),await o.mkdir(u.dir),await o.unzip(a,u.dir),cn(e),Bo(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),u}catch(h){throw i?new He:h}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:$o(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},ct={},Zr=__DEV__?0:60*1e3,Vo={},zo=(e,t)=>{var o,r;let n=F(e);return n&&Date.now()-((o=Vo[t])!=null?o:0)<Zr?Promise.resolve(n):((r=ct[e])!=null||(ct[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),c=await mn(a,{base_url:t}).promise;return Vo[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),F(e))).finally(()=>{ct[e]=void 0})),ct[e])};var Ct=new Map,Wo=(e,t)=>(Ct.set(e,t),()=>{Ct.get(e)===t&&Ct.delete(e)}),Qr=(e,t)=>{let n=Ct.get(e);return n?n(t):!1};import{useCallback as jo,useEffect as Je,useRef as Me,useState as Ot}from"react";import{Animated as N,BackHandler as ei,Dimensions as ti,Easing as kt,Pressable as ni,StyleSheet as hn,Text as pt,View as z}from"react-native";import{Fragment as gi,jsx as E,jsxs as ve}from"react/jsx-runtime";var ut="#22C55E",oi="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",ri=2,Lt=18,ii=1600,dt=14,si=2e3,Go=.38,ai=40,Ho=2,ci=8,li=2e3,pi=250,Ge=2e3,ui=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:dt},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:dt},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:dt},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:dt}],Jo=({color:e})=>E(gi,{children:ui.map((t,n)=>E(z,{style:[_.corner,t,{borderColor:e}]},n))}),It=({style:e,children:t,...n})=>{let o=Me(new N.Value(1)).current,r=i=>N.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return E(ni,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:E(N.View,{style:[e,{transform:[{scale:o}]}],children:t})})},yn=({scanner:e,closing:t=!1,onClosed:n,onHeight:o})=>{var f,b;let{vision:r,types:i,mode:a,layout:c,hint:l,glass_view:s,absolute:g}=e,d=c===ge.top,h=Me(new N.Value(0)).current,u=r.useCameraDevice("back"),y=Me(new N.Value(1)).current,[T,M]=Ot(!1),[v,A]=Ot(1),O=Me(null),[U,Z]=Ot(()=>{let{width:w,height:k}=ti.get("window");return{width:w,height:d?k*Go:k,window_y:0}}),xe=B(H,w=>w.last_value),re=B(H,w=>w.hit_tick),p=B(H,w=>w.scan_count),S=B(H,w=>w.notice),L=B(H,w=>w.is_picking),x=Me(null),ie=Et(),fe=ie.top,W=Me(new N.Value(0)).current,P=Me(new N.Value(0)).current,Q=Me(new N.Value(0)).current,q=Me(n);q.current=n,Je(()=>{if(!t)return;h.setValue(U.height);let w=N.timing(h,{toValue:0,duration:pi,easing:kt.out(kt.cubic),useNativeDriver:!1});return w.start(({finished:k})=>{var te;k&&((te=q.current)==null||te.call(q))}),()=>w.stop()},[t,h]);let Y=Math.round(U.width*(d?.8:.78)),ee=Math.round(d?U.height*.46:Y*.78),_e=Math.round((U.height-ee)/2),Ae=Math.round((U.width-Y)/2),We=r.useCodeScanner({codeTypes:i,onCodeScanned:jo(w=>on(w),[])});Je(()=>{let w=ei.addEventListener("hardwareBackPress",()=>(nn(),!0));return()=>w.remove()},[]);let Se=Me(re);Je(()=>{if(re===Se.current)return;W.setValue(1),Q.setValue(1);let w=N.parallel([N.timing(W,{toValue:0,duration:450,useNativeDriver:!0}),N.sequence([N.delay(si),N.timing(Q,{toValue:0,duration:250,useNativeDriver:!0})])]);return w.start(),()=>w.stop()},[re,W,Q]),Je(()=>{let w=te=>N.timing(P,{toValue:te,duration:ii,easing:kt.inOut(kt.quad),useNativeDriver:!0}),k=N.loop(N.sequence([w(1),w(0)]));return k.start(),()=>k.stop()},[P]);let Ee=jo(()=>{N.timing(y,{toValue:0,duration:220,useNativeDriver:!0}).start()},[y]);Je(()=>{let w=setTimeout(Ee,li);return()=>clearTimeout(w)},[Ee]);let[Ye,zt]=Ot(!1);Je(()=>{let w=requestAnimationFrame(()=>{w=requestAnimationFrame(()=>zt(!0))});return()=>cancelAnimationFrame(w)},[]);let Ue=!!(u!=null&&u.hasTorch),Xe=(f=u==null?void 0:u.neutralZoom)!=null?f:1,Ze=u?Math.min(u.maxZoom/Xe,ci):1,Wt=Xe*Math.min(v,Ze),wt=w=>{var ne;let{touches:k}=w.nativeEvent;if(k.length!==2){O.current=null;return}let te=Math.hypot(k[0].pageX-k[1].pageX,k[0].pageY-k[1].pageY);(ne=O.current)!=null||(O.current={distance:te,level:v}),A(Math.max(1,Math.min(Ze,O.current.level*(te/O.current.distance))))},bt=E(pt,{style:[_.hint,!!S&&_.hint_notice],numberOfLines:1,children:(b=S!=null?S:l)!=null?b:oi});return E(N.View,{ref:x,onTouchMove:wt,onTouchEnd:()=>{O.current=null},pointerEvents:t?"none":"auto",style:d?[_.top,g&&_.top_absolute,t&&{height:h}]:_.full,onLayout:({nativeEvent:{layout:w}})=>{var k;t||(o==null||o(w.height),(k=x.current)==null||k.measureInWindow((te,ne)=>{Z({width:w.width,height:w.height,window_y:ne||0})}))},children:ve(z,{style:t?[_.content_closing,{height:U.height}]:_.content,children:[u&&Ye&&E(r.Camera,{style:hn.absoluteFill,device:u,isActive:!L,codeScanner:We,torch:T&&Ue?"on":"off",zoom:Wt,onPreviewStarted:Ee,onError:w=>Ao(w.message)}),E(N.View,{style:[_.preview_cover,{opacity:y}],pointerEvents:"none"}),U.height>0&&ve(z,{style:_.overlay,pointerEvents:"none",children:[E(z,{style:[_.dim_ring,{top:_e-Ge,left:Ae-Ge,width:Y+Ge*2,height:ee+Ge*2}]}),ve(z,{style:{position:"absolute",top:_e,left:Ae,width:Y,height:ee},children:[E(Jo,{color:"#FFFFFF"}),E(N.View,{style:[hn.absoluteFill,{opacity:W}],children:E(Jo,{color:ut})}),ve(N.View,{style:[_.scan_line_wrap,{transform:[{translateY:P.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,ee-Lt)]})}]}],children:[E(z,{style:_.scan_glow_outer}),E(z,{style:_.scan_glow_inner}),E(z,{style:_.scan_line})]})]}),E(z,{style:[_.hint_slot,d?{top:0,height:_e-6,justifyContent:"flex-end"}:{top:_e+ee+20}],children:bt}),a===Ie.continuous&&!!xe&&E(N.View,{style:[_.result_slot,{top:d?_e+ee-ai:_e+ee+52},{opacity:Q}],children:ve(z,{style:_.result,children:[E(z,{style:_.check_badge,children:E(z,{style:_.check_mark})}),E(pt,{style:_.result_text,numberOfLines:1,children:xe}),ve(pt,{style:_.result_count,children:["\xB7 ",p," m\xE3"]})]})})]}),U.height>0&&E(z,{style:[_.close_slot,d?_.close_slot_top:{top:Math.max(12,fe-U.window_y+12)}],children:ve(It,{style:[_.close_button,!!s&&_.glass_surface],onPress:nn,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[s&&E(s,{style:_.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),E(z,{style:[_.close_bar,_.close_bar_a]}),E(z,{style:[_.close_bar,_.close_bar_b]})]})}),E(z,{style:[_.toolbar_wrap,!d&&{bottom:ie.bottom+20}],pointerEvents:"box-none",children:ve(z,{style:[_.toolbar,!!s&&_.glass_surface],children:[s&&E(s,{style:_.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),E(It,{style:_.tool,onPress:So,disabled:L,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:ve(z,{style:_.image_icon,children:[E(z,{style:_.image_icon_dot}),E(z,{style:_.image_icon_hill})]})}),!!u&&Ze>=Ho&&E(It,{style:[_.tool,v>1&&_.tool_on],onPress:()=>A(w=>w>1?1:Ho),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:ve(pt,{style:[_.zoom_text,v>1&&_.zoom_text_on],children:[Math.round(v*10)/10,"x"]})}),Ue&&E(It,{style:[_.tool,T&&_.tool_on],onPress:()=>M(w=>!w),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:T},children:E(pt,{style:[_.torch_icon,T&&_.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})})},di="rgba(0,0,0,0.5)",fn=50,_=hn.create({top:{height:`${Go*100}%`,overflow:"hidden",backgroundColor:"#000000"},full:{position:"absolute",top:0,left:0,right:0,bottom:0},content:{flex:1,backgroundColor:"#000000"},top_absolute:{position:"absolute",top:0,left:0,right:0,zIndex:1},content_closing:{position:"absolute",left:0,right:0,bottom:0,backgroundColor:"#000000"},preview_cover:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"#000000"},overlay:{position:"absolute",top:0,left:0,right:0,bottom:0,overflow:"hidden"},dim_ring:{position:"absolute",borderWidth:Ge,borderColor:di,borderRadius:Ge+dt},hint_slot:{position:"absolute",left:16,right:16,alignItems:"center"},hint:{color:"#FFFFFF",fontSize:14,fontWeight:"500"},hint_notice:{color:"#FCA5A5"},corner:{position:"absolute",width:28,height:28},scan_line_wrap:{position:"absolute",top:0,left:10,right:10,height:Lt,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:Lt,borderRadius:Lt/2,backgroundColor:ut,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:ut,opacity:.2},scan_line:{height:ri,borderRadius:1,backgroundColor:ut},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_slot_top:{bottom:15},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:fn,height:fn,borderRadius:fn/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result:{maxWidth:"100%",flexDirection:"row",alignItems:"center",gap:6,paddingHorizontal:12,paddingVertical:6,borderRadius:999,backgroundColor:"rgba(39,39,42,0.9)"},check_badge:{width:18,height:18,borderRadius:9,alignItems:"center",justifyContent:"center",backgroundColor:ut},check_mark:{width:5,height:9,marginTop:-2,borderRightWidth:2,borderBottomWidth:2,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_text:{flexShrink:1,color:"#FFFFFF",fontWeight:"600",fontSize:13},result_count:{color:"#A1A1AA",fontSize:13}});import{useEffect as Ko,useRef as gt,useState as Yo}from"react";import{AccessibilityInfo as mi,Animated as J,Platform as fi,StyleSheet as Xo,Text as hi,View as $e}from"react-native";import{Fragment as er,jsx as se,jsxs as bn}from"react/jsx-runtime";var wn={[he.info]:"#3B82F6",[he.success]:"#22C55E",[he.error]:"#EF4444"},Zo=-120,Ft=fi.OS==="android",Qo=({type:e})=>e===he.success?se($e,{style:X.check_mark}):e===he.error?bn(er,{children:[se($e,{style:[X.cross_bar,X.cross_a]}),se($e,{style:[X.cross_bar,X.cross_b]})]}):bn(er,{children:[se($e,{style:X.info_dot}),se($e,{style:X.info_bar})]}),tr=()=>{let e=B(ot,h=>h.message),t=B(ot,h=>h.type),n=B(ot,h=>h.tick),o=gt(new J.Value(Zo)).current,r=gt(new J.Value(0)).current,i=gt(new J.Value(.92)).current,a=gt(new J.Value(0)).current,[c,l]=Yo(),[s,g]=Yo(!1);Ko(()=>{let h=!0;return tn().then(u=>{h&&u&&l(()=>u)}),()=>{h=!1}},[]);let d=gt(n);return Ko(()=>{if(n===d.current)return;mi.announceForAccessibility(e),g(!0),a.setValue(0),i.setValue(.92);let h=J.sequence([J.parallel([J.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),J.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),J.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),J.sequence([J.delay(90),J.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),J.delay(no[t]),J.parallel([J.timing(o,{toValue:Zo,duration:240,useNativeDriver:!0}),J.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return h.start(({finished:u})=>{u&&g(!1)}),()=>h.stop()},[n]),s?se($e,{style:[X.layer,{top:Et().top+(Ft?12:8)}],pointerEvents:"none",children:bn(J.View,{style:[X.toast,Ft&&X.toast_android,!!c&&X.toast_glass,{opacity:c?1:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[c&&se(c,{style:X.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),Ft?se(J.View,{style:[X.badge_halo,{backgroundColor:`${wn[t]}33`,transform:[{scale:a}]}],children:se($e,{style:[X.badge,{backgroundColor:wn[t]}],children:se(Qo,{type:t})})}):se(J.View,{style:[X.badge,{backgroundColor:wn[t],transform:[{scale:a}]}],children:se(Qo,{type:t})}),se(hi,{style:[X.message,Ft&&X.message_android],numberOfLines:2,children:e})]})}):null},X=Xo.create({layer:{position:"absolute",left:16,right:16,alignItems:"center",zIndex:9999,elevation:9999},toast:{maxWidth:"100%",minHeight:50,flexDirection:"row",alignItems:"center",gap:10,paddingLeft:11,paddingRight:18,paddingVertical:11,borderRadius:25,backgroundColor:"#18181B",shadowColor:"#000000",shadowOpacity:.32,shadowRadius:18,shadowOffset:{width:0,height:8},elevation:12},toast_android:{width:"100%",minHeight:60,gap:12,paddingLeft:10,paddingRight:16,paddingVertical:10,borderRadius:20,borderWidth:Xo.hairlineWidth,borderColor:"rgba(255,255,255,0.16)",backgroundColor:"#232327",elevation:16},toast_glass:{backgroundColor:"transparent"},badge_halo:{width:40,height:40,borderRadius:20,alignItems:"center",justifyContent:"center"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},message_android:{fontSize:14,fontWeight:"500",letterSpacing:.1,color:"#F4F4F5"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ae=ke({active_key:null,instances:{}}),nr=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=D().keep_alive)==null?void 0:c.max_webviews;ae.setState(l=>{let s=t!=null?t:e.app_id,g={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},d=Object.keys(g);return a&&a>0&&d.length>a&&d.filter(h=>h!==s).sort((h,u)=>g[h].last_used_at-g[u].last_used_at).slice(0,d.length-a).forEach(h=>{delete g[h]}),i?{active_key:s,instances:g}:{instances:g}})},yi=e=>nr(e,!0),wi=e=>nr(e,!1),mt=()=>ae.setState({active_key:null}),Dt=e=>{ae.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var or="catalog",bi="paused_apps",_i="removed_apps",Ai=10*1e3,Si=2,vi=3e3,Mi=()=>{var e;try{return JSON.parse((e=D().storage.getString(or))!=null?e:"{}")}catch{return{}}},C=ke({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),rr=e=>{var t;return!!((t=D().manual_update)!=null&&t.includes(e))},Vt=new Set,ir=e=>{let t=new Set,n=()=>D().storage.setString(e,JSON.stringify([...t]));return{has:o=>t.has(o),values:()=>[...t],add:o=>t.has(o)?!1:(t.add(o),n(),!0),delete:o=>t.delete(o)?(n(),!0):!1,load:()=>{var o;t.clear();try{let r=JSON.parse((o=D().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},we=ir(bi),Ne=ir(_i);In(()=>{we.load(),Ne.load();let e=Mi(),t={};Object.keys(e).filter(n=>!Ne.has(n)).forEach(n=>{let o=F(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:we.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),C.setState({catalog:e,downloads:t})});var An=e=>B(C,t=>e?t.downloads[e]:void 0),xi=()=>B(C,e=>e.pause_reasons.length>0),ye=(...e)=>ue("queue",...e),G=[],Te={},R=null,Nt=new Set,ze={},_n=new Set,Fe=e=>{_n.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Ei=e=>(_n.add(e),()=>{_n.delete(e)}),Ri=()=>C.getState().downloads,ce=(e,t)=>{let n=!!F(e),o=C.getState().downloads[e],r=t.status==="downloading"&&n?"updating":t.status,i={...o!=null?o:{status:"queued",progress:0},...t,...r?{status:r}:{},has_local:n};C.setState(a=>({downloads:{...a.downloads,[e]:i}})),(o==null?void 0:o.status)!==i.status||(o==null?void 0:o.version)!==i.version||(o==null?void 0:o.has_local)!==i.has_local?Fe({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Fe({type:"progress",app_id:e,progress:i.progress,version:i.version})},Ut=(e,t)=>{var n;(n=ze[e])==null||n.forEach(o=>o(t)),delete ze[e]},Pi=()=>C.getState().pause_reasons.length>0,De=e=>{var c;if(R)return;let t=e?G.indexOf(e):Pi()?-1:G.findIndex(l=>!we.has(l));if(t<0||t>=G.length)return;let[n]=G.splice(t,1),o=C.getState().catalog[n];if(!o){Ut(n,F(n)),De();return}let r=Date.now();Te[n]=((c=Te[n])!=null?c:0)+1,ce(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=mn(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,ce(n,{progress:s/100,version:o.version}))}});R={app_id:n,handle:a,forced:!!e},ye("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{ye("installed",n,o.version,`${Date.now()-r}ms`),ce(n,{status:"installed",progress:1,version:o.version}),Ut(n,l)}).catch(l=>{var g;if(l instanceof He){if(Nt.has(n))return;ye("paused",n),Te[n]-=1,G.unshift(n),ce(n,{status:we.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((g=l==null?void 0:l.message)!=null?g:l);if(console.warn("[miniapp-queue] failed",n,s),Te[n]<Si){ce(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var d;G.includes(n)||(R==null?void 0:R.app_id)===n||(G.push(n),De((d=ze[n])!=null&&d.length?n:void 0))},vi);return}ce(n,{status:"failed",progress:0,version:o.version,error:s}),Ut(n,F(n))}).finally(()=>{R=null;let l=G.find(s=>{var g;return(g=ze[s])==null?void 0:g.length});De(l)})},Bt=(e,{front:t=!1}={})=>{if((R==null?void 0:R.app_id)===e)return;let n=G.indexOf(e);if(n>=0){if(!t)return;G.splice(n,1)}t?G.unshift(e):G.push(e)},Ti=async e=>{let{host_id:t,client_token:n}=D(),o=new AbortController,r=setTimeout(()=>o.abort(),Ai);try{let i=`${Ht}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(l=>({...l,channel:e}))}finally{clearTimeout(r)}},ft=null,Sn=()=>(ft!=null||(ft=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(D().channels.map(Ti)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(C.getState().catalog).filter(l=>!o[l]);D().storage.setString(or,JSON.stringify(o)),C.setState({catalog:o}),await Promise.all(r.map(l=>sr(l,{by_user:!1}))),r.forEach(l=>Ne.delete(l));let i=Object.keys(o).filter(l=>!Ne.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await gn(l)){ce(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=F(l.app_id);if(rr(l.app_id)&&!Vt.has(l.app_id)&&s&&await Pe(s)){ce(l.app_id,{status:"installed",progress:1,version:s.version}),c[l.app_id]={app_id:l.app_id,current_version:s.version,next_version:l.version};continue}a.push(l)}return C.setState({updates:c}),a.forEach(l=>{Te[l.app_id]=0,ce(l.app_id,{status:we.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),Bt(l.app_id)}),ye("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),Fe({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>Fe({type:"update_available",...l})),De(),{ok:!0,app_ids:i,removed:r}}catch(n){let o=String((n==null?void 0:n.name)==="AbortError"?"timeout":(t=n==null?void 0:n.message)!=null?t:n);return console.warn("[miniapp-queue] sync catalog failed",o),Fe({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{ft=null}})()),ft),sr=async(e,{by_user:t})=>{var r,i,a,c;if(t&&Ne.add(e),Nt.has(e))return;Nt.add(e),we.delete(e);let n=G.indexOf(e);n>=0&&G.splice(n,1),(R==null?void 0:R.app_id)===e&&R.handle.cancel();let o=(c=(a=(r=C.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=F(e))==null?void 0:i.version)!=null?c:"";ce(e,{status:"uninstalling",progress:0,version:o}),await qo(e),Dt(e),C.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete Te[e],Nt.delete(e),Ut(e,null),ye("uninstalled",e,t?"(user)":"(not in list)"),Fe({type:"uninstalled",app_id:e})},Ci=e=>sr(e,{by_user:!0}),Oi=e=>{let t=ht(e);return t?(Ne.delete(e),(R==null?void 0:R.app_id)===e||G.includes(e)||(Te[e]=0,ce(e,{status:we.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Bt(e),De(),ye("restore",e)),!0):!1},ki=e=>{if(we.has(e))return;if(we.add(e),ye("pause app",e),(R==null?void 0:R.app_id)===e&&!R.forced){R.handle.cancel();return}let t=C.getState().downloads[e];G.includes(e)&&t&&ce(e,{status:"paused",progress:0,version:t.version})},Ii=e=>{if(!we.delete(e))return;ye("resume app",e);let t=C.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!G.includes(e)&&ht(e)&&(Te[e]=0,Bt(e)),G.includes(e)&&t&&ce(e,{status:"queued",progress:0,version:t.version}),De()},Li=e=>{let{pause_reasons:t}=C.getState();t.includes(e)||(C.setState({pause_reasons:[...t,e]}),ye("pause",e),t.length===0&&Fe({type:"pause_change",paused:!0,reasons:[e]}),R&&!R.forced&&R.handle.cancel())},Fi=e=>{let{pause_reasons:t}=C.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);C.setState({pause_reasons:n}),ye("resume",e),n.length===0&&Fe({type:"pause_change",paused:!1,reasons:n}),De()},ar=e=>C.getState().updates[e],Di=async e=>{var n,o;let t=ar(e);Vt.add(e);try{let r=await qt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=ht(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(C.setState(a=>{var l;let c={...a.updates};return delete c[e],{updates:c,apply_ticks:{...a.apply_ticks,[e]:((l=a.apply_ticks[e])!=null?l:0)+1}}}),ye("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Vt.delete(e)}},Ni=()=>Object.values(C.getState().catalog).map(e=>({...e,installed:!!F(e.app_id),removed_by_user:Ne.has(e.app_id)})),ht=e=>C.getState().catalog[e],qt=async e=>{let t=ht(e);if(!t)return;if(we.delete(e),Ne.delete(e),await gn(t))return F(e);let n=F(e);if(rr(e)&&!Vt.has(e)&&n&&await Pe(n))return n;let o=new Promise(r=>{var i;((i=ze[e])!=null?i:ze[e]=[]).push(r)});return(R==null?void 0:R.app_id)===e?R.forced=!0:(Te[e]=0,Bt(e,{front:!0}),R&&!R.forced?R.handle.cancel():De(e)),o};import{Fragment as Rn,jsx as K,jsxs as Ke}from"react/jsx-runtime";var Mn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),lr=0,zi=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},Wi=Pn.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:c,opaque_background:l,allow_embedded_miniapps:s,onWebLoadEnd:g})=>{var wt,bt;let d=be(null),h=be(!1),u=B(ae,f=>f.instances[e]),y=u==null?void 0:u.app.app_id,T=u==null?void 0:u.app.manifest_url,M=u==null?void 0:u.context,v=u==null?void 0:u.url_params,A=B(H,f=>{var b;return((b=f.active)==null?void 0:b.owner)===e?f.active:null}),[O,U]=Ce(null),[Z,xe]=Ce(A);A!==Z&&(xe(A),A?U(null):(Z==null?void 0:Z.layout)===ge.top&&U(Z));let re=(A==null?void 0:A.layout)===ge.top?A:O,[p,S]=Ce(()=>y?F(y):null),[L,x]=Ce(!1),[ie,fe]=Ce(0),[W,P]=Ce(0),[Q,q]=Ce(!1),Y=be(null),ee=f=>{Y.current&&clearTimeout(Y.current),Y.current=setTimeout(()=>{Y.current=null,q(!0)},f)};le(()=>()=>{Y.current&&clearTimeout(Y.current)},[]),le(()=>{if(!y||!t&&p)return;let f=!0;return x(!1),(async()=>{let b=F(y),w=b?await Pe(b):!1;if(!f||(S(w?ne=>!ne||ne.version!==b.version||ne.permissions.join(",")!==b.permissions.join(",")?b:ne:null),__DEV__&&Date.now()-lr>1e4&&(lr=Date.now(),await Sn()),!f))return;let k=await qt(y),te=k!==void 0?k:T?await zo(y,T):F(y);if(f){if(!te){x(!0);return}S(ne=>ne!=null?ne:te)}})(),()=>{f=!1}},[t,y,T,ie]),le(()=>Wo(e,f=>d.current?(d.current.postMessage(f),!0):!1),[e]);let _e=B(C,f=>{let b=y?f.downloads[y]:void 0;return(b==null?void 0:b.status)==="installed"?b.version:void 0});le(()=>{if(t||!y||!p)return;let f=F(y);if(!f||f.version===p.version)return;let b=!0;return Pe(f).then(w=>{!b||!w||(ue(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",p.version,"\u2192",f.version),S(f))}),()=>{b=!1}},[t,y,_e,p==null?void 0:p.version]);let Ae=B(C,f=>{var b;return y&&(b=f.apply_ticks[y])!=null?b:0});le(()=>{if(!Ae||!y)return;let f=F(y);if(!f||f.version===(p==null?void 0:p.version))return;let b=!0;return Pe(f).then(w=>{!b||!w||(ue(`webview:${e}`,"c\u1EADp nh\u1EADt",p==null?void 0:p.version,"\u2192",f.version),q(!1),S(f))}),()=>{b=!1}},[Ae]),le(()=>{var w;let f=(w=D().keep_alive)==null?void 0:w.idle_close_ms;if(t||!f||f<=0)return;let b=setTimeout(()=>{Dt(e)},f);return()=>clearTimeout(b)},[t,e]),le(()=>{r>0&&(x(!1),q(!1),P(f=>f+1),fe(f=>f+1))},[r]);let We=be(t);le(()=>{var f;We.current!==t&&(We.current=t,h.current&&((f=d.current)==null||f.injectJavaScript(Oo(t?"resumed":"paused"))))},[t]);let Se=`${(wt=p==null?void 0:p.version)!=null?wt:"none"}:${(bt=p==null?void 0:p.permissions.join(","))!=null?bt:""}:${W}`,Ee=$t(()=>JSON.stringify([M!=null?M:{},v!=null?v:{}]),[M,v]),Ye=$t(()=>{var f;return Do(v!=null?v:{},(f=p==null?void 0:p.permissions)!=null?f:[])},[Ee,p==null?void 0:p.permissions]),zt=$t(()=>Lo(M!=null?M:{},Ye)+To()+Co()+(D().debug?Po():""),[Ye]),Ue=be(null),Xe=be(null);le(()=>{var b,w,k;if(!p)return;if(Xe.current!==Se){Xe.current=Se,Ue.current=Ee;return}if(Ue.current===Ee)return;let f=((w=JSON.parse((b=Ue.current)!=null?b:"[]")[0])!=null?w:{}).org_id;if(Ue.current=Ee,f===(M==null?void 0:M.org_id)&&h.current){q(!1),ee(1500),(k=d.current)==null||k.injectJavaScript(ko(M!=null?M:{},Ye));return}q(!1),P(te=>te+1)},[Ee,p,Se]),le(()=>(t||(Re(e),Le(e),qe(e)),()=>{Re(e),Le(e),qe(e)}),[t,e,Se,r]),le(()=>{let f=cr.addEventListener("change",b=>{b==="background"&&!co()&&Re(e),b==="background"&&!fo()&&Le(e)});return()=>f.remove()},[e]);let Ze=xn(async f=>{var w,k,te,ne,jt,Cn;let b=Mo(f.nativeEvent.data);if(!b){if(y&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(f.nativeEvent.data,{app_id:y,instance_id:e})).catch(V=>{console.warn("[miniapp] onWebEvent l\u1ED7i",y,V)})}catch(V){console.warn("[miniapp] onWebEvent l\u1ED7i",y,V)}return}if(b.method==="log"){let{level:V,text:$}=b;ue(`web:${e}`,V!=null?V:"log",$!=null?$:"");return}if(b.method==="pong"){Y.current||q(!0);return}if(b.method==="touchAtTop"){i.emit(!!b.at_top);return}if(b.method==="contextApplied"){Y.current&&clearTimeout(Y.current),Y.current=null,q(!0);return}if(b.method==="ready"){h.current=!0,q(!0);let V=(w=ae.getState().instances[e])==null?void 0:w.context;V&&((k=d.current)==null||k.injectJavaScript(sn(V)));return}try{let V=await Uo(b,{getHostData:()=>{var $,pe;return(pe=($=ae.getState().instances[e])==null?void 0:$.host_data)!=null?pe:{}},getPermissions:()=>{var $,pe;return y?(pe=($=F(y))==null?void 0:$.permissions)!=null?pe:[]:[]},getContext:()=>{var $,pe;return(pe=($=ae.getState().instances[e])==null?void 0:$.context)!=null?pe:{}},is_dark:o,close:mt,app_id:y!=null?y:"",instance_id:e,options:c,emit:($,pe)=>{var On;(On=d.current)==null||On.injectJavaScript(Ro($,pe))},playBeep:(te=c==null?void 0:c.playScannerBeep)!=null?te:(()=>{var $;($=d.current)==null||$.injectJavaScript(No())}),isActive:()=>ae.getState().active_key===e&&cr.currentState!=="background"});b.id&&((ne=d.current)==null||ne.injectJavaScript(xo(b.id,V)))}catch(V){if(!b.id)return;let $=V==null?void 0:V.code,pe=V instanceof m?V:new m(typeof $=="string"?$:"HOST_ERROR",String((jt=V==null?void 0:V.message)!=null?jt:V));(Cn=d.current)==null||Cn.injectJavaScript(Eo(b.id,pe))}},[e,o,y,i,c]),Wt=xn(()=>{x(!1),P(f=>f+1),fe(f=>f+1)},[]);return Ke(En,{style:[Tn.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&me.behind],pointerEvents:t?"auto":"none",children:[re&&K(yn,{scanner:re,closing:re===O,onClosed:()=>{var f;U(null),re.absolute&&((f=d.current)==null||f.injectJavaScript(an(0)))},onHeight:re.absolute?f=>{var b;return(b=d.current)==null?void 0:b.injectJavaScript(an(f))}:void 0}),p?K($i,{ref:d,source:{uri:p.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?pn():p.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:zt,onMessage:Ze,bounces:!1,overScrollMode:"never",onLoadStart:f=>{Re(e),Le(e),qe(e),ue(`webview:${e}`,"load start",Mn(f.nativeEvent.url)),h.current=!1,q(!1)},onError:f=>{Re(e),Le(e),qe(e),ue(`webview:${e}`,"load error",Mn(f.nativeEvent.url),f.nativeEvent.description),x(!0),q(!1)},onLoadEnd:f=>{let b=f.nativeEvent.url;ue(`webview:${e}`,"load end",Mn(b)),y&&(g==null||g({app_id:y,instance_id:e,url:b})),ee(1500)},onContentProcessDidTerminate:()=>{Re(e),Le(e),qe(e),h.current=!1,q(!1),P(f=>f+1)},onRenderProcessGone:()=>(Re(e),Le(e),qe(e),h.current=!1,q(!1),P(f=>f+1),!0),style:me.webview},Se):null,(A==null?void 0:A.layout)===ge.full&&K(yn,{scanner:A}),u&&K(Hi,{visible:!p||!Q,interactive:L,children:K(ji,{splash:a,app:u.app,is_dark:o,error:L,has_bundle:!!p,retry:Wt})})]})}),ji=Pn.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=An(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return K(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),Hi=({visible:e,interactive:t,children:n})=>{let o=be(new vn.Value(e?1:0)).current,[r,i]=Ce(e);return le(()=>{if(e){i(!0),o.setValue(1);return}let a=vn.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?K(vn.View,{style:[Tn.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},ur=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return Ke(En,{style:[me.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[K(En,{style:[me.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?K(Bi,{source:{uri:e.icon},style:me.splash_icon_image}):K(yt,{style:me.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),K(yt,{style:[me.splash_name,{color:i}],children:e.name}),n==="error"?Ke(Rn,{children:[K(yt,{style:me.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),K(qi,{activeOpacity:.7,style:[me.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:K(yt,{style:[me.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):Ke(Rn,{children:[K(Ui,{style:me.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&Ke(yt,{style:me.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},pr=(e,t)=>{let n=be(t),o=be(!1);__DEV__&&!o.current&&n.current!==t&&(o.current=!0,console.warn(`[miniapp] MiniAppHost prop "${e}" \u0111\u1ED5i gi\u1EEFa c\xE1c l\u1EA7n render \u2192 m\u1ECDi WebView b\u1ECB mount l\u1EA1i. Khai b\xE1o component b\xEAn ngo\xE0i render.`))},Ji=({container:e,splash:t=ur,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{pr("container",e),pr("splash",t);let l=e,s=B(ae,A=>A.active_key),g=be(s);s&&(g.current=s);let d=B(ae,A=>Object.keys(A.instances).join("|")),h=B(ae,A=>{var O;return A.active_key?(O=A.instances[A.active_key])==null?void 0:O.app.name:void 0}),u=$t(()=>d?d.split("|"):[],[d]),[y,T]=Ce({}),M=be(zi()).current;le(()=>{if(!s||!r)return;let A=Vi.addEventListener("hardwareBackPress",()=>(mt(),!0));return()=>A.remove()},[s,r]);let v=xn(()=>{let A=ae.getState().active_key;A&&T(O=>({...O,[A]:(O[A]||0)+1}))},[]);return u.length?Ke(Rn,{children:[K(l,{visible:!!s,title:h!=null?h:"",is_dark:n,close:mt,reload:v,subscribeWebAtTop:M.subscribe,children:u.map(A=>K(Wi,{instance_key:A,is_active:s===A,is_front:(s!=null?s:g.current)===A,is_dark:n,reload_tick:y[A]||0,web_at_top:M,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},A))}),K(tr,{})]}):null},me=Tn.create({webview:{flex:1,backgroundColor:"transparent"},behind:{zIndex:-1},splash:{flex:1,alignItems:"center",justifyContent:"center",gap:12},splash_icon:{width:72,height:72,borderRadius:20,alignItems:"center",justifyContent:"center",overflow:"hidden"},splash_icon_image:{width:72,height:72},splash_letter:{fontSize:28,fontWeight:"700",color:"#1D4ED8"},splash_name:{fontSize:16,fontWeight:"600"},splash_hint:{color:"#71717A"},splash_spinner:{marginTop:8},retry_button:{marginTop:4,paddingHorizontal:20,paddingVertical:10,borderRadius:999},retry_text:{fontWeight:"600"}}),Gi=Pn.memo(Ji);export{oe as CodeType,ur as DefaultMiniAppSplash,Ht as MINIAPP_PLATFORM_URL,Gi as MiniAppHost,m as MiniAppHostError,je as ScannerEndReason,Zt as ScannerEvent,ge as ScannerLayout,it as ScannerMethod,he as ToastType,mt as closeMiniApp,dr as configureMiniApp,mr as createMmkvStorage,Ln as createReactNativeBiometrics,gr as createRnfsFileSystem,qt as ensureMiniApp,F as getLocalMiniApp,Ni as getMiniAppCatalog,ht as getMiniAppCatalogEntry,Ri as getMiniAppStatuses,ar as getMiniAppUpdate,Xr as installBundledMiniApp,Ei as onMiniAppEvent,yi as openMiniApp,ki as pauseMiniApp,Li as pauseMiniAppDownloads,wi as preloadMiniApp,Re as releaseSpeechFor,Oi as restoreMiniApp,Ii as resumeMiniApp,Fi as resumeMiniAppDownloads,Qr as sendEventToWeb,Sn as syncMiniAppCatalog,Ci as uninstallMiniApp,Di as updateMiniApp,Yn as uploadToUrl,An as useMiniAppDownload,xi as useMiniAppDownloadsPaused};
|
package/docs/NATIVE_APIS.md
CHANGED
|
@@ -285,7 +285,15 @@ await stopScanner();
|
|
|
285
285
|
```
|
|
286
286
|
|
|
287
287
|
- `scanCode`: camera phủ kín vùng mini app, trả một mã rồi tự đóng.
|
|
288
|
-
- `startScanner`: mặc định (`ScannerLayout.top`) camera chiếm khoảng 38% phía trên, web thu lại ở phần dưới và vẫn thao tác được, phù hợp quầy thu ngân cần thấy giỏ hàng cập nhật. `ScannerLayout.full` phủ kín vùng mini app, thẻ trên camera hiện mã vừa quét và số mã đã quét. Camera mở đến khi người dùng bấm Đóng hoặc web gọi `stopScanner()`.
|
|
288
|
+
- `startScanner`: mặc định (`ScannerLayout.top`) camera chiếm khoảng 38% phía trên, web thu lại ở phần dưới và vẫn thao tác được, phù hợp quầy thu ngân cần thấy giỏ hàng cập nhật. `ScannerLayout.full` phủ kín vùng mini app, thẻ trên camera hiện mã vừa quét và số mã đã quét. Camera mở đến khi người dùng bấm Đóng hoặc web gọi `stopScanner()`. Đóng camera `top` thì panel thu gọn dần lên trên.
|
|
289
|
+
- `startScanner({ layout: ScannerLayout.top, absolute: true })`: camera nằm đè lên phần trên web thay vì đẩy web xuống, WebView giữ nguyên kích thước nên web không phải co / giãn lại khi mở, đóng camera. Web tự chừa chỗ theo chiều cao camera host báo:
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
// px theo WebView; 0 khi camera đã đóng. Mini app nằm trong iframe cùng origin thì đọc ở window.top
|
|
293
|
+
const onHeight = () => setCameraTop(window.__retionScannerHeight ?? 0);
|
|
294
|
+
window.addEventListener('retionscannerheight', onHeight);
|
|
295
|
+
await startScanner({ layout: ScannerLayout.top, absolute: true });
|
|
296
|
+
```
|
|
289
297
|
- Camera có nút Đóng, quét từ ảnh, zoom 1x/2x (chụm 2 ngón để zoom tự do), đèn pin (nếu máy có) và nháy khung xanh khi nhận mã.
|
|
290
298
|
- Kết hợp với toast: khi nhận mã, web gọi `showToast(...)` để báo kết quả xử lý; toast nổi trên cả camera.
|
|
291
299
|
- Nút trên camera dùng Liquid Glass trên iOS 26+ nếu app đã cài `expo-glass-effect` (tuỳ chọn); còn lại dùng nền tối. Host không dùng `expo/metro-config` mà chưa cài thư viện này phải bật `transformer.allowOptionalDependencies: true` trong `metro.config.js`, nếu không bundle sẽ báo thiếu module.
|
|
@@ -303,6 +311,7 @@ await stopScanner();
|
|
|
303
311
|
| --- | --- | --- |
|
|
304
312
|
| `types` | `CodeType.all` | Loại mã cần quét; quét ít loại hơn thì nhanh và ít nhận nhầm hơn |
|
|
305
313
|
| `layout` | `ScannerLayout.top` | Chỉ `startScanner`: `top` hoặc `full` |
|
|
314
|
+
| `absolute` | `false` | Chỉ `startScanner` với `top`: camera nằm đè lên web, web không đổi kích thước; chiều cao camera ở `window.__retionScannerHeight` (event `retionscannerheight`) |
|
|
306
315
|
| `hint` | `Đưa mã vào khung để quét` | Chữ hướng dẫn trên camera, 1–80 ký tự; truyền theo ngôn ngữ của mini app |
|
|
307
316
|
| `cooldown_ms` | `1500` | Chỉ `startScanner`, 0–60000 ms: **cùng một mã** phải rời khung đủ thời gian này mới được nhận lại, nên giữ nguyên mã trước camera không bị đếm thêm. Mã khác nhận ngay |
|
|
308
317
|
|