@retion-miniapp/react-native 0.12.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +9 -9
- package/dist/index.mjs +9 -9
- package/docs/MINIAPP_README.md +0 -1
- package/docs/NATIVE_APIS.md +23 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -246,8 +246,10 @@ type MiniAppHapticType = 'selection' | 'impactLight' | 'impactMedium' | 'impactH
|
|
|
246
246
|
interface MiniAppBridgeOptions {
|
|
247
247
|
/** Optional override. Omit to use the built-in biometric implementation. */
|
|
248
248
|
biometrics?: MiniAppBiometrics;
|
|
249
|
-
/**
|
|
250
|
-
showToast?: (message: string
|
|
249
|
+
/** Thay toast có sẵn của package khi web gọi showToast(). Thường không cần truyền. */
|
|
250
|
+
showToast?: (message: string, options: {
|
|
251
|
+
type: 'info' | 'success' | 'error';
|
|
252
|
+
}) => void;
|
|
251
253
|
/** Web gọi haptic(type) (lệnh 1 chiều). Không truyền → bỏ qua. */
|
|
252
254
|
haptic?: (type: MiniAppHapticType) => void;
|
|
253
255
|
/** Web gọi openWebview(url) / openLink(url). Mặc định Linking.openURL. */
|
|
@@ -638,6 +640,13 @@ interface SpeechOptions {
|
|
|
638
640
|
/** Đóng/ẩn mini app: huỷ, không lấy kết quả cuối. Giữ khoá đến native end để tránh event phiên cũ sang phiên mới. */
|
|
639
641
|
declare const releaseSpeechFor: (owner: string) => void;
|
|
640
642
|
|
|
643
|
+
declare const ToastType: {
|
|
644
|
+
readonly info: "info";
|
|
645
|
+
readonly success: "success";
|
|
646
|
+
readonly error: "error";
|
|
647
|
+
};
|
|
648
|
+
type ToastType = (typeof ToastType)[keyof typeof ToastType];
|
|
649
|
+
|
|
641
650
|
/** Giá trị trùng với react-native-vision-camera → truyền thẳng xuống native, không phải map. */
|
|
642
651
|
declare const CODE_TYPES: {
|
|
643
652
|
readonly qr: "qr";
|
|
@@ -759,4 +768,4 @@ interface UploadCapabilities {
|
|
|
759
768
|
/** 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. */
|
|
760
769
|
declare const uploadToUrl: MiniAppUploader;
|
|
761
770
|
|
|
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 };
|
|
771
|
+
export { CodeType, DefaultMiniAppSplash, type LocationOptions, type LocationResult, MINIAPP_PLATFORM_URL, type MiniAppBiometricAvailability, type MiniAppBiometricRequest, type MiniAppBiometricResult, type MiniAppBiometrics, type MiniAppBiometryType, type MiniAppBridgeOptions, type MiniAppCatalogEntry, type MiniAppCatalogItem, type MiniAppChannel, type MiniAppConfig, type MiniAppContainerProps, type MiniAppContext, type MiniAppDownloadState, type MiniAppDownloadStatus, type MiniAppDownloadTask, type MiniAppEvent, type MiniAppFileSystem, type MiniAppHandlerContext, type MiniAppHapticType, _default as MiniAppHost, type MiniAppHostData, BridgeError as MiniAppHostError, type MiniAppHostProps, type MiniAppKeepAlive, type MiniAppLaunch, type MiniAppLocalBundle, type MiniAppManifest, type MiniAppNativeHandlers, type MiniAppPaymentRequest, type MiniAppPaymentResult, type MiniAppPermission, type MiniAppPickedFile, type MiniAppSplashProps, type MiniAppStorage, type MiniAppSyncResult, type MiniAppUpdate, type MiniAppUploadCaller, type MiniAppUploadOptions, type MiniAppUploadProcessOptions, type MiniAppUploadProcessor, type MiniAppUploadRequest, type MiniAppUploadSource, type MiniAppUploadSourceRequest, type MiniAppUploadTarget, type MiniAppUploader, type MiniAppUrlUploadTarget, type OpenMiniAppArgs, type ReactNativeBiometricsLike, ScannerEndReason, ScannerEvent, ScannerLayout, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, ToastType, type UploadCapabilities, type UploadFileType, type UploadFilesResult, type UploadedFile, closeMiniApp, configureMiniApp, createMmkvStorage, createReactNativeBiometrics, createRnfsFileSystem, ensureMiniApp, getLocalMiniApp, getMiniAppCatalog, getMiniAppCatalogEntry, getMiniAppStatuses, getMiniAppUpdate, installBundledMiniApp, onMiniAppEvent, openMiniApp, pauseMiniApp, pauseMiniAppDownloads, preloadMiniApp, releaseSpeechFor, restoreMiniApp, resumeMiniApp, resumeMiniAppDownloads, sendEventToWeb, syncMiniAppCatalog, uninstallMiniApp, updateMiniApp, uploadToUrl, useMiniAppDownload, useMiniAppDownloadsPaused };
|
package/dist/index.d.ts
CHANGED
|
@@ -246,8 +246,10 @@ type MiniAppHapticType = 'selection' | 'impactLight' | 'impactMedium' | 'impactH
|
|
|
246
246
|
interface MiniAppBridgeOptions {
|
|
247
247
|
/** Optional override. Omit to use the built-in biometric implementation. */
|
|
248
248
|
biometrics?: MiniAppBiometrics;
|
|
249
|
-
/**
|
|
250
|
-
showToast?: (message: string
|
|
249
|
+
/** Thay toast có sẵn của package khi web gọi showToast(). Thường không cần truyền. */
|
|
250
|
+
showToast?: (message: string, options: {
|
|
251
|
+
type: 'info' | 'success' | 'error';
|
|
252
|
+
}) => void;
|
|
251
253
|
/** Web gọi haptic(type) (lệnh 1 chiều). Không truyền → bỏ qua. */
|
|
252
254
|
haptic?: (type: MiniAppHapticType) => void;
|
|
253
255
|
/** Web gọi openWebview(url) / openLink(url). Mặc định Linking.openURL. */
|
|
@@ -638,6 +640,13 @@ interface SpeechOptions {
|
|
|
638
640
|
/** Đóng/ẩn mini app: huỷ, không lấy kết quả cuối. Giữ khoá đến native end để tránh event phiên cũ sang phiên mới. */
|
|
639
641
|
declare const releaseSpeechFor: (owner: string) => void;
|
|
640
642
|
|
|
643
|
+
declare const ToastType: {
|
|
644
|
+
readonly info: "info";
|
|
645
|
+
readonly success: "success";
|
|
646
|
+
readonly error: "error";
|
|
647
|
+
};
|
|
648
|
+
type ToastType = (typeof ToastType)[keyof typeof ToastType];
|
|
649
|
+
|
|
641
650
|
/** Giá trị trùng với react-native-vision-camera → truyền thẳng xuống native, không phải map. */
|
|
642
651
|
declare const CODE_TYPES: {
|
|
643
652
|
readonly qr: "qr";
|
|
@@ -759,4 +768,4 @@ interface UploadCapabilities {
|
|
|
759
768
|
/** 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. */
|
|
760
769
|
declare const uploadToUrl: MiniAppUploader;
|
|
761
770
|
|
|
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 };
|
|
771
|
+
export { CodeType, DefaultMiniAppSplash, type LocationOptions, type LocationResult, MINIAPP_PLATFORM_URL, type MiniAppBiometricAvailability, type MiniAppBiometricRequest, type MiniAppBiometricResult, type MiniAppBiometrics, type MiniAppBiometryType, type MiniAppBridgeOptions, type MiniAppCatalogEntry, type MiniAppCatalogItem, type MiniAppChannel, type MiniAppConfig, type MiniAppContainerProps, type MiniAppContext, type MiniAppDownloadState, type MiniAppDownloadStatus, type MiniAppDownloadTask, type MiniAppEvent, type MiniAppFileSystem, type MiniAppHandlerContext, type MiniAppHapticType, _default as MiniAppHost, type MiniAppHostData, BridgeError as MiniAppHostError, type MiniAppHostProps, type MiniAppKeepAlive, type MiniAppLaunch, type MiniAppLocalBundle, type MiniAppManifest, type MiniAppNativeHandlers, type MiniAppPaymentRequest, type MiniAppPaymentResult, type MiniAppPermission, type MiniAppPickedFile, type MiniAppSplashProps, type MiniAppStorage, type MiniAppSyncResult, type MiniAppUpdate, type MiniAppUploadCaller, type MiniAppUploadOptions, type MiniAppUploadProcessOptions, type MiniAppUploadProcessor, type MiniAppUploadRequest, type MiniAppUploadSource, type MiniAppUploadSourceRequest, type MiniAppUploadTarget, type MiniAppUploader, type MiniAppUrlUploadTarget, type OpenMiniAppArgs, type ReactNativeBiometricsLike, ScannerEndReason, ScannerEvent, ScannerLayout, ScannerMethod, type ScannerOptions, type ScannerResult, type SpeechOptions, ToastType, type UploadCapabilities, type UploadFileType, type UploadFilesResult, type UploadedFile, closeMiniApp, configureMiniApp, createMmkvStorage, createReactNativeBiometrics, createRnfsFileSystem, ensureMiniApp, getLocalMiniApp, getMiniAppCatalog, getMiniAppCatalogEntry, getMiniAppStatuses, getMiniAppUpdate, installBundledMiniApp, onMiniAppEvent, openMiniApp, pauseMiniApp, pauseMiniAppDownloads, preloadMiniApp, releaseSpeechFor, restoreMiniApp, resumeMiniApp, resumeMiniAppDownloads, sendEventToWeb, syncMiniAppCatalog, uninstallMiniApp, updateMiniApp, uploadToUrl, useMiniAppDownload, useMiniAppDownloadsPaused };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Fo=Object.create;var st=Object.defineProperty;var Do=Object.getOwnPropertyDescriptor;var No=Object.getOwnPropertyNames;var Uo=Object.getPrototypeOf,Vo=Object.prototype.hasOwnProperty;var Bo=(e,t)=>{for(var n in t)st(e,n,{get:t[n],enumerable:!0})},nn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of No(t))!Vo.call(e,r)&&r!==n&&st(e,r,{get:()=>t[r],enumerable:!(o=Do(t,r))||o.enumerable});return e};var ie=(e,t,n)=>(n=e!=null?Fo(Uo(e)):{},nn(t||!e||!e.__esModule?st(n,"default",{value:e,enumerable:!0}):n,e)),qo=e=>nn(st({},"__esModule",{value:!0}),e);var Dr={};Bo(Dr,{CodeType:()=>G,DefaultMiniAppSplash:()=>en,MINIAPP_PLATFORM_URL:()=>at,MiniAppHost:()=>Io,MiniAppHostError:()=>u,ScannerEndReason:()=>De,ScannerEvent:()=>gt,ScannerLayout:()=>he,ScannerMethod:()=>Be,closeMiniApp:()=>ze,configureMiniApp:()=>rn,createMmkvStorage:()=>cn,createReactNativeBiometrics:()=>Rt,createRnfsFileSystem:()=>an,ensureMiniApp:()=>rt,getLocalMiniApp:()=>N,getMiniAppCatalog:()=>Oo,getMiniAppCatalogEntry:()=>We,getMiniAppStatuses:()=>bo,getMiniAppUpdate:()=>Zt,installBundledMiniApp:()=>so,onMiniAppEvent:()=>_o,openMiniApp:()=>mo,pauseMiniApp:()=>xo,pauseMiniAppDownloads:()=>Po,preloadMiniApp:()=>fo,releaseSpeechFor:()=>fe,restoreMiniApp:()=>Mo,resumeMiniApp:()=>Eo,resumeMiniAppDownloads:()=>Ro,sendEventToWeb:()=>lo,syncMiniAppCatalog:()=>Et,uninstallMiniApp:()=>vo,updateMiniApp:()=>Co,uploadToUrl:()=>kt,useMiniAppDownload:()=>Mt,useMiniAppDownloadsPaused:()=>Ao});module.exports=qo(Dr);var at="https://retion-miniapp-platform.vercel.app",Le=null,on=new Set,rn=e=>{Le=e,on.forEach(t=>t())},V=()=>{if(!Le)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Le},sn=e=>{on.add(e),Le&&e()},se=(...e)=>{Le!=null&&Le.debug&&console.log("[miniapp]",...e)};var an=(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:c}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:l,contentLength:a})=>r==null?void 0:r(l,a)});return{promise:c.then(({statusCode:l})=>({status:l})),cancel:()=>e.stopDownload(i)}}}),cn=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var S=ie(require("react")),O=require("react-native"),Lo=ie(require("react-native-webview"));var Xe=require("react-native");var Rt=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),ct,Ct=()=>(ct||(ct=import("react-native-biometrics").then(({default:e})=>Rt(new e({allowDeviceCredentials:!1}))).catch(e=>{throw ct=void 0,new u("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),ct);var me=require("react-native");var ln=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,c,l]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let a=t[i];if(a!==void 0&&(typeof a!="number"||!Number.isFinite(a)||a<c||a>l))throw new u("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${c}\u2013${l} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},pn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(a,s)=>{r||(r=!0,clearTimeout(c),a?o(a):n(s))},c=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=()=>r?!1:t()?!0:(i(new u("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!l())return;let a;try{a=(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(me.Platform.OS==="android"){let s=me.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,d=me.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,g=await me.PermissionsAndroid.check(s);if(!l())return;let A=g||await me.PermissionsAndroid.check(d);if(!l())return;if(!g&&!A){let p=await me.PermissionsAndroid.requestMultiple([s,d]);if(!l())return;if(p[s]!==me.PermissionsAndroid.RESULTS.GRANTED&&p[d]!==me.PermissionsAndroid.RESULTS.GRANTED)throw new u("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}l()&&a.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(a=>i(a))});var Tt=require("react-native");var Ot=20,un=20,yn=/^[a-z][a-z0-9_-]{0,31}$/,$o=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,zo=["low","medium","high"],xe=e=>!!e&&typeof e=="object"&&!Array.isArray(e),$=e=>new u("INVALID_PARAMS",e),Ge=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,dn=(e,t)=>{if(e===void 0)return{};if(!xe(e)||Object.keys(e).length>un||Object.values(e).some(n=>typeof n!="string"))throw $(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${un} key)`);return e},wn=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"||!yn.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(c=>typeof c!="string"||!$o.test(c))))throw $("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!Ge(t.max_count,1,Ot))throw $(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Ot}`);if(t.max_size!==void 0&&!Ge(t.max_size,1,Number.MAX_SAFE_INTEGER))throw $("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!Ge(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(c=>c.toLowerCase()),max_count:(r=t.max_count)!=null?r:1,max_size:t.max_size,process:Wo(t.process),target:jo(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},Wo=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&&!Ge(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&&!Ge(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&&!zo.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},jo=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"||!yn.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 c of["field_name","url_field"])if(e[c]!==void 0&&(typeof e[c]!="string"||!e[c]))throw $(`upload.${c} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:dn(e.headers,"upload.headers"),form_data:dn(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},An=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},Ho=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=An(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},Jo=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"},He,Ko=()=>(He!=null||(He=import("react-native-image-picker").catch(e=>{throw He=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)}`)})),He),gn=e=>async({accept:t,max_count:n,process:o})=>{var a,s,d,g,A,p,y,L,E;let r=await Ko(),i=Jo(t),c={mediaType:i==="image"?"photo":i,maxWidth:(a=o.image)==null?void 0:a.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(g=(d=o.image)==null?void 0:d.quality)!=null?g:.8,videoQuality:(p=(A=o.video)==null?void 0:A.quality)!=null?p:"medium",durationLimit:(y=o.video)==null?void 0:y.max_duration,assetRepresentationMode:"compatible"},l=e==="camera"?await r.launchCamera({...c,saveToPhotos:!1}):await r.launchImageLibrary({...c,selectionLimit:n});if(l.didCancel)return[];if(l.errorCode){let R=l.errorCode==="permission"?"PERMISSION_DENIED":l.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new u(R,(L=l.errorMessage)!=null?L:l.errorCode)}return((E=l.assets)!=null?E:[]).filter(R=>R.uri).map((R,x)=>{var _,J,Z;return{uri:R.uri,name:(_=R.fileName)!=null?_:`file_${x+1}`,mime_type:(J=R.type)!=null?J:"application/octet-stream",size:R.fileSize,width:R.width,height:R.height,duration:R.duration,processed:!((Z=R.type)!=null&&Z.startsWith("video/"))||Tt.Platform.OS==="ios"}})},Go={"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"},Xo=e=>async({accept:t,max_count:n})=>{var i,c,l,a;let o=t.map(s=>{var d;return(d=Go[s])!=null?d: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 d=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(p=>p.uri&&!p.error).map((p,y)=>{var L,E,R;return{uri:p.uri,name:(L=p.name)!=null?L:`file_${y+1}`,mime_type:(E=p.type)!=null?E:"application/octet-stream",size:(R=p.size)!=null?R:void 0}});if(Tt.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"}),A=new Map(g.map(p=>[p.sourceUri,p.status==="success"?p.localUri:void 0]));return d.map(p=>{var y;return{...p,uri:(y=A.get(p.uri))!=null?y:p.uri}})}catch(s){let d=s==null?void 0:s.code;if(d===((c=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?c:"OPERATION_CANCELED"))return[];throw d===((a=(l=e.errorCodes)==null?void 0:l.IN_PROGRESS)!=null?a:"ASYNC_OP_IN_PROGRESS")?new u("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},Je,Zo=async e=>(Je!=null||(Je=import("@react-native-documents/picker").then(t=>Xo(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)),_n={library:gn("library"),camera:gn("camera"),document:Zo},mn={type:"image",label:"\u1EA2nh",accept:["image/*"]},fn={type:"video",label:"Video",accept:["video/*"]},hn={library:[mn,fn],camera:[mn,fn],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"]}]},Ke,bn=()=>(Ke!=null||(Ke=import("react-native-compressor").catch(()=>(Ke=void 0,null))),Ke),Sn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},Qo=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),er={low:640,medium:1280,high:1920},tr=async(e,{image:t})=>{var o;if(!t||!Qo.has(e.mime_type.toLowerCase()))return e;let n=await bn();if(!n)return e;try{let r=await n.Image.compress(e.uri,{compressionMethod:"manual",maxWidth:t.max_width,maxHeight:t.max_height,quality:(o=t.quality)!=null?o:.8,output:"jpg"});return{...e,uri:r,mime_type:"image/jpeg",name:e.name.replace(/\.[^.]+$/,"")+".jpg",size:await Sn(n,r,e.size),processed:!0}}catch{return e}},nr=async(e,{video:t})=>{var o;let n=await bn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:er[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await Sn(n,r,e.size),processed:!0}}catch{return e}},or={image:tr,video:nr},rr=(e,t)=>t.split(".").reduce((n,o)=>xe(n)?n[o]:void 0,e),kt=({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 c=t;if(o.aborted){i(new u("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let l=new XMLHttpRequest,a=new FormData;Object.entries(c.form_data).forEach(([g,A])=>a.append(g,A)),a.append(c.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>l.abort();o.addEventListener("abort",s);let d=g=>{o.removeEventListener("abort",s),g()};l.open("POST",c.url),Object.entries(c.headers).forEach(([g,A])=>l.setRequestHeader(g,A)),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 A=rr(g,c.url_field);if(typeof A!="string"||!A){i(new u("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${c.url_field}"`));return}r({url:A,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(a)}),vn=e=>{var o,r;let t={..._n};for(let[i,c]of Object.entries((o=e==null?void 0:e.sources)!=null?o:{}))c?t[i]=c:delete t[i];let n={url:kt};for(let[i,c]of Object.entries((r=e==null?void 0:e.targets)!=null?r:{}))i!=="url"&&c&&(n[i]=c);return{sources:t,targets:n}},Mn=e=>{let{sources:t,targets:n}=vn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===_n[i]&&hn[i]).map(i=>[i,hn[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Ot}},pt=new Map,xn=(e,t)=>`${e}:${t}`,ir=0,En=(e,t)=>{var n;typeof t=="string"&&((n=pt.get(xn(e,t)))==null||n.abort())},Ie=e=>{for(let[t,n]of pt)t.startsWith(`${e}:`)&&n.abort()},lt=()=>new u("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),sr=(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)}},Pn=async(e,t)=>{var a;let{sources:n,targets:o}=vn(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 c=new AbortController,l=xn(t.instance_id,(a=t.task_id)!=null?a:`auto-${++ir}`);pt.set(l,c);try{return await ar(e,t,r,i,c.signal)}finally{pt.delete(l)}},ar=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:c,exclusivePick:l=g=>g()},a,s,d)=>{var Q,le,m;let g={app_id:n!=null?n:"",instance_id:t,context:{...(Q=o==null?void 0:o())!=null?Q:{}}},A=(await l(()=>a({accept:e.accept,max_count:e.max_count,process:e.process,caller:g}))).slice(0,e.max_count);if(d.aborted)throw lt();if(!A.length)throw new u("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let p=[],y=A.filter(w=>Ho(w,e.accept)?!0:(p.push({name:w.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${w.mime_type||An(w.name)}`}),!1)),L=y.map(()=>0),E=y.map(w=>{var P;return(P=w.size)!=null?P:0}),R=0,x=0,_=(w=!1)=>{if(!c||!r)return;let P=Date.now();if(!w&&P-x<200)return;x=P;let k=E.reduce((U,Y)=>U+Y,0),W=L.reduce((U,Y)=>U+Y,0);c("upload.progress",{task_id:r,loaded:W,total:k,percent:k?Math.min(100,Math.round(W/k*100)):0,done_count:R,count:y.length})},J=[],Z=0,oe=async()=>{var w,P,k;for(;Z<y.length;){let W=Z++,U=y[W];try{if(d.aborted)throw lt();let Y=U.mime_type.startsWith("image/")?"image":U.mime_type.startsWith("video/")?"video":void 0,Se=Y&&!U.processed?(P=(w=i==null?void 0:i.processors)==null?void 0:w[Y])!=null?P:or[Y]:void 0;if(Se&&(U=await Se(U,e.process),E[W]=(k=U.size)!=null?k:E[W],d.aborted))throw lt();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 ge=(Ae,ve)=>{L[W]=Ae,ve&&(E[W]=ve),_()},ee=await s({file:U,target:e.target,onProgress:ge,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:Oe,...we}=ee;J[W]={url:Oe,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}:{}},L[W]=E[W]}catch(Y){p.push(sr(y[W].name,Y))}finally{R++,_(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,y.length)},oe)),d.aborted)throw lt();let ye=J.filter(w=>!!w);if(!ye.length){let w=p[0];throw new u((le=w==null?void 0:w.code)!=null?le:"UPLOAD_FAILED",(m=w==null?void 0:w.message)!=null?m:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:ye,failed:p}};var Ft=require("react-native");var Fe=require("react-native");var ae,Rn=()=>Fe.Platform.OS==="android"&&!!(ae!=null&&ae.requesting_permission),cr=1500,ut=()=>new Promise(e=>{if(Fe.Platform.OS!=="android"||Fe.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,cr),o=Fe.AppState.addEventListener("change",r=>{r==="active"&&t()})}),Lt=e=>{var t;if(ae===e&&(ae=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Fe.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Cn=async(e,t,n,o=()=>!0)=>{var i,c,l,a,s;if(ae)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:[]};ae=r;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(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 ut(),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",p=>{var y,L;ae!==r||r.cancelled||n(p.isFinal?"speech.final":"speech.partial",{...p,text:(L=(y=p.results[0])==null?void 0:y.transcript)!=null?L:""})}),g.addListener("error",p=>{ae===r&&!r.cancelled&&n("speech.error",{...p,code:p.error})}),g.addListener("end",()=>{ae===r&&(Lt(r),n("speech.end"))})),r.started=!0,g.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(c=t.continuous)!=null?c:!0,interimResults:(l=t.interimResults)!=null?l:!0,addsPunctuation:(a=t.addsPunctuation)!=null?a:!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 Lt(r),d}},On=e=>{let t=ae;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},fe=e=>{let t=ae;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{Lt(t)}};var dt=require("react"),Ve=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)})}},K=(e,t,n=Object.is)=>{let o=(0,dt.useRef)(null),r=()=>{let i=e.getState(),c=o.current;if(c&&c.state===i&&c.selector===t)return c.value;let l=t(i),a=c&&n(c.value,l)?c.value:l;return o.current={state:i,selector:t,value:a},a};return(0,dt.useSyncExternalStore)(e.subscribe,r)};var Tn={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"},G={...Tn,all:Object.values(Tn)},Be={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},gt={result:"scanner.result",end:"scanner.end"},De={user:"user",web:"web",closed:"closed",error:"error"},he={top:"top",full:"full"},Ne={once:"once",continuous:"continuous"},lr=1500,kn=6e4,D,z=Ve({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),Ln=()=>Ft.Platform.OS==="android"&&!!(D!=null&&D.requesting_permission),Dt=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(c=>G.all.includes(c)))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>kn)throw new u("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${kn}`);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},Nt=e=>D!==e?!1:(D=void 0,z.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),In=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 ut(),n(),r!=="granted")throw new u("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera");if(!o.Camera.getAvailableCameraDevices().some(c=>c.position==="back"))throw new u("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await pr();n(),z.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw Nt(e),o}},pr=async()=>{if(Ft.Platform.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},Fn=(e,t,n)=>{var o,r,i;return{owner:e,mode:t,types:(o=n.types)!=null?o:G.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:lr,hint:n.hint,layout:t===Ne.once?he.full:(i=n.layout)!=null?i:he.top,cancelled:!1,requesting_permission:!1,last_seen:new Map}},Dn=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let c=Fn(e,Ne.once,t);c.onHit=o,c.resolve=r,c.reject=i,In(c,n).catch(i)}),Nn=(e,t,n,o=()=>!0,r)=>{let i=Fn(e,Ne.continuous,t);return i.emit=n,i.onHit=r,In(i,o)},mt=(e,t,n)=>{var o,r;if(!z.getState().active){e.cancelled=!0;return}if(Nt(e)){if(e.mode===Ne.once){(o=e.reject)==null||o.call(e,t===De.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,gt.end,n?{reason:t,message:n}:{reason:t})}},Un=e=>{(D==null?void 0:D.owner)===e&&mt(D,De.web)},Ee=e=>{(D==null?void 0:D.owner)===e&&mt(D,De.closed)},Ut=()=>{D&&mt(D,De.user)},Vn=e=>{D&&mt(D,De.error,e)},Vt=(e,t=Date.now(),n=!1)=>{var r,i,c;let o=D;if(!(!o||!z.getState().active))for(let{value:l,type:a}of e){if(!l)continue;let s=o.last_seen.get(l);if(!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if(o.last_seen.set(l,t),(r=o.onHit)==null||r.call(o),o.mode===Ne.once){Nt(o),(i=o.resolve)==null||i.call(o,{value:l,type:a});return}z.setState(d=>({last_value:l,hit_tick:d.hit_tick+1,scan_count:d.scan_count+1,notice:null})),(c=o.emit)==null||c.call(o,gt.result,{value:l,type:a})}}},ur={1:G.code128,2:G.code39,4:G.code93,8:G.codabar,16:G.dataMatrix,32:G.ean13,64:G.ean8,128:G.itf,256:G.qr,512:G.upcA,1024:G.upcE,2048:G.pdf417,4096:G.aztec},dr=2500,It=e=>{z.setState({notice:e}),setTimeout(()=>{z.getState().notice===e&&z.setState({notice:null})},dr)},Bn=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){It("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:c}=await import("@react-native-ml-kit/barcode-scanning"),l=await c.scan(i);if(D!==e)return;let a=l.map(({value:s,format:d})=>({value:s,code_type:ur[d]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:d})=>({value:s,type:d!=null?d:"unknown"}));if(!a.length){It("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}Vt(a,Date.now(),!0)}catch{D===e&&It("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await ut(),e.requesting_permission=!1,D===e&&z.setState({is_picking:!1})}}};var ht=1,u=class extends Error{constructor(n,o){super(o);this.code=n}},qn=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===ht&&typeof t.method=="string"?t:null}catch{return null}},Ze=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,$n=(e,t)=>Ze({id:e,result:t}),zn=(e,t)=>Ze({id:e,error:{code:t.code,message:t.message}}),Wn=(e,t)=>Ze({event:e,data:t}),qt=e=>Ze({event:"context",data:e});var jn=()=>`(function () {
|
|
1
|
+
"use strict";var Go=Object.create;var dt=Object.defineProperty;var Ko=Object.getOwnPropertyDescriptor;var Yo=Object.getOwnPropertyNames;var Xo=Object.getPrototypeOf,Zo=Object.prototype.hasOwnProperty;var Qo=(e,t)=>{for(var n in t)dt(e,n,{get:t[n],enumerable:!0})},pn=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Yo(t))!Zo.call(e,r)&&r!==n&&dt(e,r,{get:()=>t[r],enumerable:!(o=Ko(t,r))||o.enumerable});return e};var le=(e,t,n)=>(n=e!=null?Go(Xo(e)):{},pn(t||!e||!e.__esModule?dt(n,"default",{value:e,enumerable:!0}):n,e)),er=e=>pn(dt({},"__esModule",{value:!0}),e);var Xr={};Qo(Xr,{CodeType:()=>Q,DefaultMiniAppSplash:()=>cn,MINIAPP_PLATFORM_URL:()=>gt,MiniAppHost:()=>Jo,MiniAppHostError:()=>d,ScannerEndReason:()=>$e,ScannerEvent:()=>_t,ScannerLayout:()=>Ae,ScannerMethod:()=>je,ToastType:()=>ue,closeMiniApp:()=>Ge,configureMiniApp:()=>dn,createMmkvStorage:()=>fn,createReactNativeBiometrics:()=>Lt,createRnfsFileSystem:()=>mn,ensureMiniApp:()=>pt,getLocalMiniApp:()=>U,getMiniAppCatalog:()=>zo,getMiniAppCatalogEntry:()=>Ke,getMiniAppStatuses:()=>Lo,getMiniAppUpdate:()=>sn,installBundledMiniApp:()=>yo,onMiniAppEvent:()=>Io,openMiniApp:()=>Ro,pauseMiniApp:()=>Uo,pauseMiniAppDownloads:()=>Bo,preloadMiniApp:()=>Po,releaseSpeechFor:()=>be,restoreMiniApp:()=>No,resumeMiniApp:()=>Vo,resumeMiniAppDownloads:()=>qo,sendEventToWeb:()=>bo,syncMiniAppCatalog:()=>kt,uninstallMiniApp:()=>Do,updateMiniApp:()=>$o,uploadToUrl:()=>Ut,useMiniAppDownload:()=>Ct,useMiniAppDownloadsPaused:()=>ko});module.exports=er(Xr);var gt="https://retion-miniapp-platform.vercel.app",Ve=null,un=new Set,dn=e=>{Ve=e,un.forEach(t=>t())},q=()=>{if(!Ve)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Ve},gn=e=>{un.add(e),Ve&&e()},pe=(...e)=>{Ve!=null&&Ve.debug&&console.log("[miniapp]",...e)};var mn=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:l,contentLength:c})=>r==null?void 0:r(l,c)});return{promise:a.then(({statusCode:l})=>({status:l})),cancel:()=>e.stopDownload(i)}}}),fn=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});var A=le(require("react")),O=require("react-native"),Ho=le(require("react-native-webview"));var ot=require("react-native");var Lt=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),mt,Ft=()=>(mt||(mt=import("react-native-biometrics").then(({default:e})=>Lt(new e({allowDeviceCredentials:!1}))).catch(e=>{throw mt=void 0,new d("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),mt);var _e=require("react-native");var hn=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,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 d("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${l} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},yn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(c,s)=>{r||(r=!0,clearTimeout(a),c?o(c):n(s))},a=setTimeout(()=>i(new d("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),l=()=>r?!1:t()?!0:(i(new d("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 d("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(l()){if(_e.Platform.OS==="android"){let s=_e.PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,p=_e.PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,g=await _e.PermissionsAndroid.check(s);if(!l())return;let w=g||await _e.PermissionsAndroid.check(p);if(!l())return;if(!g&&!w){let u=await _e.PermissionsAndroid.requestMultiple([s,p]);if(!l())return;if(u[s]!==_e.PermissionsAndroid.RESULTS.GRANTED&&u[p]!==_e.PermissionsAndroid.RESULTS.GRANTED)throw new d("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 p=(g={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?g:"LOCATION_ERROR";i(new d(p,s.message))},e)}})().catch(c=>i(c))});var Nt=require("react-native");var Dt=20,wn=20,Mn=/^[a-z][a-z0-9_-]{0,31}$/,tr=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,nr=["low","medium","high"],Ce=e=>!!e&&typeof e=="object"&&!Array.isArray(e),H=e=>new d("INVALID_PARAMS",e),et=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,_n=(e,t)=>{if(e===void 0)return{};if(!Ce(e)||Object.keys(e).length>wn||Object.values(e).some(n=>typeof n!="string"))throw H(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${wn} key)`);return e},xn=e=>{var n,o,r,i;if(e!==void 0&&!Ce(e))throw H("Tu\u1EF3 ch\u1ECDn upload ph\u1EA3i l\xE0 object");let t=e!=null?e:{};if(t.source!==void 0&&(typeof t.source!="string"||!Mn.test(t.source)))throw H("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"||!tr.test(a))))throw H("accept ph\u1EA3i l\xE0 m\u1EA3ng mime (image/*, application/pdf) ho\u1EB7c \u0111u\xF4i (.docx)");if(t.max_count!==void 0&&!et(t.max_count,1,Dt))throw H(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Dt}`);if(t.max_size!==void 0&&!et(t.max_size,1,Number.MAX_SAFE_INTEGER))throw H("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!et(t.concurrency,1,5))throw H("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:or(t.process),target:rr(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},or=e=>{if(e===void 0)return{};if(!Ce(e))throw H("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Ce(n))throw H("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!et(n[o],1,1e4))throw H(`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 H("process.image.quality ph\u1EA3i trong kho\u1EA3ng (0, 1]");t.image={max_width:n.max_width,max_height:n.max_height,quality:n.quality}}if(e.video!==void 0){let n=e.video;if(!Ce(n))throw H("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!et(n.max_duration,1,3600))throw H("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!nr.includes(n.quality))throw H("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},rr=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Ce(e))throw H("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!Mn.test(t))throw H("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!Ce(e.params))throw H("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 H("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 H(`upload.${a} ph\u1EA3i l\xE0 chu\u1ED7i`);return{target:"url",url:e.url,headers:_n(e.headers,"upload.headers"),form_data:_n(e.form_data,"upload.form_data"),field_name:(r=e.field_name)!=null?r:"file",url_field:(i=e.url_field)!=null?i:"url"}},En=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(),o=En(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},sr=e=>{let t=e.length>0&&e.every(o=>o.startsWith("image/")),n=e.length>0&&e.every(o=>o.startsWith("video/"));return t?"image":n?"video":"mixed"},Xe,ar=()=>(Xe!=null||(Xe=import("react-native-image-picker").catch(e=>{throw Xe=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)}`)})),Xe),bn=e=>async({accept:t,max_count:n,process:o})=>{var c,s,p,g,w,u,y,F,x;let r=await ar(),i=sr(t),a={mediaType:i==="image"?"photo":i,maxWidth:(c=o.image)==null?void 0:c.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(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:(y=o.video)==null?void 0:y.max_duration,assetRepresentationMode:"compatible"},l=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(l.didCancel)return[];if(l.errorCode){let P=l.errorCode==="permission"?"PERMISSION_DENIED":l.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new d(P,(F=l.errorMessage)!=null?F:l.errorCode)}return((x=l.assets)!=null?x:[]).filter(P=>P.uri).map((P,M)=>{var _,Z,ne;return{uri:P.uri,name:(_=P.fileName)!=null?_:`file_${M+1}`,mime_type:(Z=P.type)!=null?Z:"application/octet-stream",size:P.fileSize,width:P.width,height:P.height,duration:P.duration,processed:!((ne=P.type)!=null&&ne.startsWith("video/"))||Nt.Platform.OS==="ios"}})},cr={"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"},lr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},pr=e=>async({accept:t,max_count:n})=>{var i,a,l,c;let o=t.map(s=>{var p;return(p=cr[s])!=null?p:lr[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,y)=>{var F,x,P;return{uri:u.uri,name:(F=u.name)!=null?F:`file_${y+1}`,mime_type:(x=u.type)!=null?x:"application/octet-stream",size:(P=u.size)!=null?P:void 0}});if(Nt.Platform.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 y;return{...u,uri:(y=w.get(u.uri))!=null?y: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===((c=(l=e.errorCodes)==null?void 0:l.IN_PROGRESS)!=null?c:"ASYNC_OP_IN_PROGRESS")?new d("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},Ze,ur=async e=>(Ze!=null||(Ze=import("@react-native-documents/picker").then(t=>pr(t)).catch(t=>{throw Ze=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 Ze)(e)),Rn={library:bn("library"),camera:bn("camera"),document:ur},An={type:"image",label:"\u1EA2nh",accept:["image/*"]},Sn={type:"video",label:"Video",accept:["video/*"]},vn={library:[An,Sn],camera:[An,Sn],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"]}]},Qe,Pn=()=>(Qe!=null||(Qe=import("react-native-compressor").catch(()=>(Qe=void 0,null))),Qe),Tn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},dr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),gr={low:640,medium:1280,high:1920},mr=async(e,{image:t})=>{var o;if(!t||!dr.has(e.mime_type.toLowerCase()))return e;let n=await Pn();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 Tn(n,r,e.size),processed:!0}}catch{return e}},fr=async(e,{video:t})=>{var o;let n=await Pn();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:gr[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await Tn(n,r,e.size),processed:!0}}catch{return e}},hr={image:mr,video:fr},yr=(e,t)=>t.split(".").reduce((n,o)=>Ce(n)?n[o]:void 0,e),Ut=({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 l=new XMLHttpRequest,c=new FormData;Object.entries(a.form_data).forEach(([g,w])=>c.append(g,w)),c.append(a.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>l.abort();o.addEventListener("abort",s);let p=g=>{o.removeEventListener("abort",s),g()};l.open("POST",a.url),Object.entries(a.headers).forEach(([g,w])=>l.setRequestHeader(g,w)),l.upload.onprogress=g=>n(g.loaded,g.total||e.size||0),l.onload=()=>p(()=>{let g=l.responseText;try{g=JSON.parse(l.responseText)}catch{}if(l.status<200||l.status>=300){i(new d("UPLOAD_FAILED",`HTTP ${l.status}`));return}let w=yr(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})}),l.onerror=()=>p(()=>i(new d("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),l.onabort=()=>p(()=>i(new d("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),l.send(c)}),Cn=e=>{var o,r;let t={...Rn};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:Ut};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}},On=e=>{let{sources:t,targets:n}=Cn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===Rn[i]&&vn[i]).map(i=>[i,vn[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Dt}},ht=new Map,kn=(e,t)=>`${e}:${t}`,wr=0,In=(e,t)=>{var n;typeof t=="string"&&((n=ht.get(kn(e,t)))==null||n.abort())},Be=e=>{for(let[t,n]of ht)t.startsWith(`${e}:`)&&n.abort()},ft=()=>new d("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),_r=(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)}},Ln=async(e,t)=>{var c;let{sources:n,targets:o}=Cn(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,l=kn(t.instance_id,(c=t.task_id)!=null?c:`auto-${++wr}`);ht.set(l,a);try{return await br(e,t,r,i,a.signal)}finally{ht.delete(l)}},br=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:l=g=>g()},c,s,p)=>{var m,E,z;let g={app_id:n!=null?n:"",instance_id:t,context:{...(m=o==null?void 0:o())!=null?m:{}}},w=(await l(()=>c({accept:e.accept,max_count:e.max_count,process:e.process,caller:g}))).slice(0,e.max_count);if(p.aborted)throw ft();if(!w.length)throw new d("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let u=[],y=w.filter(T=>ir(T,e.accept)?!0:(u.push({name:T.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${T.mime_type||En(T.name)}`}),!1)),F=y.map(()=>0),x=y.map(T=>{var L;return(L=T.size)!=null?L:0}),P=0,M=0,_=(T=!1)=>{if(!a||!r)return;let L=Date.now();if(!T&&L-M<200)return;M=L;let B=x.reduce((V,ee)=>V+ee,0),G=F.reduce((V,ee)=>V+ee,0);a("upload.progress",{task_id:r,loaded:G,total:B,percent:B?Math.min(100,Math.round(G/B*100)):0,done_count:P,count:y.length})},Z=[],ne=0,ae=async()=>{var T,L,B;for(;ne<y.length;){let G=ne++,V=y[G];try{if(p.aborted)throw ft();let ee=V.mime_type.startsWith("image/")?"image":V.mime_type.startsWith("video/")?"video":void 0,Re=ee&&!V.processed?(L=(T=i==null?void 0:i.processors)==null?void 0:T[ee])!=null?L:hr[ee]:void 0;if(Re&&(V=await Re(V,e.process),x[G]=(B=V.size)!=null?B:x[G],p.aborted))throw ft();if(e.max_size&&V.size&&V.size>e.max_size)throw new d("FILE_TOO_LARGE",`File ${V.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let we=(Me,Pe)=>{F[G]=Me,Pe&&(x[G]=Pe),_()},oe=await s({file:V,target:e.target,onProgress:we,signal:p,caller:g});if(typeof(oe==null?void 0:oe.url)!="string"||!oe.url)throw new d("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:De,...ve}=oe;Z[G]={url:De,name:V.name,mime_type:V.mime_type,size:V.size,width:V.width,height:V.height,duration:V.duration,...Object.keys(ve).length?{response:"response"in ve?ve.response:ve}:{}},F[G]=x[G]}catch(ee){u.push(_r(y[G].name,ee))}finally{P++,_(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,y.length)},ae)),p.aborted)throw ft();let Se=Z.filter(T=>!!T);if(!Se.length){let T=u[0];throw new d((E=T==null?void 0:T.code)!=null?E:"UPLOAD_FAILED",(z=T==null?void 0:T.message)!=null?z:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:Se,failed:u}};var yt=require("react"),Oe=e=>{let t=e,n=new Set;return{getState:()=>t,setState:o=>{let r=typeof o=="function"?o(t):o;t={...t,...r},n.forEach(i=>i())},subscribe:o=>(n.add(o),()=>{n.delete(o)})}},W=(e,t,n=Object.is)=>{let o=(0,yt.useRef)(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let l=t(i),c=a&&n(a.value,l)?a.value:l;return o.current={state:i,selector:t,value:c},c};return(0,yt.useSyncExternalStore)(e.subscribe,r)};var ue={info:"info",success:"success",error:"error"},Ar=200,Fn={info:2e3,success:2e3,error:3e3},tt=Oe({message:"",type:ue.info,tick:0}),Dn=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,Ar);return o?{message:o,type:Object.values(ue).includes(n)?n:ue.info}:null},Nn=(e,t=ue.info)=>{tt.setState(n=>({message:e,type:t,tick:n.tick+1}))};var qt=require("react-native");var qe=require("react-native");var de,Un=()=>qe.Platform.OS==="android"&&!!(de!=null&&de.requesting_permission),Sr=1500,wt=()=>new Promise(e=>{if(qe.Platform.OS!=="android"||qe.AppState.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Sr),o=qe.AppState.addEventListener("change",r=>{r==="active"&&t()})}),Vt=e=>{var t;if(de===e&&(de=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&qe.Platform.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Vn=async(e,t,n,o=()=>!0)=>{var i,a,l,c,s;if(de)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:[]};de=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 wt(),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 y,F;de!==r||r.cancelled||n(u.isFinal?"speech.final":"speech.partial",{...u,text:(F=(y=u.results[0])==null?void 0:y.transcript)!=null?F:""})}),g.addListener("error",u=>{de===r&&!r.cancelled&&n("speech.error",{...u,code:u.error})}),g.addListener("end",()=>{de===r&&(Vt(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:(l=t.interimResults)!=null?l:!0,addsPunctuation:(c=t.addsPunctuation)!=null?c:!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 Vt(r),p}},Bn=e=>{let t=de;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},be=e=>{let t=de;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{Vt(t)}};var qn={qr:"qr",ean13:"ean-13",ean8:"ean-8",upcA:"upc-a",upcE:"upc-e",code128:"code-128",code39:"code-39",code93:"code-93",codabar:"codabar",itf:"itf",pdf417:"pdf-417",aztec:"aztec",dataMatrix:"data-matrix"},Q={...qn,all:Object.values(qn)},je={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},_t={result:"scanner.result",end:"scanner.end"},$e={user:"user",web:"web",closed:"closed",error:"error"},Ae={top:"top",full:"full"},ze={once:"once",continuous:"continuous"},vr=1500,$n=6e4,N,J=Oe({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),zn=()=>qt.Platform.OS==="android"&&!!(N!=null&&N.requesting_permission),$t=e=>{let{types:t,cooldown_ms:n,hint:o,layout:r}=e!=null?e:{},i={};if(t!==void 0){if(!Array.isArray(t)||!t.length||!t.every(a=>Q.all.includes(a)))throw new 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>$n)throw new d("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${$n}`);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(Ae).includes(r))throw new d("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");i.layout=r}return i},zt=e=>N!==e?!1:(N=void 0,J.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Wn=async(e,t)=>{if(N)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");N=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 wt(),n(),r!=="granted")throw new d("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera");if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new d("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await Wt();n(),J.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw zt(e),o}},Wt=async()=>{if(qt.Platform.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},jn=(e,t,n)=>{var o,r,i;return{owner:e,mode:t,types:(o=n.types)!=null?o:Q.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:vr,hint:n.hint,layout:t===ze.once?Ae.full:(i=n.layout)!=null?i:Ae.top,cancelled:!1,requesting_permission:!1,last_seen:new Map}},Hn=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=jn(e,ze.once,t);a.onHit=o,a.resolve=r,a.reject=i,Wn(a,n).catch(i)}),Jn=(e,t,n,o=()=>!0,r)=>{let i=jn(e,ze.continuous,t);return i.emit=n,i.onHit=r,Wn(i,o)},bt=(e,t,n)=>{var o,r;if(!J.getState().active){e.cancelled=!0;return}if(zt(e)){if(e.mode===ze.once){(o=e.reject)==null||o.call(e,t===$e.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,_t.end,n?{reason:t,message:n}:{reason:t})}},Gn=e=>{(N==null?void 0:N.owner)===e&&bt(N,$e.web)},ke=e=>{(N==null?void 0:N.owner)===e&&bt(N,$e.closed)},jt=()=>{N&&bt(N,$e.user)},Kn=e=>{N&&bt(N,$e.error,e)},Ht=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=N;if(!(!o||!J.getState().active))for(let{value:l,type:c}of e){if(!l)continue;let s=o.last_seen.get(l);if(!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if(o.last_seen.set(l,t),(r=o.onHit)==null||r.call(o),o.mode===ze.once){zt(o),(i=o.resolve)==null||i.call(o,{value:l,type:c});return}J.setState(p=>({last_value:l,hit_tick:p.hit_tick+1,scan_count:p.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,_t.result,{value:l,type:c})}}},Mr={1:Q.code128,2:Q.code39,4:Q.code93,8:Q.codabar,16:Q.dataMatrix,32:Q.ean13,64:Q.ean8,128:Q.itf,256:Q.qr,512:Q.upcA,1024:Q.upcE,2048:Q.pdf417,4096:Q.aztec},xr=2500,Bt=e=>{J.setState({notice:e}),setTimeout(()=>{J.getState().notice===e&&J.setState({notice:null})},xr)},Yn=async()=>{var t,n;let e=N;if(!(!e||J.getState().is_picking)){e.requesting_permission=!0,J.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||N!==e)return;if(r.errorCode||!i){Bt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),l=await a.scan(i);if(N!==e)return;let c=l.map(({value:s,format:p})=>({value:s,code_type:Mr[p]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:p})=>({value:s,type:p!=null?p:"unknown"}));if(!c.length){Bt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}Ht(c,Date.now(),!0)}catch{N===e&&Bt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await wt(),e.requesting_permission=!1,N===e&&J.setState({is_picking:!1})}}};var St=1,d=class extends Error{constructor(n,o){super(o);this.code=n}},Xn=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===St&&typeof t.method=="string"?t:null}catch{return null}},rt=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,Zn=(e,t)=>rt({id:e,result:t}),Qn=(e,t)=>rt({id:e,error:{code:t.code,message:t.message}}),eo=(e,t)=>rt({event:e,data:t}),Gt=e=>rt({event:"context",data:e});var to=()=>`(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: ${St}, 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;`,no=()=>`(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: ${St}, 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;`,oo=()=>`(function () {
|
|
42
42
|
if (window.__retionSafeAreaFrozen) { return; }
|
|
43
43
|
window.__retionSafeAreaFrozen = true;
|
|
44
44
|
var max = {};
|
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
|
-
})(); true;`,
|
|
63
|
-
${
|
|
62
|
+
})(); true;`,ro=e=>rt({event:e}),io=(e,t)=>{let n=so(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
|
|
63
|
+
${Gt(e)}`},so=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),ao=(e,t={})=>{let n=so(t);return`window.__RETION_MINIAPP_HOST__ = { protocol: ${St} };
|
|
64
64
|
window.__RETION_MINIAPP_CONTEXT__ = ${JSON.stringify(e)};
|
|
65
65
|
${n?`try { history.replaceState(history.state, '', location.pathname + '?' + ${JSON.stringify(n)} + location.hash); } catch (e) {}`:""}
|
|
66
|
-
true;`},
|
|
66
|
+
true;`},co={partner:"partner_token",chatbox:"chatbox_token"},lo=(e,t)=>{let n={...e};for(let o of Object.values(co))t.includes(o)||delete n[o];return n},Jt=new Set,nt=async(e,t)=>{if(Jt.has(e))throw new d("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);Jt.add(e);try{return await t()}finally{Jt.delete(e)}},po=()=>`(function () {
|
|
67
67
|
try {
|
|
68
68
|
var AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
69
69
|
if (!AudioCtx) { return; }
|
|
@@ -79,4 +79,4 @@
|
|
|
79
79
|
oscillator.start(ctx.currentTime);
|
|
80
80
|
oscillator.stop(ctx.currentTime + 0.08);
|
|
81
81
|
} catch (e) {}
|
|
82
|
-
})(); true;`,gr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),ft=(e,t)=>{if(typeof e!="string"||!e)throw new u("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},to=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:c,app_id:l,instance_id:a,options:s,emit:d,isActive:g,playBeep:A})=>{var R,x,_,J,Z,oe,ye,Q,le;let p=s==null?void 0:s.handlers,y={app_id:l,instance_id:a,close:c},L=()=>{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=ln(t);return Ye(e,()=>pn(m,g))}case"speech.start":{if(!d)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 Cn(a,m,d,g)}case"speech.stop":return On(a);case Be.scan:return Dn(a,Dt(t),g,L);case Be.start:{if(!d)throw E();return Nn(a,Dt(t),d,g,L)}case Be.stop:return Un(a);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 Pn(wn(w),{instance_id:a,app_id:l,getContext:r,task_id:m,config:s==null?void 0:s.upload,emit:d,exclusivePick:P=>Ye("uploadFiles.pick",P)})}case"uploadFiles.cancel":En(a,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Mn(s==null?void 0:s.upload);case"getBiometricAvailability":return((R=s==null?void 0:s.biometrics)!=null?R:await Ct()).getAvailability();case"authenticateBiometric":{let m=ft(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 Ye(e,async()=>{var k;return((k=s==null?void 0:s.biometrics)!=null?k:await Ct()).authenticate({reason:m,cancelButtonText:w})})}case"requestPayment":{let m=p==null?void 0:p.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:ft(t==null?void 0:t.currency,"currency")};return Ye(e,()=>m(P,y))}case"printImage":{let m=p==null?void 0:p.printImage;if(!m)throw E();let w=ft(t==null?void 0:t.image,"image");await Ye(e,()=>m({image:w},y));return}case"openScreen":if(!(p!=null&&p.openScreen))throw E();await p.openScreen({screen:ft(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},y);return;case"closeApp":c();return;case"openWebview":{let m=String((x=t==null?void 0:t.url)!=null?x:"");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):Xe.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):Xe.Linking.openURL(m))}catch(w){throw new u("NOT_SUPPORTED",String((Z=(J=w==null?void 0:w.message)!=null?J:w)!=null?Z:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":(ye=s==null?void 0:s.showToast)==null||ye.call(s,String((oe=t==null?void 0:t.message)!=null?oe:""));return;case"haptic":{let m=gr.has(t==null?void 0:t.type)?t.type:"selection";(Q=s==null?void 0:s.haptic)==null||Q.call(s,m);return}case"getSystemInfo":return{platform:Xe.Platform.OS==="ios"?"ios":"android",appVersion:(le=s==null?void 0:s.app_version)!=null?le:"",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 k=n().access_token;if(!k)throw new u("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return k}if(m!=="partner"&&m!=="chatbox")throw new u("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(m)}`);let w=Zn[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 zt=e=>`bundle:${e}`,Wt=()=>`${V().file_system.document_dir}/miniapps`,jt=Wt,Ht=(e,t,n="index.html",o=!1,r=[])=>{let i=`${jt()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},$t=e=>{var t;V().storage.setString(zt(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},mr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,N=e=>{let t=V().storage.getString(zt(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return Ht(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},_e=e=>V().file_system.exists(e.entry_uri.replace("file://","")),Jt=async e=>{let t=N(e.app_id);return(t==null?void 0:t.version)===e.version&&await _e(t)},oo=async(e,t)=>{let n=V().file_system,o=`${jt()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},ro=async e=>{var t;await((t=et[e])==null?void 0:t.catch(()=>{})),V().storage.setString(zt(e),""),await V().file_system.remove(`${jt()}/${e}`).catch(()=>{})},qe=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},et={},io=(e,t)=>{var i;let o=((i=et[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return et[e]=r,r.then(()=>{et[e]===r&&delete et[e]}),o},fr=(e,t)=>{var r,i;let n=e.split(".").map(c=>parseInt(c,10)||0),o=t.split(".").map(c=>parseInt(c,10)||0);for(let c=0;c<Math.max(n.length,o.length);c++){let l=((r=n[c])!=null?r:0)-((i=o[c])!=null?i:0);if(l)return l}return 0},so=({manifest:e,zip_path:t})=>io(e.app_id,async()=>{var i;let n=V().file_system,o=N(e.app_id);if(o&&fr(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=Ht(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),$t(e),se("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),oo(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),Kt=(e,{base_url:t,onProgress:n}={})=>{let o=V().file_system,r=null,i=!1,c=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,l=()=>{if(i)throw new qe},a=async()=>{var g;l();let s=N(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return $t(e),N(e.app_id);l();let d=o.download({url:t?mr(t,e.bundle_url):e.bundle_url,to_file:c,onProgress:(A,p)=>{var L;let y=p>0?p:(L=e.size)!=null?L:0;y>0&&(n==null||n(Math.min(1,A/y)))}});r=d;try{let{status:A}=await d.promise;if(l(),A!==200)throw new Error(`bundle ${A}`);if(e.sha256)if(o.sha256){if(await o.sha256(c)!==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);l();let p=Ht(e.app_id,e.version,e.entry,!!e.context_update,(g=e.permissions)!=null?g:[]);return await o.remove(p.dir).catch(()=>{}),await o.mkdir(p.dir),await o.unzip(c,p.dir),$t(e),oo(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),p}catch(A){throw i?new qe:A}finally{r=null,o.remove(c).catch(()=>{})}};return{promise:io(e.app_id,a),cancel:()=>{i=!0,r==null||r.cancel()}}},Qe={},hr=__DEV__?0:60*1e3,no={},ao=(e,t)=>{var o,r;let n=N(e);return n&&Date.now()-((o=no[t])!=null?o:0)<hr?Promise.resolve(n):((r=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 c=await i.json(),l=await Kt(c,{base_url:t}).promise;return no[t]=Date.now(),l})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),N(e))).finally(()=>{Qe[e]=void 0})),Qe[e])};var yt=new Map,co=(e,t)=>(yt.set(e,t),()=>{yt.get(e)===t&&yt.delete(e)}),lo=(e,t)=>{let n=yt.get(e);return n?n(t):!1};var j=require("react"),h=require("react-native");var M=require("react/jsx-runtime"),tt="#22C55E",yr="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",wr=2,At=18,Ar=1600,nt=14,_r=2e3,po=2,$e=2e3,br=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:nt},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:nt},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:nt},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:nt}],uo=({color:e})=>(0,M.jsx)(M.Fragment,{children:br.map((t,n)=>(0,M.jsx)(h.View,{style:[v.corner,t,{borderColor:e}]},n))}),wt=({style:e,children:t,...n})=>{let o=(0,j.useRef)(new h.Animated.Value(1)).current,r=i=>h.Animated.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return(0,M.jsx)(h.Pressable,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:(0,M.jsx)(h.Animated.View,{style:[e,{transform:[{scale:o}]}],children:t})})},Yt=({scanner:e})=>{var we,Ae,ve;let{vision:t,types:n,mode:o,layout:r,hint:i,glass_view:c}=e,l=r===he.top,a=t.useCameraDevice("back"),[s,d]=(0,j.useState)(!1),[g,A]=(0,j.useState)(1),[p,y]=(0,j.useState)({width:0,height:0}),L=K(z,T=>T.last_value),E=K(z,T=>T.hit_tick),R=K(z,T=>T.scan_count),x=K(z,T=>T.notice),_=K(z,T=>T.is_picking),J=(0,j.useRef)(null),[Z,oe]=(0,j.useState)(0),ye=h.Platform.OS==="ios"?54:(we=h.StatusBar.currentHeight)!=null?we:0,Q=(0,j.useRef)(new h.Animated.Value(0)).current,le=(0,j.useRef)(new h.Animated.Value(0)).current,m=(0,j.useRef)(new h.Animated.Value(0)).current,w=Math.round(p.width*(l?.8:.78)),P=Math.round(l?p.height*.46:w*.78),k=Math.round((p.height-P)/2),W=Math.round((p.width-w)/2),U=t.useCodeScanner({codeTypes:n,onCodeScanned:(0,j.useCallback)(T=>Vt(T),[])});(0,j.useEffect)(()=>{let T=h.BackHandler.addEventListener("hardwareBackPress",()=>(Ut(),!0));return()=>T.remove()},[]);let Y=(0,j.useRef)(E);(0,j.useEffect)(()=>{if(E===Y.current)return;Q.setValue(1),m.setValue(1);let T=h.Animated.parallel([h.Animated.timing(Q,{toValue:0,duration:450,useNativeDriver:!0}),h.Animated.sequence([h.Animated.delay(_r),h.Animated.timing(m,{toValue:0,duration:250,useNativeDriver:!0})])]);return T.start(),()=>T.stop()},[E,Q,m]),(0,j.useEffect)(()=>{let T=je=>h.Animated.timing(le,{toValue:je,duration:Ar,easing:h.Easing.inOut(h.Easing.quad),useNativeDriver:!0}),Te=h.Animated.loop(h.Animated.sequence([T(1),T(0)]));return Te.start(),()=>Te.stop()},[le]);let Se=!!(a!=null&&a.hasTorch),ge=(Ae=a==null?void 0:a.neutralZoom)!=null?Ae:1,ee=a?Math.min(ge*g,a.maxZoom):1,Oe=(0,M.jsx)(h.Text,{style:[v.hint,!!x&&v.hint_notice],numberOfLines:1,children:(ve=x!=null?x:i)!=null?ve:yr});return(0,M.jsxs)(h.View,{ref:J,style:l?v.top:v.full,onLayout:({nativeEvent:{layout:T}})=>{var Te;y({width:T.width,height:T.height}),(Te=J.current)==null||Te.measureInWindow((je,it)=>oe(it))},children:[a&&(0,M.jsx)(t.Camera,{style:h.StyleSheet.absoluteFill,device:a,isActive:!_,codeScanner:U,torch:s&&Se?"on":"off",zoom:ee,enableZoomGesture:!0,onError:T=>Vn(T.message)}),p.height>0&&(0,M.jsxs)(h.View,{style:v.overlay,pointerEvents:"none",children:[(0,M.jsx)(h.View,{style:[v.dim_ring,{top:k-$e,left:W-$e,width:w+$e*2,height:P+$e*2}]}),(0,M.jsxs)(h.View,{style:{position:"absolute",top:k,left:W,width:w,height:P},children:[(0,M.jsx)(uo,{color:"#FFFFFF"}),(0,M.jsx)(h.Animated.View,{style:[h.StyleSheet.absoluteFill,{opacity:Q}],children:(0,M.jsx)(uo,{color:tt})}),(0,M.jsxs)(h.Animated.View,{style:[v.scan_line_wrap,{transform:[{translateY:le.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,P-At)]})}]}],children:[(0,M.jsx)(h.View,{style:v.scan_glow_outer}),(0,M.jsx)(h.View,{style:v.scan_glow_inner}),(0,M.jsx)(h.View,{style:v.scan_line})]})]}),(0,M.jsx)(h.View,{style:[v.hint_slot,l?{top:0,height:k-6,justifyContent:"flex-end"}:{top:k+P+20}],children:Oe}),o===Ne.continuous&&!!L&&(0,M.jsx)(h.Animated.View,{style:[v.result_slot,l?v.result_slot_top:{top:k+P+52},{opacity:m}],children:(0,M.jsxs)(h.View,{style:v.result,children:[(0,M.jsx)(h.View,{style:v.check_badge,children:(0,M.jsx)(h.View,{style:v.check_mark})}),(0,M.jsx)(h.Text,{style:v.result_text,numberOfLines:1,children:L}),(0,M.jsxs)(h.Text,{style:v.result_count,children:["\xB7 ",R," m\xE3"]})]})})]}),(0,M.jsx)(h.View,{style:[v.close_slot,{top:Math.max(12,ye-Z+12)}],children:(0,M.jsxs)(wt,{style:[v.close_button,!!c&&v.glass_surface],onPress:Ut,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[c&&(0,M.jsx)(c,{style:v.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,M.jsx)(h.View,{style:[v.close_bar,v.close_bar_a]}),(0,M.jsx)(h.View,{style:[v.close_bar,v.close_bar_b]})]})}),(0,M.jsx)(h.View,{style:[v.toolbar_wrap,!l&&v.toolbar_wrap_full],pointerEvents:"box-none",children:(0,M.jsxs)(h.View,{style:[v.toolbar,!!c&&v.glass_surface],children:[c&&(0,M.jsx)(c,{style:v.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,M.jsx)(wt,{style:v.tool,onPress:Bn,disabled:_,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:(0,M.jsxs)(h.View,{style:v.image_icon,children:[(0,M.jsx)(h.View,{style:v.image_icon_dot}),(0,M.jsx)(h.View,{style:v.image_icon_hill})]})}),!!a&&a.maxZoom>=ge*po&&(0,M.jsx)(wt,{style:[v.tool,g>1&&v.tool_on],onPress:()=>A(T=>T>1?1:po),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:(0,M.jsxs)(h.Text,{style:[v.zoom_text,g>1&&v.zoom_text_on],children:[g,"x"]})}),Se&&(0,M.jsx)(wt,{style:[v.tool,s&&v.tool_on],onPress:()=>d(T=>!T),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:s},children:(0,M.jsx)(h.Text,{style:[v.torch_icon,s&&v.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})},Sr="rgba(0,0,0,0.5)",Gt=50,v=h.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:$e,borderColor:Sr,borderRadius:$e+nt},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:At,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:At,borderRadius:At/2,backgroundColor:tt,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:tt,opacity:.2},scan_line:{height:wr,borderRadius:1,backgroundColor:tt},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar_wrap_full:{bottom:h.Platform.OS==="ios"?34:20},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:Gt,height:Gt,borderRadius:Gt/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result_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:tt},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 te=Ve({active_key:null,instances:{}}),go=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var l;let c=(l=V().keep_alive)==null?void 0:l.max_webviews;te.setState(a=>{let s=t!=null?t:e.app_id,d={...a.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},g=Object.keys(d);return c&&c>0&&g.length>c&&g.filter(A=>A!==s).sort((A,p)=>d[A].last_used_at-d[p].last_used_at).slice(0,g.length-c).forEach(A=>{delete d[A]}),i?{active_key:s,instances:d}:{instances:d}})},mo=e=>go(e,!0),fo=e=>go(e,!1),ze=()=>te.setState({active_key:null}),_t=e=>{te.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var ho="catalog",vr="paused_apps",Mr="removed_apps",xr=10*1e3,Er=2,Pr=3e3,Rr=()=>{var e;try{return JSON.parse((e=V().storage.getString(ho))!=null?e:"{}")}catch{return{}}},F=Ve({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),yo=e=>{var t;return!!((t=V().manual_update)!=null&&t.includes(e))},vt=new Set,wo=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{}}}},de=wo(vr),Ce=wo(Mr);sn(()=>{de.load(),Ce.load();let e=Rr(),t={};Object.keys(e).filter(n=>!Ce.has(n)).forEach(n=>{let o=N(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:de.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),F.setState({catalog:e,downloads:t})});var Mt=e=>K(F,t=>e?t.downloads[e]:void 0),Ao=()=>K(F,e=>e.pause_reasons.length>0),ue=(...e)=>se("queue",...e),H=[],be={},C=null,bt=new Set,Ue={},Xt=new Set,Pe=e=>{Xt.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},_o=e=>(Xt.add(e),()=>{Xt.delete(e)}),bo=()=>F.getState().downloads,ne=(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(c=>({downloads:{...c.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?Pe({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Pe({type:"progress",app_id:e,progress:i.progress,version:i.version})},St=(e,t)=>{var n;(n=Ue[e])==null||n.forEach(o=>o(t)),delete Ue[e]},Cr=()=>F.getState().pause_reasons.length>0,Re=e=>{var l;if(C)return;let t=e?H.indexOf(e):Cr()?-1:H.findIndex(a=>!de.has(a));if(t<0||t>=H.length)return;let[n]=H.splice(t,1),o=F.getState().catalog[n];if(!o){St(n,N(n)),Re();return}let r=Date.now();be[n]=((l=be[n])!=null?l:0)+1,ne(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,c=Kt(o,{onProgress:a=>{let s=Math.floor(a*100);s!==i&&(i=s,ne(n,{progress:s/100,version:o.version}))}});C={app_id:n,handle:c,forced:!!e},ue("start",n,o.version,e?"(forced)":""),c.promise.then(a=>{ue("installed",n,o.version,`${Date.now()-r}ms`),ne(n,{status:"installed",progress:1,version:o.version}),St(n,a)}).catch(a=>{var d;if(a instanceof qe){if(bt.has(n))return;ue("paused",n),be[n]-=1,H.unshift(n),ne(n,{status:de.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((d=a==null?void 0:a.message)!=null?d:a);if(console.warn("[miniapp-queue] failed",n,s),be[n]<Er){ne(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var g;H.includes(n)||(C==null?void 0:C.app_id)===n||(H.push(n),Re((g=Ue[n])!=null&&g.length?n:void 0))},Pr);return}ne(n,{status:"failed",progress:0,version:o.version,error:s}),St(n,N(n))}).finally(()=>{C=null;let a=H.find(s=>{var d;return(d=Ue[s])==null?void 0:d.length});Re(a)})},xt=(e,{front:t=!1}={})=>{if((C==null?void 0:C.app_id)===e)return;let n=H.indexOf(e);if(n>=0){if(!t)return;H.splice(n,1)}t?H.unshift(e):H.push(e)},Or=async e=>{let{host_id:t,client_token:n}=V(),o=new AbortController,r=setTimeout(()=>o.abort(),xr);try{let i=`${at}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,c=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!c.ok)throw new Error(`host list ${e} ${c.status}`);return(await c.json()).apps.map(a=>({...a,channel:e}))}finally{clearTimeout(r)}},ot=null,Et=()=>(ot!=null||(ot=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(V().channels.map(Or)),o={};[...n].reverse().flat().forEach(a=>{o[a.app_id]=a});let r=Object.keys(F.getState().catalog).filter(a=>!o[a]);V().storage.setString(ho,JSON.stringify(o)),F.setState({catalog:o}),await Promise.all(r.map(a=>So(a,{by_user:!1}))),r.forEach(a=>Ce.delete(a));let i=Object.keys(o).filter(a=>!Ce.has(a)),c=[],l={};for(let a of i.map(s=>o[s])){if(await Jt(a)){ne(a.app_id,{status:"installed",progress:1,version:a.version});continue}let s=N(a.app_id);if(yo(a.app_id)&&!vt.has(a.app_id)&&s&&await _e(s)){ne(a.app_id,{status:"installed",progress:1,version:s.version}),l[a.app_id]={app_id:a.app_id,current_version:s.version,next_version:a.version};continue}c.push(a)}return F.setState({updates:l}),c.forEach(a=>{be[a.app_id]=0,ne(a.app_id,{status:de.has(a.app_id)?"paused":"queued",progress:0,version:a.version,error:void 0}),xt(a.app_id)}),ue("catalog",i.length,"apps, outdated",c.map(a=>a.app_id),"removed",r,`${Date.now()-e}ms`),Pe({type:"sync_complete",app_ids:i,removed:r}),Object.values(l).forEach(a=>Pe({type:"update_available",...a})),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),Pe({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{ot=null}})()),ot),So=async(e,{by_user:t})=>{var r,i,c,l;if(t&&Ce.add(e),bt.has(e))return;bt.add(e),de.delete(e);let n=H.indexOf(e);n>=0&&H.splice(n,1),(C==null?void 0:C.app_id)===e&&C.handle.cancel();let o=(l=(c=(r=F.getState().downloads[e])==null?void 0:r.version)!=null?c:(i=N(e))==null?void 0:i.version)!=null?l:"";ne(e,{status:"uninstalling",progress:0,version:o}),await ro(e),_t(e),F.setState(a=>{let s={...a.downloads};return delete s[e],{downloads:s}}),delete be[e],bt.delete(e),St(e,null),ue("uninstalled",e,t?"(user)":"(not in list)"),Pe({type:"uninstalled",app_id:e})},vo=e=>So(e,{by_user:!0}),Mo=e=>{let t=We(e);return t?(Ce.delete(e),(C==null?void 0:C.app_id)===e||H.includes(e)||(be[e]=0,ne(e,{status:de.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),xt(e),Re(),ue("restore",e)),!0):!1},xo=e=>{if(de.has(e))return;if(de.add(e),ue("pause app",e),(C==null?void 0:C.app_id)===e&&!C.forced){C.handle.cancel();return}let t=F.getState().downloads[e];H.includes(e)&&t&&ne(e,{status:"paused",progress:0,version:t.version})},Eo=e=>{if(!de.delete(e))return;ue("resume app",e);let t=F.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!H.includes(e)&&We(e)&&(be[e]=0,xt(e)),H.includes(e)&&t&&ne(e,{status:"queued",progress:0,version:t.version}),Re()},Po=e=>{let{pause_reasons:t}=F.getState();t.includes(e)||(F.setState({pause_reasons:[...t,e]}),ue("pause",e),t.length===0&&Pe({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}),ue("resume",e),n.length===0&&Pe({type:"pause_change",paused:!1,reasons:n}),Re()},Zt=e=>F.getState().updates[e],Co=async e=>{var n,o;let t=Zt(e);vt.add(e);try{let r=await rt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=We(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(F.setState(c=>{var a;let l={...c.updates};return delete l[e],{updates:l,apply_ticks:{...c.apply_ticks,[e]:((a=c.apply_ticks[e])!=null?a:0)+1}}}),ue("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{vt.delete(e)}},Oo=()=>Object.values(F.getState().catalog).map(e=>({...e,installed:!!N(e.app_id),removed_by_user:Ce.has(e.app_id)})),We=e=>F.getState().catalog[e],rt=async e=>{let t=We(e);if(!t)return;if(de.delete(e),Ce.delete(e),await Jt(t))return N(e);let n=N(e);if(yo(e)&&!vt.has(e)&&n&&await _e(n))return n;let o=new Promise(r=>{var i;((i=Ue[e])!=null?i:Ue[e]=[]).push(r)});return(C==null?void 0:C.app_id)===e?C.forced=!0:(be[e]=0,xt(e,{front:!0}),C&&!C.forced?C.handle.cancel():Re(e)),o};var I=require("react/jsx-runtime"),Qt=e=>(e!=null?e:"").replace(/\?[^#]*/,""),To=0,Tr=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},kr=S.default.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:c,bridge:l,opaque_background:a,allow_embedded_miniapps:s,onWebLoadEnd:d})=>{var je,it;let g=(0,S.useRef)(null),A=(0,S.useRef)(!1),p=K(te,f=>f.instances[e]),y=p==null?void 0:p.app.app_id,L=p==null?void 0:p.app.manifest_url,E=p==null?void 0:p.context,R=p==null?void 0:p.url_params,x=K(z,f=>{var b;return((b=f.active)==null?void 0:b.owner)===e?f.active:null}),[_,J]=(0,S.useState)(()=>y?N(y):null),[Z,oe]=(0,S.useState)(!1),[ye,Q]=(0,S.useState)(0),[le,m]=(0,S.useState)(0),[w,P]=(0,S.useState)(!1),k=(0,S.useRef)(null),W=f=>{k.current&&clearTimeout(k.current),k.current=setTimeout(()=>{k.current=null,P(!0)},f)};(0,S.useEffect)(()=>()=>{k.current&&clearTimeout(k.current)},[]),(0,S.useEffect)(()=>{if(!y||!t&&_)return;let f=!0;return oe(!1),(async()=>{let b=N(y),X=b?await _e(b):!1;if(!f||(J(X?pe=>!pe||pe.version!==b.version||pe.permissions.join(",")!==b.permissions.join(",")?b:pe:null),__DEV__&&Date.now()-To>1e4&&(To=Date.now(),await Et()),!f))return;let Me=await rt(y),ke=Me!==void 0?Me:L?await ao(y,L):N(y);if(f){if(!ke){oe(!0);return}J(pe=>pe!=null?pe:ke)}})(),()=>{f=!1}},[t,y,L,ye]),(0,S.useEffect)(()=>co(e,f=>g.current?(g.current.postMessage(f),!0):!1),[e]);let U=K(F,f=>{let b=y?f.downloads[y]:void 0;return(b==null?void 0:b.status)==="installed"?b.version:void 0});(0,S.useEffect)(()=>{if(t||!y||!_)return;let f=N(y);if(!f||f.version===_.version)return;let b=!0;return _e(f).then(X=>{!b||!X||(se(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",_.version,"\u2192",f.version),J(f))}),()=>{b=!1}},[t,y,U,_==null?void 0:_.version]);let Y=K(F,f=>{var b;return y&&(b=f.apply_ticks[y])!=null?b:0});(0,S.useEffect)(()=>{if(!Y||!y)return;let f=N(y);if(!f||f.version===(_==null?void 0:_.version))return;let b=!0;return _e(f).then(X=>{!b||!X||(se(`webview:${e}`,"c\u1EADp nh\u1EADt",_==null?void 0:_.version,"\u2192",f.version),P(!1),J(f))}),()=>{b=!1}},[Y]),(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(()=>{_t(e)},f);return()=>clearTimeout(b)},[t,e]),(0,S.useEffect)(()=>{r>0&&(oe(!1),P(!1),m(f=>f+1),Q(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(Kn(t?"resumed":"paused"))))},[t]);let ge=`${(je=_==null?void 0:_.version)!=null?je:"none"}:${(it=_==null?void 0:_.permissions.join(","))!=null?it:""}:${le}`,ee=(0,S.useMemo)(()=>JSON.stringify([E!=null?E:{},R!=null?R:{}]),[E,R]),Oe=(0,S.useMemo)(()=>{var f;return Qn(R!=null?R:{},(f=_==null?void 0:_.permissions)!=null?f:[])},[ee,_==null?void 0:_.permissions]),we=(0,S.useMemo)(()=>Xn(E!=null?E:{},Oe)+Hn()+(O.Platform.OS==="android"?Jn():"")+(V().debug?jn():""),[Oe]),Ae=(0,S.useRef)(null),ve=(0,S.useRef)(null);(0,S.useEffect)(()=>{var b,X,Me;if(!_)return;if(ve.current!==ge){ve.current=ge,Ae.current=ee;return}if(Ae.current===ee)return;let f=((X=JSON.parse((b=Ae.current)!=null?b:"[]")[0])!=null?X:{}).org_id;if(Ae.current=ee,f===(E==null?void 0:E.org_id)&&A.current){P(!1),W(1500),(Me=g.current)==null||Me.injectJavaScript(Gn(E!=null?E:{},Oe));return}P(!1),m(ke=>ke+1)},[ee,_,ge]),(0,S.useEffect)(()=>(t||(fe(e),Ee(e),Ie(e)),()=>{fe(e),Ee(e),Ie(e)}),[t,e,ge,r]),(0,S.useEffect)(()=>{let f=O.AppState.addEventListener("change",b=>{b==="background"&&!Rn()&&fe(e),b==="background"&&!Ln()&&Ee(e)});return()=>f.remove()},[e]);let T=(0,S.useCallback)(async f=>{var X,Me,ke,pe,Pt;let b=qn(f.nativeEvent.data);if(!b){if(y&&(l!=null&&l.onWebEvent))try{Promise.resolve(l.onWebEvent(f.nativeEvent.data,{app_id:y,instance_id:e})).catch(B=>{console.warn("[miniapp] onWebEvent l\u1ED7i",y,B)})}catch(B){console.warn("[miniapp] onWebEvent l\u1ED7i",y,B)}return}if(b.method==="log"){let{level:B,text:q}=b;se(`web:${e}`,B!=null?B:"log",q!=null?q:"");return}if(b.method==="pong"){k.current||P(!0);return}if(b.method==="touchAtTop"){i.emit(!!b.at_top);return}if(b.method==="contextApplied"){k.current&&clearTimeout(k.current),k.current=null,P(!0);return}if(b.method==="ready"){A.current=!0,P(!0);let B=(X=te.getState().instances[e])==null?void 0:X.context;B&&((Me=g.current)==null||Me.injectJavaScript(qt(B)));return}try{let B=await to(b,{getHostData:()=>{var q,re;return(re=(q=te.getState().instances[e])==null?void 0:q.host_data)!=null?re:{}},getPermissions:()=>{var q,re;return y?(re=(q=N(y))==null?void 0:q.permissions)!=null?re:[]:[]},getContext:()=>{var q,re;return(re=(q=te.getState().instances[e])==null?void 0:q.context)!=null?re:{}},is_dark:o,close:ze,app_id:y!=null?y:"",instance_id:e,options:l,emit:(q,re)=>{var tn;(tn=g.current)==null||tn.injectJavaScript(Wn(q,re))},playBeep:()=>{var q;(q=g.current)==null||q.injectJavaScript(eo())},isActive:()=>te.getState().active_key===e&&O.AppState.currentState!=="background"});b.id&&((ke=g.current)==null||ke.injectJavaScript($n(b.id,B)))}catch(B){if(!b.id)return;let q=B==null?void 0:B.code,re=B instanceof u?B:new u(typeof q=="string"?q:"HOST_ERROR",String((pe=B==null?void 0:B.message)!=null?pe:B));(Pt=g.current)==null||Pt.injectJavaScript(zn(b.id,re))}},[e,o,y,i,l]),Te=(0,S.useCallback)(()=>{oe(!1),m(f=>f+1),Q(f=>f+1)},[]);return(0,I.jsxs)(O.View,{style:[O.StyleSheet.absoluteFill,a&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&ce.behind],pointerEvents:t?"auto":"none",children:[(x==null?void 0:x.layout)===he.top&&(0,I.jsx)(Yt,{scanner:x}),_?(0,I.jsx)(Lo.default,{ref:g,source:{uri:_.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?Wt():_.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:we,onMessage:T,bounces:!1,overScrollMode:"never",onLoadStart:f=>{fe(e),Ee(e),Ie(e),se(`webview:${e}`,"load start",Qt(f.nativeEvent.url)),A.current=!1,P(!1)},onError:f=>{fe(e),Ee(e),Ie(e),se(`webview:${e}`,"load error",Qt(f.nativeEvent.url),f.nativeEvent.description),oe(!0),P(!1)},onLoadEnd:f=>{let b=f.nativeEvent.url;se(`webview:${e}`,"load end",Qt(b)),y&&(d==null||d({app_id:y,instance_id:e,url:b})),W(1500)},onContentProcessDidTerminate:()=>{fe(e),Ee(e),Ie(e),A.current=!1,P(!1),m(f=>f+1)},onRenderProcessGone:()=>(fe(e),Ee(e),Ie(e),A.current=!1,P(!1),m(f=>f+1),!0),style:ce.webview},ge):null,(x==null?void 0:x.layout)===he.full&&(0,I.jsx)(Yt,{scanner:x}),p&&(0,I.jsx)(Ir,{visible:!_||!w,interactive:Z,children:(0,I.jsx)(Lr,{splash:c,app:p.app,is_dark:o,error:Z,has_bundle:!!_,retry:Te})})]})}),Lr=S.default.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let c=e,l=Mt(t.app_id),a=o?"error":!r&&(l==null?void 0:l.status)==="downloading"?"downloading":"loading";return(0,I.jsx)(c,{app:t,is_dark:n,status:a,progress:a==="downloading"?l==null?void 0:l.progress:void 0,retry:i})}),Ir=({visible:e,interactive:t,children:n})=>{let o=(0,S.useRef)(new O.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 c=O.Animated.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return c.start(({finished:l})=>{l&&i(!1)}),()=>c.stop()},[e,o]),r?(0,I.jsx)(O.Animated.View,{style:[O.StyleSheet.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},en=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return(0,I.jsxs)(O.View,{style:[ce.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,I.jsx)(O.View,{style:[ce.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,I.jsx)(O.Image,{source:{uri:e.icon},style:ce.splash_icon_image}):(0,I.jsx)(O.Text,{style:ce.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,I.jsx)(O.Text,{style:[ce.splash_name,{color:i}],children:e.name}),n==="error"?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(O.Text,{style:ce.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,I.jsx)(O.TouchableOpacity,{activeOpacity:.7,style:[ce.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:(0,I.jsx)(O.Text,{style:[ce.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(O.ActivityIndicator,{style:ce.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,I.jsxs)(O.Text,{style:ce.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},ko=(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.`))},Fr=({container:e,splash:t=en,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:c=!1,onWebLoadEnd:l})=>{ko("container",e),ko("splash",t);let a=e,s=K(te,x=>x.active_key),d=(0,S.useRef)(s);s&&(d.current=s);let g=K(te,x=>Object.keys(x.instances).join("|")),A=K(te,x=>{var _;return x.active_key?(_=x.instances[x.active_key])==null?void 0:_.app.name:void 0}),p=(0,S.useMemo)(()=>g?g.split("|"):[],[g]),[y,L]=(0,S.useState)({}),E=(0,S.useRef)(Tr()).current;(0,S.useEffect)(()=>{if(!s||!r)return;let x=O.BackHandler.addEventListener("hardwareBackPress",()=>(ze(),!0));return()=>x.remove()},[s,r]);let R=(0,S.useCallback)(()=>{let x=te.getState().active_key;x&&L(_=>({..._,[x]:(_[x]||0)+1}))},[]);return p.length?(0,I.jsx)(a,{visible:!!s,title:A!=null?A:"",is_dark:n,close:ze,reload:R,subscribeWebAtTop:E.subscribe,children:p.map(x=>(0,I.jsx)(kr,{instance_key:x,is_active:s===x,is_front:(s!=null?s:d.current)===x,is_dark:n,reload_tick:y[x]||0,web_at_top:E,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:c,onWebLoadEnd:l},x))}):null},ce=O.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"}}),Io=S.default.memo(Fr);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});
|
|
82
|
+
})(); true;`,Er=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),At=(e,t)=>{if(typeof e!="string"||!e)throw new d("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},uo=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:l,instance_id:c,options:s,emit:p,isActive:g,playBeep:w})=>{var P,M,_,Z,ne,ae,Se;let u=s==null?void 0:s.handlers,y={app_id:l,instance_id:c,close:a},F=()=>{var m;(m=s==null?void 0:s.haptic)==null||m.call(s,"impactLight"),w==null||w()},x=()=>new d("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let m=hn(t);return nt(e,()=>yn(m,g))}case"speech.start":{if(!p)throw x();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 E of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[E])!==void 0){if(typeof t[E]!="boolean")throw new d("INVALID_PARAMS",`${E} ph\u1EA3i l\xE0 boolean`);m[E]=t[E]}return Vn(c,m,p,g)}case"speech.stop":return Bn(c);case je.scan:return Hn(c,$t(t),g,F);case je.start:{if(!p)throw x();return Jn(c,$t(t),p,g,F)}case je.stop:return Gn(c);case"uploadFiles":{let{task_id:m,...E}=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 Ln(xn(E),{instance_id:c,app_id:l,getContext:r,task_id:m,config:s==null?void 0:s.upload,emit:p,exclusivePick:z=>nt("uploadFiles.pick",z)})}case"uploadFiles.cancel":In(c,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return On(s==null?void 0:s.upload);case"getBiometricAvailability":return((P=s==null?void 0:s.biometrics)!=null?P:await Ft()).getAvailability();case"authenticateBiometric":{let m=At(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 E=t==null?void 0:t.cancelButtonText;if(E!==void 0&&(typeof E!="string"||!E.trim()||E.length>80))throw new d("INVALID_PARAMS","Invalid cancelButtonText");return nt(e,async()=>{var T;return((T=s==null?void 0:s.biometrics)!=null?T:await Ft()).authenticate({reason:m,cancelButtonText:E})})}case"requestPayment":{let m=u==null?void 0:u.requestPayment;if(!m)throw x();let E=t==null?void 0:t.amount;if(typeof E!="number"||!Number.isFinite(E)||E<=0)throw new d("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let z={...t,amount:E,currency:At(t==null?void 0:t.currency,"currency")};return nt(e,()=>m(z,y))}case"printImage":{let m=u==null?void 0:u.printImage;if(!m)throw x();let E=At(t==null?void 0:t.image,"image");await nt(e,()=>m({image:E},y));return}case"openScreen":if(!(u!=null&&u.openScreen))throw x();await u.openScreen({screen:At(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},y);return;case"closeApp":a();return;case"openWebview":{let m=String((M=t==null?void 0:t.url)!=null?M:"");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):ot.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 d("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(m):ot.Linking.openURL(m))}catch(E){throw new d("NOT_SUPPORTED",String((ne=(Z=E==null?void 0:E.message)!=null?Z:E)!=null?ne:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let m=Dn(t);if(!m||(g==null?void 0:g())===!1)return;s!=null&&s.showToast?s.showToast(m.message,{type:m.type}):Nn(m.message,m.type);return}case"haptic":{let m=Er.has(t==null?void 0:t.type)?t.type:"selection";(ae=s==null?void 0:s.haptic)==null||ae.call(s,m);return}case"getSystemInfo":return{platform:ot.Platform.OS==="ios"?"ios":"android",appVersion:(Se=s==null?void 0:s.app_version)!=null?Se:"",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 T=n().access_token;if(!T)throw new d("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return T}if(m!=="partner"&&m!=="chatbox")throw new d("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(m)}`);let E=co[m];if(!o().includes(E))throw new d("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${E} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let z=m==="partner"?n().partner_token:n().chatbox_token;if(!z)throw new d("HOST_ERROR",`Kh\xF4ng c\xF3 ${E}`);return z}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 Yt=e=>`bundle:${e}`,Xt=()=>`${q().file_system.document_dir}/miniapps`,Zt=Xt,Qt=(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}},Kt=e=>{var t;q().storage.setString(Yt(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},Rr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,U=e=>{let t=q().storage.getString(Yt(e));if(!t)return null;try{let{version:n,entry:o,context_update:r,permissions:i}=JSON.parse(t);return Qt(e,n,o,!!r,Array.isArray(i)?i:[])}catch{return null}},xe=e=>q().file_system.exists(e.entry_uri.replace("file://","")),en=async e=>{let t=U(e.app_id);return(t==null?void 0:t.version)===e.version&&await xe(t)},mo=async(e,t)=>{let n=q().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(()=>{})))},fo=async e=>{var t;await((t=st[e])==null?void 0:t.catch(()=>{})),q().storage.setString(Yt(e),""),await q().file_system.remove(`${Zt()}/${e}`).catch(()=>{})},He=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},st={},ho=(e,t)=>{var i;let o=((i=st[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return st[e]=r,r.then(()=>{st[e]===r&&delete st[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 l=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(l)return l}return 0},yo=({manifest:e,zip_path:t})=>ho(e.app_id,async()=>{var i;let n=q().file_system,o=U(e.app_id);if(o&&Pr(o.version,e.version)>=0&&await xe(o))return o;if(e.sha256&&n.sha256&&await n.sha256(t)!==e.sha256)throw new Error("sha256 mismatch");let r=Qt(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),Kt(e),pe("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),mo(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),tn=(e,{base_url:t,onProgress:n}={})=>{let o=q().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,l=()=>{if(i)throw new He},c=async()=>{var g;l();let s=U(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return Kt(e),U(e.app_id);l();let p=o.download({url:t?Rr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(w,u)=>{var F;let y=u>0?u:(F=e.size)!=null?F:0;y>0&&(n==null||n(Math.min(1,w/y)))}});r=p;try{let{status:w}=await p.promise;if(l(),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 pe("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);l();let u=Qt(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),Kt(e),mo(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),u}catch(w){throw i?new He:w}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:ho(e.app_id,c),cancel:()=>{i=!0,r==null||r.cancel()}}},it={},Tr=__DEV__?0:60*1e3,go={},wo=(e,t)=>{var o,r;let n=U(e);return n&&Date.now()-((o=go[t])!=null?o:0)<Tr?Promise.resolve(n):((r=it[e])!=null||(it[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 tn(a,{base_url:t}).promise;return go[t]=Date.now(),l})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),U(e))).finally(()=>{it[e]=void 0})),it[e])};var vt=new Map,_o=(e,t)=>(vt.set(e,t),()=>{vt.get(e)===t&&vt.delete(e)}),bo=(e,t)=>{let n=vt.get(e);return n?n(t):!1};var K=require("react"),h=require("react-native");var v=require("react/jsx-runtime"),at="#22C55E",Cr="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",Or=2,xt=18,kr=1600,ct=14,Ir=2e3,Ao=2,Je=2e3,Lr=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:ct},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:ct},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:ct},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:ct}],So=({color:e})=>(0,v.jsx)(v.Fragment,{children:Lr.map((t,n)=>(0,v.jsx)(h.View,{style:[S.corner,t,{borderColor:e}]},n))}),Mt=({style:e,children:t,...n})=>{let o=(0,K.useRef)(new h.Animated.Value(1)).current,r=i=>h.Animated.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return(0,v.jsx)(h.Pressable,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:(0,v.jsx)(h.Animated.View,{style:[e,{transform:[{scale:o}]}],children:t})})},on=({scanner:e})=>{var ve,Me,Pe;let{vision:t,types:n,mode:o,layout:r,hint:i,glass_view:a}=e,l=r===Ae.top,c=t.useCameraDevice("back"),[s,p]=(0,K.useState)(!1),[g,w]=(0,K.useState)(1),[u,y]=(0,K.useState)({width:0,height:0}),F=W(J,k=>k.last_value),x=W(J,k=>k.hit_tick),P=W(J,k=>k.scan_count),M=W(J,k=>k.notice),_=W(J,k=>k.is_picking),Z=(0,K.useRef)(null),[ne,ae]=(0,K.useState)(0),Se=h.Platform.OS==="ios"?54:(ve=h.StatusBar.currentHeight)!=null?ve:0,m=(0,K.useRef)(new h.Animated.Value(0)).current,E=(0,K.useRef)(new h.Animated.Value(0)).current,z=(0,K.useRef)(new h.Animated.Value(0)).current,T=Math.round(u.width*(l?.8:.78)),L=Math.round(l?u.height*.46:T*.78),B=Math.round((u.height-L)/2),G=Math.round((u.width-T)/2),V=t.useCodeScanner({codeTypes:n,onCodeScanned:(0,K.useCallback)(k=>Ht(k),[])});(0,K.useEffect)(()=>{let k=h.BackHandler.addEventListener("hardwareBackPress",()=>(jt(),!0));return()=>k.remove()},[]);let ee=(0,K.useRef)(x);(0,K.useEffect)(()=>{if(x===ee.current)return;m.setValue(1),z.setValue(1);let k=h.Animated.parallel([h.Animated.timing(m,{toValue:0,duration:450,useNativeDriver:!0}),h.Animated.sequence([h.Animated.delay(Ir),h.Animated.timing(z,{toValue:0,duration:250,useNativeDriver:!0})])]);return k.start(),()=>k.stop()},[x,m,z]),(0,K.useEffect)(()=>{let k=Ye=>h.Animated.timing(E,{toValue:Ye,duration:kr,easing:h.Easing.inOut(h.Easing.quad),useNativeDriver:!0}),Ne=h.Animated.loop(h.Animated.sequence([k(1),k(0)]));return Ne.start(),()=>Ne.stop()},[E]);let Re=!!(c!=null&&c.hasTorch),we=(Me=c==null?void 0:c.neutralZoom)!=null?Me:1,oe=c?Math.min(we*g,c.maxZoom):1,De=(0,v.jsx)(h.Text,{style:[S.hint,!!M&&S.hint_notice],numberOfLines:1,children:(Pe=M!=null?M:i)!=null?Pe:Cr});return(0,v.jsxs)(h.View,{ref:Z,style:l?S.top:S.full,onLayout:({nativeEvent:{layout:k}})=>{var Ne;y({width:k.width,height:k.height}),(Ne=Z.current)==null||Ne.measureInWindow((Ye,ut)=>ae(ut))},children:[c&&(0,v.jsx)(t.Camera,{style:h.StyleSheet.absoluteFill,device:c,isActive:!_,codeScanner:V,torch:s&&Re?"on":"off",zoom:oe,enableZoomGesture:!0,onError:k=>Kn(k.message)}),u.height>0&&(0,v.jsxs)(h.View,{style:S.overlay,pointerEvents:"none",children:[(0,v.jsx)(h.View,{style:[S.dim_ring,{top:B-Je,left:G-Je,width:T+Je*2,height:L+Je*2}]}),(0,v.jsxs)(h.View,{style:{position:"absolute",top:B,left:G,width:T,height:L},children:[(0,v.jsx)(So,{color:"#FFFFFF"}),(0,v.jsx)(h.Animated.View,{style:[h.StyleSheet.absoluteFill,{opacity:m}],children:(0,v.jsx)(So,{color:at})}),(0,v.jsxs)(h.Animated.View,{style:[S.scan_line_wrap,{transform:[{translateY:E.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,L-xt)]})}]}],children:[(0,v.jsx)(h.View,{style:S.scan_glow_outer}),(0,v.jsx)(h.View,{style:S.scan_glow_inner}),(0,v.jsx)(h.View,{style:S.scan_line})]})]}),(0,v.jsx)(h.View,{style:[S.hint_slot,l?{top:0,height:B-6,justifyContent:"flex-end"}:{top:B+L+20}],children:De}),o===ze.continuous&&!!F&&(0,v.jsx)(h.Animated.View,{style:[S.result_slot,l?S.result_slot_top:{top:B+L+52},{opacity:z}],children:(0,v.jsxs)(h.View,{style:S.result,children:[(0,v.jsx)(h.View,{style:S.check_badge,children:(0,v.jsx)(h.View,{style:S.check_mark})}),(0,v.jsx)(h.Text,{style:S.result_text,numberOfLines:1,children:F}),(0,v.jsxs)(h.Text,{style:S.result_count,children:["\xB7 ",P," m\xE3"]})]})})]}),(0,v.jsx)(h.View,{style:[S.close_slot,{top:Math.max(12,Se-ne+12)}],children:(0,v.jsxs)(Mt,{style:[S.close_button,!!a&&S.glass_surface],onPress:jt,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[a&&(0,v.jsx)(a,{style:S.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(h.View,{style:[S.close_bar,S.close_bar_a]}),(0,v.jsx)(h.View,{style:[S.close_bar,S.close_bar_b]})]})}),(0,v.jsx)(h.View,{style:[S.toolbar_wrap,!l&&S.toolbar_wrap_full],pointerEvents:"box-none",children:(0,v.jsxs)(h.View,{style:[S.toolbar,!!a&&S.glass_surface],children:[a&&(0,v.jsx)(a,{style:S.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),(0,v.jsx)(Mt,{style:S.tool,onPress:Yn,disabled:_,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:(0,v.jsxs)(h.View,{style:S.image_icon,children:[(0,v.jsx)(h.View,{style:S.image_icon_dot}),(0,v.jsx)(h.View,{style:S.image_icon_hill})]})}),!!c&&c.maxZoom>=we*Ao&&(0,v.jsx)(Mt,{style:[S.tool,g>1&&S.tool_on],onPress:()=>w(k=>k>1?1:Ao),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:(0,v.jsxs)(h.Text,{style:[S.zoom_text,g>1&&S.zoom_text_on],children:[g,"x"]})}),Re&&(0,v.jsx)(Mt,{style:[S.tool,s&&S.tool_on],onPress:()=>p(k=>!k),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:s},children:(0,v.jsx)(h.Text,{style:[S.torch_icon,s&&S.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})},Fr="rgba(0,0,0,0.5)",nn=50,S=h.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:Je,borderColor:Fr,borderRadius:Je+ct},hint_slot:{position:"absolute",left:16,right:16,alignItems:"center"},hint:{color:"#FFFFFF",fontSize:14,fontWeight:"500"},hint_notice:{color:"#FCA5A5"},corner:{position:"absolute",width:28,height:28},scan_line_wrap:{position:"absolute",top:0,left:10,right:10,height:xt,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:xt,borderRadius:xt/2,backgroundColor:at,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:at,opacity:.2},scan_line:{height:Or,borderRadius:1,backgroundColor:at},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar_wrap_full:{bottom:h.Platform.OS==="ios"?34:20},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:nn,height:nn,borderRadius:nn/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result_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:at},check_mark:{width:5,height:9,marginTop:-2,borderRightWidth:2,borderBottomWidth:2,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_text:{flexShrink:1,color:"#FFFFFF",fontWeight:"600",fontSize:13},result_count:{color:"#A1A1AA",fontSize:13}});var fe=require("react"),R=require("react-native");var Y=require("react/jsx-runtime"),Dr={[ue.info]:"#3B82F6",[ue.success]:"#22C55E",[ue.error]:"#EF4444"},vo=-120,Nr=({type:e})=>e===ue.success?(0,Y.jsx)(R.View,{style:re.check_mark}):e===ue.error?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(R.View,{style:[re.cross_bar,re.cross_a]}),(0,Y.jsx)(R.View,{style:[re.cross_bar,re.cross_b]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(R.View,{style:re.info_dot}),(0,Y.jsx)(R.View,{style:re.info_bar})]}),xo=()=>{let e=W(tt,p=>p.message),t=W(tt,p=>p.type),n=W(tt,p=>p.tick),o=(0,fe.useRef)(new R.Animated.Value(vo)).current,r=(0,fe.useRef)(new R.Animated.Value(0)).current,i=(0,fe.useRef)(new R.Animated.Value(.92)).current,a=(0,fe.useRef)(new R.Animated.Value(0)).current,[l,c]=(0,fe.useState)();(0,fe.useEffect)(()=>{let p=!0;return Wt().then(g=>{p&&g&&c(()=>g)}),()=>{p=!1}},[]);let s=(0,fe.useRef)(n);return(0,fe.useEffect)(()=>{if(n===s.current)return;R.AccessibilityInfo.announceForAccessibility(e),a.setValue(0),i.setValue(.92);let p=R.Animated.sequence([R.Animated.parallel([R.Animated.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),R.Animated.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),R.Animated.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),R.Animated.sequence([R.Animated.delay(90),R.Animated.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),R.Animated.delay(Fn[t]),R.Animated.parallel([R.Animated.timing(o,{toValue:vo,duration:240,useNativeDriver:!0}),R.Animated.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return p.start(),()=>p.stop()},[n]),n?(0,Y.jsx)(R.View,{style:re.layer,pointerEvents:"none",children:(0,Y.jsxs)(R.Animated.View,{style:[re.toast,!!l&&re.toast_glass,{opacity:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[l&&(0,Y.jsx)(l,{style:re.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),(0,Y.jsx)(R.Animated.View,{style:[re.badge,{backgroundColor:Dr[t],transform:[{scale:a}]}],children:(0,Y.jsx)(Nr,{type:t})}),(0,Y.jsx)(R.Text,{style:re.message,numberOfLines:2,children:e})]})}):null},Mo,re=R.StyleSheet.create({layer:{position:"absolute",top:(R.Platform.OS==="ios"?54:(Mo=R.StatusBar.currentHeight)!=null?Mo:0)+8,left:16,right:16,alignItems:"center",zIndex:9999,elevation:9999},toast:{maxWidth:"100%",minHeight:50,flexDirection:"row",alignItems:"center",gap:10,paddingLeft:11,paddingRight:18,paddingVertical:11,borderRadius:25,backgroundColor:"#18181B",shadowColor:"#000000",shadowOpacity:.32,shadowRadius:18,shadowOffset:{width:0,height:8},elevation:12},toast_glass:{backgroundColor:"transparent"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ie=Oe({active_key:null,instances:{}}),Eo=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var l;let a=(l=q().keep_alive)==null?void 0:l.max_webviews;ie.setState(c=>{let s=t!=null?t:e.app_id,p={...c.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}})},Ro=e=>Eo(e,!0),Po=e=>Eo(e,!1),Ge=()=>ie.setState({active_key:null}),Et=e=>{ie.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var To="catalog",Ur="paused_apps",Vr="removed_apps",Br=10*1e3,qr=2,$r=3e3,zr=()=>{var e;try{return JSON.parse((e=q().storage.getString(To))!=null?e:"{}")}catch{return{}}},D=Oe({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),Co=e=>{var t;return!!((t=q().manual_update)!=null&&t.includes(e))},Tt=new Set,Oo=e=>{let t=new Set,n=()=>q().storage.setString(e,JSON.stringify([...t]));return{has:o=>t.has(o),values:()=>[...t],add:o=>t.has(o)?!1:(t.add(o),n(),!0),delete:o=>t.delete(o)?(n(),!0):!1,load:()=>{var o;t.clear();try{let r=JSON.parse((o=q().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},ye=Oo(Ur),Fe=Oo(Vr);gn(()=>{ye.load(),Fe.load();let e=zr(),t={};Object.keys(e).filter(n=>!Fe.has(n)).forEach(n=>{let o=U(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:ye.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),D.setState({catalog:e,downloads:t})});var Ct=e=>W(D,t=>e?t.downloads[e]:void 0),ko=()=>W(D,e=>e.pause_reasons.length>0),he=(...e)=>pe("queue",...e),X=[],Ee={},C=null,Rt=new Set,We={},rn=new Set,Ie=e=>{rn.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Io=e=>(rn.add(e),()=>{rn.delete(e)}),Lo=()=>D.getState().downloads,se=(e,t)=>{let n=!!U(e),o=D.getState().downloads[e],r=t.status==="downloading"&&n?"updating":t.status,i={...o!=null?o:{status:"queued",progress:0},...t,...r?{status:r}:{},has_local:n};D.setState(a=>({downloads:{...a.downloads,[e]:i}})),(o==null?void 0:o.status)!==i.status||(o==null?void 0:o.version)!==i.version||(o==null?void 0:o.has_local)!==i.has_local?Ie({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Ie({type:"progress",app_id:e,progress:i.progress,version:i.version})},Pt=(e,t)=>{var n;(n=We[e])==null||n.forEach(o=>o(t)),delete We[e]},Wr=()=>D.getState().pause_reasons.length>0,Le=e=>{var l;if(C)return;let t=e?X.indexOf(e):Wr()?-1:X.findIndex(c=>!ye.has(c));if(t<0||t>=X.length)return;let[n]=X.splice(t,1),o=D.getState().catalog[n];if(!o){Pt(n,U(n)),Le();return}let r=Date.now();Ee[n]=((l=Ee[n])!=null?l:0)+1,se(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=tn(o,{onProgress:c=>{let s=Math.floor(c*100);s!==i&&(i=s,se(n,{progress:s/100,version:o.version}))}});C={app_id:n,handle:a,forced:!!e},he("start",n,o.version,e?"(forced)":""),a.promise.then(c=>{he("installed",n,o.version,`${Date.now()-r}ms`),se(n,{status:"installed",progress:1,version:o.version}),Pt(n,c)}).catch(c=>{var p;if(c instanceof He){if(Rt.has(n))return;he("paused",n),Ee[n]-=1,X.unshift(n),se(n,{status:ye.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((p=c==null?void 0:c.message)!=null?p:c);if(console.warn("[miniapp-queue] failed",n,s),Ee[n]<qr){se(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var g;X.includes(n)||(C==null?void 0:C.app_id)===n||(X.push(n),Le((g=We[n])!=null&&g.length?n:void 0))},$r);return}se(n,{status:"failed",progress:0,version:o.version,error:s}),Pt(n,U(n))}).finally(()=>{C=null;let c=X.find(s=>{var p;return(p=We[s])==null?void 0:p.length});Le(c)})},Ot=(e,{front:t=!1}={})=>{if((C==null?void 0:C.app_id)===e)return;let n=X.indexOf(e);if(n>=0){if(!t)return;X.splice(n,1)}t?X.unshift(e):X.push(e)},jr=async e=>{let{host_id:t,client_token:n}=q(),o=new AbortController,r=setTimeout(()=>o.abort(),Br);try{let i=`${gt}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(c=>({...c,channel:e}))}finally{clearTimeout(r)}},lt=null,kt=()=>(lt!=null||(lt=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(q().channels.map(jr)),o={};[...n].reverse().flat().forEach(c=>{o[c.app_id]=c});let r=Object.keys(D.getState().catalog).filter(c=>!o[c]);q().storage.setString(To,JSON.stringify(o)),D.setState({catalog:o}),await Promise.all(r.map(c=>Fo(c,{by_user:!1}))),r.forEach(c=>Fe.delete(c));let i=Object.keys(o).filter(c=>!Fe.has(c)),a=[],l={};for(let c of i.map(s=>o[s])){if(await en(c)){se(c.app_id,{status:"installed",progress:1,version:c.version});continue}let s=U(c.app_id);if(Co(c.app_id)&&!Tt.has(c.app_id)&&s&&await xe(s)){se(c.app_id,{status:"installed",progress:1,version:s.version}),l[c.app_id]={app_id:c.app_id,current_version:s.version,next_version:c.version};continue}a.push(c)}return D.setState({updates:l}),a.forEach(c=>{Ee[c.app_id]=0,se(c.app_id,{status:ye.has(c.app_id)?"paused":"queued",progress:0,version:c.version,error:void 0}),Ot(c.app_id)}),he("catalog",i.length,"apps, outdated",a.map(c=>c.app_id),"removed",r,`${Date.now()-e}ms`),Ie({type:"sync_complete",app_ids:i,removed:r}),Object.values(l).forEach(c=>Ie({type:"update_available",...c})),Le(),{ok:!0,app_ids:i,removed:r}}catch(n){let o=String((n==null?void 0:n.name)==="AbortError"?"timeout":(t=n==null?void 0:n.message)!=null?t:n);return console.warn("[miniapp-queue] sync catalog failed",o),Ie({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{lt=null}})()),lt),Fo=async(e,{by_user:t})=>{var r,i,a,l;if(t&&Fe.add(e),Rt.has(e))return;Rt.add(e),ye.delete(e);let n=X.indexOf(e);n>=0&&X.splice(n,1),(C==null?void 0:C.app_id)===e&&C.handle.cancel();let o=(l=(a=(r=D.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=U(e))==null?void 0:i.version)!=null?l:"";se(e,{status:"uninstalling",progress:0,version:o}),await fo(e),Et(e),D.setState(c=>{let s={...c.downloads};return delete s[e],{downloads:s}}),delete Ee[e],Rt.delete(e),Pt(e,null),he("uninstalled",e,t?"(user)":"(not in list)"),Ie({type:"uninstalled",app_id:e})},Do=e=>Fo(e,{by_user:!0}),No=e=>{let t=Ke(e);return t?(Fe.delete(e),(C==null?void 0:C.app_id)===e||X.includes(e)||(Ee[e]=0,se(e,{status:ye.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Ot(e),Le(),he("restore",e)),!0):!1},Uo=e=>{if(ye.has(e))return;if(ye.add(e),he("pause app",e),(C==null?void 0:C.app_id)===e&&!C.forced){C.handle.cancel();return}let t=D.getState().downloads[e];X.includes(e)&&t&&se(e,{status:"paused",progress:0,version:t.version})},Vo=e=>{if(!ye.delete(e))return;he("resume app",e);let t=D.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!X.includes(e)&&Ke(e)&&(Ee[e]=0,Ot(e)),X.includes(e)&&t&&se(e,{status:"queued",progress:0,version:t.version}),Le()},Bo=e=>{let{pause_reasons:t}=D.getState();t.includes(e)||(D.setState({pause_reasons:[...t,e]}),he("pause",e),t.length===0&&Ie({type:"pause_change",paused:!0,reasons:[e]}),C&&!C.forced&&C.handle.cancel())},qo=e=>{let{pause_reasons:t}=D.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);D.setState({pause_reasons:n}),he("resume",e),n.length===0&&Ie({type:"pause_change",paused:!1,reasons:n}),Le()},sn=e=>D.getState().updates[e],$o=async e=>{var n,o;let t=sn(e);Tt.add(e);try{let r=await pt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=Ke(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(D.setState(a=>{var c;let l={...a.updates};return delete l[e],{updates:l,apply_ticks:{...a.apply_ticks,[e]:((c=a.apply_ticks[e])!=null?c:0)+1}}}),he("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Tt.delete(e)}},zo=()=>Object.values(D.getState().catalog).map(e=>({...e,installed:!!U(e.app_id),removed_by_user:Fe.has(e.app_id)})),Ke=e=>D.getState().catalog[e],pt=async e=>{let t=Ke(e);if(!t)return;if(ye.delete(e),Fe.delete(e),await en(t))return U(e);let n=U(e);if(Co(e)&&!Tt.has(e)&&n&&await xe(n))return n;let o=new Promise(r=>{var i;((i=We[e])!=null?i:We[e]=[]).push(r)});return(C==null?void 0:C.app_id)===e?C.forced=!0:(Ee[e]=0,Ot(e,{front:!0}),C&&!C.forced?C.handle.cancel():Le(e)),o};var I=require("react/jsx-runtime"),an=e=>(e!=null?e:"").replace(/\?[^#]*/,""),Wo=0,Hr=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},Jr=A.default.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:l,opaque_background:c,allow_embedded_miniapps:s,onWebLoadEnd:p})=>{var Ye,ut;let g=(0,A.useRef)(null),w=(0,A.useRef)(!1),u=W(ie,f=>f.instances[e]),y=u==null?void 0:u.app.app_id,F=u==null?void 0:u.app.manifest_url,x=u==null?void 0:u.context,P=u==null?void 0:u.url_params,M=W(J,f=>{var b;return((b=f.active)==null?void 0:b.owner)===e?f.active:null}),[_,Z]=(0,A.useState)(()=>y?U(y):null),[ne,ae]=(0,A.useState)(!1),[Se,m]=(0,A.useState)(0),[E,z]=(0,A.useState)(0),[T,L]=(0,A.useState)(!1),B=(0,A.useRef)(null),G=f=>{B.current&&clearTimeout(B.current),B.current=setTimeout(()=>{B.current=null,L(!0)},f)};(0,A.useEffect)(()=>()=>{B.current&&clearTimeout(B.current)},[]),(0,A.useEffect)(()=>{if(!y||!t&&_)return;let f=!0;return ae(!1),(async()=>{let b=U(y),te=b?await xe(b):!1;if(!f||(Z(te?me=>!me||me.version!==b.version||me.permissions.join(",")!==b.permissions.join(",")?b:me:null),__DEV__&&Date.now()-Wo>1e4&&(Wo=Date.now(),await kt()),!f))return;let Te=await pt(y),Ue=Te!==void 0?Te:F?await wo(y,F):U(y);if(f){if(!Ue){ae(!0);return}Z(me=>me!=null?me:Ue)}})(),()=>{f=!1}},[t,y,F,Se]),(0,A.useEffect)(()=>_o(e,f=>g.current?(g.current.postMessage(f),!0):!1),[e]);let V=W(D,f=>{let b=y?f.downloads[y]:void 0;return(b==null?void 0:b.status)==="installed"?b.version:void 0});(0,A.useEffect)(()=>{if(t||!y||!_)return;let f=U(y);if(!f||f.version===_.version)return;let b=!0;return xe(f).then(te=>{!b||!te||(pe(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",_.version,"\u2192",f.version),Z(f))}),()=>{b=!1}},[t,y,V,_==null?void 0:_.version]);let ee=W(D,f=>{var b;return y&&(b=f.apply_ticks[y])!=null?b:0});(0,A.useEffect)(()=>{if(!ee||!y)return;let f=U(y);if(!f||f.version===(_==null?void 0:_.version))return;let b=!0;return xe(f).then(te=>{!b||!te||(pe(`webview:${e}`,"c\u1EADp nh\u1EADt",_==null?void 0:_.version,"\u2192",f.version),L(!1),Z(f))}),()=>{b=!1}},[ee]),(0,A.useEffect)(()=>{var te;let f=(te=q().keep_alive)==null?void 0:te.idle_close_ms;if(t||!f||f<=0)return;let b=setTimeout(()=>{Et(e)},f);return()=>clearTimeout(b)},[t,e]),(0,A.useEffect)(()=>{r>0&&(ae(!1),L(!1),z(f=>f+1),m(f=>f+1))},[r]);let Re=(0,A.useRef)(t);(0,A.useEffect)(()=>{var f;Re.current!==t&&(Re.current=t,w.current&&((f=g.current)==null||f.injectJavaScript(ro(t?"resumed":"paused"))))},[t]);let we=`${(Ye=_==null?void 0:_.version)!=null?Ye:"none"}:${(ut=_==null?void 0:_.permissions.join(","))!=null?ut:""}:${E}`,oe=(0,A.useMemo)(()=>JSON.stringify([x!=null?x:{},P!=null?P:{}]),[x,P]),De=(0,A.useMemo)(()=>{var f;return lo(P!=null?P:{},(f=_==null?void 0:_.permissions)!=null?f:[])},[oe,_==null?void 0:_.permissions]),ve=(0,A.useMemo)(()=>ao(x!=null?x:{},De)+no()+(O.Platform.OS==="android"?oo():"")+(q().debug?to():""),[De]),Me=(0,A.useRef)(null),Pe=(0,A.useRef)(null);(0,A.useEffect)(()=>{var b,te,Te;if(!_)return;if(Pe.current!==we){Pe.current=we,Me.current=oe;return}if(Me.current===oe)return;let f=((te=JSON.parse((b=Me.current)!=null?b:"[]")[0])!=null?te:{}).org_id;if(Me.current=oe,f===(x==null?void 0:x.org_id)&&w.current){L(!1),G(1500),(Te=g.current)==null||Te.injectJavaScript(io(x!=null?x:{},De));return}L(!1),z(Ue=>Ue+1)},[oe,_,we]),(0,A.useEffect)(()=>(t||(be(e),ke(e),Be(e)),()=>{be(e),ke(e),Be(e)}),[t,e,we,r]),(0,A.useEffect)(()=>{let f=O.AppState.addEventListener("change",b=>{b==="background"&&!Un()&&be(e),b==="background"&&!zn()&&ke(e)});return()=>f.remove()},[e]);let k=(0,A.useCallback)(async f=>{var te,Te,Ue,me,It;let b=Xn(f.nativeEvent.data);if(!b){if(y&&(l!=null&&l.onWebEvent))try{Promise.resolve(l.onWebEvent(f.nativeEvent.data,{app_id:y,instance_id:e})).catch($=>{console.warn("[miniapp] onWebEvent l\u1ED7i",y,$)})}catch($){console.warn("[miniapp] onWebEvent l\u1ED7i",y,$)}return}if(b.method==="log"){let{level:$,text:j}=b;pe(`web:${e}`,$!=null?$:"log",j!=null?j:"");return}if(b.method==="pong"){B.current||L(!0);return}if(b.method==="touchAtTop"){i.emit(!!b.at_top);return}if(b.method==="contextApplied"){B.current&&clearTimeout(B.current),B.current=null,L(!0);return}if(b.method==="ready"){w.current=!0,L(!0);let $=(te=ie.getState().instances[e])==null?void 0:te.context;$&&((Te=g.current)==null||Te.injectJavaScript(Gt($)));return}try{let $=await uo(b,{getHostData:()=>{var j,ce;return(ce=(j=ie.getState().instances[e])==null?void 0:j.host_data)!=null?ce:{}},getPermissions:()=>{var j,ce;return y?(ce=(j=U(y))==null?void 0:j.permissions)!=null?ce:[]:[]},getContext:()=>{var j,ce;return(ce=(j=ie.getState().instances[e])==null?void 0:j.context)!=null?ce:{}},is_dark:o,close:Ge,app_id:y!=null?y:"",instance_id:e,options:l,emit:(j,ce)=>{var ln;(ln=g.current)==null||ln.injectJavaScript(eo(j,ce))},playBeep:()=>{var j;(j=g.current)==null||j.injectJavaScript(po())},isActive:()=>ie.getState().active_key===e&&O.AppState.currentState!=="background"});b.id&&((Ue=g.current)==null||Ue.injectJavaScript(Zn(b.id,$)))}catch($){if(!b.id)return;let j=$==null?void 0:$.code,ce=$ instanceof d?$:new d(typeof j=="string"?j:"HOST_ERROR",String((me=$==null?void 0:$.message)!=null?me:$));(It=g.current)==null||It.injectJavaScript(Qn(b.id,ce))}},[e,o,y,i,l]),Ne=(0,A.useCallback)(()=>{ae(!1),z(f=>f+1),m(f=>f+1)},[]);return(0,I.jsxs)(O.View,{style:[O.StyleSheet.absoluteFill,c&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&ge.behind],pointerEvents:t?"auto":"none",children:[(M==null?void 0:M.layout)===Ae.top&&(0,I.jsx)(on,{scanner:M}),_?(0,I.jsx)(Ho.default,{ref:g,source:{uri:_.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?Xt():_.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:ve,onMessage:k,bounces:!1,overScrollMode:"never",onLoadStart:f=>{be(e),ke(e),Be(e),pe(`webview:${e}`,"load start",an(f.nativeEvent.url)),w.current=!1,L(!1)},onError:f=>{be(e),ke(e),Be(e),pe(`webview:${e}`,"load error",an(f.nativeEvent.url),f.nativeEvent.description),ae(!0),L(!1)},onLoadEnd:f=>{let b=f.nativeEvent.url;pe(`webview:${e}`,"load end",an(b)),y&&(p==null||p({app_id:y,instance_id:e,url:b})),G(1500)},onContentProcessDidTerminate:()=>{be(e),ke(e),Be(e),w.current=!1,L(!1),z(f=>f+1)},onRenderProcessGone:()=>(be(e),ke(e),Be(e),w.current=!1,L(!1),z(f=>f+1),!0),style:ge.webview},we):null,(M==null?void 0:M.layout)===Ae.full&&(0,I.jsx)(on,{scanner:M}),u&&(0,I.jsx)(Kr,{visible:!_||!T,interactive:ne,children:(0,I.jsx)(Gr,{splash:a,app:u.app,is_dark:o,error:ne,has_bundle:!!_,retry:Ne})})]})}),Gr=A.default.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,l=Ct(t.app_id),c=o?"error":!r&&(l==null?void 0:l.status)==="downloading"?"downloading":"loading";return(0,I.jsx)(a,{app:t,is_dark:n,status:c,progress:c==="downloading"?l==null?void 0:l.progress:void 0,retry:i})}),Kr=({visible:e,interactive:t,children:n})=>{let o=(0,A.useRef)(new O.Animated.Value(e?1:0)).current,[r,i]=(0,A.useState)(e);return(0,A.useEffect)(()=>{if(e){i(!0),o.setValue(1);return}let a=O.Animated.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:l})=>{l&&i(!1)}),()=>a.stop()},[e,o]),r?(0,I.jsx)(O.Animated.View,{style:[O.StyleSheet.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},cn=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return(0,I.jsxs)(O.View,{style:[ge.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[(0,I.jsx)(O.View,{style:[ge.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?(0,I.jsx)(O.Image,{source:{uri:e.icon},style:ge.splash_icon_image}):(0,I.jsx)(O.Text,{style:ge.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),(0,I.jsx)(O.Text,{style:[ge.splash_name,{color:i}],children:e.name}),n==="error"?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(O.Text,{style:ge.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),(0,I.jsx)(O.TouchableOpacity,{activeOpacity:.7,style:[ge.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:(0,I.jsx)(O.Text,{style:[ge.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(O.ActivityIndicator,{style:ge.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&(0,I.jsxs)(O.Text,{style:ge.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},jo=(e,t)=>{let n=(0,A.useRef)(t),o=(0,A.useRef)(!1);__DEV__&&!o.current&&n.current!==t&&(o.current=!0,console.warn(`[miniapp] MiniAppHost prop "${e}" \u0111\u1ED5i gi\u1EEFa c\xE1c l\u1EA7n render \u2192 m\u1ECDi WebView b\u1ECB mount l\u1EA1i. Khai b\xE1o component b\xEAn ngo\xE0i render.`))},Yr=({container:e,splash:t=cn,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:l})=>{jo("container",e),jo("splash",t);let c=e,s=W(ie,M=>M.active_key),p=(0,A.useRef)(s);s&&(p.current=s);let g=W(ie,M=>Object.keys(M.instances).join("|")),w=W(ie,M=>{var _;return M.active_key?(_=M.instances[M.active_key])==null?void 0:_.app.name:void 0}),u=(0,A.useMemo)(()=>g?g.split("|"):[],[g]),[y,F]=(0,A.useState)({}),x=(0,A.useRef)(Hr()).current;(0,A.useEffect)(()=>{if(!s||!r)return;let M=O.BackHandler.addEventListener("hardwareBackPress",()=>(Ge(),!0));return()=>M.remove()},[s,r]);let P=(0,A.useCallback)(()=>{let M=ie.getState().active_key;M&&F(_=>({..._,[M]:(_[M]||0)+1}))},[]);return u.length?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(c,{visible:!!s,title:w!=null?w:"",is_dark:n,close:Ge,reload:P,subscribeWebAtTop:x.subscribe,children:u.map(M=>(0,I.jsx)(Jr,{instance_key:M,is_active:s===M,is_front:(s!=null?s:p.current)===M,is_dark:n,reload_tick:y[M]||0,web_at_top:x,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:l},M))}),(0,I.jsx)(xo,{})]}):null},ge=O.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"}}),Jo=A.default.memo(Yr);0&&(module.exports={CodeType,DefaultMiniAppSplash,MINIAPP_PLATFORM_URL,MiniAppHost,MiniAppHostError,ScannerEndReason,ScannerEvent,ScannerLayout,ScannerMethod,ToastType,closeMiniApp,configureMiniApp,createMmkvStorage,createReactNativeBiometrics,createRnfsFileSystem,ensureMiniApp,getLocalMiniApp,getMiniAppCatalog,getMiniAppCatalogEntry,getMiniAppStatuses,getMiniAppUpdate,installBundledMiniApp,onMiniAppEvent,openMiniApp,pauseMiniApp,pauseMiniAppDownloads,preloadMiniApp,releaseSpeechFor,restoreMiniApp,resumeMiniApp,resumeMiniAppDownloads,sendEventToWeb,syncMiniAppCatalog,uninstallMiniApp,updateMiniApp,uploadToUrl,useMiniAppDownload,useMiniAppDownloadsPaused});
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Pt="https://retion-miniapp-platform.vercel.app",ke=null,cn=new Set,To=e=>{ke=e,cn.forEach(t=>t())},F=()=>{if(!ke)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return ke},ln=e=>{cn.add(e),ke&&e()},re=(...e)=>{ke!=null&&ke.debug&&console.log("[miniapp]",...e)};var ko=(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:c}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:l,contentLength:a})=>r==null?void 0:r(l,a)});return{promise:c.then(({statusCode:l})=>({status:l})),cancel:()=>e.stopDownload(i)}}}),Lo=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});import rn,{useCallback as nn,useEffect as te,useMemo as xt,useRef as ue,useState as Ne}from"react";import{AppState as Eo,ActivityIndicator as Jr,Animated as en,BackHandler as Kr,Image as Gr,Platform as Yr,StyleSheet as sn,Text as it,TouchableOpacity as Xr,View as on}from"react-native";import Zr from"react-native-webview";import{Linking as Jn,Platform as cr}from"react-native";var pn=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),ct,Rt=()=>(ct||(ct=import("react-native-biometrics").then(({default:e})=>pn(new e({allowDeviceCredentials:!1}))).catch(e=>{throw ct=void 0,new u("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),ct);import{PermissionsAndroid as Le,Platform as Io}from"react-native";var un=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,c,l]of[["timeout",1,6e4],["maximumAge",0,864e5]]){let a=t[i];if(a!==void 0&&(typeof a!="number"||!Number.isFinite(a)||a<c||a>l))throw new u("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${c}\u2013${l} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},dn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(a,s)=>{r||(r=!0,clearTimeout(c),a?o(a):n(s))},c=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=()=>r?!1:t()?!0:(i(new u("CANCELLED","Mini app kh\xF4ng c\xF2n ho\u1EA1t \u0111\u1ED9ng")),!1);(async()=>{if(!l())return;let a;try{a=(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(Io.OS==="android"){let s=Le.PERMISSIONS.ACCESS_FINE_LOCATION,d=Le.PERMISSIONS.ACCESS_COARSE_LOCATION,g=await Le.check(s);if(!l())return;let w=g||await Le.check(d);if(!l())return;if(!g&&!w){let p=await Le.requestMultiple([s,d]);if(!l())return;if(p[s]!==Le.RESULTS.GRANTED&&p[d]!==Le.RESULTS.GRANTED)throw new u("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n truy c\u1EADp v\u1ECB tr\xED")}}l()&&a.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(a=>i(a))});import{Platform as An}from"react-native";var Ct=20,gn=20,_n=/^[a-z][a-z0-9_-]{0,31}$/,Fo=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,Do=["low","medium","high"],Me=e=>!!e&&typeof e=="object"&&!Array.isArray(e),V=e=>new u("INVALID_PARAMS",e),Je=(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 V(`${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 V("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 V("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(c=>typeof c!="string"||!Fo.test(c))))throw V("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,Ct))throw V(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Ct}`);if(t.max_size!==void 0&&!Je(t.max_size,1,Number.MAX_SAFE_INTEGER))throw V("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!Je(t.concurrency,1,5))throw V("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(c=>c.toLowerCase()),max_count:(r=t.max_count)!=null?r:1,max_size:t.max_size,process:No(t.process),target:Uo(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},No=e=>{if(e===void 0)return{};if(!Me(e))throw V("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Me(n))throw V("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 V(`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 V("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 V("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!Je(n.max_duration,1,3600))throw V("process.video.max_duration ph\u1EA3i l\xE0 s\u1ED1 gi\xE2y 1\u20133600");if(n.quality!==void 0&&!Do.includes(n.quality))throw V("process.video.quality ph\u1EA3i l\xE0 low | medium | high");t.video={max_duration:n.max_duration,quality:n.quality}}return t},Uo=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Me(e))throw V("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!_n.test(t))throw V("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 V("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 V("upload.url ph\u1EA3i l\xE0 https");for(let c of["field_name","url_field"])if(e[c]!==void 0&&(typeof e[c]!="string"||!e[c]))throw V(`upload.${c} 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():""},Vo=(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)},Bo=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,qo=()=>(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),fn=e=>async({accept:t,max_count:n,process:o})=>{var a,s,d,g,w,p,h,O,v;let r=await qo(),i=Bo(t),c={mediaType:i==="image"?"photo":i,maxWidth:(a=o.image)==null?void 0:a.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(g=(d=o.image)==null?void 0:d.quality)!=null?g:.8,videoQuality:(p=(w=o.video)==null?void 0:w.quality)!=null?p:"medium",durationLimit:(h=o.video)==null?void 0:h.max_duration,assetRepresentationMode:"compatible"},l=e==="camera"?await r.launchCamera({...c,saveToPhotos:!1}):await r.launchImageLibrary({...c,selectionLimit:n});if(l.didCancel)return[];if(l.errorCode){let x=l.errorCode==="permission"?"PERMISSION_DENIED":l.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new u(x,(O=l.errorMessage)!=null?O:l.errorCode)}return((v=l.assets)!=null?v:[]).filter(x=>x.uri).map((x,S)=>{var A,z,Y;return{uri:x.uri,name:(A=x.fileName)!=null?A:`file_${S+1}`,mime_type:(z=x.type)!=null?z:"application/octet-stream",size:x.fileSize,width:x.width,height:x.height,duration:x.duration,processed:!((Y=x.type)!=null&&Y.startsWith("video/"))||An.OS==="ios"}})},$o={"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"},zo={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},Wo=e=>async({accept:t,max_count:n})=>{var i,c,l,a;let o=t.map(s=>{var d;return(d=$o[s])!=null?d:zo[s]}),r=!t.length||o.some(s=>!s||!e.types[s])?e.types.allFiles:[...new Set(o)].flatMap(s=>e.types[s]);try{let d=(await e.pick({type:r,allowMultiSelection:n>1,mode:"import"})).filter(p=>p.uri&&!p.error).map((p,h)=>{var O,v,x;return{uri:p.uri,name:(O=p.name)!=null?O:`file_${h+1}`,mime_type:(v=p.type)!=null?v:"application/octet-stream",size:(x=p.size)!=null?x:void 0}});if(An.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"}),w=new Map(g.map(p=>[p.sourceUri,p.status==="success"?p.localUri:void 0]));return d.map(p=>{var h;return{...p,uri:(h=w.get(p.uri))!=null?h:p.uri}})}catch(s){let d=s==null?void 0:s.code;if(d===((c=(i=e.errorCodes)==null?void 0:i.OPERATION_CANCELED)!=null?c:"OPERATION_CANCELED"))return[];throw d===((a=(l=e.errorCodes)==null?void 0:l.IN_PROGRESS)!=null?a:"ASYNC_OP_IN_PROGRESS")?new u("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},je,jo=async e=>(je!=null||(je=import("@react-native-documents/picker").then(t=>Wo(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)),vn={library:fn("library"),camera:fn("camera"),document:jo},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"]}]},He,Mn=()=>(He!=null||(He=import("react-native-compressor").catch(()=>(He=void 0,null))),He),xn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},Ho=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),Jo={low:640,medium:1280,high:1920},Ko=async(e,{image:t})=>{var o;if(!t||!Ho.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}},Go=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:Jo[(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:Ko,video:Go},Xo=(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 u("INVALID_PARAMS","Thi\u1EBFu upload.url"));return}let c=t;if(o.aborted){i(new u("CANCELLED","\u0110\xE3 hu\u1EF7 upload"));return}let l=new XMLHttpRequest,a=new FormData;Object.entries(c.form_data).forEach(([g,w])=>a.append(g,w)),a.append(c.field_name,{uri:e.uri,name:e.name,type:e.mime_type});let s=()=>l.abort();o.addEventListener("abort",s);let d=g=>{o.removeEventListener("abort",s),g()};l.open("POST",c.url),Object.entries(c.headers).forEach(([g,w])=>l.setRequestHeader(g,w)),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 w=Xo(g,c.url_field);if(typeof w!="string"||!w){i(new u("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${c.url_field}"`));return}r({url:w,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(a)}),Pn=e=>{var o,r;let t={...vn};for(let[i,c]of Object.entries((o=e==null?void 0:e.sources)!=null?o:{}))c?t[i]=c:delete t[i];let n={url:En};for(let[i,c]of Object.entries((r=e==null?void 0:e.targets)!=null?r:{}))i!=="url"&&c&&(n[i]=c);return{sources:t,targets:n}},Rn=e=>{let{sources:t,targets:n}=Pn(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:Ct}},pt=new Map,Cn=(e,t)=>`${e}:${t}`,Zo=0,On=(e,t)=>{var n;typeof t=="string"&&((n=pt.get(Cn(e,t)))==null||n.abort())},Ie=e=>{for(let[t,n]of pt)t.startsWith(`${e}:`)&&n.abort()},lt=()=>new u("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),Qo=(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 a;let{sources:n,targets:o}=Pn(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 c=new AbortController,l=Cn(t.instance_id,(a=t.task_id)!=null?a:`auto-${++Zo}`);pt.set(l,c);try{return await er(e,t,r,i,c.signal)}finally{pt.delete(l)}},er=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:c,exclusivePick:l=g=>g()},a,s,d)=>{var X,ae,m;let g={app_id:n!=null?n:"",instance_id:t,context:{...(X=o==null?void 0:o())!=null?X:{}}},w=(await l(()=>a({accept:e.accept,max_count:e.max_count,process:e.process,caller:g}))).slice(0,e.max_count);if(d.aborted)throw lt();if(!w.length)throw new u("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let p=[],h=w.filter(y=>Vo(y,e.accept)?!0:(p.push({name:y.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${y.mime_type||Sn(y.name)}`}),!1)),O=h.map(()=>0),v=h.map(y=>{var M;return(M=y.size)!=null?M:0}),x=0,S=0,A=(y=!1)=>{if(!c||!r)return;let M=Date.now();if(!y&&M-S<200)return;S=M;let C=v.reduce((L,K)=>L+K,0),q=O.reduce((L,K)=>L+K,0);c("upload.progress",{task_id:r,loaded:q,total:C,percent:C?Math.min(100,Math.round(q/C*100)):0,done_count:x,count:h.length})},z=[],Y=0,ne=async()=>{var y,M,C;for(;Y<h.length;){let q=Y++,L=h[q];try{if(d.aborted)throw lt();let K=L.mime_type.startsWith("image/")?"image":L.mime_type.startsWith("video/")?"video":void 0,be=K&&!L.processed?(M=(y=i==null?void 0:i.processors)==null?void 0:y[K])!=null?M:Yo[K]:void 0;if(be&&(L=await be(L,e.process),v[q]=(C=L.size)!=null?C:v[q],d.aborted))throw lt();if(e.max_size&&L.size&&L.size>e.max_size)throw new u("FILE_TOO_LARGE",`File ${L.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let de=(he,Se)=>{O[q]=he,Se&&(v[q]=Se),A()},Z=await s({file:L,target:e.target,onProgress:de,signal:d,caller:g});if(typeof(Z==null?void 0:Z.url)!="string"||!Z.url)throw new u("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:Ce,...fe}=Z;z[q]={url:Ce,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}:{}},O[q]=v[q]}catch(K){p.push(Qo(h[q].name,K))}finally{x++,A(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,h.length)},ne)),d.aborted)throw lt();let me=z.filter(y=>!!y);if(!me.length){let y=p[0];throw new u((ae=y==null?void 0:y.code)!=null?ae:"UPLOAD_FAILED",(m=y==null?void 0:y.message)!=null?m:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:me,failed:p}};import{Platform as Un}from"react-native";import{AppState as kn,Platform as Tt}from"react-native";var ie,Ln=()=>Tt.OS==="android"&&!!(ie!=null&&ie.requesting_permission),tr=1500,ut=()=>new Promise(e=>{if(Tt.OS!=="android"||kn.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,tr),o=kn.addEventListener("change",r=>{r==="active"&&t()})}),Ot=e=>{var t;if(ie===e&&(ie=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,c,l,a,s;if(ie)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:[]};ie=r;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(r.native=g,r.cancelled||!o())throw new u("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 ut(),r.cancelled||!o())throw new u("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!w.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",p=>{var h,O;ie!==r||r.cancelled||n(p.isFinal?"speech.final":"speech.partial",{...p,text:(O=(h=p.results[0])==null?void 0:h.transcript)!=null?O:""})}),g.addListener("error",p=>{ie===r&&!r.cancelled&&n("speech.error",{...p,code:p.error})}),g.addListener("end",()=>{ie===r&&(Ot(r),n("speech.end"))})),r.started=!0,g.start({lang:(i=t.lang)!=null?i:"vi-VN",continuous:(c=t.continuous)!=null?c:!0,interimResults:(l=t.interimResults)!=null?l:!0,addsPunctuation:(a=t.addsPunctuation)!=null?a:!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 Ot(r),d}},Fn=e=>{let t=ie;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},ye=e=>{let t=ie;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{Ot(t)}};import{useRef as nr,useSyncExternalStore as or}from"react";var 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)})}},W=(e,t,n=Object.is)=>{let o=nr(null),r=()=>{let i=e.getState(),c=o.current;if(c&&c.state===i&&c.selector===t)return c.value;let l=t(i),a=c&&n(c.value,l)?c.value:l;return o.current={state:i,selector:t,value:a},a};return or(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"},J={...Dn,all:Object.values(Dn)},Ke={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},Lt={result:"scanner.result",end:"scanner.end"},Ve={user:"user",web:"web",closed:"closed",error:"error"},we={top:"top",full:"full"},Fe={once:"once",continuous:"continuous"},rr=1500,Nn=6e4,k,B=Ue({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),Vn=()=>Un.OS==="android"&&!!(k!=null&&k.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(c=>J.all.includes(c)))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>Nn)throw new u("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 u("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 u("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");i.layout=r}return i},Ft=e=>k!==e?!1:(k=void 0,B.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Bn=async(e,t)=>{if(k)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");k=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 ut(),n(),r!=="granted")throw new u("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera");if(!o.Camera.getAvailableCameraDevices().some(c=>c.position==="back"))throw new u("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await ir();n(),B.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw Ft(e),o}},ir=async()=>{if(Un.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},qn=(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:rr,hint:n.hint,layout:t===Fe.once?we.full:(i=n.layout)!=null?i:we.top,cancelled:!1,requesting_permission:!1,last_seen:new Map}},$n=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let c=qn(e,Fe.once,t);c.onHit=o,c.resolve=r,c.reject=i,Bn(c,n).catch(i)}),zn=(e,t,n,o=()=>!0,r)=>{let i=qn(e,Fe.continuous,t);return i.emit=n,i.onHit=r,Bn(i,o)},dt=(e,t,n)=>{var o,r;if(!B.getState().active){e.cancelled=!0;return}if(Ft(e)){if(e.mode===Fe.once){(o=e.reject)==null||o.call(e,t===Ve.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,Lt.end,n?{reason:t,message:n}:{reason:t})}},Wn=e=>{(k==null?void 0:k.owner)===e&&dt(k,Ve.web)},xe=e=>{(k==null?void 0:k.owner)===e&&dt(k,Ve.closed)},Dt=()=>{k&&dt(k,Ve.user)},jn=e=>{k&&dt(k,Ve.error,e)},Nt=(e,t=Date.now(),n=!1)=>{var r,i,c;let o=k;if(!(!o||!B.getState().active))for(let{value:l,type:a}of e){if(!l)continue;let s=o.last_seen.get(l);if(!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if(o.last_seen.set(l,t),(r=o.onHit)==null||r.call(o),o.mode===Fe.once){Ft(o),(i=o.resolve)==null||i.call(o,{value:l,type:a});return}B.setState(d=>({last_value:l,hit_tick:d.hit_tick+1,scan_count:d.scan_count+1,notice:null})),(c=o.emit)==null||c.call(o,Lt.result,{value:l,type:a})}}},sr={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},ar=2500,kt=e=>{B.setState({notice:e}),setTimeout(()=>{B.getState().notice===e&&B.setState({notice:null})},ar)},Hn=async()=>{var t,n;let e=k;if(!(!e||B.getState().is_picking)){e.requesting_permission=!0,B.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||k!==e)return;if(r.errorCode||!i){kt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:c}=await import("@react-native-ml-kit/barcode-scanning"),l=await c.scan(i);if(k!==e)return;let a=l.map(({value:s,format:d})=>({value:s,code_type:sr[d]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:d})=>({value:s,type:d!=null?d:"unknown"}));if(!a.length){kt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}Nt(a,Date.now(),!0)}catch{k===e&&kt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await ut(),e.requesting_permission=!1,k===e&&B.setState({is_picking:!1})}}};var mt=1,u=class extends Error{constructor(n,o){super(o);this.code=n}},Kn=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===mt&&typeof t.method=="string"?t:null}catch{return null}},Ye=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,Gn=(e,t)=>Ye({id:e,result:t}),Yn=(e,t)=>Ye({id:e,error:{code:t.code,message:t.message}}),Xn=(e,t)=>Ye({event:e,data:t}),Vt=e=>Ye({event:"context",data:e});var Zn=()=>`(function () {
|
|
1
|
+
var Lt="https://retion-miniapp-platform.vercel.app",Ne=null,wn=new Set,Go=e=>{Ne=e,wn.forEach(t=>t())},D=()=>{if(!Ne)throw new Error("[miniapp] Ch\u01B0a g\u1ECDi configureMiniApp()");return Ne},_n=e=>{wn.add(e),Ne&&e()},ae=(...e)=>{Ne!=null&&Ne.debug&&console.log("[miniapp]",...e)};var Ko=(e,t)=>({document_dir:e.DocumentDirectoryPath,cache_dir:e.CachesDirectoryPath,exists:n=>e.exists(n),mkdir:n=>e.mkdir(n),remove:n=>e.unlink(n).catch(()=>{}),listDir:n=>e.readDir(n).then(o=>o.map(r=>r.name)).catch(()=>[]),sha256:n=>e.hash(n,"sha256"),unzip:async(n,o)=>{await t(n,o)},download:({url:n,to_file:o,onProgress:r})=>{let{jobId:i,promise:a}=e.downloadFile({fromUrl:n,toFile:o,progressInterval:250,begin:()=>{},progress:({bytesWritten:l,contentLength:c})=>r==null?void 0:r(l,c)});return{promise:a.then(({statusCode:l})=>({status:l})),cancel:()=>e.stopDownload(i)}}}),Yo=e=>({getString:t=>e.getString(t),setString:(t,n)=>e.set(t,n)});import fn,{useCallback as dn,useEffect as re,useMemo as kt,useRef as me,useState as $e}from"react";import{AppState as Wo,ActivityIndicator as wi,Animated as pn,BackHandler as _i,Image as bi,Platform as Ai,StyleSheet as hn,Text as gt,TouchableOpacity as Si,View as gn}from"react-native";import vi from"react-native-webview";import{Linking as so,Platform as xr}from"react-native";var bn=e=>({getAvailability:()=>e.isSensorAvailable(),authenticate:({reason:t,cancelButtonText:n})=>e.simplePrompt({promptMessage:t,cancelButtonText:n,fallbackPromptMessage:""})}),ft,Ft=()=>(ft||(ft=import("react-native-biometrics").then(({default:e})=>bn(new e({allowDeviceCredentials:!1}))).catch(e=>{throw ft=void 0,new d("NOT_SUPPORTED",`Biometric native module unavailable: ${e instanceof Error?e.message:String(e)}`)})),ft);import{PermissionsAndroid as Ue,Platform as Xo}from"react-native";var An=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,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 d("INVALID_PARAMS",`${i} ph\u1EA3i n\u1EB1m trong kho\u1EA3ng ${a}\u2013${l} ms`)}return{enableHighAccuracy:(n=t.enableHighAccuracy)!=null?n:!1,timeout:(o=t.timeout)!=null?o:15e3,maximumAge:(r=t.maximumAge)!=null?r:0}},Sn=(e,t=()=>!0)=>new Promise((n,o)=>{let r=!1,i=(c,s)=>{r||(r=!0,clearTimeout(a),c?o(c):n(s))},a=setTimeout(()=>i(new d("TIMEOUT","H\u1EBFt th\u1EDDi gian ch\u1EDD c\u1EA5p quy\u1EC1n/l\u1EA5y v\u1ECB tr\xED")),12e4+e.timeout),l=()=>r?!1:t()?!0:(i(new d("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 d("NOT_SUPPORTED","Ch\u01B0a c\xF3 module v\u1ECB tr\xED trong b\u1EA3n native")}if(l()){if(Xo.OS==="android"){let s=Ue.PERMISSIONS.ACCESS_FINE_LOCATION,p=Ue.PERMISSIONS.ACCESS_COARSE_LOCATION,g=await Ue.check(s);if(!l())return;let y=g||await Ue.check(p);if(!l())return;if(!g&&!y){let u=await Ue.requestMultiple([s,p]);if(!l())return;if(u[s]!==Ue.RESULTS.GRANTED&&u[p]!==Ue.RESULTS.GRANTED)throw new d("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 p=(g={1:"PERMISSION_DENIED",2:"POSITION_UNAVAILABLE",3:"TIMEOUT"}[s.code])!=null?g:"LOCATION_ERROR";i(new d(p,s.message))},e)}})().catch(c=>i(c))});import{Platform as Tn}from"react-native";var Dt=20,vn=20,Cn=/^[a-z][a-z0-9_-]{0,31}$/,Zo=/^(\.[\w-]{1,16}|[\w.+-]+\/(\*|[\w.+-]+))$/,Qo=["low","medium","high"],Pe=e=>!!e&&typeof e=="object"&&!Array.isArray(e),$=e=>new d("INVALID_PARAMS",e),Qe=(e,t,n)=>typeof e=="number"&&Number.isInteger(e)&&e>=t&&e<=n,Mn=(e,t)=>{if(e===void 0)return{};if(!Pe(e)||Object.keys(e).length>vn||Object.values(e).some(n=>typeof n!="string"))throw $(`${t} ph\u1EA3i l\xE0 object chu\u1ED7i (t\u1ED1i \u0111a ${vn} key)`);return e},On=e=>{var n,o,r,i;if(e!==void 0&&!Pe(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"||!Cn.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"||!Zo.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&&!Qe(t.max_count,1,Dt))throw $(`max_count ph\u1EA3i l\xE0 s\u1ED1 nguy\xEAn 1\u2013${Dt}`);if(t.max_size!==void 0&&!Qe(t.max_size,1,Number.MAX_SAFE_INTEGER))throw $("max_size ph\u1EA3i l\xE0 s\u1ED1 byte > 0");if(t.concurrency!==void 0&&!Qe(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:er(t.process),target:tr(t.upload),concurrency:(i=t.concurrency)!=null?i:3}},er=e=>{if(e===void 0)return{};if(!Pe(e))throw $("process ph\u1EA3i l\xE0 object");let t={};if(e.image!==void 0){let n=e.image;if(!Pe(n))throw $("process.image ph\u1EA3i l\xE0 object");for(let o of["max_width","max_height"])if(n[o]!==void 0&&!Qe(n[o],1,1e4))throw $(`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(!Pe(n))throw $("process.video ph\u1EA3i l\xE0 object");if(n.max_duration!==void 0&&!Qe(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&&!Qo.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},tr=e=>{var n,o,r,i;if(e===void 0)return{target:"host",params:{}};if(!Pe(e))throw $("upload ph\u1EA3i l\xE0 object");let t=(n=e.target)!=null?n:"host";if(typeof t!="string"||!Cn.test(t))throw $("upload.target ph\u1EA3i l\xE0 t\xEAn \u0111\xEDch, vd host | url");if(t!=="url"){if(e.params!==void 0&&!Pe(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: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"}},kn=e=>{let t=e.lastIndexOf(".");return t>0?e.slice(t).toLowerCase():""},nr=(e,t)=>{if(!t.length)return!0;let n=e.mime_type.toLowerCase(),o=kn(e.name);return t.some(r=>r==="*/*"?!0:r.startsWith(".")?r===o:r.endsWith("/*")?n.startsWith(r.slice(0,-1)):n===r)},or=e=>{let t=e.length>0&&e.every(o=>o.startsWith("image/")),n=e.length>0&&e.every(o=>o.startsWith("video/"));return t?"image":n?"video":"mixed"},Ye,rr=()=>(Ye!=null||(Ye=import("react-native-image-picker").catch(e=>{throw Ye=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)}`)})),Ye),xn=e=>async({accept:t,max_count:n,process:o})=>{var c,s,p,g,y,u,h,C,S;let r=await rr(),i=or(t),a={mediaType:i==="image"?"photo":i,maxWidth:(c=o.image)==null?void 0:c.max_width,maxHeight:(s=o.image)==null?void 0:s.max_height,quality:(g=(p=o.image)==null?void 0:p.quality)!=null?g:.8,videoQuality:(u=(y=o.video)==null?void 0:y.quality)!=null?u:"medium",durationLimit:(h=o.video)==null?void 0:h.max_duration,assetRepresentationMode:"compatible"},l=e==="camera"?await r.launchCamera({...a,saveToPhotos:!1}):await r.launchImageLibrary({...a,selectionLimit:n});if(l.didCancel)return[];if(l.errorCode){let M=l.errorCode==="permission"?"PERMISSION_DENIED":l.errorCode==="camera_unavailable"?"NOT_SUPPORTED":"HOST_ERROR";throw new d(M,(C=l.errorMessage)!=null?C:l.errorCode)}return((S=l.assets)!=null?S:[]).filter(M=>M.uri).map((M,A)=>{var w,G,Q;return{uri:M.uri,name:(w=M.fileName)!=null?w:`file_${A+1}`,mime_type:(G=M.type)!=null?G:"application/octet-stream",size:M.fileSize,width:M.width,height:M.height,duration:M.duration,processed:!((Q=M.type)!=null&&Q.startsWith("video/"))||Tn.OS==="ios"}})},ir={"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"},sr={".pdf":"pdf",".txt":"plainText",".csv":"csv",".json":"json",".zip":"zip",".doc":"doc",".docx":"docx",".xls":"xls",".xlsx":"xlsx",".ppt":"ppt",".pptx":"pptx"},ar=e=>async({accept:t,max_count:n})=>{var i,a,l,c;let o=t.map(s=>{var p;return(p=ir[s])!=null?p:sr[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 C,S,M;return{uri:u.uri,name:(C=u.name)!=null?C:`file_${h+1}`,mime_type:(S=u.type)!=null?S:"application/octet-stream",size:(M=u.size)!=null?M:void 0}});if(Tn.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"}),y=new Map(g.map(u=>[u.sourceUri,u.status==="success"?u.localUri:void 0]));return p.map(u=>{var h;return{...u,uri:(h=y.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===((c=(l=e.errorCodes)==null?void 0:l.IN_PROGRESS)!=null?c:"ASYNC_OP_IN_PROGRESS")?new d("BUSY","\u0110ang m\u1EDF tr\xECnh ch\u1ECDn file kh\xE1c"):s}},Xe,cr=async e=>(Xe!=null||(Xe=import("@react-native-documents/picker").then(t=>ar(t)).catch(t=>{throw Xe=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 Xe)(e)),In={library:xn("library"),camera:xn("camera"),document:cr},En={type:"image",label:"\u1EA2nh",accept:["image/*"]},Rn={type:"video",label:"Video",accept:["video/*"]},Pn={library:[En,Rn],camera:[En,Rn],document:[{type:"any",label:"M\u1ECDi file",accept:[]},{type:"pdf",label:"PDF",accept:["application/pdf"]},{type:"word",label:"Word",accept:[".doc",".docx"]},{type:"excel",label:"Excel",accept:[".xls",".xlsx"]},{type:"powerpoint",label:"PowerPoint",accept:[".ppt",".pptx"]}]},Ze,Ln=()=>(Ze!=null||(Ze=import("react-native-compressor").catch(()=>(Ze=void 0,null))),Ze),Fn=async(e,t,n)=>{try{return Number(await e.getFileSize(t))||n}catch{return n}},lr=new Set(["image/jpeg","image/jpg","image/heic","image/heif","image/webp"]),pr={low:640,medium:1280,high:1920},ur=async(e,{image:t})=>{var o;if(!t||!lr.has(e.mime_type.toLowerCase()))return e;let n=await Ln();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 Fn(n,r,e.size),processed:!0}}catch{return e}},dr=async(e,{video:t})=>{var o;let n=await Ln();if(!n)return e;try{let r=await n.Video.compress(e.uri,{compressionMethod:"auto",maxSize:pr[(o=t==null?void 0:t.quality)!=null?o:"medium"],minimumFileSizeForCompress:2});return{...e,uri:r,mime_type:"video/mp4",size:await Fn(n,r,e.size),processed:!0}}catch{return e}},gr={image:ur,video:dr},mr=(e,t)=>t.split(".").reduce((n,o)=>Pe(n)?n[o]:void 0,e),Dn=({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 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();o.addEventListener("abort",s);let p=g=>{o.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=()=>p(()=>{let g=l.responseText;try{g=JSON.parse(l.responseText)}catch{}if(l.status<200||l.status>=300){i(new d("UPLOAD_FAILED",`HTTP ${l.status}`));return}let y=mr(g,a.url_field);if(typeof y!="string"||!y){i(new d("UPLOAD_FAILED",`Response kh\xF4ng c\xF3 "${a.url_field}"`));return}r({url:y,response:g})}),l.onerror=()=>p(()=>i(new d("UPLOAD_FAILED","L\u1ED7i m\u1EA1ng khi upload"))),l.onabort=()=>p(()=>i(new d("CANCELLED","\u0110\xE3 hu\u1EF7 upload"))),l.send(c)}),Nn=e=>{var o,r;let t={...In};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:Dn};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}},Un=e=>{let{sources:t,targets:n}=Nn(e),o=Object.keys(t),r=Object.fromEntries(o.filter(i=>t[i]===In[i]&&Pn[i]).map(i=>[i,Pn[i]]));return{sources:o,file_types:r,targets:Object.keys(n),max_count:Dt}},yt=new Map,Vn=(e,t)=>`${e}:${t}`,fr=0,Bn=(e,t)=>{var n;typeof t=="string"&&((n=yt.get(Vn(e,t)))==null||n.abort())},Ve=e=>{for(let[t,n]of yt)t.startsWith(`${e}:`)&&n.abort()},ht=()=>new d("CANCELLED","\u0110\xE3 hu\u1EF7 upload"),hr=(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)}},qn=async(e,t)=>{var c;let{sources:n,targets:o}=Nn(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,l=Vn(t.instance_id,(c=t.task_id)!=null?c:`auto-${++fr}`);yt.set(l,a);try{return await yr(e,t,r,i,a.signal)}finally{yt.delete(l)}},yr=async(e,{instance_id:t,app_id:n,getContext:o,task_id:r,config:i,emit:a,exclusivePick:l=g=>g()},c,s,p)=>{var m,v,U;let g={app_id:n!=null?n:"",instance_id:t,context:{...(m=o==null?void 0:o())!=null?m:{}}},y=(await l(()=>c({accept:e.accept,max_count:e.max_count,process:e.process,caller:g}))).slice(0,e.max_count);if(p.aborted)throw ht();if(!y.length)throw new d("CANCELLED","Ng\u01B0\u1EDDi d\xF9ng kh\xF4ng ch\u1ECDn file");let u=[],h=y.filter(x=>nr(x,e.accept)?!0:(u.push({name:x.name,code:"INVALID_FILE",message:`Kh\xF4ng cho ph\xE9p \u0111\u1ECBnh d\u1EA1ng ${x.mime_type||kn(x.name)}`}),!1)),C=h.map(()=>0),S=h.map(x=>{var T;return(T=x.size)!=null?T:0}),M=0,A=0,w=(x=!1)=>{if(!a||!r)return;let T=Date.now();if(!x&&T-A<200)return;A=T;let F=S.reduce((I,X)=>I+X,0),W=C.reduce((I,X)=>I+X,0);a("upload.progress",{task_id:r,loaded:W,total:F,percent:F?Math.min(100,Math.round(W/F*100)):0,done_count:M,count:h.length})},G=[],Q=0,ie=async()=>{var x,T,F;for(;Q<h.length;){let W=Q++,I=h[W];try{if(p.aborted)throw ht();let X=I.mime_type.startsWith("image/")?"image":I.mime_type.startsWith("video/")?"video":void 0,xe=X&&!I.processed?(T=(x=i==null?void 0:i.processors)==null?void 0:x[X])!=null?T:gr[X]:void 0;if(xe&&(I=await xe(I,e.process),S[W]=(F=I.size)!=null?F:S[W],p.aborted))throw ht();if(e.max_size&&I.size&&I.size>e.max_size)throw new d("FILE_TOO_LARGE",`File ${I.size} byte v\u01B0\u1EE3t gi\u1EDBi h\u1EA1n ${e.max_size}`);let fe=(be,Ee)=>{C[W]=be,Ee&&(S[W]=Ee),w()},ee=await s({file:I,target:e.target,onProgress:fe,signal:p,caller:g});if(typeof(ee==null?void 0:ee.url)!="string"||!ee.url)throw new d("UPLOAD_FAILED","Upload kh\xF4ng tr\u1EA3 url");let{url:Le,..._e}=ee;G[W]={url:Le,name:I.name,mime_type:I.mime_type,size:I.size,width:I.width,height:I.height,duration:I.duration,...Object.keys(_e).length?{response:"response"in _e?_e.response:_e}:{}},C[W]=S[W]}catch(X){u.push(hr(h[W].name,X))}finally{M++,w(!0)}}};if(await Promise.all(Array.from({length:Math.min(e.concurrency,h.length)},ie)),p.aborted)throw ht();let we=G.filter(x=>!!x);if(!we.length){let x=u[0];throw new d((v=x==null?void 0:x.code)!=null?v:"UPLOAD_FAILED",(U=x==null?void 0:x.message)!=null?U:"Kh\xF4ng upload \u0111\u01B0\u1EE3c file n\xE0o")}return{files:we,failed:u}};import{useRef as wr,useSyncExternalStore as _r}from"react";var Te=e=>{let t=e,n=new Set;return{getState:()=>t,setState:o=>{let r=typeof o=="function"?o(t):o;t={...t,...r},n.forEach(i=>i())},subscribe:o=>(n.add(o),()=>{n.delete(o)})}},V=(e,t,n=Object.is)=>{let o=wr(null),r=()=>{let i=e.getState(),a=o.current;if(a&&a.state===i&&a.selector===t)return a.value;let l=t(i),c=a&&n(a.value,l)?a.value:l;return o.current={state:i,selector:t,value:c},c};return _r(e.subscribe,r)};var ue={info:"info",success:"success",error:"error"},br=200,$n={info:2e3,success:2e3,error:3e3},et=Te({message:"",type:ue.info,tick:0}),zn=e=>{let{message:t,type:n}=e!=null?e:{},o=String(t!=null?t:"").trim().slice(0,br);return o?{message:o,type:Object.values(ue).includes(n)?n:ue.info}:null},Wn=(e,t=ue.info)=>{et.setState(n=>({message:e,type:t,tick:n.tick+1}))};import{Platform as Xn}from"react-native";import{AppState as jn,Platform as Ut}from"react-native";var ce,Hn=()=>Ut.OS==="android"&&!!(ce!=null&&ce.requesting_permission),Ar=1500,wt=()=>new Promise(e=>{if(Ut.OS!=="android"||jn.currentState==="active"){e();return}let t=()=>{clearTimeout(n),o.remove(),e()},n=setTimeout(t,Ar),o=jn.addEventListener("change",r=>{r==="active"&&t()})}),Nt=e=>{var t;if(ce===e&&(ce=void 0,e.subscriptions.forEach(n=>n.remove()),e.started&&Ut.OS==="ios"))try{(t=e.native)==null||t.setAudioSessionActiveIOS(!1,{notifyOthersOnDeactivation:!0})}catch{}},Jn=async(e,t,n,o=()=>!0)=>{var i,a,l,c,s;if(ce)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:[]};ce=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 y;try{y=await g.requestPermissionsAsync()}finally{r.requesting_permission=!1}if(await wt(),r.cancelled||!o())throw new d("CANCELLED","Mini app \u0111\xE3 \u0111\xF3ng");if(!y.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,C;ce!==r||r.cancelled||n(u.isFinal?"speech.final":"speech.partial",{...u,text:(C=(h=u.results[0])==null?void 0:h.transcript)!=null?C:""})}),g.addListener("error",u=>{ce===r&&!r.cancelled&&n("speech.error",{...u,code:u.error})}),g.addListener("end",()=>{ce===r&&(Nt(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:(l=t.interimResults)!=null?l:!0,addsPunctuation:(c=t.addsPunctuation)!=null?c:!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 Nt(r),p}},Gn=e=>{let t=ce;if(!(!t||t.owner!==e)){if(!t.started){t.cancelled=!0;return}t.native.stop()}},Ae=e=>{let t=ce;if(!(!t||t.owner!==e||t.cancelled)&&(t.cancelled=!0,t.started))try{t.native.abort()}catch{Nt(t)}};var Kn={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"},Y={...Kn,all:Object.values(Kn)},tt={scan:"scanner.scan",start:"scanner.start",stop:"scanner.stop"},Bt={result:"scanner.result",end:"scanner.end"},ze={user:"user",web:"web",closed:"closed",error:"error"},Se={top:"top",full:"full"},Be={once:"once",continuous:"continuous"},Sr=1500,Yn=6e4,k,z=Te({active:null,last_value:null,hit_tick:0,scan_count:0,notice:null,is_picking:!1}),Zn=()=>Xn.OS==="android"&&!!(k!=null&&k.requesting_permission),qt=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=>Y.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>Yn)throw new d("INVALID_PARAMS",`cooldown_ms ph\u1EA3i t\u1EEB 0 \u0111\u1EBFn ${Yn}`);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(Se).includes(r))throw new d("INVALID_PARAMS","layout ph\u1EA3i l\xE0 ScannerLayout");i.layout=r}return i},$t=e=>k!==e?!1:(k=void 0,z.setState({active:null,last_value:null,scan_count:0,notice:null,is_picking:!1}),!0),Qn=async(e,t)=>{if(k)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");k=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 wt(),n(),r!=="granted")throw new d("PERMISSION_DENIED","Ch\u01B0a c\u1EA5p quy\u1EC1n camera");if(!o.Camera.getAvailableCameraDevices().some(a=>a.position==="back"))throw new d("NOT_SUPPORTED","Thi\u1EBFt b\u1ECB kh\xF4ng c\xF3 camera sau");let i=await zt();n(),z.setState({active:{owner:e.owner,mode:e.mode,types:e.types,layout:e.layout,hint:e.hint,vision:o,glass_view:i},last_value:null,scan_count:0,notice:null})}catch(o){throw $t(e),o}},zt=async()=>{if(Xn.OS==="ios")try{let e=await import("expo-glass-effect");return e.isLiquidGlassAvailable()?e.GlassView:void 0}catch{return}},eo=(e,t,n)=>{var o,r,i;return{owner:e,mode:t,types:(o=n.types)!=null?o:Y.all,cooldown_ms:(r=n.cooldown_ms)!=null?r:Sr,hint:n.hint,layout:t===Be.once?Se.full:(i=n.layout)!=null?i:Se.top,cancelled:!1,requesting_permission:!1,last_seen:new Map}},to=(e,t,n=()=>!0,o)=>new Promise((r,i)=>{let a=eo(e,Be.once,t);a.onHit=o,a.resolve=r,a.reject=i,Qn(a,n).catch(i)}),no=(e,t,n,o=()=>!0,r)=>{let i=eo(e,Be.continuous,t);return i.emit=n,i.onHit=r,Qn(i,o)},_t=(e,t,n)=>{var o,r;if(!z.getState().active){e.cancelled=!0;return}if($t(e)){if(e.mode===Be.once){(o=e.reject)==null||o.call(e,t===ze.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,Bt.end,n?{reason:t,message:n}:{reason:t})}},oo=e=>{(k==null?void 0:k.owner)===e&&_t(k,ze.web)},Ce=e=>{(k==null?void 0:k.owner)===e&&_t(k,ze.closed)},Wt=()=>{k&&_t(k,ze.user)},ro=e=>{k&&_t(k,ze.error,e)},jt=(e,t=Date.now(),n=!1)=>{var r,i,a;let o=k;if(!(!o||!z.getState().active))for(let{value:l,type:c}of e){if(!l)continue;let s=o.last_seen.get(l);if(!(!n&&s!==void 0&&t-s<o.cooldown_ms)){if(o.last_seen.set(l,t),(r=o.onHit)==null||r.call(o),o.mode===Be.once){$t(o),(i=o.resolve)==null||i.call(o,{value:l,type:c});return}z.setState(p=>({last_value:l,hit_tick:p.hit_tick+1,scan_count:p.scan_count+1,notice:null})),(a=o.emit)==null||a.call(o,Bt.result,{value:l,type:c})}}},vr={1:Y.code128,2:Y.code39,4:Y.code93,8:Y.codabar,16:Y.dataMatrix,32:Y.ean13,64:Y.ean8,128:Y.itf,256:Y.qr,512:Y.upcA,1024:Y.upcE,2048:Y.pdf417,4096:Y.aztec},Mr=2500,Vt=e=>{z.setState({notice:e}),setTimeout(()=>{z.getState().notice===e&&z.setState({notice:null})},Mr)},io=async()=>{var t,n;let e=k;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||k!==e)return;if(r.errorCode||!i){Vt("Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c \u1EA3nh");return}let{default:a}=await import("@react-native-ml-kit/barcode-scanning"),l=await a.scan(i);if(k!==e)return;let c=l.map(({value:s,format:p})=>({value:s,code_type:vr[p]})).filter(({code_type:s})=>!s||e.types.includes(s)).map(({value:s,code_type:p})=>({value:s,type:p!=null?p:"unknown"}));if(!c.length){Vt("Kh\xF4ng t\xECm th\u1EA5y m\xE3 trong \u1EA3nh");return}jt(c,Date.now(),!0)}catch{k===e&&Vt("Kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xE3 t\u1EEB \u1EA3nh")}finally{await wt(),e.requesting_permission=!1,k===e&&z.setState({is_picking:!1})}}};var At=1,d=class extends Error{constructor(n,o){super(o);this.code=n}},ao=e=>{try{let t=JSON.parse(e);return(t==null?void 0:t.__retion)===At&&typeof t.method=="string"?t:null}catch{return null}},ot=e=>`window.__RETION_MINIAPP__ && window.__RETION_MINIAPP__.receive(${JSON.stringify(e)}); true;`,co=(e,t)=>ot({id:e,result:t}),lo=(e,t)=>ot({id:e,error:{code:t.code,message:t.message}}),po=(e,t)=>ot({event:e,data:t}),Jt=e=>ot({event:"context",data:e});var uo=()=>`(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",ke=null,cn=new Set,To=e=>{ke
|
|
|
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: ${At}, 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",ke=null,cn=new Set,To=e=>{ke
|
|
|
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;`,go=()=>`(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",ke=null,cn=new Set,To=e=>{ke
|
|
|
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: ${At}, 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",ke=null,cn=new Set,To=e=>{ke
|
|
|
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;`,mo=()=>`(function () {
|
|
42
42
|
if (window.__retionSafeAreaFrozen) { return; }
|
|
43
43
|
window.__retionSafeAreaFrozen = true;
|
|
44
44
|
var max = {};
|
|
@@ -59,11 +59,11 @@ var Pt="https://retion-miniapp-platform.vercel.app",ke=null,cn=new Set,To=e=>{ke
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
|
-
})(); true;`,
|
|
63
|
-
${
|
|
62
|
+
})(); true;`,fo=e=>ot({event:e}),ho=(e,t)=>{let n=yo(t);return`try { history.replaceState(history.state, '', location.pathname + ${JSON.stringify(n?`?${n}`:"")} + location.hash); } catch (e) {}
|
|
63
|
+
${Jt(e)}`},yo=e=>Object.entries(e).filter(([,t])=>t!=null&&t!=="").map(([t,n])=>`${encodeURIComponent(t)}=${encodeURIComponent(String(n))}`).join("&"),wo=(e,t={})=>{let n=yo(t);return`window.__RETION_MINIAPP_HOST__ = { protocol: ${At} };
|
|
64
64
|
window.__RETION_MINIAPP_CONTEXT__ = ${JSON.stringify(e)};
|
|
65
65
|
${n?`try { history.replaceState(history.state, '', location.pathname + '?' + ${JSON.stringify(n)} + location.hash); } catch (e) {}`:""}
|
|
66
|
-
true;`},
|
|
66
|
+
true;`},_o={partner:"partner_token",chatbox:"chatbox_token"},bo=(e,t)=>{let n={...e};for(let o of Object.values(_o))t.includes(o)||delete n[o];return n},Ht=new Set,nt=async(e,t)=>{if(Ht.has(e))throw new d("BUSY",`${e} \u0111ang ch\u1EA1y \u2014 ch\u1EDD l\u01B0\u1EE3t tr\u01B0\u1EDBc xong`);Ht.add(e);try{return await t()}finally{Ht.delete(e)}},Ao=()=>`(function () {
|
|
67
67
|
try {
|
|
68
68
|
var AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
69
69
|
if (!AudioCtx) { return; }
|
|
@@ -79,4 +79,4 @@ var Pt="https://retion-miniapp-platform.vercel.app",ke=null,cn=new Set,To=e=>{ke
|
|
|
79
79
|
oscillator.start(ctx.currentTime);
|
|
80
80
|
oscillator.stop(ctx.currentTime + 0.08);
|
|
81
81
|
} catch (e) {}
|
|
82
|
-
})(); true;`,lr=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),gt=(e,t)=>{if(typeof e!="string"||!e)throw new u("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},co=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:c,app_id:l,instance_id:a,options:s,emit:d,isActive:g,playBeep:w})=>{var x,S,A,z,Y,ne,me,X,ae;let p=s==null?void 0:s.handlers,h={app_id:l,instance_id:a,close:c},O=()=>{var m;(m=s==null?void 0:s.haptic)==null||m.call(s,"impactLight"),w==null||w()},v=()=>new u("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let m=un(t);return Ge(e,()=>dn(m,g))}case"speech.start":{if(!d)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 u("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 u("INVALID_PARAMS",`${y} ph\u1EA3i l\xE0 boolean`);m[y]=t[y]}return In(a,m,d,g)}case"speech.stop":return Fn(a);case Ke.scan:return $n(a,It(t),g,O);case Ke.start:{if(!d)throw v();return zn(a,It(t),d,g,O)}case Ke.stop:return Wn(a);case"uploadFiles":{let{task_id:m,...y}=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 Tn(bn(y),{instance_id:a,app_id:l,getContext:r,task_id:m,config:s==null?void 0:s.upload,emit:d,exclusivePick:M=>Ge("uploadFiles.pick",M)})}case"uploadFiles.cancel":On(a,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Rn(s==null?void 0:s.upload);case"getBiometricAvailability":return((x=s==null?void 0:s.biometrics)!=null?x:await Rt()).getAvailability();case"authenticateBiometric":{let m=gt(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 y=t==null?void 0:t.cancelButtonText;if(y!==void 0&&(typeof y!="string"||!y.trim()||y.length>80))throw new u("INVALID_PARAMS","Invalid cancelButtonText");return Ge(e,async()=>{var C;return((C=s==null?void 0:s.biometrics)!=null?C:await Rt()).authenticate({reason:m,cancelButtonText:y})})}case"requestPayment":{let m=p==null?void 0:p.requestPayment;if(!m)throw v();let y=t==null?void 0:t.amount;if(typeof y!="number"||!Number.isFinite(y)||y<=0)throw new u("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let M={...t,amount:y,currency:gt(t==null?void 0:t.currency,"currency")};return Ge(e,()=>m(M,h))}case"printImage":{let m=p==null?void 0:p.printImage;if(!m)throw v();let y=gt(t==null?void 0:t.image,"image");await Ge(e,()=>m({image:y},h));return}case"openScreen":if(!(p!=null&&p.openScreen))throw v();await p.openScreen({screen:gt(t==null?void 0:t.screen,"screen"),params:t==null?void 0:t.params},h);return;case"closeApp":c();return;case"openWebview":{let m=String((S=t==null?void 0:t.url)!=null?S:"");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):Jn.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 u("INVALID_PARAMS","url kh\xF4ng h\u1EE3p l\u1EC7");try{await(s!=null&&s.openUrl?s.openUrl(m):Jn.openURL(m))}catch(y){throw new u("NOT_SUPPORTED",String((Y=(z=y==null?void 0:y.message)!=null?z:y)!=null?Y:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":(me=s==null?void 0:s.showToast)==null||me.call(s,String((ne=t==null?void 0:t.message)!=null?ne:""));return;case"haptic":{let m=lr.has(t==null?void 0:t.type)?t.type:"selection";(X=s==null?void 0:s.haptic)==null||X.call(s,m);return}case"getSystemInfo":return{platform:cr.OS==="ios"?"ios":"android",appVersion:(ae=s==null?void 0:s.app_version)!=null?ae:"",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 C=n().access_token;if(!C)throw new u("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return C}if(m!=="partner"&&m!=="chatbox")throw new u("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(m)}`);let y=io[m];if(!o().includes(y))throw new u("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${y} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let M=m==="partner"?n().partner_token:n().chatbox_token;if(!M)throw new u("HOST_ERROR",`Kh\xF4ng c\xF3 ${y}`);return M}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 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:[]}))},pr=(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)},po=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(()=>{})))},uo=async e=>{var t;await((t=Ze[e])==null?void 0:t.catch(()=>{})),F().storage.setString(qt(e),""),await F().file_system.remove(`${zt()}/${e}`).catch(()=>{})},Be=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},Ze={},go=(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},ur=(e,t)=>{var r,i;let n=e.split(".").map(c=>parseInt(c,10)||0),o=t.split(".").map(c=>parseInt(c,10)||0);for(let c=0;c<Math.max(n.length,o.length);c++){let l=((r=n[c])!=null?r:0)-((i=o[c])!=null?i:0);if(l)return l}return 0},dr=({manifest:e,zip_path:t})=>go(e.app_id,async()=>{var i;let n=F().file_system,o=I(e.app_id);if(o&&ur(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),re("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),po(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,c=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,l=()=>{if(i)throw new Be},a=async()=>{var g;l();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);l();let d=o.download({url:t?pr(t,e.bundle_url):e.bundle_url,to_file:c,onProgress:(w,p)=>{var O;let h=p>0?p:(O=e.size)!=null?O:0;h>0&&(n==null||n(Math.min(1,w/h)))}});r=d;try{let{status:w}=await d.promise;if(l(),w!==200)throw new Error(`bundle ${w}`);if(e.sha256)if(o.sha256){if(await o.sha256(c)!==e.sha256)throw new Error("sha256 mismatch")}else re("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);l();let p=Wt(e.app_id,e.version,e.entry,!!e.context_update,(g=e.permissions)!=null?g:[]);return await o.remove(p.dir).catch(()=>{}),await o.mkdir(p.dir),await o.unzip(c,p.dir),Bt(e),po(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),p}catch(w){throw i?new Be:w}finally{r=null,o.remove(c).catch(()=>{})}};return{promise:go(e.app_id,a),cancel:()=>{i=!0,r==null||r.cancel()}}},Xe={},gr=__DEV__?0:60*1e3,lo={},mo=(e,t)=>{var o,r;let n=I(e);return n&&Date.now()-((o=lo[t])!=null?o:0)<gr?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 c=await i.json(),l=await Ht(c,{base_url:t}).promise;return lo[t]=Date.now(),l})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),I(e))).finally(()=>{Xe[e]=void 0})),Xe[e])};var ft=new Map,fo=(e,t)=>(ft.set(e,t),()=>{ft.get(e)===t&&ft.delete(e)}),mr=(e,t)=>{let n=ft.get(e);return n?n(t):!1};import{useCallback as fr,useEffect as Jt,useRef as qe,useState as ht}from"react";import{Animated as j,BackHandler as hr,Easing as ho,Platform as Ao,Pressable as yr,StatusBar as wr,StyleSheet as Gt,Text as Qe,View as U}from"react-native";import{Fragment as xr,jsx as R,jsxs as ge}from"react/jsx-runtime";var et="#22C55E",Ar="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",_r=2,wt=18,br=1600,tt=14,Sr=2e3,yo=2,$e=2e3,vr=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:tt},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:tt},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:tt},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:tt}],wo=({color:e})=>R(xr,{children:vr.map((t,n)=>R(U,{style:[b.corner,t,{borderColor:e}]},n))}),yt=({style:e,children:t,...n})=>{let o=qe(new j.Value(1)).current,r=i=>j.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return R(yr,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:R(j.View,{style:[e,{transform:[{scale:o}]}],children:t})})},Yt=({scanner:e})=>{var fe,he,Se;let{vision:t,types:n,mode:o,layout:r,hint:i,glass_view:c}=e,l=r===we.top,a=t.useCameraDevice("back"),[s,d]=ht(!1),[g,w]=ht(1),[p,h]=ht({width:0,height:0}),O=W(B,P=>P.last_value),v=W(B,P=>P.hit_tick),x=W(B,P=>P.scan_count),S=W(B,P=>P.notice),A=W(B,P=>P.is_picking),z=qe(null),[Y,ne]=ht(0),me=Ao.OS==="ios"?54:(fe=wr.currentHeight)!=null?fe:0,X=qe(new j.Value(0)).current,ae=qe(new j.Value(0)).current,m=qe(new j.Value(0)).current,y=Math.round(p.width*(l?.8:.78)),M=Math.round(l?p.height*.46:y*.78),C=Math.round((p.height-M)/2),q=Math.round((p.width-y)/2),L=t.useCodeScanner({codeTypes:n,onCodeScanned:fr(P=>Nt(P),[])});Jt(()=>{let P=hr.addEventListener("hardwareBackPress",()=>(Dt(),!0));return()=>P.remove()},[]);let K=qe(v);Jt(()=>{if(v===K.current)return;X.setValue(1),m.setValue(1);let P=j.parallel([j.timing(X,{toValue:0,duration:450,useNativeDriver:!0}),j.sequence([j.delay(Sr),j.timing(m,{toValue:0,duration:250,useNativeDriver:!0})])]);return P.start(),()=>P.stop()},[v,X,m]),Jt(()=>{let P=ze=>j.timing(ae,{toValue:ze,duration:br,easing:ho.inOut(ho.quad),useNativeDriver:!0}),Oe=j.loop(j.sequence([P(1),P(0)]));return Oe.start(),()=>Oe.stop()},[ae]);let be=!!(a!=null&&a.hasTorch),de=(he=a==null?void 0:a.neutralZoom)!=null?he:1,Z=a?Math.min(de*g,a.maxZoom):1,Ce=R(Qe,{style:[b.hint,!!S&&b.hint_notice],numberOfLines:1,children:(Se=S!=null?S:i)!=null?Se:Ar});return ge(U,{ref:z,style:l?b.top:b.full,onLayout:({nativeEvent:{layout:P}})=>{var Oe;h({width:P.width,height:P.height}),(Oe=z.current)==null||Oe.measureInWindow((ze,at)=>ne(at))},children:[a&&R(t.Camera,{style:Gt.absoluteFill,device:a,isActive:!A,codeScanner:L,torch:s&&be?"on":"off",zoom:Z,enableZoomGesture:!0,onError:P=>jn(P.message)}),p.height>0&&ge(U,{style:b.overlay,pointerEvents:"none",children:[R(U,{style:[b.dim_ring,{top:C-$e,left:q-$e,width:y+$e*2,height:M+$e*2}]}),ge(U,{style:{position:"absolute",top:C,left:q,width:y,height:M},children:[R(wo,{color:"#FFFFFF"}),R(j.View,{style:[Gt.absoluteFill,{opacity:X}],children:R(wo,{color:et})}),ge(j.View,{style:[b.scan_line_wrap,{transform:[{translateY:ae.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,M-wt)]})}]}],children:[R(U,{style:b.scan_glow_outer}),R(U,{style:b.scan_glow_inner}),R(U,{style:b.scan_line})]})]}),R(U,{style:[b.hint_slot,l?{top:0,height:C-6,justifyContent:"flex-end"}:{top:C+M+20}],children:Ce}),o===Fe.continuous&&!!O&&R(j.View,{style:[b.result_slot,l?b.result_slot_top:{top:C+M+52},{opacity:m}],children:ge(U,{style:b.result,children:[R(U,{style:b.check_badge,children:R(U,{style:b.check_mark})}),R(Qe,{style:b.result_text,numberOfLines:1,children:O}),ge(Qe,{style:b.result_count,children:["\xB7 ",x," m\xE3"]})]})})]}),R(U,{style:[b.close_slot,{top:Math.max(12,me-Y+12)}],children:ge(yt,{style:[b.close_button,!!c&&b.glass_surface],onPress:Dt,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[c&&R(c,{style:b.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),R(U,{style:[b.close_bar,b.close_bar_a]}),R(U,{style:[b.close_bar,b.close_bar_b]})]})}),R(U,{style:[b.toolbar_wrap,!l&&b.toolbar_wrap_full],pointerEvents:"box-none",children:ge(U,{style:[b.toolbar,!!c&&b.glass_surface],children:[c&&R(c,{style:b.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),R(yt,{style:b.tool,onPress:Hn,disabled:A,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:ge(U,{style:b.image_icon,children:[R(U,{style:b.image_icon_dot}),R(U,{style:b.image_icon_hill})]})}),!!a&&a.maxZoom>=de*yo&&R(yt,{style:[b.tool,g>1&&b.tool_on],onPress:()=>w(P=>P>1?1:yo),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:ge(Qe,{style:[b.zoom_text,g>1&&b.zoom_text_on],children:[g,"x"]})}),be&&R(yt,{style:[b.tool,s&&b.tool_on],onPress:()=>d(P=>!P),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:s},children:R(Qe,{style:[b.torch_icon,s&&b.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})},Mr="rgba(0,0,0,0.5)",Kt=50,b=Gt.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:$e,borderColor:Mr,borderRadius:$e+tt},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:wt,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:wt,borderRadius:wt/2,backgroundColor:et,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:et,opacity:.2},scan_line:{height:_r,borderRadius:1,backgroundColor:et},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar_wrap_full:{bottom:Ao.OS==="ios"?34:20},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:Kt,height:Kt,borderRadius:Kt/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result_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:et},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 Q=Ue({active_key:null,instances:{}}),_o=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var l;let c=(l=F().keep_alive)==null?void 0:l.max_webviews;Q.setState(a=>{let s=t!=null?t:e.app_id,d={...a.instances,[s]:{key:s,app:e,context:n,url_params:o,host_data:r,last_used_at:Date.now()}},g=Object.keys(d);return c&&c>0&&g.length>c&&g.filter(w=>w!==s).sort((w,p)=>d[w].last_used_at-d[p].last_used_at).slice(0,g.length-c).forEach(w=>{delete d[w]}),i?{active_key:s,instances:d}:{instances:d}})},Er=e=>_o(e,!0),Pr=e=>_o(e,!1),nt=()=>Q.setState({active_key:null}),At=e=>{Q.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var bo="catalog",Rr="paused_apps",Cr="removed_apps",Or=10*1e3,Tr=2,kr=3e3,Lr=()=>{var e;try{return JSON.parse((e=F().storage.getString(bo))!=null?e:"{}")}catch{return{}}},T=Ue({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),So=e=>{var t;return!!((t=F().manual_update)!=null&&t.includes(e))},St=new Set,vo=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{}}}},pe=vo(Rr),Re=vo(Cr);ln(()=>{pe.load(),Re.load();let e=Lr(),t={};Object.keys(e).filter(n=>!Re.has(n)).forEach(n=>{let o=I(n);o?t[n]={status:"installed",progress:1,version:o.version,has_local:!0}:pe.has(n)&&(t[n]={status:"paused",progress:0,version:e[n].version,has_local:!1})}),T.setState({catalog:e,downloads:t})});var Zt=e=>W(T,t=>e?t.downloads[e]:void 0),Ir=()=>W(T,e=>e.pause_reasons.length>0),le=(...e)=>re("queue",...e),$=[],_e={},E=null,_t=new Set,De={},Xt=new Set,Ee=e=>{Xt.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},Fr=e=>(Xt.add(e),()=>{Xt.delete(e)}),Dr=()=>T.getState().downloads,ee=(e,t)=>{let n=!!I(e),o=T.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};T.setState(c=>({downloads:{...c.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=De[e])==null||n.forEach(o=>o(t)),delete De[e]},Nr=()=>T.getState().pause_reasons.length>0,Pe=e=>{var l;if(E)return;let t=e?$.indexOf(e):Nr()?-1:$.findIndex(a=>!pe.has(a));if(t<0||t>=$.length)return;let[n]=$.splice(t,1),o=T.getState().catalog[n];if(!o){bt(n,I(n)),Pe();return}let r=Date.now();_e[n]=((l=_e[n])!=null?l:0)+1,ee(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,c=Ht(o,{onProgress:a=>{let s=Math.floor(a*100);s!==i&&(i=s,ee(n,{progress:s/100,version:o.version}))}});E={app_id:n,handle:c,forced:!!e},le("start",n,o.version,e?"(forced)":""),c.promise.then(a=>{le("installed",n,o.version,`${Date.now()-r}ms`),ee(n,{status:"installed",progress:1,version:o.version}),bt(n,a)}).catch(a=>{var d;if(a instanceof Be){if(_t.has(n))return;le("paused",n),_e[n]-=1,$.unshift(n),ee(n,{status:pe.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((d=a==null?void 0:a.message)!=null?d:a);if(console.warn("[miniapp-queue] failed",n,s),_e[n]<Tr){ee(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var g;$.includes(n)||(E==null?void 0:E.app_id)===n||($.push(n),Pe((g=De[n])!=null&&g.length?n:void 0))},kr);return}ee(n,{status:"failed",progress:0,version:o.version,error:s}),bt(n,I(n))}).finally(()=>{E=null;let a=$.find(s=>{var d;return(d=De[s])==null?void 0:d.length});Pe(a)})},vt=(e,{front:t=!1}={})=>{if((E==null?void 0:E.app_id)===e)return;let n=$.indexOf(e);if(n>=0){if(!t)return;$.splice(n,1)}t?$.unshift(e):$.push(e)},Ur=async e=>{let{host_id:t,client_token:n}=F(),o=new AbortController,r=setTimeout(()=>o.abort(),Or);try{let i=`${Pt}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,c=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!c.ok)throw new Error(`host list ${e} ${c.status}`);return(await c.json()).apps.map(a=>({...a,channel:e}))}finally{clearTimeout(r)}},ot=null,Qt=()=>(ot!=null||(ot=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(F().channels.map(Ur)),o={};[...n].reverse().flat().forEach(a=>{o[a.app_id]=a});let r=Object.keys(T.getState().catalog).filter(a=>!o[a]);F().storage.setString(bo,JSON.stringify(o)),T.setState({catalog:o}),await Promise.all(r.map(a=>Mo(a,{by_user:!1}))),r.forEach(a=>Re.delete(a));let i=Object.keys(o).filter(a=>!Re.has(a)),c=[],l={};for(let a of i.map(s=>o[s])){if(await jt(a)){ee(a.app_id,{status:"installed",progress:1,version:a.version});continue}let s=I(a.app_id);if(So(a.app_id)&&!St.has(a.app_id)&&s&&await Ae(s)){ee(a.app_id,{status:"installed",progress:1,version:s.version}),l[a.app_id]={app_id:a.app_id,current_version:s.version,next_version:a.version};continue}c.push(a)}return T.setState({updates:l}),c.forEach(a=>{_e[a.app_id]=0,ee(a.app_id,{status:pe.has(a.app_id)?"paused":"queued",progress:0,version:a.version,error:void 0}),vt(a.app_id)}),le("catalog",i.length,"apps, outdated",c.map(a=>a.app_id),"removed",r,`${Date.now()-e}ms`),Ee({type:"sync_complete",app_ids:i,removed:r}),Object.values(l).forEach(a=>Ee({type:"update_available",...a})),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),Ee({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{ot=null}})()),ot),Mo=async(e,{by_user:t})=>{var r,i,c,l;if(t&&Re.add(e),_t.has(e))return;_t.add(e),pe.delete(e);let n=$.indexOf(e);n>=0&&$.splice(n,1),(E==null?void 0:E.app_id)===e&&E.handle.cancel();let o=(l=(c=(r=T.getState().downloads[e])==null?void 0:r.version)!=null?c:(i=I(e))==null?void 0:i.version)!=null?l:"";ee(e,{status:"uninstalling",progress:0,version:o}),await uo(e),At(e),T.setState(a=>{let s={...a.downloads};return delete s[e],{downloads:s}}),delete _e[e],_t.delete(e),bt(e,null),le("uninstalled",e,t?"(user)":"(not in list)"),Ee({type:"uninstalled",app_id:e})},Vr=e=>Mo(e,{by_user:!0}),Br=e=>{let t=rt(e);return t?(Re.delete(e),(E==null?void 0:E.app_id)===e||$.includes(e)||(_e[e]=0,ee(e,{status:pe.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),vt(e),Pe(),le("restore",e)),!0):!1},qr=e=>{if(pe.has(e))return;if(pe.add(e),le("pause app",e),(E==null?void 0:E.app_id)===e&&!E.forced){E.handle.cancel();return}let t=T.getState().downloads[e];$.includes(e)&&t&&ee(e,{status:"paused",progress:0,version:t.version})},$r=e=>{if(!pe.delete(e))return;le("resume app",e);let t=T.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!$.includes(e)&&rt(e)&&(_e[e]=0,vt(e)),$.includes(e)&&t&&ee(e,{status:"queued",progress:0,version:t.version}),Pe()},zr=e=>{let{pause_reasons:t}=T.getState();t.includes(e)||(T.setState({pause_reasons:[...t,e]}),le("pause",e),t.length===0&&Ee({type:"pause_change",paused:!0,reasons:[e]}),E&&!E.forced&&E.handle.cancel())},Wr=e=>{let{pause_reasons:t}=T.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);T.setState({pause_reasons:n}),le("resume",e),n.length===0&&Ee({type:"pause_change",paused:!1,reasons:n}),Pe()},xo=e=>T.getState().updates[e],jr=async e=>{var n,o;let t=xo(e);St.add(e);try{let r=await Mt(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=rt(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(T.setState(c=>{var a;let l={...c.updates};return delete l[e],{updates:l,apply_ticks:{...c.apply_ticks,[e]:((a=c.apply_ticks[e])!=null?a:0)+1}}}),le("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{St.delete(e)}},Hr=()=>Object.values(T.getState().catalog).map(e=>({...e,installed:!!I(e.app_id),removed_by_user:Re.has(e.app_id)})),rt=e=>T.getState().catalog[e],Mt=async e=>{let t=rt(e);if(!t)return;if(pe.delete(e),Re.delete(e),await jt(t))return I(e);let n=I(e);if(So(e)&&!St.has(e)&&n&&await Ae(n))return n;let o=new Promise(r=>{var i;((i=De[e])!=null?i:De[e]=[]).push(r)});return(E==null?void 0:E.app_id)===e?E.forced=!0:(_e[e]=0,vt(e,{front:!0}),E&&!E.forced?E.handle.cancel():Pe(e)),o};import{Fragment as Co,jsx as H,jsxs as st}from"react/jsx-runtime";var tn=e=>(e!=null?e:"").replace(/\?[^#]*/,""),Po=0,Qr=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},ei=rn.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:c,bridge:l,opaque_background:a,allow_embedded_miniapps:s,onWebLoadEnd:d})=>{var ze,at;let g=ue(null),w=ue(!1),p=W(Q,f=>f.instances[e]),h=p==null?void 0:p.app.app_id,O=p==null?void 0:p.app.manifest_url,v=p==null?void 0:p.context,x=p==null?void 0:p.url_params,S=W(B,f=>{var _;return((_=f.active)==null?void 0:_.owner)===e?f.active:null}),[A,z]=Ne(()=>h?I(h):null),[Y,ne]=Ne(!1),[me,X]=Ne(0),[ae,m]=Ne(0),[y,M]=Ne(!1),C=ue(null),q=f=>{C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{C.current=null,M(!0)},f)};te(()=>()=>{C.current&&clearTimeout(C.current)},[]),te(()=>{if(!h||!t&&A)return;let f=!0;return ne(!1),(async()=>{let _=I(h),G=_?await Ae(_):!1;if(!f||(z(G?ce=>!ce||ce.version!==_.version||ce.permissions.join(",")!==_.permissions.join(",")?_:ce:null),__DEV__&&Date.now()-Po>1e4&&(Po=Date.now(),await Qt()),!f))return;let ve=await Mt(h),Te=ve!==void 0?ve:O?await mo(h,O):I(h);if(f){if(!Te){ne(!0);return}z(ce=>ce!=null?ce:Te)}})(),()=>{f=!1}},[t,h,O,me]),te(()=>fo(e,f=>g.current?(g.current.postMessage(f),!0):!1),[e]);let L=W(T,f=>{let _=h?f.downloads[h]:void 0;return(_==null?void 0:_.status)==="installed"?_.version:void 0});te(()=>{if(t||!h||!A)return;let f=I(h);if(!f||f.version===A.version)return;let _=!0;return Ae(f).then(G=>{!_||!G||(re(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",A.version,"\u2192",f.version),z(f))}),()=>{_=!1}},[t,h,L,A==null?void 0:A.version]);let K=W(T,f=>{var _;return h&&(_=f.apply_ticks[h])!=null?_:0});te(()=>{if(!K||!h)return;let f=I(h);if(!f||f.version===(A==null?void 0:A.version))return;let _=!0;return Ae(f).then(G=>{!_||!G||(re(`webview:${e}`,"c\u1EADp nh\u1EADt",A==null?void 0:A.version,"\u2192",f.version),M(!1),z(f))}),()=>{_=!1}},[K]),te(()=>{var G;let f=(G=F().keep_alive)==null?void 0:G.idle_close_ms;if(t||!f||f<=0)return;let _=setTimeout(()=>{At(e)},f);return()=>clearTimeout(_)},[t,e]),te(()=>{r>0&&(ne(!1),M(!1),m(f=>f+1),X(f=>f+1))},[r]);let be=ue(t);te(()=>{var f;be.current!==t&&(be.current=t,w.current&&((f=g.current)==null||f.injectJavaScript(to(t?"resumed":"paused"))))},[t]);let de=`${(ze=A==null?void 0:A.version)!=null?ze:"none"}:${(at=A==null?void 0:A.permissions.join(","))!=null?at:""}:${ae}`,Z=xt(()=>JSON.stringify([v!=null?v:{},x!=null?x:{}]),[v,x]),Ce=xt(()=>{var f;return so(x!=null?x:{},(f=A==null?void 0:A.permissions)!=null?f:[])},[Z,A==null?void 0:A.permissions]),fe=xt(()=>ro(v!=null?v:{},Ce)+Qn()+(Yr.OS==="android"?eo():"")+(F().debug?Zn():""),[Ce]),he=ue(null),Se=ue(null);te(()=>{var _,G,ve;if(!A)return;if(Se.current!==de){Se.current=de,he.current=Z;return}if(he.current===Z)return;let f=((G=JSON.parse((_=he.current)!=null?_:"[]")[0])!=null?G:{}).org_id;if(he.current=Z,f===(v==null?void 0:v.org_id)&&w.current){M(!1),q(1500),(ve=g.current)==null||ve.injectJavaScript(no(v!=null?v:{},Ce));return}M(!1),m(Te=>Te+1)},[Z,A,de]),te(()=>(t||(ye(e),xe(e),Ie(e)),()=>{ye(e),xe(e),Ie(e)}),[t,e,de,r]),te(()=>{let f=Eo.addEventListener("change",_=>{_==="background"&&!Ln()&&ye(e),_==="background"&&!Vn()&&xe(e)});return()=>f.remove()},[e]);let P=nn(async f=>{var G,ve,Te,ce,Et;let _=Kn(f.nativeEvent.data);if(!_){if(h&&(l!=null&&l.onWebEvent))try{Promise.resolve(l.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}=_;re(`web:${e}`,D!=null?D:"log",N!=null?N:"");return}if(_.method==="pong"){C.current||M(!0);return}if(_.method==="touchAtTop"){i.emit(!!_.at_top);return}if(_.method==="contextApplied"){C.current&&clearTimeout(C.current),C.current=null,M(!0);return}if(_.method==="ready"){w.current=!0,M(!0);let D=(G=Q.getState().instances[e])==null?void 0:G.context;D&&((ve=g.current)==null||ve.injectJavaScript(Vt(D)));return}try{let D=await co(_,{getHostData:()=>{var N,oe;return(oe=(N=Q.getState().instances[e])==null?void 0:N.host_data)!=null?oe:{}},getPermissions:()=>{var N,oe;return h?(oe=(N=I(h))==null?void 0:N.permissions)!=null?oe:[]:[]},getContext:()=>{var N,oe;return(oe=(N=Q.getState().instances[e])==null?void 0:N.context)!=null?oe:{}},is_dark:o,close:nt,app_id:h!=null?h:"",instance_id:e,options:l,emit:(N,oe)=>{var an;(an=g.current)==null||an.injectJavaScript(Xn(N,oe))},playBeep:()=>{var N;(N=g.current)==null||N.injectJavaScript(ao())},isActive:()=>Q.getState().active_key===e&&Eo.currentState!=="background"});_.id&&((Te=g.current)==null||Te.injectJavaScript(Gn(_.id,D)))}catch(D){if(!_.id)return;let N=D==null?void 0:D.code,oe=D instanceof u?D:new u(typeof N=="string"?N:"HOST_ERROR",String((ce=D==null?void 0:D.message)!=null?ce:D));(Et=g.current)==null||Et.injectJavaScript(Yn(_.id,oe))}},[e,o,h,i,l]),Oe=nn(()=>{ne(!1),m(f=>f+1),X(f=>f+1)},[]);return st(on,{style:[sn.absoluteFill,a&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&se.behind],pointerEvents:t?"auto":"none",children:[(S==null?void 0:S.layout)===we.top&&H(Yt,{scanner:S}),A?H(Zr,{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:P,bounces:!1,overScrollMode:"never",onLoadStart:f=>{ye(e),xe(e),Ie(e),re(`webview:${e}`,"load start",tn(f.nativeEvent.url)),w.current=!1,M(!1)},onError:f=>{ye(e),xe(e),Ie(e),re(`webview:${e}`,"load error",tn(f.nativeEvent.url),f.nativeEvent.description),ne(!0),M(!1)},onLoadEnd:f=>{let _=f.nativeEvent.url;re(`webview:${e}`,"load end",tn(_)),h&&(d==null||d({app_id:h,instance_id:e,url:_})),q(1500)},onContentProcessDidTerminate:()=>{ye(e),xe(e),Ie(e),w.current=!1,M(!1),m(f=>f+1)},onRenderProcessGone:()=>(ye(e),xe(e),Ie(e),w.current=!1,M(!1),m(f=>f+1),!0),style:se.webview},de):null,(S==null?void 0:S.layout)===we.full&&H(Yt,{scanner:S}),p&&H(ni,{visible:!A||!y,interactive:Y,children:H(ti,{splash:c,app:p.app,is_dark:o,error:Y,has_bundle:!!A,retry:Oe})})]})}),ti=rn.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let c=e,l=Zt(t.app_id),a=o?"error":!r&&(l==null?void 0:l.status)==="downloading"?"downloading":"loading";return H(c,{app:t,is_dark:n,status:a,progress:a==="downloading"?l==null?void 0:l.progress:void 0,retry:i})}),ni=({visible:e,interactive:t,children:n})=>{let o=ue(new en.Value(e?1:0)).current,[r,i]=Ne(e);return te(()=>{if(e){i(!0),o.setValue(1);return}let c=en.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return c.start(({finished:l})=>{l&&i(!1)}),()=>c.stop()},[e,o]),r?H(en.View,{style:[sn.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 st(on,{style:[se.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[H(on,{style:[se.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?H(Gr,{source:{uri:e.icon},style:se.splash_icon_image}):H(it,{style:se.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),H(it,{style:[se.splash_name,{color:i}],children:e.name}),n==="error"?st(Co,{children:[H(it,{style:se.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),H(Xr,{activeOpacity:.7,style:[se.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:H(it,{style:[se.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):st(Co,{children:[H(Jr,{style:se.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&st(it,{style:se.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},Ro=(e,t)=>{let n=ue(t),o=ue(!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.`))},oi=({container:e,splash:t=Oo,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:c=!1,onWebLoadEnd:l})=>{Ro("container",e),Ro("splash",t);let a=e,s=W(Q,S=>S.active_key),d=ue(s);s&&(d.current=s);let g=W(Q,S=>Object.keys(S.instances).join("|")),w=W(Q,S=>{var A;return S.active_key?(A=S.instances[S.active_key])==null?void 0:A.app.name:void 0}),p=xt(()=>g?g.split("|"):[],[g]),[h,O]=Ne({}),v=ue(Qr()).current;te(()=>{if(!s||!r)return;let S=Kr.addEventListener("hardwareBackPress",()=>(nt(),!0));return()=>S.remove()},[s,r]);let x=nn(()=>{let S=Q.getState().active_key;S&&O(A=>({...A,[S]:(A[S]||0)+1}))},[]);return p.length?H(a,{visible:!!s,title:w!=null?w:"",is_dark:n,close:nt,reload:x,subscribeWebAtTop:v.subscribe,children:p.map(S=>H(ei,{instance_key:S,is_active:s===S,is_front:(s!=null?s:d.current)===S,is_dark:n,reload_tick:h[S]||0,web_at_top:v,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:c,onWebLoadEnd:l},S))}):null},se=sn.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"}}),ri=rn.memo(oi);export{J as CodeType,Oo as DefaultMiniAppSplash,Pt as MINIAPP_PLATFORM_URL,ri as MiniAppHost,u as MiniAppHostError,Ve as ScannerEndReason,Lt as ScannerEvent,we as ScannerLayout,Ke as ScannerMethod,nt as closeMiniApp,To as configureMiniApp,Lo as createMmkvStorage,pn as createReactNativeBiometrics,ko as createRnfsFileSystem,Mt as ensureMiniApp,I as getLocalMiniApp,Hr as getMiniAppCatalog,rt as getMiniAppCatalogEntry,Dr as getMiniAppStatuses,xo as getMiniAppUpdate,dr as installBundledMiniApp,Fr as onMiniAppEvent,Er as openMiniApp,qr as pauseMiniApp,zr as pauseMiniAppDownloads,Pr as preloadMiniApp,ye as releaseSpeechFor,Br as restoreMiniApp,$r as resumeMiniApp,Wr as resumeMiniAppDownloads,mr as sendEventToWeb,Qt as syncMiniAppCatalog,Vr as uninstallMiniApp,jr as updateMiniApp,En as uploadToUrl,Zt as useMiniAppDownload,Ir as useMiniAppDownloadsPaused};
|
|
82
|
+
})(); true;`,Er=new Set(["selection","impactLight","impactMedium","impactHeavy","rigid","soft","notificationSuccess","notificationWarning","notificationError"]),bt=(e,t)=>{if(typeof e!="string"||!e)throw new d("INVALID_PARAMS",`Thi\u1EBFu ${t}`);return e},So=async({method:e,params:t},{getHostData:n,getPermissions:o,getContext:r,is_dark:i,close:a,app_id:l,instance_id:c,options:s,emit:p,isActive:g,playBeep:y})=>{var M,A,w,G,Q,ie,we;let u=s==null?void 0:s.handlers,h={app_id:l,instance_id:c,close:a},C=()=>{var m;(m=s==null?void 0:s.haptic)==null||m.call(s,"impactLight"),y==null||y()},S=()=>new d("NOT_SUPPORTED",`${e} ch\u01B0a h\u1ED7 tr\u1EE3 \u1EDF \u1EE9ng d\u1EE5ng n\xE0y`);switch(e){case"getCurrentLocation":{let m=An(t);return nt(e,()=>Sn(m,g))}case"speech.start":{if(!p)throw S();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 v of["continuous","interimResults","addsPunctuation","requiresOnDeviceRecognition"])if((t==null?void 0:t[v])!==void 0){if(typeof t[v]!="boolean")throw new d("INVALID_PARAMS",`${v} ph\u1EA3i l\xE0 boolean`);m[v]=t[v]}return Jn(c,m,p,g)}case"speech.stop":return Gn(c);case tt.scan:return to(c,qt(t),g,C);case tt.start:{if(!p)throw S();return no(c,qt(t),p,g,C)}case tt.stop:return oo(c);case"uploadFiles":{let{task_id:m,...v}=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 qn(On(v),{instance_id:c,app_id:l,getContext:r,task_id:m,config:s==null?void 0:s.upload,emit:p,exclusivePick:U=>nt("uploadFiles.pick",U)})}case"uploadFiles.cancel":Bn(c,t==null?void 0:t.task_id);return;case"getUploadCapabilities":return Un(s==null?void 0:s.upload);case"getBiometricAvailability":return((M=s==null?void 0:s.biometrics)!=null?M:await Ft()).getAvailability();case"authenticateBiometric":{let m=bt(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 v=t==null?void 0:t.cancelButtonText;if(v!==void 0&&(typeof v!="string"||!v.trim()||v.length>80))throw new d("INVALID_PARAMS","Invalid cancelButtonText");return nt(e,async()=>{var x;return((x=s==null?void 0:s.biometrics)!=null?x:await Ft()).authenticate({reason:m,cancelButtonText:v})})}case"requestPayment":{let m=u==null?void 0:u.requestPayment;if(!m)throw S();let v=t==null?void 0:t.amount;if(typeof v!="number"||!Number.isFinite(v)||v<=0)throw new d("INVALID_PARAMS","amount ph\u1EA3i l\xE0 s\u1ED1 > 0");let U={...t,amount:v,currency:bt(t==null?void 0:t.currency,"currency")};return nt(e,()=>m(U,h))}case"printImage":{let m=u==null?void 0:u.printImage;if(!m)throw S();let v=bt(t==null?void 0:t.image,"image");await nt(e,()=>m({image:v},h));return}case"openScreen":if(!(u!=null&&u.openScreen))throw S();await u.openScreen({screen:bt(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((A=t==null?void 0:t.url)!=null?A:"");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):so.openURL(m));return}case"openLink":{let m=String((w=t==null?void 0:t.url)!=null?w:"").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):so.openURL(m))}catch(v){throw new d("NOT_SUPPORTED",String((Q=(G=v==null?void 0:v.message)!=null?G:v)!=null?Q:"Kh\xF4ng m\u1EDF \u0111\u01B0\u1EE3c link"))}return}case"showToast":{let m=zn(t);if(!m||(g==null?void 0:g())===!1)return;s!=null&&s.showToast?s.showToast(m.message,{type:m.type}):Wn(m.message,m.type);return}case"haptic":{let m=Er.has(t==null?void 0:t.type)?t.type:"selection";(ie=s==null?void 0:s.haptic)==null||ie.call(s,m);return}case"getSystemInfo":return{platform:xr.OS==="ios"?"ios":"android",appVersion:(we=s==null?void 0:s.app_version)!=null?we:"",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 x=n().access_token;if(!x)throw new d("HOST_ERROR","Mini app ch\u01B0a c\xF3 token cho page n\xE0y");return x}if(m!=="partner"&&m!=="chatbox")throw new d("HOST_ERROR",`Lo\u1EA1i token kh\xF4ng h\u1EE3p l\u1EC7: ${String(m)}`);let v=_o[m];if(!o().includes(v))throw new d("PERMISSION_DENIED",`Mini app ch\u01B0a \u0111\u01B0\u1EE3c c\u1EA5p quy\u1EC1n ${v} (Console \u2192 Quy\u1EC1n l\u1EA5y token)`);let U=m==="partner"?n().partner_token:n().chatbox_token;if(!U)throw new d("HOST_ERROR",`Kh\xF4ng c\xF3 ${v}`);return U}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 Kt=e=>`bundle:${e}`,Yt=()=>`${D().file_system.document_dir}/miniapps`,Xt=Yt,Zt=(e,t,n="index.html",o=!1,r=[])=>{let i=`${Xt()}/${e}/${t}`;return{app_id:e,version:t,dir:i,entry_uri:`file://${i}/${n}`,context_update:o,permissions:r}},Gt=e=>{var t;D().storage.setString(Kt(e.app_id),JSON.stringify({version:e.version,entry:e.entry,context_update:!!e.context_update,permissions:(t=e.permissions)!=null?t:[]}))},Rr=(e,t)=>/^https?:\/\//.test(t)?t:`${e.replace(/[^/]*$/,"")}${t}`,L=e=>{let t=D().storage.getString(Kt(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}},ve=e=>D().file_system.exists(e.entry_uri.replace("file://","")),Qt=async e=>{let t=L(e.app_id);return(t==null?void 0:t.version)===e.version&&await ve(t)},Mo=async(e,t)=>{let n=D().file_system,o=`${Xt()}/${e}`,r=await n.listDir(o).catch(()=>[]);await Promise.all(r.filter(i=>!t.includes(i)).map(i=>n.remove(`${o}/${i}`).catch(()=>{})))},xo=async e=>{var t;await((t=it[e])==null?void 0:t.catch(()=>{})),D().storage.setString(Kt(e),""),await D().file_system.remove(`${Xt()}/${e}`).catch(()=>{})},We=class extends Error{constructor(){super("cancelled"),this.name="MiniAppInstallCancelled"}},it={},Eo=(e,t)=>{var i;let o=((i=it[e])!=null?i:Promise.resolve()).catch(()=>{}).then(t),r=o.catch(()=>{});return it[e]=r,r.then(()=>{it[e]===r&&delete it[e]}),o},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 l=((r=n[a])!=null?r:0)-((i=o[a])!=null?i:0);if(l)return l}return 0},Tr=({manifest:e,zip_path:t})=>Eo(e.app_id,async()=>{var i;let n=D().file_system,o=L(e.app_id);if(o&&Pr(o.version,e.version)>=0&&await ve(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),Gt(e),ae("\u0111\xE3 c\xE0i b\u1EA3n \u0111\xF3ng s\u1EB5n",e.app_id,e.version),Mo(e.app_id,[e.version,o==null?void 0:o.version].filter(Boolean)),r}),en=(e,{base_url:t,onProgress:n}={})=>{let o=D().file_system,r=null,i=!1,a=`${o.cache_dir}/${e.app_id}-${e.version}.zip`,l=()=>{if(i)throw new We},c=async()=>{var g;l();let s=L(e.app_id);if((s==null?void 0:s.version)===e.version&&await o.exists(s.dir))return Gt(e),L(e.app_id);l();let p=o.download({url:t?Rr(t,e.bundle_url):e.bundle_url,to_file:a,onProgress:(y,u)=>{var C;let h=u>0?u:(C=e.size)!=null?C:0;h>0&&(n==null||n(Math.min(1,y/h)))}});r=p;try{let{status:y}=await p.promise;if(l(),y!==200)throw new Error(`bundle ${y}`);if(e.sha256)if(o.sha256){if(await o.sha256(a)!==e.sha256)throw new Error("sha256 mismatch")}else ae("b\u1ECF qua ki\u1EC3m tra sha256 (file_system kh\xF4ng c\xF3 sha256)",e.app_id);l();let u=Zt(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),Gt(e),Mo(e.app_id,[e.version,s==null?void 0:s.version].filter(Boolean)),u}catch(y){throw i?new We:y}finally{r=null,o.remove(a).catch(()=>{})}};return{promise:Eo(e.app_id,c),cancel:()=>{i=!0,r==null||r.cancel()}}},rt={},Cr=__DEV__?0:60*1e3,vo={},Ro=(e,t)=>{var o,r;let n=L(e);return n&&Date.now()-((o=vo[t])!=null?o:0)<Cr?Promise.resolve(n):((r=rt[e])!=null||(rt[e]=(async()=>{let i=await fetch(t,{headers:{"Cache-Control":"no-cache"}});if(!i.ok)throw new Error(`manifest ${i.status}`);let a=await i.json(),l=await en(a,{base_url:t}).promise;return vo[t]=Date.now(),l})().catch(i=>(console.warn("[miniapp] sync failed",e,i==null?void 0:i.message),L(e))).finally(()=>{rt[e]=void 0})),rt[e])};var St=new Map,Po=(e,t)=>(St.set(e,t),()=>{St.get(e)===t&&St.delete(e)}),Or=(e,t)=>{let n=St.get(e);return n?n(t):!1};import{useCallback as kr,useEffect as tn,useRef as je,useState as vt}from"react";import{Animated as K,BackHandler as Ir,Easing as To,Platform as ko,Pressable as Lr,StatusBar as Fr,StyleSheet as on,Text as st,View as q}from"react-native";import{Fragment as $r,jsx as P,jsxs as he}from"react/jsx-runtime";var at="#22C55E",Dr="\u0110\u01B0a m\xE3 v\xE0o khung \u0111\u1EC3 qu\xE9t",Nr=2,xt=18,Ur=1600,ct=14,Vr=2e3,Co=2,He=2e3,Br=[{top:0,left:0,borderTopWidth:4,borderLeftWidth:4,borderTopLeftRadius:ct},{top:0,right:0,borderTopWidth:4,borderRightWidth:4,borderTopRightRadius:ct},{bottom:0,left:0,borderBottomWidth:4,borderLeftWidth:4,borderBottomLeftRadius:ct},{bottom:0,right:0,borderBottomWidth:4,borderRightWidth:4,borderBottomRightRadius:ct}],Oo=({color:e})=>P($r,{children:Br.map((t,n)=>P(q,{style:[b.corner,t,{borderColor:e}]},n))}),Mt=({style:e,children:t,...n})=>{let o=je(new K.Value(1)).current,r=i=>K.spring(o,{toValue:i,speed:40,bounciness:8,useNativeDriver:!0}).start();return P(Lr,{...n,onPressIn:()=>r(.88),onPressOut:()=>r(1),children:P(K.View,{style:[e,{transform:[{scale:o}]}],children:t})})},rn=({scanner:e})=>{var _e,be,Ee;let{vision:t,types:n,mode:o,layout:r,hint:i,glass_view:a}=e,l=r===Se.top,c=t.useCameraDevice("back"),[s,p]=vt(!1),[g,y]=vt(1),[u,h]=vt({width:0,height:0}),C=V(z,R=>R.last_value),S=V(z,R=>R.hit_tick),M=V(z,R=>R.scan_count),A=V(z,R=>R.notice),w=V(z,R=>R.is_picking),G=je(null),[Q,ie]=vt(0),we=ko.OS==="ios"?54:(_e=Fr.currentHeight)!=null?_e:0,m=je(new K.Value(0)).current,v=je(new K.Value(0)).current,U=je(new K.Value(0)).current,x=Math.round(u.width*(l?.8:.78)),T=Math.round(l?u.height*.46:x*.78),F=Math.round((u.height-T)/2),W=Math.round((u.width-x)/2),I=t.useCodeScanner({codeTypes:n,onCodeScanned:kr(R=>jt(R),[])});tn(()=>{let R=Ir.addEventListener("hardwareBackPress",()=>(Wt(),!0));return()=>R.remove()},[]);let X=je(S);tn(()=>{if(S===X.current)return;m.setValue(1),U.setValue(1);let R=K.parallel([K.timing(m,{toValue:0,duration:450,useNativeDriver:!0}),K.sequence([K.delay(Vr),K.timing(U,{toValue:0,duration:250,useNativeDriver:!0})])]);return R.start(),()=>R.stop()},[S,m,U]),tn(()=>{let R=Ke=>K.timing(v,{toValue:Ke,duration:Ur,easing:To.inOut(To.quad),useNativeDriver:!0}),Fe=K.loop(K.sequence([R(1),R(0)]));return Fe.start(),()=>Fe.stop()},[v]);let xe=!!(c!=null&&c.hasTorch),fe=(be=c==null?void 0:c.neutralZoom)!=null?be:1,ee=c?Math.min(fe*g,c.maxZoom):1,Le=P(st,{style:[b.hint,!!A&&b.hint_notice],numberOfLines:1,children:(Ee=A!=null?A:i)!=null?Ee:Dr});return he(q,{ref:G,style:l?b.top:b.full,onLayout:({nativeEvent:{layout:R}})=>{var Fe;h({width:R.width,height:R.height}),(Fe=G.current)==null||Fe.measureInWindow((Ke,mt)=>ie(mt))},children:[c&&P(t.Camera,{style:on.absoluteFill,device:c,isActive:!w,codeScanner:I,torch:s&&xe?"on":"off",zoom:ee,enableZoomGesture:!0,onError:R=>ro(R.message)}),u.height>0&&he(q,{style:b.overlay,pointerEvents:"none",children:[P(q,{style:[b.dim_ring,{top:F-He,left:W-He,width:x+He*2,height:T+He*2}]}),he(q,{style:{position:"absolute",top:F,left:W,width:x,height:T},children:[P(Oo,{color:"#FFFFFF"}),P(K.View,{style:[on.absoluteFill,{opacity:m}],children:P(Oo,{color:at})}),he(K.View,{style:[b.scan_line_wrap,{transform:[{translateY:v.interpolate({inputRange:[0,1],outputRange:[0,Math.max(0,T-xt)]})}]}],children:[P(q,{style:b.scan_glow_outer}),P(q,{style:b.scan_glow_inner}),P(q,{style:b.scan_line})]})]}),P(q,{style:[b.hint_slot,l?{top:0,height:F-6,justifyContent:"flex-end"}:{top:F+T+20}],children:Le}),o===Be.continuous&&!!C&&P(K.View,{style:[b.result_slot,l?b.result_slot_top:{top:F+T+52},{opacity:U}],children:he(q,{style:b.result,children:[P(q,{style:b.check_badge,children:P(q,{style:b.check_mark})}),P(st,{style:b.result_text,numberOfLines:1,children:C}),he(st,{style:b.result_count,children:["\xB7 ",M," m\xE3"]})]})})]}),P(q,{style:[b.close_slot,{top:Math.max(12,we-Q+12)}],children:he(Mt,{style:[b.close_button,!!a&&b.glass_surface],onPress:Wt,hitSlop:8,accessibilityRole:"button",accessibilityLabel:"\u0110\xF3ng",children:[a&&P(a,{style:b.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),P(q,{style:[b.close_bar,b.close_bar_a]}),P(q,{style:[b.close_bar,b.close_bar_b]})]})}),P(q,{style:[b.toolbar_wrap,!l&&b.toolbar_wrap_full],pointerEvents:"box-none",children:he(q,{style:[b.toolbar,!!a&&b.glass_surface],children:[a&&P(a,{style:b.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.35)",isInteractive:!0}),P(Mt,{style:b.tool,onPress:io,disabled:w,accessibilityRole:"button",accessibilityLabel:"Qu\xE9t t\u1EEB \u1EA3nh",children:he(q,{style:b.image_icon,children:[P(q,{style:b.image_icon_dot}),P(q,{style:b.image_icon_hill})]})}),!!c&&c.maxZoom>=fe*Co&&P(Mt,{style:[b.tool,g>1&&b.tool_on],onPress:()=>y(R=>R>1?1:Co),accessibilityRole:"button",accessibilityLabel:"Ph\xF3ng to",children:he(st,{style:[b.zoom_text,g>1&&b.zoom_text_on],children:[g,"x"]})}),xe&&P(Mt,{style:[b.tool,s&&b.tool_on],onPress:()=>p(R=>!R),accessibilityRole:"button",accessibilityLabel:"\u0110\xE8n pin",accessibilityState:{selected:s},children:P(st,{style:[b.torch_icon,s&&b.zoom_text_on],children:"\u26A1\uFE0E"})})]})})]})},qr="rgba(0,0,0,0.5)",nn=50,b=on.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:He,borderColor:qr,borderRadius:He+ct},hint_slot:{position:"absolute",left:16,right:16,alignItems:"center"},hint:{color:"#FFFFFF",fontSize:14,fontWeight:"500"},hint_notice:{color:"#FCA5A5"},corner:{position:"absolute",width:28,height:28},scan_line_wrap:{position:"absolute",top:0,left:10,right:10,height:xt,alignItems:"stretch",justifyContent:"center"},scan_glow_outer:{position:"absolute",left:0,right:0,height:xt,borderRadius:xt/2,backgroundColor:at,opacity:.1},scan_glow_inner:{position:"absolute",left:4,right:4,height:8,borderRadius:4,backgroundColor:at,opacity:.2},scan_line:{height:Nr,borderRadius:1,backgroundColor:at},glass_surface:{backgroundColor:"transparent",overflow:"visible"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:999},close_slot:{position:"absolute",right:12},close_button:{width:48,height:48,borderRadius:24,overflow:"hidden",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)"},close_bar:{position:"absolute",width:20,height:2,borderRadius:1,backgroundColor:"#FFFFFF"},close_bar_a:{transform:[{rotate:"45deg"}]},close_bar_b:{transform:[{rotate:"-45deg"}]},toolbar_wrap:{position:"absolute",left:0,right:0,bottom:10,alignItems:"center"},toolbar_wrap_full:{bottom:ko.OS==="ios"?34:20},toolbar:{flexDirection:"row",alignItems:"center",gap:4,padding:4,borderRadius:999,backgroundColor:"rgba(24,24,27,0.72)"},tool:{width:nn,height:nn,borderRadius:nn/2,alignItems:"center",justifyContent:"center"},tool_on:{backgroundColor:"#FFFFFF"},zoom_text:{color:"#FFFFFF",fontSize:16,fontWeight:"600"},zoom_text_on:{color:"#18181B"},torch_icon:{color:"#FFFFFF",fontSize:22,fontWeight:"600"},image_icon:{width:24,height:19,borderRadius:3,borderWidth:1.5,borderColor:"#FFFFFF",overflow:"hidden"},image_icon_dot:{position:"absolute",top:3,right:3,width:4,height:4,borderRadius:2,backgroundColor:"#FFFFFF"},image_icon_hill:{position:"absolute",left:2,bottom:-6,width:12,height:12,backgroundColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_slot:{position:"absolute",left:16,right:16,alignItems:"center"},result_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:at},check_mark:{width:5,height:9,marginTop:-2,borderRightWidth:2,borderBottomWidth:2,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},result_text:{flexShrink:1,color:"#FFFFFF",fontWeight:"600",fontSize:13},result_count:{color:"#A1A1AA",fontSize:13}});import{useEffect as Io,useRef as lt,useState as zr}from"react";import{AccessibilityInfo as Wr,Animated as j,Platform as jr,StatusBar as Hr,StyleSheet as Jr,Text as Gr,View as Je}from"react-native";import{Fragment as Fo,jsx as ye,jsxs as sn}from"react/jsx-runtime";var Kr={[ue.info]:"#3B82F6",[ue.success]:"#22C55E",[ue.error]:"#EF4444"},Lo=-120,Yr=({type:e})=>e===ue.success?ye(Je,{style:te.check_mark}):e===ue.error?sn(Fo,{children:[ye(Je,{style:[te.cross_bar,te.cross_a]}),ye(Je,{style:[te.cross_bar,te.cross_b]})]}):sn(Fo,{children:[ye(Je,{style:te.info_dot}),ye(Je,{style:te.info_bar})]}),No=()=>{let e=V(et,p=>p.message),t=V(et,p=>p.type),n=V(et,p=>p.tick),o=lt(new j.Value(Lo)).current,r=lt(new j.Value(0)).current,i=lt(new j.Value(.92)).current,a=lt(new j.Value(0)).current,[l,c]=zr();Io(()=>{let p=!0;return zt().then(g=>{p&&g&&c(()=>g)}),()=>{p=!1}},[]);let s=lt(n);return Io(()=>{if(n===s.current)return;Wr.announceForAccessibility(e),a.setValue(0),i.setValue(.92);let p=j.sequence([j.parallel([j.spring(o,{toValue:0,speed:16,bounciness:7,useNativeDriver:!0}),j.spring(i,{toValue:1,speed:16,bounciness:9,useNativeDriver:!0}),j.timing(r,{toValue:1,duration:140,useNativeDriver:!0}),j.sequence([j.delay(90),j.spring(a,{toValue:1,speed:18,bounciness:14,useNativeDriver:!0})])]),j.delay($n[t]),j.parallel([j.timing(o,{toValue:Lo,duration:240,useNativeDriver:!0}),j.timing(r,{toValue:0,duration:200,useNativeDriver:!0})])]);return p.start(),()=>p.stop()},[n]),n?ye(Je,{style:te.layer,pointerEvents:"none",children:sn(j.View,{style:[te.toast,!!l&&te.toast_glass,{opacity:r,transform:[{translateY:o},{scale:i}]}],accessibilityLiveRegion:"polite",children:[l&&ye(l,{style:te.glass_fill,glassEffectStyle:"regular",colorScheme:"dark",tintColor:"rgba(24,24,27,0.55)"}),ye(j.View,{style:[te.badge,{backgroundColor:Kr[t],transform:[{scale:a}]}],children:ye(Yr,{type:t})}),ye(Gr,{style:te.message,numberOfLines:2,children:e})]})}):null},Do,te=Jr.create({layer:{position:"absolute",top:(jr.OS==="ios"?54:(Do=Hr.currentHeight)!=null?Do:0)+8,left:16,right:16,alignItems:"center",zIndex:9999,elevation:9999},toast:{maxWidth:"100%",minHeight:50,flexDirection:"row",alignItems:"center",gap:10,paddingLeft:11,paddingRight:18,paddingVertical:11,borderRadius:25,backgroundColor:"#18181B",shadowColor:"#000000",shadowOpacity:.32,shadowRadius:18,shadowOffset:{width:0,height:8},elevation:12},toast_glass:{backgroundColor:"transparent"},glass_fill:{position:"absolute",top:0,left:0,right:0,bottom:0,borderRadius:25},badge:{width:28,height:28,borderRadius:14,alignItems:"center",justifyContent:"center"},message:{flexShrink:1,color:"#FFFFFF",fontSize:15,lineHeight:20,fontWeight:"600"},check_mark:{width:7,height:13,marginTop:-3,borderRightWidth:2.5,borderBottomWidth:2.5,borderColor:"#FFFFFF",transform:[{rotate:"45deg"}]},cross_bar:{position:"absolute",width:14,height:2.5,borderRadius:2,backgroundColor:"#FFFFFF"},cross_a:{transform:[{rotate:"45deg"}]},cross_b:{transform:[{rotate:"-45deg"}]},info_dot:{width:3,height:3,borderRadius:2,marginBottom:2,backgroundColor:"#FFFFFF"},info_bar:{width:2.5,height:10,borderRadius:2,backgroundColor:"#FFFFFF"}});var ne=Te({active_key:null,instances:{}}),Uo=({app:e,instance_id:t,context:n={},url_params:o={},host_data:r={}},i)=>{var l;let a=(l=D().keep_alive)==null?void 0:l.max_webviews;ne.setState(c=>{let s=t!=null?t:e.app_id,p={...c.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(y=>y!==s).sort((y,u)=>p[y].last_used_at-p[u].last_used_at).slice(0,g.length-a).forEach(y=>{delete p[y]}),i?{active_key:s,instances:p}:{instances:p}})},Xr=e=>Uo(e,!0),Zr=e=>Uo(e,!1),pt=()=>ne.setState({active_key:null}),Et=e=>{ne.setState(t=>{if(t.active_key===e||!t.instances[e])return{};let n={...t.instances};return delete n[e],{instances:n}})};var Vo="catalog",Qr="paused_apps",ei="removed_apps",ti=10*1e3,ni=2,oi=3e3,ri=()=>{var e;try{return JSON.parse((e=D().storage.getString(Vo))!=null?e:"{}")}catch{return{}}},O=Te({catalog:{},downloads:{},pause_reasons:[],updates:{},apply_ticks:{}}),Bo=e=>{var t;return!!((t=D().manual_update)!=null&&t.includes(e))},Tt=new Set,qo=e=>{let t=new Set,n=()=>D().storage.setString(e,JSON.stringify([...t]));return{has:o=>t.has(o),values:()=>[...t],add:o=>t.has(o)?!1:(t.add(o),n(),!0),delete:o=>t.delete(o)?(n(),!0):!1,load:()=>{var o;t.clear();try{let r=JSON.parse((o=D().storage.getString(e))!=null?o:"[]");Array.isArray(r)&&r.forEach(i=>{typeof i=="string"&&t.add(i)})}catch{}}}},ge=qo(Qr),Ie=qo(ei);_n(()=>{ge.load(),Ie.load();let e=ri(),t={};Object.keys(e).filter(n=>!Ie.has(n)).forEach(n=>{let o=L(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})}),O.setState({catalog:e,downloads:t})});var cn=e=>V(O,t=>e?t.downloads[e]:void 0),ii=()=>V(O,e=>e.pause_reasons.length>0),de=(...e)=>ae("queue",...e),H=[],Me={},E=null,Rt=new Set,qe={},an=new Set,Oe=e=>{an.forEach(t=>{try{t(e)}catch(n){console.warn("[miniapp-queue] event listener error",n==null?void 0:n.message)}})},si=e=>(an.add(e),()=>{an.delete(e)}),ai=()=>O.getState().downloads,oe=(e,t)=>{let n=!!L(e),o=O.getState().downloads[e],r=t.status==="downloading"&&n?"updating":t.status,i={...o!=null?o:{status:"queued",progress:0},...t,...r?{status:r}:{},has_local:n};O.setState(a=>({downloads:{...a.downloads,[e]:i}})),(o==null?void 0:o.status)!==i.status||(o==null?void 0:o.version)!==i.version||(o==null?void 0:o.has_local)!==i.has_local?Oe({type:"status_change",app_id:e,state:i}):o.progress!==i.progress&&Oe({type:"progress",app_id:e,progress:i.progress,version:i.version})},Pt=(e,t)=>{var n;(n=qe[e])==null||n.forEach(o=>o(t)),delete qe[e]},ci=()=>O.getState().pause_reasons.length>0,ke=e=>{var l;if(E)return;let t=e?H.indexOf(e):ci()?-1:H.findIndex(c=>!ge.has(c));if(t<0||t>=H.length)return;let[n]=H.splice(t,1),o=O.getState().catalog[n];if(!o){Pt(n,L(n)),ke();return}let r=Date.now();Me[n]=((l=Me[n])!=null?l:0)+1,oe(n,{status:"downloading",progress:0,version:o.version,error:void 0});let i=0,a=en(o,{onProgress:c=>{let s=Math.floor(c*100);s!==i&&(i=s,oe(n,{progress:s/100,version:o.version}))}});E={app_id:n,handle:a,forced:!!e},de("start",n,o.version,e?"(forced)":""),a.promise.then(c=>{de("installed",n,o.version,`${Date.now()-r}ms`),oe(n,{status:"installed",progress:1,version:o.version}),Pt(n,c)}).catch(c=>{var p;if(c instanceof We){if(Rt.has(n))return;de("paused",n),Me[n]-=1,H.unshift(n),oe(n,{status:ge.has(n)?"paused":"queued",progress:0,version:o.version});return}let s=String((p=c==null?void 0:c.message)!=null?p:c);if(console.warn("[miniapp-queue] failed",n,s),Me[n]<ni){oe(n,{status:"queued",progress:0,version:o.version,error:s}),setTimeout(()=>{var g;H.includes(n)||(E==null?void 0:E.app_id)===n||(H.push(n),ke((g=qe[n])!=null&&g.length?n:void 0))},oi);return}oe(n,{status:"failed",progress:0,version:o.version,error:s}),Pt(n,L(n))}).finally(()=>{E=null;let c=H.find(s=>{var p;return(p=qe[s])==null?void 0:p.length});ke(c)})},Ct=(e,{front:t=!1}={})=>{if((E==null?void 0:E.app_id)===e)return;let n=H.indexOf(e);if(n>=0){if(!t)return;H.splice(n,1)}t?H.unshift(e):H.push(e)},li=async e=>{let{host_id:t,client_token:n}=D(),o=new AbortController,r=setTimeout(()=>o.abort(),ti);try{let i=`${Lt}/api/hosts/${encodeURIComponent(t)}/miniapps?channel=${e}`,a=await fetch(i,{headers:{Authorization:`Bearer ${n}`,"Cache-Control":"no-cache"},signal:o.signal});if(!a.ok)throw new Error(`host list ${e} ${a.status}`);return(await a.json()).apps.map(c=>({...c,channel:e}))}finally{clearTimeout(r)}},ut=null,ln=()=>(ut!=null||(ut=(async()=>{var t;let e=Date.now();try{let n=await Promise.all(D().channels.map(li)),o={};[...n].reverse().flat().forEach(c=>{o[c.app_id]=c});let r=Object.keys(O.getState().catalog).filter(c=>!o[c]);D().storage.setString(Vo,JSON.stringify(o)),O.setState({catalog:o}),await Promise.all(r.map(c=>$o(c,{by_user:!1}))),r.forEach(c=>Ie.delete(c));let i=Object.keys(o).filter(c=>!Ie.has(c)),a=[],l={};for(let c of i.map(s=>o[s])){if(await Qt(c)){oe(c.app_id,{status:"installed",progress:1,version:c.version});continue}let s=L(c.app_id);if(Bo(c.app_id)&&!Tt.has(c.app_id)&&s&&await ve(s)){oe(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=>{Me[c.app_id]=0,oe(c.app_id,{status:ge.has(c.app_id)?"paused":"queued",progress:0,version:c.version,error:void 0}),Ct(c.app_id)}),de("catalog",i.length,"apps, outdated",a.map(c=>c.app_id),"removed",r,`${Date.now()-e}ms`),Oe({type:"sync_complete",app_ids:i,removed:r}),Object.values(l).forEach(c=>Oe({type:"update_available",...c})),ke(),{ok:!0,app_ids:i,removed:r}}catch(n){let o=String((n==null?void 0:n.name)==="AbortError"?"timeout":(t=n==null?void 0:n.message)!=null?t:n);return console.warn("[miniapp-queue] sync catalog failed",o),Oe({type:"sync_failed",error:o}),{ok:!1,error:o}}finally{ut=null}})()),ut),$o=async(e,{by_user:t})=>{var r,i,a,l;if(t&&Ie.add(e),Rt.has(e))return;Rt.add(e),ge.delete(e);let n=H.indexOf(e);n>=0&&H.splice(n,1),(E==null?void 0:E.app_id)===e&&E.handle.cancel();let o=(l=(a=(r=O.getState().downloads[e])==null?void 0:r.version)!=null?a:(i=L(e))==null?void 0:i.version)!=null?l:"";oe(e,{status:"uninstalling",progress:0,version:o}),await xo(e),Et(e),O.setState(c=>{let s={...c.downloads};return delete s[e],{downloads:s}}),delete Me[e],Rt.delete(e),Pt(e,null),de("uninstalled",e,t?"(user)":"(not in list)"),Oe({type:"uninstalled",app_id:e})},pi=e=>$o(e,{by_user:!0}),ui=e=>{let t=dt(e);return t?(Ie.delete(e),(E==null?void 0:E.app_id)===e||H.includes(e)||(Me[e]=0,oe(e,{status:ge.has(e)?"paused":"queued",progress:0,version:t.version,error:void 0}),Ct(e),ke(),de("restore",e)),!0):!1},di=e=>{if(ge.has(e))return;if(ge.add(e),de("pause app",e),(E==null?void 0:E.app_id)===e&&!E.forced){E.handle.cancel();return}let t=O.getState().downloads[e];H.includes(e)&&t&&oe(e,{status:"paused",progress:0,version:t.version})},gi=e=>{if(!ge.delete(e))return;de("resume app",e);let t=O.getState().downloads[e];(t==null?void 0:t.status)==="paused"&&!H.includes(e)&&dt(e)&&(Me[e]=0,Ct(e)),H.includes(e)&&t&&oe(e,{status:"queued",progress:0,version:t.version}),ke()},mi=e=>{let{pause_reasons:t}=O.getState();t.includes(e)||(O.setState({pause_reasons:[...t,e]}),de("pause",e),t.length===0&&Oe({type:"pause_change",paused:!0,reasons:[e]}),E&&!E.forced&&E.handle.cancel())},fi=e=>{let{pause_reasons:t}=O.getState();if(!t.includes(e))return;let n=t.filter(o=>o!==e);O.setState({pause_reasons:n}),de("resume",e),n.length===0&&Oe({type:"pause_change",paused:!1,reasons:n}),ke()},zo=e=>O.getState().updates[e],hi=async e=>{var n,o;let t=zo(e);Tt.add(e);try{let r=await Ot(e),i=(o=t==null?void 0:t.next_version)!=null?o:(n=dt(e))==null?void 0:n.version;return!r||!i||r.version!==i?!1:(O.setState(a=>{var c;let l={...a.updates};return delete l[e],{updates:l,apply_ticks:{...a.apply_ticks,[e]:((c=a.apply_ticks[e])!=null?c:0)+1}}}),de("updated",e,t==null?void 0:t.current_version,"\u2192",r.version),!0)}finally{Tt.delete(e)}},yi=()=>Object.values(O.getState().catalog).map(e=>({...e,installed:!!L(e.app_id),removed_by_user:Ie.has(e.app_id)})),dt=e=>O.getState().catalog[e],Ot=async e=>{let t=dt(e);if(!t)return;if(ge.delete(e),Ie.delete(e),await Qt(t))return L(e);let n=L(e);if(Bo(e)&&!Tt.has(e)&&n&&await ve(n))return n;let o=new Promise(r=>{var i;((i=qe[e])!=null?i:qe[e]=[]).push(r)});return(E==null?void 0:E.app_id)===e?E.forced=!0:(Me[e]=0,Ct(e,{front:!0}),E&&!E.forced?E.handle.cancel():ke(e)),o};import{Fragment as mn,jsx as J,jsxs as Ge}from"react/jsx-runtime";var un=e=>(e!=null?e:"").replace(/\?[^#]*/,""),jo=0,Mi=()=>{let e=new Set;return{emit:t=>e.forEach(n=>n(t)),subscribe:t=>(e.add(t),()=>{e.delete(t)})}},xi=fn.memo(({instance_key:e,is_active:t,is_front:n,is_dark:o,reload_tick:r,web_at_top:i,splash:a,bridge:l,opaque_background:c,allow_embedded_miniapps:s,onWebLoadEnd:p})=>{var Ke,mt;let g=me(null),y=me(!1),u=V(ne,f=>f.instances[e]),h=u==null?void 0:u.app.app_id,C=u==null?void 0:u.app.manifest_url,S=u==null?void 0:u.context,M=u==null?void 0:u.url_params,A=V(z,f=>{var _;return((_=f.active)==null?void 0:_.owner)===e?f.active:null}),[w,G]=$e(()=>h?L(h):null),[Q,ie]=$e(!1),[we,m]=$e(0),[v,U]=$e(0),[x,T]=$e(!1),F=me(null),W=f=>{F.current&&clearTimeout(F.current),F.current=setTimeout(()=>{F.current=null,T(!0)},f)};re(()=>()=>{F.current&&clearTimeout(F.current)},[]),re(()=>{if(!h||!t&&w)return;let f=!0;return ie(!1),(async()=>{let _=L(h),Z=_?await ve(_):!1;if(!f||(G(Z?pe=>!pe||pe.version!==_.version||pe.permissions.join(",")!==_.permissions.join(",")?_:pe:null),__DEV__&&Date.now()-jo>1e4&&(jo=Date.now(),await ln()),!f))return;let Re=await Ot(h),De=Re!==void 0?Re:C?await Ro(h,C):L(h);if(f){if(!De){ie(!0);return}G(pe=>pe!=null?pe:De)}})(),()=>{f=!1}},[t,h,C,we]),re(()=>Po(e,f=>g.current?(g.current.postMessage(f),!0):!1),[e]);let I=V(O,f=>{let _=h?f.downloads[h]:void 0;return(_==null?void 0:_.status)==="installed"?_.version:void 0});re(()=>{if(t||!h||!w)return;let f=L(h);if(!f||f.version===w.version)return;let _=!0;return ve(f).then(Z=>{!_||!Z||(ae(`webview:${e}`,"\u0111\u1ED5i bundle (\u1EA9n)",w.version,"\u2192",f.version),G(f))}),()=>{_=!1}},[t,h,I,w==null?void 0:w.version]);let X=V(O,f=>{var _;return h&&(_=f.apply_ticks[h])!=null?_:0});re(()=>{if(!X||!h)return;let f=L(h);if(!f||f.version===(w==null?void 0:w.version))return;let _=!0;return ve(f).then(Z=>{!_||!Z||(ae(`webview:${e}`,"c\u1EADp nh\u1EADt",w==null?void 0:w.version,"\u2192",f.version),T(!1),G(f))}),()=>{_=!1}},[X]),re(()=>{var Z;let f=(Z=D().keep_alive)==null?void 0:Z.idle_close_ms;if(t||!f||f<=0)return;let _=setTimeout(()=>{Et(e)},f);return()=>clearTimeout(_)},[t,e]),re(()=>{r>0&&(ie(!1),T(!1),U(f=>f+1),m(f=>f+1))},[r]);let xe=me(t);re(()=>{var f;xe.current!==t&&(xe.current=t,y.current&&((f=g.current)==null||f.injectJavaScript(fo(t?"resumed":"paused"))))},[t]);let fe=`${(Ke=w==null?void 0:w.version)!=null?Ke:"none"}:${(mt=w==null?void 0:w.permissions.join(","))!=null?mt:""}:${v}`,ee=kt(()=>JSON.stringify([S!=null?S:{},M!=null?M:{}]),[S,M]),Le=kt(()=>{var f;return bo(M!=null?M:{},(f=w==null?void 0:w.permissions)!=null?f:[])},[ee,w==null?void 0:w.permissions]),_e=kt(()=>wo(S!=null?S:{},Le)+go()+(Ai.OS==="android"?mo():"")+(D().debug?uo():""),[Le]),be=me(null),Ee=me(null);re(()=>{var _,Z,Re;if(!w)return;if(Ee.current!==fe){Ee.current=fe,be.current=ee;return}if(be.current===ee)return;let f=((Z=JSON.parse((_=be.current)!=null?_:"[]")[0])!=null?Z:{}).org_id;if(be.current=ee,f===(S==null?void 0:S.org_id)&&y.current){T(!1),W(1500),(Re=g.current)==null||Re.injectJavaScript(ho(S!=null?S:{},Le));return}T(!1),U(De=>De+1)},[ee,w,fe]),re(()=>(t||(Ae(e),Ce(e),Ve(e)),()=>{Ae(e),Ce(e),Ve(e)}),[t,e,fe,r]),re(()=>{let f=Wo.addEventListener("change",_=>{_==="background"&&!Hn()&&Ae(e),_==="background"&&!Zn()&&Ce(e)});return()=>f.remove()},[e]);let R=dn(async f=>{var Z,Re,De,pe,It;let _=ao(f.nativeEvent.data);if(!_){if(h&&(l!=null&&l.onWebEvent))try{Promise.resolve(l.onWebEvent(f.nativeEvent.data,{app_id:h,instance_id:e})).catch(N=>{console.warn("[miniapp] onWebEvent l\u1ED7i",h,N)})}catch(N){console.warn("[miniapp] onWebEvent l\u1ED7i",h,N)}return}if(_.method==="log"){let{level:N,text:B}=_;ae(`web:${e}`,N!=null?N:"log",B!=null?B:"");return}if(_.method==="pong"){F.current||T(!0);return}if(_.method==="touchAtTop"){i.emit(!!_.at_top);return}if(_.method==="contextApplied"){F.current&&clearTimeout(F.current),F.current=null,T(!0);return}if(_.method==="ready"){y.current=!0,T(!0);let N=(Z=ne.getState().instances[e])==null?void 0:Z.context;N&&((Re=g.current)==null||Re.injectJavaScript(Jt(N)));return}try{let N=await So(_,{getHostData:()=>{var B,se;return(se=(B=ne.getState().instances[e])==null?void 0:B.host_data)!=null?se:{}},getPermissions:()=>{var B,se;return h?(se=(B=L(h))==null?void 0:B.permissions)!=null?se:[]:[]},getContext:()=>{var B,se;return(se=(B=ne.getState().instances[e])==null?void 0:B.context)!=null?se:{}},is_dark:o,close:pt,app_id:h!=null?h:"",instance_id:e,options:l,emit:(B,se)=>{var yn;(yn=g.current)==null||yn.injectJavaScript(po(B,se))},playBeep:()=>{var B;(B=g.current)==null||B.injectJavaScript(Ao())},isActive:()=>ne.getState().active_key===e&&Wo.currentState!=="background"});_.id&&((De=g.current)==null||De.injectJavaScript(co(_.id,N)))}catch(N){if(!_.id)return;let B=N==null?void 0:N.code,se=N instanceof d?N:new d(typeof B=="string"?B:"HOST_ERROR",String((pe=N==null?void 0:N.message)!=null?pe:N));(It=g.current)==null||It.injectJavaScript(lo(_.id,se))}},[e,o,h,i,l]),Fe=dn(()=>{ie(!1),U(f=>f+1),m(f=>f+1)},[]);return Ge(gn,{style:[hn.absoluteFill,c&&{backgroundColor:o?"#09090B":"#FFFFFF"},!n&&le.behind],pointerEvents:t?"auto":"none",children:[(A==null?void 0:A.layout)===Se.top&&J(rn,{scanner:A}),w?J(vi,{ref:g,source:{uri:w.entry_uri},originWhitelist:["*"],hideKeyboardAccessoryView:!0,mediaPlaybackRequiresUserAction:!1,allowingReadAccessToURL:`file://${s?Yt():w.dir}`,allowFileAccess:!0,allowFileAccessFromFileURLs:!0,allowUniversalAccessFromFileURLs:!0,injectedJavaScriptBeforeContentLoaded:_e,onMessage:R,bounces:!1,overScrollMode:"never",onLoadStart:f=>{Ae(e),Ce(e),Ve(e),ae(`webview:${e}`,"load start",un(f.nativeEvent.url)),y.current=!1,T(!1)},onError:f=>{Ae(e),Ce(e),Ve(e),ae(`webview:${e}`,"load error",un(f.nativeEvent.url),f.nativeEvent.description),ie(!0),T(!1)},onLoadEnd:f=>{let _=f.nativeEvent.url;ae(`webview:${e}`,"load end",un(_)),h&&(p==null||p({app_id:h,instance_id:e,url:_})),W(1500)},onContentProcessDidTerminate:()=>{Ae(e),Ce(e),Ve(e),y.current=!1,T(!1),U(f=>f+1)},onRenderProcessGone:()=>(Ae(e),Ce(e),Ve(e),y.current=!1,T(!1),U(f=>f+1),!0),style:le.webview},fe):null,(A==null?void 0:A.layout)===Se.full&&J(rn,{scanner:A}),u&&J(Ri,{visible:!w||!x,interactive:Q,children:J(Ei,{splash:a,app:u.app,is_dark:o,error:Q,has_bundle:!!w,retry:Fe})})]})}),Ei=fn.memo(({splash:e,app:t,is_dark:n,error:o,has_bundle:r,retry:i})=>{let a=e,l=cn(t.app_id),c=o?"error":!r&&(l==null?void 0:l.status)==="downloading"?"downloading":"loading";return J(a,{app:t,is_dark:n,status:c,progress:c==="downloading"?l==null?void 0:l.progress:void 0,retry:i})}),Ri=({visible:e,interactive:t,children:n})=>{let o=me(new pn.Value(e?1:0)).current,[r,i]=$e(e);return re(()=>{if(e){i(!0),o.setValue(1);return}let a=pn.timing(o,{toValue:0,duration:180,useNativeDriver:!0});return a.start(({finished:l})=>{l&&i(!1)}),()=>a.stop()},[e,o]),r?J(pn.View,{style:[hn.absoluteFill,{opacity:o}],pointerEvents:t?"auto":"none",children:n}):null},Jo=({app:e,is_dark:t,status:n,progress:o,retry:r})=>{let i=t?"#FAFAFA":"#18181B";return Ge(gn,{style:[le.splash,{backgroundColor:t?"#09090B":"#FFFFFF"}],children:[J(gn,{style:[le.splash_icon,{backgroundColor:t?"#18181B":"#F4F4F5"}],children:e.icon?J(bi,{source:{uri:e.icon},style:le.splash_icon_image}):J(gt,{style:le.splash_letter,children:(e.name||"?").slice(0,1).toUpperCase()})}),J(gt,{style:[le.splash_name,{color:i}],children:e.name}),n==="error"?Ge(mn,{children:[J(gt,{style:le.splash_hint,children:"Kh\xF4ng t\u1EA3i \u0111\u01B0\u1EE3c mini app"}),J(Si,{activeOpacity:.7,style:[le.retry_button,{backgroundColor:t?"#27272A":"#F4F4F5"}],onPress:r,children:J(gt,{style:[le.retry_text,{color:i}],children:"Th\u1EED l\u1EA1i"})})]}):Ge(mn,{children:[J(wi,{style:le.splash_spinner,color:t?"#A1A1AA":"#71717A"}),n==="downloading"&&Ge(gt,{style:le.splash_hint,children:["\u0110ang t\u1EA3i mini app",o?` ${Math.round(o*100)}%`:"\u2026"]})]})]})},Ho=(e,t)=>{let n=me(t),o=me(!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.`))},Pi=({container:e,splash:t=Jo,is_dark:n=!1,bridge:o,close_on_back:r=!0,opaque_background:i=!0,allow_embedded_miniapps:a=!1,onWebLoadEnd:l})=>{Ho("container",e),Ho("splash",t);let c=e,s=V(ne,A=>A.active_key),p=me(s);s&&(p.current=s);let g=V(ne,A=>Object.keys(A.instances).join("|")),y=V(ne,A=>{var w;return A.active_key?(w=A.instances[A.active_key])==null?void 0:w.app.name:void 0}),u=kt(()=>g?g.split("|"):[],[g]),[h,C]=$e({}),S=me(Mi()).current;re(()=>{if(!s||!r)return;let A=_i.addEventListener("hardwareBackPress",()=>(pt(),!0));return()=>A.remove()},[s,r]);let M=dn(()=>{let A=ne.getState().active_key;A&&C(w=>({...w,[A]:(w[A]||0)+1}))},[]);return u.length?Ge(mn,{children:[J(c,{visible:!!s,title:y!=null?y:"",is_dark:n,close:pt,reload:M,subscribeWebAtTop:S.subscribe,children:u.map(A=>J(xi,{instance_key:A,is_active:s===A,is_front:(s!=null?s:p.current)===A,is_dark:n,reload_tick:h[A]||0,web_at_top:S,splash:t,bridge:o,opaque_background:i,allow_embedded_miniapps:a,onWebLoadEnd:l},A))}),J(No,{})]}):null},le=hn.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"}}),Ti=fn.memo(Pi);export{Y as CodeType,Jo as DefaultMiniAppSplash,Lt as MINIAPP_PLATFORM_URL,Ti as MiniAppHost,d as MiniAppHostError,ze as ScannerEndReason,Bt as ScannerEvent,Se as ScannerLayout,tt as ScannerMethod,ue as ToastType,pt as closeMiniApp,Go as configureMiniApp,Yo as createMmkvStorage,bn as createReactNativeBiometrics,Ko as createRnfsFileSystem,Ot as ensureMiniApp,L as getLocalMiniApp,yi as getMiniAppCatalog,dt as getMiniAppCatalogEntry,ai as getMiniAppStatuses,zo as getMiniAppUpdate,Tr as installBundledMiniApp,si as onMiniAppEvent,Xr as openMiniApp,di as pauseMiniApp,mi as pauseMiniAppDownloads,Zr as preloadMiniApp,Ae as releaseSpeechFor,ui as restoreMiniApp,gi as resumeMiniApp,fi as resumeMiniAppDownloads,Or as sendEventToWeb,ln as syncMiniAppCatalog,pi as uninstallMiniApp,hi as updateMiniApp,Dn as uploadToUrl,cn as useMiniAppDownload,ii as useMiniAppDownloadsPaused};
|
package/docs/MINIAPP_README.md
CHANGED
|
@@ -426,7 +426,6 @@ const MySplash = ({ app, status, progress, retry }: MiniAppSplashProps) => (
|
|
|
426
426
|
splash={MySplash}
|
|
427
427
|
is_dark={isDark}
|
|
428
428
|
bridge={{
|
|
429
|
-
showToast: message => Toast.show(message),
|
|
430
429
|
app_version: DeviceInfo.getVersion(),
|
|
431
430
|
openUrl: url => Linking.openURL(url), // web gọi openWebview / openLink — mặc định đã là Linking.openURL
|
|
432
431
|
}}
|
package/docs/NATIVE_APIS.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
## Tích hợp API native
|
|
2
2
|
|
|
3
|
-
Phần này hướng dẫn **Face ID / Touch ID**, **speech-to-text**, **vị trí hiện tại**, **upload file** và các API native do app chủ cung cấp. App chủ dùng `@retion-miniapp/react-native@0.10.1`; web dùng `@retion-miniapp/sdk@0.8.0` trở lên (upload cần cả hai bản 0.10.0). Package tự xử lý các tính năng này qua bridge chung, không phụ thuộc Chat SDK và không cần gắn handler riêng.
|
|
3
|
+
Phần này hướng dẫn **Face ID / Touch ID**, **speech-to-text**, **vị trí hiện tại**, **quét mã QR / barcode**, **toast**, **upload file** và các API native do app chủ cung cấp. App chủ dùng `@retion-miniapp/react-native@0.10.1`; web dùng `@retion-miniapp/sdk@0.8.0` trở lên (upload cần cả hai bản 0.10.0). Package tự xử lý các tính năng này qua bridge chung, không phụ thuộc Chat SDK và không cần gắn handler riêng.
|
|
4
4
|
|
|
5
5
|
### Thiết lập app chủ
|
|
6
6
|
|
|
@@ -287,6 +287,7 @@ await stopScanner();
|
|
|
287
287
|
- `scanCode`: camera phủ kín vùng mini app, trả một mã rồi tự đóng.
|
|
288
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
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
|
+
- Kết hợp với toast: khi nhận mã, web gọi `showToast(...)` để báo kết quả xử lý; toast nổi trên cả camera.
|
|
290
291
|
- Nút trên camera dùng Liquid Glass trên iOS 26+ nếu app đã cài `expo-glass-effect` (tuỳ chọn); còn lại dùng nền tối.
|
|
291
292
|
- 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.
|
|
292
293
|
- 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.
|
|
@@ -358,6 +359,27 @@ const BRIDGE: MiniAppBridgeOptions = {
|
|
|
358
359
|
xong hoặc huỷ (vd đóng modal máy in → throw `CANCELLED`), nếu treo thì lượt sau luôn `BUSY`.
|
|
359
360
|
- Host tự kiểm tra params (vd `amount` phải > 0, có `currency`) trước khi gọi handler → sai trả `INVALID_PARAMS`.
|
|
360
361
|
|
|
362
|
+
### Toast (`showToast`)
|
|
363
|
+
|
|
364
|
+
Web gọi lúc nào cũng được, ví dụ sau khi xử lý xong mã vừa quét. Lệnh một chiều, không cần `await`; ngoài app thì bỏ qua. Cần host và Web SDK từ **0.13.0**, app chủ không phải cấu hình.
|
|
365
|
+
|
|
366
|
+
```ts
|
|
367
|
+
import { showToast, ToastType } from '@retion-miniapp/sdk';
|
|
368
|
+
|
|
369
|
+
showToast('Đã thêm vào giỏ', { type: ToastType.success });
|
|
370
|
+
showToast('Không tìm thấy sản phẩm', { type: ToastType.error });
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
| `ToastType` | Thời gian hiện |
|
|
374
|
+
| --- | --- |
|
|
375
|
+
| `info` (mặc định) | 2 giây |
|
|
376
|
+
| `success` | 2 giây |
|
|
377
|
+
| `error` | 3 giây |
|
|
378
|
+
|
|
379
|
+
- Toast nằm dưới thanh trạng thái, nổi trên mini app, camera và container; không chặn thao tác bên dưới. Dùng Liquid Glass trên iOS 26+ nếu app đã cài `expo-glass-effect`.
|
|
380
|
+
- `message` tối đa 200 ký tự, hiện tối đa 2 dòng. Gọi liên tiếp thì toast mới thay toast cũ. Mini app đang ẩn gọi sẽ bị bỏ qua.
|
|
381
|
+
- App muốn dùng toast riêng thì truyền `bridge.showToast(message, { type })`.
|
|
382
|
+
|
|
361
383
|
### Mở link ra ngoài (`openLink`)
|
|
362
384
|
|
|
363
385
|
WebView **không tự mở** link ra ngoài: web gọi `window.open` / đổi `location` sang link khác thì link nạp ngay trong
|