@retion-miniapp/react-native 0.11.0 → 0.12.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/app.plugin.js +5 -1
- package/dist/index.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +24 -8
- package/dist/index.mjs +24 -8
- package/docs/NATIVE_APIS.md +8 -5
- package/package.json +2 -1
package/app.plugin.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Expo prebuild plugin. Bare React Native hosts set NSFaceIDUsageDescription in Info.plist.
|
|
2
2
|
const { withInfoPlist, withAndroidManifest } = require('expo/config-plugins');
|
|
3
3
|
const withSpeechRecognition = require('expo-speech-recognition/app.plugin.js');
|
|
4
|
-
|
|
4
|
+
// Plugin này build từ ES module nên hàm nằm ở .default.
|
|
5
|
+
const withVisionCamera = require('react-native-vision-camera/app.plugin.js').default;
|
|
5
6
|
|
|
6
7
|
module.exports = function withMiniApp(config, options = {}) {
|
|
7
8
|
config = withInfoPlist(config, config => {
|
|
@@ -25,7 +26,10 @@ module.exports = function withMiniApp(config, options = {}) {
|
|
|
25
26
|
androidSpeechServicePackages: options.androidSpeechServicePackages,
|
|
26
27
|
});
|
|
27
28
|
// Thêm quyền CAMERA Android và nhúng sẵn model quét mã (ML Kit, khoảng 2,4 MB) để quét được ngay, không cần tải.
|
|
29
|
+
const camera_text = config.ios?.infoPlist?.NSCameraUsageDescription;
|
|
28
30
|
config = withVisionCamera(config, { enableCodeScanner: true });
|
|
31
|
+
// Plugin vision-camera tự đặt câu mặc định, có thể đè câu của app; câu quyền đã xử lý ở withInfoPlist phía trên.
|
|
32
|
+
if (camera_text === undefined) { delete config.ios.infoPlist.NSCameraUsageDescription; }
|
|
29
33
|
return withAndroidManifest(config, config => {
|
|
30
34
|
const manifest = config.modResults.manifest;
|
|
31
35
|
const permissions = manifest['uses-permission'] || [];
|
package/dist/index.d.mts
CHANGED
|
@@ -687,10 +687,19 @@ declare const ScannerEndReason: {
|
|
|
687
687
|
readonly error: "error";
|
|
688
688
|
};
|
|
689
689
|
type ScannerEndReason = (typeof ScannerEndReason)[keyof typeof ScannerEndReason];
|
|
690
|
+
declare const ScannerLayout: {
|
|
691
|
+
readonly top: "top";
|
|
692
|
+
readonly full: "full";
|
|
693
|
+
};
|
|
694
|
+
type ScannerLayout = (typeof ScannerLayout)[keyof typeof ScannerLayout];
|
|
690
695
|
interface ScannerOptions {
|
|
691
696
|
types?: CodeType[];
|
|
692
697
|
/** Quét liên tiếp: thời gian trước khi nhận lại cùng một mã. */
|
|
693
698
|
cooldown_ms?: number;
|
|
699
|
+
/** Chữ hướng dẫn trên camera, tối đa 80 ký tự. */
|
|
700
|
+
hint?: string;
|
|
701
|
+
/** Quét liên tiếp: camera ở trên web (top, mặc định) hoặc phủ kín (full). */
|
|
702
|
+
layout?: ScannerLayout;
|
|
694
703
|
}
|
|
695
704
|
interface ScannerResult {
|
|
696
705
|
value: string;
|
|
@@ -750,4 +759,4 @@ interface UploadCapabilities {
|
|
|
750
759
|
/** 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. */
|
|
751
760
|
declare const uploadToUrl: MiniAppUploader;
|
|
752
761
|
|
|
753
|
-
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, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, 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 };
|
|
762
|
+
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, 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
|
@@ -687,10 +687,19 @@ declare const ScannerEndReason: {
|
|
|
687
687
|
readonly error: "error";
|
|
688
688
|
};
|
|
689
689
|
type ScannerEndReason = (typeof ScannerEndReason)[keyof typeof ScannerEndReason];
|
|
690
|
+
declare const ScannerLayout: {
|
|
691
|
+
readonly top: "top";
|
|
692
|
+
readonly full: "full";
|
|
693
|
+
};
|
|
694
|
+
type ScannerLayout = (typeof ScannerLayout)[keyof typeof ScannerLayout];
|
|
690
695
|
interface ScannerOptions {
|
|
691
696
|
types?: CodeType[];
|
|
692
697
|
/** Quét liên tiếp: thời gian trước khi nhận lại cùng một mã. */
|
|
693
698
|
cooldown_ms?: number;
|
|
699
|
+
/** Chữ hướng dẫn trên camera, tối đa 80 ký tự. */
|
|
700
|
+
hint?: string;
|
|
701
|
+
/** Quét liên tiếp: camera ở trên web (top, mặc định) hoặc phủ kín (full). */
|
|
702
|
+
layout?: ScannerLayout;
|
|
694
703
|
}
|
|
695
704
|
interface ScannerResult {
|
|
696
705
|
value: string;
|
|
@@ -750,4 +759,4 @@ interface UploadCapabilities {
|
|
|
750
759
|
/** 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. */
|
|
751
760
|
declare const uploadToUrl: MiniAppUploader;
|
|
752
761
|
|
|
753
|
-
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, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, 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 };
|
|
762
|
+
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, 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 Mr=Object.create;var Xe=Object.defineProperty;var vr=Object.getOwnPropertyDescriptor;var _r=Object.getOwnPropertyNames;var xr=Object.getPrototypeOf,Er=Object.prototype.hasOwnProperty;var Pr=(e,t)=>{for(var n in t)Xe(e,n,{get:t[n],enumerable:!0})},zt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of _r(t))!Er.call(e,o)&&o!==n&&Xe(e,o,{get:()=>t[o],enumerable:!(r=vr(t,o))||r.enumerable});return e};var de=(e,t,n)=>(n=e!=null?Mr(xr(e)):{},zt(t||!e||!e.__esModule?Xe(n,"default",{value:e,enumerable:!0}):n,e)),Rr=e=>zt(Xe({},"__esModule",{value:!0}),e);var ho={};Pr(ho,{CodeType:()=>rt,DefaultMiniAppSplash:()=>Bt,MINIAPP_PLATFORM_URL:()=>Qe,MiniAppHost:()=>Ar,MiniAppHostError:()=>u,ScannerEndReason:()=>Re,ScannerEvent:()=>ot,ScannerMethod:()=>Ie,closeMiniApp:()=>De,configureMiniApp:()=>Wt,createMmkvStorage:()=>Kt,createReactNativeBiometrics:()=>yt,createRnfsFileSystem:()=>Yt,ensureMiniApp:()=>Ge,getLocalMiniApp:()=>C,getMiniAppCatalog:()=>fr,getMiniAppCatalogEntry:()=>Ne,getMiniAppStatuses:()=>sr,getMiniAppUpdate:()=>Ft,installBundledMiniApp:()=>Yn,onMiniAppEvent:()=>ir,openMiniApp:()=>Zn,pauseMiniApp:()=>pr,pauseMiniAppDownloads:()=>dr,preloadMiniApp:()=>er,releaseSpeechFor:()=>le,restoreMiniApp:()=>lr,resumeMiniApp:()=>ur,resumeMiniAppDownloads:()=>gr,sendEventToWeb:()=>Xn,syncMiniAppCatalog:()=>ft,uninstallMiniApp:()=>cr,updateMiniApp:()=>mr,uploadToUrl:()=>bt,useMiniAppDownload:()=>gt,useMiniAppDownloadsPaused:()=>or});module.exports=Rr(ho);var Qe="https://retion-miniapp-platform.vercel.app",xe=null,Ht=new Set,Wt=e=>{xe=e,Ht.forEach(t=>t())},k=()=>{if(!xe)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return xe},Jt=e=>{Ht.add(e),xe&&e()},Z=(...e)=>{xe!=null&&xe.debug&&console.log("[miniapp]",...e)};var Yt=(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(r=>r.map(o=>o.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,r)=>{await t(n,r)},download:({url:n,to_file:r,onProgress:o})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:r,progressInterval:250,begin:()=>{},progress:({bytesWritten:l,contentLength:c})=>o==null?void 0:o(l,c)});return{promise:a.then(({statusCode:l})=>({status:l})),cancel:()=>e.stopDownload(i)}}}),Kt=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var S=de(require("react")),E=require("react-native"),wr=de(require("react-native-webview"));var He=require("react-native");var yt=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),Ze,wt=()=>(Ze||(Ze=import("react-native-biometrics").then(({default:e})=>yt(new e({allowDeviceCredentials:!1}))).catch(e=>{throw Ze=void 0,new u("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),Ze);var ce=require("react-native");var Gt=e=>{var n,r,o;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new u("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 u("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 u("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${l} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(r=t.timeout)!=null?r:15e3,maximumAge:(o=t.maximumAge)!=null?o:0}},Xt=(e,t=()=>!0)=>new Promise((n,r)=>{let o=!1,i=(c,s)=>{o||(o=!0,clearTimeout(a),c?r(c):n(s))},a=setTimeout(()=>i(new u("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),l=()=>o?!1:t()?!0:(i(new u("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 u("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(l()){if(ce.Platform.OS==="android"){let s=ce.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,d=ce.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,g=await ce.PermissionsAndroid.check(s);if(!l())return;let y=g||await ce.PermissionsAndroid.check(d);if(!l())return;if(!g&&!y){let p=await ce.PermissionsAndroid.requestMultiple([s,d]);if(!l())return;if(p[s]!==ce.PermissionsAndroid.RESULTS.GRANTED&&p[d]!==ce.PermissionsAndroid.RESULTS.GRANTED)throw new u("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 g;if(!l())return;let d=(g={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?g:"LOCATION_ERROR";i(new u(d,s.message))},e)}})().catch(c=>i(c))});var St=require("react-native");var At=20,Qt=20,on=/^[a-z][a-z0-9_-]{0,31}$/,Or=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,Cr=["low","medium","high"],ye=e=>!!e&&typeof e=="object"&&!Array.isArray(e),F=e=>new u("INVALID_PARAMS",e),je=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Zt=(e,t)=>{if(e===void 0)return{};if(!ye(e)||Object.keys(e).length>Qt||Object.values(e).some(n=>typeof n!="string"))throw F(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Qt} key)`);return e},sn=e=>{var n,r,o,i;if(e!==void 0&&!ye(e))throw F("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!on.test(t.source)))throw F("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"||!Or.test(a))))throw F("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!je(t.max_count,1,At))throw F(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${At}`);if(t.max_size!==void 0&&!je(t.max_size,1,Number.MAX_SAFE_INTEGER))throw F("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!je(t.concurrency,1,5))throw F("concurrency ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u20135");return{source:(n=t.source)!=null?n:"library",accept:((r=t.accept)!=null?r:[]).map(a=>a.toLowerCase()),max_count:(o=t.max_count)!=null?o:1,max_size:t.max_size,process:Tr(t.process),target:kr(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},Tr=e=>{if(e===void 0)return{};if(!ye(e))throw F("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!ye(n))throw F("process.image ph\u1EA3i l\xE0 object");for(let r of["max_width","max_height"])if(n[r]!==void 0&&!je(n[r],1,1e4))throw F(`process.image.${r} 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 F("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(!ye(n))throw F("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!je(n.max_duration,1,3600))throw F("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!Cr.includes(n.quality))throw F("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},kr=e=>{var n,r,o,i;if(e===void 0)return{target:"host",params:{}};if(!ye(e))throw F("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!on.test(t))throw F("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!ye(e.params))throw F("upload.params ph\u1EA3i l\xE0 object");return{target:t,params:(r=e.params)!=null?r:{}}}if(typeof e.url!="string"||!/^https:\/\//i.test(e.url))throw F("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 F(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:Zt(e.headers,"upload.headers"),form_data:Zt(e.form_data,"upload.form_data"),field_name:(o=e.field_name)!=null?o:"file",url_field:(i=e.url_field)!=null?i:"url"}},an=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},Ir=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),r=an(e.name);return t.some(o=>o==="*/*"?!0:o.startsWith(".")?o===r:o.endsWith("/*")?n.startsWith(o.slice(0,-1)):n===o)},Lr=e=>{let t=e.length>0&&e.every(r=>r.startsWith("image/")),n=e.length>0&&e.every(r=>r.startsWith("video/"));return t?"image":n?"video":"mixed"},Be,Dr=()=>(Be!=null||(Be=import("react-native-image-picker").catch(e=>{throw Be=void 0,new u("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),Be),en=e=>async({accept:t,max_count:n,process:r})=>{var c,s,d,g,y,p,f,T,v;let o=await Dr(),i=Lr(t),a={mediaType:i==="image"?"photo":i,maxWidth:(c=r.image)==null?void 0:c.max_width,maxHeight:(s=r.image)==null?void 0:s.max_height,quality:(g=(d=r.image)==null?void 0:d.quality)!=null?g:.8,videoQuality:(p=(y=r.video)==null?void 0:y.quality)!=null?p:"medium",durationLimit:(f=r.video)==null?void 0:f.max_duration,assetRepresentationMode:"compatible"},l=e==="camera"?await o.launchCamera({...a,saveToPhotos:!1}):await o.launchImageLibrary({...a,selectionLimit:n});if(l.didCancel)return[];if(l.errorCode){let _=l.errorCode==="permission"?"PERMISSION_DENIED":l.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new u(_,(T=l.errorMessage)!=null?T:l.errorCode)}return((v=l.assets)!=null?v:[]).filter(_=>_.uri).map((_,b)=>{var w,z,ne;return{uri:_.uri,name:(w=_.fileName)!=null?w:`file_${b+1}`,mime_type:(z=_.type)!=null?z:"application/octet-stream",size:_.fileSize,width:_.width,height:_.height,duration:_.duration,processed:!((ne=_.type)!=null&&ne.startsWith("video/"))||St.Platform.OS==="ios"}})},Nr={"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"},Ur={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},Fr=e=>async({accept:t,max_count:n})=>{var i,a,l,c;let r=t.map(s=>{var d;return(d=Nr[s])!=null?d:Ur[s]}),o=!t.length||r.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(r)].flatMap(s=>e.types[s]);try{let d=(await e.pick({type:o,allowMultiSelection:n>1,mode:"import"})).filter(p=>p.uri&&!p.error).map((p,f)=>{var T,v,_;return{uri:p.uri,name:(T=p.name)!=null?T:`file_${f+1}`,mime_type:(v=p.type)!=null?v:"application/octet-stream",size:(_=p.size)!=null?_:void 0}});if(St.Platform.OS!=="android"||!e.keepLocalCopy||!d.some(p=>p.uri.startsWith("content://")))return d;let g=await e.keepLocalCopy({files:d.map(p=>({uri:p.uri,fileName:p.name})),destination:"cachesDirectory"}),y=new Map(g.map(p=>[p.sourceUri,p.status==="success"?p.localUri:void 0]));return d.map(p=>{var f;return{...p,uri:(f=y.get(p.uri))!=null?f: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 u("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},qe,$r=async e=>(qe!=null||(qe=import("@react-native-documents/picker").then(t=>Fr(t)).catch(t=>{throw qe=void 0,new u("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await qe)(e)),cn={library:en("library"),camera:en("camera"),document:$r},tn={type:"image",label:"\u1EA2nh",accept:["image/*"]},nn={type:"video",label:"Video",accept:["video/*"]},rn={library:[tn,nn],camera:[tn,nn],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"]}]},Ve,ln=()=>(Ve!=null||(Ve=import("react-native-compressor").catch(()=>(Ve=void 0,null))),Ve),pn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},Br=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),qr={low:640,medium:1280,high:1920},Vr=async(e,{image:t})=>{var r;if(!t||!Br.has(e.mime_type.toLowerCase()))return e;let n=await ln();if(!n)return e;try{let o=await n.Image.compress(e.uri,{compressionMethod:"manual",maxWidth:t.max_width,maxHeight:t.max_height,quality:(r=t.quality)!=null?r:.8,output:"jpg"});return{...e,uri:o,mime_type:"image/jpeg",name:e.name.replace(/\.[^.]+$/,"")+".jpg",size:await pn(n,o,e.size),processed:!0}}catch{return e}},jr=async(e,{video:t})=>{var r;let n=await ln();if(!n)return e;try{let o=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:qr[(r=t==null?void 0:t.quality)!=null?r:"medium"],minimumFileSizeForCompress:2});return{...e,uri:o,mime_type:"video/mp4",size:await pn(n,o,e.size),processed:!0}}catch{return e}},zr={image:Vr,video:jr},Hr=(e,t)=>t.split(".").reduce((n,r)=>ye(n)?n[r]:void 0,e),bt=({file:e,target:t,onProgress:n,signal:r})=>new Promise((o,i)=>{if(t.target!=="url"||!("url"in t)){i(new u("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(r.aborted){i(new u("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let l=new XMLHttpRequest,c=new FormData;Object.entries(a.form_data).forEach(([g,y])=>c.append(g,y)),c.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>l.abort();r.addEventListener("abort",s);let d=g=>{r.removeEventListener("abort",s),g()};l.open("POST",a.url),Object.entries(a.headers).forEach(([g,y])=>l.setRequestHeader(g,y)),l.upload.onprogress=g=>n(g.loaded,g.total||e.size||0),l.onload=()=>d(()=>{let g=l.responseText;try{g=JSON.parse(l.responseText)}catch{}if(l.status<200||l.status>=300){i(new u("UPLOAD_FAILED",`HTTP ${l.status}`));return}let y=Hr(g,a.url_field);if(typeof y!="string"||!y){i(new u("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}o({url:y,response:g})}),l.onerror=()=>d(()=>i(new u("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),l.onabort=()=>d(()=>i(new u("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),l.send(c)}),un=e=>{var r,o;let t={...cn};for(let[i,a]of Object.entries((r=e==null?void 0:e.sources)!=null?r:{}))a?t[i]=a:delete t[i];let n={url:bt};for(let[i,a]of Object.entries((o=e==null?void 0:e.targets)!=null?o:{}))i!=="url"&&a&&(n[i]=a);return{sources:t,targets:n}},dn=e=>{let{sources:t,targets:n}=un(e),r=Object.keys(t),o=Object.fromEntries(r.filter(i=>t[i]===cn[i]&&rn[i]).map(i=>[i,rn[i]]));return{sources:r,file_types:o,targets:Object.keys(n),max_count:At}},tt=new Map,gn=(e,t)=>`${e}:${t}`,Wr=0,mn=(e,t)=>{var n;typeof t=="string"&&((n=tt.get(gn(e,t)))==null||n.abort())},Ee=e=>{for(let[t,n]of tt)t.startsWith(`${e}:`)&&n.abort()},et=()=>new u("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),Jr=(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)}},fn=async(e,t)=>{var c;let{sources:n,targets:r}=un(t.config),o=n[e.source];if(!o)throw new u("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=r[e.target.target];if(!i)throw new u("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,l=gn(t.instance_id,(c=t.task_id)!=null?c:`auto-${++Wr}`);tt.set(l,a);try{return await Yr(e,t,o,i,a.signal)}finally{tt.delete(l)}},Yr=async(e,{instance_id:t,app_id:n,getContext:r,task_id:o,config:i,emit:a,exclusivePick:l=g=>g()},c,s,d)=>{var h,M,V;let g={app_id:n!=null?n:"",instance_id:t,context:{...(h=r==null?void 0:r())!=null?h:{}}},y=(await l(()=>c({accept:e.accept,max_count:e.max_count,process:e.process,caller:g}))).slice(0,e.max_count);if(d.aborted)throw et();if(!y.length)throw new u("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let p=[],f=y.filter(P=>Ir(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||an(P.name)}`}),!1)),T=f.map(()=>0),v=f.map(P=>{var D;return(D=P.size)!=null?D:0}),_=0,b=0,w=(P=!1)=>{if(!a||!o)return;let D=Date.now();if(!P&&D-b<200)return;b=D;let B=v.reduce((I,X)=>I+X,0),j=T.reduce((I,X)=>I+X,0);a("upload.progress",{task_id:o,loaded:j,total:B,percent:B?Math.min(100,Math.round(j/B*100)):0,done_count:_,count:f.length})},z=[],ne=0,ae=async()=>{var P,D,B;for(;ne<f.length;){let j=ne++,I=f[j];try{if(d.aborted)throw et();let X=I.mime_type.startsWith("image/")?"image":I.mime_type.startsWith("video/")?"video":void 0,Ue=X&&!I.processed?(D=(P=i==null?void 0:i.processors)==null?void 0:P[X])!=null?D:zr[X]:void 0;if(Ue&&(I=await Ue(I,e.process),v[j]=(B=I.size)!=null?B:v[j],d.aborted))throw et();if(e.max_size&&I.size&&I.size>e.max_size)throw new u("FILE_TOO_LARGE",`File ${I.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let ve=(Te,$e)=>{T[j]=Te,$e&&(v[j]=$e),w()},re=await s({file:I,target:e.target,onProgress:ve,signal:d,caller:g});if(typeof(re==null?void 0:re.url)!="string"||!re.url)throw new u("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:Fe,...Ce}=re;z[j]={url:Fe,name:I.name,mime_type:I.mime_type,size:I.size,width:I.width,height:I.height,duration:I.duration,...Object.keys(Ce).length?{response:"response"in Ce?Ce.response:Ce}:{}},T[j]=v[j]}catch(X){p.push(Jr(f[j].name,X))}finally{_++,w(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,f.length)},ae)),d.aborted)throw et();let Me=z.filter(P=>!!P);if(!Me.length){let P=p[0];throw new u((M=P==null?void 0:P.code)!=null?M:"UPLOAD_FAILED",(V=P==null?void 0:P.message)!=null?V:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:Me,failed:p}};var bn=require("react-native");var Pe=require("react-native");var ee,hn=()=>Pe.Platform.OS==="android"&&!!(ee!=null&&ee.requesting_permission),Kr=1500,vt=()=>new Promise(e=>{if(Pe.Platform.OS!=="android"||Pe.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),r.remove(),e()},n=setTimeout(t,Kr),r=Pe.AppState.addEventListener("change",o=>{o==="active"&&t()})}),Mt=e=>{var t;if(ee===e&&(ee=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Pe.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},yn=async(e,t,n,r=()=>!0)=>{var i,a,l,c,s;if(ee)throw new u("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!r())throw new u("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let o={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};ee=o;try{let d;try{d=await import("expo-speech-recognition")}catch{throw new u("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let g=d.ExpoSpeechRecognitionModule;if(o.native=g,o.cancelled||!r())throw new u("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");o.requesting_permission=!0;let y;try{y=await g.requestPermissionsAsync()}finally{o.requesting_permission=!1}if(await vt(),o.cancelled||!r())throw new u("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!y.granted)throw new u("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await g.getStateAsync()!=="inactive")throw new u("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(o.cancelled||!r())throw new u("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");o.subscriptions.push(g.addListener("result",p=>{var f,T;ee!==o||o.cancelled||n(p.isFinal?"speech.final":"speech.partial",{...p,text:(T=(f=p.results[0])==null?void 0:f.transcript)!=null?T:""})}),g.addListener("error",p=>{ee===o&&!o.cancelled&&n("speech.error",{...p,code:p.error})}),g.addListener("end",()=>{ee===o&&(Mt(o),n("speech.end"))})),o.started=!0,g.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 Mt(o),d}},wn=e=>{let t=ee;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},le=e=>{let t=ee;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{Mt(t)}};var nt=require("react"),ke=e=>{let t=e,n=new Set;return{getState:()=>t,setState:r=>{let o=typeof r=="function"?r(t):r;t={...t,...o},n.forEach(i=>i())},subscribe:r=>(n.add(r),()=>{n.delete(r)})}},W=(e,t,n=Object.is)=>{let r=(0,nt.useRef)(null),o=()=>{let i=e.getState(),a=r.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 r.current={state:i,selector:t,value:c},c};return(0,nt.useSyncExternalStore)(e.subscribe,o)};var An={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"},rt={...An,all:Object.values(An)},Ie={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},ot={result:"scanner.result",end:"scanner.end"},Re={user:"user",web:"web",closed:"closed",error:"error"},ge={once:"once",continuous:"continuous"},Gr=1500,Sn=6e4,U,pe=ke({active:null,last_value:null,hit_tick:0}),Mn=()=>bn.Platform.OS==="android"&&!!(U!=null&&U.requesting_permission),_t=e=>{let{types:t,cooldown_ms:n}=e!=null?e:{},r={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(o=>rt.all.includes(o)))throw new u("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");r.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>Sn)throw new u("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${Sn}`);r.cooldown_ms=n}return r},xt=e=>U!==e?!1:(U=void 0,pe.setState({active:null,last_value:null}),!0),vn=async(e,t)=>{if(U)throw new u("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new u("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");U=e;let n=()=>{if(e.cancelled||!t())throw new u("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let r;try{r=await import("react-native-vision-camera")}catch{throw new u("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n(),e.requesting_permission=!0;let o;try{o=await r.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await vt(),n(),o!=="granted")throw new u("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera");if(!r.Camera.getAvailableCameraDevices().some(i=>i.position==="back"))throw new u("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");pe.setState({active:{owner:e.owner,mode:e.mode,types:e.types,vision:r},last_value:null})}catch(r){throw xt(e),r}},_n=(e,t,n)=>{var r,o;return{owner:e,mode:t,types:(r=n.types)!=null?r:rt.all,cooldown_ms:(o=n.cooldown_ms)!=null?o:Gr,cancelled:!1,requesting_permission:!1,last_seen:new Map}},xn=(e,t,n=()=>!0,r)=>new Promise((o,i)=>{let a=_n(e,ge.once,t);a.onHit=r,a.resolve=o,a.reject=i,vn(a,n).catch(i)}),En=(e,t,n,r=()=>!0,o)=>{let i=_n(e,ge.continuous,t);return i.emit=n,i.onHit=o,vn(i,r)},it=(e,t,n)=>{var r,o;if(!pe.getState().active){e.cancelled=!0;return}if(xt(e)){if(e.mode===ge.once){(r=e.reject)==null||r.call(e,t===Re.error?new u("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new u("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(o=e.emit)==null||o.call(e,ot.end,n?{reason:t,message:n}:{reason:t})}},Pn=e=>{(U==null?void 0:U.owner)===e&&it(U,Re.web)},we=e=>{(U==null?void 0:U.owner)===e&&it(U,Re.closed)},Et=()=>{U&&it(U,Re.user)},Rn=e=>{U&&it(U,Re.error,e)},On=(e,t=Date.now())=>{var r,o,i;let n=U;if(!(!n||!pe.getState().active))for(let{value:a,type:l}of e){if(!a)continue;let c=n.last_seen.get(a);if(!(c!==void 0&&t-c<n.cooldown_ms)){if(n.last_seen.set(a,t),(r=n.onHit)==null||r.call(n),n.mode===ge.once){xt(n),(o=n.resolve)==null||o.call(n,{value:a,type:l});return}pe.setState(s=>({last_value:a,hit_tick:s.hit_tick+1})),(i=n.emit)==null||i.call(n,ot.result,{value:a,type:l})}}};var at=1,u=class extends Error{constructor(n,r){super(r);this.code=n}},Cn=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===at&&typeof t.method=="string"?t:null}catch{return null}},We=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,Tn=(e,t)=>We({id:e,result:t}),kn=(e,t)=>We({id:e,error:{code:t.code,message:t.message}}),In=(e,t)=>We({event:e,data:t}),Rt=e=>We({event:"context",data:e});var Ln=()=>`(function () {
|
|
1
|
+
"use strict";var Io=Object.create;var it=Object.defineProperty;var Fo=Object.getOwnPropertyDescriptor;var Do=Object.getOwnPropertyNames;var No=Object.getPrototypeOf,Uo=Object.prototype.hasOwnProperty;var Vo=(e,t)=>{for(var n in t)it(e,n,{get:t[n],enumerable:!0})},en=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Do(t))!Uo.call(e,r)&&r!==n&&it(e,r,{get:()=>t[r],enumerable:!(o=Fo(t,r))||o.enumerable});return e};var ue=(e,t,n)=>(n=e!=null?Io(No(e)):{},en(t||!e||!e.__esModule?it(n,"default",{value:e,enumerable:!0}):n,e)),Bo=e=>en(it({},"__esModule",{value:!0}),e);var Ir={};Vo(Ir,{CodeType:()=>J,DefaultMiniAppSplash:()=>Xt,MINIAPP_PLATFORM_URL:()=>st,MiniAppHost:()=>Lo,MiniAppHostError:()=>u,ScannerEndReason:()=>Fe,ScannerEvent:()=>dt,ScannerLayout:()=>he,ScannerMethod:()=>Ve,closeMiniApp:()=>$e,configureMiniApp:()=>nn,createMmkvStorage:()=>sn,createReactNativeBiometrics:()=>Et,createRnfsFileSystem:()=>rn,ensureMiniApp:()=>nt,getLocalMiniApp:()=>N,getMiniAppCatalog:()=>Oo,getMiniAppCatalogEntry:()=>ze,getMiniAppStatuses:()=>_o,getMiniAppUpdate:()=>Yt,installBundledMiniApp:()=>io,onMiniAppEvent:()=>Ao,openMiniApp:()=>go,pauseMiniApp:()=>Mo,pauseMiniAppDownloads:()=>Eo,preloadMiniApp:()=>mo,releaseSpeechFor:()=>fe,restoreMiniApp:()=>vo,resumeMiniApp:()=>xo,resumeMiniAppDownloads:()=>Ro,sendEventToWeb:()=>co,syncMiniAppCatalog:()=>Mt,uninstallMiniApp:()=>So,updateMiniApp:()=>Po,uploadToUrl:()=>Ct,useMiniAppDownload:()=>St,useMiniAppDownloadsPaused:()=>wo});module.exports=Bo(Ir);var st="https://retion-miniapp-platform.vercel.app",ke=null,tn=new Set,nn=e=>{ke=e,tn.forEach(t=>t())},V=()=>{if(!ke)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return ke},on=e=>{tn.add(e),ke&&e()},ae=(...e)=>{ke!=null&&ke.debug&&console.log("[miniapp]",...e)};var rn=(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)}}}),sn=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var S=ue(require("react")),T=require("react-native"),ko=ue(require("react-native-webview"));var Ye=require("react-native");var Et=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),at,Rt=()=>(at||(at=import("react-native-biometrics").then(({default:e})=>Et(new e({allowDeviceCredentials:!1}))).catch(e=>{throw at=void 0,new u("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),at);var me=require("react-native");var an=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new u("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 u("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 u("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}},cn=(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 u("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 u("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 u("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(me.Platform.OS==="android"){let s=me.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,p=me.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,g=await me.PermissionsAndroid.check(s);if(!c())return;let A=g||await me.PermissionsAndroid.check(p);if(!c())return;if(!g&&!A){let d=await me.PermissionsAndroid.requestMultiple([s,p]);if(!c())return;if(d[s]!==me.PermissionsAndroid.RESULTS.GRANTED&&d[p]!==me.PermissionsAndroid.RESULTS.GRANTED)throw new u("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 g;if(!c())return;let p=(g={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?g:"LOCATION_ERROR";i(new u(p,s.message))},e)}})().catch(l=>i(l))});var Ot=require("react-native");var Pt=20,ln=20,fn=/^[a-z][a-z0-9_-]{0,31}$/,qo=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,$o=["low","medium","high"],xe=e=>!!e&&typeof e=="object"&&!Array.isArray(e),$=e=>new u("INVALID_PARAMS",e),Je=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,pn=(e,t)=>{if(e===void 0)return{};if(!xe(e)||Object.keys(e).length>ln||Object.values(e).some(n=>typeof n!="string"))throw $(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${ln} key)`);return e},hn=e=>{var n,o,r,i;if(e!==void 0&&!xe(e))throw $("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!fn.test(t.source)))throw $("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"||!qo.test(a))))throw $("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!Je(t.max_count,1,Pt))throw $(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Pt}`);if(t.max_size!==void 0&&!Je(t.max_size,1,Number.MAX_SAFE_INTEGER))throw $("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!Je(t.concurrency,1,5))throw $("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:zo(t.process),target:Wo(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},zo=e=>{if(e===void 0)return{};if(!xe(e))throw $("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!xe(n))throw $("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!Je(n[o],1,1e4))throw $(`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 $("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(!xe(n))throw $("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!Je(n.max_duration,1,3600))throw $("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!$o.includes(n.quality))throw $("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},Wo=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!xe(e))throw $("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!fn.test(t))throw $("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!xe(e.params))throw $("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 $("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 $(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:pn(e.headers,"upload.headers"),form_data:pn(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},yn=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},jo=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=yn(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},Ho=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"},We,Jo=()=>(We!=null||(We=import("react-native-image-picker").catch(e=>{throw We=void 0,new u("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),We),un=e=>async({accept:t,max_count:n,process:o})=>{var l,s,p,g,A,d,h,k,E;let r=await Jo(),i=Ho(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:(g=(p=o.image)==null?void 0:p.quality)!=null?g:.8,videoQuality:(d=(A=o.video)==null?void 0:A.quality)!=null?d:"medium",durationLimit:(h=o.video)==null?void 0:h.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 R=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new u(R,(k=c.errorMessage)!=null?k:c.errorCode)}return((E=c.assets)!=null?E:[]).filter(R=>R.uri).map((R,v)=>{var _,Y,Z;return{uri:R.uri,name:(_=R.fileName)!=null?_:`file_${v+1}`,mime_type:(Y=R.type)!=null?Y:"application/octet-stream",size:R.fileSize,width:R.width,height:R.height,duration:R.duration,processed:!((Z=R.type)!=null&&Z.startsWith("video/"))||Ot.Platform.OS==="ios"}})},Ko={"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"},Yo={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},Go=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var p;return(p=Ko[s])!=null?p:Yo[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let p=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(d=>d.uri&&!d.error).map((d,h)=>{var k,E,R;return{uri:d.uri,name:(k=d.name)!=null?k:`file_${h+1}`,mime_type:(E=d.type)!=null?E:"application/octet-stream",size:(R=d.size)!=null?R:void 0}});if(Ot.Platform.OS!=="android"||!e.keepLocalCopy||!p.some(d=>d.uri.startsWith("content://")))return p;let g=await e.keepLocalCopy({files:p.map(d=>({uri:d.uri,fileName:d.name})),destination:"cachesDirectory"}),A=new Map(g.map(d=>[d.sourceUri,d.status==="success"?d.localUri:void 0]));return p.map(d=>{var h;return{...d,uri:(h=A.get(d.uri))!=null?h:d.uri}})}catch(s){let p=s==null?void 0:s.code;if(p===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw p===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new u("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},je,Xo=async e=>(je!=null||(je=import("@react-native-documents/picker").then(t=>Go(t)).catch(t=>{throw je=void 0,new u("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await je)(e)),wn={library:un("library"),camera:un("camera"),document:Xo},dn={type:"image",label:"\u1EA2nh",accept:["image/*"]},gn={type:"video",label:"Video",accept:["video/*"]},mn={library:[dn,gn],camera:[dn,gn],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"]}]},He,An=()=>(He!=null||(He=import("react-native-compressor").catch(()=>(He=void 0,null))),He),_n=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},Zo=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),Qo={low:640,medium:1280,high:1920},er=async(e,{image:t})=>{var o;if(!t||!Zo.has(e.mime_type.toLowerCase()))return e;let n=await An();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 _n(n,r,e.size),processed:!0}}catch{return e}},tr=async(e,{video:t})=>{var o;let n=await An();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:Qo[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await _n(n,r,e.size),processed:!0}}catch{return e}},nr={image:er,video:tr},or=(e,t)=>t.split(".").reduce((n,o)=>xe(n)?n[o]:void 0,e),Ct=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new u("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new u("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([g,A])=>l.append(g,A)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let p=g=>{o.removeEventListener("abort",s),g()};c.open("POST",a.url),Object.entries(a.headers).forEach(([g,A])=>c.setRequestHeader(g,A)),c.upload.onprogress=g=>n(g.loaded,g.total||e.size||0),c.onload=()=>p(()=>{let g=c.responseText;try{g=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new u("UPLOAD_FAILED",`HTTP ${c.status}`));return}let A=or(g,a.url_field);if(typeof A!="string"||!A){i(new u("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:A,response:g})}),c.onerror=()=>p(()=>i(new u("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>p(()=>i(new u("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),bn=e=>{var o,r;let t={...wn};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:Ct};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}},Sn=e=>{let{sources:t,targets:n}=bn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===wn[i]&&mn[i]).map(i=>[i,mn[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Pt}},lt=new Map,vn=(e,t)=>`${e}:${t}`,rr=0,Mn=(e,t)=>{var n;typeof t=="string"&&((n=lt.get(vn(e,t)))==null||n.abort())},Le=e=>{for(let[t,n]of lt)t.startsWith(`${e}:`)&&n.abort()},ct=()=>new u("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),ir=(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)}},xn=async(e,t)=>{var l;let{sources:n,targets:o}=bn(t.config),r=n[e.source];if(!r)throw new u("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 u("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=vn(t.instance_id,(l=t.task_id)!=null?l:`auto-${++rr}`);lt.set(c,a);try{return await sr(e,t,r,i,a.signal)}finally{lt.delete(c)}},sr=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=g=>g()},l,s,p)=>{var re,ie,m;let g={app_id:n!=null?n:"",instance_id:t,context:{...(re=o==null?void 0:o())!=null?re:{}}},A=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:g}))).slice(0,e.max_count);if(p.aborted)throw ct();if(!A.length)throw new u("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let d=[],h=A.filter(w=>jo(w,e.accept)?!0:(d.push({name:w.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${w.mime_type||yn(w.name)}`}),!1)),k=h.map(()=>0),E=h.map(w=>{var P;return(P=w.size)!=null?P:0}),R=0,v=0,_=(w=!1)=>{if(!a||!r)return;let P=Date.now();if(!w&&P-v<200)return;v=P;let I=E.reduce((U,G)=>U+G,0),j=k.reduce((U,G)=>U+G,0);a("upload.progress",{task_id:r,loaded:j,total:I,percent:I?Math.min(100,Math.round(j/I*100)):0,done_count:R,count:h.length})},Y=[],Z=0,ne=async()=>{var w,P,I;for(;Z<h.length;){let j=Z++,U=h[j];try{if(p.aborted)throw ct();let G=U.mime_type.startsWith("image/")?"image":U.mime_type.startsWith("video/")?"video":void 0,Se=G&&!U.processed?(P=(w=i==null?void 0:i.processors)==null?void 0:w[G])!=null?P:nr[G]:void 0;if(Se&&(U=await Se(U,e.process),E[j]=(I=U.size)!=null?I:E[j],p.aborted))throw ct();if(e.max_size&&U.size&&U.size>e.max_size)throw new u("FILE_TOO_LARGE",`File ${U.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let ye=(Ae,O)=>{k[j]=Ae,O&&(E[j]=O),_()},Q=await s({file:U,target:e.target,onProgress:ye,signal:p,caller:g});if(typeof(Q==null?void 0:Q.url)!="string"||!Q.url)throw new u("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:ve,...we}=Q;Y[j]={url:ve,name:U.name,mime_type:U.mime_type,size:U.size,width:U.width,height:U.height,duration:U.duration,...Object.keys(we).length?{response:"response"in we?we.response:we}:{}},k[j]=E[j]}catch(G){d.push(ir(h[j].name,G))}finally{R++,_(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,h.length)},ne)),p.aborted)throw ct();let oe=Y.filter(w=>!!w);if(!oe.length){let w=d[0];throw new u((ie=w==null?void 0:w.code)!=null?ie:"UPLOAD_FAILED",(m=w==null?void 0:w.message)!=null?m:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:oe,failed:d}};var Tn=require("react-native");var Ie=require("react-native");var ce,En=()=>Ie.Platform.OS==="android"&&!!(ce!=null&&ce.requesting_permission),ar=1500,pt=()=>new Promise(e=>{if(Ie.Platform.OS!=="android"||Ie.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,ar),o=Ie.AppState.addEventListener("change",r=>{r==="active"&&t()})}),Tt=e=>{var t;if(ce===e&&(ce=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Ie.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Rn=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(ce)throw new u("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new u("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};ce=r;try{let p;try{p=await import("expo-speech-recognition")}catch{throw new u("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let g=p.ExpoSpeechRecognitionModule;if(r.native=g,r.cancelled||!o())throw new u("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let A;try{A=await g.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await pt(),r.cancelled||!o())throw new u("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!A.granted)throw new u("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await g.getStateAsync()!=="inactive")throw new u("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 u("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(g.addListener("result",d=>{var h,k;ce!==r||r.cancelled||n(d.isFinal?"speech.final":"speech.partial",{...d,text:(k=(h=d.results[0])==null?void 0:h.transcript)!=null?k:""})}),g.addListener("error",d=>{ce===r&&!r.cancelled&&n("speech.error",{...d,code:d.error})}),g.addListener("end",()=>{ce===r&&(Tt(r),n("speech.end"))})),r.started=!0,g.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:p.AVAudioSessionCategory.playAndRecord,categoryOptions:[p.AVAudioSessionCategoryOptions.defaultToSpeaker,p.AVAudioSessionCategoryOptions.allowBluetooth],mode:p.AVAudioSessionMode.measurement}})}catch(p){throw Tt(r),p}},Pn=e=>{let t=ce;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},fe=e=>{let t=ce;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{Tt(t)}};var ut=require("react"),Ue=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)})}},H=(e,t,n=Object.is)=>{let o=(0,ut.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,ut.useSyncExternalStore)(e.subscribe,r)};var On={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"},J={...On,all:Object.values(On)},Ve={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},dt={result:"scanner.result",end:"scanner.end"},Fe={user:"user",web:"web",closed:"closed",error:"error"},he={top:"top",full:"full"},De={once:"once",continuous:"continuous"},cr=1500,Cn=6e4,D,z=Ue({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),kn=()=>Tn.Platform.OS==="android"&&!!(D!=null&&D.requesting_permission),Lt=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=>J.all.includes(a)))throw new u("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>Cn)throw new u("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${Cn}`);i.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new u("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");i.hint=o}if(r!==void 0){if(!Object.values(he).includes(r))throw new u("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");i.layout=r}return i},It=e=>D!==e?!1:(D=void 0,z.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Ln=async(e,t)=>{if(D)throw new u("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new u("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");D=e;let n=()=>{if(e.cancelled||!t())throw new u("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new u("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n(),e.requesting_permission=!0;let r;try{r=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await pt(),n(),r!=="granted")throw new u("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera");if(!o.Camera.getAvailableCameraDevices().some(i=>i.position==="back"))throw new u("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");z.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,hint:e.hint,vision:o},last_value:null,scan_count:0,notice:null})}catch(o){throw It(e),o}},In=(e,t,n)=>{var o,r,i;return{owner:e,mode:t,types:(o=n.types)!=null?o:J.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:cr,hint:n.hint,layout:t===De.once?he.full:(i=n.layout)!=null?i:he.top,cancelled:!1,requesting_permission:!1,last_seen:new Map}},Fn=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=In(e,De.once,t);a.onHit=o,a.resolve=r,a.reject=i,Ln(a,n).catch(i)}),Dn=(e,t,n,o=()=>!0,r)=>{let i=In(e,De.continuous,t);return i.emit=n,i.onHit=r,Ln(i,o)},gt=(e,t,n)=>{var o,r;if(!z.getState().active){e.cancelled=!0;return}if(It(e)){if(e.mode===De.once){(o=e.reject)==null||o.call(e,t===Fe.error?new u("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new u("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,dt.end,n?{reason:t,message:n}:{reason:t})}},Nn=e=>{(D==null?void 0:D.owner)===e&>(D,Fe.web)},Ee=e=>{(D==null?void 0:D.owner)===e&>(D,Fe.closed)},Ft=()=>{D&>(D,Fe.user)},Un=e=>{D&>(D,Fe.error,e)},Dt=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=D;if(!(!o||!z.getState().active))for(let{value:c,type:l}of e){if(!c)continue;let s=o.last_seen.get(c);if(!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if(o.last_seen.set(c,t),(r=o.onHit)==null||r.call(o),o.mode===De.once){It(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}z.setState(p=>({last_value:c,hit_tick:p.hit_tick+1,scan_count:p.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,dt.result,{value:c,type:l})}}},lr={1:J.code128,2:J.code39,4:J.code93,8:J.codabar,16:J.dataMatrix,32:J.ean13,64:J.ean8,128:J.itf,256:J.qr,512:J.upcA,1024:J.upcE,2048:J.pdf417,4096:J.aztec},pr=2500,kt=e=>{z.setState({notice:e}),setTimeout(()=>{z.getState().notice===e&&z.setState({notice:null})},pr)},Vn=async()=>{var t,n;let e=D;if(!(!e||z.getState().is_picking)){e.requesting_permission=!0,z.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||D!==e)return;if(r.errorCode||!i){kt("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(D!==e)return;let l=c.map(({value:s,format:p})=>({value:s,code_type:lr[p]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:p})=>({value:s,type:p!=null?p:"unknown"}));if(!l.length){kt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}Dt(l,Date.now(),!0)}catch{D===e&&kt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await pt(),e.requesting_permission=!1,D===e&&z.setState({is_picking:!1})}}};var ft=1,u=class extends Error{constructor(n,o){super(o);this.code=n}},Bn=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===ft&&typeof t.method=="string"?t:null}catch{return null}},Ge=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,qn=(e,t)=>Ge({id:e,result:t}),$n=(e,t)=>Ge({id:e,error:{code:t.code,message:t.message}}),zn=(e,t)=>Ge({event:e,data:t}),Ut=e=>Ge({event:"context",data:e});var Wn=()=>`(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: ${ft}, 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;`,jn=()=>`(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: ${ft}, 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;`,Hn=()=>`(function () {
|
|
42
42
|
if (window.__retionSafeAreaFrozen) { return; }
|
|
43
43
|
window.__retionSafeAreaFrozen = true;
|
|
44
44
|
var max = {};
|
|
@@ -59,8 +59,24 @@
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
|
-
})(); true;`,
|
|
63
|
-
${
|
|
62
|
+
})(); true;`,Jn=e=>Ge({event:e}),Kn=(e,t)=>{let n=Yn(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
|
|
63
|
+
${Ut(e)}`},Yn=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),Gn=(e,t={})=>{let n=Yn(t);return`window.__RETION_MINIAPP_HOST__ = { protocol: ${ft} };
|
|
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;`},qn={partner:"partner_token",chatbox:"chatbox_token"},Vn=(e,t)=>{let n={...e};for(let r of Object.values(qn))t.includes(r)||delete n[r];return n},Pt=new Set,ze=async(e,t)=>{if(Pt.has(e))throw new u("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);Pt.add(e);try{return await t()}finally{Pt.delete(e)}},Xr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),st=(e,t)=>{if(typeof e!="string"||!e)throw new u("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},jn=async({method:e,params:t},{getHostData:n,getPermissions:r,getContext:o,is_dark:i,close:a,app_id:l,instance_id:c,options:s,emit:d,isActive:g})=>{var T,v,_,b,w,z,ne,ae,Me;let y=s==null?void 0:s.handlers,p={app_id:l,instance_id:c,close:a},f=()=>new u("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let h=Gt(t);return ze(e,()=>Xt(h,g))}case"speech.start":{if(!d)throw f();let h={};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 u("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");h.lang=t.lang}for(let M of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[M])!==void 0){if(typeof t[M]!="boolean")throw new u("INVALID_PARAMS",`${M} ph\u1EA3i l\xE0 boolean`);h[M]=t[M]}return yn(c,h,d,g)}case"speech.stop":return wn(c);case Ie.scan:return xn(c,_t(t),g,()=>{var h;return(h=s==null?void 0:s.haptic)==null?void 0:h.call(s,"notificationSuccess")});case Ie.start:{if(!d)throw f();return En(c,_t(t),d,g,()=>{var h;return(h=s==null?void 0:s.haptic)==null?void 0:h.call(s,"notificationSuccess")})}case Ie.stop:return Pn(c);case"uploadFiles":{let{task_id:h,...M}=t!=null?t:{};if(h!==void 0&&(typeof h!="string"||!h))throw new u("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return fn(sn(M),{instance_id:c,app_id:l,getContext:o,task_id:h,config:s==null?void 0:s.upload,emit:d,exclusivePick:V=>ze("uploadFiles.pick",V)})}case"uploadFiles.cancel":mn(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 wt()).getAvailability();case"authenticateBiometric":{let h=st(t==null?void 0:t.reason,"reason").trim();if(!h||h.length>200)throw new u("INVALID_PARAMS","reason must contain 1\u2013200 characters");let M=t==null?void 0:t.cancelButtonText;if(M!==void 0&&(typeof M!="string"||!M.trim()||M.length>80))throw new u("INVALID_PARAMS","Invalid cancelButtonText");return ze(e,async()=>{var P;return((P=s==null?void 0:s.biometrics)!=null?P:await wt()).authenticate({reason:h,cancelButtonText:M})})}case"requestPayment":{let h=y==null?void 0:y.requestPayment;if(!h)throw f();let M=t==null?void 0:t.amount;if(typeof M!="number"||!Number.isFinite(M)||M<=0)throw new u("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let V={...t,amount:M,currency:st(t==null?void 0:t.currency,"currency")};return ze(e,()=>h(V,p))}case"printImage":{let h=y==null?void 0:y.printImage;if(!h)throw f();let M=st(t==null?void 0:t.image,"image");await ze(e,()=>h({image:M},p));return}case"openScreen":if(!(y!=null&&y.openScreen))throw f();await y.openScreen({screen:st(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},p);return;case"closeApp":a();return;case"openWebview":{let h=String((v=t==null?void 0:t.url)!=null?v:"");if(!/^https?:\/\//i.test(h))throw new u("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(h):He.Linking.openURL(h));return}case"openLink":{let h=String((_=t==null?void 0:t.url)!=null?_:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(h)||/^(javascript|file|data|about|blob):/i.test(h))throw new u("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(h):He.Linking.openURL(h))}catch(M){throw new u("NOT_SUPPORTED",String((w=(b=M==null?void 0:M.message)!=null?b:M)!=null?w:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":(ne=s==null?void 0:s.showToast)==null||ne.call(s,String((z=t==null?void 0:t.message)!=null?z:""));return;case"haptic":{let h=Xr.has(t==null?void 0:t.type)?t.type:"selection";(ae=s==null?void 0:s.haptic)==null||ae.call(s,h);return}case"getSystemInfo":return{platform:He.Platform.OS==="ios"?"ios":"android",appVersion:(Me=s==null?void 0:s.app_version)!=null?Me:"",theme:i?"dark":"light"};case"getAccessToken":{let h=n().access_token;if(!h)throw new u("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return h}case"getToken":{let h=t==null?void 0:t.type;if(h==="access"){let P=n().access_token;if(!P)throw new u("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return P}if(h!=="partner"&&h!=="chatbox")throw new u("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(h)}`);let M=qn[h];if(!r().includes(M))throw new u("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${M} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let V=h==="partner"?n().partner_token:n().chatbox_token;if(!V)throw new u("HOST_ERROR",`Kh\xF4ng c\xF3 ${M}`);return V}case"getUserInfo":{let h=n().user;if(!h)throw new u("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return h}case"getPageInfo":{let h=n().page;if(!h)throw new u("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return h}case"sendMessage":case"insertText":throw new u("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new u("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var Ct=e=>`bundle:${e}`,Tt=()=>`${k().file_system.document_dir}/miniapps`,kt=Tt,It=(e,t,n="index.html",r=!1,o=[])=>{let i=`${kt()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:r,permissions:o}},Ot=e=>{var t;k().storage.setString(Ct(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},Qr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,C=e=>{let t=k().storage.getString(Ct(e));if(!t)return null;try{let{version:n,entry:r,context_update:o,permissions:i}=JSON.parse(t);return It(e,n,r,!!o,Array.isArray(i)?i:[])}catch{return null}},me=e=>k().file_system.exists(e.entry_uri.replace("file://","")),Lt=async e=>{let t=C(e.app_id);return(t==null?void 0:t.version)===e.version&&await me(t)},Hn=async(e,t)=>{let n=k().file_system,r=`${kt()}/${e}`,o=await n.listDir(r).catch(()=>[]);await Promise.all(o.filter(i=>!t.includes(i)).map(i=>n.remove(`${r}/${i}`).catch(()=>{})))},Wn=async e=>{var t;await((t=Ye[e])==null?void 0:t.catch(()=>{})),k().storage.setString(Ct(e),""),await k().file_system.remove(`${kt()}/${e}`).catch(()=>{})},Le=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},Ye={},Jn=(e,t)=>{var i;let r=((i=Ye[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),o=r.catch(()=>{});return Ye[e]=o,o.then(()=>{Ye[e]===o&&delete Ye[e]}),r},Zr=(e,t)=>{var o,i;let n=e.split(".").map(a=>parseInt(a,10)||0),r=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,r.length);a++){let l=((o=n[a])!=null?o:0)-((i=r[a])!=null?i:0);if(l)return l}return 0},Yn=({manifest:e,zip_path:t})=>Jn(e.app_id,async()=>{var i;let n=k().file_system,r=C(e.app_id);if(r&&Zr(r.version,e.version)>=0&&await me(r))return r;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let o=It(e.app_id,e.version,e.entry,!!e.context_update,(i=e.permissions)!=null?i:[]);return await n.remove(o.dir).catch(()=>{}),await n.mkdir(o.dir),await n.unzip(t,o.dir),Ot(e),Z("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),Hn(e.app_id,[e.version,r==null?void 0:r.version].filter(Boolean)),o}),Dt=(e,{base_url:t,onProgress:n}={})=>{let r=k().file_system,o=null,i=!1,a=`${r.cache_dir}/${e.app_id}-${e.version}.zip`,l=()=>{if(i)throw new Le},c=async()=>{var g;l();let s=C(e.app_id);if((s==null?void 0:s.version)===e.version&&await r.exists(s.dir))return Ot(e),C(e.app_id);l();let d=r.download({url:t?Qr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(y,p)=>{var T;let f=p>0?p:(T=e.size)!=null?T:0;f>0&&(n==null||n(Math.min(1,y/f)))}});o=d;try{let{status:y}=await d.promise;if(l(),y!==200)throw new Error(`bundle ${y}`);if(e.sha256)if(r.sha256){if(await r.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else Z("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);l();let p=It(e.app_id,e.version,e.entry,!!e.context_update,(g=e.permissions)!=null?g:[]);return await r.remove(p.dir).catch(()=>{}),await r.mkdir(p.dir),await r.unzip(a,p.dir),Ot(e),Hn(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),p}catch(y){throw i?new Le:y}finally{o=null,r.remove(a).catch(()=>{})}};return{promise:Jn(e.app_id,c),cancel:()=>{i=!0,o==null||o.cancel()}}},Je={},eo=__DEV__?0:60*1e3,zn={},Kn=(e,t)=>{var r,o;let n=C(e);return n&&Date.now()-((r=zn[t])!=null?r:0)<eo?Promise.resolve(n):((o=Je[e])!=null||(Je[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 Dt(a,{base_url:t}).promise;return zn[t]=Date.now(),l})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),C(e))).finally(()=>{Je[e]=void 0})),Je[e])};var ct=new Map,Gn=(e,t)=>(ct.set(e,t),()=>{ct.get(e)===t&&ct.delete(e)}),Xn=(e,t)=>{let n=ct.get(e);return n?n(t):!1};var ue=require("react"),N=require("react-native");var Y=require("react/jsx-runtime"),to="#22C55E",Nt=({scanner:e})=>{let{vision:t,types:n,mode:r}=e,o=t.useCameraDevice("back"),[i,a]=(0,ue.useState)(!1),l=W(pe,p=>p.last_value),c=W(pe,p=>p.hit_tick),s=(0,ue.useRef)(new N.Animated.Value(0)).current,d=t.useCodeScanner({codeTypes:n,onCodeScanned:(0,ue.useCallback)(p=>On(p),[])});(0,ue.useEffect)(()=>{let p=N.BackHandler.addEventListener("hardwareBackPress",()=>(Et(),!0));return()=>p.remove()},[]);let g=(0,ue.useRef)(c);(0,ue.useEffect)(()=>{if(c===g.current)return;s.setValue(1);let p=N.Animated.timing(s,{toValue:0,duration:350,useNativeDriver:!0});return p.start(),()=>p.stop()},[c,s]);let y=!!(o!=null&&o.hasTorch);return(0,Y.jsxs)(N.View,{style:r===ge.continuous?J.continuous:J.once,children:[o&&(0,Y.jsx)(t.Camera,{style:N.StyleSheet.absoluteFill,device:o,isActive:!0,codeScanner:d,torch:i&&y?"on":"off",onError:p=>Rn(p.message)}),(0,Y.jsxs)(N.View,{style:J.frame_wrap,pointerEvents:"none",children:[(0,Y.jsx)(N.View,{style:J.frame}),(0,Y.jsx)(N.Animated.View,{style:[J.frame,J.frame_hit,{opacity:s}]})]}),(0,Y.jsxs)(N.View,{style:J.footer,children:[(0,Y.jsx)(N.TouchableOpacity,{activeOpacity:.7,style:J.button,onPress:Et,accessibilityRole:"button",children:(0,Y.jsx)(N.Text,{style:J.button_text,children:"\u0110\xF3ng"})}),(0,Y.jsx)(N.Text,{style:J.last_value,numberOfLines:1,children:l!=null?l:""}),y&&(0,Y.jsx)(N.TouchableOpacity,{activeOpacity:.7,style:[J.button,i&&J.button_on],onPress:()=>a(p=>!p),accessibilityRole:"button",children:(0,Y.jsx)(N.Text,{style:[J.button_text,i&&J.button_text_on],children:"\u0110\xE8n"})})]})]})},J=N.StyleSheet.create({continuous:{height:"38%",backgroundColor:"#000000",overflow:"hidden"},once:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"#000000"},frame_wrap:{position:"absolute",top:0,left:0,right:0,bottom:0,alignItems:"center",justifyContent:"center"},frame:{width:"70%",aspectRatio:1.6,maxHeight:"60%",borderRadius:12,borderWidth:2,borderColor:"rgba(255,255,255,0.8)"},frame_hit:{position:"absolute",borderWidth:4,borderColor:to},footer:{position:"absolute",left:12,right:12,bottom:12,flexDirection:"row",alignItems:"center",gap:8},last_value:{flex:1,textAlign:"center",color:"#FFFFFF",fontWeight:"600"},button:{paddingHorizontal:14,paddingVertical:8,borderRadius:999,backgroundColor:"rgba(0,0,0,0.6)"},button_on:{backgroundColor:"#FFFFFF"},button_text:{color:"#FFFFFF",fontWeight:"600"},button_text_on:{color:"#18181B"}});var K=ke({active_key:null,instances:{}}),Qn=({app:e,instance_id:t,context:n={},url_params:r={},host_data:o={}},i)=>{var l;let a=(l=k().keep_alive)==null?void 0:l.max_webviews;K.setState(c=>{let s=t!=null?t:e.app_id,d={...c.instances,[s]:{key:s,app:e,context:n,url_params:r,host_data:o,last_used_at:Date.now()}},g=Object.keys(d);return a&&a>0&&g.length>a&&g.filter(y=>y!==s).sort((y,p)=>d[y].last_used_at-d[p].last_used_at).slice(0,g.length-a).forEach(y=>{delete d[y]}),i?{active_key:s,instances:d}:{instances:d}})},Zn=e=>Qn(e,!0),er=e=>Qn(e,!1),De=()=>K.setState({active_key:null}),lt=e=>{K.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var tr="catalog",no="paused_apps",ro="removed_apps",oo=10*1e3,io=2,so=3e3,ao=()=>{var e;try{return JSON.parse((e=k().storage.getString(tr))!=null?e:"{}")}catch{return{}}},O=ke({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),nr=e=>{var t;return!!((t=k().manual_update)!=null&&t.includes(e))},dt=new Set,rr=e=>{let t=new Set,n=()=>k().storage.setString(e,JSON.stringify([...t]));return{has:r=>t.has(r),values:()=>[...t],add:r=>t.has(r)?!1:(t.add(r),n(),!0),delete:r=>t.delete(r)?(n(),!0):!1,load:()=>{var r;t.clear();try{let o=JSON.parse((r=k().storage.getString(e))!=null?r:"[]");Array.isArray(o)&&o.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},se=rr(no),be=rr(ro);Jt(()=>{se.load(),be.load();let e=ao(),t={};Object.keys(e).filter(n=>!be.has(n)).forEach(n=>{let r=C(n);r?t[n]={status:"installed",progress:1,version:r.version,has_local:!0}:se.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),O.setState({catalog:e,downloads:t})});var gt=e=>W(O,t=>e?t.downloads[e]:void 0),or=()=>W(O,e=>e.pause_reasons.length>0),ie=(...e)=>Z("queue",...e),$=[],fe={},x=null,pt=new Set,Oe={},Ut=new Set,Ae=e=>{Ut.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},ir=e=>(Ut.add(e),()=>{Ut.delete(e)}),sr=()=>O.getState().downloads,G=(e,t)=>{let n=!!C(e),r=O.getState().downloads[e],o=t.status==="downloading"&&n?"updating":t.status,i={...r!=null?r:{status:"queued",progress:0},...t,...o?{status:o}:{},has_local:n};O.setState(a=>({downloads:{...a.downloads,[e]:i}})),(r==null?void 0:r.status)!==i.status||(r==null?void 0:r.version)!==i.version||(r==null?void 0:r.has_local)!==i.has_local?Ae({type:"status_change",app_id:e,state:i}):r.progress!==i.progress&&Ae({type:"progress",app_id:e,progress:i.progress,version:i.version})},ut=(e,t)=>{var n;(n=Oe[e])==null||n.forEach(r=>r(t)),delete Oe[e]},co=()=>O.getState().pause_reasons.length>0,Se=e=>{var l;if(x)return;let t=e?$.indexOf(e):co()?-1:$.findIndex(c=>!se.has(c));if(t<0||t>=$.length)return;let[n]=$.splice(t,1),r=O.getState().catalog[n];if(!r){ut(n,C(n)),Se();return}let o=Date.now();fe[n]=((l=fe[n])!=null?l:0)+1,G(n,{status:"downloading",progress:0,version:r.version,error:void 0});let i=0,a=Dt(r,{onProgress:c=>{let s=Math.floor(c*100);s!==i&&(i=s,G(n,{progress:s/100,version:r.version}))}});x={app_id:n,handle:a,forced:!!e},ie("start",n,r.version,e?"(forced)":""),a.promise.then(c=>{ie("installed",n,r.version,`${Date.now()-o}ms`),G(n,{status:"installed",progress:1,version:r.version}),ut(n,c)}).catch(c=>{var d;if(c instanceof Le){if(pt.has(n))return;ie("paused",n),fe[n]-=1,$.unshift(n),G(n,{status:se.has(n)?"paused":"queued",progress:0,version:r.version});return}let s=String((d=c==null?void 0:c.message)!=null?d:c);if(console.warn("[miniapp-queue] failed",n,s),fe[n]<io){G(n,{status:"queued",progress:0,version:r.version,error:s}),setTimeout(()=>{var g;$.includes(n)||(x==null?void 0:x.app_id)===n||($.push(n),Se((g=Oe[n])!=null&&g.length?n:void 0))},so);return}G(n,{status:"failed",progress:0,version:r.version,error:s}),ut(n,C(n))}).finally(()=>{x=null;let c=$.find(s=>{var d;return(d=Oe[s])==null?void 0:d.length});Se(c)})},mt=(e,{front:t=!1}={})=>{if((x==null?void 0:x.app_id)===e)return;let n=$.indexOf(e);if(n>=0){if(!t)return;$.splice(n,1)}t?$.unshift(e):$.push(e)},lo=async e=>{let{host_id:t,client_token:n}=k(),r=new AbortController,o=setTimeout(()=>r.abort(),oo);try{let i=`${Qe}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:r.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(c=>({...c,channel:e}))}finally{clearTimeout(o)}},Ke=null,ft=()=>(Ke!=null||(Ke=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(k().channels.map(lo)),r={};[...n].reverse().flat().forEach(c=>{r[c.app_id]=c});let o=Object.keys(O.getState().catalog).filter(c=>!r[c]);k().storage.setString(tr,JSON.stringify(r)),O.setState({catalog:r}),await Promise.all(o.map(c=>ar(c,{by_user:!1}))),o.forEach(c=>be.delete(c));let i=Object.keys(r).filter(c=>!be.has(c)),a=[],l={};for(let c of i.map(s=>r[s])){if(await Lt(c)){G(c.app_id,{status:"installed",progress:1,version:c.version});continue}let s=C(c.app_id);if(nr(c.app_id)&&!dt.has(c.app_id)&&s&&await me(s)){G(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=>{fe[c.app_id]=0,G(c.app_id,{status:se.has(c.app_id)?"paused":"queued",progress:0,version:c.version,error:void 0}),mt(c.app_id)}),ie("catalog",i.length,"apps, outdated",a.map(c=>c.app_id),"removed",o,`${Date.now()-e}ms`),Ae({type:"sync_complete",app_ids:i,removed:o}),Object.values(l).forEach(c=>Ae({type:"update_available",...c})),Se(),{ok:!0,app_ids:i,removed:o}}catch(n){let r=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",r),Ae({type:"sync_failed",error:r}),{ok:!1,error:r}}finally{Ke=null}})()),Ke),ar=async(e,{by_user:t})=>{var o,i,a,l;if(t&&be.add(e),pt.has(e))return;pt.add(e),se.delete(e);let n=$.indexOf(e);n>=0&&$.splice(n,1),(x==null?void 0:x.app_id)===e&&x.handle.cancel();let r=(l=(a=(o=O.getState().downloads[e])==null?void 0:o.version)!=null?a:(i=C(e))==null?void 0:i.version)!=null?l:"";G(e,{status:"uninstalling",progress:0,version:r}),await Wn(e),lt(e),O.setState(c=>{let s={...c.downloads};return delete s[e],{downloads:s}}),delete fe[e],pt.delete(e),ut(e,null),ie("uninstalled",e,t?"(user)":"(not in list)"),Ae({type:"uninstalled",app_id:e})},cr=e=>ar(e,{by_user:!0}),lr=e=>{let t=Ne(e);return t?(be.delete(e),(x==null?void 0:x.app_id)===e||$.includes(e)||(fe[e]=0,G(e,{status:se.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),mt(e),Se(),ie("restore",e)),!0):!1},pr=e=>{if(se.has(e))return;if(se.add(e),ie("pause app",e),(x==null?void 0:x.app_id)===e&&!x.forced){x.handle.cancel();return}let t=O.getState().downloads[e];$.includes(e)&&t&&G(e,{status:"paused",progress:0,version:t.version})},ur=e=>{if(!se.delete(e))return;ie("resume app",e);let t=O.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!$.includes(e)&&Ne(e)&&(fe[e]=0,mt(e)),$.includes(e)&&t&&G(e,{status:"queued",progress:0,version:t.version}),Se()},dr=e=>{let{pause_reasons:t}=O.getState();t.includes(e)||(O.setState({pause_reasons:[...t,e]}),ie("pause",e),t.length===0&&Ae({type:"pause_change",paused:!0,reasons:[e]}),x&&!x.forced&&x.handle.cancel())},gr=e=>{let{pause_reasons:t}=O.getState();if(!t.includes(e))return;let n=t.filter(r=>r!==e);O.setState({pause_reasons:n}),ie("resume",e),n.length===0&&Ae({type:"pause_change",paused:!1,reasons:n}),Se()},Ft=e=>O.getState().updates[e],mr=async e=>{var n,r;let t=Ft(e);dt.add(e);try{let o=await Ge(e),i=(r=t==null?void 0:t.next_version)!=null?r:(n=Ne(e))==null?void 0:n.version;return!o||!i||o.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}}}),ie("updated",e,t==null?void 0:t.current_version,"\u2192",o.version),!0)}finally{dt.delete(e)}},fr=()=>Object.values(O.getState().catalog).map(e=>({...e,installed:!!C(e.app_id),removed_by_user:be.has(e.app_id)})),Ne=e=>O.getState().catalog[e],Ge=async e=>{let t=Ne(e);if(!t)return;if(se.delete(e),be.delete(e),await Lt(t))return C(e);let n=C(e);if(nr(e)&&!dt.has(e)&&n&&await me(n))return n;let r=new Promise(o=>{var i;((i=Oe[e])!=null?i:Oe[e]=[]).push(o)});return(x==null?void 0:x.app_id)===e?x.forced=!0:(fe[e]=0,mt(e,{front:!0}),x&&!x.forced?x.handle.cancel():Se(e)),r};var R=require("react/jsx-runtime"),$t=e=>(e!=null?e:"").replace(/\?[^#]*/,""),hr=0,po=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},uo=S.default.memo(({instance_key:e,is_active:t,is_front:n,is_dark:r,reload_tick:o,web_at_top:i,splash:a,bridge:l,opaque_background:c,allow_embedded_miniapps:s,onWebLoadEnd:d})=>{var qt,Vt;let g=(0,S.useRef)(null),y=(0,S.useRef)(!1),p=W(K,m=>m.instances[e]),f=p==null?void 0:p.app.app_id,T=p==null?void 0:p.app.manifest_url,v=p==null?void 0:p.context,_=p==null?void 0:p.url_params,b=W(pe,m=>{var A;return((A=m.active)==null?void 0:A.owner)===e?m.active:null}),[w,z]=(0,S.useState)(()=>f?C(f):null),[ne,ae]=(0,S.useState)(!1),[Me,h]=(0,S.useState)(0),[M,V]=(0,S.useState)(0),[P,D]=(0,S.useState)(!1),B=(0,S.useRef)(null),j=m=>{B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{B.current=null,D(!0)},m)};(0,S.useEffect)(()=>()=>{B.current&&clearTimeout(B.current)},[]),(0,S.useEffect)(()=>{if(!f||!t&&w)return;let m=!0;return ae(!1),(async()=>{let A=C(f),H=A?await me(A):!1;if(!m||(z(H?oe=>!oe||oe.version!==A.version||oe.permissions.join(",")!==A.permissions.join(",")?A:oe:null),__DEV__&&Date.now()-hr>1e4&&(hr=Date.now(),await ft()),!m))return;let he=await Ge(f),_e=he!==void 0?he:T?await Kn(f,T):C(f);if(m){if(!_e){ae(!0);return}z(oe=>oe!=null?oe:_e)}})(),()=>{m=!1}},[t,f,T,Me]),(0,S.useEffect)(()=>Gn(e,m=>g.current?(g.current.postMessage(m),!0):!1),[e]);let I=W(O,m=>{let A=f?m.downloads[f]:void 0;return(A==null?void 0:A.status)==="installed"?A.version:void 0});(0,S.useEffect)(()=>{if(t||!f||!w)return;let m=C(f);if(!m||m.version===w.version)return;let A=!0;return me(m).then(H=>{!A||!H||(Z(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",w.version,"\u2192",m.version),z(m))}),()=>{A=!1}},[t,f,I,w==null?void 0:w.version]);let X=W(O,m=>{var A;return f&&(A=m.apply_ticks[f])!=null?A:0});(0,S.useEffect)(()=>{if(!X||!f)return;let m=C(f);if(!m||m.version===(w==null?void 0:w.version))return;let A=!0;return me(m).then(H=>{!A||!H||(Z(`webview:${e}`,"c\u1EADp nh\u1EADt",w==null?void 0:w.version,"\u2192",m.version),D(!1),z(m))}),()=>{A=!1}},[X]),(0,S.useEffect)(()=>{var H;let m=(H=k().keep_alive)==null?void 0:H.idle_close_ms;if(t||!m||m<=0)return;let A=setTimeout(()=>{lt(e)},m);return()=>clearTimeout(A)},[t,e]),(0,S.useEffect)(()=>{o>0&&(ae(!1),D(!1),V(m=>m+1),h(m=>m+1))},[o]);let Ue=(0,S.useRef)(t);(0,S.useEffect)(()=>{var m;Ue.current!==t&&(Ue.current=t,y.current&&((m=g.current)==null||m.injectJavaScript(Un(t?"resumed":"paused"))))},[t]);let ve=`${(qt=w==null?void 0:w.version)!=null?qt:"none"}:${(Vt=w==null?void 0:w.permissions.join(","))!=null?Vt:""}:${M}`,re=(0,S.useMemo)(()=>JSON.stringify([v!=null?v:{},_!=null?_:{}]),[v,_]),Fe=(0,S.useMemo)(()=>{var m;return Vn(_!=null?_:{},(m=w==null?void 0:w.permissions)!=null?m:[])},[re,w==null?void 0:w.permissions]),Ce=(0,S.useMemo)(()=>Bn(v!=null?v:{},Fe)+Dn()+(E.Platform.OS==="android"?Nn():"")+(k().debug?Ln():""),[Fe]),Te=(0,S.useRef)(null),$e=(0,S.useRef)(null);(0,S.useEffect)(()=>{var A,H,he;if(!w)return;if($e.current!==ve){$e.current=ve,Te.current=re;return}if(Te.current===re)return;let m=((H=JSON.parse((A=Te.current)!=null?A:"[]")[0])!=null?H:{}).org_id;if(Te.current=re,m===(v==null?void 0:v.org_id)&&y.current){D(!1),j(1500),(he=g.current)==null||he.injectJavaScript(Fn(v!=null?v:{},Fe));return}D(!1),V(_e=>_e+1)},[re,w,ve]),(0,S.useEffect)(()=>(t||(le(e),we(e),Ee(e)),()=>{le(e),we(e),Ee(e)}),[t,e,ve,o]),(0,S.useEffect)(()=>{let m=E.AppState.addEventListener("change",A=>{A==="background"&&!hn()&&le(e),A==="background"&&!Mn()&&we(e)});return()=>m.remove()},[e]);let Sr=(0,S.useCallback)(async m=>{var H,he,_e,oe,ht;let A=Cn(m.nativeEvent.data);if(!A){if(f&&(l!=null&&l.onWebEvent))try{Promise.resolve(l.onWebEvent(m.nativeEvent.data,{app_id:f,instance_id:e})).catch(L=>{console.warn("[miniapp] onWebEvent l\u1ED7i",f,L)})}catch(L){console.warn("[miniapp] onWebEvent l\u1ED7i",f,L)}return}if(A.method==="log"){let{level:L,text:q}=A;Z(`web:${e}`,L!=null?L:"log",q!=null?q:"");return}if(A.method==="pong"){B.current||D(!0);return}if(A.method==="touchAtTop"){i.emit(!!A.at_top);return}if(A.method==="contextApplied"){B.current&&clearTimeout(B.current),B.current=null,D(!0);return}if(A.method==="ready"){y.current=!0,D(!0);let L=(H=K.getState().instances[e])==null?void 0:H.context;L&&((he=g.current)==null||he.injectJavaScript(Rt(L)));return}try{let L=await jn(A,{getHostData:()=>{var q,Q;return(Q=(q=K.getState().instances[e])==null?void 0:q.host_data)!=null?Q:{}},getPermissions:()=>{var q,Q;return f?(Q=(q=C(f))==null?void 0:q.permissions)!=null?Q:[]:[]},getContext:()=>{var q,Q;return(Q=(q=K.getState().instances[e])==null?void 0:q.context)!=null?Q:{}},is_dark:r,close:De,app_id:f!=null?f:"",instance_id:e,options:l,emit:(q,Q)=>{var jt;(jt=g.current)==null||jt.injectJavaScript(In(q,Q))},isActive:()=>K.getState().active_key===e&&E.AppState.currentState!=="background"});A.id&&((_e=g.current)==null||_e.injectJavaScript(Tn(A.id,L)))}catch(L){if(!A.id)return;let q=L==null?void 0:L.code,Q=L instanceof u?L:new u(typeof q=="string"?q:"HOST_ERROR",String((oe=L==null?void 0:L.message)!=null?oe:L));(ht=g.current)==null||ht.injectJavaScript(kn(A.id,Q))}},[e,r,f,i,l]),br=(0,S.useCallback)(()=>{ae(!1),V(m=>m+1),h(m=>m+1)},[]);return(0,R.jsxs)(E.View,{style:[E.StyleSheet.absoluteFill,c&&{backgroundColor:r?"#09090B":"#FFFFFF"},!n&&te.behind],pointerEvents:t?"auto":"none",children:[(b==null?void 0:b.mode)===ge.continuous&&(0,R.jsx)(Nt,{scanner:b}),w?(0,R.jsx)(wr.default,{ref:g,source:{uri:w.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,allowingReadAccessToURL:`file://${s?Tt():w.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:Ce,onMessage:Sr,bounces:!1,overScrollMode:"never",onLoadStart:m=>{le(e),we(e),Ee(e),Z(`webview:${e}`,"load start",$t(m.nativeEvent.url)),y.current=!1,D(!1)},onError:m=>{le(e),we(e),Ee(e),Z(`webview:${e}`,"load error",$t(m.nativeEvent.url),m.nativeEvent.description),ae(!0),D(!1)},onLoadEnd:m=>{let A=m.nativeEvent.url;Z(`webview:${e}`,"load end",$t(A)),f&&(d==null||d({app_id:f,instance_id:e,url:A})),j(1500)},onContentProcessDidTerminate:()=>{le(e),we(e),Ee(e),y.current=!1,D(!1),V(m=>m+1)},onRenderProcessGone:()=>(le(e),we(e),Ee(e),y.current=!1,D(!1),V(m=>m+1),!0),style:te.webview},ve):null,(b==null?void 0:b.mode)===ge.once&&(0,R.jsx)(Nt,{scanner:b}),p&&(0,R.jsx)(mo,{visible:!w||!P,interactive:ne,children:(0,R.jsx)(go,{splash:a,app:p.app,is_dark:r,error:ne,has_bundle:!!w,retry:br})})]})}),go=S.default.memo(({splash:e,app:t,is_dark:n,error:r,has_bundle:o,retry:i})=>{let a=e,l=gt(t.app_id),c=r?"error":!o&&(l==null?void 0:l.status)==="downloading"?"downloading":"loading";return(0,R.jsx)(a,{app:t,is_dark:n,status:c,progress:c==="downloading"?l==null?void 0:l.progress:void 0,retry:i})}),mo=({visible:e,interactive:t,children:n})=>{let r=(0,S.useRef)(new E.Animated.Value(e?1:0)).current,[o,i]=(0,S.useState)(e);return(0,S.useEffect)(()=>{if(e){i(!0),r.setValue(1);return}let a=E.Animated.timing(r,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:l})=>{l&&i(!1)}),()=>a.stop()},[e,r]),o?(0,R.jsx)(E.Animated.View,{style:[E.StyleSheet.absoluteFill,{opacity:r}],pointerEvents:t?"auto":"none",children:n}):null},Bt=({app:e,is_dark:t,status:n,progress:r,retry:o})=>{let i=t?"#FAFAFA":"#18181B";return(0,R.jsxs)(E.View,{style:[te.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,R.jsx)(E.View,{style:[te.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,R.jsx)(E.Image,{source:{uri:e.icon},style:te.splash_icon_image}):(0,R.jsx)(E.Text,{style:te.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,R.jsx)(E.Text,{style:[te.splash_name,{color:i}],children:e.name}),n==="error"?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(E.Text,{style:te.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,R.jsx)(E.TouchableOpacity,{activeOpacity:.7,style:[te.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:o,children:(0,R.jsx)(E.Text,{style:[te.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(E.ActivityIndicator,{style:te.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,R.jsxs)(E.Text,{style:te.splash_hint,children:["\u0110ang t\u1EA3i mini app",r?` ${Math.round(r*100)}%`:"\u2026"]})]})]})},yr=(e,t)=>{let n=(0,S.useRef)(t),r=(0,S.useRef)(!1);__DEV__&&!r.current&&n.current!==t&&(r.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.`))},fo=({container:e,splash:t=Bt,is_dark:n=!1,bridge:r,close_on_back:o=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:l})=>{yr("container",e),yr("splash",t);let c=e,s=W(K,b=>b.active_key),d=(0,S.useRef)(s);s&&(d.current=s);let g=W(K,b=>Object.keys(b.instances).join("|")),y=W(K,b=>{var w;return b.active_key?(w=b.instances[b.active_key])==null?void 0:w.app.name:void 0}),p=(0,S.useMemo)(()=>g?g.split("|"):[],[g]),[f,T]=(0,S.useState)({}),v=(0,S.useRef)(po()).current;(0,S.useEffect)(()=>{if(!s||!o)return;let b=E.BackHandler.addEventListener("hardwareBackPress",()=>(De(),!0));return()=>b.remove()},[s,o]);let _=(0,S.useCallback)(()=>{let b=K.getState().active_key;b&&T(w=>({...w,[b]:(w[b]||0)+1}))},[]);return p.length?(0,R.jsx)(c,{visible:!!s,title:y!=null?y:"",is_dark:n,close:De,reload:_,subscribeWebAtTop:v.subscribe,children:p.map(b=>(0,R.jsx)(uo,{instance_key:b,is_active:s===b,is_front:(s!=null?s:d.current)===b,is_dark:n,reload_tick:f[b]||0,web_at_top:v,splash:t,bridge:r,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:l},b))}):null},te=E.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"}}),Ar=S.default.memo(fo);0&&(module.exports={CodeType,DefaultMiniAppSplash,MINIAPP_PLATFORM_URL,MiniAppHost,MiniAppHostError,ScannerEndReason,ScannerEvent,ScannerMethod,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});
|
|
66
|
+
true;`},Xn={partner:"partner_token",chatbox:"chatbox_token"},Zn=(e,t)=>{let n={...e};for(let o of Object.values(Xn))t.includes(o)||delete n[o];return n},Nt=new Set,Ke=async(e,t)=>{if(Nt.has(e))throw new u("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);Nt.add(e);try{return await t()}finally{Nt.delete(e)}},Qn=()=>`(function () {
|
|
67
|
+
try {
|
|
68
|
+
var AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
69
|
+
if (!AudioCtx) { return; }
|
|
70
|
+
var ctx = window.__retionBeepCtx || (window.__retionBeepCtx = new AudioCtx());
|
|
71
|
+
if (ctx.state === 'suspended') { ctx.resume(); }
|
|
72
|
+
var oscillator = ctx.createOscillator();
|
|
73
|
+
var gain = ctx.createGain();
|
|
74
|
+
oscillator.type = 'square';
|
|
75
|
+
oscillator.frequency.value = 2000;
|
|
76
|
+
gain.gain.value = 0.15;
|
|
77
|
+
oscillator.connect(gain);
|
|
78
|
+
gain.connect(ctx.destination);
|
|
79
|
+
oscillator.start(ctx.currentTime);
|
|
80
|
+
oscillator.stop(ctx.currentTime + 0.08);
|
|
81
|
+
} catch (e) {}
|
|
82
|
+
})(); true;`,ur=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),mt=(e,t)=>{if(typeof e!="string"||!e)throw new u("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},eo=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:p,isActive:g,playBeep:A})=>{var R,v,_,Y,Z,ne,oe,re,ie;let d=s==null?void 0:s.handlers,h={app_id:c,instance_id:l,close:a},k=()=>{var m;(m=s==null?void 0:s.haptic)==null||m.call(s,"impactLight"),A==null||A()},E=()=>new u("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let m=an(t);return Ke(e,()=>cn(m,g))}case"speech.start":{if(!p)throw E();let m={};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 u("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");m.lang=t.lang}for(let w of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[w])!==void 0){if(typeof t[w]!="boolean")throw new u("INVALID_PARAMS",`${w} ph\u1EA3i l\xE0 boolean`);m[w]=t[w]}return Rn(l,m,p,g)}case"speech.stop":return Pn(l);case Ve.scan:return Fn(l,Lt(t),g,k);case Ve.start:{if(!p)throw E();return Dn(l,Lt(t),p,g,k)}case Ve.stop:return Nn(l);case"uploadFiles":{let{task_id:m,...w}=t!=null?t:{};if(m!==void 0&&(typeof m!="string"||!m))throw new u("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return xn(hn(w),{instance_id:l,app_id:c,getContext:r,task_id:m,config:s==null?void 0:s.upload,emit:p,exclusivePick:P=>Ke("uploadFiles.pick",P)})}case"uploadFiles.cancel":Mn(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Sn(s==null?void 0:s.upload);case"getBiometricAvailability":return((R=s==null?void 0:s.biometrics)!=null?R:await Rt()).getAvailability();case"authenticateBiometric":{let m=mt(t==null?void 0:t.reason,"reason").trim();if(!m||m.length>200)throw new u("INVALID_PARAMS","reason must contain 1\u2013200 characters");let w=t==null?void 0:t.cancelButtonText;if(w!==void 0&&(typeof w!="string"||!w.trim()||w.length>80))throw new u("INVALID_PARAMS","Invalid cancelButtonText");return Ke(e,async()=>{var I;return((I=s==null?void 0:s.biometrics)!=null?I:await Rt()).authenticate({reason:m,cancelButtonText:w})})}case"requestPayment":{let m=d==null?void 0:d.requestPayment;if(!m)throw E();let w=t==null?void 0:t.amount;if(typeof w!="number"||!Number.isFinite(w)||w<=0)throw new u("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let P={...t,amount:w,currency:mt(t==null?void 0:t.currency,"currency")};return Ke(e,()=>m(P,h))}case"printImage":{let m=d==null?void 0:d.printImage;if(!m)throw E();let w=mt(t==null?void 0:t.image,"image");await Ke(e,()=>m({image:w},h));return}case"openScreen":if(!(d!=null&&d.openScreen))throw E();await d.openScreen({screen:mt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},h);return;case"closeApp":a();return;case"openWebview":{let m=String((v=t==null?void 0:t.url)!=null?v:"");if(!/^https?:\/\//i.test(m))throw new u("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(m):Ye.Linking.openURL(m));return}case"openLink":{let m=String((_=t==null?void 0:t.url)!=null?_:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(m)||/^(javascript|file|data|about|blob):/i.test(m))throw new u("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(m):Ye.Linking.openURL(m))}catch(w){throw new u("NOT_SUPPORTED",String((Z=(Y=w==null?void 0:w.message)!=null?Y:w)!=null?Z:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":(oe=s==null?void 0:s.showToast)==null||oe.call(s,String((ne=t==null?void 0:t.message)!=null?ne:""));return;case"haptic":{let m=ur.has(t==null?void 0:t.type)?t.type:"selection";(re=s==null?void 0:s.haptic)==null||re.call(s,m);return}case"getSystemInfo":return{platform:Ye.Platform.OS==="ios"?"ios":"android",appVersion:(ie=s==null?void 0:s.app_version)!=null?ie:"",theme:i?"dark":"light"};case"getAccessToken":{let m=n().access_token;if(!m)throw new u("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return m}case"getToken":{let m=t==null?void 0:t.type;if(m==="access"){let I=n().access_token;if(!I)throw new u("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return I}if(m!=="partner"&&m!=="chatbox")throw new u("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(m)}`);let w=Xn[m];if(!o().includes(w))throw new u("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${w} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let P=m==="partner"?n().partner_token:n().chatbox_token;if(!P)throw new u("HOST_ERROR",`Kh\xF4ng c\xF3 ${w}`);return P}case"getUserInfo":{let m=n().user;if(!m)throw new u("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return m}case"getPageInfo":{let m=n().page;if(!m)throw new u("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return m}case"sendMessage":case"insertText":throw new u("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new u("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var Bt=e=>`bundle:${e}`,qt=()=>`${V().file_system.document_dir}/miniapps`,$t=qt,zt=(e,t,n="index.html",o=!1,r=[])=>{let i=`${$t()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},Vt=e=>{var t;V().storage.setString(Bt(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},dr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,N=e=>{let t=V().storage.getString(Bt(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return zt(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},_e=e=>V().file_system.exists(e.entry_uri.replace("file://","")),Wt=async e=>{let t=N(e.app_id);return(t==null?void 0:t.version)===e.version&&await _e(t)},no=async(e,t)=>{let n=V().file_system,o=`${$t()}/${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=Ze[e])==null?void 0:t.catch(()=>{})),V().storage.setString(Bt(e),""),await V().file_system.remove(`${$t()}/${e}`).catch(()=>{})},Be=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},Ze={},ro=(e,t)=>{var i;let o=((i=Ze[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return Ze[e]=r,r.then(()=>{Ze[e]===r&&delete Ze[e]}),o},gr=(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},io=({manifest:e,zip_path:t})=>ro(e.app_id,async()=>{var i;let n=V().file_system,o=N(e.app_id);if(o&&gr(o.version,e.version)>=0&&await _e(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=zt(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),Vt(e),ae("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),no(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),jt=(e,{base_url:t,onProgress:n}={})=>{let o=V().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,c=()=>{if(i)throw new Be},l=async()=>{var g;c();let s=N(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return Vt(e),N(e.app_id);c();let p=o.download({url:t?dr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(A,d)=>{var k;let h=d>0?d:(k=e.size)!=null?k:0;h>0&&(n==null||n(Math.min(1,A/h)))}});r=p;try{let{status:A}=await p.promise;if(c(),A!==200)throw new Error(`bundle ${A}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else ae("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let d=zt(e.app_id,e.version,e.entry,!!e.context_update,(g=e.permissions)!=null?g:[]);return await o.remove(d.dir).catch(()=>{}),await o.mkdir(d.dir),await o.unzip(a,d.dir),Vt(e),no(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),d}catch(A){throw i?new Be:A}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:ro(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},Xe={},mr=__DEV__?0:60*1e3,to={},so=(e,t)=>{var o,r;let n=N(e);return n&&Date.now()-((o=to[t])!=null?o:0)<mr?Promise.resolve(n):((r=Xe[e])!=null||(Xe[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 jt(a,{base_url:t}).promise;return to[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),N(e))).finally(()=>{Xe[e]=void 0})),Xe[e])};var ht=new Map,ao=(e,t)=>(ht.set(e,t),()=>{ht.get(e)===t&&ht.delete(e)}),co=(e,t)=>{let n=ht.get(e);return n?n(t):!1};var K=require("react"),y=require("react-native");var x=require("react/jsx-runtime"),Qe="#22C55E",fr="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",hr=2,yt=18,yr=1600,et=14,wr=2e3,lo=2,qe=2e3,Ar=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:et},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:et},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:et},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:et}],po=({color:e})=>(0,x.jsx)(x.Fragment,{children:Ar.map((t,n)=>(0,x.jsx)(y.View,{style:[M.corner,t,{borderColor:e}]},n))}),Jt=({scanner:e})=>{var ve,we,Ae;let{vision:t,types:n,mode:o,layout:r,hint:i}=e,a=r===he.top,c=t.useCameraDevice("back"),[l,s]=(0,K.useState)(!1),[p,g]=(0,K.useState)(1),[A,d]=(0,K.useState)({width:0,height:0}),h=H(z,O=>O.last_value),k=H(z,O=>O.hit_tick),E=H(z,O=>O.scan_count),R=H(z,O=>O.notice),v=H(z,O=>O.is_picking),_=(0,K.useRef)(null),[Y,Z]=(0,K.useState)(0),ne=y.Platform.OS==="ios"?54:(ve=y.StatusBar.currentHeight)!=null?ve:0,oe=(0,K.useRef)(new y.Animated.Value(0)).current,re=(0,K.useRef)(new y.Animated.Value(0)).current,ie=(0,K.useRef)(new y.Animated.Value(0)).current,m=Math.round(A.width*(a?.8:.78)),w=Math.round(a?A.height*.46:m*.78),P=Math.round((A.height-w)/2),I=Math.round((A.width-m)/2),j=t.useCodeScanner({codeTypes:n,onCodeScanned:(0,K.useCallback)(O=>Dt(O),[])});(0,K.useEffect)(()=>{let O=y.BackHandler.addEventListener("hardwareBackPress",()=>(Ft(),!0));return()=>O.remove()},[]);let U=(0,K.useRef)(k);(0,K.useEffect)(()=>{if(k===U.current)return;oe.setValue(1),ie.setValue(1);let O=y.Animated.parallel([y.Animated.timing(oe,{toValue:0,duration:450,useNativeDriver:!0}),y.Animated.sequence([y.Animated.delay(wr),y.Animated.timing(ie,{toValue:0,duration:250,useNativeDriver:!0})])]);return O.start(),()=>O.stop()},[k,oe,ie]),(0,K.useEffect)(()=>{let O=ot=>y.Animated.timing(re,{toValue:ot,duration:yr,easing:y.Easing.inOut(y.Easing.quad),useNativeDriver:!0}),Ce=y.Animated.loop(y.Animated.sequence([O(1),O(0)]));return Ce.start(),()=>Ce.stop()},[re]);let G=!!(c!=null&&c.hasTorch),Se=(we=c==null?void 0:c.neutralZoom)!=null?we:1,ye=c?Math.min(Se*p,c.maxZoom):1,Q=(0,x.jsx)(y.Text,{style:[M.hint,!!R&&M.hint_notice],numberOfLines:1,children:(Ae=R!=null?R:i)!=null?Ae:fr});return(0,x.jsxs)(y.View,{ref:_,style:a?M.top:M.full,onLayout:({nativeEvent:{layout:O}})=>{var Ce;d({width:O.width,height:O.height}),(Ce=_.current)==null||Ce.measureInWindow((ot,rt)=>Z(rt))},children:[c&&(0,x.jsx)(t.Camera,{style:y.StyleSheet.absoluteFill,device:c,isActive:!v,codeScanner:j,torch:l&&G?"on":"off",zoom:ye,enableZoomGesture:!0,onError:O=>Un(O.message)}),A.height>0&&(0,x.jsxs)(y.View,{style:M.overlay,pointerEvents:"none",children:[(0,x.jsx)(y.View,{style:[M.dim_ring,{top:P-qe,left:I-qe,width:m+qe*2,height:w+qe*2}]}),(0,x.jsxs)(y.View,{style:{position:"absolute",top:P,left:I,width:m,height:w},children:[(0,x.jsx)(po,{color:"#FFFFFF"}),(0,x.jsx)(y.Animated.View,{style:[y.StyleSheet.absoluteFill,{opacity:oe}],children:(0,x.jsx)(po,{color:Qe})}),(0,x.jsxs)(y.Animated.View,{style:[M.scan_line_wrap,{transform:[{translateY:re.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,w-yt)]})}]}],children:[(0,x.jsx)(y.View,{style:M.scan_glow_outer}),(0,x.jsx)(y.View,{style:M.scan_glow_inner}),(0,x.jsx)(y.View,{style:M.scan_line})]})]}),(0,x.jsx)(y.View,{style:[M.hint_slot,a?{top:0,height:P-6,justifyContent:"flex-end"}:{top:P+w+20}],children:Q}),o===De.continuous&&!!h&&(0,x.jsx)(y.Animated.View,{style:[M.result_slot,a?M.result_slot_top:{top:P+w+52},{opacity:ie}],children:(0,x.jsxs)(y.View,{style:M.result,children:[(0,x.jsx)(y.View,{style:M.check_badge,children:(0,x.jsx)(y.View,{style:M.check_mark})}),(0,x.jsx)(y.Text,{style:M.result_text,numberOfLines:1,children:h}),(0,x.jsxs)(y.Text,{style:M.result_count,children:["\xB7 ",E," m\xE3"]})]})})]}),(0,x.jsxs)(y.TouchableOpacity,{activeOpacity:.7,style:[M.close_button,{top:Math.max(12,ne-Y+12)}],onPress:Ft,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[(0,x.jsx)(y.View,{style:[M.close_bar,M.close_bar_a]}),(0,x.jsx)(y.View,{style:[M.close_bar,M.close_bar_b]})]}),(0,x.jsx)(y.View,{style:[M.toolbar_wrap,!a&&M.toolbar_wrap_full],pointerEvents:"box-none",children:(0,x.jsxs)(y.View,{style:M.toolbar,children:[(0,x.jsx)(y.TouchableOpacity,{activeOpacity:.7,style:M.tool,onPress:Vn,disabled:v,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:(0,x.jsxs)(y.View,{style:M.image_icon,children:[(0,x.jsx)(y.View,{style:M.image_icon_dot}),(0,x.jsx)(y.View,{style:M.image_icon_hill})]})}),!!c&&c.maxZoom>=Se*lo&&(0,x.jsx)(y.TouchableOpacity,{activeOpacity:.7,style:[M.tool,p>1&&M.tool_on],onPress:()=>g(O=>O>1?1:lo),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:(0,x.jsxs)(y.Text,{style:[M.zoom_text,p>1&&M.zoom_text_on],children:[p,"x"]})}),G&&(0,x.jsx)(y.TouchableOpacity,{activeOpacity:.7,style:[M.tool,l&&M.tool_on],onPress:()=>s(O=>!O),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:l},children:(0,x.jsx)(y.Text,{style:[M.torch_icon,l&&M.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})},_r="rgba(0,0,0,0.5)",Ht=40,M=y.StyleSheet.create({top:{height:"38%",backgroundColor:"#000000",overflow:"hidden"},full:{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:qe,borderColor:_r,borderRadius:qe+et},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:yt,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:yt,borderRadius:yt/2,backgroundColor:Qe,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:Qe,opacity:.2},scan_line:{height:hr,borderRadius:1,backgroundColor:Qe},close_button:{position:"absolute",right:12,width:42,height:42,borderRadius:21,alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:18,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_wrap_full:{bottom:y.Platform.OS==="ios"?34:20},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)",borderWidth:y.StyleSheet.hairlineWidth,borderColor:"rgba(255,255,255,0.18)"},tool:{width:Ht,height:Ht,borderRadius:Ht/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:14,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:18,fontWeight:"600"},image_icon:{width:19,height:15,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:2,right:2,width:3,height:3,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:1,bottom:-5,width:10,height:10,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result_slot_top:{top:8},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:Qe},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 ee=Ue({active_key:null,instances:{}}),uo=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=V().keep_alive)==null?void 0:c.max_webviews;ee.setState(l=>{let s=t!=null?t:e.app_id,p={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},g=Object.keys(p);return a&&a>0&&g.length>a&&g.filter(A=>A!==s).sort((A,d)=>p[A].last_used_at-p[d].last_used_at).slice(0,g.length-a).forEach(A=>{delete p[A]}),i?{active_key:s,instances:p}:{instances:p}})},go=e=>uo(e,!0),mo=e=>uo(e,!1),$e=()=>ee.setState({active_key:null}),wt=e=>{ee.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var fo="catalog",br="paused_apps",Sr="removed_apps",vr=10*1e3,Mr=2,xr=3e3,Er=()=>{var e;try{return JSON.parse((e=V().storage.getString(fo))!=null?e:"{}")}catch{return{}}},F=Ue({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),ho=e=>{var t;return!!((t=V().manual_update)!=null&&t.includes(e))},bt=new Set,yo=e=>{let t=new Set,n=()=>V().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=V().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},ge=yo(br),Oe=yo(Sr);on(()=>{ge.load(),Oe.load();let e=Er(),t={};Object.keys(e).filter(n=>!Oe.has(n)).forEach(n=>{let o=N(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:ge.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),F.setState({catalog:e,downloads:t})});var St=e=>H(F,t=>e?t.downloads[e]:void 0),wo=()=>H(F,e=>e.pause_reasons.length>0),de=(...e)=>ae("queue",...e),W=[],be={},C=null,At=new Set,Ne={},Kt=new Set,Re=e=>{Kt.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Ao=e=>(Kt.add(e),()=>{Kt.delete(e)}),_o=()=>F.getState().downloads,te=(e,t)=>{let n=!!N(e),o=F.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};F.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?Re({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Re({type:"progress",app_id:e,progress:i.progress,version:i.version})},_t=(e,t)=>{var n;(n=Ne[e])==null||n.forEach(o=>o(t)),delete Ne[e]},Rr=()=>F.getState().pause_reasons.length>0,Pe=e=>{var c;if(C)return;let t=e?W.indexOf(e):Rr()?-1:W.findIndex(l=>!ge.has(l));if(t<0||t>=W.length)return;let[n]=W.splice(t,1),o=F.getState().catalog[n];if(!o){_t(n,N(n)),Pe();return}let r=Date.now();be[n]=((c=be[n])!=null?c:0)+1,te(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=jt(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,te(n,{progress:s/100,version:o.version}))}});C={app_id:n,handle:a,forced:!!e},de("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{de("installed",n,o.version,`${Date.now()-r}ms`),te(n,{status:"installed",progress:1,version:o.version}),_t(n,l)}).catch(l=>{var p;if(l instanceof Be){if(At.has(n))return;de("paused",n),be[n]-=1,W.unshift(n),te(n,{status:ge.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((p=l==null?void 0:l.message)!=null?p:l);if(console.warn("[miniapp-queue] failed",n,s),be[n]<Mr){te(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var g;W.includes(n)||(C==null?void 0:C.app_id)===n||(W.push(n),Pe((g=Ne[n])!=null&&g.length?n:void 0))},xr);return}te(n,{status:"failed",progress:0,version:o.version,error:s}),_t(n,N(n))}).finally(()=>{C=null;let l=W.find(s=>{var p;return(p=Ne[s])==null?void 0:p.length});Pe(l)})},vt=(e,{front:t=!1}={})=>{if((C==null?void 0:C.app_id)===e)return;let n=W.indexOf(e);if(n>=0){if(!t)return;W.splice(n,1)}t?W.unshift(e):W.push(e)},Pr=async e=>{let{host_id:t,client_token:n}=V(),o=new AbortController,r=setTimeout(()=>o.abort(),vr);try{let i=`${st}/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)}},tt=null,Mt=()=>(tt!=null||(tt=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(V().channels.map(Pr)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(F.getState().catalog).filter(l=>!o[l]);V().storage.setString(fo,JSON.stringify(o)),F.setState({catalog:o}),await Promise.all(r.map(l=>bo(l,{by_user:!1}))),r.forEach(l=>Oe.delete(l));let i=Object.keys(o).filter(l=>!Oe.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await Wt(l)){te(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=N(l.app_id);if(ho(l.app_id)&&!bt.has(l.app_id)&&s&&await _e(s)){te(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 F.setState({updates:c}),a.forEach(l=>{be[l.app_id]=0,te(l.app_id,{status:ge.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),vt(l.app_id)}),de("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),Re({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>Re({type:"update_available",...l})),Pe(),{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),Re({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{tt=null}})()),tt),bo=async(e,{by_user:t})=>{var r,i,a,c;if(t&&Oe.add(e),At.has(e))return;At.add(e),ge.delete(e);let n=W.indexOf(e);n>=0&&W.splice(n,1),(C==null?void 0:C.app_id)===e&&C.handle.cancel();let o=(c=(a=(r=F.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=N(e))==null?void 0:i.version)!=null?c:"";te(e,{status:"uninstalling",progress:0,version:o}),await oo(e),wt(e),F.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete be[e],At.delete(e),_t(e,null),de("uninstalled",e,t?"(user)":"(not in list)"),Re({type:"uninstalled",app_id:e})},So=e=>bo(e,{by_user:!0}),vo=e=>{let t=ze(e);return t?(Oe.delete(e),(C==null?void 0:C.app_id)===e||W.includes(e)||(be[e]=0,te(e,{status:ge.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),vt(e),Pe(),de("restore",e)),!0):!1},Mo=e=>{if(ge.has(e))return;if(ge.add(e),de("pause app",e),(C==null?void 0:C.app_id)===e&&!C.forced){C.handle.cancel();return}let t=F.getState().downloads[e];W.includes(e)&&t&&te(e,{status:"paused",progress:0,version:t.version})},xo=e=>{if(!ge.delete(e))return;de("resume app",e);let t=F.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!W.includes(e)&&ze(e)&&(be[e]=0,vt(e)),W.includes(e)&&t&&te(e,{status:"queued",progress:0,version:t.version}),Pe()},Eo=e=>{let{pause_reasons:t}=F.getState();t.includes(e)||(F.setState({pause_reasons:[...t,e]}),de("pause",e),t.length===0&&Re({type:"pause_change",paused:!0,reasons:[e]}),C&&!C.forced&&C.handle.cancel())},Ro=e=>{let{pause_reasons:t}=F.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);F.setState({pause_reasons:n}),de("resume",e),n.length===0&&Re({type:"pause_change",paused:!1,reasons:n}),Pe()},Yt=e=>F.getState().updates[e],Po=async e=>{var n,o;let t=Yt(e);bt.add(e);try{let r=await nt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=ze(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(F.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}}}),de("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{bt.delete(e)}},Oo=()=>Object.values(F.getState().catalog).map(e=>({...e,installed:!!N(e.app_id),removed_by_user:Oe.has(e.app_id)})),ze=e=>F.getState().catalog[e],nt=async e=>{let t=ze(e);if(!t)return;if(ge.delete(e),Oe.delete(e),await Wt(t))return N(e);let n=N(e);if(ho(e)&&!bt.has(e)&&n&&await _e(n))return n;let o=new Promise(r=>{var i;((i=Ne[e])!=null?i:Ne[e]=[]).push(r)});return(C==null?void 0:C.app_id)===e?C.forced=!0:(be[e]=0,vt(e,{front:!0}),C&&!C.forced?C.handle.cancel():Pe(e)),o};var L=require("react/jsx-runtime"),Gt=e=>(e!=null?e:"").replace(/\?[^#]*/,""),Co=0,Or=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},Cr=S.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:p})=>{var rt,Zt;let g=(0,S.useRef)(null),A=(0,S.useRef)(!1),d=H(ee,f=>f.instances[e]),h=d==null?void 0:d.app.app_id,k=d==null?void 0:d.app.manifest_url,E=d==null?void 0:d.context,R=d==null?void 0:d.url_params,v=H(z,f=>{var b;return((b=f.active)==null?void 0:b.owner)===e?f.active:null}),[_,Y]=(0,S.useState)(()=>h?N(h):null),[Z,ne]=(0,S.useState)(!1),[oe,re]=(0,S.useState)(0),[ie,m]=(0,S.useState)(0),[w,P]=(0,S.useState)(!1),I=(0,S.useRef)(null),j=f=>{I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{I.current=null,P(!0)},f)};(0,S.useEffect)(()=>()=>{I.current&&clearTimeout(I.current)},[]),(0,S.useEffect)(()=>{if(!h||!t&&_)return;let f=!0;return ne(!1),(async()=>{let b=N(h),X=b?await _e(b):!1;if(!f||(Y(X?pe=>!pe||pe.version!==b.version||pe.permissions.join(",")!==b.permissions.join(",")?b:pe:null),__DEV__&&Date.now()-Co>1e4&&(Co=Date.now(),await Mt()),!f))return;let Me=await nt(h),Te=Me!==void 0?Me:k?await so(h,k):N(h);if(f){if(!Te){ne(!0);return}Y(pe=>pe!=null?pe:Te)}})(),()=>{f=!1}},[t,h,k,oe]),(0,S.useEffect)(()=>ao(e,f=>g.current?(g.current.postMessage(f),!0):!1),[e]);let U=H(F,f=>{let b=h?f.downloads[h]:void 0;return(b==null?void 0:b.status)==="installed"?b.version:void 0});(0,S.useEffect)(()=>{if(t||!h||!_)return;let f=N(h);if(!f||f.version===_.version)return;let b=!0;return _e(f).then(X=>{!b||!X||(ae(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",_.version,"\u2192",f.version),Y(f))}),()=>{b=!1}},[t,h,U,_==null?void 0:_.version]);let G=H(F,f=>{var b;return h&&(b=f.apply_ticks[h])!=null?b:0});(0,S.useEffect)(()=>{if(!G||!h)return;let f=N(h);if(!f||f.version===(_==null?void 0:_.version))return;let b=!0;return _e(f).then(X=>{!b||!X||(ae(`webview:${e}`,"c\u1EADp nh\u1EADt",_==null?void 0:_.version,"\u2192",f.version),P(!1),Y(f))}),()=>{b=!1}},[G]),(0,S.useEffect)(()=>{var X;let f=(X=V().keep_alive)==null?void 0:X.idle_close_ms;if(t||!f||f<=0)return;let b=setTimeout(()=>{wt(e)},f);return()=>clearTimeout(b)},[t,e]),(0,S.useEffect)(()=>{r>0&&(ne(!1),P(!1),m(f=>f+1),re(f=>f+1))},[r]);let Se=(0,S.useRef)(t);(0,S.useEffect)(()=>{var f;Se.current!==t&&(Se.current=t,A.current&&((f=g.current)==null||f.injectJavaScript(Jn(t?"resumed":"paused"))))},[t]);let ye=`${(rt=_==null?void 0:_.version)!=null?rt:"none"}:${(Zt=_==null?void 0:_.permissions.join(","))!=null?Zt:""}:${ie}`,Q=(0,S.useMemo)(()=>JSON.stringify([E!=null?E:{},R!=null?R:{}]),[E,R]),ve=(0,S.useMemo)(()=>{var f;return Zn(R!=null?R:{},(f=_==null?void 0:_.permissions)!=null?f:[])},[Q,_==null?void 0:_.permissions]),we=(0,S.useMemo)(()=>Gn(E!=null?E:{},ve)+jn()+(T.Platform.OS==="android"?Hn():"")+(V().debug?Wn():""),[ve]),Ae=(0,S.useRef)(null),O=(0,S.useRef)(null);(0,S.useEffect)(()=>{var b,X,Me;if(!_)return;if(O.current!==ye){O.current=ye,Ae.current=Q;return}if(Ae.current===Q)return;let f=((X=JSON.parse((b=Ae.current)!=null?b:"[]")[0])!=null?X:{}).org_id;if(Ae.current=Q,f===(E==null?void 0:E.org_id)&&A.current){P(!1),j(1500),(Me=g.current)==null||Me.injectJavaScript(Kn(E!=null?E:{},ve));return}P(!1),m(Te=>Te+1)},[Q,_,ye]),(0,S.useEffect)(()=>(t||(fe(e),Ee(e),Le(e)),()=>{fe(e),Ee(e),Le(e)}),[t,e,ye,r]),(0,S.useEffect)(()=>{let f=T.AppState.addEventListener("change",b=>{b==="background"&&!En()&&fe(e),b==="background"&&!kn()&&Ee(e)});return()=>f.remove()},[e]);let Ce=(0,S.useCallback)(async f=>{var X,Me,Te,pe,xt;let b=Bn(f.nativeEvent.data);if(!b){if(h&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(f.nativeEvent.data,{app_id:h,instance_id:e})).catch(B=>{console.warn("[miniapp] onWebEvent l\u1ED7i",h,B)})}catch(B){console.warn("[miniapp] onWebEvent l\u1ED7i",h,B)}return}if(b.method==="log"){let{level:B,text:q}=b;ae(`web:${e}`,B!=null?B:"log",q!=null?q:"");return}if(b.method==="pong"){I.current||P(!0);return}if(b.method==="touchAtTop"){i.emit(!!b.at_top);return}if(b.method==="contextApplied"){I.current&&clearTimeout(I.current),I.current=null,P(!0);return}if(b.method==="ready"){A.current=!0,P(!0);let B=(X=ee.getState().instances[e])==null?void 0:X.context;B&&((Me=g.current)==null||Me.injectJavaScript(Ut(B)));return}try{let B=await eo(b,{getHostData:()=>{var q,se;return(se=(q=ee.getState().instances[e])==null?void 0:q.host_data)!=null?se:{}},getPermissions:()=>{var q,se;return h?(se=(q=N(h))==null?void 0:q.permissions)!=null?se:[]:[]},getContext:()=>{var q,se;return(se=(q=ee.getState().instances[e])==null?void 0:q.context)!=null?se:{}},is_dark:o,close:$e,app_id:h!=null?h:"",instance_id:e,options:c,emit:(q,se)=>{var Qt;(Qt=g.current)==null||Qt.injectJavaScript(zn(q,se))},playBeep:()=>{var q;(q=g.current)==null||q.injectJavaScript(Qn())},isActive:()=>ee.getState().active_key===e&&T.AppState.currentState!=="background"});b.id&&((Te=g.current)==null||Te.injectJavaScript(qn(b.id,B)))}catch(B){if(!b.id)return;let q=B==null?void 0:B.code,se=B instanceof u?B:new u(typeof q=="string"?q:"HOST_ERROR",String((pe=B==null?void 0:B.message)!=null?pe:B));(xt=g.current)==null||xt.injectJavaScript($n(b.id,se))}},[e,o,h,i,c]),ot=(0,S.useCallback)(()=>{ne(!1),m(f=>f+1),re(f=>f+1)},[]);return(0,L.jsxs)(T.View,{style:[T.StyleSheet.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&le.behind],pointerEvents:t?"auto":"none",children:[(v==null?void 0:v.layout)===he.top&&(0,L.jsx)(Jt,{scanner:v}),_?(0,L.jsx)(ko.default,{ref:g,source:{uri:_.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?qt():_.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:we,onMessage:Ce,bounces:!1,overScrollMode:"never",onLoadStart:f=>{fe(e),Ee(e),Le(e),ae(`webview:${e}`,"load start",Gt(f.nativeEvent.url)),A.current=!1,P(!1)},onError:f=>{fe(e),Ee(e),Le(e),ae(`webview:${e}`,"load error",Gt(f.nativeEvent.url),f.nativeEvent.description),ne(!0),P(!1)},onLoadEnd:f=>{let b=f.nativeEvent.url;ae(`webview:${e}`,"load end",Gt(b)),h&&(p==null||p({app_id:h,instance_id:e,url:b})),j(1500)},onContentProcessDidTerminate:()=>{fe(e),Ee(e),Le(e),A.current=!1,P(!1),m(f=>f+1)},onRenderProcessGone:()=>(fe(e),Ee(e),Le(e),A.current=!1,P(!1),m(f=>f+1),!0),style:le.webview},ye):null,(v==null?void 0:v.layout)===he.full&&(0,L.jsx)(Jt,{scanner:v}),d&&(0,L.jsx)(kr,{visible:!_||!w,interactive:Z,children:(0,L.jsx)(Tr,{splash:a,app:d.app,is_dark:o,error:Z,has_bundle:!!_,retry:ot})})]})}),Tr=S.default.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=St(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return(0,L.jsx)(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),kr=({visible:e,interactive:t,children:n})=>{let o=(0,S.useRef)(new T.Animated.Value(e?1:0)).current,[r,i]=(0,S.useState)(e);return(0,S.useEffect)(()=>{if(e){i(!0),o.setValue(1);return}let a=T.Animated.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?(0,L.jsx)(T.Animated.View,{style:[T.StyleSheet.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},Xt=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return(0,L.jsxs)(T.View,{style:[le.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,L.jsx)(T.View,{style:[le.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,L.jsx)(T.Image,{source:{uri:e.icon},style:le.splash_icon_image}):(0,L.jsx)(T.Text,{style:le.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,L.jsx)(T.Text,{style:[le.splash_name,{color:i}],children:e.name}),n==="error"?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(T.Text,{style:le.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,L.jsx)(T.TouchableOpacity,{activeOpacity:.7,style:[le.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:(0,L.jsx)(T.Text,{style:[le.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(T.ActivityIndicator,{style:le.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,L.jsxs)(T.Text,{style:le.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},To=(e,t)=>{let n=(0,S.useRef)(t),o=(0,S.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.`))},Lr=({container:e,splash:t=Xt,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{To("container",e),To("splash",t);let l=e,s=H(ee,v=>v.active_key),p=(0,S.useRef)(s);s&&(p.current=s);let g=H(ee,v=>Object.keys(v.instances).join("|")),A=H(ee,v=>{var _;return v.active_key?(_=v.instances[v.active_key])==null?void 0:_.app.name:void 0}),d=(0,S.useMemo)(()=>g?g.split("|"):[],[g]),[h,k]=(0,S.useState)({}),E=(0,S.useRef)(Or()).current;(0,S.useEffect)(()=>{if(!s||!r)return;let v=T.BackHandler.addEventListener("hardwareBackPress",()=>($e(),!0));return()=>v.remove()},[s,r]);let R=(0,S.useCallback)(()=>{let v=ee.getState().active_key;v&&k(_=>({..._,[v]:(_[v]||0)+1}))},[]);return d.length?(0,L.jsx)(l,{visible:!!s,title:A!=null?A:"",is_dark:n,close:$e,reload:R,subscribeWebAtTop:E.subscribe,children:d.map(v=>(0,L.jsx)(Cr,{instance_key:v,is_active:s===v,is_front:(s!=null?s:p.current)===v,is_dark:n,reload_tick:h[v]||0,web_at_top:E,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},v))}):null},le=T.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"}}),Lo=S.default.memo(Lr);0&&(module.exports={CodeType,DefaultMiniAppSplash,MINIAPP_PLATFORM_URL,MiniAppHost,MiniAppHostError,ScannerEndReason,ScannerEvent,ScannerLayout,ScannerMethod,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 pt="https://retion-miniapp-platform.vercel.app",be=null,Wt=new Set,fr=e=>{be=e,Wt.forEach(t=>t())},O=()=>{if(!be)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return be},Jt=e=>{Wt.add(e),be&&e()},G=(...e)=>{be!=null&&be.debug&&console.log("[miniapp]",...e)};var hr=(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(r=>r.map(o=>o.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,r)=>{await t(n,r)},download:({url:n,to_file:r,onProgress:o})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:r,progressInterval:250,begin:()=>{},progress:({bytesWritten:l,contentLength:c})=>o==null?void 0:o(l,c)});return{promise:a.then(({statusCode:l})=>({status:l})),cancel:()=>e.stopDownload(i)}}}),yr=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});import qt,{useCallback as $t,useEffect as J,useMemo as ct,useRef as oe,useState as xe}from"react";import{AppState as cr,ActivityIndicator as vo,Animated as Ut,BackHandler as _o,Image as xo,Platform as Eo,StyleSheet as Vt,Text as We,TouchableOpacity as Po,View as Bt}from"react-native";import Ro from"react-native-webview";import{Linking as Tn,Platform as zr}from"react-native";var Yt=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),Ye,ut=()=>(Ye||(Ye=import("react-native-biometrics").then(({default:e})=>Yt(new e({allowDeviceCredentials:!1}))).catch(e=>{throw Ye=void 0,new u("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),Ye);import{PermissionsAndroid as Me,Platform as wr}from"react-native";var Kt=e=>{var n,r,o;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new u("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 u("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 u("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${l} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(r=t.timeout)!=null?r:15e3,maximumAge:(o=t.maximumAge)!=null?o:0}},Gt=(e,t=()=>!0)=>new Promise((n,r)=>{let o=!1,i=(c,s)=>{o||(o=!0,clearTimeout(a),c?r(c):n(s))},a=setTimeout(()=>i(new u("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),l=()=>o?!1:t()?!0:(i(new u("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 u("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(l()){if(wr.OS==="android"){let s=Me.PERMISSIONS.ACCESS_FINE_LOCATION,d=Me.PERMISSIONS.ACCESS_COARSE_LOCATION,g=await Me.check(s);if(!l())return;let y=g||await Me.check(d);if(!l())return;if(!g&&!y){let p=await Me.requestMultiple([s,d]);if(!l())return;if(p[s]!==Me.RESULTS.GRANTED&&p[d]!==Me.RESULTS.GRANTED)throw new u("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 g;if(!l())return;let d=(g={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?g:"LOCATION_ERROR";i(new u(d,s.message))},e)}})().catch(c=>i(c))});import{Platform as rn}from"react-native";var dt=20,Xt=20,on=/^[a-z][a-z0-9_-]{0,31}$/,Ar=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,Sr=["low","medium","high"],de=e=>!!e&&typeof e=="object"&&!Array.isArray(e),L=e=>new u("INVALID_PARAMS",e),Ue=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Qt=(e,t)=>{if(e===void 0)return{};if(!de(e)||Object.keys(e).length>Xt||Object.values(e).some(n=>typeof n!="string"))throw L(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${Xt} key)`);return e},sn=e=>{var n,r,o,i;if(e!==void 0&&!de(e))throw L("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!on.test(t.source)))throw L("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 L("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!Ue(t.max_count,1,dt))throw L(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${dt}`);if(t.max_size!==void 0&&!Ue(t.max_size,1,Number.MAX_SAFE_INTEGER))throw L("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!Ue(t.concurrency,1,5))throw L("concurrency ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u20135");return{source:(n=t.source)!=null?n:"library",accept:((r=t.accept)!=null?r:[]).map(a=>a.toLowerCase()),max_count:(o=t.max_count)!=null?o:1,max_size:t.max_size,process:br(t.process),target:Mr(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},br=e=>{if(e===void 0)return{};if(!de(e))throw L("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!de(n))throw L("process.image ph\u1EA3i l\xE0 object");for(let r of["max_width","max_height"])if(n[r]!==void 0&&!Ue(n[r],1,1e4))throw L(`process.image.${r} 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 L("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(!de(n))throw L("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!Ue(n.max_duration,1,3600))throw L("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!Sr.includes(n.quality))throw L("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},Mr=e=>{var n,r,o,i;if(e===void 0)return{target:"host",params:{}};if(!de(e))throw L("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!on.test(t))throw L("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!de(e.params))throw L("upload.params ph\u1EA3i l\xE0 object");return{target:t,params:(r=e.params)!=null?r:{}}}if(typeof e.url!="string"||!/^https:\/\//i.test(e.url))throw L("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 L(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:Qt(e.headers,"upload.headers"),form_data:Qt(e.form_data,"upload.form_data"),field_name:(o=e.field_name)!=null?o:"file",url_field:(i=e.url_field)!=null?i:"url"}},an=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},vr=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),r=an(e.name);return t.some(o=>o==="*/*"?!0:o.startsWith(".")?o===r:o.endsWith("/*")?n.startsWith(o.slice(0,-1)):n===o)},_r=e=>{let t=e.length>0&&e.every(r=>r.startsWith("image/")),n=e.length>0&&e.every(r=>r.startsWith("video/"));return t?"image":n?"video":"mixed"},Le,xr=()=>(Le!=null||(Le=import("react-native-image-picker").catch(e=>{throw Le=void 0,new u("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),Le),Zt=e=>async({accept:t,max_count:n,process:r})=>{var c,s,d,g,y,p,f,P,M;let o=await xr(),i=_r(t),a={mediaType:i==="image"?"photo":i,maxWidth:(c=r.image)==null?void 0:c.max_width,maxHeight:(s=r.image)==null?void 0:s.max_height,quality:(g=(d=r.image)==null?void 0:d.quality)!=null?g:.8,videoQuality:(p=(y=r.video)==null?void 0:y.quality)!=null?p:"medium",durationLimit:(f=r.video)==null?void 0:f.max_duration,assetRepresentationMode:"compatible"},l=e==="camera"?await o.launchCamera({...a,saveToPhotos:!1}):await o.launchImageLibrary({...a,selectionLimit:n});if(l.didCancel)return[];if(l.errorCode){let v=l.errorCode==="permission"?"PERMISSION_DENIED":l.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new u(v,(P=l.errorMessage)!=null?P:l.errorCode)}return((M=l.assets)!=null?M:[]).filter(v=>v.uri).map((v,S)=>{var w,q,Z;return{uri:v.uri,name:(w=v.fileName)!=null?w:`file_${S+1}`,mime_type:(q=v.type)!=null?q:"application/octet-stream",size:v.fileSize,width:v.width,height:v.height,duration:v.duration,processed:!((Z=v.type)!=null&&Z.startsWith("video/"))||rn.OS==="ios"}})},Er={"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"},Pr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},Rr=e=>async({accept:t,max_count:n})=>{var i,a,l,c;let r=t.map(s=>{var d;return(d=Er[s])!=null?d:Pr[s]}),o=!t.length||r.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(r)].flatMap(s=>e.types[s]);try{let d=(await e.pick({type:o,allowMultiSelection:n>1,mode:"import"})).filter(p=>p.uri&&!p.error).map((p,f)=>{var P,M,v;return{uri:p.uri,name:(P=p.name)!=null?P:`file_${f+1}`,mime_type:(M=p.type)!=null?M:"application/octet-stream",size:(v=p.size)!=null?v:void 0}});if(rn.OS!=="android"||!e.keepLocalCopy||!d.some(p=>p.uri.startsWith("content://")))return d;let g=await e.keepLocalCopy({files:d.map(p=>({uri:p.uri,fileName:p.name})),destination:"cachesDirectory"}),y=new Map(g.map(p=>[p.sourceUri,p.status==="success"?p.localUri:void 0]));return d.map(p=>{var f;return{...p,uri:(f=y.get(p.uri))!=null?f: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 u("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},De,Or=async e=>(De!=null||(De=import("@react-native-documents/picker").then(t=>Rr(t)).catch(t=>{throw De=void 0,new u("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await De)(e)),cn={library:Zt("library"),camera:Zt("camera"),document:Or},en={type:"image",label:"\u1EA2nh",accept:["image/*"]},tn={type:"video",label:"Video",accept:["video/*"]},nn={library:[en,tn],camera:[en,tn],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"]}]},Ne,ln=()=>(Ne!=null||(Ne=import("react-native-compressor").catch(()=>(Ne=void 0,null))),Ne),pn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},Cr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),Tr={low:640,medium:1280,high:1920},kr=async(e,{image:t})=>{var r;if(!t||!Cr.has(e.mime_type.toLowerCase()))return e;let n=await ln();if(!n)return e;try{let o=await n.Image.compress(e.uri,{compressionMethod:"manual",maxWidth:t.max_width,maxHeight:t.max_height,quality:(r=t.quality)!=null?r:.8,output:"jpg"});return{...e,uri:o,mime_type:"image/jpeg",name:e.name.replace(/\.[^.]+$/,"")+".jpg",size:await pn(n,o,e.size),processed:!0}}catch{return e}},Ir=async(e,{video:t})=>{var r;let n=await ln();if(!n)return e;try{let o=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:Tr[(r=t==null?void 0:t.quality)!=null?r:"medium"],minimumFileSizeForCompress:2});return{...e,uri:o,mime_type:"video/mp4",size:await pn(n,o,e.size),processed:!0}}catch{return e}},Lr={image:kr,video:Ir},Dr=(e,t)=>t.split(".").reduce((n,r)=>de(n)?n[r]:void 0,e),un=({file:e,target:t,onProgress:n,signal:r})=>new Promise((o,i)=>{if(t.target!=="url"||!("url"in t)){i(new u("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(r.aborted){i(new u("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let l=new XMLHttpRequest,c=new FormData;Object.entries(a.form_data).forEach(([g,y])=>c.append(g,y)),c.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>l.abort();r.addEventListener("abort",s);let d=g=>{r.removeEventListener("abort",s),g()};l.open("POST",a.url),Object.entries(a.headers).forEach(([g,y])=>l.setRequestHeader(g,y)),l.upload.onprogress=g=>n(g.loaded,g.total||e.size||0),l.onload=()=>d(()=>{let g=l.responseText;try{g=JSON.parse(l.responseText)}catch{}if(l.status<200||l.status>=300){i(new u("UPLOAD_FAILED",`HTTP ${l.status}`));return}let y=Dr(g,a.url_field);if(typeof y!="string"||!y){i(new u("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}o({url:y,response:g})}),l.onerror=()=>d(()=>i(new u("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),l.onabort=()=>d(()=>i(new u("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),l.send(c)}),dn=e=>{var r,o;let t={...cn};for(let[i,a]of Object.entries((r=e==null?void 0:e.sources)!=null?r:{}))a?t[i]=a:delete t[i];let n={url:un};for(let[i,a]of Object.entries((o=e==null?void 0:e.targets)!=null?o:{}))i!=="url"&&a&&(n[i]=a);return{sources:t,targets:n}},gn=e=>{let{sources:t,targets:n}=dn(e),r=Object.keys(t),o=Object.fromEntries(r.filter(i=>t[i]===cn[i]&&nn[i]).map(i=>[i,nn[i]]));return{sources:r,file_types:o,targets:Object.keys(n),max_count:dt}},Ge=new Map,mn=(e,t)=>`${e}:${t}`,Nr=0,fn=(e,t)=>{var n;typeof t=="string"&&((n=Ge.get(mn(e,t)))==null||n.abort())},ve=e=>{for(let[t,n]of Ge)t.startsWith(`${e}:`)&&n.abort()},Ke=()=>new u("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),Ur=(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 c;let{sources:n,targets:r}=dn(t.config),o=n[e.source];if(!o)throw new u("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 ngu\u1ED3n "${e.source}"`);let i=r[e.target.target];if(!i)throw new u("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,l=mn(t.instance_id,(c=t.task_id)!=null?c:`auto-${++Nr}`);Ge.set(l,a);try{return await Fr(e,t,o,i,a.signal)}finally{Ge.delete(l)}},Fr=async(e,{instance_id:t,app_id:n,getContext:r,task_id:o,config:i,emit:a,exclusivePick:l=g=>g()},c,s,d)=>{var h,b,$;let g={app_id:n!=null?n:"",instance_id:t,context:{...(h=r==null?void 0:r())!=null?h:{}}},y=(await l(()=>c({accept:e.accept,max_count:e.max_count,process:e.process,caller:g}))).slice(0,e.max_count);if(d.aborted)throw Ke();if(!y.length)throw new u("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let p=[],f=y.filter(x=>vr(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||an(x.name)}`}),!1)),P=f.map(()=>0),M=f.map(x=>{var k;return(k=x.size)!=null?k:0}),v=0,S=0,w=(x=!1)=>{if(!a||!o)return;let k=Date.now();if(!x&&k-S<200)return;S=k;let N=M.reduce((C,Y)=>C+Y,0),B=P.reduce((C,Y)=>C+Y,0);a("upload.progress",{task_id:o,loaded:B,total:N,percent:N?Math.min(100,Math.round(B/N*100)):0,done_count:v,count:f.length})},q=[],Z=0,ie=async()=>{var x,k,N;for(;Z<f.length;){let B=Z++,C=f[B];try{if(d.aborted)throw Ke();let Y=C.mime_type.startsWith("image/")?"image":C.mime_type.startsWith("video/")?"video":void 0,Te=Y&&!C.processed?(k=(x=i==null?void 0:i.processors)==null?void 0:x[Y])!=null?k:Lr[Y]:void 0;if(Te&&(C=await Te(C,e.process),M[B]=(N=C.size)!=null?N:M[B],d.aborted))throw Ke();if(e.max_size&&C.size&&C.size>e.max_size)throw new u("FILE_TOO_LARGE",`File ${C.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let Ae=(Pe,Ie)=>{P[B]=Pe,Ie&&(M[B]=Ie),w()},ee=await s({file:C,target:e.target,onProgress:Ae,signal:d,caller:g});if(typeof(ee==null?void 0:ee.url)!="string"||!ee.url)throw new u("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:ke,...Ee}=ee;q[B]={url:ke,name:C.name,mime_type:C.mime_type,size:C.size,width:C.width,height:C.height,duration:C.duration,...Object.keys(Ee).length?{response:"response"in Ee?Ee.response:Ee}:{}},P[B]=M[B]}catch(Y){p.push(Ur(f[B].name,Y))}finally{v++,w(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,f.length)},ie)),d.aborted)throw Ke();let we=q.filter(x=>!!x);if(!we.length){let x=p[0];throw new u((b=x==null?void 0:x.code)!=null?b:"UPLOAD_FAILED",($=x==null?void 0:x.message)!=null?$:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:we,failed:p}};import{Platform as Vr}from"react-native";import{AppState as yn,Platform as mt}from"react-native";var X,wn=()=>mt.OS==="android"&&!!(X!=null&&X.requesting_permission),$r=1500,ft=()=>new Promise(e=>{if(mt.OS!=="android"||yn.currentState==="active"){e();return}let t=()=>{clearTimeout(n),r.remove(),e()},n=setTimeout(t,$r),r=yn.addEventListener("change",o=>{o==="active"&&t()})}),gt=e=>{var t;if(X===e&&(X=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&mt.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},An=async(e,t,n,r=()=>!0)=>{var i,a,l,c,s;if(X)throw new u("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!r())throw new u("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let o={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};X=o;try{let d;try{d=await import("expo-speech-recognition")}catch{throw new u("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let g=d.ExpoSpeechRecognitionModule;if(o.native=g,o.cancelled||!r())throw new u("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");o.requesting_permission=!0;let y;try{y=await g.requestPermissionsAsync()}finally{o.requesting_permission=!1}if(await ft(),o.cancelled||!r())throw new u("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!y.granted)throw new u("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await g.getStateAsync()!=="inactive")throw new u("BUSY","Nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i \u0111ang \u0111\u01B0\u1EE3c t\xEDnh n\u0103ng kh\xE1c s\u1EED d\u1EE5ng");if(o.cancelled||!r())throw new u("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");o.subscriptions.push(g.addListener("result",p=>{var f,P;X!==o||o.cancelled||n(p.isFinal?"speech.final":"speech.partial",{...p,text:(P=(f=p.results[0])==null?void 0:f.transcript)!=null?P:""})}),g.addListener("error",p=>{X===o&&!o.cancelled&&n("speech.error",{...p,code:p.error})}),g.addListener("end",()=>{X===o&&(gt(o),n("speech.end"))})),o.started=!0,g.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 gt(o),d}},Sn=e=>{let t=X;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},ae=e=>{let t=X;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{gt(t)}};import{useRef as Br,useSyncExternalStore as qr}from"react";var Re=e=>{let t=e,n=new Set;return{getState:()=>t,setState:r=>{let o=typeof r=="function"?r(t):r;t={...t,...o},n.forEach(i=>i())},subscribe:r=>(n.add(r),()=>{n.delete(r)})}},j=(e,t,n=Object.is)=>{let r=Br(null),o=()=>{let i=e.getState(),a=r.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 r.current={state:i,selector:t,value:c},c};return qr(e.subscribe,o)};var bn={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"},ht={...bn,all:Object.values(bn)},Fe={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},yt={result:"scanner.result",end:"scanner.end"},Oe={user:"user",web:"web",closed:"closed",error:"error"},ce={once:"once",continuous:"continuous"},jr=1500,Mn=6e4,I,se=Re({active:null,last_value:null,hit_tick:0}),vn=()=>Vr.OS==="android"&&!!(I!=null&&I.requesting_permission),wt=e=>{let{types:t,cooldown_ms:n}=e!=null?e:{},r={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(o=>ht.all.includes(o)))throw new u("INVALID_PARAMS","types ph\u1EA3i l\xE0 m\u1EA3ng CodeType");r.types=t}if(n!==void 0){if(typeof n!="number"||!Number.isFinite(n)||n<0||n>Mn)throw new u("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${Mn}`);r.cooldown_ms=n}return r},At=e=>I!==e?!1:(I=void 0,se.setState({active:null,last_value:null}),!0),_n=async(e,t)=>{if(I)throw new u("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new u("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");I=e;let n=()=>{if(e.cancelled||!t())throw new u("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let r;try{r=await import("react-native-vision-camera")}catch{throw new u("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n(),e.requesting_permission=!0;let o;try{o=await r.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await ft(),n(),o!=="granted")throw new u("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera");if(!r.Camera.getAvailableCameraDevices().some(i=>i.position==="back"))throw new u("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");se.setState({active:{owner:e.owner,mode:e.mode,types:e.types,vision:r},last_value:null})}catch(r){throw At(e),r}},xn=(e,t,n)=>{var r,o;return{owner:e,mode:t,types:(r=n.types)!=null?r:ht.all,cooldown_ms:(o=n.cooldown_ms)!=null?o:jr,cancelled:!1,requesting_permission:!1,last_seen:new Map}},En=(e,t,n=()=>!0,r)=>new Promise((o,i)=>{let a=xn(e,ce.once,t);a.onHit=r,a.resolve=o,a.reject=i,_n(a,n).catch(i)}),Pn=(e,t,n,r=()=>!0,o)=>{let i=xn(e,ce.continuous,t);return i.emit=n,i.onHit=o,_n(i,r)},Xe=(e,t,n)=>{var r,o;if(!se.getState().active){e.cancelled=!0;return}if(At(e)){if(e.mode===ce.once){(r=e.reject)==null||r.call(e,t===Oe.error?new u("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new u("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(o=e.emit)==null||o.call(e,yt.end,n?{reason:t,message:n}:{reason:t})}},Rn=e=>{(I==null?void 0:I.owner)===e&&Xe(I,Oe.web)},ge=e=>{(I==null?void 0:I.owner)===e&&Xe(I,Oe.closed)},St=()=>{I&&Xe(I,Oe.user)},On=e=>{I&&Xe(I,Oe.error,e)},Cn=(e,t=Date.now())=>{var r,o,i;let n=I;if(!(!n||!se.getState().active))for(let{value:a,type:l}of e){if(!a)continue;let c=n.last_seen.get(a);if(!(c!==void 0&&t-c<n.cooldown_ms)){if(n.last_seen.set(a,t),(r=n.onHit)==null||r.call(n),n.mode===ce.once){At(n),(o=n.resolve)==null||o.call(n,{value:a,type:l});return}se.setState(s=>({last_value:a,hit_tick:s.hit_tick+1})),(i=n.emit)==null||i.call(n,yt.result,{value:a,type:l})}}};var Ze=1,u=class extends Error{constructor(n,r){super(r);this.code=n}},kn=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===Ze&&typeof t.method=="string"?t:null}catch{return null}},Be=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,In=(e,t)=>Be({id:e,result:t}),Ln=(e,t)=>Be({id:e,error:{code:t.code,message:t.message}}),Dn=(e,t)=>Be({event:e,data:t}),Mt=e=>Be({event:"context",data:e});var Nn=()=>`(function () {
|
|
1
|
+
var Rt="https://retion-miniapp-platform.vercel.app",Te=null,cn=new Set,Co=e=>{Te=e,cn.forEach(t=>t())},F=()=>{if(!Te)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Te},ln=e=>{cn.add(e),Te&&e()},se=(...e)=>{Te!=null&&Te.debug&&console.log("[miniapp]",...e)};var To=(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)}}}),ko=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});import on,{useCallback as tn,useEffect as ee,useMemo as xt,useRef as de,useState as De}from"react";import{AppState as xo,ActivityIndicator as jr,Animated as Qt,BackHandler as Hr,Image as Jr,Platform as Kr,StyleSheet as rn,Text as ot,TouchableOpacity as Yr,View as nn}from"react-native";import Gr from"react-native-webview";import{Linking as Hn,Platform as ar}from"react-native";var pn=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),at,Pt=()=>(at||(at=import("react-native-biometrics").then(({default:e})=>pn(new e({allowDeviceCredentials:!1}))).catch(e=>{throw at=void 0,new d("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),at);import{PermissionsAndroid as ke,Platform as Lo}from"react-native";var un=e=>{var n,o,r;if(e!==void 0&&(e===null||typeof e!="object"||Array.isArray(e)))throw new d("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 d("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 d("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 d("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 d("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 d("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(c()){if(Lo.OS==="android"){let s=ke.PERMISSIONS.ACCESS_FINE_LOCATION,p=ke.PERMISSIONS.ACCESS_COARSE_LOCATION,g=await ke.check(s);if(!c())return;let w=g||await ke.check(p);if(!c())return;if(!g&&!w){let u=await ke.requestMultiple([s,p]);if(!c())return;if(u[s]!==ke.RESULTS.GRANTED&&u[p]!==ke.RESULTS.GRANTED)throw new d("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 g;if(!c())return;let p=(g={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?g:"LOCATION_ERROR";i(new d(p,s.message))},e)}})().catch(l=>i(l))});import{Platform as An}from"react-native";var Ot=20,gn=20,_n=/^[a-z][a-z0-9_-]{0,31}$/,Io=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,Fo=["low","medium","high"],Me=e=>!!e&&typeof e=="object"&&!Array.isArray(e),U=e=>new d("INVALID_PARAMS",e),We=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,mn=(e,t)=>{if(e===void 0)return{};if(!Me(e)||Object.keys(e).length>gn||Object.values(e).some(n=>typeof n!="string"))throw U(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${gn} key)`);return e},bn=e=>{var n,o,r,i;if(e!==void 0&&!Me(e))throw U("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!_n.test(t.source)))throw U("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"||!Io.test(a))))throw U("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!We(t.max_count,1,Ot))throw U(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Ot}`);if(t.max_size!==void 0&&!We(t.max_size,1,Number.MAX_SAFE_INTEGER))throw U("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!We(t.concurrency,1,5))throw U("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:Do(t.process),target:No(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},Do=e=>{if(e===void 0)return{};if(!Me(e))throw U("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Me(n))throw U("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!We(n[o],1,1e4))throw U(`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 U("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(!Me(n))throw U("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!We(n.max_duration,1,3600))throw U("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!Fo.includes(n.quality))throw U("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},No=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Me(e))throw U("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!_n.test(t))throw U("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!Me(e.params))throw U("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 U("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 U(`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"}},Sn=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},Uo=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=Sn(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},Vo=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,Bo=()=>(qe!=null||(qe=import("react-native-image-picker").catch(e=>{throw qe=void 0,new d("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn \u1EA3nh trong b\u1EA3n native: ${e instanceof Error?e.message:String(e)}`)})),qe),fn=e=>async({accept:t,max_count:n,process:o})=>{var l,s,p,g,w,u,h,P,v;let r=await Bo(),i=Vo(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:(g=(p=o.image)==null?void 0:p.quality)!=null?g:.8,videoQuality:(u=(w=o.video)==null?void 0:w.quality)!=null?u:"medium",durationLimit:(h=o.video)==null?void 0:h.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 M=c.errorCode==="permission"?"PERMISSION_DENIED":c.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new d(M,(P=c.errorMessage)!=null?P:c.errorCode)}return((v=c.assets)!=null?v:[]).filter(M=>M.uri).map((M,b)=>{var A,j,G;return{uri:M.uri,name:(A=M.fileName)!=null?A:`file_${b+1}`,mime_type:(j=M.type)!=null?j:"application/octet-stream",size:M.fileSize,width:M.width,height:M.height,duration:M.duration,processed:!((G=M.type)!=null&&G.startsWith("video/"))||An.OS==="ios"}})},qo={"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"},$o={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},zo=e=>async({accept:t,max_count:n})=>{var i,a,c,l;let o=t.map(s=>{var p;return(p=qo[s])!=null?p:$o[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let p=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(u=>u.uri&&!u.error).map((u,h)=>{var P,v,M;return{uri:u.uri,name:(P=u.name)!=null?P:`file_${h+1}`,mime_type:(v=u.type)!=null?v:"application/octet-stream",size:(M=u.size)!=null?M:void 0}});if(An.OS!=="android"||!e.keepLocalCopy||!p.some(u=>u.uri.startsWith("content://")))return p;let g=await e.keepLocalCopy({files:p.map(u=>({uri:u.uri,fileName:u.name})),destination:"cachesDirectory"}),w=new Map(g.map(u=>[u.sourceUri,u.status==="success"?u.localUri:void 0]));return p.map(u=>{var h;return{...u,uri:(h=w.get(u.uri))!=null?h:u.uri}})}catch(s){let p=s==null?void 0:s.code;if(p===((a=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?a:"OPERATION_CANCELED"))return[];throw p===((l=(c=e.errorCodes)==null?void 0:c.IN_PROGRESS)!=null?l:"ASYNC_OP_IN_PROGRESS")?new d("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},$e,Wo=async e=>($e!=null||($e=import("@react-native-documents/picker").then(t=>zo(t)).catch(t=>{throw $e=void 0,new d("NOT_SUPPORTED",`Ch\u01B0a c\xF3 module ch\u1ECDn file trong b\u1EA3n native: ${t instanceof Error?t.message:String(t)}`)})),(await $e)(e)),vn={library:fn("library"),camera:fn("camera"),document:Wo},hn={type:"image",label:"\u1EA2nh",accept:["image/*"]},yn={type:"video",label:"Video",accept:["video/*"]},wn={library:[hn,yn],camera:[hn,yn],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,Mn=()=>(ze!=null||(ze=import("react-native-compressor").catch(()=>(ze=void 0,null))),ze),xn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},jo=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),Ho={low:640,medium:1280,high:1920},Jo=async(e,{image:t})=>{var o;if(!t||!jo.has(e.mime_type.toLowerCase()))return e;let n=await Mn();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 xn(n,r,e.size),processed:!0}}catch{return e}},Ko=async(e,{video:t})=>{var o;let n=await Mn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:Ho[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await xn(n,r,e.size),processed:!0}}catch{return e}},Yo={image:Jo,video:Ko},Go=(e,t)=>t.split(".").reduce((n,o)=>Me(n)?n[o]:void 0,e),En=({file:e,target:t,onProgress:n,signal:o})=>new Promise((r,i)=>{if(t.target!=="url"||!("url"in t)){i(new d("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let a=t;if(o.aborted){i(new d("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let c=new XMLHttpRequest,l=new FormData;Object.entries(a.form_data).forEach(([g,w])=>l.append(g,w)),l.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>c.abort();o.addEventListener("abort",s);let p=g=>{o.removeEventListener("abort",s),g()};c.open("POST",a.url),Object.entries(a.headers).forEach(([g,w])=>c.setRequestHeader(g,w)),c.upload.onprogress=g=>n(g.loaded,g.total||e.size||0),c.onload=()=>p(()=>{let g=c.responseText;try{g=JSON.parse(c.responseText)}catch{}if(c.status<200||c.status>=300){i(new d("UPLOAD_FAILED",`HTTP ${c.status}`));return}let w=Go(g,a.url_field);if(typeof w!="string"||!w){i(new d("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:w,response:g})}),c.onerror=()=>p(()=>i(new d("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),c.onabort=()=>p(()=>i(new d("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),c.send(l)}),Rn=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:En};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}},Pn=e=>{let{sources:t,targets:n}=Rn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===vn[i]&&wn[i]).map(i=>[i,wn[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Ot}},lt=new Map,On=(e,t)=>`${e}:${t}`,Xo=0,Cn=(e,t)=>{var n;typeof t=="string"&&((n=lt.get(On(e,t)))==null||n.abort())},Le=e=>{for(let[t,n]of lt)t.startsWith(`${e}:`)&&n.abort()},ct=()=>new d("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),Zo=(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)}},Tn=async(e,t)=>{var l;let{sources:n,targets:o}=Rn(t.config),r=n[e.source];if(!r)throw new d("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 d("NOT_SUPPORTED",`\u1EE8ng d\u1EE5ng ch\u01B0a h\u1ED7 tr\u1EE3 \u0111\xEDch upload "${e.target.target}"`);let a=new AbortController,c=On(t.instance_id,(l=t.task_id)!=null?l:`auto-${++Xo}`);lt.set(c,a);try{return await Qo(e,t,r,i,a.signal)}finally{lt.delete(c)}},Qo=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:c=g=>g()},l,s,p)=>{var oe,re,m;let g={app_id:n!=null?n:"",instance_id:t,context:{...(oe=o==null?void 0:o())!=null?oe:{}}},w=(await c(()=>l({accept:e.accept,max_count:e.max_count,process:e.process,caller:g}))).slice(0,e.max_count);if(p.aborted)throw ct();if(!w.length)throw new d("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let u=[],h=w.filter(y=>Uo(y,e.accept)?!0:(u.push({name:y.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${y.mime_type||Sn(y.name)}`}),!1)),P=h.map(()=>0),v=h.map(y=>{var x;return(x=y.size)!=null?x:0}),M=0,b=0,A=(y=!1)=>{if(!a||!r)return;let x=Date.now();if(!y&&x-b<200)return;b=x;let O=v.reduce((L,J)=>L+J,0),$=P.reduce((L,J)=>L+J,0);a("upload.progress",{task_id:r,loaded:$,total:O,percent:O?Math.min(100,Math.round($/O*100)):0,done_count:M,count:h.length})},j=[],G=0,te=async()=>{var y,x,O;for(;G<h.length;){let $=G++,L=h[$];try{if(p.aborted)throw ct();let J=L.mime_type.startsWith("image/")?"image":L.mime_type.startsWith("video/")?"video":void 0,be=J&&!L.processed?(x=(y=i==null?void 0:i.processors)==null?void 0:y[J])!=null?x:Yo[J]:void 0;if(be&&(L=await be(L,e.process),v[$]=(O=L.size)!=null?O:v[$],p.aborted))throw ct();if(e.max_size&&L.size&&L.size>e.max_size)throw new d("FILE_TOO_LARGE",`File ${L.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let me=(he,E)=>{P[$]=he,E&&(v[$]=E),A()},X=await s({file:L,target:e.target,onProgress:me,signal:p,caller:g});if(typeof(X==null?void 0:X.url)!="string"||!X.url)throw new d("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:Se,...fe}=X;j[$]={url:Se,name:L.name,mime_type:L.mime_type,size:L.size,width:L.width,height:L.height,duration:L.duration,...Object.keys(fe).length?{response:"response"in fe?fe.response:fe}:{}},P[$]=v[$]}catch(J){u.push(Zo(h[$].name,J))}finally{M++,A(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,h.length)},te)),p.aborted)throw ct();let ne=j.filter(y=>!!y);if(!ne.length){let y=u[0];throw new d((re=y==null?void 0:y.code)!=null?re:"UPLOAD_FAILED",(m=y==null?void 0:y.message)!=null?m:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:ne,failed:u}};import{Platform as or}from"react-native";import{AppState as kn,Platform as Tt}from"react-native";var ae,Ln=()=>Tt.OS==="android"&&!!(ae!=null&&ae.requesting_permission),er=1500,pt=()=>new Promise(e=>{if(Tt.OS!=="android"||kn.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,er),o=kn.addEventListener("change",r=>{r==="active"&&t()})}),Ct=e=>{var t;if(ae===e&&(ae=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Tt.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},In=async(e,t,n,o=()=>!0)=>{var i,a,c,l,s;if(ae)throw new d("BUSY","Micro \u0111ang \u0111\u01B0\u1EE3c mini app kh\xE1c s\u1EED d\u1EE5ng");if(!o())throw new d("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");let r={owner:e,emit:n,cancelled:!1,started:!1,subscriptions:[]};ae=r;try{let p;try{p=await import("expo-speech-recognition")}catch{throw new d("NOT_SUPPORTED","Ch\u01B0a c\xF3 module nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i trong b\u1EA3n native")}let g=p.ExpoSpeechRecognitionModule;if(r.native=g,r.cancelled||!o())throw new d("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.requesting_permission=!0;let w;try{w=await g.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await pt(),r.cancelled||!o())throw new d("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!w.granted)throw new d("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n micro / nh\u1EADn d\u1EA1ng gi\u1ECDng n\xF3i");if(await g.getStateAsync()!=="inactive")throw new d("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 d("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");r.subscriptions.push(g.addListener("result",u=>{var h,P;ae!==r||r.cancelled||n(u.isFinal?"speech.final":"speech.partial",{...u,text:(P=(h=u.results[0])==null?void 0:h.transcript)!=null?P:""})}),g.addListener("error",u=>{ae===r&&!r.cancelled&&n("speech.error",{...u,code:u.error})}),g.addListener("end",()=>{ae===r&&(Ct(r),n("speech.end"))})),r.started=!0,g.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:p.AVAudioSessionCategory.playAndRecord,categoryOptions:[p.AVAudioSessionCategoryOptions.defaultToSpeaker,p.AVAudioSessionCategoryOptions.allowBluetooth],mode:p.AVAudioSessionMode.measurement}})}catch(p){throw Ct(r),p}},Fn=e=>{let t=ae;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},ye=e=>{let t=ae;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{Ct(t)}};import{useRef as tr,useSyncExternalStore as nr}from"react";var Ne=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)})}},z=(e,t,n=Object.is)=>{let o=tr(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 Dn={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"},H={...Dn,all:Object.values(Dn)},je={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},Lt={result:"scanner.result",end:"scanner.end"},Ue={user:"user",web:"web",closed:"closed",error:"error"},we={top:"top",full:"full"},Ie={once:"once",continuous:"continuous"},rr=1500,Nn=6e4,T,V=Ne({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),Un=()=>or.OS==="android"&&!!(T!=null&&T.requesting_permission),It=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=>H.all.includes(a)))throw new d("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>Nn)throw new d("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${Nn}`);i.cooldown_ms=n}if(o!==void 0){if(typeof o!="string"||!o.trim()||o.length>80)throw new d("INVALID_PARAMS","hint ph\u1EA3i c\xF3 1\u201380 k\xFD t\u1EF1");i.hint=o}if(r!==void 0){if(!Object.values(we).includes(r))throw new d("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");i.layout=r}return i},Ft=e=>T!==e?!1:(T=void 0,V.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Vn=async(e,t)=>{if(T)throw new d("BUSY","Camera qu\xE9t m\xE3 \u0111ang \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng");if(!t())throw new d("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng");T=e;let n=()=>{if(e.cancelled||!t())throw new d("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng")};try{let o;try{o=await import("react-native-vision-camera")}catch{throw new d("NOT_SUPPORTED","Ch\u01B0a c\xF3 module camera trong b\u1EA3n native")}n(),e.requesting_permission=!0;let r;try{r=await o.Camera.requestCameraPermission()}finally{e.requesting_permission=!1}if(await pt(),n(),r!=="granted")throw new d("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera");if(!o.Camera.getAvailableCameraDevices().some(i=>i.position==="back"))throw new d("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");V.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,hint:e.hint,vision:o},last_value:null,scan_count:0,notice:null})}catch(o){throw Ft(e),o}},Bn=(e,t,n)=>{var o,r,i;return{owner:e,mode:t,types:(o=n.types)!=null?o:H.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:rr,hint:n.hint,layout:t===Ie.once?we.full:(i=n.layout)!=null?i:we.top,cancelled:!1,requesting_permission:!1,last_seen:new Map}},qn=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=Bn(e,Ie.once,t);a.onHit=o,a.resolve=r,a.reject=i,Vn(a,n).catch(i)}),$n=(e,t,n,o=()=>!0,r)=>{let i=Bn(e,Ie.continuous,t);return i.emit=n,i.onHit=r,Vn(i,o)},ut=(e,t,n)=>{var o,r;if(!V.getState().active){e.cancelled=!0;return}if(Ft(e)){if(e.mode===Ie.once){(o=e.reject)==null||o.call(e,t===Ue.error?new d("HOST_ERROR",n!=null?n:"L\u1ED7i camera"):new d("CANCELLED","\u0110\xE3 \u0111\xF3ng camera qu\xE9t m\xE3"));return}(r=e.emit)==null||r.call(e,Lt.end,n?{reason:t,message:n}:{reason:t})}},zn=e=>{(T==null?void 0:T.owner)===e&&ut(T,Ue.web)},xe=e=>{(T==null?void 0:T.owner)===e&&ut(T,Ue.closed)},Dt=()=>{T&&ut(T,Ue.user)},Wn=e=>{T&&ut(T,Ue.error,e)},Nt=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=T;if(!(!o||!V.getState().active))for(let{value:c,type:l}of e){if(!c)continue;let s=o.last_seen.get(c);if(!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if(o.last_seen.set(c,t),(r=o.onHit)==null||r.call(o),o.mode===Ie.once){Ft(o),(i=o.resolve)==null||i.call(o,{value:c,type:l});return}V.setState(p=>({last_value:c,hit_tick:p.hit_tick+1,scan_count:p.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,Lt.result,{value:c,type:l})}}},ir={1:H.code128,2:H.code39,4:H.code93,8:H.codabar,16:H.dataMatrix,32:H.ean13,64:H.ean8,128:H.itf,256:H.qr,512:H.upcA,1024:H.upcE,2048:H.pdf417,4096:H.aztec},sr=2500,kt=e=>{V.setState({notice:e}),setTimeout(()=>{V.getState().notice===e&&V.setState({notice:null})},sr)},jn=async()=>{var t,n;let e=T;if(!(!e||V.getState().is_picking)){e.requesting_permission=!0,V.setState({is_picking:!0,notice:null});try{let{launchImageLibrary:o}=await import("react-native-image-picker"),r=await o({mediaType:"photo",selectionLimit:1}),i=(n=(t=r.assets)==null?void 0:t[0])==null?void 0:n.uri;if(r.didCancel||T!==e)return;if(r.errorCode||!i){kt("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(T!==e)return;let l=c.map(({value:s,format:p})=>({value:s,code_type:ir[p]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:p})=>({value:s,type:p!=null?p:"unknown"}));if(!l.length){kt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}Nt(l,Date.now(),!0)}catch{T===e&&kt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await pt(),e.requesting_permission=!1,T===e&&V.setState({is_picking:!1})}}};var gt=1,d=class extends Error{constructor(n,o){super(o);this.code=n}},Jn=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===gt&&typeof t.method=="string"?t:null}catch{return null}},Je=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,Kn=(e,t)=>Je({id:e,result:t}),Yn=(e,t)=>Je({id:e,error:{code:t.code,message:t.message}}),Gn=(e,t)=>Je({event:e,data:t}),Vt=e=>Je({event:"context",data:e});var Xn=()=>`(function () {
|
|
2
2
|
var post = function (level, args) {
|
|
3
3
|
try {
|
|
4
4
|
var parts = [];
|
|
@@ -8,7 +8,7 @@ var pt="https://retion-miniapp-platform.vercel.app",be=null,Wt=new Set,fr=e=>{be
|
|
|
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: ${gt}, 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 pt="https://retion-miniapp-platform.vercel.app",be=null,Wt=new Set,fr=e=>{be
|
|
|
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;`,Zn=()=>`(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 pt="https://retion-miniapp-platform.vercel.app",be=null,Wt=new Set,fr=e=>{be
|
|
|
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: ${gt}, 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 pt="https://retion-miniapp-platform.vercel.app",be=null,Wt=new Set,fr=e=>{be
|
|
|
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;`,Qn=()=>`(function () {
|
|
42
42
|
if (window.__retionSafeAreaFrozen) { return; }
|
|
43
43
|
window.__retionSafeAreaFrozen = true;
|
|
44
44
|
var max = {};
|
|
@@ -59,8 +59,24 @@ var pt="https://retion-miniapp-platform.vercel.app",be=null,Wt=new Set,fr=e=>{be
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
|
-
})(); true
|
|
63
|
-
${
|
|
62
|
+
})(); true;`,eo=e=>Je({event:e}),to=(e,t)=>{let n=no(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
|
|
63
|
+
${Vt(e)}`},no=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),oo=(e,t={})=>{let n=no(t);return`window.__RETION_MINIAPP_HOST__ = { protocol: ${gt} };
|
|
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;`},jn={partner:"partner_token",chatbox:"chatbox_token"},zn=(e,t)=>{let n={...e};for(let r of Object.values(jn))t.includes(r)||delete n[r];return n},bt=new Set,$e=async(e,t)=>{if(bt.has(e))throw new u("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);bt.add(e);try{return await t()}finally{bt.delete(e)}},Hr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),Qe=(e,t)=>{if(typeof e!="string"||!e)throw new u("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},Hn=async({method:e,params:t},{getHostData:n,getPermissions:r,getContext:o,is_dark:i,close:a,app_id:l,instance_id:c,options:s,emit:d,isActive:g})=>{var P,M,v,S,w,q,Z,ie,we;let y=s==null?void 0:s.handlers,p={app_id:l,instance_id:c,close:a},f=()=>new u("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let h=Kt(t);return $e(e,()=>Gt(h,g))}case"speech.start":{if(!d)throw f();let h={};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 u("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");h.lang=t.lang}for(let b of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[b])!==void 0){if(typeof t[b]!="boolean")throw new u("INVALID_PARAMS",`${b} ph\u1EA3i l\xE0 boolean`);h[b]=t[b]}return An(c,h,d,g)}case"speech.stop":return Sn(c);case Fe.scan:return En(c,wt(t),g,()=>{var h;return(h=s==null?void 0:s.haptic)==null?void 0:h.call(s,"notificationSuccess")});case Fe.start:{if(!d)throw f();return Pn(c,wt(t),d,g,()=>{var h;return(h=s==null?void 0:s.haptic)==null?void 0:h.call(s,"notificationSuccess")})}case Fe.stop:return Rn(c);case"uploadFiles":{let{task_id:h,...b}=t!=null?t:{};if(h!==void 0&&(typeof h!="string"||!h))throw new u("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return hn(sn(b),{instance_id:c,app_id:l,getContext:o,task_id:h,config:s==null?void 0:s.upload,emit:d,exclusivePick:$=>$e("uploadFiles.pick",$)})}case"uploadFiles.cancel":fn(c,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return gn(s==null?void 0:s.upload);case"getBiometricAvailability":return((P=s==null?void 0:s.biometrics)!=null?P:await ut()).getAvailability();case"authenticateBiometric":{let h=Qe(t==null?void 0:t.reason,"reason").trim();if(!h||h.length>200)throw new u("INVALID_PARAMS","reason must contain 1\u2013200 characters");let b=t==null?void 0:t.cancelButtonText;if(b!==void 0&&(typeof b!="string"||!b.trim()||b.length>80))throw new u("INVALID_PARAMS","Invalid cancelButtonText");return $e(e,async()=>{var x;return((x=s==null?void 0:s.biometrics)!=null?x:await ut()).authenticate({reason:h,cancelButtonText:b})})}case"requestPayment":{let h=y==null?void 0:y.requestPayment;if(!h)throw f();let b=t==null?void 0:t.amount;if(typeof b!="number"||!Number.isFinite(b)||b<=0)throw new u("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let $={...t,amount:b,currency:Qe(t==null?void 0:t.currency,"currency")};return $e(e,()=>h($,p))}case"printImage":{let h=y==null?void 0:y.printImage;if(!h)throw f();let b=Qe(t==null?void 0:t.image,"image");await $e(e,()=>h({image:b},p));return}case"openScreen":if(!(y!=null&&y.openScreen))throw f();await y.openScreen({screen:Qe(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},p);return;case"closeApp":a();return;case"openWebview":{let h=String((M=t==null?void 0:t.url)!=null?M:"");if(!/^https?:\/\//i.test(h))throw new u("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(h):Tn.openURL(h));return}case"openLink":{let h=String((v=t==null?void 0:t.url)!=null?v:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(h)||/^(javascript|file|data|about|blob):/i.test(h))throw new u("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(h):Tn.openURL(h))}catch(b){throw new u("NOT_SUPPORTED",String((w=(S=b==null?void 0:b.message)!=null?S:b)!=null?w:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":(Z=s==null?void 0:s.showToast)==null||Z.call(s,String((q=t==null?void 0:t.message)!=null?q:""));return;case"haptic":{let h=Hr.has(t==null?void 0:t.type)?t.type:"selection";(ie=s==null?void 0:s.haptic)==null||ie.call(s,h);return}case"getSystemInfo":return{platform:zr.OS==="ios"?"ios":"android",appVersion:(we=s==null?void 0:s.app_version)!=null?we:"",theme:i?"dark":"light"};case"getAccessToken":{let h=n().access_token;if(!h)throw new u("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return h}case"getToken":{let h=t==null?void 0:t.type;if(h==="access"){let x=n().access_token;if(!x)throw new u("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return x}if(h!=="partner"&&h!=="chatbox")throw new u("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(h)}`);let b=jn[h];if(!r().includes(b))throw new u("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${b} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let $=h==="partner"?n().partner_token:n().chatbox_token;if(!$)throw new u("HOST_ERROR",`Kh\xF4ng c\xF3 ${b}`);return $}case"getUserInfo":{let h=n().user;if(!h)throw new u("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return h}case"getPageInfo":{let h=n().page;if(!h)throw new u("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return h}case"sendMessage":case"insertText":throw new u("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new u("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var _t=e=>`bundle:${e}`,xt=()=>`${O().file_system.document_dir}/miniapps`,Et=xt,Pt=(e,t,n="index.html",r=!1,o=[])=>{let i=`${Et()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:r,permissions:o}},vt=e=>{var t;O().storage.setString(_t(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}`,R=e=>{let t=O().storage.getString(_t(e));if(!t)return null;try{let{version:n,entry:r,context_update:o,permissions:i}=JSON.parse(t);return Pt(e,n,r,!!o,Array.isArray(i)?i:[])}catch{return null}},le=e=>O().file_system.exists(e.entry_uri.replace("file://","")),Rt=async e=>{let t=R(e.app_id);return(t==null?void 0:t.version)===e.version&&await le(t)},Jn=async(e,t)=>{let n=O().file_system,r=`${Et()}/${e}`,o=await n.listDir(r).catch(()=>[]);await Promise.all(o.filter(i=>!t.includes(i)).map(i=>n.remove(`${r}/${i}`).catch(()=>{})))},Yn=async e=>{var t;await((t=Ve[e])==null?void 0:t.catch(()=>{})),O().storage.setString(_t(e),""),await O().file_system.remove(`${Et()}/${e}`).catch(()=>{})},Ce=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},Ve={},Kn=(e,t)=>{var i;let r=((i=Ve[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),o=r.catch(()=>{});return Ve[e]=o,o.then(()=>{Ve[e]===o&&delete Ve[e]}),r},Jr=(e,t)=>{var o,i;let n=e.split(".").map(a=>parseInt(a,10)||0),r=t.split(".").map(a=>parseInt(a,10)||0);for(let a=0;a<Math.max(n.length,r.length);a++){let l=((o=n[a])!=null?o:0)-((i=r[a])!=null?i:0);if(l)return l}return 0},Yr=({manifest:e,zip_path:t})=>Kn(e.app_id,async()=>{var i;let n=O().file_system,r=R(e.app_id);if(r&&Jr(r.version,e.version)>=0&&await le(r))return r;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let o=Pt(e.app_id,e.version,e.entry,!!e.context_update,(i=e.permissions)!=null?i:[]);return await n.remove(o.dir).catch(()=>{}),await n.mkdir(o.dir),await n.unzip(t,o.dir),vt(e),G("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),Jn(e.app_id,[e.version,r==null?void 0:r.version].filter(Boolean)),o}),Ot=(e,{base_url:t,onProgress:n}={})=>{let r=O().file_system,o=null,i=!1,a=`${r.cache_dir}/${e.app_id}-${e.version}.zip`,l=()=>{if(i)throw new Ce},c=async()=>{var g;l();let s=R(e.app_id);if((s==null?void 0:s.version)===e.version&&await r.exists(s.dir))return vt(e),R(e.app_id);l();let d=r.download({url:t?Wr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(y,p)=>{var P;let f=p>0?p:(P=e.size)!=null?P:0;f>0&&(n==null||n(Math.min(1,y/f)))}});o=d;try{let{status:y}=await d.promise;if(l(),y!==200)throw new Error(`bundle ${y}`);if(e.sha256)if(r.sha256){if(await r.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else G("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);l();let p=Pt(e.app_id,e.version,e.entry,!!e.context_update,(g=e.permissions)!=null?g:[]);return await r.remove(p.dir).catch(()=>{}),await r.mkdir(p.dir),await r.unzip(a,p.dir),vt(e),Jn(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),p}catch(y){throw i?new Ce:y}finally{o=null,r.remove(a).catch(()=>{})}};return{promise:Kn(e.app_id,c),cancel:()=>{i=!0,o==null||o.cancel()}}},qe={},Kr=__DEV__?0:60*1e3,Wn={},Gn=(e,t)=>{var r,o;let n=R(e);return n&&Date.now()-((r=Wn[t])!=null?r:0)<Kr?Promise.resolve(n):((o=qe[e])!=null||(qe[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 Ot(a,{base_url:t}).promise;return Wn[t]=Date.now(),l})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),R(e))).finally(()=>{qe[e]=void 0})),qe[e])};var et=new Map,Xn=(e,t)=>(et.set(e,t),()=>{et.get(e)===t&&et.delete(e)}),Gr=(e,t)=>{let n=et.get(e);return n?n(t):!1};import{useCallback as Xr,useEffect as Qn,useRef as Zn,useState as Qr}from"react";import{Animated as Ct,BackHandler as Zr,StyleSheet as tr,Text as Tt,TouchableOpacity as er,View as tt}from"react-native";import{jsx as me,jsxs as kt}from"react/jsx-runtime";var eo="#22C55E",It=({scanner:e})=>{let{vision:t,types:n,mode:r}=e,o=t.useCameraDevice("back"),[i,a]=Qr(!1),l=j(se,p=>p.last_value),c=j(se,p=>p.hit_tick),s=Zn(new Ct.Value(0)).current,d=t.useCodeScanner({codeTypes:n,onCodeScanned:Xr(p=>Cn(p),[])});Qn(()=>{let p=Zr.addEventListener("hardwareBackPress",()=>(St(),!0));return()=>p.remove()},[]);let g=Zn(c);Qn(()=>{if(c===g.current)return;s.setValue(1);let p=Ct.timing(s,{toValue:0,duration:350,useNativeDriver:!0});return p.start(),()=>p.stop()},[c,s]);let y=!!(o!=null&&o.hasTorch);return kt(tt,{style:r===ce.continuous?z.continuous:z.once,children:[o&&me(t.Camera,{style:tr.absoluteFill,device:o,isActive:!0,codeScanner:d,torch:i&&y?"on":"off",onError:p=>On(p.message)}),kt(tt,{style:z.frame_wrap,pointerEvents:"none",children:[me(tt,{style:z.frame}),me(Ct.View,{style:[z.frame,z.frame_hit,{opacity:s}]})]}),kt(tt,{style:z.footer,children:[me(er,{activeOpacity:.7,style:z.button,onPress:St,accessibilityRole:"button",children:me(Tt,{style:z.button_text,children:"\u0110\xF3ng"})}),me(Tt,{style:z.last_value,numberOfLines:1,children:l!=null?l:""}),y&&me(er,{activeOpacity:.7,style:[z.button,i&&z.button_on],onPress:()=>a(p=>!p),accessibilityRole:"button",children:me(Tt,{style:[z.button_text,i&&z.button_text_on],children:"\u0110\xE8n"})})]})]})},z=tr.create({continuous:{height:"38%",backgroundColor:"#000000",overflow:"hidden"},once:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"#000000"},frame_wrap:{position:"absolute",top:0,left:0,right:0,bottom:0,alignItems:"center",justifyContent:"center"},frame:{width:"70%",aspectRatio:1.6,maxHeight:"60%",borderRadius:12,borderWidth:2,borderColor:"rgba(255,255,255,0.8)"},frame_hit:{position:"absolute",borderWidth:4,borderColor:eo},footer:{position:"absolute",left:12,right:12,bottom:12,flexDirection:"row",alignItems:"center",gap:8},last_value:{flex:1,textAlign:"center",color:"#FFFFFF",fontWeight:"600"},button:{paddingHorizontal:14,paddingVertical:8,borderRadius:999,backgroundColor:"rgba(0,0,0,0.6)"},button_on:{backgroundColor:"#FFFFFF"},button_text:{color:"#FFFFFF",fontWeight:"600"},button_text_on:{color:"#18181B"}});var H=Re({active_key:null,instances:{}}),nr=({app:e,instance_id:t,context:n={},url_params:r={},host_data:o={}},i)=>{var l;let a=(l=O().keep_alive)==null?void 0:l.max_webviews;H.setState(c=>{let s=t!=null?t:e.app_id,d={...c.instances,[s]:{key:s,app:e,context:n,url_params:r,host_data:o,last_used_at:Date.now()}},g=Object.keys(d);return a&&a>0&&g.length>a&&g.filter(y=>y!==s).sort((y,p)=>d[y].last_used_at-d[p].last_used_at).slice(0,g.length-a).forEach(y=>{delete d[y]}),i?{active_key:s,instances:d}:{instances:d}})},to=e=>nr(e,!0),no=e=>nr(e,!1),je=()=>H.setState({active_key:null}),nt=e=>{H.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var rr="catalog",ro="paused_apps",oo="removed_apps",io=10*1e3,so=2,ao=3e3,co=()=>{var e;try{return JSON.parse((e=O().storage.getString(rr))!=null?e:"{}")}catch{return{}}},E=Re({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),or=e=>{var t;return!!((t=O().manual_update)!=null&&t.includes(e))},it=new Set,ir=e=>{let t=new Set,n=()=>O().storage.setString(e,JSON.stringify([...t]));return{has:r=>t.has(r),values:()=>[...t],add:r=>t.has(r)?!1:(t.add(r),n(),!0),delete:r=>t.delete(r)?(n(),!0):!1,load:()=>{var r;t.clear();try{let o=JSON.parse((r=O().storage.getString(e))!=null?r:"[]");Array.isArray(o)&&o.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},re=ir(ro),ye=ir(oo);Jt(()=>{re.load(),ye.load();let e=co(),t={};Object.keys(e).filter(n=>!ye.has(n)).forEach(n=>{let r=R(n);r?t[n]={status:"installed",progress:1,version:r.version,has_local:!0}:re.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),E.setState({catalog:e,downloads:t})});var Dt=e=>j(E,t=>e?t.downloads[e]:void 0),lo=()=>j(E,e=>e.pause_reasons.length>0),ne=(...e)=>G("queue",...e),D=[],pe={},_=null,rt=new Set,_e={},Lt=new Set,fe=e=>{Lt.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},po=e=>(Lt.add(e),()=>{Lt.delete(e)}),uo=()=>E.getState().downloads,W=(e,t)=>{let n=!!R(e),r=E.getState().downloads[e],o=t.status==="downloading"&&n?"updating":t.status,i={...r!=null?r:{status:"queued",progress:0},...t,...o?{status:o}:{},has_local:n};E.setState(a=>({downloads:{...a.downloads,[e]:i}})),(r==null?void 0:r.status)!==i.status||(r==null?void 0:r.version)!==i.version||(r==null?void 0:r.has_local)!==i.has_local?fe({type:"status_change",app_id:e,state:i}):r.progress!==i.progress&&fe({type:"progress",app_id:e,progress:i.progress,version:i.version})},ot=(e,t)=>{var n;(n=_e[e])==null||n.forEach(r=>r(t)),delete _e[e]},go=()=>E.getState().pause_reasons.length>0,he=e=>{var l;if(_)return;let t=e?D.indexOf(e):go()?-1:D.findIndex(c=>!re.has(c));if(t<0||t>=D.length)return;let[n]=D.splice(t,1),r=E.getState().catalog[n];if(!r){ot(n,R(n)),he();return}let o=Date.now();pe[n]=((l=pe[n])!=null?l:0)+1,W(n,{status:"downloading",progress:0,version:r.version,error:void 0});let i=0,a=Ot(r,{onProgress:c=>{let s=Math.floor(c*100);s!==i&&(i=s,W(n,{progress:s/100,version:r.version}))}});_={app_id:n,handle:a,forced:!!e},ne("start",n,r.version,e?"(forced)":""),a.promise.then(c=>{ne("installed",n,r.version,`${Date.now()-o}ms`),W(n,{status:"installed",progress:1,version:r.version}),ot(n,c)}).catch(c=>{var d;if(c instanceof Ce){if(rt.has(n))return;ne("paused",n),pe[n]-=1,D.unshift(n),W(n,{status:re.has(n)?"paused":"queued",progress:0,version:r.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]<so){W(n,{status:"queued",progress:0,version:r.version,error:s}),setTimeout(()=>{var g;D.includes(n)||(_==null?void 0:_.app_id)===n||(D.push(n),he((g=_e[n])!=null&&g.length?n:void 0))},ao);return}W(n,{status:"failed",progress:0,version:r.version,error:s}),ot(n,R(n))}).finally(()=>{_=null;let c=D.find(s=>{var d;return(d=_e[s])==null?void 0:d.length});he(c)})},st=(e,{front:t=!1}={})=>{if((_==null?void 0:_.app_id)===e)return;let n=D.indexOf(e);if(n>=0){if(!t)return;D.splice(n,1)}t?D.unshift(e):D.push(e)},mo=async e=>{let{host_id:t,client_token:n}=O(),r=new AbortController,o=setTimeout(()=>r.abort(),io);try{let i=`${pt}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:r.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(c=>({...c,channel:e}))}finally{clearTimeout(o)}},ze=null,Nt=()=>(ze!=null||(ze=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(O().channels.map(mo)),r={};[...n].reverse().flat().forEach(c=>{r[c.app_id]=c});let o=Object.keys(E.getState().catalog).filter(c=>!r[c]);O().storage.setString(rr,JSON.stringify(r)),E.setState({catalog:r}),await Promise.all(o.map(c=>sr(c,{by_user:!1}))),o.forEach(c=>ye.delete(c));let i=Object.keys(r).filter(c=>!ye.has(c)),a=[],l={};for(let c of i.map(s=>r[s])){if(await Rt(c)){W(c.app_id,{status:"installed",progress:1,version:c.version});continue}let s=R(c.app_id);if(or(c.app_id)&&!it.has(c.app_id)&&s&&await le(s)){W(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 E.setState({updates:l}),a.forEach(c=>{pe[c.app_id]=0,W(c.app_id,{status:re.has(c.app_id)?"paused":"queued",progress:0,version:c.version,error:void 0}),st(c.app_id)}),ne("catalog",i.length,"apps, outdated",a.map(c=>c.app_id),"removed",o,`${Date.now()-e}ms`),fe({type:"sync_complete",app_ids:i,removed:o}),Object.values(l).forEach(c=>fe({type:"update_available",...c})),he(),{ok:!0,app_ids:i,removed:o}}catch(n){let r=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",r),fe({type:"sync_failed",error:r}),{ok:!1,error:r}}finally{ze=null}})()),ze),sr=async(e,{by_user:t})=>{var o,i,a,l;if(t&&ye.add(e),rt.has(e))return;rt.add(e),re.delete(e);let n=D.indexOf(e);n>=0&&D.splice(n,1),(_==null?void 0:_.app_id)===e&&_.handle.cancel();let r=(l=(a=(o=E.getState().downloads[e])==null?void 0:o.version)!=null?a:(i=R(e))==null?void 0:i.version)!=null?l:"";W(e,{status:"uninstalling",progress:0,version:r}),await Yn(e),nt(e),E.setState(c=>{let s={...c.downloads};return delete s[e],{downloads:s}}),delete pe[e],rt.delete(e),ot(e,null),ne("uninstalled",e,t?"(user)":"(not in list)"),fe({type:"uninstalled",app_id:e})},fo=e=>sr(e,{by_user:!0}),ho=e=>{let t=He(e);return t?(ye.delete(e),(_==null?void 0:_.app_id)===e||D.includes(e)||(pe[e]=0,W(e,{status:re.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),st(e),he(),ne("restore",e)),!0):!1},yo=e=>{if(re.has(e))return;if(re.add(e),ne("pause app",e),(_==null?void 0:_.app_id)===e&&!_.forced){_.handle.cancel();return}let t=E.getState().downloads[e];D.includes(e)&&t&&W(e,{status:"paused",progress:0,version:t.version})},wo=e=>{if(!re.delete(e))return;ne("resume app",e);let t=E.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!D.includes(e)&&He(e)&&(pe[e]=0,st(e)),D.includes(e)&&t&&W(e,{status:"queued",progress:0,version:t.version}),he()},Ao=e=>{let{pause_reasons:t}=E.getState();t.includes(e)||(E.setState({pause_reasons:[...t,e]}),ne("pause",e),t.length===0&&fe({type:"pause_change",paused:!0,reasons:[e]}),_&&!_.forced&&_.handle.cancel())},So=e=>{let{pause_reasons:t}=E.getState();if(!t.includes(e))return;let n=t.filter(r=>r!==e);E.setState({pause_reasons:n}),ne("resume",e),n.length===0&&fe({type:"pause_change",paused:!1,reasons:n}),he()},ar=e=>E.getState().updates[e],bo=async e=>{var n,r;let t=ar(e);it.add(e);try{let o=await at(e),i=(r=t==null?void 0:t.next_version)!=null?r:(n=He(e))==null?void 0:n.version;return!o||!i||o.version!==i?!1:(E.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}}}),ne("updated",e,t==null?void 0:t.current_version,"\u2192",o.version),!0)}finally{it.delete(e)}},Mo=()=>Object.values(E.getState().catalog).map(e=>({...e,installed:!!R(e.app_id),removed_by_user:ye.has(e.app_id)})),He=e=>E.getState().catalog[e],at=async e=>{let t=He(e);if(!t)return;if(re.delete(e),ye.delete(e),await Rt(t))return R(e);let n=R(e);if(or(e)&&!it.has(e)&&n&&await le(n))return n;let r=new Promise(o=>{var i;((i=_e[e])!=null?i:_e[e]=[]).push(o)});return(_==null?void 0:_.app_id)===e?_.forced=!0:(pe[e]=0,st(e,{front:!0}),_&&!_.forced?_.handle.cancel():he(e)),r};import{Fragment as ur,jsx as F,jsxs as Je}from"react/jsx-runtime";var Ft=e=>(e!=null?e:"").replace(/\?[^#]*/,""),lr=0,Oo=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},Co=qt.memo(({instance_key:e,is_active:t,is_front:n,is_dark:r,reload_tick:o,web_at_top:i,splash:a,bridge:l,opaque_background:c,allow_embedded_miniapps:s,onWebLoadEnd:d})=>{var jt,zt;let g=oe(null),y=oe(!1),p=j(H,m=>m.instances[e]),f=p==null?void 0:p.app.app_id,P=p==null?void 0:p.app.manifest_url,M=p==null?void 0:p.context,v=p==null?void 0:p.url_params,S=j(se,m=>{var A;return((A=m.active)==null?void 0:A.owner)===e?m.active:null}),[w,q]=xe(()=>f?R(f):null),[Z,ie]=xe(!1),[we,h]=xe(0),[b,$]=xe(0),[x,k]=xe(!1),N=oe(null),B=m=>{N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{N.current=null,k(!0)},m)};J(()=>()=>{N.current&&clearTimeout(N.current)},[]),J(()=>{if(!f||!t&&w)return;let m=!0;return ie(!1),(async()=>{let A=R(f),V=A?await le(A):!1;if(!m||(q(V?te=>!te||te.version!==A.version||te.permissions.join(",")!==A.permissions.join(",")?A:te:null),__DEV__&&Date.now()-lr>1e4&&(lr=Date.now(),await Nt()),!m))return;let ue=await at(f),Se=ue!==void 0?ue:P?await Gn(f,P):R(f);if(m){if(!Se){ie(!0);return}q(te=>te!=null?te:Se)}})(),()=>{m=!1}},[t,f,P,we]),J(()=>Xn(e,m=>g.current?(g.current.postMessage(m),!0):!1),[e]);let C=j(E,m=>{let A=f?m.downloads[f]:void 0;return(A==null?void 0:A.status)==="installed"?A.version:void 0});J(()=>{if(t||!f||!w)return;let m=R(f);if(!m||m.version===w.version)return;let A=!0;return le(m).then(V=>{!A||!V||(G(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",w.version,"\u2192",m.version),q(m))}),()=>{A=!1}},[t,f,C,w==null?void 0:w.version]);let Y=j(E,m=>{var A;return f&&(A=m.apply_ticks[f])!=null?A:0});J(()=>{if(!Y||!f)return;let m=R(f);if(!m||m.version===(w==null?void 0:w.version))return;let A=!0;return le(m).then(V=>{!A||!V||(G(`webview:${e}`,"c\u1EADp nh\u1EADt",w==null?void 0:w.version,"\u2192",m.version),k(!1),q(m))}),()=>{A=!1}},[Y]),J(()=>{var V;let m=(V=O().keep_alive)==null?void 0:V.idle_close_ms;if(t||!m||m<=0)return;let A=setTimeout(()=>{nt(e)},m);return()=>clearTimeout(A)},[t,e]),J(()=>{o>0&&(ie(!1),k(!1),$(m=>m+1),h(m=>m+1))},[o]);let Te=oe(t);J(()=>{var m;Te.current!==t&&(Te.current=t,y.current&&((m=g.current)==null||m.injectJavaScript($n(t?"resumed":"paused"))))},[t]);let Ae=`${(jt=w==null?void 0:w.version)!=null?jt:"none"}:${(zt=w==null?void 0:w.permissions.join(","))!=null?zt:""}:${b}`,ee=ct(()=>JSON.stringify([M!=null?M:{},v!=null?v:{}]),[M,v]),ke=ct(()=>{var m;return zn(v!=null?v:{},(m=w==null?void 0:w.permissions)!=null?m:[])},[ee,w==null?void 0:w.permissions]),Ee=ct(()=>Vn(M!=null?M:{},ke)+Un()+(Eo.OS==="android"?Fn():"")+(O().debug?Nn():""),[ke]),Pe=oe(null),Ie=oe(null);J(()=>{var A,V,ue;if(!w)return;if(Ie.current!==Ae){Ie.current=Ae,Pe.current=ee;return}if(Pe.current===ee)return;let m=((V=JSON.parse((A=Pe.current)!=null?A:"[]")[0])!=null?V:{}).org_id;if(Pe.current=ee,m===(M==null?void 0:M.org_id)&&y.current){k(!1),B(1500),(ue=g.current)==null||ue.injectJavaScript(Bn(M!=null?M:{},ke));return}k(!1),$(Se=>Se+1)},[ee,w,Ae]),J(()=>(t||(ae(e),ge(e),ve(e)),()=>{ae(e),ge(e),ve(e)}),[t,e,Ae,o]),J(()=>{let m=cr.addEventListener("change",A=>{A==="background"&&!wn()&&ae(e),A==="background"&&!vn()&&ge(e)});return()=>m.remove()},[e]);let gr=$t(async m=>{var V,ue,Se,te,lt;let A=kn(m.nativeEvent.data);if(!A){if(f&&(l!=null&&l.onWebEvent))try{Promise.resolve(l.onWebEvent(m.nativeEvent.data,{app_id:f,instance_id:e})).catch(T=>{console.warn("[miniapp] onWebEvent l\u1ED7i",f,T)})}catch(T){console.warn("[miniapp] onWebEvent l\u1ED7i",f,T)}return}if(A.method==="log"){let{level:T,text:U}=A;G(`web:${e}`,T!=null?T:"log",U!=null?U:"");return}if(A.method==="pong"){N.current||k(!0);return}if(A.method==="touchAtTop"){i.emit(!!A.at_top);return}if(A.method==="contextApplied"){N.current&&clearTimeout(N.current),N.current=null,k(!0);return}if(A.method==="ready"){y.current=!0,k(!0);let T=(V=H.getState().instances[e])==null?void 0:V.context;T&&((ue=g.current)==null||ue.injectJavaScript(Mt(T)));return}try{let T=await Hn(A,{getHostData:()=>{var U,K;return(K=(U=H.getState().instances[e])==null?void 0:U.host_data)!=null?K:{}},getPermissions:()=>{var U,K;return f?(K=(U=R(f))==null?void 0:U.permissions)!=null?K:[]:[]},getContext:()=>{var U,K;return(K=(U=H.getState().instances[e])==null?void 0:U.context)!=null?K:{}},is_dark:r,close:je,app_id:f!=null?f:"",instance_id:e,options:l,emit:(U,K)=>{var Ht;(Ht=g.current)==null||Ht.injectJavaScript(Dn(U,K))},isActive:()=>H.getState().active_key===e&&cr.currentState!=="background"});A.id&&((Se=g.current)==null||Se.injectJavaScript(In(A.id,T)))}catch(T){if(!A.id)return;let U=T==null?void 0:T.code,K=T instanceof u?T:new u(typeof U=="string"?U:"HOST_ERROR",String((te=T==null?void 0:T.message)!=null?te:T));(lt=g.current)==null||lt.injectJavaScript(Ln(A.id,K))}},[e,r,f,i,l]),mr=$t(()=>{ie(!1),$(m=>m+1),h(m=>m+1)},[]);return Je(Bt,{style:[Vt.absoluteFill,c&&{backgroundColor:r?"#09090B":"#FFFFFF"},!n&&Q.behind],pointerEvents:t?"auto":"none",children:[(S==null?void 0:S.mode)===ce.continuous&&F(It,{scanner:S}),w?F(Ro,{ref:g,source:{uri:w.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,allowingReadAccessToURL:`file://${s?xt():w.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:Ee,onMessage:gr,bounces:!1,overScrollMode:"never",onLoadStart:m=>{ae(e),ge(e),ve(e),G(`webview:${e}`,"load start",Ft(m.nativeEvent.url)),y.current=!1,k(!1)},onError:m=>{ae(e),ge(e),ve(e),G(`webview:${e}`,"load error",Ft(m.nativeEvent.url),m.nativeEvent.description),ie(!0),k(!1)},onLoadEnd:m=>{let A=m.nativeEvent.url;G(`webview:${e}`,"load end",Ft(A)),f&&(d==null||d({app_id:f,instance_id:e,url:A})),B(1500)},onContentProcessDidTerminate:()=>{ae(e),ge(e),ve(e),y.current=!1,k(!1),$(m=>m+1)},onRenderProcessGone:()=>(ae(e),ge(e),ve(e),y.current=!1,k(!1),$(m=>m+1),!0),style:Q.webview},Ae):null,(S==null?void 0:S.mode)===ce.once&&F(It,{scanner:S}),p&&F(ko,{visible:!w||!x,interactive:Z,children:F(To,{splash:a,app:p.app,is_dark:r,error:Z,has_bundle:!!w,retry:mr})})]})}),To=qt.memo(({splash:e,app:t,is_dark:n,error:r,has_bundle:o,retry:i})=>{let a=e,l=Dt(t.app_id),c=r?"error":!o&&(l==null?void 0:l.status)==="downloading"?"downloading":"loading";return F(a,{app:t,is_dark:n,status:c,progress:c==="downloading"?l==null?void 0:l.progress:void 0,retry:i})}),ko=({visible:e,interactive:t,children:n})=>{let r=oe(new Ut.Value(e?1:0)).current,[o,i]=xe(e);return J(()=>{if(e){i(!0),r.setValue(1);return}let a=Ut.timing(r,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:l})=>{l&&i(!1)}),()=>a.stop()},[e,r]),o?F(Ut.View,{style:[Vt.absoluteFill,{opacity:r}],pointerEvents:t?"auto":"none",children:n}):null},dr=({app:e,is_dark:t,status:n,progress:r,retry:o})=>{let i=t?"#FAFAFA":"#18181B";return Je(Bt,{style:[Q.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[F(Bt,{style:[Q.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?F(xo,{source:{uri:e.icon},style:Q.splash_icon_image}):F(We,{style:Q.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),F(We,{style:[Q.splash_name,{color:i}],children:e.name}),n==="error"?Je(ur,{children:[F(We,{style:Q.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),F(Po,{activeOpacity:.7,style:[Q.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:o,children:F(We,{style:[Q.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):Je(ur,{children:[F(vo,{style:Q.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&Je(We,{style:Q.splash_hint,children:["\u0110ang t\u1EA3i mini app",r?` ${Math.round(r*100)}%`:"\u2026"]})]})]})},pr=(e,t)=>{let n=oe(t),r=oe(!1);__DEV__&&!r.current&&n.current!==t&&(r.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.`))},Io=({container:e,splash:t=dr,is_dark:n=!1,bridge:r,close_on_back:o=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:l})=>{pr("container",e),pr("splash",t);let c=e,s=j(H,S=>S.active_key),d=oe(s);s&&(d.current=s);let g=j(H,S=>Object.keys(S.instances).join("|")),y=j(H,S=>{var w;return S.active_key?(w=S.instances[S.active_key])==null?void 0:w.app.name:void 0}),p=ct(()=>g?g.split("|"):[],[g]),[f,P]=xe({}),M=oe(Oo()).current;J(()=>{if(!s||!o)return;let S=_o.addEventListener("hardwareBackPress",()=>(je(),!0));return()=>S.remove()},[s,o]);let v=$t(()=>{let S=H.getState().active_key;S&&P(w=>({...w,[S]:(w[S]||0)+1}))},[]);return p.length?F(c,{visible:!!s,title:y!=null?y:"",is_dark:n,close:je,reload:v,subscribeWebAtTop:M.subscribe,children:p.map(S=>F(Co,{instance_key:S,is_active:s===S,is_front:(s!=null?s:d.current)===S,is_dark:n,reload_tick:f[S]||0,web_at_top:M,splash:t,bridge:r,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:l},S))}):null},Q=Vt.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"}}),Lo=qt.memo(Io);export{ht as CodeType,dr as DefaultMiniAppSplash,pt as MINIAPP_PLATFORM_URL,Lo as MiniAppHost,u as MiniAppHostError,Oe as ScannerEndReason,yt as ScannerEvent,Fe as ScannerMethod,je as closeMiniApp,fr as configureMiniApp,yr as createMmkvStorage,Yt as createReactNativeBiometrics,hr as createRnfsFileSystem,at as ensureMiniApp,R as getLocalMiniApp,Mo as getMiniAppCatalog,He as getMiniAppCatalogEntry,uo as getMiniAppStatuses,ar as getMiniAppUpdate,Yr as installBundledMiniApp,po as onMiniAppEvent,to as openMiniApp,yo as pauseMiniApp,Ao as pauseMiniAppDownloads,no as preloadMiniApp,ae as releaseSpeechFor,ho as restoreMiniApp,wo as resumeMiniApp,So as resumeMiniAppDownloads,Gr as sendEventToWeb,Nt as syncMiniAppCatalog,fo as uninstallMiniApp,bo as updateMiniApp,un as uploadToUrl,Dt as useMiniAppDownload,lo as useMiniAppDownloadsPaused};
|
|
66
|
+
true;`},ro={partner:"partner_token",chatbox:"chatbox_token"},io=(e,t)=>{let n={...e};for(let o of Object.values(ro))t.includes(o)||delete n[o];return n},Ut=new Set,He=async(e,t)=>{if(Ut.has(e))throw new d("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);Ut.add(e);try{return await t()}finally{Ut.delete(e)}},so=()=>`(function () {
|
|
67
|
+
try {
|
|
68
|
+
var AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
69
|
+
if (!AudioCtx) { return; }
|
|
70
|
+
var ctx = window.__retionBeepCtx || (window.__retionBeepCtx = new AudioCtx());
|
|
71
|
+
if (ctx.state === 'suspended') { ctx.resume(); }
|
|
72
|
+
var oscillator = ctx.createOscillator();
|
|
73
|
+
var gain = ctx.createGain();
|
|
74
|
+
oscillator.type = 'square';
|
|
75
|
+
oscillator.frequency.value = 2000;
|
|
76
|
+
gain.gain.value = 0.15;
|
|
77
|
+
oscillator.connect(gain);
|
|
78
|
+
gain.connect(ctx.destination);
|
|
79
|
+
oscillator.start(ctx.currentTime);
|
|
80
|
+
oscillator.stop(ctx.currentTime + 0.08);
|
|
81
|
+
} catch (e) {}
|
|
82
|
+
})(); true;`,cr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),dt=(e,t)=>{if(typeof e!="string"||!e)throw new d("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},ao=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:p,isActive:g,playBeep:w})=>{var M,b,A,j,G,te,ne,oe,re;let u=s==null?void 0:s.handlers,h={app_id:c,instance_id:l,close:a},P=()=>{var m;(m=s==null?void 0:s.haptic)==null||m.call(s,"impactLight"),w==null||w()},v=()=>new d("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let m=un(t);return He(e,()=>dn(m,g))}case"speech.start":{if(!p)throw v();let m={};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 d("INVALID_PARAMS","lang ph\u1EA3i l\xE0 m\xE3 ng\xF4n ng\u1EEF nh\u01B0 vi-VN");m.lang=t.lang}for(let y of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[y])!==void 0){if(typeof t[y]!="boolean")throw new d("INVALID_PARAMS",`${y} ph\u1EA3i l\xE0 boolean`);m[y]=t[y]}return In(l,m,p,g)}case"speech.stop":return Fn(l);case je.scan:return qn(l,It(t),g,P);case je.start:{if(!p)throw v();return $n(l,It(t),p,g,P)}case je.stop:return zn(l);case"uploadFiles":{let{task_id:m,...y}=t!=null?t:{};if(m!==void 0&&(typeof m!="string"||!m))throw new d("INVALID_PARAMS","task_id ph\u1EA3i l\xE0 chu\u1ED7i");return Tn(bn(y),{instance_id:l,app_id:c,getContext:r,task_id:m,config:s==null?void 0:s.upload,emit:p,exclusivePick:x=>He("uploadFiles.pick",x)})}case"uploadFiles.cancel":Cn(l,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Pn(s==null?void 0:s.upload);case"getBiometricAvailability":return((M=s==null?void 0:s.biometrics)!=null?M:await Pt()).getAvailability();case"authenticateBiometric":{let m=dt(t==null?void 0:t.reason,"reason").trim();if(!m||m.length>200)throw new d("INVALID_PARAMS","reason must contain 1\u2013200 characters");let y=t==null?void 0:t.cancelButtonText;if(y!==void 0&&(typeof y!="string"||!y.trim()||y.length>80))throw new d("INVALID_PARAMS","Invalid cancelButtonText");return He(e,async()=>{var O;return((O=s==null?void 0:s.biometrics)!=null?O:await Pt()).authenticate({reason:m,cancelButtonText:y})})}case"requestPayment":{let m=u==null?void 0:u.requestPayment;if(!m)throw v();let y=t==null?void 0:t.amount;if(typeof y!="number"||!Number.isFinite(y)||y<=0)throw new d("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let x={...t,amount:y,currency:dt(t==null?void 0:t.currency,"currency")};return He(e,()=>m(x,h))}case"printImage":{let m=u==null?void 0:u.printImage;if(!m)throw v();let y=dt(t==null?void 0:t.image,"image");await He(e,()=>m({image:y},h));return}case"openScreen":if(!(u!=null&&u.openScreen))throw v();await u.openScreen({screen:dt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},h);return;case"closeApp":a();return;case"openWebview":{let m=String((b=t==null?void 0:t.url)!=null?b:"");if(!/^https?:\/\//i.test(m))throw new d("INVALID_PARAMS","url ph\u1EA3i l\xE0 http(s)");await(s!=null&&s.openUrl?s.openUrl(m):Hn.openURL(m));return}case"openLink":{let m=String((A=t==null?void 0:t.url)!=null?A:"").trim();if(!/^[a-z][a-z0-9+.-]*:/i.test(m)||/^(javascript|file|data|about|blob):/i.test(m))throw new d("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(m):Hn.openURL(m))}catch(y){throw new d("NOT_SUPPORTED",String((G=(j=y==null?void 0:y.message)!=null?j:y)!=null?G:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":(ne=s==null?void 0:s.showToast)==null||ne.call(s,String((te=t==null?void 0:t.message)!=null?te:""));return;case"haptic":{let m=cr.has(t==null?void 0:t.type)?t.type:"selection";(oe=s==null?void 0:s.haptic)==null||oe.call(s,m);return}case"getSystemInfo":return{platform:ar.OS==="ios"?"ios":"android",appVersion:(re=s==null?void 0:s.app_version)!=null?re:"",theme:i?"dark":"light"};case"getAccessToken":{let m=n().access_token;if(!m)throw new d("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return m}case"getToken":{let m=t==null?void 0:t.type;if(m==="access"){let O=n().access_token;if(!O)throw new d("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return O}if(m!=="partner"&&m!=="chatbox")throw new d("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(m)}`);let y=ro[m];if(!o().includes(y))throw new d("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${y} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let x=m==="partner"?n().partner_token:n().chatbox_token;if(!x)throw new d("HOST_ERROR",`Kh\xF4ng c\xF3 ${y}`);return x}case"getUserInfo":{let m=n().user;if(!m)throw new d("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin nh\xE2n vi\xEAn");return m}case"getPageInfo":{let m=n().page;if(!m)throw new d("HOST_ERROR","Kh\xF4ng l\u1EA5y \u0111\u01B0\u1EE3c th\xF4ng tin page");return m}case"sendMessage":case"insertText":throw new d("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF phi\xEAn b\u1EA3n app n\xE0y`);default:throw new d("NOT_SUPPORTED",`API kh\xF4ng t\u1ED3n t\u1EA1i: ${e}`)}};var qt=e=>`bundle:${e}`,$t=()=>`${F().file_system.document_dir}/miniapps`,zt=$t,Wt=(e,t,n="index.html",o=!1,r=[])=>{let i=`${zt()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},Bt=e=>{var t;F().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:[]}))},lr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,I=e=>{let t=F().storage.getString(qt(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return Wt(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},Ae=e=>F().file_system.exists(e.entry_uri.replace("file://","")),jt=async e=>{let t=I(e.app_id);return(t==null?void 0:t.version)===e.version&&await Ae(t)},lo=async(e,t)=>{let n=F().file_system,o=`${zt()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},po=async e=>{var t;await((t=Ye[e])==null?void 0:t.catch(()=>{})),F().storage.setString(qt(e),""),await F().file_system.remove(`${zt()}/${e}`).catch(()=>{})},Ve=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},Ye={},uo=(e,t)=>{var i;let o=((i=Ye[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return Ye[e]=r,r.then(()=>{Ye[e]===r&&delete Ye[e]}),o},pr=(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},ur=({manifest:e,zip_path:t})=>uo(e.app_id,async()=>{var i;let n=F().file_system,o=I(e.app_id);if(o&&pr(o.version,e.version)>=0&&await Ae(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=Wt(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),Bt(e),se("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),lo(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),Ht=(e,{base_url:t,onProgress:n}={})=>{let o=F().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,c=()=>{if(i)throw new Ve},l=async()=>{var g;c();let s=I(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return Bt(e),I(e.app_id);c();let p=o.download({url:t?lr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(w,u)=>{var P;let h=u>0?u:(P=e.size)!=null?P:0;h>0&&(n==null||n(Math.min(1,w/h)))}});r=p;try{let{status:w}=await p.promise;if(c(),w!==200)throw new Error(`bundle ${w}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else se("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);c();let u=Wt(e.app_id,e.version,e.entry,!!e.context_update,(g=e.permissions)!=null?g:[]);return await o.remove(u.dir).catch(()=>{}),await o.mkdir(u.dir),await o.unzip(a,u.dir),Bt(e),lo(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),u}catch(w){throw i?new Ve:w}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:uo(e.app_id,l),cancel:()=>{i=!0,r==null||r.cancel()}}},Ke={},dr=__DEV__?0:60*1e3,co={},go=(e,t)=>{var o,r;let n=I(e);return n&&Date.now()-((o=co[t])!=null?o:0)<dr?Promise.resolve(n):((r=Ke[e])!=null||(Ke[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 Ht(a,{base_url:t}).promise;return co[t]=Date.now(),c})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),I(e))).finally(()=>{Ke[e]=void 0})),Ke[e])};var mt=new Map,mo=(e,t)=>(mt.set(e,t),()=>{mt.get(e)===t&&mt.delete(e)}),gr=(e,t)=>{let n=mt.get(e);return n?n(t):!1};import{useCallback as mr,useEffect as Jt,useRef as Ge,useState as ft}from"react";import{Animated as Y,BackHandler as fr,Easing as fo,Platform as wo,StatusBar as hr,StyleSheet as wt,Text as Xe,TouchableOpacity as ht,View as B}from"react-native";import{Fragment as vr,jsx as k,jsxs as ge}from"react/jsx-runtime";var Ze="#22C55E",yr="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",wr=2,yt=18,Ar=1600,Qe=14,_r=2e3,ho=2,Be=2e3,br=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:Qe},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:Qe},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:Qe},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:Qe}],yo=({color:e})=>k(vr,{children:br.map((t,n)=>k(B,{style:[S.corner,t,{borderColor:e}]},n))}),Yt=({scanner:e})=>{var Se,fe,he;let{vision:t,types:n,mode:o,layout:r,hint:i}=e,a=r===we.top,c=t.useCameraDevice("back"),[l,s]=ft(!1),[p,g]=ft(1),[w,u]=ft({width:0,height:0}),h=z(V,E=>E.last_value),P=z(V,E=>E.hit_tick),v=z(V,E=>E.scan_count),M=z(V,E=>E.notice),b=z(V,E=>E.is_picking),A=Ge(null),[j,G]=ft(0),te=wo.OS==="ios"?54:(Se=hr.currentHeight)!=null?Se:0,ne=Ge(new Y.Value(0)).current,oe=Ge(new Y.Value(0)).current,re=Ge(new Y.Value(0)).current,m=Math.round(w.width*(a?.8:.78)),y=Math.round(a?w.height*.46:m*.78),x=Math.round((w.height-y)/2),O=Math.round((w.width-m)/2),$=t.useCodeScanner({codeTypes:n,onCodeScanned:mr(E=>Nt(E),[])});Jt(()=>{let E=fr.addEventListener("hardwareBackPress",()=>(Dt(),!0));return()=>E.remove()},[]);let L=Ge(P);Jt(()=>{if(P===L.current)return;ne.setValue(1),re.setValue(1);let E=Y.parallel([Y.timing(ne,{toValue:0,duration:450,useNativeDriver:!0}),Y.sequence([Y.delay(_r),Y.timing(re,{toValue:0,duration:250,useNativeDriver:!0})])]);return E.start(),()=>E.stop()},[P,ne,re]),Jt(()=>{let E=it=>Y.timing(oe,{toValue:it,duration:Ar,easing:fo.inOut(fo.quad),useNativeDriver:!0}),Oe=Y.loop(Y.sequence([E(1),E(0)]));return Oe.start(),()=>Oe.stop()},[oe]);let J=!!(c!=null&&c.hasTorch),be=(fe=c==null?void 0:c.neutralZoom)!=null?fe:1,me=c?Math.min(be*p,c.maxZoom):1,X=k(Xe,{style:[S.hint,!!M&&S.hint_notice],numberOfLines:1,children:(he=M!=null?M:i)!=null?he:yr});return ge(B,{ref:A,style:a?S.top:S.full,onLayout:({nativeEvent:{layout:E}})=>{var Oe;u({width:E.width,height:E.height}),(Oe=A.current)==null||Oe.measureInWindow((it,st)=>G(st))},children:[c&&k(t.Camera,{style:wt.absoluteFill,device:c,isActive:!b,codeScanner:$,torch:l&&J?"on":"off",zoom:me,enableZoomGesture:!0,onError:E=>Wn(E.message)}),w.height>0&&ge(B,{style:S.overlay,pointerEvents:"none",children:[k(B,{style:[S.dim_ring,{top:x-Be,left:O-Be,width:m+Be*2,height:y+Be*2}]}),ge(B,{style:{position:"absolute",top:x,left:O,width:m,height:y},children:[k(yo,{color:"#FFFFFF"}),k(Y.View,{style:[wt.absoluteFill,{opacity:ne}],children:k(yo,{color:Ze})}),ge(Y.View,{style:[S.scan_line_wrap,{transform:[{translateY:oe.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,y-yt)]})}]}],children:[k(B,{style:S.scan_glow_outer}),k(B,{style:S.scan_glow_inner}),k(B,{style:S.scan_line})]})]}),k(B,{style:[S.hint_slot,a?{top:0,height:x-6,justifyContent:"flex-end"}:{top:x+y+20}],children:X}),o===Ie.continuous&&!!h&&k(Y.View,{style:[S.result_slot,a?S.result_slot_top:{top:x+y+52},{opacity:re}],children:ge(B,{style:S.result,children:[k(B,{style:S.check_badge,children:k(B,{style:S.check_mark})}),k(Xe,{style:S.result_text,numberOfLines:1,children:h}),ge(Xe,{style:S.result_count,children:["\xB7 ",v," m\xE3"]})]})})]}),ge(ht,{activeOpacity:.7,style:[S.close_button,{top:Math.max(12,te-j+12)}],onPress:Dt,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[k(B,{style:[S.close_bar,S.close_bar_a]}),k(B,{style:[S.close_bar,S.close_bar_b]})]}),k(B,{style:[S.toolbar_wrap,!a&&S.toolbar_wrap_full],pointerEvents:"box-none",children:ge(B,{style:S.toolbar,children:[k(ht,{activeOpacity:.7,style:S.tool,onPress:jn,disabled:b,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:ge(B,{style:S.image_icon,children:[k(B,{style:S.image_icon_dot}),k(B,{style:S.image_icon_hill})]})}),!!c&&c.maxZoom>=be*ho&&k(ht,{activeOpacity:.7,style:[S.tool,p>1&&S.tool_on],onPress:()=>g(E=>E>1?1:ho),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:ge(Xe,{style:[S.zoom_text,p>1&&S.zoom_text_on],children:[p,"x"]})}),J&&k(ht,{activeOpacity:.7,style:[S.tool,l&&S.tool_on],onPress:()=>s(E=>!E),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:l},children:k(Xe,{style:[S.torch_icon,l&&S.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})},Sr="rgba(0,0,0,0.5)",Kt=40,S=wt.create({top:{height:"38%",backgroundColor:"#000000",overflow:"hidden"},full:{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:Be,borderColor:Sr,borderRadius:Be+Qe},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:yt,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:yt,borderRadius:yt/2,backgroundColor:Ze,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:Ze,opacity:.2},scan_line:{height:wr,borderRadius:1,backgroundColor:Ze},close_button:{position:"absolute",right:12,width:42,height:42,borderRadius:21,alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:18,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_wrap_full:{bottom:wo.OS==="ios"?34:20},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)",borderWidth:wt.hairlineWidth,borderColor:"rgba(255,255,255,0.18)"},tool:{width:Kt,height:Kt,borderRadius:Kt/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:14,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:18,fontWeight:"600"},image_icon:{width:19,height:15,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:2,right:2,width:3,height:3,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:1,bottom:-5,width:10,height:10,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result_slot_top:{top:8},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:Ze},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 Z=Ne({active_key:null,instances:{}}),Ao=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var c;let a=(c=F().keep_alive)==null?void 0:c.max_webviews;Z.setState(l=>{let s=t!=null?t:e.app_id,p={...l.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},g=Object.keys(p);return a&&a>0&&g.length>a&&g.filter(w=>w!==s).sort((w,u)=>p[w].last_used_at-p[u].last_used_at).slice(0,g.length-a).forEach(w=>{delete p[w]}),i?{active_key:s,instances:p}:{instances:p}})},Mr=e=>Ao(e,!0),xr=e=>Ao(e,!1),et=()=>Z.setState({active_key:null}),At=e=>{Z.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var _o="catalog",Er="paused_apps",Rr="removed_apps",Pr=10*1e3,Or=2,Cr=3e3,Tr=()=>{var e;try{return JSON.parse((e=F().storage.getString(_o))!=null?e:"{}")}catch{return{}}},C=Ne({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),bo=e=>{var t;return!!((t=F().manual_update)!=null&&t.includes(e))},St=new Set,So=e=>{let t=new Set,n=()=>F().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=F().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},ue=So(Er),Pe=So(Rr);ln(()=>{ue.load(),Pe.load();let e=Tr(),t={};Object.keys(e).filter(n=>!Pe.has(n)).forEach(n=>{let o=I(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:ue.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),C.setState({catalog:e,downloads:t})});var Xt=e=>z(C,t=>e?t.downloads[e]:void 0),kr=()=>z(C,e=>e.pause_reasons.length>0),pe=(...e)=>se("queue",...e),q=[],_e={},R=null,_t=new Set,Fe={},Gt=new Set,Ee=e=>{Gt.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Lr=e=>(Gt.add(e),()=>{Gt.delete(e)}),Ir=()=>C.getState().downloads,Q=(e,t)=>{let n=!!I(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?Ee({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Ee({type:"progress",app_id:e,progress:i.progress,version:i.version})},bt=(e,t)=>{var n;(n=Fe[e])==null||n.forEach(o=>o(t)),delete Fe[e]},Fr=()=>C.getState().pause_reasons.length>0,Re=e=>{var c;if(R)return;let t=e?q.indexOf(e):Fr()?-1:q.findIndex(l=>!ue.has(l));if(t<0||t>=q.length)return;let[n]=q.splice(t,1),o=C.getState().catalog[n];if(!o){bt(n,I(n)),Re();return}let r=Date.now();_e[n]=((c=_e[n])!=null?c:0)+1,Q(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=Ht(o,{onProgress:l=>{let s=Math.floor(l*100);s!==i&&(i=s,Q(n,{progress:s/100,version:o.version}))}});R={app_id:n,handle:a,forced:!!e},pe("start",n,o.version,e?"(forced)":""),a.promise.then(l=>{pe("installed",n,o.version,`${Date.now()-r}ms`),Q(n,{status:"installed",progress:1,version:o.version}),bt(n,l)}).catch(l=>{var p;if(l instanceof Ve){if(_t.has(n))return;pe("paused",n),_e[n]-=1,q.unshift(n),Q(n,{status:ue.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((p=l==null?void 0:l.message)!=null?p:l);if(console.warn("[miniapp-queue] failed",n,s),_e[n]<Or){Q(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var g;q.includes(n)||(R==null?void 0:R.app_id)===n||(q.push(n),Re((g=Fe[n])!=null&&g.length?n:void 0))},Cr);return}Q(n,{status:"failed",progress:0,version:o.version,error:s}),bt(n,I(n))}).finally(()=>{R=null;let l=q.find(s=>{var p;return(p=Fe[s])==null?void 0:p.length});Re(l)})},vt=(e,{front:t=!1}={})=>{if((R==null?void 0:R.app_id)===e)return;let n=q.indexOf(e);if(n>=0){if(!t)return;q.splice(n,1)}t?q.unshift(e):q.push(e)},Dr=async e=>{let{host_id:t,client_token:n}=F(),o=new AbortController,r=setTimeout(()=>o.abort(),Pr);try{let i=`${Rt}/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)}},tt=null,Zt=()=>(tt!=null||(tt=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(F().channels.map(Dr)),o={};[...n].reverse().flat().forEach(l=>{o[l.app_id]=l});let r=Object.keys(C.getState().catalog).filter(l=>!o[l]);F().storage.setString(_o,JSON.stringify(o)),C.setState({catalog:o}),await Promise.all(r.map(l=>vo(l,{by_user:!1}))),r.forEach(l=>Pe.delete(l));let i=Object.keys(o).filter(l=>!Pe.has(l)),a=[],c={};for(let l of i.map(s=>o[s])){if(await jt(l)){Q(l.app_id,{status:"installed",progress:1,version:l.version});continue}let s=I(l.app_id);if(bo(l.app_id)&&!St.has(l.app_id)&&s&&await Ae(s)){Q(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=>{_e[l.app_id]=0,Q(l.app_id,{status:ue.has(l.app_id)?"paused":"queued",progress:0,version:l.version,error:void 0}),vt(l.app_id)}),pe("catalog",i.length,"apps, outdated",a.map(l=>l.app_id),"removed",r,`${Date.now()-e}ms`),Ee({type:"sync_complete",app_ids:i,removed:r}),Object.values(c).forEach(l=>Ee({type:"update_available",...l})),Re(),{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),Ee({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{tt=null}})()),tt),vo=async(e,{by_user:t})=>{var r,i,a,c;if(t&&Pe.add(e),_t.has(e))return;_t.add(e),ue.delete(e);let n=q.indexOf(e);n>=0&&q.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=I(e))==null?void 0:i.version)!=null?c:"";Q(e,{status:"uninstalling",progress:0,version:o}),await po(e),At(e),C.setState(l=>{let s={...l.downloads};return delete s[e],{downloads:s}}),delete _e[e],_t.delete(e),bt(e,null),pe("uninstalled",e,t?"(user)":"(not in list)"),Ee({type:"uninstalled",app_id:e})},Nr=e=>vo(e,{by_user:!0}),Ur=e=>{let t=nt(e);return t?(Pe.delete(e),(R==null?void 0:R.app_id)===e||q.includes(e)||(_e[e]=0,Q(e,{status:ue.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),vt(e),Re(),pe("restore",e)),!0):!1},Vr=e=>{if(ue.has(e))return;if(ue.add(e),pe("pause app",e),(R==null?void 0:R.app_id)===e&&!R.forced){R.handle.cancel();return}let t=C.getState().downloads[e];q.includes(e)&&t&&Q(e,{status:"paused",progress:0,version:t.version})},Br=e=>{if(!ue.delete(e))return;pe("resume app",e);let t=C.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!q.includes(e)&&nt(e)&&(_e[e]=0,vt(e)),q.includes(e)&&t&&Q(e,{status:"queued",progress:0,version:t.version}),Re()},qr=e=>{let{pause_reasons:t}=C.getState();t.includes(e)||(C.setState({pause_reasons:[...t,e]}),pe("pause",e),t.length===0&&Ee({type:"pause_change",paused:!0,reasons:[e]}),R&&!R.forced&&R.handle.cancel())},$r=e=>{let{pause_reasons:t}=C.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);C.setState({pause_reasons:n}),pe("resume",e),n.length===0&&Ee({type:"pause_change",paused:!1,reasons:n}),Re()},Mo=e=>C.getState().updates[e],zr=async e=>{var n,o;let t=Mo(e);St.add(e);try{let r=await Mt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=nt(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}}}),pe("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{St.delete(e)}},Wr=()=>Object.values(C.getState().catalog).map(e=>({...e,installed:!!I(e.app_id),removed_by_user:Pe.has(e.app_id)})),nt=e=>C.getState().catalog[e],Mt=async e=>{let t=nt(e);if(!t)return;if(ue.delete(e),Pe.delete(e),await jt(t))return I(e);let n=I(e);if(bo(e)&&!St.has(e)&&n&&await Ae(n))return n;let o=new Promise(r=>{var i;((i=Fe[e])!=null?i:Fe[e]=[]).push(r)});return(R==null?void 0:R.app_id)===e?R.forced=!0:(_e[e]=0,vt(e,{front:!0}),R&&!R.forced?R.handle.cancel():Re(e)),o};import{Fragment as Po,jsx as W,jsxs as rt}from"react/jsx-runtime";var en=e=>(e!=null?e:"").replace(/\?[^#]*/,""),Eo=0,Xr=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},Zr=on.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:p})=>{var st,sn;let g=de(null),w=de(!1),u=z(Z,f=>f.instances[e]),h=u==null?void 0:u.app.app_id,P=u==null?void 0:u.app.manifest_url,v=u==null?void 0:u.context,M=u==null?void 0:u.url_params,b=z(V,f=>{var _;return((_=f.active)==null?void 0:_.owner)===e?f.active:null}),[A,j]=De(()=>h?I(h):null),[G,te]=De(!1),[ne,oe]=De(0),[re,m]=De(0),[y,x]=De(!1),O=de(null),$=f=>{O.current&&clearTimeout(O.current),O.current=setTimeout(()=>{O.current=null,x(!0)},f)};ee(()=>()=>{O.current&&clearTimeout(O.current)},[]),ee(()=>{if(!h||!t&&A)return;let f=!0;return te(!1),(async()=>{let _=I(h),K=_?await Ae(_):!1;if(!f||(j(K?le=>!le||le.version!==_.version||le.permissions.join(",")!==_.permissions.join(",")?_:le:null),__DEV__&&Date.now()-Eo>1e4&&(Eo=Date.now(),await Zt()),!f))return;let ve=await Mt(h),Ce=ve!==void 0?ve:P?await go(h,P):I(h);if(f){if(!Ce){te(!0);return}j(le=>le!=null?le:Ce)}})(),()=>{f=!1}},[t,h,P,ne]),ee(()=>mo(e,f=>g.current?(g.current.postMessage(f),!0):!1),[e]);let L=z(C,f=>{let _=h?f.downloads[h]:void 0;return(_==null?void 0:_.status)==="installed"?_.version:void 0});ee(()=>{if(t||!h||!A)return;let f=I(h);if(!f||f.version===A.version)return;let _=!0;return Ae(f).then(K=>{!_||!K||(se(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",A.version,"\u2192",f.version),j(f))}),()=>{_=!1}},[t,h,L,A==null?void 0:A.version]);let J=z(C,f=>{var _;return h&&(_=f.apply_ticks[h])!=null?_:0});ee(()=>{if(!J||!h)return;let f=I(h);if(!f||f.version===(A==null?void 0:A.version))return;let _=!0;return Ae(f).then(K=>{!_||!K||(se(`webview:${e}`,"c\u1EADp nh\u1EADt",A==null?void 0:A.version,"\u2192",f.version),x(!1),j(f))}),()=>{_=!1}},[J]),ee(()=>{var K;let f=(K=F().keep_alive)==null?void 0:K.idle_close_ms;if(t||!f||f<=0)return;let _=setTimeout(()=>{At(e)},f);return()=>clearTimeout(_)},[t,e]),ee(()=>{r>0&&(te(!1),x(!1),m(f=>f+1),oe(f=>f+1))},[r]);let be=de(t);ee(()=>{var f;be.current!==t&&(be.current=t,w.current&&((f=g.current)==null||f.injectJavaScript(eo(t?"resumed":"paused"))))},[t]);let me=`${(st=A==null?void 0:A.version)!=null?st:"none"}:${(sn=A==null?void 0:A.permissions.join(","))!=null?sn:""}:${re}`,X=xt(()=>JSON.stringify([v!=null?v:{},M!=null?M:{}]),[v,M]),Se=xt(()=>{var f;return io(M!=null?M:{},(f=A==null?void 0:A.permissions)!=null?f:[])},[X,A==null?void 0:A.permissions]),fe=xt(()=>oo(v!=null?v:{},Se)+Zn()+(Kr.OS==="android"?Qn():"")+(F().debug?Xn():""),[Se]),he=de(null),E=de(null);ee(()=>{var _,K,ve;if(!A)return;if(E.current!==me){E.current=me,he.current=X;return}if(he.current===X)return;let f=((K=JSON.parse((_=he.current)!=null?_:"[]")[0])!=null?K:{}).org_id;if(he.current=X,f===(v==null?void 0:v.org_id)&&w.current){x(!1),$(1500),(ve=g.current)==null||ve.injectJavaScript(to(v!=null?v:{},Se));return}x(!1),m(Ce=>Ce+1)},[X,A,me]),ee(()=>(t||(ye(e),xe(e),Le(e)),()=>{ye(e),xe(e),Le(e)}),[t,e,me,r]),ee(()=>{let f=xo.addEventListener("change",_=>{_==="background"&&!Ln()&&ye(e),_==="background"&&!Un()&&xe(e)});return()=>f.remove()},[e]);let Oe=tn(async f=>{var K,ve,Ce,le,Et;let _=Jn(f.nativeEvent.data);if(!_){if(h&&(c!=null&&c.onWebEvent))try{Promise.resolve(c.onWebEvent(f.nativeEvent.data,{app_id:h,instance_id:e})).catch(D=>{console.warn("[miniapp] onWebEvent l\u1ED7i",h,D)})}catch(D){console.warn("[miniapp] onWebEvent l\u1ED7i",h,D)}return}if(_.method==="log"){let{level:D,text:N}=_;se(`web:${e}`,D!=null?D:"log",N!=null?N:"");return}if(_.method==="pong"){O.current||x(!0);return}if(_.method==="touchAtTop"){i.emit(!!_.at_top);return}if(_.method==="contextApplied"){O.current&&clearTimeout(O.current),O.current=null,x(!0);return}if(_.method==="ready"){w.current=!0,x(!0);let D=(K=Z.getState().instances[e])==null?void 0:K.context;D&&((ve=g.current)==null||ve.injectJavaScript(Vt(D)));return}try{let D=await ao(_,{getHostData:()=>{var N,ie;return(ie=(N=Z.getState().instances[e])==null?void 0:N.host_data)!=null?ie:{}},getPermissions:()=>{var N,ie;return h?(ie=(N=I(h))==null?void 0:N.permissions)!=null?ie:[]:[]},getContext:()=>{var N,ie;return(ie=(N=Z.getState().instances[e])==null?void 0:N.context)!=null?ie:{}},is_dark:o,close:et,app_id:h!=null?h:"",instance_id:e,options:c,emit:(N,ie)=>{var an;(an=g.current)==null||an.injectJavaScript(Gn(N,ie))},playBeep:()=>{var N;(N=g.current)==null||N.injectJavaScript(so())},isActive:()=>Z.getState().active_key===e&&xo.currentState!=="background"});_.id&&((Ce=g.current)==null||Ce.injectJavaScript(Kn(_.id,D)))}catch(D){if(!_.id)return;let N=D==null?void 0:D.code,ie=D instanceof d?D:new d(typeof N=="string"?N:"HOST_ERROR",String((le=D==null?void 0:D.message)!=null?le:D));(Et=g.current)==null||Et.injectJavaScript(Yn(_.id,ie))}},[e,o,h,i,c]),it=tn(()=>{te(!1),m(f=>f+1),oe(f=>f+1)},[]);return rt(nn,{style:[rn.absoluteFill,l&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&ce.behind],pointerEvents:t?"auto":"none",children:[(b==null?void 0:b.layout)===we.top&&W(Yt,{scanner:b}),A?W(Gr,{ref:g,source:{uri:A.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?$t():A.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:fe,onMessage:Oe,bounces:!1,overScrollMode:"never",onLoadStart:f=>{ye(e),xe(e),Le(e),se(`webview:${e}`,"load start",en(f.nativeEvent.url)),w.current=!1,x(!1)},onError:f=>{ye(e),xe(e),Le(e),se(`webview:${e}`,"load error",en(f.nativeEvent.url),f.nativeEvent.description),te(!0),x(!1)},onLoadEnd:f=>{let _=f.nativeEvent.url;se(`webview:${e}`,"load end",en(_)),h&&(p==null||p({app_id:h,instance_id:e,url:_})),$(1500)},onContentProcessDidTerminate:()=>{ye(e),xe(e),Le(e),w.current=!1,x(!1),m(f=>f+1)},onRenderProcessGone:()=>(ye(e),xe(e),Le(e),w.current=!1,x(!1),m(f=>f+1),!0),style:ce.webview},me):null,(b==null?void 0:b.layout)===we.full&&W(Yt,{scanner:b}),u&&W(ei,{visible:!A||!y,interactive:G,children:W(Qr,{splash:a,app:u.app,is_dark:o,error:G,has_bundle:!!A,retry:it})})]})}),Qr=on.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,c=Xt(t.app_id),l=o?"error":!r&&(c==null?void 0:c.status)==="downloading"?"downloading":"loading";return W(a,{app:t,is_dark:n,status:l,progress:l==="downloading"?c==null?void 0:c.progress:void 0,retry:i})}),ei=({visible:e,interactive:t,children:n})=>{let o=de(new Qt.Value(e?1:0)).current,[r,i]=De(e);return ee(()=>{if(e){i(!0),o.setValue(1);return}let a=Qt.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:c})=>{c&&i(!1)}),()=>a.stop()},[e,o]),r?W(Qt.View,{style:[rn.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},Oo=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return rt(nn,{style:[ce.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[W(nn,{style:[ce.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?W(Jr,{source:{uri:e.icon},style:ce.splash_icon_image}):W(ot,{style:ce.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),W(ot,{style:[ce.splash_name,{color:i}],children:e.name}),n==="error"?rt(Po,{children:[W(ot,{style:ce.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),W(Yr,{activeOpacity:.7,style:[ce.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:W(ot,{style:[ce.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):rt(Po,{children:[W(jr,{style:ce.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&rt(ot,{style:ce.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},Ro=(e,t)=>{let n=de(t),o=de(!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.`))},ti=({container:e,splash:t=Oo,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:c})=>{Ro("container",e),Ro("splash",t);let l=e,s=z(Z,b=>b.active_key),p=de(s);s&&(p.current=s);let g=z(Z,b=>Object.keys(b.instances).join("|")),w=z(Z,b=>{var A;return b.active_key?(A=b.instances[b.active_key])==null?void 0:A.app.name:void 0}),u=xt(()=>g?g.split("|"):[],[g]),[h,P]=De({}),v=de(Xr()).current;ee(()=>{if(!s||!r)return;let b=Hr.addEventListener("hardwareBackPress",()=>(et(),!0));return()=>b.remove()},[s,r]);let M=tn(()=>{let b=Z.getState().active_key;b&&P(A=>({...A,[b]:(A[b]||0)+1}))},[]);return u.length?W(l,{visible:!!s,title:w!=null?w:"",is_dark:n,close:et,reload:M,subscribeWebAtTop:v.subscribe,children:u.map(b=>W(Zr,{instance_key:b,is_active:s===b,is_front:(s!=null?s:p.current)===b,is_dark:n,reload_tick:h[b]||0,web_at_top:v,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:c},b))}):null},ce=rn.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"}}),ni=on.memo(ti);export{H as CodeType,Oo as DefaultMiniAppSplash,Rt as MINIAPP_PLATFORM_URL,ni as MiniAppHost,d as MiniAppHostError,Ue as ScannerEndReason,Lt as ScannerEvent,we as ScannerLayout,je as ScannerMethod,et as closeMiniApp,Co as configureMiniApp,ko as createMmkvStorage,pn as createReactNativeBiometrics,To as createRnfsFileSystem,Mt as ensureMiniApp,I as getLocalMiniApp,Wr as getMiniAppCatalog,nt as getMiniAppCatalogEntry,Ir as getMiniAppStatuses,Mo as getMiniAppUpdate,ur as installBundledMiniApp,Lr as onMiniAppEvent,Mr as openMiniApp,Vr as pauseMiniApp,qr as pauseMiniAppDownloads,xr as preloadMiniApp,ye as releaseSpeechFor,Ur as restoreMiniApp,Br as resumeMiniApp,$r as resumeMiniAppDownloads,gr as sendEventToWeb,Zt as syncMiniAppCatalog,Nr as uninstallMiniApp,zr as updateMiniApp,En as uploadToUrl,Xt as useMiniAppDownload,kr as useMiniAppDownloadsPaused};
|
package/docs/NATIVE_APIS.md
CHANGED
|
@@ -258,7 +258,7 @@ Web chờ tối đa khoảng 2 phút + `timeout` (gồm thời gian người dù
|
|
|
258
258
|
|
|
259
259
|
### Quét mã QR / barcode
|
|
260
260
|
|
|
261
|
-
Cần `@retion-miniapp/react-native` và `@retion-miniapp/sdk` từ **0.11.0**.
|
|
261
|
+
Cần `@retion-miniapp/react-native` và `@retion-miniapp/sdk` từ **0.11.0**; `hint`, `layout`, zoom và quét từ ảnh cần **0.12.0**.
|
|
262
262
|
|
|
263
263
|
**Luồng:** web gọi API → host giữ phiên, xin quyền camera → host hiện camera → mã trả về web. App chủ không phải viết handler hay UI.
|
|
264
264
|
|
|
@@ -285,9 +285,10 @@ 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`: 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. Camera mở đến khi người dùng bấm Đóng hoặc web gọi `stopScanner()`.
|
|
289
|
-
- Camera có nút Đóng, đèn pin (nếu máy có) và nháy khung xanh khi nhận mã.
|
|
290
|
-
-
|
|
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()`.
|
|
289
|
+
- 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
|
+
- Quét từ ảnh: có sẵn, web không phải gọi gì. Kết quả trả như quét camera và không áp dụng cooldown; `startScanner` nhận mọi mã trong ảnh, `scanCode` lấy mã đầu tiên. Ảnh không có mã thì báo trên camera và camera vẫn mở. Nút Back Android đóng camera trước, chưa đóng mini app.
|
|
291
|
+
- Mỗi lần nhận mã: rung nhẹ qua `bridge.haptic` với `impactLight` (app chưa truyền thì không rung) và kêu tít, không cần cấu hình. Tiếng tít theo âm lượng media; iOS có thể tắt tiếng khi bật công tắc im lặng.
|
|
291
292
|
- `scanCode` chờ tối đa 10 phút phía web. Hết thời gian chờ không tự đóng camera; gọi `stopScanner()` nếu không còn cần.
|
|
292
293
|
|
|
293
294
|
| Hằng | Giá trị |
|
|
@@ -299,6 +300,8 @@ await stopScanner();
|
|
|
299
300
|
| Tuỳ chọn | Mặc định | Ý nghĩa |
|
|
300
301
|
| --- | --- | --- |
|
|
301
302
|
| `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 |
|
|
303
|
+
| `layout` | `ScannerLayout.top` | Chỉ `startScanner`: `top` hoặc `full` |
|
|
304
|
+
| `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 |
|
|
302
305
|
| `cooldown_ms` | `1500` | Chỉ `startScanner`, 0–60000 ms: thời gian trước khi nhận lại **cùng một mã**. Mã khác nhận ngay. Giữ nguyên mã trước camera thì được tính thêm một lần sau mỗi cooldown |
|
|
303
306
|
|
|
304
307
|
| Mã lỗi | Ý nghĩa |
|
|
@@ -310,7 +313,7 @@ await stopScanner();
|
|
|
310
313
|
| `INVALID_PARAMS` | `types` hoặc `cooldown_ms` không hợp lệ |
|
|
311
314
|
| `HOST_ERROR` | Lỗi camera trong lúc `scanCode` |
|
|
312
315
|
|
|
313
|
-
**Native:** package dùng `react-native-vision-camera` 4.7.3. Plugin Expo tự thêm quyền `CAMERA` và nhúng sẵn model quét mã Android (khoảng 2,4 MB). Mô tả quyền iOS tuỳ chỉnh qua `cameraPermission`. React Native thuần cần thêm `VisionCamera_enableCodeScanner=true` vào `android/gradle.properties`, quyền `android.permission.CAMERA` vào manifest, `NSCameraUsageDescription` vào `Info.plist`, và bổ sung `react-native-vision-camera` vào `react-native.config.js` nếu CLI chỉ dò dependency trực tiếp. Tính năng này phải build lại native, không cập nhật được qua OTA.
|
|
316
|
+
**Native:** package dùng `react-native-vision-camera` 4.7.3 và `@react-native-ml-kit/barcode-scanning` 2.0.0 (đọc mã từ ảnh; iOS kéo thêm pod `GoogleMLKit`, cần iOS 15.5+ và có thể không build được cho simulator trên Apple Silicon). Nếu autolinking chỉ dò dependency trực tiếp, thêm cả hai vào `package.json` của app hoặc `react-native.config.js`. Plugin Expo tự thêm quyền `CAMERA` và nhúng sẵn model quét mã Android (khoảng 2,4 MB). Mô tả quyền iOS tuỳ chỉnh qua `cameraPermission`. React Native thuần cần thêm `VisionCamera_enableCodeScanner=true` vào `android/gradle.properties`, quyền `android.permission.CAMERA` vào manifest, `NSCameraUsageDescription` vào `Info.plist`, và bổ sung `react-native-vision-camera` vào `react-native.config.js` nếu CLI chỉ dò dependency trực tiếp. Tính năng này phải build lại native, không cập nhật được qua OTA.
|
|
314
317
|
|
|
315
318
|
### Chức năng native: thanh toán, in, mở màn hình
|
|
316
319
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retion-miniapp/react-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "React Native host for Retion Mini Apps with built-in biometric authentication",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -90,6 +90,7 @@
|
|
|
90
90
|
"dependencies": {
|
|
91
91
|
"@react-native-community/geolocation": "3.4.0",
|
|
92
92
|
"@react-native-documents/picker": "12.0.2",
|
|
93
|
+
"@react-native-ml-kit/barcode-scanning": "2.0.0",
|
|
93
94
|
"expo-speech-recognition": "1.1.1",
|
|
94
95
|
"react-native-biometrics": "3.0.1",
|
|
95
96
|
"react-native-compressor": "1.13.0",
|